@deepseek-ai/dsh-llm-pi-ai 0.2.1-alpha.2 → 0.2.1-alpha.4
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 +15 -12
- package/README.md +27 -5
- package/README.zh.md +27 -5
- package/lib/index.js +247 -7
- package/lib/types/adapter.d.ts +3 -1
- package/lib/types/context.d.ts +8 -1
- package/lib/types/provider-data.d.ts +10 -0
- package/lib/types/provider-data.generated.d.ts +10 -0
- package/locale/en.json +5 -0
- package/locale/zh.json +6 -0
- package/package.json +30 -28
package/README.i18n.yaml
CHANGED
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
en: 6619e8cfe7555c73
|
|
40
40
|
zh: b2f80c25acb81cf8
|
|
41
41
|
/deepseek-ai-dsh-llm-pi-ai/use-this-package/failures-and-recovery:
|
|
42
|
-
en:
|
|
43
|
-
zh:
|
|
42
|
+
en: 3c1edbc63de24a1a
|
|
43
|
+
zh: 01592718c3a2c79f
|
|
44
44
|
/deepseek-ai-dsh-llm-pi-ai/understand-the-implementation:
|
|
45
45
|
en: 1598ac8a8bb9b6bf
|
|
46
46
|
zh: fdd089c5ae7722cd
|
|
@@ -48,14 +48,17 @@
|
|
|
48
48
|
en: 8aba1113937b368a
|
|
49
49
|
zh: 804a4ca672a776df
|
|
50
50
|
/deepseek-ai-dsh-llm-pi-ai/understand-the-implementation/source-map:
|
|
51
|
-
en:
|
|
52
|
-
zh:
|
|
51
|
+
en: 64912b8a3a336419
|
|
52
|
+
zh: 33a245969b4194f6
|
|
53
53
|
/deepseek-ai-dsh-llm-pi-ai/understand-the-implementation/registration-and-directory:
|
|
54
|
-
en:
|
|
55
|
-
zh:
|
|
54
|
+
en: 0c6df3e8b6a75372
|
|
55
|
+
zh: 476666a6f209542c
|
|
56
|
+
/deepseek-ai-dsh-llm-pi-ai/understand-the-implementation/generated-provider-metadata:
|
|
57
|
+
en: 477d277e9ac35c8f
|
|
58
|
+
zh: 96870ca333fb6510
|
|
56
59
|
/deepseek-ai-dsh-llm-pi-ai/understand-the-implementation/replay-and-vocabulary:
|
|
57
|
-
en:
|
|
58
|
-
zh:
|
|
60
|
+
en: 73242ca9b8a98c76
|
|
61
|
+
zh: 4ab98526ae70bd23
|
|
59
62
|
/deepseek-ai-dsh-llm-pi-ai/further-exploration:
|
|
60
63
|
en: a2a2ccdeae59d408
|
|
61
64
|
zh: c47ee091aa90ad91
|
|
@@ -66,8 +69,8 @@
|
|
|
66
69
|
en: e7348db3f7115960
|
|
67
70
|
zh: 5fd5fb09d7d09982
|
|
68
71
|
/deepseek-ai-dsh-llm-pi-ai/model-experience/provider-request-through-pi-ai/what-the-model-sees:
|
|
69
|
-
en:
|
|
70
|
-
zh:
|
|
72
|
+
en: 948e7c8ec2ffda92
|
|
73
|
+
zh: 72bd6c7a4691a355
|
|
71
74
|
/deepseek-ai-dsh-llm-pi-ai/model-experience/provider-request-through-pi-ai/token-effect:
|
|
72
75
|
en: 820221e8ae37aa61
|
|
73
76
|
zh: 7e6ff4db10067fc0
|
|
@@ -87,8 +90,8 @@
|
|
|
87
90
|
en: b6bd570c0159ba08
|
|
88
91
|
zh: 7d2d91eea6a8d830
|
|
89
92
|
/deepseek-ai-dsh-llm-pi-ai/known-limitations-and-deferred-work:
|
|
90
|
-
en:
|
|
91
|
-
zh:
|
|
93
|
+
en: ee870ac2ac87decc
|
|
94
|
+
zh: 9e66c5e7400c4bc6
|
|
92
95
|
/deepseek-ai-dsh-llm-pi-ai/known-limitations-and-deferred-work/dev-note:
|
|
93
96
|
en: 3678dd0f6642c2a5
|
|
94
97
|
zh: 75cbdd064cc64282
|
package/README.md
CHANGED
|
@@ -122,6 +122,8 @@ Config updates strictly validate changed providers. Initial loading retains stor
|
|
|
122
122
|
|
|
123
123
|
Changing `displayName`, `apiKeyEnv`, or `baseURL` without resolving the provider's model errors still rejects the save. For example, renaming an OpenRouter route whose model `111` needs an `api` cannot be saved on its own: repair or remove that model in the same editor draft, then save the complete provider configuration. Intermediate repairs remain in the draft until the whole provider validates; other providers can be saved independently.
|
|
124
124
|
|
|
125
|
+
Model discovery resolves each route’s credential configuration. A missing required credential yields an empty catalog; other resolution errors propagate. Routes with native authentication or no required key retain their configured catalog. This check does not probe the inference endpoint.
|
|
126
|
+
|
|
125
127
|
-----
|
|
126
128
|
|
|
127
129
|
<a id="understand-the-implementation"></a>
|
|
@@ -147,6 +149,7 @@ Initial prompt text and active tools use pi-ai's `Context.systemPrompt` and `Con
|
|
|
147
149
|
| [`src/login.ts`](src/login.ts) | Authorization flows for the installed providers that ship a login |
|
|
148
150
|
| [`src/config.ts`](src/config.ts) | Profile schema, resolution, and serviceability checks |
|
|
149
151
|
| [`src/catalog.ts`](src/catalog.ts) | Installed-catalog integration and drift gates |
|
|
152
|
+
| [`src/provider-data.ts`](src/provider-data.ts) | Generated authentication and endpoint metadata for configuration surfaces |
|
|
150
153
|
| [`src/models.ts`](src/models.ts) | Model collections, static providers, and reasoning levels over narrow pi-ai entry points |
|
|
151
154
|
| [`src/provider.ts`](src/provider.ts) | The supported-protocol table and provider construction |
|
|
152
155
|
| [`src/context.ts`](src/context.ts) | Harness-to-pi-ai context conversion, image handling, replay restore |
|
|
@@ -156,11 +159,30 @@ Initial prompt text and active tools use pi-ai's `Context.systemPrompt` and `Con
|
|
|
156
159
|
|
|
157
160
|
### Registration and directory
|
|
158
161
|
|
|
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.
|
|
162
|
+
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. A catalog entry carries `defaultBaseURL` for a fixed provider endpoint or a fixed endpoint shared by all its models, `baseURLEnv` for endpoint configuration variables, and `nativeAuth` for authentication variables and OAuth availability. Different model endpoints and unresolved URL templates are not presented as one fixed default. 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.
|
|
163
|
+
|
|
164
|
+
<a id="generated-provider-metadata"></a>
|
|
165
|
+
### Generated provider metadata
|
|
166
|
+
|
|
167
|
+
[`scripts/gen-provider-data.ts`](scripts/gen-provider-data.ts) owns [`src/provider-data.generated.ts`](src/provider-data.generated.ts). It uses public resolvers with synthetic `AuthContext` answers to discover environment reads across empty, individual and suffix configurations. Resolver failures use `findEnvKeys` through the temporary compatibility entry. All current authentication variables come from resolvers; no authentication supplement is needed. The generator reports fallback use and fails if fallback metadata is missing. It does not read real credentials, start a login flow, or send a model request. Probing covers the installed resolvers; it does not prove all possible value-dependent branches.
|
|
168
|
+
|
|
169
|
+
Endpoint data comes from the public provider/model catalog and uppercase URL placeholders. Azure, Vertex and Bedrock need small supplements for variables read outside the auth context. Runtime directory reads execute no probes. The dependency range remains unchanged. A provider added by a newer consumer installation has no generated authentication hints until regeneration. For an existing provider, changed environment names and endpoints also remain at the generated snapshot until regeneration. Environment hints check only the listed credential references; they do not inspect provider-managed files such as AWS profiles or Google application-default credentials.
|
|
170
|
+
|
|
171
|
+
After updating pi-ai or changing the generator, install the updated locked dependencies, then run these commands from the repository root:
|
|
172
|
+
|
|
173
|
+
```sh
|
|
174
|
+
pnpm run gen-provider-data
|
|
175
|
+
pnpm run verify-provider-data
|
|
176
|
+
git add packages/llm/llm-pi-ai/src/provider-data.generated.ts
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Review the generated diff and stage the dependency or generator changes with it. Do not edit the generated file by hand. Generation errors must be resolved before committing.
|
|
180
|
+
|
|
181
|
+
The `pre-commit` hook runs `node_modules/.bin/tsx packages/llm/llm-pi-ai/scripts/gen-provider-data.ts --check --cached` when `pnpm-lock.yaml`, this package's `package.json`, the generator, or the generated file is staged. It compares the staged generated file with expected data computed from the installed dependency and current generator. It does not rewrite files or stage them. Updating only the working file is insufficient; stage the generated file too. If the check reports stale metadata, rerun the commands above before retrying the commit. CI runs `pnpm run verify-provider-data` against the checkout and installed lockfile dependencies even when the local hook was not triggered.
|
|
160
182
|
|
|
161
183
|
### Replay and vocabulary
|
|
162
184
|
|
|
163
|
-
Successful assistant responses store a versioned, lossless-JSON replay state beside the provider and model that produced them — response-level facts plus one per-block entry per streamed block. At request time, `LlmRuntime` passes replay state only when the same adapter instance owns both routes; the adapter validates it and restores native response ids, provider signatures, and optional `providerThinkingLevel` effort metadata, keeping absent effort metadata absent. Replay validates the requested model identity against the assistant source and uses it to retain same-model signatures; provider-reported response models remain diagnostic metadata. Absent or unusable replay state degrades to provider-neutral content while preserving the assistant source’s required provider and model. pi-ai tool-call arguments are parsed objects, so the adapter parses input and re-stringifies output to the harness raw-JSON convention; pi-ai in-stream error events map to terminal `finish` chunks.
|
|
185
|
+
Successful assistant responses store a versioned, lossless-JSON replay state beside the provider and model that produced them — response-level facts plus one per-block entry per streamed block. At request time, `LlmRuntime` passes replay state only when the same adapter instance owns both routes; the adapter validates it and restores native response ids, provider signatures, and optional `providerThinkingLevel` effort metadata, keeping absent effort metadata absent. Replay validates the requested model identity against the assistant source and uses it to retain same-model signatures; provider-reported response models remain diagnostic metadata. Absent or unusable replay state degrades to provider-neutral content while preserving the assistant source’s required provider and model. pi-ai tool-call arguments are parsed objects, so the adapter parses input and re-stringifies output to the harness raw-JSON convention; pi-ai in-stream error events map to terminal `finish` chunks. Protocol conversion operates on request-local copies. Switching from A to B and back to A preserves the stored content, including empty text blocks, tool ids, original block order, and native replay metadata; unsupported signatures are omitted only from the foreign request.
|
|
164
186
|
|
|
165
187
|
</details>
|
|
166
188
|
|
|
@@ -187,7 +209,7 @@ Read these pages when the package-level contract is not enough. They move from t
|
|
|
187
209
|
|
|
188
210
|
#### What the model sees
|
|
189
211
|
|
|
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.
|
|
212
|
+
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. `imageRequestTarget(provider, model, image)` exposes the same request-image dimensions and byte target to screenshot consumers; adapters without image resizing preserve the normalized source.
|
|
191
213
|
|
|
192
214
|
#### Token effect
|
|
193
215
|
|
|
@@ -227,7 +249,7 @@ These limits define where the adapter stops and future work begins. They are cur
|
|
|
227
249
|
- **`headers` can carry a credential the redactor never sees** — profile resolution rejects names and values Fetch cannot represent, but the dict remains plain strings; store credentials as `apiKeyEnv` references.
|
|
228
250
|
- **Discovery does not change configured models** — adopt discovery results explicitly into the route configuration.
|
|
229
251
|
- **Anthropic discovery reads at most 1,000 models** — the request uses the API's maximum page size but does not traverse `has_more`; entries beyond the first page must be added by hand.
|
|
230
|
-
- **
|
|
252
|
+
- **Uncataloged models need an unambiguous protocol** — catalog routes preserve each model's protocol, including both Azure APIs under `azure`. A model absent from a mixed-protocol catalog needs an explicit route-level `api`, which overrides every model on the route and must be one of the supported custom protocols. For Azure deployment names, keep the catalog model ID and set `AZURE_OPENAI_DEPLOYMENT_NAME_MAP`.
|
|
231
253
|
- **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.
|
|
232
254
|
- **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`.
|
|
233
255
|
- **`GenerateOptions.stop` is unsupported** — pi-ai's common stream options cannot guarantee stop-sequence behavior across providers.
|
|
@@ -235,7 +257,7 @@ These limits define where the adapter stops and future work begins. They are cur
|
|
|
235
257
|
- **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.
|
|
236
258
|
- **Provider HTTP status is unavailable** — pi-ai error events do not expose a stable HTTP status across providers.
|
|
237
259
|
- **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.
|
|
238
|
-
- **Streamed tool-call arguments
|
|
260
|
+
- **Streamed JSON tool-call arguments avoid per-delta reparsing** — the installed pi-ai carries [`patches/@earendil-works__pi-ai@1.1.0.patch`](../../../patches/@earendil-works__pi-ai@1.1.0.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. Completion events supply parsed arguments; Responses may parse at both argument completion and output-item completion. This adapter reads only delta strings and finalized arguments. Re-apply or retire the patch on every pi-ai upgrade.
|
|
239
261
|
|
|
240
262
|
<a id="dev-note"></a>
|
|
241
263
|
### Dev Note
|
package/README.zh.md
CHANGED
|
@@ -122,6 +122,8 @@ Config 更新严格验证发生变化的 provider。初始加载将已存储的
|
|
|
122
122
|
|
|
123
123
|
只修改 `displayName`、`apiKeyEnv` 或 `baseURL` 而未解决提供方的模型配置错误时,保存仍会被拒绝。例如,OpenRouter 路由的模型 `111` 缺少 `api` 时,不能单独保存路由名称的修改:需要在同一份编辑草稿中修复或删除该模型,再保存完整的提供方配置。中间修复状态保留在草稿中,直到整条提供方配置通过校验;其他提供方可以独立保存。
|
|
124
124
|
|
|
125
|
+
模型发现会解析各路由的凭据配置。缺少必需凭据时返回空目录;其他解析错误继续抛出。使用原生认证或无需密钥的路由保留其配置的目录。此检查不会探测推理端点。
|
|
126
|
+
|
|
125
127
|
-----
|
|
126
128
|
|
|
127
129
|
<a id="understand-the-implementation"></a>
|
|
@@ -147,6 +149,7 @@ Config 更新严格验证发生变化的 provider。初始加载将已存储的
|
|
|
147
149
|
| [`src/login.ts`](src/login.ts) | 面向提供登录的已安装提供方的授权流程 |
|
|
148
150
|
| [`src/config.ts`](src/config.ts) | Profile schema、解析与可服务性校验 |
|
|
149
151
|
| [`src/catalog.ts`](src/catalog.ts) | 已安装目录集成与漂移门禁 |
|
|
152
|
+
| [`src/provider-data.ts`](src/provider-data.ts) | 配置界面使用的认证与端点生成数据 |
|
|
150
153
|
| [`src/models.ts`](src/models.ts) | 基于 pi-ai 窄入口的 model collection、静态 provider 与 reasoning level |
|
|
151
154
|
| [`src/provider.ts`](src/provider.ts) | 受支持协议表与提供方构建 |
|
|
152
155
|
| [`src/context.ts`](src/context.ts) | Harness 到 pi-ai 的上下文转换、图片处理、回放恢复 |
|
|
@@ -156,11 +159,30 @@ Config 更新严格验证发生变化的 provider。初始加载将已存储的
|
|
|
156
159
|
|
|
157
160
|
### 注册与目录
|
|
158
161
|
|
|
159
|
-
插件会在可配置提供方目录中声明它能认证的每个已安装目录提供方,并加入当前 profile 声明的每条路由,因此配置界面可以在任何路由存在之前提供完整目录。目录列出了模型却没有聊天模型的提供方(例如只有分类器模型)不进入目录,也不注册登录流程,因为本适配器只分派聊天请求。每个条目都携带 `declared`——pi-ai
|
|
162
|
+
插件会在可配置提供方目录中声明它能认证的每个已安装目录提供方,并加入当前 profile 声明的每条路由,因此配置界面可以在任何路由存在之前提供完整目录。目录列出了模型却没有聊天模型的提供方(例如只有分类器模型)不进入目录,也不注册登录流程,因为本适配器只分派聊天请求。每个条目都携带 `declared`——pi-ai 是否在该键下不提供任何内容——因为只有适配器能区分手工声明路由与收窄目录路由。目录条目以 `defaultBaseURL` 表示提供方的固定端点或全部模型共用的固定端点,以 `baseURLEnv` 表示端点配置变量,以 `nativeAuth` 表示认证变量和 OAuth 可用性。不同模型的端点和未展开的 URL 模板不会显示为单一固定默认值。路由注册具有原子性:与其他适配器冲突的候选集合会让此前路由继续服务。零路由的裸挂载即休眠姿态:settings 分节提供 profile 前不注册任何内容,分节清空时路由随之消失。
|
|
163
|
+
|
|
164
|
+
<a id="generated-provider-metadata"></a>
|
|
165
|
+
### 生成的提供方元数据
|
|
166
|
+
|
|
167
|
+
[`scripts/gen-provider-data.ts`](scripts/gen-provider-data.ts) 负责生成 [`src/provider-data.generated.ts`](src/provider-data.generated.ts)。它通过公开 resolver 和模拟的 `AuthContext` 回答,探测空配置、单个变量及变量后缀组合下的环境读取。resolver 失败时使用临时兼容入口的 `findEnvKeys`。当前所有认证变量都来自 resolver,无需认证变量补充。生成器会报告回退;缺少回退数据时生成失败。它不读取真实凭据,不启动登录流程,也不发送模型请求。探测覆盖已安装的 resolver,不能证明所有依赖具体变量值的分支。
|
|
168
|
+
|
|
169
|
+
端点数据来自公开的提供方及模型目录,以及 URL 中的大写变量占位符。Azure、Vertex 和 Bedrock 需补充认证上下文之外读取的变量。运行时读取目录不执行探测。依赖范围保持不变。用户安装的新版本新增提供方时,重新生成之前不显示其认证变量提示。已有提供方的环境变量名和端点发生变化时,也会继续使用生成快照,直到重新生成。环境提示只检查列出的凭据引用,不检查 AWS profile 或 Google 应用默认凭据等提供方管理的文件。
|
|
170
|
+
|
|
171
|
+
更新 pi-ai 或修改生成器后,先按更新的锁文件安装依赖,再从仓库根目录运行以下命令:
|
|
172
|
+
|
|
173
|
+
```sh
|
|
174
|
+
pnpm run gen-provider-data
|
|
175
|
+
pnpm run verify-provider-data
|
|
176
|
+
git add packages/llm/llm-pi-ai/src/provider-data.generated.ts
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
检查生成的 diff,并一同暂存依赖或生成器的改动。不要手工编辑生成文件。生成失败时,先解决错误再提交。
|
|
180
|
+
|
|
181
|
+
暂存 `pnpm-lock.yaml`、本包的 `package.json`、生成器或生成文件时,`pre-commit` 钩子会直接运行 `node_modules/.bin/tsx packages/llm/llm-pi-ai/scripts/gen-provider-data.ts --check --cached`,无需 Git 客户端的 PATH 中有 `pnpm`。它将暂存的生成文件与基于已安装依赖和当前生成器计算的预期数据比较,不改写或暂存文件。只更新工作区文件还不够;生成文件也必须暂存。检查报告元数据过期时,请重新运行上述命令,再尝试提交。即使本地钩子未触发,CI 仍会基于检出文件和按锁文件安装的依赖运行 `pnpm run verify-provider-data`。
|
|
160
182
|
|
|
161
183
|
### 回放与词汇
|
|
162
184
|
|
|
163
|
-
成功 assistant 响应会存储带版本的、无损 JSON 回放状态,与产生它们的提供方和模型放在一起——响应级事实加每个流式块一条逐块条目。请求时,`LlmRuntime` 仅当同一适配器实例拥有两条路由时才传递回放状态;适配器校验它并恢复原生响应 id、提供方签名与可选的 `providerThinkingLevel` effort 元数据,缺失的 effort 元数据仍保持缺失。回放会对照 assistant 来源校验请求模型身份,并用它保留同模型签名;提供方报告的响应模型仅作为诊断元数据。回放状态缺失或无法使用时会降级为提供方无关内容,并保留 assistant 来源中必需的提供方和模型。pi-ai 工具调用参数是解析后的对象,因此适配器解析输入并重新字符串化输出,以符合 harness 原始 JSON 约定;pi-ai 流内错误事件映射为终止 `finish` 分片。
|
|
185
|
+
成功 assistant 响应会存储带版本的、无损 JSON 回放状态,与产生它们的提供方和模型放在一起——响应级事实加每个流式块一条逐块条目。请求时,`LlmRuntime` 仅当同一适配器实例拥有两条路由时才传递回放状态;适配器校验它并恢复原生响应 id、提供方签名与可选的 `providerThinkingLevel` effort 元数据,缺失的 effort 元数据仍保持缺失。回放会对照 assistant 来源校验请求模型身份,并用它保留同模型签名;提供方报告的响应模型仅作为诊断元数据。回放状态缺失或无法使用时会降级为提供方无关内容,并保留 assistant 来源中必需的提供方和模型。pi-ai 工具调用参数是解析后的对象,因此适配器解析输入并重新字符串化输出,以符合 harness 原始 JSON 约定;pi-ai 流内错误事件映射为终止 `finish` 分片。 协议转换仅作用于请求副本。从 A 切换到 B 再切回 A 时,存储的内容保持完整,包括空文本块、工具 id、原始块顺序和原生回放元数据;不受支持的签名仅从发给其他协议的请求中省略。
|
|
164
186
|
|
|
165
187
|
</details>
|
|
166
188
|
|
|
@@ -187,7 +209,7 @@ Config 更新严格验证发生变化的 provider。初始加载将已存储的
|
|
|
187
209
|
|
|
188
210
|
#### 模型看到什么
|
|
189
211
|
|
|
190
|
-
所选目录模型会收到系统消息文本、对话历史、工具以及支持的采样字段。适配器按历史顺序保留后续系统消息;pi-ai 负责各协议的消息位置,并为不支持对话中系统消息的模型将它们拼接到开头。单次调用的 `GenerateOptions.system` 放在初始历史提示词之前。重复的系统消息仍会重复发送;空系统消息会被跳过,不会丢弃之前的文本。工具更新能力选择共享的历史声明投影;pi-ai 接收初始可用工具,以及按开发者消息分组的新增和受支持的移除更新。当包含工具更新的 Anthropic 请求中所有投影后的声明均为延迟加载时,初始可用工具为一个占位工具 `DeferredToolPlaceholder`,其描述要求模型永不调用它;若被调用,会得到普通的未知工具结果。Anthropic 在更新消息中以内联方式接收后续工具定义。回放会保留工具调用命名空间,以支持动态加载的 Responses 工具。每张保留图片前都会有文本,注明其完整附件 id 与实际请求尺寸。当前执行文件系统可以映射附件提供方的宿主对象时,该文本还会携带只读规范化对象路径,并警告规范化或请求投影可能缩放或重新编码上传内容。日志中的图片省略决策选中的每个出现位置都会在替换文本中保留自己的身份与当前已解析访问方式,其规范化附件不会读取或变换。当保留的出现位置按精确 base64 载荷仍超过路由的 `maxRequestImageBytes` 时,调用以 `IMAGE_OFFLOAD_REQUIRED` 失败,由 `dsh-compaction-image-offload` 用 `image/offload` 事件记录所选位置并重试步骤。提供方原生回放元数据只在适配器针对历史内容校验通过后恢复。
|
|
212
|
+
所选目录模型会收到系统消息文本、对话历史、工具以及支持的采样字段。适配器按历史顺序保留后续系统消息;pi-ai 负责各协议的消息位置,并为不支持对话中系统消息的模型将它们拼接到开头。单次调用的 `GenerateOptions.system` 放在初始历史提示词之前。重复的系统消息仍会重复发送;空系统消息会被跳过,不会丢弃之前的文本。工具更新能力选择共享的历史声明投影;pi-ai 接收初始可用工具,以及按开发者消息分组的新增和受支持的移除更新。当包含工具更新的 Anthropic 请求中所有投影后的声明均为延迟加载时,初始可用工具为一个占位工具 `DeferredToolPlaceholder`,其描述要求模型永不调用它;若被调用,会得到普通的未知工具结果。Anthropic 在更新消息中以内联方式接收后续工具定义。回放会保留工具调用命名空间,以支持动态加载的 Responses 工具。每张保留图片前都会有文本,注明其完整附件 id 与实际请求尺寸。当前执行文件系统可以映射附件提供方的宿主对象时,该文本还会携带只读规范化对象路径,并警告规范化或请求投影可能缩放或重新编码上传内容。日志中的图片省略决策选中的每个出现位置都会在替换文本中保留自己的身份与当前已解析访问方式,其规范化附件不会读取或变换。当保留的出现位置按精确 base64 载荷仍超过路由的 `maxRequestImageBytes` 时,调用以 `IMAGE_OFFLOAD_REQUIRED` 失败,由 `dsh-compaction-image-offload` 用 `image/offload` 事件记录所选位置并重试步骤。提供方原生回放元数据只在适配器针对历史内容校验通过后恢复。 `imageRequestTarget(provider, model, image)` 向截图调用方提供与模型请求一致的图片尺寸和字节目标;不缩放图片的适配器保留归一化后的原图。
|
|
191
213
|
|
|
192
214
|
#### Token 影响
|
|
193
215
|
|
|
@@ -227,7 +249,7 @@ pi-ai 事件变成 harness 的推理、文本、工具调用、用量与 finish
|
|
|
227
249
|
- **`headers` 可以携带 redactor 永远看不到的凭据**——profile 解析会拒绝 Fetch 无法表示的名称与值,但该字典仍是纯字符串;以 `apiKeyEnv` 引用存储凭据。
|
|
228
250
|
- **发现操作不更改已配置模型**——需显式将发现结果采纳到路由配置中。
|
|
229
251
|
- **Anthropic 模型发现最多读取 1,000 个模型**——请求使用 API 的最大页大小,但不会遍历 `has_more`;第一页之外的条目需要手工添加。
|
|
230
|
-
-
|
|
252
|
+
- **目录外模型需要明确的协议**——目录路由保留每个模型的协议,包括 `azure` 下的两种 Azure API。混合协议目录中不存在的模型需要显式设置路由级 `api`;该设置覆盖路由上的所有模型,且必须属于受支持的自定义协议。Azure 部署名称应通过 `AZURE_OPENAI_DEPLOYMENT_NAME_MAP` 设置,模型 ID 保持为目录中的 ID。
|
|
231
253
|
- **模态声明不受校验**——声明 `image` 而其网关不支持的模型会在提示词准入后被提供方拒绝。持久图片仍留在历史中,同一误声明模型可能再次失败;切换到纯文本模型仍然可行,因为共享 LLM 运行时会针对该请求把图片引用投影为稳定文本。
|
|
232
254
|
- **未认证路由取决于其协议**——不点名凭据的路由解析为已配置但无密钥,但 pi-ai 的 OpenAI 兼容实现仍要求 API 密钥或 `Authorization` 标头,因此无密钥本地服务器需要由 `apiKeyEnv` 引用或 `headers` 中的 `Authorization` 条目提供的占位凭据。
|
|
233
255
|
- **不支持 `GenerateOptions.stop`**——pi-ai 的通用流式选项无法跨提供方保证停止序列行为。
|
|
@@ -235,7 +257,7 @@ pi-ai 事件变成 harness 的推理、文本、工具调用、用量与 finish
|
|
|
235
257
|
- **图片只在 user 与工具结果消息中被接受**——system、developer 或 assistant 历史中的图片在两条转换路径上都会以 `UNSUPPORTED_CONTENT` 失败。
|
|
236
258
|
- **提供方 HTTP 状态不可用**——pi-ai 错误事件不跨提供方暴露稳定 HTTP 状态。
|
|
237
259
|
- **重试策略由提供方自有,而非 SDK 重试**——pi-ai SDK 重试保持禁用,因此持久 agent(智能体)步骤与 `llm/retry` 事件拥有每个可见尝试,直接 `ctx.llm.stream()` 调用仍是单次尝试。
|
|
238
|
-
-
|
|
260
|
+
- **流式 JSON 工具调用参数避免逐 delta 重复解析**——安装的 pi-ai 带有 [`patches/@earendil-works__pi-ai@1.1.0.patch`](../../../patches/@earendil-works__pi-ai@1.1.0.patch),它移除了每个流适配器中对整段累计参数 JSON 的逐 delta 重新解析(上游 [earendil-works/pi#9265](https://github.com/earendil-works/pi/issues/9265));未打补丁时,数 MB 的参数流会在事件循环上消耗 O(n²) CPU,并使进程内所有会话停滞。完成事件提供解析后的参数;Responses 可能在参数完成和输出项完成时分别解析。本适配器只读取 delta 字符串与最终参数。每次升级 pi-ai 时都要重新应用或撤销该补丁。
|
|
239
261
|
|
|
240
262
|
<a id="dev-note"></a>
|
|
241
263
|
### 开发备注
|
package/lib/index.js
CHANGED
|
@@ -1370,7 +1370,12 @@ function textOnlyContext(options, onReplayDegrade) {
|
|
|
1370
1370
|
}
|
|
1371
1371
|
return piContext(split.systemPrompt, options, messages);
|
|
1372
1372
|
}
|
|
1373
|
-
/**
|
|
1373
|
+
/**
|
|
1374
|
+
* Resolve the request target for one source under the route budgets.
|
|
1375
|
+
* @param ref - normalized source image.
|
|
1376
|
+
* @param budget - resolved route pixel and byte limits.
|
|
1377
|
+
* @returns dimensions and byte target shared by serialization and screenshot coordinate mapping.
|
|
1378
|
+
*/
|
|
1374
1379
|
function requestImageTarget(ref, budget) {
|
|
1375
1380
|
return {
|
|
1376
1381
|
...requestImageDimensions(ref.width, ref.height, budget.maxPixels),
|
|
@@ -1829,6 +1834,15 @@ var PiAiAdapter = class extends LlmAdapter {
|
|
|
1829
1834
|
super();
|
|
1830
1835
|
this.config = config;
|
|
1831
1836
|
}
|
|
1837
|
+
imageRequestTarget(provider, model, image) {
|
|
1838
|
+
const snapshot = this.current();
|
|
1839
|
+
this.modelOf(snapshot, provider, model);
|
|
1840
|
+
const profile = this.profileOf(snapshot, provider);
|
|
1841
|
+
return requestImageTarget(image, {
|
|
1842
|
+
maxPixels: profile.requestImagePixelBudget,
|
|
1843
|
+
maxBytes: profile.requestImageMaxBytes
|
|
1844
|
+
});
|
|
1845
|
+
}
|
|
1832
1846
|
/**
|
|
1833
1847
|
* The snapshot for the current profiles. Resolution memoizes its result, so
|
|
1834
1848
|
* an unchanged configuration is recognized by identity; a changed one gets a
|
|
@@ -1871,9 +1885,15 @@ var PiAiAdapter = class extends LlmAdapter {
|
|
|
1871
1885
|
return this.current().profiles.get(provider)?.retryPolicy;
|
|
1872
1886
|
}
|
|
1873
1887
|
listModels(provider) {
|
|
1874
|
-
return Promise.resolve().then(() => {
|
|
1888
|
+
return Promise.resolve().then(async () => {
|
|
1875
1889
|
const snapshot = this.current();
|
|
1876
|
-
this.profileOf(snapshot, provider);
|
|
1890
|
+
const profile = this.profileOf(snapshot, provider);
|
|
1891
|
+
try {
|
|
1892
|
+
await this.config.resolveApiKey(provider, profile);
|
|
1893
|
+
} catch (error) {
|
|
1894
|
+
if (error instanceof LlmError && error.code === "MISSING_CREDENTIAL") return [];
|
|
1895
|
+
throw error;
|
|
1896
|
+
}
|
|
1877
1897
|
return snapshot.models.getModels(provider).map((model) => ({
|
|
1878
1898
|
provider,
|
|
1879
1899
|
id: model.id,
|
|
@@ -2575,6 +2595,222 @@ function registerPiAiFlows(ctx, auth) {
|
|
|
2575
2595
|
}
|
|
2576
2596
|
}
|
|
2577
2597
|
//#endregion
|
|
2598
|
+
//#region lib/types/provider-data.generated.js
|
|
2599
|
+
/** Generated from the installed pi-ai catalog. Run pnpm gen-provider-data; do not edit. */
|
|
2600
|
+
/** Catalog endpoints and environment names; no credentials are evaluated at runtime. */
|
|
2601
|
+
const PROVIDER_DATA = {
|
|
2602
|
+
"amazon-bedrock": {
|
|
2603
|
+
env: [
|
|
2604
|
+
"AWS_BEARER_TOKEN_BEDROCK",
|
|
2605
|
+
"AWS_PROFILE",
|
|
2606
|
+
"AWS_ACCESS_KEY_ID",
|
|
2607
|
+
"AWS_SECRET_ACCESS_KEY",
|
|
2608
|
+
"AWS_CONTAINER_CREDENTIALS_RELATIVE_URI",
|
|
2609
|
+
"AWS_CONTAINER_CREDENTIALS_FULL_URI",
|
|
2610
|
+
"AWS_WEB_IDENTITY_TOKEN_FILE"
|
|
2611
|
+
],
|
|
2612
|
+
baseURLEnv: ["AWS_REGION", "AWS_DEFAULT_REGION"]
|
|
2613
|
+
},
|
|
2614
|
+
"ant-ling": {
|
|
2615
|
+
env: ["ANT_LING_API_KEY"],
|
|
2616
|
+
defaultBaseURL: "https://api.ant-ling.com/v1"
|
|
2617
|
+
},
|
|
2618
|
+
"anthropic": {
|
|
2619
|
+
env: [
|
|
2620
|
+
"ANTHROPIC_AUTH_TOKEN",
|
|
2621
|
+
"ANTHROPIC_OAUTH_TOKEN",
|
|
2622
|
+
"ANTHROPIC_API_KEY",
|
|
2623
|
+
"ANTHROPIC_FEDERATION_RULE_ID",
|
|
2624
|
+
"ANTHROPIC_ORGANIZATION_ID",
|
|
2625
|
+
"ANTHROPIC_IDENTITY_TOKEN_FILE",
|
|
2626
|
+
"ANTHROPIC_SERVICE_ACCOUNT_ID",
|
|
2627
|
+
"ANTHROPIC_WORKSPACE_ID"
|
|
2628
|
+
],
|
|
2629
|
+
defaultBaseURL: "https://api.anthropic.com"
|
|
2630
|
+
},
|
|
2631
|
+
"azure": {
|
|
2632
|
+
env: ["AZURE_OPENAI_API_KEY"],
|
|
2633
|
+
baseURLEnv: ["AZURE_OPENAI_BASE_URL", "AZURE_OPENAI_RESOURCE_NAME"]
|
|
2634
|
+
},
|
|
2635
|
+
"baseten": {
|
|
2636
|
+
env: ["BASETEN_API_KEY"],
|
|
2637
|
+
defaultBaseURL: "https://inference.baseten.co/v1"
|
|
2638
|
+
},
|
|
2639
|
+
"cerebras": {
|
|
2640
|
+
env: ["CEREBRAS_API_KEY"],
|
|
2641
|
+
defaultBaseURL: "https://api.cerebras.ai/v1"
|
|
2642
|
+
},
|
|
2643
|
+
"cloudflare-ai-gateway": {
|
|
2644
|
+
env: [
|
|
2645
|
+
"CLOUDFLARE_API_KEY",
|
|
2646
|
+
"CLOUDFLARE_ACCOUNT_ID",
|
|
2647
|
+
"CLOUDFLARE_GATEWAY_ID"
|
|
2648
|
+
],
|
|
2649
|
+
baseURLEnv: ["CLOUDFLARE_ACCOUNT_ID", "CLOUDFLARE_GATEWAY_ID"]
|
|
2650
|
+
},
|
|
2651
|
+
"cloudflare-workers-ai": {
|
|
2652
|
+
env: ["CLOUDFLARE_API_KEY", "CLOUDFLARE_ACCOUNT_ID"],
|
|
2653
|
+
baseURLEnv: ["CLOUDFLARE_ACCOUNT_ID"]
|
|
2654
|
+
},
|
|
2655
|
+
"deepseek": {
|
|
2656
|
+
env: ["DEEPSEEK_API_KEY"],
|
|
2657
|
+
defaultBaseURL: "https://api.deepseek.com"
|
|
2658
|
+
},
|
|
2659
|
+
"fireworks": {
|
|
2660
|
+
env: ["FIREWORKS_API_KEY"],
|
|
2661
|
+
defaultBaseURL: "https://api.fireworks.ai/inference"
|
|
2662
|
+
},
|
|
2663
|
+
"github-copilot": {
|
|
2664
|
+
env: ["COPILOT_GITHUB_TOKEN"],
|
|
2665
|
+
defaultBaseURL: "https://api.individual.githubcopilot.com"
|
|
2666
|
+
},
|
|
2667
|
+
"google": {
|
|
2668
|
+
env: ["GEMINI_API_KEY"],
|
|
2669
|
+
defaultBaseURL: "https://generativelanguage.googleapis.com/v1beta"
|
|
2670
|
+
},
|
|
2671
|
+
"google-vertex": {
|
|
2672
|
+
env: [
|
|
2673
|
+
"GOOGLE_CLOUD_API_KEY",
|
|
2674
|
+
"GOOGLE_APPLICATION_CREDENTIALS",
|
|
2675
|
+
"GOOGLE_CLOUD_PROJECT",
|
|
2676
|
+
"GCLOUD_PROJECT",
|
|
2677
|
+
"GOOGLE_CLOUD_LOCATION"
|
|
2678
|
+
],
|
|
2679
|
+
baseURLEnv: [
|
|
2680
|
+
"GOOGLE_CLOUD_PROJECT",
|
|
2681
|
+
"GCLOUD_PROJECT",
|
|
2682
|
+
"GOOGLE_CLOUD_LOCATION"
|
|
2683
|
+
]
|
|
2684
|
+
},
|
|
2685
|
+
"groq": {
|
|
2686
|
+
env: ["GROQ_API_KEY"],
|
|
2687
|
+
defaultBaseURL: "https://api.groq.com/openai/v1"
|
|
2688
|
+
},
|
|
2689
|
+
"huggingface": {
|
|
2690
|
+
env: ["HF_TOKEN"],
|
|
2691
|
+
defaultBaseURL: "https://router.huggingface.co/v1"
|
|
2692
|
+
},
|
|
2693
|
+
"kimi-coding": {
|
|
2694
|
+
env: ["KIMI_API_KEY"],
|
|
2695
|
+
defaultBaseURL: "https://api.kimi.com/coding"
|
|
2696
|
+
},
|
|
2697
|
+
"meta": {
|
|
2698
|
+
env: ["META_API_KEY"],
|
|
2699
|
+
defaultBaseURL: "https://api.meta.ai/v1"
|
|
2700
|
+
},
|
|
2701
|
+
"minimax": {
|
|
2702
|
+
env: ["MINIMAX_API_KEY"],
|
|
2703
|
+
defaultBaseURL: "https://api.minimax.io/anthropic"
|
|
2704
|
+
},
|
|
2705
|
+
"minimax-cn": {
|
|
2706
|
+
env: ["MINIMAX_CN_API_KEY"],
|
|
2707
|
+
defaultBaseURL: "https://api.minimaxi.com/anthropic"
|
|
2708
|
+
},
|
|
2709
|
+
"mistral": {
|
|
2710
|
+
env: ["MISTRAL_API_KEY"],
|
|
2711
|
+
defaultBaseURL: "https://api.mistral.ai"
|
|
2712
|
+
},
|
|
2713
|
+
"moonshotai": {
|
|
2714
|
+
env: ["MOONSHOT_API_KEY"],
|
|
2715
|
+
defaultBaseURL: "https://api.moonshot.ai/v1"
|
|
2716
|
+
},
|
|
2717
|
+
"moonshotai-cn": {
|
|
2718
|
+
env: ["MOONSHOT_API_KEY"],
|
|
2719
|
+
defaultBaseURL: "https://api.moonshot.cn/v1"
|
|
2720
|
+
},
|
|
2721
|
+
"nvidia": {
|
|
2722
|
+
env: ["NVIDIA_API_KEY"],
|
|
2723
|
+
defaultBaseURL: "https://integrate.api.nvidia.com/v1"
|
|
2724
|
+
},
|
|
2725
|
+
"openai": {
|
|
2726
|
+
env: ["OPENAI_API_KEY"],
|
|
2727
|
+
defaultBaseURL: "https://api.openai.com/v1"
|
|
2728
|
+
},
|
|
2729
|
+
"openai-codex": {
|
|
2730
|
+
env: [],
|
|
2731
|
+
defaultBaseURL: "https://chatgpt.com/backend-api"
|
|
2732
|
+
},
|
|
2733
|
+
"opencode": { env: ["OPENCODE_API_KEY"] },
|
|
2734
|
+
"opencode-go": { env: ["OPENCODE_API_KEY"] },
|
|
2735
|
+
"openrouter": {
|
|
2736
|
+
env: ["OPENROUTER_API_KEY"],
|
|
2737
|
+
defaultBaseURL: "https://openrouter.ai/api/v1"
|
|
2738
|
+
},
|
|
2739
|
+
"qwen-token-plan": {
|
|
2740
|
+
env: ["QWEN_TOKEN_PLAN_API_KEY"],
|
|
2741
|
+
defaultBaseURL: "https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
|
|
2742
|
+
},
|
|
2743
|
+
"qwen-token-plan-cn": {
|
|
2744
|
+
env: ["QWEN_TOKEN_PLAN_CN_API_KEY"],
|
|
2745
|
+
defaultBaseURL: "https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1"
|
|
2746
|
+
},
|
|
2747
|
+
"qwen-token-plan-individual": {
|
|
2748
|
+
env: ["QWEN_TOKEN_PLAN_API_KEY"],
|
|
2749
|
+
defaultBaseURL: "https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
|
|
2750
|
+
},
|
|
2751
|
+
"radius": {
|
|
2752
|
+
env: ["RADIUS_API_KEY"],
|
|
2753
|
+
defaultBaseURL: "https://radius.pi.dev/v1"
|
|
2754
|
+
},
|
|
2755
|
+
"together": {
|
|
2756
|
+
env: ["TOGETHER_API_KEY"],
|
|
2757
|
+
defaultBaseURL: "https://api.together.ai/v1"
|
|
2758
|
+
},
|
|
2759
|
+
"typesafe": { env: ["TYPESAFE_API_KEY"] },
|
|
2760
|
+
"vercel-ai-gateway": {
|
|
2761
|
+
env: ["AI_GATEWAY_API_KEY"],
|
|
2762
|
+
defaultBaseURL: "https://ai-gateway.vercel.sh"
|
|
2763
|
+
},
|
|
2764
|
+
"xai": {
|
|
2765
|
+
env: ["XAI_API_KEY"],
|
|
2766
|
+
defaultBaseURL: "https://api.x.ai/v1"
|
|
2767
|
+
},
|
|
2768
|
+
"xiaomi": {
|
|
2769
|
+
env: ["XIAOMI_API_KEY"],
|
|
2770
|
+
defaultBaseURL: "https://api.xiaomimimo.com/v1"
|
|
2771
|
+
},
|
|
2772
|
+
"xiaomi-token-plan-ams": {
|
|
2773
|
+
env: ["XIAOMI_TOKEN_PLAN_AMS_API_KEY"],
|
|
2774
|
+
defaultBaseURL: "https://token-plan-ams.xiaomimimo.com/v1"
|
|
2775
|
+
},
|
|
2776
|
+
"xiaomi-token-plan-cn": {
|
|
2777
|
+
env: ["XIAOMI_TOKEN_PLAN_CN_API_KEY"],
|
|
2778
|
+
defaultBaseURL: "https://token-plan-cn.xiaomimimo.com/v1"
|
|
2779
|
+
},
|
|
2780
|
+
"xiaomi-token-plan-sgp": {
|
|
2781
|
+
env: ["XIAOMI_TOKEN_PLAN_SGP_API_KEY"],
|
|
2782
|
+
defaultBaseURL: "https://token-plan-sgp.xiaomimimo.com/v1"
|
|
2783
|
+
},
|
|
2784
|
+
"zai": {
|
|
2785
|
+
env: ["ZAI_API_KEY"],
|
|
2786
|
+
defaultBaseURL: "https://api.z.ai/api/coding/paas/v4"
|
|
2787
|
+
},
|
|
2788
|
+
"zai-coding-cn": {
|
|
2789
|
+
env: ["ZAI_CODING_CN_API_KEY"],
|
|
2790
|
+
defaultBaseURL: "https://open.bigmodel.cn/api/coding/paas/v4"
|
|
2791
|
+
}
|
|
2792
|
+
};
|
|
2793
|
+
//#endregion
|
|
2794
|
+
//#region lib/types/provider-data.js
|
|
2795
|
+
/** Installed provider defaults for configuration surfaces. */
|
|
2796
|
+
/**
|
|
2797
|
+
* Return generated display metadata without executing authentication.
|
|
2798
|
+
* @param provider - Installed catalog provider, possibly from a newer consumer dependency.
|
|
2799
|
+
* @returns Known metadata, or only a fixed public endpoint for an unrecorded provider.
|
|
2800
|
+
*/
|
|
2801
|
+
function providerDefaultsOf(provider) {
|
|
2802
|
+
const data = PROVIDER_DATA[provider.id];
|
|
2803
|
+
if (data === void 0) return provider.baseUrl && !provider.baseUrl.includes("{") ? { defaultBaseURL: provider.baseUrl } : {};
|
|
2804
|
+
const { env, ...endpoint } = data;
|
|
2805
|
+
return {
|
|
2806
|
+
...endpoint,
|
|
2807
|
+
nativeAuth: {
|
|
2808
|
+
env,
|
|
2809
|
+
oauth: provider.auth.oauth !== void 0
|
|
2810
|
+
}
|
|
2811
|
+
};
|
|
2812
|
+
}
|
|
2813
|
+
//#endregion
|
|
2578
2814
|
//#region lib/types/index.js
|
|
2579
2815
|
const name = "llm-pi-ai";
|
|
2580
2816
|
const inject = ["llm"];
|
|
@@ -2595,24 +2831,28 @@ function registrationFacts(profiles) {
|
|
|
2595
2831
|
* The configurable-provider directory: every installed catalog route, plus
|
|
2596
2832
|
* every route the current profiles declare. A hand-declared route has no
|
|
2597
2833
|
* catalog entry, so without this union it would have no settings address and
|
|
2598
|
-
* configuration surfaces could neither show nor edit it.
|
|
2834
|
+
* configuration surfaces could neither show nor edit it. A catalog route also
|
|
2835
|
+
* carries its catalog endpoint and native authentication, which a settings
|
|
2836
|
+
* editor shows while the profile leaves the endpoint or the credential
|
|
2837
|
+
* reference unset.
|
|
2599
2838
|
* @param profiles - the currently resolved provider profiles.
|
|
2600
2839
|
* @returns the directory entries in catalog order, declared routes last.
|
|
2601
2840
|
*/
|
|
2602
2841
|
function directoryEntries(profiles, settingsNs) {
|
|
2603
|
-
const catalog = new Set(catalogProviderIds());
|
|
2604
2842
|
const entries = /* @__PURE__ */ new Map();
|
|
2605
2843
|
const declare = (provider, displayName, error) => {
|
|
2844
|
+
const installed = catalogProvider(provider);
|
|
2606
2845
|
entries.set(provider, {
|
|
2607
2846
|
provider,
|
|
2608
2847
|
displayName,
|
|
2609
2848
|
settingsNs,
|
|
2610
2849
|
settingsPath: ["providers", provider],
|
|
2611
|
-
declared:
|
|
2850
|
+
declared: installed === void 0,
|
|
2851
|
+
...installed === void 0 ? {} : providerDefaultsOf(installed),
|
|
2612
2852
|
...error === void 0 ? {} : { error }
|
|
2613
2853
|
});
|
|
2614
2854
|
};
|
|
2615
|
-
for (const provider of
|
|
2855
|
+
for (const provider of catalogProviderIds()) declare(provider, provider);
|
|
2616
2856
|
for (const [provider, profile] of profiles) declare(provider, profile.displayName, profile.catalogError);
|
|
2617
2857
|
return [...entries.values()];
|
|
2618
2858
|
}
|
package/lib/types/adapter.d.ts
CHANGED
|
@@ -36,7 +36,8 @@ export interface PiAiAdapterOptions {
|
|
|
36
36
|
profiles: () => ReadonlyMap<string, ResolvedPiAiProviderProfile>;
|
|
37
37
|
/**
|
|
38
38
|
* Resolve the credential for one already-resolved profile; called once per
|
|
39
|
-
* stream call and frozen for that call
|
|
39
|
+
* stream call and frozen for that call, and by `listModels`, which offers no
|
|
40
|
+
* models while it throws `MISSING_CREDENTIAL`. `undefined` defers to the route's own
|
|
40
41
|
* pi-ai auth, which for an installed catalog route is its provider-native
|
|
41
42
|
* ambient discovery; the plugin allows that only for a profile naming no
|
|
42
43
|
* credential at all, because a named reference that misses throws `LlmError`
|
|
@@ -82,6 +83,7 @@ export declare class PiAiAdapter extends LlmAdapter {
|
|
|
82
83
|
private readonly config;
|
|
83
84
|
private snapshot;
|
|
84
85
|
constructor(config: PiAiAdapterOptions);
|
|
86
|
+
imageRequestTarget(provider: string, model: string, image: ImageAttachmentRef): import("@deepseek-ai/dsh-attachment").ImageRequestTarget;
|
|
85
87
|
/**
|
|
86
88
|
* The snapshot for the current profiles. Resolution memoizes its result, so
|
|
87
89
|
* an unchanged configuration is recognized by identity; a changed one gets a
|
package/lib/types/context.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @module dsh-llm-pi-ai/context
|
|
5
5
|
*/
|
|
6
6
|
import type { GenerateOptions, ImageAttachmentAccessResolver } from '@deepseek-ai/dsh-llm';
|
|
7
|
-
import type { AttachmentStore } from '@deepseek-ai/dsh-attachment';
|
|
7
|
+
import type { AttachmentStore, ImageAttachmentRef, ImageRequestTarget } from '@deepseek-ai/dsh-attachment';
|
|
8
8
|
import type { Context as PiContext } from '@earendil-works/pi-ai';
|
|
9
9
|
/** Inputs that bind deterministic request images to one current tool execution world. */
|
|
10
10
|
export interface PiImageRequestContext {
|
|
@@ -24,6 +24,13 @@ export interface PiImageRequestBudget {
|
|
|
24
24
|
/** Encoded-byte target for one request image. */
|
|
25
25
|
maxBytes: number;
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Resolve the request target for one source under the route budgets.
|
|
29
|
+
* @param ref - normalized source image.
|
|
30
|
+
* @param budget - resolved route pixel and byte limits.
|
|
31
|
+
* @returns dimensions and byte target shared by serialization and screenshot coordinate mapping.
|
|
32
|
+
*/
|
|
33
|
+
export declare function requestImageTarget(ref: ImageAttachmentRef, budget: PiImageRequestBudget): ImageRequestTarget;
|
|
27
34
|
/**
|
|
28
35
|
* Convert text-only harness history to a synchronous pi-ai Context. Tool
|
|
29
36
|
* result names are recovered from preceding assistant tool calls.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Installed provider defaults for configuration surfaces. */
|
|
2
|
+
import type { Provider } from '@earendil-works/pi-ai';
|
|
3
|
+
import type { LlmConfigurableProvider } from '@deepseek-ai/dsh-llm';
|
|
4
|
+
/**
|
|
5
|
+
* Return generated display metadata without executing authentication.
|
|
6
|
+
* @param provider - Installed catalog provider, possibly from a newer consumer dependency.
|
|
7
|
+
* @returns Known metadata, or only a fixed public endpoint for an unrecorded provider.
|
|
8
|
+
*/
|
|
9
|
+
export declare function providerDefaultsOf(provider: Provider): Pick<LlmConfigurableProvider, 'nativeAuth' | 'defaultBaseURL' | 'baseURLEnv'>;
|
|
10
|
+
//# sourceMappingURL=provider-data.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Generated from the installed pi-ai catalog. Run pnpm gen-provider-data; do not edit. */
|
|
2
|
+
import type { BuiltinProvider } from '@earendil-works/pi-ai/providers/all';
|
|
3
|
+
import type { LlmConfigurableProvider } from '@deepseek-ai/dsh-llm';
|
|
4
|
+
type ProviderData = Pick<LlmConfigurableProvider, 'defaultBaseURL' | 'baseURLEnv'> & {
|
|
5
|
+
env: readonly string[];
|
|
6
|
+
};
|
|
7
|
+
/** Catalog endpoints and environment names; no credentials are evaluated at runtime. */
|
|
8
|
+
export declare const PROVIDER_DATA: Record<BuiltinProvider, ProviderData> & Partial<Record<string, ProviderData>>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=provider-data.generated.d.ts.map
|
package/locale/en.json
ADDED
package/locale/zh.json
ADDED
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.
|
|
4
|
+
"version": "0.2.1-alpha.4",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -19,44 +19,46 @@
|
|
|
19
19
|
"default": "./lib/index.js"
|
|
20
20
|
},
|
|
21
21
|
"./src/*": "./src/*",
|
|
22
|
-
"./package.json": "./package.json"
|
|
22
|
+
"./package.json": "./package.json",
|
|
23
|
+
"./locale/*.json": "./locale/*.json"
|
|
23
24
|
},
|
|
24
25
|
"files": [
|
|
26
|
+
"locale/*.json",
|
|
25
27
|
"lib/index.js",
|
|
26
28
|
"lib/types/**/*.d.ts"
|
|
27
29
|
],
|
|
28
30
|
"license": "MIT",
|
|
29
31
|
"peerDependencies": {
|
|
30
|
-
"@deepseek-ai/cordis": "~4.0.5-alpha.
|
|
31
|
-
"@deepseek-ai/dsh-attachment": "0.2.1-alpha.
|
|
32
|
-
"@deepseek-ai/dsh-authorization": "0.2.1-alpha.
|
|
33
|
-
"@deepseek-ai/dsh-credentials": "0.2.1-alpha.
|
|
34
|
-
"@deepseek-ai/dsh-fs": "0.2.1-alpha.
|
|
35
|
-
"@deepseek-ai/dsh-launch-environment": "0.2.1-alpha.
|
|
36
|
-
"@deepseek-ai/dsh-llm": "0.2.1-alpha.
|
|
37
|
-
"@deepseek-ai/dsh-timeout": "0.2.1-alpha.
|
|
38
|
-
"@deepseek-ai/cordis-plugin-loader": "~1.0.6-alpha.
|
|
32
|
+
"@deepseek-ai/cordis": "~4.0.5-alpha.2",
|
|
33
|
+
"@deepseek-ai/dsh-attachment": "0.2.1-alpha.4",
|
|
34
|
+
"@deepseek-ai/dsh-authorization": "0.2.1-alpha.4",
|
|
35
|
+
"@deepseek-ai/dsh-credentials": "0.2.1-alpha.4",
|
|
36
|
+
"@deepseek-ai/dsh-fs": "0.2.1-alpha.4",
|
|
37
|
+
"@deepseek-ai/dsh-launch-environment": "0.2.1-alpha.4",
|
|
38
|
+
"@deepseek-ai/dsh-llm": "0.2.1-alpha.4",
|
|
39
|
+
"@deepseek-ai/dsh-timeout": "0.2.1-alpha.4",
|
|
40
|
+
"@deepseek-ai/cordis-plugin-loader": "~1.0.6-alpha.2"
|
|
39
41
|
},
|
|
40
42
|
"dependencies": {
|
|
41
|
-
"@deepseek-ai/dsh-brand": "0.2.1-alpha.
|
|
42
|
-
"@deepseek-ai/dsh-util-values": "0.2.1-alpha.
|
|
43
|
-
"@deepseek-ai/schemastery": "~3.18.5-alpha.
|
|
44
|
-
"@earendil-works/pi-ai": "^1.0
|
|
43
|
+
"@deepseek-ai/dsh-brand": "0.2.1-alpha.4",
|
|
44
|
+
"@deepseek-ai/dsh-util-values": "0.2.1-alpha.4",
|
|
45
|
+
"@deepseek-ai/schemastery": "~3.18.5-alpha.2",
|
|
46
|
+
"@earendil-works/pi-ai": "^1.1.0"
|
|
45
47
|
},
|
|
46
48
|
"devDependencies": {
|
|
47
|
-
"@deepseek-ai/cordis": "~4.0.5-alpha.
|
|
48
|
-
"@deepseek-ai/dsh-attachment": "0.2.1-alpha.
|
|
49
|
-
"@deepseek-ai/dsh-authorization": "0.2.1-alpha.
|
|
50
|
-
"@deepseek-ai/dsh-credentials": "0.2.1-alpha.
|
|
51
|
-
"@deepseek-ai/dsh-fs": "0.2.1-alpha.
|
|
52
|
-
"@deepseek-ai/dsh-launch-environment": "0.2.1-alpha.
|
|
53
|
-
"@deepseek-ai/dsh-llm": "0.2.1-alpha.
|
|
54
|
-
"@deepseek-ai/dsh-llm-deepseek": "0.2.1-alpha.
|
|
55
|
-
"@deepseek-ai/dsh-llm-deepseek-api-key": "0.2.1-alpha.
|
|
56
|
-
"@deepseek-ai/dsh-timeout": "0.2.1-alpha.
|
|
57
|
-
"@deepseek-ai/dsh-http-proxy": "0.2.1-alpha.
|
|
58
|
-
"@deepseek-ai/cordis-plugin-loader": "~1.0.6-alpha.
|
|
59
|
-
"@deepseek-ai/dsh-settings": "0.2.1-alpha.
|
|
49
|
+
"@deepseek-ai/cordis": "~4.0.5-alpha.2",
|
|
50
|
+
"@deepseek-ai/dsh-attachment": "0.2.1-alpha.4",
|
|
51
|
+
"@deepseek-ai/dsh-authorization": "0.2.1-alpha.4",
|
|
52
|
+
"@deepseek-ai/dsh-credentials": "0.2.1-alpha.4",
|
|
53
|
+
"@deepseek-ai/dsh-fs": "0.2.1-alpha.4",
|
|
54
|
+
"@deepseek-ai/dsh-launch-environment": "0.2.1-alpha.4",
|
|
55
|
+
"@deepseek-ai/dsh-llm": "0.2.1-alpha.4",
|
|
56
|
+
"@deepseek-ai/dsh-llm-deepseek": "0.2.1-alpha.4",
|
|
57
|
+
"@deepseek-ai/dsh-llm-deepseek-api-key": "0.2.1-alpha.4",
|
|
58
|
+
"@deepseek-ai/dsh-timeout": "0.2.1-alpha.4",
|
|
59
|
+
"@deepseek-ai/dsh-http-proxy": "0.2.1-alpha.4",
|
|
60
|
+
"@deepseek-ai/cordis-plugin-loader": "~1.0.6-alpha.2",
|
|
61
|
+
"@deepseek-ai/dsh-settings": "0.2.1-alpha.4"
|
|
60
62
|
},
|
|
61
63
|
"peerDependenciesMeta": {
|
|
62
64
|
"@deepseek-ai/cordis-plugin-loader": {
|