dsh-xdpool 2.6.5 → 2.6.7

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": "dsh-xdpool",
3
3
  "displayName": "DSH XD Pool",
4
4
  "description": "One DSH model pool for every free quota you have: merge all locally signed-in WorkBuddy accounts with auto-failover, sign in to 13 vendors by QR/web, aggregate 76 vendors' free tiers, plus a usage dashboard, model routing, a local OpenAI-compatible gateway and a points-automation suite.",
5
- "version": "2.6.5",
5
+ "version": "2.6.7",
6
6
  "license": "MIT",
7
7
  "author": "XDTrees",
8
8
  "homepage": "https://github.com/XDTrees/dsh-xdpool#readme",
@@ -133,4 +133,4 @@
133
133
  "optional": true
134
134
  }
135
135
  }
136
- }
136
+ }
@@ -72,6 +72,32 @@ function resolvesFromEntry(name) {
72
72
  }
73
73
  }
74
74
 
75
+ /** The installed version of a package directory, or undefined when unreadable. */
76
+ function versionOf(dir) {
77
+ try {
78
+ const manifest = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'))
79
+ return typeof manifest.version === 'string' ? manifest.version : undefined
80
+ } catch {
81
+ return undefined
82
+ }
83
+ }
84
+
85
+ /**
86
+ * The host's copy of a peer, if one can be found.
87
+ *
88
+ * Separate from `locate` because the two answer different questions: `locate` asks "is this
89
+ * importable", `hostCopyOf` asks "where is the host's own copy". The second is needed to
90
+ * detect a version MISMATCH, which is a failure mode `locate` cannot see — the package
91
+ * resolves perfectly well at the wrong generation.
92
+ */
93
+ function hostCopyOf(name) {
94
+ for (const root of hostRoots()) {
95
+ const candidate = join(root, name)
96
+ if (existsSync(join(candidate, 'package.json'))) return candidate
97
+ }
98
+ return undefined
99
+ }
100
+
75
101
  /**
76
102
  * The package directory for `name`, whether or not it can be imported right now.
77
103
  *
@@ -160,13 +186,65 @@ const HARNESS_BASES = [
160
186
  // Linux
161
187
  join(process.env['HOME'] ?? '', '.local', 'share', 'deepseek-harness'),
162
188
  '/opt/DeepSeek Harness',
163
- // Windows
189
+ // Windows, default locations
164
190
  typeof process.env['LOCALAPPDATA'] === 'string' ? join(process.env['LOCALAPPDATA'], 'Programs', 'DeepSeek Harness') : undefined,
165
191
  typeof process.env['LOCALAPPDATA'] === 'string' ? join(process.env['LOCALAPPDATA'], 'DeepSeek Harness') : undefined,
166
192
  typeof process.env['ProgramW6432'] === 'string' ? process.env['ProgramW6432'] : undefined,
167
193
  typeof process.env['PROGRAMFILES'] === 'string' ? process.env['PROGRAMFILES'] : undefined,
194
+ /**
195
+ * Windows, installed on another drive.
196
+ *
197
+ * Not a guess about this particular machine: it is derived from where the PROFILE lives.
198
+ * A DSH profile sits at `<harness data dir>/profiles/<name>`, and on Windows the data
199
+ * directory is often the harness's own folder — which is exactly the layout this repo
200
+ * was developed against (`D:\dsh-home\profiles\desktop` beside `D:\DeepSeek Harness`).
201
+ * When they are siblings, the harness is one segment up with a different name, so the
202
+ * sibling of the data dir is tried as a harness root too.
203
+ *
204
+ * A miss costs nothing, which is why deriving is preferable to hard-coding a drive letter.
205
+ */
206
+ ...siblingHarnessBases(),
168
207
  ]
169
208
 
209
+ /**
210
+ * Harness roots that can be derived from where this profile lives.
211
+ *
212
+ * `D:\dsh-home\profiles\desktop\node_modules\dsh-xdpool` → walk up to the data directory,
213
+ * then try every plausible sibling. Cheap, and it is the only way to find a harness on a
214
+ * non-default drive without asking the user to set an environment variable.
215
+ *
216
+ * Several levels are tried because the two layouts in the wild differ:
217
+ *
218
+ * - `<dataDir>/profiles/<name>` — the data dir's PARENT holds the harness
219
+ * (`D:\dsh-home` beside `D:\DeepSeek Harness`)
220
+ * - the harness IS the data dir's parent — some installs put profiles inside the app
221
+ *
222
+ * A miss costs nothing, which is why deriving beats hard-coding a drive letter.
223
+ */
224
+ function siblingHarnessBases() {
225
+ const out = []
226
+ let dir = PACKAGE_ROOT
227
+ let dataDir
228
+ for (let i = 0; i < 8; i += 1) {
229
+ dir = dirname(dir)
230
+ if (dir === dirname(dir)) break
231
+ // `<x>/profiles/...` means `<x>` is the data directory.
232
+ if (dirname(dir).endsWith('profiles')) { dataDir = dirname(dir); break }
233
+ if (dir.endsWith('profiles')) { dataDir = dirname(dir); break }
234
+ }
235
+ const start = dataDir ?? resolve(PACKAGE_ROOT, '..', '..', '..')
236
+ // Walk up a few levels from the data directory, offering a sibling at each.
237
+ let cursor = start
238
+ for (let i = 0; i < 3; i += 1) {
239
+ out.push(join(cursor, 'DeepSeek Harness'))
240
+ const parent = dirname(cursor)
241
+ if (parent === cursor) break
242
+ out.push(join(parent, 'DeepSeek Harness'))
243
+ cursor = parent
244
+ }
245
+ return out
246
+ }
247
+
170
248
  /** Whether this is a source checkout rather than an installed package. */
171
249
  const IS_SOURCE_CHECKOUT = existsSync(join(PACKAGE_ROOT, 'src'))
172
250
 
@@ -176,16 +254,36 @@ const notFound = []
176
254
  const failed = []
177
255
 
178
256
  for (const name of peerNames()) {
179
- // Already resolvable: leave it alone. Someone who installed a peer deliberately keeps
180
- // control, and re-linking would overwrite that choice. This check is also what makes the
181
- // script idempotent — a second run must not rebuild links it made the first time.
182
- if (locate(name) !== undefined) { alreadyResolved.push(name); continue }
183
- let target
184
- for (const root of hostRoots()) {
185
- const candidate = join(root, name)
186
- // `existsSync` cannot see inside `app.asar`; on a packaged host this simply misses and
187
- // the peer is reported as not found, which is no longer fatal.
188
- if (existsSync(join(candidate, 'package.json'))) { target = candidate; break }
257
+ /**
258
+ * A peer that resolves is only acceptable if its VERSION matches the host's.
259
+ *
260
+ * Resolvability alone is not the contract that matters. `@earendil-works/pi-ai` shipped
261
+ * from a `devDependency` at 0.85.1 while the host ran 1.1.0, and the plugin's own
262
+ * `warnOnPiAiGenerationMismatch` documents the result: two copies on one call chain throw
263
+ * at the adapter seam and the host reports every turn as a non-retryable `PI_AI_ERROR`.
264
+ * The package resolved fine — at the wrong generation.
265
+ *
266
+ * So when the host has a copy and ours differs, the host's copy WINS. That is the whole
267
+ * point of treating these as peer dependencies: the host owns them, and a second
268
+ * generation beside it is a defect rather than a choice.
269
+ */
270
+ const current = locate(name)
271
+ const hostCopy = hostCopyOf(name)
272
+ const hostVersion = hostCopy === undefined ? undefined : versionOf(hostCopy)
273
+ const ours = current === undefined ? undefined : versionOf(current)
274
+ if (current !== undefined && (hostVersion === undefined || ours === hostVersion)) {
275
+ alreadyResolved.push(name)
276
+ continue
277
+ }
278
+ // A mismatch is reported below through `relinked` when the host copy is linked.
279
+ let target = hostCopy
280
+ if (target === undefined) {
281
+ for (const root of hostRoots()) {
282
+ const candidate = join(root, name)
283
+ // `existsSync` cannot see inside `app.asar`; on a packaged host this simply misses and
284
+ // the peer is reported as not found, which is no longer fatal.
285
+ if (existsSync(join(candidate, 'package.json'))) { target = candidate; break }
286
+ }
189
287
  }
190
288
  if (target === undefined) { notFound.push(name); continue }
191
289
  const dest = join(PACKAGE_ROOT, 'node_modules', name)
@@ -197,7 +295,7 @@ for (const name of peerNames()) {
197
295
  // Junction on Windows because creating a real symlink needs elevation there; a
198
296
  // junction needs none and behaves the same for directory reads.
199
297
  symlinkSync(target, dest, process.platform === 'win32' ? 'junction' : 'dir')
200
- linked.push(`${name} → ${target}`)
298
+ linked.push(`${name} → ${target}${ours === undefined ? '' : ` (was ${ours}, host has ${hostVersion ?? '?'})`}`)
201
299
  } catch (error) {
202
300
  failed.push(`${name} (${error instanceof Error ? error.message : String(error)})`)
203
301
  }
@@ -52353,6 +52353,25 @@ function hasZcodeUnusualActivity(body) {
52353
52353
  if (code !== void 0) return isZcodeUnusualActivityCode(code);
52354
52354
  return mentionsZcodeUnusualActivity(body);
52355
52355
  }
52356
+ /**
52357
+ * [xdpool-local] Recognise the risk-control refusal that arrives with NO code and a
52358
+ * non-401 status (#132).
52359
+ *
52360
+ * The reporter's screenshot showed `HTTP 405 · request has been blocked due to unusual
52361
+ * activity` reaching the user as a generic HTTP error, while the same condition on another
52362
+ * request produced the proper 3012 wording. The reason is that the body carries no
52363
+ * `code` field and the status is neither 401 nor 403, so every existing branch missed it —
52364
+ * `hasZcodeUnusualActivity` was consulted only AFTER the code checks, and the fallback
52365
+ * printed `HTTP 405: …`.
52366
+ *
52367
+ * A 405 here is never a real method error: this lane sends one fixed POST. It is the WAF
52368
+ * answering a request it decided not to inspect. Treated as risk control so the user gets
52369
+ * the cooldown warning instead of a status they can do nothing with.
52370
+ */
52371
+ function isZcodeBlockedWithoutCode(status, body) {
52372
+ if (status !== 405 && status !== 403) return false;
52373
+ return /blocked|unusual activity|forbidden/iu.test(body);
52374
+ }
52356
52375
  function looksLikeZcodeUnusualActivity(body) {
52357
52376
  return /(?<![0-9A-Za-z_-])3012(?![0-9A-Za-z_-])/.test(body);
52358
52377
  }
@@ -55690,7 +55709,7 @@ function describeUpstreamError(status, body, diagnostic) {
55690
55709
  if (code === 3007 || trimmed.includes("3007")) {
55691
55710
  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`;
55692
55711
  }
55693
- if (hasZcodeUnusualActivity(trimmed)) {
55712
+ if (hasZcodeUnusualActivity(trimmed) || isZcodeBlockedWithoutCode(status, trimmed)) {
55694
55713
  return formatZcodeUnusualActivityMessage({ diagnostic, rawResponse: suffix });
55695
55714
  }
55696
55715
  if (code === 1002 || status === 401) {
@@ -55701,7 +55720,7 @@ function describeUpstreamError(status, body, diagnostic) {
55701
55720
  function httpErrorCodeForZcode(status, body) {
55702
55721
  const trimmed = body.trim();
55703
55722
  if (trimmed.includes("3007")) return "RATE_LIMIT";
55704
- if (hasZcodeUnusualActivity(trimmed)) return "PERMISSION";
55723
+ if (hasZcodeUnusualActivity(trimmed) || isZcodeBlockedWithoutCode(status, trimmed)) return "PERMISSION";
55705
55724
  if (trimmed.includes("1113") || trimmed.includes("\u4F59\u989D\u4E0D\u8DB3")) return "QUOTA_EXCEEDED";
55706
55725
  if (status === 401 || trimmed.includes("1002")) return "AUTH";
55707
55726
  if (status === 429) return "RATE_LIMIT";
@@ -66934,7 +66953,26 @@ function createChannelFetch(options = {}) {
66934
66953
  let system;
66935
66954
  let systemAt = 0;
66936
66955
  let closed = false;
66937
- const fetchImpl = (input, init) => (options.fetchImpl ?? globalThis.fetch)(input, init);
66956
+ /**
66957
+ * [xdpool-local] Capture the fetch implementation ONCE, not at every call (#140).
66958
+ *
66959
+ * `options.fetchImpl ?? globalThis.fetch` read the global lazily, at call time. When
66960
+ * another plugin patches `globalThis.fetch` — billion-context does, to enforce an 8 MiB
66961
+ * direct-upload gate — that patch became the outbound transport for EVERY channel
66962
+ * request. It has no idea which conversation a request belongs to, so it either refused
66963
+ * the body (422, which the outer layer renders as a 400) or lost the session attribution
66964
+ * the channel needs.
66965
+ *
66966
+ * Binding here means this service uses the implementation that existed when it was
66967
+ * created, so a later patch cannot silently intercept the channel's traffic. An explicit
66968
+ * `options.fetchImpl` still wins — that is how a test or an embedder substitutes one on
66969
+ * purpose.
66970
+ */
66971
+ const boundFetch = options.fetchImpl ?? (typeof globalThis.fetch === "function" ? globalThis.fetch.bind(globalThis) : undefined);
66972
+ const fetchImpl = (input, init) => {
66973
+ if (boundFetch === undefined) throw new Error("\u6E20\u9053\u51FA\u7F51\u670D\u52A1\u7F3A\u5C11 fetch \u5B9E\u73B0");
66974
+ return boundFetch(input, init);
66975
+ };
66938
66976
  const fetcher = async (input, init) => {
66939
66977
  if (closed) throw new Error("\u6E20\u9053\u51FA\u7F51\u670D\u52A1\u5DF2\u505C\u6B62");
66940
66978
  const target = new URL(input instanceof Request ? input.url : String(input));