@dudousxd/nestjs-agent 1.13.0 → 1.15.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,195 @@ 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
+ } : {}
1959
+ };
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
+ /** `DELETE <base>/threads/:id/queue` — drop every waiting message (and any pause). */
2011
+ async clearQueue(actor, threadId) {
2012
+ await this.assertOwnsThread(actor, threadId);
2013
+ const queue = this.requireQueue();
2014
+ await queue.queueStore().clearQueue(threadId);
2015
+ await queue.queueStore().setQueuePause(threadId, null);
2016
+ return queue.publish(threadId);
2017
+ }
2018
+ /**
2019
+ * `POST <base>/threads/:id/queue/resume` — lift a pause and start the head when nothing is
2020
+ * running. Answers the queue, and the run the head started under, if it did.
2021
+ */
2022
+ async resumeQueue(actor, threadId) {
2023
+ await this.assertOwnsThread(actor, threadId);
2024
+ const queue = this.requireQueue();
2025
+ await queue.queueStore().setQueuePause(threadId, null);
2026
+ const runId = await queue.kick(threadId, this.runner);
2027
+ const state = runId === void 0 ? await queue.publish(threadId) : await queue.state(threadId);
2028
+ return {
2029
+ ...state,
2030
+ ...runId !== void 0 ? {
2031
+ runId
2032
+ } : {}
1267
2033
  };
1268
2034
  }
2035
+ /** The thread a queued message waits on, once the caller is shown to own it. */
2036
+ async assertOwnsQueuedMessage(actor, messageId) {
2037
+ const message = await this.requireQueue().queueStore().getQueuedMessage(messageId);
2038
+ if (message === null) {
2039
+ throw new NotFoundException(`queued message ${messageId} not found`);
2040
+ }
2041
+ await this.assertOwnsThread(actor, message.threadId);
2042
+ return message.threadId;
2043
+ }
1269
2044
  /**
1270
2045
  * Rebuild this turn's attachments from the staging store, keyed by the ids the caller claimed.
1271
2046
  * The model provider fetches {@link MessageAttachment.url} verbatim, so that url is only ever
@@ -1282,7 +2057,7 @@ var AgentService = class {
1282
2057
  }
1283
2058
  const staging = this.staging;
1284
2059
  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.");
2060
+ throw new NotImplementedException2("Message attachments require an AGENT_ATTACHMENT_STAGING provider implementing resolve(); attachment urls are never taken from the request.");
1286
2061
  }
1287
2062
  const resolved = [];
1288
2063
  for (const ref of refs) {
@@ -1440,7 +2215,7 @@ var AgentService = class {
1440
2215
  return;
1441
2216
  }
1442
2217
  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.");
2218
+ throw new NotImplementedException2("Setting a thread's defaultAgent or model requires an AgentStore that implements updateThread(); the bound store does not support it.");
1444
2219
  }
1445
2220
  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
2221
  await this.store.updateThread(threadId, {
@@ -1505,9 +2280,13 @@ var AgentService = class {
1505
2280
  }
1506
2281
  async toDetailView(thread, actor) {
1507
2282
  const summary = await this.toSummaryView(thread);
2283
+ const queue = this.queueing();
1508
2284
  return {
1509
2285
  ...summary,
1510
- messages: await this.freshAttachmentUrls(thread.messages, actor)
2286
+ messages: await this.freshAttachmentUrls(thread.messages, actor),
2287
+ ...queue !== void 0 ? {
2288
+ queue: await queue.state(thread.id)
2289
+ } : {}
1511
2290
  };
1512
2291
  }
1513
2292
  /**
@@ -1570,7 +2349,7 @@ var AgentService = class {
1570
2349
  throw new BadRequestException("comment must be at most 2000 characters");
1571
2350
  }
1572
2351
  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.");
2352
+ throw new NotImplementedException2("Message feedback requires an AgentStore that implements threadOfMessage() and setMessageFeedback(); the bound store does not support it.");
1574
2353
  }
1575
2354
  const threadId = await this.store.threadOfMessage(messageId);
1576
2355
  if (threadId === null) {
@@ -1622,7 +2401,7 @@ var AgentService = class {
1622
2401
  const list = this.attachmentInventory();
1623
2402
  const referencedMediaIds = this.store.referencedMediaIds?.bind(this.store);
1624
2403
  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.");
2404
+ 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
2405
  }
1627
2406
  const stagedBefore = options.olderThan.toISOString();
1628
2407
  const inventory = await list({
@@ -1644,7 +2423,7 @@ var AgentService = class {
1644
2423
  attachmentInventory() {
1645
2424
  const list = this.staging?.list?.bind(this.staging);
1646
2425
  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.");
2426
+ 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
2427
  }
1649
2428
  return list;
1650
2429
  }
@@ -1762,34 +2541,36 @@ var AgentService = class {
1762
2541
  }
1763
2542
  }
1764
2543
  };
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", [
2544
+ AgentService = _ts_decorate7([
2545
+ Injectable6(),
2546
+ _ts_param6(0, Inject6(AGENT_RUNNER)),
2547
+ _ts_param6(1, Inject6(AGENT_STORE5)),
2548
+ _ts_param6(2, Inject6(AGENT_DEPS_FACTORY3)),
2549
+ _ts_param6(3, Optional5()),
2550
+ _ts_param6(3, Inject6(AGENT_ATTACHMENT_STAGING2)),
2551
+ _ts_param6(4, Optional5()),
2552
+ _ts_param6(4, Inject6(AGENT_MODEL_CATALOG)),
2553
+ _ts_param6(5, Optional5()),
2554
+ _ts_param6(5, Inject6(AGENT_QUOTA_PROVIDER2)),
2555
+ _ts_param6(6, Optional5()),
2556
+ _ts_param6(6, Inject6(AGENT_OPTIONS3)),
2557
+ _ts_param6(7, Optional5()),
2558
+ _ts_metadata6("design:type", Function),
2559
+ _ts_metadata6("design:paramtypes", [
1780
2560
  typeof AgentRunner === "undefined" ? Object : AgentRunner,
1781
2561
  typeof AgentStore === "undefined" ? Object : AgentStore,
1782
2562
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
1783
2563
  typeof AttachmentStagingStore === "undefined" ? Object : AttachmentStagingStore,
1784
2564
  typeof ModelCatalog === "undefined" ? Object : ModelCatalog,
1785
2565
  typeof QuotaProvider === "undefined" ? Object : QuotaProvider,
1786
- typeof Pick === "undefined" ? Object : Pick
2566
+ typeof Pick === "undefined" ? Object : Pick,
2567
+ typeof ChatQueueService === "undefined" ? Object : ChatQueueService
1787
2568
  ])
1788
2569
  ], AgentService);
1789
2570
 
1790
2571
  // src/approval-port.adapter.ts
1791
- import { Injectable as Injectable6 } from "@nestjs/common";
1792
- function _ts_decorate7(decorators, target, key, desc) {
2572
+ import { Injectable as Injectable7 } from "@nestjs/common";
2573
+ function _ts_decorate8(decorators, target, key, desc) {
1793
2574
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1794
2575
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1795
2576
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1802,13 +2583,13 @@ function _ts_decorate7(decorators, target, key, desc) {
1802
2583
  }
1803
2584
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1804
2585
  }
1805
- __name(_ts_decorate7, "_ts_decorate");
1806
- function _ts_metadata6(metadataKey, metadataValue) {
2586
+ __name(_ts_decorate8, "_ts_decorate");
2587
+ function _ts_metadata7(metadataKey, metadataValue) {
1807
2588
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1808
2589
  return Reflect.metadata(metadataKey, metadataValue);
1809
2590
  }
1810
2591
  }
1811
- __name(_ts_metadata6, "_ts_metadata");
2592
+ __name(_ts_metadata7, "_ts_metadata");
1812
2593
  var AgentApprovalPortAdapter = class {
1813
2594
  static {
1814
2595
  __name(this, "AgentApprovalPortAdapter");
@@ -1846,18 +2627,18 @@ var AgentApprovalPortAdapter = class {
1846
2627
  });
1847
2628
  }
1848
2629
  };
1849
- AgentApprovalPortAdapter = _ts_decorate7([
1850
- Injectable6(),
1851
- _ts_metadata6("design:type", Function),
1852
- _ts_metadata6("design:paramtypes", [
2630
+ AgentApprovalPortAdapter = _ts_decorate8([
2631
+ Injectable7(),
2632
+ _ts_metadata7("design:type", Function),
2633
+ _ts_metadata7("design:paramtypes", [
1853
2634
  typeof AgentService === "undefined" ? Object : AgentService
1854
2635
  ])
1855
2636
  ], AgentApprovalPortAdapter);
1856
2637
 
1857
2638
  // src/controller/agents.controller.ts
1858
2639
  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) {
2640
+ import { Controller, Get, Inject as Inject7 } from "@nestjs/common";
2641
+ function _ts_decorate9(decorators, target, key, desc) {
1861
2642
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1862
2643
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1863
2644
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1870,19 +2651,19 @@ function _ts_decorate8(decorators, target, key, desc) {
1870
2651
  }
1871
2652
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1872
2653
  }
1873
- __name(_ts_decorate8, "_ts_decorate");
1874
- function _ts_metadata7(metadataKey, metadataValue) {
2654
+ __name(_ts_decorate9, "_ts_decorate");
2655
+ function _ts_metadata8(metadataKey, metadataValue) {
1875
2656
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1876
2657
  return Reflect.metadata(metadataKey, metadataValue);
1877
2658
  }
1878
2659
  }
1879
- __name(_ts_metadata7, "_ts_metadata");
1880
- function _ts_param6(paramIndex, decorator) {
2660
+ __name(_ts_metadata8, "_ts_metadata");
2661
+ function _ts_param7(paramIndex, decorator) {
1881
2662
  return function(target, key) {
1882
2663
  decorator(target, key, paramIndex);
1883
2664
  };
1884
2665
  }
1885
- __name(_ts_param6, "_ts_param");
2666
+ __name(_ts_param7, "_ts_param");
1886
2667
  var AgentsController = class {
1887
2668
  static {
1888
2669
  __name(this, "AgentsController");
@@ -1904,26 +2685,26 @@ var AgentsController = class {
1904
2685
  }));
1905
2686
  }
1906
2687
  };
1907
- _ts_decorate8([
2688
+ _ts_decorate9([
1908
2689
  Get(),
1909
- _ts_metadata7("design:type", Function),
1910
- _ts_metadata7("design:paramtypes", []),
1911
- _ts_metadata7("design:returntype", Array)
2690
+ _ts_metadata8("design:type", Function),
2691
+ _ts_metadata8("design:paramtypes", []),
2692
+ _ts_metadata8("design:returntype", Array)
1912
2693
  ], AgentsController.prototype, "list", null);
1913
- AgentsController = _ts_decorate8([
2694
+ AgentsController = _ts_decorate9([
1914
2695
  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", [
2696
+ _ts_param7(0, Inject7(AGENT_REGISTRY2)),
2697
+ _ts_param7(1, Inject7(AGENT_DEPS_FACTORY4)),
2698
+ _ts_metadata8("design:type", Function),
2699
+ _ts_metadata8("design:paramtypes", [
1919
2700
  typeof AgentRegistry3 === "undefined" ? Object : AgentRegistry3,
1920
2701
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory
1921
2702
  ])
1922
2703
  ], AgentsController);
1923
2704
 
1924
2705
  // 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";
2706
+ import { AGENT_ACTOR_RESOLVER, AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING3, AGENT_OPTIONS as AGENT_OPTIONS4 } from "@dudousxd/nestjs-agent-core";
2707
+ 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
2708
  import { FileInterceptor } from "@nestjs/platform-express";
1928
2709
 
1929
2710
  // src/attachment-limits.ts
@@ -1952,7 +2733,7 @@ function attachmentLimits(options, staging) {
1952
2733
  __name(attachmentLimits, "attachmentLimits");
1953
2734
 
1954
2735
  // src/controller/attachments.controller.ts
1955
- function _ts_decorate9(decorators, target, key, desc) {
2736
+ function _ts_decorate10(decorators, target, key, desc) {
1956
2737
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1957
2738
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1958
2739
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1965,19 +2746,19 @@ function _ts_decorate9(decorators, target, key, desc) {
1965
2746
  }
1966
2747
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1967
2748
  }
1968
- __name(_ts_decorate9, "_ts_decorate");
1969
- function _ts_metadata8(metadataKey, metadataValue) {
2749
+ __name(_ts_decorate10, "_ts_decorate");
2750
+ function _ts_metadata9(metadataKey, metadataValue) {
1970
2751
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1971
2752
  return Reflect.metadata(metadataKey, metadataValue);
1972
2753
  }
1973
2754
  }
1974
- __name(_ts_metadata8, "_ts_metadata");
1975
- function _ts_param7(paramIndex, decorator) {
2755
+ __name(_ts_metadata9, "_ts_metadata");
2756
+ function _ts_param8(paramIndex, decorator) {
1976
2757
  return function(target, key) {
1977
2758
  decorator(target, key, paramIndex);
1978
2759
  };
1979
2760
  }
1980
- __name(_ts_param7, "_ts_param");
2761
+ __name(_ts_param8, "_ts_param");
1981
2762
  var HARD_MAX_ATTACHMENT_BYTES = 32 * 1024 * 1024;
1982
2763
  var ATTACHMENT_PAGE_SIZE = 50;
1983
2764
  var AttachmentsController = class {
@@ -2011,7 +2792,7 @@ var AttachmentsController = class {
2011
2792
  }
2012
2793
  async upload(req, file) {
2013
2794
  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).");
2795
+ throw new NotImplementedException3("Attachment upload is not configured on this server: bind AGENT_ATTACHMENT_STAGING (e.g. import AgentMediaAttachmentsModule).");
2015
2796
  }
2016
2797
  if (file === void 0) {
2017
2798
  throw new BadRequestException2('multipart field "file" is required');
@@ -2033,39 +2814,39 @@ var AttachmentsController = class {
2033
2814
  });
2034
2815
  }
2035
2816
  };
2036
- _ts_decorate9([
2817
+ _ts_decorate10([
2037
2818
  Get2(),
2038
- _ts_param7(0, Req()),
2039
- _ts_metadata8("design:type", Function),
2040
- _ts_metadata8("design:paramtypes", [
2819
+ _ts_param8(0, Req()),
2820
+ _ts_metadata9("design:type", Function),
2821
+ _ts_metadata9("design:paramtypes", [
2041
2822
  typeof Request === "undefined" ? Object : Request
2042
2823
  ]),
2043
- _ts_metadata8("design:returntype", Promise)
2824
+ _ts_metadata9("design:returntype", Promise)
2044
2825
  ], AttachmentsController.prototype, "list", null);
2045
- _ts_decorate9([
2826
+ _ts_decorate10([
2046
2827
  Post(),
2047
2828
  UseInterceptors(FileInterceptor("file", {
2048
2829
  limits: {
2049
2830
  fileSize: HARD_MAX_ATTACHMENT_BYTES
2050
2831
  }
2051
2832
  })),
2052
- _ts_param7(0, Req()),
2053
- _ts_param7(1, UploadedFile()),
2054
- _ts_metadata8("design:type", Function),
2055
- _ts_metadata8("design:paramtypes", [
2833
+ _ts_param8(0, Req()),
2834
+ _ts_param8(1, UploadedFile()),
2835
+ _ts_metadata9("design:type", Function),
2836
+ _ts_metadata9("design:paramtypes", [
2056
2837
  typeof Request === "undefined" ? Object : Request,
2057
2838
  Object
2058
2839
  ]),
2059
- _ts_metadata8("design:returntype", Promise)
2840
+ _ts_metadata9("design:returntype", Promise)
2060
2841
  ], AttachmentsController.prototype, "upload", null);
2061
- AttachmentsController = _ts_decorate9([
2842
+ AttachmentsController = _ts_decorate10([
2062
2843
  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", [
2844
+ _ts_param8(0, Inject8(AGENT_OPTIONS4)),
2845
+ _ts_param8(1, Inject8(AGENT_ACTOR_RESOLVER)),
2846
+ _ts_param8(3, Optional6()),
2847
+ _ts_param8(3, Inject8(AGENT_ATTACHMENT_STAGING3)),
2848
+ _ts_metadata9("design:type", Function),
2849
+ _ts_metadata9("design:paramtypes", [
2069
2850
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
2070
2851
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
2071
2852
  typeof AgentService === "undefined" ? Object : AgentService,
@@ -2075,8 +2856,8 @@ AttachmentsController = _ts_decorate9([
2075
2856
 
2076
2857
  // src/controller/chat.controller.ts
2077
2858
  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) {
2859
+ 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";
2860
+ function _ts_decorate11(decorators, target, key, desc) {
2080
2861
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2081
2862
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2082
2863
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2089,19 +2870,32 @@ function _ts_decorate10(decorators, target, key, desc) {
2089
2870
  }
2090
2871
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2091
2872
  }
2092
- __name(_ts_decorate10, "_ts_decorate");
2093
- function _ts_metadata9(metadataKey, metadataValue) {
2873
+ __name(_ts_decorate11, "_ts_decorate");
2874
+ function _ts_metadata10(metadataKey, metadataValue) {
2094
2875
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2095
2876
  return Reflect.metadata(metadataKey, metadataValue);
2096
2877
  }
2097
2878
  }
2098
- __name(_ts_metadata9, "_ts_metadata");
2099
- function _ts_param8(paramIndex, decorator) {
2879
+ __name(_ts_metadata10, "_ts_metadata");
2880
+ function _ts_param9(paramIndex, decorator) {
2100
2881
  return function(target, key) {
2101
2882
  decorator(target, key, paramIndex);
2102
2883
  };
2103
2884
  }
2104
- __name(_ts_param8, "_ts_param");
2885
+ __name(_ts_param9, "_ts_param");
2886
+ function sendMode(body) {
2887
+ if (body.interrupt === true) {
2888
+ return "interrupt";
2889
+ }
2890
+ if (body.mode === void 0 || body.mode === null) {
2891
+ return "auto";
2892
+ }
2893
+ if (body.mode === "auto" || body.mode === "queue" || body.mode === "interrupt") {
2894
+ return body.mode;
2895
+ }
2896
+ throw new BadRequestException3("mode must be 'auto', 'queue' or 'interrupt'");
2897
+ }
2898
+ __name(sendMode, "sendMode");
2105
2899
  function attachmentRefs(claimed) {
2106
2900
  if (claimed === void 0) {
2107
2901
  return [];
@@ -2139,10 +2933,17 @@ var ChatController = class {
2139
2933
  this.agent = agent;
2140
2934
  this.actorResolver = actorResolver;
2141
2935
  }
2936
+ /**
2937
+ * Start a turn and stream it — or, when the thread already has one running, queue the message and
2938
+ * answer `202 { queued: true, messageId, position, queue, … }` (JSON, no stream): it runs when the
2939
+ * turn ahead of it settles, and the stream of the run holding the thread announces it with a
2940
+ * `queue` frame.
2941
+ */
2142
2942
  async chat(req, res, body) {
2143
2943
  const actor = await this.actorResolver.resolve(req);
2144
2944
  const attachments = attachmentRefs(body.attachments);
2145
- const { runId, threadId } = await this.agent.chat({
2945
+ const mode = sendMode(body);
2946
+ const result = await this.agent.send({
2146
2947
  actor,
2147
2948
  message: body.message,
2148
2949
  ...body.threadId !== void 0 ? {
@@ -2165,8 +2966,14 @@ var ChatController = class {
2165
2966
  } : {},
2166
2967
  ...typeof body.model === "string" && body.model.length > 0 ? {
2167
2968
  model: body.model
2168
- } : {}
2969
+ } : {},
2970
+ mode
2169
2971
  });
2972
+ if (result.queued === true) {
2973
+ res.status(202).json(result);
2974
+ return;
2975
+ }
2976
+ const { runId, threadId } = result;
2170
2977
  await this.pipe(res, runId, this.agent.subscribe(runId), threadId);
2171
2978
  }
2172
2979
  /**
@@ -2256,50 +3063,50 @@ data: ${JSON.stringify(payload)}
2256
3063
  res.end();
2257
3064
  }
2258
3065
  };
2259
- _ts_decorate10([
3066
+ _ts_decorate11([
2260
3067
  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", [
3068
+ _ts_param9(0, Req2()),
3069
+ _ts_param9(1, Res()),
3070
+ _ts_param9(2, Body()),
3071
+ _ts_metadata10("design:type", Function),
3072
+ _ts_metadata10("design:paramtypes", [
2266
3073
  typeof Request === "undefined" ? Object : Request,
2267
3074
  typeof Response === "undefined" ? Object : Response,
2268
3075
  typeof ChatBody === "undefined" ? Object : ChatBody
2269
3076
  ]),
2270
- _ts_metadata9("design:returntype", Promise)
3077
+ _ts_metadata10("design:returntype", Promise)
2271
3078
  ], ChatController.prototype, "chat", null);
2272
- _ts_decorate10([
3079
+ _ts_decorate11([
2273
3080
  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", [
3081
+ _ts_param9(0, Req2()),
3082
+ _ts_param9(1, Param("runId")),
3083
+ _ts_param9(2, Res()),
3084
+ _ts_param9(3, Query("after")),
3085
+ _ts_metadata10("design:type", Function),
3086
+ _ts_metadata10("design:paramtypes", [
2280
3087
  typeof Request === "undefined" ? Object : Request,
2281
3088
  String,
2282
3089
  typeof Response === "undefined" ? Object : Response,
2283
3090
  String
2284
3091
  ]),
2285
- _ts_metadata9("design:returntype", Promise)
3092
+ _ts_metadata10("design:returntype", Promise)
2286
3093
  ], ChatController.prototype, "stream", null);
2287
- _ts_decorate10([
3094
+ _ts_decorate11([
2288
3095
  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", [
3096
+ _ts_param9(0, Req2()),
3097
+ _ts_param9(1, Param("runId")),
3098
+ _ts_metadata10("design:type", Function),
3099
+ _ts_metadata10("design:paramtypes", [
2293
3100
  typeof Request === "undefined" ? Object : Request,
2294
3101
  String
2295
3102
  ]),
2296
- _ts_metadata9("design:returntype", Promise)
3103
+ _ts_metadata10("design:returntype", Promise)
2297
3104
  ], ChatController.prototype, "cancel", null);
2298
- ChatController = _ts_decorate10([
3105
+ ChatController = _ts_decorate11([
2299
3106
  Controller3(),
2300
- _ts_param8(1, Inject8(AGENT_ACTOR_RESOLVER2)),
2301
- _ts_metadata9("design:type", Function),
2302
- _ts_metadata9("design:paramtypes", [
3107
+ _ts_param9(1, Inject9(AGENT_ACTOR_RESOLVER2)),
3108
+ _ts_metadata10("design:type", Function),
3109
+ _ts_metadata10("design:paramtypes", [
2303
3110
  typeof AgentService === "undefined" ? Object : AgentService,
2304
3111
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2305
3112
  ])
@@ -2315,8 +3122,8 @@ function parseCursor(raw) {
2315
3122
  __name(parseCursor, "parseCursor");
2316
3123
 
2317
3124
  // 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";
3125
+ 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";
3126
+ import { Controller as Controller4, Get as Get4, Inject as Inject10, Optional as Optional7, Req as Req3 } from "@nestjs/common";
2320
3127
 
2321
3128
  // src/resolver/anonymous-actor-resolver.ts
2322
3129
  import { createHash, randomBytes } from "crypto";
@@ -2406,7 +3213,7 @@ var AnonymousActorResolver = class {
2406
3213
  };
2407
3214
 
2408
3215
  // src/controller/config.controller.ts
2409
- function _ts_decorate11(decorators, target, key, desc) {
3216
+ function _ts_decorate12(decorators, target, key, desc) {
2410
3217
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2411
3218
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2412
3219
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2419,19 +3226,19 @@ function _ts_decorate11(decorators, target, key, desc) {
2419
3226
  }
2420
3227
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2421
3228
  }
2422
- __name(_ts_decorate11, "_ts_decorate");
2423
- function _ts_metadata10(metadataKey, metadataValue) {
3229
+ __name(_ts_decorate12, "_ts_decorate");
3230
+ function _ts_metadata11(metadataKey, metadataValue) {
2424
3231
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2425
3232
  return Reflect.metadata(metadataKey, metadataValue);
2426
3233
  }
2427
3234
  }
2428
- __name(_ts_metadata10, "_ts_metadata");
2429
- function _ts_param9(paramIndex, decorator) {
3235
+ __name(_ts_metadata11, "_ts_metadata");
3236
+ function _ts_param10(paramIndex, decorator) {
2430
3237
  return function(target, key) {
2431
3238
  decorator(target, key, paramIndex);
2432
3239
  };
2433
3240
  }
2434
- __name(_ts_param9, "_ts_param");
3241
+ __name(_ts_param10, "_ts_param");
2435
3242
  var ConfigController = class {
2436
3243
  static {
2437
3244
  __name(this, "ConfigController");
@@ -2462,25 +3269,25 @@ var ConfigController = class {
2462
3269
  };
2463
3270
  }
2464
3271
  };
2465
- _ts_decorate11([
3272
+ _ts_decorate12([
2466
3273
  Get4(),
2467
- _ts_param9(0, Req3()),
2468
- _ts_metadata10("design:type", Function),
2469
- _ts_metadata10("design:paramtypes", [
3274
+ _ts_param10(0, Req3()),
3275
+ _ts_metadata11("design:type", Function),
3276
+ _ts_metadata11("design:paramtypes", [
2470
3277
  typeof Request === "undefined" ? Object : Request
2471
3278
  ]),
2472
- _ts_metadata10("design:returntype", Promise)
3279
+ _ts_metadata11("design:returntype", Promise)
2473
3280
  ], ConfigController.prototype, "config", null);
2474
- ConfigController = _ts_decorate11([
3281
+ ConfigController = _ts_decorate12([
2475
3282
  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", [
3283
+ _ts_param10(0, Inject10(AGENT_OPTIONS5)),
3284
+ _ts_param10(1, Inject10(AGENT_ACTOR_RESOLVER3)),
3285
+ _ts_param10(2, Optional7()),
3286
+ _ts_param10(2, Inject10(AGENT_ATTACHMENT_STAGING4)),
3287
+ _ts_param10(3, Optional7()),
3288
+ _ts_param10(3, Inject10(AGENT_MODEL_CATALOG2)),
3289
+ _ts_metadata11("design:type", Function),
3290
+ _ts_metadata11("design:paramtypes", [
2484
3291
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
2485
3292
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
2486
3293
  Object,
@@ -2490,8 +3297,8 @@ ConfigController = _ts_decorate11([
2490
3297
 
2491
3298
  // src/controller/memories.controller.ts
2492
3299
  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) {
3300
+ 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";
3301
+ function _ts_decorate13(decorators, target, key, desc) {
2495
3302
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2496
3303
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2497
3304
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2504,19 +3311,19 @@ function _ts_decorate12(decorators, target, key, desc) {
2504
3311
  }
2505
3312
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2506
3313
  }
2507
- __name(_ts_decorate12, "_ts_decorate");
2508
- function _ts_metadata11(metadataKey, metadataValue) {
3314
+ __name(_ts_decorate13, "_ts_decorate");
3315
+ function _ts_metadata12(metadataKey, metadataValue) {
2509
3316
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2510
3317
  return Reflect.metadata(metadataKey, metadataValue);
2511
3318
  }
2512
3319
  }
2513
- __name(_ts_metadata11, "_ts_metadata");
2514
- function _ts_param10(paramIndex, decorator) {
3320
+ __name(_ts_metadata12, "_ts_metadata");
3321
+ function _ts_param11(paramIndex, decorator) {
2515
3322
  return function(target, key) {
2516
3323
  decorator(target, key, paramIndex);
2517
3324
  };
2518
3325
  }
2519
- __name(_ts_param10, "_ts_param");
3326
+ __name(_ts_param11, "_ts_param");
2520
3327
  var MemoriesController = class {
2521
3328
  static {
2522
3329
  __name(this, "MemoriesController");
@@ -2589,35 +3396,35 @@ var MemoriesController = class {
2589
3396
  });
2590
3397
  }
2591
3398
  };
2592
- _ts_decorate12([
3399
+ _ts_decorate13([
2593
3400
  Get5(),
2594
- _ts_param10(0, Req4()),
2595
- _ts_param10(1, Query2("threadId")),
2596
- _ts_metadata11("design:type", Function),
2597
- _ts_metadata11("design:paramtypes", [
3401
+ _ts_param11(0, Req4()),
3402
+ _ts_param11(1, Query2("threadId")),
3403
+ _ts_metadata12("design:type", Function),
3404
+ _ts_metadata12("design:paramtypes", [
2598
3405
  typeof Request === "undefined" ? Object : Request,
2599
3406
  String
2600
3407
  ]),
2601
- _ts_metadata11("design:returntype", Promise)
3408
+ _ts_metadata12("design:returntype", Promise)
2602
3409
  ], MemoriesController.prototype, "list", null);
2603
- _ts_decorate12([
3410
+ _ts_decorate13([
2604
3411
  Delete(":id"),
2605
- _ts_param10(0, Req4()),
2606
- _ts_param10(1, Param2("id")),
2607
- _ts_metadata11("design:type", Function),
2608
- _ts_metadata11("design:paramtypes", [
3412
+ _ts_param11(0, Req4()),
3413
+ _ts_param11(1, Param2("id")),
3414
+ _ts_metadata12("design:type", Function),
3415
+ _ts_metadata12("design:paramtypes", [
2609
3416
  typeof Request === "undefined" ? Object : Request,
2610
3417
  String
2611
3418
  ]),
2612
- _ts_metadata11("design:returntype", Promise)
3419
+ _ts_metadata12("design:returntype", Promise)
2613
3420
  ], MemoriesController.prototype, "forget", null);
2614
- MemoriesController = _ts_decorate12([
3421
+ MemoriesController = _ts_decorate13([
2615
3422
  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", [
3423
+ _ts_param11(0, Inject11(AGENT_ACTOR_RESOLVER4)),
3424
+ _ts_param11(1, Optional8()),
3425
+ _ts_param11(1, Inject11(AGENT_MEMORY2)),
3426
+ _ts_metadata12("design:type", Function),
3427
+ _ts_metadata12("design:paramtypes", [
2621
3428
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
2622
3429
  Object
2623
3430
  ])
@@ -2625,8 +3432,8 @@ MemoriesController = _ts_decorate12([
2625
3432
 
2626
3433
  // src/controller/messages.controller.ts
2627
3434
  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) {
3435
+ import { Body as Body2, Controller as Controller6, HttpCode, Inject as Inject12, Param as Param3, Post as Post3, Req as Req5 } from "@nestjs/common";
3436
+ function _ts_decorate14(decorators, target, key, desc) {
2630
3437
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2631
3438
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2632
3439
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2639,19 +3446,19 @@ function _ts_decorate13(decorators, target, key, desc) {
2639
3446
  }
2640
3447
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2641
3448
  }
2642
- __name(_ts_decorate13, "_ts_decorate");
2643
- function _ts_metadata12(metadataKey, metadataValue) {
3449
+ __name(_ts_decorate14, "_ts_decorate");
3450
+ function _ts_metadata13(metadataKey, metadataValue) {
2644
3451
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2645
3452
  return Reflect.metadata(metadataKey, metadataValue);
2646
3453
  }
2647
3454
  }
2648
- __name(_ts_metadata12, "_ts_metadata");
2649
- function _ts_param11(paramIndex, decorator) {
3455
+ __name(_ts_metadata13, "_ts_metadata");
3456
+ function _ts_param12(paramIndex, decorator) {
2650
3457
  return function(target, key) {
2651
3458
  decorator(target, key, paramIndex);
2652
3459
  };
2653
3460
  }
2654
- __name(_ts_param11, "_ts_param");
3461
+ __name(_ts_param12, "_ts_param");
2655
3462
  var MessagesController = class {
2656
3463
  static {
2657
3464
  __name(this, "MessagesController");
@@ -2679,25 +3486,25 @@ var MessagesController = class {
2679
3486
  };
2680
3487
  }
2681
3488
  };
2682
- _ts_decorate13([
3489
+ _ts_decorate14([
2683
3490
  Post3(":id/feedback"),
2684
3491
  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", [
3492
+ _ts_param12(0, Req5()),
3493
+ _ts_param12(1, Param3("id")),
3494
+ _ts_param12(2, Body2()),
3495
+ _ts_metadata13("design:type", Function),
3496
+ _ts_metadata13("design:paramtypes", [
2690
3497
  typeof Request === "undefined" ? Object : Request,
2691
3498
  String,
2692
3499
  typeof FeedbackBody === "undefined" ? Object : FeedbackBody
2693
3500
  ]),
2694
- _ts_metadata12("design:returntype", Promise)
3501
+ _ts_metadata13("design:returntype", Promise)
2695
3502
  ], MessagesController.prototype, "feedback", null);
2696
- MessagesController = _ts_decorate13([
3503
+ MessagesController = _ts_decorate14([
2697
3504
  Controller6("messages"),
2698
- _ts_param11(1, Inject11(AGENT_ACTOR_RESOLVER5)),
2699
- _ts_metadata12("design:type", Function),
2700
- _ts_metadata12("design:paramtypes", [
3505
+ _ts_param12(1, Inject12(AGENT_ACTOR_RESOLVER5)),
3506
+ _ts_metadata13("design:type", Function),
3507
+ _ts_metadata13("design:paramtypes", [
2701
3508
  typeof AgentService === "undefined" ? Object : AgentService,
2702
3509
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2703
3510
  ])
@@ -2705,8 +3512,8 @@ MessagesController = _ts_decorate13([
2705
3512
 
2706
3513
  // src/controller/models.controller.ts
2707
3514
  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) {
3515
+ import { Controller as Controller7, Get as Get6, Inject as Inject13, Query as Query3, Req as Req6 } from "@nestjs/common";
3516
+ function _ts_decorate15(decorators, target, key, desc) {
2710
3517
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2711
3518
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2712
3519
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2719,19 +3526,19 @@ function _ts_decorate14(decorators, target, key, desc) {
2719
3526
  }
2720
3527
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2721
3528
  }
2722
- __name(_ts_decorate14, "_ts_decorate");
2723
- function _ts_metadata13(metadataKey, metadataValue) {
3529
+ __name(_ts_decorate15, "_ts_decorate");
3530
+ function _ts_metadata14(metadataKey, metadataValue) {
2724
3531
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2725
3532
  return Reflect.metadata(metadataKey, metadataValue);
2726
3533
  }
2727
3534
  }
2728
- __name(_ts_metadata13, "_ts_metadata");
2729
- function _ts_param12(paramIndex, decorator) {
3535
+ __name(_ts_metadata14, "_ts_metadata");
3536
+ function _ts_param13(paramIndex, decorator) {
2730
3537
  return function(target, key) {
2731
3538
  decorator(target, key, paramIndex);
2732
3539
  };
2733
3540
  }
2734
- __name(_ts_param12, "_ts_param");
3541
+ __name(_ts_param13, "_ts_param");
2735
3542
  var ModelsController = class {
2736
3543
  static {
2737
3544
  __name(this, "ModelsController");
@@ -2751,31 +3558,31 @@ var ModelsController = class {
2751
3558
  return this.agent.listModels(actor, agent);
2752
3559
  }
2753
3560
  };
2754
- _ts_decorate14([
3561
+ _ts_decorate15([
2755
3562
  Get6(),
2756
- _ts_param12(0, Req6()),
2757
- _ts_param12(1, Query3("agent")),
2758
- _ts_metadata13("design:type", Function),
2759
- _ts_metadata13("design:paramtypes", [
3563
+ _ts_param13(0, Req6()),
3564
+ _ts_param13(1, Query3("agent")),
3565
+ _ts_metadata14("design:type", Function),
3566
+ _ts_metadata14("design:paramtypes", [
2760
3567
  typeof Request === "undefined" ? Object : Request,
2761
3568
  String
2762
3569
  ]),
2763
- _ts_metadata13("design:returntype", Promise)
3570
+ _ts_metadata14("design:returntype", Promise)
2764
3571
  ], ModelsController.prototype, "list", null);
2765
- ModelsController = _ts_decorate14([
3572
+ ModelsController = _ts_decorate15([
2766
3573
  Controller7("models"),
2767
- _ts_param12(1, Inject12(AGENT_ACTOR_RESOLVER6)),
2768
- _ts_metadata13("design:type", Function),
2769
- _ts_metadata13("design:paramtypes", [
3574
+ _ts_param13(1, Inject13(AGENT_ACTOR_RESOLVER6)),
3575
+ _ts_metadata14("design:type", Function),
3576
+ _ts_metadata14("design:paramtypes", [
2770
3577
  typeof AgentService === "undefined" ? Object : AgentService,
2771
3578
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2772
3579
  ])
2773
3580
  ], ModelsController);
2774
3581
 
2775
- // src/controller/quota.controller.ts
3582
+ // src/controller/queue.controller.ts
2776
3583
  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) {
3584
+ 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";
3585
+ function _ts_decorate16(decorators, target, key, desc) {
2779
3586
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2780
3587
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2781
3588
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2788,19 +3595,160 @@ function _ts_decorate15(decorators, target, key, desc) {
2788
3595
  }
2789
3596
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2790
3597
  }
2791
- __name(_ts_decorate15, "_ts_decorate");
2792
- function _ts_metadata14(metadataKey, metadataValue) {
3598
+ __name(_ts_decorate16, "_ts_decorate");
3599
+ function _ts_metadata15(metadataKey, metadataValue) {
2793
3600
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2794
3601
  return Reflect.metadata(metadataKey, metadataValue);
2795
3602
  }
2796
3603
  }
2797
- __name(_ts_metadata14, "_ts_metadata");
2798
- function _ts_param13(paramIndex, decorator) {
3604
+ __name(_ts_metadata15, "_ts_metadata");
3605
+ function _ts_param14(paramIndex, decorator) {
2799
3606
  return function(target, key) {
2800
3607
  decorator(target, key, paramIndex);
2801
3608
  };
2802
3609
  }
2803
- __name(_ts_param13, "_ts_param");
3610
+ __name(_ts_param14, "_ts_param");
3611
+ var QueueController = class {
3612
+ static {
3613
+ __name(this, "QueueController");
3614
+ }
3615
+ agent;
3616
+ actorResolver;
3617
+ constructor(agent, actorResolver) {
3618
+ this.agent = agent;
3619
+ this.actorResolver = actorResolver;
3620
+ }
3621
+ async list(req, id) {
3622
+ return this.agent.getQueue(await this.actorResolver.resolve(req), id);
3623
+ }
3624
+ async clear(req, id) {
3625
+ return this.agent.clearQueue(await this.actorResolver.resolve(req), id);
3626
+ }
3627
+ /** Lift a pause; the head starts when nothing is running. Carries `runId` when it started. */
3628
+ async resume(req, id) {
3629
+ return this.agent.resumeQueue(await this.actorResolver.resolve(req), id);
3630
+ }
3631
+ async update(req, messageId, body) {
3632
+ const actor = await this.actorResolver.resolve(req);
3633
+ if (body.message !== void 0 && typeof body.message !== "string") {
3634
+ throw new BadRequestException4("message must be a string");
3635
+ }
3636
+ if (body.position !== void 0 && typeof body.position !== "number") {
3637
+ throw new BadRequestException4("position must be a number");
3638
+ }
3639
+ const attachments = body.attachments === void 0 ? void 0 : body.attachments === null ? null : attachmentRefs(body.attachments);
3640
+ return this.agent.updateQueuedMessage(actor, messageId, {
3641
+ ...body.message !== void 0 ? {
3642
+ message: body.message
3643
+ } : {},
3644
+ ...attachments !== void 0 ? {
3645
+ attachments
3646
+ } : {},
3647
+ ...body.position !== void 0 ? {
3648
+ position: body.position
3649
+ } : {}
3650
+ });
3651
+ }
3652
+ async remove(req, messageId) {
3653
+ return this.agent.removeQueuedMessage(await this.actorResolver.resolve(req), messageId);
3654
+ }
3655
+ };
3656
+ _ts_decorate16([
3657
+ Get7("threads/:id/queue"),
3658
+ _ts_param14(0, Req7()),
3659
+ _ts_param14(1, Param4("id")),
3660
+ _ts_metadata15("design:type", Function),
3661
+ _ts_metadata15("design:paramtypes", [
3662
+ typeof Request === "undefined" ? Object : Request,
3663
+ String
3664
+ ]),
3665
+ _ts_metadata15("design:returntype", Promise)
3666
+ ], QueueController.prototype, "list", null);
3667
+ _ts_decorate16([
3668
+ Delete2("threads/:id/queue"),
3669
+ _ts_param14(0, Req7()),
3670
+ _ts_param14(1, Param4("id")),
3671
+ _ts_metadata15("design:type", Function),
3672
+ _ts_metadata15("design:paramtypes", [
3673
+ typeof Request === "undefined" ? Object : Request,
3674
+ String
3675
+ ]),
3676
+ _ts_metadata15("design:returntype", Promise)
3677
+ ], QueueController.prototype, "clear", null);
3678
+ _ts_decorate16([
3679
+ Post4("threads/:id/queue/resume"),
3680
+ _ts_param14(0, Req7()),
3681
+ _ts_param14(1, Param4("id")),
3682
+ _ts_metadata15("design:type", Function),
3683
+ _ts_metadata15("design:paramtypes", [
3684
+ typeof Request === "undefined" ? Object : Request,
3685
+ String
3686
+ ]),
3687
+ _ts_metadata15("design:returntype", Promise)
3688
+ ], QueueController.prototype, "resume", null);
3689
+ _ts_decorate16([
3690
+ Patch("queue/:messageId"),
3691
+ _ts_param14(0, Req7()),
3692
+ _ts_param14(1, Param4("messageId")),
3693
+ _ts_param14(2, Body3()),
3694
+ _ts_metadata15("design:type", Function),
3695
+ _ts_metadata15("design:paramtypes", [
3696
+ typeof Request === "undefined" ? Object : Request,
3697
+ String,
3698
+ typeof UpdateQueuedMessageBody === "undefined" ? Object : UpdateQueuedMessageBody
3699
+ ]),
3700
+ _ts_metadata15("design:returntype", Promise)
3701
+ ], QueueController.prototype, "update", null);
3702
+ _ts_decorate16([
3703
+ Delete2("queue/:messageId"),
3704
+ _ts_param14(0, Req7()),
3705
+ _ts_param14(1, Param4("messageId")),
3706
+ _ts_metadata15("design:type", Function),
3707
+ _ts_metadata15("design:paramtypes", [
3708
+ typeof Request === "undefined" ? Object : Request,
3709
+ String
3710
+ ]),
3711
+ _ts_metadata15("design:returntype", Promise)
3712
+ ], QueueController.prototype, "remove", null);
3713
+ QueueController = _ts_decorate16([
3714
+ Controller8(),
3715
+ _ts_param14(1, Inject14(AGENT_ACTOR_RESOLVER7)),
3716
+ _ts_metadata15("design:type", Function),
3717
+ _ts_metadata15("design:paramtypes", [
3718
+ typeof AgentService === "undefined" ? Object : AgentService,
3719
+ typeof ActorResolver === "undefined" ? Object : ActorResolver
3720
+ ])
3721
+ ], QueueController);
3722
+
3723
+ // src/controller/quota.controller.ts
3724
+ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER8 } from "@dudousxd/nestjs-agent-core";
3725
+ import { Controller as Controller9, Get as Get8, Inject as Inject15, Req as Req8 } from "@nestjs/common";
3726
+ function _ts_decorate17(decorators, target, key, desc) {
3727
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3728
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3729
+ r = Reflect.decorate(decorators, target, key, desc);
3730
+ } else {
3731
+ for (var i = decorators.length - 1; i >= 0; i--) {
3732
+ if (d = decorators[i]) {
3733
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3734
+ }
3735
+ }
3736
+ }
3737
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
3738
+ }
3739
+ __name(_ts_decorate17, "_ts_decorate");
3740
+ function _ts_metadata16(metadataKey, metadataValue) {
3741
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3742
+ return Reflect.metadata(metadataKey, metadataValue);
3743
+ }
3744
+ }
3745
+ __name(_ts_metadata16, "_ts_metadata");
3746
+ function _ts_param15(paramIndex, decorator) {
3747
+ return function(target, key) {
3748
+ decorator(target, key, paramIndex);
3749
+ };
3750
+ }
3751
+ __name(_ts_param15, "_ts_param");
2804
3752
  var QuotaController = class {
2805
3753
  static {
2806
3754
  __name(this, "QuotaController");
@@ -2820,29 +3768,29 @@ var QuotaController = class {
2820
3768
  return this.agent.quotaReport(actor);
2821
3769
  }
2822
3770
  };
2823
- _ts_decorate15([
2824
- Get7(),
2825
- _ts_param13(0, Req7()),
2826
- _ts_metadata14("design:type", Function),
2827
- _ts_metadata14("design:paramtypes", [
3771
+ _ts_decorate17([
3772
+ Get8(),
3773
+ _ts_param15(0, Req8()),
3774
+ _ts_metadata16("design:type", Function),
3775
+ _ts_metadata16("design:paramtypes", [
2828
3776
  typeof Request === "undefined" ? Object : Request
2829
3777
  ]),
2830
- _ts_metadata14("design:returntype", Promise)
3778
+ _ts_metadata16("design:returntype", Promise)
2831
3779
  ], 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", [
3780
+ QuotaController = _ts_decorate17([
3781
+ Controller9("quota"),
3782
+ _ts_param15(1, Inject15(AGENT_ACTOR_RESOLVER8)),
3783
+ _ts_metadata16("design:type", Function),
3784
+ _ts_metadata16("design:paramtypes", [
2837
3785
  typeof AgentService === "undefined" ? Object : AgentService,
2838
3786
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2839
3787
  ])
2840
3788
  ], QuotaController);
2841
3789
 
2842
3790
  // 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) {
3791
+ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER9, AGENT_SKILLS as AGENT_SKILLS2, offerSkills } from "@dudousxd/nestjs-agent-core";
3792
+ import { Controller as Controller10, Get as Get9, Inject as Inject16, Optional as Optional9, Query as Query4, Req as Req9 } from "@nestjs/common";
3793
+ function _ts_decorate18(decorators, target, key, desc) {
2846
3794
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2847
3795
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2848
3796
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2855,19 +3803,19 @@ function _ts_decorate16(decorators, target, key, desc) {
2855
3803
  }
2856
3804
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2857
3805
  }
2858
- __name(_ts_decorate16, "_ts_decorate");
2859
- function _ts_metadata15(metadataKey, metadataValue) {
3806
+ __name(_ts_decorate18, "_ts_decorate");
3807
+ function _ts_metadata17(metadataKey, metadataValue) {
2860
3808
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2861
3809
  return Reflect.metadata(metadataKey, metadataValue);
2862
3810
  }
2863
3811
  }
2864
- __name(_ts_metadata15, "_ts_metadata");
2865
- function _ts_param14(paramIndex, decorator) {
3812
+ __name(_ts_metadata17, "_ts_metadata");
3813
+ function _ts_param16(paramIndex, decorator) {
2866
3814
  return function(target, key) {
2867
3815
  decorator(target, key, paramIndex);
2868
3816
  };
2869
3817
  }
2870
- __name(_ts_param14, "_ts_param");
3818
+ __name(_ts_param16, "_ts_param");
2871
3819
  var SkillsController = class {
2872
3820
  static {
2873
3821
  __name(this, "SkillsController");
@@ -2890,33 +3838,33 @@ var SkillsController = class {
2890
3838
  return offer.entries;
2891
3839
  }
2892
3840
  };
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", [
3841
+ _ts_decorate18([
3842
+ Get9(),
3843
+ _ts_param16(0, Req9()),
3844
+ _ts_param16(1, Query4("threadId")),
3845
+ _ts_metadata17("design:type", Function),
3846
+ _ts_metadata17("design:paramtypes", [
2899
3847
  typeof Request === "undefined" ? Object : Request,
2900
3848
  String
2901
3849
  ]),
2902
- _ts_metadata15("design:returntype", Promise)
3850
+ _ts_metadata17("design:returntype", Promise)
2903
3851
  ], 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", [
3852
+ SkillsController = _ts_decorate18([
3853
+ Controller10("skills"),
3854
+ _ts_param16(0, Inject16(AGENT_ACTOR_RESOLVER9)),
3855
+ _ts_param16(1, Optional9()),
3856
+ _ts_param16(1, Inject16(AGENT_SKILLS2)),
3857
+ _ts_metadata17("design:type", Function),
3858
+ _ts_metadata17("design:paramtypes", [
2911
3859
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
2912
3860
  Object
2913
3861
  ])
2914
3862
  ], SkillsController);
2915
3863
 
2916
3864
  // 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) {
3865
+ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER10 } from "@dudousxd/nestjs-agent-core";
3866
+ 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";
3867
+ function _ts_decorate19(decorators, target, key, desc) {
2920
3868
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2921
3869
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2922
3870
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2929,19 +3877,19 @@ function _ts_decorate17(decorators, target, key, desc) {
2929
3877
  }
2930
3878
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2931
3879
  }
2932
- __name(_ts_decorate17, "_ts_decorate");
2933
- function _ts_metadata16(metadataKey, metadataValue) {
3880
+ __name(_ts_decorate19, "_ts_decorate");
3881
+ function _ts_metadata18(metadataKey, metadataValue) {
2934
3882
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2935
3883
  return Reflect.metadata(metadataKey, metadataValue);
2936
3884
  }
2937
3885
  }
2938
- __name(_ts_metadata16, "_ts_metadata");
2939
- function _ts_param15(paramIndex, decorator) {
3886
+ __name(_ts_metadata18, "_ts_metadata");
3887
+ function _ts_param17(paramIndex, decorator) {
2940
3888
  return function(target, key) {
2941
3889
  decorator(target, key, paramIndex);
2942
3890
  };
2943
3891
  }
2944
- __name(_ts_param15, "_ts_param");
3892
+ __name(_ts_param17, "_ts_param");
2945
3893
  var ThreadsController = class {
2946
3894
  static {
2947
3895
  __name(this, "ThreadsController");
@@ -3008,101 +3956,101 @@ var ThreadsController = class {
3008
3956
  };
3009
3957
  }
3010
3958
  };
3011
- _ts_decorate17([
3012
- Get9(),
3013
- _ts_param15(0, Req9()),
3014
- _ts_metadata16("design:type", Function),
3015
- _ts_metadata16("design:paramtypes", [
3959
+ _ts_decorate19([
3960
+ Get10(),
3961
+ _ts_param17(0, Req10()),
3962
+ _ts_metadata18("design:type", Function),
3963
+ _ts_metadata18("design:paramtypes", [
3016
3964
  typeof Request === "undefined" ? Object : Request
3017
3965
  ]),
3018
- _ts_metadata16("design:returntype", Promise)
3966
+ _ts_metadata18("design:returntype", Promise)
3019
3967
  ], 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", [
3968
+ _ts_decorate19([
3969
+ Get10(":id"),
3970
+ _ts_param17(0, Req10()),
3971
+ _ts_param17(1, Param5("id")),
3972
+ _ts_metadata18("design:type", Function),
3973
+ _ts_metadata18("design:paramtypes", [
3026
3974
  typeof Request === "undefined" ? Object : Request,
3027
3975
  String
3028
3976
  ]),
3029
- _ts_metadata16("design:returntype", Promise)
3977
+ _ts_metadata18("design:returntype", Promise)
3030
3978
  ], 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", [
3979
+ _ts_decorate19([
3980
+ Delete3(":id"),
3981
+ _ts_param17(0, Req10()),
3982
+ _ts_param17(1, Param5("id")),
3983
+ _ts_metadata18("design:type", Function),
3984
+ _ts_metadata18("design:paramtypes", [
3037
3985
  typeof Request === "undefined" ? Object : Request,
3038
3986
  String
3039
3987
  ]),
3040
- _ts_metadata16("design:returntype", Promise)
3988
+ _ts_metadata18("design:returntype", Promise)
3041
3989
  ], 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", [
3990
+ _ts_decorate19([
3991
+ Post5(":id/fork-from/:messageId"),
3992
+ _ts_param17(0, Req10()),
3993
+ _ts_param17(1, Param5("id")),
3994
+ _ts_param17(2, Param5("messageId")),
3995
+ _ts_metadata18("design:type", Function),
3996
+ _ts_metadata18("design:paramtypes", [
3049
3997
  typeof Request === "undefined" ? Object : Request,
3050
3998
  String,
3051
3999
  String
3052
4000
  ]),
3053
- _ts_metadata16("design:returntype", Promise)
4001
+ _ts_metadata18("design:returntype", Promise)
3054
4002
  ], 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", [
4003
+ _ts_decorate19([
4004
+ Patch2(":id"),
4005
+ _ts_param17(0, Req10()),
4006
+ _ts_param17(1, Param5("id")),
4007
+ _ts_param17(2, Body4()),
4008
+ _ts_metadata18("design:type", Function),
4009
+ _ts_metadata18("design:paramtypes", [
3062
4010
  typeof Request === "undefined" ? Object : Request,
3063
4011
  String,
3064
4012
  typeof UpdateThreadBody === "undefined" ? Object : UpdateThreadBody
3065
4013
  ]),
3066
- _ts_metadata16("design:returntype", Promise)
4014
+ _ts_metadata18("design:returntype", Promise)
3067
4015
  ], 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", [
4016
+ _ts_decorate19([
4017
+ Post5(":id/promote"),
4018
+ _ts_param17(0, Req10()),
4019
+ _ts_param17(1, Param5("id")),
4020
+ _ts_metadata18("design:type", Function),
4021
+ _ts_metadata18("design:paramtypes", [
3074
4022
  typeof Request === "undefined" ? Object : Request,
3075
4023
  String
3076
4024
  ]),
3077
- _ts_metadata16("design:returntype", Promise)
4025
+ _ts_metadata18("design:returntype", Promise)
3078
4026
  ], 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", [
4027
+ _ts_decorate19([
4028
+ Delete3(":id/from/:messageId"),
4029
+ _ts_param17(0, Req10()),
4030
+ _ts_param17(1, Param5("id")),
4031
+ _ts_param17(2, Param5("messageId")),
4032
+ _ts_metadata18("design:type", Function),
4033
+ _ts_metadata18("design:paramtypes", [
3086
4034
  typeof Request === "undefined" ? Object : Request,
3087
4035
  String,
3088
4036
  String
3089
4037
  ]),
3090
- _ts_metadata16("design:returntype", Promise)
4038
+ _ts_metadata18("design:returntype", Promise)
3091
4039
  ], 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", [
4040
+ ThreadsController = _ts_decorate19([
4041
+ Controller11("threads"),
4042
+ _ts_param17(1, Inject17(AGENT_ACTOR_RESOLVER10)),
4043
+ _ts_metadata18("design:type", Function),
4044
+ _ts_metadata18("design:paramtypes", [
3097
4045
  typeof AgentService === "undefined" ? Object : AgentService,
3098
4046
  typeof ActorResolver === "undefined" ? Object : ActorResolver
3099
4047
  ])
3100
4048
  ], ThreadsController);
3101
4049
 
3102
4050
  // 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) {
4051
+ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER11 } from "@dudousxd/nestjs-agent-core";
4052
+ import { BadRequestException as BadRequestException5, Body as Body5, Controller as Controller12, Inject as Inject18, Post as Post6, Req as Req11 } from "@nestjs/common";
4053
+ function _ts_decorate20(decorators, target, key, desc) {
3106
4054
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3107
4055
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3108
4056
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3115,19 +4063,19 @@ function _ts_decorate18(decorators, target, key, desc) {
3115
4063
  }
3116
4064
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3117
4065
  }
3118
- __name(_ts_decorate18, "_ts_decorate");
3119
- function _ts_metadata17(metadataKey, metadataValue) {
4066
+ __name(_ts_decorate20, "_ts_decorate");
4067
+ function _ts_metadata19(metadataKey, metadataValue) {
3120
4068
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3121
4069
  return Reflect.metadata(metadataKey, metadataValue);
3122
4070
  }
3123
4071
  }
3124
- __name(_ts_metadata17, "_ts_metadata");
3125
- function _ts_param16(paramIndex, decorator) {
4072
+ __name(_ts_metadata19, "_ts_metadata");
4073
+ function _ts_param18(paramIndex, decorator) {
3126
4074
  return function(target, key) {
3127
4075
  decorator(target, key, paramIndex);
3128
4076
  };
3129
4077
  }
3130
- __name(_ts_param16, "_ts_param");
4078
+ __name(_ts_param18, "_ts_param");
3131
4079
  var MAX_ANSWERED_QUESTIONS = 100;
3132
4080
  var MAX_VALUES_PER_QUESTION = 100;
3133
4081
  var MAX_ANSWER_VALUE_LENGTH = 4096;
@@ -3136,7 +4084,7 @@ var MAX_VIA_LENGTH = 64;
3136
4084
  var DEFAULT_VIA = "web";
3137
4085
  function toolCallId(claimed) {
3138
4086
  if (typeof claimed !== "string" || claimed.length === 0) {
3139
- throw new BadRequestException4("toolCallId must be a non-empty string");
4087
+ throw new BadRequestException5("toolCallId must be a non-empty string");
3140
4088
  }
3141
4089
  return claimed;
3142
4090
  }
@@ -3146,10 +4094,10 @@ function rejectReason(claimed) {
3146
4094
  return void 0;
3147
4095
  }
3148
4096
  if (typeof claimed !== "string") {
3149
- throw new BadRequestException4("reason must be a string");
4097
+ throw new BadRequestException5("reason must be a string");
3150
4098
  }
3151
4099
  if (claimed.length > MAX_REJECT_REASON_LENGTH) {
3152
- throw new BadRequestException4(`reason must be at most ${MAX_REJECT_REASON_LENGTH} characters`);
4100
+ throw new BadRequestException5(`reason must be at most ${MAX_REJECT_REASON_LENGTH} characters`);
3153
4101
  }
3154
4102
  return claimed;
3155
4103
  }
@@ -3159,7 +4107,7 @@ function remember(claimed) {
3159
4107
  return false;
3160
4108
  }
3161
4109
  if (typeof claimed !== "boolean") {
3162
- throw new BadRequestException4("remember must be a boolean");
4110
+ throw new BadRequestException5("remember must be a boolean");
3163
4111
  }
3164
4112
  return claimed;
3165
4113
  }
@@ -3169,7 +4117,7 @@ function via(claimed) {
3169
4117
  return DEFAULT_VIA;
3170
4118
  }
3171
4119
  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`);
4120
+ throw new BadRequestException5(`via must be a string of 1-${MAX_VIA_LENGTH} characters`);
3173
4121
  }
3174
4122
  return claimed;
3175
4123
  }
@@ -3179,26 +4127,26 @@ function answers(claimed) {
3179
4127
  return void 0;
3180
4128
  }
3181
4129
  if (typeof claimed !== "object" || claimed === null || Array.isArray(claimed)) {
3182
- throw new BadRequestException4("answers must be an object of questionId \u2192 chosen values");
4130
+ throw new BadRequestException5("answers must be an object of questionId \u2192 chosen values");
3183
4131
  }
3184
4132
  const entries = Object.entries(claimed);
3185
4133
  if (entries.length > MAX_ANSWERED_QUESTIONS) {
3186
- throw new BadRequestException4(`answers may cover at most ${MAX_ANSWERED_QUESTIONS} questions`);
4134
+ throw new BadRequestException5(`answers may cover at most ${MAX_ANSWERED_QUESTIONS} questions`);
3187
4135
  }
3188
4136
  const validated = /* @__PURE__ */ Object.create(null);
3189
4137
  for (const [questionId, values] of entries) {
3190
4138
  if (!Array.isArray(values)) {
3191
- throw new BadRequestException4(`answers["${questionId}"] must be an array of chosen values`);
4139
+ throw new BadRequestException5(`answers["${questionId}"] must be an array of chosen values`);
3192
4140
  }
3193
4141
  if (values.length > MAX_VALUES_PER_QUESTION) {
3194
- throw new BadRequestException4(`answers["${questionId}"] may carry at most ${MAX_VALUES_PER_QUESTION} values`);
4142
+ throw new BadRequestException5(`answers["${questionId}"] may carry at most ${MAX_VALUES_PER_QUESTION} values`);
3195
4143
  }
3196
4144
  for (const value of values) {
3197
4145
  if (typeof value !== "string") {
3198
- throw new BadRequestException4(`answers["${questionId}"] must contain only strings`);
4146
+ throw new BadRequestException5(`answers["${questionId}"] must contain only strings`);
3199
4147
  }
3200
4148
  if (value.length > MAX_ANSWER_VALUE_LENGTH) {
3201
- throw new BadRequestException4(`answers["${questionId}"] values must be at most ${MAX_ANSWER_VALUE_LENGTH} characters`);
4149
+ throw new BadRequestException5(`answers["${questionId}"] values must be at most ${MAX_ANSWER_VALUE_LENGTH} characters`);
3202
4150
  }
3203
4151
  }
3204
4152
  validated[questionId] = values;
@@ -3260,64 +4208,64 @@ var ToolCallController = class {
3260
4208
  };
3261
4209
  }
3262
4210
  };
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", [
4211
+ _ts_decorate20([
4212
+ Post6("approve"),
4213
+ _ts_param18(0, Req11()),
4214
+ _ts_param18(1, Body5()),
4215
+ _ts_metadata19("design:type", Function),
4216
+ _ts_metadata19("design:paramtypes", [
3269
4217
  typeof Request === "undefined" ? Object : Request,
3270
4218
  typeof ApproveBody === "undefined" ? Object : ApproveBody
3271
4219
  ]),
3272
- _ts_metadata17("design:returntype", Promise)
4220
+ _ts_metadata19("design:returntype", Promise)
3273
4221
  ], 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", [
4222
+ _ts_decorate20([
4223
+ Post6("reject"),
4224
+ _ts_param18(0, Req11()),
4225
+ _ts_param18(1, Body5()),
4226
+ _ts_metadata19("design:type", Function),
4227
+ _ts_metadata19("design:paramtypes", [
3280
4228
  typeof Request === "undefined" ? Object : Request,
3281
4229
  typeof RejectBody === "undefined" ? Object : RejectBody
3282
4230
  ]),
3283
- _ts_metadata17("design:returntype", Promise)
4231
+ _ts_metadata19("design:returntype", Promise)
3284
4232
  ], 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", [
4233
+ _ts_decorate20([
4234
+ Post6("answer"),
4235
+ _ts_param18(0, Req11()),
4236
+ _ts_param18(1, Body5()),
4237
+ _ts_metadata19("design:type", Function),
4238
+ _ts_metadata19("design:paramtypes", [
3291
4239
  typeof Request === "undefined" ? Object : Request,
3292
4240
  typeof AnswerBody === "undefined" ? Object : AnswerBody
3293
4241
  ]),
3294
- _ts_metadata17("design:returntype", Promise)
4242
+ _ts_metadata19("design:returntype", Promise)
3295
4243
  ], 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", [
4244
+ _ts_decorate20([
4245
+ Post6("skip"),
4246
+ _ts_param18(0, Req11()),
4247
+ _ts_param18(1, Body5()),
4248
+ _ts_metadata19("design:type", Function),
4249
+ _ts_metadata19("design:paramtypes", [
3302
4250
  typeof Request === "undefined" ? Object : Request,
3303
4251
  Object
3304
4252
  ]),
3305
- _ts_metadata17("design:returntype", Promise)
4253
+ _ts_metadata19("design:returntype", Promise)
3306
4254
  ], 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", [
4255
+ ToolCallController = _ts_decorate20([
4256
+ Controller12("tool-call"),
4257
+ _ts_param18(1, Inject18(AGENT_ACTOR_RESOLVER11)),
4258
+ _ts_metadata19("design:type", Function),
4259
+ _ts_metadata19("design:paramtypes", [
3312
4260
  typeof AgentService === "undefined" ? Object : AgentService,
3313
4261
  typeof ActorResolver === "undefined" ? Object : ActorResolver
3314
4262
  ])
3315
4263
  ], ToolCallController);
3316
4264
 
3317
4265
  // 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, 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) {
4266
+ 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";
4267
+ import { Controller as Controller13, Get as Get11, Inject as Inject19, NotFoundException as NotFoundException3, Query as Query5, Req as Req12 } from "@nestjs/common";
4268
+ function _ts_decorate21(decorators, target, key, desc) {
3321
4269
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3322
4270
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3323
4271
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3330,19 +4278,19 @@ function _ts_decorate19(decorators, target, key, desc) {
3330
4278
  }
3331
4279
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3332
4280
  }
3333
- __name(_ts_decorate19, "_ts_decorate");
3334
- function _ts_metadata18(metadataKey, metadataValue) {
4281
+ __name(_ts_decorate21, "_ts_decorate");
4282
+ function _ts_metadata20(metadataKey, metadataValue) {
3335
4283
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3336
4284
  return Reflect.metadata(metadataKey, metadataValue);
3337
4285
  }
3338
4286
  }
3339
- __name(_ts_metadata18, "_ts_metadata");
3340
- function _ts_param17(paramIndex, decorator) {
4287
+ __name(_ts_metadata20, "_ts_metadata");
4288
+ function _ts_param19(paramIndex, decorator) {
3341
4289
  return function(target, key) {
3342
4290
  decorator(target, key, paramIndex);
3343
4291
  };
3344
4292
  }
3345
- __name(_ts_param17, "_ts_param");
4293
+ __name(_ts_param19, "_ts_param");
3346
4294
  var ToolsController = class {
3347
4295
  static {
3348
4296
  __name(this, "ToolsController");
@@ -3356,39 +4304,54 @@ var ToolsController = class {
3356
4304
  this.agents = agents;
3357
4305
  }
3358
4306
  async list(req, agent) {
3359
- if (agent !== void 0 && this.agents.get(agent) === void 0) {
4307
+ if (agent !== void 0 && agent !== ALL_AGENTS && this.agents.get(agent) === void 0) {
3360
4308
  throw new NotFoundException3(`No agent named "${agent}"`);
3361
4309
  }
3362
4310
  const actor = await this.actorResolver.resolve(req);
3363
- const deps = this.depsFactory.forAgent(agent);
3364
- const specs = await deps.registry.visibleSpecs(actor, deps.rolesPolicy, deps.toolAllowList);
3365
- return specs.map((spec) => ({
3366
- name: spec.name,
3367
- kind: spec.kind,
3368
- ...spec.presentation !== void 0 ? {
3369
- presentation: spec.presentation
3370
- } : {}
3371
- }));
4311
+ const names = agent === ALL_AGENTS ? [
4312
+ void 0,
4313
+ ...this.agents.list().map((definition) => definition.name)
4314
+ ] : [
4315
+ agent
4316
+ ];
4317
+ const entries = /* @__PURE__ */ new Map();
4318
+ for (const name of names) {
4319
+ const deps = this.depsFactory.forAgent(name);
4320
+ const specs = await deps.registry.visibleSpecs(actor, deps.rolesPolicy, deps.toolAllowList);
4321
+ for (const spec of specs) {
4322
+ if (entries.has(spec.name)) continue;
4323
+ entries.set(spec.name, {
4324
+ name: spec.name,
4325
+ kind: spec.kind,
4326
+ ...spec.presentation !== void 0 ? {
4327
+ presentation: spec.presentation
4328
+ } : {}
4329
+ });
4330
+ }
4331
+ }
4332
+ return [
4333
+ ...entries.values()
4334
+ ];
3372
4335
  }
3373
4336
  };
3374
- _ts_decorate19([
3375
- Get10(),
3376
- _ts_param17(0, Req11()),
3377
- _ts_param17(1, Query5("agent")),
3378
- _ts_metadata18("design:type", Function),
3379
- _ts_metadata18("design:paramtypes", [
4337
+ _ts_decorate21([
4338
+ Get11(),
4339
+ _ts_param19(0, Req12()),
4340
+ _ts_param19(1, Query5("agent")),
4341
+ _ts_metadata20("design:type", Function),
4342
+ _ts_metadata20("design:paramtypes", [
3380
4343
  typeof Request === "undefined" ? Object : Request,
3381
4344
  String
3382
4345
  ]),
3383
- _ts_metadata18("design:returntype", Promise)
4346
+ _ts_metadata20("design:returntype", Promise)
3384
4347
  ], ToolsController.prototype, "list", null);
3385
- ToolsController = _ts_decorate19([
3386
- Controller12("tools"),
3387
- _ts_param17(0, Inject17(AGENT_ACTOR_RESOLVER11)),
3388
- _ts_param17(1, Inject17(AGENT_DEPS_FACTORY5)),
3389
- _ts_param17(2, Inject17(AGENT_REGISTRY3)),
3390
- _ts_metadata18("design:type", Function),
3391
- _ts_metadata18("design:paramtypes", [
4348
+ ToolsController = _ts_decorate21([
4349
+ Controller13("tools"),
4350
+ _ts_param19(0, Inject19(AGENT_ACTOR_RESOLVER12)),
4351
+ _ts_param19(1, Inject19(AGENT_DEPS_FACTORY5)),
4352
+ _ts_param19(2, Inject19(AGENT_REGISTRY3)),
4353
+ _ts_metadata20("design:type", Function),
4354
+ _ts_metadata20("design:paramtypes", [
3392
4355
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
3393
4356
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
3394
4357
  typeof AgentRegistry4 === "undefined" ? Object : AgentRegistry4
@@ -3397,7 +4360,7 @@ ToolsController = _ts_decorate19([
3397
4360
 
3398
4361
  // src/discovery/agent-discovery.service.ts
3399
4362
  import { AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS2, AGENT_REGISTRY as AGENT_REGISTRY4, AgentRegistry as AgentRegistry5 } from "@dudousxd/nestjs-agent-core";
3400
- import { Inject as Inject18, Injectable as Injectable7, Logger as Logger2 } from "@nestjs/common";
4363
+ import { Inject as Inject20, Injectable as Injectable8, Logger as Logger3 } from "@nestjs/common";
3401
4364
  import { DiscoveryService, MetadataScanner } from "@nestjs/core";
3402
4365
 
3403
4366
  // src/decorator/agent.decorator.ts
@@ -3414,7 +4377,7 @@ var SYSTEM_PROMPT_METADATA = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:
3414
4377
  var SYSTEM_PROMPT_CONTRIBUTOR_METADATA = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:system-prompt-contributor");
3415
4378
 
3416
4379
  // src/discovery/agent-discovery.service.ts
3417
- function _ts_decorate20(decorators, target, key, desc) {
4380
+ function _ts_decorate22(decorators, target, key, desc) {
3418
4381
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3419
4382
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3420
4383
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3427,19 +4390,19 @@ function _ts_decorate20(decorators, target, key, desc) {
3427
4390
  }
3428
4391
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3429
4392
  }
3430
- __name(_ts_decorate20, "_ts_decorate");
3431
- function _ts_metadata19(metadataKey, metadataValue) {
4393
+ __name(_ts_decorate22, "_ts_decorate");
4394
+ function _ts_metadata21(metadataKey, metadataValue) {
3432
4395
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3433
4396
  return Reflect.metadata(metadataKey, metadataValue);
3434
4397
  }
3435
4398
  }
3436
- __name(_ts_metadata19, "_ts_metadata");
3437
- function _ts_param18(paramIndex, decorator) {
4399
+ __name(_ts_metadata21, "_ts_metadata");
4400
+ function _ts_param20(paramIndex, decorator) {
3438
4401
  return function(target, key) {
3439
4402
  decorator(target, key, paramIndex);
3440
4403
  };
3441
4404
  }
3442
- __name(_ts_param18, "_ts_param");
4405
+ __name(_ts_param20, "_ts_param");
3443
4406
  var AgentDiscoveryService = class _AgentDiscoveryService {
3444
4407
  static {
3445
4408
  __name(this, "AgentDiscoveryService");
@@ -3448,7 +4411,7 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
3448
4411
  scanner;
3449
4412
  registry;
3450
4413
  contributors;
3451
- logger = new Logger2(_AgentDiscoveryService.name);
4414
+ logger = new Logger3(_AgentDiscoveryService.name);
3452
4415
  constructor(discovery, scanner, registry, contributors) {
3453
4416
  this.discovery = discovery;
3454
4417
  this.scanner = scanner;
@@ -3566,12 +4529,12 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
3566
4529
  return (ctx) => candidate.call(instance, ctx);
3567
4530
  }
3568
4531
  };
3569
- AgentDiscoveryService = _ts_decorate20([
3570
- Injectable7(),
3571
- _ts_param18(2, Inject18(AGENT_REGISTRY4)),
3572
- _ts_param18(3, Inject18(AGENT_PROMPT_CONTRIBUTORS2)),
3573
- _ts_metadata19("design:type", Function),
3574
- _ts_metadata19("design:paramtypes", [
4532
+ AgentDiscoveryService = _ts_decorate22([
4533
+ Injectable8(),
4534
+ _ts_param20(2, Inject20(AGENT_REGISTRY4)),
4535
+ _ts_param20(3, Inject20(AGENT_PROMPT_CONTRIBUTORS2)),
4536
+ _ts_metadata21("design:type", Function),
4537
+ _ts_metadata21("design:paramtypes", [
3575
4538
  typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
3576
4539
  typeof MetadataScanner === "undefined" ? Object : MetadataScanner,
3577
4540
  typeof AgentRegistry5 === "undefined" ? Object : AgentRegistry5,
@@ -3580,8 +4543,8 @@ AgentDiscoveryService = _ts_decorate20([
3580
4543
  ], AgentDiscoveryService);
3581
4544
 
3582
4545
  // src/discovery/ai-tool-discovery.service.ts
3583
- 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";
3584
- import { Inject as Inject19, Injectable as Injectable8, Logger as Logger3 } from "@nestjs/common";
4546
+ 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";
4547
+ import { Inject as Inject21, Injectable as Injectable9, Logger as Logger4 } from "@nestjs/common";
3585
4548
  import { DiscoveryService as DiscoveryService2 } from "@nestjs/core";
3586
4549
  import { z } from "zod";
3587
4550
 
@@ -3601,7 +4564,7 @@ function isBrandedFunctionalTool(value) {
3601
4564
  __name(isBrandedFunctionalTool, "isBrandedFunctionalTool");
3602
4565
 
3603
4566
  // src/discovery/ai-tool-discovery.service.ts
3604
- function _ts_decorate21(decorators, target, key, desc) {
4567
+ function _ts_decorate23(decorators, target, key, desc) {
3605
4568
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3606
4569
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3607
4570
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3614,19 +4577,19 @@ function _ts_decorate21(decorators, target, key, desc) {
3614
4577
  }
3615
4578
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3616
4579
  }
3617
- __name(_ts_decorate21, "_ts_decorate");
3618
- function _ts_metadata20(metadataKey, metadataValue) {
4580
+ __name(_ts_decorate23, "_ts_decorate");
4581
+ function _ts_metadata22(metadataKey, metadataValue) {
3619
4582
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3620
4583
  return Reflect.metadata(metadataKey, metadataValue);
3621
4584
  }
3622
4585
  }
3623
- __name(_ts_metadata20, "_ts_metadata");
3624
- function _ts_param19(paramIndex, decorator) {
4586
+ __name(_ts_metadata22, "_ts_metadata");
4587
+ function _ts_param21(paramIndex, decorator) {
3625
4588
  return function(target, key) {
3626
4589
  decorator(target, key, paramIndex);
3627
4590
  };
3628
4591
  }
3629
- __name(_ts_param19, "_ts_param");
4592
+ __name(_ts_param21, "_ts_param");
3630
4593
  var AiToolDiscoveryService = class _AiToolDiscoveryService {
3631
4594
  static {
3632
4595
  __name(this, "AiToolDiscoveryService");
@@ -3635,7 +4598,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
3635
4598
  registry;
3636
4599
  agents;
3637
4600
  options;
3638
- logger = new Logger3(_AiToolDiscoveryService.name);
4601
+ logger = new Logger4(_AiToolDiscoveryService.name);
3639
4602
  constructor(discovery, registry, agents, options) {
3640
4603
  this.discovery = discovery;
3641
4604
  this.registry = registry;
@@ -3770,13 +4733,13 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
3770
4733
  return true;
3771
4734
  }
3772
4735
  };
3773
- AiToolDiscoveryService = _ts_decorate21([
3774
- Injectable8(),
3775
- _ts_param19(1, Inject19(AGENT_TOOL_REGISTRY2)),
3776
- _ts_param19(2, Inject19(AGENT_REGISTRY5)),
3777
- _ts_param19(3, Inject19(AGENT_OPTIONS5)),
3778
- _ts_metadata20("design:type", Function),
3779
- _ts_metadata20("design:paramtypes", [
4736
+ AiToolDiscoveryService = _ts_decorate23([
4737
+ Injectable9(),
4738
+ _ts_param21(1, Inject21(AGENT_TOOL_REGISTRY2)),
4739
+ _ts_param21(2, Inject21(AGENT_REGISTRY5)),
4740
+ _ts_param21(3, Inject21(AGENT_OPTIONS6)),
4741
+ _ts_metadata22("design:type", Function),
4742
+ _ts_metadata22("design:paramtypes", [
3780
4743
  typeof DiscoveryService2 === "undefined" ? Object : DiscoveryService2,
3781
4744
  typeof ToolRegistry === "undefined" ? Object : ToolRegistry,
3782
4745
  typeof AgentRegistry === "undefined" ? Object : AgentRegistry,
@@ -3786,7 +4749,7 @@ AiToolDiscoveryService = _ts_decorate21([
3786
4749
 
3787
4750
  // src/discovery/skill-discovery.service.ts
3788
4751
  import { AGENT_SKILL_SOURCES } from "@dudousxd/nestjs-agent-core";
3789
- import { Inject as Inject20, Injectable as Injectable9, Logger as Logger4 } from "@nestjs/common";
4752
+ import { Inject as Inject22, Injectable as Injectable10, Logger as Logger5 } from "@nestjs/common";
3790
4753
  import { DiscoveryService as DiscoveryService3 } from "@nestjs/core";
3791
4754
 
3792
4755
  // src/decorator/skill.decorator.ts
@@ -3803,7 +4766,7 @@ function skillScope(options) {
3803
4766
  __name(skillScope, "skillScope");
3804
4767
 
3805
4768
  // src/discovery/skill-discovery.service.ts
3806
- function _ts_decorate22(decorators, target, key, desc) {
4769
+ function _ts_decorate24(decorators, target, key, desc) {
3807
4770
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3808
4771
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3809
4772
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3816,26 +4779,26 @@ function _ts_decorate22(decorators, target, key, desc) {
3816
4779
  }
3817
4780
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3818
4781
  }
3819
- __name(_ts_decorate22, "_ts_decorate");
3820
- function _ts_metadata21(metadataKey, metadataValue) {
4782
+ __name(_ts_decorate24, "_ts_decorate");
4783
+ function _ts_metadata23(metadataKey, metadataValue) {
3821
4784
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3822
4785
  return Reflect.metadata(metadataKey, metadataValue);
3823
4786
  }
3824
4787
  }
3825
- __name(_ts_metadata21, "_ts_metadata");
3826
- function _ts_param20(paramIndex, decorator) {
4788
+ __name(_ts_metadata23, "_ts_metadata");
4789
+ function _ts_param22(paramIndex, decorator) {
3827
4790
  return function(target, key) {
3828
4791
  decorator(target, key, paramIndex);
3829
4792
  };
3830
4793
  }
3831
- __name(_ts_param20, "_ts_param");
4794
+ __name(_ts_param22, "_ts_param");
3832
4795
  var SkillDiscoveryService = class _SkillDiscoveryService {
3833
4796
  static {
3834
4797
  __name(this, "SkillDiscoveryService");
3835
4798
  }
3836
4799
  discovery;
3837
4800
  declared;
3838
- logger = new Logger4(_SkillDiscoveryService.name);
4801
+ logger = new Logger5(_SkillDiscoveryService.name);
3839
4802
  constructor(discovery, declared) {
3840
4803
  this.discovery = discovery;
3841
4804
  this.declared = declared;
@@ -3872,11 +4835,11 @@ var SkillDiscoveryService = class _SkillDiscoveryService {
3872
4835
  return flat === void 0 ? void 0 : () => flat;
3873
4836
  }
3874
4837
  };
3875
- SkillDiscoveryService = _ts_decorate22([
3876
- Injectable9(),
3877
- _ts_param20(1, Inject20(AGENT_SKILL_SOURCES)),
3878
- _ts_metadata21("design:type", Function),
3879
- _ts_metadata21("design:paramtypes", [
4838
+ SkillDiscoveryService = _ts_decorate24([
4839
+ Injectable10(),
4840
+ _ts_param22(1, Inject22(AGENT_SKILL_SOURCES)),
4841
+ _ts_metadata23("design:type", Function),
4842
+ _ts_metadata23("design:paramtypes", [
3880
4843
  typeof DiscoveryService3 === "undefined" ? Object : DiscoveryService3,
3881
4844
  Array
3882
4845
  ])
@@ -3945,9 +4908,9 @@ var LedgerQuotaProvider = class {
3945
4908
  };
3946
4909
 
3947
4910
  // src/runner/inline-agent-runner.ts
3948
- 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";
3949
- import { Inject as Inject21, Injectable as Injectable10, Logger as Logger5 } from "@nestjs/common";
3950
- function _ts_decorate23(decorators, target, key, desc) {
4911
+ 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";
4912
+ import { Inject as Inject23, Injectable as Injectable11, Logger as Logger6, Optional as Optional10 } from "@nestjs/common";
4913
+ function _ts_decorate25(decorators, target, key, desc) {
3951
4914
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3952
4915
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3953
4916
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3960,26 +4923,27 @@ function _ts_decorate23(decorators, target, key, desc) {
3960
4923
  }
3961
4924
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3962
4925
  }
3963
- __name(_ts_decorate23, "_ts_decorate");
3964
- function _ts_metadata22(metadataKey, metadataValue) {
4926
+ __name(_ts_decorate25, "_ts_decorate");
4927
+ function _ts_metadata24(metadataKey, metadataValue) {
3965
4928
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3966
4929
  return Reflect.metadata(metadataKey, metadataValue);
3967
4930
  }
3968
4931
  }
3969
- __name(_ts_metadata22, "_ts_metadata");
3970
- function _ts_param21(paramIndex, decorator) {
4932
+ __name(_ts_metadata24, "_ts_metadata");
4933
+ function _ts_param23(paramIndex, decorator) {
3971
4934
  return function(target, key) {
3972
4935
  decorator(target, key, paramIndex);
3973
4936
  };
3974
4937
  }
3975
- __name(_ts_param21, "_ts_param");
4938
+ __name(_ts_param23, "_ts_param");
3976
4939
  var InlineAgentRunner = class _InlineAgentRunner {
3977
4940
  static {
3978
4941
  __name(this, "InlineAgentRunner");
3979
4942
  }
3980
4943
  factory;
3981
4944
  store;
3982
- logger = new Logger5(_InlineAgentRunner.name);
4945
+ queue;
4946
+ logger = new Logger6(_InlineAgentRunner.name);
3983
4947
  pending = /* @__PURE__ */ new Map();
3984
4948
  /**
3985
4949
  * Runs someone has asked to stop. In-process, like `pending`, and for the same reason: this runner
@@ -3987,14 +4951,25 @@ var InlineAgentRunner = class _InlineAgentRunner {
3987
4951
  * running it. A cancelled id is dropped once the run settles, so the set tracks live runs only.
3988
4952
  */
3989
4953
  cancelled = /* @__PURE__ */ new Set();
3990
- constructor(factory, store) {
4954
+ /** Top-level runs this process is running now — what {@link isRunActive} answers from. */
4955
+ live = /* @__PURE__ */ new Set();
4956
+ constructor(factory, store, queue) {
3991
4957
  this.factory = factory;
3992
4958
  this.store = store;
4959
+ this.queue = queue;
3993
4960
  }
3994
- async start(input) {
3995
- const runId = crypto.randomUUID();
4961
+ /**
4962
+ * In-process, so exact: a run this process is not running is not running anywhere — the process
4963
+ * that was running it is gone (a restart), and a thread it still holds is a stale claim.
4964
+ */
4965
+ async isRunActive(runId) {
4966
+ return this.live.has(runId);
4967
+ }
4968
+ async start(input, options = {}) {
4969
+ const runId = options.runId ?? crypto.randomUUID();
3996
4970
  const day = input.day ?? utcDay();
3997
4971
  const deps = this.factory.forAgent(input.agentName);
4972
+ this.live.add(runId);
3998
4973
  const hooks = this.topLevelHooks({
3999
4974
  runId,
4000
4975
  deps,
@@ -4006,14 +4981,15 @@ var InlineAgentRunner = class _InlineAgentRunner {
4006
4981
  ...input.agentName !== void 0 ? [
4007
4982
  input.agentName
4008
4983
  ] : []
4009
- ]
4984
+ ],
4985
+ input
4010
4986
  });
4011
4987
  void runAgentLoop2({
4012
4988
  ...deps,
4013
4989
  day
4014
- }, input, hooks).then(() => this.store.setActiveStream(input.threadId, null)).catch(async (error) => {
4990
+ }, input, hooks).then(() => releaseThreadRun3(this.store, input.threadId, runId)).catch(async (error) => {
4015
4991
  if (error instanceof RunCancelledError2) {
4016
- await this.settleCancelled(runId, input.threadId, deps);
4992
+ await this.settleCancelled(runId, input, deps);
4017
4993
  return;
4018
4994
  }
4019
4995
  const message = error instanceof Error ? error.message : String(error);
@@ -4030,13 +5006,17 @@ var InlineAgentRunner = class _InlineAgentRunner {
4030
5006
  errorCode: code,
4031
5007
  errorMessage: message
4032
5008
  });
4033
- await this.store.setActiveStream(input.threadId, null);
4034
5009
  const writer = await deps.sink.open(runId);
5010
+ await this.settleQueue(writer, input, runId, "failed", message);
5011
+ await releaseThreadRun3(this.store, input.threadId, runId);
4035
5012
  await writer.fail({
4036
5013
  code,
4037
5014
  message
4038
5015
  });
4039
- }).finally(() => this.cancelled.delete(runId));
5016
+ }).finally(() => {
5017
+ this.cancelled.delete(runId);
5018
+ this.live.delete(runId);
5019
+ });
4040
5020
  return {
4041
5021
  runId
4042
5022
  };
@@ -4079,11 +5059,12 @@ var InlineAgentRunner = class _InlineAgentRunner {
4079
5059
  * the stream ENDED after a `cancelled` frame rather than failed, so a client that retries failed
4080
5060
  * streams does not retry this one.
4081
5061
  */
4082
- async settleCancelled(runId, threadId, deps) {
5062
+ async settleCancelled(runId, input, deps) {
4083
5063
  this.logger.log(`agent run ${runId} cancelled`);
4084
- await this.store.setActiveStream(threadId, null);
4085
5064
  const writer = await deps.sink.open(runId);
4086
- await writer.write(encodeStreamEvent3({
5065
+ await this.settleQueue(writer, input, runId, "cancelled");
5066
+ await releaseThreadRun3(this.store, input.threadId, runId);
5067
+ await writer.write(encodeStreamEvent5({
4087
5068
  kind: "cancelled"
4088
5069
  }));
4089
5070
  await writer.end();
@@ -4093,6 +5074,38 @@ var InlineAgentRunner = class _InlineAgentRunner {
4093
5074
  });
4094
5075
  }
4095
5076
  /**
5077
+ * Move the thread past a settling TOP-LEVEL run — to the next queued message, which starts here,
5078
+ * or to a paused/empty queue — and write the resulting `queue` frame into this run's stream. A
5079
+ * no-op without a queue-capable store, and for a run that is not a thread's own turn.
5080
+ *
5081
+ * Never throws: the run is settling either way, and a queue that could not be advanced is picked
5082
+ * up by the next send or resume on the thread.
5083
+ */
5084
+ async settleQueue(writer, input, runId, outcome, error) {
5085
+ const queue = this.queue;
5086
+ if (queue === void 0 || !queue.supported || !isThreadTurn2(input)) {
5087
+ return;
5088
+ }
5089
+ const settled = outcome === "completed" && this.cancelled.has(runId) ? "cancelled" : outcome;
5090
+ try {
5091
+ const frame = await queue.handoff({
5092
+ threadId: input.threadId,
5093
+ runId,
5094
+ outcome: settled,
5095
+ ...error !== void 0 ? {
5096
+ error
5097
+ } : {}
5098
+ }, (next, nextRunId) => this.start(next, {
5099
+ runId: nextRunId
5100
+ }));
5101
+ if (frame !== void 0) {
5102
+ await writer.write(encodeStreamEvent5(frame));
5103
+ }
5104
+ } catch (failure) {
5105
+ this.logger.error(`could not advance the queue of thread ${input.threadId} after run ${runId}: ${failure instanceof Error ? failure.message : String(failure)}`);
5106
+ }
5107
+ }
5108
+ /**
4096
5109
  * Park a run on a human, keyed by run + tool call. One map for approvals and for question-set
4097
5110
  * answers alike: both wait on the same key, and `signal` cannot tell (or need to tell) which
4098
5111
  * shape it is delivering — the loop asked for one and only ever gets what the caller sent. A
@@ -4137,10 +5150,23 @@ var InlineAgentRunner = class _InlineAgentRunner {
4137
5150
  });
4138
5151
  }
4139
5152
  topLevelHooks(args) {
4140
- const { runId, deps, actor, day, threadId, chainBelow } = args;
5153
+ const { runId, deps, actor, day, threadId, chainBelow, input } = args;
4141
5154
  return {
4142
5155
  runId,
4143
- openSink: /* @__PURE__ */ __name(() => deps.sink.open(runId), "openSink"),
5156
+ // The loop ends the stream when the turn completes. Just before, the thread passes to the next
5157
+ // queued message (or is released), and the reader is told which — so by the time a client
5158
+ // sees the run end, the thread is already free or already running what it queued.
5159
+ openSink: /* @__PURE__ */ __name(async () => {
5160
+ const writer = await deps.sink.open(runId);
5161
+ return this.queue === void 0 ? writer : {
5162
+ write: /* @__PURE__ */ __name((chunk) => writer.write(chunk), "write"),
5163
+ fail: /* @__PURE__ */ __name((error) => writer.fail(error), "fail"),
5164
+ end: /* @__PURE__ */ __name(async () => {
5165
+ await this.settleQueue(writer, input, runId, "completed");
5166
+ await writer.end();
5167
+ }, "end")
5168
+ };
5169
+ }, "openSink"),
4144
5170
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
4145
5171
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
4146
5172
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
@@ -4353,16 +5379,22 @@ var InlineAgentRunner = class _InlineAgentRunner {
4353
5379
  }
4354
5380
  }
4355
5381
  };
4356
- InlineAgentRunner = _ts_decorate23([
4357
- Injectable10(),
4358
- _ts_param21(0, Inject21(AGENT_DEPS_FACTORY6)),
4359
- _ts_param21(1, Inject21(AGENT_STORE5)),
4360
- _ts_metadata22("design:type", Function),
4361
- _ts_metadata22("design:paramtypes", [
5382
+ InlineAgentRunner = _ts_decorate25([
5383
+ Injectable11(),
5384
+ _ts_param23(0, Inject23(AGENT_DEPS_FACTORY6)),
5385
+ _ts_param23(1, Inject23(AGENT_STORE6)),
5386
+ _ts_param23(2, Optional10()),
5387
+ _ts_metadata24("design:type", Function),
5388
+ _ts_metadata24("design:paramtypes", [
4362
5389
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
4363
- typeof AgentStore === "undefined" ? Object : AgentStore
5390
+ typeof AgentStore === "undefined" ? Object : AgentStore,
5391
+ typeof ChatQueueService === "undefined" ? Object : ChatQueueService
4364
5392
  ])
4365
5393
  ], InlineAgentRunner);
5394
+ function isThreadTurn2(input) {
5395
+ return input.sinkRunId === void 0 && input.deliverTo === void 0;
5396
+ }
5397
+ __name(isThreadTurn2, "isThreadTurn");
4366
5398
 
4367
5399
  // src/skills-config.ts
4368
5400
  import { compositeSkillProvider } from "@dudousxd/nestjs-agent-core";
@@ -4403,7 +5435,7 @@ function resolveSkillsConfig(options, declared) {
4403
5435
  __name(resolveSkillsConfig, "resolveSkillsConfig");
4404
5436
 
4405
5437
  // src/agent.module.ts
4406
- function _ts_decorate24(decorators, target, key, desc) {
5438
+ function _ts_decorate26(decorators, target, key, desc) {
4407
5439
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4408
5440
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
4409
5441
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4416,13 +5448,13 @@ function _ts_decorate24(decorators, target, key, desc) {
4416
5448
  }
4417
5449
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4418
5450
  }
4419
- __name(_ts_decorate24, "_ts_decorate");
5451
+ __name(_ts_decorate26, "_ts_decorate");
4420
5452
  var DEFAULT_PATH = "agent";
4421
- var logger = new Logger6("AgentModule");
5453
+ var logger = new Logger7("AgentModule");
4422
5454
  function externalStoreWrapper(modules) {
4423
5455
  for (const module of modules.values()) {
4424
5456
  if (module.metatype === AgentModule) continue;
4425
- const wrapper = module.providers.get(AGENT_STORE6);
5457
+ const wrapper = module.providers.get(AGENT_STORE7);
4426
5458
  if (wrapper !== void 0) return wrapper;
4427
5459
  }
4428
5460
  return void 0;
@@ -4495,7 +5527,7 @@ function sharedProviders(durable) {
4495
5527
  provide: AGENT_SKILLS3,
4496
5528
  useFactory: /* @__PURE__ */ __name((options, declared) => resolveSkillsConfig(options.skills, declared), "useFactory"),
4497
5529
  inject: [
4498
- AGENT_OPTIONS6,
5530
+ AGENT_OPTIONS7,
4499
5531
  AGENT_SKILL_SOURCES2
4500
5532
  ]
4501
5533
  },
@@ -4505,58 +5537,58 @@ function sharedProviders(durable) {
4505
5537
  provide: AGENT_MEMORY3,
4506
5538
  useFactory: /* @__PURE__ */ __name((options) => options.memory, "useFactory"),
4507
5539
  inject: [
4508
- AGENT_OPTIONS6
5540
+ AGENT_OPTIONS7
4509
5541
  ]
4510
5542
  },
4511
5543
  {
4512
- provide: AGENT_SINK3,
5544
+ provide: AGENT_SINK4,
4513
5545
  useFactory: /* @__PURE__ */ __name((options) => options.sink ?? new InProcessTokenStreamSink(), "useFactory"),
4514
5546
  inject: [
4515
- AGENT_OPTIONS6
5547
+ AGENT_OPTIONS7
4516
5548
  ]
4517
5549
  },
4518
5550
  {
4519
5551
  provide: AGENT_ROLES_POLICY2,
4520
5552
  useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? new DefaultRolesPolicy(options.defaultRoles), "useFactory"),
4521
5553
  inject: [
4522
- AGENT_OPTIONS6
5554
+ AGENT_OPTIONS7
4523
5555
  ]
4524
5556
  },
4525
5557
  {
4526
- provide: AGENT_ACTOR_RESOLVER12,
5558
+ provide: AGENT_ACTOR_RESOLVER13,
4527
5559
  useFactory: /* @__PURE__ */ __name((options) => {
4528
5560
  if (options.actorResolver !== void 0) return options.actorResolver;
4529
5561
  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.");
4530
5562
  return new AnonymousActorResolver();
4531
5563
  }, "useFactory"),
4532
5564
  inject: [
4533
- AGENT_OPTIONS6
5565
+ AGENT_OPTIONS7
4534
5566
  ]
4535
5567
  },
4536
5568
  {
4537
5569
  provide: AGENT_MODEL2,
4538
5570
  useFactory: /* @__PURE__ */ __name((o) => o.model, "useFactory"),
4539
5571
  inject: [
4540
- AGENT_OPTIONS6
5572
+ AGENT_OPTIONS7
4541
5573
  ]
4542
5574
  },
4543
5575
  {
4544
5576
  // `quota` is either a provider of the host's own or ceilings for the built-in ledger one;
4545
5577
  // omitted, the ledger provider still reports usage, with no ceiling to block on.
4546
- provide: AGENT_QUOTA_PROVIDER2,
5578
+ provide: AGENT_QUOTA_PROVIDER3,
4547
5579
  useFactory: /* @__PURE__ */ __name((o, store) => isQuotaProvider(o.quota) ? o.quota : new LedgerQuotaProvider(store, o.quota?.limits, o.quota?.warnAt !== void 0 ? {
4548
5580
  warnAt: o.quota.warnAt
4549
5581
  } : {}), "useFactory"),
4550
5582
  inject: [
4551
- AGENT_OPTIONS6,
4552
- AGENT_STORE6
5583
+ AGENT_OPTIONS7,
5584
+ AGENT_STORE7
4553
5585
  ]
4554
5586
  },
4555
5587
  {
4556
5588
  provide: AGENT_MODEL_CATALOG3,
4557
5589
  useFactory: /* @__PURE__ */ __name((o) => resolveCatalog(o), "useFactory"),
4558
5590
  inject: [
4559
- AGENT_OPTIONS6
5591
+ AGENT_OPTIONS7
4560
5592
  ]
4561
5593
  },
4562
5594
  AgentDepsFactory2,
@@ -4569,6 +5601,9 @@ function sharedProviders(durable) {
4569
5601
  AgentDiscoveryService,
4570
5602
  AiToolDiscoveryService,
4571
5603
  SkillDiscoveryService,
5604
+ // The thread message queue — every surface, since both runners and the durable workflow settle
5605
+ // into it, and the chat routes enqueue into it.
5606
+ ChatQueueService,
4572
5607
  InlineAgentRunner,
4573
5608
  AgentService,
4574
5609
  // Bound ALWAYS (durable or inline) — the console's cross-thread approvals inbox routes decisions
@@ -4580,10 +5615,10 @@ function sharedProviders(durable) {
4580
5615
  }
4581
5616
  ];
4582
5617
  providers.push({
4583
- provide: AGENT_STORE6,
5618
+ provide: AGENT_STORE7,
4584
5619
  useFactory: /* @__PURE__ */ __name((o, modules) => resolveStore(o, modules), "useFactory"),
4585
5620
  inject: [
4586
- AGENT_OPTIONS6,
5621
+ AGENT_OPTIONS7,
4587
5622
  ModulesContainer
4588
5623
  ]
4589
5624
  });
@@ -4614,22 +5649,23 @@ function sharedProviders(durable) {
4614
5649
  __name(sharedProviders, "sharedProviders");
4615
5650
  function exportsFor() {
4616
5651
  return [
4617
- AGENT_OPTIONS6,
5652
+ AGENT_OPTIONS7,
4618
5653
  AGENT_TOOL_REGISTRY3,
4619
5654
  AGENT_REGISTRY6,
4620
- AGENT_SINK3,
5655
+ AGENT_SINK4,
4621
5656
  AGENT_ROLES_POLICY2,
4622
- AGENT_ACTOR_RESOLVER12,
5657
+ AGENT_ACTOR_RESOLVER13,
4623
5658
  AGENT_MODEL2,
4624
- AGENT_STORE6,
5659
+ AGENT_STORE7,
4625
5660
  AGENT_MODEL_CATALOG3,
4626
- AGENT_QUOTA_PROVIDER2,
5661
+ AGENT_QUOTA_PROVIDER3,
4627
5662
  AGENT_PROMPT_CONTRIBUTORS3,
4628
5663
  AGENT_SKILLS3,
4629
5664
  AGENT_MEMORY3,
4630
5665
  AGENT_DEPS_FACTORY7,
4631
5666
  AgentDepsFactory2,
4632
5667
  AgentService,
5668
+ ChatQueueService,
4633
5669
  InlineAgentRunner,
4634
5670
  AGENT_APPROVAL_PORT
4635
5671
  ];
@@ -4637,6 +5673,7 @@ function exportsFor() {
4637
5673
  __name(exportsFor, "exportsFor");
4638
5674
  var BASE_CONTROLLERS = [
4639
5675
  ChatController,
5676
+ QueueController,
4640
5677
  ThreadsController,
4641
5678
  ToolCallController,
4642
5679
  QuotaController,
@@ -4694,7 +5731,7 @@ var AgentModule = class _AgentModule {
4694
5731
  controllers: controllersForSurface(options.surface),
4695
5732
  providers: [
4696
5733
  {
4697
- provide: AGENT_OPTIONS6,
5734
+ provide: AGENT_OPTIONS7,
4698
5735
  useValue: options
4699
5736
  },
4700
5737
  ...sharedProviders(options.durable ?? false),
@@ -4717,7 +5754,7 @@ var AgentModule = class _AgentModule {
4717
5754
  controllers: controllersForSurface(options.surface),
4718
5755
  providers: [
4719
5756
  {
4720
- provide: AGENT_OPTIONS6,
5757
+ provide: AGENT_OPTIONS7,
4721
5758
  // Stamp the STATIC wiring flags onto the factory result: `durable`/`surface` are
4722
5759
  // authoritative on the async config object (they decided the actual wiring above), and
4723
5760
  // the durable module reads `durable` back off AGENT_OPTIONS. `surface` isn't read back by
@@ -4738,7 +5775,7 @@ var AgentModule = class _AgentModule {
4738
5775
  };
4739
5776
  }
4740
5777
  };
4741
- AgentModule = _ts_decorate24([
5778
+ AgentModule = _ts_decorate26([
4742
5779
  Global2(),
4743
5780
  Module2({})
4744
5781
  ], AgentModule);