@240xu/dsh-websearch 2.13.9 → 2.13.10

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
@@ -203,8 +203,8 @@ pnpm install
203
203
 
204
204
  ### 1. 搜索结果磁盘缓存(默认开)
205
205
 
206
- - 相同 **(整形后查询 + filters + maxResults + 启用后端集合)** 在 TTL 内直接命中缓存,不打任何后端;`sources` 与首次搜索完全一致。
207
- - 命中时 `content` 追加一行 `[websearch cache] cache hit, age Ns`。
206
+ - 相同 **(整形后查询 + filters + 生效 maxResults + 有序后端集合 + 档位/域名过滤/宿主上限)** 在 TTL 内直接命中缓存,不打任何后端;`sources` 与首次搜索完全一致。
207
+ - 命中时 `content` 追加一行 `[websearch cache] cache hit, age Ns`;`official` 档或关闭遥测时不追加(命中仍生效)。
208
208
  - 存储位置:`$DSH_HOME/cache/websearch/results/`,单条目一个 JSON 文件,tmp+rename 原子写,超出上限按最旧淘汰;任何 fs 错误都被吞掉,缓存坏了绝不影响搜索。
209
209
  - 设置:`cacheEnabled`(默认 true)、`cacheTtl`(秒,默认 900;**0 = no-store**,不读也不写)。
210
210
  - 上限 200 条,超出按 mtime 最旧淘汰;缓存目录 0700、文件 0600(查询与结果属于用户数据)。
@@ -283,7 +283,7 @@ live service before running the suite:
283
283
  ```bash
284
284
  bash tests/relink-test-deps.sh # derives the scope from dsh-web.service MainPID
285
285
  find node_modules/@deepseek-ai -xtype l # expect no output
286
- node --test tests/*.test.js # 225/225
286
+ node --test tests/*.test.js # 241/241
287
287
  ```
288
288
 
289
289
  v2.7.0 起共 76+ tests pass(`node --test "tests/*.test.js" "test/*.test.mjs"`)〔历史快照;当前口径见上〕。
package/lib/client.js CHANGED
@@ -483,6 +483,9 @@ window.__ModuleLoader__.load({
483
483
  /** Push the current projection to the store and notify subscribers. */
484
484
  republish() {
485
485
  if (this.disposed) return;
486
+ // Reconcile drafts when official arrives from a reload/revision
487
+ // update, not only from the local edit path.
488
+ this.dropOfficialDrafts(this.scope.getSnapshot().value);
486
489
  this.store.set(this.projection());
487
490
  }
488
491
 
@@ -497,19 +500,35 @@ window.__ModuleLoader__.load({
497
500
  return typeof this.scope.load === "function" ? this.scope.load() : undefined;
498
501
  }
499
502
 
503
+ /**
504
+ * Drop drafts for fields the official tier overrides, and their
505
+ * stale validation errors. Returns whether anything changed.
506
+ * @param {object} value settings snapshot
507
+ * @returns {boolean}
508
+ */
509
+ dropOfficialDrafts(value) {
510
+ if (String(value?.intervention) !== "official") return false;
511
+ let changed = false;
512
+ for (const ignored of OFFICIAL_IGNORED_FIELDS) {
513
+ if (this.staged.delete(ignored)) changed = true;
514
+ if (this.failedFields.delete(ignored)) changed = true;
515
+ }
516
+ return changed;
517
+ }
500
518
  /** Stage a field edit (clears the saved marker so the card shows "unsaved"). */
501
519
  edit(field, text) {
520
+ // A revert to the saved official value must still drop ignored drafts.
521
+ const dropped = field === "intervention" && String(text) === "official"
522
+ ? this.dropOfficialDrafts({ intervention: "official" })
523
+ : false;
502
524
  const committed = String(this.sectionValue(field) ?? "");
503
525
  if (String(text) === committed) {
504
526
  // Reverting to the stored value is not a pending write.
505
- if (this.staged.delete(field)) this.republish();
527
+ if (this.staged.delete(field) || dropped) this.republish();
506
528
  return;
507
529
  }
508
530
  this.savedAt = 0;
509
531
  this.staged.set(field, { text });
510
- if (field === "intervention" && String(text) === "official") {
511
- for (const ignored of OFFICIAL_IGNORED_FIELDS) this.staged.delete(ignored);
512
- }
513
532
  this.republish();
514
533
  }
515
534
  /** Drop a staged field edit; the stored value is untouched. */
@@ -1139,13 +1158,6 @@ window.__ModuleLoader__.load({
1139
1158
  { value: "false", label: props.t("off") },
1140
1159
  ];
1141
1160
  const selVal = (f, dflt) => state.stagedText(f) ?? String(state.value[f] ?? dflt);
1142
- const cacheOn = selVal("cacheEnabled", "true") !== "false";
1143
- const official = selVal("intervention", "balanced") === "official";
1144
- const hasDraft = (f) => state.stagedText(f) !== undefined;
1145
- // A gate only locks untouched fields; a field with a pending edit
1146
- // stays editable so the user can correct or discard it.
1147
- const officialLocked = (f) => official && !hasDraft(f); // drafts are dropped on switching to official
1148
- const ttlLocked = !cacheOn && !hasDraft("cacheTtl");
1149
1161
 
1150
1162
  return react_jsx_runtime.jsxs("div", { className: "wsc-card", children: [
1151
1163
  react_jsx_runtime.jsx(StatusSummary, { state, enabledCount, hasOverride: override.length > 0, keysReady, t: props.t }),
package/lib/provider.js CHANGED
@@ -114,6 +114,19 @@ export function getBackendBreaker(id) {
114
114
  return e ? { failCount: e.failCount ?? 0, cooledUntil: e.cooledUntil ?? 0 } : { failCount: 0, cooledUntil: 0 };
115
115
  }
116
116
 
117
+ /**
118
+ * Whether a variant may start. Variant 1 runs whenever any budget remains
119
+ * (a 1 ms clock tick at the 1 s minimum must not skip the whole search);
120
+ * later variants need a meaningful slice.
121
+ * @param {number} variantIndex
122
+ * @param {number} remaining
123
+ * @param {number} minVariantBudgetMs
124
+ * @returns {boolean}
125
+ */
126
+ export function shouldStartVariant(variantIndex, remaining, minVariantBudgetMs) {
127
+ return variantIndex === 0 ? remaining > 0 : remaining >= minVariantBudgetMs;
128
+ }
129
+
117
130
  /**
118
131
  * Simple concurrency limiter using a semaphore pattern.
119
132
  * No external dependency needed.
@@ -309,10 +322,12 @@ export function createUnifiedSearchProvider({ ctx, resolveOptions, backends, cac
309
322
  // serve each other's cached results.
310
323
  const cacheMode = (useMulti ? "multi" : "single") + (coverage ? "+coverage" : "");
311
324
 
312
- // v2.7.0 disk cache: keyed on (shaped query + filters + maxResults +
313
- // backends + mode). A hit short-circuits the fan-out entirely; sources
314
- // are byte-identical to the first search and content carries a
315
- // "cache hit, age Ns" note. Cache failures never break the search.
325
+ // v2.7.0 disk cache: keyed on the shaped query, filters, effective
326
+ // maxResults, ordered backends, mode and every result-affecting option
327
+ // (tier, domains, host bound, per-backend URL/model). A hit
328
+ // short-circuits the fan-out; sources are byte-identical and content
329
+ // carries an age note unless resultTelemetry is off. Cache failures
330
+ // never break the search.
316
331
  const cacheEnabled = opts.cacheEnabled === true && cache;
317
332
  let cacheKey = null;
318
333
  if (cacheEnabled) {
@@ -627,13 +642,14 @@ export function createUnifiedSearchProvider({ ctx, resolveOptions, backends, cac
627
642
  // Do not start a variant that cannot get a meaningful slice: its
628
643
  // "timeout" would be budget exhaustion, not a backend outage, and
629
644
  // would contradict a success from the same backend in variant 1.
630
- // A 2s budget must still be able to run three fast facets; the floor
631
- // only prevents starting a variant that cannot get a meaningful slice.
645
+ // A 2s budget must still run three fast facets because the floor is
646
+ // 1s; the floor only prevents starting a later variant with no
647
+ // meaningful slice, and variant 1 always runs while any budget remains.
632
648
  const minVariantBudgetMs = Math.min(Number(opts.backendTimeoutMs) || 24000, 1000);
633
- if (remaining < minVariantBudgetMs) break;
634
- // Per-backend timeout is a contract, not a per-variant quota: a
635
- // variant gets the configured timeout while the shared deadline still
636
- // bounds the whole search. Dividing by the variant count made a
649
+ if (!shouldStartVariant(variantIndex, remaining, minVariantBudgetMs)) break;
650
+ // Per-backend timeout is a contract, not a per-variant quota: while
651
+ // the deadline allows, a variant gets the configured timeout; later
652
+ // variants get whatever time is left, and the deadline bounds all. Dividing by the variant count made a
637
653
  // healthy 1s backend fail at 666ms under three variants.
638
654
  const share = Math.max(1, Math.min(remaining, Number(opts.backendTimeoutMs) || 24000));
639
655
  // Parallel can merge the derived facets into one request; give it the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@240xu/dsh-websearch",
3
- "version": "2.13.9",
3
+ "version": "2.13.10",
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",