@dudousxd/nestjs-agent 1.14.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.
package/dist/index.cjs CHANGED
@@ -36,6 +36,7 @@ __export(index_exports, {
36
36
  AiToolDiscoveryService: () => AiToolDiscoveryService,
37
37
  AnonymousActorResolver: () => AnonymousActorResolver,
38
38
  AttachmentsController: () => AttachmentsController,
39
+ ChatQueueService: () => ChatQueueService,
39
40
  ConfigController: () => ConfigController,
40
41
  DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES: () => DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES,
41
42
  DEFAULT_MAX_ATTACHMENT_BYTES: () => DEFAULT_MAX_ATTACHMENT_BYTES,
@@ -47,6 +48,7 @@ __export(index_exports, {
47
48
  MemoriesController: () => MemoriesController,
48
49
  MessagesController: () => MessagesController,
49
50
  ModelsController: () => ModelsController,
51
+ QueueController: () => QueueController,
50
52
  SKILL_METADATA: () => SKILL_METADATA,
51
53
  SYSTEM_PROMPT_CONTRIBUTOR_METADATA: () => SYSTEM_PROMPT_CONTRIBUTOR_METADATA,
52
54
  SYSTEM_PROMPT_METADATA: () => SYSTEM_PROMPT_METADATA,
@@ -74,8 +76,8 @@ __export(index_exports, {
74
76
  module.exports = __toCommonJS(index_exports);
75
77
 
76
78
  // src/agent.module.ts
77
- var import_nestjs_agent_core24 = require("@dudousxd/nestjs-agent-core");
78
- var import_common20 = require("@nestjs/common");
79
+ var import_nestjs_agent_core26 = require("@dudousxd/nestjs-agent-core");
80
+ var import_common22 = require("@nestjs/common");
79
81
  var import_core4 = require("@nestjs/core");
80
82
 
81
83
  // src/agent-deps.factory.ts
@@ -337,8 +339,8 @@ AgentDepsFactory2 = _ts_decorate([
337
339
  ], AgentDepsFactory2);
338
340
 
339
341
  // src/agent.service.ts
340
- var import_nestjs_agent_core3 = require("@dudousxd/nestjs-agent-core");
341
- var import_common2 = require("@nestjs/common");
342
+ var import_nestjs_agent_core4 = require("@dudousxd/nestjs-agent-core");
343
+ var import_common3 = require("@nestjs/common");
342
344
 
343
345
  // src/agent-deps.ts
344
346
  function utcDay(date = /* @__PURE__ */ new Date()) {
@@ -356,7 +358,9 @@ function childSinkWriter(writer) {
356
358
  }
357
359
  __name(childSinkWriter, "childSinkWriter");
358
360
 
359
- // src/agent.service.ts
361
+ // src/queue/chat-queue.service.ts
362
+ var import_nestjs_agent_core3 = require("@dudousxd/nestjs-agent-core");
363
+ var import_common2 = require("@nestjs/common");
360
364
  function _ts_decorate2(decorators, target, key, desc) {
361
365
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
362
366
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -383,6 +387,431 @@ function _ts_param2(paramIndex, decorator) {
383
387
  };
384
388
  }
385
389
  __name(_ts_param2, "_ts_param");
390
+ var MAX_DRAIN_ATTEMPTS = 8;
391
+ var ChatQueueService = class _ChatQueueService {
392
+ static {
393
+ __name(this, "ChatQueueService");
394
+ }
395
+ store;
396
+ sink;
397
+ quotaProvider;
398
+ options;
399
+ staging;
400
+ logger = new import_common2.Logger(_ChatQueueService.name);
401
+ /**
402
+ * Runs this process claimed a thread for and has not handed to a runner yet. A holder in here is
403
+ * alive whatever the runner says — it simply has not registered the run yet.
404
+ */
405
+ starting = /* @__PURE__ */ new Set();
406
+ constructor(store, sink, quotaProvider, options, staging) {
407
+ this.store = store;
408
+ this.sink = sink;
409
+ this.quotaProvider = quotaProvider;
410
+ this.options = options;
411
+ this.staging = staging;
412
+ }
413
+ /** Whether the bound store can hold a queue. Without one, a busy thread is not queued. */
414
+ get supported() {
415
+ return (0, import_nestjs_agent_core3.isChatQueueStore)(this.store);
416
+ }
417
+ /** The bound store as a queue store, or a 501 naming what is missing. */
418
+ queueStore() {
419
+ if (!(0, import_nestjs_agent_core3.isChatQueueStore)(this.store)) {
420
+ throw new import_common2.NotImplementedException("Queueing messages requires an AgentStore that implements ChatQueueStore (enqueueMessage, listQueue, \u2026, claimActiveStream, releaseActiveStream); the bound store does not.");
421
+ }
422
+ return this.store;
423
+ }
424
+ async state(threadId) {
425
+ const store = this.queueStore();
426
+ const [items, paused] = await Promise.all([
427
+ store.listQueue(threadId),
428
+ store.queuePause(threadId)
429
+ ]);
430
+ return {
431
+ items: items.map(import_nestjs_agent_core3.queuedMessageView),
432
+ paused
433
+ };
434
+ }
435
+ /**
436
+ * Whether `holder` is still running. A run this process is about to start is; otherwise the
437
+ * runner decides, and a runner that cannot tell says yes.
438
+ */
439
+ async isAlive(holder, runner) {
440
+ if (this.starting.has(holder)) {
441
+ return true;
442
+ }
443
+ if (typeof runner.isRunActive !== "function") {
444
+ return true;
445
+ }
446
+ try {
447
+ return await runner.isRunActive(holder);
448
+ } catch {
449
+ return true;
450
+ }
451
+ }
452
+ /**
453
+ * The run holding `threadId`, or `null` when it is free — a holder the runner reports dead counts
454
+ * as free, and is returned as `stale` so the caller can claim over it.
455
+ */
456
+ async holder(threadId, runner) {
457
+ const holder = await this.queueStore().activeRunForThread(threadId);
458
+ if (holder === null) {
459
+ return {
460
+ live: null,
461
+ stale: null
462
+ };
463
+ }
464
+ return await this.isAlive(holder, runner) ? {
465
+ live: holder,
466
+ stale: null
467
+ } : {
468
+ live: null,
469
+ stale: holder
470
+ };
471
+ }
472
+ /**
473
+ * Decide what follows a TOP-LEVEL run that is settling on `threadId`, and move the thread there:
474
+ * hand it to the next queued message (claimed and popped here, started by the caller), or pause
475
+ * the queue, or release the thread. Call it BEFORE the run's terminal frame, so a client reading
476
+ * the stream learns what comes next from the `queue` frame, and so the thread is already free
477
+ * when the client sees the run end.
478
+ *
479
+ * A no-op returning `{}` on a store without a queue.
480
+ */
481
+ async plan(args) {
482
+ if (!(0, import_nestjs_agent_core3.isChatQueueStore)(this.store)) {
483
+ return {};
484
+ }
485
+ const store = this.store;
486
+ const { threadId, outcome } = args;
487
+ if (await store.activeRunForThread(threadId) !== args.runId) {
488
+ return {};
489
+ }
490
+ let holding = args.runId;
491
+ for (let attempt = 0; attempt < MAX_DRAIN_ATTEMPTS; attempt += 1) {
492
+ const items = await store.listQueue(threadId);
493
+ const head = items[0];
494
+ if (head === void 0) {
495
+ if (holding !== null) {
496
+ await store.releaseActiveStream(threadId, holding);
497
+ holding = null;
498
+ continue;
499
+ }
500
+ return {};
501
+ }
502
+ let pause = await store.queuePause(threadId);
503
+ if (pause === null) {
504
+ const reason = pauseReasonFor(outcome, head);
505
+ if (reason !== null) {
506
+ pause = {
507
+ reason,
508
+ ...outcome === "failed" && args.error !== void 0 ? {
509
+ message: args.error
510
+ } : {},
511
+ at: (/* @__PURE__ */ new Date()).toISOString()
512
+ };
513
+ await store.setQueuePause(threadId, pause);
514
+ }
515
+ }
516
+ if (pause === null) {
517
+ const blocked = await this.quotaBlock(head.actor);
518
+ if (blocked !== null) {
519
+ pause = {
520
+ reason: "quota_exceeded",
521
+ message: blocked,
522
+ at: (/* @__PURE__ */ new Date()).toISOString()
523
+ };
524
+ await store.setQueuePause(threadId, pause);
525
+ }
526
+ }
527
+ if (pause !== null) {
528
+ if (holding !== null) {
529
+ await store.releaseActiveStream(threadId, holding);
530
+ }
531
+ return {
532
+ frame: queueFrame(items, pause)
533
+ };
534
+ }
535
+ const claimed = await store.claimActiveStream(threadId, head.id, holding !== null ? {
536
+ replacing: holding
537
+ } : {});
538
+ if (!claimed) {
539
+ return {};
540
+ }
541
+ holding = head.id;
542
+ if (!await store.removeQueuedMessage(head.id)) {
543
+ await store.releaseActiveStream(threadId, head.id);
544
+ holding = null;
545
+ continue;
546
+ }
547
+ const next = {
548
+ runId: head.id,
549
+ messageId: head.id,
550
+ input: await this.inputFor(head)
551
+ };
552
+ return {
553
+ next,
554
+ frame: queueFrame(items.slice(1), null, {
555
+ messageId: head.id,
556
+ runId: head.id
557
+ })
558
+ };
559
+ }
560
+ if (holding !== null) {
561
+ await store.releaseActiveStream(threadId, holding);
562
+ }
563
+ return {};
564
+ }
565
+ /**
566
+ * {@link plan}, then start what it picked with `start`. What an in-process settle (the inline
567
+ * runner, a durable cancel issued outside a workflow) calls; answers the frame to write.
568
+ */
569
+ async handoff(args, start) {
570
+ const plan = await this.plan(args);
571
+ if (plan.next === void 0) {
572
+ return plan.frame;
573
+ }
574
+ return await this.launch(args.threadId, plan.next, start) ? plan.frame : this.pausedFrame(args.threadId);
575
+ }
576
+ /**
577
+ * Start the head of an IDLE thread's queue — after a send queued behind a run that turned out to
578
+ * be gone, after a resume, after a stale holder. Does nothing while a live run holds the thread
579
+ * (its settle drains) or while the queue is paused. Answers the started run's id, if any.
580
+ */
581
+ async kick(threadId, runner) {
582
+ if (!(0, import_nestjs_agent_core3.isChatQueueStore)(this.store)) {
583
+ return void 0;
584
+ }
585
+ const { live, stale } = await this.holder(threadId, runner);
586
+ if (live !== null) {
587
+ return void 0;
588
+ }
589
+ if (stale !== null) {
590
+ this.logger.warn(`thread ${threadId} was held by run ${stale}, which is no longer running`);
591
+ }
592
+ const plan = await this.plan({
593
+ threadId,
594
+ runId: stale,
595
+ outcome: "completed"
596
+ });
597
+ if (plan.next === void 0) {
598
+ return void 0;
599
+ }
600
+ const started = await this.launch(threadId, plan.next, (input, runId) => runner.start(input, {
601
+ runId
602
+ }));
603
+ if (started && plan.frame !== void 0) {
604
+ await this.write(plan.next.runId, plan.frame);
605
+ }
606
+ return started ? plan.next.runId : void 0;
607
+ }
608
+ /**
609
+ * Start a turn the thread is already claimed for. On failure the message goes back to the head of
610
+ * the queue, the queue pauses (`start_failed`), and the claim is released — nothing is lost and
611
+ * nothing is left holding the thread.
612
+ */
613
+ async launch(threadId, next, start) {
614
+ this.starting.add(next.runId);
615
+ try {
616
+ await start(next.input, next.runId);
617
+ return true;
618
+ } catch (error) {
619
+ const message = error instanceof Error ? error.message : String(error);
620
+ this.logger.error(`queued message ${next.messageId} could not start: ${message}`);
621
+ await this.restore(threadId, next, "start_failed", message);
622
+ return false;
623
+ } finally {
624
+ this.starting.delete(next.runId);
625
+ }
626
+ }
627
+ /** Put a turn that never started back at the head of its queue, paused, and free the thread. */
628
+ async restore(threadId, next, reason, message) {
629
+ const store = this.queueStore();
630
+ const { input } = next;
631
+ await store.enqueueMessage({
632
+ threadId,
633
+ actor: input.actor,
634
+ content: input.userText,
635
+ at: "head",
636
+ ...input.attachments !== void 0 ? {
637
+ attachments: input.attachments
638
+ } : {},
639
+ ...input.agentName !== void 0 ? {
640
+ agentName: input.agentName
641
+ } : {},
642
+ ...input.model !== void 0 ? {
643
+ model: input.model
644
+ } : {},
645
+ ...input.pageContext !== void 0 ? {
646
+ pageContext: input.pageContext
647
+ } : {}
648
+ });
649
+ await store.setQueuePause(threadId, {
650
+ reason,
651
+ message,
652
+ at: (/* @__PURE__ */ new Date()).toISOString()
653
+ });
654
+ await store.releaseActiveStream(threadId, next.runId);
655
+ }
656
+ /** A `queue` frame with the thread's current state. */
657
+ async pausedFrame(threadId) {
658
+ return {
659
+ kind: "queue",
660
+ queue: await this.state(threadId)
661
+ };
662
+ }
663
+ /**
664
+ * Tell whoever is watching the thread that its queue changed: a `queue` frame into the stream of
665
+ * the run holding it. Best-effort — a thread nobody is streaming has no one to tell, and the next
666
+ * read of the thread carries the queue anyway.
667
+ */
668
+ async publish(threadId) {
669
+ const state = await this.state(threadId);
670
+ const holder = await this.queueStore().activeRunForThread(threadId);
671
+ if (holder !== null) {
672
+ await this.write(holder, {
673
+ kind: "queue",
674
+ queue: state
675
+ }).catch((error) => {
676
+ this.logger.warn(`could not publish the queue of thread ${threadId}: ${error instanceof Error ? error.message : String(error)}`);
677
+ });
678
+ }
679
+ return state;
680
+ }
681
+ async write(runId, frame) {
682
+ const writer = await this.sink.open(runId);
683
+ await writer.write((0, import_nestjs_agent_core3.encodeStreamEvent)(frame));
684
+ }
685
+ /** Why `actor` may not start a turn now (the quota message), or `null`. */
686
+ async quotaBlock(actor) {
687
+ if (this.options?.quota === void 0 || this.quotaProvider === void 0) {
688
+ return null;
689
+ }
690
+ try {
691
+ const { blocked } = await this.quotaProvider.report({
692
+ actor
693
+ });
694
+ if (blocked === void 0) {
695
+ return null;
696
+ }
697
+ return blocked.reason ?? `The ${blocked.period === "day" ? "daily" : "monthly"} quota is used up`;
698
+ } catch {
699
+ return null;
700
+ }
701
+ }
702
+ /**
703
+ * The turn a queued message starts: everything it was queued with, today's date, and its
704
+ * attachments' urls minted afresh — the ones stored at enqueue time may have expired while it
705
+ * waited. An attachment the staging store no longer resolves keeps its stored url.
706
+ */
707
+ async inputFor(message) {
708
+ const attachments = await this.freshAttachments(message.actor, message.attachments ?? []);
709
+ return {
710
+ threadId: message.threadId,
711
+ actor: message.actor,
712
+ userText: message.content,
713
+ day: utcDay(),
714
+ ...message.agentName !== void 0 ? {
715
+ agentName: message.agentName
716
+ } : {},
717
+ ...attachments.length > 0 ? {
718
+ attachments
719
+ } : {},
720
+ ...message.pageContext !== void 0 ? {
721
+ pageContext: message.pageContext
722
+ } : {},
723
+ ...message.model !== void 0 ? {
724
+ model: message.model
725
+ } : {}
726
+ };
727
+ }
728
+ async freshAttachments(actor, attachments) {
729
+ const staging = this.staging;
730
+ if (attachments.length === 0 || staging === void 0 || typeof staging.resolve !== "function") {
731
+ return attachments;
732
+ }
733
+ return Promise.all(attachments.map(async (attachment) => {
734
+ try {
735
+ return await staging.resolve({
736
+ mediaId: attachment.mediaId,
737
+ actor
738
+ }) ?? attachment;
739
+ } catch {
740
+ return attachment;
741
+ }
742
+ }));
743
+ }
744
+ };
745
+ ChatQueueService = _ts_decorate2([
746
+ (0, import_common2.Injectable)(),
747
+ _ts_param2(0, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_STORE)),
748
+ _ts_param2(1, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_SINK)),
749
+ _ts_param2(2, (0, import_common2.Optional)()),
750
+ _ts_param2(2, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_QUOTA_PROVIDER)),
751
+ _ts_param2(3, (0, import_common2.Optional)()),
752
+ _ts_param2(3, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_OPTIONS)),
753
+ _ts_param2(4, (0, import_common2.Optional)()),
754
+ _ts_param2(4, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_ATTACHMENT_STAGING)),
755
+ _ts_metadata2("design:type", Function),
756
+ _ts_metadata2("design:paramtypes", [
757
+ typeof AgentStore === "undefined" ? Object : AgentStore,
758
+ typeof TokenStreamSink === "undefined" ? Object : TokenStreamSink,
759
+ typeof QuotaProvider === "undefined" ? Object : QuotaProvider,
760
+ typeof Pick === "undefined" ? Object : Pick,
761
+ typeof AttachmentStagingStore === "undefined" ? Object : AttachmentStagingStore
762
+ ])
763
+ ], ChatQueueService);
764
+ function pauseReasonFor(outcome, head) {
765
+ if (outcome === "failed") {
766
+ return "run_failed";
767
+ }
768
+ if (outcome === "cancelled" && head.interrupt !== true) {
769
+ return "cancelled";
770
+ }
771
+ return null;
772
+ }
773
+ __name(pauseReasonFor, "pauseReasonFor");
774
+ function queueFrame(items, paused, started) {
775
+ return {
776
+ kind: "queue",
777
+ queue: {
778
+ items: items.map(import_nestjs_agent_core3.queuedMessageView),
779
+ paused
780
+ },
781
+ ...started !== void 0 ? {
782
+ started
783
+ } : {}
784
+ };
785
+ }
786
+ __name(queueFrame, "queueFrame");
787
+
788
+ // src/agent.service.ts
789
+ function _ts_decorate3(decorators, target, key, desc) {
790
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
791
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
792
+ r = Reflect.decorate(decorators, target, key, desc);
793
+ } else {
794
+ for (var i = decorators.length - 1; i >= 0; i--) {
795
+ if (d = decorators[i]) {
796
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
797
+ }
798
+ }
799
+ }
800
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
801
+ }
802
+ __name(_ts_decorate3, "_ts_decorate");
803
+ function _ts_metadata3(metadataKey, metadataValue) {
804
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
805
+ return Reflect.metadata(metadataKey, metadataValue);
806
+ }
807
+ }
808
+ __name(_ts_metadata3, "_ts_metadata");
809
+ function _ts_param3(paramIndex, decorator) {
810
+ return function(target, key) {
811
+ decorator(target, key, paramIndex);
812
+ };
813
+ }
814
+ __name(_ts_param3, "_ts_param");
386
815
  var AgentService = class {
387
816
  static {
388
817
  __name(this, "AgentService");
@@ -394,7 +823,8 @@ var AgentService = class {
394
823
  models;
395
824
  quotaProvider;
396
825
  options;
397
- constructor(runner, store, deps, staging, models, quotaProvider, options) {
826
+ queue;
827
+ constructor(runner, store, deps, staging, models, quotaProvider, options, queue) {
398
828
  this.runner = runner;
399
829
  this.store = store;
400
830
  this.deps = deps;
@@ -402,6 +832,19 @@ var AgentService = class {
402
832
  this.models = models;
403
833
  this.quotaProvider = quotaProvider;
404
834
  this.options = options;
835
+ this.queue = queue;
836
+ }
837
+ /** The queue service when the bound store can hold a queue, else `undefined`. */
838
+ queueing() {
839
+ return this.queue?.supported === true ? this.queue : void 0;
840
+ }
841
+ /** The queue service, or a 501 naming what is missing. */
842
+ requireQueue() {
843
+ const queue = this.queueing();
844
+ if (queue === void 0) {
845
+ throw new import_common3.NotImplementedException("Queueing messages requires an AgentStore that implements ChatQueueStore; the bound store does not.");
846
+ }
847
+ return queue;
405
848
  }
406
849
  /**
407
850
  * The actor's budget across windows (`GET <base>/quota`) — the bound {@link QuotaProvider}'s
@@ -436,12 +879,12 @@ var AgentService = class {
436
879
  actor
437
880
  });
438
881
  if (blocked !== void 0) {
439
- throw new import_common2.HttpException({
440
- statusCode: import_common2.HttpStatus.TOO_MANY_REQUESTS,
882
+ throw new import_common3.HttpException({
883
+ statusCode: import_common3.HttpStatus.TOO_MANY_REQUESTS,
441
884
  code: "quota_exceeded",
442
885
  period: blocked.period,
443
886
  message: blocked.reason ?? `The ${blocked.period === "day" ? "daily" : "monthly"} quota is used up`
444
- }, import_common2.HttpStatus.TOO_MANY_REQUESTS);
887
+ }, import_common3.HttpStatus.TOO_MANY_REQUESTS);
445
888
  }
446
889
  }
447
890
  /**
@@ -469,17 +912,17 @@ var AgentService = class {
469
912
  */
470
913
  async assertModelAllowed(actor, agent, model) {
471
914
  if (this.models === void 0) {
472
- throw new import_common2.BadRequestException(`model "${model}" cannot be selected: no ModelCatalog is configured (AgentModule.forRoot({ models }))`);
915
+ throw new import_common3.BadRequestException(`model "${model}" cannot be selected: no ModelCatalog is configured (AgentModule.forRoot({ models }))`);
473
916
  }
474
- const entry = (0, import_nestjs_agent_core3.findCatalogModel)(await this.models.list({
917
+ const entry = (0, import_nestjs_agent_core4.findCatalogModel)(await this.models.list({
475
918
  actor,
476
919
  agent
477
920
  }), model);
478
921
  if (entry === void 0) {
479
- throw new import_common2.BadRequestException(`model "${model}" is not offered`);
922
+ throw new import_common3.BadRequestException(`model "${model}" is not offered`);
480
923
  }
481
924
  if (!entry.available) {
482
- throw new import_common2.BadRequestException(`model "${model}" is not available${entry.unavailableReason ? `: ${entry.unavailableReason}` : ""}`);
925
+ throw new import_common3.BadRequestException(`model "${model}" is not available${entry.unavailableReason ? `: ${entry.unavailableReason}` : ""}`);
483
926
  }
484
927
  return entry.id;
485
928
  }
@@ -495,7 +938,7 @@ var AgentService = class {
495
938
  })).locked : void 0;
496
939
  if (locked !== void 0) {
497
940
  if (requested !== void 0 && requested !== locked.model) {
498
- throw new import_common2.BadRequestException(`model "${requested}" cannot be selected: ${locked.reason ?? `this agent always uses "${locked.model}"`}`);
941
+ throw new import_common3.BadRequestException(`model "${requested}" cannot be selected: ${locked.reason ?? `this agent always uses "${locked.model}"`}`);
499
942
  }
500
943
  return locked.model;
501
944
  }
@@ -512,7 +955,44 @@ var AgentService = class {
512
955
  }
513
956
  return (await this.store.getThread(threadId))?.model ?? null;
514
957
  }
958
+ /**
959
+ * Start a turn — for in-process callers that need a run id back. A send that would have to wait
960
+ * (its thread already has a turn running) is refused with `409` instead; {@link send} is the form
961
+ * that queues it.
962
+ */
515
963
  async chat(params) {
964
+ const result = await this.send({
965
+ ...params,
966
+ mode: "auto"
967
+ });
968
+ if (result.queued !== true) {
969
+ return result;
970
+ }
971
+ if (result.runId !== void 0) {
972
+ return {
973
+ runId: result.runId,
974
+ threadId: result.threadId
975
+ };
976
+ }
977
+ const store = this.requireQueue().queueStore();
978
+ if (!await store.removeQueuedMessage(result.messageId)) {
979
+ return {
980
+ runId: result.messageId,
981
+ threadId: result.threadId
982
+ };
983
+ }
984
+ await this.requireQueue().publish(result.threadId);
985
+ throw new import_common3.ConflictException({
986
+ statusCode: 409,
987
+ code: "run_active",
988
+ message: `thread ${result.threadId} already has a turn running`
989
+ });
990
+ }
991
+ /**
992
+ * Send a message: start a turn, or — when its thread already has one running — queue the message
993
+ * to run after it (see {@link ChatSendMode}). What `POST <base>/chat` calls.
994
+ */
995
+ async send(params) {
516
996
  await this.assertWithinQuota(params.actor);
517
997
  const agentName = await this.resolveAgentName(params.agentName, params.threadId);
518
998
  const model = await this.resolveModel(params.actor, agentName, params.model, params.threadId);
@@ -520,7 +1000,7 @@ var AgentService = class {
520
1000
  let threadId = params.threadId;
521
1001
  if (threadId === void 0) {
522
1002
  if (params.regenerate === true) {
523
- throw new import_common2.BadRequestException("regenerate requires an existing threadId");
1003
+ throw new import_common3.BadRequestException("regenerate requires an existing threadId");
524
1004
  }
525
1005
  const created = await this.store.createThread({
526
1006
  actor: params.actor,
@@ -529,7 +1009,7 @@ var AgentService = class {
529
1009
  } : {}
530
1010
  });
531
1011
  threadId = created.id;
532
- } else if (params.regenerate === true) {
1012
+ } else {
533
1013
  await this.assertOwnsThread(params.actor, threadId);
534
1014
  }
535
1015
  const input = {
@@ -551,62 +1031,244 @@ var AgentService = class {
551
1031
  model
552
1032
  } : {}
553
1033
  };
554
- const { runId } = await this.runner.start(input);
555
- await this.store.setActiveStream(threadId, runId);
556
- return {
557
- runId,
558
- threadId
559
- };
560
- }
561
- /**
562
- * Rebuild this turn's attachments from the staging store, keyed by the ids the caller claimed.
563
- * The model provider fetches {@link MessageAttachment.url} verbatim, so that url is only ever
564
- * allowed to come from the host's own store — a caller that could name it could point the server
565
- * at anything it can reach (cloud metadata, internal services) and read the response back out of
566
- * the model's answer.
567
- *
568
- * No store bound means no way to tell an id the actor owns from one they don't, so a turn simply
569
- * cannot carry attachments: 501 rather than trusting the request.
570
- */
571
- async resolveAttachments(actor, refs) {
572
- if (refs.length === 0) {
573
- return [];
1034
+ const queue = this.queueing();
1035
+ if (queue === void 0) {
1036
+ const { runId } = await this.runner.start(input);
1037
+ await this.store.setActiveStream(threadId, runId);
1038
+ return {
1039
+ runId,
1040
+ threadId
1041
+ };
574
1042
  }
575
- const staging = this.staging;
576
- if (staging === void 0 || typeof staging.resolve !== "function") {
577
- throw new import_common2.NotImplementedException("Message attachments require an AGENT_ATTACHMENT_STAGING provider implementing resolve(); attachment urls are never taken from the request.");
1043
+ const mode = params.mode ?? "auto";
1044
+ const { live, stale } = await queue.holder(threadId, this.runner);
1045
+ if (live === null && mode !== "queue") {
1046
+ const runId = crypto.randomUUID();
1047
+ if (await queue.queueStore().claimActiveStream(threadId, runId, stale !== null ? {
1048
+ replacing: stale
1049
+ } : {})) {
1050
+ return {
1051
+ runId: await this.startClaimed(input, runId),
1052
+ threadId
1053
+ };
1054
+ }
578
1055
  }
579
- const resolved = [];
580
- for (const ref of refs) {
581
- const attachment = await staging.resolve({
582
- mediaId: ref.mediaId,
583
- actor
1056
+ if (params.regenerate === true) {
1057
+ throw new import_common3.ConflictException({
1058
+ statusCode: 409,
1059
+ code: "run_active",
1060
+ message: "cannot regenerate while a turn is running on this thread"
584
1061
  });
585
- if (attachment === null) {
586
- throw new import_common2.ForbiddenException(`attachment ${ref.mediaId} is not available to this actor`);
587
- }
588
- resolved.push(attachment);
589
1062
  }
590
- return resolved;
1063
+ return this.enqueue(queue, input, mode, live);
591
1064
  }
592
1065
  /**
593
- * The run's live token stream, WITHOUT an ownership check — for in-process callers that are
594
- * already authorized (the MCP bridge, a host's own job code), the same split as
595
- * {@link signalToolCall} vs {@link approve}. Anything reachable from a request must go through
596
- * {@link subscribeAs} instead: a runId is the only thing standing between a caller and another
597
- * actor's answer, tool arguments and tool results.
598
- */
599
- subscribe(runId) {
600
- return this.deps.forAgent().sink.subscribe(runId);
601
- }
602
- /**
603
- * {@link subscribe}, gated the way {@link cancel} is: only the actor whose thread is currently
604
- * streaming this run may read it. A run that has already finished is reported missing rather than
605
- * replayed — the runner clears the thread's active stream as the run ends, and that field is what
606
- * ownership is derived from.
1066
+ * Start a turn the thread is already claimed for, under the claimed id. A runner that minted an
1067
+ * id of its own anyway gets the thread re-pointed at it; one that fails to start frees the thread.
607
1068
  */
608
- async subscribeAs(actor, runId) {
609
- await this.assertOwnsActiveStream(actor, runId);
1069
+ async startClaimed(input, runId) {
1070
+ const store = this.requireQueue().queueStore();
1071
+ let started;
1072
+ try {
1073
+ started = (await this.runner.start(input, {
1074
+ runId
1075
+ })).runId;
1076
+ } catch (error) {
1077
+ await store.releaseActiveStream(input.threadId, runId);
1078
+ throw error;
1079
+ }
1080
+ if (started !== runId) {
1081
+ await store.claimActiveStream(input.threadId, started, {
1082
+ replacing: runId
1083
+ });
1084
+ }
1085
+ return started;
1086
+ }
1087
+ /** Put a send in its thread's queue, then drain it if the thread turned out to be free. */
1088
+ async enqueue(queue, input, mode, live) {
1089
+ const store = queue.queueStore();
1090
+ const threadId = input.threadId;
1091
+ const interrupting = mode === "interrupt" && live !== null ? live : void 0;
1092
+ const queued = await store.enqueueMessage({
1093
+ threadId,
1094
+ actor: input.actor,
1095
+ content: input.userText,
1096
+ ...input.attachments !== void 0 ? {
1097
+ attachments: input.attachments
1098
+ } : {},
1099
+ ...input.agentName !== void 0 ? {
1100
+ agentName: input.agentName
1101
+ } : {},
1102
+ ...input.model !== void 0 ? {
1103
+ model: input.model
1104
+ } : {},
1105
+ ...input.pageContext !== void 0 ? {
1106
+ pageContext: input.pageContext
1107
+ } : {},
1108
+ ...interrupting !== void 0 ? {
1109
+ interrupt: true,
1110
+ at: "head"
1111
+ } : {}
1112
+ });
1113
+ let runId;
1114
+ if (interrupting !== void 0) {
1115
+ await store.setQueuePause(threadId, null);
1116
+ await queue.publish(threadId);
1117
+ await this.runner.cancel(interrupting);
1118
+ } else {
1119
+ runId = await queue.kick(threadId, this.runner);
1120
+ if (runId === void 0) {
1121
+ await queue.publish(threadId);
1122
+ }
1123
+ }
1124
+ const state = await queue.state(threadId);
1125
+ const position = state.items.findIndex((item) => item.id === queued.id);
1126
+ return {
1127
+ threadId,
1128
+ queued: true,
1129
+ messageId: queued.id,
1130
+ position: position === -1 ? 0 : position,
1131
+ queue: state,
1132
+ ...runId !== void 0 && runId === queued.id ? {
1133
+ runId
1134
+ } : {},
1135
+ ...interrupting !== void 0 ? {
1136
+ interrupting
1137
+ } : {}
1138
+ };
1139
+ }
1140
+ /** `GET <base>/threads/:id/queue` — the thread's waiting messages and whether it drains. */
1141
+ async getQueue(actor, threadId) {
1142
+ await this.assertOwnsThread(actor, threadId);
1143
+ return this.requireQueue().state(threadId);
1144
+ }
1145
+ /**
1146
+ * `PATCH <base>/queue/:messageId` — change a waiting message's text and/or attachments, and/or move
1147
+ * it to `position` in the queue. Answers the thread's queue.
1148
+ */
1149
+ async updateQueuedMessage(actor, messageId, patch) {
1150
+ const queue = this.requireQueue();
1151
+ const store = queue.queueStore();
1152
+ const threadId = await this.assertOwnsQueuedMessage(actor, messageId);
1153
+ if (patch.message !== void 0 && patch.message.trim().length === 0) {
1154
+ throw new import_common3.BadRequestException("message must not be empty");
1155
+ }
1156
+ const attachments = patch.attachments === void 0 || patch.attachments === null ? patch.attachments : await this.resolveAttachments(actor, patch.attachments);
1157
+ if (patch.message !== void 0 || attachments !== void 0) {
1158
+ const updated = await store.updateQueuedMessage(messageId, {
1159
+ ...patch.message !== void 0 ? {
1160
+ content: patch.message
1161
+ } : {},
1162
+ ...attachments !== void 0 ? {
1163
+ attachments
1164
+ } : {}
1165
+ });
1166
+ if (updated === null) {
1167
+ throw new import_common3.GoneException(`queued message ${messageId} already started or was removed`);
1168
+ }
1169
+ }
1170
+ if (patch.position !== void 0) {
1171
+ if (!Number.isInteger(patch.position) || patch.position < 0) {
1172
+ throw new import_common3.BadRequestException("position must be a non-negative integer");
1173
+ }
1174
+ if (!await store.moveQueuedMessage(messageId, patch.position)) {
1175
+ throw new import_common3.GoneException(`queued message ${messageId} already started or was removed`);
1176
+ }
1177
+ }
1178
+ return queue.publish(threadId);
1179
+ }
1180
+ /** `DELETE <base>/queue/:messageId` — drop a waiting message. Answers the thread's queue. */
1181
+ async removeQueuedMessage(actor, messageId) {
1182
+ const queue = this.requireQueue();
1183
+ const threadId = await this.assertOwnsQueuedMessage(actor, messageId);
1184
+ if (!await queue.queueStore().removeQueuedMessage(messageId)) {
1185
+ throw new import_common3.GoneException(`queued message ${messageId} already started or was removed`);
1186
+ }
1187
+ return queue.publish(threadId);
1188
+ }
1189
+ /** `DELETE <base>/threads/:id/queue` — drop every waiting message (and any pause). */
1190
+ async clearQueue(actor, threadId) {
1191
+ await this.assertOwnsThread(actor, threadId);
1192
+ const queue = this.requireQueue();
1193
+ await queue.queueStore().clearQueue(threadId);
1194
+ await queue.queueStore().setQueuePause(threadId, null);
1195
+ return queue.publish(threadId);
1196
+ }
1197
+ /**
1198
+ * `POST <base>/threads/:id/queue/resume` — lift a pause and start the head when nothing is
1199
+ * running. Answers the queue, and the run the head started under, if it did.
1200
+ */
1201
+ async resumeQueue(actor, threadId) {
1202
+ await this.assertOwnsThread(actor, threadId);
1203
+ const queue = this.requireQueue();
1204
+ await queue.queueStore().setQueuePause(threadId, null);
1205
+ const runId = await queue.kick(threadId, this.runner);
1206
+ const state = runId === void 0 ? await queue.publish(threadId) : await queue.state(threadId);
1207
+ return {
1208
+ ...state,
1209
+ ...runId !== void 0 ? {
1210
+ runId
1211
+ } : {}
1212
+ };
1213
+ }
1214
+ /** The thread a queued message waits on, once the caller is shown to own it. */
1215
+ async assertOwnsQueuedMessage(actor, messageId) {
1216
+ const message = await this.requireQueue().queueStore().getQueuedMessage(messageId);
1217
+ if (message === null) {
1218
+ throw new import_common3.NotFoundException(`queued message ${messageId} not found`);
1219
+ }
1220
+ await this.assertOwnsThread(actor, message.threadId);
1221
+ return message.threadId;
1222
+ }
1223
+ /**
1224
+ * Rebuild this turn's attachments from the staging store, keyed by the ids the caller claimed.
1225
+ * The model provider fetches {@link MessageAttachment.url} verbatim, so that url is only ever
1226
+ * allowed to come from the host's own store — a caller that could name it could point the server
1227
+ * at anything it can reach (cloud metadata, internal services) and read the response back out of
1228
+ * the model's answer.
1229
+ *
1230
+ * No store bound means no way to tell an id the actor owns from one they don't, so a turn simply
1231
+ * cannot carry attachments: 501 rather than trusting the request.
1232
+ */
1233
+ async resolveAttachments(actor, refs) {
1234
+ if (refs.length === 0) {
1235
+ return [];
1236
+ }
1237
+ const staging = this.staging;
1238
+ if (staging === void 0 || typeof staging.resolve !== "function") {
1239
+ throw new import_common3.NotImplementedException("Message attachments require an AGENT_ATTACHMENT_STAGING provider implementing resolve(); attachment urls are never taken from the request.");
1240
+ }
1241
+ const resolved = [];
1242
+ for (const ref of refs) {
1243
+ const attachment = await staging.resolve({
1244
+ mediaId: ref.mediaId,
1245
+ actor
1246
+ });
1247
+ if (attachment === null) {
1248
+ throw new import_common3.ForbiddenException(`attachment ${ref.mediaId} is not available to this actor`);
1249
+ }
1250
+ resolved.push(attachment);
1251
+ }
1252
+ return resolved;
1253
+ }
1254
+ /**
1255
+ * The run's live token stream, WITHOUT an ownership check — for in-process callers that are
1256
+ * already authorized (the MCP bridge, a host's own job code), the same split as
1257
+ * {@link signalToolCall} vs {@link approve}. Anything reachable from a request must go through
1258
+ * {@link subscribeAs} instead: a runId is the only thing standing between a caller and another
1259
+ * actor's answer, tool arguments and tool results.
1260
+ */
1261
+ subscribe(runId) {
1262
+ return this.deps.forAgent().sink.subscribe(runId);
1263
+ }
1264
+ /**
1265
+ * {@link subscribe}, gated the way {@link cancel} is: only the actor whose thread is currently
1266
+ * streaming this run may read it. A run that has already finished is reported missing rather than
1267
+ * replayed — the runner clears the thread's active stream as the run ends, and that field is what
1268
+ * ownership is derived from.
1269
+ */
1270
+ async subscribeAs(actor, runId) {
1271
+ await this.assertOwnsActiveStream(actor, runId);
610
1272
  return this.subscribe(runId);
611
1273
  }
612
1274
  /**
@@ -732,7 +1394,7 @@ var AgentService = class {
732
1394
  return;
733
1395
  }
734
1396
  if (this.store.updateThread === void 0) {
735
- throw new import_common2.NotImplementedException("Setting a thread's defaultAgent or model requires an AgentStore that implements updateThread(); the bound store does not support it.");
1397
+ throw new import_common3.NotImplementedException("Setting a thread's defaultAgent or model requires an AgentStore that implements updateThread(); the bound store does not support it.");
736
1398
  }
737
1399
  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);
738
1400
  await this.store.updateThread(threadId, {
@@ -750,10 +1412,10 @@ var AgentService = class {
750
1412
  validateTitle(title) {
751
1413
  const trimmed = title.trim();
752
1414
  if (trimmed.length === 0) {
753
- throw new import_common2.BadRequestException("title must not be empty");
1415
+ throw new import_common3.BadRequestException("title must not be empty");
754
1416
  }
755
1417
  if (trimmed.length > 200) {
756
- throw new import_common2.BadRequestException("title must be at most 200 characters");
1418
+ throw new import_common3.BadRequestException("title must be at most 200 characters");
757
1419
  }
758
1420
  return trimmed;
759
1421
  }
@@ -797,9 +1459,13 @@ var AgentService = class {
797
1459
  }
798
1460
  async toDetailView(thread, actor) {
799
1461
  const summary = await this.toSummaryView(thread);
1462
+ const queue = this.queueing();
800
1463
  return {
801
1464
  ...summary,
802
- messages: await this.freshAttachmentUrls(thread.messages, actor)
1465
+ messages: await this.freshAttachmentUrls(thread.messages, actor),
1466
+ ...queue !== void 0 ? {
1467
+ queue: await queue.state(thread.id)
1468
+ } : {}
803
1469
  };
804
1470
  }
805
1471
  /**
@@ -852,21 +1518,21 @@ var AgentService = class {
852
1518
  */
853
1519
  async setMessageFeedback(actor, messageId, input) {
854
1520
  if (input.value !== null && input.value !== "up" && input.value !== "down") {
855
- throw new import_common2.BadRequestException("value must be 'up', 'down' or null");
1521
+ throw new import_common3.BadRequestException("value must be 'up', 'down' or null");
856
1522
  }
857
1523
  if (input.comment !== void 0 && typeof input.comment !== "string") {
858
- throw new import_common2.BadRequestException("comment must be a string");
1524
+ throw new import_common3.BadRequestException("comment must be a string");
859
1525
  }
860
1526
  const comment = input.comment?.trim();
861
1527
  if (comment !== void 0 && comment.length > 2e3) {
862
- throw new import_common2.BadRequestException("comment must be at most 2000 characters");
1528
+ throw new import_common3.BadRequestException("comment must be at most 2000 characters");
863
1529
  }
864
1530
  if (this.store.threadOfMessage === void 0 || this.store.setMessageFeedback === void 0) {
865
- throw new import_common2.NotImplementedException("Message feedback requires an AgentStore that implements threadOfMessage() and setMessageFeedback(); the bound store does not support it.");
1531
+ throw new import_common3.NotImplementedException("Message feedback requires an AgentStore that implements threadOfMessage() and setMessageFeedback(); the bound store does not support it.");
866
1532
  }
867
1533
  const threadId = await this.store.threadOfMessage(messageId);
868
1534
  if (threadId === null) {
869
- throw new import_common2.NotFoundException(`message ${messageId} not found`);
1535
+ throw new import_common3.NotFoundException(`message ${messageId} not found`);
870
1536
  }
871
1537
  await this.assertOwnsThread(actor, threadId);
872
1538
  const feedback = input.value === null ? null : {
@@ -914,7 +1580,7 @@ var AgentService = class {
914
1580
  const list = this.attachmentInventory();
915
1581
  const referencedMediaIds = this.store.referencedMediaIds?.bind(this.store);
916
1582
  if (referencedMediaIds === void 0) {
917
- throw new import_common2.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.");
1583
+ throw new import_common3.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.");
918
1584
  }
919
1585
  const stagedBefore = options.olderThan.toISOString();
920
1586
  const inventory = await list({
@@ -936,7 +1602,7 @@ var AgentService = class {
936
1602
  attachmentInventory() {
937
1603
  const list = this.staging?.list?.bind(this.staging);
938
1604
  if (list === void 0) {
939
- throw new import_common2.NotImplementedException("Listing attachments requires an AGENT_ATTACHMENT_STAGING provider implementing list(); the host owns the staged bytes, so only it can enumerate them.");
1605
+ throw new import_common3.NotImplementedException("Listing attachments requires an AGENT_ATTACHMENT_STAGING provider implementing list(); the host owns the staged bytes, so only it can enumerate them.");
940
1606
  }
941
1607
  return list;
942
1608
  }
@@ -947,10 +1613,10 @@ var AgentService = class {
947
1613
  async assertOwnsThread(actor, threadId) {
948
1614
  const owner = await this.store.ownerOfThread(threadId);
949
1615
  if (owner === null) {
950
- throw new import_common2.NotFoundException(`thread ${threadId} not found`);
1616
+ throw new import_common3.NotFoundException(`thread ${threadId} not found`);
951
1617
  }
952
1618
  if (owner !== actor.id) {
953
- throw new import_common2.ForbiddenException("thread belongs to another actor");
1619
+ throw new import_common3.ForbiddenException("thread belongs to another actor");
954
1620
  }
955
1621
  }
956
1622
  /**
@@ -961,10 +1627,10 @@ var AgentService = class {
961
1627
  async assertOwnsToolCall(actor, toolCallId2) {
962
1628
  const owner = await this.store.ownerOfToolCall(toolCallId2);
963
1629
  if (owner === null) {
964
- throw new import_common2.NotFoundException(`tool call ${toolCallId2} not found`);
1630
+ throw new import_common3.NotFoundException(`tool call ${toolCallId2} not found`);
965
1631
  }
966
1632
  if (owner !== actor.id) {
967
- throw new import_common2.ForbiddenException("tool call belongs to another actor");
1633
+ throw new import_common3.ForbiddenException("tool call belongs to another actor");
968
1634
  }
969
1635
  }
970
1636
  /**
@@ -979,12 +1645,12 @@ var AgentService = class {
979
1645
  if (this.store.toolCallInput === void 0) {
980
1646
  return;
981
1647
  }
982
- const questions = (0, import_nestjs_agent_core3.readElicitationQuestions)(await this.store.toolCallInput(toolCallId2));
1648
+ const questions = (0, import_nestjs_agent_core4.readElicitationQuestions)(await this.store.toolCallInput(toolCallId2));
983
1649
  for (const question of questions) {
984
1650
  const submitted = Object.hasOwn(answers2, question.id) ? answers2[question.id] : void 0;
985
- const problem = (0, import_nestjs_agent_core3.validateElicitationAnswer)(question, submitted ?? question.defaults ?? []);
1651
+ const problem = (0, import_nestjs_agent_core4.validateElicitationAnswer)(question, submitted ?? question.defaults ?? []);
986
1652
  if (problem !== null) {
987
- throw new import_common2.BadRequestException(`answers["${question.id}"] ${problem}`);
1653
+ throw new import_common3.BadRequestException(`answers["${question.id}"] ${problem}`);
988
1654
  }
989
1655
  }
990
1656
  }
@@ -996,21 +1662,21 @@ var AgentService = class {
996
1662
  */
997
1663
  async assertMayDecide(actor, toolCallId2) {
998
1664
  const approval = await this.store.toolCallApproval?.(toolCallId2);
999
- const approver = approval?.approver ?? import_nestjs_agent_core3.REQUESTER_APPROVER;
1000
- if (approver === import_nestjs_agent_core3.REQUESTER_APPROVER) {
1665
+ const approver = approval?.approver ?? import_nestjs_agent_core4.REQUESTER_APPROVER;
1666
+ if (approver === import_nestjs_agent_core4.REQUESTER_APPROVER) {
1001
1667
  return this.assertOwnsToolCall(actor, toolCallId2);
1002
1668
  }
1003
1669
  const requesterRef = await this.store.ownerOfToolCall(toolCallId2);
1004
1670
  if (requesterRef === null) {
1005
- throw new import_common2.NotFoundException(`tool call ${toolCallId2} not found`);
1671
+ throw new import_common3.NotFoundException(`tool call ${toolCallId2} not found`);
1006
1672
  }
1007
- const allowed = await (0, import_nestjs_agent_core3.mayDecideApproval)(this.deps.forAgent().approvalPolicy, actor, {
1673
+ const allowed = await (0, import_nestjs_agent_core4.mayDecideApproval)(this.deps.forAgent().approvalPolicy, actor, {
1008
1674
  toolCallId: toolCallId2,
1009
1675
  approver,
1010
1676
  requesterRef
1011
1677
  });
1012
1678
  if (!allowed) {
1013
- throw new import_common2.ForbiddenException(`this approval is for ${approver}`);
1679
+ throw new import_common3.ForbiddenException(`this approval is for ${approver}`);
1014
1680
  }
1015
1681
  }
1016
1682
  /**
@@ -1026,7 +1692,7 @@ var AgentService = class {
1026
1692
  }
1027
1693
  const lapsed = approval.status === "expired" || approval.status === "pending_approval" && approval.expiresAt !== null && Date.parse(approval.expiresAt) <= Date.now();
1028
1694
  if (lapsed) {
1029
- throw new import_common2.GoneException(`the approval request for tool call ${toolCallId2} has expired`);
1695
+ throw new import_common3.GoneException(`the approval request for tool call ${toolCallId2} has expired`);
1030
1696
  }
1031
1697
  }
1032
1698
  /**
@@ -1039,7 +1705,7 @@ var AgentService = class {
1039
1705
  async resolveRunForToolCall(toolCallId2) {
1040
1706
  const runId = await this.store.runForToolCall(toolCallId2);
1041
1707
  if (runId === null) {
1042
- throw new import_common2.NotFoundException(`tool call ${toolCallId2} has no active run to signal`);
1708
+ throw new import_common3.NotFoundException(`tool call ${toolCallId2} has no active run to signal`);
1043
1709
  }
1044
1710
  return runId;
1045
1711
  }
@@ -1047,41 +1713,43 @@ var AgentService = class {
1047
1713
  async assertOwnsActiveStream(actor, runId) {
1048
1714
  const owner = await this.store.ownerOfActiveStream(runId);
1049
1715
  if (owner === null) {
1050
- throw new import_common2.NotFoundException(`no active run ${runId}`);
1716
+ throw new import_common3.NotFoundException(`no active run ${runId}`);
1051
1717
  }
1052
1718
  if (owner !== actor.id) {
1053
- throw new import_common2.ForbiddenException("run belongs to another actor");
1719
+ throw new import_common3.ForbiddenException("run belongs to another actor");
1054
1720
  }
1055
1721
  }
1056
1722
  };
1057
- AgentService = _ts_decorate2([
1058
- (0, import_common2.Injectable)(),
1059
- _ts_param2(0, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_RUNNER)),
1060
- _ts_param2(1, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_STORE)),
1061
- _ts_param2(2, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_DEPS_FACTORY)),
1062
- _ts_param2(3, (0, import_common2.Optional)()),
1063
- _ts_param2(3, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_ATTACHMENT_STAGING)),
1064
- _ts_param2(4, (0, import_common2.Optional)()),
1065
- _ts_param2(4, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_MODEL_CATALOG)),
1066
- _ts_param2(5, (0, import_common2.Optional)()),
1067
- _ts_param2(5, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_QUOTA_PROVIDER)),
1068
- _ts_param2(6, (0, import_common2.Optional)()),
1069
- _ts_param2(6, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_OPTIONS)),
1070
- _ts_metadata2("design:type", Function),
1071
- _ts_metadata2("design:paramtypes", [
1723
+ AgentService = _ts_decorate3([
1724
+ (0, import_common3.Injectable)(),
1725
+ _ts_param3(0, (0, import_common3.Inject)(import_nestjs_agent_core4.AGENT_RUNNER)),
1726
+ _ts_param3(1, (0, import_common3.Inject)(import_nestjs_agent_core4.AGENT_STORE)),
1727
+ _ts_param3(2, (0, import_common3.Inject)(import_nestjs_agent_core4.AGENT_DEPS_FACTORY)),
1728
+ _ts_param3(3, (0, import_common3.Optional)()),
1729
+ _ts_param3(3, (0, import_common3.Inject)(import_nestjs_agent_core4.AGENT_ATTACHMENT_STAGING)),
1730
+ _ts_param3(4, (0, import_common3.Optional)()),
1731
+ _ts_param3(4, (0, import_common3.Inject)(import_nestjs_agent_core4.AGENT_MODEL_CATALOG)),
1732
+ _ts_param3(5, (0, import_common3.Optional)()),
1733
+ _ts_param3(5, (0, import_common3.Inject)(import_nestjs_agent_core4.AGENT_QUOTA_PROVIDER)),
1734
+ _ts_param3(6, (0, import_common3.Optional)()),
1735
+ _ts_param3(6, (0, import_common3.Inject)(import_nestjs_agent_core4.AGENT_OPTIONS)),
1736
+ _ts_param3(7, (0, import_common3.Optional)()),
1737
+ _ts_metadata3("design:type", Function),
1738
+ _ts_metadata3("design:paramtypes", [
1072
1739
  typeof AgentRunner === "undefined" ? Object : AgentRunner,
1073
1740
  typeof AgentStore === "undefined" ? Object : AgentStore,
1074
1741
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
1075
1742
  typeof AttachmentStagingStore === "undefined" ? Object : AttachmentStagingStore,
1076
1743
  typeof ModelCatalog === "undefined" ? Object : ModelCatalog,
1077
1744
  typeof QuotaProvider === "undefined" ? Object : QuotaProvider,
1078
- typeof Pick === "undefined" ? Object : Pick
1745
+ typeof Pick === "undefined" ? Object : Pick,
1746
+ typeof ChatQueueService === "undefined" ? Object : ChatQueueService
1079
1747
  ])
1080
1748
  ], AgentService);
1081
1749
 
1082
1750
  // src/approval-port.adapter.ts
1083
- var import_common3 = require("@nestjs/common");
1084
- function _ts_decorate3(decorators, target, key, desc) {
1751
+ var import_common4 = require("@nestjs/common");
1752
+ function _ts_decorate4(decorators, target, key, desc) {
1085
1753
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1086
1754
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1087
1755
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1094,13 +1762,13 @@ function _ts_decorate3(decorators, target, key, desc) {
1094
1762
  }
1095
1763
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1096
1764
  }
1097
- __name(_ts_decorate3, "_ts_decorate");
1098
- function _ts_metadata3(metadataKey, metadataValue) {
1765
+ __name(_ts_decorate4, "_ts_decorate");
1766
+ function _ts_metadata4(metadataKey, metadataValue) {
1099
1767
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1100
1768
  return Reflect.metadata(metadataKey, metadataValue);
1101
1769
  }
1102
1770
  }
1103
- __name(_ts_metadata3, "_ts_metadata");
1771
+ __name(_ts_metadata4, "_ts_metadata");
1104
1772
  var AgentApprovalPortAdapter = class {
1105
1773
  static {
1106
1774
  __name(this, "AgentApprovalPortAdapter");
@@ -1138,18 +1806,18 @@ var AgentApprovalPortAdapter = class {
1138
1806
  });
1139
1807
  }
1140
1808
  };
1141
- AgentApprovalPortAdapter = _ts_decorate3([
1142
- (0, import_common3.Injectable)(),
1143
- _ts_metadata3("design:type", Function),
1144
- _ts_metadata3("design:paramtypes", [
1809
+ AgentApprovalPortAdapter = _ts_decorate4([
1810
+ (0, import_common4.Injectable)(),
1811
+ _ts_metadata4("design:type", Function),
1812
+ _ts_metadata4("design:paramtypes", [
1145
1813
  typeof AgentService === "undefined" ? Object : AgentService
1146
1814
  ])
1147
1815
  ], AgentApprovalPortAdapter);
1148
1816
 
1149
1817
  // src/controller/agents.controller.ts
1150
- var import_nestjs_agent_core4 = require("@dudousxd/nestjs-agent-core");
1151
- var import_common4 = require("@nestjs/common");
1152
- function _ts_decorate4(decorators, target, key, desc) {
1818
+ var import_nestjs_agent_core5 = require("@dudousxd/nestjs-agent-core");
1819
+ var import_common5 = require("@nestjs/common");
1820
+ function _ts_decorate5(decorators, target, key, desc) {
1153
1821
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1154
1822
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1155
1823
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1162,19 +1830,19 @@ function _ts_decorate4(decorators, target, key, desc) {
1162
1830
  }
1163
1831
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1164
1832
  }
1165
- __name(_ts_decorate4, "_ts_decorate");
1166
- function _ts_metadata4(metadataKey, metadataValue) {
1833
+ __name(_ts_decorate5, "_ts_decorate");
1834
+ function _ts_metadata5(metadataKey, metadataValue) {
1167
1835
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1168
1836
  return Reflect.metadata(metadataKey, metadataValue);
1169
1837
  }
1170
1838
  }
1171
- __name(_ts_metadata4, "_ts_metadata");
1172
- function _ts_param3(paramIndex, decorator) {
1839
+ __name(_ts_metadata5, "_ts_metadata");
1840
+ function _ts_param4(paramIndex, decorator) {
1173
1841
  return function(target, key) {
1174
1842
  decorator(target, key, paramIndex);
1175
1843
  };
1176
1844
  }
1177
- __name(_ts_param3, "_ts_param");
1845
+ __name(_ts_param4, "_ts_param");
1178
1846
  var AgentsController = class {
1179
1847
  static {
1180
1848
  __name(this, "AgentsController");
@@ -1196,26 +1864,26 @@ var AgentsController = class {
1196
1864
  }));
1197
1865
  }
1198
1866
  };
1199
- _ts_decorate4([
1200
- (0, import_common4.Get)(),
1201
- _ts_metadata4("design:type", Function),
1202
- _ts_metadata4("design:paramtypes", []),
1203
- _ts_metadata4("design:returntype", Array)
1867
+ _ts_decorate5([
1868
+ (0, import_common5.Get)(),
1869
+ _ts_metadata5("design:type", Function),
1870
+ _ts_metadata5("design:paramtypes", []),
1871
+ _ts_metadata5("design:returntype", Array)
1204
1872
  ], AgentsController.prototype, "list", null);
1205
- AgentsController = _ts_decorate4([
1206
- (0, import_common4.Controller)("agents"),
1207
- _ts_param3(0, (0, import_common4.Inject)(import_nestjs_agent_core4.AGENT_REGISTRY)),
1208
- _ts_param3(1, (0, import_common4.Inject)(import_nestjs_agent_core4.AGENT_DEPS_FACTORY)),
1209
- _ts_metadata4("design:type", Function),
1210
- _ts_metadata4("design:paramtypes", [
1211
- typeof import_nestjs_agent_core4.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core4.AgentRegistry,
1873
+ AgentsController = _ts_decorate5([
1874
+ (0, import_common5.Controller)("agents"),
1875
+ _ts_param4(0, (0, import_common5.Inject)(import_nestjs_agent_core5.AGENT_REGISTRY)),
1876
+ _ts_param4(1, (0, import_common5.Inject)(import_nestjs_agent_core5.AGENT_DEPS_FACTORY)),
1877
+ _ts_metadata5("design:type", Function),
1878
+ _ts_metadata5("design:paramtypes", [
1879
+ typeof import_nestjs_agent_core5.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core5.AgentRegistry,
1212
1880
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory
1213
1881
  ])
1214
1882
  ], AgentsController);
1215
1883
 
1216
1884
  // src/controller/attachments.controller.ts
1217
- var import_nestjs_agent_core5 = require("@dudousxd/nestjs-agent-core");
1218
- var import_common5 = require("@nestjs/common");
1885
+ var import_nestjs_agent_core6 = require("@dudousxd/nestjs-agent-core");
1886
+ var import_common6 = require("@nestjs/common");
1219
1887
  var import_platform_express = require("@nestjs/platform-express");
1220
1888
 
1221
1889
  // src/attachment-limits.ts
@@ -1244,7 +1912,7 @@ function attachmentLimits(options, staging) {
1244
1912
  __name(attachmentLimits, "attachmentLimits");
1245
1913
 
1246
1914
  // src/controller/attachments.controller.ts
1247
- function _ts_decorate5(decorators, target, key, desc) {
1915
+ function _ts_decorate6(decorators, target, key, desc) {
1248
1916
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1249
1917
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1250
1918
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1257,19 +1925,19 @@ function _ts_decorate5(decorators, target, key, desc) {
1257
1925
  }
1258
1926
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1259
1927
  }
1260
- __name(_ts_decorate5, "_ts_decorate");
1261
- function _ts_metadata5(metadataKey, metadataValue) {
1928
+ __name(_ts_decorate6, "_ts_decorate");
1929
+ function _ts_metadata6(metadataKey, metadataValue) {
1262
1930
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1263
1931
  return Reflect.metadata(metadataKey, metadataValue);
1264
1932
  }
1265
1933
  }
1266
- __name(_ts_metadata5, "_ts_metadata");
1267
- function _ts_param4(paramIndex, decorator) {
1934
+ __name(_ts_metadata6, "_ts_metadata");
1935
+ function _ts_param5(paramIndex, decorator) {
1268
1936
  return function(target, key) {
1269
1937
  decorator(target, key, paramIndex);
1270
1938
  };
1271
1939
  }
1272
- __name(_ts_param4, "_ts_param");
1940
+ __name(_ts_param5, "_ts_param");
1273
1941
  var HARD_MAX_ATTACHMENT_BYTES = 32 * 1024 * 1024;
1274
1942
  var ATTACHMENT_PAGE_SIZE = 50;
1275
1943
  var AttachmentsController = class {
@@ -1303,17 +1971,17 @@ var AttachmentsController = class {
1303
1971
  }
1304
1972
  async upload(req, file) {
1305
1973
  if (this.staging === void 0) {
1306
- throw new import_common5.NotImplementedException("Attachment upload is not configured on this server: bind AGENT_ATTACHMENT_STAGING (e.g. import AgentMediaAttachmentsModule).");
1974
+ throw new import_common6.NotImplementedException("Attachment upload is not configured on this server: bind AGENT_ATTACHMENT_STAGING (e.g. import AgentMediaAttachmentsModule).");
1307
1975
  }
1308
1976
  if (file === void 0) {
1309
- throw new import_common5.BadRequestException('multipart field "file" is required');
1977
+ throw new import_common6.BadRequestException('multipart field "file" is required');
1310
1978
  }
1311
1979
  const { allowedContentTypes, maxBytes } = attachmentLimits(this.options, this.staging);
1312
1980
  if (!allowedContentTypes.includes(file.mimetype)) {
1313
- throw new import_common5.UnsupportedMediaTypeException(`content type "${file.mimetype}" is not allowed (allowed: ${allowedContentTypes.join(", ")})`);
1981
+ throw new import_common6.UnsupportedMediaTypeException(`content type "${file.mimetype}" is not allowed (allowed: ${allowedContentTypes.join(", ")})`);
1314
1982
  }
1315
1983
  if (file.size > maxBytes) {
1316
- throw new import_common5.PayloadTooLargeException(`file exceeds the ${maxBytes}-byte limit`);
1984
+ throw new import_common6.PayloadTooLargeException(`file exceeds the ${maxBytes}-byte limit`);
1317
1985
  }
1318
1986
  const actor = await this.actorResolver.resolve(req);
1319
1987
  return this.staging.stage({
@@ -1325,39 +1993,39 @@ var AttachmentsController = class {
1325
1993
  });
1326
1994
  }
1327
1995
  };
1328
- _ts_decorate5([
1329
- (0, import_common5.Get)(),
1330
- _ts_param4(0, (0, import_common5.Req)()),
1331
- _ts_metadata5("design:type", Function),
1332
- _ts_metadata5("design:paramtypes", [
1996
+ _ts_decorate6([
1997
+ (0, import_common6.Get)(),
1998
+ _ts_param5(0, (0, import_common6.Req)()),
1999
+ _ts_metadata6("design:type", Function),
2000
+ _ts_metadata6("design:paramtypes", [
1333
2001
  typeof Request === "undefined" ? Object : Request
1334
2002
  ]),
1335
- _ts_metadata5("design:returntype", Promise)
2003
+ _ts_metadata6("design:returntype", Promise)
1336
2004
  ], AttachmentsController.prototype, "list", null);
1337
- _ts_decorate5([
1338
- (0, import_common5.Post)(),
1339
- (0, import_common5.UseInterceptors)((0, import_platform_express.FileInterceptor)("file", {
2005
+ _ts_decorate6([
2006
+ (0, import_common6.Post)(),
2007
+ (0, import_common6.UseInterceptors)((0, import_platform_express.FileInterceptor)("file", {
1340
2008
  limits: {
1341
2009
  fileSize: HARD_MAX_ATTACHMENT_BYTES
1342
2010
  }
1343
2011
  })),
1344
- _ts_param4(0, (0, import_common5.Req)()),
1345
- _ts_param4(1, (0, import_common5.UploadedFile)()),
1346
- _ts_metadata5("design:type", Function),
1347
- _ts_metadata5("design:paramtypes", [
2012
+ _ts_param5(0, (0, import_common6.Req)()),
2013
+ _ts_param5(1, (0, import_common6.UploadedFile)()),
2014
+ _ts_metadata6("design:type", Function),
2015
+ _ts_metadata6("design:paramtypes", [
1348
2016
  typeof Request === "undefined" ? Object : Request,
1349
2017
  Object
1350
2018
  ]),
1351
- _ts_metadata5("design:returntype", Promise)
2019
+ _ts_metadata6("design:returntype", Promise)
1352
2020
  ], AttachmentsController.prototype, "upload", null);
1353
- AttachmentsController = _ts_decorate5([
1354
- (0, import_common5.Controller)("attachments"),
1355
- _ts_param4(0, (0, import_common5.Inject)(import_nestjs_agent_core5.AGENT_OPTIONS)),
1356
- _ts_param4(1, (0, import_common5.Inject)(import_nestjs_agent_core5.AGENT_ACTOR_RESOLVER)),
1357
- _ts_param4(3, (0, import_common5.Optional)()),
1358
- _ts_param4(3, (0, import_common5.Inject)(import_nestjs_agent_core5.AGENT_ATTACHMENT_STAGING)),
1359
- _ts_metadata5("design:type", Function),
1360
- _ts_metadata5("design:paramtypes", [
2021
+ AttachmentsController = _ts_decorate6([
2022
+ (0, import_common6.Controller)("attachments"),
2023
+ _ts_param5(0, (0, import_common6.Inject)(import_nestjs_agent_core6.AGENT_OPTIONS)),
2024
+ _ts_param5(1, (0, import_common6.Inject)(import_nestjs_agent_core6.AGENT_ACTOR_RESOLVER)),
2025
+ _ts_param5(3, (0, import_common6.Optional)()),
2026
+ _ts_param5(3, (0, import_common6.Inject)(import_nestjs_agent_core6.AGENT_ATTACHMENT_STAGING)),
2027
+ _ts_metadata6("design:type", Function),
2028
+ _ts_metadata6("design:paramtypes", [
1361
2029
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
1362
2030
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
1363
2031
  typeof AgentService === "undefined" ? Object : AgentService,
@@ -1366,9 +2034,9 @@ AttachmentsController = _ts_decorate5([
1366
2034
  ], AttachmentsController);
1367
2035
 
1368
2036
  // src/controller/chat.controller.ts
1369
- var import_nestjs_agent_core6 = require("@dudousxd/nestjs-agent-core");
1370
- var import_common6 = require("@nestjs/common");
1371
- function _ts_decorate6(decorators, target, key, desc) {
2037
+ var import_nestjs_agent_core7 = require("@dudousxd/nestjs-agent-core");
2038
+ var import_common7 = require("@nestjs/common");
2039
+ function _ts_decorate7(decorators, target, key, desc) {
1372
2040
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1373
2041
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1374
2042
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1381,39 +2049,52 @@ function _ts_decorate6(decorators, target, key, desc) {
1381
2049
  }
1382
2050
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1383
2051
  }
1384
- __name(_ts_decorate6, "_ts_decorate");
1385
- function _ts_metadata6(metadataKey, metadataValue) {
2052
+ __name(_ts_decorate7, "_ts_decorate");
2053
+ function _ts_metadata7(metadataKey, metadataValue) {
1386
2054
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1387
2055
  return Reflect.metadata(metadataKey, metadataValue);
1388
2056
  }
1389
2057
  }
1390
- __name(_ts_metadata6, "_ts_metadata");
1391
- function _ts_param5(paramIndex, decorator) {
2058
+ __name(_ts_metadata7, "_ts_metadata");
2059
+ function _ts_param6(paramIndex, decorator) {
1392
2060
  return function(target, key) {
1393
2061
  decorator(target, key, paramIndex);
1394
2062
  };
1395
2063
  }
1396
- __name(_ts_param5, "_ts_param");
2064
+ __name(_ts_param6, "_ts_param");
2065
+ function sendMode(body) {
2066
+ if (body.interrupt === true) {
2067
+ return "interrupt";
2068
+ }
2069
+ if (body.mode === void 0 || body.mode === null) {
2070
+ return "auto";
2071
+ }
2072
+ if (body.mode === "auto" || body.mode === "queue" || body.mode === "interrupt") {
2073
+ return body.mode;
2074
+ }
2075
+ throw new import_common7.BadRequestException("mode must be 'auto', 'queue' or 'interrupt'");
2076
+ }
2077
+ __name(sendMode, "sendMode");
1397
2078
  function attachmentRefs(claimed) {
1398
2079
  if (claimed === void 0) {
1399
2080
  return [];
1400
2081
  }
1401
2082
  if (!Array.isArray(claimed)) {
1402
- throw new import_common6.BadRequestException("attachments must be an array of { mediaId }");
2083
+ throw new import_common7.BadRequestException("attachments must be an array of { mediaId }");
1403
2084
  }
1404
2085
  if (claimed.length > MAX_ATTACHMENTS_PER_MESSAGE) {
1405
- throw new import_common6.BadRequestException(`a message may carry at most ${MAX_ATTACHMENTS_PER_MESSAGE} attachments`);
2086
+ throw new import_common7.BadRequestException(`a message may carry at most ${MAX_ATTACHMENTS_PER_MESSAGE} attachments`);
1406
2087
  }
1407
2088
  return claimed.map((entry) => {
1408
2089
  if (typeof entry !== "object" || entry === null || !("mediaId" in entry)) {
1409
- throw new import_common6.BadRequestException("each attachment must be an object with a mediaId");
2090
+ throw new import_common7.BadRequestException("each attachment must be an object with a mediaId");
1410
2091
  }
1411
2092
  if (Object.keys(entry).some((key) => key !== "mediaId")) {
1412
- throw new import_common6.BadRequestException("attachments are { mediaId } refs \u2014 send nothing but the id");
2093
+ throw new import_common7.BadRequestException("attachments are { mediaId } refs \u2014 send nothing but the id");
1413
2094
  }
1414
2095
  const { mediaId } = entry;
1415
2096
  if (typeof mediaId !== "string" || mediaId.length === 0) {
1416
- throw new import_common6.BadRequestException("each attachment must carry a non-empty string mediaId");
2097
+ throw new import_common7.BadRequestException("each attachment must carry a non-empty string mediaId");
1417
2098
  }
1418
2099
  return {
1419
2100
  mediaId
@@ -1431,10 +2112,17 @@ var ChatController = class {
1431
2112
  this.agent = agent;
1432
2113
  this.actorResolver = actorResolver;
1433
2114
  }
2115
+ /**
2116
+ * Start a turn and stream it — or, when the thread already has one running, queue the message and
2117
+ * answer `202 { queued: true, messageId, position, queue, … }` (JSON, no stream): it runs when the
2118
+ * turn ahead of it settles, and the stream of the run holding the thread announces it with a
2119
+ * `queue` frame.
2120
+ */
1434
2121
  async chat(req, res, body) {
1435
2122
  const actor = await this.actorResolver.resolve(req);
1436
2123
  const attachments = attachmentRefs(body.attachments);
1437
- const { runId, threadId } = await this.agent.chat({
2124
+ const mode = sendMode(body);
2125
+ const result = await this.agent.send({
1438
2126
  actor,
1439
2127
  message: body.message,
1440
2128
  ...body.threadId !== void 0 ? {
@@ -1457,8 +2145,14 @@ var ChatController = class {
1457
2145
  } : {},
1458
2146
  ...typeof body.model === "string" && body.model.length > 0 ? {
1459
2147
  model: body.model
1460
- } : {}
2148
+ } : {},
2149
+ mode
1461
2150
  });
2151
+ if (result.queued === true) {
2152
+ res.status(202).json(result);
2153
+ return;
2154
+ }
2155
+ const { runId, threadId } = result;
1462
2156
  await this.pipe(res, runId, this.agent.subscribe(runId), threadId);
1463
2157
  }
1464
2158
  /**
@@ -1533,7 +2227,7 @@ data: ${line}
1533
2227
  }
1534
2228
  res.write("event: done\ndata: {}\n\n");
1535
2229
  } catch (error) {
1536
- const payload = error instanceof import_nestjs_agent_core6.AgentStreamError ? {
2230
+ const payload = error instanceof import_nestjs_agent_core7.AgentStreamError ? {
1537
2231
  code: error.code,
1538
2232
  message: error.message
1539
2233
  } : {
@@ -1548,50 +2242,50 @@ data: ${JSON.stringify(payload)}
1548
2242
  res.end();
1549
2243
  }
1550
2244
  };
1551
- _ts_decorate6([
1552
- (0, import_common6.Post)("chat"),
1553
- _ts_param5(0, (0, import_common6.Req)()),
1554
- _ts_param5(1, (0, import_common6.Res)()),
1555
- _ts_param5(2, (0, import_common6.Body)()),
1556
- _ts_metadata6("design:type", Function),
1557
- _ts_metadata6("design:paramtypes", [
2245
+ _ts_decorate7([
2246
+ (0, import_common7.Post)("chat"),
2247
+ _ts_param6(0, (0, import_common7.Req)()),
2248
+ _ts_param6(1, (0, import_common7.Res)()),
2249
+ _ts_param6(2, (0, import_common7.Body)()),
2250
+ _ts_metadata7("design:type", Function),
2251
+ _ts_metadata7("design:paramtypes", [
1558
2252
  typeof Request === "undefined" ? Object : Request,
1559
2253
  typeof Response === "undefined" ? Object : Response,
1560
2254
  typeof ChatBody === "undefined" ? Object : ChatBody
1561
2255
  ]),
1562
- _ts_metadata6("design:returntype", Promise)
2256
+ _ts_metadata7("design:returntype", Promise)
1563
2257
  ], ChatController.prototype, "chat", null);
1564
- _ts_decorate6([
1565
- (0, import_common6.Get)("chat/:runId/stream"),
1566
- _ts_param5(0, (0, import_common6.Req)()),
1567
- _ts_param5(1, (0, import_common6.Param)("runId")),
1568
- _ts_param5(2, (0, import_common6.Res)()),
1569
- _ts_param5(3, (0, import_common6.Query)("after")),
1570
- _ts_metadata6("design:type", Function),
1571
- _ts_metadata6("design:paramtypes", [
2258
+ _ts_decorate7([
2259
+ (0, import_common7.Get)("chat/:runId/stream"),
2260
+ _ts_param6(0, (0, import_common7.Req)()),
2261
+ _ts_param6(1, (0, import_common7.Param)("runId")),
2262
+ _ts_param6(2, (0, import_common7.Res)()),
2263
+ _ts_param6(3, (0, import_common7.Query)("after")),
2264
+ _ts_metadata7("design:type", Function),
2265
+ _ts_metadata7("design:paramtypes", [
1572
2266
  typeof Request === "undefined" ? Object : Request,
1573
2267
  String,
1574
2268
  typeof Response === "undefined" ? Object : Response,
1575
2269
  String
1576
2270
  ]),
1577
- _ts_metadata6("design:returntype", Promise)
2271
+ _ts_metadata7("design:returntype", Promise)
1578
2272
  ], ChatController.prototype, "stream", null);
1579
- _ts_decorate6([
1580
- (0, import_common6.Post)("chat/:runId/cancel"),
1581
- _ts_param5(0, (0, import_common6.Req)()),
1582
- _ts_param5(1, (0, import_common6.Param)("runId")),
1583
- _ts_metadata6("design:type", Function),
1584
- _ts_metadata6("design:paramtypes", [
2273
+ _ts_decorate7([
2274
+ (0, import_common7.Post)("chat/:runId/cancel"),
2275
+ _ts_param6(0, (0, import_common7.Req)()),
2276
+ _ts_param6(1, (0, import_common7.Param)("runId")),
2277
+ _ts_metadata7("design:type", Function),
2278
+ _ts_metadata7("design:paramtypes", [
1585
2279
  typeof Request === "undefined" ? Object : Request,
1586
2280
  String
1587
2281
  ]),
1588
- _ts_metadata6("design:returntype", Promise)
2282
+ _ts_metadata7("design:returntype", Promise)
1589
2283
  ], ChatController.prototype, "cancel", null);
1590
- ChatController = _ts_decorate6([
1591
- (0, import_common6.Controller)(),
1592
- _ts_param5(1, (0, import_common6.Inject)(import_nestjs_agent_core6.AGENT_ACTOR_RESOLVER)),
1593
- _ts_metadata6("design:type", Function),
1594
- _ts_metadata6("design:paramtypes", [
2284
+ ChatController = _ts_decorate7([
2285
+ (0, import_common7.Controller)(),
2286
+ _ts_param6(1, (0, import_common7.Inject)(import_nestjs_agent_core7.AGENT_ACTOR_RESOLVER)),
2287
+ _ts_metadata7("design:type", Function),
2288
+ _ts_metadata7("design:paramtypes", [
1595
2289
  typeof AgentService === "undefined" ? Object : AgentService,
1596
2290
  typeof ActorResolver === "undefined" ? Object : ActorResolver
1597
2291
  ])
@@ -1607,8 +2301,8 @@ function parseCursor(raw) {
1607
2301
  __name(parseCursor, "parseCursor");
1608
2302
 
1609
2303
  // src/controller/config.controller.ts
1610
- var import_nestjs_agent_core7 = require("@dudousxd/nestjs-agent-core");
1611
- var import_common7 = require("@nestjs/common");
2304
+ var import_nestjs_agent_core8 = require("@dudousxd/nestjs-agent-core");
2305
+ var import_common8 = require("@nestjs/common");
1612
2306
 
1613
2307
  // src/resolver/anonymous-actor-resolver.ts
1614
2308
  var import_node_crypto = require("crypto");
@@ -1698,7 +2392,7 @@ var AnonymousActorResolver = class {
1698
2392
  };
1699
2393
 
1700
2394
  // src/controller/config.controller.ts
1701
- function _ts_decorate7(decorators, target, key, desc) {
2395
+ function _ts_decorate8(decorators, target, key, desc) {
1702
2396
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1703
2397
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1704
2398
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1711,19 +2405,19 @@ function _ts_decorate7(decorators, target, key, desc) {
1711
2405
  }
1712
2406
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1713
2407
  }
1714
- __name(_ts_decorate7, "_ts_decorate");
1715
- function _ts_metadata7(metadataKey, metadataValue) {
2408
+ __name(_ts_decorate8, "_ts_decorate");
2409
+ function _ts_metadata8(metadataKey, metadataValue) {
1716
2410
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1717
2411
  return Reflect.metadata(metadataKey, metadataValue);
1718
2412
  }
1719
2413
  }
1720
- __name(_ts_metadata7, "_ts_metadata");
1721
- function _ts_param6(paramIndex, decorator) {
2414
+ __name(_ts_metadata8, "_ts_metadata");
2415
+ function _ts_param7(paramIndex, decorator) {
1722
2416
  return function(target, key) {
1723
2417
  decorator(target, key, paramIndex);
1724
2418
  };
1725
2419
  }
1726
- __name(_ts_param6, "_ts_param");
2420
+ __name(_ts_param7, "_ts_param");
1727
2421
  var ConfigController = class {
1728
2422
  static {
1729
2423
  __name(this, "ConfigController");
@@ -1754,25 +2448,25 @@ var ConfigController = class {
1754
2448
  };
1755
2449
  }
1756
2450
  };
1757
- _ts_decorate7([
1758
- (0, import_common7.Get)(),
1759
- _ts_param6(0, (0, import_common7.Req)()),
1760
- _ts_metadata7("design:type", Function),
1761
- _ts_metadata7("design:paramtypes", [
2451
+ _ts_decorate8([
2452
+ (0, import_common8.Get)(),
2453
+ _ts_param7(0, (0, import_common8.Req)()),
2454
+ _ts_metadata8("design:type", Function),
2455
+ _ts_metadata8("design:paramtypes", [
1762
2456
  typeof Request === "undefined" ? Object : Request
1763
2457
  ]),
1764
- _ts_metadata7("design:returntype", Promise)
2458
+ _ts_metadata8("design:returntype", Promise)
1765
2459
  ], ConfigController.prototype, "config", null);
1766
- ConfigController = _ts_decorate7([
1767
- (0, import_common7.Controller)("config"),
1768
- _ts_param6(0, (0, import_common7.Inject)(import_nestjs_agent_core7.AGENT_OPTIONS)),
1769
- _ts_param6(1, (0, import_common7.Inject)(import_nestjs_agent_core7.AGENT_ACTOR_RESOLVER)),
1770
- _ts_param6(2, (0, import_common7.Optional)()),
1771
- _ts_param6(2, (0, import_common7.Inject)(import_nestjs_agent_core7.AGENT_ATTACHMENT_STAGING)),
1772
- _ts_param6(3, (0, import_common7.Optional)()),
1773
- _ts_param6(3, (0, import_common7.Inject)(import_nestjs_agent_core7.AGENT_MODEL_CATALOG)),
1774
- _ts_metadata7("design:type", Function),
1775
- _ts_metadata7("design:paramtypes", [
2460
+ ConfigController = _ts_decorate8([
2461
+ (0, import_common8.Controller)("config"),
2462
+ _ts_param7(0, (0, import_common8.Inject)(import_nestjs_agent_core8.AGENT_OPTIONS)),
2463
+ _ts_param7(1, (0, import_common8.Inject)(import_nestjs_agent_core8.AGENT_ACTOR_RESOLVER)),
2464
+ _ts_param7(2, (0, import_common8.Optional)()),
2465
+ _ts_param7(2, (0, import_common8.Inject)(import_nestjs_agent_core8.AGENT_ATTACHMENT_STAGING)),
2466
+ _ts_param7(3, (0, import_common8.Optional)()),
2467
+ _ts_param7(3, (0, import_common8.Inject)(import_nestjs_agent_core8.AGENT_MODEL_CATALOG)),
2468
+ _ts_metadata8("design:type", Function),
2469
+ _ts_metadata8("design:paramtypes", [
1776
2470
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
1777
2471
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
1778
2472
  Object,
@@ -1781,9 +2475,9 @@ ConfigController = _ts_decorate7([
1781
2475
  ], ConfigController);
1782
2476
 
1783
2477
  // src/controller/memories.controller.ts
1784
- var import_nestjs_agent_core8 = require("@dudousxd/nestjs-agent-core");
1785
- var import_common8 = require("@nestjs/common");
1786
- function _ts_decorate8(decorators, target, key, desc) {
2478
+ var import_nestjs_agent_core9 = require("@dudousxd/nestjs-agent-core");
2479
+ var import_common9 = require("@nestjs/common");
2480
+ function _ts_decorate9(decorators, target, key, desc) {
1787
2481
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1788
2482
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1789
2483
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1796,19 +2490,19 @@ function _ts_decorate8(decorators, target, key, desc) {
1796
2490
  }
1797
2491
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1798
2492
  }
1799
- __name(_ts_decorate8, "_ts_decorate");
1800
- function _ts_metadata8(metadataKey, metadataValue) {
2493
+ __name(_ts_decorate9, "_ts_decorate");
2494
+ function _ts_metadata9(metadataKey, metadataValue) {
1801
2495
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1802
2496
  return Reflect.metadata(metadataKey, metadataValue);
1803
2497
  }
1804
2498
  }
1805
- __name(_ts_metadata8, "_ts_metadata");
1806
- function _ts_param7(paramIndex, decorator) {
2499
+ __name(_ts_metadata9, "_ts_metadata");
2500
+ function _ts_param8(paramIndex, decorator) {
1807
2501
  return function(target, key) {
1808
2502
  decorator(target, key, paramIndex);
1809
2503
  };
1810
2504
  }
1811
- __name(_ts_param7, "_ts_param");
2505
+ __name(_ts_param8, "_ts_param");
1812
2506
  var MemoriesController = class {
1813
2507
  static {
1814
2508
  __name(this, "MemoriesController");
@@ -1842,20 +2536,20 @@ var MemoriesController = class {
1842
2536
  */
1843
2537
  async forget(req, id) {
1844
2538
  if (this.memory === void 0) {
1845
- throw new import_common8.NotFoundException("No memory is configured in this deployment.");
2539
+ throw new import_common9.NotFoundException("No memory is configured in this deployment.");
1846
2540
  }
1847
2541
  const actor = await this.actorResolver.resolve(req);
1848
2542
  const digest = await this.unbounded("", actor);
1849
2543
  const entry = digest.entries.find((candidate) => candidate.id === id);
1850
2544
  if (entry === void 0) {
1851
- throw new import_common8.NotFoundException(`No memory with id "${id}".`);
2545
+ throw new import_common9.NotFoundException(`No memory with id "${id}".`);
1852
2546
  }
1853
- const verdict = (0, import_nestjs_agent_core8.memoryForgetVerdict)({
2547
+ const verdict = (0, import_nestjs_agent_core9.memoryForgetVerdict)({
1854
2548
  record: entry,
1855
2549
  actor
1856
2550
  });
1857
2551
  if (!verdict.allowed) {
1858
- throw new import_common8.ForbiddenException(verdict.reason);
2552
+ throw new import_common9.ForbiddenException(verdict.reason);
1859
2553
  }
1860
2554
  return {
1861
2555
  forgotten: await this.memory.provider.forget({
@@ -1869,7 +2563,7 @@ var MemoriesController = class {
1869
2563
  }
1870
2564
  async unbounded(threadId, actor) {
1871
2565
  const config = this.memory;
1872
- return await (0, import_nestjs_agent_core8.offerMemories)({
2566
+ return await (0, import_nestjs_agent_core9.offerMemories)({
1873
2567
  config: {
1874
2568
  ...config,
1875
2569
  maxMemories: Number.POSITIVE_INFINITY
@@ -1881,44 +2575,44 @@ var MemoriesController = class {
1881
2575
  });
1882
2576
  }
1883
2577
  };
1884
- _ts_decorate8([
1885
- (0, import_common8.Get)(),
1886
- _ts_param7(0, (0, import_common8.Req)()),
1887
- _ts_param7(1, (0, import_common8.Query)("threadId")),
1888
- _ts_metadata8("design:type", Function),
1889
- _ts_metadata8("design:paramtypes", [
2578
+ _ts_decorate9([
2579
+ (0, import_common9.Get)(),
2580
+ _ts_param8(0, (0, import_common9.Req)()),
2581
+ _ts_param8(1, (0, import_common9.Query)("threadId")),
2582
+ _ts_metadata9("design:type", Function),
2583
+ _ts_metadata9("design:paramtypes", [
1890
2584
  typeof Request === "undefined" ? Object : Request,
1891
2585
  String
1892
2586
  ]),
1893
- _ts_metadata8("design:returntype", Promise)
2587
+ _ts_metadata9("design:returntype", Promise)
1894
2588
  ], MemoriesController.prototype, "list", null);
1895
- _ts_decorate8([
1896
- (0, import_common8.Delete)(":id"),
1897
- _ts_param7(0, (0, import_common8.Req)()),
1898
- _ts_param7(1, (0, import_common8.Param)("id")),
1899
- _ts_metadata8("design:type", Function),
1900
- _ts_metadata8("design:paramtypes", [
2589
+ _ts_decorate9([
2590
+ (0, import_common9.Delete)(":id"),
2591
+ _ts_param8(0, (0, import_common9.Req)()),
2592
+ _ts_param8(1, (0, import_common9.Param)("id")),
2593
+ _ts_metadata9("design:type", Function),
2594
+ _ts_metadata9("design:paramtypes", [
1901
2595
  typeof Request === "undefined" ? Object : Request,
1902
2596
  String
1903
2597
  ]),
1904
- _ts_metadata8("design:returntype", Promise)
2598
+ _ts_metadata9("design:returntype", Promise)
1905
2599
  ], MemoriesController.prototype, "forget", null);
1906
- MemoriesController = _ts_decorate8([
1907
- (0, import_common8.Controller)("memories"),
1908
- _ts_param7(0, (0, import_common8.Inject)(import_nestjs_agent_core8.AGENT_ACTOR_RESOLVER)),
1909
- _ts_param7(1, (0, import_common8.Optional)()),
1910
- _ts_param7(1, (0, import_common8.Inject)(import_nestjs_agent_core8.AGENT_MEMORY)),
1911
- _ts_metadata8("design:type", Function),
1912
- _ts_metadata8("design:paramtypes", [
2600
+ MemoriesController = _ts_decorate9([
2601
+ (0, import_common9.Controller)("memories"),
2602
+ _ts_param8(0, (0, import_common9.Inject)(import_nestjs_agent_core9.AGENT_ACTOR_RESOLVER)),
2603
+ _ts_param8(1, (0, import_common9.Optional)()),
2604
+ _ts_param8(1, (0, import_common9.Inject)(import_nestjs_agent_core9.AGENT_MEMORY)),
2605
+ _ts_metadata9("design:type", Function),
2606
+ _ts_metadata9("design:paramtypes", [
1913
2607
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
1914
2608
  Object
1915
2609
  ])
1916
2610
  ], MemoriesController);
1917
2611
 
1918
2612
  // src/controller/messages.controller.ts
1919
- var import_nestjs_agent_core9 = require("@dudousxd/nestjs-agent-core");
1920
- var import_common9 = require("@nestjs/common");
1921
- function _ts_decorate9(decorators, target, key, desc) {
2613
+ var import_nestjs_agent_core10 = require("@dudousxd/nestjs-agent-core");
2614
+ var import_common10 = require("@nestjs/common");
2615
+ function _ts_decorate10(decorators, target, key, desc) {
1922
2616
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1923
2617
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1924
2618
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1931,19 +2625,19 @@ function _ts_decorate9(decorators, target, key, desc) {
1931
2625
  }
1932
2626
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1933
2627
  }
1934
- __name(_ts_decorate9, "_ts_decorate");
1935
- function _ts_metadata9(metadataKey, metadataValue) {
2628
+ __name(_ts_decorate10, "_ts_decorate");
2629
+ function _ts_metadata10(metadataKey, metadataValue) {
1936
2630
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1937
2631
  return Reflect.metadata(metadataKey, metadataValue);
1938
2632
  }
1939
2633
  }
1940
- __name(_ts_metadata9, "_ts_metadata");
1941
- function _ts_param8(paramIndex, decorator) {
2634
+ __name(_ts_metadata10, "_ts_metadata");
2635
+ function _ts_param9(paramIndex, decorator) {
1942
2636
  return function(target, key) {
1943
2637
  decorator(target, key, paramIndex);
1944
2638
  };
1945
2639
  }
1946
- __name(_ts_param8, "_ts_param");
2640
+ __name(_ts_param9, "_ts_param");
1947
2641
  var MessagesController = class {
1948
2642
  static {
1949
2643
  __name(this, "MessagesController");
@@ -1971,34 +2665,34 @@ var MessagesController = class {
1971
2665
  };
1972
2666
  }
1973
2667
  };
1974
- _ts_decorate9([
1975
- (0, import_common9.Post)(":id/feedback"),
1976
- (0, import_common9.HttpCode)(200),
1977
- _ts_param8(0, (0, import_common9.Req)()),
1978
- _ts_param8(1, (0, import_common9.Param)("id")),
1979
- _ts_param8(2, (0, import_common9.Body)()),
1980
- _ts_metadata9("design:type", Function),
1981
- _ts_metadata9("design:paramtypes", [
2668
+ _ts_decorate10([
2669
+ (0, import_common10.Post)(":id/feedback"),
2670
+ (0, import_common10.HttpCode)(200),
2671
+ _ts_param9(0, (0, import_common10.Req)()),
2672
+ _ts_param9(1, (0, import_common10.Param)("id")),
2673
+ _ts_param9(2, (0, import_common10.Body)()),
2674
+ _ts_metadata10("design:type", Function),
2675
+ _ts_metadata10("design:paramtypes", [
1982
2676
  typeof Request === "undefined" ? Object : Request,
1983
2677
  String,
1984
2678
  typeof FeedbackBody === "undefined" ? Object : FeedbackBody
1985
2679
  ]),
1986
- _ts_metadata9("design:returntype", Promise)
2680
+ _ts_metadata10("design:returntype", Promise)
1987
2681
  ], MessagesController.prototype, "feedback", null);
1988
- MessagesController = _ts_decorate9([
1989
- (0, import_common9.Controller)("messages"),
1990
- _ts_param8(1, (0, import_common9.Inject)(import_nestjs_agent_core9.AGENT_ACTOR_RESOLVER)),
1991
- _ts_metadata9("design:type", Function),
1992
- _ts_metadata9("design:paramtypes", [
2682
+ MessagesController = _ts_decorate10([
2683
+ (0, import_common10.Controller)("messages"),
2684
+ _ts_param9(1, (0, import_common10.Inject)(import_nestjs_agent_core10.AGENT_ACTOR_RESOLVER)),
2685
+ _ts_metadata10("design:type", Function),
2686
+ _ts_metadata10("design:paramtypes", [
1993
2687
  typeof AgentService === "undefined" ? Object : AgentService,
1994
2688
  typeof ActorResolver === "undefined" ? Object : ActorResolver
1995
2689
  ])
1996
2690
  ], MessagesController);
1997
2691
 
1998
2692
  // src/controller/models.controller.ts
1999
- var import_nestjs_agent_core10 = require("@dudousxd/nestjs-agent-core");
2000
- var import_common10 = require("@nestjs/common");
2001
- function _ts_decorate10(decorators, target, key, desc) {
2693
+ var import_nestjs_agent_core11 = require("@dudousxd/nestjs-agent-core");
2694
+ var import_common11 = require("@nestjs/common");
2695
+ function _ts_decorate11(decorators, target, key, desc) {
2002
2696
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2003
2697
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2004
2698
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2011,19 +2705,19 @@ function _ts_decorate10(decorators, target, key, desc) {
2011
2705
  }
2012
2706
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2013
2707
  }
2014
- __name(_ts_decorate10, "_ts_decorate");
2015
- function _ts_metadata10(metadataKey, metadataValue) {
2708
+ __name(_ts_decorate11, "_ts_decorate");
2709
+ function _ts_metadata11(metadataKey, metadataValue) {
2016
2710
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2017
2711
  return Reflect.metadata(metadataKey, metadataValue);
2018
2712
  }
2019
2713
  }
2020
- __name(_ts_metadata10, "_ts_metadata");
2021
- function _ts_param9(paramIndex, decorator) {
2714
+ __name(_ts_metadata11, "_ts_metadata");
2715
+ function _ts_param10(paramIndex, decorator) {
2022
2716
  return function(target, key) {
2023
2717
  decorator(target, key, paramIndex);
2024
2718
  };
2025
2719
  }
2026
- __name(_ts_param9, "_ts_param");
2720
+ __name(_ts_param10, "_ts_param");
2027
2721
  var ModelsController = class {
2028
2722
  static {
2029
2723
  __name(this, "ModelsController");
@@ -2043,31 +2737,172 @@ var ModelsController = class {
2043
2737
  return this.agent.listModels(actor, agent);
2044
2738
  }
2045
2739
  };
2046
- _ts_decorate10([
2047
- (0, import_common10.Get)(),
2048
- _ts_param9(0, (0, import_common10.Req)()),
2049
- _ts_param9(1, (0, import_common10.Query)("agent")),
2050
- _ts_metadata10("design:type", Function),
2051
- _ts_metadata10("design:paramtypes", [
2740
+ _ts_decorate11([
2741
+ (0, import_common11.Get)(),
2742
+ _ts_param10(0, (0, import_common11.Req)()),
2743
+ _ts_param10(1, (0, import_common11.Query)("agent")),
2744
+ _ts_metadata11("design:type", Function),
2745
+ _ts_metadata11("design:paramtypes", [
2052
2746
  typeof Request === "undefined" ? Object : Request,
2053
2747
  String
2054
2748
  ]),
2055
- _ts_metadata10("design:returntype", Promise)
2749
+ _ts_metadata11("design:returntype", Promise)
2056
2750
  ], ModelsController.prototype, "list", null);
2057
- ModelsController = _ts_decorate10([
2058
- (0, import_common10.Controller)("models"),
2059
- _ts_param9(1, (0, import_common10.Inject)(import_nestjs_agent_core10.AGENT_ACTOR_RESOLVER)),
2060
- _ts_metadata10("design:type", Function),
2061
- _ts_metadata10("design:paramtypes", [
2751
+ ModelsController = _ts_decorate11([
2752
+ (0, import_common11.Controller)("models"),
2753
+ _ts_param10(1, (0, import_common11.Inject)(import_nestjs_agent_core11.AGENT_ACTOR_RESOLVER)),
2754
+ _ts_metadata11("design:type", Function),
2755
+ _ts_metadata11("design:paramtypes", [
2062
2756
  typeof AgentService === "undefined" ? Object : AgentService,
2063
2757
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2064
2758
  ])
2065
2759
  ], ModelsController);
2066
2760
 
2761
+ // src/controller/queue.controller.ts
2762
+ var import_nestjs_agent_core12 = require("@dudousxd/nestjs-agent-core");
2763
+ var import_common12 = require("@nestjs/common");
2764
+ function _ts_decorate12(decorators, target, key, desc) {
2765
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2766
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2767
+ r = Reflect.decorate(decorators, target, key, desc);
2768
+ } else {
2769
+ for (var i = decorators.length - 1; i >= 0; i--) {
2770
+ if (d = decorators[i]) {
2771
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2772
+ }
2773
+ }
2774
+ }
2775
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2776
+ }
2777
+ __name(_ts_decorate12, "_ts_decorate");
2778
+ function _ts_metadata12(metadataKey, metadataValue) {
2779
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2780
+ return Reflect.metadata(metadataKey, metadataValue);
2781
+ }
2782
+ }
2783
+ __name(_ts_metadata12, "_ts_metadata");
2784
+ function _ts_param11(paramIndex, decorator) {
2785
+ return function(target, key) {
2786
+ decorator(target, key, paramIndex);
2787
+ };
2788
+ }
2789
+ __name(_ts_param11, "_ts_param");
2790
+ var QueueController = class {
2791
+ static {
2792
+ __name(this, "QueueController");
2793
+ }
2794
+ agent;
2795
+ actorResolver;
2796
+ constructor(agent, actorResolver) {
2797
+ this.agent = agent;
2798
+ this.actorResolver = actorResolver;
2799
+ }
2800
+ async list(req, id) {
2801
+ return this.agent.getQueue(await this.actorResolver.resolve(req), id);
2802
+ }
2803
+ async clear(req, id) {
2804
+ return this.agent.clearQueue(await this.actorResolver.resolve(req), id);
2805
+ }
2806
+ /** Lift a pause; the head starts when nothing is running. Carries `runId` when it started. */
2807
+ async resume(req, id) {
2808
+ return this.agent.resumeQueue(await this.actorResolver.resolve(req), id);
2809
+ }
2810
+ async update(req, messageId, body) {
2811
+ const actor = await this.actorResolver.resolve(req);
2812
+ if (body.message !== void 0 && typeof body.message !== "string") {
2813
+ throw new import_common12.BadRequestException("message must be a string");
2814
+ }
2815
+ if (body.position !== void 0 && typeof body.position !== "number") {
2816
+ throw new import_common12.BadRequestException("position must be a number");
2817
+ }
2818
+ const attachments = body.attachments === void 0 ? void 0 : body.attachments === null ? null : attachmentRefs(body.attachments);
2819
+ return this.agent.updateQueuedMessage(actor, messageId, {
2820
+ ...body.message !== void 0 ? {
2821
+ message: body.message
2822
+ } : {},
2823
+ ...attachments !== void 0 ? {
2824
+ attachments
2825
+ } : {},
2826
+ ...body.position !== void 0 ? {
2827
+ position: body.position
2828
+ } : {}
2829
+ });
2830
+ }
2831
+ async remove(req, messageId) {
2832
+ return this.agent.removeQueuedMessage(await this.actorResolver.resolve(req), messageId);
2833
+ }
2834
+ };
2835
+ _ts_decorate12([
2836
+ (0, import_common12.Get)("threads/:id/queue"),
2837
+ _ts_param11(0, (0, import_common12.Req)()),
2838
+ _ts_param11(1, (0, import_common12.Param)("id")),
2839
+ _ts_metadata12("design:type", Function),
2840
+ _ts_metadata12("design:paramtypes", [
2841
+ typeof Request === "undefined" ? Object : Request,
2842
+ String
2843
+ ]),
2844
+ _ts_metadata12("design:returntype", Promise)
2845
+ ], QueueController.prototype, "list", null);
2846
+ _ts_decorate12([
2847
+ (0, import_common12.Delete)("threads/:id/queue"),
2848
+ _ts_param11(0, (0, import_common12.Req)()),
2849
+ _ts_param11(1, (0, import_common12.Param)("id")),
2850
+ _ts_metadata12("design:type", Function),
2851
+ _ts_metadata12("design:paramtypes", [
2852
+ typeof Request === "undefined" ? Object : Request,
2853
+ String
2854
+ ]),
2855
+ _ts_metadata12("design:returntype", Promise)
2856
+ ], QueueController.prototype, "clear", null);
2857
+ _ts_decorate12([
2858
+ (0, import_common12.Post)("threads/:id/queue/resume"),
2859
+ _ts_param11(0, (0, import_common12.Req)()),
2860
+ _ts_param11(1, (0, import_common12.Param)("id")),
2861
+ _ts_metadata12("design:type", Function),
2862
+ _ts_metadata12("design:paramtypes", [
2863
+ typeof Request === "undefined" ? Object : Request,
2864
+ String
2865
+ ]),
2866
+ _ts_metadata12("design:returntype", Promise)
2867
+ ], QueueController.prototype, "resume", null);
2868
+ _ts_decorate12([
2869
+ (0, import_common12.Patch)("queue/:messageId"),
2870
+ _ts_param11(0, (0, import_common12.Req)()),
2871
+ _ts_param11(1, (0, import_common12.Param)("messageId")),
2872
+ _ts_param11(2, (0, import_common12.Body)()),
2873
+ _ts_metadata12("design:type", Function),
2874
+ _ts_metadata12("design:paramtypes", [
2875
+ typeof Request === "undefined" ? Object : Request,
2876
+ String,
2877
+ typeof UpdateQueuedMessageBody === "undefined" ? Object : UpdateQueuedMessageBody
2878
+ ]),
2879
+ _ts_metadata12("design:returntype", Promise)
2880
+ ], QueueController.prototype, "update", null);
2881
+ _ts_decorate12([
2882
+ (0, import_common12.Delete)("queue/:messageId"),
2883
+ _ts_param11(0, (0, import_common12.Req)()),
2884
+ _ts_param11(1, (0, import_common12.Param)("messageId")),
2885
+ _ts_metadata12("design:type", Function),
2886
+ _ts_metadata12("design:paramtypes", [
2887
+ typeof Request === "undefined" ? Object : Request,
2888
+ String
2889
+ ]),
2890
+ _ts_metadata12("design:returntype", Promise)
2891
+ ], QueueController.prototype, "remove", null);
2892
+ QueueController = _ts_decorate12([
2893
+ (0, import_common12.Controller)(),
2894
+ _ts_param11(1, (0, import_common12.Inject)(import_nestjs_agent_core12.AGENT_ACTOR_RESOLVER)),
2895
+ _ts_metadata12("design:type", Function),
2896
+ _ts_metadata12("design:paramtypes", [
2897
+ typeof AgentService === "undefined" ? Object : AgentService,
2898
+ typeof ActorResolver === "undefined" ? Object : ActorResolver
2899
+ ])
2900
+ ], QueueController);
2901
+
2067
2902
  // src/controller/quota.controller.ts
2068
- var import_nestjs_agent_core11 = require("@dudousxd/nestjs-agent-core");
2069
- var import_common11 = require("@nestjs/common");
2070
- function _ts_decorate11(decorators, target, key, desc) {
2903
+ var import_nestjs_agent_core13 = require("@dudousxd/nestjs-agent-core");
2904
+ var import_common13 = require("@nestjs/common");
2905
+ function _ts_decorate13(decorators, target, key, desc) {
2071
2906
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2072
2907
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2073
2908
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2080,19 +2915,19 @@ function _ts_decorate11(decorators, target, key, desc) {
2080
2915
  }
2081
2916
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2082
2917
  }
2083
- __name(_ts_decorate11, "_ts_decorate");
2084
- function _ts_metadata11(metadataKey, metadataValue) {
2918
+ __name(_ts_decorate13, "_ts_decorate");
2919
+ function _ts_metadata13(metadataKey, metadataValue) {
2085
2920
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2086
2921
  return Reflect.metadata(metadataKey, metadataValue);
2087
2922
  }
2088
2923
  }
2089
- __name(_ts_metadata11, "_ts_metadata");
2090
- function _ts_param10(paramIndex, decorator) {
2924
+ __name(_ts_metadata13, "_ts_metadata");
2925
+ function _ts_param12(paramIndex, decorator) {
2091
2926
  return function(target, key) {
2092
2927
  decorator(target, key, paramIndex);
2093
2928
  };
2094
2929
  }
2095
- __name(_ts_param10, "_ts_param");
2930
+ __name(_ts_param12, "_ts_param");
2096
2931
  var QuotaController = class {
2097
2932
  static {
2098
2933
  __name(this, "QuotaController");
@@ -2112,29 +2947,29 @@ var QuotaController = class {
2112
2947
  return this.agent.quotaReport(actor);
2113
2948
  }
2114
2949
  };
2115
- _ts_decorate11([
2116
- (0, import_common11.Get)(),
2117
- _ts_param10(0, (0, import_common11.Req)()),
2118
- _ts_metadata11("design:type", Function),
2119
- _ts_metadata11("design:paramtypes", [
2950
+ _ts_decorate13([
2951
+ (0, import_common13.Get)(),
2952
+ _ts_param12(0, (0, import_common13.Req)()),
2953
+ _ts_metadata13("design:type", Function),
2954
+ _ts_metadata13("design:paramtypes", [
2120
2955
  typeof Request === "undefined" ? Object : Request
2121
2956
  ]),
2122
- _ts_metadata11("design:returntype", Promise)
2957
+ _ts_metadata13("design:returntype", Promise)
2123
2958
  ], QuotaController.prototype, "report", null);
2124
- QuotaController = _ts_decorate11([
2125
- (0, import_common11.Controller)("quota"),
2126
- _ts_param10(1, (0, import_common11.Inject)(import_nestjs_agent_core11.AGENT_ACTOR_RESOLVER)),
2127
- _ts_metadata11("design:type", Function),
2128
- _ts_metadata11("design:paramtypes", [
2959
+ QuotaController = _ts_decorate13([
2960
+ (0, import_common13.Controller)("quota"),
2961
+ _ts_param12(1, (0, import_common13.Inject)(import_nestjs_agent_core13.AGENT_ACTOR_RESOLVER)),
2962
+ _ts_metadata13("design:type", Function),
2963
+ _ts_metadata13("design:paramtypes", [
2129
2964
  typeof AgentService === "undefined" ? Object : AgentService,
2130
2965
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2131
2966
  ])
2132
2967
  ], QuotaController);
2133
2968
 
2134
2969
  // src/controller/skills.controller.ts
2135
- var import_nestjs_agent_core12 = require("@dudousxd/nestjs-agent-core");
2136
- var import_common12 = require("@nestjs/common");
2137
- function _ts_decorate12(decorators, target, key, desc) {
2970
+ var import_nestjs_agent_core14 = require("@dudousxd/nestjs-agent-core");
2971
+ var import_common14 = require("@nestjs/common");
2972
+ function _ts_decorate14(decorators, target, key, desc) {
2138
2973
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2139
2974
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2140
2975
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2147,19 +2982,19 @@ function _ts_decorate12(decorators, target, key, desc) {
2147
2982
  }
2148
2983
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2149
2984
  }
2150
- __name(_ts_decorate12, "_ts_decorate");
2151
- function _ts_metadata12(metadataKey, metadataValue) {
2985
+ __name(_ts_decorate14, "_ts_decorate");
2986
+ function _ts_metadata14(metadataKey, metadataValue) {
2152
2987
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2153
2988
  return Reflect.metadata(metadataKey, metadataValue);
2154
2989
  }
2155
2990
  }
2156
- __name(_ts_metadata12, "_ts_metadata");
2157
- function _ts_param11(paramIndex, decorator) {
2991
+ __name(_ts_metadata14, "_ts_metadata");
2992
+ function _ts_param13(paramIndex, decorator) {
2158
2993
  return function(target, key) {
2159
2994
  decorator(target, key, paramIndex);
2160
2995
  };
2161
2996
  }
2162
- __name(_ts_param11, "_ts_param");
2997
+ __name(_ts_param13, "_ts_param");
2163
2998
  var SkillsController = class {
2164
2999
  static {
2165
3000
  __name(this, "SkillsController");
@@ -2175,40 +3010,40 @@ var SkillsController = class {
2175
3010
  return [];
2176
3011
  }
2177
3012
  const actor = await this.actorResolver.resolve(req);
2178
- const offer = await (0, import_nestjs_agent_core12.offerSkills)(this.skills, {
3013
+ const offer = await (0, import_nestjs_agent_core14.offerSkills)(this.skills, {
2179
3014
  actor,
2180
3015
  threadId: threadId ?? ""
2181
3016
  });
2182
3017
  return offer.entries;
2183
3018
  }
2184
3019
  };
2185
- _ts_decorate12([
2186
- (0, import_common12.Get)(),
2187
- _ts_param11(0, (0, import_common12.Req)()),
2188
- _ts_param11(1, (0, import_common12.Query)("threadId")),
2189
- _ts_metadata12("design:type", Function),
2190
- _ts_metadata12("design:paramtypes", [
3020
+ _ts_decorate14([
3021
+ (0, import_common14.Get)(),
3022
+ _ts_param13(0, (0, import_common14.Req)()),
3023
+ _ts_param13(1, (0, import_common14.Query)("threadId")),
3024
+ _ts_metadata14("design:type", Function),
3025
+ _ts_metadata14("design:paramtypes", [
2191
3026
  typeof Request === "undefined" ? Object : Request,
2192
3027
  String
2193
3028
  ]),
2194
- _ts_metadata12("design:returntype", Promise)
3029
+ _ts_metadata14("design:returntype", Promise)
2195
3030
  ], SkillsController.prototype, "list", null);
2196
- SkillsController = _ts_decorate12([
2197
- (0, import_common12.Controller)("skills"),
2198
- _ts_param11(0, (0, import_common12.Inject)(import_nestjs_agent_core12.AGENT_ACTOR_RESOLVER)),
2199
- _ts_param11(1, (0, import_common12.Optional)()),
2200
- _ts_param11(1, (0, import_common12.Inject)(import_nestjs_agent_core12.AGENT_SKILLS)),
2201
- _ts_metadata12("design:type", Function),
2202
- _ts_metadata12("design:paramtypes", [
3031
+ SkillsController = _ts_decorate14([
3032
+ (0, import_common14.Controller)("skills"),
3033
+ _ts_param13(0, (0, import_common14.Inject)(import_nestjs_agent_core14.AGENT_ACTOR_RESOLVER)),
3034
+ _ts_param13(1, (0, import_common14.Optional)()),
3035
+ _ts_param13(1, (0, import_common14.Inject)(import_nestjs_agent_core14.AGENT_SKILLS)),
3036
+ _ts_metadata14("design:type", Function),
3037
+ _ts_metadata14("design:paramtypes", [
2203
3038
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
2204
3039
  Object
2205
3040
  ])
2206
3041
  ], SkillsController);
2207
3042
 
2208
3043
  // src/controller/threads.controller.ts
2209
- var import_nestjs_agent_core13 = require("@dudousxd/nestjs-agent-core");
2210
- var import_common13 = require("@nestjs/common");
2211
- function _ts_decorate13(decorators, target, key, desc) {
3044
+ var import_nestjs_agent_core15 = require("@dudousxd/nestjs-agent-core");
3045
+ var import_common15 = require("@nestjs/common");
3046
+ function _ts_decorate15(decorators, target, key, desc) {
2212
3047
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2213
3048
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2214
3049
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2221,19 +3056,19 @@ function _ts_decorate13(decorators, target, key, desc) {
2221
3056
  }
2222
3057
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2223
3058
  }
2224
- __name(_ts_decorate13, "_ts_decorate");
2225
- function _ts_metadata13(metadataKey, metadataValue) {
3059
+ __name(_ts_decorate15, "_ts_decorate");
3060
+ function _ts_metadata15(metadataKey, metadataValue) {
2226
3061
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2227
3062
  return Reflect.metadata(metadataKey, metadataValue);
2228
3063
  }
2229
3064
  }
2230
- __name(_ts_metadata13, "_ts_metadata");
2231
- function _ts_param12(paramIndex, decorator) {
3065
+ __name(_ts_metadata15, "_ts_metadata");
3066
+ function _ts_param14(paramIndex, decorator) {
2232
3067
  return function(target, key) {
2233
3068
  decorator(target, key, paramIndex);
2234
3069
  };
2235
3070
  }
2236
- __name(_ts_param12, "_ts_param");
3071
+ __name(_ts_param14, "_ts_param");
2237
3072
  var ThreadsController = class {
2238
3073
  static {
2239
3074
  __name(this, "ThreadsController");
@@ -2298,103 +3133,103 @@ var ThreadsController = class {
2298
3133
  return {
2299
3134
  ok: true
2300
3135
  };
2301
- }
2302
- };
2303
- _ts_decorate13([
2304
- (0, import_common13.Get)(),
2305
- _ts_param12(0, (0, import_common13.Req)()),
2306
- _ts_metadata13("design:type", Function),
2307
- _ts_metadata13("design:paramtypes", [
3136
+ }
3137
+ };
3138
+ _ts_decorate15([
3139
+ (0, import_common15.Get)(),
3140
+ _ts_param14(0, (0, import_common15.Req)()),
3141
+ _ts_metadata15("design:type", Function),
3142
+ _ts_metadata15("design:paramtypes", [
2308
3143
  typeof Request === "undefined" ? Object : Request
2309
3144
  ]),
2310
- _ts_metadata13("design:returntype", Promise)
3145
+ _ts_metadata15("design:returntype", Promise)
2311
3146
  ], ThreadsController.prototype, "list", null);
2312
- _ts_decorate13([
2313
- (0, import_common13.Get)(":id"),
2314
- _ts_param12(0, (0, import_common13.Req)()),
2315
- _ts_param12(1, (0, import_common13.Param)("id")),
2316
- _ts_metadata13("design:type", Function),
2317
- _ts_metadata13("design:paramtypes", [
3147
+ _ts_decorate15([
3148
+ (0, import_common15.Get)(":id"),
3149
+ _ts_param14(0, (0, import_common15.Req)()),
3150
+ _ts_param14(1, (0, import_common15.Param)("id")),
3151
+ _ts_metadata15("design:type", Function),
3152
+ _ts_metadata15("design:paramtypes", [
2318
3153
  typeof Request === "undefined" ? Object : Request,
2319
3154
  String
2320
3155
  ]),
2321
- _ts_metadata13("design:returntype", Promise)
3156
+ _ts_metadata15("design:returntype", Promise)
2322
3157
  ], ThreadsController.prototype, "detail", null);
2323
- _ts_decorate13([
2324
- (0, import_common13.Delete)(":id"),
2325
- _ts_param12(0, (0, import_common13.Req)()),
2326
- _ts_param12(1, (0, import_common13.Param)("id")),
2327
- _ts_metadata13("design:type", Function),
2328
- _ts_metadata13("design:paramtypes", [
3158
+ _ts_decorate15([
3159
+ (0, import_common15.Delete)(":id"),
3160
+ _ts_param14(0, (0, import_common15.Req)()),
3161
+ _ts_param14(1, (0, import_common15.Param)("id")),
3162
+ _ts_metadata15("design:type", Function),
3163
+ _ts_metadata15("design:paramtypes", [
2329
3164
  typeof Request === "undefined" ? Object : Request,
2330
3165
  String
2331
3166
  ]),
2332
- _ts_metadata13("design:returntype", Promise)
3167
+ _ts_metadata15("design:returntype", Promise)
2333
3168
  ], ThreadsController.prototype, "remove", null);
2334
- _ts_decorate13([
2335
- (0, import_common13.Post)(":id/fork-from/:messageId"),
2336
- _ts_param12(0, (0, import_common13.Req)()),
2337
- _ts_param12(1, (0, import_common13.Param)("id")),
2338
- _ts_param12(2, (0, import_common13.Param)("messageId")),
2339
- _ts_metadata13("design:type", Function),
2340
- _ts_metadata13("design:paramtypes", [
3169
+ _ts_decorate15([
3170
+ (0, import_common15.Post)(":id/fork-from/:messageId"),
3171
+ _ts_param14(0, (0, import_common15.Req)()),
3172
+ _ts_param14(1, (0, import_common15.Param)("id")),
3173
+ _ts_param14(2, (0, import_common15.Param)("messageId")),
3174
+ _ts_metadata15("design:type", Function),
3175
+ _ts_metadata15("design:paramtypes", [
2341
3176
  typeof Request === "undefined" ? Object : Request,
2342
3177
  String,
2343
3178
  String
2344
3179
  ]),
2345
- _ts_metadata13("design:returntype", Promise)
3180
+ _ts_metadata15("design:returntype", Promise)
2346
3181
  ], ThreadsController.prototype, "fork", null);
2347
- _ts_decorate13([
2348
- (0, import_common13.Patch)(":id"),
2349
- _ts_param12(0, (0, import_common13.Req)()),
2350
- _ts_param12(1, (0, import_common13.Param)("id")),
2351
- _ts_param12(2, (0, import_common13.Body)()),
2352
- _ts_metadata13("design:type", Function),
2353
- _ts_metadata13("design:paramtypes", [
3182
+ _ts_decorate15([
3183
+ (0, import_common15.Patch)(":id"),
3184
+ _ts_param14(0, (0, import_common15.Req)()),
3185
+ _ts_param14(1, (0, import_common15.Param)("id")),
3186
+ _ts_param14(2, (0, import_common15.Body)()),
3187
+ _ts_metadata15("design:type", Function),
3188
+ _ts_metadata15("design:paramtypes", [
2354
3189
  typeof Request === "undefined" ? Object : Request,
2355
3190
  String,
2356
3191
  typeof UpdateThreadBody === "undefined" ? Object : UpdateThreadBody
2357
3192
  ]),
2358
- _ts_metadata13("design:returntype", Promise)
3193
+ _ts_metadata15("design:returntype", Promise)
2359
3194
  ], ThreadsController.prototype, "update", null);
2360
- _ts_decorate13([
2361
- (0, import_common13.Post)(":id/promote"),
2362
- _ts_param12(0, (0, import_common13.Req)()),
2363
- _ts_param12(1, (0, import_common13.Param)("id")),
2364
- _ts_metadata13("design:type", Function),
2365
- _ts_metadata13("design:paramtypes", [
3195
+ _ts_decorate15([
3196
+ (0, import_common15.Post)(":id/promote"),
3197
+ _ts_param14(0, (0, import_common15.Req)()),
3198
+ _ts_param14(1, (0, import_common15.Param)("id")),
3199
+ _ts_metadata15("design:type", Function),
3200
+ _ts_metadata15("design:paramtypes", [
2366
3201
  typeof Request === "undefined" ? Object : Request,
2367
3202
  String
2368
3203
  ]),
2369
- _ts_metadata13("design:returntype", Promise)
3204
+ _ts_metadata15("design:returntype", Promise)
2370
3205
  ], ThreadsController.prototype, "promote", null);
2371
- _ts_decorate13([
2372
- (0, import_common13.Delete)(":id/from/:messageId"),
2373
- _ts_param12(0, (0, import_common13.Req)()),
2374
- _ts_param12(1, (0, import_common13.Param)("id")),
2375
- _ts_param12(2, (0, import_common13.Param)("messageId")),
2376
- _ts_metadata13("design:type", Function),
2377
- _ts_metadata13("design:paramtypes", [
3206
+ _ts_decorate15([
3207
+ (0, import_common15.Delete)(":id/from/:messageId"),
3208
+ _ts_param14(0, (0, import_common15.Req)()),
3209
+ _ts_param14(1, (0, import_common15.Param)("id")),
3210
+ _ts_param14(2, (0, import_common15.Param)("messageId")),
3211
+ _ts_metadata15("design:type", Function),
3212
+ _ts_metadata15("design:paramtypes", [
2378
3213
  typeof Request === "undefined" ? Object : Request,
2379
3214
  String,
2380
3215
  String
2381
3216
  ]),
2382
- _ts_metadata13("design:returntype", Promise)
3217
+ _ts_metadata15("design:returntype", Promise)
2383
3218
  ], ThreadsController.prototype, "truncateFrom", null);
2384
- ThreadsController = _ts_decorate13([
2385
- (0, import_common13.Controller)("threads"),
2386
- _ts_param12(1, (0, import_common13.Inject)(import_nestjs_agent_core13.AGENT_ACTOR_RESOLVER)),
2387
- _ts_metadata13("design:type", Function),
2388
- _ts_metadata13("design:paramtypes", [
3219
+ ThreadsController = _ts_decorate15([
3220
+ (0, import_common15.Controller)("threads"),
3221
+ _ts_param14(1, (0, import_common15.Inject)(import_nestjs_agent_core15.AGENT_ACTOR_RESOLVER)),
3222
+ _ts_metadata15("design:type", Function),
3223
+ _ts_metadata15("design:paramtypes", [
2389
3224
  typeof AgentService === "undefined" ? Object : AgentService,
2390
3225
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2391
3226
  ])
2392
3227
  ], ThreadsController);
2393
3228
 
2394
3229
  // src/controller/tool-call.controller.ts
2395
- var import_nestjs_agent_core14 = require("@dudousxd/nestjs-agent-core");
2396
- var import_common14 = require("@nestjs/common");
2397
- function _ts_decorate14(decorators, target, key, desc) {
3230
+ var import_nestjs_agent_core16 = require("@dudousxd/nestjs-agent-core");
3231
+ var import_common16 = require("@nestjs/common");
3232
+ function _ts_decorate16(decorators, target, key, desc) {
2398
3233
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2399
3234
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2400
3235
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2407,19 +3242,19 @@ function _ts_decorate14(decorators, target, key, desc) {
2407
3242
  }
2408
3243
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2409
3244
  }
2410
- __name(_ts_decorate14, "_ts_decorate");
2411
- function _ts_metadata14(metadataKey, metadataValue) {
3245
+ __name(_ts_decorate16, "_ts_decorate");
3246
+ function _ts_metadata16(metadataKey, metadataValue) {
2412
3247
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2413
3248
  return Reflect.metadata(metadataKey, metadataValue);
2414
3249
  }
2415
3250
  }
2416
- __name(_ts_metadata14, "_ts_metadata");
2417
- function _ts_param13(paramIndex, decorator) {
3251
+ __name(_ts_metadata16, "_ts_metadata");
3252
+ function _ts_param15(paramIndex, decorator) {
2418
3253
  return function(target, key) {
2419
3254
  decorator(target, key, paramIndex);
2420
3255
  };
2421
3256
  }
2422
- __name(_ts_param13, "_ts_param");
3257
+ __name(_ts_param15, "_ts_param");
2423
3258
  var MAX_ANSWERED_QUESTIONS = 100;
2424
3259
  var MAX_VALUES_PER_QUESTION = 100;
2425
3260
  var MAX_ANSWER_VALUE_LENGTH = 4096;
@@ -2428,7 +3263,7 @@ var MAX_VIA_LENGTH = 64;
2428
3263
  var DEFAULT_VIA = "web";
2429
3264
  function toolCallId(claimed) {
2430
3265
  if (typeof claimed !== "string" || claimed.length === 0) {
2431
- throw new import_common14.BadRequestException("toolCallId must be a non-empty string");
3266
+ throw new import_common16.BadRequestException("toolCallId must be a non-empty string");
2432
3267
  }
2433
3268
  return claimed;
2434
3269
  }
@@ -2438,10 +3273,10 @@ function rejectReason(claimed) {
2438
3273
  return void 0;
2439
3274
  }
2440
3275
  if (typeof claimed !== "string") {
2441
- throw new import_common14.BadRequestException("reason must be a string");
3276
+ throw new import_common16.BadRequestException("reason must be a string");
2442
3277
  }
2443
3278
  if (claimed.length > MAX_REJECT_REASON_LENGTH) {
2444
- throw new import_common14.BadRequestException(`reason must be at most ${MAX_REJECT_REASON_LENGTH} characters`);
3279
+ throw new import_common16.BadRequestException(`reason must be at most ${MAX_REJECT_REASON_LENGTH} characters`);
2445
3280
  }
2446
3281
  return claimed;
2447
3282
  }
@@ -2451,7 +3286,7 @@ function remember(claimed) {
2451
3286
  return false;
2452
3287
  }
2453
3288
  if (typeof claimed !== "boolean") {
2454
- throw new import_common14.BadRequestException("remember must be a boolean");
3289
+ throw new import_common16.BadRequestException("remember must be a boolean");
2455
3290
  }
2456
3291
  return claimed;
2457
3292
  }
@@ -2461,7 +3296,7 @@ function via(claimed) {
2461
3296
  return DEFAULT_VIA;
2462
3297
  }
2463
3298
  if (typeof claimed !== "string" || claimed.length === 0 || claimed.length > MAX_VIA_LENGTH) {
2464
- throw new import_common14.BadRequestException(`via must be a string of 1-${MAX_VIA_LENGTH} characters`);
3299
+ throw new import_common16.BadRequestException(`via must be a string of 1-${MAX_VIA_LENGTH} characters`);
2465
3300
  }
2466
3301
  return claimed;
2467
3302
  }
@@ -2471,26 +3306,26 @@ function answers(claimed) {
2471
3306
  return void 0;
2472
3307
  }
2473
3308
  if (typeof claimed !== "object" || claimed === null || Array.isArray(claimed)) {
2474
- throw new import_common14.BadRequestException("answers must be an object of questionId \u2192 chosen values");
3309
+ throw new import_common16.BadRequestException("answers must be an object of questionId \u2192 chosen values");
2475
3310
  }
2476
3311
  const entries = Object.entries(claimed);
2477
3312
  if (entries.length > MAX_ANSWERED_QUESTIONS) {
2478
- throw new import_common14.BadRequestException(`answers may cover at most ${MAX_ANSWERED_QUESTIONS} questions`);
3313
+ throw new import_common16.BadRequestException(`answers may cover at most ${MAX_ANSWERED_QUESTIONS} questions`);
2479
3314
  }
2480
3315
  const validated = /* @__PURE__ */ Object.create(null);
2481
3316
  for (const [questionId, values] of entries) {
2482
3317
  if (!Array.isArray(values)) {
2483
- throw new import_common14.BadRequestException(`answers["${questionId}"] must be an array of chosen values`);
3318
+ throw new import_common16.BadRequestException(`answers["${questionId}"] must be an array of chosen values`);
2484
3319
  }
2485
3320
  if (values.length > MAX_VALUES_PER_QUESTION) {
2486
- throw new import_common14.BadRequestException(`answers["${questionId}"] may carry at most ${MAX_VALUES_PER_QUESTION} values`);
3321
+ throw new import_common16.BadRequestException(`answers["${questionId}"] may carry at most ${MAX_VALUES_PER_QUESTION} values`);
2487
3322
  }
2488
3323
  for (const value of values) {
2489
3324
  if (typeof value !== "string") {
2490
- throw new import_common14.BadRequestException(`answers["${questionId}"] must contain only strings`);
3325
+ throw new import_common16.BadRequestException(`answers["${questionId}"] must contain only strings`);
2491
3326
  }
2492
3327
  if (value.length > MAX_ANSWER_VALUE_LENGTH) {
2493
- throw new import_common14.BadRequestException(`answers["${questionId}"] values must be at most ${MAX_ANSWER_VALUE_LENGTH} characters`);
3328
+ throw new import_common16.BadRequestException(`answers["${questionId}"] values must be at most ${MAX_ANSWER_VALUE_LENGTH} characters`);
2494
3329
  }
2495
3330
  }
2496
3331
  validated[questionId] = values;
@@ -2552,64 +3387,64 @@ var ToolCallController = class {
2552
3387
  };
2553
3388
  }
2554
3389
  };
2555
- _ts_decorate14([
2556
- (0, import_common14.Post)("approve"),
2557
- _ts_param13(0, (0, import_common14.Req)()),
2558
- _ts_param13(1, (0, import_common14.Body)()),
2559
- _ts_metadata14("design:type", Function),
2560
- _ts_metadata14("design:paramtypes", [
3390
+ _ts_decorate16([
3391
+ (0, import_common16.Post)("approve"),
3392
+ _ts_param15(0, (0, import_common16.Req)()),
3393
+ _ts_param15(1, (0, import_common16.Body)()),
3394
+ _ts_metadata16("design:type", Function),
3395
+ _ts_metadata16("design:paramtypes", [
2561
3396
  typeof Request === "undefined" ? Object : Request,
2562
3397
  typeof ApproveBody === "undefined" ? Object : ApproveBody
2563
3398
  ]),
2564
- _ts_metadata14("design:returntype", Promise)
3399
+ _ts_metadata16("design:returntype", Promise)
2565
3400
  ], ToolCallController.prototype, "approve", null);
2566
- _ts_decorate14([
2567
- (0, import_common14.Post)("reject"),
2568
- _ts_param13(0, (0, import_common14.Req)()),
2569
- _ts_param13(1, (0, import_common14.Body)()),
2570
- _ts_metadata14("design:type", Function),
2571
- _ts_metadata14("design:paramtypes", [
3401
+ _ts_decorate16([
3402
+ (0, import_common16.Post)("reject"),
3403
+ _ts_param15(0, (0, import_common16.Req)()),
3404
+ _ts_param15(1, (0, import_common16.Body)()),
3405
+ _ts_metadata16("design:type", Function),
3406
+ _ts_metadata16("design:paramtypes", [
2572
3407
  typeof Request === "undefined" ? Object : Request,
2573
3408
  typeof RejectBody === "undefined" ? Object : RejectBody
2574
3409
  ]),
2575
- _ts_metadata14("design:returntype", Promise)
3410
+ _ts_metadata16("design:returntype", Promise)
2576
3411
  ], ToolCallController.prototype, "reject", null);
2577
- _ts_decorate14([
2578
- (0, import_common14.Post)("answer"),
2579
- _ts_param13(0, (0, import_common14.Req)()),
2580
- _ts_param13(1, (0, import_common14.Body)()),
2581
- _ts_metadata14("design:type", Function),
2582
- _ts_metadata14("design:paramtypes", [
3412
+ _ts_decorate16([
3413
+ (0, import_common16.Post)("answer"),
3414
+ _ts_param15(0, (0, import_common16.Req)()),
3415
+ _ts_param15(1, (0, import_common16.Body)()),
3416
+ _ts_metadata16("design:type", Function),
3417
+ _ts_metadata16("design:paramtypes", [
2583
3418
  typeof Request === "undefined" ? Object : Request,
2584
3419
  typeof AnswerBody === "undefined" ? Object : AnswerBody
2585
3420
  ]),
2586
- _ts_metadata14("design:returntype", Promise)
3421
+ _ts_metadata16("design:returntype", Promise)
2587
3422
  ], ToolCallController.prototype, "answer", null);
2588
- _ts_decorate14([
2589
- (0, import_common14.Post)("skip"),
2590
- _ts_param13(0, (0, import_common14.Req)()),
2591
- _ts_param13(1, (0, import_common14.Body)()),
2592
- _ts_metadata14("design:type", Function),
2593
- _ts_metadata14("design:paramtypes", [
3423
+ _ts_decorate16([
3424
+ (0, import_common16.Post)("skip"),
3425
+ _ts_param15(0, (0, import_common16.Req)()),
3426
+ _ts_param15(1, (0, import_common16.Body)()),
3427
+ _ts_metadata16("design:type", Function),
3428
+ _ts_metadata16("design:paramtypes", [
2594
3429
  typeof Request === "undefined" ? Object : Request,
2595
3430
  Object
2596
3431
  ]),
2597
- _ts_metadata14("design:returntype", Promise)
3432
+ _ts_metadata16("design:returntype", Promise)
2598
3433
  ], ToolCallController.prototype, "skip", null);
2599
- ToolCallController = _ts_decorate14([
2600
- (0, import_common14.Controller)("tool-call"),
2601
- _ts_param13(1, (0, import_common14.Inject)(import_nestjs_agent_core14.AGENT_ACTOR_RESOLVER)),
2602
- _ts_metadata14("design:type", Function),
2603
- _ts_metadata14("design:paramtypes", [
3434
+ ToolCallController = _ts_decorate16([
3435
+ (0, import_common16.Controller)("tool-call"),
3436
+ _ts_param15(1, (0, import_common16.Inject)(import_nestjs_agent_core16.AGENT_ACTOR_RESOLVER)),
3437
+ _ts_metadata16("design:type", Function),
3438
+ _ts_metadata16("design:paramtypes", [
2604
3439
  typeof AgentService === "undefined" ? Object : AgentService,
2605
3440
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2606
3441
  ])
2607
3442
  ], ToolCallController);
2608
3443
 
2609
3444
  // src/controller/tools.controller.ts
2610
- var import_nestjs_agent_core15 = require("@dudousxd/nestjs-agent-core");
2611
- var import_common15 = require("@nestjs/common");
2612
- function _ts_decorate15(decorators, target, key, desc) {
3445
+ var import_nestjs_agent_core17 = require("@dudousxd/nestjs-agent-core");
3446
+ var import_common17 = require("@nestjs/common");
3447
+ function _ts_decorate17(decorators, target, key, desc) {
2613
3448
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2614
3449
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2615
3450
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2622,19 +3457,19 @@ function _ts_decorate15(decorators, target, key, desc) {
2622
3457
  }
2623
3458
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2624
3459
  }
2625
- __name(_ts_decorate15, "_ts_decorate");
2626
- function _ts_metadata15(metadataKey, metadataValue) {
3460
+ __name(_ts_decorate17, "_ts_decorate");
3461
+ function _ts_metadata17(metadataKey, metadataValue) {
2627
3462
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2628
3463
  return Reflect.metadata(metadataKey, metadataValue);
2629
3464
  }
2630
3465
  }
2631
- __name(_ts_metadata15, "_ts_metadata");
2632
- function _ts_param14(paramIndex, decorator) {
3466
+ __name(_ts_metadata17, "_ts_metadata");
3467
+ function _ts_param16(paramIndex, decorator) {
2633
3468
  return function(target, key) {
2634
3469
  decorator(target, key, paramIndex);
2635
3470
  };
2636
3471
  }
2637
- __name(_ts_param14, "_ts_param");
3472
+ __name(_ts_param16, "_ts_param");
2638
3473
  var ToolsController = class {
2639
3474
  static {
2640
3475
  __name(this, "ToolsController");
@@ -2648,11 +3483,11 @@ var ToolsController = class {
2648
3483
  this.agents = agents;
2649
3484
  }
2650
3485
  async list(req, agent) {
2651
- if (agent !== void 0 && agent !== import_nestjs_agent_core15.ALL_AGENTS && this.agents.get(agent) === void 0) {
2652
- throw new import_common15.NotFoundException(`No agent named "${agent}"`);
3486
+ if (agent !== void 0 && agent !== import_nestjs_agent_core17.ALL_AGENTS && this.agents.get(agent) === void 0) {
3487
+ throw new import_common17.NotFoundException(`No agent named "${agent}"`);
2653
3488
  }
2654
3489
  const actor = await this.actorResolver.resolve(req);
2655
- const names = agent === import_nestjs_agent_core15.ALL_AGENTS ? [
3490
+ const names = agent === import_nestjs_agent_core17.ALL_AGENTS ? [
2656
3491
  void 0,
2657
3492
  ...this.agents.list().map((definition) => definition.name)
2658
3493
  ] : [
@@ -2678,33 +3513,33 @@ var ToolsController = class {
2678
3513
  ];
2679
3514
  }
2680
3515
  };
2681
- _ts_decorate15([
2682
- (0, import_common15.Get)(),
2683
- _ts_param14(0, (0, import_common15.Req)()),
2684
- _ts_param14(1, (0, import_common15.Query)("agent")),
2685
- _ts_metadata15("design:type", Function),
2686
- _ts_metadata15("design:paramtypes", [
3516
+ _ts_decorate17([
3517
+ (0, import_common17.Get)(),
3518
+ _ts_param16(0, (0, import_common17.Req)()),
3519
+ _ts_param16(1, (0, import_common17.Query)("agent")),
3520
+ _ts_metadata17("design:type", Function),
3521
+ _ts_metadata17("design:paramtypes", [
2687
3522
  typeof Request === "undefined" ? Object : Request,
2688
3523
  String
2689
3524
  ]),
2690
- _ts_metadata15("design:returntype", Promise)
3525
+ _ts_metadata17("design:returntype", Promise)
2691
3526
  ], ToolsController.prototype, "list", null);
2692
- ToolsController = _ts_decorate15([
2693
- (0, import_common15.Controller)("tools"),
2694
- _ts_param14(0, (0, import_common15.Inject)(import_nestjs_agent_core15.AGENT_ACTOR_RESOLVER)),
2695
- _ts_param14(1, (0, import_common15.Inject)(import_nestjs_agent_core15.AGENT_DEPS_FACTORY)),
2696
- _ts_param14(2, (0, import_common15.Inject)(import_nestjs_agent_core15.AGENT_REGISTRY)),
2697
- _ts_metadata15("design:type", Function),
2698
- _ts_metadata15("design:paramtypes", [
3527
+ ToolsController = _ts_decorate17([
3528
+ (0, import_common17.Controller)("tools"),
3529
+ _ts_param16(0, (0, import_common17.Inject)(import_nestjs_agent_core17.AGENT_ACTOR_RESOLVER)),
3530
+ _ts_param16(1, (0, import_common17.Inject)(import_nestjs_agent_core17.AGENT_DEPS_FACTORY)),
3531
+ _ts_param16(2, (0, import_common17.Inject)(import_nestjs_agent_core17.AGENT_REGISTRY)),
3532
+ _ts_metadata17("design:type", Function),
3533
+ _ts_metadata17("design:paramtypes", [
2699
3534
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
2700
3535
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
2701
- typeof import_nestjs_agent_core15.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core15.AgentRegistry
3536
+ typeof import_nestjs_agent_core17.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core17.AgentRegistry
2702
3537
  ])
2703
3538
  ], ToolsController);
2704
3539
 
2705
3540
  // src/discovery/agent-discovery.service.ts
2706
- var import_nestjs_agent_core16 = require("@dudousxd/nestjs-agent-core");
2707
- var import_common16 = require("@nestjs/common");
3541
+ var import_nestjs_agent_core18 = require("@dudousxd/nestjs-agent-core");
3542
+ var import_common18 = require("@nestjs/common");
2708
3543
  var import_core = require("@nestjs/core");
2709
3544
 
2710
3545
  // src/decorator/agent.decorator.ts
@@ -2739,7 +3574,7 @@ function SystemPromptContributor() {
2739
3574
  __name(SystemPromptContributor, "SystemPromptContributor");
2740
3575
 
2741
3576
  // src/discovery/agent-discovery.service.ts
2742
- function _ts_decorate16(decorators, target, key, desc) {
3577
+ function _ts_decorate18(decorators, target, key, desc) {
2743
3578
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2744
3579
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2745
3580
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2752,19 +3587,19 @@ function _ts_decorate16(decorators, target, key, desc) {
2752
3587
  }
2753
3588
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2754
3589
  }
2755
- __name(_ts_decorate16, "_ts_decorate");
2756
- function _ts_metadata16(metadataKey, metadataValue) {
3590
+ __name(_ts_decorate18, "_ts_decorate");
3591
+ function _ts_metadata18(metadataKey, metadataValue) {
2757
3592
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2758
3593
  return Reflect.metadata(metadataKey, metadataValue);
2759
3594
  }
2760
3595
  }
2761
- __name(_ts_metadata16, "_ts_metadata");
2762
- function _ts_param15(paramIndex, decorator) {
3596
+ __name(_ts_metadata18, "_ts_metadata");
3597
+ function _ts_param17(paramIndex, decorator) {
2763
3598
  return function(target, key) {
2764
3599
  decorator(target, key, paramIndex);
2765
3600
  };
2766
3601
  }
2767
- __name(_ts_param15, "_ts_param");
3602
+ __name(_ts_param17, "_ts_param");
2768
3603
  var AgentDiscoveryService = class _AgentDiscoveryService {
2769
3604
  static {
2770
3605
  __name(this, "AgentDiscoveryService");
@@ -2773,7 +3608,7 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
2773
3608
  scanner;
2774
3609
  registry;
2775
3610
  contributors;
2776
- logger = new import_common16.Logger(_AgentDiscoveryService.name);
3611
+ logger = new import_common18.Logger(_AgentDiscoveryService.name);
2777
3612
  constructor(discovery, scanner, registry, contributors) {
2778
3613
  this.discovery = discovery;
2779
3614
  this.scanner = scanner;
@@ -2891,22 +3726,22 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
2891
3726
  return (ctx) => candidate.call(instance, ctx);
2892
3727
  }
2893
3728
  };
2894
- AgentDiscoveryService = _ts_decorate16([
2895
- (0, import_common16.Injectable)(),
2896
- _ts_param15(2, (0, import_common16.Inject)(import_nestjs_agent_core16.AGENT_REGISTRY)),
2897
- _ts_param15(3, (0, import_common16.Inject)(import_nestjs_agent_core16.AGENT_PROMPT_CONTRIBUTORS)),
2898
- _ts_metadata16("design:type", Function),
2899
- _ts_metadata16("design:paramtypes", [
3729
+ AgentDiscoveryService = _ts_decorate18([
3730
+ (0, import_common18.Injectable)(),
3731
+ _ts_param17(2, (0, import_common18.Inject)(import_nestjs_agent_core18.AGENT_REGISTRY)),
3732
+ _ts_param17(3, (0, import_common18.Inject)(import_nestjs_agent_core18.AGENT_PROMPT_CONTRIBUTORS)),
3733
+ _ts_metadata18("design:type", Function),
3734
+ _ts_metadata18("design:paramtypes", [
2900
3735
  typeof import_core.DiscoveryService === "undefined" ? Object : import_core.DiscoveryService,
2901
3736
  typeof import_core.MetadataScanner === "undefined" ? Object : import_core.MetadataScanner,
2902
- typeof import_nestjs_agent_core16.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core16.AgentRegistry,
3737
+ typeof import_nestjs_agent_core18.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core18.AgentRegistry,
2903
3738
  Array
2904
3739
  ])
2905
3740
  ], AgentDiscoveryService);
2906
3741
 
2907
3742
  // src/discovery/ai-tool-discovery.service.ts
2908
- var import_nestjs_agent_core17 = require("@dudousxd/nestjs-agent-core");
2909
- var import_common17 = require("@nestjs/common");
3743
+ var import_nestjs_agent_core19 = require("@dudousxd/nestjs-agent-core");
3744
+ var import_common19 = require("@nestjs/common");
2910
3745
  var import_core2 = require("@nestjs/core");
2911
3746
  var import_zod = require("zod");
2912
3747
 
@@ -2977,7 +3812,7 @@ function provideAgentTools(factory, inject) {
2977
3812
  __name(provideAgentTools, "provideAgentTools");
2978
3813
 
2979
3814
  // src/discovery/ai-tool-discovery.service.ts
2980
- function _ts_decorate17(decorators, target, key, desc) {
3815
+ function _ts_decorate19(decorators, target, key, desc) {
2981
3816
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2982
3817
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2983
3818
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2990,19 +3825,19 @@ function _ts_decorate17(decorators, target, key, desc) {
2990
3825
  }
2991
3826
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2992
3827
  }
2993
- __name(_ts_decorate17, "_ts_decorate");
2994
- function _ts_metadata17(metadataKey, metadataValue) {
3828
+ __name(_ts_decorate19, "_ts_decorate");
3829
+ function _ts_metadata19(metadataKey, metadataValue) {
2995
3830
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2996
3831
  return Reflect.metadata(metadataKey, metadataValue);
2997
3832
  }
2998
3833
  }
2999
- __name(_ts_metadata17, "_ts_metadata");
3000
- function _ts_param16(paramIndex, decorator) {
3834
+ __name(_ts_metadata19, "_ts_metadata");
3835
+ function _ts_param18(paramIndex, decorator) {
3001
3836
  return function(target, key) {
3002
3837
  decorator(target, key, paramIndex);
3003
3838
  };
3004
3839
  }
3005
- __name(_ts_param16, "_ts_param");
3840
+ __name(_ts_param18, "_ts_param");
3006
3841
  var AiToolDiscoveryService = class _AiToolDiscoveryService {
3007
3842
  static {
3008
3843
  __name(this, "AiToolDiscoveryService");
@@ -3011,7 +3846,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
3011
3846
  registry;
3012
3847
  agents;
3013
3848
  options;
3014
- logger = new import_common17.Logger(_AiToolDiscoveryService.name);
3849
+ logger = new import_common19.Logger(_AiToolDiscoveryService.name);
3015
3850
  constructor(discovery, registry, agents, options) {
3016
3851
  this.discovery = discovery;
3017
3852
  this.registry = registry;
@@ -3096,7 +3931,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
3096
3931
  let delegates = 0;
3097
3932
  for (const definition of this.agents.list()) {
3098
3933
  for (const edge of definition.delegatesTo ?? []) {
3099
- const { agent: target, detached } = (0, import_nestjs_agent_core17.normalizeDelegation)(edge);
3934
+ const { agent: target, detached } = (0, import_nestjs_agent_core19.normalizeDelegation)(edge);
3100
3935
  const targetDefinition = this.agents.get(target);
3101
3936
  if (targetDefinition === void 0) {
3102
3937
  throw new Error(`Agent "${definition.name}" hands off to "${target}", which is not a registered @Agent. Declare it as an @Agent provider or fix the reference.`);
@@ -3146,13 +3981,13 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
3146
3981
  return true;
3147
3982
  }
3148
3983
  };
3149
- AiToolDiscoveryService = _ts_decorate17([
3150
- (0, import_common17.Injectable)(),
3151
- _ts_param16(1, (0, import_common17.Inject)(import_nestjs_agent_core17.AGENT_TOOL_REGISTRY)),
3152
- _ts_param16(2, (0, import_common17.Inject)(import_nestjs_agent_core17.AGENT_REGISTRY)),
3153
- _ts_param16(3, (0, import_common17.Inject)(import_nestjs_agent_core17.AGENT_OPTIONS)),
3154
- _ts_metadata17("design:type", Function),
3155
- _ts_metadata17("design:paramtypes", [
3984
+ AiToolDiscoveryService = _ts_decorate19([
3985
+ (0, import_common19.Injectable)(),
3986
+ _ts_param18(1, (0, import_common19.Inject)(import_nestjs_agent_core19.AGENT_TOOL_REGISTRY)),
3987
+ _ts_param18(2, (0, import_common19.Inject)(import_nestjs_agent_core19.AGENT_REGISTRY)),
3988
+ _ts_param18(3, (0, import_common19.Inject)(import_nestjs_agent_core19.AGENT_OPTIONS)),
3989
+ _ts_metadata19("design:type", Function),
3990
+ _ts_metadata19("design:paramtypes", [
3156
3991
  typeof import_core2.DiscoveryService === "undefined" ? Object : import_core2.DiscoveryService,
3157
3992
  typeof ToolRegistry === "undefined" ? Object : ToolRegistry,
3158
3993
  typeof AgentRegistry === "undefined" ? Object : AgentRegistry,
@@ -3161,13 +3996,13 @@ AiToolDiscoveryService = _ts_decorate17([
3161
3996
  ], AiToolDiscoveryService);
3162
3997
 
3163
3998
  // src/discovery/skill-discovery.service.ts
3164
- var import_nestjs_agent_core19 = require("@dudousxd/nestjs-agent-core");
3165
- var import_common18 = require("@nestjs/common");
3999
+ var import_nestjs_agent_core21 = require("@dudousxd/nestjs-agent-core");
4000
+ var import_common20 = require("@nestjs/common");
3166
4001
  var import_core3 = require("@nestjs/core");
3167
4002
 
3168
4003
  // src/decorator/skill.decorator.ts
3169
4004
  var import_reflect_metadata4 = require("reflect-metadata");
3170
- var import_nestjs_agent_core18 = require("@dudousxd/nestjs-agent-core");
4005
+ var import_nestjs_agent_core20 = require("@dudousxd/nestjs-agent-core");
3171
4006
  var SKILL_METADATA = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:skill-metadata");
3172
4007
  function Skill(options) {
3173
4008
  return (target) => {
@@ -3180,12 +4015,12 @@ function readSkillMetadata(target) {
3180
4015
  }
3181
4016
  __name(readSkillMetadata, "readSkillMetadata");
3182
4017
  function skillScope(options) {
3183
- return options.scope ?? import_nestjs_agent_core18.GLOBAL_SCOPE;
4018
+ return options.scope ?? import_nestjs_agent_core20.GLOBAL_SCOPE;
3184
4019
  }
3185
4020
  __name(skillScope, "skillScope");
3186
4021
 
3187
4022
  // src/discovery/skill-discovery.service.ts
3188
- function _ts_decorate18(decorators, target, key, desc) {
4023
+ function _ts_decorate20(decorators, target, key, desc) {
3189
4024
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3190
4025
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3191
4026
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3198,26 +4033,26 @@ function _ts_decorate18(decorators, target, key, desc) {
3198
4033
  }
3199
4034
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3200
4035
  }
3201
- __name(_ts_decorate18, "_ts_decorate");
3202
- function _ts_metadata18(metadataKey, metadataValue) {
4036
+ __name(_ts_decorate20, "_ts_decorate");
4037
+ function _ts_metadata20(metadataKey, metadataValue) {
3203
4038
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3204
4039
  return Reflect.metadata(metadataKey, metadataValue);
3205
4040
  }
3206
4041
  }
3207
- __name(_ts_metadata18, "_ts_metadata");
3208
- function _ts_param17(paramIndex, decorator) {
4042
+ __name(_ts_metadata20, "_ts_metadata");
4043
+ function _ts_param19(paramIndex, decorator) {
3209
4044
  return function(target, key) {
3210
4045
  decorator(target, key, paramIndex);
3211
4046
  };
3212
4047
  }
3213
- __name(_ts_param17, "_ts_param");
4048
+ __name(_ts_param19, "_ts_param");
3214
4049
  var SkillDiscoveryService = class _SkillDiscoveryService {
3215
4050
  static {
3216
4051
  __name(this, "SkillDiscoveryService");
3217
4052
  }
3218
4053
  discovery;
3219
4054
  declared;
3220
- logger = new import_common18.Logger(_SkillDiscoveryService.name);
4055
+ logger = new import_common20.Logger(_SkillDiscoveryService.name);
3221
4056
  constructor(discovery, declared) {
3222
4057
  this.discovery = discovery;
3223
4058
  this.declared = declared;
@@ -3254,18 +4089,18 @@ var SkillDiscoveryService = class _SkillDiscoveryService {
3254
4089
  return flat === void 0 ? void 0 : () => flat;
3255
4090
  }
3256
4091
  };
3257
- SkillDiscoveryService = _ts_decorate18([
3258
- (0, import_common18.Injectable)(),
3259
- _ts_param17(1, (0, import_common18.Inject)(import_nestjs_agent_core19.AGENT_SKILL_SOURCES)),
3260
- _ts_metadata18("design:type", Function),
3261
- _ts_metadata18("design:paramtypes", [
4092
+ SkillDiscoveryService = _ts_decorate20([
4093
+ (0, import_common20.Injectable)(),
4094
+ _ts_param19(1, (0, import_common20.Inject)(import_nestjs_agent_core21.AGENT_SKILL_SOURCES)),
4095
+ _ts_metadata20("design:type", Function),
4096
+ _ts_metadata20("design:paramtypes", [
3262
4097
  typeof import_core3.DiscoveryService === "undefined" ? Object : import_core3.DiscoveryService,
3263
4098
  Array
3264
4099
  ])
3265
4100
  ], SkillDiscoveryService);
3266
4101
 
3267
4102
  // src/in-process-sink.ts
3268
- var import_nestjs_agent_core20 = require("@dudousxd/nestjs-agent-core");
4103
+ var import_nestjs_agent_core22 = require("@dudousxd/nestjs-agent-core");
3269
4104
  var InProcessTokenStreamSink = class {
3270
4105
  static {
3271
4106
  __name(this, "InProcessTokenStreamSink");
@@ -3320,7 +4155,7 @@ var InProcessTokenStreamSink = class {
3320
4155
  }
3321
4156
  if (buf.ended) {
3322
4157
  if (buf.failure !== void 0) {
3323
- throw new import_nestjs_agent_core20.AgentStreamError(buf.failure);
4158
+ throw new import_nestjs_agent_core22.AgentStreamError(buf.failure);
3324
4159
  }
3325
4160
  return;
3326
4161
  }
@@ -3333,7 +4168,7 @@ var InProcessTokenStreamSink = class {
3333
4168
  };
3334
4169
 
3335
4170
  // src/ledger-quota-provider.ts
3336
- var import_nestjs_agent_core21 = require("@dudousxd/nestjs-agent-core");
4171
+ var import_nestjs_agent_core23 = require("@dudousxd/nestjs-agent-core");
3337
4172
  var LedgerQuotaProvider = class {
3338
4173
  static {
3339
4174
  __name(this, "LedgerQuotaProvider");
@@ -3353,12 +4188,12 @@ var LedgerQuotaProvider = class {
3353
4188
  await this.dayWindow(actorRef, now)
3354
4189
  ];
3355
4190
  if (this.store.usageBetween !== void 0) {
3356
- const range = (0, import_nestjs_agent_core21.quotaPeriodRange)("month", now);
4191
+ const range = (0, import_nestjs_agent_core23.quotaPeriodRange)("month", now);
3357
4192
  const used = await this.store.usageBetween(actorRef, range.fromDay, range.toDay);
3358
4193
  windows.push(this.window("month", used.usedTokens, used.costUsd, range.resetsAt));
3359
4194
  }
3360
- const blocked = (0, import_nestjs_agent_core21.exhaustedWindow)(windows);
3361
- const warning = (0, import_nestjs_agent_core21.quotaWarning)(windows);
4195
+ const blocked = (0, import_nestjs_agent_core23.exhaustedWindow)(windows);
4196
+ const warning = (0, import_nestjs_agent_core23.quotaWarning)(windows);
3362
4197
  return {
3363
4198
  windows,
3364
4199
  ...blocked !== void 0 ? {
@@ -3370,7 +4205,7 @@ var LedgerQuotaProvider = class {
3370
4205
  };
3371
4206
  }
3372
4207
  async dayWindow(actorRef, now) {
3373
- const range = (0, import_nestjs_agent_core21.quotaPeriodRange)("day", now);
4208
+ const range = (0, import_nestjs_agent_core23.quotaPeriodRange)("day", now);
3374
4209
  const { usedTokens, costUsd } = await this.store.quotaToday(actorRef, range.fromDay);
3375
4210
  return this.window("day", usedTokens, costUsd, range.resetsAt);
3376
4211
  }
@@ -3395,9 +4230,9 @@ var LedgerQuotaProvider = class {
3395
4230
  };
3396
4231
 
3397
4232
  // src/runner/inline-agent-runner.ts
3398
- var import_nestjs_agent_core22 = require("@dudousxd/nestjs-agent-core");
3399
- var import_common19 = require("@nestjs/common");
3400
- function _ts_decorate19(decorators, target, key, desc) {
4233
+ var import_nestjs_agent_core24 = require("@dudousxd/nestjs-agent-core");
4234
+ var import_common21 = require("@nestjs/common");
4235
+ function _ts_decorate21(decorators, target, key, desc) {
3401
4236
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3402
4237
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3403
4238
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3410,26 +4245,27 @@ function _ts_decorate19(decorators, target, key, desc) {
3410
4245
  }
3411
4246
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3412
4247
  }
3413
- __name(_ts_decorate19, "_ts_decorate");
3414
- function _ts_metadata19(metadataKey, metadataValue) {
4248
+ __name(_ts_decorate21, "_ts_decorate");
4249
+ function _ts_metadata21(metadataKey, metadataValue) {
3415
4250
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3416
4251
  return Reflect.metadata(metadataKey, metadataValue);
3417
4252
  }
3418
4253
  }
3419
- __name(_ts_metadata19, "_ts_metadata");
3420
- function _ts_param18(paramIndex, decorator) {
4254
+ __name(_ts_metadata21, "_ts_metadata");
4255
+ function _ts_param20(paramIndex, decorator) {
3421
4256
  return function(target, key) {
3422
4257
  decorator(target, key, paramIndex);
3423
4258
  };
3424
4259
  }
3425
- __name(_ts_param18, "_ts_param");
4260
+ __name(_ts_param20, "_ts_param");
3426
4261
  var InlineAgentRunner = class _InlineAgentRunner {
3427
4262
  static {
3428
4263
  __name(this, "InlineAgentRunner");
3429
4264
  }
3430
4265
  factory;
3431
4266
  store;
3432
- logger = new import_common19.Logger(_InlineAgentRunner.name);
4267
+ queue;
4268
+ logger = new import_common21.Logger(_InlineAgentRunner.name);
3433
4269
  pending = /* @__PURE__ */ new Map();
3434
4270
  /**
3435
4271
  * Runs someone has asked to stop. In-process, like `pending`, and for the same reason: this runner
@@ -3437,14 +4273,25 @@ var InlineAgentRunner = class _InlineAgentRunner {
3437
4273
  * running it. A cancelled id is dropped once the run settles, so the set tracks live runs only.
3438
4274
  */
3439
4275
  cancelled = /* @__PURE__ */ new Set();
3440
- constructor(factory, store) {
4276
+ /** Top-level runs this process is running now — what {@link isRunActive} answers from. */
4277
+ live = /* @__PURE__ */ new Set();
4278
+ constructor(factory, store, queue) {
3441
4279
  this.factory = factory;
3442
4280
  this.store = store;
4281
+ this.queue = queue;
3443
4282
  }
3444
- async start(input) {
3445
- const runId = crypto.randomUUID();
4283
+ /**
4284
+ * In-process, so exact: a run this process is not running is not running anywhere — the process
4285
+ * that was running it is gone (a restart), and a thread it still holds is a stale claim.
4286
+ */
4287
+ async isRunActive(runId) {
4288
+ return this.live.has(runId);
4289
+ }
4290
+ async start(input, options = {}) {
4291
+ const runId = options.runId ?? crypto.randomUUID();
3446
4292
  const day = input.day ?? utcDay();
3447
4293
  const deps = this.factory.forAgent(input.agentName);
4294
+ this.live.add(runId);
3448
4295
  const hooks = this.topLevelHooks({
3449
4296
  runId,
3450
4297
  deps,
@@ -3456,20 +4303,21 @@ var InlineAgentRunner = class _InlineAgentRunner {
3456
4303
  ...input.agentName !== void 0 ? [
3457
4304
  input.agentName
3458
4305
  ] : []
3459
- ]
4306
+ ],
4307
+ input
3460
4308
  });
3461
- void (0, import_nestjs_agent_core22.runAgentLoop)({
4309
+ void (0, import_nestjs_agent_core24.runAgentLoop)({
3462
4310
  ...deps,
3463
4311
  day
3464
- }, input, hooks).then(() => this.store.setActiveStream(input.threadId, null)).catch(async (error) => {
3465
- if (error instanceof import_nestjs_agent_core22.RunCancelledError) {
3466
- await this.settleCancelled(runId, input.threadId, deps);
4312
+ }, input, hooks).then(() => (0, import_nestjs_agent_core24.releaseThreadRun)(this.store, input.threadId, runId)).catch(async (error) => {
4313
+ if (error instanceof import_nestjs_agent_core24.RunCancelledError) {
4314
+ await this.settleCancelled(runId, input, deps);
3467
4315
  return;
3468
4316
  }
3469
4317
  const message = error instanceof Error ? error.message : String(error);
3470
- const code = (0, import_nestjs_agent_core22.agentFailureCode)(error);
4318
+ const code = (0, import_nestjs_agent_core24.agentFailureCode)(error);
3471
4319
  this.logger.error(`agent run ${runId} failed (${code}): ${message}`);
3472
- (0, import_nestjs_agent_core22.publishAgentRunFailed)({
4320
+ (0, import_nestjs_agent_core24.publishAgentRunFailed)({
3473
4321
  runId,
3474
4322
  code,
3475
4323
  message
@@ -3480,13 +4328,17 @@ var InlineAgentRunner = class _InlineAgentRunner {
3480
4328
  errorCode: code,
3481
4329
  errorMessage: message
3482
4330
  });
3483
- await this.store.setActiveStream(input.threadId, null);
3484
4331
  const writer = await deps.sink.open(runId);
4332
+ await this.settleQueue(writer, input, runId, "failed", message);
4333
+ await (0, import_nestjs_agent_core24.releaseThreadRun)(this.store, input.threadId, runId);
3485
4334
  await writer.fail({
3486
4335
  code,
3487
4336
  message
3488
4337
  });
3489
- }).finally(() => this.cancelled.delete(runId));
4338
+ }).finally(() => {
4339
+ this.cancelled.delete(runId);
4340
+ this.live.delete(runId);
4341
+ });
3490
4342
  return {
3491
4343
  runId
3492
4344
  };
@@ -3518,7 +4370,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3518
4370
  for (const [key, waiter] of this.pending) {
3519
4371
  if (key.startsWith(`${runId}:`)) {
3520
4372
  this.pending.delete(key);
3521
- waiter.reject(new import_nestjs_agent_core22.RunCancelledError());
4373
+ waiter.reject(new import_nestjs_agent_core24.RunCancelledError());
3522
4374
  }
3523
4375
  }
3524
4376
  await Promise.resolve();
@@ -3529,11 +4381,12 @@ var InlineAgentRunner = class _InlineAgentRunner {
3529
4381
  * the stream ENDED after a `cancelled` frame rather than failed, so a client that retries failed
3530
4382
  * streams does not retry this one.
3531
4383
  */
3532
- async settleCancelled(runId, threadId, deps) {
4384
+ async settleCancelled(runId, input, deps) {
3533
4385
  this.logger.log(`agent run ${runId} cancelled`);
3534
- await this.store.setActiveStream(threadId, null);
3535
4386
  const writer = await deps.sink.open(runId);
3536
- await writer.write((0, import_nestjs_agent_core22.encodeStreamEvent)({
4387
+ await this.settleQueue(writer, input, runId, "cancelled");
4388
+ await (0, import_nestjs_agent_core24.releaseThreadRun)(this.store, input.threadId, runId);
4389
+ await writer.write((0, import_nestjs_agent_core24.encodeStreamEvent)({
3537
4390
  kind: "cancelled"
3538
4391
  }));
3539
4392
  await writer.end();
@@ -3543,6 +4396,38 @@ var InlineAgentRunner = class _InlineAgentRunner {
3543
4396
  });
3544
4397
  }
3545
4398
  /**
4399
+ * Move the thread past a settling TOP-LEVEL run — to the next queued message, which starts here,
4400
+ * or to a paused/empty queue — and write the resulting `queue` frame into this run's stream. A
4401
+ * no-op without a queue-capable store, and for a run that is not a thread's own turn.
4402
+ *
4403
+ * Never throws: the run is settling either way, and a queue that could not be advanced is picked
4404
+ * up by the next send or resume on the thread.
4405
+ */
4406
+ async settleQueue(writer, input, runId, outcome, error) {
4407
+ const queue = this.queue;
4408
+ if (queue === void 0 || !queue.supported || !isThreadTurn(input)) {
4409
+ return;
4410
+ }
4411
+ const settled = outcome === "completed" && this.cancelled.has(runId) ? "cancelled" : outcome;
4412
+ try {
4413
+ const frame = await queue.handoff({
4414
+ threadId: input.threadId,
4415
+ runId,
4416
+ outcome: settled,
4417
+ ...error !== void 0 ? {
4418
+ error
4419
+ } : {}
4420
+ }, (next, nextRunId) => this.start(next, {
4421
+ runId: nextRunId
4422
+ }));
4423
+ if (frame !== void 0) {
4424
+ await writer.write((0, import_nestjs_agent_core24.encodeStreamEvent)(frame));
4425
+ }
4426
+ } catch (failure) {
4427
+ this.logger.error(`could not advance the queue of thread ${input.threadId} after run ${runId}: ${failure instanceof Error ? failure.message : String(failure)}`);
4428
+ }
4429
+ }
4430
+ /**
3546
4431
  * Park a run on a human, keyed by run + tool call. One map for approvals and for question-set
3547
4432
  * answers alike: both wait on the same key, and `signal` cannot tell (or need to tell) which
3548
4433
  * shape it is delivering — the loop asked for one and only ever gets what the caller sent. A
@@ -3587,14 +4472,27 @@ var InlineAgentRunner = class _InlineAgentRunner {
3587
4472
  });
3588
4473
  }
3589
4474
  topLevelHooks(args) {
3590
- const { runId, deps, actor, day, threadId, chainBelow } = args;
4475
+ const { runId, deps, actor, day, threadId, chainBelow, input } = args;
3591
4476
  return {
3592
4477
  runId,
3593
- openSink: /* @__PURE__ */ __name(() => deps.sink.open(runId), "openSink"),
4478
+ // The loop ends the stream when the turn completes. Just before, the thread passes to the next
4479
+ // queued message (or is released), and the reader is told which — so by the time a client
4480
+ // sees the run end, the thread is already free or already running what it queued.
4481
+ openSink: /* @__PURE__ */ __name(async () => {
4482
+ const writer = await deps.sink.open(runId);
4483
+ return this.queue === void 0 ? writer : {
4484
+ write: /* @__PURE__ */ __name((chunk) => writer.write(chunk), "write"),
4485
+ fail: /* @__PURE__ */ __name((error) => writer.fail(error), "fail"),
4486
+ end: /* @__PURE__ */ __name(async () => {
4487
+ await this.settleQueue(writer, input, runId, "completed");
4488
+ await writer.end();
4489
+ }, "end")
4490
+ };
4491
+ }, "openSink"),
3594
4492
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
3595
4493
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
3596
4494
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
3597
- parallel: import_nestjs_agent_core22.settleAll,
4495
+ parallel: import_nestjs_agent_core24.settleAll,
3598
4496
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
3599
4497
  runAgent: /* @__PURE__ */ __name((agentName, task) => this.runNested({
3600
4498
  agentName,
@@ -3645,7 +4543,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3645
4543
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
3646
4544
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
3647
4545
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
3648
- parallel: import_nestjs_agent_core22.settleAll,
4546
+ parallel: import_nestjs_agent_core24.settleAll,
3649
4547
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
3650
4548
  runAgent: /* @__PURE__ */ __name((childName, childTask) => this.runNested({
3651
4549
  agentName: childName,
@@ -3678,7 +4576,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3678
4576
  }
3679
4577
  }), "startAgent")
3680
4578
  };
3681
- void (0, import_nestjs_agent_core22.runAgentLoop)({
4579
+ void (0, import_nestjs_agent_core24.runAgentLoop)({
3682
4580
  ...deps,
3683
4581
  day
3684
4582
  }, {
@@ -3692,13 +4590,13 @@ var InlineAgentRunner = class _InlineAgentRunner {
3692
4590
  parentRunId,
3693
4591
  deliverTo
3694
4592
  }, hooks).catch(async (error) => {
3695
- const cancelled = error instanceof import_nestjs_agent_core22.RunCancelledError;
4593
+ const cancelled = error instanceof import_nestjs_agent_core24.RunCancelledError;
3696
4594
  const message = error instanceof Error ? error.message : String(error);
3697
4595
  if (!cancelled) {
3698
4596
  this.logger.error(`detached agent run ${runId} failed: ${message}`);
3699
- (0, import_nestjs_agent_core22.publishAgentRunFailed)({
4597
+ (0, import_nestjs_agent_core24.publishAgentRunFailed)({
3700
4598
  runId,
3701
- code: (0, import_nestjs_agent_core22.agentFailureCode)(error),
4599
+ code: (0, import_nestjs_agent_core24.agentFailureCode)(error),
3702
4600
  message
3703
4601
  });
3704
4602
  }
@@ -3706,11 +4604,11 @@ var InlineAgentRunner = class _InlineAgentRunner {
3706
4604
  runId,
3707
4605
  status: cancelled ? "cancelled" : "failed",
3708
4606
  ...cancelled ? {} : {
3709
- errorCode: (0, import_nestjs_agent_core22.agentFailureCode)(error),
4607
+ errorCode: (0, import_nestjs_agent_core24.agentFailureCode)(error),
3710
4608
  errorMessage: message
3711
4609
  }
3712
4610
  });
3713
- await (0, import_nestjs_agent_core22.settleUnsettledDelegation)({
4611
+ await (0, import_nestjs_agent_core24.settleUnsettledDelegation)({
3714
4612
  store: this.store,
3715
4613
  delivery: deliverTo,
3716
4614
  agent: agentName,
@@ -3749,7 +4647,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3749
4647
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
3750
4648
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
3751
4649
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
3752
- parallel: import_nestjs_agent_core22.settleAll,
4650
+ parallel: import_nestjs_agent_core24.settleAll,
3753
4651
  // A child stops when it is cancelled OR when the run a human is actually watching is: the
3754
4652
  // canceller names the top-level run, which is the only id that ever left the server.
3755
4653
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId) || this.cancelled.has(sinkRunId), "cancelled"),
@@ -3784,7 +4682,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3784
4682
  }), "startAgent")
3785
4683
  };
3786
4684
  try {
3787
- return await (0, import_nestjs_agent_core22.runAgentLoop)({
4685
+ return await (0, import_nestjs_agent_core24.runAgentLoop)({
3788
4686
  ...deps,
3789
4687
  day
3790
4688
  }, {
@@ -3803,19 +4701,25 @@ var InlineAgentRunner = class _InlineAgentRunner {
3803
4701
  }
3804
4702
  }
3805
4703
  };
3806
- InlineAgentRunner = _ts_decorate19([
3807
- (0, import_common19.Injectable)(),
3808
- _ts_param18(0, (0, import_common19.Inject)(import_nestjs_agent_core22.AGENT_DEPS_FACTORY)),
3809
- _ts_param18(1, (0, import_common19.Inject)(import_nestjs_agent_core22.AGENT_STORE)),
3810
- _ts_metadata19("design:type", Function),
3811
- _ts_metadata19("design:paramtypes", [
4704
+ InlineAgentRunner = _ts_decorate21([
4705
+ (0, import_common21.Injectable)(),
4706
+ _ts_param20(0, (0, import_common21.Inject)(import_nestjs_agent_core24.AGENT_DEPS_FACTORY)),
4707
+ _ts_param20(1, (0, import_common21.Inject)(import_nestjs_agent_core24.AGENT_STORE)),
4708
+ _ts_param20(2, (0, import_common21.Optional)()),
4709
+ _ts_metadata21("design:type", Function),
4710
+ _ts_metadata21("design:paramtypes", [
3812
4711
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
3813
- typeof AgentStore === "undefined" ? Object : AgentStore
4712
+ typeof AgentStore === "undefined" ? Object : AgentStore,
4713
+ typeof ChatQueueService === "undefined" ? Object : ChatQueueService
3814
4714
  ])
3815
4715
  ], InlineAgentRunner);
4716
+ function isThreadTurn(input) {
4717
+ return input.sinkRunId === void 0 && input.deliverTo === void 0;
4718
+ }
4719
+ __name(isThreadTurn, "isThreadTurn");
3816
4720
 
3817
4721
  // src/skills-config.ts
3818
- var import_nestjs_agent_core23 = require("@dudousxd/nestjs-agent-core");
4722
+ var import_nestjs_agent_core25 = require("@dudousxd/nestjs-agent-core");
3819
4723
  function declaredSkillProvider(declared) {
3820
4724
  return {
3821
4725
  list: /* @__PURE__ */ __name(({ scopes }) => declared.filter((skill) => scopes.includes(skill.scope)).map(({ name, description, scope }) => ({
@@ -3841,7 +4745,7 @@ function resolveSkillsConfig(options, declared) {
3841
4745
  declaredSkillProvider(declared)
3842
4746
  ];
3843
4747
  return {
3844
- provider: providers.length === 1 ? providers[0] : (0, import_nestjs_agent_core23.compositeSkillProvider)(providers),
4748
+ provider: providers.length === 1 ? providers[0] : (0, import_nestjs_agent_core25.compositeSkillProvider)(providers),
3845
4749
  ...options.scopes !== void 0 ? {
3846
4750
  scopes: options.scopes
3847
4751
  } : {},
@@ -3853,7 +4757,7 @@ function resolveSkillsConfig(options, declared) {
3853
4757
  __name(resolveSkillsConfig, "resolveSkillsConfig");
3854
4758
 
3855
4759
  // src/agent.module.ts
3856
- function _ts_decorate20(decorators, target, key, desc) {
4760
+ function _ts_decorate22(decorators, target, key, desc) {
3857
4761
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3858
4762
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3859
4763
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3866,13 +4770,13 @@ function _ts_decorate20(decorators, target, key, desc) {
3866
4770
  }
3867
4771
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3868
4772
  }
3869
- __name(_ts_decorate20, "_ts_decorate");
4773
+ __name(_ts_decorate22, "_ts_decorate");
3870
4774
  var DEFAULT_PATH = "agent";
3871
- var logger = new import_common20.Logger("AgentModule");
4775
+ var logger = new import_common22.Logger("AgentModule");
3872
4776
  function externalStoreWrapper(modules) {
3873
4777
  for (const module2 of modules.values()) {
3874
4778
  if (module2.metatype === AgentModule) continue;
3875
- const wrapper = module2.providers.get(import_nestjs_agent_core24.AGENT_STORE);
4779
+ const wrapper = module2.providers.get(import_nestjs_agent_core26.AGENT_STORE);
3876
4780
  if (wrapper !== void 0) return wrapper;
3877
4781
  }
3878
4782
  return void 0;
@@ -3903,7 +4807,7 @@ function resolveStore(options, modules) {
3903
4807
  const external = externalStoreWrapper(modules);
3904
4808
  if (external !== void 0) return forwardingStore(external);
3905
4809
  logger.warn("No `store` configured and no store module imported \u2014 using the in-memory store. Threads are lost on restart and not shared between processes: not for production. Pass `store`, or import a store module (e.g. MikroOrmAgentStoreModule.forFeature()).");
3906
- return new import_nestjs_agent_core24.InMemoryAgentStore();
4810
+ return new import_nestjs_agent_core26.InMemoryAgentStore();
3907
4811
  }
3908
4812
  __name(resolveStore, "resolveStore");
3909
4813
  function isQuotaProvider(quota) {
@@ -3919,99 +4823,99 @@ __name(resolveCatalog, "resolveCatalog");
3919
4823
  function sharedProviders(durable) {
3920
4824
  const providers = [
3921
4825
  {
3922
- provide: import_nestjs_agent_core24.AGENT_TOOL_REGISTRY,
3923
- useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core24.ToolRegistry(), "useFactory")
4826
+ provide: import_nestjs_agent_core26.AGENT_TOOL_REGISTRY,
4827
+ useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core26.ToolRegistry(), "useFactory")
3924
4828
  },
3925
4829
  // Starts empty; AgentDiscoveryService populates it from `@Agent`-decorated providers at boot.
3926
4830
  {
3927
- provide: import_nestjs_agent_core24.AGENT_REGISTRY,
3928
- useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core24.AgentRegistry(), "useFactory")
4831
+ provide: import_nestjs_agent_core26.AGENT_REGISTRY,
4832
+ useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core26.AgentRegistry(), "useFactory")
3929
4833
  },
3930
4834
  // A shared, mutable list AgentDiscoveryService fills with `@SystemPromptContributor()` methods.
3931
4835
  {
3932
- provide: import_nestjs_agent_core24.AGENT_PROMPT_CONTRIBUTORS,
4836
+ provide: import_nestjs_agent_core26.AGENT_PROMPT_CONTRIBUTORS,
3933
4837
  useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
3934
4838
  },
3935
4839
  // Likewise for `@Skill`-decorated providers — filled by SkillDiscoveryService at onModuleInit,
3936
4840
  // read lazily by the AGENT_SKILLS provider below (which DI builds before discovery has run).
3937
4841
  {
3938
- provide: import_nestjs_agent_core24.AGENT_SKILL_SOURCES,
4842
+ provide: import_nestjs_agent_core26.AGENT_SKILL_SOURCES,
3939
4843
  useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
3940
4844
  },
3941
4845
  {
3942
4846
  // One resolution, shared by the loop's deps and the listing endpoint: a second one would
3943
4847
  // drift, and a user would be offered a skill the agent cannot reach. `undefined` when the
3944
4848
  // host configured none — which is what keeps the turn's checkpoint sequence unchanged.
3945
- provide: import_nestjs_agent_core24.AGENT_SKILLS,
4849
+ provide: import_nestjs_agent_core26.AGENT_SKILLS,
3946
4850
  useFactory: /* @__PURE__ */ __name((options, declared) => resolveSkillsConfig(options.skills, declared), "useFactory"),
3947
4851
  inject: [
3948
- import_nestjs_agent_core24.AGENT_OPTIONS,
3949
- import_nestjs_agent_core24.AGENT_SKILL_SOURCES
4852
+ import_nestjs_agent_core26.AGENT_OPTIONS,
4853
+ import_nestjs_agent_core26.AGENT_SKILL_SOURCES
3950
4854
  ]
3951
4855
  },
3952
4856
  {
3953
4857
  // One resolution, shared by the loop's deps and the read-back endpoint: a person has to be
3954
4858
  // shown what the model was shown, and two resolutions would eventually disagree about that.
3955
- provide: import_nestjs_agent_core24.AGENT_MEMORY,
4859
+ provide: import_nestjs_agent_core26.AGENT_MEMORY,
3956
4860
  useFactory: /* @__PURE__ */ __name((options) => options.memory, "useFactory"),
3957
4861
  inject: [
3958
- import_nestjs_agent_core24.AGENT_OPTIONS
4862
+ import_nestjs_agent_core26.AGENT_OPTIONS
3959
4863
  ]
3960
4864
  },
3961
4865
  {
3962
- provide: import_nestjs_agent_core24.AGENT_SINK,
4866
+ provide: import_nestjs_agent_core26.AGENT_SINK,
3963
4867
  useFactory: /* @__PURE__ */ __name((options) => options.sink ?? new InProcessTokenStreamSink(), "useFactory"),
3964
4868
  inject: [
3965
- import_nestjs_agent_core24.AGENT_OPTIONS
4869
+ import_nestjs_agent_core26.AGENT_OPTIONS
3966
4870
  ]
3967
4871
  },
3968
4872
  {
3969
- provide: import_nestjs_agent_core24.AGENT_ROLES_POLICY,
3970
- useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? new import_nestjs_agent_core24.DefaultRolesPolicy(options.defaultRoles), "useFactory"),
4873
+ provide: import_nestjs_agent_core26.AGENT_ROLES_POLICY,
4874
+ useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? new import_nestjs_agent_core26.DefaultRolesPolicy(options.defaultRoles), "useFactory"),
3971
4875
  inject: [
3972
- import_nestjs_agent_core24.AGENT_OPTIONS
4876
+ import_nestjs_agent_core26.AGENT_OPTIONS
3973
4877
  ]
3974
4878
  },
3975
4879
  {
3976
- provide: import_nestjs_agent_core24.AGENT_ACTOR_RESOLVER,
4880
+ provide: import_nestjs_agent_core26.AGENT_ACTOR_RESOLVER,
3977
4881
  useFactory: /* @__PURE__ */ __name((options) => {
3978
4882
  if (options.actorResolver !== void 0) return options.actorResolver;
3979
4883
  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.");
3980
4884
  return new AnonymousActorResolver();
3981
4885
  }, "useFactory"),
3982
4886
  inject: [
3983
- import_nestjs_agent_core24.AGENT_OPTIONS
4887
+ import_nestjs_agent_core26.AGENT_OPTIONS
3984
4888
  ]
3985
4889
  },
3986
4890
  {
3987
- provide: import_nestjs_agent_core24.AGENT_MODEL,
4891
+ provide: import_nestjs_agent_core26.AGENT_MODEL,
3988
4892
  useFactory: /* @__PURE__ */ __name((o) => o.model, "useFactory"),
3989
4893
  inject: [
3990
- import_nestjs_agent_core24.AGENT_OPTIONS
4894
+ import_nestjs_agent_core26.AGENT_OPTIONS
3991
4895
  ]
3992
4896
  },
3993
4897
  {
3994
4898
  // `quota` is either a provider of the host's own or ceilings for the built-in ledger one;
3995
4899
  // omitted, the ledger provider still reports usage, with no ceiling to block on.
3996
- provide: import_nestjs_agent_core24.AGENT_QUOTA_PROVIDER,
4900
+ provide: import_nestjs_agent_core26.AGENT_QUOTA_PROVIDER,
3997
4901
  useFactory: /* @__PURE__ */ __name((o, store) => isQuotaProvider(o.quota) ? o.quota : new LedgerQuotaProvider(store, o.quota?.limits, o.quota?.warnAt !== void 0 ? {
3998
4902
  warnAt: o.quota.warnAt
3999
4903
  } : {}), "useFactory"),
4000
4904
  inject: [
4001
- import_nestjs_agent_core24.AGENT_OPTIONS,
4002
- import_nestjs_agent_core24.AGENT_STORE
4905
+ import_nestjs_agent_core26.AGENT_OPTIONS,
4906
+ import_nestjs_agent_core26.AGENT_STORE
4003
4907
  ]
4004
4908
  },
4005
4909
  {
4006
- provide: import_nestjs_agent_core24.AGENT_MODEL_CATALOG,
4910
+ provide: import_nestjs_agent_core26.AGENT_MODEL_CATALOG,
4007
4911
  useFactory: /* @__PURE__ */ __name((o) => resolveCatalog(o), "useFactory"),
4008
4912
  inject: [
4009
- import_nestjs_agent_core24.AGENT_OPTIONS
4913
+ import_nestjs_agent_core26.AGENT_OPTIONS
4010
4914
  ]
4011
4915
  },
4012
4916
  AgentDepsFactory2,
4013
4917
  {
4014
- provide: import_nestjs_agent_core24.AGENT_DEPS_FACTORY,
4918
+ provide: import_nestjs_agent_core26.AGENT_DEPS_FACTORY,
4015
4919
  useExisting: AgentDepsFactory2
4016
4920
  },
4017
4921
  // Populates the registry + contributors (onModuleInit) BEFORE AiToolDiscoveryService synthesizes
@@ -4019,27 +4923,30 @@ function sharedProviders(durable) {
4019
4923
  AgentDiscoveryService,
4020
4924
  AiToolDiscoveryService,
4021
4925
  SkillDiscoveryService,
4926
+ // The thread message queue — every surface, since both runners and the durable workflow settle
4927
+ // into it, and the chat routes enqueue into it.
4928
+ ChatQueueService,
4022
4929
  InlineAgentRunner,
4023
4930
  AgentService,
4024
4931
  // Bound ALWAYS (durable or inline) — the console's cross-thread approvals inbox routes decisions
4025
4932
  // through AgentService.signalToolCall, which reaches whichever AGENT_RUNNER is bound above.
4026
4933
  AgentApprovalPortAdapter,
4027
4934
  {
4028
- provide: import_nestjs_agent_core24.AGENT_APPROVAL_PORT,
4935
+ provide: import_nestjs_agent_core26.AGENT_APPROVAL_PORT,
4029
4936
  useExisting: AgentApprovalPortAdapter
4030
4937
  }
4031
4938
  ];
4032
4939
  providers.push({
4033
- provide: import_nestjs_agent_core24.AGENT_STORE,
4940
+ provide: import_nestjs_agent_core26.AGENT_STORE,
4034
4941
  useFactory: /* @__PURE__ */ __name((o, modules) => resolveStore(o, modules), "useFactory"),
4035
4942
  inject: [
4036
- import_nestjs_agent_core24.AGENT_OPTIONS,
4943
+ import_nestjs_agent_core26.AGENT_OPTIONS,
4037
4944
  import_core4.ModulesContainer
4038
4945
  ]
4039
4946
  });
4040
4947
  if (durable) {
4041
4948
  providers.push({
4042
- provide: import_nestjs_agent_core24.AGENT_RUNNER,
4949
+ provide: import_nestjs_agent_core26.AGENT_RUNNER,
4043
4950
  useFactory: /* @__PURE__ */ __name((durableRunner) => {
4044
4951
  if (durableRunner === void 0) {
4045
4952
  throw new Error("AgentModule.forRoot({ durable: true }) requires importing AgentDurableModule from '@dudousxd/nestjs-agent/durable' (alongside a configured DurableModule). It was not found.");
@@ -4048,14 +4955,14 @@ function sharedProviders(durable) {
4048
4955
  }, "useFactory"),
4049
4956
  inject: [
4050
4957
  {
4051
- token: import_nestjs_agent_core24.AGENT_DURABLE_RUNNER,
4958
+ token: import_nestjs_agent_core26.AGENT_DURABLE_RUNNER,
4052
4959
  optional: true
4053
4960
  }
4054
4961
  ]
4055
4962
  });
4056
4963
  } else {
4057
4964
  providers.push({
4058
- provide: import_nestjs_agent_core24.AGENT_RUNNER,
4965
+ provide: import_nestjs_agent_core26.AGENT_RUNNER,
4059
4966
  useExisting: InlineAgentRunner
4060
4967
  });
4061
4968
  }
@@ -4064,29 +4971,31 @@ function sharedProviders(durable) {
4064
4971
  __name(sharedProviders, "sharedProviders");
4065
4972
  function exportsFor() {
4066
4973
  return [
4067
- import_nestjs_agent_core24.AGENT_OPTIONS,
4068
- import_nestjs_agent_core24.AGENT_TOOL_REGISTRY,
4069
- import_nestjs_agent_core24.AGENT_REGISTRY,
4070
- import_nestjs_agent_core24.AGENT_SINK,
4071
- import_nestjs_agent_core24.AGENT_ROLES_POLICY,
4072
- import_nestjs_agent_core24.AGENT_ACTOR_RESOLVER,
4073
- import_nestjs_agent_core24.AGENT_MODEL,
4074
- import_nestjs_agent_core24.AGENT_STORE,
4075
- import_nestjs_agent_core24.AGENT_MODEL_CATALOG,
4076
- import_nestjs_agent_core24.AGENT_QUOTA_PROVIDER,
4077
- import_nestjs_agent_core24.AGENT_PROMPT_CONTRIBUTORS,
4078
- import_nestjs_agent_core24.AGENT_SKILLS,
4079
- import_nestjs_agent_core24.AGENT_MEMORY,
4080
- import_nestjs_agent_core24.AGENT_DEPS_FACTORY,
4974
+ import_nestjs_agent_core26.AGENT_OPTIONS,
4975
+ import_nestjs_agent_core26.AGENT_TOOL_REGISTRY,
4976
+ import_nestjs_agent_core26.AGENT_REGISTRY,
4977
+ import_nestjs_agent_core26.AGENT_SINK,
4978
+ import_nestjs_agent_core26.AGENT_ROLES_POLICY,
4979
+ import_nestjs_agent_core26.AGENT_ACTOR_RESOLVER,
4980
+ import_nestjs_agent_core26.AGENT_MODEL,
4981
+ import_nestjs_agent_core26.AGENT_STORE,
4982
+ import_nestjs_agent_core26.AGENT_MODEL_CATALOG,
4983
+ import_nestjs_agent_core26.AGENT_QUOTA_PROVIDER,
4984
+ import_nestjs_agent_core26.AGENT_PROMPT_CONTRIBUTORS,
4985
+ import_nestjs_agent_core26.AGENT_SKILLS,
4986
+ import_nestjs_agent_core26.AGENT_MEMORY,
4987
+ import_nestjs_agent_core26.AGENT_DEPS_FACTORY,
4081
4988
  AgentDepsFactory2,
4082
4989
  AgentService,
4990
+ ChatQueueService,
4083
4991
  InlineAgentRunner,
4084
- import_nestjs_agent_core24.AGENT_APPROVAL_PORT
4992
+ import_nestjs_agent_core26.AGENT_APPROVAL_PORT
4085
4993
  ];
4086
4994
  }
4087
4995
  __name(exportsFor, "exportsFor");
4088
4996
  var BASE_CONTROLLERS = [
4089
4997
  ChatController,
4998
+ QueueController,
4090
4999
  ThreadsController,
4091
5000
  ToolCallController,
4092
5001
  QuotaController,
@@ -4144,7 +5053,7 @@ var AgentModule = class _AgentModule {
4144
5053
  controllers: controllersForSurface(options.surface),
4145
5054
  providers: [
4146
5055
  {
4147
- provide: import_nestjs_agent_core24.AGENT_OPTIONS,
5056
+ provide: import_nestjs_agent_core26.AGENT_OPTIONS,
4148
5057
  useValue: options
4149
5058
  },
4150
5059
  ...sharedProviders(options.durable ?? false),
@@ -4167,7 +5076,7 @@ var AgentModule = class _AgentModule {
4167
5076
  controllers: controllersForSurface(options.surface),
4168
5077
  providers: [
4169
5078
  {
4170
- provide: import_nestjs_agent_core24.AGENT_OPTIONS,
5079
+ provide: import_nestjs_agent_core26.AGENT_OPTIONS,
4171
5080
  // Stamp the STATIC wiring flags onto the factory result: `durable`/`surface` are
4172
5081
  // authoritative on the async config object (they decided the actual wiring above), and
4173
5082
  // the durable module reads `durable` back off AGENT_OPTIONS. `surface` isn't read back by
@@ -4188,13 +5097,13 @@ var AgentModule = class _AgentModule {
4188
5097
  };
4189
5098
  }
4190
5099
  };
4191
- AgentModule = _ts_decorate20([
4192
- (0, import_common20.Global)(),
4193
- (0, import_common20.Module)({})
5100
+ AgentModule = _ts_decorate22([
5101
+ (0, import_common22.Global)(),
5102
+ (0, import_common22.Module)({})
4194
5103
  ], AgentModule);
4195
5104
 
4196
5105
  // src/resolver/header-actor-resolver.ts
4197
- var import_common21 = require("@nestjs/common");
5106
+ var import_common23 = require("@nestjs/common");
4198
5107
  function readHeader(req, name) {
4199
5108
  if (typeof req !== "object" || req === null || !("headers" in req)) return void 0;
4200
5109
  const { headers } = req;
@@ -4210,7 +5119,7 @@ var HeaderActorResolver = class {
4210
5119
  resolve(req) {
4211
5120
  const id = readHeader(req, "x-actor-id");
4212
5121
  if (id === void 0 || id.length === 0) {
4213
- throw new import_common21.UnauthorizedException("HeaderActorResolver: missing x-actor-id header. No default actor is fabricated. Send x-actor-id from a trusted gateway, or configure AgentModule.forRoot({ actorResolver }) with a resolver that reads your authenticated principal.");
5122
+ throw new import_common23.UnauthorizedException("HeaderActorResolver: missing x-actor-id header. No default actor is fabricated. Send x-actor-id from a trusted gateway, or configure AgentModule.forRoot({ actorResolver }) with a resolver that reads your authenticated principal.");
4214
5123
  }
4215
5124
  const roles = (readHeader(req, "x-actor-role") ?? "").split(",").map((role) => role.trim()).filter((role) => role.length > 0);
4216
5125
  const tenantRef = readHeader(req, "x-tenant-ref");
@@ -4225,7 +5134,7 @@ var HeaderActorResolver = class {
4225
5134
  };
4226
5135
 
4227
5136
  // src/resolver/request-user-actor-resolver.ts
4228
- var import_common22 = require("@nestjs/common");
5137
+ var import_common24 = require("@nestjs/common");
4229
5138
  function field(user, ...names) {
4230
5139
  for (const name of names) {
4231
5140
  const value = user[name];
@@ -4237,7 +5146,7 @@ __name(field, "field");
4237
5146
  function defaultRequestUserMapper(user) {
4238
5147
  const id = field(user, "id", "sub", "_id", "userId");
4239
5148
  if (id === void 0) {
4240
- throw new import_common22.UnauthorizedException("requestUserActorResolver: req.user has no id/sub/_id/userId \u2014 pass a mapper: requestUserActorResolver((user) => ({ id: \u2026, roles: \u2026 }))");
5149
+ throw new import_common24.UnauthorizedException("requestUserActorResolver: req.user has no id/sub/_id/userId \u2014 pass a mapper: requestUserActorResolver((user) => ({ id: \u2026, roles: \u2026 }))");
4241
5150
  }
4242
5151
  const rawRoles = field(user, "roles", "role");
4243
5152
  const roles = Array.isArray(rawRoles) ? rawRoles.map(String) : typeof rawRoles === "string" ? [
@@ -4258,7 +5167,7 @@ function requestUserActorResolver(map) {
4258
5167
  async resolve(req) {
4259
5168
  const user = typeof req === "object" && req !== null ? req.user : void 0;
4260
5169
  if (user === void 0 || user === null || user === false) {
4261
- throw new import_common22.UnauthorizedException("Sign in to use the agent.");
5170
+ throw new import_common24.UnauthorizedException("Sign in to use the agent.");
4262
5171
  }
4263
5172
  if (map !== void 0) return map(user, req);
4264
5173
  return defaultRequestUserMapper(user);
@@ -4285,6 +5194,7 @@ __reExport(index_exports, require("@dudousxd/nestjs-agent-core"), module.exports
4285
5194
  AiToolDiscoveryService,
4286
5195
  AnonymousActorResolver,
4287
5196
  AttachmentsController,
5197
+ ChatQueueService,
4288
5198
  ConfigController,
4289
5199
  DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES,
4290
5200
  DEFAULT_MAX_ATTACHMENT_BYTES,
@@ -4296,6 +5206,7 @@ __reExport(index_exports, require("@dudousxd/nestjs-agent-core"), module.exports
4296
5206
  MemoriesController,
4297
5207
  MessagesController,
4298
5208
  ModelsController,
5209
+ QueueController,
4299
5210
  SKILL_METADATA,
4300
5211
  SYSTEM_PROMPT_CONTRIBUTOR_METADATA,
4301
5212
  SYSTEM_PROMPT_METADATA,