dsh-free-model 0.5.2 → 0.5.3
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/README.md +9 -2
- package/README_EN.md +9 -2
- package/SECURITY-AUDIT.md +3 -3
- package/package.json +1 -1
- package/vendor/channel-pack/pack.js +913 -249
|
@@ -893,7 +893,7 @@ async function requestToken(body, keyPair, fetcher = fetch) {
|
|
|
893
893
|
if (!response.ok || !data?.credentials) {
|
|
894
894
|
const message2 = `CodeArts token request failed: ${response.status}${data ? ` ${JSON.stringify(data)}` : ""}`;
|
|
895
895
|
const errorCode = String(data?.error_code ?? "");
|
|
896
|
-
if (data?.error === "invalid_grant" || errorCode.includes("ExpiredRefreshToken")) {
|
|
896
|
+
if (data?.error === "invalid_grant" || errorCode.includes("ExpiredRefreshToken") || errorCode.includes("STS5.1806") || /refresh\s*token\s+has\s+been\s+used/i.test(message2)) {
|
|
897
897
|
throw new RefreshTokenExpiredError(message2);
|
|
898
898
|
}
|
|
899
899
|
throw new Error(message2);
|
|
@@ -29339,10 +29339,10 @@ function normalizeModelId(id) {
|
|
|
29339
29339
|
function parseModelInfo(m, seen) {
|
|
29340
29340
|
const rawId = m["model_id"];
|
|
29341
29341
|
if (typeof rawId !== "string" || rawId.length === 0) return void 0;
|
|
29342
|
-
const id =
|
|
29342
|
+
const id = rawId;
|
|
29343
29343
|
if (id.includes("-VL-") || id.endsWith("-VL")) return void 0;
|
|
29344
29344
|
const rawName = m["model_name"];
|
|
29345
|
-
const name2 = typeof rawName === "string" && rawName.length > 0 ?
|
|
29345
|
+
const name2 = typeof rawName === "string" && rawName.length > 0 ? rawName : id;
|
|
29346
29346
|
if (seen.has(id)) return void 0;
|
|
29347
29347
|
seen.add(id);
|
|
29348
29348
|
return { id, name: name2 };
|
|
@@ -32349,6 +32349,95 @@ function isTruncatedArguments(raw) {
|
|
|
32349
32349
|
return true;
|
|
32350
32350
|
}
|
|
32351
32351
|
}
|
|
32352
|
+
var COMPLETE_INVALID_LITERAL_RE = /^(?:NaN|-?Infinity|undefined)$/;
|
|
32353
|
+
var INVISIBLE_FORMAT_RE = /[\p{Cf}]/gu;
|
|
32354
|
+
function classifyToolArguments(raw) {
|
|
32355
|
+
const trimmed = raw.trim();
|
|
32356
|
+
if (trimmed.length === 0) return "ok";
|
|
32357
|
+
try {
|
|
32358
|
+
JSON.parse(trimmed);
|
|
32359
|
+
return "ok";
|
|
32360
|
+
} catch {
|
|
32361
|
+
}
|
|
32362
|
+
if (COMPLETE_INVALID_LITERAL_RE.test(trimmed)) return "invalid";
|
|
32363
|
+
const visible = trimmed.replace(INVISIBLE_FORMAT_RE, "");
|
|
32364
|
+
if (visible !== trimmed) {
|
|
32365
|
+
try {
|
|
32366
|
+
JSON.parse(visible);
|
|
32367
|
+
return "truncated";
|
|
32368
|
+
} catch {
|
|
32369
|
+
}
|
|
32370
|
+
}
|
|
32371
|
+
const last = trimmed[trimmed.length - 1];
|
|
32372
|
+
if (last !== "}" && last !== "]") return "truncated";
|
|
32373
|
+
let braces = 0;
|
|
32374
|
+
let brackets = 0;
|
|
32375
|
+
let inString = false;
|
|
32376
|
+
let escaped = false;
|
|
32377
|
+
for (const ch of trimmed) {
|
|
32378
|
+
if (escaped) {
|
|
32379
|
+
escaped = false;
|
|
32380
|
+
continue;
|
|
32381
|
+
}
|
|
32382
|
+
if (ch === "\\") {
|
|
32383
|
+
escaped = true;
|
|
32384
|
+
continue;
|
|
32385
|
+
}
|
|
32386
|
+
if (ch === '"') {
|
|
32387
|
+
inString = !inString;
|
|
32388
|
+
continue;
|
|
32389
|
+
}
|
|
32390
|
+
if (inString) continue;
|
|
32391
|
+
if (ch === "{") braces += 1;
|
|
32392
|
+
else if (ch === "}") {
|
|
32393
|
+
braces -= 1;
|
|
32394
|
+
if (braces < 0) return "truncated";
|
|
32395
|
+
} else if (ch === "[") brackets += 1;
|
|
32396
|
+
else if (ch === "]") {
|
|
32397
|
+
brackets -= 1;
|
|
32398
|
+
if (brackets < 0) return "truncated";
|
|
32399
|
+
}
|
|
32400
|
+
}
|
|
32401
|
+
if (braces !== 0 || brackets !== 0) return "truncated";
|
|
32402
|
+
if (inString) return "truncated";
|
|
32403
|
+
return "invalid";
|
|
32404
|
+
}
|
|
32405
|
+
var TOOL_ARGS_INVALID_CODE = "TOOL_ARGS_INVALID";
|
|
32406
|
+
function isUsableToolArguments(raw) {
|
|
32407
|
+
if (raw.trim().length === 0) return true;
|
|
32408
|
+
let parsed;
|
|
32409
|
+
try {
|
|
32410
|
+
parsed = JSON.parse(raw);
|
|
32411
|
+
} catch {
|
|
32412
|
+
return false;
|
|
32413
|
+
}
|
|
32414
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return false;
|
|
32415
|
+
return true;
|
|
32416
|
+
}
|
|
32417
|
+
function toolArgsInvalidIsSoleOutput(invalidCount, emittedProse, blocks, upstreamTruncated) {
|
|
32418
|
+
if (invalidCount === 0) return false;
|
|
32419
|
+
if (upstreamTruncated) return false;
|
|
32420
|
+
if (emittedProse !== "") return false;
|
|
32421
|
+
for (const block of blocks) {
|
|
32422
|
+
if (hasUsableToolName(block.name) && isUsableToolArguments(block.text)) return false;
|
|
32423
|
+
}
|
|
32424
|
+
return true;
|
|
32425
|
+
}
|
|
32426
|
+
function toolArgsInvalidBlocks(entries) {
|
|
32427
|
+
const out = [];
|
|
32428
|
+
for (const entry of entries) {
|
|
32429
|
+
out.push({ name: entry.block.name, chars: entry.block.text.length });
|
|
32430
|
+
}
|
|
32431
|
+
return out;
|
|
32432
|
+
}
|
|
32433
|
+
function toolArgsInvalidFailure(blocks) {
|
|
32434
|
+
const shown = blocks.slice(0, 3).map((block) => `${block.name ?? "(\u672A\u547D\u540D\u5DE5\u5177)"}\uFF0C${block.chars} \u5B57\u7B26`).join("\uFF1B");
|
|
32435
|
+
const scope = blocks.length > 3 ? `${shown}\uFF1B\u7B49 ${blocks.length} \u4E2A\u8C03\u7528` : shown;
|
|
32436
|
+
return {
|
|
32437
|
+
message: `\u6A21\u578B\u751F\u6210\u7684\u5DE5\u5177\u53C2\u6570\u4E0D\u662F\u5408\u6CD5 JSON\uFF08${scope}\uFF09\uFF0C\u672C\u6B21\u8C03\u7528\u5DF2\u4E22\u5F03\u3002\u8FD9\u4E0D\u662F\u8F93\u51FA token \u4E0A\u9650\uFF0C\u4E5F\u4E0D\u662F\u7F51\u7EDC\u4E2D\u65AD \u2014\u2014 \u76F4\u63A5\u91CD\u8BD5\u5373\u53EF\uFF1B\u82E5\u8FDE\u7EED\u51FA\u73B0\uFF0C\u5EFA\u8BAE\u66F4\u6362\u6A21\u578B\u6216\u7F29\u5C0F\u8BE5\u6B21\u8C03\u7528\u7684\u8DE8\u5EA6\uFF08\u4F8B\u5982\u4E0A\u4E0B\u6587\u538B\u7F29\u7684 startId\u2013endId \u533A\u95F4\uFF09\u3002`,
|
|
32438
|
+
code: TOOL_ARGS_INVALID_CODE
|
|
32439
|
+
};
|
|
32440
|
+
}
|
|
32352
32441
|
var REASONING_LOOP_CODE = "REASONING_LOOP";
|
|
32353
32442
|
function resolveSliceChars(raw) {
|
|
32354
32443
|
const value = raw ?? 64;
|
|
@@ -33801,6 +33890,33 @@ var CodeArtsAdapter = class extends LlmAdapter {
|
|
|
33801
33890
|
* 懒加载远端模型目录。resolveModel 可能先于 listModels 被调用
|
|
33802
33891
|
* (如直接进入会话),此时同样触发远端拉取。
|
|
33803
33892
|
*/
|
|
33893
|
+
/**
|
|
33894
|
+
* **强制重拉远端目录**(模型上下架自适应;供 `index.ts` 的定时器调用)。
|
|
33895
|
+
*
|
|
33896
|
+
* ## ⚠️⚠️ 只清「已完成」标记,**绝不清 `remoteModels` 数据**
|
|
33897
|
+
*
|
|
33898
|
+
* `ensureRemoteModels` 的失败语义**已经是对的**:
|
|
33899
|
+
* - `fetchRemote()` 抛异常 ⇒ 直接冒出,`remoteModels` **保持旧值**
|
|
33900
|
+
* (用户继续看到旧目录,比退回 `DEFAULT_MODELS` 兜底子集好);
|
|
33901
|
+
* - 返回空数组 ⇒ `return false`(不落缓存、不立刻重试)。
|
|
33902
|
+
*
|
|
33903
|
+
* 若在这里顺手写 `this.remoteModels = undefined` 就会**毁掉**这个好语义:
|
|
33904
|
+
* 一次网络抖动 ⇒ 好端端的旧目录被清 ⇒ `listAllModels()` 落回兜底表
|
|
33905
|
+
*(那是**子集**且**已过期**,实测 3 条已 404)⇒ 用户突然少看到一批模型。
|
|
33906
|
+
*
|
|
33907
|
+
* ⇒ **只清标记**,让 `ensureRemoteModels` 自己决定何时覆盖数据。
|
|
33908
|
+
*
|
|
33909
|
+
* ⚠️ `listAllModels()` 是**同步**读 `remoteModels` 的缓存视图 ⇒ 刷新成功后它
|
|
33910
|
+
* 立刻看到新值(`ensureRemoteModels` 已重新赋值),无需额外「补读」步骤。
|
|
33911
|
+
*
|
|
33912
|
+
* ⚠️ 本方法**必须 public**:`index.ts` 的定时器经 `modelAdapters` 逐家调用
|
|
33913
|
+
*(那里每项是 `withDeadModelPruning` 的 Proxy,新成员自动透出并绑 `this`)。
|
|
33914
|
+
*/
|
|
33915
|
+
async refreshCatalog() {
|
|
33916
|
+
if (this.options.fetchRemoteModels === void 0) return;
|
|
33917
|
+
this.remoteComplete = false;
|
|
33918
|
+
await this.ensureRemoteModels();
|
|
33919
|
+
}
|
|
33804
33920
|
async ensureRemoteModels() {
|
|
33805
33921
|
const fetchRemote = this.options.fetchRemoteModels;
|
|
33806
33922
|
if (this.remoteComplete || fetchRemote === void 0) return;
|
|
@@ -34465,6 +34581,48 @@ function isRateLimited(body, status) {
|
|
|
34465
34581
|
}
|
|
34466
34582
|
var RESET_TIME_PATTERN = /(?:将在|reset at)\s+([\d-]+\s+[\d:]+)\s+(UTC[+-]\d+(?::\d+)?)/i;
|
|
34467
34583
|
var RATE_LIMIT_FALLBACK_MS = 36e5;
|
|
34584
|
+
var CREDIT_EXHAUSTED_BUSINESS_CODE = 14018;
|
|
34585
|
+
var CREDIT_EXHAUSTED_PATTERN = /credits?\s+exhausted|quota\s+exhausted|积分.{0,4}(?:不足|耗尽|用尽)|额度.{0,4}(?:不足|耗尽|用尽)|余额.{0,4}(?:不足|耗尽|用尽)/i;
|
|
34586
|
+
function isCreditExhausted(body) {
|
|
34587
|
+
if (body.length === 0) return false;
|
|
34588
|
+
try {
|
|
34589
|
+
const data = JSON.parse(body);
|
|
34590
|
+
const inner = typeof data.error === "object" && data.error !== null ? data.error : void 0;
|
|
34591
|
+
const nested = typeof inner?.data === "object" && inner.data !== null ? inner.data : void 0;
|
|
34592
|
+
const codes = [data.code, inner?.code, nested?.code];
|
|
34593
|
+
if (codes.some((code) => code === CREDIT_EXHAUSTED_BUSINESS_CODE || code === String(CREDIT_EXHAUSTED_BUSINESS_CODE))) {
|
|
34594
|
+
return true;
|
|
34595
|
+
}
|
|
34596
|
+
} catch {
|
|
34597
|
+
}
|
|
34598
|
+
return CREDIT_EXHAUSTED_PATTERN.test(body);
|
|
34599
|
+
}
|
|
34600
|
+
function creditExhaustedResetAtMs(nowMs = Date.now()) {
|
|
34601
|
+
return nextUtc8DayStartMs(nowMs);
|
|
34602
|
+
}
|
|
34603
|
+
function explicitRateResetAtMs(body) {
|
|
34604
|
+
try {
|
|
34605
|
+
const data = JSON.parse(body);
|
|
34606
|
+
const inner = typeof data.error === "object" && data.error !== null ? data.error : void 0;
|
|
34607
|
+
const nested = typeof inner?.data === "object" && inner.data !== null ? inner.data : void 0;
|
|
34608
|
+
const candidates = [data.msg, inner?.msg, nested?.msg];
|
|
34609
|
+
for (const candidate of candidates) {
|
|
34610
|
+
if (typeof candidate !== "string") continue;
|
|
34611
|
+
const resetMatch = RESET_TIME_PATTERN.exec(candidate);
|
|
34612
|
+
if (!resetMatch) continue;
|
|
34613
|
+
const resetMs = Date.parse(`${resetMatch[1]} ${resetMatch[2]}`);
|
|
34614
|
+
if (!Number.isNaN(resetMs)) return resetMs;
|
|
34615
|
+
}
|
|
34616
|
+
return void 0;
|
|
34617
|
+
} catch {
|
|
34618
|
+
const bareMatch = RESET_TIME_PATTERN.exec(body);
|
|
34619
|
+
if (bareMatch !== null) {
|
|
34620
|
+
const bareMs = Date.parse(`${bareMatch[1]} ${bareMatch[2]}`);
|
|
34621
|
+
if (!Number.isNaN(bareMs)) return bareMs;
|
|
34622
|
+
}
|
|
34623
|
+
return void 0;
|
|
34624
|
+
}
|
|
34625
|
+
}
|
|
34468
34626
|
function parseRateLimitError(body, currentModel, status) {
|
|
34469
34627
|
const fallback = () => ({
|
|
34470
34628
|
modelId: currentModel,
|
|
@@ -34567,8 +34725,11 @@ var CONTENT_FINGERPRINTS = [
|
|
|
34567
34725
|
// 且不动后半句 —— 破坏 agent 提示词的语义比多拦一轮更糟。
|
|
34568
34726
|
// ⚠️ 匹配仍走本文件的**大小写不敏感 + 位置无关** replaceAll(行首锚定是
|
|
34569
34727
|
// 服务端的判据,不是我们的改写范围)—— 改写范围宁可略宽。
|
|
34570
|
-
|
|
34571
|
-
|
|
34728
|
+
// ⚠️ **`find` 刻意不带末尾句点**(对齐上游 76d33062):DSH 哪天把句号改成别的
|
|
34729
|
+
// 标点或去掉,带句点的写法会**静默停止匹配**(症状 = 渠道整轮 400 复发,
|
|
34730
|
+
// 与「完全没登记」同形)。不带句点只要求前 52 字符逐字一致。
|
|
34731
|
+
find: "You are an AI agent powered by DeepSeek Harness",
|
|
34732
|
+
replace: "You are an AI agent built on the DeepSeek Harness runtime",
|
|
34572
34733
|
note: "2026-10-21 \u672C\u673A\u5BF9 copilot.tencent.com \u5B9E\u6D4B\uFF1A\u539F\u53E5 400/11128\u3001\u6539\u5199\u540E 200\uFF083 \u6A21\u578B\u590D\u9A8C\uFF09"
|
|
34573
34734
|
},
|
|
34574
34735
|
{
|
|
@@ -34698,6 +34859,38 @@ var CONTENT_FINGERPRINTS = [
|
|
|
34698
34859
|
// 实测两端点均 200(buddy / workbuddy,2026-10-18)。措辞与原文等义。
|
|
34699
34860
|
replace: "To give feedback, users should report the issue at the project issue tracker",
|
|
34700
34861
|
note: "Gitee IKLYCT\uFF1B\u672C\u673A 2026-10-18 \u5BF9 workbuddy / CodeBuddy \u53CC\u7AEF\u70B9\u5B9E\u6D4B\uFF1Asystem\uFF08\u542B\u975E\u9996\u4F4D\uFF09\u4E0E assistant \u6B63\u6587\u5747 400/11128\uFF0Cuser / reasoning_content / tool \u7ED3\u679C\u653E\u884C\uFF0C\u6539\u5199\u540E\u4E24\u7AEF\u70B9\u5747 200"
|
|
34862
|
+
},
|
|
34863
|
+
{
|
|
34864
|
+
// ★ **DSH 的 Web GUI 环境说明句**(2026-10-29 本机二分定位,**上游尚未登记**)。
|
|
34865
|
+
//
|
|
34866
|
+
// ## 怎么发现的:前两条都已改写、整段仍 400 逼出来的第三条
|
|
34867
|
+
//
|
|
34868
|
+
// 0.5.2 上线后本机复验:真实 system 里身份首句与 `@` 文件引用句**都确认已改写**,
|
|
34869
|
+
// 但**整段仍然 400**。行级二分 58 行 → 定位到这一行(1111 字符),
|
|
34870
|
+
// 再前缀二分到**精确 221 字符**(220 放行)。
|
|
34871
|
+
//
|
|
34872
|
+
// ## 触发性(本机 2026-10-29,copilot.tencent.com,真实账号)
|
|
34873
|
+
//
|
|
34874
|
+
// | 探针 | 结果 |
|
|
34875
|
+
// |---|---|
|
|
34876
|
+
// | 该行整行(1111 字符) | ❌ 400 |
|
|
34877
|
+
// | 改 `they mean this GUI` → `they mean the GUI` | ✅ **200(采用)** |
|
|
34878
|
+
// | 改 `DeepSeek Harness Web GUI` → `… web interface` | ✅ 200 |
|
|
34879
|
+
// | 改 `You are interacting` → `You are talking` | ✅ 200 |
|
|
34880
|
+
//
|
|
34881
|
+
// ⇒ 服务端认**逐字符长字面量**,改任一字符即放行。
|
|
34882
|
+
//
|
|
34883
|
+
// ## 为什么选「this GUI → the GUI」
|
|
34884
|
+
//
|
|
34885
|
+
// 三种改法都实测 200。选这一条因为**不碰专有名词、不改动词、句长几乎不变、
|
|
34886
|
+
// 语义完全等同**(两者都指当前这个 GUI)。改 `Web GUI` 会动产品名形态,
|
|
34887
|
+
// 改 `interacting` 会改语气 —— 都没必要。
|
|
34888
|
+
//
|
|
34889
|
+
// ⚠️ 已知边界(与 `@` 那条同型):服务端认逐字符长字面量 ⇒ DSH 改动这句任一
|
|
34890
|
+
// 字符,本规则会**静默停止匹配**(症状 = 该渠道整轮 400 复发)。
|
|
34891
|
+
find: 'You are interacting with the user through the DeepSeek Harness Web GUI whose URL the runtime context names. When the user refers to "this page", "this GUI", or "this app" without naming another target, they mean this GUI.',
|
|
34892
|
+
replace: 'You are interacting with the user through the DeepSeek Harness Web GUI whose URL the runtime context names. When the user refers to "this page", "the GUI", or "this app" without naming another target, they mean the GUI.',
|
|
34893
|
+
note: "2026-10-29 \u672C\u673A\u4E8C\u5206\u5B9A\u4F4D\uFF08\u4E0A\u6E38\u5C1A\u672A\u767B\u8BB0\uFF09\uFF1A221 \u5B57\u7B26\u5B57\u9762\u91CF\u3001220 \u653E\u884C\uFF1B\u524D\u4E24\u6761\u5DF2\u6539\u5199\u4F46\u6574\u6BB5\u4ECD 400 \u65F6\u903C\u51FA\u6765\u7684\u7B2C\u4E09\u6761\uFF1B\u6539 this GUI\u2192the GUI \u5B9E\u6D4B 200"
|
|
34701
34894
|
}
|
|
34702
34895
|
];
|
|
34703
34896
|
function escapeRegExp(literal) {
|
|
@@ -35216,6 +35409,27 @@ var BuddyAdapter = class _BuddyAdapter extends LlmAdapter2 {
|
|
|
35216
35409
|
pixelBudget: this.product.imagePixelBudget
|
|
35217
35410
|
});
|
|
35218
35411
|
}
|
|
35412
|
+
/**
|
|
35413
|
+
* **强制重拉远端目录**(模型上下架自适应;供 `index.ts` 的定时器调用)。
|
|
35414
|
+
*
|
|
35415
|
+
* ## ⚠️⚠️ 只清 `remoteComplete`,**三个缓存字段都不清**
|
|
35416
|
+
*
|
|
35417
|
+
* 本类的目录缓存有**三个联动字段**(`remoteModels` / `remoteMeta` /
|
|
35418
|
+
* `remoteContextWindows`),它们由 `ensureRemoteModels` 内部**一起重建** ⇒
|
|
35419
|
+
* 清标记后重拉即可,手动清任何一个都会制造「只更新一半」的不一致中间态。
|
|
35420
|
+
*
|
|
35421
|
+
* 失败语义(与 codearts 同):拉取抛异常 ⇒ `ensureRemoteModels` 直接冒出、
|
|
35422
|
+
* **三个字段都保留旧值**;返回空数组 ⇒ `return false`(不落缓存)。
|
|
35423
|
+
* ⇒ 一次网络抖动不会把好端端的旧目录清成兜底子集。
|
|
35424
|
+
*
|
|
35425
|
+
* ⚠️ 本类服务**两个产品**(buddy / workbuddy),各自一个实例 ⇒ 定时器按
|
|
35426
|
+
* `modelAdapters` 的两项分别调用,各自刷新,互不影响。
|
|
35427
|
+
*/
|
|
35428
|
+
async refreshCatalog() {
|
|
35429
|
+
if (this.options.fetchRemoteModels === void 0) return;
|
|
35430
|
+
this.remoteComplete = false;
|
|
35431
|
+
await this.ensureRemoteModels();
|
|
35432
|
+
}
|
|
35219
35433
|
async ensureRemoteModels() {
|
|
35220
35434
|
const fetchRemote = this.options.fetchRemoteModels;
|
|
35221
35435
|
if (this.remoteComplete || fetchRemote === void 0) return;
|
|
@@ -35684,12 +35898,21 @@ var BuddyAdapter = class _BuddyAdapter extends LlmAdapter2 {
|
|
|
35684
35898
|
}
|
|
35685
35899
|
}
|
|
35686
35900
|
const channelRejected = isChannelVerificationRejection(errorText, response.status);
|
|
35687
|
-
|
|
35901
|
+
const contentRejectedOn400 = isContentRejection(errorText);
|
|
35902
|
+
if (this.options.accountPool && (isRateLimited(errorText, response.status) || channelRejected || contentRejectedOn400)) {
|
|
35688
35903
|
const tried = /* @__PURE__ */ new Set();
|
|
35689
35904
|
if (currentAccountId) tried.add(currentAccountId);
|
|
35690
|
-
let sawContentRejection =
|
|
35691
|
-
let contentRejectionStatus = 0;
|
|
35692
|
-
let contentRejectionBody = "";
|
|
35905
|
+
let sawContentRejection = contentRejectedOn400;
|
|
35906
|
+
let contentRejectionStatus = contentRejectedOn400 ? response.status : 0;
|
|
35907
|
+
let contentRejectionBody = contentRejectedOn400 ? errorText : "";
|
|
35908
|
+
if (contentRejectedOn400 && currentAccountId !== "") {
|
|
35909
|
+
await markPolicyBlockedAccount(
|
|
35910
|
+
this.options.accountPool,
|
|
35911
|
+
this.product.id,
|
|
35912
|
+
currentAccountId,
|
|
35913
|
+
options.model
|
|
35914
|
+
);
|
|
35915
|
+
}
|
|
35693
35916
|
let sawChannelVerification = channelRejected;
|
|
35694
35917
|
let channelVerificationStatus = channelRejected ? response.status : 0;
|
|
35695
35918
|
let channelVerificationBody = channelRejected ? errorText : "";
|
|
@@ -35698,10 +35921,12 @@ var BuddyAdapter = class _BuddyAdapter extends LlmAdapter2 {
|
|
|
35698
35921
|
if (currentAccountId !== "" && isRateLimited(errorText, response.status) && !rateLimitMarked.has(currentAccountId)) {
|
|
35699
35922
|
rateLimitMarked.add(currentAccountId);
|
|
35700
35923
|
const parsed = parseRateLimitError(errorText, options.model, response.status);
|
|
35924
|
+
const creditExhausted = isCreditExhausted(errorText);
|
|
35925
|
+
const resetAtMs = creditExhausted ? explicitRateResetAtMs(errorText) ?? creditExhaustedResetAtMs() : parsed?.resetTimeMs ?? Date.now() + RATE_LIMIT_FALLBACK_MS;
|
|
35701
35926
|
await this.options.accountPool.updateModelRateLimit(
|
|
35702
35927
|
currentAccountId,
|
|
35703
35928
|
parsed?.modelId ?? options.model,
|
|
35704
|
-
|
|
35929
|
+
resetAtMs
|
|
35705
35930
|
);
|
|
35706
35931
|
}
|
|
35707
35932
|
const next = await this.options.accountPool.getAvailableAccount(
|
|
@@ -36043,6 +36268,7 @@ var BuddyAdapter = class _BuddyAdapter extends LlmAdapter2 {
|
|
|
36043
36268
|
}
|
|
36044
36269
|
}
|
|
36045
36270
|
const argsTruncated = [...toolCalls.values()].some((block) => isTruncatedArguments(block.text));
|
|
36271
|
+
const invalidArgEntries = [...toolCalls.values()].filter((block) => hasUsableToolName(block.name)).map((block) => ({ block, kind: classifyToolArguments(block.text) })).filter((entry) => entry.kind === "invalid");
|
|
36046
36272
|
const droppedUnnamedCalls = [...toolCalls.values()].some((block) => !block.announced);
|
|
36047
36273
|
const proseCutByStopString = finishReason2 === "stop" && toolOrder.length === 0 && isProseTruncatedByStopString(emittedProse);
|
|
36048
36274
|
const reasoningLoopIsSoleOutput = loopDetected && emittedProse === "" && toolOrder.length === 0;
|
|
@@ -36050,7 +36276,12 @@ var BuddyAdapter = class _BuddyAdapter extends LlmAdapter2 {
|
|
|
36050
36276
|
loopGuard?.diagnostics,
|
|
36051
36277
|
options.maxTokens,
|
|
36052
36278
|
"reasoning"
|
|
36053
|
-
) } : loopDetected ? { kind: "max-tokens" } :
|
|
36279
|
+
) } : loopDetected ? { kind: "max-tokens" } : toolArgsInvalidIsSoleOutput(
|
|
36280
|
+
invalidArgEntries.length,
|
|
36281
|
+
emittedProse,
|
|
36282
|
+
toolCalls.values(),
|
|
36283
|
+
argsTruncated
|
|
36284
|
+
) ? { kind: "error", failure: toolArgsInvalidFailure(toolArgsInvalidBlocks(invalidArgEntries)) } : finishReason2 === "length" || finishReason2 === void 0 && toolOrder.length > 0 || argsTruncated || proseCutByStopString || droppedUnnamedCalls && toolOrder.length === 0 ? { kind: "max-tokens" } : finishReason2 === "tool_calls" || toolOrder.length > 0 ? { kind: "tool-calls" } : { kind: "stop" };
|
|
36054
36285
|
yield { type: "finish", reason: resolveEmptyResponseReason(reason, blockCount) };
|
|
36055
36286
|
}
|
|
36056
36287
|
};
|
|
@@ -36789,6 +37020,30 @@ var LobsteraiAdapter = class extends LlmAdapter3 {
|
|
|
36789
37020
|
* `listModels` 与 `resolveModel` 共用:`resolveModel` 可能先于 `listModels`
|
|
36790
37021
|
* 被调用(如直接从历史会话进入),此时同样需要触发一次拉取。
|
|
36791
37022
|
*/
|
|
37023
|
+
/**
|
|
37024
|
+
* **强制重拉远端目录**(模型上下架自适应;供 `index.ts` 的定时器调用)。
|
|
37025
|
+
*
|
|
37026
|
+
* ## ⚠️⚠️ 本类短路判据是 `remoteModels !== undefined`(不是 `remoteComplete`)
|
|
37027
|
+
*
|
|
37028
|
+
* ⇒ 必须**先清 `remoteModels`** 才能触发重拉;但清掉后若重拉失败,
|
|
37029
|
+
* `ensureRemoteModels` 会**保留 undefined** ⇒ 目录退回**兜底子表**(那是个**子集**
|
|
37030
|
+
* 且**已过期**)⇒ 一次网络抖动就让用户少看到一批模型。
|
|
37031
|
+
*
|
|
37032
|
+
* ⇒ 采用**保存—尝试—失败恢复**:旧目录先存下来,重拉后若仍为空就放回去。
|
|
37033
|
+
* 这样「刷新失败」与「不刷新」对用户是无差别的(都继续看旧目录)。
|
|
37034
|
+
*/
|
|
37035
|
+
async refreshCatalog() {
|
|
37036
|
+
if (this.options.fetchRemoteModels === void 0) return;
|
|
37037
|
+
const previous = this.remoteModels;
|
|
37038
|
+
this.remoteModels = void 0;
|
|
37039
|
+
try {
|
|
37040
|
+
await this.ensureRemoteModels();
|
|
37041
|
+
} finally {
|
|
37042
|
+
if (this.remoteModels === void 0 && previous !== void 0) {
|
|
37043
|
+
this.remoteModels = previous;
|
|
37044
|
+
}
|
|
37045
|
+
}
|
|
37046
|
+
}
|
|
36792
37047
|
async ensureRemoteModels() {
|
|
36793
37048
|
const fetchRemote = this.options.fetchRemoteModels;
|
|
36794
37049
|
if (this.remoteModels !== void 0 || fetchRemote === void 0) return;
|
|
@@ -38787,6 +39042,7 @@ async function* consumeOpenAiSse(response, options, config) {
|
|
|
38787
39042
|
}
|
|
38788
39043
|
}
|
|
38789
39044
|
const argsTruncated = [...toolCalls.values()].some((block) => isTruncatedArguments(block.text));
|
|
39045
|
+
const invalidArgEntries = [...toolCalls.values()].filter((block) => hasUsableToolName(block.name)).map((block) => ({ block, kind: classifyToolArguments(block.text) })).filter((entry) => entry.kind === "invalid");
|
|
38790
39046
|
const incompleteTools = finishReason2 === void 0 && toolOrder.length > 0;
|
|
38791
39047
|
const droppedUnnamedCalls = [...toolCalls.values()].some((block) => !block.announced);
|
|
38792
39048
|
if (!sawDataFrame) {
|
|
@@ -38805,7 +39061,12 @@ async function* consumeOpenAiSse(response, options, config) {
|
|
|
38805
39061
|
loopGuard?.diagnostics,
|
|
38806
39062
|
config.maxTokens,
|
|
38807
39063
|
"reasoning"
|
|
38808
|
-
) } : loopDetected ? { kind: "max-tokens" } :
|
|
39064
|
+
) } : loopDetected ? { kind: "max-tokens" } : toolArgsInvalidIsSoleOutput(
|
|
39065
|
+
invalidArgEntries.length,
|
|
39066
|
+
emittedProse,
|
|
39067
|
+
toolCalls.values(),
|
|
39068
|
+
truncatedStream
|
|
39069
|
+
) ? { kind: "error", failure: toolArgsInvalidFailure(toolArgsInvalidBlocks(invalidArgEntries)) } : finishReason2 === "length" || incompleteTools || truncatedStream || argsTruncated || proseCutByStopString || droppedUnnamedCalls && toolOrder.length === 0 ? { kind: "max-tokens" } : finishReason2 === "tool_calls" || toolOrder.length > 0 ? { kind: "tool-calls" } : { kind: "stop" };
|
|
38809
39070
|
yield { type: "finish", reason: resolveEmptyResponseReason(reason, blockCount) };
|
|
38810
39071
|
}
|
|
38811
39072
|
|
|
@@ -40371,6 +40632,9 @@ function collectImages4(content, refs) {
|
|
|
40371
40632
|
if (block.type === "tool-result" && Array.isArray(block.content)) collectImages4(block.content, refs);
|
|
40372
40633
|
}
|
|
40373
40634
|
}
|
|
40635
|
+
function serializeTraeMessagesForTest(messages, imageUrls) {
|
|
40636
|
+
return serializeTraeMessages(messages, imageUrls);
|
|
40637
|
+
}
|
|
40374
40638
|
function serializeTraeMessages(messages, imageUrls) {
|
|
40375
40639
|
const wire = [];
|
|
40376
40640
|
const normalized = normalizeHarnessMessages(messages);
|
|
@@ -40386,6 +40650,7 @@ function serializeTraeMessages(messages, imageUrls) {
|
|
|
40386
40650
|
};
|
|
40387
40651
|
for (const message2 of normalized) {
|
|
40388
40652
|
if (message2.role === "assistant") {
|
|
40653
|
+
flushToolImages();
|
|
40389
40654
|
const content2 = stripCourseLeakFromHistoryContent(
|
|
40390
40655
|
message2.role,
|
|
40391
40656
|
Array.isArray(message2.content) ? message2.content : []
|
|
@@ -40444,8 +40709,8 @@ function serializeTraeMessages(messages, imageUrls) {
|
|
|
40444
40709
|
flushToolImages();
|
|
40445
40710
|
wire.push({ role: "user", content: parts ?? text });
|
|
40446
40711
|
}
|
|
40447
|
-
flushToolImages();
|
|
40448
40712
|
}
|
|
40713
|
+
flushToolImages();
|
|
40449
40714
|
return wire;
|
|
40450
40715
|
}
|
|
40451
40716
|
function errorDetail5(body) {
|
|
@@ -40528,6 +40793,30 @@ var TraeAdapter = class extends LlmAdapter5 {
|
|
|
40528
40793
|
return { id, name: this.product.displayName };
|
|
40529
40794
|
}
|
|
40530
40795
|
/** 懒加载远端模型目录(仅拉取一次)。 */
|
|
40796
|
+
/**
|
|
40797
|
+
* **强制重拉远端目录**(模型上下架自适应;供 `index.ts` 的定时器调用)。
|
|
40798
|
+
*
|
|
40799
|
+
* ## ⚠️⚠️ 本类短路判据是 `remoteModels !== undefined`(不是 `remoteComplete`)
|
|
40800
|
+
*
|
|
40801
|
+
* ⇒ 必须**先清 `remoteModels`** 才能触发重拉;但清掉后若重拉失败,
|
|
40802
|
+
* `ensureRemoteModels` 会**保留 undefined** ⇒ 目录退回**兜底子表**(那是个**子集**
|
|
40803
|
+
* 且**已过期**)⇒ 一次网络抖动就让用户少看到一批模型。
|
|
40804
|
+
*
|
|
40805
|
+
* ⇒ 采用**保存—尝试—失败恢复**:旧目录先存下来,重拉后若仍为空就放回去。
|
|
40806
|
+
* 这样「刷新失败」与「不刷新」对用户是无差别的(都继续看旧目录)。
|
|
40807
|
+
*/
|
|
40808
|
+
async refreshCatalog() {
|
|
40809
|
+
if (this.options.fetchRemoteModels === void 0) return;
|
|
40810
|
+
const previous = this.remoteModels;
|
|
40811
|
+
this.remoteModels = void 0;
|
|
40812
|
+
try {
|
|
40813
|
+
await this.ensureRemoteModels();
|
|
40814
|
+
} finally {
|
|
40815
|
+
if (this.remoteModels === void 0 && previous !== void 0) {
|
|
40816
|
+
this.remoteModels = previous;
|
|
40817
|
+
}
|
|
40818
|
+
}
|
|
40819
|
+
}
|
|
40531
40820
|
async ensureRemoteModels() {
|
|
40532
40821
|
const fetchRemote = this.options.fetchRemoteModels;
|
|
40533
40822
|
if (this.remoteModels !== void 0 || fetchRemote === void 0) return;
|
|
@@ -42111,6 +42400,31 @@ var ClineAdapter = class extends LlmAdapter6 {
|
|
|
42111
42400
|
* ⚠️ **并发去重**:`listModels` 与 `resolveModel` 会在启动时被 DSH 并发调用,
|
|
42112
42401
|
* 不去重会打出多份重复的远端请求(两个端点各一次,乘以并发数)。
|
|
42113
42402
|
*/
|
|
42403
|
+
/**
|
|
42404
|
+
* **强制重拉远端目录**(模型上下架自适应;供 `index.ts` 的定时器调用)。
|
|
42405
|
+
*
|
|
42406
|
+
* ## ⚠️⚠️ 本类短路判据是 `remoteModels !== undefined`(不是 `remoteComplete`)
|
|
42407
|
+
*
|
|
42408
|
+
* ⇒ 必须**先清 `remoteModels`** 才能触发重拉;但清掉后若重拉失败,
|
|
42409
|
+
* `ensureRemoteModels` 会**保留 undefined** ⇒ 目录退回**兜底子表**(那是个**子集**
|
|
42410
|
+
* 且**已过期**)⇒ 一次网络抖动就让用户少看到一批模型。
|
|
42411
|
+
*
|
|
42412
|
+
* ⇒ 采用**保存—尝试—失败恢复**:旧目录先存下来,重拉后若仍为空就放回去。
|
|
42413
|
+
* 这样「刷新失败」与「不刷新」对用户是无差别的(都继续看旧目录)。
|
|
42414
|
+
*/
|
|
42415
|
+
async refreshCatalog() {
|
|
42416
|
+
if (this.options.fetchRemoteModels === void 0) return;
|
|
42417
|
+
this.remoteComplete = false;
|
|
42418
|
+
const previous = this.remoteModels;
|
|
42419
|
+
this.remoteModels = void 0;
|
|
42420
|
+
try {
|
|
42421
|
+
await this.ensureRemoteModels();
|
|
42422
|
+
} finally {
|
|
42423
|
+
if (this.remoteModels === void 0 && previous !== void 0) {
|
|
42424
|
+
this.remoteModels = previous;
|
|
42425
|
+
}
|
|
42426
|
+
}
|
|
42427
|
+
}
|
|
42114
42428
|
async ensureRemoteModels() {
|
|
42115
42429
|
if (this.remoteComplete) return;
|
|
42116
42430
|
await this.catalogGate.run(async () => {
|
|
@@ -42797,6 +43111,32 @@ var LoomyAdapter = class extends LlmAdapter7 {
|
|
|
42797
43111
|
* 改为:只缓存**真实远端目录**,兜底表每次现算(纯本地、零成本),
|
|
42798
43112
|
* 并用 {@link RemoteCatalogGate} 的冷却挡住「每模型重试一次」的放大。
|
|
42799
43113
|
*/
|
|
43114
|
+
/**
|
|
43115
|
+
* **强制重拉远端目录**(模型上下架自适应;供 `index.ts` 的定时器调用)。
|
|
43116
|
+
*
|
|
43117
|
+
* ## ⚠️⚠️ 本类短路判据是 `if (this.remoteModels !== undefined) return`(在 `loadModels` 里)
|
|
43118
|
+
*
|
|
43119
|
+
* ⇒ 必须**先清 `remoteModels`** 才能触发重拉;但清掉后若重拉失败,`loadModels`
|
|
43120
|
+
* 会**返回兜底子表**并把结果留在 `remoteModels` 之外 ⇒ 用户少看到一批模型。
|
|
43121
|
+
*
|
|
43122
|
+
* ⇒ **保存—尝试—失败恢复**:旧目录先存下来,重拉后若没拿到远端就放回去
|
|
43123
|
+
*(「刷新失败」与「不刷新」对用户无差别,都继续看旧目录)。
|
|
43124
|
+
*
|
|
43125
|
+
* ⚠️ 判据是「`remoteModels` 是否被**远端**填上」,不能用「`loadModels` 返回了什么」:
|
|
43126
|
+
* 它在拿不到远端时**照样返回兜底表**(那是展示用,不落 `remoteModels`)。
|
|
43127
|
+
*/
|
|
43128
|
+
async refreshCatalog() {
|
|
43129
|
+
if (this.options.fetchRemoteModels === void 0) return;
|
|
43130
|
+
const previous = this.remoteModels;
|
|
43131
|
+
this.remoteModels = void 0;
|
|
43132
|
+
try {
|
|
43133
|
+
await this.loadModels();
|
|
43134
|
+
} finally {
|
|
43135
|
+
if (this.remoteModels === void 0 && previous !== void 0) {
|
|
43136
|
+
this.remoteModels = previous;
|
|
43137
|
+
}
|
|
43138
|
+
}
|
|
43139
|
+
}
|
|
42800
43140
|
async loadModels() {
|
|
42801
43141
|
if (this.remoteModels !== void 0) return this.remoteModels;
|
|
42802
43142
|
const fetchRemote = this.options.fetchRemoteModels;
|
|
@@ -43261,6 +43601,32 @@ var RaccoonAdapter = class extends LlmAdapter8 {
|
|
|
43261
43601
|
* 改为:只缓存**真实远端目录**,兜底表每次现算(纯本地、零成本),
|
|
43262
43602
|
* 并用 {@link RemoteCatalogGate} 的冷却挡住「每模型重试一次」的放大。
|
|
43263
43603
|
*/
|
|
43604
|
+
/**
|
|
43605
|
+
* **强制重拉远端目录**(模型上下架自适应;供 `index.ts` 的定时器调用)。
|
|
43606
|
+
*
|
|
43607
|
+
* ## ⚠️⚠️ 本类短路判据是 `if (this.remoteModels !== undefined) return`(在 `loadModels` 里)
|
|
43608
|
+
*
|
|
43609
|
+
* ⇒ 必须**先清 `remoteModels`** 才能触发重拉;但清掉后若重拉失败,`loadModels`
|
|
43610
|
+
* 会**返回兜底子表**并把结果留在 `remoteModels` 之外 ⇒ 用户少看到一批模型。
|
|
43611
|
+
*
|
|
43612
|
+
* ⇒ **保存—尝试—失败恢复**:旧目录先存下来,重拉后若没拿到远端就放回去
|
|
43613
|
+
*(「刷新失败」与「不刷新」对用户无差别,都继续看旧目录)。
|
|
43614
|
+
*
|
|
43615
|
+
* ⚠️ 判据是「`remoteModels` 是否被**远端**填上」,不能用「`loadModels` 返回了什么」:
|
|
43616
|
+
* 它在拿不到远端时**照样返回兜底表**(那是展示用,不落 `remoteModels`)。
|
|
43617
|
+
*/
|
|
43618
|
+
async refreshCatalog() {
|
|
43619
|
+
if (this.options.fetchRemoteModels === void 0) return;
|
|
43620
|
+
const previous = this.remoteModels;
|
|
43621
|
+
this.remoteModels = void 0;
|
|
43622
|
+
try {
|
|
43623
|
+
await this.loadModels();
|
|
43624
|
+
} finally {
|
|
43625
|
+
if (this.remoteModels === void 0 && previous !== void 0) {
|
|
43626
|
+
this.remoteModels = previous;
|
|
43627
|
+
}
|
|
43628
|
+
}
|
|
43629
|
+
}
|
|
43264
43630
|
async loadModels() {
|
|
43265
43631
|
if (this.remoteModels !== void 0) return this.remoteModels;
|
|
43266
43632
|
const fetchRemote = this.options.fetchRemoteModels;
|
|
@@ -43622,9 +43988,13 @@ var RefreshScheduler = class {
|
|
|
43622
43988
|
|
|
43623
43989
|
// vendor/channel-pack/src/expiry-sync.ts
|
|
43624
43990
|
var EXPIRY_TOLERANCE_MS = 1e3;
|
|
43625
|
-
function shouldRefreshNow(expiresAtMs, nowMs = Date.now()) {
|
|
43991
|
+
function shouldRefreshNow(expiresAtMs, nowMs = Date.now(), refreshExpiresAtMs) {
|
|
43626
43992
|
if (expiresAtMs === void 0 || !Number.isFinite(expiresAtMs)) return true;
|
|
43627
|
-
|
|
43993
|
+
if (expiresAtMs - nowMs <= REFRESH_LEAD_MS) return true;
|
|
43994
|
+
if (refreshExpiresAtMs !== void 0 && Number.isFinite(refreshExpiresAtMs) && refreshExpiresAtMs - nowMs <= REFRESH_LEAD_MS) {
|
|
43995
|
+
return true;
|
|
43996
|
+
}
|
|
43997
|
+
return false;
|
|
43628
43998
|
}
|
|
43629
43999
|
async function syncAccountExpiry(params) {
|
|
43630
44000
|
const { pool, provider, credential, accessors, accountId, current, tag: tag2 } = params;
|
|
@@ -43671,7 +44041,16 @@ async function refreshAccountWithReconcile(params) {
|
|
|
43671
44041
|
if (refreshed === void 0) {
|
|
43672
44042
|
throw new Error(`${tag2} \u7EED\u671F\u54CD\u5E94\u7F3A\u5C11\u8BBF\u95EE\u4EE4\u724C\uFF0C\u51ED\u636E\u672A\u66F4\u65B0`);
|
|
43673
44043
|
}
|
|
43674
|
-
|
|
44044
|
+
try {
|
|
44045
|
+
await save(refreshed);
|
|
44046
|
+
} catch (error) {
|
|
44047
|
+
params.warn?.(
|
|
44048
|
+
`${tag2} \u8D26\u53F7 ${accountId} \u7EED\u671F**\u5DF2\u6210\u529F\u4F46\u843D\u76D8\u5931\u8D25**\uFF08${provider}\uFF09\uFF1A${error instanceof Error ? error.message : String(error)} \u21D2 refresh_token \u5DF2\u5728\u670D\u52A1\u7AEF\u88AB\u6D88\u8017\uFF0C\u672C\u5730\u51ED\u636E\u5DF2\u5931\u6548\uFF0C\u9700\u91CD\u65B0\u767B\u5F55`
|
|
44049
|
+
);
|
|
44050
|
+
throw params.makeTerminalError(
|
|
44051
|
+
`${tag2} \u8D26\u53F7 ${accountId} \u7EED\u671F\u6210\u529F\u4F46**\u65B0\u51ED\u636E\u843D\u76D8\u5931\u8D25**\uFF1A${provider} \u7684 refresh_token \u662F\u4E00\u6B21\u6027\u7684\uFF0C\u670D\u52A1\u7AEF\u90A3\u4EFD\u5DF2\u88AB\u6D88\u8017\uFF0C\u672C\u5730\u4ECD\u505C\u7559\u5728\u65E7 token \u4E0A\uFF0C\u7EE7\u7EED\u91CD\u8BD5\u53EA\u4F1A\u5F97\u5230\u300C\u5DF2\u88AB\u4F7F\u7528\u300D\u21D2 \u5FC5\u987B\u91CD\u65B0\u767B\u5F55\u3002\u843D\u76D8\u9519\u8BEF\uFF1A${error instanceof Error ? error.message : String(error)}`
|
|
44052
|
+
);
|
|
44053
|
+
}
|
|
43675
44054
|
await syncAccountExpiry({
|
|
43676
44055
|
pool,
|
|
43677
44056
|
provider,
|
|
@@ -43686,6 +44065,192 @@ async function refreshAccountWithReconcile(params) {
|
|
|
43686
44065
|
return true;
|
|
43687
44066
|
}
|
|
43688
44067
|
|
|
44068
|
+
// vendor/channel-pack/src/minimax-product.ts
|
|
44069
|
+
var MINIMAX_FALLBACK_MODELS = [
|
|
44070
|
+
{
|
|
44071
|
+
id: "MiniMax-M3.1-Flash-Preview",
|
|
44072
|
+
name: "M3.1-Flash-Preview",
|
|
44073
|
+
contextWindow: 1e6,
|
|
44074
|
+
maxTokens: 128e3,
|
|
44075
|
+
supportsImage: true,
|
|
44076
|
+
effortOptions: ["default", "low", "medium", "high", "xhigh", "max"],
|
|
44077
|
+
defaultEffort: "default",
|
|
44078
|
+
// ⚠️ forced_on:传 disabled 会被服务端**硬拒**(400 `requires adaptive
|
|
44079
|
+
// thinking ... (2013)`,实测)。它与 M2.7 的 forced_on 不同形态:
|
|
44080
|
+
// M2.7 是**静默忽略**,M3.1 是**报错**。
|
|
44081
|
+
thinkingMode: "forced_on"
|
|
44082
|
+
},
|
|
44083
|
+
{
|
|
44084
|
+
id: "MiniMax-M3",
|
|
44085
|
+
name: "M3",
|
|
44086
|
+
contextWindow: 1e6,
|
|
44087
|
+
maxTokens: 128e3,
|
|
44088
|
+
supportsImage: true,
|
|
44089
|
+
// ⚠️ 实测可开关思考(`switchable`):不传/disabled → 0 思考块,
|
|
44090
|
+
// adaptive → 有思考块。官方形态见远端 `variants`。
|
|
44091
|
+
// ⚠️ 但它**没有 `effort_options`** ⇒ 没有「档位」可选,
|
|
44092
|
+
// 只有「开/关」两态 —— 与 Qoder `qmodel` 的「只有关闭思考」同型。
|
|
44093
|
+
thinkingMode: "switchable"
|
|
44094
|
+
},
|
|
44095
|
+
{
|
|
44096
|
+
id: "MiniMax-M2.7-highspeed",
|
|
44097
|
+
name: "M2.7-highspeed",
|
|
44098
|
+
contextWindow: 2e5,
|
|
44099
|
+
maxTokens: 128e3,
|
|
44100
|
+
supportsImage: false,
|
|
44101
|
+
// ⚠️ forced_on:传 disabled 被**静默忽略**(实测仍产出思考块)
|
|
44102
|
+
thinkingMode: "forced_on"
|
|
44103
|
+
},
|
|
44104
|
+
{
|
|
44105
|
+
id: "MiniMax-M2.7",
|
|
44106
|
+
name: "M2.7",
|
|
44107
|
+
contextWindow: 2e5,
|
|
44108
|
+
maxTokens: 128e3,
|
|
44109
|
+
supportsImage: false,
|
|
44110
|
+
thinkingMode: "forced_on"
|
|
44111
|
+
}
|
|
44112
|
+
];
|
|
44113
|
+
var MINIMAX = {
|
|
44114
|
+
id: "minimax",
|
|
44115
|
+
displayName: "MiniMax Code",
|
|
44116
|
+
accountHost: "https://account.minimax.cn",
|
|
44117
|
+
apiHost: "https://agent.minimax.cn",
|
|
44118
|
+
region: "cn",
|
|
44119
|
+
buildEnv: "prod",
|
|
44120
|
+
clientId: "mcode-public",
|
|
44121
|
+
audience: "agent-backend",
|
|
44122
|
+
scope: "agent.default",
|
|
44123
|
+
defaultCredentialRef: "MINIMAX_ACCESS_TOKEN",
|
|
44124
|
+
fallbackModels: MINIMAX_FALLBACK_MODELS,
|
|
44125
|
+
maxImageBytesInline: 10 * 1024 * 1024,
|
|
44126
|
+
maxRequestBodyBytes: 64 * 1024 * 1024
|
|
44127
|
+
};
|
|
44128
|
+
var MINIMAX_DEVICE_CODE_PATH = "/oauth2/device/code";
|
|
44129
|
+
var MINIMAX_TOKEN_PATH = "/oauth2/token";
|
|
44130
|
+
var MINIMAX_MODELS_PATH = "/mavis/api/v1/models";
|
|
44131
|
+
var MINIMAX_INFER_PATH = "/mavis/api/v1/llm/v1/messages";
|
|
44132
|
+
var MINIMAX_SIGNIN_STATUS_PATH = "/minimax-cloud/api/v1/signin/status";
|
|
44133
|
+
var MINIMAX_SIGNIN_CLAIM_PATH = "/minimax-cloud/api/v1/signin/claim";
|
|
44134
|
+
var MINIMAX_CREDIT_DETAILS_PATH = "/minimax-cloud/api/v1/credit/details";
|
|
44135
|
+
var MINIMAX_REQUEST_TIMEOUT_MS = 3e4;
|
|
44136
|
+
var MINIMAX_OAUTH_TIMEOUT_MS = 2e4;
|
|
44137
|
+
|
|
44138
|
+
// vendor/channel-pack/src/minimax.ts
|
|
44139
|
+
function decodeJwtExpMs2(token) {
|
|
44140
|
+
const segments = token.split(".");
|
|
44141
|
+
if (segments.length !== 3 || segments[1] === void 0) return void 0;
|
|
44142
|
+
try {
|
|
44143
|
+
const payload = JSON.parse(Buffer.from(segments[1], "base64url").toString("utf8"));
|
|
44144
|
+
return typeof payload.exp === "number" && Number.isFinite(payload.exp) ? Number.isFinite(payload.exp * 1e3) ? payload.exp * 1e3 : void 0 : void 0;
|
|
44145
|
+
} catch {
|
|
44146
|
+
return void 0;
|
|
44147
|
+
}
|
|
44148
|
+
}
|
|
44149
|
+
function decodeJwtSub(token) {
|
|
44150
|
+
const segments = token.split(".");
|
|
44151
|
+
if (segments.length !== 3 || segments[1] === void 0) return void 0;
|
|
44152
|
+
try {
|
|
44153
|
+
const payload = JSON.parse(Buffer.from(segments[1], "base64url").toString("utf8"));
|
|
44154
|
+
return typeof payload.sub === "string" && payload.sub.length > 0 ? payload.sub : void 0;
|
|
44155
|
+
} catch {
|
|
44156
|
+
return void 0;
|
|
44157
|
+
}
|
|
44158
|
+
}
|
|
44159
|
+
function minimaxCredentialExpiresAtMs(credential) {
|
|
44160
|
+
const raw = credential.expires_at;
|
|
44161
|
+
if (raw !== void 0) {
|
|
44162
|
+
if (/^\d+$/.test(raw)) {
|
|
44163
|
+
const value = Number(raw);
|
|
44164
|
+
const parsed = value > 1e12 ? value : value * 1e3;
|
|
44165
|
+
if (Number.isFinite(parsed) && parsed > 0) return parsed;
|
|
44166
|
+
}
|
|
44167
|
+
}
|
|
44168
|
+
return decodeJwtExpMs2(credential.access_token);
|
|
44169
|
+
}
|
|
44170
|
+
function isMinimaxExpired(credential, nowMs = Date.now()) {
|
|
44171
|
+
const expiresAt = minimaxCredentialExpiresAtMs(credential);
|
|
44172
|
+
return expiresAt !== void 0 && nowMs >= expiresAt;
|
|
44173
|
+
}
|
|
44174
|
+
function isMinimaxRefreshable(credential) {
|
|
44175
|
+
return typeof credential.refresh_token === "string" && credential.refresh_token.length > 0;
|
|
44176
|
+
}
|
|
44177
|
+
function minimaxHeaders(credential) {
|
|
44178
|
+
const headers = new Headers();
|
|
44179
|
+
headers.set("Authorization", `Bearer ${credential.access_token}`);
|
|
44180
|
+
headers.set("Accept", "application/json");
|
|
44181
|
+
return headers;
|
|
44182
|
+
}
|
|
44183
|
+
function minimaxInferHeaders(credential) {
|
|
44184
|
+
const headers = new Headers();
|
|
44185
|
+
headers.set("Authorization", `Bearer ${credential.access_token}`);
|
|
44186
|
+
headers.set("Content-Type", "application/json");
|
|
44187
|
+
headers.set("Accept", "text/event-stream");
|
|
44188
|
+
return headers;
|
|
44189
|
+
}
|
|
44190
|
+
function positiveInt(value) {
|
|
44191
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : void 0;
|
|
44192
|
+
}
|
|
44193
|
+
function nonEmptyString(value) {
|
|
44194
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
44195
|
+
}
|
|
44196
|
+
function stringArray(value) {
|
|
44197
|
+
if (!Array.isArray(value)) return void 0;
|
|
44198
|
+
const out = [];
|
|
44199
|
+
const seen = /* @__PURE__ */ new Set();
|
|
44200
|
+
for (const item of value) {
|
|
44201
|
+
const text = nonEmptyString(item);
|
|
44202
|
+
if (text === void 0 || seen.has(text)) continue;
|
|
44203
|
+
seen.add(text);
|
|
44204
|
+
out.push(text);
|
|
44205
|
+
}
|
|
44206
|
+
return out.length > 0 ? out : void 0;
|
|
44207
|
+
}
|
|
44208
|
+
function normalizeMinimaxModel(raw) {
|
|
44209
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return void 0;
|
|
44210
|
+
const record = raw;
|
|
44211
|
+
const id = nonEmptyString(record.id) ?? nonEmptyString(record.name);
|
|
44212
|
+
if (id === void 0) return void 0;
|
|
44213
|
+
const name2 = nonEmptyString(record.name) ?? id;
|
|
44214
|
+
const limit = typeof record.limit === "object" && record.limit !== null ? record.limit : {};
|
|
44215
|
+
const options = Array.isArray(record.context_window_options) ? record.context_window_options.filter((v) => positiveInt(v) !== void 0) : [];
|
|
44216
|
+
const limitContext = positiveInt(limit.context);
|
|
44217
|
+
const contextWindow = options.length > 0 ? Math.max(...options) : limitContext;
|
|
44218
|
+
const modalities = typeof record.modalities === "object" && record.modalities !== null ? record.modalities : {};
|
|
44219
|
+
const inputs = Array.isArray(modalities.input) ? modalities.input.filter((v) => typeof v === "string") : [];
|
|
44220
|
+
const effortOptions = stringArray(record.effort_options);
|
|
44221
|
+
const rawDefault = nonEmptyString(record.default_effort);
|
|
44222
|
+
const defaultEffort = rawDefault !== void 0 && effortOptions?.includes(rawDefault) === true ? rawDefault : void 0;
|
|
44223
|
+
const thinkingConfig = typeof record.thinking_config === "object" && record.thinking_config !== null ? record.thinking_config : void 0;
|
|
44224
|
+
const thinkingMode = thinkingConfig === void 0 ? void 0 : nonEmptyString(thinkingConfig.mode);
|
|
44225
|
+
const maxTokens = positiveInt(limit.output);
|
|
44226
|
+
return {
|
|
44227
|
+
id,
|
|
44228
|
+
name: name2,
|
|
44229
|
+
// 窗口未知时**不编造**:用 0 表示「不知道」,由 resolveModel 判 `> 0`
|
|
44230
|
+
contextWindow: contextWindow ?? 0,
|
|
44231
|
+
...maxTokens === void 0 ? {} : { maxTokens },
|
|
44232
|
+
supportsImage: inputs.includes("image"),
|
|
44233
|
+
...effortOptions === void 0 ? {} : { effortOptions },
|
|
44234
|
+
...defaultEffort === void 0 ? {} : { defaultEffort },
|
|
44235
|
+
...thinkingMode === void 0 ? {} : { thinkingMode }
|
|
44236
|
+
};
|
|
44237
|
+
}
|
|
44238
|
+
function fallbackToEntry(model) {
|
|
44239
|
+
return {
|
|
44240
|
+
id: model.id,
|
|
44241
|
+
name: model.name,
|
|
44242
|
+
contextWindow: model.contextWindow,
|
|
44243
|
+
maxTokens: model.maxTokens,
|
|
44244
|
+
supportsImage: model.supportsImage,
|
|
44245
|
+
...model.effortOptions === void 0 ? {} : { effortOptions: model.effortOptions },
|
|
44246
|
+
...model.defaultEffort === void 0 ? {} : { defaultEffort: model.defaultEffort },
|
|
44247
|
+
...model.thinkingMode === void 0 ? {} : { thinkingMode: model.thinkingMode }
|
|
44248
|
+
};
|
|
44249
|
+
}
|
|
44250
|
+
function minimaxFallbackEntries(product = MINIMAX) {
|
|
44251
|
+
return product.fallbackModels.map(fallbackToEntry);
|
|
44252
|
+
}
|
|
44253
|
+
|
|
43689
44254
|
// vendor/channel-pack/src/service.ts
|
|
43690
44255
|
function isCodeArtsRefreshable(credential) {
|
|
43691
44256
|
return Boolean(
|
|
@@ -43698,6 +44263,24 @@ var CODEARTS_EXPIRY_ACCESSORS = {
|
|
|
43698
44263
|
return Number.isFinite(parsed) ? parsed : void 0;
|
|
43699
44264
|
},
|
|
43700
44265
|
refreshableOf: isCodeArtsRefreshable,
|
|
44266
|
+
/**
|
|
44267
|
+
* **refresh_token 自己的过期时刻**(上游 577b27a7 / 真实报废事故)。
|
|
44268
|
+
*
|
|
44269
|
+
* ⚠️ 华为 STS 的 `refresh_token` JWT 里 `exp` **恒等于「登录时刻 + 30 天」**,
|
|
44270
|
+
* **续期不延长它**;而 `access_token` 寿命恒为 2 小时。⇒ 最后一天两侧严重
|
|
44271
|
+
* 不对称:lead-time 最早放行时刻是 `access 到期 − 60m`,可能**晚于** refresh
|
|
44272
|
+
* 的死亡时刻(实测某账号差 5.8 分钟)⇒ 那次续期「成功得太晚」、随后 refresh
|
|
44273
|
+
* 已只剩 54 分钟寿命 ⇒ 账号报废,而面板仍显示「自动续期」。
|
|
44274
|
+
*
|
|
44275
|
+
* ⇒ 补这条腿让 refresh 也进入 lead-time 判据(两条腿取「或」,见
|
|
44276
|
+
* `shouldRefreshNow` 的注释:「与」会把「refresh 还有 3 天、access 只剩 2 分钟」
|
|
44277
|
+
* 这个**正常态**误判成不用续)。
|
|
44278
|
+
*
|
|
44279
|
+
* ⚠️ 复用 `decodeJwtExpMs`(已处理 `exp` 溢出成 `Infinity` 的形态,那种情况返回
|
|
44280
|
+
* `undefined` 而不是一个假的无限远时刻)。不是 JWT / 无 refresh_token 时返回
|
|
44281
|
+
* `undefined` ⇒ 判据退化成单腿(与改动前逐字节相同)。
|
|
44282
|
+
*/
|
|
44283
|
+
refreshExpiresAtOf: (credential) => decodeJwtExpMs2(credential.refresh_token ?? ""),
|
|
43701
44284
|
identityOf: (credential) => credential.access_key_id ?? ""
|
|
43702
44285
|
};
|
|
43703
44286
|
var CODEARTS_CREDENTIAL_REF = "CODEARTS_ACCESS_TOKEN";
|
|
@@ -43992,6 +44575,7 @@ var CodeArtsAuth = class extends Service {
|
|
|
43992
44575
|
current: entry,
|
|
43993
44576
|
refresh: (c) => this.refreshCredentialUnderLock(entry.credentialRef, c),
|
|
43994
44577
|
save: (c) => this.ctx.credentials.set(ref, JSON.stringify(c)),
|
|
44578
|
+
makeTerminalError: (message2) => new RefreshTokenExpiredError(message2),
|
|
43995
44579
|
warn: (message2) => this.ctx.logger?.warn?.(message2),
|
|
43996
44580
|
info: (message2) => this.ctx.logger?.info?.(message2)
|
|
43997
44581
|
});
|
|
@@ -44360,6 +44944,7 @@ var BuddyAuth = class extends Service2 {
|
|
|
44360
44944
|
current: entry,
|
|
44361
44945
|
refresh: (c) => this.refreshCredential(c),
|
|
44362
44946
|
save: (c) => this.ctx.credentials.set(ref, JSON.stringify(c)),
|
|
44947
|
+
makeTerminalError: (message2) => new RefreshTokenExpiredError2(message2),
|
|
44363
44948
|
warn: (message2) => this.ctx.logger?.warn?.(message2)
|
|
44364
44949
|
});
|
|
44365
44950
|
} catch (error) {
|
|
@@ -45051,6 +45636,7 @@ var LobsteraiAuth = class extends Service3 {
|
|
|
45051
45636
|
current: entry,
|
|
45052
45637
|
refresh: (c) => this.refreshCredential(c),
|
|
45053
45638
|
save: (c) => this.ctx.credentials.set(ref, JSON.stringify(c)),
|
|
45639
|
+
makeTerminalError: (message2) => new RefreshTokenExpiredError3(message2),
|
|
45054
45640
|
warn: (message2) => this.ctx.logger?.warn?.(message2)
|
|
45055
45641
|
});
|
|
45056
45642
|
} catch (error) {
|
|
@@ -45563,6 +46149,7 @@ var QoderAuth = class extends Service4 {
|
|
|
45563
46149
|
current: entry,
|
|
45564
46150
|
refresh: (c) => this.refreshCredential(c),
|
|
45565
46151
|
save: (c) => this.ctx.credentials.set(ref, JSON.stringify(c)),
|
|
46152
|
+
makeTerminalError: (message2) => new RefreshTokenExpiredError4(message2),
|
|
45566
46153
|
warn: (message2) => this.ctx.logger?.warn?.(message2)
|
|
45567
46154
|
});
|
|
45568
46155
|
} catch (error) {
|
|
@@ -46312,6 +46899,7 @@ var TraeAuth = class _TraeAuth extends Service5 {
|
|
|
46312
46899
|
current: entry,
|
|
46313
46900
|
refresh: (c) => this.refreshCredential(c),
|
|
46314
46901
|
save: (c) => this.ctx.credentials.set(ref, JSON.stringify(c)),
|
|
46902
|
+
makeTerminalError: (message2) => new RefreshTokenExpiredError5(message2),
|
|
46315
46903
|
warn: (message2) => this.ctx.logger?.warn?.(message2)
|
|
46316
46904
|
});
|
|
46317
46905
|
} catch (error) {
|
|
@@ -47058,6 +47646,7 @@ var ClineAuth = class extends Service6 {
|
|
|
47058
47646
|
current: entry,
|
|
47059
47647
|
refresh: (c) => this.refreshCredential(c),
|
|
47060
47648
|
save: (c) => this.ctx.credentials.set(ref, JSON.stringify(c)),
|
|
47649
|
+
makeTerminalError: (message2) => new RefreshTokenExpiredError6(message2),
|
|
47061
47650
|
warn: (message2) => this.ctx.logger?.warn?.(message2)
|
|
47062
47651
|
});
|
|
47063
47652
|
} catch (error) {
|
|
@@ -54059,7 +54648,7 @@ var OFFICIAL_STABLE_SECTIONS = [
|
|
|
54059
54648
|
'# ZCode Desktop Context\n\n### Files & URLs\n- Return local web URLs as Markdown links (e.g., [label](http://127.0.0.1:8080)).\n- File should be an absolute path or include the workspace folder segment so it can be resolved relative to the workspace.\n- Unless otherwise specified, return local file references as Markdown links (e.g., [name.md](/absolute/path/to/name.md)).\n\n### Inline Code Comments\n- Use the ::code-comment{...} directive when you need to attach feedback directly to specific code lines.\n- Emit one directive per inline comment; emit none when there are no actionable inline comments.\n- Required attributes: title (short label), body (one-paragraph explanation), file (path to the file).\n- Optional attributes: start, end (1-based line numbers), priority (0-3).\n- file should be an absolute path or include the workspace folder segment so it can be resolved relative to the workspace.\n- Keep line ranges tight; end defaults to start.\n- Example: ::code-comment{title="[P2] Off-by-one" body="Loop iterates past the end when length is 0." file="/path/to/foo.ts" start=10 end=11 priority=2}',
|
|
54060
54649
|
"# Working style\n\nWhen you have enough information to act, act. Do not re-derive facts already established in the conversation, re-litigate a decision the user has already made, or narrate options you will not pursue. If you are weighing a choice, give a recommendation, not an exhaustive survey. Prefer reading the actual file or running the actual command over reasoning about what it probably contains. When a signal pattern-matches to a known failure, check that the evidence actually supports that specific diagnosis before acting on it."
|
|
54061
54650
|
];
|
|
54062
|
-
function buildZcodeSystemBlocks(
|
|
54651
|
+
function buildZcodeSystemBlocks(options) {
|
|
54063
54652
|
const ephemeral = { type: "ephemeral" };
|
|
54064
54653
|
const stable = OFFICIAL_STABLE_SECTIONS.join("\n\n");
|
|
54065
54654
|
const blocks = [
|
|
@@ -54067,13 +54656,34 @@ function buildZcodeSystemBlocks(callerSystem, options) {
|
|
|
54067
54656
|
{ type: "text", text: stable },
|
|
54068
54657
|
{ type: "text", text: buildEnvironmentSection(options) }
|
|
54069
54658
|
];
|
|
54070
|
-
if (typeof callerSystem === "string" && callerSystem.trim().length > 0) {
|
|
54071
|
-
blocks.push({ type: "text", text: callerSystem });
|
|
54072
|
-
}
|
|
54073
54659
|
const last = blocks[blocks.length - 1];
|
|
54074
54660
|
if (last !== void 0) last.cache_control = ephemeral;
|
|
54075
54661
|
return blocks;
|
|
54076
54662
|
}
|
|
54663
|
+
function withCallerSystem(messages, callerSystem) {
|
|
54664
|
+
const out = messages.map((message2) => ({ ...message2 }));
|
|
54665
|
+
if (typeof callerSystem !== "string" || callerSystem.trim().length === 0) return out;
|
|
54666
|
+
const first = out[0];
|
|
54667
|
+
const targetIndex = first !== void 0 && first.role === "user" ? 0 : out.findIndex((message2) => message2.role === "user");
|
|
54668
|
+
if (targetIndex < 0) return out;
|
|
54669
|
+
const target = out[targetIndex];
|
|
54670
|
+
if (target === void 0) return out;
|
|
54671
|
+
const block = { type: "text", text: callerSystem };
|
|
54672
|
+
const content = target.content;
|
|
54673
|
+
if (Array.isArray(content)) {
|
|
54674
|
+
const already = content.some(
|
|
54675
|
+
(item) => item?.text === callerSystem
|
|
54676
|
+
);
|
|
54677
|
+
if (already) return out;
|
|
54678
|
+
target.content = [...content, block];
|
|
54679
|
+
} else if (typeof content === "string") {
|
|
54680
|
+
if (content === callerSystem) return out;
|
|
54681
|
+
target.content = [{ type: "text", text: content }, block];
|
|
54682
|
+
} else {
|
|
54683
|
+
target.content = [block];
|
|
54684
|
+
}
|
|
54685
|
+
return out;
|
|
54686
|
+
}
|
|
54077
54687
|
function buildEnvironmentSection(options) {
|
|
54078
54688
|
const cwd = options.cwd.trim().length > 0 ? options.cwd : ".";
|
|
54079
54689
|
const provider = options.provider ?? "zcode";
|
|
@@ -54735,6 +55345,32 @@ var ZcodeAdapter = class extends LlmAdapter9 {
|
|
|
54735
55345
|
* 改为:只缓存**真实远端目录**,兜底表每次现算(纯本地、零成本),
|
|
54736
55346
|
* 并用 {@link RemoteCatalogGate} 的冷却挡住「每模型重试一次」的放大。
|
|
54737
55347
|
*/
|
|
55348
|
+
/**
|
|
55349
|
+
* **强制重拉远端目录**(模型上下架自适应;供 `index.ts` 的定时器调用)。
|
|
55350
|
+
*
|
|
55351
|
+
* ## ⚠️⚠️ 本类短路判据是 `if (this.remoteModels !== undefined) return`(在 `loadModels` 里)
|
|
55352
|
+
*
|
|
55353
|
+
* ⇒ 必须**先清 `remoteModels`** 才能触发重拉;但清掉后若重拉失败,`loadModels`
|
|
55354
|
+
* 会**返回兜底子表**并把结果留在 `remoteModels` 之外 ⇒ 用户少看到一批模型。
|
|
55355
|
+
*
|
|
55356
|
+
* ⇒ **保存—尝试—失败恢复**:旧目录先存下来,重拉后若没拿到远端就放回去
|
|
55357
|
+
*(「刷新失败」与「不刷新」对用户无差别,都继续看旧目录)。
|
|
55358
|
+
*
|
|
55359
|
+
* ⚠️ 判据是「`remoteModels` 是否被**远端**填上」,不能用「`loadModels` 返回了什么」:
|
|
55360
|
+
* 它在拿不到远端时**照样返回兜底表**(那是展示用,不落 `remoteModels`)。
|
|
55361
|
+
*/
|
|
55362
|
+
async refreshCatalog() {
|
|
55363
|
+
if (this.options.fetchRemoteModels === void 0) return;
|
|
55364
|
+
const previous = this.remoteModels;
|
|
55365
|
+
this.remoteModels = void 0;
|
|
55366
|
+
try {
|
|
55367
|
+
await this.loadModels();
|
|
55368
|
+
} finally {
|
|
55369
|
+
if (this.remoteModels === void 0 && previous !== void 0) {
|
|
55370
|
+
this.remoteModels = previous;
|
|
55371
|
+
}
|
|
55372
|
+
}
|
|
55373
|
+
}
|
|
54738
55374
|
async loadModels() {
|
|
54739
55375
|
if (this.remoteModels !== void 0) return this.remoteModels;
|
|
54740
55376
|
const fetchRemote = this.options.fetchRemoteModels;
|
|
@@ -54964,8 +55600,16 @@ var ZcodeAdapter = class extends LlmAdapter9 {
|
|
|
54964
55600
|
if (activeAccountId !== void 0 && activeAccountId.length > 0) tried.add(activeAccountId);
|
|
54965
55601
|
let credential = await this.resolveCredentialOrThrow(options);
|
|
54966
55602
|
const wire = serializeMessages4(options.messages, imageUrls);
|
|
54967
|
-
const messages =
|
|
54968
|
-
|
|
55603
|
+
const messages = withCallerSystem(
|
|
55604
|
+
// ⚠️ **`withContextPrefix` 不能省**:它负责首轮 user 消息的 `<system-reminder>`
|
|
55605
|
+
// 日期块(官方如此)。上游的正确组合是
|
|
55606
|
+
// `withCallerSystem(withContextPrefix(toAnthropicMessages(wire)), system)` ——
|
|
55607
|
+
// 我第一版只写了 `withCallerSystem(toAnthropicMessages(wire), …)` 会**丢掉日期块**
|
|
55608
|
+
//(虽然实测该块不是 3012 判据,但它是官方形状的一部分)。
|
|
55609
|
+
withContextPrefix(toAnthropicMessages(wire)),
|
|
55610
|
+
options.system
|
|
55611
|
+
);
|
|
55612
|
+
const system = buildZcodeSystemBlocks({
|
|
54969
55613
|
cwd: process.cwd(),
|
|
54970
55614
|
provider: this.product.id,
|
|
54971
55615
|
model: options.model
|
|
@@ -55411,10 +56055,11 @@ function httpErrorCodeForZcode(status, body) {
|
|
|
55411
56055
|
const trimmed = body.trim();
|
|
55412
56056
|
if (trimmed.includes("3007")) return "RATE_LIMIT";
|
|
55413
56057
|
if (hasZcodeUnusualActivity(trimmed)) return "PERMISSION";
|
|
55414
|
-
if (trimmed.includes("1113") || trimmed.includes("\u4F59\u989D\u4E0D\u8DB3")) return "QUOTA_EXCEEDED";
|
|
56058
|
+
if (trimmed.includes("1113") || trimmed.includes("1005") || trimmed.includes("\u4F59\u989D\u4E0D\u8DB3")) return "QUOTA_EXCEEDED";
|
|
55415
56059
|
if (status === 401 || trimmed.includes("1002")) return "AUTH";
|
|
55416
56060
|
if (status === 429) return "RATE_LIMIT";
|
|
55417
56061
|
if (status >= 500) return "SERVER";
|
|
56062
|
+
if (status === 405) return "PERMISSION_DENIED";
|
|
55418
56063
|
if (status === 400) return "INVALID_REQUEST";
|
|
55419
56064
|
return "SERVER";
|
|
55420
56065
|
}
|
|
@@ -55682,192 +56327,6 @@ function rankBuddyAccountsByBalance(accounts, options = {}) {
|
|
|
55682
56327
|
return accounts.map((account, index) => ({ account, index, tier: buddyBalanceTier(account, options) })).sort((a, b) => a.tier - b.tier || a.index - b.index).map((entry) => entry.account);
|
|
55683
56328
|
}
|
|
55684
56329
|
|
|
55685
|
-
// vendor/channel-pack/src/minimax-product.ts
|
|
55686
|
-
var MINIMAX_FALLBACK_MODELS = [
|
|
55687
|
-
{
|
|
55688
|
-
id: "MiniMax-M3.1-Flash-Preview",
|
|
55689
|
-
name: "M3.1-Flash-Preview",
|
|
55690
|
-
contextWindow: 1e6,
|
|
55691
|
-
maxTokens: 128e3,
|
|
55692
|
-
supportsImage: true,
|
|
55693
|
-
effortOptions: ["default", "low", "medium", "high", "xhigh", "max"],
|
|
55694
|
-
defaultEffort: "default",
|
|
55695
|
-
// ⚠️ forced_on:传 disabled 会被服务端**硬拒**(400 `requires adaptive
|
|
55696
|
-
// thinking ... (2013)`,实测)。它与 M2.7 的 forced_on 不同形态:
|
|
55697
|
-
// M2.7 是**静默忽略**,M3.1 是**报错**。
|
|
55698
|
-
thinkingMode: "forced_on"
|
|
55699
|
-
},
|
|
55700
|
-
{
|
|
55701
|
-
id: "MiniMax-M3",
|
|
55702
|
-
name: "M3",
|
|
55703
|
-
contextWindow: 1e6,
|
|
55704
|
-
maxTokens: 128e3,
|
|
55705
|
-
supportsImage: true,
|
|
55706
|
-
// ⚠️ 实测可开关思考(`switchable`):不传/disabled → 0 思考块,
|
|
55707
|
-
// adaptive → 有思考块。官方形态见远端 `variants`。
|
|
55708
|
-
// ⚠️ 但它**没有 `effort_options`** ⇒ 没有「档位」可选,
|
|
55709
|
-
// 只有「开/关」两态 —— 与 Qoder `qmodel` 的「只有关闭思考」同型。
|
|
55710
|
-
thinkingMode: "switchable"
|
|
55711
|
-
},
|
|
55712
|
-
{
|
|
55713
|
-
id: "MiniMax-M2.7-highspeed",
|
|
55714
|
-
name: "M2.7-highspeed",
|
|
55715
|
-
contextWindow: 2e5,
|
|
55716
|
-
maxTokens: 128e3,
|
|
55717
|
-
supportsImage: false,
|
|
55718
|
-
// ⚠️ forced_on:传 disabled 被**静默忽略**(实测仍产出思考块)
|
|
55719
|
-
thinkingMode: "forced_on"
|
|
55720
|
-
},
|
|
55721
|
-
{
|
|
55722
|
-
id: "MiniMax-M2.7",
|
|
55723
|
-
name: "M2.7",
|
|
55724
|
-
contextWindow: 2e5,
|
|
55725
|
-
maxTokens: 128e3,
|
|
55726
|
-
supportsImage: false,
|
|
55727
|
-
thinkingMode: "forced_on"
|
|
55728
|
-
}
|
|
55729
|
-
];
|
|
55730
|
-
var MINIMAX = {
|
|
55731
|
-
id: "minimax",
|
|
55732
|
-
displayName: "MiniMax Code",
|
|
55733
|
-
accountHost: "https://account.minimax.cn",
|
|
55734
|
-
apiHost: "https://agent.minimax.cn",
|
|
55735
|
-
region: "cn",
|
|
55736
|
-
buildEnv: "prod",
|
|
55737
|
-
clientId: "mcode-public",
|
|
55738
|
-
audience: "agent-backend",
|
|
55739
|
-
scope: "agent.default",
|
|
55740
|
-
defaultCredentialRef: "MINIMAX_ACCESS_TOKEN",
|
|
55741
|
-
fallbackModels: MINIMAX_FALLBACK_MODELS,
|
|
55742
|
-
maxImageBytesInline: 10 * 1024 * 1024,
|
|
55743
|
-
maxRequestBodyBytes: 64 * 1024 * 1024
|
|
55744
|
-
};
|
|
55745
|
-
var MINIMAX_DEVICE_CODE_PATH = "/oauth2/device/code";
|
|
55746
|
-
var MINIMAX_TOKEN_PATH = "/oauth2/token";
|
|
55747
|
-
var MINIMAX_MODELS_PATH = "/mavis/api/v1/models";
|
|
55748
|
-
var MINIMAX_INFER_PATH = "/mavis/api/v1/llm/v1/messages";
|
|
55749
|
-
var MINIMAX_SIGNIN_STATUS_PATH = "/minimax-cloud/api/v1/signin/status";
|
|
55750
|
-
var MINIMAX_SIGNIN_CLAIM_PATH = "/minimax-cloud/api/v1/signin/claim";
|
|
55751
|
-
var MINIMAX_CREDIT_DETAILS_PATH = "/minimax-cloud/api/v1/credit/details";
|
|
55752
|
-
var MINIMAX_REQUEST_TIMEOUT_MS = 3e4;
|
|
55753
|
-
var MINIMAX_OAUTH_TIMEOUT_MS = 2e4;
|
|
55754
|
-
|
|
55755
|
-
// vendor/channel-pack/src/minimax.ts
|
|
55756
|
-
function decodeJwtExpMs2(token) {
|
|
55757
|
-
const segments = token.split(".");
|
|
55758
|
-
if (segments.length !== 3 || segments[1] === void 0) return void 0;
|
|
55759
|
-
try {
|
|
55760
|
-
const payload = JSON.parse(Buffer.from(segments[1], "base64url").toString("utf8"));
|
|
55761
|
-
return typeof payload.exp === "number" && Number.isFinite(payload.exp) ? Number.isFinite(payload.exp * 1e3) ? payload.exp * 1e3 : void 0 : void 0;
|
|
55762
|
-
} catch {
|
|
55763
|
-
return void 0;
|
|
55764
|
-
}
|
|
55765
|
-
}
|
|
55766
|
-
function decodeJwtSub(token) {
|
|
55767
|
-
const segments = token.split(".");
|
|
55768
|
-
if (segments.length !== 3 || segments[1] === void 0) return void 0;
|
|
55769
|
-
try {
|
|
55770
|
-
const payload = JSON.parse(Buffer.from(segments[1], "base64url").toString("utf8"));
|
|
55771
|
-
return typeof payload.sub === "string" && payload.sub.length > 0 ? payload.sub : void 0;
|
|
55772
|
-
} catch {
|
|
55773
|
-
return void 0;
|
|
55774
|
-
}
|
|
55775
|
-
}
|
|
55776
|
-
function minimaxCredentialExpiresAtMs(credential) {
|
|
55777
|
-
const raw = credential.expires_at;
|
|
55778
|
-
if (raw !== void 0) {
|
|
55779
|
-
if (/^\d+$/.test(raw)) {
|
|
55780
|
-
const value = Number(raw);
|
|
55781
|
-
const parsed = value > 1e12 ? value : value * 1e3;
|
|
55782
|
-
if (Number.isFinite(parsed) && parsed > 0) return parsed;
|
|
55783
|
-
}
|
|
55784
|
-
}
|
|
55785
|
-
return decodeJwtExpMs2(credential.access_token);
|
|
55786
|
-
}
|
|
55787
|
-
function isMinimaxExpired(credential, nowMs = Date.now()) {
|
|
55788
|
-
const expiresAt = minimaxCredentialExpiresAtMs(credential);
|
|
55789
|
-
return expiresAt !== void 0 && nowMs >= expiresAt;
|
|
55790
|
-
}
|
|
55791
|
-
function isMinimaxRefreshable(credential) {
|
|
55792
|
-
return typeof credential.refresh_token === "string" && credential.refresh_token.length > 0;
|
|
55793
|
-
}
|
|
55794
|
-
function minimaxHeaders(credential) {
|
|
55795
|
-
const headers = new Headers();
|
|
55796
|
-
headers.set("Authorization", `Bearer ${credential.access_token}`);
|
|
55797
|
-
headers.set("Accept", "application/json");
|
|
55798
|
-
return headers;
|
|
55799
|
-
}
|
|
55800
|
-
function minimaxInferHeaders(credential) {
|
|
55801
|
-
const headers = new Headers();
|
|
55802
|
-
headers.set("Authorization", `Bearer ${credential.access_token}`);
|
|
55803
|
-
headers.set("Content-Type", "application/json");
|
|
55804
|
-
headers.set("Accept", "text/event-stream");
|
|
55805
|
-
return headers;
|
|
55806
|
-
}
|
|
55807
|
-
function positiveInt(value) {
|
|
55808
|
-
return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : void 0;
|
|
55809
|
-
}
|
|
55810
|
-
function nonEmptyString(value) {
|
|
55811
|
-
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
55812
|
-
}
|
|
55813
|
-
function stringArray(value) {
|
|
55814
|
-
if (!Array.isArray(value)) return void 0;
|
|
55815
|
-
const out = [];
|
|
55816
|
-
const seen = /* @__PURE__ */ new Set();
|
|
55817
|
-
for (const item of value) {
|
|
55818
|
-
const text = nonEmptyString(item);
|
|
55819
|
-
if (text === void 0 || seen.has(text)) continue;
|
|
55820
|
-
seen.add(text);
|
|
55821
|
-
out.push(text);
|
|
55822
|
-
}
|
|
55823
|
-
return out.length > 0 ? out : void 0;
|
|
55824
|
-
}
|
|
55825
|
-
function normalizeMinimaxModel(raw) {
|
|
55826
|
-
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return void 0;
|
|
55827
|
-
const record = raw;
|
|
55828
|
-
const id = nonEmptyString(record.id) ?? nonEmptyString(record.name);
|
|
55829
|
-
if (id === void 0) return void 0;
|
|
55830
|
-
const name2 = nonEmptyString(record.name) ?? id;
|
|
55831
|
-
const limit = typeof record.limit === "object" && record.limit !== null ? record.limit : {};
|
|
55832
|
-
const options = Array.isArray(record.context_window_options) ? record.context_window_options.filter((v) => positiveInt(v) !== void 0) : [];
|
|
55833
|
-
const limitContext = positiveInt(limit.context);
|
|
55834
|
-
const contextWindow = options.length > 0 ? Math.max(...options) : limitContext;
|
|
55835
|
-
const modalities = typeof record.modalities === "object" && record.modalities !== null ? record.modalities : {};
|
|
55836
|
-
const inputs = Array.isArray(modalities.input) ? modalities.input.filter((v) => typeof v === "string") : [];
|
|
55837
|
-
const effortOptions = stringArray(record.effort_options);
|
|
55838
|
-
const rawDefault = nonEmptyString(record.default_effort);
|
|
55839
|
-
const defaultEffort = rawDefault !== void 0 && effortOptions?.includes(rawDefault) === true ? rawDefault : void 0;
|
|
55840
|
-
const thinkingConfig = typeof record.thinking_config === "object" && record.thinking_config !== null ? record.thinking_config : void 0;
|
|
55841
|
-
const thinkingMode = thinkingConfig === void 0 ? void 0 : nonEmptyString(thinkingConfig.mode);
|
|
55842
|
-
const maxTokens = positiveInt(limit.output);
|
|
55843
|
-
return {
|
|
55844
|
-
id,
|
|
55845
|
-
name: name2,
|
|
55846
|
-
// 窗口未知时**不编造**:用 0 表示「不知道」,由 resolveModel 判 `> 0`
|
|
55847
|
-
contextWindow: contextWindow ?? 0,
|
|
55848
|
-
...maxTokens === void 0 ? {} : { maxTokens },
|
|
55849
|
-
supportsImage: inputs.includes("image"),
|
|
55850
|
-
...effortOptions === void 0 ? {} : { effortOptions },
|
|
55851
|
-
...defaultEffort === void 0 ? {} : { defaultEffort },
|
|
55852
|
-
...thinkingMode === void 0 ? {} : { thinkingMode }
|
|
55853
|
-
};
|
|
55854
|
-
}
|
|
55855
|
-
function fallbackToEntry(model) {
|
|
55856
|
-
return {
|
|
55857
|
-
id: model.id,
|
|
55858
|
-
name: model.name,
|
|
55859
|
-
contextWindow: model.contextWindow,
|
|
55860
|
-
maxTokens: model.maxTokens,
|
|
55861
|
-
supportsImage: model.supportsImage,
|
|
55862
|
-
...model.effortOptions === void 0 ? {} : { effortOptions: model.effortOptions },
|
|
55863
|
-
...model.defaultEffort === void 0 ? {} : { defaultEffort: model.defaultEffort },
|
|
55864
|
-
...model.thinkingMode === void 0 ? {} : { thinkingMode: model.thinkingMode }
|
|
55865
|
-
};
|
|
55866
|
-
}
|
|
55867
|
-
function minimaxFallbackEntries(product = MINIMAX) {
|
|
55868
|
-
return product.fallbackModels.map(fallbackToEntry);
|
|
55869
|
-
}
|
|
55870
|
-
|
|
55871
56330
|
// vendor/channel-pack/src/credits.ts
|
|
55872
56331
|
var CHECKIN_ACTIVITY_STATUS_PATH = "/v2/billing/meter/checkin-activity-status";
|
|
55873
56332
|
var DAILY_CHECKIN_PATH = "/v2/billing/meter/daily-checkin";
|
|
@@ -59335,6 +59794,16 @@ async function probeWithAdapter(entry, credential, modelId, timeoutMs) {
|
|
|
59335
59794
|
const message2 = error instanceof Error ? error.message : String(error);
|
|
59336
59795
|
if (isRateLimitFailure(error)) {
|
|
59337
59796
|
const parsed = parseRateLimitError(message2, modelId);
|
|
59797
|
+
const creditExhausted = isCreditExhausted(message2);
|
|
59798
|
+
if (creditExhausted) {
|
|
59799
|
+
const resetMs = explicitRateResetAtMs(message2) ?? creditExhaustedResetAtMs();
|
|
59800
|
+
return {
|
|
59801
|
+
modelId,
|
|
59802
|
+
ok: false,
|
|
59803
|
+
message: `\u989D\u5EA6\u5DF2\u8017\u5C3D\uFF08\u4E0D\u662F\u9650\u6D41\uFF09\uFF1A${message2}\u3002\u6062\u590D\u8981\u9760**\u6B21\u65E5\u914D\u989D**\u6216\u5145\u503C\uFF0C\u4E0D\u662F\u7B49\u4E00\u4F1A\u513F \u2014\u2014 \u8BE5\u8D26\u53F7\u5728\u989D\u5EA6\u6062\u590D\u524D\u4E0D\u53EF\u7528\u3002`,
|
|
59804
|
+
resetTimeMs: resetMs
|
|
59805
|
+
};
|
|
59806
|
+
}
|
|
59338
59807
|
return {
|
|
59339
59808
|
modelId,
|
|
59340
59809
|
ok: false,
|
|
@@ -62873,6 +63342,7 @@ function registerChannelPackEndpoints(ctx, pool, codearts, buddy, workbuddy, lob
|
|
|
62873
63342
|
const all = catalogSource?.listAllModels();
|
|
62874
63343
|
let catalog;
|
|
62875
63344
|
if (all !== void 0) {
|
|
63345
|
+
catalog = [...all];
|
|
62876
63346
|
catalog = [...all];
|
|
62877
63347
|
const known = new Set(catalog.map((model) => model.id));
|
|
62878
63348
|
for (const id of Object.keys(disabledMap)) {
|
|
@@ -66115,6 +66585,7 @@ var MinimaxAuth = class extends Service10 {
|
|
|
66115
66585
|
accessors: MINIMAX_EXPIRY_ACCESSORS,
|
|
66116
66586
|
refresh: (c) => this.refreshCredentialFor(c),
|
|
66117
66587
|
save: (c) => this.ctx.credentials.set(ref, JSON.stringify(c)),
|
|
66588
|
+
makeTerminalError: (message2) => new MinimaxRefreshTokenExpiredError(message2),
|
|
66118
66589
|
warn: (message2) => this.ctx.logger?.warn?.(message2),
|
|
66119
66590
|
info: (message2) => this.ctx.logger?.info?.(message2)
|
|
66120
66591
|
});
|
|
@@ -66156,6 +66627,7 @@ var MinimaxAuth = class extends Service10 {
|
|
|
66156
66627
|
current: entry,
|
|
66157
66628
|
refresh: (c) => this.refreshCredentialFor(c),
|
|
66158
66629
|
save: (c) => this.ctx.credentials.set(ref, JSON.stringify(c)),
|
|
66630
|
+
makeTerminalError: (message2) => new MinimaxRefreshTokenExpiredError(message2),
|
|
66159
66631
|
warn: (message2) => this.ctx.logger?.warn?.(message2)
|
|
66160
66632
|
});
|
|
66161
66633
|
} catch (error) {
|
|
@@ -66687,6 +67159,32 @@ var MinimaxAdapter = class extends LlmAdapter11 {
|
|
|
66687
67159
|
* 改为:只缓存**真实远端目录**,兜底表每次现算(纯本地、零成本),
|
|
66688
67160
|
* 并用 {@link RemoteCatalogGate} 的冷却挡住「每模型重试一次」的放大。
|
|
66689
67161
|
*/
|
|
67162
|
+
/**
|
|
67163
|
+
* **强制重拉远端目录**(模型上下架自适应;供 `index.ts` 的定时器调用)。
|
|
67164
|
+
*
|
|
67165
|
+
* ## ⚠️⚠️ 本类短路判据是 `if (this.remoteModels !== undefined) return`(在 `loadModels` 里)
|
|
67166
|
+
*
|
|
67167
|
+
* ⇒ 必须**先清 `remoteModels`** 才能触发重拉;但清掉后若重拉失败,`loadModels`
|
|
67168
|
+
* 会**返回兜底子表**并把结果留在 `remoteModels` 之外 ⇒ 用户少看到一批模型。
|
|
67169
|
+
*
|
|
67170
|
+
* ⇒ **保存—尝试—失败恢复**:旧目录先存下来,重拉后若没拿到远端就放回去
|
|
67171
|
+
*(「刷新失败」与「不刷新」对用户无差别,都继续看旧目录)。
|
|
67172
|
+
*
|
|
67173
|
+
* ⚠️ 判据是「`remoteModels` 是否被**远端**填上」,不能用「`loadModels` 返回了什么」:
|
|
67174
|
+
* 它在拿不到远端时**照样返回兜底表**(那是展示用,不落 `remoteModels`)。
|
|
67175
|
+
*/
|
|
67176
|
+
async refreshCatalog() {
|
|
67177
|
+
if (this.options.fetchRemoteModels === void 0) return;
|
|
67178
|
+
const previous = this.remoteModels;
|
|
67179
|
+
this.remoteModels = void 0;
|
|
67180
|
+
try {
|
|
67181
|
+
await this.loadModels();
|
|
67182
|
+
} finally {
|
|
67183
|
+
if (this.remoteModels === void 0 && previous !== void 0) {
|
|
67184
|
+
this.remoteModels = previous;
|
|
67185
|
+
}
|
|
67186
|
+
}
|
|
67187
|
+
}
|
|
66690
67188
|
async loadModels() {
|
|
66691
67189
|
if (this.remoteModels !== void 0) return this.remoteModels;
|
|
66692
67190
|
const fetchRemote = this.options.fetchRemoteModels;
|
|
@@ -67468,6 +67966,7 @@ var GeminiAuth = class extends Service11 {
|
|
|
67468
67966
|
accessors: GEMINI_EXPIRY_ACCESSORS,
|
|
67469
67967
|
refresh: (c) => this.refreshCredential(c),
|
|
67470
67968
|
save: (c) => this.ctx.credentials.set(ref, JSON.stringify(c)),
|
|
67969
|
+
makeTerminalError: (message2) => new GeminiRefreshTokenExpiredError(message2),
|
|
67471
67970
|
warn: (message2) => this.ctx.logger?.warn?.(message2),
|
|
67472
67971
|
info: (message2) => this.ctx.logger?.info?.(message2)
|
|
67473
67972
|
});
|
|
@@ -67515,6 +68014,7 @@ var GeminiAuth = class extends Service11 {
|
|
|
67515
68014
|
current: entry,
|
|
67516
68015
|
refresh: (c) => this.refreshCredentialUnderLock(entry.credentialRef, c),
|
|
67517
68016
|
save: (c) => this.ctx.credentials.set(ref, JSON.stringify(c)),
|
|
68017
|
+
makeTerminalError: (message2) => new GeminiRefreshTokenExpiredError(message2),
|
|
67518
68018
|
warn: (message2) => this.ctx.logger?.warn?.(message2),
|
|
67519
68019
|
info: (message2) => this.ctx.logger?.info?.(message2)
|
|
67520
68020
|
});
|
|
@@ -68417,6 +68917,7 @@ var AccioAuth = class extends Service12 {
|
|
|
68417
68917
|
current: entry,
|
|
68418
68918
|
refresh: (c) => this.refreshCredentialUnderLock(entry.credentialRef, c),
|
|
68419
68919
|
save: (c) => this.ctx.credentials.set(ref, JSON.stringify(c)),
|
|
68920
|
+
makeTerminalError: (message2) => new AccioRefreshTokenExpiredError(message2),
|
|
68420
68921
|
warn: (message2) => this.warn(message2),
|
|
68421
68922
|
info: (message2) => this.ctx.logger?.info?.(message2)
|
|
68422
68923
|
});
|
|
@@ -69171,6 +69672,21 @@ function isTransportError6(error) {
|
|
|
69171
69672
|
if (message2.includes("epipe") || message2.includes("socket hang up")) return true;
|
|
69172
69673
|
return false;
|
|
69173
69674
|
}
|
|
69675
|
+
function accioFailureClassOf(code) {
|
|
69676
|
+
if (code === "QUOTA_EXCEEDED") return "quota";
|
|
69677
|
+
if (code === "RATE_LIMIT") return "rate";
|
|
69678
|
+
if (code === "AUTH") return "auth";
|
|
69679
|
+
return "other";
|
|
69680
|
+
}
|
|
69681
|
+
function shouldRotateAccioAccount(code) {
|
|
69682
|
+
return accioFailureClassOf(code) !== "other";
|
|
69683
|
+
}
|
|
69684
|
+
function recordsAccioRateLimit(code) {
|
|
69685
|
+
const cls = accioFailureClassOf(code);
|
|
69686
|
+
return cls === "quota" || cls === "rate";
|
|
69687
|
+
}
|
|
69688
|
+
var ACCIO_MAX_ROTATE = 8;
|
|
69689
|
+
var ACCIO_RATE_LIMIT_COOLDOWN_MS = 36e5;
|
|
69174
69690
|
function httpErrorCode6(status) {
|
|
69175
69691
|
if (status === 401 || status === 403) return "AUTH";
|
|
69176
69692
|
if (status === 402) return "QUOTA_EXCEEDED";
|
|
@@ -69457,6 +69973,30 @@ var AccioAdapter = class extends LlmAdapter12 {
|
|
|
69457
69973
|
return { id, name: this.product.displayName };
|
|
69458
69974
|
}
|
|
69459
69975
|
/** 懒加载远端模型目录(仅拉取一次;失败/空结果走闸门冷却)。 */
|
|
69976
|
+
/**
|
|
69977
|
+
* **强制重拉远端目录**(模型上下架自适应;供 `index.ts` 的定时器调用)。
|
|
69978
|
+
*
|
|
69979
|
+
* ## ⚠️⚠️ 本类短路判据是 `remoteModels !== undefined`(不是 `remoteComplete`)
|
|
69980
|
+
*
|
|
69981
|
+
* ⇒ 必须**先清 `remoteModels`** 才能触发重拉;但清掉后若重拉失败,
|
|
69982
|
+
* `ensureRemoteModels` 会**保留 undefined** ⇒ 目录退回**兜底子表**(那是个**子集**
|
|
69983
|
+
* 且**已过期**)⇒ 一次网络抖动就让用户少看到一批模型。
|
|
69984
|
+
*
|
|
69985
|
+
* ⇒ 采用**保存—尝试—失败恢复**:旧目录先存下来,重拉后若仍为空就放回去。
|
|
69986
|
+
* 这样「刷新失败」与「不刷新」对用户是无差别的(都继续看旧目录)。
|
|
69987
|
+
*/
|
|
69988
|
+
async refreshCatalog() {
|
|
69989
|
+
if (this.options.fetchRemoteModels === void 0) return;
|
|
69990
|
+
const previous = this.remoteModels;
|
|
69991
|
+
this.remoteModels = void 0;
|
|
69992
|
+
try {
|
|
69993
|
+
await this.ensureRemoteModels();
|
|
69994
|
+
} finally {
|
|
69995
|
+
if (this.remoteModels === void 0 && previous !== void 0) {
|
|
69996
|
+
this.remoteModels = previous;
|
|
69997
|
+
}
|
|
69998
|
+
}
|
|
69999
|
+
}
|
|
69460
70000
|
async ensureRemoteModels() {
|
|
69461
70001
|
const fetchRemote = this.options.fetchRemoteModels;
|
|
69462
70002
|
if (this.remoteModels !== void 0 || fetchRemote === void 0) return;
|
|
@@ -69678,44 +70218,125 @@ var AccioAdapter = class extends LlmAdapter12 {
|
|
|
69678
70218
|
if (systemInstruction !== "") body.system_instruction = systemInstruction;
|
|
69679
70219
|
else delete body.system_instruction;
|
|
69680
70220
|
if (options.stop !== void 0 && options.stop.length > 0) body.stop_sequences = options.stop;
|
|
69681
|
-
applyAccessToken(body, credential.access_token);
|
|
69682
70221
|
let response = await this.send(credential, body, options);
|
|
69683
|
-
|
|
69684
|
-
|
|
69685
|
-
|
|
69686
|
-
|
|
69687
|
-
|
|
69688
|
-
|
|
69689
|
-
|
|
70222
|
+
let currentAccountId = "";
|
|
70223
|
+
if (this.options.accountPool !== void 0) {
|
|
70224
|
+
try {
|
|
70225
|
+
currentAccountId = await this.options.accountPool.findAccountIdByCredential(
|
|
70226
|
+
ACCIO.id,
|
|
70227
|
+
credential.access_token
|
|
70228
|
+
) ?? "";
|
|
70229
|
+
} catch {
|
|
69690
70230
|
}
|
|
69691
|
-
credential = refreshed;
|
|
69692
|
-
applyAccessToken(body, credential.access_token);
|
|
69693
|
-
response = await this.send(credential, body, options);
|
|
69694
70231
|
}
|
|
69695
|
-
|
|
69696
|
-
|
|
69697
|
-
|
|
69698
|
-
|
|
69699
|
-
|
|
69700
|
-
|
|
69701
|
-
|
|
69702
|
-
|
|
69703
|
-
|
|
69704
|
-
|
|
69705
|
-
|
|
69706
|
-
|
|
69707
|
-
|
|
69708
|
-
|
|
69709
|
-
|
|
69710
|
-
|
|
69711
|
-
|
|
70232
|
+
const tried = /* @__PURE__ */ new Set();
|
|
70233
|
+
let producedAny = false;
|
|
70234
|
+
const markCurrentAccount = async (failureCode) => {
|
|
70235
|
+
if (this.options.accountPool === void 0) return;
|
|
70236
|
+
if (currentAccountId === "" || !recordsAccioRateLimit(failureCode)) return;
|
|
70237
|
+
try {
|
|
70238
|
+
const cls = accioFailureClassOf(failureCode);
|
|
70239
|
+
await this.options.accountPool.updateModelRateLimit(
|
|
70240
|
+
currentAccountId,
|
|
70241
|
+
options.model,
|
|
70242
|
+
cls === "quota" ? nextUtc8DayStartMs() : Date.now() + ACCIO_RATE_LIMIT_COOLDOWN_MS
|
|
70243
|
+
);
|
|
70244
|
+
} catch (error) {
|
|
70245
|
+
console.warn(
|
|
70246
|
+
`[accio] \u8D26\u53F7 ${currentAccountId} \u7684\u51B7\u5374\u6807\u8BB0\u5199\u5165\u5931\u8D25\uFF08\u4E0D\u5F71\u54CD\u6362\u53F7\uFF09\uFF1A`,
|
|
70247
|
+
error instanceof Error ? error.message : String(error)
|
|
70248
|
+
);
|
|
70249
|
+
}
|
|
70250
|
+
};
|
|
70251
|
+
const rotate = async () => {
|
|
70252
|
+
if (this.options.accountPool === void 0) return void 0;
|
|
70253
|
+
try {
|
|
70254
|
+
const next = await this.options.accountPool.getAvailableAccount(
|
|
70255
|
+
ACCIO.id,
|
|
70256
|
+
options.model,
|
|
70257
|
+
tried
|
|
70258
|
+
);
|
|
70259
|
+
if (!next || tried.has(next.entry.id)) return void 0;
|
|
70260
|
+
tried.add(next.entry.id);
|
|
70261
|
+
const nextCredential = next.credential;
|
|
70262
|
+
currentAccountId = next.entry.id;
|
|
70263
|
+
credential = nextCredential;
|
|
70264
|
+
applyAccessToken(body, credential.access_token);
|
|
70265
|
+
return await this.send(credential, body, options);
|
|
70266
|
+
} catch (error) {
|
|
70267
|
+
console.warn(
|
|
70268
|
+
"[accio] \u6362\u53F7\u5931\u8D25\uFF0C\u6309\u300C\u65E0\u53EF\u7528\u8D26\u53F7\u300D\u5904\u7406\uFF1A",
|
|
70269
|
+
error instanceof Error ? error.message : String(error)
|
|
70270
|
+
);
|
|
70271
|
+
return void 0;
|
|
70272
|
+
}
|
|
70273
|
+
};
|
|
70274
|
+
const consumeOnce = async function* (target) {
|
|
70275
|
+
const streamBody = target.body;
|
|
70276
|
+
if (streamBody === null) throw new LlmError20("accio: empty model response body", "EMPTY_RESPONSE");
|
|
70277
|
+
for await (const chunk of consumeAccioSse({
|
|
70278
|
+
body: streamBody.pipeThrough(accioToolCallMergeTransform()),
|
|
70279
|
+
...options.signal === void 0 ? {} : { signal: options.signal },
|
|
70280
|
+
idleTimeoutMs: ACCIO_SSE_IDLE_TIMEOUT_MS
|
|
70281
|
+
})) {
|
|
70282
|
+
producedAny = true;
|
|
70283
|
+
yield chunk;
|
|
70284
|
+
}
|
|
70285
|
+
};
|
|
70286
|
+
for (let round = 0; ; round++) {
|
|
70287
|
+
if (!response.ok) {
|
|
70288
|
+
const text = await response.text().catch(() => "");
|
|
70289
|
+
if (response.status === 401 || response.status === 403) {
|
|
70290
|
+
await this.options.refresh();
|
|
70291
|
+
const refreshed = await this.options.resolveCredential(options.model);
|
|
70292
|
+
if (refreshed !== void 0 && refreshed.access_token !== "") {
|
|
70293
|
+
credential = refreshed;
|
|
70294
|
+
applyAccessToken(body, credential.access_token);
|
|
70295
|
+
response = await this.send(credential, body, options);
|
|
70296
|
+
if (response.ok) continue;
|
|
70297
|
+
}
|
|
70298
|
+
}
|
|
70299
|
+
const code = httpErrorCode6(response.status);
|
|
70300
|
+
if (!shouldRotateAccioAccount(code)) {
|
|
70301
|
+
throw new LlmError20(`accio: ${errorDetail6(text)}`, code, { status: response.status });
|
|
70302
|
+
}
|
|
70303
|
+
await markCurrentAccount(code);
|
|
70304
|
+
if (round >= ACCIO_MAX_ROTATE - 1) {
|
|
70305
|
+
throw new LlmError20(`accio: ${errorDetail6(text)}`, code, { status: response.status });
|
|
70306
|
+
}
|
|
70307
|
+
const rotated = await rotate();
|
|
70308
|
+
if (rotated === void 0) {
|
|
70309
|
+
throw new LlmError20(`accio: ${errorDetail6(text)}`, code, { status: response.status });
|
|
70310
|
+
}
|
|
70311
|
+
response = rotated;
|
|
70312
|
+
continue;
|
|
70313
|
+
}
|
|
70314
|
+
if (response.body === null) {
|
|
70315
|
+
throw new LlmError20("accio: empty model response body", "EMPTY_RESPONSE");
|
|
70316
|
+
}
|
|
70317
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
70318
|
+
if (!contentType.includes("text/event-stream")) {
|
|
70319
|
+
const peek = await response.text().catch(() => "");
|
|
70320
|
+
throw new LlmError20(
|
|
70321
|
+
`accio: \u4E0A\u6E38\u672A\u8FD4\u56DE\u4E8B\u4EF6\u6D41\uFF08content-type: ${contentType || "(\u7A7A)"}\uFF09\u2014\u2014\u901A\u5E38\u662F\u88AB\u98CE\u63A7\u62E6\u622A\uFF08\u7F51\u5173\u8FD4\u56DE 200 + HTML \u62E6\u622A\u9875\uFF09\u3002${peek === "" ? "" : ` \u670D\u52A1\u7AEF\u539F\u6587\uFF1A${peek.slice(0, 200)}`}`,
|
|
70322
|
+
"SERVER",
|
|
70323
|
+
{ status: response.status }
|
|
70324
|
+
);
|
|
70325
|
+
}
|
|
70326
|
+
try {
|
|
70327
|
+
yield* consumeOnce(response);
|
|
70328
|
+
return;
|
|
70329
|
+
} catch (error) {
|
|
70330
|
+
if (producedAny) throw error;
|
|
70331
|
+
const code = error instanceof LlmError20 ? error.code : "";
|
|
70332
|
+
if (code === "" || !shouldRotateAccioAccount(code)) throw error;
|
|
70333
|
+
await markCurrentAccount(code);
|
|
70334
|
+
if (round >= ACCIO_MAX_ROTATE - 1) throw error;
|
|
70335
|
+
const rotated = await rotate();
|
|
70336
|
+
if (rotated === void 0) throw error;
|
|
70337
|
+
response = rotated;
|
|
70338
|
+
}
|
|
69712
70339
|
}
|
|
69713
|
-
const merged = response.body.pipeThrough(accioToolCallMergeTransform());
|
|
69714
|
-
yield* consumeAccioSse({
|
|
69715
|
-
body: merged,
|
|
69716
|
-
...options.signal === void 0 ? {} : { signal: options.signal },
|
|
69717
|
-
idleTimeoutMs: ACCIO_SSE_IDLE_TIMEOUT_MS
|
|
69718
|
-
});
|
|
69719
70340
|
}
|
|
69720
70341
|
/** 发起一次推理请求;网络失败映射为可重试的 `TRANSPORT`。 */
|
|
69721
70342
|
async send(credential, body, options) {
|
|
@@ -69923,6 +70544,7 @@ __export(officeace_auth_exports, {
|
|
|
69923
70544
|
fetchModelTokenRates: () => fetchModelTokenRates,
|
|
69924
70545
|
fetchSubscriptionSummary: () => fetchSubscriptionSummary,
|
|
69925
70546
|
isExpiring: () => isExpiring,
|
|
70547
|
+
maybeClaimBonus: () => maybeClaimBonus,
|
|
69926
70548
|
persistLogin: () => persistLogin,
|
|
69927
70549
|
pollLoginCode: () => pollLoginCode,
|
|
69928
70550
|
probeOfficeAce: () => probeOfficeAce,
|
|
@@ -70584,7 +71206,7 @@ async function fetchCloudSubscriptionFor(credential) {
|
|
|
70584
71206
|
}
|
|
70585
71207
|
async function claimDailyBonus(credential) {
|
|
70586
71208
|
if (!credentialUsable(credential)) {
|
|
70587
|
-
|
|
71209
|
+
throw new Error("\u51ED\u636E\u7F3A\u5931\uFF08access \u6216 securityToken \u7F3A\u5931\u6216\u4E3A\u7A7A\uFF09\uFF0C\u672A\u53D1\u8D77\u7B7E\u5230\u8BF7\u6C42");
|
|
70588
71210
|
}
|
|
70589
71211
|
try {
|
|
70590
71212
|
const body = await signAndRequest(
|
|
@@ -70599,8 +71221,10 @@ async function claimDailyBonus(credential) {
|
|
|
70599
71221
|
activityName: typeof s.activity_name === "string" ? s.activity_name : "\u6D3B\u52A8\u5956\u52B1",
|
|
70600
71222
|
points: Number(s.points) || 0
|
|
70601
71223
|
}));
|
|
70602
|
-
} catch {
|
|
70603
|
-
|
|
71224
|
+
} catch (error) {
|
|
71225
|
+
throw new Error(
|
|
71226
|
+
`\u7B7E\u5230\u8BF7\u6C42\u5931\u8D25\uFF1A${error instanceof Error ? error.message : String(error)}`
|
|
71227
|
+
);
|
|
70604
71228
|
}
|
|
70605
71229
|
}
|
|
70606
71230
|
var lastClaimAt = /* @__PURE__ */ new Map();
|
|
@@ -70609,7 +71233,18 @@ function maybeClaimBonus(credential, ref) {
|
|
|
70609
71233
|
const hourKey = `${now.getFullYear()}-${now.getMonth()}-${now.getDate()}-${now.getHours()}`;
|
|
70610
71234
|
if (lastClaimAt.get(ref) === hourKey) return Promise.resolve([]);
|
|
70611
71235
|
lastClaimAt.set(ref, hourKey);
|
|
70612
|
-
|
|
71236
|
+
const releaseSlot = () => {
|
|
71237
|
+
if (lastClaimAt.get(ref) === hourKey) lastClaimAt.delete(ref);
|
|
71238
|
+
};
|
|
71239
|
+
return claimDailyBonus(credential).then((skus) => {
|
|
71240
|
+
return skus;
|
|
71241
|
+
}).catch((error) => {
|
|
71242
|
+
console.warn(
|
|
71243
|
+
`[officeace] \u6BCF\u65E5\u7B7E\u5230\u5931\u8D25\uFF08ref=${ref}\uFF09\uFF0C\u5DF2\u64A4\u9500\u672C\u5C0F\u65F6\u5360\u5751\u5141\u8BB8\u91CD\u8BD5\uFF1A${error instanceof Error ? error.message : String(error)}`
|
|
71244
|
+
);
|
|
71245
|
+
releaseSlot();
|
|
71246
|
+
return [];
|
|
71247
|
+
});
|
|
70613
71248
|
}
|
|
70614
71249
|
function basicAuthorization(credential) {
|
|
70615
71250
|
return "Basic " + Buffer.from(`${credential.modelAppKey}:${credential.modelAppSecret}`).toString("base64");
|
|
@@ -72823,6 +73458,27 @@ function apply(ctx, config = {}) {
|
|
|
72823
73458
|
// Accio **可续期**(标准 OAuth refresh_token grant)。同款教训见上两行。
|
|
72824
73459
|
["accio", (p) => accio.refreshAll(p)]
|
|
72825
73460
|
];
|
|
73461
|
+
let catalogRefreshInFlight = false;
|
|
73462
|
+
async function refreshAllCatalogs() {
|
|
73463
|
+
if (catalogRefreshInFlight) return;
|
|
73464
|
+
if (typeof modelAdapters === "undefined") return;
|
|
73465
|
+
catalogRefreshInFlight = true;
|
|
73466
|
+
try {
|
|
73467
|
+
for (const [tag2, adapter] of Object.entries(modelAdapters)) {
|
|
73468
|
+
const refresh = adapter.refreshCatalog;
|
|
73469
|
+
if (typeof refresh !== "function") continue;
|
|
73470
|
+
try {
|
|
73471
|
+
await refresh.call(adapter);
|
|
73472
|
+
} catch (error) {
|
|
73473
|
+
ctx.logger?.warn?.(
|
|
73474
|
+
`[channel-pack] ${tag2} \u76EE\u5F55\u5237\u65B0\u5931\u8D25\uFF08\u4FDD\u7559\u65E7\u76EE\u5F55\uFF09\uFF1A${error instanceof Error ? error.message : String(error)}`
|
|
73475
|
+
);
|
|
73476
|
+
}
|
|
73477
|
+
}
|
|
73478
|
+
} finally {
|
|
73479
|
+
catalogRefreshInFlight = false;
|
|
73480
|
+
}
|
|
73481
|
+
}
|
|
72826
73482
|
async function refreshAllCredentials() {
|
|
72827
73483
|
for (const [tag2, refreshAll2] of refreshTargets) {
|
|
72828
73484
|
try {
|
|
@@ -72837,7 +73493,10 @@ function apply(ctx, config = {}) {
|
|
|
72837
73493
|
pool.listAllAccounts().then((accounts) => {
|
|
72838
73494
|
if (accounts.length === 0) return;
|
|
72839
73495
|
void refreshAllCredentials();
|
|
72840
|
-
const refreshTimer = setInterval(() =>
|
|
73496
|
+
const refreshTimer = setInterval(() => {
|
|
73497
|
+
void refreshAllCredentials();
|
|
73498
|
+
void refreshAllCatalogs();
|
|
73499
|
+
}, REFRESH_INTERVAL_MS);
|
|
72841
73500
|
refreshTimer.unref?.();
|
|
72842
73501
|
ctx.effect(() => () => {
|
|
72843
73502
|
clearInterval(refreshTimer);
|
|
@@ -73093,11 +73752,16 @@ function apply(ctx, config = {}) {
|
|
|
73093
73752
|
export {
|
|
73094
73753
|
Config,
|
|
73095
73754
|
apply,
|
|
73755
|
+
buildZcodeSystemBlocks,
|
|
73096
73756
|
channelProxyBypassed,
|
|
73097
73757
|
createChannelFetch,
|
|
73758
|
+
httpErrorCodeForZcode,
|
|
73098
73759
|
inject,
|
|
73099
73760
|
makeReadImage,
|
|
73100
73761
|
makeReadImageRequest,
|
|
73762
|
+
maybeClaimBonus,
|
|
73101
73763
|
name,
|
|
73102
|
-
parseWindowsProxy
|
|
73764
|
+
parseWindowsProxy,
|
|
73765
|
+
serializeTraeMessagesForTest,
|
|
73766
|
+
withCallerSystem
|
|
73103
73767
|
};
|