@deepseek-ai/dsh-llm-pi-ai 0.2.3-alpha.1 → 0.2.3-alpha.3
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 +17 -14
- package/README.md +34 -4
- package/README.zh.md +34 -4
- package/lib/index.js +225 -13
- package/lib/provider-row.js +941 -0
- package/lib/types/config.d.ts +29 -0
- package/lib/types/config.d.ts.map +1 -1
- package/lib/types/config.js.map +1 -1
- package/lib/types/index.d.ts +3 -2
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js.map +1 -1
- package/lib/types/provider-row.d.ts +39 -0
- package/lib/types/provider-row.d.ts.map +1 -0
- package/lib/types/provider-row.js.map +1 -0
- package/lib/types/registry.d.ts +88 -0
- package/lib/types/registry.d.ts.map +1 -0
- package/lib/types/registry.js.map +1 -0
- package/lib/types/stream.d.ts +1 -1
- package/lib/types/stream.js.map +1 -1
- package/locale/provider/de.json +5 -0
- package/locale/provider/en.json +5 -0
- package/locale/provider/es.json +5 -0
- package/locale/provider/fr.json +5 -0
- package/locale/provider/ja.json +5 -0
- package/locale/provider/pt.json +5 -0
- package/locale/provider/ru.json +5 -0
- package/locale/provider/zh.json +5 -0
- package/package.json +41 -32
- package/src/config.ts +38 -0
- package/src/index.ts +75 -14
- package/src/provider-row.ts +53 -0
- package/src/registry.ts +218 -0
- package/src/stream.ts +2 -2
package/README.i18n.yaml
CHANGED
|
@@ -15,14 +15,17 @@
|
|
|
15
15
|
en: d152484eb41ac6b4
|
|
16
16
|
zh: 09388d293f9be9cb
|
|
17
17
|
/deepseek-ai-dsh-llm-pi-ai/use-this-package:
|
|
18
|
-
en:
|
|
19
|
-
zh:
|
|
18
|
+
en: ca6d2dfeed5d75be
|
|
19
|
+
zh: 19b97a2b800dfcb3
|
|
20
20
|
/deepseek-ai-dsh-llm-pi-ai/use-this-package/when-to-choose-it:
|
|
21
21
|
en: f3b761c7c7ecb82f
|
|
22
22
|
zh: e10d999aa348ef86
|
|
23
23
|
/deepseek-ai-dsh-llm-pi-ai/use-this-package/configure-provider-routes:
|
|
24
|
-
en:
|
|
25
|
-
zh:
|
|
24
|
+
en: dfbaeaca5a43e3af
|
|
25
|
+
zh: 9c852c203d0d3b2f
|
|
26
|
+
/deepseek-ai-dsh-llm-pi-ai/use-this-package/add-a-route-from-another-composition-layer:
|
|
27
|
+
en: 78c8cd4f901dedbc
|
|
28
|
+
zh: ea57ceceb461f934
|
|
26
29
|
/deepseek-ai-dsh-llm-pi-ai/use-this-package/sign-in-to-a-provider:
|
|
27
30
|
en: c36f66438638ae08
|
|
28
31
|
zh: 066a2fc4cb97c86f
|
|
@@ -33,8 +36,8 @@
|
|
|
33
36
|
en: b58b917e7f250aee
|
|
34
37
|
zh: aff599081bac08c3
|
|
35
38
|
/deepseek-ai-dsh-llm-pi-ai/use-this-package/change-configuration-at-runtime:
|
|
36
|
-
en:
|
|
37
|
-
zh:
|
|
39
|
+
en: 841bbf7d06489b57
|
|
40
|
+
zh: 93e6bfa1dcb694a6
|
|
38
41
|
/deepseek-ai-dsh-llm-pi-ai/use-this-package/discover-models-from-endpoints:
|
|
39
42
|
en: ac930f29006456cf
|
|
40
43
|
zh: 8d37c47f02761452
|
|
@@ -51,11 +54,11 @@
|
|
|
51
54
|
en: 615ca9834bf6544f
|
|
52
55
|
zh: 2d70b548f99000d1
|
|
53
56
|
/deepseek-ai-dsh-llm-pi-ai/understand-the-implementation/source-map:
|
|
54
|
-
en:
|
|
55
|
-
zh:
|
|
57
|
+
en: 0a5dc937ade89818
|
|
58
|
+
zh: 74d44211d3281e40
|
|
56
59
|
/deepseek-ai-dsh-llm-pi-ai/understand-the-implementation/registration-and-directory:
|
|
57
|
-
en:
|
|
58
|
-
zh:
|
|
60
|
+
en: 0ad663b4670808b0
|
|
61
|
+
zh: 7d3c996ff2dacdb6
|
|
59
62
|
/deepseek-ai-dsh-llm-pi-ai/understand-the-implementation/generated-provider-metadata:
|
|
60
63
|
en: 477d277e9ac35c8f
|
|
61
64
|
zh: 96870ca333fb6510
|
|
@@ -84,8 +87,8 @@
|
|
|
84
87
|
en: 802d7ff60a1d03ff
|
|
85
88
|
zh: c41c56e28f3e8680
|
|
86
89
|
/deepseek-ai-dsh-llm-pi-ai/model-experience/provider-response/what-the-model-sees:
|
|
87
|
-
en:
|
|
88
|
-
zh:
|
|
90
|
+
en: 4654fa63e82c0d94
|
|
91
|
+
zh: b13871a942c46c33
|
|
89
92
|
/deepseek-ai-dsh-llm-pi-ai/model-experience/provider-response/token-effect:
|
|
90
93
|
en: f002b21d0f4c3df0
|
|
91
94
|
zh: 388c8ed4676ed1af
|
|
@@ -93,8 +96,8 @@
|
|
|
93
96
|
en: b6bd570c0159ba08
|
|
94
97
|
zh: 7d2d91eea6a8d830
|
|
95
98
|
/deepseek-ai-dsh-llm-pi-ai/known-limitations-and-deferred-work:
|
|
96
|
-
en:
|
|
97
|
-
zh:
|
|
99
|
+
en: baae3d9fb6897f71
|
|
100
|
+
zh: 7886ed97959e2366
|
|
98
101
|
/deepseek-ai-dsh-llm-pi-ai/known-limitations-and-deferred-work/dev-note:
|
|
99
102
|
en: 3678dd0f6642c2a5
|
|
100
103
|
zh: 75cbdd064cc64282
|
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ English | [中文](README.zh.md)
|
|
|
25
25
|
<a id="use-this-package"></a>
|
|
26
26
|
## Use this package
|
|
27
27
|
|
|
28
|
-
Mount this plugin when a composition routes model requests through pi-ai's provider catalogs or through gateways that pi-ai's installed catalog does not describe. The `providers` dictionary
|
|
28
|
+
Mount this plugin when a composition routes model requests through pi-ai's provider catalogs or through gateways that pi-ai's installed catalog does not describe. The `providers` dictionary configures the routes of the row itself: each key is the provider route name a request selects with `GenerateOptions.provider`. A composition layer that adds a route without restating that dictionary writes a [provider row](#add-a-route-from-another-composition-layer) instead.
|
|
29
29
|
|
|
30
30
|
The adapter accepts the LLM service's [request-only user inputs](../llm/README.md#use-this-package) alongside durable history. User identity and attribution do not enter pi-ai content; assistant replay metadata and tool-call correlation remain attached to durable messages.
|
|
31
31
|
|
|
@@ -102,6 +102,29 @@ pi exposes no separate soft-byte target: the shared encoder's `imageTargetBytes`
|
|
|
102
102
|
|
|
103
103
|
The generated [configuration catalog](../../../docs/config-catalog.md#deepseek-aidsh-llm-pi-ai) is the exhaustive source for every accepted field and its JSDoc.
|
|
104
104
|
|
|
105
|
+
<a id="add-a-route-from-another-composition-layer"></a>
|
|
106
|
+
### Add a route from another composition layer
|
|
107
|
+
|
|
108
|
+
A patch that sets `providers` replaces the whole dictionary of the layers before it, so a layer that only adds a route writes a row of the provider plugin, `@deepseek-ai/dsh-llm-pi-ai/provider`. The row's config is the route key in `provider` and the profile fields of the table above beside it. A deployment's home patch adds its providers this way and leaves the dictionary in the profile patch, which the Models page writes, as it is.
|
|
109
|
+
|
|
110
|
+
```yaml
|
|
111
|
+
- insert:
|
|
112
|
+
- id: llm-pi-ai-team-gateway
|
|
113
|
+
name: '@deepseek-ai/dsh-llm-pi-ai/provider'
|
|
114
|
+
config:
|
|
115
|
+
provider: team-gateway
|
|
116
|
+
displayName: Team Gateway
|
|
117
|
+
apiKeyEnv: TEAM_GATEWAY_API_KEY
|
|
118
|
+
api: openai-completions
|
|
119
|
+
baseURL: https://gateway.team.example/v1
|
|
120
|
+
models:
|
|
121
|
+
- id: team-large
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
The adapter row serves the routes of the provider rows together with its dictionary's. When several declarations name one route, the one that comes last in the composed entry list is in effect, and the dictionary takes the position of the adapter's row: a row that a home patch or a `--patch` overlay adds replaces the dictionary entry of the same route, and that entry serves again once the row is gone. A route key selects one profile, so a deployment whose provider must be offered beside a person's own provider of the same vendor gives its row a route key of its own and a `displayName`. Only a route key that names an installed pi-ai provider inherits that provider's endpoint, protocol, and models; a row under any other key declares `api`, `baseURL`, and `models`.
|
|
125
|
+
|
|
126
|
+
Settings gives each provider row a form of its own under the row's id, and the configuration editor refuses a write to a row that a home patch or an overlay adds. The Models page recognizes that form as a pi-ai profile: it lists the row's route beside the dictionary's routes, offers no deletion for it, and opens it as a pi-ai card with the config the row runs with. A key typed there is stored under the credential reference the row names.
|
|
127
|
+
|
|
105
128
|
### Sign in to a provider
|
|
106
129
|
|
|
107
130
|
A provider pi-ai ships a login for can be signed into through the harness authorization seam: the flow offers OAuth or an interactive key prompt (a key is typed into pi-ai's own login prompt, not into the settings form), and the resulting credential is stored in the harness credential store at `llm-pi-ai/<provider id>`. The stored sign-in authenticates its route beneath any `apiKeyEnv` override and refreshes itself under the store's cross-process lock; signing out deletes the stored record. A hand-declared route key outside the record grammar — a lowercase hyphenated identifier — cannot be signed into, because a record write for it refuses with `LlmError('UNSTORABLE_PROVIDER_ID')`; such a route authenticates through `apiKeyEnv` or ambient provider settings instead.
|
|
@@ -120,7 +143,7 @@ For self-hosted Chat Completions endpoints, `thinkingTokenBudgetField` selects t
|
|
|
120
143
|
|
|
121
144
|
### Change configuration at runtime
|
|
122
145
|
|
|
123
|
-
Each operation captures the current `providers` Config reference. New or changed provider profiles are validated before form persistence; unchanged catalog failures remain editable. Route-set or retry-policy changes update registration atomically, preserving previous routes if another adapter owns a requested route.
|
|
146
|
+
Each operation captures the current `providers` Config reference. New or changed provider profiles are validated before form persistence; unchanged catalog failures remain editable. Route-set or retry-policy changes update registration atomically, preserving previous routes if another adapter owns a requested route. A provider row applies a changed profile field in place and validates the changed row before it is stored; a row whose route another adapter owns fails alone. After a configuration reload moves rows, the adapter re-evaluates which declaration of each route is in effect.
|
|
124
147
|
|
|
125
148
|
### Discover models from endpoints
|
|
126
149
|
|
|
@@ -166,6 +189,8 @@ This event covers inference calls with or without a Session id, including auxili
|
|
|
166
189
|
| [`src/index.ts`](src/index.ts) | Config snapshots, directory and route registration |
|
|
167
190
|
| [`src/auth.ts`](src/auth.ts) | The credential store and ambient auth context over the harness credential plane |
|
|
168
191
|
| [`src/login.ts`](src/login.ts) | Authorization flows for the installed providers that ship a login |
|
|
192
|
+
| [`src/registry.ts`](src/registry.ts) | `ctx.piAiProviders`: the routes that provider rows add, ordered by the composed entry list |
|
|
193
|
+
| [`src/provider-row.ts`](src/provider-row.ts) | The provider row plugin, exported as `@deepseek-ai/dsh-llm-pi-ai/provider` |
|
|
169
194
|
| [`src/config.ts`](src/config.ts) | Profile schema, resolution, and serviceability checks |
|
|
170
195
|
| [`src/catalog.ts`](src/catalog.ts) | Installed-catalog integration and drift gates |
|
|
171
196
|
| [`src/provider-data.ts`](src/provider-data.ts) | Generated authentication and endpoint metadata for configuration surfaces |
|
|
@@ -179,7 +204,7 @@ This event covers inference calls with or without a Session id, including auxili
|
|
|
179
204
|
|
|
180
205
|
### Registration and directory
|
|
181
206
|
|
|
182
|
-
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
|
|
207
|
+
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 or a provider row supplies a profile, and routes drop when both are empty. The directory addresses a route that a provider row serves by that row, whose whole config section is the profile, and every other route by its entry of the `providers` dictionary.
|
|
183
208
|
|
|
184
209
|
<a id="generated-provider-metadata"></a>
|
|
185
210
|
### Generated provider metadata
|
|
@@ -245,7 +270,7 @@ Later system messages supplied to the adapter stay out of the initial prompt, pr
|
|
|
245
270
|
|
|
246
271
|
#### What the model sees
|
|
247
272
|
|
|
248
|
-
pi-ai events become harness reasoning, text, tool-call, usage, and finish chunks. The adapter passes parsed tool arguments to the harness as raw JSON strings. If pi-ai reports invalid completed arguments, the attempt fails with `
|
|
273
|
+
pi-ai events become harness reasoning, text, tool-call, usage, and finish chunks. The adapter passes parsed tool arguments to the harness as raw JSON strings. If pi-ai reports invalid completed arguments, the attempt fails with `INVALID_TOOL_ARGUMENTS` before tool dispatch and publishes no successful replay state. The default normal retry policy retries this code; an explicit `retryableCodes` list still controls recovery.
|
|
249
274
|
|
|
250
275
|
#### Token effect
|
|
251
276
|
|
|
@@ -269,6 +294,11 @@ These limits define where the adapter stops and future work begins. They are cur
|
|
|
269
294
|
- **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.
|
|
270
295
|
- **Reset restores inherited configuration** — resetting a route supplied by a lower profile layer restores that route.
|
|
271
296
|
- **Complete Config replacement can remove inherited dictionary entries** — a field reset instead restores its inherited value.
|
|
297
|
+
- **A `providers` dictionary that cannot start stops provider rows too** — the adapter row provides the registry that provider rows register with, so when an entry of the dictionary fails resolution the adapter row fails, every provider row waits for it, and no pi-ai route serves until the dictionary is repaired. A provider row that cannot start fails alone.
|
|
298
|
+
- **A provider row under its own route key inherits no installed catalog** — only a route key that names an installed pi-ai provider takes that provider's endpoint, protocol, and models. A row under another key declares `api`, `baseURL`, and `models`, and a model it lists by id alone gets the route's default capacities and text input.
|
|
299
|
+
- **One route key serves one profile** — when the dictionary and a provider row name one route, the declaration placed last serves it and the other serves nothing while that one runs; nothing reports the overlap.
|
|
300
|
+
- **Rows that move without restarting are re-evaluated only after a profile reconciliation** — the adapter re-reads the places of the provider rows on `app-boot/config-reload`. A composition that reorders running rows by another means keeps serving the previous choice for a shared route until a provider row registers, changes, or is withdrawn.
|
|
301
|
+
- **The Models page does not tell a deployment's provider row from a person's own provider** — apart from the missing delete control the two cards look alike, and a changed field of a row that a home patch or an overlay adds is refused by the configuration editor only when it is saved. A typed key is stored, because it is a credential and not a field of the row.
|
|
272
302
|
- **`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.
|
|
273
303
|
- **Discovery does not change configured models** — adopt discovery results explicitly into the route configuration.
|
|
274
304
|
- **Anthropic and Gemini discovery read at most 1,000 models** — the request uses the API's maximum page size but does not traverse `has_more` or `nextPageToken`; entries beyond the first page must be added by hand.
|
package/README.zh.md
CHANGED
|
@@ -25,7 +25,7 @@ kind: "package-reference"
|
|
|
25
25
|
<a id="use-this-package"></a>
|
|
26
26
|
## 使用本包
|
|
27
27
|
|
|
28
|
-
当组合需要通过 pi-ai 的提供方目录、或通过 pi-ai 已安装目录未描述的网关路由模型请求时挂载本插件。`providers`
|
|
28
|
+
当组合需要通过 pi-ai 的提供方目录、或通过 pi-ai 已安装目录未描述的网关路由模型请求时挂载本插件。`providers` 字典配置本条目自己的路由:每个键都是请求用 `GenerateOptions.provider` 选择的提供方路由名。需要添加路由而又不重写该字典的配置层,改为写一个[提供方条目](#add-a-route-from-another-composition-layer)。
|
|
29
29
|
|
|
30
30
|
适配器接受 LLM 服务的[仅供请求使用的 user 输入](../llm/README.zh.md#use-this-package),并可将其与持久历史混用。user 身份与来源不会进入 pi-ai 内容;assistant 回放元数据和工具调用关联仍由持久消息携带。
|
|
31
31
|
|
|
@@ -102,6 +102,29 @@ pi 不暴露单独的软字节目标,共享编码器的 `imageTargetBytes` 等
|
|
|
102
102
|
|
|
103
103
|
生成的[配置目录](../../../docs/config-catalog.zh.md#deepseek-aidsh-llm-pi-ai)是每个受支持字段及其 JSDoc 的穷尽式真源。
|
|
104
104
|
|
|
105
|
+
<a id="add-a-route-from-another-composition-layer"></a>
|
|
106
|
+
### 由其他配置层添加路由
|
|
107
|
+
|
|
108
|
+
设置 `providers` 的 patch 会替换此前各层的整个字典,因此只需添加路由的配置层改为写一个提供方插件 `@deepseek-ai/dsh-llm-pi-ai/provider` 的条目。条目的配置是 `provider` 中的路由键,以及与它并列的上表各 profile 字段。部署方的 home patch 以这种方式添加自己的提供方,Models 页写入 profile patch 的字典保持原样。
|
|
109
|
+
|
|
110
|
+
```yaml
|
|
111
|
+
- insert:
|
|
112
|
+
- id: llm-pi-ai-team-gateway
|
|
113
|
+
name: '@deepseek-ai/dsh-llm-pi-ai/provider'
|
|
114
|
+
config:
|
|
115
|
+
provider: team-gateway
|
|
116
|
+
displayName: Team Gateway
|
|
117
|
+
apiKeyEnv: TEAM_GATEWAY_API_KEY
|
|
118
|
+
api: openai-completions
|
|
119
|
+
baseURL: https://gateway.team.example/v1
|
|
120
|
+
models:
|
|
121
|
+
- id: team-large
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
适配器条目把各提供方条目的路由与自身字典的路由一并提供。多处声明同一条路由时,组合后条目列表中位置最靠后的那处生效,字典按适配器条目所在的位置计:home patch 或 `--patch` overlay 添加的条目会替换字典中同一路由的条目,该条目移除后字典条目重新生效。一个路由键只选择一份 profile,因此部署方的提供方若要与用户自己的同厂商提供方并列出现,应给条目使用独立的路由键并设置 `displayName`。只有路由键与已安装的 pi-ai 提供方同名时,才继承该提供方的端点、协议和模型;使用其他键的条目需要声明 `api`、`baseURL` 和 `models`。
|
|
125
|
+
|
|
126
|
+
Settings 以条目 id 为每个提供方条目提供独立表单;对由 home patch 或 overlay 添加的条目的写入会被配置编辑器拒绝。Models 页把这个表单识别为 pi-ai profile:它把该条目的路由与字典的路由并列列出,不提供删除,并以 pi-ai 卡片打开,显示该条目运行时的配置。在卡片中输入的密钥保存在该条目指名的凭据引用下。
|
|
127
|
+
|
|
105
128
|
### 登录提供方
|
|
106
129
|
|
|
107
130
|
pi-ai 提供登录的提供方可以通过 harness 授权 seam 登录:流程提供 OAuth 或交互式密钥提示(密钥键入 pi-ai 自己的登录提示,而非设置表单),得到的凭据存储在 harness 凭据存储的 `llm-pi-ai/<provider id>` 记录中。存储的登录在其路由的 `apiKeyEnv` 覆盖之下完成认证,并在存储的跨进程锁下自行刷新;退出登录即删除存储记录。落在记录文法之外——小写连字符标识符——的手工声明路由键无法登录,因为对它的记录写入会以 `LlmError('UNSTORABLE_PROVIDER_ID')` 拒绝;这类路由改用 `apiKeyEnv` 或提供方 ambient 设置认证。
|
|
@@ -120,7 +143,7 @@ profile 的 `models` 列表会替换而非扩展路由的已安装目录;每
|
|
|
120
143
|
|
|
121
144
|
### 运行时更改配置
|
|
122
145
|
|
|
123
|
-
每次操作捕获当前 `providers` Config 引用。新增或修改的 provider
|
|
146
|
+
每次操作捕获当前 `providers` Config 引用。新增或修改的 provider 配置在表单持久化前验证;未更改的目录故障仍可编辑。路由集合或重试策略变化时原子更新注册;如果其他适配器已拥有所请求的路由,则保留先前路由。提供方条目的 profile 字段变化会就地生效,变更后的条目在保存前校验;路由已被其他适配器拥有的条目只让自身失败。配置重载移动条目后,适配器会重新判定每条路由由哪处声明生效。
|
|
124
147
|
|
|
125
148
|
### 从端点发现模型
|
|
126
149
|
|
|
@@ -166,6 +189,8 @@ Config 更新严格验证发生变化的 provider。初始加载将已存储的
|
|
|
166
189
|
| [`src/index.ts`](src/index.ts) | Config 快照、目录及路由注册 |
|
|
167
190
|
| [`src/auth.ts`](src/auth.ts) | 覆盖 harness 凭据平面的凭据存储与 ambient auth context |
|
|
168
191
|
| [`src/login.ts`](src/login.ts) | 面向提供登录的已安装提供方的授权流程 |
|
|
192
|
+
| [`src/registry.ts`](src/registry.ts) | `ctx.piAiProviders`:各提供方条目添加的路由,按组合后的条目列表排序 |
|
|
193
|
+
| [`src/provider-row.ts`](src/provider-row.ts) | 提供方条目插件,以 `@deepseek-ai/dsh-llm-pi-ai/provider` 导出 |
|
|
169
194
|
| [`src/config.ts`](src/config.ts) | Profile schema、解析与可服务性校验 |
|
|
170
195
|
| [`src/catalog.ts`](src/catalog.ts) | 已安装目录集成与漂移门禁 |
|
|
171
196
|
| [`src/provider-data.ts`](src/provider-data.ts) | 配置界面使用的认证与端点生成数据 |
|
|
@@ -179,7 +204,7 @@ Config 更新严格验证发生变化的 provider。初始加载将已存储的
|
|
|
179
204
|
|
|
180
205
|
### 注册与目录
|
|
181
206
|
|
|
182
|
-
插件会在可配置提供方目录中声明它能认证的每个已安装目录提供方,并加入当前 profile 声明的每条路由,因此配置界面可以在任何路由存在之前提供完整目录。目录列出了模型却没有聊天模型的提供方(例如只有分类器模型)不进入目录,也不注册登录流程,因为本适配器只分派聊天请求。每个条目都携带 `declared`——pi-ai 是否在该键下不提供任何内容——因为只有适配器能区分手工声明路由与收窄目录路由。目录条目以 `defaultBaseURL` 表示提供方的固定端点或全部模型共用的固定端点,以 `baseURLEnv` 表示端点配置变量,以 `nativeAuth` 表示认证变量和 OAuth 可用性。不同模型的端点和未展开的 URL 模板不会显示为单一固定默认值。路由注册具有原子性:与其他适配器冲突的候选集合会让此前路由继续服务。零路由的裸挂载即休眠姿态:settings
|
|
207
|
+
插件会在可配置提供方目录中声明它能认证的每个已安装目录提供方,并加入当前 profile 声明的每条路由,因此配置界面可以在任何路由存在之前提供完整目录。目录列出了模型却没有聊天模型的提供方(例如只有分类器模型)不进入目录,也不注册登录流程,因为本适配器只分派聊天请求。每个条目都携带 `declared`——pi-ai 是否在该键下不提供任何内容——因为只有适配器能区分手工声明路由与收窄目录路由。目录条目以 `defaultBaseURL` 表示提供方的固定端点或全部模型共用的固定端点,以 `baseURLEnv` 表示端点配置变量,以 `nativeAuth` 表示认证变量和 OAuth 可用性。不同模型的端点和未展开的 URL 模板不会显示为单一固定默认值。路由注册具有原子性:与其他适配器冲突的候选集合会让此前路由继续服务。零路由的裸挂载即休眠姿态:settings 分节或提供方条目提供 profile 前不注册任何内容,两者都为空时路由随之消失。提供方条目所服务的路由,目录以该条目寻址,条目的整个配置分节就是 profile;其余路由以 `providers` 字典中的条目寻址。
|
|
183
208
|
|
|
184
209
|
<a id="generated-provider-metadata"></a>
|
|
185
210
|
### 生成的提供方元数据
|
|
@@ -245,7 +270,7 @@ Anthropic 可以将每个已签名 thinking 块绑定到生成它时的请求前
|
|
|
245
270
|
|
|
246
271
|
#### 模型看到什么
|
|
247
272
|
|
|
248
|
-
pi-ai 事件变成 harness 的推理、文本、工具调用、用量与 finish 分片。适配器把解析后的工具参数以原始 JSON 字符串传给 harness。如果 pi-ai 报告已完成调用的参数无效,本次尝试会在分派工具前以 `
|
|
273
|
+
pi-ai 事件变成 harness 的推理、文本、工具调用、用量与 finish 分片。适配器把解析后的工具参数以原始 JSON 字符串传给 harness。如果 pi-ai 报告已完成调用的参数无效,本次尝试会在分派工具前以 `INVALID_TOOL_ARGUMENTS` 失败,且不发布成功的回放状态。默认的普通重试策略会重试此错误码;显式的 `retryableCodes` 列表仍然控制恢复。
|
|
249
274
|
|
|
250
275
|
#### Token 影响
|
|
251
276
|
|
|
@@ -269,6 +294,11 @@ pi-ai 事件变成 harness 的推理、文本、工具调用、用量与 finish
|
|
|
269
294
|
- **提供方原生发现经本插件的 ambient context 回答**——不点名凭据的路由交由目录提供方自身解析,它会询问环境值(`AZURE_OPENAI_API_KEY`、`AWS_PROFILE` 及各提供方自有集合)与本地凭据文件。两个问题都在这里得到回答:凭据 seam 先于进程环境被查询,文件存在性则针对宿主进程的文件系统以 `~` 展开后检查。它做不到的是*读取*凭据文件内容——自行解析 `~/.aws/credentials` 的提供方会直接读取,不经该 seam。
|
|
270
295
|
- **重置恢复继承配置**——重置下层 profile 提供的路由会恢复该路由。
|
|
271
296
|
- **完整替换 Config 可以移除继承的字典条目**——字段重置则恢复其继承值。
|
|
297
|
+
- **`providers` 字典无法启动时,提供方条目也随之停止**——适配器条目提供各提供方条目注册所用的注册表,因此字典中某个条目解析失败时适配器条目失败,所有提供方条目等待它,字典修复前没有任何 pi-ai 路由可用。无法启动的提供方条目只让自身失败。
|
|
298
|
+
- **使用独立路由键的提供方条目不继承已安装目录**——只有与已安装 pi-ai 提供方同名的路由键才取得该提供方的端点、协议和模型。使用其他键的条目需要声明 `api`、`baseURL` 和 `models`,只按 id 列出的模型取得该路由的默认容量和文本输入。
|
|
299
|
+
- **一个路由键只服务一份 profile**——字典与提供方条目声明同一条路由时,位置最靠后的声明提供服务,另一处在其运行期间不提供任何服务;这种重叠不会被报告。
|
|
300
|
+
- **不重启而移动的条目只在 profile 重新组合后重新判定**——适配器在 `app-boot/config-reload` 时重新读取各提供方条目的位置。以其他方式调整运行中条目顺序的组合,在有提供方条目注册、变更或撤回之前,共享路由仍由此前选定的声明提供服务。
|
|
301
|
+
- **Models 页不区分部署方的提供方条目与用户自己的提供方**——除了没有删除控件之外,两种卡片外观相同;修改由 home patch 或 overlay 添加的条目的字段,要到保存时才被配置编辑器拒绝。输入的密钥可以保存,因为它是凭据,不是条目的字段。
|
|
272
302
|
- **`headers` 可以携带 redactor 永远看不到的凭据**——profile 解析会拒绝 Fetch 无法表示的名称与值,但该字典仍是纯字符串;以 `apiKeyEnv` 引用存储凭据。
|
|
273
303
|
- **发现操作不更改已配置模型**——需显式将发现结果采纳到路由配置中。
|
|
274
304
|
- **Anthropic 与 Gemini 模型发现最多读取 1,000 个模型**——请求使用 API 的最大页大小,但不会遍历 `has_more` 或 `nextPageToken`;第一页之外的条目需要手工添加。
|
package/lib/index.js
CHANGED
|
@@ -17,6 +17,7 @@ import { createHash } from "node:crypto";
|
|
|
17
17
|
import { homedir } from "node:os";
|
|
18
18
|
import { access } from "node:fs/promises";
|
|
19
19
|
import { resolve } from "node:path";
|
|
20
|
+
import { Service } from "@deepseek-ai/cordis";
|
|
20
21
|
//#region lib/types/replay.js
|
|
21
22
|
/**
|
|
22
23
|
* Durable pi-ai replay metadata and assistant-history reconstruction.
|
|
@@ -1091,6 +1092,12 @@ const profile = z.object({
|
|
|
1091
1092
|
});
|
|
1092
1093
|
/** Runtime schema for {@link Config}. */
|
|
1093
1094
|
const Config = z.object({ providers: z.dict(profile).default({}).volatile() });
|
|
1095
|
+
/** Field schemas of one route's profile, which an entry of the `providers` dict and a provider row share. */
|
|
1096
|
+
const profileFields = profile.dict;
|
|
1097
|
+
z.object({
|
|
1098
|
+
provider: z.string().required(),
|
|
1099
|
+
...Object.fromEntries(Object.entries(profileFields).map(([field, schema]) => [field, schema.volatile()]))
|
|
1100
|
+
});
|
|
1094
1101
|
/**
|
|
1095
1102
|
* Reject new or changed provider profiles that cannot be served. Unchanged
|
|
1096
1103
|
* stored profiles may need repair after a catalog upgrade and do not block
|
|
@@ -1583,7 +1590,7 @@ function mapStopReason(message, contextWindow) {
|
|
|
1583
1590
|
* @param prefixDigest - request-context digest recorded for durable replay.
|
|
1584
1591
|
* @returns the harness chunks, ending with `usage` then `finish`; throws
|
|
1585
1592
|
* `LlmError` (`STREAM_CLOSED`) if the source ends without a terminal event, or
|
|
1586
|
-
* `
|
|
1593
|
+
* `INVALID_TOOL_ARGUMENTS` when completed tool arguments are invalid. Length-limited
|
|
1587
1594
|
* output retains its terminal reason so the assembler can discard incomplete calls.
|
|
1588
1595
|
*/
|
|
1589
1596
|
async function* toStreamChunks(events, contextWindow, callerSignal, requestedModel, prefixDigest) {
|
|
@@ -1686,7 +1693,7 @@ async function* toStreamChunks(events, contextWindow, callerSignal, requestedMod
|
|
|
1686
1693
|
type: "usage",
|
|
1687
1694
|
usage: mapUsage(event.message.usage)
|
|
1688
1695
|
};
|
|
1689
|
-
if (argumentsError !== void 0 && event.message.stopReason !== "length") throw new LlmError(argumentsError, "
|
|
1696
|
+
if (argumentsError !== void 0 && event.message.stopReason !== "length") throw new LlmError(argumentsError, "INVALID_TOOL_ARGUMENTS");
|
|
1690
1697
|
yield {
|
|
1691
1698
|
type: "finish",
|
|
1692
1699
|
reason: mapStopReason(event.message, contextWindow),
|
|
@@ -3023,6 +3030,167 @@ function providerDefaultsOf(provider) {
|
|
|
3023
3030
|
};
|
|
3024
3031
|
}
|
|
3025
3032
|
//#endregion
|
|
3033
|
+
//#region lib/types/registry.js
|
|
3034
|
+
/**
|
|
3035
|
+
* The provider routes that plugin rows add to one pi-ai adapter, beside the routes of the adapter row's own
|
|
3036
|
+
* `providers` dict.
|
|
3037
|
+
*
|
|
3038
|
+
* Several rows may name one route, and the dict may name it too, which is how a later composition layer
|
|
3039
|
+
* replaces a provider that an earlier layer configures. The declaration that comes last in the composed entry
|
|
3040
|
+
* list is in effect, and the dict takes the position of the adapter's row; the other declarations stay
|
|
3041
|
+
* registered and take over when that one is withdrawn.
|
|
3042
|
+
*
|
|
3043
|
+
* @module dsh-llm-pi-ai/registry
|
|
3044
|
+
*/
|
|
3045
|
+
/** Position of a plugin's row in the composed entry list: its index in each enclosing list, outermost first. */
|
|
3046
|
+
function position(caller) {
|
|
3047
|
+
const path = [];
|
|
3048
|
+
for (let entry = caller.fiber.entry; entry !== void 0; entry = entry.parent.ctx.fiber.entry) {
|
|
3049
|
+
const { id } = entry.options;
|
|
3050
|
+
path.unshift(entry.parent.data.findIndex((options) => options.id === id));
|
|
3051
|
+
}
|
|
3052
|
+
return path;
|
|
3053
|
+
}
|
|
3054
|
+
/** Order two positions as their rows appear in the composed entry list; a plugin outside any list comes first. */
|
|
3055
|
+
function comparePositions(left, right) {
|
|
3056
|
+
for (let index = 0; index < left.length && index < right.length; index++) if (left[index] !== right[index]) return left[index] - right[index];
|
|
3057
|
+
return left.length - right.length;
|
|
3058
|
+
}
|
|
3059
|
+
function sameRoutes(left, right) {
|
|
3060
|
+
const others = [...right];
|
|
3061
|
+
return left.size === right.size && [...left].every(([provider, route], index) => others[index]?.[0] === provider && others[index][1] === route);
|
|
3062
|
+
}
|
|
3063
|
+
/**
|
|
3064
|
+
* Lay an adapter row's own dict between the rows that precede that row and the rows that follow it.
|
|
3065
|
+
* @param own - resolved profiles of the adapter row's dict.
|
|
3066
|
+
* @param rows - routes of the registered rows.
|
|
3067
|
+
* @returns the profile in effect for each route, and the entry id of the row that serves a route; a route that
|
|
3068
|
+
* the dict serves, or a plugin mounted outside a Loader entry, has no row.
|
|
3069
|
+
*/
|
|
3070
|
+
function routesInEffect(own, rows) {
|
|
3071
|
+
const profiles = /* @__PURE__ */ new Map();
|
|
3072
|
+
const ids = /* @__PURE__ */ new Map();
|
|
3073
|
+
const lay = (provider, profile, row) => {
|
|
3074
|
+
profiles.set(provider, profile);
|
|
3075
|
+
if (row === void 0) ids.delete(provider);
|
|
3076
|
+
else ids.set(provider, row);
|
|
3077
|
+
};
|
|
3078
|
+
for (const [provider, route] of rows.before) lay(provider, route.profile, route.row);
|
|
3079
|
+
for (const [provider, profile] of own) lay(provider, profile, void 0);
|
|
3080
|
+
for (const [provider, route] of rows.after) lay(provider, route.profile, route.row);
|
|
3081
|
+
return {
|
|
3082
|
+
profiles,
|
|
3083
|
+
rows: ids
|
|
3084
|
+
};
|
|
3085
|
+
}
|
|
3086
|
+
function resolve$1(provider, profile) {
|
|
3087
|
+
return resolveProfiles({ [provider]: structuredClone(profile) }, "deferred").get(provider);
|
|
3088
|
+
}
|
|
3089
|
+
/** Keeps every provider registration and publishes, per route, the row in effect on each side of its owner's row. */
|
|
3090
|
+
var PiAiProviderRegistry = class extends Service {
|
|
3091
|
+
owner;
|
|
3092
|
+
publish;
|
|
3093
|
+
registrations = /* @__PURE__ */ new Set();
|
|
3094
|
+
sequence = 0;
|
|
3095
|
+
published = {
|
|
3096
|
+
before: /* @__PURE__ */ new Map(),
|
|
3097
|
+
after: /* @__PURE__ */ new Map()
|
|
3098
|
+
};
|
|
3099
|
+
/**
|
|
3100
|
+
* @param owner - the adapter plugin's context, which owns the service.
|
|
3101
|
+
* @param publish - applies the routes of the rows in effect to the adapter's routes and directory; called
|
|
3102
|
+
* only when they changed. A throw rejects the change that produced them and must leave the previously
|
|
3103
|
+
* published routes applied.
|
|
3104
|
+
*/
|
|
3105
|
+
constructor(owner, publish) {
|
|
3106
|
+
super(owner, "piAiProviders");
|
|
3107
|
+
this.owner = owner;
|
|
3108
|
+
this.publish = publish;
|
|
3109
|
+
owner.on("app-boot/config-reload", () => {
|
|
3110
|
+
try {
|
|
3111
|
+
this.commit();
|
|
3112
|
+
} catch (error) {
|
|
3113
|
+
owner.logger.error("llm-pi-ai: the provider rows in effect after a configuration reload could not be applied");
|
|
3114
|
+
owner.logger.error(error);
|
|
3115
|
+
}
|
|
3116
|
+
});
|
|
3117
|
+
}
|
|
3118
|
+
register(provider, profile) {
|
|
3119
|
+
const caller = this.ctx;
|
|
3120
|
+
const row = caller.fiber.entry?.options.id;
|
|
3121
|
+
const routeOf = (next) => ({
|
|
3122
|
+
profile: resolve$1(provider, next),
|
|
3123
|
+
...row === void 0 ? {} : { row }
|
|
3124
|
+
});
|
|
3125
|
+
let registration;
|
|
3126
|
+
const dispose = caller.effect(function* () {
|
|
3127
|
+
const added = {
|
|
3128
|
+
provider,
|
|
3129
|
+
route: routeOf(profile),
|
|
3130
|
+
caller,
|
|
3131
|
+
sequence: this.sequence++
|
|
3132
|
+
};
|
|
3133
|
+
this.registrations.add(added);
|
|
3134
|
+
try {
|
|
3135
|
+
this.commit();
|
|
3136
|
+
} catch (error) {
|
|
3137
|
+
this.registrations.delete(added);
|
|
3138
|
+
throw error;
|
|
3139
|
+
}
|
|
3140
|
+
registration = added;
|
|
3141
|
+
yield () => {
|
|
3142
|
+
registration = void 0;
|
|
3143
|
+
this.registrations.delete(added);
|
|
3144
|
+
if (this.owner.fiber.state === 2) this.commit();
|
|
3145
|
+
};
|
|
3146
|
+
}.bind(this), "piAiProviders.register()");
|
|
3147
|
+
const handle = (() => void dispose());
|
|
3148
|
+
handle.replace = (next) => {
|
|
3149
|
+
if (registration === void 0) throw new Error("llm-pi-ai: a withdrawn provider registration cannot replace its profile");
|
|
3150
|
+
const current = registration;
|
|
3151
|
+
const previous = current.route;
|
|
3152
|
+
current.route = routeOf(next);
|
|
3153
|
+
try {
|
|
3154
|
+
this.commit();
|
|
3155
|
+
} catch (error) {
|
|
3156
|
+
current.route = previous;
|
|
3157
|
+
throw error;
|
|
3158
|
+
}
|
|
3159
|
+
};
|
|
3160
|
+
return handle;
|
|
3161
|
+
}
|
|
3162
|
+
/**
|
|
3163
|
+
* Publish the routes of the rows in effect when a change to the registrations, or to the places of their rows,
|
|
3164
|
+
* changed them; the caller undoes a registration change whose publication throws.
|
|
3165
|
+
*/
|
|
3166
|
+
commit() {
|
|
3167
|
+
const owner = position(this.owner);
|
|
3168
|
+
const ordered = [...this.registrations].map((registration) => ({
|
|
3169
|
+
registration,
|
|
3170
|
+
position: position(registration.caller)
|
|
3171
|
+
})).sort((left, right) => comparePositions(left.position, right.position) || left.registration.sequence - right.registration.sequence);
|
|
3172
|
+
const before = /* @__PURE__ */ new Map();
|
|
3173
|
+
const after = /* @__PURE__ */ new Map();
|
|
3174
|
+
for (const { registration, position: place } of ordered) {
|
|
3175
|
+
const side = comparePositions(place, owner) < 0 ? before : after;
|
|
3176
|
+
side.delete(registration.provider);
|
|
3177
|
+
side.set(registration.provider, registration.route);
|
|
3178
|
+
}
|
|
3179
|
+
if (sameRoutes(before, this.published.before) && sameRoutes(after, this.published.after)) return;
|
|
3180
|
+
const previous = this.published;
|
|
3181
|
+
this.published = {
|
|
3182
|
+
before,
|
|
3183
|
+
after
|
|
3184
|
+
};
|
|
3185
|
+
try {
|
|
3186
|
+
this.publish(this.published);
|
|
3187
|
+
} catch (error) {
|
|
3188
|
+
this.published = previous;
|
|
3189
|
+
throw error;
|
|
3190
|
+
}
|
|
3191
|
+
}
|
|
3192
|
+
};
|
|
3193
|
+
//#endregion
|
|
3026
3194
|
//#region lib/types/index.js
|
|
3027
3195
|
const name = "llm-pi-ai";
|
|
3028
3196
|
const inject = ["llm"];
|
|
@@ -3043,22 +3211,33 @@ function registrationFacts(profiles) {
|
|
|
3043
3211
|
* The configurable-provider directory: every installed catalog route, plus
|
|
3044
3212
|
* every route the current profiles declare. A hand-declared route has no
|
|
3045
3213
|
* catalog entry, so without this union it would have no settings address and
|
|
3046
|
-
* configuration surfaces could neither show nor edit it. A
|
|
3214
|
+
* configuration surfaces could neither show nor edit it. A route that a
|
|
3215
|
+
* provider row serves is addressed by that row, whose whole config section is
|
|
3216
|
+
* the profile; every other route by its entry of this plugin's dict, where a
|
|
3217
|
+
* configuration surface adds a catalog route. A catalog route also
|
|
3047
3218
|
* carries its catalog endpoint and native authentication, which a settings
|
|
3048
3219
|
* editor shows while the profile leaves the endpoint or the credential
|
|
3049
3220
|
* reference unset.
|
|
3050
3221
|
* @param profiles - the currently resolved provider profiles.
|
|
3222
|
+
* @param rows - entry id of the provider row in effect for each route that one serves.
|
|
3223
|
+
* @param settingsNs - entry id of this plugin's row.
|
|
3051
3224
|
* @returns the directory entries in catalog order, declared routes last.
|
|
3052
3225
|
*/
|
|
3053
|
-
function directoryEntries(profiles, settingsNs) {
|
|
3226
|
+
function directoryEntries(profiles, rows, settingsNs) {
|
|
3054
3227
|
const entries = /* @__PURE__ */ new Map();
|
|
3055
3228
|
const declare = (provider, displayName, error) => {
|
|
3056
3229
|
const installed = catalogProvider(provider);
|
|
3230
|
+
const row = rows.get(provider);
|
|
3057
3231
|
entries.set(provider, {
|
|
3058
3232
|
provider,
|
|
3059
3233
|
displayName,
|
|
3060
|
-
|
|
3061
|
-
|
|
3234
|
+
...row === void 0 ? {
|
|
3235
|
+
settingsNs,
|
|
3236
|
+
settingsPath: ["providers", provider]
|
|
3237
|
+
} : {
|
|
3238
|
+
settingsNs: row,
|
|
3239
|
+
settingsPath: []
|
|
3240
|
+
},
|
|
3062
3241
|
declared: installed === void 0,
|
|
3063
3242
|
...installed === void 0 ? {} : providerDefaultsOf(installed),
|
|
3064
3243
|
...error === void 0 ? {} : { error }
|
|
@@ -3068,7 +3247,7 @@ function directoryEntries(profiles, settingsNs) {
|
|
|
3068
3247
|
for (const [provider, profile] of profiles) declare(provider, profile.displayName, profile.catalogError);
|
|
3069
3248
|
return [...entries.values()];
|
|
3070
3249
|
}
|
|
3071
|
-
/** Register one generic pi-ai adapter for
|
|
3250
|
+
/** Register one generic pi-ai adapter for the routes of its dict and of the provider rows. */
|
|
3072
3251
|
function apply(ctx, config) {
|
|
3073
3252
|
ctx.inject(["settings"], (child) => {
|
|
3074
3253
|
child.effect(() => child.settings.configure({ auto: false }, ctx.fiber));
|
|
@@ -3077,15 +3256,14 @@ function apply(ctx, config) {
|
|
|
3077
3256
|
let lastRaw;
|
|
3078
3257
|
let memoized;
|
|
3079
3258
|
/**
|
|
3080
|
-
* The resolved profiles
|
|
3081
|
-
* snapshot's identity
|
|
3082
|
-
* stable across operations that observe no change.
|
|
3259
|
+
* The resolved profiles of this row's own dict, memoized by the raw
|
|
3260
|
+
* snapshot's identity.
|
|
3083
3261
|
*
|
|
3084
3262
|
* Catalog diagnostics stay in the snapshot beside serviceable models, so
|
|
3085
3263
|
* stored configuration remains visible after an installed catalog changes.
|
|
3086
3264
|
* Scalar configuration errors still reject resolution.
|
|
3087
3265
|
*/
|
|
3088
|
-
const
|
|
3266
|
+
const own = () => {
|
|
3089
3267
|
const raw = config.providers.get();
|
|
3090
3268
|
if (raw === lastRaw && memoized !== void 0) return memoized;
|
|
3091
3269
|
const next = resolveProfiles(structuredClone(raw), "deferred");
|
|
@@ -3093,7 +3271,28 @@ function apply(ctx, config) {
|
|
|
3093
3271
|
memoized = next;
|
|
3094
3272
|
return next;
|
|
3095
3273
|
};
|
|
3096
|
-
|
|
3274
|
+
own();
|
|
3275
|
+
/** Routes of the provider rows, replaced as one value whenever a row registers, changes, moves, or is withdrawn. */
|
|
3276
|
+
let rows = {
|
|
3277
|
+
before: /* @__PURE__ */ new Map(),
|
|
3278
|
+
after: /* @__PURE__ */ new Map()
|
|
3279
|
+
};
|
|
3280
|
+
let laid;
|
|
3281
|
+
/**
|
|
3282
|
+
* The routes in effect over the dict and the provider rows, memoized by the
|
|
3283
|
+
* identities of both — which is also what makes the adapter's own snapshot
|
|
3284
|
+
* stable across operations that observe no change.
|
|
3285
|
+
*/
|
|
3286
|
+
const routes = () => {
|
|
3287
|
+
const dict = own();
|
|
3288
|
+
if (laid?.own !== dict || laid.rows !== rows) laid = {
|
|
3289
|
+
own: dict,
|
|
3290
|
+
rows,
|
|
3291
|
+
routes: routesInEffect(dict, rows)
|
|
3292
|
+
};
|
|
3293
|
+
return laid.routes;
|
|
3294
|
+
};
|
|
3295
|
+
const profiles = () => routes().profiles;
|
|
3097
3296
|
ctx.on("internal/config", (fiber, next) => {
|
|
3098
3297
|
const raw = next();
|
|
3099
3298
|
if (fiber !== ctx.fiber) return raw;
|
|
@@ -3140,7 +3339,7 @@ function apply(ctx, config) {
|
|
|
3140
3339
|
let directory;
|
|
3141
3340
|
let directoryFacts;
|
|
3142
3341
|
const ensureDirectory = () => {
|
|
3143
|
-
const entries = directoryEntries(profiles(), settingsNs);
|
|
3342
|
+
const entries = directoryEntries(profiles(), routes().rows, settingsNs);
|
|
3144
3343
|
if (deepEqualJson(entries, directoryFacts)) return;
|
|
3145
3344
|
if (directory === void 0) directory = ctx.llm.registerConfigurableProviders(entries);
|
|
3146
3345
|
else directory.replace(entries);
|
|
@@ -3186,6 +3385,19 @@ function apply(ctx, config) {
|
|
|
3186
3385
|
ctx.logger.error(error);
|
|
3187
3386
|
}
|
|
3188
3387
|
});
|
|
3388
|
+
new PiAiProviderRegistry(ctx, (next) => {
|
|
3389
|
+
const previous = rows;
|
|
3390
|
+
rows = next;
|
|
3391
|
+
try {
|
|
3392
|
+
ensureRegistrationFacts();
|
|
3393
|
+
ensureDirectory();
|
|
3394
|
+
} catch (error) {
|
|
3395
|
+
rows = previous;
|
|
3396
|
+
ensureRegistrationFacts();
|
|
3397
|
+
ensureDirectory();
|
|
3398
|
+
throw error;
|
|
3399
|
+
}
|
|
3400
|
+
});
|
|
3189
3401
|
}
|
|
3190
3402
|
//#endregion
|
|
3191
3403
|
export { Config, PiAiAdapter, apply, inject, name, supportedProtocols };
|