@dudousxd/nestjs-agent 1.14.0 → 1.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,297 @@ 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
+ /**
1190
+ * `POST <base>/queue/:messageId/interrupt` — run a message that is already waiting NOW: it moves
1191
+ * to the head of its queue marked as an interrupt, any pause is lifted, and the running turn is
1192
+ * cancelled (its settle starts this message — the same path a `mode: 'interrupt'` send takes).
1193
+ * With nothing running, the message starts at once.
1194
+ *
1195
+ * One request, and the message never leaves the queue: a client that removed it and sent it again
1196
+ * would lose it if the second call failed, and would run it twice if another tab's drain started
1197
+ * it in between. Answers the queue, plus `interrupting` (the run that was cancelled) or `runId`
1198
+ * (the run this message started).
1199
+ */
1200
+ async interruptQueuedMessage(actor, messageId) {
1201
+ const queue = this.requireQueue();
1202
+ const store = queue.queueStore();
1203
+ const threadId = await this.assertOwnsQueuedMessage(actor, messageId);
1204
+ const gone = /* @__PURE__ */ __name(() => new import_common3.GoneException(`queued message ${messageId} already started or was removed`), "gone");
1205
+ const marked = await store.updateQueuedMessage(messageId, {
1206
+ interrupt: true
1207
+ });
1208
+ if (marked === null) {
1209
+ throw gone();
1210
+ }
1211
+ if (marked.interrupt !== true) {
1212
+ throw new import_common3.NotImplementedException("Interrupting a queued message requires a ChatQueueStore whose updateQueuedMessage stores `interrupt`; the bound store ignored it.");
1213
+ }
1214
+ if (!await store.moveQueuedMessage(messageId, 0)) {
1215
+ throw gone();
1216
+ }
1217
+ await store.setQueuePause(threadId, null);
1218
+ const { live } = await queue.holder(threadId, this.runner);
1219
+ if (live !== null && live !== messageId && await store.getQueuedMessage(messageId) !== null) {
1220
+ const state2 = await queue.publish(threadId);
1221
+ await this.runner.cancel(live);
1222
+ return {
1223
+ ...state2,
1224
+ interrupting: live
1225
+ };
1226
+ }
1227
+ if (live !== null) {
1228
+ return {
1229
+ ...await queue.state(threadId),
1230
+ runId: messageId
1231
+ };
1232
+ }
1233
+ const runId = await queue.kick(threadId, this.runner);
1234
+ const state = runId === void 0 ? await queue.publish(threadId) : await queue.state(threadId);
1235
+ return {
1236
+ ...state,
1237
+ ...runId !== void 0 ? {
1238
+ runId
1239
+ } : {}
1240
+ };
1241
+ }
1242
+ /** `DELETE <base>/threads/:id/queue` — drop every waiting message (and any pause). */
1243
+ async clearQueue(actor, threadId) {
1244
+ await this.assertOwnsThread(actor, threadId);
1245
+ const queue = this.requireQueue();
1246
+ await queue.queueStore().clearQueue(threadId);
1247
+ await queue.queueStore().setQueuePause(threadId, null);
1248
+ return queue.publish(threadId);
1249
+ }
1250
+ /**
1251
+ * `POST <base>/threads/:id/queue/resume` — lift a pause and start the head when nothing is
1252
+ * running. Answers the queue, and the run the head started under, if it did.
1253
+ */
1254
+ async resumeQueue(actor, threadId) {
1255
+ await this.assertOwnsThread(actor, threadId);
1256
+ const queue = this.requireQueue();
1257
+ await queue.queueStore().setQueuePause(threadId, null);
1258
+ const runId = await queue.kick(threadId, this.runner);
1259
+ const state = runId === void 0 ? await queue.publish(threadId) : await queue.state(threadId);
1260
+ return {
1261
+ ...state,
1262
+ ...runId !== void 0 ? {
1263
+ runId
1264
+ } : {}
1265
+ };
1266
+ }
1267
+ /** The thread a queued message waits on, once the caller is shown to own it. */
1268
+ async assertOwnsQueuedMessage(actor, messageId) {
1269
+ const message = await this.requireQueue().queueStore().getQueuedMessage(messageId);
1270
+ if (message === null) {
1271
+ throw new import_common3.NotFoundException(`queued message ${messageId} not found`);
1272
+ }
1273
+ await this.assertOwnsThread(actor, message.threadId);
1274
+ return message.threadId;
1275
+ }
1276
+ /**
1277
+ * Rebuild this turn's attachments from the staging store, keyed by the ids the caller claimed.
1278
+ * The model provider fetches {@link MessageAttachment.url} verbatim, so that url is only ever
1279
+ * allowed to come from the host's own store — a caller that could name it could point the server
1280
+ * at anything it can reach (cloud metadata, internal services) and read the response back out of
1281
+ * the model's answer.
1282
+ *
1283
+ * No store bound means no way to tell an id the actor owns from one they don't, so a turn simply
1284
+ * cannot carry attachments: 501 rather than trusting the request.
1285
+ */
1286
+ async resolveAttachments(actor, refs) {
1287
+ if (refs.length === 0) {
1288
+ return [];
1289
+ }
1290
+ const staging = this.staging;
1291
+ if (staging === void 0 || typeof staging.resolve !== "function") {
1292
+ throw new import_common3.NotImplementedException("Message attachments require an AGENT_ATTACHMENT_STAGING provider implementing resolve(); attachment urls are never taken from the request.");
1293
+ }
1294
+ const resolved = [];
1295
+ for (const ref of refs) {
1296
+ const attachment = await staging.resolve({
1297
+ mediaId: ref.mediaId,
1298
+ actor
1299
+ });
1300
+ if (attachment === null) {
1301
+ throw new import_common3.ForbiddenException(`attachment ${ref.mediaId} is not available to this actor`);
1302
+ }
1303
+ resolved.push(attachment);
1304
+ }
1305
+ return resolved;
1306
+ }
1307
+ /**
1308
+ * The run's live token stream, WITHOUT an ownership check — for in-process callers that are
1309
+ * already authorized (the MCP bridge, a host's own job code), the same split as
1310
+ * {@link signalToolCall} vs {@link approve}. Anything reachable from a request must go through
1311
+ * {@link subscribeAs} instead: a runId is the only thing standing between a caller and another
1312
+ * actor's answer, tool arguments and tool results.
1313
+ */
1314
+ subscribe(runId) {
1315
+ return this.deps.forAgent().sink.subscribe(runId);
1316
+ }
1317
+ /**
1318
+ * {@link subscribe}, gated the way {@link cancel} is: only the actor whose thread is currently
1319
+ * streaming this run may read it. A run that has already finished is reported missing rather than
1320
+ * replayed — the runner clears the thread's active stream as the run ends, and that field is what
1321
+ * ownership is derived from.
1322
+ */
1323
+ async subscribeAs(actor, runId) {
1324
+ await this.assertOwnsActiveStream(actor, runId);
610
1325
  return this.subscribe(runId);
611
1326
  }
612
1327
  /**
@@ -732,7 +1447,7 @@ var AgentService = class {
732
1447
  return;
733
1448
  }
734
1449
  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.");
1450
+ 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
1451
  }
737
1452
  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
1453
  await this.store.updateThread(threadId, {
@@ -750,10 +1465,10 @@ var AgentService = class {
750
1465
  validateTitle(title) {
751
1466
  const trimmed = title.trim();
752
1467
  if (trimmed.length === 0) {
753
- throw new import_common2.BadRequestException("title must not be empty");
1468
+ throw new import_common3.BadRequestException("title must not be empty");
754
1469
  }
755
1470
  if (trimmed.length > 200) {
756
- throw new import_common2.BadRequestException("title must be at most 200 characters");
1471
+ throw new import_common3.BadRequestException("title must be at most 200 characters");
757
1472
  }
758
1473
  return trimmed;
759
1474
  }
@@ -797,9 +1512,13 @@ var AgentService = class {
797
1512
  }
798
1513
  async toDetailView(thread, actor) {
799
1514
  const summary = await this.toSummaryView(thread);
1515
+ const queue = this.queueing();
800
1516
  return {
801
1517
  ...summary,
802
- messages: await this.freshAttachmentUrls(thread.messages, actor)
1518
+ messages: await this.freshAttachmentUrls(thread.messages, actor),
1519
+ ...queue !== void 0 ? {
1520
+ queue: await queue.state(thread.id)
1521
+ } : {}
803
1522
  };
804
1523
  }
805
1524
  /**
@@ -852,21 +1571,21 @@ var AgentService = class {
852
1571
  */
853
1572
  async setMessageFeedback(actor, messageId, input) {
854
1573
  if (input.value !== null && input.value !== "up" && input.value !== "down") {
855
- throw new import_common2.BadRequestException("value must be 'up', 'down' or null");
1574
+ throw new import_common3.BadRequestException("value must be 'up', 'down' or null");
856
1575
  }
857
1576
  if (input.comment !== void 0 && typeof input.comment !== "string") {
858
- throw new import_common2.BadRequestException("comment must be a string");
1577
+ throw new import_common3.BadRequestException("comment must be a string");
859
1578
  }
860
1579
  const comment = input.comment?.trim();
861
1580
  if (comment !== void 0 && comment.length > 2e3) {
862
- throw new import_common2.BadRequestException("comment must be at most 2000 characters");
1581
+ throw new import_common3.BadRequestException("comment must be at most 2000 characters");
863
1582
  }
864
1583
  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.");
1584
+ throw new import_common3.NotImplementedException("Message feedback requires an AgentStore that implements threadOfMessage() and setMessageFeedback(); the bound store does not support it.");
866
1585
  }
867
1586
  const threadId = await this.store.threadOfMessage(messageId);
868
1587
  if (threadId === null) {
869
- throw new import_common2.NotFoundException(`message ${messageId} not found`);
1588
+ throw new import_common3.NotFoundException(`message ${messageId} not found`);
870
1589
  }
871
1590
  await this.assertOwnsThread(actor, threadId);
872
1591
  const feedback = input.value === null ? null : {
@@ -914,7 +1633,7 @@ var AgentService = class {
914
1633
  const list = this.attachmentInventory();
915
1634
  const referencedMediaIds = this.store.referencedMediaIds?.bind(this.store);
916
1635
  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.");
1636
+ 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
1637
  }
919
1638
  const stagedBefore = options.olderThan.toISOString();
920
1639
  const inventory = await list({
@@ -936,7 +1655,7 @@ var AgentService = class {
936
1655
  attachmentInventory() {
937
1656
  const list = this.staging?.list?.bind(this.staging);
938
1657
  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.");
1658
+ 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
1659
  }
941
1660
  return list;
942
1661
  }
@@ -947,10 +1666,10 @@ var AgentService = class {
947
1666
  async assertOwnsThread(actor, threadId) {
948
1667
  const owner = await this.store.ownerOfThread(threadId);
949
1668
  if (owner === null) {
950
- throw new import_common2.NotFoundException(`thread ${threadId} not found`);
1669
+ throw new import_common3.NotFoundException(`thread ${threadId} not found`);
951
1670
  }
952
1671
  if (owner !== actor.id) {
953
- throw new import_common2.ForbiddenException("thread belongs to another actor");
1672
+ throw new import_common3.ForbiddenException("thread belongs to another actor");
954
1673
  }
955
1674
  }
956
1675
  /**
@@ -961,10 +1680,10 @@ var AgentService = class {
961
1680
  async assertOwnsToolCall(actor, toolCallId2) {
962
1681
  const owner = await this.store.ownerOfToolCall(toolCallId2);
963
1682
  if (owner === null) {
964
- throw new import_common2.NotFoundException(`tool call ${toolCallId2} not found`);
1683
+ throw new import_common3.NotFoundException(`tool call ${toolCallId2} not found`);
965
1684
  }
966
1685
  if (owner !== actor.id) {
967
- throw new import_common2.ForbiddenException("tool call belongs to another actor");
1686
+ throw new import_common3.ForbiddenException("tool call belongs to another actor");
968
1687
  }
969
1688
  }
970
1689
  /**
@@ -979,12 +1698,12 @@ var AgentService = class {
979
1698
  if (this.store.toolCallInput === void 0) {
980
1699
  return;
981
1700
  }
982
- const questions = (0, import_nestjs_agent_core3.readElicitationQuestions)(await this.store.toolCallInput(toolCallId2));
1701
+ const questions = (0, import_nestjs_agent_core4.readElicitationQuestions)(await this.store.toolCallInput(toolCallId2));
983
1702
  for (const question of questions) {
984
1703
  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 ?? []);
1704
+ const problem = (0, import_nestjs_agent_core4.validateElicitationAnswer)(question, submitted ?? question.defaults ?? []);
986
1705
  if (problem !== null) {
987
- throw new import_common2.BadRequestException(`answers["${question.id}"] ${problem}`);
1706
+ throw new import_common3.BadRequestException(`answers["${question.id}"] ${problem}`);
988
1707
  }
989
1708
  }
990
1709
  }
@@ -996,21 +1715,21 @@ var AgentService = class {
996
1715
  */
997
1716
  async assertMayDecide(actor, toolCallId2) {
998
1717
  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) {
1718
+ const approver = approval?.approver ?? import_nestjs_agent_core4.REQUESTER_APPROVER;
1719
+ if (approver === import_nestjs_agent_core4.REQUESTER_APPROVER) {
1001
1720
  return this.assertOwnsToolCall(actor, toolCallId2);
1002
1721
  }
1003
1722
  const requesterRef = await this.store.ownerOfToolCall(toolCallId2);
1004
1723
  if (requesterRef === null) {
1005
- throw new import_common2.NotFoundException(`tool call ${toolCallId2} not found`);
1724
+ throw new import_common3.NotFoundException(`tool call ${toolCallId2} not found`);
1006
1725
  }
1007
- const allowed = await (0, import_nestjs_agent_core3.mayDecideApproval)(this.deps.forAgent().approvalPolicy, actor, {
1726
+ const allowed = await (0, import_nestjs_agent_core4.mayDecideApproval)(this.deps.forAgent().approvalPolicy, actor, {
1008
1727
  toolCallId: toolCallId2,
1009
1728
  approver,
1010
1729
  requesterRef
1011
1730
  });
1012
1731
  if (!allowed) {
1013
- throw new import_common2.ForbiddenException(`this approval is for ${approver}`);
1732
+ throw new import_common3.ForbiddenException(`this approval is for ${approver}`);
1014
1733
  }
1015
1734
  }
1016
1735
  /**
@@ -1026,7 +1745,7 @@ var AgentService = class {
1026
1745
  }
1027
1746
  const lapsed = approval.status === "expired" || approval.status === "pending_approval" && approval.expiresAt !== null && Date.parse(approval.expiresAt) <= Date.now();
1028
1747
  if (lapsed) {
1029
- throw new import_common2.GoneException(`the approval request for tool call ${toolCallId2} has expired`);
1748
+ throw new import_common3.GoneException(`the approval request for tool call ${toolCallId2} has expired`);
1030
1749
  }
1031
1750
  }
1032
1751
  /**
@@ -1039,7 +1758,7 @@ var AgentService = class {
1039
1758
  async resolveRunForToolCall(toolCallId2) {
1040
1759
  const runId = await this.store.runForToolCall(toolCallId2);
1041
1760
  if (runId === null) {
1042
- throw new import_common2.NotFoundException(`tool call ${toolCallId2} has no active run to signal`);
1761
+ throw new import_common3.NotFoundException(`tool call ${toolCallId2} has no active run to signal`);
1043
1762
  }
1044
1763
  return runId;
1045
1764
  }
@@ -1047,41 +1766,43 @@ var AgentService = class {
1047
1766
  async assertOwnsActiveStream(actor, runId) {
1048
1767
  const owner = await this.store.ownerOfActiveStream(runId);
1049
1768
  if (owner === null) {
1050
- throw new import_common2.NotFoundException(`no active run ${runId}`);
1769
+ throw new import_common3.NotFoundException(`no active run ${runId}`);
1051
1770
  }
1052
1771
  if (owner !== actor.id) {
1053
- throw new import_common2.ForbiddenException("run belongs to another actor");
1772
+ throw new import_common3.ForbiddenException("run belongs to another actor");
1054
1773
  }
1055
1774
  }
1056
1775
  };
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", [
1776
+ AgentService = _ts_decorate3([
1777
+ (0, import_common3.Injectable)(),
1778
+ _ts_param3(0, (0, import_common3.Inject)(import_nestjs_agent_core4.AGENT_RUNNER)),
1779
+ _ts_param3(1, (0, import_common3.Inject)(import_nestjs_agent_core4.AGENT_STORE)),
1780
+ _ts_param3(2, (0, import_common3.Inject)(import_nestjs_agent_core4.AGENT_DEPS_FACTORY)),
1781
+ _ts_param3(3, (0, import_common3.Optional)()),
1782
+ _ts_param3(3, (0, import_common3.Inject)(import_nestjs_agent_core4.AGENT_ATTACHMENT_STAGING)),
1783
+ _ts_param3(4, (0, import_common3.Optional)()),
1784
+ _ts_param3(4, (0, import_common3.Inject)(import_nestjs_agent_core4.AGENT_MODEL_CATALOG)),
1785
+ _ts_param3(5, (0, import_common3.Optional)()),
1786
+ _ts_param3(5, (0, import_common3.Inject)(import_nestjs_agent_core4.AGENT_QUOTA_PROVIDER)),
1787
+ _ts_param3(6, (0, import_common3.Optional)()),
1788
+ _ts_param3(6, (0, import_common3.Inject)(import_nestjs_agent_core4.AGENT_OPTIONS)),
1789
+ _ts_param3(7, (0, import_common3.Optional)()),
1790
+ _ts_metadata3("design:type", Function),
1791
+ _ts_metadata3("design:paramtypes", [
1072
1792
  typeof AgentRunner === "undefined" ? Object : AgentRunner,
1073
1793
  typeof AgentStore === "undefined" ? Object : AgentStore,
1074
1794
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
1075
1795
  typeof AttachmentStagingStore === "undefined" ? Object : AttachmentStagingStore,
1076
1796
  typeof ModelCatalog === "undefined" ? Object : ModelCatalog,
1077
1797
  typeof QuotaProvider === "undefined" ? Object : QuotaProvider,
1078
- typeof Pick === "undefined" ? Object : Pick
1798
+ typeof Pick === "undefined" ? Object : Pick,
1799
+ typeof ChatQueueService === "undefined" ? Object : ChatQueueService
1079
1800
  ])
1080
1801
  ], AgentService);
1081
1802
 
1082
1803
  // src/approval-port.adapter.ts
1083
- var import_common3 = require("@nestjs/common");
1084
- function _ts_decorate3(decorators, target, key, desc) {
1804
+ var import_common4 = require("@nestjs/common");
1805
+ function _ts_decorate4(decorators, target, key, desc) {
1085
1806
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1086
1807
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1087
1808
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1094,13 +1815,13 @@ function _ts_decorate3(decorators, target, key, desc) {
1094
1815
  }
1095
1816
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1096
1817
  }
1097
- __name(_ts_decorate3, "_ts_decorate");
1098
- function _ts_metadata3(metadataKey, metadataValue) {
1818
+ __name(_ts_decorate4, "_ts_decorate");
1819
+ function _ts_metadata4(metadataKey, metadataValue) {
1099
1820
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1100
1821
  return Reflect.metadata(metadataKey, metadataValue);
1101
1822
  }
1102
1823
  }
1103
- __name(_ts_metadata3, "_ts_metadata");
1824
+ __name(_ts_metadata4, "_ts_metadata");
1104
1825
  var AgentApprovalPortAdapter = class {
1105
1826
  static {
1106
1827
  __name(this, "AgentApprovalPortAdapter");
@@ -1138,18 +1859,18 @@ var AgentApprovalPortAdapter = class {
1138
1859
  });
1139
1860
  }
1140
1861
  };
1141
- AgentApprovalPortAdapter = _ts_decorate3([
1142
- (0, import_common3.Injectable)(),
1143
- _ts_metadata3("design:type", Function),
1144
- _ts_metadata3("design:paramtypes", [
1862
+ AgentApprovalPortAdapter = _ts_decorate4([
1863
+ (0, import_common4.Injectable)(),
1864
+ _ts_metadata4("design:type", Function),
1865
+ _ts_metadata4("design:paramtypes", [
1145
1866
  typeof AgentService === "undefined" ? Object : AgentService
1146
1867
  ])
1147
1868
  ], AgentApprovalPortAdapter);
1148
1869
 
1149
1870
  // 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) {
1871
+ var import_nestjs_agent_core5 = require("@dudousxd/nestjs-agent-core");
1872
+ var import_common5 = require("@nestjs/common");
1873
+ function _ts_decorate5(decorators, target, key, desc) {
1153
1874
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1154
1875
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1155
1876
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1162,19 +1883,19 @@ function _ts_decorate4(decorators, target, key, desc) {
1162
1883
  }
1163
1884
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1164
1885
  }
1165
- __name(_ts_decorate4, "_ts_decorate");
1166
- function _ts_metadata4(metadataKey, metadataValue) {
1886
+ __name(_ts_decorate5, "_ts_decorate");
1887
+ function _ts_metadata5(metadataKey, metadataValue) {
1167
1888
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1168
1889
  return Reflect.metadata(metadataKey, metadataValue);
1169
1890
  }
1170
1891
  }
1171
- __name(_ts_metadata4, "_ts_metadata");
1172
- function _ts_param3(paramIndex, decorator) {
1892
+ __name(_ts_metadata5, "_ts_metadata");
1893
+ function _ts_param4(paramIndex, decorator) {
1173
1894
  return function(target, key) {
1174
1895
  decorator(target, key, paramIndex);
1175
1896
  };
1176
1897
  }
1177
- __name(_ts_param3, "_ts_param");
1898
+ __name(_ts_param4, "_ts_param");
1178
1899
  var AgentsController = class {
1179
1900
  static {
1180
1901
  __name(this, "AgentsController");
@@ -1196,26 +1917,26 @@ var AgentsController = class {
1196
1917
  }));
1197
1918
  }
1198
1919
  };
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)
1920
+ _ts_decorate5([
1921
+ (0, import_common5.Get)(),
1922
+ _ts_metadata5("design:type", Function),
1923
+ _ts_metadata5("design:paramtypes", []),
1924
+ _ts_metadata5("design:returntype", Array)
1204
1925
  ], 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,
1926
+ AgentsController = _ts_decorate5([
1927
+ (0, import_common5.Controller)("agents"),
1928
+ _ts_param4(0, (0, import_common5.Inject)(import_nestjs_agent_core5.AGENT_REGISTRY)),
1929
+ _ts_param4(1, (0, import_common5.Inject)(import_nestjs_agent_core5.AGENT_DEPS_FACTORY)),
1930
+ _ts_metadata5("design:type", Function),
1931
+ _ts_metadata5("design:paramtypes", [
1932
+ typeof import_nestjs_agent_core5.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core5.AgentRegistry,
1212
1933
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory
1213
1934
  ])
1214
1935
  ], AgentsController);
1215
1936
 
1216
1937
  // src/controller/attachments.controller.ts
1217
- var import_nestjs_agent_core5 = require("@dudousxd/nestjs-agent-core");
1218
- var import_common5 = require("@nestjs/common");
1938
+ var import_nestjs_agent_core6 = require("@dudousxd/nestjs-agent-core");
1939
+ var import_common6 = require("@nestjs/common");
1219
1940
  var import_platform_express = require("@nestjs/platform-express");
1220
1941
 
1221
1942
  // src/attachment-limits.ts
@@ -1244,7 +1965,7 @@ function attachmentLimits(options, staging) {
1244
1965
  __name(attachmentLimits, "attachmentLimits");
1245
1966
 
1246
1967
  // src/controller/attachments.controller.ts
1247
- function _ts_decorate5(decorators, target, key, desc) {
1968
+ function _ts_decorate6(decorators, target, key, desc) {
1248
1969
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1249
1970
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1250
1971
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1257,19 +1978,19 @@ function _ts_decorate5(decorators, target, key, desc) {
1257
1978
  }
1258
1979
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1259
1980
  }
1260
- __name(_ts_decorate5, "_ts_decorate");
1261
- function _ts_metadata5(metadataKey, metadataValue) {
1981
+ __name(_ts_decorate6, "_ts_decorate");
1982
+ function _ts_metadata6(metadataKey, metadataValue) {
1262
1983
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1263
1984
  return Reflect.metadata(metadataKey, metadataValue);
1264
1985
  }
1265
1986
  }
1266
- __name(_ts_metadata5, "_ts_metadata");
1267
- function _ts_param4(paramIndex, decorator) {
1987
+ __name(_ts_metadata6, "_ts_metadata");
1988
+ function _ts_param5(paramIndex, decorator) {
1268
1989
  return function(target, key) {
1269
1990
  decorator(target, key, paramIndex);
1270
1991
  };
1271
1992
  }
1272
- __name(_ts_param4, "_ts_param");
1993
+ __name(_ts_param5, "_ts_param");
1273
1994
  var HARD_MAX_ATTACHMENT_BYTES = 32 * 1024 * 1024;
1274
1995
  var ATTACHMENT_PAGE_SIZE = 50;
1275
1996
  var AttachmentsController = class {
@@ -1303,17 +2024,17 @@ var AttachmentsController = class {
1303
2024
  }
1304
2025
  async upload(req, file) {
1305
2026
  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).");
2027
+ throw new import_common6.NotImplementedException("Attachment upload is not configured on this server: bind AGENT_ATTACHMENT_STAGING (e.g. import AgentMediaAttachmentsModule).");
1307
2028
  }
1308
2029
  if (file === void 0) {
1309
- throw new import_common5.BadRequestException('multipart field "file" is required');
2030
+ throw new import_common6.BadRequestException('multipart field "file" is required');
1310
2031
  }
1311
2032
  const { allowedContentTypes, maxBytes } = attachmentLimits(this.options, this.staging);
1312
2033
  if (!allowedContentTypes.includes(file.mimetype)) {
1313
- throw new import_common5.UnsupportedMediaTypeException(`content type "${file.mimetype}" is not allowed (allowed: ${allowedContentTypes.join(", ")})`);
2034
+ throw new import_common6.UnsupportedMediaTypeException(`content type "${file.mimetype}" is not allowed (allowed: ${allowedContentTypes.join(", ")})`);
1314
2035
  }
1315
2036
  if (file.size > maxBytes) {
1316
- throw new import_common5.PayloadTooLargeException(`file exceeds the ${maxBytes}-byte limit`);
2037
+ throw new import_common6.PayloadTooLargeException(`file exceeds the ${maxBytes}-byte limit`);
1317
2038
  }
1318
2039
  const actor = await this.actorResolver.resolve(req);
1319
2040
  return this.staging.stage({
@@ -1325,39 +2046,39 @@ var AttachmentsController = class {
1325
2046
  });
1326
2047
  }
1327
2048
  };
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", [
2049
+ _ts_decorate6([
2050
+ (0, import_common6.Get)(),
2051
+ _ts_param5(0, (0, import_common6.Req)()),
2052
+ _ts_metadata6("design:type", Function),
2053
+ _ts_metadata6("design:paramtypes", [
1333
2054
  typeof Request === "undefined" ? Object : Request
1334
2055
  ]),
1335
- _ts_metadata5("design:returntype", Promise)
2056
+ _ts_metadata6("design:returntype", Promise)
1336
2057
  ], AttachmentsController.prototype, "list", null);
1337
- _ts_decorate5([
1338
- (0, import_common5.Post)(),
1339
- (0, import_common5.UseInterceptors)((0, import_platform_express.FileInterceptor)("file", {
2058
+ _ts_decorate6([
2059
+ (0, import_common6.Post)(),
2060
+ (0, import_common6.UseInterceptors)((0, import_platform_express.FileInterceptor)("file", {
1340
2061
  limits: {
1341
2062
  fileSize: HARD_MAX_ATTACHMENT_BYTES
1342
2063
  }
1343
2064
  })),
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", [
2065
+ _ts_param5(0, (0, import_common6.Req)()),
2066
+ _ts_param5(1, (0, import_common6.UploadedFile)()),
2067
+ _ts_metadata6("design:type", Function),
2068
+ _ts_metadata6("design:paramtypes", [
1348
2069
  typeof Request === "undefined" ? Object : Request,
1349
2070
  Object
1350
2071
  ]),
1351
- _ts_metadata5("design:returntype", Promise)
2072
+ _ts_metadata6("design:returntype", Promise)
1352
2073
  ], 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", [
2074
+ AttachmentsController = _ts_decorate6([
2075
+ (0, import_common6.Controller)("attachments"),
2076
+ _ts_param5(0, (0, import_common6.Inject)(import_nestjs_agent_core6.AGENT_OPTIONS)),
2077
+ _ts_param5(1, (0, import_common6.Inject)(import_nestjs_agent_core6.AGENT_ACTOR_RESOLVER)),
2078
+ _ts_param5(3, (0, import_common6.Optional)()),
2079
+ _ts_param5(3, (0, import_common6.Inject)(import_nestjs_agent_core6.AGENT_ATTACHMENT_STAGING)),
2080
+ _ts_metadata6("design:type", Function),
2081
+ _ts_metadata6("design:paramtypes", [
1361
2082
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
1362
2083
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
1363
2084
  typeof AgentService === "undefined" ? Object : AgentService,
@@ -1366,9 +2087,9 @@ AttachmentsController = _ts_decorate5([
1366
2087
  ], AttachmentsController);
1367
2088
 
1368
2089
  // 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) {
2090
+ var import_nestjs_agent_core7 = require("@dudousxd/nestjs-agent-core");
2091
+ var import_common7 = require("@nestjs/common");
2092
+ function _ts_decorate7(decorators, target, key, desc) {
1372
2093
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1373
2094
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1374
2095
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1381,39 +2102,52 @@ function _ts_decorate6(decorators, target, key, desc) {
1381
2102
  }
1382
2103
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1383
2104
  }
1384
- __name(_ts_decorate6, "_ts_decorate");
1385
- function _ts_metadata6(metadataKey, metadataValue) {
2105
+ __name(_ts_decorate7, "_ts_decorate");
2106
+ function _ts_metadata7(metadataKey, metadataValue) {
1386
2107
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1387
2108
  return Reflect.metadata(metadataKey, metadataValue);
1388
2109
  }
1389
2110
  }
1390
- __name(_ts_metadata6, "_ts_metadata");
1391
- function _ts_param5(paramIndex, decorator) {
2111
+ __name(_ts_metadata7, "_ts_metadata");
2112
+ function _ts_param6(paramIndex, decorator) {
1392
2113
  return function(target, key) {
1393
2114
  decorator(target, key, paramIndex);
1394
2115
  };
1395
2116
  }
1396
- __name(_ts_param5, "_ts_param");
2117
+ __name(_ts_param6, "_ts_param");
2118
+ function sendMode(body) {
2119
+ if (body.interrupt === true) {
2120
+ return "interrupt";
2121
+ }
2122
+ if (body.mode === void 0 || body.mode === null) {
2123
+ return "auto";
2124
+ }
2125
+ if (body.mode === "auto" || body.mode === "queue" || body.mode === "interrupt") {
2126
+ return body.mode;
2127
+ }
2128
+ throw new import_common7.BadRequestException("mode must be 'auto', 'queue' or 'interrupt'");
2129
+ }
2130
+ __name(sendMode, "sendMode");
1397
2131
  function attachmentRefs(claimed) {
1398
2132
  if (claimed === void 0) {
1399
2133
  return [];
1400
2134
  }
1401
2135
  if (!Array.isArray(claimed)) {
1402
- throw new import_common6.BadRequestException("attachments must be an array of { mediaId }");
2136
+ throw new import_common7.BadRequestException("attachments must be an array of { mediaId }");
1403
2137
  }
1404
2138
  if (claimed.length > MAX_ATTACHMENTS_PER_MESSAGE) {
1405
- throw new import_common6.BadRequestException(`a message may carry at most ${MAX_ATTACHMENTS_PER_MESSAGE} attachments`);
2139
+ throw new import_common7.BadRequestException(`a message may carry at most ${MAX_ATTACHMENTS_PER_MESSAGE} attachments`);
1406
2140
  }
1407
2141
  return claimed.map((entry) => {
1408
2142
  if (typeof entry !== "object" || entry === null || !("mediaId" in entry)) {
1409
- throw new import_common6.BadRequestException("each attachment must be an object with a mediaId");
2143
+ throw new import_common7.BadRequestException("each attachment must be an object with a mediaId");
1410
2144
  }
1411
2145
  if (Object.keys(entry).some((key) => key !== "mediaId")) {
1412
- throw new import_common6.BadRequestException("attachments are { mediaId } refs \u2014 send nothing but the id");
2146
+ throw new import_common7.BadRequestException("attachments are { mediaId } refs \u2014 send nothing but the id");
1413
2147
  }
1414
2148
  const { mediaId } = entry;
1415
2149
  if (typeof mediaId !== "string" || mediaId.length === 0) {
1416
- throw new import_common6.BadRequestException("each attachment must carry a non-empty string mediaId");
2150
+ throw new import_common7.BadRequestException("each attachment must carry a non-empty string mediaId");
1417
2151
  }
1418
2152
  return {
1419
2153
  mediaId
@@ -1431,10 +2165,17 @@ var ChatController = class {
1431
2165
  this.agent = agent;
1432
2166
  this.actorResolver = actorResolver;
1433
2167
  }
2168
+ /**
2169
+ * Start a turn and stream it — or, when the thread already has one running, queue the message and
2170
+ * answer `202 { queued: true, messageId, position, queue, … }` (JSON, no stream): it runs when the
2171
+ * turn ahead of it settles, and the stream of the run holding the thread announces it with a
2172
+ * `queue` frame.
2173
+ */
1434
2174
  async chat(req, res, body) {
1435
2175
  const actor = await this.actorResolver.resolve(req);
1436
2176
  const attachments = attachmentRefs(body.attachments);
1437
- const { runId, threadId } = await this.agent.chat({
2177
+ const mode = sendMode(body);
2178
+ const result = await this.agent.send({
1438
2179
  actor,
1439
2180
  message: body.message,
1440
2181
  ...body.threadId !== void 0 ? {
@@ -1457,8 +2198,14 @@ var ChatController = class {
1457
2198
  } : {},
1458
2199
  ...typeof body.model === "string" && body.model.length > 0 ? {
1459
2200
  model: body.model
1460
- } : {}
2201
+ } : {},
2202
+ mode
1461
2203
  });
2204
+ if (result.queued === true) {
2205
+ res.status(202).json(result);
2206
+ return;
2207
+ }
2208
+ const { runId, threadId } = result;
1462
2209
  await this.pipe(res, runId, this.agent.subscribe(runId), threadId);
1463
2210
  }
1464
2211
  /**
@@ -1533,7 +2280,7 @@ data: ${line}
1533
2280
  }
1534
2281
  res.write("event: done\ndata: {}\n\n");
1535
2282
  } catch (error) {
1536
- const payload = error instanceof import_nestjs_agent_core6.AgentStreamError ? {
2283
+ const payload = error instanceof import_nestjs_agent_core7.AgentStreamError ? {
1537
2284
  code: error.code,
1538
2285
  message: error.message
1539
2286
  } : {
@@ -1548,50 +2295,50 @@ data: ${JSON.stringify(payload)}
1548
2295
  res.end();
1549
2296
  }
1550
2297
  };
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", [
2298
+ _ts_decorate7([
2299
+ (0, import_common7.Post)("chat"),
2300
+ _ts_param6(0, (0, import_common7.Req)()),
2301
+ _ts_param6(1, (0, import_common7.Res)()),
2302
+ _ts_param6(2, (0, import_common7.Body)()),
2303
+ _ts_metadata7("design:type", Function),
2304
+ _ts_metadata7("design:paramtypes", [
1558
2305
  typeof Request === "undefined" ? Object : Request,
1559
2306
  typeof Response === "undefined" ? Object : Response,
1560
2307
  typeof ChatBody === "undefined" ? Object : ChatBody
1561
2308
  ]),
1562
- _ts_metadata6("design:returntype", Promise)
2309
+ _ts_metadata7("design:returntype", Promise)
1563
2310
  ], 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", [
2311
+ _ts_decorate7([
2312
+ (0, import_common7.Get)("chat/:runId/stream"),
2313
+ _ts_param6(0, (0, import_common7.Req)()),
2314
+ _ts_param6(1, (0, import_common7.Param)("runId")),
2315
+ _ts_param6(2, (0, import_common7.Res)()),
2316
+ _ts_param6(3, (0, import_common7.Query)("after")),
2317
+ _ts_metadata7("design:type", Function),
2318
+ _ts_metadata7("design:paramtypes", [
1572
2319
  typeof Request === "undefined" ? Object : Request,
1573
2320
  String,
1574
2321
  typeof Response === "undefined" ? Object : Response,
1575
2322
  String
1576
2323
  ]),
1577
- _ts_metadata6("design:returntype", Promise)
2324
+ _ts_metadata7("design:returntype", Promise)
1578
2325
  ], 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", [
2326
+ _ts_decorate7([
2327
+ (0, import_common7.Post)("chat/:runId/cancel"),
2328
+ _ts_param6(0, (0, import_common7.Req)()),
2329
+ _ts_param6(1, (0, import_common7.Param)("runId")),
2330
+ _ts_metadata7("design:type", Function),
2331
+ _ts_metadata7("design:paramtypes", [
1585
2332
  typeof Request === "undefined" ? Object : Request,
1586
2333
  String
1587
2334
  ]),
1588
- _ts_metadata6("design:returntype", Promise)
2335
+ _ts_metadata7("design:returntype", Promise)
1589
2336
  ], 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", [
2337
+ ChatController = _ts_decorate7([
2338
+ (0, import_common7.Controller)(),
2339
+ _ts_param6(1, (0, import_common7.Inject)(import_nestjs_agent_core7.AGENT_ACTOR_RESOLVER)),
2340
+ _ts_metadata7("design:type", Function),
2341
+ _ts_metadata7("design:paramtypes", [
1595
2342
  typeof AgentService === "undefined" ? Object : AgentService,
1596
2343
  typeof ActorResolver === "undefined" ? Object : ActorResolver
1597
2344
  ])
@@ -1607,8 +2354,8 @@ function parseCursor(raw) {
1607
2354
  __name(parseCursor, "parseCursor");
1608
2355
 
1609
2356
  // src/controller/config.controller.ts
1610
- var import_nestjs_agent_core7 = require("@dudousxd/nestjs-agent-core");
1611
- var import_common7 = require("@nestjs/common");
2357
+ var import_nestjs_agent_core8 = require("@dudousxd/nestjs-agent-core");
2358
+ var import_common8 = require("@nestjs/common");
1612
2359
 
1613
2360
  // src/resolver/anonymous-actor-resolver.ts
1614
2361
  var import_node_crypto = require("crypto");
@@ -1698,7 +2445,7 @@ var AnonymousActorResolver = class {
1698
2445
  };
1699
2446
 
1700
2447
  // src/controller/config.controller.ts
1701
- function _ts_decorate7(decorators, target, key, desc) {
2448
+ function _ts_decorate8(decorators, target, key, desc) {
1702
2449
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1703
2450
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1704
2451
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1711,19 +2458,19 @@ function _ts_decorate7(decorators, target, key, desc) {
1711
2458
  }
1712
2459
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1713
2460
  }
1714
- __name(_ts_decorate7, "_ts_decorate");
1715
- function _ts_metadata7(metadataKey, metadataValue) {
2461
+ __name(_ts_decorate8, "_ts_decorate");
2462
+ function _ts_metadata8(metadataKey, metadataValue) {
1716
2463
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1717
2464
  return Reflect.metadata(metadataKey, metadataValue);
1718
2465
  }
1719
2466
  }
1720
- __name(_ts_metadata7, "_ts_metadata");
1721
- function _ts_param6(paramIndex, decorator) {
2467
+ __name(_ts_metadata8, "_ts_metadata");
2468
+ function _ts_param7(paramIndex, decorator) {
1722
2469
  return function(target, key) {
1723
2470
  decorator(target, key, paramIndex);
1724
2471
  };
1725
2472
  }
1726
- __name(_ts_param6, "_ts_param");
2473
+ __name(_ts_param7, "_ts_param");
1727
2474
  var ConfigController = class {
1728
2475
  static {
1729
2476
  __name(this, "ConfigController");
@@ -1754,25 +2501,25 @@ var ConfigController = class {
1754
2501
  };
1755
2502
  }
1756
2503
  };
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", [
2504
+ _ts_decorate8([
2505
+ (0, import_common8.Get)(),
2506
+ _ts_param7(0, (0, import_common8.Req)()),
2507
+ _ts_metadata8("design:type", Function),
2508
+ _ts_metadata8("design:paramtypes", [
1762
2509
  typeof Request === "undefined" ? Object : Request
1763
2510
  ]),
1764
- _ts_metadata7("design:returntype", Promise)
2511
+ _ts_metadata8("design:returntype", Promise)
1765
2512
  ], 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", [
2513
+ ConfigController = _ts_decorate8([
2514
+ (0, import_common8.Controller)("config"),
2515
+ _ts_param7(0, (0, import_common8.Inject)(import_nestjs_agent_core8.AGENT_OPTIONS)),
2516
+ _ts_param7(1, (0, import_common8.Inject)(import_nestjs_agent_core8.AGENT_ACTOR_RESOLVER)),
2517
+ _ts_param7(2, (0, import_common8.Optional)()),
2518
+ _ts_param7(2, (0, import_common8.Inject)(import_nestjs_agent_core8.AGENT_ATTACHMENT_STAGING)),
2519
+ _ts_param7(3, (0, import_common8.Optional)()),
2520
+ _ts_param7(3, (0, import_common8.Inject)(import_nestjs_agent_core8.AGENT_MODEL_CATALOG)),
2521
+ _ts_metadata8("design:type", Function),
2522
+ _ts_metadata8("design:paramtypes", [
1776
2523
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
1777
2524
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
1778
2525
  Object,
@@ -1781,9 +2528,9 @@ ConfigController = _ts_decorate7([
1781
2528
  ], ConfigController);
1782
2529
 
1783
2530
  // 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) {
2531
+ var import_nestjs_agent_core9 = require("@dudousxd/nestjs-agent-core");
2532
+ var import_common9 = require("@nestjs/common");
2533
+ function _ts_decorate9(decorators, target, key, desc) {
1787
2534
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1788
2535
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1789
2536
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1796,19 +2543,19 @@ function _ts_decorate8(decorators, target, key, desc) {
1796
2543
  }
1797
2544
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1798
2545
  }
1799
- __name(_ts_decorate8, "_ts_decorate");
1800
- function _ts_metadata8(metadataKey, metadataValue) {
2546
+ __name(_ts_decorate9, "_ts_decorate");
2547
+ function _ts_metadata9(metadataKey, metadataValue) {
1801
2548
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1802
2549
  return Reflect.metadata(metadataKey, metadataValue);
1803
2550
  }
1804
2551
  }
1805
- __name(_ts_metadata8, "_ts_metadata");
1806
- function _ts_param7(paramIndex, decorator) {
2552
+ __name(_ts_metadata9, "_ts_metadata");
2553
+ function _ts_param8(paramIndex, decorator) {
1807
2554
  return function(target, key) {
1808
2555
  decorator(target, key, paramIndex);
1809
2556
  };
1810
2557
  }
1811
- __name(_ts_param7, "_ts_param");
2558
+ __name(_ts_param8, "_ts_param");
1812
2559
  var MemoriesController = class {
1813
2560
  static {
1814
2561
  __name(this, "MemoriesController");
@@ -1842,20 +2589,20 @@ var MemoriesController = class {
1842
2589
  */
1843
2590
  async forget(req, id) {
1844
2591
  if (this.memory === void 0) {
1845
- throw new import_common8.NotFoundException("No memory is configured in this deployment.");
2592
+ throw new import_common9.NotFoundException("No memory is configured in this deployment.");
1846
2593
  }
1847
2594
  const actor = await this.actorResolver.resolve(req);
1848
2595
  const digest = await this.unbounded("", actor);
1849
2596
  const entry = digest.entries.find((candidate) => candidate.id === id);
1850
2597
  if (entry === void 0) {
1851
- throw new import_common8.NotFoundException(`No memory with id "${id}".`);
2598
+ throw new import_common9.NotFoundException(`No memory with id "${id}".`);
1852
2599
  }
1853
- const verdict = (0, import_nestjs_agent_core8.memoryForgetVerdict)({
2600
+ const verdict = (0, import_nestjs_agent_core9.memoryForgetVerdict)({
1854
2601
  record: entry,
1855
2602
  actor
1856
2603
  });
1857
2604
  if (!verdict.allowed) {
1858
- throw new import_common8.ForbiddenException(verdict.reason);
2605
+ throw new import_common9.ForbiddenException(verdict.reason);
1859
2606
  }
1860
2607
  return {
1861
2608
  forgotten: await this.memory.provider.forget({
@@ -1869,7 +2616,7 @@ var MemoriesController = class {
1869
2616
  }
1870
2617
  async unbounded(threadId, actor) {
1871
2618
  const config = this.memory;
1872
- return await (0, import_nestjs_agent_core8.offerMemories)({
2619
+ return await (0, import_nestjs_agent_core9.offerMemories)({
1873
2620
  config: {
1874
2621
  ...config,
1875
2622
  maxMemories: Number.POSITIVE_INFINITY
@@ -1881,44 +2628,44 @@ var MemoriesController = class {
1881
2628
  });
1882
2629
  }
1883
2630
  };
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", [
2631
+ _ts_decorate9([
2632
+ (0, import_common9.Get)(),
2633
+ _ts_param8(0, (0, import_common9.Req)()),
2634
+ _ts_param8(1, (0, import_common9.Query)("threadId")),
2635
+ _ts_metadata9("design:type", Function),
2636
+ _ts_metadata9("design:paramtypes", [
1890
2637
  typeof Request === "undefined" ? Object : Request,
1891
2638
  String
1892
2639
  ]),
1893
- _ts_metadata8("design:returntype", Promise)
2640
+ _ts_metadata9("design:returntype", Promise)
1894
2641
  ], 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", [
2642
+ _ts_decorate9([
2643
+ (0, import_common9.Delete)(":id"),
2644
+ _ts_param8(0, (0, import_common9.Req)()),
2645
+ _ts_param8(1, (0, import_common9.Param)("id")),
2646
+ _ts_metadata9("design:type", Function),
2647
+ _ts_metadata9("design:paramtypes", [
1901
2648
  typeof Request === "undefined" ? Object : Request,
1902
2649
  String
1903
2650
  ]),
1904
- _ts_metadata8("design:returntype", Promise)
2651
+ _ts_metadata9("design:returntype", Promise)
1905
2652
  ], 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", [
2653
+ MemoriesController = _ts_decorate9([
2654
+ (0, import_common9.Controller)("memories"),
2655
+ _ts_param8(0, (0, import_common9.Inject)(import_nestjs_agent_core9.AGENT_ACTOR_RESOLVER)),
2656
+ _ts_param8(1, (0, import_common9.Optional)()),
2657
+ _ts_param8(1, (0, import_common9.Inject)(import_nestjs_agent_core9.AGENT_MEMORY)),
2658
+ _ts_metadata9("design:type", Function),
2659
+ _ts_metadata9("design:paramtypes", [
1913
2660
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
1914
2661
  Object
1915
2662
  ])
1916
2663
  ], MemoriesController);
1917
2664
 
1918
2665
  // 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) {
2666
+ var import_nestjs_agent_core10 = require("@dudousxd/nestjs-agent-core");
2667
+ var import_common10 = require("@nestjs/common");
2668
+ function _ts_decorate10(decorators, target, key, desc) {
1922
2669
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1923
2670
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1924
2671
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1931,19 +2678,19 @@ function _ts_decorate9(decorators, target, key, desc) {
1931
2678
  }
1932
2679
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1933
2680
  }
1934
- __name(_ts_decorate9, "_ts_decorate");
1935
- function _ts_metadata9(metadataKey, metadataValue) {
2681
+ __name(_ts_decorate10, "_ts_decorate");
2682
+ function _ts_metadata10(metadataKey, metadataValue) {
1936
2683
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1937
2684
  return Reflect.metadata(metadataKey, metadataValue);
1938
2685
  }
1939
2686
  }
1940
- __name(_ts_metadata9, "_ts_metadata");
1941
- function _ts_param8(paramIndex, decorator) {
2687
+ __name(_ts_metadata10, "_ts_metadata");
2688
+ function _ts_param9(paramIndex, decorator) {
1942
2689
  return function(target, key) {
1943
2690
  decorator(target, key, paramIndex);
1944
2691
  };
1945
2692
  }
1946
- __name(_ts_param8, "_ts_param");
2693
+ __name(_ts_param9, "_ts_param");
1947
2694
  var MessagesController = class {
1948
2695
  static {
1949
2696
  __name(this, "MessagesController");
@@ -1971,34 +2718,34 @@ var MessagesController = class {
1971
2718
  };
1972
2719
  }
1973
2720
  };
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", [
2721
+ _ts_decorate10([
2722
+ (0, import_common10.Post)(":id/feedback"),
2723
+ (0, import_common10.HttpCode)(200),
2724
+ _ts_param9(0, (0, import_common10.Req)()),
2725
+ _ts_param9(1, (0, import_common10.Param)("id")),
2726
+ _ts_param9(2, (0, import_common10.Body)()),
2727
+ _ts_metadata10("design:type", Function),
2728
+ _ts_metadata10("design:paramtypes", [
1982
2729
  typeof Request === "undefined" ? Object : Request,
1983
2730
  String,
1984
2731
  typeof FeedbackBody === "undefined" ? Object : FeedbackBody
1985
2732
  ]),
1986
- _ts_metadata9("design:returntype", Promise)
2733
+ _ts_metadata10("design:returntype", Promise)
1987
2734
  ], 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", [
2735
+ MessagesController = _ts_decorate10([
2736
+ (0, import_common10.Controller)("messages"),
2737
+ _ts_param9(1, (0, import_common10.Inject)(import_nestjs_agent_core10.AGENT_ACTOR_RESOLVER)),
2738
+ _ts_metadata10("design:type", Function),
2739
+ _ts_metadata10("design:paramtypes", [
1993
2740
  typeof AgentService === "undefined" ? Object : AgentService,
1994
2741
  typeof ActorResolver === "undefined" ? Object : ActorResolver
1995
2742
  ])
1996
2743
  ], MessagesController);
1997
2744
 
1998
2745
  // 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) {
2746
+ var import_nestjs_agent_core11 = require("@dudousxd/nestjs-agent-core");
2747
+ var import_common11 = require("@nestjs/common");
2748
+ function _ts_decorate11(decorators, target, key, desc) {
2002
2749
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2003
2750
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2004
2751
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2011,19 +2758,19 @@ function _ts_decorate10(decorators, target, key, desc) {
2011
2758
  }
2012
2759
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2013
2760
  }
2014
- __name(_ts_decorate10, "_ts_decorate");
2015
- function _ts_metadata10(metadataKey, metadataValue) {
2761
+ __name(_ts_decorate11, "_ts_decorate");
2762
+ function _ts_metadata11(metadataKey, metadataValue) {
2016
2763
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2017
2764
  return Reflect.metadata(metadataKey, metadataValue);
2018
2765
  }
2019
2766
  }
2020
- __name(_ts_metadata10, "_ts_metadata");
2021
- function _ts_param9(paramIndex, decorator) {
2767
+ __name(_ts_metadata11, "_ts_metadata");
2768
+ function _ts_param10(paramIndex, decorator) {
2022
2769
  return function(target, key) {
2023
2770
  decorator(target, key, paramIndex);
2024
2771
  };
2025
2772
  }
2026
- __name(_ts_param9, "_ts_param");
2773
+ __name(_ts_param10, "_ts_param");
2027
2774
  var ModelsController = class {
2028
2775
  static {
2029
2776
  __name(this, "ModelsController");
@@ -2043,31 +2790,191 @@ var ModelsController = class {
2043
2790
  return this.agent.listModels(actor, agent);
2044
2791
  }
2045
2792
  };
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", [
2793
+ _ts_decorate11([
2794
+ (0, import_common11.Get)(),
2795
+ _ts_param10(0, (0, import_common11.Req)()),
2796
+ _ts_param10(1, (0, import_common11.Query)("agent")),
2797
+ _ts_metadata11("design:type", Function),
2798
+ _ts_metadata11("design:paramtypes", [
2052
2799
  typeof Request === "undefined" ? Object : Request,
2053
2800
  String
2054
2801
  ]),
2055
- _ts_metadata10("design:returntype", Promise)
2802
+ _ts_metadata11("design:returntype", Promise)
2056
2803
  ], 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", [
2804
+ ModelsController = _ts_decorate11([
2805
+ (0, import_common11.Controller)("models"),
2806
+ _ts_param10(1, (0, import_common11.Inject)(import_nestjs_agent_core11.AGENT_ACTOR_RESOLVER)),
2807
+ _ts_metadata11("design:type", Function),
2808
+ _ts_metadata11("design:paramtypes", [
2062
2809
  typeof AgentService === "undefined" ? Object : AgentService,
2063
2810
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2064
2811
  ])
2065
2812
  ], ModelsController);
2066
2813
 
2814
+ // src/controller/queue.controller.ts
2815
+ var import_nestjs_agent_core12 = require("@dudousxd/nestjs-agent-core");
2816
+ var import_common12 = require("@nestjs/common");
2817
+ function _ts_decorate12(decorators, target, key, desc) {
2818
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2819
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2820
+ r = Reflect.decorate(decorators, target, key, desc);
2821
+ } else {
2822
+ for (var i = decorators.length - 1; i >= 0; i--) {
2823
+ if (d = decorators[i]) {
2824
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2825
+ }
2826
+ }
2827
+ }
2828
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2829
+ }
2830
+ __name(_ts_decorate12, "_ts_decorate");
2831
+ function _ts_metadata12(metadataKey, metadataValue) {
2832
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2833
+ return Reflect.metadata(metadataKey, metadataValue);
2834
+ }
2835
+ }
2836
+ __name(_ts_metadata12, "_ts_metadata");
2837
+ function _ts_param11(paramIndex, decorator) {
2838
+ return function(target, key) {
2839
+ decorator(target, key, paramIndex);
2840
+ };
2841
+ }
2842
+ __name(_ts_param11, "_ts_param");
2843
+ var QueueController = class {
2844
+ static {
2845
+ __name(this, "QueueController");
2846
+ }
2847
+ agent;
2848
+ actorResolver;
2849
+ constructor(agent, actorResolver) {
2850
+ this.agent = agent;
2851
+ this.actorResolver = actorResolver;
2852
+ }
2853
+ async list(req, id) {
2854
+ return this.agent.getQueue(await this.actorResolver.resolve(req), id);
2855
+ }
2856
+ async clear(req, id) {
2857
+ return this.agent.clearQueue(await this.actorResolver.resolve(req), id);
2858
+ }
2859
+ /** Lift a pause; the head starts when nothing is running. Carries `runId` when it started. */
2860
+ async resume(req, id) {
2861
+ return this.agent.resumeQueue(await this.actorResolver.resolve(req), id);
2862
+ }
2863
+ async update(req, messageId, body) {
2864
+ const actor = await this.actorResolver.resolve(req);
2865
+ if (body.message !== void 0 && typeof body.message !== "string") {
2866
+ throw new import_common12.BadRequestException("message must be a string");
2867
+ }
2868
+ if (body.position !== void 0 && typeof body.position !== "number") {
2869
+ throw new import_common12.BadRequestException("position must be a number");
2870
+ }
2871
+ const attachments = body.attachments === void 0 ? void 0 : body.attachments === null ? null : attachmentRefs(body.attachments);
2872
+ return this.agent.updateQueuedMessage(actor, messageId, {
2873
+ ...body.message !== void 0 ? {
2874
+ message: body.message
2875
+ } : {},
2876
+ ...attachments !== void 0 ? {
2877
+ attachments
2878
+ } : {},
2879
+ ...body.position !== void 0 ? {
2880
+ position: body.position
2881
+ } : {}
2882
+ });
2883
+ }
2884
+ /**
2885
+ * Run a waiting message now: it moves to the head as an interrupt and the running turn is
2886
+ * cancelled for it. Carries `interrupting` (the cancelled run), or `runId` when nothing was
2887
+ * running and it started at once.
2888
+ */
2889
+ async interrupt(req, messageId) {
2890
+ return this.agent.interruptQueuedMessage(await this.actorResolver.resolve(req), messageId);
2891
+ }
2892
+ async remove(req, messageId) {
2893
+ return this.agent.removeQueuedMessage(await this.actorResolver.resolve(req), messageId);
2894
+ }
2895
+ };
2896
+ _ts_decorate12([
2897
+ (0, import_common12.Get)("threads/:id/queue"),
2898
+ _ts_param11(0, (0, import_common12.Req)()),
2899
+ _ts_param11(1, (0, import_common12.Param)("id")),
2900
+ _ts_metadata12("design:type", Function),
2901
+ _ts_metadata12("design:paramtypes", [
2902
+ typeof Request === "undefined" ? Object : Request,
2903
+ String
2904
+ ]),
2905
+ _ts_metadata12("design:returntype", Promise)
2906
+ ], QueueController.prototype, "list", null);
2907
+ _ts_decorate12([
2908
+ (0, import_common12.Delete)("threads/:id/queue"),
2909
+ _ts_param11(0, (0, import_common12.Req)()),
2910
+ _ts_param11(1, (0, import_common12.Param)("id")),
2911
+ _ts_metadata12("design:type", Function),
2912
+ _ts_metadata12("design:paramtypes", [
2913
+ typeof Request === "undefined" ? Object : Request,
2914
+ String
2915
+ ]),
2916
+ _ts_metadata12("design:returntype", Promise)
2917
+ ], QueueController.prototype, "clear", null);
2918
+ _ts_decorate12([
2919
+ (0, import_common12.Post)("threads/:id/queue/resume"),
2920
+ _ts_param11(0, (0, import_common12.Req)()),
2921
+ _ts_param11(1, (0, import_common12.Param)("id")),
2922
+ _ts_metadata12("design:type", Function),
2923
+ _ts_metadata12("design:paramtypes", [
2924
+ typeof Request === "undefined" ? Object : Request,
2925
+ String
2926
+ ]),
2927
+ _ts_metadata12("design:returntype", Promise)
2928
+ ], QueueController.prototype, "resume", null);
2929
+ _ts_decorate12([
2930
+ (0, import_common12.Patch)("queue/:messageId"),
2931
+ _ts_param11(0, (0, import_common12.Req)()),
2932
+ _ts_param11(1, (0, import_common12.Param)("messageId")),
2933
+ _ts_param11(2, (0, import_common12.Body)()),
2934
+ _ts_metadata12("design:type", Function),
2935
+ _ts_metadata12("design:paramtypes", [
2936
+ typeof Request === "undefined" ? Object : Request,
2937
+ String,
2938
+ typeof UpdateQueuedMessageBody === "undefined" ? Object : UpdateQueuedMessageBody
2939
+ ]),
2940
+ _ts_metadata12("design:returntype", Promise)
2941
+ ], QueueController.prototype, "update", null);
2942
+ _ts_decorate12([
2943
+ (0, import_common12.Post)("queue/:messageId/interrupt"),
2944
+ _ts_param11(0, (0, import_common12.Req)()),
2945
+ _ts_param11(1, (0, import_common12.Param)("messageId")),
2946
+ _ts_metadata12("design:type", Function),
2947
+ _ts_metadata12("design:paramtypes", [
2948
+ typeof Request === "undefined" ? Object : Request,
2949
+ String
2950
+ ]),
2951
+ _ts_metadata12("design:returntype", Promise)
2952
+ ], QueueController.prototype, "interrupt", null);
2953
+ _ts_decorate12([
2954
+ (0, import_common12.Delete)("queue/:messageId"),
2955
+ _ts_param11(0, (0, import_common12.Req)()),
2956
+ _ts_param11(1, (0, import_common12.Param)("messageId")),
2957
+ _ts_metadata12("design:type", Function),
2958
+ _ts_metadata12("design:paramtypes", [
2959
+ typeof Request === "undefined" ? Object : Request,
2960
+ String
2961
+ ]),
2962
+ _ts_metadata12("design:returntype", Promise)
2963
+ ], QueueController.prototype, "remove", null);
2964
+ QueueController = _ts_decorate12([
2965
+ (0, import_common12.Controller)(),
2966
+ _ts_param11(1, (0, import_common12.Inject)(import_nestjs_agent_core12.AGENT_ACTOR_RESOLVER)),
2967
+ _ts_metadata12("design:type", Function),
2968
+ _ts_metadata12("design:paramtypes", [
2969
+ typeof AgentService === "undefined" ? Object : AgentService,
2970
+ typeof ActorResolver === "undefined" ? Object : ActorResolver
2971
+ ])
2972
+ ], QueueController);
2973
+
2067
2974
  // 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) {
2975
+ var import_nestjs_agent_core13 = require("@dudousxd/nestjs-agent-core");
2976
+ var import_common13 = require("@nestjs/common");
2977
+ function _ts_decorate13(decorators, target, key, desc) {
2071
2978
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2072
2979
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2073
2980
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2080,19 +2987,19 @@ function _ts_decorate11(decorators, target, key, desc) {
2080
2987
  }
2081
2988
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2082
2989
  }
2083
- __name(_ts_decorate11, "_ts_decorate");
2084
- function _ts_metadata11(metadataKey, metadataValue) {
2990
+ __name(_ts_decorate13, "_ts_decorate");
2991
+ function _ts_metadata13(metadataKey, metadataValue) {
2085
2992
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2086
2993
  return Reflect.metadata(metadataKey, metadataValue);
2087
2994
  }
2088
2995
  }
2089
- __name(_ts_metadata11, "_ts_metadata");
2090
- function _ts_param10(paramIndex, decorator) {
2996
+ __name(_ts_metadata13, "_ts_metadata");
2997
+ function _ts_param12(paramIndex, decorator) {
2091
2998
  return function(target, key) {
2092
2999
  decorator(target, key, paramIndex);
2093
3000
  };
2094
3001
  }
2095
- __name(_ts_param10, "_ts_param");
3002
+ __name(_ts_param12, "_ts_param");
2096
3003
  var QuotaController = class {
2097
3004
  static {
2098
3005
  __name(this, "QuotaController");
@@ -2112,29 +3019,29 @@ var QuotaController = class {
2112
3019
  return this.agent.quotaReport(actor);
2113
3020
  }
2114
3021
  };
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", [
3022
+ _ts_decorate13([
3023
+ (0, import_common13.Get)(),
3024
+ _ts_param12(0, (0, import_common13.Req)()),
3025
+ _ts_metadata13("design:type", Function),
3026
+ _ts_metadata13("design:paramtypes", [
2120
3027
  typeof Request === "undefined" ? Object : Request
2121
3028
  ]),
2122
- _ts_metadata11("design:returntype", Promise)
3029
+ _ts_metadata13("design:returntype", Promise)
2123
3030
  ], 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", [
3031
+ QuotaController = _ts_decorate13([
3032
+ (0, import_common13.Controller)("quota"),
3033
+ _ts_param12(1, (0, import_common13.Inject)(import_nestjs_agent_core13.AGENT_ACTOR_RESOLVER)),
3034
+ _ts_metadata13("design:type", Function),
3035
+ _ts_metadata13("design:paramtypes", [
2129
3036
  typeof AgentService === "undefined" ? Object : AgentService,
2130
3037
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2131
3038
  ])
2132
3039
  ], QuotaController);
2133
3040
 
2134
3041
  // 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) {
3042
+ var import_nestjs_agent_core14 = require("@dudousxd/nestjs-agent-core");
3043
+ var import_common14 = require("@nestjs/common");
3044
+ function _ts_decorate14(decorators, target, key, desc) {
2138
3045
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2139
3046
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2140
3047
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2147,19 +3054,19 @@ function _ts_decorate12(decorators, target, key, desc) {
2147
3054
  }
2148
3055
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2149
3056
  }
2150
- __name(_ts_decorate12, "_ts_decorate");
2151
- function _ts_metadata12(metadataKey, metadataValue) {
3057
+ __name(_ts_decorate14, "_ts_decorate");
3058
+ function _ts_metadata14(metadataKey, metadataValue) {
2152
3059
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2153
3060
  return Reflect.metadata(metadataKey, metadataValue);
2154
3061
  }
2155
3062
  }
2156
- __name(_ts_metadata12, "_ts_metadata");
2157
- function _ts_param11(paramIndex, decorator) {
3063
+ __name(_ts_metadata14, "_ts_metadata");
3064
+ function _ts_param13(paramIndex, decorator) {
2158
3065
  return function(target, key) {
2159
3066
  decorator(target, key, paramIndex);
2160
3067
  };
2161
3068
  }
2162
- __name(_ts_param11, "_ts_param");
3069
+ __name(_ts_param13, "_ts_param");
2163
3070
  var SkillsController = class {
2164
3071
  static {
2165
3072
  __name(this, "SkillsController");
@@ -2175,40 +3082,40 @@ var SkillsController = class {
2175
3082
  return [];
2176
3083
  }
2177
3084
  const actor = await this.actorResolver.resolve(req);
2178
- const offer = await (0, import_nestjs_agent_core12.offerSkills)(this.skills, {
3085
+ const offer = await (0, import_nestjs_agent_core14.offerSkills)(this.skills, {
2179
3086
  actor,
2180
3087
  threadId: threadId ?? ""
2181
3088
  });
2182
3089
  return offer.entries;
2183
3090
  }
2184
3091
  };
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", [
3092
+ _ts_decorate14([
3093
+ (0, import_common14.Get)(),
3094
+ _ts_param13(0, (0, import_common14.Req)()),
3095
+ _ts_param13(1, (0, import_common14.Query)("threadId")),
3096
+ _ts_metadata14("design:type", Function),
3097
+ _ts_metadata14("design:paramtypes", [
2191
3098
  typeof Request === "undefined" ? Object : Request,
2192
3099
  String
2193
3100
  ]),
2194
- _ts_metadata12("design:returntype", Promise)
3101
+ _ts_metadata14("design:returntype", Promise)
2195
3102
  ], 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", [
3103
+ SkillsController = _ts_decorate14([
3104
+ (0, import_common14.Controller)("skills"),
3105
+ _ts_param13(0, (0, import_common14.Inject)(import_nestjs_agent_core14.AGENT_ACTOR_RESOLVER)),
3106
+ _ts_param13(1, (0, import_common14.Optional)()),
3107
+ _ts_param13(1, (0, import_common14.Inject)(import_nestjs_agent_core14.AGENT_SKILLS)),
3108
+ _ts_metadata14("design:type", Function),
3109
+ _ts_metadata14("design:paramtypes", [
2203
3110
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
2204
3111
  Object
2205
3112
  ])
2206
3113
  ], SkillsController);
2207
3114
 
2208
3115
  // 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) {
3116
+ var import_nestjs_agent_core15 = require("@dudousxd/nestjs-agent-core");
3117
+ var import_common15 = require("@nestjs/common");
3118
+ function _ts_decorate15(decorators, target, key, desc) {
2212
3119
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2213
3120
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2214
3121
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2221,19 +3128,19 @@ function _ts_decorate13(decorators, target, key, desc) {
2221
3128
  }
2222
3129
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2223
3130
  }
2224
- __name(_ts_decorate13, "_ts_decorate");
2225
- function _ts_metadata13(metadataKey, metadataValue) {
3131
+ __name(_ts_decorate15, "_ts_decorate");
3132
+ function _ts_metadata15(metadataKey, metadataValue) {
2226
3133
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2227
3134
  return Reflect.metadata(metadataKey, metadataValue);
2228
3135
  }
2229
3136
  }
2230
- __name(_ts_metadata13, "_ts_metadata");
2231
- function _ts_param12(paramIndex, decorator) {
3137
+ __name(_ts_metadata15, "_ts_metadata");
3138
+ function _ts_param14(paramIndex, decorator) {
2232
3139
  return function(target, key) {
2233
3140
  decorator(target, key, paramIndex);
2234
3141
  };
2235
3142
  }
2236
- __name(_ts_param12, "_ts_param");
3143
+ __name(_ts_param14, "_ts_param");
2237
3144
  var ThreadsController = class {
2238
3145
  static {
2239
3146
  __name(this, "ThreadsController");
@@ -2298,103 +3205,103 @@ var ThreadsController = class {
2298
3205
  return {
2299
3206
  ok: true
2300
3207
  };
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", [
3208
+ }
3209
+ };
3210
+ _ts_decorate15([
3211
+ (0, import_common15.Get)(),
3212
+ _ts_param14(0, (0, import_common15.Req)()),
3213
+ _ts_metadata15("design:type", Function),
3214
+ _ts_metadata15("design:paramtypes", [
2308
3215
  typeof Request === "undefined" ? Object : Request
2309
3216
  ]),
2310
- _ts_metadata13("design:returntype", Promise)
3217
+ _ts_metadata15("design:returntype", Promise)
2311
3218
  ], 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", [
3219
+ _ts_decorate15([
3220
+ (0, import_common15.Get)(":id"),
3221
+ _ts_param14(0, (0, import_common15.Req)()),
3222
+ _ts_param14(1, (0, import_common15.Param)("id")),
3223
+ _ts_metadata15("design:type", Function),
3224
+ _ts_metadata15("design:paramtypes", [
2318
3225
  typeof Request === "undefined" ? Object : Request,
2319
3226
  String
2320
3227
  ]),
2321
- _ts_metadata13("design:returntype", Promise)
3228
+ _ts_metadata15("design:returntype", Promise)
2322
3229
  ], 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", [
3230
+ _ts_decorate15([
3231
+ (0, import_common15.Delete)(":id"),
3232
+ _ts_param14(0, (0, import_common15.Req)()),
3233
+ _ts_param14(1, (0, import_common15.Param)("id")),
3234
+ _ts_metadata15("design:type", Function),
3235
+ _ts_metadata15("design:paramtypes", [
2329
3236
  typeof Request === "undefined" ? Object : Request,
2330
3237
  String
2331
3238
  ]),
2332
- _ts_metadata13("design:returntype", Promise)
3239
+ _ts_metadata15("design:returntype", Promise)
2333
3240
  ], 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", [
3241
+ _ts_decorate15([
3242
+ (0, import_common15.Post)(":id/fork-from/:messageId"),
3243
+ _ts_param14(0, (0, import_common15.Req)()),
3244
+ _ts_param14(1, (0, import_common15.Param)("id")),
3245
+ _ts_param14(2, (0, import_common15.Param)("messageId")),
3246
+ _ts_metadata15("design:type", Function),
3247
+ _ts_metadata15("design:paramtypes", [
2341
3248
  typeof Request === "undefined" ? Object : Request,
2342
3249
  String,
2343
3250
  String
2344
3251
  ]),
2345
- _ts_metadata13("design:returntype", Promise)
3252
+ _ts_metadata15("design:returntype", Promise)
2346
3253
  ], 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", [
3254
+ _ts_decorate15([
3255
+ (0, import_common15.Patch)(":id"),
3256
+ _ts_param14(0, (0, import_common15.Req)()),
3257
+ _ts_param14(1, (0, import_common15.Param)("id")),
3258
+ _ts_param14(2, (0, import_common15.Body)()),
3259
+ _ts_metadata15("design:type", Function),
3260
+ _ts_metadata15("design:paramtypes", [
2354
3261
  typeof Request === "undefined" ? Object : Request,
2355
3262
  String,
2356
3263
  typeof UpdateThreadBody === "undefined" ? Object : UpdateThreadBody
2357
3264
  ]),
2358
- _ts_metadata13("design:returntype", Promise)
3265
+ _ts_metadata15("design:returntype", Promise)
2359
3266
  ], 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", [
3267
+ _ts_decorate15([
3268
+ (0, import_common15.Post)(":id/promote"),
3269
+ _ts_param14(0, (0, import_common15.Req)()),
3270
+ _ts_param14(1, (0, import_common15.Param)("id")),
3271
+ _ts_metadata15("design:type", Function),
3272
+ _ts_metadata15("design:paramtypes", [
2366
3273
  typeof Request === "undefined" ? Object : Request,
2367
3274
  String
2368
3275
  ]),
2369
- _ts_metadata13("design:returntype", Promise)
3276
+ _ts_metadata15("design:returntype", Promise)
2370
3277
  ], 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", [
3278
+ _ts_decorate15([
3279
+ (0, import_common15.Delete)(":id/from/:messageId"),
3280
+ _ts_param14(0, (0, import_common15.Req)()),
3281
+ _ts_param14(1, (0, import_common15.Param)("id")),
3282
+ _ts_param14(2, (0, import_common15.Param)("messageId")),
3283
+ _ts_metadata15("design:type", Function),
3284
+ _ts_metadata15("design:paramtypes", [
2378
3285
  typeof Request === "undefined" ? Object : Request,
2379
3286
  String,
2380
3287
  String
2381
3288
  ]),
2382
- _ts_metadata13("design:returntype", Promise)
3289
+ _ts_metadata15("design:returntype", Promise)
2383
3290
  ], 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", [
3291
+ ThreadsController = _ts_decorate15([
3292
+ (0, import_common15.Controller)("threads"),
3293
+ _ts_param14(1, (0, import_common15.Inject)(import_nestjs_agent_core15.AGENT_ACTOR_RESOLVER)),
3294
+ _ts_metadata15("design:type", Function),
3295
+ _ts_metadata15("design:paramtypes", [
2389
3296
  typeof AgentService === "undefined" ? Object : AgentService,
2390
3297
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2391
3298
  ])
2392
3299
  ], ThreadsController);
2393
3300
 
2394
3301
  // 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) {
3302
+ var import_nestjs_agent_core16 = require("@dudousxd/nestjs-agent-core");
3303
+ var import_common16 = require("@nestjs/common");
3304
+ function _ts_decorate16(decorators, target, key, desc) {
2398
3305
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2399
3306
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2400
3307
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2407,19 +3314,19 @@ function _ts_decorate14(decorators, target, key, desc) {
2407
3314
  }
2408
3315
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2409
3316
  }
2410
- __name(_ts_decorate14, "_ts_decorate");
2411
- function _ts_metadata14(metadataKey, metadataValue) {
3317
+ __name(_ts_decorate16, "_ts_decorate");
3318
+ function _ts_metadata16(metadataKey, metadataValue) {
2412
3319
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2413
3320
  return Reflect.metadata(metadataKey, metadataValue);
2414
3321
  }
2415
3322
  }
2416
- __name(_ts_metadata14, "_ts_metadata");
2417
- function _ts_param13(paramIndex, decorator) {
3323
+ __name(_ts_metadata16, "_ts_metadata");
3324
+ function _ts_param15(paramIndex, decorator) {
2418
3325
  return function(target, key) {
2419
3326
  decorator(target, key, paramIndex);
2420
3327
  };
2421
3328
  }
2422
- __name(_ts_param13, "_ts_param");
3329
+ __name(_ts_param15, "_ts_param");
2423
3330
  var MAX_ANSWERED_QUESTIONS = 100;
2424
3331
  var MAX_VALUES_PER_QUESTION = 100;
2425
3332
  var MAX_ANSWER_VALUE_LENGTH = 4096;
@@ -2428,7 +3335,7 @@ var MAX_VIA_LENGTH = 64;
2428
3335
  var DEFAULT_VIA = "web";
2429
3336
  function toolCallId(claimed) {
2430
3337
  if (typeof claimed !== "string" || claimed.length === 0) {
2431
- throw new import_common14.BadRequestException("toolCallId must be a non-empty string");
3338
+ throw new import_common16.BadRequestException("toolCallId must be a non-empty string");
2432
3339
  }
2433
3340
  return claimed;
2434
3341
  }
@@ -2438,10 +3345,10 @@ function rejectReason(claimed) {
2438
3345
  return void 0;
2439
3346
  }
2440
3347
  if (typeof claimed !== "string") {
2441
- throw new import_common14.BadRequestException("reason must be a string");
3348
+ throw new import_common16.BadRequestException("reason must be a string");
2442
3349
  }
2443
3350
  if (claimed.length > MAX_REJECT_REASON_LENGTH) {
2444
- throw new import_common14.BadRequestException(`reason must be at most ${MAX_REJECT_REASON_LENGTH} characters`);
3351
+ throw new import_common16.BadRequestException(`reason must be at most ${MAX_REJECT_REASON_LENGTH} characters`);
2445
3352
  }
2446
3353
  return claimed;
2447
3354
  }
@@ -2451,7 +3358,7 @@ function remember(claimed) {
2451
3358
  return false;
2452
3359
  }
2453
3360
  if (typeof claimed !== "boolean") {
2454
- throw new import_common14.BadRequestException("remember must be a boolean");
3361
+ throw new import_common16.BadRequestException("remember must be a boolean");
2455
3362
  }
2456
3363
  return claimed;
2457
3364
  }
@@ -2461,7 +3368,7 @@ function via(claimed) {
2461
3368
  return DEFAULT_VIA;
2462
3369
  }
2463
3370
  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`);
3371
+ throw new import_common16.BadRequestException(`via must be a string of 1-${MAX_VIA_LENGTH} characters`);
2465
3372
  }
2466
3373
  return claimed;
2467
3374
  }
@@ -2471,26 +3378,26 @@ function answers(claimed) {
2471
3378
  return void 0;
2472
3379
  }
2473
3380
  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");
3381
+ throw new import_common16.BadRequestException("answers must be an object of questionId \u2192 chosen values");
2475
3382
  }
2476
3383
  const entries = Object.entries(claimed);
2477
3384
  if (entries.length > MAX_ANSWERED_QUESTIONS) {
2478
- throw new import_common14.BadRequestException(`answers may cover at most ${MAX_ANSWERED_QUESTIONS} questions`);
3385
+ throw new import_common16.BadRequestException(`answers may cover at most ${MAX_ANSWERED_QUESTIONS} questions`);
2479
3386
  }
2480
3387
  const validated = /* @__PURE__ */ Object.create(null);
2481
3388
  for (const [questionId, values] of entries) {
2482
3389
  if (!Array.isArray(values)) {
2483
- throw new import_common14.BadRequestException(`answers["${questionId}"] must be an array of chosen values`);
3390
+ throw new import_common16.BadRequestException(`answers["${questionId}"] must be an array of chosen values`);
2484
3391
  }
2485
3392
  if (values.length > MAX_VALUES_PER_QUESTION) {
2486
- throw new import_common14.BadRequestException(`answers["${questionId}"] may carry at most ${MAX_VALUES_PER_QUESTION} values`);
3393
+ throw new import_common16.BadRequestException(`answers["${questionId}"] may carry at most ${MAX_VALUES_PER_QUESTION} values`);
2487
3394
  }
2488
3395
  for (const value of values) {
2489
3396
  if (typeof value !== "string") {
2490
- throw new import_common14.BadRequestException(`answers["${questionId}"] must contain only strings`);
3397
+ throw new import_common16.BadRequestException(`answers["${questionId}"] must contain only strings`);
2491
3398
  }
2492
3399
  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`);
3400
+ throw new import_common16.BadRequestException(`answers["${questionId}"] values must be at most ${MAX_ANSWER_VALUE_LENGTH} characters`);
2494
3401
  }
2495
3402
  }
2496
3403
  validated[questionId] = values;
@@ -2552,64 +3459,64 @@ var ToolCallController = class {
2552
3459
  };
2553
3460
  }
2554
3461
  };
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", [
3462
+ _ts_decorate16([
3463
+ (0, import_common16.Post)("approve"),
3464
+ _ts_param15(0, (0, import_common16.Req)()),
3465
+ _ts_param15(1, (0, import_common16.Body)()),
3466
+ _ts_metadata16("design:type", Function),
3467
+ _ts_metadata16("design:paramtypes", [
2561
3468
  typeof Request === "undefined" ? Object : Request,
2562
3469
  typeof ApproveBody === "undefined" ? Object : ApproveBody
2563
3470
  ]),
2564
- _ts_metadata14("design:returntype", Promise)
3471
+ _ts_metadata16("design:returntype", Promise)
2565
3472
  ], 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", [
3473
+ _ts_decorate16([
3474
+ (0, import_common16.Post)("reject"),
3475
+ _ts_param15(0, (0, import_common16.Req)()),
3476
+ _ts_param15(1, (0, import_common16.Body)()),
3477
+ _ts_metadata16("design:type", Function),
3478
+ _ts_metadata16("design:paramtypes", [
2572
3479
  typeof Request === "undefined" ? Object : Request,
2573
3480
  typeof RejectBody === "undefined" ? Object : RejectBody
2574
3481
  ]),
2575
- _ts_metadata14("design:returntype", Promise)
3482
+ _ts_metadata16("design:returntype", Promise)
2576
3483
  ], 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", [
3484
+ _ts_decorate16([
3485
+ (0, import_common16.Post)("answer"),
3486
+ _ts_param15(0, (0, import_common16.Req)()),
3487
+ _ts_param15(1, (0, import_common16.Body)()),
3488
+ _ts_metadata16("design:type", Function),
3489
+ _ts_metadata16("design:paramtypes", [
2583
3490
  typeof Request === "undefined" ? Object : Request,
2584
3491
  typeof AnswerBody === "undefined" ? Object : AnswerBody
2585
3492
  ]),
2586
- _ts_metadata14("design:returntype", Promise)
3493
+ _ts_metadata16("design:returntype", Promise)
2587
3494
  ], 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", [
3495
+ _ts_decorate16([
3496
+ (0, import_common16.Post)("skip"),
3497
+ _ts_param15(0, (0, import_common16.Req)()),
3498
+ _ts_param15(1, (0, import_common16.Body)()),
3499
+ _ts_metadata16("design:type", Function),
3500
+ _ts_metadata16("design:paramtypes", [
2594
3501
  typeof Request === "undefined" ? Object : Request,
2595
3502
  Object
2596
3503
  ]),
2597
- _ts_metadata14("design:returntype", Promise)
3504
+ _ts_metadata16("design:returntype", Promise)
2598
3505
  ], 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", [
3506
+ ToolCallController = _ts_decorate16([
3507
+ (0, import_common16.Controller)("tool-call"),
3508
+ _ts_param15(1, (0, import_common16.Inject)(import_nestjs_agent_core16.AGENT_ACTOR_RESOLVER)),
3509
+ _ts_metadata16("design:type", Function),
3510
+ _ts_metadata16("design:paramtypes", [
2604
3511
  typeof AgentService === "undefined" ? Object : AgentService,
2605
3512
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2606
3513
  ])
2607
3514
  ], ToolCallController);
2608
3515
 
2609
3516
  // 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) {
3517
+ var import_nestjs_agent_core17 = require("@dudousxd/nestjs-agent-core");
3518
+ var import_common17 = require("@nestjs/common");
3519
+ function _ts_decorate17(decorators, target, key, desc) {
2613
3520
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2614
3521
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2615
3522
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2622,19 +3529,19 @@ function _ts_decorate15(decorators, target, key, desc) {
2622
3529
  }
2623
3530
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2624
3531
  }
2625
- __name(_ts_decorate15, "_ts_decorate");
2626
- function _ts_metadata15(metadataKey, metadataValue) {
3532
+ __name(_ts_decorate17, "_ts_decorate");
3533
+ function _ts_metadata17(metadataKey, metadataValue) {
2627
3534
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2628
3535
  return Reflect.metadata(metadataKey, metadataValue);
2629
3536
  }
2630
3537
  }
2631
- __name(_ts_metadata15, "_ts_metadata");
2632
- function _ts_param14(paramIndex, decorator) {
3538
+ __name(_ts_metadata17, "_ts_metadata");
3539
+ function _ts_param16(paramIndex, decorator) {
2633
3540
  return function(target, key) {
2634
3541
  decorator(target, key, paramIndex);
2635
3542
  };
2636
3543
  }
2637
- __name(_ts_param14, "_ts_param");
3544
+ __name(_ts_param16, "_ts_param");
2638
3545
  var ToolsController = class {
2639
3546
  static {
2640
3547
  __name(this, "ToolsController");
@@ -2648,11 +3555,11 @@ var ToolsController = class {
2648
3555
  this.agents = agents;
2649
3556
  }
2650
3557
  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}"`);
3558
+ if (agent !== void 0 && agent !== import_nestjs_agent_core17.ALL_AGENTS && this.agents.get(agent) === void 0) {
3559
+ throw new import_common17.NotFoundException(`No agent named "${agent}"`);
2653
3560
  }
2654
3561
  const actor = await this.actorResolver.resolve(req);
2655
- const names = agent === import_nestjs_agent_core15.ALL_AGENTS ? [
3562
+ const names = agent === import_nestjs_agent_core17.ALL_AGENTS ? [
2656
3563
  void 0,
2657
3564
  ...this.agents.list().map((definition) => definition.name)
2658
3565
  ] : [
@@ -2678,33 +3585,33 @@ var ToolsController = class {
2678
3585
  ];
2679
3586
  }
2680
3587
  };
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", [
3588
+ _ts_decorate17([
3589
+ (0, import_common17.Get)(),
3590
+ _ts_param16(0, (0, import_common17.Req)()),
3591
+ _ts_param16(1, (0, import_common17.Query)("agent")),
3592
+ _ts_metadata17("design:type", Function),
3593
+ _ts_metadata17("design:paramtypes", [
2687
3594
  typeof Request === "undefined" ? Object : Request,
2688
3595
  String
2689
3596
  ]),
2690
- _ts_metadata15("design:returntype", Promise)
3597
+ _ts_metadata17("design:returntype", Promise)
2691
3598
  ], 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", [
3599
+ ToolsController = _ts_decorate17([
3600
+ (0, import_common17.Controller)("tools"),
3601
+ _ts_param16(0, (0, import_common17.Inject)(import_nestjs_agent_core17.AGENT_ACTOR_RESOLVER)),
3602
+ _ts_param16(1, (0, import_common17.Inject)(import_nestjs_agent_core17.AGENT_DEPS_FACTORY)),
3603
+ _ts_param16(2, (0, import_common17.Inject)(import_nestjs_agent_core17.AGENT_REGISTRY)),
3604
+ _ts_metadata17("design:type", Function),
3605
+ _ts_metadata17("design:paramtypes", [
2699
3606
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
2700
3607
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
2701
- typeof import_nestjs_agent_core15.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core15.AgentRegistry
3608
+ typeof import_nestjs_agent_core17.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core17.AgentRegistry
2702
3609
  ])
2703
3610
  ], ToolsController);
2704
3611
 
2705
3612
  // src/discovery/agent-discovery.service.ts
2706
- var import_nestjs_agent_core16 = require("@dudousxd/nestjs-agent-core");
2707
- var import_common16 = require("@nestjs/common");
3613
+ var import_nestjs_agent_core18 = require("@dudousxd/nestjs-agent-core");
3614
+ var import_common18 = require("@nestjs/common");
2708
3615
  var import_core = require("@nestjs/core");
2709
3616
 
2710
3617
  // src/decorator/agent.decorator.ts
@@ -2739,7 +3646,7 @@ function SystemPromptContributor() {
2739
3646
  __name(SystemPromptContributor, "SystemPromptContributor");
2740
3647
 
2741
3648
  // src/discovery/agent-discovery.service.ts
2742
- function _ts_decorate16(decorators, target, key, desc) {
3649
+ function _ts_decorate18(decorators, target, key, desc) {
2743
3650
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2744
3651
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2745
3652
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2752,19 +3659,19 @@ function _ts_decorate16(decorators, target, key, desc) {
2752
3659
  }
2753
3660
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2754
3661
  }
2755
- __name(_ts_decorate16, "_ts_decorate");
2756
- function _ts_metadata16(metadataKey, metadataValue) {
3662
+ __name(_ts_decorate18, "_ts_decorate");
3663
+ function _ts_metadata18(metadataKey, metadataValue) {
2757
3664
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2758
3665
  return Reflect.metadata(metadataKey, metadataValue);
2759
3666
  }
2760
3667
  }
2761
- __name(_ts_metadata16, "_ts_metadata");
2762
- function _ts_param15(paramIndex, decorator) {
3668
+ __name(_ts_metadata18, "_ts_metadata");
3669
+ function _ts_param17(paramIndex, decorator) {
2763
3670
  return function(target, key) {
2764
3671
  decorator(target, key, paramIndex);
2765
3672
  };
2766
3673
  }
2767
- __name(_ts_param15, "_ts_param");
3674
+ __name(_ts_param17, "_ts_param");
2768
3675
  var AgentDiscoveryService = class _AgentDiscoveryService {
2769
3676
  static {
2770
3677
  __name(this, "AgentDiscoveryService");
@@ -2773,7 +3680,7 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
2773
3680
  scanner;
2774
3681
  registry;
2775
3682
  contributors;
2776
- logger = new import_common16.Logger(_AgentDiscoveryService.name);
3683
+ logger = new import_common18.Logger(_AgentDiscoveryService.name);
2777
3684
  constructor(discovery, scanner, registry, contributors) {
2778
3685
  this.discovery = discovery;
2779
3686
  this.scanner = scanner;
@@ -2891,22 +3798,22 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
2891
3798
  return (ctx) => candidate.call(instance, ctx);
2892
3799
  }
2893
3800
  };
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", [
3801
+ AgentDiscoveryService = _ts_decorate18([
3802
+ (0, import_common18.Injectable)(),
3803
+ _ts_param17(2, (0, import_common18.Inject)(import_nestjs_agent_core18.AGENT_REGISTRY)),
3804
+ _ts_param17(3, (0, import_common18.Inject)(import_nestjs_agent_core18.AGENT_PROMPT_CONTRIBUTORS)),
3805
+ _ts_metadata18("design:type", Function),
3806
+ _ts_metadata18("design:paramtypes", [
2900
3807
  typeof import_core.DiscoveryService === "undefined" ? Object : import_core.DiscoveryService,
2901
3808
  typeof import_core.MetadataScanner === "undefined" ? Object : import_core.MetadataScanner,
2902
- typeof import_nestjs_agent_core16.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core16.AgentRegistry,
3809
+ typeof import_nestjs_agent_core18.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core18.AgentRegistry,
2903
3810
  Array
2904
3811
  ])
2905
3812
  ], AgentDiscoveryService);
2906
3813
 
2907
3814
  // 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");
3815
+ var import_nestjs_agent_core19 = require("@dudousxd/nestjs-agent-core");
3816
+ var import_common19 = require("@nestjs/common");
2910
3817
  var import_core2 = require("@nestjs/core");
2911
3818
  var import_zod = require("zod");
2912
3819
 
@@ -2977,7 +3884,7 @@ function provideAgentTools(factory, inject) {
2977
3884
  __name(provideAgentTools, "provideAgentTools");
2978
3885
 
2979
3886
  // src/discovery/ai-tool-discovery.service.ts
2980
- function _ts_decorate17(decorators, target, key, desc) {
3887
+ function _ts_decorate19(decorators, target, key, desc) {
2981
3888
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2982
3889
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2983
3890
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2990,19 +3897,19 @@ function _ts_decorate17(decorators, target, key, desc) {
2990
3897
  }
2991
3898
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2992
3899
  }
2993
- __name(_ts_decorate17, "_ts_decorate");
2994
- function _ts_metadata17(metadataKey, metadataValue) {
3900
+ __name(_ts_decorate19, "_ts_decorate");
3901
+ function _ts_metadata19(metadataKey, metadataValue) {
2995
3902
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2996
3903
  return Reflect.metadata(metadataKey, metadataValue);
2997
3904
  }
2998
3905
  }
2999
- __name(_ts_metadata17, "_ts_metadata");
3000
- function _ts_param16(paramIndex, decorator) {
3906
+ __name(_ts_metadata19, "_ts_metadata");
3907
+ function _ts_param18(paramIndex, decorator) {
3001
3908
  return function(target, key) {
3002
3909
  decorator(target, key, paramIndex);
3003
3910
  };
3004
3911
  }
3005
- __name(_ts_param16, "_ts_param");
3912
+ __name(_ts_param18, "_ts_param");
3006
3913
  var AiToolDiscoveryService = class _AiToolDiscoveryService {
3007
3914
  static {
3008
3915
  __name(this, "AiToolDiscoveryService");
@@ -3011,7 +3918,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
3011
3918
  registry;
3012
3919
  agents;
3013
3920
  options;
3014
- logger = new import_common17.Logger(_AiToolDiscoveryService.name);
3921
+ logger = new import_common19.Logger(_AiToolDiscoveryService.name);
3015
3922
  constructor(discovery, registry, agents, options) {
3016
3923
  this.discovery = discovery;
3017
3924
  this.registry = registry;
@@ -3096,7 +4003,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
3096
4003
  let delegates = 0;
3097
4004
  for (const definition of this.agents.list()) {
3098
4005
  for (const edge of definition.delegatesTo ?? []) {
3099
- const { agent: target, detached } = (0, import_nestjs_agent_core17.normalizeDelegation)(edge);
4006
+ const { agent: target, detached } = (0, import_nestjs_agent_core19.normalizeDelegation)(edge);
3100
4007
  const targetDefinition = this.agents.get(target);
3101
4008
  if (targetDefinition === void 0) {
3102
4009
  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 +4053,13 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
3146
4053
  return true;
3147
4054
  }
3148
4055
  };
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", [
4056
+ AiToolDiscoveryService = _ts_decorate19([
4057
+ (0, import_common19.Injectable)(),
4058
+ _ts_param18(1, (0, import_common19.Inject)(import_nestjs_agent_core19.AGENT_TOOL_REGISTRY)),
4059
+ _ts_param18(2, (0, import_common19.Inject)(import_nestjs_agent_core19.AGENT_REGISTRY)),
4060
+ _ts_param18(3, (0, import_common19.Inject)(import_nestjs_agent_core19.AGENT_OPTIONS)),
4061
+ _ts_metadata19("design:type", Function),
4062
+ _ts_metadata19("design:paramtypes", [
3156
4063
  typeof import_core2.DiscoveryService === "undefined" ? Object : import_core2.DiscoveryService,
3157
4064
  typeof ToolRegistry === "undefined" ? Object : ToolRegistry,
3158
4065
  typeof AgentRegistry === "undefined" ? Object : AgentRegistry,
@@ -3161,13 +4068,13 @@ AiToolDiscoveryService = _ts_decorate17([
3161
4068
  ], AiToolDiscoveryService);
3162
4069
 
3163
4070
  // src/discovery/skill-discovery.service.ts
3164
- var import_nestjs_agent_core19 = require("@dudousxd/nestjs-agent-core");
3165
- var import_common18 = require("@nestjs/common");
4071
+ var import_nestjs_agent_core21 = require("@dudousxd/nestjs-agent-core");
4072
+ var import_common20 = require("@nestjs/common");
3166
4073
  var import_core3 = require("@nestjs/core");
3167
4074
 
3168
4075
  // src/decorator/skill.decorator.ts
3169
4076
  var import_reflect_metadata4 = require("reflect-metadata");
3170
- var import_nestjs_agent_core18 = require("@dudousxd/nestjs-agent-core");
4077
+ var import_nestjs_agent_core20 = require("@dudousxd/nestjs-agent-core");
3171
4078
  var SKILL_METADATA = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:skill-metadata");
3172
4079
  function Skill(options) {
3173
4080
  return (target) => {
@@ -3180,12 +4087,12 @@ function readSkillMetadata(target) {
3180
4087
  }
3181
4088
  __name(readSkillMetadata, "readSkillMetadata");
3182
4089
  function skillScope(options) {
3183
- return options.scope ?? import_nestjs_agent_core18.GLOBAL_SCOPE;
4090
+ return options.scope ?? import_nestjs_agent_core20.GLOBAL_SCOPE;
3184
4091
  }
3185
4092
  __name(skillScope, "skillScope");
3186
4093
 
3187
4094
  // src/discovery/skill-discovery.service.ts
3188
- function _ts_decorate18(decorators, target, key, desc) {
4095
+ function _ts_decorate20(decorators, target, key, desc) {
3189
4096
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3190
4097
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3191
4098
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3198,26 +4105,26 @@ function _ts_decorate18(decorators, target, key, desc) {
3198
4105
  }
3199
4106
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3200
4107
  }
3201
- __name(_ts_decorate18, "_ts_decorate");
3202
- function _ts_metadata18(metadataKey, metadataValue) {
4108
+ __name(_ts_decorate20, "_ts_decorate");
4109
+ function _ts_metadata20(metadataKey, metadataValue) {
3203
4110
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3204
4111
  return Reflect.metadata(metadataKey, metadataValue);
3205
4112
  }
3206
4113
  }
3207
- __name(_ts_metadata18, "_ts_metadata");
3208
- function _ts_param17(paramIndex, decorator) {
4114
+ __name(_ts_metadata20, "_ts_metadata");
4115
+ function _ts_param19(paramIndex, decorator) {
3209
4116
  return function(target, key) {
3210
4117
  decorator(target, key, paramIndex);
3211
4118
  };
3212
4119
  }
3213
- __name(_ts_param17, "_ts_param");
4120
+ __name(_ts_param19, "_ts_param");
3214
4121
  var SkillDiscoveryService = class _SkillDiscoveryService {
3215
4122
  static {
3216
4123
  __name(this, "SkillDiscoveryService");
3217
4124
  }
3218
4125
  discovery;
3219
4126
  declared;
3220
- logger = new import_common18.Logger(_SkillDiscoveryService.name);
4127
+ logger = new import_common20.Logger(_SkillDiscoveryService.name);
3221
4128
  constructor(discovery, declared) {
3222
4129
  this.discovery = discovery;
3223
4130
  this.declared = declared;
@@ -3254,18 +4161,18 @@ var SkillDiscoveryService = class _SkillDiscoveryService {
3254
4161
  return flat === void 0 ? void 0 : () => flat;
3255
4162
  }
3256
4163
  };
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", [
4164
+ SkillDiscoveryService = _ts_decorate20([
4165
+ (0, import_common20.Injectable)(),
4166
+ _ts_param19(1, (0, import_common20.Inject)(import_nestjs_agent_core21.AGENT_SKILL_SOURCES)),
4167
+ _ts_metadata20("design:type", Function),
4168
+ _ts_metadata20("design:paramtypes", [
3262
4169
  typeof import_core3.DiscoveryService === "undefined" ? Object : import_core3.DiscoveryService,
3263
4170
  Array
3264
4171
  ])
3265
4172
  ], SkillDiscoveryService);
3266
4173
 
3267
4174
  // src/in-process-sink.ts
3268
- var import_nestjs_agent_core20 = require("@dudousxd/nestjs-agent-core");
4175
+ var import_nestjs_agent_core22 = require("@dudousxd/nestjs-agent-core");
3269
4176
  var InProcessTokenStreamSink = class {
3270
4177
  static {
3271
4178
  __name(this, "InProcessTokenStreamSink");
@@ -3320,7 +4227,7 @@ var InProcessTokenStreamSink = class {
3320
4227
  }
3321
4228
  if (buf.ended) {
3322
4229
  if (buf.failure !== void 0) {
3323
- throw new import_nestjs_agent_core20.AgentStreamError(buf.failure);
4230
+ throw new import_nestjs_agent_core22.AgentStreamError(buf.failure);
3324
4231
  }
3325
4232
  return;
3326
4233
  }
@@ -3333,7 +4240,7 @@ var InProcessTokenStreamSink = class {
3333
4240
  };
3334
4241
 
3335
4242
  // src/ledger-quota-provider.ts
3336
- var import_nestjs_agent_core21 = require("@dudousxd/nestjs-agent-core");
4243
+ var import_nestjs_agent_core23 = require("@dudousxd/nestjs-agent-core");
3337
4244
  var LedgerQuotaProvider = class {
3338
4245
  static {
3339
4246
  __name(this, "LedgerQuotaProvider");
@@ -3353,12 +4260,12 @@ var LedgerQuotaProvider = class {
3353
4260
  await this.dayWindow(actorRef, now)
3354
4261
  ];
3355
4262
  if (this.store.usageBetween !== void 0) {
3356
- const range = (0, import_nestjs_agent_core21.quotaPeriodRange)("month", now);
4263
+ const range = (0, import_nestjs_agent_core23.quotaPeriodRange)("month", now);
3357
4264
  const used = await this.store.usageBetween(actorRef, range.fromDay, range.toDay);
3358
4265
  windows.push(this.window("month", used.usedTokens, used.costUsd, range.resetsAt));
3359
4266
  }
3360
- const blocked = (0, import_nestjs_agent_core21.exhaustedWindow)(windows);
3361
- const warning = (0, import_nestjs_agent_core21.quotaWarning)(windows);
4267
+ const blocked = (0, import_nestjs_agent_core23.exhaustedWindow)(windows);
4268
+ const warning = (0, import_nestjs_agent_core23.quotaWarning)(windows);
3362
4269
  return {
3363
4270
  windows,
3364
4271
  ...blocked !== void 0 ? {
@@ -3370,7 +4277,7 @@ var LedgerQuotaProvider = class {
3370
4277
  };
3371
4278
  }
3372
4279
  async dayWindow(actorRef, now) {
3373
- const range = (0, import_nestjs_agent_core21.quotaPeriodRange)("day", now);
4280
+ const range = (0, import_nestjs_agent_core23.quotaPeriodRange)("day", now);
3374
4281
  const { usedTokens, costUsd } = await this.store.quotaToday(actorRef, range.fromDay);
3375
4282
  return this.window("day", usedTokens, costUsd, range.resetsAt);
3376
4283
  }
@@ -3395,9 +4302,9 @@ var LedgerQuotaProvider = class {
3395
4302
  };
3396
4303
 
3397
4304
  // 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) {
4305
+ var import_nestjs_agent_core24 = require("@dudousxd/nestjs-agent-core");
4306
+ var import_common21 = require("@nestjs/common");
4307
+ function _ts_decorate21(decorators, target, key, desc) {
3401
4308
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3402
4309
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3403
4310
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3410,26 +4317,27 @@ function _ts_decorate19(decorators, target, key, desc) {
3410
4317
  }
3411
4318
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3412
4319
  }
3413
- __name(_ts_decorate19, "_ts_decorate");
3414
- function _ts_metadata19(metadataKey, metadataValue) {
4320
+ __name(_ts_decorate21, "_ts_decorate");
4321
+ function _ts_metadata21(metadataKey, metadataValue) {
3415
4322
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3416
4323
  return Reflect.metadata(metadataKey, metadataValue);
3417
4324
  }
3418
4325
  }
3419
- __name(_ts_metadata19, "_ts_metadata");
3420
- function _ts_param18(paramIndex, decorator) {
4326
+ __name(_ts_metadata21, "_ts_metadata");
4327
+ function _ts_param20(paramIndex, decorator) {
3421
4328
  return function(target, key) {
3422
4329
  decorator(target, key, paramIndex);
3423
4330
  };
3424
4331
  }
3425
- __name(_ts_param18, "_ts_param");
4332
+ __name(_ts_param20, "_ts_param");
3426
4333
  var InlineAgentRunner = class _InlineAgentRunner {
3427
4334
  static {
3428
4335
  __name(this, "InlineAgentRunner");
3429
4336
  }
3430
4337
  factory;
3431
4338
  store;
3432
- logger = new import_common19.Logger(_InlineAgentRunner.name);
4339
+ queue;
4340
+ logger = new import_common21.Logger(_InlineAgentRunner.name);
3433
4341
  pending = /* @__PURE__ */ new Map();
3434
4342
  /**
3435
4343
  * Runs someone has asked to stop. In-process, like `pending`, and for the same reason: this runner
@@ -3437,14 +4345,25 @@ var InlineAgentRunner = class _InlineAgentRunner {
3437
4345
  * running it. A cancelled id is dropped once the run settles, so the set tracks live runs only.
3438
4346
  */
3439
4347
  cancelled = /* @__PURE__ */ new Set();
3440
- constructor(factory, store) {
4348
+ /** Top-level runs this process is running now — what {@link isRunActive} answers from. */
4349
+ live = /* @__PURE__ */ new Set();
4350
+ constructor(factory, store, queue) {
3441
4351
  this.factory = factory;
3442
4352
  this.store = store;
4353
+ this.queue = queue;
3443
4354
  }
3444
- async start(input) {
3445
- const runId = crypto.randomUUID();
4355
+ /**
4356
+ * In-process, so exact: a run this process is not running is not running anywhere — the process
4357
+ * that was running it is gone (a restart), and a thread it still holds is a stale claim.
4358
+ */
4359
+ async isRunActive(runId) {
4360
+ return this.live.has(runId);
4361
+ }
4362
+ async start(input, options = {}) {
4363
+ const runId = options.runId ?? crypto.randomUUID();
3446
4364
  const day = input.day ?? utcDay();
3447
4365
  const deps = this.factory.forAgent(input.agentName);
4366
+ this.live.add(runId);
3448
4367
  const hooks = this.topLevelHooks({
3449
4368
  runId,
3450
4369
  deps,
@@ -3456,20 +4375,21 @@ var InlineAgentRunner = class _InlineAgentRunner {
3456
4375
  ...input.agentName !== void 0 ? [
3457
4376
  input.agentName
3458
4377
  ] : []
3459
- ]
4378
+ ],
4379
+ input
3460
4380
  });
3461
- void (0, import_nestjs_agent_core22.runAgentLoop)({
4381
+ void (0, import_nestjs_agent_core24.runAgentLoop)({
3462
4382
  ...deps,
3463
4383
  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);
4384
+ }, input, hooks).then(() => (0, import_nestjs_agent_core24.releaseThreadRun)(this.store, input.threadId, runId)).catch(async (error) => {
4385
+ if (error instanceof import_nestjs_agent_core24.RunCancelledError) {
4386
+ await this.settleCancelled(runId, input, deps);
3467
4387
  return;
3468
4388
  }
3469
4389
  const message = error instanceof Error ? error.message : String(error);
3470
- const code = (0, import_nestjs_agent_core22.agentFailureCode)(error);
4390
+ const code = (0, import_nestjs_agent_core24.agentFailureCode)(error);
3471
4391
  this.logger.error(`agent run ${runId} failed (${code}): ${message}`);
3472
- (0, import_nestjs_agent_core22.publishAgentRunFailed)({
4392
+ (0, import_nestjs_agent_core24.publishAgentRunFailed)({
3473
4393
  runId,
3474
4394
  code,
3475
4395
  message
@@ -3480,13 +4400,17 @@ var InlineAgentRunner = class _InlineAgentRunner {
3480
4400
  errorCode: code,
3481
4401
  errorMessage: message
3482
4402
  });
3483
- await this.store.setActiveStream(input.threadId, null);
3484
4403
  const writer = await deps.sink.open(runId);
4404
+ await this.settleQueue(writer, input, runId, "failed", message);
4405
+ await (0, import_nestjs_agent_core24.releaseThreadRun)(this.store, input.threadId, runId);
3485
4406
  await writer.fail({
3486
4407
  code,
3487
4408
  message
3488
4409
  });
3489
- }).finally(() => this.cancelled.delete(runId));
4410
+ }).finally(() => {
4411
+ this.cancelled.delete(runId);
4412
+ this.live.delete(runId);
4413
+ });
3490
4414
  return {
3491
4415
  runId
3492
4416
  };
@@ -3518,7 +4442,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3518
4442
  for (const [key, waiter] of this.pending) {
3519
4443
  if (key.startsWith(`${runId}:`)) {
3520
4444
  this.pending.delete(key);
3521
- waiter.reject(new import_nestjs_agent_core22.RunCancelledError());
4445
+ waiter.reject(new import_nestjs_agent_core24.RunCancelledError());
3522
4446
  }
3523
4447
  }
3524
4448
  await Promise.resolve();
@@ -3529,11 +4453,12 @@ var InlineAgentRunner = class _InlineAgentRunner {
3529
4453
  * the stream ENDED after a `cancelled` frame rather than failed, so a client that retries failed
3530
4454
  * streams does not retry this one.
3531
4455
  */
3532
- async settleCancelled(runId, threadId, deps) {
4456
+ async settleCancelled(runId, input, deps) {
3533
4457
  this.logger.log(`agent run ${runId} cancelled`);
3534
- await this.store.setActiveStream(threadId, null);
3535
4458
  const writer = await deps.sink.open(runId);
3536
- await writer.write((0, import_nestjs_agent_core22.encodeStreamEvent)({
4459
+ await this.settleQueue(writer, input, runId, "cancelled");
4460
+ await (0, import_nestjs_agent_core24.releaseThreadRun)(this.store, input.threadId, runId);
4461
+ await writer.write((0, import_nestjs_agent_core24.encodeStreamEvent)({
3537
4462
  kind: "cancelled"
3538
4463
  }));
3539
4464
  await writer.end();
@@ -3543,6 +4468,38 @@ var InlineAgentRunner = class _InlineAgentRunner {
3543
4468
  });
3544
4469
  }
3545
4470
  /**
4471
+ * Move the thread past a settling TOP-LEVEL run — to the next queued message, which starts here,
4472
+ * or to a paused/empty queue — and write the resulting `queue` frame into this run's stream. A
4473
+ * no-op without a queue-capable store, and for a run that is not a thread's own turn.
4474
+ *
4475
+ * Never throws: the run is settling either way, and a queue that could not be advanced is picked
4476
+ * up by the next send or resume on the thread.
4477
+ */
4478
+ async settleQueue(writer, input, runId, outcome, error) {
4479
+ const queue = this.queue;
4480
+ if (queue === void 0 || !queue.supported || !isThreadTurn(input)) {
4481
+ return;
4482
+ }
4483
+ const settled = outcome === "completed" && this.cancelled.has(runId) ? "cancelled" : outcome;
4484
+ try {
4485
+ const frame = await queue.handoff({
4486
+ threadId: input.threadId,
4487
+ runId,
4488
+ outcome: settled,
4489
+ ...error !== void 0 ? {
4490
+ error
4491
+ } : {}
4492
+ }, (next, nextRunId) => this.start(next, {
4493
+ runId: nextRunId
4494
+ }));
4495
+ if (frame !== void 0) {
4496
+ await writer.write((0, import_nestjs_agent_core24.encodeStreamEvent)(frame));
4497
+ }
4498
+ } catch (failure) {
4499
+ this.logger.error(`could not advance the queue of thread ${input.threadId} after run ${runId}: ${failure instanceof Error ? failure.message : String(failure)}`);
4500
+ }
4501
+ }
4502
+ /**
3546
4503
  * Park a run on a human, keyed by run + tool call. One map for approvals and for question-set
3547
4504
  * answers alike: both wait on the same key, and `signal` cannot tell (or need to tell) which
3548
4505
  * shape it is delivering — the loop asked for one and only ever gets what the caller sent. A
@@ -3587,14 +4544,27 @@ var InlineAgentRunner = class _InlineAgentRunner {
3587
4544
  });
3588
4545
  }
3589
4546
  topLevelHooks(args) {
3590
- const { runId, deps, actor, day, threadId, chainBelow } = args;
4547
+ const { runId, deps, actor, day, threadId, chainBelow, input } = args;
3591
4548
  return {
3592
4549
  runId,
3593
- openSink: /* @__PURE__ */ __name(() => deps.sink.open(runId), "openSink"),
4550
+ // The loop ends the stream when the turn completes. Just before, the thread passes to the next
4551
+ // queued message (or is released), and the reader is told which — so by the time a client
4552
+ // sees the run end, the thread is already free or already running what it queued.
4553
+ openSink: /* @__PURE__ */ __name(async () => {
4554
+ const writer = await deps.sink.open(runId);
4555
+ return this.queue === void 0 ? writer : {
4556
+ write: /* @__PURE__ */ __name((chunk) => writer.write(chunk), "write"),
4557
+ fail: /* @__PURE__ */ __name((error) => writer.fail(error), "fail"),
4558
+ end: /* @__PURE__ */ __name(async () => {
4559
+ await this.settleQueue(writer, input, runId, "completed");
4560
+ await writer.end();
4561
+ }, "end")
4562
+ };
4563
+ }, "openSink"),
3594
4564
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
3595
4565
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
3596
4566
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
3597
- parallel: import_nestjs_agent_core22.settleAll,
4567
+ parallel: import_nestjs_agent_core24.settleAll,
3598
4568
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
3599
4569
  runAgent: /* @__PURE__ */ __name((agentName, task) => this.runNested({
3600
4570
  agentName,
@@ -3645,7 +4615,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3645
4615
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
3646
4616
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
3647
4617
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
3648
- parallel: import_nestjs_agent_core22.settleAll,
4618
+ parallel: import_nestjs_agent_core24.settleAll,
3649
4619
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
3650
4620
  runAgent: /* @__PURE__ */ __name((childName, childTask) => this.runNested({
3651
4621
  agentName: childName,
@@ -3678,7 +4648,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3678
4648
  }
3679
4649
  }), "startAgent")
3680
4650
  };
3681
- void (0, import_nestjs_agent_core22.runAgentLoop)({
4651
+ void (0, import_nestjs_agent_core24.runAgentLoop)({
3682
4652
  ...deps,
3683
4653
  day
3684
4654
  }, {
@@ -3692,13 +4662,13 @@ var InlineAgentRunner = class _InlineAgentRunner {
3692
4662
  parentRunId,
3693
4663
  deliverTo
3694
4664
  }, hooks).catch(async (error) => {
3695
- const cancelled = error instanceof import_nestjs_agent_core22.RunCancelledError;
4665
+ const cancelled = error instanceof import_nestjs_agent_core24.RunCancelledError;
3696
4666
  const message = error instanceof Error ? error.message : String(error);
3697
4667
  if (!cancelled) {
3698
4668
  this.logger.error(`detached agent run ${runId} failed: ${message}`);
3699
- (0, import_nestjs_agent_core22.publishAgentRunFailed)({
4669
+ (0, import_nestjs_agent_core24.publishAgentRunFailed)({
3700
4670
  runId,
3701
- code: (0, import_nestjs_agent_core22.agentFailureCode)(error),
4671
+ code: (0, import_nestjs_agent_core24.agentFailureCode)(error),
3702
4672
  message
3703
4673
  });
3704
4674
  }
@@ -3706,11 +4676,11 @@ var InlineAgentRunner = class _InlineAgentRunner {
3706
4676
  runId,
3707
4677
  status: cancelled ? "cancelled" : "failed",
3708
4678
  ...cancelled ? {} : {
3709
- errorCode: (0, import_nestjs_agent_core22.agentFailureCode)(error),
4679
+ errorCode: (0, import_nestjs_agent_core24.agentFailureCode)(error),
3710
4680
  errorMessage: message
3711
4681
  }
3712
4682
  });
3713
- await (0, import_nestjs_agent_core22.settleUnsettledDelegation)({
4683
+ await (0, import_nestjs_agent_core24.settleUnsettledDelegation)({
3714
4684
  store: this.store,
3715
4685
  delivery: deliverTo,
3716
4686
  agent: agentName,
@@ -3749,7 +4719,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3749
4719
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
3750
4720
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
3751
4721
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
3752
- parallel: import_nestjs_agent_core22.settleAll,
4722
+ parallel: import_nestjs_agent_core24.settleAll,
3753
4723
  // A child stops when it is cancelled OR when the run a human is actually watching is: the
3754
4724
  // canceller names the top-level run, which is the only id that ever left the server.
3755
4725
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId) || this.cancelled.has(sinkRunId), "cancelled"),
@@ -3784,7 +4754,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3784
4754
  }), "startAgent")
3785
4755
  };
3786
4756
  try {
3787
- return await (0, import_nestjs_agent_core22.runAgentLoop)({
4757
+ return await (0, import_nestjs_agent_core24.runAgentLoop)({
3788
4758
  ...deps,
3789
4759
  day
3790
4760
  }, {
@@ -3803,19 +4773,25 @@ var InlineAgentRunner = class _InlineAgentRunner {
3803
4773
  }
3804
4774
  }
3805
4775
  };
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", [
4776
+ InlineAgentRunner = _ts_decorate21([
4777
+ (0, import_common21.Injectable)(),
4778
+ _ts_param20(0, (0, import_common21.Inject)(import_nestjs_agent_core24.AGENT_DEPS_FACTORY)),
4779
+ _ts_param20(1, (0, import_common21.Inject)(import_nestjs_agent_core24.AGENT_STORE)),
4780
+ _ts_param20(2, (0, import_common21.Optional)()),
4781
+ _ts_metadata21("design:type", Function),
4782
+ _ts_metadata21("design:paramtypes", [
3812
4783
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
3813
- typeof AgentStore === "undefined" ? Object : AgentStore
4784
+ typeof AgentStore === "undefined" ? Object : AgentStore,
4785
+ typeof ChatQueueService === "undefined" ? Object : ChatQueueService
3814
4786
  ])
3815
4787
  ], InlineAgentRunner);
4788
+ function isThreadTurn(input) {
4789
+ return input.sinkRunId === void 0 && input.deliverTo === void 0;
4790
+ }
4791
+ __name(isThreadTurn, "isThreadTurn");
3816
4792
 
3817
4793
  // src/skills-config.ts
3818
- var import_nestjs_agent_core23 = require("@dudousxd/nestjs-agent-core");
4794
+ var import_nestjs_agent_core25 = require("@dudousxd/nestjs-agent-core");
3819
4795
  function declaredSkillProvider(declared) {
3820
4796
  return {
3821
4797
  list: /* @__PURE__ */ __name(({ scopes }) => declared.filter((skill) => scopes.includes(skill.scope)).map(({ name, description, scope }) => ({
@@ -3841,7 +4817,7 @@ function resolveSkillsConfig(options, declared) {
3841
4817
  declaredSkillProvider(declared)
3842
4818
  ];
3843
4819
  return {
3844
- provider: providers.length === 1 ? providers[0] : (0, import_nestjs_agent_core23.compositeSkillProvider)(providers),
4820
+ provider: providers.length === 1 ? providers[0] : (0, import_nestjs_agent_core25.compositeSkillProvider)(providers),
3845
4821
  ...options.scopes !== void 0 ? {
3846
4822
  scopes: options.scopes
3847
4823
  } : {},
@@ -3853,7 +4829,7 @@ function resolveSkillsConfig(options, declared) {
3853
4829
  __name(resolveSkillsConfig, "resolveSkillsConfig");
3854
4830
 
3855
4831
  // src/agent.module.ts
3856
- function _ts_decorate20(decorators, target, key, desc) {
4832
+ function _ts_decorate22(decorators, target, key, desc) {
3857
4833
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3858
4834
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3859
4835
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3866,13 +4842,13 @@ function _ts_decorate20(decorators, target, key, desc) {
3866
4842
  }
3867
4843
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3868
4844
  }
3869
- __name(_ts_decorate20, "_ts_decorate");
4845
+ __name(_ts_decorate22, "_ts_decorate");
3870
4846
  var DEFAULT_PATH = "agent";
3871
- var logger = new import_common20.Logger("AgentModule");
4847
+ var logger = new import_common22.Logger("AgentModule");
3872
4848
  function externalStoreWrapper(modules) {
3873
4849
  for (const module2 of modules.values()) {
3874
4850
  if (module2.metatype === AgentModule) continue;
3875
- const wrapper = module2.providers.get(import_nestjs_agent_core24.AGENT_STORE);
4851
+ const wrapper = module2.providers.get(import_nestjs_agent_core26.AGENT_STORE);
3876
4852
  if (wrapper !== void 0) return wrapper;
3877
4853
  }
3878
4854
  return void 0;
@@ -3903,7 +4879,7 @@ function resolveStore(options, modules) {
3903
4879
  const external = externalStoreWrapper(modules);
3904
4880
  if (external !== void 0) return forwardingStore(external);
3905
4881
  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();
4882
+ return new import_nestjs_agent_core26.InMemoryAgentStore();
3907
4883
  }
3908
4884
  __name(resolveStore, "resolveStore");
3909
4885
  function isQuotaProvider(quota) {
@@ -3919,99 +4895,99 @@ __name(resolveCatalog, "resolveCatalog");
3919
4895
  function sharedProviders(durable) {
3920
4896
  const providers = [
3921
4897
  {
3922
- provide: import_nestjs_agent_core24.AGENT_TOOL_REGISTRY,
3923
- useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core24.ToolRegistry(), "useFactory")
4898
+ provide: import_nestjs_agent_core26.AGENT_TOOL_REGISTRY,
4899
+ useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core26.ToolRegistry(), "useFactory")
3924
4900
  },
3925
4901
  // Starts empty; AgentDiscoveryService populates it from `@Agent`-decorated providers at boot.
3926
4902
  {
3927
- provide: import_nestjs_agent_core24.AGENT_REGISTRY,
3928
- useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core24.AgentRegistry(), "useFactory")
4903
+ provide: import_nestjs_agent_core26.AGENT_REGISTRY,
4904
+ useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core26.AgentRegistry(), "useFactory")
3929
4905
  },
3930
4906
  // A shared, mutable list AgentDiscoveryService fills with `@SystemPromptContributor()` methods.
3931
4907
  {
3932
- provide: import_nestjs_agent_core24.AGENT_PROMPT_CONTRIBUTORS,
4908
+ provide: import_nestjs_agent_core26.AGENT_PROMPT_CONTRIBUTORS,
3933
4909
  useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
3934
4910
  },
3935
4911
  // Likewise for `@Skill`-decorated providers — filled by SkillDiscoveryService at onModuleInit,
3936
4912
  // read lazily by the AGENT_SKILLS provider below (which DI builds before discovery has run).
3937
4913
  {
3938
- provide: import_nestjs_agent_core24.AGENT_SKILL_SOURCES,
4914
+ provide: import_nestjs_agent_core26.AGENT_SKILL_SOURCES,
3939
4915
  useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
3940
4916
  },
3941
4917
  {
3942
4918
  // One resolution, shared by the loop's deps and the listing endpoint: a second one would
3943
4919
  // drift, and a user would be offered a skill the agent cannot reach. `undefined` when the
3944
4920
  // host configured none — which is what keeps the turn's checkpoint sequence unchanged.
3945
- provide: import_nestjs_agent_core24.AGENT_SKILLS,
4921
+ provide: import_nestjs_agent_core26.AGENT_SKILLS,
3946
4922
  useFactory: /* @__PURE__ */ __name((options, declared) => resolveSkillsConfig(options.skills, declared), "useFactory"),
3947
4923
  inject: [
3948
- import_nestjs_agent_core24.AGENT_OPTIONS,
3949
- import_nestjs_agent_core24.AGENT_SKILL_SOURCES
4924
+ import_nestjs_agent_core26.AGENT_OPTIONS,
4925
+ import_nestjs_agent_core26.AGENT_SKILL_SOURCES
3950
4926
  ]
3951
4927
  },
3952
4928
  {
3953
4929
  // One resolution, shared by the loop's deps and the read-back endpoint: a person has to be
3954
4930
  // shown what the model was shown, and two resolutions would eventually disagree about that.
3955
- provide: import_nestjs_agent_core24.AGENT_MEMORY,
4931
+ provide: import_nestjs_agent_core26.AGENT_MEMORY,
3956
4932
  useFactory: /* @__PURE__ */ __name((options) => options.memory, "useFactory"),
3957
4933
  inject: [
3958
- import_nestjs_agent_core24.AGENT_OPTIONS
4934
+ import_nestjs_agent_core26.AGENT_OPTIONS
3959
4935
  ]
3960
4936
  },
3961
4937
  {
3962
- provide: import_nestjs_agent_core24.AGENT_SINK,
4938
+ provide: import_nestjs_agent_core26.AGENT_SINK,
3963
4939
  useFactory: /* @__PURE__ */ __name((options) => options.sink ?? new InProcessTokenStreamSink(), "useFactory"),
3964
4940
  inject: [
3965
- import_nestjs_agent_core24.AGENT_OPTIONS
4941
+ import_nestjs_agent_core26.AGENT_OPTIONS
3966
4942
  ]
3967
4943
  },
3968
4944
  {
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"),
4945
+ provide: import_nestjs_agent_core26.AGENT_ROLES_POLICY,
4946
+ useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? new import_nestjs_agent_core26.DefaultRolesPolicy(options.defaultRoles), "useFactory"),
3971
4947
  inject: [
3972
- import_nestjs_agent_core24.AGENT_OPTIONS
4948
+ import_nestjs_agent_core26.AGENT_OPTIONS
3973
4949
  ]
3974
4950
  },
3975
4951
  {
3976
- provide: import_nestjs_agent_core24.AGENT_ACTOR_RESOLVER,
4952
+ provide: import_nestjs_agent_core26.AGENT_ACTOR_RESOLVER,
3977
4953
  useFactory: /* @__PURE__ */ __name((options) => {
3978
4954
  if (options.actorResolver !== void 0) return options.actorResolver;
3979
4955
  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
4956
  return new AnonymousActorResolver();
3981
4957
  }, "useFactory"),
3982
4958
  inject: [
3983
- import_nestjs_agent_core24.AGENT_OPTIONS
4959
+ import_nestjs_agent_core26.AGENT_OPTIONS
3984
4960
  ]
3985
4961
  },
3986
4962
  {
3987
- provide: import_nestjs_agent_core24.AGENT_MODEL,
4963
+ provide: import_nestjs_agent_core26.AGENT_MODEL,
3988
4964
  useFactory: /* @__PURE__ */ __name((o) => o.model, "useFactory"),
3989
4965
  inject: [
3990
- import_nestjs_agent_core24.AGENT_OPTIONS
4966
+ import_nestjs_agent_core26.AGENT_OPTIONS
3991
4967
  ]
3992
4968
  },
3993
4969
  {
3994
4970
  // `quota` is either a provider of the host's own or ceilings for the built-in ledger one;
3995
4971
  // omitted, the ledger provider still reports usage, with no ceiling to block on.
3996
- provide: import_nestjs_agent_core24.AGENT_QUOTA_PROVIDER,
4972
+ provide: import_nestjs_agent_core26.AGENT_QUOTA_PROVIDER,
3997
4973
  useFactory: /* @__PURE__ */ __name((o, store) => isQuotaProvider(o.quota) ? o.quota : new LedgerQuotaProvider(store, o.quota?.limits, o.quota?.warnAt !== void 0 ? {
3998
4974
  warnAt: o.quota.warnAt
3999
4975
  } : {}), "useFactory"),
4000
4976
  inject: [
4001
- import_nestjs_agent_core24.AGENT_OPTIONS,
4002
- import_nestjs_agent_core24.AGENT_STORE
4977
+ import_nestjs_agent_core26.AGENT_OPTIONS,
4978
+ import_nestjs_agent_core26.AGENT_STORE
4003
4979
  ]
4004
4980
  },
4005
4981
  {
4006
- provide: import_nestjs_agent_core24.AGENT_MODEL_CATALOG,
4982
+ provide: import_nestjs_agent_core26.AGENT_MODEL_CATALOG,
4007
4983
  useFactory: /* @__PURE__ */ __name((o) => resolveCatalog(o), "useFactory"),
4008
4984
  inject: [
4009
- import_nestjs_agent_core24.AGENT_OPTIONS
4985
+ import_nestjs_agent_core26.AGENT_OPTIONS
4010
4986
  ]
4011
4987
  },
4012
4988
  AgentDepsFactory2,
4013
4989
  {
4014
- provide: import_nestjs_agent_core24.AGENT_DEPS_FACTORY,
4990
+ provide: import_nestjs_agent_core26.AGENT_DEPS_FACTORY,
4015
4991
  useExisting: AgentDepsFactory2
4016
4992
  },
4017
4993
  // Populates the registry + contributors (onModuleInit) BEFORE AiToolDiscoveryService synthesizes
@@ -4019,27 +4995,30 @@ function sharedProviders(durable) {
4019
4995
  AgentDiscoveryService,
4020
4996
  AiToolDiscoveryService,
4021
4997
  SkillDiscoveryService,
4998
+ // The thread message queue — every surface, since both runners and the durable workflow settle
4999
+ // into it, and the chat routes enqueue into it.
5000
+ ChatQueueService,
4022
5001
  InlineAgentRunner,
4023
5002
  AgentService,
4024
5003
  // Bound ALWAYS (durable or inline) — the console's cross-thread approvals inbox routes decisions
4025
5004
  // through AgentService.signalToolCall, which reaches whichever AGENT_RUNNER is bound above.
4026
5005
  AgentApprovalPortAdapter,
4027
5006
  {
4028
- provide: import_nestjs_agent_core24.AGENT_APPROVAL_PORT,
5007
+ provide: import_nestjs_agent_core26.AGENT_APPROVAL_PORT,
4029
5008
  useExisting: AgentApprovalPortAdapter
4030
5009
  }
4031
5010
  ];
4032
5011
  providers.push({
4033
- provide: import_nestjs_agent_core24.AGENT_STORE,
5012
+ provide: import_nestjs_agent_core26.AGENT_STORE,
4034
5013
  useFactory: /* @__PURE__ */ __name((o, modules) => resolveStore(o, modules), "useFactory"),
4035
5014
  inject: [
4036
- import_nestjs_agent_core24.AGENT_OPTIONS,
5015
+ import_nestjs_agent_core26.AGENT_OPTIONS,
4037
5016
  import_core4.ModulesContainer
4038
5017
  ]
4039
5018
  });
4040
5019
  if (durable) {
4041
5020
  providers.push({
4042
- provide: import_nestjs_agent_core24.AGENT_RUNNER,
5021
+ provide: import_nestjs_agent_core26.AGENT_RUNNER,
4043
5022
  useFactory: /* @__PURE__ */ __name((durableRunner) => {
4044
5023
  if (durableRunner === void 0) {
4045
5024
  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 +5027,14 @@ function sharedProviders(durable) {
4048
5027
  }, "useFactory"),
4049
5028
  inject: [
4050
5029
  {
4051
- token: import_nestjs_agent_core24.AGENT_DURABLE_RUNNER,
5030
+ token: import_nestjs_agent_core26.AGENT_DURABLE_RUNNER,
4052
5031
  optional: true
4053
5032
  }
4054
5033
  ]
4055
5034
  });
4056
5035
  } else {
4057
5036
  providers.push({
4058
- provide: import_nestjs_agent_core24.AGENT_RUNNER,
5037
+ provide: import_nestjs_agent_core26.AGENT_RUNNER,
4059
5038
  useExisting: InlineAgentRunner
4060
5039
  });
4061
5040
  }
@@ -4064,29 +5043,31 @@ function sharedProviders(durable) {
4064
5043
  __name(sharedProviders, "sharedProviders");
4065
5044
  function exportsFor() {
4066
5045
  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,
5046
+ import_nestjs_agent_core26.AGENT_OPTIONS,
5047
+ import_nestjs_agent_core26.AGENT_TOOL_REGISTRY,
5048
+ import_nestjs_agent_core26.AGENT_REGISTRY,
5049
+ import_nestjs_agent_core26.AGENT_SINK,
5050
+ import_nestjs_agent_core26.AGENT_ROLES_POLICY,
5051
+ import_nestjs_agent_core26.AGENT_ACTOR_RESOLVER,
5052
+ import_nestjs_agent_core26.AGENT_MODEL,
5053
+ import_nestjs_agent_core26.AGENT_STORE,
5054
+ import_nestjs_agent_core26.AGENT_MODEL_CATALOG,
5055
+ import_nestjs_agent_core26.AGENT_QUOTA_PROVIDER,
5056
+ import_nestjs_agent_core26.AGENT_PROMPT_CONTRIBUTORS,
5057
+ import_nestjs_agent_core26.AGENT_SKILLS,
5058
+ import_nestjs_agent_core26.AGENT_MEMORY,
5059
+ import_nestjs_agent_core26.AGENT_DEPS_FACTORY,
4081
5060
  AgentDepsFactory2,
4082
5061
  AgentService,
5062
+ ChatQueueService,
4083
5063
  InlineAgentRunner,
4084
- import_nestjs_agent_core24.AGENT_APPROVAL_PORT
5064
+ import_nestjs_agent_core26.AGENT_APPROVAL_PORT
4085
5065
  ];
4086
5066
  }
4087
5067
  __name(exportsFor, "exportsFor");
4088
5068
  var BASE_CONTROLLERS = [
4089
5069
  ChatController,
5070
+ QueueController,
4090
5071
  ThreadsController,
4091
5072
  ToolCallController,
4092
5073
  QuotaController,
@@ -4144,7 +5125,7 @@ var AgentModule = class _AgentModule {
4144
5125
  controllers: controllersForSurface(options.surface),
4145
5126
  providers: [
4146
5127
  {
4147
- provide: import_nestjs_agent_core24.AGENT_OPTIONS,
5128
+ provide: import_nestjs_agent_core26.AGENT_OPTIONS,
4148
5129
  useValue: options
4149
5130
  },
4150
5131
  ...sharedProviders(options.durable ?? false),
@@ -4167,7 +5148,7 @@ var AgentModule = class _AgentModule {
4167
5148
  controllers: controllersForSurface(options.surface),
4168
5149
  providers: [
4169
5150
  {
4170
- provide: import_nestjs_agent_core24.AGENT_OPTIONS,
5151
+ provide: import_nestjs_agent_core26.AGENT_OPTIONS,
4171
5152
  // Stamp the STATIC wiring flags onto the factory result: `durable`/`surface` are
4172
5153
  // authoritative on the async config object (they decided the actual wiring above), and
4173
5154
  // the durable module reads `durable` back off AGENT_OPTIONS. `surface` isn't read back by
@@ -4188,13 +5169,13 @@ var AgentModule = class _AgentModule {
4188
5169
  };
4189
5170
  }
4190
5171
  };
4191
- AgentModule = _ts_decorate20([
4192
- (0, import_common20.Global)(),
4193
- (0, import_common20.Module)({})
5172
+ AgentModule = _ts_decorate22([
5173
+ (0, import_common22.Global)(),
5174
+ (0, import_common22.Module)({})
4194
5175
  ], AgentModule);
4195
5176
 
4196
5177
  // src/resolver/header-actor-resolver.ts
4197
- var import_common21 = require("@nestjs/common");
5178
+ var import_common23 = require("@nestjs/common");
4198
5179
  function readHeader(req, name) {
4199
5180
  if (typeof req !== "object" || req === null || !("headers" in req)) return void 0;
4200
5181
  const { headers } = req;
@@ -4210,7 +5191,7 @@ var HeaderActorResolver = class {
4210
5191
  resolve(req) {
4211
5192
  const id = readHeader(req, "x-actor-id");
4212
5193
  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.");
5194
+ 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
5195
  }
4215
5196
  const roles = (readHeader(req, "x-actor-role") ?? "").split(",").map((role) => role.trim()).filter((role) => role.length > 0);
4216
5197
  const tenantRef = readHeader(req, "x-tenant-ref");
@@ -4225,7 +5206,7 @@ var HeaderActorResolver = class {
4225
5206
  };
4226
5207
 
4227
5208
  // src/resolver/request-user-actor-resolver.ts
4228
- var import_common22 = require("@nestjs/common");
5209
+ var import_common24 = require("@nestjs/common");
4229
5210
  function field(user, ...names) {
4230
5211
  for (const name of names) {
4231
5212
  const value = user[name];
@@ -4237,7 +5218,7 @@ __name(field, "field");
4237
5218
  function defaultRequestUserMapper(user) {
4238
5219
  const id = field(user, "id", "sub", "_id", "userId");
4239
5220
  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 }))");
5221
+ 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
5222
  }
4242
5223
  const rawRoles = field(user, "roles", "role");
4243
5224
  const roles = Array.isArray(rawRoles) ? rawRoles.map(String) : typeof rawRoles === "string" ? [
@@ -4258,7 +5239,7 @@ function requestUserActorResolver(map) {
4258
5239
  async resolve(req) {
4259
5240
  const user = typeof req === "object" && req !== null ? req.user : void 0;
4260
5241
  if (user === void 0 || user === null || user === false) {
4261
- throw new import_common22.UnauthorizedException("Sign in to use the agent.");
5242
+ throw new import_common24.UnauthorizedException("Sign in to use the agent.");
4262
5243
  }
4263
5244
  if (map !== void 0) return map(user, req);
4264
5245
  return defaultRequestUserMapper(user);
@@ -4285,6 +5266,7 @@ __reExport(index_exports, require("@dudousxd/nestjs-agent-core"), module.exports
4285
5266
  AiToolDiscoveryService,
4286
5267
  AnonymousActorResolver,
4287
5268
  AttachmentsController,
5269
+ ChatQueueService,
4288
5270
  ConfigController,
4289
5271
  DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES,
4290
5272
  DEFAULT_MAX_ATTACHMENT_BYTES,
@@ -4296,6 +5278,7 @@ __reExport(index_exports, require("@dudousxd/nestjs-agent-core"), module.exports
4296
5278
  MemoriesController,
4297
5279
  MessagesController,
4298
5280
  ModelsController,
5281
+ QueueController,
4299
5282
  SKILL_METADATA,
4300
5283
  SYSTEM_PROMPT_CONTRIBUTOR_METADATA,
4301
5284
  SYSTEM_PROMPT_METADATA,