@240xu/dsh-websearch 2.9.1 → 2.10.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/README.md +6 -4
- package/lib/backends/anthropic-like.js +6 -1
- package/lib/backends/exa.js +2 -2
- package/lib/backends/openai.js +7 -1
- package/lib/cache.js +4 -4
- package/lib/client.js +1 -1
- package/lib/index.js +30 -2
- package/lib/provider.js +27 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -92,14 +92,16 @@ pnpm install
|
|
|
92
92
|
> 每个 API Key 字段旁有 **「获取 Key ↗」** 直达对应平台控制台;保存即写入凭证库并立即生效。
|
|
93
93
|
|
|
94
94
|
|
|
95
|
-
插件向 DSH 设置面板注册 `unified-search` namespace(Settings → Unified Search),面板可编辑 24
|
|
95
|
+
插件向 DSH 设置面板注册 `unified-search` namespace(Settings → Unified Search),面板可编辑 24 个开关/参数(共 60 个配置字段);缓存、熔断、历史、多查询、BaseURL、Model 与 `*ApiKeyEnv` 等其余字段通过 profile patch 配置:
|
|
96
96
|
|
|
97
97
|
**全局**
|
|
98
98
|
|
|
99
99
|
| 字段 | 默认 | 说明 |
|
|
100
100
|
|---|---|---|
|
|
101
101
|
| `intervention` | balanced | 搜索介入程度:`official` / `balanced` / `thorough`(见下表) |
|
|
102
|
-
| `numResults` | 10 | 每次搜索返回结果数(1-
|
|
102
|
+
| `numResults` | 10 | 每次搜索返回结果数(1-100;Exa 上限 100,official 档沿用宿主工具的条数上限) |
|
|
103
|
+
| `includeDomains` | 空 | 仅允许这些域名(逗号/空格分隔,最多 20;OpenAI/Anthropic 原生后端生效) |
|
|
104
|
+
| `excludeDomains` | 空 | 排除这些域名(最多 20;同时设置时原生后端优先 allow) |
|
|
103
105
|
| `concurrency` | 6 | 并发后端数(1-10) |
|
|
104
106
|
| `backendTimeoutMs` | 24000 | 单后端超时毫秒(为宿主 30s 工具超时预留余量) |
|
|
105
107
|
| `recency` | any | 时间范围过滤:day / week / month / year(映射到各后端原生参数) |
|
|
@@ -264,7 +266,7 @@ tests/
|
|
|
264
266
|
node --test tests/
|
|
265
267
|
```
|
|
266
268
|
|
|
267
|
-
当前
|
|
269
|
+
当前 220/220 pass(`node --test tests/*.test.js`;`tests/up-health.test.mjs` 单独跑)。
|
|
268
270
|
|
|
269
271
|
### Test-only dependencies
|
|
270
272
|
|
|
@@ -277,7 +279,7 @@ live service before running the suite:
|
|
|
277
279
|
```bash
|
|
278
280
|
bash tests/relink-test-deps.sh # derives the scope from dsh-web.service MainPID
|
|
279
281
|
find node_modules/@deepseek-ai -xtype l # expect no output
|
|
280
|
-
node --test tests/*.test.js #
|
|
282
|
+
node --test tests/*.test.js # 220/220
|
|
281
283
|
```
|
|
282
284
|
|
|
283
285
|
v2.7.0 起共 76+ tests pass(`node --test "tests/*.test.js" "test/*.test.mjs"`)〔历史快照;当前口径见上〕。
|
|
@@ -86,6 +86,11 @@ export function createAnthropicLikeBackend(spec) {
|
|
|
86
86
|
const maxUses = options.maxUses ?? 5;
|
|
87
87
|
const endpoint = `${baseURL.replace(/\/$/, "")}/messages`;
|
|
88
88
|
|
|
89
|
+
const domainArgs = Array.isArray(options?.includeDomains) && options.includeDomains.length > 0
|
|
90
|
+
? { allowed_domains: options.includeDomains }
|
|
91
|
+
: Array.isArray(options?.excludeDomains) && options.excludeDomains.length > 0
|
|
92
|
+
? { blocked_domains: options.excludeDomains }
|
|
93
|
+
: {};
|
|
89
94
|
const body = {
|
|
90
95
|
model,
|
|
91
96
|
max_tokens: maxTokens,
|
|
@@ -100,7 +105,7 @@ export function createAnthropicLikeBackend(spec) {
|
|
|
100
105
|
],
|
|
101
106
|
},
|
|
102
107
|
],
|
|
103
|
-
tools: [{ type: toolName, name: "web_search", max_uses: maxUses }],
|
|
108
|
+
tools: [{ type: toolName, name: "web_search", max_uses: maxUses, ...domainArgs }],
|
|
104
109
|
};
|
|
105
110
|
|
|
106
111
|
hooks.recordRequest?.({
|
package/lib/backends/exa.js
CHANGED
|
@@ -41,7 +41,7 @@ export const exaBackend = {
|
|
|
41
41
|
async search(request, signal, options, hooks = {}) {
|
|
42
42
|
const args = {
|
|
43
43
|
query: request.query,
|
|
44
|
-
numResults: request.maxResults
|
|
44
|
+
numResults: Math.max(1, Math.min(Number(request.maxResults) || 10, 100)),
|
|
45
45
|
};
|
|
46
46
|
// v2.8.0: category inference — deepCoverage-gated like tavily (searchDepth
|
|
47
47
|
// advanced) and searxng (category sweep): 2.8.1 审计发现此处漏了门控,
|
|
@@ -78,7 +78,7 @@ export const exaBackend = {
|
|
|
78
78
|
throw new WebError(`exa returned an MCP error: ${message}`, "WEB_PROVIDER_ERROR");
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
const sources = parseExaResult(result, request.maxResults
|
|
81
|
+
const sources = parseExaResult(result, Math.max(1, Math.min(Number(request.maxResults) || 10, 100)));
|
|
82
82
|
hooks.recordOutcome?.({ status: "ok", count: sources.length });
|
|
83
83
|
|
|
84
84
|
return { sources, content: undefined, truncated: false };
|
package/lib/backends/openai.js
CHANGED
|
@@ -53,9 +53,15 @@ export const openaiBackend = {
|
|
|
53
53
|
const model = options.model || "gpt-4o";
|
|
54
54
|
const endpoint = `${baseURL}/responses`;
|
|
55
55
|
|
|
56
|
+
const domainFilters = {};
|
|
57
|
+
if (Array.isArray(options?.includeDomains) && options.includeDomains.length > 0) domainFilters.allowed_domains = options.includeDomains;
|
|
58
|
+
if (Array.isArray(options?.excludeDomains) && options.excludeDomains.length > 0) domainFilters.blocked_domains = options.excludeDomains;
|
|
56
59
|
const body = {
|
|
57
60
|
model,
|
|
58
|
-
tools: [{
|
|
61
|
+
tools: [{
|
|
62
|
+
type: "web_search",
|
|
63
|
+
...(Object.keys(domainFilters).length > 0 ? { filters: domainFilters } : {}),
|
|
64
|
+
}],
|
|
59
65
|
input: request.query,
|
|
60
66
|
};
|
|
61
67
|
|
package/lib/cache.js
CHANGED
|
@@ -30,13 +30,13 @@ export const CACHE_DEFAULTS = {
|
|
|
30
30
|
/**
|
|
31
31
|
* Compute the deterministic cache key for a search.
|
|
32
32
|
* The key covers the shaped query, filters, the effective maxResults, the
|
|
33
|
-
* enabledBackends
|
|
34
|
-
* option: switching the
|
|
35
|
-
*
|
|
33
|
+
* enabledBackends selection **in fan-out order**, the cache mode, and every
|
|
34
|
+
* non-function result option: switching the mix or reordering it can change
|
|
35
|
+
* which duplicate's title/snippet wins, so both must miss (arch-review P1-1).
|
|
36
36
|
* Pure function; exported for tests and host reuse.
|
|
37
37
|
*/
|
|
38
38
|
export function cacheKeyFor({ query, filters, maxResults, backends, mode, resultOptions }) {
|
|
39
|
-
const backendSet = Array.isArray(backends) ?
|
|
39
|
+
const backendSet = Array.isArray(backends) ? backends.join(",") : "";
|
|
40
40
|
let shaped = {};
|
|
41
41
|
if (resultOptions && typeof resultOptions === "object") {
|
|
42
42
|
const keys = Object.keys(resultOptions).filter((k) =>
|
package/lib/client.js
CHANGED
|
@@ -680,7 +680,7 @@ window.__ModuleLoader__.load({
|
|
|
680
680
|
// Mirror the server schema bounds client-side so bad input is
|
|
681
681
|
// caught in the UI instead of a failed Host round-trip.
|
|
682
682
|
const BOUNDS = {
|
|
683
|
-
numResults: [1,
|
|
683
|
+
numResults: [1, 100],
|
|
684
684
|
concurrency: [1, 10],
|
|
685
685
|
backendTimeoutMs: [1000, 120000],
|
|
686
686
|
};
|
package/lib/index.js
CHANGED
|
@@ -161,7 +161,7 @@ export const Config = z.object({
|
|
|
161
161
|
// Global
|
|
162
162
|
intervention: z.union(["official", "balanced", "thorough"]).default("balanced")
|
|
163
163
|
.description("搜索介入程度【策略】:official=只做官方 provider 该做的(原样查询、不加结果头/遥测、沿用工具的条数上限);balanced=确定性去噪 + 去重/遥测(默认);thorough=额外启用相关性重排与深度覆盖(内部多查询仍是独立开关,默认关)"),
|
|
164
|
-
numResults: z.number().step(1).min(1).max(
|
|
164
|
+
numResults: z.number().step(1).min(1).max(100).default(10)
|
|
165
165
|
.description("每次搜索返回的最大结果数(official 档沿用宿主工具的条数上限)"),
|
|
166
166
|
concurrency: z.number().step(1).min(1).max(10).default(6)
|
|
167
167
|
.description("同时并发的后端数量"),
|
|
@@ -175,6 +175,10 @@ export const Config = z.object({
|
|
|
175
175
|
.description("搜索语言(如 en、zh-CN;留空用各后端默认)"),
|
|
176
176
|
safeSearch: z.boolean().default(true)
|
|
177
177
|
.description("安全搜索(SearXNG / Brave 支持开关,其余后端忽略)"),
|
|
178
|
+
includeDomains: z.string().default("")
|
|
179
|
+
.description("只允许这些域名(逗号/空格分隔,最多 20 个;OpenAI/Anthropic 原生后端生效)"),
|
|
180
|
+
excludeDomains: z.string().default("")
|
|
181
|
+
.description("排除这些域名(逗号/空格分隔,最多 20 个;与 includeDomains 同时设置时原生后端优先 include)"),
|
|
178
182
|
dedupStrategy: z.union(["url", "url+title"]).default("url")
|
|
179
183
|
.description("去重策略:url 仅按链接;url+title 额外合并同标题的转载镜像"),
|
|
180
184
|
rerank: z.boolean().default(false)
|
|
@@ -197,7 +201,7 @@ export const Config = z.object({
|
|
|
197
201
|
breakerThreshold: z.number().step(1).min(1).max(20).default(BREAKER_DEFAULTS.threshold)
|
|
198
202
|
.description("熔断阈值【熔断】:连续失败多少次后触发(默认 3 次)"),
|
|
199
203
|
breakerCooldownMs: z.number().step(1000).min(0).max(3600000).default(BREAKER_DEFAULTS.cooldownMs)
|
|
200
|
-
.description("熔断冷却时长【熔断】(单位:毫秒):默认 60000
|
|
204
|
+
.description("熔断冷却时长【熔断】(单位:毫秒):默认 60000;0 关闭按阈值的冷却,带 Retry-After 的 429 仍按该窗口冷却"),
|
|
201
205
|
historyEnabled: z.boolean().default(true)
|
|
202
206
|
.description("记录搜索历史【历史】:只追加,最多 50 条;可在设置 → 搜索 中查看与清空"),
|
|
203
207
|
|
|
@@ -327,6 +331,26 @@ for (const [key, label] of Object.entries(FIELD_LABELS)) {
|
|
|
327
331
|
* serves its NEXT search with. Key resolution: credentialRef -> credentials
|
|
328
332
|
* service -> env.
|
|
329
333
|
*/
|
|
334
|
+
/** Normalize a comma/space-domain setting into lowercase bare hostnames. */
|
|
335
|
+
function normalizeDomainList(raw) {
|
|
336
|
+
if (typeof raw !== "string" || raw.trim() === "") return [];
|
|
337
|
+
const out = [];
|
|
338
|
+
for (const piece of raw.split(/[,\s]+/)) {
|
|
339
|
+
const item = piece.trim().toLowerCase();
|
|
340
|
+
if (item === "") continue;
|
|
341
|
+
let host = item;
|
|
342
|
+
try {
|
|
343
|
+
const u = new URL(item.includes("://") ? item : "https://" + item);
|
|
344
|
+
host = u.hostname;
|
|
345
|
+
} catch { /* keep the raw token and validate below */ }
|
|
346
|
+
host = host.replace(/^\[|\]$/g, "");
|
|
347
|
+
if (!/^[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?$/.test(host)) continue;
|
|
348
|
+
if (!out.includes(host)) out.push(host);
|
|
349
|
+
if (out.length >= 20) break;
|
|
350
|
+
}
|
|
351
|
+
return out;
|
|
352
|
+
}
|
|
353
|
+
|
|
330
354
|
export function resolveOptions(ctx, config) {
|
|
331
355
|
// 1. Determine enabled backends: explicit list > toggles > env > defaults.
|
|
332
356
|
// The four keyless toggles default to true, so the env fallback is reachable
|
|
@@ -377,6 +401,8 @@ export function resolveOptions(ctx, config) {
|
|
|
377
401
|
: [],
|
|
378
402
|
} : {}),
|
|
379
403
|
safeSearch: config?.safeSearch !== false,
|
|
404
|
+
includeDomains: normalizeDomainList(config?.includeDomains),
|
|
405
|
+
excludeDomains: normalizeDomainList(config?.excludeDomains),
|
|
380
406
|
label: DEFAULT_LABELS[id] ?? id,
|
|
381
407
|
requiresKey: DEFAULT_KEY_ENV[id] !== undefined && !OPTIONAL_KEY_IDS.has(id),
|
|
382
408
|
optionalKey: OPTIONAL_KEY_IDS.has(id),
|
|
@@ -432,6 +458,8 @@ export function resolveOptions(ctx, config) {
|
|
|
432
458
|
// invisibly.
|
|
433
459
|
multiQueryEnabled: !official && config?.multiQueryEnabled === true,
|
|
434
460
|
deepCoverage: thorough || (!official && config?.deepCoverage === true),
|
|
461
|
+
includeDomains: normalizeDomainList(config?.includeDomains),
|
|
462
|
+
excludeDomains: normalizeDomainList(config?.excludeDomains),
|
|
435
463
|
filters: {
|
|
436
464
|
recency: typeof config?.recency === "string" && config.recency !== "any" ? config.recency : undefined,
|
|
437
465
|
lang: language.length > 0 ? language : undefined,
|
package/lib/provider.js
CHANGED
|
@@ -654,7 +654,29 @@ export function createUnifiedSearchProvider({ ctx, resolveOptions, backends, cac
|
|
|
654
654
|
// finished by this point so the array no longer grows. History counts
|
|
655
655
|
// unique backends, not attempts: multi-query fans one backend out once
|
|
656
656
|
// per variant, which used to report `backendsTotal` as variants × backends.
|
|
657
|
-
|
|
657
|
+
// One display segment per backend, not per variant: a multi-query
|
|
658
|
+
// search otherwise repeats the same backend N times and can hide a
|
|
659
|
+
// backend beyond the 12-slot cap while health/history show it once.
|
|
660
|
+
const foldedTelemetry = [];
|
|
661
|
+
const telemetryById = new Map();
|
|
662
|
+
for (const t of allTelemetry) {
|
|
663
|
+
const prev = telemetryById.get(t.id);
|
|
664
|
+
if (prev === undefined) {
|
|
665
|
+
const copy = { ...t };
|
|
666
|
+
telemetryById.set(t.id, copy);
|
|
667
|
+
foldedTelemetry.push(copy);
|
|
668
|
+
continue;
|
|
669
|
+
}
|
|
670
|
+
if (t.ok === true) {
|
|
671
|
+
prev.ok = true;
|
|
672
|
+
prev.count = Math.max(prev.count ?? 0, t.count ?? 0);
|
|
673
|
+
prev.error = undefined;
|
|
674
|
+
} else if (prev.ok !== true) {
|
|
675
|
+
prev.error = t.error;
|
|
676
|
+
}
|
|
677
|
+
prev.ms = Math.max(prev.ms ?? 0, t.ms ?? 0);
|
|
678
|
+
}
|
|
679
|
+
const okCount = foldedTelemetry.filter((t) => t.ok).length;
|
|
658
680
|
const historyOk = new Set(allTelemetry.filter((t) => t.ok).map((t) => t.id)).size;
|
|
659
681
|
const historyTotal = new Set(allTelemetry.map((t) => t.id)).size;
|
|
660
682
|
|
|
@@ -716,7 +738,7 @@ export function createUnifiedSearchProvider({ ctx, resolveOptions, backends, cac
|
|
|
716
738
|
// labels (route6 P2); the raw text remains the fallback, and a
|
|
717
739
|
// backend that just crossed the breaker threshold is annotated as
|
|
718
740
|
// cooled on this same line.
|
|
719
|
-
const parts =
|
|
741
|
+
const parts = foldedTelemetry
|
|
720
742
|
.slice(0, 12)
|
|
721
743
|
.map((t) => {
|
|
722
744
|
if (t.ok) return t.id + " ✓" + t.ms + "ms/" + t.count;
|
|
@@ -725,7 +747,7 @@ export function createUnifiedSearchProvider({ ctx, resolveOptions, backends, cac
|
|
|
725
747
|
return t.id + " ✗" + t.ms + "ms" + (label ? " (" + label + ")" : "") + (cooledNow ? " " + cooledNow : "");
|
|
726
748
|
})
|
|
727
749
|
.concat(cooledParts);
|
|
728
|
-
if (
|
|
750
|
+
if (foldedTelemetry.length > 12) parts.push(`… +${foldedTelemetry.length - 12}`);
|
|
729
751
|
const line = "[websearch backends]" + TELEMETRY_TAG + " " + parts.join(" · ");
|
|
730
752
|
outContent = outContent === undefined ? line : outContent + "\n\n" + line;
|
|
731
753
|
}
|
|
@@ -752,12 +774,12 @@ export function createUnifiedSearchProvider({ ctx, resolveOptions, backends, cac
|
|
|
752
774
|
emptyContent = header + "\n\n" + emptyContent;
|
|
753
775
|
}
|
|
754
776
|
if (opts.resultTelemetry !== false && allFailures.length > 0) {
|
|
755
|
-
const parts =
|
|
777
|
+
const parts = foldedTelemetry.slice(0, 12).map((t) => {
|
|
756
778
|
if (t.ok) return t.id + " ✓" + t.ms + "ms/" + t.count;
|
|
757
779
|
const label = failureLabel(t.id, t.error) ?? (t.error ? String(t.error).slice(0, 40) : "");
|
|
758
780
|
return t.id + " ✗" + t.ms + "ms" + (label ? " (" + label + ")" : "");
|
|
759
781
|
});
|
|
760
|
-
if (
|
|
782
|
+
if (foldedTelemetry.length > 12) parts.push(`… +${foldedTelemetry.length - 12}`);
|
|
761
783
|
const line = "[websearch backends]" + TELEMETRY_TAG + " " + parts.join(" · ");
|
|
762
784
|
emptyContent = emptyContent === undefined ? line : emptyContent + "\n\n" + line;
|
|
763
785
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@240xu/dsh-websearch",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.0",
|
|
4
4
|
"description": "Unified web search provider for DeepSeek Harness (ctx.web): 13 backends — Exa + Parallel + DDG + SearXNG (keyless), DeepSeek + Anthropic + OpenAI + Brave + Tavily + Serper + Mojeek (key-gated via Settings credentials), Firecrawl + TinyFish (metered keyless, opt-in). Registers provider id \"unified\" for zero-config web_search. 统一网页搜索聚合:13 后端并发扇出、去重合并。See CHANGELOG.md for version history.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|