SuperPi.Event.Renderer.OpenAI (super_pi v0.1.0)

Copy Markdown View Source

Renders events as OpenAI chat.completion.chunk maps for the Gateway's SSE stream.

  • text_delta becomes delta.content.
  • thinking_delta becomes delta.reasoning_content.
  • tool_started and tool_completed become short progress lines in delta.reasoning_content, so a client shows tool use without the progress entering the answer text.
  • permission_request becomes a reasoning_content line (a Gateway client cannot answer it, so Permissions fails closed and the tool call is blocked).

Every other event produces no chunk. The first chunk (role) and the closing chunks (stop, usage) belong to the HTTP handler, which knows the usage totals.

Options: :id, :created (Unix seconds), :model.

Summary

Functions

A chunk with an empty delta and a finish_reason, for the handler's closing frame.

The chunk that carries only the assistant role. The handler sends it first.

The usage chunk. It has no choices.

Functions

finish_chunk(st, reason)

@spec finish_chunk(map(), String.t()) :: map()

A chunk with an empty delta and a finish_reason, for the handler's closing frame.

role_chunk(st)

@spec role_chunk(map()) :: map()

The chunk that carries only the assistant role. The handler sends it first.

usage_chunk(st, usage)

@spec usage_chunk(map(), map()) :: map()

The usage chunk. It has no choices.