@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/index.js
CHANGED
|
@@ -569,18 +569,6 @@ var ErrorClassifier = class {
|
|
|
569
569
|
});
|
|
570
570
|
}
|
|
571
571
|
}
|
|
572
|
-
const quotaPatterns = ["\u5DF2\u8FBE\u4E0A\u9650", "\u514D\u8D39\u671F\u5DF2\u7ED3\u675F"];
|
|
573
|
-
for (const pattern of quotaPatterns) {
|
|
574
|
-
if (errorMessage.includes(pattern)) {
|
|
575
|
-
logClassification(context, "\u68C0\u6D4B\u5230\u4E91\u7AEF\u989D\u5EA6\u9650\u5236\uFF0C\u4E0D\u91CD\u8BD5", { matchedPattern: pattern });
|
|
576
|
-
return createClassification("non_retryable" /* NON_RETRYABLE */, `\u4E91\u7AEF\u989D\u5EA6\u9650\u5236: ${pattern}`, null, {
|
|
577
|
-
errorCode: ENGINE_ERROR_CODES.LLM_PROVIDER_DOWN,
|
|
578
|
-
recoverable: false,
|
|
579
|
-
hint: "check_billing_or_provider_status",
|
|
580
|
-
metadata: { matchedPattern: pattern }
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
572
|
const authPatterns = [
|
|
585
573
|
{ pattern: "unauthorized", code: "401" },
|
|
586
574
|
{ pattern: "forbidden", code: "403" },
|
|
@@ -835,17 +823,6 @@ var ErrorClassifier = class {
|
|
|
835
823
|
}
|
|
836
824
|
return Math.max(baseDelay, classification.suggestedDelay ?? 0);
|
|
837
825
|
}
|
|
838
|
-
static isCloudQuotaError(error) {
|
|
839
|
-
const msg = (error.message || "").toLowerCase();
|
|
840
|
-
const patterns = [
|
|
841
|
-
"\u989D\u5EA6\u4E0A\u9650",
|
|
842
|
-
"\u5DF2\u8FBE\u4E0A\u9650",
|
|
843
|
-
"\u514D\u8D39\u671F\u5DF2\u7ED3\u675F",
|
|
844
|
-
"\u8BE5\u6A21\u578B\u6682\u4E0D\u53EF\u7528",
|
|
845
|
-
"cloud_quota_exhausted"
|
|
846
|
-
];
|
|
847
|
-
return patterns.some((pattern) => msg.includes(pattern));
|
|
848
|
-
}
|
|
849
826
|
};
|
|
850
827
|
|
|
851
828
|
// src/contracts/index.ts
|
|
@@ -4900,8 +4877,8 @@ var TokenCalculator = class {
|
|
|
4900
4877
|
return;
|
|
4901
4878
|
}
|
|
4902
4879
|
this.failedEncodingWarnings.add(requestedEncoding);
|
|
4903
|
-
const
|
|
4904
|
-
|
|
4880
|
+
const logger18 = new Logger("TokenCalculator");
|
|
4881
|
+
logger18.warn("tiktoken encoding unavailable, falling back to avgCharsPerToken estimator", {
|
|
4905
4882
|
requestedEncoding,
|
|
4906
4883
|
error
|
|
4907
4884
|
});
|
|
@@ -5003,49 +4980,6 @@ var llmTelemetryMiddleware = async (ctx, stage, next) => {
|
|
|
5003
4980
|
});
|
|
5004
4981
|
};
|
|
5005
4982
|
|
|
5006
|
-
// src/runtime-kernel/graph-engine/functions/runModelLock.ts
|
|
5007
|
-
function readNonEmptyString4(value) {
|
|
5008
|
-
if (typeof value !== "string") return void 0;
|
|
5009
|
-
const trimmed = value.trim();
|
|
5010
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
5011
|
-
}
|
|
5012
|
-
function decideRunModelLockPatch(params) {
|
|
5013
|
-
if (params.stageId !== "execute_llm") {
|
|
5014
|
-
return { shouldLog: false };
|
|
5015
|
-
}
|
|
5016
|
-
const normalized = readNonEmptyString4(params.appliedFallbackModelId);
|
|
5017
|
-
if (!normalized) {
|
|
5018
|
-
return { shouldLog: false };
|
|
5019
|
-
}
|
|
5020
|
-
if (readNonEmptyString4(params.currentRunLockedModelId) === normalized) {
|
|
5021
|
-
return { shouldLog: false };
|
|
5022
|
-
}
|
|
5023
|
-
return {
|
|
5024
|
-
executorLocalPatch: { runLockedModelId: normalized },
|
|
5025
|
-
shouldLog: true
|
|
5026
|
-
};
|
|
5027
|
-
}
|
|
5028
|
-
|
|
5029
|
-
// src/runtime-kernel/graph-engine/tick-pipeline/middlewares/runModelLockMiddleware.ts
|
|
5030
|
-
var logger4 = new Logger("GraphAgentExecutor");
|
|
5031
|
-
var runModelLockMiddleware = async (ctx, stage, next) => {
|
|
5032
|
-
await next();
|
|
5033
|
-
const decision = decideRunModelLockPatch({
|
|
5034
|
-
stageId: stage.id,
|
|
5035
|
-
appliedFallbackModelId: ctx.cloudQuotaFallbackAppliedModelId,
|
|
5036
|
-
currentRunLockedModelId: ctx.executorLocalPatch?.runLockedModelId ?? ctx.executorLocal?.runLockedModelId
|
|
5037
|
-
});
|
|
5038
|
-
if (!decision.executorLocalPatch) {
|
|
5039
|
-
return;
|
|
5040
|
-
}
|
|
5041
|
-
if (decision.shouldLog) {
|
|
5042
|
-
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}`);
|
|
5043
|
-
}
|
|
5044
|
-
return {
|
|
5045
|
-
executorLocalPatch: decision.executorLocalPatch
|
|
5046
|
-
};
|
|
5047
|
-
};
|
|
5048
|
-
|
|
5049
4983
|
// src/runtime-kernel/graph-engine/tick-pipeline/runTickPipeline.ts
|
|
5050
4984
|
var tickPipelineContextKeys = [
|
|
5051
4985
|
"input",
|
|
@@ -5081,7 +5015,6 @@ var tickPipelineContextKeys = [
|
|
|
5081
5015
|
"decision",
|
|
5082
5016
|
"systemReminderHitRuleIds",
|
|
5083
5017
|
"contextTrace",
|
|
5084
|
-
"cloudQuotaFallbackAppliedModelId",
|
|
5085
5018
|
"modelFallbackAudit",
|
|
5086
5019
|
"telemetry",
|
|
5087
5020
|
"audit",
|
|
@@ -5420,7 +5353,7 @@ ${normalized}
|
|
|
5420
5353
|
}
|
|
5421
5354
|
|
|
5422
5355
|
// src/runtime-kernel/system-reminder/apply.ts
|
|
5423
|
-
var
|
|
5356
|
+
var logger4 = new Logger("SystemReminder");
|
|
5424
5357
|
var readString2 = (v) => {
|
|
5425
5358
|
if (typeof v !== "string") return void 0;
|
|
5426
5359
|
const s = v;
|
|
@@ -5483,7 +5416,7 @@ function applySystemReminders(params) {
|
|
|
5483
5416
|
} catch {
|
|
5484
5417
|
}
|
|
5485
5418
|
}
|
|
5486
|
-
|
|
5419
|
+
logger4.info("SystemReminder \u5DF2\u6CE8\u5165\u5230 LLM \u8F93\u5165\u672B\u5C3E", {
|
|
5487
5420
|
ruleIds: injectedRuleIds.length > 0 ? injectedRuleIds : Array.from(seenRuleIds),
|
|
5488
5421
|
promptKey: ctx.request.promptKey,
|
|
5489
5422
|
executorLocal: {
|
|
@@ -6193,18 +6126,14 @@ function createExecuteLlmStage(dependencies) {
|
|
|
6193
6126
|
"turnId"
|
|
6194
6127
|
],
|
|
6195
6128
|
writes: [
|
|
6196
|
-
"cloudQuotaFallbackAppliedModelId",
|
|
6197
6129
|
"modelFallbackAudit",
|
|
6198
6130
|
"llmCallStartedAt",
|
|
6199
6131
|
"llmResp",
|
|
6200
6132
|
"llmCallDurationMs",
|
|
6201
|
-
"executorLocalPatch",
|
|
6202
6133
|
"contextUsage"
|
|
6203
6134
|
],
|
|
6204
6135
|
async run(ctx) {
|
|
6205
|
-
let cloudQuotaFallbackAppliedModelId;
|
|
6206
6136
|
let modelFallbackAudit;
|
|
6207
|
-
let lastSuccessfulLlmModelId;
|
|
6208
6137
|
let contextUsage;
|
|
6209
6138
|
const modelFallbackRejections = [];
|
|
6210
6139
|
const promptBudget = ctx.promptBudget;
|
|
@@ -6222,11 +6151,7 @@ function createExecuteLlmStage(dependencies) {
|
|
|
6222
6151
|
streamEventHandler,
|
|
6223
6152
|
ctx.signal,
|
|
6224
6153
|
{
|
|
6225
|
-
|
|
6226
|
-
cloudQuotaFallbackAppliedModelId = readNonEmptyString3(fallbackModelId);
|
|
6227
|
-
},
|
|
6228
|
-
onLlmAttemptSucceeded(activeModelId, attemptContextUsage) {
|
|
6229
|
-
lastSuccessfulLlmModelId = readNonEmptyString3(activeModelId);
|
|
6154
|
+
onLlmAttemptSucceeded(_activeModelId, attemptContextUsage) {
|
|
6230
6155
|
contextUsage = attemptContextUsage;
|
|
6231
6156
|
},
|
|
6232
6157
|
onModelFallbackApplied(info) {
|
|
@@ -6322,12 +6247,10 @@ function createExecuteLlmStage(dependencies) {
|
|
|
6322
6247
|
});
|
|
6323
6248
|
}
|
|
6324
6249
|
return {
|
|
6325
|
-
cloudQuotaFallbackAppliedModelId,
|
|
6326
6250
|
modelFallbackAudit,
|
|
6327
6251
|
llmCallStartedAt,
|
|
6328
6252
|
llmResp,
|
|
6329
6253
|
llmCallDurationMs,
|
|
6330
|
-
executorLocalPatch: lastSuccessfulLlmModelId ? { lastSuccessfulLlmModelId } : void 0,
|
|
6331
6254
|
contextUsage
|
|
6332
6255
|
};
|
|
6333
6256
|
}
|
|
@@ -7244,18 +7167,16 @@ function createPrepareCallStage(dependencies) {
|
|
|
7244
7167
|
"toolDefinitionTokens"
|
|
7245
7168
|
],
|
|
7246
7169
|
async run(ctx) {
|
|
7247
|
-
const
|
|
7248
|
-
const requestedModelId = lockedRunModelId ?? ctx.request.model_id;
|
|
7170
|
+
const requestedModelId = ctx.request.model_id;
|
|
7249
7171
|
const modelId = dependencies.modelResolver.resolveModelId(requestedModelId);
|
|
7250
7172
|
await emitAuditEnvelope(ctx.audit, {
|
|
7251
7173
|
action: "model.select",
|
|
7252
7174
|
actor: { kind: "system" },
|
|
7253
7175
|
decision: {
|
|
7254
7176
|
outcome: "recorded",
|
|
7255
|
-
reason:
|
|
7177
|
+
reason: requestedModelId ? "request model id" : "default model resolver",
|
|
7256
7178
|
metadata: {
|
|
7257
7179
|
requestedModelId,
|
|
7258
|
-
lockedRunModelId,
|
|
7259
7180
|
selectedModelId: modelId
|
|
7260
7181
|
}
|
|
7261
7182
|
},
|
|
@@ -7302,10 +7223,6 @@ function createPrepareCallStage(dependencies) {
|
|
|
7302
7223
|
if (ctx.executorLocal?.lockRequestedModelId === true) {
|
|
7303
7224
|
llmOptions.allow_model_fallback = false;
|
|
7304
7225
|
}
|
|
7305
|
-
const isRunContinuation = ctx.executorLocal?.llmInvocationKind === "continuation";
|
|
7306
|
-
if (dependencies.cloudQuotaFallbackModelId && modelConfig?.billing_mode === "cloud" && modelId !== dependencies.cloudQuotaFallbackModelId && isRunContinuation && ctx.executorLocal?.lockRequestedModelId !== true) {
|
|
7307
|
-
llmOptions.cloud_quota_fallback_model_id = dependencies.cloudQuotaFallbackModelId;
|
|
7308
|
-
}
|
|
7309
7226
|
const effectiveEffort = resolveEffectiveEffort(
|
|
7310
7227
|
ctx.request.reasoning_effort,
|
|
7311
7228
|
modelConfig?.reasoning
|
|
@@ -7422,12 +7339,11 @@ function applyCalibration(rawLocalTotal, imageInputTokens, coefficient) {
|
|
|
7422
7339
|
}
|
|
7423
7340
|
|
|
7424
7341
|
// src/runtime-kernel/graph-engine/executor.ts
|
|
7425
|
-
var
|
|
7342
|
+
var logger5 = new Logger("GraphAgentExecutor");
|
|
7426
7343
|
var GraphAgentExecutor = class {
|
|
7427
7344
|
llmCaller;
|
|
7428
7345
|
toolRuntime;
|
|
7429
7346
|
contextBuilder;
|
|
7430
|
-
cloudQuotaFallbackModelId;
|
|
7431
7347
|
modelResolver;
|
|
7432
7348
|
modelCatalog;
|
|
7433
7349
|
telemetryPort;
|
|
@@ -7439,7 +7355,6 @@ var GraphAgentExecutor = class {
|
|
|
7439
7355
|
this.llmCaller = dependencies.llmCaller;
|
|
7440
7356
|
this.toolRuntime = dependencies.toolRuntime;
|
|
7441
7357
|
this.contextBuilder = dependencies.contextBuilder;
|
|
7442
|
-
this.cloudQuotaFallbackModelId = readNonEmptyString3(dependencies.cloudQuotaFallbackModelId);
|
|
7443
7358
|
this.modelCatalog = dependencies.modelCatalog ?? createEmptyModelCatalog();
|
|
7444
7359
|
this.modelResolver = dependencies.modelResolver ?? new ModelResolver({
|
|
7445
7360
|
modelCatalog: this.modelCatalog
|
|
@@ -7456,8 +7371,7 @@ var GraphAgentExecutor = class {
|
|
|
7456
7371
|
createPrepareCallStage({
|
|
7457
7372
|
modelResolver: this.modelResolver,
|
|
7458
7373
|
modelCatalog: this.modelCatalog,
|
|
7459
|
-
toolCatalog: this.toolRuntime
|
|
7460
|
-
cloudQuotaFallbackModelId: this.cloudQuotaFallbackModelId
|
|
7374
|
+
toolCatalog: this.toolRuntime
|
|
7461
7375
|
}),
|
|
7462
7376
|
createBuildContextStage({
|
|
7463
7377
|
contextBuilder: this.contextBuilder
|
|
@@ -7479,7 +7393,7 @@ var GraphAgentExecutor = class {
|
|
|
7479
7393
|
}),
|
|
7480
7394
|
createBuildDecisionStage()
|
|
7481
7395
|
];
|
|
7482
|
-
this.middlewares = [llmTelemetryMiddleware
|
|
7396
|
+
this.middlewares = [llmTelemetryMiddleware];
|
|
7483
7397
|
}
|
|
7484
7398
|
async tick(input, eventHandler) {
|
|
7485
7399
|
const ctx = {
|
|
@@ -7504,7 +7418,7 @@ var GraphAgentExecutor = class {
|
|
|
7504
7418
|
audit: this.auditPort,
|
|
7505
7419
|
tokenizer: this.tokenizer
|
|
7506
7420
|
};
|
|
7507
|
-
|
|
7421
|
+
logger5.info("[GraphAgentExecutor] tick \u8C03\u7528", {
|
|
7508
7422
|
stream: input.stream === true,
|
|
7509
7423
|
hasEventHandler: Boolean(eventHandler),
|
|
7510
7424
|
hasSummarizationCallbacks: Boolean(input.summarizationCallbacks)
|
|
@@ -8527,7 +8441,7 @@ var LlmNodeEventBridge = class {
|
|
|
8527
8441
|
};
|
|
8528
8442
|
|
|
8529
8443
|
// src/runtime-kernel/graph-engine/nodes/llmNode.ts
|
|
8530
|
-
var
|
|
8444
|
+
var logger6 = new Logger("LlmNode");
|
|
8531
8445
|
var LlmNode = class {
|
|
8532
8446
|
id = "llm";
|
|
8533
8447
|
reasoner;
|
|
@@ -8536,7 +8450,7 @@ var LlmNode = class {
|
|
|
8536
8450
|
}
|
|
8537
8451
|
async run(state) {
|
|
8538
8452
|
const local = state.local ?? {};
|
|
8539
|
-
|
|
8453
|
+
logger6.info("[LlmNode] \u5F00\u59CB\u6267\u884C LLM \u8282\u70B9", {
|
|
8540
8454
|
localKeys: Object.keys(local)
|
|
8541
8455
|
});
|
|
8542
8456
|
const graphLocal = readGraphAgentLocal(state.local);
|
|
@@ -8551,12 +8465,12 @@ var LlmNode = class {
|
|
|
8551
8465
|
signal,
|
|
8552
8466
|
history
|
|
8553
8467
|
} = graphLocal;
|
|
8554
|
-
|
|
8468
|
+
logger6.info("[LlmNode] \u5DF2\u52A0\u8F7D\u5386\u53F2\u4E8B\u4EF6", {
|
|
8555
8469
|
historyCount: history.length,
|
|
8556
8470
|
hasSummarizationCallbacks: Boolean(summarizationCallbacks)
|
|
8557
8471
|
});
|
|
8558
8472
|
if (!request) {
|
|
8559
|
-
|
|
8473
|
+
logger6.warn("Request object is missing, yielding.");
|
|
8560
8474
|
return { kind: "yield", events: [] };
|
|
8561
8475
|
}
|
|
8562
8476
|
const turnId = requireRuntimeIdentity(graphLocal.turnId, "turnId");
|
|
@@ -8649,12 +8563,12 @@ var LlmNode = class {
|
|
|
8649
8563
|
...nodeState.streamRuntimeEvents,
|
|
8650
8564
|
...contextUsageEvent ? [contextUsageEvent] : []
|
|
8651
8565
|
];
|
|
8652
|
-
|
|
8566
|
+
logger6.info("[LlmNode] \u5386\u53F2\u4E8B\u4EF6\u5DF2\u66F4\u65B0", {
|
|
8653
8567
|
previousCount: history.length,
|
|
8654
8568
|
nextCount: patch.history.length,
|
|
8655
8569
|
streamedEventCount: nodeState.streamRuntimeEvents.length
|
|
8656
8570
|
});
|
|
8657
|
-
|
|
8571
|
+
logger6.info("[LlmNode] \u6267\u884C\u5668\u51B3\u7B56\u5B8C\u6210", {
|
|
8658
8572
|
decisionKind: decision.kind,
|
|
8659
8573
|
emittedEventCount: combinedEvents.length
|
|
8660
8574
|
});
|
|
@@ -8676,7 +8590,7 @@ var LlmNode = class {
|
|
|
8676
8590
|
}
|
|
8677
8591
|
case "error": {
|
|
8678
8592
|
const { name, message, stack } = decision.error;
|
|
8679
|
-
|
|
8593
|
+
logger6.error("[LlmNode] Executor returned an error", { name, message, stack });
|
|
8680
8594
|
return { kind: "yield", events: combinedEvents };
|
|
8681
8595
|
}
|
|
8682
8596
|
default: {
|
|
@@ -8782,7 +8696,7 @@ async function resolveToolModelInput(input) {
|
|
|
8782
8696
|
}
|
|
8783
8697
|
|
|
8784
8698
|
// src/runtime-kernel/graph-engine/nodes/toolNode.finalAnswerProjector.ts
|
|
8785
|
-
function
|
|
8699
|
+
function readNonEmptyString4(value) {
|
|
8786
8700
|
if (typeof value !== "string") {
|
|
8787
8701
|
return void 0;
|
|
8788
8702
|
}
|
|
@@ -8790,7 +8704,7 @@ function readNonEmptyString5(value) {
|
|
|
8790
8704
|
return normalized.length > 0 ? normalized : void 0;
|
|
8791
8705
|
}
|
|
8792
8706
|
function resolveFinalAnswerFromToolControl(finalAnswer) {
|
|
8793
|
-
return
|
|
8707
|
+
return readNonEmptyString4(finalAnswer);
|
|
8794
8708
|
}
|
|
8795
8709
|
|
|
8796
8710
|
// src/runtime-kernel/graph-engine/nodes/toolNode.helpers.ts
|
|
@@ -9046,7 +8960,7 @@ function buildErrorLocalState(params) {
|
|
|
9046
8960
|
}
|
|
9047
8961
|
|
|
9048
8962
|
// src/runtime-kernel/tools/argNormalizer.ts
|
|
9049
|
-
var
|
|
8963
|
+
var logger7 = new Logger("ToolArgNormalizer");
|
|
9050
8964
|
function isRecord10(v) {
|
|
9051
8965
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
9052
8966
|
}
|
|
@@ -9066,7 +8980,7 @@ function joinPath(basePath, segment) {
|
|
|
9066
8980
|
function logJsonEncodedNormalization(expectedType, options) {
|
|
9067
8981
|
const toolPrefix = options.toolName ? `${options.toolName}.` : "";
|
|
9068
8982
|
const path = options.path ?? "<root>";
|
|
9069
|
-
|
|
8983
|
+
logger7.warn("normalized JSON-encoded tool argument", {
|
|
9070
8984
|
expectedType,
|
|
9071
8985
|
path: `${toolPrefix}${path}`
|
|
9072
8986
|
});
|
|
@@ -9422,7 +9336,7 @@ function stripRuntimeReservedToolContextPatch(patch) {
|
|
|
9422
9336
|
}
|
|
9423
9337
|
|
|
9424
9338
|
// src/runtime-kernel/graph-engine/nodes/toolNode.eventBridge.ts
|
|
9425
|
-
var
|
|
9339
|
+
var logger8 = new Logger("ToolNode");
|
|
9426
9340
|
var ToolNodeEventBridge = class {
|
|
9427
9341
|
constructor(deps) {
|
|
9428
9342
|
this.deps = deps;
|
|
@@ -9444,7 +9358,7 @@ var ToolNodeEventBridge = class {
|
|
|
9444
9358
|
status,
|
|
9445
9359
|
payload: { ...payload }
|
|
9446
9360
|
};
|
|
9447
|
-
|
|
9361
|
+
logger8.info("[ToolNode] \u53D1\u51FA tool_process \u4E8B\u4EF6", {
|
|
9448
9362
|
phase,
|
|
9449
9363
|
status,
|
|
9450
9364
|
toolName: this.deps.toolName,
|
|
@@ -9484,7 +9398,7 @@ var ToolNodeEventBridge = class {
|
|
|
9484
9398
|
const answerId = generateAnswerSegmentId();
|
|
9485
9399
|
const id = answerId;
|
|
9486
9400
|
const timestamp = Date.now();
|
|
9487
|
-
|
|
9401
|
+
logger8.info("[ToolNode] \u5DE5\u5177\u8F93\u51FA\u6620\u5C04\u4E3A final_answer", {
|
|
9488
9402
|
sourceToolName: params.sourceToolName,
|
|
9489
9403
|
toolCallId: this.deps.toolCallId,
|
|
9490
9404
|
conversationId: this.deps.conversationId,
|
|
@@ -9542,7 +9456,7 @@ var ToolNodeEventBridge = class {
|
|
|
9542
9456
|
};
|
|
9543
9457
|
|
|
9544
9458
|
// src/runtime-kernel/graph-engine/nodes/toolNode.executionSetup.ts
|
|
9545
|
-
var
|
|
9459
|
+
var logger9 = new Logger("ToolNode");
|
|
9546
9460
|
function parseToolArgs(call) {
|
|
9547
9461
|
const rawArguments = typeof call.function?.arguments === "string" ? call.function.arguments : "";
|
|
9548
9462
|
if (!rawArguments.trim()) {
|
|
@@ -9562,7 +9476,7 @@ function parseToolArgs(call) {
|
|
|
9562
9476
|
return { ok: true, value: parsed };
|
|
9563
9477
|
} catch (error) {
|
|
9564
9478
|
const reason = error instanceof Error ? error.message : "Unknown JSON parse error";
|
|
9565
|
-
|
|
9479
|
+
logger9.warn("failed to parse tool arguments", { error });
|
|
9566
9480
|
return {
|
|
9567
9481
|
ok: false,
|
|
9568
9482
|
error: `Tool arguments are not valid JSON: ${reason}`
|
|
@@ -9963,7 +9877,7 @@ async function claimPendingUserInputs(state, result) {
|
|
|
9963
9877
|
}
|
|
9964
9878
|
|
|
9965
9879
|
// src/runtime-kernel/graph-engine/nodes/toolNode.ts
|
|
9966
|
-
var
|
|
9880
|
+
var logger10 = new Logger("ToolNode");
|
|
9967
9881
|
function isAbortSignal(value) {
|
|
9968
9882
|
return value !== null && typeof value === "object" && "aborted" in value;
|
|
9969
9883
|
}
|
|
@@ -10176,7 +10090,7 @@ var ToolNode = class {
|
|
|
10176
10090
|
throw abortError;
|
|
10177
10091
|
}
|
|
10178
10092
|
const prepared = prepareToolNodeContext(state);
|
|
10179
|
-
|
|
10093
|
+
logger10.info("[ToolNode] \u5F00\u59CB\u6267\u884C\u5DE5\u5177\u8282\u70B9", {
|
|
10180
10094
|
conversationId: prepared.conversationId,
|
|
10181
10095
|
turnId: prepared.turnId,
|
|
10182
10096
|
pendingCallCount: calls.length
|
|
@@ -10191,7 +10105,7 @@ var ToolNode = class {
|
|
|
10191
10105
|
toolCatalog: this.toolRuntime
|
|
10192
10106
|
});
|
|
10193
10107
|
if (!execution) {
|
|
10194
|
-
|
|
10108
|
+
logger10.warn("no tool name found in call");
|
|
10195
10109
|
return { kind: "yield", events: [] };
|
|
10196
10110
|
}
|
|
10197
10111
|
if (typeof execution.protocolError === "string") {
|
|
@@ -10231,7 +10145,7 @@ var ToolNode = class {
|
|
|
10231
10145
|
call,
|
|
10232
10146
|
context: prepared.toolContext,
|
|
10233
10147
|
abortGraceMs: this.abortGraceMs,
|
|
10234
|
-
onAbandon: () =>
|
|
10148
|
+
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", {
|
|
10235
10149
|
toolName: execution.toolName,
|
|
10236
10150
|
toolCallId: execution.toolCallId,
|
|
10237
10151
|
conversationId: prepared.conversationId,
|
|
@@ -10401,7 +10315,7 @@ var ToolNode = class {
|
|
|
10401
10315
|
runtimeEvents: context.bridge.getRuntimeEvents()
|
|
10402
10316
|
});
|
|
10403
10317
|
if (control?.terminateRun) {
|
|
10404
|
-
|
|
10318
|
+
logger10.info("[ToolNode] \u6536\u5230 control.terminateRun\uFF0C\u6267\u884C\u5B8C\u5DE5\u5177\u540E\u76F4\u63A5 yield \u7ED3\u675F\u672C\u8F6E run", {
|
|
10405
10319
|
toolName: context.toolName,
|
|
10406
10320
|
toolCallId: context.toolCallId,
|
|
10407
10321
|
conversationId: context.conversationId,
|
|
@@ -10410,7 +10324,7 @@ var ToolNode = class {
|
|
|
10410
10324
|
return { kind: "yield", events: context.bridge.getRuntimeEvents() };
|
|
10411
10325
|
}
|
|
10412
10326
|
if (remainingCalls.length === 0 && context.local.toolBatchCompletionMode === "yield_after_batch") {
|
|
10413
|
-
|
|
10327
|
+
logger10.info("[ToolNode] \u5DE5\u5177\u6279\u6B21\u5DF2\u7ED3\u7B97\uFF0C\u6309 Host \u7B56\u7565\u76F4\u63A5 yield", {
|
|
10414
10328
|
toolName: context.toolName,
|
|
10415
10329
|
toolCallId: context.toolCallId,
|
|
10416
10330
|
conversationId: context.conversationId,
|
|
@@ -10857,6 +10771,8 @@ var executor = z.object({
|
|
|
10857
10771
|
lastStepsHintThreshold: counter.optional(),
|
|
10858
10772
|
systemReminderPolicy: AgentSpecSystemReminderPolicy.optional(),
|
|
10859
10773
|
toolObservationPolicy: AgentSpecToolObservationGovernancePolicy.optional(),
|
|
10774
|
+
// 已删除字段:0.45 及更早的 checkpoint 可能带 lastSuccessfulLlmModelId,0.46 及更早的可能带云端额度兜底留下的
|
|
10775
|
+
// runLockedModelId;照常接受,读入时丢弃(兜底已移除,恢复后按请求的模型继续)。
|
|
10860
10776
|
runLockedModelId: z.string().optional(),
|
|
10861
10777
|
lastSuccessfulLlmModelId: z.string().optional(),
|
|
10862
10778
|
llmInvocationKind: z.enum(["user_initiated", "continuation"]).optional(),
|
|
@@ -10867,7 +10783,7 @@ var executor = z.object({
|
|
|
10867
10783
|
committedCount: counter,
|
|
10868
10784
|
lastCommittedFingerprint: z.string().optional()
|
|
10869
10785
|
}).strict().optional()
|
|
10870
|
-
}).strict();
|
|
10786
|
+
}).strict().transform(({ lastSuccessfulLlmModelId: _retired, runLockedModelId: _retiredLock, ...state }) => state);
|
|
10871
10787
|
var checkpoint = z.object({
|
|
10872
10788
|
nodeId: z.string().min(1),
|
|
10873
10789
|
schemaVersion: z.literal(ENGINE_STATE_SCHEMA_VERSION).optional(),
|
|
@@ -11181,7 +11097,7 @@ __export(execution_exports, {
|
|
|
11181
11097
|
});
|
|
11182
11098
|
|
|
11183
11099
|
// src/runtime-kernel/execution/event-bus.ts
|
|
11184
|
-
var
|
|
11100
|
+
var logger11 = new Logger("EventBus");
|
|
11185
11101
|
var TypedEventEmitter = class {
|
|
11186
11102
|
listeners = /* @__PURE__ */ new Map();
|
|
11187
11103
|
maxListeners = 10;
|
|
@@ -11189,7 +11105,7 @@ var TypedEventEmitter = class {
|
|
|
11189
11105
|
const listeners = this.getListeners(event);
|
|
11190
11106
|
listeners.add(listener);
|
|
11191
11107
|
if (listeners.size > this.maxListeners) {
|
|
11192
|
-
|
|
11108
|
+
logger11.warn("EventBus listener count exceeds configured max", {
|
|
11193
11109
|
event: String(event),
|
|
11194
11110
|
count: listeners.size,
|
|
11195
11111
|
maxListeners: this.maxListeners
|
|
@@ -11249,7 +11165,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
11249
11165
|
super();
|
|
11250
11166
|
this.executionId = executionId;
|
|
11251
11167
|
this.setMaxListeners(30);
|
|
11252
|
-
|
|
11168
|
+
logger11.info(`EventBus created for execution ${this.executionId}`);
|
|
11253
11169
|
}
|
|
11254
11170
|
/**
|
|
11255
11171
|
* 发布一个事件到总线
|
|
@@ -11258,7 +11174,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
11258
11174
|
publish(envelope) {
|
|
11259
11175
|
if (envelope.trace.execution_id !== this.executionId) {
|
|
11260
11176
|
const error = new Error("EventEnvelope execution_id does not match EventBus instance.");
|
|
11261
|
-
|
|
11177
|
+
logger11.error("Mismatched execution_id", {
|
|
11262
11178
|
busExecutionId: this.executionId,
|
|
11263
11179
|
eventExecutionId: envelope.trace.execution_id,
|
|
11264
11180
|
eventSeq: envelope.seq
|
|
@@ -11270,7 +11186,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
11270
11186
|
const error = new Error(
|
|
11271
11187
|
"EventBus only accepts RuntimeEvent with formal run routing identity."
|
|
11272
11188
|
);
|
|
11273
|
-
|
|
11189
|
+
logger11.error("RuntimeEvent is missing formal run routing identity", {
|
|
11274
11190
|
executionId: this.executionId,
|
|
11275
11191
|
eventId: envelope.payload.id,
|
|
11276
11192
|
eventType: envelope.payload.type
|
|
@@ -11284,14 +11200,14 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
11284
11200
|
* 关闭总线,清理所有监听器
|
|
11285
11201
|
*/
|
|
11286
11202
|
close() {
|
|
11287
|
-
|
|
11203
|
+
logger11.info(`Closing EventBus for execution ${this.executionId}`);
|
|
11288
11204
|
this.emit("close");
|
|
11289
11205
|
this.removeAllListeners();
|
|
11290
11206
|
}
|
|
11291
11207
|
};
|
|
11292
11208
|
|
|
11293
11209
|
// src/runtime-kernel/execution/sequencer.ts
|
|
11294
|
-
var
|
|
11210
|
+
var logger12 = new Logger("EventSequencer");
|
|
11295
11211
|
var EventSequencer = class {
|
|
11296
11212
|
executionId;
|
|
11297
11213
|
traceId;
|
|
@@ -11299,7 +11215,7 @@ var EventSequencer = class {
|
|
|
11299
11215
|
constructor(conversationId, traceId) {
|
|
11300
11216
|
this.executionId = generateExecutionId();
|
|
11301
11217
|
this.traceId = traceId || generateTraceId();
|
|
11302
|
-
|
|
11218
|
+
logger12.info(`EventSequencer created for conversation ${conversationId}`, {
|
|
11303
11219
|
executionId: this.executionId,
|
|
11304
11220
|
traceId: this.traceId
|
|
11305
11221
|
});
|
|
@@ -12157,7 +12073,7 @@ var ThoughtStreamSegmenter = class {
|
|
|
12157
12073
|
};
|
|
12158
12074
|
|
|
12159
12075
|
// src/runtime-kernel/llm/streaming-adapter.ts
|
|
12160
|
-
var
|
|
12076
|
+
var logger13 = new Logger("LlmCaller");
|
|
12161
12077
|
var CanonicalInferenceFailureError = class extends Error {
|
|
12162
12078
|
errorCode;
|
|
12163
12079
|
recoverable;
|
|
@@ -12381,7 +12297,7 @@ async function callLlmStream(params) {
|
|
|
12381
12297
|
} catch (error) {
|
|
12382
12298
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
12383
12299
|
if (normalized.name === "AbortError") {
|
|
12384
|
-
|
|
12300
|
+
logger13.info("Canonical inference \u6536\u5230\u53D6\u6D88\u7EC8\u6001\uFF0C\u4E0D\u53D1\u5E03\u666E\u901A error event", { modelId });
|
|
12385
12301
|
throw normalized;
|
|
12386
12302
|
}
|
|
12387
12303
|
const classification = ErrorClassifier.classify(normalized, {
|
|
@@ -12457,7 +12373,7 @@ var LlmRetryEpisode = class {
|
|
|
12457
12373
|
};
|
|
12458
12374
|
|
|
12459
12375
|
// src/runtime-kernel/llm/retry-fallback-routing.ts
|
|
12460
|
-
var
|
|
12376
|
+
var logger14 = new Logger("LlmCaller");
|
|
12461
12377
|
function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement, fallbackObserver, error, evaluateFallbackPromptCapacity2) {
|
|
12462
12378
|
deps.modelCatalog.getModelById(activeModelId);
|
|
12463
12379
|
const policyDecision = deps.policyEngine.decideOnError(error, {
|
|
@@ -12487,81 +12403,16 @@ function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement
|
|
|
12487
12403
|
reason: "no_eligible_fallback_candidate",
|
|
12488
12404
|
requiredPlacements: requirement.placements
|
|
12489
12405
|
});
|
|
12490
|
-
|
|
12406
|
+
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");
|
|
12491
12407
|
return null;
|
|
12492
12408
|
}
|
|
12493
|
-
|
|
12409
|
+
logger14.warn("Policy \u5207\u6362\u6A21\u578B\u7EE7\u7EED", {
|
|
12494
12410
|
reason: policyDecision.reason,
|
|
12495
12411
|
activeModelId,
|
|
12496
12412
|
fallbackModelId
|
|
12497
12413
|
});
|
|
12498
12414
|
return fallbackModelId;
|
|
12499
12415
|
}
|
|
12500
|
-
function tryCloudQuotaFallback({
|
|
12501
|
-
deps,
|
|
12502
|
-
activeModelId,
|
|
12503
|
-
options,
|
|
12504
|
-
excludedModelIds,
|
|
12505
|
-
requirement,
|
|
12506
|
-
error,
|
|
12507
|
-
fallbackObserver,
|
|
12508
|
-
evaluateFallbackPromptCapacity: evaluateFallbackPromptCapacity2
|
|
12509
|
-
}) {
|
|
12510
|
-
const fallbackModelId = options.cloud_quota_fallback_model_id;
|
|
12511
|
-
if (!fallbackModelId || !ErrorClassifier.isCloudQuotaError(error) || excludedModelIds.has(fallbackModelId)) {
|
|
12512
|
-
return null;
|
|
12513
|
-
}
|
|
12514
|
-
const fallbackConfig = deps.modelCatalog.getModelById(fallbackModelId);
|
|
12515
|
-
if (!fallbackConfig?.api_key) {
|
|
12516
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
12517
|
-
fromModelId: activeModelId,
|
|
12518
|
-
candidateModelId: fallbackModelId,
|
|
12519
|
-
policy: "cloud-quota",
|
|
12520
|
-
reason: "fallback_model_unavailable",
|
|
12521
|
-
requiredPlacements: requirement.placements
|
|
12522
|
-
});
|
|
12523
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\u76EE\u6807\u4E0D\u53EF\u7528\uFF08\u672A\u6CE8\u518C\u6216\u7F3A\u5C11 API Key\uFF09", { fallbackModelId });
|
|
12524
|
-
return null;
|
|
12525
|
-
}
|
|
12526
|
-
const compatibility = evaluateModelInputCompatibility(fallbackConfig, requirement);
|
|
12527
|
-
if (!compatibility.compatible) {
|
|
12528
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
12529
|
-
fromModelId: activeModelId,
|
|
12530
|
-
candidateModelId: fallbackModelId,
|
|
12531
|
-
policy: "cloud-quota",
|
|
12532
|
-
reason: compatibility.reason,
|
|
12533
|
-
requiredPlacements: requirement.placements
|
|
12534
|
-
});
|
|
12535
|
-
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", {
|
|
12536
|
-
fallbackModelId,
|
|
12537
|
-
requiredPlacements: requirement.placements,
|
|
12538
|
-
reason: compatibility.reason
|
|
12539
|
-
});
|
|
12540
|
-
return null;
|
|
12541
|
-
}
|
|
12542
|
-
const capacityAdmission = evaluateFallbackPromptCapacity2?.(fallbackModelId);
|
|
12543
|
-
if (capacityAdmission && !capacityAdmission.admitted) {
|
|
12544
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
12545
|
-
fromModelId: activeModelId,
|
|
12546
|
-
candidateModelId: fallbackModelId,
|
|
12547
|
-
policy: "cloud-quota",
|
|
12548
|
-
reason: capacityAdmission.reason,
|
|
12549
|
-
requiredPlacements: requirement.placements
|
|
12550
|
-
});
|
|
12551
|
-
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", {
|
|
12552
|
-
fallbackModelId,
|
|
12553
|
-
reason: capacityAdmission.reason
|
|
12554
|
-
});
|
|
12555
|
-
return null;
|
|
12556
|
-
}
|
|
12557
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\uFF08run \u5185\u7EED\u8DD1\uFF09", {
|
|
12558
|
-
activeModelId,
|
|
12559
|
-
fallbackModelId,
|
|
12560
|
-
reason: error.message
|
|
12561
|
-
});
|
|
12562
|
-
fallbackObserver?.onCloudQuotaFallbackApplied?.(fallbackModelId);
|
|
12563
|
-
return fallbackModelId;
|
|
12564
|
-
}
|
|
12565
12416
|
|
|
12566
12417
|
// src/runtime-kernel/llm/usage-telemetry.ts
|
|
12567
12418
|
async function callPlainCompletion(inferencePort, modelId, messages, options = {}, signal, traceId) {
|
|
@@ -12684,7 +12535,7 @@ var LlmImageInputError = class extends Error {
|
|
|
12684
12535
|
};
|
|
12685
12536
|
|
|
12686
12537
|
// src/runtime-kernel/llm/retry-fallback.ts
|
|
12687
|
-
var
|
|
12538
|
+
var logger15 = new Logger("LlmCaller");
|
|
12688
12539
|
async function callWithRetryFallback(params) {
|
|
12689
12540
|
const {
|
|
12690
12541
|
deps,
|
|
@@ -12712,11 +12563,9 @@ async function callWithRetryFallback(params) {
|
|
|
12712
12563
|
const retryEpisode = new LlmRetryEpisode(traceId, eventHandler);
|
|
12713
12564
|
let previousAttemptTracker;
|
|
12714
12565
|
if (!clientRetryEnabled) {
|
|
12715
|
-
|
|
12716
|
-
logger16.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
12566
|
+
logger15.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
12717
12567
|
modelId,
|
|
12718
|
-
|
|
12719
|
-
reason: options.retry_policy === "none" ? "options.retry_policy=none" : "model config (cloud billing or enable_client_retry=false)"
|
|
12568
|
+
reason: options.retry_policy === "none" ? "options.retry_policy=none" : "model config enable_client_retry=false"
|
|
12720
12569
|
});
|
|
12721
12570
|
}
|
|
12722
12571
|
try {
|
|
@@ -12752,7 +12601,7 @@ async function callWithRetryFallback(params) {
|
|
|
12752
12601
|
}) : void 0;
|
|
12753
12602
|
try {
|
|
12754
12603
|
if (isRetry) {
|
|
12755
|
-
|
|
12604
|
+
logger15.info("LLM \u8C03\u7528\u91CD\u8BD5", { attempt, configuredMaxRetries });
|
|
12756
12605
|
}
|
|
12757
12606
|
actualAttempts++;
|
|
12758
12607
|
retryEpisode.retrying(actualAttempts);
|
|
@@ -12781,7 +12630,7 @@ async function callWithRetryFallback(params) {
|
|
|
12781
12630
|
if (deps.retryConfig.enableEmptyResponseRetry && !responseContent?.trim() && !toolCallsFromLLM?.length) {
|
|
12782
12631
|
throw new Error("LLM\u8FD4\u56DE\u4E86\u7A7A\u54CD\u5E94");
|
|
12783
12632
|
}
|
|
12784
|
-
|
|
12633
|
+
logger15.debug("LLM \u8C03\u7528\u6210\u529F", { attempts: actualAttempts, maxTotalAttempts });
|
|
12785
12634
|
if (attemptContextUsage) {
|
|
12786
12635
|
fallbackObserver?.onLlmAttemptSucceeded?.(activeModelId, attemptContextUsage);
|
|
12787
12636
|
} else {
|
|
@@ -12792,7 +12641,7 @@ async function callWithRetryFallback(params) {
|
|
|
12792
12641
|
} catch (error) {
|
|
12793
12642
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
12794
12643
|
if (lastError.name === "AbortError") {
|
|
12795
|
-
|
|
12644
|
+
logger15.info("LLM \u8C03\u7528\u5DF2\u53D6\u6D88\uFF0C\u4E0D\u8FDB\u5165 provider failure \u5206\u7C7B\u4E0E\u91CD\u8BD5\u6D41\u7A0B", {
|
|
12796
12645
|
attempt: attempt + 1,
|
|
12797
12646
|
actualAttempts,
|
|
12798
12647
|
maxTotalAttempts,
|
|
@@ -12811,7 +12660,7 @@ async function callWithRetryFallback(params) {
|
|
|
12811
12660
|
total_attempts: actualAttempts,
|
|
12812
12661
|
error_code: classification.errorCode
|
|
12813
12662
|
};
|
|
12814
|
-
|
|
12663
|
+
logger15.error("LLM \u8C03\u7528\u5931\u8D25", {
|
|
12815
12664
|
attempt: attempt + 1,
|
|
12816
12665
|
maxAttempts: currentMaxRetries + 1,
|
|
12817
12666
|
actualAttempts,
|
|
@@ -12820,7 +12669,7 @@ async function callWithRetryFallback(params) {
|
|
|
12820
12669
|
});
|
|
12821
12670
|
previousAttemptTracker = attemptTracker;
|
|
12822
12671
|
if (!hasLlmAttemptBudgetRemaining({ actualAttempts, maxTotalAttempts })) {
|
|
12823
|
-
|
|
12672
|
+
logger15.error("\u5DF2\u8FBE\u5230 LLM \u603B\u8C03\u7528\u6B21\u6570\u4E0A\u9650\uFF0C\u505C\u6B62\u91CD\u8BD5/\u5207\u6A21\u578B", {
|
|
12824
12673
|
actualAttempts,
|
|
12825
12674
|
maxTotalAttempts
|
|
12826
12675
|
});
|
|
@@ -12850,37 +12699,15 @@ async function callWithRetryFallback(params) {
|
|
|
12850
12699
|
attempt -= 1;
|
|
12851
12700
|
continue;
|
|
12852
12701
|
}
|
|
12853
|
-
const quotaFallbackModelId = tryCloudQuotaFallback({
|
|
12854
|
-
deps,
|
|
12855
|
-
activeModelId,
|
|
12856
|
-
options,
|
|
12857
|
-
excludedModelIds,
|
|
12858
|
-
requirement,
|
|
12859
|
-
error: lastError,
|
|
12860
|
-
fallbackObserver,
|
|
12861
|
-
evaluateFallbackPromptCapacity: invocationContext?.evaluateFallbackPromptCapacity
|
|
12862
|
-
});
|
|
12863
|
-
if (quotaFallbackModelId) {
|
|
12864
|
-
fallbackObserver?.onModelFallbackApplied?.({
|
|
12865
|
-
fromModelId: activeModelId,
|
|
12866
|
-
toModelId: quotaFallbackModelId,
|
|
12867
|
-
reason: lastError.message,
|
|
12868
|
-
policy: "cloud-quota"
|
|
12869
|
-
});
|
|
12870
|
-
activeModelId = quotaFallbackModelId;
|
|
12871
|
-
excludedModelIds.add(quotaFallbackModelId);
|
|
12872
|
-
attempt -= 1;
|
|
12873
|
-
continue;
|
|
12874
|
-
}
|
|
12875
12702
|
}
|
|
12876
12703
|
if (classification.category === "non_retryable" /* NON_RETRYABLE */) {
|
|
12877
|
-
|
|
12704
|
+
logger15.error("\u9519\u8BEF\u4E0D\u53EF\u91CD\u8BD5\uFF0C\u76F4\u63A5\u5931\u8D25", { reason: classification.reason });
|
|
12878
12705
|
retryEpisode.finish("failed", failedRetryState);
|
|
12879
12706
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
12880
12707
|
throw lastError;
|
|
12881
12708
|
}
|
|
12882
12709
|
if (attempt >= configuredMaxRetries || categoryRetries[category] >= currentMaxRetries) {
|
|
12883
|
-
|
|
12710
|
+
logger15.error("\u5DF2\u8FBE\u5230\u6700\u5927\u91CD\u8BD5\u6B21\u6570\uFF0C\u653E\u5F03\u91CD\u8BD5", { maxRetries: currentMaxRetries });
|
|
12884
12711
|
retryEpisode.finish("exhausted", failedRetryState);
|
|
12885
12712
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
12886
12713
|
throw lastError;
|
|
@@ -12892,9 +12719,9 @@ async function callWithRetryFallback(params) {
|
|
|
12892
12719
|
6e4
|
|
12893
12720
|
);
|
|
12894
12721
|
if (classification.category === "rate_limit" /* RATE_LIMIT */) {
|
|
12895
|
-
|
|
12722
|
+
logger15.warn("\u901F\u7387\u9650\u5236\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
12896
12723
|
} else if (classification.category === "retryable" /* RETRYABLE */) {
|
|
12897
|
-
|
|
12724
|
+
logger15.warn("\u53EF\u91CD\u8BD5\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
12898
12725
|
}
|
|
12899
12726
|
throwIfAborted(signal, "\u5EF6\u8FDF\u7B49\u5F85\u524D\u68C0\u6D4B\u5230\u53D6\u6D88\u4FE1\u53F7\uFF0C\u505C\u6B62\u91CD\u8BD5");
|
|
12900
12727
|
categoryRetries[category] += 1;
|
|
@@ -12931,16 +12758,11 @@ function waitForRetry(delayMs, signal) {
|
|
|
12931
12758
|
}
|
|
12932
12759
|
function isClientRetryEnabledForModel(modelCatalog, modelId, options) {
|
|
12933
12760
|
if (options.retry_policy === "none") return false;
|
|
12934
|
-
|
|
12935
|
-
if (cfg?.billing_mode === "cloud") return false;
|
|
12936
|
-
if (options.retry_policy === "client") return true;
|
|
12937
|
-
if (!cfg) return true;
|
|
12938
|
-
if (cfg.enable_client_retry === false) return false;
|
|
12939
|
-
return true;
|
|
12761
|
+
return modelCatalog.getModelById(modelId)?.enable_client_retry !== false;
|
|
12940
12762
|
}
|
|
12941
12763
|
function throwIfAborted(signal, message) {
|
|
12942
12764
|
if (!signal?.aborted) return;
|
|
12943
|
-
|
|
12765
|
+
logger15.info(message);
|
|
12944
12766
|
const reason = signal.reason;
|
|
12945
12767
|
if (reason instanceof Error && reason.name === "AbortError") throw reason;
|
|
12946
12768
|
const reasonText = typeof reason === "string" && reason.trim().length > 0 ? reason : "stream_interrupted";
|
|
@@ -13258,7 +13080,7 @@ async function recoverChildRunEventsFromCheckpoint(params) {
|
|
|
13258
13080
|
}
|
|
13259
13081
|
|
|
13260
13082
|
// src/runtime-kernel/child-runs/childRunInvoker.ts
|
|
13261
|
-
var
|
|
13083
|
+
var logger16 = new Logger("ChildRunInvoker");
|
|
13262
13084
|
var ChildRunInvoker = class {
|
|
13263
13085
|
modelResolver;
|
|
13264
13086
|
createLlmNode;
|
|
@@ -13300,7 +13122,7 @@ var ChildRunInvoker = class {
|
|
|
13300
13122
|
const resolvedParentRunId = parentRunId ?? parentToolContext.runId;
|
|
13301
13123
|
const depthDecision = decideChildRunDepth({ parentToolContext });
|
|
13302
13124
|
if (!depthDecision.allowed) {
|
|
13303
|
-
|
|
13125
|
+
logger16.warn("child-run \u6DF1\u5EA6\u8D85\u8FC7\u4E0A\u9650\uFF0C\u62D2\u7EDD\u7EE7\u7EED\u9012\u5F52\u6267\u884C", {
|
|
13304
13126
|
runId: childRunId,
|
|
13305
13127
|
parentRunId: resolvedParentRunId,
|
|
13306
13128
|
parentDepth: depthDecision.parentDepth,
|
|
@@ -13317,7 +13139,7 @@ var ChildRunInvoker = class {
|
|
|
13317
13139
|
};
|
|
13318
13140
|
}
|
|
13319
13141
|
if (abortSignal?.aborted || parentToolContext.abortSignal?.aborted) {
|
|
13320
|
-
|
|
13142
|
+
logger16.info("child-run \u5728\u4EFB\u52A1\u63A5\u7EB3\u524D\u5DF2\u53D6\u6D88", {
|
|
13321
13143
|
runId: childRunId,
|
|
13322
13144
|
parentRunId: resolvedParentRunId
|
|
13323
13145
|
});
|
|
@@ -13341,7 +13163,7 @@ var ChildRunInvoker = class {
|
|
|
13341
13163
|
}
|
|
13342
13164
|
const turnId = config.initialInput?.turnId ?? generateTurnId();
|
|
13343
13165
|
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");
|
|
13344
|
-
|
|
13166
|
+
logger16.info(`\u542F\u52A8 child-run: ${agentConfig.id}`, {
|
|
13345
13167
|
conversationId: runtimeConversationId,
|
|
13346
13168
|
checkpointKey: internalCheckpointKey,
|
|
13347
13169
|
maxSteps,
|
|
@@ -13459,7 +13281,7 @@ var ChildRunInvoker = class {
|
|
|
13459
13281
|
);
|
|
13460
13282
|
finalAnswer = extractFinalAnswer(allEvents);
|
|
13461
13283
|
lastProgress = finalAnswer ? void 0 : extractLastProgress(allEvents);
|
|
13462
|
-
|
|
13284
|
+
logger16.info("child-run \u6267\u884C\u5B8C\u6210", {
|
|
13463
13285
|
stepCount,
|
|
13464
13286
|
eventCount: allEvents.length,
|
|
13465
13287
|
hasFinalAnswer: !!finalAnswer,
|
|
@@ -13489,13 +13311,13 @@ var ChildRunInvoker = class {
|
|
|
13489
13311
|
cancelled = abortSignal?.aborted === true || isAbortError2(err);
|
|
13490
13312
|
error = err instanceof Error ? err.message : String(err);
|
|
13491
13313
|
if (cancelled) {
|
|
13492
|
-
|
|
13314
|
+
logger16.info("child-run \u6267\u884C\u53D6\u6D88", {
|
|
13493
13315
|
runId: childRunId,
|
|
13494
13316
|
parentRunId: resolvedParentRunId,
|
|
13495
13317
|
message: error
|
|
13496
13318
|
});
|
|
13497
13319
|
} else {
|
|
13498
|
-
|
|
13320
|
+
logger16.error(
|
|
13499
13321
|
"child-run \u6267\u884C\u5931\u8D25:",
|
|
13500
13322
|
err instanceof Error ? {
|
|
13501
13323
|
name: err.name,
|
|
@@ -13591,7 +13413,7 @@ var ChildRunInvoker = class {
|
|
|
13591
13413
|
function isAbortError2(error) {
|
|
13592
13414
|
return error instanceof Error && error.name === "AbortError";
|
|
13593
13415
|
}
|
|
13594
|
-
function
|
|
13416
|
+
function readNonEmptyString5(value) {
|
|
13595
13417
|
if (typeof value !== "string") {
|
|
13596
13418
|
return void 0;
|
|
13597
13419
|
}
|
|
@@ -13599,7 +13421,7 @@ function readNonEmptyString6(value) {
|
|
|
13599
13421
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
13600
13422
|
}
|
|
13601
13423
|
function resolveChildRunConversationId(params) {
|
|
13602
|
-
const conversationId =
|
|
13424
|
+
const conversationId = readNonEmptyString5(params.explicitConversationId) ?? readNonEmptyString5(params.parentToolContext.conversationId);
|
|
13603
13425
|
if (!conversationId) {
|
|
13604
13426
|
throw new Error(
|
|
13605
13427
|
"ChildRunInvoker requires conversationId from admission or parent ToolContext."
|
|
@@ -13608,7 +13430,7 @@ function resolveChildRunConversationId(params) {
|
|
|
13608
13430
|
return conversationId;
|
|
13609
13431
|
}
|
|
13610
13432
|
function resolveChildRunModelId(params) {
|
|
13611
|
-
const explicitModelId =
|
|
13433
|
+
const explicitModelId = readNonEmptyString5(params.explicitModelId);
|
|
13612
13434
|
if (explicitModelId) {
|
|
13613
13435
|
return explicitModelId;
|
|
13614
13436
|
}
|
|
@@ -14553,7 +14375,7 @@ function runMetaFromRecord(record) {
|
|
|
14553
14375
|
}
|
|
14554
14376
|
|
|
14555
14377
|
// src/runtime-kernel/run-supervisor/functions/awaitingUserWatcher.ts
|
|
14556
|
-
var
|
|
14378
|
+
var logger17 = new Logger("RunSupervisorAwaitingUserWatcher");
|
|
14557
14379
|
function isRecord16(value) {
|
|
14558
14380
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14559
14381
|
}
|
|
@@ -14598,7 +14420,7 @@ function createAwaitingUserWatcher(options) {
|
|
|
14598
14420
|
resumeToken: event.resume_token
|
|
14599
14421
|
}
|
|
14600
14422
|
}).catch((error) => {
|
|
14601
|
-
|
|
14423
|
+
logger17.warn("failed to mark awaiting_user from requires_user_interaction", { error });
|
|
14602
14424
|
});
|
|
14603
14425
|
};
|
|
14604
14426
|
const dispose = () => {
|