@linnlabs/linnkit 0.8.0 → 0.9.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 +18 -0
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/dist/cli.cjs +118 -28
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +118 -28
- package/dist/cli.js.map +1 -1
- package/dist/context-manager.cjs +0 -4
- package/dist/context-manager.cjs.map +1 -1
- package/dist/context-manager.js +0 -4
- package/dist/context-manager.js.map +1 -1
- package/dist/{index-Cm-JbzTH.d.cts → index-BanRABEt.d.cts} +14 -3
- package/dist/{index-DRBWi1fy.d.ts → index-Z8NXKNwI.d.ts} +14 -3
- package/dist/index.cjs +146 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +146 -30
- package/dist/index.js.map +1 -1
- package/dist/quickstart.cjs +115 -25
- package/dist/quickstart.cjs.map +1 -1
- package/dist/quickstart.js +115 -25
- package/dist/quickstart.js.map +1 -1
- package/dist/runtime-kernel.cjs +142 -26
- package/dist/runtime-kernel.cjs.map +1 -1
- package/dist/runtime-kernel.d.cts +1 -1
- package/dist/runtime-kernel.d.ts +1 -1
- package/dist/runtime-kernel.js +140 -27
- package/dist/runtime-kernel.js.map +1 -1
- package/dist/testkit.cjs +155 -39
- package/dist/testkit.cjs.map +1 -1
- package/dist/testkit.js +155 -39
- package/dist/testkit.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AnswerNode, a as AuditEnvelopePersistenceError, B as BUILTIN_SYSTEM_REMINDER_TEMPLATES, b as BUILTIN_SYSTEM_REMINDER_TRIGGERS, C as CompositeAuditOptions, c as CompositeAuditPort, d as ConsoleAuditOptions, e as ContextCheckpointPayload, f as ContextCheckpointPayloadExtension, g as ContextCheckpointTool, h as ContextCheckpointToolArgs, j as ContextCheckpointToolHookParams, k as ContextCheckpointToolOptions, D as DefaultTokenizerPort, l as DefaultTokenizerPortConfig, E as ENGINE_ERROR_CODES, m as EmitAuditEnvelopeParams, n as EnrichmentContext, o as EnrichmentResult, p as ErrorClassification, q as EventBusSubRunTracePublisher, r as EventStoreAuditOptions, s as EventStoreAuditPort, F as FileAuditOptions, t as FileAuditPort, G as GraphAgentExecutor, u as GraphAgentExecutorDependencies, v as GraphExecutorContextBuildInput, w as GraphExecutorContextBuildOutput, x as GraphExecutorContextBuilder, L as LLMPolicyEngine, y as LlmNode, M as MemoryCheckpointer, P as PendingContextRuntimeEvent, R as RegistryEnrichmentResult, z as RequestEnricher, S as SYSTEM_REMINDER_RULES, H as SystemReminderContentTemplate, I as SystemReminderContext, J as SystemReminderRegistry, K as SystemReminderRule, N as SystemReminderRuleDefinition, O as SystemReminderTriggerEvaluator, T as ToolNode, U as UserNode, W as WaitUserNode, Q as agentHasToolTrigger, V as
|
|
1
|
+
export { A as AnswerNode, a as AuditEnvelopePersistenceError, B as BUILTIN_SYSTEM_REMINDER_TEMPLATES, b as BUILTIN_SYSTEM_REMINDER_TRIGGERS, C as CompositeAuditOptions, c as CompositeAuditPort, d as ConsoleAuditOptions, e as ContextCheckpointPayload, f as ContextCheckpointPayloadExtension, g as ContextCheckpointTool, h as ContextCheckpointToolArgs, j as ContextCheckpointToolHookParams, k as ContextCheckpointToolOptions, D as DefaultTokenizerPort, l as DefaultTokenizerPortConfig, E as ENGINE_ERROR_CODES, m as EmitAuditEnvelopeParams, n as EnrichmentContext, o as EnrichmentResult, p as ErrorClassification, q as EventBusSubRunTracePublisher, r as EventStoreAuditOptions, s as EventStoreAuditPort, F as FileAuditOptions, t as FileAuditPort, G as GraphAgentExecutor, u as GraphAgentExecutorDependencies, v as GraphExecutorContextBuildInput, w as GraphExecutorContextBuildOutput, x as GraphExecutorContextBuilder, L as LLMPolicyEngine, y as LlmNode, M as MemoryCheckpointer, P as PendingContextRuntimeEvent, R as RegistryEnrichmentResult, z as RequestEnricher, S as SYSTEM_REMINDER_RULES, H as SystemReminderContentTemplate, I as SystemReminderContext, J as SystemReminderRegistry, K as SystemReminderRule, N as SystemReminderRuleDefinition, O as SystemReminderTriggerEvaluator, T as ToolNode, U as UserNode, W as WaitUserNode, Q as agentHasToolTrigger, V as appendStreamingProviderReasoningDetails, X as applySystemReminders, Y as audit, Z as budgetWarningTrigger, _ as childRunTrace, $ as childRuns, a0 as compactProviderReasoningDetails, a1 as compactReasoningDetailsInValue, a2 as consoleAudit, a3 as contextBudgetWarningTemplate, a4 as countToolCallsInCurrentRequest, a5 as createCompositeAudit, a6 as createConsoleAudit, a7 as createContextCheckpointTool, a8 as createDefaultSystemReminderRegistry, a9 as createDefaultTokenizerPort, aa as createEventStoreAudit, ab as createFileAudit, ac as createSystemReminderRules, ad as defaultPolicyEngine, ae as defaultSystemReminderRegistry, af as emitAuditEnvelope, ag as emitSandboxDecisionAudit, ah as enrichment, ai as ensureToolContextRuntimeCapability, aj as execution, ak as getToolContextRuntimeBinding, al as graph, am as lastStepsHintTemplate, an as llm, ao as maxStepsForceFinalAnswerTemplate, ap as noopAudit, aq as normalizeToolArgs, ar as periodicTaskstateReflectionTemplate, as as phaseEqualsTrigger, at as readContextCheckpointToolName, au as readNonEmptyStrings, av as readToolContextPersistedHistory, aw as readToolContextWorkingHistory, ax as remainingStepsLeqTrigger, ay as requestEnricherRegistry, az as runContext, aA as runSupervisor, aB as stepCountModuloTrigger, aC as stripRuntimeReservedToolContextPatch, aD as systemReminder, aE as telemetry, aF as toDisplayStep, aG as toolCallStreakTemplate, aH as toolCallStreakTrigger, aI as tools } from './index-BanRABEt.cjs';
|
|
2
2
|
export { i as events } from './index-DO4dQgf2.cjs';
|
|
3
3
|
export { l as CheckpointListFilter, k as CheckpointMeta, m as CheckpointSummary, C as Checkpointer, P as DefaultGraphExecutorOptions, n as ENGINE_STATE_SCHEMA_VERSION, j as EngineState, E as ExecutorLocalState, o as GraphExecutor, Q as GraphLoopHarness, U as GraphLoopHarnessOptions, V as GraphLoopHarnessRunResult, W as GraphLoopLlmNodeFactoryParams, G as GraphNode, a as LLMPolicy, e as LLMPolicyErrorDecision, d as LLMPolicyMatchContext, b as LLMPolicyRequestContext, c as LLMPolicyResponseContext, f as LlmCaller, p as MemoryEventStore, M as ModelCatalogEntry, g as ModelCatalogLike, h as ModelResolver, q as ToolContextPatch, X as createDefaultGraphExecutor, Y as createGraphLoopHarness, s as summarizeCheckpoint } from './defaultGraphExecutor-BIjJj7WF.cjs';
|
|
4
4
|
export { A as AgentTool, B as BaseTool, C as CommonParameterTypes, J as JsonObjectSchema, O as OpenAIToolSchema, S as StructuredToolResult, s as SubRunTracePublisher, a as ToolArgs, e as ToolCallResult, f as ToolContextCompatibilityFields, d as ToolContextConversationView, g as ToolControlInfo, h as ToolDisplayOptions, T as ToolExecutionContext, i as ToolLayoutOptions, c as ToolParameterProperty, b as ToolParameterSchema, j as ToolRegistryEntry, k as ToolResult, U as UnifiedToolResult, l as computeToolIdempotencyKey, m as findCachedToolOutputByIdempotencyKey, r as readToolContextModelId, n as readToolContextRunContext, o as readToolContextUserQuery } from './toolContracts-CLkQmhTG.cjs';
|
package/dist/runtime-kernel.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AnswerNode, a as AuditEnvelopePersistenceError, B as BUILTIN_SYSTEM_REMINDER_TEMPLATES, b as BUILTIN_SYSTEM_REMINDER_TRIGGERS, C as CompositeAuditOptions, c as CompositeAuditPort, d as ConsoleAuditOptions, e as ContextCheckpointPayload, f as ContextCheckpointPayloadExtension, g as ContextCheckpointTool, h as ContextCheckpointToolArgs, j as ContextCheckpointToolHookParams, k as ContextCheckpointToolOptions, D as DefaultTokenizerPort, l as DefaultTokenizerPortConfig, E as ENGINE_ERROR_CODES, m as EmitAuditEnvelopeParams, n as EnrichmentContext, o as EnrichmentResult, p as ErrorClassification, q as EventBusSubRunTracePublisher, r as EventStoreAuditOptions, s as EventStoreAuditPort, F as FileAuditOptions, t as FileAuditPort, G as GraphAgentExecutor, u as GraphAgentExecutorDependencies, v as GraphExecutorContextBuildInput, w as GraphExecutorContextBuildOutput, x as GraphExecutorContextBuilder, L as LLMPolicyEngine, y as LlmNode, M as MemoryCheckpointer, P as PendingContextRuntimeEvent, R as RegistryEnrichmentResult, z as RequestEnricher, S as SYSTEM_REMINDER_RULES, H as SystemReminderContentTemplate, I as SystemReminderContext, J as SystemReminderRegistry, K as SystemReminderRule, N as SystemReminderRuleDefinition, O as SystemReminderTriggerEvaluator, T as ToolNode, U as UserNode, W as WaitUserNode, Q as agentHasToolTrigger, V as
|
|
1
|
+
export { A as AnswerNode, a as AuditEnvelopePersistenceError, B as BUILTIN_SYSTEM_REMINDER_TEMPLATES, b as BUILTIN_SYSTEM_REMINDER_TRIGGERS, C as CompositeAuditOptions, c as CompositeAuditPort, d as ConsoleAuditOptions, e as ContextCheckpointPayload, f as ContextCheckpointPayloadExtension, g as ContextCheckpointTool, h as ContextCheckpointToolArgs, j as ContextCheckpointToolHookParams, k as ContextCheckpointToolOptions, D as DefaultTokenizerPort, l as DefaultTokenizerPortConfig, E as ENGINE_ERROR_CODES, m as EmitAuditEnvelopeParams, n as EnrichmentContext, o as EnrichmentResult, p as ErrorClassification, q as EventBusSubRunTracePublisher, r as EventStoreAuditOptions, s as EventStoreAuditPort, F as FileAuditOptions, t as FileAuditPort, G as GraphAgentExecutor, u as GraphAgentExecutorDependencies, v as GraphExecutorContextBuildInput, w as GraphExecutorContextBuildOutput, x as GraphExecutorContextBuilder, L as LLMPolicyEngine, y as LlmNode, M as MemoryCheckpointer, P as PendingContextRuntimeEvent, R as RegistryEnrichmentResult, z as RequestEnricher, S as SYSTEM_REMINDER_RULES, H as SystemReminderContentTemplate, I as SystemReminderContext, J as SystemReminderRegistry, K as SystemReminderRule, N as SystemReminderRuleDefinition, O as SystemReminderTriggerEvaluator, T as ToolNode, U as UserNode, W as WaitUserNode, Q as agentHasToolTrigger, V as appendStreamingProviderReasoningDetails, X as applySystemReminders, Y as audit, Z as budgetWarningTrigger, _ as childRunTrace, $ as childRuns, a0 as compactProviderReasoningDetails, a1 as compactReasoningDetailsInValue, a2 as consoleAudit, a3 as contextBudgetWarningTemplate, a4 as countToolCallsInCurrentRequest, a5 as createCompositeAudit, a6 as createConsoleAudit, a7 as createContextCheckpointTool, a8 as createDefaultSystemReminderRegistry, a9 as createDefaultTokenizerPort, aa as createEventStoreAudit, ab as createFileAudit, ac as createSystemReminderRules, ad as defaultPolicyEngine, ae as defaultSystemReminderRegistry, af as emitAuditEnvelope, ag as emitSandboxDecisionAudit, ah as enrichment, ai as ensureToolContextRuntimeCapability, aj as execution, ak as getToolContextRuntimeBinding, al as graph, am as lastStepsHintTemplate, an as llm, ao as maxStepsForceFinalAnswerTemplate, ap as noopAudit, aq as normalizeToolArgs, ar as periodicTaskstateReflectionTemplate, as as phaseEqualsTrigger, at as readContextCheckpointToolName, au as readNonEmptyStrings, av as readToolContextPersistedHistory, aw as readToolContextWorkingHistory, ax as remainingStepsLeqTrigger, ay as requestEnricherRegistry, az as runContext, aA as runSupervisor, aB as stepCountModuloTrigger, aC as stripRuntimeReservedToolContextPatch, aD as systemReminder, aE as telemetry, aF as toDisplayStep, aG as toolCallStreakTemplate, aH as toolCallStreakTrigger, aI as tools } from './index-Z8NXKNwI.js';
|
|
2
2
|
export { i as events } from './index-CJeWHopy.js';
|
|
3
3
|
export { l as CheckpointListFilter, k as CheckpointMeta, m as CheckpointSummary, C as Checkpointer, P as DefaultGraphExecutorOptions, n as ENGINE_STATE_SCHEMA_VERSION, j as EngineState, E as ExecutorLocalState, o as GraphExecutor, Q as GraphLoopHarness, U as GraphLoopHarnessOptions, V as GraphLoopHarnessRunResult, W as GraphLoopLlmNodeFactoryParams, G as GraphNode, a as LLMPolicy, e as LLMPolicyErrorDecision, d as LLMPolicyMatchContext, b as LLMPolicyRequestContext, c as LLMPolicyResponseContext, f as LlmCaller, p as MemoryEventStore, M as ModelCatalogEntry, g as ModelCatalogLike, h as ModelResolver, q as ToolContextPatch, X as createDefaultGraphExecutor, Y as createGraphLoopHarness, s as summarizeCheckpoint } from './defaultGraphExecutor-BBswR8wn.js';
|
|
4
4
|
export { A as AgentTool, B as BaseTool, C as CommonParameterTypes, J as JsonObjectSchema, O as OpenAIToolSchema, S as StructuredToolResult, s as SubRunTracePublisher, a as ToolArgs, e as ToolCallResult, f as ToolContextCompatibilityFields, d as ToolContextConversationView, g as ToolControlInfo, h as ToolDisplayOptions, T as ToolExecutionContext, i as ToolLayoutOptions, c as ToolParameterProperty, b as ToolParameterSchema, j as ToolRegistryEntry, k as ToolResult, U as UnifiedToolResult, l as computeToolIdempotencyKey, m as findCachedToolOutputByIdempotencyKey, r as readToolContextModelId, n as readToolContextRunContext, o as readToolContextUserQuery } from './toolContracts-Blll0241.js';
|
package/dist/runtime-kernel.js
CHANGED
|
@@ -40,7 +40,6 @@ var Logger = class {
|
|
|
40
40
|
constructor(moduleName) {
|
|
41
41
|
this.moduleName = moduleName;
|
|
42
42
|
}
|
|
43
|
-
moduleName;
|
|
44
43
|
debug(message, data) {
|
|
45
44
|
this.log(0 /* DEBUG */, "debug", message, data);
|
|
46
45
|
}
|
|
@@ -1028,7 +1027,6 @@ var GraphExecutor = class {
|
|
|
1028
1027
|
};
|
|
1029
1028
|
this.telemetryPort = config.telemetryPort ?? noopTelemetry;
|
|
1030
1029
|
}
|
|
1031
|
-
checkpointer;
|
|
1032
1030
|
nodes = /* @__PURE__ */ new Map();
|
|
1033
1031
|
ephemeralLocals = /* @__PURE__ */ new Map();
|
|
1034
1032
|
config;
|
|
@@ -4421,6 +4419,22 @@ var ToolNode = class {
|
|
|
4421
4419
|
});
|
|
4422
4420
|
}
|
|
4423
4421
|
async run(state) {
|
|
4422
|
+
const events = [];
|
|
4423
|
+
while (true) {
|
|
4424
|
+
const result = await this.runNextPendingToolCall(state);
|
|
4425
|
+
if (Array.isArray(result.events) && result.events.length > 0) {
|
|
4426
|
+
events.push(...result.events);
|
|
4427
|
+
}
|
|
4428
|
+
if (result.kind === "route" && result.nextNodeId === "tool") {
|
|
4429
|
+
continue;
|
|
4430
|
+
}
|
|
4431
|
+
return {
|
|
4432
|
+
...result,
|
|
4433
|
+
events
|
|
4434
|
+
};
|
|
4435
|
+
}
|
|
4436
|
+
}
|
|
4437
|
+
async runNextPendingToolCall(state) {
|
|
4424
4438
|
const calls = state.local?.pendingToolCalls ?? [];
|
|
4425
4439
|
const signalRaw = state.local?.signal;
|
|
4426
4440
|
if (isAbortSignal(signalRaw) && signalRaw.aborted) {
|
|
@@ -4628,18 +4642,25 @@ var ToolNode = class {
|
|
|
4628
4642
|
rawArguments: context.call.function?.arguments,
|
|
4629
4643
|
parsedArguments: context.toolArgs
|
|
4630
4644
|
});
|
|
4645
|
+
const remainingCalls = context.calls.slice(1);
|
|
4631
4646
|
context.state.local = buildErrorLocalState({
|
|
4632
4647
|
local: context.local,
|
|
4633
|
-
remainingCalls
|
|
4648
|
+
remainingCalls,
|
|
4634
4649
|
conversationId: context.conversationId,
|
|
4635
4650
|
turnId: context.turnId,
|
|
4636
4651
|
runtimeEvents: context.bridge.getRuntimeEvents(),
|
|
4637
4652
|
nextProtocolErrorCount: fuse.nextCount
|
|
4638
4653
|
});
|
|
4639
|
-
if (fuse.shouldFuse) {
|
|
4654
|
+
if (fuse.shouldFuse && remainingCalls.length === 0) {
|
|
4640
4655
|
throw createToolProtocolFuseError(fuse.nextCount, context.exec.error);
|
|
4641
4656
|
}
|
|
4642
|
-
return {
|
|
4657
|
+
return {
|
|
4658
|
+
kind: "route",
|
|
4659
|
+
// 同一个 assistant.tool_calls batch 必须为每个 call 产出 tool_output。
|
|
4660
|
+
// 出错时也继续消费剩余 call,ToolNode.run 会在本节点内 drain 完 batch 再回 LLM。
|
|
4661
|
+
nextNodeId: remainingCalls.length > 0 ? "tool" : "llm",
|
|
4662
|
+
events: context.bridge.getRuntimeEvents()
|
|
4663
|
+
};
|
|
4643
4664
|
}
|
|
4644
4665
|
};
|
|
4645
4666
|
|
|
@@ -5376,18 +5397,18 @@ function createClassification(category, reason, suggestedDelay, extras) {
|
|
|
5376
5397
|
}
|
|
5377
5398
|
var ErrorClassifier = class {
|
|
5378
5399
|
static classify(error, context) {
|
|
5379
|
-
const
|
|
5400
|
+
const isRecord24 = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
5380
5401
|
const baseMsg = (error.message || "").toLowerCase();
|
|
5381
5402
|
const causeMsg = (() => {
|
|
5382
5403
|
const cause = error.cause;
|
|
5383
5404
|
if (typeof cause === "string") return cause.toLowerCase();
|
|
5384
5405
|
if (cause instanceof Error) return (cause.message || "").toLowerCase();
|
|
5385
|
-
if (
|
|
5406
|
+
if (isRecord24(cause) && typeof cause["message"] === "string") return String(cause["message"]).toLowerCase();
|
|
5386
5407
|
return "";
|
|
5387
5408
|
})();
|
|
5388
5409
|
const causeCode = (() => {
|
|
5389
5410
|
const cause = error.cause;
|
|
5390
|
-
if (
|
|
5411
|
+
if (isRecord24(cause) && typeof cause["code"] === "string") return String(cause["code"]);
|
|
5391
5412
|
return "";
|
|
5392
5413
|
})();
|
|
5393
5414
|
const errorMessage = `${baseMsg} ${causeMsg}`.trim();
|
|
@@ -5879,6 +5900,9 @@ __export(llm_exports, {
|
|
|
5879
5900
|
LLMPolicyEngine: () => LLMPolicyEngine,
|
|
5880
5901
|
LlmCaller: () => LlmCaller,
|
|
5881
5902
|
ModelResolver: () => ModelResolver,
|
|
5903
|
+
appendStreamingProviderReasoningDetails: () => appendStreamingProviderReasoningDetails,
|
|
5904
|
+
compactProviderReasoningDetails: () => compactProviderReasoningDetails,
|
|
5905
|
+
compactReasoningDetailsInValue: () => compactReasoningDetailsInValue,
|
|
5882
5906
|
createDefaultTokenizerPort: () => createDefaultTokenizerPort,
|
|
5883
5907
|
defaultPolicyEngine: () => defaultPolicyEngine
|
|
5884
5908
|
});
|
|
@@ -6268,6 +6292,90 @@ function assertToolCallsHaveValidJsonArguments(toolCalls) {
|
|
|
6268
6292
|
}
|
|
6269
6293
|
}
|
|
6270
6294
|
|
|
6295
|
+
// src/runtime-kernel/llm/reasoning-details.ts
|
|
6296
|
+
var mergeableTextFields = ["reasoning_content"];
|
|
6297
|
+
function isRecord20(value) {
|
|
6298
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
6299
|
+
}
|
|
6300
|
+
function findMergeableTextField(detail) {
|
|
6301
|
+
if (!isRecord20(detail)) return void 0;
|
|
6302
|
+
if (typeof detail.provider !== "string") return void 0;
|
|
6303
|
+
if (typeof detail.type !== "string") return void 0;
|
|
6304
|
+
for (const field of mergeableTextFields) {
|
|
6305
|
+
if (typeof detail[field] === "string") {
|
|
6306
|
+
return field;
|
|
6307
|
+
}
|
|
6308
|
+
}
|
|
6309
|
+
return void 0;
|
|
6310
|
+
}
|
|
6311
|
+
function hasOnlyStableTextDetailFields(detail, textField) {
|
|
6312
|
+
const allowedKeys = /* @__PURE__ */ new Set(["provider", "type", textField]);
|
|
6313
|
+
return Object.keys(detail).every((key) => allowedKeys.has(key));
|
|
6314
|
+
}
|
|
6315
|
+
function canMergeTextDetails(previous, incoming) {
|
|
6316
|
+
if (!isRecord20(previous) || !isRecord20(incoming)) return false;
|
|
6317
|
+
const previousField = findMergeableTextField(previous);
|
|
6318
|
+
const incomingField = findMergeableTextField(incoming);
|
|
6319
|
+
if (!previousField || previousField !== incomingField) return false;
|
|
6320
|
+
return previous.provider === incoming.provider && previous.type === incoming.type && hasOnlyStableTextDetailFields(previous, previousField) && hasOnlyStableTextDetailFields(incoming, incomingField);
|
|
6321
|
+
}
|
|
6322
|
+
function mergeStreamingText(previous, incoming) {
|
|
6323
|
+
if (!previous) return incoming;
|
|
6324
|
+
if (!incoming) return previous;
|
|
6325
|
+
if (incoming.startsWith(previous)) {
|
|
6326
|
+
return incoming;
|
|
6327
|
+
}
|
|
6328
|
+
if (previous.endsWith(incoming)) {
|
|
6329
|
+
return previous;
|
|
6330
|
+
}
|
|
6331
|
+
return `${previous}${incoming}`;
|
|
6332
|
+
}
|
|
6333
|
+
function appendStreamingProviderReasoningDetails(existing, incoming) {
|
|
6334
|
+
const next = [...existing];
|
|
6335
|
+
for (const detail of incoming) {
|
|
6336
|
+
const previous = next[next.length - 1];
|
|
6337
|
+
if (canMergeTextDetails(previous, detail)) {
|
|
6338
|
+
const textField = findMergeableTextField(previous);
|
|
6339
|
+
if (textField && isRecord20(detail)) {
|
|
6340
|
+
const mergedText = mergeStreamingText(String(previous[textField]), String(detail[textField]));
|
|
6341
|
+
if (mergedText === previous[textField]) {
|
|
6342
|
+
continue;
|
|
6343
|
+
}
|
|
6344
|
+
next[next.length - 1] = {
|
|
6345
|
+
...previous,
|
|
6346
|
+
[textField]: mergedText
|
|
6347
|
+
};
|
|
6348
|
+
continue;
|
|
6349
|
+
}
|
|
6350
|
+
}
|
|
6351
|
+
next.push(detail);
|
|
6352
|
+
}
|
|
6353
|
+
return next;
|
|
6354
|
+
}
|
|
6355
|
+
function compactProviderReasoningDetails(reasoningDetails) {
|
|
6356
|
+
return appendStreamingProviderReasoningDetails([], reasoningDetails);
|
|
6357
|
+
}
|
|
6358
|
+
function compactReasoningDetailsInValue(value) {
|
|
6359
|
+
return compactValue(value);
|
|
6360
|
+
}
|
|
6361
|
+
function compactValue(value) {
|
|
6362
|
+
if (Array.isArray(value)) {
|
|
6363
|
+
return value.map((item) => compactValue(item));
|
|
6364
|
+
}
|
|
6365
|
+
if (!isRecord20(value)) {
|
|
6366
|
+
return value;
|
|
6367
|
+
}
|
|
6368
|
+
const compacted = {};
|
|
6369
|
+
for (const [key, childValue] of Object.entries(value)) {
|
|
6370
|
+
if (key === "reasoning_details" && Array.isArray(childValue)) {
|
|
6371
|
+
compacted[key] = compactProviderReasoningDetails(childValue);
|
|
6372
|
+
continue;
|
|
6373
|
+
}
|
|
6374
|
+
compacted[key] = compactValue(childValue);
|
|
6375
|
+
}
|
|
6376
|
+
return compacted;
|
|
6377
|
+
}
|
|
6378
|
+
|
|
6271
6379
|
// src/runtime-kernel/llm/streaming-adapter.ts
|
|
6272
6380
|
async function callLlmStream(params) {
|
|
6273
6381
|
const {
|
|
@@ -6280,7 +6388,7 @@ async function callLlmStream(params) {
|
|
|
6280
6388
|
} = params;
|
|
6281
6389
|
let fullResponse = "";
|
|
6282
6390
|
let streamError = null;
|
|
6283
|
-
|
|
6391
|
+
let reasoningDetails = [];
|
|
6284
6392
|
const streamAnswerId = generateMessageId();
|
|
6285
6393
|
let streamChunkSeq = 0;
|
|
6286
6394
|
let capturedUsage = void 0;
|
|
@@ -6350,13 +6458,21 @@ async function callLlmStream(params) {
|
|
|
6350
6458
|
const reasoning = isRecord19(chunk) ? chunk["reasoning_details"] : void 0;
|
|
6351
6459
|
if (reasoning !== void 0) {
|
|
6352
6460
|
const newReasoningDetails = Array.isArray(reasoning) ? reasoning : [reasoning];
|
|
6353
|
-
reasoningDetails
|
|
6354
|
-
|
|
6355
|
-
|
|
6356
|
-
|
|
6357
|
-
|
|
6358
|
-
|
|
6359
|
-
|
|
6461
|
+
const previousReasoningDetails = reasoningDetails;
|
|
6462
|
+
const previousLength = previousReasoningDetails.length;
|
|
6463
|
+
const compactedReasoningDetails = appendStreamingProviderReasoningDetails(reasoningDetails, newReasoningDetails);
|
|
6464
|
+
reasoningDetails = compactedReasoningDetails;
|
|
6465
|
+
const previousLastChanged = previousLength > 0 && compactedReasoningDetails[previousLength - 1] !== previousReasoningDetails[previousLength - 1];
|
|
6466
|
+
const emitFromIndex = previousLastChanged ? previousLength - 1 : previousLength;
|
|
6467
|
+
const emittedReasoningDetails = compactedReasoningDetails.slice(Math.max(0, emitFromIndex));
|
|
6468
|
+
if (emittedReasoningDetails.length > 0) {
|
|
6469
|
+
eventHandler({
|
|
6470
|
+
type: "provider_sidecar",
|
|
6471
|
+
id: generateMessageId(),
|
|
6472
|
+
timestamp: Date.now(),
|
|
6473
|
+
reasoning_details: emittedReasoningDetails
|
|
6474
|
+
});
|
|
6475
|
+
}
|
|
6360
6476
|
}
|
|
6361
6477
|
if (chunk.tool_calls) {
|
|
6362
6478
|
emitThoughtComplete(thoughtSegmenter.onBoundary());
|
|
@@ -6782,7 +6898,6 @@ var DefaultTokenizerPort = class {
|
|
|
6782
6898
|
constructor(config = {}) {
|
|
6783
6899
|
this.config = config;
|
|
6784
6900
|
}
|
|
6785
|
-
config;
|
|
6786
6901
|
estimateText(text, _modelId) {
|
|
6787
6902
|
return TokenCalculator.estimateTokens(text, {
|
|
6788
6903
|
encoding: this.config.encoding,
|
|
@@ -6924,8 +7039,6 @@ var FinalAnswerCollector = class {
|
|
|
6924
7039
|
this.conversationId = conversationId;
|
|
6925
7040
|
this.turnId = turnId;
|
|
6926
7041
|
}
|
|
6927
|
-
conversationId;
|
|
6928
|
-
turnId;
|
|
6929
7042
|
answerId;
|
|
6930
7043
|
chunks = [];
|
|
6931
7044
|
chunkCount = 0;
|
|
@@ -6973,7 +7086,7 @@ var FinalAnswerCollector = class {
|
|
|
6973
7086
|
};
|
|
6974
7087
|
|
|
6975
7088
|
// src/runtime-kernel/child-runs/childRunTraceSink.ts
|
|
6976
|
-
function
|
|
7089
|
+
function isRecord21(v) {
|
|
6977
7090
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
6978
7091
|
}
|
|
6979
7092
|
function getString2(obj, key) {
|
|
@@ -7006,7 +7119,7 @@ function createChildRunTraceSink(params) {
|
|
|
7006
7119
|
const { publisher, conversationId, turnId } = params;
|
|
7007
7120
|
const finalAnswerCollector = new FinalAnswerCollector(conversationId, turnId);
|
|
7008
7121
|
const sink = (evt) => {
|
|
7009
|
-
if (!
|
|
7122
|
+
if (!isRecord21(evt)) {
|
|
7010
7123
|
return [];
|
|
7011
7124
|
}
|
|
7012
7125
|
const type = getString2(evt, "type");
|
|
@@ -7675,7 +7788,7 @@ function runRecordToMeta(record) {
|
|
|
7675
7788
|
errorIfAny: record.errorIfAny ? { ...record.errorIfAny } : void 0
|
|
7676
7789
|
};
|
|
7677
7790
|
}
|
|
7678
|
-
function
|
|
7791
|
+
function isRecord22(value) {
|
|
7679
7792
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7680
7793
|
}
|
|
7681
7794
|
function readStringField(record, key) {
|
|
@@ -7696,7 +7809,7 @@ function getRunIdFromMetadata(event) {
|
|
|
7696
7809
|
return snakeCaseRunId;
|
|
7697
7810
|
}
|
|
7698
7811
|
const runContext = metadata["run_context"];
|
|
7699
|
-
if (
|
|
7812
|
+
if (isRecord22(runContext)) {
|
|
7700
7813
|
return readStringField(runContext, "runId") ?? readStringField(runContext, "run_id");
|
|
7701
7814
|
}
|
|
7702
7815
|
return void 0;
|
|
@@ -7914,7 +8027,7 @@ function runMetaFromRecord(record) {
|
|
|
7914
8027
|
}
|
|
7915
8028
|
|
|
7916
8029
|
// src/runtime-kernel/run-supervisor/runSupervisor.ts
|
|
7917
|
-
function
|
|
8030
|
+
function isRecord23(value) {
|
|
7918
8031
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7919
8032
|
}
|
|
7920
8033
|
function readStringField2(record, key) {
|
|
@@ -7931,7 +8044,7 @@ function readRunIdFromRuntimeEvent(event) {
|
|
|
7931
8044
|
return directRunId;
|
|
7932
8045
|
}
|
|
7933
8046
|
const runContext = metadata["run_context"];
|
|
7934
|
-
if (!
|
|
8047
|
+
if (!isRecord23(runContext)) {
|
|
7935
8048
|
return void 0;
|
|
7936
8049
|
}
|
|
7937
8050
|
return readStringField2(runContext, "runId") ?? readStringField2(runContext, "run_id");
|
|
@@ -7943,7 +8056,7 @@ function readAwaitingUserReason(event) {
|
|
|
7943
8056
|
if (typeof event.prompt === "string" && event.prompt.trim().length > 0) {
|
|
7944
8057
|
return event.prompt;
|
|
7945
8058
|
}
|
|
7946
|
-
if (
|
|
8059
|
+
if (isRecord23(event.form)) {
|
|
7947
8060
|
const prompt = readStringField2(event.form, "prompt");
|
|
7948
8061
|
if (prompt && prompt.trim().length > 0) {
|
|
7949
8062
|
return prompt;
|
|
@@ -8563,6 +8676,6 @@ function createGraphLoopHarness(options) {
|
|
|
8563
8676
|
};
|
|
8564
8677
|
}
|
|
8565
8678
|
|
|
8566
|
-
export { AnswerNode, AuditEnvelopePersistenceError, BUILTIN_SYSTEM_REMINDER_TEMPLATES, BUILTIN_SYSTEM_REMINDER_TRIGGERS, BaseTool, CommonParameterTypes, CompositeAuditPort, ContextCheckpointTool, DEFAULT_CONTEXT_CHECKPOINT_TOOL_NAME, DefaultTokenizerPort, ENGINE_ERROR_CODES, ENGINE_STATE_SCHEMA_VERSION, EventBusSubRunTracePublisher, EventStoreAuditPort, FileAuditPort, GraphAgentExecutor, GraphExecutor, LLMPolicyEngine, LlmCaller, LlmNode, MemoryCheckpointer, MemoryEventStore, ModelResolver, SYSTEM_REMINDER_RULES, SystemReminderRegistry, ToolNode, UserNode, WaitUserNode, agentHasToolTrigger, applySystemReminders, audit_exports as audit, budgetWarningTrigger, child_run_trace_exports as childRunTrace, child_runs_exports as childRuns, computeToolIdempotencyKey, consoleAudit, contextBudgetWarningTemplate, countToolCallsInCurrentRequest, createCompositeAudit, createConsoleAudit, createContextCheckpointTool, createDefaultGraphExecutor, createDefaultSystemReminderRegistry, createDefaultTokenizerPort, createEventStoreAudit, createFileAudit, createGraphLoopHarness, createMonotonicEventIdFactory, createSystemReminderRules, defaultPolicyEngine, defaultSystemReminderRegistry, emitAuditEnvelope, emitSandboxDecisionAudit, enrichment_exports as enrichment, ensureToolContextRuntimeCapability, events_exports as events, execution_exports as execution, findCachedToolOutputByIdempotencyKey, getToolContextRuntimeBinding, graph_engine_exports as graph, lastStepsHintTemplate, llm_exports as llm, maxStepsForceFinalAnswerTemplate, noopAudit, normalizeToolArgs, periodicTaskstateReflectionTemplate, phaseEqualsTrigger, readContextCheckpointToolName, readNonEmptyStrings, readToolContextModelId, readToolContextPersistedHistory, readToolContextRunContext, readToolContextUserQuery, readToolContextWorkingHistory, remainingStepsLeqTrigger, requestEnricherRegistry, run_context_exports as runContext, run_supervisor_exports as runSupervisor, stepCountModuloTrigger, stripRuntimeReservedToolContextPatch, summarizeCheckpoint, system_reminder_exports as systemReminder, telemetry_exports as telemetry, toDisplayStep, toolCallStreakTemplate, toolCallStreakTrigger, tools_exports as tools };
|
|
8679
|
+
export { AnswerNode, AuditEnvelopePersistenceError, BUILTIN_SYSTEM_REMINDER_TEMPLATES, BUILTIN_SYSTEM_REMINDER_TRIGGERS, BaseTool, CommonParameterTypes, CompositeAuditPort, ContextCheckpointTool, DEFAULT_CONTEXT_CHECKPOINT_TOOL_NAME, DefaultTokenizerPort, ENGINE_ERROR_CODES, ENGINE_STATE_SCHEMA_VERSION, EventBusSubRunTracePublisher, EventStoreAuditPort, FileAuditPort, GraphAgentExecutor, GraphExecutor, LLMPolicyEngine, LlmCaller, LlmNode, MemoryCheckpointer, MemoryEventStore, ModelResolver, SYSTEM_REMINDER_RULES, SystemReminderRegistry, ToolNode, UserNode, WaitUserNode, agentHasToolTrigger, appendStreamingProviderReasoningDetails, applySystemReminders, audit_exports as audit, budgetWarningTrigger, child_run_trace_exports as childRunTrace, child_runs_exports as childRuns, compactProviderReasoningDetails, compactReasoningDetailsInValue, computeToolIdempotencyKey, consoleAudit, contextBudgetWarningTemplate, countToolCallsInCurrentRequest, createCompositeAudit, createConsoleAudit, createContextCheckpointTool, createDefaultGraphExecutor, createDefaultSystemReminderRegistry, createDefaultTokenizerPort, createEventStoreAudit, createFileAudit, createGraphLoopHarness, createMonotonicEventIdFactory, createSystemReminderRules, defaultPolicyEngine, defaultSystemReminderRegistry, emitAuditEnvelope, emitSandboxDecisionAudit, enrichment_exports as enrichment, ensureToolContextRuntimeCapability, events_exports as events, execution_exports as execution, findCachedToolOutputByIdempotencyKey, getToolContextRuntimeBinding, graph_engine_exports as graph, lastStepsHintTemplate, llm_exports as llm, maxStepsForceFinalAnswerTemplate, noopAudit, normalizeToolArgs, periodicTaskstateReflectionTemplate, phaseEqualsTrigger, readContextCheckpointToolName, readNonEmptyStrings, readToolContextModelId, readToolContextPersistedHistory, readToolContextRunContext, readToolContextUserQuery, readToolContextWorkingHistory, remainingStepsLeqTrigger, requestEnricherRegistry, run_context_exports as runContext, run_supervisor_exports as runSupervisor, stepCountModuloTrigger, stripRuntimeReservedToolContextPatch, summarizeCheckpoint, system_reminder_exports as systemReminder, telemetry_exports as telemetry, toDisplayStep, toolCallStreakTemplate, toolCallStreakTrigger, tools_exports as tools };
|
|
8567
8680
|
//# sourceMappingURL=runtime-kernel.js.map
|
|
8568
8681
|
//# sourceMappingURL=runtime-kernel.js.map
|