MingaClaudeBridge.Route.Mapping (minga_claude_bridge v0.1.0)

Copy Markdown View Source

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} where text joins every text part and calls lists {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

continuation()

@type continuation() ::
  {:tool_results, [MingaClaudeBridge.Session.Request.tool_result()]}
  | {:prompt, [MingaClaudeBridge.Wire.Block.t()]}
  | :fresh

Functions

assistant_entry(text, calls)

Builds the assistant entry for a streamed reply: its joined text and its tool calls, in order.

cli_model(request)

@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.

continuation(messages)

@spec continuation([MingaAgent.InferenceRoute.Message.t()]) :: continuation()

Classifies the messages a request adds to a live session.

effort(request)

@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.

entries(messages)

Converts request messages to history entries.

entry(message)

Converts one message to a history entry.

event(other)

Converts a session event to a route event.

fallback_models()

@spec fallback_models() :: [MingaAgent.InferenceRoute.Model.t()]

The model list shown when Claude Code cannot be probed.

fingerprint(request, effort)

Builds the history fingerprint for a request.

fresh_prompt(messages)

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.

model(entry)

@spec model(map()) :: {:ok, MingaAgent.InferenceRoute.Model.t()} | :error

Converts a model entry of Claude Code's initialize answer to a route model.

model(entry, windows)

@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.

tools(declarations)

Converts tool declarations to the session's tools/list set.

workdir_key(conversation_id)

@spec workdir_key(String.t()) :: String.t()

Returns a stable working-directory key for a conversation id.