@linnlabs/linnkit 0.36.0 → 0.37.1

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/dist/index.js CHANGED
@@ -3899,6 +3899,26 @@ function resolveAssistantReplayParts(response) {
3899
3899
  return response.assistant_replay_parts;
3900
3900
  }
3901
3901
 
3902
+ // src/runtime-kernel/graph-engine/definitions/runContinuation.ts
3903
+ var RunRecoveryBlockedError = class extends Error {
3904
+ code = "RUN_RECOVERY_BLOCKED";
3905
+ constructor(message) {
3906
+ super(message);
3907
+ this.name = "RunRecoveryBlockedError";
3908
+ }
3909
+ };
3910
+ var RunPauseRequested = class extends Error {
3911
+ code = "RUN_PAUSE_REQUESTED";
3912
+ constructor(message = "Run paused by user") {
3913
+ super(message);
3914
+ this.name = "RunPauseRequested";
3915
+ }
3916
+ };
3917
+ function isRunPauseSignal(signal) {
3918
+ const reason = signal?.reason;
3919
+ return signal?.aborted === true && typeof reason === "object" && reason !== null && "code" in reason && reason.code === "RUN_PAUSE_REQUESTED";
3920
+ }
3921
+
3902
3922
  // src/runtime-kernel/graph-engine/engine.ts
3903
3923
  var logger2 = new Logger("GraphExecutor");
3904
3924
  function isRecord4(value) {
@@ -4208,6 +4228,7 @@ var GraphExecutor = class {
4208
4228
  reportStepsUsed(stepCount);
4209
4229
  const signalRaw = state.local?.signal;
4210
4230
  if (isAbortSignal2(signalRaw) && signalRaw.aborted) {
4231
+ if (!isRunPauseSignal(signalRaw)) await this.nodes.get(state.nodeId)?.cancel?.(state);
4211
4232
  logger2.warn("[GraphExecutor] \u6536\u5230 AbortSignal\uFF0C\u7ACB\u5373\u505C\u6B62\u63A8\u7406\u5FAA\u73AF");
4212
4233
  this.ephemeralLocals.delete(checkpointKey);
4213
4234
  throwAbortError();
@@ -4258,6 +4279,12 @@ var GraphExecutor = class {
4258
4279
  allEvents.push(...stepResolution.events);
4259
4280
  }
4260
4281
  state = stepResolution.state;
4282
+ const completedSignal = state.local?.signal;
4283
+ if (isAbortSignal2(completedSignal) && completedSignal.aborted && !isRunPauseSignal(completedSignal)) {
4284
+ await this.nodes.get(state.nodeId)?.cancel?.(state);
4285
+ this.ephemeralLocals.delete(checkpointKey);
4286
+ throwAbortError();
4287
+ }
4261
4288
  if (stepResolution.action.kind === "route") {
4262
4289
  logger2.info("[GraphExecutor] \u8DEF\u7531\u5207\u6362", {
4263
4290
  fromNodeId: stepResolution.action.fromNodeId,
@@ -9484,26 +9511,6 @@ function recordToolProtocolError(params) {
9484
9511
  recorder?.recordToolProtocolError?.(params);
9485
9512
  }
9486
9513
 
9487
- // src/runtime-kernel/graph-engine/definitions/runContinuation.ts
9488
- var RunRecoveryBlockedError = class extends Error {
9489
- code = "RUN_RECOVERY_BLOCKED";
9490
- constructor(message) {
9491
- super(message);
9492
- this.name = "RunRecoveryBlockedError";
9493
- }
9494
- };
9495
- var RunPauseRequested = class extends Error {
9496
- code = "RUN_PAUSE_REQUESTED";
9497
- constructor(message = "Run paused by user") {
9498
- super(message);
9499
- this.name = "RunPauseRequested";
9500
- }
9501
- };
9502
- function isRunPauseSignal(signal) {
9503
- const reason = signal?.reason;
9504
- return signal?.aborted === true && typeof reason === "object" && reason !== null && "code" in reason && reason.code === "RUN_PAUSE_REQUESTED";
9505
- }
9506
-
9507
9514
  // src/runtime-kernel/graph-engine/nodes/toolNode.recovery.ts
9508
9515
  async function executeRecoverableTool(input) {
9509
9516
  const local = input.state.local;
@@ -9705,7 +9712,30 @@ var ToolNode = class {
9705
9712
  async run(state) {
9706
9713
  const events = [];
9707
9714
  while (true) {
9708
- const result = await this.runNextPendingToolCall(state);
9715
+ let result;
9716
+ try {
9717
+ result = await this.runNextPendingToolCall(state);
9718
+ } catch (error) {
9719
+ if (isToolExecutionAbort(error) && !isRunPauseSignal(state.local?.signal)) {
9720
+ await this.cancel(state);
9721
+ }
9722
+ throw error;
9723
+ }
9724
+ const signal = state.local?.signal;
9725
+ if (isAbortSignal(signal) && signal.aborted && !isRunPauseSignal(signal)) {
9726
+ await this.cancel(state);
9727
+ const error = new Error("The user aborted a request.");
9728
+ error.name = "AbortError";
9729
+ throw error;
9730
+ }
9731
+ if (result.kind === "interrupted") {
9732
+ await commitToolBoundary(state, {
9733
+ kind: "route",
9734
+ nextNodeId: "llm",
9735
+ events: result.events
9736
+ });
9737
+ throw result.error;
9738
+ }
9709
9739
  await commitToolBoundary(state, result);
9710
9740
  if (Array.isArray(result.events) && result.events.length > 0) {
9711
9741
  events.push(...result.events);
@@ -9719,6 +9749,14 @@ var ToolNode = class {
9719
9749
  };
9720
9750
  }
9721
9751
  }
9752
+ async cancel(state) {
9753
+ settlePendingToolCallsAfterAbort({
9754
+ state,
9755
+ calls: parsePendingToolCalls(state.local?.pendingToolCalls ?? []),
9756
+ toolCatalog: this.toolRuntime
9757
+ });
9758
+ await commitToolBoundary(state, { kind: "yield"});
9759
+ }
9722
9760
  async runNextPendingToolCall(state) {
9723
9761
  const calls = parsePendingToolCalls(state.local?.pendingToolCalls ?? []);
9724
9762
  const signalRaw = state.local?.signal;
@@ -10138,7 +10176,11 @@ var ToolNode = class {
10138
10176
  nextProtocolErrorCount: fuse.nextCount
10139
10177
  });
10140
10178
  if (fuse.shouldFuse && remainingCalls.length === 0) {
10141
- throw createToolProtocolFuseError(fuse.nextCount, context.exec.error);
10179
+ return {
10180
+ kind: "interrupted",
10181
+ error: createToolProtocolFuseError(fuse.nextCount, context.exec.error),
10182
+ events: context.bridge.getRuntimeEvents()
10183
+ };
10142
10184
  }
10143
10185
  if (remainingCalls.length === 0 && context.local.toolBatchCompletionMode === "yield_after_batch") {
10144
10186
  return { kind: "yield", events: context.bridge.getRuntimeEvents() };