"use client"; import { type ReactNode, useEffect, useRef, useState } from "react"; import { ArrowUpIcon, MessageCircleQuestionIcon, SquareIcon, Trash2Icon, XIcon } from "lucide-react"; import { Markdown } from "@/components/markdown"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Drawer, DrawerContent, DrawerDescription, DrawerHeader, DrawerTitle } from "@/components/ui/drawer"; import { Empty, EmptyDescription, EmptyHeader, EmptyTitle } from "@/components/ui/empty"; import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupTextarea } from "@/components/ui/input-group"; import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "@/components/ui/resizable"; import { Skeleton } from "@/components/ui/skeleton"; import { useIsMobile } from "@/hooks/use-mobile"; import type { SideQuestions } from "@/hooks/use-side-questions"; import { cn } from "@/lib/utils"; type ComposerLayout = "inline" | "stacked"; const preparationLabels = { preparing: "正在准备上下文…", summarizing_history: "正在整理早期旁路问答…", compressing_snapshot: "正在压缩旁路上下文副本…", retrying: "模型上下文超限,正在缩减后重试…", answering: "正在回答…", }; export function SideQuestionButton({ side }: { side: SideQuestions }) { if (!side.enabled) return null; return ( ); } function SidePanel({ side, label, composerLayout, suggestions, placeholder, }: { side: SideQuestions; label: string; composerLayout: ComposerLayout; suggestions?: string[]; placeholder?: string; }) { const inlineComposer = composerLayout === "inline"; const [confirm, setConfirm] = useState(false); const viewport = useRef(null); const pinned = useRef(true); const tail = side.items.at(-1); // biome-ignore lint/correctness/useExhaustiveDependencies: New cumulative text scrolls only readers who remain at the bottom. useEffect(() => { if (pinned.current && viewport.current) viewport.current.scrollTop = viewport.current.scrollHeight; }, [tail?.answer, tail?.id]); const status = { running: "回答中", completed: "已完成", failed: "失败", cancelled: "已停止", interrupted: "已中断" }; return (

旁路提问 /btw

{label}

{side.snapshot ? ( <>

{side.snapshot.model.model}

上下文更新于 {new Date(side.snapshot.captured_at).toLocaleString()}

) : ( "主 Agent 首次运行后即可提问" )}
{ const el = event.currentTarget; pinned.current = el.scrollHeight - el.scrollTop - el.clientHeight < 80; }} className="min-h-0 flex-1 overflow-y-auto p-3" > {side.nextCursor > 0 && ( )} {side.loading && } {!side.loading && side.items.length === 0 && ( 随时问一个问题 根据当前 Agent 的上下文回答,主任务继续运行。 )}
{side.items.map((item) => (
{item.question}
{status[item.status]} {item.model.model}
{item.context?.estimated_input_tokens != null && (

最近 {item.context.recent_exchanges} 组问答原文 {item.context.history_summarized && " · 含早期问答摘要"} {item.context.snapshot_summarized && " · 使用主上下文摘要"}

)} {item.answer && } {!item.answer && item.status === "running" && (

{preparationLabels[item.context?.phase ?? "answering"]}

)} {item.error && ( {item.error} )}
))}
{(side.error || side.snapshot?.reason) && ( {side.error || side.snapshot?.reason} )} side.setDraft(event.target.value)} onKeyDown={(event) => { if (event.key === "Enter" && !event.shiftKey && !event.nativeEvent.isComposing) { event.preventDefault(); void side.ask(side.draft); } }} /> {!inlineComposer && 独立问答 · 无工具执行} {side.running ? ( void side.stop()} aria-label="停止旁路回答" > ) : ( void side.ask(side.draft)} disabled={side.busy || !side.draft.trim() || !side.snapshot?.available} aria-label="发送旁路问题" > )} {suggestions?.length ? (
{suggestions.map((suggestion) => ( ))}
) : null}
{inlineComposer && (
独立问答 · 无工具执行
)} 清空旁路历史? 删除当前 Agent 的旁路问答,并停止正在生成的旁路回答。主会话和上下文快照会保留。 取消 void side.clear()}>清空历史
); } export function SideQuestionWorkspace({ side, label, children, composerLayout = "stacked", suggestions, placeholder, className, mainClassName, }: { side: SideQuestions; label: string; children: ReactNode; composerLayout?: ComposerLayout; suggestions?: string[]; placeholder?: string; className?: string; mainClassName?: string; }) { const mobile = useIsMobile(); const desktopSideOpen = side.open && side.enabled && !mobile; return ( <> {desktopSideOpen ? ( {children} ) : (
{children}
)} 旁路提问 {label} 的独立问答 ); }