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