@linnlabs/linnkit 0.45.0 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +60 -0
- package/dist/cli.cjs +65 -243
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +65 -243
- package/dist/cli.js.map +1 -1
- package/dist/context-manager.cjs +7 -6
- package/dist/context-manager.cjs.map +1 -1
- package/dist/context-manager.js +7 -6
- package/dist/context-manager.js.map +1 -1
- package/dist/index.cjs +75 -253
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +75 -253
- package/dist/index.js.map +1 -1
- package/dist/ports/llm-call.d.cts +2 -16
- package/dist/ports/llm-call.d.ts +2 -16
- package/dist/quickstart.cjs +65 -243
- package/dist/quickstart.cjs.map +1 -1
- package/dist/quickstart.js +65 -243
- package/dist/quickstart.js.map +1 -1
- package/dist/runtime-kernel/graph-engine/executor.d.cts +0 -2
- package/dist/runtime-kernel/graph-engine/executor.d.ts +0 -2
- package/dist/runtime-kernel/graph-engine/types.d.cts +1 -4
- package/dist/runtime-kernel/graph-engine/types.d.ts +1 -4
- package/dist/runtime-kernel/llm/definitions/llmFallbackObserver.d.cts +1 -2
- package/dist/runtime-kernel/llm/definitions/llmFallbackObserver.d.ts +1 -2
- package/dist/runtime-kernel/llm/modelCatalog.d.cts +2 -3
- package/dist/runtime-kernel/llm/modelCatalog.d.ts +2 -3
- package/dist/runtime-kernel.cjs +75 -253
- package/dist/runtime-kernel.cjs.map +1 -1
- package/dist/runtime-kernel.js +75 -253
- package/dist/runtime-kernel.js.map +1 -1
- package/dist/testkit.cjs +83 -261
- package/dist/testkit.cjs.map +1 -1
- package/dist/testkit.js +83 -261
- package/dist/testkit.js.map +1 -1
- package/docs/integration/agent-registration-guide.md +1 -1
- package/docs/integration/context-engineering.md +5 -5
- package/docs/integration/llm-provider.md +1 -1
- package/docs/integration/tool-development-guide.md +4 -2
- package/package.json +2 -1
package/dist/runtime-kernel.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,18 +5101,14 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5168
5101
|
"turnId"
|
|
5169
5102
|
],
|
|
5170
5103
|
writes: [
|
|
5171
|
-
"cloudQuotaFallbackAppliedModelId",
|
|
5172
5104
|
"modelFallbackAudit",
|
|
5173
5105
|
"llmCallStartedAt",
|
|
5174
5106
|
"llmResp",
|
|
5175
5107
|
"llmCallDurationMs",
|
|
5176
|
-
"executorLocalPatch",
|
|
5177
5108
|
"contextUsage"
|
|
5178
5109
|
],
|
|
5179
5110
|
async run(ctx) {
|
|
5180
|
-
let cloudQuotaFallbackAppliedModelId;
|
|
5181
5111
|
let modelFallbackAudit;
|
|
5182
|
-
let lastSuccessfulLlmModelId;
|
|
5183
5112
|
let contextUsage;
|
|
5184
5113
|
const modelFallbackRejections = [];
|
|
5185
5114
|
const promptBudget = ctx.promptBudget;
|
|
@@ -5197,11 +5126,7 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5197
5126
|
streamEventHandler,
|
|
5198
5127
|
ctx.signal,
|
|
5199
5128
|
{
|
|
5200
|
-
|
|
5201
|
-
cloudQuotaFallbackAppliedModelId = readNonEmptyString3(fallbackModelId);
|
|
5202
|
-
},
|
|
5203
|
-
onLlmAttemptSucceeded(activeModelId, attemptContextUsage) {
|
|
5204
|
-
lastSuccessfulLlmModelId = readNonEmptyString3(activeModelId);
|
|
5129
|
+
onLlmAttemptSucceeded(_activeModelId, attemptContextUsage) {
|
|
5205
5130
|
contextUsage = attemptContextUsage;
|
|
5206
5131
|
},
|
|
5207
5132
|
onModelFallbackApplied(info) {
|
|
@@ -5297,12 +5222,10 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5297
5222
|
});
|
|
5298
5223
|
}
|
|
5299
5224
|
return {
|
|
5300
|
-
cloudQuotaFallbackAppliedModelId,
|
|
5301
5225
|
modelFallbackAudit,
|
|
5302
5226
|
llmCallStartedAt,
|
|
5303
5227
|
llmResp,
|
|
5304
5228
|
llmCallDurationMs,
|
|
5305
|
-
executorLocalPatch: lastSuccessfulLlmModelId ? { lastSuccessfulLlmModelId } : void 0,
|
|
5306
5229
|
contextUsage
|
|
5307
5230
|
};
|
|
5308
5231
|
}
|
|
@@ -6219,18 +6142,16 @@ function createPrepareCallStage(dependencies) {
|
|
|
6219
6142
|
"toolDefinitionTokens"
|
|
6220
6143
|
],
|
|
6221
6144
|
async run(ctx) {
|
|
6222
|
-
const
|
|
6223
|
-
const requestedModelId = lockedRunModelId ?? ctx.request.model_id;
|
|
6145
|
+
const requestedModelId = ctx.request.model_id;
|
|
6224
6146
|
const modelId = dependencies.modelResolver.resolveModelId(requestedModelId);
|
|
6225
6147
|
await emitAuditEnvelope(ctx.audit, {
|
|
6226
6148
|
action: "model.select",
|
|
6227
6149
|
actor: { kind: "system" },
|
|
6228
6150
|
decision: {
|
|
6229
6151
|
outcome: "recorded",
|
|
6230
|
-
reason:
|
|
6152
|
+
reason: requestedModelId ? "request model id" : "default model resolver",
|
|
6231
6153
|
metadata: {
|
|
6232
6154
|
requestedModelId,
|
|
6233
|
-
lockedRunModelId,
|
|
6234
6155
|
selectedModelId: modelId
|
|
6235
6156
|
}
|
|
6236
6157
|
},
|
|
@@ -6277,10 +6198,6 @@ function createPrepareCallStage(dependencies) {
|
|
|
6277
6198
|
if (ctx.executorLocal?.lockRequestedModelId === true) {
|
|
6278
6199
|
llmOptions.allow_model_fallback = false;
|
|
6279
6200
|
}
|
|
6280
|
-
const isRunContinuation = ctx.executorLocal?.llmInvocationKind === "continuation";
|
|
6281
|
-
if (dependencies.cloudQuotaFallbackModelId && modelConfig?.billing_mode === "cloud" && modelId !== dependencies.cloudQuotaFallbackModelId && isRunContinuation && ctx.executorLocal?.lockRequestedModelId !== true) {
|
|
6282
|
-
llmOptions.cloud_quota_fallback_model_id = dependencies.cloudQuotaFallbackModelId;
|
|
6283
|
-
}
|
|
6284
6201
|
const effectiveEffort = resolveEffectiveEffort(
|
|
6285
6202
|
ctx.request.reasoning_effort,
|
|
6286
6203
|
modelConfig?.reasoning
|
|
@@ -6397,12 +6314,11 @@ function applyCalibration(rawLocalTotal, imageInputTokens, coefficient) {
|
|
|
6397
6314
|
}
|
|
6398
6315
|
|
|
6399
6316
|
// src/runtime-kernel/graph-engine/executor.ts
|
|
6400
|
-
var
|
|
6317
|
+
var logger5 = new Logger("GraphAgentExecutor");
|
|
6401
6318
|
var GraphAgentExecutor = class {
|
|
6402
6319
|
llmCaller;
|
|
6403
6320
|
toolRuntime;
|
|
6404
6321
|
contextBuilder;
|
|
6405
|
-
cloudQuotaFallbackModelId;
|
|
6406
6322
|
modelResolver;
|
|
6407
6323
|
modelCatalog;
|
|
6408
6324
|
telemetryPort;
|
|
@@ -6414,7 +6330,6 @@ var GraphAgentExecutor = class {
|
|
|
6414
6330
|
this.llmCaller = dependencies.llmCaller;
|
|
6415
6331
|
this.toolRuntime = dependencies.toolRuntime;
|
|
6416
6332
|
this.contextBuilder = dependencies.contextBuilder;
|
|
6417
|
-
this.cloudQuotaFallbackModelId = readNonEmptyString3(dependencies.cloudQuotaFallbackModelId);
|
|
6418
6333
|
this.modelCatalog = dependencies.modelCatalog ?? createEmptyModelCatalog();
|
|
6419
6334
|
this.modelResolver = dependencies.modelResolver ?? new ModelResolver({
|
|
6420
6335
|
modelCatalog: this.modelCatalog
|
|
@@ -6431,8 +6346,7 @@ var GraphAgentExecutor = class {
|
|
|
6431
6346
|
createPrepareCallStage({
|
|
6432
6347
|
modelResolver: this.modelResolver,
|
|
6433
6348
|
modelCatalog: this.modelCatalog,
|
|
6434
|
-
toolCatalog: this.toolRuntime
|
|
6435
|
-
cloudQuotaFallbackModelId: this.cloudQuotaFallbackModelId
|
|
6349
|
+
toolCatalog: this.toolRuntime
|
|
6436
6350
|
}),
|
|
6437
6351
|
createBuildContextStage({
|
|
6438
6352
|
contextBuilder: this.contextBuilder
|
|
@@ -6454,7 +6368,7 @@ var GraphAgentExecutor = class {
|
|
|
6454
6368
|
}),
|
|
6455
6369
|
createBuildDecisionStage()
|
|
6456
6370
|
];
|
|
6457
|
-
this.middlewares = [llmTelemetryMiddleware
|
|
6371
|
+
this.middlewares = [llmTelemetryMiddleware];
|
|
6458
6372
|
}
|
|
6459
6373
|
async tick(input, eventHandler) {
|
|
6460
6374
|
const ctx = {
|
|
@@ -6479,7 +6393,7 @@ var GraphAgentExecutor = class {
|
|
|
6479
6393
|
audit: this.auditPort,
|
|
6480
6394
|
tokenizer: this.tokenizer
|
|
6481
6395
|
};
|
|
6482
|
-
|
|
6396
|
+
logger5.info("[GraphAgentExecutor] tick \u8C03\u7528", {
|
|
6483
6397
|
stream: input.stream === true,
|
|
6484
6398
|
hasEventHandler: Boolean(eventHandler),
|
|
6485
6399
|
hasSummarizationCallbacks: Boolean(input.summarizationCallbacks)
|
|
@@ -7502,7 +7416,7 @@ var LlmNodeEventBridge = class {
|
|
|
7502
7416
|
};
|
|
7503
7417
|
|
|
7504
7418
|
// src/runtime-kernel/graph-engine/nodes/llmNode.ts
|
|
7505
|
-
var
|
|
7419
|
+
var logger6 = new Logger("LlmNode");
|
|
7506
7420
|
var LlmNode = class {
|
|
7507
7421
|
id = "llm";
|
|
7508
7422
|
reasoner;
|
|
@@ -7511,7 +7425,7 @@ var LlmNode = class {
|
|
|
7511
7425
|
}
|
|
7512
7426
|
async run(state) {
|
|
7513
7427
|
const local = state.local ?? {};
|
|
7514
|
-
|
|
7428
|
+
logger6.info("[LlmNode] \u5F00\u59CB\u6267\u884C LLM \u8282\u70B9", {
|
|
7515
7429
|
localKeys: Object.keys(local)
|
|
7516
7430
|
});
|
|
7517
7431
|
const graphLocal = readGraphAgentLocal(state.local);
|
|
@@ -7526,12 +7440,12 @@ var LlmNode = class {
|
|
|
7526
7440
|
signal,
|
|
7527
7441
|
history
|
|
7528
7442
|
} = graphLocal;
|
|
7529
|
-
|
|
7443
|
+
logger6.info("[LlmNode] \u5DF2\u52A0\u8F7D\u5386\u53F2\u4E8B\u4EF6", {
|
|
7530
7444
|
historyCount: history.length,
|
|
7531
7445
|
hasSummarizationCallbacks: Boolean(summarizationCallbacks)
|
|
7532
7446
|
});
|
|
7533
7447
|
if (!request) {
|
|
7534
|
-
|
|
7448
|
+
logger6.warn("Request object is missing, yielding.");
|
|
7535
7449
|
return { kind: "yield", events: [] };
|
|
7536
7450
|
}
|
|
7537
7451
|
const turnId = requireRuntimeIdentity(graphLocal.turnId, "turnId");
|
|
@@ -7624,12 +7538,12 @@ var LlmNode = class {
|
|
|
7624
7538
|
...nodeState.streamRuntimeEvents,
|
|
7625
7539
|
...contextUsageEvent ? [contextUsageEvent] : []
|
|
7626
7540
|
];
|
|
7627
|
-
|
|
7541
|
+
logger6.info("[LlmNode] \u5386\u53F2\u4E8B\u4EF6\u5DF2\u66F4\u65B0", {
|
|
7628
7542
|
previousCount: history.length,
|
|
7629
7543
|
nextCount: patch.history.length,
|
|
7630
7544
|
streamedEventCount: nodeState.streamRuntimeEvents.length
|
|
7631
7545
|
});
|
|
7632
|
-
|
|
7546
|
+
logger6.info("[LlmNode] \u6267\u884C\u5668\u51B3\u7B56\u5B8C\u6210", {
|
|
7633
7547
|
decisionKind: decision.kind,
|
|
7634
7548
|
emittedEventCount: combinedEvents.length
|
|
7635
7549
|
});
|
|
@@ -7651,7 +7565,7 @@ var LlmNode = class {
|
|
|
7651
7565
|
}
|
|
7652
7566
|
case "error": {
|
|
7653
7567
|
const { name, message, stack } = decision.error;
|
|
7654
|
-
|
|
7568
|
+
logger6.error("[LlmNode] Executor returned an error", { name, message, stack });
|
|
7655
7569
|
return { kind: "yield", events: combinedEvents };
|
|
7656
7570
|
}
|
|
7657
7571
|
default: {
|
|
@@ -7757,7 +7671,7 @@ async function resolveToolModelInput(input) {
|
|
|
7757
7671
|
}
|
|
7758
7672
|
|
|
7759
7673
|
// src/runtime-kernel/graph-engine/nodes/toolNode.finalAnswerProjector.ts
|
|
7760
|
-
function
|
|
7674
|
+
function readNonEmptyString4(value) {
|
|
7761
7675
|
if (typeof value !== "string") {
|
|
7762
7676
|
return void 0;
|
|
7763
7677
|
}
|
|
@@ -7765,7 +7679,7 @@ function readNonEmptyString5(value) {
|
|
|
7765
7679
|
return normalized.length > 0 ? normalized : void 0;
|
|
7766
7680
|
}
|
|
7767
7681
|
function resolveFinalAnswerFromToolControl(finalAnswer) {
|
|
7768
|
-
return
|
|
7682
|
+
return readNonEmptyString4(finalAnswer);
|
|
7769
7683
|
}
|
|
7770
7684
|
|
|
7771
7685
|
// src/runtime-kernel/graph-engine/nodes/toolNode.helpers.ts
|
|
@@ -8021,7 +7935,7 @@ function buildErrorLocalState(params) {
|
|
|
8021
7935
|
}
|
|
8022
7936
|
|
|
8023
7937
|
// src/runtime-kernel/tools/argNormalizer.ts
|
|
8024
|
-
var
|
|
7938
|
+
var logger7 = new Logger("ToolArgNormalizer");
|
|
8025
7939
|
function isRecord10(v) {
|
|
8026
7940
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
8027
7941
|
}
|
|
@@ -8041,7 +7955,7 @@ function joinPath(basePath, segment) {
|
|
|
8041
7955
|
function logJsonEncodedNormalization(expectedType, options) {
|
|
8042
7956
|
const toolPrefix = options.toolName ? `${options.toolName}.` : "";
|
|
8043
7957
|
const path = options.path ?? "<root>";
|
|
8044
|
-
|
|
7958
|
+
logger7.warn("normalized JSON-encoded tool argument", {
|
|
8045
7959
|
expectedType,
|
|
8046
7960
|
path: `${toolPrefix}${path}`
|
|
8047
7961
|
});
|
|
@@ -8397,7 +8311,7 @@ function stripRuntimeReservedToolContextPatch(patch) {
|
|
|
8397
8311
|
}
|
|
8398
8312
|
|
|
8399
8313
|
// src/runtime-kernel/graph-engine/nodes/toolNode.eventBridge.ts
|
|
8400
|
-
var
|
|
8314
|
+
var logger8 = new Logger("ToolNode");
|
|
8401
8315
|
var ToolNodeEventBridge = class {
|
|
8402
8316
|
constructor(deps) {
|
|
8403
8317
|
this.deps = deps;
|
|
@@ -8419,7 +8333,7 @@ var ToolNodeEventBridge = class {
|
|
|
8419
8333
|
status,
|
|
8420
8334
|
payload: { ...payload }
|
|
8421
8335
|
};
|
|
8422
|
-
|
|
8336
|
+
logger8.info("[ToolNode] \u53D1\u51FA tool_process \u4E8B\u4EF6", {
|
|
8423
8337
|
phase,
|
|
8424
8338
|
status,
|
|
8425
8339
|
toolName: this.deps.toolName,
|
|
@@ -8459,7 +8373,7 @@ var ToolNodeEventBridge = class {
|
|
|
8459
8373
|
const answerId = generateAnswerSegmentId();
|
|
8460
8374
|
const id = answerId;
|
|
8461
8375
|
const timestamp = Date.now();
|
|
8462
|
-
|
|
8376
|
+
logger8.info("[ToolNode] \u5DE5\u5177\u8F93\u51FA\u6620\u5C04\u4E3A final_answer", {
|
|
8463
8377
|
sourceToolName: params.sourceToolName,
|
|
8464
8378
|
toolCallId: this.deps.toolCallId,
|
|
8465
8379
|
conversationId: this.deps.conversationId,
|
|
@@ -8517,7 +8431,7 @@ var ToolNodeEventBridge = class {
|
|
|
8517
8431
|
};
|
|
8518
8432
|
|
|
8519
8433
|
// src/runtime-kernel/graph-engine/nodes/toolNode.executionSetup.ts
|
|
8520
|
-
var
|
|
8434
|
+
var logger9 = new Logger("ToolNode");
|
|
8521
8435
|
function parseToolArgs(call) {
|
|
8522
8436
|
const rawArguments = typeof call.function?.arguments === "string" ? call.function.arguments : "";
|
|
8523
8437
|
if (!rawArguments.trim()) {
|
|
@@ -8537,7 +8451,7 @@ function parseToolArgs(call) {
|
|
|
8537
8451
|
return { ok: true, value: parsed };
|
|
8538
8452
|
} catch (error) {
|
|
8539
8453
|
const reason = error instanceof Error ? error.message : "Unknown JSON parse error";
|
|
8540
|
-
|
|
8454
|
+
logger9.warn("failed to parse tool arguments", { error });
|
|
8541
8455
|
return {
|
|
8542
8456
|
ok: false,
|
|
8543
8457
|
error: `Tool arguments are not valid JSON: ${reason}`
|
|
@@ -8931,7 +8845,7 @@ async function claimPendingUserInputs(state, result) {
|
|
|
8931
8845
|
}
|
|
8932
8846
|
|
|
8933
8847
|
// src/runtime-kernel/graph-engine/nodes/toolNode.ts
|
|
8934
|
-
var
|
|
8848
|
+
var logger10 = new Logger("ToolNode");
|
|
8935
8849
|
function isAbortSignal(value) {
|
|
8936
8850
|
return value !== null && typeof value === "object" && "aborted" in value;
|
|
8937
8851
|
}
|
|
@@ -9144,7 +9058,7 @@ var ToolNode = class {
|
|
|
9144
9058
|
throw abortError;
|
|
9145
9059
|
}
|
|
9146
9060
|
const prepared = prepareToolNodeContext(state);
|
|
9147
|
-
|
|
9061
|
+
logger10.info("[ToolNode] \u5F00\u59CB\u6267\u884C\u5DE5\u5177\u8282\u70B9", {
|
|
9148
9062
|
conversationId: prepared.conversationId,
|
|
9149
9063
|
turnId: prepared.turnId,
|
|
9150
9064
|
pendingCallCount: calls.length
|
|
@@ -9159,7 +9073,7 @@ var ToolNode = class {
|
|
|
9159
9073
|
toolCatalog: this.toolRuntime
|
|
9160
9074
|
});
|
|
9161
9075
|
if (!execution) {
|
|
9162
|
-
|
|
9076
|
+
logger10.warn("no tool name found in call");
|
|
9163
9077
|
return { kind: "yield", events: [] };
|
|
9164
9078
|
}
|
|
9165
9079
|
if (typeof execution.protocolError === "string") {
|
|
@@ -9199,7 +9113,7 @@ var ToolNode = class {
|
|
|
9199
9113
|
call,
|
|
9200
9114
|
context: prepared.toolContext,
|
|
9201
9115
|
abortGraceMs: this.abortGraceMs,
|
|
9202
|
-
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", {
|
|
9203
9117
|
toolName: execution.toolName,
|
|
9204
9118
|
toolCallId: execution.toolCallId,
|
|
9205
9119
|
conversationId: prepared.conversationId,
|
|
@@ -9369,7 +9283,7 @@ var ToolNode = class {
|
|
|
9369
9283
|
runtimeEvents: context.bridge.getRuntimeEvents()
|
|
9370
9284
|
});
|
|
9371
9285
|
if (control?.terminateRun) {
|
|
9372
|
-
|
|
9286
|
+
logger10.info("[ToolNode] \u6536\u5230 control.terminateRun\uFF0C\u6267\u884C\u5B8C\u5DE5\u5177\u540E\u76F4\u63A5 yield \u7ED3\u675F\u672C\u8F6E run", {
|
|
9373
9287
|
toolName: context.toolName,
|
|
9374
9288
|
toolCallId: context.toolCallId,
|
|
9375
9289
|
conversationId: context.conversationId,
|
|
@@ -9378,7 +9292,7 @@ var ToolNode = class {
|
|
|
9378
9292
|
return { kind: "yield", events: context.bridge.getRuntimeEvents() };
|
|
9379
9293
|
}
|
|
9380
9294
|
if (remainingCalls.length === 0 && context.local.toolBatchCompletionMode === "yield_after_batch") {
|
|
9381
|
-
|
|
9295
|
+
logger10.info("[ToolNode] \u5DE5\u5177\u6279\u6B21\u5DF2\u7ED3\u7B97\uFF0C\u6309 Host \u7B56\u7565\u76F4\u63A5 yield", {
|
|
9382
9296
|
toolName: context.toolName,
|
|
9383
9297
|
toolCallId: context.toolCallId,
|
|
9384
9298
|
conversationId: context.conversationId,
|
|
@@ -9825,6 +9739,8 @@ var executor = z.object({
|
|
|
9825
9739
|
lastStepsHintThreshold: counter.optional(),
|
|
9826
9740
|
systemReminderPolicy: AgentSpecSystemReminderPolicy.optional(),
|
|
9827
9741
|
toolObservationPolicy: AgentSpecToolObservationGovernancePolicy.optional(),
|
|
9742
|
+
// 已删除字段:0.45 及更早的 checkpoint 可能带 lastSuccessfulLlmModelId,0.46 及更早的可能带云端额度兜底留下的
|
|
9743
|
+
// runLockedModelId;照常接受,读入时丢弃(兜底已移除,恢复后按请求的模型继续)。
|
|
9828
9744
|
runLockedModelId: z.string().optional(),
|
|
9829
9745
|
lastSuccessfulLlmModelId: z.string().optional(),
|
|
9830
9746
|
llmInvocationKind: z.enum(["user_initiated", "continuation"]).optional(),
|
|
@@ -9835,7 +9751,7 @@ var executor = z.object({
|
|
|
9835
9751
|
committedCount: counter,
|
|
9836
9752
|
lastCommittedFingerprint: z.string().optional()
|
|
9837
9753
|
}).strict().optional()
|
|
9838
|
-
}).strict();
|
|
9754
|
+
}).strict().transform(({ lastSuccessfulLlmModelId: _retired, runLockedModelId: _retiredLock, ...state }) => state);
|
|
9839
9755
|
var checkpoint = z.object({
|
|
9840
9756
|
nodeId: z.string().min(1),
|
|
9841
9757
|
schemaVersion: z.literal(ENGINE_STATE_SCHEMA_VERSION).optional(),
|
|
@@ -10149,7 +10065,7 @@ __export(execution_exports, {
|
|
|
10149
10065
|
});
|
|
10150
10066
|
|
|
10151
10067
|
// src/runtime-kernel/execution/event-bus.ts
|
|
10152
|
-
var
|
|
10068
|
+
var logger11 = new Logger("EventBus");
|
|
10153
10069
|
var TypedEventEmitter = class {
|
|
10154
10070
|
listeners = /* @__PURE__ */ new Map();
|
|
10155
10071
|
maxListeners = 10;
|
|
@@ -10157,7 +10073,7 @@ var TypedEventEmitter = class {
|
|
|
10157
10073
|
const listeners = this.getListeners(event);
|
|
10158
10074
|
listeners.add(listener);
|
|
10159
10075
|
if (listeners.size > this.maxListeners) {
|
|
10160
|
-
|
|
10076
|
+
logger11.warn("EventBus listener count exceeds configured max", {
|
|
10161
10077
|
event: String(event),
|
|
10162
10078
|
count: listeners.size,
|
|
10163
10079
|
maxListeners: this.maxListeners
|
|
@@ -10217,7 +10133,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10217
10133
|
super();
|
|
10218
10134
|
this.executionId = executionId;
|
|
10219
10135
|
this.setMaxListeners(30);
|
|
10220
|
-
|
|
10136
|
+
logger11.info(`EventBus created for execution ${this.executionId}`);
|
|
10221
10137
|
}
|
|
10222
10138
|
/**
|
|
10223
10139
|
* 发布一个事件到总线
|
|
@@ -10226,7 +10142,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10226
10142
|
publish(envelope) {
|
|
10227
10143
|
if (envelope.trace.execution_id !== this.executionId) {
|
|
10228
10144
|
const error = new Error("EventEnvelope execution_id does not match EventBus instance.");
|
|
10229
|
-
|
|
10145
|
+
logger11.error("Mismatched execution_id", {
|
|
10230
10146
|
busExecutionId: this.executionId,
|
|
10231
10147
|
eventExecutionId: envelope.trace.execution_id,
|
|
10232
10148
|
eventSeq: envelope.seq
|
|
@@ -10238,7 +10154,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10238
10154
|
const error = new Error(
|
|
10239
10155
|
"EventBus only accepts RuntimeEvent with formal run routing identity."
|
|
10240
10156
|
);
|
|
10241
|
-
|
|
10157
|
+
logger11.error("RuntimeEvent is missing formal run routing identity", {
|
|
10242
10158
|
executionId: this.executionId,
|
|
10243
10159
|
eventId: envelope.payload.id,
|
|
10244
10160
|
eventType: envelope.payload.type
|
|
@@ -10252,14 +10168,14 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10252
10168
|
* 关闭总线,清理所有监听器
|
|
10253
10169
|
*/
|
|
10254
10170
|
close() {
|
|
10255
|
-
|
|
10171
|
+
logger11.info(`Closing EventBus for execution ${this.executionId}`);
|
|
10256
10172
|
this.emit("close");
|
|
10257
10173
|
this.removeAllListeners();
|
|
10258
10174
|
}
|
|
10259
10175
|
};
|
|
10260
10176
|
|
|
10261
10177
|
// src/runtime-kernel/execution/sequencer.ts
|
|
10262
|
-
var
|
|
10178
|
+
var logger12 = new Logger("EventSequencer");
|
|
10263
10179
|
var EventSequencer = class {
|
|
10264
10180
|
executionId;
|
|
10265
10181
|
traceId;
|
|
@@ -10267,7 +10183,7 @@ var EventSequencer = class {
|
|
|
10267
10183
|
constructor(conversationId, traceId) {
|
|
10268
10184
|
this.executionId = generateExecutionId();
|
|
10269
10185
|
this.traceId = traceId || generateTraceId();
|
|
10270
|
-
|
|
10186
|
+
logger12.info(`EventSequencer created for conversation ${conversationId}`, {
|
|
10271
10187
|
executionId: this.executionId,
|
|
10272
10188
|
traceId: this.traceId
|
|
10273
10189
|
});
|
|
@@ -11125,7 +11041,7 @@ var ThoughtStreamSegmenter = class {
|
|
|
11125
11041
|
};
|
|
11126
11042
|
|
|
11127
11043
|
// src/runtime-kernel/llm/streaming-adapter.ts
|
|
11128
|
-
var
|
|
11044
|
+
var logger13 = new Logger("LlmCaller");
|
|
11129
11045
|
var CanonicalInferenceFailureError = class extends Error {
|
|
11130
11046
|
errorCode;
|
|
11131
11047
|
recoverable;
|
|
@@ -11349,7 +11265,7 @@ async function callLlmStream(params) {
|
|
|
11349
11265
|
} catch (error) {
|
|
11350
11266
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
11351
11267
|
if (normalized.name === "AbortError") {
|
|
11352
|
-
|
|
11268
|
+
logger13.info("Canonical inference \u6536\u5230\u53D6\u6D88\u7EC8\u6001\uFF0C\u4E0D\u53D1\u5E03\u666E\u901A error event", { modelId });
|
|
11353
11269
|
throw normalized;
|
|
11354
11270
|
}
|
|
11355
11271
|
const classification = ErrorClassifier.classify(normalized, {
|
|
@@ -11425,7 +11341,7 @@ var LlmRetryEpisode = class {
|
|
|
11425
11341
|
};
|
|
11426
11342
|
|
|
11427
11343
|
// src/runtime-kernel/llm/retry-fallback-routing.ts
|
|
11428
|
-
var
|
|
11344
|
+
var logger14 = new Logger("LlmCaller");
|
|
11429
11345
|
function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement, fallbackObserver, error, evaluateFallbackPromptCapacity2) {
|
|
11430
11346
|
deps.modelCatalog.getModelById(activeModelId);
|
|
11431
11347
|
const policyDecision = deps.policyEngine.decideOnError(error, {
|
|
@@ -11455,81 +11371,16 @@ function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement
|
|
|
11455
11371
|
reason: "no_eligible_fallback_candidate",
|
|
11456
11372
|
requiredPlacements: requirement.placements
|
|
11457
11373
|
});
|
|
11458
|
-
|
|
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");
|
|
11459
11375
|
return null;
|
|
11460
11376
|
}
|
|
11461
|
-
|
|
11377
|
+
logger14.warn("Policy \u5207\u6362\u6A21\u578B\u7EE7\u7EED", {
|
|
11462
11378
|
reason: policyDecision.reason,
|
|
11463
11379
|
activeModelId,
|
|
11464
11380
|
fallbackModelId
|
|
11465
11381
|
});
|
|
11466
11382
|
return fallbackModelId;
|
|
11467
11383
|
}
|
|
11468
|
-
function tryCloudQuotaFallback({
|
|
11469
|
-
deps,
|
|
11470
|
-
activeModelId,
|
|
11471
|
-
options,
|
|
11472
|
-
excludedModelIds,
|
|
11473
|
-
requirement,
|
|
11474
|
-
error,
|
|
11475
|
-
fallbackObserver,
|
|
11476
|
-
evaluateFallbackPromptCapacity: evaluateFallbackPromptCapacity2
|
|
11477
|
-
}) {
|
|
11478
|
-
const fallbackModelId = options.cloud_quota_fallback_model_id;
|
|
11479
|
-
if (!fallbackModelId || !ErrorClassifier.isCloudQuotaError(error) || excludedModelIds.has(fallbackModelId)) {
|
|
11480
|
-
return null;
|
|
11481
|
-
}
|
|
11482
|
-
const fallbackConfig = deps.modelCatalog.getModelById(fallbackModelId);
|
|
11483
|
-
if (!fallbackConfig?.api_key) {
|
|
11484
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11485
|
-
fromModelId: activeModelId,
|
|
11486
|
-
candidateModelId: fallbackModelId,
|
|
11487
|
-
policy: "cloud-quota",
|
|
11488
|
-
reason: "fallback_model_unavailable",
|
|
11489
|
-
requiredPlacements: requirement.placements
|
|
11490
|
-
});
|
|
11491
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\u76EE\u6807\u4E0D\u53EF\u7528\uFF08\u672A\u6CE8\u518C\u6216\u7F3A\u5C11 API Key\uFF09", { fallbackModelId });
|
|
11492
|
-
return null;
|
|
11493
|
-
}
|
|
11494
|
-
const compatibility = evaluateModelInputCompatibility(fallbackConfig, requirement);
|
|
11495
|
-
if (!compatibility.compatible) {
|
|
11496
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11497
|
-
fromModelId: activeModelId,
|
|
11498
|
-
candidateModelId: fallbackModelId,
|
|
11499
|
-
policy: "cloud-quota",
|
|
11500
|
-
reason: compatibility.reason,
|
|
11501
|
-
requiredPlacements: requirement.placements
|
|
11502
|
-
});
|
|
11503
|
-
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", {
|
|
11504
|
-
fallbackModelId,
|
|
11505
|
-
requiredPlacements: requirement.placements,
|
|
11506
|
-
reason: compatibility.reason
|
|
11507
|
-
});
|
|
11508
|
-
return null;
|
|
11509
|
-
}
|
|
11510
|
-
const capacityAdmission = evaluateFallbackPromptCapacity2?.(fallbackModelId);
|
|
11511
|
-
if (capacityAdmission && !capacityAdmission.admitted) {
|
|
11512
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11513
|
-
fromModelId: activeModelId,
|
|
11514
|
-
candidateModelId: fallbackModelId,
|
|
11515
|
-
policy: "cloud-quota",
|
|
11516
|
-
reason: capacityAdmission.reason,
|
|
11517
|
-
requiredPlacements: requirement.placements
|
|
11518
|
-
});
|
|
11519
|
-
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", {
|
|
11520
|
-
fallbackModelId,
|
|
11521
|
-
reason: capacityAdmission.reason
|
|
11522
|
-
});
|
|
11523
|
-
return null;
|
|
11524
|
-
}
|
|
11525
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\uFF08run \u5185\u7EED\u8DD1\uFF09", {
|
|
11526
|
-
activeModelId,
|
|
11527
|
-
fallbackModelId,
|
|
11528
|
-
reason: error.message
|
|
11529
|
-
});
|
|
11530
|
-
fallbackObserver?.onCloudQuotaFallbackApplied?.(fallbackModelId);
|
|
11531
|
-
return fallbackModelId;
|
|
11532
|
-
}
|
|
11533
11384
|
|
|
11534
11385
|
// src/runtime-kernel/llm/usage-telemetry.ts
|
|
11535
11386
|
async function callPlainCompletion(inferencePort, modelId, messages, options = {}, signal, traceId) {
|
|
@@ -11652,7 +11503,7 @@ var LlmImageInputError = class extends Error {
|
|
|
11652
11503
|
};
|
|
11653
11504
|
|
|
11654
11505
|
// src/runtime-kernel/llm/retry-fallback.ts
|
|
11655
|
-
var
|
|
11506
|
+
var logger15 = new Logger("LlmCaller");
|
|
11656
11507
|
async function callWithRetryFallback(params) {
|
|
11657
11508
|
const {
|
|
11658
11509
|
deps,
|
|
@@ -11680,11 +11531,9 @@ async function callWithRetryFallback(params) {
|
|
|
11680
11531
|
const retryEpisode = new LlmRetryEpisode(traceId, eventHandler);
|
|
11681
11532
|
let previousAttemptTracker;
|
|
11682
11533
|
if (!clientRetryEnabled) {
|
|
11683
|
-
|
|
11684
|
-
logger16.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
11534
|
+
logger15.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
11685
11535
|
modelId,
|
|
11686
|
-
|
|
11687
|
-
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"
|
|
11688
11537
|
});
|
|
11689
11538
|
}
|
|
11690
11539
|
try {
|
|
@@ -11720,7 +11569,7 @@ async function callWithRetryFallback(params) {
|
|
|
11720
11569
|
}) : void 0;
|
|
11721
11570
|
try {
|
|
11722
11571
|
if (isRetry) {
|
|
11723
|
-
|
|
11572
|
+
logger15.info("LLM \u8C03\u7528\u91CD\u8BD5", { attempt, configuredMaxRetries });
|
|
11724
11573
|
}
|
|
11725
11574
|
actualAttempts++;
|
|
11726
11575
|
retryEpisode.retrying(actualAttempts);
|
|
@@ -11749,7 +11598,7 @@ async function callWithRetryFallback(params) {
|
|
|
11749
11598
|
if (deps.retryConfig.enableEmptyResponseRetry && !responseContent?.trim() && !toolCallsFromLLM?.length) {
|
|
11750
11599
|
throw new Error("LLM\u8FD4\u56DE\u4E86\u7A7A\u54CD\u5E94");
|
|
11751
11600
|
}
|
|
11752
|
-
|
|
11601
|
+
logger15.debug("LLM \u8C03\u7528\u6210\u529F", { attempts: actualAttempts, maxTotalAttempts });
|
|
11753
11602
|
if (attemptContextUsage) {
|
|
11754
11603
|
fallbackObserver?.onLlmAttemptSucceeded?.(activeModelId, attemptContextUsage);
|
|
11755
11604
|
} else {
|
|
@@ -11760,7 +11609,7 @@ async function callWithRetryFallback(params) {
|
|
|
11760
11609
|
} catch (error) {
|
|
11761
11610
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
11762
11611
|
if (lastError.name === "AbortError") {
|
|
11763
|
-
|
|
11612
|
+
logger15.info("LLM \u8C03\u7528\u5DF2\u53D6\u6D88\uFF0C\u4E0D\u8FDB\u5165 provider failure \u5206\u7C7B\u4E0E\u91CD\u8BD5\u6D41\u7A0B", {
|
|
11764
11613
|
attempt: attempt + 1,
|
|
11765
11614
|
actualAttempts,
|
|
11766
11615
|
maxTotalAttempts,
|
|
@@ -11779,7 +11628,7 @@ async function callWithRetryFallback(params) {
|
|
|
11779
11628
|
total_attempts: actualAttempts,
|
|
11780
11629
|
error_code: classification.errorCode
|
|
11781
11630
|
};
|
|
11782
|
-
|
|
11631
|
+
logger15.error("LLM \u8C03\u7528\u5931\u8D25", {
|
|
11783
11632
|
attempt: attempt + 1,
|
|
11784
11633
|
maxAttempts: currentMaxRetries + 1,
|
|
11785
11634
|
actualAttempts,
|
|
@@ -11788,7 +11637,7 @@ async function callWithRetryFallback(params) {
|
|
|
11788
11637
|
});
|
|
11789
11638
|
previousAttemptTracker = attemptTracker;
|
|
11790
11639
|
if (!hasLlmAttemptBudgetRemaining({ actualAttempts, maxTotalAttempts })) {
|
|
11791
|
-
|
|
11640
|
+
logger15.error("\u5DF2\u8FBE\u5230 LLM \u603B\u8C03\u7528\u6B21\u6570\u4E0A\u9650\uFF0C\u505C\u6B62\u91CD\u8BD5/\u5207\u6A21\u578B", {
|
|
11792
11641
|
actualAttempts,
|
|
11793
11642
|
maxTotalAttempts
|
|
11794
11643
|
});
|
|
@@ -11818,37 +11667,15 @@ async function callWithRetryFallback(params) {
|
|
|
11818
11667
|
attempt -= 1;
|
|
11819
11668
|
continue;
|
|
11820
11669
|
}
|
|
11821
|
-
const quotaFallbackModelId = tryCloudQuotaFallback({
|
|
11822
|
-
deps,
|
|
11823
|
-
activeModelId,
|
|
11824
|
-
options,
|
|
11825
|
-
excludedModelIds,
|
|
11826
|
-
requirement,
|
|
11827
|
-
error: lastError,
|
|
11828
|
-
fallbackObserver,
|
|
11829
|
-
evaluateFallbackPromptCapacity: invocationContext?.evaluateFallbackPromptCapacity
|
|
11830
|
-
});
|
|
11831
|
-
if (quotaFallbackModelId) {
|
|
11832
|
-
fallbackObserver?.onModelFallbackApplied?.({
|
|
11833
|
-
fromModelId: activeModelId,
|
|
11834
|
-
toModelId: quotaFallbackModelId,
|
|
11835
|
-
reason: lastError.message,
|
|
11836
|
-
policy: "cloud-quota"
|
|
11837
|
-
});
|
|
11838
|
-
activeModelId = quotaFallbackModelId;
|
|
11839
|
-
excludedModelIds.add(quotaFallbackModelId);
|
|
11840
|
-
attempt -= 1;
|
|
11841
|
-
continue;
|
|
11842
|
-
}
|
|
11843
11670
|
}
|
|
11844
11671
|
if (classification.category === "non_retryable" /* NON_RETRYABLE */) {
|
|
11845
|
-
|
|
11672
|
+
logger15.error("\u9519\u8BEF\u4E0D\u53EF\u91CD\u8BD5\uFF0C\u76F4\u63A5\u5931\u8D25", { reason: classification.reason });
|
|
11846
11673
|
retryEpisode.finish("failed", failedRetryState);
|
|
11847
11674
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
11848
11675
|
throw lastError;
|
|
11849
11676
|
}
|
|
11850
11677
|
if (attempt >= configuredMaxRetries || categoryRetries[category] >= currentMaxRetries) {
|
|
11851
|
-
|
|
11678
|
+
logger15.error("\u5DF2\u8FBE\u5230\u6700\u5927\u91CD\u8BD5\u6B21\u6570\uFF0C\u653E\u5F03\u91CD\u8BD5", { maxRetries: currentMaxRetries });
|
|
11852
11679
|
retryEpisode.finish("exhausted", failedRetryState);
|
|
11853
11680
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
11854
11681
|
throw lastError;
|
|
@@ -11860,9 +11687,9 @@ async function callWithRetryFallback(params) {
|
|
|
11860
11687
|
6e4
|
|
11861
11688
|
);
|
|
11862
11689
|
if (classification.category === "rate_limit" /* RATE_LIMIT */) {
|
|
11863
|
-
|
|
11690
|
+
logger15.warn("\u901F\u7387\u9650\u5236\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
11864
11691
|
} else if (classification.category === "retryable" /* RETRYABLE */) {
|
|
11865
|
-
|
|
11692
|
+
logger15.warn("\u53EF\u91CD\u8BD5\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
11866
11693
|
}
|
|
11867
11694
|
throwIfAborted(signal, "\u5EF6\u8FDF\u7B49\u5F85\u524D\u68C0\u6D4B\u5230\u53D6\u6D88\u4FE1\u53F7\uFF0C\u505C\u6B62\u91CD\u8BD5");
|
|
11868
11695
|
categoryRetries[category] += 1;
|
|
@@ -11899,16 +11726,11 @@ function waitForRetry(delayMs, signal) {
|
|
|
11899
11726
|
}
|
|
11900
11727
|
function isClientRetryEnabledForModel(modelCatalog, modelId, options) {
|
|
11901
11728
|
if (options.retry_policy === "none") return false;
|
|
11902
|
-
|
|
11903
|
-
if (cfg?.billing_mode === "cloud") return false;
|
|
11904
|
-
if (options.retry_policy === "client") return true;
|
|
11905
|
-
if (!cfg) return true;
|
|
11906
|
-
if (cfg.enable_client_retry === false) return false;
|
|
11907
|
-
return true;
|
|
11729
|
+
return modelCatalog.getModelById(modelId)?.enable_client_retry !== false;
|
|
11908
11730
|
}
|
|
11909
11731
|
function throwIfAborted(signal, message) {
|
|
11910
11732
|
if (!signal?.aborted) return;
|
|
11911
|
-
|
|
11733
|
+
logger15.info(message);
|
|
11912
11734
|
const reason = signal.reason;
|
|
11913
11735
|
if (reason instanceof Error && reason.name === "AbortError") throw reason;
|
|
11914
11736
|
const reasonText = typeof reason === "string" && reason.trim().length > 0 ? reason : "stream_interrupted";
|
|
@@ -12226,7 +12048,7 @@ async function recoverChildRunEventsFromCheckpoint(params) {
|
|
|
12226
12048
|
}
|
|
12227
12049
|
|
|
12228
12050
|
// src/runtime-kernel/child-runs/childRunInvoker.ts
|
|
12229
|
-
var
|
|
12051
|
+
var logger16 = new Logger("ChildRunInvoker");
|
|
12230
12052
|
var ChildRunInvoker = class {
|
|
12231
12053
|
modelResolver;
|
|
12232
12054
|
createLlmNode;
|
|
@@ -12268,7 +12090,7 @@ var ChildRunInvoker = class {
|
|
|
12268
12090
|
const resolvedParentRunId = parentRunId ?? parentToolContext.runId;
|
|
12269
12091
|
const depthDecision = decideChildRunDepth({ parentToolContext });
|
|
12270
12092
|
if (!depthDecision.allowed) {
|
|
12271
|
-
|
|
12093
|
+
logger16.warn("child-run \u6DF1\u5EA6\u8D85\u8FC7\u4E0A\u9650\uFF0C\u62D2\u7EDD\u7EE7\u7EED\u9012\u5F52\u6267\u884C", {
|
|
12272
12094
|
runId: childRunId,
|
|
12273
12095
|
parentRunId: resolvedParentRunId,
|
|
12274
12096
|
parentDepth: depthDecision.parentDepth,
|
|
@@ -12285,7 +12107,7 @@ var ChildRunInvoker = class {
|
|
|
12285
12107
|
};
|
|
12286
12108
|
}
|
|
12287
12109
|
if (abortSignal?.aborted || parentToolContext.abortSignal?.aborted) {
|
|
12288
|
-
|
|
12110
|
+
logger16.info("child-run \u5728\u4EFB\u52A1\u63A5\u7EB3\u524D\u5DF2\u53D6\u6D88", {
|
|
12289
12111
|
runId: childRunId,
|
|
12290
12112
|
parentRunId: resolvedParentRunId
|
|
12291
12113
|
});
|
|
@@ -12309,7 +12131,7 @@ var ChildRunInvoker = class {
|
|
|
12309
12131
|
}
|
|
12310
12132
|
const turnId = config.initialInput?.turnId ?? generateTurnId();
|
|
12311
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");
|
|
12312
|
-
|
|
12134
|
+
logger16.info(`\u542F\u52A8 child-run: ${agentConfig.id}`, {
|
|
12313
12135
|
conversationId: runtimeConversationId,
|
|
12314
12136
|
checkpointKey: internalCheckpointKey,
|
|
12315
12137
|
maxSteps,
|
|
@@ -12427,7 +12249,7 @@ var ChildRunInvoker = class {
|
|
|
12427
12249
|
);
|
|
12428
12250
|
finalAnswer = extractFinalAnswer(allEvents);
|
|
12429
12251
|
lastProgress = finalAnswer ? void 0 : extractLastProgress(allEvents);
|
|
12430
|
-
|
|
12252
|
+
logger16.info("child-run \u6267\u884C\u5B8C\u6210", {
|
|
12431
12253
|
stepCount,
|
|
12432
12254
|
eventCount: allEvents.length,
|
|
12433
12255
|
hasFinalAnswer: !!finalAnswer,
|
|
@@ -12457,13 +12279,13 @@ var ChildRunInvoker = class {
|
|
|
12457
12279
|
cancelled = abortSignal?.aborted === true || isAbortError2(err);
|
|
12458
12280
|
error = err instanceof Error ? err.message : String(err);
|
|
12459
12281
|
if (cancelled) {
|
|
12460
|
-
|
|
12282
|
+
logger16.info("child-run \u6267\u884C\u53D6\u6D88", {
|
|
12461
12283
|
runId: childRunId,
|
|
12462
12284
|
parentRunId: resolvedParentRunId,
|
|
12463
12285
|
message: error
|
|
12464
12286
|
});
|
|
12465
12287
|
} else {
|
|
12466
|
-
|
|
12288
|
+
logger16.error(
|
|
12467
12289
|
"child-run \u6267\u884C\u5931\u8D25:",
|
|
12468
12290
|
err instanceof Error ? {
|
|
12469
12291
|
name: err.name,
|
|
@@ -12559,7 +12381,7 @@ var ChildRunInvoker = class {
|
|
|
12559
12381
|
function isAbortError2(error) {
|
|
12560
12382
|
return error instanceof Error && error.name === "AbortError";
|
|
12561
12383
|
}
|
|
12562
|
-
function
|
|
12384
|
+
function readNonEmptyString5(value) {
|
|
12563
12385
|
if (typeof value !== "string") {
|
|
12564
12386
|
return void 0;
|
|
12565
12387
|
}
|
|
@@ -12567,7 +12389,7 @@ function readNonEmptyString6(value) {
|
|
|
12567
12389
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
12568
12390
|
}
|
|
12569
12391
|
function resolveChildRunConversationId(params) {
|
|
12570
|
-
const conversationId =
|
|
12392
|
+
const conversationId = readNonEmptyString5(params.explicitConversationId) ?? readNonEmptyString5(params.parentToolContext.conversationId);
|
|
12571
12393
|
if (!conversationId) {
|
|
12572
12394
|
throw new Error(
|
|
12573
12395
|
"ChildRunInvoker requires conversationId from admission or parent ToolContext."
|
|
@@ -12576,7 +12398,7 @@ function resolveChildRunConversationId(params) {
|
|
|
12576
12398
|
return conversationId;
|
|
12577
12399
|
}
|
|
12578
12400
|
function resolveChildRunModelId(params) {
|
|
12579
|
-
const explicitModelId =
|
|
12401
|
+
const explicitModelId = readNonEmptyString5(params.explicitModelId);
|
|
12580
12402
|
if (explicitModelId) {
|
|
12581
12403
|
return explicitModelId;
|
|
12582
12404
|
}
|
|
@@ -13521,7 +13343,7 @@ function runMetaFromRecord(record) {
|
|
|
13521
13343
|
}
|
|
13522
13344
|
|
|
13523
13345
|
// src/runtime-kernel/run-supervisor/functions/awaitingUserWatcher.ts
|
|
13524
|
-
var
|
|
13346
|
+
var logger17 = new Logger("RunSupervisorAwaitingUserWatcher");
|
|
13525
13347
|
function isRecord16(value) {
|
|
13526
13348
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13527
13349
|
}
|
|
@@ -13566,7 +13388,7 @@ function createAwaitingUserWatcher(options) {
|
|
|
13566
13388
|
resumeToken: event.resume_token
|
|
13567
13389
|
}
|
|
13568
13390
|
}).catch((error) => {
|
|
13569
|
-
|
|
13391
|
+
logger17.warn("failed to mark awaiting_user from requires_user_interaction", { error });
|
|
13570
13392
|
});
|
|
13571
13393
|
};
|
|
13572
13394
|
const dispose = () => {
|