@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/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,7 +5103,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5170
5103
|
"turnId"
|
|
5171
5104
|
],
|
|
5172
5105
|
writes: [
|
|
5173
|
-
"cloudQuotaFallbackAppliedModelId",
|
|
5174
5106
|
"modelFallbackAudit",
|
|
5175
5107
|
"llmCallStartedAt",
|
|
5176
5108
|
"llmResp",
|
|
@@ -5178,7 +5110,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5178
5110
|
"contextUsage"
|
|
5179
5111
|
],
|
|
5180
5112
|
async run(ctx) {
|
|
5181
|
-
let cloudQuotaFallbackAppliedModelId;
|
|
5182
5113
|
let modelFallbackAudit;
|
|
5183
5114
|
let contextUsage;
|
|
5184
5115
|
const modelFallbackRejections = [];
|
|
@@ -5197,9 +5128,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5197
5128
|
streamEventHandler,
|
|
5198
5129
|
ctx.signal,
|
|
5199
5130
|
{
|
|
5200
|
-
onCloudQuotaFallbackApplied(fallbackModelId) {
|
|
5201
|
-
cloudQuotaFallbackAppliedModelId = readNonEmptyString3(fallbackModelId);
|
|
5202
|
-
},
|
|
5203
5131
|
onLlmAttemptSucceeded(_activeModelId, attemptContextUsage) {
|
|
5204
5132
|
contextUsage = attemptContextUsage;
|
|
5205
5133
|
},
|
|
@@ -5296,7 +5224,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5296
5224
|
});
|
|
5297
5225
|
}
|
|
5298
5226
|
return {
|
|
5299
|
-
cloudQuotaFallbackAppliedModelId,
|
|
5300
5227
|
modelFallbackAudit,
|
|
5301
5228
|
llmCallStartedAt,
|
|
5302
5229
|
llmResp,
|
|
@@ -6217,18 +6144,16 @@ function createPrepareCallStage(dependencies) {
|
|
|
6217
6144
|
"toolDefinitionTokens"
|
|
6218
6145
|
],
|
|
6219
6146
|
async run(ctx) {
|
|
6220
|
-
const
|
|
6221
|
-
const requestedModelId = lockedRunModelId ?? ctx.request.model_id;
|
|
6147
|
+
const requestedModelId = ctx.request.model_id;
|
|
6222
6148
|
const modelId = dependencies.modelResolver.resolveModelId(requestedModelId);
|
|
6223
6149
|
await emitAuditEnvelope(ctx.audit, {
|
|
6224
6150
|
action: "model.select",
|
|
6225
6151
|
actor: { kind: "system" },
|
|
6226
6152
|
decision: {
|
|
6227
6153
|
outcome: "recorded",
|
|
6228
|
-
reason:
|
|
6154
|
+
reason: requestedModelId ? "request model id" : "default model resolver",
|
|
6229
6155
|
metadata: {
|
|
6230
6156
|
requestedModelId,
|
|
6231
|
-
lockedRunModelId,
|
|
6232
6157
|
selectedModelId: modelId
|
|
6233
6158
|
}
|
|
6234
6159
|
},
|
|
@@ -6275,10 +6200,6 @@ function createPrepareCallStage(dependencies) {
|
|
|
6275
6200
|
if (ctx.executorLocal?.lockRequestedModelId === true) {
|
|
6276
6201
|
llmOptions.allow_model_fallback = false;
|
|
6277
6202
|
}
|
|
6278
|
-
const isRunContinuation = ctx.executorLocal?.llmInvocationKind === "continuation";
|
|
6279
|
-
if (dependencies.cloudQuotaFallbackModelId && modelConfig?.billing_mode === "cloud" && modelId !== dependencies.cloudQuotaFallbackModelId && isRunContinuation && ctx.executorLocal?.lockRequestedModelId !== true) {
|
|
6280
|
-
llmOptions.cloud_quota_fallback_model_id = dependencies.cloudQuotaFallbackModelId;
|
|
6281
|
-
}
|
|
6282
6203
|
const effectiveEffort = resolveEffectiveEffort(
|
|
6283
6204
|
ctx.request.reasoning_effort,
|
|
6284
6205
|
modelConfig?.reasoning
|
|
@@ -6395,12 +6316,11 @@ function applyCalibration(rawLocalTotal, imageInputTokens, coefficient) {
|
|
|
6395
6316
|
}
|
|
6396
6317
|
|
|
6397
6318
|
// src/runtime-kernel/graph-engine/executor.ts
|
|
6398
|
-
var
|
|
6319
|
+
var logger5 = new Logger("GraphAgentExecutor");
|
|
6399
6320
|
var GraphAgentExecutor = class {
|
|
6400
6321
|
llmCaller;
|
|
6401
6322
|
toolRuntime;
|
|
6402
6323
|
contextBuilder;
|
|
6403
|
-
cloudQuotaFallbackModelId;
|
|
6404
6324
|
modelResolver;
|
|
6405
6325
|
modelCatalog;
|
|
6406
6326
|
telemetryPort;
|
|
@@ -6412,7 +6332,6 @@ var GraphAgentExecutor = class {
|
|
|
6412
6332
|
this.llmCaller = dependencies.llmCaller;
|
|
6413
6333
|
this.toolRuntime = dependencies.toolRuntime;
|
|
6414
6334
|
this.contextBuilder = dependencies.contextBuilder;
|
|
6415
|
-
this.cloudQuotaFallbackModelId = readNonEmptyString3(dependencies.cloudQuotaFallbackModelId);
|
|
6416
6335
|
this.modelCatalog = dependencies.modelCatalog ?? createEmptyModelCatalog();
|
|
6417
6336
|
this.modelResolver = dependencies.modelResolver ?? new ModelResolver({
|
|
6418
6337
|
modelCatalog: this.modelCatalog
|
|
@@ -6429,8 +6348,7 @@ var GraphAgentExecutor = class {
|
|
|
6429
6348
|
createPrepareCallStage({
|
|
6430
6349
|
modelResolver: this.modelResolver,
|
|
6431
6350
|
modelCatalog: this.modelCatalog,
|
|
6432
|
-
toolCatalog: this.toolRuntime
|
|
6433
|
-
cloudQuotaFallbackModelId: this.cloudQuotaFallbackModelId
|
|
6351
|
+
toolCatalog: this.toolRuntime
|
|
6434
6352
|
}),
|
|
6435
6353
|
createBuildContextStage({
|
|
6436
6354
|
contextBuilder: this.contextBuilder
|
|
@@ -6452,7 +6370,7 @@ var GraphAgentExecutor = class {
|
|
|
6452
6370
|
}),
|
|
6453
6371
|
createBuildDecisionStage()
|
|
6454
6372
|
];
|
|
6455
|
-
this.middlewares = [llmTelemetryMiddleware
|
|
6373
|
+
this.middlewares = [llmTelemetryMiddleware];
|
|
6456
6374
|
}
|
|
6457
6375
|
async tick(input, eventHandler) {
|
|
6458
6376
|
const ctx = {
|
|
@@ -6477,7 +6395,7 @@ var GraphAgentExecutor = class {
|
|
|
6477
6395
|
audit: this.auditPort,
|
|
6478
6396
|
tokenizer: this.tokenizer
|
|
6479
6397
|
};
|
|
6480
|
-
|
|
6398
|
+
logger5.info("[GraphAgentExecutor] tick \u8C03\u7528", {
|
|
6481
6399
|
stream: input.stream === true,
|
|
6482
6400
|
hasEventHandler: Boolean(eventHandler),
|
|
6483
6401
|
hasSummarizationCallbacks: Boolean(input.summarizationCallbacks)
|
|
@@ -7500,7 +7418,7 @@ var LlmNodeEventBridge = class {
|
|
|
7500
7418
|
};
|
|
7501
7419
|
|
|
7502
7420
|
// src/runtime-kernel/graph-engine/nodes/llmNode.ts
|
|
7503
|
-
var
|
|
7421
|
+
var logger6 = new Logger("LlmNode");
|
|
7504
7422
|
var LlmNode = class {
|
|
7505
7423
|
id = "llm";
|
|
7506
7424
|
reasoner;
|
|
@@ -7509,7 +7427,7 @@ var LlmNode = class {
|
|
|
7509
7427
|
}
|
|
7510
7428
|
async run(state) {
|
|
7511
7429
|
const local = state.local ?? {};
|
|
7512
|
-
|
|
7430
|
+
logger6.info("[LlmNode] \u5F00\u59CB\u6267\u884C LLM \u8282\u70B9", {
|
|
7513
7431
|
localKeys: Object.keys(local)
|
|
7514
7432
|
});
|
|
7515
7433
|
const graphLocal = readGraphAgentLocal(state.local);
|
|
@@ -7524,12 +7442,12 @@ var LlmNode = class {
|
|
|
7524
7442
|
signal,
|
|
7525
7443
|
history
|
|
7526
7444
|
} = graphLocal;
|
|
7527
|
-
|
|
7445
|
+
logger6.info("[LlmNode] \u5DF2\u52A0\u8F7D\u5386\u53F2\u4E8B\u4EF6", {
|
|
7528
7446
|
historyCount: history.length,
|
|
7529
7447
|
hasSummarizationCallbacks: Boolean(summarizationCallbacks)
|
|
7530
7448
|
});
|
|
7531
7449
|
if (!request) {
|
|
7532
|
-
|
|
7450
|
+
logger6.warn("Request object is missing, yielding.");
|
|
7533
7451
|
return { kind: "yield", events: [] };
|
|
7534
7452
|
}
|
|
7535
7453
|
const turnId = requireRuntimeIdentity(graphLocal.turnId, "turnId");
|
|
@@ -7622,12 +7540,12 @@ var LlmNode = class {
|
|
|
7622
7540
|
...nodeState.streamRuntimeEvents,
|
|
7623
7541
|
...contextUsageEvent ? [contextUsageEvent] : []
|
|
7624
7542
|
];
|
|
7625
|
-
|
|
7543
|
+
logger6.info("[LlmNode] \u5386\u53F2\u4E8B\u4EF6\u5DF2\u66F4\u65B0", {
|
|
7626
7544
|
previousCount: history.length,
|
|
7627
7545
|
nextCount: patch.history.length,
|
|
7628
7546
|
streamedEventCount: nodeState.streamRuntimeEvents.length
|
|
7629
7547
|
});
|
|
7630
|
-
|
|
7548
|
+
logger6.info("[LlmNode] \u6267\u884C\u5668\u51B3\u7B56\u5B8C\u6210", {
|
|
7631
7549
|
decisionKind: decision.kind,
|
|
7632
7550
|
emittedEventCount: combinedEvents.length
|
|
7633
7551
|
});
|
|
@@ -7649,7 +7567,7 @@ var LlmNode = class {
|
|
|
7649
7567
|
}
|
|
7650
7568
|
case "error": {
|
|
7651
7569
|
const { name, message, stack } = decision.error;
|
|
7652
|
-
|
|
7570
|
+
logger6.error("[LlmNode] Executor returned an error", { name, message, stack });
|
|
7653
7571
|
return { kind: "yield", events: combinedEvents };
|
|
7654
7572
|
}
|
|
7655
7573
|
default: {
|
|
@@ -7755,7 +7673,7 @@ async function resolveToolModelInput(input) {
|
|
|
7755
7673
|
}
|
|
7756
7674
|
|
|
7757
7675
|
// src/runtime-kernel/graph-engine/nodes/toolNode.finalAnswerProjector.ts
|
|
7758
|
-
function
|
|
7676
|
+
function readNonEmptyString4(value) {
|
|
7759
7677
|
if (typeof value !== "string") {
|
|
7760
7678
|
return void 0;
|
|
7761
7679
|
}
|
|
@@ -7763,7 +7681,7 @@ function readNonEmptyString5(value) {
|
|
|
7763
7681
|
return normalized.length > 0 ? normalized : void 0;
|
|
7764
7682
|
}
|
|
7765
7683
|
function resolveFinalAnswerFromToolControl(finalAnswer) {
|
|
7766
|
-
return
|
|
7684
|
+
return readNonEmptyString4(finalAnswer);
|
|
7767
7685
|
}
|
|
7768
7686
|
|
|
7769
7687
|
// src/runtime-kernel/graph-engine/nodes/toolNode.helpers.ts
|
|
@@ -8019,7 +7937,7 @@ function buildErrorLocalState(params) {
|
|
|
8019
7937
|
}
|
|
8020
7938
|
|
|
8021
7939
|
// src/runtime-kernel/tools/argNormalizer.ts
|
|
8022
|
-
var
|
|
7940
|
+
var logger7 = new Logger("ToolArgNormalizer");
|
|
8023
7941
|
function isRecord10(v) {
|
|
8024
7942
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
8025
7943
|
}
|
|
@@ -8039,7 +7957,7 @@ function joinPath(basePath, segment) {
|
|
|
8039
7957
|
function logJsonEncodedNormalization(expectedType, options) {
|
|
8040
7958
|
const toolPrefix = options.toolName ? `${options.toolName}.` : "";
|
|
8041
7959
|
const path = options.path ?? "<root>";
|
|
8042
|
-
|
|
7960
|
+
logger7.warn("normalized JSON-encoded tool argument", {
|
|
8043
7961
|
expectedType,
|
|
8044
7962
|
path: `${toolPrefix}${path}`
|
|
8045
7963
|
});
|
|
@@ -8209,7 +8127,6 @@ var TOOL_CONTEXT_RUNTIME_RESERVED_KEYS = [
|
|
|
8209
8127
|
"conversationView",
|
|
8210
8128
|
"userQuery",
|
|
8211
8129
|
"modelId",
|
|
8212
|
-
"activeModelId",
|
|
8213
8130
|
"conversationId",
|
|
8214
8131
|
"turnId",
|
|
8215
8132
|
"runId",
|
|
@@ -8396,7 +8313,7 @@ function stripRuntimeReservedToolContextPatch(patch) {
|
|
|
8396
8313
|
}
|
|
8397
8314
|
|
|
8398
8315
|
// src/runtime-kernel/graph-engine/nodes/toolNode.eventBridge.ts
|
|
8399
|
-
var
|
|
8316
|
+
var logger8 = new Logger("ToolNode");
|
|
8400
8317
|
var ToolNodeEventBridge = class {
|
|
8401
8318
|
constructor(deps) {
|
|
8402
8319
|
this.deps = deps;
|
|
@@ -8418,7 +8335,7 @@ var ToolNodeEventBridge = class {
|
|
|
8418
8335
|
status,
|
|
8419
8336
|
payload: { ...payload }
|
|
8420
8337
|
};
|
|
8421
|
-
|
|
8338
|
+
logger8.info("[ToolNode] \u53D1\u51FA tool_process \u4E8B\u4EF6", {
|
|
8422
8339
|
phase,
|
|
8423
8340
|
status,
|
|
8424
8341
|
toolName: this.deps.toolName,
|
|
@@ -8458,7 +8375,7 @@ var ToolNodeEventBridge = class {
|
|
|
8458
8375
|
const answerId = generateAnswerSegmentId();
|
|
8459
8376
|
const id = answerId;
|
|
8460
8377
|
const timestamp = Date.now();
|
|
8461
|
-
|
|
8378
|
+
logger8.info("[ToolNode] \u5DE5\u5177\u8F93\u51FA\u6620\u5C04\u4E3A final_answer", {
|
|
8462
8379
|
sourceToolName: params.sourceToolName,
|
|
8463
8380
|
toolCallId: this.deps.toolCallId,
|
|
8464
8381
|
conversationId: this.deps.conversationId,
|
|
@@ -8516,7 +8433,7 @@ var ToolNodeEventBridge = class {
|
|
|
8516
8433
|
};
|
|
8517
8434
|
|
|
8518
8435
|
// src/runtime-kernel/graph-engine/nodes/toolNode.executionSetup.ts
|
|
8519
|
-
var
|
|
8436
|
+
var logger9 = new Logger("ToolNode");
|
|
8520
8437
|
function parseToolArgs(call) {
|
|
8521
8438
|
const rawArguments = typeof call.function?.arguments === "string" ? call.function.arguments : "";
|
|
8522
8439
|
if (!rawArguments.trim()) {
|
|
@@ -8536,19 +8453,13 @@ function parseToolArgs(call) {
|
|
|
8536
8453
|
return { ok: true, value: parsed };
|
|
8537
8454
|
} catch (error) {
|
|
8538
8455
|
const reason = error instanceof Error ? error.message : "Unknown JSON parse error";
|
|
8539
|
-
|
|
8456
|
+
logger9.warn("failed to parse tool arguments", { error });
|
|
8540
8457
|
return {
|
|
8541
8458
|
ok: false,
|
|
8542
8459
|
error: `Tool arguments are not valid JSON: ${reason}`
|
|
8543
8460
|
};
|
|
8544
8461
|
}
|
|
8545
8462
|
}
|
|
8546
|
-
function readRunLockedModelId(local) {
|
|
8547
|
-
const executorLocal = local.executorLocal;
|
|
8548
|
-
if (!isRecord9(executorLocal)) return void 0;
|
|
8549
|
-
const lockedModelId = executorLocal.runLockedModelId;
|
|
8550
|
-
return typeof lockedModelId === "string" && lockedModelId.trim() ? lockedModelId : void 0;
|
|
8551
|
-
}
|
|
8552
8463
|
function prepareToolNodeContext(state) {
|
|
8553
8464
|
const local = state.local || {};
|
|
8554
8465
|
const toolContext = isRecord9(local.toolContext) ? local.toolContext : {};
|
|
@@ -8566,7 +8477,6 @@ function prepareToolNodeContext(state) {
|
|
|
8566
8477
|
}
|
|
8567
8478
|
});
|
|
8568
8479
|
attachWorkingHistoryView({ state, toolContext });
|
|
8569
|
-
toolContext.activeModelId = readRunLockedModelId(local) ?? toolContext.modelId;
|
|
8570
8480
|
return {
|
|
8571
8481
|
state,
|
|
8572
8482
|
local,
|
|
@@ -8937,7 +8847,7 @@ async function claimPendingUserInputs(state, result) {
|
|
|
8937
8847
|
}
|
|
8938
8848
|
|
|
8939
8849
|
// src/runtime-kernel/graph-engine/nodes/toolNode.ts
|
|
8940
|
-
var
|
|
8850
|
+
var logger10 = new Logger("ToolNode");
|
|
8941
8851
|
function isAbortSignal(value) {
|
|
8942
8852
|
return value !== null && typeof value === "object" && "aborted" in value;
|
|
8943
8853
|
}
|
|
@@ -9150,7 +9060,7 @@ var ToolNode = class {
|
|
|
9150
9060
|
throw abortError;
|
|
9151
9061
|
}
|
|
9152
9062
|
const prepared = prepareToolNodeContext(state);
|
|
9153
|
-
|
|
9063
|
+
logger10.info("[ToolNode] \u5F00\u59CB\u6267\u884C\u5DE5\u5177\u8282\u70B9", {
|
|
9154
9064
|
conversationId: prepared.conversationId,
|
|
9155
9065
|
turnId: prepared.turnId,
|
|
9156
9066
|
pendingCallCount: calls.length
|
|
@@ -9165,7 +9075,7 @@ var ToolNode = class {
|
|
|
9165
9075
|
toolCatalog: this.toolRuntime
|
|
9166
9076
|
});
|
|
9167
9077
|
if (!execution) {
|
|
9168
|
-
|
|
9078
|
+
logger10.warn("no tool name found in call");
|
|
9169
9079
|
return { kind: "yield", events: [] };
|
|
9170
9080
|
}
|
|
9171
9081
|
if (typeof execution.protocolError === "string") {
|
|
@@ -9205,7 +9115,7 @@ var ToolNode = class {
|
|
|
9205
9115
|
call,
|
|
9206
9116
|
context: prepared.toolContext,
|
|
9207
9117
|
abortGraceMs: this.abortGraceMs,
|
|
9208
|
-
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", {
|
|
9209
9119
|
toolName: execution.toolName,
|
|
9210
9120
|
toolCallId: execution.toolCallId,
|
|
9211
9121
|
conversationId: prepared.conversationId,
|
|
@@ -9375,7 +9285,7 @@ var ToolNode = class {
|
|
|
9375
9285
|
runtimeEvents: context.bridge.getRuntimeEvents()
|
|
9376
9286
|
});
|
|
9377
9287
|
if (control?.terminateRun) {
|
|
9378
|
-
|
|
9288
|
+
logger10.info("[ToolNode] \u6536\u5230 control.terminateRun\uFF0C\u6267\u884C\u5B8C\u5DE5\u5177\u540E\u76F4\u63A5 yield \u7ED3\u675F\u672C\u8F6E run", {
|
|
9379
9289
|
toolName: context.toolName,
|
|
9380
9290
|
toolCallId: context.toolCallId,
|
|
9381
9291
|
conversationId: context.conversationId,
|
|
@@ -9384,7 +9294,7 @@ var ToolNode = class {
|
|
|
9384
9294
|
return { kind: "yield", events: context.bridge.getRuntimeEvents() };
|
|
9385
9295
|
}
|
|
9386
9296
|
if (remainingCalls.length === 0 && context.local.toolBatchCompletionMode === "yield_after_batch") {
|
|
9387
|
-
|
|
9297
|
+
logger10.info("[ToolNode] \u5DE5\u5177\u6279\u6B21\u5DF2\u7ED3\u7B97\uFF0C\u6309 Host \u7B56\u7565\u76F4\u63A5 yield", {
|
|
9388
9298
|
toolName: context.toolName,
|
|
9389
9299
|
toolCallId: context.toolCallId,
|
|
9390
9300
|
conversationId: context.conversationId,
|
|
@@ -9831,8 +9741,9 @@ var executor = zod.z.object({
|
|
|
9831
9741
|
lastStepsHintThreshold: counter.optional(),
|
|
9832
9742
|
systemReminderPolicy: AgentSpecSystemReminderPolicy.optional(),
|
|
9833
9743
|
toolObservationPolicy: AgentSpecToolObservationGovernancePolicy.optional(),
|
|
9744
|
+
// 已删除字段:0.45 及更早的 checkpoint 可能带 lastSuccessfulLlmModelId,0.46 及更早的可能带云端额度兜底留下的
|
|
9745
|
+
// runLockedModelId;照常接受,读入时丢弃(兜底已移除,恢复后按请求的模型继续)。
|
|
9834
9746
|
runLockedModelId: zod.z.string().optional(),
|
|
9835
|
-
// 0.45 及更早的 checkpoint 可能带这个已删除字段;照常接受,读入时丢弃。
|
|
9836
9747
|
lastSuccessfulLlmModelId: zod.z.string().optional(),
|
|
9837
9748
|
llmInvocationKind: zod.z.enum(["user_initiated", "continuation"]).optional(),
|
|
9838
9749
|
llmInvocationCount: counter.optional(),
|
|
@@ -9842,7 +9753,7 @@ var executor = zod.z.object({
|
|
|
9842
9753
|
committedCount: counter,
|
|
9843
9754
|
lastCommittedFingerprint: zod.z.string().optional()
|
|
9844
9755
|
}).strict().optional()
|
|
9845
|
-
}).strict().transform(({ lastSuccessfulLlmModelId: _retired, ...state }) => state);
|
|
9756
|
+
}).strict().transform(({ lastSuccessfulLlmModelId: _retired, runLockedModelId: _retiredLock, ...state }) => state);
|
|
9846
9757
|
var checkpoint = zod.z.object({
|
|
9847
9758
|
nodeId: zod.z.string().min(1),
|
|
9848
9759
|
schemaVersion: zod.z.literal(ENGINE_STATE_SCHEMA_VERSION).optional(),
|
|
@@ -10156,7 +10067,7 @@ __export(execution_exports, {
|
|
|
10156
10067
|
});
|
|
10157
10068
|
|
|
10158
10069
|
// src/runtime-kernel/execution/event-bus.ts
|
|
10159
|
-
var
|
|
10070
|
+
var logger11 = new Logger("EventBus");
|
|
10160
10071
|
var TypedEventEmitter = class {
|
|
10161
10072
|
listeners = /* @__PURE__ */ new Map();
|
|
10162
10073
|
maxListeners = 10;
|
|
@@ -10164,7 +10075,7 @@ var TypedEventEmitter = class {
|
|
|
10164
10075
|
const listeners = this.getListeners(event);
|
|
10165
10076
|
listeners.add(listener);
|
|
10166
10077
|
if (listeners.size > this.maxListeners) {
|
|
10167
|
-
|
|
10078
|
+
logger11.warn("EventBus listener count exceeds configured max", {
|
|
10168
10079
|
event: String(event),
|
|
10169
10080
|
count: listeners.size,
|
|
10170
10081
|
maxListeners: this.maxListeners
|
|
@@ -10224,7 +10135,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10224
10135
|
super();
|
|
10225
10136
|
this.executionId = executionId;
|
|
10226
10137
|
this.setMaxListeners(30);
|
|
10227
|
-
|
|
10138
|
+
logger11.info(`EventBus created for execution ${this.executionId}`);
|
|
10228
10139
|
}
|
|
10229
10140
|
/**
|
|
10230
10141
|
* 发布一个事件到总线
|
|
@@ -10233,7 +10144,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10233
10144
|
publish(envelope) {
|
|
10234
10145
|
if (envelope.trace.execution_id !== this.executionId) {
|
|
10235
10146
|
const error = new Error("EventEnvelope execution_id does not match EventBus instance.");
|
|
10236
|
-
|
|
10147
|
+
logger11.error("Mismatched execution_id", {
|
|
10237
10148
|
busExecutionId: this.executionId,
|
|
10238
10149
|
eventExecutionId: envelope.trace.execution_id,
|
|
10239
10150
|
eventSeq: envelope.seq
|
|
@@ -10245,7 +10156,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10245
10156
|
const error = new Error(
|
|
10246
10157
|
"EventBus only accepts RuntimeEvent with formal run routing identity."
|
|
10247
10158
|
);
|
|
10248
|
-
|
|
10159
|
+
logger11.error("RuntimeEvent is missing formal run routing identity", {
|
|
10249
10160
|
executionId: this.executionId,
|
|
10250
10161
|
eventId: envelope.payload.id,
|
|
10251
10162
|
eventType: envelope.payload.type
|
|
@@ -10259,14 +10170,14 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10259
10170
|
* 关闭总线,清理所有监听器
|
|
10260
10171
|
*/
|
|
10261
10172
|
close() {
|
|
10262
|
-
|
|
10173
|
+
logger11.info(`Closing EventBus for execution ${this.executionId}`);
|
|
10263
10174
|
this.emit("close");
|
|
10264
10175
|
this.removeAllListeners();
|
|
10265
10176
|
}
|
|
10266
10177
|
};
|
|
10267
10178
|
|
|
10268
10179
|
// src/runtime-kernel/execution/sequencer.ts
|
|
10269
|
-
var
|
|
10180
|
+
var logger12 = new Logger("EventSequencer");
|
|
10270
10181
|
var EventSequencer = class {
|
|
10271
10182
|
executionId;
|
|
10272
10183
|
traceId;
|
|
@@ -10274,7 +10185,7 @@ var EventSequencer = class {
|
|
|
10274
10185
|
constructor(conversationId, traceId) {
|
|
10275
10186
|
this.executionId = generateExecutionId();
|
|
10276
10187
|
this.traceId = traceId || generateTraceId();
|
|
10277
|
-
|
|
10188
|
+
logger12.info(`EventSequencer created for conversation ${conversationId}`, {
|
|
10278
10189
|
executionId: this.executionId,
|
|
10279
10190
|
traceId: this.traceId
|
|
10280
10191
|
});
|
|
@@ -11132,7 +11043,7 @@ var ThoughtStreamSegmenter = class {
|
|
|
11132
11043
|
};
|
|
11133
11044
|
|
|
11134
11045
|
// src/runtime-kernel/llm/streaming-adapter.ts
|
|
11135
|
-
var
|
|
11046
|
+
var logger13 = new Logger("LlmCaller");
|
|
11136
11047
|
var CanonicalInferenceFailureError = class extends Error {
|
|
11137
11048
|
errorCode;
|
|
11138
11049
|
recoverable;
|
|
@@ -11356,7 +11267,7 @@ async function callLlmStream(params) {
|
|
|
11356
11267
|
} catch (error) {
|
|
11357
11268
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
11358
11269
|
if (normalized.name === "AbortError") {
|
|
11359
|
-
|
|
11270
|
+
logger13.info("Canonical inference \u6536\u5230\u53D6\u6D88\u7EC8\u6001\uFF0C\u4E0D\u53D1\u5E03\u666E\u901A error event", { modelId });
|
|
11360
11271
|
throw normalized;
|
|
11361
11272
|
}
|
|
11362
11273
|
const classification = ErrorClassifier.classify(normalized, {
|
|
@@ -11432,7 +11343,7 @@ var LlmRetryEpisode = class {
|
|
|
11432
11343
|
};
|
|
11433
11344
|
|
|
11434
11345
|
// src/runtime-kernel/llm/retry-fallback-routing.ts
|
|
11435
|
-
var
|
|
11346
|
+
var logger14 = new Logger("LlmCaller");
|
|
11436
11347
|
function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement, fallbackObserver, error, evaluateFallbackPromptCapacity2) {
|
|
11437
11348
|
deps.modelCatalog.getModelById(activeModelId);
|
|
11438
11349
|
const policyDecision = deps.policyEngine.decideOnError(error, {
|
|
@@ -11462,81 +11373,16 @@ function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement
|
|
|
11462
11373
|
reason: "no_eligible_fallback_candidate",
|
|
11463
11374
|
requiredPlacements: requirement.placements
|
|
11464
11375
|
});
|
|
11465
|
-
|
|
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");
|
|
11466
11377
|
return null;
|
|
11467
11378
|
}
|
|
11468
|
-
|
|
11379
|
+
logger14.warn("Policy \u5207\u6362\u6A21\u578B\u7EE7\u7EED", {
|
|
11469
11380
|
reason: policyDecision.reason,
|
|
11470
11381
|
activeModelId,
|
|
11471
11382
|
fallbackModelId
|
|
11472
11383
|
});
|
|
11473
11384
|
return fallbackModelId;
|
|
11474
11385
|
}
|
|
11475
|
-
function tryCloudQuotaFallback({
|
|
11476
|
-
deps,
|
|
11477
|
-
activeModelId,
|
|
11478
|
-
options,
|
|
11479
|
-
excludedModelIds,
|
|
11480
|
-
requirement,
|
|
11481
|
-
error,
|
|
11482
|
-
fallbackObserver,
|
|
11483
|
-
evaluateFallbackPromptCapacity: evaluateFallbackPromptCapacity2
|
|
11484
|
-
}) {
|
|
11485
|
-
const fallbackModelId = options.cloud_quota_fallback_model_id;
|
|
11486
|
-
if (!fallbackModelId || !ErrorClassifier.isCloudQuotaError(error) || excludedModelIds.has(fallbackModelId)) {
|
|
11487
|
-
return null;
|
|
11488
|
-
}
|
|
11489
|
-
const fallbackConfig = deps.modelCatalog.getModelById(fallbackModelId);
|
|
11490
|
-
if (!fallbackConfig?.api_key) {
|
|
11491
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11492
|
-
fromModelId: activeModelId,
|
|
11493
|
-
candidateModelId: fallbackModelId,
|
|
11494
|
-
policy: "cloud-quota",
|
|
11495
|
-
reason: "fallback_model_unavailable",
|
|
11496
|
-
requiredPlacements: requirement.placements
|
|
11497
|
-
});
|
|
11498
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\u76EE\u6807\u4E0D\u53EF\u7528\uFF08\u672A\u6CE8\u518C\u6216\u7F3A\u5C11 API Key\uFF09", { fallbackModelId });
|
|
11499
|
-
return null;
|
|
11500
|
-
}
|
|
11501
|
-
const compatibility = evaluateModelInputCompatibility(fallbackConfig, requirement);
|
|
11502
|
-
if (!compatibility.compatible) {
|
|
11503
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11504
|
-
fromModelId: activeModelId,
|
|
11505
|
-
candidateModelId: fallbackModelId,
|
|
11506
|
-
policy: "cloud-quota",
|
|
11507
|
-
reason: compatibility.reason,
|
|
11508
|
-
requiredPlacements: requirement.placements
|
|
11509
|
-
});
|
|
11510
|
-
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", {
|
|
11511
|
-
fallbackModelId,
|
|
11512
|
-
requiredPlacements: requirement.placements,
|
|
11513
|
-
reason: compatibility.reason
|
|
11514
|
-
});
|
|
11515
|
-
return null;
|
|
11516
|
-
}
|
|
11517
|
-
const capacityAdmission = evaluateFallbackPromptCapacity2?.(fallbackModelId);
|
|
11518
|
-
if (capacityAdmission && !capacityAdmission.admitted) {
|
|
11519
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11520
|
-
fromModelId: activeModelId,
|
|
11521
|
-
candidateModelId: fallbackModelId,
|
|
11522
|
-
policy: "cloud-quota",
|
|
11523
|
-
reason: capacityAdmission.reason,
|
|
11524
|
-
requiredPlacements: requirement.placements
|
|
11525
|
-
});
|
|
11526
|
-
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", {
|
|
11527
|
-
fallbackModelId,
|
|
11528
|
-
reason: capacityAdmission.reason
|
|
11529
|
-
});
|
|
11530
|
-
return null;
|
|
11531
|
-
}
|
|
11532
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\uFF08run \u5185\u7EED\u8DD1\uFF09", {
|
|
11533
|
-
activeModelId,
|
|
11534
|
-
fallbackModelId,
|
|
11535
|
-
reason: error.message
|
|
11536
|
-
});
|
|
11537
|
-
fallbackObserver?.onCloudQuotaFallbackApplied?.(fallbackModelId);
|
|
11538
|
-
return fallbackModelId;
|
|
11539
|
-
}
|
|
11540
11386
|
|
|
11541
11387
|
// src/runtime-kernel/llm/usage-telemetry.ts
|
|
11542
11388
|
async function callPlainCompletion(inferencePort, modelId, messages, options = {}, signal, traceId) {
|
|
@@ -11659,7 +11505,7 @@ var LlmImageInputError = class extends Error {
|
|
|
11659
11505
|
};
|
|
11660
11506
|
|
|
11661
11507
|
// src/runtime-kernel/llm/retry-fallback.ts
|
|
11662
|
-
var
|
|
11508
|
+
var logger15 = new Logger("LlmCaller");
|
|
11663
11509
|
async function callWithRetryFallback(params) {
|
|
11664
11510
|
const {
|
|
11665
11511
|
deps,
|
|
@@ -11687,11 +11533,9 @@ async function callWithRetryFallback(params) {
|
|
|
11687
11533
|
const retryEpisode = new LlmRetryEpisode(traceId, eventHandler);
|
|
11688
11534
|
let previousAttemptTracker;
|
|
11689
11535
|
if (!clientRetryEnabled) {
|
|
11690
|
-
|
|
11691
|
-
logger16.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
11536
|
+
logger15.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
11692
11537
|
modelId,
|
|
11693
|
-
|
|
11694
|
-
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"
|
|
11695
11539
|
});
|
|
11696
11540
|
}
|
|
11697
11541
|
try {
|
|
@@ -11727,7 +11571,7 @@ async function callWithRetryFallback(params) {
|
|
|
11727
11571
|
}) : void 0;
|
|
11728
11572
|
try {
|
|
11729
11573
|
if (isRetry) {
|
|
11730
|
-
|
|
11574
|
+
logger15.info("LLM \u8C03\u7528\u91CD\u8BD5", { attempt, configuredMaxRetries });
|
|
11731
11575
|
}
|
|
11732
11576
|
actualAttempts++;
|
|
11733
11577
|
retryEpisode.retrying(actualAttempts);
|
|
@@ -11756,7 +11600,7 @@ async function callWithRetryFallback(params) {
|
|
|
11756
11600
|
if (deps.retryConfig.enableEmptyResponseRetry && !responseContent?.trim() && !toolCallsFromLLM?.length) {
|
|
11757
11601
|
throw new Error("LLM\u8FD4\u56DE\u4E86\u7A7A\u54CD\u5E94");
|
|
11758
11602
|
}
|
|
11759
|
-
|
|
11603
|
+
logger15.debug("LLM \u8C03\u7528\u6210\u529F", { attempts: actualAttempts, maxTotalAttempts });
|
|
11760
11604
|
if (attemptContextUsage) {
|
|
11761
11605
|
fallbackObserver?.onLlmAttemptSucceeded?.(activeModelId, attemptContextUsage);
|
|
11762
11606
|
} else {
|
|
@@ -11767,7 +11611,7 @@ async function callWithRetryFallback(params) {
|
|
|
11767
11611
|
} catch (error) {
|
|
11768
11612
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
11769
11613
|
if (lastError.name === "AbortError") {
|
|
11770
|
-
|
|
11614
|
+
logger15.info("LLM \u8C03\u7528\u5DF2\u53D6\u6D88\uFF0C\u4E0D\u8FDB\u5165 provider failure \u5206\u7C7B\u4E0E\u91CD\u8BD5\u6D41\u7A0B", {
|
|
11771
11615
|
attempt: attempt + 1,
|
|
11772
11616
|
actualAttempts,
|
|
11773
11617
|
maxTotalAttempts,
|
|
@@ -11786,7 +11630,7 @@ async function callWithRetryFallback(params) {
|
|
|
11786
11630
|
total_attempts: actualAttempts,
|
|
11787
11631
|
error_code: classification.errorCode
|
|
11788
11632
|
};
|
|
11789
|
-
|
|
11633
|
+
logger15.error("LLM \u8C03\u7528\u5931\u8D25", {
|
|
11790
11634
|
attempt: attempt + 1,
|
|
11791
11635
|
maxAttempts: currentMaxRetries + 1,
|
|
11792
11636
|
actualAttempts,
|
|
@@ -11795,7 +11639,7 @@ async function callWithRetryFallback(params) {
|
|
|
11795
11639
|
});
|
|
11796
11640
|
previousAttemptTracker = attemptTracker;
|
|
11797
11641
|
if (!hasLlmAttemptBudgetRemaining({ actualAttempts, maxTotalAttempts })) {
|
|
11798
|
-
|
|
11642
|
+
logger15.error("\u5DF2\u8FBE\u5230 LLM \u603B\u8C03\u7528\u6B21\u6570\u4E0A\u9650\uFF0C\u505C\u6B62\u91CD\u8BD5/\u5207\u6A21\u578B", {
|
|
11799
11643
|
actualAttempts,
|
|
11800
11644
|
maxTotalAttempts
|
|
11801
11645
|
});
|
|
@@ -11825,37 +11669,15 @@ async function callWithRetryFallback(params) {
|
|
|
11825
11669
|
attempt -= 1;
|
|
11826
11670
|
continue;
|
|
11827
11671
|
}
|
|
11828
|
-
const quotaFallbackModelId = tryCloudQuotaFallback({
|
|
11829
|
-
deps,
|
|
11830
|
-
activeModelId,
|
|
11831
|
-
options,
|
|
11832
|
-
excludedModelIds,
|
|
11833
|
-
requirement,
|
|
11834
|
-
error: lastError,
|
|
11835
|
-
fallbackObserver,
|
|
11836
|
-
evaluateFallbackPromptCapacity: invocationContext?.evaluateFallbackPromptCapacity
|
|
11837
|
-
});
|
|
11838
|
-
if (quotaFallbackModelId) {
|
|
11839
|
-
fallbackObserver?.onModelFallbackApplied?.({
|
|
11840
|
-
fromModelId: activeModelId,
|
|
11841
|
-
toModelId: quotaFallbackModelId,
|
|
11842
|
-
reason: lastError.message,
|
|
11843
|
-
policy: "cloud-quota"
|
|
11844
|
-
});
|
|
11845
|
-
activeModelId = quotaFallbackModelId;
|
|
11846
|
-
excludedModelIds.add(quotaFallbackModelId);
|
|
11847
|
-
attempt -= 1;
|
|
11848
|
-
continue;
|
|
11849
|
-
}
|
|
11850
11672
|
}
|
|
11851
11673
|
if (classification.category === "non_retryable" /* NON_RETRYABLE */) {
|
|
11852
|
-
|
|
11674
|
+
logger15.error("\u9519\u8BEF\u4E0D\u53EF\u91CD\u8BD5\uFF0C\u76F4\u63A5\u5931\u8D25", { reason: classification.reason });
|
|
11853
11675
|
retryEpisode.finish("failed", failedRetryState);
|
|
11854
11676
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
11855
11677
|
throw lastError;
|
|
11856
11678
|
}
|
|
11857
11679
|
if (attempt >= configuredMaxRetries || categoryRetries[category] >= currentMaxRetries) {
|
|
11858
|
-
|
|
11680
|
+
logger15.error("\u5DF2\u8FBE\u5230\u6700\u5927\u91CD\u8BD5\u6B21\u6570\uFF0C\u653E\u5F03\u91CD\u8BD5", { maxRetries: currentMaxRetries });
|
|
11859
11681
|
retryEpisode.finish("exhausted", failedRetryState);
|
|
11860
11682
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
11861
11683
|
throw lastError;
|
|
@@ -11867,9 +11689,9 @@ async function callWithRetryFallback(params) {
|
|
|
11867
11689
|
6e4
|
|
11868
11690
|
);
|
|
11869
11691
|
if (classification.category === "rate_limit" /* RATE_LIMIT */) {
|
|
11870
|
-
|
|
11692
|
+
logger15.warn("\u901F\u7387\u9650\u5236\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
11871
11693
|
} else if (classification.category === "retryable" /* RETRYABLE */) {
|
|
11872
|
-
|
|
11694
|
+
logger15.warn("\u53EF\u91CD\u8BD5\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
11873
11695
|
}
|
|
11874
11696
|
throwIfAborted(signal, "\u5EF6\u8FDF\u7B49\u5F85\u524D\u68C0\u6D4B\u5230\u53D6\u6D88\u4FE1\u53F7\uFF0C\u505C\u6B62\u91CD\u8BD5");
|
|
11875
11697
|
categoryRetries[category] += 1;
|
|
@@ -11906,16 +11728,11 @@ function waitForRetry(delayMs, signal) {
|
|
|
11906
11728
|
}
|
|
11907
11729
|
function isClientRetryEnabledForModel(modelCatalog, modelId, options) {
|
|
11908
11730
|
if (options.retry_policy === "none") return false;
|
|
11909
|
-
|
|
11910
|
-
if (cfg?.billing_mode === "cloud") return false;
|
|
11911
|
-
if (options.retry_policy === "client") return true;
|
|
11912
|
-
if (!cfg) return true;
|
|
11913
|
-
if (cfg.enable_client_retry === false) return false;
|
|
11914
|
-
return true;
|
|
11731
|
+
return modelCatalog.getModelById(modelId)?.enable_client_retry !== false;
|
|
11915
11732
|
}
|
|
11916
11733
|
function throwIfAborted(signal, message) {
|
|
11917
11734
|
if (!signal?.aborted) return;
|
|
11918
|
-
|
|
11735
|
+
logger15.info(message);
|
|
11919
11736
|
const reason = signal.reason;
|
|
11920
11737
|
if (reason instanceof Error && reason.name === "AbortError") throw reason;
|
|
11921
11738
|
const reasonText = typeof reason === "string" && reason.trim().length > 0 ? reason : "stream_interrupted";
|
|
@@ -12233,7 +12050,7 @@ async function recoverChildRunEventsFromCheckpoint(params) {
|
|
|
12233
12050
|
}
|
|
12234
12051
|
|
|
12235
12052
|
// src/runtime-kernel/child-runs/childRunInvoker.ts
|
|
12236
|
-
var
|
|
12053
|
+
var logger16 = new Logger("ChildRunInvoker");
|
|
12237
12054
|
var ChildRunInvoker = class {
|
|
12238
12055
|
modelResolver;
|
|
12239
12056
|
createLlmNode;
|
|
@@ -12275,7 +12092,7 @@ var ChildRunInvoker = class {
|
|
|
12275
12092
|
const resolvedParentRunId = parentRunId ?? parentToolContext.runId;
|
|
12276
12093
|
const depthDecision = decideChildRunDepth({ parentToolContext });
|
|
12277
12094
|
if (!depthDecision.allowed) {
|
|
12278
|
-
|
|
12095
|
+
logger16.warn("child-run \u6DF1\u5EA6\u8D85\u8FC7\u4E0A\u9650\uFF0C\u62D2\u7EDD\u7EE7\u7EED\u9012\u5F52\u6267\u884C", {
|
|
12279
12096
|
runId: childRunId,
|
|
12280
12097
|
parentRunId: resolvedParentRunId,
|
|
12281
12098
|
parentDepth: depthDecision.parentDepth,
|
|
@@ -12292,7 +12109,7 @@ var ChildRunInvoker = class {
|
|
|
12292
12109
|
};
|
|
12293
12110
|
}
|
|
12294
12111
|
if (abortSignal?.aborted || parentToolContext.abortSignal?.aborted) {
|
|
12295
|
-
|
|
12112
|
+
logger16.info("child-run \u5728\u4EFB\u52A1\u63A5\u7EB3\u524D\u5DF2\u53D6\u6D88", {
|
|
12296
12113
|
runId: childRunId,
|
|
12297
12114
|
parentRunId: resolvedParentRunId
|
|
12298
12115
|
});
|
|
@@ -12316,7 +12133,7 @@ var ChildRunInvoker = class {
|
|
|
12316
12133
|
}
|
|
12317
12134
|
const turnId = config.initialInput?.turnId ?? generateTurnId();
|
|
12318
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");
|
|
12319
|
-
|
|
12136
|
+
logger16.info(`\u542F\u52A8 child-run: ${agentConfig.id}`, {
|
|
12320
12137
|
conversationId: runtimeConversationId,
|
|
12321
12138
|
checkpointKey: internalCheckpointKey,
|
|
12322
12139
|
maxSteps,
|
|
@@ -12434,7 +12251,7 @@ var ChildRunInvoker = class {
|
|
|
12434
12251
|
);
|
|
12435
12252
|
finalAnswer = extractFinalAnswer(allEvents);
|
|
12436
12253
|
lastProgress = finalAnswer ? void 0 : extractLastProgress(allEvents);
|
|
12437
|
-
|
|
12254
|
+
logger16.info("child-run \u6267\u884C\u5B8C\u6210", {
|
|
12438
12255
|
stepCount,
|
|
12439
12256
|
eventCount: allEvents.length,
|
|
12440
12257
|
hasFinalAnswer: !!finalAnswer,
|
|
@@ -12464,13 +12281,13 @@ var ChildRunInvoker = class {
|
|
|
12464
12281
|
cancelled = abortSignal?.aborted === true || isAbortError2(err);
|
|
12465
12282
|
error = err instanceof Error ? err.message : String(err);
|
|
12466
12283
|
if (cancelled) {
|
|
12467
|
-
|
|
12284
|
+
logger16.info("child-run \u6267\u884C\u53D6\u6D88", {
|
|
12468
12285
|
runId: childRunId,
|
|
12469
12286
|
parentRunId: resolvedParentRunId,
|
|
12470
12287
|
message: error
|
|
12471
12288
|
});
|
|
12472
12289
|
} else {
|
|
12473
|
-
|
|
12290
|
+
logger16.error(
|
|
12474
12291
|
"child-run \u6267\u884C\u5931\u8D25:",
|
|
12475
12292
|
err instanceof Error ? {
|
|
12476
12293
|
name: err.name,
|
|
@@ -12566,7 +12383,7 @@ var ChildRunInvoker = class {
|
|
|
12566
12383
|
function isAbortError2(error) {
|
|
12567
12384
|
return error instanceof Error && error.name === "AbortError";
|
|
12568
12385
|
}
|
|
12569
|
-
function
|
|
12386
|
+
function readNonEmptyString5(value) {
|
|
12570
12387
|
if (typeof value !== "string") {
|
|
12571
12388
|
return void 0;
|
|
12572
12389
|
}
|
|
@@ -12574,7 +12391,7 @@ function readNonEmptyString6(value) {
|
|
|
12574
12391
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
12575
12392
|
}
|
|
12576
12393
|
function resolveChildRunConversationId(params) {
|
|
12577
|
-
const conversationId =
|
|
12394
|
+
const conversationId = readNonEmptyString5(params.explicitConversationId) ?? readNonEmptyString5(params.parentToolContext.conversationId);
|
|
12578
12395
|
if (!conversationId) {
|
|
12579
12396
|
throw new Error(
|
|
12580
12397
|
"ChildRunInvoker requires conversationId from admission or parent ToolContext."
|
|
@@ -12583,7 +12400,7 @@ function resolveChildRunConversationId(params) {
|
|
|
12583
12400
|
return conversationId;
|
|
12584
12401
|
}
|
|
12585
12402
|
function resolveChildRunModelId(params) {
|
|
12586
|
-
const explicitModelId =
|
|
12403
|
+
const explicitModelId = readNonEmptyString5(params.explicitModelId);
|
|
12587
12404
|
if (explicitModelId) {
|
|
12588
12405
|
return explicitModelId;
|
|
12589
12406
|
}
|
|
@@ -13528,7 +13345,7 @@ function runMetaFromRecord(record) {
|
|
|
13528
13345
|
}
|
|
13529
13346
|
|
|
13530
13347
|
// src/runtime-kernel/run-supervisor/functions/awaitingUserWatcher.ts
|
|
13531
|
-
var
|
|
13348
|
+
var logger17 = new Logger("RunSupervisorAwaitingUserWatcher");
|
|
13532
13349
|
function isRecord16(value) {
|
|
13533
13350
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13534
13351
|
}
|
|
@@ -13573,7 +13390,7 @@ function createAwaitingUserWatcher(options) {
|
|
|
13573
13390
|
resumeToken: event.resume_token
|
|
13574
13391
|
}
|
|
13575
13392
|
}).catch((error) => {
|
|
13576
|
-
|
|
13393
|
+
logger17.warn("failed to mark awaiting_user from requires_user_interaction", { error });
|
|
13577
13394
|
});
|
|
13578
13395
|
};
|
|
13579
13396
|
const dispose = () => {
|