heybash-xdpool 1.0.4 → 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/CHANGELOG.md +12 -0
- package/lib/bin.js +293 -11
- package/lib/client.js +101 -76
- package/lib/index.d.ts +190 -5
- package/lib/index.js +685 -37
- package/package.json +2 -1
- package/tools/sync-npmmirror.mjs +16 -3
- package/vendor/channel-pack/pack.js +41 -3
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
|
+
"version": "1.0.6",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Heybash",
|
|
8
8
|
"contributors": [
|
|
@@ -101,6 +101,7 @@
|
|
|
101
101
|
"@types/react": "~18.3.31",
|
|
102
102
|
"@types/react-dom": "~18.3.0",
|
|
103
103
|
"react": "^18.2.0",
|
|
104
|
+
"react-dom": "^18.3.1",
|
|
104
105
|
"tsdown": "^0.23.0",
|
|
105
106
|
"typescript": "^7.0.2",
|
|
106
107
|
"vite": "8.3.0",
|
package/tools/sync-npmmirror.mjs
CHANGED
|
@@ -41,11 +41,15 @@ async function retry(label, action, { attempts, intervalMs, sleep, log }) {
|
|
|
41
41
|
*/
|
|
42
42
|
export async function syncMirror({
|
|
43
43
|
version, fetchImpl = fetch, sleep = delay, log = console.log,
|
|
44
|
-
attempts = 24, intervalMs = 10_000, syncAttempts = 3,
|
|
44
|
+
attempts = 24, officialAttempts = attempts * 2, intervalMs = 10_000, syncAttempts = 3,
|
|
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
|
-
|
|
48
|
+
// Match npm/pnpm's install metadata representation. The mirror can cache
|
|
49
|
+
// generic JSON and install metadata independently for several minutes.
|
|
50
|
+
const read = async (url) => (await request(fetchImpl, url, {
|
|
51
|
+
headers: { accept: 'application/vnd.npm.install-v1+json' },
|
|
52
|
+
})).json()
|
|
49
53
|
const official = await retry('Waiting for npm', async () => {
|
|
50
54
|
const data = await read(NPM)
|
|
51
55
|
const target = version ?? data['dist-tags']?.latest
|
|
@@ -53,7 +57,7 @@ export async function syncMirror({
|
|
|
53
57
|
const checksum = data.versions?.[target]?.dist?.shasum
|
|
54
58
|
if (typeof checksum !== 'string' || !/^[a-f0-9]{40}$/u.test(checksum)) throw new Error(`npm ${target} is not yet available with a checksum`)
|
|
55
59
|
return { target, checksum, latest: data['dist-tags']?.latest }
|
|
56
|
-
}, options)
|
|
60
|
+
}, { ...options, attempts: officialAttempts })
|
|
57
61
|
log(`npm target ${official.target}; latest ${official.latest}`)
|
|
58
62
|
|
|
59
63
|
const verify = async (download = false) => {
|
|
@@ -109,6 +113,15 @@ export async function syncMirror({
|
|
|
109
113
|
} catch (error) {
|
|
110
114
|
lastError = error
|
|
111
115
|
log(`Mirror synchronization attempt ${attempt + 1}/${syncAttempts} failed: ${error instanceof Error ? error.message : String(error)}`)
|
|
116
|
+
// A sync task can fail or time out after another worker already updated
|
|
117
|
+
// the mirror. Verify the artifact before submitting a redundant task.
|
|
118
|
+
try {
|
|
119
|
+
const target = await verify(true)
|
|
120
|
+
log(`Mirror serves ${target} with the correct checksum`)
|
|
121
|
+
return { version: target, synced: true }
|
|
122
|
+
} catch {
|
|
123
|
+
// Still unavailable: proceed with the bounded retry below.
|
|
124
|
+
}
|
|
112
125
|
if (attempt + 1 < syncAttempts) await sleep(intervalMs)
|
|
113
126
|
}
|
|
114
127
|
}
|
|
@@ -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
|
-
|
|
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));
|