"use client"; import { ChevronDownIcon, ChevronUpIcon, PlusIcon, XIcon, } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import type { AgentQuestion } from "@/core/agents"; /** Soft cap on the chip label length — beyond this the landing chip truncates. */ const TITLE_SOFT_LIMIT = 80; /** The text a question row would actually persist as (panel save falls back * title↔prompt), used for duplicate detection. */ function effectivePrompt(q: AgentQuestion): string { return (q.prompt.trim() || q.title.trim()).toLowerCase(); } /** * Editable list of an agent's 常用问题 (recommended questions). Each row has a * short `title` (the chip label) and the full `prompt` sent on click. Supports * add / remove / inline edit / reorder (move up & down), with non-blocking * hints for over-long titles and duplicate questions. Pure controlled * component — persistence stays with the caller (edit dialog or detail panel). */ export function AgentQuestionEditor({ value, onChange, disabled, }: { value: AgentQuestion[]; onChange: (next: AgentQuestion[]) => void; disabled?: boolean; }) { function update(index: number, patch: Partial) { const next = [...value]; next[index] = { ...next[index]!, ...patch }; onChange(next); } function remove(index: number) { onChange(value.filter((_, i) => i !== index)); } function move(index: number, delta: -1 | 1) { const target = index + delta; if (target < 0 || target >= value.length) return; const next = [...value]; [next[index], next[target]] = [next[target]!, next[index]!]; onChange(next); } return (
{value.length === 0 && (

尚未配置常用问题,点击下方按钮添加。

)} {value.map((item, index) => { const titleLength = item.title.trim().length; const prompt = effectivePrompt(item); const duplicateOf = prompt ? value.findIndex((other, i) => i < index && effectivePrompt(other) === prompt) : -1; return (
update(index, { title: e.currentTarget.value })} className="h-8 text-sm font-medium" />