@240xu/dsh-websearch 2.12.0 → 2.13.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/README.md CHANGED
@@ -164,7 +164,7 @@ pnpm install
164
164
 
165
165
  - 每后端请求条数上调至 `ceil(maxResults × 1.5)`,全局去重后仍按 maxResults 截断——牺牲带宽换覆盖面。
166
166
  - 后端能力适配(feature-detect,不破坏旧参数):Tavily 自动切 `search_depth: advanced`(2 credits,多 snippet/URL);SearXNG 类目扩为 `general,news,it`(Search API `categories` 逗号列表)。
167
- - Exa:`inferExaCategory` 从查询推断 data category(github / research paper / news,仅高置信注入)。
167
+ - Exa:只发送工具 schema 声明的 `query` / `numResults`;不注入 category(`tools/list` 未声明)。
168
168
 
169
169
  ### 3. 运维可观测(P2)
170
170
 
@@ -14,22 +14,6 @@ import { describeError } from "../util/describe-error.js";
14
14
  const EXA_ENDPOINT = "https://mcp.exa.ai/mcp";
15
15
  const EXA_TOOL = "web_search_exa";
16
16
 
17
- /**
18
- * Infer an Exa data category from the query (v2.8.0). Only high-confidence
19
- * patterns map — Exa rejects unknown categories with a 400, so this returns
20
- * undefined unless a signal is explicit. Valid values per the Exa OpenAPI
21
- * enum: github / "research paper" / news / pdf / company / people /
22
- * "personal site" / "financial report".
23
- */
24
- export function inferExaCategory(query) {
25
- const q = typeof query === "string" ? query.toLowerCase() : "";
26
- if (!q) return undefined;
27
- if (/\bgithub\b|\brepo\b|repository|开源项目|源码/.test(q)) return "github";
28
- if (/\barxiv\b|\bpaper\b|论文|研究文献|preprint/.test(q)) return "research paper";
29
- if (/\bnews\b|新闻|最新消息|动态/.test(q)) return "news";
30
- return undefined;
31
- }
32
-
33
17
  export const exaBackend = {
34
18
  id: "exa",
35
19
  requiresCredential: false,
@@ -43,14 +27,6 @@ export const exaBackend = {
43
27
  query: request.query,
44
28
  numResults: Math.max(1, Math.min(Number(request.maxResults) || 10, 100)),
45
29
  };
46
- // v2.8.0: category inference — deepCoverage-gated like tavily (searchDepth
47
- // advanced) and searxng (category sweep): 2.8.1 审计发现此处漏了门控,
48
- // 默认关着 deepCoverage 也注入 category,把结果悄悄收窄到单类目,与 README
49
- // 「deepCoverage 深度覆盖」承诺相反。
50
- if (request.deepCoverage === true) {
51
- const category = inferExaCategory(request.query);
52
- if (category) args.category = category;
53
- }
54
30
  hooks.recordRequest?.({
55
31
  endpoint: EXA_ENDPOINT,
56
32
  toolName: EXA_TOOL,
package/lib/provider.js CHANGED
@@ -370,7 +370,7 @@ export function createUnifiedSearchProvider({ ctx, resolveOptions, backends, cac
370
370
  // cache hit for a four-backend search used to report one backend.
371
371
  const hitOk = Number.isInteger(hit.value.backendsOk) ? hit.value.backendsOk : 1;
372
372
  const hitTotal = Number.isInteger(hit.value.backendsTotal) ? hit.value.backendsTotal : 1;
373
- recordHistory(history, request?.query, hit.value.sources.length, hitOk, hitTotal);
373
+ recordHistory(history, request?.query, safeSources.length, hitOk, hitTotal);
374
374
  return {
375
375
  sources: safeSources,
376
376
  ...(hitContent !== undefined ? { content: hitContent } : {}),
@@ -585,9 +585,12 @@ export function createUnifiedSearchProvider({ ctx, resolveOptions, backends, cac
585
585
  rateLimited: rateLimited(err), keylessRejected: keylessRejected(err), retryAfterMs: retryAfterMsFrom(err),
586
586
  });
587
587
  }
588
- throw timedOut
589
- ? new WebError(reason, "WEB_PROVIDER_ERROR", { cause: err instanceof Error ? err : undefined })
590
- : err;
588
+ if (timedOut) {
589
+ const wrapped = new WebError(reason, "WEB_PROVIDER_ERROR", { cause: err instanceof Error ? err : undefined });
590
+ wrapped.timedOut = true;
591
+ throw wrapped;
592
+ }
593
+ throw err;
591
594
  },
592
595
  )
593
596
  .finally(() => { clearTimeout(timeoutId); guardCleanup(); });
@@ -621,6 +624,8 @@ export function createUnifiedSearchProvider({ ctx, resolveOptions, backends, cac
621
624
  // Final outcome per backend across every variant. Success wins; otherwise
622
625
  // keep the latest failure and the most severe quota classification.
623
626
  const searchHealth = new Map();
627
+ const planBackendIds = new Set(eligible.filter(({ backend }) => backend.handlesAllVariants === true).map(({ id }) => id));
628
+ let primaryPlanFailed = false;
624
629
  for (let variantIndex = 0; variantIndex < variants.length; variantIndex += 1) {
625
630
  const variantQuery = variants[variantIndex];
626
631
  const remaining = searchDeadline - Date.now();
@@ -629,10 +634,11 @@ export function createUnifiedSearchProvider({ ctx, resolveOptions, backends, cac
629
634
  // would contradict a success from the same backend in variant 1.
630
635
  const minVariantBudgetMs = Math.min(Number(opts.backendTimeoutMs) || 24000, 2000);
631
636
  if (remaining < minVariantBudgetMs) break;
632
- // Split the remaining budget across the variants still owed, so one
633
- // slow variant cannot starve the rest (the old code gave each variant
634
- // the full budget, and each backend inside it).
635
- const share = Math.max(1, Math.floor(remaining / Math.max(1, variants.length - variantIndex)));
637
+ // Per-backend timeout is a contract, not a per-variant quota: a
638
+ // variant gets the configured timeout while the shared deadline still
639
+ // bounds the whole search. Dividing by the variant count made a
640
+ // healthy 1s backend fail at 666ms under three variants.
641
+ const share = Math.max(1, Math.min(remaining, Number(opts.backendTimeoutMs) || 24000));
636
642
  // Parallel can merge the derived facets into one request; give it the
637
643
  // plan on the primary variant and skip it for later variants. Other
638
644
  // backends must not opt into handlesAllVariants (they cannot merge
@@ -640,7 +646,9 @@ export function createUnifiedSearchProvider({ ctx, resolveOptions, backends, cac
640
646
  const searchPlan = useMulti && variantIndex === 0
641
647
  ? { objective: effReq.query, queries: variants.slice(0, 3) }
642
648
  : undefined;
643
- const variantEligible = variantIndex === 0
649
+ // If the single planned call failed, later variants retry the
650
+ // plan-capable backend per facet instead of silently losing it.
651
+ const variantEligible = variantIndex === 0 || primaryPlanFailed
644
652
  ? eligible
645
653
  : eligible.filter(({ backend }) => backend.handlesAllVariants !== true);
646
654
  const variantReq = {
@@ -654,6 +662,13 @@ export function createUnifiedSearchProvider({ ctx, resolveOptions, backends, cac
654
662
  pageLimit: coverage && !useMulti ? 2 : 1,
655
663
  };
656
664
  const fold = await fanoutVariant(variantReq, share, searchDeadline, variantEligible);
665
+ if (variantIndex === 0 && useMulti) {
666
+ // A hung plan backend will not recover under a smaller later share;
667
+ // only fast failures fall back to per-facet retries.
668
+ primaryPlanFailed = fold.failures.some(
669
+ (failure) => planBackendIds.has(failure.id) && failure.err?.timedOut !== true,
670
+ );
671
+ }
657
672
  for (const outcome of fold.health) {
658
673
  const prev = searchHealth.get(outcome.id);
659
674
  if (prev === undefined || outcome.ok === true) {
@@ -713,14 +728,17 @@ export function createUnifiedSearchProvider({ ctx, resolveOptions, backends, cac
713
728
  foldedTelemetry.push(copy);
714
729
  continue;
715
730
  }
731
+ if (prev.ok === true) continue; // a success already won; keep its latency
716
732
  if (t.ok === true) {
717
733
  prev.ok = true;
734
+ prev.skipped = false;
718
735
  prev.count = Math.max(prev.count ?? 0, t.count ?? 0);
719
736
  prev.error = undefined;
720
- } else if (prev.ok !== true) {
737
+ prev.ms = t.ms ?? 0;
738
+ } else {
721
739
  prev.error = t.error;
740
+ prev.ms = Math.max(prev.ms ?? 0, t.ms ?? 0);
722
741
  }
723
- prev.ms = Math.max(prev.ms ?? 0, t.ms ?? 0);
724
742
  }
725
743
  const okCount = foldedTelemetry.filter((t) => t.ok).length;
726
744
  const historyOk = new Set(allTelemetry.filter((t) => t.ok).map((t) => t.id)).size;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@240xu/dsh-websearch",
3
- "version": "2.12.0",
3
+ "version": "2.13.1",
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",