@linnlabs/linnkit 0.42.0 → 0.44.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.
Files changed (75) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/dist/cli.cjs +113 -5
  3. package/dist/cli.cjs.map +1 -1
  4. package/dist/cli.js +113 -5
  5. package/dist/cli.js.map +1 -1
  6. package/dist/context-manager/profiles/agent/context/config.d.cts +1 -1
  7. package/dist/context-manager/profiles/agent/context/config.d.ts +1 -1
  8. package/dist/context-manager.cjs +37 -4
  9. package/dist/context-manager.cjs.map +1 -1
  10. package/dist/context-manager.js +37 -4
  11. package/dist/context-manager.js.map +1 -1
  12. package/dist/contracts/events.d.cts +4 -0
  13. package/dist/contracts/events.d.ts +4 -0
  14. package/dist/contracts/messages.d.cts +226 -2
  15. package/dist/contracts/messages.d.ts +226 -2
  16. package/dist/contracts/sse.d.cts +65 -1
  17. package/dist/contracts/sse.d.ts +65 -1
  18. package/dist/contracts.cjs +19 -2
  19. package/dist/contracts.cjs.map +1 -1
  20. package/dist/contracts.d.cts +1 -1
  21. package/dist/contracts.d.ts +1 -1
  22. package/dist/contracts.js +19 -3
  23. package/dist/contracts.js.map +1 -1
  24. package/dist/index.cjs +115 -5
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.js +115 -5
  27. package/dist/index.js.map +1 -1
  28. package/dist/quickstart.cjs +113 -5
  29. package/dist/quickstart.cjs.map +1 -1
  30. package/dist/quickstart.js +113 -5
  31. package/dist/quickstart.js.map +1 -1
  32. package/dist/runtime-kernel/events.cjs +29 -2
  33. package/dist/runtime-kernel/events.cjs.map +1 -1
  34. package/dist/runtime-kernel/events.js +29 -2
  35. package/dist/runtime-kernel/events.js.map +1 -1
  36. package/dist/runtime-kernel/graph-engine/definitions/pendingUserInput.d.cts +27 -0
  37. package/dist/runtime-kernel/graph-engine/definitions/pendingUserInput.d.ts +27 -0
  38. package/dist/runtime-kernel/graph-engine/engine.d.cts +2 -1
  39. package/dist/runtime-kernel/graph-engine/engine.d.ts +2 -1
  40. package/dist/runtime-kernel/graph-engine/index.d.cts +1 -0
  41. package/dist/runtime-kernel/graph-engine/index.d.ts +1 -0
  42. package/dist/runtime-kernel/graph-engine/types.d.cts +3 -0
  43. package/dist/runtime-kernel/graph-engine/types.d.ts +3 -0
  44. package/dist/runtime-kernel.cjs +113 -5
  45. package/dist/runtime-kernel.cjs.map +1 -1
  46. package/dist/runtime-kernel.d.cts +1 -0
  47. package/dist/runtime-kernel.d.ts +1 -0
  48. package/dist/runtime-kernel.js +113 -5
  49. package/dist/runtime-kernel.js.map +1 -1
  50. package/dist/testkit/agent-harness/scriptedInferenceHarness.d.cts +24 -6
  51. package/dist/testkit/agent-harness/scriptedInferenceHarness.d.ts +24 -6
  52. package/dist/testkit/scenario/graphScenario.d.cts +89 -0
  53. package/dist/testkit/scenario/graphScenario.d.ts +89 -0
  54. package/dist/testkit/scenario/pendingUserInputQueue.d.cts +26 -0
  55. package/dist/testkit/scenario/pendingUserInputQueue.d.ts +26 -0
  56. package/dist/testkit/scenario/runtimeEventRecorder.d.cts +36 -0
  57. package/dist/testkit/scenario/runtimeEventRecorder.d.ts +36 -0
  58. package/dist/testkit/scenario/scriptedToolRuntime.d.cts +51 -0
  59. package/dist/testkit/scenario/scriptedToolRuntime.d.ts +51 -0
  60. package/dist/testkit/scenario/steeringInvariants.d.cts +33 -0
  61. package/dist/testkit/scenario/steeringInvariants.d.ts +33 -0
  62. package/dist/testkit/scenario/timeline.d.cts +27 -0
  63. package/dist/testkit/scenario/timeline.d.ts +27 -0
  64. package/dist/testkit.cjs +683 -18
  65. package/dist/testkit.cjs.map +1 -1
  66. package/dist/testkit.d.cts +7 -1
  67. package/dist/testkit.d.ts +7 -1
  68. package/dist/testkit.js +675 -19
  69. package/dist/testkit.js.map +1 -1
  70. package/docs/integration/README.md +1 -0
  71. package/docs/integration/mid-run-user-input.md +73 -0
  72. package/docs/integration/realtime.md +4 -0
  73. package/docs/integration/testing.md +40 -4
  74. package/docs/integration/tool-development-guide.md +1 -0
  75. package/package.json +2 -2
@@ -0,0 +1,27 @@
1
+ /**
2
+ * 运行中途由 Host 交给 Graph 的用户输入(插话)。
3
+ *
4
+ * `id` 直接成为送达后 `user_input` 事实的事件身份:同一条插话因提交失败被重新取用时,
5
+ * 事件身份不变,Host 可以据此去重。
6
+ */
7
+ interface PendingUserInput {
8
+ readonly id: string;
9
+ readonly content: string;
10
+ readonly timestamp?: number;
11
+ }
12
+ /**
13
+ * 运行中插话的 Host 端口(可选运行能力,不进入 checkpoint)。
14
+ *
15
+ * Graph 只在一批工具全部结算、即将回到模型时取用:
16
+ * - `claim` 取走当前待送达的输入;在 `confirm` 前这些条目仍归 Host 所有,不得被撤回后又送达。
17
+ * - 边界提交成功后调用 `confirm`;提交失败调用 `release`,条目回到待送达。
18
+ *
19
+ * 没有装配该端口的 Host 行为不变。子运行不接收插话。
20
+ */
21
+ interface PendingUserInputPort {
22
+ claim(): Promise<readonly PendingUserInput[]> | readonly PendingUserInput[];
23
+ confirm(ids: readonly string[]): Promise<void> | void;
24
+ release(ids: readonly string[]): Promise<void> | void;
25
+ }
26
+
27
+ export type { PendingUserInput, PendingUserInputPort };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * 运行中途由 Host 交给 Graph 的用户输入(插话)。
3
+ *
4
+ * `id` 直接成为送达后 `user_input` 事实的事件身份:同一条插话因提交失败被重新取用时,
5
+ * 事件身份不变,Host 可以据此去重。
6
+ */
7
+ interface PendingUserInput {
8
+ readonly id: string;
9
+ readonly content: string;
10
+ readonly timestamp?: number;
11
+ }
12
+ /**
13
+ * 运行中插话的 Host 端口(可选运行能力,不进入 checkpoint)。
14
+ *
15
+ * Graph 只在一批工具全部结算、即将回到模型时取用:
16
+ * - `claim` 取走当前待送达的输入;在 `confirm` 前这些条目仍归 Host 所有,不得被撤回后又送达。
17
+ * - 边界提交成功后调用 `confirm`;提交失败调用 `release`,条目回到待送达。
18
+ *
19
+ * 没有装配该端口的 Host 行为不变。子运行不接收插话。
20
+ */
21
+ interface PendingUserInputPort {
22
+ claim(): Promise<readonly PendingUserInput[]> | readonly PendingUserInput[];
23
+ confirm(ids: readonly string[]): Promise<void> | void;
24
+ release(ids: readonly string[]): Promise<void> | void;
25
+ }
26
+
27
+ export type { PendingUserInput, PendingUserInputPort };
@@ -12,6 +12,7 @@ type GraphRunResult = {
12
12
  interface GraphResumeSessionInput {
13
13
  expectedRevision: number;
14
14
  localPatch: Record<string, unknown>;
15
+ /** 恢复后的起点。省略时:同批还有未执行的工具调用则先回 tool,否则 llm;有未执行调用时只接受 tool。 */
15
16
  nodeId?: string;
16
17
  expectedNodeId?: string;
17
18
  /** 本次 session execution 使用的步数预算;未传时沿用已持久化预算或 executor 默认值。 */
@@ -33,7 +34,7 @@ interface GraphExecutorConfig {
33
34
  interface GraphContinuationInput {
34
35
  readonly expectedRevision: number;
35
36
  /** 只能重建运行能力,不能覆盖持久请求、历史、模型或预算。 */
36
- readonly capabilities: Pick<EngineLocalState, 'signal' | 'toolContext' | 'runtimeEventSink' | 'runtimeEventCommitPort' | 'runtimeFailureFactSink' | 'summarizationCallbacks' | 'toolRecoveryPort'>;
37
+ readonly capabilities: Pick<EngineLocalState, 'signal' | 'toolContext' | 'runtimeEventSink' | 'runtimeEventCommitPort' | 'runtimeFailureFactSink' | 'summarizationCallbacks' | 'toolRecoveryPort' | 'pendingUserInputPort'>;
37
38
  }
38
39
  declare class GraphExecutor {
39
40
  private readonly checkpointer;
@@ -12,6 +12,7 @@ type GraphRunResult = {
12
12
  interface GraphResumeSessionInput {
13
13
  expectedRevision: number;
14
14
  localPatch: Record<string, unknown>;
15
+ /** 恢复后的起点。省略时:同批还有未执行的工具调用则先回 tool,否则 llm;有未执行调用时只接受 tool。 */
15
16
  nodeId?: string;
16
17
  expectedNodeId?: string;
17
18
  /** 本次 session execution 使用的步数预算;未传时沿用已持久化预算或 executor 默认值。 */
@@ -33,7 +34,7 @@ interface GraphExecutorConfig {
33
34
  interface GraphContinuationInput {
34
35
  readonly expectedRevision: number;
35
36
  /** 只能重建运行能力,不能覆盖持久请求、历史、模型或预算。 */
36
- readonly capabilities: Pick<EngineLocalState, 'signal' | 'toolContext' | 'runtimeEventSink' | 'runtimeEventCommitPort' | 'runtimeFailureFactSink' | 'summarizationCallbacks' | 'toolRecoveryPort'>;
37
+ readonly capabilities: Pick<EngineLocalState, 'signal' | 'toolContext' | 'runtimeEventSink' | 'runtimeEventCommitPort' | 'runtimeFailureFactSink' | 'summarizationCallbacks' | 'toolRecoveryPort' | 'pendingUserInputPort'>;
37
38
  }
38
39
  declare class GraphExecutor {
39
40
  private readonly checkpointer;
@@ -17,4 +17,5 @@ export { parseEngineCheckpoint } from './functions/parseEngineCheckpoint.cjs';
17
17
  export { isRuntimeFailureFact } from './functions/runtimeFailureFact.cjs';
18
18
  export { ENGINE_STATE_SCHEMA_VERSION, EngineState, ExecutorLlmInvocationKind, ExecutorLocalPatch, ExecutorLocalState, GraphNode, RuntimeEventCommitPort, RuntimeEventSink, RuntimeFailureFact, RuntimeFailureFactSink, ToolBatchCompletionMode } from './types.cjs';
19
19
  export { ExecutionCheckpointPort, RunPauseRequested, RunRecoveryBlockedError, ToolRecoveryDecision, ToolRecoveryPort, isRunPauseSignal } from './definitions/runContinuation.cjs';
20
+ export { PendingUserInput, PendingUserInputPort } from './definitions/pendingUserInput.cjs';
20
21
  export { GraphContextCompactionCandidate, GraphExecutorContextApplyInput, GraphExecutorContextApplyOutput, GraphExecutorContextBuildInput, GraphExecutorContextBuildOutput, GraphExecutorContextBuilder, GraphExecutorOutputProcessor } from './executorContextBuilder.cjs';
@@ -17,4 +17,5 @@ export { parseEngineCheckpoint } from './functions/parseEngineCheckpoint.js';
17
17
  export { isRuntimeFailureFact } from './functions/runtimeFailureFact.js';
18
18
  export { ENGINE_STATE_SCHEMA_VERSION, EngineState, ExecutorLlmInvocationKind, ExecutorLocalPatch, ExecutorLocalState, GraphNode, RuntimeEventCommitPort, RuntimeEventSink, RuntimeFailureFact, RuntimeFailureFactSink, ToolBatchCompletionMode } from './types.js';
19
19
  export { ExecutionCheckpointPort, RunPauseRequested, RunRecoveryBlockedError, ToolRecoveryDecision, ToolRecoveryPort, isRunPauseSignal } from './definitions/runContinuation.js';
20
+ export { PendingUserInput, PendingUserInputPort } from './definitions/pendingUserInput.js';
20
21
  export { GraphContextCompactionCandidate, GraphExecutorContextApplyInput, GraphExecutorContextApplyOutput, GraphExecutorContextBuildInput, GraphExecutorContextBuildOutput, GraphExecutorContextBuilder, GraphExecutorOutputProcessor } from './executorContextBuilder.js';
@@ -1,5 +1,6 @@
1
1
  import { ToolExecutionContext } from '../tools/toolExecutionContext.cjs';
2
2
  import { ToolRecoveryPort } from './definitions/runContinuation.cjs';
3
+ import { PendingUserInputPort } from './definitions/pendingUserInput.cjs';
3
4
  import { RunId, ToolCallId } from '../../contracts/identity/definitions.cjs';
4
5
  import { AgentSpecSystemReminderPolicy, AgentSpecToolObservationGovernancePolicy } from '../../contracts/contextPolicy.cjs';
5
6
  import { RuntimeEvent, RoutedRuntimeEvent } from '../../contracts/events.cjs';
@@ -85,6 +86,8 @@ interface EngineLocalState extends Record<string, unknown> {
85
86
  /** Graph 注入的短提交边界,ToolNode 每个 call 前后复用;不序列化能力。 */
86
87
  commitExecutionBoundary?: (state: EngineState) => Promise<void>;
87
88
  toolRecoveryPort?: ToolRecoveryPort;
89
+ /** 运行中插话:一批工具结算完、回到模型前取用 Host 的待送达输入;不序列化能力。 */
90
+ pendingUserInputPort?: PendingUserInputPort;
88
91
  /** 意图已提交但结果未提交的原始 call;重启时必须经过工具 owner 对账。 */
89
92
  executingToolCallId?: ToolCallId;
90
93
  runtimeFailureFactSink?: RuntimeFailureFactSink;
@@ -1,5 +1,6 @@
1
1
  import { ToolExecutionContext } from '../tools/toolExecutionContext.js';
2
2
  import { ToolRecoveryPort } from './definitions/runContinuation.js';
3
+ import { PendingUserInputPort } from './definitions/pendingUserInput.js';
3
4
  import { RunId, ToolCallId } from '../../contracts/identity/definitions.js';
4
5
  import { AgentSpecSystemReminderPolicy, AgentSpecToolObservationGovernancePolicy } from '../../contracts/contextPolicy.js';
5
6
  import { RuntimeEvent, RoutedRuntimeEvent } from '../../contracts/events.js';
@@ -85,6 +86,8 @@ interface EngineLocalState extends Record<string, unknown> {
85
86
  /** Graph 注入的短提交边界,ToolNode 每个 call 前后复用;不序列化能力。 */
86
87
  commitExecutionBoundary?: (state: EngineState) => Promise<void>;
87
88
  toolRecoveryPort?: ToolRecoveryPort;
89
+ /** 运行中插话:一批工具结算完、回到模型前取用 Host 的待送达输入;不序列化能力。 */
90
+ pendingUserInputPort?: PendingUserInputPort;
88
91
  /** 意图已提交但结果未提交的原始 call;重启时必须经过工具 owner 对账。 */
89
92
  executingToolCallId?: ToolCallId;
90
93
  runtimeFailureFactSink?: RuntimeFailureFactSink;
@@ -902,6 +902,10 @@ var UserInputMessage = BaseMessage.extend({
902
902
  type: zod.z.literal("user_input"),
903
903
  attachments: RuntimeResourceRefs.optional()
904
904
  });
905
+ var UserSteerMessage = BaseMessage.extend({
906
+ role: zod.z.literal("user"),
907
+ type: zod.z.literal("user_steer")
908
+ });
905
909
  var UserContextMessage = BaseMessage.extend({
906
910
  role: zod.z.literal("user"),
907
911
  // 产品上下文种类由 Host fence metadata 表达,不进入框架消息枚举。
@@ -910,7 +914,7 @@ var UserContextMessage = BaseMessage.extend({
910
914
  "task_request"
911
915
  ])
912
916
  });
913
- var UserMessage = zod.z.union([UserInputMessage, UserContextMessage]);
917
+ var UserMessage = zod.z.union([UserInputMessage, UserSteerMessage, UserContextMessage]);
914
918
  var AssistantMessage = BaseMessage.extend({
915
919
  role: zod.z.literal("assistant"),
916
920
  type: zod.z.enum(["thought", "final_answer", "tool_code", "tool_calls", "task_completion"])
@@ -1512,7 +1516,12 @@ var RuntimeEventShape = zod.z.discriminatedUnion("type", [
1512
1516
  content: zod.z.string(),
1513
1517
  raw_content: zod.z.string().optional(),
1514
1518
  source: zod.z.enum(["user", "editor", "system"]).default("user"),
1515
- attachments: RuntimeResourceRefs.optional()
1519
+ attachments: RuntimeResourceRefs.optional(),
1520
+ /**
1521
+ * 运行中途送达的用户输入(插话)。缺省表示运行起点的输入。
1522
+ * 上下文里投影为 `user_steer`,不改变“当前轮从哪条 user_input 开始”的判定。
1523
+ */
1524
+ delivery: zod.z.literal("mid_run").optional()
1516
1525
  }),
1517
1526
  BaseEvent.extend({
1518
1527
  type: zod.z.literal("thought"),
@@ -1972,6 +1981,11 @@ zod.z.object({
1972
1981
  run_id: RunIdSchema,
1973
1982
  execution_id: ExecutionIdSchema
1974
1983
  });
1984
+ var SSEUserInputEvent = BaseSSEEvent.extend({
1985
+ type: zod.z.literal("user_input"),
1986
+ content: zod.z.string(),
1987
+ delivery: zod.z.literal("mid_run")
1988
+ });
1975
1989
  var SSEThoughtEvent = BaseSSEEvent.extend({
1976
1990
  type: zod.z.literal("thought"),
1977
1991
  thought_message_id: ThoughtMessageIdSchema.optional(),
@@ -2126,6 +2140,7 @@ var SSESummarizationErrorEvent = BaseSSEEvent.extend({
2126
2140
  error: zod.z.string()
2127
2141
  });
2128
2142
  zod.z.discriminatedUnion("type", [
2143
+ SSEUserInputEvent,
2129
2144
  SSEThoughtEvent,
2130
2145
  SSEFinalAnswerChunkEvent,
2131
2146
  SSEFinalAnswerResetEvent,
@@ -2448,6 +2463,7 @@ var NON_CHECKPOINT_LOCAL_KEYS = [
2448
2463
  "runtimeEventCommitPort",
2449
2464
  "commitExecutionBoundary",
2450
2465
  "toolRecoveryPort",
2466
+ "pendingUserInputPort",
2451
2467
  "runtimeFailureFactSink",
2452
2468
  "signal",
2453
2469
  "summarizationCallbacks",
@@ -3011,6 +3027,16 @@ function mergeResumeSessionLocal(persistedLocal, localPatch) {
3011
3027
  }
3012
3028
  };
3013
3029
  }
3030
+ function resolveResumeNodeId(local, requested) {
3031
+ const pending = local?.pendingToolCalls;
3032
+ if (!Array.isArray(pending) || pending.length === 0) return requested ?? "llm";
3033
+ if (requested !== void 0 && requested !== "tool") {
3034
+ throw new Error(
3035
+ `Graph resume must first run ${pending.length} pending tool call(s) from the interrupted batch: requested node=${requested}`
3036
+ );
3037
+ }
3038
+ return "tool";
3039
+ }
3014
3040
  var GraphExecutor = class {
3015
3041
  constructor(checkpointer, config = {}) {
3016
3042
  this.checkpointer = checkpointer;
@@ -3123,13 +3149,14 @@ var GraphExecutor = class {
3123
3149
  );
3124
3150
  }
3125
3151
  const resumedLocal = mergeResumeSessionLocal(current.local, input.localPatch);
3152
+ const nodeId = resolveResumeNodeId(resumedLocal, input.nodeId);
3126
3153
  if (this.executionCheckpointPort && current.local?.executorLocal) {
3127
3154
  resumedLocal.executorLocal = { ...current.local.executorLocal };
3128
3155
  }
3129
3156
  this.ephemeralLocals.set(checkpointKey, resumedLocal);
3130
3157
  await this.commitCheckpoint(checkpointKey, {
3131
3158
  ...current,
3132
- nodeId: input.nodeId ?? "llm",
3159
+ nodeId,
3133
3160
  ...this.executionCheckpointPort ? { executionStatus: "ready" } : {},
3134
3161
  revision: currentRevision + 1,
3135
3162
  local: sanitizeCheckpointLocal(resumedLocal)
@@ -6647,6 +6674,8 @@ function describeRuntimeEventLifecycle(event) {
6647
6674
  case "run_execution_metrics":
6648
6675
  case "history_summary":
6649
6676
  return "event_bus_sse";
6677
+ case "user_input":
6678
+ return event.type === "user_input" && event.delivery === "mid_run" ? "event_bus_sse" : "none";
6650
6679
  case "audit_envelope":
6651
6680
  return "none";
6652
6681
  default:
@@ -7090,6 +7119,16 @@ function requireEventTimestamp(value) {
7090
7119
  function applyRuntimeEventToMemory(event, memory) {
7091
7120
  switch (event.type) {
7092
7121
  case "user_input": {
7122
+ if (event.delivery === "mid_run") {
7123
+ memory.appendMessage({
7124
+ id: event.id,
7125
+ role: "user",
7126
+ type: "user_steer",
7127
+ content: event.content,
7128
+ timestamp: event.timestamp
7129
+ });
7130
+ break;
7131
+ }
7093
7132
  memory.addUserMessage(event.content, event.id, event.attachments);
7094
7133
  break;
7095
7134
  }
@@ -8797,6 +8836,62 @@ async function commitToolBoundary(state, result) {
8797
8836
  await state.local.commitExecutionBoundary(state);
8798
8837
  }
8799
8838
 
8839
+ // src/runtime-kernel/graph-engine/nodes/toolNode.pendingUserInput.ts
8840
+ function isPendingUserInputPort(value) {
8841
+ return !!value && typeof value === "object" && typeof Reflect.get(value, "claim") === "function" && typeof Reflect.get(value, "confirm") === "function" && typeof Reflect.get(value, "release") === "function";
8842
+ }
8843
+ function readRemainingSteps(state) {
8844
+ const value = state.local?.executorLocal?.remainingSteps;
8845
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
8846
+ }
8847
+ function readIdentity(value, field) {
8848
+ if (typeof value !== "string" || value.trim().length === 0) {
8849
+ throw new Error(`ToolNode pending user input requires ${field}`);
8850
+ }
8851
+ return value;
8852
+ }
8853
+ async function claimPendingUserInputs(state, result) {
8854
+ if (result.kind !== "route" || result.nextNodeId !== "llm") return void 0;
8855
+ const local = state.local;
8856
+ const port = local?.pendingUserInputPort;
8857
+ if (!isPendingUserInputPort(port)) return void 0;
8858
+ const signal = local?.signal;
8859
+ if (signal?.aborted || isRunPauseSignal(signal)) return void 0;
8860
+ const remainingSteps = readRemainingSteps(state);
8861
+ if (remainingSteps !== void 0 && remainingSteps < 1) return void 0;
8862
+ const inputs = await port.claim();
8863
+ if (inputs.length === 0) return void 0;
8864
+ const ids = inputs.map((input) => input.id);
8865
+ try {
8866
+ const conversationId = readIdentity(local?.conversationId, "conversationId");
8867
+ const turnId = readIdentity(local?.turnId, "turnId");
8868
+ const sink = requireRuntimeEventSink(local);
8869
+ const events = inputs.map((input) => sink(
8870
+ createUserInputEvent(readIdentity(input.id, "input id"), conversationId, turnId, input.content, {
8871
+ timestamp: input.timestamp ?? Date.now(),
8872
+ delivery: "mid_run"
8873
+ }),
8874
+ "ToolNode.pending_user_input"
8875
+ ));
8876
+ state.local = {
8877
+ ...state.local,
8878
+ history: appendWorkingHistory(parseRuntimeEvents(state.local?.history ?? []), events)
8879
+ };
8880
+ return {
8881
+ events,
8882
+ confirm: async () => {
8883
+ await port.confirm(ids);
8884
+ },
8885
+ release: async () => {
8886
+ await port.release(ids);
8887
+ }
8888
+ };
8889
+ } catch (error) {
8890
+ await port.release(ids);
8891
+ throw error;
8892
+ }
8893
+ }
8894
+
8800
8895
  // src/runtime-kernel/graph-engine/nodes/toolNode.ts
8801
8896
  var logger11 = new Logger("ToolNode");
8802
8897
  function isAbortSignal(value) {
@@ -8964,7 +9059,19 @@ var ToolNode = class {
8964
9059
  });
8965
9060
  throw result.error;
8966
9061
  }
8967
- await commitToolBoundary(state, result);
9062
+ const steering = await claimPendingUserInputs(state, result);
9063
+ if (steering) {
9064
+ result = { ...result, events: [...result.events ?? [], ...steering.events] };
9065
+ try {
9066
+ await commitToolBoundary(state, result);
9067
+ } catch (error) {
9068
+ await steering.release();
9069
+ throw error;
9070
+ }
9071
+ await steering.confirm();
9072
+ } else {
9073
+ await commitToolBoundary(state, result);
9074
+ }
8968
9075
  if (Array.isArray(result.events) && result.events.length > 0) {
8969
9076
  events.push(...result.events);
8970
9077
  }
@@ -9722,7 +9829,8 @@ function parseEngineCheckpoint(value) {
9722
9829
  "runtimeFailureFactSink",
9723
9830
  "summarizationCallbacks",
9724
9831
  "commitExecutionBoundary",
9725
- "toolRecoveryPort"
9832
+ "toolRecoveryPort",
9833
+ "pendingUserInputPort"
9726
9834
  ]) {
9727
9835
  if (result.local && Object.hasOwn(result.local, key)) {
9728
9836
  throw new Error(`Checkpoint must not contain execution capability: ${key}`);