@dudousxd/nestjs-agent 1.14.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.
@@ -2,10 +2,10 @@ var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
4
  // src/durable/agent-run.workflow.ts
5
- import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY2, AGENT_STORE, RunCancelledError, agentFailureCode, isReplayIntegrityError, publishAgentRunFailed, runAgentLoop, settleAll, settleUnsettledDelegation } from "@dudousxd/nestjs-agent-core";
5
+ import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY2, AGENT_STORE as AGENT_STORE2, RunCancelledError, agentFailureCode, encodeStreamEvent as encodeStreamEvent3, isReplayIntegrityError, publishAgentRunFailed, releaseThreadRun, runAgentLoop, settleAll, settleUnsettledDelegation } from "@dudousxd/nestjs-agent-core";
6
6
  import { RUN_GATEWAY, Workflow } from "@dudousxd/nestjs-durable";
7
7
  import { isWorkflowControlFlowSignal } from "@dudousxd/nestjs-durable-core";
8
- import { Inject as Inject2, Injectable as Injectable2, Optional } from "@nestjs/common";
8
+ import { Inject as Inject3, Injectable as Injectable3, Optional as Optional2 } from "@nestjs/common";
9
9
 
10
10
  // src/agent-deps.ts
11
11
  function utcDay(date = /* @__PURE__ */ new Date()) {
@@ -23,10 +23,9 @@ function childSinkWriter(writer) {
23
23
  }
24
24
  __name(childSinkWriter, "childSinkWriter");
25
25
 
26
- // src/durable/agent-run.steps.ts
27
- import { AGENT_DEPS_FACTORY, createFrameBuffer, createUiCollector, encodeStreamEvent, invokeWithTransientRetry, observeTurnFrames, publishAgentToolRetry, stampToolKinds, traceLlmTurn, traceToolExecution, withAskTool, withMemoryTool, withSkillTool, withToolTimeout, withTurnFrames, wrapToolStepOutput } from "@dudousxd/nestjs-agent-core";
28
- import { Step } from "@dudousxd/nestjs-durable";
29
- import { Inject, Injectable } from "@nestjs/common";
26
+ // src/queue/chat-queue.service.ts
27
+ import { AGENT_ATTACHMENT_STAGING, AGENT_OPTIONS, AGENT_QUOTA_PROVIDER, AGENT_SINK, AGENT_STORE, encodeStreamEvent, isChatQueueStore, queuedMessageView } from "@dudousxd/nestjs-agent-core";
28
+ import { Inject, Injectable, Logger, NotImplementedException, Optional } from "@nestjs/common";
30
29
  function _ts_decorate(decorators, target, key, desc) {
31
30
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
32
31
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -53,6 +52,434 @@ function _ts_param(paramIndex, decorator) {
53
52
  };
54
53
  }
55
54
  __name(_ts_param, "_ts_param");
55
+ var MAX_DRAIN_ATTEMPTS = 8;
56
+ var ChatQueueService = class _ChatQueueService {
57
+ static {
58
+ __name(this, "ChatQueueService");
59
+ }
60
+ store;
61
+ sink;
62
+ quotaProvider;
63
+ options;
64
+ staging;
65
+ logger = new Logger(_ChatQueueService.name);
66
+ /**
67
+ * Runs this process claimed a thread for and has not handed to a runner yet. A holder in here is
68
+ * alive whatever the runner says — it simply has not registered the run yet.
69
+ */
70
+ starting = /* @__PURE__ */ new Set();
71
+ constructor(store, sink, quotaProvider, options, staging) {
72
+ this.store = store;
73
+ this.sink = sink;
74
+ this.quotaProvider = quotaProvider;
75
+ this.options = options;
76
+ this.staging = staging;
77
+ }
78
+ /** Whether the bound store can hold a queue. Without one, a busy thread is not queued. */
79
+ get supported() {
80
+ return isChatQueueStore(this.store);
81
+ }
82
+ /** The bound store as a queue store, or a 501 naming what is missing. */
83
+ queueStore() {
84
+ if (!isChatQueueStore(this.store)) {
85
+ throw new NotImplementedException("Queueing messages requires an AgentStore that implements ChatQueueStore (enqueueMessage, listQueue, \u2026, claimActiveStream, releaseActiveStream); the bound store does not.");
86
+ }
87
+ return this.store;
88
+ }
89
+ async state(threadId) {
90
+ const store = this.queueStore();
91
+ const [items, paused] = await Promise.all([
92
+ store.listQueue(threadId),
93
+ store.queuePause(threadId)
94
+ ]);
95
+ return {
96
+ items: items.map(queuedMessageView),
97
+ paused
98
+ };
99
+ }
100
+ /**
101
+ * Whether `holder` is still running. A run this process is about to start is; otherwise the
102
+ * runner decides, and a runner that cannot tell says yes.
103
+ */
104
+ async isAlive(holder, runner) {
105
+ if (this.starting.has(holder)) {
106
+ return true;
107
+ }
108
+ if (typeof runner.isRunActive !== "function") {
109
+ return true;
110
+ }
111
+ try {
112
+ return await runner.isRunActive(holder);
113
+ } catch {
114
+ return true;
115
+ }
116
+ }
117
+ /**
118
+ * The run holding `threadId`, or `null` when it is free — a holder the runner reports dead counts
119
+ * as free, and is returned as `stale` so the caller can claim over it.
120
+ */
121
+ async holder(threadId, runner) {
122
+ const holder = await this.queueStore().activeRunForThread(threadId);
123
+ if (holder === null) {
124
+ return {
125
+ live: null,
126
+ stale: null
127
+ };
128
+ }
129
+ return await this.isAlive(holder, runner) ? {
130
+ live: holder,
131
+ stale: null
132
+ } : {
133
+ live: null,
134
+ stale: holder
135
+ };
136
+ }
137
+ /**
138
+ * Decide what follows a TOP-LEVEL run that is settling on `threadId`, and move the thread there:
139
+ * hand it to the next queued message (claimed and popped here, started by the caller), or pause
140
+ * the queue, or release the thread. Call it BEFORE the run's terminal frame, so a client reading
141
+ * the stream learns what comes next from the `queue` frame, and so the thread is already free
142
+ * when the client sees the run end.
143
+ *
144
+ * A no-op returning `{}` on a store without a queue.
145
+ */
146
+ async plan(args) {
147
+ if (!isChatQueueStore(this.store)) {
148
+ return {};
149
+ }
150
+ const store = this.store;
151
+ const { threadId, outcome } = args;
152
+ if (await store.activeRunForThread(threadId) !== args.runId) {
153
+ return {};
154
+ }
155
+ let holding = args.runId;
156
+ for (let attempt = 0; attempt < MAX_DRAIN_ATTEMPTS; attempt += 1) {
157
+ const items = await store.listQueue(threadId);
158
+ const head = items[0];
159
+ if (head === void 0) {
160
+ if (holding !== null) {
161
+ await store.releaseActiveStream(threadId, holding);
162
+ holding = null;
163
+ continue;
164
+ }
165
+ return {};
166
+ }
167
+ let pause = await store.queuePause(threadId);
168
+ if (pause === null) {
169
+ const reason = pauseReasonFor(outcome, head);
170
+ if (reason !== null) {
171
+ pause = {
172
+ reason,
173
+ ...outcome === "failed" && args.error !== void 0 ? {
174
+ message: args.error
175
+ } : {},
176
+ at: (/* @__PURE__ */ new Date()).toISOString()
177
+ };
178
+ await store.setQueuePause(threadId, pause);
179
+ }
180
+ }
181
+ if (pause === null) {
182
+ const blocked = await this.quotaBlock(head.actor);
183
+ if (blocked !== null) {
184
+ pause = {
185
+ reason: "quota_exceeded",
186
+ message: blocked,
187
+ at: (/* @__PURE__ */ new Date()).toISOString()
188
+ };
189
+ await store.setQueuePause(threadId, pause);
190
+ }
191
+ }
192
+ if (pause !== null) {
193
+ if (holding !== null) {
194
+ await store.releaseActiveStream(threadId, holding);
195
+ }
196
+ return {
197
+ frame: queueFrame(items, pause)
198
+ };
199
+ }
200
+ const claimed = await store.claimActiveStream(threadId, head.id, holding !== null ? {
201
+ replacing: holding
202
+ } : {});
203
+ if (!claimed) {
204
+ return {};
205
+ }
206
+ holding = head.id;
207
+ if (!await store.removeQueuedMessage(head.id)) {
208
+ await store.releaseActiveStream(threadId, head.id);
209
+ holding = null;
210
+ continue;
211
+ }
212
+ const next = {
213
+ runId: head.id,
214
+ messageId: head.id,
215
+ input: await this.inputFor(head)
216
+ };
217
+ return {
218
+ next,
219
+ frame: queueFrame(items.slice(1), null, {
220
+ messageId: head.id,
221
+ runId: head.id
222
+ })
223
+ };
224
+ }
225
+ if (holding !== null) {
226
+ await store.releaseActiveStream(threadId, holding);
227
+ }
228
+ return {};
229
+ }
230
+ /**
231
+ * {@link plan}, then start what it picked with `start`. What an in-process settle (the inline
232
+ * runner, a durable cancel issued outside a workflow) calls; answers the frame to write.
233
+ */
234
+ async handoff(args, start) {
235
+ const plan = await this.plan(args);
236
+ if (plan.next === void 0) {
237
+ return plan.frame;
238
+ }
239
+ return await this.launch(args.threadId, plan.next, start) ? plan.frame : this.pausedFrame(args.threadId);
240
+ }
241
+ /**
242
+ * Start the head of an IDLE thread's queue — after a send queued behind a run that turned out to
243
+ * be gone, after a resume, after a stale holder. Does nothing while a live run holds the thread
244
+ * (its settle drains) or while the queue is paused. Answers the started run's id, if any.
245
+ */
246
+ async kick(threadId, runner) {
247
+ if (!isChatQueueStore(this.store)) {
248
+ return void 0;
249
+ }
250
+ const { live, stale } = await this.holder(threadId, runner);
251
+ if (live !== null) {
252
+ return void 0;
253
+ }
254
+ if (stale !== null) {
255
+ this.logger.warn(`thread ${threadId} was held by run ${stale}, which is no longer running`);
256
+ }
257
+ const plan = await this.plan({
258
+ threadId,
259
+ runId: stale,
260
+ outcome: "completed"
261
+ });
262
+ if (plan.next === void 0) {
263
+ return void 0;
264
+ }
265
+ const started = await this.launch(threadId, plan.next, (input, runId) => runner.start(input, {
266
+ runId
267
+ }));
268
+ if (started && plan.frame !== void 0) {
269
+ await this.write(plan.next.runId, plan.frame);
270
+ }
271
+ return started ? plan.next.runId : void 0;
272
+ }
273
+ /**
274
+ * Start a turn the thread is already claimed for. On failure the message goes back to the head of
275
+ * the queue, the queue pauses (`start_failed`), and the claim is released — nothing is lost and
276
+ * nothing is left holding the thread.
277
+ */
278
+ async launch(threadId, next, start) {
279
+ this.starting.add(next.runId);
280
+ try {
281
+ await start(next.input, next.runId);
282
+ return true;
283
+ } catch (error) {
284
+ const message = error instanceof Error ? error.message : String(error);
285
+ this.logger.error(`queued message ${next.messageId} could not start: ${message}`);
286
+ await this.restore(threadId, next, "start_failed", message);
287
+ return false;
288
+ } finally {
289
+ this.starting.delete(next.runId);
290
+ }
291
+ }
292
+ /** Put a turn that never started back at the head of its queue, paused, and free the thread. */
293
+ async restore(threadId, next, reason, message) {
294
+ const store = this.queueStore();
295
+ const { input } = next;
296
+ await store.enqueueMessage({
297
+ threadId,
298
+ actor: input.actor,
299
+ content: input.userText,
300
+ at: "head",
301
+ ...input.attachments !== void 0 ? {
302
+ attachments: input.attachments
303
+ } : {},
304
+ ...input.agentName !== void 0 ? {
305
+ agentName: input.agentName
306
+ } : {},
307
+ ...input.model !== void 0 ? {
308
+ model: input.model
309
+ } : {},
310
+ ...input.pageContext !== void 0 ? {
311
+ pageContext: input.pageContext
312
+ } : {}
313
+ });
314
+ await store.setQueuePause(threadId, {
315
+ reason,
316
+ message,
317
+ at: (/* @__PURE__ */ new Date()).toISOString()
318
+ });
319
+ await store.releaseActiveStream(threadId, next.runId);
320
+ }
321
+ /** A `queue` frame with the thread's current state. */
322
+ async pausedFrame(threadId) {
323
+ return {
324
+ kind: "queue",
325
+ queue: await this.state(threadId)
326
+ };
327
+ }
328
+ /**
329
+ * Tell whoever is watching the thread that its queue changed: a `queue` frame into the stream of
330
+ * the run holding it. Best-effort — a thread nobody is streaming has no one to tell, and the next
331
+ * read of the thread carries the queue anyway.
332
+ */
333
+ async publish(threadId) {
334
+ const state = await this.state(threadId);
335
+ const holder = await this.queueStore().activeRunForThread(threadId);
336
+ if (holder !== null) {
337
+ await this.write(holder, {
338
+ kind: "queue",
339
+ queue: state
340
+ }).catch((error) => {
341
+ this.logger.warn(`could not publish the queue of thread ${threadId}: ${error instanceof Error ? error.message : String(error)}`);
342
+ });
343
+ }
344
+ return state;
345
+ }
346
+ async write(runId, frame) {
347
+ const writer = await this.sink.open(runId);
348
+ await writer.write(encodeStreamEvent(frame));
349
+ }
350
+ /** Why `actor` may not start a turn now (the quota message), or `null`. */
351
+ async quotaBlock(actor) {
352
+ if (this.options?.quota === void 0 || this.quotaProvider === void 0) {
353
+ return null;
354
+ }
355
+ try {
356
+ const { blocked } = await this.quotaProvider.report({
357
+ actor
358
+ });
359
+ if (blocked === void 0) {
360
+ return null;
361
+ }
362
+ return blocked.reason ?? `The ${blocked.period === "day" ? "daily" : "monthly"} quota is used up`;
363
+ } catch {
364
+ return null;
365
+ }
366
+ }
367
+ /**
368
+ * The turn a queued message starts: everything it was queued with, today's date, and its
369
+ * attachments' urls minted afresh — the ones stored at enqueue time may have expired while it
370
+ * waited. An attachment the staging store no longer resolves keeps its stored url.
371
+ */
372
+ async inputFor(message) {
373
+ const attachments = await this.freshAttachments(message.actor, message.attachments ?? []);
374
+ return {
375
+ threadId: message.threadId,
376
+ actor: message.actor,
377
+ userText: message.content,
378
+ day: utcDay(),
379
+ ...message.agentName !== void 0 ? {
380
+ agentName: message.agentName
381
+ } : {},
382
+ ...attachments.length > 0 ? {
383
+ attachments
384
+ } : {},
385
+ ...message.pageContext !== void 0 ? {
386
+ pageContext: message.pageContext
387
+ } : {},
388
+ ...message.model !== void 0 ? {
389
+ model: message.model
390
+ } : {}
391
+ };
392
+ }
393
+ async freshAttachments(actor, attachments) {
394
+ const staging = this.staging;
395
+ if (attachments.length === 0 || staging === void 0 || typeof staging.resolve !== "function") {
396
+ return attachments;
397
+ }
398
+ return Promise.all(attachments.map(async (attachment) => {
399
+ try {
400
+ return await staging.resolve({
401
+ mediaId: attachment.mediaId,
402
+ actor
403
+ }) ?? attachment;
404
+ } catch {
405
+ return attachment;
406
+ }
407
+ }));
408
+ }
409
+ };
410
+ ChatQueueService = _ts_decorate([
411
+ Injectable(),
412
+ _ts_param(0, Inject(AGENT_STORE)),
413
+ _ts_param(1, Inject(AGENT_SINK)),
414
+ _ts_param(2, Optional()),
415
+ _ts_param(2, Inject(AGENT_QUOTA_PROVIDER)),
416
+ _ts_param(3, Optional()),
417
+ _ts_param(3, Inject(AGENT_OPTIONS)),
418
+ _ts_param(4, Optional()),
419
+ _ts_param(4, Inject(AGENT_ATTACHMENT_STAGING)),
420
+ _ts_metadata("design:type", Function),
421
+ _ts_metadata("design:paramtypes", [
422
+ typeof AgentStore === "undefined" ? Object : AgentStore,
423
+ typeof TokenStreamSink === "undefined" ? Object : TokenStreamSink,
424
+ typeof QuotaProvider === "undefined" ? Object : QuotaProvider,
425
+ typeof Pick === "undefined" ? Object : Pick,
426
+ typeof AttachmentStagingStore === "undefined" ? Object : AttachmentStagingStore
427
+ ])
428
+ ], ChatQueueService);
429
+ function pauseReasonFor(outcome, head) {
430
+ if (outcome === "failed") {
431
+ return "run_failed";
432
+ }
433
+ if (outcome === "cancelled" && head.interrupt !== true) {
434
+ return "cancelled";
435
+ }
436
+ return null;
437
+ }
438
+ __name(pauseReasonFor, "pauseReasonFor");
439
+ function queueFrame(items, paused, started) {
440
+ return {
441
+ kind: "queue",
442
+ queue: {
443
+ items: items.map(queuedMessageView),
444
+ paused
445
+ },
446
+ ...started !== void 0 ? {
447
+ started
448
+ } : {}
449
+ };
450
+ }
451
+ __name(queueFrame, "queueFrame");
452
+
453
+ // src/durable/agent-run.steps.ts
454
+ import { AGENT_DEPS_FACTORY, createFrameBuffer, createUiCollector, encodeStreamEvent as encodeStreamEvent2, invokeWithTransientRetry, observeTurnFrames, publishAgentToolRetry, stampToolKinds, traceLlmTurn, traceToolExecution, withAskTool, withMemoryTool, withSkillTool, withToolTimeout, withTurnFrames, wrapToolStepOutput } from "@dudousxd/nestjs-agent-core";
455
+ import { Step } from "@dudousxd/nestjs-durable";
456
+ import { Inject as Inject2, Injectable as Injectable2 } from "@nestjs/common";
457
+ function _ts_decorate2(decorators, target, key, desc) {
458
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
459
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
460
+ r = Reflect.decorate(decorators, target, key, desc);
461
+ } else {
462
+ for (var i = decorators.length - 1; i >= 0; i--) {
463
+ if (d = decorators[i]) {
464
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
465
+ }
466
+ }
467
+ }
468
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
469
+ }
470
+ __name(_ts_decorate2, "_ts_decorate");
471
+ function _ts_metadata2(metadataKey, metadataValue) {
472
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
473
+ return Reflect.metadata(metadataKey, metadataValue);
474
+ }
475
+ }
476
+ __name(_ts_metadata2, "_ts_metadata");
477
+ function _ts_param2(paramIndex, decorator) {
478
+ return function(target, key) {
479
+ decorator(target, key, paramIndex);
480
+ };
481
+ }
482
+ __name(_ts_param2, "_ts_param");
56
483
  var AgentRunSteps = class {
57
484
  static {
58
485
  __name(this, "AgentRunSteps");
@@ -129,7 +556,7 @@ var AgentRunSteps = class {
129
556
  let opened;
130
557
  const ui = createUiCollector(input.toolCallId, sinkRunId === void 0 ? void 0 : async (event) => {
131
558
  opened ??= Promise.resolve(deps.sink.open(sinkRunId)).then((writer) => input.childSink === true ? childSinkWriter(writer) : writer);
132
- await (await opened).write(encodeStreamEvent(event));
559
+ await (await opened).write(encodeStreamEvent2(event));
133
560
  });
134
561
  const ctx = {
135
562
  ...input.ctx,
@@ -164,35 +591,35 @@ var AgentRunSteps = class {
164
591
  return input.collectUi === true ? wrapToolStepOutput(output, ui.components()) : output;
165
592
  }
166
593
  };
167
- _ts_decorate([
594
+ _ts_decorate2([
168
595
  Step({
169
596
  retries: 3
170
597
  }),
171
- _ts_metadata("design:type", Function),
172
- _ts_metadata("design:paramtypes", [
598
+ _ts_metadata2("design:type", Function),
599
+ _ts_metadata2("design:paramtypes", [
173
600
  typeof DispatchedLlmInput === "undefined" ? Object : DispatchedLlmInput
174
601
  ]),
175
- _ts_metadata("design:returntype", Promise)
602
+ _ts_metadata2("design:returntype", Promise)
176
603
  ], AgentRunSteps.prototype, "llm", null);
177
- _ts_decorate([
604
+ _ts_decorate2([
178
605
  Step(),
179
- _ts_metadata("design:type", Function),
180
- _ts_metadata("design:paramtypes", [
606
+ _ts_metadata2("design:type", Function),
607
+ _ts_metadata2("design:paramtypes", [
181
608
  typeof DispatchedToolInput === "undefined" ? Object : DispatchedToolInput
182
609
  ]),
183
- _ts_metadata("design:returntype", Promise)
610
+ _ts_metadata2("design:returntype", Promise)
184
611
  ], AgentRunSteps.prototype, "tool", null);
185
- AgentRunSteps = _ts_decorate([
186
- Injectable(),
187
- _ts_param(0, Inject(AGENT_DEPS_FACTORY)),
188
- _ts_metadata("design:type", Function),
189
- _ts_metadata("design:paramtypes", [
612
+ AgentRunSteps = _ts_decorate2([
613
+ Injectable2(),
614
+ _ts_param2(0, Inject2(AGENT_DEPS_FACTORY)),
615
+ _ts_metadata2("design:type", Function),
616
+ _ts_metadata2("design:paramtypes", [
190
617
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory
191
618
  ])
192
619
  ], AgentRunSteps);
193
620
 
194
621
  // src/durable/agent-run.workflow.ts
195
- function _ts_decorate2(decorators, target, key, desc) {
622
+ function _ts_decorate3(decorators, target, key, desc) {
196
623
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
197
624
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
198
625
  r = Reflect.decorate(decorators, target, key, desc);
@@ -205,19 +632,19 @@ function _ts_decorate2(decorators, target, key, desc) {
205
632
  }
206
633
  return c > 3 && r && Object.defineProperty(target, key, r), r;
207
634
  }
208
- __name(_ts_decorate2, "_ts_decorate");
209
- function _ts_metadata2(metadataKey, metadataValue) {
635
+ __name(_ts_decorate3, "_ts_decorate");
636
+ function _ts_metadata3(metadataKey, metadataValue) {
210
637
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
211
638
  return Reflect.metadata(metadataKey, metadataValue);
212
639
  }
213
640
  }
214
- __name(_ts_metadata2, "_ts_metadata");
215
- function _ts_param2(paramIndex, decorator) {
641
+ __name(_ts_metadata3, "_ts_metadata");
642
+ function _ts_param3(paramIndex, decorator) {
216
643
  return function(target, key) {
217
644
  decorator(target, key, paramIndex);
218
645
  };
219
646
  }
220
- __name(_ts_param2, "_ts_param");
647
+ __name(_ts_param3, "_ts_param");
221
648
  var AgentRunWorkflow = class _AgentRunWorkflow {
222
649
  static {
223
650
  __name(this, "AgentRunWorkflow");
@@ -225,10 +652,63 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
225
652
  factory;
226
653
  store;
227
654
  runs;
228
- constructor(factory, store, runs) {
655
+ queue;
656
+ constructor(factory, store, runs, queue) {
229
657
  this.factory = factory;
230
658
  this.store = store;
231
659
  this.runs = runs;
660
+ this.queue = queue;
661
+ }
662
+ /**
663
+ * Move the thread past this settling turn — to the next queued message, started here as a
664
+ * fire-and-forget `ctx.startChild` under the message's own id, or to a paused/empty queue — and
665
+ * answer the `queue` frame to write before the turn's terminal.
666
+ *
667
+ * Journaled: the decision (which message, claimed and popped) is one `localStep`, so a replay
668
+ * reads it back instead of popping a second message, and the start is the runtime's own
669
+ * replay-safe spawn. Gated by `ctx.patched`, so a run recorded before the queue existed replays
670
+ * against the history it has. A no-op for a sub-agent's run and on a store without a queue.
671
+ */
672
+ async advanceQueue(ctx, input, outcome, error) {
673
+ const queue = this.queue;
674
+ if (queue === void 0 || !queue.supported || input.sinkRunId !== void 0 || input.deliverTo !== void 0) {
675
+ return void 0;
676
+ }
677
+ if (!await ctx.patched("agent:chat-queue")) {
678
+ return void 0;
679
+ }
680
+ const plan = await ctx.localStep(`queue:${outcome}`, async () => {
681
+ try {
682
+ const settled = outcome === "completed" && await this.isCancelled(ctx.runId) ? "cancelled" : outcome;
683
+ return await queue.plan({
684
+ threadId: input.threadId,
685
+ runId: ctx.runId,
686
+ outcome: settled,
687
+ ...error !== void 0 ? {
688
+ error
689
+ } : {}
690
+ });
691
+ } catch {
692
+ return {};
693
+ }
694
+ });
695
+ const next = plan.next;
696
+ if (next === void 0) {
697
+ return plan.frame;
698
+ }
699
+ try {
700
+ await ctx.startChild(_AgentRunWorkflow, next.input, next.runId);
701
+ return plan.frame;
702
+ } catch (failure) {
703
+ if (isWorkflowControlFlowSignal(failure)) {
704
+ throw failure;
705
+ }
706
+ const reason = failure instanceof Error ? failure.message : String(failure);
707
+ return ctx.localStep("queue:restore", async () => {
708
+ await queue.restore(input.threadId, next, "start_failed", reason);
709
+ return queue.pausedFrame(input.threadId);
710
+ });
711
+ }
232
712
  }
233
713
  /**
234
714
  * Has someone asked this run to stop? Read from the runtime's own run status, which is where
@@ -294,7 +774,25 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
294
774
  const hooks = {
295
775
  runId: ctx.runId,
296
776
  // A child forwards into the top-level sink but must not end/fail it (the top-level run owns it).
297
- openSink: /* @__PURE__ */ __name(async () => input.sinkRunId !== void 0 ? childSinkWriter(await deps.sink.open(sinkRunId)) : deps.sink.open(ctx.runId), "openSink"),
777
+ // A thread's own turn hands the thread to its queue just before the loop ends the stream, so
778
+ // the reader learns what runs next from the `queue` frame, before the end.
779
+ openSink: /* @__PURE__ */ __name(async () => {
780
+ if (input.sinkRunId !== void 0) {
781
+ return childSinkWriter(await deps.sink.open(sinkRunId));
782
+ }
783
+ const writer = await deps.sink.open(ctx.runId);
784
+ return {
785
+ write: /* @__PURE__ */ __name((chunk) => writer.write(chunk), "write"),
786
+ fail: /* @__PURE__ */ __name((failure) => writer.fail(failure), "fail"),
787
+ end: /* @__PURE__ */ __name(async () => {
788
+ const frame = await this.advanceQueue(ctx, input, "completed");
789
+ if (frame !== void 0) {
790
+ await writer.write(encodeStreamEvent3(frame));
791
+ }
792
+ await writer.end();
793
+ }, "end")
794
+ };
795
+ }, "openSink"),
298
796
  // A policy's time to live becomes the signal wait's own timeout: the runtime journals the
299
797
  // deadline on the first call (a position of its own, reached only for a call the journal says
300
798
  // has a ttl) and wakes the run when it passes. The lapse comes back as a Decision rather than a
@@ -417,14 +915,14 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
417
915
  ...deps,
418
916
  day
419
917
  }, input, hooks);
420
- await ctx.localStep("deactivate", () => this.store.setActiveStream(input.threadId, null));
918
+ await ctx.localStep("deactivate", () => releaseThreadRun(this.store, input.threadId, ctx.runId));
421
919
  return result;
422
920
  } catch (error) {
423
921
  if (isWorkflowControlFlowSignal(error)) {
424
922
  throw error;
425
923
  }
426
924
  if (error instanceof RunCancelledError) {
427
- await ctx.localStep("deactivate", () => this.store.setActiveStream(input.threadId, null));
925
+ await ctx.localStep("deactivate", () => releaseThreadRun(this.store, input.threadId, ctx.runId));
428
926
  await this.settleDetachedParent(ctx, input, {
429
927
  status: "cancelled"
430
928
  });
@@ -455,12 +953,16 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
455
953
  errorCode: code,
456
954
  errorMessage: message
457
955
  }) ?? Promise.resolve());
458
- await ctx.localStep("deactivate", () => this.store.setActiveStream(input.threadId, null));
956
+ const queueFrame2 = await this.advanceQueue(ctx, input, "failed", message);
957
+ await ctx.localStep("deactivate", () => releaseThreadRun(this.store, input.threadId, ctx.runId));
459
958
  await this.settleDetachedParent(ctx, input, {
460
959
  status: "failed",
461
960
  error: message
462
961
  });
463
962
  const writer = await hooks.openSink();
963
+ if (queueFrame2 !== void 0) {
964
+ await writer.write(encodeStreamEvent3(queueFrame2));
965
+ }
464
966
  await writer.fail({
465
967
  code,
466
968
  message
@@ -469,21 +971,23 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
469
971
  }
470
972
  }
471
973
  };
472
- AgentRunWorkflow = _ts_decorate2([
473
- Injectable2(),
974
+ AgentRunWorkflow = _ts_decorate3([
975
+ Injectable3(),
474
976
  Workflow({
475
977
  name: "agent.run",
476
978
  version: "1"
477
979
  }),
478
- _ts_param2(0, Inject2(AGENT_DEPS_FACTORY2)),
479
- _ts_param2(1, Inject2(AGENT_STORE)),
480
- _ts_param2(2, Optional()),
481
- _ts_param2(2, Inject2(RUN_GATEWAY)),
482
- _ts_metadata2("design:type", Function),
483
- _ts_metadata2("design:paramtypes", [
980
+ _ts_param3(0, Inject3(AGENT_DEPS_FACTORY2)),
981
+ _ts_param3(1, Inject3(AGENT_STORE2)),
982
+ _ts_param3(2, Optional2()),
983
+ _ts_param3(2, Inject3(RUN_GATEWAY)),
984
+ _ts_param3(3, Optional2()),
985
+ _ts_metadata3("design:type", Function),
986
+ _ts_metadata3("design:paramtypes", [
484
987
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
485
988
  typeof AgentStore === "undefined" ? Object : AgentStore,
486
- typeof RunGateway === "undefined" ? Object : RunGateway
989
+ typeof RunGateway === "undefined" ? Object : RunGateway,
990
+ typeof ChatQueueService === "undefined" ? Object : ChatQueueService
487
991
  ])
488
992
  ], AgentRunWorkflow);
489
993
  function isSignalTimeout(error) {
@@ -493,10 +997,10 @@ __name(isSignalTimeout, "isSignalTimeout");
493
997
 
494
998
  // src/durable/durable-agent-runner.ts
495
999
  import { randomUUID } from "crypto";
496
- import { AGENT_SINK, AGENT_STORE as AGENT_STORE2, encodeStreamEvent as encodeStreamEvent2 } from "@dudousxd/nestjs-agent-core";
1000
+ import { AGENT_SINK as AGENT_SINK2, AGENT_STORE as AGENT_STORE3, encodeStreamEvent as encodeStreamEvent4, releaseThreadRun as releaseThreadRun2 } from "@dudousxd/nestjs-agent-core";
497
1001
  import { RUN_GATEWAY as RUN_GATEWAY2, WorkflowService } from "@dudousxd/nestjs-durable";
498
1002
  import { isWorkflowControlFlowSignal as isWorkflowControlFlowSignal2 } from "@dudousxd/nestjs-durable-core";
499
- import { Inject as Inject3, Injectable as Injectable3, Logger } from "@nestjs/common";
1003
+ import { Inject as Inject4, Injectable as Injectable4, Logger as Logger2, Optional as Optional3 } from "@nestjs/common";
500
1004
 
501
1005
  // src/in-process-sink.ts
502
1006
  import { AgentStreamError } from "@dudousxd/nestjs-agent-core";
@@ -567,7 +1071,7 @@ var InProcessTokenStreamSink = class {
567
1071
  };
568
1072
 
569
1073
  // src/durable/durable-agent-runner.ts
570
- function _ts_decorate3(decorators, target, key, desc) {
1074
+ function _ts_decorate4(decorators, target, key, desc) {
571
1075
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
572
1076
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
573
1077
  r = Reflect.decorate(decorators, target, key, desc);
@@ -580,19 +1084,19 @@ function _ts_decorate3(decorators, target, key, desc) {
580
1084
  }
581
1085
  return c > 3 && r && Object.defineProperty(target, key, r), r;
582
1086
  }
583
- __name(_ts_decorate3, "_ts_decorate");
584
- function _ts_metadata3(metadataKey, metadataValue) {
1087
+ __name(_ts_decorate4, "_ts_decorate");
1088
+ function _ts_metadata4(metadataKey, metadataValue) {
585
1089
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
586
1090
  return Reflect.metadata(metadataKey, metadataValue);
587
1091
  }
588
1092
  }
589
- __name(_ts_metadata3, "_ts_metadata");
590
- function _ts_param3(paramIndex, decorator) {
1093
+ __name(_ts_metadata4, "_ts_metadata");
1094
+ function _ts_param4(paramIndex, decorator) {
591
1095
  return function(target, key) {
592
1096
  decorator(target, key, paramIndex);
593
1097
  };
594
1098
  }
595
- __name(_ts_param3, "_ts_param");
1099
+ __name(_ts_param4, "_ts_param");
596
1100
  function threadOfRun(input) {
597
1101
  if (typeof input !== "object" || input === null || !("threadId" in input)) {
598
1102
  return void 0;
@@ -600,6 +1104,10 @@ function threadOfRun(input) {
600
1104
  return typeof input.threadId === "string" ? input.threadId : void 0;
601
1105
  }
602
1106
  __name(threadOfRun, "threadOfRun");
1107
+ function isThreadTurn(input) {
1108
+ return typeof input === "object" && input !== null && input.sinkRunId === void 0 && input.deliverTo === void 0;
1109
+ }
1110
+ __name(isThreadTurn, "isThreadTurn");
603
1111
  var DurableAgentRunner = class _DurableAgentRunner {
604
1112
  static {
605
1113
  __name(this, "DurableAgentRunner");
@@ -608,22 +1116,24 @@ var DurableAgentRunner = class _DurableAgentRunner {
608
1116
  runs;
609
1117
  store;
610
1118
  sink;
611
- logger = new Logger(_DurableAgentRunner.name);
612
- constructor(workflows, runs, store, sink) {
1119
+ queue;
1120
+ logger = new Logger2(_DurableAgentRunner.name);
1121
+ constructor(workflows, runs, store, sink, queue) {
613
1122
  this.workflows = workflows;
614
1123
  this.runs = runs;
615
1124
  this.store = store;
616
1125
  this.sink = sink;
1126
+ this.queue = queue;
617
1127
  if (this.sink instanceof InProcessTokenStreamSink) {
618
1128
  this.logger.warn("durable: true with the default InProcessTokenStreamSink, which only buffers tokens in this process. The worker that runs the turn \u2014 and the one that serves its dispatched `llm` step \u2014 cannot stream into this buffer. Wire a cross-process TokenStreamSink (e.g. a Redis pub/sub sink) via AgentModule.forRoot({ sink }) before running multi-pod.");
619
1129
  }
620
1130
  }
621
- async start(input) {
1131
+ async start(input, options = {}) {
622
1132
  const stamped = {
623
1133
  ...input,
624
1134
  day: input.day ?? utcDay()
625
1135
  };
626
- const runId = randomUUID();
1136
+ const runId = options.runId ?? randomUUID();
627
1137
  try {
628
1138
  await this.workflows.start(AgentRunWorkflow, stamped, runId);
629
1139
  } catch (error) {
@@ -635,6 +1145,19 @@ var DurableAgentRunner = class _DurableAgentRunner {
635
1145
  runId
636
1146
  };
637
1147
  }
1148
+ /**
1149
+ * From the runtime's own run row. A run it does not know yet counts as running — a queued turn is
1150
+ * claimed before its `startChild` lands — and so does one it cannot be asked about: only a run the
1151
+ * runtime reports settled (`completed`/`failed`/`cancelled`/`dead`) is stale.
1152
+ */
1153
+ async isRunActive(runId) {
1154
+ try {
1155
+ const status = (await this.runs.getRunDetail(runId))?.run.status;
1156
+ return !(status === "completed" || status === "failed" || status === "cancelled" || status === "dead");
1157
+ } catch {
1158
+ return true;
1159
+ }
1160
+ }
638
1161
  async signal(runId, toolCallId2, reply) {
639
1162
  await this.workflows.signal(`tool:${runId}:${toolCallId2}`, reply);
640
1163
  }
@@ -664,15 +1187,32 @@ var DurableAgentRunner = class _DurableAgentRunner {
664
1187
  */
665
1188
  async cancel(runId) {
666
1189
  this.logger.log(`cancelling agent run ${runId}`);
667
- const threadId = await this.threadOf(runId);
1190
+ const input = await this.inputOf(runId);
1191
+ const threadId = threadOfRun(input);
668
1192
  await this.runs.cancel(runId, {
669
1193
  compensate: true
670
1194
  });
1195
+ const writer = await this.sink.open(runId);
671
1196
  if (threadId !== void 0) {
672
- await this.store.setActiveStream(threadId, null);
1197
+ if (this.queue?.supported === true && isThreadTurn(input)) {
1198
+ try {
1199
+ const frame = await this.queue.handoff({
1200
+ threadId,
1201
+ runId,
1202
+ outcome: "cancelled"
1203
+ }, (next, nextRunId) => this.start(next, {
1204
+ runId: nextRunId
1205
+ }));
1206
+ if (frame !== void 0) {
1207
+ await writer.write(encodeStreamEvent4(frame));
1208
+ }
1209
+ } catch (error) {
1210
+ this.logger.error(`could not advance the queue of thread ${threadId} after cancelling ${runId}: ${error instanceof Error ? error.message : String(error)}`);
1211
+ }
1212
+ }
1213
+ await releaseThreadRun2(this.store, threadId, runId);
673
1214
  }
674
- const writer = await this.sink.open(runId);
675
- await writer.write(encodeStreamEvent2({
1215
+ await writer.write(encodeStreamEvent4({
676
1216
  kind: "cancelled"
677
1217
  }));
678
1218
  await writer.end();
@@ -682,7 +1222,7 @@ var DurableAgentRunner = class _DurableAgentRunner {
682
1222
  });
683
1223
  }
684
1224
  /**
685
- * Which thread a run was streaming, or `undefined` where the gateway cannot say.
1225
+ * The input a run was started with (which thread it was streaming), or `undefined` where the gateway cannot say.
686
1226
  *
687
1227
  * A read failure answers `undefined` instead of propagating, the same posture `AgentRunWorkflow`
688
1228
  * takes for its own cancel observation: failing to ask is not an answer worth failing a cancel
@@ -691,32 +1231,34 @@ var DurableAgentRunner = class _DurableAgentRunner {
691
1231
  * with a subscriber holding a stream that never settles, from the one call whose entire job is to
692
1232
  * make a run stop.
693
1233
  */
694
- async threadOf(runId) {
1234
+ async inputOf(runId) {
695
1235
  try {
696
- return threadOfRun((await this.runs.getRunDetail(runId))?.run.input);
1236
+ return (await this.runs.getRunDetail(runId))?.run.input;
697
1237
  } catch {
698
1238
  return void 0;
699
1239
  }
700
1240
  }
701
1241
  };
702
- DurableAgentRunner = _ts_decorate3([
703
- Injectable3(),
704
- _ts_param3(1, Inject3(RUN_GATEWAY2)),
705
- _ts_param3(2, Inject3(AGENT_STORE2)),
706
- _ts_param3(3, Inject3(AGENT_SINK)),
707
- _ts_metadata3("design:type", Function),
708
- _ts_metadata3("design:paramtypes", [
1242
+ DurableAgentRunner = _ts_decorate4([
1243
+ Injectable4(),
1244
+ _ts_param4(1, Inject4(RUN_GATEWAY2)),
1245
+ _ts_param4(2, Inject4(AGENT_STORE3)),
1246
+ _ts_param4(3, Inject4(AGENT_SINK2)),
1247
+ _ts_param4(4, Optional3()),
1248
+ _ts_metadata4("design:type", Function),
1249
+ _ts_metadata4("design:paramtypes", [
709
1250
  typeof WorkflowService === "undefined" ? Object : WorkflowService,
710
1251
  typeof RunGateway === "undefined" ? Object : RunGateway,
711
1252
  typeof AgentStore === "undefined" ? Object : AgentStore,
712
- typeof TokenStreamSink === "undefined" ? Object : TokenStreamSink
1253
+ typeof TokenStreamSink === "undefined" ? Object : TokenStreamSink,
1254
+ typeof ChatQueueService === "undefined" ? Object : ChatQueueService
713
1255
  ])
714
1256
  ], DurableAgentRunner);
715
1257
 
716
1258
  // src/durable/agent-durable.module.ts
717
1259
  import { AGENT_DURABLE_RUNNER } from "@dudousxd/nestjs-agent-core";
718
1260
  import { Global, Module } from "@nestjs/common";
719
- function _ts_decorate4(decorators, target, key, desc) {
1261
+ function _ts_decorate5(decorators, target, key, desc) {
720
1262
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
721
1263
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
722
1264
  r = Reflect.decorate(decorators, target, key, desc);
@@ -729,7 +1271,7 @@ function _ts_decorate4(decorators, target, key, desc) {
729
1271
  }
730
1272
  return c > 3 && r && Object.defineProperty(target, key, r), r;
731
1273
  }
732
- __name(_ts_decorate4, "_ts_decorate");
1274
+ __name(_ts_decorate5, "_ts_decorate");
733
1275
  function runnerProviders() {
734
1276
  return [
735
1277
  DurableAgentRunner,
@@ -745,7 +1287,7 @@ var AgentDurableHttpModule = class AgentDurableHttpModule2 {
745
1287
  __name(this, "AgentDurableHttpModule");
746
1288
  }
747
1289
  };
748
- AgentDurableHttpModule = _ts_decorate4([
1290
+ AgentDurableHttpModule = _ts_decorate5([
749
1291
  Global(),
750
1292
  Module({
751
1293
  providers: [
@@ -783,7 +1325,7 @@ var AgentDurableModule = class _AgentDurableModule {
783
1325
  };
784
1326
  }
785
1327
  };
786
- AgentDurableModule = _ts_decorate4([
1328
+ AgentDurableModule = _ts_decorate5([
787
1329
  Global(),
788
1330
  Module({
789
1331
  providers: [
@@ -800,15 +1342,15 @@ AgentDurableModule = _ts_decorate4([
800
1342
  ], AgentDurableModule);
801
1343
 
802
1344
  // src/agent.module.ts
803
- import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER12, AGENT_APPROVAL_PORT, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY7, AGENT_DURABLE_RUNNER as AGENT_DURABLE_RUNNER2, AGENT_MEMORY as AGENT_MEMORY3, AGENT_MODEL as AGENT_MODEL2, AGENT_MODEL_CATALOG as AGENT_MODEL_CATALOG3, AGENT_OPTIONS as AGENT_OPTIONS6, AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS3, AGENT_QUOTA_PROVIDER as AGENT_QUOTA_PROVIDER2, AGENT_REGISTRY as AGENT_REGISTRY6, AGENT_ROLES_POLICY as AGENT_ROLES_POLICY2, AGENT_RUNNER as AGENT_RUNNER2, AGENT_SINK as AGENT_SINK3, AGENT_SKILLS as AGENT_SKILLS3, AGENT_SKILL_SOURCES as AGENT_SKILL_SOURCES2, AGENT_STORE as AGENT_STORE6, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY3, AgentRegistry as AgentRegistry6, DefaultRolesPolicy, InMemoryAgentStore, ToolRegistry as ToolRegistry3 } from "@dudousxd/nestjs-agent-core";
804
- import { Global as Global2, Logger as Logger6, Module as Module2 } from "@nestjs/common";
1345
+ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER13, AGENT_APPROVAL_PORT, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY7, AGENT_DURABLE_RUNNER as AGENT_DURABLE_RUNNER2, AGENT_MEMORY as AGENT_MEMORY3, AGENT_MODEL as AGENT_MODEL2, AGENT_MODEL_CATALOG as AGENT_MODEL_CATALOG3, AGENT_OPTIONS as AGENT_OPTIONS7, AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS3, AGENT_QUOTA_PROVIDER as AGENT_QUOTA_PROVIDER3, AGENT_REGISTRY as AGENT_REGISTRY6, AGENT_ROLES_POLICY as AGENT_ROLES_POLICY2, AGENT_RUNNER as AGENT_RUNNER2, AGENT_SINK as AGENT_SINK4, AGENT_SKILLS as AGENT_SKILLS3, AGENT_SKILL_SOURCES as AGENT_SKILL_SOURCES2, AGENT_STORE as AGENT_STORE7, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY3, AgentRegistry as AgentRegistry6, DefaultRolesPolicy, InMemoryAgentStore, ToolRegistry as ToolRegistry3 } from "@dudousxd/nestjs-agent-core";
1346
+ import { Global as Global2, Logger as Logger7, Module as Module2 } from "@nestjs/common";
805
1347
  import { DiscoveryModule, ModulesContainer, RouterModule } from "@nestjs/core";
806
1348
 
807
1349
  // src/agent-deps.factory.ts
808
- import { AGENT_MEMORY, AGENT_MODEL, AGENT_PRICING_STORE, AGENT_PROMPT_CONTRIBUTORS, AGENT_REGISTRY, AGENT_ROLES_POLICY, AGENT_SINK as AGENT_SINK2, AGENT_SKILLS, AGENT_STORE as AGENT_STORE3, AGENT_TOOL_REGISTRY, AgentRegistry as AgentRegistry2, ToolRegistry as ToolRegistry2, normalizeDelegation, summarizeWithModel, windowHistory } from "@dudousxd/nestjs-agent-core";
809
- import { AGENT_OPTIONS } from "@dudousxd/nestjs-agent-core";
810
- import { Inject as Inject4, Injectable as Injectable4, Optional as Optional2 } from "@nestjs/common";
811
- function _ts_decorate5(decorators, target, key, desc) {
1350
+ import { AGENT_MEMORY, AGENT_MODEL, AGENT_PRICING_STORE, AGENT_PROMPT_CONTRIBUTORS, AGENT_REGISTRY, AGENT_ROLES_POLICY, AGENT_SINK as AGENT_SINK3, AGENT_SKILLS, AGENT_STORE as AGENT_STORE4, AGENT_TOOL_REGISTRY, AgentRegistry as AgentRegistry2, ToolRegistry as ToolRegistry2, normalizeDelegation, summarizeWithModel, windowHistory } from "@dudousxd/nestjs-agent-core";
1351
+ import { AGENT_OPTIONS as AGENT_OPTIONS2 } from "@dudousxd/nestjs-agent-core";
1352
+ import { Inject as Inject5, Injectable as Injectable5, Optional as Optional4 } from "@nestjs/common";
1353
+ function _ts_decorate6(decorators, target, key, desc) {
812
1354
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
813
1355
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
814
1356
  r = Reflect.decorate(decorators, target, key, desc);
@@ -821,19 +1363,19 @@ function _ts_decorate5(decorators, target, key, desc) {
821
1363
  }
822
1364
  return c > 3 && r && Object.defineProperty(target, key, r), r;
823
1365
  }
824
- __name(_ts_decorate5, "_ts_decorate");
825
- function _ts_metadata4(metadataKey, metadataValue) {
1366
+ __name(_ts_decorate6, "_ts_decorate");
1367
+ function _ts_metadata5(metadataKey, metadataValue) {
826
1368
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
827
1369
  return Reflect.metadata(metadataKey, metadataValue);
828
1370
  }
829
1371
  }
830
- __name(_ts_metadata4, "_ts_metadata");
831
- function _ts_param4(paramIndex, decorator) {
1372
+ __name(_ts_metadata5, "_ts_metadata");
1373
+ function _ts_param5(paramIndex, decorator) {
832
1374
  return function(target, key) {
833
1375
  decorator(target, key, paramIndex);
834
1376
  };
835
1377
  }
836
- __name(_ts_param4, "_ts_param");
1378
+ __name(_ts_param5, "_ts_param");
837
1379
  function delegateToolName(args) {
838
1380
  const slug = args.target.replace(/[^a-zA-Z0-9]+/g, "_");
839
1381
  return args.detached === true ? `start_${slug}` : `ask_${slug}`;
@@ -1030,24 +1572,24 @@ var AgentDepsFactory2 = class {
1030
1572
  return void 0;
1031
1573
  }
1032
1574
  };
1033
- AgentDepsFactory2 = _ts_decorate5([
1034
- Injectable4(),
1035
- _ts_param4(0, Inject4(AGENT_OPTIONS)),
1036
- _ts_param4(1, Inject4(AGENT_MODEL)),
1037
- _ts_param4(2, Inject4(AGENT_STORE3)),
1038
- _ts_param4(3, Inject4(AGENT_SINK2)),
1039
- _ts_param4(4, Inject4(AGENT_ROLES_POLICY)),
1040
- _ts_param4(5, Inject4(AGENT_TOOL_REGISTRY)),
1041
- _ts_param4(6, Inject4(AGENT_REGISTRY)),
1042
- _ts_param4(7, Inject4(AGENT_PROMPT_CONTRIBUTORS)),
1043
- _ts_param4(8, Optional2()),
1044
- _ts_param4(8, Inject4(AGENT_PRICING_STORE)),
1045
- _ts_param4(9, Optional2()),
1046
- _ts_param4(9, Inject4(AGENT_SKILLS)),
1047
- _ts_param4(10, Optional2()),
1048
- _ts_param4(10, Inject4(AGENT_MEMORY)),
1049
- _ts_metadata4("design:type", Function),
1050
- _ts_metadata4("design:paramtypes", [
1575
+ AgentDepsFactory2 = _ts_decorate6([
1576
+ Injectable5(),
1577
+ _ts_param5(0, Inject5(AGENT_OPTIONS2)),
1578
+ _ts_param5(1, Inject5(AGENT_MODEL)),
1579
+ _ts_param5(2, Inject5(AGENT_STORE4)),
1580
+ _ts_param5(3, Inject5(AGENT_SINK3)),
1581
+ _ts_param5(4, Inject5(AGENT_ROLES_POLICY)),
1582
+ _ts_param5(5, Inject5(AGENT_TOOL_REGISTRY)),
1583
+ _ts_param5(6, Inject5(AGENT_REGISTRY)),
1584
+ _ts_param5(7, Inject5(AGENT_PROMPT_CONTRIBUTORS)),
1585
+ _ts_param5(8, Optional4()),
1586
+ _ts_param5(8, Inject5(AGENT_PRICING_STORE)),
1587
+ _ts_param5(9, Optional4()),
1588
+ _ts_param5(9, Inject5(AGENT_SKILLS)),
1589
+ _ts_param5(10, Optional4()),
1590
+ _ts_param5(10, Inject5(AGENT_MEMORY)),
1591
+ _ts_metadata5("design:type", Function),
1592
+ _ts_metadata5("design:paramtypes", [
1051
1593
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
1052
1594
  typeof ModelProvider === "undefined" ? Object : ModelProvider,
1053
1595
  typeof AgentStore === "undefined" ? Object : AgentStore,
@@ -1063,9 +1605,9 @@ AgentDepsFactory2 = _ts_decorate5([
1063
1605
  ], AgentDepsFactory2);
1064
1606
 
1065
1607
  // src/agent.service.ts
1066
- import { AGENT_ATTACHMENT_STAGING, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY3, AGENT_MODEL_CATALOG, AGENT_OPTIONS as AGENT_OPTIONS2, AGENT_QUOTA_PROVIDER, AGENT_RUNNER, AGENT_STORE as AGENT_STORE4, REQUESTER_APPROVER, findCatalogModel, mayDecideApproval, readElicitationQuestions, validateElicitationAnswer } from "@dudousxd/nestjs-agent-core";
1067
- import { BadRequestException, ForbiddenException, GoneException, HttpException, HttpStatus, Inject as Inject5, Injectable as Injectable5, NotFoundException, NotImplementedException, Optional as Optional3 } from "@nestjs/common";
1068
- function _ts_decorate6(decorators, target, key, desc) {
1608
+ import { AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING2, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY3, AGENT_MODEL_CATALOG, AGENT_OPTIONS as AGENT_OPTIONS3, AGENT_QUOTA_PROVIDER as AGENT_QUOTA_PROVIDER2, AGENT_RUNNER, AGENT_STORE as AGENT_STORE5, REQUESTER_APPROVER, findCatalogModel, mayDecideApproval, readElicitationQuestions, validateElicitationAnswer } from "@dudousxd/nestjs-agent-core";
1609
+ import { BadRequestException, ConflictException, ForbiddenException, GoneException, HttpException, HttpStatus, Inject as Inject6, Injectable as Injectable6, NotFoundException, NotImplementedException as NotImplementedException2, Optional as Optional5 } from "@nestjs/common";
1610
+ function _ts_decorate7(decorators, target, key, desc) {
1069
1611
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1070
1612
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1071
1613
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1078,19 +1620,19 @@ function _ts_decorate6(decorators, target, key, desc) {
1078
1620
  }
1079
1621
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1080
1622
  }
1081
- __name(_ts_decorate6, "_ts_decorate");
1082
- function _ts_metadata5(metadataKey, metadataValue) {
1623
+ __name(_ts_decorate7, "_ts_decorate");
1624
+ function _ts_metadata6(metadataKey, metadataValue) {
1083
1625
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1084
1626
  return Reflect.metadata(metadataKey, metadataValue);
1085
1627
  }
1086
1628
  }
1087
- __name(_ts_metadata5, "_ts_metadata");
1088
- function _ts_param5(paramIndex, decorator) {
1629
+ __name(_ts_metadata6, "_ts_metadata");
1630
+ function _ts_param6(paramIndex, decorator) {
1089
1631
  return function(target, key) {
1090
1632
  decorator(target, key, paramIndex);
1091
1633
  };
1092
1634
  }
1093
- __name(_ts_param5, "_ts_param");
1635
+ __name(_ts_param6, "_ts_param");
1094
1636
  var AgentService = class {
1095
1637
  static {
1096
1638
  __name(this, "AgentService");
@@ -1102,7 +1644,8 @@ var AgentService = class {
1102
1644
  models;
1103
1645
  quotaProvider;
1104
1646
  options;
1105
- constructor(runner, store, deps, staging, models, quotaProvider, options) {
1647
+ queue;
1648
+ constructor(runner, store, deps, staging, models, quotaProvider, options, queue) {
1106
1649
  this.runner = runner;
1107
1650
  this.store = store;
1108
1651
  this.deps = deps;
@@ -1110,6 +1653,19 @@ var AgentService = class {
1110
1653
  this.models = models;
1111
1654
  this.quotaProvider = quotaProvider;
1112
1655
  this.options = options;
1656
+ this.queue = queue;
1657
+ }
1658
+ /** The queue service when the bound store can hold a queue, else `undefined`. */
1659
+ queueing() {
1660
+ return this.queue?.supported === true ? this.queue : void 0;
1661
+ }
1662
+ /** The queue service, or a 501 naming what is missing. */
1663
+ requireQueue() {
1664
+ const queue = this.queueing();
1665
+ if (queue === void 0) {
1666
+ throw new NotImplementedException2("Queueing messages requires an AgentStore that implements ChatQueueStore; the bound store does not.");
1667
+ }
1668
+ return queue;
1113
1669
  }
1114
1670
  /**
1115
1671
  * The actor's budget across windows (`GET <base>/quota`) — the bound {@link QuotaProvider}'s
@@ -1220,7 +1776,44 @@ var AgentService = class {
1220
1776
  }
1221
1777
  return (await this.store.getThread(threadId))?.model ?? null;
1222
1778
  }
1779
+ /**
1780
+ * Start a turn — for in-process callers that need a run id back. A send that would have to wait
1781
+ * (its thread already has a turn running) is refused with `409` instead; {@link send} is the form
1782
+ * that queues it.
1783
+ */
1223
1784
  async chat(params) {
1785
+ const result = await this.send({
1786
+ ...params,
1787
+ mode: "auto"
1788
+ });
1789
+ if (result.queued !== true) {
1790
+ return result;
1791
+ }
1792
+ if (result.runId !== void 0) {
1793
+ return {
1794
+ runId: result.runId,
1795
+ threadId: result.threadId
1796
+ };
1797
+ }
1798
+ const store = this.requireQueue().queueStore();
1799
+ if (!await store.removeQueuedMessage(result.messageId)) {
1800
+ return {
1801
+ runId: result.messageId,
1802
+ threadId: result.threadId
1803
+ };
1804
+ }
1805
+ await this.requireQueue().publish(result.threadId);
1806
+ throw new ConflictException({
1807
+ statusCode: 409,
1808
+ code: "run_active",
1809
+ message: `thread ${result.threadId} already has a turn running`
1810
+ });
1811
+ }
1812
+ /**
1813
+ * Send a message: start a turn, or — when its thread already has one running — queue the message
1814
+ * to run after it (see {@link ChatSendMode}). What `POST <base>/chat` calls.
1815
+ */
1816
+ async send(params) {
1224
1817
  await this.assertWithinQuota(params.actor);
1225
1818
  const agentName = await this.resolveAgentName(params.agentName, params.threadId);
1226
1819
  const model = await this.resolveModel(params.actor, agentName, params.model, params.threadId);
@@ -1237,7 +1830,7 @@ var AgentService = class {
1237
1830
  } : {}
1238
1831
  });
1239
1832
  threadId = created.id;
1240
- } else if (params.regenerate === true) {
1833
+ } else {
1241
1834
  await this.assertOwnsThread(params.actor, threadId);
1242
1835
  }
1243
1836
  const input = {
@@ -1259,13 +1852,248 @@ var AgentService = class {
1259
1852
  model
1260
1853
  } : {}
1261
1854
  };
1262
- const { runId } = await this.runner.start(input);
1263
- await this.store.setActiveStream(threadId, runId);
1855
+ const queue = this.queueing();
1856
+ if (queue === void 0) {
1857
+ const { runId } = await this.runner.start(input);
1858
+ await this.store.setActiveStream(threadId, runId);
1859
+ return {
1860
+ runId,
1861
+ threadId
1862
+ };
1863
+ }
1864
+ const mode = params.mode ?? "auto";
1865
+ const { live, stale } = await queue.holder(threadId, this.runner);
1866
+ if (live === null && mode !== "queue") {
1867
+ const runId = crypto.randomUUID();
1868
+ if (await queue.queueStore().claimActiveStream(threadId, runId, stale !== null ? {
1869
+ replacing: stale
1870
+ } : {})) {
1871
+ return {
1872
+ runId: await this.startClaimed(input, runId),
1873
+ threadId
1874
+ };
1875
+ }
1876
+ }
1877
+ if (params.regenerate === true) {
1878
+ throw new ConflictException({
1879
+ statusCode: 409,
1880
+ code: "run_active",
1881
+ message: "cannot regenerate while a turn is running on this thread"
1882
+ });
1883
+ }
1884
+ return this.enqueue(queue, input, mode, live);
1885
+ }
1886
+ /**
1887
+ * Start a turn the thread is already claimed for, under the claimed id. A runner that minted an
1888
+ * id of its own anyway gets the thread re-pointed at it; one that fails to start frees the thread.
1889
+ */
1890
+ async startClaimed(input, runId) {
1891
+ const store = this.requireQueue().queueStore();
1892
+ let started;
1893
+ try {
1894
+ started = (await this.runner.start(input, {
1895
+ runId
1896
+ })).runId;
1897
+ } catch (error) {
1898
+ await store.releaseActiveStream(input.threadId, runId);
1899
+ throw error;
1900
+ }
1901
+ if (started !== runId) {
1902
+ await store.claimActiveStream(input.threadId, started, {
1903
+ replacing: runId
1904
+ });
1905
+ }
1906
+ return started;
1907
+ }
1908
+ /** Put a send in its thread's queue, then drain it if the thread turned out to be free. */
1909
+ async enqueue(queue, input, mode, live) {
1910
+ const store = queue.queueStore();
1911
+ const threadId = input.threadId;
1912
+ const interrupting = mode === "interrupt" && live !== null ? live : void 0;
1913
+ const queued = await store.enqueueMessage({
1914
+ threadId,
1915
+ actor: input.actor,
1916
+ content: input.userText,
1917
+ ...input.attachments !== void 0 ? {
1918
+ attachments: input.attachments
1919
+ } : {},
1920
+ ...input.agentName !== void 0 ? {
1921
+ agentName: input.agentName
1922
+ } : {},
1923
+ ...input.model !== void 0 ? {
1924
+ model: input.model
1925
+ } : {},
1926
+ ...input.pageContext !== void 0 ? {
1927
+ pageContext: input.pageContext
1928
+ } : {},
1929
+ ...interrupting !== void 0 ? {
1930
+ interrupt: true,
1931
+ at: "head"
1932
+ } : {}
1933
+ });
1934
+ let runId;
1935
+ if (interrupting !== void 0) {
1936
+ await store.setQueuePause(threadId, null);
1937
+ await queue.publish(threadId);
1938
+ await this.runner.cancel(interrupting);
1939
+ } else {
1940
+ runId = await queue.kick(threadId, this.runner);
1941
+ if (runId === void 0) {
1942
+ await queue.publish(threadId);
1943
+ }
1944
+ }
1945
+ const state = await queue.state(threadId);
1946
+ const position = state.items.findIndex((item) => item.id === queued.id);
1264
1947
  return {
1265
- runId,
1266
- threadId
1948
+ threadId,
1949
+ queued: true,
1950
+ messageId: queued.id,
1951
+ position: position === -1 ? 0 : position,
1952
+ queue: state,
1953
+ ...runId !== void 0 && runId === queued.id ? {
1954
+ runId
1955
+ } : {},
1956
+ ...interrupting !== void 0 ? {
1957
+ interrupting
1958
+ } : {}
1267
1959
  };
1268
1960
  }
1961
+ /** `GET <base>/threads/:id/queue` — the thread's waiting messages and whether it drains. */
1962
+ async getQueue(actor, threadId) {
1963
+ await this.assertOwnsThread(actor, threadId);
1964
+ return this.requireQueue().state(threadId);
1965
+ }
1966
+ /**
1967
+ * `PATCH <base>/queue/:messageId` — change a waiting message's text and/or attachments, and/or move
1968
+ * it to `position` in the queue. Answers the thread's queue.
1969
+ */
1970
+ async updateQueuedMessage(actor, messageId, patch) {
1971
+ const queue = this.requireQueue();
1972
+ const store = queue.queueStore();
1973
+ const threadId = await this.assertOwnsQueuedMessage(actor, messageId);
1974
+ if (patch.message !== void 0 && patch.message.trim().length === 0) {
1975
+ throw new BadRequestException("message must not be empty");
1976
+ }
1977
+ const attachments = patch.attachments === void 0 || patch.attachments === null ? patch.attachments : await this.resolveAttachments(actor, patch.attachments);
1978
+ if (patch.message !== void 0 || attachments !== void 0) {
1979
+ const updated = await store.updateQueuedMessage(messageId, {
1980
+ ...patch.message !== void 0 ? {
1981
+ content: patch.message
1982
+ } : {},
1983
+ ...attachments !== void 0 ? {
1984
+ attachments
1985
+ } : {}
1986
+ });
1987
+ if (updated === null) {
1988
+ throw new GoneException(`queued message ${messageId} already started or was removed`);
1989
+ }
1990
+ }
1991
+ if (patch.position !== void 0) {
1992
+ if (!Number.isInteger(patch.position) || patch.position < 0) {
1993
+ throw new BadRequestException("position must be a non-negative integer");
1994
+ }
1995
+ if (!await store.moveQueuedMessage(messageId, patch.position)) {
1996
+ throw new GoneException(`queued message ${messageId} already started or was removed`);
1997
+ }
1998
+ }
1999
+ return queue.publish(threadId);
2000
+ }
2001
+ /** `DELETE <base>/queue/:messageId` — drop a waiting message. Answers the thread's queue. */
2002
+ async removeQueuedMessage(actor, messageId) {
2003
+ const queue = this.requireQueue();
2004
+ const threadId = await this.assertOwnsQueuedMessage(actor, messageId);
2005
+ if (!await queue.queueStore().removeQueuedMessage(messageId)) {
2006
+ throw new GoneException(`queued message ${messageId} already started or was removed`);
2007
+ }
2008
+ return queue.publish(threadId);
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
+ }
2063
+ /** `DELETE <base>/threads/:id/queue` — drop every waiting message (and any pause). */
2064
+ async clearQueue(actor, threadId) {
2065
+ await this.assertOwnsThread(actor, threadId);
2066
+ const queue = this.requireQueue();
2067
+ await queue.queueStore().clearQueue(threadId);
2068
+ await queue.queueStore().setQueuePause(threadId, null);
2069
+ return queue.publish(threadId);
2070
+ }
2071
+ /**
2072
+ * `POST <base>/threads/:id/queue/resume` — lift a pause and start the head when nothing is
2073
+ * running. Answers the queue, and the run the head started under, if it did.
2074
+ */
2075
+ async resumeQueue(actor, threadId) {
2076
+ await this.assertOwnsThread(actor, threadId);
2077
+ const queue = this.requireQueue();
2078
+ await queue.queueStore().setQueuePause(threadId, null);
2079
+ const runId = await queue.kick(threadId, this.runner);
2080
+ const state = runId === void 0 ? await queue.publish(threadId) : await queue.state(threadId);
2081
+ return {
2082
+ ...state,
2083
+ ...runId !== void 0 ? {
2084
+ runId
2085
+ } : {}
2086
+ };
2087
+ }
2088
+ /** The thread a queued message waits on, once the caller is shown to own it. */
2089
+ async assertOwnsQueuedMessage(actor, messageId) {
2090
+ const message = await this.requireQueue().queueStore().getQueuedMessage(messageId);
2091
+ if (message === null) {
2092
+ throw new NotFoundException(`queued message ${messageId} not found`);
2093
+ }
2094
+ await this.assertOwnsThread(actor, message.threadId);
2095
+ return message.threadId;
2096
+ }
1269
2097
  /**
1270
2098
  * Rebuild this turn's attachments from the staging store, keyed by the ids the caller claimed.
1271
2099
  * The model provider fetches {@link MessageAttachment.url} verbatim, so that url is only ever
@@ -1282,7 +2110,7 @@ var AgentService = class {
1282
2110
  }
1283
2111
  const staging = this.staging;
1284
2112
  if (staging === void 0 || typeof staging.resolve !== "function") {
1285
- throw new NotImplementedException("Message attachments require an AGENT_ATTACHMENT_STAGING provider implementing resolve(); attachment urls are never taken from the request.");
2113
+ throw new NotImplementedException2("Message attachments require an AGENT_ATTACHMENT_STAGING provider implementing resolve(); attachment urls are never taken from the request.");
1286
2114
  }
1287
2115
  const resolved = [];
1288
2116
  for (const ref of refs) {
@@ -1440,7 +2268,7 @@ var AgentService = class {
1440
2268
  return;
1441
2269
  }
1442
2270
  if (this.store.updateThread === void 0) {
1443
- throw new NotImplementedException("Setting a thread's defaultAgent or model requires an AgentStore that implements updateThread(); the bound store does not support it.");
2271
+ throw new NotImplementedException2("Setting a thread's defaultAgent or model requires an AgentStore that implements updateThread(); the bound store does not support it.");
1444
2272
  }
1445
2273
  const model = patch.model === void 0 || patch.model === null ? patch.model : await this.assertModelAllowed(actor, patch.defaultAgent ?? await this.resolveAgentName(void 0, threadId), patch.model);
1446
2274
  await this.store.updateThread(threadId, {
@@ -1505,9 +2333,13 @@ var AgentService = class {
1505
2333
  }
1506
2334
  async toDetailView(thread, actor) {
1507
2335
  const summary = await this.toSummaryView(thread);
2336
+ const queue = this.queueing();
1508
2337
  return {
1509
2338
  ...summary,
1510
- messages: await this.freshAttachmentUrls(thread.messages, actor)
2339
+ messages: await this.freshAttachmentUrls(thread.messages, actor),
2340
+ ...queue !== void 0 ? {
2341
+ queue: await queue.state(thread.id)
2342
+ } : {}
1511
2343
  };
1512
2344
  }
1513
2345
  /**
@@ -1570,7 +2402,7 @@ var AgentService = class {
1570
2402
  throw new BadRequestException("comment must be at most 2000 characters");
1571
2403
  }
1572
2404
  if (this.store.threadOfMessage === void 0 || this.store.setMessageFeedback === void 0) {
1573
- throw new NotImplementedException("Message feedback requires an AgentStore that implements threadOfMessage() and setMessageFeedback(); the bound store does not support it.");
2405
+ throw new NotImplementedException2("Message feedback requires an AgentStore that implements threadOfMessage() and setMessageFeedback(); the bound store does not support it.");
1574
2406
  }
1575
2407
  const threadId = await this.store.threadOfMessage(messageId);
1576
2408
  if (threadId === null) {
@@ -1622,7 +2454,7 @@ var AgentService = class {
1622
2454
  const list = this.attachmentInventory();
1623
2455
  const referencedMediaIds = this.store.referencedMediaIds?.bind(this.store);
1624
2456
  if (referencedMediaIds === void 0) {
1625
- throw new NotImplementedException("Collecting attachments requires an AgentStore that implements referencedMediaIds(); the bound store cannot say which media a message still references, and guessing would delete files that are in use.");
2457
+ throw new NotImplementedException2("Collecting attachments requires an AgentStore that implements referencedMediaIds(); the bound store cannot say which media a message still references, and guessing would delete files that are in use.");
1626
2458
  }
1627
2459
  const stagedBefore = options.olderThan.toISOString();
1628
2460
  const inventory = await list({
@@ -1644,7 +2476,7 @@ var AgentService = class {
1644
2476
  attachmentInventory() {
1645
2477
  const list = this.staging?.list?.bind(this.staging);
1646
2478
  if (list === void 0) {
1647
- throw new NotImplementedException("Listing attachments requires an AGENT_ATTACHMENT_STAGING provider implementing list(); the host owns the staged bytes, so only it can enumerate them.");
2479
+ throw new NotImplementedException2("Listing attachments requires an AGENT_ATTACHMENT_STAGING provider implementing list(); the host owns the staged bytes, so only it can enumerate them.");
1648
2480
  }
1649
2481
  return list;
1650
2482
  }
@@ -1762,34 +2594,36 @@ var AgentService = class {
1762
2594
  }
1763
2595
  }
1764
2596
  };
1765
- AgentService = _ts_decorate6([
1766
- Injectable5(),
1767
- _ts_param5(0, Inject5(AGENT_RUNNER)),
1768
- _ts_param5(1, Inject5(AGENT_STORE4)),
1769
- _ts_param5(2, Inject5(AGENT_DEPS_FACTORY3)),
1770
- _ts_param5(3, Optional3()),
1771
- _ts_param5(3, Inject5(AGENT_ATTACHMENT_STAGING)),
1772
- _ts_param5(4, Optional3()),
1773
- _ts_param5(4, Inject5(AGENT_MODEL_CATALOG)),
1774
- _ts_param5(5, Optional3()),
1775
- _ts_param5(5, Inject5(AGENT_QUOTA_PROVIDER)),
1776
- _ts_param5(6, Optional3()),
1777
- _ts_param5(6, Inject5(AGENT_OPTIONS2)),
1778
- _ts_metadata5("design:type", Function),
1779
- _ts_metadata5("design:paramtypes", [
2597
+ AgentService = _ts_decorate7([
2598
+ Injectable6(),
2599
+ _ts_param6(0, Inject6(AGENT_RUNNER)),
2600
+ _ts_param6(1, Inject6(AGENT_STORE5)),
2601
+ _ts_param6(2, Inject6(AGENT_DEPS_FACTORY3)),
2602
+ _ts_param6(3, Optional5()),
2603
+ _ts_param6(3, Inject6(AGENT_ATTACHMENT_STAGING2)),
2604
+ _ts_param6(4, Optional5()),
2605
+ _ts_param6(4, Inject6(AGENT_MODEL_CATALOG)),
2606
+ _ts_param6(5, Optional5()),
2607
+ _ts_param6(5, Inject6(AGENT_QUOTA_PROVIDER2)),
2608
+ _ts_param6(6, Optional5()),
2609
+ _ts_param6(6, Inject6(AGENT_OPTIONS3)),
2610
+ _ts_param6(7, Optional5()),
2611
+ _ts_metadata6("design:type", Function),
2612
+ _ts_metadata6("design:paramtypes", [
1780
2613
  typeof AgentRunner === "undefined" ? Object : AgentRunner,
1781
2614
  typeof AgentStore === "undefined" ? Object : AgentStore,
1782
2615
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
1783
2616
  typeof AttachmentStagingStore === "undefined" ? Object : AttachmentStagingStore,
1784
2617
  typeof ModelCatalog === "undefined" ? Object : ModelCatalog,
1785
2618
  typeof QuotaProvider === "undefined" ? Object : QuotaProvider,
1786
- typeof Pick === "undefined" ? Object : Pick
2619
+ typeof Pick === "undefined" ? Object : Pick,
2620
+ typeof ChatQueueService === "undefined" ? Object : ChatQueueService
1787
2621
  ])
1788
2622
  ], AgentService);
1789
2623
 
1790
2624
  // src/approval-port.adapter.ts
1791
- import { Injectable as Injectable6 } from "@nestjs/common";
1792
- function _ts_decorate7(decorators, target, key, desc) {
2625
+ import { Injectable as Injectable7 } from "@nestjs/common";
2626
+ function _ts_decorate8(decorators, target, key, desc) {
1793
2627
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1794
2628
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1795
2629
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1802,13 +2636,13 @@ function _ts_decorate7(decorators, target, key, desc) {
1802
2636
  }
1803
2637
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1804
2638
  }
1805
- __name(_ts_decorate7, "_ts_decorate");
1806
- function _ts_metadata6(metadataKey, metadataValue) {
2639
+ __name(_ts_decorate8, "_ts_decorate");
2640
+ function _ts_metadata7(metadataKey, metadataValue) {
1807
2641
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1808
2642
  return Reflect.metadata(metadataKey, metadataValue);
1809
2643
  }
1810
2644
  }
1811
- __name(_ts_metadata6, "_ts_metadata");
2645
+ __name(_ts_metadata7, "_ts_metadata");
1812
2646
  var AgentApprovalPortAdapter = class {
1813
2647
  static {
1814
2648
  __name(this, "AgentApprovalPortAdapter");
@@ -1846,18 +2680,18 @@ var AgentApprovalPortAdapter = class {
1846
2680
  });
1847
2681
  }
1848
2682
  };
1849
- AgentApprovalPortAdapter = _ts_decorate7([
1850
- Injectable6(),
1851
- _ts_metadata6("design:type", Function),
1852
- _ts_metadata6("design:paramtypes", [
2683
+ AgentApprovalPortAdapter = _ts_decorate8([
2684
+ Injectable7(),
2685
+ _ts_metadata7("design:type", Function),
2686
+ _ts_metadata7("design:paramtypes", [
1853
2687
  typeof AgentService === "undefined" ? Object : AgentService
1854
2688
  ])
1855
2689
  ], AgentApprovalPortAdapter);
1856
2690
 
1857
2691
  // src/controller/agents.controller.ts
1858
2692
  import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY4, AGENT_REGISTRY as AGENT_REGISTRY2, AgentRegistry as AgentRegistry3 } from "@dudousxd/nestjs-agent-core";
1859
- import { Controller, Get, Inject as Inject6 } from "@nestjs/common";
1860
- function _ts_decorate8(decorators, target, key, desc) {
2693
+ import { Controller, Get, Inject as Inject7 } from "@nestjs/common";
2694
+ function _ts_decorate9(decorators, target, key, desc) {
1861
2695
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1862
2696
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1863
2697
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1870,19 +2704,19 @@ function _ts_decorate8(decorators, target, key, desc) {
1870
2704
  }
1871
2705
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1872
2706
  }
1873
- __name(_ts_decorate8, "_ts_decorate");
1874
- function _ts_metadata7(metadataKey, metadataValue) {
2707
+ __name(_ts_decorate9, "_ts_decorate");
2708
+ function _ts_metadata8(metadataKey, metadataValue) {
1875
2709
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1876
2710
  return Reflect.metadata(metadataKey, metadataValue);
1877
2711
  }
1878
2712
  }
1879
- __name(_ts_metadata7, "_ts_metadata");
1880
- function _ts_param6(paramIndex, decorator) {
2713
+ __name(_ts_metadata8, "_ts_metadata");
2714
+ function _ts_param7(paramIndex, decorator) {
1881
2715
  return function(target, key) {
1882
2716
  decorator(target, key, paramIndex);
1883
2717
  };
1884
2718
  }
1885
- __name(_ts_param6, "_ts_param");
2719
+ __name(_ts_param7, "_ts_param");
1886
2720
  var AgentsController = class {
1887
2721
  static {
1888
2722
  __name(this, "AgentsController");
@@ -1904,26 +2738,26 @@ var AgentsController = class {
1904
2738
  }));
1905
2739
  }
1906
2740
  };
1907
- _ts_decorate8([
2741
+ _ts_decorate9([
1908
2742
  Get(),
1909
- _ts_metadata7("design:type", Function),
1910
- _ts_metadata7("design:paramtypes", []),
1911
- _ts_metadata7("design:returntype", Array)
2743
+ _ts_metadata8("design:type", Function),
2744
+ _ts_metadata8("design:paramtypes", []),
2745
+ _ts_metadata8("design:returntype", Array)
1912
2746
  ], AgentsController.prototype, "list", null);
1913
- AgentsController = _ts_decorate8([
2747
+ AgentsController = _ts_decorate9([
1914
2748
  Controller("agents"),
1915
- _ts_param6(0, Inject6(AGENT_REGISTRY2)),
1916
- _ts_param6(1, Inject6(AGENT_DEPS_FACTORY4)),
1917
- _ts_metadata7("design:type", Function),
1918
- _ts_metadata7("design:paramtypes", [
2749
+ _ts_param7(0, Inject7(AGENT_REGISTRY2)),
2750
+ _ts_param7(1, Inject7(AGENT_DEPS_FACTORY4)),
2751
+ _ts_metadata8("design:type", Function),
2752
+ _ts_metadata8("design:paramtypes", [
1919
2753
  typeof AgentRegistry3 === "undefined" ? Object : AgentRegistry3,
1920
2754
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory
1921
2755
  ])
1922
2756
  ], AgentsController);
1923
2757
 
1924
2758
  // src/controller/attachments.controller.ts
1925
- import { AGENT_ACTOR_RESOLVER, AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING2, AGENT_OPTIONS as AGENT_OPTIONS3 } from "@dudousxd/nestjs-agent-core";
1926
- import { BadRequestException as BadRequestException2, Controller as Controller2, Get as Get2, Inject as Inject7, NotImplementedException as NotImplementedException2, Optional as Optional4, PayloadTooLargeException, Post, Req, UnsupportedMediaTypeException, UploadedFile, UseInterceptors } from "@nestjs/common";
2759
+ import { AGENT_ACTOR_RESOLVER, AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING3, AGENT_OPTIONS as AGENT_OPTIONS4 } from "@dudousxd/nestjs-agent-core";
2760
+ import { BadRequestException as BadRequestException2, Controller as Controller2, Get as Get2, Inject as Inject8, NotImplementedException as NotImplementedException3, Optional as Optional6, PayloadTooLargeException, Post, Req, UnsupportedMediaTypeException, UploadedFile, UseInterceptors } from "@nestjs/common";
1927
2761
  import { FileInterceptor } from "@nestjs/platform-express";
1928
2762
 
1929
2763
  // src/attachment-limits.ts
@@ -1952,7 +2786,7 @@ function attachmentLimits(options, staging) {
1952
2786
  __name(attachmentLimits, "attachmentLimits");
1953
2787
 
1954
2788
  // src/controller/attachments.controller.ts
1955
- function _ts_decorate9(decorators, target, key, desc) {
2789
+ function _ts_decorate10(decorators, target, key, desc) {
1956
2790
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1957
2791
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1958
2792
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1965,19 +2799,19 @@ function _ts_decorate9(decorators, target, key, desc) {
1965
2799
  }
1966
2800
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1967
2801
  }
1968
- __name(_ts_decorate9, "_ts_decorate");
1969
- function _ts_metadata8(metadataKey, metadataValue) {
2802
+ __name(_ts_decorate10, "_ts_decorate");
2803
+ function _ts_metadata9(metadataKey, metadataValue) {
1970
2804
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1971
2805
  return Reflect.metadata(metadataKey, metadataValue);
1972
2806
  }
1973
2807
  }
1974
- __name(_ts_metadata8, "_ts_metadata");
1975
- function _ts_param7(paramIndex, decorator) {
2808
+ __name(_ts_metadata9, "_ts_metadata");
2809
+ function _ts_param8(paramIndex, decorator) {
1976
2810
  return function(target, key) {
1977
2811
  decorator(target, key, paramIndex);
1978
2812
  };
1979
2813
  }
1980
- __name(_ts_param7, "_ts_param");
2814
+ __name(_ts_param8, "_ts_param");
1981
2815
  var HARD_MAX_ATTACHMENT_BYTES = 32 * 1024 * 1024;
1982
2816
  var ATTACHMENT_PAGE_SIZE = 50;
1983
2817
  var AttachmentsController = class {
@@ -2011,7 +2845,7 @@ var AttachmentsController = class {
2011
2845
  }
2012
2846
  async upload(req, file) {
2013
2847
  if (this.staging === void 0) {
2014
- throw new NotImplementedException2("Attachment upload is not configured on this server: bind AGENT_ATTACHMENT_STAGING (e.g. import AgentMediaAttachmentsModule).");
2848
+ throw new NotImplementedException3("Attachment upload is not configured on this server: bind AGENT_ATTACHMENT_STAGING (e.g. import AgentMediaAttachmentsModule).");
2015
2849
  }
2016
2850
  if (file === void 0) {
2017
2851
  throw new BadRequestException2('multipart field "file" is required');
@@ -2033,39 +2867,39 @@ var AttachmentsController = class {
2033
2867
  });
2034
2868
  }
2035
2869
  };
2036
- _ts_decorate9([
2870
+ _ts_decorate10([
2037
2871
  Get2(),
2038
- _ts_param7(0, Req()),
2039
- _ts_metadata8("design:type", Function),
2040
- _ts_metadata8("design:paramtypes", [
2872
+ _ts_param8(0, Req()),
2873
+ _ts_metadata9("design:type", Function),
2874
+ _ts_metadata9("design:paramtypes", [
2041
2875
  typeof Request === "undefined" ? Object : Request
2042
2876
  ]),
2043
- _ts_metadata8("design:returntype", Promise)
2877
+ _ts_metadata9("design:returntype", Promise)
2044
2878
  ], AttachmentsController.prototype, "list", null);
2045
- _ts_decorate9([
2879
+ _ts_decorate10([
2046
2880
  Post(),
2047
2881
  UseInterceptors(FileInterceptor("file", {
2048
2882
  limits: {
2049
2883
  fileSize: HARD_MAX_ATTACHMENT_BYTES
2050
2884
  }
2051
2885
  })),
2052
- _ts_param7(0, Req()),
2053
- _ts_param7(1, UploadedFile()),
2054
- _ts_metadata8("design:type", Function),
2055
- _ts_metadata8("design:paramtypes", [
2886
+ _ts_param8(0, Req()),
2887
+ _ts_param8(1, UploadedFile()),
2888
+ _ts_metadata9("design:type", Function),
2889
+ _ts_metadata9("design:paramtypes", [
2056
2890
  typeof Request === "undefined" ? Object : Request,
2057
2891
  Object
2058
2892
  ]),
2059
- _ts_metadata8("design:returntype", Promise)
2893
+ _ts_metadata9("design:returntype", Promise)
2060
2894
  ], AttachmentsController.prototype, "upload", null);
2061
- AttachmentsController = _ts_decorate9([
2895
+ AttachmentsController = _ts_decorate10([
2062
2896
  Controller2("attachments"),
2063
- _ts_param7(0, Inject7(AGENT_OPTIONS3)),
2064
- _ts_param7(1, Inject7(AGENT_ACTOR_RESOLVER)),
2065
- _ts_param7(3, Optional4()),
2066
- _ts_param7(3, Inject7(AGENT_ATTACHMENT_STAGING2)),
2067
- _ts_metadata8("design:type", Function),
2068
- _ts_metadata8("design:paramtypes", [
2897
+ _ts_param8(0, Inject8(AGENT_OPTIONS4)),
2898
+ _ts_param8(1, Inject8(AGENT_ACTOR_RESOLVER)),
2899
+ _ts_param8(3, Optional6()),
2900
+ _ts_param8(3, Inject8(AGENT_ATTACHMENT_STAGING3)),
2901
+ _ts_metadata9("design:type", Function),
2902
+ _ts_metadata9("design:paramtypes", [
2069
2903
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
2070
2904
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
2071
2905
  typeof AgentService === "undefined" ? Object : AgentService,
@@ -2075,8 +2909,8 @@ AttachmentsController = _ts_decorate9([
2075
2909
 
2076
2910
  // src/controller/chat.controller.ts
2077
2911
  import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER2, AgentStreamError as AgentStreamError2 } from "@dudousxd/nestjs-agent-core";
2078
- import { BadRequestException as BadRequestException3, Body, Controller as Controller3, Get as Get3, Inject as Inject8, Param, Post as Post2, Query, Req as Req2, Res } from "@nestjs/common";
2079
- function _ts_decorate10(decorators, target, key, desc) {
2912
+ import { BadRequestException as BadRequestException3, Body, Controller as Controller3, Get as Get3, Inject as Inject9, Param, Post as Post2, Query, Req as Req2, Res } from "@nestjs/common";
2913
+ function _ts_decorate11(decorators, target, key, desc) {
2080
2914
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2081
2915
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2082
2916
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2089,19 +2923,32 @@ function _ts_decorate10(decorators, target, key, desc) {
2089
2923
  }
2090
2924
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2091
2925
  }
2092
- __name(_ts_decorate10, "_ts_decorate");
2093
- function _ts_metadata9(metadataKey, metadataValue) {
2926
+ __name(_ts_decorate11, "_ts_decorate");
2927
+ function _ts_metadata10(metadataKey, metadataValue) {
2094
2928
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2095
2929
  return Reflect.metadata(metadataKey, metadataValue);
2096
2930
  }
2097
2931
  }
2098
- __name(_ts_metadata9, "_ts_metadata");
2099
- function _ts_param8(paramIndex, decorator) {
2932
+ __name(_ts_metadata10, "_ts_metadata");
2933
+ function _ts_param9(paramIndex, decorator) {
2100
2934
  return function(target, key) {
2101
2935
  decorator(target, key, paramIndex);
2102
2936
  };
2103
2937
  }
2104
- __name(_ts_param8, "_ts_param");
2938
+ __name(_ts_param9, "_ts_param");
2939
+ function sendMode(body) {
2940
+ if (body.interrupt === true) {
2941
+ return "interrupt";
2942
+ }
2943
+ if (body.mode === void 0 || body.mode === null) {
2944
+ return "auto";
2945
+ }
2946
+ if (body.mode === "auto" || body.mode === "queue" || body.mode === "interrupt") {
2947
+ return body.mode;
2948
+ }
2949
+ throw new BadRequestException3("mode must be 'auto', 'queue' or 'interrupt'");
2950
+ }
2951
+ __name(sendMode, "sendMode");
2105
2952
  function attachmentRefs(claimed) {
2106
2953
  if (claimed === void 0) {
2107
2954
  return [];
@@ -2139,10 +2986,17 @@ var ChatController = class {
2139
2986
  this.agent = agent;
2140
2987
  this.actorResolver = actorResolver;
2141
2988
  }
2989
+ /**
2990
+ * Start a turn and stream it — or, when the thread already has one running, queue the message and
2991
+ * answer `202 { queued: true, messageId, position, queue, … }` (JSON, no stream): it runs when the
2992
+ * turn ahead of it settles, and the stream of the run holding the thread announces it with a
2993
+ * `queue` frame.
2994
+ */
2142
2995
  async chat(req, res, body) {
2143
2996
  const actor = await this.actorResolver.resolve(req);
2144
2997
  const attachments = attachmentRefs(body.attachments);
2145
- const { runId, threadId } = await this.agent.chat({
2998
+ const mode = sendMode(body);
2999
+ const result = await this.agent.send({
2146
3000
  actor,
2147
3001
  message: body.message,
2148
3002
  ...body.threadId !== void 0 ? {
@@ -2165,8 +3019,14 @@ var ChatController = class {
2165
3019
  } : {},
2166
3020
  ...typeof body.model === "string" && body.model.length > 0 ? {
2167
3021
  model: body.model
2168
- } : {}
3022
+ } : {},
3023
+ mode
2169
3024
  });
3025
+ if (result.queued === true) {
3026
+ res.status(202).json(result);
3027
+ return;
3028
+ }
3029
+ const { runId, threadId } = result;
2170
3030
  await this.pipe(res, runId, this.agent.subscribe(runId), threadId);
2171
3031
  }
2172
3032
  /**
@@ -2256,50 +3116,50 @@ data: ${JSON.stringify(payload)}
2256
3116
  res.end();
2257
3117
  }
2258
3118
  };
2259
- _ts_decorate10([
3119
+ _ts_decorate11([
2260
3120
  Post2("chat"),
2261
- _ts_param8(0, Req2()),
2262
- _ts_param8(1, Res()),
2263
- _ts_param8(2, Body()),
2264
- _ts_metadata9("design:type", Function),
2265
- _ts_metadata9("design:paramtypes", [
3121
+ _ts_param9(0, Req2()),
3122
+ _ts_param9(1, Res()),
3123
+ _ts_param9(2, Body()),
3124
+ _ts_metadata10("design:type", Function),
3125
+ _ts_metadata10("design:paramtypes", [
2266
3126
  typeof Request === "undefined" ? Object : Request,
2267
3127
  typeof Response === "undefined" ? Object : Response,
2268
3128
  typeof ChatBody === "undefined" ? Object : ChatBody
2269
3129
  ]),
2270
- _ts_metadata9("design:returntype", Promise)
3130
+ _ts_metadata10("design:returntype", Promise)
2271
3131
  ], ChatController.prototype, "chat", null);
2272
- _ts_decorate10([
3132
+ _ts_decorate11([
2273
3133
  Get3("chat/:runId/stream"),
2274
- _ts_param8(0, Req2()),
2275
- _ts_param8(1, Param("runId")),
2276
- _ts_param8(2, Res()),
2277
- _ts_param8(3, Query("after")),
2278
- _ts_metadata9("design:type", Function),
2279
- _ts_metadata9("design:paramtypes", [
3134
+ _ts_param9(0, Req2()),
3135
+ _ts_param9(1, Param("runId")),
3136
+ _ts_param9(2, Res()),
3137
+ _ts_param9(3, Query("after")),
3138
+ _ts_metadata10("design:type", Function),
3139
+ _ts_metadata10("design:paramtypes", [
2280
3140
  typeof Request === "undefined" ? Object : Request,
2281
3141
  String,
2282
3142
  typeof Response === "undefined" ? Object : Response,
2283
3143
  String
2284
3144
  ]),
2285
- _ts_metadata9("design:returntype", Promise)
3145
+ _ts_metadata10("design:returntype", Promise)
2286
3146
  ], ChatController.prototype, "stream", null);
2287
- _ts_decorate10([
3147
+ _ts_decorate11([
2288
3148
  Post2("chat/:runId/cancel"),
2289
- _ts_param8(0, Req2()),
2290
- _ts_param8(1, Param("runId")),
2291
- _ts_metadata9("design:type", Function),
2292
- _ts_metadata9("design:paramtypes", [
3149
+ _ts_param9(0, Req2()),
3150
+ _ts_param9(1, Param("runId")),
3151
+ _ts_metadata10("design:type", Function),
3152
+ _ts_metadata10("design:paramtypes", [
2293
3153
  typeof Request === "undefined" ? Object : Request,
2294
3154
  String
2295
3155
  ]),
2296
- _ts_metadata9("design:returntype", Promise)
3156
+ _ts_metadata10("design:returntype", Promise)
2297
3157
  ], ChatController.prototype, "cancel", null);
2298
- ChatController = _ts_decorate10([
3158
+ ChatController = _ts_decorate11([
2299
3159
  Controller3(),
2300
- _ts_param8(1, Inject8(AGENT_ACTOR_RESOLVER2)),
2301
- _ts_metadata9("design:type", Function),
2302
- _ts_metadata9("design:paramtypes", [
3160
+ _ts_param9(1, Inject9(AGENT_ACTOR_RESOLVER2)),
3161
+ _ts_metadata10("design:type", Function),
3162
+ _ts_metadata10("design:paramtypes", [
2303
3163
  typeof AgentService === "undefined" ? Object : AgentService,
2304
3164
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2305
3165
  ])
@@ -2315,8 +3175,8 @@ function parseCursor(raw) {
2315
3175
  __name(parseCursor, "parseCursor");
2316
3176
 
2317
3177
  // src/controller/config.controller.ts
2318
- import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER3, AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING3, AGENT_MODEL_CATALOG as AGENT_MODEL_CATALOG2, AGENT_OPTIONS as AGENT_OPTIONS4 } from "@dudousxd/nestjs-agent-core";
2319
- import { Controller as Controller4, Get as Get4, Inject as Inject9, Optional as Optional5, Req as Req3 } from "@nestjs/common";
3178
+ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER3, AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING4, AGENT_MODEL_CATALOG as AGENT_MODEL_CATALOG2, AGENT_OPTIONS as AGENT_OPTIONS5 } from "@dudousxd/nestjs-agent-core";
3179
+ import { Controller as Controller4, Get as Get4, Inject as Inject10, Optional as Optional7, Req as Req3 } from "@nestjs/common";
2320
3180
 
2321
3181
  // src/resolver/anonymous-actor-resolver.ts
2322
3182
  import { createHash, randomBytes } from "crypto";
@@ -2406,7 +3266,7 @@ var AnonymousActorResolver = class {
2406
3266
  };
2407
3267
 
2408
3268
  // src/controller/config.controller.ts
2409
- function _ts_decorate11(decorators, target, key, desc) {
3269
+ function _ts_decorate12(decorators, target, key, desc) {
2410
3270
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2411
3271
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2412
3272
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2419,19 +3279,19 @@ function _ts_decorate11(decorators, target, key, desc) {
2419
3279
  }
2420
3280
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2421
3281
  }
2422
- __name(_ts_decorate11, "_ts_decorate");
2423
- function _ts_metadata10(metadataKey, metadataValue) {
3282
+ __name(_ts_decorate12, "_ts_decorate");
3283
+ function _ts_metadata11(metadataKey, metadataValue) {
2424
3284
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2425
3285
  return Reflect.metadata(metadataKey, metadataValue);
2426
3286
  }
2427
3287
  }
2428
- __name(_ts_metadata10, "_ts_metadata");
2429
- function _ts_param9(paramIndex, decorator) {
3288
+ __name(_ts_metadata11, "_ts_metadata");
3289
+ function _ts_param10(paramIndex, decorator) {
2430
3290
  return function(target, key) {
2431
3291
  decorator(target, key, paramIndex);
2432
3292
  };
2433
3293
  }
2434
- __name(_ts_param9, "_ts_param");
3294
+ __name(_ts_param10, "_ts_param");
2435
3295
  var ConfigController = class {
2436
3296
  static {
2437
3297
  __name(this, "ConfigController");
@@ -2462,25 +3322,25 @@ var ConfigController = class {
2462
3322
  };
2463
3323
  }
2464
3324
  };
2465
- _ts_decorate11([
3325
+ _ts_decorate12([
2466
3326
  Get4(),
2467
- _ts_param9(0, Req3()),
2468
- _ts_metadata10("design:type", Function),
2469
- _ts_metadata10("design:paramtypes", [
3327
+ _ts_param10(0, Req3()),
3328
+ _ts_metadata11("design:type", Function),
3329
+ _ts_metadata11("design:paramtypes", [
2470
3330
  typeof Request === "undefined" ? Object : Request
2471
3331
  ]),
2472
- _ts_metadata10("design:returntype", Promise)
3332
+ _ts_metadata11("design:returntype", Promise)
2473
3333
  ], ConfigController.prototype, "config", null);
2474
- ConfigController = _ts_decorate11([
3334
+ ConfigController = _ts_decorate12([
2475
3335
  Controller4("config"),
2476
- _ts_param9(0, Inject9(AGENT_OPTIONS4)),
2477
- _ts_param9(1, Inject9(AGENT_ACTOR_RESOLVER3)),
2478
- _ts_param9(2, Optional5()),
2479
- _ts_param9(2, Inject9(AGENT_ATTACHMENT_STAGING3)),
2480
- _ts_param9(3, Optional5()),
2481
- _ts_param9(3, Inject9(AGENT_MODEL_CATALOG2)),
2482
- _ts_metadata10("design:type", Function),
2483
- _ts_metadata10("design:paramtypes", [
3336
+ _ts_param10(0, Inject10(AGENT_OPTIONS5)),
3337
+ _ts_param10(1, Inject10(AGENT_ACTOR_RESOLVER3)),
3338
+ _ts_param10(2, Optional7()),
3339
+ _ts_param10(2, Inject10(AGENT_ATTACHMENT_STAGING4)),
3340
+ _ts_param10(3, Optional7()),
3341
+ _ts_param10(3, Inject10(AGENT_MODEL_CATALOG2)),
3342
+ _ts_metadata11("design:type", Function),
3343
+ _ts_metadata11("design:paramtypes", [
2484
3344
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
2485
3345
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
2486
3346
  Object,
@@ -2490,8 +3350,8 @@ ConfigController = _ts_decorate11([
2490
3350
 
2491
3351
  // src/controller/memories.controller.ts
2492
3352
  import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER4, AGENT_MEMORY as AGENT_MEMORY2, memoryForgetVerdict, offerMemories } from "@dudousxd/nestjs-agent-core";
2493
- import { Controller as Controller5, Delete, ForbiddenException as ForbiddenException2, Get as Get5, Inject as Inject10, NotFoundException as NotFoundException2, Optional as Optional6, Param as Param2, Query as Query2, Req as Req4 } from "@nestjs/common";
2494
- function _ts_decorate12(decorators, target, key, desc) {
3353
+ import { Controller as Controller5, Delete, ForbiddenException as ForbiddenException2, Get as Get5, Inject as Inject11, NotFoundException as NotFoundException2, Optional as Optional8, Param as Param2, Query as Query2, Req as Req4 } from "@nestjs/common";
3354
+ function _ts_decorate13(decorators, target, key, desc) {
2495
3355
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2496
3356
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2497
3357
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2504,19 +3364,19 @@ function _ts_decorate12(decorators, target, key, desc) {
2504
3364
  }
2505
3365
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2506
3366
  }
2507
- __name(_ts_decorate12, "_ts_decorate");
2508
- function _ts_metadata11(metadataKey, metadataValue) {
3367
+ __name(_ts_decorate13, "_ts_decorate");
3368
+ function _ts_metadata12(metadataKey, metadataValue) {
2509
3369
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2510
3370
  return Reflect.metadata(metadataKey, metadataValue);
2511
3371
  }
2512
3372
  }
2513
- __name(_ts_metadata11, "_ts_metadata");
2514
- function _ts_param10(paramIndex, decorator) {
3373
+ __name(_ts_metadata12, "_ts_metadata");
3374
+ function _ts_param11(paramIndex, decorator) {
2515
3375
  return function(target, key) {
2516
3376
  decorator(target, key, paramIndex);
2517
3377
  };
2518
3378
  }
2519
- __name(_ts_param10, "_ts_param");
3379
+ __name(_ts_param11, "_ts_param");
2520
3380
  var MemoriesController = class {
2521
3381
  static {
2522
3382
  __name(this, "MemoriesController");
@@ -2589,35 +3449,35 @@ var MemoriesController = class {
2589
3449
  });
2590
3450
  }
2591
3451
  };
2592
- _ts_decorate12([
3452
+ _ts_decorate13([
2593
3453
  Get5(),
2594
- _ts_param10(0, Req4()),
2595
- _ts_param10(1, Query2("threadId")),
2596
- _ts_metadata11("design:type", Function),
2597
- _ts_metadata11("design:paramtypes", [
3454
+ _ts_param11(0, Req4()),
3455
+ _ts_param11(1, Query2("threadId")),
3456
+ _ts_metadata12("design:type", Function),
3457
+ _ts_metadata12("design:paramtypes", [
2598
3458
  typeof Request === "undefined" ? Object : Request,
2599
3459
  String
2600
3460
  ]),
2601
- _ts_metadata11("design:returntype", Promise)
3461
+ _ts_metadata12("design:returntype", Promise)
2602
3462
  ], MemoriesController.prototype, "list", null);
2603
- _ts_decorate12([
3463
+ _ts_decorate13([
2604
3464
  Delete(":id"),
2605
- _ts_param10(0, Req4()),
2606
- _ts_param10(1, Param2("id")),
2607
- _ts_metadata11("design:type", Function),
2608
- _ts_metadata11("design:paramtypes", [
3465
+ _ts_param11(0, Req4()),
3466
+ _ts_param11(1, Param2("id")),
3467
+ _ts_metadata12("design:type", Function),
3468
+ _ts_metadata12("design:paramtypes", [
2609
3469
  typeof Request === "undefined" ? Object : Request,
2610
3470
  String
2611
3471
  ]),
2612
- _ts_metadata11("design:returntype", Promise)
3472
+ _ts_metadata12("design:returntype", Promise)
2613
3473
  ], MemoriesController.prototype, "forget", null);
2614
- MemoriesController = _ts_decorate12([
3474
+ MemoriesController = _ts_decorate13([
2615
3475
  Controller5("memories"),
2616
- _ts_param10(0, Inject10(AGENT_ACTOR_RESOLVER4)),
2617
- _ts_param10(1, Optional6()),
2618
- _ts_param10(1, Inject10(AGENT_MEMORY2)),
2619
- _ts_metadata11("design:type", Function),
2620
- _ts_metadata11("design:paramtypes", [
3476
+ _ts_param11(0, Inject11(AGENT_ACTOR_RESOLVER4)),
3477
+ _ts_param11(1, Optional8()),
3478
+ _ts_param11(1, Inject11(AGENT_MEMORY2)),
3479
+ _ts_metadata12("design:type", Function),
3480
+ _ts_metadata12("design:paramtypes", [
2621
3481
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
2622
3482
  Object
2623
3483
  ])
@@ -2625,8 +3485,8 @@ MemoriesController = _ts_decorate12([
2625
3485
 
2626
3486
  // src/controller/messages.controller.ts
2627
3487
  import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER5 } from "@dudousxd/nestjs-agent-core";
2628
- import { Body as Body2, Controller as Controller6, HttpCode, Inject as Inject11, Param as Param3, Post as Post3, Req as Req5 } from "@nestjs/common";
2629
- function _ts_decorate13(decorators, target, key, desc) {
3488
+ import { Body as Body2, Controller as Controller6, HttpCode, Inject as Inject12, Param as Param3, Post as Post3, Req as Req5 } from "@nestjs/common";
3489
+ function _ts_decorate14(decorators, target, key, desc) {
2630
3490
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2631
3491
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2632
3492
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2639,19 +3499,19 @@ function _ts_decorate13(decorators, target, key, desc) {
2639
3499
  }
2640
3500
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2641
3501
  }
2642
- __name(_ts_decorate13, "_ts_decorate");
2643
- function _ts_metadata12(metadataKey, metadataValue) {
3502
+ __name(_ts_decorate14, "_ts_decorate");
3503
+ function _ts_metadata13(metadataKey, metadataValue) {
2644
3504
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2645
3505
  return Reflect.metadata(metadataKey, metadataValue);
2646
3506
  }
2647
3507
  }
2648
- __name(_ts_metadata12, "_ts_metadata");
2649
- function _ts_param11(paramIndex, decorator) {
3508
+ __name(_ts_metadata13, "_ts_metadata");
3509
+ function _ts_param12(paramIndex, decorator) {
2650
3510
  return function(target, key) {
2651
3511
  decorator(target, key, paramIndex);
2652
3512
  };
2653
3513
  }
2654
- __name(_ts_param11, "_ts_param");
3514
+ __name(_ts_param12, "_ts_param");
2655
3515
  var MessagesController = class {
2656
3516
  static {
2657
3517
  __name(this, "MessagesController");
@@ -2679,25 +3539,25 @@ var MessagesController = class {
2679
3539
  };
2680
3540
  }
2681
3541
  };
2682
- _ts_decorate13([
3542
+ _ts_decorate14([
2683
3543
  Post3(":id/feedback"),
2684
3544
  HttpCode(200),
2685
- _ts_param11(0, Req5()),
2686
- _ts_param11(1, Param3("id")),
2687
- _ts_param11(2, Body2()),
2688
- _ts_metadata12("design:type", Function),
2689
- _ts_metadata12("design:paramtypes", [
3545
+ _ts_param12(0, Req5()),
3546
+ _ts_param12(1, Param3("id")),
3547
+ _ts_param12(2, Body2()),
3548
+ _ts_metadata13("design:type", Function),
3549
+ _ts_metadata13("design:paramtypes", [
2690
3550
  typeof Request === "undefined" ? Object : Request,
2691
3551
  String,
2692
3552
  typeof FeedbackBody === "undefined" ? Object : FeedbackBody
2693
3553
  ]),
2694
- _ts_metadata12("design:returntype", Promise)
3554
+ _ts_metadata13("design:returntype", Promise)
2695
3555
  ], MessagesController.prototype, "feedback", null);
2696
- MessagesController = _ts_decorate13([
3556
+ MessagesController = _ts_decorate14([
2697
3557
  Controller6("messages"),
2698
- _ts_param11(1, Inject11(AGENT_ACTOR_RESOLVER5)),
2699
- _ts_metadata12("design:type", Function),
2700
- _ts_metadata12("design:paramtypes", [
3558
+ _ts_param12(1, Inject12(AGENT_ACTOR_RESOLVER5)),
3559
+ _ts_metadata13("design:type", Function),
3560
+ _ts_metadata13("design:paramtypes", [
2701
3561
  typeof AgentService === "undefined" ? Object : AgentService,
2702
3562
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2703
3563
  ])
@@ -2705,8 +3565,8 @@ MessagesController = _ts_decorate13([
2705
3565
 
2706
3566
  // src/controller/models.controller.ts
2707
3567
  import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER6 } from "@dudousxd/nestjs-agent-core";
2708
- import { Controller as Controller7, Get as Get6, Inject as Inject12, Query as Query3, Req as Req6 } from "@nestjs/common";
2709
- function _ts_decorate14(decorators, target, key, desc) {
3568
+ import { Controller as Controller7, Get as Get6, Inject as Inject13, Query as Query3, Req as Req6 } from "@nestjs/common";
3569
+ function _ts_decorate15(decorators, target, key, desc) {
2710
3570
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2711
3571
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2712
3572
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2719,19 +3579,19 @@ function _ts_decorate14(decorators, target, key, desc) {
2719
3579
  }
2720
3580
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2721
3581
  }
2722
- __name(_ts_decorate14, "_ts_decorate");
2723
- function _ts_metadata13(metadataKey, metadataValue) {
3582
+ __name(_ts_decorate15, "_ts_decorate");
3583
+ function _ts_metadata14(metadataKey, metadataValue) {
2724
3584
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2725
3585
  return Reflect.metadata(metadataKey, metadataValue);
2726
3586
  }
2727
3587
  }
2728
- __name(_ts_metadata13, "_ts_metadata");
2729
- function _ts_param12(paramIndex, decorator) {
3588
+ __name(_ts_metadata14, "_ts_metadata");
3589
+ function _ts_param13(paramIndex, decorator) {
2730
3590
  return function(target, key) {
2731
3591
  decorator(target, key, paramIndex);
2732
3592
  };
2733
3593
  }
2734
- __name(_ts_param12, "_ts_param");
3594
+ __name(_ts_param13, "_ts_param");
2735
3595
  var ModelsController = class {
2736
3596
  static {
2737
3597
  __name(this, "ModelsController");
@@ -2751,31 +3611,31 @@ var ModelsController = class {
2751
3611
  return this.agent.listModels(actor, agent);
2752
3612
  }
2753
3613
  };
2754
- _ts_decorate14([
3614
+ _ts_decorate15([
2755
3615
  Get6(),
2756
- _ts_param12(0, Req6()),
2757
- _ts_param12(1, Query3("agent")),
2758
- _ts_metadata13("design:type", Function),
2759
- _ts_metadata13("design:paramtypes", [
3616
+ _ts_param13(0, Req6()),
3617
+ _ts_param13(1, Query3("agent")),
3618
+ _ts_metadata14("design:type", Function),
3619
+ _ts_metadata14("design:paramtypes", [
2760
3620
  typeof Request === "undefined" ? Object : Request,
2761
3621
  String
2762
3622
  ]),
2763
- _ts_metadata13("design:returntype", Promise)
3623
+ _ts_metadata14("design:returntype", Promise)
2764
3624
  ], ModelsController.prototype, "list", null);
2765
- ModelsController = _ts_decorate14([
3625
+ ModelsController = _ts_decorate15([
2766
3626
  Controller7("models"),
2767
- _ts_param12(1, Inject12(AGENT_ACTOR_RESOLVER6)),
2768
- _ts_metadata13("design:type", Function),
2769
- _ts_metadata13("design:paramtypes", [
3627
+ _ts_param13(1, Inject13(AGENT_ACTOR_RESOLVER6)),
3628
+ _ts_metadata14("design:type", Function),
3629
+ _ts_metadata14("design:paramtypes", [
2770
3630
  typeof AgentService === "undefined" ? Object : AgentService,
2771
3631
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2772
3632
  ])
2773
3633
  ], ModelsController);
2774
3634
 
2775
- // src/controller/quota.controller.ts
3635
+ // src/controller/queue.controller.ts
2776
3636
  import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER7 } from "@dudousxd/nestjs-agent-core";
2777
- import { Controller as Controller8, Get as Get7, Inject as Inject13, Req as Req7 } from "@nestjs/common";
2778
- function _ts_decorate15(decorators, target, key, desc) {
3637
+ import { BadRequestException as BadRequestException4, Body as Body3, Controller as Controller8, Delete as Delete2, Get as Get7, Inject as Inject14, Param as Param4, Patch, Post as Post4, Req as Req7 } from "@nestjs/common";
3638
+ function _ts_decorate16(decorators, target, key, desc) {
2779
3639
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2780
3640
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2781
3641
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2788,19 +3648,179 @@ function _ts_decorate15(decorators, target, key, desc) {
2788
3648
  }
2789
3649
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2790
3650
  }
2791
- __name(_ts_decorate15, "_ts_decorate");
2792
- function _ts_metadata14(metadataKey, metadataValue) {
3651
+ __name(_ts_decorate16, "_ts_decorate");
3652
+ function _ts_metadata15(metadataKey, metadataValue) {
2793
3653
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2794
3654
  return Reflect.metadata(metadataKey, metadataValue);
2795
3655
  }
2796
3656
  }
2797
- __name(_ts_metadata14, "_ts_metadata");
2798
- function _ts_param13(paramIndex, decorator) {
3657
+ __name(_ts_metadata15, "_ts_metadata");
3658
+ function _ts_param14(paramIndex, decorator) {
2799
3659
  return function(target, key) {
2800
3660
  decorator(target, key, paramIndex);
2801
3661
  };
2802
3662
  }
2803
- __name(_ts_param13, "_ts_param");
3663
+ __name(_ts_param14, "_ts_param");
3664
+ var QueueController = class {
3665
+ static {
3666
+ __name(this, "QueueController");
3667
+ }
3668
+ agent;
3669
+ actorResolver;
3670
+ constructor(agent, actorResolver) {
3671
+ this.agent = agent;
3672
+ this.actorResolver = actorResolver;
3673
+ }
3674
+ async list(req, id) {
3675
+ return this.agent.getQueue(await this.actorResolver.resolve(req), id);
3676
+ }
3677
+ async clear(req, id) {
3678
+ return this.agent.clearQueue(await this.actorResolver.resolve(req), id);
3679
+ }
3680
+ /** Lift a pause; the head starts when nothing is running. Carries `runId` when it started. */
3681
+ async resume(req, id) {
3682
+ return this.agent.resumeQueue(await this.actorResolver.resolve(req), id);
3683
+ }
3684
+ async update(req, messageId, body) {
3685
+ const actor = await this.actorResolver.resolve(req);
3686
+ if (body.message !== void 0 && typeof body.message !== "string") {
3687
+ throw new BadRequestException4("message must be a string");
3688
+ }
3689
+ if (body.position !== void 0 && typeof body.position !== "number") {
3690
+ throw new BadRequestException4("position must be a number");
3691
+ }
3692
+ const attachments = body.attachments === void 0 ? void 0 : body.attachments === null ? null : attachmentRefs(body.attachments);
3693
+ return this.agent.updateQueuedMessage(actor, messageId, {
3694
+ ...body.message !== void 0 ? {
3695
+ message: body.message
3696
+ } : {},
3697
+ ...attachments !== void 0 ? {
3698
+ attachments
3699
+ } : {},
3700
+ ...body.position !== void 0 ? {
3701
+ position: body.position
3702
+ } : {}
3703
+ });
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
+ }
3713
+ async remove(req, messageId) {
3714
+ return this.agent.removeQueuedMessage(await this.actorResolver.resolve(req), messageId);
3715
+ }
3716
+ };
3717
+ _ts_decorate16([
3718
+ Get7("threads/:id/queue"),
3719
+ _ts_param14(0, Req7()),
3720
+ _ts_param14(1, Param4("id")),
3721
+ _ts_metadata15("design:type", Function),
3722
+ _ts_metadata15("design:paramtypes", [
3723
+ typeof Request === "undefined" ? Object : Request,
3724
+ String
3725
+ ]),
3726
+ _ts_metadata15("design:returntype", Promise)
3727
+ ], QueueController.prototype, "list", null);
3728
+ _ts_decorate16([
3729
+ Delete2("threads/:id/queue"),
3730
+ _ts_param14(0, Req7()),
3731
+ _ts_param14(1, Param4("id")),
3732
+ _ts_metadata15("design:type", Function),
3733
+ _ts_metadata15("design:paramtypes", [
3734
+ typeof Request === "undefined" ? Object : Request,
3735
+ String
3736
+ ]),
3737
+ _ts_metadata15("design:returntype", Promise)
3738
+ ], QueueController.prototype, "clear", null);
3739
+ _ts_decorate16([
3740
+ Post4("threads/:id/queue/resume"),
3741
+ _ts_param14(0, Req7()),
3742
+ _ts_param14(1, Param4("id")),
3743
+ _ts_metadata15("design:type", Function),
3744
+ _ts_metadata15("design:paramtypes", [
3745
+ typeof Request === "undefined" ? Object : Request,
3746
+ String
3747
+ ]),
3748
+ _ts_metadata15("design:returntype", Promise)
3749
+ ], QueueController.prototype, "resume", null);
3750
+ _ts_decorate16([
3751
+ Patch("queue/:messageId"),
3752
+ _ts_param14(0, Req7()),
3753
+ _ts_param14(1, Param4("messageId")),
3754
+ _ts_param14(2, Body3()),
3755
+ _ts_metadata15("design:type", Function),
3756
+ _ts_metadata15("design:paramtypes", [
3757
+ typeof Request === "undefined" ? Object : Request,
3758
+ String,
3759
+ typeof UpdateQueuedMessageBody === "undefined" ? Object : UpdateQueuedMessageBody
3760
+ ]),
3761
+ _ts_metadata15("design:returntype", Promise)
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);
3774
+ _ts_decorate16([
3775
+ Delete2("queue/:messageId"),
3776
+ _ts_param14(0, Req7()),
3777
+ _ts_param14(1, Param4("messageId")),
3778
+ _ts_metadata15("design:type", Function),
3779
+ _ts_metadata15("design:paramtypes", [
3780
+ typeof Request === "undefined" ? Object : Request,
3781
+ String
3782
+ ]),
3783
+ _ts_metadata15("design:returntype", Promise)
3784
+ ], QueueController.prototype, "remove", null);
3785
+ QueueController = _ts_decorate16([
3786
+ Controller8(),
3787
+ _ts_param14(1, Inject14(AGENT_ACTOR_RESOLVER7)),
3788
+ _ts_metadata15("design:type", Function),
3789
+ _ts_metadata15("design:paramtypes", [
3790
+ typeof AgentService === "undefined" ? Object : AgentService,
3791
+ typeof ActorResolver === "undefined" ? Object : ActorResolver
3792
+ ])
3793
+ ], QueueController);
3794
+
3795
+ // src/controller/quota.controller.ts
3796
+ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER8 } from "@dudousxd/nestjs-agent-core";
3797
+ import { Controller as Controller9, Get as Get8, Inject as Inject15, Req as Req8 } from "@nestjs/common";
3798
+ function _ts_decorate17(decorators, target, key, desc) {
3799
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3800
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3801
+ r = Reflect.decorate(decorators, target, key, desc);
3802
+ } else {
3803
+ for (var i = decorators.length - 1; i >= 0; i--) {
3804
+ if (d = decorators[i]) {
3805
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3806
+ }
3807
+ }
3808
+ }
3809
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
3810
+ }
3811
+ __name(_ts_decorate17, "_ts_decorate");
3812
+ function _ts_metadata16(metadataKey, metadataValue) {
3813
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3814
+ return Reflect.metadata(metadataKey, metadataValue);
3815
+ }
3816
+ }
3817
+ __name(_ts_metadata16, "_ts_metadata");
3818
+ function _ts_param15(paramIndex, decorator) {
3819
+ return function(target, key) {
3820
+ decorator(target, key, paramIndex);
3821
+ };
3822
+ }
3823
+ __name(_ts_param15, "_ts_param");
2804
3824
  var QuotaController = class {
2805
3825
  static {
2806
3826
  __name(this, "QuotaController");
@@ -2820,29 +3840,29 @@ var QuotaController = class {
2820
3840
  return this.agent.quotaReport(actor);
2821
3841
  }
2822
3842
  };
2823
- _ts_decorate15([
2824
- Get7(),
2825
- _ts_param13(0, Req7()),
2826
- _ts_metadata14("design:type", Function),
2827
- _ts_metadata14("design:paramtypes", [
3843
+ _ts_decorate17([
3844
+ Get8(),
3845
+ _ts_param15(0, Req8()),
3846
+ _ts_metadata16("design:type", Function),
3847
+ _ts_metadata16("design:paramtypes", [
2828
3848
  typeof Request === "undefined" ? Object : Request
2829
3849
  ]),
2830
- _ts_metadata14("design:returntype", Promise)
3850
+ _ts_metadata16("design:returntype", Promise)
2831
3851
  ], QuotaController.prototype, "report", null);
2832
- QuotaController = _ts_decorate15([
2833
- Controller8("quota"),
2834
- _ts_param13(1, Inject13(AGENT_ACTOR_RESOLVER7)),
2835
- _ts_metadata14("design:type", Function),
2836
- _ts_metadata14("design:paramtypes", [
3852
+ QuotaController = _ts_decorate17([
3853
+ Controller9("quota"),
3854
+ _ts_param15(1, Inject15(AGENT_ACTOR_RESOLVER8)),
3855
+ _ts_metadata16("design:type", Function),
3856
+ _ts_metadata16("design:paramtypes", [
2837
3857
  typeof AgentService === "undefined" ? Object : AgentService,
2838
3858
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2839
3859
  ])
2840
3860
  ], QuotaController);
2841
3861
 
2842
3862
  // src/controller/skills.controller.ts
2843
- import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER8, AGENT_SKILLS as AGENT_SKILLS2, offerSkills } from "@dudousxd/nestjs-agent-core";
2844
- import { Controller as Controller9, Get as Get8, Inject as Inject14, Optional as Optional7, Query as Query4, Req as Req8 } from "@nestjs/common";
2845
- function _ts_decorate16(decorators, target, key, desc) {
3863
+ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER9, AGENT_SKILLS as AGENT_SKILLS2, offerSkills } from "@dudousxd/nestjs-agent-core";
3864
+ import { Controller as Controller10, Get as Get9, Inject as Inject16, Optional as Optional9, Query as Query4, Req as Req9 } from "@nestjs/common";
3865
+ function _ts_decorate18(decorators, target, key, desc) {
2846
3866
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2847
3867
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2848
3868
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2855,19 +3875,19 @@ function _ts_decorate16(decorators, target, key, desc) {
2855
3875
  }
2856
3876
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2857
3877
  }
2858
- __name(_ts_decorate16, "_ts_decorate");
2859
- function _ts_metadata15(metadataKey, metadataValue) {
3878
+ __name(_ts_decorate18, "_ts_decorate");
3879
+ function _ts_metadata17(metadataKey, metadataValue) {
2860
3880
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2861
3881
  return Reflect.metadata(metadataKey, metadataValue);
2862
3882
  }
2863
3883
  }
2864
- __name(_ts_metadata15, "_ts_metadata");
2865
- function _ts_param14(paramIndex, decorator) {
3884
+ __name(_ts_metadata17, "_ts_metadata");
3885
+ function _ts_param16(paramIndex, decorator) {
2866
3886
  return function(target, key) {
2867
3887
  decorator(target, key, paramIndex);
2868
3888
  };
2869
3889
  }
2870
- __name(_ts_param14, "_ts_param");
3890
+ __name(_ts_param16, "_ts_param");
2871
3891
  var SkillsController = class {
2872
3892
  static {
2873
3893
  __name(this, "SkillsController");
@@ -2890,33 +3910,33 @@ var SkillsController = class {
2890
3910
  return offer.entries;
2891
3911
  }
2892
3912
  };
2893
- _ts_decorate16([
2894
- Get8(),
2895
- _ts_param14(0, Req8()),
2896
- _ts_param14(1, Query4("threadId")),
2897
- _ts_metadata15("design:type", Function),
2898
- _ts_metadata15("design:paramtypes", [
3913
+ _ts_decorate18([
3914
+ Get9(),
3915
+ _ts_param16(0, Req9()),
3916
+ _ts_param16(1, Query4("threadId")),
3917
+ _ts_metadata17("design:type", Function),
3918
+ _ts_metadata17("design:paramtypes", [
2899
3919
  typeof Request === "undefined" ? Object : Request,
2900
3920
  String
2901
3921
  ]),
2902
- _ts_metadata15("design:returntype", Promise)
3922
+ _ts_metadata17("design:returntype", Promise)
2903
3923
  ], SkillsController.prototype, "list", null);
2904
- SkillsController = _ts_decorate16([
2905
- Controller9("skills"),
2906
- _ts_param14(0, Inject14(AGENT_ACTOR_RESOLVER8)),
2907
- _ts_param14(1, Optional7()),
2908
- _ts_param14(1, Inject14(AGENT_SKILLS2)),
2909
- _ts_metadata15("design:type", Function),
2910
- _ts_metadata15("design:paramtypes", [
3924
+ SkillsController = _ts_decorate18([
3925
+ Controller10("skills"),
3926
+ _ts_param16(0, Inject16(AGENT_ACTOR_RESOLVER9)),
3927
+ _ts_param16(1, Optional9()),
3928
+ _ts_param16(1, Inject16(AGENT_SKILLS2)),
3929
+ _ts_metadata17("design:type", Function),
3930
+ _ts_metadata17("design:paramtypes", [
2911
3931
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
2912
3932
  Object
2913
3933
  ])
2914
3934
  ], SkillsController);
2915
3935
 
2916
3936
  // src/controller/threads.controller.ts
2917
- import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER9 } from "@dudousxd/nestjs-agent-core";
2918
- import { Body as Body3, Controller as Controller10, Delete as Delete2, Get as Get9, Inject as Inject15, Param as Param4, Patch, Post as Post4, Req as Req9 } from "@nestjs/common";
2919
- function _ts_decorate17(decorators, target, key, desc) {
3937
+ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER10 } from "@dudousxd/nestjs-agent-core";
3938
+ import { Body as Body4, Controller as Controller11, Delete as Delete3, Get as Get10, Inject as Inject17, Param as Param5, Patch as Patch2, Post as Post5, Req as Req10 } from "@nestjs/common";
3939
+ function _ts_decorate19(decorators, target, key, desc) {
2920
3940
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2921
3941
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2922
3942
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2929,19 +3949,19 @@ function _ts_decorate17(decorators, target, key, desc) {
2929
3949
  }
2930
3950
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2931
3951
  }
2932
- __name(_ts_decorate17, "_ts_decorate");
2933
- function _ts_metadata16(metadataKey, metadataValue) {
3952
+ __name(_ts_decorate19, "_ts_decorate");
3953
+ function _ts_metadata18(metadataKey, metadataValue) {
2934
3954
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2935
3955
  return Reflect.metadata(metadataKey, metadataValue);
2936
3956
  }
2937
3957
  }
2938
- __name(_ts_metadata16, "_ts_metadata");
2939
- function _ts_param15(paramIndex, decorator) {
3958
+ __name(_ts_metadata18, "_ts_metadata");
3959
+ function _ts_param17(paramIndex, decorator) {
2940
3960
  return function(target, key) {
2941
3961
  decorator(target, key, paramIndex);
2942
3962
  };
2943
3963
  }
2944
- __name(_ts_param15, "_ts_param");
3964
+ __name(_ts_param17, "_ts_param");
2945
3965
  var ThreadsController = class {
2946
3966
  static {
2947
3967
  __name(this, "ThreadsController");
@@ -3008,101 +4028,101 @@ var ThreadsController = class {
3008
4028
  };
3009
4029
  }
3010
4030
  };
3011
- _ts_decorate17([
3012
- Get9(),
3013
- _ts_param15(0, Req9()),
3014
- _ts_metadata16("design:type", Function),
3015
- _ts_metadata16("design:paramtypes", [
4031
+ _ts_decorate19([
4032
+ Get10(),
4033
+ _ts_param17(0, Req10()),
4034
+ _ts_metadata18("design:type", Function),
4035
+ _ts_metadata18("design:paramtypes", [
3016
4036
  typeof Request === "undefined" ? Object : Request
3017
4037
  ]),
3018
- _ts_metadata16("design:returntype", Promise)
4038
+ _ts_metadata18("design:returntype", Promise)
3019
4039
  ], ThreadsController.prototype, "list", null);
3020
- _ts_decorate17([
3021
- Get9(":id"),
3022
- _ts_param15(0, Req9()),
3023
- _ts_param15(1, Param4("id")),
3024
- _ts_metadata16("design:type", Function),
3025
- _ts_metadata16("design:paramtypes", [
4040
+ _ts_decorate19([
4041
+ Get10(":id"),
4042
+ _ts_param17(0, Req10()),
4043
+ _ts_param17(1, Param5("id")),
4044
+ _ts_metadata18("design:type", Function),
4045
+ _ts_metadata18("design:paramtypes", [
3026
4046
  typeof Request === "undefined" ? Object : Request,
3027
4047
  String
3028
4048
  ]),
3029
- _ts_metadata16("design:returntype", Promise)
4049
+ _ts_metadata18("design:returntype", Promise)
3030
4050
  ], ThreadsController.prototype, "detail", null);
3031
- _ts_decorate17([
3032
- Delete2(":id"),
3033
- _ts_param15(0, Req9()),
3034
- _ts_param15(1, Param4("id")),
3035
- _ts_metadata16("design:type", Function),
3036
- _ts_metadata16("design:paramtypes", [
4051
+ _ts_decorate19([
4052
+ Delete3(":id"),
4053
+ _ts_param17(0, Req10()),
4054
+ _ts_param17(1, Param5("id")),
4055
+ _ts_metadata18("design:type", Function),
4056
+ _ts_metadata18("design:paramtypes", [
3037
4057
  typeof Request === "undefined" ? Object : Request,
3038
4058
  String
3039
4059
  ]),
3040
- _ts_metadata16("design:returntype", Promise)
4060
+ _ts_metadata18("design:returntype", Promise)
3041
4061
  ], ThreadsController.prototype, "remove", null);
3042
- _ts_decorate17([
3043
- Post4(":id/fork-from/:messageId"),
3044
- _ts_param15(0, Req9()),
3045
- _ts_param15(1, Param4("id")),
3046
- _ts_param15(2, Param4("messageId")),
3047
- _ts_metadata16("design:type", Function),
3048
- _ts_metadata16("design:paramtypes", [
4062
+ _ts_decorate19([
4063
+ Post5(":id/fork-from/:messageId"),
4064
+ _ts_param17(0, Req10()),
4065
+ _ts_param17(1, Param5("id")),
4066
+ _ts_param17(2, Param5("messageId")),
4067
+ _ts_metadata18("design:type", Function),
4068
+ _ts_metadata18("design:paramtypes", [
3049
4069
  typeof Request === "undefined" ? Object : Request,
3050
4070
  String,
3051
4071
  String
3052
4072
  ]),
3053
- _ts_metadata16("design:returntype", Promise)
4073
+ _ts_metadata18("design:returntype", Promise)
3054
4074
  ], ThreadsController.prototype, "fork", null);
3055
- _ts_decorate17([
3056
- Patch(":id"),
3057
- _ts_param15(0, Req9()),
3058
- _ts_param15(1, Param4("id")),
3059
- _ts_param15(2, Body3()),
3060
- _ts_metadata16("design:type", Function),
3061
- _ts_metadata16("design:paramtypes", [
4075
+ _ts_decorate19([
4076
+ Patch2(":id"),
4077
+ _ts_param17(0, Req10()),
4078
+ _ts_param17(1, Param5("id")),
4079
+ _ts_param17(2, Body4()),
4080
+ _ts_metadata18("design:type", Function),
4081
+ _ts_metadata18("design:paramtypes", [
3062
4082
  typeof Request === "undefined" ? Object : Request,
3063
4083
  String,
3064
4084
  typeof UpdateThreadBody === "undefined" ? Object : UpdateThreadBody
3065
4085
  ]),
3066
- _ts_metadata16("design:returntype", Promise)
4086
+ _ts_metadata18("design:returntype", Promise)
3067
4087
  ], ThreadsController.prototype, "update", null);
3068
- _ts_decorate17([
3069
- Post4(":id/promote"),
3070
- _ts_param15(0, Req9()),
3071
- _ts_param15(1, Param4("id")),
3072
- _ts_metadata16("design:type", Function),
3073
- _ts_metadata16("design:paramtypes", [
4088
+ _ts_decorate19([
4089
+ Post5(":id/promote"),
4090
+ _ts_param17(0, Req10()),
4091
+ _ts_param17(1, Param5("id")),
4092
+ _ts_metadata18("design:type", Function),
4093
+ _ts_metadata18("design:paramtypes", [
3074
4094
  typeof Request === "undefined" ? Object : Request,
3075
4095
  String
3076
4096
  ]),
3077
- _ts_metadata16("design:returntype", Promise)
4097
+ _ts_metadata18("design:returntype", Promise)
3078
4098
  ], ThreadsController.prototype, "promote", null);
3079
- _ts_decorate17([
3080
- Delete2(":id/from/:messageId"),
3081
- _ts_param15(0, Req9()),
3082
- _ts_param15(1, Param4("id")),
3083
- _ts_param15(2, Param4("messageId")),
3084
- _ts_metadata16("design:type", Function),
3085
- _ts_metadata16("design:paramtypes", [
4099
+ _ts_decorate19([
4100
+ Delete3(":id/from/:messageId"),
4101
+ _ts_param17(0, Req10()),
4102
+ _ts_param17(1, Param5("id")),
4103
+ _ts_param17(2, Param5("messageId")),
4104
+ _ts_metadata18("design:type", Function),
4105
+ _ts_metadata18("design:paramtypes", [
3086
4106
  typeof Request === "undefined" ? Object : Request,
3087
4107
  String,
3088
4108
  String
3089
4109
  ]),
3090
- _ts_metadata16("design:returntype", Promise)
4110
+ _ts_metadata18("design:returntype", Promise)
3091
4111
  ], ThreadsController.prototype, "truncateFrom", null);
3092
- ThreadsController = _ts_decorate17([
3093
- Controller10("threads"),
3094
- _ts_param15(1, Inject15(AGENT_ACTOR_RESOLVER9)),
3095
- _ts_metadata16("design:type", Function),
3096
- _ts_metadata16("design:paramtypes", [
4112
+ ThreadsController = _ts_decorate19([
4113
+ Controller11("threads"),
4114
+ _ts_param17(1, Inject17(AGENT_ACTOR_RESOLVER10)),
4115
+ _ts_metadata18("design:type", Function),
4116
+ _ts_metadata18("design:paramtypes", [
3097
4117
  typeof AgentService === "undefined" ? Object : AgentService,
3098
4118
  typeof ActorResolver === "undefined" ? Object : ActorResolver
3099
4119
  ])
3100
4120
  ], ThreadsController);
3101
4121
 
3102
4122
  // src/controller/tool-call.controller.ts
3103
- import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER10 } from "@dudousxd/nestjs-agent-core";
3104
- import { BadRequestException as BadRequestException4, Body as Body4, Controller as Controller11, Inject as Inject16, Post as Post5, Req as Req10 } from "@nestjs/common";
3105
- function _ts_decorate18(decorators, target, key, desc) {
4123
+ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER11 } from "@dudousxd/nestjs-agent-core";
4124
+ import { BadRequestException as BadRequestException5, Body as Body5, Controller as Controller12, Inject as Inject18, Post as Post6, Req as Req11 } from "@nestjs/common";
4125
+ function _ts_decorate20(decorators, target, key, desc) {
3106
4126
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3107
4127
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3108
4128
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3115,19 +4135,19 @@ function _ts_decorate18(decorators, target, key, desc) {
3115
4135
  }
3116
4136
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3117
4137
  }
3118
- __name(_ts_decorate18, "_ts_decorate");
3119
- function _ts_metadata17(metadataKey, metadataValue) {
4138
+ __name(_ts_decorate20, "_ts_decorate");
4139
+ function _ts_metadata19(metadataKey, metadataValue) {
3120
4140
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3121
4141
  return Reflect.metadata(metadataKey, metadataValue);
3122
4142
  }
3123
4143
  }
3124
- __name(_ts_metadata17, "_ts_metadata");
3125
- function _ts_param16(paramIndex, decorator) {
4144
+ __name(_ts_metadata19, "_ts_metadata");
4145
+ function _ts_param18(paramIndex, decorator) {
3126
4146
  return function(target, key) {
3127
4147
  decorator(target, key, paramIndex);
3128
4148
  };
3129
4149
  }
3130
- __name(_ts_param16, "_ts_param");
4150
+ __name(_ts_param18, "_ts_param");
3131
4151
  var MAX_ANSWERED_QUESTIONS = 100;
3132
4152
  var MAX_VALUES_PER_QUESTION = 100;
3133
4153
  var MAX_ANSWER_VALUE_LENGTH = 4096;
@@ -3136,7 +4156,7 @@ var MAX_VIA_LENGTH = 64;
3136
4156
  var DEFAULT_VIA = "web";
3137
4157
  function toolCallId(claimed) {
3138
4158
  if (typeof claimed !== "string" || claimed.length === 0) {
3139
- throw new BadRequestException4("toolCallId must be a non-empty string");
4159
+ throw new BadRequestException5("toolCallId must be a non-empty string");
3140
4160
  }
3141
4161
  return claimed;
3142
4162
  }
@@ -3146,10 +4166,10 @@ function rejectReason(claimed) {
3146
4166
  return void 0;
3147
4167
  }
3148
4168
  if (typeof claimed !== "string") {
3149
- throw new BadRequestException4("reason must be a string");
4169
+ throw new BadRequestException5("reason must be a string");
3150
4170
  }
3151
4171
  if (claimed.length > MAX_REJECT_REASON_LENGTH) {
3152
- throw new BadRequestException4(`reason must be at most ${MAX_REJECT_REASON_LENGTH} characters`);
4172
+ throw new BadRequestException5(`reason must be at most ${MAX_REJECT_REASON_LENGTH} characters`);
3153
4173
  }
3154
4174
  return claimed;
3155
4175
  }
@@ -3159,7 +4179,7 @@ function remember(claimed) {
3159
4179
  return false;
3160
4180
  }
3161
4181
  if (typeof claimed !== "boolean") {
3162
- throw new BadRequestException4("remember must be a boolean");
4182
+ throw new BadRequestException5("remember must be a boolean");
3163
4183
  }
3164
4184
  return claimed;
3165
4185
  }
@@ -3169,7 +4189,7 @@ function via(claimed) {
3169
4189
  return DEFAULT_VIA;
3170
4190
  }
3171
4191
  if (typeof claimed !== "string" || claimed.length === 0 || claimed.length > MAX_VIA_LENGTH) {
3172
- throw new BadRequestException4(`via must be a string of 1-${MAX_VIA_LENGTH} characters`);
4192
+ throw new BadRequestException5(`via must be a string of 1-${MAX_VIA_LENGTH} characters`);
3173
4193
  }
3174
4194
  return claimed;
3175
4195
  }
@@ -3179,26 +4199,26 @@ function answers(claimed) {
3179
4199
  return void 0;
3180
4200
  }
3181
4201
  if (typeof claimed !== "object" || claimed === null || Array.isArray(claimed)) {
3182
- throw new BadRequestException4("answers must be an object of questionId \u2192 chosen values");
4202
+ throw new BadRequestException5("answers must be an object of questionId \u2192 chosen values");
3183
4203
  }
3184
4204
  const entries = Object.entries(claimed);
3185
4205
  if (entries.length > MAX_ANSWERED_QUESTIONS) {
3186
- throw new BadRequestException4(`answers may cover at most ${MAX_ANSWERED_QUESTIONS} questions`);
4206
+ throw new BadRequestException5(`answers may cover at most ${MAX_ANSWERED_QUESTIONS} questions`);
3187
4207
  }
3188
4208
  const validated = /* @__PURE__ */ Object.create(null);
3189
4209
  for (const [questionId, values] of entries) {
3190
4210
  if (!Array.isArray(values)) {
3191
- throw new BadRequestException4(`answers["${questionId}"] must be an array of chosen values`);
4211
+ throw new BadRequestException5(`answers["${questionId}"] must be an array of chosen values`);
3192
4212
  }
3193
4213
  if (values.length > MAX_VALUES_PER_QUESTION) {
3194
- throw new BadRequestException4(`answers["${questionId}"] may carry at most ${MAX_VALUES_PER_QUESTION} values`);
4214
+ throw new BadRequestException5(`answers["${questionId}"] may carry at most ${MAX_VALUES_PER_QUESTION} values`);
3195
4215
  }
3196
4216
  for (const value of values) {
3197
4217
  if (typeof value !== "string") {
3198
- throw new BadRequestException4(`answers["${questionId}"] must contain only strings`);
4218
+ throw new BadRequestException5(`answers["${questionId}"] must contain only strings`);
3199
4219
  }
3200
4220
  if (value.length > MAX_ANSWER_VALUE_LENGTH) {
3201
- throw new BadRequestException4(`answers["${questionId}"] values must be at most ${MAX_ANSWER_VALUE_LENGTH} characters`);
4221
+ throw new BadRequestException5(`answers["${questionId}"] values must be at most ${MAX_ANSWER_VALUE_LENGTH} characters`);
3202
4222
  }
3203
4223
  }
3204
4224
  validated[questionId] = values;
@@ -3260,64 +4280,64 @@ var ToolCallController = class {
3260
4280
  };
3261
4281
  }
3262
4282
  };
3263
- _ts_decorate18([
3264
- Post5("approve"),
3265
- _ts_param16(0, Req10()),
3266
- _ts_param16(1, Body4()),
3267
- _ts_metadata17("design:type", Function),
3268
- _ts_metadata17("design:paramtypes", [
4283
+ _ts_decorate20([
4284
+ Post6("approve"),
4285
+ _ts_param18(0, Req11()),
4286
+ _ts_param18(1, Body5()),
4287
+ _ts_metadata19("design:type", Function),
4288
+ _ts_metadata19("design:paramtypes", [
3269
4289
  typeof Request === "undefined" ? Object : Request,
3270
4290
  typeof ApproveBody === "undefined" ? Object : ApproveBody
3271
4291
  ]),
3272
- _ts_metadata17("design:returntype", Promise)
4292
+ _ts_metadata19("design:returntype", Promise)
3273
4293
  ], ToolCallController.prototype, "approve", null);
3274
- _ts_decorate18([
3275
- Post5("reject"),
3276
- _ts_param16(0, Req10()),
3277
- _ts_param16(1, Body4()),
3278
- _ts_metadata17("design:type", Function),
3279
- _ts_metadata17("design:paramtypes", [
4294
+ _ts_decorate20([
4295
+ Post6("reject"),
4296
+ _ts_param18(0, Req11()),
4297
+ _ts_param18(1, Body5()),
4298
+ _ts_metadata19("design:type", Function),
4299
+ _ts_metadata19("design:paramtypes", [
3280
4300
  typeof Request === "undefined" ? Object : Request,
3281
4301
  typeof RejectBody === "undefined" ? Object : RejectBody
3282
4302
  ]),
3283
- _ts_metadata17("design:returntype", Promise)
4303
+ _ts_metadata19("design:returntype", Promise)
3284
4304
  ], ToolCallController.prototype, "reject", null);
3285
- _ts_decorate18([
3286
- Post5("answer"),
3287
- _ts_param16(0, Req10()),
3288
- _ts_param16(1, Body4()),
3289
- _ts_metadata17("design:type", Function),
3290
- _ts_metadata17("design:paramtypes", [
4305
+ _ts_decorate20([
4306
+ Post6("answer"),
4307
+ _ts_param18(0, Req11()),
4308
+ _ts_param18(1, Body5()),
4309
+ _ts_metadata19("design:type", Function),
4310
+ _ts_metadata19("design:paramtypes", [
3291
4311
  typeof Request === "undefined" ? Object : Request,
3292
4312
  typeof AnswerBody === "undefined" ? Object : AnswerBody
3293
4313
  ]),
3294
- _ts_metadata17("design:returntype", Promise)
4314
+ _ts_metadata19("design:returntype", Promise)
3295
4315
  ], ToolCallController.prototype, "answer", null);
3296
- _ts_decorate18([
3297
- Post5("skip"),
3298
- _ts_param16(0, Req10()),
3299
- _ts_param16(1, Body4()),
3300
- _ts_metadata17("design:type", Function),
3301
- _ts_metadata17("design:paramtypes", [
4316
+ _ts_decorate20([
4317
+ Post6("skip"),
4318
+ _ts_param18(0, Req11()),
4319
+ _ts_param18(1, Body5()),
4320
+ _ts_metadata19("design:type", Function),
4321
+ _ts_metadata19("design:paramtypes", [
3302
4322
  typeof Request === "undefined" ? Object : Request,
3303
4323
  Object
3304
4324
  ]),
3305
- _ts_metadata17("design:returntype", Promise)
4325
+ _ts_metadata19("design:returntype", Promise)
3306
4326
  ], ToolCallController.prototype, "skip", null);
3307
- ToolCallController = _ts_decorate18([
3308
- Controller11("tool-call"),
3309
- _ts_param16(1, Inject16(AGENT_ACTOR_RESOLVER10)),
3310
- _ts_metadata17("design:type", Function),
3311
- _ts_metadata17("design:paramtypes", [
4327
+ ToolCallController = _ts_decorate20([
4328
+ Controller12("tool-call"),
4329
+ _ts_param18(1, Inject18(AGENT_ACTOR_RESOLVER11)),
4330
+ _ts_metadata19("design:type", Function),
4331
+ _ts_metadata19("design:paramtypes", [
3312
4332
  typeof AgentService === "undefined" ? Object : AgentService,
3313
4333
  typeof ActorResolver === "undefined" ? Object : ActorResolver
3314
4334
  ])
3315
4335
  ], ToolCallController);
3316
4336
 
3317
4337
  // src/controller/tools.controller.ts
3318
- import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER11, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY5, AGENT_REGISTRY as AGENT_REGISTRY3, ALL_AGENTS, AgentRegistry as AgentRegistry4 } from "@dudousxd/nestjs-agent-core";
3319
- import { Controller as Controller12, Get as Get10, Inject as Inject17, NotFoundException as NotFoundException3, Query as Query5, Req as Req11 } from "@nestjs/common";
3320
- function _ts_decorate19(decorators, target, key, desc) {
4338
+ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER12, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY5, AGENT_REGISTRY as AGENT_REGISTRY3, ALL_AGENTS, AgentRegistry as AgentRegistry4 } from "@dudousxd/nestjs-agent-core";
4339
+ import { Controller as Controller13, Get as Get11, Inject as Inject19, NotFoundException as NotFoundException3, Query as Query5, Req as Req12 } from "@nestjs/common";
4340
+ function _ts_decorate21(decorators, target, key, desc) {
3321
4341
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3322
4342
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3323
4343
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3330,19 +4350,19 @@ function _ts_decorate19(decorators, target, key, desc) {
3330
4350
  }
3331
4351
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3332
4352
  }
3333
- __name(_ts_decorate19, "_ts_decorate");
3334
- function _ts_metadata18(metadataKey, metadataValue) {
4353
+ __name(_ts_decorate21, "_ts_decorate");
4354
+ function _ts_metadata20(metadataKey, metadataValue) {
3335
4355
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3336
4356
  return Reflect.metadata(metadataKey, metadataValue);
3337
4357
  }
3338
4358
  }
3339
- __name(_ts_metadata18, "_ts_metadata");
3340
- function _ts_param17(paramIndex, decorator) {
4359
+ __name(_ts_metadata20, "_ts_metadata");
4360
+ function _ts_param19(paramIndex, decorator) {
3341
4361
  return function(target, key) {
3342
4362
  decorator(target, key, paramIndex);
3343
4363
  };
3344
4364
  }
3345
- __name(_ts_param17, "_ts_param");
4365
+ __name(_ts_param19, "_ts_param");
3346
4366
  var ToolsController = class {
3347
4367
  static {
3348
4368
  __name(this, "ToolsController");
@@ -3386,24 +4406,24 @@ var ToolsController = class {
3386
4406
  ];
3387
4407
  }
3388
4408
  };
3389
- _ts_decorate19([
3390
- Get10(),
3391
- _ts_param17(0, Req11()),
3392
- _ts_param17(1, Query5("agent")),
3393
- _ts_metadata18("design:type", Function),
3394
- _ts_metadata18("design:paramtypes", [
4409
+ _ts_decorate21([
4410
+ Get11(),
4411
+ _ts_param19(0, Req12()),
4412
+ _ts_param19(1, Query5("agent")),
4413
+ _ts_metadata20("design:type", Function),
4414
+ _ts_metadata20("design:paramtypes", [
3395
4415
  typeof Request === "undefined" ? Object : Request,
3396
4416
  String
3397
4417
  ]),
3398
- _ts_metadata18("design:returntype", Promise)
4418
+ _ts_metadata20("design:returntype", Promise)
3399
4419
  ], ToolsController.prototype, "list", null);
3400
- ToolsController = _ts_decorate19([
3401
- Controller12("tools"),
3402
- _ts_param17(0, Inject17(AGENT_ACTOR_RESOLVER11)),
3403
- _ts_param17(1, Inject17(AGENT_DEPS_FACTORY5)),
3404
- _ts_param17(2, Inject17(AGENT_REGISTRY3)),
3405
- _ts_metadata18("design:type", Function),
3406
- _ts_metadata18("design:paramtypes", [
4420
+ ToolsController = _ts_decorate21([
4421
+ Controller13("tools"),
4422
+ _ts_param19(0, Inject19(AGENT_ACTOR_RESOLVER12)),
4423
+ _ts_param19(1, Inject19(AGENT_DEPS_FACTORY5)),
4424
+ _ts_param19(2, Inject19(AGENT_REGISTRY3)),
4425
+ _ts_metadata20("design:type", Function),
4426
+ _ts_metadata20("design:paramtypes", [
3407
4427
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
3408
4428
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
3409
4429
  typeof AgentRegistry4 === "undefined" ? Object : AgentRegistry4
@@ -3412,7 +4432,7 @@ ToolsController = _ts_decorate19([
3412
4432
 
3413
4433
  // src/discovery/agent-discovery.service.ts
3414
4434
  import { AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS2, AGENT_REGISTRY as AGENT_REGISTRY4, AgentRegistry as AgentRegistry5 } from "@dudousxd/nestjs-agent-core";
3415
- import { Inject as Inject18, Injectable as Injectable7, Logger as Logger2 } from "@nestjs/common";
4435
+ import { Inject as Inject20, Injectable as Injectable8, Logger as Logger3 } from "@nestjs/common";
3416
4436
  import { DiscoveryService, MetadataScanner } from "@nestjs/core";
3417
4437
 
3418
4438
  // src/decorator/agent.decorator.ts
@@ -3429,7 +4449,7 @@ var SYSTEM_PROMPT_METADATA = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:
3429
4449
  var SYSTEM_PROMPT_CONTRIBUTOR_METADATA = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:system-prompt-contributor");
3430
4450
 
3431
4451
  // src/discovery/agent-discovery.service.ts
3432
- function _ts_decorate20(decorators, target, key, desc) {
4452
+ function _ts_decorate22(decorators, target, key, desc) {
3433
4453
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3434
4454
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3435
4455
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3442,19 +4462,19 @@ function _ts_decorate20(decorators, target, key, desc) {
3442
4462
  }
3443
4463
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3444
4464
  }
3445
- __name(_ts_decorate20, "_ts_decorate");
3446
- function _ts_metadata19(metadataKey, metadataValue) {
4465
+ __name(_ts_decorate22, "_ts_decorate");
4466
+ function _ts_metadata21(metadataKey, metadataValue) {
3447
4467
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3448
4468
  return Reflect.metadata(metadataKey, metadataValue);
3449
4469
  }
3450
4470
  }
3451
- __name(_ts_metadata19, "_ts_metadata");
3452
- function _ts_param18(paramIndex, decorator) {
4471
+ __name(_ts_metadata21, "_ts_metadata");
4472
+ function _ts_param20(paramIndex, decorator) {
3453
4473
  return function(target, key) {
3454
4474
  decorator(target, key, paramIndex);
3455
4475
  };
3456
4476
  }
3457
- __name(_ts_param18, "_ts_param");
4477
+ __name(_ts_param20, "_ts_param");
3458
4478
  var AgentDiscoveryService = class _AgentDiscoveryService {
3459
4479
  static {
3460
4480
  __name(this, "AgentDiscoveryService");
@@ -3463,7 +4483,7 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
3463
4483
  scanner;
3464
4484
  registry;
3465
4485
  contributors;
3466
- logger = new Logger2(_AgentDiscoveryService.name);
4486
+ logger = new Logger3(_AgentDiscoveryService.name);
3467
4487
  constructor(discovery, scanner, registry, contributors) {
3468
4488
  this.discovery = discovery;
3469
4489
  this.scanner = scanner;
@@ -3581,12 +4601,12 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
3581
4601
  return (ctx) => candidate.call(instance, ctx);
3582
4602
  }
3583
4603
  };
3584
- AgentDiscoveryService = _ts_decorate20([
3585
- Injectable7(),
3586
- _ts_param18(2, Inject18(AGENT_REGISTRY4)),
3587
- _ts_param18(3, Inject18(AGENT_PROMPT_CONTRIBUTORS2)),
3588
- _ts_metadata19("design:type", Function),
3589
- _ts_metadata19("design:paramtypes", [
4604
+ AgentDiscoveryService = _ts_decorate22([
4605
+ Injectable8(),
4606
+ _ts_param20(2, Inject20(AGENT_REGISTRY4)),
4607
+ _ts_param20(3, Inject20(AGENT_PROMPT_CONTRIBUTORS2)),
4608
+ _ts_metadata21("design:type", Function),
4609
+ _ts_metadata21("design:paramtypes", [
3590
4610
  typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
3591
4611
  typeof MetadataScanner === "undefined" ? Object : MetadataScanner,
3592
4612
  typeof AgentRegistry5 === "undefined" ? Object : AgentRegistry5,
@@ -3595,8 +4615,8 @@ AgentDiscoveryService = _ts_decorate20([
3595
4615
  ], AgentDiscoveryService);
3596
4616
 
3597
4617
  // src/discovery/ai-tool-discovery.service.ts
3598
- import { AGENT_OPTIONS as AGENT_OPTIONS5, AGENT_REGISTRY as AGENT_REGISTRY5, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY2, normalizeDelegation as normalizeDelegation2 } from "@dudousxd/nestjs-agent-core";
3599
- import { Inject as Inject19, Injectable as Injectable8, Logger as Logger3 } from "@nestjs/common";
4618
+ import { AGENT_OPTIONS as AGENT_OPTIONS6, AGENT_REGISTRY as AGENT_REGISTRY5, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY2, normalizeDelegation as normalizeDelegation2 } from "@dudousxd/nestjs-agent-core";
4619
+ import { Inject as Inject21, Injectable as Injectable9, Logger as Logger4 } from "@nestjs/common";
3600
4620
  import { DiscoveryService as DiscoveryService2 } from "@nestjs/core";
3601
4621
  import { z } from "zod";
3602
4622
 
@@ -3616,7 +4636,7 @@ function isBrandedFunctionalTool(value) {
3616
4636
  __name(isBrandedFunctionalTool, "isBrandedFunctionalTool");
3617
4637
 
3618
4638
  // src/discovery/ai-tool-discovery.service.ts
3619
- function _ts_decorate21(decorators, target, key, desc) {
4639
+ function _ts_decorate23(decorators, target, key, desc) {
3620
4640
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3621
4641
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3622
4642
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3629,19 +4649,19 @@ function _ts_decorate21(decorators, target, key, desc) {
3629
4649
  }
3630
4650
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3631
4651
  }
3632
- __name(_ts_decorate21, "_ts_decorate");
3633
- function _ts_metadata20(metadataKey, metadataValue) {
4652
+ __name(_ts_decorate23, "_ts_decorate");
4653
+ function _ts_metadata22(metadataKey, metadataValue) {
3634
4654
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3635
4655
  return Reflect.metadata(metadataKey, metadataValue);
3636
4656
  }
3637
4657
  }
3638
- __name(_ts_metadata20, "_ts_metadata");
3639
- function _ts_param19(paramIndex, decorator) {
4658
+ __name(_ts_metadata22, "_ts_metadata");
4659
+ function _ts_param21(paramIndex, decorator) {
3640
4660
  return function(target, key) {
3641
4661
  decorator(target, key, paramIndex);
3642
4662
  };
3643
4663
  }
3644
- __name(_ts_param19, "_ts_param");
4664
+ __name(_ts_param21, "_ts_param");
3645
4665
  var AiToolDiscoveryService = class _AiToolDiscoveryService {
3646
4666
  static {
3647
4667
  __name(this, "AiToolDiscoveryService");
@@ -3650,7 +4670,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
3650
4670
  registry;
3651
4671
  agents;
3652
4672
  options;
3653
- logger = new Logger3(_AiToolDiscoveryService.name);
4673
+ logger = new Logger4(_AiToolDiscoveryService.name);
3654
4674
  constructor(discovery, registry, agents, options) {
3655
4675
  this.discovery = discovery;
3656
4676
  this.registry = registry;
@@ -3785,13 +4805,13 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
3785
4805
  return true;
3786
4806
  }
3787
4807
  };
3788
- AiToolDiscoveryService = _ts_decorate21([
3789
- Injectable8(),
3790
- _ts_param19(1, Inject19(AGENT_TOOL_REGISTRY2)),
3791
- _ts_param19(2, Inject19(AGENT_REGISTRY5)),
3792
- _ts_param19(3, Inject19(AGENT_OPTIONS5)),
3793
- _ts_metadata20("design:type", Function),
3794
- _ts_metadata20("design:paramtypes", [
4808
+ AiToolDiscoveryService = _ts_decorate23([
4809
+ Injectable9(),
4810
+ _ts_param21(1, Inject21(AGENT_TOOL_REGISTRY2)),
4811
+ _ts_param21(2, Inject21(AGENT_REGISTRY5)),
4812
+ _ts_param21(3, Inject21(AGENT_OPTIONS6)),
4813
+ _ts_metadata22("design:type", Function),
4814
+ _ts_metadata22("design:paramtypes", [
3795
4815
  typeof DiscoveryService2 === "undefined" ? Object : DiscoveryService2,
3796
4816
  typeof ToolRegistry === "undefined" ? Object : ToolRegistry,
3797
4817
  typeof AgentRegistry === "undefined" ? Object : AgentRegistry,
@@ -3801,7 +4821,7 @@ AiToolDiscoveryService = _ts_decorate21([
3801
4821
 
3802
4822
  // src/discovery/skill-discovery.service.ts
3803
4823
  import { AGENT_SKILL_SOURCES } from "@dudousxd/nestjs-agent-core";
3804
- import { Inject as Inject20, Injectable as Injectable9, Logger as Logger4 } from "@nestjs/common";
4824
+ import { Inject as Inject22, Injectable as Injectable10, Logger as Logger5 } from "@nestjs/common";
3805
4825
  import { DiscoveryService as DiscoveryService3 } from "@nestjs/core";
3806
4826
 
3807
4827
  // src/decorator/skill.decorator.ts
@@ -3818,7 +4838,7 @@ function skillScope(options) {
3818
4838
  __name(skillScope, "skillScope");
3819
4839
 
3820
4840
  // src/discovery/skill-discovery.service.ts
3821
- function _ts_decorate22(decorators, target, key, desc) {
4841
+ function _ts_decorate24(decorators, target, key, desc) {
3822
4842
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3823
4843
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3824
4844
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3831,26 +4851,26 @@ function _ts_decorate22(decorators, target, key, desc) {
3831
4851
  }
3832
4852
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3833
4853
  }
3834
- __name(_ts_decorate22, "_ts_decorate");
3835
- function _ts_metadata21(metadataKey, metadataValue) {
4854
+ __name(_ts_decorate24, "_ts_decorate");
4855
+ function _ts_metadata23(metadataKey, metadataValue) {
3836
4856
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3837
4857
  return Reflect.metadata(metadataKey, metadataValue);
3838
4858
  }
3839
4859
  }
3840
- __name(_ts_metadata21, "_ts_metadata");
3841
- function _ts_param20(paramIndex, decorator) {
4860
+ __name(_ts_metadata23, "_ts_metadata");
4861
+ function _ts_param22(paramIndex, decorator) {
3842
4862
  return function(target, key) {
3843
4863
  decorator(target, key, paramIndex);
3844
4864
  };
3845
4865
  }
3846
- __name(_ts_param20, "_ts_param");
4866
+ __name(_ts_param22, "_ts_param");
3847
4867
  var SkillDiscoveryService = class _SkillDiscoveryService {
3848
4868
  static {
3849
4869
  __name(this, "SkillDiscoveryService");
3850
4870
  }
3851
4871
  discovery;
3852
4872
  declared;
3853
- logger = new Logger4(_SkillDiscoveryService.name);
4873
+ logger = new Logger5(_SkillDiscoveryService.name);
3854
4874
  constructor(discovery, declared) {
3855
4875
  this.discovery = discovery;
3856
4876
  this.declared = declared;
@@ -3887,11 +4907,11 @@ var SkillDiscoveryService = class _SkillDiscoveryService {
3887
4907
  return flat === void 0 ? void 0 : () => flat;
3888
4908
  }
3889
4909
  };
3890
- SkillDiscoveryService = _ts_decorate22([
3891
- Injectable9(),
3892
- _ts_param20(1, Inject20(AGENT_SKILL_SOURCES)),
3893
- _ts_metadata21("design:type", Function),
3894
- _ts_metadata21("design:paramtypes", [
4910
+ SkillDiscoveryService = _ts_decorate24([
4911
+ Injectable10(),
4912
+ _ts_param22(1, Inject22(AGENT_SKILL_SOURCES)),
4913
+ _ts_metadata23("design:type", Function),
4914
+ _ts_metadata23("design:paramtypes", [
3895
4915
  typeof DiscoveryService3 === "undefined" ? Object : DiscoveryService3,
3896
4916
  Array
3897
4917
  ])
@@ -3960,9 +4980,9 @@ var LedgerQuotaProvider = class {
3960
4980
  };
3961
4981
 
3962
4982
  // src/runner/inline-agent-runner.ts
3963
- import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY6, AGENT_STORE as AGENT_STORE5, RunCancelledError as RunCancelledError2, agentFailureCode as agentFailureCode2, encodeStreamEvent as encodeStreamEvent3, publishAgentRunFailed as publishAgentRunFailed2, runAgentLoop as runAgentLoop2, settleAll as settleAll2, settleUnsettledDelegation as settleUnsettledDelegation2 } from "@dudousxd/nestjs-agent-core";
3964
- import { Inject as Inject21, Injectable as Injectable10, Logger as Logger5 } from "@nestjs/common";
3965
- function _ts_decorate23(decorators, target, key, desc) {
4983
+ import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY6, AGENT_STORE as AGENT_STORE6, RunCancelledError as RunCancelledError2, agentFailureCode as agentFailureCode2, encodeStreamEvent as encodeStreamEvent5, publishAgentRunFailed as publishAgentRunFailed2, releaseThreadRun as releaseThreadRun3, runAgentLoop as runAgentLoop2, settleAll as settleAll2, settleUnsettledDelegation as settleUnsettledDelegation2 } from "@dudousxd/nestjs-agent-core";
4984
+ import { Inject as Inject23, Injectable as Injectable11, Logger as Logger6, Optional as Optional10 } from "@nestjs/common";
4985
+ function _ts_decorate25(decorators, target, key, desc) {
3966
4986
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3967
4987
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3968
4988
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3975,26 +4995,27 @@ function _ts_decorate23(decorators, target, key, desc) {
3975
4995
  }
3976
4996
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3977
4997
  }
3978
- __name(_ts_decorate23, "_ts_decorate");
3979
- function _ts_metadata22(metadataKey, metadataValue) {
4998
+ __name(_ts_decorate25, "_ts_decorate");
4999
+ function _ts_metadata24(metadataKey, metadataValue) {
3980
5000
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3981
5001
  return Reflect.metadata(metadataKey, metadataValue);
3982
5002
  }
3983
5003
  }
3984
- __name(_ts_metadata22, "_ts_metadata");
3985
- function _ts_param21(paramIndex, decorator) {
5004
+ __name(_ts_metadata24, "_ts_metadata");
5005
+ function _ts_param23(paramIndex, decorator) {
3986
5006
  return function(target, key) {
3987
5007
  decorator(target, key, paramIndex);
3988
5008
  };
3989
5009
  }
3990
- __name(_ts_param21, "_ts_param");
5010
+ __name(_ts_param23, "_ts_param");
3991
5011
  var InlineAgentRunner = class _InlineAgentRunner {
3992
5012
  static {
3993
5013
  __name(this, "InlineAgentRunner");
3994
5014
  }
3995
5015
  factory;
3996
5016
  store;
3997
- logger = new Logger5(_InlineAgentRunner.name);
5017
+ queue;
5018
+ logger = new Logger6(_InlineAgentRunner.name);
3998
5019
  pending = /* @__PURE__ */ new Map();
3999
5020
  /**
4000
5021
  * Runs someone has asked to stop. In-process, like `pending`, and for the same reason: this runner
@@ -4002,14 +5023,25 @@ var InlineAgentRunner = class _InlineAgentRunner {
4002
5023
  * running it. A cancelled id is dropped once the run settles, so the set tracks live runs only.
4003
5024
  */
4004
5025
  cancelled = /* @__PURE__ */ new Set();
4005
- constructor(factory, store) {
5026
+ /** Top-level runs this process is running now — what {@link isRunActive} answers from. */
5027
+ live = /* @__PURE__ */ new Set();
5028
+ constructor(factory, store, queue) {
4006
5029
  this.factory = factory;
4007
5030
  this.store = store;
5031
+ this.queue = queue;
4008
5032
  }
4009
- async start(input) {
4010
- const runId = crypto.randomUUID();
5033
+ /**
5034
+ * In-process, so exact: a run this process is not running is not running anywhere — the process
5035
+ * that was running it is gone (a restart), and a thread it still holds is a stale claim.
5036
+ */
5037
+ async isRunActive(runId) {
5038
+ return this.live.has(runId);
5039
+ }
5040
+ async start(input, options = {}) {
5041
+ const runId = options.runId ?? crypto.randomUUID();
4011
5042
  const day = input.day ?? utcDay();
4012
5043
  const deps = this.factory.forAgent(input.agentName);
5044
+ this.live.add(runId);
4013
5045
  const hooks = this.topLevelHooks({
4014
5046
  runId,
4015
5047
  deps,
@@ -4021,14 +5053,15 @@ var InlineAgentRunner = class _InlineAgentRunner {
4021
5053
  ...input.agentName !== void 0 ? [
4022
5054
  input.agentName
4023
5055
  ] : []
4024
- ]
5056
+ ],
5057
+ input
4025
5058
  });
4026
5059
  void runAgentLoop2({
4027
5060
  ...deps,
4028
5061
  day
4029
- }, input, hooks).then(() => this.store.setActiveStream(input.threadId, null)).catch(async (error) => {
5062
+ }, input, hooks).then(() => releaseThreadRun3(this.store, input.threadId, runId)).catch(async (error) => {
4030
5063
  if (error instanceof RunCancelledError2) {
4031
- await this.settleCancelled(runId, input.threadId, deps);
5064
+ await this.settleCancelled(runId, input, deps);
4032
5065
  return;
4033
5066
  }
4034
5067
  const message = error instanceof Error ? error.message : String(error);
@@ -4045,13 +5078,17 @@ var InlineAgentRunner = class _InlineAgentRunner {
4045
5078
  errorCode: code,
4046
5079
  errorMessage: message
4047
5080
  });
4048
- await this.store.setActiveStream(input.threadId, null);
4049
5081
  const writer = await deps.sink.open(runId);
5082
+ await this.settleQueue(writer, input, runId, "failed", message);
5083
+ await releaseThreadRun3(this.store, input.threadId, runId);
4050
5084
  await writer.fail({
4051
5085
  code,
4052
5086
  message
4053
5087
  });
4054
- }).finally(() => this.cancelled.delete(runId));
5088
+ }).finally(() => {
5089
+ this.cancelled.delete(runId);
5090
+ this.live.delete(runId);
5091
+ });
4055
5092
  return {
4056
5093
  runId
4057
5094
  };
@@ -4094,11 +5131,12 @@ var InlineAgentRunner = class _InlineAgentRunner {
4094
5131
  * the stream ENDED after a `cancelled` frame rather than failed, so a client that retries failed
4095
5132
  * streams does not retry this one.
4096
5133
  */
4097
- async settleCancelled(runId, threadId, deps) {
5134
+ async settleCancelled(runId, input, deps) {
4098
5135
  this.logger.log(`agent run ${runId} cancelled`);
4099
- await this.store.setActiveStream(threadId, null);
4100
5136
  const writer = await deps.sink.open(runId);
4101
- await writer.write(encodeStreamEvent3({
5137
+ await this.settleQueue(writer, input, runId, "cancelled");
5138
+ await releaseThreadRun3(this.store, input.threadId, runId);
5139
+ await writer.write(encodeStreamEvent5({
4102
5140
  kind: "cancelled"
4103
5141
  }));
4104
5142
  await writer.end();
@@ -4108,6 +5146,38 @@ var InlineAgentRunner = class _InlineAgentRunner {
4108
5146
  });
4109
5147
  }
4110
5148
  /**
5149
+ * Move the thread past a settling TOP-LEVEL run — to the next queued message, which starts here,
5150
+ * or to a paused/empty queue — and write the resulting `queue` frame into this run's stream. A
5151
+ * no-op without a queue-capable store, and for a run that is not a thread's own turn.
5152
+ *
5153
+ * Never throws: the run is settling either way, and a queue that could not be advanced is picked
5154
+ * up by the next send or resume on the thread.
5155
+ */
5156
+ async settleQueue(writer, input, runId, outcome, error) {
5157
+ const queue = this.queue;
5158
+ if (queue === void 0 || !queue.supported || !isThreadTurn2(input)) {
5159
+ return;
5160
+ }
5161
+ const settled = outcome === "completed" && this.cancelled.has(runId) ? "cancelled" : outcome;
5162
+ try {
5163
+ const frame = await queue.handoff({
5164
+ threadId: input.threadId,
5165
+ runId,
5166
+ outcome: settled,
5167
+ ...error !== void 0 ? {
5168
+ error
5169
+ } : {}
5170
+ }, (next, nextRunId) => this.start(next, {
5171
+ runId: nextRunId
5172
+ }));
5173
+ if (frame !== void 0) {
5174
+ await writer.write(encodeStreamEvent5(frame));
5175
+ }
5176
+ } catch (failure) {
5177
+ this.logger.error(`could not advance the queue of thread ${input.threadId} after run ${runId}: ${failure instanceof Error ? failure.message : String(failure)}`);
5178
+ }
5179
+ }
5180
+ /**
4111
5181
  * Park a run on a human, keyed by run + tool call. One map for approvals and for question-set
4112
5182
  * answers alike: both wait on the same key, and `signal` cannot tell (or need to tell) which
4113
5183
  * shape it is delivering — the loop asked for one and only ever gets what the caller sent. A
@@ -4152,10 +5222,23 @@ var InlineAgentRunner = class _InlineAgentRunner {
4152
5222
  });
4153
5223
  }
4154
5224
  topLevelHooks(args) {
4155
- const { runId, deps, actor, day, threadId, chainBelow } = args;
5225
+ const { runId, deps, actor, day, threadId, chainBelow, input } = args;
4156
5226
  return {
4157
5227
  runId,
4158
- openSink: /* @__PURE__ */ __name(() => deps.sink.open(runId), "openSink"),
5228
+ // The loop ends the stream when the turn completes. Just before, the thread passes to the next
5229
+ // queued message (or is released), and the reader is told which — so by the time a client
5230
+ // sees the run end, the thread is already free or already running what it queued.
5231
+ openSink: /* @__PURE__ */ __name(async () => {
5232
+ const writer = await deps.sink.open(runId);
5233
+ return this.queue === void 0 ? writer : {
5234
+ write: /* @__PURE__ */ __name((chunk) => writer.write(chunk), "write"),
5235
+ fail: /* @__PURE__ */ __name((error) => writer.fail(error), "fail"),
5236
+ end: /* @__PURE__ */ __name(async () => {
5237
+ await this.settleQueue(writer, input, runId, "completed");
5238
+ await writer.end();
5239
+ }, "end")
5240
+ };
5241
+ }, "openSink"),
4159
5242
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
4160
5243
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
4161
5244
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
@@ -4368,16 +5451,22 @@ var InlineAgentRunner = class _InlineAgentRunner {
4368
5451
  }
4369
5452
  }
4370
5453
  };
4371
- InlineAgentRunner = _ts_decorate23([
4372
- Injectable10(),
4373
- _ts_param21(0, Inject21(AGENT_DEPS_FACTORY6)),
4374
- _ts_param21(1, Inject21(AGENT_STORE5)),
4375
- _ts_metadata22("design:type", Function),
4376
- _ts_metadata22("design:paramtypes", [
5454
+ InlineAgentRunner = _ts_decorate25([
5455
+ Injectable11(),
5456
+ _ts_param23(0, Inject23(AGENT_DEPS_FACTORY6)),
5457
+ _ts_param23(1, Inject23(AGENT_STORE6)),
5458
+ _ts_param23(2, Optional10()),
5459
+ _ts_metadata24("design:type", Function),
5460
+ _ts_metadata24("design:paramtypes", [
4377
5461
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
4378
- typeof AgentStore === "undefined" ? Object : AgentStore
5462
+ typeof AgentStore === "undefined" ? Object : AgentStore,
5463
+ typeof ChatQueueService === "undefined" ? Object : ChatQueueService
4379
5464
  ])
4380
5465
  ], InlineAgentRunner);
5466
+ function isThreadTurn2(input) {
5467
+ return input.sinkRunId === void 0 && input.deliverTo === void 0;
5468
+ }
5469
+ __name(isThreadTurn2, "isThreadTurn");
4381
5470
 
4382
5471
  // src/skills-config.ts
4383
5472
  import { compositeSkillProvider } from "@dudousxd/nestjs-agent-core";
@@ -4418,7 +5507,7 @@ function resolveSkillsConfig(options, declared) {
4418
5507
  __name(resolveSkillsConfig, "resolveSkillsConfig");
4419
5508
 
4420
5509
  // src/agent.module.ts
4421
- function _ts_decorate24(decorators, target, key, desc) {
5510
+ function _ts_decorate26(decorators, target, key, desc) {
4422
5511
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4423
5512
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
4424
5513
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4431,13 +5520,13 @@ function _ts_decorate24(decorators, target, key, desc) {
4431
5520
  }
4432
5521
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4433
5522
  }
4434
- __name(_ts_decorate24, "_ts_decorate");
5523
+ __name(_ts_decorate26, "_ts_decorate");
4435
5524
  var DEFAULT_PATH = "agent";
4436
- var logger = new Logger6("AgentModule");
5525
+ var logger = new Logger7("AgentModule");
4437
5526
  function externalStoreWrapper(modules) {
4438
5527
  for (const module of modules.values()) {
4439
5528
  if (module.metatype === AgentModule) continue;
4440
- const wrapper = module.providers.get(AGENT_STORE6);
5529
+ const wrapper = module.providers.get(AGENT_STORE7);
4441
5530
  if (wrapper !== void 0) return wrapper;
4442
5531
  }
4443
5532
  return void 0;
@@ -4510,7 +5599,7 @@ function sharedProviders(durable) {
4510
5599
  provide: AGENT_SKILLS3,
4511
5600
  useFactory: /* @__PURE__ */ __name((options, declared) => resolveSkillsConfig(options.skills, declared), "useFactory"),
4512
5601
  inject: [
4513
- AGENT_OPTIONS6,
5602
+ AGENT_OPTIONS7,
4514
5603
  AGENT_SKILL_SOURCES2
4515
5604
  ]
4516
5605
  },
@@ -4520,58 +5609,58 @@ function sharedProviders(durable) {
4520
5609
  provide: AGENT_MEMORY3,
4521
5610
  useFactory: /* @__PURE__ */ __name((options) => options.memory, "useFactory"),
4522
5611
  inject: [
4523
- AGENT_OPTIONS6
5612
+ AGENT_OPTIONS7
4524
5613
  ]
4525
5614
  },
4526
5615
  {
4527
- provide: AGENT_SINK3,
5616
+ provide: AGENT_SINK4,
4528
5617
  useFactory: /* @__PURE__ */ __name((options) => options.sink ?? new InProcessTokenStreamSink(), "useFactory"),
4529
5618
  inject: [
4530
- AGENT_OPTIONS6
5619
+ AGENT_OPTIONS7
4531
5620
  ]
4532
5621
  },
4533
5622
  {
4534
5623
  provide: AGENT_ROLES_POLICY2,
4535
5624
  useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? new DefaultRolesPolicy(options.defaultRoles), "useFactory"),
4536
5625
  inject: [
4537
- AGENT_OPTIONS6
5626
+ AGENT_OPTIONS7
4538
5627
  ]
4539
5628
  },
4540
5629
  {
4541
- provide: AGENT_ACTOR_RESOLVER12,
5630
+ provide: AGENT_ACTOR_RESOLVER13,
4542
5631
  useFactory: /* @__PURE__ */ __name((options) => {
4543
5632
  if (options.actorResolver !== void 0) return options.actorResolver;
4544
5633
  logger.warn("No `actorResolver` configured \u2014 the agent endpoints are PUBLIC: every browser gets its own anonymous identity (an HttpOnly cookie). Set `actorResolver: requestUserActorResolver()` (or your own) to require login.");
4545
5634
  return new AnonymousActorResolver();
4546
5635
  }, "useFactory"),
4547
5636
  inject: [
4548
- AGENT_OPTIONS6
5637
+ AGENT_OPTIONS7
4549
5638
  ]
4550
5639
  },
4551
5640
  {
4552
5641
  provide: AGENT_MODEL2,
4553
5642
  useFactory: /* @__PURE__ */ __name((o) => o.model, "useFactory"),
4554
5643
  inject: [
4555
- AGENT_OPTIONS6
5644
+ AGENT_OPTIONS7
4556
5645
  ]
4557
5646
  },
4558
5647
  {
4559
5648
  // `quota` is either a provider of the host's own or ceilings for the built-in ledger one;
4560
5649
  // omitted, the ledger provider still reports usage, with no ceiling to block on.
4561
- provide: AGENT_QUOTA_PROVIDER2,
5650
+ provide: AGENT_QUOTA_PROVIDER3,
4562
5651
  useFactory: /* @__PURE__ */ __name((o, store) => isQuotaProvider(o.quota) ? o.quota : new LedgerQuotaProvider(store, o.quota?.limits, o.quota?.warnAt !== void 0 ? {
4563
5652
  warnAt: o.quota.warnAt
4564
5653
  } : {}), "useFactory"),
4565
5654
  inject: [
4566
- AGENT_OPTIONS6,
4567
- AGENT_STORE6
5655
+ AGENT_OPTIONS7,
5656
+ AGENT_STORE7
4568
5657
  ]
4569
5658
  },
4570
5659
  {
4571
5660
  provide: AGENT_MODEL_CATALOG3,
4572
5661
  useFactory: /* @__PURE__ */ __name((o) => resolveCatalog(o), "useFactory"),
4573
5662
  inject: [
4574
- AGENT_OPTIONS6
5663
+ AGENT_OPTIONS7
4575
5664
  ]
4576
5665
  },
4577
5666
  AgentDepsFactory2,
@@ -4584,6 +5673,9 @@ function sharedProviders(durable) {
4584
5673
  AgentDiscoveryService,
4585
5674
  AiToolDiscoveryService,
4586
5675
  SkillDiscoveryService,
5676
+ // The thread message queue — every surface, since both runners and the durable workflow settle
5677
+ // into it, and the chat routes enqueue into it.
5678
+ ChatQueueService,
4587
5679
  InlineAgentRunner,
4588
5680
  AgentService,
4589
5681
  // Bound ALWAYS (durable or inline) — the console's cross-thread approvals inbox routes decisions
@@ -4595,10 +5687,10 @@ function sharedProviders(durable) {
4595
5687
  }
4596
5688
  ];
4597
5689
  providers.push({
4598
- provide: AGENT_STORE6,
5690
+ provide: AGENT_STORE7,
4599
5691
  useFactory: /* @__PURE__ */ __name((o, modules) => resolveStore(o, modules), "useFactory"),
4600
5692
  inject: [
4601
- AGENT_OPTIONS6,
5693
+ AGENT_OPTIONS7,
4602
5694
  ModulesContainer
4603
5695
  ]
4604
5696
  });
@@ -4629,22 +5721,23 @@ function sharedProviders(durable) {
4629
5721
  __name(sharedProviders, "sharedProviders");
4630
5722
  function exportsFor() {
4631
5723
  return [
4632
- AGENT_OPTIONS6,
5724
+ AGENT_OPTIONS7,
4633
5725
  AGENT_TOOL_REGISTRY3,
4634
5726
  AGENT_REGISTRY6,
4635
- AGENT_SINK3,
5727
+ AGENT_SINK4,
4636
5728
  AGENT_ROLES_POLICY2,
4637
- AGENT_ACTOR_RESOLVER12,
5729
+ AGENT_ACTOR_RESOLVER13,
4638
5730
  AGENT_MODEL2,
4639
- AGENT_STORE6,
5731
+ AGENT_STORE7,
4640
5732
  AGENT_MODEL_CATALOG3,
4641
- AGENT_QUOTA_PROVIDER2,
5733
+ AGENT_QUOTA_PROVIDER3,
4642
5734
  AGENT_PROMPT_CONTRIBUTORS3,
4643
5735
  AGENT_SKILLS3,
4644
5736
  AGENT_MEMORY3,
4645
5737
  AGENT_DEPS_FACTORY7,
4646
5738
  AgentDepsFactory2,
4647
5739
  AgentService,
5740
+ ChatQueueService,
4648
5741
  InlineAgentRunner,
4649
5742
  AGENT_APPROVAL_PORT
4650
5743
  ];
@@ -4652,6 +5745,7 @@ function exportsFor() {
4652
5745
  __name(exportsFor, "exportsFor");
4653
5746
  var BASE_CONTROLLERS = [
4654
5747
  ChatController,
5748
+ QueueController,
4655
5749
  ThreadsController,
4656
5750
  ToolCallController,
4657
5751
  QuotaController,
@@ -4709,7 +5803,7 @@ var AgentModule = class _AgentModule {
4709
5803
  controllers: controllersForSurface(options.surface),
4710
5804
  providers: [
4711
5805
  {
4712
- provide: AGENT_OPTIONS6,
5806
+ provide: AGENT_OPTIONS7,
4713
5807
  useValue: options
4714
5808
  },
4715
5809
  ...sharedProviders(options.durable ?? false),
@@ -4732,7 +5826,7 @@ var AgentModule = class _AgentModule {
4732
5826
  controllers: controllersForSurface(options.surface),
4733
5827
  providers: [
4734
5828
  {
4735
- provide: AGENT_OPTIONS6,
5829
+ provide: AGENT_OPTIONS7,
4736
5830
  // Stamp the STATIC wiring flags onto the factory result: `durable`/`surface` are
4737
5831
  // authoritative on the async config object (they decided the actual wiring above), and
4738
5832
  // the durable module reads `durable` back off AGENT_OPTIONS. `surface` isn't read back by
@@ -4753,7 +5847,7 @@ var AgentModule = class _AgentModule {
4753
5847
  };
4754
5848
  }
4755
5849
  };
4756
- AgentModule = _ts_decorate24([
5850
+ AgentModule = _ts_decorate26([
4757
5851
  Global2(),
4758
5852
  Module2({})
4759
5853
  ], AgentModule);