@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/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,18 +5291,14 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5358
5291
|
"turnId"
|
|
5359
5292
|
],
|
|
5360
5293
|
writes: [
|
|
5361
|
-
"cloudQuotaFallbackAppliedModelId",
|
|
5362
5294
|
"modelFallbackAudit",
|
|
5363
5295
|
"llmCallStartedAt",
|
|
5364
5296
|
"llmResp",
|
|
5365
5297
|
"llmCallDurationMs",
|
|
5366
|
-
"executorLocalPatch",
|
|
5367
5298
|
"contextUsage"
|
|
5368
5299
|
],
|
|
5369
5300
|
async run(ctx) {
|
|
5370
|
-
let cloudQuotaFallbackAppliedModelId;
|
|
5371
5301
|
let modelFallbackAudit;
|
|
5372
|
-
let lastSuccessfulLlmModelId;
|
|
5373
5302
|
let contextUsage;
|
|
5374
5303
|
const modelFallbackRejections = [];
|
|
5375
5304
|
const promptBudget = ctx.promptBudget;
|
|
@@ -5387,11 +5316,7 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5387
5316
|
streamEventHandler,
|
|
5388
5317
|
ctx.signal,
|
|
5389
5318
|
{
|
|
5390
|
-
|
|
5391
|
-
cloudQuotaFallbackAppliedModelId = readNonEmptyString3(fallbackModelId);
|
|
5392
|
-
},
|
|
5393
|
-
onLlmAttemptSucceeded(activeModelId, attemptContextUsage) {
|
|
5394
|
-
lastSuccessfulLlmModelId = readNonEmptyString3(activeModelId);
|
|
5319
|
+
onLlmAttemptSucceeded(_activeModelId, attemptContextUsage) {
|
|
5395
5320
|
contextUsage = attemptContextUsage;
|
|
5396
5321
|
},
|
|
5397
5322
|
onModelFallbackApplied(info) {
|
|
@@ -5487,12 +5412,10 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5487
5412
|
});
|
|
5488
5413
|
}
|
|
5489
5414
|
return {
|
|
5490
|
-
cloudQuotaFallbackAppliedModelId,
|
|
5491
5415
|
modelFallbackAudit,
|
|
5492
5416
|
llmCallStartedAt,
|
|
5493
5417
|
llmResp,
|
|
5494
5418
|
llmCallDurationMs,
|
|
5495
|
-
executorLocalPatch: lastSuccessfulLlmModelId ? { lastSuccessfulLlmModelId } : void 0,
|
|
5496
5419
|
contextUsage
|
|
5497
5420
|
};
|
|
5498
5421
|
}
|
|
@@ -6409,18 +6332,16 @@ function createPrepareCallStage(dependencies) {
|
|
|
6409
6332
|
"toolDefinitionTokens"
|
|
6410
6333
|
],
|
|
6411
6334
|
async run(ctx) {
|
|
6412
|
-
const
|
|
6413
|
-
const requestedModelId = lockedRunModelId ?? ctx.request.model_id;
|
|
6335
|
+
const requestedModelId = ctx.request.model_id;
|
|
6414
6336
|
const modelId = dependencies.modelResolver.resolveModelId(requestedModelId);
|
|
6415
6337
|
await emitAuditEnvelope(ctx.audit, {
|
|
6416
6338
|
action: "model.select",
|
|
6417
6339
|
actor: { kind: "system" },
|
|
6418
6340
|
decision: {
|
|
6419
6341
|
outcome: "recorded",
|
|
6420
|
-
reason:
|
|
6342
|
+
reason: requestedModelId ? "request model id" : "default model resolver",
|
|
6421
6343
|
metadata: {
|
|
6422
6344
|
requestedModelId,
|
|
6423
|
-
lockedRunModelId,
|
|
6424
6345
|
selectedModelId: modelId
|
|
6425
6346
|
}
|
|
6426
6347
|
},
|
|
@@ -6467,10 +6388,6 @@ function createPrepareCallStage(dependencies) {
|
|
|
6467
6388
|
if (ctx.executorLocal?.lockRequestedModelId === true) {
|
|
6468
6389
|
llmOptions.allow_model_fallback = false;
|
|
6469
6390
|
}
|
|
6470
|
-
const isRunContinuation = ctx.executorLocal?.llmInvocationKind === "continuation";
|
|
6471
|
-
if (dependencies.cloudQuotaFallbackModelId && modelConfig?.billing_mode === "cloud" && modelId !== dependencies.cloudQuotaFallbackModelId && isRunContinuation && ctx.executorLocal?.lockRequestedModelId !== true) {
|
|
6472
|
-
llmOptions.cloud_quota_fallback_model_id = dependencies.cloudQuotaFallbackModelId;
|
|
6473
|
-
}
|
|
6474
6391
|
const effectiveEffort = resolveEffectiveEffort(
|
|
6475
6392
|
ctx.request.reasoning_effort,
|
|
6476
6393
|
modelConfig?.reasoning
|
|
@@ -6587,12 +6504,11 @@ function applyCalibration(rawLocalTotal, imageInputTokens, coefficient) {
|
|
|
6587
6504
|
}
|
|
6588
6505
|
|
|
6589
6506
|
// src/runtime-kernel/graph-engine/executor.ts
|
|
6590
|
-
var
|
|
6507
|
+
var logger5 = new Logger("GraphAgentExecutor");
|
|
6591
6508
|
var GraphAgentExecutor = class {
|
|
6592
6509
|
llmCaller;
|
|
6593
6510
|
toolRuntime;
|
|
6594
6511
|
contextBuilder;
|
|
6595
|
-
cloudQuotaFallbackModelId;
|
|
6596
6512
|
modelResolver;
|
|
6597
6513
|
modelCatalog;
|
|
6598
6514
|
telemetryPort;
|
|
@@ -6604,7 +6520,6 @@ var GraphAgentExecutor = class {
|
|
|
6604
6520
|
this.llmCaller = dependencies.llmCaller;
|
|
6605
6521
|
this.toolRuntime = dependencies.toolRuntime;
|
|
6606
6522
|
this.contextBuilder = dependencies.contextBuilder;
|
|
6607
|
-
this.cloudQuotaFallbackModelId = readNonEmptyString3(dependencies.cloudQuotaFallbackModelId);
|
|
6608
6523
|
this.modelCatalog = dependencies.modelCatalog ?? createEmptyModelCatalog();
|
|
6609
6524
|
this.modelResolver = dependencies.modelResolver ?? new ModelResolver({
|
|
6610
6525
|
modelCatalog: this.modelCatalog
|
|
@@ -6621,8 +6536,7 @@ var GraphAgentExecutor = class {
|
|
|
6621
6536
|
createPrepareCallStage({
|
|
6622
6537
|
modelResolver: this.modelResolver,
|
|
6623
6538
|
modelCatalog: this.modelCatalog,
|
|
6624
|
-
toolCatalog: this.toolRuntime
|
|
6625
|
-
cloudQuotaFallbackModelId: this.cloudQuotaFallbackModelId
|
|
6539
|
+
toolCatalog: this.toolRuntime
|
|
6626
6540
|
}),
|
|
6627
6541
|
createBuildContextStage({
|
|
6628
6542
|
contextBuilder: this.contextBuilder
|
|
@@ -6644,7 +6558,7 @@ var GraphAgentExecutor = class {
|
|
|
6644
6558
|
}),
|
|
6645
6559
|
createBuildDecisionStage()
|
|
6646
6560
|
];
|
|
6647
|
-
this.middlewares = [llmTelemetryMiddleware
|
|
6561
|
+
this.middlewares = [llmTelemetryMiddleware];
|
|
6648
6562
|
}
|
|
6649
6563
|
async tick(input, eventHandler) {
|
|
6650
6564
|
const ctx = {
|
|
@@ -6669,7 +6583,7 @@ var GraphAgentExecutor = class {
|
|
|
6669
6583
|
audit: this.auditPort,
|
|
6670
6584
|
tokenizer: this.tokenizer
|
|
6671
6585
|
};
|
|
6672
|
-
|
|
6586
|
+
logger5.info("[GraphAgentExecutor] tick \u8C03\u7528", {
|
|
6673
6587
|
stream: input.stream === true,
|
|
6674
6588
|
hasEventHandler: Boolean(eventHandler),
|
|
6675
6589
|
hasSummarizationCallbacks: Boolean(input.summarizationCallbacks)
|
|
@@ -7692,7 +7606,7 @@ var LlmNodeEventBridge = class {
|
|
|
7692
7606
|
};
|
|
7693
7607
|
|
|
7694
7608
|
// src/runtime-kernel/graph-engine/nodes/llmNode.ts
|
|
7695
|
-
var
|
|
7609
|
+
var logger6 = new Logger("LlmNode");
|
|
7696
7610
|
var LlmNode = class {
|
|
7697
7611
|
id = "llm";
|
|
7698
7612
|
reasoner;
|
|
@@ -7701,7 +7615,7 @@ var LlmNode = class {
|
|
|
7701
7615
|
}
|
|
7702
7616
|
async run(state) {
|
|
7703
7617
|
const local = state.local ?? {};
|
|
7704
|
-
|
|
7618
|
+
logger6.info("[LlmNode] \u5F00\u59CB\u6267\u884C LLM \u8282\u70B9", {
|
|
7705
7619
|
localKeys: Object.keys(local)
|
|
7706
7620
|
});
|
|
7707
7621
|
const graphLocal = readGraphAgentLocal(state.local);
|
|
@@ -7716,12 +7630,12 @@ var LlmNode = class {
|
|
|
7716
7630
|
signal,
|
|
7717
7631
|
history
|
|
7718
7632
|
} = graphLocal;
|
|
7719
|
-
|
|
7633
|
+
logger6.info("[LlmNode] \u5DF2\u52A0\u8F7D\u5386\u53F2\u4E8B\u4EF6", {
|
|
7720
7634
|
historyCount: history.length,
|
|
7721
7635
|
hasSummarizationCallbacks: Boolean(summarizationCallbacks)
|
|
7722
7636
|
});
|
|
7723
7637
|
if (!request) {
|
|
7724
|
-
|
|
7638
|
+
logger6.warn("Request object is missing, yielding.");
|
|
7725
7639
|
return { kind: "yield", events: [] };
|
|
7726
7640
|
}
|
|
7727
7641
|
const turnId = requireRuntimeIdentity(graphLocal.turnId, "turnId");
|
|
@@ -7814,12 +7728,12 @@ var LlmNode = class {
|
|
|
7814
7728
|
...nodeState.streamRuntimeEvents,
|
|
7815
7729
|
...contextUsageEvent ? [contextUsageEvent] : []
|
|
7816
7730
|
];
|
|
7817
|
-
|
|
7731
|
+
logger6.info("[LlmNode] \u5386\u53F2\u4E8B\u4EF6\u5DF2\u66F4\u65B0", {
|
|
7818
7732
|
previousCount: history.length,
|
|
7819
7733
|
nextCount: patch.history.length,
|
|
7820
7734
|
streamedEventCount: nodeState.streamRuntimeEvents.length
|
|
7821
7735
|
});
|
|
7822
|
-
|
|
7736
|
+
logger6.info("[LlmNode] \u6267\u884C\u5668\u51B3\u7B56\u5B8C\u6210", {
|
|
7823
7737
|
decisionKind: decision.kind,
|
|
7824
7738
|
emittedEventCount: combinedEvents.length
|
|
7825
7739
|
});
|
|
@@ -7841,7 +7755,7 @@ var LlmNode = class {
|
|
|
7841
7755
|
}
|
|
7842
7756
|
case "error": {
|
|
7843
7757
|
const { name, message, stack } = decision.error;
|
|
7844
|
-
|
|
7758
|
+
logger6.error("[LlmNode] Executor returned an error", { name, message, stack });
|
|
7845
7759
|
return { kind: "yield", events: combinedEvents };
|
|
7846
7760
|
}
|
|
7847
7761
|
default: {
|
|
@@ -7947,7 +7861,7 @@ async function resolveToolModelInput(input) {
|
|
|
7947
7861
|
}
|
|
7948
7862
|
|
|
7949
7863
|
// src/runtime-kernel/graph-engine/nodes/toolNode.finalAnswerProjector.ts
|
|
7950
|
-
function
|
|
7864
|
+
function readNonEmptyString4(value) {
|
|
7951
7865
|
if (typeof value !== "string") {
|
|
7952
7866
|
return void 0;
|
|
7953
7867
|
}
|
|
@@ -7955,7 +7869,7 @@ function readNonEmptyString5(value) {
|
|
|
7955
7869
|
return normalized.length > 0 ? normalized : void 0;
|
|
7956
7870
|
}
|
|
7957
7871
|
function resolveFinalAnswerFromToolControl(finalAnswer) {
|
|
7958
|
-
return
|
|
7872
|
+
return readNonEmptyString4(finalAnswer);
|
|
7959
7873
|
}
|
|
7960
7874
|
|
|
7961
7875
|
// src/runtime-kernel/graph-engine/nodes/toolNode.helpers.ts
|
|
@@ -8211,7 +8125,7 @@ function buildErrorLocalState(params) {
|
|
|
8211
8125
|
}
|
|
8212
8126
|
|
|
8213
8127
|
// src/runtime-kernel/tools/argNormalizer.ts
|
|
8214
|
-
var
|
|
8128
|
+
var logger7 = new Logger("ToolArgNormalizer");
|
|
8215
8129
|
function isRecord10(v) {
|
|
8216
8130
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
8217
8131
|
}
|
|
@@ -8231,7 +8145,7 @@ function joinPath(basePath, segment) {
|
|
|
8231
8145
|
function logJsonEncodedNormalization(expectedType, options) {
|
|
8232
8146
|
const toolPrefix = options.toolName ? `${options.toolName}.` : "";
|
|
8233
8147
|
const path = options.path ?? "<root>";
|
|
8234
|
-
|
|
8148
|
+
logger7.warn("normalized JSON-encoded tool argument", {
|
|
8235
8149
|
expectedType,
|
|
8236
8150
|
path: `${toolPrefix}${path}`
|
|
8237
8151
|
});
|
|
@@ -8587,7 +8501,7 @@ function stripRuntimeReservedToolContextPatch(patch) {
|
|
|
8587
8501
|
}
|
|
8588
8502
|
|
|
8589
8503
|
// src/runtime-kernel/graph-engine/nodes/toolNode.eventBridge.ts
|
|
8590
|
-
var
|
|
8504
|
+
var logger8 = new Logger("ToolNode");
|
|
8591
8505
|
var ToolNodeEventBridge = class {
|
|
8592
8506
|
constructor(deps) {
|
|
8593
8507
|
this.deps = deps;
|
|
@@ -8609,7 +8523,7 @@ var ToolNodeEventBridge = class {
|
|
|
8609
8523
|
status,
|
|
8610
8524
|
payload: { ...payload }
|
|
8611
8525
|
};
|
|
8612
|
-
|
|
8526
|
+
logger8.info("[ToolNode] \u53D1\u51FA tool_process \u4E8B\u4EF6", {
|
|
8613
8527
|
phase,
|
|
8614
8528
|
status,
|
|
8615
8529
|
toolName: this.deps.toolName,
|
|
@@ -8649,7 +8563,7 @@ var ToolNodeEventBridge = class {
|
|
|
8649
8563
|
const answerId = generateAnswerSegmentId();
|
|
8650
8564
|
const id = answerId;
|
|
8651
8565
|
const timestamp = Date.now();
|
|
8652
|
-
|
|
8566
|
+
logger8.info("[ToolNode] \u5DE5\u5177\u8F93\u51FA\u6620\u5C04\u4E3A final_answer", {
|
|
8653
8567
|
sourceToolName: params.sourceToolName,
|
|
8654
8568
|
toolCallId: this.deps.toolCallId,
|
|
8655
8569
|
conversationId: this.deps.conversationId,
|
|
@@ -8707,7 +8621,7 @@ var ToolNodeEventBridge = class {
|
|
|
8707
8621
|
};
|
|
8708
8622
|
|
|
8709
8623
|
// src/runtime-kernel/graph-engine/nodes/toolNode.executionSetup.ts
|
|
8710
|
-
var
|
|
8624
|
+
var logger9 = new Logger("ToolNode");
|
|
8711
8625
|
function parseToolArgs(call) {
|
|
8712
8626
|
const rawArguments = typeof call.function?.arguments === "string" ? call.function.arguments : "";
|
|
8713
8627
|
if (!rawArguments.trim()) {
|
|
@@ -8727,7 +8641,7 @@ function parseToolArgs(call) {
|
|
|
8727
8641
|
return { ok: true, value: parsed };
|
|
8728
8642
|
} catch (error) {
|
|
8729
8643
|
const reason = error instanceof Error ? error.message : "Unknown JSON parse error";
|
|
8730
|
-
|
|
8644
|
+
logger9.warn("failed to parse tool arguments", { error });
|
|
8731
8645
|
return {
|
|
8732
8646
|
ok: false,
|
|
8733
8647
|
error: `Tool arguments are not valid JSON: ${reason}`
|
|
@@ -9121,7 +9035,7 @@ async function claimPendingUserInputs(state, result) {
|
|
|
9121
9035
|
}
|
|
9122
9036
|
|
|
9123
9037
|
// src/runtime-kernel/graph-engine/nodes/toolNode.ts
|
|
9124
|
-
var
|
|
9038
|
+
var logger10 = new Logger("ToolNode");
|
|
9125
9039
|
function isAbortSignal(value) {
|
|
9126
9040
|
return value !== null && typeof value === "object" && "aborted" in value;
|
|
9127
9041
|
}
|
|
@@ -9334,7 +9248,7 @@ var ToolNode = class {
|
|
|
9334
9248
|
throw abortError;
|
|
9335
9249
|
}
|
|
9336
9250
|
const prepared = prepareToolNodeContext(state);
|
|
9337
|
-
|
|
9251
|
+
logger10.info("[ToolNode] \u5F00\u59CB\u6267\u884C\u5DE5\u5177\u8282\u70B9", {
|
|
9338
9252
|
conversationId: prepared.conversationId,
|
|
9339
9253
|
turnId: prepared.turnId,
|
|
9340
9254
|
pendingCallCount: calls.length
|
|
@@ -9349,7 +9263,7 @@ var ToolNode = class {
|
|
|
9349
9263
|
toolCatalog: this.toolRuntime
|
|
9350
9264
|
});
|
|
9351
9265
|
if (!execution) {
|
|
9352
|
-
|
|
9266
|
+
logger10.warn("no tool name found in call");
|
|
9353
9267
|
return { kind: "yield", events: [] };
|
|
9354
9268
|
}
|
|
9355
9269
|
if (typeof execution.protocolError === "string") {
|
|
@@ -9389,7 +9303,7 @@ var ToolNode = class {
|
|
|
9389
9303
|
call,
|
|
9390
9304
|
context: prepared.toolContext,
|
|
9391
9305
|
abortGraceMs: this.abortGraceMs,
|
|
9392
|
-
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", {
|
|
9393
9307
|
toolName: execution.toolName,
|
|
9394
9308
|
toolCallId: execution.toolCallId,
|
|
9395
9309
|
conversationId: prepared.conversationId,
|
|
@@ -9559,7 +9473,7 @@ var ToolNode = class {
|
|
|
9559
9473
|
runtimeEvents: context.bridge.getRuntimeEvents()
|
|
9560
9474
|
});
|
|
9561
9475
|
if (control?.terminateRun) {
|
|
9562
|
-
|
|
9476
|
+
logger10.info("[ToolNode] \u6536\u5230 control.terminateRun\uFF0C\u6267\u884C\u5B8C\u5DE5\u5177\u540E\u76F4\u63A5 yield \u7ED3\u675F\u672C\u8F6E run", {
|
|
9563
9477
|
toolName: context.toolName,
|
|
9564
9478
|
toolCallId: context.toolCallId,
|
|
9565
9479
|
conversationId: context.conversationId,
|
|
@@ -9568,7 +9482,7 @@ var ToolNode = class {
|
|
|
9568
9482
|
return { kind: "yield", events: context.bridge.getRuntimeEvents() };
|
|
9569
9483
|
}
|
|
9570
9484
|
if (remainingCalls.length === 0 && context.local.toolBatchCompletionMode === "yield_after_batch") {
|
|
9571
|
-
|
|
9485
|
+
logger10.info("[ToolNode] \u5DE5\u5177\u6279\u6B21\u5DF2\u7ED3\u7B97\uFF0C\u6309 Host \u7B56\u7565\u76F4\u63A5 yield", {
|
|
9572
9486
|
toolName: context.toolName,
|
|
9573
9487
|
toolCallId: context.toolCallId,
|
|
9574
9488
|
conversationId: context.conversationId,
|
|
@@ -10015,6 +9929,8 @@ var executor = zod.z.object({
|
|
|
10015
9929
|
lastStepsHintThreshold: counter.optional(),
|
|
10016
9930
|
systemReminderPolicy: AgentSpecSystemReminderPolicy.optional(),
|
|
10017
9931
|
toolObservationPolicy: AgentSpecToolObservationGovernancePolicy.optional(),
|
|
9932
|
+
// 已删除字段:0.45 及更早的 checkpoint 可能带 lastSuccessfulLlmModelId,0.46 及更早的可能带云端额度兜底留下的
|
|
9933
|
+
// runLockedModelId;照常接受,读入时丢弃(兜底已移除,恢复后按请求的模型继续)。
|
|
10018
9934
|
runLockedModelId: zod.z.string().optional(),
|
|
10019
9935
|
lastSuccessfulLlmModelId: zod.z.string().optional(),
|
|
10020
9936
|
llmInvocationKind: zod.z.enum(["user_initiated", "continuation"]).optional(),
|
|
@@ -10025,7 +9941,7 @@ var executor = zod.z.object({
|
|
|
10025
9941
|
committedCount: counter,
|
|
10026
9942
|
lastCommittedFingerprint: zod.z.string().optional()
|
|
10027
9943
|
}).strict().optional()
|
|
10028
|
-
}).strict();
|
|
9944
|
+
}).strict().transform(({ lastSuccessfulLlmModelId: _retired, runLockedModelId: _retiredLock, ...state }) => state);
|
|
10029
9945
|
var checkpoint = zod.z.object({
|
|
10030
9946
|
nodeId: zod.z.string().min(1),
|
|
10031
9947
|
schemaVersion: zod.z.literal(ENGINE_STATE_SCHEMA_VERSION).optional(),
|
|
@@ -10339,7 +10255,7 @@ __export(execution_exports, {
|
|
|
10339
10255
|
});
|
|
10340
10256
|
|
|
10341
10257
|
// src/runtime-kernel/execution/event-bus.ts
|
|
10342
|
-
var
|
|
10258
|
+
var logger11 = new Logger("EventBus");
|
|
10343
10259
|
var TypedEventEmitter = class {
|
|
10344
10260
|
listeners = /* @__PURE__ */ new Map();
|
|
10345
10261
|
maxListeners = 10;
|
|
@@ -10347,7 +10263,7 @@ var TypedEventEmitter = class {
|
|
|
10347
10263
|
const listeners = this.getListeners(event);
|
|
10348
10264
|
listeners.add(listener);
|
|
10349
10265
|
if (listeners.size > this.maxListeners) {
|
|
10350
|
-
|
|
10266
|
+
logger11.warn("EventBus listener count exceeds configured max", {
|
|
10351
10267
|
event: String(event),
|
|
10352
10268
|
count: listeners.size,
|
|
10353
10269
|
maxListeners: this.maxListeners
|
|
@@ -10407,7 +10323,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10407
10323
|
super();
|
|
10408
10324
|
this.executionId = executionId;
|
|
10409
10325
|
this.setMaxListeners(30);
|
|
10410
|
-
|
|
10326
|
+
logger11.info(`EventBus created for execution ${this.executionId}`);
|
|
10411
10327
|
}
|
|
10412
10328
|
/**
|
|
10413
10329
|
* 发布一个事件到总线
|
|
@@ -10416,7 +10332,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10416
10332
|
publish(envelope) {
|
|
10417
10333
|
if (envelope.trace.execution_id !== this.executionId) {
|
|
10418
10334
|
const error = new Error("EventEnvelope execution_id does not match EventBus instance.");
|
|
10419
|
-
|
|
10335
|
+
logger11.error("Mismatched execution_id", {
|
|
10420
10336
|
busExecutionId: this.executionId,
|
|
10421
10337
|
eventExecutionId: envelope.trace.execution_id,
|
|
10422
10338
|
eventSeq: envelope.seq
|
|
@@ -10428,7 +10344,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10428
10344
|
const error = new Error(
|
|
10429
10345
|
"EventBus only accepts RuntimeEvent with formal run routing identity."
|
|
10430
10346
|
);
|
|
10431
|
-
|
|
10347
|
+
logger11.error("RuntimeEvent is missing formal run routing identity", {
|
|
10432
10348
|
executionId: this.executionId,
|
|
10433
10349
|
eventId: envelope.payload.id,
|
|
10434
10350
|
eventType: envelope.payload.type
|
|
@@ -10442,14 +10358,14 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
10442
10358
|
* 关闭总线,清理所有监听器
|
|
10443
10359
|
*/
|
|
10444
10360
|
close() {
|
|
10445
|
-
|
|
10361
|
+
logger11.info(`Closing EventBus for execution ${this.executionId}`);
|
|
10446
10362
|
this.emit("close");
|
|
10447
10363
|
this.removeAllListeners();
|
|
10448
10364
|
}
|
|
10449
10365
|
};
|
|
10450
10366
|
|
|
10451
10367
|
// src/runtime-kernel/execution/sequencer.ts
|
|
10452
|
-
var
|
|
10368
|
+
var logger12 = new Logger("EventSequencer");
|
|
10453
10369
|
var EventSequencer = class {
|
|
10454
10370
|
executionId;
|
|
10455
10371
|
traceId;
|
|
@@ -10457,7 +10373,7 @@ var EventSequencer = class {
|
|
|
10457
10373
|
constructor(conversationId, traceId) {
|
|
10458
10374
|
this.executionId = generateExecutionId();
|
|
10459
10375
|
this.traceId = traceId || generateTraceId();
|
|
10460
|
-
|
|
10376
|
+
logger12.info(`EventSequencer created for conversation ${conversationId}`, {
|
|
10461
10377
|
executionId: this.executionId,
|
|
10462
10378
|
traceId: this.traceId
|
|
10463
10379
|
});
|
|
@@ -11315,7 +11231,7 @@ var ThoughtStreamSegmenter = class {
|
|
|
11315
11231
|
};
|
|
11316
11232
|
|
|
11317
11233
|
// src/runtime-kernel/llm/streaming-adapter.ts
|
|
11318
|
-
var
|
|
11234
|
+
var logger13 = new Logger("LlmCaller");
|
|
11319
11235
|
var CanonicalInferenceFailureError = class extends Error {
|
|
11320
11236
|
errorCode;
|
|
11321
11237
|
recoverable;
|
|
@@ -11539,7 +11455,7 @@ async function callLlmStream(params) {
|
|
|
11539
11455
|
} catch (error) {
|
|
11540
11456
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
11541
11457
|
if (normalized.name === "AbortError") {
|
|
11542
|
-
|
|
11458
|
+
logger13.info("Canonical inference \u6536\u5230\u53D6\u6D88\u7EC8\u6001\uFF0C\u4E0D\u53D1\u5E03\u666E\u901A error event", { modelId });
|
|
11543
11459
|
throw normalized;
|
|
11544
11460
|
}
|
|
11545
11461
|
const classification = ErrorClassifier.classify(normalized, {
|
|
@@ -11615,7 +11531,7 @@ var LlmRetryEpisode = class {
|
|
|
11615
11531
|
};
|
|
11616
11532
|
|
|
11617
11533
|
// src/runtime-kernel/llm/retry-fallback-routing.ts
|
|
11618
|
-
var
|
|
11534
|
+
var logger14 = new Logger("LlmCaller");
|
|
11619
11535
|
function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement, fallbackObserver, error, evaluateFallbackPromptCapacity2) {
|
|
11620
11536
|
deps.modelCatalog.getModelById(activeModelId);
|
|
11621
11537
|
const policyDecision = deps.policyEngine.decideOnError(error, {
|
|
@@ -11645,81 +11561,16 @@ function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement
|
|
|
11645
11561
|
reason: "no_eligible_fallback_candidate",
|
|
11646
11562
|
requiredPlacements: requirement.placements
|
|
11647
11563
|
});
|
|
11648
|
-
|
|
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");
|
|
11649
11565
|
return null;
|
|
11650
11566
|
}
|
|
11651
|
-
|
|
11567
|
+
logger14.warn("Policy \u5207\u6362\u6A21\u578B\u7EE7\u7EED", {
|
|
11652
11568
|
reason: policyDecision.reason,
|
|
11653
11569
|
activeModelId,
|
|
11654
11570
|
fallbackModelId
|
|
11655
11571
|
});
|
|
11656
11572
|
return fallbackModelId;
|
|
11657
11573
|
}
|
|
11658
|
-
function tryCloudQuotaFallback({
|
|
11659
|
-
deps,
|
|
11660
|
-
activeModelId,
|
|
11661
|
-
options,
|
|
11662
|
-
excludedModelIds,
|
|
11663
|
-
requirement,
|
|
11664
|
-
error,
|
|
11665
|
-
fallbackObserver,
|
|
11666
|
-
evaluateFallbackPromptCapacity: evaluateFallbackPromptCapacity2
|
|
11667
|
-
}) {
|
|
11668
|
-
const fallbackModelId = options.cloud_quota_fallback_model_id;
|
|
11669
|
-
if (!fallbackModelId || !ErrorClassifier.isCloudQuotaError(error) || excludedModelIds.has(fallbackModelId)) {
|
|
11670
|
-
return null;
|
|
11671
|
-
}
|
|
11672
|
-
const fallbackConfig = deps.modelCatalog.getModelById(fallbackModelId);
|
|
11673
|
-
if (!fallbackConfig?.api_key) {
|
|
11674
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11675
|
-
fromModelId: activeModelId,
|
|
11676
|
-
candidateModelId: fallbackModelId,
|
|
11677
|
-
policy: "cloud-quota",
|
|
11678
|
-
reason: "fallback_model_unavailable",
|
|
11679
|
-
requiredPlacements: requirement.placements
|
|
11680
|
-
});
|
|
11681
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\u76EE\u6807\u4E0D\u53EF\u7528\uFF08\u672A\u6CE8\u518C\u6216\u7F3A\u5C11 API Key\uFF09", { fallbackModelId });
|
|
11682
|
-
return null;
|
|
11683
|
-
}
|
|
11684
|
-
const compatibility = evaluateModelInputCompatibility(fallbackConfig, requirement);
|
|
11685
|
-
if (!compatibility.compatible) {
|
|
11686
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11687
|
-
fromModelId: activeModelId,
|
|
11688
|
-
candidateModelId: fallbackModelId,
|
|
11689
|
-
policy: "cloud-quota",
|
|
11690
|
-
reason: compatibility.reason,
|
|
11691
|
-
requiredPlacements: requirement.placements
|
|
11692
|
-
});
|
|
11693
|
-
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", {
|
|
11694
|
-
fallbackModelId,
|
|
11695
|
-
requiredPlacements: requirement.placements,
|
|
11696
|
-
reason: compatibility.reason
|
|
11697
|
-
});
|
|
11698
|
-
return null;
|
|
11699
|
-
}
|
|
11700
|
-
const capacityAdmission = evaluateFallbackPromptCapacity2?.(fallbackModelId);
|
|
11701
|
-
if (capacityAdmission && !capacityAdmission.admitted) {
|
|
11702
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11703
|
-
fromModelId: activeModelId,
|
|
11704
|
-
candidateModelId: fallbackModelId,
|
|
11705
|
-
policy: "cloud-quota",
|
|
11706
|
-
reason: capacityAdmission.reason,
|
|
11707
|
-
requiredPlacements: requirement.placements
|
|
11708
|
-
});
|
|
11709
|
-
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", {
|
|
11710
|
-
fallbackModelId,
|
|
11711
|
-
reason: capacityAdmission.reason
|
|
11712
|
-
});
|
|
11713
|
-
return null;
|
|
11714
|
-
}
|
|
11715
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\uFF08run \u5185\u7EED\u8DD1\uFF09", {
|
|
11716
|
-
activeModelId,
|
|
11717
|
-
fallbackModelId,
|
|
11718
|
-
reason: error.message
|
|
11719
|
-
});
|
|
11720
|
-
fallbackObserver?.onCloudQuotaFallbackApplied?.(fallbackModelId);
|
|
11721
|
-
return fallbackModelId;
|
|
11722
|
-
}
|
|
11723
11574
|
|
|
11724
11575
|
// src/runtime-kernel/llm/usage-telemetry.ts
|
|
11725
11576
|
async function callPlainCompletion(inferencePort, modelId, messages, options = {}, signal, traceId) {
|
|
@@ -11842,7 +11693,7 @@ var LlmImageInputError = class extends Error {
|
|
|
11842
11693
|
};
|
|
11843
11694
|
|
|
11844
11695
|
// src/runtime-kernel/llm/retry-fallback.ts
|
|
11845
|
-
var
|
|
11696
|
+
var logger15 = new Logger("LlmCaller");
|
|
11846
11697
|
async function callWithRetryFallback(params) {
|
|
11847
11698
|
const {
|
|
11848
11699
|
deps,
|
|
@@ -11870,11 +11721,9 @@ async function callWithRetryFallback(params) {
|
|
|
11870
11721
|
const retryEpisode = new LlmRetryEpisode(traceId, eventHandler);
|
|
11871
11722
|
let previousAttemptTracker;
|
|
11872
11723
|
if (!clientRetryEnabled) {
|
|
11873
|
-
|
|
11874
|
-
logger16.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
11724
|
+
logger15.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
11875
11725
|
modelId,
|
|
11876
|
-
|
|
11877
|
-
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"
|
|
11878
11727
|
});
|
|
11879
11728
|
}
|
|
11880
11729
|
try {
|
|
@@ -11910,7 +11759,7 @@ async function callWithRetryFallback(params) {
|
|
|
11910
11759
|
}) : void 0;
|
|
11911
11760
|
try {
|
|
11912
11761
|
if (isRetry) {
|
|
11913
|
-
|
|
11762
|
+
logger15.info("LLM \u8C03\u7528\u91CD\u8BD5", { attempt, configuredMaxRetries });
|
|
11914
11763
|
}
|
|
11915
11764
|
actualAttempts++;
|
|
11916
11765
|
retryEpisode.retrying(actualAttempts);
|
|
@@ -11939,7 +11788,7 @@ async function callWithRetryFallback(params) {
|
|
|
11939
11788
|
if (deps.retryConfig.enableEmptyResponseRetry && !responseContent?.trim() && !toolCallsFromLLM?.length) {
|
|
11940
11789
|
throw new Error("LLM\u8FD4\u56DE\u4E86\u7A7A\u54CD\u5E94");
|
|
11941
11790
|
}
|
|
11942
|
-
|
|
11791
|
+
logger15.debug("LLM \u8C03\u7528\u6210\u529F", { attempts: actualAttempts, maxTotalAttempts });
|
|
11943
11792
|
if (attemptContextUsage) {
|
|
11944
11793
|
fallbackObserver?.onLlmAttemptSucceeded?.(activeModelId, attemptContextUsage);
|
|
11945
11794
|
} else {
|
|
@@ -11950,7 +11799,7 @@ async function callWithRetryFallback(params) {
|
|
|
11950
11799
|
} catch (error) {
|
|
11951
11800
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
11952
11801
|
if (lastError.name === "AbortError") {
|
|
11953
|
-
|
|
11802
|
+
logger15.info("LLM \u8C03\u7528\u5DF2\u53D6\u6D88\uFF0C\u4E0D\u8FDB\u5165 provider failure \u5206\u7C7B\u4E0E\u91CD\u8BD5\u6D41\u7A0B", {
|
|
11954
11803
|
attempt: attempt + 1,
|
|
11955
11804
|
actualAttempts,
|
|
11956
11805
|
maxTotalAttempts,
|
|
@@ -11969,7 +11818,7 @@ async function callWithRetryFallback(params) {
|
|
|
11969
11818
|
total_attempts: actualAttempts,
|
|
11970
11819
|
error_code: classification.errorCode
|
|
11971
11820
|
};
|
|
11972
|
-
|
|
11821
|
+
logger15.error("LLM \u8C03\u7528\u5931\u8D25", {
|
|
11973
11822
|
attempt: attempt + 1,
|
|
11974
11823
|
maxAttempts: currentMaxRetries + 1,
|
|
11975
11824
|
actualAttempts,
|
|
@@ -11978,7 +11827,7 @@ async function callWithRetryFallback(params) {
|
|
|
11978
11827
|
});
|
|
11979
11828
|
previousAttemptTracker = attemptTracker;
|
|
11980
11829
|
if (!hasLlmAttemptBudgetRemaining({ actualAttempts, maxTotalAttempts })) {
|
|
11981
|
-
|
|
11830
|
+
logger15.error("\u5DF2\u8FBE\u5230 LLM \u603B\u8C03\u7528\u6B21\u6570\u4E0A\u9650\uFF0C\u505C\u6B62\u91CD\u8BD5/\u5207\u6A21\u578B", {
|
|
11982
11831
|
actualAttempts,
|
|
11983
11832
|
maxTotalAttempts
|
|
11984
11833
|
});
|
|
@@ -12008,37 +11857,15 @@ async function callWithRetryFallback(params) {
|
|
|
12008
11857
|
attempt -= 1;
|
|
12009
11858
|
continue;
|
|
12010
11859
|
}
|
|
12011
|
-
const quotaFallbackModelId = tryCloudQuotaFallback({
|
|
12012
|
-
deps,
|
|
12013
|
-
activeModelId,
|
|
12014
|
-
options,
|
|
12015
|
-
excludedModelIds,
|
|
12016
|
-
requirement,
|
|
12017
|
-
error: lastError,
|
|
12018
|
-
fallbackObserver,
|
|
12019
|
-
evaluateFallbackPromptCapacity: invocationContext?.evaluateFallbackPromptCapacity
|
|
12020
|
-
});
|
|
12021
|
-
if (quotaFallbackModelId) {
|
|
12022
|
-
fallbackObserver?.onModelFallbackApplied?.({
|
|
12023
|
-
fromModelId: activeModelId,
|
|
12024
|
-
toModelId: quotaFallbackModelId,
|
|
12025
|
-
reason: lastError.message,
|
|
12026
|
-
policy: "cloud-quota"
|
|
12027
|
-
});
|
|
12028
|
-
activeModelId = quotaFallbackModelId;
|
|
12029
|
-
excludedModelIds.add(quotaFallbackModelId);
|
|
12030
|
-
attempt -= 1;
|
|
12031
|
-
continue;
|
|
12032
|
-
}
|
|
12033
11860
|
}
|
|
12034
11861
|
if (classification.category === "non_retryable" /* NON_RETRYABLE */) {
|
|
12035
|
-
|
|
11862
|
+
logger15.error("\u9519\u8BEF\u4E0D\u53EF\u91CD\u8BD5\uFF0C\u76F4\u63A5\u5931\u8D25", { reason: classification.reason });
|
|
12036
11863
|
retryEpisode.finish("failed", failedRetryState);
|
|
12037
11864
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
12038
11865
|
throw lastError;
|
|
12039
11866
|
}
|
|
12040
11867
|
if (attempt >= configuredMaxRetries || categoryRetries[category] >= currentMaxRetries) {
|
|
12041
|
-
|
|
11868
|
+
logger15.error("\u5DF2\u8FBE\u5230\u6700\u5927\u91CD\u8BD5\u6B21\u6570\uFF0C\u653E\u5F03\u91CD\u8BD5", { maxRetries: currentMaxRetries });
|
|
12042
11869
|
retryEpisode.finish("exhausted", failedRetryState);
|
|
12043
11870
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
12044
11871
|
throw lastError;
|
|
@@ -12050,9 +11877,9 @@ async function callWithRetryFallback(params) {
|
|
|
12050
11877
|
6e4
|
|
12051
11878
|
);
|
|
12052
11879
|
if (classification.category === "rate_limit" /* RATE_LIMIT */) {
|
|
12053
|
-
|
|
11880
|
+
logger15.warn("\u901F\u7387\u9650\u5236\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
12054
11881
|
} else if (classification.category === "retryable" /* RETRYABLE */) {
|
|
12055
|
-
|
|
11882
|
+
logger15.warn("\u53EF\u91CD\u8BD5\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
12056
11883
|
}
|
|
12057
11884
|
throwIfAborted(signal, "\u5EF6\u8FDF\u7B49\u5F85\u524D\u68C0\u6D4B\u5230\u53D6\u6D88\u4FE1\u53F7\uFF0C\u505C\u6B62\u91CD\u8BD5");
|
|
12058
11885
|
categoryRetries[category] += 1;
|
|
@@ -12089,16 +11916,11 @@ function waitForRetry(delayMs, signal) {
|
|
|
12089
11916
|
}
|
|
12090
11917
|
function isClientRetryEnabledForModel(modelCatalog, modelId, options) {
|
|
12091
11918
|
if (options.retry_policy === "none") return false;
|
|
12092
|
-
|
|
12093
|
-
if (cfg?.billing_mode === "cloud") return false;
|
|
12094
|
-
if (options.retry_policy === "client") return true;
|
|
12095
|
-
if (!cfg) return true;
|
|
12096
|
-
if (cfg.enable_client_retry === false) return false;
|
|
12097
|
-
return true;
|
|
11919
|
+
return modelCatalog.getModelById(modelId)?.enable_client_retry !== false;
|
|
12098
11920
|
}
|
|
12099
11921
|
function throwIfAborted(signal, message) {
|
|
12100
11922
|
if (!signal?.aborted) return;
|
|
12101
|
-
|
|
11923
|
+
logger15.info(message);
|
|
12102
11924
|
const reason = signal.reason;
|
|
12103
11925
|
if (reason instanceof Error && reason.name === "AbortError") throw reason;
|
|
12104
11926
|
const reasonText = typeof reason === "string" && reason.trim().length > 0 ? reason : "stream_interrupted";
|
|
@@ -12416,7 +12238,7 @@ async function recoverChildRunEventsFromCheckpoint(params) {
|
|
|
12416
12238
|
}
|
|
12417
12239
|
|
|
12418
12240
|
// src/runtime-kernel/child-runs/childRunInvoker.ts
|
|
12419
|
-
var
|
|
12241
|
+
var logger16 = new Logger("ChildRunInvoker");
|
|
12420
12242
|
var ChildRunInvoker = class {
|
|
12421
12243
|
modelResolver;
|
|
12422
12244
|
createLlmNode;
|
|
@@ -12458,7 +12280,7 @@ var ChildRunInvoker = class {
|
|
|
12458
12280
|
const resolvedParentRunId = parentRunId ?? parentToolContext.runId;
|
|
12459
12281
|
const depthDecision = decideChildRunDepth({ parentToolContext });
|
|
12460
12282
|
if (!depthDecision.allowed) {
|
|
12461
|
-
|
|
12283
|
+
logger16.warn("child-run \u6DF1\u5EA6\u8D85\u8FC7\u4E0A\u9650\uFF0C\u62D2\u7EDD\u7EE7\u7EED\u9012\u5F52\u6267\u884C", {
|
|
12462
12284
|
runId: childRunId,
|
|
12463
12285
|
parentRunId: resolvedParentRunId,
|
|
12464
12286
|
parentDepth: depthDecision.parentDepth,
|
|
@@ -12475,7 +12297,7 @@ var ChildRunInvoker = class {
|
|
|
12475
12297
|
};
|
|
12476
12298
|
}
|
|
12477
12299
|
if (abortSignal?.aborted || parentToolContext.abortSignal?.aborted) {
|
|
12478
|
-
|
|
12300
|
+
logger16.info("child-run \u5728\u4EFB\u52A1\u63A5\u7EB3\u524D\u5DF2\u53D6\u6D88", {
|
|
12479
12301
|
runId: childRunId,
|
|
12480
12302
|
parentRunId: resolvedParentRunId
|
|
12481
12303
|
});
|
|
@@ -12499,7 +12321,7 @@ var ChildRunInvoker = class {
|
|
|
12499
12321
|
}
|
|
12500
12322
|
const turnId = config.initialInput?.turnId ?? generateTurnId();
|
|
12501
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");
|
|
12502
|
-
|
|
12324
|
+
logger16.info(`\u542F\u52A8 child-run: ${agentConfig.id}`, {
|
|
12503
12325
|
conversationId: runtimeConversationId,
|
|
12504
12326
|
checkpointKey: internalCheckpointKey,
|
|
12505
12327
|
maxSteps,
|
|
@@ -12617,7 +12439,7 @@ var ChildRunInvoker = class {
|
|
|
12617
12439
|
);
|
|
12618
12440
|
finalAnswer = extractFinalAnswer(allEvents);
|
|
12619
12441
|
lastProgress = finalAnswer ? void 0 : extractLastProgress(allEvents);
|
|
12620
|
-
|
|
12442
|
+
logger16.info("child-run \u6267\u884C\u5B8C\u6210", {
|
|
12621
12443
|
stepCount,
|
|
12622
12444
|
eventCount: allEvents.length,
|
|
12623
12445
|
hasFinalAnswer: !!finalAnswer,
|
|
@@ -12647,13 +12469,13 @@ var ChildRunInvoker = class {
|
|
|
12647
12469
|
cancelled = abortSignal?.aborted === true || isAbortError2(err);
|
|
12648
12470
|
error = err instanceof Error ? err.message : String(err);
|
|
12649
12471
|
if (cancelled) {
|
|
12650
|
-
|
|
12472
|
+
logger16.info("child-run \u6267\u884C\u53D6\u6D88", {
|
|
12651
12473
|
runId: childRunId,
|
|
12652
12474
|
parentRunId: resolvedParentRunId,
|
|
12653
12475
|
message: error
|
|
12654
12476
|
});
|
|
12655
12477
|
} else {
|
|
12656
|
-
|
|
12478
|
+
logger16.error(
|
|
12657
12479
|
"child-run \u6267\u884C\u5931\u8D25:",
|
|
12658
12480
|
err instanceof Error ? {
|
|
12659
12481
|
name: err.name,
|
|
@@ -12749,7 +12571,7 @@ var ChildRunInvoker = class {
|
|
|
12749
12571
|
function isAbortError2(error) {
|
|
12750
12572
|
return error instanceof Error && error.name === "AbortError";
|
|
12751
12573
|
}
|
|
12752
|
-
function
|
|
12574
|
+
function readNonEmptyString5(value) {
|
|
12753
12575
|
if (typeof value !== "string") {
|
|
12754
12576
|
return void 0;
|
|
12755
12577
|
}
|
|
@@ -12757,7 +12579,7 @@ function readNonEmptyString6(value) {
|
|
|
12757
12579
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
12758
12580
|
}
|
|
12759
12581
|
function resolveChildRunConversationId(params) {
|
|
12760
|
-
const conversationId =
|
|
12582
|
+
const conversationId = readNonEmptyString5(params.explicitConversationId) ?? readNonEmptyString5(params.parentToolContext.conversationId);
|
|
12761
12583
|
if (!conversationId) {
|
|
12762
12584
|
throw new Error(
|
|
12763
12585
|
"ChildRunInvoker requires conversationId from admission or parent ToolContext."
|
|
@@ -12766,7 +12588,7 @@ function resolveChildRunConversationId(params) {
|
|
|
12766
12588
|
return conversationId;
|
|
12767
12589
|
}
|
|
12768
12590
|
function resolveChildRunModelId(params) {
|
|
12769
|
-
const explicitModelId =
|
|
12591
|
+
const explicitModelId = readNonEmptyString5(params.explicitModelId);
|
|
12770
12592
|
if (explicitModelId) {
|
|
12771
12593
|
return explicitModelId;
|
|
12772
12594
|
}
|
|
@@ -13711,7 +13533,7 @@ function runMetaFromRecord(record) {
|
|
|
13711
13533
|
}
|
|
13712
13534
|
|
|
13713
13535
|
// src/runtime-kernel/run-supervisor/functions/awaitingUserWatcher.ts
|
|
13714
|
-
var
|
|
13536
|
+
var logger17 = new Logger("RunSupervisorAwaitingUserWatcher");
|
|
13715
13537
|
function isRecord16(value) {
|
|
13716
13538
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13717
13539
|
}
|
|
@@ -13756,7 +13578,7 @@ function createAwaitingUserWatcher(options) {
|
|
|
13756
13578
|
resumeToken: event.resume_token
|
|
13757
13579
|
}
|
|
13758
13580
|
}).catch((error) => {
|
|
13759
|
-
|
|
13581
|
+
logger17.warn("failed to mark awaiting_user from requires_user_interaction", { error });
|
|
13760
13582
|
});
|
|
13761
13583
|
};
|
|
13762
13584
|
const dispose = () => {
|
|
@@ -15023,7 +14845,7 @@ function createScriptedInferenceHarness(script, options = {}) {
|
|
|
15023
14845
|
}
|
|
15024
14846
|
|
|
15025
14847
|
// src/context-manager/shared/MessageFormatter.ts
|
|
15026
|
-
var
|
|
14848
|
+
var logger18 = new Logger("MessageFormatter");
|
|
15027
14849
|
var MessageFormatter = class {
|
|
15028
14850
|
fenceRegistry;
|
|
15029
14851
|
constructor(options = {}) {
|
|
@@ -15089,12 +14911,12 @@ var MessageFormatter = class {
|
|
|
15089
14911
|
case "context_injection": {
|
|
15090
14912
|
const fenceKind = metadata?.fenceKind;
|
|
15091
14913
|
if (!fenceKind) {
|
|
15092
|
-
|
|
14914
|
+
logger18.warn("context_injection missing metadata.fenceKind, skipping");
|
|
15093
14915
|
return null;
|
|
15094
14916
|
}
|
|
15095
14917
|
const descriptor = fenceRegistry?.get(fenceKind);
|
|
15096
14918
|
if (!descriptor) {
|
|
15097
|
-
|
|
14919
|
+
logger18.warn("fence kind is not registered, skipping", { fenceKind });
|
|
15098
14920
|
return null;
|
|
15099
14921
|
}
|
|
15100
14922
|
return {
|
|
@@ -15133,7 +14955,7 @@ var MessageFormatter = class {
|
|
|
15133
14955
|
case "task_completion":
|
|
15134
14956
|
return { role, content };
|
|
15135
14957
|
default:
|
|
15136
|
-
|
|
14958
|
+
logger18.warn("unhandled message type for chat history, skipping", { type });
|
|
15137
14959
|
return null;
|
|
15138
14960
|
}
|
|
15139
14961
|
}
|
|
@@ -15148,7 +14970,7 @@ zod.z.object({
|
|
|
15148
14970
|
}).strict();
|
|
15149
14971
|
|
|
15150
14972
|
// src/context-manager/profiles/agent/utils/toolOutputSummarizer.ts
|
|
15151
|
-
var
|
|
14973
|
+
var logger20 = new Logger("ToolOutputSummarizer");
|
|
15152
14974
|
var DEFAULT_SUMMARIZER_CONFIG = {
|
|
15153
14975
|
fullContentThreshold: 400,
|
|
15154
14976
|
textPreviewLength: 200,
|
|
@@ -15188,7 +15010,7 @@ var ToolOutputSummarizer = class {
|
|
|
15188
15010
|
return tool.getExecutionSummary(output);
|
|
15189
15011
|
}
|
|
15190
15012
|
} catch (error) {
|
|
15191
|
-
|
|
15013
|
+
logger20.error("tool getExecutionSummary failed", { toolName, error });
|
|
15192
15014
|
}
|
|
15193
15015
|
return null;
|
|
15194
15016
|
}
|
|
@@ -15239,14 +15061,14 @@ var summarizeToolOutput = (toolName, output, toolSummaryProvider, config) => {
|
|
|
15239
15061
|
};
|
|
15240
15062
|
|
|
15241
15063
|
// src/context-manager/profiles/agent/utils/eventConverter.ts
|
|
15242
|
-
var
|
|
15064
|
+
var logger21 = new Logger("AgentEventConverter");
|
|
15243
15065
|
function isHistorySummaryEvent(event) {
|
|
15244
15066
|
return "type" in event && event.type === "history_summary";
|
|
15245
15067
|
}
|
|
15246
15068
|
function convertEventToAiMessage(event) {
|
|
15247
15069
|
if (isHistorySummaryEvent(event)) {
|
|
15248
15070
|
const replacedIds = Array.isArray(event.replaced_message_ids) ? event.replaced_message_ids : [];
|
|
15249
|
-
|
|
15071
|
+
logger21.debug("Converted history_summary RuntimeEvent to AiMessage", {
|
|
15250
15072
|
summaryId: event.id,
|
|
15251
15073
|
replacedCount: replacedIds.length,
|
|
15252
15074
|
summarySeq: event.summary_seq,
|