import { useEffect, useRef, useState } from "react"; import { LoaderCircle } from "lucide-react"; import type { SessionSummary, SideChat, SideMessage } from "@linkshell/wire"; import { Button } from "@/components/ui/button"; import { Textarea } from "@/components/ui/textarea"; import { ErrorNotice, useActions, useClient, useJob, useSessionOnline } from "./common"; import { RichText } from "./Timeline"; const NO_SIDES: SideChat[] = []; /** * The session's side conversations (Codex's `/side`, Claude's and Grok's * `/btw`): questions about the session that don't interrupt it or enter it. */ export function Side({ session, label }: { session: SessionSummary; label: string }) { const actions = useActions(); const online = useSessionOnline(); const sides = useClient((state) => state.sides[session.id] ?? NO_SIDES); const job = useJob(); const [sideId, setSideId] = useState(); const [draft, setDraft] = useState(""); const end = useRef(null); const current = sides.find((entry) => entry.sideId === sideId) ?? (sideId ? undefined : sides[sides.length - 1]); const last = current?.messages[current.messages.length - 1]; useEffect(() => { if (online) void actions.loadSides(session.id).catch(() => {}); }, [online, actions, session.id]); useEffect(() => { end.current?.scrollIntoView({ block: "end" }); }, [current?.messages.length, last?.text.length]); const ask = () => void job.run(async () => { const text = draft.trim(); if (!text) return; const asked = await actions.askSide(session.id, text, current?.sideId); setSideId(asked.sideId); setDraft(""); }); return (

问一个关于这个会话的问题,不打断正在进行的一轮。 {session.agent === "codex" ? `${label} 在只读的临时分叉里回答,可以查看文件,不会改动任何东西;问答不进入会话。` : `${label} 依据会话到现在为止的内容回答,不使用工具;问答不进入会话。`}

{sides.length > 0 && (
{sides.map((entry, index) => ( ))}
)} {current && (
{current.messages.map((message, index) => ( ))}
)}
{ event.preventDefault(); ask(); }} >