@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/testkit.cjs
CHANGED
|
@@ -610,18 +610,6 @@ var ErrorClassifier = class {
|
|
|
610
610
|
});
|
|
611
611
|
}
|
|
612
612
|
}
|
|
613
|
-
const quotaPatterns = ["\u5DF2\u8FBE\u4E0A\u9650", "\u514D\u8D39\u671F\u5DF2\u7ED3\u675F"];
|
|
614
|
-
for (const pattern of quotaPatterns) {
|
|
615
|
-
if (errorMessage.includes(pattern)) {
|
|
616
|
-
logClassification(context, "\u68C0\u6D4B\u5230\u4E91\u7AEF\u989D\u5EA6\u9650\u5236\uFF0C\u4E0D\u91CD\u8BD5", { matchedPattern: pattern });
|
|
617
|
-
return createClassification("non_retryable" /* NON_RETRYABLE */, `\u4E91\u7AEF\u989D\u5EA6\u9650\u5236: ${pattern}`, null, {
|
|
618
|
-
errorCode: ENGINE_ERROR_CODES.LLM_PROVIDER_DOWN,
|
|
619
|
-
recoverable: false,
|
|
620
|
-
hint: "check_billing_or_provider_status",
|
|
621
|
-
metadata: { matchedPattern: pattern }
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
613
|
const authPatterns = [
|
|
626
614
|
{ pattern: "unauthorized", code: "401" },
|
|
627
615
|
{ pattern: "forbidden", code: "403" },
|
|
@@ -876,17 +864,6 @@ var ErrorClassifier = class {
|
|
|
876
864
|
}
|
|
877
865
|
return Math.max(baseDelay, classification.suggestedDelay ?? 0);
|
|
878
866
|
}
|
|
879
|
-
static isCloudQuotaError(error) {
|
|
880
|
-
const msg = (error.message || "").toLowerCase();
|
|
881
|
-
const patterns = [
|
|
882
|
-
"\u989D\u5EA6\u4E0A\u9650",
|
|
883
|
-
"\u5DF2\u8FBE\u4E0A\u9650",
|
|
884
|
-
"\u514D\u8D39\u671F\u5DF2\u7ED3\u675F",
|
|
885
|
-
"\u8BE5\u6A21\u578B\u6682\u4E0D\u53EF\u7528",
|
|
886
|
-
"cloud_quota_exhausted"
|
|
887
|
-
];
|
|
888
|
-
return patterns.some((pattern) => msg.includes(pattern));
|
|
889
|
-
}
|
|
890
867
|
};
|
|
891
868
|
var NonBlankIdentitySchema = zod.z.string().max(200).refine(
|
|
892
869
|
(value) => value.trim().length > 0 && value === value.trim(),
|
|
@@ -4075,8 +4052,8 @@ var TokenCalculator = class {
|
|
|
4075
4052
|
return;
|
|
4076
4053
|
}
|
|
4077
4054
|
this.failedEncodingWarnings.add(requestedEncoding);
|
|
4078
|
-
const
|
|
4079
|
-
|
|
4055
|
+
const logger22 = new Logger("TokenCalculator");
|
|
4056
|
+
logger22.warn("tiktoken encoding unavailable, falling back to avgCharsPerToken estimator", {
|
|
4080
4057
|
requestedEncoding,
|
|
4081
4058
|
error
|
|
4082
4059
|
});
|
|
@@ -4168,49 +4145,6 @@ var llmTelemetryMiddleware = async (ctx, stage, next) => {
|
|
|
4168
4145
|
});
|
|
4169
4146
|
};
|
|
4170
4147
|
|
|
4171
|
-
// src/runtime-kernel/graph-engine/functions/runModelLock.ts
|
|
4172
|
-
function readNonEmptyString4(value) {
|
|
4173
|
-
if (typeof value !== "string") return void 0;
|
|
4174
|
-
const trimmed = value.trim();
|
|
4175
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
4176
|
-
}
|
|
4177
|
-
function decideRunModelLockPatch(params) {
|
|
4178
|
-
if (params.stageId !== "execute_llm") {
|
|
4179
|
-
return { shouldLog: false };
|
|
4180
|
-
}
|
|
4181
|
-
const normalized = readNonEmptyString4(params.appliedFallbackModelId);
|
|
4182
|
-
if (!normalized) {
|
|
4183
|
-
return { shouldLog: false };
|
|
4184
|
-
}
|
|
4185
|
-
if (readNonEmptyString4(params.currentRunLockedModelId) === normalized) {
|
|
4186
|
-
return { shouldLog: false };
|
|
4187
|
-
}
|
|
4188
|
-
return {
|
|
4189
|
-
executorLocalPatch: { runLockedModelId: normalized },
|
|
4190
|
-
shouldLog: true
|
|
4191
|
-
};
|
|
4192
|
-
}
|
|
4193
|
-
|
|
4194
|
-
// src/runtime-kernel/graph-engine/tick-pipeline/middlewares/runModelLockMiddleware.ts
|
|
4195
|
-
var logger4 = new Logger("GraphAgentExecutor");
|
|
4196
|
-
var runModelLockMiddleware = async (ctx, stage, next) => {
|
|
4197
|
-
await next();
|
|
4198
|
-
const decision = decideRunModelLockPatch({
|
|
4199
|
-
stageId: stage.id,
|
|
4200
|
-
appliedFallbackModelId: ctx.cloudQuotaFallbackAppliedModelId,
|
|
4201
|
-
currentRunLockedModelId: ctx.executorLocalPatch?.runLockedModelId ?? ctx.executorLocal?.runLockedModelId
|
|
4202
|
-
});
|
|
4203
|
-
if (!decision.executorLocalPatch) {
|
|
4204
|
-
return;
|
|
4205
|
-
}
|
|
4206
|
-
if (decision.shouldLog) {
|
|
4207
|
-
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}`);
|
|
4208
|
-
}
|
|
4209
|
-
return {
|
|
4210
|
-
executorLocalPatch: decision.executorLocalPatch
|
|
4211
|
-
};
|
|
4212
|
-
};
|
|
4213
|
-
|
|
4214
4148
|
// src/runtime-kernel/graph-engine/tick-pipeline/runTickPipeline.ts
|
|
4215
4149
|
var tickPipelineContextKeys = [
|
|
4216
4150
|
"input",
|
|
@@ -4246,7 +4180,6 @@ var tickPipelineContextKeys = [
|
|
|
4246
4180
|
"decision",
|
|
4247
4181
|
"systemReminderHitRuleIds",
|
|
4248
4182
|
"contextTrace",
|
|
4249
|
-
"cloudQuotaFallbackAppliedModelId",
|
|
4250
4183
|
"modelFallbackAudit",
|
|
4251
4184
|
"telemetry",
|
|
4252
4185
|
"audit",
|
|
@@ -4585,7 +4518,7 @@ ${normalized}
|
|
|
4585
4518
|
}
|
|
4586
4519
|
|
|
4587
4520
|
// src/runtime-kernel/system-reminder/apply.ts
|
|
4588
|
-
var
|
|
4521
|
+
var logger4 = new Logger("SystemReminder");
|
|
4589
4522
|
var readString2 = (v) => {
|
|
4590
4523
|
if (typeof v !== "string") return void 0;
|
|
4591
4524
|
const s = v;
|
|
@@ -4648,7 +4581,7 @@ function applySystemReminders(params) {
|
|
|
4648
4581
|
} catch {
|
|
4649
4582
|
}
|
|
4650
4583
|
}
|
|
4651
|
-
|
|
4584
|
+
logger4.info("SystemReminder \u5DF2\u6CE8\u5165\u5230 LLM \u8F93\u5165\u672B\u5C3E", {
|
|
4652
4585
|
ruleIds: injectedRuleIds.length > 0 ? injectedRuleIds : Array.from(seenRuleIds),
|
|
4653
4586
|
promptKey: ctx.request.promptKey,
|
|
4654
4587
|
executorLocal: {
|
|
@@ -5358,7 +5291,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5358
5291
|
"turnId"
|
|
5359
5292
|
],
|
|
5360
5293
|
writes: [
|
|
5361
|
-
"cloudQuotaFallbackAppliedModelId",
|
|
5362
5294
|
"modelFallbackAudit",
|
|
5363
5295
|
"llmCallStartedAt",
|
|
5364
5296
|
"llmResp",
|
|
@@ -5366,7 +5298,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5366
5298
|
"contextUsage"
|
|
5367
5299
|
],
|
|
5368
5300
|
async run(ctx) {
|
|
5369
|
-
let cloudQuotaFallbackAppliedModelId;
|
|
5370
5301
|
let modelFallbackAudit;
|
|
5371
5302
|
let contextUsage;
|
|
5372
5303
|
const modelFallbackRejections = [];
|
|
@@ -5385,9 +5316,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5385
5316
|
streamEventHandler,
|
|
5386
5317
|
ctx.signal,
|
|
5387
5318
|
{
|
|
5388
|
-
onCloudQuotaFallbackApplied(fallbackModelId) {
|
|
5389
|
-
cloudQuotaFallbackAppliedModelId = readNonEmptyString3(fallbackModelId);
|
|
5390
|
-
},
|
|
5391
5319
|
onLlmAttemptSucceeded(_activeModelId, attemptContextUsage) {
|
|
5392
5320
|
contextUsage = attemptContextUsage;
|
|
5393
5321
|
},
|
|
@@ -5484,7 +5412,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5484
5412
|
});
|
|
5485
5413
|
}
|
|
5486
5414
|
return {
|
|
5487
|
-
cloudQuotaFallbackAppliedModelId,
|
|
5488
5415
|
modelFallbackAudit,
|
|
5489
5416
|
llmCallStartedAt,
|
|
5490
5417
|
llmResp,
|
|
@@ -6405,18 +6332,16 @@ function createPrepareCallStage(dependencies) {
|
|
|
6405
6332
|
"toolDefinitionTokens"
|
|
6406
6333
|
],
|
|
6407
6334
|
async run(ctx) {
|
|
6408
|
-
const
|
|
6409
|
-
const requestedModelId = lockedRunModelId ?? ctx.request.model_id;
|
|
6335
|
+
const requestedModelId = ctx.request.model_id;
|
|
6410
6336
|
const modelId = dependencies.modelResolver.resolveModelId(requestedModelId);
|
|
6411
6337
|
await emitAuditEnvelope(ctx.audit, {
|
|
6412
6338
|
action: "model.select",
|
|
6413
6339
|
actor: { kind: "system" },
|
|
6414
6340
|
decision: {
|
|
6415
6341
|
outcome: "recorded",
|
|
6416
|
-
reason:
|
|
6342
|
+
reason: requestedModelId ? "request model id" : "default model resolver",
|
|
6417
6343
|
metadata: {
|
|
6418
6344
|
requestedModelId,
|
|
6419
|
-
lockedRunModelId,
|
|
6420
6345
|
selectedModelId: modelId
|
|
6421
6346
|
}
|
|
6422
6347
|
},
|
|
@@ -6463,10 +6388,6 @@ function createPrepareCallStage(dependencies) {
|
|
|
6463
6388
|
if (ctx.executorLocal?.lockRequestedModelId === true) {
|
|
6464
6389
|
llmOptions.allow_model_fallback = false;
|
|
6465
6390
|
}
|
|
6466
|
-
const isRunContinuation = ctx.executorLocal?.llmInvocationKind === "continuation";
|
|
6467
|
-
if (dependencies.cloudQuotaFallbackModelId && modelConfig?.billing_mode === "cloud" && modelId !== dependencies.cloudQuotaFallbackModelId && isRunContinuation && ctx.executorLocal?.lockRequestedModelId !== true) {
|
|
6468
|
-
llmOptions.cloud_quota_fallback_model_id = dependencies.cloudQuotaFallbackModelId;
|
|
6469
|
-
}
|
|
6470
6391
|
const effectiveEffort = resolveEffectiveEffort(
|
|
6471
6392
|
ctx.request.reasoning_effort,
|
|
6472
6393
|
modelConfig?.reasoning
|
|
@@ -6583,12 +6504,11 @@ function applyCalibration(rawLocalTotal, imageInputTokens, coefficient) {
|
|
|
6583
6504
|
}
|
|
6584
6505
|
|
|
6585
6506
|
// src/runtime-kernel/graph-engine/executor.ts
|
|
6586
|
-
var
|
|
6507
|
+
var logger5 = new Logger("GraphAgentExecutor");
|
|
6587
6508
|
var GraphAgentExecutor = class {
|
|
6588
6509
|
llmCaller;
|
|
6589
6510
|
toolRuntime;
|
|
6590
6511
|
contextBuilder;
|
|
6591
|
-
cloudQuotaFallbackModelId;
|
|
6592
6512
|
modelResolver;
|
|
6593
6513
|
modelCatalog;
|
|
6594
6514
|
telemetryPort;
|
|
@@ -6600,7 +6520,6 @@ var GraphAgentExecutor = class {
|
|
|
6600
6520
|
this.llmCaller = dependencies.llmCaller;
|
|
6601
6521
|
this.toolRuntime = dependencies.toolRuntime;
|
|
6602
6522
|
this.contextBuilder = dependencies.contextBuilder;
|
|
6603
|
-
this.cloudQuotaFallbackModelId = readNonEmptyString3(dependencies.cloudQuotaFallbackModelId);
|
|
6604
6523
|
this.modelCatalog = dependencies.modelCatalog ?? createEmptyModelCatalog();
|
|
6605
6524
|
this.modelResolver = dependencies.modelResolver ?? new ModelResolver({
|
|
6606
6525
|
modelCatalog: this.modelCatalog
|
|
@@ -6617,8 +6536,7 @@ var GraphAgentExecutor = class {
|
|
|
6617
6536
|
createPrepareCallStage({
|
|
6618
6537
|
modelResolver: this.modelResolver,
|
|
6619
6538
|
modelCatalog: this.modelCatalog,
|
|
6620
|
-
toolCatalog: this.toolRuntime
|
|
6621
|
-
cloudQuotaFallbackModelId: this.cloudQuotaFallbackModelId
|
|
6539
|
+
toolCatalog: this.toolRuntime
|
|
6622
6540
|
}),
|
|
6623
6541
|
createBuildContextStage({
|
|
6624
6542
|
contextBuilder: this.contextBuilder
|
|
@@ -6640,7 +6558,7 @@ var GraphAgentExecutor = class {
|
|
|
6640
6558
|
}),
|
|
6641
6559
|
createBuildDecisionStage()
|
|
6642
6560
|
];
|
|
6643
|
-
this.middlewares = [llmTelemetryMiddleware
|
|
6561
|
+
this.middlewares = [llmTelemetryMiddleware];
|
|
6644
6562
|
}
|
|
6645
6563
|
async tick(input, eventHandler) {
|
|
6646
6564
|
const ctx = {
|
|
@@ -6665,7 +6583,7 @@ var GraphAgentExecutor = class {
|
|
|
6665
6583
|
audit: this.auditPort,
|
|
6666
6584
|
tokenizer: this.tokenizer
|
|
6667
6585
|
};
|
|
6668
|
-
|
|
6586
|
+
logger5.info("[GraphAgentExecutor] tick \u8C03\u7528", {
|
|
6669
6587
|
stream: input.stream === true,
|
|
6670
6588
|
hasEventHandler: Boolean(eventHandler),
|
|
6671
6589
|
hasSummarizationCallbacks: Boolean(input.summarizationCallbacks)
|
|
@@ -7688,7 +7606,7 @@ var LlmNodeEventBridge = class {
|
|
|
7688
7606
|
};
|
|
7689
7607
|
|
|
7690
7608
|
// src/runtime-kernel/graph-engine/nodes/llmNode.ts
|
|
7691
|
-
var
|
|
7609
|
+
var logger6 = new Logger("LlmNode");
|
|
7692
7610
|
var LlmNode = class {
|
|
7693
7611
|
id = "llm";
|
|
7694
7612
|
reasoner;
|
|
@@ -7697,7 +7615,7 @@ var LlmNode = class {
|
|
|
7697
7615
|
}
|
|
7698
7616
|
async run(state) {
|
|
7699
7617
|
const local = state.local ?? {};
|
|
7700
|
-
|
|
7618
|
+
logger6.info("[LlmNode] \u5F00\u59CB\u6267\u884C LLM \u8282\u70B9", {
|
|
7701
7619
|
localKeys: Object.keys(local)
|
|
7702
7620
|
});
|
|
7703
7621
|
const graphLocal = readGraphAgentLocal(state.local);
|
|
@@ -7712,12 +7630,12 @@ var LlmNode = class {
|
|
|
7712
7630
|
signal,
|
|
7713
7631
|
history
|
|
7714
7632
|
} = graphLocal;
|
|
7715
|
-
|
|
7633
|
+
logger6.info("[LlmNode] \u5DF2\u52A0\u8F7D\u5386\u53F2\u4E8B\u4EF6", {
|
|
7716
7634
|
historyCount: history.length,
|
|
7717
7635
|
hasSummarizationCallbacks: Boolean(summarizationCallbacks)
|
|
7718
7636
|
});
|
|
7719
7637
|
if (!request) {
|
|
7720
|
-
|
|
7638
|
+
logger6.warn("Request object is missing, yielding.");
|
|
7721
7639
|
return { kind: "yield", events: [] };
|
|
7722
7640
|
}
|
|
7723
7641
|
const turnId = requireRuntimeIdentity(graphLocal.turnId, "turnId");
|
|
@@ -7810,12 +7728,12 @@ var LlmNode = class {
|
|
|
7810
7728
|
...nodeState.streamRuntimeEvents,
|
|
7811
7729
|
...contextUsageEvent ? [contextUsageEvent] : []
|
|
7812
7730
|
];
|
|
7813
|
-
|
|
7731
|
+
logger6.info("[LlmNode] \u5386\u53F2\u4E8B\u4EF6\u5DF2\u66F4\u65B0", {
|
|
7814
7732
|
previousCount: history.length,
|
|
7815
7733
|
nextCount: patch.history.length,
|
|
7816
7734
|
streamedEventCount: nodeState.streamRuntimeEvents.length
|
|
7817
7735
|
});
|
|
7818
|
-
|
|
7736
|
+
logger6.info("[LlmNode] \u6267\u884C\u5668\u51B3\u7B56\u5B8C\u6210", {
|
|
7819
7737
|
decisionKind: decision.kind,
|
|
7820
7738
|
emittedEventCount: combinedEvents.length
|
|
7821
7739
|
});
|
|
@@ -7837,7 +7755,7 @@ var LlmNode = class {
|
|
|
7837
7755
|
}
|
|
7838
7756
|
case "error": {
|
|
7839
7757
|
const { name, message, stack } = decision.error;
|
|
7840
|
-
|
|
7758
|
+
logger6.error("[LlmNode] Executor returned an error", { name, message, stack });
|
|
7841
7759
|
return { kind: "yield", events: combinedEvents };
|
|
7842
7760
|
}
|
|
7843
7761
|
default: {
|
|
@@ -7943,7 +7861,7 @@ async function resolveToolModelInput(input) {
|
|
|
7943
7861
|
}
|
|
7944
7862
|
|
|
7945
7863
|
// src/runtime-kernel/graph-engine/nodes/toolNode.finalAnswerProjector.ts
|
|
7946
|
-
function
|
|
7864
|
+
function readNonEmptyString4(value) {
|
|
7947
7865
|
if (typeof value !== "string") {
|
|
7948
7866
|
return void 0;
|
|
7949
7867
|
}
|
|
@@ -7951,7 +7869,7 @@ function readNonEmptyString5(value) {
|
|
|
7951
7869
|
return normalized.length > 0 ? normalized : void 0;
|
|
7952
7870
|
}
|
|
7953
7871
|
function resolveFinalAnswerFromToolControl(finalAnswer) {
|
|
7954
|
-
return
|
|
7872
|
+
return readNonEmptyString4(finalAnswer);
|
|
7955
7873
|
}
|
|
7956
7874
|
|
|
7957
7875
|
// src/runtime-kernel/graph-engine/nodes/toolNode.helpers.ts
|
|
@@ -8207,7 +8125,7 @@ function buildErrorLocalState(params) {
|
|
|
8207
8125
|
}
|
|
8208
8126
|
|
|
8209
8127
|
// src/runtime-kernel/tools/argNormalizer.ts
|
|
8210
|
-
var
|
|
8128
|
+
var logger7 = new Logger("ToolArgNormalizer");
|
|
8211
8129
|
function isRecord10(v) {
|
|
8212
8130
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
8213
8131
|
}
|
|
@@ -8227,7 +8145,7 @@ function joinPath(basePath, segment) {
|
|
|
8227
8145
|
function logJsonEncodedNormalization(expectedType, options) {
|
|
8228
8146
|
const toolPrefix = options.toolName ? `${options.toolName}.` : "";
|
|
8229
8147
|
const path = options.path ?? "<root>";
|
|
8230
|
-
|
|
8148
|
+
logger7.warn("normalized JSON-encoded tool argument", {
|
|
8231
8149
|
expectedType,
|
|
8232
8150
|
path: `${toolPrefix}${path}`
|
|
8233
8151
|
});
|
|
@@ -8397,7 +8315,6 @@ var TOOL_CONTEXT_RUNTIME_RESERVED_KEYS = [
|
|
|
8397
8315
|
"conversationView",
|
|
8398
8316
|
"userQuery",
|
|
8399
8317
|
"modelId",
|
|
8400
|
-
"activeModelId",
|
|
8401
8318
|
"conversationId",
|
|
8402
8319
|
"turnId",
|
|
8403
8320
|
"runId",
|
|
@@ -8584,7 +8501,7 @@ function stripRuntimeReservedToolContextPatch(patch) {
|
|
|
8584
8501
|
}
|
|
8585
8502
|
|
|
8586
8503
|
// src/runtime-kernel/graph-engine/nodes/toolNode.eventBridge.ts
|
|
8587
|
-
var
|
|
8504
|
+
var logger8 = new Logger("ToolNode");
|
|
8588
8505
|
var ToolNodeEventBridge = class {
|
|
8589
8506
|
constructor(deps) {
|
|
8590
8507
|
this.deps = deps;
|
|
@@ -8606,7 +8523,7 @@ var ToolNodeEventBridge = class {
|
|
|
8606
8523
|
status,
|
|
8607
8524
|
payload: { ...payload }
|
|
8608
8525
|
};
|
|
8609
|
-
|
|
8526
|
+
logger8.info("[ToolNode] \u53D1\u51FA tool_process \u4E8B\u4EF6", {
|
|
8610
8527
|
phase,
|
|
8611
8528
|
status,
|
|
8612
8529
|
toolName: this.deps.toolName,
|
|
@@ -8646,7 +8563,7 @@ var ToolNodeEventBridge = class {
|
|
|
8646
8563
|
const answerId = generateAnswerSegmentId();
|
|
8647
8564
|
const id = answerId;
|
|
8648
8565
|
const timestamp = Date.now();
|
|
8649
|
-
|
|
8566
|
+
logger8.info("[ToolNode] \u5DE5\u5177\u8F93\u51FA\u6620\u5C04\u4E3A final_answer", {
|
|
8650
8567
|
sourceToolName: params.sourceToolName,
|
|
8651
8568
|
toolCallId: this.deps.toolCallId,
|
|
8652
8569
|
conversationId: this.deps.conversationId,
|
|
@@ -8704,7 +8621,7 @@ var ToolNodeEventBridge = class {
|
|
|
8704
8621
|
};
|
|
8705
8622
|
|
|
8706
8623
|
// src/runtime-kernel/graph-engine/nodes/toolNode.executionSetup.ts
|
|
8707
|
-
var
|
|
8624
|
+
var logger9 = new Logger("ToolNode");
|
|
8708
8625
|
function parseToolArgs(call) {
|
|
8709
8626
|
const rawArguments = typeof call.function?.arguments === "string" ? call.function.arguments : "";
|
|
8710
8627
|
if (!rawArguments.trim()) {
|
|
@@ -8724,19 +8641,13 @@ function parseToolArgs(call) {
|
|
|
8724
8641
|
return { ok: true, value: parsed };
|
|
8725
8642
|
} catch (error) {
|
|
8726
8643
|
const reason = error instanceof Error ? error.message : "Unknown JSON parse error";
|
|
8727
|
-
|
|
8644
|
+
logger9.warn("failed to parse tool arguments", { error });
|
|
8728
8645
|
return {
|
|
8729
8646
|
ok: false,
|
|
8730
8647
|
error: `Tool arguments are not valid JSON: ${reason}`
|
|
8731
8648
|
};
|
|
8732
8649
|
}
|
|
8733
8650
|
}
|
|
8734
|
-
function readRunLockedModelId(local) {
|
|
8735
|
-
const executorLocal = local.executorLocal;
|
|
8736
|
-
if (!isRecord9(executorLocal)) return void 0;
|
|
8737
|
-
const lockedModelId = executorLocal.runLockedModelId;
|
|
8738
|
-
return typeof lockedModelId === "string" && lockedModelId.trim() ? lockedModelId : void 0;
|
|
8739
|
-
}
|
|
8740
8651
|
function prepareToolNodeContext(state) {
|
|
8741
8652
|
const local = state.local || {};
|
|
8742
8653
|
const toolContext = isRecord9(local.toolContext) ? local.toolContext : {};
|
|
@@ -8754,7 +8665,6 @@ function prepareToolNodeContext(state) {
|
|
|
8754
8665
|
}
|
|
8755
8666
|
});
|
|
8756
8667
|
attachWorkingHistoryView({ state, toolContext });
|
|
8757
|
-
toolContext.activeModelId = readRunLockedModelId(local) ?? toolContext.modelId;
|
|
8758
8668
|
return {
|
|
8759
8669
|
state,
|
|
8760
8670
|
local,
|
|
@@ -9125,7 +9035,7 @@ async function claimPendingUserInputs(state, result) {
|
|
|
9125
9035
|
}
|
|
9126
9036
|
|
|
9127
9037
|
// src/runtime-kernel/graph-engine/nodes/toolNode.ts
|
|
9128
|
-
var
|
|
9038
|
+
var logger10 = new Logger("ToolNode");
|
|
9129
9039
|
function isAbortSignal(value) {
|
|
9130
9040
|
return value !== null && typeof value === "object" && "aborted" in value;
|
|
9131
9041
|
}
|
|
@@ -9338,7 +9248,7 @@ var ToolNode = class {
|
|
|
9338
9248
|
throw abortError;
|
|
9339
9249
|
}
|
|
9340
9250
|
const prepared = prepareToolNodeContext(state);
|
|
9341
|
-
|
|
9251
|
+
logger10.info("[ToolNode] \u5F00\u59CB\u6267\u884C\u5DE5\u5177\u8282\u70B9", {
|
|
9342
9252
|
conversationId: prepared.conversationId,
|
|
9343
9253
|
turnId: prepared.turnId,
|
|
9344
9254
|
pendingCallCount: calls.length
|
|
@@ -9353,7 +9263,7 @@ var ToolNode = class {
|
|
|
9353
9263
|
toolCatalog: this.toolRuntime
|
|
9354
9264
|
});
|
|
9355
9265
|
if (!execution) {
|
|
9356
|
-
|
|
9266
|
+
logger10.warn("no tool name found in call");
|
|
9357
9267
|
return { kind: "yield", events: [] };
|
|
9358
9268
|
}
|
|
9359
9269
|
if (typeof execution.protocolError === "string") {
|
|
@@ -9393,7 +9303,7 @@ var ToolNode = class {
|
|
|
9393
9303
|
call,
|
|
9394
9304
|
context: prepared.toolContext,
|
|
9395
9305
|
abortGraceMs: this.abortGraceMs,
|
|
9396
|
-
onAbandon: () =>
|
|
9306
|
+
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", {
|
|
9397
9307
|
toolName: execution.toolName,
|
|
9398
9308
|
toolCallId: execution.toolCallId,
|
|
9399
9309
|
conversationId: prepared.conversationId,
|
|
@@ -9563,7 +9473,7 @@ var ToolNode = class {
|
|
|
9563
9473
|
runtimeEvents: context.bridge.getRuntimeEvents()
|
|
9564
9474
|
});
|
|
9565
9475
|
if (control?.terminateRun) {
|
|
9566
|
-
|
|
9476
|
+
logger10.info("[ToolNode] \u6536\u5230 control.terminateRun\uFF0C\u6267\u884C\u5B8C\u5DE5\u5177\u540E\u76F4\u63A5 yield \u7ED3\u675F\u672C\u8F6E run", {
|
|
9567
9477
|
toolName: context.toolName,
|
|
9568
9478
|
toolCallId: context.toolCallId,
|
|
9569
9479
|
conversationId: context.conversationId,
|
|
@@ -9572,7 +9482,7 @@ var ToolNode = class {
|
|
|
9572
9482
|
return { kind: "yield", events: context.bridge.getRuntimeEvents() };
|
|
9573
9483
|
}
|
|
9574
9484
|
if (remainingCalls.length === 0 && context.local.toolBatchCompletionMode === "yield_after_batch") {
|
|
9575
|
-
|
|
9485
|
+
logger10.info("[ToolNode] \u5DE5\u5177\u6279\u6B21\u5DF2\u7ED3\u7B97\uFF0C\u6309 Host \u7B56\u7565\u76F4\u63A5 yield", {
|
|
9576
9486
|
toolName: context.toolName,
|
|
9577
9487
|
toolCallId: context.toolCallId,
|
|
9578
9488
|
conversationId: context.conversationId,
|
|
@@ -10019,8 +9929,9 @@ var executor = zod.z.object({
|
|
|
10019
9929
|
lastStepsHintThreshold: counter.optional(),
|
|
10020
9930
|
systemReminderPolicy: AgentSpecSystemReminderPolicy.optional(),
|
|
10021
9931
|
toolObservationPolicy: AgentSpecToolObservationGovernancePolicy.optional(),
|
|
9932
|
+
// 已删除字段:0.45 及更早的 checkpoint 可能带 lastSuccessfulLlmModelId,0.46 及更早的可能带云端额度兜底留下的
|
|
9933
|
+
// runLockedModelId;照常接受,读入时丢弃(兜底已移除,恢复后按请求的模型继续)。
|
|
10022
9934
|
runLockedModelId: zod.z.string().optional(),
|
|
10023
|
-
// 0.45 及更早的 checkpoint 可能带这个已删除字段;照常接受,读入时丢弃。
|
|
10024
9935
|
lastSuccessfulLlmModelId: zod.z.string().optional(),
|
|
10025
9936
|
llmInvocationKind: zod.z.enum(["user_initiated", "continuation"]).optional(),
|
|
10026
9937
|
llmInvocationCount: counter.optional(),
|
|
@@ -10030,7 +9941,7 @@ var executor = zod.z.object({
|
|
|
10030
9941
|
committedCount: counter,
|
|
10031
9942
|
lastCommittedFingerprint: zod.z.string().optional()
|
|
10032
9943
|
}).strict().optional()
|
|
10033
|
-
}).strict().transform(({ lastSuccessfulLlmModelId: _retired, ...state }) => state);
|
|
9944
|
+
}).strict().transform(({ lastSuccessfulLlmModelId: _retired, runLockedModelId: _retiredLock, ...state }) => state);
|
|
10034
9945
|
var checkpoint = zod.z.object({
|
|
10035
9946
|
nodeId: zod.z.string().min(1),
|
|
10036
9947
|
schemaVersion: zod.z.literal(ENGINE_STATE_SCHEMA_VERSION).optional(),
|
|
@@ -10344,7 +10255,7 @@ __export(execution_exports, {
|
|
|
10344
10255
|
});
|
|
10345
10256
|
|
|
10346
10257
|
// src/runtime-kernel/execution/event-bus.ts
|
|
10347
|
-
var
|
|
10258
|
+
var logger11 = new Logger("EventBus");
|
|
10348
10259
|
var TypedEventEmitter = class {
|
|
10349
10260
|
listeners = /* @__PURE__ */ new Map();
|
|
10350
10261
|
maxListeners = 10;
|
|
@@ -10352,7 +10263,7 @@ var TypedEventEmitter = class {
|
|
|
10352
10263
|
const listeners = this.getListeners(event);
|
|
10353
10264
|
listeners.add(listener);
|
|
10354
10265
|
if (listeners.size > this.maxListeners) {
|
|
10355
|
-
|
|
10266
|
+
logger11.warn("EventBus listener count exceeds configured max", {
|
|
10356
10267
|
event: String(event),
|
|
10357
10268
|
count: listeners.size,
|
|
10358
10269
|
maxListeners: this.maxListeners
|
|
@@ -10412,7 +10323,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10412
10323
|
super();
|
|
10413
10324
|
this.executionId = executionId;
|
|
10414
10325
|
this.setMaxListeners(30);
|
|
10415
|
-
|
|
10326
|
+
logger11.info(`EventBus created for execution ${this.executionId}`);
|
|
10416
10327
|
}
|
|
10417
10328
|
/**
|
|
10418
10329
|
* 发布一个事件到总线
|
|
@@ -10421,7 +10332,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10421
10332
|
publish(envelope) {
|
|
10422
10333
|
if (envelope.trace.execution_id !== this.executionId) {
|
|
10423
10334
|
const error = new Error("EventEnvelope execution_id does not match EventBus instance.");
|
|
10424
|
-
|
|
10335
|
+
logger11.error("Mismatched execution_id", {
|
|
10425
10336
|
busExecutionId: this.executionId,
|
|
10426
10337
|
eventExecutionId: envelope.trace.execution_id,
|
|
10427
10338
|
eventSeq: envelope.seq
|
|
@@ -10433,7 +10344,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10433
10344
|
const error = new Error(
|
|
10434
10345
|
"EventBus only accepts RuntimeEvent with formal run routing identity."
|
|
10435
10346
|
);
|
|
10436
|
-
|
|
10347
|
+
logger11.error("RuntimeEvent is missing formal run routing identity", {
|
|
10437
10348
|
executionId: this.executionId,
|
|
10438
10349
|
eventId: envelope.payload.id,
|
|
10439
10350
|
eventType: envelope.payload.type
|
|
@@ -10447,14 +10358,14 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10447
10358
|
* 关闭总线,清理所有监听器
|
|
10448
10359
|
*/
|
|
10449
10360
|
close() {
|
|
10450
|
-
|
|
10361
|
+
logger11.info(`Closing EventBus for execution ${this.executionId}`);
|
|
10451
10362
|
this.emit("close");
|
|
10452
10363
|
this.removeAllListeners();
|
|
10453
10364
|
}
|
|
10454
10365
|
};
|
|
10455
10366
|
|
|
10456
10367
|
// src/runtime-kernel/execution/sequencer.ts
|
|
10457
|
-
var
|
|
10368
|
+
var logger12 = new Logger("EventSequencer");
|
|
10458
10369
|
var EventSequencer = class {
|
|
10459
10370
|
executionId;
|
|
10460
10371
|
traceId;
|
|
@@ -10462,7 +10373,7 @@ var EventSequencer = class {
|
|
|
10462
10373
|
constructor(conversationId, traceId) {
|
|
10463
10374
|
this.executionId = generateExecutionId();
|
|
10464
10375
|
this.traceId = traceId || generateTraceId();
|
|
10465
|
-
|
|
10376
|
+
logger12.info(`EventSequencer created for conversation ${conversationId}`, {
|
|
10466
10377
|
executionId: this.executionId,
|
|
10467
10378
|
traceId: this.traceId
|
|
10468
10379
|
});
|
|
@@ -11320,7 +11231,7 @@ var ThoughtStreamSegmenter = class {
|
|
|
11320
11231
|
};
|
|
11321
11232
|
|
|
11322
11233
|
// src/runtime-kernel/llm/streaming-adapter.ts
|
|
11323
|
-
var
|
|
11234
|
+
var logger13 = new Logger("LlmCaller");
|
|
11324
11235
|
var CanonicalInferenceFailureError = class extends Error {
|
|
11325
11236
|
errorCode;
|
|
11326
11237
|
recoverable;
|
|
@@ -11544,7 +11455,7 @@ async function callLlmStream(params) {
|
|
|
11544
11455
|
} catch (error) {
|
|
11545
11456
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
11546
11457
|
if (normalized.name === "AbortError") {
|
|
11547
|
-
|
|
11458
|
+
logger13.info("Canonical inference \u6536\u5230\u53D6\u6D88\u7EC8\u6001\uFF0C\u4E0D\u53D1\u5E03\u666E\u901A error event", { modelId });
|
|
11548
11459
|
throw normalized;
|
|
11549
11460
|
}
|
|
11550
11461
|
const classification = ErrorClassifier.classify(normalized, {
|
|
@@ -11620,7 +11531,7 @@ var LlmRetryEpisode = class {
|
|
|
11620
11531
|
};
|
|
11621
11532
|
|
|
11622
11533
|
// src/runtime-kernel/llm/retry-fallback-routing.ts
|
|
11623
|
-
var
|
|
11534
|
+
var logger14 = new Logger("LlmCaller");
|
|
11624
11535
|
function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement, fallbackObserver, error, evaluateFallbackPromptCapacity2) {
|
|
11625
11536
|
deps.modelCatalog.getModelById(activeModelId);
|
|
11626
11537
|
const policyDecision = deps.policyEngine.decideOnError(error, {
|
|
@@ -11650,81 +11561,16 @@ function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement
|
|
|
11650
11561
|
reason: "no_eligible_fallback_candidate",
|
|
11651
11562
|
requiredPlacements: requirement.placements
|
|
11652
11563
|
});
|
|
11653
|
-
|
|
11564
|
+
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");
|
|
11654
11565
|
return null;
|
|
11655
11566
|
}
|
|
11656
|
-
|
|
11567
|
+
logger14.warn("Policy \u5207\u6362\u6A21\u578B\u7EE7\u7EED", {
|
|
11657
11568
|
reason: policyDecision.reason,
|
|
11658
11569
|
activeModelId,
|
|
11659
11570
|
fallbackModelId
|
|
11660
11571
|
});
|
|
11661
11572
|
return fallbackModelId;
|
|
11662
11573
|
}
|
|
11663
|
-
function tryCloudQuotaFallback({
|
|
11664
|
-
deps,
|
|
11665
|
-
activeModelId,
|
|
11666
|
-
options,
|
|
11667
|
-
excludedModelIds,
|
|
11668
|
-
requirement,
|
|
11669
|
-
error,
|
|
11670
|
-
fallbackObserver,
|
|
11671
|
-
evaluateFallbackPromptCapacity: evaluateFallbackPromptCapacity2
|
|
11672
|
-
}) {
|
|
11673
|
-
const fallbackModelId = options.cloud_quota_fallback_model_id;
|
|
11674
|
-
if (!fallbackModelId || !ErrorClassifier.isCloudQuotaError(error) || excludedModelIds.has(fallbackModelId)) {
|
|
11675
|
-
return null;
|
|
11676
|
-
}
|
|
11677
|
-
const fallbackConfig = deps.modelCatalog.getModelById(fallbackModelId);
|
|
11678
|
-
if (!fallbackConfig?.api_key) {
|
|
11679
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11680
|
-
fromModelId: activeModelId,
|
|
11681
|
-
candidateModelId: fallbackModelId,
|
|
11682
|
-
policy: "cloud-quota",
|
|
11683
|
-
reason: "fallback_model_unavailable",
|
|
11684
|
-
requiredPlacements: requirement.placements
|
|
11685
|
-
});
|
|
11686
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\u76EE\u6807\u4E0D\u53EF\u7528\uFF08\u672A\u6CE8\u518C\u6216\u7F3A\u5C11 API Key\uFF09", { fallbackModelId });
|
|
11687
|
-
return null;
|
|
11688
|
-
}
|
|
11689
|
-
const compatibility = evaluateModelInputCompatibility(fallbackConfig, requirement);
|
|
11690
|
-
if (!compatibility.compatible) {
|
|
11691
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11692
|
-
fromModelId: activeModelId,
|
|
11693
|
-
candidateModelId: fallbackModelId,
|
|
11694
|
-
policy: "cloud-quota",
|
|
11695
|
-
reason: compatibility.reason,
|
|
11696
|
-
requiredPlacements: requirement.placements
|
|
11697
|
-
});
|
|
11698
|
-
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", {
|
|
11699
|
-
fallbackModelId,
|
|
11700
|
-
requiredPlacements: requirement.placements,
|
|
11701
|
-
reason: compatibility.reason
|
|
11702
|
-
});
|
|
11703
|
-
return null;
|
|
11704
|
-
}
|
|
11705
|
-
const capacityAdmission = evaluateFallbackPromptCapacity2?.(fallbackModelId);
|
|
11706
|
-
if (capacityAdmission && !capacityAdmission.admitted) {
|
|
11707
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11708
|
-
fromModelId: activeModelId,
|
|
11709
|
-
candidateModelId: fallbackModelId,
|
|
11710
|
-
policy: "cloud-quota",
|
|
11711
|
-
reason: capacityAdmission.reason,
|
|
11712
|
-
requiredPlacements: requirement.placements
|
|
11713
|
-
});
|
|
11714
|
-
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", {
|
|
11715
|
-
fallbackModelId,
|
|
11716
|
-
reason: capacityAdmission.reason
|
|
11717
|
-
});
|
|
11718
|
-
return null;
|
|
11719
|
-
}
|
|
11720
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\uFF08run \u5185\u7EED\u8DD1\uFF09", {
|
|
11721
|
-
activeModelId,
|
|
11722
|
-
fallbackModelId,
|
|
11723
|
-
reason: error.message
|
|
11724
|
-
});
|
|
11725
|
-
fallbackObserver?.onCloudQuotaFallbackApplied?.(fallbackModelId);
|
|
11726
|
-
return fallbackModelId;
|
|
11727
|
-
}
|
|
11728
11574
|
|
|
11729
11575
|
// src/runtime-kernel/llm/usage-telemetry.ts
|
|
11730
11576
|
async function callPlainCompletion(inferencePort, modelId, messages, options = {}, signal, traceId) {
|
|
@@ -11847,7 +11693,7 @@ var LlmImageInputError = class extends Error {
|
|
|
11847
11693
|
};
|
|
11848
11694
|
|
|
11849
11695
|
// src/runtime-kernel/llm/retry-fallback.ts
|
|
11850
|
-
var
|
|
11696
|
+
var logger15 = new Logger("LlmCaller");
|
|
11851
11697
|
async function callWithRetryFallback(params) {
|
|
11852
11698
|
const {
|
|
11853
11699
|
deps,
|
|
@@ -11875,11 +11721,9 @@ async function callWithRetryFallback(params) {
|
|
|
11875
11721
|
const retryEpisode = new LlmRetryEpisode(traceId, eventHandler);
|
|
11876
11722
|
let previousAttemptTracker;
|
|
11877
11723
|
if (!clientRetryEnabled) {
|
|
11878
|
-
|
|
11879
|
-
logger16.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
11724
|
+
logger15.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
11880
11725
|
modelId,
|
|
11881
|
-
|
|
11882
|
-
reason: options.retry_policy === "none" ? "options.retry_policy=none" : "model config (cloud billing or enable_client_retry=false)"
|
|
11726
|
+
reason: options.retry_policy === "none" ? "options.retry_policy=none" : "model config enable_client_retry=false"
|
|
11883
11727
|
});
|
|
11884
11728
|
}
|
|
11885
11729
|
try {
|
|
@@ -11915,7 +11759,7 @@ async function callWithRetryFallback(params) {
|
|
|
11915
11759
|
}) : void 0;
|
|
11916
11760
|
try {
|
|
11917
11761
|
if (isRetry) {
|
|
11918
|
-
|
|
11762
|
+
logger15.info("LLM \u8C03\u7528\u91CD\u8BD5", { attempt, configuredMaxRetries });
|
|
11919
11763
|
}
|
|
11920
11764
|
actualAttempts++;
|
|
11921
11765
|
retryEpisode.retrying(actualAttempts);
|
|
@@ -11944,7 +11788,7 @@ async function callWithRetryFallback(params) {
|
|
|
11944
11788
|
if (deps.retryConfig.enableEmptyResponseRetry && !responseContent?.trim() && !toolCallsFromLLM?.length) {
|
|
11945
11789
|
throw new Error("LLM\u8FD4\u56DE\u4E86\u7A7A\u54CD\u5E94");
|
|
11946
11790
|
}
|
|
11947
|
-
|
|
11791
|
+
logger15.debug("LLM \u8C03\u7528\u6210\u529F", { attempts: actualAttempts, maxTotalAttempts });
|
|
11948
11792
|
if (attemptContextUsage) {
|
|
11949
11793
|
fallbackObserver?.onLlmAttemptSucceeded?.(activeModelId, attemptContextUsage);
|
|
11950
11794
|
} else {
|
|
@@ -11955,7 +11799,7 @@ async function callWithRetryFallback(params) {
|
|
|
11955
11799
|
} catch (error) {
|
|
11956
11800
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
11957
11801
|
if (lastError.name === "AbortError") {
|
|
11958
|
-
|
|
11802
|
+
logger15.info("LLM \u8C03\u7528\u5DF2\u53D6\u6D88\uFF0C\u4E0D\u8FDB\u5165 provider failure \u5206\u7C7B\u4E0E\u91CD\u8BD5\u6D41\u7A0B", {
|
|
11959
11803
|
attempt: attempt + 1,
|
|
11960
11804
|
actualAttempts,
|
|
11961
11805
|
maxTotalAttempts,
|
|
@@ -11974,7 +11818,7 @@ async function callWithRetryFallback(params) {
|
|
|
11974
11818
|
total_attempts: actualAttempts,
|
|
11975
11819
|
error_code: classification.errorCode
|
|
11976
11820
|
};
|
|
11977
|
-
|
|
11821
|
+
logger15.error("LLM \u8C03\u7528\u5931\u8D25", {
|
|
11978
11822
|
attempt: attempt + 1,
|
|
11979
11823
|
maxAttempts: currentMaxRetries + 1,
|
|
11980
11824
|
actualAttempts,
|
|
@@ -11983,7 +11827,7 @@ async function callWithRetryFallback(params) {
|
|
|
11983
11827
|
});
|
|
11984
11828
|
previousAttemptTracker = attemptTracker;
|
|
11985
11829
|
if (!hasLlmAttemptBudgetRemaining({ actualAttempts, maxTotalAttempts })) {
|
|
11986
|
-
|
|
11830
|
+
logger15.error("\u5DF2\u8FBE\u5230 LLM \u603B\u8C03\u7528\u6B21\u6570\u4E0A\u9650\uFF0C\u505C\u6B62\u91CD\u8BD5/\u5207\u6A21\u578B", {
|
|
11987
11831
|
actualAttempts,
|
|
11988
11832
|
maxTotalAttempts
|
|
11989
11833
|
});
|
|
@@ -12013,37 +11857,15 @@ async function callWithRetryFallback(params) {
|
|
|
12013
11857
|
attempt -= 1;
|
|
12014
11858
|
continue;
|
|
12015
11859
|
}
|
|
12016
|
-
const quotaFallbackModelId = tryCloudQuotaFallback({
|
|
12017
|
-
deps,
|
|
12018
|
-
activeModelId,
|
|
12019
|
-
options,
|
|
12020
|
-
excludedModelIds,
|
|
12021
|
-
requirement,
|
|
12022
|
-
error: lastError,
|
|
12023
|
-
fallbackObserver,
|
|
12024
|
-
evaluateFallbackPromptCapacity: invocationContext?.evaluateFallbackPromptCapacity
|
|
12025
|
-
});
|
|
12026
|
-
if (quotaFallbackModelId) {
|
|
12027
|
-
fallbackObserver?.onModelFallbackApplied?.({
|
|
12028
|
-
fromModelId: activeModelId,
|
|
12029
|
-
toModelId: quotaFallbackModelId,
|
|
12030
|
-
reason: lastError.message,
|
|
12031
|
-
policy: "cloud-quota"
|
|
12032
|
-
});
|
|
12033
|
-
activeModelId = quotaFallbackModelId;
|
|
12034
|
-
excludedModelIds.add(quotaFallbackModelId);
|
|
12035
|
-
attempt -= 1;
|
|
12036
|
-
continue;
|
|
12037
|
-
}
|
|
12038
11860
|
}
|
|
12039
11861
|
if (classification.category === "non_retryable" /* NON_RETRYABLE */) {
|
|
12040
|
-
|
|
11862
|
+
logger15.error("\u9519\u8BEF\u4E0D\u53EF\u91CD\u8BD5\uFF0C\u76F4\u63A5\u5931\u8D25", { reason: classification.reason });
|
|
12041
11863
|
retryEpisode.finish("failed", failedRetryState);
|
|
12042
11864
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
12043
11865
|
throw lastError;
|
|
12044
11866
|
}
|
|
12045
11867
|
if (attempt >= configuredMaxRetries || categoryRetries[category] >= currentMaxRetries) {
|
|
12046
|
-
|
|
11868
|
+
logger15.error("\u5DF2\u8FBE\u5230\u6700\u5927\u91CD\u8BD5\u6B21\u6570\uFF0C\u653E\u5F03\u91CD\u8BD5", { maxRetries: currentMaxRetries });
|
|
12047
11869
|
retryEpisode.finish("exhausted", failedRetryState);
|
|
12048
11870
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
12049
11871
|
throw lastError;
|
|
@@ -12055,9 +11877,9 @@ async function callWithRetryFallback(params) {
|
|
|
12055
11877
|
6e4
|
|
12056
11878
|
);
|
|
12057
11879
|
if (classification.category === "rate_limit" /* RATE_LIMIT */) {
|
|
12058
|
-
|
|
11880
|
+
logger15.warn("\u901F\u7387\u9650\u5236\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
12059
11881
|
} else if (classification.category === "retryable" /* RETRYABLE */) {
|
|
12060
|
-
|
|
11882
|
+
logger15.warn("\u53EF\u91CD\u8BD5\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
12061
11883
|
}
|
|
12062
11884
|
throwIfAborted(signal, "\u5EF6\u8FDF\u7B49\u5F85\u524D\u68C0\u6D4B\u5230\u53D6\u6D88\u4FE1\u53F7\uFF0C\u505C\u6B62\u91CD\u8BD5");
|
|
12063
11885
|
categoryRetries[category] += 1;
|
|
@@ -12094,16 +11916,11 @@ function waitForRetry(delayMs, signal) {
|
|
|
12094
11916
|
}
|
|
12095
11917
|
function isClientRetryEnabledForModel(modelCatalog, modelId, options) {
|
|
12096
11918
|
if (options.retry_policy === "none") return false;
|
|
12097
|
-
|
|
12098
|
-
if (cfg?.billing_mode === "cloud") return false;
|
|
12099
|
-
if (options.retry_policy === "client") return true;
|
|
12100
|
-
if (!cfg) return true;
|
|
12101
|
-
if (cfg.enable_client_retry === false) return false;
|
|
12102
|
-
return true;
|
|
11919
|
+
return modelCatalog.getModelById(modelId)?.enable_client_retry !== false;
|
|
12103
11920
|
}
|
|
12104
11921
|
function throwIfAborted(signal, message) {
|
|
12105
11922
|
if (!signal?.aborted) return;
|
|
12106
|
-
|
|
11923
|
+
logger15.info(message);
|
|
12107
11924
|
const reason = signal.reason;
|
|
12108
11925
|
if (reason instanceof Error && reason.name === "AbortError") throw reason;
|
|
12109
11926
|
const reasonText = typeof reason === "string" && reason.trim().length > 0 ? reason : "stream_interrupted";
|
|
@@ -12421,7 +12238,7 @@ async function recoverChildRunEventsFromCheckpoint(params) {
|
|
|
12421
12238
|
}
|
|
12422
12239
|
|
|
12423
12240
|
// src/runtime-kernel/child-runs/childRunInvoker.ts
|
|
12424
|
-
var
|
|
12241
|
+
var logger16 = new Logger("ChildRunInvoker");
|
|
12425
12242
|
var ChildRunInvoker = class {
|
|
12426
12243
|
modelResolver;
|
|
12427
12244
|
createLlmNode;
|
|
@@ -12463,7 +12280,7 @@ var ChildRunInvoker = class {
|
|
|
12463
12280
|
const resolvedParentRunId = parentRunId ?? parentToolContext.runId;
|
|
12464
12281
|
const depthDecision = decideChildRunDepth({ parentToolContext });
|
|
12465
12282
|
if (!depthDecision.allowed) {
|
|
12466
|
-
|
|
12283
|
+
logger16.warn("child-run \u6DF1\u5EA6\u8D85\u8FC7\u4E0A\u9650\uFF0C\u62D2\u7EDD\u7EE7\u7EED\u9012\u5F52\u6267\u884C", {
|
|
12467
12284
|
runId: childRunId,
|
|
12468
12285
|
parentRunId: resolvedParentRunId,
|
|
12469
12286
|
parentDepth: depthDecision.parentDepth,
|
|
@@ -12480,7 +12297,7 @@ var ChildRunInvoker = class {
|
|
|
12480
12297
|
};
|
|
12481
12298
|
}
|
|
12482
12299
|
if (abortSignal?.aborted || parentToolContext.abortSignal?.aborted) {
|
|
12483
|
-
|
|
12300
|
+
logger16.info("child-run \u5728\u4EFB\u52A1\u63A5\u7EB3\u524D\u5DF2\u53D6\u6D88", {
|
|
12484
12301
|
runId: childRunId,
|
|
12485
12302
|
parentRunId: resolvedParentRunId
|
|
12486
12303
|
});
|
|
@@ -12504,7 +12321,7 @@ var ChildRunInvoker = class {
|
|
|
12504
12321
|
}
|
|
12505
12322
|
const turnId = config.initialInput?.turnId ?? generateTurnId();
|
|
12506
12323
|
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");
|
|
12507
|
-
|
|
12324
|
+
logger16.info(`\u542F\u52A8 child-run: ${agentConfig.id}`, {
|
|
12508
12325
|
conversationId: runtimeConversationId,
|
|
12509
12326
|
checkpointKey: internalCheckpointKey,
|
|
12510
12327
|
maxSteps,
|
|
@@ -12622,7 +12439,7 @@ var ChildRunInvoker = class {
|
|
|
12622
12439
|
);
|
|
12623
12440
|
finalAnswer = extractFinalAnswer(allEvents);
|
|
12624
12441
|
lastProgress = finalAnswer ? void 0 : extractLastProgress(allEvents);
|
|
12625
|
-
|
|
12442
|
+
logger16.info("child-run \u6267\u884C\u5B8C\u6210", {
|
|
12626
12443
|
stepCount,
|
|
12627
12444
|
eventCount: allEvents.length,
|
|
12628
12445
|
hasFinalAnswer: !!finalAnswer,
|
|
@@ -12652,13 +12469,13 @@ var ChildRunInvoker = class {
|
|
|
12652
12469
|
cancelled = abortSignal?.aborted === true || isAbortError2(err);
|
|
12653
12470
|
error = err instanceof Error ? err.message : String(err);
|
|
12654
12471
|
if (cancelled) {
|
|
12655
|
-
|
|
12472
|
+
logger16.info("child-run \u6267\u884C\u53D6\u6D88", {
|
|
12656
12473
|
runId: childRunId,
|
|
12657
12474
|
parentRunId: resolvedParentRunId,
|
|
12658
12475
|
message: error
|
|
12659
12476
|
});
|
|
12660
12477
|
} else {
|
|
12661
|
-
|
|
12478
|
+
logger16.error(
|
|
12662
12479
|
"child-run \u6267\u884C\u5931\u8D25:",
|
|
12663
12480
|
err instanceof Error ? {
|
|
12664
12481
|
name: err.name,
|
|
@@ -12754,7 +12571,7 @@ var ChildRunInvoker = class {
|
|
|
12754
12571
|
function isAbortError2(error) {
|
|
12755
12572
|
return error instanceof Error && error.name === "AbortError";
|
|
12756
12573
|
}
|
|
12757
|
-
function
|
|
12574
|
+
function readNonEmptyString5(value) {
|
|
12758
12575
|
if (typeof value !== "string") {
|
|
12759
12576
|
return void 0;
|
|
12760
12577
|
}
|
|
@@ -12762,7 +12579,7 @@ function readNonEmptyString6(value) {
|
|
|
12762
12579
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
12763
12580
|
}
|
|
12764
12581
|
function resolveChildRunConversationId(params) {
|
|
12765
|
-
const conversationId =
|
|
12582
|
+
const conversationId = readNonEmptyString5(params.explicitConversationId) ?? readNonEmptyString5(params.parentToolContext.conversationId);
|
|
12766
12583
|
if (!conversationId) {
|
|
12767
12584
|
throw new Error(
|
|
12768
12585
|
"ChildRunInvoker requires conversationId from admission or parent ToolContext."
|
|
@@ -12771,7 +12588,7 @@ function resolveChildRunConversationId(params) {
|
|
|
12771
12588
|
return conversationId;
|
|
12772
12589
|
}
|
|
12773
12590
|
function resolveChildRunModelId(params) {
|
|
12774
|
-
const explicitModelId =
|
|
12591
|
+
const explicitModelId = readNonEmptyString5(params.explicitModelId);
|
|
12775
12592
|
if (explicitModelId) {
|
|
12776
12593
|
return explicitModelId;
|
|
12777
12594
|
}
|
|
@@ -13716,7 +13533,7 @@ function runMetaFromRecord(record) {
|
|
|
13716
13533
|
}
|
|
13717
13534
|
|
|
13718
13535
|
// src/runtime-kernel/run-supervisor/functions/awaitingUserWatcher.ts
|
|
13719
|
-
var
|
|
13536
|
+
var logger17 = new Logger("RunSupervisorAwaitingUserWatcher");
|
|
13720
13537
|
function isRecord16(value) {
|
|
13721
13538
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13722
13539
|
}
|
|
@@ -13761,7 +13578,7 @@ function createAwaitingUserWatcher(options) {
|
|
|
13761
13578
|
resumeToken: event.resume_token
|
|
13762
13579
|
}
|
|
13763
13580
|
}).catch((error) => {
|
|
13764
|
-
|
|
13581
|
+
logger17.warn("failed to mark awaiting_user from requires_user_interaction", { error });
|
|
13765
13582
|
});
|
|
13766
13583
|
};
|
|
13767
13584
|
const dispose = () => {
|
|
@@ -15028,7 +14845,7 @@ function createScriptedInferenceHarness(script, options = {}) {
|
|
|
15028
14845
|
}
|
|
15029
14846
|
|
|
15030
14847
|
// src/context-manager/shared/MessageFormatter.ts
|
|
15031
|
-
var
|
|
14848
|
+
var logger18 = new Logger("MessageFormatter");
|
|
15032
14849
|
var MessageFormatter = class {
|
|
15033
14850
|
fenceRegistry;
|
|
15034
14851
|
constructor(options = {}) {
|
|
@@ -15094,12 +14911,12 @@ var MessageFormatter = class {
|
|
|
15094
14911
|
case "context_injection": {
|
|
15095
14912
|
const fenceKind = metadata?.fenceKind;
|
|
15096
14913
|
if (!fenceKind) {
|
|
15097
|
-
|
|
14914
|
+
logger18.warn("context_injection missing metadata.fenceKind, skipping");
|
|
15098
14915
|
return null;
|
|
15099
14916
|
}
|
|
15100
14917
|
const descriptor = fenceRegistry?.get(fenceKind);
|
|
15101
14918
|
if (!descriptor) {
|
|
15102
|
-
|
|
14919
|
+
logger18.warn("fence kind is not registered, skipping", { fenceKind });
|
|
15103
14920
|
return null;
|
|
15104
14921
|
}
|
|
15105
14922
|
return {
|
|
@@ -15138,7 +14955,7 @@ var MessageFormatter = class {
|
|
|
15138
14955
|
case "task_completion":
|
|
15139
14956
|
return { role, content };
|
|
15140
14957
|
default:
|
|
15141
|
-
|
|
14958
|
+
logger18.warn("unhandled message type for chat history, skipping", { type });
|
|
15142
14959
|
return null;
|
|
15143
14960
|
}
|
|
15144
14961
|
}
|
|
@@ -15153,7 +14970,7 @@ zod.z.object({
|
|
|
15153
14970
|
}).strict();
|
|
15154
14971
|
|
|
15155
14972
|
// src/context-manager/profiles/agent/utils/toolOutputSummarizer.ts
|
|
15156
|
-
var
|
|
14973
|
+
var logger20 = new Logger("ToolOutputSummarizer");
|
|
15157
14974
|
var DEFAULT_SUMMARIZER_CONFIG = {
|
|
15158
14975
|
fullContentThreshold: 400,
|
|
15159
14976
|
textPreviewLength: 200,
|
|
@@ -15193,7 +15010,7 @@ var ToolOutputSummarizer = class {
|
|
|
15193
15010
|
return tool.getExecutionSummary(output);
|
|
15194
15011
|
}
|
|
15195
15012
|
} catch (error) {
|
|
15196
|
-
|
|
15013
|
+
logger20.error("tool getExecutionSummary failed", { toolName, error });
|
|
15197
15014
|
}
|
|
15198
15015
|
return null;
|
|
15199
15016
|
}
|
|
@@ -15244,14 +15061,14 @@ var summarizeToolOutput = (toolName, output, toolSummaryProvider, config) => {
|
|
|
15244
15061
|
};
|
|
15245
15062
|
|
|
15246
15063
|
// src/context-manager/profiles/agent/utils/eventConverter.ts
|
|
15247
|
-
var
|
|
15064
|
+
var logger21 = new Logger("AgentEventConverter");
|
|
15248
15065
|
function isHistorySummaryEvent(event) {
|
|
15249
15066
|
return "type" in event && event.type === "history_summary";
|
|
15250
15067
|
}
|
|
15251
15068
|
function convertEventToAiMessage(event) {
|
|
15252
15069
|
if (isHistorySummaryEvent(event)) {
|
|
15253
15070
|
const replacedIds = Array.isArray(event.replaced_message_ids) ? event.replaced_message_ids : [];
|
|
15254
|
-
|
|
15071
|
+
logger21.debug("Converted history_summary RuntimeEvent to AiMessage", {
|
|
15255
15072
|
summaryId: event.id,
|
|
15256
15073
|
replacedCount: replacedIds.length,
|
|
15257
15074
|
summarySeq: event.summary_seq,
|