@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/cli.js CHANGED
@@ -3004,6 +3004,26 @@ function resolveAssistantReplayParts(response) {
3004
3004
  return response.assistant_replay_parts;
3005
3005
  }
3006
3006
 
3007
+ // src/runtime-kernel/graph-engine/definitions/runContinuation.ts
3008
+ var RunRecoveryBlockedError = class extends Error {
3009
+ code = "RUN_RECOVERY_BLOCKED";
3010
+ constructor(message) {
3011
+ super(message);
3012
+ this.name = "RunRecoveryBlockedError";
3013
+ }
3014
+ };
3015
+ var RunPauseRequested = class extends Error {
3016
+ code = "RUN_PAUSE_REQUESTED";
3017
+ constructor(message = "Run paused by user") {
3018
+ super(message);
3019
+ this.name = "RunPauseRequested";
3020
+ }
3021
+ };
3022
+ function isRunPauseSignal(signal) {
3023
+ const reason = signal?.reason;
3024
+ return signal?.aborted === true && typeof reason === "object" && reason !== null && "code" in reason && reason.code === "RUN_PAUSE_REQUESTED";
3025
+ }
3026
+
3007
3027
  // src/runtime-kernel/graph-engine/engine.ts
3008
3028
  var logger2 = new Logger("GraphExecutor");
3009
3029
  function isRecord4(value) {
@@ -3313,6 +3333,7 @@ var GraphExecutor = class {
3313
3333
  reportStepsUsed(stepCount);
3314
3334
  const signalRaw = state.local?.signal;
3315
3335
  if (isAbortSignal2(signalRaw) && signalRaw.aborted) {
3336
+ if (!isRunPauseSignal(signalRaw)) await this.nodes.get(state.nodeId)?.cancel?.(state);
3316
3337
  logger2.warn("[GraphExecutor] \u6536\u5230 AbortSignal\uFF0C\u7ACB\u5373\u505C\u6B62\u63A8\u7406\u5FAA\u73AF");
3317
3338
  this.ephemeralLocals.delete(checkpointKey);
3318
3339
  throwAbortError();
@@ -3363,6 +3384,12 @@ var GraphExecutor = class {
3363
3384
  allEvents.push(...stepResolution.events);
3364
3385
  }
3365
3386
  state = stepResolution.state;
3387
+ const completedSignal = state.local?.signal;
3388
+ if (isAbortSignal2(completedSignal) && completedSignal.aborted && !isRunPauseSignal(completedSignal)) {
3389
+ await this.nodes.get(state.nodeId)?.cancel?.(state);
3390
+ this.ephemeralLocals.delete(checkpointKey);
3391
+ throwAbortError();
3392
+ }
3366
3393
  if (stepResolution.action.kind === "route") {
3367
3394
  logger2.info("[GraphExecutor] \u8DEF\u7531\u5207\u6362", {
3368
3395
  fromNodeId: stepResolution.action.fromNodeId,
@@ -8293,26 +8320,6 @@ function buildCancelledToolBatchLocalState(local, runtimeEvents) {
8293
8320
  function recordToolProtocolError(params) {
8294
8321
  }
8295
8322
 
8296
- // src/runtime-kernel/graph-engine/definitions/runContinuation.ts
8297
- var RunRecoveryBlockedError = class extends Error {
8298
- code = "RUN_RECOVERY_BLOCKED";
8299
- constructor(message) {
8300
- super(message);
8301
- this.name = "RunRecoveryBlockedError";
8302
- }
8303
- };
8304
- var RunPauseRequested = class extends Error {
8305
- code = "RUN_PAUSE_REQUESTED";
8306
- constructor(message = "Run paused by user") {
8307
- super(message);
8308
- this.name = "RunPauseRequested";
8309
- }
8310
- };
8311
- function isRunPauseSignal(signal) {
8312
- const reason = signal?.reason;
8313
- return signal?.aborted === true && typeof reason === "object" && reason !== null && "code" in reason && reason.code === "RUN_PAUSE_REQUESTED";
8314
- }
8315
-
8316
8323
  // src/runtime-kernel/graph-engine/nodes/toolNode.recovery.ts
8317
8324
  async function executeRecoverableTool(input) {
8318
8325
  const local = input.state.local;
@@ -8514,7 +8521,22 @@ var ToolNode = class {
8514
8521
  async run(state) {
8515
8522
  const events = [];
8516
8523
  while (true) {
8517
- const result = await this.runNextPendingToolCall(state);
8524
+ let result;
8525
+ try {
8526
+ result = await this.runNextPendingToolCall(state);
8527
+ } catch (error) {
8528
+ if (isToolExecutionAbort(error) && !isRunPauseSignal(state.local?.signal)) {
8529
+ await this.cancel(state);
8530
+ }
8531
+ throw error;
8532
+ }
8533
+ const signal = state.local?.signal;
8534
+ if (isAbortSignal(signal) && signal.aborted && !isRunPauseSignal(signal)) {
8535
+ await this.cancel(state);
8536
+ const error = new Error("The user aborted a request.");
8537
+ error.name = "AbortError";
8538
+ throw error;
8539
+ }
8518
8540
  await commitToolBoundary(state, result);
8519
8541
  if (Array.isArray(result.events) && result.events.length > 0) {
8520
8542
  events.push(...result.events);
@@ -8528,6 +8550,14 @@ var ToolNode = class {
8528
8550
  };
8529
8551
  }
8530
8552
  }
8553
+ async cancel(state) {
8554
+ settlePendingToolCallsAfterAbort({
8555
+ state,
8556
+ calls: parsePendingToolCalls(state.local?.pendingToolCalls ?? []),
8557
+ toolCatalog: this.toolRuntime
8558
+ });
8559
+ await commitToolBoundary(state, { kind: "yield"});
8560
+ }
8531
8561
  async runNextPendingToolCall(state) {
8532
8562
  const calls = parsePendingToolCalls(state.local?.pendingToolCalls ?? []);
8533
8563
  const signalRaw = state.local?.signal;
@@ -11943,7 +11973,7 @@ function createAwaitingUserWatcher(options) {
11943
11973
  const onClose = () => {
11944
11974
  dispose();
11945
11975
  };
11946
- eventBus.on("event", onEvent);
11976
+ if (options.stateOwner !== "host") eventBus.on("event", onEvent);
11947
11977
  eventBus.on("close", onClose);
11948
11978
  return dispose;
11949
11979
  }
@@ -12419,6 +12449,7 @@ var DefaultRunSupervisor = class {
12419
12449
  this.runSlotLimiter = createRunSlotLimiter({ maxActiveRuns: options.maxActiveRuns });
12420
12450
  this.runConcurrencyKeys = createRunConcurrencyKeyRegistry();
12421
12451
  this.awaitingUserWatcher = createAwaitingUserWatcher({
12452
+ stateOwner: options.awaitingUserStateOwner,
12422
12453
  markAwaitingUser: (runId, patch) => this.getHandle(runId).markAwaitingUser(patch),
12423
12454
  onDisposed: (runId) => {
12424
12455
  this.eventWatchDisposers.delete(runId);
@@ -12615,8 +12646,17 @@ var DefaultRunSupervisor = class {
12615
12646
  canRestoreRun: this.canRestoreRun
12616
12647
  });
12617
12648
  }
12618
- async pause(runId, reason) {
12619
- await this.withRunControlLock(runId, () => this.getHandle(runId).pause(reason));
12649
+ async pause(runId, reason, expectedExecutionId) {
12650
+ await this.withRunControlLock(runId, async () => {
12651
+ const handle = this.getHandle(runId);
12652
+ if (expectedExecutionId !== void 0) {
12653
+ const record = await this.registryStore.load(runId);
12654
+ if (record?.metadata?.executionId !== expectedExecutionId) {
12655
+ throw new RunInteractionConflictError(runId, "pause execution ownership has changed");
12656
+ }
12657
+ }
12658
+ await handle.pause(reason);
12659
+ });
12620
12660
  }
12621
12661
  async resumePausedRun(input) {
12622
12662
  return this.withRunControlLock(input.runId, async () => {