Skip to main content

parse_opencode_event

Function parse_opencode_event 

Source
pub fn parse_opencode_event(line: &str) -> Option<StreamEvent>
Expand description

Parse a line of OpenCode JSON output into a StreamEvent

OpenCode CLI (opencode run --format json) outputs newline-delimited JSON events with the following structure:

  • {"type": "assistant", "message": {"content": [{"text": "..."}]}} - Text output
  • {"type": "tool_call", "subtype": "started", "tool_call": {"name": "...", "input": {...}}} - Tool start
  • {"type": "tool_call", "subtype": "completed", "tool_call": {...}, "result": {...}} - Tool result
  • {"type": "result", "success": true} - Completion
  • {"type": "error", "message": "..."} - Error
  • {"type": "session", "session_id": "..."} - Session assignment

Returns None for unparseable or unknown event types (graceful degradation).