@linnlabs/linnkit 0.45.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 +60 -0
- package/dist/cli.cjs +65 -243
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +65 -243
- package/dist/cli.js.map +1 -1
- package/dist/context-manager.cjs +7 -6
- package/dist/context-manager.cjs.map +1 -1
- package/dist/context-manager.js +7 -6
- package/dist/context-manager.js.map +1 -1
- package/dist/index.cjs +75 -253
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +75 -253
- 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 +65 -243
- package/dist/quickstart.cjs.map +1 -1
- package/dist/quickstart.js +65 -243
- 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 -4
- package/dist/runtime-kernel/graph-engine/types.d.ts +1 -4
- 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.cjs +75 -253
- package/dist/runtime-kernel.cjs.map +1 -1
- package/dist/runtime-kernel.js +75 -253
- package/dist/runtime-kernel.js.map +1 -1
- package/dist/testkit.cjs +83 -261
- package/dist/testkit.cjs.map +1 -1
- package/dist/testkit.js +83 -261
- package/dist/testkit.js.map +1 -1
- package/docs/integration/agent-registration-guide.md +1 -1
- package/docs/integration/context-engineering.md +5 -5
- package/docs/integration/llm-provider.md +1 -1
- package/docs/integration/tool-development-guide.md +4 -2
- package/package.json +2 -1
package/dist/runtime-kernel.cjs
CHANGED
|
@@ -422,18 +422,6 @@ var ErrorClassifier = class {
|
|
|
422
422
|
});
|
|
423
423
|
}
|
|
424
424
|
}
|
|
425
|
-
const quotaPatterns = ["\u5DF2\u8FBE\u4E0A\u9650", "\u514D\u8D39\u671F\u5DF2\u7ED3\u675F"];
|
|
426
|
-
for (const pattern of quotaPatterns) {
|
|
427
|
-
if (errorMessage.includes(pattern)) {
|
|
428
|
-
logClassification(context, "\u68C0\u6D4B\u5230\u4E91\u7AEF\u989D\u5EA6\u9650\u5236\uFF0C\u4E0D\u91CD\u8BD5", { matchedPattern: pattern });
|
|
429
|
-
return createClassification("non_retryable" /* NON_RETRYABLE */, `\u4E91\u7AEF\u989D\u5EA6\u9650\u5236: ${pattern}`, null, {
|
|
430
|
-
errorCode: ENGINE_ERROR_CODES.LLM_PROVIDER_DOWN,
|
|
431
|
-
recoverable: false,
|
|
432
|
-
hint: "check_billing_or_provider_status",
|
|
433
|
-
metadata: { matchedPattern: pattern }
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
425
|
const authPatterns = [
|
|
438
426
|
{ pattern: "unauthorized", code: "401" },
|
|
439
427
|
{ pattern: "forbidden", code: "403" },
|
|
@@ -688,17 +676,6 @@ var ErrorClassifier = class {
|
|
|
688
676
|
}
|
|
689
677
|
return Math.max(baseDelay, classification.suggestedDelay ?? 0);
|
|
690
678
|
}
|
|
691
|
-
static isCloudQuotaError(error) {
|
|
692
|
-
const msg = (error.message || "").toLowerCase();
|
|
693
|
-
const patterns = [
|
|
694
|
-
"\u989D\u5EA6\u4E0A\u9650",
|
|
695
|
-
"\u5DF2\u8FBE\u4E0A\u9650",
|
|
696
|
-
"\u514D\u8D39\u671F\u5DF2\u7ED3\u675F",
|
|
697
|
-
"\u8BE5\u6A21\u578B\u6682\u4E0D\u53EF\u7528",
|
|
698
|
-
"cloud_quota_exhausted"
|
|
699
|
-
];
|
|
700
|
-
return patterns.some((pattern) => msg.includes(pattern));
|
|
701
|
-
}
|
|
702
679
|
};
|
|
703
680
|
var NonBlankIdentitySchema = zod.z.string().max(200).refine(
|
|
704
681
|
(value) => value.trim().length > 0 && value === value.trim(),
|
|
@@ -3887,8 +3864,8 @@ var TokenCalculator = class {
|
|
|
3887
3864
|
return;
|
|
3888
3865
|
}
|
|
3889
3866
|
this.failedEncodingWarnings.add(requestedEncoding);
|
|
3890
|
-
const
|
|
3891
|
-
|
|
3867
|
+
const logger18 = new Logger("TokenCalculator");
|
|
3868
|
+
logger18.warn("tiktoken encoding unavailable, falling back to avgCharsPerToken estimator", {
|
|
3892
3869
|
requestedEncoding,
|
|
3893
3870
|
error
|
|
3894
3871
|
});
|
|
@@ -3980,49 +3957,6 @@ var llmTelemetryMiddleware = async (ctx, stage, next) => {
|
|
|
3980
3957
|
});
|
|
3981
3958
|
};
|
|
3982
3959
|
|
|
3983
|
-
// src/runtime-kernel/graph-engine/functions/runModelLock.ts
|
|
3984
|
-
function readNonEmptyString4(value) {
|
|
3985
|
-
if (typeof value !== "string") return void 0;
|
|
3986
|
-
const trimmed = value.trim();
|
|
3987
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
3988
|
-
}
|
|
3989
|
-
function decideRunModelLockPatch(params) {
|
|
3990
|
-
if (params.stageId !== "execute_llm") {
|
|
3991
|
-
return { shouldLog: false };
|
|
3992
|
-
}
|
|
3993
|
-
const normalized = readNonEmptyString4(params.appliedFallbackModelId);
|
|
3994
|
-
if (!normalized) {
|
|
3995
|
-
return { shouldLog: false };
|
|
3996
|
-
}
|
|
3997
|
-
if (readNonEmptyString4(params.currentRunLockedModelId) === normalized) {
|
|
3998
|
-
return { shouldLog: false };
|
|
3999
|
-
}
|
|
4000
|
-
return {
|
|
4001
|
-
executorLocalPatch: { runLockedModelId: normalized },
|
|
4002
|
-
shouldLog: true
|
|
4003
|
-
};
|
|
4004
|
-
}
|
|
4005
|
-
|
|
4006
|
-
// src/runtime-kernel/graph-engine/tick-pipeline/middlewares/runModelLockMiddleware.ts
|
|
4007
|
-
var logger4 = new Logger("GraphAgentExecutor");
|
|
4008
|
-
var runModelLockMiddleware = async (ctx, stage, next) => {
|
|
4009
|
-
await next();
|
|
4010
|
-
const decision = decideRunModelLockPatch({
|
|
4011
|
-
stageId: stage.id,
|
|
4012
|
-
appliedFallbackModelId: ctx.cloudQuotaFallbackAppliedModelId,
|
|
4013
|
-
currentRunLockedModelId: ctx.executorLocalPatch?.runLockedModelId ?? ctx.executorLocal?.runLockedModelId
|
|
4014
|
-
});
|
|
4015
|
-
if (!decision.executorLocalPatch) {
|
|
4016
|
-
return;
|
|
4017
|
-
}
|
|
4018
|
-
if (decision.shouldLog) {
|
|
4019
|
-
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}`);
|
|
4020
|
-
}
|
|
4021
|
-
return {
|
|
4022
|
-
executorLocalPatch: decision.executorLocalPatch
|
|
4023
|
-
};
|
|
4024
|
-
};
|
|
4025
|
-
|
|
4026
3960
|
// src/runtime-kernel/graph-engine/tick-pipeline/runTickPipeline.ts
|
|
4027
3961
|
var tickPipelineContextKeys = [
|
|
4028
3962
|
"input",
|
|
@@ -4058,7 +3992,6 @@ var tickPipelineContextKeys = [
|
|
|
4058
3992
|
"decision",
|
|
4059
3993
|
"systemReminderHitRuleIds",
|
|
4060
3994
|
"contextTrace",
|
|
4061
|
-
"cloudQuotaFallbackAppliedModelId",
|
|
4062
3995
|
"modelFallbackAudit",
|
|
4063
3996
|
"telemetry",
|
|
4064
3997
|
"audit",
|
|
@@ -4397,7 +4330,7 @@ ${normalized}
|
|
|
4397
4330
|
}
|
|
4398
4331
|
|
|
4399
4332
|
// src/runtime-kernel/system-reminder/apply.ts
|
|
4400
|
-
var
|
|
4333
|
+
var logger4 = new Logger("SystemReminder");
|
|
4401
4334
|
var readString2 = (v) => {
|
|
4402
4335
|
if (typeof v !== "string") return void 0;
|
|
4403
4336
|
const s = v;
|
|
@@ -4460,7 +4393,7 @@ function applySystemReminders(params) {
|
|
|
4460
4393
|
} catch {
|
|
4461
4394
|
}
|
|
4462
4395
|
}
|
|
4463
|
-
|
|
4396
|
+
logger4.info("SystemReminder \u5DF2\u6CE8\u5165\u5230 LLM \u8F93\u5165\u672B\u5C3E", {
|
|
4464
4397
|
ruleIds: injectedRuleIds.length > 0 ? injectedRuleIds : Array.from(seenRuleIds),
|
|
4465
4398
|
promptKey: ctx.request.promptKey,
|
|
4466
4399
|
executorLocal: {
|
|
@@ -5170,18 +5103,14 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5170
5103
|
"turnId"
|
|
5171
5104
|
],
|
|
5172
5105
|
writes: [
|
|
5173
|
-
"cloudQuotaFallbackAppliedModelId",
|
|
5174
5106
|
"modelFallbackAudit",
|
|
5175
5107
|
"llmCallStartedAt",
|
|
5176
5108
|
"llmResp",
|
|
5177
5109
|
"llmCallDurationMs",
|
|
5178
|
-
"executorLocalPatch",
|
|
5179
5110
|
"contextUsage"
|
|
5180
5111
|
],
|
|
5181
5112
|
async run(ctx) {
|
|
5182
|
-
let cloudQuotaFallbackAppliedModelId;
|
|
5183
5113
|
let modelFallbackAudit;
|
|
5184
|
-
let lastSuccessfulLlmModelId;
|
|
5185
5114
|
let contextUsage;
|
|
5186
5115
|
const modelFallbackRejections = [];
|
|
5187
5116
|
const promptBudget = ctx.promptBudget;
|
|
@@ -5199,11 +5128,7 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5199
5128
|
streamEventHandler,
|
|
5200
5129
|
ctx.signal,
|
|
5201
5130
|
{
|
|
5202
|
-
|
|
5203
|
-
cloudQuotaFallbackAppliedModelId = readNonEmptyString3(fallbackModelId);
|
|
5204
|
-
},
|
|
5205
|
-
onLlmAttemptSucceeded(activeModelId, attemptContextUsage) {
|
|
5206
|
-
lastSuccessfulLlmModelId = readNonEmptyString3(activeModelId);
|
|
5131
|
+
onLlmAttemptSucceeded(_activeModelId, attemptContextUsage) {
|
|
5207
5132
|
contextUsage = attemptContextUsage;
|
|
5208
5133
|
},
|
|
5209
5134
|
onModelFallbackApplied(info) {
|
|
@@ -5299,12 +5224,10 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5299
5224
|
});
|
|
5300
5225
|
}
|
|
5301
5226
|
return {
|
|
5302
|
-
cloudQuotaFallbackAppliedModelId,
|
|
5303
5227
|
modelFallbackAudit,
|
|
5304
5228
|
llmCallStartedAt,
|
|
5305
5229
|
llmResp,
|
|
5306
5230
|
llmCallDurationMs,
|
|
5307
|
-
executorLocalPatch: lastSuccessfulLlmModelId ? { lastSuccessfulLlmModelId } : void 0,
|
|
5308
5231
|
contextUsage
|
|
5309
5232
|
};
|
|
5310
5233
|
}
|
|
@@ -6221,18 +6144,16 @@ function createPrepareCallStage(dependencies) {
|
|
|
6221
6144
|
"toolDefinitionTokens"
|
|
6222
6145
|
],
|
|
6223
6146
|
async run(ctx) {
|
|
6224
|
-
const
|
|
6225
|
-
const requestedModelId = lockedRunModelId ?? ctx.request.model_id;
|
|
6147
|
+
const requestedModelId = ctx.request.model_id;
|
|
6226
6148
|
const modelId = dependencies.modelResolver.resolveModelId(requestedModelId);
|
|
6227
6149
|
await emitAuditEnvelope(ctx.audit, {
|
|
6228
6150
|
action: "model.select",
|
|
6229
6151
|
actor: { kind: "system" },
|
|
6230
6152
|
decision: {
|
|
6231
6153
|
outcome: "recorded",
|
|
6232
|
-
reason:
|
|
6154
|
+
reason: requestedModelId ? "request model id" : "default model resolver",
|
|
6233
6155
|
metadata: {
|
|
6234
6156
|
requestedModelId,
|
|
6235
|
-
lockedRunModelId,
|
|
6236
6157
|
selectedModelId: modelId
|
|
6237
6158
|
}
|
|
6238
6159
|
},
|
|
@@ -6279,10 +6200,6 @@ function createPrepareCallStage(dependencies) {
|
|
|
6279
6200
|
if (ctx.executorLocal?.lockRequestedModelId === true) {
|
|
6280
6201
|
llmOptions.allow_model_fallback = false;
|
|
6281
6202
|
}
|
|
6282
|
-
const isRunContinuation = ctx.executorLocal?.llmInvocationKind === "continuation";
|
|
6283
|
-
if (dependencies.cloudQuotaFallbackModelId && modelConfig?.billing_mode === "cloud" && modelId !== dependencies.cloudQuotaFallbackModelId && isRunContinuation && ctx.executorLocal?.lockRequestedModelId !== true) {
|
|
6284
|
-
llmOptions.cloud_quota_fallback_model_id = dependencies.cloudQuotaFallbackModelId;
|
|
6285
|
-
}
|
|
6286
6203
|
const effectiveEffort = resolveEffectiveEffort(
|
|
6287
6204
|
ctx.request.reasoning_effort,
|
|
6288
6205
|
modelConfig?.reasoning
|
|
@@ -6399,12 +6316,11 @@ function applyCalibration(rawLocalTotal, imageInputTokens, coefficient) {
|
|
|
6399
6316
|
}
|
|
6400
6317
|
|
|
6401
6318
|
// src/runtime-kernel/graph-engine/executor.ts
|
|
6402
|
-
var
|
|
6319
|
+
var logger5 = new Logger("GraphAgentExecutor");
|
|
6403
6320
|
var GraphAgentExecutor = class {
|
|
6404
6321
|
llmCaller;
|
|
6405
6322
|
toolRuntime;
|
|
6406
6323
|
contextBuilder;
|
|
6407
|
-
cloudQuotaFallbackModelId;
|
|
6408
6324
|
modelResolver;
|
|
6409
6325
|
modelCatalog;
|
|
6410
6326
|
telemetryPort;
|
|
@@ -6416,7 +6332,6 @@ var GraphAgentExecutor = class {
|
|
|
6416
6332
|
this.llmCaller = dependencies.llmCaller;
|
|
6417
6333
|
this.toolRuntime = dependencies.toolRuntime;
|
|
6418
6334
|
this.contextBuilder = dependencies.contextBuilder;
|
|
6419
|
-
this.cloudQuotaFallbackModelId = readNonEmptyString3(dependencies.cloudQuotaFallbackModelId);
|
|
6420
6335
|
this.modelCatalog = dependencies.modelCatalog ?? createEmptyModelCatalog();
|
|
6421
6336
|
this.modelResolver = dependencies.modelResolver ?? new ModelResolver({
|
|
6422
6337
|
modelCatalog: this.modelCatalog
|
|
@@ -6433,8 +6348,7 @@ var GraphAgentExecutor = class {
|
|
|
6433
6348
|
createPrepareCallStage({
|
|
6434
6349
|
modelResolver: this.modelResolver,
|
|
6435
6350
|
modelCatalog: this.modelCatalog,
|
|
6436
|
-
toolCatalog: this.toolRuntime
|
|
6437
|
-
cloudQuotaFallbackModelId: this.cloudQuotaFallbackModelId
|
|
6351
|
+
toolCatalog: this.toolRuntime
|
|
6438
6352
|
}),
|
|
6439
6353
|
createBuildContextStage({
|
|
6440
6354
|
contextBuilder: this.contextBuilder
|
|
@@ -6456,7 +6370,7 @@ var GraphAgentExecutor = class {
|
|
|
6456
6370
|
}),
|
|
6457
6371
|
createBuildDecisionStage()
|
|
6458
6372
|
];
|
|
6459
|
-
this.middlewares = [llmTelemetryMiddleware
|
|
6373
|
+
this.middlewares = [llmTelemetryMiddleware];
|
|
6460
6374
|
}
|
|
6461
6375
|
async tick(input, eventHandler) {
|
|
6462
6376
|
const ctx = {
|
|
@@ -6481,7 +6395,7 @@ var GraphAgentExecutor = class {
|
|
|
6481
6395
|
audit: this.auditPort,
|
|
6482
6396
|
tokenizer: this.tokenizer
|
|
6483
6397
|
};
|
|
6484
|
-
|
|
6398
|
+
logger5.info("[GraphAgentExecutor] tick \u8C03\u7528", {
|
|
6485
6399
|
stream: input.stream === true,
|
|
6486
6400
|
hasEventHandler: Boolean(eventHandler),
|
|
6487
6401
|
hasSummarizationCallbacks: Boolean(input.summarizationCallbacks)
|
|
@@ -7504,7 +7418,7 @@ var LlmNodeEventBridge = class {
|
|
|
7504
7418
|
};
|
|
7505
7419
|
|
|
7506
7420
|
// src/runtime-kernel/graph-engine/nodes/llmNode.ts
|
|
7507
|
-
var
|
|
7421
|
+
var logger6 = new Logger("LlmNode");
|
|
7508
7422
|
var LlmNode = class {
|
|
7509
7423
|
id = "llm";
|
|
7510
7424
|
reasoner;
|
|
@@ -7513,7 +7427,7 @@ var LlmNode = class {
|
|
|
7513
7427
|
}
|
|
7514
7428
|
async run(state) {
|
|
7515
7429
|
const local = state.local ?? {};
|
|
7516
|
-
|
|
7430
|
+
logger6.info("[LlmNode] \u5F00\u59CB\u6267\u884C LLM \u8282\u70B9", {
|
|
7517
7431
|
localKeys: Object.keys(local)
|
|
7518
7432
|
});
|
|
7519
7433
|
const graphLocal = readGraphAgentLocal(state.local);
|
|
@@ -7528,12 +7442,12 @@ var LlmNode = class {
|
|
|
7528
7442
|
signal,
|
|
7529
7443
|
history
|
|
7530
7444
|
} = graphLocal;
|
|
7531
|
-
|
|
7445
|
+
logger6.info("[LlmNode] \u5DF2\u52A0\u8F7D\u5386\u53F2\u4E8B\u4EF6", {
|
|
7532
7446
|
historyCount: history.length,
|
|
7533
7447
|
hasSummarizationCallbacks: Boolean(summarizationCallbacks)
|
|
7534
7448
|
});
|
|
7535
7449
|
if (!request) {
|
|
7536
|
-
|
|
7450
|
+
logger6.warn("Request object is missing, yielding.");
|
|
7537
7451
|
return { kind: "yield", events: [] };
|
|
7538
7452
|
}
|
|
7539
7453
|
const turnId = requireRuntimeIdentity(graphLocal.turnId, "turnId");
|
|
@@ -7626,12 +7540,12 @@ var LlmNode = class {
|
|
|
7626
7540
|
...nodeState.streamRuntimeEvents,
|
|
7627
7541
|
...contextUsageEvent ? [contextUsageEvent] : []
|
|
7628
7542
|
];
|
|
7629
|
-
|
|
7543
|
+
logger6.info("[LlmNode] \u5386\u53F2\u4E8B\u4EF6\u5DF2\u66F4\u65B0", {
|
|
7630
7544
|
previousCount: history.length,
|
|
7631
7545
|
nextCount: patch.history.length,
|
|
7632
7546
|
streamedEventCount: nodeState.streamRuntimeEvents.length
|
|
7633
7547
|
});
|
|
7634
|
-
|
|
7548
|
+
logger6.info("[LlmNode] \u6267\u884C\u5668\u51B3\u7B56\u5B8C\u6210", {
|
|
7635
7549
|
decisionKind: decision.kind,
|
|
7636
7550
|
emittedEventCount: combinedEvents.length
|
|
7637
7551
|
});
|
|
@@ -7653,7 +7567,7 @@ var LlmNode = class {
|
|
|
7653
7567
|
}
|
|
7654
7568
|
case "error": {
|
|
7655
7569
|
const { name, message, stack } = decision.error;
|
|
7656
|
-
|
|
7570
|
+
logger6.error("[LlmNode] Executor returned an error", { name, message, stack });
|
|
7657
7571
|
return { kind: "yield", events: combinedEvents };
|
|
7658
7572
|
}
|
|
7659
7573
|
default: {
|
|
@@ -7759,7 +7673,7 @@ async function resolveToolModelInput(input) {
|
|
|
7759
7673
|
}
|
|
7760
7674
|
|
|
7761
7675
|
// src/runtime-kernel/graph-engine/nodes/toolNode.finalAnswerProjector.ts
|
|
7762
|
-
function
|
|
7676
|
+
function readNonEmptyString4(value) {
|
|
7763
7677
|
if (typeof value !== "string") {
|
|
7764
7678
|
return void 0;
|
|
7765
7679
|
}
|
|
@@ -7767,7 +7681,7 @@ function readNonEmptyString5(value) {
|
|
|
7767
7681
|
return normalized.length > 0 ? normalized : void 0;
|
|
7768
7682
|
}
|
|
7769
7683
|
function resolveFinalAnswerFromToolControl(finalAnswer) {
|
|
7770
|
-
return
|
|
7684
|
+
return readNonEmptyString4(finalAnswer);
|
|
7771
7685
|
}
|
|
7772
7686
|
|
|
7773
7687
|
// src/runtime-kernel/graph-engine/nodes/toolNode.helpers.ts
|
|
@@ -8023,7 +7937,7 @@ function buildErrorLocalState(params) {
|
|
|
8023
7937
|
}
|
|
8024
7938
|
|
|
8025
7939
|
// src/runtime-kernel/tools/argNormalizer.ts
|
|
8026
|
-
var
|
|
7940
|
+
var logger7 = new Logger("ToolArgNormalizer");
|
|
8027
7941
|
function isRecord10(v) {
|
|
8028
7942
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
8029
7943
|
}
|
|
@@ -8043,7 +7957,7 @@ function joinPath(basePath, segment) {
|
|
|
8043
7957
|
function logJsonEncodedNormalization(expectedType, options) {
|
|
8044
7958
|
const toolPrefix = options.toolName ? `${options.toolName}.` : "";
|
|
8045
7959
|
const path = options.path ?? "<root>";
|
|
8046
|
-
|
|
7960
|
+
logger7.warn("normalized JSON-encoded tool argument", {
|
|
8047
7961
|
expectedType,
|
|
8048
7962
|
path: `${toolPrefix}${path}`
|
|
8049
7963
|
});
|
|
@@ -8399,7 +8313,7 @@ function stripRuntimeReservedToolContextPatch(patch) {
|
|
|
8399
8313
|
}
|
|
8400
8314
|
|
|
8401
8315
|
// src/runtime-kernel/graph-engine/nodes/toolNode.eventBridge.ts
|
|
8402
|
-
var
|
|
8316
|
+
var logger8 = new Logger("ToolNode");
|
|
8403
8317
|
var ToolNodeEventBridge = class {
|
|
8404
8318
|
constructor(deps) {
|
|
8405
8319
|
this.deps = deps;
|
|
@@ -8421,7 +8335,7 @@ var ToolNodeEventBridge = class {
|
|
|
8421
8335
|
status,
|
|
8422
8336
|
payload: { ...payload }
|
|
8423
8337
|
};
|
|
8424
|
-
|
|
8338
|
+
logger8.info("[ToolNode] \u53D1\u51FA tool_process \u4E8B\u4EF6", {
|
|
8425
8339
|
phase,
|
|
8426
8340
|
status,
|
|
8427
8341
|
toolName: this.deps.toolName,
|
|
@@ -8461,7 +8375,7 @@ var ToolNodeEventBridge = class {
|
|
|
8461
8375
|
const answerId = generateAnswerSegmentId();
|
|
8462
8376
|
const id = answerId;
|
|
8463
8377
|
const timestamp = Date.now();
|
|
8464
|
-
|
|
8378
|
+
logger8.info("[ToolNode] \u5DE5\u5177\u8F93\u51FA\u6620\u5C04\u4E3A final_answer", {
|
|
8465
8379
|
sourceToolName: params.sourceToolName,
|
|
8466
8380
|
toolCallId: this.deps.toolCallId,
|
|
8467
8381
|
conversationId: this.deps.conversationId,
|
|
@@ -8519,7 +8433,7 @@ var ToolNodeEventBridge = class {
|
|
|
8519
8433
|
};
|
|
8520
8434
|
|
|
8521
8435
|
// src/runtime-kernel/graph-engine/nodes/toolNode.executionSetup.ts
|
|
8522
|
-
var
|
|
8436
|
+
var logger9 = new Logger("ToolNode");
|
|
8523
8437
|
function parseToolArgs(call) {
|
|
8524
8438
|
const rawArguments = typeof call.function?.arguments === "string" ? call.function.arguments : "";
|
|
8525
8439
|
if (!rawArguments.trim()) {
|
|
@@ -8539,7 +8453,7 @@ function parseToolArgs(call) {
|
|
|
8539
8453
|
return { ok: true, value: parsed };
|
|
8540
8454
|
} catch (error) {
|
|
8541
8455
|
const reason = error instanceof Error ? error.message : "Unknown JSON parse error";
|
|
8542
|
-
|
|
8456
|
+
logger9.warn("failed to parse tool arguments", { error });
|
|
8543
8457
|
return {
|
|
8544
8458
|
ok: false,
|
|
8545
8459
|
error: `Tool arguments are not valid JSON: ${reason}`
|
|
@@ -8933,7 +8847,7 @@ async function claimPendingUserInputs(state, result) {
|
|
|
8933
8847
|
}
|
|
8934
8848
|
|
|
8935
8849
|
// src/runtime-kernel/graph-engine/nodes/toolNode.ts
|
|
8936
|
-
var
|
|
8850
|
+
var logger10 = new Logger("ToolNode");
|
|
8937
8851
|
function isAbortSignal(value) {
|
|
8938
8852
|
return value !== null && typeof value === "object" && "aborted" in value;
|
|
8939
8853
|
}
|
|
@@ -9146,7 +9060,7 @@ var ToolNode = class {
|
|
|
9146
9060
|
throw abortError;
|
|
9147
9061
|
}
|
|
9148
9062
|
const prepared = prepareToolNodeContext(state);
|
|
9149
|
-
|
|
9063
|
+
logger10.info("[ToolNode] \u5F00\u59CB\u6267\u884C\u5DE5\u5177\u8282\u70B9", {
|
|
9150
9064
|
conversationId: prepared.conversationId,
|
|
9151
9065
|
turnId: prepared.turnId,
|
|
9152
9066
|
pendingCallCount: calls.length
|
|
@@ -9161,7 +9075,7 @@ var ToolNode = class {
|
|
|
9161
9075
|
toolCatalog: this.toolRuntime
|
|
9162
9076
|
});
|
|
9163
9077
|
if (!execution) {
|
|
9164
|
-
|
|
9078
|
+
logger10.warn("no tool name found in call");
|
|
9165
9079
|
return { kind: "yield", events: [] };
|
|
9166
9080
|
}
|
|
9167
9081
|
if (typeof execution.protocolError === "string") {
|
|
@@ -9201,7 +9115,7 @@ var ToolNode = class {
|
|
|
9201
9115
|
call,
|
|
9202
9116
|
context: prepared.toolContext,
|
|
9203
9117
|
abortGraceMs: this.abortGraceMs,
|
|
9204
|
-
onAbandon: () =>
|
|
9118
|
+
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", {
|
|
9205
9119
|
toolName: execution.toolName,
|
|
9206
9120
|
toolCallId: execution.toolCallId,
|
|
9207
9121
|
conversationId: prepared.conversationId,
|
|
@@ -9371,7 +9285,7 @@ var ToolNode = class {
|
|
|
9371
9285
|
runtimeEvents: context.bridge.getRuntimeEvents()
|
|
9372
9286
|
});
|
|
9373
9287
|
if (control?.terminateRun) {
|
|
9374
|
-
|
|
9288
|
+
logger10.info("[ToolNode] \u6536\u5230 control.terminateRun\uFF0C\u6267\u884C\u5B8C\u5DE5\u5177\u540E\u76F4\u63A5 yield \u7ED3\u675F\u672C\u8F6E run", {
|
|
9375
9289
|
toolName: context.toolName,
|
|
9376
9290
|
toolCallId: context.toolCallId,
|
|
9377
9291
|
conversationId: context.conversationId,
|
|
@@ -9380,7 +9294,7 @@ var ToolNode = class {
|
|
|
9380
9294
|
return { kind: "yield", events: context.bridge.getRuntimeEvents() };
|
|
9381
9295
|
}
|
|
9382
9296
|
if (remainingCalls.length === 0 && context.local.toolBatchCompletionMode === "yield_after_batch") {
|
|
9383
|
-
|
|
9297
|
+
logger10.info("[ToolNode] \u5DE5\u5177\u6279\u6B21\u5DF2\u7ED3\u7B97\uFF0C\u6309 Host \u7B56\u7565\u76F4\u63A5 yield", {
|
|
9384
9298
|
toolName: context.toolName,
|
|
9385
9299
|
toolCallId: context.toolCallId,
|
|
9386
9300
|
conversationId: context.conversationId,
|
|
@@ -9827,6 +9741,8 @@ var executor = zod.z.object({
|
|
|
9827
9741
|
lastStepsHintThreshold: counter.optional(),
|
|
9828
9742
|
systemReminderPolicy: AgentSpecSystemReminderPolicy.optional(),
|
|
9829
9743
|
toolObservationPolicy: AgentSpecToolObservationGovernancePolicy.optional(),
|
|
9744
|
+
// 已删除字段:0.45 及更早的 checkpoint 可能带 lastSuccessfulLlmModelId,0.46 及更早的可能带云端额度兜底留下的
|
|
9745
|
+
// runLockedModelId;照常接受,读入时丢弃(兜底已移除,恢复后按请求的模型继续)。
|
|
9830
9746
|
runLockedModelId: zod.z.string().optional(),
|
|
9831
9747
|
lastSuccessfulLlmModelId: zod.z.string().optional(),
|
|
9832
9748
|
llmInvocationKind: zod.z.enum(["user_initiated", "continuation"]).optional(),
|
|
@@ -9837,7 +9753,7 @@ var executor = zod.z.object({
|
|
|
9837
9753
|
committedCount: counter,
|
|
9838
9754
|
lastCommittedFingerprint: zod.z.string().optional()
|
|
9839
9755
|
}).strict().optional()
|
|
9840
|
-
}).strict();
|
|
9756
|
+
}).strict().transform(({ lastSuccessfulLlmModelId: _retired, runLockedModelId: _retiredLock, ...state }) => state);
|
|
9841
9757
|
var checkpoint = zod.z.object({
|
|
9842
9758
|
nodeId: zod.z.string().min(1),
|
|
9843
9759
|
schemaVersion: zod.z.literal(ENGINE_STATE_SCHEMA_VERSION).optional(),
|
|
@@ -10151,7 +10067,7 @@ __export(execution_exports, {
|
|
|
10151
10067
|
});
|
|
10152
10068
|
|
|
10153
10069
|
// src/runtime-kernel/execution/event-bus.ts
|
|
10154
|
-
var
|
|
10070
|
+
var logger11 = new Logger("EventBus");
|
|
10155
10071
|
var TypedEventEmitter = class {
|
|
10156
10072
|
listeners = /* @__PURE__ */ new Map();
|
|
10157
10073
|
maxListeners = 10;
|
|
@@ -10159,7 +10075,7 @@ var TypedEventEmitter = class {
|
|
|
10159
10075
|
const listeners = this.getListeners(event);
|
|
10160
10076
|
listeners.add(listener);
|
|
10161
10077
|
if (listeners.size > this.maxListeners) {
|
|
10162
|
-
|
|
10078
|
+
logger11.warn("EventBus listener count exceeds configured max", {
|
|
10163
10079
|
event: String(event),
|
|
10164
10080
|
count: listeners.size,
|
|
10165
10081
|
maxListeners: this.maxListeners
|
|
@@ -10219,7 +10135,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10219
10135
|
super();
|
|
10220
10136
|
this.executionId = executionId;
|
|
10221
10137
|
this.setMaxListeners(30);
|
|
10222
|
-
|
|
10138
|
+
logger11.info(`EventBus created for execution ${this.executionId}`);
|
|
10223
10139
|
}
|
|
10224
10140
|
/**
|
|
10225
10141
|
* 发布一个事件到总线
|
|
@@ -10228,7 +10144,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10228
10144
|
publish(envelope) {
|
|
10229
10145
|
if (envelope.trace.execution_id !== this.executionId) {
|
|
10230
10146
|
const error = new Error("EventEnvelope execution_id does not match EventBus instance.");
|
|
10231
|
-
|
|
10147
|
+
logger11.error("Mismatched execution_id", {
|
|
10232
10148
|
busExecutionId: this.executionId,
|
|
10233
10149
|
eventExecutionId: envelope.trace.execution_id,
|
|
10234
10150
|
eventSeq: envelope.seq
|
|
@@ -10240,7 +10156,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10240
10156
|
const error = new Error(
|
|
10241
10157
|
"EventBus only accepts RuntimeEvent with formal run routing identity."
|
|
10242
10158
|
);
|
|
10243
|
-
|
|
10159
|
+
logger11.error("RuntimeEvent is missing formal run routing identity", {
|
|
10244
10160
|
executionId: this.executionId,
|
|
10245
10161
|
eventId: envelope.payload.id,
|
|
10246
10162
|
eventType: envelope.payload.type
|
|
@@ -10254,14 +10170,14 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10254
10170
|
* 关闭总线,清理所有监听器
|
|
10255
10171
|
*/
|
|
10256
10172
|
close() {
|
|
10257
|
-
|
|
10173
|
+
logger11.info(`Closing EventBus for execution ${this.executionId}`);
|
|
10258
10174
|
this.emit("close");
|
|
10259
10175
|
this.removeAllListeners();
|
|
10260
10176
|
}
|
|
10261
10177
|
};
|
|
10262
10178
|
|
|
10263
10179
|
// src/runtime-kernel/execution/sequencer.ts
|
|
10264
|
-
var
|
|
10180
|
+
var logger12 = new Logger("EventSequencer");
|
|
10265
10181
|
var EventSequencer = class {
|
|
10266
10182
|
executionId;
|
|
10267
10183
|
traceId;
|
|
@@ -10269,7 +10185,7 @@ var EventSequencer = class {
|
|
|
10269
10185
|
constructor(conversationId, traceId) {
|
|
10270
10186
|
this.executionId = generateExecutionId();
|
|
10271
10187
|
this.traceId = traceId || generateTraceId();
|
|
10272
|
-
|
|
10188
|
+
logger12.info(`EventSequencer created for conversation ${conversationId}`, {
|
|
10273
10189
|
executionId: this.executionId,
|
|
10274
10190
|
traceId: this.traceId
|
|
10275
10191
|
});
|
|
@@ -11127,7 +11043,7 @@ var ThoughtStreamSegmenter = class {
|
|
|
11127
11043
|
};
|
|
11128
11044
|
|
|
11129
11045
|
// src/runtime-kernel/llm/streaming-adapter.ts
|
|
11130
|
-
var
|
|
11046
|
+
var logger13 = new Logger("LlmCaller");
|
|
11131
11047
|
var CanonicalInferenceFailureError = class extends Error {
|
|
11132
11048
|
errorCode;
|
|
11133
11049
|
recoverable;
|
|
@@ -11351,7 +11267,7 @@ async function callLlmStream(params) {
|
|
|
11351
11267
|
} catch (error) {
|
|
11352
11268
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
11353
11269
|
if (normalized.name === "AbortError") {
|
|
11354
|
-
|
|
11270
|
+
logger13.info("Canonical inference \u6536\u5230\u53D6\u6D88\u7EC8\u6001\uFF0C\u4E0D\u53D1\u5E03\u666E\u901A error event", { modelId });
|
|
11355
11271
|
throw normalized;
|
|
11356
11272
|
}
|
|
11357
11273
|
const classification = ErrorClassifier.classify(normalized, {
|
|
@@ -11427,7 +11343,7 @@ var LlmRetryEpisode = class {
|
|
|
11427
11343
|
};
|
|
11428
11344
|
|
|
11429
11345
|
// src/runtime-kernel/llm/retry-fallback-routing.ts
|
|
11430
|
-
var
|
|
11346
|
+
var logger14 = new Logger("LlmCaller");
|
|
11431
11347
|
function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement, fallbackObserver, error, evaluateFallbackPromptCapacity2) {
|
|
11432
11348
|
deps.modelCatalog.getModelById(activeModelId);
|
|
11433
11349
|
const policyDecision = deps.policyEngine.decideOnError(error, {
|
|
@@ -11457,81 +11373,16 @@ function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement
|
|
|
11457
11373
|
reason: "no_eligible_fallback_candidate",
|
|
11458
11374
|
requiredPlacements: requirement.placements
|
|
11459
11375
|
});
|
|
11460
|
-
|
|
11376
|
+
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");
|
|
11461
11377
|
return null;
|
|
11462
11378
|
}
|
|
11463
|
-
|
|
11379
|
+
logger14.warn("Policy \u5207\u6362\u6A21\u578B\u7EE7\u7EED", {
|
|
11464
11380
|
reason: policyDecision.reason,
|
|
11465
11381
|
activeModelId,
|
|
11466
11382
|
fallbackModelId
|
|
11467
11383
|
});
|
|
11468
11384
|
return fallbackModelId;
|
|
11469
11385
|
}
|
|
11470
|
-
function tryCloudQuotaFallback({
|
|
11471
|
-
deps,
|
|
11472
|
-
activeModelId,
|
|
11473
|
-
options,
|
|
11474
|
-
excludedModelIds,
|
|
11475
|
-
requirement,
|
|
11476
|
-
error,
|
|
11477
|
-
fallbackObserver,
|
|
11478
|
-
evaluateFallbackPromptCapacity: evaluateFallbackPromptCapacity2
|
|
11479
|
-
}) {
|
|
11480
|
-
const fallbackModelId = options.cloud_quota_fallback_model_id;
|
|
11481
|
-
if (!fallbackModelId || !ErrorClassifier.isCloudQuotaError(error) || excludedModelIds.has(fallbackModelId)) {
|
|
11482
|
-
return null;
|
|
11483
|
-
}
|
|
11484
|
-
const fallbackConfig = deps.modelCatalog.getModelById(fallbackModelId);
|
|
11485
|
-
if (!fallbackConfig?.api_key) {
|
|
11486
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11487
|
-
fromModelId: activeModelId,
|
|
11488
|
-
candidateModelId: fallbackModelId,
|
|
11489
|
-
policy: "cloud-quota",
|
|
11490
|
-
reason: "fallback_model_unavailable",
|
|
11491
|
-
requiredPlacements: requirement.placements
|
|
11492
|
-
});
|
|
11493
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\u76EE\u6807\u4E0D\u53EF\u7528\uFF08\u672A\u6CE8\u518C\u6216\u7F3A\u5C11 API Key\uFF09", { fallbackModelId });
|
|
11494
|
-
return null;
|
|
11495
|
-
}
|
|
11496
|
-
const compatibility = evaluateModelInputCompatibility(fallbackConfig, requirement);
|
|
11497
|
-
if (!compatibility.compatible) {
|
|
11498
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11499
|
-
fromModelId: activeModelId,
|
|
11500
|
-
candidateModelId: fallbackModelId,
|
|
11501
|
-
policy: "cloud-quota",
|
|
11502
|
-
reason: compatibility.reason,
|
|
11503
|
-
requiredPlacements: requirement.placements
|
|
11504
|
-
});
|
|
11505
|
-
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", {
|
|
11506
|
-
fallbackModelId,
|
|
11507
|
-
requiredPlacements: requirement.placements,
|
|
11508
|
-
reason: compatibility.reason
|
|
11509
|
-
});
|
|
11510
|
-
return null;
|
|
11511
|
-
}
|
|
11512
|
-
const capacityAdmission = evaluateFallbackPromptCapacity2?.(fallbackModelId);
|
|
11513
|
-
if (capacityAdmission && !capacityAdmission.admitted) {
|
|
11514
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11515
|
-
fromModelId: activeModelId,
|
|
11516
|
-
candidateModelId: fallbackModelId,
|
|
11517
|
-
policy: "cloud-quota",
|
|
11518
|
-
reason: capacityAdmission.reason,
|
|
11519
|
-
requiredPlacements: requirement.placements
|
|
11520
|
-
});
|
|
11521
|
-
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", {
|
|
11522
|
-
fallbackModelId,
|
|
11523
|
-
reason: capacityAdmission.reason
|
|
11524
|
-
});
|
|
11525
|
-
return null;
|
|
11526
|
-
}
|
|
11527
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\uFF08run \u5185\u7EED\u8DD1\uFF09", {
|
|
11528
|
-
activeModelId,
|
|
11529
|
-
fallbackModelId,
|
|
11530
|
-
reason: error.message
|
|
11531
|
-
});
|
|
11532
|
-
fallbackObserver?.onCloudQuotaFallbackApplied?.(fallbackModelId);
|
|
11533
|
-
return fallbackModelId;
|
|
11534
|
-
}
|
|
11535
11386
|
|
|
11536
11387
|
// src/runtime-kernel/llm/usage-telemetry.ts
|
|
11537
11388
|
async function callPlainCompletion(inferencePort, modelId, messages, options = {}, signal, traceId) {
|
|
@@ -11654,7 +11505,7 @@ var LlmImageInputError = class extends Error {
|
|
|
11654
11505
|
};
|
|
11655
11506
|
|
|
11656
11507
|
// src/runtime-kernel/llm/retry-fallback.ts
|
|
11657
|
-
var
|
|
11508
|
+
var logger15 = new Logger("LlmCaller");
|
|
11658
11509
|
async function callWithRetryFallback(params) {
|
|
11659
11510
|
const {
|
|
11660
11511
|
deps,
|
|
@@ -11682,11 +11533,9 @@ async function callWithRetryFallback(params) {
|
|
|
11682
11533
|
const retryEpisode = new LlmRetryEpisode(traceId, eventHandler);
|
|
11683
11534
|
let previousAttemptTracker;
|
|
11684
11535
|
if (!clientRetryEnabled) {
|
|
11685
|
-
|
|
11686
|
-
logger16.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
11536
|
+
logger15.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
11687
11537
|
modelId,
|
|
11688
|
-
|
|
11689
|
-
reason: options.retry_policy === "none" ? "options.retry_policy=none" : "model config (cloud billing or enable_client_retry=false)"
|
|
11538
|
+
reason: options.retry_policy === "none" ? "options.retry_policy=none" : "model config enable_client_retry=false"
|
|
11690
11539
|
});
|
|
11691
11540
|
}
|
|
11692
11541
|
try {
|
|
@@ -11722,7 +11571,7 @@ async function callWithRetryFallback(params) {
|
|
|
11722
11571
|
}) : void 0;
|
|
11723
11572
|
try {
|
|
11724
11573
|
if (isRetry) {
|
|
11725
|
-
|
|
11574
|
+
logger15.info("LLM \u8C03\u7528\u91CD\u8BD5", { attempt, configuredMaxRetries });
|
|
11726
11575
|
}
|
|
11727
11576
|
actualAttempts++;
|
|
11728
11577
|
retryEpisode.retrying(actualAttempts);
|
|
@@ -11751,7 +11600,7 @@ async function callWithRetryFallback(params) {
|
|
|
11751
11600
|
if (deps.retryConfig.enableEmptyResponseRetry && !responseContent?.trim() && !toolCallsFromLLM?.length) {
|
|
11752
11601
|
throw new Error("LLM\u8FD4\u56DE\u4E86\u7A7A\u54CD\u5E94");
|
|
11753
11602
|
}
|
|
11754
|
-
|
|
11603
|
+
logger15.debug("LLM \u8C03\u7528\u6210\u529F", { attempts: actualAttempts, maxTotalAttempts });
|
|
11755
11604
|
if (attemptContextUsage) {
|
|
11756
11605
|
fallbackObserver?.onLlmAttemptSucceeded?.(activeModelId, attemptContextUsage);
|
|
11757
11606
|
} else {
|
|
@@ -11762,7 +11611,7 @@ async function callWithRetryFallback(params) {
|
|
|
11762
11611
|
} catch (error) {
|
|
11763
11612
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
11764
11613
|
if (lastError.name === "AbortError") {
|
|
11765
|
-
|
|
11614
|
+
logger15.info("LLM \u8C03\u7528\u5DF2\u53D6\u6D88\uFF0C\u4E0D\u8FDB\u5165 provider failure \u5206\u7C7B\u4E0E\u91CD\u8BD5\u6D41\u7A0B", {
|
|
11766
11615
|
attempt: attempt + 1,
|
|
11767
11616
|
actualAttempts,
|
|
11768
11617
|
maxTotalAttempts,
|
|
@@ -11781,7 +11630,7 @@ async function callWithRetryFallback(params) {
|
|
|
11781
11630
|
total_attempts: actualAttempts,
|
|
11782
11631
|
error_code: classification.errorCode
|
|
11783
11632
|
};
|
|
11784
|
-
|
|
11633
|
+
logger15.error("LLM \u8C03\u7528\u5931\u8D25", {
|
|
11785
11634
|
attempt: attempt + 1,
|
|
11786
11635
|
maxAttempts: currentMaxRetries + 1,
|
|
11787
11636
|
actualAttempts,
|
|
@@ -11790,7 +11639,7 @@ async function callWithRetryFallback(params) {
|
|
|
11790
11639
|
});
|
|
11791
11640
|
previousAttemptTracker = attemptTracker;
|
|
11792
11641
|
if (!hasLlmAttemptBudgetRemaining({ actualAttempts, maxTotalAttempts })) {
|
|
11793
|
-
|
|
11642
|
+
logger15.error("\u5DF2\u8FBE\u5230 LLM \u603B\u8C03\u7528\u6B21\u6570\u4E0A\u9650\uFF0C\u505C\u6B62\u91CD\u8BD5/\u5207\u6A21\u578B", {
|
|
11794
11643
|
actualAttempts,
|
|
11795
11644
|
maxTotalAttempts
|
|
11796
11645
|
});
|
|
@@ -11820,37 +11669,15 @@ async function callWithRetryFallback(params) {
|
|
|
11820
11669
|
attempt -= 1;
|
|
11821
11670
|
continue;
|
|
11822
11671
|
}
|
|
11823
|
-
const quotaFallbackModelId = tryCloudQuotaFallback({
|
|
11824
|
-
deps,
|
|
11825
|
-
activeModelId,
|
|
11826
|
-
options,
|
|
11827
|
-
excludedModelIds,
|
|
11828
|
-
requirement,
|
|
11829
|
-
error: lastError,
|
|
11830
|
-
fallbackObserver,
|
|
11831
|
-
evaluateFallbackPromptCapacity: invocationContext?.evaluateFallbackPromptCapacity
|
|
11832
|
-
});
|
|
11833
|
-
if (quotaFallbackModelId) {
|
|
11834
|
-
fallbackObserver?.onModelFallbackApplied?.({
|
|
11835
|
-
fromModelId: activeModelId,
|
|
11836
|
-
toModelId: quotaFallbackModelId,
|
|
11837
|
-
reason: lastError.message,
|
|
11838
|
-
policy: "cloud-quota"
|
|
11839
|
-
});
|
|
11840
|
-
activeModelId = quotaFallbackModelId;
|
|
11841
|
-
excludedModelIds.add(quotaFallbackModelId);
|
|
11842
|
-
attempt -= 1;
|
|
11843
|
-
continue;
|
|
11844
|
-
}
|
|
11845
11672
|
}
|
|
11846
11673
|
if (classification.category === "non_retryable" /* NON_RETRYABLE */) {
|
|
11847
|
-
|
|
11674
|
+
logger15.error("\u9519\u8BEF\u4E0D\u53EF\u91CD\u8BD5\uFF0C\u76F4\u63A5\u5931\u8D25", { reason: classification.reason });
|
|
11848
11675
|
retryEpisode.finish("failed", failedRetryState);
|
|
11849
11676
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
11850
11677
|
throw lastError;
|
|
11851
11678
|
}
|
|
11852
11679
|
if (attempt >= configuredMaxRetries || categoryRetries[category] >= currentMaxRetries) {
|
|
11853
|
-
|
|
11680
|
+
logger15.error("\u5DF2\u8FBE\u5230\u6700\u5927\u91CD\u8BD5\u6B21\u6570\uFF0C\u653E\u5F03\u91CD\u8BD5", { maxRetries: currentMaxRetries });
|
|
11854
11681
|
retryEpisode.finish("exhausted", failedRetryState);
|
|
11855
11682
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
11856
11683
|
throw lastError;
|
|
@@ -11862,9 +11689,9 @@ async function callWithRetryFallback(params) {
|
|
|
11862
11689
|
6e4
|
|
11863
11690
|
);
|
|
11864
11691
|
if (classification.category === "rate_limit" /* RATE_LIMIT */) {
|
|
11865
|
-
|
|
11692
|
+
logger15.warn("\u901F\u7387\u9650\u5236\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
11866
11693
|
} else if (classification.category === "retryable" /* RETRYABLE */) {
|
|
11867
|
-
|
|
11694
|
+
logger15.warn("\u53EF\u91CD\u8BD5\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
11868
11695
|
}
|
|
11869
11696
|
throwIfAborted(signal, "\u5EF6\u8FDF\u7B49\u5F85\u524D\u68C0\u6D4B\u5230\u53D6\u6D88\u4FE1\u53F7\uFF0C\u505C\u6B62\u91CD\u8BD5");
|
|
11870
11697
|
categoryRetries[category] += 1;
|
|
@@ -11901,16 +11728,11 @@ function waitForRetry(delayMs, signal) {
|
|
|
11901
11728
|
}
|
|
11902
11729
|
function isClientRetryEnabledForModel(modelCatalog, modelId, options) {
|
|
11903
11730
|
if (options.retry_policy === "none") return false;
|
|
11904
|
-
|
|
11905
|
-
if (cfg?.billing_mode === "cloud") return false;
|
|
11906
|
-
if (options.retry_policy === "client") return true;
|
|
11907
|
-
if (!cfg) return true;
|
|
11908
|
-
if (cfg.enable_client_retry === false) return false;
|
|
11909
|
-
return true;
|
|
11731
|
+
return modelCatalog.getModelById(modelId)?.enable_client_retry !== false;
|
|
11910
11732
|
}
|
|
11911
11733
|
function throwIfAborted(signal, message) {
|
|
11912
11734
|
if (!signal?.aborted) return;
|
|
11913
|
-
|
|
11735
|
+
logger15.info(message);
|
|
11914
11736
|
const reason = signal.reason;
|
|
11915
11737
|
if (reason instanceof Error && reason.name === "AbortError") throw reason;
|
|
11916
11738
|
const reasonText = typeof reason === "string" && reason.trim().length > 0 ? reason : "stream_interrupted";
|
|
@@ -12228,7 +12050,7 @@ async function recoverChildRunEventsFromCheckpoint(params) {
|
|
|
12228
12050
|
}
|
|
12229
12051
|
|
|
12230
12052
|
// src/runtime-kernel/child-runs/childRunInvoker.ts
|
|
12231
|
-
var
|
|
12053
|
+
var logger16 = new Logger("ChildRunInvoker");
|
|
12232
12054
|
var ChildRunInvoker = class {
|
|
12233
12055
|
modelResolver;
|
|
12234
12056
|
createLlmNode;
|
|
@@ -12270,7 +12092,7 @@ var ChildRunInvoker = class {
|
|
|
12270
12092
|
const resolvedParentRunId = parentRunId ?? parentToolContext.runId;
|
|
12271
12093
|
const depthDecision = decideChildRunDepth({ parentToolContext });
|
|
12272
12094
|
if (!depthDecision.allowed) {
|
|
12273
|
-
|
|
12095
|
+
logger16.warn("child-run \u6DF1\u5EA6\u8D85\u8FC7\u4E0A\u9650\uFF0C\u62D2\u7EDD\u7EE7\u7EED\u9012\u5F52\u6267\u884C", {
|
|
12274
12096
|
runId: childRunId,
|
|
12275
12097
|
parentRunId: resolvedParentRunId,
|
|
12276
12098
|
parentDepth: depthDecision.parentDepth,
|
|
@@ -12287,7 +12109,7 @@ var ChildRunInvoker = class {
|
|
|
12287
12109
|
};
|
|
12288
12110
|
}
|
|
12289
12111
|
if (abortSignal?.aborted || parentToolContext.abortSignal?.aborted) {
|
|
12290
|
-
|
|
12112
|
+
logger16.info("child-run \u5728\u4EFB\u52A1\u63A5\u7EB3\u524D\u5DF2\u53D6\u6D88", {
|
|
12291
12113
|
runId: childRunId,
|
|
12292
12114
|
parentRunId: resolvedParentRunId
|
|
12293
12115
|
});
|
|
@@ -12311,7 +12133,7 @@ var ChildRunInvoker = class {
|
|
|
12311
12133
|
}
|
|
12312
12134
|
const turnId = config.initialInput?.turnId ?? generateTurnId();
|
|
12313
12135
|
if (config.initialInput && (!turnId.trim() || config.initialInput.request.query !== userMessage || config.initialInput.request.promptKey !== agentConfig.promptKey || !config.initialInput.request.model_id)) throw new Error("Child initial input does not match the admitted invocation");
|
|
12314
|
-
|
|
12136
|
+
logger16.info(`\u542F\u52A8 child-run: ${agentConfig.id}`, {
|
|
12315
12137
|
conversationId: runtimeConversationId,
|
|
12316
12138
|
checkpointKey: internalCheckpointKey,
|
|
12317
12139
|
maxSteps,
|
|
@@ -12429,7 +12251,7 @@ var ChildRunInvoker = class {
|
|
|
12429
12251
|
);
|
|
12430
12252
|
finalAnswer = extractFinalAnswer(allEvents);
|
|
12431
12253
|
lastProgress = finalAnswer ? void 0 : extractLastProgress(allEvents);
|
|
12432
|
-
|
|
12254
|
+
logger16.info("child-run \u6267\u884C\u5B8C\u6210", {
|
|
12433
12255
|
stepCount,
|
|
12434
12256
|
eventCount: allEvents.length,
|
|
12435
12257
|
hasFinalAnswer: !!finalAnswer,
|
|
@@ -12459,13 +12281,13 @@ var ChildRunInvoker = class {
|
|
|
12459
12281
|
cancelled = abortSignal?.aborted === true || isAbortError2(err);
|
|
12460
12282
|
error = err instanceof Error ? err.message : String(err);
|
|
12461
12283
|
if (cancelled) {
|
|
12462
|
-
|
|
12284
|
+
logger16.info("child-run \u6267\u884C\u53D6\u6D88", {
|
|
12463
12285
|
runId: childRunId,
|
|
12464
12286
|
parentRunId: resolvedParentRunId,
|
|
12465
12287
|
message: error
|
|
12466
12288
|
});
|
|
12467
12289
|
} else {
|
|
12468
|
-
|
|
12290
|
+
logger16.error(
|
|
12469
12291
|
"child-run \u6267\u884C\u5931\u8D25:",
|
|
12470
12292
|
err instanceof Error ? {
|
|
12471
12293
|
name: err.name,
|
|
@@ -12561,7 +12383,7 @@ var ChildRunInvoker = class {
|
|
|
12561
12383
|
function isAbortError2(error) {
|
|
12562
12384
|
return error instanceof Error && error.name === "AbortError";
|
|
12563
12385
|
}
|
|
12564
|
-
function
|
|
12386
|
+
function readNonEmptyString5(value) {
|
|
12565
12387
|
if (typeof value !== "string") {
|
|
12566
12388
|
return void 0;
|
|
12567
12389
|
}
|
|
@@ -12569,7 +12391,7 @@ function readNonEmptyString6(value) {
|
|
|
12569
12391
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
12570
12392
|
}
|
|
12571
12393
|
function resolveChildRunConversationId(params) {
|
|
12572
|
-
const conversationId =
|
|
12394
|
+
const conversationId = readNonEmptyString5(params.explicitConversationId) ?? readNonEmptyString5(params.parentToolContext.conversationId);
|
|
12573
12395
|
if (!conversationId) {
|
|
12574
12396
|
throw new Error(
|
|
12575
12397
|
"ChildRunInvoker requires conversationId from admission or parent ToolContext."
|
|
@@ -12578,7 +12400,7 @@ function resolveChildRunConversationId(params) {
|
|
|
12578
12400
|
return conversationId;
|
|
12579
12401
|
}
|
|
12580
12402
|
function resolveChildRunModelId(params) {
|
|
12581
|
-
const explicitModelId =
|
|
12403
|
+
const explicitModelId = readNonEmptyString5(params.explicitModelId);
|
|
12582
12404
|
if (explicitModelId) {
|
|
12583
12405
|
return explicitModelId;
|
|
12584
12406
|
}
|
|
@@ -13523,7 +13345,7 @@ function runMetaFromRecord(record) {
|
|
|
13523
13345
|
}
|
|
13524
13346
|
|
|
13525
13347
|
// src/runtime-kernel/run-supervisor/functions/awaitingUserWatcher.ts
|
|
13526
|
-
var
|
|
13348
|
+
var logger17 = new Logger("RunSupervisorAwaitingUserWatcher");
|
|
13527
13349
|
function isRecord16(value) {
|
|
13528
13350
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13529
13351
|
}
|
|
@@ -13568,7 +13390,7 @@ function createAwaitingUserWatcher(options) {
|
|
|
13568
13390
|
resumeToken: event.resume_token
|
|
13569
13391
|
}
|
|
13570
13392
|
}).catch((error) => {
|
|
13571
|
-
|
|
13393
|
+
logger17.warn("failed to mark awaiting_user from requires_user_interaction", { error });
|
|
13572
13394
|
});
|
|
13573
13395
|
};
|
|
13574
13396
|
const dispose = () => {
|