@penguinharness/agent-development 0.2.11 → 0.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,29 +1,30 @@
1
1
  ---
2
2
  name: unified-llm-api
3
- description: Call model APIs through @prismshadow/agenthub — streaming text generation, image generation, speech synthesis, embeddings and the supported-model registry with one client.
3
+ description: Call model APIs through @prismshadow/mmsp (MMSP) — streaming text generation, image generation, speech synthesis, embeddings and the supported-model registry with one client.
4
+ version: 2026.10.10.1
4
5
  ---
5
6
 
6
- # Unified LLM API (AgentHub)
7
+ # Unified LLM API (MMSP)
7
8
 
8
- `@prismshadow/agenthub` is a unified TypeScript client for model APIs: streaming text, image generation, speech synthesis and embeddings behind one entry point.
9
+ `@prismshadow/mmsp` — MMSP, the Model Message Stream Protocol, formerly `@prismshadow/agenthub` — is a unified TypeScript client for model APIs: one message format and one streaming grammar for text, image generation, speech synthesis and embeddings, behind one entry point.
9
10
 
10
11
  ```bash
11
- npm install @prismshadow/agenthub
12
+ npm install @prismshadow/mmsp
12
13
  ```
13
14
 
14
15
  The main entry point is `AutoLLMClient`:
15
16
 
16
17
  ```ts
17
- import { AutoLLMClient } from "@prismshadow/agenthub";
18
+ import { AutoLLMClient } from "@prismshadow/mmsp";
18
19
 
19
20
  const client = new AutoLLMClient({ model: "<model_id>", apiKey: "<key>", baseUrl: "<url>", clientType: "<type>" });
20
21
  ```
21
22
 
22
- `apiKey`, `baseUrl` and `clientType` are optional (see routing below). The package also exports `listSupportedModels` (the model registry) and the error classes `AgentHubError`, `UnsupportedParameterError`, `EmptyResponseError` and `ToolCallArgumentParseError`.
23
+ `apiKey`, `baseUrl` and `clientType` are optional (see [Routing and credentials](#routing-and-credentials)); `defaultHeaders` adds request headers. The package also exports `listSupportedModels` (the model registry), `normalizeLegacyMessages`, the `ThinkingLevel` / `PromptCaching` enums, the message and event types, and the error classes (see [Errors](#errors)).
23
24
 
24
25
  ## Before you start
25
26
 
26
- If the user's message only invokes this skill (e.g. "use agenthub-models skill") without a concrete task, ask the user what they want to build. Do not write code until the requirement is clear.
27
+ If the user's message only invokes this skill (e.g. "use unified-llm-api skill") without a concrete task, ask the user what they want to build. Do not write code until the requirement is clear.
27
28
 
28
29
  **Important prerequisite — set the key up first, then develop.** When the script is an AI app you are building for the user, have them add the model API key in **this agent's key vault** (gear icon on its card, Agents page → settings → key vault tab) *before* you start, so the credential is in your shell environment. If the app stores its own model config, keep its Penguin data root **inside the CWD workspace** (`--root ./penguin_data`), never `~/.penguin`. Model ids can come from the penguin CLI catalog and the id table below.
29
30
 
@@ -41,39 +42,35 @@ Keep model API keys **project-local**: for an app that stores its own model conf
41
42
 
42
43
  ## Model IDs
43
44
 
44
- Use exact model ids. If an id is not in the table below and the user has not given one, ask the user to confirm the exact id before writing code.
45
-
46
- | Family | Official IDs | Gateway variants |
47
- | ---------------- | --------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
48
- | Gemini 3.8 | `gemini-3.8-flash` | OpenRouter `google/gemini-3.8-flash` |
49
- | Gemini 3.7 | `gemini-3.7-flash` | OpenRouter `google/gemini-3.7-flash` |
50
- | Gemini 3.6 | `gemini-3.6-flash`, `gemini-3.5-flash-lite` | — |
51
- | Gemini 3 | `gemini-3.1-pro-preview`, `gemini-3.5-flash`, `gemini-3.1-flash-lite` | — |
52
- | Gemini 3 image | `gemini-3.1-flash-image`, `gemini-3-pro-image-preview` | — |
53
- | Gemini 3 TTS | `gemini-3.1-flash-tts-preview` | — |
54
- | Gemini embedding | `gemini-embedding-2` | — |
55
- | Claude 5 | `claude-fable-5`, `claude-opus-5`, `claude-sonnet-5` | OpenRouter `anthropic/claude-fable-5`, `anthropic/claude-opus-5`, `anthropic/claude-sonnet-5` |
56
- | Claude 4 | `claude-sonnet-4-6`, `claude-opus-4-7`, `claude-opus-4-8` | OpenRouter `anthropic/claude-opus-4.8`, `anthropic/claude-opus-4.7` |
57
- | GPT-6 | `gpt-6-astra` | OpenRouter `openai/gpt-6-astra` |
58
- | GPT-5.6 | `gpt-5.6` (routes to sol), `gpt-5.6-terra`, `gpt-5.6-luna` | OpenRouter `openai/gpt-5.6-sol`, `openai/gpt-5.6-terra`, `openai/gpt-5.6-luna` |
59
- | GPT-5.5 / 5.4 | `gpt-5.5`, `gpt-5.4`, `gpt-5.4-mini`, `gpt-5.4-nano` | OpenRouter `openai/gpt-5.5`, `openai/gpt-5.5-pro`, `openai/gpt-5.4`, `openai/gpt-5.4-mini`, `openai/gpt-5.4-nano`, `openai/gpt-5.4-pro` |
60
- | OpenAI embedding | `text-embedding-3-small`, `text-embedding-3-large` | — |
61
- | MiniMax M3 | `MiniMax-M3` | OpenRouter `minimax/minimax-m3` |
62
- | Kimi K3 | `kimi-k3` | OpenRouter `moonshotai/kimi-k3` |
63
- | Kimi K2.7 Code | — | SiliconFlow `moonshotai/Kimi-K2.7-Code`; Fireworks AI `accounts/fireworks/models/kimi-k2p7-code` |
64
- | Kimi K2.6 | `kimi-k2.6` | OpenRouter `moonshotai/kimi-k2.6`; SiliconFlow `Pro/moonshotai/Kimi-K2.6` |
65
- | DeepSeek V4 | `deepseek-flash`, `deepseek-v4-pro`, `deepseek-v4-flash`, `deepseek-v4-flash-vision-exp` | OpenRouter `deepseek/deepseek-v4.1-flash`, `deepseek/deepseek-v4-pro-0813`, `deepseek/deepseek-v4-pro`, `deepseek/deepseek-v4-flash`, `deepseek/deepseek-v4-flash-0731`, `deepseek/deepseek-v4-flash-vision-exp`; Fireworks AI `accounts/fireworks/models/deepseek-v4-flash-0731`; SiliconFlow `deepseek-ai/DeepSeek-V4-Pro`, `deepseek-ai/DeepSeek-V4-Flash` |
66
- | GLM 5.3 | `glm-5.3`, `glm-5.3-flash` | OpenRouter `z-ai/glm-5.3`, `z-ai/glm-5.3-flash` |
67
- | GLM 5.2 | `glm-5.2` | OpenRouter `z-ai/glm-5.2`; SiliconFlow `zai-org/GLM-5.2` |
68
- | GLM 5.1 | `glm-5.1` | — |
69
- | Qwen 3.8 Max | — | OpenRouter `qwen/qwen3.8-max` |
70
- | Qwen 3.8 Flash | — | Qwen DashScope `qwen3.8-flash` |
71
- | Qwen 3.6 | — | OpenRouter `qwen/qwen3.6-35b-a3b`; SiliconFlow `Qwen/Qwen3.6-35B-A3B` |
72
- | Inkling | — | OpenRouter `thinkingmachines/inkling`; Fireworks AI `accounts/fireworks/models/inkling` |
45
+ Use exact model ids. If an id is not in the table below and the user has not given one, ask the user to confirm the exact id before writing code. Official ids route on their own; every gateway id needs an explicit `clientType` (see [Routing and credentials](#routing-and-credentials)).
46
+
47
+ | Family | Official IDs | Gateway variants |
48
+ | ---------------------- | ------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
49
+ | Gemini 3.8 / 3.7 / 3.6 | `gemini-3.8-flash`, `gemini-3.7-flash`, `gemini-3.6-flash`, `gemini-3.5-flash-lite` | OpenRouter `google/gemini-3.8-flash`, `google/gemini-3.7-flash` |
50
+ | Gemini 3 | `gemini-3.1-pro-preview`, `gemini-3.5-flash`, `gemini-3.1-flash-lite` | — |
51
+ | Gemini image | `gemini-3.1-flash-image`, `gemini-3.1-flash-lite-image`, `gemini-3-pro-image` | — |
52
+ | Gemini TTS | `gemini-3.8-flash-tts`, `gemini-3.8-flash-lite-tts`, `gemini-3.1-flash-tts-preview` | — |
53
+ | Gemini embedding | `gemini-embedding-2` | — |
54
+ | Claude 5.5 / Fable 5.1 | `claude-opus-5-5`, `claude-sonnet-5-5`, `claude-haiku-5-5`, `claude-fable-5-1` | OpenRouter `anthropic/claude-opus-5.5`, `anthropic/claude-sonnet-5.5`, `anthropic/claude-haiku-5.5`, `anthropic/claude-fable-5.1` |
55
+ | Claude 5 | `claude-fable-5`, `claude-opus-5`, `claude-sonnet-5` | OpenRouter `anthropic/claude-fable-5`, `anthropic/claude-opus-5`, `anthropic/claude-sonnet-5` |
56
+ | Claude 4 | `claude-sonnet-4-6`, `claude-opus-4-7`, `claude-opus-4-8` | OpenRouter `anthropic/claude-opus-4.8`, `anthropic/claude-opus-4.7` |
57
+ | GPT-6 | `gpt-6.1-sol`, `gpt-6-astra` | OpenRouter `openai/gpt-6.1-sol`, `openai/gpt-6-astra` |
58
+ | GPT-5.6 | `gpt-5.6` (routes to sol), `gpt-5.6-sol`, `gpt-5.6-terra`, `gpt-5.6-luna` | OpenRouter `openai/gpt-5.6-sol`, `openai/gpt-5.6-terra`, `openai/gpt-5.6-luna` |
59
+ | GPT-5.5 / 5.4 | `gpt-5.5`, `gpt-5.4`, `gpt-5.4-mini`, `gpt-5.4-nano` | OpenRouter `openai/gpt-5.5`, `openai/gpt-5.5-pro`, `openai/gpt-5.4`, `openai/gpt-5.4-mini`, `openai/gpt-5.4-nano`, `openai/gpt-5.4-pro` |
60
+ | OpenAI embedding | `text-embedding-3-small`, `text-embedding-3-large` | — |
61
+ | MiniMax M3 | `MiniMax-M3` | OpenRouter `minimax/minimax-m3` |
62
+ | Kimi K3 / K2.6 | `kimi-k3`, `kimi-k2.6` | OpenRouter `moonshotai/kimi-k3`, `moonshotai/kimi-k2.6`; SiliconFlow `Pro/moonshotai/Kimi-K2.6` |
63
+ | Kimi K2.7 Code | — | SiliconFlow `moonshotai/Kimi-K2.7-Code`; Fireworks AI `accounts/fireworks/models/kimi-k2p7-code` |
64
+ | DeepSeek V4 | `deepseek-flash`, `deepseek-v4-pro` | OpenRouter `deepseek/deepseek-v4.1-flash`, `deepseek/deepseek-v4-pro-0813`, `deepseek/deepseek-v4-pro`, `deepseek/deepseek-v4-flash`, `deepseek/deepseek-v4-flash-0731`, `deepseek/deepseek-v4-flash-vision-exp`; Fireworks AI `accounts/fireworks/models/deepseek-v4p1-flash`, `accounts/fireworks/models/deepseek-v4-pro-0813`, `accounts/fireworks/models/deepseek-v4-flash-0731`; SiliconFlow `deepseek-ai/DeepSeek-V4-Pro`, `deepseek-ai/DeepSeek-V4-Flash` |
65
+ | GLM 5.3 / 5.2 / 5.1 | `glm-5.3`, `glm-5.3-flash`, `glm-5.2`, `glm-5.1` | OpenRouter `z-ai/glm-5.3`, `z-ai/glm-5.3-flash`, `z-ai/glm-5.2`; SiliconFlow `zai-org/GLM-5.2` |
66
+ | Qwen 3.8 Max | — | OpenRouter `qwen/qwen3.8-max` |
67
+ | Qwen 3.8 Flash | — | Qwen DashScope `qwen3.8-flash` |
68
+ | Qwen 3.6 | — | OpenRouter `qwen/qwen3.6-35b-a3b`; SiliconFlow `Qwen/Qwen3.6-35B-A3B` |
69
+ | Inkling | — | OpenRouter `thinkingmachines/inkling`; Fireworks AI `accounts/fireworks/models/inkling` |
73
70
 
74
71
  The image endpoint dropped its preview suffix: `gemini-3.1-flash-image-preview` is deprecated, use `gemini-3.1-flash-image`.
75
72
 
76
- `glm-5.3-flash` is the one GLM model that reads images (`@prismshadow/agenthub` >= 0.4.8). The GLM client sends an `image_url` item as an `image_url` part, in a prompt and in a tool result alike, and both an HTTP(S) URL and a base64 data URL pass through unchanged. The version match is case-insensitive, so the gateway spellings `z-ai/glm-5.3-flash` and `zai-org/GLM-5.3-Flash` are recognised too. Every other GLM id refuses an image rather than dropping it — `GLM <id> does not support image inputs.` in a prompt, `GLM <id> does not support images in tool results.` in a tool result — and that includes `glm-5v-turbo`.
73
+ `glm-5.3-flash` is the one GLM model that reads images: `zai-official` sends an `image_url.done` item as an `image_url` part, in a prompt and in a tool result alike (an HTTP(S) URL and a base64 data URL both pass through), and matches the version case-insensitively, so the gateway spellings `z-ai/glm-5.3-flash` and `zai-org/GLM-5.3-Flash` count too. Every other GLM id refuses an image rather than dropping it (`GLM <id> does not support image inputs.`), `glm-5v-turbo` included.
77
74
 
78
75
  Gateway model lists can be queried online:
79
76
 
@@ -84,57 +81,112 @@ curl --request GET --url https://api.siliconflow.cn/v1/models --header 'Authoriz
84
81
 
85
82
  ## Supported-model registry
86
83
 
87
- `listSupportedModels(currency?)` returns the models AgentHub itself knows how to route, so ids, endpoints, modalities, context windows and prices can be read from the package instead of being hardcoded:
84
+ `listSupportedModels(currency?)` returns the models MMSP curates, so ids, endpoints, modalities, context windows and prices can be read from the package instead of being hardcoded:
88
85
 
89
86
  ```ts
90
- import { listSupportedModels } from "@prismshadow/agenthub";
87
+ import { listSupportedModels } from "@prismshadow/mmsp";
91
88
 
92
89
  for (const m of listSupportedModels()) {
93
90
  console.log(m.model, m.base_url, m.client, m.context_window, m.pricing?.prompt_tokens);
94
91
  }
95
92
  ```
96
93
 
97
- - Each `SupportedModel` is `{ model, base_url, client, input_modalities, output_modalities, context_window?, pricing? }`. The `(model, base_url, client)` triple maps straight onto the constructor: `new AutoLLMClient({ model, baseUrl: base_url, clientType: client })`.
98
- - Modalities are `"Text" | "Image" | "Video" | "Audio" | "Embed"`. Coverage includes the official vendor endpoints plus the OpenRouter and SiliconFlow gateways; `context_window` and `pricing` are omitted where the platform publishes no authoritative value (image and TTS models, for instance).
99
- - `pricing` is per million tokens, keyed by the same usage buckets as `usage_metadata`: `prompt_tokens` (non-cached input), `thoughts_tokens` / `response_tokens` (both the output price) and optional `cached_tokens` (cache-hit price). Values are stored in USD; pass `listSupportedModels("CNY")` to convert at 7 CNY/USD.
94
+ - Each `SupportedModel` is `{ model, base_url, client, input_modalities, output_modalities, context_window?, pricing? }`. The `(model, base_url, client)` triple maps straight onto the constructor: `new AutoLLMClient({ model, baseUrl: base_url, clientType: client })` — `client` is the client type MMSP pairs with that id, gateway ids included.
95
+ - Modalities are `"Text" | "Image" | "Video" | "Audio" | "Embed"`. Coverage includes the official vendor endpoints plus the OpenRouter and SiliconFlow gateways; `context_window` and `pricing` are omitted where the platform publishes no authoritative value.
96
+ - `pricing` is the list price per million tokens (a running promotion is not recorded), keyed by the usage buckets of `usage_metadata`: `prompt_tokens` (non-cached input), `thoughts_tokens` / `response_tokens` (both the output price) and optional `cached_tokens` (cache-hit price). Values are stored in USD; `listSupportedModels("CNY")` converts at 7 CNY/USD.
100
97
 
101
- The registry is the curated current line-up, so prefer it when picking a model or estimating cost. It is not the routing table, and it lags in both directions: older ids in the table above (`gpt-5.4`, `claude-opus-4-7`, `gemini-3.1-pro-preview`, `gemini-3.1-flash-lite`) still route fine without appearing in it, and a newly launched id can route before the registry carries it. For an id the registry omits, take the context window and price from the vendor's own page.
98
+ The registry is the curated current line-up, not the routing table: any id of a known family routes whether or not the registry lists it. For an id it omits, take the context window and price from the vendor's own page.
102
99
 
103
100
  ## Routing and credentials
104
101
 
105
- - Without `clientType`, the client auto-routes by model id substring, in this order: `minimax-m3` (exact), `gemini-3*` / `gemini-embedding`, `claude` 4-6/4-7/4-8/-5, `gpt-5.4`/`gpt-5.5`/`gpt-5.6`/`gpt-6`, `glm-5` (whole series, 5.3 included), `kimi-k3`/`kimi-k2.5`/`kimi-k2.6`, `deepseek-v4`, `ant-messages`, `openai-responses`, `openai`+`embedding` (embeddings), `openai` (chat). Ids matching none of these throw. Most gateway variants in the table above hit the same substrings, so they route to the right family — just set `baseUrl` to the gateway endpoint.
106
- - Three generic protocol clients cover everything else (all take `baseUrl` + `apiKey`):
107
- - `clientType: "openai-chat"` — any OpenAI Chat Completions compatible endpoint (gateway models, Qwen via OpenRouter/SiliconFlow or DashScope `https://dashscope.aliyuncs.com/compatible-mode/v1`, local vLLM, …). Renamed from `openai` in AgentHub 0.4.2; the bare `openai` string still routes as a deprecated alias.
108
- - `clientType: "openai-responses"` — OpenAI Responses-compatible endpoints (OpenAI, OpenRouter, DeepSeek, Z.AI, MiniMax all serve one).
109
- - `clientType: "ant-messages"` — Anthropic Messages-compatible endpoints (Anthropic, OpenRouter `https://openrouter.ai/api`, DeepSeek `https://api.deepseek.com/anthropic`, Z.AI, MiniMax).
110
- - Exception: an id served by an OpenAI-compatible gateway that still matches a first-party substring (e.g. OpenRouter's `google/gemini-3.7-flash`, `anthropic/claude-sonnet-5` or `openai/gpt-5.6-sol` on the `/api/v1` endpoint) would auto-route to the vendor protocol client — and a dotted id like `anthropic/claude-opus-4.8` matches nothing and throws. Always pass an explicit `clientType` for gateway ids; never rely on the id. Routing reads `clientType` (or the model id) as a plain lowercased string and never looks at `baseUrl`, so the vendor prefix gives no protection.
111
- - OpenRouter serves both protocols at `https://openrouter.ai/api/v1`, so its `openai/*` ids work with `clientType: "openai-responses"` as well as `"openai-chat"`; use Responses when you want reasoning items round-tripped.
112
- - The first-party `deepseek-v4` client posts to `{baseUrl}/responses` (AgentHub 0.4.6 moved it off Chat Completions). A self-hosted endpoint serving a `deepseek-v4*` id over Chat Completions must therefore pass `clientType: "openai-chat"` explicitly rather than rely on id routing.
113
- - API key: constructor parameter first, then the provider environment variable — `DEEPSEEK_API_KEY`, `ANTHROPIC_API_KEY` (also for `ant-messages`), `OPENAI_API_KEY` (also for `openai-chat`/`openai-responses`), `GEMINI_API_KEY`, `ZAI_API_KEY`, `MOONSHOT_API_KEY`, `MINIMAX_API_KEY`. Base URLs read the same names with `_BASE_URL`.
102
+ **Client types.** `clientType` names one client:
114
103
 
115
- ## Streaming text
104
+ - **Official** clients speak their vendor's own API: `openai-official` (Responses API; `text-embedding-*` ids go to the Embeddings API), `anthropic-official` (Messages; a `bedrock://<region>` base URL reaches Bedrock), `google-official` (Interactions API only; a Vertex AI service-account JSON key is refused with an error naming `google-genai`; `gemini-official`, its name before 0.5.2, is kept as an alias), `zai-official` and `moonshot-official` (Chat Completions), `deepseek-official` and `minimax-official` (Responses API).
105
+ - **Compatible** clients speak one wire protocol for any endpoint that serves it: `openai-responses`, `openai-chat` (the bare `openai` is an alias), `openai-chat-vllm-adapter` (Chat Completions plus the served model's thinking switch), `openai-embedding`, `ant-messages` (Anthropic Messages), `google-genai` (Google's generateContent as the Google GenAI SDK speaks it — Vertex AI with a service-account JSON key as `apiKey`, the Gemini API, or a relay; `gemini-generate-content` is its 0.5.0 name, kept as an alias), `mmsp` (an MMSP server, which serves the models of its table and keeps the upstream keys; base URL `http://127.0.0.1:25752/v1` by default).
106
+
107
+ **Routing by prefix.** Without `clientType` (or the `CLIENT_TYPE` environment variable), the family the lowercased model id begins with names its official client: `gpt-` and `text-embedding-` → `openai-official`, `claude-` → `anthropic-official`, `gemini-` → `google-official`, `glm-` → `zai-official`, `kimi-` → `moonshot-official`, `deepseek-` → `deepseek-official`, `minimax-` → `minimax-official`. Any other id throws at construction: `No client for model "<id>": its family is not known. Pass clientType, one of the official clients: …; compatible clients: …`. An unknown client type throws `Unknown client type "<type>". Pass one of the …`. Routing never looks at `baseUrl`.
108
+
109
+ **Renamed in 0.5.0.** The 0.4.x vendor client types no longer exist, and a model id passed as `clientType` no longer works; the compatible client types are unchanged. The table gives the 0.5.2 names; 0.5.0 and 0.5.1 called the Gemini client `gemini-official`.
110
+
111
+ | 0.4.x `clientType` | 0.5.0 |
112
+ | ------------------------------------------------------------------------------------------------- | -------------------- |
113
+ | `gpt-6`, `gpt-5.6`, `gpt-5.5`, `gpt-5.4` | `openai-official` |
114
+ | `claude-5`, `claude-4-8`, `claude-4-7`, `claude-4-6` | `anthropic-official` |
115
+ | `gemini-3.8`, `gemini-3.7`, `gemini-3.6`, `gemini-3`, `gemini-embedding`, `gemini-interactions` | `google-official` |
116
+ | `glm-5.3`, `glm-5.2`, `glm-5.1` | `zai-official` |
117
+ | `kimi-k3`, `kimi-k2.6`, `kimi-k2.5` | `moonshot-official` |
118
+ | `deepseek-v4` | `deepseek-official` |
119
+ | `minimax-m3` | `minimax-official` |
120
+
121
+ **Gateway ids: always pass `clientType`.** Owner-prefixed ids (`openai/gpt-5.6-sol`, `anthropic/claude-opus-4.8`, `moonshotai/kimi-k3`) begin with no family and throw; an id that does begin with one (`deepseek-ai/DeepSeek-V4-Pro`) would reach the vendor's official client aimed at the gateway.
122
+
123
+ - `openai-responses` on OpenRouter: `https://openrouter.ai/api/v1` serves the Responses API for every model it resells and round-trips reasoning items (`openai-chat` works there too).
124
+ - `openai-chat` on Chat Completions endpoints: SiliconFlow, Fireworks AI, DashScope `https://dashscope.aliyuncs.com/compatible-mode/v1`, a self-hosted server (`openai-chat-vllm-adapter` for vLLM, to switch the served model's thinking). A self-hosted `deepseek-*` id needs it too, because `deepseek-official` posts to `{baseUrl}/responses`.
125
+ - `ant-messages` on Anthropic Messages endpoints (Anthropic, OpenRouter `https://openrouter.ai/api`, DeepSeek `https://api.deepseek.com/anthropic`, Z.AI, MiniMax); `google-genai` on Vertex AI or a relay that proxies Gemini's generateContent.
126
+
127
+ **Credentials.** The constructor's `apiKey` comes first, then the environment: an official client reads its vendor's pair (`DEEPSEEK_`, `OPENAI_`, `ANTHROPIC_`, `GEMINI_`, `ZAI_`, `MOONSHOT_`, `MINIMAX_` + `API_KEY` / `BASE_URL`), a compatible client the pair of its protocol (`OPENAI_*`; `ANTHROPIC_*` for `ant-messages`, `GEMINI_*` for `google-genai`, `MMSP_*` for `mmsp`). The OpenAI-, Anthropic- and generateContent-protocol clients send an environment key only to the environment's endpoint: a `baseUrl` without an `apiKey` throws `apiKey is required for <Client> with a baseUrl: OPENAI_API_KEY is not sent to another endpoint.` `mmsp` sends `MMSP_API_KEY` only to `MMSP_BASE_URL`, and a `baseUrl` without an `apiKey` is sent no key, which is what an open MMSP server takes. The other clients read their own variable whatever endpoint they are given, so pass a gateway's key as `apiKey` every time.
128
+
129
+ ## Streaming
116
130
 
117
131
  ```ts
118
132
  for await (const event of client.streamingResponseStateful({
119
- message: { role: "user", content_items: [{ type: "text", text: "Hello" }] },
133
+ message: { role: "user", content_items: [{ type: "text.done", text: "Hello" }] },
120
134
  config: {},
121
135
  })) {
122
- for (const item of event.content_items) {
123
- if (item.type === "text") process.stdout.write(item.text);
136
+ if (event.event_type === "stop") {
137
+ console.log("\n", event.finish_reason, event.usage_metadata); // always last, exactly once
138
+ continue;
124
139
  }
140
+ const item = event.content_items[0]; // a delta event carries exactly one item
141
+ if (item.type === "text.delta") process.stdout.write(item.text);
125
142
  }
126
143
  ```
127
144
 
128
- - Each `event` is a `UniEvent`: `event_type` is `start` | `delta` | `stop`, and `content_items` carry the increments.
129
- - `config` accepts `max_tokens`, `temperature`, `system_prompt`, `thinking_level` (the `ThinkingLevel` enum, `NONE` to `MAX`), `tool_choice`, `prompt_caching`, `fast_mode` and `tools`.
130
- - `streamingResponseStateful` keeps conversation history inside the client; manage it with `getHistory()` / `setHistory(history)` / `clearHistory()`. The stateless variant is `streamingResponse({ messages, config })`.
145
+ - `event_type` is `delta` or `stop` — there is no start event. The `stop` event comes last, exactly once, carries no items and always carries `usage_metadata` and `finish_reason` (`stop` | `length` | `tool_call` | `unknown`); `delta` events carry `null` for both. Read usage from `stop`; never add it up across events.
146
+ - Items stream in groups: one or more `K.delta` fragments, then one `K.done` holding the complete item (K = `text`, `thinking`, `tool_call`, `inline_data`, `inline_thinking`, `embedding`). Groups never interleave. Render the `.delta` items; keep the `.done` items — in stream order they are the assistant message.
147
+ - Tool calls: the first `tool_call.delta` of a call carries `name` and `tool_call_id` (later fragments carry `""`), and `arguments` is a raw JSON string fragment. `tool_call.done` carries `arguments` parsed into an object. Execute tools from `tool_call.done` only, and answer each with a `tool_result.done` item (`text`, optional `images`) carrying the exact `tool_call_id`:
148
+
149
+ ```ts
150
+ // in the loop: if (item.type === "tool_call.done") calls.push(item);
151
+ const reply: UniMessage = {
152
+ role: "user",
153
+ content_items: calls.map((call) => ({
154
+ type: "tool_result.done",
155
+ text: runTool(call.name, call.arguments), // your dispatcher
156
+ tool_call_id: call.tool_call_id,
157
+ })),
158
+ };
159
+ ```
160
+
161
+ - `config` accepts `max_tokens`, `temperature`, `system_prompt`, `thinking_level` (the `ThinkingLevel` enum, `NONE` to `MAX`), `thinking_summary`, `tool_choice`, `prompt_caching`, `fast_mode`, `tools`, `image_config`, `tts_config`, `embedding_config` and `trace_id`.
162
+
163
+ ## Messages and history
164
+
165
+ - A message holds only `.done` items: `text.done`, `image_url.done`, `inline_data.done`, `thinking.done`, `inline_thinking.done`, `tool_call.done`, `tool_result.done`, `embedding.done`. The item types without the suffix (messages saved before 0.5.0) are still accepted, with a deprecation warning, until 0.6.0; convert stored data with `normalizeLegacyMessages(messages)`.
166
+ - `streamingResponseStateful` keeps the conversation inside the client and records the turn before it yields `stop`; manage it with `getHistory()` / `setHistory(history)` / `clearHistory()`. The stateless variant is `streamingResponse({ messages, config })`.
167
+ - Keep `thinking.done` and `inline_thinking.done` items in history, and never strip or modify any item's `fidelity` — it is what replays the original wire message.
168
+
169
+ ## Errors
170
+
171
+ MMSP's error classes extend `MMSPError`; a construction problem and a stream cut short throw a plain `Error`. A stream ends with its `stop` event or with an exception, never both.
172
+
173
+ - Construction throws a plain `Error`: an id of no known family, an unknown client type, or a `baseUrl` without an `apiKey` (see above).
174
+ - `UnsupportedParameterError` (`client`, `parameter`): a config value the client cannot honour, thrown while the request is built, before anything reaches the network.
175
+ - `UnsupportedOperationError` (`client`, `operation`): a capability the client lacks, such as `listModels()` on a client with no models endpoint.
176
+ - `ToolCallArgumentParseError` (`toolName`, `toolCallId`, `rawArgumentsLength`, `rawArgumentsPreview`): thrown in place of a `tool_call.done` whose arguments are malformed or not a JSON object. Never run the tool from partial arguments; retry or re-prompt.
177
+ - `EmptyResponseError` (`finishReason`, `usageMetadata`): thrown in place of the `stop` event when the response held thinking only; the stateful history is left unchanged, and `usageMetadata` still reports the tokens.
178
+ - `StreamProtocolError`: a client broke the streaming grammar — a bug in MMSP, not in the model output.
179
+ - `UpstreamError` (`client`, `status`, `errorType`, `message`, `error`): the one error `mmsp` raises for anything its server reports — a refusal (wrong key, a model not in its table) or an error the server's client raised; `errorType` names the server-side class and `error` holds its fields.
180
+ - A stream that ends without usage or a finish reason throws `Error("Streaming response ended without usage_metadata")` (or `finish_reason`).
181
+
182
+ `MMSP_DEBUG=1` makes clients fail loudly on provider output they do not recognize; `MMSP_CACHE_DIR` moves the tracer's cache directory (default `cache/`).
131
183
 
132
184
  ## Config parameters the model may reject
133
185
 
134
- A config value the target client cannot honour throws `UnsupportedParameterError` (an `AgentHubError` carrying `client` and `parameter`) while building the request, before anything reaches the network:
186
+ Leave a parameter unset and the protocol default applies, which is the portable choice when a script must run against several families. A value the client cannot honour throws `UnsupportedParameterError` before any network request:
135
187
 
136
188
  ```ts
137
- import { UnsupportedParameterError } from "@prismshadow/agenthub";
189
+ import { UnsupportedParameterError } from "@prismshadow/mmsp";
138
190
 
139
191
  try {
140
192
  // ...
@@ -143,13 +195,17 @@ try {
143
195
  }
144
196
  ```
145
197
 
146
- - `thinking_level` never throws: every client maps each level onto the closest one the model supports, and `MAX` (the tier above `XHIGH`, added in AgentHub 0.4.4) degrades silently wherever the vendor has no such tier — Gemini and MiniMax M3 stop at `high`. Kimi K3 reasons unconditionally, so `NONE` degrades to its lowest effort rather than disabling thinking; GLM-5.2 sends `reasoning_effort` alongside its `thinking` block and only `NONE` disables it. GLM-5.3 thinks unconditionally (`NONE` degrades to the light `low` effort) and clamps `reasoning_effort` to `low`/`high`/`max`; `gemini-3.7-*` clamps to `low`/`medium`/`high` (`NONE` degrades to `low`). DeepSeek V4 accepts `low`/`high`/`max` and maps `medium` and `xhigh` onto `high` server-side, so since 0.4.4 `LOW` sends `low` (it sent `high`) and `XHIGH` sends `high` (it sent `max`).
147
- - `temperature` is rejected outright by Gemini 3.6/3.7 — those generations deprecated the sampling parameters, so the client refuses them instead of sending a value the API ignores. GPT-5.5/5.6, the whole Claude 4.6+ family (4.6 included since AgentHub 0.4.2), DeepSeek V4, Kimi K2.6 and Kimi K3 accept only the protocol default `1.0` and reject any other value. Gemini 3, GLM and the generic protocol clients (`openai-chat` / `openai-responses` / `ant-messages`) pass it through.
148
- - `tool_choice`: `"auto"` is safe everywhere. Claude accepts a single forced tool name; DeepSeek V4 and Kimi K2.6 allow `"auto"` / `"none"`; Kimi K3 adds `"required"` but refuses a specific tool (K2.x also rejects `"required"`); GLM only accepts `"auto"`.
149
- - `prompt_caching`: every client accepts `PromptCaching.ENABLE` and rejects the other values — caching is on by default and Kimi K3 caches context automatically.
150
- - `fast_mode` (`UniConfig`, AgentHub 0.4.2): fast processing at premium pricing. OpenAI-protocol clients (`openai-chat`, `openai-responses`, `gpt-6`, `minimax-m3`) map it to `service_tier: "priority"`; Anthropic-protocol clients (`ant-messages`, `claude-5`) map it to `speed: "fast"` with a beta header (an Anthropic research preview limited to Claude Opus 5 / Opus 4.8 — organizations without access get a 429). Clients without a fast tier (Gemini, GLM, Kimi, DeepSeek, embeddings, Claude 4.6 models) raise `UnsupportedParameterError`; DeepSeek and Z.AI's OpenAI-compatible endpoints simply ignore the tier.
198
+ - `thinking_level` never throws: every client maps each level onto the closest one the model supports. `MAX` falls back silently where the vendor has no such tier, and a model that always reasons (Kimi K3, GLM-5.3, Claude Opus 5.5 / Fable 5.1) turns `NONE` into its lowest effort, and so does Claude Haiku 5.5.
199
+ - `temperature`: both Gemini clients reject any value; `openai-official`, `anthropic-official`, `moonshot-official` and `deepseek-official` accept only `1.0`; `minimax-official` accepts 0 to 1; `zai-official` and the compatible clients pass it through.
200
+ - `tool_choice`: `"auto"` works everywhere. `zai-official` accepts nothing else; `deepseek-official` and `minimax-official` add `"none"`; `moonshot-official` adds `"required"` for Kimi K3 but never a named tool; `anthropic-official` takes `"required"` or one tool name, except on Claude Opus 5.5, Sonnet 5.5, Haiku 5.5 and Fable 5.1, which cannot be forced.
201
+ - `prompt_caching`: `ENABLE` (the default) works everywhere; only `anthropic-official` also takes `DISABLE` and `ENHANCE` (a one-hour cache).
202
+ - `fast_mode`: fast processing at premium pricing, decided by the client the model routes to:
203
+ - sent as `service_tier: "priority"` by `openai-official`, `openai-responses`, `openai-chat`, `openai-chat-vllm-adapter`, `google-official` and `minimax-official`;
204
+ - sent as `speed: "fast"` with the fast-mode beta header by `ant-messages` and `anthropic-official` — except on Bedrock and on Claude 4.6, Sonnet 5.5, Haiku 5.5 and Fable 5.1, which reject it. Anthropic's fast mode is a research preview: organizations without access get a 429;
205
+ - rejected by `zai-official`, `moonshot-official`, `deepseek-official`, `google-genai` and `openai-embedding` (which also serves `openai-official`'s `text-embedding-*` ids);
206
+ - forwarded by `mmsp` to its server, whose client for the model decides.
151
207
 
152
- Leave a parameter unset and the protocol default applies, which is the portable choice when a script must run against several families.
208
+ A third-party OpenAI-compatible endpoint may accept `service_tier` and still serve the standard tier.
153
209
 
154
210
  ## Image generation
155
211
 
@@ -160,39 +216,35 @@ import fs from "node:fs";
160
216
 
161
217
  const client = new AutoLLMClient({ model: "gemini-3.1-flash-image" });
162
218
  for await (const event of client.streamingResponseStateful({
163
- message: { role: "user", content_items: [{ type: "text", text: "A penguin on a glacier" }] },
219
+ message: { role: "user", content_items: [{ type: "text.done", text: "A penguin on a glacier" }] },
164
220
  config: { image_config: { aspect_ratio: "16:9", image_size: "2K" } },
165
221
  })) {
166
222
  for (const item of event.content_items) {
167
- if (item.type === "inline_data") fs.writeFileSync("image.png", item.data);
223
+ if (item.type === "inline_data.done") fs.writeFileSync("image.png", item.data);
168
224
  }
169
225
  }
170
226
  ```
171
227
 
172
- Images arrive as `inline_data` content items (`data` is a Buffer, with `mime_type`).
228
+ An image streams as `inline_data.delta` chunks closed by one `inline_data.done` holding the whole image (`data` is a Buffer, with `mime_type`). Interim images a model thinks with arrive as `inline_thinking` items; they are not the output.
173
229
 
174
230
  ## Speech synthesis
175
231
 
176
- Use a Gemini TTS model (`gemini-3.1-flash-tts-preview`) and set `config.tts_config`:
232
+ Use a Gemini TTS model (`gemini-3.8-flash-tts`, `gemini-3.1-flash-tts-preview`, …) and set `config.tts_config`:
177
233
 
178
234
  ```ts
179
235
  config: { tts_config: [{ voice: "Kore" }] }
180
236
  ```
181
237
 
182
- - One entry → single voice; two entries → multi-speaker, and each entry must also set `speaker`.
183
- - The `inline_data` output is raw PCM (24kHz 16-bit mono) — wrap it in a WAV header yourself before saving as `.wav`.
238
+ - One entry → single voice; two entries → multi-speaker, and each entry must also set `speaker`. Write a two-speaker text as a script, one `Name: line` per turn.
239
+ - The audio is raw PCM, in `inline_data.done` whose `mime_type` names the sample rate and channel count — wrap it in a WAV header yourself before saving as `.wav`.
184
240
 
185
241
  ## Embeddings
186
242
 
187
- Two routes:
243
+ - `gemini-embedding-2` and `text-embedding-3-small` / `text-embedding-3-large` route on their own (`google-official`, and `openai-official` through the Embeddings API).
244
+ - Any other OpenAI-compatible embeddings endpoint: pass `clientType: "openai-embedding"` with its `baseUrl` and `apiKey`.
188
245
 
189
- - Gemini: a model whose id contains `gemini-embedding` auto-routes (`gemini-embedding-2`).
190
- - Any OpenAI-compatible embeddings endpoint: pass `clientType: "openai-embedding"` (plus `baseUrl` and `apiKey` as needed) — ids like `text-embedding-3-small` / `text-embedding-3-large` match no auto-route substring and would throw without it.
191
-
192
- Optional `config.embedding_config`:
246
+ Call `streamingResponse({ messages, config })`: each message yields one vector, as an `embedding.done` item (`embedding` is a number array), and the items within one message are embedded together. Set the size with `config.embedding_config`:
193
247
 
194
248
  ```ts
195
249
  config: { embedding_config: { dimensions: 768 } }
196
250
  ```
197
-
198
- The output arrives as `embedding` content items (`embedding` is a number array).
package/plugin.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "description": "Agent development on PenguinHarness: build on the SDK, call any model through one unified LLM API, manage models and secrets, and orchestrate agents, sessions, costs and schedules.",
3
- "description_zh": "基于 PenguinHarness 的智能体开发:用 SDK 构建应用、经统一的 LLM API 调用任意模型、管理模型与密钥、编排智能体/会话/成本/定时任务。",
4
- "short_description": "SDK, unified LLM API, config and orchestration.",
5
- "short_description_zh": "SDK、统一 LLM API、配置与编排。",
6
- "version": "2026.09.10.1",
7
- "category": "ai-app-development"
8
- }