@dudousxd/nestjs-agent 1.15.0 → 1.16.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.
@@ -2007,6 +2007,59 @@ var AgentService = class {
2007
2007
  }
2008
2008
  return queue.publish(threadId);
2009
2009
  }
2010
+ /**
2011
+ * `POST <base>/queue/:messageId/interrupt` — run a message that is already waiting NOW: it moves
2012
+ * to the head of its queue marked as an interrupt, any pause is lifted, and the running turn is
2013
+ * cancelled (its settle starts this message — the same path a `mode: 'interrupt'` send takes).
2014
+ * With nothing running, the message starts at once.
2015
+ *
2016
+ * One request, and the message never leaves the queue: a client that removed it and sent it again
2017
+ * would lose it if the second call failed, and would run it twice if another tab's drain started
2018
+ * it in between. Answers the queue, plus `interrupting` (the run that was cancelled) or `runId`
2019
+ * (the run this message started).
2020
+ */
2021
+ async interruptQueuedMessage(actor, messageId) {
2022
+ const queue = this.requireQueue();
2023
+ const store = queue.queueStore();
2024
+ const threadId = await this.assertOwnsQueuedMessage(actor, messageId);
2025
+ const gone = /* @__PURE__ */ __name(() => new GoneException(`queued message ${messageId} already started or was removed`), "gone");
2026
+ const marked = await store.updateQueuedMessage(messageId, {
2027
+ interrupt: true
2028
+ });
2029
+ if (marked === null) {
2030
+ throw gone();
2031
+ }
2032
+ if (marked.interrupt !== true) {
2033
+ throw new NotImplementedException2("Interrupting a queued message requires a ChatQueueStore whose updateQueuedMessage stores `interrupt`; the bound store ignored it.");
2034
+ }
2035
+ if (!await store.moveQueuedMessage(messageId, 0)) {
2036
+ throw gone();
2037
+ }
2038
+ await store.setQueuePause(threadId, null);
2039
+ const { live } = await queue.holder(threadId, this.runner);
2040
+ if (live !== null && live !== messageId && await store.getQueuedMessage(messageId) !== null) {
2041
+ const state2 = await queue.publish(threadId);
2042
+ await this.runner.cancel(live);
2043
+ return {
2044
+ ...state2,
2045
+ interrupting: live
2046
+ };
2047
+ }
2048
+ if (live !== null) {
2049
+ return {
2050
+ ...await queue.state(threadId),
2051
+ runId: messageId
2052
+ };
2053
+ }
2054
+ const runId = await queue.kick(threadId, this.runner);
2055
+ const state = runId === void 0 ? await queue.publish(threadId) : await queue.state(threadId);
2056
+ return {
2057
+ ...state,
2058
+ ...runId !== void 0 ? {
2059
+ runId
2060
+ } : {}
2061
+ };
2062
+ }
2010
2063
  /** `DELETE <base>/threads/:id/queue` — drop every waiting message (and any pause). */
2011
2064
  async clearQueue(actor, threadId) {
2012
2065
  await this.assertOwnsThread(actor, threadId);
@@ -3649,6 +3702,14 @@ var QueueController = class {
3649
3702
  } : {}
3650
3703
  });
3651
3704
  }
3705
+ /**
3706
+ * Run a waiting message now: it moves to the head as an interrupt and the running turn is
3707
+ * cancelled for it. Carries `interrupting` (the cancelled run), or `runId` when nothing was
3708
+ * running and it started at once.
3709
+ */
3710
+ async interrupt(req, messageId) {
3711
+ return this.agent.interruptQueuedMessage(await this.actorResolver.resolve(req), messageId);
3712
+ }
3652
3713
  async remove(req, messageId) {
3653
3714
  return this.agent.removeQueuedMessage(await this.actorResolver.resolve(req), messageId);
3654
3715
  }
@@ -3699,6 +3760,17 @@ _ts_decorate16([
3699
3760
  ]),
3700
3761
  _ts_metadata15("design:returntype", Promise)
3701
3762
  ], QueueController.prototype, "update", null);
3763
+ _ts_decorate16([
3764
+ Post4("queue/:messageId/interrupt"),
3765
+ _ts_param14(0, Req7()),
3766
+ _ts_param14(1, Param4("messageId")),
3767
+ _ts_metadata15("design:type", Function),
3768
+ _ts_metadata15("design:paramtypes", [
3769
+ typeof Request === "undefined" ? Object : Request,
3770
+ String
3771
+ ]),
3772
+ _ts_metadata15("design:returntype", Promise)
3773
+ ], QueueController.prototype, "interrupt", null);
3702
3774
  _ts_decorate16([
3703
3775
  Delete2("queue/:messageId"),
3704
3776
  _ts_param14(0, Req7()),