# v0.16.0 — MiMo provider + anthropic-compat shared core

Xiaomi MiMo joins the builtin provider lineup, accessed through MiMo's Anthropic API–compatible endpoint. To make the integration clean, `anthropic.ts`'s wire-format / SSE / fetch core was lifted into a reusable shared module that mirrors the existing OpenAI-compat shared core. Future Anthropic-compatible providers (Bedrock, Vertex, custom proxies) plug in with a 15-line wrapper instead of a fork.

## MiMo (小米) provider

```
Provider: MiMo (小米)
Base URL: https://api.xiaomimimo.com
Endpoint: /anthropic/v1/messages
Auth:     Authorization: Bearer <key>
```

Five chat models are registered (TTS variants are excluded — they don't implement `/v1/messages`):

| Model | Context | Vision | Tools |
|---|---|---|---|
| `mimo-v2.5-pro` | 1M | – | ✓ |
| `mimo-v2.5` | 1M | ✓ | ✓ |
| `mimo-v2-pro` | 1M | – | ✓ |
| `mimo-v2-omni` | 256K | ✓ | ✓ |
| `mimo-v2-flash` | 256K | – | ✓ |

Drop your key into Settings, pick a model, send a message. Streaming + tool calling work out of the box; the wire format is byte-for-byte Anthropic.

## `_shared/anthropic-compat-core.ts`

The new shared core exposes four hooks, mirroring the openai-compat-core pattern:

```ts
interface AnthropicCompatHooks {
  endpointPath?: string;          // default "/v1/messages"
  authHeaders?: (c) => Record<string, string>;
                                  // default: x-api-key + anthropic-version
  customHeaders?: (c) => Record<string, string>;
  promptCache?: boolean;          // default false — cache_control ephemeral
}
```

`anthropic.ts` is now a 15-line wrapper that opts into `promptCache: true` (Anthropic native preserves the existing cache_control breakpoints on system + last tool). `mimo.ts` is a 15-line wrapper that overrides `endpointPath` to `/anthropic/v1/messages` and `authHeaders` to `Authorization: Bearer`. No other diff between them.

The hook surface also paid for a real bug fix: `ToolResultBlock` IR carries `toolUseId` / `isError` (camelCase) but the Anthropic wire format requires `tool_use_id` / `is_error`. `toWireMessages` was passing the block through verbatim, so the IR field names landed on the wire. Anthropic was silently tolerating the unknown fields; MiMo's stricter validator rejected the request with `tool_result block missing tool_use_id`. The shared core now translates these fields, matching what openai-compat and gemini already do for the same IR.

## Naming consistency

`OpenAICompatHooks.authHeader` (singular) is renamed to `authHeaders` (plural) so both shared cores share a hook vocabulary. The plural form is also more accurate — the hook returns a `Record<string, string>` of multiple headers. No production callers were affected (all OpenAI-compat providers use the Bearer default).

## Manifest

Adds `https://api.xiaomimimo.com/*` to `host_permissions`. Existing Anthropic / OpenAI / DeepSeek / OpenRouter / MiniMax / ZhiPu / Bailian / Gemini entries are unchanged.

## Files of note

- `src/lib/model-router/providers/_shared/anthropic-compat-core.ts` — NEW (247 lines)
- `src/lib/model-router/providers/mimo.ts` — NEW (15 lines)
- `src/lib/model-router/providers/anthropic.ts` — rewritten as thin wrapper (265 → 16 lines, test-only exports preserved)
- `manifest.json` — host_permission added

## Tests

- 1204/1204 tests pass (was 1190 pre-PR; +14 from hook coverage, MiMo wrapper, registry coverage, and the `tool_use_id` regression test)
- `pnpm build` succeeds; manifest invariants green
- Existing `anthropic.test.ts` passes without modification — it remains the regression net for the extraction

## 中文摘要

v0.16.0 接入小米 **MiMo** provider，走 MiMo 的 Anthropic 兼容端点 `/anthropic/v1/messages`，Bearer 鉴权。内置 5 个 chat 模型：`mimo-v2.5-pro`、`mimo-v2.5`、`mimo-v2-pro`、`mimo-v2-omni`、`mimo-v2-flash`（TTS 系列不接 `/v1/messages` 故排除）。Settings 里粘贴 API key、选模型即用，streaming + tool calling 现成可用。

技术上把原 `anthropic.ts` 的 wire-format / SSE / fetch 核心抽进了新的 `_shared/anthropic-compat-core.ts`，对称于已有的 `_shared/openai-compat-core.ts`。共享 core 暴露 4 个 hooks（`endpointPath` / `authHeaders` / `customHeaders` / `promptCache`），让 Anthropic native 和 MiMo 各自走 ~15 行 wrapper 即可，将来接 Bedrock / Vertex / 自建代理也不需要 fork 代码。

重构过程中顺手修了一个 pre-existing bug：`ToolResultBlock` IR 用 camelCase 字段 (`toolUseId` / `isError`)，但 Anthropic wire 要求 snake_case (`tool_use_id` / `is_error`)。原来直接 pass-through，Anthropic 服务端宽松忍了，MiMo 严格校验暴露出来 —— 现在补上字段翻译，与 openai-compat / gemini 一致。

附带把 `OpenAICompatHooks.authHeader` (单数) 改成 `authHeaders` (复数)，让两个 shared core 的 hook 词汇对齐；无生产 caller 受影响。
