@linnlabs/linnkit 0.46.0 → 0.47.0
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 +29 -0
- package/dist/cli.cjs +64 -246
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +64 -246
- package/dist/cli.js.map +1 -1
- package/dist/context-manager.cjs +7 -7
- package/dist/context-manager.cjs.map +1 -1
- package/dist/context-manager.js +7 -7
- package/dist/context-manager.js.map +1 -1
- package/dist/index.cjs +74 -257
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +74 -257
- package/dist/index.js.map +1 -1
- package/dist/ports/llm-call.d.cts +2 -16
- package/dist/ports/llm-call.d.ts +2 -16
- package/dist/quickstart.cjs +64 -246
- package/dist/quickstart.cjs.map +1 -1
- package/dist/quickstart.js +64 -246
- package/dist/quickstart.js.map +1 -1
- package/dist/runtime-kernel/graph-engine/executor.d.cts +0 -2
- package/dist/runtime-kernel/graph-engine/executor.d.ts +0 -2
- package/dist/runtime-kernel/graph-engine/types.d.cts +1 -2
- package/dist/runtime-kernel/graph-engine/types.d.ts +1 -2
- package/dist/runtime-kernel/llm/definitions/llmFallbackObserver.d.cts +1 -2
- package/dist/runtime-kernel/llm/definitions/llmFallbackObserver.d.ts +1 -2
- package/dist/runtime-kernel/llm/modelCatalog.d.cts +2 -3
- package/dist/runtime-kernel/llm/modelCatalog.d.ts +2 -3
- package/dist/runtime-kernel/tools/toolContextRuntime.d.cts +1 -1
- package/dist/runtime-kernel/tools/toolContextRuntime.d.ts +1 -1
- package/dist/runtime-kernel/tools/toolExecutionContext.d.cts +0 -10
- package/dist/runtime-kernel/tools/toolExecutionContext.d.ts +0 -10
- package/dist/runtime-kernel.cjs +74 -257
- package/dist/runtime-kernel.cjs.map +1 -1
- package/dist/runtime-kernel.js +74 -257
- package/dist/runtime-kernel.js.map +1 -1
- package/dist/testkit.cjs +82 -265
- package/dist/testkit.cjs.map +1 -1
- package/dist/testkit.js +82 -265
- package/dist/testkit.js.map +1 -1
- package/docs/integration/llm-provider.md +1 -1
- package/docs/integration/tool-development-guide.md +1 -1
- package/package.json +1 -1
package/dist/quickstart.js
CHANGED
|
@@ -2332,18 +2332,6 @@ var ErrorClassifier = class {
|
|
|
2332
2332
|
});
|
|
2333
2333
|
}
|
|
2334
2334
|
}
|
|
2335
|
-
const quotaPatterns = ["\u5DF2\u8FBE\u4E0A\u9650", "\u514D\u8D39\u671F\u5DF2\u7ED3\u675F"];
|
|
2336
|
-
for (const pattern of quotaPatterns) {
|
|
2337
|
-
if (errorMessage.includes(pattern)) {
|
|
2338
|
-
logClassification(context, "\u68C0\u6D4B\u5230\u4E91\u7AEF\u989D\u5EA6\u9650\u5236\uFF0C\u4E0D\u91CD\u8BD5", { matchedPattern: pattern });
|
|
2339
|
-
return createClassification("non_retryable" /* NON_RETRYABLE */, `\u4E91\u7AEF\u989D\u5EA6\u9650\u5236: ${pattern}`, null, {
|
|
2340
|
-
errorCode: ENGINE_ERROR_CODES.LLM_PROVIDER_DOWN,
|
|
2341
|
-
recoverable: false,
|
|
2342
|
-
hint: "check_billing_or_provider_status",
|
|
2343
|
-
metadata: { matchedPattern: pattern }
|
|
2344
|
-
});
|
|
2345
|
-
}
|
|
2346
|
-
}
|
|
2347
2335
|
const authPatterns = [
|
|
2348
2336
|
{ pattern: "unauthorized", code: "401" },
|
|
2349
2337
|
{ pattern: "forbidden", code: "403" },
|
|
@@ -2598,17 +2586,6 @@ var ErrorClassifier = class {
|
|
|
2598
2586
|
}
|
|
2599
2587
|
return Math.max(baseDelay, classification.suggestedDelay ?? 0);
|
|
2600
2588
|
}
|
|
2601
|
-
static isCloudQuotaError(error) {
|
|
2602
|
-
const msg = (error.message || "").toLowerCase();
|
|
2603
|
-
const patterns = [
|
|
2604
|
-
"\u989D\u5EA6\u4E0A\u9650",
|
|
2605
|
-
"\u5DF2\u8FBE\u4E0A\u9650",
|
|
2606
|
-
"\u514D\u8D39\u671F\u5DF2\u7ED3\u675F",
|
|
2607
|
-
"\u8BE5\u6A21\u578B\u6682\u4E0D\u53EF\u7528",
|
|
2608
|
-
"cloud_quota_exhausted"
|
|
2609
|
-
];
|
|
2610
|
-
return patterns.some((pattern) => msg.includes(pattern));
|
|
2611
|
-
}
|
|
2612
2589
|
};
|
|
2613
2590
|
|
|
2614
2591
|
// src/shared/engineErrorEvent.ts
|
|
@@ -4092,8 +4069,8 @@ var TokenCalculator = class {
|
|
|
4092
4069
|
return;
|
|
4093
4070
|
}
|
|
4094
4071
|
this.failedEncodingWarnings.add(requestedEncoding);
|
|
4095
|
-
const
|
|
4096
|
-
|
|
4072
|
+
const logger18 = new Logger("TokenCalculator");
|
|
4073
|
+
logger18.warn("tiktoken encoding unavailable, falling back to avgCharsPerToken estimator", {
|
|
4097
4074
|
requestedEncoding,
|
|
4098
4075
|
error
|
|
4099
4076
|
});
|
|
@@ -4185,49 +4162,6 @@ var llmTelemetryMiddleware = async (ctx, stage, next) => {
|
|
|
4185
4162
|
});
|
|
4186
4163
|
};
|
|
4187
4164
|
|
|
4188
|
-
// src/runtime-kernel/graph-engine/functions/runModelLock.ts
|
|
4189
|
-
function readNonEmptyString4(value) {
|
|
4190
|
-
if (typeof value !== "string") return void 0;
|
|
4191
|
-
const trimmed = value.trim();
|
|
4192
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
4193
|
-
}
|
|
4194
|
-
function decideRunModelLockPatch(params) {
|
|
4195
|
-
if (params.stageId !== "execute_llm") {
|
|
4196
|
-
return { shouldLog: false };
|
|
4197
|
-
}
|
|
4198
|
-
const normalized = readNonEmptyString4(params.appliedFallbackModelId);
|
|
4199
|
-
if (!normalized) {
|
|
4200
|
-
return { shouldLog: false };
|
|
4201
|
-
}
|
|
4202
|
-
if (readNonEmptyString4(params.currentRunLockedModelId) === normalized) {
|
|
4203
|
-
return { shouldLog: false };
|
|
4204
|
-
}
|
|
4205
|
-
return {
|
|
4206
|
-
executorLocalPatch: { runLockedModelId: normalized },
|
|
4207
|
-
shouldLog: true
|
|
4208
|
-
};
|
|
4209
|
-
}
|
|
4210
|
-
|
|
4211
|
-
// src/runtime-kernel/graph-engine/tick-pipeline/middlewares/runModelLockMiddleware.ts
|
|
4212
|
-
var logger4 = new Logger("GraphAgentExecutor");
|
|
4213
|
-
var runModelLockMiddleware = async (ctx, stage, next) => {
|
|
4214
|
-
await next();
|
|
4215
|
-
const decision = decideRunModelLockPatch({
|
|
4216
|
-
stageId: stage.id,
|
|
4217
|
-
appliedFallbackModelId: ctx.cloudQuotaFallbackAppliedModelId,
|
|
4218
|
-
currentRunLockedModelId: ctx.executorLocalPatch?.runLockedModelId ?? ctx.executorLocal?.runLockedModelId
|
|
4219
|
-
});
|
|
4220
|
-
if (!decision.executorLocalPatch) {
|
|
4221
|
-
return;
|
|
4222
|
-
}
|
|
4223
|
-
if (decision.shouldLog) {
|
|
4224
|
-
logger4.warn(`\u68C0\u6D4B\u5230\u4E91\u7AEF\u989D\u5EA6\u964D\u7EA7\uFF0C\u5DF2\u9501\u5B9A\u672C run \u540E\u7EED\u6A21\u578B: ${ctx.modelId} -> ${decision.executorLocalPatch.runLockedModelId}`);
|
|
4225
|
-
}
|
|
4226
|
-
return {
|
|
4227
|
-
executorLocalPatch: decision.executorLocalPatch
|
|
4228
|
-
};
|
|
4229
|
-
};
|
|
4230
|
-
|
|
4231
4165
|
// src/runtime-kernel/graph-engine/tick-pipeline/runTickPipeline.ts
|
|
4232
4166
|
var tickPipelineContextKeys = [
|
|
4233
4167
|
"input",
|
|
@@ -4263,7 +4197,6 @@ var tickPipelineContextKeys = [
|
|
|
4263
4197
|
"decision",
|
|
4264
4198
|
"systemReminderHitRuleIds",
|
|
4265
4199
|
"contextTrace",
|
|
4266
|
-
"cloudQuotaFallbackAppliedModelId",
|
|
4267
4200
|
"modelFallbackAudit",
|
|
4268
4201
|
"telemetry",
|
|
4269
4202
|
"audit",
|
|
@@ -4602,7 +4535,7 @@ ${normalized}
|
|
|
4602
4535
|
}
|
|
4603
4536
|
|
|
4604
4537
|
// src/runtime-kernel/system-reminder/apply.ts
|
|
4605
|
-
var
|
|
4538
|
+
var logger4 = new Logger("SystemReminder");
|
|
4606
4539
|
var readString2 = (v) => {
|
|
4607
4540
|
if (typeof v !== "string") return void 0;
|
|
4608
4541
|
const s = v;
|
|
@@ -4665,7 +4598,7 @@ function applySystemReminders(params) {
|
|
|
4665
4598
|
} catch {
|
|
4666
4599
|
}
|
|
4667
4600
|
}
|
|
4668
|
-
|
|
4601
|
+
logger4.info("SystemReminder \u5DF2\u6CE8\u5165\u5230 LLM \u8F93\u5165\u672B\u5C3E", {
|
|
4669
4602
|
ruleIds: injectedRuleIds.length > 0 ? injectedRuleIds : Array.from(seenRuleIds),
|
|
4670
4603
|
promptKey: ctx.request.promptKey,
|
|
4671
4604
|
executorLocal: {
|
|
@@ -5157,7 +5090,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5157
5090
|
"turnId"
|
|
5158
5091
|
],
|
|
5159
5092
|
writes: [
|
|
5160
|
-
"cloudQuotaFallbackAppliedModelId",
|
|
5161
5093
|
"modelFallbackAudit",
|
|
5162
5094
|
"llmCallStartedAt",
|
|
5163
5095
|
"llmResp",
|
|
@@ -5165,7 +5097,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5165
5097
|
"contextUsage"
|
|
5166
5098
|
],
|
|
5167
5099
|
async run(ctx) {
|
|
5168
|
-
let cloudQuotaFallbackAppliedModelId;
|
|
5169
5100
|
let modelFallbackAudit;
|
|
5170
5101
|
let contextUsage;
|
|
5171
5102
|
const modelFallbackRejections = [];
|
|
@@ -5184,9 +5115,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5184
5115
|
streamEventHandler,
|
|
5185
5116
|
ctx.signal,
|
|
5186
5117
|
{
|
|
5187
|
-
onCloudQuotaFallbackApplied(fallbackModelId) {
|
|
5188
|
-
cloudQuotaFallbackAppliedModelId = readNonEmptyString3(fallbackModelId);
|
|
5189
|
-
},
|
|
5190
5118
|
onLlmAttemptSucceeded(_activeModelId, attemptContextUsage) {
|
|
5191
5119
|
contextUsage = attemptContextUsage;
|
|
5192
5120
|
},
|
|
@@ -5283,7 +5211,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5283
5211
|
});
|
|
5284
5212
|
}
|
|
5285
5213
|
return {
|
|
5286
|
-
cloudQuotaFallbackAppliedModelId,
|
|
5287
5214
|
modelFallbackAudit,
|
|
5288
5215
|
llmCallStartedAt,
|
|
5289
5216
|
llmResp,
|
|
@@ -6204,18 +6131,16 @@ function createPrepareCallStage(dependencies) {
|
|
|
6204
6131
|
"toolDefinitionTokens"
|
|
6205
6132
|
],
|
|
6206
6133
|
async run(ctx) {
|
|
6207
|
-
const
|
|
6208
|
-
const requestedModelId = lockedRunModelId ?? ctx.request.model_id;
|
|
6134
|
+
const requestedModelId = ctx.request.model_id;
|
|
6209
6135
|
const modelId = dependencies.modelResolver.resolveModelId(requestedModelId);
|
|
6210
6136
|
await emitAuditEnvelope(ctx.audit, {
|
|
6211
6137
|
action: "model.select",
|
|
6212
6138
|
actor: { kind: "system" },
|
|
6213
6139
|
decision: {
|
|
6214
6140
|
outcome: "recorded",
|
|
6215
|
-
reason:
|
|
6141
|
+
reason: requestedModelId ? "request model id" : "default model resolver",
|
|
6216
6142
|
metadata: {
|
|
6217
6143
|
requestedModelId,
|
|
6218
|
-
lockedRunModelId,
|
|
6219
6144
|
selectedModelId: modelId
|
|
6220
6145
|
}
|
|
6221
6146
|
},
|
|
@@ -6262,10 +6187,6 @@ function createPrepareCallStage(dependencies) {
|
|
|
6262
6187
|
if (ctx.executorLocal?.lockRequestedModelId === true) {
|
|
6263
6188
|
llmOptions.allow_model_fallback = false;
|
|
6264
6189
|
}
|
|
6265
|
-
const isRunContinuation = ctx.executorLocal?.llmInvocationKind === "continuation";
|
|
6266
|
-
if (dependencies.cloudQuotaFallbackModelId && modelConfig?.billing_mode === "cloud" && modelId !== dependencies.cloudQuotaFallbackModelId && isRunContinuation && ctx.executorLocal?.lockRequestedModelId !== true) {
|
|
6267
|
-
llmOptions.cloud_quota_fallback_model_id = dependencies.cloudQuotaFallbackModelId;
|
|
6268
|
-
}
|
|
6269
6190
|
const effectiveEffort = resolveEffectiveEffort(
|
|
6270
6191
|
ctx.request.reasoning_effort,
|
|
6271
6192
|
modelConfig?.reasoning
|
|
@@ -6382,12 +6303,11 @@ function applyCalibration(rawLocalTotal, imageInputTokens, coefficient) {
|
|
|
6382
6303
|
}
|
|
6383
6304
|
|
|
6384
6305
|
// src/runtime-kernel/graph-engine/executor.ts
|
|
6385
|
-
var
|
|
6306
|
+
var logger5 = new Logger("GraphAgentExecutor");
|
|
6386
6307
|
var GraphAgentExecutor = class {
|
|
6387
6308
|
llmCaller;
|
|
6388
6309
|
toolRuntime;
|
|
6389
6310
|
contextBuilder;
|
|
6390
|
-
cloudQuotaFallbackModelId;
|
|
6391
6311
|
modelResolver;
|
|
6392
6312
|
modelCatalog;
|
|
6393
6313
|
telemetryPort;
|
|
@@ -6399,7 +6319,6 @@ var GraphAgentExecutor = class {
|
|
|
6399
6319
|
this.llmCaller = dependencies.llmCaller;
|
|
6400
6320
|
this.toolRuntime = dependencies.toolRuntime;
|
|
6401
6321
|
this.contextBuilder = dependencies.contextBuilder;
|
|
6402
|
-
this.cloudQuotaFallbackModelId = readNonEmptyString3(dependencies.cloudQuotaFallbackModelId);
|
|
6403
6322
|
this.modelCatalog = dependencies.modelCatalog ?? createEmptyModelCatalog();
|
|
6404
6323
|
this.modelResolver = dependencies.modelResolver ?? new ModelResolver({
|
|
6405
6324
|
modelCatalog: this.modelCatalog
|
|
@@ -6416,8 +6335,7 @@ var GraphAgentExecutor = class {
|
|
|
6416
6335
|
createPrepareCallStage({
|
|
6417
6336
|
modelResolver: this.modelResolver,
|
|
6418
6337
|
modelCatalog: this.modelCatalog,
|
|
6419
|
-
toolCatalog: this.toolRuntime
|
|
6420
|
-
cloudQuotaFallbackModelId: this.cloudQuotaFallbackModelId
|
|
6338
|
+
toolCatalog: this.toolRuntime
|
|
6421
6339
|
}),
|
|
6422
6340
|
createBuildContextStage({
|
|
6423
6341
|
contextBuilder: this.contextBuilder
|
|
@@ -6439,7 +6357,7 @@ var GraphAgentExecutor = class {
|
|
|
6439
6357
|
}),
|
|
6440
6358
|
createBuildDecisionStage()
|
|
6441
6359
|
];
|
|
6442
|
-
this.middlewares = [llmTelemetryMiddleware
|
|
6360
|
+
this.middlewares = [llmTelemetryMiddleware];
|
|
6443
6361
|
}
|
|
6444
6362
|
async tick(input, eventHandler) {
|
|
6445
6363
|
const ctx = {
|
|
@@ -6464,7 +6382,7 @@ var GraphAgentExecutor = class {
|
|
|
6464
6382
|
audit: this.auditPort,
|
|
6465
6383
|
tokenizer: this.tokenizer
|
|
6466
6384
|
};
|
|
6467
|
-
|
|
6385
|
+
logger5.info("[GraphAgentExecutor] tick \u8C03\u7528", {
|
|
6468
6386
|
stream: input.stream === true,
|
|
6469
6387
|
hasEventHandler: Boolean(eventHandler),
|
|
6470
6388
|
hasSummarizationCallbacks: Boolean(input.summarizationCallbacks)
|
|
@@ -7487,7 +7405,7 @@ var LlmNodeEventBridge = class {
|
|
|
7487
7405
|
};
|
|
7488
7406
|
|
|
7489
7407
|
// src/runtime-kernel/graph-engine/nodes/llmNode.ts
|
|
7490
|
-
var
|
|
7408
|
+
var logger6 = new Logger("LlmNode");
|
|
7491
7409
|
var LlmNode = class {
|
|
7492
7410
|
id = "llm";
|
|
7493
7411
|
reasoner;
|
|
@@ -7496,7 +7414,7 @@ var LlmNode = class {
|
|
|
7496
7414
|
}
|
|
7497
7415
|
async run(state) {
|
|
7498
7416
|
const local = state.local ?? {};
|
|
7499
|
-
|
|
7417
|
+
logger6.info("[LlmNode] \u5F00\u59CB\u6267\u884C LLM \u8282\u70B9", {
|
|
7500
7418
|
localKeys: Object.keys(local)
|
|
7501
7419
|
});
|
|
7502
7420
|
const graphLocal = readGraphAgentLocal(state.local);
|
|
@@ -7511,12 +7429,12 @@ var LlmNode = class {
|
|
|
7511
7429
|
signal,
|
|
7512
7430
|
history
|
|
7513
7431
|
} = graphLocal;
|
|
7514
|
-
|
|
7432
|
+
logger6.info("[LlmNode] \u5DF2\u52A0\u8F7D\u5386\u53F2\u4E8B\u4EF6", {
|
|
7515
7433
|
historyCount: history.length,
|
|
7516
7434
|
hasSummarizationCallbacks: Boolean(summarizationCallbacks)
|
|
7517
7435
|
});
|
|
7518
7436
|
if (!request) {
|
|
7519
|
-
|
|
7437
|
+
logger6.warn("Request object is missing, yielding.");
|
|
7520
7438
|
return { kind: "yield", events: [] };
|
|
7521
7439
|
}
|
|
7522
7440
|
const turnId = requireRuntimeIdentity(graphLocal.turnId, "turnId");
|
|
@@ -7609,12 +7527,12 @@ var LlmNode = class {
|
|
|
7609
7527
|
...nodeState.streamRuntimeEvents,
|
|
7610
7528
|
...contextUsageEvent ? [contextUsageEvent] : []
|
|
7611
7529
|
];
|
|
7612
|
-
|
|
7530
|
+
logger6.info("[LlmNode] \u5386\u53F2\u4E8B\u4EF6\u5DF2\u66F4\u65B0", {
|
|
7613
7531
|
previousCount: history.length,
|
|
7614
7532
|
nextCount: patch.history.length,
|
|
7615
7533
|
streamedEventCount: nodeState.streamRuntimeEvents.length
|
|
7616
7534
|
});
|
|
7617
|
-
|
|
7535
|
+
logger6.info("[LlmNode] \u6267\u884C\u5668\u51B3\u7B56\u5B8C\u6210", {
|
|
7618
7536
|
decisionKind: decision.kind,
|
|
7619
7537
|
emittedEventCount: combinedEvents.length
|
|
7620
7538
|
});
|
|
@@ -7636,7 +7554,7 @@ var LlmNode = class {
|
|
|
7636
7554
|
}
|
|
7637
7555
|
case "error": {
|
|
7638
7556
|
const { name, message, stack } = decision.error;
|
|
7639
|
-
|
|
7557
|
+
logger6.error("[LlmNode] Executor returned an error", { name, message, stack });
|
|
7640
7558
|
return { kind: "yield", events: combinedEvents };
|
|
7641
7559
|
}
|
|
7642
7560
|
default: {
|
|
@@ -7742,7 +7660,7 @@ async function resolveToolModelInput(input) {
|
|
|
7742
7660
|
}
|
|
7743
7661
|
|
|
7744
7662
|
// src/runtime-kernel/graph-engine/nodes/toolNode.finalAnswerProjector.ts
|
|
7745
|
-
function
|
|
7663
|
+
function readNonEmptyString4(value) {
|
|
7746
7664
|
if (typeof value !== "string") {
|
|
7747
7665
|
return void 0;
|
|
7748
7666
|
}
|
|
@@ -7750,7 +7668,7 @@ function readNonEmptyString5(value) {
|
|
|
7750
7668
|
return normalized.length > 0 ? normalized : void 0;
|
|
7751
7669
|
}
|
|
7752
7670
|
function resolveFinalAnswerFromToolControl(finalAnswer) {
|
|
7753
|
-
return
|
|
7671
|
+
return readNonEmptyString4(finalAnswer);
|
|
7754
7672
|
}
|
|
7755
7673
|
|
|
7756
7674
|
// src/runtime-kernel/graph-engine/nodes/toolNode.helpers.ts
|
|
@@ -8006,7 +7924,7 @@ function buildErrorLocalState(params) {
|
|
|
8006
7924
|
}
|
|
8007
7925
|
|
|
8008
7926
|
// src/runtime-kernel/tools/argNormalizer.ts
|
|
8009
|
-
var
|
|
7927
|
+
var logger7 = new Logger("ToolArgNormalizer");
|
|
8010
7928
|
function isRecord10(v) {
|
|
8011
7929
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
8012
7930
|
}
|
|
@@ -8026,7 +7944,7 @@ function joinPath(basePath, segment) {
|
|
|
8026
7944
|
function logJsonEncodedNormalization(expectedType, options) {
|
|
8027
7945
|
const toolPrefix = options.toolName ? `${options.toolName}.` : "";
|
|
8028
7946
|
const path = options.path ?? "<root>";
|
|
8029
|
-
|
|
7947
|
+
logger7.warn("normalized JSON-encoded tool argument", {
|
|
8030
7948
|
expectedType,
|
|
8031
7949
|
path: `${toolPrefix}${path}`
|
|
8032
7950
|
});
|
|
@@ -8322,7 +8240,7 @@ function ensureToolContextRuntimeCapability(params) {
|
|
|
8322
8240
|
}
|
|
8323
8241
|
|
|
8324
8242
|
// src/runtime-kernel/graph-engine/nodes/toolNode.eventBridge.ts
|
|
8325
|
-
var
|
|
8243
|
+
var logger8 = new Logger("ToolNode");
|
|
8326
8244
|
var ToolNodeEventBridge = class {
|
|
8327
8245
|
constructor(deps) {
|
|
8328
8246
|
this.deps = deps;
|
|
@@ -8344,7 +8262,7 @@ var ToolNodeEventBridge = class {
|
|
|
8344
8262
|
status,
|
|
8345
8263
|
payload: { ...payload }
|
|
8346
8264
|
};
|
|
8347
|
-
|
|
8265
|
+
logger8.info("[ToolNode] \u53D1\u51FA tool_process \u4E8B\u4EF6", {
|
|
8348
8266
|
phase,
|
|
8349
8267
|
status,
|
|
8350
8268
|
toolName: this.deps.toolName,
|
|
@@ -8384,7 +8302,7 @@ var ToolNodeEventBridge = class {
|
|
|
8384
8302
|
const answerId = generateAnswerSegmentId();
|
|
8385
8303
|
const id = answerId;
|
|
8386
8304
|
const timestamp = Date.now();
|
|
8387
|
-
|
|
8305
|
+
logger8.info("[ToolNode] \u5DE5\u5177\u8F93\u51FA\u6620\u5C04\u4E3A final_answer", {
|
|
8388
8306
|
sourceToolName: params.sourceToolName,
|
|
8389
8307
|
toolCallId: this.deps.toolCallId,
|
|
8390
8308
|
conversationId: this.deps.conversationId,
|
|
@@ -8442,7 +8360,7 @@ var ToolNodeEventBridge = class {
|
|
|
8442
8360
|
};
|
|
8443
8361
|
|
|
8444
8362
|
// src/runtime-kernel/graph-engine/nodes/toolNode.executionSetup.ts
|
|
8445
|
-
var
|
|
8363
|
+
var logger9 = new Logger("ToolNode");
|
|
8446
8364
|
function parseToolArgs(call) {
|
|
8447
8365
|
const rawArguments = typeof call.function?.arguments === "string" ? call.function.arguments : "";
|
|
8448
8366
|
if (!rawArguments.trim()) {
|
|
@@ -8462,19 +8380,13 @@ function parseToolArgs(call) {
|
|
|
8462
8380
|
return { ok: true, value: parsed };
|
|
8463
8381
|
} catch (error) {
|
|
8464
8382
|
const reason = error instanceof Error ? error.message : "Unknown JSON parse error";
|
|
8465
|
-
|
|
8383
|
+
logger9.warn("failed to parse tool arguments", { error });
|
|
8466
8384
|
return {
|
|
8467
8385
|
ok: false,
|
|
8468
8386
|
error: `Tool arguments are not valid JSON: ${reason}`
|
|
8469
8387
|
};
|
|
8470
8388
|
}
|
|
8471
8389
|
}
|
|
8472
|
-
function readRunLockedModelId(local) {
|
|
8473
|
-
const executorLocal = local.executorLocal;
|
|
8474
|
-
if (!isRecord9(executorLocal)) return void 0;
|
|
8475
|
-
const lockedModelId = executorLocal.runLockedModelId;
|
|
8476
|
-
return typeof lockedModelId === "string" && lockedModelId.trim() ? lockedModelId : void 0;
|
|
8477
|
-
}
|
|
8478
8390
|
function prepareToolNodeContext(state) {
|
|
8479
8391
|
const local = state.local || {};
|
|
8480
8392
|
const toolContext = isRecord9(local.toolContext) ? local.toolContext : {};
|
|
@@ -8492,7 +8404,6 @@ function prepareToolNodeContext(state) {
|
|
|
8492
8404
|
}
|
|
8493
8405
|
});
|
|
8494
8406
|
attachWorkingHistoryView({ state, toolContext });
|
|
8495
|
-
toolContext.activeModelId = readRunLockedModelId(local) ?? toolContext.modelId;
|
|
8496
8407
|
return {
|
|
8497
8408
|
state,
|
|
8498
8409
|
local,
|
|
@@ -8863,7 +8774,7 @@ async function claimPendingUserInputs(state, result) {
|
|
|
8863
8774
|
}
|
|
8864
8775
|
|
|
8865
8776
|
// src/runtime-kernel/graph-engine/nodes/toolNode.ts
|
|
8866
|
-
var
|
|
8777
|
+
var logger10 = new Logger("ToolNode");
|
|
8867
8778
|
function isAbortSignal(value) {
|
|
8868
8779
|
return value !== null && typeof value === "object" && "aborted" in value;
|
|
8869
8780
|
}
|
|
@@ -9076,7 +8987,7 @@ var ToolNode = class {
|
|
|
9076
8987
|
throw abortError;
|
|
9077
8988
|
}
|
|
9078
8989
|
const prepared = prepareToolNodeContext(state);
|
|
9079
|
-
|
|
8990
|
+
logger10.info("[ToolNode] \u5F00\u59CB\u6267\u884C\u5DE5\u5177\u8282\u70B9", {
|
|
9080
8991
|
conversationId: prepared.conversationId,
|
|
9081
8992
|
turnId: prepared.turnId,
|
|
9082
8993
|
pendingCallCount: calls.length
|
|
@@ -9091,7 +9002,7 @@ var ToolNode = class {
|
|
|
9091
9002
|
toolCatalog: this.toolRuntime
|
|
9092
9003
|
});
|
|
9093
9004
|
if (!execution) {
|
|
9094
|
-
|
|
9005
|
+
logger10.warn("no tool name found in call");
|
|
9095
9006
|
return { kind: "yield", events: [] };
|
|
9096
9007
|
}
|
|
9097
9008
|
if (typeof execution.protocolError === "string") {
|
|
@@ -9131,7 +9042,7 @@ var ToolNode = class {
|
|
|
9131
9042
|
call,
|
|
9132
9043
|
context: prepared.toolContext,
|
|
9133
9044
|
abortGraceMs: this.abortGraceMs,
|
|
9134
|
-
onAbandon: () =>
|
|
9045
|
+
onAbandon: () => logger10.warn("[ToolNode] \u5DE5\u5177\u672A\u5728\u505C\u6B62\u671F\u9650\u5185\u7ED3\u675F\uFF0C\u6309\u4E2D\u65AD\u5904\u7406\u5E76\u4E22\u5F03\u8FDF\u5230\u7ED3\u679C", {
|
|
9135
9046
|
toolName: execution.toolName,
|
|
9136
9047
|
toolCallId: execution.toolCallId,
|
|
9137
9048
|
conversationId: prepared.conversationId,
|
|
@@ -9301,7 +9212,7 @@ var ToolNode = class {
|
|
|
9301
9212
|
runtimeEvents: context.bridge.getRuntimeEvents()
|
|
9302
9213
|
});
|
|
9303
9214
|
if (control?.terminateRun) {
|
|
9304
|
-
|
|
9215
|
+
logger10.info("[ToolNode] \u6536\u5230 control.terminateRun\uFF0C\u6267\u884C\u5B8C\u5DE5\u5177\u540E\u76F4\u63A5 yield \u7ED3\u675F\u672C\u8F6E run", {
|
|
9305
9216
|
toolName: context.toolName,
|
|
9306
9217
|
toolCallId: context.toolCallId,
|
|
9307
9218
|
conversationId: context.conversationId,
|
|
@@ -9310,7 +9221,7 @@ var ToolNode = class {
|
|
|
9310
9221
|
return { kind: "yield", events: context.bridge.getRuntimeEvents() };
|
|
9311
9222
|
}
|
|
9312
9223
|
if (remainingCalls.length === 0 && context.local.toolBatchCompletionMode === "yield_after_batch") {
|
|
9313
|
-
|
|
9224
|
+
logger10.info("[ToolNode] \u5DE5\u5177\u6279\u6B21\u5DF2\u7ED3\u7B97\uFF0C\u6309 Host \u7B56\u7565\u76F4\u63A5 yield", {
|
|
9314
9225
|
toolName: context.toolName,
|
|
9315
9226
|
toolCallId: context.toolCallId,
|
|
9316
9227
|
conversationId: context.conversationId,
|
|
@@ -9757,8 +9668,9 @@ var executor = z.object({
|
|
|
9757
9668
|
lastStepsHintThreshold: counter.optional(),
|
|
9758
9669
|
systemReminderPolicy: AgentSpecSystemReminderPolicy.optional(),
|
|
9759
9670
|
toolObservationPolicy: AgentSpecToolObservationGovernancePolicy.optional(),
|
|
9671
|
+
// 已删除字段:0.45 及更早的 checkpoint 可能带 lastSuccessfulLlmModelId,0.46 及更早的可能带云端额度兜底留下的
|
|
9672
|
+
// runLockedModelId;照常接受,读入时丢弃(兜底已移除,恢复后按请求的模型继续)。
|
|
9760
9673
|
runLockedModelId: z.string().optional(),
|
|
9761
|
-
// 0.45 及更早的 checkpoint 可能带这个已删除字段;照常接受,读入时丢弃。
|
|
9762
9674
|
lastSuccessfulLlmModelId: z.string().optional(),
|
|
9763
9675
|
llmInvocationKind: z.enum(["user_initiated", "continuation"]).optional(),
|
|
9764
9676
|
llmInvocationCount: counter.optional(),
|
|
@@ -9768,7 +9680,7 @@ var executor = z.object({
|
|
|
9768
9680
|
committedCount: counter,
|
|
9769
9681
|
lastCommittedFingerprint: z.string().optional()
|
|
9770
9682
|
}).strict().optional()
|
|
9771
|
-
}).strict().transform(({ lastSuccessfulLlmModelId: _retired, ...state }) => state);
|
|
9683
|
+
}).strict().transform(({ lastSuccessfulLlmModelId: _retired, runLockedModelId: _retiredLock, ...state }) => state);
|
|
9772
9684
|
var checkpoint = z.object({
|
|
9773
9685
|
nodeId: z.string().min(1),
|
|
9774
9686
|
schemaVersion: z.literal(ENGINE_STATE_SCHEMA_VERSION).optional(),
|
|
@@ -9830,7 +9742,7 @@ __export(execution_exports, {
|
|
|
9830
9742
|
});
|
|
9831
9743
|
|
|
9832
9744
|
// src/runtime-kernel/execution/event-bus.ts
|
|
9833
|
-
var
|
|
9745
|
+
var logger11 = new Logger("EventBus");
|
|
9834
9746
|
var TypedEventEmitter = class {
|
|
9835
9747
|
listeners = /* @__PURE__ */ new Map();
|
|
9836
9748
|
maxListeners = 10;
|
|
@@ -9838,7 +9750,7 @@ var TypedEventEmitter = class {
|
|
|
9838
9750
|
const listeners = this.getListeners(event);
|
|
9839
9751
|
listeners.add(listener);
|
|
9840
9752
|
if (listeners.size > this.maxListeners) {
|
|
9841
|
-
|
|
9753
|
+
logger11.warn("EventBus listener count exceeds configured max", {
|
|
9842
9754
|
event: String(event),
|
|
9843
9755
|
count: listeners.size,
|
|
9844
9756
|
maxListeners: this.maxListeners
|
|
@@ -9898,7 +9810,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
9898
9810
|
super();
|
|
9899
9811
|
this.executionId = executionId;
|
|
9900
9812
|
this.setMaxListeners(30);
|
|
9901
|
-
|
|
9813
|
+
logger11.info(`EventBus created for execution ${this.executionId}`);
|
|
9902
9814
|
}
|
|
9903
9815
|
/**
|
|
9904
9816
|
* 发布一个事件到总线
|
|
@@ -9907,7 +9819,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
9907
9819
|
publish(envelope) {
|
|
9908
9820
|
if (envelope.trace.execution_id !== this.executionId) {
|
|
9909
9821
|
const error = new Error("EventEnvelope execution_id does not match EventBus instance.");
|
|
9910
|
-
|
|
9822
|
+
logger11.error("Mismatched execution_id", {
|
|
9911
9823
|
busExecutionId: this.executionId,
|
|
9912
9824
|
eventExecutionId: envelope.trace.execution_id,
|
|
9913
9825
|
eventSeq: envelope.seq
|
|
@@ -9919,7 +9831,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
9919
9831
|
const error = new Error(
|
|
9920
9832
|
"EventBus only accepts RuntimeEvent with formal run routing identity."
|
|
9921
9833
|
);
|
|
9922
|
-
|
|
9834
|
+
logger11.error("RuntimeEvent is missing formal run routing identity", {
|
|
9923
9835
|
executionId: this.executionId,
|
|
9924
9836
|
eventId: envelope.payload.id,
|
|
9925
9837
|
eventType: envelope.payload.type
|
|
@@ -9933,14 +9845,14 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
9933
9845
|
* 关闭总线,清理所有监听器
|
|
9934
9846
|
*/
|
|
9935
9847
|
close() {
|
|
9936
|
-
|
|
9848
|
+
logger11.info(`Closing EventBus for execution ${this.executionId}`);
|
|
9937
9849
|
this.emit("close");
|
|
9938
9850
|
this.removeAllListeners();
|
|
9939
9851
|
}
|
|
9940
9852
|
};
|
|
9941
9853
|
|
|
9942
9854
|
// src/runtime-kernel/execution/sequencer.ts
|
|
9943
|
-
var
|
|
9855
|
+
var logger12 = new Logger("EventSequencer");
|
|
9944
9856
|
var EventSequencer = class {
|
|
9945
9857
|
executionId;
|
|
9946
9858
|
traceId;
|
|
@@ -9948,7 +9860,7 @@ var EventSequencer = class {
|
|
|
9948
9860
|
constructor(conversationId, traceId) {
|
|
9949
9861
|
this.executionId = generateExecutionId();
|
|
9950
9862
|
this.traceId = traceId || generateTraceId();
|
|
9951
|
-
|
|
9863
|
+
logger12.info(`EventSequencer created for conversation ${conversationId}`, {
|
|
9952
9864
|
executionId: this.executionId,
|
|
9953
9865
|
traceId: this.traceId
|
|
9954
9866
|
});
|
|
@@ -10761,7 +10673,7 @@ var ThoughtStreamSegmenter = class {
|
|
|
10761
10673
|
};
|
|
10762
10674
|
|
|
10763
10675
|
// src/runtime-kernel/llm/streaming-adapter.ts
|
|
10764
|
-
var
|
|
10676
|
+
var logger13 = new Logger("LlmCaller");
|
|
10765
10677
|
var CanonicalInferenceFailureError = class extends Error {
|
|
10766
10678
|
errorCode;
|
|
10767
10679
|
recoverable;
|
|
@@ -10985,7 +10897,7 @@ async function callLlmStream(params) {
|
|
|
10985
10897
|
} catch (error) {
|
|
10986
10898
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
10987
10899
|
if (normalized.name === "AbortError") {
|
|
10988
|
-
|
|
10900
|
+
logger13.info("Canonical inference \u6536\u5230\u53D6\u6D88\u7EC8\u6001\uFF0C\u4E0D\u53D1\u5E03\u666E\u901A error event", { modelId });
|
|
10989
10901
|
throw normalized;
|
|
10990
10902
|
}
|
|
10991
10903
|
const classification = ErrorClassifier.classify(normalized, {
|
|
@@ -11061,7 +10973,7 @@ var LlmRetryEpisode = class {
|
|
|
11061
10973
|
};
|
|
11062
10974
|
|
|
11063
10975
|
// src/runtime-kernel/llm/retry-fallback-routing.ts
|
|
11064
|
-
var
|
|
10976
|
+
var logger14 = new Logger("LlmCaller");
|
|
11065
10977
|
function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement, fallbackObserver, error, evaluateFallbackPromptCapacity2) {
|
|
11066
10978
|
deps.modelCatalog.getModelById(activeModelId);
|
|
11067
10979
|
const policyDecision = deps.policyEngine.decideOnError(error, {
|
|
@@ -11091,81 +11003,16 @@ function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement
|
|
|
11091
11003
|
reason: "no_eligible_fallback_candidate",
|
|
11092
11004
|
requiredPlacements: requirement.placements
|
|
11093
11005
|
});
|
|
11094
|
-
|
|
11006
|
+
logger14.warn("Policy\u8981\u6C42\u5207\u6362\u6A21\u578B\uFF0C\u4F46\u672A\u627E\u5230\u53EF\u7528\u5907\u7528\u6A21\u578B\uFF08\u53EF\u80FD\u672A\u914D\u7F6E API Key\uFF09");
|
|
11095
11007
|
return null;
|
|
11096
11008
|
}
|
|
11097
|
-
|
|
11009
|
+
logger14.warn("Policy \u5207\u6362\u6A21\u578B\u7EE7\u7EED", {
|
|
11098
11010
|
reason: policyDecision.reason,
|
|
11099
11011
|
activeModelId,
|
|
11100
11012
|
fallbackModelId
|
|
11101
11013
|
});
|
|
11102
11014
|
return fallbackModelId;
|
|
11103
11015
|
}
|
|
11104
|
-
function tryCloudQuotaFallback({
|
|
11105
|
-
deps,
|
|
11106
|
-
activeModelId,
|
|
11107
|
-
options,
|
|
11108
|
-
excludedModelIds,
|
|
11109
|
-
requirement,
|
|
11110
|
-
error,
|
|
11111
|
-
fallbackObserver,
|
|
11112
|
-
evaluateFallbackPromptCapacity: evaluateFallbackPromptCapacity2
|
|
11113
|
-
}) {
|
|
11114
|
-
const fallbackModelId = options.cloud_quota_fallback_model_id;
|
|
11115
|
-
if (!fallbackModelId || !ErrorClassifier.isCloudQuotaError(error) || excludedModelIds.has(fallbackModelId)) {
|
|
11116
|
-
return null;
|
|
11117
|
-
}
|
|
11118
|
-
const fallbackConfig = deps.modelCatalog.getModelById(fallbackModelId);
|
|
11119
|
-
if (!fallbackConfig?.api_key) {
|
|
11120
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11121
|
-
fromModelId: activeModelId,
|
|
11122
|
-
candidateModelId: fallbackModelId,
|
|
11123
|
-
policy: "cloud-quota",
|
|
11124
|
-
reason: "fallback_model_unavailable",
|
|
11125
|
-
requiredPlacements: requirement.placements
|
|
11126
|
-
});
|
|
11127
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\u76EE\u6807\u4E0D\u53EF\u7528\uFF08\u672A\u6CE8\u518C\u6216\u7F3A\u5C11 API Key\uFF09", { fallbackModelId });
|
|
11128
|
-
return null;
|
|
11129
|
-
}
|
|
11130
|
-
const compatibility = evaluateModelInputCompatibility(fallbackConfig, requirement);
|
|
11131
|
-
if (!compatibility.compatible) {
|
|
11132
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11133
|
-
fromModelId: activeModelId,
|
|
11134
|
-
candidateModelId: fallbackModelId,
|
|
11135
|
-
policy: "cloud-quota",
|
|
11136
|
-
reason: compatibility.reason,
|
|
11137
|
-
requiredPlacements: requirement.placements
|
|
11138
|
-
});
|
|
11139
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\u76EE\u6807\u4E0D\u6EE1\u8DB3\u5F53\u524D\u8F93\u5165\u80FD\u529B\uFF0C\u4FDD\u7559\u539F\u59CB\u9519\u8BEF", {
|
|
11140
|
-
fallbackModelId,
|
|
11141
|
-
requiredPlacements: requirement.placements,
|
|
11142
|
-
reason: compatibility.reason
|
|
11143
|
-
});
|
|
11144
|
-
return null;
|
|
11145
|
-
}
|
|
11146
|
-
const capacityAdmission = evaluateFallbackPromptCapacity2?.(fallbackModelId);
|
|
11147
|
-
if (capacityAdmission && !capacityAdmission.admitted) {
|
|
11148
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11149
|
-
fromModelId: activeModelId,
|
|
11150
|
-
candidateModelId: fallbackModelId,
|
|
11151
|
-
policy: "cloud-quota",
|
|
11152
|
-
reason: capacityAdmission.reason,
|
|
11153
|
-
requiredPlacements: requirement.placements
|
|
11154
|
-
});
|
|
11155
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\u76EE\u6807\u4E0D\u6EE1\u8DB3\u5F53\u524D Prompt \u5BB9\u91CF\u8981\u6C42\uFF0C\u4FDD\u7559\u539F\u59CB\u9519\u8BEF", {
|
|
11156
|
-
fallbackModelId,
|
|
11157
|
-
reason: capacityAdmission.reason
|
|
11158
|
-
});
|
|
11159
|
-
return null;
|
|
11160
|
-
}
|
|
11161
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\uFF08run \u5185\u7EED\u8DD1\uFF09", {
|
|
11162
|
-
activeModelId,
|
|
11163
|
-
fallbackModelId,
|
|
11164
|
-
reason: error.message
|
|
11165
|
-
});
|
|
11166
|
-
fallbackObserver?.onCloudQuotaFallbackApplied?.(fallbackModelId);
|
|
11167
|
-
return fallbackModelId;
|
|
11168
|
-
}
|
|
11169
11016
|
|
|
11170
11017
|
// src/runtime-kernel/llm/usage-telemetry.ts
|
|
11171
11018
|
async function callPlainCompletion(inferencePort, modelId, messages, options = {}, signal, traceId) {
|
|
@@ -11268,7 +11115,7 @@ async function runLlmInputPreflight(params) {
|
|
|
11268
11115
|
}
|
|
11269
11116
|
|
|
11270
11117
|
// src/runtime-kernel/llm/retry-fallback.ts
|
|
11271
|
-
var
|
|
11118
|
+
var logger15 = new Logger("LlmCaller");
|
|
11272
11119
|
async function callWithRetryFallback(params) {
|
|
11273
11120
|
const {
|
|
11274
11121
|
deps,
|
|
@@ -11296,11 +11143,9 @@ async function callWithRetryFallback(params) {
|
|
|
11296
11143
|
const retryEpisode = new LlmRetryEpisode(traceId, eventHandler);
|
|
11297
11144
|
let previousAttemptTracker;
|
|
11298
11145
|
if (!clientRetryEnabled) {
|
|
11299
|
-
|
|
11300
|
-
logger16.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
11146
|
+
logger15.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
11301
11147
|
modelId,
|
|
11302
|
-
|
|
11303
|
-
reason: options.retry_policy === "none" ? "options.retry_policy=none" : "model config (cloud billing or enable_client_retry=false)"
|
|
11148
|
+
reason: options.retry_policy === "none" ? "options.retry_policy=none" : "model config enable_client_retry=false"
|
|
11304
11149
|
});
|
|
11305
11150
|
}
|
|
11306
11151
|
try {
|
|
@@ -11336,7 +11181,7 @@ async function callWithRetryFallback(params) {
|
|
|
11336
11181
|
}) : void 0;
|
|
11337
11182
|
try {
|
|
11338
11183
|
if (isRetry) {
|
|
11339
|
-
|
|
11184
|
+
logger15.info("LLM \u8C03\u7528\u91CD\u8BD5", { attempt, configuredMaxRetries });
|
|
11340
11185
|
}
|
|
11341
11186
|
actualAttempts++;
|
|
11342
11187
|
retryEpisode.retrying(actualAttempts);
|
|
@@ -11365,7 +11210,7 @@ async function callWithRetryFallback(params) {
|
|
|
11365
11210
|
if (deps.retryConfig.enableEmptyResponseRetry && !responseContent?.trim() && !toolCallsFromLLM?.length) {
|
|
11366
11211
|
throw new Error("LLM\u8FD4\u56DE\u4E86\u7A7A\u54CD\u5E94");
|
|
11367
11212
|
}
|
|
11368
|
-
|
|
11213
|
+
logger15.debug("LLM \u8C03\u7528\u6210\u529F", { attempts: actualAttempts, maxTotalAttempts });
|
|
11369
11214
|
if (attemptContextUsage) {
|
|
11370
11215
|
fallbackObserver?.onLlmAttemptSucceeded?.(activeModelId, attemptContextUsage);
|
|
11371
11216
|
} else {
|
|
@@ -11376,7 +11221,7 @@ async function callWithRetryFallback(params) {
|
|
|
11376
11221
|
} catch (error) {
|
|
11377
11222
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
11378
11223
|
if (lastError.name === "AbortError") {
|
|
11379
|
-
|
|
11224
|
+
logger15.info("LLM \u8C03\u7528\u5DF2\u53D6\u6D88\uFF0C\u4E0D\u8FDB\u5165 provider failure \u5206\u7C7B\u4E0E\u91CD\u8BD5\u6D41\u7A0B", {
|
|
11380
11225
|
attempt: attempt + 1,
|
|
11381
11226
|
actualAttempts,
|
|
11382
11227
|
maxTotalAttempts,
|
|
@@ -11395,7 +11240,7 @@ async function callWithRetryFallback(params) {
|
|
|
11395
11240
|
total_attempts: actualAttempts,
|
|
11396
11241
|
error_code: classification.errorCode
|
|
11397
11242
|
};
|
|
11398
|
-
|
|
11243
|
+
logger15.error("LLM \u8C03\u7528\u5931\u8D25", {
|
|
11399
11244
|
attempt: attempt + 1,
|
|
11400
11245
|
maxAttempts: currentMaxRetries + 1,
|
|
11401
11246
|
actualAttempts,
|
|
@@ -11404,7 +11249,7 @@ async function callWithRetryFallback(params) {
|
|
|
11404
11249
|
});
|
|
11405
11250
|
previousAttemptTracker = attemptTracker;
|
|
11406
11251
|
if (!hasLlmAttemptBudgetRemaining({ actualAttempts, maxTotalAttempts })) {
|
|
11407
|
-
|
|
11252
|
+
logger15.error("\u5DF2\u8FBE\u5230 LLM \u603B\u8C03\u7528\u6B21\u6570\u4E0A\u9650\uFF0C\u505C\u6B62\u91CD\u8BD5/\u5207\u6A21\u578B", {
|
|
11408
11253
|
actualAttempts,
|
|
11409
11254
|
maxTotalAttempts
|
|
11410
11255
|
});
|
|
@@ -11434,37 +11279,15 @@ async function callWithRetryFallback(params) {
|
|
|
11434
11279
|
attempt -= 1;
|
|
11435
11280
|
continue;
|
|
11436
11281
|
}
|
|
11437
|
-
const quotaFallbackModelId = tryCloudQuotaFallback({
|
|
11438
|
-
deps,
|
|
11439
|
-
activeModelId,
|
|
11440
|
-
options,
|
|
11441
|
-
excludedModelIds,
|
|
11442
|
-
requirement,
|
|
11443
|
-
error: lastError,
|
|
11444
|
-
fallbackObserver,
|
|
11445
|
-
evaluateFallbackPromptCapacity: invocationContext?.evaluateFallbackPromptCapacity
|
|
11446
|
-
});
|
|
11447
|
-
if (quotaFallbackModelId) {
|
|
11448
|
-
fallbackObserver?.onModelFallbackApplied?.({
|
|
11449
|
-
fromModelId: activeModelId,
|
|
11450
|
-
toModelId: quotaFallbackModelId,
|
|
11451
|
-
reason: lastError.message,
|
|
11452
|
-
policy: "cloud-quota"
|
|
11453
|
-
});
|
|
11454
|
-
activeModelId = quotaFallbackModelId;
|
|
11455
|
-
excludedModelIds.add(quotaFallbackModelId);
|
|
11456
|
-
attempt -= 1;
|
|
11457
|
-
continue;
|
|
11458
|
-
}
|
|
11459
11282
|
}
|
|
11460
11283
|
if (classification.category === "non_retryable" /* NON_RETRYABLE */) {
|
|
11461
|
-
|
|
11284
|
+
logger15.error("\u9519\u8BEF\u4E0D\u53EF\u91CD\u8BD5\uFF0C\u76F4\u63A5\u5931\u8D25", { reason: classification.reason });
|
|
11462
11285
|
retryEpisode.finish("failed", failedRetryState);
|
|
11463
11286
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
11464
11287
|
throw lastError;
|
|
11465
11288
|
}
|
|
11466
11289
|
if (attempt >= configuredMaxRetries || categoryRetries[category] >= currentMaxRetries) {
|
|
11467
|
-
|
|
11290
|
+
logger15.error("\u5DF2\u8FBE\u5230\u6700\u5927\u91CD\u8BD5\u6B21\u6570\uFF0C\u653E\u5F03\u91CD\u8BD5", { maxRetries: currentMaxRetries });
|
|
11468
11291
|
retryEpisode.finish("exhausted", failedRetryState);
|
|
11469
11292
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
11470
11293
|
throw lastError;
|
|
@@ -11476,9 +11299,9 @@ async function callWithRetryFallback(params) {
|
|
|
11476
11299
|
6e4
|
|
11477
11300
|
);
|
|
11478
11301
|
if (classification.category === "rate_limit" /* RATE_LIMIT */) {
|
|
11479
|
-
|
|
11302
|
+
logger15.warn("\u901F\u7387\u9650\u5236\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
11480
11303
|
} else if (classification.category === "retryable" /* RETRYABLE */) {
|
|
11481
|
-
|
|
11304
|
+
logger15.warn("\u53EF\u91CD\u8BD5\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
11482
11305
|
}
|
|
11483
11306
|
throwIfAborted(signal, "\u5EF6\u8FDF\u7B49\u5F85\u524D\u68C0\u6D4B\u5230\u53D6\u6D88\u4FE1\u53F7\uFF0C\u505C\u6B62\u91CD\u8BD5");
|
|
11484
11307
|
categoryRetries[category] += 1;
|
|
@@ -11515,16 +11338,11 @@ function waitForRetry(delayMs, signal) {
|
|
|
11515
11338
|
}
|
|
11516
11339
|
function isClientRetryEnabledForModel(modelCatalog, modelId, options) {
|
|
11517
11340
|
if (options.retry_policy === "none") return false;
|
|
11518
|
-
|
|
11519
|
-
if (cfg?.billing_mode === "cloud") return false;
|
|
11520
|
-
if (options.retry_policy === "client") return true;
|
|
11521
|
-
if (!cfg) return true;
|
|
11522
|
-
if (cfg.enable_client_retry === false) return false;
|
|
11523
|
-
return true;
|
|
11341
|
+
return modelCatalog.getModelById(modelId)?.enable_client_retry !== false;
|
|
11524
11342
|
}
|
|
11525
11343
|
function throwIfAborted(signal, message) {
|
|
11526
11344
|
if (!signal?.aborted) return;
|
|
11527
|
-
|
|
11345
|
+
logger15.info(message);
|
|
11528
11346
|
const reason = signal.reason;
|
|
11529
11347
|
if (reason instanceof Error && reason.name === "AbortError") throw reason;
|
|
11530
11348
|
const reasonText = typeof reason === "string" && reason.trim().length > 0 ? reason : "stream_interrupted";
|
|
@@ -12207,7 +12025,7 @@ function runMetaFromRecord(record) {
|
|
|
12207
12025
|
}
|
|
12208
12026
|
|
|
12209
12027
|
// src/runtime-kernel/run-supervisor/functions/awaitingUserWatcher.ts
|
|
12210
|
-
var
|
|
12028
|
+
var logger17 = new Logger("RunSupervisorAwaitingUserWatcher");
|
|
12211
12029
|
function isRecord16(value) {
|
|
12212
12030
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12213
12031
|
}
|
|
@@ -12252,7 +12070,7 @@ function createAwaitingUserWatcher(options) {
|
|
|
12252
12070
|
resumeToken: event.resume_token
|
|
12253
12071
|
}
|
|
12254
12072
|
}).catch((error) => {
|
|
12255
|
-
|
|
12073
|
+
logger17.warn("failed to mark awaiting_user from requires_user_interaction", { error });
|
|
12256
12074
|
});
|
|
12257
12075
|
};
|
|
12258
12076
|
const dispose = () => {
|