import { useStreamContext as useAgentThreadStream, useToolCalls } from "@langchain/react" import { Check, Loader2, X } from "lucide-react" function humanizeToolName(name: string): string { return name.replace(/_/g, " ").trim() || "tool" } /** * Live status for a single subagent, read straight from the SDK's scoped * `tools` projection (`useToolCalls(stream, { namespace })`). The namespace * comes from `stream.subagents` (attached to the `task` chunk by * `streamMessagesToUi`), so this subscribes to exactly the subagent that the * parent card represents. * * Hotfix: rather than listing every nested tool call (which balloons the card), * this shows a single line with the subagent's current activity plus a running * step count. A richer activity UI will replace this later. * * Mounting opens a ref-counted subscription scoped to `namespace`; unmounting * closes it. Only mounted from {@link SubagentCard} when * `useIsInAgentThreadStream()` is true, so the `useStreamContext` read is * always inside a `StreamProvider`. */ export function SubagentActivity({ namespace }: { namespace: Array }) { const stream = useAgentThreadStream() const toolCalls = useToolCalls(stream, { namespace }) const current = toolCalls[toolCalls.length - 1] if (!current) return null const stepCount = toolCalls.length return (
{current.status === "finished" ? ( ) : current.status === "error" ? ( ) : ( )} {humanizeToolName(current.name)} {stepCount} {stepCount === 1 ? "step" : "steps"}
) }