dsh-web-search-plugin 0.4.1 → 0.5.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/CHANGELOG.md +59 -1
- package/README.md +267 -148
- package/README.zh.md +335 -0
- package/assets/icon.svg +13 -0
- package/cordis.patch.yml +4 -4
- package/lib/brave.js +6 -4
- package/lib/client.js +270 -140
- package/lib/config.js +29 -0
- package/lib/deepseek.js +77 -19
- package/lib/index.js +165 -85
- package/lib/providers.js +7 -7
- package/lib/rest.js +10 -5
- package/lib/shared.js +1 -1
- package/lib/tavily.js +11 -9
- package/lib/usage.js +53 -30
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +14 -8
package/lib/client.js
CHANGED
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
* writes once, credential written through the credentials domain) without
|
|
13
13
|
* depending on that package's internal `CardForm`.
|
|
14
14
|
*
|
|
15
|
+
* Adapted to DeepSeek Harness `0.2.x`: the card reads and writes its namespace
|
|
16
|
+
* through `ctx.configForms` (`ConfigForm`), replacing the removed
|
|
17
|
+
* `ctx.settingsScope` service.
|
|
18
|
+
*
|
|
15
19
|
* @module dsh-web-search-plugin/client
|
|
16
20
|
*/
|
|
17
21
|
window.__ModuleLoader__.load({
|
|
@@ -25,6 +29,34 @@ window.__ModuleLoader__.load({
|
|
|
25
29
|
|
|
26
30
|
/** Settings namespace of this plugin. */
|
|
27
31
|
const NS = "dsh-web-search-plugin";
|
|
32
|
+
// Mirrors lib/config.js; this client bundle has no host-module imports.
|
|
33
|
+
const SUPPLIER_CONFIG_ALIASES = {
|
|
34
|
+
tavilyApiKey: "apiKey",
|
|
35
|
+
tavilyApiKeyEnv: "apiKeyEnv",
|
|
36
|
+
tavilyBaseURL: "baseURL",
|
|
37
|
+
tavilyMode: "mode",
|
|
38
|
+
tavilySearchDepth: "searchDepth",
|
|
39
|
+
tavilyIncludeAnswer: "includeAnswer",
|
|
40
|
+
tavilyTopic: "topic",
|
|
41
|
+
deepseekModel: "model",
|
|
42
|
+
deepseekApiVersion: "apiVersion",
|
|
43
|
+
deepseekMaxTokens: "maxTokens",
|
|
44
|
+
deepseekMaxUses: "maxUses",
|
|
45
|
+
braveCountry: "country",
|
|
46
|
+
braveSearchLang: "searchLang",
|
|
47
|
+
braveFreshness: "freshness",
|
|
48
|
+
braveProxy: "proxy",
|
|
49
|
+
scavioCountry: "country",
|
|
50
|
+
scavioSearchLang: "searchLang"
|
|
51
|
+
};
|
|
52
|
+
const SUPPLIER_DEFAULTS = {
|
|
53
|
+
deepseekModel: "deepseek-flash", deepseekApiVersion: "2023-06-01", deepseekMaxTokens: 4096, deepseekMaxUses: 5,
|
|
54
|
+
tavilyMode: "keyless", tavilyApiKey: "", tavilyApiKeyEnv: "TAVILY_API_KEY", tavilyBaseURL: "",
|
|
55
|
+
tavilySearchDepth: "basic", tavilyIncludeAnswer: true, tavilyTopic: "general",
|
|
56
|
+
braveCountry: "", braveSearchLang: "", braveFreshness: "", braveProxy: "",
|
|
57
|
+
scavioCountry: "", scavioSearchLang: ""
|
|
58
|
+
};
|
|
59
|
+
const supplierValue = (values, field) => values?.[field] ?? values?.[SUPPLIER_CONFIG_ALIASES[field]] ?? SUPPLIER_DEFAULTS[field];
|
|
28
60
|
/** Built-in REST providers (mirrors `lib/providers.js`; browser bundle is self-contained). */
|
|
29
61
|
const BUILTIN_REST_PROVIDERS = [
|
|
30
62
|
{ id: "serper", name: "Serper", officialUrl: "https://serper.dev/", defaultBaseURL: "https://google.serper.dev", keyRequired: true, keyField: "serperApiKey", keyEnvField: "serperApiKeyEnv", baseURLField: "serperBaseURL" },
|
|
@@ -44,6 +76,42 @@ window.__ModuleLoader__.load({
|
|
|
44
76
|
for (const entry of BUILTIN_REST_PROVIDERS) if (entry.keyField === field) return entry;
|
|
45
77
|
return void 0;
|
|
46
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Where each provider issues its keys. The REST rows carry their own
|
|
81
|
+
* `officialUrl`; the three with dedicated branches are listed here so every
|
|
82
|
+
* engine gets the same "get an API key" affordance.
|
|
83
|
+
*/
|
|
84
|
+
const KEY_CONSOLE_URLS = {
|
|
85
|
+
"deepseek-official": "https://platform.deepseek.com/",
|
|
86
|
+
tavily: "https://app.tavily.com/",
|
|
87
|
+
brave: "https://api-dashboard.search.brave.com/"
|
|
88
|
+
};
|
|
89
|
+
/** The console URL for the active engine, when it issues keys. */
|
|
90
|
+
function keyConsoleUrl(provider, restMeta) {
|
|
91
|
+
if (restMeta !== void 0) return restMeta.keyRequired ? restMeta.officialUrl : "";
|
|
92
|
+
return KEY_CONSOLE_URLS[provider] ?? "";
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The "get an API key" link every key-issuing engine shows.
|
|
96
|
+
* @param t - the card's locale reader.
|
|
97
|
+
* @param provider - the active engine id.
|
|
98
|
+
* @param restMeta - the engine's metadata row, when it has one.
|
|
99
|
+
* @param keyed - Tavily only: whether it is in keyed mode.
|
|
100
|
+
* @returns the link element, or null when the engine issues no keys.
|
|
101
|
+
*/
|
|
102
|
+
function keyConsoleLink(t, provider, restMeta, keyed) {
|
|
103
|
+
// Tavily's keyless mode needs no key, so it gets no console link.
|
|
104
|
+
if (provider === "tavily" && keyed !== true) return null;
|
|
105
|
+
const url = keyConsoleUrl(provider, restMeta);
|
|
106
|
+
if (url === "") return null;
|
|
107
|
+
return react.createElement("a", {
|
|
108
|
+
href: url,
|
|
109
|
+
target: "_blank",
|
|
110
|
+
rel: "noopener noreferrer",
|
|
111
|
+
className: "dshws_field_hint",
|
|
112
|
+
style: { color: "var(--dsw-alias-brand-primary,#3b82f6)", textDecoration: "none", padding: "8px 0", display: "inline-block" }
|
|
113
|
+
}, t("getKey") + " ↗");
|
|
114
|
+
}
|
|
47
115
|
/** Credential reference Tavily keyed mode resolves when the section names none. */
|
|
48
116
|
const DEFAULT_TAVILY_KEY_REF = "TAVILY_API_KEY";
|
|
49
117
|
/** Credential reference Brave resolves when the section names none. */
|
|
@@ -51,7 +119,7 @@ window.__ModuleLoader__.load({
|
|
|
51
119
|
/** Credential reference DeepSeek resolves when the section names none. */
|
|
52
120
|
const DEFAULT_DEEPSEEK_KEY_REF = "DEEPSEEK_API_KEY";
|
|
53
121
|
/** Form field the Tavily write-only credential control stages under. */
|
|
54
|
-
const TAVILY_API_KEY_FIELD = "
|
|
122
|
+
const TAVILY_API_KEY_FIELD = "tavilyApiKey";
|
|
55
123
|
/** Form field the Brave write-only credential control stages under. */
|
|
56
124
|
const BRAVE_API_KEY_FIELD = "braveApiKey";
|
|
57
125
|
/** Form field the DeepSeek write-only credential control stages under. */
|
|
@@ -123,6 +191,8 @@ window.__ModuleLoader__.load({
|
|
|
123
191
|
topicNews: "News",
|
|
124
192
|
country: "Country",
|
|
125
193
|
countryHint: "ISO 2-letter code (e.g. cn).",
|
|
194
|
+
scavioCountryHint: "Country/region code accepted by Scavio (e.g. cn).",
|
|
195
|
+
scavioSearchLangHint: "Language code accepted by Scavio (e.g. zh-CN).",
|
|
126
196
|
searchLang: "Search language",
|
|
127
197
|
searchLangHint: "e.g. zh-hans or en.",
|
|
128
198
|
freshness: "Freshness",
|
|
@@ -139,8 +209,6 @@ window.__ModuleLoader__.load({
|
|
|
139
209
|
deepseekBaseURLHint: "Leave blank to use the DeepSeek Anthropic-compatible API default.",
|
|
140
210
|
model: "Model",
|
|
141
211
|
modelHint: "Anthropic-format model name for the search request.",
|
|
142
|
-
apiVersion: "API version",
|
|
143
|
-
apiVersionHint: "anthropic-version header value.",
|
|
144
212
|
maxTokens: "Max tokens",
|
|
145
213
|
maxTokensHint: "Upper bound on generated tokens for the search request.",
|
|
146
214
|
maxUses: "Max uses",
|
|
@@ -162,6 +230,7 @@ window.__ModuleLoader__.load({
|
|
|
162
230
|
invalidToast: "Fix the highlighted fields before saving.",
|
|
163
231
|
readOnly: "This deployment stores settings read-only.",
|
|
164
232
|
invalidNumber: "Enter a whole number of at least 1, or leave blank for the default.",
|
|
233
|
+
invalidCredentialRef: "Use an environment variable name: letters, digits, and underscores; the first character must be a letter or underscore.",
|
|
165
234
|
quotaTitle: "Quota",
|
|
166
235
|
quotaPlan: "Plan {plan}",
|
|
167
236
|
quotaUsed: "Used {used} / {limit}",
|
|
@@ -219,6 +288,8 @@ window.__ModuleLoader__.load({
|
|
|
219
288
|
topicNews: "新闻",
|
|
220
289
|
country: "国家/地区",
|
|
221
290
|
countryHint: "ISO 两位码(如 cn)。",
|
|
291
|
+
scavioCountryHint: "Scavio 支持的国家/地区码(如 cn)。",
|
|
292
|
+
scavioSearchLangHint: "Scavio 支持的语言码(如 zh-CN)。",
|
|
222
293
|
searchLang: "搜索语言",
|
|
223
294
|
searchLangHint: "如 zh-hans、en。",
|
|
224
295
|
freshness: "时效",
|
|
@@ -235,8 +306,6 @@ window.__ModuleLoader__.load({
|
|
|
235
306
|
deepseekBaseURLHint: "留空则使用 DeepSeek Anthropic 兼容 API 默认地址。",
|
|
236
307
|
model: "模型",
|
|
237
308
|
modelHint: "搜索请求使用的 Anthropic 格式模型名。",
|
|
238
|
-
apiVersion: "API 版本",
|
|
239
|
-
apiVersionHint: "anthropic-version 请求头值。",
|
|
240
309
|
maxTokens: "最大 token",
|
|
241
310
|
maxTokensHint: "搜索请求生成 token 的上限。",
|
|
242
311
|
maxUses: "最大调用次数",
|
|
@@ -258,6 +327,7 @@ window.__ModuleLoader__.load({
|
|
|
258
327
|
invalidToast: "请先修正标红的字段再保存。",
|
|
259
328
|
readOnly: "本部署的设置为只读。",
|
|
260
329
|
invalidNumber: "请输入不小于 1 的整数;留空表示使用默认值。",
|
|
330
|
+
invalidCredentialRef: "请使用环境变量名:仅含字母、数字和下划线,且以字母或下划线开头。",
|
|
261
331
|
quotaTitle: "额度",
|
|
262
332
|
quotaPlan: "计划 {plan}",
|
|
263
333
|
quotaUsed: "已用 {used} / {limit}",
|
|
@@ -311,6 +381,17 @@ window.__ModuleLoader__.load({
|
|
|
311
381
|
}
|
|
312
382
|
};
|
|
313
383
|
}
|
|
384
|
+
function credentialField(field) {
|
|
385
|
+
return {
|
|
386
|
+
field,
|
|
387
|
+
format: (value) => typeof value === "string" ? value : "",
|
|
388
|
+
parse: (text) => {
|
|
389
|
+
const trimmed = text.trim();
|
|
390
|
+
if (trimmed === "") return { kind: "clear" };
|
|
391
|
+
return /^[A-Za-z_][A-Za-z0-9_]*$/u.test(trimmed) ? { kind: "set", value: trimmed } : void 0;
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
}
|
|
314
395
|
/** A choice field spec: staged as its raw string. */
|
|
315
396
|
function choiceField(field) {
|
|
316
397
|
return {
|
|
@@ -330,7 +411,7 @@ window.__ModuleLoader__.load({
|
|
|
330
411
|
|
|
331
412
|
/**
|
|
332
413
|
* Staged form over the `dsh-web-search-plugin` settings namespace.
|
|
333
|
-
* Write-only credential fields
|
|
414
|
+
* Write-only credential fields have no section
|
|
334
415
|
* spec and are written through the credentials domain.
|
|
335
416
|
*/
|
|
336
417
|
var SearchCardForm = class {
|
|
@@ -339,35 +420,36 @@ window.__ModuleLoader__.load({
|
|
|
339
420
|
this.remote = remote;
|
|
340
421
|
this.specs = new Map([
|
|
341
422
|
choiceField("provider"),
|
|
342
|
-
choiceField("
|
|
423
|
+
choiceField("tavilyMode"),
|
|
343
424
|
numberField("maxResults", { min: 1, max: MAX_RESULTS_CAP }),
|
|
344
|
-
|
|
345
|
-
textField("
|
|
346
|
-
choiceField("
|
|
347
|
-
choiceField("
|
|
348
|
-
booleanField("
|
|
349
|
-
|
|
425
|
+
credentialField("tavilyApiKeyEnv"),
|
|
426
|
+
textField("tavilyBaseURL"),
|
|
427
|
+
choiceField("tavilySearchDepth"),
|
|
428
|
+
choiceField("tavilyTopic"),
|
|
429
|
+
booleanField("tavilyIncludeAnswer"),
|
|
430
|
+
credentialField("braveApiKeyEnv"),
|
|
350
431
|
textField("braveBaseURL"),
|
|
351
|
-
textField("
|
|
352
|
-
textField("
|
|
353
|
-
choiceField("
|
|
354
|
-
textField("
|
|
355
|
-
|
|
432
|
+
textField("braveCountry"),
|
|
433
|
+
textField("braveSearchLang"),
|
|
434
|
+
choiceField("braveFreshness"),
|
|
435
|
+
textField("braveProxy"),
|
|
436
|
+
credentialField("deepseekApiKeyEnv"),
|
|
356
437
|
textField("deepseekBaseURL"),
|
|
357
|
-
textField("
|
|
358
|
-
|
|
359
|
-
numberField("
|
|
360
|
-
|
|
361
|
-
textField("serperApiKeyEnv"),
|
|
438
|
+
textField("deepseekModel"),
|
|
439
|
+
numberField("deepseekMaxTokens", { min: 1 }),
|
|
440
|
+
numberField("deepseekMaxUses", { min: 1 }),
|
|
441
|
+
credentialField("serperApiKeyEnv"),
|
|
362
442
|
textField("serperBaseURL"),
|
|
363
|
-
|
|
443
|
+
credentialField("serpapiApiKeyEnv"),
|
|
364
444
|
textField("serpapiBaseURL"),
|
|
365
|
-
|
|
445
|
+
credentialField("exaApiKeyEnv"),
|
|
366
446
|
textField("exaBaseURL"),
|
|
367
447
|
textField("searxngBaseURL"),
|
|
368
|
-
|
|
448
|
+
credentialField("scavioApiKeyEnv"),
|
|
369
449
|
textField("scavioBaseURL"),
|
|
370
|
-
textField("
|
|
450
|
+
textField("scavioCountry"),
|
|
451
|
+
textField("scavioSearchLang"),
|
|
452
|
+
credentialField("firecrawlApiKeyEnv"),
|
|
371
453
|
textField("firecrawlBaseURL")
|
|
372
454
|
].map((spec) => [spec.field, spec]));
|
|
373
455
|
this.staged = new Map();
|
|
@@ -379,7 +461,9 @@ window.__ModuleLoader__.load({
|
|
|
379
461
|
this.listeners = new Set();
|
|
380
462
|
const draft = readDraft();
|
|
381
463
|
if (draft?.staged) {
|
|
382
|
-
for (const [
|
|
464
|
+
for (const [oldField, edit] of Object.entries(draft.staged)) {
|
|
465
|
+
const field = Object.entries(SUPPLIER_CONFIG_ALIASES).find(([name, legacy]) => !name.startsWith("scavio") && legacy === oldField)?.[0] ?? oldField;
|
|
466
|
+
if (field !== oldField && Object.hasOwn(draft.staged, field)) continue;
|
|
383
467
|
if (!this.specs.has(field) || edit === null || typeof edit !== "object") continue;
|
|
384
468
|
this.staged.set(field, { text: String(edit.text ?? ""), clear: edit.clear === true });
|
|
385
469
|
}
|
|
@@ -404,7 +488,7 @@ window.__ModuleLoader__.load({
|
|
|
404
488
|
available: snapshot.status === "ready",
|
|
405
489
|
writable: snapshot.writable,
|
|
406
490
|
dirty: plan.length > 0,
|
|
407
|
-
invalid: plan.some((item) => item.
|
|
491
|
+
invalid: plan.some((item) => item.invalid === true),
|
|
408
492
|
saving: this.saving,
|
|
409
493
|
failed: this.failed,
|
|
410
494
|
toastKey: this.toastKey
|
|
@@ -435,19 +519,19 @@ window.__ModuleLoader__.load({
|
|
|
435
519
|
for (const [field, staged] of this.staged) {
|
|
436
520
|
if (SECRET_FIELDS.has(field)) {
|
|
437
521
|
const value = staged.text.trim();
|
|
438
|
-
if (value !== "") plan.push({ field,
|
|
522
|
+
if (value !== "") plan.push({ field, credential: () => this.writeKey(field, value) });
|
|
439
523
|
continue;
|
|
440
524
|
}
|
|
441
525
|
const spec = this.specs.get(field);
|
|
442
526
|
if (staged.clear) {
|
|
443
|
-
if (this.stored(field)) plan.push({ field,
|
|
527
|
+
if (this.stored(field)) plan.push({ field, op: { op: "unset", path: [field] } });
|
|
444
528
|
continue;
|
|
445
529
|
}
|
|
446
530
|
if (staged.text === spec.format(this.sectionValue(field))) continue;
|
|
447
531
|
const write = spec.parse(staged.text);
|
|
448
|
-
if (write === void 0) plan.push({ field,
|
|
449
|
-
else if (write.kind === "clear") plan.push({ field,
|
|
450
|
-
else plan.push({ field,
|
|
532
|
+
if (write === void 0) plan.push({ field, invalid: true });
|
|
533
|
+
else if (write.kind === "clear") plan.push({ field, op: { op: "unset", path: [field] } });
|
|
534
|
+
else plan.push({ field, op: { op: "set", path: [field], value: write.value } });
|
|
451
535
|
}
|
|
452
536
|
return plan;
|
|
453
537
|
}
|
|
@@ -463,22 +547,40 @@ window.__ModuleLoader__.load({
|
|
|
463
547
|
}
|
|
464
548
|
async save() {
|
|
465
549
|
const plan = this.plan();
|
|
466
|
-
const writes = plan.flatMap((item) => item.run === void 0 ? [] : [item.run]);
|
|
467
550
|
if (this.saving) return;
|
|
468
551
|
if (plan.length === 0) {
|
|
469
552
|
this.showToast("nothing");
|
|
470
553
|
return;
|
|
471
554
|
}
|
|
472
|
-
if (
|
|
555
|
+
if (plan.some((item) => item.invalid === true)) {
|
|
473
556
|
this.showToast("invalid");
|
|
474
557
|
return;
|
|
475
558
|
}
|
|
559
|
+
const revision = this.snapshotOf().revision;
|
|
560
|
+
const credentials = plan.filter((item) => item.credential !== void 0);
|
|
561
|
+
const ops = plan.flatMap((item) => item.op === void 0 ? [] : [item.op]);
|
|
562
|
+
for (const item of plan) {
|
|
563
|
+
const legacy = SUPPLIER_CONFIG_ALIASES[item.field];
|
|
564
|
+
if (item.op?.op !== "unset" || legacy === void 0 || !Object.hasOwn(this.userLayer() ?? {}, legacy)) continue;
|
|
565
|
+
for (const [other, alias] of Object.entries(SUPPLIER_CONFIG_ALIASES)) {
|
|
566
|
+
if (other === item.field || alias !== legacy || plan.some((entry) => entry.field === other) || this.snapshotOf().value?.[other] != null) continue;
|
|
567
|
+
ops.push({ op: "set", path: [other], value: this.sectionValue(other) });
|
|
568
|
+
}
|
|
569
|
+
if (!ops.some((op) => op.op === "unset" && op.path[0] === legacy)) ops.push({ op: "unset", path: [legacy] });
|
|
570
|
+
}
|
|
571
|
+
for (const item of credentials) {
|
|
572
|
+
// Override even an inherited literal key; unsetting could expose it again.
|
|
573
|
+
if (!ops.some((op) => op.path[0] === item.field)) ops.push({ op: "set", path: [item.field], value: "" });
|
|
574
|
+
}
|
|
476
575
|
this.saving = true;
|
|
477
576
|
this.failed = false;
|
|
478
577
|
this.publish();
|
|
479
578
|
let landed = true;
|
|
480
579
|
try {
|
|
481
|
-
for (const
|
|
580
|
+
for (const item of credentials) {
|
|
581
|
+
if (!await item.credential()) { landed = false; break; }
|
|
582
|
+
}
|
|
583
|
+
if (landed && ops.length > 0) landed = await this.scope.mutate(ops, revision) === true;
|
|
482
584
|
} catch (_saveFailure) {
|
|
483
585
|
landed = false;
|
|
484
586
|
}
|
|
@@ -486,19 +588,23 @@ window.__ModuleLoader__.load({
|
|
|
486
588
|
this.saving = false;
|
|
487
589
|
this.failed = !landed;
|
|
488
590
|
this.showToast(landed ? "saved" : "failed");
|
|
591
|
+
if (landed) void usageStore.sync();
|
|
489
592
|
}
|
|
490
593
|
actions() {
|
|
491
594
|
return {
|
|
492
595
|
edit: (field, text) => {
|
|
596
|
+
if (this.saving) return;
|
|
493
597
|
this.stage(field, { text, clear: false });
|
|
494
598
|
},
|
|
495
599
|
resetField: (field) => {
|
|
600
|
+
if (this.saving) return;
|
|
496
601
|
this.stage(field, { text: this.baseText(field), clear: true });
|
|
497
602
|
},
|
|
498
603
|
save: () => {
|
|
499
604
|
this.save();
|
|
500
605
|
},
|
|
501
606
|
discard: () => {
|
|
607
|
+
if (this.saving) return;
|
|
502
608
|
if (this.staged.size === 0 && !this.failed) return;
|
|
503
609
|
this.staged.clear();
|
|
504
610
|
this.failed = false;
|
|
@@ -506,43 +612,27 @@ window.__ModuleLoader__.load({
|
|
|
506
612
|
}
|
|
507
613
|
};
|
|
508
614
|
}
|
|
509
|
-
async clear(field) {
|
|
510
|
-
try {
|
|
511
|
-
await this.scope.unset(field);
|
|
512
|
-
return true;
|
|
513
|
-
} catch (_clearFailure) {
|
|
514
|
-
return false;
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
async store(field, value) {
|
|
518
|
-
try {
|
|
519
|
-
await this.scope.set(field, value);
|
|
520
|
-
return true;
|
|
521
|
-
} catch (_storeFailure) {
|
|
522
|
-
return false;
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
615
|
stage(field, edit) {
|
|
526
616
|
this.staged.set(field, edit);
|
|
527
617
|
this.failed = false;
|
|
528
618
|
this.publish();
|
|
529
|
-
if (field === "provider" || field === "
|
|
619
|
+
if (field === "provider" || field === "tavilyApiKeyEnv" || field === "braveApiKeyEnv" || field === "deepseekApiKeyEnv" || BUILTIN_REST_PROVIDERS.some((entry) => entry.keyEnvField === field)) this.readCredential();
|
|
530
620
|
}
|
|
531
621
|
snapshotOf() {
|
|
532
622
|
return this.scope.getSnapshot();
|
|
533
623
|
}
|
|
534
624
|
sectionValue(field) {
|
|
535
|
-
return this.snapshotOf().value
|
|
625
|
+
return supplierValue(this.snapshotOf().value, field);
|
|
536
626
|
}
|
|
537
627
|
baseText(field) {
|
|
538
|
-
return this.specs.get(field).format(this.snapshotOf().base
|
|
628
|
+
return this.specs.get(field).format(supplierValue(this.snapshotOf().base, field));
|
|
539
629
|
}
|
|
540
630
|
userLayer() {
|
|
541
631
|
return this.snapshotOf().user;
|
|
542
632
|
}
|
|
543
633
|
stored(field) {
|
|
544
634
|
const user = this.userLayer();
|
|
545
|
-
return user !== void 0 && Object.hasOwn(user, field);
|
|
635
|
+
return user !== void 0 && (Object.hasOwn(user, field) || Object.hasOwn(user, SUPPLIER_CONFIG_ALIASES[field]));
|
|
546
636
|
}
|
|
547
637
|
publish() {
|
|
548
638
|
writeDraft(this);
|
|
@@ -556,17 +646,21 @@ window.__ModuleLoader__.load({
|
|
|
556
646
|
if (declared === "tavily" || declared === "brave" || declared === "deepseek-official" || builtinRest(declared) !== void 0) return declared;
|
|
557
647
|
return "deepseek-official";
|
|
558
648
|
}
|
|
649
|
+
credentialRef(field, fallback) {
|
|
650
|
+
const staged = this.staged.get(field);
|
|
651
|
+
const declared = staged === void 0
|
|
652
|
+
? this.sectionValue(field)
|
|
653
|
+
: staged.clear ? supplierValue(this.snapshotOf().base, field) : staged.text.trim();
|
|
654
|
+
return typeof declared === "string" && declared.length > 0 ? declared : fallback;
|
|
655
|
+
}
|
|
559
656
|
tavilyRef() {
|
|
560
|
-
|
|
561
|
-
return declared !== void 0 && declared.length > 0 ? declared : DEFAULT_TAVILY_KEY_REF;
|
|
657
|
+
return this.credentialRef("tavilyApiKeyEnv", DEFAULT_TAVILY_KEY_REF);
|
|
562
658
|
}
|
|
563
659
|
braveRef() {
|
|
564
|
-
|
|
565
|
-
return declared !== void 0 && declared.length > 0 ? declared : DEFAULT_BRAVE_KEY_REF;
|
|
660
|
+
return this.credentialRef("braveApiKeyEnv", DEFAULT_BRAVE_KEY_REF);
|
|
566
661
|
}
|
|
567
662
|
deepseekRef() {
|
|
568
|
-
|
|
569
|
-
return declared !== void 0 && declared.length > 0 ? declared : DEFAULT_DEEPSEEK_KEY_REF;
|
|
663
|
+
return this.credentialRef("deepseekApiKeyEnv", DEFAULT_DEEPSEEK_KEY_REF);
|
|
570
664
|
}
|
|
571
665
|
/** The credential reference the currently visible engine uses. */
|
|
572
666
|
refOf() {
|
|
@@ -579,9 +673,8 @@ window.__ModuleLoader__.load({
|
|
|
579
673
|
}
|
|
580
674
|
/** Credential reference for a built-in REST provider's key env field. */
|
|
581
675
|
restKeyRef(rest) {
|
|
582
|
-
const
|
|
583
|
-
|
|
584
|
-
return rest.id === "serper" ? "SERPER_API_KEY" : rest.id === "serpapi" ? "SERPAPI_API_KEY" : rest.id === "exa" ? "EXA_API_KEY" : rest.id === "scavio" ? "SCAVIO_API_KEY" : "FIRECRAWL_API_KEY";
|
|
676
|
+
const fallback = rest.id === "serper" ? "SERPER_API_KEY" : rest.id === "serpapi" ? "SERPAPI_API_KEY" : rest.id === "exa" ? "EXA_API_KEY" : rest.id === "scavio" ? "SCAVIO_API_KEY" : "FIRECRAWL_API_KEY";
|
|
677
|
+
return this.credentialRef(rest.keyEnvField, fallback);
|
|
585
678
|
}
|
|
586
679
|
async readCredential() {
|
|
587
680
|
const ref = this.refOf();
|
|
@@ -621,9 +714,11 @@ window.__ModuleLoader__.load({
|
|
|
621
714
|
try {
|
|
622
715
|
const response = await this.remote.credentials.set(ref, value);
|
|
623
716
|
if (!response.ok) return false;
|
|
624
|
-
} catch (_credentialWriteFailure) {
|
|
717
|
+
} catch (_credentialWriteFailure) {
|
|
718
|
+
return false;
|
|
719
|
+
}
|
|
625
720
|
await this.readCredential();
|
|
626
|
-
return
|
|
721
|
+
return true;
|
|
627
722
|
}
|
|
628
723
|
};
|
|
629
724
|
|
|
@@ -642,28 +737,27 @@ window.__ModuleLoader__.load({
|
|
|
642
737
|
return {
|
|
643
738
|
...this.form.shell(),
|
|
644
739
|
provider: this.form.field("provider"),
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
740
|
+
tavilyMode: this.form.field("tavilyMode"),
|
|
741
|
+
tavilyApiKey: this.form.field(TAVILY_API_KEY_FIELD),
|
|
742
|
+
tavilyApiKeyEnv: this.form.field("tavilyApiKeyEnv"),
|
|
743
|
+
tavilyBaseURL: this.form.field("tavilyBaseURL"),
|
|
649
744
|
maxResults: this.form.field("maxResults"),
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
745
|
+
tavilySearchDepth: this.form.field("tavilySearchDepth"),
|
|
746
|
+
tavilyIncludeAnswer: this.form.field("tavilyIncludeAnswer"),
|
|
747
|
+
tavilyTopic: this.form.field("tavilyTopic"),
|
|
653
748
|
braveApiKey: this.form.field(BRAVE_API_KEY_FIELD),
|
|
654
749
|
braveApiKeyEnv: this.form.field("braveApiKeyEnv"),
|
|
655
750
|
braveBaseURL: this.form.field("braveBaseURL"),
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
751
|
+
braveCountry: this.form.field("braveCountry"),
|
|
752
|
+
braveSearchLang: this.form.field("braveSearchLang"),
|
|
753
|
+
braveFreshness: this.form.field("braveFreshness"),
|
|
754
|
+
braveProxy: this.form.field("braveProxy"),
|
|
660
755
|
deepseekApiKey: this.form.field(DEEPSEEK_API_KEY_FIELD),
|
|
661
756
|
deepseekApiKeyEnv: this.form.field("deepseekApiKeyEnv"),
|
|
662
757
|
deepseekBaseURL: this.form.field("deepseekBaseURL"),
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
maxUses: this.form.field("maxUses"),
|
|
758
|
+
deepseekModel: this.form.field("deepseekModel"),
|
|
759
|
+
deepseekMaxTokens: this.form.field("deepseekMaxTokens"),
|
|
760
|
+
deepseekMaxUses: this.form.field("deepseekMaxUses"),
|
|
667
761
|
serperApiKey: this.form.field("serperApiKey"),
|
|
668
762
|
serperApiKeyEnv: this.form.field("serperApiKeyEnv"),
|
|
669
763
|
serperBaseURL: this.form.field("serperBaseURL"),
|
|
@@ -677,14 +771,16 @@ window.__ModuleLoader__.load({
|
|
|
677
771
|
scavioApiKey: this.form.field("scavioApiKey"),
|
|
678
772
|
scavioApiKeyEnv: this.form.field("scavioApiKeyEnv"),
|
|
679
773
|
scavioBaseURL: this.form.field("scavioBaseURL"),
|
|
774
|
+
scavioCountry: this.form.field("scavioCountry"),
|
|
775
|
+
scavioSearchLang: this.form.field("scavioSearchLang"),
|
|
680
776
|
firecrawlApiKey: this.form.field("firecrawlApiKey"),
|
|
681
777
|
firecrawlApiKeyEnv: this.form.field("firecrawlApiKeyEnv"),
|
|
682
778
|
firecrawlBaseURL: this.form.field("firecrawlBaseURL"),
|
|
683
779
|
apiKeyConfigured: this.form.credential.configured,
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
780
|
+
apiKeyWritable: this.form.credential.writable,
|
|
781
|
+
toastKey: this.form.toastKey
|
|
782
|
+
};
|
|
783
|
+
}
|
|
688
784
|
inject() {
|
|
689
785
|
return {
|
|
690
786
|
hooks: { pluginSearchCard: this.store },
|
|
@@ -701,7 +797,7 @@ window.__ModuleLoader__.load({
|
|
|
701
797
|
react.createElement("span", { className: "dshws_badge" }, meta.t("overridden")),
|
|
702
798
|
react.createElement("button", { type: "button", className: "dshws_reset", disabled: meta.disabled === true, onClick: meta.onReset }, meta.t("reset"))) : null),
|
|
703
799
|
children,
|
|
704
|
-
meta?.invalid ? react.createElement("p", { className: "dshws_field_error" }, meta.t("invalidNumber")) : hint ? react.createElement("p", { className: "dshws_field_hint" }, hint) : null);
|
|
800
|
+
meta?.invalid ? react.createElement("p", { className: "dshws_field_error" }, meta.t(meta.errorKey ?? "invalidNumber")) : hint ? react.createElement("p", { className: "dshws_field_hint" }, hint) : null);
|
|
705
801
|
const pair = (left, right) => {
|
|
706
802
|
if (!left && !right) return null;
|
|
707
803
|
if (!left) return right;
|
|
@@ -838,8 +934,9 @@ window.__ModuleLoader__.load({
|
|
|
838
934
|
return snap;
|
|
839
935
|
},
|
|
840
936
|
refresh: () => load(true),
|
|
937
|
+
sync: () => load(false),
|
|
841
938
|
start() {
|
|
842
|
-
void load(
|
|
939
|
+
void load(false);
|
|
843
940
|
const timer = setInterval(() => {
|
|
844
941
|
void load(false);
|
|
845
942
|
}, USAGE_POLL_MS);
|
|
@@ -970,13 +1067,13 @@ window.__ModuleLoader__.load({
|
|
|
970
1067
|
function WebSearchCard(props) {
|
|
971
1068
|
const { t, state, actions } = props;
|
|
972
1069
|
if (!state.available) return null;
|
|
973
|
-
const disabled = !state.writable;
|
|
1070
|
+
const disabled = !state.writable || state.saving;
|
|
974
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";
|
|
975
1072
|
const brave = provider === "brave";
|
|
976
1073
|
const deepseek = provider === "deepseek-official";
|
|
977
1074
|
const tavily = provider === "tavily";
|
|
978
1075
|
const restMeta = builtinRest(provider);
|
|
979
|
-
const keyed = state.
|
|
1076
|
+
const keyed = state.tavilyMode.text === "keyed";
|
|
980
1077
|
const keyHint = state.apiKeyConfigured ? t("apiKeyHint") : t("apiKeyHint") + " " + t("apiKeyUnavailableHint");
|
|
981
1078
|
const toastText = toastCopy(t, state.toastKey);
|
|
982
1079
|
const toastTone = state.toastKey === "failed" || state.toastKey === "invalid" ? "error" : state.toastKey === "nothing" ? "info" : "success";
|
|
@@ -984,6 +1081,7 @@ window.__ModuleLoader__.load({
|
|
|
984
1081
|
t,
|
|
985
1082
|
overridden: state[field]?.overridden === true,
|
|
986
1083
|
invalid: state[field]?.invalid === true,
|
|
1084
|
+
errorKey: field.endsWith("ApiKeyEnv") || field === "apiKeyEnv" ? "invalidCredentialRef" : "invalidNumber",
|
|
987
1085
|
disabled,
|
|
988
1086
|
onReset: () => actions.resetField(field)
|
|
989
1087
|
});
|
|
@@ -1008,62 +1106,60 @@ window.__ModuleLoader__.load({
|
|
|
1008
1106
|
!state.writable ? react.createElement("p", { className: "dshws_field_hint", style: { padding: "8px 0 0" } }, t("readOnly")) : null,
|
|
1009
1107
|
pair(
|
|
1010
1108
|
row("provider", t("provider"), null, selectInput({ id: "ws-provider", value: provider, disabled, onChange: (e) => actions.edit("provider", e.target.value), children: [
|
|
1109
|
+
react.createElement("option", { value: "deepseek-official", key: "deepseek-official" }, t("providerDeepseek")),
|
|
1011
1110
|
react.createElement("option", { value: "tavily", key: "tavily" }, t("providerTavily")),
|
|
1012
1111
|
react.createElement("option", { value: "brave", key: "brave" }, t("providerBrave")),
|
|
1013
|
-
react.createElement("option", { value: "deepseek-official", key: "deepseek-official" }, t("providerDeepseek")),
|
|
1014
1112
|
...BUILTIN_REST_PROVIDERS.map((entry) => react.createElement("option", { value: entry.id, key: entry.id }, entry.name)),
|
|
1015
1113
|
react.createElement("option", { value: "__ddg__", key: "ddg", disabled: true }, t("ddgDisabled"))
|
|
1016
1114
|
] }),
|
|
1017
1115
|
react.createElement("p", { className: "dshws_field_hint", style: { padding: "4px 0 0" } }, t("ddgHint"))),
|
|
1018
|
-
tavily ? row("
|
|
1116
|
+
tavily ? row("tavilyMode", t("mode"), null, selectInput({ id: "ws-mode", value: state.tavilyMode.text, disabled, onChange: (e) => actions.edit("tavilyMode", e.target.value), children: [
|
|
1019
1117
|
react.createElement("option", { value: "keyless", key: "keyless" }, t("modeKeyless")),
|
|
1020
1118
|
react.createElement("option", { value: "keyed", key: "keyed" }, t("modeKeyed"))
|
|
1021
1119
|
] })) : null
|
|
1022
1120
|
),
|
|
1023
1121
|
react.createElement(QuotaCard, { t, provider, keyed }),
|
|
1122
|
+
keyConsoleLink(t, provider, restMeta, keyed),
|
|
1024
1123
|
deepseek ? pair(
|
|
1025
|
-
fieldRow(t("apiKey"), keyHint, secretInput({ id: "ws-deepseek-key", value: state.deepseekApiKey.text, disabled: !state.apiKeyWritable, placeholder: state.apiKeyConfigured ? t("apiKeySet") : t("apiKeyUnset"), onChange: (e) => actions.edit(DEEPSEEK_API_KEY_FIELD, e.target.value) })),
|
|
1124
|
+
fieldRow(t("apiKey"), keyHint, secretInput({ id: "ws-deepseek-key", value: state.deepseekApiKey.text, disabled: disabled || !state.apiKeyWritable, placeholder: state.apiKeyConfigured ? t("apiKeySet") : t("apiKeyUnset"), onChange: (e) => actions.edit(DEEPSEEK_API_KEY_FIELD, e.target.value) })),
|
|
1026
1125
|
row("deepseekApiKeyEnv", t("deepseekApiKeyEnv"), t("deepseekApiKeyEnvHint"), textInput({ id: "ws-deepseek-keyref", value: state.deepseekApiKeyEnv.text, disabled, onChange: (e) => actions.edit("deepseekApiKeyEnv", e.target.value) }))
|
|
1027
1126
|
) : null,
|
|
1028
1127
|
brave ? pair(
|
|
1029
|
-
fieldRow(t("apiKey"), keyHint, secretInput({ id: "ws-brave-key", value: state.braveApiKey.text, disabled: !state.apiKeyWritable, placeholder: state.apiKeyConfigured ? t("apiKeySet") : t("apiKeyUnset"), onChange: (e) => actions.edit(BRAVE_API_KEY_FIELD, e.target.value) })),
|
|
1128
|
+
fieldRow(t("apiKey"), keyHint, secretInput({ id: "ws-brave-key", value: state.braveApiKey.text, disabled: disabled || !state.apiKeyWritable, placeholder: state.apiKeyConfigured ? t("apiKeySet") : t("apiKeyUnset"), onChange: (e) => actions.edit(BRAVE_API_KEY_FIELD, e.target.value) })),
|
|
1030
1129
|
row("braveApiKeyEnv", t("braveApiKeyEnv"), t("braveApiKeyEnvHint"), textInput({ id: "ws-brave-keyref", value: state.braveApiKeyEnv.text, disabled, onChange: (e) => actions.edit("braveApiKeyEnv", e.target.value) }))
|
|
1031
1130
|
) : null,
|
|
1032
1131
|
(tavily && keyed) ? pair(
|
|
1033
|
-
fieldRow(t("apiKey"), keyHint, secretInput({ id: "ws-tavily-key", value: state.
|
|
1034
|
-
row("
|
|
1132
|
+
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) })),
|
|
1133
|
+
row("tavilyApiKeyEnv", t("apiKeyEnv"), t("apiKeyEnvHint"), textInput({ id: "ws-tavily-keyref", value: state.tavilyApiKeyEnv.text, disabled, onChange: (e) => actions.edit("tavilyApiKeyEnv", e.target.value) }))
|
|
1035
1134
|
) : null,
|
|
1036
1135
|
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,
|
|
1037
1136
|
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,
|
|
1038
|
-
tavily ? row("
|
|
1137
|
+
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,
|
|
1138
|
+
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,
|
|
1039
1139
|
deepseek ? pair(
|
|
1040
|
-
row("
|
|
1041
|
-
row("
|
|
1042
|
-
) : null,
|
|
1043
|
-
deepseek ? pair(
|
|
1044
|
-
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 })),
|
|
1045
|
-
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 }))
|
|
1140
|
+
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 })),
|
|
1141
|
+
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 }))
|
|
1046
1142
|
) : null,
|
|
1047
1143
|
tavily ? pair(
|
|
1048
|
-
row("
|
|
1144
|
+
row("tavilySearchDepth", t("searchDepth"), null, selectInput({ id: "ws-depth", value: state.tavilySearchDepth.text, disabled, onChange: (e) => actions.edit("tavilySearchDepth", e.target.value), children: [
|
|
1049
1145
|
react.createElement("option", { value: "basic", key: "basic" }, t("searchDepthBasic")),
|
|
1050
1146
|
react.createElement("option", { value: "advanced", key: "advanced" }, t("searchDepthAdvanced"))
|
|
1051
1147
|
] })),
|
|
1052
|
-
row("
|
|
1148
|
+
row("tavilyTopic", t("topic"), null, selectInput({ id: "ws-topic", value: state.tavilyTopic.text, disabled, onChange: (e) => actions.edit("tavilyTopic", e.target.value), children: [
|
|
1053
1149
|
react.createElement("option", { value: "general", key: "general" }, t("topicGeneral")),
|
|
1054
1150
|
react.createElement("option", { value: "news", key: "news" }, t("topicNews"))
|
|
1055
1151
|
] }))
|
|
1056
1152
|
) : null,
|
|
1057
1153
|
tavily ? pair(
|
|
1058
|
-
row("
|
|
1154
|
+
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" : "") })),
|
|
1059
1155
|
maxResultsRow
|
|
1060
1156
|
) : null,
|
|
1061
1157
|
brave ? pair(
|
|
1062
|
-
row("
|
|
1063
|
-
row("
|
|
1158
|
+
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) })),
|
|
1159
|
+
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) }))
|
|
1064
1160
|
) : null,
|
|
1065
1161
|
brave ? pair(
|
|
1066
|
-
row("
|
|
1162
|
+
row("braveFreshness", t("freshness"), null, selectInput({ id: "ws-freshness", value: state.braveFreshness.text, disabled, onChange: (e) => actions.edit("braveFreshness", e.target.value), children: [
|
|
1067
1163
|
react.createElement("option", { value: "", key: "any" }, t("freshnessAny")),
|
|
1068
1164
|
react.createElement("option", { value: "pd", key: "pd" }, t("freshnessDay")),
|
|
1069
1165
|
react.createElement("option", { value: "pw", key: "pw" }, t("freshnessWeek")),
|
|
@@ -1072,20 +1168,17 @@ window.__ModuleLoader__.load({
|
|
|
1072
1168
|
] })),
|
|
1073
1169
|
maxResultsRow
|
|
1074
1170
|
) : null,
|
|
1075
|
-
brave ? row("
|
|
1171
|
+
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,
|
|
1076
1172
|
deepseek ? maxResultsRow : null,
|
|
1077
1173
|
restMeta ? react.createElement("div", { className: "dshws_form" },
|
|
1078
|
-
restMeta.keyRequired && restMeta.officialUrl ? react.createElement("a", {
|
|
1079
|
-
href: restMeta.officialUrl,
|
|
1080
|
-
target: "_blank",
|
|
1081
|
-
rel: "noopener noreferrer",
|
|
1082
|
-
className: "dshws_field_hint",
|
|
1083
|
-
style: { color: "var(--dsw-alias-brand-primary,#3b82f6)", textDecoration: "none", padding: "8px 0", display: "inline-block" }
|
|
1084
|
-
}, t("getKey") + " ↗") : null,
|
|
1085
1174
|
restMeta.keyRequired ? pair(
|
|
1086
|
-
fieldRow(t("apiKey"), keyHint, secretInput({ id: "ws-" + restMeta.id + "-key", value: state[restMeta.keyField]?.text ?? "", disabled: !state.apiKeyWritable, placeholder: state.apiKeyConfigured ? t("apiKeySet") : t("apiKeyUnset"), onChange: (e) => actions.edit(restMeta.keyField, e.target.value) })),
|
|
1175
|
+
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) })),
|
|
1087
1176
|
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) }))
|
|
1088
1177
|
) : null,
|
|
1178
|
+
provider === "scavio" ? pair(
|
|
1179
|
+
row("scavioCountry", t("country"), t("scavioCountryHint"), textInput({ id: "ws-scavio-country", value: state.scavioCountry.text, disabled, onChange: (e) => actions.edit("scavioCountry", e.target.value) })),
|
|
1180
|
+
row("scavioSearchLang", t("searchLang"), t("scavioSearchLangHint"), textInput({ id: "ws-scavio-lang", value: state.scavioSearchLang.text, disabled, onChange: (e) => actions.edit("scavioSearchLang", e.target.value) }))
|
|
1181
|
+
) : null,
|
|
1089
1182
|
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) })),
|
|
1090
1183
|
maxResultsRow
|
|
1091
1184
|
) : null,
|
|
@@ -1112,17 +1205,37 @@ window.__ModuleLoader__.load({
|
|
|
1112
1205
|
}
|
|
1113
1206
|
|
|
1114
1207
|
/** Section component: the "Web search" page body, driven by useSyncExternalStore. */
|
|
1115
|
-
function makeSection(ctx
|
|
1208
|
+
function makeSection(ctx) {
|
|
1116
1209
|
return function WebSearchSection() {
|
|
1117
|
-
|
|
1118
|
-
const t = ctx.locale.bind(NS);
|
|
1119
|
-
if (!state.available) return react.createElement("p", { style: { padding: "16px" } }, t("readOnly"));
|
|
1210
|
+
if (shared.controller === null) return null;
|
|
1120
1211
|
return react.createElement("div", { style: { padding: "16px" } },
|
|
1121
|
-
react.createElement(
|
|
1122
|
-
react.createElement(WebSearchCard, { t: t, state: state, actions: controller.form.actions() })));
|
|
1212
|
+
react.createElement(WebSearchConfigCard, { ctx: ctx }));
|
|
1123
1213
|
};
|
|
1124
1214
|
}
|
|
1125
1215
|
|
|
1216
|
+
/**
|
|
1217
|
+
* The settings card controller, or `null` when the Host does not serve
|
|
1218
|
+
* this namespace.
|
|
1219
|
+
* @type {{controller: SearchCardController | null}}
|
|
1220
|
+
*/
|
|
1221
|
+
const shared = { controller: null };
|
|
1222
|
+
|
|
1223
|
+
/**
|
|
1224
|
+
* The configuration card reads the shared controller's store and draws
|
|
1225
|
+
* the bordered panel in the settings section.
|
|
1226
|
+
* @param props - `ctx` for locale binding.
|
|
1227
|
+
* @returns the card element, or null while the namespace is unserved.
|
|
1228
|
+
*/
|
|
1229
|
+
function WebSearchConfigCard(props) {
|
|
1230
|
+
const controller = shared.controller;
|
|
1231
|
+
if (controller === null) return null;
|
|
1232
|
+
const state = react.useSyncExternalStore(controller.store.subscribe, controller.store.getSnapshot);
|
|
1233
|
+
const t = props.ctx.locale.bind(NS);
|
|
1234
|
+
if (!state.available) return react.createElement("p", { style: { padding: "16px" } }, t("readOnly"));
|
|
1235
|
+
return react.createElement("div", { style: { border: "1px solid var(--dsw-alias-border-l2)", background: "var(--dsw-alias-bg-layer-3)", borderRadius: "12px", padding: "4px 16px" } },
|
|
1236
|
+
react.createElement(WebSearchCard, { t: t, state: state, actions: controller.form.actions() }));
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1126
1239
|
function syncSettingsNavIcon() {
|
|
1127
1240
|
if (typeof document === "undefined" || typeof document.querySelectorAll !== "function") return;
|
|
1128
1241
|
const lists = document.querySelectorAll("[class*='_navList']");
|
|
@@ -1149,26 +1262,43 @@ window.__ModuleLoader__.load({
|
|
|
1149
1262
|
return () => observer.disconnect();
|
|
1150
1263
|
}
|
|
1151
1264
|
|
|
1152
|
-
/** Mount the top-level "Web search" settings section. */
|
|
1153
1265
|
function apply(ctx) {
|
|
1154
1266
|
const t = ctx.locale.bind(NS);
|
|
1155
1267
|
ctx.effect(() => ctx.locale.register(NS, { zh, en }), "dsh-web-search-plugin: card dictionaries");
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1268
|
+
|
|
1269
|
+
// One controller for the settings section, created as soon as the Host
|
|
1270
|
+
// serves this namespace and torn down with it.
|
|
1271
|
+
ctx.effect(() => ctx.configForms.whileServed([NS], () => {
|
|
1272
|
+
shared.controller = new SearchCardController(ctx.configForms.get(NS), ctx.remote);
|
|
1273
|
+
const stopUsage = usageStore.start();
|
|
1274
|
+
const stopCredentials = ctx.remote.$on("credentials/reference-updated", (ref) => {
|
|
1275
|
+
shared.controller?.form.refreshCredential(ref);
|
|
1276
|
+
});
|
|
1277
|
+
const stopNavIcon = startSettingsNavIconSync();
|
|
1278
|
+
// The navigation entry belongs to the same lifetime as its Host form.
|
|
1279
|
+
let stopSection = () => {};
|
|
1280
|
+
const sectionFiber = ctx.slots.inject("settings.section", () => {
|
|
1281
|
+
stopSection = ctx.slots.register({
|
|
1282
|
+
name: "settings.section",
|
|
1283
|
+
id: "web-search",
|
|
1284
|
+
order: 10,
|
|
1285
|
+
label: () => t("nav"),
|
|
1286
|
+
locale: NS
|
|
1287
|
+
}, makeSection(ctx));
|
|
1288
|
+
return stopSection;
|
|
1289
|
+
});
|
|
1290
|
+
return () => {
|
|
1291
|
+
shared.controller = null;
|
|
1292
|
+
stopUsage();
|
|
1293
|
+
stopCredentials();
|
|
1294
|
+
stopNavIcon();
|
|
1295
|
+
stopSection();
|
|
1296
|
+
void sectionFiber.dispose();
|
|
1297
|
+
};
|
|
1298
|
+
}), "dsh-web-search-plugin: forms");
|
|
1169
1299
|
}
|
|
1170
1300
|
|
|
1171
|
-
const inject = ["slots", "locale", "remote", "remote.credentials", "
|
|
1301
|
+
const inject = ["slots", "locale", "remote", "remote.credentials", "configForms"];
|
|
1172
1302
|
|
|
1173
1303
|
exports.apply = apply;
|
|
1174
1304
|
exports.inject = inject;
|