dsh-xdpool 2.6.7 → 2.7.1

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.7",
5
+ "version": "2.7.1",
6
6
  "license": "MIT",
7
7
  "author": "XDTrees",
8
8
  "homepage": "https://github.com/XDTrees/dsh-xdpool#readme",
@@ -33373,7 +33373,22 @@ var CodeArtsAdapter = class extends LlmAdapter {
33373
33373
  if (currentAccountId) rateLimitTried.add(currentAccountId);
33374
33374
  const isBenefitModel = isCodeArtsBenefitModel(options.model);
33375
33375
  for (; ; ) {
33376
- const extraSignedHeaders = isBenefitModel && !benefitHeaderDropped ? { maas_type: "benefit" } : void 0;
33376
+ /**
33377
+ * [xdpool-local] The benefit header is NEVER sent — issue #150.
33378
+ *
33379
+ * `maas_type: benefit` routes the request onto a lane the upstream has retired: with it
33380
+ * the first frame is `InferHub.APIG.0101.404`, which surfaces as
33381
+ * "The API does not exist or has not been published in the environment". Without it the
33382
+ * SAME model, account, body and endpoint answer normally — measured both ways on
33383
+ * `glm-5.3-flash` and `deepseek-v4.1-flash`.
33384
+ *
33385
+ * #149 read the same failure as "these model ids are no longer published" and proposed
33386
+ * switching them off. Its control group changed the ID rather than the header, and every
33387
+ * id it compared happened to be outside the benefit list — so the variable it meant to
33388
+ * isolate was never isolated, and disabling the ids would have removed two working
33389
+ * models while leaving the real cause in place.
33390
+ */
33391
+ const extraSignedHeaders = void 0;
33377
33392
  const signed = await signRequestHuawei(
33378
33393
  credential.access_key_id,
33379
33394
  credential.secret_access_key,
@@ -37756,6 +37771,59 @@ function buildQoderInferPayload(ask, requestId = crypto.randomUUID()) {
37756
37771
  };
37757
37772
  }
37758
37773
  var gluePromise = null;
37774
+ /**
37775
+ * [xdpool-local] Keep a Qoder payload inside the WASM's memory budget — issue #155.
37776
+ *
37777
+ * WHAT IS CUT, AND IN WHICH ORDER
37778
+ *
37779
+ * Oldest conversation turns go first: they are the least likely to matter for the next reply,
37780
+ * and dropping one whole turn keeps the message list valid (a lone tool result without its
37781
+ * call is what makes a request *invalid* rather than merely shorter). Tool schemas are never
37782
+ * cut — a call without its schema is worse than a shorter history — but the largest ones are
37783
+ * trimmed of their `description`, which is prose the model can do without.
37784
+ *
37785
+ * The budget is deliberately below the ceiling: serialisation produces several copies at
37786
+ * once, so a payload that merely FITS is not enough.
37787
+ */
37788
+ const QODER_PAYLOAD_BYTE_BUDGET = 700 * 1024;
37789
+
37790
+ function shrinkQoderPayload(payload) {
37791
+ const measure = (value) => {
37792
+ try {
37793
+ return Buffer.byteLength(JSON.stringify(value), "utf8");
37794
+ } catch {
37795
+ return Number.MAX_SAFE_INTEGER;
37796
+ }
37797
+ };
37798
+ if (measure(payload) <= QODER_PAYLOAD_BYTE_BUDGET) return payload;
37799
+ const out = { ...payload, messages: Array.isArray(payload.messages) ? [...payload.messages] : [] };
37800
+ // Oldest first, but never the last message: that is the actual question.
37801
+ while (out.messages.length > 2 && measure(out) > QODER_PAYLOAD_BYTE_BUDGET) {
37802
+ out.messages.shift();
37803
+ }
37804
+ // Still too big: drop tool descriptions, which are prose rather than contract.
37805
+ if (measure(out) > QODER_PAYLOAD_BYTE_BUDGET && Array.isArray(out.tools)) {
37806
+ out.tools = out.tools.map((tool) => {
37807
+ const fn = tool && typeof tool === "object" ? tool.function : void 0;
37808
+ if (!fn || typeof fn !== "object" || typeof fn.description !== "string") return tool;
37809
+ return { ...tool, function: { ...fn, description: "" } };
37810
+ });
37811
+ }
37812
+ // Last resort: trim the longest message bodies from the front of the list.
37813
+ let guard = 0;
37814
+ while (measure(out) > QODER_PAYLOAD_BYTE_BUDGET && out.messages.length > 1 && guard < 64) {
37815
+ guard += 1;
37816
+ const first = out.messages[0];
37817
+ if (first && typeof first === "object" && typeof first.content === "string" && first.content.length > 2000) {
37818
+ out.messages[0] = { ...first, content: `${first.content.slice(0, 2000)}
37819
+ …(已截断)` };
37820
+ continue;
37821
+ }
37822
+ out.messages.shift();
37823
+ }
37824
+ return out;
37825
+ }
37826
+
37759
37827
  async function getGlue() {
37760
37828
  gluePromise ??= createGlue();
37761
37829
  return gluePromise;
@@ -37975,7 +38043,22 @@ var QoderEncryptedInfer = class _QoderEncryptedInfer {
37975
38043
  const result = g.callPointer((stack) => {
37976
38044
  const host = g.writeString(this.host);
37977
38045
  const hostLen = g.lastLength();
37978
- const body = g.writeString(JSON.stringify(payload));
38046
+ /**
38047
+ * [xdpool-local] Shrink the payload before it reaches the WASM — issue #155.
38048
+ *
38049
+ * The encrypted-infer glue declares ~1 MB of linear memory, and the whole request is
38050
+ * written into it as UTF-8: the plaintext JSON string, its encoded copy and the WASM
38051
+ * copy all exist at once. A body approaching that ceiling makes `__wbindgen_export2`
38052
+ * fail to allocate, the Rust side panics, and the panic surfaces to DSH as the bare
38053
+ * word `unreachable` — which reads like a network fault and is an out-of-memory abort.
38054
+ *
38055
+ * At a Chinese ratio of ~1.6–2 char/token, 1 MB is ~240k–330k tokens, which is why the
38056
+ * failure was reported as "breaks around 256k context": the limit is BYTES, not the
38057
+ * model's advertised window. Trimming here keeps the request sendable; the caller's
38058
+ * context budget is untouched, so nothing else has to know.
38059
+ */
38060
+ const shrunk = shrinkQoderPayload(payload);
38061
+ const body = g.writeString(JSON.stringify(shrunk));
37979
38062
  const bodyLen = g.lastLength();
37980
38063
  const key = g.writeString(ask.modelKey);
37981
38064
  const keyLen = g.lastLength();
@@ -46776,6 +46859,29 @@ var TraeAuth = class _TraeAuth extends Service5 {
46776
46859
  if (pool) {
46777
46860
  const available2 = await pool.getAvailableAccount(this.product.id, "").catch(() => void 0);
46778
46861
  if (available2) credential = available2.credential;
46862
+ /**
46863
+ * [xdpool-local] Fall back to ANY account the pool holds — issue #154.
46864
+ *
46865
+ * `getAvailableAccount` skips accounts that are cooling down, disabled, or simply not
46866
+ * the current pick. When it answers nothing, the code below resolved
46867
+ * `TRAE_ACCESS_TOKEN`, a ref that only exists on the single-credential path — a scan
46868
+ * login writes `TRAE_ACCOUNT_<hash>` instead, so the resolve was always undefined for
46869
+ * anyone who signed in through the card.
46870
+ *
46871
+ * The result was an empty list, `ensureRemoteModels` silently giving up, and
46872
+ * `listModels` returning the 28 hard-coded fallback rows — models the account does not
46873
+ * have, under names the vendor never published. Re-signing in could not help, because
46874
+ * the ref it wrote was never the one being read.
46875
+ *
46876
+ * Listing one turn does not need a usable account, only a real credential: the model
46877
+ * catalogue is the same for every account of this vendor.
46878
+ */
46879
+ if (credential === void 0) {
46880
+ const all = pool.listAccountsByProvider(this.product.id) ?? [];
46881
+ for (const entry of all) {
46882
+ if (entry.credential !== void 0) { credential = entry.credential; break }
46883
+ }
46884
+ }
46779
46885
  }
46780
46886
  if (credential === void 0) {
46781
46887
  const resolved = await this.ctx.credentials.resolve(credentialRef6(this.credentialRefName));