Module claude

Module claude 

Source
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; subsequent text_deltas belong to it.
  • stream_event.content_block_start.content_block.type=tool_use — starts an in-flight tool_use; subsequent input_json_deltas accumulate; content_block_stop emits the finalized AgentEvent::ToolUse.
  • stream_event.content_block_delta.delta.type=text_deltaAgentEvent::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 — emits AgentEvent::ToolResult.
  • result.cost_usd + result.usage — emits AgentEvent::Cost followed by AgentEvent::Done. The Done’s response is the explicit result.result field if present, otherwise the accumulated text from streamed text_deltas.

Unknown frame types and malformed shapes produce an empty Vec rather than panicking — the runner falls back to whatever the parallel raw-byte WPS path published, so an unfamiliar frame degrades gracefully.

thinking_delta and message_delta / message_stop are discarded (the agent pane filters them too).

Structs§

ClaudeTranslator
PendingToolUse 🔒

Functions§

handle_assistant_message 🔒
handle_result 🔒
handle_stream_event 🔒
handle_user_message 🔒
now_ms 🔒
parse_usage 🔒