heybash-xdpool 1.0.5 → 1.0.6

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "heybash-xdpool",
3
3
  "displayName": "Heybash",
4
4
  "description": "Heybash model pool for DeepSeek Harness: account rotation, provider aggregation, routing chains, usage insights and a local OpenAI-compatible gateway.",
5
- "version": "1.0.5",
5
+ "version": "1.0.6",
6
6
  "license": "MIT",
7
7
  "author": "Heybash",
8
8
  "contributors": [
@@ -45,10 +45,10 @@ export async function syncMirror({
45
45
  } = {}) {
46
46
  if (version !== undefined && !VERSION.test(version)) throw new Error('Invalid target version')
47
47
  const options = { attempts, intervalMs, sleep, log }
48
- // Match npm/pnpm's metadata representation. The mirror can cache its
49
- // generic */* representation separately from the package-manager response.
48
+ // Match npm/pnpm's install metadata representation. The mirror can cache
49
+ // generic JSON and install metadata independently for several minutes.
50
50
  const read = async (url) => (await request(fetchImpl, url, {
51
- headers: { accept: 'application/json' },
51
+ headers: { accept: 'application/vnd.npm.install-v1+json' },
52
52
  })).json()
53
53
  const official = await retry('Waiting for npm', async () => {
54
54
  const data = await read(NPM)
@@ -52376,6 +52376,25 @@ function hasZcodeUnusualActivity(body) {
52376
52376
  if (code !== void 0) return isZcodeUnusualActivityCode(code);
52377
52377
  return mentionsZcodeUnusualActivity(body);
52378
52378
  }
52379
+ /**
52380
+ * [xdpool-local] Recognise the risk-control refusal that arrives with NO code and a
52381
+ * non-401 status (#132).
52382
+ *
52383
+ * The reporter's screenshot showed `HTTP 405 · request has been blocked due to unusual
52384
+ * activity` reaching the user as a generic HTTP error, while the same condition on another
52385
+ * request produced the proper 3012 wording. The reason is that the body carries no
52386
+ * `code` field and the status is neither 401 nor 403, so every existing branch missed it —
52387
+ * `hasZcodeUnusualActivity` was consulted only AFTER the code checks, and the fallback
52388
+ * printed `HTTP 405: …`.
52389
+ *
52390
+ * A 405 here is never a real method error: this lane sends one fixed POST. It is the WAF
52391
+ * answering a request it decided not to inspect. Treated as risk control so the user gets
52392
+ * the cooldown warning instead of a status they can do nothing with.
52393
+ */
52394
+ function isZcodeBlockedWithoutCode(status, body) {
52395
+ if (status !== 405 && status !== 403) return false;
52396
+ return /blocked|unusual activity|forbidden/iu.test(body);
52397
+ }
52379
52398
  function looksLikeZcodeUnusualActivity(body) {
52380
52399
  return /(?<![0-9A-Za-z_-])3012(?![0-9A-Za-z_-])/.test(body);
52381
52400
  }
@@ -55713,7 +55732,7 @@ function describeUpstreamError(status, body, diagnostic) {
55713
55732
  if (code === 3007 || trimmed.includes("3007")) {
55714
55733
  return `\u963F\u91CC\u4E91 captcha \u6821\u9A8C\u5931\u8D25\uFF083007\uFF09\u3002\u8BF7\u91CD\u8BD5\uFF1B\u82E5\u6301\u7EED\u5931\u8D25\uFF0C\u68C0\u67E5\u6D4F\u89C8\u5668\u662F\u5426\u53EF\u7528\u3002`;
55715
55734
  }
55716
- if (hasZcodeUnusualActivity(trimmed)) {
55735
+ if (hasZcodeUnusualActivity(trimmed) || isZcodeBlockedWithoutCode(status, trimmed)) {
55717
55736
  return formatZcodeUnusualActivityMessage({ diagnostic, rawResponse: suffix });
55718
55737
  }
55719
55738
  if (code === 1002 || status === 401) {
@@ -55724,7 +55743,7 @@ function describeUpstreamError(status, body, diagnostic) {
55724
55743
  function httpErrorCodeForZcode(status, body) {
55725
55744
  const trimmed = body.trim();
55726
55745
  if (trimmed.includes("3007")) return "RATE_LIMIT";
55727
- if (hasZcodeUnusualActivity(trimmed)) return "PERMISSION";
55746
+ if (hasZcodeUnusualActivity(trimmed) || isZcodeBlockedWithoutCode(status, trimmed)) return "PERMISSION";
55728
55747
  if (trimmed.includes("1113") || trimmed.includes("\u4F59\u989D\u4E0D\u8DB3")) return "QUOTA_EXCEEDED";
55729
55748
  if (status === 401 || trimmed.includes("1002")) return "AUTH";
55730
55749
  if (status === 429) return "RATE_LIMIT";
@@ -66957,7 +66976,26 @@ function createChannelFetch(options = {}) {
66957
66976
  let system;
66958
66977
  let systemAt = 0;
66959
66978
  let closed = false;
66960
- const fetchImpl = (input, init) => (options.fetchImpl ?? globalThis.fetch)(input, init);
66979
+ /**
66980
+ * [xdpool-local] Capture the fetch implementation ONCE, not at every call (#140).
66981
+ *
66982
+ * `options.fetchImpl ?? globalThis.fetch` read the global lazily, at call time. When
66983
+ * another plugin patches `globalThis.fetch` — billion-context does, to enforce an 8 MiB
66984
+ * direct-upload gate — that patch became the outbound transport for EVERY channel
66985
+ * request. It has no idea which conversation a request belongs to, so it either refused
66986
+ * the body (422, which the outer layer renders as a 400) or lost the session attribution
66987
+ * the channel needs.
66988
+ *
66989
+ * Binding here means this service uses the implementation that existed when it was
66990
+ * created, so a later patch cannot silently intercept the channel's traffic. An explicit
66991
+ * `options.fetchImpl` still wins — that is how a test or an embedder substitutes one on
66992
+ * purpose.
66993
+ */
66994
+ const boundFetch = options.fetchImpl ?? (typeof globalThis.fetch === "function" ? globalThis.fetch.bind(globalThis) : undefined);
66995
+ const fetchImpl = (input, init) => {
66996
+ if (boundFetch === undefined) throw new Error("\u6E20\u9053\u51FA\u7F51\u670D\u52A1\u7F3A\u5C11 fetch \u5B9E\u73B0");
66997
+ return boundFetch(input, init);
66998
+ };
66961
66999
  const fetcher = async (input, init) => {
66962
67000
  if (closed) throw new Error("\u6E20\u9053\u51FA\u7F51\u670D\u52A1\u5DF2\u505C\u6B62");
66963
67001
  const target = new URL(input instanceof Request ? input.url : String(input));