"use client"; import * as React from "react"; import { ArrowDownIcon, ArrowUpIcon, XIcon } from "lucide-react"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Combobox, ComboboxChip, ComboboxChips, ComboboxChipsInput, ComboboxContent, ComboboxEmpty, ComboboxItem, ComboboxList, ComboboxValue, } from "@/components/ui/combobox"; import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import type { LLMProfile } from "@/lib/types"; interface TaskLLMProfileChainProps { profiles: LLMProfile[]; value: string[]; onValueChange: (value: string[]) => void; activeProfileId?: string; onActiveProfileChange?: (value: string) => void; disabled?: boolean; inputId?: string; portalContainer?: React.RefObject; } function ProfileRoleBadge({ index, currentIndex }: { index: number; currentIndex: number }) { if (index === currentIndex) return 当前; if (index < currentIndex) { return ( 已跳过 ); } return 备用 {index - currentIndex}; } export function TaskLLMProfileChain({ profiles, value, onValueChange, activeProfileId, onActiveProfileChange, disabled = false, inputId, portalContainer, }: TaskLLMProfileChainProps) { const profilesByID = React.useMemo(() => new Map(profiles.map((profile) => [profile.id, profile])), [profiles]); const itemIDs = React.useMemo(() => profiles.map((profile) => profile.id), [profiles]); const profilesUnavailable = profiles.length === 0; const currentProfileID = activeProfileId && value.includes(activeProfileId) ? activeProfileId : value[0]; const currentIndex = value.indexOf(currentProfileID); // api_key_hint is display-only and is empty for valid keys shorter than four // characters. The task API remains authoritative for profile validation. const profileLabel = React.useCallback( (id: string) => { const profile = profilesByID.get(id); return profile ? `${profile.name} ${profile.model}` : `配置 #${id}`; }, [profilesByID], ); const move = (index: number, offset: -1 | 1) => { const target = index + offset; if (target < 0 || target >= value.length) return; const next = [...value]; [next[index], next[target]] = [next[target], next[index]]; onValueChange(next); }; const remove = (id: string) => { const next = value.filter((profileID) => profileID !== id); onValueChange(next); if (activeProfileId === id) onActiveProfileChange?.(next[0] ?? ""); }; const handleValueChange = (next: string[]) => { onValueChange(next); if (activeProfileId && !next.includes(activeProfileId)) { onActiveProfileChange?.(next[0] ?? ""); } }; return (
{value.map((id) => ( {profilesByID.get(id)?.name ?? `#${id}`} ))} 0 ? "搜索并添加 LLM 配置" : "暂无可用 LLM 配置"} disabled={disabled ? true : profilesUnavailable} /> 没有匹配的 LLM 配置 {(id) => { const profile = profilesByID.get(id); return (
{profile?.name ?? `配置 #${id}`} {profile?.is_default ? "(激活)" : ""} {profile && {profile.model}}
); }}
{value.length === 0 ? (

未指定配置时,任务跟随 Agent 或全局激活配置。

) : (
{value.map((id, index) => { const profile = profilesByID.get(id); return (
{index + 1}

{profile?.name ?? `配置 #${id}`}

{profile?.model ?? "配置已不可用"}

); })}
)} {onActiveProfileChange && value.length > 0 && (
当前配置
)}
); }