@linnlabs/linnkit 0.44.0 → 0.45.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.
package/dist/testkit.js CHANGED
@@ -8991,9 +8991,49 @@ function recordToolProtocolError(params) {
8991
8991
  }
8992
8992
 
8993
8993
  // src/runtime-kernel/graph-engine/nodes/toolNode.recovery.ts
8994
+ var DEFAULT_TOOL_ABORT_GRACE_MS = 3e3;
8995
+ function settleToolWithinAbortGrace(input) {
8996
+ const { execution, signal, graceMs } = input;
8997
+ if (!signal) return execution;
8998
+ return new Promise((resolve, reject) => {
8999
+ let timer;
9000
+ const cleanup = () => {
9001
+ if (timer !== void 0) clearTimeout(timer);
9002
+ signal.removeEventListener("abort", startGrace);
9003
+ };
9004
+ function startGrace() {
9005
+ timer = setTimeout(() => {
9006
+ cleanup();
9007
+ execution.catch(() => void 0);
9008
+ input.onAbandon?.();
9009
+ const error = new Error("Tool did not stop within the abort grace period; its late outcome is discarded.");
9010
+ error.name = "AbortError";
9011
+ reject(error);
9012
+ }, graceMs);
9013
+ }
9014
+ if (signal.aborted) startGrace();
9015
+ else signal.addEventListener("abort", startGrace, { once: true });
9016
+ execution.then(
9017
+ (value) => {
9018
+ cleanup();
9019
+ resolve(value);
9020
+ },
9021
+ (error) => {
9022
+ cleanup();
9023
+ reject(error);
9024
+ }
9025
+ );
9026
+ });
9027
+ }
8994
9028
  async function executeRecoverableTool(input) {
8995
9029
  const local = input.state.local;
8996
- if (!local?.commitExecutionBoundary) return input.execute();
9030
+ const run = () => settleToolWithinAbortGrace({
9031
+ execution: input.execute(),
9032
+ signal: local?.signal,
9033
+ graceMs: input.abortGraceMs ?? DEFAULT_TOOL_ABORT_GRACE_MS,
9034
+ onAbandon: input.onAbandon
9035
+ });
9036
+ if (!local?.commitExecutionBoundary) return run();
8997
9037
  if (local.executingToolCallId) {
8998
9038
  if (local.executingToolCallId !== input.call.id) {
8999
9039
  throw new RunRecoveryBlockedError("Pending tool identity does not match execution intent");
@@ -9006,7 +9046,7 @@ async function executeRecoverableTool(input) {
9006
9046
  }
9007
9047
  local.executingToolCallId = input.call.id;
9008
9048
  await local.commitExecutionBoundary(input.state);
9009
- const result = await input.execute();
9049
+ const result = await run();
9010
9050
  if (!result.success && isRunPauseSignal(local.signal)) {
9011
9051
  const error = new Error("Tool execution paused before its outcome was confirmed");
9012
9052
  error.name = "AbortError";
@@ -9126,7 +9166,9 @@ var ToolNode = class {
9126
9166
  auditPort;
9127
9167
  modelInputResolver;
9128
9168
  idempotencyInFlight = /* @__PURE__ */ new Map();
9169
+ abortGraceMs;
9129
9170
  constructor(dependencies) {
9171
+ this.abortGraceMs = dependencies.abortGraceMs;
9130
9172
  this.toolRuntime = dependencies.toolRuntime;
9131
9173
  this.observationPreview = dependencies.observationPreview;
9132
9174
  this.telemetryPort = dependencies.telemetryPort ?? noopTelemetry;
@@ -9344,6 +9386,13 @@ var ToolNode = class {
9344
9386
  state,
9345
9387
  call,
9346
9388
  context: prepared.toolContext,
9389
+ abortGraceMs: this.abortGraceMs,
9390
+ onAbandon: () => logger11.warn("[ToolNode] \u5DE5\u5177\u672A\u5728\u505C\u6B62\u671F\u9650\u5185\u7ED3\u675F\uFF0C\u6309\u4E2D\u65AD\u5904\u7406\u5E76\u4E22\u5F03\u8FDF\u5230\u7ED3\u679C", {
9391
+ toolName: execution.toolName,
9392
+ toolCallId: execution.toolCallId,
9393
+ conversationId: prepared.conversationId,
9394
+ turnId: prepared.turnId
9395
+ }),
9347
9396
  execute: () => executeToolWithIdempotency({
9348
9397
  idempotencyKey: execution.idempotencyKey,
9349
9398
  inFlight: this.idempotencyInFlight,