@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.cjs
CHANGED
|
@@ -571,18 +571,6 @@ var ErrorClassifier = class {
|
|
|
571
571
|
});
|
|
572
572
|
}
|
|
573
573
|
}
|
|
574
|
-
const quotaPatterns = ["\u5DF2\u8FBE\u4E0A\u9650", "\u514D\u8D39\u671F\u5DF2\u7ED3\u675F"];
|
|
575
|
-
for (const pattern of quotaPatterns) {
|
|
576
|
-
if (errorMessage.includes(pattern)) {
|
|
577
|
-
logClassification(context, "\u68C0\u6D4B\u5230\u4E91\u7AEF\u989D\u5EA6\u9650\u5236\uFF0C\u4E0D\u91CD\u8BD5", { matchedPattern: pattern });
|
|
578
|
-
return createClassification("non_retryable" /* NON_RETRYABLE */, `\u4E91\u7AEF\u989D\u5EA6\u9650\u5236: ${pattern}`, null, {
|
|
579
|
-
errorCode: ENGINE_ERROR_CODES.LLM_PROVIDER_DOWN,
|
|
580
|
-
recoverable: false,
|
|
581
|
-
hint: "check_billing_or_provider_status",
|
|
582
|
-
metadata: { matchedPattern: pattern }
|
|
583
|
-
});
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
574
|
const authPatterns = [
|
|
587
575
|
{ pattern: "unauthorized", code: "401" },
|
|
588
576
|
{ pattern: "forbidden", code: "403" },
|
|
@@ -837,17 +825,6 @@ var ErrorClassifier = class {
|
|
|
837
825
|
}
|
|
838
826
|
return Math.max(baseDelay, classification.suggestedDelay ?? 0);
|
|
839
827
|
}
|
|
840
|
-
static isCloudQuotaError(error) {
|
|
841
|
-
const msg = (error.message || "").toLowerCase();
|
|
842
|
-
const patterns = [
|
|
843
|
-
"\u989D\u5EA6\u4E0A\u9650",
|
|
844
|
-
"\u5DF2\u8FBE\u4E0A\u9650",
|
|
845
|
-
"\u514D\u8D39\u671F\u5DF2\u7ED3\u675F",
|
|
846
|
-
"\u8BE5\u6A21\u578B\u6682\u4E0D\u53EF\u7528",
|
|
847
|
-
"cloud_quota_exhausted"
|
|
848
|
-
];
|
|
849
|
-
return patterns.some((pattern) => msg.includes(pattern));
|
|
850
|
-
}
|
|
851
828
|
};
|
|
852
829
|
|
|
853
830
|
// src/contracts/index.ts
|
|
@@ -4902,8 +4879,8 @@ var TokenCalculator = class {
|
|
|
4902
4879
|
return;
|
|
4903
4880
|
}
|
|
4904
4881
|
this.failedEncodingWarnings.add(requestedEncoding);
|
|
4905
|
-
const
|
|
4906
|
-
|
|
4882
|
+
const logger18 = new Logger("TokenCalculator");
|
|
4883
|
+
logger18.warn("tiktoken encoding unavailable, falling back to avgCharsPerToken estimator", {
|
|
4907
4884
|
requestedEncoding,
|
|
4908
4885
|
error
|
|
4909
4886
|
});
|
|
@@ -5005,49 +4982,6 @@ var llmTelemetryMiddleware = async (ctx, stage, next) => {
|
|
|
5005
4982
|
});
|
|
5006
4983
|
};
|
|
5007
4984
|
|
|
5008
|
-
// src/runtime-kernel/graph-engine/functions/runModelLock.ts
|
|
5009
|
-
function readNonEmptyString4(value) {
|
|
5010
|
-
if (typeof value !== "string") return void 0;
|
|
5011
|
-
const trimmed = value.trim();
|
|
5012
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
5013
|
-
}
|
|
5014
|
-
function decideRunModelLockPatch(params) {
|
|
5015
|
-
if (params.stageId !== "execute_llm") {
|
|
5016
|
-
return { shouldLog: false };
|
|
5017
|
-
}
|
|
5018
|
-
const normalized = readNonEmptyString4(params.appliedFallbackModelId);
|
|
5019
|
-
if (!normalized) {
|
|
5020
|
-
return { shouldLog: false };
|
|
5021
|
-
}
|
|
5022
|
-
if (readNonEmptyString4(params.currentRunLockedModelId) === normalized) {
|
|
5023
|
-
return { shouldLog: false };
|
|
5024
|
-
}
|
|
5025
|
-
return {
|
|
5026
|
-
executorLocalPatch: { runLockedModelId: normalized },
|
|
5027
|
-
shouldLog: true
|
|
5028
|
-
};
|
|
5029
|
-
}
|
|
5030
|
-
|
|
5031
|
-
// src/runtime-kernel/graph-engine/tick-pipeline/middlewares/runModelLockMiddleware.ts
|
|
5032
|
-
var logger4 = new Logger("GraphAgentExecutor");
|
|
5033
|
-
var runModelLockMiddleware = async (ctx, stage, next) => {
|
|
5034
|
-
await next();
|
|
5035
|
-
const decision = decideRunModelLockPatch({
|
|
5036
|
-
stageId: stage.id,
|
|
5037
|
-
appliedFallbackModelId: ctx.cloudQuotaFallbackAppliedModelId,
|
|
5038
|
-
currentRunLockedModelId: ctx.executorLocalPatch?.runLockedModelId ?? ctx.executorLocal?.runLockedModelId
|
|
5039
|
-
});
|
|
5040
|
-
if (!decision.executorLocalPatch) {
|
|
5041
|
-
return;
|
|
5042
|
-
}
|
|
5043
|
-
if (decision.shouldLog) {
|
|
5044
|
-
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}`);
|
|
5045
|
-
}
|
|
5046
|
-
return {
|
|
5047
|
-
executorLocalPatch: decision.executorLocalPatch
|
|
5048
|
-
};
|
|
5049
|
-
};
|
|
5050
|
-
|
|
5051
4985
|
// src/runtime-kernel/graph-engine/tick-pipeline/runTickPipeline.ts
|
|
5052
4986
|
var tickPipelineContextKeys = [
|
|
5053
4987
|
"input",
|
|
@@ -5083,7 +5017,6 @@ var tickPipelineContextKeys = [
|
|
|
5083
5017
|
"decision",
|
|
5084
5018
|
"systemReminderHitRuleIds",
|
|
5085
5019
|
"contextTrace",
|
|
5086
|
-
"cloudQuotaFallbackAppliedModelId",
|
|
5087
5020
|
"modelFallbackAudit",
|
|
5088
5021
|
"telemetry",
|
|
5089
5022
|
"audit",
|
|
@@ -5422,7 +5355,7 @@ ${normalized}
|
|
|
5422
5355
|
}
|
|
5423
5356
|
|
|
5424
5357
|
// src/runtime-kernel/system-reminder/apply.ts
|
|
5425
|
-
var
|
|
5358
|
+
var logger4 = new Logger("SystemReminder");
|
|
5426
5359
|
var readString2 = (v) => {
|
|
5427
5360
|
if (typeof v !== "string") return void 0;
|
|
5428
5361
|
const s = v;
|
|
@@ -5485,7 +5418,7 @@ function applySystemReminders(params) {
|
|
|
5485
5418
|
} catch {
|
|
5486
5419
|
}
|
|
5487
5420
|
}
|
|
5488
|
-
|
|
5421
|
+
logger4.info("SystemReminder \u5DF2\u6CE8\u5165\u5230 LLM \u8F93\u5165\u672B\u5C3E", {
|
|
5489
5422
|
ruleIds: injectedRuleIds.length > 0 ? injectedRuleIds : Array.from(seenRuleIds),
|
|
5490
5423
|
promptKey: ctx.request.promptKey,
|
|
5491
5424
|
executorLocal: {
|
|
@@ -6195,18 +6128,14 @@ function createExecuteLlmStage(dependencies) {
|
|
|
6195
6128
|
"turnId"
|
|
6196
6129
|
],
|
|
6197
6130
|
writes: [
|
|
6198
|
-
"cloudQuotaFallbackAppliedModelId",
|
|
6199
6131
|
"modelFallbackAudit",
|
|
6200
6132
|
"llmCallStartedAt",
|
|
6201
6133
|
"llmResp",
|
|
6202
6134
|
"llmCallDurationMs",
|
|
6203
|
-
"executorLocalPatch",
|
|
6204
6135
|
"contextUsage"
|
|
6205
6136
|
],
|
|
6206
6137
|
async run(ctx) {
|
|
6207
|
-
let cloudQuotaFallbackAppliedModelId;
|
|
6208
6138
|
let modelFallbackAudit;
|
|
6209
|
-
let lastSuccessfulLlmModelId;
|
|
6210
6139
|
let contextUsage;
|
|
6211
6140
|
const modelFallbackRejections = [];
|
|
6212
6141
|
const promptBudget = ctx.promptBudget;
|
|
@@ -6224,11 +6153,7 @@ function createExecuteLlmStage(dependencies) {
|
|
|
6224
6153
|
streamEventHandler,
|
|
6225
6154
|
ctx.signal,
|
|
6226
6155
|
{
|
|
6227
|
-
|
|
6228
|
-
cloudQuotaFallbackAppliedModelId = readNonEmptyString3(fallbackModelId);
|
|
6229
|
-
},
|
|
6230
|
-
onLlmAttemptSucceeded(activeModelId, attemptContextUsage) {
|
|
6231
|
-
lastSuccessfulLlmModelId = readNonEmptyString3(activeModelId);
|
|
6156
|
+
onLlmAttemptSucceeded(_activeModelId, attemptContextUsage) {
|
|
6232
6157
|
contextUsage = attemptContextUsage;
|
|
6233
6158
|
},
|
|
6234
6159
|
onModelFallbackApplied(info) {
|
|
@@ -6324,12 +6249,10 @@ function createExecuteLlmStage(dependencies) {
|
|
|
6324
6249
|
});
|
|
6325
6250
|
}
|
|
6326
6251
|
return {
|
|
6327
|
-
cloudQuotaFallbackAppliedModelId,
|
|
6328
6252
|
modelFallbackAudit,
|
|
6329
6253
|
llmCallStartedAt,
|
|
6330
6254
|
llmResp,
|
|
6331
6255
|
llmCallDurationMs,
|
|
6332
|
-
executorLocalPatch: lastSuccessfulLlmModelId ? { lastSuccessfulLlmModelId } : void 0,
|
|
6333
6256
|
contextUsage
|
|
6334
6257
|
};
|
|
6335
6258
|
}
|
|
@@ -7246,18 +7169,16 @@ function createPrepareCallStage(dependencies) {
|
|
|
7246
7169
|
"toolDefinitionTokens"
|
|
7247
7170
|
],
|
|
7248
7171
|
async run(ctx) {
|
|
7249
|
-
const
|
|
7250
|
-
const requestedModelId = lockedRunModelId ?? ctx.request.model_id;
|
|
7172
|
+
const requestedModelId = ctx.request.model_id;
|
|
7251
7173
|
const modelId = dependencies.modelResolver.resolveModelId(requestedModelId);
|
|
7252
7174
|
await emitAuditEnvelope(ctx.audit, {
|
|
7253
7175
|
action: "model.select",
|
|
7254
7176
|
actor: { kind: "system" },
|
|
7255
7177
|
decision: {
|
|
7256
7178
|
outcome: "recorded",
|
|
7257
|
-
reason:
|
|
7179
|
+
reason: requestedModelId ? "request model id" : "default model resolver",
|
|
7258
7180
|
metadata: {
|
|
7259
7181
|
requestedModelId,
|
|
7260
|
-
lockedRunModelId,
|
|
7261
7182
|
selectedModelId: modelId
|
|
7262
7183
|
}
|
|
7263
7184
|
},
|
|
@@ -7304,10 +7225,6 @@ function createPrepareCallStage(dependencies) {
|
|
|
7304
7225
|
if (ctx.executorLocal?.lockRequestedModelId === true) {
|
|
7305
7226
|
llmOptions.allow_model_fallback = false;
|
|
7306
7227
|
}
|
|
7307
|
-
const isRunContinuation = ctx.executorLocal?.llmInvocationKind === "continuation";
|
|
7308
|
-
if (dependencies.cloudQuotaFallbackModelId && modelConfig?.billing_mode === "cloud" && modelId !== dependencies.cloudQuotaFallbackModelId && isRunContinuation && ctx.executorLocal?.lockRequestedModelId !== true) {
|
|
7309
|
-
llmOptions.cloud_quota_fallback_model_id = dependencies.cloudQuotaFallbackModelId;
|
|
7310
|
-
}
|
|
7311
7228
|
const effectiveEffort = resolveEffectiveEffort(
|
|
7312
7229
|
ctx.request.reasoning_effort,
|
|
7313
7230
|
modelConfig?.reasoning
|
|
@@ -7424,12 +7341,11 @@ function applyCalibration(rawLocalTotal, imageInputTokens, coefficient) {
|
|
|
7424
7341
|
}
|
|
7425
7342
|
|
|
7426
7343
|
// src/runtime-kernel/graph-engine/executor.ts
|
|
7427
|
-
var
|
|
7344
|
+
var logger5 = new Logger("GraphAgentExecutor");
|
|
7428
7345
|
var GraphAgentExecutor = class {
|
|
7429
7346
|
llmCaller;
|
|
7430
7347
|
toolRuntime;
|
|
7431
7348
|
contextBuilder;
|
|
7432
|
-
cloudQuotaFallbackModelId;
|
|
7433
7349
|
modelResolver;
|
|
7434
7350
|
modelCatalog;
|
|
7435
7351
|
telemetryPort;
|
|
@@ -7441,7 +7357,6 @@ var GraphAgentExecutor = class {
|
|
|
7441
7357
|
this.llmCaller = dependencies.llmCaller;
|
|
7442
7358
|
this.toolRuntime = dependencies.toolRuntime;
|
|
7443
7359
|
this.contextBuilder = dependencies.contextBuilder;
|
|
7444
|
-
this.cloudQuotaFallbackModelId = readNonEmptyString3(dependencies.cloudQuotaFallbackModelId);
|
|
7445
7360
|
this.modelCatalog = dependencies.modelCatalog ?? createEmptyModelCatalog();
|
|
7446
7361
|
this.modelResolver = dependencies.modelResolver ?? new ModelResolver({
|
|
7447
7362
|
modelCatalog: this.modelCatalog
|
|
@@ -7458,8 +7373,7 @@ var GraphAgentExecutor = class {
|
|
|
7458
7373
|
createPrepareCallStage({
|
|
7459
7374
|
modelResolver: this.modelResolver,
|
|
7460
7375
|
modelCatalog: this.modelCatalog,
|
|
7461
|
-
toolCatalog: this.toolRuntime
|
|
7462
|
-
cloudQuotaFallbackModelId: this.cloudQuotaFallbackModelId
|
|
7376
|
+
toolCatalog: this.toolRuntime
|
|
7463
7377
|
}),
|
|
7464
7378
|
createBuildContextStage({
|
|
7465
7379
|
contextBuilder: this.contextBuilder
|
|
@@ -7481,7 +7395,7 @@ var GraphAgentExecutor = class {
|
|
|
7481
7395
|
}),
|
|
7482
7396
|
createBuildDecisionStage()
|
|
7483
7397
|
];
|
|
7484
|
-
this.middlewares = [llmTelemetryMiddleware
|
|
7398
|
+
this.middlewares = [llmTelemetryMiddleware];
|
|
7485
7399
|
}
|
|
7486
7400
|
async tick(input, eventHandler) {
|
|
7487
7401
|
const ctx = {
|
|
@@ -7506,7 +7420,7 @@ var GraphAgentExecutor = class {
|
|
|
7506
7420
|
audit: this.auditPort,
|
|
7507
7421
|
tokenizer: this.tokenizer
|
|
7508
7422
|
};
|
|
7509
|
-
|
|
7423
|
+
logger5.info("[GraphAgentExecutor] tick \u8C03\u7528", {
|
|
7510
7424
|
stream: input.stream === true,
|
|
7511
7425
|
hasEventHandler: Boolean(eventHandler),
|
|
7512
7426
|
hasSummarizationCallbacks: Boolean(input.summarizationCallbacks)
|
|
@@ -8529,7 +8443,7 @@ var LlmNodeEventBridge = class {
|
|
|
8529
8443
|
};
|
|
8530
8444
|
|
|
8531
8445
|
// src/runtime-kernel/graph-engine/nodes/llmNode.ts
|
|
8532
|
-
var
|
|
8446
|
+
var logger6 = new Logger("LlmNode");
|
|
8533
8447
|
var LlmNode = class {
|
|
8534
8448
|
id = "llm";
|
|
8535
8449
|
reasoner;
|
|
@@ -8538,7 +8452,7 @@ var LlmNode = class {
|
|
|
8538
8452
|
}
|
|
8539
8453
|
async run(state) {
|
|
8540
8454
|
const local = state.local ?? {};
|
|
8541
|
-
|
|
8455
|
+
logger6.info("[LlmNode] \u5F00\u59CB\u6267\u884C LLM \u8282\u70B9", {
|
|
8542
8456
|
localKeys: Object.keys(local)
|
|
8543
8457
|
});
|
|
8544
8458
|
const graphLocal = readGraphAgentLocal(state.local);
|
|
@@ -8553,12 +8467,12 @@ var LlmNode = class {
|
|
|
8553
8467
|
signal,
|
|
8554
8468
|
history
|
|
8555
8469
|
} = graphLocal;
|
|
8556
|
-
|
|
8470
|
+
logger6.info("[LlmNode] \u5DF2\u52A0\u8F7D\u5386\u53F2\u4E8B\u4EF6", {
|
|
8557
8471
|
historyCount: history.length,
|
|
8558
8472
|
hasSummarizationCallbacks: Boolean(summarizationCallbacks)
|
|
8559
8473
|
});
|
|
8560
8474
|
if (!request) {
|
|
8561
|
-
|
|
8475
|
+
logger6.warn("Request object is missing, yielding.");
|
|
8562
8476
|
return { kind: "yield", events: [] };
|
|
8563
8477
|
}
|
|
8564
8478
|
const turnId = requireRuntimeIdentity(graphLocal.turnId, "turnId");
|
|
@@ -8651,12 +8565,12 @@ var LlmNode = class {
|
|
|
8651
8565
|
...nodeState.streamRuntimeEvents,
|
|
8652
8566
|
...contextUsageEvent ? [contextUsageEvent] : []
|
|
8653
8567
|
];
|
|
8654
|
-
|
|
8568
|
+
logger6.info("[LlmNode] \u5386\u53F2\u4E8B\u4EF6\u5DF2\u66F4\u65B0", {
|
|
8655
8569
|
previousCount: history.length,
|
|
8656
8570
|
nextCount: patch.history.length,
|
|
8657
8571
|
streamedEventCount: nodeState.streamRuntimeEvents.length
|
|
8658
8572
|
});
|
|
8659
|
-
|
|
8573
|
+
logger6.info("[LlmNode] \u6267\u884C\u5668\u51B3\u7B56\u5B8C\u6210", {
|
|
8660
8574
|
decisionKind: decision.kind,
|
|
8661
8575
|
emittedEventCount: combinedEvents.length
|
|
8662
8576
|
});
|
|
@@ -8678,7 +8592,7 @@ var LlmNode = class {
|
|
|
8678
8592
|
}
|
|
8679
8593
|
case "error": {
|
|
8680
8594
|
const { name, message, stack } = decision.error;
|
|
8681
|
-
|
|
8595
|
+
logger6.error("[LlmNode] Executor returned an error", { name, message, stack });
|
|
8682
8596
|
return { kind: "yield", events: combinedEvents };
|
|
8683
8597
|
}
|
|
8684
8598
|
default: {
|
|
@@ -8784,7 +8698,7 @@ async function resolveToolModelInput(input) {
|
|
|
8784
8698
|
}
|
|
8785
8699
|
|
|
8786
8700
|
// src/runtime-kernel/graph-engine/nodes/toolNode.finalAnswerProjector.ts
|
|
8787
|
-
function
|
|
8701
|
+
function readNonEmptyString4(value) {
|
|
8788
8702
|
if (typeof value !== "string") {
|
|
8789
8703
|
return void 0;
|
|
8790
8704
|
}
|
|
@@ -8792,7 +8706,7 @@ function readNonEmptyString5(value) {
|
|
|
8792
8706
|
return normalized.length > 0 ? normalized : void 0;
|
|
8793
8707
|
}
|
|
8794
8708
|
function resolveFinalAnswerFromToolControl(finalAnswer) {
|
|
8795
|
-
return
|
|
8709
|
+
return readNonEmptyString4(finalAnswer);
|
|
8796
8710
|
}
|
|
8797
8711
|
|
|
8798
8712
|
// src/runtime-kernel/graph-engine/nodes/toolNode.helpers.ts
|
|
@@ -9048,7 +8962,7 @@ function buildErrorLocalState(params) {
|
|
|
9048
8962
|
}
|
|
9049
8963
|
|
|
9050
8964
|
// src/runtime-kernel/tools/argNormalizer.ts
|
|
9051
|
-
var
|
|
8965
|
+
var logger7 = new Logger("ToolArgNormalizer");
|
|
9052
8966
|
function isRecord10(v) {
|
|
9053
8967
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
9054
8968
|
}
|
|
@@ -9068,7 +8982,7 @@ function joinPath(basePath, segment) {
|
|
|
9068
8982
|
function logJsonEncodedNormalization(expectedType, options) {
|
|
9069
8983
|
const toolPrefix = options.toolName ? `${options.toolName}.` : "";
|
|
9070
8984
|
const path = options.path ?? "<root>";
|
|
9071
|
-
|
|
8985
|
+
logger7.warn("normalized JSON-encoded tool argument", {
|
|
9072
8986
|
expectedType,
|
|
9073
8987
|
path: `${toolPrefix}${path}`
|
|
9074
8988
|
});
|
|
@@ -9424,7 +9338,7 @@ function stripRuntimeReservedToolContextPatch(patch) {
|
|
|
9424
9338
|
}
|
|
9425
9339
|
|
|
9426
9340
|
// src/runtime-kernel/graph-engine/nodes/toolNode.eventBridge.ts
|
|
9427
|
-
var
|
|
9341
|
+
var logger8 = new Logger("ToolNode");
|
|
9428
9342
|
var ToolNodeEventBridge = class {
|
|
9429
9343
|
constructor(deps) {
|
|
9430
9344
|
this.deps = deps;
|
|
@@ -9446,7 +9360,7 @@ var ToolNodeEventBridge = class {
|
|
|
9446
9360
|
status,
|
|
9447
9361
|
payload: { ...payload }
|
|
9448
9362
|
};
|
|
9449
|
-
|
|
9363
|
+
logger8.info("[ToolNode] \u53D1\u51FA tool_process \u4E8B\u4EF6", {
|
|
9450
9364
|
phase,
|
|
9451
9365
|
status,
|
|
9452
9366
|
toolName: this.deps.toolName,
|
|
@@ -9486,7 +9400,7 @@ var ToolNodeEventBridge = class {
|
|
|
9486
9400
|
const answerId = generateAnswerSegmentId();
|
|
9487
9401
|
const id = answerId;
|
|
9488
9402
|
const timestamp = Date.now();
|
|
9489
|
-
|
|
9403
|
+
logger8.info("[ToolNode] \u5DE5\u5177\u8F93\u51FA\u6620\u5C04\u4E3A final_answer", {
|
|
9490
9404
|
sourceToolName: params.sourceToolName,
|
|
9491
9405
|
toolCallId: this.deps.toolCallId,
|
|
9492
9406
|
conversationId: this.deps.conversationId,
|
|
@@ -9544,7 +9458,7 @@ var ToolNodeEventBridge = class {
|
|
|
9544
9458
|
};
|
|
9545
9459
|
|
|
9546
9460
|
// src/runtime-kernel/graph-engine/nodes/toolNode.executionSetup.ts
|
|
9547
|
-
var
|
|
9461
|
+
var logger9 = new Logger("ToolNode");
|
|
9548
9462
|
function parseToolArgs(call) {
|
|
9549
9463
|
const rawArguments = typeof call.function?.arguments === "string" ? call.function.arguments : "";
|
|
9550
9464
|
if (!rawArguments.trim()) {
|
|
@@ -9564,7 +9478,7 @@ function parseToolArgs(call) {
|
|
|
9564
9478
|
return { ok: true, value: parsed };
|
|
9565
9479
|
} catch (error) {
|
|
9566
9480
|
const reason = error instanceof Error ? error.message : "Unknown JSON parse error";
|
|
9567
|
-
|
|
9481
|
+
logger9.warn("failed to parse tool arguments", { error });
|
|
9568
9482
|
return {
|
|
9569
9483
|
ok: false,
|
|
9570
9484
|
error: `Tool arguments are not valid JSON: ${reason}`
|
|
@@ -9965,7 +9879,7 @@ async function claimPendingUserInputs(state, result) {
|
|
|
9965
9879
|
}
|
|
9966
9880
|
|
|
9967
9881
|
// src/runtime-kernel/graph-engine/nodes/toolNode.ts
|
|
9968
|
-
var
|
|
9882
|
+
var logger10 = new Logger("ToolNode");
|
|
9969
9883
|
function isAbortSignal(value) {
|
|
9970
9884
|
return value !== null && typeof value === "object" && "aborted" in value;
|
|
9971
9885
|
}
|
|
@@ -10178,7 +10092,7 @@ var ToolNode = class {
|
|
|
10178
10092
|
throw abortError;
|
|
10179
10093
|
}
|
|
10180
10094
|
const prepared = prepareToolNodeContext(state);
|
|
10181
|
-
|
|
10095
|
+
logger10.info("[ToolNode] \u5F00\u59CB\u6267\u884C\u5DE5\u5177\u8282\u70B9", {
|
|
10182
10096
|
conversationId: prepared.conversationId,
|
|
10183
10097
|
turnId: prepared.turnId,
|
|
10184
10098
|
pendingCallCount: calls.length
|
|
@@ -10193,7 +10107,7 @@ var ToolNode = class {
|
|
|
10193
10107
|
toolCatalog: this.toolRuntime
|
|
10194
10108
|
});
|
|
10195
10109
|
if (!execution) {
|
|
10196
|
-
|
|
10110
|
+
logger10.warn("no tool name found in call");
|
|
10197
10111
|
return { kind: "yield", events: [] };
|
|
10198
10112
|
}
|
|
10199
10113
|
if (typeof execution.protocolError === "string") {
|
|
@@ -10233,7 +10147,7 @@ var ToolNode = class {
|
|
|
10233
10147
|
call,
|
|
10234
10148
|
context: prepared.toolContext,
|
|
10235
10149
|
abortGraceMs: this.abortGraceMs,
|
|
10236
|
-
onAbandon: () =>
|
|
10150
|
+
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", {
|
|
10237
10151
|
toolName: execution.toolName,
|
|
10238
10152
|
toolCallId: execution.toolCallId,
|
|
10239
10153
|
conversationId: prepared.conversationId,
|
|
@@ -10403,7 +10317,7 @@ var ToolNode = class {
|
|
|
10403
10317
|
runtimeEvents: context.bridge.getRuntimeEvents()
|
|
10404
10318
|
});
|
|
10405
10319
|
if (control?.terminateRun) {
|
|
10406
|
-
|
|
10320
|
+
logger10.info("[ToolNode] \u6536\u5230 control.terminateRun\uFF0C\u6267\u884C\u5B8C\u5DE5\u5177\u540E\u76F4\u63A5 yield \u7ED3\u675F\u672C\u8F6E run", {
|
|
10407
10321
|
toolName: context.toolName,
|
|
10408
10322
|
toolCallId: context.toolCallId,
|
|
10409
10323
|
conversationId: context.conversationId,
|
|
@@ -10412,7 +10326,7 @@ var ToolNode = class {
|
|
|
10412
10326
|
return { kind: "yield", events: context.bridge.getRuntimeEvents() };
|
|
10413
10327
|
}
|
|
10414
10328
|
if (remainingCalls.length === 0 && context.local.toolBatchCompletionMode === "yield_after_batch") {
|
|
10415
|
-
|
|
10329
|
+
logger10.info("[ToolNode] \u5DE5\u5177\u6279\u6B21\u5DF2\u7ED3\u7B97\uFF0C\u6309 Host \u7B56\u7565\u76F4\u63A5 yield", {
|
|
10416
10330
|
toolName: context.toolName,
|
|
10417
10331
|
toolCallId: context.toolCallId,
|
|
10418
10332
|
conversationId: context.conversationId,
|
|
@@ -10859,6 +10773,8 @@ var executor = zod.z.object({
|
|
|
10859
10773
|
lastStepsHintThreshold: counter.optional(),
|
|
10860
10774
|
systemReminderPolicy: AgentSpecSystemReminderPolicy.optional(),
|
|
10861
10775
|
toolObservationPolicy: AgentSpecToolObservationGovernancePolicy.optional(),
|
|
10776
|
+
// 已删除字段:0.45 及更早的 checkpoint 可能带 lastSuccessfulLlmModelId,0.46 及更早的可能带云端额度兜底留下的
|
|
10777
|
+
// runLockedModelId;照常接受,读入时丢弃(兜底已移除,恢复后按请求的模型继续)。
|
|
10862
10778
|
runLockedModelId: zod.z.string().optional(),
|
|
10863
10779
|
lastSuccessfulLlmModelId: zod.z.string().optional(),
|
|
10864
10780
|
llmInvocationKind: zod.z.enum(["user_initiated", "continuation"]).optional(),
|
|
@@ -10869,7 +10785,7 @@ var executor = zod.z.object({
|
|
|
10869
10785
|
committedCount: counter,
|
|
10870
10786
|
lastCommittedFingerprint: zod.z.string().optional()
|
|
10871
10787
|
}).strict().optional()
|
|
10872
|
-
}).strict();
|
|
10788
|
+
}).strict().transform(({ lastSuccessfulLlmModelId: _retired, runLockedModelId: _retiredLock, ...state }) => state);
|
|
10873
10789
|
var checkpoint = zod.z.object({
|
|
10874
10790
|
nodeId: zod.z.string().min(1),
|
|
10875
10791
|
schemaVersion: zod.z.literal(ENGINE_STATE_SCHEMA_VERSION).optional(),
|
|
@@ -11183,7 +11099,7 @@ __export(execution_exports, {
|
|
|
11183
11099
|
});
|
|
11184
11100
|
|
|
11185
11101
|
// src/runtime-kernel/execution/event-bus.ts
|
|
11186
|
-
var
|
|
11102
|
+
var logger11 = new Logger("EventBus");
|
|
11187
11103
|
var TypedEventEmitter = class {
|
|
11188
11104
|
listeners = /* @__PURE__ */ new Map();
|
|
11189
11105
|
maxListeners = 10;
|
|
@@ -11191,7 +11107,7 @@ var TypedEventEmitter = class {
|
|
|
11191
11107
|
const listeners = this.getListeners(event);
|
|
11192
11108
|
listeners.add(listener);
|
|
11193
11109
|
if (listeners.size > this.maxListeners) {
|
|
11194
|
-
|
|
11110
|
+
logger11.warn("EventBus listener count exceeds configured max", {
|
|
11195
11111
|
event: String(event),
|
|
11196
11112
|
count: listeners.size,
|
|
11197
11113
|
maxListeners: this.maxListeners
|
|
@@ -11251,7 +11167,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
11251
11167
|
super();
|
|
11252
11168
|
this.executionId = executionId;
|
|
11253
11169
|
this.setMaxListeners(30);
|
|
11254
|
-
|
|
11170
|
+
logger11.info(`EventBus created for execution ${this.executionId}`);
|
|
11255
11171
|
}
|
|
11256
11172
|
/**
|
|
11257
11173
|
* 发布一个事件到总线
|
|
@@ -11260,7 +11176,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
11260
11176
|
publish(envelope) {
|
|
11261
11177
|
if (envelope.trace.execution_id !== this.executionId) {
|
|
11262
11178
|
const error = new Error("EventEnvelope execution_id does not match EventBus instance.");
|
|
11263
|
-
|
|
11179
|
+
logger11.error("Mismatched execution_id", {
|
|
11264
11180
|
busExecutionId: this.executionId,
|
|
11265
11181
|
eventExecutionId: envelope.trace.execution_id,
|
|
11266
11182
|
eventSeq: envelope.seq
|
|
@@ -11272,7 +11188,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
11272
11188
|
const error = new Error(
|
|
11273
11189
|
"EventBus only accepts RuntimeEvent with formal run routing identity."
|
|
11274
11190
|
);
|
|
11275
|
-
|
|
11191
|
+
logger11.error("RuntimeEvent is missing formal run routing identity", {
|
|
11276
11192
|
executionId: this.executionId,
|
|
11277
11193
|
eventId: envelope.payload.id,
|
|
11278
11194
|
eventType: envelope.payload.type
|
|
@@ -11286,14 +11202,14 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
11286
11202
|
* 关闭总线,清理所有监听器
|
|
11287
11203
|
*/
|
|
11288
11204
|
close() {
|
|
11289
|
-
|
|
11205
|
+
logger11.info(`Closing EventBus for execution ${this.executionId}`);
|
|
11290
11206
|
this.emit("close");
|
|
11291
11207
|
this.removeAllListeners();
|
|
11292
11208
|
}
|
|
11293
11209
|
};
|
|
11294
11210
|
|
|
11295
11211
|
// src/runtime-kernel/execution/sequencer.ts
|
|
11296
|
-
var
|
|
11212
|
+
var logger12 = new Logger("EventSequencer");
|
|
11297
11213
|
var EventSequencer = class {
|
|
11298
11214
|
executionId;
|
|
11299
11215
|
traceId;
|
|
@@ -11301,7 +11217,7 @@ var EventSequencer = class {
|
|
|
11301
11217
|
constructor(conversationId, traceId) {
|
|
11302
11218
|
this.executionId = generateExecutionId();
|
|
11303
11219
|
this.traceId = traceId || generateTraceId();
|
|
11304
|
-
|
|
11220
|
+
logger12.info(`EventSequencer created for conversation ${conversationId}`, {
|
|
11305
11221
|
executionId: this.executionId,
|
|
11306
11222
|
traceId: this.traceId
|
|
11307
11223
|
});
|
|
@@ -12159,7 +12075,7 @@ var ThoughtStreamSegmenter = class {
|
|
|
12159
12075
|
};
|
|
12160
12076
|
|
|
12161
12077
|
// src/runtime-kernel/llm/streaming-adapter.ts
|
|
12162
|
-
var
|
|
12078
|
+
var logger13 = new Logger("LlmCaller");
|
|
12163
12079
|
var CanonicalInferenceFailureError = class extends Error {
|
|
12164
12080
|
errorCode;
|
|
12165
12081
|
recoverable;
|
|
@@ -12383,7 +12299,7 @@ async function callLlmStream(params) {
|
|
|
12383
12299
|
} catch (error) {
|
|
12384
12300
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
12385
12301
|
if (normalized.name === "AbortError") {
|
|
12386
|
-
|
|
12302
|
+
logger13.info("Canonical inference \u6536\u5230\u53D6\u6D88\u7EC8\u6001\uFF0C\u4E0D\u53D1\u5E03\u666E\u901A error event", { modelId });
|
|
12387
12303
|
throw normalized;
|
|
12388
12304
|
}
|
|
12389
12305
|
const classification = ErrorClassifier.classify(normalized, {
|
|
@@ -12459,7 +12375,7 @@ var LlmRetryEpisode = class {
|
|
|
12459
12375
|
};
|
|
12460
12376
|
|
|
12461
12377
|
// src/runtime-kernel/llm/retry-fallback-routing.ts
|
|
12462
|
-
var
|
|
12378
|
+
var logger14 = new Logger("LlmCaller");
|
|
12463
12379
|
function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement, fallbackObserver, error, evaluateFallbackPromptCapacity2) {
|
|
12464
12380
|
deps.modelCatalog.getModelById(activeModelId);
|
|
12465
12381
|
const policyDecision = deps.policyEngine.decideOnError(error, {
|
|
@@ -12489,81 +12405,16 @@ function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement
|
|
|
12489
12405
|
reason: "no_eligible_fallback_candidate",
|
|
12490
12406
|
requiredPlacements: requirement.placements
|
|
12491
12407
|
});
|
|
12492
|
-
|
|
12408
|
+
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");
|
|
12493
12409
|
return null;
|
|
12494
12410
|
}
|
|
12495
|
-
|
|
12411
|
+
logger14.warn("Policy \u5207\u6362\u6A21\u578B\u7EE7\u7EED", {
|
|
12496
12412
|
reason: policyDecision.reason,
|
|
12497
12413
|
activeModelId,
|
|
12498
12414
|
fallbackModelId
|
|
12499
12415
|
});
|
|
12500
12416
|
return fallbackModelId;
|
|
12501
12417
|
}
|
|
12502
|
-
function tryCloudQuotaFallback({
|
|
12503
|
-
deps,
|
|
12504
|
-
activeModelId,
|
|
12505
|
-
options,
|
|
12506
|
-
excludedModelIds,
|
|
12507
|
-
requirement,
|
|
12508
|
-
error,
|
|
12509
|
-
fallbackObserver,
|
|
12510
|
-
evaluateFallbackPromptCapacity: evaluateFallbackPromptCapacity2
|
|
12511
|
-
}) {
|
|
12512
|
-
const fallbackModelId = options.cloud_quota_fallback_model_id;
|
|
12513
|
-
if (!fallbackModelId || !ErrorClassifier.isCloudQuotaError(error) || excludedModelIds.has(fallbackModelId)) {
|
|
12514
|
-
return null;
|
|
12515
|
-
}
|
|
12516
|
-
const fallbackConfig = deps.modelCatalog.getModelById(fallbackModelId);
|
|
12517
|
-
if (!fallbackConfig?.api_key) {
|
|
12518
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
12519
|
-
fromModelId: activeModelId,
|
|
12520
|
-
candidateModelId: fallbackModelId,
|
|
12521
|
-
policy: "cloud-quota",
|
|
12522
|
-
reason: "fallback_model_unavailable",
|
|
12523
|
-
requiredPlacements: requirement.placements
|
|
12524
|
-
});
|
|
12525
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\u76EE\u6807\u4E0D\u53EF\u7528\uFF08\u672A\u6CE8\u518C\u6216\u7F3A\u5C11 API Key\uFF09", { fallbackModelId });
|
|
12526
|
-
return null;
|
|
12527
|
-
}
|
|
12528
|
-
const compatibility = evaluateModelInputCompatibility(fallbackConfig, requirement);
|
|
12529
|
-
if (!compatibility.compatible) {
|
|
12530
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
12531
|
-
fromModelId: activeModelId,
|
|
12532
|
-
candidateModelId: fallbackModelId,
|
|
12533
|
-
policy: "cloud-quota",
|
|
12534
|
-
reason: compatibility.reason,
|
|
12535
|
-
requiredPlacements: requirement.placements
|
|
12536
|
-
});
|
|
12537
|
-
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", {
|
|
12538
|
-
fallbackModelId,
|
|
12539
|
-
requiredPlacements: requirement.placements,
|
|
12540
|
-
reason: compatibility.reason
|
|
12541
|
-
});
|
|
12542
|
-
return null;
|
|
12543
|
-
}
|
|
12544
|
-
const capacityAdmission = evaluateFallbackPromptCapacity2?.(fallbackModelId);
|
|
12545
|
-
if (capacityAdmission && !capacityAdmission.admitted) {
|
|
12546
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
12547
|
-
fromModelId: activeModelId,
|
|
12548
|
-
candidateModelId: fallbackModelId,
|
|
12549
|
-
policy: "cloud-quota",
|
|
12550
|
-
reason: capacityAdmission.reason,
|
|
12551
|
-
requiredPlacements: requirement.placements
|
|
12552
|
-
});
|
|
12553
|
-
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", {
|
|
12554
|
-
fallbackModelId,
|
|
12555
|
-
reason: capacityAdmission.reason
|
|
12556
|
-
});
|
|
12557
|
-
return null;
|
|
12558
|
-
}
|
|
12559
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\uFF08run \u5185\u7EED\u8DD1\uFF09", {
|
|
12560
|
-
activeModelId,
|
|
12561
|
-
fallbackModelId,
|
|
12562
|
-
reason: error.message
|
|
12563
|
-
});
|
|
12564
|
-
fallbackObserver?.onCloudQuotaFallbackApplied?.(fallbackModelId);
|
|
12565
|
-
return fallbackModelId;
|
|
12566
|
-
}
|
|
12567
12418
|
|
|
12568
12419
|
// src/runtime-kernel/llm/usage-telemetry.ts
|
|
12569
12420
|
async function callPlainCompletion(inferencePort, modelId, messages, options = {}, signal, traceId) {
|
|
@@ -12686,7 +12537,7 @@ var LlmImageInputError = class extends Error {
|
|
|
12686
12537
|
};
|
|
12687
12538
|
|
|
12688
12539
|
// src/runtime-kernel/llm/retry-fallback.ts
|
|
12689
|
-
var
|
|
12540
|
+
var logger15 = new Logger("LlmCaller");
|
|
12690
12541
|
async function callWithRetryFallback(params) {
|
|
12691
12542
|
const {
|
|
12692
12543
|
deps,
|
|
@@ -12714,11 +12565,9 @@ async function callWithRetryFallback(params) {
|
|
|
12714
12565
|
const retryEpisode = new LlmRetryEpisode(traceId, eventHandler);
|
|
12715
12566
|
let previousAttemptTracker;
|
|
12716
12567
|
if (!clientRetryEnabled) {
|
|
12717
|
-
|
|
12718
|
-
logger16.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
12568
|
+
logger15.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
12719
12569
|
modelId,
|
|
12720
|
-
|
|
12721
|
-
reason: options.retry_policy === "none" ? "options.retry_policy=none" : "model config (cloud billing or enable_client_retry=false)"
|
|
12570
|
+
reason: options.retry_policy === "none" ? "options.retry_policy=none" : "model config enable_client_retry=false"
|
|
12722
12571
|
});
|
|
12723
12572
|
}
|
|
12724
12573
|
try {
|
|
@@ -12754,7 +12603,7 @@ async function callWithRetryFallback(params) {
|
|
|
12754
12603
|
}) : void 0;
|
|
12755
12604
|
try {
|
|
12756
12605
|
if (isRetry) {
|
|
12757
|
-
|
|
12606
|
+
logger15.info("LLM \u8C03\u7528\u91CD\u8BD5", { attempt, configuredMaxRetries });
|
|
12758
12607
|
}
|
|
12759
12608
|
actualAttempts++;
|
|
12760
12609
|
retryEpisode.retrying(actualAttempts);
|
|
@@ -12783,7 +12632,7 @@ async function callWithRetryFallback(params) {
|
|
|
12783
12632
|
if (deps.retryConfig.enableEmptyResponseRetry && !responseContent?.trim() && !toolCallsFromLLM?.length) {
|
|
12784
12633
|
throw new Error("LLM\u8FD4\u56DE\u4E86\u7A7A\u54CD\u5E94");
|
|
12785
12634
|
}
|
|
12786
|
-
|
|
12635
|
+
logger15.debug("LLM \u8C03\u7528\u6210\u529F", { attempts: actualAttempts, maxTotalAttempts });
|
|
12787
12636
|
if (attemptContextUsage) {
|
|
12788
12637
|
fallbackObserver?.onLlmAttemptSucceeded?.(activeModelId, attemptContextUsage);
|
|
12789
12638
|
} else {
|
|
@@ -12794,7 +12643,7 @@ async function callWithRetryFallback(params) {
|
|
|
12794
12643
|
} catch (error) {
|
|
12795
12644
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
12796
12645
|
if (lastError.name === "AbortError") {
|
|
12797
|
-
|
|
12646
|
+
logger15.info("LLM \u8C03\u7528\u5DF2\u53D6\u6D88\uFF0C\u4E0D\u8FDB\u5165 provider failure \u5206\u7C7B\u4E0E\u91CD\u8BD5\u6D41\u7A0B", {
|
|
12798
12647
|
attempt: attempt + 1,
|
|
12799
12648
|
actualAttempts,
|
|
12800
12649
|
maxTotalAttempts,
|
|
@@ -12813,7 +12662,7 @@ async function callWithRetryFallback(params) {
|
|
|
12813
12662
|
total_attempts: actualAttempts,
|
|
12814
12663
|
error_code: classification.errorCode
|
|
12815
12664
|
};
|
|
12816
|
-
|
|
12665
|
+
logger15.error("LLM \u8C03\u7528\u5931\u8D25", {
|
|
12817
12666
|
attempt: attempt + 1,
|
|
12818
12667
|
maxAttempts: currentMaxRetries + 1,
|
|
12819
12668
|
actualAttempts,
|
|
@@ -12822,7 +12671,7 @@ async function callWithRetryFallback(params) {
|
|
|
12822
12671
|
});
|
|
12823
12672
|
previousAttemptTracker = attemptTracker;
|
|
12824
12673
|
if (!hasLlmAttemptBudgetRemaining({ actualAttempts, maxTotalAttempts })) {
|
|
12825
|
-
|
|
12674
|
+
logger15.error("\u5DF2\u8FBE\u5230 LLM \u603B\u8C03\u7528\u6B21\u6570\u4E0A\u9650\uFF0C\u505C\u6B62\u91CD\u8BD5/\u5207\u6A21\u578B", {
|
|
12826
12675
|
actualAttempts,
|
|
12827
12676
|
maxTotalAttempts
|
|
12828
12677
|
});
|
|
@@ -12852,37 +12701,15 @@ async function callWithRetryFallback(params) {
|
|
|
12852
12701
|
attempt -= 1;
|
|
12853
12702
|
continue;
|
|
12854
12703
|
}
|
|
12855
|
-
const quotaFallbackModelId = tryCloudQuotaFallback({
|
|
12856
|
-
deps,
|
|
12857
|
-
activeModelId,
|
|
12858
|
-
options,
|
|
12859
|
-
excludedModelIds,
|
|
12860
|
-
requirement,
|
|
12861
|
-
error: lastError,
|
|
12862
|
-
fallbackObserver,
|
|
12863
|
-
evaluateFallbackPromptCapacity: invocationContext?.evaluateFallbackPromptCapacity
|
|
12864
|
-
});
|
|
12865
|
-
if (quotaFallbackModelId) {
|
|
12866
|
-
fallbackObserver?.onModelFallbackApplied?.({
|
|
12867
|
-
fromModelId: activeModelId,
|
|
12868
|
-
toModelId: quotaFallbackModelId,
|
|
12869
|
-
reason: lastError.message,
|
|
12870
|
-
policy: "cloud-quota"
|
|
12871
|
-
});
|
|
12872
|
-
activeModelId = quotaFallbackModelId;
|
|
12873
|
-
excludedModelIds.add(quotaFallbackModelId);
|
|
12874
|
-
attempt -= 1;
|
|
12875
|
-
continue;
|
|
12876
|
-
}
|
|
12877
12704
|
}
|
|
12878
12705
|
if (classification.category === "non_retryable" /* NON_RETRYABLE */) {
|
|
12879
|
-
|
|
12706
|
+
logger15.error("\u9519\u8BEF\u4E0D\u53EF\u91CD\u8BD5\uFF0C\u76F4\u63A5\u5931\u8D25", { reason: classification.reason });
|
|
12880
12707
|
retryEpisode.finish("failed", failedRetryState);
|
|
12881
12708
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
12882
12709
|
throw lastError;
|
|
12883
12710
|
}
|
|
12884
12711
|
if (attempt >= configuredMaxRetries || categoryRetries[category] >= currentMaxRetries) {
|
|
12885
|
-
|
|
12712
|
+
logger15.error("\u5DF2\u8FBE\u5230\u6700\u5927\u91CD\u8BD5\u6B21\u6570\uFF0C\u653E\u5F03\u91CD\u8BD5", { maxRetries: currentMaxRetries });
|
|
12886
12713
|
retryEpisode.finish("exhausted", failedRetryState);
|
|
12887
12714
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
12888
12715
|
throw lastError;
|
|
@@ -12894,9 +12721,9 @@ async function callWithRetryFallback(params) {
|
|
|
12894
12721
|
6e4
|
|
12895
12722
|
);
|
|
12896
12723
|
if (classification.category === "rate_limit" /* RATE_LIMIT */) {
|
|
12897
|
-
|
|
12724
|
+
logger15.warn("\u901F\u7387\u9650\u5236\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
12898
12725
|
} else if (classification.category === "retryable" /* RETRYABLE */) {
|
|
12899
|
-
|
|
12726
|
+
logger15.warn("\u53EF\u91CD\u8BD5\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
12900
12727
|
}
|
|
12901
12728
|
throwIfAborted(signal, "\u5EF6\u8FDF\u7B49\u5F85\u524D\u68C0\u6D4B\u5230\u53D6\u6D88\u4FE1\u53F7\uFF0C\u505C\u6B62\u91CD\u8BD5");
|
|
12902
12729
|
categoryRetries[category] += 1;
|
|
@@ -12933,16 +12760,11 @@ function waitForRetry(delayMs, signal) {
|
|
|
12933
12760
|
}
|
|
12934
12761
|
function isClientRetryEnabledForModel(modelCatalog, modelId, options) {
|
|
12935
12762
|
if (options.retry_policy === "none") return false;
|
|
12936
|
-
|
|
12937
|
-
if (cfg?.billing_mode === "cloud") return false;
|
|
12938
|
-
if (options.retry_policy === "client") return true;
|
|
12939
|
-
if (!cfg) return true;
|
|
12940
|
-
if (cfg.enable_client_retry === false) return false;
|
|
12941
|
-
return true;
|
|
12763
|
+
return modelCatalog.getModelById(modelId)?.enable_client_retry !== false;
|
|
12942
12764
|
}
|
|
12943
12765
|
function throwIfAborted(signal, message) {
|
|
12944
12766
|
if (!signal?.aborted) return;
|
|
12945
|
-
|
|
12767
|
+
logger15.info(message);
|
|
12946
12768
|
const reason = signal.reason;
|
|
12947
12769
|
if (reason instanceof Error && reason.name === "AbortError") throw reason;
|
|
12948
12770
|
const reasonText = typeof reason === "string" && reason.trim().length > 0 ? reason : "stream_interrupted";
|
|
@@ -13260,7 +13082,7 @@ async function recoverChildRunEventsFromCheckpoint(params) {
|
|
|
13260
13082
|
}
|
|
13261
13083
|
|
|
13262
13084
|
// src/runtime-kernel/child-runs/childRunInvoker.ts
|
|
13263
|
-
var
|
|
13085
|
+
var logger16 = new Logger("ChildRunInvoker");
|
|
13264
13086
|
var ChildRunInvoker = class {
|
|
13265
13087
|
modelResolver;
|
|
13266
13088
|
createLlmNode;
|
|
@@ -13302,7 +13124,7 @@ var ChildRunInvoker = class {
|
|
|
13302
13124
|
const resolvedParentRunId = parentRunId ?? parentToolContext.runId;
|
|
13303
13125
|
const depthDecision = decideChildRunDepth({ parentToolContext });
|
|
13304
13126
|
if (!depthDecision.allowed) {
|
|
13305
|
-
|
|
13127
|
+
logger16.warn("child-run \u6DF1\u5EA6\u8D85\u8FC7\u4E0A\u9650\uFF0C\u62D2\u7EDD\u7EE7\u7EED\u9012\u5F52\u6267\u884C", {
|
|
13306
13128
|
runId: childRunId,
|
|
13307
13129
|
parentRunId: resolvedParentRunId,
|
|
13308
13130
|
parentDepth: depthDecision.parentDepth,
|
|
@@ -13319,7 +13141,7 @@ var ChildRunInvoker = class {
|
|
|
13319
13141
|
};
|
|
13320
13142
|
}
|
|
13321
13143
|
if (abortSignal?.aborted || parentToolContext.abortSignal?.aborted) {
|
|
13322
|
-
|
|
13144
|
+
logger16.info("child-run \u5728\u4EFB\u52A1\u63A5\u7EB3\u524D\u5DF2\u53D6\u6D88", {
|
|
13323
13145
|
runId: childRunId,
|
|
13324
13146
|
parentRunId: resolvedParentRunId
|
|
13325
13147
|
});
|
|
@@ -13343,7 +13165,7 @@ var ChildRunInvoker = class {
|
|
|
13343
13165
|
}
|
|
13344
13166
|
const turnId = config.initialInput?.turnId ?? generateTurnId();
|
|
13345
13167
|
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");
|
|
13346
|
-
|
|
13168
|
+
logger16.info(`\u542F\u52A8 child-run: ${agentConfig.id}`, {
|
|
13347
13169
|
conversationId: runtimeConversationId,
|
|
13348
13170
|
checkpointKey: internalCheckpointKey,
|
|
13349
13171
|
maxSteps,
|
|
@@ -13461,7 +13283,7 @@ var ChildRunInvoker = class {
|
|
|
13461
13283
|
);
|
|
13462
13284
|
finalAnswer = extractFinalAnswer(allEvents);
|
|
13463
13285
|
lastProgress = finalAnswer ? void 0 : extractLastProgress(allEvents);
|
|
13464
|
-
|
|
13286
|
+
logger16.info("child-run \u6267\u884C\u5B8C\u6210", {
|
|
13465
13287
|
stepCount,
|
|
13466
13288
|
eventCount: allEvents.length,
|
|
13467
13289
|
hasFinalAnswer: !!finalAnswer,
|
|
@@ -13491,13 +13313,13 @@ var ChildRunInvoker = class {
|
|
|
13491
13313
|
cancelled = abortSignal?.aborted === true || isAbortError2(err);
|
|
13492
13314
|
error = err instanceof Error ? err.message : String(err);
|
|
13493
13315
|
if (cancelled) {
|
|
13494
|
-
|
|
13316
|
+
logger16.info("child-run \u6267\u884C\u53D6\u6D88", {
|
|
13495
13317
|
runId: childRunId,
|
|
13496
13318
|
parentRunId: resolvedParentRunId,
|
|
13497
13319
|
message: error
|
|
13498
13320
|
});
|
|
13499
13321
|
} else {
|
|
13500
|
-
|
|
13322
|
+
logger16.error(
|
|
13501
13323
|
"child-run \u6267\u884C\u5931\u8D25:",
|
|
13502
13324
|
err instanceof Error ? {
|
|
13503
13325
|
name: err.name,
|
|
@@ -13593,7 +13415,7 @@ var ChildRunInvoker = class {
|
|
|
13593
13415
|
function isAbortError2(error) {
|
|
13594
13416
|
return error instanceof Error && error.name === "AbortError";
|
|
13595
13417
|
}
|
|
13596
|
-
function
|
|
13418
|
+
function readNonEmptyString5(value) {
|
|
13597
13419
|
if (typeof value !== "string") {
|
|
13598
13420
|
return void 0;
|
|
13599
13421
|
}
|
|
@@ -13601,7 +13423,7 @@ function readNonEmptyString6(value) {
|
|
|
13601
13423
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
13602
13424
|
}
|
|
13603
13425
|
function resolveChildRunConversationId(params) {
|
|
13604
|
-
const conversationId =
|
|
13426
|
+
const conversationId = readNonEmptyString5(params.explicitConversationId) ?? readNonEmptyString5(params.parentToolContext.conversationId);
|
|
13605
13427
|
if (!conversationId) {
|
|
13606
13428
|
throw new Error(
|
|
13607
13429
|
"ChildRunInvoker requires conversationId from admission or parent ToolContext."
|
|
@@ -13610,7 +13432,7 @@ function resolveChildRunConversationId(params) {
|
|
|
13610
13432
|
return conversationId;
|
|
13611
13433
|
}
|
|
13612
13434
|
function resolveChildRunModelId(params) {
|
|
13613
|
-
const explicitModelId =
|
|
13435
|
+
const explicitModelId = readNonEmptyString5(params.explicitModelId);
|
|
13614
13436
|
if (explicitModelId) {
|
|
13615
13437
|
return explicitModelId;
|
|
13616
13438
|
}
|
|
@@ -14555,7 +14377,7 @@ function runMetaFromRecord(record) {
|
|
|
14555
14377
|
}
|
|
14556
14378
|
|
|
14557
14379
|
// src/runtime-kernel/run-supervisor/functions/awaitingUserWatcher.ts
|
|
14558
|
-
var
|
|
14380
|
+
var logger17 = new Logger("RunSupervisorAwaitingUserWatcher");
|
|
14559
14381
|
function isRecord16(value) {
|
|
14560
14382
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14561
14383
|
}
|
|
@@ -14600,7 +14422,7 @@ function createAwaitingUserWatcher(options) {
|
|
|
14600
14422
|
resumeToken: event.resume_token
|
|
14601
14423
|
}
|
|
14602
14424
|
}).catch((error) => {
|
|
14603
|
-
|
|
14425
|
+
logger17.warn("failed to mark awaiting_user from requires_user_interaction", { error });
|
|
14604
14426
|
});
|
|
14605
14427
|
};
|
|
14606
14428
|
const dispose = () => {
|