@deepseek-ai/dsh-llm-pi-ai 0.2.1-alpha.1 → 0.2.1-alpha.2

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.
package/README.i18n.yaml CHANGED
@@ -30,8 +30,8 @@
30
30
  en: 376f83206858b601
31
31
  zh: 38bb6993609c96a6
32
32
  /deepseek-ai-dsh-llm-pi-ai/use-this-package/run-with-reasoning-and-wire-compatibility:
33
- en: 86b456496b54854e
34
- zh: ff77ca11d39ba8d2
33
+ en: b58b917e7f250aee
34
+ zh: aff599081bac08c3
35
35
  /deepseek-ai-dsh-llm-pi-ai/use-this-package/change-configuration-at-runtime:
36
36
  en: 92f554e1718614ca
37
37
  zh: f17ed3ad3e5d28e2
@@ -45,14 +45,14 @@
45
45
  en: 1598ac8a8bb9b6bf
46
46
  zh: fdd089c5ae7722cd
47
47
  /deepseek-ai-dsh-llm-pi-ai/understand-the-implementation/design-philosophy:
48
- en: 280416de410744bb
49
- zh: 64cbfc0902e3f436
48
+ en: 8aba1113937b368a
49
+ zh: 804a4ca672a776df
50
50
  /deepseek-ai-dsh-llm-pi-ai/understand-the-implementation/source-map:
51
51
  en: 20afee7bbfb332ca
52
52
  zh: b080cf4e97094366
53
53
  /deepseek-ai-dsh-llm-pi-ai/understand-the-implementation/registration-and-directory:
54
- en: 4da379c9be65c18a
55
- zh: fd305d4bd3dfa452
54
+ en: 3e12da237dea76da
55
+ zh: f4d917343e822d2d
56
56
  /deepseek-ai-dsh-llm-pi-ai/understand-the-implementation/replay-and-vocabulary:
57
57
  en: 36e0c59a0f9f5980
58
58
  zh: 90a62c4a9cd23429
@@ -66,8 +66,8 @@
66
66
  en: e7348db3f7115960
67
67
  zh: 5fd5fb09d7d09982
68
68
  /deepseek-ai-dsh-llm-pi-ai/model-experience/provider-request-through-pi-ai/what-the-model-sees:
69
- en: 34e63beee750a3a9
70
- zh: a869322d161d922f
69
+ en: 203535e4c439eb08
70
+ zh: d51d696f122691cb
71
71
  /deepseek-ai-dsh-llm-pi-ai/model-experience/provider-request-through-pi-ai/token-effect:
72
72
  en: 820221e8ae37aa61
73
73
  zh: 7e6ff4db10067fc0
@@ -87,8 +87,8 @@
87
87
  en: b6bd570c0159ba08
88
88
  zh: 7d2d91eea6a8d830
89
89
  /deepseek-ai-dsh-llm-pi-ai/known-limitations-and-deferred-work:
90
- en: bb240ee5dd3f81c7
91
- zh: 884506a36f4aac62
90
+ en: 552281e47ba3980f
91
+ zh: 4af4dff3d9fa52d5
92
92
  /deepseek-ai-dsh-llm-pi-ai/known-limitations-and-deferred-work/dev-note:
93
93
  en: 3678dd0f6642c2a5
94
94
  zh: 75cbdd064cc64282
package/README.md CHANGED
@@ -102,6 +102,8 @@ A profile's `models` list replaces the route's installed catalog rather than ext
102
102
 
103
103
  `reasoningEfforts` declares a model's selectable thinking levels: each key is a level selectors offer, its value the spelling dispatch sends on the wire, so `max: ultra` renames a level for a gateway with its own vocabulary. Omitting the field keeps the installed catalog entry's capability; `false` declares a non-reasoning model. `compat` switches reshape the request for endpoints pi-ai cannot recognize — which role carries the system prompt, which field caps output, how a thinking level travels — configurable per route and per model. A model neither the entry nor the installed catalog sizes takes the route's `defaultContextWindow` and `defaultMaxTokens` fallbacks.
104
104
 
105
+ Exact-model metadata lists `reasoning.efforts` from least to greatest selectable effort. A configuration function can select from that list before `prepareCall()` validates the concrete effort. The adapter receives only the resolved controls. Selecting `off` does not guarantee disabled reasoning: a protocol that expresses it by omitting the reasoning field leaves the gateway's default in effect. Reasoning tokens at any selected level count toward the request's output cap.
106
+
105
107
  For self-hosted Chat Completions endpoints, `thinkingTokenBudgetField` selects the reasoning-budget parameter, and `vllmPriority` sets an integer scheduler priority when the server enables priority scheduling. Template arguments accept `$var: thinking.budget`. `openai-responses` gateways can set `supportsMaxOutputTokens: false` to omit `max_output_tokens`; Azure and Codex transports ignore this shared compatibility field. These controls are opt-in; catalog-owned Anthropic effort and fallback capabilities are not configurable switches.
106
108
 
107
109
  ### Change configuration at runtime
@@ -134,6 +136,8 @@ This section explains the design behind the adapter; the observable behavior is
134
136
 
135
137
  The adapter is built on immutable snapshots and per-operation resolution. Each operation captures a whole snapshot — the profiles plus a `createModels()` collection holding the `Provider` each route built — before its first `await`, and a configuration change builds a new collection rather than mutating the one in use, so a request that started under one configuration never finishes under another. A route's own credential reference resolves through the harness seam and rides as the request's `apiKey` option, which pi-ai treats as the highest-priority auth override — that is what keeps the fail-loud reference semantics. Everything that override does not cover reaches pi-ai through the collection's own auth: the credential store holds the records a login wrote and a refresh rotates (addressed as `llm-pi-ai/<provider id>`), and the auth context answers the ambient questions a provider asks while resolving. Both are stable across snapshots, so a configuration change rebuilds the collection without forgetting who is signed in. Runtime imports use pi-ai's provider, API, and utility entry points; `src/models.ts` supplies the small model-helper subset this adapter needs without evaluating pi-ai's aggregate entry point.
136
138
 
139
+ Initial prompt text and active tools use pi-ai's `Context.systemPrompt` and `Context.tools`; later system and tool updates remain in `Context.messages`. pi-ai normalizes these fields and applies the selected protocol's serialization rules.
140
+
137
141
  ### Source map
138
142
 
139
143
  | File | Role |
@@ -152,7 +156,7 @@ The adapter is built on immutable snapshots and per-operation resolution. Each o
152
156
 
153
157
  ### Registration and directory
154
158
 
155
- The plugin declares every installed catalog provider it can authenticate in the configurable-provider directory, joined with every route the current profiles declare, so configuration surfaces can offer the full catalog before any route exists. Each entry carries `declared` — whether pi-ai ships nothing under that key — because only the adapter can distinguish a hand-declared route from a narrowed catalog route. Route registration is atomic: a candidate set that collides with another adapter leaves the previous routes serving. A bare mount with zero routes is the dormant posture: nothing registers until the Config supplies profiles, and routes drop when it empties.
159
+ The plugin declares every installed catalog provider it can authenticate in the configurable-provider directory, joined with every route the current profiles declare, so configuration surfaces can offer the full catalog before any route exists. A catalog provider whose catalog lists models but no chat model, such as one of classifier models alone, is left out and gets no sign-in flow, because this adapter dispatches chat requests only. Each entry carries `declared` — whether pi-ai ships nothing under that key — because only the adapter can distinguish a hand-declared route from a narrowed catalog route. Route registration is atomic: a candidate set that collides with another adapter leaves the previous routes serving. A bare mount with zero routes is the dormant posture: nothing registers until the Config supplies profiles, and routes drop when it empties.
156
160
 
157
161
  ### Replay and vocabulary
158
162
 
@@ -183,7 +187,7 @@ Read these pages when the package-level contract is not enough. They move from t
183
187
 
184
188
  #### What the model sees
185
189
 
186
- The selected catalog model receives one system prompt (`GenerateOptions.system`, otherwise the text of a leading `system` history message; a leading system message with empty text sends none), the remaining history, tools, and sampling fields supported by pi-ai's common streaming API. Each retained image is preceded by text naming its complete attachment id and actual request dimensions. When the current execution filesystem maps the attachment provider's host object, the text also carries a read-only normalized-object path and warns that normalization or request projection may have resized or re-encoded the upload. Each occurrence selected by a logged image-offload decision keeps its own identity and currently resolved access in replacement text, and its normalized attachment is not read or transformed. When the retained occurrences' exact base64 payload still exceeds the route's `maxRequestImageBytes`, the call fails with `IMAGE_OFFLOAD_REQUIRED` so `dsh-compaction-image-offload` records the selected occurrences in an `image/offload` event and retries the step. Provider-native replay metadata is restored only when the adapter validates it for the historical content.
190
+ The selected catalog model receives system-message text, conversation history, tools, and supported sampling fields. The adapter preserves later system messages in history order; pi-ai owns protocol-specific placement and concatenates them at the beginning for models without mid-conversation system support. One-shot `GenerateOptions.system` precedes the initial history prompt. Repeated system messages remain repeated; empty system messages are skipped without discarding earlier text. Tool-update capabilities select the shared historical declaration projection; pi-ai receives initially active tools and grouped developer updates carrying additions and supported removals. When every projected declaration of an Anthropic request with tool updates is deferred, the initially active tools are one placeholder, `DeferredToolPlaceholder`, whose description tells the model never to call it; a call reaches the ordinary unknown-tool result. Anthropic receives later tool definitions inline in the update message. Replay preserves tool-call namespaces for dynamically loaded Responses tools. Each retained image is preceded by text naming its complete attachment id and actual request dimensions. When the current execution filesystem maps the attachment provider's host object, the text also carries a read-only normalized-object path and warns that normalization or request projection may have resized or re-encoded the upload. Each occurrence selected by a logged image-offload decision keeps its own identity and currently resolved access in replacement text, and its normalized attachment is not read or transformed. When the retained occurrences' exact base64 payload still exceeds the route's `maxRequestImageBytes`, the call fails with `IMAGE_OFFLOAD_REQUIRED` so `dsh-compaction-image-offload` records the selected occurrences in an `image/offload` event and retries the step. Provider-native replay metadata is restored only when the adapter validates it for the historical content.
187
191
 
188
192
  #### Token effect
189
193
 
@@ -216,6 +220,7 @@ These limits define where the adapter stops and future work begins. They are cur
216
220
 
217
221
  - **`maxRequestImageBytes` counts base64 image payload only** — text, tools, descriptors, and JSON structure ride outside the bound, so it must sit below the gateway's request-body cap with headroom.
218
222
  - **A sign-in lives only in the process that started it** — an authorization attempt is not durable, so reloading the page mid-login abandons it and the human starts over. Signing out is `deleteRecord` on the stored record, which forgets it locally without telling the issuer.
223
+ - **OpenAI offers no ChatGPT sign-in** — pi-ai's Sign in with ChatGPT identifies the installation to OpenAI with a stable UUID the app supplies, and the harness keeps no installation ID meant for a third-party account sign-in; the `openai` route signs in with an API key.
219
224
  - **Provider-native discovery answers through this plugin's ambient context** — a route naming no credential defers to the catalog provider's own resolution, which asks for environment values (`AZURE_OPENAI_API_KEY`, `AWS_PROFILE`, and each provider's own set) and for local credential files. Both questions are answered here: the credential seam is consulted before the process environment, and file existence is checked against the host process's filesystem with `~` expanded. What it cannot do is *read* a credential file's contents — a provider that parses `~/.aws/credentials` itself does so directly, outside the seam.
220
225
  - **Reset restores inherited configuration** — resetting a route supplied by a lower profile layer restores that route.
221
226
  - **Complete Config replacement can remove inherited dictionary entries** — a field reset instead restores its inherited value.
@@ -226,10 +231,11 @@ These limits define where the adapter stops and future work begins. They are cur
226
231
  - **A modality declaration is not verified** — a model declaring `image` its gateway does not serve is refused by the provider after prompt admission. The durable image remains in history and the same misdeclared model can fail again; switching to a text-only model remains possible because the shared LLM runtime projects image references into stable text for that request.
227
232
  - **An unauthenticated route depends on its protocol** — a route naming no credential resolves as configured-but-keyless, but pi-ai's OpenAI-compatible implementation still requires an API key or an `Authorization` header, so a keyless local server needs a placeholder credential referenced by `apiKeyEnv` or an `Authorization` entry in `headers`.
228
233
  - **`GenerateOptions.stop` is unsupported** — pi-ai's common stream options cannot guarantee stop-sequence behavior across providers.
229
- - **Only a leading in-history `system` message becomes pi-ai's `systemPrompt`** — this adapter uses pi-ai's single `systemPrompt` input, so a later `system` message, or a leading one when `GenerateOptions.system` is also set, folds into a `user` message at its position; provider-specific placement of the prompt follows pi-ai rather than a harness-owned wire override. Images in system or assistant history, including the leading system message, fail with `UNSUPPORTED_CONTENT` on both conversion paths.
234
+ - **Conversation update support comes only from the installed pi-ai catalog** — a route receives in-history prompt and tool updates only when its catalog model declares the mid-conversation compat flags, and profiles cannot set them; hand-declared routes and unflagged models receive the concatenated system messages and the complete current tool list at the start of each request.
235
+ - **Images are accepted only in user and tool-result messages** — images in system, developer, or assistant history fail with `UNSUPPORTED_CONTENT` on both conversion paths.
230
236
  - **Provider HTTP status is unavailable** — pi-ai error events do not expose a stable HTTP status across providers.
231
237
  - **Retry policy is provider-owned, not an SDK retry** — pi-ai SDK retries stay disabled so durable agent steps and `llm/retry` events own every visible attempt, and direct `ctx.llm.stream()` calls remain single-attempt.
232
- - **Streamed tool-call arguments are parsed once, when the call ends** — the installed pi-ai carries [`patches/@earendil-works__pi-ai@0.87.1.patch`](../../../patches/@earendil-works__pi-ai@0.87.1.patch), which removes the per-delta re-parse of the whole accumulated argument JSON in every stream adapter (upstream [earendil-works/pi#9265](https://github.com/earendil-works/pi/issues/9265)); unpatched, a multi-megabyte argument stream costs O(n²) CPU on the event loop and stalls every session in the process. Until `toolcall_end`, a pi-ai partial's tool-call `arguments` stays `{}`; this adapter reads only the delta strings and the finalized arguments. Re-apply or retire the patch on every pi-ai upgrade.
238
+ - **Streamed tool-call arguments are parsed once, when the call ends** — the installed pi-ai carries [`patches/@earendil-works__pi-ai@1.0.2.patch`](../../../patches/@earendil-works__pi-ai@1.0.2.patch), which removes the per-delta re-parse of the whole accumulated argument JSON in every stream adapter (upstream [earendil-works/pi#9265](https://github.com/earendil-works/pi/issues/9265)); unpatched, a multi-megabyte argument stream costs O(n²) CPU on the event loop and stalls every session in the process. Until `toolcall_end`, a pi-ai partial's tool-call `arguments` stays `{}`; this adapter reads only the delta strings and the finalized arguments. Re-apply or retire the patch on every pi-ai upgrade.
233
239
 
234
240
  <a id="dev-note"></a>
235
241
  ### Dev Note
package/README.zh.md CHANGED
@@ -102,6 +102,8 @@ profile 的 `models` 列表会替换而非扩展路由的已安装目录;每
102
102
 
103
103
  `reasoningEfforts` 声明模型可选择的 thinking 等级:每个键都是选择器提供的等级,其值是分派时在协议中发送的拼写,因此 `max: ultra` 可以为拥有自有词汇的网关重命名等级。省略该字段时保留已安装目录条目的能力;`false` 声明非推理模型。对于 pi-ai 无法识别的端点,`compat` 开关重塑请求——哪个角色携带系统提示词、哪个字段限制输出、thinking 等级如何传递——可逐路由、逐模型配置。条目与已安装目录都没有尺寸的模型,会采用路由的 `defaultContextWindow` 与 `defaultMaxTokens` 回退值。
104
104
 
105
+ 确切模型元数据将 `reasoning.efforts` 按可选强度从低到高排列。配置函数可从该列表中选择,再由 `prepareCall()` 校验具体强度。适配器只接收解析后的控制项。选择 `off` 不保证禁用推理:以省略推理字段表达该值的协议会沿用网关默认行为。所选等级下产生的推理 token 都计入该请求的输出上限。
106
+
105
107
  对于自托管 Chat Completions 端点,`thinkingTokenBudgetField` 选择推理预算参数,`vllmPriority` 在服务端启用优先级调度时设置整数调度优先级。模板参数接受 `$var: thinking.budget`。`openai-responses` 网关可设置 `supportsMaxOutputTokens: false` 来省略 `max_output_tokens`;Azure 与 Codex 传输会忽略这个共享兼容字段。这些控制均需显式启用;目录拥有的 Anthropic effort 和回退能力不是可配置开关。
106
108
 
107
109
  ### 运行时更改配置
@@ -134,6 +136,8 @@ Config 更新严格验证发生变化的 provider。初始加载将已存储的
134
136
 
135
137
  适配器建立在不可变快照与按操作解析之上。每个操作都会在第一次 `await` 前捕获整个快照——profile 加一个持有每条路由所构建 `Provider` 的 `createModels()` 集合——配置变更会构建新集合而非修改使用中的集合,因此在一个配置下开始的请求绝不会在另一个配置下结束。路由自己的凭据引用经 harness seam 解析,并以请求 `apiKey` 选项传入,pi-ai 将其视为优先级最高的 auth 覆盖——这正是明确失败引用语义的所在。该覆盖未覆盖的一切都经集合自身的 auth 到达 pi-ai:凭据存储持有登录写入、刷新轮换的记录(以 `llm-pi-ai/<provider id>` 寻址),auth context 回答提供方解析时提出的 ambient 问题。两者跨快照保持稳定,因此配置变更重建集合时不会忘记谁已登录。运行时 import 使用 pi-ai 的 provider、API 与 utility 入口;`src/models.ts` 提供本适配器所需的少量 model helper,而不会求值 pi-ai 聚合入口。
136
138
 
139
+ 初始提示词文本和可用工具分别使用 pi-ai 的 `Context.systemPrompt` 与 `Context.tools`;后续系统消息和工具更新保留在 `Context.messages` 中。pi-ai 负责规范化这些字段,并应用所选协议的序列化规则。
140
+
137
141
  ### 源码地图
138
142
 
139
143
  | 文件 | 职责 |
@@ -152,7 +156,7 @@ Config 更新严格验证发生变化的 provider。初始加载将已存储的
152
156
 
153
157
  ### 注册与目录
154
158
 
155
- 插件会在可配置提供方目录中声明它能认证的每个已安装目录提供方,并加入当前 profile 声明的每条路由,因此配置界面可以在任何路由存在之前提供完整目录。每个条目都携带 `declared`——pi-ai 是否在该键下不提供任何内容——因为只有适配器能区分手工声明路由与收窄目录路由。路由注册具有原子性:与其他适配器冲突的候选集合会让此前路由继续服务。零路由的裸挂载即休眠姿态:settings 分节提供 profile 前不注册任何内容,分节清空时路由随之消失。
159
+ 插件会在可配置提供方目录中声明它能认证的每个已安装目录提供方,并加入当前 profile 声明的每条路由,因此配置界面可以在任何路由存在之前提供完整目录。目录列出了模型却没有聊天模型的提供方(例如只有分类器模型)不进入目录,也不注册登录流程,因为本适配器只分派聊天请求。每个条目都携带 `declared`——pi-ai 是否在该键下不提供任何内容——因为只有适配器能区分手工声明路由与收窄目录路由。路由注册具有原子性:与其他适配器冲突的候选集合会让此前路由继续服务。零路由的裸挂载即休眠姿态:settings 分节提供 profile 前不注册任何内容,分节清空时路由随之消失。
156
160
 
157
161
  ### 回放与词汇
158
162
 
@@ -183,7 +187,7 @@ Config 更新严格验证发生变化的 provider。初始加载将已存储的
183
187
 
184
188
  #### 模型看到什么
185
189
 
186
- 所选目录模型会收到一条系统提示词(`GenerateOptions.system`,否则取历史中首条 `system` 消息的文本;首条 system 消息文本为空时不发送系统提示词)、其余历史、工具与 pi-ai 通用流式 API 支持的采样字段。每张保留图片前都会有文本,注明其完整附件 id 与实际请求尺寸。当前执行文件系统可以映射附件提供方的宿主对象时,该文本还会携带只读规范化对象路径,并警告规范化或请求投影可能缩放或重新编码上传内容。日志中的图片省略决策选中的每个出现位置都会在替换文本中保留自己的身份与当前已解析访问方式,其规范化附件不会读取或变换。当保留的出现位置按精确 base64 载荷仍超过路由的 `maxRequestImageBytes` 时,调用以 `IMAGE_OFFLOAD_REQUIRED` 失败,由 `dsh-compaction-image-offload` 用 `image/offload` 事件记录所选位置并重试步骤。提供方原生回放元数据只在适配器针对历史内容校验通过后恢复。
190
+ 所选目录模型会收到系统消息文本、对话历史、工具以及支持的采样字段。适配器按历史顺序保留后续系统消息;pi-ai 负责各协议的消息位置,并为不支持对话中系统消息的模型将它们拼接到开头。单次调用的 `GenerateOptions.system` 放在初始历史提示词之前。重复的系统消息仍会重复发送;空系统消息会被跳过,不会丢弃之前的文本。工具更新能力选择共享的历史声明投影;pi-ai 接收初始可用工具,以及按开发者消息分组的新增和受支持的移除更新。当包含工具更新的 Anthropic 请求中所有投影后的声明均为延迟加载时,初始可用工具为一个占位工具 `DeferredToolPlaceholder`,其描述要求模型永不调用它;若被调用,会得到普通的未知工具结果。Anthropic 在更新消息中以内联方式接收后续工具定义。回放会保留工具调用命名空间,以支持动态加载的 Responses 工具。每张保留图片前都会有文本,注明其完整附件 id 与实际请求尺寸。当前执行文件系统可以映射附件提供方的宿主对象时,该文本还会携带只读规范化对象路径,并警告规范化或请求投影可能缩放或重新编码上传内容。日志中的图片省略决策选中的每个出现位置都会在替换文本中保留自己的身份与当前已解析访问方式,其规范化附件不会读取或变换。当保留的出现位置按精确 base64 载荷仍超过路由的 `maxRequestImageBytes` 时,调用以 `IMAGE_OFFLOAD_REQUIRED` 失败,由 `dsh-compaction-image-offload` 用 `image/offload` 事件记录所选位置并重试步骤。提供方原生回放元数据只在适配器针对历史内容校验通过后恢复。
187
191
 
188
192
  #### Token 影响
189
193
 
@@ -216,6 +220,7 @@ pi-ai 事件变成 harness 的推理、文本、工具调用、用量与 finish
216
220
 
217
221
  - **`maxRequestImageBytes` 只计算 base64 图片载荷**,文本、工具、描述符与 JSON 结构在该上限之外,因此它必须留有余量地低于网关请求体上限。
218
222
  - **登录只存在于发起它的进程中**——授权尝试不持久,因此登录中途刷新页面会放弃它,用户需要重新开始。退出登录是对已存储记录执行 `deleteRecord`,只在本地忘记它,不会告知签发方。
223
+ - **OpenAI 不提供 ChatGPT 登录**——pi-ai 的 Sign in with ChatGPT 用应用提供的稳定 UUID 向 OpenAI 标识安装实例,而 harness 没有用于第三方账号登录的安装 ID;`openai` 路由改用 API key 登录。
219
224
  - **提供方原生发现经本插件的 ambient context 回答**——不点名凭据的路由交由目录提供方自身解析,它会询问环境值(`AZURE_OPENAI_API_KEY`、`AWS_PROFILE` 及各提供方自有集合)与本地凭据文件。两个问题都在这里得到回答:凭据 seam 先于进程环境被查询,文件存在性则针对宿主进程的文件系统以 `~` 展开后检查。它做不到的是*读取*凭据文件内容——自行解析 `~/.aws/credentials` 的提供方会直接读取,不经该 seam。
220
225
  - **重置恢复继承配置**——重置下层 profile 提供的路由会恢复该路由。
221
226
  - **完整替换 Config 可以移除继承的字典条目**——字段重置则恢复其继承值。
@@ -226,10 +231,11 @@ pi-ai 事件变成 harness 的推理、文本、工具调用、用量与 finish
226
231
  - **模态声明不受校验**——声明 `image` 而其网关不支持的模型会在提示词准入后被提供方拒绝。持久图片仍留在历史中,同一误声明模型可能再次失败;切换到纯文本模型仍然可行,因为共享 LLM 运行时会针对该请求把图片引用投影为稳定文本。
227
232
  - **未认证路由取决于其协议**——不点名凭据的路由解析为已配置但无密钥,但 pi-ai 的 OpenAI 兼容实现仍要求 API 密钥或 `Authorization` 标头,因此无密钥本地服务器需要由 `apiKeyEnv` 引用或 `headers` 中的 `Authorization` 条目提供的占位凭据。
228
233
  - **不支持 `GenerateOptions.stop`**——pi-ai 的通用流式选项无法跨提供方保证停止序列行为。
229
- - **只有历史中首条 `system` 消息会成为 pi-ai 的 `systemPrompt`**——本适配器使用 pi-ai 的单一 `systemPrompt` 输入,因此后续的 `system` 消息,或在同时设置了 `GenerateOptions.system` 时的首条消息,会在原位置折叠为 `user` 消息;系统提示词的提供方专属放置遵循 pi-ai,而非 harness 自有的协议覆盖。system 或 assistant 历史中的图片(包括首条系统消息中的图片)在两条转换路径上都会以 `UNSUPPORTED_CONTENT` 失败。
234
+ - **对话更新支持只来自已安装的 pi-ai 目录**——只有当路由的目录模型声明了对话中 compat 标志时,该路由才会在历史中接收提示词与工具更新,且 profile 不能设置这些标志;手工声明的路由与未标记的模型会在每次请求开头接收拼接后的系统消息与完整的当前工具列表。
235
+ - **图片只在 user 与工具结果消息中被接受**——system、developer 或 assistant 历史中的图片在两条转换路径上都会以 `UNSUPPORTED_CONTENT` 失败。
230
236
  - **提供方 HTTP 状态不可用**——pi-ai 错误事件不跨提供方暴露稳定 HTTP 状态。
231
237
  - **重试策略由提供方自有,而非 SDK 重试**——pi-ai SDK 重试保持禁用,因此持久 agent(智能体)步骤与 `llm/retry` 事件拥有每个可见尝试,直接 `ctx.llm.stream()` 调用仍是单次尝试。
232
- - **流式工具调用参数只在调用结束时解析一次**——安装的 pi-ai 带有 [`patches/@earendil-works__pi-ai@0.87.1.patch`](../../../patches/@earendil-works__pi-ai@0.87.1.patch),它移除了每个流适配器中对整段累计参数 JSON 的逐 delta 重新解析(上游 [earendil-works/pi#9265](https://github.com/earendil-works/pi/issues/9265));未打补丁时,数 MB 的参数流会在事件循环上消耗 O(n²) CPU,并使进程内所有会话停滞。在 `toolcall_end` 之前,pi-ai partial 的工具调用 `arguments` 保持为 `{}`;本适配器只读取 delta 字符串与最终参数。每次升级 pi-ai 时都要重新应用或撤销该补丁。
238
+ - **流式工具调用参数只在调用结束时解析一次**——安装的 pi-ai 带有 [`patches/@earendil-works__pi-ai@1.0.2.patch`](../../../patches/@earendil-works__pi-ai@1.0.2.patch),它移除了每个流适配器中对整段累计参数 JSON 的逐 delta 重新解析(上游 [earendil-works/pi#9265](https://github.com/earendil-works/pi/issues/9265));未打补丁时,数 MB 的参数流会在事件循环上消耗 O(n²) CPU,并使进程内所有会话停滞。在 `toolcall_end` 之前,pi-ai partial 的工具调用 `arguments` 保持为 `{}`;本适配器只读取 delta 字符串与最终参数。每次升级 pi-ai 时都要重新应用或撤销该补丁。
233
239
 
234
240
  <a id="dev-note"></a>
235
241
  ### 开发备注
package/lib/index.js CHANGED
@@ -6,7 +6,7 @@ import { brandString } from "@deepseek-ai/dsh-brand";
6
6
  import { requestImageDimensions } from "@deepseek-ai/dsh-attachment";
7
7
  import z from "@deepseek-ai/schemastery";
8
8
  import { credentialKey, credentialKeyId, credentialKeyScope, credentialRef, isCredentialKeySegment, isCredentialRefName } from "@deepseek-ai/dsh-credentials";
9
- import { builtinModels, builtinProviders, getBuiltinModels, getBuiltinProviders } from "@earendil-works/pi-ai/providers/all";
9
+ import { builtinModels, builtinProviders, getAllBuiltinModels, getBuiltinModels } from "@earendil-works/pi-ai/providers/all";
10
10
  import { anthropicMessagesApi } from "@earendil-works/pi-ai/api/anthropic-messages.lazy";
11
11
  import { openAICompletionsApi } from "@earendil-works/pi-ai/api/openai-completions.lazy";
12
12
  import { openAIResponsesApi } from "@earendil-works/pi-ai/api/openai-responses.lazy";
@@ -84,7 +84,8 @@ function toPiReplayState(message, requestedModel = message.model) {
84
84
  };
85
85
  case "toolCall": return {
86
86
  type: "tool-call",
87
- ...block.thoughtSignature === void 0 ? {} : { thoughtSignature: block.thoughtSignature }
87
+ ...block.thoughtSignature === void 0 ? {} : { thoughtSignature: block.thoughtSignature },
88
+ ...block.namespace === void 0 ? {} : { namespace: block.namespace }
88
89
  };
89
90
  }
90
91
  })
@@ -130,7 +131,8 @@ function readReplayState(value) {
130
131
  for (const signature of [
131
132
  "textSignature",
132
133
  "thinkingSignature",
133
- "thoughtSignature"
134
+ "thoughtSignature",
135
+ "namespace"
134
136
  ]) if (block[signature] !== void 0 && typeof block[signature] !== "string") return invalidReplay(`block ${index} ${signature} must be a string`);
135
137
  if (block["redacted"] !== void 0 && typeof block["redacted"] !== "boolean") return invalidReplay(`block ${index} redacted must be boolean`);
136
138
  }
@@ -206,7 +208,8 @@ function replayedAssistant(message, source, rawState) {
206
208
  id: block.id,
207
209
  name: block.name,
208
210
  arguments: parseArguments(block.arguments),
209
- ...replay.type === "tool-call" && replay.thoughtSignature !== void 0 ? { thoughtSignature: replay.thoughtSignature } : {}
211
+ ...replay.type === "tool-call" && replay.thoughtSignature !== void 0 ? { thoughtSignature: replay.thoughtSignature } : {},
212
+ ...replay.type === "tool-call" && replay.namespace !== void 0 ? { namespace: replay.namespace } : {}
210
213
  };
211
214
  /* v8 ignore next -- readReplayState rejects unknown replay tags, so an equal plugin-added Harness tag cannot reach this switch */
212
215
  default: return invalidReplay(`block ${index} has an unsupported Harness type`);
@@ -337,34 +340,49 @@ const CHAT_TEMPLATE_VARS = Object.keys({
337
340
  });
338
341
  let providerIndex;
339
342
  /**
340
- * Installed catalog providers by id, constructed once. Each entry owns the API
341
- * implementations for its own models, which is why a catalog route reuses this
342
- * provider instead of being rebuilt from parts.
343
- * @returns the catalog provider index.
343
+ * Whether this adapter serves one installed catalog provider. It dispatches
344
+ * chat requests only, so a provider whose catalog lists models but no chat
345
+ * model (image-generation or classifier models alone) is not a catalog route;
346
+ * a provider whose catalog lists no models at all stays one.
347
+ * @param provider - the installed provider.
348
+ * @returns whether the provider ships a chat model or lists no models.
349
+ */
350
+ function servesChat(provider) {
351
+ const id = provider.id;
352
+ return getBuiltinModels(id).length > 0 || getAllBuiltinModels(id).length === 0;
353
+ }
354
+ /**
355
+ * Installed catalog providers this adapter serves, by id, constructed once.
356
+ * Each entry owns the API implementations for its own models, which is why a
357
+ * catalog route reuses this provider instead of being rebuilt from parts.
358
+ * @returns the catalog provider index, in catalog order.
344
359
  */
345
360
  function catalogProviders() {
346
- providerIndex ??= new Map(builtinProviders().map((provider) => [provider.id, provider]));
361
+ providerIndex ??= new Map(builtinProviders().filter(servesChat).map((provider) => [provider.id, provider]));
347
362
  return providerIndex;
348
363
  }
349
364
  /**
350
- * The installed catalog provider for one route, when pi-ai ships one.
365
+ * The installed catalog provider for one route, when pi-ai ships one this
366
+ * adapter serves.
351
367
  * @param provider - provider route key.
352
- * @returns the catalog provider, or `undefined` for a route pi-ai does not ship.
368
+ * @returns the catalog provider, or `undefined` for a route pi-ai does not ship
369
+ * or ships without a chat model.
353
370
  */
354
371
  function catalogProvider(provider) {
355
372
  return catalogProviders().get(provider);
356
373
  }
357
374
  /**
358
- * Every provider route the installed pi-ai catalog ships.
359
- * @returns the catalog provider ids.
375
+ * Every provider route the installed pi-ai catalog ships and this adapter
376
+ * serves: a provider whose catalog lists models but no chat model is left out.
377
+ * @returns the catalog provider ids, in catalog order.
360
378
  */
361
379
  function catalogProviderIds() {
362
- return getBuiltinProviders();
380
+ return [...catalogProviders().keys()];
363
381
  }
364
382
  /**
365
383
  * The installed catalog models for one route, indexed by model id.
366
384
  * @param provider - provider route key.
367
- * @returns catalog models by id; empty for a route pi-ai does not ship.
385
+ * @returns catalog models by id; empty for a route {@link catalogProvider} does not return.
368
386
  */
369
387
  function catalogModels(provider) {
370
388
  if (!catalogProviders().has(provider)) return /* @__PURE__ */ new Map();
@@ -759,6 +777,20 @@ function getSupportedThinkingLevels(model) {
759
777
  return true;
760
778
  });
761
779
  }
780
+ /**
781
+ * Resolve transcript update modes from the exact model's protocol capabilities.
782
+ * @param model - Materialized pi-ai model, including catalog compatibility flags.
783
+ * @returns Update modes consumed by prompt admission and tool-history projection.
784
+ */
785
+ function conversationUpdates(model) {
786
+ const compat = model.compat;
787
+ if (compat === void 0 || !("supportsMidConvoSystemMessages" in compat) || !compat.supportsMidConvoSystemMessages) return {};
788
+ const updates = { systemPromptUpdate: "in-history" };
789
+ if (model.api === "anthropic-messages" && "supportsMidConvoToolChanges" in compat && compat.supportsMidConvoToolChanges) updates.toolUpdate = "in-history";
790
+ else if (model.api === "openai-completions" && "supportsMidConvoToolAdditions" in compat && compat.supportsMidConvoToolAdditions) updates.toolUpdate = "addition-only";
791
+ else if ((model.api === "openai-responses" || model.api === "azure-openai-responses" || model.api === "openai-codex-responses") && ("supportsAdditionalTools" in compat && compat.supportsAdditionalTools || "supportsToolSearch" in compat && compat.supportsToolSearch)) updates.toolUpdate = "addition-only";
792
+ return updates;
793
+ }
762
794
  //#endregion
763
795
  //#region lib/types/provider.js
764
796
  /**
@@ -1177,12 +1209,12 @@ function toolResultOf(message, toolNames, content) {
1177
1209
  timestamp: 0
1178
1210
  };
1179
1211
  }
1180
- /** Reject unsupported roles, tool-change blocks, and image roles before replay or image offloading. */
1212
+ /** Reject misplaced tool-change blocks and unsupported image roles before replay or image offloading. */
1181
1213
  function assertSupportedHistory(messages) {
1182
1214
  for (const message of messages) {
1183
- if (message.role === "developer") throw new LlmError("Developer messages are not supported yet", "UNSUPPORTED_CONTENT");
1184
- if (message.content.some((block) => block.type === "tool-addition" || block.type === "tool-removal")) throw new LlmError("Tool-change blocks require developer role", "UNSUPPORTED_CONTENT");
1215
+ if (message.role !== "developer" && message.content.some((block) => block.type === "tool-addition" || block.type === "tool-removal")) throw new LlmError("Tool-change blocks require developer role", "UNSUPPORTED_CONTENT");
1185
1216
  if (message.role !== "user" && message.role !== "tool" && contentHasImage(message.content)) throw new LlmError(`pi-ai cannot represent an image in an in-history ${message.role} message`, "UNSUPPORTED_CONTENT");
1217
+ if (message.role === "system" && message.content.some((block) => block.type !== "text")) throw new LlmError("pi-ai cannot represent non-text system messages", "UNSUPPORTED_CONTENT");
1186
1218
  }
1187
1219
  }
1188
1220
  function userContent(blocks, requestImages, resolveImageAccess) {
@@ -1226,35 +1258,29 @@ async function prepareRequestImages(messages, attachments, budget, signal) {
1226
1258
  for (const [index, ref] of orderedRefs.entries()) versions.set(ref.attachmentId, prepared[index]);
1227
1259
  return versions;
1228
1260
  }
1229
- function toolsOf(options) {
1230
- if (options.tools?.some((tool) => tool.deferLoading === true)) throw new LlmError("Deferred tool loading is not supported yet", "UNSUPPORTED_CONTENT");
1231
- return options.tools?.map((tool) => ({
1261
+ /** Convert a projected declaration without its harness-owned activation marker. */
1262
+ function piTool(tool) {
1263
+ return {
1232
1264
  name: tool.name,
1233
1265
  description: tool.description,
1234
1266
  parameters: tool.parameters
1235
- }));
1267
+ };
1236
1268
  }
1237
- /**
1238
- * Select the pi-ai `systemPrompt` source shared by both conversion paths.
1239
- * `options.system` wins when defined and every history message converts,
1240
- * including a leading `system` message, which then folds into a `user`
1241
- * message. Otherwise a leading `system` history message supplies the prompt
1242
- * and leaves the converted history; empty leading text sends no prompt.
1243
- */
1269
+ function toolsOf(options) {
1270
+ return options.tools?.filter((tool) => !tool.deferLoading).map(piTool);
1271
+ }
1272
+ /** Combine request-level text and leading system history into the initial prompt. */
1244
1273
  function splitSystemPrompt(options) {
1245
- if (options.system !== void 0) return {
1246
- systemPrompt: options.system,
1247
- messages: options.messages
1248
- };
1249
- const [first, ...rest] = options.messages;
1250
- if (first?.role !== "system") return {
1251
- systemPrompt: void 0,
1252
- messages: options.messages
1253
- };
1254
- const text = flattenText(first);
1274
+ const text = [options.system];
1275
+ let end = 0;
1276
+ for (const message of options.messages) {
1277
+ if (message.role !== "system") break;
1278
+ text.push(flattenText(message));
1279
+ end++;
1280
+ }
1255
1281
  return {
1256
- systemPrompt: text.length > 0 ? text : void 0,
1257
- messages: rest
1282
+ systemPrompt: text.filter(Boolean).join("\n\n") || void 0,
1283
+ messages: options.messages.slice(end)
1258
1284
  };
1259
1285
  }
1260
1286
  /** Assemble the request-level pi-ai context envelope shared by both conversion paths. */
@@ -1266,17 +1292,54 @@ function piContext(systemPrompt, options, messages) {
1266
1292
  ...tools !== void 0 && tools.length > 0 ? { tools } : {}
1267
1293
  };
1268
1294
  }
1295
+ /** Keep one developer event in one system update, resolving its projected tool declarations. */
1296
+ function appendDeveloper(message, options, messages) {
1297
+ const content = [];
1298
+ const toolsAdded = [];
1299
+ const toolsRemoved = [];
1300
+ for (const block of message.content) switch (block.type) {
1301
+ case "text":
1302
+ if (block.text.length > 0) content.push({
1303
+ type: "text",
1304
+ text: block.text
1305
+ });
1306
+ break;
1307
+ case "tool-addition": {
1308
+ const tool = options.tools?.find((tool) => tool.name === block.toolName);
1309
+ if (tool === void 0) throw new LlmError(`pi-ai tool update references undeclared tool "${block.toolName}"`, "INVALID_REQUEST");
1310
+ toolsAdded.push(piTool(tool));
1311
+ break;
1312
+ }
1313
+ case "tool-removal":
1314
+ toolsRemoved.push({ name: block.toolName });
1315
+ break;
1316
+ default: throw new LlmError(`pi-ai cannot represent developer content ${block.type}`, "UNSUPPORTED_CONTENT");
1317
+ }
1318
+ if (content.length === 0 && toolsAdded.length === 0 && toolsRemoved.length === 0) return;
1319
+ messages.push({
1320
+ role: "system",
1321
+ content,
1322
+ timestamp: 0,
1323
+ ...toolsAdded.length === 0 ? {} : { toolsAdded },
1324
+ ...toolsRemoved.length === 0 ? {} : { toolsRemoved }
1325
+ });
1326
+ }
1269
1327
  function appendAssistant(message, messages, toolNames, onReplayDegrade) {
1270
1328
  const assistant = toPiAssistant(message, onReplayDegrade);
1271
1329
  for (const block of assistant.content) if (block.type === "toolCall") toolNames.set(brandString(block.id), block.name);
1272
1330
  messages.push(assistant);
1273
1331
  }
1274
- /** Append the system and assistant roles both context builders treat identically; true when consumed. */
1275
- function appendSystemOrAssistant(message, messages, toolNames, onReplayDegrade) {
1332
+ /** Append shared system, developer, and assistant roles; true when consumed. */
1333
+ function appendSharedHistory(message, options, messages, toolNames, onReplayDegrade) {
1334
+ if (message.role === "developer") {
1335
+ appendDeveloper(message, options, messages);
1336
+ return true;
1337
+ }
1276
1338
  if (message.role === "system") {
1277
- messages.push({
1278
- role: "user",
1279
- content: flattenText(message),
1339
+ const content = flattenText(message);
1340
+ if (content.length > 0) messages.push({
1341
+ role: "system",
1342
+ content,
1280
1343
  timestamp: 0
1281
1344
  });
1282
1345
  return true;
@@ -1294,7 +1357,7 @@ function textOnlyContext(options, onReplayDegrade) {
1294
1357
  const messages = [];
1295
1358
  for (const message of split.messages) {
1296
1359
  if (contentHasImage(message.content)) throw new LlmError("pi-ai image conversion requires the durable attachment service", "UNSUPPORTED_CONTENT");
1297
- if (appendSystemOrAssistant(message, messages, toolNames, onReplayDegrade)) continue;
1360
+ if (appendSharedHistory(message, options, messages, toolNames, onReplayDegrade)) continue;
1298
1361
  if (message.role === "tool") {
1299
1362
  messages.push(toolResultOf(message, toolNames, flattenText(message)));
1300
1363
  continue;
@@ -1337,7 +1400,7 @@ async function toPiContextWithImages(options, images, onReplayDegrade) {
1337
1400
  const toolNames = /* @__PURE__ */ new Map();
1338
1401
  const messages = [];
1339
1402
  for (const message of exactMessages) {
1340
- if (appendSystemOrAssistant(message, messages, toolNames, onReplayDegrade)) continue;
1403
+ if (appendSharedHistory(message, options, messages, toolNames, onReplayDegrade)) continue;
1341
1404
  if (message.role === "tool") {
1342
1405
  messages.push(toolResultOf(message, toolNames, userContent(message.content, requestImages, resolveImageAccess)));
1343
1406
  continue;
@@ -1670,6 +1733,18 @@ var __disposeResources = (function(SuppressedError) {
1670
1733
  var e = new Error(message);
1671
1734
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1672
1735
  });
1736
+ /**
1737
+ * Initially active declaration added to an Anthropic request whose projected
1738
+ * tools are all deferred, because Anthropic rejects a tool list without one.
1739
+ */
1740
+ const ANTHROPIC_TOOL_UPDATE_PLACEHOLDER = {
1741
+ name: "DeferredToolPlaceholder",
1742
+ description: "Reserved placeholder that keeps deferred tool loading active; never call this tool.",
1743
+ parameters: {
1744
+ type: "object",
1745
+ properties: {}
1746
+ }
1747
+ };
1673
1748
  /** Copy profile stream knobs into pi-ai's common option vocabulary. */
1674
1749
  function profileOptions(profile, reasoning, apiKey) {
1675
1750
  const enabledReasoning = reasoning === "off" ? void 0 : reasoning;
@@ -1825,7 +1900,8 @@ var PiAiAdapter = class extends LlmAdapter {
1825
1900
  inputModalities: [...resolvedModel.input],
1826
1901
  context: { contextWindow: resolvedModel.contextWindow },
1827
1902
  ...configuredMaxTokens === void 0 ? {} : { defaultMaxTokens: configuredMaxTokens },
1828
- ...reasoningInfo(resolvedModel, defaultLevel)
1903
+ ...reasoningInfo(resolvedModel, defaultLevel),
1904
+ ...conversationUpdates(resolvedModel)
1829
1905
  };
1830
1906
  }
1831
1907
  prepareCall(provider, model, _signal) {
@@ -1848,6 +1924,12 @@ var PiAiAdapter = class extends LlmAdapter {
1848
1924
  if (options.stop !== void 0) throw new LlmError("llm-pi-ai does not support GenerateOptions.stop", "UNSUPPORTED_OPTION");
1849
1925
  const profile = this.profileOf(snapshot, options.provider);
1850
1926
  const model = this.modelOf(snapshot, options.provider, options.model);
1927
+ const updates = conversationUpdates(model);
1928
+ const tools = options.tools ?? [];
1929
+ const request = model.api === "anthropic-messages" && updates.toolUpdate === "in-history" && tools.every((tool) => tool.deferLoading === true) && options.messages.some((message) => message.role === "developer" && message.content.some((block) => block.type === "tool-addition" || block.type === "tool-removal")) ? {
1930
+ ...options,
1931
+ tools: [ANTHROPIC_TOOL_UPDATE_PLACEHOLDER, ...tools]
1932
+ } : options;
1851
1933
  const reasoning = resolveReasoningLevel(model, options.reasoningEffort ?? profile.reasoning);
1852
1934
  const apiKey = await this.config.resolveApiKey(options.provider, profile);
1853
1935
  const consumer = new AbortController();
@@ -1866,8 +1948,8 @@ var PiAiAdapter = class extends LlmAdapter {
1866
1948
  reason
1867
1949
  });
1868
1950
  };
1869
- const context = attachments === void 0 ? toPiContext(options, void 0, onReplayDegrade) : await toPiContext({
1870
- ...options,
1951
+ const context = attachments === void 0 ? toPiContext(request, void 0, onReplayDegrade) : await toPiContext({
1952
+ ...request,
1871
1953
  signal: watchdog.signal
1872
1954
  }, {
1873
1955
  attachments,
@@ -1890,8 +1972,6 @@ var PiAiAdapter = class extends LlmAdapter {
1890
1972
  try {
1891
1973
  while (true) {
1892
1974
  const result = await watchdog.next(iterator);
1893
- const timeout = timeoutOf(watchdog.signal, "LLM_STREAM_IDLE_TIMEOUT");
1894
- if (timeout !== void 0) throw timeout;
1895
1975
  if (result.done) {
1896
1976
  exhausted = true;
1897
1977
  return;
@@ -1901,9 +1981,8 @@ var PiAiAdapter = class extends LlmAdapter {
1901
1981
  } finally {
1902
1982
  if (!exhausted) {
1903
1983
  consumer.abort("pi-ai stream consumer stopped");
1904
- try {
1905
- await iterator.return(void 0);
1906
- } catch (_abortedSdkTeardown) {}
1984
+ /* v8 ignore next -- the detached drain only rejects while unwinding an abandoned stream. */
1985
+ iterator.return(void 0).catch(() => {});
1907
1986
  }
1908
1987
  }
1909
1988
  } catch (error) {
@@ -2346,18 +2425,28 @@ async function discoverModels(request, storedProfile) {
2346
2425
  * @module dsh-llm-pi-ai/login
2347
2426
  */
2348
2427
  /**
2428
+ * Catalog providers whose OAuth login this adapter does not offer. pi-ai's Sign
2429
+ * in with ChatGPT (`openai`) identifies the installation to OpenAI with a
2430
+ * stable UUID that the app supplies through `LoginOptions.getDeviceId`, and it
2431
+ * refuses to start without one. The harness keeps no installation ID meant for
2432
+ * a third-party account sign-in, so the route signs in with an API key.
2433
+ */
2434
+ const UNSERVED_OAUTH = new Set(["openai"]);
2435
+ /**
2349
2436
  * The login methods one catalog provider offers.
2350
2437
  *
2351
- * A method appears only when pi-ai can actually run it: `oauth` always carries
2352
- * a `login`, while an api-key method has one only when the provider collects
2353
- * its key interactively — which every installed one currently does, so a key is
2354
- * typed into pi-ai's own prompt rather than into the settings form.
2438
+ * A method appears only when pi-ai can actually run it: `oauth` carries a
2439
+ * `login` that runs without app-supplied login options except for the
2440
+ * providers in {@link UNSERVED_OAUTH}, while an api-key method has one only
2441
+ * when the provider collects its key interactively — which every installed one
2442
+ * currently does, so a key is typed into pi-ai's own prompt rather than into
2443
+ * the settings form.
2355
2444
  * @param provider - the installed catalog provider, if pi-ai ships one.
2356
2445
  * @returns its methods, most preferred first; empty when it offers no login.
2357
2446
  */
2358
2447
  function loginMethods(provider) {
2359
2448
  const methods = [];
2360
- const oauth = provider?.auth.oauth;
2449
+ const oauth = provider === void 0 || UNSERVED_OAUTH.has(provider.id) ? void 0 : provider.auth.oauth;
2361
2450
  if (oauth !== void 0) methods.push({
2362
2451
  id: "oauth",
2363
2452
  label: oauth.loginLabel ?? oauth.name
@@ -41,20 +41,23 @@ export type PiAiChatTemplateVar = Extract<ChatTemplateKwargValue, {
41
41
  /** The request-state placeholders a profile may name. */
42
42
  export declare const CHAT_TEMPLATE_VARS: readonly PiAiChatTemplateVar[];
43
43
  /**
44
- * The installed catalog provider for one route, when pi-ai ships one.
44
+ * The installed catalog provider for one route, when pi-ai ships one this
45
+ * adapter serves.
45
46
  * @param provider - provider route key.
46
- * @returns the catalog provider, or `undefined` for a route pi-ai does not ship.
47
+ * @returns the catalog provider, or `undefined` for a route pi-ai does not ship
48
+ * or ships without a chat model.
47
49
  */
48
50
  export declare function catalogProvider(provider: string): Provider | undefined;
49
51
  /**
50
- * Every provider route the installed pi-ai catalog ships.
51
- * @returns the catalog provider ids.
52
+ * Every provider route the installed pi-ai catalog ships and this adapter
53
+ * serves: a provider whose catalog lists models but no chat model is left out.
54
+ * @returns the catalog provider ids, in catalog order.
52
55
  */
53
56
  export declare function catalogProviderIds(): readonly string[];
54
57
  /**
55
58
  * The installed catalog models for one route, indexed by model id.
56
59
  * @param provider - provider route key.
57
- * @returns catalog models by id; empty for a route pi-ai does not ship.
60
+ * @returns catalog models by id; empty for a route {@link catalogProvider} does not return.
58
61
  */
59
62
  export declare function catalogModels(provider: string): Map<string, Model<Api>>;
60
63
  /**
@@ -27,7 +27,7 @@ export interface PiImageRequestBudget {
27
27
  /**
28
28
  * Convert text-only harness history to a synchronous pi-ai Context. Tool
29
29
  * result names are recovered from preceding assistant tool calls.
30
- * @param options - the harness request; `options.system`, else a leading `system` message, maps to pi-ai's single `systemPrompt` slot.
30
+ * @param options - projected request; one-shot system text precedes the leading history prompt.
31
31
  * @param images - absent; selects the synchronous conversion.
32
32
  * @param onReplayDegrade - forwarded to {@link toPiAssistant} for each assistant message.
33
33
  * @returns the pi-ai context; `tools` is omitted when the request declares none.
@@ -41,7 +41,7 @@ export declare function toPiContext(options: GenerateOptions, images?: undefined
41
41
  * retained occurrences' exact base64 payload still exceeds
42
42
  * `maxRequestImageBytes`, the call fails with `IMAGE_OFFLOAD_REQUIRED` naming
43
43
  * how many more oldest occurrences must be offloaded.
44
- * @param options - the harness request; `options.system`, else a leading `system` message, maps to pi-ai's single `systemPrompt` slot.
44
+ * @param options - projected request; one-shot system text precedes the leading history prompt.
45
45
  * @param images - attachment provider, current path resolver, and request limits.
46
46
  * @param onReplayDegrade - forwarded to {@link toPiAssistant} for each assistant message.
47
47
  * @returns the asynchronously resolved pi-ai context.
@@ -1,5 +1,6 @@
1
1
  /** pi-ai model helpers assembled from public narrow entry points. */
2
2
  import type { Api, CreateModelsOptions, Model, ModelThinkingLevel, MutableModels, Provider, ProviderAuth, ProviderStreams } from '@earendil-works/pi-ai';
3
+ import type { LlmResolvedModelInfo } from '@deepseek-ai/dsh-llm';
3
4
  /** Input accepted by the static, single-protocol providers this package builds. */
4
5
  interface StaticProviderOptions {
5
6
  id: string;
@@ -27,5 +28,11 @@ export declare function createProvider(input: StaticProviderOptions): Provider;
27
28
  * @returns supported levels in pi-ai's escalation order.
28
29
  */
29
30
  export declare function getSupportedThinkingLevels(model: Model<Api>): ModelThinkingLevel[];
31
+ /**
32
+ * Resolve transcript update modes from the exact model's protocol capabilities.
33
+ * @param model - Materialized pi-ai model, including catalog compatibility flags.
34
+ * @returns Update modes consumed by prompt admission and tool-history projection.
35
+ */
36
+ export declare function conversationUpdates(model: Model<Api>): Pick<LlmResolvedModelInfo, 'systemPromptUpdate' | 'toolUpdate'>;
30
37
  export {};
31
38
  //# sourceMappingURL=models.d.ts.map
@@ -20,6 +20,7 @@ export type PiAiReplayBlock = {
20
20
  } | {
21
21
  type: 'tool-call';
22
22
  thoughtSignature?: string;
23
+ namespace?: string;
23
24
  };
24
25
  /** Versioned response-level half of the pi-ai replay envelope. */
25
26
  export interface PiAiReplayResponse {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@deepseek-ai/dsh-llm-pi-ai",
3
3
  "description": "pi-ai-backed DeepSeek adapter for the DeepSeek Harness LLM seam (design-verification twin of dsh-llm-deepseek)",
4
- "version": "0.2.1-alpha.1",
4
+ "version": "0.2.1-alpha.2",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -28,35 +28,35 @@
28
28
  "license": "MIT",
29
29
  "peerDependencies": {
30
30
  "@deepseek-ai/cordis": "~4.0.5-alpha.1",
31
- "@deepseek-ai/dsh-attachment": "0.2.1-alpha.1",
32
- "@deepseek-ai/dsh-authorization": "0.2.1-alpha.1",
33
- "@deepseek-ai/dsh-credentials": "0.2.1-alpha.1",
34
- "@deepseek-ai/dsh-fs": "0.2.1-alpha.1",
35
- "@deepseek-ai/dsh-launch-environment": "0.2.1-alpha.1",
36
- "@deepseek-ai/dsh-llm": "0.2.1-alpha.1",
37
- "@deepseek-ai/dsh-timeout": "0.2.1-alpha.1",
31
+ "@deepseek-ai/dsh-attachment": "0.2.1-alpha.2",
32
+ "@deepseek-ai/dsh-authorization": "0.2.1-alpha.2",
33
+ "@deepseek-ai/dsh-credentials": "0.2.1-alpha.2",
34
+ "@deepseek-ai/dsh-fs": "0.2.1-alpha.2",
35
+ "@deepseek-ai/dsh-launch-environment": "0.2.1-alpha.2",
36
+ "@deepseek-ai/dsh-llm": "0.2.1-alpha.2",
37
+ "@deepseek-ai/dsh-timeout": "0.2.1-alpha.2",
38
38
  "@deepseek-ai/cordis-plugin-loader": "~1.0.6-alpha.1"
39
39
  },
40
40
  "dependencies": {
41
- "@earendil-works/pi-ai": "^0.87.1",
42
- "@deepseek-ai/dsh-brand": "0.2.1-alpha.1",
43
- "@deepseek-ai/dsh-util-values": "0.2.1-alpha.1",
44
- "@deepseek-ai/schemastery": "~3.18.5-alpha.1"
41
+ "@deepseek-ai/dsh-brand": "0.2.1-alpha.2",
42
+ "@deepseek-ai/dsh-util-values": "0.2.1-alpha.2",
43
+ "@deepseek-ai/schemastery": "~3.18.5-alpha.1",
44
+ "@earendil-works/pi-ai": "^1.0.2"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@deepseek-ai/cordis": "~4.0.5-alpha.1",
48
- "@deepseek-ai/dsh-attachment": "0.2.1-alpha.1",
49
- "@deepseek-ai/dsh-authorization": "0.2.1-alpha.1",
50
- "@deepseek-ai/dsh-credentials": "0.2.1-alpha.1",
51
- "@deepseek-ai/dsh-fs": "0.2.1-alpha.1",
52
- "@deepseek-ai/dsh-launch-environment": "0.2.1-alpha.1",
53
- "@deepseek-ai/dsh-llm": "0.2.1-alpha.1",
54
- "@deepseek-ai/dsh-llm-deepseek": "0.2.1-alpha.1",
55
- "@deepseek-ai/dsh-llm-deepseek-api-key": "0.2.1-alpha.1",
56
- "@deepseek-ai/dsh-timeout": "0.2.1-alpha.1",
57
- "@deepseek-ai/dsh-http-proxy": "0.2.1-alpha.1",
48
+ "@deepseek-ai/dsh-attachment": "0.2.1-alpha.2",
49
+ "@deepseek-ai/dsh-authorization": "0.2.1-alpha.2",
50
+ "@deepseek-ai/dsh-credentials": "0.2.1-alpha.2",
51
+ "@deepseek-ai/dsh-fs": "0.2.1-alpha.2",
52
+ "@deepseek-ai/dsh-launch-environment": "0.2.1-alpha.2",
53
+ "@deepseek-ai/dsh-llm": "0.2.1-alpha.2",
54
+ "@deepseek-ai/dsh-llm-deepseek": "0.2.1-alpha.2",
55
+ "@deepseek-ai/dsh-llm-deepseek-api-key": "0.2.1-alpha.2",
56
+ "@deepseek-ai/dsh-timeout": "0.2.1-alpha.2",
57
+ "@deepseek-ai/dsh-http-proxy": "0.2.1-alpha.2",
58
58
  "@deepseek-ai/cordis-plugin-loader": "~1.0.6-alpha.1",
59
- "@deepseek-ai/dsh-settings": "0.2.1-alpha.1"
59
+ "@deepseek-ai/dsh-settings": "0.2.1-alpha.2"
60
60
  },
61
61
  "peerDependenciesMeta": {
62
62
  "@deepseek-ai/cordis-plugin-loader": {