dsh-web-search-plugin 0.6.1 → 0.8.0

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/lib/client.js CHANGED
@@ -32,64 +32,210 @@ window.__ModuleLoader__.load({
32
32
  const API_NS = "web-deepseek-api";
33
33
  const API_SEARCH = "deepseek-search-api";
34
34
  const API_FETCH = "deepseek-fetch-api";
35
+ /**
36
+ * Card value for "follow the conversation model": leaves `web.searchProvider`
37
+ * unset, so Harness `0.2.2-rc.5` routes DeepSeek model requests to the in-box
38
+ * `deepseek-official` provider and every other route to `deepseek-search-api`.
39
+ */
40
+ const AUTO = "__auto__";
41
+ /** The in-box DeepSeek provider's settings namespace; the card's DeepSeek rows read and write it. */
42
+ const LEGACY_NS = "web-search-deepseek";
43
+ /** Card fields bound to the in-box provider's keys. */
44
+ const LEGACY_FIELDS = {
45
+ deepseekApiKeyEnv: "apiKeyEnv",
46
+ deepseekBaseURL: "baseURL",
47
+ deepseekModel: "model",
48
+ deepseekMaxTokens: "maxTokens",
49
+ deepseekMaxUses: "maxUses"
50
+ };
35
51
  const API_FIELDS = { webApiKey: "apiKey", webApiKeyEnv: "apiKeyEnv", webApiBaseURL: "baseURL", webApiCount: "count" };
52
+ /**
53
+ * The same card fields against the per-capability `web-deepseek-api`
54
+ * schema that replaced `apiKey` / `apiKeyEnv` / `baseURL` in DSH
55
+ * `0.2.2-rc.2`. One card field can feed several keys: the card keeps a
56
+ * single credential and endpoint for Search and Fetch, so a write fans
57
+ * out to both capabilities and a read takes the first present key.
58
+ */
59
+ const API_FIELDS_SPLIT = {
60
+ webApiKeyEnv: ["searchApiKeyEnv", "fetchApiKeyEnv"],
61
+ webApiBaseURL: ["searchBaseURL", "fetchBaseURL"],
62
+ webApiCount: ["count"],
63
+ webApiSearchBilling: ["searchBilling"],
64
+ webApiFetchBilling: ["fetchBilling"]
65
+ };
66
+ /**
67
+ * Which `web-deepseek-api` schema the Host serves.
68
+ * `searchBilling` carries a schema default, so a ready section always
69
+ * answers it; the pre-rc.2 schema has no such field.
70
+ * @param snapshot - the `web-deepseek-api` config-form snapshot.
71
+ * @returns true for the per-capability schema.
72
+ */
73
+ function splitApiSchema(snapshot) {
74
+ const value = snapshot?.value;
75
+ return value !== void 0 && value !== null && Object.hasOwn(value, "searchBilling");
76
+ }
36
77
  /** Combine public ConfigForms; save parameters before switching providers.
37
78
  * Each namespace has its own revision. Refusal retains the page's draft;
38
79
  * previously accepted namespaces are not rolled back over concurrent edits.
39
80
  */
40
81
  function combinedScope(forms) {
41
- const plugin = forms.get(NS), web = forms.get("web"), api = forms.get(API_NS);
42
- const merge = (p, w, a) => {
82
+ const plugin = forms.get(NS), web = forms.get("web"), api = forms.get(API_NS), legacy = forms.get(LEGACY_NS);
83
+ /** Namespace keys one card field addresses on the schema in force. */
84
+ const apiKeys = (field, split) => split
85
+ ? API_FIELDS_SPLIT[field] ?? []
86
+ : API_FIELDS[field] === void 0 ? [] : [API_FIELDS[field]];
87
+ const apiFieldNames = (split) => Object.keys(split ? API_FIELDS_SPLIT : API_FIELDS);
88
+ const merge = (p, w, a, split, following) => {
43
89
  const value = { ...p, fetchProvider: w?.fetchProvider ?? "http" };
44
- if (w?.searchProvider === API_SEARCH) value.provider = API_SEARCH;
45
- for (const [field, key] of Object.entries(API_FIELDS)) if (a && Object.hasOwn(a, key)) value[field] = a[key];
90
+ if (following) value.provider = AUTO;
91
+ else if (w?.searchProvider === "deepseek-official") value.provider = "deepseek-official";
92
+ else if (w?.searchProvider === API_SEARCH) value.provider = API_SEARCH;
93
+ for (const field of apiFieldNames(split)) {
94
+ for (const key of apiKeys(field, split)) {
95
+ if (a === void 0 || !Object.hasOwn(a, key)) continue;
96
+ value[field] = a[key];
97
+ break;
98
+ }
99
+ }
46
100
  return value;
47
101
  };
102
+ const mergeUser = (p, w, a, split, following) => {
103
+ const user = { ...p.user };
104
+ for (const field of apiFieldNames(split)) {
105
+ const key = apiKeys(field, split).find((candidate) => Object.hasOwn(a.user ?? {}, candidate));
106
+ if (key !== void 0) user[field] = a.user[key];
107
+ }
108
+ if (Object.hasOwn(w.user ?? {}, "fetchProvider")) user.fetchProvider = w.user.fetchProvider;
109
+ if (following) user.provider = AUTO;
110
+ else if (w.user?.searchProvider === API_SEARCH) user.provider = API_SEARCH;
111
+ return user;
112
+ };
48
113
  return {
49
114
  getSnapshot() {
50
115
  const p = plugin.getSnapshot(), w = web.getSnapshot(), a = api.getSnapshot();
51
- return { ...p, value: merge(p.value, w.value, a.value), base: merge(p.base, w.base, a.base),
52
- user: { ...p.user, ...Object.fromEntries(Object.entries(API_FIELDS).filter(([, key]) => Object.hasOwn(a.user ?? {}, key)).map(([field, key]) => [field, a.user[key]])), ...(Object.hasOwn(w.user ?? {}, "fetchProvider") ? { fetchProvider: w.user.fetchProvider } : {}), ...(w.user?.searchProvider === API_SEARCH ? { provider: API_SEARCH } : {}) },
53
- revision: { plugin: p.revision, api: a.revision, web: w.revision },
116
+ const l = legacy.getSnapshot();
117
+ const split = splitApiSchema(a);
118
+ const autoAvailable = l.status === "ready";
119
+ const following = autoAvailable && w.status === "ready" && w.value?.searchProvider === void 0;
120
+ // DeepSeek rows belong to the in-box provider's namespace. A user value
121
+ // there wins; a value this card previously stored on its own namespace
122
+ // stays visible until the next save carries it over.
123
+ const overlay = (target, layer) => {
124
+ if (!autoAvailable) return target;
125
+ const next = { ...target };
126
+ for (const [field, key] of Object.entries(LEGACY_FIELDS)) {
127
+ const alias = SUPPLIER_CONFIG_ALIASES[field];
128
+ const declared = next[field] !== void 0 ? next[field] : alias !== void 0 ? next[alias] : void 0;
129
+ if (layer === "user") {
130
+ if (Object.hasOwn(l.user ?? {}, key)) next[field] = l.user[key];
131
+ } else if (layer === "base") {
132
+ next[field] = l.base?.[key];
133
+ } else if (Object.hasOwn(l.user ?? {}, key)) {
134
+ next[field] = l.value?.[key];
135
+ } else if (declared === void 0) {
136
+ next[field] = l.value?.[key];
137
+ }
138
+ }
139
+ return next;
140
+ };
141
+ return { ...p, value: overlay(merge(p.value, w.value, a.value, split, following), "value"),
142
+ base: overlay(merge(p.base, w.base, a.base, split, false), "base"),
143
+ user: overlay(mergeUser(p, w, a, split, following), "user"),
144
+ revision: { plugin: p.revision, api: a.revision, web: w.revision, legacy: l.revision },
54
145
  apiAvailable: a.status === "ready" && w.status === "ready",
55
146
  apiWritable: a.writable && w.writable,
147
+ apiSplit: split,
56
148
  selectionAvailable: w.status === "ready", selectionWritable: w.writable,
149
+ autoAvailable, following,
150
+ autoMissing: w.status === "ready" && !autoAvailable
151
+ && (w.value?.searchProvider === void 0 || w.value?.searchProvider === "deepseek-official"),
57
152
  searchProvider: w.value?.searchProvider };
58
153
  },
59
154
  subscribe(listener) {
60
- const stops = [plugin, web, api].map(scope => scope.subscribe(listener));
155
+ const stops = [plugin, web, api, legacy].map(scope => scope.subscribe(listener));
61
156
  return () => stops.forEach(stop => stop());
62
157
  },
63
158
  async mutate(ops, revisions) {
64
- const groups = { plugin: [], api: [], web: [] };
159
+ const split = splitApiSchema(api.getSnapshot());
160
+ const groups = { plugin: [], api: [], legacy: [], web: [] };
161
+ const legacySnapshot = legacy.getSnapshot();
162
+ const legacyReady = legacySnapshot.status === "ready";
163
+ const current = plugin.getSnapshot().value ?? {};
164
+ const webProvider = web.getSnapshot().value?.searchProvider;
165
+ const arrivingAuto = ops.some(op => op.path[0] === "provider" && op.op === "set" && op.value === AUTO);
166
+ // A profile pinned to this plugin's id with the Messages backend predates
167
+ // the in-box pin; the next save moves it onto `deepseek-official`.
168
+ const migrating = arrivingAuto
169
+ || (current.provider === "deepseek-official" && webProvider === "dsh-web-search");
65
170
  for (const op of ops) {
66
171
  const field = op.path[0];
67
- if (API_FIELDS[field]) groups.api.push({ ...op, path: [API_FIELDS[field]] });
68
- else if (field === "fetchProvider") groups.web.push(op);
172
+ const keys = apiKeys(field, split);
173
+ if (keys.length > 0) {
174
+ for (const key of keys) groups.api.push({ ...op, path: [key] });
175
+ } else if (field === "fetchProvider") groups.web.push(op);
69
176
  else if (field === "provider") {
177
+ if (op.op === "set" && op.value === AUTO) continue;
70
178
  if (op.op === "set" && op.value === API_SEARCH) groups.web.push({ op: "set", path: ["searchProvider"], value: API_SEARCH });
179
+ else if (op.op === "set" && op.value === "deepseek-official") groups.web.push({ op: "set", path: ["searchProvider"], value: "deepseek-official" });
71
180
  else {
72
181
  groups.plugin.push(op);
73
182
  groups.web.push({ op: "set", path: ["searchProvider"], value: "dsh-web-search" });
74
183
  }
184
+ } else if (LEGACY_FIELDS[field] !== void 0) {
185
+ groups.legacy.push({ ...op, path: [LEGACY_FIELDS[field]] });
75
186
  } else groups.plugin.push(op);
76
187
  }
188
+ if (arrivingAuto) groups.plugin.push({ op: "set", path: ["provider"], value: "deepseek-official" });
189
+ if (arrivingAuto && !groups.web.some(op => op.path[0] === "searchProvider")) {
190
+ groups.web.push({ op: "unset", path: ["searchProvider"] });
191
+ }
192
+ if (!arrivingAuto && migrating && !groups.web.some(op => op.path[0] === "searchProvider")) {
193
+ groups.web.push({ op: "set", path: ["searchProvider"], value: "deepseek-official" });
194
+ }
195
+ const seed = legacyReady && (arrivingAuto || migrating || groups.legacy.length > 0);
196
+ if (seed) {
197
+ // The card owns these rows now: carry over values this profile still
198
+ // stores on the plugin namespace, and leave the in-box defaults alone
199
+ // for anything nobody set.
200
+ const pluginUser = plugin.getSnapshot().user ?? {};
201
+ for (const [field, key] of Object.entries(LEGACY_FIELDS)) {
202
+ if (groups.legacy.some(op => op.path[0] === key)) continue;
203
+ if (Object.hasOwn(legacySnapshot.user ?? {}, key)) continue;
204
+ const alias = SUPPLIER_CONFIG_ALIASES[field];
205
+ const declared = Object.hasOwn(pluginUser, field) || (alias !== void 0 && Object.hasOwn(pluginUser, alias));
206
+ if (!declared) continue;
207
+ const value = pluginUser[field] ?? (alias !== void 0 ? pluginUser[alias] : void 0);
208
+ groups.legacy.push(value === void 0 || value === null || value === ""
209
+ ? { op: "unset", path: [key] }
210
+ : { op: "set", path: [key], value });
211
+ }
212
+ }
77
213
  if (groups.web.some(op => op.op === "set" && [API_SEARCH, API_FETCH].includes(op.value)) && api.getSnapshot().status !== "ready") return false;
78
- for (const [name, scope] of [["plugin", plugin], ["api", api], ["web", web]]) {
214
+ for (const [name, scope] of [["plugin", plugin], ["api", api], ["legacy", legacy], ["web", web]]) {
79
215
  if (groups[name].length && (scope.getSnapshot().status !== "ready" || !scope.getSnapshot().writable)) return false;
80
216
  }
81
- for (const [name, scope] of [["plugin", plugin], ["api", api], ["web", web]]) {
217
+ for (const [name, scope] of [["plugin", plugin], ["api", api], ["legacy", legacy], ["web", web]]) {
82
218
  if (groups[name].length && await scope.mutate(groups[name], revisions[name]) !== true) return false;
83
219
  }
84
220
  return true;
85
221
  },
86
222
  canWrite(plan) {
223
+ const split = splitApiSchema(api.getSnapshot());
224
+ const legacySnapshot = legacy.getSnapshot();
225
+ const legacyWritable = legacySnapshot.status === "ready" && legacySnapshot.writable;
226
+ const pinnedLegacy = plugin.getSnapshot().value?.provider === "deepseek-official"
227
+ && web.getSnapshot().value?.searchProvider === "dsh-web-search";
87
228
  return plan.every(item => {
88
229
  const field = item.field;
89
- if ([API_SEARCH, API_FETCH].includes(item.op?.value) && (api.getSnapshot().status !== "ready" || !api.getSnapshot().writable)) return false;
90
- const scope = API_FIELDS[field] ? api : field === "fetchProvider" ? web : plugin;
91
- return scope.getSnapshot().status === "ready" && scope.getSnapshot().writable
230
+ const value = item.op?.value;
231
+ if ([API_SEARCH, API_FETCH].includes(value) && (api.getSnapshot().status !== "ready" || !api.getSnapshot().writable)) return false;
232
+ if (LEGACY_FIELDS[field] !== void 0) return legacyWritable;
233
+ const scope = apiKeys(field, split).length > 0 ? api : field === "fetchProvider" ? web : plugin;
234
+ const writable = scope.getSnapshot().status === "ready" && scope.getSnapshot().writable
92
235
  && (field !== "provider" || (web.getSnapshot().status === "ready" && web.getSnapshot().writable));
236
+ if (!writable) return false;
237
+ const movesDeepSeek = field === "provider" && item.op?.op === "set" && (value === AUTO || value === "deepseek-official");
238
+ return (!movesDeepSeek && !pinnedLegacy) || legacyWritable;
93
239
  });
94
240
  }
95
241
  };
@@ -225,32 +371,47 @@ window.__ModuleLoader__.load({
225
371
 
226
372
  /** Locale bundles for the card. */
227
373
  const en = {
228
- nav: "Web search",
229
- provider: "Search engine",
374
+ nav: "Web search & fetch",
375
+ provider: "Web search provider",
230
376
  providerTavily: "Tavily",
231
377
  providerBrave: "Brave Search",
232
- providerDeepseek: "DeepSeek Messages search (default)",
378
+ providerDeepseek: "DeepSeek server-side search",
379
+ providerAuto: "Follow the conversation model",
380
+ providerAutoHint: "DeepSeek model requests use DeepSeek server-side search (no per-search charge, extra model tokens); every other model uses DeepSeek Search API. Picking an engine above pins it for every model.",
381
+ deepseekOwnedHint: "These rows belong to the in-box DeepSeek provider: it runs DeepSeek model requests in follow mode, and every model when server-side search is pinned.",
233
382
  providerApi: "DeepSeek Search API",
234
- searchHeading: "Search engines",
235
- fetchHeading: "Web retrieval",
236
- fetchProvider: "Retrieval method",
237
- fetchHttp: "Local HTTP (default)",
383
+ searchHeading: "Web search",
384
+ fetchHeading: "Web fetch",
385
+ fetchProvider: "Web fetch provider",
386
+ fetchHttp: "Local fetch",
238
387
  fetchApi: "DeepSeek Fetch API",
239
388
  fetchOther: "Current custom provider: ",
240
- fetchHttpHint: "Retrieve pages from this device. No DeepSeek Fetch API fee; returned content still uses conversation tokens.",
241
- apiHint: "Direct API requests, without an auxiliary model call. Search and Fetch are billed per successful request; reading results still uses conversation tokens.",
242
- messagesHint: "Uses an auxiliary Messages model request in addition to retrieval. Choose Search API to avoid that model call.",
389
+ fetchHttpHint: "Free, and reaches your intranet and this machine. Cannot render pages that need JavaScript or a sign-in, and cannot read PDFs. Returned content still uses conversation tokens.",
390
+ apiHint: "Direct API requests, without an auxiliary model call. Reading results still uses conversation tokens.",
391
+ providerDeepseekHint: "No per-search charge, but every search uses extra model tokens. Requires a DeepSeek account or API key.",
392
+ providerApiHint: "Costs money, paid by the account or API key chosen under Billing.",
393
+ providerFetchApiHint: "Cannot reach your intranet or this machine. Costs money, paid by the account or API key chosen under Billing.",
394
+ providerSearxngHint: "DuckDuckGo has no official search API. Point SearXNG at an instance that includes DuckDuckGo (most public ones do), or self-host one.",
395
+ advanced: "Advanced settings",
243
396
  apiBase: "DeepSeek Search / Fetch API base URL",
244
397
  apiCount: "Results per search",
245
- apiCountHint: "1–50 results per query; the tool's own result limit still applies. This does not limit requests or spending.",
246
- apiBilling: "API guide and billing ↗",
398
+ apiCountHint: "Results returned per search, 1–50, default 10.",
399
+ apiBillingMode: "Billing",
400
+ apiBillingAuto: "Automatic",
401
+ apiBillingAccount: "Signed-in DeepSeek account",
402
+ apiBillingApiKey: "DeepSeek API key",
403
+ apiBillingHint: "Follows the conversation's DeepSeek account or API key; with other models, uses the API key first, then the signed-in account.",
404
+ apiBillingAccountHint: "Requires signing in to DeepSeek.",
405
+ apiBillingApiKeyHint: "Uses the API key from the Models page; set one first.",
406
+ apiBilling: "Search & Fetch guide ↗",
247
407
  credentialConflict: "Two different keys target the same credential reference. Use one key or separate references.",
248
408
  invalidApiCount: "Enter a whole number from 1 to 50, or leave blank for the default.",
249
- apiBaseHint: "Include the API prefix, e.g. https://api.deepseek.com/v1/tools. Shared by Search and Fetch; separate from the Messages endpoint.",
250
- apiRefHint: "Credential shared by DeepSeek Search API and Fetch API. Account sessions may use an authorized account token.",
409
+ apiBaseHint: "Include the API prefix, e.g. https://api.deepseek.com/v1/tools. Written to both Search and Fetch; separate from the Messages endpoint.",
410
+ apiRefHint: "Credential used when Billing is API key. Written to both Search and Fetch.",
251
411
  apiShared: "Uses the DeepSeek API configuration in the search section above.",
252
412
  apiUnavailable: "The Host must serve web and web-deepseek-api to enable the new APIs (DSH 0.2.1-rc.2 or compatible).",
253
413
  searchInactive: "Another search provider is selected in the Host. Choose an engine here to use this page's configuration.",
414
+ autoUnavailable: "The Host does not compose the in-box DeepSeek provider, so neither follow mode nor DeepSeek server-side search can run. Choose an engine here so searches keep working.",
254
415
  partialFailed: "Save failed; some settings may already have been saved. Your draft is retained. Review and retry.",
255
416
  mode: "Auth mode",
256
417
  modeKeyless: "Keyless (free, rate-limited)",
@@ -292,20 +453,17 @@ window.__ModuleLoader__.load({
292
453
  proxy: "Proxy",
293
454
  proxyPlaceholder: "Leave blank to inherit the DSH proxy settings.",
294
455
  deepseekApiKeyEnv: "Credential reference",
295
- deepseekApiKeyEnvHint: "Name of the credential/env var resolved for DeepSeek search.",
296
- deepseekBaseURL: "Endpoint",
297
- deepseekBaseURLHint: "Leave blank to use the DeepSeek Anthropic-compatible API default.",
456
+ deepseekApiKeyEnvHint: "Models on the DeepSeek account route use the signed-in account; every other request uses this API key (DEEPSEEK_API_KEY), shared with the Models page by default.",
457
+ deepseekBaseURL: "Base URL",
458
+ deepseekBaseURLHint: "Include the API prefix; leave blank to use the official endpoint. The program appends /messages.",
298
459
  model: "Model",
299
460
  modelHint: "Anthropic-format model name for the search request.",
300
461
  maxTokens: "Max tokens",
301
462
  maxTokensHint: "Upper bound on generated tokens for the search request.",
302
- maxUses: "Max uses",
303
- maxUsesHint: "Maximum web_search server-tool uses per request.",
304
- expand: "Show settings",
305
- collapse: "Hide settings",
463
+ maxUses: "Max searches per request",
464
+ maxUsesHint: "Upper bound on server-side searches each Messages request may run; a positive integer, default 5.",
306
465
  getKey: "Get API key",
307
466
  ddgDisabled: "DuckDuckGo — use via SearXNG",
308
- ddgHint: "DuckDuckGo has no official search API. Pick SearXNG and point it at an instance that includes DuckDuckGo (most public ones do), or self-host one.",
309
467
  save: "Save",
310
468
  saving: "Saving…",
311
469
  discard: "Discard",
@@ -344,32 +502,47 @@ window.__ModuleLoader__.load({
344
502
  };
345
503
  /** Simplified Chinese copy. */
346
504
  const zh = {
347
- nav: "网页搜索",
348
- provider: "搜索引擎",
505
+ nav: "网页搜索与获取",
506
+ provider: "网页搜索提供方",
349
507
  providerTavily: "Tavily",
350
508
  providerBrave: "Brave Search",
351
- providerDeepseek: "DeepSeek Messages 搜索(默认)",
509
+ providerDeepseek: "DeepSeek 服务端搜索",
510
+ providerAuto: "跟随会话模型",
511
+ providerAutoHint: "DeepSeek 模型的请求使用 DeepSeek 服务端搜索(搜索不按次收费,会额外消耗模型 token);其他模型使用 DeepSeek Search API。选择上面的任一引擎会固定给所有模型使用。",
512
+ deepseekOwnedHint: "以下参数属于内置 DeepSeek 提供方:跟随会话模型时它执行 DeepSeek 模型的搜索;固定为服务端搜索时所有模型都由它执行。",
352
513
  providerApi: "DeepSeek Search API",
353
- searchHeading: "搜索引擎",
354
- fetchHeading: "网页抓取",
355
- fetchProvider: "抓取方式",
356
- fetchHttp: "本地 HTTP(默认)",
514
+ searchHeading: "网页搜索",
515
+ fetchHeading: "网页获取",
516
+ fetchProvider: "网页获取提供方",
517
+ fetchHttp: "本机直接获取",
357
518
  fetchApi: "DeepSeek Fetch API",
358
519
  fetchOther: "当前自定义提供方:",
359
- fetchHttpHint: "由当前设备直接读取网页,无 DeepSeek Fetch 接口费;返回内容仍占用主会话 token。",
360
- apiHint: "直接请求 API,不调用辅助模型。Search 与 Fetch 按成功请求计费,主模型阅读结果仍消耗 token。",
361
- messagesHint: "搜索会额外发起 Messages 模型请求;选择 Search API 可省去该辅助模型调用。",
520
+ fetchHttpHint: "免费,可访问内网和本机。不支持需要 JavaScript 或登录的页面,也不支持 PDF。返回内容仍占用主会话 token。",
521
+ apiHint: "直接请求 API,不调用辅助模型。主模型阅读结果仍消耗 token。",
522
+ providerDeepseekHint: "搜索不按次收费,每次搜索都会额外消耗模型 token。需要 DeepSeek 账号或 API Key。",
523
+ providerApiHint: "会产生费用,由「计费方式」选定的账号或 API Key 支付。",
524
+ providerFetchApiHint: "无法访问内网和本机。会产生费用,由「计费方式」选定的账号或 API Key 支付。",
525
+ providerSearxngHint: "DuckDuckGo 没有官方搜索 API。请把 SearXNG 指向一个聚合了 DuckDuckGo 的实例(多数公共实例都有),或自建一个。",
526
+ advanced: "高级设置",
362
527
  apiBase: "DeepSeek Search / Fetch API 基础地址",
363
528
  apiCount: "每次搜索结果数",
364
- apiCountHint: "每个查询返回 1–50 条,仍受工具自身结果上限约束;这不是请求次数或费用上限。",
365
- apiBilling: "API 使用与计费说明 ↗",
529
+ apiCountHint: "每次搜索返回的结果条数,1–50,默认 10。",
530
+ apiBillingMode: "计费方式",
531
+ apiBillingAuto: "自动",
532
+ apiBillingAccount: "已登录的 DeepSeek 账号",
533
+ apiBillingApiKey: "DeepSeek API Key",
534
+ apiBillingHint: "跟随当前会话的 DeepSeek 账号或 API Key;会话用其他模型时,优先用 API Key,没有则用已登录账号。",
535
+ apiBillingAccountHint: "需要先登录 DeepSeek 账号。",
536
+ apiBillingApiKeyHint: "使用「模型」页配置的 API Key,需要先配置。",
537
+ apiBilling: "网页搜索与获取指南 ↗",
366
538
  credentialConflict: "两个不同密钥使用了同一凭据引用。请使用同一密钥,或分别设置引用名。",
367
539
  invalidApiCount: "请输入 1–50 的整数;留空表示使用默认值。",
368
- apiBaseHint: "填写含 API 前缀的地址,如 https://api.deepseek.com/v1/tools。Search 与 Fetch 共用,与 Messages 地址分别保存。",
369
- apiRefHint: "DeepSeek Search API 与 Fetch API 共用的凭据;账号会话可使用经授权的账号令牌。",
370
- apiShared: "使用上方搜索引擎区域中的 DeepSeek API 配置。",
540
+ apiBaseHint: "填写含 API 前缀的地址,如 https://api.deepseek.com/v1/tools。同时写入 Search 与 Fetch,与 Messages 地址分别保存。",
541
+ apiRefHint: "「计费方式」为 API Key 时使用的凭据;同时写入 Search 与 Fetch。",
542
+ apiShared: "使用上方网页搜索区域中的 DeepSeek API 配置。",
371
543
  apiUnavailable: "新版 API 需要 Host 提供 web 与 web-deepseek-api 配置(DSH 0.2.1-rc.2 或兼容版本)。",
372
- searchInactive: "Host 当前选择了其他搜索提供方;请在此选择引擎以启用本页面的配置。",
544
+ searchInactive: "Host 当前选择了其他搜索提供方;请在此选择搜索引擎以启用本页面的配置。",
545
+ autoUnavailable: "Host 未组合内置 DeepSeek 提供方,跟随会话模型与 DeepSeek 服务端搜索都无法运行;请在此选择一个引擎,否则搜索会失败。",
373
546
  partialFailed: "保存失败,部分设置可能已保存。草稿已保留,请核对后重试。",
374
547
  mode: "认证模式",
375
548
  modeKeyless: "Keyless(免费、限流)",
@@ -411,20 +584,17 @@ window.__ModuleLoader__.load({
411
584
  proxy: "代理",
412
585
  proxyPlaceholder: "留空继承 DSH 全局代理设置",
413
586
  deepseekApiKeyEnv: "凭据引用名",
414
- deepseekApiKeyEnvHint: "DeepSeek 搜索解析的凭据/环境变量名。",
415
- deepseekBaseURL: "接口地址",
416
- deepseekBaseURLHint: "留空则使用 DeepSeek Anthropic 兼容 API 默认地址。",
587
+ deepseekApiKeyEnvHint: "账号模型发起的请求使用已登录账号;其他请求使用此 API Key(DEEPSEEK_API_KEY),默认与「模型」页共用。",
588
+ deepseekBaseURL: "Base URL",
589
+ deepseekBaseURLHint: "填写含 API 前缀的地址;留空时使用官方地址;程序追加 /messages。",
417
590
  model: "模型",
418
591
  modelHint: "搜索请求使用的 Anthropic 格式模型名。",
419
592
  maxTokens: "最大 token",
420
593
  maxTokensHint: "搜索请求生成 token 的上限。",
421
- maxUses: "最大调用次数",
422
- maxUsesHint: "每次请求 web_search 服务端工具的最大调用次数。",
423
- expand: "展开设置",
424
- collapse: "收起设置",
594
+ maxUses: "单次请求最多搜索次数",
595
+ maxUsesHint: "每次 Messages 请求允许的服务端搜索次数上限,须为正整数,默认 5。",
425
596
  getKey: "获取 API key",
426
597
  ddgDisabled: "DuckDuckGo — 请经 SearXNG 使用",
427
- ddgHint: "DuckDuckGo 没有官方搜索 API。请选择 SearXNG,并填入一个聚合了 DuckDuckGo 的实例地址(多数公共实例都有),或自建一个。",
428
598
  save: "保存",
429
599
  saving: "保存中…",
430
600
  discard: "放弃修改",
@@ -534,6 +704,8 @@ window.__ModuleLoader__.load({
534
704
  credentialField("webApiKeyEnv"),
535
705
  textField("webApiBaseURL"),
536
706
  numberField("webApiCount", { min: 1, max: 50, strict: true }),
707
+ choiceField("webApiSearchBilling"),
708
+ choiceField("webApiFetchBilling"),
537
709
  choiceField("provider"),
538
710
  choiceField("tavilyMode"),
539
711
  numberField("maxResults", { min: 1, max: MAX_RESULTS_CAP }),
@@ -609,8 +781,12 @@ window.__ModuleLoader__.load({
609
781
  failed: this.failed,
610
782
  apiAvailable: snapshot.apiAvailable,
611
783
  apiWritable: snapshot.apiWritable,
784
+ apiSplit: snapshot.apiSplit === true,
612
785
  selectionAvailable: snapshot.selectionAvailable,
613
786
  selectionWritable: snapshot.selectionWritable,
787
+ autoAvailable: snapshot.autoAvailable === true,
788
+ following: snapshot.following === true,
789
+ autoMissing: snapshot.autoMissing === true,
614
790
  searchInactive: snapshot.searchProvider && !["dsh-web-search", API_SEARCH].includes(snapshot.searchProvider),
615
791
  toastKey: this.toastKey
616
792
  };
@@ -892,6 +1068,8 @@ window.__ModuleLoader__.load({
892
1068
  webApiKeyEnv: this.form.field("webApiKeyEnv"),
893
1069
  webApiBaseURL: this.form.field("webApiBaseURL"),
894
1070
  webApiCount: this.form.field("webApiCount"),
1071
+ webApiSearchBilling: this.form.field("webApiSearchBilling"),
1072
+ webApiFetchBilling: this.form.field("webApiFetchBilling"),
895
1073
  webApiKeyConfigured: this.form.apiCredential.configured,
896
1074
  webApiKeyWritable: this.form.apiCredential.writable,
897
1075
  provider: this.form.field("provider"),
@@ -1229,24 +1407,32 @@ window.__ModuleLoader__.load({
1229
1407
  const { t, state, actions } = props;
1230
1408
  if (!state.available) return null;
1231
1409
  const disabled = !state.writable || state.saving;
1232
- const provider = state.provider.text === API_SEARCH || state.provider.text === "tavily" || state.provider.text === "brave" || state.provider.text === "deepseek-official" || builtinRest(state.provider.text) !== void 0 ? state.provider.text : "deepseek-official";
1410
+ const auto = state.provider.text === AUTO && state.autoAvailable === true;
1411
+ const provider = auto ? AUTO : state.provider.text === API_SEARCH || state.provider.text === "tavily" || state.provider.text === "brave" || state.provider.text === "deepseek-official" || builtinRest(state.provider.text) !== void 0 ? state.provider.text : "deepseek-official";
1233
1412
  const apiSearch = provider === API_SEARCH;
1234
1413
  const fetchProvider = state.fetchProvider.text || "http";
1235
1414
  const apiFetch = fetchProvider === API_FETCH;
1236
1415
  const brave = provider === "brave";
1237
- const deepseek = provider === "deepseek-official";
1416
+ const deepseek = provider === "deepseek-official" || auto;
1238
1417
  const tavily = provider === "tavily";
1239
1418
  const restMeta = builtinRest(provider);
1240
1419
  const keyed = state.tavilyMode.text === "keyed";
1420
+ /** One line under the selector describing the provider in force. */
1421
+ const providerHint = auto ? t("providerAutoHint")
1422
+ : provider === API_SEARCH ? t("providerApiHint")
1423
+ : provider === "deepseek-official" ? t("providerDeepseekHint")
1424
+ : provider === "searxng" ? t("providerSearxngHint")
1425
+ : "";
1241
1426
  const keyHint = state.apiKeyConfigured ? t("apiKeyHint") : t("apiKeyHint") + " " + t("apiKeyUnavailableHint");
1242
1427
  const toastText = toastCopy(t, state.toastKey);
1243
1428
  const toastTone = ["failed", "invalid", "credentialConflict"].includes(state.toastKey) ? "error" : state.toastKey === "nothing" ? "info" : "success";
1429
+ const isApiField = (field) => Object.hasOwn(API_FIELDS, field) || Object.hasOwn(API_FIELDS_SPLIT, field);
1244
1430
  const row = (field, label, hint, children) => fieldRow(label, hint, children, {
1245
1431
  t,
1246
1432
  overridden: state[field]?.overridden === true,
1247
1433
  invalid: state[field]?.invalid === true,
1248
1434
  errorKey: field.endsWith("ApiKeyEnv") || field === "apiKeyEnv" ? "invalidCredentialRef" : field === "webApiCount" ? "invalidApiCount" : "invalidNumber",
1249
- disabled: disabled || (API_FIELDS[field] ? !state.apiWritable : field === "fetchProvider" || field === "provider" ? !state.selectionWritable : false),
1435
+ disabled: disabled || (isApiField(field) ? !state.apiWritable : field === "fetchProvider" || field === "provider" ? !state.selectionWritable : false),
1250
1436
  onReset: () => actions.resetField(field)
1251
1437
  });
1252
1438
  const maxResultsWrite = numberField("maxResults", { min: 1, max: MAX_RESULTS_CAP }).parse(String(state.maxResults.text ?? "").trim());
@@ -1262,16 +1448,44 @@ window.__ModuleLoader__.load({
1262
1448
  return react.createElement("option", { value: n, key: n }, n);
1263
1449
  })
1264
1450
  }));
1451
+ /**
1452
+ * The `web-deepseek-api` rows the card owns. `0.2.2-rc.2` replaced
1453
+ * the literal key and shared endpoint with a per-capability split
1454
+ * plus a billing choice, so the literal-key row disappears there and
1455
+ * the credential reference takes its place.
1456
+ */
1265
1457
  const apiConfig = () => react.createElement("div", { className: "dshws_form" },
1266
- pair(
1458
+ state.apiSplit ? null : pair(
1267
1459
  fieldRow(t("apiKey"), t("apiKeyHint"), secretInput({ id: "ws-api-key", value: state.webApiKey.text, disabled: disabled || !state.apiWritable || !state.webApiKeyWritable, placeholder: state.webApiKeyConfigured ? t("apiKeySet") : t("apiKeyUnset"), onChange: e => actions.edit("webApiKey", e.target.value) })),
1268
1460
  row("webApiKeyEnv", t("apiKeyEnv"), t("apiRefHint"), textInput({ id: "ws-api-keyref", value: state.webApiKeyEnv.text, disabled: disabled || !state.apiWritable, onChange: e => actions.edit("webApiKeyEnv", e.target.value) }))
1269
1461
  ),
1462
+ state.apiSplit ? row("webApiKeyEnv", t("apiKeyEnv"), t("apiRefHint"), textInput({ id: "ws-api-keyref", value: state.webApiKeyEnv.text, disabled: disabled || !state.apiWritable, onChange: e => actions.edit("webApiKeyEnv", e.target.value) })) : null,
1270
1463
  row("webApiBaseURL", t("apiBase"), t("apiBaseHint"), textInput({ id: "ws-api-base", value: state.webApiBaseURL.text, disabled: disabled || !state.apiWritable, onChange: e => actions.edit("webApiBaseURL", e.target.value) })),
1271
1464
  keyConsoleLink(t, "deepseek-official"),
1272
1465
  react.createElement("p", { className: "dshws_field_hint" }, t("apiHint")),
1273
1466
  react.createElement("a", { href: "https://api-docs.deepseek.com/zh-cn/guides/search/", target: "_blank", rel: "noopener noreferrer", className: "dshws_field_hint", style: { padding: "6px 0 10px" } }, t("apiBilling"))
1274
1467
  );
1468
+ /**
1469
+ * One capability's billing choice. Present only where the Host
1470
+ * serves the split schema; the pre-rc.2 schema resolves credentials
1471
+ * on its own, so the row would address a field that does not exist.
1472
+ * @param field - `webApiSearchBilling` or `webApiFetchBilling`.
1473
+ */
1474
+ /** Hint under a billing select: the official page explains each choice inline. */
1475
+ const billingHint = (value) => value === "account" ? t("apiBillingAccountHint")
1476
+ : value === "api-key" ? t("apiBillingApiKeyHint")
1477
+ : t("apiBillingHint");
1478
+ const billingRow = (field) => row(field, t("apiBillingMode"), billingHint(state[field]?.text || "auto"), selectInput({
1479
+ id: "ws-" + field,
1480
+ value: state[field]?.text || "auto",
1481
+ disabled: disabled || !state.apiWritable,
1482
+ onChange: (e) => actions.edit(field, e.target.value),
1483
+ children: [
1484
+ react.createElement("option", { value: "auto", key: "auto" }, t("apiBillingAuto")),
1485
+ react.createElement("option", { value: "account", key: "account" }, t("apiBillingAccount")),
1486
+ react.createElement("option", { value: "api-key", key: "api-key" }, t("apiBillingApiKey"))
1487
+ ]
1488
+ }));
1275
1489
  return react.createElement("div", { className: "dshws_form" },
1276
1490
  react.createElement("div", { className: "dshws_card_header" },
1277
1491
  react.createElement("div", { className: "dshws_card_headText" },
@@ -1280,17 +1494,19 @@ window.__ModuleLoader__.load({
1280
1494
  !state.writable ? react.createElement("p", { className: "dshws_field_hint", style: { padding: "8px 0 0" } }, t("readOnly")) : null,
1281
1495
  react.createElement("h3", { className: "dshws_section_title" }, t("searchHeading")),
1282
1496
  state.searchInactive ? react.createElement("p", { className: "dshws_field_hint" }, t("searchInactive")) : null,
1497
+ state.autoMissing ? react.createElement("p", { className: "dshws_field_hint" }, t("autoUnavailable")) : null,
1283
1498
  !state.apiAvailable ? react.createElement("p", { className: "dshws_field_hint" }, t("apiUnavailable")) : null,
1284
1499
  pair(
1285
1500
  row("provider", t("provider"), null, selectInput({ id: "ws-provider", value: provider, disabled: disabled || !state.selectionWritable, onChange: (e) => actions.edit("provider", e.target.value), children: [
1501
+ ...(state.autoAvailable === true ? [react.createElement("option", { value: AUTO, key: AUTO }, t("providerAuto"))] : []),
1286
1502
  react.createElement("option", { value: API_SEARCH, key: API_SEARCH, disabled: !state.apiAvailable || !state.apiWritable }, t("providerApi")),
1287
- react.createElement("option", { value: "deepseek-official", key: "deepseek-official" }, t("providerDeepseek")),
1503
+ react.createElement("option", { value: "deepseek-official", key: "deepseek-official", disabled: state.autoAvailable !== true }, t("providerDeepseek")),
1288
1504
  react.createElement("option", { value: "tavily", key: "tavily" }, t("providerTavily")),
1289
1505
  react.createElement("option", { value: "brave", key: "brave" }, t("providerBrave")),
1290
1506
  ...BUILTIN_REST_PROVIDERS.map((entry) => react.createElement("option", { value: entry.id, key: entry.id }, entry.name)),
1291
1507
  react.createElement("option", { value: "__ddg__", key: "ddg", disabled: true }, t("ddgDisabled"))
1292
1508
  ] }),
1293
- react.createElement("p", { className: "dshws_field_hint", style: { padding: "4px 0 0" } }, t("ddgHint"))),
1509
+ providerHint === "" ? null : react.createElement("p", { className: "dshws_field_hint", style: { padding: "4px 0 0" } }, providerHint)),
1294
1510
  tavily ? row("tavilyMode", t("mode"), null, selectInput({ id: "ws-mode", value: state.tavilyMode.text, disabled, onChange: (e) => actions.edit("tavilyMode", e.target.value), children: [
1295
1511
  react.createElement("option", { value: "keyless", key: "keyless" }, t("modeKeyless")),
1296
1512
  react.createElement("option", { value: "keyed", key: "keyed" }, t("modeKeyed"))
@@ -1298,9 +1514,10 @@ window.__ModuleLoader__.load({
1298
1514
  ),
1299
1515
  apiSearch ? apiConfig() : null,
1300
1516
  apiSearch ? row("webApiCount", t("apiCount"), t("apiCountHint"), numberInput({ id: "ws-api-count", value: state.webApiCount.text, min: 1, max: 50, disabled: disabled || !state.apiWritable, onChange: e => actions.edit("webApiCount", e.target.value) })) : null,
1301
- deepseek ? react.createElement("p", { className: "dshws_field_hint" }, t("messagesHint")) : null,
1517
+ apiSearch && state.apiSplit ? billingRow("webApiSearchBilling") : null,
1302
1518
  react.createElement(QuotaCard, { t, provider, keyed }),
1303
1519
  keyConsoleLink(t, provider, restMeta, keyed),
1520
+ deepseek ? react.createElement("p", { className: "dshws_field_hint" }, t("deepseekOwnedHint")) : null,
1304
1521
  deepseek ? pair(
1305
1522
  fieldRow(t("apiKey"), keyHint, secretInput({ id: "ws-deepseek-key", value: state.deepseekApiKey.text, disabled: disabled || !state.apiKeyWritable, placeholder: state.apiKeyConfigured ? t("apiKeySet") : t("apiKeyUnset"), onChange: (e) => actions.edit(DEEPSEEK_API_KEY_FIELD, e.target.value) })),
1306
1523
  row("deepseekApiKeyEnv", t("deepseekApiKeyEnv"), t("deepseekApiKeyEnvHint"), textInput({ id: "ws-deepseek-keyref", value: state.deepseekApiKeyEnv.text, disabled, onChange: (e) => actions.edit("deepseekApiKeyEnv", e.target.value) }))
@@ -1316,10 +1533,11 @@ window.__ModuleLoader__.load({
1316
1533
  deepseek ? row("deepseekBaseURL", t("deepseekBaseURL"), t("deepseekBaseURLHint"), textInput({ id: "ws-deepseek-base", value: state.deepseekBaseURL.text, disabled, onChange: (e) => actions.edit("deepseekBaseURL", e.target.value) })) : null,
1317
1534
  brave ? row("braveBaseURL", t("braveBaseURL"), t("braveBaseURLHint"), textInput({ id: "ws-brave-base", value: state.braveBaseURL.text, disabled, onChange: (e) => actions.edit("braveBaseURL", e.target.value) })) : null,
1318
1535
  tavily ? row("tavilyBaseURL", t("baseURL"), t("baseURLHint"), textInput({ id: "ws-tavily-base", value: state.tavilyBaseURL.text, disabled, onChange: (e) => actions.edit("tavilyBaseURL", e.target.value) })) : null,
1319
- deepseek ? row("deepseekModel", t("model"), t("modelHint"), textInput({ id: "ws-model", value: state.deepseekModel.text, disabled, onChange: (e) => actions.edit("deepseekModel", e.target.value) })) : null,
1320
- deepseek ? pair(
1321
- row("deepseekMaxTokens", t("maxTokens"), t("maxTokensHint"), numberInput({ id: "ws-maxtokens", value: state.deepseekMaxTokens.text, disabled, onChange: (e) => actions.edit("deepseekMaxTokens", e.target.value), className: state.deepseekMaxTokens.invalid ? "dshws_input_invalid" : void 0 })),
1322
- row("deepseekMaxUses", t("maxUses"), t("maxUsesHint"), numberInput({ id: "ws-maxuses", value: state.deepseekMaxUses.text, disabled, onChange: (e) => actions.edit("deepseekMaxUses", e.target.value), className: state.deepseekMaxUses.invalid ? "dshws_input_invalid" : void 0 }))
1536
+ deepseek ? row("deepseekMaxUses", t("maxUses"), t("maxUsesHint"), numberInput({ id: "ws-maxuses", value: state.deepseekMaxUses.text, disabled, onChange: (e) => actions.edit("deepseekMaxUses", e.target.value), className: state.deepseekMaxUses.invalid ? "dshws_input_invalid" : void 0 })) : null,
1537
+ deepseek ? react.createElement("details", { className: "dshws_form" },
1538
+ react.createElement("summary", { className: "dshws_field_hint", style: { cursor: "pointer", padding: "8px 0" } }, t("advanced")),
1539
+ row("deepseekModel", t("model"), t("modelHint"), textInput({ id: "ws-model", value: state.deepseekModel.text, disabled, onChange: (e) => actions.edit("deepseekModel", e.target.value) })),
1540
+ row("deepseekMaxTokens", t("maxTokens"), t("maxTokensHint"), numberInput({ id: "ws-maxtokens", value: state.deepseekMaxTokens.text, disabled, onChange: (e) => actions.edit("deepseekMaxTokens", e.target.value), className: state.deepseekMaxTokens.invalid ? "dshws_input_invalid" : void 0 }))
1323
1541
  ) : null,
1324
1542
  tavily ? pair(
1325
1543
  row("tavilySearchDepth", t("searchDepth"), null, selectInput({ id: "ws-depth", value: state.tavilySearchDepth.text, disabled, onChange: (e) => actions.edit("tavilySearchDepth", e.target.value), children: [
@@ -1370,7 +1588,9 @@ window.__ModuleLoader__.load({
1370
1588
  !["http", API_FETCH].includes(fetchProvider) ? react.createElement("option", { value: fetchProvider, key: fetchProvider }, t("fetchOther") + fetchProvider) : null
1371
1589
  ] })),
1372
1590
  fetchProvider === "http" ? react.createElement("p", { className: "dshws_field_hint" }, t("fetchHttpHint")) : null,
1591
+ apiFetch ? react.createElement("p", { className: "dshws_field_hint" }, t("providerFetchApiHint")) : null,
1373
1592
  apiFetch ? (apiSearch ? react.createElement("p", { className: "dshws_field_hint" }, t("apiShared")) : apiConfig()) : null,
1593
+ apiFetch && state.apiSplit ? billingRow("webApiFetchBilling") : null,
1374
1594
  react.createElement("div", { style: { borderTop: "1px solid var(--dsw-alias-border-l2)", justifyContent: "flex-end", alignItems: "center", gap: "8px", padding: "12px 0 4px", display: "flex" } },
1375
1595
  react.createElement("button", {
1376
1596
  type: "button",