@fffangchenghao/dsh-web-search 0.13.10 → 0.13.11

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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.13.11
4
+
5
+ ### Fixed
6
+ - **`web_fetch` failed on every request more than 25 s after a restart**
7
+ ("no time left in the fetch budget" from the direct, tunnel and extract
8
+ rungs). The 25 s ladder budget was captured in the provider factory, which
9
+ runs once when the plugin mounts, so the deadline had already passed for any
10
+ later request. The budget now starts inside each `fetch()` call; a regression
11
+ test builds a provider, waits 1.2 s, and fetches twice.
12
+ - The budget test that was supposed to prove the ladder cap had `useProxy:
13
+ false`, so it never reached the tunnel rung. It now asserts the rung after the
14
+ first timeout refuses to start.
15
+
3
16
  ## 0.13.10
4
17
 
5
18
  ### Security
package/lib/fetch.js CHANGED
@@ -172,10 +172,6 @@ export function createFetchProvider(options = {}, overrides = {}) {
172
172
  ...overrides,
173
173
  };
174
174
  const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
175
- const overallMs = options.overallMs ?? DEFAULT_OVERALL_MS;
176
- const startedAt = Date.now();
177
- /** What is left of the whole-ladder budget. */
178
- const remaining = () => Math.max(0, overallMs - (Date.now() - startedAt));
179
175
  const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
180
176
  const userAgent = options.userAgent ?? USER_AGENT;
181
177
  const apiKey = (options.anysearchApiKey ?? '').trim();
@@ -275,6 +271,14 @@ export function createFetchProvider(options = {}, overrides = {}) {
275
271
  if (typeof target !== 'string' || !/^https?:\/\//i.test(target)) {
276
272
  throw new SearchError(`not an http(s) URL: ${String(target)}`, 'SEARCH_PARSE', false);
277
273
  }
274
+ // The ladder budget belongs to THIS request. Starting it in the factory
275
+ // made it start at plugin mount, so every fetch more than 25 s after a
276
+ // restart failed with "no time left in the fetch budget" before touching
277
+ // the network.
278
+ const overallMs = options.overallMs ?? DEFAULT_OVERALL_MS;
279
+ const startedAt = Date.now();
280
+ /** What is left of the whole-ladder budget for this request. */
281
+ const remaining = () => Math.max(0, overallMs - (Date.now() - startedAt));
278
282
  const failures = [];
279
283
  /** True once the caller cancelled; a cancellation must not be retried. */
280
284
  const cancelled = () => signal !== undefined && signal.aborted;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fffangchenghao/dsh-web-search",
3
- "version": "0.13.10",
3
+ "version": "0.13.11",
4
4
  "description": "DSH bundle: a key-free web search provider. Leads with the anonymous AnySearch API and falls back to public result pages (DuckDuckGo, Bing, 360), merged by reciprocal-rank fusion with a bilingual region policy, an engine cooldown and a TTL cache.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",