@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.
@@ -2909,6 +2909,26 @@ function resolveAssistantReplayParts(response) {
2909
2909
  return response.assistant_replay_parts;
2910
2910
  }
2911
2911
 
2912
+ // src/runtime-kernel/graph-engine/definitions/runContinuation.ts
2913
+ var RunRecoveryBlockedError = class extends Error {
2914
+ code = "RUN_RECOVERY_BLOCKED";
2915
+ constructor(message) {
2916
+ super(message);
2917
+ this.name = "RunRecoveryBlockedError";
2918
+ }
2919
+ };
2920
+ var RunPauseRequested = class extends Error {
2921
+ code = "RUN_PAUSE_REQUESTED";
2922
+ constructor(message = "Run paused by user") {
2923
+ super(message);
2924
+ this.name = "RunPauseRequested";
2925
+ }
2926
+ };
2927
+ function isRunPauseSignal(signal) {
2928
+ const reason = signal?.reason;
2929
+ return signal?.aborted === true && typeof reason === "object" && reason !== null && "code" in reason && reason.code === "RUN_PAUSE_REQUESTED";
2930
+ }
2931
+
2912
2932
  // src/runtime-kernel/graph-engine/engine.ts
2913
2933
  var logger2 = new Logger("GraphExecutor");
2914
2934
  function isRecord4(value) {
@@ -3218,6 +3238,7 @@ var GraphExecutor = class {
3218
3238
  reportStepsUsed(stepCount);
3219
3239
  const signalRaw = state.local?.signal;
3220
3240
  if (isAbortSignal2(signalRaw) && signalRaw.aborted) {
3241
+ if (!isRunPauseSignal(signalRaw)) await this.nodes.get(state.nodeId)?.cancel?.(state);
3221
3242
  logger2.warn("[GraphExecutor] \u6536\u5230 AbortSignal\uFF0C\u7ACB\u5373\u505C\u6B62\u63A8\u7406\u5FAA\u73AF");
3222
3243
  this.ephemeralLocals.delete(checkpointKey);
3223
3244
  throwAbortError();
@@ -3268,6 +3289,12 @@ var GraphExecutor = class {
3268
3289
  allEvents.push(...stepResolution.events);
3269
3290
  }
3270
3291
  state = stepResolution.state;
3292
+ const completedSignal = state.local?.signal;
3293
+ if (isAbortSignal2(completedSignal) && completedSignal.aborted && !isRunPauseSignal(completedSignal)) {
3294
+ await this.nodes.get(state.nodeId)?.cancel?.(state);
3295
+ this.ephemeralLocals.delete(checkpointKey);
3296
+ throwAbortError();
3297
+ }
3271
3298
  if (stepResolution.action.kind === "route") {
3272
3299
  logger2.info("[GraphExecutor] \u8DEF\u7531\u5207\u6362", {
3273
3300
  fromNodeId: stepResolution.action.fromNodeId,
@@ -8477,26 +8504,6 @@ function buildCancelledToolBatchLocalState(local, runtimeEvents) {
8477
8504
  function recordToolProtocolError(params) {
8478
8505
  }
8479
8506
 
8480
- // src/runtime-kernel/graph-engine/definitions/runContinuation.ts
8481
- var RunRecoveryBlockedError = class extends Error {
8482
- code = "RUN_RECOVERY_BLOCKED";
8483
- constructor(message) {
8484
- super(message);
8485
- this.name = "RunRecoveryBlockedError";
8486
- }
8487
- };
8488
- var RunPauseRequested = class extends Error {
8489
- code = "RUN_PAUSE_REQUESTED";
8490
- constructor(message = "Run paused by user") {
8491
- super(message);
8492
- this.name = "RunPauseRequested";
8493
- }
8494
- };
8495
- function isRunPauseSignal(signal) {
8496
- const reason = signal?.reason;
8497
- return signal?.aborted === true && typeof reason === "object" && reason !== null && "code" in reason && reason.code === "RUN_PAUSE_REQUESTED";
8498
- }
8499
-
8500
8507
  // src/runtime-kernel/graph-engine/nodes/toolNode.recovery.ts
8501
8508
  async function executeRecoverableTool(input) {
8502
8509
  const local = input.state.local;
@@ -8698,7 +8705,30 @@ var ToolNode = class {
8698
8705
  async run(state) {
8699
8706
  const events = [];
8700
8707
  while (true) {
8701
- const result = await this.runNextPendingToolCall(state);
8708
+ let result;
8709
+ try {
8710
+ result = await this.runNextPendingToolCall(state);
8711
+ } catch (error) {
8712
+ if (isToolExecutionAbort(error) && !isRunPauseSignal(state.local?.signal)) {
8713
+ await this.cancel(state);
8714
+ }
8715
+ throw error;
8716
+ }
8717
+ const signal = state.local?.signal;
8718
+ if (isAbortSignal(signal) && signal.aborted && !isRunPauseSignal(signal)) {
8719
+ await this.cancel(state);
8720
+ const error = new Error("The user aborted a request.");
8721
+ error.name = "AbortError";
8722
+ throw error;
8723
+ }
8724
+ if (result.kind === "interrupted") {
8725
+ await commitToolBoundary(state, {
8726
+ kind: "route",
8727
+ nextNodeId: "llm",
8728
+ events: result.events
8729
+ });
8730
+ throw result.error;
8731
+ }
8702
8732
  await commitToolBoundary(state, result);
8703
8733
  if (Array.isArray(result.events) && result.events.length > 0) {
8704
8734
  events.push(...result.events);
@@ -8712,6 +8742,14 @@ var ToolNode = class {
8712
8742
  };
8713
8743
  }
8714
8744
  }
8745
+ async cancel(state) {
8746
+ settlePendingToolCallsAfterAbort({
8747
+ state,
8748
+ calls: parsePendingToolCalls(state.local?.pendingToolCalls ?? []),
8749
+ toolCatalog: this.toolRuntime
8750
+ });
8751
+ await commitToolBoundary(state, { kind: "yield"});
8752
+ }
8715
8753
  async runNextPendingToolCall(state) {
8716
8754
  const calls = parsePendingToolCalls(state.local?.pendingToolCalls ?? []);
8717
8755
  const signalRaw = state.local?.signal;
@@ -9131,7 +9169,11 @@ var ToolNode = class {
9131
9169
  nextProtocolErrorCount: fuse.nextCount
9132
9170
  });
9133
9171
  if (fuse.shouldFuse && remainingCalls.length === 0) {
9134
- throw createToolProtocolFuseError(fuse.nextCount, context.exec.error);
9172
+ return {
9173
+ kind: "interrupted",
9174
+ error: createToolProtocolFuseError(fuse.nextCount, context.exec.error),
9175
+ events: context.bridge.getRuntimeEvents()
9176
+ };
9135
9177
  }
9136
9178
  if (remainingCalls.length === 0 && context.local.toolBatchCompletionMode === "yield_after_batch") {
9137
9179
  return { kind: "yield", events: context.bridge.getRuntimeEvents() };