Expand description
Claude Code stream-json → AgentEvent translator.
Mirrors the frontend reference implementation at
frontend/app/view/agent/providers/claude-translator.ts so the
drone Agent block can consume the same stream without
round-tripping through the renderer. Handled frames:
stream_event.content_block_start.content_block.type=text— starts a text block; subsequenttext_deltas belong to it.stream_event.content_block_start.content_block.type=tool_use— starts an in-flight tool_use; subsequentinput_json_deltas accumulate;content_block_stopemits the finalizedAgentEvent::ToolUse.stream_event.content_block_delta.delta.type=text_delta—AgentEvent::AssistantText(also accumulated into the final response).stream_event.content_block_delta.delta.type=input_json_delta— appends to the pending tool_use’s partial_json.stream_event.content_block_stop— flushes the pending tool_use.user.message.content[].type=tool_result— emitsAgentEvent::ToolResult.stream_event.message_startwithmessage.role=user— sametool_resultextraction as above (Anthropic sometimes carries tool results here instead of a top-leveluserframe; mirrors TS’shandleMessageStart).result.cost_usd+result.usage— emitsAgentEvent::Cost. Then, ifresult.is_erroris true, emitsAgentEvent::Error(mirrors TS’serror_result); otherwise emitsAgentEvent::Donewhoseresponseis the explicitresult.resultfield if present, otherwise the accumulated text from streamed text_deltas.system.subtype=compact_boundary— emitsAgentEvent::CompactionBoundarywith the exact trigger/token/ duration data fromcompact_metadata(stdout, snake_case) orcompactMetadata(transcript, camelCase). Othersystemsubtypes are still discarded. Seedocs/specs/SPEC_COMPACTION_DETECTION_AND_HANDLING_2026_07_31.md§4.1 — this used to be silently dropped as an unhandledsystemframe.
Unknown frame types and malformed shapes produce an empty Vec
rather than panicking — the runner falls back to whatever the
parallel raw-byte MPS path published, so an unfamiliar frame
degrades gracefully.
thinking_delta, message_delta / message_stop are discarded
(the agent pane filters them too). rate_limit_event (TS:
provider_waiting) is also currently discarded — surfacing it
here would need a new AgentEvent variant, and types.rs
explicitly reserves that decision rather than shipping it
casually; left as a deliberate follow-up, not an oversight.
Structs§
Functions§
- extract_
tool_ 🔒results - Shared by
handle_user_message(top-leveluserframes) and themessage_startcase inhandle_stream_event— both carrytool_resultblocks in the samecontentarray shape. - field 🔒
obj[snake], elseobj[camel].- handle_
assistant_ 🔒message - handle_
result 🔒 - handle_
stream_ 🔒event - handle_
system_ 🔒message type: "system"frames cover several subtypes; today we only act oncompact_boundary(seedocs/specs/SPEC_COMPACTION_DETECTION_AND_HANDLING_2026_07_31.md§4.1). Any other subtype — or acompact_boundaryframe missing its metadata / carrying malformed fields — produces no event rather than a bad one, matching this file’s existing philosophy (see the module doc comment).- handle_
user_ 🔒message - parse_
usage 🔒