@eddyskywalker/dsh-chatgpt-subscription 0.73.0 → 0.74.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/lib/client.js.map +1 -1
- package/lib/codemode.js +125 -60
- package/lib/{entry-plan-mode-5DBZA4Il.js → entry-plan-mode-EShP3ndV.js} +34 -8
- package/lib/index.js +852 -501
- package/lib/{llm-compat-u9mor0uu.js → llm-compat--WsaC9K6.js} +25 -1
- package/lib/plan-mode.js +2 -2
- package/lib/types/compat.d.ts +1 -1
- package/lib/types/entry-codemode.d.ts.map +1 -1
- package/lib/types/entry-plan-mode.d.ts +14 -0
- package/lib/types/entry-plan-mode.d.ts.map +1 -1
- package/lib/types/host/antigravity-acp/adapter.d.ts +102 -10
- package/lib/types/host/antigravity-acp/adapter.d.ts.map +1 -1
- package/lib/types/host/antigravity-acp/catalog.d.ts +11 -2
- package/lib/types/host/antigravity-acp/catalog.d.ts.map +1 -1
- package/lib/types/host/antigravity-acp/errors.d.ts +1 -1
- package/lib/types/host/antigravity-acp/errors.d.ts.map +1 -1
- package/lib/types/host/antigravity-acp/history.d.ts +31 -2
- package/lib/types/host/antigravity-acp/history.d.ts.map +1 -1
- package/lib/types/host/cache-warmup/contracts.d.ts +11 -1
- package/lib/types/host/cache-warmup/contracts.d.ts.map +1 -1
- package/lib/types/host/cache-warmup/result-tool.d.ts +4 -0
- package/lib/types/host/cache-warmup/result-tool.d.ts.map +1 -1
- package/lib/types/host/cache-warmup/store.d.ts.map +1 -1
- package/lib/types/host/claude/adapter.d.ts +2 -1
- package/lib/types/host/claude/adapter.d.ts.map +1 -1
- package/lib/types/host/cline-pass/adapter.d.ts.map +1 -1
- package/lib/types/host/cline-pass/mapper.d.ts +1 -1
- package/lib/types/host/cline-pass/mapper.d.ts.map +1 -1
- package/lib/types/host/codemode/rules.d.ts.map +1 -1
- package/lib/types/host/codemode/transport.d.ts +23 -1
- package/lib/types/host/codemode/transport.d.ts.map +1 -1
- package/lib/types/host/command-code/adapter.d.ts.map +1 -1
- package/lib/types/host/common/llm-compat.d.ts +15 -2
- package/lib/types/host/common/llm-compat.d.ts.map +1 -1
- package/lib/types/host/common/stream-error.d.ts +1 -1
- package/lib/types/host/common/stream-error.d.ts.map +1 -1
- package/lib/types/host/common/tool-runaway.d.ts +91 -3
- package/lib/types/host/common/tool-runaway.d.ts.map +1 -1
- package/lib/types/host/compaction-policy-guard.d.ts.map +1 -1
- package/lib/types/host/glm-coding-plan/adapter.d.ts.map +1 -1
- package/lib/types/host/kimi-code/adapter.d.ts.map +1 -1
- package/lib/types/host/kimi-code/repeat-breaker.d.ts +3 -1
- package/lib/types/host/kimi-code/repeat-breaker.d.ts.map +1 -1
- package/lib/types/host/minimax-code/adapter.d.ts.map +1 -1
- package/lib/types/host/minimax-code/runtime-enhancements.d.ts +10 -97
- package/lib/types/host/minimax-code/runtime-enhancements.d.ts.map +1 -1
- package/lib/types/host/ollama/adapter.d.ts.map +1 -1
- package/lib/types/host/opendesign/adapter.d.ts.map +1 -1
- package/lib/types/host/opendesign/mapper.d.ts +1 -1
- package/lib/types/host/opendesign/mapper.d.ts.map +1 -1
- package/lib/types/host/qoder/adapter.d.ts.map +1 -1
- package/lib/types/host/responses-client.d.ts.map +1 -1
- package/lib/types/host/step-code/adapter.d.ts.map +1 -1
- package/lib/types/host/workbuddy/account-pool.d.ts +1 -1
- package/lib/types/host/workbuddy/account-pool.d.ts.map +1 -1
- package/lib/types/host/workbuddy/adapter.d.ts +2 -1
- package/lib/types/host/workbuddy/adapter.d.ts.map +1 -1
- package/lib/types/index.d.ts +2 -2
- package/lib/types/index.d.ts.map +1 -1
- package/package.json +42 -42
- package/presets/dispatch/README.md +2 -2
- package/presets/dispatch/agent.cordis.yml +2 -2
package/lib/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { a as resolveProgressUpdatesSettings, n as attachProgressSettings } from "./entry-progress-updates-DMLVID9V.js";
|
|
2
2
|
import { attachPlanModePipelineSettings, resolvePlanModePipelineEnabled } from "./plan-mode-pipeline.js";
|
|
3
|
-
import { n as PLUGIN_MESSAGE_SOURCE_KIND, r as normalizeGenerateOptions, t as LlmError$1 } from "./llm-compat
|
|
3
|
+
import { n as PLUGIN_MESSAGE_SOURCE_KIND, r as normalizeGenerateOptions, t as LlmError$1 } from "./llm-compat--WsaC9K6.js";
|
|
4
4
|
import { DEFAULT_SKIP_PROVIDERS, PRUNER_SERVICE_NAME, resolveSkipProviders, shouldSkipPruningForSession } from "./tool-result-pruner.js";
|
|
5
|
-
import {
|
|
5
|
+
import { S as resolveDispatchExecutionGuardEnabled, g as installPlanModeExitReminder, l as PLAN_PROJECTION_KEY, m as createPlanNotice, x as installDispatchExecutionGuard, y as registeredPlanControllerActive } from "./entry-plan-mode-EShP3ndV.js";
|
|
6
6
|
import { createRequire } from "node:module";
|
|
7
7
|
import * as LlmModule from "@deepseek-ai/dsh-llm";
|
|
8
8
|
import { EMPTY_RESPONSE_CODE, HarnessError, LlmAdapter, LlmError, ProviderRequestId, ReasoningEffortId, ToolCallId, attributionHeaders, createUserMessage, errorChain, resolveRetryPolicy } from "@deepseek-ai/dsh-llm";
|
|
@@ -817,7 +817,7 @@ const ROUTE_PREFIX$5 = "/api/dsh-chatgpt-subscription";
|
|
|
817
817
|
* `test/responses-client.test.ts` asserts the two agree, so a release that
|
|
818
818
|
* forgets this constant fails the suite instead of shipping quietly.
|
|
819
819
|
*/
|
|
820
|
-
const PLUGIN_VERSION = "0.
|
|
820
|
+
const PLUGIN_VERSION = "0.74.1";
|
|
821
821
|
const CODEX_CHATGPT_PROVIDER_ID = "codex-chatgpt";
|
|
822
822
|
const CODEX_API_BASE = "https://chatgpt.com/backend-api/codex";
|
|
823
823
|
const CODEX_RESPONSES_URL = `${CODEX_API_BASE}/responses`;
|
|
@@ -4486,8 +4486,8 @@ var OAuthService = class {
|
|
|
4486
4486
|
}
|
|
4487
4487
|
const payload = await response.json().catch(() => null);
|
|
4488
4488
|
const record = isRecord$69(payload) ? payload : {};
|
|
4489
|
-
const authId = nonEmptyString$
|
|
4490
|
-
const userCode = nonEmptyString$
|
|
4489
|
+
const authId = nonEmptyString$12(record.device_auth_id);
|
|
4490
|
+
const userCode = nonEmptyString$12(record.user_code) ?? nonEmptyString$12(record.usercode);
|
|
4491
4491
|
if (authId === void 0 || userCode === void 0) throw new OAuthServiceError("oauth-token-exchange-failed", "ChatGPT returned no device code.");
|
|
4492
4492
|
return {
|
|
4493
4493
|
authId,
|
|
@@ -4553,8 +4553,8 @@ var OAuthService = class {
|
|
|
4553
4553
|
throw new OAuthServiceError("oauth-token-exchange-failed", `The ChatGPT device confirmation was refused (${response.status}${detail === void 0 ? "" : `, ${detail}`}).`, response.status);
|
|
4554
4554
|
}
|
|
4555
4555
|
const record = isRecord$69(payload) ? payload : {};
|
|
4556
|
-
const authorizationCode = nonEmptyString$
|
|
4557
|
-
const codeVerifier = nonEmptyString$
|
|
4556
|
+
const authorizationCode = nonEmptyString$12(record.authorization_code);
|
|
4557
|
+
const codeVerifier = nonEmptyString$12(record.code_verifier);
|
|
4558
4558
|
if (authorizationCode === void 0 || codeVerifier === void 0) throw new OAuthServiceError("oauth-token-exchange-failed", "ChatGPT confirmed the device code but returned no authorization code.");
|
|
4559
4559
|
return {
|
|
4560
4560
|
authorizationCode,
|
|
@@ -4911,7 +4911,7 @@ function deviceErrorIdentifier(payload) {
|
|
|
4911
4911
|
candidates.push(payload.status);
|
|
4912
4912
|
for (const candidate of candidates) if (typeof candidate === "string" && /^[a-z0-9_.-]{1,64}$/i.test(candidate)) return candidate;
|
|
4913
4913
|
}
|
|
4914
|
-
function nonEmptyString$
|
|
4914
|
+
function nonEmptyString$12(value) {
|
|
4915
4915
|
return typeof value === "string" && value !== "" ? value : void 0;
|
|
4916
4916
|
}
|
|
4917
4917
|
function isRecord$69(value) {
|
|
@@ -5099,7 +5099,7 @@ function isRecord$68(value) {
|
|
|
5099
5099
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5100
5100
|
}
|
|
5101
5101
|
/** A trimmed, non-empty string, or nothing. */
|
|
5102
|
-
function nonEmptyString$
|
|
5102
|
+
function nonEmptyString$11(value) {
|
|
5103
5103
|
if (typeof value !== "string") return void 0;
|
|
5104
5104
|
const trimmed = value.trim();
|
|
5105
5105
|
return trimmed === "" ? void 0 : trimmed;
|
|
@@ -5246,9 +5246,9 @@ function parseAdoptedCodexCredential(value, sourcePath) {
|
|
|
5246
5246
|
if (value.auth_mode !== "chatgpt") return void 0;
|
|
5247
5247
|
const tokens = value[CODEX_CLI_TOKENS_KEY];
|
|
5248
5248
|
if (!isRecord$68(tokens)) return void 0;
|
|
5249
|
-
const accessToken = nonEmptyString$
|
|
5249
|
+
const accessToken = nonEmptyString$11(tokens.access_token);
|
|
5250
5250
|
if (accessToken === void 0) return void 0;
|
|
5251
|
-
const refreshToken = nonEmptyString$
|
|
5251
|
+
const refreshToken = nonEmptyString$11(tokens.refresh_token);
|
|
5252
5252
|
if (refreshToken === void 0) return void 0;
|
|
5253
5253
|
const expiresAt = expiryFromAccessToken(accessToken);
|
|
5254
5254
|
if (expiresAt === void 0) return void 0;
|
|
@@ -5257,17 +5257,17 @@ function parseAdoptedCodexCredential(value, sourcePath) {
|
|
|
5257
5257
|
refreshToken,
|
|
5258
5258
|
expiresAt
|
|
5259
5259
|
};
|
|
5260
|
-
const idToken = nonEmptyString$
|
|
5260
|
+
const idToken = nonEmptyString$11(tokens.id_token);
|
|
5261
5261
|
if (idToken !== void 0) {
|
|
5262
5262
|
credentials.idToken = idToken;
|
|
5263
5263
|
const claims = decodeJwtClaims$1(idToken);
|
|
5264
|
-
const email = claims === void 0 ? void 0 : nonEmptyString$
|
|
5264
|
+
const email = claims === void 0 ? void 0 : nonEmptyString$11(claims.email);
|
|
5265
5265
|
if (email !== void 0) credentials.email = email;
|
|
5266
5266
|
const authClaims = claims === void 0 ? void 0 : claims[CODEX_AUTH_CLAIMS_KEY];
|
|
5267
|
-
const planType = isRecord$68(authClaims) ? nonEmptyString$
|
|
5267
|
+
const planType = isRecord$68(authClaims) ? nonEmptyString$11(authClaims.chatgpt_plan_type) : void 0;
|
|
5268
5268
|
if (planType !== void 0) credentials.planType = planType;
|
|
5269
5269
|
}
|
|
5270
|
-
const accountId = nonEmptyString$
|
|
5270
|
+
const accountId = nonEmptyString$11(tokens.account_id);
|
|
5271
5271
|
if (accountId !== void 0) credentials.accountId = accountId;
|
|
5272
5272
|
return {
|
|
5273
5273
|
adopted: true,
|
|
@@ -7575,20 +7575,214 @@ function resolveToolRunawayGuardEnabled(config) {
|
|
|
7575
7575
|
}
|
|
7576
7576
|
return field !== false;
|
|
7577
7577
|
}
|
|
7578
|
+
/** 轮询类工具名(后台任务的结果读取)。 */
|
|
7579
|
+
const POLLING_TOOL_NAMES = Object.freeze(["job_output", "task_output"]);
|
|
7580
|
+
const TURN_ONLY_SUFFIX = " This is a temporary runtime reminder for the current Turn only, not a user preference or a durable rule; do not save this reminder or generalize it into Memory, Skills, or other persistent instruction files for future Turns or sessions.";
|
|
7581
|
+
/** 渲染「同一个动作立刻重复」提醒。 */
|
|
7582
|
+
function renderExactActionRepeatReminder(occurrences) {
|
|
7583
|
+
return `[runaway guard] The immediately repeated tool action has now occurred ${occurrences} times with the same arguments. Do not repeat it unchanged. Inspect the results already available, then either change strategy with a concrete expected state change, or report the blocker. Repetition alone does not establish that the task is complete or impossible.${TURN_ONLY_SUFFIX}`;
|
|
7584
|
+
}
|
|
7585
|
+
/** 渲染「同一族错误连续发生」提醒。 */
|
|
7586
|
+
function renderSameErrorFamilyReminder(occurrences) {
|
|
7587
|
+
return `[runaway guard] The same tool error family has now occurred ${occurrences} times in a row. Do not retry the same route unchanged. Diagnose the cause, change one controlled variable or switch route. Do not infer that the entire task has failed from this signal.${TURN_ONLY_SUFFIX}`;
|
|
7588
|
+
}
|
|
7589
|
+
/** 渲染「反复轮询同一个后台任务」提醒。 */
|
|
7590
|
+
function renderPollingRepeatReminder(occurrences) {
|
|
7591
|
+
return [
|
|
7592
|
+
"<system-reminder>",
|
|
7593
|
+
`${occurrences === 3 ? "Three" : String(occurrences)} task_output reads for the same task have returned an unchanged status and output cursor. Avoid repeated polling; you will be notified automatically and this conversation will resume when the background task completes.`,
|
|
7594
|
+
"This reminder applies only to the current Turn. Do not save or generalize it into Memory, Skills, or other persistent instructions.",
|
|
7595
|
+
"</system-reminder>"
|
|
7596
|
+
].join("\n");
|
|
7597
|
+
}
|
|
7598
|
+
/** 规范化错误文本,去掉会漂移的数字/id/时间戳,取它的「族」。 */
|
|
7599
|
+
function normalizeToolErrorFamily(text) {
|
|
7600
|
+
if (text === void 0 || text === "") return "unknown";
|
|
7601
|
+
return (text.split(/\r?\n/, 1)[0] ?? "").replace(/\d+/g, "#").slice(0, 200);
|
|
7602
|
+
}
|
|
7603
|
+
function nonEmptyString$10(value) {
|
|
7604
|
+
return typeof value === "string" && value !== "" ? value : void 0;
|
|
7605
|
+
}
|
|
7606
|
+
/** 判断一次工具执行结果是否失败。 */
|
|
7607
|
+
function isToolErrorResult(result) {
|
|
7608
|
+
return isRecord$67(result) && result["isError"] === true;
|
|
7609
|
+
}
|
|
7610
|
+
/** 读一次工具执行结果里的结构化错误码。 */
|
|
7611
|
+
function toolErrorCodeOf(result) {
|
|
7612
|
+
if (!isRecord$67(result)) return void 0;
|
|
7613
|
+
const error = result["error"];
|
|
7614
|
+
if (!isRecord$67(error)) return void 0;
|
|
7615
|
+
const info = error["info"];
|
|
7616
|
+
if (isRecord$67(info)) {
|
|
7617
|
+
const infoCode = nonEmptyString$10(info["code"]);
|
|
7618
|
+
if (infoCode !== void 0) return infoCode;
|
|
7619
|
+
}
|
|
7620
|
+
return nonEmptyString$10(error["code"]);
|
|
7621
|
+
}
|
|
7622
|
+
/** 读一次工具执行结果里的全部文本块。 */
|
|
7623
|
+
function toolResultTextOf(result) {
|
|
7624
|
+
if (!isRecord$67(result)) return "";
|
|
7625
|
+
const content = result["content"];
|
|
7626
|
+
if (!Array.isArray(content)) return "";
|
|
7627
|
+
const parts = [];
|
|
7628
|
+
for (const block of content) if (isRecord$67(block) && block["type"] === "text") parts.push(nonEmptyString$10(block["text"]) ?? "");
|
|
7629
|
+
return parts.join("\n");
|
|
7630
|
+
}
|
|
7631
|
+
/** 读一次工具执行结果里的失败文本(无 `error.message` 且为错误结果时回退读取文本内容)。 */
|
|
7632
|
+
function toolErrorTextOf(result) {
|
|
7633
|
+
if (isRecord$67(result)) {
|
|
7634
|
+
const error = result["error"];
|
|
7635
|
+
if (isRecord$67(error)) {
|
|
7636
|
+
const msg = nonEmptyString$10(error["message"]);
|
|
7637
|
+
if (msg !== void 0) return msg;
|
|
7638
|
+
}
|
|
7639
|
+
}
|
|
7640
|
+
if (!isToolErrorResult(result)) return void 0;
|
|
7641
|
+
const text = toolResultTextOf(result);
|
|
7642
|
+
return text === "" ? void 0 : text;
|
|
7643
|
+
}
|
|
7644
|
+
/** 从一次工具执行与结果中构造失控检测观察量。 */
|
|
7645
|
+
function observationFromToolExecution(toolName, args, result) {
|
|
7646
|
+
return {
|
|
7647
|
+
toolName,
|
|
7648
|
+
arguments: args,
|
|
7649
|
+
isError: isToolErrorResult(result),
|
|
7650
|
+
errorCode: toolErrorCodeOf(result),
|
|
7651
|
+
errorText: toolErrorTextOf(result),
|
|
7652
|
+
resultText: toolResultTextOf(result)
|
|
7653
|
+
};
|
|
7654
|
+
}
|
|
7655
|
+
function isPollingObservation(toolName, args) {
|
|
7656
|
+
if (!POLLING_TOOL_NAMES.includes(toolName)) return false;
|
|
7657
|
+
return (isPlainRecord$2(args) ? args : void 0)?.["wait"] !== true;
|
|
7658
|
+
}
|
|
7659
|
+
/**
|
|
7660
|
+
* 造一台单会话工具级失控守卫。
|
|
7661
|
+
*
|
|
7662
|
+
* 三种可提醒信号(顺序即提醒优先级):
|
|
7663
|
+
* 1. `same_error_family` —— 同一个工具连续报同一族错误;
|
|
7664
|
+
* 2. `exact_action_repeat` —— 同一次动作(同名 + 同参数)立刻重复;
|
|
7665
|
+
* 3. `polling_repeat` —— 连续轮询同一个后台任务而输出没变。
|
|
7666
|
+
*/
|
|
7667
|
+
function createToolRunawayGuard(options = {}) {
|
|
7668
|
+
const threshold = options.remindAfterOccurrences ?? 3;
|
|
7669
|
+
const exactActionRepeats = createExactRepeatTracker();
|
|
7670
|
+
const errorStreaks = /* @__PURE__ */ new Map();
|
|
7671
|
+
const pollingStreaks = /* @__PURE__ */ new Map();
|
|
7672
|
+
const recentActions = [];
|
|
7673
|
+
let activeAbabKey;
|
|
7674
|
+
let reminderAttempted = false;
|
|
7675
|
+
const signals = [];
|
|
7676
|
+
const record = (kind, occurrences, toolName) => {
|
|
7677
|
+
signals.push({
|
|
7678
|
+
kind,
|
|
7679
|
+
occurrences,
|
|
7680
|
+
toolName
|
|
7681
|
+
});
|
|
7682
|
+
};
|
|
7683
|
+
return {
|
|
7684
|
+
observe(observation) {
|
|
7685
|
+
const toolName = observation.toolName;
|
|
7686
|
+
const actionKey = canonicalToolCallKey(toolName, observation.arguments);
|
|
7687
|
+
const countsAsAction = !POLLING_TOOL_NAMES.includes(toolName);
|
|
7688
|
+
if (countsAsAction) {
|
|
7689
|
+
const action = exactActionRepeats.observe(toolName, observation.arguments);
|
|
7690
|
+
record("exact_action_repeat", action.count, toolName);
|
|
7691
|
+
}
|
|
7692
|
+
if (countsAsAction) {
|
|
7693
|
+
recentActions.push(actionKey);
|
|
7694
|
+
if (recentActions.length > 4) recentActions.shift();
|
|
7695
|
+
if (recentActions.length === 4) {
|
|
7696
|
+
const [a, b, c, d] = recentActions;
|
|
7697
|
+
if (a !== void 0 && b !== void 0 && a !== b && a === c && b === d) {
|
|
7698
|
+
const episode = `${a}\u0000${b}`;
|
|
7699
|
+
if (activeAbabKey !== episode) {
|
|
7700
|
+
activeAbabKey = episode;
|
|
7701
|
+
record("abab_action_cycle", 2, toolName);
|
|
7702
|
+
}
|
|
7703
|
+
} else activeAbabKey = void 0;
|
|
7704
|
+
}
|
|
7705
|
+
}
|
|
7706
|
+
if (observation.isError === true) {
|
|
7707
|
+
const key = `${toolName}\u0000${observation.errorCode ?? normalizeToolErrorFamily(observation.errorText)}`;
|
|
7708
|
+
const previous = errorStreaks.get(key);
|
|
7709
|
+
const count = previous === void 0 ? 1 : previous.count + 1;
|
|
7710
|
+
errorStreaks.set(key, {
|
|
7711
|
+
toolName,
|
|
7712
|
+
count
|
|
7713
|
+
});
|
|
7714
|
+
record("same_error_family", count, toolName);
|
|
7715
|
+
} else for (const [key, entry] of [...errorStreaks]) if (entry.toolName === toolName) errorStreaks.delete(key);
|
|
7716
|
+
if (isPollingObservation(toolName, observation.arguments)) {
|
|
7717
|
+
const key = `${canonicalToolCallKey(toolName, observation.arguments)}\u0000${observation.resultText ?? ""}`;
|
|
7718
|
+
const previous = pollingStreaks.get(toolName);
|
|
7719
|
+
const count = previous !== void 0 && previous.key === key ? previous.count + 1 : 1;
|
|
7720
|
+
pollingStreaks.set(toolName, {
|
|
7721
|
+
key,
|
|
7722
|
+
count
|
|
7723
|
+
});
|
|
7724
|
+
record("polling_repeat", count, toolName);
|
|
7725
|
+
} else pollingStreaks.delete(toolName);
|
|
7726
|
+
if (reminderAttempted) return void 0;
|
|
7727
|
+
const errorCandidate = [...errorStreaks.values()].find((entry) => entry.count >= threshold);
|
|
7728
|
+
if (errorCandidate !== void 0) {
|
|
7729
|
+
reminderAttempted = true;
|
|
7730
|
+
return {
|
|
7731
|
+
kind: "same_error_family",
|
|
7732
|
+
occurrences: errorCandidate.count,
|
|
7733
|
+
text: renderSameErrorFamilyReminder(errorCandidate.count)
|
|
7734
|
+
};
|
|
7735
|
+
}
|
|
7736
|
+
const actionStreak = exactActionRepeats.current();
|
|
7737
|
+
if (countsAsAction && actionStreak !== void 0 && actionStreak.count >= threshold) {
|
|
7738
|
+
reminderAttempted = true;
|
|
7739
|
+
return {
|
|
7740
|
+
kind: "exact_action_repeat",
|
|
7741
|
+
occurrences: actionStreak.count,
|
|
7742
|
+
text: renderExactActionRepeatReminder(actionStreak.count)
|
|
7743
|
+
};
|
|
7744
|
+
}
|
|
7745
|
+
const pollingCandidate = [...pollingStreaks.values()].find((entry) => entry.count >= threshold);
|
|
7746
|
+
if (pollingCandidate !== void 0) {
|
|
7747
|
+
reminderAttempted = true;
|
|
7748
|
+
return {
|
|
7749
|
+
kind: "polling_repeat",
|
|
7750
|
+
occurrences: pollingCandidate.count,
|
|
7751
|
+
text: renderPollingRepeatReminder(pollingCandidate.count)
|
|
7752
|
+
};
|
|
7753
|
+
}
|
|
7754
|
+
},
|
|
7755
|
+
reset() {
|
|
7756
|
+
exactActionRepeats.reset();
|
|
7757
|
+
errorStreaks.clear();
|
|
7758
|
+
pollingStreaks.clear();
|
|
7759
|
+
recentActions.length = 0;
|
|
7760
|
+
activeAbabKey = void 0;
|
|
7761
|
+
reminderAttempted = false;
|
|
7762
|
+
},
|
|
7763
|
+
get signals() {
|
|
7764
|
+
return signals;
|
|
7765
|
+
}
|
|
7766
|
+
};
|
|
7767
|
+
}
|
|
7578
7768
|
/**
|
|
7579
|
-
* Exact-repeat
|
|
7580
|
-
*
|
|
7769
|
+
* Exact-repeat + deterministic zero-progress (same error family / unchanged polling)
|
|
7770
|
+
* state machine shared by provider profiles. A missing forceStopAt gives reminders only;
|
|
7771
|
+
* no provider inherits Kimi's hard stop accidentally.
|
|
7581
7772
|
*/
|
|
7582
7773
|
function createExactRepeatBreaker(options) {
|
|
7583
7774
|
const sessions = /* @__PURE__ */ new Map();
|
|
7584
7775
|
const maxSessions = options.maxSessions ?? 256;
|
|
7585
7776
|
const exempt = new Set(options.exemptTools ?? TOOL_RUNAWAY_EXEMPT_TOOLS);
|
|
7777
|
+
const errorAndPollingThreshold = options.errorAndPollingThreshold ?? 3;
|
|
7586
7778
|
const stateOf = (sessionId) => {
|
|
7587
7779
|
let state = sessions.get(sessionId);
|
|
7588
7780
|
if (state === void 0) state = {
|
|
7589
7781
|
tracker: createExactRepeatTracker(),
|
|
7590
7782
|
count: 0,
|
|
7591
|
-
handoffActive: false
|
|
7783
|
+
handoffActive: false,
|
|
7784
|
+
errorStreaks: /* @__PURE__ */ new Map(),
|
|
7785
|
+
pollingStreaks: /* @__PURE__ */ new Map()
|
|
7592
7786
|
};
|
|
7593
7787
|
sessions.delete(sessionId);
|
|
7594
7788
|
sessions.set(sessionId, state);
|
|
@@ -7598,11 +7792,26 @@ function createExactRepeatBreaker(options) {
|
|
|
7598
7792
|
}
|
|
7599
7793
|
return state;
|
|
7600
7794
|
};
|
|
7795
|
+
const updateErrorStreaks = (state, toolName, observation) => {
|
|
7796
|
+
if (observation.isError === true) {
|
|
7797
|
+
const key = `${toolName}\u0000${observation.errorCode ?? normalizeToolErrorFamily(observation.errorText)}`;
|
|
7798
|
+
const previous = state.errorStreaks.get(key);
|
|
7799
|
+
const count = previous === void 0 ? 1 : previous.count + 1;
|
|
7800
|
+
state.errorStreaks.set(key, {
|
|
7801
|
+
toolName,
|
|
7802
|
+
count
|
|
7803
|
+
});
|
|
7804
|
+
return count;
|
|
7805
|
+
}
|
|
7806
|
+
for (const [key, entry] of [...state.errorStreaks]) if (entry.toolName === toolName) state.errorStreaks.delete(key);
|
|
7807
|
+
return 0;
|
|
7808
|
+
};
|
|
7601
7809
|
return {
|
|
7602
7810
|
checkBeforeExecute(sessionId, toolName, args) {
|
|
7603
7811
|
if (options.forceStopAt === void 0) return void 0;
|
|
7604
7812
|
const state = stateOf(sessionId);
|
|
7605
7813
|
if (state.handoffActive) return options.handoffVeto ?? options.handoffReminder;
|
|
7814
|
+
if (POLLING_TOOL_NAMES.includes(toolName)) return void 0;
|
|
7606
7815
|
const key = canonicalToolCallKey(toolName, args);
|
|
7607
7816
|
if (state.tracker.current()?.key === key && state.count + 1 >= options.forceStopAt) {
|
|
7608
7817
|
state.count += 1;
|
|
@@ -7610,16 +7819,37 @@ function createExactRepeatBreaker(options) {
|
|
|
7610
7819
|
return options.handoffVeto ?? options.handoffReminder;
|
|
7611
7820
|
}
|
|
7612
7821
|
},
|
|
7613
|
-
recordAfterExecute(sessionId, toolName, args) {
|
|
7822
|
+
recordAfterExecute(sessionId, toolName, args, observation) {
|
|
7614
7823
|
if (exempt.has(toolName)) return void 0;
|
|
7615
7824
|
const state = stateOf(sessionId);
|
|
7616
7825
|
if (state.handoffActive) return options.handoffReminder ?? options.reminder(state.count);
|
|
7826
|
+
if (POLLING_TOOL_NAMES.includes(toolName) && observation !== void 0) {
|
|
7827
|
+
const errorCount = updateErrorStreaks(state, toolName, observation);
|
|
7828
|
+
const isPolling = isPollingObservation(toolName, args);
|
|
7829
|
+
let pollCount = 0;
|
|
7830
|
+
if (isPolling) {
|
|
7831
|
+
const key = `${canonicalToolCallKey(toolName, args)}\u0000${observation.resultText ?? ""}`;
|
|
7832
|
+
const previous = state.pollingStreaks.get(toolName);
|
|
7833
|
+
pollCount = previous !== void 0 && previous.key === key ? previous.count + 1 : 1;
|
|
7834
|
+
state.pollingStreaks.set(toolName, {
|
|
7835
|
+
key,
|
|
7836
|
+
count: pollCount
|
|
7837
|
+
});
|
|
7838
|
+
} else state.pollingStreaks.delete(toolName);
|
|
7839
|
+
if (observation.isError === true && errorCount >= errorAndPollingThreshold) return renderSameErrorFamilyReminder(errorCount);
|
|
7840
|
+
if (isPolling && pollCount >= errorAndPollingThreshold) return renderPollingRepeatReminder(pollCount);
|
|
7841
|
+
return;
|
|
7842
|
+
}
|
|
7843
|
+
if (!POLLING_TOOL_NAMES.includes(toolName)) state.pollingStreaks.clear();
|
|
7617
7844
|
state.count = state.tracker.observe(toolName, args).count;
|
|
7618
7845
|
if (options.forceStopAt !== void 0 && state.count >= options.forceStopAt) {
|
|
7619
7846
|
state.handoffActive = true;
|
|
7620
7847
|
return options.handoffReminder ?? options.reminder(state.count);
|
|
7621
7848
|
}
|
|
7622
|
-
|
|
7849
|
+
const errorCount = observation !== void 0 ? updateErrorStreaks(state, toolName, observation) : 0;
|
|
7850
|
+
const exactReminder = options.reminder(state.count);
|
|
7851
|
+
if (exactReminder !== void 0) return exactReminder;
|
|
7852
|
+
if (errorCount >= errorAndPollingThreshold) return renderSameErrorFamilyReminder(errorCount);
|
|
7623
7853
|
},
|
|
7624
7854
|
resetSession(sessionId) {
|
|
7625
7855
|
sessions.delete(sessionId);
|
|
@@ -10195,7 +10425,7 @@ var ResponsesClient = class {
|
|
|
10195
10425
|
release = opened.release;
|
|
10196
10426
|
break;
|
|
10197
10427
|
} catch (error) {
|
|
10198
|
-
if (error instanceof LlmError && (error.code === "NOT_FOUND" || error.status === 404)) {
|
|
10428
|
+
if (error instanceof LlmError$1 && (error.code === "NOT_FOUND" || error.status === 404)) {
|
|
10199
10429
|
const fallback = resolveCodexFallbackModel(currentModel);
|
|
10200
10430
|
if (fallback && fallback.id !== currentModel) {
|
|
10201
10431
|
currentModel = fallback.id;
|
|
@@ -10321,7 +10551,7 @@ var ResponsesClient = class {
|
|
|
10321
10551
|
await pool.markAuthFailed(account.id, error instanceof Error ? error.message : "ChatGPT sign-in expired.").catch(() => void 0);
|
|
10322
10552
|
free();
|
|
10323
10553
|
if (await pool.hasAnotherAvailableAccount(tried)) continue;
|
|
10324
|
-
throw new LlmError("ChatGPT sign-in has expired. Sign in again.", "AUTH", {
|
|
10554
|
+
throw new LlmError$1("ChatGPT sign-in has expired. Sign in again.", "AUTH", {
|
|
10325
10555
|
status: 401,
|
|
10326
10556
|
cause: error
|
|
10327
10557
|
});
|
|
@@ -10333,7 +10563,7 @@ var ResponsesClient = class {
|
|
|
10333
10563
|
await pool.markCooldown(account.id, after ?? DEFAULT_POOL_COOLDOWN_MS, "Codex 429").catch(() => void 0);
|
|
10334
10564
|
free();
|
|
10335
10565
|
if (await pool.hasAnotherAvailableAccount(tried)) continue;
|
|
10336
|
-
throw new LlmError("Codex rate limit reached.", "RATE_LIMIT", {
|
|
10566
|
+
throw new LlmError$1("Codex rate limit reached.", "RATE_LIMIT", {
|
|
10337
10567
|
status: 429,
|
|
10338
10568
|
...after === void 0 ? {} : { providerRetryAfterMs: after }
|
|
10339
10569
|
});
|
|
@@ -10382,7 +10612,7 @@ var ResponsesClient = class {
|
|
|
10382
10612
|
continue;
|
|
10383
10613
|
}
|
|
10384
10614
|
const chain = errorChain(cause).trim();
|
|
10385
|
-
throw new LlmError(`Codex request failed: ${chain === "" ? "the connection failed before any response arrived" : chain.slice(0, 500)}${isPreConnectionFailure$2(cause) ? " The request never reached ChatGPT. Check the network, proxy/VPN/TUN, or the plugin proxy settings." : ""}`, "NETWORK", { cause });
|
|
10615
|
+
throw new LlmError$1(`Codex request failed: ${chain === "" ? "the connection failed before any response arrived" : chain.slice(0, 500)}${isPreConnectionFailure$2(cause) ? " The request never reached ChatGPT. Check the network, proxy/VPN/TUN, or the plugin proxy settings." : ""}`, "NETWORK", { cause });
|
|
10386
10616
|
}
|
|
10387
10617
|
}
|
|
10388
10618
|
};
|
|
@@ -10428,10 +10658,10 @@ function isPreConnectionFailure$2(error) {
|
|
|
10428
10658
|
* so retrying can neither repeat committed output nor re-run a tool.
|
|
10429
10659
|
*/
|
|
10430
10660
|
function streamFailure$2(error, signal) {
|
|
10431
|
-
if (error instanceof LlmError) return error;
|
|
10432
|
-
if (signal?.aborted) return new LlmError("Codex request aborted", "ABORTED", { cause: error });
|
|
10661
|
+
if (error instanceof LlmError$1) return error;
|
|
10662
|
+
if (signal?.aborted) return new LlmError$1("Codex request aborted", "ABORTED", { cause: error });
|
|
10433
10663
|
const chain = errorChain(error).trim();
|
|
10434
|
-
return new LlmError(`Codex stream failed: ${chain === "" ? "the response stream ended unexpectedly" : chain.slice(0, 500)}`, "TRANSPORT", { cause: error });
|
|
10664
|
+
return new LlmError$1(`Codex stream failed: ${chain === "" ? "the response stream ended unexpectedly" : chain.slice(0, 500)}`, "TRANSPORT", { cause: error });
|
|
10435
10665
|
}
|
|
10436
10666
|
/**
|
|
10437
10667
|
* Prompt cache key for one conversation.
|
|
@@ -10455,7 +10685,7 @@ function perRequestNonce() {
|
|
|
10455
10685
|
return requestCounter;
|
|
10456
10686
|
}
|
|
10457
10687
|
async function* parseResponsesStream(response, signal, _legacyHiddenSandboxControls = /* @__PURE__ */ new Set(), activity) {
|
|
10458
|
-
if (response.body === null) throw new LlmError("Codex returned no response stream.", "PROVIDER_ERROR");
|
|
10688
|
+
if (response.body === null) throw new LlmError$1("Codex returned no response stream.", "PROVIDER_ERROR");
|
|
10459
10689
|
const reader = response.body.getReader();
|
|
10460
10690
|
const abortReader = () => {
|
|
10461
10691
|
reader.cancel(signal?.reason).catch(() => void 0);
|
|
@@ -10651,7 +10881,7 @@ async function* parseResponsesStream(response, signal, _legacyHiddenSandboxContr
|
|
|
10651
10881
|
const message = string(error?.message) ?? "Codex generation failed.";
|
|
10652
10882
|
const rawCode = string(error?.code)?.toLowerCase();
|
|
10653
10883
|
const isOverload = message.toLowerCase().includes("overload") || message.toLowerCase().includes("server error") || rawCode === "server_error" || rawCode === "service_unavailable" || rawCode === "internal_error";
|
|
10654
|
-
throw new LlmError(message, message.toLowerCase().includes("rate limit") || rawCode === "rate_limit" ? "RATE_LIMIT" : isOverload ? "SERVER_ERROR" : isContextOverflow(error) ? CONTEXT_OVERFLOW_CODE : string(error?.code)?.toUpperCase() ?? "PROVIDER_ERROR");
|
|
10884
|
+
throw new LlmError$1(message, message.toLowerCase().includes("rate limit") || rawCode === "rate_limit" ? "RATE_LIMIT" : isOverload ? "SERVER_ERROR" : isContextOverflow(error) ? CONTEXT_OVERFLOW_CODE : string(error?.code)?.toUpperCase() ?? "PROVIDER_ERROR");
|
|
10655
10885
|
}
|
|
10656
10886
|
};
|
|
10657
10887
|
try {
|
|
@@ -10671,7 +10901,7 @@ async function* parseResponsesStream(response, signal, _legacyHiddenSandboxContr
|
|
|
10671
10901
|
try {
|
|
10672
10902
|
event = JSON.parse(data);
|
|
10673
10903
|
} catch {
|
|
10674
|
-
throw new LlmError("Codex returned malformed streaming JSON.", "PROTOCOL_ERROR");
|
|
10904
|
+
throw new LlmError$1("Codex returned malformed streaming JSON.", "PROTOCOL_ERROR");
|
|
10675
10905
|
}
|
|
10676
10906
|
const valueRecord = record$3(event);
|
|
10677
10907
|
if (valueRecord !== null) yield* consume(valueRecord);
|
|
@@ -10682,7 +10912,7 @@ async function* parseResponsesStream(response, signal, _legacyHiddenSandboxContr
|
|
|
10682
10912
|
reader.releaseLock();
|
|
10683
10913
|
}
|
|
10684
10914
|
if (signal?.aborted) throw signal.reason ?? new DOMException("Aborted", "AbortError");
|
|
10685
|
-
if (terminal === null) throw new LlmError("Codex stream ended before a terminal event.", "PROTOCOL_ERROR");
|
|
10915
|
+
if (terminal === null) throw new LlmError$1("Codex stream ended before a terminal event.", "PROTOCOL_ERROR");
|
|
10686
10916
|
const finalReason = terminal;
|
|
10687
10917
|
if (reasoningIndex !== null) {
|
|
10688
10918
|
if (pendingReasoningDelta !== "") {
|
|
@@ -10718,7 +10948,7 @@ async function* parseResponsesStream(response, signal, _legacyHiddenSandboxContr
|
|
|
10718
10948
|
const replayedToolCallIds = new Set(replayOutput.flatMap((item) => item.type === "function_call" && typeof item.call_id === "string" ? [item.call_id] : []));
|
|
10719
10949
|
for (const tool of tools.values()) {
|
|
10720
10950
|
if (!tool.started) continue;
|
|
10721
|
-
if (!isSafeJsonArguments(tool.arguments) || tool.name === "") throw new LlmError(`Codex returned invalid JSON arguments for tool ${tool.name || "(unnamed)"}.`, "INVALID_TOOL_ARGUMENTS");
|
|
10951
|
+
if (!isSafeJsonArguments(tool.arguments) || tool.name === "") throw new LlmError$1(`Codex returned invalid JSON arguments for tool ${tool.name || "(unnamed)"}.`, "INVALID_TOOL_ARGUMENTS");
|
|
10722
10952
|
validToolCount++;
|
|
10723
10953
|
if (!replayedToolCallIds.has(tool.id)) {
|
|
10724
10954
|
replayOutput.push({
|
|
@@ -10775,7 +11005,7 @@ function incompleteFinishReason(response) {
|
|
|
10775
11005
|
if (reason === "steered") return { kind: "stop" };
|
|
10776
11006
|
const detail = JSON.stringify(reason);
|
|
10777
11007
|
const message = string(record$3(response?.error)?.message);
|
|
10778
|
-
throw new LlmError(`Codex returned an incomplete response (${detail})${message ? `: ${message}` : "."}`, reason === "content_filter" ? "CONTENT_FILTER" : "PROVIDER_INCOMPLETE");
|
|
11008
|
+
throw new LlmError$1(`Codex returned an incomplete response (${detail})${message ? `: ${message}` : "."}`, reason === "content_filter" ? "CONTENT_FILTER" : "PROVIDER_INCOMPLETE");
|
|
10779
11009
|
}
|
|
10780
11010
|
function visibleReasoningDelta(delta, currentVisibleChars, alreadyTruncated) {
|
|
10781
11011
|
if (delta === "" || alreadyTruncated) return {
|
|
@@ -10837,12 +11067,12 @@ async function responseError(response) {
|
|
|
10837
11067
|
...requestId ? { requestId: ProviderRequestId(requestId) } : {},
|
|
10838
11068
|
...response.status === 429 ? { providerRetryAfterMs: retryAfterMs$1(response.headers) } : {}
|
|
10839
11069
|
};
|
|
10840
|
-
if (isHttpContextOverflow(response.status, detail)) return new LlmError(`Codex context window exceeded: ${detail}`, CONTEXT_OVERFLOW_CODE, options);
|
|
10841
|
-
if (response.status === 401) return new LlmError("ChatGPT sign-in has expired. Sign in again.", "AUTH", options);
|
|
10842
|
-
if (response.status === 404) return new LlmError(`Codex model or resource not found (${response.status})${detail ? `: ${detail}` : "."}`, "NOT_FOUND", options);
|
|
10843
|
-
if (response.status === 429) return new LlmError("Codex rate limit reached.", "RATE_LIMIT", options);
|
|
10844
|
-
if (response.status >= 500) return new LlmError(`Codex service error (${response.status}).`, "SERVER_ERROR", options);
|
|
10845
|
-
return new LlmError(`Codex request failed (${response.status})${detail ? `: ${detail}` : "."}`, "PROVIDER_ERROR", options);
|
|
11070
|
+
if (isHttpContextOverflow(response.status, detail)) return new LlmError$1(`Codex context window exceeded: ${detail}`, CONTEXT_OVERFLOW_CODE, options);
|
|
11071
|
+
if (response.status === 401) return new LlmError$1("ChatGPT sign-in has expired. Sign in again.", "AUTH", options);
|
|
11072
|
+
if (response.status === 404) return new LlmError$1(`Codex model or resource not found (${response.status})${detail ? `: ${detail}` : "."}`, "NOT_FOUND", options);
|
|
11073
|
+
if (response.status === 429) return new LlmError$1("Codex rate limit reached.", "RATE_LIMIT", options);
|
|
11074
|
+
if (response.status >= 500) return new LlmError$1(`Codex service error (${response.status}).`, "SERVER_ERROR", options);
|
|
11075
|
+
return new LlmError$1(`Codex request failed (${response.status})${detail ? `: ${detail}` : "."}`, "PROVIDER_ERROR", options);
|
|
10846
11076
|
}
|
|
10847
11077
|
/**
|
|
10848
11078
|
* Concatenated assistant text a non-delta `message` output item carries, which
|
|
@@ -19624,7 +19854,7 @@ function reclassifyInBandError(thrown, rawError, classify, statusFor = inBandAnt
|
|
|
19624
19854
|
if (status === null) return thrown;
|
|
19625
19855
|
const failure = classify(status, JSON.stringify({ error: rawError }));
|
|
19626
19856
|
if (!failure.retryable) return thrown;
|
|
19627
|
-
return new LlmError(thrown.message, failure.code, { cause: thrown });
|
|
19857
|
+
return new LlmError$1(thrown.message, failure.code, { cause: thrown });
|
|
19628
19858
|
}
|
|
19629
19859
|
/**
|
|
19630
19860
|
* {@link reclassifyInBandError} for a line whose classifier reads a status, fed
|
|
@@ -19647,7 +19877,7 @@ function reclassifyInBandResponsesError(thrown, rawError, message, classify) {
|
|
|
19647
19877
|
message
|
|
19648
19878
|
}));
|
|
19649
19879
|
if (!failure.retryable) return thrown;
|
|
19650
|
-
return new LlmError(thrown.message, failure.code, { cause: thrown });
|
|
19880
|
+
return new LlmError$1(thrown.message, failure.code, { cause: thrown });
|
|
19651
19881
|
}
|
|
19652
19882
|
/** The wire `error` object of an in-band event, read defensively. */
|
|
19653
19883
|
function readErrorType(error) {
|
|
@@ -20067,7 +20297,7 @@ var CommandCodeAdapter = class extends LlmAdapter {
|
|
|
20067
20297
|
}));
|
|
20068
20298
|
}
|
|
20069
20299
|
async resolveModel(provider, modelId, signal) {
|
|
20070
|
-
if (signal?.aborted) throw new LlmError("Command Code model resolution aborted", "ABORTED");
|
|
20300
|
+
if (signal?.aborted) throw new LlmError$1("Command Code model resolution aborted", "ABORTED");
|
|
20071
20301
|
const settings = await this.settings();
|
|
20072
20302
|
const entry = (await this.catalog()).find((model) => model.id === modelId);
|
|
20073
20303
|
const efforts = reasoningEffortsFor$1(modelId);
|
|
@@ -20136,7 +20366,7 @@ var CommandCodeAdapter = class extends LlmAdapter {
|
|
|
20136
20366
|
let apiEnv;
|
|
20137
20367
|
if (pool === null) {
|
|
20138
20368
|
const credentials = await this.store.read();
|
|
20139
|
-
if (credentials === null) throw new LlmError(`Not signed in to ${PROVIDER_NAME$11}. Sign in from Settings > Command Code, or paste an API key there.`, "MISSING_CREDENTIAL");
|
|
20369
|
+
if (credentials === null) throw new LlmError$1(`Not signed in to ${PROVIDER_NAME$11}. Sign in from Settings > Command Code, or paste an API key there.`, "MISSING_CREDENTIAL");
|
|
20140
20370
|
apiKey = credentials.apiKey;
|
|
20141
20371
|
apiEnv = credentials.apiEnv ?? resolveApiEnv();
|
|
20142
20372
|
} else {
|
|
@@ -20166,13 +20396,13 @@ var CommandCodeAdapter = class extends LlmAdapter {
|
|
|
20166
20396
|
});
|
|
20167
20397
|
activity?.pulse();
|
|
20168
20398
|
} catch (error) {
|
|
20169
|
-
if (signal.aborted) throw new LlmError("Command Code request aborted", "ABORTED", { cause: error });
|
|
20170
|
-
throw new LlmError(`Command Code request failed: ${error instanceof Error ? error.message : String(error)}`, "TRANSPORT", { cause: error });
|
|
20399
|
+
if (signal.aborted) throw new LlmError$1("Command Code request aborted", "ABORTED", { cause: error });
|
|
20400
|
+
throw new LlmError$1(`Command Code request failed: ${error instanceof Error ? error.message : String(error)}`, "TRANSPORT", { cause: error });
|
|
20171
20401
|
}
|
|
20172
20402
|
if (response.ok) break;
|
|
20173
20403
|
detail = (await response.text().catch(() => "")).slice(0, 600);
|
|
20174
20404
|
if (response.status === 422) {
|
|
20175
|
-
if (detail.includes("cmd_zdr_no_providers")) throw new LlmError(`${PROVIDER_NAME$11} rejected request under Zero Data Retention: no ZDR-capable upstream is available for this model (${detail || "cmd_zdr_no_providers"}).`, "PROVIDER_ERROR", { status: 422 });
|
|
20405
|
+
if (detail.includes("cmd_zdr_no_providers")) throw new LlmError$1(`${PROVIDER_NAME$11} rejected request under Zero Data Retention: no ZDR-capable upstream is available for this model (${detail || "cmd_zdr_no_providers"}).`, "PROVIDER_ERROR", { status: 422 });
|
|
20176
20406
|
break;
|
|
20177
20407
|
}
|
|
20178
20408
|
if (pool === null || accountId === void 0) break;
|
|
@@ -20194,22 +20424,22 @@ var CommandCodeAdapter = class extends LlmAdapter {
|
|
|
20194
20424
|
const status = response?.status ?? 500;
|
|
20195
20425
|
const { code } = classifyCommandCodeFailure(status, detail);
|
|
20196
20426
|
if (status === 422) {
|
|
20197
|
-
if (detail.includes("cmd_zdr_no_providers")) throw new LlmError(`${PROVIDER_NAME$11} rejected request under Zero Data Retention: no ZDR-capable upstream is available for this model (${detail || "cmd_zdr_no_providers"}).`, code, { status: 422 });
|
|
20198
|
-
throw new LlmError(`${PROVIDER_NAME$11} validation error (422): ${detail || "Unprocessable Entity"}`, code, { status: 422 });
|
|
20427
|
+
if (detail.includes("cmd_zdr_no_providers")) throw new LlmError$1(`${PROVIDER_NAME$11} rejected request under Zero Data Retention: no ZDR-capable upstream is available for this model (${detail || "cmd_zdr_no_providers"}).`, code, { status: 422 });
|
|
20428
|
+
throw new LlmError$1(`${PROVIDER_NAME$11} validation error (422): ${detail || "Unprocessable Entity"}`, code, { status: 422 });
|
|
20199
20429
|
}
|
|
20200
|
-
if (isCommandCodeModelAccessDenied(status, detail)) throw new LlmError(`${PROVIDER_NAME$11} access denied for model ${options.model}: this model is not included in the plan or requires higher entitlement (${status}).${detail ? ` ${detail}` : ""}`, code, { status });
|
|
20201
|
-
if (isCommandCodeCredentialInvalid(status, detail) || status === 401) throw new LlmError(`${PROVIDER_NAME$11} rejected the stored API key (${status}). Sign in again from Settings > Command Code.${detail ? ` ${detail}` : ""}`, code, { status });
|
|
20430
|
+
if (isCommandCodeModelAccessDenied(status, detail)) throw new LlmError$1(`${PROVIDER_NAME$11} access denied for model ${options.model}: this model is not included in the plan or requires higher entitlement (${status}).${detail ? ` ${detail}` : ""}`, code, { status });
|
|
20431
|
+
if (isCommandCodeCredentialInvalid(status, detail) || status === 401) throw new LlmError$1(`${PROVIDER_NAME$11} rejected the stored API key (${status}). Sign in again from Settings > Command Code.${detail ? ` ${detail}` : ""}`, code, { status });
|
|
20202
20432
|
if (status === 429) {
|
|
20203
20433
|
const after = response === void 0 ? void 0 : retryAfterMs$1(response.headers);
|
|
20204
|
-
throw new LlmError(`${PROVIDER_NAME$11} rate limit or plan quota reached (429). Check the quota card in Settings > Command Code.${detail ? ` ${detail}` : ""}`, code, {
|
|
20434
|
+
throw new LlmError$1(`${PROVIDER_NAME$11} rate limit or plan quota reached (429). Check the quota card in Settings > Command Code.${detail ? ` ${detail}` : ""}`, code, {
|
|
20205
20435
|
status: 429,
|
|
20206
20436
|
...after === void 0 ? {} : { providerRetryAfterMs: after }
|
|
20207
20437
|
});
|
|
20208
20438
|
}
|
|
20209
|
-
if (status >= 500) throw new LlmError(`${PROVIDER_NAME$11} upstream server error (${status}): ${detail || "No response"}`, code, { status });
|
|
20210
|
-
throw new LlmError(`${PROVIDER_NAME$11} API error (${status}): ${detail || "No response"}`, code, { status });
|
|
20439
|
+
if (status >= 500) throw new LlmError$1(`${PROVIDER_NAME$11} upstream server error (${status}): ${detail || "No response"}`, code, { status });
|
|
20440
|
+
throw new LlmError$1(`${PROVIDER_NAME$11} API error (${status}): ${detail || "No response"}`, code, { status });
|
|
20211
20441
|
}
|
|
20212
|
-
if (response.body === null) throw new LlmError("Command Code returned an empty response body", "PROVIDER_ERROR");
|
|
20442
|
+
if (response.body === null) throw new LlmError$1("Command Code returned an empty response body", "PROVIDER_ERROR");
|
|
20213
20443
|
const reader = response.body.getReader();
|
|
20214
20444
|
const decoder = new TextDecoder();
|
|
20215
20445
|
const state = createStreamState$7(wire);
|
|
@@ -20255,7 +20485,7 @@ var CommandCodeAdapter = class extends LlmAdapter {
|
|
|
20255
20485
|
}
|
|
20256
20486
|
} catch (error) {
|
|
20257
20487
|
const inBand = state.streamError;
|
|
20258
|
-
if (error instanceof LlmError && !outputStarted && inBand !== void 0 && error.code === "PROVIDER_ERROR") {
|
|
20488
|
+
if (error instanceof LlmError$1 && !outputStarted && inBand !== void 0 && error.code === "PROVIDER_ERROR") {
|
|
20259
20489
|
const reclassified = reclassifyInBandStreamError(error, inBand);
|
|
20260
20490
|
if (reclassified.code === "RATE_LIMIT" && pool !== null && accountId !== void 0) {
|
|
20261
20491
|
const after = retryAfterMs$1(response.headers);
|
|
@@ -20277,10 +20507,10 @@ var CommandCodeAdapter = class extends LlmAdapter {
|
|
|
20277
20507
|
* body-read failure as TRANSPORT and retain its cause chain in the message.
|
|
20278
20508
|
*/
|
|
20279
20509
|
function streamFailure$1(error, signal) {
|
|
20280
|
-
if (error instanceof LlmError) return error;
|
|
20281
|
-
if (signal.aborted) return new LlmError("Command Code stream aborted", "ABORTED", { cause: error });
|
|
20510
|
+
if (error instanceof LlmError$1) return error;
|
|
20511
|
+
if (signal.aborted) return new LlmError$1("Command Code stream aborted", "ABORTED", { cause: error });
|
|
20282
20512
|
const chain = errorChain(error).trim();
|
|
20283
|
-
return new LlmError(`Command Code stream failed: ${chain === "" ? "the response stream ended unexpectedly" : chain.slice(0, 500)}`, "TRANSPORT", { cause: error });
|
|
20513
|
+
return new LlmError$1(`Command Code stream failed: ${chain === "" ? "the response stream ended unexpectedly" : chain.slice(0, 500)}`, "TRANSPORT", { cause: error });
|
|
20284
20514
|
}
|
|
20285
20515
|
/**
|
|
20286
20516
|
* The error one recorded in-band failure becomes, or the mapper's own verdict.
|
|
@@ -22787,7 +23017,7 @@ var OllamaAdapter = class extends LlmAdapter {
|
|
|
22787
23017
|
}));
|
|
22788
23018
|
}
|
|
22789
23019
|
async resolveModel(provider, modelId, signal) {
|
|
22790
|
-
if (signal?.aborted) throw new LlmError("Ollama model resolution aborted", "ABORTED");
|
|
23020
|
+
if (signal?.aborted) throw new LlmError$1("Ollama model resolution aborted", "ABORTED");
|
|
22791
23021
|
const settings = await this.settings();
|
|
22792
23022
|
const entry = (await this.catalog()).find((model) => model.id === modelId);
|
|
22793
23023
|
const declared = signal?.aborted ? void 0 : await this.thinkingCapability(modelId);
|
|
@@ -22855,7 +23085,7 @@ var OllamaAdapter = class extends LlmAdapter {
|
|
|
22855
23085
|
let credentials;
|
|
22856
23086
|
if (pool === null) {
|
|
22857
23087
|
const stored = await this.store.read();
|
|
22858
|
-
if (stored === null) throw new LlmError(`No ${PROVIDER_NAME$10} API key configured. Add one from Settings > ${PROVIDER_NAME$10} (create a key at https://ollama.com/settings/keys).`, "MISSING_CREDENTIAL");
|
|
23088
|
+
if (stored === null) throw new LlmError$1(`No ${PROVIDER_NAME$10} API key configured. Add one from Settings > ${PROVIDER_NAME$10} (create a key at https://ollama.com/settings/keys).`, "MISSING_CREDENTIAL");
|
|
22859
23089
|
credentials = stored;
|
|
22860
23090
|
} else {
|
|
22861
23091
|
const effective = await pool.getEffectiveCredential(tried, fetchFn);
|
|
@@ -22916,9 +23146,9 @@ var OllamaAdapter = class extends LlmAdapter {
|
|
|
22916
23146
|
break;
|
|
22917
23147
|
}
|
|
22918
23148
|
const status = lastStatus;
|
|
22919
|
-
if (status === 401 || status === 403) throw new LlmError(`${PROVIDER_NAME$10} rejected the API key (${status}). Replace it from Settings > ${PROVIDER_NAME$10}.${lastDetail ? ` ${lastDetail}` : ""}`, "INVALID_CREDENTIAL", { status });
|
|
22920
|
-
if (status === 429) throw new LlmError(`${PROVIDER_NAME$10} rate limit or plan quota reached (429). Add another key, or wait for the cooldown shown in Settings > ${PROVIDER_NAME$10}.${lastDetail ? ` ${lastDetail}` : ""}`, "RATE_LIMIT", { status: 429 });
|
|
22921
|
-
throw new LlmError(`${PROVIDER_NAME$10} request failed${status === void 0 ? "" : ` (${status})`}.${lastDetail}`, lastInBandCode ?? (status !== void 0 && status >= 500 ? "SERVER" : "INVALID_REQUEST"), status === void 0 ? {} : { status });
|
|
23149
|
+
if (status === 401 || status === 403) throw new LlmError$1(`${PROVIDER_NAME$10} rejected the API key (${status}). Replace it from Settings > ${PROVIDER_NAME$10}.${lastDetail ? ` ${lastDetail}` : ""}`, "INVALID_CREDENTIAL", { status });
|
|
23150
|
+
if (status === 429) throw new LlmError$1(`${PROVIDER_NAME$10} rate limit or plan quota reached (429). Add another key, or wait for the cooldown shown in Settings > ${PROVIDER_NAME$10}.${lastDetail ? ` ${lastDetail}` : ""}`, "RATE_LIMIT", { status: 429 });
|
|
23151
|
+
throw new LlmError$1(`${PROVIDER_NAME$10} request failed${status === void 0 ? "" : ` (${status})`}.${lastDetail}`, lastInBandCode ?? (status !== void 0 && status >= 500 ? "SERVER" : "INVALID_REQUEST"), status === void 0 ? {} : { status });
|
|
22922
23152
|
}
|
|
22923
23153
|
};
|
|
22924
23154
|
/**
|
|
@@ -25051,7 +25281,7 @@ const ACP_ERROR_CODES = {
|
|
|
25051
25281
|
*/
|
|
25052
25282
|
function acpError(code, detail) {
|
|
25053
25283
|
const base = ACP_ERROR_CODES[code];
|
|
25054
|
-
return new LlmError(detail === void 0 ? base : `${base} ${detail}`, code);
|
|
25284
|
+
return new LlmError$1(detail === void 0 ? base : `${base} ${detail}`, code);
|
|
25055
25285
|
}
|
|
25056
25286
|
//#endregion
|
|
25057
25287
|
//#region src/host/antigravity-acp/history.ts
|
|
@@ -25068,9 +25298,10 @@ function acpError(code, detail) {
|
|
|
25068
25298
|
* that history is the only transcript the model may rely on.
|
|
25069
25299
|
* - **An existing ACP session** is fed only the messages DSH added since the
|
|
25070
25300
|
* last prompt, because the agent already has the rest.
|
|
25071
|
-
* - A mismatch (compaction, an edited turn, a
|
|
25301
|
+
* - A mismatch (compaction, an edited turn, a rewritten prefix) means the ACP
|
|
25072
25302
|
* transcript can no longer be trusted as a prefix of DSH's: the session is
|
|
25073
|
-
* abandoned and replayed in full.
|
|
25303
|
+
* abandoned and replayed in full, behind a history boundary marker. A different
|
|
25304
|
+
* model is not a mismatch - it is a config option of the same conversation.
|
|
25074
25305
|
*
|
|
25075
25306
|
* The fingerprint is an HMAC-style digest rather than a stored transcript: it
|
|
25076
25307
|
* costs one hash per message and never keeps a second copy of user content.
|
|
@@ -25080,6 +25311,28 @@ function acpError(code, detail) {
|
|
|
25080
25311
|
/** ACP's own image ceiling per content block. */
|
|
25081
25312
|
const ACP_MAX_INLINE_IMAGE_BYTES = 12 * 1024 * 1024;
|
|
25082
25313
|
/**
|
|
25314
|
+
* The sentence every replayed transcript ends with.
|
|
25315
|
+
*
|
|
25316
|
+
* ACP has no notion of "this is the current task". A session created now and fed
|
|
25317
|
+
* a hundred messages is one long prompt, and a transcript that reads like a stack
|
|
25318
|
+
* of outstanding requests is exactly how a long session ends up redoing its first
|
|
25319
|
+
* request: the user writes "go with A" and the agent, reading a wall of earlier
|
|
25320
|
+
* instructions, starts over on the first one. The anchor marks where the history
|
|
25321
|
+
* ends and which line the turn is about.
|
|
25322
|
+
*
|
|
25323
|
+
* It is appended to a *replay* only. A fresh session's first prompt already ends
|
|
25324
|
+
* with the request it is answering, and a boundary sentence there would be noise
|
|
25325
|
+
* on every cold start.
|
|
25326
|
+
*/
|
|
25327
|
+
const REPLAY_ANCHOR_INSTRUCTION = [
|
|
25328
|
+
"[history boundary]",
|
|
25329
|
+
"Everything above this line is earlier conversation, replayed to you for context only.",
|
|
25330
|
+
"The current request is the LAST user message in that history.",
|
|
25331
|
+
"Do not re-run, re-answer or re-dispatch work an earlier message already asked for; completed requests are completed.",
|
|
25332
|
+
"A short reference such as \"do that\" or \"go with A\" points at the assistant message immediately before it.",
|
|
25333
|
+
"Model names, providers and routing mentioned in older turns describe the turn they ran on, not the one you are answering now."
|
|
25334
|
+
].join(" ");
|
|
25335
|
+
/**
|
|
25083
25336
|
* Build the prompt for one generation.
|
|
25084
25337
|
*
|
|
25085
25338
|
* @param options - Normalized request options.
|
|
@@ -25100,6 +25353,10 @@ function buildPrompt(options, images, fromMessage) {
|
|
|
25100
25353
|
return inlineBytes <= ACP_MAX_INLINE_IMAGE_BYTES;
|
|
25101
25354
|
});
|
|
25102
25355
|
}
|
|
25356
|
+
if (start === 0 && messages.some((message) => message.role === "assistant")) blocks.push({
|
|
25357
|
+
type: "text",
|
|
25358
|
+
text: REPLAY_ANCHOR_INSTRUCTION
|
|
25359
|
+
});
|
|
25103
25360
|
return {
|
|
25104
25361
|
blocks,
|
|
25105
25362
|
coveredMessages: messages.length,
|
|
@@ -25132,6 +25389,35 @@ function fingerprintMessages(messages, from, to) {
|
|
|
25132
25389
|
return hash.digest("hex");
|
|
25133
25390
|
}
|
|
25134
25391
|
/**
|
|
25392
|
+
* Digest over the tool catalogue an ACP session's bridge exposes.
|
|
25393
|
+
*
|
|
25394
|
+
* The catalogue is fixed when the session is created: the agent listed it once,
|
|
25395
|
+
* and the bridge answers `listChanged: false`, so a session resumed after the
|
|
25396
|
+
* harness's tool set changed would keep offering the old schemas to the agent. The
|
|
25397
|
+
* digest is therefore part of "may this session be reused", and a changed
|
|
25398
|
+
* catalogue forces a fresh session.
|
|
25399
|
+
*
|
|
25400
|
+
* @param tools - The tool schemas of one request.
|
|
25401
|
+
* @returns Hex digest; one catalogue always produces one value.
|
|
25402
|
+
*/
|
|
25403
|
+
function fingerprintTools(tools) {
|
|
25404
|
+
const hash = createHash("sha256");
|
|
25405
|
+
const entries = (tools ?? []).map((tool) => ({
|
|
25406
|
+
name: tool.name,
|
|
25407
|
+
description: tool.description ?? "",
|
|
25408
|
+
parameters: JSON.stringify(tool.parameters ?? {})
|
|
25409
|
+
})).sort((left, right) => left.name === right.name ? 0 : left.name < right.name ? -1 : 1);
|
|
25410
|
+
for (const entry of entries) {
|
|
25411
|
+
hash.update(entry.name);
|
|
25412
|
+
hash.update("\0");
|
|
25413
|
+
hash.update(entry.description);
|
|
25414
|
+
hash.update("\0");
|
|
25415
|
+
hash.update(entry.parameters);
|
|
25416
|
+
hash.update("");
|
|
25417
|
+
}
|
|
25418
|
+
return hash.digest("hex");
|
|
25419
|
+
}
|
|
25420
|
+
/**
|
|
25135
25421
|
* Whether `messages` still begins with everything a live ACP session has seen.
|
|
25136
25422
|
*
|
|
25137
25423
|
* @param messages - The history about to be sent.
|
|
@@ -25372,12 +25658,22 @@ function missingBinaryMessage(detail) {
|
|
|
25372
25658
|
* This class therefore keeps a *live turn* per DSH session: the ACP session, the
|
|
25373
25659
|
* bridge, and how much history that turn has already been told about.
|
|
25374
25660
|
*
|
|
25375
|
-
*
|
|
25376
|
-
*
|
|
25377
|
-
*
|
|
25378
|
-
*
|
|
25379
|
-
*
|
|
25380
|
-
*
|
|
25661
|
+
* A turn that ends without a tool round does not lose its ACP session: it is
|
|
25662
|
+
* parked *dormant* together with the process it runs on, and the next user
|
|
25663
|
+
* message on the same DSH session is sent as an increment on that same
|
|
25664
|
+
* conversation. That is worth more than the prefill it saves. A session created
|
|
25665
|
+
* per message hands a thinking model a hundred-message transcript and hopes it
|
|
25666
|
+
* picks out the newest line; the observed failure was a model re-running the
|
|
25667
|
+
* conversation's *first* request when the user wrote "go with option A".
|
|
25668
|
+
*
|
|
25669
|
+
* Reuse is never assumed. The prefix the agent was told about must still match
|
|
25670
|
+
* the harness's history (the history module's fingerprint), the tool catalogue
|
|
25671
|
+
* the bridge exposed must be unchanged, and a different model or effort is
|
|
25672
|
+
* applied with `session/set_config_option` on the same conversation. A
|
|
25673
|
+
* compaction, an edited turn, a new tool set, a dead process, or a refused
|
|
25674
|
+
* reconfiguration all fall back to a fresh session fed the complete history - and
|
|
25675
|
+
* that replay ends with a history boundary marker, so it is read as a transcript
|
|
25676
|
+
* rather than as a task list.
|
|
25381
25677
|
*
|
|
25382
25678
|
* Where the tool calls come from
|
|
25383
25679
|
* ------------------------------
|
|
@@ -25457,6 +25753,8 @@ var UpdateQueue = class {
|
|
|
25457
25753
|
var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
25458
25754
|
options;
|
|
25459
25755
|
live = /* @__PURE__ */ new Map();
|
|
25756
|
+
/** Finished sessions, keyed by DSH session, waiting for the next user message. */
|
|
25757
|
+
dormant = /* @__PURE__ */ new Map();
|
|
25460
25758
|
idle = [];
|
|
25461
25759
|
activeTurns = 0;
|
|
25462
25760
|
lastUsage;
|
|
@@ -25509,12 +25807,20 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
25509
25807
|
}
|
|
25510
25808
|
/** Close every process this adapter owns. */
|
|
25511
25809
|
async dispose() {
|
|
25810
|
+
for (const entry of [...this.dormant.values()]) await this.closeDormant(entry);
|
|
25811
|
+
for (const turn of [...this.live.values()]) {
|
|
25812
|
+
if (this.live.get(turn.dshSessionId) === turn) this.live.delete(turn.dshSessionId);
|
|
25813
|
+
this.activeTurns = Math.max(0, this.activeTurns - 1);
|
|
25814
|
+
turn.queue.close();
|
|
25815
|
+
this.cancelTurn(turn);
|
|
25816
|
+
await turn.bridge.close().catch(() => void 0);
|
|
25817
|
+
await turn.client.dispose().catch(() => void 0);
|
|
25818
|
+
}
|
|
25819
|
+
this.live.clear();
|
|
25512
25820
|
for (const entry of this.idle.splice(0)) {
|
|
25513
25821
|
clearTimeout(entry.timer);
|
|
25514
25822
|
await entry.client.dispose().catch(() => void 0);
|
|
25515
25823
|
}
|
|
25516
|
-
for (const turn of [...this.live.values()]) await this.closeTurn(turn);
|
|
25517
|
-
this.live.clear();
|
|
25518
25824
|
}
|
|
25519
25825
|
/**
|
|
25520
25826
|
* Resolve which turn this generation belongs to, then hand back its stream.
|
|
@@ -25536,10 +25842,16 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
25536
25842
|
const live = this.live.get(dshSessionId);
|
|
25537
25843
|
if (live !== void 0 && live.model === options.model && live.effort === effort && canContinue(options.messages, live.covered, live.fingerprint)) return this.continueTurn(live, options, images, signal, activity);
|
|
25538
25844
|
if (live !== void 0) await this.closeTurn(live);
|
|
25539
|
-
|
|
25845
|
+
const auxiliary = options.purpose !== void 0;
|
|
25846
|
+
const dormant = auxiliary ? void 0 : this.dormant.get(dshSessionId);
|
|
25847
|
+
if (dormant !== void 0) if (this.usableDormant(dormant, options)) {
|
|
25848
|
+
const resumed = await this.resumeDormant(dormant, options, settings, effort, images, signal, activity);
|
|
25849
|
+
if (resumed !== void 0) return resumed;
|
|
25850
|
+
} else await this.closeDormant(dormant);
|
|
25851
|
+
return this.startTurn(dshSessionId, options, settings, images, effort, signal, activity, !auxiliary);
|
|
25540
25852
|
}
|
|
25541
25853
|
/** Start a fresh ACP session for one generation and stream its answer. */
|
|
25542
|
-
async startTurn(dshSessionId, options, settings, images, effort, signal, activity) {
|
|
25854
|
+
async startTurn(dshSessionId, options, settings, images, effort, signal, activity, parkable) {
|
|
25543
25855
|
const limit = this.options.maxActiveTurns ?? 4;
|
|
25544
25856
|
if (this.activeTurns >= limit) throw new LlmError(`${PROVIDER_NAME$9} already has ${this.activeTurns} turns in flight; wait for one to finish before starting another.`, "RATE_LIMIT");
|
|
25545
25857
|
this.activeTurns += 1;
|
|
@@ -25579,7 +25891,9 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
25579
25891
|
nativeToolPolicy: settings.nativeToolPolicy,
|
|
25580
25892
|
startedAt: this.now(),
|
|
25581
25893
|
awaitingHarness: false,
|
|
25582
|
-
sessionsUsed: reusedSessions + 1
|
|
25894
|
+
sessionsUsed: reusedSessions + 1,
|
|
25895
|
+
tools: fingerprintTools(options.tools),
|
|
25896
|
+
parkable
|
|
25583
25897
|
};
|
|
25584
25898
|
this.live.set(dshSessionId, turn);
|
|
25585
25899
|
this.sendPrompt(turn, prompt.blocks);
|
|
@@ -25804,13 +26118,12 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
25804
26118
|
]);
|
|
25805
26119
|
}
|
|
25806
26120
|
} finally {
|
|
25807
|
-
if (!finished)
|
|
25808
|
-
|
|
25809
|
-
await this.closeTurn(turn);
|
|
25810
|
-
} else if (!turn.awaitingHarness && this.live.get(turn.dshSessionId) === turn) {
|
|
26121
|
+
if (!finished) await this.closeTurn(turn);
|
|
26122
|
+
else if (!turn.awaitingHarness && this.live.get(turn.dshSessionId) === turn) {
|
|
25811
26123
|
this.live.delete(turn.dshSessionId);
|
|
25812
26124
|
this.activeTurns = Math.max(0, this.activeTurns - 1);
|
|
25813
|
-
await this.
|
|
26125
|
+
if (turn.parkable) await this.park(turn);
|
|
26126
|
+
else await this.release(turn);
|
|
25814
26127
|
}
|
|
25815
26128
|
}
|
|
25816
26129
|
}
|
|
@@ -25966,12 +26279,164 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
25966
26279
|
turn.queue.push({ sessionUpdate: "prompt_settled" });
|
|
25967
26280
|
}
|
|
25968
26281
|
}
|
|
26282
|
+
/**
|
|
26283
|
+
* Abandon one live turn.
|
|
26284
|
+
*
|
|
26285
|
+
* The turn cannot be resumed by the harness any more, so its prompt is cancelled
|
|
26286
|
+
* and its process is handed back to the pool. Disposing the process instead -
|
|
26287
|
+
* what this used to do - made every cancellation pay a fresh spawn and the
|
|
26288
|
+
* agent's own start-up wait on the next message.
|
|
26289
|
+
*/
|
|
25969
26290
|
async closeTurn(turn) {
|
|
25970
26291
|
if (this.live.get(turn.dshSessionId) === turn) this.live.delete(turn.dshSessionId);
|
|
25971
26292
|
this.activeTurns = Math.max(0, this.activeTurns - 1);
|
|
25972
26293
|
turn.queue.close();
|
|
25973
|
-
|
|
25974
|
-
await
|
|
26294
|
+
this.cancelTurn(turn);
|
|
26295
|
+
await this.release(turn);
|
|
26296
|
+
}
|
|
26297
|
+
/**
|
|
26298
|
+
* Ask the agent to stop the prompt this turn left running.
|
|
26299
|
+
*
|
|
26300
|
+
* `session/cancel` is an ACP notification, not a request, so it is written
|
|
26301
|
+
* without waiting for an answer: a prompt that already settled ignores it, and a
|
|
26302
|
+
* client that waited would hang on a server that never replies.
|
|
26303
|
+
*/
|
|
26304
|
+
cancelTurn(turn) {
|
|
26305
|
+
if (!turn.client.alive) return;
|
|
26306
|
+
turn.client.notify("session/cancel", { sessionId: turn.acpSessionId });
|
|
26307
|
+
}
|
|
26308
|
+
/**
|
|
26309
|
+
* Whether the parked session is still a prefix of the history about to be sent.
|
|
26310
|
+
*
|
|
26311
|
+
* Three questions, and every one of them must answer yes: the process is alive,
|
|
26312
|
+
* the bridge still exposes the tool catalogue the agent listed (the bridge
|
|
26313
|
+
* publishes no change feed, so a different set cannot reach a resumed session),
|
|
26314
|
+
* and the harness history still begins with exactly what the agent was told.
|
|
26315
|
+
*
|
|
26316
|
+
* @param entry - The parked session.
|
|
26317
|
+
* @param options - The generation about to run.
|
|
26318
|
+
*/
|
|
26319
|
+
usableDormant(entry, options) {
|
|
26320
|
+
if (!entry.client.alive) return false;
|
|
26321
|
+
if (entry.tools !== fingerprintTools(options.tools)) return false;
|
|
26322
|
+
return canContinue(options.messages, entry.covered, entry.fingerprint);
|
|
26323
|
+
}
|
|
26324
|
+
/**
|
|
26325
|
+
* Continue a parked session with only what the harness added since.
|
|
26326
|
+
*
|
|
26327
|
+
* @param entry - The parked session to reuse.
|
|
26328
|
+
* @param options - The generation about to run.
|
|
26329
|
+
* @param settings - This line's own preferences, read for the native-tool policy.
|
|
26330
|
+
* @param effort - The thinking level this generation asked for.
|
|
26331
|
+
* @param images - Images resolved for this request.
|
|
26332
|
+
* @param signal - Caller cancellation.
|
|
26333
|
+
* @param activity - Watchdog pulse.
|
|
26334
|
+
* @returns the stream, or undefined when the session could not be reused. On
|
|
26335
|
+
* that path the process has already been handed back, so the caller starts a
|
|
26336
|
+
* cold turn rather than failing the generation.
|
|
26337
|
+
*/
|
|
26338
|
+
async resumeDormant(entry, options, settings, effort, images, signal, activity) {
|
|
26339
|
+
const limit = this.options.maxActiveTurns ?? 4;
|
|
26340
|
+
if (this.activeTurns >= limit) return void 0;
|
|
26341
|
+
this.dormant.delete(entry.dshSessionId);
|
|
26342
|
+
if (entry.timer !== void 0) clearTimeout(entry.timer);
|
|
26343
|
+
const queue = new UpdateQueue();
|
|
26344
|
+
try {
|
|
26345
|
+
if (entry.model !== options.model || entry.effort !== effort) await this.applyModelAndEffort(entry.client, entry.acpSessionId, options.model, effort);
|
|
26346
|
+
this.attachHandlers(entry.client, queue, activity);
|
|
26347
|
+
const prompt = buildPrompt(options, images, entry.covered);
|
|
26348
|
+
const turn = {
|
|
26349
|
+
dshSessionId: entry.dshSessionId,
|
|
26350
|
+
client: entry.client,
|
|
26351
|
+
bridge: entry.bridge,
|
|
26352
|
+
acpSessionId: entry.acpSessionId,
|
|
26353
|
+
covered: prompt.coveredMessages,
|
|
26354
|
+
fingerprint: prompt.fingerprint,
|
|
26355
|
+
model: options.model,
|
|
26356
|
+
effort,
|
|
26357
|
+
queue,
|
|
26358
|
+
settled: void 0,
|
|
26359
|
+
surfaced: /* @__PURE__ */ new Set(),
|
|
26360
|
+
notedNative: /* @__PURE__ */ new Set(),
|
|
26361
|
+
nativeToolPolicy: settings.nativeToolPolicy,
|
|
26362
|
+
startedAt: this.now(),
|
|
26363
|
+
awaitingHarness: false,
|
|
26364
|
+
sessionsUsed: entry.sessionsUsed,
|
|
26365
|
+
tools: entry.tools,
|
|
26366
|
+
parkable: true
|
|
26367
|
+
};
|
|
26368
|
+
this.live.set(turn.dshSessionId, turn);
|
|
26369
|
+
this.activeTurns += 1;
|
|
26370
|
+
this.sendPrompt(turn, prompt.blocks);
|
|
26371
|
+
return this.pump(turn, signal, activity);
|
|
26372
|
+
} catch {
|
|
26373
|
+
queue.close();
|
|
26374
|
+
await this.release({
|
|
26375
|
+
client: entry.client,
|
|
26376
|
+
bridge: entry.bridge,
|
|
26377
|
+
sessionsUsed: entry.sessionsUsed
|
|
26378
|
+
});
|
|
26379
|
+
return;
|
|
26380
|
+
}
|
|
26381
|
+
}
|
|
26382
|
+
/**
|
|
26383
|
+
* Keep a finished turn's session ready for the next user message.
|
|
26384
|
+
*
|
|
26385
|
+
* The bridge stays open on purpose: its endpoint is what the parked session's
|
|
26386
|
+
* tool list points at, and closing it would leave the agent calling a port
|
|
26387
|
+
* nobody answers.
|
|
26388
|
+
*/
|
|
26389
|
+
async park(turn) {
|
|
26390
|
+
turn.queue.close();
|
|
26391
|
+
const limit = this.options.dormantSessionLimit ?? 2;
|
|
26392
|
+
if (limit <= 0 || !turn.client.alive) {
|
|
26393
|
+
await this.release(turn);
|
|
26394
|
+
return;
|
|
26395
|
+
}
|
|
26396
|
+
const previous = this.dormant.get(turn.dshSessionId);
|
|
26397
|
+
if (previous !== void 0) await this.closeDormant(previous);
|
|
26398
|
+
const entry = {
|
|
26399
|
+
dshSessionId: turn.dshSessionId,
|
|
26400
|
+
client: turn.client,
|
|
26401
|
+
bridge: turn.bridge,
|
|
26402
|
+
acpSessionId: turn.acpSessionId,
|
|
26403
|
+
covered: turn.covered,
|
|
26404
|
+
fingerprint: turn.fingerprint,
|
|
26405
|
+
tools: turn.tools,
|
|
26406
|
+
model: turn.model,
|
|
26407
|
+
effort: turn.effort,
|
|
26408
|
+
sessionsUsed: turn.sessionsUsed,
|
|
26409
|
+
timer: void 0
|
|
26410
|
+
};
|
|
26411
|
+
const timer = setTimeout(() => {
|
|
26412
|
+
this.closeDormant(entry);
|
|
26413
|
+
}, this.options.dormantSessionTimeoutMs ?? 3e5);
|
|
26414
|
+
timer.unref?.();
|
|
26415
|
+
entry.timer = timer;
|
|
26416
|
+
this.dormant.set(turn.dshSessionId, entry);
|
|
26417
|
+
while (this.dormant.size > limit) {
|
|
26418
|
+
const oldest = this.dormant.values().next().value;
|
|
26419
|
+
if (oldest === void 0) break;
|
|
26420
|
+
await this.closeDormant(oldest);
|
|
26421
|
+
}
|
|
26422
|
+
}
|
|
26423
|
+
/**
|
|
26424
|
+
* Drop a parked session and hand its process back to the pool.
|
|
26425
|
+
*
|
|
26426
|
+
* The conversation itself is abandoned rather than closed with `session/close`:
|
|
26427
|
+
* not every agent version this line supports answers that request, and a request
|
|
26428
|
+
* that never settles would occupy one of the client's protocol slots for the
|
|
26429
|
+
* life of the process. The next turn opens a fresh conversation on the same warm
|
|
26430
|
+
* process.
|
|
26431
|
+
*/
|
|
26432
|
+
async closeDormant(entry) {
|
|
26433
|
+
if (this.dormant.get(entry.dshSessionId) === entry) this.dormant.delete(entry.dshSessionId);
|
|
26434
|
+
if (entry.timer !== void 0) clearTimeout(entry.timer);
|
|
26435
|
+
await this.release({
|
|
26436
|
+
client: entry.client,
|
|
26437
|
+
bridge: entry.bridge,
|
|
26438
|
+
sessionsUsed: entry.sessionsUsed
|
|
26439
|
+
});
|
|
25975
26440
|
}
|
|
25976
26441
|
/**
|
|
25977
26442
|
* Take one warm process out of the pool.
|
|
@@ -26018,12 +26483,14 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
26018
26483
|
onActivity: () => activity.pulse()
|
|
26019
26484
|
});
|
|
26020
26485
|
}
|
|
26486
|
+
/** Hand one turn's process back to the idle pool, disposing it when it is spent. */
|
|
26021
26487
|
async release(turn) {
|
|
26022
|
-
turn.queue
|
|
26488
|
+
turn.queue?.close();
|
|
26023
26489
|
await turn.bridge.close().catch(() => void 0);
|
|
26024
26490
|
const limit = this.options.idleProcessLimit ?? 2;
|
|
26025
26491
|
const cap = this.options.maxSessionsPerProcess ?? 100;
|
|
26026
|
-
|
|
26492
|
+
const sessionsUsed = turn.sessionsUsed ?? 1;
|
|
26493
|
+
if (limit <= 0 || !turn.client.alive || sessionsUsed >= cap) {
|
|
26027
26494
|
await turn.client.dispose().catch(() => void 0);
|
|
26028
26495
|
return;
|
|
26029
26496
|
}
|
|
@@ -26037,7 +26504,7 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
26037
26504
|
this.idle.push({
|
|
26038
26505
|
client,
|
|
26039
26506
|
timer,
|
|
26040
|
-
sessions:
|
|
26507
|
+
sessions: sessionsUsed
|
|
26041
26508
|
});
|
|
26042
26509
|
while (this.idle.length > limit) {
|
|
26043
26510
|
const oldest = this.idle.shift();
|
|
@@ -26497,7 +26964,7 @@ var AcpCatalog = class {
|
|
|
26497
26964
|
*/
|
|
26498
26965
|
async read(options = {}) {
|
|
26499
26966
|
const current = this.cached ?? await this.rehydrate();
|
|
26500
|
-
if (!options.force && current !== void 0 && this.now() - current.fetchedAt <
|
|
26967
|
+
if (!options.force && current !== void 0 && this.now() - current.fetchedAt < 9e5) return current;
|
|
26501
26968
|
if (this.inflight !== void 0) return this.inflight;
|
|
26502
26969
|
this.inflight = this.refresh(options.signal).catch(() => current).finally(() => {
|
|
26503
26970
|
this.inflight = void 0;
|
|
@@ -27955,7 +28422,25 @@ function countLines(text, escapedMode = usesEscapedNewlines(text)) {
|
|
|
27955
28422
|
return text.endsWith("\n") || escapedMode && text.endsWith("n") && isEscapedNewlineAt(text, text.length - 1) ? lines : lines + 1;
|
|
27956
28423
|
}
|
|
27957
28424
|
/**
|
|
27958
|
-
*
|
|
28425
|
+
* 向上查找某 UTF-8 字节偏移所在逻辑行的行首字节偏移。
|
|
28426
|
+
*
|
|
28427
|
+
* 与 {@link countLines} / {@link pageText} 保持一致:支持真实换行 `\n` 以及
|
|
28428
|
+
* 单行 JSON 里的转义换行 `\n`(前面紧邻奇数个 `\`)。
|
|
28429
|
+
*/
|
|
28430
|
+
function findLineStartByte(buffer, fromByte, escapedMode) {
|
|
28431
|
+
for (let cursor = fromByte - 1; cursor >= 0; cursor -= 1) {
|
|
28432
|
+
const byte = buffer[cursor];
|
|
28433
|
+
if (byte === 10) return cursor + 1;
|
|
28434
|
+
if (escapedMode && byte === 110) {
|
|
28435
|
+
let backslashes = 0;
|
|
28436
|
+
for (let probe = cursor - 1; probe >= 0 && buffer[probe] === 92; probe -= 1) backslashes += 1;
|
|
28437
|
+
if ((backslashes & 1) === 1) return cursor + 1;
|
|
28438
|
+
}
|
|
28439
|
+
}
|
|
28440
|
+
return 0;
|
|
28441
|
+
}
|
|
28442
|
+
/**
|
|
28443
|
+
* 按 UTF-8 字节安全分页(可选按字面量 `query` 定位首个匹配行)。
|
|
27959
28444
|
*
|
|
27960
28445
|
* `offset` 是字节偏移,必须落在字符边界上(上一页的 `nextOffset` 天然满足);
|
|
27961
28446
|
* 每页最多 `limit` 行且不超过 `maxBytes` 字节,任何一页都不会把一个字符切成两半。
|
|
@@ -27963,13 +28448,52 @@ function countLines(text, escapedMode = usesEscapedNewlines(text)) {
|
|
|
27963
28448
|
* 「两次翻页拼起来等于原文」是构造出来的性质,不是巧合。
|
|
27964
28449
|
*/
|
|
27965
28450
|
function pageText(args) {
|
|
27966
|
-
const { sessionId, refId, text, buffer, offset, limit, maxBytes } = args;
|
|
28451
|
+
const { sessionId, refId, text, buffer, offset, limit, maxBytes, query } = args;
|
|
27967
28452
|
const totalBytes = buffer.length;
|
|
27968
28453
|
if (!Number.isInteger(offset) || offset < 0) throw new CacheWarmupStoreError("offset must be a non-negative integer byte offset", "OFFSET_OUT_OF_RANGE");
|
|
27969
28454
|
if (offset > totalBytes) throw new CacheWarmupStoreError(`offset ${offset} is past the ${totalBytes}-byte result`, "OFFSET_OUT_OF_RANGE");
|
|
27970
28455
|
if (offset < totalBytes && (buffer[offset] & 192) === 128) throw new CacheWarmupStoreError("offset is not on a UTF-8 character boundary", "OFFSET_INVALID");
|
|
27971
28456
|
const escapedMode = usesEscapedNewlines(text);
|
|
27972
|
-
|
|
28457
|
+
let sliceOffset = offset;
|
|
28458
|
+
let matchMeta;
|
|
28459
|
+
if (query !== void 0) {
|
|
28460
|
+
const queryBytes = Buffer.from(query, "utf8");
|
|
28461
|
+
const hitByteOffset = offset === totalBytes ? -1 : buffer.indexOf(queryBytes, offset);
|
|
28462
|
+
if (hitByteOffset < 0) return {
|
|
28463
|
+
sessionId,
|
|
28464
|
+
refId,
|
|
28465
|
+
mode: "text",
|
|
28466
|
+
content: "",
|
|
28467
|
+
offset,
|
|
28468
|
+
nextOffset: null,
|
|
28469
|
+
complete: true,
|
|
28470
|
+
matched: false,
|
|
28471
|
+
omitted: {
|
|
28472
|
+
reason: "none",
|
|
28473
|
+
chars: 0,
|
|
28474
|
+
lines: 0,
|
|
28475
|
+
rows: 0,
|
|
28476
|
+
bytes: 0
|
|
28477
|
+
},
|
|
28478
|
+
totalChars: text.length,
|
|
28479
|
+
totalBytes,
|
|
28480
|
+
limit,
|
|
28481
|
+
maxBytes
|
|
28482
|
+
};
|
|
28483
|
+
const lineStartByte = findLineStartByte(buffer, hitByteOffset, escapedMode);
|
|
28484
|
+
const maxLeadBytes = maxBytes >= 8 ? Math.min(2048, Math.floor(maxBytes / 4)) : 0;
|
|
28485
|
+
sliceOffset = lineStartByte;
|
|
28486
|
+
if (hitByteOffset - lineStartByte > maxLeadBytes) {
|
|
28487
|
+
let pos = hitByteOffset - maxLeadBytes;
|
|
28488
|
+
while (pos < hitByteOffset && (buffer[pos] & 192) === 128) pos += 1;
|
|
28489
|
+
sliceOffset = pos;
|
|
28490
|
+
}
|
|
28491
|
+
matchMeta = {
|
|
28492
|
+
matched: true,
|
|
28493
|
+
matchOffset: hitByteOffset
|
|
28494
|
+
};
|
|
28495
|
+
}
|
|
28496
|
+
const rest = sliceOffset === 0 ? text : new TextDecoder("utf-8").decode(buffer.subarray(sliceOffset));
|
|
27973
28497
|
let content = "";
|
|
27974
28498
|
let contentBytes = 0;
|
|
27975
28499
|
let lines = 0;
|
|
@@ -27994,7 +28518,8 @@ function pageText(args) {
|
|
|
27994
28518
|
if (char === "\n") lines += 1;
|
|
27995
28519
|
else if (escapedMode && char === "n" && isEscapedNewlineAt(content, content.length - 1)) lines += 1;
|
|
27996
28520
|
}
|
|
27997
|
-
const
|
|
28521
|
+
const consumedBytes = Buffer.byteLength(content, "utf8");
|
|
28522
|
+
const nextOffset = sliceOffset + consumedBytes;
|
|
27998
28523
|
const complete = nextOffset >= totalBytes;
|
|
27999
28524
|
const remaining = rest.slice(content.length);
|
|
28000
28525
|
return {
|
|
@@ -28002,9 +28527,10 @@ function pageText(args) {
|
|
|
28002
28527
|
refId,
|
|
28003
28528
|
mode: "text",
|
|
28004
28529
|
content,
|
|
28005
|
-
offset,
|
|
28530
|
+
offset: sliceOffset,
|
|
28006
28531
|
nextOffset: complete ? null : nextOffset,
|
|
28007
28532
|
complete,
|
|
28533
|
+
...matchMeta ?? {},
|
|
28008
28534
|
omitted: {
|
|
28009
28535
|
reason: complete ? "none" : stoppedByBytes ? "bytes" : stoppedByLines ? "lines" : "bytes",
|
|
28010
28536
|
chars: remaining.length,
|
|
@@ -28226,22 +28752,26 @@ var FileResultReferenceStore = class {
|
|
|
28226
28752
|
if (stats === void 0 || !stats.isFile()) throw new CacheWarmupStoreError("stored result is missing; it was released or evicted", "RESULT_NOT_FOUND");
|
|
28227
28753
|
const ttlMs = this.options.ttlMs;
|
|
28228
28754
|
if (ttlMs !== void 0 && ttlMs > 0 && this.now() - stats.mtimeMs > ttlMs) throw new CacheWarmupStoreError("stored result expired", "RESULT_EXPIRED");
|
|
28755
|
+
if (input.query !== void 0 && (typeof input.query !== "string" || input.query.length === 0)) throw new CacheWarmupStoreError("query must be a non-empty string", "QUERY_INVALID");
|
|
28229
28756
|
const buffer = await fs.readFile(file);
|
|
28230
28757
|
const text = new TextDecoder("utf-8").decode(buffer);
|
|
28231
28758
|
const limit = clampLimit(input.limit);
|
|
28232
28759
|
const maxBytes = clampMaxBytes(input.maxBytes);
|
|
28233
28760
|
const offset = input.offset ?? 0;
|
|
28234
|
-
if (input.fields !== void 0 || input.equals !== void 0)
|
|
28235
|
-
|
|
28236
|
-
|
|
28237
|
-
|
|
28238
|
-
|
|
28239
|
-
|
|
28240
|
-
|
|
28241
|
-
|
|
28242
|
-
|
|
28243
|
-
|
|
28244
|
-
|
|
28761
|
+
if (input.fields !== void 0 || input.equals !== void 0) {
|
|
28762
|
+
if (input.query !== void 0) throw new CacheWarmupStoreError("query applies to text mode only; omit fields and equals when using query", "QUERY_INVALID");
|
|
28763
|
+
return pageStructured({
|
|
28764
|
+
sessionId,
|
|
28765
|
+
refId: input.refId,
|
|
28766
|
+
text,
|
|
28767
|
+
buffer,
|
|
28768
|
+
offset,
|
|
28769
|
+
limit,
|
|
28770
|
+
maxBytes,
|
|
28771
|
+
fields: input.fields,
|
|
28772
|
+
equals: input.equals
|
|
28773
|
+
});
|
|
28774
|
+
}
|
|
28245
28775
|
return pageText({
|
|
28246
28776
|
sessionId,
|
|
28247
28777
|
refId: input.refId,
|
|
@@ -28249,7 +28779,8 @@ var FileResultReferenceStore = class {
|
|
|
28249
28779
|
buffer,
|
|
28250
28780
|
offset,
|
|
28251
28781
|
limit,
|
|
28252
|
-
maxBytes
|
|
28782
|
+
maxBytes,
|
|
28783
|
+
query: input.query
|
|
28253
28784
|
});
|
|
28254
28785
|
}
|
|
28255
28786
|
/**
|
|
@@ -30280,7 +30811,7 @@ function planProjection(text, toolName, navigation, retrievalOnly, spilled = fal
|
|
|
30280
30811
|
}
|
|
30281
30812
|
/** 预览尾部:把「怎么读全文」写死在预览里,模型不用猜。 */
|
|
30282
30813
|
function footerFor(refId) {
|
|
30283
|
-
return `[full result: ${refId} · page with offset/limit(default 64 lines)/maxBytes(default 16384 bytes)]`;
|
|
30814
|
+
return `[full result: ${refId} · page with query/offset/limit(default 64 lines)/maxBytes(default 16384 bytes)]`;
|
|
30284
30815
|
}
|
|
30285
30816
|
/**
|
|
30286
30817
|
* 核心决策:预算 → 计划 → 装配 → 入库。
|
|
@@ -38407,7 +38938,7 @@ var KimiCodeAdapter = class extends LlmAdapter {
|
|
|
38407
38938
|
(item.kind === "image" ? imageReferences : videoReferences).set(item.attachmentId, reference);
|
|
38408
38939
|
cited.push(item);
|
|
38409
38940
|
} catch (error) {
|
|
38410
|
-
if (input.signal.aborted || isAbortError(error)) throw new LlmError("Kimi Code media upload aborted", "ABORTED", { cause: error });
|
|
38941
|
+
if (input.signal.aborted || isAbortError(error)) throw new LlmError$1("Kimi Code media upload aborted", "ABORTED", { cause: error });
|
|
38411
38942
|
}
|
|
38412
38943
|
}));
|
|
38413
38944
|
return {
|
|
@@ -38563,7 +39094,7 @@ var KimiCodeAdapter = class extends LlmAdapter {
|
|
|
38563
39094
|
}));
|
|
38564
39095
|
}
|
|
38565
39096
|
async resolveModel(provider, modelId, signal) {
|
|
38566
|
-
if (signal?.aborted) throw new LlmError("Kimi Code model resolution aborted", "ABORTED");
|
|
39097
|
+
if (signal?.aborted) throw new LlmError$1("Kimi Code model resolution aborted", "ABORTED");
|
|
38567
39098
|
const settings = await this.settings();
|
|
38568
39099
|
const catalog = await this.catalog();
|
|
38569
39100
|
const entry = catalog.find((model) => model.id === modelId);
|
|
@@ -38848,13 +39379,13 @@ var KimiCodeAdapter = class extends LlmAdapter {
|
|
|
38848
39379
|
activity?.pulse();
|
|
38849
39380
|
return response;
|
|
38850
39381
|
} catch (error) {
|
|
38851
|
-
if (signal.aborted) throw new LlmError("Kimi Code request aborted", "ABORTED", { cause: error });
|
|
38852
|
-
throw new LlmError(`Kimi Code request failed: ${error instanceof Error ? error.message : String(error)}`, "TRANSPORT", { cause: error });
|
|
39382
|
+
if (signal.aborted) throw new LlmError$1("Kimi Code request aborted", "ABORTED", { cause: error });
|
|
39383
|
+
throw new LlmError$1(`Kimi Code request failed: ${error instanceof Error ? error.message : String(error)}`, "TRANSPORT", { cause: error });
|
|
38853
39384
|
}
|
|
38854
39385
|
};
|
|
38855
39386
|
if (sideChannel && sessionKey !== "") {
|
|
38856
39387
|
await prefixRequests.waitForMainSession(sessionKey, signal);
|
|
38857
|
-
if (signal.aborted) throw new LlmError("Kimi Code request aborted", "ABORTED");
|
|
39388
|
+
if (signal.aborted) throw new LlmError$1("Kimi Code request aborted", "ABORTED");
|
|
38858
39389
|
}
|
|
38859
39390
|
const coldGroupKey = sideChannel ? void 0 : coldStartGroupKey(region, requestOptions, accountScope);
|
|
38860
39391
|
const coldGate = coldGroupKey === void 0 ? void 0 : await acquireColdStartWarmup(coldGroupKey, signal);
|
|
@@ -38927,7 +39458,7 @@ var KimiCodeAdapter = class extends LlmAdapter {
|
|
|
38927
39458
|
if (await pool.hasAnotherAvailableAccount(tried)) continue;
|
|
38928
39459
|
}
|
|
38929
39460
|
}
|
|
38930
|
-
throw new LlmError(failure.message, failure.code, {
|
|
39461
|
+
throw new LlmError$1(failure.message, failure.code, {
|
|
38931
39462
|
status: response.status,
|
|
38932
39463
|
...after === void 0 ? {} : { providerRetryAfterMs: after }
|
|
38933
39464
|
});
|
|
@@ -38945,7 +39476,7 @@ var KimiCodeAdapter = class extends LlmAdapter {
|
|
|
38945
39476
|
droppedImages: stickyOffload.droppedCount + bodyFitDroppedKeys.length
|
|
38946
39477
|
}, requestOptions);
|
|
38947
39478
|
}
|
|
38948
|
-
if (response.body === null) throw new LlmError("Kimi Code returned an empty response body", "PROVIDER_ERROR");
|
|
39479
|
+
if (response.body === null) throw new LlmError$1("Kimi Code returned an empty response body", "PROVIDER_ERROR");
|
|
38949
39480
|
const reader = response.body.getReader();
|
|
38950
39481
|
const decoder = new TextDecoder();
|
|
38951
39482
|
const state = createStreamState$5(wire, requestOptions.sessionId, sideChannel);
|
|
@@ -38994,20 +39525,20 @@ var KimiCodeAdapter = class extends LlmAdapter {
|
|
|
38994
39525
|
}
|
|
38995
39526
|
} catch (error) {
|
|
38996
39527
|
const inBand = state.streamError;
|
|
38997
|
-
if (error instanceof LlmError && !outputStarted && error.code === "PROVIDER_ERROR" && inBand !== void 0) throw await this.inBandStreamFailure(error, inBand, servedByAccountId, retrySignal, requestDiagnostic.attempts.at(-1));
|
|
39528
|
+
if (error instanceof LlmError$1 && !outputStarted && error.code === "PROVIDER_ERROR" && inBand !== void 0) throw await this.inBandStreamFailure(error, inBand, servedByAccountId, retrySignal, requestDiagnostic.attempts.at(-1));
|
|
38998
39529
|
throw streamFailure(error, signal);
|
|
38999
39530
|
}
|
|
39000
39531
|
} finally {
|
|
39001
39532
|
reader.cancel().catch(() => void 0);
|
|
39002
39533
|
}
|
|
39003
39534
|
} catch (error) {
|
|
39004
|
-
if (error instanceof LlmError && isKimiToolArgumentGuardCode(error.code)) rememberSameAccountRetry(retrySignal, diagnosticState?.accountId);
|
|
39535
|
+
if (error instanceof LlmError$1 && isKimiToolArgumentGuardCode(error.code)) rememberSameAccountRetry(retrySignal, diagnosticState?.accountId);
|
|
39005
39536
|
requestError = error;
|
|
39006
39537
|
throw error;
|
|
39007
39538
|
} finally {
|
|
39008
39539
|
const endedAt = Date.now();
|
|
39009
39540
|
const finalAccountId = diagnosticState?.accountId ?? requestDiagnostic.accountId ?? requestDiagnostic.attempts.at(-1)?.accountId;
|
|
39010
|
-
const errorCode = requestError instanceof LlmError ? requestError.code : requestError === void 0 ? void 0 : "UNKNOWN";
|
|
39541
|
+
const errorCode = requestError instanceof LlmError$1 ? requestError.code : requestError === void 0 ? void 0 : "UNKNOWN";
|
|
39011
39542
|
const lastAttempt = requestDiagnostic.attempts.at(-1);
|
|
39012
39543
|
if (lastAttempt !== void 0 && errorCode !== void 0) {
|
|
39013
39544
|
lastAttempt.code = errorCode;
|
|
@@ -39088,22 +39619,22 @@ function isRefreshTimeout(error) {
|
|
|
39088
39619
|
}
|
|
39089
39620
|
/** Preserve OAuth failure semantics before the first model request. */
|
|
39090
39621
|
function credentialFailure(error, signal) {
|
|
39091
|
-
if (signal.aborted) return new LlmError("Kimi Code credential preparation aborted", "ABORTED", { cause: error });
|
|
39092
|
-
if (error instanceof LlmError) return error;
|
|
39093
|
-
if (error instanceof KimiCodeUnauthorizedError) return new LlmError(error.message, "INVALID_CREDENTIAL", { cause: error });
|
|
39094
|
-
if (error instanceof KimiCodeOAuthError) return new LlmError(error.message, "INVALID_REQUEST", {
|
|
39622
|
+
if (signal.aborted) return new LlmError$1("Kimi Code credential preparation aborted", "ABORTED", { cause: error });
|
|
39623
|
+
if (error instanceof LlmError$1) return error;
|
|
39624
|
+
if (error instanceof KimiCodeUnauthorizedError) return new LlmError$1(error.message, "INVALID_CREDENTIAL", { cause: error });
|
|
39625
|
+
if (error instanceof KimiCodeOAuthError) return new LlmError$1(error.message, "INVALID_REQUEST", {
|
|
39095
39626
|
cause: error,
|
|
39096
39627
|
status: error.status
|
|
39097
39628
|
});
|
|
39098
39629
|
if (error instanceof KimiCodeRetryableError) {
|
|
39099
39630
|
const detail = errorChain(error).trim().slice(0, 500);
|
|
39100
39631
|
const code = error.status === 429 ? "RATE_LIMIT" : error.status !== void 0 ? "SERVER" : isRefreshTimeout(error) ? "TIMEOUT" : "TRANSPORT";
|
|
39101
|
-
return new LlmError(`Kimi Code credential refresh failed: ${detail}`, code, {
|
|
39632
|
+
return new LlmError$1(`Kimi Code credential refresh failed: ${detail}`, code, {
|
|
39102
39633
|
cause: error,
|
|
39103
39634
|
...error.status === void 0 ? {} : { status: error.status }
|
|
39104
39635
|
});
|
|
39105
39636
|
}
|
|
39106
|
-
return new LlmError(`Kimi Code credential could not be prepared: ${error instanceof Error ? error.message : String(error)}`, "MISSING_CREDENTIAL", { cause: error });
|
|
39637
|
+
return new LlmError$1(`Kimi Code credential could not be prepared: ${error instanceof Error ? error.message : String(error)}`, "MISSING_CREDENTIAL", { cause: error });
|
|
39107
39638
|
}
|
|
39108
39639
|
/**
|
|
39109
39640
|
* The failure a stream that died mid-body is reported as.
|
|
@@ -39131,10 +39662,10 @@ function credentialFailure(error, signal) {
|
|
|
39131
39662
|
* retried one.
|
|
39132
39663
|
*/
|
|
39133
39664
|
function streamFailure(error, signal) {
|
|
39134
|
-
if (error instanceof LlmError) return error;
|
|
39135
|
-
if (signal.aborted) return new LlmError("Kimi Code stream aborted", "ABORTED", { cause: error });
|
|
39665
|
+
if (error instanceof LlmError$1) return error;
|
|
39666
|
+
if (signal.aborted) return new LlmError$1("Kimi Code stream aborted", "ABORTED", { cause: error });
|
|
39136
39667
|
const chain = errorChain(error).trim();
|
|
39137
|
-
return new LlmError(`Kimi Code stream failed: ${chain === "" ? "the response stream ended unexpectedly" : chain.slice(0, 500)}`, "TRANSPORT", { cause: error });
|
|
39668
|
+
return new LlmError$1(`Kimi Code stream failed: ${chain === "" ? "the response stream ended unexpectedly" : chain.slice(0, 500)}`, "TRANSPORT", { cause: error });
|
|
39138
39669
|
}
|
|
39139
39670
|
function processLine(line, state, wire) {
|
|
39140
39671
|
return wire === "anthropic" ? processAnthropicStreamLine(line, state) : processOpenAIStreamLine(line, state);
|
|
@@ -41301,204 +41832,13 @@ function renderDirectCallReminder(toolNames) {
|
|
|
41301
41832
|
].join("\n");
|
|
41302
41833
|
}
|
|
41303
41834
|
/**
|
|
41304
|
-
*
|
|
41305
|
-
* @returns 后缀正文。
|
|
41306
|
-
*/
|
|
41307
|
-
const TURN_ONLY_SUFFIX = " This is a temporary runtime reminder for the current Turn only, not a user preference or a durable rule; do not save this reminder or generalize it into Memory, Skills, or other persistent instruction files for future Turns or sessions.";
|
|
41308
|
-
/**
|
|
41309
|
-
* 渲染「同一个动作立刻重复」提醒。
|
|
41310
|
-
*
|
|
41311
|
-
* 与官方 `packages/agent-modules/runaway-guard/src/reminder.ts` 逐字一致。
|
|
41312
|
-
* @param occurrences - 连击次数。
|
|
41313
|
-
* @returns 提醒正文。
|
|
41314
|
-
*/
|
|
41315
|
-
function renderExactActionRepeatReminder(occurrences) {
|
|
41316
|
-
return `[runaway guard] The immediately repeated tool action has now occurred ${occurrences} times with the same arguments. Do not repeat it unchanged. Inspect the results already available, then either change strategy with a concrete expected state change, or report the blocker. Repetition alone does not establish that the task is complete or impossible.${TURN_ONLY_SUFFIX}`;
|
|
41317
|
-
}
|
|
41318
|
-
/**
|
|
41319
|
-
* 渲染「同一族错误连续发生」提醒。
|
|
41320
|
-
*
|
|
41321
|
-
* 与官方 `packages/agent-modules/runaway-guard/src/reminder.ts` 逐字一致。
|
|
41322
|
-
* @param occurrences - 连击次数。
|
|
41323
|
-
* @returns 提醒正文。
|
|
41324
|
-
*/
|
|
41325
|
-
function renderSameErrorFamilyReminder(occurrences) {
|
|
41326
|
-
return `[runaway guard] The same tool error family has now occurred ${occurrences} times in a row. Do not retry the same route unchanged. Diagnose the cause, change one controlled variable or switch route. Do not infer that the entire task has failed from this signal.${TURN_ONLY_SUFFIX}`;
|
|
41327
|
-
}
|
|
41328
|
-
/**
|
|
41329
|
-
* 渲染「反复轮询同一个后台任务」提醒。
|
|
41330
|
-
*
|
|
41331
|
-
* 与官方 `packages/agent-modules/runaway-guard/src/reminder.ts` 逐字一致:
|
|
41332
|
-
* 三次读同一个任务时写的是 `Three`,其它次数写数字。
|
|
41333
|
-
* @param occurrences - 连击次数。
|
|
41334
|
-
* @returns 提醒正文。
|
|
41335
|
-
*/
|
|
41336
|
-
function renderPollingRepeatReminder(occurrences) {
|
|
41337
|
-
return [
|
|
41338
|
-
"<system-reminder>",
|
|
41339
|
-
`${occurrences === 3 ? "Three" : String(occurrences)} task_output reads for the same task have returned an unchanged status and output cursor. Avoid repeated polling; you will be notified automatically and this conversation will resume when the background task completes.`,
|
|
41340
|
-
"This reminder applies only to the current Turn. Do not save or generalize it into Memory, Skills, or other persistent instructions.",
|
|
41341
|
-
"</system-reminder>"
|
|
41342
|
-
].join("\n");
|
|
41343
|
-
}
|
|
41344
|
-
/**
|
|
41345
|
-
* 轮询类工具名(后台任务的结果读取)。
|
|
41346
|
-
*
|
|
41347
|
-
* 这两个工具读的是后台任务的状态;反复读同一个任务而输出没变,就是官方说的
|
|
41348
|
-
* 「polling repeat」。
|
|
41349
|
-
*/
|
|
41350
|
-
const POLLING_TOOL_NAMES = Object.freeze(["job_output", "task_output"]);
|
|
41351
|
-
/**
|
|
41352
|
-
* 规范化一段错误文本,取它的「族」。
|
|
41353
|
-
*
|
|
41354
|
-
* 族的作用是**把同一类错误认成同一类**:路径里的数字、id、时间戳都不该让
|
|
41355
|
-
* 两次一模一样的失败看起来是两回事。
|
|
41356
|
-
* @param text - 错误文本。
|
|
41357
|
-
* @returns 族标识。
|
|
41358
|
-
*/
|
|
41359
|
-
function errorFamilyOf(text) {
|
|
41360
|
-
if (text === void 0 || text === "") return "unknown";
|
|
41361
|
-
return (text.split(/\r?\n/, 1)[0] ?? "").replace(/\d+/g, "#").slice(0, 200);
|
|
41362
|
-
}
|
|
41363
|
-
/**
|
|
41364
|
-
* 造一台工具级失控守卫。
|
|
41365
|
-
*
|
|
41366
|
-
* 三种可提醒信号(顺序即官方提醒优先级):
|
|
41367
|
-
*
|
|
41368
|
-
* 1. `same_error_family` —— 同一个工具连续报同一族错误;
|
|
41369
|
-
* 2. `exact_action_repeat` —— 同一次动作(同名 + 同参数)立刻重复;
|
|
41370
|
-
* 3. `polling_repeat` —— 连续轮询同一个后台任务而输出没变。
|
|
41371
|
-
*
|
|
41372
|
-
* `abab_action_cycle`(A B A B 的循环)**只记录不提醒**:官方把它排在提醒
|
|
41373
|
-
* 候选之外——模型在两个动作之间来回跳时,提醒它「别重复」是没有意义的。
|
|
41374
|
-
*
|
|
41375
|
-
* 每轮**至多一条**提醒:官方在发出第一条后就把本轮的提醒机会用掉了。
|
|
41835
|
+
* 造一台 MiniMax Code 会话的工具级失控守卫(实现已下沉至共享内核 `tool-runaway.ts`)。
|
|
41376
41836
|
*
|
|
41377
41837
|
* @param options - 守卫选项。
|
|
41378
41838
|
* @returns 守卫。
|
|
41379
41839
|
*/
|
|
41380
41840
|
function createMinimaxRunawayGuard(options = {}) {
|
|
41381
|
-
|
|
41382
|
-
/** 同一次动作的连击,由所有线路共享的规范键与跟踪器计算。 */
|
|
41383
|
-
const exactActionRepeats = createExactRepeatTracker();
|
|
41384
|
-
/** 同一族错误的连击(键是工具名 + 错误族)。 */
|
|
41385
|
-
const errorStreaks = /* @__PURE__ */ new Map();
|
|
41386
|
-
/** 轮询连击(键是工具名)。 */
|
|
41387
|
-
const pollingStreaks = /* @__PURE__ */ new Map();
|
|
41388
|
-
/** 最近几次动作,用来认 A B A B 的循环。 */
|
|
41389
|
-
const recentActions = [];
|
|
41390
|
-
/** 当前正在计数的 A B 循环对。 */
|
|
41391
|
-
let activeAbabKey;
|
|
41392
|
-
/** 本轮是否已经提醒过。 */
|
|
41393
|
-
let reminderAttempted = false;
|
|
41394
|
-
/** 观察到的信号。 */
|
|
41395
|
-
const signals = [];
|
|
41396
|
-
/**
|
|
41397
|
-
* 记一条信号。
|
|
41398
|
-
* @param kind - 信号种类。
|
|
41399
|
-
* @param occurrences - 连击次数。
|
|
41400
|
-
* @param toolName - 工具名。
|
|
41401
|
-
*/
|
|
41402
|
-
const record = (kind, occurrences, toolName) => {
|
|
41403
|
-
signals.push({
|
|
41404
|
-
kind,
|
|
41405
|
-
occurrences,
|
|
41406
|
-
toolName
|
|
41407
|
-
});
|
|
41408
|
-
};
|
|
41409
|
-
/**
|
|
41410
|
-
* 判断这次执行是不是一次「原地不动」的轮询。
|
|
41411
|
-
* @param observation - 观察事实。
|
|
41412
|
-
* @returns 是轮询时为 true。
|
|
41413
|
-
*/
|
|
41414
|
-
const isPolling = (observation) => {
|
|
41415
|
-
if (!POLLING_TOOL_NAMES.includes(observation.toolName)) return false;
|
|
41416
|
-
return (isPlainRecord(observation.arguments) ? observation.arguments : void 0)?.["wait"] !== true;
|
|
41417
|
-
};
|
|
41418
|
-
return {
|
|
41419
|
-
observe(observation) {
|
|
41420
|
-
const toolName = observation.toolName;
|
|
41421
|
-
const actionKey = canonicalToolCallKey(toolName, observation.arguments);
|
|
41422
|
-
const countsAsAction = !POLLING_TOOL_NAMES.includes(toolName);
|
|
41423
|
-
if (countsAsAction) {
|
|
41424
|
-
const action = exactActionRepeats.observe(toolName, observation.arguments);
|
|
41425
|
-
record("exact_action_repeat", action.count, toolName);
|
|
41426
|
-
}
|
|
41427
|
-
if (countsAsAction) {
|
|
41428
|
-
recentActions.push(actionKey);
|
|
41429
|
-
if (recentActions.length > 4) recentActions.shift();
|
|
41430
|
-
if (recentActions.length === 4) {
|
|
41431
|
-
const [a, b, c, d] = recentActions;
|
|
41432
|
-
if (a !== void 0 && b !== void 0 && a !== b && a === c && b === d) {
|
|
41433
|
-
const episode = `${a}\u0000${b}`;
|
|
41434
|
-
if (activeAbabKey !== episode) {
|
|
41435
|
-
activeAbabKey = episode;
|
|
41436
|
-
record("abab_action_cycle", 2, toolName);
|
|
41437
|
-
}
|
|
41438
|
-
} else activeAbabKey = void 0;
|
|
41439
|
-
}
|
|
41440
|
-
}
|
|
41441
|
-
if (observation.isError === true) {
|
|
41442
|
-
const key = `${toolName}\u0000${observation.errorCode ?? errorFamilyOf(observation.errorText)}`;
|
|
41443
|
-
const previous = errorStreaks.get(key);
|
|
41444
|
-
const count = previous === void 0 ? 1 : previous.count + 1;
|
|
41445
|
-
errorStreaks.set(key, {
|
|
41446
|
-
toolName,
|
|
41447
|
-
count
|
|
41448
|
-
});
|
|
41449
|
-
record("same_error_family", count, toolName);
|
|
41450
|
-
} else for (const [key, entry] of [...errorStreaks]) if (entry.toolName === toolName) errorStreaks.delete(key);
|
|
41451
|
-
if (isPolling(observation)) {
|
|
41452
|
-
const key = `${canonicalToolCallKey(toolName, observation.arguments)}\u0000${observation.resultText ?? ""}`;
|
|
41453
|
-
const previous = pollingStreaks.get(toolName);
|
|
41454
|
-
const count = previous !== void 0 && previous.key === key ? previous.count + 1 : 1;
|
|
41455
|
-
pollingStreaks.set(toolName, {
|
|
41456
|
-
key,
|
|
41457
|
-
count
|
|
41458
|
-
});
|
|
41459
|
-
record("polling_repeat", count, toolName);
|
|
41460
|
-
} else pollingStreaks.delete(toolName);
|
|
41461
|
-
if (reminderAttempted) return void 0;
|
|
41462
|
-
const errorCandidate = [...errorStreaks.values()].find((entry) => entry.count >= threshold);
|
|
41463
|
-
if (errorCandidate !== void 0) {
|
|
41464
|
-
reminderAttempted = true;
|
|
41465
|
-
return {
|
|
41466
|
-
kind: "same_error_family",
|
|
41467
|
-
occurrences: errorCandidate.count,
|
|
41468
|
-
text: renderSameErrorFamilyReminder(errorCandidate.count)
|
|
41469
|
-
};
|
|
41470
|
-
}
|
|
41471
|
-
const actionStreak = exactActionRepeats.current();
|
|
41472
|
-
if (countsAsAction && actionStreak !== void 0 && actionStreak.count >= threshold) {
|
|
41473
|
-
reminderAttempted = true;
|
|
41474
|
-
return {
|
|
41475
|
-
kind: "exact_action_repeat",
|
|
41476
|
-
occurrences: actionStreak.count,
|
|
41477
|
-
text: renderExactActionRepeatReminder(actionStreak.count)
|
|
41478
|
-
};
|
|
41479
|
-
}
|
|
41480
|
-
const pollingCandidate = [...pollingStreaks.values()].find((entry) => entry.count >= threshold);
|
|
41481
|
-
if (pollingCandidate !== void 0) {
|
|
41482
|
-
reminderAttempted = true;
|
|
41483
|
-
return {
|
|
41484
|
-
kind: "polling_repeat",
|
|
41485
|
-
occurrences: pollingCandidate.count,
|
|
41486
|
-
text: renderPollingRepeatReminder(pollingCandidate.count)
|
|
41487
|
-
};
|
|
41488
|
-
}
|
|
41489
|
-
},
|
|
41490
|
-
reset() {
|
|
41491
|
-
exactActionRepeats.reset();
|
|
41492
|
-
errorStreaks.clear();
|
|
41493
|
-
pollingStreaks.clear();
|
|
41494
|
-
recentActions.length = 0;
|
|
41495
|
-
activeAbabKey = void 0;
|
|
41496
|
-
reminderAttempted = false;
|
|
41497
|
-
},
|
|
41498
|
-
get signals() {
|
|
41499
|
-
return signals;
|
|
41500
|
-
}
|
|
41501
|
-
};
|
|
41841
|
+
return createToolRunawayGuard(options);
|
|
41502
41842
|
}
|
|
41503
41843
|
/**
|
|
41504
41844
|
* 读宿主上下文上的工具注册面。
|
|
@@ -41683,51 +42023,6 @@ function createRunawayReminder(reminder) {
|
|
|
41683
42023
|
});
|
|
41684
42024
|
}
|
|
41685
42025
|
/**
|
|
41686
|
-
* 读一次执行的结果是不是失败。
|
|
41687
|
-
* @param result - 工具执行结果。
|
|
41688
|
-
* @returns 失败时为 true。
|
|
41689
|
-
*/
|
|
41690
|
-
function isErrorResult(result) {
|
|
41691
|
-
return isRecord$50(result) && result["isError"] === true;
|
|
41692
|
-
}
|
|
41693
|
-
/**
|
|
41694
|
-
* 读一次执行的结构化错误码。
|
|
41695
|
-
* @param result - 工具执行结果。
|
|
41696
|
-
* @returns 错误码;没有时为 undefined。
|
|
41697
|
-
*/
|
|
41698
|
-
function errorCodeOf$1(result) {
|
|
41699
|
-
if (!isRecord$50(result)) return void 0;
|
|
41700
|
-
const error = result["error"];
|
|
41701
|
-
if (!isRecord$50(error)) return void 0;
|
|
41702
|
-
const info = error["info"];
|
|
41703
|
-
if (!isRecord$50(info)) return void 0;
|
|
41704
|
-
return stringOf$4(info["code"]);
|
|
41705
|
-
}
|
|
41706
|
-
/**
|
|
41707
|
-
* 读一次执行的失败文本。
|
|
41708
|
-
* @param result - 工具执行结果。
|
|
41709
|
-
* @returns 失败文本;没有时为 undefined。
|
|
41710
|
-
*/
|
|
41711
|
-
function errorTextOf(result) {
|
|
41712
|
-
if (!isRecord$50(result)) return void 0;
|
|
41713
|
-
const error = result["error"];
|
|
41714
|
-
if (!isRecord$50(error)) return void 0;
|
|
41715
|
-
return stringOf$4(error["message"]);
|
|
41716
|
-
}
|
|
41717
|
-
/**
|
|
41718
|
-
* 读一次执行的结果文本(轮询判定用)。
|
|
41719
|
-
* @param result - 工具执行结果。
|
|
41720
|
-
* @returns 结果文本;没有时是空串。
|
|
41721
|
-
*/
|
|
41722
|
-
function resultTextOf(result) {
|
|
41723
|
-
if (!isRecord$50(result)) return "";
|
|
41724
|
-
const content = result["content"];
|
|
41725
|
-
if (!Array.isArray(content)) return "";
|
|
41726
|
-
const parts = [];
|
|
41727
|
-
for (const block of content) if (isRecord$50(block) && block["type"] === "text") parts.push(stringOf$4(block["text"]) ?? "");
|
|
41728
|
-
return parts.join("\n");
|
|
41729
|
-
}
|
|
41730
|
-
/**
|
|
41731
42026
|
* 找一次工具调用的参数 schema。
|
|
41732
42027
|
* @param tools - 工具注册面。
|
|
41733
42028
|
* @param name - 工具名。
|
|
@@ -41833,15 +42128,16 @@ function installMinimaxRuntimeEnhancements(ctx, options = {}) {
|
|
|
41833
42128
|
const contexts = [];
|
|
41834
42129
|
const directName = directCallToolNameOf(exec);
|
|
41835
42130
|
if (directName !== void 0 && isPtcSessionOf(agent, tools)) contexts.push(createDirectCallReminder(directName));
|
|
41836
|
-
|
|
41837
|
-
|
|
41838
|
-
|
|
41839
|
-
|
|
41840
|
-
|
|
41841
|
-
|
|
41842
|
-
|
|
41843
|
-
|
|
41844
|
-
|
|
42131
|
+
if ((() => {
|
|
42132
|
+
try {
|
|
42133
|
+
return options.runawayEnabled?.() !== false;
|
|
42134
|
+
} catch {
|
|
42135
|
+
return true;
|
|
42136
|
+
}
|
|
42137
|
+
})()) {
|
|
42138
|
+
const reminder = guardOf(agent).observe(observationFromToolExecution(exec.name, exec.arguments, result));
|
|
42139
|
+
if (reminder !== void 0) contexts.push(createRunawayReminder(reminder));
|
|
42140
|
+
}
|
|
41845
42141
|
if (contexts.length === 0) return decision;
|
|
41846
42142
|
return withAdditionalContexts$1(decision, contexts);
|
|
41847
42143
|
} catch {
|
|
@@ -45977,7 +46273,7 @@ function sameModelId(requested, answered) {
|
|
|
45977
46273
|
* substitution means this id no longer routes, so the selection has to change.
|
|
45978
46274
|
*/
|
|
45979
46275
|
function modelSubstitutedFailure(requested, answered) {
|
|
45980
|
-
return new LlmError("MiniMax Code(编程订阅) answered with a different model than the one requested: the request asked for \"" + requested + "\", and the service answered as \"" + answered + "\". This endpoint does not reject a model id it cannot route — it silently runs another one — so the id \"" + requested + "\" is not being served and the request was billed at the answering model's rate instead. Nothing was retried, because the same request would be answered the same way. Pick a different model for this line, or check whether \"" + requested + "\" is still offered, then send the request again.", MODEL_SUBSTITUTED_CODE, { status: 200 });
|
|
46276
|
+
return new LlmError$1("MiniMax Code(编程订阅) answered with a different model than the one requested: the request asked for \"" + requested + "\", and the service answered as \"" + answered + "\". This endpoint does not reject a model id it cannot route — it silently runs another one — so the id \"" + requested + "\" is not being served and the request was billed at the answering model's rate instead. Nothing was retried, because the same request would be answered the same way. Pick a different model for this line, or check whether \"" + requested + "\" is still offered, then send the request again.", MODEL_SUBSTITUTED_CODE, { status: 200 });
|
|
45981
46277
|
}
|
|
45982
46278
|
var MinimaxCodeAdapter = class extends LlmAdapter {
|
|
45983
46279
|
store;
|
|
@@ -46108,7 +46404,7 @@ var MinimaxCodeAdapter = class extends LlmAdapter {
|
|
|
46108
46404
|
* deliberately not exposed as a fixed defaultMaxTokens reservation here.
|
|
46109
46405
|
*/
|
|
46110
46406
|
async resolveModel(provider, modelId, signal) {
|
|
46111
|
-
if (signal?.aborted === true) throw new LlmError("MiniMax Code model resolution aborted", "ABORTED");
|
|
46407
|
+
if (signal?.aborted === true) throw new LlmError$1("MiniMax Code model resolution aborted", "ABORTED");
|
|
46112
46408
|
const settings = await this.settings();
|
|
46113
46409
|
const entry = minimaxCodeModelDef(modelId);
|
|
46114
46410
|
const efforts = orderReasoningEfforts(effortsForModel(modelId), [
|
|
@@ -46202,8 +46498,8 @@ var MinimaxCodeAdapter = class extends LlmAdapter {
|
|
|
46202
46498
|
credentials = selection.credentials;
|
|
46203
46499
|
accountId = selection.accountId;
|
|
46204
46500
|
} catch (error) {
|
|
46205
|
-
if (error instanceof MinimaxCodeUnauthorizedError) throw new LlmError(error.message, "INVALID_CREDENTIAL", { cause: error });
|
|
46206
|
-
throw new LlmError("MiniMax Code(编程订阅) credential could not be prepared: " + (error instanceof Error ? error.message : String(error)), "MISSING_CREDENTIAL", { cause: error });
|
|
46501
|
+
if (error instanceof MinimaxCodeUnauthorizedError) throw new LlmError$1(error.message, "INVALID_CREDENTIAL", { cause: error });
|
|
46502
|
+
throw new LlmError$1("MiniMax Code(编程订阅) credential could not be prepared: " + (error instanceof Error ? error.message : String(error)), "MISSING_CREDENTIAL", { cause: error });
|
|
46207
46503
|
}
|
|
46208
46504
|
if (accountId !== void 0) tried.add(accountId);
|
|
46209
46505
|
authOwner = computeMinimaxAuthOwner(credentials, accountId);
|
|
@@ -46252,8 +46548,8 @@ var MinimaxCodeAdapter = class extends LlmAdapter {
|
|
|
46252
46548
|
});
|
|
46253
46549
|
activity?.pulse();
|
|
46254
46550
|
} catch (error) {
|
|
46255
|
-
if (signal.aborted) throw new LlmError("MiniMax Code request aborted", "ABORTED", { cause: error });
|
|
46256
|
-
throw new LlmError("MiniMax Code(编程订阅) request failed: " + (error instanceof Error ? error.message : String(error)), "TRANSPORT", { cause: error });
|
|
46551
|
+
if (signal.aborted) throw new LlmError$1("MiniMax Code request aborted", "ABORTED", { cause: error });
|
|
46552
|
+
throw new LlmError$1("MiniMax Code(编程订阅) request failed: " + (error instanceof Error ? error.message : String(error)), "TRANSPORT", { cause: error });
|
|
46257
46553
|
}
|
|
46258
46554
|
refusedBody = void 0;
|
|
46259
46555
|
if (response.ok) break;
|
|
@@ -46266,8 +46562,8 @@ var MinimaxCodeAdapter = class extends LlmAdapter {
|
|
|
46266
46562
|
authOwner = computeMinimaxAuthOwner(credentials, accountId);
|
|
46267
46563
|
body = buildBodyForOwner(authOwner);
|
|
46268
46564
|
} catch (error) {
|
|
46269
|
-
if (error instanceof MinimaxCodeUnauthorizedError) throw new LlmError(error.message, "INVALID_CREDENTIAL", { cause: error });
|
|
46270
|
-
throw new LlmError("MiniMax Code(编程订阅) credential could not be renewed after the service refused " + redactToken(refused) + ": " + (error instanceof Error ? error.message : String(error)), "INVALID_CREDENTIAL", { cause: error });
|
|
46565
|
+
if (error instanceof MinimaxCodeUnauthorizedError) throw new LlmError$1(error.message, "INVALID_CREDENTIAL", { cause: error });
|
|
46566
|
+
throw new LlmError$1("MiniMax Code(编程订阅) credential could not be renewed after the service refused " + redactToken(refused) + ": " + (error instanceof Error ? error.message : String(error)), "INVALID_CREDENTIAL", { cause: error });
|
|
46271
46567
|
}
|
|
46272
46568
|
}
|
|
46273
46569
|
if (response.ok) break;
|
|
@@ -46282,12 +46578,12 @@ var MinimaxCodeAdapter = class extends LlmAdapter {
|
|
|
46282
46578
|
}
|
|
46283
46579
|
}
|
|
46284
46580
|
const hint = failure.code === "INVALID_CREDENTIAL" ? " (credential " + redactToken(credentials.accessToken) + ")" : "";
|
|
46285
|
-
throw new LlmError(failure.message + hint, failure.code, {
|
|
46581
|
+
throw new LlmError$1(failure.message + hint, failure.code, {
|
|
46286
46582
|
status: response.status,
|
|
46287
46583
|
...after === void 0 ? {} : { providerRetryAfterMs: after }
|
|
46288
46584
|
});
|
|
46289
46585
|
}
|
|
46290
|
-
if (response.body === null) throw new LlmError("MiniMax Code(编程订阅) returned an empty response body", "PROVIDER_ERROR");
|
|
46586
|
+
if (response.body === null) throw new LlmError$1("MiniMax Code(编程订阅) returned an empty response body", "PROVIDER_ERROR");
|
|
46291
46587
|
const reader = response.body.getReader();
|
|
46292
46588
|
const decoder = new TextDecoder();
|
|
46293
46589
|
const state = createStreamState({
|
|
@@ -46378,7 +46674,7 @@ var MinimaxCodeAdapter = class extends LlmAdapter {
|
|
|
46378
46674
|
yield chunk;
|
|
46379
46675
|
}
|
|
46380
46676
|
} catch (error) {
|
|
46381
|
-
if (error instanceof LlmError && !outputStarted && error.code === "PROVIDER_ERROR" && state.streamError !== void 0) {
|
|
46677
|
+
if (error instanceof LlmError$1 && !outputStarted && error.code === "PROVIDER_ERROR" && state.streamError !== void 0) {
|
|
46382
46678
|
const reclassified = reclassifyInBandError(error, state.streamError, classifyMinimaxFailure);
|
|
46383
46679
|
if (pool !== void 0 && accountId !== void 0) {
|
|
46384
46680
|
const inBandBody = JSON.stringify({ error: state.streamError });
|
|
@@ -49605,7 +49901,14 @@ function installKimiRepeatBreaker(ctx, options = {}) {
|
|
|
49605
49901
|
if (target === void 0) return decision;
|
|
49606
49902
|
const toolName = stringOf$3(exec.name);
|
|
49607
49903
|
if (toolName === void 0) return decision;
|
|
49608
|
-
const
|
|
49904
|
+
const args = exec.arguments;
|
|
49905
|
+
const obs = observationFromToolExecution(toolName, args, result);
|
|
49906
|
+
const reminder = target.breaker.recordAfterExecute(target.key, toolName, args, {
|
|
49907
|
+
isError: obs.isError,
|
|
49908
|
+
errorCode: obs.errorCode,
|
|
49909
|
+
errorText: obs.errorText,
|
|
49910
|
+
resultText: obs.resultText
|
|
49911
|
+
});
|
|
49609
49912
|
if (reminder === void 0) return decision;
|
|
49610
49913
|
return withAdditionalContexts(decision, [createRepeatBreakerReminder(reminder)]);
|
|
49611
49914
|
} catch {
|
|
@@ -57129,7 +57432,7 @@ function assertClaudeCliVersionMeetsFloor(modelId, catalog = FALLBACK_MODELS) {
|
|
|
57129
57432
|
if (floor === void 0) return;
|
|
57130
57433
|
const effective = claudeCliVersion();
|
|
57131
57434
|
if (meetsDottedVersionFloor(effective, floor)) return;
|
|
57132
|
-
throw new LlmError("Claude(订阅) will not serve " + modelId + " to a client reporting version " + effective + ": upstream requires " + floor + " or newer for this model, and a lower claim is refused with claude_code_version_too_old. This was caught locally, before the request was sent. Raise the reported version with the DSH_CLAUDE_CLI_VERSION environment variable, or with a setClaudeCliVersion pin, then retry. The stored sign-in is still valid — this is not a credential problem and signing in again will not change it.", "PROVIDER_ERROR");
|
|
57435
|
+
throw new LlmError$1("Claude(订阅) will not serve " + modelId + " to a client reporting version " + effective + ": upstream requires " + floor + " or newer for this model, and a lower claim is refused with claude_code_version_too_old. This was caught locally, before the request was sent. Raise the reported version with the DSH_CLAUDE_CLI_VERSION environment variable, or with a setClaudeCliVersion pin, then retry. The stored sign-in is still valid — this is not a credential problem and signing in again will not change it.", "PROVIDER_ERROR");
|
|
57133
57436
|
}
|
|
57134
57437
|
const claudePrefixRequests = new PrefixRequestCoordinator();
|
|
57135
57438
|
const claudeStickyImages = new StickyImageBudgetStore("claude");
|
|
@@ -57277,7 +57580,7 @@ var ClaudeAdapter = class ClaudeAdapter extends LlmAdapter {
|
|
|
57277
57580
|
}));
|
|
57278
57581
|
}
|
|
57279
57582
|
async resolveModel(provider, modelId, signal) {
|
|
57280
|
-
if (signal?.aborted) throw new LlmError("Claude model resolution aborted", "ABORTED");
|
|
57583
|
+
if (signal?.aborted) throw new LlmError$1("Claude model resolution aborted", "ABORTED");
|
|
57281
57584
|
const settings = await this.settings();
|
|
57282
57585
|
const record = await this.primaryAccount(settings);
|
|
57283
57586
|
const catalog = record === null ? FALLBACK_MODELS : await this.catalog(record.credentials);
|
|
@@ -57326,7 +57629,7 @@ var ClaudeAdapter = class ClaudeAdapter extends LlmAdapter {
|
|
|
57326
57629
|
async resolveCredential(pool, tried, fetchFn, signal) {
|
|
57327
57630
|
if (pool === null) {
|
|
57328
57631
|
const record = await this.primaryAccount(await this.settings());
|
|
57329
|
-
if (record === null) throw new LlmError(MISSING_CREDENTIAL_MESSAGE, "MISSING_CREDENTIAL");
|
|
57632
|
+
if (record === null) throw new LlmError$1(MISSING_CREDENTIAL_MESSAGE, "MISSING_CREDENTIAL");
|
|
57330
57633
|
try {
|
|
57331
57634
|
return {
|
|
57332
57635
|
credentials: await ensureAccessToken(new ClaudeAccountTokenStore(this.store, record.internalId), {
|
|
@@ -57336,8 +57639,8 @@ var ClaudeAdapter = class ClaudeAdapter extends LlmAdapter {
|
|
|
57336
57639
|
accountId: void 0
|
|
57337
57640
|
};
|
|
57338
57641
|
} catch (error) {
|
|
57339
|
-
if (error instanceof ClaudeUnauthorizedError) throw new LlmError(error.message, "INVALID_CREDENTIAL", { cause: error });
|
|
57340
|
-
throw new LlmError("Claude credential could not be prepared: " + (error instanceof Error ? error.message : String(error)), "MISSING_CREDENTIAL", { cause: error });
|
|
57642
|
+
if (error instanceof ClaudeUnauthorizedError) throw new LlmError$1(error.message, "INVALID_CREDENTIAL", { cause: error });
|
|
57643
|
+
throw new LlmError$1("Claude credential could not be prepared: " + (error instanceof Error ? error.message : String(error)), "MISSING_CREDENTIAL", { cause: error });
|
|
57341
57644
|
}
|
|
57342
57645
|
}
|
|
57343
57646
|
try {
|
|
@@ -57348,8 +57651,8 @@ var ClaudeAdapter = class ClaudeAdapter extends LlmAdapter {
|
|
|
57348
57651
|
accountId: effective.account.id
|
|
57349
57652
|
};
|
|
57350
57653
|
} catch (error) {
|
|
57351
|
-
if (error instanceof LlmError) throw error;
|
|
57352
|
-
throw new LlmError(error instanceof Error ? error.message : MISSING_CREDENTIAL_MESSAGE, "MISSING_CREDENTIAL", { cause: error });
|
|
57654
|
+
if (error instanceof LlmError$1) throw error;
|
|
57655
|
+
throw new LlmError$1(error instanceof Error ? error.message : MISSING_CREDENTIAL_MESSAGE, "MISSING_CREDENTIAL", { cause: error });
|
|
57353
57656
|
}
|
|
57354
57657
|
}
|
|
57355
57658
|
/**
|
|
@@ -57402,7 +57705,7 @@ var ClaudeAdapter = class ClaudeAdapter extends LlmAdapter {
|
|
|
57402
57705
|
signal
|
|
57403
57706
|
});
|
|
57404
57707
|
} catch (error) {
|
|
57405
|
-
if (signal.aborted) throw new LlmError("Claude request aborted", "ABORTED", { cause: error });
|
|
57708
|
+
if (signal.aborted) throw new LlmError$1("Claude request aborted", "ABORTED", { cause: error });
|
|
57406
57709
|
throw toLlmError(networkFailure(error));
|
|
57407
57710
|
}
|
|
57408
57711
|
}
|
|
@@ -57461,8 +57764,8 @@ var ClaudeAdapter = class ClaudeAdapter extends LlmAdapter {
|
|
|
57461
57764
|
}
|
|
57462
57765
|
throw toLlmError(failure);
|
|
57463
57766
|
}
|
|
57464
|
-
if (response === void 0) throw new LlmError("Claude produced no response", "PROVIDER_ERROR");
|
|
57465
|
-
if (response.body === null) throw new LlmError("Claude returned an empty response body", "PROVIDER_ERROR");
|
|
57767
|
+
if (response === void 0) throw new LlmError$1("Claude produced no response", "PROVIDER_ERROR");
|
|
57768
|
+
if (response.body === null) throw new LlmError$1("Claude returned an empty response body", "PROVIDER_ERROR");
|
|
57466
57769
|
const reader = response.body.getReader();
|
|
57467
57770
|
const decoder = new TextDecoder();
|
|
57468
57771
|
const state = createStreamState$4(toolNames);
|
|
@@ -57497,14 +57800,14 @@ var ClaudeAdapter = class ClaudeAdapter extends LlmAdapter {
|
|
|
57497
57800
|
yield chunk;
|
|
57498
57801
|
}
|
|
57499
57802
|
} catch (error) {
|
|
57500
|
-
if (error instanceof LlmError) {
|
|
57803
|
+
if (error instanceof LlmError$1) {
|
|
57501
57804
|
if (outputStarted || error.code !== "PROVIDER_ERROR" || state.streamError === void 0) throw error;
|
|
57502
57805
|
const verdict = inBandStreamVerdict(error, state.streamError, response.headers);
|
|
57503
57806
|
if (verdict.failure !== null && shouldRotateAccount(verdict.failure, outputStarted) && usedAccountId !== void 0) await pool?.markCooldown(usedAccountId, cooldownMsFor(verdict.failure), "Claude(订阅) in-stream 429").catch(() => void 0);
|
|
57504
57807
|
throw verdict.error;
|
|
57505
57808
|
}
|
|
57506
|
-
if (signal.aborted) throw new LlmError("Claude request aborted", "ABORTED", { cause: error });
|
|
57507
|
-
throw new LlmError("Claude stream failed: " + (error instanceof Error ? error.message : String(error)), outputStarted ? "PROVIDER_ERROR" : "TRANSPORT", { cause: error });
|
|
57809
|
+
if (signal.aborted) throw new LlmError$1("Claude request aborted", "ABORTED", { cause: error });
|
|
57810
|
+
throw new LlmError$1("Claude stream failed: " + (error instanceof Error ? error.message : String(error)), outputStarted ? "PROVIDER_ERROR" : "TRANSPORT", { cause: error });
|
|
57508
57811
|
}
|
|
57509
57812
|
} finally {
|
|
57510
57813
|
reader.cancel().catch(() => void 0);
|
|
@@ -57630,7 +57933,7 @@ function inBandStreamVerdict(thrown, streamError, headers) {
|
|
|
57630
57933
|
};
|
|
57631
57934
|
const retryAfter = failure.retryAfterMs !== null && failure.retryAfterMs > 0 ? failure.retryAfterMs : void 0;
|
|
57632
57935
|
return {
|
|
57633
|
-
error: new LlmError(thrown.message, codeForFailure(failure), retryAfter === void 0 ? {} : { providerRetryAfterMs: retryAfter }),
|
|
57936
|
+
error: new LlmError$1(thrown.message, codeForFailure(failure), retryAfter === void 0 ? {} : { providerRetryAfterMs: retryAfter }),
|
|
57634
57937
|
failure
|
|
57635
57938
|
};
|
|
57636
57939
|
}
|
|
@@ -57650,16 +57953,16 @@ function toLlmError(failure) {
|
|
|
57650
57953
|
...retryAfter === void 0 ? {} : { providerRetryAfterMs: retryAfter }
|
|
57651
57954
|
};
|
|
57652
57955
|
const detail = failure.message === "" ? "" : " " + failure.message;
|
|
57653
|
-
if (failure.clientVersionTooOld) return new LlmError("Claude(订阅) refused this request because the client version it was told is below the server's floor (claude_code_version_too_old). Raise it with the DSH_CLAUDE_CLI_VERSION environment variable (or a setClaudeCliVersion pin), then retry — the stored sign-in is still valid." + detail, "PROVIDER_ERROR", options);
|
|
57654
|
-
if (failure.kind === "request" && isHttpContextOverflow(failure.status, failure.message)) return new LlmError("Claude(订阅) context window exceeded." + detail, CONTEXT_OVERFLOW_CODE, options);
|
|
57956
|
+
if (failure.clientVersionTooOld) return new LlmError$1("Claude(订阅) refused this request because the client version it was told is below the server's floor (claude_code_version_too_old). Raise it with the DSH_CLAUDE_CLI_VERSION environment variable (or a setClaudeCliVersion pin), then retry — the stored sign-in is still valid." + detail, "PROVIDER_ERROR", options);
|
|
57957
|
+
if (failure.kind === "request" && isHttpContextOverflow(failure.status, failure.message)) return new LlmError$1("Claude(订阅) context window exceeded." + detail, CONTEXT_OVERFLOW_CODE, options);
|
|
57655
57958
|
switch (failure.kind) {
|
|
57656
|
-
case "credential": return new LlmError("Claude(订阅) rejected the stored credential. Sign in again from Settings > Claude." + detail, "INVALID_CREDENTIAL", options);
|
|
57959
|
+
case "credential": return new LlmError$1("Claude(订阅) rejected the stored credential. Sign in again from Settings > Claude." + detail, "INVALID_CREDENTIAL", options);
|
|
57657
57960
|
case "rate_limit_account":
|
|
57658
|
-
case "rate_limit_global": return new LlmError("Claude(订阅) rate limit reached" + (failure.accountScoped ? " for this account" : "") + (failure.resetsAt === null ? "" : ", resets at " + failure.resetsAt) + ". Check the quota card in Settings > Claude." + detail, "RATE_LIMIT", options);
|
|
57659
|
-
case "overloaded": return new LlmError("Claude(订阅) is temporarily overloaded." + detail, "SERVER", options);
|
|
57660
|
-
case "server": return new LlmError("Claude(订阅) upstream server error (" + failure.status + ")." + detail, "SERVER", options);
|
|
57661
|
-
case "request": return new LlmError("Claude(订阅) rejected the request." + detail, "PROVIDER_ERROR", options);
|
|
57662
|
-
default: return new LlmError("Claude(订阅) request failed before a response arrived." + detail, "TRANSPORT", options);
|
|
57961
|
+
case "rate_limit_global": return new LlmError$1("Claude(订阅) rate limit reached" + (failure.accountScoped ? " for this account" : "") + (failure.resetsAt === null ? "" : ", resets at " + failure.resetsAt) + ". Check the quota card in Settings > Claude." + detail, "RATE_LIMIT", options);
|
|
57962
|
+
case "overloaded": return new LlmError$1("Claude(订阅) is temporarily overloaded." + detail, "SERVER", options);
|
|
57963
|
+
case "server": return new LlmError$1("Claude(订阅) upstream server error (" + failure.status + ")." + detail, "SERVER", options);
|
|
57964
|
+
case "request": return new LlmError$1("Claude(订阅) rejected the request." + detail, "PROVIDER_ERROR", options);
|
|
57965
|
+
default: return new LlmError$1("Claude(订阅) request failed before a response arrived." + detail, "TRANSPORT", options);
|
|
57663
57966
|
}
|
|
57664
57967
|
}
|
|
57665
57968
|
//#endregion
|
|
@@ -64445,7 +64748,7 @@ function glmCooldownDecision(input) {
|
|
|
64445
64748
|
function requireWire(modelId, entry) {
|
|
64446
64749
|
const wire = entry.wire;
|
|
64447
64750
|
if (wire === "anthropic" || wire === "openai") return wire;
|
|
64448
|
-
throw new LlmError("GLM(ZCode 账号) 的模型目录里没有 " + modelId + " 的协议声明,无法选择调用面。请在设置页刷新模型目录;若这是上游新增的模型,本插件还没记录它走哪个面。", "NOT_FOUND");
|
|
64751
|
+
throw new LlmError$1("GLM(ZCode 账号) 的模型目录里没有 " + modelId + " 的协议声明,无法选择调用面。请在设置页刷新模型目录;若这是上游新增的模型,本插件还没记录它走哪个面。", "NOT_FOUND");
|
|
64449
64752
|
}
|
|
64450
64753
|
/**
|
|
64451
64754
|
* 构造一次请求。**不联网、不读设置**,所以可以被单独测。
|
|
@@ -64569,7 +64872,7 @@ var GlmCodingPlanAdapter = class extends LlmAdapter {
|
|
|
64569
64872
|
};
|
|
64570
64873
|
}
|
|
64571
64874
|
const stored = await this.store.read();
|
|
64572
|
-
if (stored === null) throw new LlmError("还没有登录 GLM(ZCode 账号) 账号。请在设置页点击登录,或先在 ZCode 客户端登录后使用 adopt。", "MISSING_CREDENTIAL");
|
|
64875
|
+
if (stored === null) throw new LlmError$1("还没有登录 GLM(ZCode 账号) 账号。请在设置页点击登录,或先在 ZCode 客户端登录后使用 adopt。", "MISSING_CREDENTIAL");
|
|
64573
64876
|
return {
|
|
64574
64877
|
accountId: null,
|
|
64575
64878
|
credentials: stored
|
|
@@ -64591,7 +64894,7 @@ var GlmCodingPlanAdapter = class extends LlmAdapter {
|
|
|
64591
64894
|
}));
|
|
64592
64895
|
}
|
|
64593
64896
|
async resolveModel(provider, model, signal) {
|
|
64594
|
-
if (signal?.aborted) throw new LlmError(t("glm.modelResolveAborted", { provider: PROVIDER_NAME$1 }), "ABORTED");
|
|
64897
|
+
if (signal?.aborted) throw new LlmError$1(t("glm.modelResolveAborted", { provider: PROVIDER_NAME$1 }), "ABORTED");
|
|
64595
64898
|
const settings = await this.settings();
|
|
64596
64899
|
const region = await this.catalogRegion(settings) ?? "intl";
|
|
64597
64900
|
const entry = resolveGlmModel(model, this.catalog(region));
|
|
@@ -64660,8 +64963,8 @@ var GlmCodingPlanAdapter = class extends LlmAdapter {
|
|
|
64660
64963
|
});
|
|
64661
64964
|
activity?.pulse();
|
|
64662
64965
|
} catch (error) {
|
|
64663
|
-
if (signal.aborted) throw new LlmError(t("glm.requestAborted", { provider: PROVIDER_NAME$1 }), "ABORTED", { cause: error });
|
|
64664
|
-
throw new LlmError(t("glm.requestFailed", {
|
|
64966
|
+
if (signal.aborted) throw new LlmError$1(t("glm.requestAborted", { provider: PROVIDER_NAME$1 }), "ABORTED", { cause: error });
|
|
64967
|
+
throw new LlmError$1(t("glm.requestFailed", {
|
|
64665
64968
|
provider: PROVIDER_NAME$1,
|
|
64666
64969
|
detail: error instanceof Error ? error.message : String(error)
|
|
64667
64970
|
}), "TRANSPORT", { cause: error });
|
|
@@ -64701,8 +65004,8 @@ var GlmCodingPlanAdapter = class extends LlmAdapter {
|
|
|
64701
65004
|
throw failure;
|
|
64702
65005
|
}
|
|
64703
65006
|
const settled = plan;
|
|
64704
|
-
if (response === void 0) throw new LlmError(t("glm.noResponse", { provider: PROVIDER_NAME$1 }), "PROVIDER_ERROR");
|
|
64705
|
-
if (response.body === null) throw new LlmError(t("glm.emptyBody", { provider: PROVIDER_NAME$1 }), "PROVIDER_ERROR");
|
|
65007
|
+
if (response === void 0) throw new LlmError$1(t("glm.noResponse", { provider: PROVIDER_NAME$1 }), "PROVIDER_ERROR");
|
|
65008
|
+
if (response.body === null) throw new LlmError$1(t("glm.emptyBody", { provider: PROVIDER_NAME$1 }), "PROVIDER_ERROR");
|
|
64706
65009
|
const reader = response.body.getReader();
|
|
64707
65010
|
const decoder = new TextDecoder();
|
|
64708
65011
|
let buffer = "";
|
|
@@ -64725,7 +65028,7 @@ var GlmCodingPlanAdapter = class extends LlmAdapter {
|
|
|
64725
65028
|
buffer += decoder.decode();
|
|
64726
65029
|
if (buffer.trim() !== "") for (const line of buffer.split("\n")) for (const chunk of processGlmAnthropicStreamLine(line, state)) yield chunk;
|
|
64727
65030
|
if (state.finished) return;
|
|
64728
|
-
if (!glmStreamHasContent(state)) throw new LlmError(t("glm.anthropicEmpty", { provider: PROVIDER_NAME$1 }), "PROVIDER_ERROR");
|
|
65031
|
+
if (!glmStreamHasContent(state)) throw new LlmError$1(t("glm.anthropicEmpty", { provider: PROVIDER_NAME$1 }), "PROVIDER_ERROR");
|
|
64729
65032
|
assertGlmStreamComplete(state);
|
|
64730
65033
|
for (const chunk of closeGlmAnthropicStream(state)) yield chunk;
|
|
64731
65034
|
} finally {
|
|
@@ -69245,7 +69548,7 @@ var StepCodeAdapter = class extends LlmAdapter {
|
|
|
69245
69548
|
};
|
|
69246
69549
|
}
|
|
69247
69550
|
const stored = await this.store.read();
|
|
69248
|
-
if (stored === null) throw new LlmError("还没有登录 Step Code(Step Plan 订阅) 账号。请在设置页点击登录、在 stepcode 客户端登录后使用导入,或粘贴一个 Platform API Key。", "MISSING_CREDENTIAL");
|
|
69551
|
+
if (stored === null) throw new LlmError$1("还没有登录 Step Code(Step Plan 订阅) 账号。请在设置页点击登录、在 stepcode 客户端登录后使用导入,或粘贴一个 Platform API Key。", "MISSING_CREDENTIAL");
|
|
69249
69552
|
return {
|
|
69250
69553
|
accountId: null,
|
|
69251
69554
|
credentials: {
|
|
@@ -69297,7 +69600,7 @@ var StepCodeAdapter = class extends LlmAdapter {
|
|
|
69297
69600
|
}));
|
|
69298
69601
|
}
|
|
69299
69602
|
async resolveModel(provider, model, signal) {
|
|
69300
|
-
if (signal?.aborted) throw new LlmError(t("sc.modelResolveAborted", { provider: PROVIDER_NAME$6 }), "ABORTED");
|
|
69603
|
+
if (signal?.aborted) throw new LlmError$1(t("sc.modelResolveAborted", { provider: PROVIDER_NAME$6 }), "ABORTED");
|
|
69301
69604
|
const settings = await this.settings();
|
|
69302
69605
|
const picked = await this.credentialFor().catch(() => null);
|
|
69303
69606
|
const catalog = this.catalog(picked?.credentials.profile);
|
|
@@ -69367,8 +69670,8 @@ var StepCodeAdapter = class extends LlmAdapter {
|
|
|
69367
69670
|
});
|
|
69368
69671
|
activity?.pulse();
|
|
69369
69672
|
} catch (error) {
|
|
69370
|
-
if (signal.aborted) throw new LlmError(t("sc.requestAborted", { provider: PROVIDER_NAME$6 }), "ABORTED", { cause: error });
|
|
69371
|
-
throw new LlmError(t("sc.requestFailed", {
|
|
69673
|
+
if (signal.aborted) throw new LlmError$1(t("sc.requestAborted", { provider: PROVIDER_NAME$6 }), "ABORTED", { cause: error });
|
|
69674
|
+
throw new LlmError$1(t("sc.requestFailed", {
|
|
69372
69675
|
provider: PROVIDER_NAME$6,
|
|
69373
69676
|
detail: error instanceof Error ? error.message : String(error)
|
|
69374
69677
|
}), "TRANSPORT", { cause: error });
|
|
@@ -69394,8 +69697,8 @@ var StepCodeAdapter = class extends LlmAdapter {
|
|
|
69394
69697
|
}
|
|
69395
69698
|
throw failure;
|
|
69396
69699
|
}
|
|
69397
|
-
if (response === void 0) throw new LlmError(t("sc.noResponse", { provider: PROVIDER_NAME$6 }), "PROVIDER_ERROR");
|
|
69398
|
-
if (response.body === null) throw new LlmError(t("sc.emptyBody", { provider: PROVIDER_NAME$6 }), "PROVIDER_ERROR");
|
|
69700
|
+
if (response === void 0) throw new LlmError$1(t("sc.noResponse", { provider: PROVIDER_NAME$6 }), "PROVIDER_ERROR");
|
|
69701
|
+
if (response.body === null) throw new LlmError$1(t("sc.emptyBody", { provider: PROVIDER_NAME$6 }), "PROVIDER_ERROR");
|
|
69399
69702
|
const reader = response.body.getReader();
|
|
69400
69703
|
const decoder = new TextDecoder();
|
|
69401
69704
|
const state = createStreamState$2();
|
|
@@ -72872,7 +73175,7 @@ function serializeMessages(messages, images) {
|
|
|
72872
73175
|
* raised locally with the id that has no question.
|
|
72873
73176
|
*/
|
|
72874
73177
|
const answer = (callId, content) => {
|
|
72875
|
-
if (!awaiting.includes(callId)) throw new LlmError(`tool result for call "${callId}" has no tool_call awaiting it: the conversation cannot be expressed as a valid OpenAI message sequence`, "INVALID_REQUEST");
|
|
73178
|
+
if (!awaiting.includes(callId)) throw new LlmError$1(`tool result for call "${callId}" has no tool_call awaiting it: the conversation cannot be expressed as a valid OpenAI message sequence`, "INVALID_REQUEST");
|
|
72876
73179
|
wire.push({
|
|
72877
73180
|
role: "tool",
|
|
72878
73181
|
tool_call_id: callId,
|
|
@@ -73095,7 +73398,7 @@ async function* parseServerSentEvents$1(body) {
|
|
|
73095
73398
|
yield JSON.parse(payload);
|
|
73096
73399
|
} catch {}
|
|
73097
73400
|
}
|
|
73098
|
-
throw new LlmError("stream ended without [DONE]", "STREAM_CLOSED");
|
|
73401
|
+
throw new LlmError$1("stream ended without [DONE]", "STREAM_CLOSED");
|
|
73099
73402
|
}
|
|
73100
73403
|
/** Assemble the terminal content block for one open block. */
|
|
73101
73404
|
function closeBlock$1(block) {
|
|
@@ -73229,7 +73532,7 @@ async function* translate(payloads) {
|
|
|
73229
73532
|
return;
|
|
73230
73533
|
}
|
|
73231
73534
|
const chunk = unwrapEnvelope(payload);
|
|
73232
|
-
if (chunk.error !== void 0 && chunk.choices === void 0) throw new LlmError(errorText$1(chunk.error), streamErrorCode$1(errorText$1(chunk.error)));
|
|
73535
|
+
if (chunk.error !== void 0 && chunk.choices === void 0) throw new LlmError$1(errorText$1(chunk.error), streamErrorCode$1(errorText$1(chunk.error)));
|
|
73233
73536
|
const choices = Array.isArray(chunk.choices) ? chunk.choices : [];
|
|
73234
73537
|
for (const choice of choices) {
|
|
73235
73538
|
if (!isRecord$26(choice)) continue;
|
|
@@ -73304,7 +73607,7 @@ async function* translate(payloads) {
|
|
|
73304
73607
|
for (const chunk of closing()) yield chunk;
|
|
73305
73608
|
return;
|
|
73306
73609
|
}
|
|
73307
|
-
throw new LlmError("stream ended without [DONE]", "STREAM_CLOSED");
|
|
73610
|
+
throw new LlmError$1("stream ended without [DONE]", "STREAM_CLOSED");
|
|
73308
73611
|
}
|
|
73309
73612
|
//#endregion
|
|
73310
73613
|
//#region src/host/cline-pass/adapter.ts
|
|
@@ -73447,7 +73750,7 @@ var ClinePassAdapter = class extends LlmAdapter {
|
|
|
73447
73750
|
}));
|
|
73448
73751
|
}
|
|
73449
73752
|
async resolveModel(provider, modelId, signal) {
|
|
73450
|
-
if (signal?.aborted) throw new LlmError("Cline Pass model resolution aborted", "ABORTED");
|
|
73753
|
+
if (signal?.aborted) throw new LlmError$1("Cline Pass model resolution aborted", "ABORTED");
|
|
73451
73754
|
const info = await this.modelInfo(modelId);
|
|
73452
73755
|
return {
|
|
73453
73756
|
provider,
|
|
@@ -73474,10 +73777,10 @@ var ClinePassAdapter = class extends LlmAdapter {
|
|
|
73474
73777
|
yield* wrapStreamWithWatchdog((watchdogSignal, activity) => this.requestStream(options, settings, watchdogSignal, activity), options.signal, settings.streamIdleTimeoutMs, STREAM_IDLE_TIMEOUT_CODE$6, PROVIDER_NAME$5);
|
|
73475
73778
|
}
|
|
73476
73779
|
async *requestStream(rawOptions, settings, signal, activity) {
|
|
73477
|
-
if (settings.enabled === false) throw new LlmError(`${PROVIDER_NAME$5} is disabled in Settings > Subscription. Enable the line there, then retry.`, "INVALID_REQUEST");
|
|
73780
|
+
if (settings.enabled === false) throw new LlmError$1(`${PROVIDER_NAME$5} is disabled in Settings > Subscription. Enable the line there, then retry.`, "INVALID_REQUEST");
|
|
73478
73781
|
const normalized = normalizeGenerateOptions(rawOptions);
|
|
73479
73782
|
const images = await resolveRequestImages$1(normalized, this.options.attachments, signal).catch((error) => {
|
|
73480
|
-
if (signal.aborted) throw new LlmError("Cline Pass request aborted by caller", "ABORTED", { cause: error });
|
|
73783
|
+
if (signal.aborted) throw new LlmError$1("Cline Pass request aborted by caller", "ABORTED", { cause: error });
|
|
73481
73784
|
return NO_RESOLVED_IMAGES$3;
|
|
73482
73785
|
});
|
|
73483
73786
|
const options = offloadOldestRequestImages$1(normalized, void 0, images);
|
|
@@ -73514,7 +73817,7 @@ var ClinePassAdapter = class extends LlmAdapter {
|
|
|
73514
73817
|
try {
|
|
73515
73818
|
release = await this.gate.acquire(account.id, upstream);
|
|
73516
73819
|
} catch (error) {
|
|
73517
|
-
if (signal.aborted) throw new LlmError("Cline Pass request aborted by caller", "ABORTED", { cause: error });
|
|
73820
|
+
if (signal.aborted) throw new LlmError$1("Cline Pass request aborted by caller", "ABORTED", { cause: error });
|
|
73518
73821
|
throw error;
|
|
73519
73822
|
}
|
|
73520
73823
|
const attemptLabel = "(auto)";
|
|
@@ -73530,13 +73833,13 @@ var ClinePassAdapter = class extends LlmAdapter {
|
|
|
73530
73833
|
break;
|
|
73531
73834
|
} catch (error) {
|
|
73532
73835
|
headerDeadline.clear();
|
|
73533
|
-
if (signal.aborted) throw new LlmError("Cline Pass request aborted by caller", "ABORTED", { cause: error });
|
|
73836
|
+
if (signal.aborted) throw new LlmError$1("Cline Pass request aborted by caller", "ABORTED", { cause: error });
|
|
73534
73837
|
transportError = error;
|
|
73535
73838
|
if (transportTry < TRANSPORT_RETRIES$1 && isPreConnectionFailure$1(error)) {
|
|
73536
73839
|
try {
|
|
73537
73840
|
await setTimeout$1(TRANSPORT_RETRY_BASE_MS$1 * (transportTry + 1), void 0, { signal: upstream });
|
|
73538
73841
|
} catch (waitError) {
|
|
73539
|
-
if (signal.aborted) throw new LlmError("Cline Pass request aborted by caller", "ABORTED", { cause: waitError });
|
|
73842
|
+
if (signal.aborted) throw new LlmError$1("Cline Pass request aborted by caller", "ABORTED", { cause: waitError });
|
|
73540
73843
|
throw waitError;
|
|
73541
73844
|
}
|
|
73542
73845
|
continue;
|
|
@@ -73548,7 +73851,7 @@ var ClinePassAdapter = class extends LlmAdapter {
|
|
|
73548
73851
|
const note = errorChain$2(transportError);
|
|
73549
73852
|
const hint = isPreConnectionFailure$1(transportError) ? ` The request never reached the gateway: ${account.baseURL} failed during TLS/connect. Check the network, proxy or TUN, or set a custom proxy in the plugin.` : "";
|
|
73550
73853
|
trace.push(attemptLabel);
|
|
73551
|
-
lastError = new LlmError(note + hint, "TRANSPORT", { cause: transportError });
|
|
73854
|
+
lastError = new LlmError$1(note + hint, "TRANSPORT", { cause: transportError });
|
|
73552
73855
|
continue;
|
|
73553
73856
|
}
|
|
73554
73857
|
if (!response.ok) {
|
|
@@ -73559,7 +73862,7 @@ var ClinePassAdapter = class extends LlmAdapter {
|
|
|
73559
73862
|
} catch {}
|
|
73560
73863
|
trace.push(attemptLabel);
|
|
73561
73864
|
const code = streamErrorCode$1(detail, response.status);
|
|
73562
|
-
lastError = new LlmError(`${detail || `HTTP ${response.status}`} [model=${options.model}]`, code, { status: response.status });
|
|
73865
|
+
lastError = new LlmError$1(`${detail || `HTTP ${response.status}`} [model=${options.model}]`, code, { status: response.status });
|
|
73563
73866
|
if (code === "AUTH" || code === "QUOTA") {
|
|
73564
73867
|
refused.add(account.id);
|
|
73565
73868
|
await this.standDown(account.id, code, detail);
|
|
@@ -73578,7 +73881,7 @@ var ClinePassAdapter = class extends LlmAdapter {
|
|
|
73578
73881
|
continue;
|
|
73579
73882
|
}
|
|
73580
73883
|
if (response.body === null) {
|
|
73581
|
-
lastError = new LlmError("gateway returned no response body", "EMPTY_RESPONSE", { status: response.status });
|
|
73884
|
+
lastError = new LlmError$1("gateway returned no response body", "EMPTY_RESPONSE", { status: response.status });
|
|
73582
73885
|
continue;
|
|
73583
73886
|
}
|
|
73584
73887
|
const observed = {
|
|
@@ -73628,9 +73931,9 @@ var ClinePassAdapter = class extends LlmAdapter {
|
|
|
73628
73931
|
yield chunk;
|
|
73629
73932
|
}
|
|
73630
73933
|
} catch (error) {
|
|
73631
|
-
if (signal.aborted) throw new LlmError("Cline Pass request aborted by caller", "ABORTED", { cause: error });
|
|
73632
|
-
const note = error instanceof LlmError ? error.message : errorChain$2(error);
|
|
73633
|
-
const code = error instanceof LlmError ? error.code : "TRANSPORT";
|
|
73934
|
+
if (signal.aborted) throw new LlmError$1("Cline Pass request aborted by caller", "ABORTED", { cause: error });
|
|
73935
|
+
const note = error instanceof LlmError$1 ? error.message : errorChain$2(error);
|
|
73936
|
+
const code = error instanceof LlmError$1 ? error.code : "TRANSPORT";
|
|
73634
73937
|
trace.push(attemptLabel);
|
|
73635
73938
|
if (yielded) {
|
|
73636
73939
|
this.store.record({
|
|
@@ -73646,7 +73949,7 @@ var ClinePassAdapter = class extends LlmAdapter {
|
|
|
73646
73949
|
code,
|
|
73647
73950
|
account: account.name
|
|
73648
73951
|
});
|
|
73649
|
-
throw error instanceof LlmError ? error : new LlmError(note, "TRANSPORT", { cause: error });
|
|
73952
|
+
throw error instanceof LlmError$1 ? error : new LlmError$1(note, "TRANSPORT", { cause: error });
|
|
73650
73953
|
}
|
|
73651
73954
|
if (code === "AUTH" || code === "QUOTA") {
|
|
73652
73955
|
refused.add(account.id);
|
|
@@ -73666,7 +73969,7 @@ var ClinePassAdapter = class extends LlmAdapter {
|
|
|
73666
73969
|
account: account.name
|
|
73667
73970
|
});
|
|
73668
73971
|
}
|
|
73669
|
-
lastError = error instanceof LlmError ? error : new LlmError(note, "TRANSPORT", { cause: error });
|
|
73972
|
+
lastError = error instanceof LlmError$1 ? error : new LlmError$1(note, "TRANSPORT", { cause: error });
|
|
73670
73973
|
continue;
|
|
73671
73974
|
} finally {
|
|
73672
73975
|
consumer.abort("Cline Pass stream consumer stopped");
|
|
@@ -73678,7 +73981,7 @@ var ClinePassAdapter = class extends LlmAdapter {
|
|
|
73678
73981
|
try {
|
|
73679
73982
|
await setTimeout$1(EMPTY_REPLY_DELAY_MS, void 0, { signal });
|
|
73680
73983
|
} catch (waitError) {
|
|
73681
|
-
if (signal.aborted) throw new LlmError("Cline Pass request aborted by caller", "ABORTED", { cause: waitError });
|
|
73984
|
+
if (signal.aborted) throw new LlmError$1("Cline Pass request aborted by caller", "ABORTED", { cause: waitError });
|
|
73682
73985
|
throw waitError;
|
|
73683
73986
|
}
|
|
73684
73987
|
attemptIndex -= 1;
|
|
@@ -73740,7 +74043,7 @@ var ClinePassAdapter = class extends LlmAdapter {
|
|
|
73740
74043
|
error: message.slice(0, 200),
|
|
73741
74044
|
account: ""
|
|
73742
74045
|
});
|
|
73743
|
-
throw lastError ?? new LlmError(`${message} [model=${options.model}]`, "UPSTREAM");
|
|
74046
|
+
throw lastError ?? new LlmError$1(`${message} [model=${options.model}]`, "UPSTREAM");
|
|
73744
74047
|
}
|
|
73745
74048
|
}
|
|
73746
74049
|
/** Park an account that refused a request, for the reason it refused. */
|
|
@@ -79407,7 +79710,7 @@ var QoderAdapter = class extends LlmAdapter {
|
|
|
79407
79710
|
};
|
|
79408
79711
|
}
|
|
79409
79712
|
const stored = await this.store.read();
|
|
79410
|
-
if (stored === null) throw new LlmError("还没有登录 Qoder(订阅) 账号。请在设置页点击登录(全球区)、粘贴 PAT,或在本机 qodercli 登录后使用导入。", "MISSING_CREDENTIAL");
|
|
79713
|
+
if (stored === null) throw new LlmError$1("还没有登录 Qoder(订阅) 账号。请在设置页点击登录(全球区)、粘贴 PAT,或在本机 qodercli 登录后使用导入。", "MISSING_CREDENTIAL");
|
|
79411
79714
|
return {
|
|
79412
79715
|
accountId: null,
|
|
79413
79716
|
credentials: upstreamCredentialOf$1(stored)
|
|
@@ -79431,7 +79734,7 @@ var QoderAdapter = class extends LlmAdapter {
|
|
|
79431
79734
|
}));
|
|
79432
79735
|
}
|
|
79433
79736
|
async resolveModel(provider, model, signal) {
|
|
79434
|
-
if (signal?.aborted) throw new LlmError(t("qo.modelResolveAborted", { provider: PROVIDER_NAME$4 }), "ABORTED");
|
|
79737
|
+
if (signal?.aborted) throw new LlmError$1(t("qo.modelResolveAborted", { provider: PROVIDER_NAME$4 }), "ABORTED");
|
|
79435
79738
|
const settings = await this.settings();
|
|
79436
79739
|
const region = (await this.credentialFor().catch(() => null))?.credentials.region ?? "global";
|
|
79437
79740
|
const catalog = this.catalog(region);
|
|
@@ -79578,8 +79881,8 @@ var QoderAdapter = class extends LlmAdapter {
|
|
|
79578
79881
|
});
|
|
79579
79882
|
activity?.pulse();
|
|
79580
79883
|
} catch (error) {
|
|
79581
|
-
if (signal.aborted) throw new LlmError(t("qo.requestAborted", { provider: PROVIDER_NAME$4 }), "ABORTED", { cause: error });
|
|
79582
|
-
throw new LlmError(t("qo.requestFailed", {
|
|
79884
|
+
if (signal.aborted) throw new LlmError$1(t("qo.requestAborted", { provider: PROVIDER_NAME$4 }), "ABORTED", { cause: error });
|
|
79885
|
+
throw new LlmError$1(t("qo.requestFailed", {
|
|
79583
79886
|
provider: PROVIDER_NAME$4,
|
|
79584
79887
|
detail: error instanceof Error ? error.message : String(error)
|
|
79585
79888
|
}), "TRANSPORT", { cause: error });
|
|
@@ -79590,7 +79893,7 @@ var QoderAdapter = class extends LlmAdapter {
|
|
|
79590
79893
|
if (await handlePreContentFailure(failure, response.headers)) continue;
|
|
79591
79894
|
throw failure;
|
|
79592
79895
|
}
|
|
79593
|
-
if (response.body === null) throw new LlmError(t("qo.emptyBody", { provider: PROVIDER_NAME$4 }), "PROVIDER_ERROR");
|
|
79896
|
+
if (response.body === null) throw new LlmError$1(t("qo.emptyBody", { provider: PROVIDER_NAME$4 }), "PROVIDER_ERROR");
|
|
79594
79897
|
const reader = response.body.getReader();
|
|
79595
79898
|
const decoder = new TextDecoder();
|
|
79596
79899
|
const state = createQoderStreamState();
|
|
@@ -79626,7 +79929,7 @@ var QoderAdapter = class extends LlmAdapter {
|
|
|
79626
79929
|
}
|
|
79627
79930
|
return;
|
|
79628
79931
|
} catch (error) {
|
|
79629
|
-
if (!yielded && error instanceof LlmError) {
|
|
79932
|
+
if (!yielded && error instanceof LlmError$1) {
|
|
79630
79933
|
if (await handlePreContentFailure(error, response.headers)) continue;
|
|
79631
79934
|
}
|
|
79632
79935
|
throw error;
|
|
@@ -83562,7 +83865,7 @@ function serializeMessages$1(messages, images) {
|
|
|
83562
83865
|
};
|
|
83563
83866
|
/** A tool answer: it closes its own id, and the group when it was the last. */
|
|
83564
83867
|
const answer = (callId, content) => {
|
|
83565
|
-
if (!awaiting.includes(callId)) throw new LlmError(`OpenDesign request is invalid: the tool result for call id "${callId}" has no pending tool call to answer, so the message list would carry a tool message that no assistant tool_calls message introduced. Nothing was sent.`, "INVALID_REQUEST");
|
|
83868
|
+
if (!awaiting.includes(callId)) throw new LlmError$1(`OpenDesign request is invalid: the tool result for call id "${callId}" has no pending tool call to answer, so the message list would carry a tool message that no assistant tool_calls message introduced. Nothing was sent.`, "INVALID_REQUEST");
|
|
83566
83869
|
wire.push({
|
|
83567
83870
|
role: "tool",
|
|
83568
83871
|
tool_call_id: callId,
|
|
@@ -83914,7 +84217,7 @@ async function* parseServerSentEvents(body) {
|
|
|
83914
84217
|
yield JSON.parse(payload);
|
|
83915
84218
|
} catch {}
|
|
83916
84219
|
}
|
|
83917
|
-
throw new LlmError("stream ended without [DONE]", "STREAM_CLOSED");
|
|
84220
|
+
throw new LlmError$1("stream ended without [DONE]", "STREAM_CLOSED");
|
|
83918
84221
|
}
|
|
83919
84222
|
/**
|
|
83920
84223
|
* Whether one failure is the SSE parser's own "the body ended without [DONE]".
|
|
@@ -84050,7 +84353,7 @@ async function* translate$1(payloads) {
|
|
|
84050
84353
|
for (const chunk of terminal(reason)) yield chunk;
|
|
84051
84354
|
return;
|
|
84052
84355
|
}
|
|
84053
|
-
if (isErrorPayload(payload)) throw new LlmError(errorText(payload.error), streamErrorCode(errorText(payload.error)));
|
|
84356
|
+
if (isErrorPayload(payload)) throw new LlmError$1(errorText(payload.error), streamErrorCode(errorText(payload.error)));
|
|
84054
84357
|
const chunk = isRecord$17(payload) ? payload : {};
|
|
84055
84358
|
const choices = Array.isArray(chunk.choices) ? chunk.choices : [];
|
|
84056
84359
|
for (const choice of choices) {
|
|
@@ -84126,7 +84429,7 @@ async function* translate$1(payloads) {
|
|
|
84126
84429
|
for (const chunk of terminal(pendingFinish)) yield chunk;
|
|
84127
84430
|
return;
|
|
84128
84431
|
}
|
|
84129
|
-
throw new LlmError("stream ended without [DONE]", "STREAM_CLOSED");
|
|
84432
|
+
throw new LlmError$1("stream ended without [DONE]", "STREAM_CLOSED");
|
|
84130
84433
|
}
|
|
84131
84434
|
//#endregion
|
|
84132
84435
|
//#region src/host/opendesign/adapter.ts
|
|
@@ -84254,7 +84557,7 @@ var OpenDesignAdapter = class extends LlmAdapter {
|
|
|
84254
84557
|
}));
|
|
84255
84558
|
}
|
|
84256
84559
|
async resolveModel(provider, modelId, signal) {
|
|
84257
|
-
if (signal?.aborted) throw new LlmError("OpenDesign model resolution aborted", "ABORTED");
|
|
84560
|
+
if (signal?.aborted) throw new LlmError$1("OpenDesign model resolution aborted", "ABORTED");
|
|
84258
84561
|
const info = await this.modelInfo(modelId);
|
|
84259
84562
|
return {
|
|
84260
84563
|
provider,
|
|
@@ -84285,13 +84588,13 @@ var OpenDesignAdapter = class extends LlmAdapter {
|
|
|
84285
84588
|
}
|
|
84286
84589
|
/** The message the pool's empty state should raise, in this line's words. */
|
|
84287
84590
|
noAccountError(cause) {
|
|
84288
|
-
return new LlmError(`${PROVIDER_NAME$2} has no usable account: ${cause instanceof Error ? cause.message : String(cause)} Add an API key from the OpenDesign Cloud console in Settings > Subscription.`, "AUTH", { cause });
|
|
84591
|
+
return new LlmError$1(`${PROVIDER_NAME$2} has no usable account: ${cause instanceof Error ? cause.message : String(cause)} Add an API key from the OpenDesign Cloud console in Settings > Subscription.`, "AUTH", { cause });
|
|
84289
84592
|
}
|
|
84290
84593
|
async *requestStream(rawOptions, settings, signal, activity) {
|
|
84291
|
-
if (settings.enabled === false) throw new LlmError(`${PROVIDER_NAME$2} is disabled in Settings > Subscription. Enable the line there, then retry.`, "INVALID_REQUEST");
|
|
84594
|
+
if (settings.enabled === false) throw new LlmError$1(`${PROVIDER_NAME$2} is disabled in Settings > Subscription. Enable the line there, then retry.`, "INVALID_REQUEST");
|
|
84292
84595
|
const normalized = normalizeGenerateOptions(rawOptions);
|
|
84293
84596
|
const images = await resolveRequestImages$1(normalized, this.options.attachments, signal).catch((error) => {
|
|
84294
|
-
if (signal.aborted) throw new LlmError("OpenDesign request aborted by caller", "ABORTED", { cause: error });
|
|
84597
|
+
if (signal.aborted) throw new LlmError$1("OpenDesign request aborted by caller", "ABORTED", { cause: error });
|
|
84295
84598
|
return NO_RESOLVED_IMAGES$3;
|
|
84296
84599
|
});
|
|
84297
84600
|
const options = offloadOldestRequestImages$1(normalized, MAX_REQUEST_IMAGE_BYTES$1, images);
|
|
@@ -84316,7 +84619,7 @@ var OpenDesignAdapter = class extends LlmAdapter {
|
|
|
84316
84619
|
this.gate.setLimit(account.id, settings.maxConcurrentRequests);
|
|
84317
84620
|
release = await this.gate.acquire(account.id, upstream);
|
|
84318
84621
|
} catch (error) {
|
|
84319
|
-
if (signal.aborted) throw new LlmError("OpenDesign request aborted by caller", "ABORTED", { cause: error });
|
|
84622
|
+
if (signal.aborted) throw new LlmError$1("OpenDesign request aborted by caller", "ABORTED", { cause: error });
|
|
84320
84623
|
throw error;
|
|
84321
84624
|
}
|
|
84322
84625
|
try {
|
|
@@ -84337,13 +84640,13 @@ var OpenDesignAdapter = class extends LlmAdapter {
|
|
|
84337
84640
|
break;
|
|
84338
84641
|
} catch (error) {
|
|
84339
84642
|
headerDeadline.clear();
|
|
84340
|
-
if (signal.aborted) throw new LlmError("OpenDesign request aborted by caller", "ABORTED", { cause: error });
|
|
84643
|
+
if (signal.aborted) throw new LlmError$1("OpenDesign request aborted by caller", "ABORTED", { cause: error });
|
|
84341
84644
|
transportError = error;
|
|
84342
84645
|
if (transportTry < TRANSPORT_RETRIES && isPreConnectionFailure(error)) {
|
|
84343
84646
|
try {
|
|
84344
84647
|
await setTimeout$1(TRANSPORT_RETRY_BASE_MS * (transportTry + 1), void 0, { signal: upstream });
|
|
84345
84648
|
} catch (waitError) {
|
|
84346
|
-
if (signal.aborted) throw new LlmError("OpenDesign request aborted by caller", "ABORTED", { cause: waitError });
|
|
84649
|
+
if (signal.aborted) throw new LlmError$1("OpenDesign request aborted by caller", "ABORTED", { cause: waitError });
|
|
84347
84650
|
throw waitError;
|
|
84348
84651
|
}
|
|
84349
84652
|
continue;
|
|
@@ -84352,7 +84655,7 @@ var OpenDesignAdapter = class extends LlmAdapter {
|
|
|
84352
84655
|
}
|
|
84353
84656
|
}
|
|
84354
84657
|
if (response === void 0) {
|
|
84355
|
-
lastError = new LlmError(`${errorChain$1(transportError)} The request never reached the gateway: ${baseURL} failed during TLS/connect. Check the network or proxy.`, "TRANSPORT", { cause: transportError });
|
|
84658
|
+
lastError = new LlmError$1(`${errorChain$1(transportError)} The request never reached the gateway: ${baseURL} failed during TLS/connect. Check the network or proxy.`, "TRANSPORT", { cause: transportError });
|
|
84356
84659
|
break;
|
|
84357
84660
|
}
|
|
84358
84661
|
if (!response.ok) {
|
|
@@ -84367,7 +84670,7 @@ var OpenDesignAdapter = class extends LlmAdapter {
|
|
|
84367
84670
|
continue;
|
|
84368
84671
|
}
|
|
84369
84672
|
const code = streamErrorCode(detail, response.status);
|
|
84370
|
-
lastError = new LlmError(`${detail || `HTTP ${response.status}`} [model=${options.model}]`, code, { status: response.status });
|
|
84673
|
+
lastError = new LlmError$1(`${detail || `HTTP ${response.status}`} [model=${options.model}]`, code, { status: response.status });
|
|
84371
84674
|
if (code === "AUTH" || code === "QUOTA") {
|
|
84372
84675
|
refused.add(account.id);
|
|
84373
84676
|
await this.standDown(account.id, code, detail);
|
|
@@ -84380,7 +84683,7 @@ var OpenDesignAdapter = class extends LlmAdapter {
|
|
|
84380
84683
|
break;
|
|
84381
84684
|
}
|
|
84382
84685
|
if (response.body === null) {
|
|
84383
|
-
lastError = new LlmError("gateway returned no response body", "EMPTY_RESPONSE", { status: response.status });
|
|
84686
|
+
lastError = new LlmError$1("gateway returned no response body", "EMPTY_RESPONSE", { status: response.status });
|
|
84384
84687
|
break;
|
|
84385
84688
|
}
|
|
84386
84689
|
const iterator = translate$1(parseServerSentEvents(tapChunks(response.body, () => activity?.pulse())))[Symbol.asyncIterator]();
|
|
@@ -84393,17 +84696,17 @@ var OpenDesignAdapter = class extends LlmAdapter {
|
|
|
84393
84696
|
yield next.value;
|
|
84394
84697
|
}
|
|
84395
84698
|
} catch (error) {
|
|
84396
|
-
if (signal.aborted) throw new LlmError("OpenDesign request aborted by caller", "ABORTED", { cause: error });
|
|
84397
|
-
const note = error instanceof LlmError ? error.message : errorChain$1(error);
|
|
84398
|
-
const code = error instanceof LlmError ? error.code : "TRANSPORT";
|
|
84399
|
-
if (yielded) throw error instanceof LlmError ? error : new LlmError(note, "TRANSPORT", { cause: error });
|
|
84699
|
+
if (signal.aborted) throw new LlmError$1("OpenDesign request aborted by caller", "ABORTED", { cause: error });
|
|
84700
|
+
const note = error instanceof LlmError$1 ? error.message : errorChain$1(error);
|
|
84701
|
+
const code = error instanceof LlmError$1 ? error.code : "TRANSPORT";
|
|
84702
|
+
if (yielded) throw error instanceof LlmError$1 ? error : new LlmError$1(note, "TRANSPORT", { cause: error });
|
|
84400
84703
|
if (code === "AUTH" || code === "QUOTA") {
|
|
84401
84704
|
refused.add(account.id);
|
|
84402
84705
|
await this.standDown(account.id, code, note);
|
|
84403
|
-
lastError = error instanceof LlmError ? error : new LlmError(note, "TRANSPORT", { cause: error });
|
|
84706
|
+
lastError = error instanceof LlmError$1 ? error : new LlmError$1(note, "TRANSPORT", { cause: error });
|
|
84404
84707
|
continue;
|
|
84405
84708
|
}
|
|
84406
|
-
lastError = error instanceof LlmError ? error : new LlmError(note, "TRANSPORT", { cause: error });
|
|
84709
|
+
lastError = error instanceof LlmError$1 ? error : new LlmError$1(note, "TRANSPORT", { cause: error });
|
|
84407
84710
|
break;
|
|
84408
84711
|
} finally {
|
|
84409
84712
|
consumer.abort("OpenDesign stream consumer stopped");
|
|
@@ -84415,7 +84718,7 @@ var OpenDesignAdapter = class extends LlmAdapter {
|
|
|
84415
84718
|
release();
|
|
84416
84719
|
}
|
|
84417
84720
|
}
|
|
84418
|
-
throw lastError ?? new LlmError(`no account could serve the request [model=${options.model}]`, "UPSTREAM");
|
|
84721
|
+
throw lastError ?? new LlmError$1(`no account could serve the request [model=${options.model}]`, "UPSTREAM");
|
|
84419
84722
|
}
|
|
84420
84723
|
/** Park an account that refused a request, for the reason it refused. */
|
|
84421
84724
|
async standDown(accountId, code, detail) {
|
|
@@ -89373,6 +89676,31 @@ function installCompactionPolicyGuard(ctx, options = {}) {
|
|
|
89373
89676
|
if (isRecord$11(optionsField)) observe(readString(optionsField["provider"]), readString(optionsField["model"]));
|
|
89374
89677
|
const config = source["config"];
|
|
89375
89678
|
if (isRecord$11(config)) observe(readString(config["provider"]), readString(config["model"]));
|
|
89679
|
+
const modelField = source["model"];
|
|
89680
|
+
if (isRecord$11(modelField) && typeof modelField["current"] === "function") {
|
|
89681
|
+
let current;
|
|
89682
|
+
try {
|
|
89683
|
+
current = modelField["current"].call(modelField);
|
|
89684
|
+
} catch {
|
|
89685
|
+
current = void 0;
|
|
89686
|
+
}
|
|
89687
|
+
if (isRecord$11(current)) observe(readString(current["provider"]), readString(current["model"]));
|
|
89688
|
+
}
|
|
89689
|
+
const messages = source["messages"];
|
|
89690
|
+
if (Array.isArray(messages)) for (let i = messages.length - 1; i >= 0; i -= 1) {
|
|
89691
|
+
const msg = messages[i];
|
|
89692
|
+
if (!isRecord$11(msg)) continue;
|
|
89693
|
+
const role = msg["role"];
|
|
89694
|
+
if (role !== void 0 && role !== "assistant") continue;
|
|
89695
|
+
const msgSource = msg["source"];
|
|
89696
|
+
if (!isRecord$11(msgSource)) continue;
|
|
89697
|
+
const provider = readString(msgSource["provider"]);
|
|
89698
|
+
const model = readString(msgSource["model"]);
|
|
89699
|
+
if (provider !== void 0 && model !== void 0) {
|
|
89700
|
+
observe(provider, model);
|
|
89701
|
+
break;
|
|
89702
|
+
}
|
|
89703
|
+
}
|
|
89376
89704
|
};
|
|
89377
89705
|
/**
|
|
89378
89706
|
* 读一个字符串字段。
|
|
@@ -93256,7 +93584,7 @@ Determine tier by semantic impact and uncertainty (write a brief "Tier + Rationa
|
|
|
93256
93584
|
- L1 Moderate: unambiguous module-local or mechanical multi-file work; edits at most 5 files (5 is a cap, not a range and not a target), no external contract break or unsettled product/UI decision, at most 2 open points. -> Ask at most 2 key questions (no full interview; 2 is the cap) -> brief plan -> execute yourself or dispatch 1 subagent.
|
|
93257
93585
|
- L2 Complex / Multi-step: cross-module/contract changes, multi-part work, unsettled decisions, or major irreversible risk. -> L2-Clear (settled, reversible): brief decision-complete plan -> R1 -> R6, without full interview/Plan Mode. L2-Governed (unsettled product/UI/external contract or major irreversible risk): R-G Interview -> R9 Plan & Approval -> R1 -> R6.
|
|
93258
93586
|
- [Stop by Impact, Not by Effort] Within Boundary, a subagent fixes all affected call sites, types, and tests, but pauses with status: hand_back immediately if a change would break an external contract, alter cross-module responsibilities, or require an unsettled product/UI decision—even for a single line.
|
|
93259
|
-
- [Execution Economy] Use one cheap probe, the smallest complete change, batched independent
|
|
93587
|
+
- [Execution Economy] Use one cheap probe, the smallest complete change, batched reads of known, independent paths (probe before reading unknown paths), and incremental edits; with no code/config change since a check passed, do not re-run that same equivalent check (still run distinct unexecuted checks such as typecheck/build). Stop after at most 2 consecutive model steps without progress to change approach or escalate; re-triage if complexity grows mid-task.
|
|
93260
93588
|
|
|
93261
93589
|
## R-G · Clarification Interview (L2-Governed Only, Before R9)
|
|
93262
93590
|
- G1 Design Tree & G2 Frontier: Model requirements as a decision dependency tree; ask the entire current frontier (decisions whose prerequisites are settled) in one round, wait for answers, and recompute. Never ask one question per round or dependent questions together.
|
|
@@ -93287,7 +93615,7 @@ Every task brief covers six elements: Goal / Boundary / Constraints / Limits (se
|
|
|
93287
93615
|
- [Limits] Each override states **what it bounds, in what unit, the cap, and whether it accumulates**. Use explicit caps ("at most 3 runs", "edits at most 5 files"), never ranges ("2–5 files"); silence is read as a limit of zero, and a quota that resets per cycle is lost, not banked. Do not ask the child to restate your rules back as a correctness check. Dispatch independent tasks concurrently through code_run Promise.all once decisions are settled.
|
|
93288
93616
|
|
|
93289
93617
|
## R6 · Lead Acceptance
|
|
93290
|
-
One acceptance layer owned by Lead: subagents supply implementation/evidence; Lead reads the final diff, checks every criterion, and runs risk-relevant verification. The completion notification is a post-hoc signal: a child stopped, not that the work passed.
|
|
93618
|
+
One acceptance layer owned by Lead: subagents supply implementation/evidence; Lead reads the final diff, checks every criterion, and runs risk-relevant verification without re-running an already-passed equivalent check when no code/config changed. The completion notification is a post-hoc signal: a child stopped, not that the work passed.
|
|
93291
93619
|
- Re-dispatch budget per brief: 1 first attempt + at most 2 re-dispatches = at most 3 runs total. Count runs, not failures; the number belongs in the task list item for that brief (R7). Only after the third run ends without acceptance, transition to R8 Fallback.
|
|
93292
93620
|
- [Non-Penalized hand_back] Clean status: hand_back with a valid hand_back_reason and no out-of-boundary mutation does not increment a failure count or trigger R8 by itself (each run still counts toward the 3-run cap). Re-scope or answer via send_message({ agent }) on the existing child to preserve its warm prefix cache.
|
|
93293
93621
|
- [Noticed but not handled] Every defect found in review: the defect goes back out on a re-dispatch with evidence or goes to the user via R-W (or fix and re-verify on Lead-Core/Hybrid core). Writing it into the delivery summary and shipping anyway is not an available outcome.
|
|
@@ -95140,6 +95468,8 @@ function pageValue(raw, refId, sessionId) {
|
|
|
95140
95468
|
const nextOffset = complete ? void 0 : numberOf$2(page.nextOffset);
|
|
95141
95469
|
const omitted = omittedCharsOf(page.omitted);
|
|
95142
95470
|
const totalChars = numberOf$2(page.totalChars);
|
|
95471
|
+
const matched = booleanOf$1(page.matched);
|
|
95472
|
+
const matchOffset = numberOf$2(page.matchOffset);
|
|
95143
95473
|
return {
|
|
95144
95474
|
ok: true,
|
|
95145
95475
|
action: "page",
|
|
@@ -95150,6 +95480,8 @@ function pageValue(raw, refId, sessionId) {
|
|
|
95150
95480
|
...nextOffset === void 0 ? {} : { nextOffset },
|
|
95151
95481
|
...omitted === void 0 ? {} : { omitted },
|
|
95152
95482
|
...totalChars === void 0 ? {} : { totalChars },
|
|
95483
|
+
...matched === void 0 ? {} : { matched },
|
|
95484
|
+
...matchOffset === void 0 ? {} : { matchOffset },
|
|
95153
95485
|
...text === void 0 ? {} : {
|
|
95154
95486
|
text,
|
|
95155
95487
|
chars: text.length
|
|
@@ -95172,7 +95504,7 @@ function createCacheWarmupResultTool(deps) {
|
|
|
95172
95504
|
name: CACHE_WARMUP_RESULT_TOOL,
|
|
95173
95505
|
description: [
|
|
95174
95506
|
"Read back a result that was replaced by a preview, using the `ref://<session>/<sha256>` handle written in that preview.",
|
|
95175
|
-
"Use `action: \"page\"` to read a slice: pass `offset
|
|
95507
|
+
"Use `action: \"page\"` to read a slice: pass `offset` (or `query` to locate a literal substring in text results), and optionally `limit`, `maxBytes`, `fields` and `equals`.",
|
|
95176
95508
|
"Keep slices small (a page defaults to 64 lines / 16 KB and is capped at 25 KB): every character a page returns is processed again on the next turn, so read only the slice you need.",
|
|
95177
95509
|
"Every page reports `complete`, `nextOffset`, `omitted` and `totalChars`, so you can see whether more remains instead of assuming a slice is the whole thing.",
|
|
95178
95510
|
"Use `action: \"release\"` when the stored copy is no longer needed."
|
|
@@ -95193,9 +95525,13 @@ function createCacheWarmupResultTool(deps) {
|
|
|
95193
95525
|
type: "integer",
|
|
95194
95526
|
description: "Where to start: a UTF-8 byte offset for text results, a row index for structured ones."
|
|
95195
95527
|
},
|
|
95528
|
+
query: {
|
|
95529
|
+
type: "string",
|
|
95530
|
+
description: "Case-sensitive literal substring to locate in a text result starting from `offset` (default 0); returns a page starting at the matched line, or `matched: false` when absent."
|
|
95531
|
+
},
|
|
95196
95532
|
limit: {
|
|
95197
95533
|
type: "integer",
|
|
95198
|
-
description: "Maximum number of
|
|
95534
|
+
description: "Maximum number of lines (text) or rows (structured) in this page."
|
|
95199
95535
|
},
|
|
95200
95536
|
maxBytes: {
|
|
95201
95537
|
type: "integer",
|
|
@@ -95258,6 +95594,14 @@ function createCacheWarmupResultTool(deps) {
|
|
|
95258
95594
|
type: "number",
|
|
95259
95595
|
description: "Characters in the whole stored result."
|
|
95260
95596
|
},
|
|
95597
|
+
matched: {
|
|
95598
|
+
type: "boolean",
|
|
95599
|
+
description: "Whether `query` matched in a text result."
|
|
95600
|
+
},
|
|
95601
|
+
matchOffset: {
|
|
95602
|
+
type: "number",
|
|
95603
|
+
description: "UTF-8 byte offset of the first `query` match."
|
|
95604
|
+
},
|
|
95261
95605
|
released: {
|
|
95262
95606
|
type: "boolean",
|
|
95263
95607
|
description: "Whether a stored copy was actually released."
|
|
@@ -95296,13 +95640,18 @@ function createCacheWarmupResultTool(deps) {
|
|
|
95296
95640
|
text: value.released === true ? "Released " + value.refId + ". The preview in your history is unchanged; it can no longer be read back." : "Nothing stored for " + value.refId + "; nothing to release."
|
|
95297
95641
|
}];
|
|
95298
95642
|
const at = value.offset ?? 0;
|
|
95299
|
-
const span = typeof value.chars === "number" ? value.chars + " chars" : "no content";
|
|
95300
95643
|
const total = typeof value.totalChars === "number" ? " of " + value.totalChars : "";
|
|
95644
|
+
if (value.matched === false) return [{
|
|
95645
|
+
type: "text",
|
|
95646
|
+
text: value.refId + " from offset " + at + " — no match found" + total + ", complete\n\n(no match)"
|
|
95647
|
+
}];
|
|
95648
|
+
const span = typeof value.chars === "number" ? value.chars + " chars" : "no content";
|
|
95649
|
+
const matchNote = value.matched === true && typeof value.matchOffset === "number" ? " (matched at offset " + value.matchOffset + ")" : "";
|
|
95301
95650
|
const tail = value.complete === true ? "complete" : "more remains" + (typeof value.nextOffset === "number" ? ", continue at offset " + value.nextOffset : "") + (typeof value.omitted === "number" ? ", " + value.omitted + " chars omitted" : "");
|
|
95302
95651
|
const body = typeof value.text === "string" && value.text !== "" ? value.text : "(empty page)";
|
|
95303
95652
|
return [{
|
|
95304
95653
|
type: "text",
|
|
95305
|
-
text: value.refId + " from offset " + at + " — " + span + total + ", " + tail + "\n\n" + body
|
|
95654
|
+
text: value.refId + " from offset " + at + matchNote + " — " + span + total + ", " + tail + "\n\n" + body
|
|
95306
95655
|
}];
|
|
95307
95656
|
}
|
|
95308
95657
|
},
|
|
@@ -95345,11 +95694,13 @@ function createCacheWarmupResultTool(deps) {
|
|
|
95345
95694
|
["limit", args.limit],
|
|
95346
95695
|
["maxBytes", args.maxBytes]
|
|
95347
95696
|
]) if (value !== void 0 && !isCount(value)) return failure(action, refId, sessionId, "BAD_ARGUMENT", name + " must be a non-negative integer");
|
|
95697
|
+
if (args.query !== void 0 && (typeof args.query !== "string" || args.query === "")) return failure(action, refId, sessionId, "BAD_ARGUMENT", "query must be a non-empty string");
|
|
95348
95698
|
const request = {
|
|
95349
95699
|
sessionId,
|
|
95350
95700
|
refId
|
|
95351
95701
|
};
|
|
95352
95702
|
if (args.offset !== void 0) request.offset = args.offset;
|
|
95703
|
+
if (args.query !== void 0) request.query = args.query;
|
|
95353
95704
|
if (args.limit !== void 0) request.limit = args.limit;
|
|
95354
95705
|
if (args.maxBytes !== void 0) request.maxBytes = args.maxBytes;
|
|
95355
95706
|
if (args.fields !== void 0) request.fields = args.fields;
|
|
@@ -95485,7 +95836,7 @@ const CACHE_WARMUP_GUIDANCE = [
|
|
|
95485
95836
|
"On large `run_code`/`code_run` results this line may replace the output with a preview: a short description plus one or more `ref://<session>/<sha256>` handles.",
|
|
95486
95837
|
"",
|
|
95487
95838
|
"- A preview is **not** the full result. It states `complete`, `omitted` and `nextOffset` explicitly; treat an incomplete preview as incomplete data, not as the whole output.",
|
|
95488
|
-
"- To read the original, call `cache_warmup_result` with `action: \"page\"` and that `refId
|
|
95839
|
+
"- To read the original, call `cache_warmup_result` with `action: \"page\"` and that `refId` (pass `query` to jump directly to a literal keyword/error in text logs, or follow `offset` / `nextOffset` until `complete` is true).",
|
|
95489
95840
|
"- Page in small slices (`limit` around 64-120 lines, `maxBytes` at most 8-16 KB) and read only the slice you actually need. Reading a whole stored result back in one call re-sends what the preview just saved.",
|
|
95490
95841
|
"- `action: \"release\"` drops the stored copy. The preview already in the conversation stays identical; it simply can no longer be read back.",
|
|
95491
95842
|
"- Source code, type and contract definitions, mixed evidence and anything that could not be parsed reliably are never replaced: they arrive in full.",
|
|
@@ -101036,11 +101387,11 @@ async function refreshCredentials(credentials, options = {}) {
|
|
|
101036
101387
|
const text = await response.text().catch(() => "");
|
|
101037
101388
|
if (!response.ok) {
|
|
101038
101389
|
const detail = text.slice(0, 200);
|
|
101039
|
-
throw new LlmError(`${PROVIDER_NAME$3} token refresh failed (${response.status})${detail ? `: ${detail}` : ""}`, response.status === 401 || response.status === 403 ? "INVALID_CREDENTIAL" : "TRANSPORT", { status: response.status });
|
|
101390
|
+
throw new LlmError$1(`${PROVIDER_NAME$3} token refresh failed (${response.status})${detail ? `: ${detail}` : ""}`, response.status === 401 || response.status === 403 ? "INVALID_CREDENTIAL" : "TRANSPORT", { status: response.status });
|
|
101040
101391
|
}
|
|
101041
101392
|
const payload = asRecord(JSON.parse(text));
|
|
101042
101393
|
const data = asRecord(payload?.data);
|
|
101043
|
-
if (payload === void 0 || payload.code !== 0 || data === void 0) throw new LlmError(`${PROVIDER_NAME$3} token refresh was rejected: ${asString(payload?.msg) ?? "no detail"}`, "INVALID_CREDENTIAL");
|
|
101394
|
+
if (payload === void 0 || payload.code !== 0 || data === void 0) throw new LlmError$1(`${PROVIDER_NAME$3} token refresh was rejected: ${asString(payload?.msg) ?? "no detail"}`, "INVALID_CREDENTIAL");
|
|
101044
101395
|
const accessToken = asString(data.accessToken);
|
|
101045
101396
|
if (accessToken === void 0) throw new Error(`${PROVIDER_NAME$3} token refresh returned no access token`);
|
|
101046
101397
|
const expiresIn = asNumber(data.expiresIn);
|
|
@@ -101673,7 +102024,7 @@ var WorkBuddyAdapter = class extends LlmAdapter {
|
|
|
101673
102024
|
}));
|
|
101674
102025
|
}
|
|
101675
102026
|
async resolveModel(provider, modelId, signal) {
|
|
101676
|
-
if (signal?.aborted) throw new LlmError("WorkBuddy model resolution aborted", "ABORTED");
|
|
102027
|
+
if (signal?.aborted) throw new LlmError$1("WorkBuddy model resolution aborted", "ABORTED");
|
|
101677
102028
|
const settings = await this.settings();
|
|
101678
102029
|
const credentials = await this.credentials(settings);
|
|
101679
102030
|
const catalog = credentials === null ? FALLBACK_MODELS$1 : await this.catalog(credentials);
|
|
@@ -101804,7 +102155,7 @@ var WorkBuddyAdapter = class extends LlmAdapter {
|
|
|
101804
102155
|
if (pool === null) {
|
|
101805
102156
|
const currentSettings = await this.settings();
|
|
101806
102157
|
const stored = await this.credentials(currentSettings);
|
|
101807
|
-
if (stored === null) throw new LlmError(`Not signed in to ${PROVIDER_NAME$3}. Sign in with the CodeBuddy desktop client; this route reads its credential from the local auth directory.`, "MISSING_CREDENTIAL");
|
|
102158
|
+
if (stored === null) throw new LlmError$1(`Not signed in to ${PROVIDER_NAME$3}. Sign in with the CodeBuddy desktop client; this route reads its credential from the local auth directory.`, "MISSING_CREDENTIAL");
|
|
101808
102159
|
credentials = await this.store.ensureFresh(stored, (current) => refreshCredentials(current, { fetchFn }));
|
|
101809
102160
|
} else {
|
|
101810
102161
|
let effective;
|
|
@@ -101812,8 +102163,8 @@ var WorkBuddyAdapter = class extends LlmAdapter {
|
|
|
101812
102163
|
effective = await pool.getEffectiveCredential(tried, fetchFn, options.model);
|
|
101813
102164
|
} catch (error) {
|
|
101814
102165
|
if (isPoolPausedError(error)) throw error;
|
|
101815
|
-
if (error instanceof LlmError) throw error;
|
|
101816
|
-
throw new LlmError(error instanceof Error ? error.message : `Not signed in to ${PROVIDER_NAME$3}.`, "MISSING_CREDENTIAL", { cause: error });
|
|
102166
|
+
if (error instanceof LlmError$1) throw error;
|
|
102167
|
+
throw new LlmError$1(error instanceof Error ? error.message : `Not signed in to ${PROVIDER_NAME$3}.`, "MISSING_CREDENTIAL", { cause: error });
|
|
101817
102168
|
}
|
|
101818
102169
|
accountId = effective.account.id;
|
|
101819
102170
|
servedAccountId = accountId;
|
|
@@ -101855,8 +102206,8 @@ var WorkBuddyAdapter = class extends LlmAdapter {
|
|
|
101855
102206
|
});
|
|
101856
102207
|
activity?.pulse();
|
|
101857
102208
|
} catch (error) {
|
|
101858
|
-
if (signal.aborted) throw new LlmError("WorkBuddy request aborted", "ABORTED", { cause: error });
|
|
101859
|
-
throw new LlmError(`WorkBuddy request failed: ${error instanceof Error ? error.message : String(error)}`, "TRANSPORT", { cause: error });
|
|
102209
|
+
if (signal.aborted) throw new LlmError$1("WorkBuddy request aborted", "ABORTED", { cause: error });
|
|
102210
|
+
throw new LlmError$1(`WorkBuddy request failed: ${error instanceof Error ? error.message : String(error)}`, "TRANSPORT", { cause: error });
|
|
101860
102211
|
}
|
|
101861
102212
|
if (response.ok) break;
|
|
101862
102213
|
refusedStatus = response.status;
|
|
@@ -101885,7 +102236,7 @@ var WorkBuddyAdapter = class extends LlmAdapter {
|
|
|
101885
102236
|
credentials = pool !== null && accountId !== void 0 ? await pool.renewCredential(accountId, fetchFn, credentials) : await this.store.renew(credentials, (current) => refreshCredentials(current, { fetchFn }));
|
|
101886
102237
|
} catch (error) {
|
|
101887
102238
|
if (isPoolPausedError(error)) throw error;
|
|
101888
|
-
const verdict = error instanceof LlmError ? error : new LlmError(`${PROVIDER_NAME$3} credential could not be renewed after the service refused it: ${error instanceof Error ? error.message : String(error)}`, "INVALID_CREDENTIAL", { cause: error });
|
|
102239
|
+
const verdict = error instanceof LlmError$1 ? error : new LlmError$1(`${PROVIDER_NAME$3} credential could not be renewed after the service refused it: ${error instanceof Error ? error.message : String(error)}`, "INVALID_CREDENTIAL", { cause: error });
|
|
101889
102240
|
if (pool !== null && await pool.hasAnotherAvailableAccount(tried)) continue rotation;
|
|
101890
102241
|
throw verdict;
|
|
101891
102242
|
}
|
|
@@ -101921,8 +102272,8 @@ var WorkBuddyAdapter = class extends LlmAdapter {
|
|
|
101921
102272
|
}
|
|
101922
102273
|
throw failure;
|
|
101923
102274
|
}
|
|
101924
|
-
if (response === void 0) throw new LlmError("WorkBuddy produced no response", "PROVIDER_ERROR");
|
|
101925
|
-
if (response.body === null) throw new LlmError("WorkBuddy returned an empty response body", "PROVIDER_ERROR");
|
|
102275
|
+
if (response === void 0) throw new LlmError$1("WorkBuddy produced no response", "PROVIDER_ERROR");
|
|
102276
|
+
if (response.body === null) throw new LlmError$1("WorkBuddy returned an empty response body", "PROVIDER_ERROR");
|
|
101926
102277
|
const recorded = { tokens: 0 };
|
|
101927
102278
|
try {
|
|
101928
102279
|
if (servedProtocol === "anthropic-messages") {
|
|
@@ -102019,7 +102370,7 @@ const SIGNATURE_REFUSED_CODE = 11159;
|
|
|
102019
102370
|
* from the service, and no retry can help.
|
|
102020
102371
|
*/
|
|
102021
102372
|
function accountRestrictedFailure(detail, status) {
|
|
102022
|
-
return new LlmError(`${PROVIDER_NAME$3} barred this account (11140): the subscription refused to serve it at all, which is not a model park and not a usage window. Every model of this account is affected; use another account or have this one released by the service.${detail ? ` ${detail}` : ""}`, "ACCOUNT_RESTRICTED", { status });
|
|
102373
|
+
return new LlmError$1(`${PROVIDER_NAME$3} barred this account (11140): the subscription refused to serve it at all, which is not a model park and not a usage window. Every model of this account is affected; use another account or have this one released by the service.${detail ? ` ${detail}` : ""}`, "ACCOUNT_RESTRICTED", { status });
|
|
102023
102374
|
}
|
|
102024
102375
|
/**
|
|
102025
102376
|
* Map one failed HTTP response onto a DSH failure.
|
|
@@ -102032,27 +102383,27 @@ function accountRestrictedFailure(detail, status) {
|
|
|
102032
102383
|
function classifyFailure$1(status, detail, headers) {
|
|
102033
102384
|
const code = readErrorCode(detail);
|
|
102034
102385
|
if (status === 401) {
|
|
102035
|
-
if (!namesRejectedCredential(detail)) return new LlmError(`${PROVIDER_NAME$3} refused this request once (401), and neither the renewed credential nor the replay changed that answer. The sign-in was NOT marked invalid: this endpoint also refuses a valid bearer, so a dead credential needs the token endpoint's own word before it is recorded.${detail ? ` ${detail}` : ""}`, "PROVIDER_ERROR", { status });
|
|
102036
|
-
return new LlmError(`${PROVIDER_NAME$3} rejected the stored credential (401). Sign in again with the CodeBuddy desktop client.${detail ? ` ${detail}` : ""}`, "INVALID_CREDENTIAL", { status });
|
|
102386
|
+
if (!namesRejectedCredential(detail)) return new LlmError$1(`${PROVIDER_NAME$3} refused this request once (401), and neither the renewed credential nor the replay changed that answer. The sign-in was NOT marked invalid: this endpoint also refuses a valid bearer, so a dead credential needs the token endpoint's own word before it is recorded.${detail ? ` ${detail}` : ""}`, "PROVIDER_ERROR", { status });
|
|
102387
|
+
return new LlmError$1(`${PROVIDER_NAME$3} rejected the stored credential (401). Sign in again with the CodeBuddy desktop client.${detail ? ` ${detail}` : ""}`, "INVALID_CREDENTIAL", { status });
|
|
102037
102388
|
}
|
|
102038
102389
|
if (status === 403) {
|
|
102039
|
-
if (refusalIsNotCredential(detail)) return new LlmError(`${PROVIDER_NAME$3} refused this request (403) before it reached the model: the refusal did not name a rejected credential, so it most likely came from a proxy, a gateway rule or another component on this lane rather than from the subscription. The stored credential was left untouched.${detail ? ` ${detail}` : ""}`, "PROVIDER_ERROR", { status });
|
|
102040
|
-
return new LlmError(`${PROVIDER_NAME$3} rejected the stored credential (${status}). Sign in again with the CodeBuddy desktop client.${detail ? ` ${detail}` : ""}`, "INVALID_CREDENTIAL", { status });
|
|
102390
|
+
if (refusalIsNotCredential(detail)) return new LlmError$1(`${PROVIDER_NAME$3} refused this request (403) before it reached the model: the refusal did not name a rejected credential, so it most likely came from a proxy, a gateway rule or another component on this lane rather than from the subscription. The stored credential was left untouched.${detail ? ` ${detail}` : ""}`, "PROVIDER_ERROR", { status });
|
|
102391
|
+
return new LlmError$1(`${PROVIDER_NAME$3} rejected the stored credential (${status}). Sign in again with the CodeBuddy desktop client.${detail ? ` ${detail}` : ""}`, "INVALID_CREDENTIAL", { status });
|
|
102041
102392
|
}
|
|
102042
102393
|
if (status === 429 || code === 6004 || code === 14003) {
|
|
102043
102394
|
const after = (headers ? retryAfterMs$1(headers) : void 0) ?? readRateLimitReset(detail);
|
|
102044
|
-
return new LlmError(`${PROVIDER_NAME$3} rate limit or plan quota reached. Check the quota card in Settings > WorkBuddy.${detail ? ` ${detail}` : ""}`, "RATE_LIMIT", {
|
|
102395
|
+
return new LlmError$1(`${PROVIDER_NAME$3} rate limit or plan quota reached. Check the quota card in Settings > WorkBuddy.${detail ? ` ${detail}` : ""}`, "RATE_LIMIT", {
|
|
102045
102396
|
status: status === 429 ? 429 : void 0,
|
|
102046
102397
|
...after === void 0 ? {} : { providerRetryAfterMs: after }
|
|
102047
102398
|
});
|
|
102048
102399
|
}
|
|
102049
|
-
if (code === 11102) return new LlmError(`${PROVIDER_NAME$3} does not serve this model for the signed-in account: it is either unavailable in the account's region or not included in its plan. Pick a different model in Settings > WorkBuddy.${detail ? ` ${detail}` : ""}`, "PROVIDER_ERROR", { status });
|
|
102050
|
-
if (code === 11135 || code === 11133) return new LlmError(`${PROVIDER_NAME$3} rejected the request parameters (${code}). An image may be unsupported by this model or unreadable.${detail ? ` ${detail}` : ""}`, "PROVIDER_ERROR", { status });
|
|
102400
|
+
if (code === 11102) return new LlmError$1(`${PROVIDER_NAME$3} does not serve this model for the signed-in account: it is either unavailable in the account's region or not included in its plan. Pick a different model in Settings > WorkBuddy.${detail ? ` ${detail}` : ""}`, "PROVIDER_ERROR", { status });
|
|
102401
|
+
if (code === 11135 || code === 11133) return new LlmError$1(`${PROVIDER_NAME$3} rejected the request parameters (${code}). An image may be unsupported by this model or unreadable.${detail ? ` ${detail}` : ""}`, "PROVIDER_ERROR", { status });
|
|
102051
102402
|
if (code === ERROR_CODE.ACCOUNT_RESTRICTED) return accountRestrictedFailure(detail, status);
|
|
102052
|
-
if (code === SIGNATURE_REFUSED_CODE) return new LlmError(`${PROVIDER_NAME$3} refused a thinking block's signature (11159). A replayed reasoning block whose signature this route did not produce cannot be verified, so it has to be dropped rather than replayed.${detail ? ` ${detail}` : ""}`, "PROVIDER_ERROR", { status });
|
|
102053
|
-
if (code === 11128) return new LlmError(/conversation id|unapproved channel/i.test(detail) ? `${PROVIDER_NAME$3} blocked the request at its channel check (11128): the gateway did not accept it as an official client request. This is a plugin-side gap, not an account problem.${detail ? ` ${detail}` : ""}` : `${PROVIDER_NAME$3} rejected the message history: the conversation must open with a system prompt.${detail ? ` ${detail}` : ""}`, "PROVIDER_ERROR", { status });
|
|
102054
|
-
if (status >= 500 || code === 11134) return new LlmError(`${PROVIDER_NAME$3} upstream server error (${status}): ${detail || "No response"}`, "SERVER", { status });
|
|
102055
|
-
return new LlmError(`${PROVIDER_NAME$3} API error (${status}): ${detail || "No response"}`, isHttpContextOverflow(status, detail) ? CONTEXT_OVERFLOW_CODE : "PROVIDER_ERROR", { status });
|
|
102403
|
+
if (code === SIGNATURE_REFUSED_CODE) return new LlmError$1(`${PROVIDER_NAME$3} refused a thinking block's signature (11159). A replayed reasoning block whose signature this route did not produce cannot be verified, so it has to be dropped rather than replayed.${detail ? ` ${detail}` : ""}`, "PROVIDER_ERROR", { status });
|
|
102404
|
+
if (code === 11128) return new LlmError$1(/conversation id|unapproved channel/i.test(detail) ? `${PROVIDER_NAME$3} blocked the request at its channel check (11128): the gateway did not accept it as an official client request. This is a plugin-side gap, not an account problem.${detail ? ` ${detail}` : ""}` : `${PROVIDER_NAME$3} rejected the message history: the conversation must open with a system prompt.${detail ? ` ${detail}` : ""}`, "PROVIDER_ERROR", { status });
|
|
102405
|
+
if (status >= 500 || code === 11134) return new LlmError$1(`${PROVIDER_NAME$3} upstream server error (${status}): ${detail || "No response"}`, "SERVER", { status });
|
|
102406
|
+
return new LlmError$1(`${PROVIDER_NAME$3} API error (${status}): ${detail || "No response"}`, isHttpContextOverflow(status, detail) ? CONTEXT_OVERFLOW_CODE : "PROVIDER_ERROR", { status });
|
|
102056
102407
|
}
|
|
102057
102408
|
/**
|
|
102058
102409
|
* Whether a 403 body carries POSITIVE evidence that the refusal was not a
|
|
@@ -102182,7 +102533,7 @@ const WORKBUDDY_POOL_PAUSED_CODE = "WORKBUDDY_POOL_PAUSED";
|
|
|
102182
102533
|
* accounts" (wait for the pause, then sign the restricted ones in again) from
|
|
102183
102534
|
* "this request was rate limited". It is never reported as an upstream 429.
|
|
102184
102535
|
*/
|
|
102185
|
-
var WorkBuddyPoolPausedError = class extends LlmError {
|
|
102536
|
+
var WorkBuddyPoolPausedError = class extends LlmError$1 {
|
|
102186
102537
|
/** Unix milliseconds the pause lifts on its own; absent when nothing named one. */
|
|
102187
102538
|
pausedUntil;
|
|
102188
102539
|
constructor(message, pausedUntil) {
|
|
@@ -102491,7 +102842,7 @@ var WorkBuddyAccountPool = class extends AccountPoolCore {
|
|
|
102491
102842
|
if (refreshed.source === "desktop") await store.writeBack(refreshed);
|
|
102492
102843
|
return refreshed;
|
|
102493
102844
|
},
|
|
102494
|
-
refreshFailureStatus: (error) => error instanceof LlmError && error.code === "INVALID_CREDENTIAL" ? "expired" : void 0,
|
|
102845
|
+
refreshFailureStatus: (error) => error instanceof LlmError$1 && error.code === "INVALID_CREDENTIAL" ? "expired" : void 0,
|
|
102495
102846
|
extendSummary: (account, base, now) => ({
|
|
102496
102847
|
...base,
|
|
102497
102848
|
region: account.region ?? account.credentials.region,
|
|
@@ -104268,7 +104619,7 @@ const Config = z$1.object({
|
|
|
104268
104619
|
]).default("auto").volatile().description("进展更新的输出语言:auto 跟随对话语言,zh 中文,en 英文。"),
|
|
104269
104620
|
planModePipeline: z$1.boolean().default(true).volatile().description("启用计划模式管线:允许调度模式在澄清访谈收敛后用 enter_plan_mode 进入计划模式,放弃规划时用 leave_plan_mode 退出。"),
|
|
104270
104621
|
dispatchExecutionGuard: z$1.boolean().default(true).volatile().description("启用调度执行守卫:在执行期拦截子代理越权调用主控专用工具,并拦截等待子代理期间的纯 sleep 空等命令;不修改工具声明面,零损耗保护 Kimi 缓存。"),
|
|
104271
|
-
toolRunawayGuard: z$1.boolean().default(true).volatile().description("
|
|
104622
|
+
toolRunawayGuard: z$1.boolean().default(true).volatile().description("启用工具失控治理:对零增量病态信号(同名同参重复、同一工具连续同族报错、后台任务无变化轮询)分级提醒;Kimi 保留第 12 次同参强停,其他线路只提醒。"),
|
|
104272
104623
|
mediaTools: z$1.boolean().default(true).volatile().description("注册图片/视频工具:Codex 生图、Kimi 视频挂载、MiniMax 视频生成与理解;默认开启。修改后重载插件或重启 DSH,Kimi 既有会话在工具表变化后会重建一次前缀缓存。"),
|
|
104273
104624
|
teamPolicyCacheGuard: z$1.boolean().default(true).volatile().description("把内置 Agent Teams 的 team:policy 段从 system prompt 摘掉,改为开关切换时以尾部用户消息投递一次,避免中途开团队协作时刷掉整段前缀缓存;默认开启。"),
|
|
104274
104625
|
cacheWarmup: z$1.boolean().default(true).volatile().description(CACHE_WARMUP_SETTING_DESCRIPTION),
|
|
@@ -104355,7 +104706,7 @@ function apply(ctx, pluginConfig = {}) {
|
|
|
104355
104706
|
const guard = installCompactionPolicyGuard(ctx);
|
|
104356
104707
|
return () => guard.dispose();
|
|
104357
104708
|
}, "dsh-chatgpt-subscription: compaction policy guard");
|
|
104358
|
-
ctx.effect(() => installMinimaxRuntimeEnhancements(ctx), "dsh-chatgpt-subscription: MiniMax runtime enhancements");
|
|
104709
|
+
ctx.effect(() => installMinimaxRuntimeEnhancements(ctx, { runawayEnabled: () => resolveToolRunawayGuardEnabled(pluginConfig) }), "dsh-chatgpt-subscription: MiniMax runtime enhancements");
|
|
104359
104710
|
ctx.effect(() => installKimiRepeatBreaker(ctx, {
|
|
104360
104711
|
providers: CONTROLLED_PROVIDERS.filter((provider) => provider !== "minimax-code"),
|
|
104361
104712
|
globalEnabled: () => resolveToolRunawayGuardEnabled(pluginConfig)
|