@linnlabs/linnkit 0.35.1 → 0.37.0

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/dist/cli.cjs +64 -24
  3. package/dist/cli.cjs.map +1 -1
  4. package/dist/cli.js +64 -24
  5. package/dist/cli.js.map +1 -1
  6. package/dist/context-manager.cjs.map +1 -1
  7. package/dist/context-manager.js.map +1 -1
  8. package/dist/index.cjs +64 -24
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.js +64 -24
  11. package/dist/index.js.map +1 -1
  12. package/dist/quickstart.cjs +64 -24
  13. package/dist/quickstart.cjs.map +1 -1
  14. package/dist/quickstart.js +64 -24
  15. package/dist/quickstart.js.map +1 -1
  16. package/dist/runtime-kernel/graph-engine/nodes/toolNode.d.cts +1 -0
  17. package/dist/runtime-kernel/graph-engine/nodes/toolNode.d.ts +1 -0
  18. package/dist/runtime-kernel/graph-engine/types.d.cts +2 -0
  19. package/dist/runtime-kernel/graph-engine/types.d.ts +2 -0
  20. package/dist/runtime-kernel/run-supervisor/definitions/runSupervisorContracts.d.cts +3 -1
  21. package/dist/runtime-kernel/run-supervisor/definitions/runSupervisorContracts.d.ts +3 -1
  22. package/dist/runtime-kernel/run-supervisor/runSupervisor.d.cts +2 -2
  23. package/dist/runtime-kernel/run-supervisor/runSupervisor.d.ts +2 -2
  24. package/dist/runtime-kernel.cjs +64 -24
  25. package/dist/runtime-kernel.cjs.map +1 -1
  26. package/dist/runtime-kernel.js +64 -24
  27. package/dist/runtime-kernel.js.map +1 -1
  28. package/dist/testkit.cjs +64 -24
  29. package/dist/testkit.cjs.map +1 -1
  30. package/dist/testkit.js +64 -24
  31. package/dist/testkit.js.map +1 -1
  32. package/docs/integration/persistence.md +9 -0
  33. package/docs/integration/run-supervisor.md +2 -0
  34. package/package.json +2 -2
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,22 @@ 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
+ }
8890
8912
  await commitToolBoundary(state, result);
8891
8913
  if (Array.isArray(result.events) && result.events.length > 0) {
8892
8914
  events.push(...result.events);
@@ -8900,6 +8922,14 @@ var ToolNode = class {
8900
8922
  };
8901
8923
  }
8902
8924
  }
8925
+ async cancel(state) {
8926
+ settlePendingToolCallsAfterAbort({
8927
+ state,
8928
+ calls: parsePendingToolCalls(state.local?.pendingToolCalls ?? []),
8929
+ toolCatalog: this.toolRuntime
8930
+ });
8931
+ await commitToolBoundary(state, { kind: "yield"});
8932
+ }
8903
8933
  async runNextPendingToolCall(state) {
8904
8934
  const calls = parsePendingToolCalls(state.local?.pendingToolCalls ?? []);
8905
8935
  const signalRaw = state.local?.signal;
@@ -13493,7 +13523,7 @@ function createAwaitingUserWatcher(options) {
13493
13523
  const onClose = () => {
13494
13524
  dispose();
13495
13525
  };
13496
- eventBus.on("event", onEvent);
13526
+ if (options.stateOwner !== "host") eventBus.on("event", onEvent);
13497
13527
  eventBus.on("close", onClose);
13498
13528
  return dispose;
13499
13529
  }
@@ -13969,6 +13999,7 @@ var DefaultRunSupervisor = class {
13969
13999
  this.runSlotLimiter = createRunSlotLimiter({ maxActiveRuns: options.maxActiveRuns });
13970
14000
  this.runConcurrencyKeys = createRunConcurrencyKeyRegistry();
13971
14001
  this.awaitingUserWatcher = createAwaitingUserWatcher({
14002
+ stateOwner: options.awaitingUserStateOwner,
13972
14003
  markAwaitingUser: (runId, patch) => this.getHandle(runId).markAwaitingUser(patch),
13973
14004
  onDisposed: (runId) => {
13974
14005
  this.eventWatchDisposers.delete(runId);
@@ -14165,8 +14196,17 @@ var DefaultRunSupervisor = class {
14165
14196
  canRestoreRun: this.canRestoreRun
14166
14197
  });
14167
14198
  }
14168
- async pause(runId, reason) {
14169
- await this.withRunControlLock(runId, () => this.getHandle(runId).pause(reason));
14199
+ async pause(runId, reason, expectedExecutionId) {
14200
+ await this.withRunControlLock(runId, async () => {
14201
+ const handle = this.getHandle(runId);
14202
+ if (expectedExecutionId !== void 0) {
14203
+ const record = await this.registryStore.load(runId);
14204
+ if (record?.metadata?.executionId !== expectedExecutionId) {
14205
+ throw new RunInteractionConflictError(runId, "pause execution ownership has changed");
14206
+ }
14207
+ }
14208
+ await handle.pause(reason);
14209
+ });
14170
14210
  }
14171
14211
  async resumePausedRun(input) {
14172
14212
  return this.withRunControlLock(input.runId, async () => {