@deepseek-ai/dsh-web-search-deepseek 0.2.2-rc.1 → 0.2.2-rc.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 CHANGED
@@ -21,11 +21,11 @@
21
21
  en: 0187c8af8d2d98c5
22
22
  zh: 1c9607b3a662bcaa
23
23
  /deepseek-ai-dsh-web-search-deepseek/use-this-package/minimal-configuration:
24
- en: 0553b6c926c44cf4
25
- zh: 5cd3221d3e8eebd9
24
+ en: 3ed88edabdf63c8d
25
+ zh: c66176c8a7c9a434
26
26
  /deepseek-ai-dsh-web-search-deepseek/use-this-package/authentication:
27
- en: e9104c20ee90b3be
28
- zh: 5fcc71d403976eaa
27
+ en: 7a765ba931329067
28
+ zh: 6fc14edcc378684a
29
29
  /deepseek-ai-dsh-web-search-deepseek/use-this-package/what-a-search-returns:
30
30
  en: e30442c90365357b
31
31
  zh: 9c9e2f1182963a8a
@@ -33,8 +33,8 @@
33
33
  en: 467b8238cf7e140c
34
34
  zh: 85a519c8811557aa
35
35
  /deepseek-ai-dsh-web-search-deepseek/use-this-package/failures-and-recovery:
36
- en: e8b3d05fa39ccf47
37
- zh: 2faa8b06ce0c4ad4
36
+ en: 8e69cf009b707c49
37
+ zh: f7d50bfc06b01b6d
38
38
  /deepseek-ai-dsh-web-search-deepseek/understand-the-implementation:
39
39
  en: 9842c69ad3636bb3
40
40
  zh: 3cdc3f816cbdd0cb
@@ -48,8 +48,8 @@
48
48
  en: d6c3f30b70a5f4b5
49
49
  zh: ab7c5b7d6fc3cae6
50
50
  /deepseek-ai-dsh-web-search-deepseek/further-exploration:
51
- en: 4c0730d979693c5a
52
- zh: 74681ad82b7b45ed
51
+ en: 3a650478cf33d792
52
+ zh: ab4247c4c31f4a90
53
53
  /deepseek-ai-dsh-web-search-deepseek/model-experience:
54
54
  en: 215e7ba838619b7b
55
55
  zh: a311da3843709f90
@@ -96,5 +96,5 @@
96
96
  en: 7f775cc79dbce94b
97
97
  zh: 12b8f68f9e7c48ca
98
98
  /deepseek-ai-dsh-web-search-deepseek/known-limitations-and-deferred-work/dev-note/dedicated-retrieval-endpoint:
99
- en: 2a0437bd17a5a8a4
100
- zh: 4032f3feb2388f6e
99
+ en: 188ca3400a73352e
100
+ zh: f948e2c565ec6ac1
package/README.md CHANGED
@@ -33,7 +33,7 @@ Choose this backend when a deployment wants DeepSeek's native server-side web se
33
33
 
34
34
  ### Minimal configuration
35
35
 
36
- Load the web service and the provider; the key resolves from `ctx.credentials` when that service is mounted, otherwise from the process environment. The auxiliary search call has its own endpoint setting and uses the Anthropic-compatible base `https://api.deepseek.com/anthropic/v1`, with `/messages` appended. It reads `$DEEPSEEK_SEARCH_BASE_URL`, independently of the conversation adapter’s `$DEEPSEEK_BASE_URL`.
36
+ Load the web service and the provider; the key resolves from `ctx.credentials` when that service is mounted, otherwise from the process environment. The auxiliary search call has its own endpoint setting and uses the Anthropic-compatible base `https://api.deepseek.com/anthropic/v1`, with `/messages` appended. It reads `$DEEPSEEK_SEARCH_BASE_URL`, independently of the conversation adapter’s `$DEEPSEEK_BASE_URL`; the `dsh` launcher accepts both variables from the launching environment or `$DSH_HOME/.env`, never from a project `.env` ([app-boot](../../boot/app-boot/README.md)).
37
37
 
38
38
  ```yaml
39
39
  - name: '@deepseek-ai/dsh-web'
@@ -58,10 +58,12 @@ The generated [configuration catalog](../../../docs/config-catalog.md#deepseek-a
58
58
  <a id="authentication"></a>
59
59
  ### Authentication
60
60
 
61
- A search authenticates with the DeepSeek account when the latest `request/context` event of the initiating Session names the `deepseek-account` provider route and `ctx.deepseekAccount` resolves a token for the search endpoint. The account service resolves one only while signed in and only for its deployment-configured inference origin, `https://api.deepseek.com` by default. That search sends only `x-dsh-auth-token`, even when an API key is configured. Every other search, including a call without an initiating Session and a search whose endpoint has another origin, sends the API key as both `x-api-key` and `Authorization: Bearer`. An HTTP 401 response to an account-authenticated search fails as `WEB_PROVIDER_ERROR` with sign-in guidance instead of endpoint guidance, and leaves the account signed in.
61
+ A search authenticates with the DeepSeek account when the latest `request/context` event of the initiating Session names the `deepseek-account` provider route and `ctx.deepseekAccount` resolves a token for the search endpoint. The account service resolves one only while signed in and only for its deployment-configured inference origin, `https://api.deepseek.com` by default. That search sends only `x-dsh-auth-token`, even when an API key is configured. Every other search, including a call without an initiating Session and a search whose endpoint has another origin, sends the API key as both `x-api-key` and `Authorization: Bearer`. An HTTP 401 response to an account-authenticated search fails as `WEB_PROVIDER_ERROR` with sign-in guidance instead of endpoint guidance, and invalidates only the token that search sent: a newer sign-in is preserved, and a credential-removal failure or a cancelled error-body read does not skip invalidation or replace the reported failure. An API-key 401 and every HTTP 403 leave the account signed in.
62
62
 
63
63
  The provider's `ready()` answers whether the search a model request would make has a credential, on any model route: the request's route is `deepseek-account` and `ctx.deepseekAccount` resolves a token for the configured search endpoint, or a literal `apiKey` is set or `ctx.credentials.describe` reports the `apiKeyEnv` reference configured (without that service, the process environment must carry it). It checks them in the order a search resolves them, and a failed account-token or credential-store read answers false, because the search fails on that read instead of trying the next credential. While this provider is the selected search provider, [`dsh-tool-web`](../tool-web/README.md#search-readiness) withholds `web_search` and its prompt guidance from each request for which it answers false. Only presence is checked: a wrong key, or an endpoint that does not serve the native `web_search_20250305` server tool, counts as ready and fails each call. A call that still arrives resolves credentials when it runs.
64
64
 
65
+ Referenced keys use the [shared DeepSeek credential helpers](../../llm/llm-deepseek/README.md#account-credentials), including the same whitespace normalization and format validation as model requests. A malformed referenced key fails before dispatch; readiness remains a presence-only check.
66
+
65
67
  ### What a search returns
66
68
 
67
69
  `content` is always omitted: DeepSeek's provider prose is not trusted as an answer. `sources[]` comes from `web_search_result` items inside `web_search_tool_result` blocks — `url` and `title` directly, and `publishedAt` from `page_age` — with snippets joined from URL-keyed `cited_text` entries where an excerpt exists. Results are deduplicated by URL, and because DeepSeek exposes no result-count knob, the service enforces `maxResults` by truncating and flagging.
@@ -72,7 +74,7 @@ A search running under an initiating agent appends the log-only `web/deepseek-se
72
74
 
73
75
  ### Failures and recovery
74
76
 
75
- Failures throw `WebError` with a machine-routable code: a missing credential is `WEB_PROVIDER_CREDENTIAL_MISSING`, caller cancellation is `WEB_ABORTED`, and provider or transport failures — including a response with no `web_search_tool_result` block — are `WEB_PROVIDER_ERROR`. HTTP redirects are rejected before the `Location` target is contacted. Every failure after dispatch names the resolved search endpoint and explains that search endpoint configuration is separate from chat. If the endpoint is unintended, the message tells the conversation model to guide the user to the Messages API base URL field under Plugins > Built-in plugin settings > Web search and save the change. When that page is unavailable, it names `web-search-deepseek.baseURL` as the deployment configuration alternative. The model must not choose or change the endpoint. The model-facing `web_search` tool surfaces this text under its own error wrapper.
77
+ Failures throw `WebError` with a machine-routable code: a missing credential is `WEB_PROVIDER_CREDENTIAL_MISSING`, caller cancellation is `WEB_ABORTED`, and provider or transport failures — including a response with no `web_search_tool_result` block — are `WEB_PROVIDER_ERROR`. HTTP redirects are rejected before the `Location` target is contacted. Every failure after dispatch names the resolved search endpoint and explains that search endpoint configuration is separate from chat. If the endpoint is unintended, the message tells the conversation model to guide the user to Plugins > Built-in plugin settings > Web search and fetch, select DeepSeek (legacy) under Search, and save its Base URL. When that page is unavailable, it names `web-search-deepseek.baseURL` as the deployment configuration alternative. The model must not choose or change the endpoint. The model-facing `web_search` tool surfaces this text under its own error wrapper.
76
78
 
77
79
  -----
78
80
 
@@ -115,7 +117,7 @@ Readiness captures the same options but reads no API key value: on the account r
115
117
  Read these pages when the package-level contract is not enough. They move from the shared vocabulary to the service, the model-facing tools, and the design rationale.
116
118
 
117
119
  - [Web subsystem](../../../docs/subsystems/web.md) — the exhaustive search request/result vocabulary and error codes.
118
- - [Web package map](../README.md) — the seven-package family and each role.
120
+ - [Web package map](../README.md) — the web package family and each role.
119
121
  - [dsh-web](../web/README.md) — the web service this provider registers into.
120
122
  - [dsh-tool-web](../tool-web/README.md) — the model-facing `web_search` tool that renders this provider's sources.
121
123
  - [Generated configuration catalog](../../../docs/config-catalog.md#deepseek-aidsh-web-search-deepseek) — every accepted config field and its source declaration.
@@ -193,6 +195,6 @@ This Dev Note is working context for maintainers: open questions and undecided d
193
195
 
194
196
  #### Dedicated retrieval endpoint
195
197
 
196
- DeepSeek's Search and Fetch APIs, which avoid the full model turn, live in [dsh-web-deepseek-api](../web-deepseek-api/README.md) and are selected by the Web search settings switch; this provider stays the default until the Search API launch is announced.
198
+ DeepSeek's Search and Fetch APIs, which avoid the full model turn, live in [dsh-web-deepseek-api](../web-deepseek-api/README.md) and are selected with the Search and Fetch menus on the Web search and fetch settings page. Shipped profiles select the Search API, so this provider runs only when `searchProvider: deepseek-official` is selected (for example, on gateways without Search API routes).
197
199
 
198
200
  </details>
package/README.zh.md CHANGED
@@ -33,7 +33,7 @@ kind: "package-reference"
33
33
 
34
34
  ### 最小配置
35
35
 
36
- 加载 web 服务与本提供方;密钥在已挂载 `ctx.credentials` 服务时从其解析,否则从进程环境解析。辅助搜索调用有独立的端点设置,使用 Anthropic 兼容基址 `https://api.deepseek.com/anthropic/v1`,并追加 `/messages`。它读取 `$DEEPSEEK_SEARCH_BASE_URL`,与会话适配器的 `$DEEPSEEK_BASE_URL` 相互独立。
36
+ 加载 web 服务与本提供方;密钥在已挂载 `ctx.credentials` 服务时从其解析,否则从进程环境解析。辅助搜索调用有独立的端点设置,使用 Anthropic 兼容基址 `https://api.deepseek.com/anthropic/v1`,并追加 `/messages`。它读取 `$DEEPSEEK_SEARCH_BASE_URL`,与会话适配器的 `$DEEPSEEK_BASE_URL` 相互独立;`dsh` 启动器从启动环境或 `$DSH_HOME/.env` 接受这两个变量,绝不从项目 `.env` 接受([app-boot](../../boot/app-boot/README.zh.md))。
37
37
 
38
38
  ```yaml
39
39
  - name: '@deepseek-ai/dsh-web'
@@ -58,10 +58,12 @@ kind: "package-reference"
58
58
  <a id="authentication"></a>
59
59
  ### 鉴权
60
60
 
61
- 当发起会话最近的 `request/context` 事件指明 `deepseek-account` 提供方路由,且 `ctx.deepseekAccount` 为搜索端点解析出 token 时,搜索使用 DeepSeek 账号鉴权。账号服务仅在已登录时、且仅对部署配置的推理 origin(默认 `https://api.deepseek.com`)解析 token。这类搜索只发送 `x-dsh-auth-token`,即使配置了 API 密钥也是如此。其余所有搜索,包括没有发起会话的调用以及端点属于其他 origin 的搜索,都把 API 密钥同时作为 `x-api-key` 与 `Authorization: Bearer` 发送。账号鉴权的搜索收到 HTTP 401 时以 `WEB_PROVIDER_ERROR` 失败,附带登录指引而非端点指引,账号保持登录。
61
+ 当发起会话最近的 `request/context` 事件指明 `deepseek-account` 提供方路由,且 `ctx.deepseekAccount` 为搜索端点解析出 token 时,搜索使用 DeepSeek 账号鉴权。账号服务仅在已登录时、且仅对部署配置的推理 origin(默认 `https://api.deepseek.com`)解析 token。这类搜索只发送 `x-dsh-auth-token`,即使配置了 API 密钥也是如此。其余所有搜索,包括没有发起会话的调用以及端点属于其他 origin 的搜索,都把 API 密钥同时作为 `x-api-key` 与 `Authorization: Bearer` 发送。账号鉴权的搜索收到 HTTP 401 时以 `WEB_PROVIDER_ERROR` 失败,附带登录指引而非端点指引,并只作废该搜索实际发送的 token:更新的登录不受影响,凭据删除失败或错误正文读取被取消既不会跳过作废,也不会替换所报告的失败。API 密钥请求的 401 与所有 HTTP 403 不影响账号登录状态。
62
62
 
63
63
  提供方的 `ready()` 回答模型请求将发起的搜索是否有凭据,不论模型路由:该请求的路由是 `deepseek-account` 且 `ctx.deepseekAccount` 为配置的搜索端点解析出 token,或者设置了字面 `apiKey`,或 `ctx.credentials.describe` 报告 `apiKeyEnv` 引用已配置(没有该服务时,进程环境中必须存在该变量)。它按搜索解析凭据的顺序检查,读取账号 token 或凭据存储失败时回答 false,因为搜索会在该次读取上失败,而不会尝试下一种凭据。本提供方是选中的搜索提供方时,[`dsh-tool-web`](../tool-web/README.zh.md#search-readiness) 会从它回答 false 的每个请求中撤下 `web_search` 及其提示词说明。这里只检查凭据是否存在:错误的密钥,或不提供原生 `web_search_20250305` 服务器工具的端点,都视为就绪并使每次调用失败。仍然到达的调用会在运行时解析凭据。
64
64
 
65
+ 引用密钥使用[共享 DeepSeek 凭据函数](../../llm/llm-deepseek/README.zh.md#account-credentials),接受与模型请求相同的首尾空白规范化和格式校验。引用密钥格式错误会在发送请求前失败;就绪判断仍只检查是否存在。
66
+
65
67
  ### 搜索返回什么
66
68
 
67
69
  `content` 始终省略:DeepSeek 的提供方文本不作为答案受到信任。`sources[]` 来自 `web_search_tool_result` 块内的 `web_search_result` 条目——`url` 和 `title` 直接取自同名字段,`publishedAt` 取自 `page_age`——snippet 在存在摘录时按 URL 关联的 `cited_text` 条目拼接。结果按 URL 去重,且由于 DeepSeek 不公开结果数量旋钮,服务通过截断并标记来强制执行 `maxResults`。
@@ -72,7 +74,7 @@ kind: "package-reference"
72
74
 
73
75
  ### 失败与恢复
74
76
 
75
- 失败抛出携带可按机器路由 code 的 `WebError`:凭据缺失为 `WEB_PROVIDER_CREDENTIAL_MISSING`,调用方取消为 `WEB_ABORTED`,提供方或传输失败,包括响应中没有 `web_search_tool_result` 块,为 `WEB_PROVIDER_ERROR`。HTTP 重定向会在接触 `Location` 指向的目标之前被拒绝。请求发出后的每项失败都会指出已解析的搜索端点,并说明搜索端点配置独立于聊天端点。如果该端点不符合用户预期,错误消息会要求会话模型指导用户进入 Plugins > Built-in plugin settings > Web search,修改 Messages API base URL 字段并保存。该页面不可用时,消息会把 `web-search-deepseek.baseURL` 作为部署配置方式。模型不得替用户选择或修改端点。面向模型的 `web_search` 工具会在自己的错误包装层内呈现这段文本。
77
+ 失败抛出携带可按机器路由 code 的 `WebError`:凭据缺失为 `WEB_PROVIDER_CREDENTIAL_MISSING`,调用方取消为 `WEB_ABORTED`,提供方或传输失败,包括响应中没有 `web_search_tool_result` 块,为 `WEB_PROVIDER_ERROR`。HTTP 重定向会在接触 `Location` 指向的目标之前被拒绝。请求发出后的每项失败都会指出已解析的搜索端点,并说明搜索端点配置独立于聊天端点。如果该端点不符合用户预期,错误消息会要求会话模型指导用户进入 Plugins > Built-in plugin settings > Web search and fetch,在 Search 中选择 DeepSeek(旧版),修改其 Base URL 并保存。该页面不可用时,消息会把 `web-search-deepseek.baseURL` 作为部署配置方式。模型不得替用户选择或修改端点。面向模型的 `web_search` 工具会在自己的错误包装层内呈现这段文本。
76
78
 
77
79
  -----
78
80
 
@@ -115,7 +117,7 @@ kind: "package-reference"
115
117
  当包级约定不够用时阅读以下页面。它们从共享词汇逐步进入服务、面向模型的工具与设计依据。
116
118
 
117
119
  - [web 子系统](../../../docs/subsystems/web.zh.md)——穷尽式的搜索请求/结果词汇与错误码。
118
- - [web 包映射](../README.zh.md)——七包家族与各角色。
120
+ - [web 包映射](../README.zh.md)——Web 包家族与各角色。
119
121
  - [dsh-web](../web/README.zh.md)——本提供方注册进入的 web 服务。
120
122
  - [dsh-tool-web](../tool-web/README.zh.md)——渲染本提供方来源的面向模型 `web_search` 工具。
121
123
  - [生成配置目录](../../../docs/config-catalog.zh.md#deepseek-aidsh-web-search-deepseek)——每个受支持配置字段及其源声明。
@@ -193,6 +195,6 @@ kind: "package-reference"
193
195
 
194
196
  #### 专用检索端点
195
197
 
196
- 无需完整模型轮次的 DeepSeek Search 与 Fetch API 位于 [dsh-web-deepseek-api](../web-deepseek-api/README.zh.md),由网页搜索设置页的开关选择;在 Search API 正式发布公告之前,本提供方仍是默认值。
198
+ 无需完整模型轮次的 DeepSeek Search 与 Fetch API 位于 [dsh-web-deepseek-api](../web-deepseek-api/README.zh.md),由「网页搜索与获取」设置页的搜索和获取下拉框分别选择。内置配置选择 Search API,因此仅在选用 `searchProvider: deepseek-official` 时(例如网关未提供 Search API 路由)本提供方才会运行。
197
199
 
198
200
  </details>
package/lib/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import z from "@deepseek-ai/schemastery";
2
2
  import { credentialRef } from "@deepseek-ai/dsh-credentials";
3
3
  import { launchEnvironmentOf } from "@deepseek-ai/dsh-launch-environment";
4
+ import { deepSeekApiKeyConfigured, rejectDeepSeekAccountToken, resolveDeepSeekAccountToken, resolveDeepSeekApiKey } from "@deepseek-ai/dsh-llm-deepseek";
4
5
  import { WebError } from "@deepseek-ai/dsh-web";
5
6
  //#region lib/types/provider.js
6
7
  /**
@@ -86,6 +87,17 @@ function mapAnthropicResponse(response) {
86
87
  var DeepSeekSearchProvider = class {
87
88
  resolveOptions;
88
89
  id = DEEPSEEK_PROVIDER_ID;
90
+ /** Picker description: what this provider suits and what it costs or cannot do. */
91
+ description = {
92
+ en: "Slower, and every search uses extra model tokens. Requires a DeepSeek account or API key.",
93
+ zh: "速度较慢,每次搜索都会额外消耗模型 token。需要 DeepSeek 账号或 API Key。",
94
+ ja: "低速で、検索のたびに追加のモデルトークンを消費します。DeepSeek アカウントまたは API キーが必要です。",
95
+ es: "Más lenta, y cada búsqueda consume tokens adicionales del modelo. Requiere una cuenta de DeepSeek o una clave de API.",
96
+ fr: "Plus lente, et chaque recherche consomme des jetons de modèle supplémentaires. Nécessite un compte DeepSeek ou une clé API.",
97
+ de: "Langsamer, und jede Suche verbraucht zusätzliche Modell-Tokens. Erfordert ein DeepSeek-Konto oder einen API-Schlüssel.",
98
+ ru: "Работает медленнее, и каждый поиск расходует дополнительные токены модели. Требуется учётная запись DeepSeek или ключ API.",
99
+ pt: "Mais lenta, e cada pesquisa consome tokens extras do modelo. Requer uma conta DeepSeek ou uma chave de API."
100
+ };
89
101
  /**
90
102
  * @param resolveOptions - the options for the NEXT operation, snapshotted
91
103
  * once at each operation's entry so one search never mixes two sections. A
@@ -150,14 +162,21 @@ var DeepSeekSearchProvider = class {
150
162
  if (!response.ok) {
151
163
  const status = response.status;
152
164
  let message = `DeepSeek API error (HTTP ${status})`;
165
+ let aborted;
153
166
  try {
154
167
  const parsed = await response.json();
155
168
  const detail = typeof parsed.error === "string" ? parsed.error : parsed.error?.message ?? parsed.message;
156
169
  if (detail !== void 0 && detail.length > 0) message += `: ${detail}`;
157
170
  } catch (error) {
158
- if (signal?.aborted === true || isAbortError(error)) throw searchAborted(signal, error);
171
+ if (signal?.aborted === true || isAbortError(error)) aborted = searchAborted(signal, error);
172
+ }
173
+ if (status === 401 && auth.kind === "account") {
174
+ try {
175
+ await auth.reject?.();
176
+ } catch (_credentialRemovalFailed) {}
177
+ throw aborted ?? accountRejectedError(message);
159
178
  }
160
- if (status === 401 && auth.kind === "account") throw accountRejectedError(message);
179
+ if (aborted !== void 0) throw aborted;
161
180
  throw searchEndpointError(endpoint, message);
162
181
  }
163
182
  try {
@@ -175,11 +194,12 @@ var DeepSeekSearchProvider = class {
175
194
  * @returns the account-token header when one resolves, otherwise the API-key headers, tagged by credential kind.
176
195
  */
177
196
  async authHeaders(options, endpoint, signal) {
178
- const { resolveAccountToken } = options;
197
+ const { resolveAccountToken, rejectAccountToken } = options;
179
198
  const token = resolveAccountToken === void 0 ? void 0 : await resolveCredential(() => resolveAccountToken(endpoint), signal);
180
199
  if (token !== void 0 && token.length > 0) return {
181
200
  kind: "account",
182
- headers: { "x-dsh-auth-token": token }
201
+ headers: { "x-dsh-auth-token": token },
202
+ ...rejectAccountToken === void 0 ? {} : { reject: () => rejectAccountToken(token) }
183
203
  };
184
204
  const apiKey = await this.apiKey(options, signal);
185
205
  return {
@@ -228,7 +248,7 @@ function accountRejectedError(message) {
228
248
  }
229
249
  /** Add endpoint recovery instructions to failures that occur after request dispatch begins. */
230
250
  function searchEndpointError(endpoint, message, cause) {
231
- return new WebError(`${message}\n\nThe web request used endpoint ${JSON.stringify(endpoint)}. Search endpoint configuration is separate from chat. If that endpoint is not intended, guide the user to Plugins > Built-in plugin settings > Web search, where they can change and save Messages API base URL. If that settings page is unavailable, the user can set web-search-deepseek.baseURL to a trusted DeepSeek endpoint. Only the user should choose or change the endpoint.`, "WEB_PROVIDER_ERROR", cause === void 0 ? void 0 : { cause });
251
+ return new WebError(`${message}\n\nThe web request used endpoint ${JSON.stringify(endpoint)}. Search endpoint configuration is separate from chat. If that endpoint is not intended, guide the user to Plugins > Built-in plugin settings > Web search and fetch, select DeepSeek (legacy) under Search, and change and save its Base URL. If that settings page is unavailable, the user can set web-search-deepseek.baseURL to a trusted DeepSeek endpoint. Only the user should choose or change the endpoint.`, "WEB_PROVIDER_ERROR", cause === void 0 ? void 0 : { cause });
232
252
  }
233
253
  /**
234
254
  * Race a same-process asynchronous preflight against caller cancellation. The
@@ -307,14 +327,10 @@ function resolveOptions(ctx, config) {
307
327
  ...literalApiKey === void 0 ? {} : { apiKey: literalApiKey },
308
328
  resolveAccountToken: async (endpoint) => {
309
329
  if (ctx.get("agents")?.currentInitiator()?.session.requestContext()?.provider !== ACCOUNT_PROVIDER) return void 0;
310
- return await ctx.get("deepseekAccount")?.resolveToken(endpoint);
311
- },
312
- resolveApiKey: async () => {
313
- const credentials = ctx.get("credentials");
314
- if (credentials !== void 0) return (await credentials.resolve(apiKeyEnv))?.value;
315
- const ambient = launchEnvironmentOf(ctx).get(apiKeyEnv);
316
- return ambient !== void 0 && ambient.value.length > 0 ? ambient.value : void 0;
330
+ return await resolveDeepSeekAccountToken(ctx, endpoint);
317
331
  },
332
+ rejectAccountToken: (token) => rejectDeepSeekAccountToken(ctx, token),
333
+ resolveApiKey: () => resolveDeepSeekApiKey(ctx, apiKeyEnv),
318
334
  apiKeyEnv,
319
335
  baseURL: config.baseURL ?? launchEnvironmentOf(ctx).get(SEARCH_BASE_URL_ENV)?.value ?? "https://api.deepseek.com/anthropic/v1",
320
336
  model: config.model,
@@ -349,13 +365,8 @@ async function searchConfigured(ctx, options, route) {
349
365
  if (token !== void 0 && token.length > 0) return true;
350
366
  }
351
367
  if (options.apiKey !== void 0) return true;
352
- const credentials = ctx.get("credentials");
353
- if (credentials === void 0) {
354
- const ambient = launchEnvironmentOf(ctx).get(options.apiKeyEnv);
355
- return ambient !== void 0 && ambient.value.length > 0;
356
- }
357
368
  try {
358
- return (await credentials.describe(options.apiKeyEnv)).configured;
369
+ return await deepSeekApiKeyConfigured(ctx, options.apiKeyEnv);
359
370
  } catch (_unreadableStore) {
360
371
  return false;
361
372
  }
@@ -377,6 +388,7 @@ function apply(ctx, config) {
377
388
  const provider = new DeepSeekSearchProvider(options);
378
389
  ctx.web.registerSearchProvider({
379
390
  id: provider.id,
391
+ description: provider.description,
380
392
  available: () => provider.available(),
381
393
  ready: (llmProvider) => searchConfigured(ctx, options(), llmProvider),
382
394
  search: (request, signal) => provider.search(request, signal)
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAEnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAqBxC,OAAO,EACL,sBAAsB,EACtB,4BAA4B,EAC5B,yBAAyB,EACzB,2BAA2B,EAC3B,yBAAyB,EACzB,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,eAAe,CAAA;AACtB,YAAY,EAAE,wBAAwB,EAAE,6BAA6B,EAAE,MAAM,eAAe,CAAA;AAE5F,qDAAqD;AACrD,eAAO,MAAM,IAAI,wBAAwB,CAAA;AAEzC,iDAAiD;AACjD,eAAO,MAAM,MAAM,UAAU,CAAA;AAI7B,kFAAkF;AAClF,MAAM,WAAW,MAAM;IACrB,kGAAkG;IAClG,MAAM,EAAE,QAAQ,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;IACpC,qFAAqF;IACrF,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;IAC3B,mEAAmE;IACnE,OAAO,EAAE,QAAQ,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;IACrC,oEAAoE;IACpE,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;IACvB,kEAAkE;IAClE,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;IAC5B,kFAAkF;IAClF,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;IA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AsB,CAAC,OAAO,CAAC,CAAA;IACpD,GAAG,CAAC,GAAG,CAAC,sBAAsB,CAAC;QAC7B,EAAE,EAAE,QAAQ,CAAC,EAAE;QACf,WAAW,EAAE,QAAQ,CAAC,WAAW;QACjC,SAAS,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,SAAS,EAAE;QACrC,KAAK,EAAE,WAAW,CAAC,EAAE,CAAC,gBAAgB,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,WAAW,CAAC;QACnE,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC;KAC9D,CAAC,CAAA;AACJ,CAAC"}
@@ -80,6 +80,8 @@ export interface DeepSeekSearchProviderOptions {
80
80
  * `undefined` selects API-key authentication.
81
81
  */
82
82
  resolveAccountToken?: (endpoint: string) => Promise<string | undefined>;
83
+ /** Invalidate the exact account token rejected by HTTP 401; failures must not replace the search error. */
84
+ rejectAccountToken?: (token: string) => Promise<void>;
83
85
  /** Literal DeepSeek API key; when present it wins over {@link resolveApiKey}. */
84
86
  apiKey?: string;
85
87
  /** Resolve the current DeepSeek API key for one search operation. */
@@ -131,6 +133,8 @@ export declare function mapAnthropicResponse(response: AnthropicResponse): WebSe
131
133
  export declare class DeepSeekSearchProvider implements WebSearchProvider {
132
134
  private readonly resolveOptions;
133
135
  readonly id = "deepseek-official";
136
+ /** Picker description: what this provider suits and what it costs or cannot do. */
137
+ readonly description: NonNullable<WebSearchProvider['description']>;
134
138
  /**
135
139
  * @param resolveOptions - the options for the NEXT operation, snapshotted
136
140
  * once at each operation's entry so one search never mixes two sections. A
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EAEhB,MAAM,sBAAsB,CAAA;A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B;AAED,2EAA2E;AAC3E,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,wBAAwB,CAAA;IAC9B,OAAO,CAAC,EAAE,mBAAmB,EAAE,CAAA;CAChC;AAED,wEAAwE;AACxE,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC3B;AAED,wEAAwE;AACxE,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,SAAS,CAAC,EAAE,gBAAgB,EAAE,CAAA;CAC/B;AAED,gFAAgF;AAChF,MAAM,MAAM,YAAY,GAAG,wBAAwB,GAAG,SAAS,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAElF,uDAAuD;AACvD,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,YAAY,EAAE,CAAA;CACzB;AAED,qEAAqE;AACrE,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAA;IACrC,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@deepseek-ai/dsh-web-search-deepseek",
3
3
  "description": "DeepSeek-backed search provider (native web_search via the Anthropic-compatible API) for the DeepSeek Harness web capability seam (ctx.web)",
4
- "version": "0.2.2-rc.1",
4
+ "version": "0.2.2-rc.3",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -25,31 +25,36 @@
25
25
  "files": [
26
26
  "locale/*.json",
27
27
  "lib/index.js",
28
- "lib/types/**/*.d.ts"
28
+ "lib/types/**/*.d.ts",
29
+ "lib/types/**/*.d.ts.map",
30
+ "lib/**/*.js.map",
31
+ "src"
29
32
  ],
30
33
  "license": "MIT",
31
34
  "peerDependencies": {
32
- "@deepseek-ai/dsh-agent": "0.2.2-rc.1",
33
- "@deepseek-ai/dsh-credentials": "0.2.2-rc.1",
34
- "@deepseek-ai/dsh-deepseek-account": "0.2.2-rc.1",
35
- "@deepseek-ai/dsh-launch-environment": "0.2.2-rc.1",
36
- "@deepseek-ai/dsh-session": "0.2.2-rc.1",
37
- "@deepseek-ai/dsh-web": "0.2.2-rc.1",
35
+ "@deepseek-ai/dsh-agent": "0.2.2-rc.3",
36
+ "@deepseek-ai/dsh-credentials": "0.2.2-rc.3",
37
+ "@deepseek-ai/dsh-deepseek-account": "0.2.2-rc.3",
38
+ "@deepseek-ai/dsh-launch-environment": "0.2.2-rc.3",
39
+ "@deepseek-ai/dsh-llm-deepseek": "0.2.2-rc.3",
40
+ "@deepseek-ai/dsh-session": "0.2.2-rc.3",
41
+ "@deepseek-ai/dsh-web": "0.2.2-rc.3",
38
42
  "@deepseek-ai/cordis": "~4.1.0"
39
43
  },
40
44
  "dependencies": {
41
45
  "@deepseek-ai/schemastery": "~3.19.0"
42
46
  },
43
47
  "devDependencies": {
44
- "@deepseek-ai/dsh-agent": "0.2.2-rc.1",
45
- "@deepseek-ai/dsh-credentials": "0.2.2-rc.1",
46
- "@deepseek-ai/dsh-credentials-local": "0.2.2-rc.1",
47
- "@deepseek-ai/dsh-deepseek-account": "0.2.2-rc.1",
48
- "@deepseek-ai/dsh-launch-environment": "0.2.2-rc.1",
49
- "@deepseek-ai/dsh-session": "0.2.2-rc.1",
50
- "@deepseek-ai/dsh-web": "0.2.2-rc.1",
48
+ "@deepseek-ai/dsh-agent": "0.2.2-rc.3",
49
+ "@deepseek-ai/dsh-credentials": "0.2.2-rc.3",
50
+ "@deepseek-ai/dsh-credentials-local": "0.2.2-rc.3",
51
+ "@deepseek-ai/dsh-deepseek-account": "0.2.2-rc.3",
52
+ "@deepseek-ai/dsh-launch-environment": "0.2.2-rc.3",
53
+ "@deepseek-ai/dsh-llm-deepseek": "0.2.2-rc.3",
54
+ "@deepseek-ai/dsh-session": "0.2.2-rc.3",
55
+ "@deepseek-ai/dsh-web": "0.2.2-rc.3",
51
56
  "@deepseek-ai/cordis": "~4.1.0",
52
- "@deepseek-ai/dsh-http-proxy": "0.2.2-rc.1"
57
+ "@deepseek-ai/dsh-http-proxy": "0.2.2-rc.3"
53
58
  },
54
59
  "peerDependenciesMeta": {
55
60
  "@deepseek-ai/dsh-deepseek-account": {
package/src/index.ts ADDED
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Register a DeepSeek-backed provider in `ctx.web`. It calls the Anthropic-compatible Messages API
3
+ * with native `web_search_20250305`. A search initiated by a Session on the DeepSeek account route
4
+ * authenticates with the account token when the account service allows the search endpoint;
5
+ * every other search reuses `DEEPSEEK_API_KEY`. The provider does not reuse `DEEPSEEK_BASE_URL`;
6
+ * auxiliary search has its own endpoint configuration. The provider reports itself not ready for a
7
+ * model request whose search would have no credential.
8
+ * @module @deepseek-ai/dsh-web-search-deepseek
9
+ */
10
+ import type { Volatile } from '@deepseek-ai/cordis'
11
+
12
+ import type { Context } from '@deepseek-ai/cordis'
13
+ import z from '@deepseek-ai/schemastery'
14
+ import type {} from '@deepseek-ai/dsh-agent'
15
+ import { credentialRef } from '@deepseek-ai/dsh-credentials'
16
+ import type { CredentialRef } from '@deepseek-ai/dsh-credentials'
17
+ import type {} from '@deepseek-ai/dsh-deepseek-account'
18
+ import { launchEnvironmentOf } from '@deepseek-ai/dsh-launch-environment'
19
+ import {
20
+ deepSeekApiKeyConfigured, rejectDeepSeekAccountToken, resolveDeepSeekAccountToken, resolveDeepSeekApiKey,
21
+ } from '@deepseek-ai/dsh-llm-deepseek'
22
+ import type {} from '@deepseek-ai/dsh-session'
23
+ import type {} from '@deepseek-ai/dsh-web'
24
+ import {
25
+ DeepSeekSearchProvider,
26
+ DEEPSEEK_DEFAULT_API_VERSION,
27
+ DEEPSEEK_DEFAULT_BASE_URL,
28
+ DEEPSEEK_DEFAULT_MAX_TOKENS,
29
+ DEEPSEEK_DEFAULT_MAX_USES,
30
+ DEEPSEEK_DEFAULT_MODEL,
31
+ } from './provider.ts'
32
+ import type { DeepSeekSearchProviderOptions } from './provider.ts'
33
+
34
+ export {
35
+ DeepSeekSearchProvider,
36
+ DEEPSEEK_DEFAULT_API_VERSION,
37
+ DEEPSEEK_DEFAULT_BASE_URL,
38
+ DEEPSEEK_DEFAULT_MAX_TOKENS,
39
+ DEEPSEEK_DEFAULT_MAX_USES,
40
+ DEEPSEEK_DEFAULT_MODEL,
41
+ DEEPSEEK_PROVIDER_ID,
42
+ } from './provider.ts'
43
+ export type { DeepSeekSearchLlmRequest, DeepSeekSearchProviderOptions } from './provider.ts'
44
+
45
+ /** Cordis plugin name used by loader diagnostics. */
46
+ export const name = 'web-search-deepseek'
47
+
48
+ /** The web seam this provider registers into. */
49
+ export const inject = ['web']
50
+
51
+ const DEFAULT_API_KEY_ENV = 'DEEPSEEK_API_KEY'
52
+
53
+ /** Plugin config (all optional — `apply` fills env-var and constant defaults). */
54
+ export interface Config {
55
+ /** Literal DeepSeek API key; prefer {@link apiKeyEnv} so no secret enters configuration files. */
56
+ apiKey: Volatile<string | undefined>
57
+ /** Credential reference resolved for each search; defaults to `DEEPSEEK_API_KEY`. */
58
+ apiKeyEnv: Volatile<string>
59
+ /** Anthropic-compatible endpoint base; `/messages` is appended. */
60
+ baseURL: Volatile<string | undefined>
61
+ /** Anthropic-format model name. Defaults to `deepseek-v4-flash`. */
62
+ model: Volatile<string>
63
+ /** `anthropic-version` header value. Defaults to `2023-06-01`. */
64
+ apiVersion: Volatile<string>
65
+ /** Upper bound on generated tokens for the Messages request. Defaults to 4096. */
66
+ maxTokens: Volatile<number>
67
+ /** Maximum `web_search` server-tool uses per request. Defaults to 5. */
68
+ maxUses: Volatile<number>
69
+ }
70
+
71
+ export const Config = z.object({
72
+ apiKey: z.string().role('secret').volatile(),
73
+ apiKeyEnv: z.string().role('credential-ref').default(DEFAULT_API_KEY_ENV).volatile(),
74
+ // Declared here rather than only at the use site: a configuration surface
75
+ // renders the resolved section, so a default the schema does not carry reads
76
+ // there as no value at all.
77
+ baseURL: z.string().volatile(),
78
+ model: z.string().default(DEEPSEEK_DEFAULT_MODEL).volatile(),
79
+ apiVersion: z.string().default(DEEPSEEK_DEFAULT_API_VERSION).volatile(),
80
+ maxTokens: z.number().step(1).min(1).default(DEEPSEEK_DEFAULT_MAX_TOKENS).volatile(),
81
+ maxUses: z.number().step(1).min(1).default(DEEPSEEK_DEFAULT_MAX_USES).volatile(),
82
+ })
83
+
84
+ /**
85
+ * Auxiliary-search endpoint, independent of the conversation adapter's
86
+ * `$DEEPSEEK_BASE_URL` and selected protocol.
87
+ */
88
+ const SEARCH_BASE_URL_ENV = 'DEEPSEEK_SEARCH_BASE_URL'
89
+
90
+ /** Provider route id `dsh-llm-deepseek-account` registers; `request/context` events record it per Session. */
91
+ const ACCOUNT_PROVIDER = 'deepseek-account'
92
+
93
+ /** Settings namespace carrying this provider's endpoint, model, and key reference. */
94
+ export const WEB_SEARCH_DEEPSEEK_SETTINGS_NAMESPACE = 'web-search-deepseek'
95
+
96
+ /** Options for one search, with the key reference the readiness check reads. */
97
+ type SearchOptions = DeepSeekSearchProviderOptions & { readonly apiKeyEnv: CredentialRef }
98
+
99
+ /**
100
+ * Project one resolved section into the options the provider serves its next
101
+ * search with. Environment fallbacks stay here rather than in the provider:
102
+ * every value it reads is already fully defaulted.
103
+ * @param ctx - plugin context supplying the credential and environment planes.
104
+ * @param config - the currently authoritative section.
105
+ * @returns options for one search.
106
+ */
107
+ function resolveOptions(
108
+ ctx: Context, config: { [K in keyof Config]: ReturnType<Config[K]['get']> },
109
+ ): SearchOptions {
110
+ const apiKeyEnv = credentialRef(config.apiKeyEnv)
111
+ const literalApiKey = config.apiKey !== undefined && config.apiKey.length > 0
112
+ ? config.apiKey
113
+ : undefined
114
+ return {
115
+ ...literalApiKey === undefined ? {} : { apiKey: literalApiKey },
116
+ resolveAccountToken: async (endpoint) => {
117
+ // The latest request context names the route that served the model
118
+ // request which called this search, as account sign-out reads it.
119
+ const provider = ctx.get('agents')?.currentInitiator()?.session.requestContext()?.provider
120
+ if (provider !== ACCOUNT_PROVIDER) return undefined
121
+ return await resolveDeepSeekAccountToken(ctx, endpoint)
122
+ },
123
+ rejectAccountToken: token => rejectDeepSeekAccountToken(ctx, token),
124
+ resolveApiKey: () => resolveDeepSeekApiKey(ctx, apiKeyEnv),
125
+ apiKeyEnv,
126
+ baseURL: config.baseURL
127
+ ?? launchEnvironmentOf(ctx).get(SEARCH_BASE_URL_ENV)?.value
128
+ ?? DEEPSEEK_DEFAULT_BASE_URL,
129
+ model: config.model,
130
+ apiVersion: config.apiVersion,
131
+ maxTokens: config.maxTokens,
132
+ maxUses: config.maxUses,
133
+ recordRequest: (request) => {
134
+ ctx.get('agents')?.currentInitiator()?.session.append(
135
+ 'web/deepseek-search-llm-request',
136
+ request,
137
+ )
138
+ },
139
+ }
140
+ }
141
+
142
+ /**
143
+ * Whether the search a model request on `route` would make has a credential, checked in the order
144
+ * the search resolves them: the account token first on the account route, then the API key. A failed
145
+ * read answers false, because the search fails on that read instead of trying the next credential.
146
+ * Only presence is checked: the API key's value is not read and the endpoint is not contacted, so a
147
+ * wrong key or an endpoint without native search still counts as configured.
148
+ * @param ctx - plugin context supplying the account, credential, and environment planes.
149
+ * @param options - options the next search would use.
150
+ * @param route - provider route of the model request being assembled.
151
+ * @returns whether the account token or an API key is available to that search.
152
+ */
153
+ async function searchConfigured(
154
+ ctx: Context, options: SearchOptions, route: string | undefined,
155
+ ): Promise<boolean> {
156
+ const account = ctx.get('deepseekAccount')
157
+ if (route === ACCOUNT_PROVIDER && account !== undefined) {
158
+ let token: string | undefined
159
+ try { token = await account.resolveToken(`${options.baseURL}/messages`) }
160
+ catch (_unreadableGrant) { return false /* The search fails on this read before it tries the API key. */ }
161
+ if (token !== undefined && token.length > 0) return true
162
+ }
163
+ if (options.apiKey !== undefined) return true
164
+ try { return await deepSeekApiKeyConfigured(ctx, options.apiKeyEnv) }
165
+ catch (_unreadableStore) { return false /* A store that cannot be read supplies no key to the search either. */ }
166
+ }
167
+
168
+ /**
169
+ * Register the DeepSeek search provider with `ctx.web`. Its `ready()` answers whether a
170
+ * search for a model request on the given route would have a credential to send.
171
+ */
172
+ export function apply(ctx: Context, config: Config): void {
173
+ const options = () => resolveOptions(ctx, {
174
+ apiKey: config.apiKey.get(), apiKeyEnv: config.apiKeyEnv.get(), baseURL: config.baseURL.get(), model: config.model.get(),
175
+ apiVersion: config.apiVersion.get(), maxTokens: config.maxTokens.get(), maxUses: config.maxUses.get(),
176
+ })
177
+ const provider = new DeepSeekSearchProvider(options)
178
+ ctx.web.registerSearchProvider({
179
+ id: provider.id,
180
+ description: provider.description,
181
+ available: () => provider.available(),
182
+ ready: llmProvider => searchConfigured(ctx, options(), llmProvider),
183
+ search: (request, signal) => provider.search(request, signal),
184
+ })
185
+ }
@@ -0,0 +1,462 @@
1
+ /**
2
+ * DeepSeek search through an Anthropic-compatible Messages model call with the native
3
+ * `web_search_20250305` server tool. Each search costs a model turn, but returns structured
4
+ * result blocks; absence of those blocks is an error rather than a prose-scraping fallback.
5
+ * The wire format and native `fetch` client are provider-private and do not use `ctx.llm`.
6
+ * @module @deepseek-ai/dsh-web-search-deepseek/provider
7
+ */
8
+
9
+ import { WebError } from '@deepseek-ai/dsh-web'
10
+ import type {
11
+ WebSearchProvider,
12
+ WebSearchRequest,
13
+ WebSearchResult,
14
+ WebSearchSource,
15
+ } from '@deepseek-ai/dsh-web'
16
+ import type { CredentialRef } from '@deepseek-ai/dsh-credentials'
17
+ import type {} from '@deepseek-ai/dsh-session'
18
+ import type {
19
+ AnthropicError,
20
+ AnthropicResponse,
21
+ ContentBlock,
22
+ TextBlock,
23
+ WebSearchToolResultBlock,
24
+ } from './types.ts'
25
+
26
+ /** Stable id this provider registers under. */
27
+ export const DEEPSEEK_PROVIDER_ID = 'deepseek-official'
28
+
29
+ /**
30
+ * Default auxiliary-search endpoint, including `/v1`; `/messages` is appended.
31
+ * `$DEEPSEEK_SEARCH_BASE_URL` overrides it independently of the conversation
32
+ * adapter's endpoint. Both providers share the API key.
33
+ */
34
+ export const DEEPSEEK_DEFAULT_BASE_URL = 'https://api.deepseek.com/anthropic/v1'
35
+
36
+ /** Default Anthropic-format model name (aligned with the repo's DeepSeek model vocabulary). */
37
+ export const DEEPSEEK_DEFAULT_MODEL = 'deepseek-v4-flash'
38
+
39
+ /** Default `anthropic-version` header value. */
40
+ export const DEEPSEEK_DEFAULT_API_VERSION = '2023-06-01'
41
+
42
+ /** Default upper bound on generated tokens for the Messages request. */
43
+ export const DEEPSEEK_DEFAULT_MAX_TOKENS = 4096
44
+
45
+ /** Default maximum `web_search` server-tool uses per request. */
46
+ export const DEEPSEEK_DEFAULT_MAX_USES = 5
47
+
48
+ /** Attribution header sent on every request. Bump with the package version. */
49
+ const USER_AGENT = 'deepseek-harness/0.0.1'
50
+
51
+ /**
52
+ * Exact secret-free DeepSeek Messages request recorded immediately before one
53
+ * auxiliary search dispatch.
54
+ */
55
+ export interface DeepSeekSearchLlmRequest {
56
+ /** Fully resolved Messages endpoint. */
57
+ readonly endpoint: string
58
+ /** `anthropic-version` header value. */
59
+ readonly apiVersion: string
60
+ /** Exact JSON body sent to the provider. */
61
+ readonly body: {
62
+ readonly model: string
63
+ readonly max_tokens: number
64
+ readonly messages: readonly [{
65
+ readonly role: 'user'
66
+ readonly content: readonly [{
67
+ readonly type: 'text'
68
+ readonly text: string
69
+ }]
70
+ }]
71
+ readonly tools: readonly [{
72
+ readonly type: 'web_search_20250305'
73
+ readonly name: 'web_search'
74
+ readonly max_uses: number
75
+ }]
76
+ /**
77
+ * Thinking mode for the auxiliary turn. The provider always sends
78
+ * `disabled`: it discards the generated text, so reasoning tokens have no
79
+ * consumer. Absent means the request omitted the field and the provider
80
+ * applied its default.
81
+ */
82
+ readonly thinking?: { readonly type: 'disabled' }
83
+ }
84
+ }
85
+
86
+ declare module '@deepseek-ai/dsh-session/types' {
87
+ interface SessionEventMap {
88
+ /** Secret-free auxiliary DeepSeek search request recorded before dispatch. */
89
+ 'web/deepseek-search-llm-request': DeepSeekSearchLlmRequest
90
+ }
91
+ }
92
+
93
+ /** Resolved provider options (the plugin's `apply` supplies credential and constant defaults). */
94
+ export interface DeepSeekSearchProviderOptions {
95
+ /**
96
+ * Resolve the DeepSeek account token for one search endpoint. A token takes
97
+ * precedence over every API key and is sent only as `x-dsh-auth-token`;
98
+ * `undefined` selects API-key authentication.
99
+ */
100
+ resolveAccountToken?: (endpoint: string) => Promise<string | undefined>
101
+ /** Invalidate the exact account token rejected by HTTP 401; failures must not replace the search error. */
102
+ rejectAccountToken?: (token: string) => Promise<void>
103
+ /** Literal DeepSeek API key; when present it wins over {@link resolveApiKey}. */
104
+ apiKey?: string
105
+ /** Resolve the current DeepSeek API key for one search operation. */
106
+ resolveApiKey?: () => Promise<string | undefined>
107
+ /** Credential reference named by missing-credential diagnostics. */
108
+ apiKeyEnv?: CredentialRef
109
+ /** Endpoint base; `/messages` is appended. */
110
+ baseURL: string
111
+ /** Anthropic-format model name. */
112
+ model: string
113
+ /** `anthropic-version` header value. */
114
+ apiVersion: string
115
+ /** Upper bound on generated tokens for the Messages request. */
116
+ maxTokens: number
117
+ /** Maximum `web_search` server-tool uses per request. */
118
+ maxUses: number
119
+ /**
120
+ * Record the exact secret-free request immediately before dispatch. A throw
121
+ * prevents dispatch so model-visible auxiliary input cannot escape logging.
122
+ */
123
+ recordRequest?: (request: DeepSeekSearchLlmRequest) => void
124
+ }
125
+
126
+ /**
127
+ * Build a `url → cited_text` map from every `text` block's `citations[]`. This
128
+ * is the snippet source: Anthropic `web_search_result` items carry
129
+ * `url`/`title`/`page_age` but typically NO inline snippet — the excerpt lives
130
+ * in a separate `text` block's citation, keyed by `url` (first occurrence wins).
131
+ *
132
+ * @param blocks - the response's content blocks; non-`text` blocks are skipped.
133
+ * @returns the `url → cited_text` map (empty when no citations are present).
134
+ */
135
+ export function citationSnippets(blocks: readonly ContentBlock[]): Map<string, string> {
136
+ const map = new Map<string, string>()
137
+ for (const block of blocks) {
138
+ if (block.type !== 'text') continue
139
+ for (const cite of (block as TextBlock).citations ?? []) {
140
+ if (cite.url != null && cite.url.length > 0 && cite.cited_text != null && cite.cited_text.length > 0 && !map.has(cite.url)) {
141
+ map.set(cite.url, cite.cited_text)
142
+ }
143
+ }
144
+ }
145
+ return map
146
+ }
147
+
148
+ /**
149
+ * Map a DeepSeek Anthropic Messages response to a normalized search result. Walks
150
+ * `web_search_tool_result` blocks for citeable `web_search_result` items, joins each to its
151
+ * citation excerpt as `snippet`, and dedupes by `url` (a `max_uses > 1` request can surface
152
+ * the same URL across searches). The web service owns the final `maxResults` truncation, so
153
+ * `truncated` is always `false` here.
154
+ *
155
+ * @param response - the parsed Messages response body.
156
+ * @returns the normalized result with deduped, snippet-joined sources.
157
+ * @throws {@link WebError} when native search produced no result block.
158
+ */
159
+ export function mapAnthropicResponse(response: AnthropicResponse): WebSearchResult {
160
+ const blocks = response.content ?? []
161
+ const resultBlocks = blocks.filter(
162
+ (block): block is WebSearchToolResultBlock => block.type === 'web_search_tool_result',
163
+ )
164
+ if (resultBlocks.length === 0) {
165
+ throw new WebError(
166
+ 'DeepSeek returned no web_search_tool_result blocks; the request may not have triggered native web search',
167
+ 'WEB_PROVIDER_ERROR',
168
+ )
169
+ }
170
+
171
+ const snippets = citationSnippets(blocks)
172
+ const seen = new Set<string>()
173
+ const sources: WebSearchSource[] = []
174
+ for (const block of resultBlocks) {
175
+ for (const item of block.content ?? []) {
176
+ if (item.type !== 'web_search_result' || item.url.length === 0 || seen.has(item.url)) continue
177
+ seen.add(item.url)
178
+ const snippet = snippets.get(item.url)
179
+ sources.push({
180
+ url: item.url,
181
+ ...item.title != null && item.title.length > 0 ? { title: item.title } : {},
182
+ ...snippet != null && snippet.length > 0 ? { snippet } : {},
183
+ ...item.page_age != null && item.page_age.length > 0 ? { publishedAt: item.page_age } : {},
184
+ })
185
+ }
186
+ }
187
+ return { sources, truncated: false }
188
+ }
189
+
190
+ /** Authentication headers for one search, tagged by the credential that produced them. */
191
+ interface SearchAuth {
192
+ /** `account` for a DeepSeek account token, `api-key` for an API key. */
193
+ readonly kind: 'account' | 'api-key'
194
+ /** Headers carrying the credential. */
195
+ readonly headers: Readonly<Record<string, string>>
196
+ /** Request-bound invalidation, present only when an account token was sent. */
197
+ readonly reject?: () => Promise<void>
198
+ }
199
+
200
+ /**
201
+ * The DeepSeek-backed search provider. HTTP redirects fail as `WEB_PROVIDER_ERROR`;
202
+ * failures after dispatch name the endpoint and tell the model how the user can configure it.
203
+ */
204
+ export class DeepSeekSearchProvider implements WebSearchProvider {
205
+ readonly id = DEEPSEEK_PROVIDER_ID
206
+ /** Picker description: what this provider suits and what it costs or cannot do. */
207
+ readonly description: NonNullable<WebSearchProvider['description']> = {
208
+ en: 'Slower, and every search uses extra model tokens. Requires a DeepSeek account or API key.',
209
+ zh: '速度较慢,每次搜索都会额外消耗模型 token。需要 DeepSeek 账号或 API Key。',
210
+ ja: '低速で、検索のたびに追加のモデルトークンを消費します。DeepSeek アカウントまたは API キーが必要です。',
211
+ es: 'Más lenta, y cada búsqueda consume tokens adicionales del modelo. Requiere una cuenta de DeepSeek o una clave de API.',
212
+ fr: 'Plus lente, et chaque recherche consomme des jetons de modèle supplémentaires. Nécessite un compte DeepSeek ou une clé API.',
213
+ de: 'Langsamer, und jede Suche verbraucht zusätzliche Modell-Tokens. Erfordert ein DeepSeek-Konto oder einen API-Schlüssel.',
214
+ ru: 'Работает медленнее, и каждый поиск расходует дополнительные токены модели. Требуется учётная запись DeepSeek или ключ API.',
215
+ pt: 'Mais lenta, e cada pesquisa consome tokens extras do modelo. Requer uma conta DeepSeek ou uma chave de API.',
216
+ }
217
+
218
+ /**
219
+ * @param resolveOptions - the options for the NEXT operation, snapshotted
220
+ * once at each operation's entry so one search never mixes two sections. A
221
+ * thunk rather than a value because the plugin's settings section can change
222
+ * between searches, and re-registering the provider to carry a new endpoint
223
+ * would make the seam's selection observable to the user as a flicker.
224
+ */
225
+ constructor(private readonly resolveOptions: () => DeepSeekSearchProviderOptions) {}
226
+
227
+ available(): boolean {
228
+ const options = this.resolveOptions()
229
+ return ((options.apiKey?.length ?? 0) > 0 || options.resolveApiKey !== undefined || options.resolveAccountToken !== undefined)
230
+ && URL.canParse(options.baseURL)
231
+ && isPositiveInteger(options.maxTokens)
232
+ && isPositiveInteger(options.maxUses)
233
+ }
234
+
235
+ async search(request: WebSearchRequest, signal?: AbortSignal): Promise<WebSearchResult> {
236
+ // One snapshot for the whole operation: credential resolution awaits, and a
237
+ // settings write landing inside that await must not send the key resolved
238
+ // from the old section to the endpoint named by the new one.
239
+ const options = this.resolveOptions()
240
+ const endpoint = `${options.baseURL}/messages`
241
+ const auth = await this.authHeaders(options, endpoint, signal)
242
+ throwIfSearchAborted(signal)
243
+ const body: DeepSeekSearchLlmRequest['body'] = {
244
+ model: options.model,
245
+ max_tokens: options.maxTokens,
246
+ messages: [{
247
+ role: 'user',
248
+ content: [{ type: 'text', text: `Perform a web search for the query: ${request.query}` }],
249
+ }],
250
+ tools: [{ type: 'web_search_20250305', name: 'web_search', max_uses: options.maxUses }],
251
+ thinking: { type: 'disabled' },
252
+ }
253
+ options.recordRequest?.({
254
+ endpoint,
255
+ apiVersion: options.apiVersion,
256
+ body,
257
+ })
258
+ throwIfSearchAborted(signal)
259
+ let response: Response
260
+ try {
261
+ response = await fetch(endpoint, {
262
+ method: 'POST',
263
+ redirect: 'error',
264
+ headers: {
265
+ ...auth.headers,
266
+ 'anthropic-version': options.apiVersion,
267
+ 'content-type': 'application/json',
268
+ 'accept': 'application/json',
269
+ 'user-agent': USER_AGENT,
270
+ },
271
+ body: JSON.stringify(body),
272
+ ...signal !== undefined ? { signal } : {},
273
+ })
274
+ } catch (error: unknown) {
275
+ if (signal?.aborted === true || isAbortError(error)) throw searchAborted(signal, error)
276
+ throw searchEndpointError(
277
+ endpoint,
278
+ `DeepSeek search request failed: ${String(error)}`,
279
+ error,
280
+ )
281
+ }
282
+
283
+ if (!response.ok) {
284
+ const status = response.status
285
+ let message = `DeepSeek API error (HTTP ${status})`
286
+ let aborted: WebError | undefined
287
+ try {
288
+ const parsed = await response.json() as AnthropicError
289
+ const detail = typeof parsed.error === 'string' ? parsed.error : parsed.error?.message ?? parsed.message
290
+ if (detail !== undefined && detail.length > 0) message += `: ${detail}`
291
+ } catch (error: unknown) {
292
+ // An abort fired mid-body must surface as WEB_ABORTED, not be swallowed
293
+ // into a generic HTTP-error message — cancellation is not a provider
294
+ // error (the seam's cancellation contract).
295
+ if (signal?.aborted === true || isAbortError(error)) aborted = searchAborted(signal, error)
296
+ // Otherwise: the HTTP status is already captured in `message` above; a
297
+ // malformed/non-JSON error body (normal for gateway 5xx/429s) can only
298
+ // cost a richer provider message, never the real error.
299
+ }
300
+ // The account service released this token only for its inference
301
+ // origin, so the endpoint is not what the user must change.
302
+ if (status === 401 && auth.kind === 'account') {
303
+ // Invalidation can cancel this Session; finish reading the HTTP failure before it does. A cancelled read
304
+ // still invalidates the token the status rejected.
305
+ try { await auth.reject?.() }
306
+ catch (_credentialRemovalFailed) { /* Report the original failure even if credential removal fails. */ }
307
+ throw aborted ?? accountRejectedError(message)
308
+ }
309
+ if (aborted !== undefined) throw aborted
310
+ throw searchEndpointError(endpoint, message)
311
+ }
312
+
313
+ try {
314
+ const payload = await response.json() as AnthropicResponse
315
+ return mapAnthropicResponse(payload)
316
+ } catch (error: unknown) {
317
+ if (signal?.aborted === true || isAbortError(error)) throw searchAborted(signal, error)
318
+ const message = error instanceof WebError
319
+ ? error.message
320
+ : `DeepSeek returned an unprocessable response body: ${String(error)}`
321
+ throw searchEndpointError(endpoint, message, error)
322
+ }
323
+ }
324
+
325
+ /**
326
+ * Resolve one operation's authentication headers without retaining a credential on the provider.
327
+ * @param options - the caller's snapshot, so the credential and the endpoint it is sent to come from one section.
328
+ * @param endpoint - the Messages endpoint this operation dispatches to.
329
+ * @param signal - abort signal for the surrounding search.
330
+ * @returns the account-token header when one resolves, otherwise the API-key headers, tagged by credential kind.
331
+ */
332
+ private async authHeaders(
333
+ options: DeepSeekSearchProviderOptions, endpoint: string, signal?: AbortSignal,
334
+ ): Promise<SearchAuth> {
335
+ const { resolveAccountToken, rejectAccountToken } = options
336
+ const token = resolveAccountToken === undefined
337
+ ? undefined
338
+ : await resolveCredential(() => resolveAccountToken(endpoint), signal)
339
+ if (token !== undefined && token.length > 0) return {
340
+ kind: 'account', headers: { 'x-dsh-auth-token': token },
341
+ ...rejectAccountToken === undefined ? {} : { reject: () => rejectAccountToken(token) },
342
+ }
343
+ const apiKey = await this.apiKey(options, signal)
344
+ // Official DeepSeek expects `x-api-key`; an Anthropic-compatible proxy
345
+ // may expect `Authorization: Bearer` — send both so either resolves.
346
+ return { kind: 'api-key', headers: { 'x-api-key': apiKey, 'authorization': `Bearer ${apiKey}` } }
347
+ }
348
+
349
+ /**
350
+ * Resolve one operation's API key without retaining it on the provider.
351
+ * @param options - the caller's snapshot, so the key and the endpoint it is sent to come from one section.
352
+ * @param signal - abort signal for the surrounding search.
353
+ * @returns the resolved key.
354
+ */
355
+ private async apiKey(options: DeepSeekSearchProviderOptions, signal?: AbortSignal): Promise<string> {
356
+ throwIfSearchAborted(signal)
357
+ if (options.apiKey !== undefined && options.apiKey.length > 0) return options.apiKey
358
+ const { resolveApiKey } = options
359
+ const resolved = resolveApiKey === undefined ? undefined : await resolveCredential(resolveApiKey, signal)
360
+ if (resolved !== undefined && resolved.length > 0) return resolved
361
+ const ref = options.apiKeyEnv ?? 'DEEPSEEK_API_KEY'
362
+ throw new WebError(
363
+ `DeepSeek search has no API key for "${ref}"; store it through the credentials service`
364
+ + ' (the web Models page writes it), export it in the launching environment, or set a literal'
365
+ + ' "apiKey" in the web-search-deepseek config; a conversation using a DeepSeek Account model'
366
+ + ' searches with the account sign-in instead',
367
+ 'WEB_PROVIDER_CREDENTIAL_MISSING',
368
+ )
369
+ }
370
+ }
371
+
372
+ /**
373
+ * Run one credential resolver under the search's cancellation signal. An
374
+ * already-cancelled search never starts the resolver.
375
+ * @param resolve - the resolver; a synchronous throw is mapped like a rejection.
376
+ * @param signal - abort signal for the surrounding search.
377
+ * @returns the resolved credential, or undefined when the resolver supplied none.
378
+ * @throws {@link WebError} `WEB_ABORTED` on cancellation, `WEB_PROVIDER_ERROR` when the resolver fails.
379
+ */
380
+ async function resolveCredential(
381
+ resolve: () => Promise<string | undefined>, signal?: AbortSignal,
382
+ ): Promise<string | undefined> {
383
+ throwIfSearchAborted(signal)
384
+ try {
385
+ return await abortable(resolve(), signal)
386
+ } catch (error: unknown) {
387
+ if (signal?.aborted === true || isAbortError(error)) throw searchAborted(signal, error)
388
+ throw new WebError(
389
+ `DeepSeek search credential resolution failed: ${String(error)}`,
390
+ 'WEB_PROVIDER_ERROR',
391
+ { cause: error },
392
+ )
393
+ }
394
+ }
395
+
396
+ /** Replace endpoint guidance with sign-in guidance when DeepSeek rejects the account token. */
397
+ function accountRejectedError(message: string): WebError {
398
+ return new WebError(
399
+ `${message}\n\nDeepSeek rejected the account sign-in used for this web search. `
400
+ + 'Guide the user to sign in to DeepSeek again; the search endpoint does not need changing.',
401
+ 'WEB_PROVIDER_ERROR',
402
+ )
403
+ }
404
+
405
+ /** Add endpoint recovery instructions to failures that occur after request dispatch begins. */
406
+ function searchEndpointError(endpoint: string, message: string, cause?: unknown): WebError {
407
+ return new WebError(
408
+ `${message}\n\nThe web request used endpoint ${JSON.stringify(endpoint)}. `
409
+ + 'Search endpoint configuration is separate from chat. If that endpoint is not intended, '
410
+ + 'guide the user to Plugins > Built-in plugin settings > Web search and fetch, select DeepSeek (legacy) under Search, '
411
+ + 'and change and save its Base URL. If that settings page is unavailable, the user can set '
412
+ + 'web-search-deepseek.baseURL to a trusted DeepSeek endpoint. Only the user should choose or change the endpoint.',
413
+ 'WEB_PROVIDER_ERROR',
414
+ cause === undefined ? undefined : { cause },
415
+ )
416
+ }
417
+
418
+ /**
419
+ * Race a same-process asynchronous preflight against caller cancellation. The
420
+ * attached settlement handlers keep observing an uncooperative operation after
421
+ * abort so a later rejection cannot become unhandled.
422
+ */
423
+ function abortable<T>(operation: Promise<T>, signal?: AbortSignal): Promise<T> {
424
+ if (signal === undefined) return operation
425
+ if (signal.aborted) return Promise.reject(searchAborted(signal))
426
+ return new Promise<T>((resolve, reject) => {
427
+ const onAbort = (): void => { reject(searchAborted(signal)) }
428
+ signal.addEventListener('abort', onAbort, { once: true })
429
+ void operation.then(
430
+ (value) => {
431
+ signal.removeEventListener('abort', onAbort)
432
+ resolve(value)
433
+ },
434
+ (error: unknown) => {
435
+ signal.removeEventListener('abort', onAbort)
436
+ reject(new Error(String(error).replace(/^Error: /u, ''), { cause: error }))
437
+ },
438
+ )
439
+ })
440
+ }
441
+
442
+ /** Throw the provider's stable cancellation error when the caller already aborted. */
443
+ function throwIfSearchAborted(signal?: AbortSignal): void {
444
+ if (signal?.aborted === true) throw searchAborted(signal)
445
+ }
446
+
447
+ /** Build the provider's stable cancellation error while retaining the caller's reason. */
448
+ function searchAborted(signal?: AbortSignal, fallback?: unknown): WebError {
449
+ return new WebError('DeepSeek search aborted', 'WEB_ABORTED', {
450
+ cause: signal?.aborted === true ? signal.reason : fallback,
451
+ })
452
+ }
453
+
454
+ /** True for a fetch/`AbortSignal` abort, surfaced as `WEB_ABORTED`. */
455
+ function isAbortError(error: unknown): boolean {
456
+ return error instanceof DOMException && error.name === 'AbortError'
457
+ }
458
+
459
+ /** True for DeepSeek request limits that can be sent to the Messages API. */
460
+ function isPositiveInteger(value: number): boolean {
461
+ return Number.isInteger(value) && value > 0
462
+ }
package/src/types.ts ADDED
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Provider-private wire types for DeepSeek's Anthropic-compatible Messages API. Citeable
3
+ * result items and citation excerpts arrive in separate blocks; the provider joins them by
4
+ * URL. These types do not create a dependency on `ctx.llm`.
5
+ * @module @deepseek-ai/dsh-web-search-deepseek/types
6
+ */
7
+
8
+ /** A `web_search_result` item inside a `web_search_tool_result` block. */
9
+ export interface WebSearchResultItem {
10
+ type: string
11
+ url: string
12
+ title?: string | null
13
+ /** Provider-supplied page age/recency string (mapped to `publishedAt`). */
14
+ page_age?: string | null
15
+ }
16
+
17
+ /** A `web_search_tool_result` content block: the citeable result shape. */
18
+ export interface WebSearchToolResultBlock {
19
+ type: 'web_search_tool_result'
20
+ content?: WebSearchResultItem[]
21
+ }
22
+
23
+ /** One citation location inside a `text` block (the snippet source). */
24
+ export interface CitationLocation {
25
+ type?: string
26
+ url?: string | null
27
+ cited_text?: string | null
28
+ }
29
+
30
+ /** A `text` content block: the model's prose plus per-URL citations. */
31
+ export interface TextBlock {
32
+ type: 'text'
33
+ text?: string | null
34
+ citations?: CitationLocation[]
35
+ }
36
+
37
+ /** Any content block; only `web_search_tool_result` and `text` are consumed. */
38
+ export type ContentBlock = WebSearchToolResultBlock | TextBlock | { type: string }
39
+
40
+ /** DeepSeek's Anthropic Messages response envelope. */
41
+ export interface AnthropicResponse {
42
+ content?: ContentBlock[]
43
+ }
44
+
45
+ /** DeepSeek's error response envelope (best-effort; fields vary). */
46
+ export interface AnthropicError {
47
+ error?: { message?: string } | string
48
+ message?: string
49
+ }