@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
@@ -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,22 @@ 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
+ }
8634
8656
  await commitToolBoundary(state, result);
8635
8657
  if (Array.isArray(result.events) && result.events.length > 0) {
8636
8658
  events.push(...result.events);
@@ -8644,6 +8666,14 @@ var ToolNode = class {
8644
8666
  };
8645
8667
  }
8646
8668
  }
8669
+ async cancel(state) {
8670
+ settlePendingToolCallsAfterAbort({
8671
+ state,
8672
+ calls: parsePendingToolCalls(state.local?.pendingToolCalls ?? []),
8673
+ toolCatalog: this.toolRuntime
8674
+ });
8675
+ await commitToolBoundary(state, { kind: "yield"});
8676
+ }
8647
8677
  async runNextPendingToolCall(state) {
8648
8678
  const calls = parsePendingToolCalls(state.local?.pendingToolCalls ?? []);
8649
8679
  const signalRaw = state.local?.signal;
@@ -12059,7 +12089,7 @@ function createAwaitingUserWatcher(options) {
12059
12089
  const onClose = () => {
12060
12090
  dispose();
12061
12091
  };
12062
- eventBus.on("event", onEvent);
12092
+ if (options.stateOwner !== "host") eventBus.on("event", onEvent);
12063
12093
  eventBus.on("close", onClose);
12064
12094
  return dispose;
12065
12095
  }
@@ -12535,6 +12565,7 @@ var DefaultRunSupervisor = class {
12535
12565
  this.runSlotLimiter = createRunSlotLimiter({ maxActiveRuns: options.maxActiveRuns });
12536
12566
  this.runConcurrencyKeys = createRunConcurrencyKeyRegistry();
12537
12567
  this.awaitingUserWatcher = createAwaitingUserWatcher({
12568
+ stateOwner: options.awaitingUserStateOwner,
12538
12569
  markAwaitingUser: (runId, patch) => this.getHandle(runId).markAwaitingUser(patch),
12539
12570
  onDisposed: (runId) => {
12540
12571
  this.eventWatchDisposers.delete(runId);
@@ -12731,8 +12762,17 @@ var DefaultRunSupervisor = class {
12731
12762
  canRestoreRun: this.canRestoreRun
12732
12763
  });
12733
12764
  }
12734
- async pause(runId, reason) {
12735
- await this.withRunControlLock(runId, () => this.getHandle(runId).pause(reason));
12765
+ async pause(runId, reason, expectedExecutionId) {
12766
+ await this.withRunControlLock(runId, async () => {
12767
+ const handle = this.getHandle(runId);
12768
+ if (expectedExecutionId !== void 0) {
12769
+ const record = await this.registryStore.load(runId);
12770
+ if (record?.metadata?.executionId !== expectedExecutionId) {
12771
+ throw new RunInteractionConflictError(runId, "pause execution ownership has changed");
12772
+ }
12773
+ }
12774
+ await handle.pause(reason);
12775
+ });
12736
12776
  }
12737
12777
  async resumePausedRun(input) {
12738
12778
  return this.withRunControlLock(input.runId, async () => {