@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.js
CHANGED
|
@@ -420,18 +420,6 @@ var ErrorClassifier = class {
|
|
|
420
420
|
});
|
|
421
421
|
}
|
|
422
422
|
}
|
|
423
|
-
const quotaPatterns = ["\u5DF2\u8FBE\u4E0A\u9650", "\u514D\u8D39\u671F\u5DF2\u7ED3\u675F"];
|
|
424
|
-
for (const pattern of quotaPatterns) {
|
|
425
|
-
if (errorMessage.includes(pattern)) {
|
|
426
|
-
logClassification(context, "\u68C0\u6D4B\u5230\u4E91\u7AEF\u989D\u5EA6\u9650\u5236\uFF0C\u4E0D\u91CD\u8BD5", { matchedPattern: pattern });
|
|
427
|
-
return createClassification("non_retryable" /* NON_RETRYABLE */, `\u4E91\u7AEF\u989D\u5EA6\u9650\u5236: ${pattern}`, null, {
|
|
428
|
-
errorCode: ENGINE_ERROR_CODES.LLM_PROVIDER_DOWN,
|
|
429
|
-
recoverable: false,
|
|
430
|
-
hint: "check_billing_or_provider_status",
|
|
431
|
-
metadata: { matchedPattern: pattern }
|
|
432
|
-
});
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
423
|
const authPatterns = [
|
|
436
424
|
{ pattern: "unauthorized", code: "401" },
|
|
437
425
|
{ pattern: "forbidden", code: "403" },
|
|
@@ -686,17 +674,6 @@ var ErrorClassifier = class {
|
|
|
686
674
|
}
|
|
687
675
|
return Math.max(baseDelay, classification.suggestedDelay ?? 0);
|
|
688
676
|
}
|
|
689
|
-
static isCloudQuotaError(error) {
|
|
690
|
-
const msg = (error.message || "").toLowerCase();
|
|
691
|
-
const patterns = [
|
|
692
|
-
"\u989D\u5EA6\u4E0A\u9650",
|
|
693
|
-
"\u5DF2\u8FBE\u4E0A\u9650",
|
|
694
|
-
"\u514D\u8D39\u671F\u5DF2\u7ED3\u675F",
|
|
695
|
-
"\u8BE5\u6A21\u578B\u6682\u4E0D\u53EF\u7528",
|
|
696
|
-
"cloud_quota_exhausted"
|
|
697
|
-
];
|
|
698
|
-
return patterns.some((pattern) => msg.includes(pattern));
|
|
699
|
-
}
|
|
700
677
|
};
|
|
701
678
|
var NonBlankIdentitySchema = z.string().max(200).refine(
|
|
702
679
|
(value) => value.trim().length > 0 && value === value.trim(),
|
|
@@ -3885,8 +3862,8 @@ var TokenCalculator = class {
|
|
|
3885
3862
|
return;
|
|
3886
3863
|
}
|
|
3887
3864
|
this.failedEncodingWarnings.add(requestedEncoding);
|
|
3888
|
-
const
|
|
3889
|
-
|
|
3865
|
+
const logger18 = new Logger("TokenCalculator");
|
|
3866
|
+
logger18.warn("tiktoken encoding unavailable, falling back to avgCharsPerToken estimator", {
|
|
3890
3867
|
requestedEncoding,
|
|
3891
3868
|
error
|
|
3892
3869
|
});
|
|
@@ -3978,49 +3955,6 @@ var llmTelemetryMiddleware = async (ctx, stage, next) => {
|
|
|
3978
3955
|
});
|
|
3979
3956
|
};
|
|
3980
3957
|
|
|
3981
|
-
// src/runtime-kernel/graph-engine/functions/runModelLock.ts
|
|
3982
|
-
function readNonEmptyString4(value) {
|
|
3983
|
-
if (typeof value !== "string") return void 0;
|
|
3984
|
-
const trimmed = value.trim();
|
|
3985
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
3986
|
-
}
|
|
3987
|
-
function decideRunModelLockPatch(params) {
|
|
3988
|
-
if (params.stageId !== "execute_llm") {
|
|
3989
|
-
return { shouldLog: false };
|
|
3990
|
-
}
|
|
3991
|
-
const normalized = readNonEmptyString4(params.appliedFallbackModelId);
|
|
3992
|
-
if (!normalized) {
|
|
3993
|
-
return { shouldLog: false };
|
|
3994
|
-
}
|
|
3995
|
-
if (readNonEmptyString4(params.currentRunLockedModelId) === normalized) {
|
|
3996
|
-
return { shouldLog: false };
|
|
3997
|
-
}
|
|
3998
|
-
return {
|
|
3999
|
-
executorLocalPatch: { runLockedModelId: normalized },
|
|
4000
|
-
shouldLog: true
|
|
4001
|
-
};
|
|
4002
|
-
}
|
|
4003
|
-
|
|
4004
|
-
// src/runtime-kernel/graph-engine/tick-pipeline/middlewares/runModelLockMiddleware.ts
|
|
4005
|
-
var logger4 = new Logger("GraphAgentExecutor");
|
|
4006
|
-
var runModelLockMiddleware = async (ctx, stage, next) => {
|
|
4007
|
-
await next();
|
|
4008
|
-
const decision = decideRunModelLockPatch({
|
|
4009
|
-
stageId: stage.id,
|
|
4010
|
-
appliedFallbackModelId: ctx.cloudQuotaFallbackAppliedModelId,
|
|
4011
|
-
currentRunLockedModelId: ctx.executorLocalPatch?.runLockedModelId ?? ctx.executorLocal?.runLockedModelId
|
|
4012
|
-
});
|
|
4013
|
-
if (!decision.executorLocalPatch) {
|
|
4014
|
-
return;
|
|
4015
|
-
}
|
|
4016
|
-
if (decision.shouldLog) {
|
|
4017
|
-
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}`);
|
|
4018
|
-
}
|
|
4019
|
-
return {
|
|
4020
|
-
executorLocalPatch: decision.executorLocalPatch
|
|
4021
|
-
};
|
|
4022
|
-
};
|
|
4023
|
-
|
|
4024
3958
|
// src/runtime-kernel/graph-engine/tick-pipeline/runTickPipeline.ts
|
|
4025
3959
|
var tickPipelineContextKeys = [
|
|
4026
3960
|
"input",
|
|
@@ -4056,7 +3990,6 @@ var tickPipelineContextKeys = [
|
|
|
4056
3990
|
"decision",
|
|
4057
3991
|
"systemReminderHitRuleIds",
|
|
4058
3992
|
"contextTrace",
|
|
4059
|
-
"cloudQuotaFallbackAppliedModelId",
|
|
4060
3993
|
"modelFallbackAudit",
|
|
4061
3994
|
"telemetry",
|
|
4062
3995
|
"audit",
|
|
@@ -4395,7 +4328,7 @@ ${normalized}
|
|
|
4395
4328
|
}
|
|
4396
4329
|
|
|
4397
4330
|
// src/runtime-kernel/system-reminder/apply.ts
|
|
4398
|
-
var
|
|
4331
|
+
var logger4 = new Logger("SystemReminder");
|
|
4399
4332
|
var readString2 = (v) => {
|
|
4400
4333
|
if (typeof v !== "string") return void 0;
|
|
4401
4334
|
const s = v;
|
|
@@ -4458,7 +4391,7 @@ function applySystemReminders(params) {
|
|
|
4458
4391
|
} catch {
|
|
4459
4392
|
}
|
|
4460
4393
|
}
|
|
4461
|
-
|
|
4394
|
+
logger4.info("SystemReminder \u5DF2\u6CE8\u5165\u5230 LLM \u8F93\u5165\u672B\u5C3E", {
|
|
4462
4395
|
ruleIds: injectedRuleIds.length > 0 ? injectedRuleIds : Array.from(seenRuleIds),
|
|
4463
4396
|
promptKey: ctx.request.promptKey,
|
|
4464
4397
|
executorLocal: {
|
|
@@ -5168,7 +5101,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5168
5101
|
"turnId"
|
|
5169
5102
|
],
|
|
5170
5103
|
writes: [
|
|
5171
|
-
"cloudQuotaFallbackAppliedModelId",
|
|
5172
5104
|
"modelFallbackAudit",
|
|
5173
5105
|
"llmCallStartedAt",
|
|
5174
5106
|
"llmResp",
|
|
@@ -5176,7 +5108,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5176
5108
|
"contextUsage"
|
|
5177
5109
|
],
|
|
5178
5110
|
async run(ctx) {
|
|
5179
|
-
let cloudQuotaFallbackAppliedModelId;
|
|
5180
5111
|
let modelFallbackAudit;
|
|
5181
5112
|
let contextUsage;
|
|
5182
5113
|
const modelFallbackRejections = [];
|
|
@@ -5195,9 +5126,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5195
5126
|
streamEventHandler,
|
|
5196
5127
|
ctx.signal,
|
|
5197
5128
|
{
|
|
5198
|
-
onCloudQuotaFallbackApplied(fallbackModelId) {
|
|
5199
|
-
cloudQuotaFallbackAppliedModelId = readNonEmptyString3(fallbackModelId);
|
|
5200
|
-
},
|
|
5201
5129
|
onLlmAttemptSucceeded(_activeModelId, attemptContextUsage) {
|
|
5202
5130
|
contextUsage = attemptContextUsage;
|
|
5203
5131
|
},
|
|
@@ -5294,7 +5222,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5294
5222
|
});
|
|
5295
5223
|
}
|
|
5296
5224
|
return {
|
|
5297
|
-
cloudQuotaFallbackAppliedModelId,
|
|
5298
5225
|
modelFallbackAudit,
|
|
5299
5226
|
llmCallStartedAt,
|
|
5300
5227
|
llmResp,
|
|
@@ -6215,18 +6142,16 @@ function createPrepareCallStage(dependencies) {
|
|
|
6215
6142
|
"toolDefinitionTokens"
|
|
6216
6143
|
],
|
|
6217
6144
|
async run(ctx) {
|
|
6218
|
-
const
|
|
6219
|
-
const requestedModelId = lockedRunModelId ?? ctx.request.model_id;
|
|
6145
|
+
const requestedModelId = ctx.request.model_id;
|
|
6220
6146
|
const modelId = dependencies.modelResolver.resolveModelId(requestedModelId);
|
|
6221
6147
|
await emitAuditEnvelope(ctx.audit, {
|
|
6222
6148
|
action: "model.select",
|
|
6223
6149
|
actor: { kind: "system" },
|
|
6224
6150
|
decision: {
|
|
6225
6151
|
outcome: "recorded",
|
|
6226
|
-
reason:
|
|
6152
|
+
reason: requestedModelId ? "request model id" : "default model resolver",
|
|
6227
6153
|
metadata: {
|
|
6228
6154
|
requestedModelId,
|
|
6229
|
-
lockedRunModelId,
|
|
6230
6155
|
selectedModelId: modelId
|
|
6231
6156
|
}
|
|
6232
6157
|
},
|
|
@@ -6273,10 +6198,6 @@ function createPrepareCallStage(dependencies) {
|
|
|
6273
6198
|
if (ctx.executorLocal?.lockRequestedModelId === true) {
|
|
6274
6199
|
llmOptions.allow_model_fallback = false;
|
|
6275
6200
|
}
|
|
6276
|
-
const isRunContinuation = ctx.executorLocal?.llmInvocationKind === "continuation";
|
|
6277
|
-
if (dependencies.cloudQuotaFallbackModelId && modelConfig?.billing_mode === "cloud" && modelId !== dependencies.cloudQuotaFallbackModelId && isRunContinuation && ctx.executorLocal?.lockRequestedModelId !== true) {
|
|
6278
|
-
llmOptions.cloud_quota_fallback_model_id = dependencies.cloudQuotaFallbackModelId;
|
|
6279
|
-
}
|
|
6280
6201
|
const effectiveEffort = resolveEffectiveEffort(
|
|
6281
6202
|
ctx.request.reasoning_effort,
|
|
6282
6203
|
modelConfig?.reasoning
|
|
@@ -6393,12 +6314,11 @@ function applyCalibration(rawLocalTotal, imageInputTokens, coefficient) {
|
|
|
6393
6314
|
}
|
|
6394
6315
|
|
|
6395
6316
|
// src/runtime-kernel/graph-engine/executor.ts
|
|
6396
|
-
var
|
|
6317
|
+
var logger5 = new Logger("GraphAgentExecutor");
|
|
6397
6318
|
var GraphAgentExecutor = class {
|
|
6398
6319
|
llmCaller;
|
|
6399
6320
|
toolRuntime;
|
|
6400
6321
|
contextBuilder;
|
|
6401
|
-
cloudQuotaFallbackModelId;
|
|
6402
6322
|
modelResolver;
|
|
6403
6323
|
modelCatalog;
|
|
6404
6324
|
telemetryPort;
|
|
@@ -6410,7 +6330,6 @@ var GraphAgentExecutor = class {
|
|
|
6410
6330
|
this.llmCaller = dependencies.llmCaller;
|
|
6411
6331
|
this.toolRuntime = dependencies.toolRuntime;
|
|
6412
6332
|
this.contextBuilder = dependencies.contextBuilder;
|
|
6413
|
-
this.cloudQuotaFallbackModelId = readNonEmptyString3(dependencies.cloudQuotaFallbackModelId);
|
|
6414
6333
|
this.modelCatalog = dependencies.modelCatalog ?? createEmptyModelCatalog();
|
|
6415
6334
|
this.modelResolver = dependencies.modelResolver ?? new ModelResolver({
|
|
6416
6335
|
modelCatalog: this.modelCatalog
|
|
@@ -6427,8 +6346,7 @@ var GraphAgentExecutor = class {
|
|
|
6427
6346
|
createPrepareCallStage({
|
|
6428
6347
|
modelResolver: this.modelResolver,
|
|
6429
6348
|
modelCatalog: this.modelCatalog,
|
|
6430
|
-
toolCatalog: this.toolRuntime
|
|
6431
|
-
cloudQuotaFallbackModelId: this.cloudQuotaFallbackModelId
|
|
6349
|
+
toolCatalog: this.toolRuntime
|
|
6432
6350
|
}),
|
|
6433
6351
|
createBuildContextStage({
|
|
6434
6352
|
contextBuilder: this.contextBuilder
|
|
@@ -6450,7 +6368,7 @@ var GraphAgentExecutor = class {
|
|
|
6450
6368
|
}),
|
|
6451
6369
|
createBuildDecisionStage()
|
|
6452
6370
|
];
|
|
6453
|
-
this.middlewares = [llmTelemetryMiddleware
|
|
6371
|
+
this.middlewares = [llmTelemetryMiddleware];
|
|
6454
6372
|
}
|
|
6455
6373
|
async tick(input, eventHandler) {
|
|
6456
6374
|
const ctx = {
|
|
@@ -6475,7 +6393,7 @@ var GraphAgentExecutor = class {
|
|
|
6475
6393
|
audit: this.auditPort,
|
|
6476
6394
|
tokenizer: this.tokenizer
|
|
6477
6395
|
};
|
|
6478
|
-
|
|
6396
|
+
logger5.info("[GraphAgentExecutor] tick \u8C03\u7528", {
|
|
6479
6397
|
stream: input.stream === true,
|
|
6480
6398
|
hasEventHandler: Boolean(eventHandler),
|
|
6481
6399
|
hasSummarizationCallbacks: Boolean(input.summarizationCallbacks)
|
|
@@ -7498,7 +7416,7 @@ var LlmNodeEventBridge = class {
|
|
|
7498
7416
|
};
|
|
7499
7417
|
|
|
7500
7418
|
// src/runtime-kernel/graph-engine/nodes/llmNode.ts
|
|
7501
|
-
var
|
|
7419
|
+
var logger6 = new Logger("LlmNode");
|
|
7502
7420
|
var LlmNode = class {
|
|
7503
7421
|
id = "llm";
|
|
7504
7422
|
reasoner;
|
|
@@ -7507,7 +7425,7 @@ var LlmNode = class {
|
|
|
7507
7425
|
}
|
|
7508
7426
|
async run(state) {
|
|
7509
7427
|
const local = state.local ?? {};
|
|
7510
|
-
|
|
7428
|
+
logger6.info("[LlmNode] \u5F00\u59CB\u6267\u884C LLM \u8282\u70B9", {
|
|
7511
7429
|
localKeys: Object.keys(local)
|
|
7512
7430
|
});
|
|
7513
7431
|
const graphLocal = readGraphAgentLocal(state.local);
|
|
@@ -7522,12 +7440,12 @@ var LlmNode = class {
|
|
|
7522
7440
|
signal,
|
|
7523
7441
|
history
|
|
7524
7442
|
} = graphLocal;
|
|
7525
|
-
|
|
7443
|
+
logger6.info("[LlmNode] \u5DF2\u52A0\u8F7D\u5386\u53F2\u4E8B\u4EF6", {
|
|
7526
7444
|
historyCount: history.length,
|
|
7527
7445
|
hasSummarizationCallbacks: Boolean(summarizationCallbacks)
|
|
7528
7446
|
});
|
|
7529
7447
|
if (!request) {
|
|
7530
|
-
|
|
7448
|
+
logger6.warn("Request object is missing, yielding.");
|
|
7531
7449
|
return { kind: "yield", events: [] };
|
|
7532
7450
|
}
|
|
7533
7451
|
const turnId = requireRuntimeIdentity(graphLocal.turnId, "turnId");
|
|
@@ -7620,12 +7538,12 @@ var LlmNode = class {
|
|
|
7620
7538
|
...nodeState.streamRuntimeEvents,
|
|
7621
7539
|
...contextUsageEvent ? [contextUsageEvent] : []
|
|
7622
7540
|
];
|
|
7623
|
-
|
|
7541
|
+
logger6.info("[LlmNode] \u5386\u53F2\u4E8B\u4EF6\u5DF2\u66F4\u65B0", {
|
|
7624
7542
|
previousCount: history.length,
|
|
7625
7543
|
nextCount: patch.history.length,
|
|
7626
7544
|
streamedEventCount: nodeState.streamRuntimeEvents.length
|
|
7627
7545
|
});
|
|
7628
|
-
|
|
7546
|
+
logger6.info("[LlmNode] \u6267\u884C\u5668\u51B3\u7B56\u5B8C\u6210", {
|
|
7629
7547
|
decisionKind: decision.kind,
|
|
7630
7548
|
emittedEventCount: combinedEvents.length
|
|
7631
7549
|
});
|
|
@@ -7647,7 +7565,7 @@ var LlmNode = class {
|
|
|
7647
7565
|
}
|
|
7648
7566
|
case "error": {
|
|
7649
7567
|
const { name, message, stack } = decision.error;
|
|
7650
|
-
|
|
7568
|
+
logger6.error("[LlmNode] Executor returned an error", { name, message, stack });
|
|
7651
7569
|
return { kind: "yield", events: combinedEvents };
|
|
7652
7570
|
}
|
|
7653
7571
|
default: {
|
|
@@ -7753,7 +7671,7 @@ async function resolveToolModelInput(input) {
|
|
|
7753
7671
|
}
|
|
7754
7672
|
|
|
7755
7673
|
// src/runtime-kernel/graph-engine/nodes/toolNode.finalAnswerProjector.ts
|
|
7756
|
-
function
|
|
7674
|
+
function readNonEmptyString4(value) {
|
|
7757
7675
|
if (typeof value !== "string") {
|
|
7758
7676
|
return void 0;
|
|
7759
7677
|
}
|
|
@@ -7761,7 +7679,7 @@ function readNonEmptyString5(value) {
|
|
|
7761
7679
|
return normalized.length > 0 ? normalized : void 0;
|
|
7762
7680
|
}
|
|
7763
7681
|
function resolveFinalAnswerFromToolControl(finalAnswer) {
|
|
7764
|
-
return
|
|
7682
|
+
return readNonEmptyString4(finalAnswer);
|
|
7765
7683
|
}
|
|
7766
7684
|
|
|
7767
7685
|
// src/runtime-kernel/graph-engine/nodes/toolNode.helpers.ts
|
|
@@ -8017,7 +7935,7 @@ function buildErrorLocalState(params) {
|
|
|
8017
7935
|
}
|
|
8018
7936
|
|
|
8019
7937
|
// src/runtime-kernel/tools/argNormalizer.ts
|
|
8020
|
-
var
|
|
7938
|
+
var logger7 = new Logger("ToolArgNormalizer");
|
|
8021
7939
|
function isRecord10(v) {
|
|
8022
7940
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
8023
7941
|
}
|
|
@@ -8037,7 +7955,7 @@ function joinPath(basePath, segment) {
|
|
|
8037
7955
|
function logJsonEncodedNormalization(expectedType, options) {
|
|
8038
7956
|
const toolPrefix = options.toolName ? `${options.toolName}.` : "";
|
|
8039
7957
|
const path = options.path ?? "<root>";
|
|
8040
|
-
|
|
7958
|
+
logger7.warn("normalized JSON-encoded tool argument", {
|
|
8041
7959
|
expectedType,
|
|
8042
7960
|
path: `${toolPrefix}${path}`
|
|
8043
7961
|
});
|
|
@@ -8207,7 +8125,6 @@ var TOOL_CONTEXT_RUNTIME_RESERVED_KEYS = [
|
|
|
8207
8125
|
"conversationView",
|
|
8208
8126
|
"userQuery",
|
|
8209
8127
|
"modelId",
|
|
8210
|
-
"activeModelId",
|
|
8211
8128
|
"conversationId",
|
|
8212
8129
|
"turnId",
|
|
8213
8130
|
"runId",
|
|
@@ -8394,7 +8311,7 @@ function stripRuntimeReservedToolContextPatch(patch) {
|
|
|
8394
8311
|
}
|
|
8395
8312
|
|
|
8396
8313
|
// src/runtime-kernel/graph-engine/nodes/toolNode.eventBridge.ts
|
|
8397
|
-
var
|
|
8314
|
+
var logger8 = new Logger("ToolNode");
|
|
8398
8315
|
var ToolNodeEventBridge = class {
|
|
8399
8316
|
constructor(deps) {
|
|
8400
8317
|
this.deps = deps;
|
|
@@ -8416,7 +8333,7 @@ var ToolNodeEventBridge = class {
|
|
|
8416
8333
|
status,
|
|
8417
8334
|
payload: { ...payload }
|
|
8418
8335
|
};
|
|
8419
|
-
|
|
8336
|
+
logger8.info("[ToolNode] \u53D1\u51FA tool_process \u4E8B\u4EF6", {
|
|
8420
8337
|
phase,
|
|
8421
8338
|
status,
|
|
8422
8339
|
toolName: this.deps.toolName,
|
|
@@ -8456,7 +8373,7 @@ var ToolNodeEventBridge = class {
|
|
|
8456
8373
|
const answerId = generateAnswerSegmentId();
|
|
8457
8374
|
const id = answerId;
|
|
8458
8375
|
const timestamp = Date.now();
|
|
8459
|
-
|
|
8376
|
+
logger8.info("[ToolNode] \u5DE5\u5177\u8F93\u51FA\u6620\u5C04\u4E3A final_answer", {
|
|
8460
8377
|
sourceToolName: params.sourceToolName,
|
|
8461
8378
|
toolCallId: this.deps.toolCallId,
|
|
8462
8379
|
conversationId: this.deps.conversationId,
|
|
@@ -8514,7 +8431,7 @@ var ToolNodeEventBridge = class {
|
|
|
8514
8431
|
};
|
|
8515
8432
|
|
|
8516
8433
|
// src/runtime-kernel/graph-engine/nodes/toolNode.executionSetup.ts
|
|
8517
|
-
var
|
|
8434
|
+
var logger9 = new Logger("ToolNode");
|
|
8518
8435
|
function parseToolArgs(call) {
|
|
8519
8436
|
const rawArguments = typeof call.function?.arguments === "string" ? call.function.arguments : "";
|
|
8520
8437
|
if (!rawArguments.trim()) {
|
|
@@ -8534,19 +8451,13 @@ function parseToolArgs(call) {
|
|
|
8534
8451
|
return { ok: true, value: parsed };
|
|
8535
8452
|
} catch (error) {
|
|
8536
8453
|
const reason = error instanceof Error ? error.message : "Unknown JSON parse error";
|
|
8537
|
-
|
|
8454
|
+
logger9.warn("failed to parse tool arguments", { error });
|
|
8538
8455
|
return {
|
|
8539
8456
|
ok: false,
|
|
8540
8457
|
error: `Tool arguments are not valid JSON: ${reason}`
|
|
8541
8458
|
};
|
|
8542
8459
|
}
|
|
8543
8460
|
}
|
|
8544
|
-
function readRunLockedModelId(local) {
|
|
8545
|
-
const executorLocal = local.executorLocal;
|
|
8546
|
-
if (!isRecord9(executorLocal)) return void 0;
|
|
8547
|
-
const lockedModelId = executorLocal.runLockedModelId;
|
|
8548
|
-
return typeof lockedModelId === "string" && lockedModelId.trim() ? lockedModelId : void 0;
|
|
8549
|
-
}
|
|
8550
8461
|
function prepareToolNodeContext(state) {
|
|
8551
8462
|
const local = state.local || {};
|
|
8552
8463
|
const toolContext = isRecord9(local.toolContext) ? local.toolContext : {};
|
|
@@ -8564,7 +8475,6 @@ function prepareToolNodeContext(state) {
|
|
|
8564
8475
|
}
|
|
8565
8476
|
});
|
|
8566
8477
|
attachWorkingHistoryView({ state, toolContext });
|
|
8567
|
-
toolContext.activeModelId = readRunLockedModelId(local) ?? toolContext.modelId;
|
|
8568
8478
|
return {
|
|
8569
8479
|
state,
|
|
8570
8480
|
local,
|
|
@@ -8935,7 +8845,7 @@ async function claimPendingUserInputs(state, result) {
|
|
|
8935
8845
|
}
|
|
8936
8846
|
|
|
8937
8847
|
// src/runtime-kernel/graph-engine/nodes/toolNode.ts
|
|
8938
|
-
var
|
|
8848
|
+
var logger10 = new Logger("ToolNode");
|
|
8939
8849
|
function isAbortSignal(value) {
|
|
8940
8850
|
return value !== null && typeof value === "object" && "aborted" in value;
|
|
8941
8851
|
}
|
|
@@ -9148,7 +9058,7 @@ var ToolNode = class {
|
|
|
9148
9058
|
throw abortError;
|
|
9149
9059
|
}
|
|
9150
9060
|
const prepared = prepareToolNodeContext(state);
|
|
9151
|
-
|
|
9061
|
+
logger10.info("[ToolNode] \u5F00\u59CB\u6267\u884C\u5DE5\u5177\u8282\u70B9", {
|
|
9152
9062
|
conversationId: prepared.conversationId,
|
|
9153
9063
|
turnId: prepared.turnId,
|
|
9154
9064
|
pendingCallCount: calls.length
|
|
@@ -9163,7 +9073,7 @@ var ToolNode = class {
|
|
|
9163
9073
|
toolCatalog: this.toolRuntime
|
|
9164
9074
|
});
|
|
9165
9075
|
if (!execution) {
|
|
9166
|
-
|
|
9076
|
+
logger10.warn("no tool name found in call");
|
|
9167
9077
|
return { kind: "yield", events: [] };
|
|
9168
9078
|
}
|
|
9169
9079
|
if (typeof execution.protocolError === "string") {
|
|
@@ -9203,7 +9113,7 @@ var ToolNode = class {
|
|
|
9203
9113
|
call,
|
|
9204
9114
|
context: prepared.toolContext,
|
|
9205
9115
|
abortGraceMs: this.abortGraceMs,
|
|
9206
|
-
onAbandon: () =>
|
|
9116
|
+
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", {
|
|
9207
9117
|
toolName: execution.toolName,
|
|
9208
9118
|
toolCallId: execution.toolCallId,
|
|
9209
9119
|
conversationId: prepared.conversationId,
|
|
@@ -9373,7 +9283,7 @@ var ToolNode = class {
|
|
|
9373
9283
|
runtimeEvents: context.bridge.getRuntimeEvents()
|
|
9374
9284
|
});
|
|
9375
9285
|
if (control?.terminateRun) {
|
|
9376
|
-
|
|
9286
|
+
logger10.info("[ToolNode] \u6536\u5230 control.terminateRun\uFF0C\u6267\u884C\u5B8C\u5DE5\u5177\u540E\u76F4\u63A5 yield \u7ED3\u675F\u672C\u8F6E run", {
|
|
9377
9287
|
toolName: context.toolName,
|
|
9378
9288
|
toolCallId: context.toolCallId,
|
|
9379
9289
|
conversationId: context.conversationId,
|
|
@@ -9382,7 +9292,7 @@ var ToolNode = class {
|
|
|
9382
9292
|
return { kind: "yield", events: context.bridge.getRuntimeEvents() };
|
|
9383
9293
|
}
|
|
9384
9294
|
if (remainingCalls.length === 0 && context.local.toolBatchCompletionMode === "yield_after_batch") {
|
|
9385
|
-
|
|
9295
|
+
logger10.info("[ToolNode] \u5DE5\u5177\u6279\u6B21\u5DF2\u7ED3\u7B97\uFF0C\u6309 Host \u7B56\u7565\u76F4\u63A5 yield", {
|
|
9386
9296
|
toolName: context.toolName,
|
|
9387
9297
|
toolCallId: context.toolCallId,
|
|
9388
9298
|
conversationId: context.conversationId,
|
|
@@ -9829,8 +9739,9 @@ var executor = z.object({
|
|
|
9829
9739
|
lastStepsHintThreshold: counter.optional(),
|
|
9830
9740
|
systemReminderPolicy: AgentSpecSystemReminderPolicy.optional(),
|
|
9831
9741
|
toolObservationPolicy: AgentSpecToolObservationGovernancePolicy.optional(),
|
|
9742
|
+
// 已删除字段:0.45 及更早的 checkpoint 可能带 lastSuccessfulLlmModelId,0.46 及更早的可能带云端额度兜底留下的
|
|
9743
|
+
// runLockedModelId;照常接受,读入时丢弃(兜底已移除,恢复后按请求的模型继续)。
|
|
9832
9744
|
runLockedModelId: z.string().optional(),
|
|
9833
|
-
// 0.45 及更早的 checkpoint 可能带这个已删除字段;照常接受,读入时丢弃。
|
|
9834
9745
|
lastSuccessfulLlmModelId: z.string().optional(),
|
|
9835
9746
|
llmInvocationKind: z.enum(["user_initiated", "continuation"]).optional(),
|
|
9836
9747
|
llmInvocationCount: counter.optional(),
|
|
@@ -9840,7 +9751,7 @@ var executor = z.object({
|
|
|
9840
9751
|
committedCount: counter,
|
|
9841
9752
|
lastCommittedFingerprint: z.string().optional()
|
|
9842
9753
|
}).strict().optional()
|
|
9843
|
-
}).strict().transform(({ lastSuccessfulLlmModelId: _retired, ...state }) => state);
|
|
9754
|
+
}).strict().transform(({ lastSuccessfulLlmModelId: _retired, runLockedModelId: _retiredLock, ...state }) => state);
|
|
9844
9755
|
var checkpoint = z.object({
|
|
9845
9756
|
nodeId: z.string().min(1),
|
|
9846
9757
|
schemaVersion: z.literal(ENGINE_STATE_SCHEMA_VERSION).optional(),
|
|
@@ -10154,7 +10065,7 @@ __export(execution_exports, {
|
|
|
10154
10065
|
});
|
|
10155
10066
|
|
|
10156
10067
|
// src/runtime-kernel/execution/event-bus.ts
|
|
10157
|
-
var
|
|
10068
|
+
var logger11 = new Logger("EventBus");
|
|
10158
10069
|
var TypedEventEmitter = class {
|
|
10159
10070
|
listeners = /* @__PURE__ */ new Map();
|
|
10160
10071
|
maxListeners = 10;
|
|
@@ -10162,7 +10073,7 @@ var TypedEventEmitter = class {
|
|
|
10162
10073
|
const listeners = this.getListeners(event);
|
|
10163
10074
|
listeners.add(listener);
|
|
10164
10075
|
if (listeners.size > this.maxListeners) {
|
|
10165
|
-
|
|
10076
|
+
logger11.warn("EventBus listener count exceeds configured max", {
|
|
10166
10077
|
event: String(event),
|
|
10167
10078
|
count: listeners.size,
|
|
10168
10079
|
maxListeners: this.maxListeners
|
|
@@ -10222,7 +10133,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10222
10133
|
super();
|
|
10223
10134
|
this.executionId = executionId;
|
|
10224
10135
|
this.setMaxListeners(30);
|
|
10225
|
-
|
|
10136
|
+
logger11.info(`EventBus created for execution ${this.executionId}`);
|
|
10226
10137
|
}
|
|
10227
10138
|
/**
|
|
10228
10139
|
* 发布一个事件到总线
|
|
@@ -10231,7 +10142,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10231
10142
|
publish(envelope) {
|
|
10232
10143
|
if (envelope.trace.execution_id !== this.executionId) {
|
|
10233
10144
|
const error = new Error("EventEnvelope execution_id does not match EventBus instance.");
|
|
10234
|
-
|
|
10145
|
+
logger11.error("Mismatched execution_id", {
|
|
10235
10146
|
busExecutionId: this.executionId,
|
|
10236
10147
|
eventExecutionId: envelope.trace.execution_id,
|
|
10237
10148
|
eventSeq: envelope.seq
|
|
@@ -10243,7 +10154,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10243
10154
|
const error = new Error(
|
|
10244
10155
|
"EventBus only accepts RuntimeEvent with formal run routing identity."
|
|
10245
10156
|
);
|
|
10246
|
-
|
|
10157
|
+
logger11.error("RuntimeEvent is missing formal run routing identity", {
|
|
10247
10158
|
executionId: this.executionId,
|
|
10248
10159
|
eventId: envelope.payload.id,
|
|
10249
10160
|
eventType: envelope.payload.type
|
|
@@ -10257,14 +10168,14 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10257
10168
|
* 关闭总线,清理所有监听器
|
|
10258
10169
|
*/
|
|
10259
10170
|
close() {
|
|
10260
|
-
|
|
10171
|
+
logger11.info(`Closing EventBus for execution ${this.executionId}`);
|
|
10261
10172
|
this.emit("close");
|
|
10262
10173
|
this.removeAllListeners();
|
|
10263
10174
|
}
|
|
10264
10175
|
};
|
|
10265
10176
|
|
|
10266
10177
|
// src/runtime-kernel/execution/sequencer.ts
|
|
10267
|
-
var
|
|
10178
|
+
var logger12 = new Logger("EventSequencer");
|
|
10268
10179
|
var EventSequencer = class {
|
|
10269
10180
|
executionId;
|
|
10270
10181
|
traceId;
|
|
@@ -10272,7 +10183,7 @@ var EventSequencer = class {
|
|
|
10272
10183
|
constructor(conversationId, traceId) {
|
|
10273
10184
|
this.executionId = generateExecutionId();
|
|
10274
10185
|
this.traceId = traceId || generateTraceId();
|
|
10275
|
-
|
|
10186
|
+
logger12.info(`EventSequencer created for conversation ${conversationId}`, {
|
|
10276
10187
|
executionId: this.executionId,
|
|
10277
10188
|
traceId: this.traceId
|
|
10278
10189
|
});
|
|
@@ -11130,7 +11041,7 @@ var ThoughtStreamSegmenter = class {
|
|
|
11130
11041
|
};
|
|
11131
11042
|
|
|
11132
11043
|
// src/runtime-kernel/llm/streaming-adapter.ts
|
|
11133
|
-
var
|
|
11044
|
+
var logger13 = new Logger("LlmCaller");
|
|
11134
11045
|
var CanonicalInferenceFailureError = class extends Error {
|
|
11135
11046
|
errorCode;
|
|
11136
11047
|
recoverable;
|
|
@@ -11354,7 +11265,7 @@ async function callLlmStream(params) {
|
|
|
11354
11265
|
} catch (error) {
|
|
11355
11266
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
11356
11267
|
if (normalized.name === "AbortError") {
|
|
11357
|
-
|
|
11268
|
+
logger13.info("Canonical inference \u6536\u5230\u53D6\u6D88\u7EC8\u6001\uFF0C\u4E0D\u53D1\u5E03\u666E\u901A error event", { modelId });
|
|
11358
11269
|
throw normalized;
|
|
11359
11270
|
}
|
|
11360
11271
|
const classification = ErrorClassifier.classify(normalized, {
|
|
@@ -11430,7 +11341,7 @@ var LlmRetryEpisode = class {
|
|
|
11430
11341
|
};
|
|
11431
11342
|
|
|
11432
11343
|
// src/runtime-kernel/llm/retry-fallback-routing.ts
|
|
11433
|
-
var
|
|
11344
|
+
var logger14 = new Logger("LlmCaller");
|
|
11434
11345
|
function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement, fallbackObserver, error, evaluateFallbackPromptCapacity2) {
|
|
11435
11346
|
deps.modelCatalog.getModelById(activeModelId);
|
|
11436
11347
|
const policyDecision = deps.policyEngine.decideOnError(error, {
|
|
@@ -11460,81 +11371,16 @@ function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement
|
|
|
11460
11371
|
reason: "no_eligible_fallback_candidate",
|
|
11461
11372
|
requiredPlacements: requirement.placements
|
|
11462
11373
|
});
|
|
11463
|
-
|
|
11374
|
+
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");
|
|
11464
11375
|
return null;
|
|
11465
11376
|
}
|
|
11466
|
-
|
|
11377
|
+
logger14.warn("Policy \u5207\u6362\u6A21\u578B\u7EE7\u7EED", {
|
|
11467
11378
|
reason: policyDecision.reason,
|
|
11468
11379
|
activeModelId,
|
|
11469
11380
|
fallbackModelId
|
|
11470
11381
|
});
|
|
11471
11382
|
return fallbackModelId;
|
|
11472
11383
|
}
|
|
11473
|
-
function tryCloudQuotaFallback({
|
|
11474
|
-
deps,
|
|
11475
|
-
activeModelId,
|
|
11476
|
-
options,
|
|
11477
|
-
excludedModelIds,
|
|
11478
|
-
requirement,
|
|
11479
|
-
error,
|
|
11480
|
-
fallbackObserver,
|
|
11481
|
-
evaluateFallbackPromptCapacity: evaluateFallbackPromptCapacity2
|
|
11482
|
-
}) {
|
|
11483
|
-
const fallbackModelId = options.cloud_quota_fallback_model_id;
|
|
11484
|
-
if (!fallbackModelId || !ErrorClassifier.isCloudQuotaError(error) || excludedModelIds.has(fallbackModelId)) {
|
|
11485
|
-
return null;
|
|
11486
|
-
}
|
|
11487
|
-
const fallbackConfig = deps.modelCatalog.getModelById(fallbackModelId);
|
|
11488
|
-
if (!fallbackConfig?.api_key) {
|
|
11489
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11490
|
-
fromModelId: activeModelId,
|
|
11491
|
-
candidateModelId: fallbackModelId,
|
|
11492
|
-
policy: "cloud-quota",
|
|
11493
|
-
reason: "fallback_model_unavailable",
|
|
11494
|
-
requiredPlacements: requirement.placements
|
|
11495
|
-
});
|
|
11496
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\u76EE\u6807\u4E0D\u53EF\u7528\uFF08\u672A\u6CE8\u518C\u6216\u7F3A\u5C11 API Key\uFF09", { fallbackModelId });
|
|
11497
|
-
return null;
|
|
11498
|
-
}
|
|
11499
|
-
const compatibility = evaluateModelInputCompatibility(fallbackConfig, requirement);
|
|
11500
|
-
if (!compatibility.compatible) {
|
|
11501
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11502
|
-
fromModelId: activeModelId,
|
|
11503
|
-
candidateModelId: fallbackModelId,
|
|
11504
|
-
policy: "cloud-quota",
|
|
11505
|
-
reason: compatibility.reason,
|
|
11506
|
-
requiredPlacements: requirement.placements
|
|
11507
|
-
});
|
|
11508
|
-
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", {
|
|
11509
|
-
fallbackModelId,
|
|
11510
|
-
requiredPlacements: requirement.placements,
|
|
11511
|
-
reason: compatibility.reason
|
|
11512
|
-
});
|
|
11513
|
-
return null;
|
|
11514
|
-
}
|
|
11515
|
-
const capacityAdmission = evaluateFallbackPromptCapacity2?.(fallbackModelId);
|
|
11516
|
-
if (capacityAdmission && !capacityAdmission.admitted) {
|
|
11517
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11518
|
-
fromModelId: activeModelId,
|
|
11519
|
-
candidateModelId: fallbackModelId,
|
|
11520
|
-
policy: "cloud-quota",
|
|
11521
|
-
reason: capacityAdmission.reason,
|
|
11522
|
-
requiredPlacements: requirement.placements
|
|
11523
|
-
});
|
|
11524
|
-
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", {
|
|
11525
|
-
fallbackModelId,
|
|
11526
|
-
reason: capacityAdmission.reason
|
|
11527
|
-
});
|
|
11528
|
-
return null;
|
|
11529
|
-
}
|
|
11530
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\uFF08run \u5185\u7EED\u8DD1\uFF09", {
|
|
11531
|
-
activeModelId,
|
|
11532
|
-
fallbackModelId,
|
|
11533
|
-
reason: error.message
|
|
11534
|
-
});
|
|
11535
|
-
fallbackObserver?.onCloudQuotaFallbackApplied?.(fallbackModelId);
|
|
11536
|
-
return fallbackModelId;
|
|
11537
|
-
}
|
|
11538
11384
|
|
|
11539
11385
|
// src/runtime-kernel/llm/usage-telemetry.ts
|
|
11540
11386
|
async function callPlainCompletion(inferencePort, modelId, messages, options = {}, signal, traceId) {
|
|
@@ -11657,7 +11503,7 @@ var LlmImageInputError = class extends Error {
|
|
|
11657
11503
|
};
|
|
11658
11504
|
|
|
11659
11505
|
// src/runtime-kernel/llm/retry-fallback.ts
|
|
11660
|
-
var
|
|
11506
|
+
var logger15 = new Logger("LlmCaller");
|
|
11661
11507
|
async function callWithRetryFallback(params) {
|
|
11662
11508
|
const {
|
|
11663
11509
|
deps,
|
|
@@ -11685,11 +11531,9 @@ async function callWithRetryFallback(params) {
|
|
|
11685
11531
|
const retryEpisode = new LlmRetryEpisode(traceId, eventHandler);
|
|
11686
11532
|
let previousAttemptTracker;
|
|
11687
11533
|
if (!clientRetryEnabled) {
|
|
11688
|
-
|
|
11689
|
-
logger16.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
11534
|
+
logger15.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
11690
11535
|
modelId,
|
|
11691
|
-
|
|
11692
|
-
reason: options.retry_policy === "none" ? "options.retry_policy=none" : "model config (cloud billing or enable_client_retry=false)"
|
|
11536
|
+
reason: options.retry_policy === "none" ? "options.retry_policy=none" : "model config enable_client_retry=false"
|
|
11693
11537
|
});
|
|
11694
11538
|
}
|
|
11695
11539
|
try {
|
|
@@ -11725,7 +11569,7 @@ async function callWithRetryFallback(params) {
|
|
|
11725
11569
|
}) : void 0;
|
|
11726
11570
|
try {
|
|
11727
11571
|
if (isRetry) {
|
|
11728
|
-
|
|
11572
|
+
logger15.info("LLM \u8C03\u7528\u91CD\u8BD5", { attempt, configuredMaxRetries });
|
|
11729
11573
|
}
|
|
11730
11574
|
actualAttempts++;
|
|
11731
11575
|
retryEpisode.retrying(actualAttempts);
|
|
@@ -11754,7 +11598,7 @@ async function callWithRetryFallback(params) {
|
|
|
11754
11598
|
if (deps.retryConfig.enableEmptyResponseRetry && !responseContent?.trim() && !toolCallsFromLLM?.length) {
|
|
11755
11599
|
throw new Error("LLM\u8FD4\u56DE\u4E86\u7A7A\u54CD\u5E94");
|
|
11756
11600
|
}
|
|
11757
|
-
|
|
11601
|
+
logger15.debug("LLM \u8C03\u7528\u6210\u529F", { attempts: actualAttempts, maxTotalAttempts });
|
|
11758
11602
|
if (attemptContextUsage) {
|
|
11759
11603
|
fallbackObserver?.onLlmAttemptSucceeded?.(activeModelId, attemptContextUsage);
|
|
11760
11604
|
} else {
|
|
@@ -11765,7 +11609,7 @@ async function callWithRetryFallback(params) {
|
|
|
11765
11609
|
} catch (error) {
|
|
11766
11610
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
11767
11611
|
if (lastError.name === "AbortError") {
|
|
11768
|
-
|
|
11612
|
+
logger15.info("LLM \u8C03\u7528\u5DF2\u53D6\u6D88\uFF0C\u4E0D\u8FDB\u5165 provider failure \u5206\u7C7B\u4E0E\u91CD\u8BD5\u6D41\u7A0B", {
|
|
11769
11613
|
attempt: attempt + 1,
|
|
11770
11614
|
actualAttempts,
|
|
11771
11615
|
maxTotalAttempts,
|
|
@@ -11784,7 +11628,7 @@ async function callWithRetryFallback(params) {
|
|
|
11784
11628
|
total_attempts: actualAttempts,
|
|
11785
11629
|
error_code: classification.errorCode
|
|
11786
11630
|
};
|
|
11787
|
-
|
|
11631
|
+
logger15.error("LLM \u8C03\u7528\u5931\u8D25", {
|
|
11788
11632
|
attempt: attempt + 1,
|
|
11789
11633
|
maxAttempts: currentMaxRetries + 1,
|
|
11790
11634
|
actualAttempts,
|
|
@@ -11793,7 +11637,7 @@ async function callWithRetryFallback(params) {
|
|
|
11793
11637
|
});
|
|
11794
11638
|
previousAttemptTracker = attemptTracker;
|
|
11795
11639
|
if (!hasLlmAttemptBudgetRemaining({ actualAttempts, maxTotalAttempts })) {
|
|
11796
|
-
|
|
11640
|
+
logger15.error("\u5DF2\u8FBE\u5230 LLM \u603B\u8C03\u7528\u6B21\u6570\u4E0A\u9650\uFF0C\u505C\u6B62\u91CD\u8BD5/\u5207\u6A21\u578B", {
|
|
11797
11641
|
actualAttempts,
|
|
11798
11642
|
maxTotalAttempts
|
|
11799
11643
|
});
|
|
@@ -11823,37 +11667,15 @@ async function callWithRetryFallback(params) {
|
|
|
11823
11667
|
attempt -= 1;
|
|
11824
11668
|
continue;
|
|
11825
11669
|
}
|
|
11826
|
-
const quotaFallbackModelId = tryCloudQuotaFallback({
|
|
11827
|
-
deps,
|
|
11828
|
-
activeModelId,
|
|
11829
|
-
options,
|
|
11830
|
-
excludedModelIds,
|
|
11831
|
-
requirement,
|
|
11832
|
-
error: lastError,
|
|
11833
|
-
fallbackObserver,
|
|
11834
|
-
evaluateFallbackPromptCapacity: invocationContext?.evaluateFallbackPromptCapacity
|
|
11835
|
-
});
|
|
11836
|
-
if (quotaFallbackModelId) {
|
|
11837
|
-
fallbackObserver?.onModelFallbackApplied?.({
|
|
11838
|
-
fromModelId: activeModelId,
|
|
11839
|
-
toModelId: quotaFallbackModelId,
|
|
11840
|
-
reason: lastError.message,
|
|
11841
|
-
policy: "cloud-quota"
|
|
11842
|
-
});
|
|
11843
|
-
activeModelId = quotaFallbackModelId;
|
|
11844
|
-
excludedModelIds.add(quotaFallbackModelId);
|
|
11845
|
-
attempt -= 1;
|
|
11846
|
-
continue;
|
|
11847
|
-
}
|
|
11848
11670
|
}
|
|
11849
11671
|
if (classification.category === "non_retryable" /* NON_RETRYABLE */) {
|
|
11850
|
-
|
|
11672
|
+
logger15.error("\u9519\u8BEF\u4E0D\u53EF\u91CD\u8BD5\uFF0C\u76F4\u63A5\u5931\u8D25", { reason: classification.reason });
|
|
11851
11673
|
retryEpisode.finish("failed", failedRetryState);
|
|
11852
11674
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
11853
11675
|
throw lastError;
|
|
11854
11676
|
}
|
|
11855
11677
|
if (attempt >= configuredMaxRetries || categoryRetries[category] >= currentMaxRetries) {
|
|
11856
|
-
|
|
11678
|
+
logger15.error("\u5DF2\u8FBE\u5230\u6700\u5927\u91CD\u8BD5\u6B21\u6570\uFF0C\u653E\u5F03\u91CD\u8BD5", { maxRetries: currentMaxRetries });
|
|
11857
11679
|
retryEpisode.finish("exhausted", failedRetryState);
|
|
11858
11680
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
11859
11681
|
throw lastError;
|
|
@@ -11865,9 +11687,9 @@ async function callWithRetryFallback(params) {
|
|
|
11865
11687
|
6e4
|
|
11866
11688
|
);
|
|
11867
11689
|
if (classification.category === "rate_limit" /* RATE_LIMIT */) {
|
|
11868
|
-
|
|
11690
|
+
logger15.warn("\u901F\u7387\u9650\u5236\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
11869
11691
|
} else if (classification.category === "retryable" /* RETRYABLE */) {
|
|
11870
|
-
|
|
11692
|
+
logger15.warn("\u53EF\u91CD\u8BD5\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
11871
11693
|
}
|
|
11872
11694
|
throwIfAborted(signal, "\u5EF6\u8FDF\u7B49\u5F85\u524D\u68C0\u6D4B\u5230\u53D6\u6D88\u4FE1\u53F7\uFF0C\u505C\u6B62\u91CD\u8BD5");
|
|
11873
11695
|
categoryRetries[category] += 1;
|
|
@@ -11904,16 +11726,11 @@ function waitForRetry(delayMs, signal) {
|
|
|
11904
11726
|
}
|
|
11905
11727
|
function isClientRetryEnabledForModel(modelCatalog, modelId, options) {
|
|
11906
11728
|
if (options.retry_policy === "none") return false;
|
|
11907
|
-
|
|
11908
|
-
if (cfg?.billing_mode === "cloud") return false;
|
|
11909
|
-
if (options.retry_policy === "client") return true;
|
|
11910
|
-
if (!cfg) return true;
|
|
11911
|
-
if (cfg.enable_client_retry === false) return false;
|
|
11912
|
-
return true;
|
|
11729
|
+
return modelCatalog.getModelById(modelId)?.enable_client_retry !== false;
|
|
11913
11730
|
}
|
|
11914
11731
|
function throwIfAborted(signal, message) {
|
|
11915
11732
|
if (!signal?.aborted) return;
|
|
11916
|
-
|
|
11733
|
+
logger15.info(message);
|
|
11917
11734
|
const reason = signal.reason;
|
|
11918
11735
|
if (reason instanceof Error && reason.name === "AbortError") throw reason;
|
|
11919
11736
|
const reasonText = typeof reason === "string" && reason.trim().length > 0 ? reason : "stream_interrupted";
|
|
@@ -12231,7 +12048,7 @@ async function recoverChildRunEventsFromCheckpoint(params) {
|
|
|
12231
12048
|
}
|
|
12232
12049
|
|
|
12233
12050
|
// src/runtime-kernel/child-runs/childRunInvoker.ts
|
|
12234
|
-
var
|
|
12051
|
+
var logger16 = new Logger("ChildRunInvoker");
|
|
12235
12052
|
var ChildRunInvoker = class {
|
|
12236
12053
|
modelResolver;
|
|
12237
12054
|
createLlmNode;
|
|
@@ -12273,7 +12090,7 @@ var ChildRunInvoker = class {
|
|
|
12273
12090
|
const resolvedParentRunId = parentRunId ?? parentToolContext.runId;
|
|
12274
12091
|
const depthDecision = decideChildRunDepth({ parentToolContext });
|
|
12275
12092
|
if (!depthDecision.allowed) {
|
|
12276
|
-
|
|
12093
|
+
logger16.warn("child-run \u6DF1\u5EA6\u8D85\u8FC7\u4E0A\u9650\uFF0C\u62D2\u7EDD\u7EE7\u7EED\u9012\u5F52\u6267\u884C", {
|
|
12277
12094
|
runId: childRunId,
|
|
12278
12095
|
parentRunId: resolvedParentRunId,
|
|
12279
12096
|
parentDepth: depthDecision.parentDepth,
|
|
@@ -12290,7 +12107,7 @@ var ChildRunInvoker = class {
|
|
|
12290
12107
|
};
|
|
12291
12108
|
}
|
|
12292
12109
|
if (abortSignal?.aborted || parentToolContext.abortSignal?.aborted) {
|
|
12293
|
-
|
|
12110
|
+
logger16.info("child-run \u5728\u4EFB\u52A1\u63A5\u7EB3\u524D\u5DF2\u53D6\u6D88", {
|
|
12294
12111
|
runId: childRunId,
|
|
12295
12112
|
parentRunId: resolvedParentRunId
|
|
12296
12113
|
});
|
|
@@ -12314,7 +12131,7 @@ var ChildRunInvoker = class {
|
|
|
12314
12131
|
}
|
|
12315
12132
|
const turnId = config.initialInput?.turnId ?? generateTurnId();
|
|
12316
12133
|
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");
|
|
12317
|
-
|
|
12134
|
+
logger16.info(`\u542F\u52A8 child-run: ${agentConfig.id}`, {
|
|
12318
12135
|
conversationId: runtimeConversationId,
|
|
12319
12136
|
checkpointKey: internalCheckpointKey,
|
|
12320
12137
|
maxSteps,
|
|
@@ -12432,7 +12249,7 @@ var ChildRunInvoker = class {
|
|
|
12432
12249
|
);
|
|
12433
12250
|
finalAnswer = extractFinalAnswer(allEvents);
|
|
12434
12251
|
lastProgress = finalAnswer ? void 0 : extractLastProgress(allEvents);
|
|
12435
|
-
|
|
12252
|
+
logger16.info("child-run \u6267\u884C\u5B8C\u6210", {
|
|
12436
12253
|
stepCount,
|
|
12437
12254
|
eventCount: allEvents.length,
|
|
12438
12255
|
hasFinalAnswer: !!finalAnswer,
|
|
@@ -12462,13 +12279,13 @@ var ChildRunInvoker = class {
|
|
|
12462
12279
|
cancelled = abortSignal?.aborted === true || isAbortError2(err);
|
|
12463
12280
|
error = err instanceof Error ? err.message : String(err);
|
|
12464
12281
|
if (cancelled) {
|
|
12465
|
-
|
|
12282
|
+
logger16.info("child-run \u6267\u884C\u53D6\u6D88", {
|
|
12466
12283
|
runId: childRunId,
|
|
12467
12284
|
parentRunId: resolvedParentRunId,
|
|
12468
12285
|
message: error
|
|
12469
12286
|
});
|
|
12470
12287
|
} else {
|
|
12471
|
-
|
|
12288
|
+
logger16.error(
|
|
12472
12289
|
"child-run \u6267\u884C\u5931\u8D25:",
|
|
12473
12290
|
err instanceof Error ? {
|
|
12474
12291
|
name: err.name,
|
|
@@ -12564,7 +12381,7 @@ var ChildRunInvoker = class {
|
|
|
12564
12381
|
function isAbortError2(error) {
|
|
12565
12382
|
return error instanceof Error && error.name === "AbortError";
|
|
12566
12383
|
}
|
|
12567
|
-
function
|
|
12384
|
+
function readNonEmptyString5(value) {
|
|
12568
12385
|
if (typeof value !== "string") {
|
|
12569
12386
|
return void 0;
|
|
12570
12387
|
}
|
|
@@ -12572,7 +12389,7 @@ function readNonEmptyString6(value) {
|
|
|
12572
12389
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
12573
12390
|
}
|
|
12574
12391
|
function resolveChildRunConversationId(params) {
|
|
12575
|
-
const conversationId =
|
|
12392
|
+
const conversationId = readNonEmptyString5(params.explicitConversationId) ?? readNonEmptyString5(params.parentToolContext.conversationId);
|
|
12576
12393
|
if (!conversationId) {
|
|
12577
12394
|
throw new Error(
|
|
12578
12395
|
"ChildRunInvoker requires conversationId from admission or parent ToolContext."
|
|
@@ -12581,7 +12398,7 @@ function resolveChildRunConversationId(params) {
|
|
|
12581
12398
|
return conversationId;
|
|
12582
12399
|
}
|
|
12583
12400
|
function resolveChildRunModelId(params) {
|
|
12584
|
-
const explicitModelId =
|
|
12401
|
+
const explicitModelId = readNonEmptyString5(params.explicitModelId);
|
|
12585
12402
|
if (explicitModelId) {
|
|
12586
12403
|
return explicitModelId;
|
|
12587
12404
|
}
|
|
@@ -13526,7 +13343,7 @@ function runMetaFromRecord(record) {
|
|
|
13526
13343
|
}
|
|
13527
13344
|
|
|
13528
13345
|
// src/runtime-kernel/run-supervisor/functions/awaitingUserWatcher.ts
|
|
13529
|
-
var
|
|
13346
|
+
var logger17 = new Logger("RunSupervisorAwaitingUserWatcher");
|
|
13530
13347
|
function isRecord16(value) {
|
|
13531
13348
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13532
13349
|
}
|
|
@@ -13571,7 +13388,7 @@ function createAwaitingUserWatcher(options) {
|
|
|
13571
13388
|
resumeToken: event.resume_token
|
|
13572
13389
|
}
|
|
13573
13390
|
}).catch((error) => {
|
|
13574
|
-
|
|
13391
|
+
logger17.warn("failed to mark awaiting_user from requires_user_interaction", { error });
|
|
13575
13392
|
});
|
|
13576
13393
|
};
|
|
13577
13394
|
const dispose = () => {
|