dsh-web-search-plugin 0.5.0 → 0.6.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
@@ -29,6 +29,100 @@ 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
+ }
97
+ // Mirrors lib/config.js; this client bundle has no host-module imports.
98
+ const SUPPLIER_CONFIG_ALIASES = {
99
+ tavilyApiKey: "apiKey",
100
+ tavilyApiKeyEnv: "apiKeyEnv",
101
+ tavilyBaseURL: "baseURL",
102
+ tavilyMode: "mode",
103
+ tavilySearchDepth: "searchDepth",
104
+ tavilyIncludeAnswer: "includeAnswer",
105
+ tavilyTopic: "topic",
106
+ deepseekModel: "model",
107
+ deepseekApiVersion: "apiVersion",
108
+ deepseekMaxTokens: "maxTokens",
109
+ deepseekMaxUses: "maxUses",
110
+ braveCountry: "country",
111
+ braveSearchLang: "searchLang",
112
+ braveFreshness: "freshness",
113
+ braveProxy: "proxy",
114
+ scavioCountry: "country",
115
+ scavioSearchLang: "searchLang"
116
+ };
117
+ const SUPPLIER_DEFAULTS = {
118
+ webApiKeyEnv: "DEEPSEEK_API_KEY", webApiBaseURL: "https://api.deepseek.com/v1/tools", webApiCount: 10, fetchProvider: "http",
119
+ deepseekModel: "deepseek-flash", deepseekApiVersion: "2023-06-01", deepseekMaxTokens: 4096, deepseekMaxUses: 5,
120
+ tavilyMode: "keyless", tavilyApiKey: "", tavilyApiKeyEnv: "TAVILY_API_KEY", tavilyBaseURL: "",
121
+ tavilySearchDepth: "basic", tavilyIncludeAnswer: true, tavilyTopic: "general",
122
+ braveCountry: "", braveSearchLang: "", braveFreshness: "", braveProxy: "",
123
+ scavioCountry: "", scavioSearchLang: ""
124
+ };
125
+ const supplierValue = (values, field) => values?.[field] ?? values?.[SUPPLIER_CONFIG_ALIASES[field]] ?? SUPPLIER_DEFAULTS[field];
32
126
  /** Built-in REST providers (mirrors `lib/providers.js`; browser bundle is self-contained). */
33
127
  const BUILTIN_REST_PROVIDERS = [
34
128
  { id: "serper", name: "Serper", officialUrl: "https://serper.dev/", defaultBaseURL: "https://google.serper.dev", keyRequired: true, keyField: "serperApiKey", keyEnvField: "serperApiKeyEnv", baseURLField: "serperBaseURL" },
@@ -91,14 +185,14 @@ window.__ModuleLoader__.load({
91
185
  /** Credential reference DeepSeek resolves when the section names none. */
92
186
  const DEFAULT_DEEPSEEK_KEY_REF = "DEEPSEEK_API_KEY";
93
187
  /** Form field the Tavily write-only credential control stages under. */
94
- const TAVILY_API_KEY_FIELD = "apiKey";
188
+ const TAVILY_API_KEY_FIELD = "tavilyApiKey";
95
189
  /** Form field the Brave write-only credential control stages under. */
96
190
  const BRAVE_API_KEY_FIELD = "braveApiKey";
97
191
  /** Form field the DeepSeek write-only credential control stages under. */
98
192
  const DEEPSEEK_API_KEY_FIELD = "deepseekApiKey";
99
193
  /** Form fields carrying literal API keys (write-only, staged under the credentials domain). */
100
194
  const REST_KEY_FIELDS = BUILTIN_REST_PROVIDERS.map((entry) => entry.keyField).filter((field) => field !== "");
101
- 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]);
102
196
  const DRAFT_KEY = "dsh-web-search-plugin:settings-draft";
103
197
 
104
198
  function readDraft() {
@@ -135,7 +229,29 @@ window.__ModuleLoader__.load({
135
229
  provider: "Search engine",
136
230
  providerTavily: "Tavily",
137
231
  providerBrave: "Brave Search",
138
- 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.",
139
255
  mode: "Auth mode",
140
256
  modeKeyless: "Keyless (free, rate-limited)",
141
257
  modeKeyed: "API key",
@@ -163,6 +279,8 @@ window.__ModuleLoader__.load({
163
279
  topicNews: "News",
164
280
  country: "Country",
165
281
  countryHint: "ISO 2-letter code (e.g. cn).",
282
+ scavioCountryHint: "Country/region code accepted by Scavio (e.g. cn).",
283
+ scavioSearchLangHint: "Language code accepted by Scavio (e.g. zh-CN).",
166
284
  searchLang: "Search language",
167
285
  searchLangHint: "e.g. zh-hans or en.",
168
286
  freshness: "Freshness",
@@ -179,8 +297,6 @@ window.__ModuleLoader__.load({
179
297
  deepseekBaseURLHint: "Leave blank to use the DeepSeek Anthropic-compatible API default.",
180
298
  model: "Model",
181
299
  modelHint: "Anthropic-format model name for the search request.",
182
- apiVersion: "API version",
183
- apiVersionHint: "anthropic-version header value.",
184
300
  maxTokens: "Max tokens",
185
301
  maxTokensHint: "Upper bound on generated tokens for the search request.",
186
302
  maxUses: "Max uses",
@@ -232,7 +348,29 @@ window.__ModuleLoader__.load({
232
348
  provider: "搜索引擎",
233
349
  providerTavily: "Tavily",
234
350
  providerBrave: "Brave Search",
235
- 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: "保存失败,部分设置可能已保存。草稿已保留,请核对后重试。",
236
374
  mode: "认证模式",
237
375
  modeKeyless: "Keyless(免费、限流)",
238
376
  modeKeyed: "API key",
@@ -260,6 +398,8 @@ window.__ModuleLoader__.load({
260
398
  topicNews: "新闻",
261
399
  country: "国家/地区",
262
400
  countryHint: "ISO 两位码(如 cn)。",
401
+ scavioCountryHint: "Scavio 支持的国家/地区码(如 cn)。",
402
+ scavioSearchLangHint: "Scavio 支持的语言码(如 zh-CN)。",
263
403
  searchLang: "搜索语言",
264
404
  searchLangHint: "如 zh-hans、en。",
265
405
  freshness: "时效",
@@ -276,8 +416,6 @@ window.__ModuleLoader__.load({
276
416
  deepseekBaseURLHint: "留空则使用 DeepSeek Anthropic 兼容 API 默认地址。",
277
417
  model: "模型",
278
418
  modelHint: "搜索请求使用的 Anthropic 格式模型名。",
279
- apiVersion: "API 版本",
280
- apiVersionHint: "anthropic-version 请求头值。",
281
419
  maxTokens: "最大 token",
282
420
  maxTokensHint: "搜索请求生成 token 的上限。",
283
421
  maxUses: "最大调用次数",
@@ -336,6 +474,7 @@ window.__ModuleLoader__.load({
336
474
  if (!/^[0-9]+$/u.test(trimmed)) return void 0;
337
475
  let parsed = Number(trimmed);
338
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;
339
478
  if (bounds?.min != null && parsed < bounds.min) parsed = bounds.min;
340
479
  if (bounds?.max != null && parsed > bounds.max) parsed = bounds.max;
341
480
  return { kind: "set", value: parsed };
@@ -391,26 +530,29 @@ window.__ModuleLoader__.load({
391
530
  this.scope = scope;
392
531
  this.remote = remote;
393
532
  this.specs = new Map([
533
+ choiceField("fetchProvider"),
534
+ credentialField("webApiKeyEnv"),
535
+ textField("webApiBaseURL"),
536
+ numberField("webApiCount", { min: 1, max: 50, strict: true }),
394
537
  choiceField("provider"),
395
- choiceField("mode"),
538
+ choiceField("tavilyMode"),
396
539
  numberField("maxResults", { min: 1, max: MAX_RESULTS_CAP }),
397
- credentialField("apiKeyEnv"),
398
- textField("baseURL"),
399
- choiceField("searchDepth"),
400
- choiceField("topic"),
401
- booleanField("includeAnswer"),
540
+ credentialField("tavilyApiKeyEnv"),
541
+ textField("tavilyBaseURL"),
542
+ choiceField("tavilySearchDepth"),
543
+ choiceField("tavilyTopic"),
544
+ booleanField("tavilyIncludeAnswer"),
402
545
  credentialField("braveApiKeyEnv"),
403
546
  textField("braveBaseURL"),
404
- textField("country"),
405
- textField("searchLang"),
406
- choiceField("freshness"),
407
- textField("proxy"),
547
+ textField("braveCountry"),
548
+ textField("braveSearchLang"),
549
+ choiceField("braveFreshness"),
550
+ textField("braveProxy"),
408
551
  credentialField("deepseekApiKeyEnv"),
409
552
  textField("deepseekBaseURL"),
410
- textField("model"),
411
- textField("apiVersion"),
412
- numberField("maxTokens", { min: 1 }),
413
- numberField("maxUses", { min: 1 }),
553
+ textField("deepseekModel"),
554
+ numberField("deepseekMaxTokens", { min: 1 }),
555
+ numberField("deepseekMaxUses", { min: 1 }),
414
556
  credentialField("serperApiKeyEnv"),
415
557
  textField("serperBaseURL"),
416
558
  credentialField("serpapiApiKeyEnv"),
@@ -420,6 +562,8 @@ window.__ModuleLoader__.load({
420
562
  textField("searxngBaseURL"),
421
563
  credentialField("scavioApiKeyEnv"),
422
564
  textField("scavioBaseURL"),
565
+ textField("scavioCountry"),
566
+ textField("scavioSearchLang"),
423
567
  credentialField("firecrawlApiKeyEnv"),
424
568
  textField("firecrawlBaseURL")
425
569
  ].map((spec) => [spec.field, spec]));
@@ -427,18 +571,21 @@ window.__ModuleLoader__.load({
427
571
  this.saving = false;
428
572
  this.failed = false;
429
573
  this.credential = { ref: "", configured: false, writable: true };
574
+ this.apiCredential = { ref: "", configured: false, writable: true };
430
575
  this.toastKey = null;
431
576
  this.toastTimer = 0;
432
577
  this.listeners = new Set();
433
578
  const draft = readDraft();
434
579
  if (draft?.staged) {
435
- for (const [field, edit] of Object.entries(draft.staged)) {
580
+ for (const [oldField, edit] of Object.entries(draft.staged)) {
581
+ const field = Object.entries(SUPPLIER_CONFIG_ALIASES).find(([name, legacy]) => !name.startsWith("scavio") && legacy === oldField)?.[0] ?? oldField;
582
+ if (field !== oldField && Object.hasOwn(draft.staged, field)) continue;
436
583
  if (!this.specs.has(field) || edit === null || typeof edit !== "object") continue;
437
584
  this.staged.set(field, { text: String(edit.text ?? ""), clear: edit.clear === true });
438
585
  }
439
586
  if (draft.failed === true) this.failed = true;
440
587
  }
441
- scope.subscribe(() => {
588
+ this.unsubscribe = scope.subscribe(() => {
442
589
  this.publish();
443
590
  });
444
591
  this.readCredential();
@@ -460,6 +607,11 @@ window.__ModuleLoader__.load({
460
607
  invalid: plan.some((item) => item.invalid === true),
461
608
  saving: this.saving,
462
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),
463
615
  toastKey: this.toastKey
464
616
  };
465
617
  }
@@ -496,7 +648,7 @@ window.__ModuleLoader__.load({
496
648
  if (this.stored(field)) plan.push({ field, op: { op: "unset", path: [field] } });
497
649
  continue;
498
650
  }
499
- 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;
500
652
  const write = spec.parse(staged.text);
501
653
  if (write === void 0) plan.push({ field, invalid: true });
502
654
  else if (write.kind === "clear") plan.push({ field, op: { op: "unset", path: [field] } });
@@ -525,9 +677,32 @@ window.__ModuleLoader__.load({
525
677
  this.showToast("invalid");
526
678
  return;
527
679
  }
680
+ if (this.scope.canWrite && !this.scope.canWrite(plan)) {
681
+ this.failed = true;
682
+ this.showToast("failed");
683
+ return;
684
+ }
528
685
  const revision = this.snapshotOf().revision;
529
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
+ }
530
696
  const ops = plan.flatMap((item) => item.op === void 0 ? [] : [item.op]);
697
+ for (const item of plan) {
698
+ const legacy = SUPPLIER_CONFIG_ALIASES[item.field];
699
+ if (item.op?.op !== "unset" || legacy === void 0 || !Object.hasOwn(this.userLayer() ?? {}, legacy)) continue;
700
+ for (const [other, alias] of Object.entries(SUPPLIER_CONFIG_ALIASES)) {
701
+ if (other === item.field || alias !== legacy || plan.some((entry) => entry.field === other) || this.snapshotOf().value?.[other] != null) continue;
702
+ ops.push({ op: "set", path: [other], value: this.sectionValue(other) });
703
+ }
704
+ if (!ops.some((op) => op.op === "unset" && op.path[0] === legacy)) ops.push({ op: "unset", path: [legacy] });
705
+ }
531
706
  for (const item of credentials) {
532
707
  // Override even an inherited literal key; unsetting could expose it again.
533
708
  if (!ops.some((op) => op.path[0] === item.field)) ops.push({ op: "set", path: [item.field], value: "" });
@@ -576,45 +751,44 @@ window.__ModuleLoader__.load({
576
751
  this.staged.set(field, edit);
577
752
  this.failed = false;
578
753
  this.publish();
579
- if (field === "provider" || field === "apiKeyEnv" || 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();
580
755
  }
581
756
  snapshotOf() {
582
757
  return this.scope.getSnapshot();
583
758
  }
584
759
  sectionValue(field) {
585
- return this.snapshotOf().value?.[field];
760
+ return supplierValue(this.snapshotOf().value, field);
586
761
  }
587
762
  baseText(field) {
588
- return this.specs.get(field).format(this.snapshotOf().base?.[field]);
763
+ return this.specs.get(field).format(supplierValue(this.snapshotOf().base, field));
589
764
  }
590
765
  userLayer() {
591
766
  return this.snapshotOf().user;
592
767
  }
593
768
  stored(field) {
594
769
  const user = this.userLayer();
595
- return user !== void 0 && Object.hasOwn(user, field);
770
+ return user !== void 0 && (Object.hasOwn(user, field) || Object.hasOwn(user, SUPPLIER_CONFIG_ALIASES[field]));
596
771
  }
597
772
  publish() {
773
+ if (this.disposed) return;
598
774
  writeDraft(this);
599
775
  for (const listener of this.listeners) listener();
600
776
  }
601
777
  /** Draft-aware engine: staged `provider` wins over the saved section. */
602
778
  providerOf() {
603
- const staged = this.staged.get("provider");
604
- if (staged !== void 0 && !staged.clear && staged.text.trim() !== "") return staged.text.trim();
605
- const declared = this.sectionValue("provider");
606
- 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;
607
781
  return "deepseek-official";
608
782
  }
609
783
  credentialRef(field, fallback) {
610
784
  const staged = this.staged.get(field);
611
785
  const declared = staged === void 0
612
786
  ? this.sectionValue(field)
613
- : staged.clear ? this.snapshotOf().base?.[field] : staged.text.trim();
787
+ : staged.clear ? supplierValue(this.snapshotOf().base, field) : staged.text.trim();
614
788
  return typeof declared === "string" && declared.length > 0 ? declared : fallback;
615
789
  }
616
790
  tavilyRef() {
617
- return this.credentialRef("apiKeyEnv", DEFAULT_TAVILY_KEY_REF);
791
+ return this.credentialRef("tavilyApiKeyEnv", DEFAULT_TAVILY_KEY_REF);
618
792
  }
619
793
  braveRef() {
620
794
  return this.credentialRef("braveApiKeyEnv", DEFAULT_BRAVE_KEY_REF);
@@ -625,6 +799,7 @@ window.__ModuleLoader__.load({
625
799
  /** The credential reference the currently visible engine uses. */
626
800
  refOf() {
627
801
  const provider = this.providerOf();
802
+ if (provider === API_SEARCH) return this.credentialRef("webApiKeyEnv", DEFAULT_DEEPSEEK_KEY_REF);
628
803
  if (provider === "brave") return this.braveRef();
629
804
  if (provider === "deepseek-official") return this.deepseekRef();
630
805
  const rest = builtinRest(provider);
@@ -638,39 +813,49 @@ window.__ModuleLoader__.load({
638
813
  }
639
814
  async readCredential() {
640
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 };
641
818
  if (ref !== this.credential.ref) {
642
819
  this.credential = { ref, configured: false, writable: true };
643
820
  this.publish();
644
821
  }
645
822
  let response;
646
823
  try {
647
- response = await this.remote.credentials.describe([ref]);
824
+ response = await this.remote.credentials.describe([...new Set([ref, apiRef])]);
648
825
  } catch (_credentialReadFailure) {
649
826
  return;
650
827
  }
651
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
+ }
652
833
  const view = response.value[ref];
653
834
  const next = {
654
835
  ref,
655
836
  configured: view?.configured ?? false,
656
837
  writable: view?.writable ?? true
657
838
  };
658
- if (next.configured === this.credential.configured && next.writable === this.credential.writable) return;
659
839
  this.credential = next;
660
840
  this.publish();
661
841
  }
662
842
  refreshCredential(ref) {
663
- if (ref !== this.credential.ref) return;
843
+ if (ref !== this.credential.ref && ref !== this.apiCredential.ref) return;
664
844
  this.readCredential();
665
845
  }
666
- async writeKey(field, value) {
846
+ keyRef(field) {
667
847
  let ref;
668
848
  if (field === BRAVE_API_KEY_FIELD) ref = this.braveRef();
849
+ else if (field === "webApiKey") ref = this.credentialRef("webApiKeyEnv", DEFAULT_DEEPSEEK_KEY_REF);
669
850
  else if (field === DEEPSEEK_API_KEY_FIELD) ref = this.deepseekRef();
670
851
  else {
671
852
  const rest = builtinRestByKeyField(field);
672
853
  ref = rest !== void 0 ? this.restKeyRef(rest) : this.tavilyRef();
673
854
  }
855
+ return ref;
856
+ }
857
+ async writeKey(field, value) {
858
+ const ref = this.keyRef(field);
674
859
  try {
675
860
  const response = await this.remote.credentials.set(ref, value);
676
861
  if (!response.ok) return false;
@@ -680,6 +865,12 @@ window.__ModuleLoader__.load({
680
865
  await this.readCredential();
681
866
  return true;
682
867
  }
868
+ dispose() {
869
+ this.disposed = true;
870
+ this.unsubscribe();
871
+ this.listeners.clear();
872
+ if (this.toastTimer) clearTimeout(this.toastTimer);
873
+ }
683
874
  };
684
875
 
685
876
  /** Bridges the plugin scope and the credentials domain onto the card. */
@@ -689,36 +880,42 @@ window.__ModuleLoader__.load({
689
880
  this.remote = remote;
690
881
  this.form = new SearchCardForm(scope, remote);
691
882
  this.store = this.form.bind(() => this.projection());
692
- scope.subscribe(() => {
883
+ this.unsubscribe = scope.subscribe(() => {
693
884
  this.form.readCredential();
694
885
  });
695
886
  }
696
887
  projection() {
697
888
  return {
698
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,
699
897
  provider: this.form.field("provider"),
700
- mode: this.form.field("mode"),
701
- apiKey: this.form.field(TAVILY_API_KEY_FIELD),
702
- apiKeyEnv: this.form.field("apiKeyEnv"),
703
- baseURL: this.form.field("baseURL"),
898
+ tavilyMode: this.form.field("tavilyMode"),
899
+ tavilyApiKey: this.form.field(TAVILY_API_KEY_FIELD),
900
+ tavilyApiKeyEnv: this.form.field("tavilyApiKeyEnv"),
901
+ tavilyBaseURL: this.form.field("tavilyBaseURL"),
704
902
  maxResults: this.form.field("maxResults"),
705
- searchDepth: this.form.field("searchDepth"),
706
- includeAnswer: this.form.field("includeAnswer"),
707
- topic: this.form.field("topic"),
903
+ tavilySearchDepth: this.form.field("tavilySearchDepth"),
904
+ tavilyIncludeAnswer: this.form.field("tavilyIncludeAnswer"),
905
+ tavilyTopic: this.form.field("tavilyTopic"),
708
906
  braveApiKey: this.form.field(BRAVE_API_KEY_FIELD),
709
907
  braveApiKeyEnv: this.form.field("braveApiKeyEnv"),
710
908
  braveBaseURL: this.form.field("braveBaseURL"),
711
- country: this.form.field("country"),
712
- searchLang: this.form.field("searchLang"),
713
- freshness: this.form.field("freshness"),
714
- proxy: this.form.field("proxy"),
909
+ braveCountry: this.form.field("braveCountry"),
910
+ braveSearchLang: this.form.field("braveSearchLang"),
911
+ braveFreshness: this.form.field("braveFreshness"),
912
+ braveProxy: this.form.field("braveProxy"),
715
913
  deepseekApiKey: this.form.field(DEEPSEEK_API_KEY_FIELD),
716
914
  deepseekApiKeyEnv: this.form.field("deepseekApiKeyEnv"),
717
915
  deepseekBaseURL: this.form.field("deepseekBaseURL"),
718
- model: this.form.field("model"),
719
- apiVersion: this.form.field("apiVersion"),
720
- maxTokens: this.form.field("maxTokens"),
721
- maxUses: this.form.field("maxUses"),
916
+ deepseekModel: this.form.field("deepseekModel"),
917
+ deepseekMaxTokens: this.form.field("deepseekMaxTokens"),
918
+ deepseekMaxUses: this.form.field("deepseekMaxUses"),
722
919
  serperApiKey: this.form.field("serperApiKey"),
723
920
  serperApiKeyEnv: this.form.field("serperApiKeyEnv"),
724
921
  serperBaseURL: this.form.field("serperBaseURL"),
@@ -732,6 +929,8 @@ window.__ModuleLoader__.load({
732
929
  scavioApiKey: this.form.field("scavioApiKey"),
733
930
  scavioApiKeyEnv: this.form.field("scavioApiKeyEnv"),
734
931
  scavioBaseURL: this.form.field("scavioBaseURL"),
932
+ scavioCountry: this.form.field("scavioCountry"),
933
+ scavioSearchLang: this.form.field("scavioSearchLang"),
735
934
  firecrawlApiKey: this.form.field("firecrawlApiKey"),
736
935
  firecrawlApiKeyEnv: this.form.field("firecrawlApiKeyEnv"),
737
936
  firecrawlBaseURL: this.form.field("firecrawlBaseURL"),
@@ -751,7 +950,7 @@ window.__ModuleLoader__.load({
751
950
  /** Row style: one labelled field with optional override badge and restore-default. */
752
951
  const fieldRow = (label, hint, children, meta) => react.createElement("div", { className: "dshws_field" },
753
952
  react.createElement("div", { className: "dshws_field_head" },
754
- react.createElement("label", { className: "dshws_field_label" }, label),
953
+ react.createElement("label", { className: "dshws_field_label", htmlFor: children?.props?.id }, label),
755
954
  meta?.overridden ? react.createElement("span", { className: "dshws_field_badges" },
756
955
  react.createElement("span", { className: "dshws_badge" }, meta.t("overridden")),
757
956
  react.createElement("button", { type: "button", className: "dshws_reset", disabled: meta.disabled === true, onClick: meta.onReset }, meta.t("reset"))) : null),
@@ -820,6 +1019,7 @@ window.__ModuleLoader__.load({
820
1019
  ".dshws_card_desc{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5}",
821
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}",
822
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)}",
823
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}",
824
1024
  ".dshws_field_head{display:flex;align-items:center;gap:8px}",
825
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}",
@@ -828,6 +1028,7 @@ window.__ModuleLoader__.load({
828
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}",
829
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)}",
830
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}}",
831
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}",
832
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}",
833
1034
  ".dshws_reset:hover:not(:disabled){color:var(--dsw-alias-label-primary)}",
@@ -1018,7 +1219,8 @@ window.__ModuleLoader__.load({
1018
1219
  if (key === "saved") return t("savedToast");
1019
1220
  if (key === "nothing") return t("nothingToSave");
1020
1221
  if (key === "invalid") return t("invalidToast");
1021
- if (key === "failed") return t("saveFailed");
1222
+ if (key === "failed") return t("partialFailed");
1223
+ if (key === "credentialConflict") return t("credentialConflict");
1022
1224
  return "";
1023
1225
  }
1024
1226
 
@@ -1027,21 +1229,24 @@ window.__ModuleLoader__.load({
1027
1229
  const { t, state, actions } = props;
1028
1230
  if (!state.available) return null;
1029
1231
  const disabled = !state.writable || state.saving;
1030
- 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;
1031
1236
  const brave = provider === "brave";
1032
1237
  const deepseek = provider === "deepseek-official";
1033
1238
  const tavily = provider === "tavily";
1034
1239
  const restMeta = builtinRest(provider);
1035
- const keyed = state.mode.text === "keyed";
1240
+ const keyed = state.tavilyMode.text === "keyed";
1036
1241
  const keyHint = state.apiKeyConfigured ? t("apiKeyHint") : t("apiKeyHint") + " " + t("apiKeyUnavailableHint");
1037
1242
  const toastText = toastCopy(t, state.toastKey);
1038
- 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";
1039
1244
  const row = (field, label, hint, children) => fieldRow(label, hint, children, {
1040
1245
  t,
1041
1246
  overridden: state[field]?.overridden === true,
1042
1247
  invalid: state[field]?.invalid === true,
1043
- errorKey: field.endsWith("ApiKeyEnv") || field === "apiKeyEnv" ? "invalidCredentialRef" : "invalidNumber",
1044
- 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),
1045
1250
  onReset: () => actions.resetField(field)
1046
1251
  });
1047
1252
  const maxResultsWrite = numberField("maxResults", { min: 1, max: MAX_RESULTS_CAP }).parse(String(state.maxResults.text ?? "").trim());
@@ -1057,14 +1262,28 @@ window.__ModuleLoader__.load({
1057
1262
  return react.createElement("option", { value: n, key: n }, n);
1058
1263
  })
1059
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
+ );
1060
1275
  return react.createElement("div", { className: "dshws_form" },
1061
1276
  react.createElement("div", { className: "dshws_card_header" },
1062
1277
  react.createElement("div", { className: "dshws_card_headText" },
1063
1278
  react.createElement("span", { className: "dshws_card_name" }, t("nav"))),
1064
1279
  state.dirty || state.failed ? react.createElement("span", { className: "dshws_pending" }, t("unsaved")) : null),
1065
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,
1066
1284
  pair(
1067
- 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")),
1068
1287
  react.createElement("option", { value: "deepseek-official", key: "deepseek-official" }, t("providerDeepseek")),
1069
1288
  react.createElement("option", { value: "tavily", key: "tavily" }, t("providerTavily")),
1070
1289
  react.createElement("option", { value: "brave", key: "brave" }, t("providerBrave")),
@@ -1072,11 +1291,14 @@ window.__ModuleLoader__.load({
1072
1291
  react.createElement("option", { value: "__ddg__", key: "ddg", disabled: true }, t("ddgDisabled"))
1073
1292
  ] }),
1074
1293
  react.createElement("p", { className: "dshws_field_hint", style: { padding: "4px 0 0" } }, t("ddgHint"))),
1075
- tavily ? row("mode", t("mode"), null, selectInput({ id: "ws-mode", value: state.mode.text, disabled, onChange: (e) => actions.edit("mode", e.target.value), children: [
1294
+ tavily ? row("tavilyMode", t("mode"), null, selectInput({ id: "ws-mode", value: state.tavilyMode.text, disabled, onChange: (e) => actions.edit("tavilyMode", e.target.value), children: [
1076
1295
  react.createElement("option", { value: "keyless", key: "keyless" }, t("modeKeyless")),
1077
1296
  react.createElement("option", { value: "keyed", key: "keyed" }, t("modeKeyed"))
1078
1297
  ] })) : null
1079
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,
1080
1302
  react.createElement(QuotaCard, { t, provider, keyed }),
1081
1303
  keyConsoleLink(t, provider, restMeta, keyed),
1082
1304
  deepseek ? pair(
@@ -1088,40 +1310,37 @@ window.__ModuleLoader__.load({
1088
1310
  row("braveApiKeyEnv", t("braveApiKeyEnv"), t("braveApiKeyEnvHint"), textInput({ id: "ws-brave-keyref", value: state.braveApiKeyEnv.text, disabled, onChange: (e) => actions.edit("braveApiKeyEnv", e.target.value) }))
1089
1311
  ) : null,
1090
1312
  (tavily && keyed) ? pair(
1091
- fieldRow(t("apiKey"), keyHint, secretInput({ id: "ws-tavily-key", value: state.apiKey.text, disabled: disabled || !state.apiKeyWritable, placeholder: state.apiKeyConfigured ? t("apiKeySet") : t("apiKeyUnset"), onChange: (e) => actions.edit(TAVILY_API_KEY_FIELD, e.target.value) })),
1092
- row("apiKeyEnv", t("apiKeyEnv"), t("apiKeyEnvHint"), textInput({ id: "ws-tavily-keyref", value: state.apiKeyEnv.text, disabled, onChange: (e) => actions.edit("apiKeyEnv", e.target.value) }))
1313
+ fieldRow(t("apiKey"), keyHint, secretInput({ id: "ws-tavily-key", value: state.tavilyApiKey.text, disabled: disabled || !state.apiKeyWritable, placeholder: state.apiKeyConfigured ? t("apiKeySet") : t("apiKeyUnset"), onChange: (e) => actions.edit(TAVILY_API_KEY_FIELD, e.target.value) })),
1314
+ row("tavilyApiKeyEnv", t("apiKeyEnv"), t("apiKeyEnvHint"), textInput({ id: "ws-tavily-keyref", value: state.tavilyApiKeyEnv.text, disabled, onChange: (e) => actions.edit("tavilyApiKeyEnv", e.target.value) }))
1093
1315
  ) : null,
1094
1316
  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,
1095
1317
  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,
1096
- tavily ? row("baseURL", t("baseURL"), t("baseURLHint"), textInput({ id: "ws-tavily-base", value: state.baseURL.text, disabled, onChange: (e) => actions.edit("baseURL", e.target.value) })) : null,
1097
- deepseek ? pair(
1098
- row("model", t("model"), t("modelHint"), textInput({ id: "ws-model", value: state.model.text, disabled, onChange: (e) => actions.edit("model", e.target.value) })),
1099
- row("apiVersion", t("apiVersion"), t("apiVersionHint"), textInput({ id: "ws-apiversion", value: state.apiVersion.text, disabled, onChange: (e) => actions.edit("apiVersion", e.target.value) }))
1100
- ) : null,
1318
+ 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,
1101
1320
  deepseek ? pair(
1102
- row("maxTokens", t("maxTokens"), t("maxTokensHint"), numberInput({ id: "ws-maxtokens", value: state.maxTokens.text, disabled, onChange: (e) => actions.edit("maxTokens", e.target.value), className: state.maxTokens.invalid ? "dshws_input_invalid" : void 0 })),
1103
- row("maxUses", t("maxUses"), t("maxUsesHint"), numberInput({ id: "ws-maxuses", value: state.maxUses.text, disabled, onChange: (e) => actions.edit("maxUses", e.target.value), className: state.maxUses.invalid ? "dshws_input_invalid" : void 0 }))
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 }))
1104
1323
  ) : null,
1105
1324
  tavily ? pair(
1106
- row("searchDepth", t("searchDepth"), null, selectInput({ id: "ws-depth", value: state.searchDepth.text, disabled, onChange: (e) => actions.edit("searchDepth", e.target.value), children: [
1325
+ row("tavilySearchDepth", t("searchDepth"), null, selectInput({ id: "ws-depth", value: state.tavilySearchDepth.text, disabled, onChange: (e) => actions.edit("tavilySearchDepth", e.target.value), children: [
1107
1326
  react.createElement("option", { value: "basic", key: "basic" }, t("searchDepthBasic")),
1108
1327
  react.createElement("option", { value: "advanced", key: "advanced" }, t("searchDepthAdvanced"))
1109
1328
  ] })),
1110
- row("topic", t("topic"), null, selectInput({ id: "ws-topic", value: state.topic.text, disabled, onChange: (e) => actions.edit("topic", e.target.value), children: [
1329
+ row("tavilyTopic", t("topic"), null, selectInput({ id: "ws-topic", value: state.tavilyTopic.text, disabled, onChange: (e) => actions.edit("tavilyTopic", e.target.value), children: [
1111
1330
  react.createElement("option", { value: "general", key: "general" }, t("topicGeneral")),
1112
1331
  react.createElement("option", { value: "news", key: "news" }, t("topicNews"))
1113
1332
  ] }))
1114
1333
  ) : null,
1115
1334
  tavily ? pair(
1116
- row("includeAnswer", t("includeAnswer"), t("includeAnswerHint"), checkboxInput({ id: "ws-answer", checked: state.includeAnswer.text === "true", disabled, onChange: (e) => actions.edit("includeAnswer", e.target.checked ? "true" : "") })),
1335
+ row("tavilyIncludeAnswer", t("includeAnswer"), t("includeAnswerHint"), checkboxInput({ id: "ws-answer", checked: state.tavilyIncludeAnswer.text === "true", disabled, onChange: (e) => actions.edit("tavilyIncludeAnswer", e.target.checked ? "true" : "") })),
1117
1336
  maxResultsRow
1118
1337
  ) : null,
1119
1338
  brave ? pair(
1120
- row("country", t("country"), t("countryHint"), textInput({ id: "ws-country", value: state.country.text, disabled, placeholder: t("braveDefaultPlaceholder"), onChange: (e) => actions.edit("country", e.target.value) })),
1121
- row("searchLang", t("searchLang"), t("searchLangHint"), textInput({ id: "ws-lang", value: state.searchLang.text, disabled, placeholder: t("braveDefaultPlaceholder"), onChange: (e) => actions.edit("searchLang", e.target.value) }))
1339
+ row("braveCountry", t("country"), t("countryHint"), textInput({ id: "ws-country", value: state.braveCountry.text, disabled, placeholder: t("braveDefaultPlaceholder"), onChange: (e) => actions.edit("braveCountry", e.target.value) })),
1340
+ row("braveSearchLang", t("searchLang"), t("searchLangHint"), textInput({ id: "ws-lang", value: state.braveSearchLang.text, disabled, placeholder: t("braveDefaultPlaceholder"), onChange: (e) => actions.edit("braveSearchLang", e.target.value) }))
1122
1341
  ) : null,
1123
1342
  brave ? pair(
1124
- row("freshness", t("freshness"), null, selectInput({ id: "ws-freshness", value: state.freshness.text, disabled, onChange: (e) => actions.edit("freshness", e.target.value), children: [
1343
+ row("braveFreshness", t("freshness"), null, selectInput({ id: "ws-freshness", value: state.braveFreshness.text, disabled, onChange: (e) => actions.edit("braveFreshness", e.target.value), children: [
1125
1344
  react.createElement("option", { value: "", key: "any" }, t("freshnessAny")),
1126
1345
  react.createElement("option", { value: "pd", key: "pd" }, t("freshnessDay")),
1127
1346
  react.createElement("option", { value: "pw", key: "pw" }, t("freshnessWeek")),
@@ -1130,16 +1349,28 @@ window.__ModuleLoader__.load({
1130
1349
  ] })),
1131
1350
  maxResultsRow
1132
1351
  ) : null,
1133
- brave ? row("proxy", t("proxy"), null, textInput({ id: "ws-proxy", value: state.proxy.text, disabled, placeholder: t("proxyPlaceholder"), onChange: (e) => actions.edit("proxy", e.target.value) })) : null,
1352
+ brave ? row("braveProxy", t("proxy"), null, textInput({ id: "ws-proxy", value: state.braveProxy.text, disabled, placeholder: t("proxyPlaceholder"), onChange: (e) => actions.edit("braveProxy", e.target.value) })) : null,
1134
1353
  deepseek ? maxResultsRow : null,
1135
1354
  restMeta ? react.createElement("div", { className: "dshws_form" },
1136
1355
  restMeta.keyRequired ? pair(
1137
1356
  fieldRow(t("apiKey"), keyHint, secretInput({ id: "ws-" + restMeta.id + "-key", value: state[restMeta.keyField]?.text ?? "", disabled: disabled || !state.apiKeyWritable, placeholder: state.apiKeyConfigured ? t("apiKeySet") : t("apiKeyUnset"), onChange: (e) => actions.edit(restMeta.keyField, e.target.value) })),
1138
1357
  row(restMeta.keyEnvField, t("apiKeyEnv"), t("apiKeyEnvHint"), textInput({ id: "ws-" + restMeta.id + "-keyref", value: state[restMeta.keyEnvField]?.text ?? "", disabled, onChange: (e) => actions.edit(restMeta.keyEnvField, e.target.value) }))
1139
1358
  ) : null,
1359
+ provider === "scavio" ? pair(
1360
+ row("scavioCountry", t("country"), t("scavioCountryHint"), textInput({ id: "ws-scavio-country", value: state.scavioCountry.text, disabled, onChange: (e) => actions.edit("scavioCountry", e.target.value) })),
1361
+ row("scavioSearchLang", t("searchLang"), t("scavioSearchLangHint"), textInput({ id: "ws-scavio-lang", value: state.scavioSearchLang.text, disabled, onChange: (e) => actions.edit("scavioSearchLang", e.target.value) }))
1362
+ ) : null,
1140
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) })),
1141
1364
  maxResultsRow
1142
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,
1143
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" } },
1144
1375
  react.createElement("button", {
1145
1376
  type: "button",
@@ -1153,7 +1384,7 @@ window.__ModuleLoader__.load({
1153
1384
  react.createElement("button", {
1154
1385
  type: "button",
1155
1386
  className: "dshws_btn dshws_btn_primary",
1156
- disabled: state.saving || !state.writable,
1387
+ disabled: state.saving || !state.writable || state.invalid || (!state.dirty && !state.failed),
1157
1388
  onClick: (event) => {
1158
1389
  event.preventDefault();
1159
1390
  void actions.save();
@@ -1227,7 +1458,7 @@ window.__ModuleLoader__.load({
1227
1458
  // One controller for the settings section, created as soon as the Host
1228
1459
  // serves this namespace and torn down with it.
1229
1460
  ctx.effect(() => ctx.configForms.whileServed([NS], () => {
1230
- shared.controller = new SearchCardController(ctx.configForms.get(NS), ctx.remote);
1461
+ shared.controller = new SearchCardController(combinedScope(ctx.configForms), ctx.remote);
1231
1462
  const stopUsage = usageStore.start();
1232
1463
  const stopCredentials = ctx.remote.$on("credentials/reference-updated", (ref) => {
1233
1464
  shared.controller?.form.refreshCredential(ref);
@@ -1246,6 +1477,8 @@ window.__ModuleLoader__.load({
1246
1477
  return stopSection;
1247
1478
  });
1248
1479
  return () => {
1480
+ shared.controller?.unsubscribe();
1481
+ shared.controller?.form.dispose();
1249
1482
  shared.controller = null;
1250
1483
  stopUsage();
1251
1484
  stopCredentials();