@dudousxd/nestjs-agent 1.15.0 → 1.16.1

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/index.cjs CHANGED
@@ -1186,6 +1186,59 @@ var AgentService = class {
1186
1186
  }
1187
1187
  return queue.publish(threadId);
1188
1188
  }
1189
+ /**
1190
+ * `POST <base>/queue/:messageId/interrupt` — run a message that is already waiting NOW: it moves
1191
+ * to the head of its queue marked as an interrupt, any pause is lifted, and the running turn is
1192
+ * cancelled (its settle starts this message — the same path a `mode: 'interrupt'` send takes).
1193
+ * With nothing running, the message starts at once.
1194
+ *
1195
+ * One request, and the message never leaves the queue: a client that removed it and sent it again
1196
+ * would lose it if the second call failed, and would run it twice if another tab's drain started
1197
+ * it in between. Answers the queue, plus `interrupting` (the run that was cancelled) or `runId`
1198
+ * (the run this message started).
1199
+ */
1200
+ async interruptQueuedMessage(actor, messageId) {
1201
+ const queue = this.requireQueue();
1202
+ const store = queue.queueStore();
1203
+ const threadId = await this.assertOwnsQueuedMessage(actor, messageId);
1204
+ const gone = /* @__PURE__ */ __name(() => new import_common3.GoneException(`queued message ${messageId} already started or was removed`), "gone");
1205
+ const marked = await store.updateQueuedMessage(messageId, {
1206
+ interrupt: true
1207
+ });
1208
+ if (marked === null) {
1209
+ throw gone();
1210
+ }
1211
+ if (marked.interrupt !== true) {
1212
+ throw new import_common3.NotImplementedException("Interrupting a queued message requires a ChatQueueStore whose updateQueuedMessage stores `interrupt`; the bound store ignored it.");
1213
+ }
1214
+ if (!await store.moveQueuedMessage(messageId, 0)) {
1215
+ throw gone();
1216
+ }
1217
+ await store.setQueuePause(threadId, null);
1218
+ const { live } = await queue.holder(threadId, this.runner);
1219
+ if (live !== null && live !== messageId && await store.getQueuedMessage(messageId) !== null) {
1220
+ const state2 = await queue.publish(threadId);
1221
+ await this.runner.cancel(live);
1222
+ return {
1223
+ ...state2,
1224
+ interrupting: live
1225
+ };
1226
+ }
1227
+ if (live !== null) {
1228
+ return {
1229
+ ...await queue.state(threadId),
1230
+ runId: messageId
1231
+ };
1232
+ }
1233
+ const runId = await queue.kick(threadId, this.runner);
1234
+ const state = runId === void 0 ? await queue.publish(threadId) : await queue.state(threadId);
1235
+ return {
1236
+ ...state,
1237
+ ...runId !== void 0 ? {
1238
+ runId
1239
+ } : {}
1240
+ };
1241
+ }
1189
1242
  /** `DELETE <base>/threads/:id/queue` — drop every waiting message (and any pause). */
1190
1243
  async clearQueue(actor, threadId) {
1191
1244
  await this.assertOwnsThread(actor, threadId);
@@ -2828,6 +2881,14 @@ var QueueController = class {
2828
2881
  } : {}
2829
2882
  });
2830
2883
  }
2884
+ /**
2885
+ * Run a waiting message now: it moves to the head as an interrupt and the running turn is
2886
+ * cancelled for it. Carries `interrupting` (the cancelled run), or `runId` when nothing was
2887
+ * running and it started at once.
2888
+ */
2889
+ async interrupt(req, messageId) {
2890
+ return this.agent.interruptQueuedMessage(await this.actorResolver.resolve(req), messageId);
2891
+ }
2831
2892
  async remove(req, messageId) {
2832
2893
  return this.agent.removeQueuedMessage(await this.actorResolver.resolve(req), messageId);
2833
2894
  }
@@ -2878,6 +2939,17 @@ _ts_decorate12([
2878
2939
  ]),
2879
2940
  _ts_metadata12("design:returntype", Promise)
2880
2941
  ], QueueController.prototype, "update", null);
2942
+ _ts_decorate12([
2943
+ (0, import_common12.Post)("queue/:messageId/interrupt"),
2944
+ _ts_param11(0, (0, import_common12.Req)()),
2945
+ _ts_param11(1, (0, import_common12.Param)("messageId")),
2946
+ _ts_metadata12("design:type", Function),
2947
+ _ts_metadata12("design:paramtypes", [
2948
+ typeof Request === "undefined" ? Object : Request,
2949
+ String
2950
+ ]),
2951
+ _ts_metadata12("design:returntype", Promise)
2952
+ ], QueueController.prototype, "interrupt", null);
2881
2953
  _ts_decorate12([
2882
2954
  (0, import_common12.Delete)("queue/:messageId"),
2883
2955
  _ts_param11(0, (0, import_common12.Req)()),