/** * Subagent card: nested inside a run_subagent card (or as a * standalone card), renders the subsession's full streaming process by following the origin * chain — expanded by default while running, collapsed once finished; nesting inside the card * uses the same rendering recursively. */ import { useEffect, useRef, useState } from "react"; import { S } from "../../lib/strings"; import type { StreamModel } from "../../lib/omni/stream-model"; import { Chevron } from "../../components/ui/chevron"; import { MessageItems } from "./message-stream"; import type { StreamRenderContext } from "./message-stream"; export function SubagentCard({ sessionId, model, running, ctx, }: { sessionId: string; model: StreamModel; running: boolean; ctx: StreamRenderContext; }) { const [open, setOpen] = useState(running); const userToggled = useRef(false); const wasRunning = useRef(running); // Append this card's subsession id to the nesting level: tool cards within the card match // pending approvals by the full origin chain; the running state inside the subsession follows // this card's own running prop, not the parent session's taskRunning. const nestedCtx: StreamRenderContext = { ...ctx, ...(sessionId ? { origin: [...ctx.origin, sessionId] } : {}), taskRunning: running, }; useEffect(() => { // Auto-collapse once finished (respects the user's choice if they manually toggled it). if (wasRunning.current && !running && !userToggled.current) setOpen(false); wasRunning.current = running; }, [running]); return (