@deepseek-ai/dsh-web 0.2.2-alpha.3 → 0.2.2-rc.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 +18 -12
- package/README.md +38 -7
- package/README.zh.md +38 -7
- package/lib/index.js +220 -112
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +178 -0
- package/lib/typert.remote-client.d.ts +25 -0
- package/lib/typert.remote-client.d.ts.map +1 -0
- package/lib/typert.remote-client.js +45 -0
- package/lib/types/index.d.ts +24 -11
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +277 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/types.d.ts +57 -7
- package/lib/types/types.d.ts.map +1 -0
- package/lib/types/types.js +18 -0
- package/lib/types/types.js.map +1 -0
- package/package.json +30 -7
- package/src/index.ts +305 -0
- package/src/types.ts +202 -0
package/README.i18n.yaml
CHANGED
|
@@ -21,14 +21,20 @@
|
|
|
21
21
|
en: 557a8a3f2dfebae4
|
|
22
22
|
zh: 3c85382484e4b717
|
|
23
23
|
/deepseek-ai-dsh-web/use-this-package/minimal-configuration:
|
|
24
|
-
en:
|
|
25
|
-
zh:
|
|
24
|
+
en: cb5267c425eef938
|
|
25
|
+
zh: 26c3c04ee28c8c01
|
|
26
26
|
/deepseek-ai-dsh-web/use-this-package/searching-and-fetching:
|
|
27
27
|
en: 713944abf68263cd
|
|
28
28
|
zh: c428cb53b8708e99
|
|
29
29
|
/deepseek-ai-dsh-web/use-this-package/provider-selection:
|
|
30
|
-
en:
|
|
31
|
-
zh:
|
|
30
|
+
en: 5973c94b327aa8ae
|
|
31
|
+
zh: cbc15a2925f70347
|
|
32
|
+
/deepseek-ai-dsh-web/use-this-package/listing-providers:
|
|
33
|
+
en: 229aed591f2194e0
|
|
34
|
+
zh: d62b4b41d26be94c
|
|
35
|
+
/deepseek-ai-dsh-web/use-this-package/listing-providers/add-another-provider:
|
|
36
|
+
en: cf0c7f95d944be5a
|
|
37
|
+
zh: 1a2b3796acec7c29
|
|
32
38
|
/deepseek-ai-dsh-web/use-this-package/search-and-fetch-readiness:
|
|
33
39
|
en: 30fec45dfb417eed
|
|
34
40
|
zh: 253f887aeb3deeea
|
|
@@ -42,8 +48,8 @@
|
|
|
42
48
|
en: c4d5437cfb1e2157
|
|
43
49
|
zh: 411b1b398de73426
|
|
44
50
|
/deepseek-ai-dsh-web/understand-the-implementation/source-map:
|
|
45
|
-
en:
|
|
46
|
-
zh:
|
|
51
|
+
en: 2d8d315dba3b5f1e
|
|
52
|
+
zh: dca7443453d96ba7
|
|
47
53
|
/deepseek-ai-dsh-web/understand-the-implementation/data-model:
|
|
48
54
|
en: 300340ff8465a03e
|
|
49
55
|
zh: 34ab66eb6969dc94
|
|
@@ -51,8 +57,8 @@
|
|
|
51
57
|
en: d5cd4851d81892e6
|
|
52
58
|
zh: 18266b0bc8b1d1ae
|
|
53
59
|
/deepseek-ai-dsh-web/further-exploration:
|
|
54
|
-
en:
|
|
55
|
-
zh:
|
|
60
|
+
en: f969a627e746906d
|
|
61
|
+
zh: e6ffbe79fc539cec
|
|
56
62
|
/deepseek-ai-dsh-web/model-experience:
|
|
57
63
|
en: cbc7053cba173085
|
|
58
64
|
zh: 73828c1f1ec82d50
|
|
@@ -60,11 +66,11 @@
|
|
|
60
66
|
en: 40294c1c31b74824
|
|
61
67
|
zh: d75d48f485447a74
|
|
62
68
|
/deepseek-ai-dsh-web/known-limitations-and-deferred-work:
|
|
63
|
-
en:
|
|
64
|
-
zh:
|
|
69
|
+
en: 12624cc86e6bc4e9
|
|
70
|
+
zh: c86de7d9b5302601
|
|
65
71
|
/deepseek-ai-dsh-web/known-limitations-and-deferred-work/dev-note:
|
|
66
72
|
en: 7f775cc79dbce94b
|
|
67
73
|
zh: 12b8f68f9e7c48ca
|
|
68
74
|
/deepseek-ai-dsh-web/known-limitations-and-deferred-work/dev-note/future-observing-provider-state:
|
|
69
|
-
en:
|
|
70
|
-
zh:
|
|
75
|
+
en: a4ece830bb4d86ba
|
|
76
|
+
zh: 6e6fa8b9b407f142
|
package/README.md
CHANGED
|
@@ -33,11 +33,13 @@ Choose the service when a plugin or tool must search or fetch without hard-codin
|
|
|
33
33
|
|
|
34
34
|
### Minimal configuration
|
|
35
35
|
|
|
36
|
-
Load the service and let a single mounted backend auto-select, or pin a provider id with `searchProvider`/`fetchProvider`. The environment variables `$DSH_WEB_SEARCH_PROVIDER` and `$DSH_WEB_FETCH_PROVIDER` feed the same fields and are not a separate priority chain.
|
|
36
|
+
Load the service and let a single mounted backend auto-select, or pin a provider id with `searchProvider`/`fetchProvider`. The environment variables `$DSH_WEB_SEARCH_PROVIDER` and `$DSH_WEB_FETCH_PROVIDER` feed the same fields and are not a separate priority chain. Both backends below register a fetch provider, so the example pins `fetchProvider: http`.
|
|
37
37
|
|
|
38
38
|
```yaml
|
|
39
39
|
- name: '@deepseek-ai/dsh-web'
|
|
40
|
-
|
|
40
|
+
config:
|
|
41
|
+
fetchProvider: http
|
|
42
|
+
- name: '@deepseek-ai/dsh-web-deepseek-api'
|
|
41
43
|
- name: '@deepseek-ai/dsh-web-fetch-http'
|
|
42
44
|
```
|
|
43
45
|
|
|
@@ -75,8 +77,37 @@ Each call resolves its provider at execution time, and registration or load orde
|
|
|
75
77
|
| no id, no usable provider | `WEB_PROVIDER_UNAVAILABLE` |
|
|
76
78
|
| no id, multiple usable providers | `WEB_PROVIDER_AMBIGUOUS` |
|
|
77
79
|
|
|
80
|
+
The shipped `deepseek-official` and `deepseek-search-api` search ids select legacy Messages search and the direct Search API respectively.
|
|
81
|
+
|
|
78
82
|
A provider's availability is a cheap local check — for example whether its API key is present — and never makes network calls, so selection stays fast and deterministic.
|
|
79
83
|
|
|
84
|
+
<a id="listing-providers"></a>
|
|
85
|
+
### Listing providers
|
|
86
|
+
|
|
87
|
+
`listProviders()` returns every registered search and fetch provider as `{ id, title?, description? }` entries, each list in registration order; it lists unavailable providers too, because a picker shows what can be pinned. `title` is the provider's optional display name, and a picker shows `id` when it is absent. `description` is optional `LocalizedText` from `dsh-package-manifest`, a plain string or translations keyed by lowercase language id with a required `en` entry, stating what the provider suits and what it costs or cannot do; a picker shows it under the selected provider and shows nothing when it is absent. Each registration and each disposal emits the payload-free `web/providers-changed` event after the registry changes, and observer failures cannot veto the change. Clients call the same method as the `web` Remote namespace, `ctx.remote.web.listProviders()`, whose Remote result carries the lists in `value` only when `ok` is true, and refresh on the forwarded `web/providers-changed` event; the [Web search and fetch settings page](../../client/ui-settings-web-search/README.md) fills its Search and Fetch menus this way. A plugin (including one written in creator mode) that registers a provider with a `title` appears in the matching menu under that title, shows its `description` while selected, and choosing it pins `searchProvider` or `fetchProvider` to its `id`.
|
|
88
|
+
|
|
89
|
+
```text
|
|
90
|
+
// Remote: web/listProviders; Host event: web/providers-changed
|
|
91
|
+
const response = await ctx.remote.web.listProviders()
|
|
92
|
+
if (response.ok) {
|
|
93
|
+
const { search, fetch } = response.value
|
|
94
|
+
} // else: response.error is a structured RemoteError; keep any previous list and report it
|
|
95
|
+
ctx.remote.$on('web/providers-changed', () => { /* re-read the lists */ })
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
<a id="adding-a-provider"></a>
|
|
99
|
+
#### Add another provider
|
|
100
|
+
|
|
101
|
+
A search or fetch backend outside the shipped composition is a plugin package that calls `ctx.web.registerSearchProvider()` or `ctx.web.registerFetchProvider()` with a unique `id`, and an optional `title`. To enable one in a profile, install the package with `dsh plugin --profile <name> add <package>` ([install rules](../../../docs/user/develop/basic/publish.md)), add its row to the profile's user patch layer `$DSH_HOME/profiles/<name>/cordis.patch.yml`, and restart DSH. That file is a top-level YAML array of patch entries; append the `insert` entry below, or replace a lone `[]` with it. The example mounts a hypothetical `@example/dsh-web-search-acme`; use the provider's real package name and add the `config` its README documents.
|
|
102
|
+
|
|
103
|
+
```yaml
|
|
104
|
+
- insert:
|
|
105
|
+
- id: web-search-acme
|
|
106
|
+
name: '@example/dsh-web-search-acme'
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`dsh --profile <name> --dump-config` prints the row under the patch file's layer. After the restart, the provider appears in the **Web search provider** or **Web fetch provider** menu of the [settings page](../../client/ui-settings-web-search/README.md) under its `title`, or its `id` when it has none; the page needs no change. Choosing it pins `searchProvider` or `fetchProvider` to its `id`. If the row is later removed while the provider is selected, the menu shows the stored id as **(not loaded)** and each call fails with `WEB_PROVIDER_CONFIGURED_MISSING` until another provider is chosen.
|
|
110
|
+
|
|
80
111
|
<a id="search-readiness"></a>
|
|
81
112
|
### Search and fetch readiness
|
|
82
113
|
|
|
@@ -114,8 +145,8 @@ The package is built on one deliberate separation:
|
|
|
114
145
|
|
|
115
146
|
| File | Role |
|
|
116
147
|
|---|---|
|
|
117
|
-
| [`src/index.ts`](src/index.ts) | Plugin entry: the `WebRuntime` service, both provider registries, execution-time selection, and per-route readiness |
|
|
118
|
-
| [`src/types.ts`](src/types.ts) | Vocabulary: request/result types, the closed `WebFetchBody` union, and the `WebError` taxonomy |
|
|
148
|
+
| [`src/index.ts`](src/index.ts) | Plugin entry: the `WebRuntime` service, both provider registries, the `web/listProviders` Remote method and `web/providers-changed` event, execution-time selection, and per-route readiness |
|
|
149
|
+
| [`src/types.ts`](src/types.ts) | Vocabulary: request/result types, provider list entries, the `web/providers-changed` event declaration, the closed `WebFetchBody` union, and the `WebError` taxonomy |
|
|
119
150
|
|
|
120
151
|
### Data model
|
|
121
152
|
|
|
@@ -135,7 +166,7 @@ At call time the service resolves the provider — configured id first, then the
|
|
|
135
166
|
Read these pages when the package-level contract is not enough. They move from the shared vocabulary to the shipped backends, the model-facing tools, and the design rationale.
|
|
136
167
|
|
|
137
168
|
- [Web subsystem](../../../docs/subsystems/web.md) — the exhaustive search/fetch requests and results, provider availability, and error codes.
|
|
138
|
-
- [Web package map](../README.md) — the
|
|
169
|
+
- [Web package map](../README.md) — the five-package family and each role.
|
|
139
170
|
- [dsh-tool-web](../tool-web/README.md) — the model-facing `web_search` and `web_fetch` tools over this service.
|
|
140
171
|
- [dsh-web-fetch-http](../web-fetch-http/README.md) — the shipped anonymous HTTP(S) fetch backend.
|
|
141
172
|
- [Generated configuration catalog](../../../docs/config-catalog.md#deepseek-aidsh-web) — every accepted config field and its source declaration.
|
|
@@ -160,7 +191,7 @@ No direct invalidation; the named consumer owns any request-prefix changes.
|
|
|
160
191
|
|
|
161
192
|
These limits define when the service is incomplete on its own. They are current package constraints.
|
|
162
193
|
|
|
163
|
-
- **No observation
|
|
194
|
+
- **No availability observation** — `listProviders()` and `web/providers-changed` report which providers are registered, not whether they are usable; there is no capability-status query, and `searchReady()` and `fetchReady()` report only the selected provider's credential readiness and answer true when selection fails. Availability is observable only by running a search or fetch and routing the thrown code, and the no-provider failure is the generic `WEB_PROVIDER_UNAVAILABLE` with no per-provider reason enumeration ([Agent Note](../../../.agents/notes/archived/simplification/2026-07-04-drop-unconsumed-web-observation-surface.md)).
|
|
164
195
|
- **Search requests carry only `query` and `maxResults`** — provider-neutral controls (recency, domain filters, regional hints, search depth) are deferred until the backends can honor them ([seam Agent Note](../../../.agents/notes/implemented/architecture/2026-06-24-web-capability-seam.md)).
|
|
165
196
|
- **`WebFetchBody` has no `pdf` arm** — text-extractable PDF support is named deferred work; the closed union makes adding it a compile-enforced change across the web packages.
|
|
166
197
|
- **Provider-backed page extraction is out of scope of `fetch()`** — a Firecrawl/Tavily-style `web_extract` capability is deferred rather than widening the fetch operation.
|
|
@@ -175,6 +206,6 @@ This Dev Note is working context for maintainers: open questions and undecided d
|
|
|
175
206
|
|
|
176
207
|
#### Future: observing provider state
|
|
177
208
|
|
|
178
|
-
|
|
209
|
+
Registration is observable through `listProviders()` and `web/providers-changed`, but no capability-status query exists; consumers observe availability only by executing a call and routing the thrown code. Restoring a small observation surface is possible if a consumer needs per-provider reasons, but the archived simplification note records why the earlier one was dropped.
|
|
179
210
|
|
|
180
211
|
</details>
|
package/README.zh.md
CHANGED
|
@@ -33,11 +33,13 @@ kind: "package-reference"
|
|
|
33
33
|
|
|
34
34
|
### 最小配置
|
|
35
35
|
|
|
36
|
-
加载服务并让唯一挂载的后端自动选择,或用 `searchProvider`/`fetchProvider` 固定提供方 id。环境变量 `$DSH_WEB_SEARCH_PROVIDER` 与 `$DSH_WEB_FETCH_PROVIDER`
|
|
36
|
+
加载服务并让唯一挂载的后端自动选择,或用 `searchProvider`/`fetchProvider` 固定提供方 id。环境变量 `$DSH_WEB_SEARCH_PROVIDER` 与 `$DSH_WEB_FETCH_PROVIDER` 提供相同字段,不是另一条优先级链。下面两个后端都注册了抓取提供方,因此示例固定 `fetchProvider: http`。
|
|
37
37
|
|
|
38
38
|
```yaml
|
|
39
39
|
- name: '@deepseek-ai/dsh-web'
|
|
40
|
-
|
|
40
|
+
config:
|
|
41
|
+
fetchProvider: http
|
|
42
|
+
- name: '@deepseek-ai/dsh-web-deepseek-api'
|
|
41
43
|
- name: '@deepseek-ai/dsh-web-fetch-http'
|
|
42
44
|
```
|
|
43
45
|
|
|
@@ -75,8 +77,37 @@ const page = await ctx.web.fetch({ url: 'https://example.com' })
|
|
|
75
77
|
| 无 id,没有可用提供方 | `WEB_PROVIDER_UNAVAILABLE` |
|
|
76
78
|
| 无 id,多个可用提供方 | `WEB_PROVIDER_AMBIGUOUS` |
|
|
77
79
|
|
|
80
|
+
随附的 `deepseek-official` 与 `deepseek-search-api` 搜索 id 分别选择旧版 Messages 搜索与直接 Search API。
|
|
81
|
+
|
|
78
82
|
提供方的可用性是一项廉价的局部检查——例如其 API 密钥是否存在——并且从不发起网络调用,因此选择保持快速且确定。
|
|
79
83
|
|
|
84
|
+
<a id="listing-providers"></a>
|
|
85
|
+
### 列出提供方
|
|
86
|
+
|
|
87
|
+
`listProviders()` 以 `{ id, title?, description? }` 条目返回所有已注册的搜索与抓取提供方,每个列表按注册顺序排列;不可用的提供方同样列出,因为选择器展示的是可以固定的提供方。`title` 是提供方可选的显示名,缺省时选择器显示 `id`。`description` 是可选的 `LocalizedText`(来自 `dsh-package-manifest`),可以是纯字符串,也可以是以小写语言 id 为键、必须含 `en` 的翻译表,说明该提供方适合什么、有什么代价或做不到什么;选择器在选中该提供方时把它显示在下方,缺省时不显示。每次注册与每次注销都会在注册表变更后发出无载荷的 `web/providers-changed` 事件,观察者失败不能否决该变更。客户端通过 `web` Remote 命名空间调用同一方法,即 `ctx.remote.web.listProviders()`;它返回 Remote 结果,只有 `ok` 为 true 时 `value` 才带有列表。客户端在转发的 `web/providers-changed` 事件上刷新;[网页搜索与获取设置页](../../client/ui-settings-web-search/README.zh.md)以此填充搜索与获取下拉框。插件(包括在创造模式中编写的插件)注册带 `title` 的提供方后,即以该名称出现在对应下拉框中,选中时显示其 `description`,选中它会把 `searchProvider` 或 `fetchProvider` 固定为它的 `id`。
|
|
88
|
+
|
|
89
|
+
```text
|
|
90
|
+
// Remote: web/listProviders; Host event: web/providers-changed
|
|
91
|
+
const response = await ctx.remote.web.listProviders()
|
|
92
|
+
if (response.ok) {
|
|
93
|
+
const { search, fetch } = response.value
|
|
94
|
+
} // else: response.error is a structured RemoteError; keep any previous list and report it
|
|
95
|
+
ctx.remote.$on('web/providers-changed', () => { /* re-read the lists */ })
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
<a id="adding-a-provider"></a>
|
|
99
|
+
#### 添加其他提供方
|
|
100
|
+
|
|
101
|
+
内置组合之外的搜索或抓取后端是一个插件包,它以唯一的 `id` 和可选的 `title` 调用 `ctx.web.registerSearchProvider()` 或 `ctx.web.registerFetchProvider()`。要在某个 profile 中启用它,先用 `dsh plugin --profile <name> add <package>` 安装该包([安装规则](../../../docs/user/develop/basic/publish.zh.md)),再把它的行加入该 profile 的用户 patch 层 `$DSH_HOME/profiles/<name>/cordis.patch.yml`,然后重启 DSH。该文件是由 patch 条目组成的顶层 YAML 数组;请追加下面的 `insert` 条目,或用它替换单独的 `[]`。示例挂载一个假想的 `@example/dsh-web-search-acme`;请换成提供方真实的包名,并添加其 README 说明的 `config`。
|
|
102
|
+
|
|
103
|
+
```yaml
|
|
104
|
+
- insert:
|
|
105
|
+
- id: web-search-acme
|
|
106
|
+
name: '@example/dsh-web-search-acme'
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`dsh --profile <name> --dump-config` 会在该 patch 文件的层下打印这一行。重启后,该提供方以其 `title`(没有 `title` 时以其 `id`)出现在[设置页](../../client/ui-settings-web-search/README.zh.md)的**网页搜索提供方**或**网页获取提供方**下拉框中,设置页无需任何修改。选中它会把 `searchProvider` 或 `fetchProvider` 固定为它的 `id`。如果之后在该提供方被选中时删除了这一行,下拉框会把已保存的 id 显示为 **(未加载)**,每次调用都会以 `WEB_PROVIDER_CONFIGURED_MISSING` 失败,直到选择其他提供方。
|
|
110
|
+
|
|
80
111
|
<a id="search-readiness"></a>
|
|
81
112
|
### 搜索与抓取就绪
|
|
82
113
|
|
|
@@ -114,8 +145,8 @@ const fetchOffered = await ctx.web.fetchReady('deepseek-official')
|
|
|
114
145
|
|
|
115
146
|
| 文件 | 职责 |
|
|
116
147
|
|---|---|
|
|
117
|
-
| [`src/index.ts`](src/index.ts) | 插件入口:`WebRuntime`
|
|
118
|
-
| [`src/types.ts`](src/types.ts) |
|
|
148
|
+
| [`src/index.ts`](src/index.ts) | 插件入口:`WebRuntime` 服务、两个提供方注册表、`web/listProviders` Remote 方法与 `web/providers-changed` 事件、执行时选择与按路由的就绪判断 |
|
|
149
|
+
| [`src/types.ts`](src/types.ts) | 词汇:请求/结果类型、提供方列表条目、`web/providers-changed` 事件声明、封闭的 `WebFetchBody` 联合与 `WebError` 分类体系 |
|
|
119
150
|
|
|
120
151
|
### 数据模型
|
|
121
152
|
|
|
@@ -135,7 +166,7 @@ const fetchOffered = await ctx.web.fetchReady('deepseek-official')
|
|
|
135
166
|
当包级约定不够用时阅读以下页面。它们从共享词汇逐步进入已交付后端、面向模型的工具与设计依据。
|
|
136
167
|
|
|
137
168
|
- [web 子系统](../../../docs/subsystems/web.zh.md)——穷尽式的搜索/抓取请求与结果、提供方可用性与错误码。
|
|
138
|
-
- [web 包映射](../README.zh.md)
|
|
169
|
+
- [web 包映射](../README.zh.md)——五包家族与各角色。
|
|
139
170
|
- [dsh-tool-web](../tool-web/README.zh.md)——构建于本服务之上的面向模型 `web_search` 与 `web_fetch` 工具。
|
|
140
171
|
- [dsh-web-fetch-http](../web-fetch-http/README.zh.md)——已交付的匿名 HTTP(S) 抓取后端。
|
|
141
172
|
- [生成配置目录](../../../docs/config-catalog.zh.md#deepseek-aidsh-web)——每个受支持配置字段及其源声明。
|
|
@@ -160,7 +191,7 @@ const fetchOffered = await ctx.web.fetchReady('deepseek-official')
|
|
|
160
191
|
|
|
161
192
|
这些限制说明本服务单独使用时在哪些方面不完整。它们是当前包约束。
|
|
162
193
|
|
|
163
|
-
-
|
|
194
|
+
- **没有可用性观测**:`listProviders()` 与 `web/providers-changed` 只报告哪些提供方已注册,不报告它们是否可用;没有能力状态查询,`searchReady()` 与 `fetchReady()` 只报告选中提供方的凭据就绪状态,选择失败时回答 true。可用性只能通过执行搜索或抓取并按抛出的 code 路由来观测,无提供方失败是通用的 `WEB_PROVIDER_UNAVAILABLE`,不枚举逐提供方原因(见 [Agent Note](../../../.agents/notes/archived/simplification/2026-07-04-drop-unconsumed-web-observation-surface.md))。
|
|
164
195
|
- **搜索请求只携带 `query` 与 `maxResults`**:提供方无关的控制项(新近程度、域名过滤条件、区域提示、搜索深度)暂缓至后端都能诚实支持时(见 [seam Agent Note](../../../.agents/notes/implemented/architecture/2026-06-24-web-capability-seam.zh.md))。
|
|
165
196
|
- **`WebFetchBody` 没有 `pdf` 分支**:可提取文本的 PDF 支持属于明确的延期工作;封闭联合会使新增该分支成为跨 web 包、由编译强制执行的变更。
|
|
166
197
|
- **提供方支持的页面提取不属于 `fetch()` 范围**:Firecrawl/Tavily 风格的 `web_extract` 能力延期,而不会扩展抓取操作。
|
|
@@ -175,6 +206,6 @@ const fetchOffered = await ctx.web.fetchReady('deepseek-official')
|
|
|
175
206
|
|
|
176
207
|
#### 未来:观测提供方状态
|
|
177
208
|
|
|
178
|
-
|
|
209
|
+
注册情况可通过 `listProviders()` 与 `web/providers-changed` 观测,但没有能力状态查询;消费方只能通过执行调用并按抛出的 code 路由来观测可用性。如果消费方需要逐提供方原因,恢复一个小的观测接口是可行的,但已归档的简化笔记记录了为何放弃此前的那个接口。
|
|
179
210
|
|
|
180
211
|
</details>
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Remote, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
2
2
|
import z from "@deepseek-ai/schemastery";
|
|
3
3
|
import { HarnessError } from "@deepseek-ai/dsh-llm";
|
|
4
4
|
//#region lib/types/types.js
|
|
@@ -26,8 +26,47 @@ var WebError = class extends HarnessError {};
|
|
|
26
26
|
* on registration order.
|
|
27
27
|
* @module @deepseek-ai/dsh-web
|
|
28
28
|
*/
|
|
29
|
+
var __runInitializers = function(thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
32
|
+
return useValue ? value : void 0;
|
|
33
|
+
};
|
|
34
|
+
var __esDecorate = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
35
|
+
function accept(f) {
|
|
36
|
+
if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected");
|
|
37
|
+
return f;
|
|
38
|
+
}
|
|
39
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
40
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
41
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
42
|
+
var _, done = false;
|
|
43
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
44
|
+
var context = {};
|
|
45
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
46
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
47
|
+
context.addInitializer = function(f) {
|
|
48
|
+
if (done) throw new TypeError("Cannot add initializers after decoration has completed");
|
|
49
|
+
extraInitializers.push(accept(f || null));
|
|
50
|
+
};
|
|
51
|
+
var result = (0, decorators[i])(kind === "accessor" ? {
|
|
52
|
+
get: descriptor.get,
|
|
53
|
+
set: descriptor.set
|
|
54
|
+
} : descriptor[key], context);
|
|
55
|
+
if (kind === "accessor") {
|
|
56
|
+
if (result === void 0) continue;
|
|
57
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
58
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
59
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
60
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
61
|
+
} else if (_ = accept(result)) if (kind === "field") initializers.unshift(_);
|
|
62
|
+
else descriptor[key] = _;
|
|
63
|
+
}
|
|
64
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
65
|
+
done = true;
|
|
66
|
+
};
|
|
29
67
|
/**
|
|
30
|
-
* The web access service. Registered as `ctx.web` (one instance per context)
|
|
68
|
+
* The web access service. Registered as `ctx.web` (one instance per context)
|
|
69
|
+
* and exposed to Clients as the `web` Remote namespace (`listProviders`).
|
|
31
70
|
*
|
|
32
71
|
* Selection semantics (resolved at execution time, never order-dependent):
|
|
33
72
|
* - A configured id that is registered and `available()` → that provider.
|
|
@@ -38,117 +77,186 @@ var WebError = class extends HarnessError {};
|
|
|
38
77
|
* - No id configured, multiple usable providers → `WEB_PROVIDER_AMBIGUOUS`.
|
|
39
78
|
* - No id configured, no usable provider → `WEB_PROVIDER_UNAVAILABLE`.
|
|
40
79
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
* @param provider - the provider; its `id` is the registry key.
|
|
77
|
-
* @returns the disposer that unregisters the provider.
|
|
78
|
-
*/
|
|
79
|
-
registerFetchProvider(provider) {
|
|
80
|
-
return this.registerProvider(this.fetchProviders, provider);
|
|
81
|
-
}
|
|
82
|
-
registerProvider(store, provider) {
|
|
83
|
-
if (store.has(provider.id)) throw new WebError(`a web provider with id "${provider.id}" is already registered`, "WEB_DUPLICATE_PROVIDER");
|
|
84
|
-
const dispose = this.ctx.effect(function* () {
|
|
85
|
-
store.set(provider.id, provider);
|
|
86
|
-
yield () => store.delete(provider.id);
|
|
87
|
-
}, "web.registerProvider()");
|
|
88
|
-
return () => void dispose();
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Run one search through the selected provider. Resolves the provider at call
|
|
92
|
-
* time with the selection rules above; throws {@link WebError} when the
|
|
93
|
-
* capability cannot run. The seam enforces `request.maxResults` on the result:
|
|
94
|
-
* if the provider over-returns, `sources[]` is truncated and `truncated` set.
|
|
95
|
-
* @param request - the query and optional result limit.
|
|
96
|
-
* @param signal - optional cancellation signal forwarded to the provider.
|
|
97
|
-
* @returns the provider's results, capped to `request.maxResults`.
|
|
98
|
-
*/
|
|
99
|
-
async search(request, signal) {
|
|
100
|
-
return capSources(await this.selectSearchProvider().search(request, signal), request.maxResults);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Whether the provider `search()` would select can authenticate a search made for a
|
|
104
|
-
* model request on the `llmProvider` chat route. Asks only that provider's `ready()`;
|
|
105
|
-
* one without `ready()` counts as ready. Makes no network calls. A selection failure
|
|
106
|
-
* answers true, because `search()` reports that failure as a structured `WebError`.
|
|
107
|
-
* @param llmProvider - the provider route id of the model request, when known.
|
|
108
|
-
* @returns false only when the selected provider reports that it cannot authenticate.
|
|
109
|
-
*/
|
|
110
|
-
async searchReady(llmProvider) {
|
|
111
|
-
return await selectedProviderReady(() => this.selectSearchProvider(), llmProvider);
|
|
112
|
-
}
|
|
113
|
-
/** Select the search provider with the rules above, throwing the matching {@link WebError}. */
|
|
114
|
-
selectSearchProvider() {
|
|
115
|
-
const configuredId = this.config.searchProvider.get() ?? this.searchProviderEnv;
|
|
116
|
-
return resolveProvider({
|
|
117
|
-
providers: this.searchProviders,
|
|
118
|
-
...configuredId !== void 0 ? { configuredId } : {}
|
|
80
|
+
let WebRuntime = (() => {
|
|
81
|
+
let _classSuper = TypertRemoteService;
|
|
82
|
+
let _instanceExtraInitializers = [];
|
|
83
|
+
let _listProviders_decorators;
|
|
84
|
+
return class WebRuntime extends _classSuper {
|
|
85
|
+
static {
|
|
86
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
87
|
+
_listProviders_decorators = [Remote];
|
|
88
|
+
__esDecorate(this, null, _listProviders_decorators, {
|
|
89
|
+
kind: "method",
|
|
90
|
+
name: "listProviders",
|
|
91
|
+
static: false,
|
|
92
|
+
private: false,
|
|
93
|
+
access: {
|
|
94
|
+
has: (obj) => "listProviders" in obj,
|
|
95
|
+
get: (obj) => obj.listProviders
|
|
96
|
+
},
|
|
97
|
+
metadata: _metadata
|
|
98
|
+
}, null, _instanceExtraInitializers);
|
|
99
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, {
|
|
100
|
+
enumerable: true,
|
|
101
|
+
configurable: true,
|
|
102
|
+
writable: true,
|
|
103
|
+
value: _metadata
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
config = __runInitializers(this, _instanceExtraInitializers);
|
|
107
|
+
/**
|
|
108
|
+
* Provider selection config. Operational env overrides feed the SAME fields:
|
|
109
|
+
* `$DSH_WEB_SEARCH_PROVIDER` / `$DSH_WEB_FETCH_PROVIDER` are equivalent to
|
|
110
|
+
* `searchProvider` / `fetchProvider` and are NOT a hidden priority chain.
|
|
111
|
+
*/
|
|
112
|
+
static Config = z.object({
|
|
113
|
+
searchProvider: z.string().volatile(),
|
|
114
|
+
fetchProvider: z.string().volatile()
|
|
119
115
|
});
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
116
|
+
searchProviders = /* @__PURE__ */ new Map();
|
|
117
|
+
fetchProviders = /* @__PURE__ */ new Map();
|
|
118
|
+
searchProviderEnv;
|
|
119
|
+
fetchProviderEnv;
|
|
120
|
+
constructor(ctx, config) {
|
|
121
|
+
super(ctx, "web");
|
|
122
|
+
this.config = config;
|
|
123
|
+
this.searchProviderEnv = process.env.DSH_WEB_SEARCH_PROVIDER;
|
|
124
|
+
this.fetchProviderEnv = process.env.DSH_WEB_FETCH_PROVIDER;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Register a search provider. `listProviders()` lists it until the
|
|
128
|
+
* registration is disposed, which happens with the calling fiber or through
|
|
129
|
+
* the returned disposer; registration and disposal each emit
|
|
130
|
+
* `web/providers-changed`. Throws {@link WebError} `WEB_DUPLICATE_PROVIDER`
|
|
131
|
+
* if its id is already registered for search.
|
|
132
|
+
* @param provider - the provider; its `id` is the registry key.
|
|
133
|
+
* @returns the disposer that unregisters the provider.
|
|
134
|
+
*/
|
|
135
|
+
registerSearchProvider(provider) {
|
|
136
|
+
return this.registerProvider(this.searchProviders, provider);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Register a fetch provider, with the listing, disposal, and event behavior
|
|
140
|
+
* of {@link WebRuntime.registerSearchProvider}. Throws {@link WebError}
|
|
141
|
+
* `WEB_DUPLICATE_PROVIDER` if its id is already registered for fetch.
|
|
142
|
+
* @param provider - the provider; its `id` is the registry key.
|
|
143
|
+
* @returns the disposer that unregisters the provider.
|
|
144
|
+
*/
|
|
145
|
+
registerFetchProvider(provider) {
|
|
146
|
+
return this.registerProvider(this.fetchProviders, provider);
|
|
147
|
+
}
|
|
148
|
+
registerProvider(store, provider) {
|
|
149
|
+
if (store.has(provider.id)) throw new WebError(`a web provider with id "${provider.id}" is already registered`, "WEB_DUPLICATE_PROVIDER");
|
|
150
|
+
const emitChanged = () => {
|
|
151
|
+
this.emitProvidersChanged();
|
|
152
|
+
};
|
|
153
|
+
const dispose = this.ctx.effect(function* () {
|
|
154
|
+
store.set(provider.id, provider);
|
|
155
|
+
emitChanged();
|
|
156
|
+
yield () => {
|
|
157
|
+
store.delete(provider.id);
|
|
158
|
+
emitChanged();
|
|
159
|
+
};
|
|
160
|
+
}, "web.registerProvider()");
|
|
161
|
+
return () => void dispose();
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* List every registered search and fetch provider for provider pickers.
|
|
165
|
+
* Availability does not filter the lists.
|
|
166
|
+
* @returns detached `{ id, title, description }` entries per capability, in registration order.
|
|
167
|
+
*/
|
|
168
|
+
listProviders() {
|
|
169
|
+
return {
|
|
170
|
+
search: [...this.searchProviders.values()].map(providerInfo),
|
|
171
|
+
fetch: [...this.fetchProviders.values()].map(providerInfo)
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/** Emit `web/providers-changed`, containing each listener's failure so none vetoes the mutation. */
|
|
175
|
+
emitProvidersChanged() {
|
|
176
|
+
for (const listener of this.ctx.events.dispatch("emit", ["web/providers-changed"])) try {
|
|
177
|
+
const returned = listener();
|
|
178
|
+
Promise.resolve(returned).catch((error) => {
|
|
179
|
+
this.warnListenerFailure(error);
|
|
180
|
+
});
|
|
181
|
+
} catch (error) {
|
|
182
|
+
this.warnListenerFailure(error);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
warnListenerFailure(error) {
|
|
186
|
+
this.ctx.logger.warn("web: a web/providers-changed listener failed");
|
|
187
|
+
this.ctx.logger.warn(error);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Run one search through the selected provider. Resolves the provider at call
|
|
191
|
+
* time with the selection rules above; throws {@link WebError} when the
|
|
192
|
+
* capability cannot run. The seam enforces `request.maxResults` on the result:
|
|
193
|
+
* if the provider over-returns, `sources[]` is truncated and `truncated` set.
|
|
194
|
+
* @param request - the query and optional result limit.
|
|
195
|
+
* @param signal - optional cancellation signal forwarded to the provider.
|
|
196
|
+
* @returns the provider's results, capped to `request.maxResults`.
|
|
197
|
+
*/
|
|
198
|
+
async search(request, signal) {
|
|
199
|
+
return capSources(await this.selectSearchProvider().search(request, signal), request.maxResults);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Whether the provider `search()` would select can authenticate a search made for a
|
|
203
|
+
* model request on the `llmProvider` chat route. Asks only that provider's `ready()`;
|
|
204
|
+
* one without `ready()` counts as ready. Makes no network calls. A selection failure
|
|
205
|
+
* answers true, because `search()` reports that failure as a structured `WebError`.
|
|
206
|
+
* @param llmProvider - the provider route id of the model request, when known.
|
|
207
|
+
* @returns false only when the selected provider reports that it cannot authenticate.
|
|
208
|
+
*/
|
|
209
|
+
async searchReady(llmProvider) {
|
|
210
|
+
return await selectedProviderReady(() => this.selectSearchProvider(), llmProvider);
|
|
211
|
+
}
|
|
212
|
+
/** Select the search provider with the rules above, throwing the matching {@link WebError}. */
|
|
213
|
+
selectSearchProvider() {
|
|
214
|
+
const configuredId = this.config.searchProvider.get() ?? this.searchProviderEnv;
|
|
215
|
+
return resolveProvider({
|
|
216
|
+
providers: this.searchProviders,
|
|
217
|
+
...configuredId !== void 0 ? { configuredId } : {}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Retrieve one URL through the selected provider. Resolves the provider at
|
|
222
|
+
* call time with the selection rules above; throws {@link WebError} when the
|
|
223
|
+
* capability cannot run. A non-2xx response is a result, not a throw.
|
|
224
|
+
* @param request - the URL plus retrieval options.
|
|
225
|
+
* @param signal - optional cancellation signal forwarded to the provider.
|
|
226
|
+
* @returns the retrieval outcome; non-2xx responses resolve descriptively.
|
|
227
|
+
*/
|
|
228
|
+
async fetch(request, signal) {
|
|
229
|
+
return await this.selectFetchProvider().fetch(request, signal);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Whether the provider `fetch()` would select can authenticate a fetch made for a
|
|
233
|
+
* model request on the `llmProvider` chat route. Asks only that provider's `ready()`;
|
|
234
|
+
* one without `ready()` counts as ready. Makes no network calls. A selection failure
|
|
235
|
+
* answers true, because `fetch()` reports that failure as a structured `WebError`.
|
|
236
|
+
* @param llmProvider - the provider route id of the model request, when known.
|
|
237
|
+
* @returns false only when the selected provider reports that it cannot authenticate.
|
|
238
|
+
*/
|
|
239
|
+
async fetchReady(llmProvider) {
|
|
240
|
+
return await selectedProviderReady(() => this.selectFetchProvider(), llmProvider);
|
|
241
|
+
}
|
|
242
|
+
/** Select the fetch provider with the rules above, throwing the matching {@link WebError}. */
|
|
243
|
+
selectFetchProvider() {
|
|
244
|
+
const configuredId = this.config.fetchProvider.get() ?? this.fetchProviderEnv;
|
|
245
|
+
return resolveProvider({
|
|
246
|
+
providers: this.fetchProviders,
|
|
247
|
+
...configuredId !== void 0 ? { configuredId } : {}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
})();
|
|
252
|
+
/** Project one provider to its picker entry, omitting an absent title or description. */
|
|
253
|
+
function providerInfo(provider) {
|
|
254
|
+
return {
|
|
255
|
+
id: provider.id,
|
|
256
|
+
...provider.title === void 0 ? {} : { title: provider.title },
|
|
257
|
+
...provider.description === void 0 ? {} : { description: provider.description }
|
|
258
|
+
};
|
|
259
|
+
}
|
|
152
260
|
/**
|
|
153
261
|
* Ask the provider an operation selects whether it can authenticate for one chat route.
|
|
154
262
|
* @param select - the operation's selection; throws its {@link WebError} when no provider qualifies.
|