feat(ui): render streaming Agent tool calls as Agent cards with nested child grouping

Support Agent card rendering during live streaming responses for Claude
Code, Codex CLI, and OpenCode. Previously Agent cards only rendered for
loaded/historical messages parsed from the DB.

- Fix tool name inference: subagent_type in input now returns "agent"
  instead of "task"; add spawn_agent/wait_agent/close_agent aliases
- Group sub-agent tool calls inside parent Agent cards during streaming
  using position-based heuristic (ACP SDK lacks parent_id tracking)
- Clean raw Agent output (JSON content blocks, XML task_result wrappers)
- Emit agent_stats with nested tool calls so AgentToolCallPart renders
  child execution inline, matching the loaded message appearance
This commit is contained in:
xintaofei
2026-04-17 01:28:13 +08:00
parent 488b0c2e53
commit 4189aa04de
2 changed files with 166 additions and 10 deletions

View File

@@ -50,6 +50,9 @@ const EXACT_TOOL_NAME_ALIASES: Record<string, string> = {
browser_action: "webfetch",
use_mcp_tool: "tool",
// Codex
spawn_agent: "agent",
wait_agent: "task",
close_agent: "task",
update_plan: "task",
request_user_input: "question",
// OpenCode
@@ -197,7 +200,10 @@ function inferFromInput(
if (hasAnyKey(parsed, ["question"])) return "question"
if (hasAnyKey(parsed, ["subagent_type", "taskId", "task_id", "subject"])) {
if (hasAnyKey(parsed, ["subagent_type"])) {
return "agent"
}
if (hasAnyKey(parsed, ["taskId", "task_id", "subject"])) {
return "task"
}