@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/cli.cjs
CHANGED
|
@@ -2221,18 +2221,6 @@ var ErrorClassifier = class {
|
|
|
2221
2221
|
});
|
|
2222
2222
|
}
|
|
2223
2223
|
}
|
|
2224
|
-
const quotaPatterns = ["\u5DF2\u8FBE\u4E0A\u9650", "\u514D\u8D39\u671F\u5DF2\u7ED3\u675F"];
|
|
2225
|
-
for (const pattern of quotaPatterns) {
|
|
2226
|
-
if (errorMessage.includes(pattern)) {
|
|
2227
|
-
logClassification(context, "\u68C0\u6D4B\u5230\u4E91\u7AEF\u989D\u5EA6\u9650\u5236\uFF0C\u4E0D\u91CD\u8BD5", { matchedPattern: pattern });
|
|
2228
|
-
return createClassification("non_retryable" /* NON_RETRYABLE */, `\u4E91\u7AEF\u989D\u5EA6\u9650\u5236: ${pattern}`, null, {
|
|
2229
|
-
errorCode: ENGINE_ERROR_CODES.LLM_PROVIDER_DOWN,
|
|
2230
|
-
recoverable: false,
|
|
2231
|
-
hint: "check_billing_or_provider_status",
|
|
2232
|
-
metadata: { matchedPattern: pattern }
|
|
2233
|
-
});
|
|
2234
|
-
}
|
|
2235
|
-
}
|
|
2236
2224
|
const authPatterns = [
|
|
2237
2225
|
{ pattern: "unauthorized", code: "401" },
|
|
2238
2226
|
{ pattern: "forbidden", code: "403" },
|
|
@@ -2487,17 +2475,6 @@ var ErrorClassifier = class {
|
|
|
2487
2475
|
}
|
|
2488
2476
|
return Math.max(baseDelay, classification.suggestedDelay ?? 0);
|
|
2489
2477
|
}
|
|
2490
|
-
static isCloudQuotaError(error) {
|
|
2491
|
-
const msg = (error.message || "").toLowerCase();
|
|
2492
|
-
const patterns = [
|
|
2493
|
-
"\u989D\u5EA6\u4E0A\u9650",
|
|
2494
|
-
"\u5DF2\u8FBE\u4E0A\u9650",
|
|
2495
|
-
"\u514D\u8D39\u671F\u5DF2\u7ED3\u675F",
|
|
2496
|
-
"\u8BE5\u6A21\u578B\u6682\u4E0D\u53EF\u7528",
|
|
2497
|
-
"cloud_quota_exhausted"
|
|
2498
|
-
];
|
|
2499
|
-
return patterns.some((pattern) => msg.includes(pattern));
|
|
2500
|
-
}
|
|
2501
2478
|
};
|
|
2502
2479
|
|
|
2503
2480
|
// src/shared/engineErrorEvent.ts
|
|
@@ -3981,8 +3958,8 @@ var TokenCalculator = class {
|
|
|
3981
3958
|
return;
|
|
3982
3959
|
}
|
|
3983
3960
|
this.failedEncodingWarnings.add(requestedEncoding);
|
|
3984
|
-
const
|
|
3985
|
-
|
|
3961
|
+
const logger18 = new Logger("TokenCalculator");
|
|
3962
|
+
logger18.warn("tiktoken encoding unavailable, falling back to avgCharsPerToken estimator", {
|
|
3986
3963
|
requestedEncoding,
|
|
3987
3964
|
error
|
|
3988
3965
|
});
|
|
@@ -4074,49 +4051,6 @@ var llmTelemetryMiddleware = async (ctx, stage, next) => {
|
|
|
4074
4051
|
});
|
|
4075
4052
|
};
|
|
4076
4053
|
|
|
4077
|
-
// src/runtime-kernel/graph-engine/functions/runModelLock.ts
|
|
4078
|
-
function readNonEmptyString4(value) {
|
|
4079
|
-
if (typeof value !== "string") return void 0;
|
|
4080
|
-
const trimmed = value.trim();
|
|
4081
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
4082
|
-
}
|
|
4083
|
-
function decideRunModelLockPatch(params) {
|
|
4084
|
-
if (params.stageId !== "execute_llm") {
|
|
4085
|
-
return { shouldLog: false };
|
|
4086
|
-
}
|
|
4087
|
-
const normalized = readNonEmptyString4(params.appliedFallbackModelId);
|
|
4088
|
-
if (!normalized) {
|
|
4089
|
-
return { shouldLog: false };
|
|
4090
|
-
}
|
|
4091
|
-
if (readNonEmptyString4(params.currentRunLockedModelId) === normalized) {
|
|
4092
|
-
return { shouldLog: false };
|
|
4093
|
-
}
|
|
4094
|
-
return {
|
|
4095
|
-
executorLocalPatch: { runLockedModelId: normalized },
|
|
4096
|
-
shouldLog: true
|
|
4097
|
-
};
|
|
4098
|
-
}
|
|
4099
|
-
|
|
4100
|
-
// src/runtime-kernel/graph-engine/tick-pipeline/middlewares/runModelLockMiddleware.ts
|
|
4101
|
-
var logger4 = new Logger("GraphAgentExecutor");
|
|
4102
|
-
var runModelLockMiddleware = async (ctx, stage, next) => {
|
|
4103
|
-
await next();
|
|
4104
|
-
const decision = decideRunModelLockPatch({
|
|
4105
|
-
stageId: stage.id,
|
|
4106
|
-
appliedFallbackModelId: ctx.cloudQuotaFallbackAppliedModelId,
|
|
4107
|
-
currentRunLockedModelId: ctx.executorLocalPatch?.runLockedModelId ?? ctx.executorLocal?.runLockedModelId
|
|
4108
|
-
});
|
|
4109
|
-
if (!decision.executorLocalPatch) {
|
|
4110
|
-
return;
|
|
4111
|
-
}
|
|
4112
|
-
if (decision.shouldLog) {
|
|
4113
|
-
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}`);
|
|
4114
|
-
}
|
|
4115
|
-
return {
|
|
4116
|
-
executorLocalPatch: decision.executorLocalPatch
|
|
4117
|
-
};
|
|
4118
|
-
};
|
|
4119
|
-
|
|
4120
4054
|
// src/runtime-kernel/graph-engine/tick-pipeline/runTickPipeline.ts
|
|
4121
4055
|
var tickPipelineContextKeys = [
|
|
4122
4056
|
"input",
|
|
@@ -4152,7 +4086,6 @@ var tickPipelineContextKeys = [
|
|
|
4152
4086
|
"decision",
|
|
4153
4087
|
"systemReminderHitRuleIds",
|
|
4154
4088
|
"contextTrace",
|
|
4155
|
-
"cloudQuotaFallbackAppliedModelId",
|
|
4156
4089
|
"modelFallbackAudit",
|
|
4157
4090
|
"telemetry",
|
|
4158
4091
|
"audit",
|
|
@@ -4491,7 +4424,7 @@ ${normalized}
|
|
|
4491
4424
|
}
|
|
4492
4425
|
|
|
4493
4426
|
// src/runtime-kernel/system-reminder/apply.ts
|
|
4494
|
-
var
|
|
4427
|
+
var logger4 = new Logger("SystemReminder");
|
|
4495
4428
|
var readString2 = (v) => {
|
|
4496
4429
|
if (typeof v !== "string") return void 0;
|
|
4497
4430
|
const s = v;
|
|
@@ -4554,7 +4487,7 @@ function applySystemReminders(params) {
|
|
|
4554
4487
|
} catch {
|
|
4555
4488
|
}
|
|
4556
4489
|
}
|
|
4557
|
-
|
|
4490
|
+
logger4.info("SystemReminder \u5DF2\u6CE8\u5165\u5230 LLM \u8F93\u5165\u672B\u5C3E", {
|
|
4558
4491
|
ruleIds: injectedRuleIds.length > 0 ? injectedRuleIds : Array.from(seenRuleIds),
|
|
4559
4492
|
promptKey: ctx.request.promptKey,
|
|
4560
4493
|
executorLocal: {
|
|
@@ -5046,7 +4979,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5046
4979
|
"turnId"
|
|
5047
4980
|
],
|
|
5048
4981
|
writes: [
|
|
5049
|
-
"cloudQuotaFallbackAppliedModelId",
|
|
5050
4982
|
"modelFallbackAudit",
|
|
5051
4983
|
"llmCallStartedAt",
|
|
5052
4984
|
"llmResp",
|
|
@@ -5054,7 +4986,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5054
4986
|
"contextUsage"
|
|
5055
4987
|
],
|
|
5056
4988
|
async run(ctx) {
|
|
5057
|
-
let cloudQuotaFallbackAppliedModelId;
|
|
5058
4989
|
let modelFallbackAudit;
|
|
5059
4990
|
let contextUsage;
|
|
5060
4991
|
const modelFallbackRejections = [];
|
|
@@ -5073,9 +5004,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5073
5004
|
streamEventHandler,
|
|
5074
5005
|
ctx.signal,
|
|
5075
5006
|
{
|
|
5076
|
-
onCloudQuotaFallbackApplied(fallbackModelId) {
|
|
5077
|
-
cloudQuotaFallbackAppliedModelId = readNonEmptyString3(fallbackModelId);
|
|
5078
|
-
},
|
|
5079
5007
|
onLlmAttemptSucceeded(_activeModelId, attemptContextUsage) {
|
|
5080
5008
|
contextUsage = attemptContextUsage;
|
|
5081
5009
|
},
|
|
@@ -5172,7 +5100,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5172
5100
|
});
|
|
5173
5101
|
}
|
|
5174
5102
|
return {
|
|
5175
|
-
cloudQuotaFallbackAppliedModelId,
|
|
5176
5103
|
modelFallbackAudit,
|
|
5177
5104
|
llmCallStartedAt,
|
|
5178
5105
|
llmResp,
|
|
@@ -6093,18 +6020,16 @@ function createPrepareCallStage(dependencies) {
|
|
|
6093
6020
|
"toolDefinitionTokens"
|
|
6094
6021
|
],
|
|
6095
6022
|
async run(ctx) {
|
|
6096
|
-
const
|
|
6097
|
-
const requestedModelId = lockedRunModelId ?? ctx.request.model_id;
|
|
6023
|
+
const requestedModelId = ctx.request.model_id;
|
|
6098
6024
|
const modelId = dependencies.modelResolver.resolveModelId(requestedModelId);
|
|
6099
6025
|
await emitAuditEnvelope(ctx.audit, {
|
|
6100
6026
|
action: "model.select",
|
|
6101
6027
|
actor: { kind: "system" },
|
|
6102
6028
|
decision: {
|
|
6103
6029
|
outcome: "recorded",
|
|
6104
|
-
reason:
|
|
6030
|
+
reason: requestedModelId ? "request model id" : "default model resolver",
|
|
6105
6031
|
metadata: {
|
|
6106
6032
|
requestedModelId,
|
|
6107
|
-
lockedRunModelId,
|
|
6108
6033
|
selectedModelId: modelId
|
|
6109
6034
|
}
|
|
6110
6035
|
},
|
|
@@ -6151,10 +6076,6 @@ function createPrepareCallStage(dependencies) {
|
|
|
6151
6076
|
if (ctx.executorLocal?.lockRequestedModelId === true) {
|
|
6152
6077
|
llmOptions.allow_model_fallback = false;
|
|
6153
6078
|
}
|
|
6154
|
-
const isRunContinuation = ctx.executorLocal?.llmInvocationKind === "continuation";
|
|
6155
|
-
if (dependencies.cloudQuotaFallbackModelId && modelConfig?.billing_mode === "cloud" && modelId !== dependencies.cloudQuotaFallbackModelId && isRunContinuation && ctx.executorLocal?.lockRequestedModelId !== true) {
|
|
6156
|
-
llmOptions.cloud_quota_fallback_model_id = dependencies.cloudQuotaFallbackModelId;
|
|
6157
|
-
}
|
|
6158
6079
|
const effectiveEffort = resolveEffectiveEffort(
|
|
6159
6080
|
ctx.request.reasoning_effort,
|
|
6160
6081
|
modelConfig?.reasoning
|
|
@@ -6271,12 +6192,11 @@ function applyCalibration(rawLocalTotal, imageInputTokens, coefficient) {
|
|
|
6271
6192
|
}
|
|
6272
6193
|
|
|
6273
6194
|
// src/runtime-kernel/graph-engine/executor.ts
|
|
6274
|
-
var
|
|
6195
|
+
var logger5 = new Logger("GraphAgentExecutor");
|
|
6275
6196
|
var GraphAgentExecutor = class {
|
|
6276
6197
|
llmCaller;
|
|
6277
6198
|
toolRuntime;
|
|
6278
6199
|
contextBuilder;
|
|
6279
|
-
cloudQuotaFallbackModelId;
|
|
6280
6200
|
modelResolver;
|
|
6281
6201
|
modelCatalog;
|
|
6282
6202
|
telemetryPort;
|
|
@@ -6288,7 +6208,6 @@ var GraphAgentExecutor = class {
|
|
|
6288
6208
|
this.llmCaller = dependencies.llmCaller;
|
|
6289
6209
|
this.toolRuntime = dependencies.toolRuntime;
|
|
6290
6210
|
this.contextBuilder = dependencies.contextBuilder;
|
|
6291
|
-
this.cloudQuotaFallbackModelId = readNonEmptyString3(dependencies.cloudQuotaFallbackModelId);
|
|
6292
6211
|
this.modelCatalog = dependencies.modelCatalog ?? createEmptyModelCatalog();
|
|
6293
6212
|
this.modelResolver = dependencies.modelResolver ?? new ModelResolver({
|
|
6294
6213
|
modelCatalog: this.modelCatalog
|
|
@@ -6305,8 +6224,7 @@ var GraphAgentExecutor = class {
|
|
|
6305
6224
|
createPrepareCallStage({
|
|
6306
6225
|
modelResolver: this.modelResolver,
|
|
6307
6226
|
modelCatalog: this.modelCatalog,
|
|
6308
|
-
toolCatalog: this.toolRuntime
|
|
6309
|
-
cloudQuotaFallbackModelId: this.cloudQuotaFallbackModelId
|
|
6227
|
+
toolCatalog: this.toolRuntime
|
|
6310
6228
|
}),
|
|
6311
6229
|
createBuildContextStage({
|
|
6312
6230
|
contextBuilder: this.contextBuilder
|
|
@@ -6328,7 +6246,7 @@ var GraphAgentExecutor = class {
|
|
|
6328
6246
|
}),
|
|
6329
6247
|
createBuildDecisionStage()
|
|
6330
6248
|
];
|
|
6331
|
-
this.middlewares = [llmTelemetryMiddleware
|
|
6249
|
+
this.middlewares = [llmTelemetryMiddleware];
|
|
6332
6250
|
}
|
|
6333
6251
|
async tick(input, eventHandler) {
|
|
6334
6252
|
const ctx = {
|
|
@@ -6353,7 +6271,7 @@ var GraphAgentExecutor = class {
|
|
|
6353
6271
|
audit: this.auditPort,
|
|
6354
6272
|
tokenizer: this.tokenizer
|
|
6355
6273
|
};
|
|
6356
|
-
|
|
6274
|
+
logger5.info("[GraphAgentExecutor] tick \u8C03\u7528", {
|
|
6357
6275
|
stream: input.stream === true,
|
|
6358
6276
|
hasEventHandler: Boolean(eventHandler),
|
|
6359
6277
|
hasSummarizationCallbacks: Boolean(input.summarizationCallbacks)
|
|
@@ -7376,7 +7294,7 @@ var LlmNodeEventBridge = class {
|
|
|
7376
7294
|
};
|
|
7377
7295
|
|
|
7378
7296
|
// src/runtime-kernel/graph-engine/nodes/llmNode.ts
|
|
7379
|
-
var
|
|
7297
|
+
var logger6 = new Logger("LlmNode");
|
|
7380
7298
|
var LlmNode = class {
|
|
7381
7299
|
id = "llm";
|
|
7382
7300
|
reasoner;
|
|
@@ -7385,7 +7303,7 @@ var LlmNode = class {
|
|
|
7385
7303
|
}
|
|
7386
7304
|
async run(state) {
|
|
7387
7305
|
const local = state.local ?? {};
|
|
7388
|
-
|
|
7306
|
+
logger6.info("[LlmNode] \u5F00\u59CB\u6267\u884C LLM \u8282\u70B9", {
|
|
7389
7307
|
localKeys: Object.keys(local)
|
|
7390
7308
|
});
|
|
7391
7309
|
const graphLocal = readGraphAgentLocal(state.local);
|
|
@@ -7400,12 +7318,12 @@ var LlmNode = class {
|
|
|
7400
7318
|
signal,
|
|
7401
7319
|
history
|
|
7402
7320
|
} = graphLocal;
|
|
7403
|
-
|
|
7321
|
+
logger6.info("[LlmNode] \u5DF2\u52A0\u8F7D\u5386\u53F2\u4E8B\u4EF6", {
|
|
7404
7322
|
historyCount: history.length,
|
|
7405
7323
|
hasSummarizationCallbacks: Boolean(summarizationCallbacks)
|
|
7406
7324
|
});
|
|
7407
7325
|
if (!request) {
|
|
7408
|
-
|
|
7326
|
+
logger6.warn("Request object is missing, yielding.");
|
|
7409
7327
|
return { kind: "yield", events: [] };
|
|
7410
7328
|
}
|
|
7411
7329
|
const turnId = requireRuntimeIdentity(graphLocal.turnId, "turnId");
|
|
@@ -7498,12 +7416,12 @@ var LlmNode = class {
|
|
|
7498
7416
|
...nodeState.streamRuntimeEvents,
|
|
7499
7417
|
...contextUsageEvent ? [contextUsageEvent] : []
|
|
7500
7418
|
];
|
|
7501
|
-
|
|
7419
|
+
logger6.info("[LlmNode] \u5386\u53F2\u4E8B\u4EF6\u5DF2\u66F4\u65B0", {
|
|
7502
7420
|
previousCount: history.length,
|
|
7503
7421
|
nextCount: patch.history.length,
|
|
7504
7422
|
streamedEventCount: nodeState.streamRuntimeEvents.length
|
|
7505
7423
|
});
|
|
7506
|
-
|
|
7424
|
+
logger6.info("[LlmNode] \u6267\u884C\u5668\u51B3\u7B56\u5B8C\u6210", {
|
|
7507
7425
|
decisionKind: decision.kind,
|
|
7508
7426
|
emittedEventCount: combinedEvents.length
|
|
7509
7427
|
});
|
|
@@ -7525,7 +7443,7 @@ var LlmNode = class {
|
|
|
7525
7443
|
}
|
|
7526
7444
|
case "error": {
|
|
7527
7445
|
const { name, message, stack } = decision.error;
|
|
7528
|
-
|
|
7446
|
+
logger6.error("[LlmNode] Executor returned an error", { name, message, stack });
|
|
7529
7447
|
return { kind: "yield", events: combinedEvents };
|
|
7530
7448
|
}
|
|
7531
7449
|
default: {
|
|
@@ -7631,7 +7549,7 @@ async function resolveToolModelInput(input) {
|
|
|
7631
7549
|
}
|
|
7632
7550
|
|
|
7633
7551
|
// src/runtime-kernel/graph-engine/nodes/toolNode.finalAnswerProjector.ts
|
|
7634
|
-
function
|
|
7552
|
+
function readNonEmptyString4(value) {
|
|
7635
7553
|
if (typeof value !== "string") {
|
|
7636
7554
|
return void 0;
|
|
7637
7555
|
}
|
|
@@ -7639,7 +7557,7 @@ function readNonEmptyString5(value) {
|
|
|
7639
7557
|
return normalized.length > 0 ? normalized : void 0;
|
|
7640
7558
|
}
|
|
7641
7559
|
function resolveFinalAnswerFromToolControl(finalAnswer) {
|
|
7642
|
-
return
|
|
7560
|
+
return readNonEmptyString4(finalAnswer);
|
|
7643
7561
|
}
|
|
7644
7562
|
|
|
7645
7563
|
// src/runtime-kernel/graph-engine/nodes/toolNode.helpers.ts
|
|
@@ -7895,7 +7813,7 @@ function buildErrorLocalState(params) {
|
|
|
7895
7813
|
}
|
|
7896
7814
|
|
|
7897
7815
|
// src/runtime-kernel/tools/argNormalizer.ts
|
|
7898
|
-
var
|
|
7816
|
+
var logger7 = new Logger("ToolArgNormalizer");
|
|
7899
7817
|
function isRecord10(v) {
|
|
7900
7818
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
7901
7819
|
}
|
|
@@ -7915,7 +7833,7 @@ function joinPath(basePath, segment) {
|
|
|
7915
7833
|
function logJsonEncodedNormalization(expectedType, options) {
|
|
7916
7834
|
const toolPrefix = options.toolName ? `${options.toolName}.` : "";
|
|
7917
7835
|
const path = options.path ?? "<root>";
|
|
7918
|
-
|
|
7836
|
+
logger7.warn("normalized JSON-encoded tool argument", {
|
|
7919
7837
|
expectedType,
|
|
7920
7838
|
path: `${toolPrefix}${path}`
|
|
7921
7839
|
});
|
|
@@ -8211,7 +8129,7 @@ function ensureToolContextRuntimeCapability(params) {
|
|
|
8211
8129
|
}
|
|
8212
8130
|
|
|
8213
8131
|
// src/runtime-kernel/graph-engine/nodes/toolNode.eventBridge.ts
|
|
8214
|
-
var
|
|
8132
|
+
var logger8 = new Logger("ToolNode");
|
|
8215
8133
|
var ToolNodeEventBridge = class {
|
|
8216
8134
|
constructor(deps) {
|
|
8217
8135
|
this.deps = deps;
|
|
@@ -8233,7 +8151,7 @@ var ToolNodeEventBridge = class {
|
|
|
8233
8151
|
status,
|
|
8234
8152
|
payload: { ...payload }
|
|
8235
8153
|
};
|
|
8236
|
-
|
|
8154
|
+
logger8.info("[ToolNode] \u53D1\u51FA tool_process \u4E8B\u4EF6", {
|
|
8237
8155
|
phase,
|
|
8238
8156
|
status,
|
|
8239
8157
|
toolName: this.deps.toolName,
|
|
@@ -8273,7 +8191,7 @@ var ToolNodeEventBridge = class {
|
|
|
8273
8191
|
const answerId = generateAnswerSegmentId();
|
|
8274
8192
|
const id = answerId;
|
|
8275
8193
|
const timestamp = Date.now();
|
|
8276
|
-
|
|
8194
|
+
logger8.info("[ToolNode] \u5DE5\u5177\u8F93\u51FA\u6620\u5C04\u4E3A final_answer", {
|
|
8277
8195
|
sourceToolName: params.sourceToolName,
|
|
8278
8196
|
toolCallId: this.deps.toolCallId,
|
|
8279
8197
|
conversationId: this.deps.conversationId,
|
|
@@ -8331,7 +8249,7 @@ var ToolNodeEventBridge = class {
|
|
|
8331
8249
|
};
|
|
8332
8250
|
|
|
8333
8251
|
// src/runtime-kernel/graph-engine/nodes/toolNode.executionSetup.ts
|
|
8334
|
-
var
|
|
8252
|
+
var logger9 = new Logger("ToolNode");
|
|
8335
8253
|
function parseToolArgs(call) {
|
|
8336
8254
|
const rawArguments = typeof call.function?.arguments === "string" ? call.function.arguments : "";
|
|
8337
8255
|
if (!rawArguments.trim()) {
|
|
@@ -8351,19 +8269,13 @@ function parseToolArgs(call) {
|
|
|
8351
8269
|
return { ok: true, value: parsed };
|
|
8352
8270
|
} catch (error) {
|
|
8353
8271
|
const reason = error instanceof Error ? error.message : "Unknown JSON parse error";
|
|
8354
|
-
|
|
8272
|
+
logger9.warn("failed to parse tool arguments", { error });
|
|
8355
8273
|
return {
|
|
8356
8274
|
ok: false,
|
|
8357
8275
|
error: `Tool arguments are not valid JSON: ${reason}`
|
|
8358
8276
|
};
|
|
8359
8277
|
}
|
|
8360
8278
|
}
|
|
8361
|
-
function readRunLockedModelId(local) {
|
|
8362
|
-
const executorLocal = local.executorLocal;
|
|
8363
|
-
if (!isRecord9(executorLocal)) return void 0;
|
|
8364
|
-
const lockedModelId = executorLocal.runLockedModelId;
|
|
8365
|
-
return typeof lockedModelId === "string" && lockedModelId.trim() ? lockedModelId : void 0;
|
|
8366
|
-
}
|
|
8367
8279
|
function prepareToolNodeContext(state) {
|
|
8368
8280
|
const local = state.local || {};
|
|
8369
8281
|
const toolContext = isRecord9(local.toolContext) ? local.toolContext : {};
|
|
@@ -8381,7 +8293,6 @@ function prepareToolNodeContext(state) {
|
|
|
8381
8293
|
}
|
|
8382
8294
|
});
|
|
8383
8295
|
attachWorkingHistoryView({ state, toolContext });
|
|
8384
|
-
toolContext.activeModelId = readRunLockedModelId(local) ?? toolContext.modelId;
|
|
8385
8296
|
return {
|
|
8386
8297
|
state,
|
|
8387
8298
|
local,
|
|
@@ -8752,7 +8663,7 @@ async function claimPendingUserInputs(state, result) {
|
|
|
8752
8663
|
}
|
|
8753
8664
|
|
|
8754
8665
|
// src/runtime-kernel/graph-engine/nodes/toolNode.ts
|
|
8755
|
-
var
|
|
8666
|
+
var logger10 = new Logger("ToolNode");
|
|
8756
8667
|
function isAbortSignal(value) {
|
|
8757
8668
|
return value !== null && typeof value === "object" && "aborted" in value;
|
|
8758
8669
|
}
|
|
@@ -8965,7 +8876,7 @@ var ToolNode = class {
|
|
|
8965
8876
|
throw abortError;
|
|
8966
8877
|
}
|
|
8967
8878
|
const prepared = prepareToolNodeContext(state);
|
|
8968
|
-
|
|
8879
|
+
logger10.info("[ToolNode] \u5F00\u59CB\u6267\u884C\u5DE5\u5177\u8282\u70B9", {
|
|
8969
8880
|
conversationId: prepared.conversationId,
|
|
8970
8881
|
turnId: prepared.turnId,
|
|
8971
8882
|
pendingCallCount: calls.length
|
|
@@ -8980,7 +8891,7 @@ var ToolNode = class {
|
|
|
8980
8891
|
toolCatalog: this.toolRuntime
|
|
8981
8892
|
});
|
|
8982
8893
|
if (!execution) {
|
|
8983
|
-
|
|
8894
|
+
logger10.warn("no tool name found in call");
|
|
8984
8895
|
return { kind: "yield", events: [] };
|
|
8985
8896
|
}
|
|
8986
8897
|
if (typeof execution.protocolError === "string") {
|
|
@@ -9020,7 +8931,7 @@ var ToolNode = class {
|
|
|
9020
8931
|
call,
|
|
9021
8932
|
context: prepared.toolContext,
|
|
9022
8933
|
abortGraceMs: this.abortGraceMs,
|
|
9023
|
-
onAbandon: () =>
|
|
8934
|
+
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", {
|
|
9024
8935
|
toolName: execution.toolName,
|
|
9025
8936
|
toolCallId: execution.toolCallId,
|
|
9026
8937
|
conversationId: prepared.conversationId,
|
|
@@ -9190,7 +9101,7 @@ var ToolNode = class {
|
|
|
9190
9101
|
runtimeEvents: context.bridge.getRuntimeEvents()
|
|
9191
9102
|
});
|
|
9192
9103
|
if (control?.terminateRun) {
|
|
9193
|
-
|
|
9104
|
+
logger10.info("[ToolNode] \u6536\u5230 control.terminateRun\uFF0C\u6267\u884C\u5B8C\u5DE5\u5177\u540E\u76F4\u63A5 yield \u7ED3\u675F\u672C\u8F6E run", {
|
|
9194
9105
|
toolName: context.toolName,
|
|
9195
9106
|
toolCallId: context.toolCallId,
|
|
9196
9107
|
conversationId: context.conversationId,
|
|
@@ -9199,7 +9110,7 @@ var ToolNode = class {
|
|
|
9199
9110
|
return { kind: "yield", events: context.bridge.getRuntimeEvents() };
|
|
9200
9111
|
}
|
|
9201
9112
|
if (remainingCalls.length === 0 && context.local.toolBatchCompletionMode === "yield_after_batch") {
|
|
9202
|
-
|
|
9113
|
+
logger10.info("[ToolNode] \u5DE5\u5177\u6279\u6B21\u5DF2\u7ED3\u7B97\uFF0C\u6309 Host \u7B56\u7565\u76F4\u63A5 yield", {
|
|
9203
9114
|
toolName: context.toolName,
|
|
9204
9115
|
toolCallId: context.toolCallId,
|
|
9205
9116
|
conversationId: context.conversationId,
|
|
@@ -9646,8 +9557,9 @@ var executor = zod.z.object({
|
|
|
9646
9557
|
lastStepsHintThreshold: counter.optional(),
|
|
9647
9558
|
systemReminderPolicy: AgentSpecSystemReminderPolicy.optional(),
|
|
9648
9559
|
toolObservationPolicy: AgentSpecToolObservationGovernancePolicy.optional(),
|
|
9560
|
+
// 已删除字段:0.45 及更早的 checkpoint 可能带 lastSuccessfulLlmModelId,0.46 及更早的可能带云端额度兜底留下的
|
|
9561
|
+
// runLockedModelId;照常接受,读入时丢弃(兜底已移除,恢复后按请求的模型继续)。
|
|
9649
9562
|
runLockedModelId: zod.z.string().optional(),
|
|
9650
|
-
// 0.45 及更早的 checkpoint 可能带这个已删除字段;照常接受,读入时丢弃。
|
|
9651
9563
|
lastSuccessfulLlmModelId: zod.z.string().optional(),
|
|
9652
9564
|
llmInvocationKind: zod.z.enum(["user_initiated", "continuation"]).optional(),
|
|
9653
9565
|
llmInvocationCount: counter.optional(),
|
|
@@ -9657,7 +9569,7 @@ var executor = zod.z.object({
|
|
|
9657
9569
|
committedCount: counter,
|
|
9658
9570
|
lastCommittedFingerprint: zod.z.string().optional()
|
|
9659
9571
|
}).strict().optional()
|
|
9660
|
-
}).strict().transform(({ lastSuccessfulLlmModelId: _retired, ...state }) => state);
|
|
9572
|
+
}).strict().transform(({ lastSuccessfulLlmModelId: _retired, runLockedModelId: _retiredLock, ...state }) => state);
|
|
9661
9573
|
var checkpoint = zod.z.object({
|
|
9662
9574
|
nodeId: zod.z.string().min(1),
|
|
9663
9575
|
schemaVersion: zod.z.literal(ENGINE_STATE_SCHEMA_VERSION).optional(),
|
|
@@ -9719,7 +9631,7 @@ __export(execution_exports, {
|
|
|
9719
9631
|
});
|
|
9720
9632
|
|
|
9721
9633
|
// src/runtime-kernel/execution/event-bus.ts
|
|
9722
|
-
var
|
|
9634
|
+
var logger11 = new Logger("EventBus");
|
|
9723
9635
|
var TypedEventEmitter = class {
|
|
9724
9636
|
listeners = /* @__PURE__ */ new Map();
|
|
9725
9637
|
maxListeners = 10;
|
|
@@ -9727,7 +9639,7 @@ var TypedEventEmitter = class {
|
|
|
9727
9639
|
const listeners = this.getListeners(event);
|
|
9728
9640
|
listeners.add(listener);
|
|
9729
9641
|
if (listeners.size > this.maxListeners) {
|
|
9730
|
-
|
|
9642
|
+
logger11.warn("EventBus listener count exceeds configured max", {
|
|
9731
9643
|
event: String(event),
|
|
9732
9644
|
count: listeners.size,
|
|
9733
9645
|
maxListeners: this.maxListeners
|
|
@@ -9787,7 +9699,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
9787
9699
|
super();
|
|
9788
9700
|
this.executionId = executionId;
|
|
9789
9701
|
this.setMaxListeners(30);
|
|
9790
|
-
|
|
9702
|
+
logger11.info(`EventBus created for execution ${this.executionId}`);
|
|
9791
9703
|
}
|
|
9792
9704
|
/**
|
|
9793
9705
|
* 发布一个事件到总线
|
|
@@ -9796,7 +9708,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
9796
9708
|
publish(envelope) {
|
|
9797
9709
|
if (envelope.trace.execution_id !== this.executionId) {
|
|
9798
9710
|
const error = new Error("EventEnvelope execution_id does not match EventBus instance.");
|
|
9799
|
-
|
|
9711
|
+
logger11.error("Mismatched execution_id", {
|
|
9800
9712
|
busExecutionId: this.executionId,
|
|
9801
9713
|
eventExecutionId: envelope.trace.execution_id,
|
|
9802
9714
|
eventSeq: envelope.seq
|
|
@@ -9808,7 +9720,7 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
9808
9720
|
const error = new Error(
|
|
9809
9721
|
"EventBus only accepts RuntimeEvent with formal run routing identity."
|
|
9810
9722
|
);
|
|
9811
|
-
|
|
9723
|
+
logger11.error("RuntimeEvent is missing formal run routing identity", {
|
|
9812
9724
|
executionId: this.executionId,
|
|
9813
9725
|
eventId: envelope.payload.id,
|
|
9814
9726
|
eventType: envelope.payload.type
|
|
@@ -9822,14 +9734,14 @@ var EventBus = class extends TypedEventEmitter {
|
|
|
9822
9734
|
* 关闭总线,清理所有监听器
|
|
9823
9735
|
*/
|
|
9824
9736
|
close() {
|
|
9825
|
-
|
|
9737
|
+
logger11.info(`Closing EventBus for execution ${this.executionId}`);
|
|
9826
9738
|
this.emit("close");
|
|
9827
9739
|
this.removeAllListeners();
|
|
9828
9740
|
}
|
|
9829
9741
|
};
|
|
9830
9742
|
|
|
9831
9743
|
// src/runtime-kernel/execution/sequencer.ts
|
|
9832
|
-
var
|
|
9744
|
+
var logger12 = new Logger("EventSequencer");
|
|
9833
9745
|
var EventSequencer = class {
|
|
9834
9746
|
executionId;
|
|
9835
9747
|
traceId;
|
|
@@ -9837,7 +9749,7 @@ var EventSequencer = class {
|
|
|
9837
9749
|
constructor(conversationId, traceId) {
|
|
9838
9750
|
this.executionId = generateExecutionId();
|
|
9839
9751
|
this.traceId = traceId || generateTraceId();
|
|
9840
|
-
|
|
9752
|
+
logger12.info(`EventSequencer created for conversation ${conversationId}`, {
|
|
9841
9753
|
executionId: this.executionId,
|
|
9842
9754
|
traceId: this.traceId
|
|
9843
9755
|
});
|
|
@@ -10650,7 +10562,7 @@ var ThoughtStreamSegmenter = class {
|
|
|
10650
10562
|
};
|
|
10651
10563
|
|
|
10652
10564
|
// src/runtime-kernel/llm/streaming-adapter.ts
|
|
10653
|
-
var
|
|
10565
|
+
var logger13 = new Logger("LlmCaller");
|
|
10654
10566
|
var CanonicalInferenceFailureError = class extends Error {
|
|
10655
10567
|
errorCode;
|
|
10656
10568
|
recoverable;
|
|
@@ -10874,7 +10786,7 @@ async function callLlmStream(params) {
|
|
|
10874
10786
|
} catch (error) {
|
|
10875
10787
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
10876
10788
|
if (normalized.name === "AbortError") {
|
|
10877
|
-
|
|
10789
|
+
logger13.info("Canonical inference \u6536\u5230\u53D6\u6D88\u7EC8\u6001\uFF0C\u4E0D\u53D1\u5E03\u666E\u901A error event", { modelId });
|
|
10878
10790
|
throw normalized;
|
|
10879
10791
|
}
|
|
10880
10792
|
const classification = ErrorClassifier.classify(normalized, {
|
|
@@ -10950,7 +10862,7 @@ var LlmRetryEpisode = class {
|
|
|
10950
10862
|
};
|
|
10951
10863
|
|
|
10952
10864
|
// src/runtime-kernel/llm/retry-fallback-routing.ts
|
|
10953
|
-
var
|
|
10865
|
+
var logger14 = new Logger("LlmCaller");
|
|
10954
10866
|
function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement, fallbackObserver, error, evaluateFallbackPromptCapacity2) {
|
|
10955
10867
|
deps.modelCatalog.getModelById(activeModelId);
|
|
10956
10868
|
const policyDecision = deps.policyEngine.decideOnError(error, {
|
|
@@ -10980,81 +10892,16 @@ function tryPolicyModelSwitch(deps, activeModelId, excludedModelIds, requirement
|
|
|
10980
10892
|
reason: "no_eligible_fallback_candidate",
|
|
10981
10893
|
requiredPlacements: requirement.placements
|
|
10982
10894
|
});
|
|
10983
|
-
|
|
10895
|
+
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");
|
|
10984
10896
|
return null;
|
|
10985
10897
|
}
|
|
10986
|
-
|
|
10898
|
+
logger14.warn("Policy \u5207\u6362\u6A21\u578B\u7EE7\u7EED", {
|
|
10987
10899
|
reason: policyDecision.reason,
|
|
10988
10900
|
activeModelId,
|
|
10989
10901
|
fallbackModelId
|
|
10990
10902
|
});
|
|
10991
10903
|
return fallbackModelId;
|
|
10992
10904
|
}
|
|
10993
|
-
function tryCloudQuotaFallback({
|
|
10994
|
-
deps,
|
|
10995
|
-
activeModelId,
|
|
10996
|
-
options,
|
|
10997
|
-
excludedModelIds,
|
|
10998
|
-
requirement,
|
|
10999
|
-
error,
|
|
11000
|
-
fallbackObserver,
|
|
11001
|
-
evaluateFallbackPromptCapacity: evaluateFallbackPromptCapacity2
|
|
11002
|
-
}) {
|
|
11003
|
-
const fallbackModelId = options.cloud_quota_fallback_model_id;
|
|
11004
|
-
if (!fallbackModelId || !ErrorClassifier.isCloudQuotaError(error) || excludedModelIds.has(fallbackModelId)) {
|
|
11005
|
-
return null;
|
|
11006
|
-
}
|
|
11007
|
-
const fallbackConfig = deps.modelCatalog.getModelById(fallbackModelId);
|
|
11008
|
-
if (!fallbackConfig?.api_key) {
|
|
11009
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11010
|
-
fromModelId: activeModelId,
|
|
11011
|
-
candidateModelId: fallbackModelId,
|
|
11012
|
-
policy: "cloud-quota",
|
|
11013
|
-
reason: "fallback_model_unavailable",
|
|
11014
|
-
requiredPlacements: requirement.placements
|
|
11015
|
-
});
|
|
11016
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\u76EE\u6807\u4E0D\u53EF\u7528\uFF08\u672A\u6CE8\u518C\u6216\u7F3A\u5C11 API Key\uFF09", { fallbackModelId });
|
|
11017
|
-
return null;
|
|
11018
|
-
}
|
|
11019
|
-
const compatibility = evaluateModelInputCompatibility(fallbackConfig, requirement);
|
|
11020
|
-
if (!compatibility.compatible) {
|
|
11021
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11022
|
-
fromModelId: activeModelId,
|
|
11023
|
-
candidateModelId: fallbackModelId,
|
|
11024
|
-
policy: "cloud-quota",
|
|
11025
|
-
reason: compatibility.reason,
|
|
11026
|
-
requiredPlacements: requirement.placements
|
|
11027
|
-
});
|
|
11028
|
-
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", {
|
|
11029
|
-
fallbackModelId,
|
|
11030
|
-
requiredPlacements: requirement.placements,
|
|
11031
|
-
reason: compatibility.reason
|
|
11032
|
-
});
|
|
11033
|
-
return null;
|
|
11034
|
-
}
|
|
11035
|
-
const capacityAdmission = evaluateFallbackPromptCapacity2?.(fallbackModelId);
|
|
11036
|
-
if (capacityAdmission && !capacityAdmission.admitted) {
|
|
11037
|
-
fallbackObserver?.onModelFallbackRejected?.({
|
|
11038
|
-
fromModelId: activeModelId,
|
|
11039
|
-
candidateModelId: fallbackModelId,
|
|
11040
|
-
policy: "cloud-quota",
|
|
11041
|
-
reason: capacityAdmission.reason,
|
|
11042
|
-
requiredPlacements: requirement.placements
|
|
11043
|
-
});
|
|
11044
|
-
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", {
|
|
11045
|
-
fallbackModelId,
|
|
11046
|
-
reason: capacityAdmission.reason
|
|
11047
|
-
});
|
|
11048
|
-
return null;
|
|
11049
|
-
}
|
|
11050
|
-
logger15.warn("\u4E91\u7AEF\u9650\u989D\u964D\u7EA7\uFF08run \u5185\u7EED\u8DD1\uFF09", {
|
|
11051
|
-
activeModelId,
|
|
11052
|
-
fallbackModelId,
|
|
11053
|
-
reason: error.message
|
|
11054
|
-
});
|
|
11055
|
-
fallbackObserver?.onCloudQuotaFallbackApplied?.(fallbackModelId);
|
|
11056
|
-
return fallbackModelId;
|
|
11057
|
-
}
|
|
11058
10905
|
|
|
11059
10906
|
// src/runtime-kernel/llm/usage-telemetry.ts
|
|
11060
10907
|
async function callPlainCompletion(inferencePort, modelId, messages, options = {}, signal, traceId) {
|
|
@@ -11157,7 +11004,7 @@ async function runLlmInputPreflight(params) {
|
|
|
11157
11004
|
}
|
|
11158
11005
|
|
|
11159
11006
|
// src/runtime-kernel/llm/retry-fallback.ts
|
|
11160
|
-
var
|
|
11007
|
+
var logger15 = new Logger("LlmCaller");
|
|
11161
11008
|
async function callWithRetryFallback(params) {
|
|
11162
11009
|
const {
|
|
11163
11010
|
deps,
|
|
@@ -11185,11 +11032,9 @@ async function callWithRetryFallback(params) {
|
|
|
11185
11032
|
const retryEpisode = new LlmRetryEpisode(traceId, eventHandler);
|
|
11186
11033
|
let previousAttemptTracker;
|
|
11187
11034
|
if (!clientRetryEnabled) {
|
|
11188
|
-
|
|
11189
|
-
logger16.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
11035
|
+
logger15.debug("\u5BA2\u6237\u7AEF\u91CD\u8BD5\u5DF2\u7981\u7528", {
|
|
11190
11036
|
modelId,
|
|
11191
|
-
|
|
11192
|
-
reason: options.retry_policy === "none" ? "options.retry_policy=none" : "model config (cloud billing or enable_client_retry=false)"
|
|
11037
|
+
reason: options.retry_policy === "none" ? "options.retry_policy=none" : "model config enable_client_retry=false"
|
|
11193
11038
|
});
|
|
11194
11039
|
}
|
|
11195
11040
|
try {
|
|
@@ -11225,7 +11070,7 @@ async function callWithRetryFallback(params) {
|
|
|
11225
11070
|
}) : void 0;
|
|
11226
11071
|
try {
|
|
11227
11072
|
if (isRetry) {
|
|
11228
|
-
|
|
11073
|
+
logger15.info("LLM \u8C03\u7528\u91CD\u8BD5", { attempt, configuredMaxRetries });
|
|
11229
11074
|
}
|
|
11230
11075
|
actualAttempts++;
|
|
11231
11076
|
retryEpisode.retrying(actualAttempts);
|
|
@@ -11254,7 +11099,7 @@ async function callWithRetryFallback(params) {
|
|
|
11254
11099
|
if (deps.retryConfig.enableEmptyResponseRetry && !responseContent?.trim() && !toolCallsFromLLM?.length) {
|
|
11255
11100
|
throw new Error("LLM\u8FD4\u56DE\u4E86\u7A7A\u54CD\u5E94");
|
|
11256
11101
|
}
|
|
11257
|
-
|
|
11102
|
+
logger15.debug("LLM \u8C03\u7528\u6210\u529F", { attempts: actualAttempts, maxTotalAttempts });
|
|
11258
11103
|
if (attemptContextUsage) {
|
|
11259
11104
|
fallbackObserver?.onLlmAttemptSucceeded?.(activeModelId, attemptContextUsage);
|
|
11260
11105
|
} else {
|
|
@@ -11265,7 +11110,7 @@ async function callWithRetryFallback(params) {
|
|
|
11265
11110
|
} catch (error) {
|
|
11266
11111
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
11267
11112
|
if (lastError.name === "AbortError") {
|
|
11268
|
-
|
|
11113
|
+
logger15.info("LLM \u8C03\u7528\u5DF2\u53D6\u6D88\uFF0C\u4E0D\u8FDB\u5165 provider failure \u5206\u7C7B\u4E0E\u91CD\u8BD5\u6D41\u7A0B", {
|
|
11269
11114
|
attempt: attempt + 1,
|
|
11270
11115
|
actualAttempts,
|
|
11271
11116
|
maxTotalAttempts,
|
|
@@ -11284,7 +11129,7 @@ async function callWithRetryFallback(params) {
|
|
|
11284
11129
|
total_attempts: actualAttempts,
|
|
11285
11130
|
error_code: classification.errorCode
|
|
11286
11131
|
};
|
|
11287
|
-
|
|
11132
|
+
logger15.error("LLM \u8C03\u7528\u5931\u8D25", {
|
|
11288
11133
|
attempt: attempt + 1,
|
|
11289
11134
|
maxAttempts: currentMaxRetries + 1,
|
|
11290
11135
|
actualAttempts,
|
|
@@ -11293,7 +11138,7 @@ async function callWithRetryFallback(params) {
|
|
|
11293
11138
|
});
|
|
11294
11139
|
previousAttemptTracker = attemptTracker;
|
|
11295
11140
|
if (!hasLlmAttemptBudgetRemaining({ actualAttempts, maxTotalAttempts })) {
|
|
11296
|
-
|
|
11141
|
+
logger15.error("\u5DF2\u8FBE\u5230 LLM \u603B\u8C03\u7528\u6B21\u6570\u4E0A\u9650\uFF0C\u505C\u6B62\u91CD\u8BD5/\u5207\u6A21\u578B", {
|
|
11297
11142
|
actualAttempts,
|
|
11298
11143
|
maxTotalAttempts
|
|
11299
11144
|
});
|
|
@@ -11323,37 +11168,15 @@ async function callWithRetryFallback(params) {
|
|
|
11323
11168
|
attempt -= 1;
|
|
11324
11169
|
continue;
|
|
11325
11170
|
}
|
|
11326
|
-
const quotaFallbackModelId = tryCloudQuotaFallback({
|
|
11327
|
-
deps,
|
|
11328
|
-
activeModelId,
|
|
11329
|
-
options,
|
|
11330
|
-
excludedModelIds,
|
|
11331
|
-
requirement,
|
|
11332
|
-
error: lastError,
|
|
11333
|
-
fallbackObserver,
|
|
11334
|
-
evaluateFallbackPromptCapacity: invocationContext?.evaluateFallbackPromptCapacity
|
|
11335
|
-
});
|
|
11336
|
-
if (quotaFallbackModelId) {
|
|
11337
|
-
fallbackObserver?.onModelFallbackApplied?.({
|
|
11338
|
-
fromModelId: activeModelId,
|
|
11339
|
-
toModelId: quotaFallbackModelId,
|
|
11340
|
-
reason: lastError.message,
|
|
11341
|
-
policy: "cloud-quota"
|
|
11342
|
-
});
|
|
11343
|
-
activeModelId = quotaFallbackModelId;
|
|
11344
|
-
excludedModelIds.add(quotaFallbackModelId);
|
|
11345
|
-
attempt -= 1;
|
|
11346
|
-
continue;
|
|
11347
|
-
}
|
|
11348
11171
|
}
|
|
11349
11172
|
if (classification.category === "non_retryable" /* NON_RETRYABLE */) {
|
|
11350
|
-
|
|
11173
|
+
logger15.error("\u9519\u8BEF\u4E0D\u53EF\u91CD\u8BD5\uFF0C\u76F4\u63A5\u5931\u8D25", { reason: classification.reason });
|
|
11351
11174
|
retryEpisode.finish("failed", failedRetryState);
|
|
11352
11175
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
11353
11176
|
throw lastError;
|
|
11354
11177
|
}
|
|
11355
11178
|
if (attempt >= configuredMaxRetries || categoryRetries[category] >= currentMaxRetries) {
|
|
11356
|
-
|
|
11179
|
+
logger15.error("\u5DF2\u8FBE\u5230\u6700\u5927\u91CD\u8BD5\u6B21\u6570\uFF0C\u653E\u5F03\u91CD\u8BD5", { maxRetries: currentMaxRetries });
|
|
11357
11180
|
retryEpisode.finish("exhausted", failedRetryState);
|
|
11358
11181
|
emitFinalError(eventHandler, pendingErrorEvent, lastError, classification, retryEpisode.activeId);
|
|
11359
11182
|
throw lastError;
|
|
@@ -11365,9 +11188,9 @@ async function callWithRetryFallback(params) {
|
|
|
11365
11188
|
6e4
|
|
11366
11189
|
);
|
|
11367
11190
|
if (classification.category === "rate_limit" /* RATE_LIMIT */) {
|
|
11368
|
-
|
|
11191
|
+
logger15.warn("\u901F\u7387\u9650\u5236\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
11369
11192
|
} else if (classification.category === "retryable" /* RETRYABLE */) {
|
|
11370
|
-
|
|
11193
|
+
logger15.warn("\u53EF\u91CD\u8BD5\u9519\u8BEF\uFF0C\u5EF6\u8FDF\u540E\u91CD\u8BD5", { retryDelay, reason: classification.reason });
|
|
11371
11194
|
}
|
|
11372
11195
|
throwIfAborted(signal, "\u5EF6\u8FDF\u7B49\u5F85\u524D\u68C0\u6D4B\u5230\u53D6\u6D88\u4FE1\u53F7\uFF0C\u505C\u6B62\u91CD\u8BD5");
|
|
11373
11196
|
categoryRetries[category] += 1;
|
|
@@ -11404,16 +11227,11 @@ function waitForRetry(delayMs, signal) {
|
|
|
11404
11227
|
}
|
|
11405
11228
|
function isClientRetryEnabledForModel(modelCatalog, modelId, options) {
|
|
11406
11229
|
if (options.retry_policy === "none") return false;
|
|
11407
|
-
|
|
11408
|
-
if (cfg?.billing_mode === "cloud") return false;
|
|
11409
|
-
if (options.retry_policy === "client") return true;
|
|
11410
|
-
if (!cfg) return true;
|
|
11411
|
-
if (cfg.enable_client_retry === false) return false;
|
|
11412
|
-
return true;
|
|
11230
|
+
return modelCatalog.getModelById(modelId)?.enable_client_retry !== false;
|
|
11413
11231
|
}
|
|
11414
11232
|
function throwIfAborted(signal, message) {
|
|
11415
11233
|
if (!signal?.aborted) return;
|
|
11416
|
-
|
|
11234
|
+
logger15.info(message);
|
|
11417
11235
|
const reason = signal.reason;
|
|
11418
11236
|
if (reason instanceof Error && reason.name === "AbortError") throw reason;
|
|
11419
11237
|
const reasonText = typeof reason === "string" && reason.trim().length > 0 ? reason : "stream_interrupted";
|
|
@@ -12096,7 +11914,7 @@ function runMetaFromRecord(record) {
|
|
|
12096
11914
|
}
|
|
12097
11915
|
|
|
12098
11916
|
// src/runtime-kernel/run-supervisor/functions/awaitingUserWatcher.ts
|
|
12099
|
-
var
|
|
11917
|
+
var logger17 = new Logger("RunSupervisorAwaitingUserWatcher");
|
|
12100
11918
|
function isRecord16(value) {
|
|
12101
11919
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12102
11920
|
}
|
|
@@ -12141,7 +11959,7 @@ function createAwaitingUserWatcher(options) {
|
|
|
12141
11959
|
resumeToken: event.resume_token
|
|
12142
11960
|
}
|
|
12143
11961
|
}).catch((error) => {
|
|
12144
|
-
|
|
11962
|
+
logger17.warn("failed to mark awaiting_user from requires_user_interaction", { error });
|
|
12145
11963
|
});
|
|
12146
11964
|
};
|
|
12147
11965
|
const dispose = () => {
|