@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.
@@ -8803,9 +8803,49 @@ function recordToolProtocolError(params) {
8803
8803
  }
8804
8804
 
8805
8805
  // src/runtime-kernel/graph-engine/nodes/toolNode.recovery.ts
8806
+ var DEFAULT_TOOL_ABORT_GRACE_MS = 3e3;
8807
+ function settleToolWithinAbortGrace(input) {
8808
+ const { execution, signal, graceMs } = input;
8809
+ if (!signal) return execution;
8810
+ return new Promise((resolve, reject) => {
8811
+ let timer;
8812
+ const cleanup = () => {
8813
+ if (timer !== void 0) clearTimeout(timer);
8814
+ signal.removeEventListener("abort", startGrace);
8815
+ };
8816
+ function startGrace() {
8817
+ timer = setTimeout(() => {
8818
+ cleanup();
8819
+ execution.catch(() => void 0);
8820
+ input.onAbandon?.();
8821
+ const error = new Error("Tool did not stop within the abort grace period; its late outcome is discarded.");
8822
+ error.name = "AbortError";
8823
+ reject(error);
8824
+ }, graceMs);
8825
+ }
8826
+ if (signal.aborted) startGrace();
8827
+ else signal.addEventListener("abort", startGrace, { once: true });
8828
+ execution.then(
8829
+ (value) => {
8830
+ cleanup();
8831
+ resolve(value);
8832
+ },
8833
+ (error) => {
8834
+ cleanup();
8835
+ reject(error);
8836
+ }
8837
+ );
8838
+ });
8839
+ }
8806
8840
  async function executeRecoverableTool(input) {
8807
8841
  const local = input.state.local;
8808
- if (!local?.commitExecutionBoundary) return input.execute();
8842
+ const run = () => settleToolWithinAbortGrace({
8843
+ execution: input.execute(),
8844
+ signal: local?.signal,
8845
+ graceMs: input.abortGraceMs ?? DEFAULT_TOOL_ABORT_GRACE_MS,
8846
+ onAbandon: input.onAbandon
8847
+ });
8848
+ if (!local?.commitExecutionBoundary) return run();
8809
8849
  if (local.executingToolCallId) {
8810
8850
  if (local.executingToolCallId !== input.call.id) {
8811
8851
  throw new RunRecoveryBlockedError("Pending tool identity does not match execution intent");
@@ -8818,7 +8858,7 @@ async function executeRecoverableTool(input) {
8818
8858
  }
8819
8859
  local.executingToolCallId = input.call.id;
8820
8860
  await local.commitExecutionBoundary(input.state);
8821
- const result = await input.execute();
8861
+ const result = await run();
8822
8862
  if (!result.success && isRunPauseSignal(local.signal)) {
8823
8863
  const error = new Error("Tool execution paused before its outcome was confirmed");
8824
8864
  error.name = "AbortError";
@@ -8938,7 +8978,9 @@ var ToolNode = class {
8938
8978
  auditPort;
8939
8979
  modelInputResolver;
8940
8980
  idempotencyInFlight = /* @__PURE__ */ new Map();
8981
+ abortGraceMs;
8941
8982
  constructor(dependencies) {
8983
+ this.abortGraceMs = dependencies.abortGraceMs;
8942
8984
  this.toolRuntime = dependencies.toolRuntime;
8943
8985
  this.observationPreview = dependencies.observationPreview;
8944
8986
  this.telemetryPort = dependencies.telemetryPort ?? noopTelemetry;
@@ -9156,6 +9198,13 @@ var ToolNode = class {
9156
9198
  state,
9157
9199
  call,
9158
9200
  context: prepared.toolContext,
9201
+ abortGraceMs: this.abortGraceMs,
9202
+ 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", {
9203
+ toolName: execution.toolName,
9204
+ toolCallId: execution.toolCallId,
9205
+ conversationId: prepared.conversationId,
9206
+ turnId: prepared.turnId
9207
+ }),
9159
9208
  execute: () => executeToolWithIdempotency({
9160
9209
  idempotencyKey: execution.idempotencyKey,
9161
9210
  inFlight: this.idempotencyInFlight,