Pure conversions between Minga's route values (MingaAgent.InferenceRoute.*) and the bridge's session values.
History entries
entries/1 turns Request.messages into MingaClaudeBridge.History entries. The digest_input of each entry keeps exactly what Claude Code saw of the message, in a form that does not depend on how Minga splits or stores it:
- user and tool messages: their text, image, and tool-result parts in order; thinking parts are dropped.
- assistant messages:
{:assistant, text, calls}wheretextjoins every text part andcallslists{id, name, arguments}in order; thinking parts are dropped.
assistant_entry/2 builds the same assistant form from the events the bridge streamed, so the entry recorded after a turn equals the one Minga sends back in the next request.
The fingerprint covers the system prompt, the tool declarations, and the model and effort, because the model and effort are launch flags of the Claude Code process.
Continuations
continuation/1 classifies the messages a request adds to a live session: only tool messages become tool results, only user messages become one prompt, and anything else needs a fresh session.
Fresh sessions (lossy import)
fresh_prompt/1 imports earlier history as one structured transcript text block in front of the newest user input. The import is lossy: thinking and images of earlier messages are left out, and Claude Code sees earlier tool calls and results as text, not as its own tool use. Importing a session JSONL file for --resume would keep them; that is a follow-up.
Summary
Functions
Builds the assistant entry for a streamed reply: its joined text and its tool calls, in order.
Returns the --model value: the model id, or nil for Claude Code's own default.
Classifies the messages a request adds to a live session.
Returns the --effort level for a request, or nil when the selected level is not one the CLI accepts.
Converts request messages to history entries.
Converts one message to a history entry.
Converts a session event to a route event.
The model list shown when Claude Code cannot be probed.
Builds the history fingerprint for a request.
Builds the first prompt of a fresh session: the earlier history as one transcript block, then the newest user input. When the history ends with tool results instead of a user message, the transcript is followed by an instruction to continue.
Converts a model entry of Claude Code's initialize answer to a route model.
Converts a model entry using measured context windows (model id to tokens, see MingaClaudeBridge.Route.Probe.measure/3). A model without a measurement gets 200000 tokens.
Converts tool declarations to the session's tools/list set.
Returns a stable working-directory key for a conversation id.
Types
@type continuation() :: {:tool_results, [MingaClaudeBridge.Session.Request.tool_result()]} | {:prompt, [MingaClaudeBridge.Wire.Block.t()]} | :fresh
Functions
@spec assistant_entry(String.t(), [MingaClaudeBridge.Session.Event.tool_call()]) :: MingaClaudeBridge.History.entry()
Builds the assistant entry for a streamed reply: its joined text and its tool calls, in order.
@spec cli_model(MingaAgent.InferenceRoute.Request.t()) :: String.t() | nil
Returns the --model value: the model id, or nil for Claude Code's own default.
@spec continuation([MingaAgent.InferenceRoute.Message.t()]) :: continuation()
Classifies the messages a request adds to a live session.
@spec effort(MingaAgent.InferenceRoute.Request.t()) :: String.t() | nil
Returns the --effort level for a request, or nil when the selected level is not one the CLI accepts.
@spec entries([MingaAgent.InferenceRoute.Message.t()]) :: [ MingaClaudeBridge.History.entry() ]
Converts request messages to history entries.
@spec entry(MingaAgent.InferenceRoute.Message.t()) :: MingaClaudeBridge.History.entry()
Converts one message to a history entry.
@spec event(MingaClaudeBridge.Session.Event.t()) :: MingaAgent.InferenceRoute.Event.t()
Converts a session event to a route event.
@spec fallback_models() :: [MingaAgent.InferenceRoute.Model.t()]
The model list shown when Claude Code cannot be probed.
@spec fingerprint(MingaAgent.InferenceRoute.Request.t(), String.t() | nil) :: MingaClaudeBridge.History.fingerprint()
Builds the history fingerprint for a request.
@spec fresh_prompt([MingaAgent.InferenceRoute.Message.t()]) :: [ MingaClaudeBridge.Wire.Block.t() ]
Builds the first prompt of a fresh session: the earlier history as one transcript block, then the newest user input. When the history ends with tool results instead of a user message, the transcript is followed by an instruction to continue.
@spec model(map()) :: {:ok, MingaAgent.InferenceRoute.Model.t()} | :error
Converts a model entry of Claude Code's initialize answer to a route model.
@spec model(map(), %{required(String.t()) => pos_integer()}) :: {:ok, MingaAgent.InferenceRoute.Model.t()} | :error
Converts a model entry using measured context windows (model id to tokens, see MingaClaudeBridge.Route.Probe.measure/3). A model without a measurement gets 200000 tokens.
@spec tools([MingaAgent.InferenceRoute.ToolDeclaration.t()]) :: [ MingaClaudeBridge.MCP.tool() ]
Converts tool declarations to the session's tools/list set.
Returns a stable working-directory key for a conversation id.