# `MingaClaudeBridge.Route.Mapping`
[🔗](https://github.com/jsmestad/minga-claude-bridge/blob/main/lib/minga_claude_bridge/route/mapping.ex#L1)

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.

# `continuation`

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

# `assistant_entry`

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

# `cli_model`

```elixir
@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`

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

Classifies the messages a request adds to a live session.

# `effort`

```elixir
@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`

```elixir
@spec entries([MingaAgent.InferenceRoute.Message.t()]) :: [
  MingaClaudeBridge.History.entry()
]
```

Converts request messages to history entries.

# `entry`

```elixir
@spec entry(MingaAgent.InferenceRoute.Message.t()) ::
  MingaClaudeBridge.History.entry()
```

Converts one message to a history entry.

# `event`

```elixir
@spec event(MingaClaudeBridge.Session.Event.t()) ::
  MingaAgent.InferenceRoute.Event.t()
```

Converts a session event to a route event.

# `fallback_models`

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

The model list shown when Claude Code cannot be probed.

# `fingerprint`

```elixir
@spec fingerprint(MingaAgent.InferenceRoute.Request.t(), String.t() | nil) ::
  MingaClaudeBridge.History.fingerprint()
```

Builds the history fingerprint for a request.

# `fresh_prompt`

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

# `model`

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

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

# `model`

```elixir
@spec model(map(), %{required(String.t()) =&gt; 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`

```elixir
@spec tools([MingaAgent.InferenceRoute.ToolDeclaration.t()]) :: [
  MingaClaudeBridge.MCP.tool()
]
```

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

# `workdir_key`

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

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
