dsh-web-search-plugin 0.5.1 → 0.6.1

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
@@ -29,6 +29,71 @@ window.__ModuleLoader__.load({
29
29
 
30
30
  /** Settings namespace of this plugin. */
31
31
  const NS = "dsh-web-search-plugin";
32
+ const API_NS = "web-deepseek-api";
33
+ const API_SEARCH = "deepseek-search-api";
34
+ const API_FETCH = "deepseek-fetch-api";
35
+ const API_FIELDS = { webApiKey: "apiKey", webApiKeyEnv: "apiKeyEnv", webApiBaseURL: "baseURL", webApiCount: "count" };
36
+ /** Combine public ConfigForms; save parameters before switching providers.
37
+ * Each namespace has its own revision. Refusal retains the page's draft;
38
+ * previously accepted namespaces are not rolled back over concurrent edits.
39
+ */
40
+ function combinedScope(forms) {
41
+ const plugin = forms.get(NS), web = forms.get("web"), api = forms.get(API_NS);
42
+ const merge = (p, w, a) => {
43
+ 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];
46
+ return value;
47
+ };
48
+ return {
49
+ getSnapshot() {
50
+ 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 },
54
+ apiAvailable: a.status === "ready" && w.status === "ready",
55
+ apiWritable: a.writable && w.writable,
56
+ selectionAvailable: w.status === "ready", selectionWritable: w.writable,
57
+ searchProvider: w.value?.searchProvider };
58
+ },
59
+ subscribe(listener) {
60
+ const stops = [plugin, web, api].map(scope => scope.subscribe(listener));
61
+ return () => stops.forEach(stop => stop());
62
+ },
63
+ async mutate(ops, revisions) {
64
+ const groups = { plugin: [], api: [], web: [] };
65
+ for (const op of ops) {
66
+ 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);
69
+ else if (field === "provider") {
70
+ if (op.op === "set" && op.value === API_SEARCH) groups.web.push({ op: "set", path: ["searchProvider"], value: API_SEARCH });
71
+ else {
72
+ groups.plugin.push(op);
73
+ groups.web.push({ op: "set", path: ["searchProvider"], value: "dsh-web-search" });
74
+ }
75
+ } else groups.plugin.push(op);
76
+ }
77
+ 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]]) {
79
+ if (groups[name].length && (scope.getSnapshot().status !== "ready" || !scope.getSnapshot().writable)) return false;
80
+ }
81
+ for (const [name, scope] of [["plugin", plugin], ["api", api], ["web", web]]) {
82
+ if (groups[name].length && await scope.mutate(groups[name], revisions[name]) !== true) return false;
83
+ }
84
+ return true;
85
+ },
86
+ canWrite(plan) {
87
+ return plan.every(item => {
88
+ 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
92
+ && (field !== "provider" || (web.getSnapshot().status === "ready" && web.getSnapshot().writable));
93
+ });
94
+ }
95
+ };
96
+ }
32
97
  // Mirrors lib/config.js; this client bundle has no host-module imports.
33
98
  const SUPPLIER_CONFIG_ALIASES = {
34
99
  tavilyApiKey: "apiKey",
@@ -50,6 +115,7 @@ window.__ModuleLoader__.load({
50
115
  scavioSearchLang: "searchLang"
51
116
  };
52
117
  const SUPPLIER_DEFAULTS = {
118
+ webApiKeyEnv: "DEEPSEEK_API_KEY", webApiBaseURL: "https://api.deepseek.com/v1/tools", webApiCount: 10, fetchProvider: "http",
53
119
  deepseekModel: "deepseek-flash", deepseekApiVersion: "2023-06-01", deepseekMaxTokens: 4096, deepseekMaxUses: 5,
54
120
  tavilyMode: "keyless", tavilyApiKey: "", tavilyApiKeyEnv: "TAVILY_API_KEY", tavilyBaseURL: "",
55
121
  tavilySearchDepth: "basic", tavilyIncludeAnswer: true, tavilyTopic: "general",
@@ -126,7 +192,7 @@ window.__ModuleLoader__.load({
126
192
  const DEEPSEEK_API_KEY_FIELD = "deepseekApiKey";
127
193
  /** Form fields carrying literal API keys (write-only, staged under the credentials domain). */
128
194
  const REST_KEY_FIELDS = BUILTIN_REST_PROVIDERS.map((entry) => entry.keyField).filter((field) => field !== "");
129
- const SECRET_FIELDS = new Set([TAVILY_API_KEY_FIELD, BRAVE_API_KEY_FIELD, DEEPSEEK_API_KEY_FIELD, ...REST_KEY_FIELDS]);
195
+ const SECRET_FIELDS = new Set([TAVILY_API_KEY_FIELD, BRAVE_API_KEY_FIELD, DEEPSEEK_API_KEY_FIELD, "webApiKey", ...REST_KEY_FIELDS]);
130
196
  const DRAFT_KEY = "dsh-web-search-plugin:settings-draft";
131
197
 
132
198
  function readDraft() {
@@ -163,7 +229,29 @@ window.__ModuleLoader__.load({
163
229
  provider: "Search engine",
164
230
  providerTavily: "Tavily",
165
231
  providerBrave: "Brave Search",
166
- providerDeepseek: "DeepSeek (official)",
232
+ providerDeepseek: "DeepSeek Messages search (default)",
233
+ providerApi: "DeepSeek Search API",
234
+ searchHeading: "Search engines",
235
+ fetchHeading: "Web retrieval",
236
+ fetchProvider: "Retrieval method",
237
+ fetchHttp: "Local HTTP (default)",
238
+ fetchApi: "DeepSeek Fetch API",
239
+ 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.",
243
+ apiBase: "DeepSeek Search / Fetch API base URL",
244
+ 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 ↗",
247
+ credentialConflict: "Two different keys target the same credential reference. Use one key or separate references.",
248
+ 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.",
251
+ apiShared: "Uses the DeepSeek API configuration in the search section above.",
252
+ apiUnavailable: "The Host must serve web and web-deepseek-api to enable the new APIs (DSH 0.2.1-rc.2 or compatible).",
253
+ searchInactive: "Another search provider is selected in the Host. Choose an engine here to use this page's configuration.",
254
+ partialFailed: "Save failed; some settings may already have been saved. Your draft is retained. Review and retry.",
167
255
  mode: "Auth mode",
168
256
  modeKeyless: "Keyless (free, rate-limited)",
169
257
  modeKeyed: "API key",
@@ -260,7 +348,29 @@ window.__ModuleLoader__.load({
260
348
  provider: "搜索引擎",
261
349
  providerTavily: "Tavily",
262
350
  providerBrave: "Brave Search",
263
- providerDeepseek: "DeepSeek(官方)",
351
+ providerDeepseek: "DeepSeek Messages 搜索(默认)",
352
+ providerApi: "DeepSeek Search API",
353
+ searchHeading: "搜索引擎",
354
+ fetchHeading: "网页抓取",
355
+ fetchProvider: "抓取方式",
356
+ fetchHttp: "本地 HTTP(默认)",
357
+ fetchApi: "DeepSeek Fetch API",
358
+ fetchOther: "当前自定义提供方:",
359
+ fetchHttpHint: "由当前设备直接读取网页,无 DeepSeek Fetch 接口费;返回内容仍占用主会话 token。",
360
+ apiHint: "直接请求 API,不调用辅助模型。Search 与 Fetch 按成功请求计费,主模型阅读结果仍消耗 token。",
361
+ messagesHint: "搜索会额外发起 Messages 模型请求;选择 Search API 可省去该辅助模型调用。",
362
+ apiBase: "DeepSeek Search / Fetch API 基础地址",
363
+ apiCount: "每次搜索结果数",
364
+ apiCountHint: "每个查询返回 1–50 条,仍受工具自身结果上限约束;这不是请求次数或费用上限。",
365
+ apiBilling: "API 使用与计费说明 ↗",
366
+ credentialConflict: "两个不同密钥使用了同一凭据引用。请使用同一密钥,或分别设置引用名。",
367
+ 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 配置。",
371
+ apiUnavailable: "新版 API 需要 Host 提供 web 与 web-deepseek-api 配置(DSH 0.2.1-rc.2 或兼容版本)。",
372
+ searchInactive: "Host 当前选择了其他搜索提供方;请在此选择引擎以启用本页面的配置。",
373
+ partialFailed: "保存失败,部分设置可能已保存。草稿已保留,请核对后重试。",
264
374
  mode: "认证模式",
265
375
  modeKeyless: "Keyless(免费、限流)",
266
376
  modeKeyed: "API key",
@@ -364,6 +474,7 @@ window.__ModuleLoader__.load({
364
474
  if (!/^[0-9]+$/u.test(trimmed)) return void 0;
365
475
  let parsed = Number(trimmed);
366
476
  if (!Number.isInteger(parsed) || parsed < 1) return void 0;
477
+ if (bounds?.strict && ((bounds.min != null && parsed < bounds.min) || (bounds.max != null && parsed > bounds.max))) return void 0;
367
478
  if (bounds?.min != null && parsed < bounds.min) parsed = bounds.min;
368
479
  if (bounds?.max != null && parsed > bounds.max) parsed = bounds.max;
369
480
  return { kind: "set", value: parsed };
@@ -419,6 +530,10 @@ window.__ModuleLoader__.load({
419
530
  this.scope = scope;
420
531
  this.remote = remote;
421
532
  this.specs = new Map([
533
+ choiceField("fetchProvider"),
534
+ credentialField("webApiKeyEnv"),
535
+ textField("webApiBaseURL"),
536
+ numberField("webApiCount", { min: 1, max: 50, strict: true }),
422
537
  choiceField("provider"),
423
538
  choiceField("tavilyMode"),
424
539
  numberField("maxResults", { min: 1, max: MAX_RESULTS_CAP }),
@@ -456,6 +571,7 @@ window.__ModuleLoader__.load({
456
571
  this.saving = false;
457
572
  this.failed = false;
458
573
  this.credential = { ref: "", configured: false, writable: true };
574
+ this.apiCredential = { ref: "", configured: false, writable: true };
459
575
  this.toastKey = null;
460
576
  this.toastTimer = 0;
461
577
  this.listeners = new Set();
@@ -469,7 +585,7 @@ window.__ModuleLoader__.load({
469
585
  }
470
586
  if (draft.failed === true) this.failed = true;
471
587
  }
472
- scope.subscribe(() => {
588
+ this.unsubscribe = scope.subscribe(() => {
473
589
  this.publish();
474
590
  });
475
591
  this.readCredential();
@@ -491,6 +607,11 @@ window.__ModuleLoader__.load({
491
607
  invalid: plan.some((item) => item.invalid === true),
492
608
  saving: this.saving,
493
609
  failed: this.failed,
610
+ apiAvailable: snapshot.apiAvailable,
611
+ apiWritable: snapshot.apiWritable,
612
+ selectionAvailable: snapshot.selectionAvailable,
613
+ selectionWritable: snapshot.selectionWritable,
614
+ searchInactive: snapshot.searchProvider && !["dsh-web-search", API_SEARCH].includes(snapshot.searchProvider),
494
615
  toastKey: this.toastKey
495
616
  };
496
617
  }
@@ -527,7 +648,7 @@ window.__ModuleLoader__.load({
527
648
  if (this.stored(field)) plan.push({ field, op: { op: "unset", path: [field] } });
528
649
  continue;
529
650
  }
530
- if (staged.text === spec.format(this.sectionValue(field))) continue;
651
+ if (staged.text === spec.format(this.sectionValue(field)) && !(field === "provider" && this.snapshotOf().searchProvider && this.snapshotOf().searchProvider !== (staged.text === API_SEARCH ? API_SEARCH : "dsh-web-search"))) continue;
531
652
  const write = spec.parse(staged.text);
532
653
  if (write === void 0) plan.push({ field, invalid: true });
533
654
  else if (write.kind === "clear") plan.push({ field, op: { op: "unset", path: [field] } });
@@ -556,8 +677,22 @@ window.__ModuleLoader__.load({
556
677
  this.showToast("invalid");
557
678
  return;
558
679
  }
680
+ if (this.scope.canWrite && !this.scope.canWrite(plan)) {
681
+ this.failed = true;
682
+ this.showToast("failed");
683
+ return;
684
+ }
559
685
  const revision = this.snapshotOf().revision;
560
686
  const credentials = plan.filter((item) => item.credential !== void 0);
687
+ const keysByRef = new Map();
688
+ for (const item of credentials) {
689
+ const ref = this.keyRef(item.field), value = this.staged.get(item.field).text.trim();
690
+ if (keysByRef.has(ref) && keysByRef.get(ref) !== value) {
691
+ this.showToast("credentialConflict");
692
+ return;
693
+ }
694
+ keysByRef.set(ref, value);
695
+ }
561
696
  const ops = plan.flatMap((item) => item.op === void 0 ? [] : [item.op]);
562
697
  for (const item of plan) {
563
698
  const legacy = SUPPLIER_CONFIG_ALIASES[item.field];
@@ -616,7 +751,7 @@ window.__ModuleLoader__.load({
616
751
  this.staged.set(field, edit);
617
752
  this.failed = false;
618
753
  this.publish();
619
- if (field === "provider" || field === "tavilyApiKeyEnv" || field === "braveApiKeyEnv" || field === "deepseekApiKeyEnv" || BUILTIN_REST_PROVIDERS.some((entry) => entry.keyEnvField === field)) this.readCredential();
754
+ if (field === "provider" || field === "fetchProvider" || field === "webApiKeyEnv" || field === "tavilyApiKeyEnv" || field === "braveApiKeyEnv" || field === "deepseekApiKeyEnv" || BUILTIN_REST_PROVIDERS.some((entry) => entry.keyEnvField === field)) this.readCredential();
620
755
  }
621
756
  snapshotOf() {
622
757
  return this.scope.getSnapshot();
@@ -635,15 +770,14 @@ window.__ModuleLoader__.load({
635
770
  return user !== void 0 && (Object.hasOwn(user, field) || Object.hasOwn(user, SUPPLIER_CONFIG_ALIASES[field]));
636
771
  }
637
772
  publish() {
773
+ if (this.disposed) return;
638
774
  writeDraft(this);
639
775
  for (const listener of this.listeners) listener();
640
776
  }
641
777
  /** Draft-aware engine: staged `provider` wins over the saved section. */
642
778
  providerOf() {
643
- const staged = this.staged.get("provider");
644
- if (staged !== void 0 && !staged.clear && staged.text.trim() !== "") return staged.text.trim();
645
- const declared = this.sectionValue("provider");
646
- if (declared === "tavily" || declared === "brave" || declared === "deepseek-official" || builtinRest(declared) !== void 0) return declared;
779
+ const declared = this.field("provider").text;
780
+ if (declared === API_SEARCH || declared === "tavily" || declared === "brave" || declared === "deepseek-official" || builtinRest(declared) !== void 0) return declared;
647
781
  return "deepseek-official";
648
782
  }
649
783
  credentialRef(field, fallback) {
@@ -665,6 +799,7 @@ window.__ModuleLoader__.load({
665
799
  /** The credential reference the currently visible engine uses. */
666
800
  refOf() {
667
801
  const provider = this.providerOf();
802
+ if (provider === API_SEARCH) return this.credentialRef("webApiKeyEnv", DEFAULT_DEEPSEEK_KEY_REF);
668
803
  if (provider === "brave") return this.braveRef();
669
804
  if (provider === "deepseek-official") return this.deepseekRef();
670
805
  const rest = builtinRest(provider);
@@ -678,39 +813,49 @@ window.__ModuleLoader__.load({
678
813
  }
679
814
  async readCredential() {
680
815
  const ref = this.refOf();
816
+ const apiRef = this.credentialRef("webApiKeyEnv", DEFAULT_DEEPSEEK_KEY_REF);
817
+ if (this.apiCredential.ref !== apiRef) this.apiCredential = { ref: apiRef, configured: false, writable: true };
681
818
  if (ref !== this.credential.ref) {
682
819
  this.credential = { ref, configured: false, writable: true };
683
820
  this.publish();
684
821
  }
685
822
  let response;
686
823
  try {
687
- response = await this.remote.credentials.describe([ref]);
824
+ response = await this.remote.credentials.describe([...new Set([ref, apiRef])]);
688
825
  } catch (_credentialReadFailure) {
689
826
  return;
690
827
  }
691
828
  if (!response.ok || ref !== this.refOf()) return;
829
+ if (apiRef === this.credentialRef("webApiKeyEnv", DEFAULT_DEEPSEEK_KEY_REF)) {
830
+ const apiView = response.value[apiRef];
831
+ this.apiCredential = { ref: apiRef, configured: apiView?.configured ?? false, writable: apiView?.writable ?? true };
832
+ }
692
833
  const view = response.value[ref];
693
834
  const next = {
694
835
  ref,
695
836
  configured: view?.configured ?? false,
696
837
  writable: view?.writable ?? true
697
838
  };
698
- if (next.configured === this.credential.configured && next.writable === this.credential.writable) return;
699
839
  this.credential = next;
700
840
  this.publish();
701
841
  }
702
842
  refreshCredential(ref) {
703
- if (ref !== this.credential.ref) return;
843
+ if (ref !== this.credential.ref && ref !== this.apiCredential.ref) return;
704
844
  this.readCredential();
705
845
  }
706
- async writeKey(field, value) {
846
+ keyRef(field) {
707
847
  let ref;
708
848
  if (field === BRAVE_API_KEY_FIELD) ref = this.braveRef();
849
+ else if (field === "webApiKey") ref = this.credentialRef("webApiKeyEnv", DEFAULT_DEEPSEEK_KEY_REF);
709
850
  else if (field === DEEPSEEK_API_KEY_FIELD) ref = this.deepseekRef();
710
851
  else {
711
852
  const rest = builtinRestByKeyField(field);
712
853
  ref = rest !== void 0 ? this.restKeyRef(rest) : this.tavilyRef();
713
854
  }
855
+ return ref;
856
+ }
857
+ async writeKey(field, value) {
858
+ const ref = this.keyRef(field);
714
859
  try {
715
860
  const response = await this.remote.credentials.set(ref, value);
716
861
  if (!response.ok) return false;
@@ -720,6 +865,12 @@ window.__ModuleLoader__.load({
720
865
  await this.readCredential();
721
866
  return true;
722
867
  }
868
+ dispose() {
869
+ this.disposed = true;
870
+ this.unsubscribe();
871
+ this.listeners.clear();
872
+ if (this.toastTimer) clearTimeout(this.toastTimer);
873
+ }
723
874
  };
724
875
 
725
876
  /** Bridges the plugin scope and the credentials domain onto the card. */
@@ -729,13 +880,20 @@ window.__ModuleLoader__.load({
729
880
  this.remote = remote;
730
881
  this.form = new SearchCardForm(scope, remote);
731
882
  this.store = this.form.bind(() => this.projection());
732
- scope.subscribe(() => {
883
+ this.unsubscribe = scope.subscribe(() => {
733
884
  this.form.readCredential();
734
885
  });
735
886
  }
736
887
  projection() {
737
888
  return {
738
889
  ...this.form.shell(),
890
+ fetchProvider: this.form.field("fetchProvider"),
891
+ webApiKey: this.form.field("webApiKey"),
892
+ webApiKeyEnv: this.form.field("webApiKeyEnv"),
893
+ webApiBaseURL: this.form.field("webApiBaseURL"),
894
+ webApiCount: this.form.field("webApiCount"),
895
+ webApiKeyConfigured: this.form.apiCredential.configured,
896
+ webApiKeyWritable: this.form.apiCredential.writable,
739
897
  provider: this.form.field("provider"),
740
898
  tavilyMode: this.form.field("tavilyMode"),
741
899
  tavilyApiKey: this.form.field(TAVILY_API_KEY_FIELD),
@@ -792,7 +950,7 @@ window.__ModuleLoader__.load({
792
950
  /** Row style: one labelled field with optional override badge and restore-default. */
793
951
  const fieldRow = (label, hint, children, meta) => react.createElement("div", { className: "dshws_field" },
794
952
  react.createElement("div", { className: "dshws_field_head" },
795
- react.createElement("label", { className: "dshws_field_label" }, label),
953
+ react.createElement("label", { className: "dshws_field_label", htmlFor: children?.props?.id }, label),
796
954
  meta?.overridden ? react.createElement("span", { className: "dshws_field_badges" },
797
955
  react.createElement("span", { className: "dshws_badge" }, meta.t("overridden")),
798
956
  react.createElement("button", { type: "button", className: "dshws_reset", disabled: meta.disabled === true, onClick: meta.onReset }, meta.t("reset"))) : null),
@@ -861,6 +1019,7 @@ window.__ModuleLoader__.load({
861
1019
  ".dshws_card_desc{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5}",
862
1020
  ".dshws_pending{white-space:nowrap;background:var(--dsw-alias-bg-module-platform,rgba(128,128,128,0.12));color:var(--dsw-alias-label-secondary);border-radius:999px;flex:none;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}",
863
1021
  ".dshws_form{display:flex;flex-direction:column;gap:0}",
1022
+ ".dshws_section_title{font-size:15px;font-weight:600;line-height:1.5;margin:20px 0 10px;color:var(--dsw-alias-label-primary)}",
864
1023
  ".dshws_field{display:flex;flex-direction:column;gap:4px;padding:10px 0;border-top:1px solid var(--dsw-alias-border-l2);min-width:0}",
865
1024
  ".dshws_field_head{display:flex;align-items:center;gap:8px}",
866
1025
  ".dshws_field_label{min-width:0;flex:1;color:var(--dsw-alias-label-primary);font-size:13px;font-weight:500;line-height:1.5}",
@@ -869,6 +1028,7 @@ window.__ModuleLoader__.load({
869
1028
  ".dshws_field_error{color:var(--dsw-alias-state-error-primary,#ef4444)!important;margin:0;font-size:12px;line-height:1.45;font-weight:500}",
870
1029
  ".dshws_pair{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);column-gap:12px;border-top:1px solid var(--dsw-alias-border-l2)}",
871
1030
  ".dshws_pair>.dshws_field{border-top:none;padding:10px 0}",
1031
+ "@media(max-width:600px){.dshws_pair{grid-template-columns:minmax(0,1fr)}.dshws_pair>.dshws_field+.dshws_field{border-top:1px solid var(--dsw-alias-border-l2)}.dshws_field_hint{overflow-wrap:anywhere}}",
872
1032
  ".dshws_badge{white-space:nowrap;background:var(--dsw-alias-bg-module-platform,rgba(128,128,128,0.12));color:var(--dsw-alias-label-secondary);border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}",
873
1033
  ".dshws_reset{appearance:none;font:inherit;color:var(--dsw-alias-label-secondary);cursor:pointer;background:transparent;border:none;padding:0;font-size:12px;line-height:1.5}",
874
1034
  ".dshws_reset:hover:not(:disabled){color:var(--dsw-alias-label-primary)}",
@@ -1059,7 +1219,8 @@ window.__ModuleLoader__.load({
1059
1219
  if (key === "saved") return t("savedToast");
1060
1220
  if (key === "nothing") return t("nothingToSave");
1061
1221
  if (key === "invalid") return t("invalidToast");
1062
- if (key === "failed") return t("saveFailed");
1222
+ if (key === "failed") return t("partialFailed");
1223
+ if (key === "credentialConflict") return t("credentialConflict");
1063
1224
  return "";
1064
1225
  }
1065
1226
 
@@ -1068,7 +1229,10 @@ window.__ModuleLoader__.load({
1068
1229
  const { t, state, actions } = props;
1069
1230
  if (!state.available) return null;
1070
1231
  const disabled = !state.writable || state.saving;
1071
- const provider = state.provider.text === "tavily" || state.provider.text === "brave" || state.provider.text === "deepseek-official" || builtinRest(state.provider.text) !== void 0 ? state.provider.text : "deepseek-official";
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";
1233
+ const apiSearch = provider === API_SEARCH;
1234
+ const fetchProvider = state.fetchProvider.text || "http";
1235
+ const apiFetch = fetchProvider === API_FETCH;
1072
1236
  const brave = provider === "brave";
1073
1237
  const deepseek = provider === "deepseek-official";
1074
1238
  const tavily = provider === "tavily";
@@ -1076,13 +1240,13 @@ window.__ModuleLoader__.load({
1076
1240
  const keyed = state.tavilyMode.text === "keyed";
1077
1241
  const keyHint = state.apiKeyConfigured ? t("apiKeyHint") : t("apiKeyHint") + " " + t("apiKeyUnavailableHint");
1078
1242
  const toastText = toastCopy(t, state.toastKey);
1079
- const toastTone = state.toastKey === "failed" || state.toastKey === "invalid" ? "error" : state.toastKey === "nothing" ? "info" : "success";
1243
+ const toastTone = ["failed", "invalid", "credentialConflict"].includes(state.toastKey) ? "error" : state.toastKey === "nothing" ? "info" : "success";
1080
1244
  const row = (field, label, hint, children) => fieldRow(label, hint, children, {
1081
1245
  t,
1082
1246
  overridden: state[field]?.overridden === true,
1083
1247
  invalid: state[field]?.invalid === true,
1084
- errorKey: field.endsWith("ApiKeyEnv") || field === "apiKeyEnv" ? "invalidCredentialRef" : "invalidNumber",
1085
- disabled,
1248
+ 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),
1086
1250
  onReset: () => actions.resetField(field)
1087
1251
  });
1088
1252
  const maxResultsWrite = numberField("maxResults", { min: 1, max: MAX_RESULTS_CAP }).parse(String(state.maxResults.text ?? "").trim());
@@ -1098,14 +1262,28 @@ window.__ModuleLoader__.load({
1098
1262
  return react.createElement("option", { value: n, key: n }, n);
1099
1263
  })
1100
1264
  }));
1265
+ const apiConfig = () => react.createElement("div", { className: "dshws_form" },
1266
+ pair(
1267
+ 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
+ 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
+ ),
1270
+ 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
+ keyConsoleLink(t, "deepseek-official"),
1272
+ react.createElement("p", { className: "dshws_field_hint" }, t("apiHint")),
1273
+ 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
+ );
1101
1275
  return react.createElement("div", { className: "dshws_form" },
1102
1276
  react.createElement("div", { className: "dshws_card_header" },
1103
1277
  react.createElement("div", { className: "dshws_card_headText" },
1104
1278
  react.createElement("span", { className: "dshws_card_name" }, t("nav"))),
1105
1279
  state.dirty || state.failed ? react.createElement("span", { className: "dshws_pending" }, t("unsaved")) : null),
1106
1280
  !state.writable ? react.createElement("p", { className: "dshws_field_hint", style: { padding: "8px 0 0" } }, t("readOnly")) : null,
1281
+ react.createElement("h3", { className: "dshws_section_title" }, t("searchHeading")),
1282
+ state.searchInactive ? react.createElement("p", { className: "dshws_field_hint" }, t("searchInactive")) : null,
1283
+ !state.apiAvailable ? react.createElement("p", { className: "dshws_field_hint" }, t("apiUnavailable")) : null,
1107
1284
  pair(
1108
- row("provider", t("provider"), null, selectInput({ id: "ws-provider", value: provider, disabled, onChange: (e) => actions.edit("provider", e.target.value), children: [
1285
+ row("provider", t("provider"), null, selectInput({ id: "ws-provider", value: provider, disabled: disabled || !state.selectionWritable, onChange: (e) => actions.edit("provider", e.target.value), children: [
1286
+ react.createElement("option", { value: API_SEARCH, key: API_SEARCH, disabled: !state.apiAvailable || !state.apiWritable }, t("providerApi")),
1109
1287
  react.createElement("option", { value: "deepseek-official", key: "deepseek-official" }, t("providerDeepseek")),
1110
1288
  react.createElement("option", { value: "tavily", key: "tavily" }, t("providerTavily")),
1111
1289
  react.createElement("option", { value: "brave", key: "brave" }, t("providerBrave")),
@@ -1118,6 +1296,9 @@ window.__ModuleLoader__.load({
1118
1296
  react.createElement("option", { value: "keyed", key: "keyed" }, t("modeKeyed"))
1119
1297
  ] })) : null
1120
1298
  ),
1299
+ apiSearch ? apiConfig() : null,
1300
+ 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,
1121
1302
  react.createElement(QuotaCard, { t, provider, keyed }),
1122
1303
  keyConsoleLink(t, provider, restMeta, keyed),
1123
1304
  deepseek ? pair(
@@ -1182,6 +1363,14 @@ window.__ModuleLoader__.load({
1182
1363
  row(restMeta.baseURLField, t("baseURL"), t("baseURLHint"), textInput({ id: "ws-" + restMeta.id + "-base", value: state[restMeta.baseURLField]?.text || restMeta.defaultBaseURL || "", disabled, onChange: (e) => actions.edit(restMeta.baseURLField, e.target.value) })),
1183
1364
  maxResultsRow
1184
1365
  ) : null,
1366
+ react.createElement("h3", { className: "dshws_section_title", style: { borderTop: "1px solid var(--dsw-alias-border-l2)", paddingTop: "20px", marginTop: "20px" } }, t("fetchHeading")),
1367
+ row("fetchProvider", t("fetchProvider"), null, selectInput({ id: "ws-fetch-provider", value: fetchProvider, disabled: disabled || !state.selectionAvailable || !state.selectionWritable, onChange: e => actions.edit("fetchProvider", e.target.value), children: [
1368
+ react.createElement("option", { value: "http", key: "http" }, t("fetchHttp")),
1369
+ react.createElement("option", { value: API_FETCH, key: API_FETCH, disabled: !state.apiAvailable || !state.apiWritable }, t("fetchApi")),
1370
+ !["http", API_FETCH].includes(fetchProvider) ? react.createElement("option", { value: fetchProvider, key: fetchProvider }, t("fetchOther") + fetchProvider) : null
1371
+ ] })),
1372
+ fetchProvider === "http" ? react.createElement("p", { className: "dshws_field_hint" }, t("fetchHttpHint")) : null,
1373
+ apiFetch ? (apiSearch ? react.createElement("p", { className: "dshws_field_hint" }, t("apiShared")) : apiConfig()) : null,
1185
1374
  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" } },
1186
1375
  react.createElement("button", {
1187
1376
  type: "button",
@@ -1195,7 +1384,7 @@ window.__ModuleLoader__.load({
1195
1384
  react.createElement("button", {
1196
1385
  type: "button",
1197
1386
  className: "dshws_btn dshws_btn_primary",
1198
- disabled: state.saving || !state.writable,
1387
+ disabled: state.saving || !state.writable || state.invalid || (!state.dirty && !state.failed),
1199
1388
  onClick: (event) => {
1200
1389
  event.preventDefault();
1201
1390
  void actions.save();
@@ -1269,7 +1458,7 @@ window.__ModuleLoader__.load({
1269
1458
  // One controller for the settings section, created as soon as the Host
1270
1459
  // serves this namespace and torn down with it.
1271
1460
  ctx.effect(() => ctx.configForms.whileServed([NS], () => {
1272
- shared.controller = new SearchCardController(ctx.configForms.get(NS), ctx.remote);
1461
+ shared.controller = new SearchCardController(combinedScope(ctx.configForms), ctx.remote);
1273
1462
  const stopUsage = usageStore.start();
1274
1463
  const stopCredentials = ctx.remote.$on("credentials/reference-updated", (ref) => {
1275
1464
  shared.controller?.form.refreshCredential(ref);
@@ -1288,6 +1477,8 @@ window.__ModuleLoader__.load({
1288
1477
  return stopSection;
1289
1478
  });
1290
1479
  return () => {
1480
+ shared.controller?.unsubscribe();
1481
+ shared.controller?.form.dispose();
1291
1482
  shared.controller = null;
1292
1483
  stopUsage();
1293
1484
  stopCredentials();
package/lib/deepseek.js CHANGED
@@ -22,7 +22,7 @@
22
22
  import { resolveSupplierConfig } from "./config.js";
23
23
  import { WebError } from "@deepseek-ai/dsh-web";
24
24
  import { launchEnvironmentOf } from "@deepseek-ai/dsh-launch-environment";
25
- import { MAX_RESULTS_CAP, USER_AGENT, abortable, isAbortError, resolveApiKey, resolveSecret, searchAborted, throwIfSearchAborted } from "./shared.js";
25
+ import { apiKeyReady, MAX_RESULTS_CAP, USER_AGENT, abortable, isAbortError, resolveApiKey, resolveSecret, searchAborted, throwIfSearchAborted } from "./shared.js";
26
26
 
27
27
  /** Default endpoint: DeepSeek's Anthropic-compatible API (`/messages` appended). */
28
28
  export const DEEPSEEK_DEFAULT_BASE_URL = "https://api.deepseek.com/anthropic/v1";
@@ -95,6 +95,21 @@ export class DeepSeekSearchProvider {
95
95
  && Number.isInteger(options.maxUses) && options.maxUses > 0;
96
96
  }
97
97
 
98
+ /** Use the pending model route, rather than the previous session request. */
99
+ async ready(llmProvider) {
100
+ const options = this.resolveOptions();
101
+ if (llmProvider === ACCOUNT_PROVIDER && options.resolveAccountToken !== void 0) {
102
+ try {
103
+ const endpoint = `${options.baseURL.replace(/\/+$/u, "")}/messages`;
104
+ const token = await options.resolveAccountToken(endpoint, llmProvider);
105
+ if ((token?.length ?? 0) > 0) return true;
106
+ } catch {
107
+ return false;
108
+ }
109
+ }
110
+ return await apiKeyReady(options);
111
+ }
112
+
98
113
  async search(request, signal) {
99
114
  const options = this.resolveOptions();
100
115
  throwIfSearchAborted(signal);
@@ -124,7 +139,8 @@ export class DeepSeekSearchProvider {
124
139
  role: "user",
125
140
  content: [{ type: "text", text: `Perform a web search for the query: ${request.query}` }]
126
141
  }],
127
- tools: [{ type: "web_search_20250305", name: "web_search", max_uses: options.maxUses }]
142
+ tools: [{ type: "web_search_20250305", name: "web_search", max_uses: options.maxUses }],
143
+ thinking: { type: "disabled" }
128
144
  };
129
145
  // Record the exact secret-free request before it leaves; a throw here
130
146
  // prevents dispatch rather than logging an unrecorded model input.
@@ -189,8 +205,8 @@ export function resolveDeepseekOptions(ctx, config) {
189
205
  }),
190
206
  // Only a DeepSeek-account session may spend account quota; every other
191
207
  // session falls back to the API key resolved above.
192
- resolveAccountToken: async (endpoint) => {
193
- if (ctx.get("agents")?.currentInitiator()?.session.requestContext()?.provider !== ACCOUNT_PROVIDER) return void 0;
208
+ resolveAccountToken: async (endpoint, llmProvider = ctx.get("agents")?.currentInitiator()?.session.requestContext()?.provider) => {
209
+ if (llmProvider !== ACCOUNT_PROVIDER) return void 0;
194
210
  return await ctx.get("deepseekAccount")?.resolveToken(endpoint);
195
211
  },
196
212
  recordRequest: (request) => {
package/lib/index.js CHANGED
@@ -151,7 +151,7 @@ const Config = z.object({
151
151
  /**
152
152
  * One seam-facing provider whose `id` stays `dsh-web-search`. The active
153
153
  * backend is read from the live settings section on every `available` /
154
- * `search` call, so a card save takes effect on the next search.
154
+ * `ready` / `search` call, so a card save takes effect on the next search.
155
155
  */
156
156
  class PluginSearchProvider {
157
157
  id = SEARCH_PROVIDER_ID;
@@ -172,6 +172,10 @@ class PluginSearchProvider {
172
172
  return this.backend().available();
173
173
  }
174
174
 
175
+ async ready(llmProvider) {
176
+ return await this.backend().ready(llmProvider);
177
+ }
178
+
175
179
  async search(request, signal) {
176
180
  return this.backend().search(request, signal);
177
181
  }
package/lib/rest.js CHANGED
@@ -17,7 +17,7 @@
17
17
  */
18
18
  import { WebError } from "@deepseek-ai/dsh-web";
19
19
  import { ProxyAgent } from "undici";
20
- import { MAX_RESULTS_CAP, USER_AGENT, isAbortError, resolveApiKey, resolveSecret, searchAborted, throwIfSearchAborted } from "./shared.js";
20
+ import { apiKeyReady, MAX_RESULTS_CAP, USER_AGENT, isAbortError, resolveApiKey, resolveSecret, searchAborted, throwIfSearchAborted } from "./shared.js";
21
21
 
22
22
  /** Acceptable auth templates (superset includes `query` for SerpApi). */
23
23
  const AUTH_TYPES = new Set(["bearer", "header", "none", "query"]);
@@ -163,6 +163,12 @@ export class RestSearchProvider {
163
163
  return (options.apiKey?.length ?? 0) > 0 || options.resolveApiKey !== void 0;
164
164
  }
165
165
 
166
+ /** New Hosts gate tools on credential presence; keyless engines stay ready. */
167
+ async ready() {
168
+ const options = this.resolveOptions();
169
+ return (options.auth?.type ?? "none") === "none" || await apiKeyReady(options);
170
+ }
171
+
166
172
  async search(request, signal) {
167
173
  const options = this.resolveOptions();
168
174
  throwIfSearchAborted(signal);
package/lib/shared.js CHANGED
@@ -7,7 +7,7 @@ import { launchEnvironmentOf } from "@deepseek-ai/dsh-launch-environment";
7
7
  import { WebError } from "@deepseek-ai/dsh-web";
8
8
 
9
9
  /** Attribution header sent on every request. */
10
- export const USER_AGENT = "dsh-web-search-plugin/0.5.1";
10
+ export const USER_AGENT = "dsh-web-search-plugin/0.6.1";
11
11
  /** Shared cap: Tavily `max_results` and Brave `count` both accept 1..20. */
12
12
  export const MAX_RESULTS_CAP = 20;
13
13
 
@@ -25,6 +25,15 @@ export function resolveSecret(ctx, config) {
25
25
  return {
26
26
  ...literal === void 0 ? {} : { apiKey: literal },
27
27
  apiKeyEnv,
28
+ // Inspect presence only; resolving a stored secret belongs to search().
29
+ apiKeyReady: async () => {
30
+ if (literal !== void 0) return true;
31
+ const credentials = ctx.get("credentials");
32
+ if (credentials !== void 0 && (await credentials.describe(apiKeyEnv)).configured) return true;
33
+ const ambient = launchEnvironmentOf(ctx).get(apiKeyEnv);
34
+ if (ambient !== void 0 && ambient.value.length > 0) return true;
35
+ return (process.env[apiKeyEnv]?.length ?? 0) > 0;
36
+ },
28
37
  resolveApiKey: async () => {
29
38
  const credentials = ctx.get("credentials");
30
39
  if (credentials !== void 0) {
@@ -39,6 +48,19 @@ export function resolveSecret(ctx, config) {
39
48
  };
40
49
  }
41
50
 
51
+ /** Check configured key presence without retaining a secret or contacting an endpoint. */
52
+ export async function apiKeyReady(options) {
53
+ try {
54
+ if ((options.apiKey?.length ?? 0) > 0) return true;
55
+ if (options.apiKeyReady !== void 0) return await options.apiKeyReady();
56
+ // Directly constructed providers may supply only a local credential resolver.
57
+ return ((await options.resolveApiKey?.())?.length ?? 0) > 0;
58
+ } catch {
59
+ // Execution also fails when the credential plane cannot be read.
60
+ return false;
61
+ }
62
+ }
63
+
42
64
  /** Race a same-process asynchronous preflight against caller cancellation. */
43
65
  export function abortable(operation, signal) {
44
66
  if (signal === void 0) return operation;
package/locale/en.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Web search",
4
- "description": "Unified web search for the DeepSeek Harness seam (ctx.web): DeepSeek (official), Tavily, Brave, Serper, SerpApi, Exa, SearXNG, Scavio, and Firecrawl. Switch engines from settings."
4
+ "description": "Search engines and web retrieval in one page: DeepSeek Search API, Messages, eight third-party engines, local HTTP and optional DeepSeek Fetch API.",
5
+ "detail": "assets/detail/en.md"
5
6
  }
6
- }
7
+ }