"use client"; import { useState } from "react"; import { Settings2, Trash2 } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { useChatConfig, type MountItem, } from "@/components/chat/chat-config-context"; import { MountRetrievalDialog } from "./mount-retrieval-dialog"; import { useI18n } from "@/i18n/i18n-context"; import type { KnowledgeBase } from "@/types/knowledge-base"; interface MountRowProps { mount: MountItem; subspaceEnabled: boolean; /** * 该挂载行对应的 KnowledgeBase 详情。仅用于透传给 * `MountRetrievalDialog`,由父组件按需注入;缺省时设置入口被禁用, * 因为 Dialog 渲染依赖 `KnowledgeBase` 上的 `multimodal` / 名称等字段。 */ knowledgeBase?: KnowledgeBase; } /** * Single-line representation of a mounted KB: name + (optional) subspace * editor + per-KB retrieval settings + remove. The session-wide defaults * still live in `UnifiedRetrievalSection`; this row exposes the per-KB * override entry via the gear icon (opens `MountRetrievalDialog`). * * `subspaceEnabled` controls whether the subspace input is shown; when the * KB was created without subspace support we hide the input entirely so the * row stays visually clean (the server would reject a subspace anyway). * Any residual `mount.subspace` from prior sessions is left untouched — if * it's a non-empty array it still gets sent; in practice this path is cold * because a KB's subspace flag is immutable post-creation. * * 当 `mount.retrieval` 存在(即该 KB 已切换为自定义配置)时,齿轮按钮 * 右上角显示一个小色点作为视觉提示,便于用户在不打开 Dialog 的情况下 * 区分继承全局 / 自定义配置。 */ export function MountRow({ mount, subspaceEnabled, knowledgeBase, }: MountRowProps) { const { t } = useI18n(); const cfg = useChatConfig(); const [subspaceText, setSubspaceText] = useState( (mount.subspace ?? []).join(", "), ); const [dialogOpen, setDialogOpen] = useState(false); const commitSubspace = () => { const next = subspaceText .split(",") .map((s) => s.trim()) .filter(Boolean); const prev = mount.subspace ?? []; // Avoid a redundant dispatch when nothing actually changed. const same = next.length === prev.length && next.every((v, i) => v === prev[i]); if (same) return; cfg.updateMount(mount.id, { subspace: next.length ? next : undefined }); }; return (
{mount.knowledgeBaseName} {subspaceEnabled ? ( setSubspaceText(e.target.value)} onBlur={commitSubspace} onKeyDown={(e) => { if (e.key === "Enter") { e.preventDefault(); (e.target as HTMLInputElement).blur(); } }} placeholder={t("chat.mount.subspacePlaceholder")} className="h-8 w-44 text-xs" /> ) : null}
{mount.retrieval ? ( ) : null}
{knowledgeBase ? ( ) : null}
); }