@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/cli.js
CHANGED
|
@@ -2218,18 +2218,6 @@ var ErrorClassifier = class {
|
|
|
2218
2218
|
});
|
|
2219
2219
|
}
|
|
2220
2220
|
}
|
|
2221
|
-
const quotaPatterns = ["\u5DF2\u8FBE\u4E0A\u9650", "\u514D\u8D39\u671F\u5DF2\u7ED3\u675F"];
|
|
2222
|
-
for (const pattern of quotaPatterns) {
|
|
2223
|
-
if (errorMessage.includes(pattern)) {
|
|
2224
|
-
logClassification(context, "\u68C0\u6D4B\u5230\u4E91\u7AEF\u989D\u5EA6\u9650\u5236\uFF0C\u4E0D\u91CD\u8BD5", { matchedPattern: pattern });
|
|
2225
|
-
return createClassification("non_retryable" /* NON_RETRYABLE */, `\u4E91\u7AEF\u989D\u5EA6\u9650\u5236: ${pattern}`, null, {
|
|
2226
|
-
errorCode: ENGINE_ERROR_CODES.LLM_PROVIDER_DOWN,
|
|
2227
|
-
recoverable: false,
|
|
2228
|
-
hint: "check_billing_or_provider_status",
|
|
2229
|
-
metadata: { matchedPattern: pattern }
|
|
2230
|
-
});
|
|
2231
|
-
}
|
|
2232
|
-
}
|
|
2233
2221
|
const authPatterns = [
|
|
2234
2222
|
{ pattern: "unauthorized", code: "401" },
|
|
2235
2223
|
{ pattern: "forbidden", code: "403" },
|
|
@@ -2484,17 +2472,6 @@ var ErrorClassifier = class {
|
|
|
2484
2472
|
}
|
|
2485
2473
|
return Math.max(baseDelay, classification.suggestedDelay ?? 0);
|
|
2486
2474
|
}
|
|
2487
|
-
static isCloudQuotaError(error) {
|
|
2488
|
-
const msg = (error.message || "").toLowerCase();
|
|
2489
|
-
const patterns = [
|
|
2490
|
-
"\u989D\u5EA6\u4E0A\u9650",
|
|
2491
|
-
"\u5DF2\u8FBE\u4E0A\u9650",
|
|
2492
|
-
"\u514D\u8D39\u671F\u5DF2\u7ED3\u675F",
|
|
2493
|
-
"\u8BE5\u6A21\u578B\u6682\u4E0D\u53EF\u7528",
|
|
2494
|
-
"cloud_quota_exhausted"
|
|
2495
|
-
];
|
|
2496
|
-
return patterns.some((pattern) => msg.includes(pattern));
|
|
2497
|
-
}
|
|
2498
2475
|
};
|
|
2499
2476
|
|
|
2500
2477
|
// src/shared/engineErrorEvent.ts
|
|
@@ -3978,8 +3955,8 @@ var TokenCalculator = class {
|
|
|
3978
3955
|
return;
|
|
3979
3956
|
}
|
|
3980
3957
|
this.failedEncodingWarnings.add(requestedEncoding);
|
|
3981
|
-
const
|
|
3982
|
-
|
|
3958
|
+
const logger18 = new Logger("TokenCalculator");
|
|
3959
|
+
logger18.warn("tiktoken encoding unavailable, falling back to avgCharsPerToken estimator", {
|
|
3983
3960
|
requestedEncoding,
|
|
3984
3961
|
error
|
|
3985
3962
|
});
|
|
@@ -4071,49 +4048,6 @@ var llmTelemetryMiddleware = async (ctx, stage, next) => {
|
|
|
4071
4048
|
});
|
|
4072
4049
|
};
|
|
4073
4050
|
|
|
4074
|
-
// src/runtime-kernel/graph-engine/functions/runModelLock.ts
|
|
4075
|
-
function readNonEmptyString4(value) {
|
|
4076
|
-
if (typeof value !== "string") return void 0;
|
|
4077
|
-
const trimmed = value.trim();
|
|
4078
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
4079
|
-
}
|
|
4080
|
-
function decideRunModelLockPatch(params) {
|
|
4081
|
-
if (params.stageId !== "execute_llm") {
|
|
4082
|
-
return { shouldLog: false };
|
|
4083
|
-
}
|
|
4084
|
-
const normalized = readNonEmptyString4(params.appliedFallbackModelId);
|
|
4085
|
-
if (!normalized) {
|
|
4086
|
-
return { shouldLog: false };
|
|
4087
|
-
}
|
|
4088
|
-
if (readNonEmptyString4(params.currentRunLockedModelId) === normalized) {
|
|
4089
|
-
return { shouldLog: false };
|
|
4090
|
-
}
|
|
4091
|
-
return {
|
|
4092
|
-
executorLocalPatch: { runLockedModelId: normalized },
|
|
4093
|
-
shouldLog: true
|
|
4094
|
-
};
|
|
4095
|
-
}
|
|
4096
|
-
|
|
4097
|
-
// src/runtime-kernel/graph-engine/tick-pipeline/middlewares/runModelLockMiddleware.ts
|
|
4098
|
-
var logger4 = new Logger("GraphAgentExecutor");
|
|
4099
|
-
var runModelLockMiddleware = async (ctx, stage, next) => {
|
|
4100
|
-
await next();
|
|
4101
|
-
const decision = decideRunModelLockPatch({
|
|
4102
|
-
stageId: stage.id,
|
|
4103
|
-
appliedFallbackModelId: ctx.cloudQuotaFallbackAppliedModelId,
|
|
4104
|
-
currentRunLockedModelId: ctx.executorLocalPatch?.runLockedModelId ?? ctx.executorLocal?.runLockedModelId
|
|
4105
|
-
});
|
|
4106
|
-
if (!decision.executorLocalPatch) {
|
|
4107
|
-
return;
|
|
4108
|
-
}
|
|
4109
|
-
if (decision.shouldLog) {
|
|
4110
|
-
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}`);
|
|
4111
|
-
}
|
|
4112
|
-
return {
|
|
4113
|
-
executorLocalPatch: decision.executorLocalPatch
|
|
4114
|
-
};
|
|
4115
|
-
};
|
|
4116
|
-
|
|
4117
4051
|
// src/runtime-kernel/graph-engine/tick-pipeline/runTickPipeline.ts
|
|
4118
4052
|
var tickPipelineContextKeys = [
|
|
4119
4053
|
"input",
|
|
@@ -4149,7 +4083,6 @@ var tickPipelineContextKeys = [
|
|
|
4149
4083
|
"decision",
|
|
4150
4084
|
"systemReminderHitRuleIds",
|
|
4151
4085
|
"contextTrace",
|
|
4152
|
-
"cloudQuotaFallbackAppliedModelId",
|
|
4153
4086
|
"modelFallbackAudit",
|
|
4154
4087
|
"telemetry",
|
|
4155
4088
|
"audit",
|
|
@@ -4488,7 +4421,7 @@ ${normalized}
|
|
|
4488
4421
|
}
|
|
4489
4422
|
|
|
4490
4423
|
// src/runtime-kernel/system-reminder/apply.ts
|
|
4491
|
-
var
|
|
4424
|
+
var logger4 = new Logger("SystemReminder");
|
|
4492
4425
|
var readString2 = (v) => {
|
|
4493
4426
|
if (typeof v !== "string") return void 0;
|
|
4494
4427
|
const s = v;
|
|
@@ -4551,7 +4484,7 @@ function applySystemReminders(params) {
|
|
|
4551
4484
|
} catch {
|
|
4552
4485
|
}
|
|
4553
4486
|
}
|
|
4554
|
-
|
|
4487
|
+
logger4.info("SystemReminder \u5DF2\u6CE8\u5165\u5230 LLM \u8F93\u5165\u672B\u5C3E", {
|
|
4555
4488
|
ruleIds: injectedRuleIds.length > 0 ? injectedRuleIds : Array.from(seenRuleIds),
|
|
4556
4489
|
promptKey: ctx.request.promptKey,
|
|
4557
4490
|
executorLocal: {
|
|
@@ -5043,7 +4976,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5043
4976
|
"turnId"
|
|
5044
4977
|
],
|
|
5045
4978
|
writes: [
|
|
5046
|
-
"cloudQuotaFallbackAppliedModelId",
|
|
5047
4979
|
"modelFallbackAudit",
|
|
5048
4980
|
"llmCallStartedAt",
|
|
5049
4981
|
"llmResp",
|
|
@@ -5051,7 +4983,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5051
4983
|
"contextUsage"
|
|
5052
4984
|
],
|
|
5053
4985
|
async run(ctx) {
|
|
5054
|
-
let cloudQuotaFallbackAppliedModelId;
|
|
5055
4986
|
let modelFallbackAudit;
|
|
5056
4987
|
let contextUsage;
|
|
5057
4988
|
const modelFallbackRejections = [];
|
|
@@ -5070,9 +5001,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5070
5001
|
streamEventHandler,
|
|
5071
5002
|
ctx.signal,
|
|
5072
5003
|
{
|
|
5073
|
-
onCloudQuotaFallbackApplied(fallbackModelId) {
|
|
5074
|
-
cloudQuotaFallbackAppliedModelId = readNonEmptyString3(fallbackModelId);
|
|
5075
|
-
},
|
|
5076
5004
|
onLlmAttemptSucceeded(_activeModelId, attemptContextUsage) {
|
|
5077
5005
|
contextUsage = attemptContextUsage;
|
|
5078
5006
|
},
|
|
@@ -5169,7 +5097,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5169
5097
|
});
|
|
5170
5098
|
}
|
|
5171
5099
|
return {
|
|
5172
|
-
cloudQuotaFallbackAppliedModelId,
|
|
5173
5100
|
modelFallbackAudit,
|
|
5174
5101
|
llmCallStartedAt,
|
|
5175
5102
|
llmResp,
|
|
@@ -6090,18 +6017,16 @@ function createPrepareCallStage(dependencies) {
|
|
|
6090
6017
|
"toolDefinitionTokens"
|
|
6091
6018
|
],
|
|
6092
6019
|
async run(ctx) {
|
|
6093
|
-
const
|
|
6094
|
-
const requestedModelId = lockedRunModelId ?? ctx.request.model_id;
|
|
6020
|
+
const requestedModelId = ctx.request.model_id;
|
|
6095
6021
|
const modelId = dependencies.modelResolver.resolveModelId(requestedModelId);
|
|
6096
6022
|
await emitAuditEnvelope(ctx.audit, {
|
|
6097
6023
|
action: "model.select",
|
|
6098
6024
|
actor: { kind: "system" },
|
|
6099
6025
|
decision: {
|
|
6100
6026
|
outcome: "recorded",
|
|
6101
|
-
reason:
|
|
6027
|
+
reason: requestedModelId ? "request model id" : "default model resolver",
|
|
6102
6028
|
metadata: {
|
|
6103
6029
|
requestedModelId,
|
|
6104
|
-
lockedRunModelId,
|
|
6105
6030
|
selectedModelId: modelId
|
|
6106
6031
|
}
|
|
6107
6032
|
},
|
|
@@ -6148,10 +6073,6 @@ function createPrepareCallStage(dependencies) {
|
|
|
6148
6073
|
if (ctx.executorLocal?.lockRequestedModelId === true) {
|
|
6149
6074
|
llmOptions.allow_model_fallback = false;
|
|
6150
6075
|
}
|
|
6151
|
-
const isRunContinuation = ctx.executorLocal?.llmInvocationKind === "continuation";
|
|
6152
|
-
if (dependencies.cloudQuotaFallbackModelId && modelConfig?.billing_mode === "cloud" && modelId !== dependencies.cloudQuotaFallbackModelId && isRunContinuation && ctx.executorLocal?.lockRequestedModelId !== true) {
|
|
6153
|
-
llmOptions.cloud_quota_fallback_model_id = dependencies.cloudQuotaFallbackModelId;
|
|
6154
|
-
}
|
|
6155
6076
|
const effectiveEffort = resolveEffectiveEffort(
|
|
6156
6077
|
ctx.request.reasoning_effort,
|
|
6157
6078
|
modelConfig?.reasoning
|
|
@@ -6268,12 +6189,11 @@ function applyCalibration(rawLocalTotal, imageInputTokens, coefficient) {
|
|
|
6268
6189
|
}
|
|
6269
6190
|
|
|
6270
6191
|
// src/runtime-kernel/graph-engine/executor.ts
|
|
6271
|
-
var
|
|
6192
|
+
var logger5 = new Logger("GraphAgentExecutor");
|
|
6272
6193
|
var GraphAgentExecutor = class {
|
|
6273
6194
|
llmCaller;
|
|
6274
6195
|
toolRuntime;
|
|
6275
6196
|
contextBuilder;
|
|
6276
|
-
cloudQuotaFallbackModelId;
|
|
6277
6197
|
modelResolver;
|
|
6278
6198
|
modelCatalog;
|
|
6279
6199
|
telemetryPort;
|
|
@@ -6285,7 +6205,6 @@ var GraphAgentExecutor = class {
|
|
|
6285
6205
|
this.llmCaller = dependencies.llmCaller;
|
|
6286
6206
|
this.toolRuntime = dependencies.toolRuntime;
|
|
6287
6207
|
this.contextBuilder = dependencies.contextBuilder;
|
|
6288
|
-
this.cloudQuotaFallbackModelId = readNonEmptyString3(dependencies.cloudQuotaFallbackModelId);
|
|
6289
6208
|
this.modelCatalog = dependencies.modelCatalog ?? createEmptyModelCatalog();
|
|
6290
6209
|
this.modelResolver = dependencies.modelResolver ?? new ModelResolver({
|
|
6291
6210
|
modelCatalog: this.modelCatalog
|
|
@@ -6302,8 +6221,7 @@ var GraphAgentExecutor = class {
|
|
|
6302
6221
|
createPrepareCallStage({
|
|
6303
6222
|
modelResolver: this.modelResolver,
|
|
6304
6223
|
modelCatalog: this.modelCatalog,
|
|
6305
|
-
toolCatalog: this.toolRuntime
|
|
6306
|
-
cloudQuotaFallbackModelId: this.cloudQuotaFallbackModelId
|
|
6224
|
+
toolCatalog: this.toolRuntime
|
|
6307
6225
|
}),
|
|
6308
6226
|
createBuildContextStage({
|
|
6309
6227
|
contextBuilder: this.contextBuilder
|
|
@@ -6325,7 +6243,7 @@ var GraphAgentExecutor = class {
|
|
|
6325
6243
|
}),
|
|
6326
6244
|
createBuildDecisionStage()
|
|
6327
6245
|
];
|
|
6328
|
-
this.middlewares = [llmTelemetryMiddleware
|
|
6246
|
+
this.middlewares = [llmTelemetryMiddleware];
|
|
6329
6247
|
}
|
|
6330
6248
|
async tick(input, eventHandler) {
|
|
6331
6249
|
const ctx = {
|
|
@@ -6350,7 +6268,7 @@ var GraphAgentExecutor = class {
|
|
|
6350
6268
|
audit: this.auditPort,
|
|
6351
6269
|
tokenizer: this.tokenizer
|
|
6352
6270
|
};
|
|
6353
|
-
|
|
6271
|
+
logger5.info("[GraphAgentExecutor] tick \u8C03\u7528", {
|
|
6354
6272
|
stream: input.stream === true,
|
|
6355
6273
|
hasEventHandler: Boolean(eventHandler),
|
|
6356
6274
|
hasSummarizationCallbacks: Boolean(input.summarizationCallbacks)
|
|
@@ -7373,7 +7291,7 @@ var LlmNodeEventBridge = class {
|
|
|
7373
7291
|
};
|
|
7374
7292
|
|
|
7375
7293
|
// src/runtime-kernel/graph-engine/nodes/llmNode.ts
|
|
7376
|
-
var
|
|
7294
|
+
var logger6 = new Logger("LlmNode");
|
|
7377
7295
|
var LlmNode = class {
|
|
7378
7296
|
id = "llm";
|
|
7379
7297
|
reasoner;
|
|
@@ -7382,7 +7300,7 @@ var LlmNode = class {
|
|
|
7382
7300
|
}
|
|
7383
7301
|
async run(state) {
|
|
7384
7302
|
const local = state.local ?? {};
|
|
7385
|
-
|
|
7303
|
+
logger6.info("[LlmNode] \u5F00\u59CB\u6267\u884C LLM \u8282\u70B9", {
|
|
7386
7304
|
localKeys: Object.keys(local)
|
|
7387
7305
|
});
|
|
7388
7306
|
const graphLocal = readGraphAgentLocal(state.local);
|
|
@@ -7397,12 +7315,12 @@ var LlmNode = class {
|
|
|
7397
7315
|
signal,
|
|
7398
7316
|
history
|
|
7399
7317
|
} = graphLocal;
|
|
7400
|
-
|
|
7318
|
+
logger6.info("[LlmNode] \u5DF2\u52A0\u8F7D\u5386\u53F2\u4E8B\u4EF6", {
|
|
7401
7319
|
historyCount: history.length,
|
|
7402
7320
|
hasSummarizationCallbacks: Boolean(summarizationCallbacks)
|
|
7403
7321
|
});
|
|
7404
7322
|
if (!request) {
|
|
7405
|
-
|
|
7323
|
+
logger6.warn("Request object is missing, yielding.");
|
|
7406
7324
|
return { kind: "yield", events: [] };
|
|
7407
7325
|
}
|
|
7408
7326
|
const turnId = requireRuntimeIdentity(graphLocal.turnId, "turnId");
|
|
@@ -7495,12 +7413,12 @@ var LlmNode = class {
|
|
|
7495
7413
|
...nodeState.streamRuntimeEvents,
|
|
7496
7414
|
...contextUsageEvent ? [contextUsageEvent] : []
|
|
7497
7415
|
];
|
|
7498
|
-
|
|
7416
|
+
logger6.info("[LlmNode] \u5386\u53F2\u4E8B\u4EF6\u5DF2\u66F4\u65B0", {
|
|
7499
7417
|
previousCount: history.length,
|
|
7500
7418
|
nextCount: patch.history.length,
|
|
7501
7419
|
streamedEventCount: nodeState.streamRuntimeEvents.length
|
|
7502
7420
|
});
|
|
7503
|
-
|
|
7421
|
+
logger6.info("[LlmNode] \u6267\u884C\u5668\u51B3\u7B56\u5B8C\u6210", {
|
|
7504
7422
|
decisionKind: decision.kind,
|
|
7505
7423
|
emittedEventCount: combinedEvents.length
|
|
7506
7424
|
});
|
|
@@ -7522,7 +7440,7 @@ var LlmNode = class {
|
|
|
7522
7440
|
}
|
|
7523
7441
|
case "error": {
|
|
7524
7442
|
const { name, message, stack } = decision.error;
|
|
7525
|
-
|
|
7443
|
+
logger6.error("[LlmNode] Executor returned an error", { name, message, stack });
|
|
7526
7444
|
return { kind: "yield", events: combinedEvents };
|
|
7527
7445
|
}
|
|
7528
7446
|
default: {
|
|
@@ -7628,7 +7546,7 @@ async function resolveToolModelInput(input) {
|
|
|
7628
7546
|
}
|
|
7629
7547
|
|
|
7630
7548
|
// src/runtime-kernel/graph-engine/nodes/toolNode.finalAnswerProjector.ts
|
|
7631
|
-
function
|
|
7549
|
+
function readNonEmptyString4(value) {
|
|
7632
7550
|
if (typeof value !== "string") {
|
|
7633
7551
|
return void 0;
|
|
7634
7552
|
}
|
|
@@ -7636,7 +7554,7 @@ function readNonEmptyString5(value) {
|
|
|
7636
7554
|
return normalized.length > 0 ? normalized : void 0;
|
|
7637
7555
|
}
|
|
7638
7556
|
function resolveFinalAnswerFromToolControl(finalAnswer) {
|
|
7639
|
-
return
|
|
7557
|
+
return readNonEmptyString4(finalAnswer);
|
|
7640
7558
|
}
|
|
7641
7559
|
|
|
7642
7560
|
// src/runtime-kernel/graph-engine/nodes/toolNode.helpers.ts
|
|
@@ -7892,7 +7810,7 @@ function buildErrorLocalState(params) {
|
|
|
7892
7810
|
}
|
|
7893
7811
|
|
|
7894
7812
|
// src/runtime-kernel/tools/argNormalizer.ts
|
|
7895
|
-
var
|
|
7813
|
+
var logger7 = new Logger("ToolArgNormalizer");
|
|
7896
7814
|
function isRecord10(v) {
|
|
7897
7815
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
7898
7816
|
}
|
|
@@ -7912,7 +7830,7 @@ function joinPath(basePath, segment) {
|
|
|
7912
7830
|
function logJsonEncodedNormalization(expectedType, options) {
|
|
7913
7831
|
const toolPrefix = options.toolName ? `${options.toolName}.` : "";
|
|
7914
7832
|
const path = options.path ?? "<root>";
|
|
7915
|
-
|
|
7833
|
+
logger7.warn("normalized JSON-encoded tool argument", {
|
|
7916
7834
|
expectedType,
|
|
7917
7835
|
path: `${toolPrefix}${path}`
|
|
7918
7836
|
});
|
|
@@ -8208,7 +8126,7 @@ function ensureToolContextRuntimeCapability(params) {
|
|
|
8208
8126
|
}
|
|
8209
8127
|
|
|
8210
8128
|
// src/runtime-kernel/graph-engine/nodes/toolNode.eventBridge.ts
|
|
8211
|
-
var
|
|
8129
|
+
var logger8 = new Logger("ToolNode");
|
|
8212
8130
|
var ToolNodeEventBridge = class {
|
|
8213
8131
|
constructor(deps) {
|
|
8214
8132
|
this.deps = deps;
|
|
@@ -8230,7 +8148,7 @@ var ToolNodeEventBridge = class {
|
|
|
8230
8148
|
status,
|
|
8231
8149
|
payload: { ...payload }
|
|
8232
8150
|
};
|
|
8233
|
-
|
|
8151
|
+
logger8.info("[ToolNode] \u53D1\u51FA tool_process \u4E8B\u4EF6", {
|
|
8234
8152
|
phase,
|
|
8235
8153
|
status,
|
|
8236
8154
|
toolName: this.deps.toolName,
|
|
@@ -8270,7 +8188,7 @@ var ToolNodeEventBridge = class {
|
|
|
8270
8188
|
const answerId = generateAnswerSegmentId();
|
|
8271
8189
|
const id = answerId;
|
|
8272
8190
|
const timestamp = Date.now();
|
|
8273
|
-
|
|
8191
|
+
logger8.info("[ToolNode] \u5DE5\u5177\u8F93\u51FA\u6620\u5C04\u4E3A final_answer", {
|
|
8274
8192
|
sourceToolName: params.sourceToolName,
|
|
8275
8193
|
toolCallId: this.deps.toolCallId,
|
|
8276
8194
|
conversationId: this.deps.conversationId,
|
|
@@ -8328,7 +8246,7 @@ var ToolNodeEventBridge = class {
|
|
|
8328
8246
|
};
|
|
8329
8247
|
|
|
8330
8248
|
// src/runtime-kernel/graph-engine/nodes/toolNode.executionSetup.ts
|
|
8331
|
-
var
|
|
8249
|
+
var logger9 = new Logger("ToolNode");
|
|
8332
8250
|
function parseToolArgs(call) {
|
|
8333
8251
|
const rawArguments = typeof call.function?.arguments === "string" ? call.function.arguments : "";
|
|
8334
8252
|
if (!rawArguments.trim()) {
|
|
@@ -8348,19 +8266,13 @@ function parseToolArgs(call) {
|
|
|
8348
8266
|
return { ok: true, value: parsed };
|
|
8349
8267
|
} catch (error) {
|
|
8350
8268
|
const reason = error instanceof Error ? error.message : "Unknown JSON parse error";
|
|
8351
|
-
|
|
8269
|
+
logger9.warn("failed to parse tool arguments", { error });
|
|
8352
8270
|
return {
|
|
8353
8271
|
ok: false,
|
|
8354
8272
|
error: `Tool arguments are not valid JSON: ${reason}`
|
|
8355
8273
|
};
|
|
8356
8274
|
}
|
|
8357
8275
|
}
|
|
8358
|
-
function readRunLockedModelId(local) {
|
|
8359
|
-
const executorLocal = local.executorLocal;
|
|
8360
|
-
if (!isRecord9(executorLocal)) return void 0;
|
|
8361
|
-
const lockedModelId = executorLocal.runLockedModelId;
|
|
8362
|
-
return typeof lockedModelId === "string" && lockedModelId.trim() ? lockedModelId : void 0;
|
|
8363
|
-
}
|
|
8364
8276
|
function prepareToolNodeContext(state) {
|
|
8365
8277
|
const local = state.local || {};
|
|
8366
8278
|
const toolContext = isRecord9(local.toolContext) ? local.toolContext : {};
|
|
@@ -8378,7 +8290,6 @@ function prepareToolNodeContext(state) {
|
|
|
8378
8290
|
}
|
|
8379
8291
|
});
|
|
8380
8292
|
attachWorkingHistoryView({ state, toolContext });
|
|
8381
|
-
toolContext.activeModelId = readRunLockedModelId(local) ?? toolContext.modelId;
|
|
8382
8293
|
return {
|
|
8383
8294
|
state,
|
|
8384
8295
|
local,
|
|
@@ -8749,7 +8660,7 @@ async function claimPendingUserInputs(state, result) {
|
|
|
8749
8660
|
}
|
|
8750
8661
|
|
|
8751
8662
|
// src/runtime-kernel/graph-engine/nodes/toolNode.ts
|
|
8752
|
-
var
|
|
8663
|
+
var logger10 = new Logger("ToolNode");
|
|
8753
8664
|
function isAbortSignal(value) {
|
|
8754
8665
|
return value !== null && typeof value === "object" && "aborted" in value;
|
|
8755
8666
|
}
|
|
@@ -8962,7 +8873,7 @@ var ToolNode = class {
|
|
|
8962
8873
|
throw abortError;
|
|
8963
8874
|
}
|
|
8964
8875
|
const prepared = prepareToolNodeContext(state);
|
|
8965
|
-
|
|
8876
|
+
logger10.info("[ToolNode] \u5F00\u59CB\u6267\u884C\u5DE5\u5177\u8282\u70B9", {
|
|
8966
8877
|
conversationId: prepared.conversationId,
|
|
8967
8878
|
turnId: prepared.turnId,
|
|
8968
8879
|
pendingCallCount: calls.length
|
|
@@ -8977,7 +8888,7 @@ var ToolNode = class {
|
|
|
8977
8888
|
toolCatalog: this.toolRuntime
|
|
8978
8889
|
});
|
|
8979
8890
|
if (!execution) {
|
|
8980
|
-
|
|
8891
|
+
logger10.warn("no tool name found in call");
|
|
8981
8892
|
return { kind: "yield", events: [] };
|
|
8982
8893
|
}
|
|
8983
8894
|
if (typeof execution.protocolError === "string") {
|
|
@@ -9017,7 +8928,7 @@ var ToolNode = class {
|
|
|
9017
8928
|
call,
|
|
9018
8929
|
context: prepared.toolContext,
|
|
9019
8930
|
abortGraceMs: this.abortGraceMs,
|
|
9020
|
-
onAbandon: () =>
|
|
8931
|
+
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", {
|
|
9021
8932
|
toolName: execution.toolName,
|
|
9022
8933
|
toolCallId: execution.toolCallId,
|
|
9023
8934
|
conversationId: prepared.conversationId,
|
|
@@ -9187,7 +9098,7 @@ var ToolNode = class {
|
|
|
9187
9098
|
runtimeEvents: context.bridge.getRuntimeEvents()
|
|
9188
9099
|
});
|
|
9189
9100
|
if (control?.terminateRun) {
|
|
9190
|
-
|
|
9101
|
+
logger10.info("[ToolNode] \u6536\u5230 control.terminateRun\uFF0C\u6267\u884C\u5B8C\u5DE5\u5177\u540E\u76F4\u63A5 yield \u7ED3\u675F\u672C\u8F6E run", {
|
|
9191
9102
|
toolName: context.toolName,
|
|
9192
9103
|
toolCallId: context.toolCallId,
|
|
9193
9104
|
conversationId: context.conversationId,
|
|
@@ -9196,7 +9107,7 @@ var ToolNode = class {
|
|
|
9196
9107
|
return { kind: "yield", events: context.bridge.getRuntimeEvents() };
|
|
9197
9108
|
}
|
|
9198
9109
|
if (remainingCalls.length === 0 && context.local.toolBatchCompletionMode === "yield_after_batch") {
|
|
9199
|
-
|
|
9110
|
+
logger10.info("[ToolNode] \u5DE5\u5177\u6279\u6B21\u5DF2\u7ED3\u7B97\uFF0C\u6309 Host \u7B56\u7565\u76F4\u63A5 yield", {
|
|
9200
9111
|
toolName: context.toolName,
|
|
9201
9112
|
toolCallId: context.toolCallId,
|
|
9202
9113
|
conversationId: context.conversationId,
|
|
@@ -9643,8 +9554,9 @@ var executor = z.object({
|
|
|
9643
9554
|
lastStepsHintThreshold: counter.optional(),
|
|
9644
9555
|
systemReminderPolicy: AgentSpecSystemReminderPolicy.optional(),
|
|
9645
9556
|
toolObservationPolicy: AgentSpecToolObservationGovernancePolicy.optional(),
|
|
9557
|
+
// 已删除字段:0.45 及更早的 checkpoint 可能带 lastSuccessfulLlmModelId,0.46 及更早的可能带云端额度兜底留下的
|
|
9558
|
+
// runLockedModelId;照常接受,读入时丢弃(兜底已移除,恢复后按请求的模型继续)。
|
|
9646
9559
|
runLockedModelId: z.string().optional(),
|
|
9647
|
-
// 0.45 及更早的 checkpoint 可能带这个已删除字段;照常接受,读入时丢弃。
|
|
9648
9560
|
lastSuccessfulLlmModelId: z.string().optional(),
|
|
9649
9561
|
llmInvocationKind: z.enum(["user_initiated", "continuation"]).optional(),
|
|
9650
9562
|
llmInvocationCount: counter.optional(),
|
|
@@ -9654,7 +9566,7 @@ var executor = z.object({
|
|
|
9654
9566
|
committedCount: counter,
|
|
9655
9567
|
lastCommittedFingerprint: z.string().optional()
|
|
9656
9568
|
}).strict().optional()
|
|
9657
|
-
}).strict().transform(({ lastSuccessfulLlmModelId: _retired, ...state }) => state);
|
|
9569
|
+
}).strict().transform(({ lastSuccessfulLlmModelId: _retired, runLockedModelId: _retiredLock, ...state }) => state);
|
|
9658
9570
|
var checkpoint = z.object({
|
|
9659
9571
|
nodeId: z.string().min(1),
|
|
9660
9572
|
schemaVersion: z.literal(ENGINE_STATE_SCHEMA_VERSION).optional(),
|
|
@@ -9716,7 +9628,7 @@ __export(execution_exports, {
|
|
|
9716
9628
|
});
|
|
9717
9629
|
|
|
9718
9630
|
// src/runtime-kernel/execution/event-bus.ts
|
|
9719
|
-
var
|
|
9631
|
+
var logger11 = new Logger("EventBus");
|
|
9720
9632
|
var TypedEventEmitter = class {
|
|
9721
9633
|
listeners = /* @__PURE__ */ new Map();
|
|
9722
9634
|
maxListeners = 10;
|
|
@@ -9724,7 +9636,7 @@ var TypedEventEmitter = class {
|
|
|
9724
9636
|
const listeners = this.getListeners(event);
|
|
9725
9637
|
listeners.add(listener);
|
|
9726
9638
|
if (listeners.size > this.maxListeners) {
|
|
9727
|
-
|
|
9639
|
+
logger11.warn("EventBus listener count exceeds configured max", {
|
|
9728
9640
|
event: String(event),
|
|
9729
9641
|
count: listeners.size,
|
|
9730
9642
|
maxListeners: this.maxListeners
|
|
@@ -9784,7 +9696,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
9784
9696
|
super();
|
|
9785
9697
|
this.executionId = executionId;
|
|
9786
9698
|
this.setMaxListeners(30);
|
|
9787
|
-
|
|
9699
|
+
logger11.info(`EventBus created for execution ${this.executionId}`);
|
|
9788
9700
|
}
|
|
9789
9701
|
/**
|
|
9790
9702
|
* 发布一个事件到总线
|
|
@@ -9793,7 +9705,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
9793
9705
|
publish(envelope) {
|
|
9794
9706
|
if (envelope.trace.execution_id !== this.executionId) {
|
|
9795
9707
|
const error = new Error("EventEnvelope execution_id does not match EventBus instance.");
|
|
9796
|
-
|
|
9708
|
+
logger11.error("Mismatched execution_id", {
|
|
9797
9709
|
busExecutionId: this.executionId,
|
|
9798
9710
|
eventExecutionId: envelope.trace.execution_id,
|
|
9799
9711
|
eventSeq: envelope.seq
|
|
@@ -9805,7 +9717,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
9805
9717
|
const error = new Error(
|
|
9806
9718
|
"EventBus only accepts RuntimeEvent with formal run routing identity."
|
|
9807
9719
|
);
|
|
9808
|
-
|
|
9720
|
+
logger11.error("RuntimeEvent is missing formal run routing identity", {
|
|
9809
9721
|
executionId: this.executionId,
|
|
9810
9722
|
eventId: envelope.payload.id,
|
|
9811
9723
|
eventType: envelope.payload.type
|
|
@@ -9819,14 +9731,14 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
9819
9731
|
* 关闭总线,清理所有监听器
|
|
9820
9732
|
*/
|
|
9821
9733
|
close() {
|
|
9822
|
-
|
|
9734
|
+
logger11.info(`Closing EventBus for execution ${this.executionId}`);
|
|
9823
9735
|
this.emit("close");
|
|
9824
9736
|
this.removeAllListeners();
|
|
9825
9737
|
}
|
|
9826
9738
|
};
|
|
9827
9739
|
|
|
9828
9740
|
// src/runtime-kernel/execution/sequencer.ts
|
|
9829
|
-
var
|
|
9741
|
+
var logger12 = new Logger("EventSequencer");
|
|
9830
9742
|
var EventSequencer = class {
|
|
9831
9743
|
executionId;
|
|
9832
9744
|
traceId;
|
|
@@ -9834,7 +9746,7 @@ var EventSequencer = class {
|
|
|
9834
9746
|
constructor(conversationId, traceId) {
|
|
9835
9747
|
this.executionId = generateExecutionId();
|
|
9836
9748
|
this.traceId = traceId || generateTraceId();
|
|
9837
|
-
|
|
9749
|
+
logger12.info(`EventSequencer created for conversation ${conversationId}`, {
|
|
9838
9750
|
executionId: this.executionId,
|
|
9839
9751
|
traceId: this.traceId
|
|
9840
9752
|
});
|
|
@@ -10647,7 +10559,7 @@ var ThoughtStreamSegmenter = class {
|
|
|
10647
10559
|
};
|
|
10648
10560
|
|
|
10649
10561
|
// src/runtime-kernel/llm/streaming-adapter.ts
|
|
10650
|
-
var
|
|
10562
|
+
var logger13 = new Logger("LlmCaller");
|
|
10651
10563
|
var CanonicalInferenceFailureError = class extends Error {
|
|
10652
10564
|
errorCode;
|
|
10653
10565
|
recoverable;
|
|
@@ -10871,7 +10783,7 @@ async function callLlmStream(params) {
|
|
|
10871
10783
|
} catch (error) {
|
|
10872
10784
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
10873
10785
|
if (normalized.name === "AbortError") {
|
|
10874
|
-
|
|
10786
|
+
logger13.info("Canonical inference \u6536\u5230\u53D6\u6D88\u7EC8\u6001\uFF0C\u4E0D\u53D1\u5E03\u666E\u901A error event", { modelId });
|
|
10875
10787
|
throw normalized;
|
|
10876
10788
|
}
|
|
10877
10789
|
const classification = ErrorClassifier.classify(normalized, {
|
|
@@ -10947,7 +10859,7 @@ var LlmRetryEpisode = class {
|
|
|
10947
10859
|
};
|
|
10948
10860
|
|
|
10949
10861
|
// src/runtime-kernel/llm/retry-fallback-routing.ts
|
|
10950
|
-
var
|
|
10862
|
+
var logger14 = new Logger("LlmCaller");
|
|
10951
10863
|
function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement, fallbackObserver, error, evaluateFallbackPromptCapacity2) {
|
|
10952
10864
|
deps.modelCatalog.getModelById(activeModelId);
|
|
10953
10865
|
const policyDecision = deps.policyEngine.decideOnError(error, {
|
|
@@ -10977,81 +10889,16 @@ function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement
|
|
|
10977
10889
|
reason: "no_eligible_fallback_candidate",
|
|
10978
10890
|
requiredPlacements: requirement.placements
|
|
10979
10891
|
});
|
|
10980
|
-
|
|
10892
|
+
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");
|
|
10981
10893
|
return null;
|
|
10982
10894
|
}
|
|
10983
|
-
|
|
10895
|
+
logger14.warn("Policy \u5207\u6362\u6A21\u578B\u7EE7\u7EED", {
|
|
10984
10896
|
reason: policyDecision.reason,
|
|
10985
10897
|
activeModelId,
|
|
10986
10898
|
fallbackModelId
|
|
10987
10899
|
});
|
|
10988
10900
|
return fallbackModelId;
|
|
10989
10901
|
}
|
|
10990
|
-
function tryCloudQuotaFallback({
|
|
10991
|
-
deps,
|
|
10992
|
-
activeModelId,
|
|
10993
|
-
options,
|
|
10994
|
-
excludedModelIds,
|
|
10995
|
-
requirement,
|
|
10996
|
-
error,
|
|
10997
|
-
fallbackObserver,
|
|
10998
|
-
evaluateFallbackPromptCapacity: evaluateFallbackPromptCapacity2
|
|
10999
|
-
}) {
|
|
11000
|
-
const fallbackModelId = options.cloud_quota_fallback_model_id;
|
|
11001
|
-
if (!fallbackModelId || !ErrorClassifier.isCloudQuotaError(error) || excludedModelIds.has(fallbackModelId)) {
|
|
11002
|
-
return null;
|
|
11003
|
-
}
|
|
11004
|
-
const fallbackConfig = deps.modelCatalog.getModelById(fallbackModelId);
|
|
11005
|
-
if (!fallbackConfig?.api_key) {
|
|
11006
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11007
|
-
fromModelId: activeModelId,
|
|
11008
|
-
candidateModelId: fallbackModelId,
|
|
11009
|
-
policy: "cloud-quota",
|
|
11010
|
-
reason: "fallback_model_unavailable",
|
|
11011
|
-
requiredPlacements: requirement.placements
|
|
11012
|
-
});
|
|
11013
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\u76EE\u6807\u4E0D\u53EF\u7528\uFF08\u672A\u6CE8\u518C\u6216\u7F3A\u5C11 API Key\uFF09", { fallbackModelId });
|
|
11014
|
-
return null;
|
|
11015
|
-
}
|
|
11016
|
-
const compatibility = evaluateModelInputCompatibility(fallbackConfig, requirement);
|
|
11017
|
-
if (!compatibility.compatible) {
|
|
11018
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11019
|
-
fromModelId: activeModelId,
|
|
11020
|
-
candidateModelId: fallbackModelId,
|
|
11021
|
-
policy: "cloud-quota",
|
|
11022
|
-
reason: compatibility.reason,
|
|
11023
|
-
requiredPlacements: requirement.placements
|
|
11024
|
-
});
|
|
11025
|
-
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", {
|
|
11026
|
-
fallbackModelId,
|
|
11027
|
-
requiredPlacements: requirement.placements,
|
|
11028
|
-
reason: compatibility.reason
|
|
11029
|
-
});
|
|
11030
|
-
return null;
|
|
11031
|
-
}
|
|
11032
|
-
const capacityAdmission = evaluateFallbackPromptCapacity2?.(fallbackModelId);
|
|
11033
|
-
if (capacityAdmission && !capacityAdmission.admitted) {
|
|
11034
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11035
|
-
fromModelId: activeModelId,
|
|
11036
|
-
candidateModelId: fallbackModelId,
|
|
11037
|
-
policy: "cloud-quota",
|
|
11038
|
-
reason: capacityAdmission.reason,
|
|
11039
|
-
requiredPlacements: requirement.placements
|
|
11040
|
-
});
|
|
11041
|
-
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", {
|
|
11042
|
-
fallbackModelId,
|
|
11043
|
-
reason: capacityAdmission.reason
|
|
11044
|
-
});
|
|
11045
|
-
return null;
|
|
11046
|
-
}
|
|
11047
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\uFF08run \u5185\u7EED\u8DD1\uFF09", {
|
|
11048
|
-
activeModelId,
|
|
11049
|
-
fallbackModelId,
|
|
11050
|
-
reason: error.message
|
|
11051
|
-
});
|
|
11052
|
-
fallbackObserver?.onCloudQuotaFallbackApplied?.(fallbackModelId);
|
|
11053
|
-
return fallbackModelId;
|
|
11054
|
-
}
|
|
11055
10902
|
|
|
11056
10903
|
// src/runtime-kernel/llm/usage-telemetry.ts
|
|
11057
10904
|
async function callPlainCompletion(inferencePort, modelId, messages, options = {}, signal, traceId) {
|
|
@@ -11154,7 +11001,7 @@ async function runLlmInputPreflight(params) {
|
|
|
11154
11001
|
}
|
|
11155
11002
|
|
|
11156
11003
|
// src/runtime-kernel/llm/retry-fallback.ts
|
|
11157
|
-
var
|
|
11004
|
+
var logger15 = new Logger("LlmCaller");
|
|
11158
11005
|
async function callWithRetryFallback(params) {
|
|
11159
11006
|
const {
|
|
11160
11007
|
deps,
|
|
@@ -11182,11 +11029,9 @@ async function callWithRetryFallback(params) {
|
|
|
11182
11029
|
const retryEpisode = new LlmRetryEpisode(traceId, eventHandler);
|
|
11183
11030
|
let previousAttemptTracker;
|
|
11184
11031
|
if (!clientRetryEnabled) {
|
|
11185
|
-
|
|
11186
|
-
logger16.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
11032
|
+
logger15.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
11187
11033
|
modelId,
|
|
11188
|
-
|
|
11189
|
-
reason: options.retry_policy === "none" ? "options.retry_policy=none" : "model config (cloud billing or enable_client_retry=false)"
|
|
11034
|
+
reason: options.retry_policy === "none" ? "options.retry_policy=none" : "model config enable_client_retry=false"
|
|
11190
11035
|
});
|
|
11191
11036
|
}
|
|
11192
11037
|
try {
|
|
@@ -11222,7 +11067,7 @@ async function callWithRetryFallback(params) {
|
|
|
11222
11067
|
}) : void 0;
|
|
11223
11068
|
try {
|
|
11224
11069
|
if (isRetry) {
|
|
11225
|
-
|
|
11070
|
+
logger15.info("LLM \u8C03\u7528\u91CD\u8BD5", { attempt, configuredMaxRetries });
|
|
11226
11071
|
}
|
|
11227
11072
|
actualAttempts++;
|
|
11228
11073
|
retryEpisode.retrying(actualAttempts);
|
|
@@ -11251,7 +11096,7 @@ async function callWithRetryFallback(params) {
|
|
|
11251
11096
|
if (deps.retryConfig.enableEmptyResponseRetry && !responseContent?.trim() && !toolCallsFromLLM?.length) {
|
|
11252
11097
|
throw new Error("LLM\u8FD4\u56DE\u4E86\u7A7A\u54CD\u5E94");
|
|
11253
11098
|
}
|
|
11254
|
-
|
|
11099
|
+
logger15.debug("LLM \u8C03\u7528\u6210\u529F", { attempts: actualAttempts, maxTotalAttempts });
|
|
11255
11100
|
if (attemptContextUsage) {
|
|
11256
11101
|
fallbackObserver?.onLlmAttemptSucceeded?.(activeModelId, attemptContextUsage);
|
|
11257
11102
|
} else {
|
|
@@ -11262,7 +11107,7 @@ async function callWithRetryFallback(params) {
|
|
|
11262
11107
|
} catch (error) {
|
|
11263
11108
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
11264
11109
|
if (lastError.name === "AbortError") {
|
|
11265
|
-
|
|
11110
|
+
logger15.info("LLM \u8C03\u7528\u5DF2\u53D6\u6D88\uFF0C\u4E0D\u8FDB\u5165 provider failure \u5206\u7C7B\u4E0E\u91CD\u8BD5\u6D41\u7A0B", {
|
|
11266
11111
|
attempt: attempt + 1,
|
|
11267
11112
|
actualAttempts,
|
|
11268
11113
|
maxTotalAttempts,
|
|
@@ -11281,7 +11126,7 @@ async function callWithRetryFallback(params) {
|
|
|
11281
11126
|
total_attempts: actualAttempts,
|
|
11282
11127
|
error_code: classification.errorCode
|
|
11283
11128
|
};
|
|
11284
|
-
|
|
11129
|
+
logger15.error("LLM \u8C03\u7528\u5931\u8D25", {
|
|
11285
11130
|
attempt: attempt + 1,
|
|
11286
11131
|
maxAttempts: currentMaxRetries + 1,
|
|
11287
11132
|
actualAttempts,
|
|
@@ -11290,7 +11135,7 @@ async function callWithRetryFallback(params) {
|
|
|
11290
11135
|
});
|
|
11291
11136
|
previousAttemptTracker = attemptTracker;
|
|
11292
11137
|
if (!hasLlmAttemptBudgetRemaining({ actualAttempts, maxTotalAttempts })) {
|
|
11293
|
-
|
|
11138
|
+
logger15.error("\u5DF2\u8FBE\u5230 LLM \u603B\u8C03\u7528\u6B21\u6570\u4E0A\u9650\uFF0C\u505C\u6B62\u91CD\u8BD5/\u5207\u6A21\u578B", {
|
|
11294
11139
|
actualAttempts,
|
|
11295
11140
|
maxTotalAttempts
|
|
11296
11141
|
});
|
|
@@ -11320,37 +11165,15 @@ async function callWithRetryFallback(params) {
|
|
|
11320
11165
|
attempt -= 1;
|
|
11321
11166
|
continue;
|
|
11322
11167
|
}
|
|
11323
|
-
const quotaFallbackModelId = tryCloudQuotaFallback({
|
|
11324
|
-
deps,
|
|
11325
|
-
activeModelId,
|
|
11326
|
-
options,
|
|
11327
|
-
excludedModelIds,
|
|
11328
|
-
requirement,
|
|
11329
|
-
error: lastError,
|
|
11330
|
-
fallbackObserver,
|
|
11331
|
-
evaluateFallbackPromptCapacity: invocationContext?.evaluateFallbackPromptCapacity
|
|
11332
|
-
});
|
|
11333
|
-
if (quotaFallbackModelId) {
|
|
11334
|
-
fallbackObserver?.onModelFallbackApplied?.({
|
|
11335
|
-
fromModelId: activeModelId,
|
|
11336
|
-
toModelId: quotaFallbackModelId,
|
|
11337
|
-
reason: lastError.message,
|
|
11338
|
-
policy: "cloud-quota"
|
|
11339
|
-
});
|
|
11340
|
-
activeModelId = quotaFallbackModelId;
|
|
11341
|
-
excludedModelIds.add(quotaFallbackModelId);
|
|
11342
|
-
attempt -= 1;
|
|
11343
|
-
continue;
|
|
11344
|
-
}
|
|
11345
11168
|
}
|
|
11346
11169
|
if (classification.category === "non_retryable" /* NON_RETRYABLE */) {
|
|
11347
|
-
|
|
11170
|
+
logger15.error("\u9519\u8BEF\u4E0D\u53EF\u91CD\u8BD5\uFF0C\u76F4\u63A5\u5931\u8D25", { reason: classification.reason });
|
|
11348
11171
|
retryEpisode.finish("failed", failedRetryState);
|
|
11349
11172
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
11350
11173
|
throw lastError;
|
|
11351
11174
|
}
|
|
11352
11175
|
if (attempt >= configuredMaxRetries || categoryRetries[category] >= currentMaxRetries) {
|
|
11353
|
-
|
|
11176
|
+
logger15.error("\u5DF2\u8FBE\u5230\u6700\u5927\u91CD\u8BD5\u6B21\u6570\uFF0C\u653E\u5F03\u91CD\u8BD5", { maxRetries: currentMaxRetries });
|
|
11354
11177
|
retryEpisode.finish("exhausted", failedRetryState);
|
|
11355
11178
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
11356
11179
|
throw lastError;
|
|
@@ -11362,9 +11185,9 @@ async function callWithRetryFallback(params) {
|
|
|
11362
11185
|
6e4
|
|
11363
11186
|
);
|
|
11364
11187
|
if (classification.category === "rate_limit" /* RATE_LIMIT */) {
|
|
11365
|
-
|
|
11188
|
+
logger15.warn("\u901F\u7387\u9650\u5236\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
11366
11189
|
} else if (classification.category === "retryable" /* RETRYABLE */) {
|
|
11367
|
-
|
|
11190
|
+
logger15.warn("\u53EF\u91CD\u8BD5\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
11368
11191
|
}
|
|
11369
11192
|
throwIfAborted(signal, "\u5EF6\u8FDF\u7B49\u5F85\u524D\u68C0\u6D4B\u5230\u53D6\u6D88\u4FE1\u53F7\uFF0C\u505C\u6B62\u91CD\u8BD5");
|
|
11370
11193
|
categoryRetries[category] += 1;
|
|
@@ -11401,16 +11224,11 @@ function waitForRetry(delayMs, signal) {
|
|
|
11401
11224
|
}
|
|
11402
11225
|
function isClientRetryEnabledForModel(modelCatalog, modelId, options) {
|
|
11403
11226
|
if (options.retry_policy === "none") return false;
|
|
11404
|
-
|
|
11405
|
-
if (cfg?.billing_mode === "cloud") return false;
|
|
11406
|
-
if (options.retry_policy === "client") return true;
|
|
11407
|
-
if (!cfg) return true;
|
|
11408
|
-
if (cfg.enable_client_retry === false) return false;
|
|
11409
|
-
return true;
|
|
11227
|
+
return modelCatalog.getModelById(modelId)?.enable_client_retry !== false;
|
|
11410
11228
|
}
|
|
11411
11229
|
function throwIfAborted(signal, message) {
|
|
11412
11230
|
if (!signal?.aborted) return;
|
|
11413
|
-
|
|
11231
|
+
logger15.info(message);
|
|
11414
11232
|
const reason = signal.reason;
|
|
11415
11233
|
if (reason instanceof Error && reason.name === "AbortError") throw reason;
|
|
11416
11234
|
const reasonText = typeof reason === "string" && reason.trim().length > 0 ? reason : "stream_interrupted";
|
|
@@ -12093,7 +11911,7 @@ function runMetaFromRecord(record) {
|
|
|
12093
11911
|
}
|
|
12094
11912
|
|
|
12095
11913
|
// src/runtime-kernel/run-supervisor/functions/awaitingUserWatcher.ts
|
|
12096
|
-
var
|
|
11914
|
+
var logger17 = new Logger("RunSupervisorAwaitingUserWatcher");
|
|
12097
11915
|
function isRecord16(value) {
|
|
12098
11916
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12099
11917
|
}
|
|
@@ -12138,7 +11956,7 @@ function createAwaitingUserWatcher(options) {
|
|
|
12138
11956
|
resumeToken: event.resume_token
|
|
12139
11957
|
}
|
|
12140
11958
|
}).catch((error) => {
|
|
12141
|
-
|
|
11959
|
+
logger17.warn("failed to mark awaiting_user from requires_user_interaction", { error });
|
|
12142
11960
|
});
|
|
12143
11961
|
};
|
|
12144
11962
|
const dispose = () => {
|