Translates CodexWrapper.JsonLineEvent values from one Codex turn
into GenAgent.Event values. translate_stream/1 preserves arrival
order and remembers the thread_id reported by thread.started,
adding it to the terminal :result as session_id.
Event mapping
thread.started-- captured forthread_id, no GenAgent event emitted directly. The captured id is threaded into the final:resultevent assession_id.turn.started-- filtered.item.completedwithitem.type == "agent_message"-- emits a:textevent with the item's text content and a message boundary.item.completedwithitem.type == "tool_call"or similar -- emits a:tool_useevent. (Exact shape depends on what Codex surfaces; we pass the raw item through in:data.)item.completedwithmcp_tool_call,command_execution, orfile_changeemits:tool_useand:tool_resultwith the full item in both events. This retains IDs, arguments, outputs and completion status.item.started/item.updatedare ignored so each action is counted once.turn.completed-- emits a:usageevent (if token counts are present) followed by a terminal:resultevent carrying the capturedthread_idassession_id.errororturn.failed-- emits a terminal:errorevent.- Unknown event types -- filtered.
If a turn's event list contains no turn.completed and no error
event, the translator emits nothing terminal. The state machine's
no_terminal_event guard will then deliver {:error, :no_terminal_event}
to the caller.
Summary
Functions
Translate a full turn's worth of events.
Translate events as they arrive while retaining the thread ID for the terminal event.
Functions
@spec translate([CodexWrapper.JsonLineEvent.t()]) :: [GenAgent.Event.t()]
Translate a full turn's worth of events.
@spec translate_stream(Enumerable.t()) :: Enumerable.t()
Translate events as they arrive while retaining the thread ID for the terminal event.