@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.
@@ -3120,6 +3120,26 @@ function resolveAssistantReplayParts(response) {
3120
3120
  return response.assistant_replay_parts;
3121
3121
  }
3122
3122
 
3123
+ // src/runtime-kernel/graph-engine/definitions/runContinuation.ts
3124
+ var RunRecoveryBlockedError = class extends Error {
3125
+ code = "RUN_RECOVERY_BLOCKED";
3126
+ constructor(message) {
3127
+ super(message);
3128
+ this.name = "RunRecoveryBlockedError";
3129
+ }
3130
+ };
3131
+ var RunPauseRequested = class extends Error {
3132
+ code = "RUN_PAUSE_REQUESTED";
3133
+ constructor(message = "Run paused by user") {
3134
+ super(message);
3135
+ this.name = "RunPauseRequested";
3136
+ }
3137
+ };
3138
+ function isRunPauseSignal(signal) {
3139
+ const reason = signal?.reason;
3140
+ return signal?.aborted === true && typeof reason === "object" && reason !== null && "code" in reason && reason.code === "RUN_PAUSE_REQUESTED";
3141
+ }
3142
+
3123
3143
  // src/runtime-kernel/graph-engine/engine.ts
3124
3144
  var logger2 = new Logger("GraphExecutor");
3125
3145
  function isRecord4(value) {
@@ -3429,6 +3449,7 @@ var GraphExecutor = class {
3429
3449
  reportStepsUsed(stepCount);
3430
3450
  const signalRaw = state.local?.signal;
3431
3451
  if (isAbortSignal2(signalRaw) && signalRaw.aborted) {
3452
+ if (!isRunPauseSignal(signalRaw)) await this.nodes.get(state.nodeId)?.cancel?.(state);
3432
3453
  logger2.warn("[GraphExecutor] \u6536\u5230 AbortSignal\uFF0C\u7ACB\u5373\u505C\u6B62\u63A8\u7406\u5FAA\u73AF");
3433
3454
  this.ephemeralLocals.delete(checkpointKey);
3434
3455
  throwAbortError();
@@ -3479,6 +3500,12 @@ var GraphExecutor = class {
3479
3500
  allEvents.push(...stepResolution.events);
3480
3501
  }
3481
3502
  state = stepResolution.state;
3503
+ const completedSignal = state.local?.signal;
3504
+ if (isAbortSignal2(completedSignal) && completedSignal.aborted && !isRunPauseSignal(completedSignal)) {
3505
+ await this.nodes.get(state.nodeId)?.cancel?.(state);
3506
+ this.ephemeralLocals.delete(checkpointKey);
3507
+ throwAbortError();
3508
+ }
3482
3509
  if (stepResolution.action.kind === "route") {
3483
3510
  logger2.info("[GraphExecutor] \u8DEF\u7531\u5207\u6362", {
3484
3511
  fromNodeId: stepResolution.action.fromNodeId,
@@ -8409,26 +8436,6 @@ function buildCancelledToolBatchLocalState(local, runtimeEvents) {
8409
8436
  function recordToolProtocolError(params) {
8410
8437
  }
8411
8438
 
8412
- // src/runtime-kernel/graph-engine/definitions/runContinuation.ts
8413
- var RunRecoveryBlockedError = class extends Error {
8414
- code = "RUN_RECOVERY_BLOCKED";
8415
- constructor(message) {
8416
- super(message);
8417
- this.name = "RunRecoveryBlockedError";
8418
- }
8419
- };
8420
- var RunPauseRequested = class extends Error {
8421
- code = "RUN_PAUSE_REQUESTED";
8422
- constructor(message = "Run paused by user") {
8423
- super(message);
8424
- this.name = "RunPauseRequested";
8425
- }
8426
- };
8427
- function isRunPauseSignal(signal) {
8428
- const reason = signal?.reason;
8429
- return signal?.aborted === true && typeof reason === "object" && reason !== null && "code" in reason && reason.code === "RUN_PAUSE_REQUESTED";
8430
- }
8431
-
8432
8439
  // src/runtime-kernel/graph-engine/nodes/toolNode.recovery.ts
8433
8440
  async function executeRecoverableTool(input) {
8434
8441
  const local = input.state.local;
@@ -8630,7 +8637,30 @@ var ToolNode = class {
8630
8637
  async run(state) {
8631
8638
  const events = [];
8632
8639
  while (true) {
8633
- const result = await this.runNextPendingToolCall(state);
8640
+ let result;
8641
+ try {
8642
+ result = await this.runNextPendingToolCall(state);
8643
+ } catch (error) {
8644
+ if (isToolExecutionAbort(error) && !isRunPauseSignal(state.local?.signal)) {
8645
+ await this.cancel(state);
8646
+ }
8647
+ throw error;
8648
+ }
8649
+ const signal = state.local?.signal;
8650
+ if (isAbortSignal(signal) && signal.aborted && !isRunPauseSignal(signal)) {
8651
+ await this.cancel(state);
8652
+ const error = new Error("The user aborted a request.");
8653
+ error.name = "AbortError";
8654
+ throw error;
8655
+ }
8656
+ if (result.kind === "interrupted") {
8657
+ await commitToolBoundary(state, {
8658
+ kind: "route",
8659
+ nextNodeId: "llm",
8660
+ events: result.events
8661
+ });
8662
+ throw result.error;
8663
+ }
8634
8664
  await commitToolBoundary(state, result);
8635
8665
  if (Array.isArray(result.events) && result.events.length > 0) {
8636
8666
  events.push(...result.events);
@@ -8644,6 +8674,14 @@ var ToolNode = class {
8644
8674
  };
8645
8675
  }
8646
8676
  }
8677
+ async cancel(state) {
8678
+ settlePendingToolCallsAfterAbort({
8679
+ state,
8680
+ calls: parsePendingToolCalls(state.local?.pendingToolCalls ?? []),
8681
+ toolCatalog: this.toolRuntime
8682
+ });
8683
+ await commitToolBoundary(state, { kind: "yield"});
8684
+ }
8647
8685
  async runNextPendingToolCall(state) {
8648
8686
  const calls = parsePendingToolCalls(state.local?.pendingToolCalls ?? []);
8649
8687
  const signalRaw = state.local?.signal;
@@ -9063,7 +9101,11 @@ var ToolNode = class {
9063
9101
  nextProtocolErrorCount: fuse.nextCount
9064
9102
  });
9065
9103
  if (fuse.shouldFuse && remainingCalls.length === 0) {
9066
- throw createToolProtocolFuseError(fuse.nextCount, context.exec.error);
9104
+ return {
9105
+ kind: "interrupted",
9106
+ error: createToolProtocolFuseError(fuse.nextCount, context.exec.error),
9107
+ events: context.bridge.getRuntimeEvents()
9108
+ };
9067
9109
  }
9068
9110
  if (remainingCalls.length === 0 && context.local.toolBatchCompletionMode === "yield_after_batch") {
9069
9111
  return { kind: "yield", events: context.bridge.getRuntimeEvents() };