@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/testkit.js CHANGED
@@ -3097,6 +3097,26 @@ function resolveAssistantReplayParts(response) {
3097
3097
  return response.assistant_replay_parts;
3098
3098
  }
3099
3099
 
3100
+ // src/runtime-kernel/graph-engine/definitions/runContinuation.ts
3101
+ var RunRecoveryBlockedError = class extends Error {
3102
+ code = "RUN_RECOVERY_BLOCKED";
3103
+ constructor(message) {
3104
+ super(message);
3105
+ this.name = "RunRecoveryBlockedError";
3106
+ }
3107
+ };
3108
+ var RunPauseRequested = class extends Error {
3109
+ code = "RUN_PAUSE_REQUESTED";
3110
+ constructor(message = "Run paused by user") {
3111
+ super(message);
3112
+ this.name = "RunPauseRequested";
3113
+ }
3114
+ };
3115
+ function isRunPauseSignal(signal) {
3116
+ const reason = signal?.reason;
3117
+ return signal?.aborted === true && typeof reason === "object" && reason !== null && "code" in reason && reason.code === "RUN_PAUSE_REQUESTED";
3118
+ }
3119
+
3100
3120
  // src/runtime-kernel/graph-engine/engine.ts
3101
3121
  var logger2 = new Logger("GraphExecutor");
3102
3122
  function isRecord4(value) {
@@ -3406,6 +3426,7 @@ var GraphExecutor = class {
3406
3426
  reportStepsUsed(stepCount);
3407
3427
  const signalRaw = state.local?.signal;
3408
3428
  if (isAbortSignal2(signalRaw) && signalRaw.aborted) {
3429
+ if (!isRunPauseSignal(signalRaw)) await this.nodes.get(state.nodeId)?.cancel?.(state);
3409
3430
  logger2.warn("[GraphExecutor] \u6536\u5230 AbortSignal\uFF0C\u7ACB\u5373\u505C\u6B62\u63A8\u7406\u5FAA\u73AF");
3410
3431
  this.ephemeralLocals.delete(checkpointKey);
3411
3432
  throwAbortError();
@@ -3456,6 +3477,12 @@ var GraphExecutor = class {
3456
3477
  allEvents.push(...stepResolution.events);
3457
3478
  }
3458
3479
  state = stepResolution.state;
3480
+ const completedSignal = state.local?.signal;
3481
+ if (isAbortSignal2(completedSignal) && completedSignal.aborted && !isRunPauseSignal(completedSignal)) {
3482
+ await this.nodes.get(state.nodeId)?.cancel?.(state);
3483
+ this.ephemeralLocals.delete(checkpointKey);
3484
+ throwAbortError();
3485
+ }
3459
3486
  if (stepResolution.action.kind === "route") {
3460
3487
  logger2.info("[GraphExecutor] \u8DEF\u7531\u5207\u6362", {
3461
3488
  fromNodeId: stepResolution.action.fromNodeId,
@@ -8665,26 +8692,6 @@ function buildCancelledToolBatchLocalState(local, runtimeEvents) {
8665
8692
  function recordToolProtocolError(params) {
8666
8693
  }
8667
8694
 
8668
- // src/runtime-kernel/graph-engine/definitions/runContinuation.ts
8669
- var RunRecoveryBlockedError = class extends Error {
8670
- code = "RUN_RECOVERY_BLOCKED";
8671
- constructor(message) {
8672
- super(message);
8673
- this.name = "RunRecoveryBlockedError";
8674
- }
8675
- };
8676
- var RunPauseRequested = class extends Error {
8677
- code = "RUN_PAUSE_REQUESTED";
8678
- constructor(message = "Run paused by user") {
8679
- super(message);
8680
- this.name = "RunPauseRequested";
8681
- }
8682
- };
8683
- function isRunPauseSignal(signal) {
8684
- const reason = signal?.reason;
8685
- return signal?.aborted === true && typeof reason === "object" && reason !== null && "code" in reason && reason.code === "RUN_PAUSE_REQUESTED";
8686
- }
8687
-
8688
8695
  // src/runtime-kernel/graph-engine/nodes/toolNode.recovery.ts
8689
8696
  async function executeRecoverableTool(input) {
8690
8697
  const local = input.state.local;
@@ -8886,7 +8893,30 @@ var ToolNode = class {
8886
8893
  async run(state) {
8887
8894
  const events = [];
8888
8895
  while (true) {
8889
- const result = await this.runNextPendingToolCall(state);
8896
+ let result;
8897
+ try {
8898
+ result = await this.runNextPendingToolCall(state);
8899
+ } catch (error) {
8900
+ if (isToolExecutionAbort(error) && !isRunPauseSignal(state.local?.signal)) {
8901
+ await this.cancel(state);
8902
+ }
8903
+ throw error;
8904
+ }
8905
+ const signal = state.local?.signal;
8906
+ if (isAbortSignal(signal) && signal.aborted && !isRunPauseSignal(signal)) {
8907
+ await this.cancel(state);
8908
+ const error = new Error("The user aborted a request.");
8909
+ error.name = "AbortError";
8910
+ throw error;
8911
+ }
8912
+ if (result.kind === "interrupted") {
8913
+ await commitToolBoundary(state, {
8914
+ kind: "route",
8915
+ nextNodeId: "llm",
8916
+ events: result.events
8917
+ });
8918
+ throw result.error;
8919
+ }
8890
8920
  await commitToolBoundary(state, result);
8891
8921
  if (Array.isArray(result.events) && result.events.length > 0) {
8892
8922
  events.push(...result.events);
@@ -8900,6 +8930,14 @@ var ToolNode = class {
8900
8930
  };
8901
8931
  }
8902
8932
  }
8933
+ async cancel(state) {
8934
+ settlePendingToolCallsAfterAbort({
8935
+ state,
8936
+ calls: parsePendingToolCalls(state.local?.pendingToolCalls ?? []),
8937
+ toolCatalog: this.toolRuntime
8938
+ });
8939
+ await commitToolBoundary(state, { kind: "yield"});
8940
+ }
8903
8941
  async runNextPendingToolCall(state) {
8904
8942
  const calls = parsePendingToolCalls(state.local?.pendingToolCalls ?? []);
8905
8943
  const signalRaw = state.local?.signal;
@@ -9319,7 +9357,11 @@ var ToolNode = class {
9319
9357
  nextProtocolErrorCount: fuse.nextCount
9320
9358
  });
9321
9359
  if (fuse.shouldFuse && remainingCalls.length === 0) {
9322
- throw createToolProtocolFuseError(fuse.nextCount, context.exec.error);
9360
+ return {
9361
+ kind: "interrupted",
9362
+ error: createToolProtocolFuseError(fuse.nextCount, context.exec.error),
9363
+ events: context.bridge.getRuntimeEvents()
9364
+ };
9323
9365
  }
9324
9366
  if (remainingCalls.length === 0 && context.local.toolBatchCompletionMode === "yield_after_batch") {
9325
9367
  return { kind: "yield", events: context.bridge.getRuntimeEvents() };