dsh-codearts 1.1.1 → 1.1.4

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.
@@ -0,0 +1,35 @@
1
+ import { createRequire } from "node:module";
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
10
+ var __exportAll = (all, no_symbols) => {
11
+ let target = {};
12
+ for (var name in all) __defProp(target, name, {
13
+ get: all[name],
14
+ enumerable: true
15
+ });
16
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
17
+ return target;
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
21
+ key = keys[i];
22
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
23
+ get: ((k) => from[k]).bind(null, key),
24
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
25
+ });
26
+ }
27
+ return to;
28
+ };
29
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
30
+ value: mod,
31
+ enumerable: true
32
+ }) : target, mod));
33
+ var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
34
+ //#endregion
35
+ export { __toESM as i, __exportAll as n, __require as r, __commonJSMin as t };
@@ -1,21 +1,10 @@
1
+ import { n as __exportAll } from "./rolldown-runtime-B4iAMlE-.mjs";
1
2
  import { createHash, createHmac, createPrivateKey, createSign, generateKeyPairSync, randomBytes } from "node:crypto";
2
3
  import { chmod, mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
3
4
  import { homedir } from "node:os";
4
5
  import { dirname, join } from "node:path";
5
6
  import http from "node:http";
6
7
  import { existsSync } from "node:fs";
7
- //#region \0rolldown/runtime.js
8
- var __defProp = Object.defineProperty;
9
- var __exportAll = (all, no_symbols) => {
10
- let target = {};
11
- for (var name in all) __defProp(target, name, {
12
- get: all[name],
13
- enumerable: true
14
- });
15
- if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
16
- return target;
17
- };
18
- //#endregion
19
8
  //#region src/dpop.ts
20
9
  /**
21
10
  * DPoP(RFC 9449)证明 JWT:ES256 + P-256,供 oauth2/tokens 请求头使用。
@@ -1246,6 +1235,7 @@ var upstream_exports = /* @__PURE__ */ __exportAll({
1246
1235
  isConcurrencyCap: () => isConcurrencyCap,
1247
1236
  isParamInvalidFrame: () => isParamInvalidFrame,
1248
1237
  isQueueableRate: () => isQueueableRate,
1238
+ isResignRefusal: () => isResignRefusal,
1249
1239
  isTpmLimit: () => isTpmLimit,
1250
1240
  isWelfareClaimedStatus: () => isWelfareClaimedStatus,
1251
1241
  maxTokensCeilingFor: () => maxTokensCeilingFor,
@@ -1596,6 +1586,7 @@ function rateLimitFrame(text) {
1596
1586
  * 让人以为是自己配错了。默认分支仍保留原始信息,便于排查。
1597
1587
  */
1598
1588
  function upstreamErrorMessage(message, status = 0) {
1589
+ if (isResignRefusal(message)) return "本地代理 billion-context 拦下了这条签名请求(它拿不到 CodeArts 凭据做重签,在本地直接拒了),不是你的账号问题:请在 ~/.config/billion-context/billion-context.json 加上 \"resign\": { \"sdk-hmac-sha256\": { \"passthrough\": true } } 后重启 DSH,或为它配置重签凭据。";
1599
1590
  if (MODEL_RATE_CODE.test(message) || MODEL_RATE_TEXT.test(message)) return "华为侧该模型当前请求过多(共享 TPM 超限),不是你的账号或插件问题。稍后重试,或临时改用 GLM-5.2 / GLM-5.3。";
1600
1591
  if (message.includes("TM.00001041")) return "CodeArts 免费档同时只允许 3 个会话,当前槽位一直占满(被打断的会话约 1 分钟才释放)。请稍后重试。";
1601
1592
  if (isBenefitMissing("", message)) return "这个模型属于限时福利,当前福利通道不可用(不是账号问题)。可以刷新模型列表,改用非福利模型。";
@@ -1614,8 +1605,18 @@ const BENEFIT_MISSING_CODE = "InferHub.4004.200";
1614
1605
  function isBenefitMissing(code, message) {
1615
1606
  return code === "InferHub.4004.200" || message.toLowerCase().includes("benefit not found");
1616
1607
  }
1608
+ /**
1609
+ * 本地代理「拒签」标记:billion-context 这类宿主层代理拦截出站请求做上下文压缩,
1610
+ * 碰到 SDK-HMAC-SHA256 签名请求要用 CodeArts 凭据重签;找不到凭据时在**本地**回
1611
+ * 403(根本没出网),body 里带这两个标记。这不是凭据失效 —— 归 session_dead 会把
1612
+ * 账号永久禁用(见 issue #1)。
1613
+ */
1614
+ function isResignRefusal(message) {
1615
+ return message.includes("signed_request_requires_resign") || message.includes("bili_resign_unavailable");
1616
+ }
1617
1617
  function classify(status, message) {
1618
1618
  const m = message.toLowerCase();
1619
+ if (isResignRefusal(message)) return "client";
1619
1620
  if (status === 401 || status === 403) return "session_dead";
1620
1621
  if (status === 402) return "hard_credit";
1621
1622
  if (status === 429) return "soft_rate";
@@ -1625,6 +1626,34 @@ function classify(status, message) {
1625
1626
  if (m.includes("tpm") || m.includes("并发")) return "soft_rate";
1626
1627
  return "client";
1627
1628
  }
1629
+ /**
1630
+ * 出网唯一入口:**只把 URL 字符串和普通 init 交给 fetch,绝不把 Request 对象交出去**。
1631
+ *
1632
+ * 邻居插件会换掉 `globalThis.fetch`(例如 IP 池出口路由直接把 undici 模块自带的
1633
+ * fetch 装成全局)。这时 `globalThis.Request` 还是另一份实例,而 undici 的 fetch
1634
+ * 用 `instanceof` 认自己的 Request:不是自己那份就当 URL 字符串处理,报
1635
+ * `Failed to parse URL from [object Request]`,而且是 HTTP 0(根本没出网)。
1636
+ * 所以 Request 只当签名的载体(signer 要读写它的头部),发出去时拆回纯数据。
1637
+ *
1638
+ * 头部按 forEach 展开会全部变成小写名 —— 签名侧本来也按小写规范化,HTTP 头大小写
1639
+ * 不敏感,上游不受影响。
1640
+ *
1641
+ * @param req 已签好名的请求
1642
+ * @param body 原始请求体;GET/DELETE 传 undefined(带空 body 的 GET 会被 fetch 直接拒)
1643
+ * @param signal 中止信号
1644
+ */
1645
+ async function dispatch(req, body, signal) {
1646
+ const headers = {};
1647
+ req.headers.forEach((value, key) => {
1648
+ headers[key] = value;
1649
+ });
1650
+ return fetch(req.url, {
1651
+ method: req.method,
1652
+ headers,
1653
+ ...body === void 0 ? {} : { body },
1654
+ ...signal === void 0 ? {} : { signal }
1655
+ });
1656
+ }
1628
1657
  const enc = new TextEncoder();
1629
1658
  function openAIData(obj) {
1630
1659
  return enc.encode(`data: ${JSON.stringify(obj)}\n\n`);
@@ -1672,7 +1701,7 @@ async function chatStream(credential, prepared, signal) {
1672
1701
  }
1673
1702
  let resp;
1674
1703
  try {
1675
- resp = await fetch(req, { signal });
1704
+ resp = await dispatch(req, bodyBuf, signal);
1676
1705
  } catch (err) {
1677
1706
  const message = err instanceof Error ? err.message : String(err);
1678
1707
  if (signal?.aborted === true) return {
@@ -1855,7 +1884,7 @@ async function signedGet(url, credential, agentType, signal) {
1855
1884
  });
1856
1885
  let resp;
1857
1886
  try {
1858
- resp = await fetch(req, { signal });
1887
+ resp = await dispatch(req, void 0, signal);
1859
1888
  } catch (error) {
1860
1889
  return {
1861
1890
  ok: false,
@@ -2044,7 +2073,7 @@ async function fetchThinkingVariants(credential, modelIds, signal) {
2044
2073
  secretAccessKey: credential.secretAccessKey,
2045
2074
  securityToken: credential.securityToken
2046
2075
  });
2047
- const resp = await fetch(req, { signal });
2076
+ const resp = await dispatch(req, bodyBuf, signal);
2048
2077
  if (!resp.ok) {
2049
2078
  const text = await resp.text().catch(() => "");
2050
2079
  throw new Error(`thinking-variants HTTP ${resp.status} ${text.slice(0, 200)}`);
@@ -2090,7 +2119,7 @@ async function fetchQueueStatus(credential, chatId, model, signal) {
2090
2119
  secretAccessKey: credential.secretAccessKey,
2091
2120
  securityToken: credential.securityToken
2092
2121
  });
2093
- const resp = await fetch(req, { signal });
2122
+ const resp = await dispatch(req, void 0, signal);
2094
2123
  if (!resp.ok) {
2095
2124
  const text = await resp.text().catch(() => "");
2096
2125
  throw new Error(`queue status HTTP ${resp.status} ${text.slice(0, 200)}`);
@@ -2128,7 +2157,7 @@ async function clearQueueStatus(credential, chatId, model, signal) {
2128
2157
  secretAccessKey: credential.secretAccessKey,
2129
2158
  securityToken: credential.securityToken
2130
2159
  });
2131
- const resp = await fetch(req, { signal });
2160
+ const resp = await dispatch(req, void 0, signal);
2132
2161
  if (!resp.ok) {
2133
2162
  const text = await resp.text().catch(() => "");
2134
2163
  throw new Error(`queue clear HTTP ${resp.status} ${text.slice(0, 200)}`);
@@ -2238,7 +2267,7 @@ async function claimBenefit(credential, abort) {
2238
2267
  secretAccessKey: credential.secretAccessKey,
2239
2268
  securityToken: credential.securityToken
2240
2269
  });
2241
- const resp = await fetch(req, { signal: abort });
2270
+ const resp = await dispatch(req, bodyBuf, abort);
2242
2271
  const raw = await resp.text().catch(() => "");
2243
2272
  if (!resp.ok) throw new Error(`claim benefit failed: ${resp.status} ${raw.slice(0, 200)}`);
2244
2273
  let json;
@@ -2310,7 +2339,7 @@ async function welfareRequest(url, method, credential, body, signal) {
2310
2339
  });
2311
2340
  let resp;
2312
2341
  try {
2313
- resp = await fetch(req, { signal });
2342
+ resp = await dispatch(req, body === void 0 ? void 0 : bodyBuf, signal);
2314
2343
  } catch (error) {
2315
2344
  return {
2316
2345
  ok: false,
@@ -2740,4 +2769,4 @@ function sumOf(store) {
2740
2769
  return out;
2741
2770
  }
2742
2771
  //#endregion
2743
- export { filterEnabledModels as A, rateLimitFrame as C, FALLBACK_CODEARTS_MODELS as D, CodeArtsCatalog as E, codeartsAccountsPath as F, codeartsAuthPath as I, startLogin as L, isBenefitModel as M, CodeArtsAccountStore as N, clearBenefitBlocked as O, CodeArtsCredentialStore as P, prepareChatBody as S, upstreamErrorMessage as T, isQueueableRate as _, SNAP_HOST as a, maxTokensCeilingFor as b, claimDailyWelfare as c, fetchCallerIdentity as d, fetchModels as f, isParamInvalidFrame as g, isConcurrencyCap as h, refreshCatalog as i, isBenefitBlocked as j, creditRatioLabel as k, clearQueueStatus as l, fetchWelfareCampaigns as m, codeartsUsagePath as n, canonicalModel as o, fetchQueueStatus as p, discoverModels as r, chatStream as s, CodeArtsUsageTracker as t, degradeTokenCeiling as u, isTpmLimit as v, signedGet as w, pickDailyWelfareCampaign as x, isWelfareClaimedStatus as y };
2772
+ export { filterEnabledModels as A, rateLimitFrame as C, FALLBACK_CODEARTS_MODELS as D, CodeArtsCatalog as E, MANUAL_ACCOUNT_ID as F, codeartsAccountsPath as I, codeartsAuthPath as L, isBenefitModel as M, CodeArtsAccountStore as N, clearBenefitBlocked as O, CodeArtsCredentialStore as P, startLogin as R, prepareChatBody as S, upstreamErrorMessage as T, isQueueableRate as _, SNAP_HOST as a, maxTokensCeilingFor as b, claimDailyWelfare as c, fetchCallerIdentity as d, fetchModels as f, isParamInvalidFrame as g, isConcurrencyCap as h, refreshCatalog as i, isBenefitBlocked as j, creditRatioLabel as k, clearQueueStatus as l, fetchWelfareCampaigns as m, codeartsUsagePath as n, canonicalModel as o, fetchQueueStatus as p, discoverModels as r, chatStream as s, CodeArtsUsageTracker as t, degradeTokenCeiling as u, isTpmLimit as v, signedGet as w, pickDailyWelfareCampaign as x, isWelfareClaimedStatus as y };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "dsh-codearts",
3
3
  "displayName": "DSH CodeArts Connect",
4
4
  "description": "把华为云 CodeArts 接入 DeepSeek Harness —— 内置 OAuth2 登录(PKCE + DPoP),登录后即可在 DSH 对话窗口使用 CodeArts 的模型。",
5
- "version": "1.1.1",
5
+ "version": "1.1.4",
6
6
  "packageManager": "pnpm@11.24.0",
7
7
  "author": "elegant01",
8
8
  "keywords": [
@@ -92,7 +92,6 @@
92
92
  "@deepseek-ai/dsh-llm-pi-ai": ">=0.1.2-rc.1 <0.3.0-0",
93
93
  "@deepseek-ai/dsh-settings": ">=0.1.2-rc.1 <0.3.0-0",
94
94
  "@deepseek-ai/schemastery": "^3.18.2",
95
- "@earendil-works/pi-ai": ">=0.84.2 <2.0.0",
96
95
  "react": "^18.2.0"
97
96
  },
98
97
  "devDependencies": {