GenAgent.Backends.Codex.EventTranslator (GenAgentCodex v0.2.2)

Copy Markdown View Source

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 for thread_id, no GenAgent event emitted directly. The captured id is threaded into the final :result event as session_id.
  • turn.started -- filtered.
  • item.completed with item.type == "agent_message" -- emits a :text event with the item's text content.
  • item.completed with item.type == "tool_call" or similar -- emits a :tool_use event. (Exact shape depends on what Codex surfaces; we pass the raw item through in :data.)
  • item.completed with mcp_tool_call, command_execution, or file_change emits :tool_use and :tool_result with the full item in both events. This retains IDs, arguments, outputs and completion status. item.started/item.updated are ignored so each action is counted once.
  • turn.completed -- emits a :usage event (if token counts are present) followed by a terminal :result event carrying the captured thread_id as session_id.
  • error or turn.failed -- emits a terminal :error event.
  • 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

translate(events)

@spec translate([CodexWrapper.JsonLineEvent.t()]) :: [GenAgent.Event.t()]

Translate a full turn's worth of events.

translate_stream(events)

@spec translate_stream(Enumerable.t()) :: Enumerable.t()

Translate events as they arrive while retaining the thread ID for the terminal event.