@tangle-network/agent-app 0.63.3 → 0.63.5

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.
@@ -20,7 +20,7 @@ import {
20
20
  createSandboxRunTool,
21
21
  escalationHints,
22
22
  resolveTurnStorage
23
- } from "./chunk-POIVNKYH.js";
23
+ } from "./chunk-OCR36QGZ.js";
24
24
  import {
25
25
  addStepFinishUsage,
26
26
  assistantRowIdForTurn,
@@ -1568,6 +1568,10 @@ async function cancelChatTurn(request, options) {
1568
1568
  return targetChanged();
1569
1569
  }
1570
1570
  if (target.status === "stopped" || target.status === "answered") return success(false);
1571
+ if (target.control) {
1572
+ const intent = await target.control.request(target.capturedMetadata);
1573
+ return intent.requested ? Response.json({ succeeded: true, sandboxInterrupted: false, cancellationRequested: true }) : targetChanged();
1574
+ }
1571
1575
  const markStopped = async () => await target.markStopped(target.capturedMetadata, (/* @__PURE__ */ new Date()).toISOString()) ? null : stateChanged();
1572
1576
  if (!target.native) return await markStopped() ?? success(false);
1573
1577
  const native = target.native;
@@ -1841,6 +1845,8 @@ function createChatTurnOwnership(state, log, turnStreamId, options) {
1841
1845
  turnId: turnStreamId,
1842
1846
  error: err instanceof Error ? err.message : String(err)
1843
1847
  });
1848
+ } finally {
1849
+ await state.closeCancellation?.();
1844
1850
  }
1845
1851
  }
1846
1852
  })();
@@ -1850,6 +1856,14 @@ function createChatTurnOwnership(state, log, turnStreamId, options) {
1850
1856
  const releaseLock = async () => {
1851
1857
  if (state.completionHandoff || !state.lockAcquired || state.lockReleased) return;
1852
1858
  state.lockReleased = true;
1859
+ try {
1860
+ await state.closeCancellation?.();
1861
+ } catch (err) {
1862
+ log("[chat-routes] turn cancellation close failed", {
1863
+ turnId: turnStreamId,
1864
+ error: err instanceof Error ? err.message : String(err)
1865
+ });
1866
+ }
1853
1867
  try {
1854
1868
  await options.turnLock.release(state.lockHandle);
1855
1869
  } catch (err) {
@@ -2255,7 +2269,11 @@ async function runAdmittedTurn({
2255
2269
  request,
2256
2270
  waitUntil: ctx?.waitUntil,
2257
2271
  earlyResource: early.resource,
2258
- admissionSignal: state.cancellationAbort?.signal,
2272
+ admissionSignal: AbortSignal.any([
2273
+ state.executionAbort.signal,
2274
+ ...state.cancellationAbort ? [state.cancellationAbort.signal] : [],
2275
+ ...ctx?.cancelOnDisconnect ? [request.signal] : []
2276
+ ]),
2259
2277
  body: payload,
2260
2278
  identity,
2261
2279
  context,
@@ -2280,6 +2298,16 @@ async function runAdmittedTurn({
2280
2298
  if (!acquired.acquired) return acquired.response;
2281
2299
  state.lockAcquired = true;
2282
2300
  state.lockHandle = acquired.handle;
2301
+ if (acquired.cancellation) {
2302
+ const cancellation = acquired.cancellation;
2303
+ const abort = () => state.executionAbort.abort(cancellation.signal.reason);
2304
+ if (cancellation.signal.aborted) abort();
2305
+ else cancellation.signal.addEventListener("abort", abort, { once: true });
2306
+ state.closeCancellation = async () => {
2307
+ cancellation.signal.removeEventListener("abort", abort);
2308
+ await cancellation.close();
2309
+ };
2310
+ }
2283
2311
  }
2284
2312
  progress?.("preparing", progressMessages.preparing);
2285
2313
  const { endTrace, exportTraceInBackground, fireTerminalLifecycle, assistantRowId, exportTrace, runAfterSettle } = createTurnSettlement(state, trace, options, executionId, traceSink, identity, traceOptions, context, turnStreamId, log, ctx);
@@ -2421,6 +2449,8 @@ async function runAdmittedTurn({
2421
2449
  }
2422
2450
  function createAdmittedTurnState() {
2423
2451
  return {
2452
+ executionAbort: new AbortController(),
2453
+ closeCancellation: void 0,
2424
2454
  draft: void 0,
2425
2455
  tap: void 0,
2426
2456
  nativeTiming: void 0,
@@ -2655,7 +2685,7 @@ function createTurnEngine(identity, ctx, log, state, dispatched, produceArgs, tr
2655
2685
  yield* state.producer.stream;
2656
2686
  };
2657
2687
  let source = producerStream();
2658
- if (options.cancel && state.cancellationAbort) {
2688
+ if (options.cancel && state.cancellationAbort && !state.closeCancellation) {
2659
2689
  source = observeTurnCancellation(source, produceArgs, options.cancel, state.cancellationAbort);
2660
2690
  }
2661
2691
  if (ctx?.cancelOnDisconnect) {
@@ -3348,4 +3378,4 @@ export {
3348
3378
  createChatTurnRoutes,
3349
3379
  streamChatRouteAsSandboxEvents
3350
3380
  };
3351
- //# sourceMappingURL=chunk-PGWKYLHC.js.map
3381
+ //# sourceMappingURL=chunk-XYSKMHWG.js.map