@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.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,7 +6128,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
6195
6128
|
"turnId"
|
|
6196
6129
|
],
|
|
6197
6130
|
writes: [
|
|
6198
|
-
"cloudQuotaFallbackAppliedModelId",
|
|
6199
6131
|
"modelFallbackAudit",
|
|
6200
6132
|
"llmCallStartedAt",
|
|
6201
6133
|
"llmResp",
|
|
@@ -6203,7 +6135,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
6203
6135
|
"contextUsage"
|
|
6204
6136
|
],
|
|
6205
6137
|
async run(ctx) {
|
|
6206
|
-
let cloudQuotaFallbackAppliedModelId;
|
|
6207
6138
|
let modelFallbackAudit;
|
|
6208
6139
|
let contextUsage;
|
|
6209
6140
|
const modelFallbackRejections = [];
|
|
@@ -6222,9 +6153,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
6222
6153
|
streamEventHandler,
|
|
6223
6154
|
ctx.signal,
|
|
6224
6155
|
{
|
|
6225
|
-
onCloudQuotaFallbackApplied(fallbackModelId) {
|
|
6226
|
-
cloudQuotaFallbackAppliedModelId = readNonEmptyString3(fallbackModelId);
|
|
6227
|
-
},
|
|
6228
6156
|
onLlmAttemptSucceeded(_activeModelId, attemptContextUsage) {
|
|
6229
6157
|
contextUsage = attemptContextUsage;
|
|
6230
6158
|
},
|
|
@@ -6321,7 +6249,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
6321
6249
|
});
|
|
6322
6250
|
}
|
|
6323
6251
|
return {
|
|
6324
|
-
cloudQuotaFallbackAppliedModelId,
|
|
6325
6252
|
modelFallbackAudit,
|
|
6326
6253
|
llmCallStartedAt,
|
|
6327
6254
|
llmResp,
|
|
@@ -7242,18 +7169,16 @@ function createPrepareCallStage(dependencies) {
|
|
|
7242
7169
|
"toolDefinitionTokens"
|
|
7243
7170
|
],
|
|
7244
7171
|
async run(ctx) {
|
|
7245
|
-
const
|
|
7246
|
-
const requestedModelId = lockedRunModelId ?? ctx.request.model_id;
|
|
7172
|
+
const requestedModelId = ctx.request.model_id;
|
|
7247
7173
|
const modelId = dependencies.modelResolver.resolveModelId(requestedModelId);
|
|
7248
7174
|
await emitAuditEnvelope(ctx.audit, {
|
|
7249
7175
|
action: "model.select",
|
|
7250
7176
|
actor: { kind: "system" },
|
|
7251
7177
|
decision: {
|
|
7252
7178
|
outcome: "recorded",
|
|
7253
|
-
reason:
|
|
7179
|
+
reason: requestedModelId ? "request model id" : "default model resolver",
|
|
7254
7180
|
metadata: {
|
|
7255
7181
|
requestedModelId,
|
|
7256
|
-
lockedRunModelId,
|
|
7257
7182
|
selectedModelId: modelId
|
|
7258
7183
|
}
|
|
7259
7184
|
},
|
|
@@ -7300,10 +7225,6 @@ function createPrepareCallStage(dependencies) {
|
|
|
7300
7225
|
if (ctx.executorLocal?.lockRequestedModelId === true) {
|
|
7301
7226
|
llmOptions.allow_model_fallback = false;
|
|
7302
7227
|
}
|
|
7303
|
-
const isRunContinuation = ctx.executorLocal?.llmInvocationKind === "continuation";
|
|
7304
|
-
if (dependencies.cloudQuotaFallbackModelId && modelConfig?.billing_mode === "cloud" && modelId !== dependencies.cloudQuotaFallbackModelId && isRunContinuation && ctx.executorLocal?.lockRequestedModelId !== true) {
|
|
7305
|
-
llmOptions.cloud_quota_fallback_model_id = dependencies.cloudQuotaFallbackModelId;
|
|
7306
|
-
}
|
|
7307
7228
|
const effectiveEffort = resolveEffectiveEffort(
|
|
7308
7229
|
ctx.request.reasoning_effort,
|
|
7309
7230
|
modelConfig?.reasoning
|
|
@@ -7420,12 +7341,11 @@ function applyCalibration(rawLocalTotal, imageInputTokens, coefficient) {
|
|
|
7420
7341
|
}
|
|
7421
7342
|
|
|
7422
7343
|
// src/runtime-kernel/graph-engine/executor.ts
|
|
7423
|
-
var
|
|
7344
|
+
var logger5 = new Logger("GraphAgentExecutor");
|
|
7424
7345
|
var GraphAgentExecutor = class {
|
|
7425
7346
|
llmCaller;
|
|
7426
7347
|
toolRuntime;
|
|
7427
7348
|
contextBuilder;
|
|
7428
|
-
cloudQuotaFallbackModelId;
|
|
7429
7349
|
modelResolver;
|
|
7430
7350
|
modelCatalog;
|
|
7431
7351
|
telemetryPort;
|
|
@@ -7437,7 +7357,6 @@ var GraphAgentExecutor = class {
|
|
|
7437
7357
|
this.llmCaller = dependencies.llmCaller;
|
|
7438
7358
|
this.toolRuntime = dependencies.toolRuntime;
|
|
7439
7359
|
this.contextBuilder = dependencies.contextBuilder;
|
|
7440
|
-
this.cloudQuotaFallbackModelId = readNonEmptyString3(dependencies.cloudQuotaFallbackModelId);
|
|
7441
7360
|
this.modelCatalog = dependencies.modelCatalog ?? createEmptyModelCatalog();
|
|
7442
7361
|
this.modelResolver = dependencies.modelResolver ?? new ModelResolver({
|
|
7443
7362
|
modelCatalog: this.modelCatalog
|
|
@@ -7454,8 +7373,7 @@ var GraphAgentExecutor = class {
|
|
|
7454
7373
|
createPrepareCallStage({
|
|
7455
7374
|
modelResolver: this.modelResolver,
|
|
7456
7375
|
modelCatalog: this.modelCatalog,
|
|
7457
|
-
toolCatalog: this.toolRuntime
|
|
7458
|
-
cloudQuotaFallbackModelId: this.cloudQuotaFallbackModelId
|
|
7376
|
+
toolCatalog: this.toolRuntime
|
|
7459
7377
|
}),
|
|
7460
7378
|
createBuildContextStage({
|
|
7461
7379
|
contextBuilder: this.contextBuilder
|
|
@@ -7477,7 +7395,7 @@ var GraphAgentExecutor = class {
|
|
|
7477
7395
|
}),
|
|
7478
7396
|
createBuildDecisionStage()
|
|
7479
7397
|
];
|
|
7480
|
-
this.middlewares = [llmTelemetryMiddleware
|
|
7398
|
+
this.middlewares = [llmTelemetryMiddleware];
|
|
7481
7399
|
}
|
|
7482
7400
|
async tick(input, eventHandler) {
|
|
7483
7401
|
const ctx = {
|
|
@@ -7502,7 +7420,7 @@ var GraphAgentExecutor = class {
|
|
|
7502
7420
|
audit: this.auditPort,
|
|
7503
7421
|
tokenizer: this.tokenizer
|
|
7504
7422
|
};
|
|
7505
|
-
|
|
7423
|
+
logger5.info("[GraphAgentExecutor] tick \u8C03\u7528", {
|
|
7506
7424
|
stream: input.stream === true,
|
|
7507
7425
|
hasEventHandler: Boolean(eventHandler),
|
|
7508
7426
|
hasSummarizationCallbacks: Boolean(input.summarizationCallbacks)
|
|
@@ -8525,7 +8443,7 @@ var LlmNodeEventBridge = class {
|
|
|
8525
8443
|
};
|
|
8526
8444
|
|
|
8527
8445
|
// src/runtime-kernel/graph-engine/nodes/llmNode.ts
|
|
8528
|
-
var
|
|
8446
|
+
var logger6 = new Logger("LlmNode");
|
|
8529
8447
|
var LlmNode = class {
|
|
8530
8448
|
id = "llm";
|
|
8531
8449
|
reasoner;
|
|
@@ -8534,7 +8452,7 @@ var LlmNode = class {
|
|
|
8534
8452
|
}
|
|
8535
8453
|
async run(state) {
|
|
8536
8454
|
const local = state.local ?? {};
|
|
8537
|
-
|
|
8455
|
+
logger6.info("[LlmNode] \u5F00\u59CB\u6267\u884C LLM \u8282\u70B9", {
|
|
8538
8456
|
localKeys: Object.keys(local)
|
|
8539
8457
|
});
|
|
8540
8458
|
const graphLocal = readGraphAgentLocal(state.local);
|
|
@@ -8549,12 +8467,12 @@ var LlmNode = class {
|
|
|
8549
8467
|
signal,
|
|
8550
8468
|
history
|
|
8551
8469
|
} = graphLocal;
|
|
8552
|
-
|
|
8470
|
+
logger6.info("[LlmNode] \u5DF2\u52A0\u8F7D\u5386\u53F2\u4E8B\u4EF6", {
|
|
8553
8471
|
historyCount: history.length,
|
|
8554
8472
|
hasSummarizationCallbacks: Boolean(summarizationCallbacks)
|
|
8555
8473
|
});
|
|
8556
8474
|
if (!request) {
|
|
8557
|
-
|
|
8475
|
+
logger6.warn("Request object is missing, yielding.");
|
|
8558
8476
|
return { kind: "yield", events: [] };
|
|
8559
8477
|
}
|
|
8560
8478
|
const turnId = requireRuntimeIdentity(graphLocal.turnId, "turnId");
|
|
@@ -8647,12 +8565,12 @@ var LlmNode = class {
|
|
|
8647
8565
|
...nodeState.streamRuntimeEvents,
|
|
8648
8566
|
...contextUsageEvent ? [contextUsageEvent] : []
|
|
8649
8567
|
];
|
|
8650
|
-
|
|
8568
|
+
logger6.info("[LlmNode] \u5386\u53F2\u4E8B\u4EF6\u5DF2\u66F4\u65B0", {
|
|
8651
8569
|
previousCount: history.length,
|
|
8652
8570
|
nextCount: patch.history.length,
|
|
8653
8571
|
streamedEventCount: nodeState.streamRuntimeEvents.length
|
|
8654
8572
|
});
|
|
8655
|
-
|
|
8573
|
+
logger6.info("[LlmNode] \u6267\u884C\u5668\u51B3\u7B56\u5B8C\u6210", {
|
|
8656
8574
|
decisionKind: decision.kind,
|
|
8657
8575
|
emittedEventCount: combinedEvents.length
|
|
8658
8576
|
});
|
|
@@ -8674,7 +8592,7 @@ var LlmNode = class {
|
|
|
8674
8592
|
}
|
|
8675
8593
|
case "error": {
|
|
8676
8594
|
const { name, message, stack } = decision.error;
|
|
8677
|
-
|
|
8595
|
+
logger6.error("[LlmNode] Executor returned an error", { name, message, stack });
|
|
8678
8596
|
return { kind: "yield", events: combinedEvents };
|
|
8679
8597
|
}
|
|
8680
8598
|
default: {
|
|
@@ -8780,7 +8698,7 @@ async function resolveToolModelInput(input) {
|
|
|
8780
8698
|
}
|
|
8781
8699
|
|
|
8782
8700
|
// src/runtime-kernel/graph-engine/nodes/toolNode.finalAnswerProjector.ts
|
|
8783
|
-
function
|
|
8701
|
+
function readNonEmptyString4(value) {
|
|
8784
8702
|
if (typeof value !== "string") {
|
|
8785
8703
|
return void 0;
|
|
8786
8704
|
}
|
|
@@ -8788,7 +8706,7 @@ function readNonEmptyString5(value) {
|
|
|
8788
8706
|
return normalized.length > 0 ? normalized : void 0;
|
|
8789
8707
|
}
|
|
8790
8708
|
function resolveFinalAnswerFromToolControl(finalAnswer) {
|
|
8791
|
-
return
|
|
8709
|
+
return readNonEmptyString4(finalAnswer);
|
|
8792
8710
|
}
|
|
8793
8711
|
|
|
8794
8712
|
// src/runtime-kernel/graph-engine/nodes/toolNode.helpers.ts
|
|
@@ -9044,7 +8962,7 @@ function buildErrorLocalState(params) {
|
|
|
9044
8962
|
}
|
|
9045
8963
|
|
|
9046
8964
|
// src/runtime-kernel/tools/argNormalizer.ts
|
|
9047
|
-
var
|
|
8965
|
+
var logger7 = new Logger("ToolArgNormalizer");
|
|
9048
8966
|
function isRecord10(v) {
|
|
9049
8967
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
9050
8968
|
}
|
|
@@ -9064,7 +8982,7 @@ function joinPath(basePath, segment) {
|
|
|
9064
8982
|
function logJsonEncodedNormalization(expectedType, options) {
|
|
9065
8983
|
const toolPrefix = options.toolName ? `${options.toolName}.` : "";
|
|
9066
8984
|
const path = options.path ?? "<root>";
|
|
9067
|
-
|
|
8985
|
+
logger7.warn("normalized JSON-encoded tool argument", {
|
|
9068
8986
|
expectedType,
|
|
9069
8987
|
path: `${toolPrefix}${path}`
|
|
9070
8988
|
});
|
|
@@ -9234,7 +9152,6 @@ var TOOL_CONTEXT_RUNTIME_RESERVED_KEYS = [
|
|
|
9234
9152
|
"conversationView",
|
|
9235
9153
|
"userQuery",
|
|
9236
9154
|
"modelId",
|
|
9237
|
-
"activeModelId",
|
|
9238
9155
|
"conversationId",
|
|
9239
9156
|
"turnId",
|
|
9240
9157
|
"runId",
|
|
@@ -9421,7 +9338,7 @@ function stripRuntimeReservedToolContextPatch(patch) {
|
|
|
9421
9338
|
}
|
|
9422
9339
|
|
|
9423
9340
|
// src/runtime-kernel/graph-engine/nodes/toolNode.eventBridge.ts
|
|
9424
|
-
var
|
|
9341
|
+
var logger8 = new Logger("ToolNode");
|
|
9425
9342
|
var ToolNodeEventBridge = class {
|
|
9426
9343
|
constructor(deps) {
|
|
9427
9344
|
this.deps = deps;
|
|
@@ -9443,7 +9360,7 @@ var ToolNodeEventBridge = class {
|
|
|
9443
9360
|
status,
|
|
9444
9361
|
payload: { ...payload }
|
|
9445
9362
|
};
|
|
9446
|
-
|
|
9363
|
+
logger8.info("[ToolNode] \u53D1\u51FA tool_process \u4E8B\u4EF6", {
|
|
9447
9364
|
phase,
|
|
9448
9365
|
status,
|
|
9449
9366
|
toolName: this.deps.toolName,
|
|
@@ -9483,7 +9400,7 @@ var ToolNodeEventBridge = class {
|
|
|
9483
9400
|
const answerId = generateAnswerSegmentId();
|
|
9484
9401
|
const id = answerId;
|
|
9485
9402
|
const timestamp = Date.now();
|
|
9486
|
-
|
|
9403
|
+
logger8.info("[ToolNode] \u5DE5\u5177\u8F93\u51FA\u6620\u5C04\u4E3A final_answer", {
|
|
9487
9404
|
sourceToolName: params.sourceToolName,
|
|
9488
9405
|
toolCallId: this.deps.toolCallId,
|
|
9489
9406
|
conversationId: this.deps.conversationId,
|
|
@@ -9541,7 +9458,7 @@ var ToolNodeEventBridge = class {
|
|
|
9541
9458
|
};
|
|
9542
9459
|
|
|
9543
9460
|
// src/runtime-kernel/graph-engine/nodes/toolNode.executionSetup.ts
|
|
9544
|
-
var
|
|
9461
|
+
var logger9 = new Logger("ToolNode");
|
|
9545
9462
|
function parseToolArgs(call) {
|
|
9546
9463
|
const rawArguments = typeof call.function?.arguments === "string" ? call.function.arguments : "";
|
|
9547
9464
|
if (!rawArguments.trim()) {
|
|
@@ -9561,19 +9478,13 @@ function parseToolArgs(call) {
|
|
|
9561
9478
|
return { ok: true, value: parsed };
|
|
9562
9479
|
} catch (error) {
|
|
9563
9480
|
const reason = error instanceof Error ? error.message : "Unknown JSON parse error";
|
|
9564
|
-
|
|
9481
|
+
logger9.warn("failed to parse tool arguments", { error });
|
|
9565
9482
|
return {
|
|
9566
9483
|
ok: false,
|
|
9567
9484
|
error: `Tool arguments are not valid JSON: ${reason}`
|
|
9568
9485
|
};
|
|
9569
9486
|
}
|
|
9570
9487
|
}
|
|
9571
|
-
function readRunLockedModelId(local) {
|
|
9572
|
-
const executorLocal = local.executorLocal;
|
|
9573
|
-
if (!isRecord9(executorLocal)) return void 0;
|
|
9574
|
-
const lockedModelId = executorLocal.runLockedModelId;
|
|
9575
|
-
return typeof lockedModelId === "string" && lockedModelId.trim() ? lockedModelId : void 0;
|
|
9576
|
-
}
|
|
9577
9488
|
function prepareToolNodeContext(state) {
|
|
9578
9489
|
const local = state.local || {};
|
|
9579
9490
|
const toolContext = isRecord9(local.toolContext) ? local.toolContext : {};
|
|
@@ -9591,7 +9502,6 @@ function prepareToolNodeContext(state) {
|
|
|
9591
9502
|
}
|
|
9592
9503
|
});
|
|
9593
9504
|
attachWorkingHistoryView({ state, toolContext });
|
|
9594
|
-
toolContext.activeModelId = readRunLockedModelId(local) ?? toolContext.modelId;
|
|
9595
9505
|
return {
|
|
9596
9506
|
state,
|
|
9597
9507
|
local,
|
|
@@ -9969,7 +9879,7 @@ async function claimPendingUserInputs(state, result) {
|
|
|
9969
9879
|
}
|
|
9970
9880
|
|
|
9971
9881
|
// src/runtime-kernel/graph-engine/nodes/toolNode.ts
|
|
9972
|
-
var
|
|
9882
|
+
var logger10 = new Logger("ToolNode");
|
|
9973
9883
|
function isAbortSignal(value) {
|
|
9974
9884
|
return value !== null && typeof value === "object" && "aborted" in value;
|
|
9975
9885
|
}
|
|
@@ -10182,7 +10092,7 @@ var ToolNode = class {
|
|
|
10182
10092
|
throw abortError;
|
|
10183
10093
|
}
|
|
10184
10094
|
const prepared = prepareToolNodeContext(state);
|
|
10185
|
-
|
|
10095
|
+
logger10.info("[ToolNode] \u5F00\u59CB\u6267\u884C\u5DE5\u5177\u8282\u70B9", {
|
|
10186
10096
|
conversationId: prepared.conversationId,
|
|
10187
10097
|
turnId: prepared.turnId,
|
|
10188
10098
|
pendingCallCount: calls.length
|
|
@@ -10197,7 +10107,7 @@ var ToolNode = class {
|
|
|
10197
10107
|
toolCatalog: this.toolRuntime
|
|
10198
10108
|
});
|
|
10199
10109
|
if (!execution) {
|
|
10200
|
-
|
|
10110
|
+
logger10.warn("no tool name found in call");
|
|
10201
10111
|
return { kind: "yield", events: [] };
|
|
10202
10112
|
}
|
|
10203
10113
|
if (typeof execution.protocolError === "string") {
|
|
@@ -10237,7 +10147,7 @@ var ToolNode = class {
|
|
|
10237
10147
|
call,
|
|
10238
10148
|
context: prepared.toolContext,
|
|
10239
10149
|
abortGraceMs: this.abortGraceMs,
|
|
10240
|
-
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", {
|
|
10241
10151
|
toolName: execution.toolName,
|
|
10242
10152
|
toolCallId: execution.toolCallId,
|
|
10243
10153
|
conversationId: prepared.conversationId,
|
|
@@ -10407,7 +10317,7 @@ var ToolNode = class {
|
|
|
10407
10317
|
runtimeEvents: context.bridge.getRuntimeEvents()
|
|
10408
10318
|
});
|
|
10409
10319
|
if (control?.terminateRun) {
|
|
10410
|
-
|
|
10320
|
+
logger10.info("[ToolNode] \u6536\u5230 control.terminateRun\uFF0C\u6267\u884C\u5B8C\u5DE5\u5177\u540E\u76F4\u63A5 yield \u7ED3\u675F\u672C\u8F6E run", {
|
|
10411
10321
|
toolName: context.toolName,
|
|
10412
10322
|
toolCallId: context.toolCallId,
|
|
10413
10323
|
conversationId: context.conversationId,
|
|
@@ -10416,7 +10326,7 @@ var ToolNode = class {
|
|
|
10416
10326
|
return { kind: "yield", events: context.bridge.getRuntimeEvents() };
|
|
10417
10327
|
}
|
|
10418
10328
|
if (remainingCalls.length === 0 && context.local.toolBatchCompletionMode === "yield_after_batch") {
|
|
10419
|
-
|
|
10329
|
+
logger10.info("[ToolNode] \u5DE5\u5177\u6279\u6B21\u5DF2\u7ED3\u7B97\uFF0C\u6309 Host \u7B56\u7565\u76F4\u63A5 yield", {
|
|
10420
10330
|
toolName: context.toolName,
|
|
10421
10331
|
toolCallId: context.toolCallId,
|
|
10422
10332
|
conversationId: context.conversationId,
|
|
@@ -10863,8 +10773,9 @@ var executor = zod.z.object({
|
|
|
10863
10773
|
lastStepsHintThreshold: counter.optional(),
|
|
10864
10774
|
systemReminderPolicy: AgentSpecSystemReminderPolicy.optional(),
|
|
10865
10775
|
toolObservationPolicy: AgentSpecToolObservationGovernancePolicy.optional(),
|
|
10776
|
+
// 已删除字段:0.45 及更早的 checkpoint 可能带 lastSuccessfulLlmModelId,0.46 及更早的可能带云端额度兜底留下的
|
|
10777
|
+
// runLockedModelId;照常接受,读入时丢弃(兜底已移除,恢复后按请求的模型继续)。
|
|
10866
10778
|
runLockedModelId: zod.z.string().optional(),
|
|
10867
|
-
// 0.45 及更早的 checkpoint 可能带这个已删除字段;照常接受,读入时丢弃。
|
|
10868
10779
|
lastSuccessfulLlmModelId: zod.z.string().optional(),
|
|
10869
10780
|
llmInvocationKind: zod.z.enum(["user_initiated", "continuation"]).optional(),
|
|
10870
10781
|
llmInvocationCount: counter.optional(),
|
|
@@ -10874,7 +10785,7 @@ var executor = zod.z.object({
|
|
|
10874
10785
|
committedCount: counter,
|
|
10875
10786
|
lastCommittedFingerprint: zod.z.string().optional()
|
|
10876
10787
|
}).strict().optional()
|
|
10877
|
-
}).strict().transform(({ lastSuccessfulLlmModelId: _retired, ...state }) => state);
|
|
10788
|
+
}).strict().transform(({ lastSuccessfulLlmModelId: _retired, runLockedModelId: _retiredLock, ...state }) => state);
|
|
10878
10789
|
var checkpoint = zod.z.object({
|
|
10879
10790
|
nodeId: zod.z.string().min(1),
|
|
10880
10791
|
schemaVersion: zod.z.literal(ENGINE_STATE_SCHEMA_VERSION).optional(),
|
|
@@ -11188,7 +11099,7 @@ __export(execution_exports, {
|
|
|
11188
11099
|
});
|
|
11189
11100
|
|
|
11190
11101
|
// src/runtime-kernel/execution/event-bus.ts
|
|
11191
|
-
var
|
|
11102
|
+
var logger11 = new Logger("EventBus");
|
|
11192
11103
|
var TypedEventEmitter = class {
|
|
11193
11104
|
listeners = /* @__PURE__ */ new Map();
|
|
11194
11105
|
maxListeners = 10;
|
|
@@ -11196,7 +11107,7 @@ var TypedEventEmitter = class {
|
|
|
11196
11107
|
const listeners = this.getListeners(event);
|
|
11197
11108
|
listeners.add(listener);
|
|
11198
11109
|
if (listeners.size > this.maxListeners) {
|
|
11199
|
-
|
|
11110
|
+
logger11.warn("EventBus listener count exceeds configured max", {
|
|
11200
11111
|
event: String(event),
|
|
11201
11112
|
count: listeners.size,
|
|
11202
11113
|
maxListeners: this.maxListeners
|
|
@@ -11256,7 +11167,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
11256
11167
|
super();
|
|
11257
11168
|
this.executionId = executionId;
|
|
11258
11169
|
this.setMaxListeners(30);
|
|
11259
|
-
|
|
11170
|
+
logger11.info(`EventBus created for execution ${this.executionId}`);
|
|
11260
11171
|
}
|
|
11261
11172
|
/**
|
|
11262
11173
|
* 发布一个事件到总线
|
|
@@ -11265,7 +11176,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
11265
11176
|
publish(envelope) {
|
|
11266
11177
|
if (envelope.trace.execution_id !== this.executionId) {
|
|
11267
11178
|
const error = new Error("EventEnvelope execution_id does not match EventBus instance.");
|
|
11268
|
-
|
|
11179
|
+
logger11.error("Mismatched execution_id", {
|
|
11269
11180
|
busExecutionId: this.executionId,
|
|
11270
11181
|
eventExecutionId: envelope.trace.execution_id,
|
|
11271
11182
|
eventSeq: envelope.seq
|
|
@@ -11277,7 +11188,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
11277
11188
|
const error = new Error(
|
|
11278
11189
|
"EventBus only accepts RuntimeEvent with formal run routing identity."
|
|
11279
11190
|
);
|
|
11280
|
-
|
|
11191
|
+
logger11.error("RuntimeEvent is missing formal run routing identity", {
|
|
11281
11192
|
executionId: this.executionId,
|
|
11282
11193
|
eventId: envelope.payload.id,
|
|
11283
11194
|
eventType: envelope.payload.type
|
|
@@ -11291,14 +11202,14 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
11291
11202
|
* 关闭总线,清理所有监听器
|
|
11292
11203
|
*/
|
|
11293
11204
|
close() {
|
|
11294
|
-
|
|
11205
|
+
logger11.info(`Closing EventBus for execution ${this.executionId}`);
|
|
11295
11206
|
this.emit("close");
|
|
11296
11207
|
this.removeAllListeners();
|
|
11297
11208
|
}
|
|
11298
11209
|
};
|
|
11299
11210
|
|
|
11300
11211
|
// src/runtime-kernel/execution/sequencer.ts
|
|
11301
|
-
var
|
|
11212
|
+
var logger12 = new Logger("EventSequencer");
|
|
11302
11213
|
var EventSequencer = class {
|
|
11303
11214
|
executionId;
|
|
11304
11215
|
traceId;
|
|
@@ -11306,7 +11217,7 @@ var EventSequencer = class {
|
|
|
11306
11217
|
constructor(conversationId, traceId) {
|
|
11307
11218
|
this.executionId = generateExecutionId();
|
|
11308
11219
|
this.traceId = traceId || generateTraceId();
|
|
11309
|
-
|
|
11220
|
+
logger12.info(`EventSequencer created for conversation ${conversationId}`, {
|
|
11310
11221
|
executionId: this.executionId,
|
|
11311
11222
|
traceId: this.traceId
|
|
11312
11223
|
});
|
|
@@ -12164,7 +12075,7 @@ var ThoughtStreamSegmenter = class {
|
|
|
12164
12075
|
};
|
|
12165
12076
|
|
|
12166
12077
|
// src/runtime-kernel/llm/streaming-adapter.ts
|
|
12167
|
-
var
|
|
12078
|
+
var logger13 = new Logger("LlmCaller");
|
|
12168
12079
|
var CanonicalInferenceFailureError = class extends Error {
|
|
12169
12080
|
errorCode;
|
|
12170
12081
|
recoverable;
|
|
@@ -12388,7 +12299,7 @@ async function callLlmStream(params) {
|
|
|
12388
12299
|
} catch (error) {
|
|
12389
12300
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
12390
12301
|
if (normalized.name === "AbortError") {
|
|
12391
|
-
|
|
12302
|
+
logger13.info("Canonical inference \u6536\u5230\u53D6\u6D88\u7EC8\u6001\uFF0C\u4E0D\u53D1\u5E03\u666E\u901A error event", { modelId });
|
|
12392
12303
|
throw normalized;
|
|
12393
12304
|
}
|
|
12394
12305
|
const classification = ErrorClassifier.classify(normalized, {
|
|
@@ -12464,7 +12375,7 @@ var LlmRetryEpisode = class {
|
|
|
12464
12375
|
};
|
|
12465
12376
|
|
|
12466
12377
|
// src/runtime-kernel/llm/retry-fallback-routing.ts
|
|
12467
|
-
var
|
|
12378
|
+
var logger14 = new Logger("LlmCaller");
|
|
12468
12379
|
function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement, fallbackObserver, error, evaluateFallbackPromptCapacity2) {
|
|
12469
12380
|
deps.modelCatalog.getModelById(activeModelId);
|
|
12470
12381
|
const policyDecision = deps.policyEngine.decideOnError(error, {
|
|
@@ -12494,81 +12405,16 @@ function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement
|
|
|
12494
12405
|
reason: "no_eligible_fallback_candidate",
|
|
12495
12406
|
requiredPlacements: requirement.placements
|
|
12496
12407
|
});
|
|
12497
|
-
|
|
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");
|
|
12498
12409
|
return null;
|
|
12499
12410
|
}
|
|
12500
|
-
|
|
12411
|
+
logger14.warn("Policy \u5207\u6362\u6A21\u578B\u7EE7\u7EED", {
|
|
12501
12412
|
reason: policyDecision.reason,
|
|
12502
12413
|
activeModelId,
|
|
12503
12414
|
fallbackModelId
|
|
12504
12415
|
});
|
|
12505
12416
|
return fallbackModelId;
|
|
12506
12417
|
}
|
|
12507
|
-
function tryCloudQuotaFallback({
|
|
12508
|
-
deps,
|
|
12509
|
-
activeModelId,
|
|
12510
|
-
options,
|
|
12511
|
-
excludedModelIds,
|
|
12512
|
-
requirement,
|
|
12513
|
-
error,
|
|
12514
|
-
fallbackObserver,
|
|
12515
|
-
evaluateFallbackPromptCapacity: evaluateFallbackPromptCapacity2
|
|
12516
|
-
}) {
|
|
12517
|
-
const fallbackModelId = options.cloud_quota_fallback_model_id;
|
|
12518
|
-
if (!fallbackModelId || !ErrorClassifier.isCloudQuotaError(error) || excludedModelIds.has(fallbackModelId)) {
|
|
12519
|
-
return null;
|
|
12520
|
-
}
|
|
12521
|
-
const fallbackConfig = deps.modelCatalog.getModelById(fallbackModelId);
|
|
12522
|
-
if (!fallbackConfig?.api_key) {
|
|
12523
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
12524
|
-
fromModelId: activeModelId,
|
|
12525
|
-
candidateModelId: fallbackModelId,
|
|
12526
|
-
policy: "cloud-quota",
|
|
12527
|
-
reason: "fallback_model_unavailable",
|
|
12528
|
-
requiredPlacements: requirement.placements
|
|
12529
|
-
});
|
|
12530
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\u76EE\u6807\u4E0D\u53EF\u7528\uFF08\u672A\u6CE8\u518C\u6216\u7F3A\u5C11 API Key\uFF09", { fallbackModelId });
|
|
12531
|
-
return null;
|
|
12532
|
-
}
|
|
12533
|
-
const compatibility = evaluateModelInputCompatibility(fallbackConfig, requirement);
|
|
12534
|
-
if (!compatibility.compatible) {
|
|
12535
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
12536
|
-
fromModelId: activeModelId,
|
|
12537
|
-
candidateModelId: fallbackModelId,
|
|
12538
|
-
policy: "cloud-quota",
|
|
12539
|
-
reason: compatibility.reason,
|
|
12540
|
-
requiredPlacements: requirement.placements
|
|
12541
|
-
});
|
|
12542
|
-
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", {
|
|
12543
|
-
fallbackModelId,
|
|
12544
|
-
requiredPlacements: requirement.placements,
|
|
12545
|
-
reason: compatibility.reason
|
|
12546
|
-
});
|
|
12547
|
-
return null;
|
|
12548
|
-
}
|
|
12549
|
-
const capacityAdmission = evaluateFallbackPromptCapacity2?.(fallbackModelId);
|
|
12550
|
-
if (capacityAdmission && !capacityAdmission.admitted) {
|
|
12551
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
12552
|
-
fromModelId: activeModelId,
|
|
12553
|
-
candidateModelId: fallbackModelId,
|
|
12554
|
-
policy: "cloud-quota",
|
|
12555
|
-
reason: capacityAdmission.reason,
|
|
12556
|
-
requiredPlacements: requirement.placements
|
|
12557
|
-
});
|
|
12558
|
-
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", {
|
|
12559
|
-
fallbackModelId,
|
|
12560
|
-
reason: capacityAdmission.reason
|
|
12561
|
-
});
|
|
12562
|
-
return null;
|
|
12563
|
-
}
|
|
12564
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\uFF08run \u5185\u7EED\u8DD1\uFF09", {
|
|
12565
|
-
activeModelId,
|
|
12566
|
-
fallbackModelId,
|
|
12567
|
-
reason: error.message
|
|
12568
|
-
});
|
|
12569
|
-
fallbackObserver?.onCloudQuotaFallbackApplied?.(fallbackModelId);
|
|
12570
|
-
return fallbackModelId;
|
|
12571
|
-
}
|
|
12572
12418
|
|
|
12573
12419
|
// src/runtime-kernel/llm/usage-telemetry.ts
|
|
12574
12420
|
async function callPlainCompletion(inferencePort, modelId, messages, options = {}, signal, traceId) {
|
|
@@ -12691,7 +12537,7 @@ var LlmImageInputError = class extends Error {
|
|
|
12691
12537
|
};
|
|
12692
12538
|
|
|
12693
12539
|
// src/runtime-kernel/llm/retry-fallback.ts
|
|
12694
|
-
var
|
|
12540
|
+
var logger15 = new Logger("LlmCaller");
|
|
12695
12541
|
async function callWithRetryFallback(params) {
|
|
12696
12542
|
const {
|
|
12697
12543
|
deps,
|
|
@@ -12719,11 +12565,9 @@ async function callWithRetryFallback(params) {
|
|
|
12719
12565
|
const retryEpisode = new LlmRetryEpisode(traceId, eventHandler);
|
|
12720
12566
|
let previousAttemptTracker;
|
|
12721
12567
|
if (!clientRetryEnabled) {
|
|
12722
|
-
|
|
12723
|
-
logger16.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
12568
|
+
logger15.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
12724
12569
|
modelId,
|
|
12725
|
-
|
|
12726
|
-
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"
|
|
12727
12571
|
});
|
|
12728
12572
|
}
|
|
12729
12573
|
try {
|
|
@@ -12759,7 +12603,7 @@ async function callWithRetryFallback(params) {
|
|
|
12759
12603
|
}) : void 0;
|
|
12760
12604
|
try {
|
|
12761
12605
|
if (isRetry) {
|
|
12762
|
-
|
|
12606
|
+
logger15.info("LLM \u8C03\u7528\u91CD\u8BD5", { attempt, configuredMaxRetries });
|
|
12763
12607
|
}
|
|
12764
12608
|
actualAttempts++;
|
|
12765
12609
|
retryEpisode.retrying(actualAttempts);
|
|
@@ -12788,7 +12632,7 @@ async function callWithRetryFallback(params) {
|
|
|
12788
12632
|
if (deps.retryConfig.enableEmptyResponseRetry && !responseContent?.trim() && !toolCallsFromLLM?.length) {
|
|
12789
12633
|
throw new Error("LLM\u8FD4\u56DE\u4E86\u7A7A\u54CD\u5E94");
|
|
12790
12634
|
}
|
|
12791
|
-
|
|
12635
|
+
logger15.debug("LLM \u8C03\u7528\u6210\u529F", { attempts: actualAttempts, maxTotalAttempts });
|
|
12792
12636
|
if (attemptContextUsage) {
|
|
12793
12637
|
fallbackObserver?.onLlmAttemptSucceeded?.(activeModelId, attemptContextUsage);
|
|
12794
12638
|
} else {
|
|
@@ -12799,7 +12643,7 @@ async function callWithRetryFallback(params) {
|
|
|
12799
12643
|
} catch (error) {
|
|
12800
12644
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
12801
12645
|
if (lastError.name === "AbortError") {
|
|
12802
|
-
|
|
12646
|
+
logger15.info("LLM \u8C03\u7528\u5DF2\u53D6\u6D88\uFF0C\u4E0D\u8FDB\u5165 provider failure \u5206\u7C7B\u4E0E\u91CD\u8BD5\u6D41\u7A0B", {
|
|
12803
12647
|
attempt: attempt + 1,
|
|
12804
12648
|
actualAttempts,
|
|
12805
12649
|
maxTotalAttempts,
|
|
@@ -12818,7 +12662,7 @@ async function callWithRetryFallback(params) {
|
|
|
12818
12662
|
total_attempts: actualAttempts,
|
|
12819
12663
|
error_code: classification.errorCode
|
|
12820
12664
|
};
|
|
12821
|
-
|
|
12665
|
+
logger15.error("LLM \u8C03\u7528\u5931\u8D25", {
|
|
12822
12666
|
attempt: attempt + 1,
|
|
12823
12667
|
maxAttempts: currentMaxRetries + 1,
|
|
12824
12668
|
actualAttempts,
|
|
@@ -12827,7 +12671,7 @@ async function callWithRetryFallback(params) {
|
|
|
12827
12671
|
});
|
|
12828
12672
|
previousAttemptTracker = attemptTracker;
|
|
12829
12673
|
if (!hasLlmAttemptBudgetRemaining({ actualAttempts, maxTotalAttempts })) {
|
|
12830
|
-
|
|
12674
|
+
logger15.error("\u5DF2\u8FBE\u5230 LLM \u603B\u8C03\u7528\u6B21\u6570\u4E0A\u9650\uFF0C\u505C\u6B62\u91CD\u8BD5/\u5207\u6A21\u578B", {
|
|
12831
12675
|
actualAttempts,
|
|
12832
12676
|
maxTotalAttempts
|
|
12833
12677
|
});
|
|
@@ -12857,37 +12701,15 @@ async function callWithRetryFallback(params) {
|
|
|
12857
12701
|
attempt -= 1;
|
|
12858
12702
|
continue;
|
|
12859
12703
|
}
|
|
12860
|
-
const quotaFallbackModelId = tryCloudQuotaFallback({
|
|
12861
|
-
deps,
|
|
12862
|
-
activeModelId,
|
|
12863
|
-
options,
|
|
12864
|
-
excludedModelIds,
|
|
12865
|
-
requirement,
|
|
12866
|
-
error: lastError,
|
|
12867
|
-
fallbackObserver,
|
|
12868
|
-
evaluateFallbackPromptCapacity: invocationContext?.evaluateFallbackPromptCapacity
|
|
12869
|
-
});
|
|
12870
|
-
if (quotaFallbackModelId) {
|
|
12871
|
-
fallbackObserver?.onModelFallbackApplied?.({
|
|
12872
|
-
fromModelId: activeModelId,
|
|
12873
|
-
toModelId: quotaFallbackModelId,
|
|
12874
|
-
reason: lastError.message,
|
|
12875
|
-
policy: "cloud-quota"
|
|
12876
|
-
});
|
|
12877
|
-
activeModelId = quotaFallbackModelId;
|
|
12878
|
-
excludedModelIds.add(quotaFallbackModelId);
|
|
12879
|
-
attempt -= 1;
|
|
12880
|
-
continue;
|
|
12881
|
-
}
|
|
12882
12704
|
}
|
|
12883
12705
|
if (classification.category === "non_retryable" /* NON_RETRYABLE */) {
|
|
12884
|
-
|
|
12706
|
+
logger15.error("\u9519\u8BEF\u4E0D\u53EF\u91CD\u8BD5\uFF0C\u76F4\u63A5\u5931\u8D25", { reason: classification.reason });
|
|
12885
12707
|
retryEpisode.finish("failed", failedRetryState);
|
|
12886
12708
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
12887
12709
|
throw lastError;
|
|
12888
12710
|
}
|
|
12889
12711
|
if (attempt >= configuredMaxRetries || categoryRetries[category] >= currentMaxRetries) {
|
|
12890
|
-
|
|
12712
|
+
logger15.error("\u5DF2\u8FBE\u5230\u6700\u5927\u91CD\u8BD5\u6B21\u6570\uFF0C\u653E\u5F03\u91CD\u8BD5", { maxRetries: currentMaxRetries });
|
|
12891
12713
|
retryEpisode.finish("exhausted", failedRetryState);
|
|
12892
12714
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
12893
12715
|
throw lastError;
|
|
@@ -12899,9 +12721,9 @@ async function callWithRetryFallback(params) {
|
|
|
12899
12721
|
6e4
|
|
12900
12722
|
);
|
|
12901
12723
|
if (classification.category === "rate_limit" /* RATE_LIMIT */) {
|
|
12902
|
-
|
|
12724
|
+
logger15.warn("\u901F\u7387\u9650\u5236\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
12903
12725
|
} else if (classification.category === "retryable" /* RETRYABLE */) {
|
|
12904
|
-
|
|
12726
|
+
logger15.warn("\u53EF\u91CD\u8BD5\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
12905
12727
|
}
|
|
12906
12728
|
throwIfAborted(signal, "\u5EF6\u8FDF\u7B49\u5F85\u524D\u68C0\u6D4B\u5230\u53D6\u6D88\u4FE1\u53F7\uFF0C\u505C\u6B62\u91CD\u8BD5");
|
|
12907
12729
|
categoryRetries[category] += 1;
|
|
@@ -12938,16 +12760,11 @@ function waitForRetry(delayMs, signal) {
|
|
|
12938
12760
|
}
|
|
12939
12761
|
function isClientRetryEnabledForModel(modelCatalog, modelId, options) {
|
|
12940
12762
|
if (options.retry_policy === "none") return false;
|
|
12941
|
-
|
|
12942
|
-
if (cfg?.billing_mode === "cloud") return false;
|
|
12943
|
-
if (options.retry_policy === "client") return true;
|
|
12944
|
-
if (!cfg) return true;
|
|
12945
|
-
if (cfg.enable_client_retry === false) return false;
|
|
12946
|
-
return true;
|
|
12763
|
+
return modelCatalog.getModelById(modelId)?.enable_client_retry !== false;
|
|
12947
12764
|
}
|
|
12948
12765
|
function throwIfAborted(signal, message) {
|
|
12949
12766
|
if (!signal?.aborted) return;
|
|
12950
|
-
|
|
12767
|
+
logger15.info(message);
|
|
12951
12768
|
const reason = signal.reason;
|
|
12952
12769
|
if (reason instanceof Error && reason.name === "AbortError") throw reason;
|
|
12953
12770
|
const reasonText = typeof reason === "string" && reason.trim().length > 0 ? reason : "stream_interrupted";
|
|
@@ -13265,7 +13082,7 @@ async function recoverChildRunEventsFromCheckpoint(params) {
|
|
|
13265
13082
|
}
|
|
13266
13083
|
|
|
13267
13084
|
// src/runtime-kernel/child-runs/childRunInvoker.ts
|
|
13268
|
-
var
|
|
13085
|
+
var logger16 = new Logger("ChildRunInvoker");
|
|
13269
13086
|
var ChildRunInvoker = class {
|
|
13270
13087
|
modelResolver;
|
|
13271
13088
|
createLlmNode;
|
|
@@ -13307,7 +13124,7 @@ var ChildRunInvoker = class {
|
|
|
13307
13124
|
const resolvedParentRunId = parentRunId ?? parentToolContext.runId;
|
|
13308
13125
|
const depthDecision = decideChildRunDepth({ parentToolContext });
|
|
13309
13126
|
if (!depthDecision.allowed) {
|
|
13310
|
-
|
|
13127
|
+
logger16.warn("child-run \u6DF1\u5EA6\u8D85\u8FC7\u4E0A\u9650\uFF0C\u62D2\u7EDD\u7EE7\u7EED\u9012\u5F52\u6267\u884C", {
|
|
13311
13128
|
runId: childRunId,
|
|
13312
13129
|
parentRunId: resolvedParentRunId,
|
|
13313
13130
|
parentDepth: depthDecision.parentDepth,
|
|
@@ -13324,7 +13141,7 @@ var ChildRunInvoker = class {
|
|
|
13324
13141
|
};
|
|
13325
13142
|
}
|
|
13326
13143
|
if (abortSignal?.aborted || parentToolContext.abortSignal?.aborted) {
|
|
13327
|
-
|
|
13144
|
+
logger16.info("child-run \u5728\u4EFB\u52A1\u63A5\u7EB3\u524D\u5DF2\u53D6\u6D88", {
|
|
13328
13145
|
runId: childRunId,
|
|
13329
13146
|
parentRunId: resolvedParentRunId
|
|
13330
13147
|
});
|
|
@@ -13348,7 +13165,7 @@ var ChildRunInvoker = class {
|
|
|
13348
13165
|
}
|
|
13349
13166
|
const turnId = config.initialInput?.turnId ?? generateTurnId();
|
|
13350
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");
|
|
13351
|
-
|
|
13168
|
+
logger16.info(`\u542F\u52A8 child-run: ${agentConfig.id}`, {
|
|
13352
13169
|
conversationId: runtimeConversationId,
|
|
13353
13170
|
checkpointKey: internalCheckpointKey,
|
|
13354
13171
|
maxSteps,
|
|
@@ -13466,7 +13283,7 @@ var ChildRunInvoker = class {
|
|
|
13466
13283
|
);
|
|
13467
13284
|
finalAnswer = extractFinalAnswer(allEvents);
|
|
13468
13285
|
lastProgress = finalAnswer ? void 0 : extractLastProgress(allEvents);
|
|
13469
|
-
|
|
13286
|
+
logger16.info("child-run \u6267\u884C\u5B8C\u6210", {
|
|
13470
13287
|
stepCount,
|
|
13471
13288
|
eventCount: allEvents.length,
|
|
13472
13289
|
hasFinalAnswer: !!finalAnswer,
|
|
@@ -13496,13 +13313,13 @@ var ChildRunInvoker = class {
|
|
|
13496
13313
|
cancelled = abortSignal?.aborted === true || isAbortError2(err);
|
|
13497
13314
|
error = err instanceof Error ? err.message : String(err);
|
|
13498
13315
|
if (cancelled) {
|
|
13499
|
-
|
|
13316
|
+
logger16.info("child-run \u6267\u884C\u53D6\u6D88", {
|
|
13500
13317
|
runId: childRunId,
|
|
13501
13318
|
parentRunId: resolvedParentRunId,
|
|
13502
13319
|
message: error
|
|
13503
13320
|
});
|
|
13504
13321
|
} else {
|
|
13505
|
-
|
|
13322
|
+
logger16.error(
|
|
13506
13323
|
"child-run \u6267\u884C\u5931\u8D25:",
|
|
13507
13324
|
err instanceof Error ? {
|
|
13508
13325
|
name: err.name,
|
|
@@ -13598,7 +13415,7 @@ var ChildRunInvoker = class {
|
|
|
13598
13415
|
function isAbortError2(error) {
|
|
13599
13416
|
return error instanceof Error && error.name === "AbortError";
|
|
13600
13417
|
}
|
|
13601
|
-
function
|
|
13418
|
+
function readNonEmptyString5(value) {
|
|
13602
13419
|
if (typeof value !== "string") {
|
|
13603
13420
|
return void 0;
|
|
13604
13421
|
}
|
|
@@ -13606,7 +13423,7 @@ function readNonEmptyString6(value) {
|
|
|
13606
13423
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
13607
13424
|
}
|
|
13608
13425
|
function resolveChildRunConversationId(params) {
|
|
13609
|
-
const conversationId =
|
|
13426
|
+
const conversationId = readNonEmptyString5(params.explicitConversationId) ?? readNonEmptyString5(params.parentToolContext.conversationId);
|
|
13610
13427
|
if (!conversationId) {
|
|
13611
13428
|
throw new Error(
|
|
13612
13429
|
"ChildRunInvoker requires conversationId from admission or parent ToolContext."
|
|
@@ -13615,7 +13432,7 @@ function resolveChildRunConversationId(params) {
|
|
|
13615
13432
|
return conversationId;
|
|
13616
13433
|
}
|
|
13617
13434
|
function resolveChildRunModelId(params) {
|
|
13618
|
-
const explicitModelId =
|
|
13435
|
+
const explicitModelId = readNonEmptyString5(params.explicitModelId);
|
|
13619
13436
|
if (explicitModelId) {
|
|
13620
13437
|
return explicitModelId;
|
|
13621
13438
|
}
|
|
@@ -14560,7 +14377,7 @@ function runMetaFromRecord(record) {
|
|
|
14560
14377
|
}
|
|
14561
14378
|
|
|
14562
14379
|
// src/runtime-kernel/run-supervisor/functions/awaitingUserWatcher.ts
|
|
14563
|
-
var
|
|
14380
|
+
var logger17 = new Logger("RunSupervisorAwaitingUserWatcher");
|
|
14564
14381
|
function isRecord16(value) {
|
|
14565
14382
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14566
14383
|
}
|
|
@@ -14605,7 +14422,7 @@ function createAwaitingUserWatcher(options) {
|
|
|
14605
14422
|
resumeToken: event.resume_token
|
|
14606
14423
|
}
|
|
14607
14424
|
}).catch((error) => {
|
|
14608
|
-
|
|
14425
|
+
logger17.warn("failed to mark awaiting_user from requires_user_interaction", { error });
|
|
14609
14426
|
});
|
|
14610
14427
|
};
|
|
14611
14428
|
const dispose = () => {
|