@linnlabs/linnkit 0.46.0 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/dist/cli.cjs +64 -246
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +64 -246
- package/dist/cli.js.map +1 -1
- package/dist/context-manager.cjs +7 -7
- package/dist/context-manager.cjs.map +1 -1
- package/dist/context-manager.js +7 -7
- package/dist/context-manager.js.map +1 -1
- package/dist/index.cjs +74 -257
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +74 -257
- package/dist/index.js.map +1 -1
- package/dist/ports/llm-call.d.cts +2 -16
- package/dist/ports/llm-call.d.ts +2 -16
- package/dist/quickstart.cjs +64 -246
- package/dist/quickstart.cjs.map +1 -1
- package/dist/quickstart.js +64 -246
- package/dist/quickstart.js.map +1 -1
- package/dist/runtime-kernel/graph-engine/executor.d.cts +0 -2
- package/dist/runtime-kernel/graph-engine/executor.d.ts +0 -2
- package/dist/runtime-kernel/graph-engine/types.d.cts +1 -2
- package/dist/runtime-kernel/graph-engine/types.d.ts +1 -2
- package/dist/runtime-kernel/llm/definitions/llmFallbackObserver.d.cts +1 -2
- package/dist/runtime-kernel/llm/definitions/llmFallbackObserver.d.ts +1 -2
- package/dist/runtime-kernel/llm/modelCatalog.d.cts +2 -3
- package/dist/runtime-kernel/llm/modelCatalog.d.ts +2 -3
- package/dist/runtime-kernel/tools/toolContextRuntime.d.cts +1 -1
- package/dist/runtime-kernel/tools/toolContextRuntime.d.ts +1 -1
- package/dist/runtime-kernel/tools/toolExecutionContext.d.cts +0 -10
- package/dist/runtime-kernel/tools/toolExecutionContext.d.ts +0 -10
- package/dist/runtime-kernel.cjs +74 -257
- package/dist/runtime-kernel.cjs.map +1 -1
- package/dist/runtime-kernel.js +74 -257
- package/dist/runtime-kernel.js.map +1 -1
- package/dist/testkit.cjs +82 -265
- package/dist/testkit.cjs.map +1 -1
- package/dist/testkit.js +82 -265
- package/dist/testkit.js.map +1 -1
- package/docs/integration/llm-provider.md +1 -1
- package/docs/integration/tool-development-guide.md +1 -1
- package/package.json +1 -1
package/dist/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,7 +6126,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
6193
6126
|
"turnId"
|
|
6194
6127
|
],
|
|
6195
6128
|
writes: [
|
|
6196
|
-
"cloudQuotaFallbackAppliedModelId",
|
|
6197
6129
|
"modelFallbackAudit",
|
|
6198
6130
|
"llmCallStartedAt",
|
|
6199
6131
|
"llmResp",
|
|
@@ -6201,7 +6133,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
6201
6133
|
"contextUsage"
|
|
6202
6134
|
],
|
|
6203
6135
|
async run(ctx) {
|
|
6204
|
-
let cloudQuotaFallbackAppliedModelId;
|
|
6205
6136
|
let modelFallbackAudit;
|
|
6206
6137
|
let contextUsage;
|
|
6207
6138
|
const modelFallbackRejections = [];
|
|
@@ -6220,9 +6151,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
6220
6151
|
streamEventHandler,
|
|
6221
6152
|
ctx.signal,
|
|
6222
6153
|
{
|
|
6223
|
-
onCloudQuotaFallbackApplied(fallbackModelId) {
|
|
6224
|
-
cloudQuotaFallbackAppliedModelId = readNonEmptyString3(fallbackModelId);
|
|
6225
|
-
},
|
|
6226
6154
|
onLlmAttemptSucceeded(_activeModelId, attemptContextUsage) {
|
|
6227
6155
|
contextUsage = attemptContextUsage;
|
|
6228
6156
|
},
|
|
@@ -6319,7 +6247,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
6319
6247
|
});
|
|
6320
6248
|
}
|
|
6321
6249
|
return {
|
|
6322
|
-
cloudQuotaFallbackAppliedModelId,
|
|
6323
6250
|
modelFallbackAudit,
|
|
6324
6251
|
llmCallStartedAt,
|
|
6325
6252
|
llmResp,
|
|
@@ -7240,18 +7167,16 @@ function createPrepareCallStage(dependencies) {
|
|
|
7240
7167
|
"toolDefinitionTokens"
|
|
7241
7168
|
],
|
|
7242
7169
|
async run(ctx) {
|
|
7243
|
-
const
|
|
7244
|
-
const requestedModelId = lockedRunModelId ?? ctx.request.model_id;
|
|
7170
|
+
const requestedModelId = ctx.request.model_id;
|
|
7245
7171
|
const modelId = dependencies.modelResolver.resolveModelId(requestedModelId);
|
|
7246
7172
|
await emitAuditEnvelope(ctx.audit, {
|
|
7247
7173
|
action: "model.select",
|
|
7248
7174
|
actor: { kind: "system" },
|
|
7249
7175
|
decision: {
|
|
7250
7176
|
outcome: "recorded",
|
|
7251
|
-
reason:
|
|
7177
|
+
reason: requestedModelId ? "request model id" : "default model resolver",
|
|
7252
7178
|
metadata: {
|
|
7253
7179
|
requestedModelId,
|
|
7254
|
-
lockedRunModelId,
|
|
7255
7180
|
selectedModelId: modelId
|
|
7256
7181
|
}
|
|
7257
7182
|
},
|
|
@@ -7298,10 +7223,6 @@ function createPrepareCallStage(dependencies) {
|
|
|
7298
7223
|
if (ctx.executorLocal?.lockRequestedModelId === true) {
|
|
7299
7224
|
llmOptions.allow_model_fallback = false;
|
|
7300
7225
|
}
|
|
7301
|
-
const isRunContinuation = ctx.executorLocal?.llmInvocationKind === "continuation";
|
|
7302
|
-
if (dependencies.cloudQuotaFallbackModelId && modelConfig?.billing_mode === "cloud" && modelId !== dependencies.cloudQuotaFallbackModelId && isRunContinuation && ctx.executorLocal?.lockRequestedModelId !== true) {
|
|
7303
|
-
llmOptions.cloud_quota_fallback_model_id = dependencies.cloudQuotaFallbackModelId;
|
|
7304
|
-
}
|
|
7305
7226
|
const effectiveEffort = resolveEffectiveEffort(
|
|
7306
7227
|
ctx.request.reasoning_effort,
|
|
7307
7228
|
modelConfig?.reasoning
|
|
@@ -7418,12 +7339,11 @@ function applyCalibration(rawLocalTotal, imageInputTokens, coefficient) {
|
|
|
7418
7339
|
}
|
|
7419
7340
|
|
|
7420
7341
|
// src/runtime-kernel/graph-engine/executor.ts
|
|
7421
|
-
var
|
|
7342
|
+
var logger5 = new Logger("GraphAgentExecutor");
|
|
7422
7343
|
var GraphAgentExecutor = class {
|
|
7423
7344
|
llmCaller;
|
|
7424
7345
|
toolRuntime;
|
|
7425
7346
|
contextBuilder;
|
|
7426
|
-
cloudQuotaFallbackModelId;
|
|
7427
7347
|
modelResolver;
|
|
7428
7348
|
modelCatalog;
|
|
7429
7349
|
telemetryPort;
|
|
@@ -7435,7 +7355,6 @@ var GraphAgentExecutor = class {
|
|
|
7435
7355
|
this.llmCaller = dependencies.llmCaller;
|
|
7436
7356
|
this.toolRuntime = dependencies.toolRuntime;
|
|
7437
7357
|
this.contextBuilder = dependencies.contextBuilder;
|
|
7438
|
-
this.cloudQuotaFallbackModelId = readNonEmptyString3(dependencies.cloudQuotaFallbackModelId);
|
|
7439
7358
|
this.modelCatalog = dependencies.modelCatalog ?? createEmptyModelCatalog();
|
|
7440
7359
|
this.modelResolver = dependencies.modelResolver ?? new ModelResolver({
|
|
7441
7360
|
modelCatalog: this.modelCatalog
|
|
@@ -7452,8 +7371,7 @@ var GraphAgentExecutor = class {
|
|
|
7452
7371
|
createPrepareCallStage({
|
|
7453
7372
|
modelResolver: this.modelResolver,
|
|
7454
7373
|
modelCatalog: this.modelCatalog,
|
|
7455
|
-
toolCatalog: this.toolRuntime
|
|
7456
|
-
cloudQuotaFallbackModelId: this.cloudQuotaFallbackModelId
|
|
7374
|
+
toolCatalog: this.toolRuntime
|
|
7457
7375
|
}),
|
|
7458
7376
|
createBuildContextStage({
|
|
7459
7377
|
contextBuilder: this.contextBuilder
|
|
@@ -7475,7 +7393,7 @@ var GraphAgentExecutor = class {
|
|
|
7475
7393
|
}),
|
|
7476
7394
|
createBuildDecisionStage()
|
|
7477
7395
|
];
|
|
7478
|
-
this.middlewares = [llmTelemetryMiddleware
|
|
7396
|
+
this.middlewares = [llmTelemetryMiddleware];
|
|
7479
7397
|
}
|
|
7480
7398
|
async tick(input, eventHandler) {
|
|
7481
7399
|
const ctx = {
|
|
@@ -7500,7 +7418,7 @@ var GraphAgentExecutor = class {
|
|
|
7500
7418
|
audit: this.auditPort,
|
|
7501
7419
|
tokenizer: this.tokenizer
|
|
7502
7420
|
};
|
|
7503
|
-
|
|
7421
|
+
logger5.info("[GraphAgentExecutor] tick \u8C03\u7528", {
|
|
7504
7422
|
stream: input.stream === true,
|
|
7505
7423
|
hasEventHandler: Boolean(eventHandler),
|
|
7506
7424
|
hasSummarizationCallbacks: Boolean(input.summarizationCallbacks)
|
|
@@ -8523,7 +8441,7 @@ var LlmNodeEventBridge = class {
|
|
|
8523
8441
|
};
|
|
8524
8442
|
|
|
8525
8443
|
// src/runtime-kernel/graph-engine/nodes/llmNode.ts
|
|
8526
|
-
var
|
|
8444
|
+
var logger6 = new Logger("LlmNode");
|
|
8527
8445
|
var LlmNode = class {
|
|
8528
8446
|
id = "llm";
|
|
8529
8447
|
reasoner;
|
|
@@ -8532,7 +8450,7 @@ var LlmNode = class {
|
|
|
8532
8450
|
}
|
|
8533
8451
|
async run(state) {
|
|
8534
8452
|
const local = state.local ?? {};
|
|
8535
|
-
|
|
8453
|
+
logger6.info("[LlmNode] \u5F00\u59CB\u6267\u884C LLM \u8282\u70B9", {
|
|
8536
8454
|
localKeys: Object.keys(local)
|
|
8537
8455
|
});
|
|
8538
8456
|
const graphLocal = readGraphAgentLocal(state.local);
|
|
@@ -8547,12 +8465,12 @@ var LlmNode = class {
|
|
|
8547
8465
|
signal,
|
|
8548
8466
|
history
|
|
8549
8467
|
} = graphLocal;
|
|
8550
|
-
|
|
8468
|
+
logger6.info("[LlmNode] \u5DF2\u52A0\u8F7D\u5386\u53F2\u4E8B\u4EF6", {
|
|
8551
8469
|
historyCount: history.length,
|
|
8552
8470
|
hasSummarizationCallbacks: Boolean(summarizationCallbacks)
|
|
8553
8471
|
});
|
|
8554
8472
|
if (!request) {
|
|
8555
|
-
|
|
8473
|
+
logger6.warn("Request object is missing, yielding.");
|
|
8556
8474
|
return { kind: "yield", events: [] };
|
|
8557
8475
|
}
|
|
8558
8476
|
const turnId = requireRuntimeIdentity(graphLocal.turnId, "turnId");
|
|
@@ -8645,12 +8563,12 @@ var LlmNode = class {
|
|
|
8645
8563
|
...nodeState.streamRuntimeEvents,
|
|
8646
8564
|
...contextUsageEvent ? [contextUsageEvent] : []
|
|
8647
8565
|
];
|
|
8648
|
-
|
|
8566
|
+
logger6.info("[LlmNode] \u5386\u53F2\u4E8B\u4EF6\u5DF2\u66F4\u65B0", {
|
|
8649
8567
|
previousCount: history.length,
|
|
8650
8568
|
nextCount: patch.history.length,
|
|
8651
8569
|
streamedEventCount: nodeState.streamRuntimeEvents.length
|
|
8652
8570
|
});
|
|
8653
|
-
|
|
8571
|
+
logger6.info("[LlmNode] \u6267\u884C\u5668\u51B3\u7B56\u5B8C\u6210", {
|
|
8654
8572
|
decisionKind: decision.kind,
|
|
8655
8573
|
emittedEventCount: combinedEvents.length
|
|
8656
8574
|
});
|
|
@@ -8672,7 +8590,7 @@ var LlmNode = class {
|
|
|
8672
8590
|
}
|
|
8673
8591
|
case "error": {
|
|
8674
8592
|
const { name, message, stack } = decision.error;
|
|
8675
|
-
|
|
8593
|
+
logger6.error("[LlmNode] Executor returned an error", { name, message, stack });
|
|
8676
8594
|
return { kind: "yield", events: combinedEvents };
|
|
8677
8595
|
}
|
|
8678
8596
|
default: {
|
|
@@ -8778,7 +8696,7 @@ async function resolveToolModelInput(input) {
|
|
|
8778
8696
|
}
|
|
8779
8697
|
|
|
8780
8698
|
// src/runtime-kernel/graph-engine/nodes/toolNode.finalAnswerProjector.ts
|
|
8781
|
-
function
|
|
8699
|
+
function readNonEmptyString4(value) {
|
|
8782
8700
|
if (typeof value !== "string") {
|
|
8783
8701
|
return void 0;
|
|
8784
8702
|
}
|
|
@@ -8786,7 +8704,7 @@ function readNonEmptyString5(value) {
|
|
|
8786
8704
|
return normalized.length > 0 ? normalized : void 0;
|
|
8787
8705
|
}
|
|
8788
8706
|
function resolveFinalAnswerFromToolControl(finalAnswer) {
|
|
8789
|
-
return
|
|
8707
|
+
return readNonEmptyString4(finalAnswer);
|
|
8790
8708
|
}
|
|
8791
8709
|
|
|
8792
8710
|
// src/runtime-kernel/graph-engine/nodes/toolNode.helpers.ts
|
|
@@ -9042,7 +8960,7 @@ function buildErrorLocalState(params) {
|
|
|
9042
8960
|
}
|
|
9043
8961
|
|
|
9044
8962
|
// src/runtime-kernel/tools/argNormalizer.ts
|
|
9045
|
-
var
|
|
8963
|
+
var logger7 = new Logger("ToolArgNormalizer");
|
|
9046
8964
|
function isRecord10(v) {
|
|
9047
8965
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
9048
8966
|
}
|
|
@@ -9062,7 +8980,7 @@ function joinPath(basePath, segment) {
|
|
|
9062
8980
|
function logJsonEncodedNormalization(expectedType, options) {
|
|
9063
8981
|
const toolPrefix = options.toolName ? `${options.toolName}.` : "";
|
|
9064
8982
|
const path = options.path ?? "<root>";
|
|
9065
|
-
|
|
8983
|
+
logger7.warn("normalized JSON-encoded tool argument", {
|
|
9066
8984
|
expectedType,
|
|
9067
8985
|
path: `${toolPrefix}${path}`
|
|
9068
8986
|
});
|
|
@@ -9232,7 +9150,6 @@ var TOOL_CONTEXT_RUNTIME_RESERVED_KEYS = [
|
|
|
9232
9150
|
"conversationView",
|
|
9233
9151
|
"userQuery",
|
|
9234
9152
|
"modelId",
|
|
9235
|
-
"activeModelId",
|
|
9236
9153
|
"conversationId",
|
|
9237
9154
|
"turnId",
|
|
9238
9155
|
"runId",
|
|
@@ -9419,7 +9336,7 @@ function stripRuntimeReservedToolContextPatch(patch) {
|
|
|
9419
9336
|
}
|
|
9420
9337
|
|
|
9421
9338
|
// src/runtime-kernel/graph-engine/nodes/toolNode.eventBridge.ts
|
|
9422
|
-
var
|
|
9339
|
+
var logger8 = new Logger("ToolNode");
|
|
9423
9340
|
var ToolNodeEventBridge = class {
|
|
9424
9341
|
constructor(deps) {
|
|
9425
9342
|
this.deps = deps;
|
|
@@ -9441,7 +9358,7 @@ var ToolNodeEventBridge = class {
|
|
|
9441
9358
|
status,
|
|
9442
9359
|
payload: { ...payload }
|
|
9443
9360
|
};
|
|
9444
|
-
|
|
9361
|
+
logger8.info("[ToolNode] \u53D1\u51FA tool_process \u4E8B\u4EF6", {
|
|
9445
9362
|
phase,
|
|
9446
9363
|
status,
|
|
9447
9364
|
toolName: this.deps.toolName,
|
|
@@ -9481,7 +9398,7 @@ var ToolNodeEventBridge = class {
|
|
|
9481
9398
|
const answerId = generateAnswerSegmentId();
|
|
9482
9399
|
const id = answerId;
|
|
9483
9400
|
const timestamp = Date.now();
|
|
9484
|
-
|
|
9401
|
+
logger8.info("[ToolNode] \u5DE5\u5177\u8F93\u51FA\u6620\u5C04\u4E3A final_answer", {
|
|
9485
9402
|
sourceToolName: params.sourceToolName,
|
|
9486
9403
|
toolCallId: this.deps.toolCallId,
|
|
9487
9404
|
conversationId: this.deps.conversationId,
|
|
@@ -9539,7 +9456,7 @@ var ToolNodeEventBridge = class {
|
|
|
9539
9456
|
};
|
|
9540
9457
|
|
|
9541
9458
|
// src/runtime-kernel/graph-engine/nodes/toolNode.executionSetup.ts
|
|
9542
|
-
var
|
|
9459
|
+
var logger9 = new Logger("ToolNode");
|
|
9543
9460
|
function parseToolArgs(call) {
|
|
9544
9461
|
const rawArguments = typeof call.function?.arguments === "string" ? call.function.arguments : "";
|
|
9545
9462
|
if (!rawArguments.trim()) {
|
|
@@ -9559,19 +9476,13 @@ function parseToolArgs(call) {
|
|
|
9559
9476
|
return { ok: true, value: parsed };
|
|
9560
9477
|
} catch (error) {
|
|
9561
9478
|
const reason = error instanceof Error ? error.message : "Unknown JSON parse error";
|
|
9562
|
-
|
|
9479
|
+
logger9.warn("failed to parse tool arguments", { error });
|
|
9563
9480
|
return {
|
|
9564
9481
|
ok: false,
|
|
9565
9482
|
error: `Tool arguments are not valid JSON: ${reason}`
|
|
9566
9483
|
};
|
|
9567
9484
|
}
|
|
9568
9485
|
}
|
|
9569
|
-
function readRunLockedModelId(local) {
|
|
9570
|
-
const executorLocal = local.executorLocal;
|
|
9571
|
-
if (!isRecord9(executorLocal)) return void 0;
|
|
9572
|
-
const lockedModelId = executorLocal.runLockedModelId;
|
|
9573
|
-
return typeof lockedModelId === "string" && lockedModelId.trim() ? lockedModelId : void 0;
|
|
9574
|
-
}
|
|
9575
9486
|
function prepareToolNodeContext(state) {
|
|
9576
9487
|
const local = state.local || {};
|
|
9577
9488
|
const toolContext = isRecord9(local.toolContext) ? local.toolContext : {};
|
|
@@ -9589,7 +9500,6 @@ function prepareToolNodeContext(state) {
|
|
|
9589
9500
|
}
|
|
9590
9501
|
});
|
|
9591
9502
|
attachWorkingHistoryView({ state, toolContext });
|
|
9592
|
-
toolContext.activeModelId = readRunLockedModelId(local) ?? toolContext.modelId;
|
|
9593
9503
|
return {
|
|
9594
9504
|
state,
|
|
9595
9505
|
local,
|
|
@@ -9967,7 +9877,7 @@ async function claimPendingUserInputs(state, result) {
|
|
|
9967
9877
|
}
|
|
9968
9878
|
|
|
9969
9879
|
// src/runtime-kernel/graph-engine/nodes/toolNode.ts
|
|
9970
|
-
var
|
|
9880
|
+
var logger10 = new Logger("ToolNode");
|
|
9971
9881
|
function isAbortSignal(value) {
|
|
9972
9882
|
return value !== null && typeof value === "object" && "aborted" in value;
|
|
9973
9883
|
}
|
|
@@ -10180,7 +10090,7 @@ var ToolNode = class {
|
|
|
10180
10090
|
throw abortError;
|
|
10181
10091
|
}
|
|
10182
10092
|
const prepared = prepareToolNodeContext(state);
|
|
10183
|
-
|
|
10093
|
+
logger10.info("[ToolNode] \u5F00\u59CB\u6267\u884C\u5DE5\u5177\u8282\u70B9", {
|
|
10184
10094
|
conversationId: prepared.conversationId,
|
|
10185
10095
|
turnId: prepared.turnId,
|
|
10186
10096
|
pendingCallCount: calls.length
|
|
@@ -10195,7 +10105,7 @@ var ToolNode = class {
|
|
|
10195
10105
|
toolCatalog: this.toolRuntime
|
|
10196
10106
|
});
|
|
10197
10107
|
if (!execution) {
|
|
10198
|
-
|
|
10108
|
+
logger10.warn("no tool name found in call");
|
|
10199
10109
|
return { kind: "yield", events: [] };
|
|
10200
10110
|
}
|
|
10201
10111
|
if (typeof execution.protocolError === "string") {
|
|
@@ -10235,7 +10145,7 @@ var ToolNode = class {
|
|
|
10235
10145
|
call,
|
|
10236
10146
|
context: prepared.toolContext,
|
|
10237
10147
|
abortGraceMs: this.abortGraceMs,
|
|
10238
|
-
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", {
|
|
10239
10149
|
toolName: execution.toolName,
|
|
10240
10150
|
toolCallId: execution.toolCallId,
|
|
10241
10151
|
conversationId: prepared.conversationId,
|
|
@@ -10405,7 +10315,7 @@ var ToolNode = class {
|
|
|
10405
10315
|
runtimeEvents: context.bridge.getRuntimeEvents()
|
|
10406
10316
|
});
|
|
10407
10317
|
if (control?.terminateRun) {
|
|
10408
|
-
|
|
10318
|
+
logger10.info("[ToolNode] \u6536\u5230 control.terminateRun\uFF0C\u6267\u884C\u5B8C\u5DE5\u5177\u540E\u76F4\u63A5 yield \u7ED3\u675F\u672C\u8F6E run", {
|
|
10409
10319
|
toolName: context.toolName,
|
|
10410
10320
|
toolCallId: context.toolCallId,
|
|
10411
10321
|
conversationId: context.conversationId,
|
|
@@ -10414,7 +10324,7 @@ var ToolNode = class {
|
|
|
10414
10324
|
return { kind: "yield", events: context.bridge.getRuntimeEvents() };
|
|
10415
10325
|
}
|
|
10416
10326
|
if (remainingCalls.length === 0 && context.local.toolBatchCompletionMode === "yield_after_batch") {
|
|
10417
|
-
|
|
10327
|
+
logger10.info("[ToolNode] \u5DE5\u5177\u6279\u6B21\u5DF2\u7ED3\u7B97\uFF0C\u6309 Host \u7B56\u7565\u76F4\u63A5 yield", {
|
|
10418
10328
|
toolName: context.toolName,
|
|
10419
10329
|
toolCallId: context.toolCallId,
|
|
10420
10330
|
conversationId: context.conversationId,
|
|
@@ -10861,8 +10771,9 @@ var executor = z.object({
|
|
|
10861
10771
|
lastStepsHintThreshold: counter.optional(),
|
|
10862
10772
|
systemReminderPolicy: AgentSpecSystemReminderPolicy.optional(),
|
|
10863
10773
|
toolObservationPolicy: AgentSpecToolObservationGovernancePolicy.optional(),
|
|
10774
|
+
// 已删除字段:0.45 及更早的 checkpoint 可能带 lastSuccessfulLlmModelId,0.46 及更早的可能带云端额度兜底留下的
|
|
10775
|
+
// runLockedModelId;照常接受,读入时丢弃(兜底已移除,恢复后按请求的模型继续)。
|
|
10864
10776
|
runLockedModelId: z.string().optional(),
|
|
10865
|
-
// 0.45 及更早的 checkpoint 可能带这个已删除字段;照常接受,读入时丢弃。
|
|
10866
10777
|
lastSuccessfulLlmModelId: z.string().optional(),
|
|
10867
10778
|
llmInvocationKind: z.enum(["user_initiated", "continuation"]).optional(),
|
|
10868
10779
|
llmInvocationCount: counter.optional(),
|
|
@@ -10872,7 +10783,7 @@ var executor = z.object({
|
|
|
10872
10783
|
committedCount: counter,
|
|
10873
10784
|
lastCommittedFingerprint: z.string().optional()
|
|
10874
10785
|
}).strict().optional()
|
|
10875
|
-
}).strict().transform(({ lastSuccessfulLlmModelId: _retired, ...state }) => state);
|
|
10786
|
+
}).strict().transform(({ lastSuccessfulLlmModelId: _retired, runLockedModelId: _retiredLock, ...state }) => state);
|
|
10876
10787
|
var checkpoint = z.object({
|
|
10877
10788
|
nodeId: z.string().min(1),
|
|
10878
10789
|
schemaVersion: z.literal(ENGINE_STATE_SCHEMA_VERSION).optional(),
|
|
@@ -11186,7 +11097,7 @@ __export(execution_exports, {
|
|
|
11186
11097
|
});
|
|
11187
11098
|
|
|
11188
11099
|
// src/runtime-kernel/execution/event-bus.ts
|
|
11189
|
-
var
|
|
11100
|
+
var logger11 = new Logger("EventBus");
|
|
11190
11101
|
var TypedEventEmitter = class {
|
|
11191
11102
|
listeners = /* @__PURE__ */ new Map();
|
|
11192
11103
|
maxListeners = 10;
|
|
@@ -11194,7 +11105,7 @@ var TypedEventEmitter = class {
|
|
|
11194
11105
|
const listeners = this.getListeners(event);
|
|
11195
11106
|
listeners.add(listener);
|
|
11196
11107
|
if (listeners.size > this.maxListeners) {
|
|
11197
|
-
|
|
11108
|
+
logger11.warn("EventBus listener count exceeds configured max", {
|
|
11198
11109
|
event: String(event),
|
|
11199
11110
|
count: listeners.size,
|
|
11200
11111
|
maxListeners: this.maxListeners
|
|
@@ -11254,7 +11165,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
11254
11165
|
super();
|
|
11255
11166
|
this.executionId = executionId;
|
|
11256
11167
|
this.setMaxListeners(30);
|
|
11257
|
-
|
|
11168
|
+
logger11.info(`EventBus created for execution ${this.executionId}`);
|
|
11258
11169
|
}
|
|
11259
11170
|
/**
|
|
11260
11171
|
* 发布一个事件到总线
|
|
@@ -11263,7 +11174,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
11263
11174
|
publish(envelope) {
|
|
11264
11175
|
if (envelope.trace.execution_id !== this.executionId) {
|
|
11265
11176
|
const error = new Error("EventEnvelope execution_id does not match EventBus instance.");
|
|
11266
|
-
|
|
11177
|
+
logger11.error("Mismatched execution_id", {
|
|
11267
11178
|
busExecutionId: this.executionId,
|
|
11268
11179
|
eventExecutionId: envelope.trace.execution_id,
|
|
11269
11180
|
eventSeq: envelope.seq
|
|
@@ -11275,7 +11186,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
11275
11186
|
const error = new Error(
|
|
11276
11187
|
"EventBus only accepts RuntimeEvent with formal run routing identity."
|
|
11277
11188
|
);
|
|
11278
|
-
|
|
11189
|
+
logger11.error("RuntimeEvent is missing formal run routing identity", {
|
|
11279
11190
|
executionId: this.executionId,
|
|
11280
11191
|
eventId: envelope.payload.id,
|
|
11281
11192
|
eventType: envelope.payload.type
|
|
@@ -11289,14 +11200,14 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
11289
11200
|
* 关闭总线,清理所有监听器
|
|
11290
11201
|
*/
|
|
11291
11202
|
close() {
|
|
11292
|
-
|
|
11203
|
+
logger11.info(`Closing EventBus for execution ${this.executionId}`);
|
|
11293
11204
|
this.emit("close");
|
|
11294
11205
|
this.removeAllListeners();
|
|
11295
11206
|
}
|
|
11296
11207
|
};
|
|
11297
11208
|
|
|
11298
11209
|
// src/runtime-kernel/execution/sequencer.ts
|
|
11299
|
-
var
|
|
11210
|
+
var logger12 = new Logger("EventSequencer");
|
|
11300
11211
|
var EventSequencer = class {
|
|
11301
11212
|
executionId;
|
|
11302
11213
|
traceId;
|
|
@@ -11304,7 +11215,7 @@ var EventSequencer = class {
|
|
|
11304
11215
|
constructor(conversationId, traceId) {
|
|
11305
11216
|
this.executionId = generateExecutionId();
|
|
11306
11217
|
this.traceId = traceId || generateTraceId();
|
|
11307
|
-
|
|
11218
|
+
logger12.info(`EventSequencer created for conversation ${conversationId}`, {
|
|
11308
11219
|
executionId: this.executionId,
|
|
11309
11220
|
traceId: this.traceId
|
|
11310
11221
|
});
|
|
@@ -12162,7 +12073,7 @@ var ThoughtStreamSegmenter = class {
|
|
|
12162
12073
|
};
|
|
12163
12074
|
|
|
12164
12075
|
// src/runtime-kernel/llm/streaming-adapter.ts
|
|
12165
|
-
var
|
|
12076
|
+
var logger13 = new Logger("LlmCaller");
|
|
12166
12077
|
var CanonicalInferenceFailureError = class extends Error {
|
|
12167
12078
|
errorCode;
|
|
12168
12079
|
recoverable;
|
|
@@ -12386,7 +12297,7 @@ async function callLlmStream(params) {
|
|
|
12386
12297
|
} catch (error) {
|
|
12387
12298
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
12388
12299
|
if (normalized.name === "AbortError") {
|
|
12389
|
-
|
|
12300
|
+
logger13.info("Canonical inference \u6536\u5230\u53D6\u6D88\u7EC8\u6001\uFF0C\u4E0D\u53D1\u5E03\u666E\u901A error event", { modelId });
|
|
12390
12301
|
throw normalized;
|
|
12391
12302
|
}
|
|
12392
12303
|
const classification = ErrorClassifier.classify(normalized, {
|
|
@@ -12462,7 +12373,7 @@ var LlmRetryEpisode = class {
|
|
|
12462
12373
|
};
|
|
12463
12374
|
|
|
12464
12375
|
// src/runtime-kernel/llm/retry-fallback-routing.ts
|
|
12465
|
-
var
|
|
12376
|
+
var logger14 = new Logger("LlmCaller");
|
|
12466
12377
|
function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement, fallbackObserver, error, evaluateFallbackPromptCapacity2) {
|
|
12467
12378
|
deps.modelCatalog.getModelById(activeModelId);
|
|
12468
12379
|
const policyDecision = deps.policyEngine.decideOnError(error, {
|
|
@@ -12492,81 +12403,16 @@ function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement
|
|
|
12492
12403
|
reason: "no_eligible_fallback_candidate",
|
|
12493
12404
|
requiredPlacements: requirement.placements
|
|
12494
12405
|
});
|
|
12495
|
-
|
|
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");
|
|
12496
12407
|
return null;
|
|
12497
12408
|
}
|
|
12498
|
-
|
|
12409
|
+
logger14.warn("Policy \u5207\u6362\u6A21\u578B\u7EE7\u7EED", {
|
|
12499
12410
|
reason: policyDecision.reason,
|
|
12500
12411
|
activeModelId,
|
|
12501
12412
|
fallbackModelId
|
|
12502
12413
|
});
|
|
12503
12414
|
return fallbackModelId;
|
|
12504
12415
|
}
|
|
12505
|
-
function tryCloudQuotaFallback({
|
|
12506
|
-
deps,
|
|
12507
|
-
activeModelId,
|
|
12508
|
-
options,
|
|
12509
|
-
excludedModelIds,
|
|
12510
|
-
requirement,
|
|
12511
|
-
error,
|
|
12512
|
-
fallbackObserver,
|
|
12513
|
-
evaluateFallbackPromptCapacity: evaluateFallbackPromptCapacity2
|
|
12514
|
-
}) {
|
|
12515
|
-
const fallbackModelId = options.cloud_quota_fallback_model_id;
|
|
12516
|
-
if (!fallbackModelId || !ErrorClassifier.isCloudQuotaError(error) || excludedModelIds.has(fallbackModelId)) {
|
|
12517
|
-
return null;
|
|
12518
|
-
}
|
|
12519
|
-
const fallbackConfig = deps.modelCatalog.getModelById(fallbackModelId);
|
|
12520
|
-
if (!fallbackConfig?.api_key) {
|
|
12521
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
12522
|
-
fromModelId: activeModelId,
|
|
12523
|
-
candidateModelId: fallbackModelId,
|
|
12524
|
-
policy: "cloud-quota",
|
|
12525
|
-
reason: "fallback_model_unavailable",
|
|
12526
|
-
requiredPlacements: requirement.placements
|
|
12527
|
-
});
|
|
12528
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\u76EE\u6807\u4E0D\u53EF\u7528\uFF08\u672A\u6CE8\u518C\u6216\u7F3A\u5C11 API Key\uFF09", { fallbackModelId });
|
|
12529
|
-
return null;
|
|
12530
|
-
}
|
|
12531
|
-
const compatibility = evaluateModelInputCompatibility(fallbackConfig, requirement);
|
|
12532
|
-
if (!compatibility.compatible) {
|
|
12533
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
12534
|
-
fromModelId: activeModelId,
|
|
12535
|
-
candidateModelId: fallbackModelId,
|
|
12536
|
-
policy: "cloud-quota",
|
|
12537
|
-
reason: compatibility.reason,
|
|
12538
|
-
requiredPlacements: requirement.placements
|
|
12539
|
-
});
|
|
12540
|
-
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", {
|
|
12541
|
-
fallbackModelId,
|
|
12542
|
-
requiredPlacements: requirement.placements,
|
|
12543
|
-
reason: compatibility.reason
|
|
12544
|
-
});
|
|
12545
|
-
return null;
|
|
12546
|
-
}
|
|
12547
|
-
const capacityAdmission = evaluateFallbackPromptCapacity2?.(fallbackModelId);
|
|
12548
|
-
if (capacityAdmission && !capacityAdmission.admitted) {
|
|
12549
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
12550
|
-
fromModelId: activeModelId,
|
|
12551
|
-
candidateModelId: fallbackModelId,
|
|
12552
|
-
policy: "cloud-quota",
|
|
12553
|
-
reason: capacityAdmission.reason,
|
|
12554
|
-
requiredPlacements: requirement.placements
|
|
12555
|
-
});
|
|
12556
|
-
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", {
|
|
12557
|
-
fallbackModelId,
|
|
12558
|
-
reason: capacityAdmission.reason
|
|
12559
|
-
});
|
|
12560
|
-
return null;
|
|
12561
|
-
}
|
|
12562
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\uFF08run \u5185\u7EED\u8DD1\uFF09", {
|
|
12563
|
-
activeModelId,
|
|
12564
|
-
fallbackModelId,
|
|
12565
|
-
reason: error.message
|
|
12566
|
-
});
|
|
12567
|
-
fallbackObserver?.onCloudQuotaFallbackApplied?.(fallbackModelId);
|
|
12568
|
-
return fallbackModelId;
|
|
12569
|
-
}
|
|
12570
12416
|
|
|
12571
12417
|
// src/runtime-kernel/llm/usage-telemetry.ts
|
|
12572
12418
|
async function callPlainCompletion(inferencePort, modelId, messages, options = {}, signal, traceId) {
|
|
@@ -12689,7 +12535,7 @@ var LlmImageInputError = class extends Error {
|
|
|
12689
12535
|
};
|
|
12690
12536
|
|
|
12691
12537
|
// src/runtime-kernel/llm/retry-fallback.ts
|
|
12692
|
-
var
|
|
12538
|
+
var logger15 = new Logger("LlmCaller");
|
|
12693
12539
|
async function callWithRetryFallback(params) {
|
|
12694
12540
|
const {
|
|
12695
12541
|
deps,
|
|
@@ -12717,11 +12563,9 @@ async function callWithRetryFallback(params) {
|
|
|
12717
12563
|
const retryEpisode = new LlmRetryEpisode(traceId, eventHandler);
|
|
12718
12564
|
let previousAttemptTracker;
|
|
12719
12565
|
if (!clientRetryEnabled) {
|
|
12720
|
-
|
|
12721
|
-
logger16.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
12566
|
+
logger15.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
12722
12567
|
modelId,
|
|
12723
|
-
|
|
12724
|
-
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"
|
|
12725
12569
|
});
|
|
12726
12570
|
}
|
|
12727
12571
|
try {
|
|
@@ -12757,7 +12601,7 @@ async function callWithRetryFallback(params) {
|
|
|
12757
12601
|
}) : void 0;
|
|
12758
12602
|
try {
|
|
12759
12603
|
if (isRetry) {
|
|
12760
|
-
|
|
12604
|
+
logger15.info("LLM \u8C03\u7528\u91CD\u8BD5", { attempt, configuredMaxRetries });
|
|
12761
12605
|
}
|
|
12762
12606
|
actualAttempts++;
|
|
12763
12607
|
retryEpisode.retrying(actualAttempts);
|
|
@@ -12786,7 +12630,7 @@ async function callWithRetryFallback(params) {
|
|
|
12786
12630
|
if (deps.retryConfig.enableEmptyResponseRetry && !responseContent?.trim() && !toolCallsFromLLM?.length) {
|
|
12787
12631
|
throw new Error("LLM\u8FD4\u56DE\u4E86\u7A7A\u54CD\u5E94");
|
|
12788
12632
|
}
|
|
12789
|
-
|
|
12633
|
+
logger15.debug("LLM \u8C03\u7528\u6210\u529F", { attempts: actualAttempts, maxTotalAttempts });
|
|
12790
12634
|
if (attemptContextUsage) {
|
|
12791
12635
|
fallbackObserver?.onLlmAttemptSucceeded?.(activeModelId, attemptContextUsage);
|
|
12792
12636
|
} else {
|
|
@@ -12797,7 +12641,7 @@ async function callWithRetryFallback(params) {
|
|
|
12797
12641
|
} catch (error) {
|
|
12798
12642
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
12799
12643
|
if (lastError.name === "AbortError") {
|
|
12800
|
-
|
|
12644
|
+
logger15.info("LLM \u8C03\u7528\u5DF2\u53D6\u6D88\uFF0C\u4E0D\u8FDB\u5165 provider failure \u5206\u7C7B\u4E0E\u91CD\u8BD5\u6D41\u7A0B", {
|
|
12801
12645
|
attempt: attempt + 1,
|
|
12802
12646
|
actualAttempts,
|
|
12803
12647
|
maxTotalAttempts,
|
|
@@ -12816,7 +12660,7 @@ async function callWithRetryFallback(params) {
|
|
|
12816
12660
|
total_attempts: actualAttempts,
|
|
12817
12661
|
error_code: classification.errorCode
|
|
12818
12662
|
};
|
|
12819
|
-
|
|
12663
|
+
logger15.error("LLM \u8C03\u7528\u5931\u8D25", {
|
|
12820
12664
|
attempt: attempt + 1,
|
|
12821
12665
|
maxAttempts: currentMaxRetries + 1,
|
|
12822
12666
|
actualAttempts,
|
|
@@ -12825,7 +12669,7 @@ async function callWithRetryFallback(params) {
|
|
|
12825
12669
|
});
|
|
12826
12670
|
previousAttemptTracker = attemptTracker;
|
|
12827
12671
|
if (!hasLlmAttemptBudgetRemaining({ actualAttempts, maxTotalAttempts })) {
|
|
12828
|
-
|
|
12672
|
+
logger15.error("\u5DF2\u8FBE\u5230 LLM \u603B\u8C03\u7528\u6B21\u6570\u4E0A\u9650\uFF0C\u505C\u6B62\u91CD\u8BD5/\u5207\u6A21\u578B", {
|
|
12829
12673
|
actualAttempts,
|
|
12830
12674
|
maxTotalAttempts
|
|
12831
12675
|
});
|
|
@@ -12855,37 +12699,15 @@ async function callWithRetryFallback(params) {
|
|
|
12855
12699
|
attempt -= 1;
|
|
12856
12700
|
continue;
|
|
12857
12701
|
}
|
|
12858
|
-
const quotaFallbackModelId = tryCloudQuotaFallback({
|
|
12859
|
-
deps,
|
|
12860
|
-
activeModelId,
|
|
12861
|
-
options,
|
|
12862
|
-
excludedModelIds,
|
|
12863
|
-
requirement,
|
|
12864
|
-
error: lastError,
|
|
12865
|
-
fallbackObserver,
|
|
12866
|
-
evaluateFallbackPromptCapacity: invocationContext?.evaluateFallbackPromptCapacity
|
|
12867
|
-
});
|
|
12868
|
-
if (quotaFallbackModelId) {
|
|
12869
|
-
fallbackObserver?.onModelFallbackApplied?.({
|
|
12870
|
-
fromModelId: activeModelId,
|
|
12871
|
-
toModelId: quotaFallbackModelId,
|
|
12872
|
-
reason: lastError.message,
|
|
12873
|
-
policy: "cloud-quota"
|
|
12874
|
-
});
|
|
12875
|
-
activeModelId = quotaFallbackModelId;
|
|
12876
|
-
excludedModelIds.add(quotaFallbackModelId);
|
|
12877
|
-
attempt -= 1;
|
|
12878
|
-
continue;
|
|
12879
|
-
}
|
|
12880
12702
|
}
|
|
12881
12703
|
if (classification.category === "non_retryable" /* NON_RETRYABLE */) {
|
|
12882
|
-
|
|
12704
|
+
logger15.error("\u9519\u8BEF\u4E0D\u53EF\u91CD\u8BD5\uFF0C\u76F4\u63A5\u5931\u8D25", { reason: classification.reason });
|
|
12883
12705
|
retryEpisode.finish("failed", failedRetryState);
|
|
12884
12706
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
12885
12707
|
throw lastError;
|
|
12886
12708
|
}
|
|
12887
12709
|
if (attempt >= configuredMaxRetries || categoryRetries[category] >= currentMaxRetries) {
|
|
12888
|
-
|
|
12710
|
+
logger15.error("\u5DF2\u8FBE\u5230\u6700\u5927\u91CD\u8BD5\u6B21\u6570\uFF0C\u653E\u5F03\u91CD\u8BD5", { maxRetries: currentMaxRetries });
|
|
12889
12711
|
retryEpisode.finish("exhausted", failedRetryState);
|
|
12890
12712
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
12891
12713
|
throw lastError;
|
|
@@ -12897,9 +12719,9 @@ async function callWithRetryFallback(params) {
|
|
|
12897
12719
|
6e4
|
|
12898
12720
|
);
|
|
12899
12721
|
if (classification.category === "rate_limit" /* RATE_LIMIT */) {
|
|
12900
|
-
|
|
12722
|
+
logger15.warn("\u901F\u7387\u9650\u5236\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
12901
12723
|
} else if (classification.category === "retryable" /* RETRYABLE */) {
|
|
12902
|
-
|
|
12724
|
+
logger15.warn("\u53EF\u91CD\u8BD5\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
12903
12725
|
}
|
|
12904
12726
|
throwIfAborted(signal, "\u5EF6\u8FDF\u7B49\u5F85\u524D\u68C0\u6D4B\u5230\u53D6\u6D88\u4FE1\u53F7\uFF0C\u505C\u6B62\u91CD\u8BD5");
|
|
12905
12727
|
categoryRetries[category] += 1;
|
|
@@ -12936,16 +12758,11 @@ function waitForRetry(delayMs, signal) {
|
|
|
12936
12758
|
}
|
|
12937
12759
|
function isClientRetryEnabledForModel(modelCatalog, modelId, options) {
|
|
12938
12760
|
if (options.retry_policy === "none") return false;
|
|
12939
|
-
|
|
12940
|
-
if (cfg?.billing_mode === "cloud") return false;
|
|
12941
|
-
if (options.retry_policy === "client") return true;
|
|
12942
|
-
if (!cfg) return true;
|
|
12943
|
-
if (cfg.enable_client_retry === false) return false;
|
|
12944
|
-
return true;
|
|
12761
|
+
return modelCatalog.getModelById(modelId)?.enable_client_retry !== false;
|
|
12945
12762
|
}
|
|
12946
12763
|
function throwIfAborted(signal, message) {
|
|
12947
12764
|
if (!signal?.aborted) return;
|
|
12948
|
-
|
|
12765
|
+
logger15.info(message);
|
|
12949
12766
|
const reason = signal.reason;
|
|
12950
12767
|
if (reason instanceof Error && reason.name === "AbortError") throw reason;
|
|
12951
12768
|
const reasonText = typeof reason === "string" && reason.trim().length > 0 ? reason : "stream_interrupted";
|
|
@@ -13263,7 +13080,7 @@ async function recoverChildRunEventsFromCheckpoint(params) {
|
|
|
13263
13080
|
}
|
|
13264
13081
|
|
|
13265
13082
|
// src/runtime-kernel/child-runs/childRunInvoker.ts
|
|
13266
|
-
var
|
|
13083
|
+
var logger16 = new Logger("ChildRunInvoker");
|
|
13267
13084
|
var ChildRunInvoker = class {
|
|
13268
13085
|
modelResolver;
|
|
13269
13086
|
createLlmNode;
|
|
@@ -13305,7 +13122,7 @@ var ChildRunInvoker = class {
|
|
|
13305
13122
|
const resolvedParentRunId = parentRunId ?? parentToolContext.runId;
|
|
13306
13123
|
const depthDecision = decideChildRunDepth({ parentToolContext });
|
|
13307
13124
|
if (!depthDecision.allowed) {
|
|
13308
|
-
|
|
13125
|
+
logger16.warn("child-run \u6DF1\u5EA6\u8D85\u8FC7\u4E0A\u9650\uFF0C\u62D2\u7EDD\u7EE7\u7EED\u9012\u5F52\u6267\u884C", {
|
|
13309
13126
|
runId: childRunId,
|
|
13310
13127
|
parentRunId: resolvedParentRunId,
|
|
13311
13128
|
parentDepth: depthDecision.parentDepth,
|
|
@@ -13322,7 +13139,7 @@ var ChildRunInvoker = class {
|
|
|
13322
13139
|
};
|
|
13323
13140
|
}
|
|
13324
13141
|
if (abortSignal?.aborted || parentToolContext.abortSignal?.aborted) {
|
|
13325
|
-
|
|
13142
|
+
logger16.info("child-run \u5728\u4EFB\u52A1\u63A5\u7EB3\u524D\u5DF2\u53D6\u6D88", {
|
|
13326
13143
|
runId: childRunId,
|
|
13327
13144
|
parentRunId: resolvedParentRunId
|
|
13328
13145
|
});
|
|
@@ -13346,7 +13163,7 @@ var ChildRunInvoker = class {
|
|
|
13346
13163
|
}
|
|
13347
13164
|
const turnId = config.initialInput?.turnId ?? generateTurnId();
|
|
13348
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");
|
|
13349
|
-
|
|
13166
|
+
logger16.info(`\u542F\u52A8 child-run: ${agentConfig.id}`, {
|
|
13350
13167
|
conversationId: runtimeConversationId,
|
|
13351
13168
|
checkpointKey: internalCheckpointKey,
|
|
13352
13169
|
maxSteps,
|
|
@@ -13464,7 +13281,7 @@ var ChildRunInvoker = class {
|
|
|
13464
13281
|
);
|
|
13465
13282
|
finalAnswer = extractFinalAnswer(allEvents);
|
|
13466
13283
|
lastProgress = finalAnswer ? void 0 : extractLastProgress(allEvents);
|
|
13467
|
-
|
|
13284
|
+
logger16.info("child-run \u6267\u884C\u5B8C\u6210", {
|
|
13468
13285
|
stepCount,
|
|
13469
13286
|
eventCount: allEvents.length,
|
|
13470
13287
|
hasFinalAnswer: !!finalAnswer,
|
|
@@ -13494,13 +13311,13 @@ var ChildRunInvoker = class {
|
|
|
13494
13311
|
cancelled = abortSignal?.aborted === true || isAbortError2(err);
|
|
13495
13312
|
error = err instanceof Error ? err.message : String(err);
|
|
13496
13313
|
if (cancelled) {
|
|
13497
|
-
|
|
13314
|
+
logger16.info("child-run \u6267\u884C\u53D6\u6D88", {
|
|
13498
13315
|
runId: childRunId,
|
|
13499
13316
|
parentRunId: resolvedParentRunId,
|
|
13500
13317
|
message: error
|
|
13501
13318
|
});
|
|
13502
13319
|
} else {
|
|
13503
|
-
|
|
13320
|
+
logger16.error(
|
|
13504
13321
|
"child-run \u6267\u884C\u5931\u8D25:",
|
|
13505
13322
|
err instanceof Error ? {
|
|
13506
13323
|
name: err.name,
|
|
@@ -13596,7 +13413,7 @@ var ChildRunInvoker = class {
|
|
|
13596
13413
|
function isAbortError2(error) {
|
|
13597
13414
|
return error instanceof Error && error.name === "AbortError";
|
|
13598
13415
|
}
|
|
13599
|
-
function
|
|
13416
|
+
function readNonEmptyString5(value) {
|
|
13600
13417
|
if (typeof value !== "string") {
|
|
13601
13418
|
return void 0;
|
|
13602
13419
|
}
|
|
@@ -13604,7 +13421,7 @@ function readNonEmptyString6(value) {
|
|
|
13604
13421
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
13605
13422
|
}
|
|
13606
13423
|
function resolveChildRunConversationId(params) {
|
|
13607
|
-
const conversationId =
|
|
13424
|
+
const conversationId = readNonEmptyString5(params.explicitConversationId) ?? readNonEmptyString5(params.parentToolContext.conversationId);
|
|
13608
13425
|
if (!conversationId) {
|
|
13609
13426
|
throw new Error(
|
|
13610
13427
|
"ChildRunInvoker requires conversationId from admission or parent ToolContext."
|
|
@@ -13613,7 +13430,7 @@ function resolveChildRunConversationId(params) {
|
|
|
13613
13430
|
return conversationId;
|
|
13614
13431
|
}
|
|
13615
13432
|
function resolveChildRunModelId(params) {
|
|
13616
|
-
const explicitModelId =
|
|
13433
|
+
const explicitModelId = readNonEmptyString5(params.explicitModelId);
|
|
13617
13434
|
if (explicitModelId) {
|
|
13618
13435
|
return explicitModelId;
|
|
13619
13436
|
}
|
|
@@ -14558,7 +14375,7 @@ function runMetaFromRecord(record) {
|
|
|
14558
14375
|
}
|
|
14559
14376
|
|
|
14560
14377
|
// src/runtime-kernel/run-supervisor/functions/awaitingUserWatcher.ts
|
|
14561
|
-
var
|
|
14378
|
+
var logger17 = new Logger("RunSupervisorAwaitingUserWatcher");
|
|
14562
14379
|
function isRecord16(value) {
|
|
14563
14380
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14564
14381
|
}
|
|
@@ -14603,7 +14420,7 @@ function createAwaitingUserWatcher(options) {
|
|
|
14603
14420
|
resumeToken: event.resume_token
|
|
14604
14421
|
}
|
|
14605
14422
|
}).catch((error) => {
|
|
14606
|
-
|
|
14423
|
+
logger17.warn("failed to mark awaiting_user from requires_user_interaction", { error });
|
|
14607
14424
|
});
|
|
14608
14425
|
};
|
|
14609
14426
|
const dispose = () => {
|