@dudousxd/nestjs-agent 1.21.0 → 1.22.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
@@ -68,6 +68,7 @@ __export(index_exports, {
68
68
  attachmentLimits: () => attachmentLimits,
69
69
  declaredSkillProvider: () => declaredSkillProvider,
70
70
  defaultRequestUserMapper: () => defaultRequestUserMapper,
71
+ defineTool: () => defineTool,
71
72
  delegateToolName: () => delegateToolName,
72
73
  provideAgentTool: () => provideAgentTool,
73
74
  provideAgentTools: () => provideAgentTools,
@@ -84,14 +85,14 @@ __export(index_exports, {
84
85
  module.exports = __toCommonJS(index_exports);
85
86
 
86
87
  // src/agent.module.ts
87
- var import_nestjs_agent_core31 = require("@dudousxd/nestjs-agent-core");
88
+ var import_nestjs_agent_core33 = require("@dudousxd/nestjs-agent-core");
88
89
  var import_common27 = require("@nestjs/common");
89
90
  var import_core4 = require("@nestjs/core");
90
91
 
91
92
  // src/agent-deps.factory.ts
92
- var import_nestjs_agent_core = require("@dudousxd/nestjs-agent-core");
93
93
  var import_nestjs_agent_core2 = require("@dudousxd/nestjs-agent-core");
94
94
  var import_nestjs_agent_core3 = require("@dudousxd/nestjs-agent-core");
95
+ var import_nestjs_agent_core4 = require("@dudousxd/nestjs-agent-core");
95
96
  var import_common2 = require("@nestjs/common");
96
97
 
97
98
  // src/genui/agent-genui.module.ts
@@ -99,6 +100,7 @@ var import_genui = require("@dudousxd/nestjs-agent-core/genui");
99
100
  var import_common = require("@nestjs/common");
100
101
 
101
102
  // src/functional-tool.ts
103
+ var import_nestjs_agent_core = require("@dudousxd/nestjs-agent-core");
102
104
  var AGENT_TOOL_BRAND = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:functional-tool");
103
105
  function brand(tool) {
104
106
  return {
@@ -135,6 +137,7 @@ function provideAgentTools(factory, inject) {
135
137
  };
136
138
  }
137
139
  __name(provideAgentTools, "provideAgentTools");
140
+ var defineTool = import_nestjs_agent_core.createFunctionalTool;
138
141
 
139
142
  // src/genui/agent-genui.module.ts
140
143
  function _ts_decorate(decorators, target, key, desc) {
@@ -317,7 +320,7 @@ var AgentDepsFactory2 = class {
317
320
  this.memory = memory;
318
321
  this.uiCatalog = uiCatalog;
319
322
  this.uiCatalogResolver = uiCatalogResolver;
320
- if (options.actionApprovalMode === "independent") (0, import_nestjs_agent_core.assertIndependentActionCapabilities)(store, options.backgroundActorResolver);
323
+ if (options.actionApprovalMode === "independent") (0, import_nestjs_agent_core2.assertIndependentActionCapabilities)(store, options.backgroundActorResolver);
321
324
  }
322
325
  /** The turn's memory seam, shared with the read-back endpoint. Undefined → memory is not configured. */
323
326
  memoryConfig() {
@@ -343,7 +346,7 @@ var AgentDepsFactory2 = class {
343
346
  return void 0;
344
347
  }
345
348
  const delegated = (definition.delegatesTo ?? []).map((edge) => {
346
- const { agent, detached } = (0, import_nestjs_agent_core2.normalizeDelegation)(edge);
349
+ const { agent, detached } = (0, import_nestjs_agent_core3.normalizeDelegation)(edge);
347
350
  return delegateToolName({
348
351
  target: agent,
349
352
  detached
@@ -367,7 +370,7 @@ var AgentDepsFactory2 = class {
367
370
  agentName: name
368
371
  };
369
372
  }
370
- const alias = (0, import_nestjs_agent_core2.resolvePersonaAlias)(this.agents.list(), name);
373
+ const alias = (0, import_nestjs_agent_core3.resolvePersonaAlias)(this.agents.list(), name);
371
374
  return alias === void 0 ? {
372
375
  agentName: name
373
376
  } : {
@@ -377,7 +380,7 @@ var AgentDepsFactory2 = class {
377
380
  }
378
381
  /** `agentName`'s personas as a picker reads them. Empty when it declares none. */
379
382
  personaCatalog(agentName) {
380
- return (this.agents.get(agentName)?.personas ?? []).map(import_nestjs_agent_core2.personaCatalogEntry);
383
+ return (this.agents.get(agentName)?.personas ?? []).map(import_nestjs_agent_core3.personaCatalogEntry);
381
384
  }
382
385
  /** The persona `agentName` runs under when nothing names one. Undefined → none. */
383
386
  defaultPersona(agentName) {
@@ -391,7 +394,7 @@ var AgentDepsFactory2 = class {
391
394
  resolvePersona(args) {
392
395
  const definition = this.agents.get(args.agentName);
393
396
  if (args.requested !== void 0) {
394
- if ((0, import_nestjs_agent_core2.findPersona)(definition, args.requested) === void 0) {
397
+ if ((0, import_nestjs_agent_core3.findPersona)(definition, args.requested) === void 0) {
395
398
  throw new import_common2.BadRequestException({
396
399
  statusCode: 400,
397
400
  code: "persona_not_found",
@@ -401,7 +404,7 @@ var AgentDepsFactory2 = class {
401
404
  return args.requested;
402
405
  }
403
406
  const pinned = args.threadPersona ?? void 0;
404
- if (pinned !== void 0 && (0, import_nestjs_agent_core2.findPersona)(definition, pinned) !== void 0) {
407
+ if (pinned !== void 0 && (0, import_nestjs_agent_core3.findPersona)(definition, pinned) !== void 0) {
405
408
  return pinned;
406
409
  }
407
410
  return definition?.defaultPersona;
@@ -421,8 +424,8 @@ var AgentDepsFactory2 = class {
421
424
  forAgent(agentName) {
422
425
  const name = agentName ?? this.defaultAgentName();
423
426
  if (agentName !== void 0 && !this.agents.has(agentName)) {
424
- const alias = (0, import_nestjs_agent_core2.resolvePersonaAlias)(this.agents.list(), agentName);
425
- const persona = alias === void 0 ? void 0 : (0, import_nestjs_agent_core2.findPersona)(this.agents.get(alias.agent), alias.persona);
427
+ const alias = (0, import_nestjs_agent_core3.resolvePersonaAlias)(this.agents.list(), agentName);
428
+ const persona = alias === void 0 ? void 0 : (0, import_nestjs_agent_core3.findPersona)(this.agents.get(alias.agent), alias.persona);
426
429
  if (alias !== void 0 && persona !== void 0) {
427
430
  return this.withPersona(this.forAgent(alias.agent), persona);
428
431
  }
@@ -556,7 +559,7 @@ var AgentDepsFactory2 = class {
556
559
  } : {}
557
560
  });
558
561
  }, "systemPrompt");
559
- const toolAllowList = (0, import_nestjs_agent_core2.intersectAllowLists)(deps.toolAllowList, persona.allowedTools);
562
+ const toolAllowList = (0, import_nestjs_agent_core3.intersectAllowLists)(deps.toolAllowList, persona.allowedTools);
560
563
  return {
561
564
  ...deps,
562
565
  systemPrompt,
@@ -581,7 +584,7 @@ var AgentDepsFactory2 = class {
581
584
  }
582
585
  /** Build the built-in window policy from the declarative `{ maxMessages, maxTokens, summarize }`. */
583
586
  window(config) {
584
- return (0, import_nestjs_agent_core2.windowHistory)({
587
+ return (0, import_nestjs_agent_core3.windowHistory)({
585
588
  ...config.maxMessages !== void 0 ? {
586
589
  maxMessages: config.maxMessages
587
590
  } : {},
@@ -591,7 +594,7 @@ var AgentDepsFactory2 = class {
591
594
  // The shared module model, not a per-agent one: an agent's `modelId` is an accounting label,
592
595
  // and only one provider is ever bound.
593
596
  ...config.summarize === true ? {
594
- summarize: (0, import_nestjs_agent_core2.summarizeWithModel)(this.model)
597
+ summarize: (0, import_nestjs_agent_core3.summarizeWithModel)(this.model)
595
598
  } : {}
596
599
  });
597
600
  }
@@ -609,20 +612,20 @@ var AgentDepsFactory2 = class {
609
612
  };
610
613
  AgentDepsFactory2 = _ts_decorate2([
611
614
  (0, import_common2.Injectable)(),
612
- _ts_param(0, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_OPTIONS)),
613
- _ts_param(1, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_MODEL)),
614
- _ts_param(2, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_STORE)),
615
- _ts_param(3, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_SINK)),
616
- _ts_param(4, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_ROLES_POLICY)),
617
- _ts_param(5, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_TOOL_REGISTRY)),
618
- _ts_param(6, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_REGISTRY)),
619
- _ts_param(7, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_PROMPT_CONTRIBUTORS)),
615
+ _ts_param(0, (0, import_common2.Inject)(import_nestjs_agent_core4.AGENT_OPTIONS)),
616
+ _ts_param(1, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_MODEL)),
617
+ _ts_param(2, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_STORE)),
618
+ _ts_param(3, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_SINK)),
619
+ _ts_param(4, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_ROLES_POLICY)),
620
+ _ts_param(5, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_TOOL_REGISTRY)),
621
+ _ts_param(6, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_REGISTRY)),
622
+ _ts_param(7, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_PROMPT_CONTRIBUTORS)),
620
623
  _ts_param(8, (0, import_common2.Optional)()),
621
- _ts_param(8, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_PRICING_STORE)),
624
+ _ts_param(8, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_PRICING_STORE)),
622
625
  _ts_param(9, (0, import_common2.Optional)()),
623
- _ts_param(9, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_SKILLS)),
626
+ _ts_param(9, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_SKILLS)),
624
627
  _ts_param(10, (0, import_common2.Optional)()),
625
- _ts_param(10, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_MEMORY)),
628
+ _ts_param(10, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_MEMORY)),
626
629
  _ts_param(11, (0, import_common2.Optional)()),
627
630
  _ts_param(11, (0, import_common2.Inject)(GENUI_CATALOG)),
628
631
  _ts_param(12, (0, import_common2.Optional)()),
@@ -633,8 +636,8 @@ AgentDepsFactory2 = _ts_decorate2([
633
636
  typeof AgentStore === "undefined" ? Object : AgentStore,
634
637
  typeof TokenStreamSink === "undefined" ? Object : TokenStreamSink,
635
638
  typeof RolesPolicy === "undefined" ? Object : RolesPolicy,
636
- typeof import_nestjs_agent_core2.ToolRegistry === "undefined" ? Object : import_nestjs_agent_core2.ToolRegistry,
637
- typeof import_nestjs_agent_core2.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core2.AgentRegistry,
639
+ typeof import_nestjs_agent_core3.ToolRegistry === "undefined" ? Object : import_nestjs_agent_core3.ToolRegistry,
640
+ typeof import_nestjs_agent_core3.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core3.AgentRegistry,
638
641
  Array,
639
642
  Object,
640
643
  Object,
@@ -645,7 +648,7 @@ AgentDepsFactory2 = _ts_decorate2([
645
648
  ], AgentDepsFactory2);
646
649
 
647
650
  // src/agent.service.ts
648
- var import_nestjs_agent_core7 = require("@dudousxd/nestjs-agent-core");
651
+ var import_nestjs_agent_core9 = require("@dudousxd/nestjs-agent-core");
649
652
  var import_common6 = require("@nestjs/common");
650
653
 
651
654
  // src/agent-deps.ts
@@ -671,7 +674,7 @@ function childSinkWriter(writer) {
671
674
  __name(childSinkWriter, "childSinkWriter");
672
675
 
673
676
  // src/proposals/action-proposal.service.ts
674
- var import_nestjs_agent_core4 = require("@dudousxd/nestjs-agent-core");
677
+ var import_nestjs_agent_core5 = require("@dudousxd/nestjs-agent-core");
675
678
  var import_common3 = require("@nestjs/common");
676
679
  function _ts_decorate3(decorators, target, key, desc) {
677
680
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -708,7 +711,19 @@ var ActionProposalService = class {
708
711
  constructor(store, options) {
709
712
  this.store = store;
710
713
  this.options = options;
714
+ const text = options.actionProposalText;
715
+ this.vocabulary = {
716
+ ...import_nestjs_agent_core5.DEFAULT_TEXT_ACTION_PROPOSAL_VOCABULARY,
717
+ ...text?.vocabulary
718
+ };
719
+ this.replies = {
720
+ ...import_nestjs_agent_core5.DEFAULT_TEXT_ACTION_PROPOSAL_REPLIES,
721
+ ...text?.replies
722
+ };
711
723
  }
724
+ /** The words a text decision is made of, and what the agent answers — English unless configured. */
725
+ vocabulary;
726
+ replies;
712
727
  capability() {
713
728
  const store = this.store;
714
729
  if (typeof store.getThreadActionProposalScope !== "function" || typeof store.listActionProposals !== "function") throw new import_common3.NotImplementedException("Action proposals are unavailable");
@@ -721,7 +736,7 @@ var ActionProposalService = class {
721
736
  return scope;
722
737
  }
723
738
  mayDecide(actor, proposal) {
724
- return (0, import_nestjs_agent_core4.mayDecideApproval)(this.options.approvalPolicy, actor, {
739
+ return (0, import_nestjs_agent_core5.mayDecideApproval)(this.options.approvalPolicy, actor, {
725
740
  toolCallId: proposal.originToolCallId,
726
741
  approver: proposal.approver,
727
742
  requesterRef: proposal.actorRef
@@ -737,7 +752,8 @@ var ActionProposalService = class {
737
752
  for (const row of rows) if (scope.actorRef === actor.id || await this.mayDecide(actor, row)) visible.push(row);
738
753
  const last = rows.at(-1);
739
754
  return {
740
- items: visible,
755
+ // The public view: a row carries the worker's lease token and the tool's idempotency key.
756
+ items: visible.map(import_nestjs_agent_core5.toActionProposalView),
741
757
  ...rows.length === 1e3 && last ? {
742
758
  next: {
743
759
  createdAt: last.createdAt,
@@ -754,7 +770,7 @@ var ActionProposalService = class {
754
770
  const proposal = await this.capability().getActionProposal(scope, proposalId);
755
771
  if (!proposal) throw new import_common3.NotFoundException("Proposal not found");
756
772
  if (!await this.mayDecide(actor, proposal)) throw new import_common3.ForbiddenException("May not decide this proposal");
757
- return this.capability().decideActionProposal(scope, proposalId, {
773
+ const result = await this.capability().decideActionProposal(scope, proposalId, {
758
774
  decision: command.decision,
759
775
  actorRef: actor.id,
760
776
  via: command.via ?? "web",
@@ -765,9 +781,10 @@ var ActionProposalService = class {
765
781
  reason: command.reason
766
782
  } : {}
767
783
  });
784
+ return (0, import_nestjs_agent_core5.toActionProposalMutationView)(result);
768
785
  }
769
786
  async handleTextDecision(threadId, actor, text) {
770
- const command = (0, import_nestjs_agent_core4.parseTextActionProposalCommand)(text);
787
+ const command = (0, import_nestjs_agent_core5.parseTextActionProposalCommand)(text, this.vocabulary);
771
788
  if (command.status === "unmatched") return command;
772
789
  if (command.proposalId !== void 0) {
773
790
  const result2 = await this.decide(threadId, command.proposalId, actor, {
@@ -775,7 +792,7 @@ var ActionProposalService = class {
775
792
  remember: command.remember,
776
793
  via: "text"
777
794
  });
778
- return this.textReceipt(threadId, result2);
795
+ return this.textReceipt(threadId, result2, command.decision);
779
796
  }
780
797
  const candidates = [];
781
798
  const scope = await this.scope(threadId, actor);
@@ -784,35 +801,43 @@ var ActionProposalService = class {
784
801
  limit: 1e3
785
802
  });
786
803
  for (const proposal of pending) if (await this.mayDecide(actor, proposal)) candidates.push(proposal);
787
- const resolution = (0, import_nestjs_agent_core4.resolveTextActionProposalDecision)(text, candidates);
804
+ const resolution = (0, import_nestjs_agent_core5.resolveTextActionProposalDecision)(text, candidates, this.vocabulary);
788
805
  if (resolution.status === "unmatched") return resolution;
789
- if (resolution.status === "ambiguous" || resolution.status === "decision" && pending.length === 1e3 && !text.includes("#")) return {
790
- threadId,
791
- proposalDecision: {
792
- status: "ambiguous",
793
- proposalIds: candidates.map(({ id }) => id)
794
- },
795
- text: `Choose the action to decide: ${candidates.map(({ id }) => id).map((id) => `#${id}`).join(", ")}`
796
- };
806
+ const saturated = pending.length === 1e3 && !text.includes("#");
807
+ if (resolution.status === "ambiguous" || saturated) {
808
+ const proposalIds = candidates.map(({ id }) => id);
809
+ return {
810
+ threadId,
811
+ proposalDecision: {
812
+ status: "ambiguous",
813
+ proposalIds
814
+ },
815
+ text: saturated ? this.replies.tooMany : this.replies.ambiguous(proposalIds)
816
+ };
817
+ }
797
818
  const result = await this.decide(threadId, resolution.proposalId, actor, {
798
819
  decision: resolution.decision,
799
820
  remember: resolution.remember,
800
821
  via: "text"
801
822
  });
802
- return this.textReceipt(threadId, result);
823
+ return this.textReceipt(threadId, result, resolution.decision);
803
824
  }
804
- textReceipt(threadId, result) {
825
+ textReceipt(threadId, result, decision) {
805
826
  return {
806
827
  threadId,
807
828
  proposalDecision: result,
808
- text: result.proposal?.decision === "approved" ? "Action approved and queued for execution." : `Action ${result.proposal?.decision ?? result.status}; no execution was performed by this decision.`
829
+ text: this.reply(result, decision)
809
830
  };
810
831
  }
832
+ /** The configured reply to a decision the store answered with `result`. */
833
+ reply(result, decision) {
834
+ return (0, import_nestjs_agent_core5.textActionProposalReply)(result, decision, this.replies);
835
+ }
811
836
  };
812
837
  ActionProposalService = _ts_decorate3([
813
838
  (0, import_common3.Injectable)(),
814
- _ts_param2(0, (0, import_common3.Inject)(import_nestjs_agent_core4.AGENT_STORE)),
815
- _ts_param2(1, (0, import_common3.Inject)(import_nestjs_agent_core4.AGENT_OPTIONS)),
839
+ _ts_param2(0, (0, import_common3.Inject)(import_nestjs_agent_core5.AGENT_STORE)),
840
+ _ts_param2(1, (0, import_common3.Inject)(import_nestjs_agent_core5.AGENT_OPTIONS)),
816
841
  _ts_metadata2("design:type", Function),
817
842
  _ts_metadata2("design:paramtypes", [
818
843
  typeof AgentStore === "undefined" ? Object : AgentStore,
@@ -821,9 +846,36 @@ ActionProposalService = _ts_decorate3([
821
846
  ], ActionProposalService);
822
847
 
823
848
  // src/queue/chat-queue.service.ts
824
- var import_nestjs_agent_core5 = require("@dudousxd/nestjs-agent-core");
849
+ var import_nestjs_agent_core7 = require("@dudousxd/nestjs-agent-core");
825
850
  var import_common4 = require("@nestjs/common");
826
851
 
852
+ // src/quota-exceeded.ts
853
+ var import_nestjs_agent_core6 = require("@dudousxd/nestjs-agent-core");
854
+ function publishQuotaBlocked(actor, report, blocked) {
855
+ const window = report.windows.find((candidate) => candidate.period === blocked.period);
856
+ const payload = {
857
+ actorId: actor.id,
858
+ period: blocked.period,
859
+ ...blocked.reason !== void 0 ? {
860
+ reason: blocked.reason
861
+ } : {},
862
+ ...window?.usedTokens !== void 0 ? {
863
+ usedTokens: window.usedTokens
864
+ } : {},
865
+ ...window?.limitTokens !== void 0 ? {
866
+ limitTokens: window.limitTokens
867
+ } : {},
868
+ ...window !== void 0 ? {
869
+ usedUsd: window.usedUsd
870
+ } : {},
871
+ ...window?.limitUsd !== void 0 ? {
872
+ limitUsd: window.limitUsd
873
+ } : {}
874
+ };
875
+ (0, import_nestjs_agent_core6.publishAgentQuotaExceeded)(payload);
876
+ }
877
+ __name(publishQuotaBlocked, "publishQuotaBlocked");
878
+
827
879
  // src/thread-persona.ts
828
880
  async function threadPersona(store, threadId) {
829
881
  const projecting = store;
@@ -888,11 +940,11 @@ var ChatQueueService = class _ChatQueueService {
888
940
  }
889
941
  /** Whether the bound store can hold a queue. Without one, a busy thread is not queued. */
890
942
  get supported() {
891
- return (0, import_nestjs_agent_core5.isChatQueueStore)(this.store);
943
+ return (0, import_nestjs_agent_core7.isChatQueueStore)(this.store);
892
944
  }
893
945
  /** The bound store as a queue store, or a 501 naming what is missing. */
894
946
  queueStore() {
895
- if (!(0, import_nestjs_agent_core5.isChatQueueStore)(this.store)) {
947
+ if (!(0, import_nestjs_agent_core7.isChatQueueStore)(this.store)) {
896
948
  throw new import_common4.NotImplementedException("Queueing messages requires an AgentStore that implements ChatQueueStore (enqueueMessage, listQueue, \u2026, claimActiveStream, releaseActiveStream); the bound store does not.");
897
949
  }
898
950
  return this.store;
@@ -904,7 +956,7 @@ var ChatQueueService = class _ChatQueueService {
904
956
  store.queuePause(threadId)
905
957
  ]);
906
958
  return {
907
- items: items.map(import_nestjs_agent_core5.queuedMessageView),
959
+ items: items.map(import_nestjs_agent_core7.queuedMessageView),
908
960
  paused
909
961
  };
910
962
  }
@@ -955,7 +1007,7 @@ var ChatQueueService = class _ChatQueueService {
955
1007
  * A no-op returning `{}` on a store without a queue.
956
1008
  */
957
1009
  async plan(args) {
958
- if (!(0, import_nestjs_agent_core5.isChatQueueStore)(this.store)) {
1010
+ if (!(0, import_nestjs_agent_core7.isChatQueueStore)(this.store)) {
959
1011
  return {};
960
1012
  }
961
1013
  const store = this.store;
@@ -1055,7 +1107,7 @@ var ChatQueueService = class _ChatQueueService {
1055
1107
  * (its settle drains) or while the queue is paused. Answers the started run's id, if any.
1056
1108
  */
1057
1109
  async kick(threadId, runner) {
1058
- if (!(0, import_nestjs_agent_core5.isChatQueueStore)(this.store)) {
1110
+ if (!(0, import_nestjs_agent_core7.isChatQueueStore)(this.store)) {
1059
1111
  return void 0;
1060
1112
  }
1061
1113
  const { live, stale } = await this.holder(threadId, runner);
@@ -1159,7 +1211,7 @@ var ChatQueueService = class _ChatQueueService {
1159
1211
  }
1160
1212
  async write(runId, frame) {
1161
1213
  const writer = await this.sink.open(runId);
1162
- await writer.write((0, import_nestjs_agent_core5.encodeStreamEvent)(frame));
1214
+ await writer.write((0, import_nestjs_agent_core7.encodeStreamEvent)(frame));
1163
1215
  }
1164
1216
  /** Why `actor` may not start a turn now (the quota message), or `null`. */
1165
1217
  async quotaBlock(actor) {
@@ -1167,12 +1219,14 @@ var ChatQueueService = class _ChatQueueService {
1167
1219
  return null;
1168
1220
  }
1169
1221
  try {
1170
- const { blocked } = await this.quotaProvider.report({
1222
+ const report = await this.quotaProvider.report({
1171
1223
  actor
1172
1224
  });
1225
+ const { blocked } = report;
1173
1226
  if (blocked === void 0) {
1174
1227
  return null;
1175
1228
  }
1229
+ publishQuotaBlocked(actor, report, blocked);
1176
1230
  return blocked.reason ?? `The ${blocked.period === "day" ? "daily" : "monthly"} quota is used up`;
1177
1231
  } catch {
1178
1232
  return null;
@@ -1261,16 +1315,16 @@ var ChatQueueService = class _ChatQueueService {
1261
1315
  };
1262
1316
  ChatQueueService = _ts_decorate4([
1263
1317
  (0, import_common4.Injectable)(),
1264
- _ts_param3(0, (0, import_common4.Inject)(import_nestjs_agent_core5.AGENT_STORE)),
1265
- _ts_param3(1, (0, import_common4.Inject)(import_nestjs_agent_core5.AGENT_SINK)),
1318
+ _ts_param3(0, (0, import_common4.Inject)(import_nestjs_agent_core7.AGENT_STORE)),
1319
+ _ts_param3(1, (0, import_common4.Inject)(import_nestjs_agent_core7.AGENT_SINK)),
1266
1320
  _ts_param3(2, (0, import_common4.Optional)()),
1267
- _ts_param3(2, (0, import_common4.Inject)(import_nestjs_agent_core5.AGENT_QUOTA_PROVIDER)),
1321
+ _ts_param3(2, (0, import_common4.Inject)(import_nestjs_agent_core7.AGENT_QUOTA_PROVIDER)),
1268
1322
  _ts_param3(3, (0, import_common4.Optional)()),
1269
- _ts_param3(3, (0, import_common4.Inject)(import_nestjs_agent_core5.AGENT_OPTIONS)),
1323
+ _ts_param3(3, (0, import_common4.Inject)(import_nestjs_agent_core7.AGENT_OPTIONS)),
1270
1324
  _ts_param3(4, (0, import_common4.Optional)()),
1271
- _ts_param3(4, (0, import_common4.Inject)(import_nestjs_agent_core5.AGENT_ATTACHMENT_STAGING)),
1325
+ _ts_param3(4, (0, import_common4.Inject)(import_nestjs_agent_core7.AGENT_ATTACHMENT_STAGING)),
1272
1326
  _ts_param3(5, (0, import_common4.Optional)()),
1273
- _ts_param3(5, (0, import_common4.Inject)(import_nestjs_agent_core5.AGENT_DEPS_FACTORY)),
1327
+ _ts_param3(5, (0, import_common4.Inject)(import_nestjs_agent_core7.AGENT_DEPS_FACTORY)),
1274
1328
  _ts_metadata3("design:type", Function),
1275
1329
  _ts_metadata3("design:paramtypes", [
1276
1330
  typeof AgentStore === "undefined" ? Object : AgentStore,
@@ -1295,7 +1349,7 @@ function queueFrame(items, paused, started) {
1295
1349
  return {
1296
1350
  kind: "queue",
1297
1351
  queue: {
1298
- items: items.map(import_nestjs_agent_core5.queuedMessageView),
1352
+ items: items.map(import_nestjs_agent_core7.queuedMessageView),
1299
1353
  paused
1300
1354
  },
1301
1355
  ...started !== void 0 ? {
@@ -1306,19 +1360,19 @@ function queueFrame(items, paused, started) {
1306
1360
  __name(queueFrame, "queueFrame");
1307
1361
 
1308
1362
  // src/run-not-active.exception.ts
1309
- var import_nestjs_agent_core6 = require("@dudousxd/nestjs-agent-core");
1363
+ var import_nestjs_agent_core8 = require("@dudousxd/nestjs-agent-core");
1310
1364
  var import_common5 = require("@nestjs/common");
1311
1365
  var RunNotActiveException = class extends import_common5.ConflictException {
1312
1366
  static {
1313
1367
  __name(this, "RunNotActiveException");
1314
1368
  }
1315
1369
  runId;
1316
- code = import_nestjs_agent_core6.RUN_NOT_ACTIVE_CODE;
1370
+ code = import_nestjs_agent_core8.RUN_NOT_ACTIVE_CODE;
1317
1371
  constructor(runId) {
1318
1372
  super({
1319
1373
  statusCode: 409,
1320
- code: import_nestjs_agent_core6.RUN_NOT_ACTIVE_CODE,
1321
- message: import_nestjs_agent_core6.RUN_NOT_ACTIVE_MESSAGE
1374
+ code: import_nestjs_agent_core8.RUN_NOT_ACTIVE_CODE,
1375
+ message: import_nestjs_agent_core8.RUN_NOT_ACTIVE_MESSAGE
1322
1376
  }), this.runId = runId;
1323
1377
  }
1324
1378
  };
@@ -1374,6 +1428,21 @@ var AgentService = class {
1374
1428
  this.queue = queue;
1375
1429
  this.proposals = proposals;
1376
1430
  }
1431
+ /**
1432
+ * Decide one independent proposal through the scoped proposal service — what the native
1433
+ * `action-proposals/:id/approve|reject` routes call — and the reply to show for it. `404` when
1434
+ * proposals are not on, `403`/`404` when this actor may not decide it.
1435
+ */
1436
+ async decideActionProposal(actor, threadId, proposalId, command) {
1437
+ if (this.options?.actionApprovalMode !== "independent" || !this.proposals) {
1438
+ throw new import_common6.NotFoundException("Proposal not found");
1439
+ }
1440
+ const result = await this.proposals.decide(threadId, proposalId, actor, command);
1441
+ return {
1442
+ proposalDecision: result,
1443
+ text: this.proposals.reply(result, command.decision)
1444
+ };
1445
+ }
1377
1446
  async handleTextDecision(threadId, actor, text) {
1378
1447
  if (this.options?.actionApprovalMode !== "independent" || !this.proposals) return {
1379
1448
  status: "unmatched"
@@ -1421,10 +1490,12 @@ var AgentService = class {
1421
1490
  if (this.options?.quota === void 0 || this.quotaProvider === void 0) {
1422
1491
  return;
1423
1492
  }
1424
- const { blocked } = await this.quotaProvider.report({
1493
+ const report = await this.quotaProvider.report({
1425
1494
  actor
1426
1495
  });
1496
+ const { blocked } = report;
1427
1497
  if (blocked !== void 0) {
1498
+ publishQuotaBlocked(actor, report, blocked);
1428
1499
  throw new import_common6.HttpException({
1429
1500
  statusCode: import_common6.HttpStatus.TOO_MANY_REQUESTS,
1430
1501
  code: "quota_exceeded",
@@ -1460,7 +1531,7 @@ var AgentService = class {
1460
1531
  if (this.models === void 0) {
1461
1532
  throw new import_common6.BadRequestException(`model "${model}" cannot be selected: no ModelCatalog is configured (AgentModule.forRoot({ models }))`);
1462
1533
  }
1463
- const entry = (0, import_nestjs_agent_core7.findCatalogModel)(await this.models.list({
1534
+ const entry = (0, import_nestjs_agent_core9.findCatalogModel)(await this.models.list({
1464
1535
  actor,
1465
1536
  agent
1466
1537
  }), model);
@@ -1614,7 +1685,7 @@ var AgentService = class {
1614
1685
  const mode = params.mode ?? "auto";
1615
1686
  const { live, stale } = await queue.holder(threadId, this.runner);
1616
1687
  if (stale !== null) {
1617
- await (0, import_nestjs_agent_core7.settleDeadRun)(this.store, {
1688
+ await (0, import_nestjs_agent_core9.settleDeadRun)(this.store, {
1618
1689
  runId: stale
1619
1690
  });
1620
1691
  }
@@ -2003,7 +2074,7 @@ var AgentService = class {
2003
2074
  if (active) {
2004
2075
  return;
2005
2076
  }
2006
- await (0, import_nestjs_agent_core7.settleDeadRun)(this.store, {
2077
+ await (0, import_nestjs_agent_core9.settleDeadRun)(this.store, {
2007
2078
  runId
2008
2079
  });
2009
2080
  throw new RunNotActiveException(runId);
@@ -2371,10 +2442,10 @@ var AgentService = class {
2371
2442
  if (this.store.toolCallInput === void 0) {
2372
2443
  return;
2373
2444
  }
2374
- const questions = (0, import_nestjs_agent_core7.readElicitationQuestions)(await this.store.toolCallInput(toolCallId2));
2445
+ const questions = (0, import_nestjs_agent_core9.readElicitationQuestions)(await this.store.toolCallInput(toolCallId2));
2375
2446
  for (const question of questions) {
2376
2447
  const submitted = Object.hasOwn(answers2, question.id) ? answers2[question.id] : void 0;
2377
- const problem = (0, import_nestjs_agent_core7.validateElicitationAnswer)(question, submitted ?? question.defaults ?? []);
2448
+ const problem = (0, import_nestjs_agent_core9.validateElicitationAnswer)(question, submitted ?? question.defaults ?? []);
2378
2449
  if (problem !== null) {
2379
2450
  throw new import_common6.BadRequestException(`answers["${question.id}"] ${problem}`);
2380
2451
  }
@@ -2388,15 +2459,15 @@ var AgentService = class {
2388
2459
  */
2389
2460
  async assertMayDecide(actor, toolCallId2) {
2390
2461
  const approval = await this.store.toolCallApproval?.(toolCallId2);
2391
- const approver = approval?.approver ?? import_nestjs_agent_core7.REQUESTER_APPROVER;
2392
- if (approver === import_nestjs_agent_core7.REQUESTER_APPROVER) {
2462
+ const approver = approval?.approver ?? import_nestjs_agent_core9.REQUESTER_APPROVER;
2463
+ if (approver === import_nestjs_agent_core9.REQUESTER_APPROVER) {
2393
2464
  return this.assertOwnsToolCall(actor, toolCallId2);
2394
2465
  }
2395
2466
  const requesterRef = await this.store.ownerOfToolCall(toolCallId2);
2396
2467
  if (requesterRef === null) {
2397
2468
  throw new import_common6.NotFoundException(`tool call ${toolCallId2} not found`);
2398
2469
  }
2399
- const allowed = await (0, import_nestjs_agent_core7.mayDecideApproval)(this.deps.forAgent().approvalPolicy, actor, {
2470
+ const allowed = await (0, import_nestjs_agent_core9.mayDecideApproval)(this.deps.forAgent().approvalPolicy, actor, {
2400
2471
  toolCallId: toolCallId2,
2401
2472
  approver,
2402
2473
  requesterRef
@@ -2448,17 +2519,17 @@ var AgentService = class {
2448
2519
  };
2449
2520
  AgentService = _ts_decorate5([
2450
2521
  (0, import_common6.Injectable)(),
2451
- _ts_param4(0, (0, import_common6.Inject)(import_nestjs_agent_core7.AGENT_RUNNER)),
2452
- _ts_param4(1, (0, import_common6.Inject)(import_nestjs_agent_core7.AGENT_STORE)),
2453
- _ts_param4(2, (0, import_common6.Inject)(import_nestjs_agent_core7.AGENT_DEPS_FACTORY)),
2522
+ _ts_param4(0, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_RUNNER)),
2523
+ _ts_param4(1, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_STORE)),
2524
+ _ts_param4(2, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_DEPS_FACTORY)),
2454
2525
  _ts_param4(3, (0, import_common6.Optional)()),
2455
- _ts_param4(3, (0, import_common6.Inject)(import_nestjs_agent_core7.AGENT_ATTACHMENT_STAGING)),
2526
+ _ts_param4(3, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_ATTACHMENT_STAGING)),
2456
2527
  _ts_param4(4, (0, import_common6.Optional)()),
2457
- _ts_param4(4, (0, import_common6.Inject)(import_nestjs_agent_core7.AGENT_MODEL_CATALOG)),
2528
+ _ts_param4(4, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_MODEL_CATALOG)),
2458
2529
  _ts_param4(5, (0, import_common6.Optional)()),
2459
- _ts_param4(5, (0, import_common6.Inject)(import_nestjs_agent_core7.AGENT_QUOTA_PROVIDER)),
2530
+ _ts_param4(5, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_QUOTA_PROVIDER)),
2460
2531
  _ts_param4(6, (0, import_common6.Optional)()),
2461
- _ts_param4(6, (0, import_common6.Inject)(import_nestjs_agent_core7.AGENT_OPTIONS)),
2532
+ _ts_param4(6, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_OPTIONS)),
2462
2533
  _ts_param4(7, (0, import_common6.Optional)()),
2463
2534
  _ts_param4(8, (0, import_common6.Optional)()),
2464
2535
  _ts_metadata4("design:type", Function),
@@ -2573,7 +2644,7 @@ AgentApprovalPortAdapter = _ts_decorate6([
2573
2644
  ], AgentApprovalPortAdapter);
2574
2645
 
2575
2646
  // src/controller/agents.controller.ts
2576
- var import_nestjs_agent_core8 = require("@dudousxd/nestjs-agent-core");
2647
+ var import_nestjs_agent_core10 = require("@dudousxd/nestjs-agent-core");
2577
2648
  var import_common8 = require("@nestjs/common");
2578
2649
  function _ts_decorate7(decorators, target, key, desc) {
2579
2650
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -2639,17 +2710,17 @@ _ts_decorate7([
2639
2710
  ], AgentsController.prototype, "list", null);
2640
2711
  AgentsController = _ts_decorate7([
2641
2712
  (0, import_common8.Controller)("agents"),
2642
- _ts_param6(0, (0, import_common8.Inject)(import_nestjs_agent_core8.AGENT_REGISTRY)),
2643
- _ts_param6(1, (0, import_common8.Inject)(import_nestjs_agent_core8.AGENT_DEPS_FACTORY)),
2713
+ _ts_param6(0, (0, import_common8.Inject)(import_nestjs_agent_core10.AGENT_REGISTRY)),
2714
+ _ts_param6(1, (0, import_common8.Inject)(import_nestjs_agent_core10.AGENT_DEPS_FACTORY)),
2644
2715
  _ts_metadata6("design:type", Function),
2645
2716
  _ts_metadata6("design:paramtypes", [
2646
- typeof import_nestjs_agent_core8.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core8.AgentRegistry,
2717
+ typeof import_nestjs_agent_core10.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core10.AgentRegistry,
2647
2718
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory
2648
2719
  ])
2649
2720
  ], AgentsController);
2650
2721
 
2651
2722
  // src/controller/attachments.controller.ts
2652
- var import_nestjs_agent_core9 = require("@dudousxd/nestjs-agent-core");
2723
+ var import_nestjs_agent_core11 = require("@dudousxd/nestjs-agent-core");
2653
2724
  var import_common9 = require("@nestjs/common");
2654
2725
  var import_platform_express = require("@nestjs/platform-express");
2655
2726
 
@@ -2787,10 +2858,10 @@ _ts_decorate8([
2787
2858
  ], AttachmentsController.prototype, "upload", null);
2788
2859
  AttachmentsController = _ts_decorate8([
2789
2860
  (0, import_common9.Controller)("attachments"),
2790
- _ts_param7(0, (0, import_common9.Inject)(import_nestjs_agent_core9.AGENT_OPTIONS)),
2791
- _ts_param7(1, (0, import_common9.Inject)(import_nestjs_agent_core9.AGENT_ACTOR_RESOLVER)),
2861
+ _ts_param7(0, (0, import_common9.Inject)(import_nestjs_agent_core11.AGENT_OPTIONS)),
2862
+ _ts_param7(1, (0, import_common9.Inject)(import_nestjs_agent_core11.AGENT_ACTOR_RESOLVER)),
2792
2863
  _ts_param7(3, (0, import_common9.Optional)()),
2793
- _ts_param7(3, (0, import_common9.Inject)(import_nestjs_agent_core9.AGENT_ATTACHMENT_STAGING)),
2864
+ _ts_param7(3, (0, import_common9.Inject)(import_nestjs_agent_core11.AGENT_ATTACHMENT_STAGING)),
2794
2865
  _ts_metadata7("design:type", Function),
2795
2866
  _ts_metadata7("design:paramtypes", [
2796
2867
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
@@ -2801,7 +2872,7 @@ AttachmentsController = _ts_decorate8([
2801
2872
  ], AttachmentsController);
2802
2873
 
2803
2874
  // src/controller/chat.controller.ts
2804
- var import_nestjs_agent_core10 = require("@dudousxd/nestjs-agent-core");
2875
+ var import_nestjs_agent_core12 = require("@dudousxd/nestjs-agent-core");
2805
2876
  var import_genui2 = require("@dudousxd/nestjs-agent-core/genui");
2806
2877
  var import_common10 = require("@nestjs/common");
2807
2878
  function _ts_decorate9(decorators, target, key, desc) {
@@ -3011,10 +3082,10 @@ data: ${line}
3011
3082
  }
3012
3083
  res.write("event: done\ndata: {}\n\n");
3013
3084
  } catch (error) {
3014
- const payload = error instanceof import_nestjs_agent_core10.AgentStreamError ? {
3085
+ const payload = error instanceof import_nestjs_agent_core12.AgentStreamError ? {
3015
3086
  code: error.code,
3016
3087
  message: error.message
3017
- } : (0, import_nestjs_agent_core10.streamFailure)(error);
3088
+ } : (0, import_nestjs_agent_core12.streamFailure)(error);
3018
3089
  res.write(`event: error
3019
3090
  data: ${JSON.stringify(payload)}
3020
3091
 
@@ -3064,7 +3135,7 @@ _ts_decorate9([
3064
3135
  ], ChatController.prototype, "cancel", null);
3065
3136
  ChatController = _ts_decorate9([
3066
3137
  (0, import_common10.Controller)(),
3067
- _ts_param8(1, (0, import_common10.Inject)(import_nestjs_agent_core10.AGENT_ACTOR_RESOLVER)),
3138
+ _ts_param8(1, (0, import_common10.Inject)(import_nestjs_agent_core12.AGENT_ACTOR_RESOLVER)),
3068
3139
  _ts_metadata8("design:type", Function),
3069
3140
  _ts_metadata8("design:paramtypes", [
3070
3141
  typeof AgentService === "undefined" ? Object : AgentService,
@@ -3082,7 +3153,7 @@ function parseCursor(raw) {
3082
3153
  __name(parseCursor, "parseCursor");
3083
3154
 
3084
3155
  // src/controller/config.controller.ts
3085
- var import_nestjs_agent_core11 = require("@dudousxd/nestjs-agent-core");
3156
+ var import_nestjs_agent_core13 = require("@dudousxd/nestjs-agent-core");
3086
3157
  var import_common11 = require("@nestjs/common");
3087
3158
 
3088
3159
  // src/resolver/anonymous-actor-resolver.ts
@@ -3240,12 +3311,12 @@ _ts_decorate10([
3240
3311
  ], ConfigController.prototype, "config", null);
3241
3312
  ConfigController = _ts_decorate10([
3242
3313
  (0, import_common11.Controller)("config"),
3243
- _ts_param9(0, (0, import_common11.Inject)(import_nestjs_agent_core11.AGENT_OPTIONS)),
3244
- _ts_param9(1, (0, import_common11.Inject)(import_nestjs_agent_core11.AGENT_ACTOR_RESOLVER)),
3314
+ _ts_param9(0, (0, import_common11.Inject)(import_nestjs_agent_core13.AGENT_OPTIONS)),
3315
+ _ts_param9(1, (0, import_common11.Inject)(import_nestjs_agent_core13.AGENT_ACTOR_RESOLVER)),
3245
3316
  _ts_param9(2, (0, import_common11.Optional)()),
3246
- _ts_param9(2, (0, import_common11.Inject)(import_nestjs_agent_core11.AGENT_ATTACHMENT_STAGING)),
3317
+ _ts_param9(2, (0, import_common11.Inject)(import_nestjs_agent_core13.AGENT_ATTACHMENT_STAGING)),
3247
3318
  _ts_param9(3, (0, import_common11.Optional)()),
3248
- _ts_param9(3, (0, import_common11.Inject)(import_nestjs_agent_core11.AGENT_MODEL_CATALOG)),
3319
+ _ts_param9(3, (0, import_common11.Inject)(import_nestjs_agent_core13.AGENT_MODEL_CATALOG)),
3249
3320
  _ts_metadata9("design:type", Function),
3250
3321
  _ts_metadata9("design:paramtypes", [
3251
3322
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
@@ -3256,7 +3327,7 @@ ConfigController = _ts_decorate10([
3256
3327
  ], ConfigController);
3257
3328
 
3258
3329
  // src/controller/memories.controller.ts
3259
- var import_nestjs_agent_core12 = require("@dudousxd/nestjs-agent-core");
3330
+ var import_nestjs_agent_core14 = require("@dudousxd/nestjs-agent-core");
3260
3331
  var import_common12 = require("@nestjs/common");
3261
3332
  function _ts_decorate11(decorators, target, key, desc) {
3262
3333
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -3325,7 +3396,7 @@ var MemoriesController = class {
3325
3396
  if (entry === void 0) {
3326
3397
  throw new import_common12.NotFoundException(`No memory with id "${id}".`);
3327
3398
  }
3328
- const verdict = (0, import_nestjs_agent_core12.memoryForgetVerdict)({
3399
+ const verdict = (0, import_nestjs_agent_core14.memoryForgetVerdict)({
3329
3400
  record: entry,
3330
3401
  actor
3331
3402
  });
@@ -3344,7 +3415,7 @@ var MemoriesController = class {
3344
3415
  }
3345
3416
  async unbounded(threadId, actor) {
3346
3417
  const config = this.memory;
3347
- return await (0, import_nestjs_agent_core12.offerMemories)({
3418
+ return await (0, import_nestjs_agent_core14.offerMemories)({
3348
3419
  config: {
3349
3420
  ...config,
3350
3421
  maxMemories: Number.POSITIVE_INFINITY
@@ -3380,9 +3451,9 @@ _ts_decorate11([
3380
3451
  ], MemoriesController.prototype, "forget", null);
3381
3452
  MemoriesController = _ts_decorate11([
3382
3453
  (0, import_common12.Controller)("memories"),
3383
- _ts_param10(0, (0, import_common12.Inject)(import_nestjs_agent_core12.AGENT_ACTOR_RESOLVER)),
3454
+ _ts_param10(0, (0, import_common12.Inject)(import_nestjs_agent_core14.AGENT_ACTOR_RESOLVER)),
3384
3455
  _ts_param10(1, (0, import_common12.Optional)()),
3385
- _ts_param10(1, (0, import_common12.Inject)(import_nestjs_agent_core12.AGENT_MEMORY)),
3456
+ _ts_param10(1, (0, import_common12.Inject)(import_nestjs_agent_core14.AGENT_MEMORY)),
3386
3457
  _ts_metadata10("design:type", Function),
3387
3458
  _ts_metadata10("design:paramtypes", [
3388
3459
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
@@ -3391,7 +3462,7 @@ MemoriesController = _ts_decorate11([
3391
3462
  ], MemoriesController);
3392
3463
 
3393
3464
  // src/controller/messages.controller.ts
3394
- var import_nestjs_agent_core13 = require("@dudousxd/nestjs-agent-core");
3465
+ var import_nestjs_agent_core15 = require("@dudousxd/nestjs-agent-core");
3395
3466
  var import_common13 = require("@nestjs/common");
3396
3467
  function _ts_decorate12(decorators, target, key, desc) {
3397
3468
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -3462,7 +3533,7 @@ _ts_decorate12([
3462
3533
  ], MessagesController.prototype, "feedback", null);
3463
3534
  MessagesController = _ts_decorate12([
3464
3535
  (0, import_common13.Controller)("messages"),
3465
- _ts_param11(1, (0, import_common13.Inject)(import_nestjs_agent_core13.AGENT_ACTOR_RESOLVER)),
3536
+ _ts_param11(1, (0, import_common13.Inject)(import_nestjs_agent_core15.AGENT_ACTOR_RESOLVER)),
3466
3537
  _ts_metadata11("design:type", Function),
3467
3538
  _ts_metadata11("design:paramtypes", [
3468
3539
  typeof AgentService === "undefined" ? Object : AgentService,
@@ -3471,7 +3542,7 @@ MessagesController = _ts_decorate12([
3471
3542
  ], MessagesController);
3472
3543
 
3473
3544
  // src/controller/models.controller.ts
3474
- var import_nestjs_agent_core14 = require("@dudousxd/nestjs-agent-core");
3545
+ var import_nestjs_agent_core16 = require("@dudousxd/nestjs-agent-core");
3475
3546
  var import_common14 = require("@nestjs/common");
3476
3547
  function _ts_decorate13(decorators, target, key, desc) {
3477
3548
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -3531,7 +3602,7 @@ _ts_decorate13([
3531
3602
  ], ModelsController.prototype, "list", null);
3532
3603
  ModelsController = _ts_decorate13([
3533
3604
  (0, import_common14.Controller)("models"),
3534
- _ts_param12(1, (0, import_common14.Inject)(import_nestjs_agent_core14.AGENT_ACTOR_RESOLVER)),
3605
+ _ts_param12(1, (0, import_common14.Inject)(import_nestjs_agent_core16.AGENT_ACTOR_RESOLVER)),
3535
3606
  _ts_metadata12("design:type", Function),
3536
3607
  _ts_metadata12("design:paramtypes", [
3537
3608
  typeof AgentService === "undefined" ? Object : AgentService,
@@ -3540,7 +3611,7 @@ ModelsController = _ts_decorate13([
3540
3611
  ], ModelsController);
3541
3612
 
3542
3613
  // src/controller/queue.controller.ts
3543
- var import_nestjs_agent_core15 = require("@dudousxd/nestjs-agent-core");
3614
+ var import_nestjs_agent_core17 = require("@dudousxd/nestjs-agent-core");
3544
3615
  var import_common15 = require("@nestjs/common");
3545
3616
  function _ts_decorate14(decorators, target, key, desc) {
3546
3617
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -3691,7 +3762,7 @@ _ts_decorate14([
3691
3762
  ], QueueController.prototype, "remove", null);
3692
3763
  QueueController = _ts_decorate14([
3693
3764
  (0, import_common15.Controller)(),
3694
- _ts_param13(1, (0, import_common15.Inject)(import_nestjs_agent_core15.AGENT_ACTOR_RESOLVER)),
3765
+ _ts_param13(1, (0, import_common15.Inject)(import_nestjs_agent_core17.AGENT_ACTOR_RESOLVER)),
3695
3766
  _ts_metadata13("design:type", Function),
3696
3767
  _ts_metadata13("design:paramtypes", [
3697
3768
  typeof AgentService === "undefined" ? Object : AgentService,
@@ -3700,7 +3771,7 @@ QueueController = _ts_decorate14([
3700
3771
  ], QueueController);
3701
3772
 
3702
3773
  // src/controller/quota.controller.ts
3703
- var import_nestjs_agent_core16 = require("@dudousxd/nestjs-agent-core");
3774
+ var import_nestjs_agent_core18 = require("@dudousxd/nestjs-agent-core");
3704
3775
  var import_common16 = require("@nestjs/common");
3705
3776
  function _ts_decorate15(decorators, target, key, desc) {
3706
3777
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -3758,7 +3829,7 @@ _ts_decorate15([
3758
3829
  ], QuotaController.prototype, "report", null);
3759
3830
  QuotaController = _ts_decorate15([
3760
3831
  (0, import_common16.Controller)("quota"),
3761
- _ts_param14(1, (0, import_common16.Inject)(import_nestjs_agent_core16.AGENT_ACTOR_RESOLVER)),
3832
+ _ts_param14(1, (0, import_common16.Inject)(import_nestjs_agent_core18.AGENT_ACTOR_RESOLVER)),
3762
3833
  _ts_metadata14("design:type", Function),
3763
3834
  _ts_metadata14("design:paramtypes", [
3764
3835
  typeof AgentService === "undefined" ? Object : AgentService,
@@ -3767,7 +3838,7 @@ QuotaController = _ts_decorate15([
3767
3838
  ], QuotaController);
3768
3839
 
3769
3840
  // src/controller/skills.controller.ts
3770
- var import_nestjs_agent_core17 = require("@dudousxd/nestjs-agent-core");
3841
+ var import_nestjs_agent_core19 = require("@dudousxd/nestjs-agent-core");
3771
3842
  var import_common17 = require("@nestjs/common");
3772
3843
  function _ts_decorate16(decorators, target, key, desc) {
3773
3844
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -3810,7 +3881,7 @@ var SkillsController = class {
3810
3881
  return [];
3811
3882
  }
3812
3883
  const actor = await this.actorResolver.resolve(req);
3813
- const offer = await (0, import_nestjs_agent_core17.offerSkills)(this.skills, {
3884
+ const offer = await (0, import_nestjs_agent_core19.offerSkills)(this.skills, {
3814
3885
  actor,
3815
3886
  threadId: threadId ?? ""
3816
3887
  });
@@ -3830,9 +3901,9 @@ _ts_decorate16([
3830
3901
  ], SkillsController.prototype, "list", null);
3831
3902
  SkillsController = _ts_decorate16([
3832
3903
  (0, import_common17.Controller)("skills"),
3833
- _ts_param15(0, (0, import_common17.Inject)(import_nestjs_agent_core17.AGENT_ACTOR_RESOLVER)),
3904
+ _ts_param15(0, (0, import_common17.Inject)(import_nestjs_agent_core19.AGENT_ACTOR_RESOLVER)),
3834
3905
  _ts_param15(1, (0, import_common17.Optional)()),
3835
- _ts_param15(1, (0, import_common17.Inject)(import_nestjs_agent_core17.AGENT_SKILLS)),
3906
+ _ts_param15(1, (0, import_common17.Inject)(import_nestjs_agent_core19.AGENT_SKILLS)),
3836
3907
  _ts_metadata15("design:type", Function),
3837
3908
  _ts_metadata15("design:paramtypes", [
3838
3909
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
@@ -3841,7 +3912,7 @@ SkillsController = _ts_decorate16([
3841
3912
  ], SkillsController);
3842
3913
 
3843
3914
  // src/controller/threads.controller.ts
3844
- var import_nestjs_agent_core18 = require("@dudousxd/nestjs-agent-core");
3915
+ var import_nestjs_agent_core20 = require("@dudousxd/nestjs-agent-core");
3845
3916
  var import_common18 = require("@nestjs/common");
3846
3917
  function _ts_decorate17(decorators, target, key, desc) {
3847
3918
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -4021,7 +4092,7 @@ _ts_decorate17([
4021
4092
  ], ThreadsController.prototype, "truncateFrom", null);
4022
4093
  ThreadsController = _ts_decorate17([
4023
4094
  (0, import_common18.Controller)("threads"),
4024
- _ts_param16(1, (0, import_common18.Inject)(import_nestjs_agent_core18.AGENT_ACTOR_RESOLVER)),
4095
+ _ts_param16(1, (0, import_common18.Inject)(import_nestjs_agent_core20.AGENT_ACTOR_RESOLVER)),
4025
4096
  _ts_metadata16("design:type", Function),
4026
4097
  _ts_metadata16("design:paramtypes", [
4027
4098
  typeof AgentService === "undefined" ? Object : AgentService,
@@ -4030,7 +4101,7 @@ ThreadsController = _ts_decorate17([
4030
4101
  ], ThreadsController);
4031
4102
 
4032
4103
  // src/controller/tool-call.controller.ts
4033
- var import_nestjs_agent_core19 = require("@dudousxd/nestjs-agent-core");
4104
+ var import_nestjs_agent_core21 = require("@dudousxd/nestjs-agent-core");
4034
4105
  var import_common19 = require("@nestjs/common");
4035
4106
  function _ts_decorate18(decorators, target, key, desc) {
4036
4107
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -4236,7 +4307,7 @@ _ts_decorate18([
4236
4307
  ], ToolCallController.prototype, "skip", null);
4237
4308
  ToolCallController = _ts_decorate18([
4238
4309
  (0, import_common19.Controller)("tool-call"),
4239
- _ts_param17(1, (0, import_common19.Inject)(import_nestjs_agent_core19.AGENT_ACTOR_RESOLVER)),
4310
+ _ts_param17(1, (0, import_common19.Inject)(import_nestjs_agent_core21.AGENT_ACTOR_RESOLVER)),
4240
4311
  _ts_metadata17("design:type", Function),
4241
4312
  _ts_metadata17("design:paramtypes", [
4242
4313
  typeof AgentService === "undefined" ? Object : AgentService,
@@ -4245,7 +4316,7 @@ ToolCallController = _ts_decorate18([
4245
4316
  ], ToolCallController);
4246
4317
 
4247
4318
  // src/controller/tools.controller.ts
4248
- var import_nestjs_agent_core20 = require("@dudousxd/nestjs-agent-core");
4319
+ var import_nestjs_agent_core22 = require("@dudousxd/nestjs-agent-core");
4249
4320
  var import_common20 = require("@nestjs/common");
4250
4321
  function _ts_decorate19(decorators, target, key, desc) {
4251
4322
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -4286,11 +4357,11 @@ var ToolsController = class {
4286
4357
  this.agents = agents;
4287
4358
  }
4288
4359
  async list(req, agent) {
4289
- if (agent !== void 0 && agent !== import_nestjs_agent_core20.ALL_AGENTS && this.agents.get(agent) === void 0) {
4360
+ if (agent !== void 0 && agent !== import_nestjs_agent_core22.ALL_AGENTS && this.agents.get(agent) === void 0) {
4290
4361
  throw new import_common20.NotFoundException(`No agent named "${agent}"`);
4291
4362
  }
4292
4363
  const actor = await this.actorResolver.resolve(req);
4293
- const names = agent === import_nestjs_agent_core20.ALL_AGENTS ? [
4364
+ const names = agent === import_nestjs_agent_core22.ALL_AGENTS ? [
4294
4365
  void 0,
4295
4366
  ...this.agents.list().map((definition) => definition.name)
4296
4367
  ] : [
@@ -4329,19 +4400,19 @@ _ts_decorate19([
4329
4400
  ], ToolsController.prototype, "list", null);
4330
4401
  ToolsController = _ts_decorate19([
4331
4402
  (0, import_common20.Controller)("tools"),
4332
- _ts_param18(0, (0, import_common20.Inject)(import_nestjs_agent_core20.AGENT_ACTOR_RESOLVER)),
4333
- _ts_param18(1, (0, import_common20.Inject)(import_nestjs_agent_core20.AGENT_DEPS_FACTORY)),
4334
- _ts_param18(2, (0, import_common20.Inject)(import_nestjs_agent_core20.AGENT_REGISTRY)),
4403
+ _ts_param18(0, (0, import_common20.Inject)(import_nestjs_agent_core22.AGENT_ACTOR_RESOLVER)),
4404
+ _ts_param18(1, (0, import_common20.Inject)(import_nestjs_agent_core22.AGENT_DEPS_FACTORY)),
4405
+ _ts_param18(2, (0, import_common20.Inject)(import_nestjs_agent_core22.AGENT_REGISTRY)),
4335
4406
  _ts_metadata18("design:type", Function),
4336
4407
  _ts_metadata18("design:paramtypes", [
4337
4408
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
4338
4409
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
4339
- typeof import_nestjs_agent_core20.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core20.AgentRegistry
4410
+ typeof import_nestjs_agent_core22.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core22.AgentRegistry
4340
4411
  ])
4341
4412
  ], ToolsController);
4342
4413
 
4343
4414
  // src/discovery/agent-discovery.service.ts
4344
- var import_nestjs_agent_core21 = require("@dudousxd/nestjs-agent-core");
4415
+ var import_nestjs_agent_core23 = require("@dudousxd/nestjs-agent-core");
4345
4416
  var import_common21 = require("@nestjs/common");
4346
4417
  var import_core = require("@nestjs/core");
4347
4418
 
@@ -4570,19 +4641,19 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
4570
4641
  };
4571
4642
  AgentDiscoveryService = _ts_decorate20([
4572
4643
  (0, import_common21.Injectable)(),
4573
- _ts_param19(2, (0, import_common21.Inject)(import_nestjs_agent_core21.AGENT_REGISTRY)),
4574
- _ts_param19(3, (0, import_common21.Inject)(import_nestjs_agent_core21.AGENT_PROMPT_CONTRIBUTORS)),
4644
+ _ts_param19(2, (0, import_common21.Inject)(import_nestjs_agent_core23.AGENT_REGISTRY)),
4645
+ _ts_param19(3, (0, import_common21.Inject)(import_nestjs_agent_core23.AGENT_PROMPT_CONTRIBUTORS)),
4575
4646
  _ts_metadata19("design:type", Function),
4576
4647
  _ts_metadata19("design:paramtypes", [
4577
4648
  typeof import_core.DiscoveryService === "undefined" ? Object : import_core.DiscoveryService,
4578
4649
  typeof import_core.MetadataScanner === "undefined" ? Object : import_core.MetadataScanner,
4579
- typeof import_nestjs_agent_core21.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core21.AgentRegistry,
4650
+ typeof import_nestjs_agent_core23.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core23.AgentRegistry,
4580
4651
  Array
4581
4652
  ])
4582
4653
  ], AgentDiscoveryService);
4583
4654
 
4584
4655
  // src/discovery/ai-tool-discovery.service.ts
4585
- var import_nestjs_agent_core22 = require("@dudousxd/nestjs-agent-core");
4656
+ var import_nestjs_agent_core24 = require("@dudousxd/nestjs-agent-core");
4586
4657
  var import_common22 = require("@nestjs/common");
4587
4658
  var import_core2 = require("@nestjs/core");
4588
4659
  var import_zod = require("zod");
@@ -4715,6 +4786,9 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
4715
4786
  } : {}
4716
4787
  }, {
4717
4788
  execute: /* @__PURE__ */ __name((input, ctx) => instance.execute(input, ctx), "execute"),
4789
+ ...typeof handler.present === "function" ? {
4790
+ present: /* @__PURE__ */ __name((output, ctx) => instance.present(output, ctx), "present")
4791
+ } : {},
4718
4792
  ...typeof handler.preflight === "function" ? {
4719
4793
  preflight: /* @__PURE__ */ __name((input, ctx, options) => instance.preflight(input, ctx, options), "preflight")
4720
4794
  } : {},
@@ -4741,7 +4815,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
4741
4815
  let delegates = 0;
4742
4816
  for (const definition of this.agents.list()) {
4743
4817
  for (const edge of definition.delegatesTo ?? []) {
4744
- const { agent: target, detached } = (0, import_nestjs_agent_core22.normalizeDelegation)(edge);
4818
+ const { agent: target, detached } = (0, import_nestjs_agent_core24.normalizeDelegation)(edge);
4745
4819
  const targetDefinition = this.agents.get(target);
4746
4820
  if (targetDefinition === void 0) {
4747
4821
  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.`);
@@ -4793,9 +4867,9 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
4793
4867
  };
4794
4868
  AiToolDiscoveryService = _ts_decorate21([
4795
4869
  (0, import_common22.Injectable)(),
4796
- _ts_param20(1, (0, import_common22.Inject)(import_nestjs_agent_core22.AGENT_TOOL_REGISTRY)),
4797
- _ts_param20(2, (0, import_common22.Inject)(import_nestjs_agent_core22.AGENT_REGISTRY)),
4798
- _ts_param20(3, (0, import_common22.Inject)(import_nestjs_agent_core22.AGENT_OPTIONS)),
4870
+ _ts_param20(1, (0, import_common22.Inject)(import_nestjs_agent_core24.AGENT_TOOL_REGISTRY)),
4871
+ _ts_param20(2, (0, import_common22.Inject)(import_nestjs_agent_core24.AGENT_REGISTRY)),
4872
+ _ts_param20(3, (0, import_common22.Inject)(import_nestjs_agent_core24.AGENT_OPTIONS)),
4799
4873
  _ts_metadata20("design:type", Function),
4800
4874
  _ts_metadata20("design:paramtypes", [
4801
4875
  typeof import_core2.DiscoveryService === "undefined" ? Object : import_core2.DiscoveryService,
@@ -4806,13 +4880,13 @@ AiToolDiscoveryService = _ts_decorate21([
4806
4880
  ], AiToolDiscoveryService);
4807
4881
 
4808
4882
  // src/discovery/skill-discovery.service.ts
4809
- var import_nestjs_agent_core24 = require("@dudousxd/nestjs-agent-core");
4883
+ var import_nestjs_agent_core26 = require("@dudousxd/nestjs-agent-core");
4810
4884
  var import_common23 = require("@nestjs/common");
4811
4885
  var import_core3 = require("@nestjs/core");
4812
4886
 
4813
4887
  // src/decorator/skill.decorator.ts
4814
4888
  var import_reflect_metadata4 = require("reflect-metadata");
4815
- var import_nestjs_agent_core23 = require("@dudousxd/nestjs-agent-core");
4889
+ var import_nestjs_agent_core25 = require("@dudousxd/nestjs-agent-core");
4816
4890
  var SKILL_METADATA = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:skill-metadata");
4817
4891
  function Skill(options) {
4818
4892
  return (target) => {
@@ -4825,7 +4899,7 @@ function readSkillMetadata(target) {
4825
4899
  }
4826
4900
  __name(readSkillMetadata, "readSkillMetadata");
4827
4901
  function skillScope(options) {
4828
- return options.scope ?? import_nestjs_agent_core23.GLOBAL_SCOPE;
4902
+ return options.scope ?? import_nestjs_agent_core25.GLOBAL_SCOPE;
4829
4903
  }
4830
4904
  __name(skillScope, "skillScope");
4831
4905
 
@@ -4901,7 +4975,7 @@ var SkillDiscoveryService = class _SkillDiscoveryService {
4901
4975
  };
4902
4976
  SkillDiscoveryService = _ts_decorate22([
4903
4977
  (0, import_common23.Injectable)(),
4904
- _ts_param21(1, (0, import_common23.Inject)(import_nestjs_agent_core24.AGENT_SKILL_SOURCES)),
4978
+ _ts_param21(1, (0, import_common23.Inject)(import_nestjs_agent_core26.AGENT_SKILL_SOURCES)),
4905
4979
  _ts_metadata21("design:type", Function),
4906
4980
  _ts_metadata21("design:paramtypes", [
4907
4981
  typeof import_core3.DiscoveryService === "undefined" ? Object : import_core3.DiscoveryService,
@@ -4910,7 +4984,7 @@ SkillDiscoveryService = _ts_decorate22([
4910
4984
  ], SkillDiscoveryService);
4911
4985
 
4912
4986
  // src/in-process-sink.ts
4913
- var import_nestjs_agent_core25 = require("@dudousxd/nestjs-agent-core");
4987
+ var import_nestjs_agent_core27 = require("@dudousxd/nestjs-agent-core");
4914
4988
  var InProcessTokenStreamSink = class {
4915
4989
  static {
4916
4990
  __name(this, "InProcessTokenStreamSink");
@@ -4965,7 +5039,7 @@ var InProcessTokenStreamSink = class {
4965
5039
  }
4966
5040
  if (buf.ended) {
4967
5041
  if (buf.failure !== void 0) {
4968
- throw new import_nestjs_agent_core25.AgentStreamError(buf.failure);
5042
+ throw new import_nestjs_agent_core27.AgentStreamError(buf.failure);
4969
5043
  }
4970
5044
  return;
4971
5045
  }
@@ -4978,7 +5052,7 @@ var InProcessTokenStreamSink = class {
4978
5052
  };
4979
5053
 
4980
5054
  // src/ledger-quota-provider.ts
4981
- var import_nestjs_agent_core26 = require("@dudousxd/nestjs-agent-core");
5055
+ var import_nestjs_agent_core28 = require("@dudousxd/nestjs-agent-core");
4982
5056
  var LedgerQuotaProvider = class {
4983
5057
  static {
4984
5058
  __name(this, "LedgerQuotaProvider");
@@ -4998,12 +5072,12 @@ var LedgerQuotaProvider = class {
4998
5072
  await this.dayWindow(actorRef, now)
4999
5073
  ];
5000
5074
  if (this.store.usageBetween !== void 0) {
5001
- const range = (0, import_nestjs_agent_core26.quotaPeriodRange)("month", now);
5075
+ const range = (0, import_nestjs_agent_core28.quotaPeriodRange)("month", now);
5002
5076
  const used = await this.store.usageBetween(actorRef, range.fromDay, range.toDay);
5003
5077
  windows.push(this.window("month", used.usedTokens, used.costUsd, range.resetsAt));
5004
5078
  }
5005
- const blocked = (0, import_nestjs_agent_core26.exhaustedWindow)(windows);
5006
- const warning = (0, import_nestjs_agent_core26.quotaWarning)(windows);
5079
+ const blocked = (0, import_nestjs_agent_core28.exhaustedWindow)(windows);
5080
+ const warning = (0, import_nestjs_agent_core28.quotaWarning)(windows);
5007
5081
  return {
5008
5082
  windows,
5009
5083
  ...blocked !== void 0 ? {
@@ -5015,7 +5089,7 @@ var LedgerQuotaProvider = class {
5015
5089
  };
5016
5090
  }
5017
5091
  async dayWindow(actorRef, now) {
5018
- const range = (0, import_nestjs_agent_core26.quotaPeriodRange)("day", now);
5092
+ const range = (0, import_nestjs_agent_core28.quotaPeriodRange)("day", now);
5019
5093
  const { usedTokens, costUsd } = await this.store.quotaToday(actorRef, range.fromDay);
5020
5094
  return this.window("day", usedTokens, costUsd, range.resetsAt);
5021
5095
  }
@@ -5041,7 +5115,7 @@ var LedgerQuotaProvider = class {
5041
5115
 
5042
5116
  // src/proposals/action-proposal-worker.service.ts
5043
5117
  var import_node_crypto2 = require("crypto");
5044
- var import_nestjs_agent_core27 = require("@dudousxd/nestjs-agent-core");
5118
+ var import_nestjs_agent_core29 = require("@dudousxd/nestjs-agent-core");
5045
5119
  var import_common24 = require("@nestjs/common");
5046
5120
  function _ts_decorate23(decorators, target, key, desc) {
5047
5121
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -5085,15 +5159,15 @@ var ActionProposalWorkerService = class _ActionProposalWorkerService {
5085
5159
  }
5086
5160
  onModuleInit() {
5087
5161
  if (this.options.actionApprovalMode !== "independent") return;
5088
- (0, import_nestjs_agent_core27.assertIndependentActionCapabilities)(this.store, this.options.backgroundActorResolver);
5162
+ (0, import_nestjs_agent_core29.assertIndependentActionCapabilities)(this.store, this.options.backgroundActorResolver);
5089
5163
  if (this.options.surface === "http") return;
5090
5164
  const resolver = this.options.backgroundActorResolver;
5091
5165
  if (!resolver) throw new Error("BackgroundActorResolver is required");
5092
- this.worker = new import_nestjs_agent_core27.ActionProposalWorker({
5166
+ this.worker = new import_nestjs_agent_core29.ActionProposalWorker({
5093
5167
  store: this.store,
5094
5168
  workerId: (0, import_node_crypto2.randomUUID)(),
5095
5169
  ...this.options.actionProposalWorker,
5096
- executor: new import_nestjs_agent_core27.ActionProposalExecutor({
5170
+ executor: new import_nestjs_agent_core29.ActionProposalExecutor({
5097
5171
  resolver,
5098
5172
  resolveExecution: /* @__PURE__ */ __name(async (proposal, actor) => {
5099
5173
  const deps = this.deps.forProposal(proposal, actor);
@@ -5119,9 +5193,9 @@ var ActionProposalWorkerService = class _ActionProposalWorkerService {
5119
5193
  };
5120
5194
  ActionProposalWorkerService = _ts_decorate23([
5121
5195
  (0, import_common24.Injectable)(),
5122
- _ts_param22(0, (0, import_common24.Inject)(import_nestjs_agent_core27.AGENT_STORE)),
5123
- _ts_param22(1, (0, import_common24.Inject)(import_nestjs_agent_core27.AGENT_OPTIONS)),
5124
- _ts_param22(2, (0, import_common24.Inject)(import_nestjs_agent_core27.AGENT_DEPS_FACTORY)),
5196
+ _ts_param22(0, (0, import_common24.Inject)(import_nestjs_agent_core29.AGENT_STORE)),
5197
+ _ts_param22(1, (0, import_common24.Inject)(import_nestjs_agent_core29.AGENT_OPTIONS)),
5198
+ _ts_param22(2, (0, import_common24.Inject)(import_nestjs_agent_core29.AGENT_DEPS_FACTORY)),
5125
5199
  _ts_metadata22("design:type", Function),
5126
5200
  _ts_metadata22("design:paramtypes", [
5127
5201
  typeof AgentStore === "undefined" ? Object : AgentStore,
@@ -5131,7 +5205,7 @@ ActionProposalWorkerService = _ts_decorate23([
5131
5205
  ], ActionProposalWorkerService);
5132
5206
 
5133
5207
  // src/proposals/action-proposal.controller.ts
5134
- var import_nestjs_agent_core28 = require("@dudousxd/nestjs-agent-core");
5208
+ var import_nestjs_agent_core30 = require("@dudousxd/nestjs-agent-core");
5135
5209
  var import_common25 = require("@nestjs/common");
5136
5210
  function _ts_decorate24(decorators, target, key, desc) {
5137
5211
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -5185,7 +5259,7 @@ var ActionProposalController = class {
5185
5259
  query = {
5186
5260
  after: JSON.parse(cursor)
5187
5261
  };
5188
- (0, import_nestjs_agent_core28.validateActionProposalListQuery)(query);
5262
+ (0, import_nestjs_agent_core30.validateActionProposalListQuery)(query);
5189
5263
  } catch {
5190
5264
  throw new import_common25.BadRequestException("Invalid action proposal cursor");
5191
5265
  }
@@ -5266,7 +5340,7 @@ _ts_decorate24([
5266
5340
  ], ActionProposalController.prototype, "reject", null);
5267
5341
  ActionProposalController = _ts_decorate24([
5268
5342
  (0, import_common25.Controller)("threads/:threadId/action-proposals"),
5269
- _ts_param23(1, (0, import_common25.Inject)(import_nestjs_agent_core28.AGENT_ACTOR_RESOLVER)),
5343
+ _ts_param23(1, (0, import_common25.Inject)(import_nestjs_agent_core30.AGENT_ACTOR_RESOLVER)),
5270
5344
  _ts_metadata23("design:type", Function),
5271
5345
  _ts_metadata23("design:paramtypes", [
5272
5346
  typeof ActionProposalService === "undefined" ? Object : ActionProposalService,
@@ -5278,7 +5352,7 @@ ActionProposalController = _ts_decorate24([
5278
5352
  var AGENT_CHAT_QUEUE = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:chat-queue");
5279
5353
 
5280
5354
  // src/runner/inline-agent-runner.ts
5281
- var import_nestjs_agent_core29 = require("@dudousxd/nestjs-agent-core");
5355
+ var import_nestjs_agent_core31 = require("@dudousxd/nestjs-agent-core");
5282
5356
  var import_common26 = require("@nestjs/common");
5283
5357
  function _ts_decorate25(decorators, target, key, desc) {
5284
5358
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -5362,18 +5436,18 @@ var InlineAgentRunner = class _InlineAgentRunner {
5362
5436
  ],
5363
5437
  input
5364
5438
  });
5365
- void (0, import_nestjs_agent_core29.runAgentLoop)({
5439
+ void (0, import_nestjs_agent_core31.runAgentLoop)({
5366
5440
  ...deps,
5367
5441
  day
5368
- }, input, hooks).then(() => (0, import_nestjs_agent_core29.releaseThreadRun)(this.store, input.threadId, runId)).catch(async (error) => {
5369
- if (error instanceof import_nestjs_agent_core29.RunCancelledError) {
5442
+ }, input, hooks).then(() => (0, import_nestjs_agent_core31.releaseThreadRun)(this.store, input.threadId, runId)).catch(async (error) => {
5443
+ if (error instanceof import_nestjs_agent_core31.RunCancelledError) {
5370
5444
  await this.settleCancelled(runId, input, deps);
5371
5445
  return;
5372
5446
  }
5373
5447
  const message = error instanceof Error ? error.message : String(error);
5374
- const code = (0, import_nestjs_agent_core29.agentFailureCode)(error);
5448
+ const code = (0, import_nestjs_agent_core31.agentFailureCode)(error);
5375
5449
  this.logger.error(`agent run ${runId} failed (${code}): ${message}`);
5376
- (0, import_nestjs_agent_core29.publishAgentRunFailed)({
5450
+ (0, import_nestjs_agent_core31.publishAgentRunFailed)({
5377
5451
  runId,
5378
5452
  code,
5379
5453
  message
@@ -5384,11 +5458,11 @@ var InlineAgentRunner = class _InlineAgentRunner {
5384
5458
  errorCode: code,
5385
5459
  errorMessage: message
5386
5460
  });
5387
- await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core29.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
5461
+ await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core31.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
5388
5462
  const writer = await deps.sink.open(runId);
5389
5463
  await this.settleQueue(writer, input, runId, "failed", message);
5390
- await (0, import_nestjs_agent_core29.releaseThreadRun)(this.store, input.threadId, runId);
5391
- await writer.fail((0, import_nestjs_agent_core29.streamFailure)(error));
5464
+ await (0, import_nestjs_agent_core31.releaseThreadRun)(this.store, input.threadId, runId);
5465
+ await writer.fail((0, import_nestjs_agent_core31.streamFailure)(error));
5392
5466
  }).finally(() => {
5393
5467
  this.cancelled.delete(runId);
5394
5468
  this.live.delete(runId);
@@ -5424,7 +5498,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
5424
5498
  for (const [key, waiter] of this.pending) {
5425
5499
  if (key.startsWith(`${runId}:`)) {
5426
5500
  this.pending.delete(key);
5427
- waiter.reject(new import_nestjs_agent_core29.RunCancelledError());
5501
+ waiter.reject(new import_nestjs_agent_core31.RunCancelledError());
5428
5502
  }
5429
5503
  }
5430
5504
  await Promise.resolve();
@@ -5439,8 +5513,8 @@ var InlineAgentRunner = class _InlineAgentRunner {
5439
5513
  this.logger.log(`agent run ${runId} cancelled`);
5440
5514
  const writer = await deps.sink.open(runId);
5441
5515
  await this.settleQueue(writer, input, runId, "cancelled");
5442
- await (0, import_nestjs_agent_core29.releaseThreadRun)(this.store, input.threadId, runId);
5443
- await writer.write((0, import_nestjs_agent_core29.encodeStreamEvent)({
5516
+ await (0, import_nestjs_agent_core31.releaseThreadRun)(this.store, input.threadId, runId);
5517
+ await writer.write((0, import_nestjs_agent_core31.encodeStreamEvent)({
5444
5518
  kind: "cancelled"
5445
5519
  }));
5446
5520
  await writer.end();
@@ -5475,7 +5549,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
5475
5549
  runId: nextRunId
5476
5550
  }));
5477
5551
  if (frame !== void 0) {
5478
- await writer.write((0, import_nestjs_agent_core29.encodeStreamEvent)(frame));
5552
+ await writer.write((0, import_nestjs_agent_core31.encodeStreamEvent)(frame));
5479
5553
  }
5480
5554
  } catch (failure) {
5481
5555
  this.logger.error(`could not advance the queue of thread ${input.threadId} after run ${runId}: ${failure instanceof Error ? failure.message : String(failure)}`);
@@ -5546,7 +5620,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
5546
5620
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
5547
5621
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
5548
5622
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
5549
- parallel: import_nestjs_agent_core29.settleAll,
5623
+ parallel: import_nestjs_agent_core31.settleAll,
5550
5624
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
5551
5625
  runAgent: /* @__PURE__ */ __name((agentName, task) => this.runNested({
5552
5626
  agentName,
@@ -5597,7 +5671,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
5597
5671
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
5598
5672
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
5599
5673
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
5600
- parallel: import_nestjs_agent_core29.settleAll,
5674
+ parallel: import_nestjs_agent_core31.settleAll,
5601
5675
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
5602
5676
  runAgent: /* @__PURE__ */ __name((childName, childTask) => this.runNested({
5603
5677
  agentName: childName,
@@ -5630,7 +5704,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
5630
5704
  }
5631
5705
  }), "startAgent")
5632
5706
  };
5633
- void (0, import_nestjs_agent_core29.runAgentLoop)({
5707
+ void (0, import_nestjs_agent_core31.runAgentLoop)({
5634
5708
  ...deps,
5635
5709
  day
5636
5710
  }, {
@@ -5644,13 +5718,13 @@ var InlineAgentRunner = class _InlineAgentRunner {
5644
5718
  parentRunId,
5645
5719
  deliverTo
5646
5720
  }, hooks).catch(async (error) => {
5647
- const cancelled = error instanceof import_nestjs_agent_core29.RunCancelledError;
5721
+ const cancelled = error instanceof import_nestjs_agent_core31.RunCancelledError;
5648
5722
  const message = error instanceof Error ? error.message : String(error);
5649
5723
  if (!cancelled) {
5650
5724
  this.logger.error(`detached agent run ${runId} failed: ${message}`);
5651
- (0, import_nestjs_agent_core29.publishAgentRunFailed)({
5725
+ (0, import_nestjs_agent_core31.publishAgentRunFailed)({
5652
5726
  runId,
5653
- code: (0, import_nestjs_agent_core29.agentFailureCode)(error),
5727
+ code: (0, import_nestjs_agent_core31.agentFailureCode)(error),
5654
5728
  message
5655
5729
  });
5656
5730
  }
@@ -5658,12 +5732,12 @@ var InlineAgentRunner = class _InlineAgentRunner {
5658
5732
  runId,
5659
5733
  status: cancelled ? "cancelled" : "failed",
5660
5734
  ...cancelled ? {} : {
5661
- errorCode: (0, import_nestjs_agent_core29.agentFailureCode)(error),
5735
+ errorCode: (0, import_nestjs_agent_core31.agentFailureCode)(error),
5662
5736
  errorMessage: message
5663
5737
  }
5664
5738
  });
5665
- await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core29.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
5666
- await (0, import_nestjs_agent_core29.settleUnsettledDelegation)({
5739
+ await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core31.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
5740
+ await (0, import_nestjs_agent_core31.settleUnsettledDelegation)({
5667
5741
  store: this.store,
5668
5742
  delivery: deliverTo,
5669
5743
  agent: agentName,
@@ -5702,7 +5776,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
5702
5776
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
5703
5777
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
5704
5778
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
5705
- parallel: import_nestjs_agent_core29.settleAll,
5779
+ parallel: import_nestjs_agent_core31.settleAll,
5706
5780
  // A child stops when it is cancelled OR when the run a human is actually watching is: the
5707
5781
  // canceller names the top-level run, which is the only id that ever left the server.
5708
5782
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId) || this.cancelled.has(sinkRunId), "cancelled"),
@@ -5737,7 +5811,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
5737
5811
  }), "startAgent")
5738
5812
  };
5739
5813
  try {
5740
- return await (0, import_nestjs_agent_core29.runAgentLoop)({
5814
+ return await (0, import_nestjs_agent_core31.runAgentLoop)({
5741
5815
  ...deps,
5742
5816
  day
5743
5817
  }, {
@@ -5758,8 +5832,8 @@ var InlineAgentRunner = class _InlineAgentRunner {
5758
5832
  };
5759
5833
  InlineAgentRunner = _ts_decorate25([
5760
5834
  (0, import_common26.Injectable)(),
5761
- _ts_param24(0, (0, import_common26.Inject)(import_nestjs_agent_core29.AGENT_DEPS_FACTORY)),
5762
- _ts_param24(1, (0, import_common26.Inject)(import_nestjs_agent_core29.AGENT_STORE)),
5835
+ _ts_param24(0, (0, import_common26.Inject)(import_nestjs_agent_core31.AGENT_DEPS_FACTORY)),
5836
+ _ts_param24(1, (0, import_common26.Inject)(import_nestjs_agent_core31.AGENT_STORE)),
5763
5837
  _ts_param24(2, (0, import_common26.Optional)()),
5764
5838
  _ts_metadata24("design:type", Function),
5765
5839
  _ts_metadata24("design:paramtypes", [
@@ -5774,7 +5848,7 @@ function isThreadTurn(input) {
5774
5848
  __name(isThreadTurn, "isThreadTurn");
5775
5849
 
5776
5850
  // src/skills-config.ts
5777
- var import_nestjs_agent_core30 = require("@dudousxd/nestjs-agent-core");
5851
+ var import_nestjs_agent_core32 = require("@dudousxd/nestjs-agent-core");
5778
5852
  function declaredSkillProvider(declared) {
5779
5853
  return {
5780
5854
  list: /* @__PURE__ */ __name(({ scopes }) => declared.filter((skill) => scopes.includes(skill.scope)).map(({ name, description, scope }) => ({
@@ -5800,7 +5874,7 @@ function resolveSkillsConfig(options, declared) {
5800
5874
  declaredSkillProvider(declared)
5801
5875
  ];
5802
5876
  return {
5803
- provider: providers.length === 1 ? providers[0] : (0, import_nestjs_agent_core30.compositeSkillProvider)(providers),
5877
+ provider: providers.length === 1 ? providers[0] : (0, import_nestjs_agent_core32.compositeSkillProvider)(providers),
5804
5878
  ...options.scopes !== void 0 ? {
5805
5879
  scopes: options.scopes
5806
5880
  } : {},
@@ -5828,15 +5902,15 @@ function _ts_decorate26(decorators, target, key, desc) {
5828
5902
  __name(_ts_decorate26, "_ts_decorate");
5829
5903
  var DEFAULT_PATH = "agent";
5830
5904
  var logger = new import_common27.Logger("AgentModule");
5831
- function externalStoreWrapper(modules) {
5905
+ function externalWrapper(modules, token) {
5832
5906
  for (const module2 of modules.values()) {
5833
5907
  if (module2.metatype === AgentModule) continue;
5834
- const wrapper = module2.providers.get(import_nestjs_agent_core31.AGENT_STORE);
5908
+ const wrapper = module2.providers.get(token);
5835
5909
  if (wrapper !== void 0) return wrapper;
5836
5910
  }
5837
5911
  return void 0;
5838
5912
  }
5839
- __name(externalStoreWrapper, "externalStoreWrapper");
5913
+ __name(externalWrapper, "externalWrapper");
5840
5914
  function forwardingStore(wrapper) {
5841
5915
  const target = /* @__PURE__ */ __name(() => {
5842
5916
  const instance = wrapper.instance;
@@ -5859,12 +5933,36 @@ function forwardingStore(wrapper) {
5859
5933
  __name(forwardingStore, "forwardingStore");
5860
5934
  function resolveStore(options, modules) {
5861
5935
  if (options.store !== void 0) return options.store;
5862
- const external = externalStoreWrapper(modules);
5936
+ const external = externalWrapper(modules, import_nestjs_agent_core33.AGENT_STORE);
5863
5937
  if (external !== void 0) return forwardingStore(external);
5864
5938
  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()).");
5865
- return new import_nestjs_agent_core31.InMemoryAgentStore();
5939
+ return new import_nestjs_agent_core33.InMemoryAgentStore();
5866
5940
  }
5867
5941
  __name(resolveStore, "resolveStore");
5942
+ function resolveRolesPolicy(options, modules) {
5943
+ const external = externalWrapper(modules, import_nestjs_agent_core33.AGENT_ROLES_POLICY);
5944
+ if (options.rolesPolicy !== void 0) {
5945
+ if (external !== void 0) {
5946
+ logger.warn("Both a `rolesPolicy` option and a module binding AGENT_ROLES_POLICY (e.g. AgentAuthzModule) are configured \u2014 the `rolesPolicy` option wins.");
5947
+ }
5948
+ return options.rolesPolicy;
5949
+ }
5950
+ if (external !== void 0) return forwardingPolicy(external);
5951
+ return options.emptyRoles === "deny" ? new import_nestjs_agent_core33.ClosedRolesPolicy(options.defaultRoles) : new import_nestjs_agent_core33.DefaultRolesPolicy(options.defaultRoles);
5952
+ }
5953
+ __name(resolveRolesPolicy, "resolveRolesPolicy");
5954
+ function forwardingPolicy(wrapper) {
5955
+ return {
5956
+ can(actor, tool) {
5957
+ const policy = wrapper.instance;
5958
+ if (policy === void 0 || policy === null) {
5959
+ throw new Error("AgentModule: the AGENT_ROLES_POLICY bound by another module is not ready yet");
5960
+ }
5961
+ return policy.can(actor, tool);
5962
+ }
5963
+ };
5964
+ }
5965
+ __name(forwardingPolicy, "forwardingPolicy");
5868
5966
  function isQuotaProvider(quota) {
5869
5967
  return quota !== void 0 && typeof quota.report === "function";
5870
5968
  }
@@ -5878,99 +5976,100 @@ __name(resolveCatalog, "resolveCatalog");
5878
5976
  function sharedProviders(durable) {
5879
5977
  const providers = [
5880
5978
  {
5881
- provide: import_nestjs_agent_core31.AGENT_TOOL_REGISTRY,
5882
- useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core31.ToolRegistry(), "useFactory")
5979
+ provide: import_nestjs_agent_core33.AGENT_TOOL_REGISTRY,
5980
+ useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core33.ToolRegistry(), "useFactory")
5883
5981
  },
5884
5982
  // Starts empty; AgentDiscoveryService populates it from `@Agent`-decorated providers at boot.
5885
5983
  {
5886
- provide: import_nestjs_agent_core31.AGENT_REGISTRY,
5887
- useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core31.AgentRegistry(), "useFactory")
5984
+ provide: import_nestjs_agent_core33.AGENT_REGISTRY,
5985
+ useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core33.AgentRegistry(), "useFactory")
5888
5986
  },
5889
5987
  // A shared, mutable list AgentDiscoveryService fills with `@SystemPromptContributor()` methods.
5890
5988
  {
5891
- provide: import_nestjs_agent_core31.AGENT_PROMPT_CONTRIBUTORS,
5989
+ provide: import_nestjs_agent_core33.AGENT_PROMPT_CONTRIBUTORS,
5892
5990
  useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
5893
5991
  },
5894
5992
  // Likewise for `@Skill`-decorated providers — filled by SkillDiscoveryService at onModuleInit,
5895
5993
  // read lazily by the AGENT_SKILLS provider below (which DI builds before discovery has run).
5896
5994
  {
5897
- provide: import_nestjs_agent_core31.AGENT_SKILL_SOURCES,
5995
+ provide: import_nestjs_agent_core33.AGENT_SKILL_SOURCES,
5898
5996
  useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
5899
5997
  },
5900
5998
  {
5901
5999
  // One resolution, shared by the loop's deps and the listing endpoint: a second one would
5902
6000
  // drift, and a user would be offered a skill the agent cannot reach. `undefined` when the
5903
6001
  // host configured none — which is what keeps the turn's checkpoint sequence unchanged.
5904
- provide: import_nestjs_agent_core31.AGENT_SKILLS,
6002
+ provide: import_nestjs_agent_core33.AGENT_SKILLS,
5905
6003
  useFactory: /* @__PURE__ */ __name((options, declared) => resolveSkillsConfig(options.skills, declared), "useFactory"),
5906
6004
  inject: [
5907
- import_nestjs_agent_core31.AGENT_OPTIONS,
5908
- import_nestjs_agent_core31.AGENT_SKILL_SOURCES
6005
+ import_nestjs_agent_core33.AGENT_OPTIONS,
6006
+ import_nestjs_agent_core33.AGENT_SKILL_SOURCES
5909
6007
  ]
5910
6008
  },
5911
6009
  {
5912
6010
  // One resolution, shared by the loop's deps and the read-back endpoint: a person has to be
5913
6011
  // shown what the model was shown, and two resolutions would eventually disagree about that.
5914
- provide: import_nestjs_agent_core31.AGENT_MEMORY,
6012
+ provide: import_nestjs_agent_core33.AGENT_MEMORY,
5915
6013
  useFactory: /* @__PURE__ */ __name((options) => options.memory, "useFactory"),
5916
6014
  inject: [
5917
- import_nestjs_agent_core31.AGENT_OPTIONS
6015
+ import_nestjs_agent_core33.AGENT_OPTIONS
5918
6016
  ]
5919
6017
  },
5920
6018
  {
5921
- provide: import_nestjs_agent_core31.AGENT_SINK,
6019
+ provide: import_nestjs_agent_core33.AGENT_SINK,
5922
6020
  useFactory: /* @__PURE__ */ __name((options) => options.sink ?? new InProcessTokenStreamSink(), "useFactory"),
5923
6021
  inject: [
5924
- import_nestjs_agent_core31.AGENT_OPTIONS
6022
+ import_nestjs_agent_core33.AGENT_OPTIONS
5925
6023
  ]
5926
6024
  },
5927
6025
  {
5928
- provide: import_nestjs_agent_core31.AGENT_ROLES_POLICY,
5929
- useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? (options.emptyRoles === "deny" ? new import_nestjs_agent_core31.ClosedRolesPolicy(options.defaultRoles) : new import_nestjs_agent_core31.DefaultRolesPolicy(options.defaultRoles)), "useFactory"),
6026
+ provide: import_nestjs_agent_core33.AGENT_ROLES_POLICY,
6027
+ useFactory: /* @__PURE__ */ __name((options, modules) => resolveRolesPolicy(options, modules), "useFactory"),
5930
6028
  inject: [
5931
- import_nestjs_agent_core31.AGENT_OPTIONS
6029
+ import_nestjs_agent_core33.AGENT_OPTIONS,
6030
+ import_core4.ModulesContainer
5932
6031
  ]
5933
6032
  },
5934
6033
  {
5935
- provide: import_nestjs_agent_core31.AGENT_ACTOR_RESOLVER,
6034
+ provide: import_nestjs_agent_core33.AGENT_ACTOR_RESOLVER,
5936
6035
  useFactory: /* @__PURE__ */ __name((options) => {
5937
6036
  if (options.actorResolver !== void 0) return options.actorResolver;
5938
6037
  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.");
5939
6038
  return new AnonymousActorResolver();
5940
6039
  }, "useFactory"),
5941
6040
  inject: [
5942
- import_nestjs_agent_core31.AGENT_OPTIONS
6041
+ import_nestjs_agent_core33.AGENT_OPTIONS
5943
6042
  ]
5944
6043
  },
5945
6044
  {
5946
- provide: import_nestjs_agent_core31.AGENT_MODEL,
6045
+ provide: import_nestjs_agent_core33.AGENT_MODEL,
5947
6046
  useFactory: /* @__PURE__ */ __name((o) => o.model, "useFactory"),
5948
6047
  inject: [
5949
- import_nestjs_agent_core31.AGENT_OPTIONS
6048
+ import_nestjs_agent_core33.AGENT_OPTIONS
5950
6049
  ]
5951
6050
  },
5952
6051
  {
5953
6052
  // `quota` is either a provider of the host's own or ceilings for the built-in ledger one;
5954
6053
  // omitted, the ledger provider still reports usage, with no ceiling to block on.
5955
- provide: import_nestjs_agent_core31.AGENT_QUOTA_PROVIDER,
6054
+ provide: import_nestjs_agent_core33.AGENT_QUOTA_PROVIDER,
5956
6055
  useFactory: /* @__PURE__ */ __name((o, store) => isQuotaProvider(o.quota) ? o.quota : new LedgerQuotaProvider(store, o.quota?.limits, o.quota?.warnAt !== void 0 ? {
5957
6056
  warnAt: o.quota.warnAt
5958
6057
  } : {}), "useFactory"),
5959
6058
  inject: [
5960
- import_nestjs_agent_core31.AGENT_OPTIONS,
5961
- import_nestjs_agent_core31.AGENT_STORE
6059
+ import_nestjs_agent_core33.AGENT_OPTIONS,
6060
+ import_nestjs_agent_core33.AGENT_STORE
5962
6061
  ]
5963
6062
  },
5964
6063
  {
5965
- provide: import_nestjs_agent_core31.AGENT_MODEL_CATALOG,
6064
+ provide: import_nestjs_agent_core33.AGENT_MODEL_CATALOG,
5966
6065
  useFactory: /* @__PURE__ */ __name((o) => resolveCatalog(o), "useFactory"),
5967
6066
  inject: [
5968
- import_nestjs_agent_core31.AGENT_OPTIONS
6067
+ import_nestjs_agent_core33.AGENT_OPTIONS
5969
6068
  ]
5970
6069
  },
5971
6070
  AgentDepsFactory2,
5972
6071
  {
5973
- provide: import_nestjs_agent_core31.AGENT_DEPS_FACTORY,
6072
+ provide: import_nestjs_agent_core33.AGENT_DEPS_FACTORY,
5974
6073
  useExisting: AgentDepsFactory2
5975
6074
  },
5976
6075
  // Populates the registry + contributors (onModuleInit) BEFORE AiToolDiscoveryService synthesizes
@@ -5993,21 +6092,21 @@ function sharedProviders(durable) {
5993
6092
  // through AgentService.signalToolCall, which reaches whichever AGENT_RUNNER is bound above.
5994
6093
  AgentApprovalPortAdapter,
5995
6094
  {
5996
- provide: import_nestjs_agent_core31.AGENT_APPROVAL_PORT,
6095
+ provide: import_nestjs_agent_core33.AGENT_APPROVAL_PORT,
5997
6096
  useExisting: AgentApprovalPortAdapter
5998
6097
  }
5999
6098
  ];
6000
6099
  providers.push({
6001
- provide: import_nestjs_agent_core31.AGENT_STORE,
6100
+ provide: import_nestjs_agent_core33.AGENT_STORE,
6002
6101
  useFactory: /* @__PURE__ */ __name((o, modules) => resolveStore(o, modules), "useFactory"),
6003
6102
  inject: [
6004
- import_nestjs_agent_core31.AGENT_OPTIONS,
6103
+ import_nestjs_agent_core33.AGENT_OPTIONS,
6005
6104
  import_core4.ModulesContainer
6006
6105
  ]
6007
6106
  });
6008
6107
  if (durable) {
6009
6108
  providers.push({
6010
- provide: import_nestjs_agent_core31.AGENT_RUNNER,
6109
+ provide: import_nestjs_agent_core33.AGENT_RUNNER,
6011
6110
  useFactory: /* @__PURE__ */ __name((durableRunner) => {
6012
6111
  if (durableRunner === void 0) {
6013
6112
  throw new Error("AgentModule.forRoot({ durable: true }) requires importing AgentDurableModule from '@dudousxd/nestjs-agent/durable' (alongside a configured DurableModule). It was not found.");
@@ -6016,14 +6115,14 @@ function sharedProviders(durable) {
6016
6115
  }, "useFactory"),
6017
6116
  inject: [
6018
6117
  {
6019
- token: import_nestjs_agent_core31.AGENT_DURABLE_RUNNER,
6118
+ token: import_nestjs_agent_core33.AGENT_DURABLE_RUNNER,
6020
6119
  optional: true
6021
6120
  }
6022
6121
  ]
6023
6122
  });
6024
6123
  } else {
6025
6124
  providers.push({
6026
- provide: import_nestjs_agent_core31.AGENT_RUNNER,
6125
+ provide: import_nestjs_agent_core33.AGENT_RUNNER,
6027
6126
  useExisting: InlineAgentRunner
6028
6127
  });
6029
6128
  }
@@ -6032,20 +6131,20 @@ function sharedProviders(durable) {
6032
6131
  __name(sharedProviders, "sharedProviders");
6033
6132
  function exportsFor() {
6034
6133
  return [
6035
- import_nestjs_agent_core31.AGENT_OPTIONS,
6036
- import_nestjs_agent_core31.AGENT_TOOL_REGISTRY,
6037
- import_nestjs_agent_core31.AGENT_REGISTRY,
6038
- import_nestjs_agent_core31.AGENT_SINK,
6039
- import_nestjs_agent_core31.AGENT_ROLES_POLICY,
6040
- import_nestjs_agent_core31.AGENT_ACTOR_RESOLVER,
6041
- import_nestjs_agent_core31.AGENT_MODEL,
6042
- import_nestjs_agent_core31.AGENT_STORE,
6043
- import_nestjs_agent_core31.AGENT_MODEL_CATALOG,
6044
- import_nestjs_agent_core31.AGENT_QUOTA_PROVIDER,
6045
- import_nestjs_agent_core31.AGENT_PROMPT_CONTRIBUTORS,
6046
- import_nestjs_agent_core31.AGENT_SKILLS,
6047
- import_nestjs_agent_core31.AGENT_MEMORY,
6048
- import_nestjs_agent_core31.AGENT_DEPS_FACTORY,
6134
+ import_nestjs_agent_core33.AGENT_OPTIONS,
6135
+ import_nestjs_agent_core33.AGENT_TOOL_REGISTRY,
6136
+ import_nestjs_agent_core33.AGENT_REGISTRY,
6137
+ import_nestjs_agent_core33.AGENT_SINK,
6138
+ import_nestjs_agent_core33.AGENT_ROLES_POLICY,
6139
+ import_nestjs_agent_core33.AGENT_ACTOR_RESOLVER,
6140
+ import_nestjs_agent_core33.AGENT_MODEL,
6141
+ import_nestjs_agent_core33.AGENT_STORE,
6142
+ import_nestjs_agent_core33.AGENT_MODEL_CATALOG,
6143
+ import_nestjs_agent_core33.AGENT_QUOTA_PROVIDER,
6144
+ import_nestjs_agent_core33.AGENT_PROMPT_CONTRIBUTORS,
6145
+ import_nestjs_agent_core33.AGENT_SKILLS,
6146
+ import_nestjs_agent_core33.AGENT_MEMORY,
6147
+ import_nestjs_agent_core33.AGENT_DEPS_FACTORY,
6049
6148
  AgentDepsFactory2,
6050
6149
  AgentService,
6051
6150
  ActionProposalService,
@@ -6053,7 +6152,7 @@ function exportsFor() {
6053
6152
  ChatQueueService,
6054
6153
  AGENT_CHAT_QUEUE,
6055
6154
  InlineAgentRunner,
6056
- import_nestjs_agent_core31.AGENT_APPROVAL_PORT
6155
+ import_nestjs_agent_core33.AGENT_APPROVAL_PORT
6057
6156
  ];
6058
6157
  }
6059
6158
  __name(exportsFor, "exportsFor");
@@ -6131,7 +6230,7 @@ var AgentModule = class _AgentModule {
6131
6230
  controllers: controllersForSurface(options.surface, options.adapters),
6132
6231
  providers: [
6133
6232
  {
6134
- provide: import_nestjs_agent_core31.AGENT_OPTIONS,
6233
+ provide: import_nestjs_agent_core33.AGENT_OPTIONS,
6135
6234
  useValue: options
6136
6235
  },
6137
6236
  ...sharedProviders(options.durable ?? false),
@@ -6155,7 +6254,7 @@ var AgentModule = class _AgentModule {
6155
6254
  controllers: controllersForSurface(options.surface, options.adapters),
6156
6255
  providers: [
6157
6256
  {
6158
- provide: import_nestjs_agent_core31.AGENT_OPTIONS,
6257
+ provide: import_nestjs_agent_core33.AGENT_OPTIONS,
6159
6258
  // Stamp the STATIC wiring flags onto the factory result: `durable`/`surface` are
6160
6259
  // authoritative on the async config object (they decided the actual wiring above), and
6161
6260
  // the durable module reads `durable` back off AGENT_OPTIONS. `surface` isn't read back by
@@ -6183,7 +6282,7 @@ AgentModule = _ts_decorate26([
6183
6282
  ], AgentModule);
6184
6283
 
6185
6284
  // src/ag-ui/ag-ui.adapter.ts
6186
- var import_nestjs_agent_core32 = require("@dudousxd/nestjs-agent-core");
6285
+ var import_nestjs_agent_core34 = require("@dudousxd/nestjs-agent-core");
6187
6286
  var import_ag_ui = require("@dudousxd/nestjs-agent-core/ag-ui");
6188
6287
  var import_common28 = require("@nestjs/common");
6189
6288
  function _ts_decorate27(decorators, target, key, desc) {
@@ -6270,6 +6369,19 @@ var AgUiRunHandler = class {
6270
6369
  warnings.push(`The resume entry ${id} answers an interrupt this agent did not raise.`);
6271
6370
  }
6272
6371
  const first = plan.decisions[0];
6372
+ if (first !== void 0 && plan.decisions.every((d) => d.address.kind === "proposal")) {
6373
+ const decided = await this.decideProposals(actor, plan.decisions);
6374
+ this.writeEvents(res, [
6375
+ ...warningEvents(warnings),
6376
+ ...decided.flatMap((outcome, index) => (0, import_ag_ui.actionProposalDecisionEvents)({
6377
+ threadId: input.threadId,
6378
+ runId: index === 0 ? input.runId : `${input.runId}:${index}`,
6379
+ text: outcome.text,
6380
+ proposalDecision: outcome.proposalDecision
6381
+ }))
6382
+ ]);
6383
+ return;
6384
+ }
6273
6385
  if (first !== void 0) {
6274
6386
  const streamRunId = first.address.stream;
6275
6387
  await this.agent.assertResumable(actor, streamRunId);
@@ -6298,11 +6410,7 @@ var AgUiRunHandler = class {
6298
6410
  if (owner !== null && turn.media.length === 0) {
6299
6411
  const decision = await this.agent.handleTextDecision(input.threadId, actor, turn.text);
6300
6412
  if ("proposalDecision" in decision) {
6301
- res.status(200);
6302
- res.setHeader("Content-Type", "text/event-stream");
6303
- res.setHeader("Cache-Control", "no-cache, no-transform");
6304
- res.flushHeaders();
6305
- for (const event of [
6413
+ this.writeEvents(res, [
6306
6414
  ...warningEvents(warnings),
6307
6415
  ...(0, import_ag_ui.actionProposalDecisionEvents)({
6308
6416
  threadId: input.threadId,
@@ -6310,8 +6418,7 @@ var AgUiRunHandler = class {
6310
6418
  text: decision.text,
6311
6419
  proposalDecision: decision.proposalDecision
6312
6420
  })
6313
- ]) res.write((0, import_ag_ui.agUiSse)(event));
6314
- res.end();
6421
+ ]);
6315
6422
  return;
6316
6423
  }
6317
6424
  }
@@ -6403,9 +6510,11 @@ var AgUiRunHandler = class {
6403
6510
  */
6404
6511
  async settle(actor, decisions) {
6405
6512
  const deliveries = [];
6513
+ const proposals = decisions.filter((decision) => decision.address.kind === "proposal");
6406
6514
  for (const { address, entry } of decisions) {
6407
6515
  const { toolCallId: toolCallId2 } = address;
6408
6516
  const abandoned = entry.status === "cancelled";
6517
+ if (address.kind === "proposal") continue;
6409
6518
  if (address.kind === "approval") {
6410
6519
  await this.agent.checkDecision(actor, toolCallId2);
6411
6520
  const decision = abandoned ? {
@@ -6442,9 +6551,53 @@ var AgUiRunHandler = class {
6442
6551
  via: AG_UI_VIA
6443
6552
  }));
6444
6553
  }
6554
+ if (proposals.length > 0) await this.decideProposals(actor, proposals);
6445
6555
  for (const deliver of deliveries) await deliver();
6446
6556
  }
6447
6557
  /**
6558
+ * Decide independent proposals through the proposal service — the call the native
6559
+ * `action-proposals/:id/approve|reject` routes make — never by signalling the origin run, which
6560
+ * is not waiting. Every payload is checked before the first decision; a refusal is the service's
6561
+ * own `403`/`404`.
6562
+ */
6563
+ async decideProposals(actor, decisions) {
6564
+ const planned = decisions.map(({ address, entry }) => {
6565
+ const decision = entry.status === "cancelled" ? {
6566
+ approved: false
6567
+ } : (0, import_ag_ui.readApprovalPayload)(entry.payload);
6568
+ if (decision === null || address.proposalId === void 0 || address.threadId === void 0) {
6569
+ throw invalid("invalid_resume", "an approval is answered with { approved: boolean, reason?, remember? }");
6570
+ }
6571
+ return {
6572
+ address,
6573
+ decision
6574
+ };
6575
+ });
6576
+ const outcomes = [];
6577
+ for (const { address, decision } of planned) {
6578
+ outcomes.push(await this.agent.decideActionProposal(actor, address.threadId, address.proposalId, {
6579
+ decision: decision.approved ? "approved" : "rejected",
6580
+ via: AG_UI_VIA,
6581
+ ...decision.remember !== void 0 ? {
6582
+ remember: decision.remember
6583
+ } : {},
6584
+ ...decision.reason !== void 0 ? {
6585
+ reason: decision.reason
6586
+ } : {}
6587
+ }));
6588
+ }
6589
+ return outcomes;
6590
+ }
6591
+ /** Answer with a complete list of events, no run behind them. */
6592
+ writeEvents(res, events) {
6593
+ res.status(200);
6594
+ res.setHeader("Content-Type", "text/event-stream");
6595
+ res.setHeader("Cache-Control", "no-cache, no-transform");
6596
+ res.flushHeaders();
6597
+ for (const event of events) res.write((0, import_ag_ui.agUiSse)(event));
6598
+ res.end();
6599
+ }
6600
+ /**
6448
6601
  * Pipe a run to the client as AG-UI 1.0 over SSE: one event per `data:` line, from `RUN_STARTED`
6449
6602
  * to the run's terminal event. It ends when the run stops to ask — the library run stays parked,
6450
6603
  * and the request that answers re-attaches to it.
@@ -6507,10 +6660,10 @@ function agUiAdapter(options = {}) {
6507
6660
  AgUiController = _ts_decorate27([
6508
6661
  (0, import_common28.Controller)(),
6509
6662
  _ts_param25(0, (0, import_common28.Inject)(AgentService)),
6510
- _ts_param25(1, (0, import_common28.Inject)(import_nestjs_agent_core32.AGENT_ACTOR_RESOLVER)),
6511
- _ts_param25(2, (0, import_common28.Inject)(import_nestjs_agent_core32.AGENT_OPTIONS)),
6663
+ _ts_param25(1, (0, import_common28.Inject)(import_nestjs_agent_core34.AGENT_ACTOR_RESOLVER)),
6664
+ _ts_param25(2, (0, import_common28.Inject)(import_nestjs_agent_core34.AGENT_OPTIONS)),
6512
6665
  _ts_param25(3, (0, import_common28.Optional)()),
6513
- _ts_param25(3, (0, import_common28.Inject)(import_nestjs_agent_core32.AGENT_ATTACHMENT_STAGING)),
6666
+ _ts_param25(3, (0, import_common28.Inject)(import_nestjs_agent_core34.AGENT_ATTACHMENT_STAGING)),
6514
6667
  _ts_metadata25("design:type", Function),
6515
6668
  _ts_metadata25("design:paramtypes", [
6516
6669
  typeof AgentService === "undefined" ? Object : AgentService,
@@ -6652,6 +6805,7 @@ __reExport(index_exports, require("@dudousxd/nestjs-agent-core"), module.exports
6652
6805
  attachmentLimits,
6653
6806
  declaredSkillProvider,
6654
6807
  defaultRequestUserMapper,
6808
+ defineTool,
6655
6809
  delegateToolName,
6656
6810
  provideAgentTool,
6657
6811
  provideAgentTools,