@dudousxd/nestjs-agent 1.1.2 → 1.3.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.
@@ -304,7 +304,21 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
304
304
  runId: ctx.runId,
305
305
  // A child forwards into the top-level sink but must not end/fail it (the top-level run owns it).
306
306
  openSink: /* @__PURE__ */ __name(async () => input.sinkRunId !== void 0 ? childSinkWriter(await deps.sink.open(sinkRunId)) : deps.sink.open(ctx.runId), "openSink"),
307
- awaitApproval: /* @__PURE__ */ __name((call) => ctx.waitForSignal(`tool:${ctx.runId}:${call.id}`), "awaitApproval"),
307
+ // A policy's time to live becomes the signal wait's own timeout: the runtime journals the
308
+ // deadline on the first call (a position of its own, reached only for a call the journal says
309
+ // has a ttl) and wakes the run when it passes. The lapse comes back as a Decision rather than a
310
+ // throw, so the loop settles the call `expired` on its ordinary rejection checkpoint.
311
+ awaitApproval: /* @__PURE__ */ __name((call, _toolCtx, opts) => opts?.timeoutMs === void 0 ? ctx.waitForSignal(`tool:${ctx.runId}:${call.id}`) : ctx.waitForSignal(`tool:${ctx.runId}:${call.id}`, {
312
+ timeoutMs: opts.timeoutMs
313
+ }).catch((error) => {
314
+ if (isSignalTimeout(error)) {
315
+ return {
316
+ approved: false,
317
+ expired: true
318
+ };
319
+ }
320
+ throw error;
321
+ }), "awaitApproval"),
308
322
  // The same wait, on the same signal key, carrying a typed answer instead of a yes/no — so a
309
323
  // question set and an approval reach a parked run through one path, and the HTTP surface that
310
324
  // settles either one is the same `POST /agent/tool-call/*` family.
@@ -478,6 +492,10 @@ AgentRunWorkflow = _ts_decorate2([
478
492
  typeof RunGateway === "undefined" ? Object : RunGateway
479
493
  ])
480
494
  ], AgentRunWorkflow);
495
+ function isSignalTimeout(error) {
496
+ return error instanceof Error && error.name === "SignalTimeoutError";
497
+ }
498
+ __name(isSignalTimeout, "isSignalTimeout");
481
499
 
482
500
  // src/durable/durable-agent-runner.ts
483
501
  var import_node_crypto = require("crypto");
@@ -788,8 +806,8 @@ AgentDurableModule = _ts_decorate4([
788
806
  ], AgentDurableModule);
789
807
 
790
808
  // src/agent.module.ts
791
- var import_nestjs_agent_core23 = require("@dudousxd/nestjs-agent-core");
792
- var import_common20 = require("@nestjs/common");
809
+ var import_nestjs_agent_core24 = require("@dudousxd/nestjs-agent-core");
810
+ var import_common21 = require("@nestjs/common");
793
811
  var import_core4 = require("@nestjs/core");
794
812
 
795
813
  // src/agent-deps.factory.ts
@@ -908,6 +926,9 @@ var AgentDepsFactory2 = class {
908
926
  store: this.store,
909
927
  sink: this.sink,
910
928
  rolesPolicy: this.rolesPolicy,
929
+ ...this.options.approvalPolicy !== void 0 ? {
930
+ approvalPolicy: this.options.approvalPolicy
931
+ } : {},
911
932
  registry: this.registry,
912
933
  promptContributors: this.promptContributors,
913
934
  systemPrompt: definition?.systemPrompt ?? "You are a helpful assistant.",
@@ -1191,18 +1212,35 @@ var AgentService = class {
1191
1212
  await this.assertOwnsActiveStream(actor, runId);
1192
1213
  return this.subscribe(runId);
1193
1214
  }
1194
- async approve(actor, toolCallId2) {
1195
- await this.assertOwnsToolCall(actor, toolCallId2);
1215
+ /**
1216
+ * Approve a parked action call as `actor`. Who may is the call's recorded approver's business
1217
+ * (see {@link assertMayDecide}); `remember` approves later calls of the same tool in the same
1218
+ * thread, and `via` names the surface the decision came through (`'web'`, `'slack'`, …) — both
1219
+ * persisted with the call.
1220
+ */
1221
+ async approve(actor, toolCallId2, opts = {}) {
1222
+ await this.assertMayDecide(actor, toolCallId2);
1196
1223
  return this.signalToolCall(toolCallId2, {
1197
- approved: true
1224
+ approved: true,
1225
+ executedByRef: actor.id,
1226
+ ...opts.remember === true ? {
1227
+ remember: true
1228
+ } : {},
1229
+ ...opts.via !== void 0 ? {
1230
+ decidedVia: opts.via
1231
+ } : {}
1198
1232
  });
1199
1233
  }
1200
- async reject(actor, toolCallId2, reason) {
1201
- await this.assertOwnsToolCall(actor, toolCallId2);
1234
+ async reject(actor, toolCallId2, reason, opts = {}) {
1235
+ await this.assertMayDecide(actor, toolCallId2);
1202
1236
  return this.signalToolCall(toolCallId2, {
1203
1237
  approved: false,
1238
+ executedByRef: actor.id,
1204
1239
  ...reason !== void 0 ? {
1205
1240
  reason
1241
+ } : {},
1242
+ ...opts.via !== void 0 ? {
1243
+ decidedVia: opts.via
1206
1244
  } : {}
1207
1245
  });
1208
1246
  }
@@ -1243,6 +1281,7 @@ var AgentService = class {
1243
1281
  * not the thread's own actor).
1244
1282
  */
1245
1283
  async signalToolCall(toolCallId2, reply) {
1284
+ await this.assertNotExpired(toolCallId2);
1246
1285
  const runId = await this.resolveRunForToolCall(toolCallId2);
1247
1286
  return this.runner.signal(runId, toolCallId2, reply);
1248
1287
  }
@@ -1481,6 +1520,47 @@ var AgentService = class {
1481
1520
  }
1482
1521
  }
1483
1522
  /**
1523
+ * Authorization seam for approve/reject. The call's recorded approver decides who may settle it:
1524
+ * the requester (the default, and every call recorded before approvers existed) is the thread's
1525
+ * own actor — the ownership check this always was; any other approver goes through the policy's
1526
+ * `canDecide`, which by default asks whether the actor holds that role.
1527
+ */
1528
+ async assertMayDecide(actor, toolCallId2) {
1529
+ const approval = await this.store.toolCallApproval?.(toolCallId2);
1530
+ const approver = approval?.approver ?? import_nestjs_agent_core8.REQUESTER_APPROVER;
1531
+ if (approver === import_nestjs_agent_core8.REQUESTER_APPROVER) {
1532
+ return this.assertOwnsToolCall(actor, toolCallId2);
1533
+ }
1534
+ const requesterRef = await this.store.ownerOfToolCall(toolCallId2);
1535
+ if (requesterRef === null) {
1536
+ throw new import_common6.NotFoundException(`tool call ${toolCallId2} not found`);
1537
+ }
1538
+ const allowed = await (0, import_nestjs_agent_core8.mayDecideApproval)(this.deps.forAgent().approvalPolicy, actor, {
1539
+ toolCallId: toolCallId2,
1540
+ approver,
1541
+ requesterRef
1542
+ });
1543
+ if (!allowed) {
1544
+ throw new import_common6.ForbiddenException(`this approval is for ${approver}`);
1545
+ }
1546
+ }
1547
+ /**
1548
+ * Refuse a decision on a request that has already lapsed — recorded `expired`, or past its
1549
+ * `expiresAt` with the run's own timer about to fire. Signalling it anyway would race the timeout:
1550
+ * a durable runtime buffers a signal nobody is waiting on, and a late approval must not be what a
1551
+ * later replay of the run reads back.
1552
+ */
1553
+ async assertNotExpired(toolCallId2) {
1554
+ const approval = await this.store.toolCallApproval?.(toolCallId2);
1555
+ if (approval === null || approval === void 0) {
1556
+ return;
1557
+ }
1558
+ const lapsed = approval.status === "expired" || approval.status === "pending_approval" && approval.expiresAt !== null && Date.parse(approval.expiresAt) <= Date.now();
1559
+ if (lapsed) {
1560
+ throw new import_common6.GoneException(`the approval request for tool call ${toolCallId2} has expired`);
1561
+ }
1562
+ }
1563
+ /**
1484
1564
  * Resolve the run awaiting `toolCallId`. Derived server-side from the tool call alone — the client
1485
1565
  * never knows or supplies a runId, and that run is the sub-agent's own child run when the pending
1486
1566
  * call belongs to a delegated agent. The store answers from the CALL'S OWN `runId` where it has
@@ -1558,6 +1638,12 @@ var AgentApprovalPortAdapter = class {
1558
1638
  approved: true,
1559
1639
  ...opts?.executedByRef !== void 0 ? {
1560
1640
  executedByRef: opts.executedByRef
1641
+ } : {},
1642
+ ...opts?.remember === true ? {
1643
+ remember: true
1644
+ } : {},
1645
+ ...opts?.decidedVia !== void 0 ? {
1646
+ decidedVia: opts.decidedVia
1561
1647
  } : {}
1562
1648
  });
1563
1649
  }
@@ -1569,6 +1655,9 @@ var AgentApprovalPortAdapter = class {
1569
1655
  } : {},
1570
1656
  ...opts?.reason !== void 0 ? {
1571
1657
  reason: opts.reason
1658
+ } : {},
1659
+ ...opts?.decidedVia !== void 0 ? {
1660
+ decidedVia: opts.decidedVia
1572
1661
  } : {}
1573
1662
  });
1574
1663
  }
@@ -2488,6 +2577,8 @@ var MAX_ANSWERED_QUESTIONS = 100;
2488
2577
  var MAX_VALUES_PER_QUESTION = 100;
2489
2578
  var MAX_ANSWER_VALUE_LENGTH = 4096;
2490
2579
  var MAX_REJECT_REASON_LENGTH = 4096;
2580
+ var MAX_VIA_LENGTH = 64;
2581
+ var DEFAULT_VIA = "web";
2491
2582
  function toolCallId(claimed) {
2492
2583
  if (typeof claimed !== "string" || claimed.length === 0) {
2493
2584
  throw new import_common15.BadRequestException("toolCallId must be a non-empty string");
@@ -2508,6 +2599,26 @@ function rejectReason(claimed) {
2508
2599
  return claimed;
2509
2600
  }
2510
2601
  __name(rejectReason, "rejectReason");
2602
+ function remember(claimed) {
2603
+ if (claimed === void 0) {
2604
+ return false;
2605
+ }
2606
+ if (typeof claimed !== "boolean") {
2607
+ throw new import_common15.BadRequestException("remember must be a boolean");
2608
+ }
2609
+ return claimed;
2610
+ }
2611
+ __name(remember, "remember");
2612
+ function via(claimed) {
2613
+ if (claimed === void 0) {
2614
+ return DEFAULT_VIA;
2615
+ }
2616
+ if (typeof claimed !== "string" || claimed.length === 0 || claimed.length > MAX_VIA_LENGTH) {
2617
+ throw new import_common15.BadRequestException(`via must be a string of 1-${MAX_VIA_LENGTH} characters`);
2618
+ }
2619
+ return claimed;
2620
+ }
2621
+ __name(via, "via");
2511
2622
  function answers(claimed) {
2512
2623
  if (claimed === void 0) {
2513
2624
  return void 0;
@@ -2552,14 +2663,19 @@ var ToolCallController = class {
2552
2663
  }
2553
2664
  async approve(req, body) {
2554
2665
  const actor = await this.actorResolver.resolve(req);
2555
- await this.agent.approve(actor, toolCallId(body.toolCallId));
2666
+ await this.agent.approve(actor, toolCallId(body.toolCallId), {
2667
+ remember: remember(body.remember),
2668
+ via: via(body.via)
2669
+ });
2556
2670
  return {
2557
2671
  ok: true
2558
2672
  };
2559
2673
  }
2560
2674
  async reject(req, body) {
2561
2675
  const actor = await this.actorResolver.resolve(req);
2562
- await this.agent.reject(actor, toolCallId(body.toolCallId), rejectReason(body.reason));
2676
+ await this.agent.reject(actor, toolCallId(body.toolCallId), rejectReason(body.reason), {
2677
+ via: via(body.via)
2678
+ });
2563
2679
  return {
2564
2680
  ok: true
2565
2681
  };
@@ -2625,7 +2741,7 @@ _ts_decorate15([
2625
2741
  _ts_metadata14("design:type", Function),
2626
2742
  _ts_metadata14("design:paramtypes", [
2627
2743
  typeof Request === "undefined" ? Object : Request,
2628
- typeof ApproveBody === "undefined" ? Object : ApproveBody
2744
+ Object
2629
2745
  ]),
2630
2746
  _ts_metadata14("design:returntype", Promise)
2631
2747
  ], ToolCallController.prototype, "skip", null);
@@ -2639,9 +2755,90 @@ ToolCallController = _ts_decorate15([
2639
2755
  ])
2640
2756
  ], ToolCallController);
2641
2757
 
2642
- // src/discovery/agent-discovery.service.ts
2758
+ // src/controller/tools.controller.ts
2643
2759
  var import_nestjs_agent_core17 = require("@dudousxd/nestjs-agent-core");
2644
2760
  var import_common16 = require("@nestjs/common");
2761
+ function _ts_decorate16(decorators, target, key, desc) {
2762
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2763
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2764
+ r = Reflect.decorate(decorators, target, key, desc);
2765
+ } else {
2766
+ for (var i = decorators.length - 1; i >= 0; i--) {
2767
+ if (d = decorators[i]) {
2768
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2769
+ }
2770
+ }
2771
+ }
2772
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2773
+ }
2774
+ __name(_ts_decorate16, "_ts_decorate");
2775
+ function _ts_metadata15(metadataKey, metadataValue) {
2776
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2777
+ return Reflect.metadata(metadataKey, metadataValue);
2778
+ }
2779
+ }
2780
+ __name(_ts_metadata15, "_ts_metadata");
2781
+ function _ts_param14(paramIndex, decorator) {
2782
+ return function(target, key) {
2783
+ decorator(target, key, paramIndex);
2784
+ };
2785
+ }
2786
+ __name(_ts_param14, "_ts_param");
2787
+ var ToolsController = class {
2788
+ static {
2789
+ __name(this, "ToolsController");
2790
+ }
2791
+ actorResolver;
2792
+ depsFactory;
2793
+ agents;
2794
+ constructor(actorResolver, depsFactory, agents) {
2795
+ this.actorResolver = actorResolver;
2796
+ this.depsFactory = depsFactory;
2797
+ this.agents = agents;
2798
+ }
2799
+ async list(req, agent) {
2800
+ if (agent !== void 0 && this.agents.get(agent) === void 0) {
2801
+ throw new import_common16.NotFoundException(`No agent named "${agent}"`);
2802
+ }
2803
+ const actor = await this.actorResolver.resolve(req);
2804
+ const deps = this.depsFactory.forAgent(agent);
2805
+ const specs = await deps.registry.visibleSpecs(actor, deps.rolesPolicy, deps.toolAllowList);
2806
+ return specs.map((spec) => ({
2807
+ name: spec.name,
2808
+ kind: spec.kind,
2809
+ ...spec.presentation !== void 0 ? {
2810
+ presentation: spec.presentation
2811
+ } : {}
2812
+ }));
2813
+ }
2814
+ };
2815
+ _ts_decorate16([
2816
+ (0, import_common16.Get)(),
2817
+ _ts_param14(0, (0, import_common16.Req)()),
2818
+ _ts_param14(1, (0, import_common16.Query)("agent")),
2819
+ _ts_metadata15("design:type", Function),
2820
+ _ts_metadata15("design:paramtypes", [
2821
+ typeof Request === "undefined" ? Object : Request,
2822
+ String
2823
+ ]),
2824
+ _ts_metadata15("design:returntype", Promise)
2825
+ ], ToolsController.prototype, "list", null);
2826
+ ToolsController = _ts_decorate16([
2827
+ (0, import_common16.Controller)("tools"),
2828
+ _ts_param14(0, (0, import_common16.Inject)(import_nestjs_agent_core17.AGENT_ACTOR_RESOLVER)),
2829
+ _ts_param14(1, (0, import_common16.Inject)(import_nestjs_agent_core17.AGENT_DEPS_FACTORY)),
2830
+ _ts_param14(2, (0, import_common16.Inject)(import_nestjs_agent_core17.AGENT_REGISTRY)),
2831
+ _ts_metadata15("design:type", Function),
2832
+ _ts_metadata15("design:paramtypes", [
2833
+ typeof ActorResolver === "undefined" ? Object : ActorResolver,
2834
+ typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
2835
+ typeof import_nestjs_agent_core17.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core17.AgentRegistry
2836
+ ])
2837
+ ], ToolsController);
2838
+
2839
+ // src/discovery/agent-discovery.service.ts
2840
+ var import_nestjs_agent_core18 = require("@dudousxd/nestjs-agent-core");
2841
+ var import_common17 = require("@nestjs/common");
2645
2842
  var import_core = require("@nestjs/core");
2646
2843
 
2647
2844
  // src/decorator/agent.decorator.ts
@@ -2658,7 +2855,7 @@ var SYSTEM_PROMPT_METADATA = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:
2658
2855
  var SYSTEM_PROMPT_CONTRIBUTOR_METADATA = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:system-prompt-contributor");
2659
2856
 
2660
2857
  // src/discovery/agent-discovery.service.ts
2661
- function _ts_decorate16(decorators, target, key, desc) {
2858
+ function _ts_decorate17(decorators, target, key, desc) {
2662
2859
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2663
2860
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2664
2861
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2671,19 +2868,19 @@ function _ts_decorate16(decorators, target, key, desc) {
2671
2868
  }
2672
2869
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2673
2870
  }
2674
- __name(_ts_decorate16, "_ts_decorate");
2675
- function _ts_metadata15(metadataKey, metadataValue) {
2871
+ __name(_ts_decorate17, "_ts_decorate");
2872
+ function _ts_metadata16(metadataKey, metadataValue) {
2676
2873
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2677
2874
  return Reflect.metadata(metadataKey, metadataValue);
2678
2875
  }
2679
2876
  }
2680
- __name(_ts_metadata15, "_ts_metadata");
2681
- function _ts_param14(paramIndex, decorator) {
2877
+ __name(_ts_metadata16, "_ts_metadata");
2878
+ function _ts_param15(paramIndex, decorator) {
2682
2879
  return function(target, key) {
2683
2880
  decorator(target, key, paramIndex);
2684
2881
  };
2685
2882
  }
2686
- __name(_ts_param14, "_ts_param");
2883
+ __name(_ts_param15, "_ts_param");
2687
2884
  var AgentDiscoveryService = class _AgentDiscoveryService {
2688
2885
  static {
2689
2886
  __name(this, "AgentDiscoveryService");
@@ -2692,7 +2889,7 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
2692
2889
  scanner;
2693
2890
  registry;
2694
2891
  contributors;
2695
- logger = new import_common16.Logger(_AgentDiscoveryService.name);
2892
+ logger = new import_common17.Logger(_AgentDiscoveryService.name);
2696
2893
  constructor(discovery, scanner, registry, contributors) {
2697
2894
  this.discovery = discovery;
2698
2895
  this.scanner = scanner;
@@ -2810,22 +3007,22 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
2810
3007
  return (ctx) => candidate.call(instance, ctx);
2811
3008
  }
2812
3009
  };
2813
- AgentDiscoveryService = _ts_decorate16([
2814
- (0, import_common16.Injectable)(),
2815
- _ts_param14(2, (0, import_common16.Inject)(import_nestjs_agent_core17.AGENT_REGISTRY)),
2816
- _ts_param14(3, (0, import_common16.Inject)(import_nestjs_agent_core17.AGENT_PROMPT_CONTRIBUTORS)),
2817
- _ts_metadata15("design:type", Function),
2818
- _ts_metadata15("design:paramtypes", [
3010
+ AgentDiscoveryService = _ts_decorate17([
3011
+ (0, import_common17.Injectable)(),
3012
+ _ts_param15(2, (0, import_common17.Inject)(import_nestjs_agent_core18.AGENT_REGISTRY)),
3013
+ _ts_param15(3, (0, import_common17.Inject)(import_nestjs_agent_core18.AGENT_PROMPT_CONTRIBUTORS)),
3014
+ _ts_metadata16("design:type", Function),
3015
+ _ts_metadata16("design:paramtypes", [
2819
3016
  typeof import_core.DiscoveryService === "undefined" ? Object : import_core.DiscoveryService,
2820
3017
  typeof import_core.MetadataScanner === "undefined" ? Object : import_core.MetadataScanner,
2821
- typeof import_nestjs_agent_core17.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core17.AgentRegistry,
3018
+ typeof import_nestjs_agent_core18.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core18.AgentRegistry,
2822
3019
  Array
2823
3020
  ])
2824
3021
  ], AgentDiscoveryService);
2825
3022
 
2826
3023
  // src/discovery/ai-tool-discovery.service.ts
2827
- var import_nestjs_agent_core18 = require("@dudousxd/nestjs-agent-core");
2828
- var import_common17 = require("@nestjs/common");
3024
+ var import_nestjs_agent_core19 = require("@dudousxd/nestjs-agent-core");
3025
+ var import_common18 = require("@nestjs/common");
2829
3026
  var import_core2 = require("@nestjs/core");
2830
3027
  var import_zod = require("zod");
2831
3028
 
@@ -2845,7 +3042,7 @@ function isBrandedFunctionalTool(value) {
2845
3042
  __name(isBrandedFunctionalTool, "isBrandedFunctionalTool");
2846
3043
 
2847
3044
  // src/discovery/ai-tool-discovery.service.ts
2848
- function _ts_decorate17(decorators, target, key, desc) {
3045
+ function _ts_decorate18(decorators, target, key, desc) {
2849
3046
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2850
3047
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2851
3048
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2858,19 +3055,19 @@ function _ts_decorate17(decorators, target, key, desc) {
2858
3055
  }
2859
3056
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2860
3057
  }
2861
- __name(_ts_decorate17, "_ts_decorate");
2862
- function _ts_metadata16(metadataKey, metadataValue) {
3058
+ __name(_ts_decorate18, "_ts_decorate");
3059
+ function _ts_metadata17(metadataKey, metadataValue) {
2863
3060
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2864
3061
  return Reflect.metadata(metadataKey, metadataValue);
2865
3062
  }
2866
3063
  }
2867
- __name(_ts_metadata16, "_ts_metadata");
2868
- function _ts_param15(paramIndex, decorator) {
3064
+ __name(_ts_metadata17, "_ts_metadata");
3065
+ function _ts_param16(paramIndex, decorator) {
2869
3066
  return function(target, key) {
2870
3067
  decorator(target, key, paramIndex);
2871
3068
  };
2872
3069
  }
2873
- __name(_ts_param15, "_ts_param");
3070
+ __name(_ts_param16, "_ts_param");
2874
3071
  var AiToolDiscoveryService = class _AiToolDiscoveryService {
2875
3072
  static {
2876
3073
  __name(this, "AiToolDiscoveryService");
@@ -2879,7 +3076,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
2879
3076
  registry;
2880
3077
  agents;
2881
3078
  options;
2882
- logger = new import_common17.Logger(_AiToolDiscoveryService.name);
3079
+ logger = new import_common18.Logger(_AiToolDiscoveryService.name);
2883
3080
  constructor(discovery, registry, agents, options) {
2884
3081
  this.discovery = discovery;
2885
3082
  this.registry = registry;
@@ -2924,6 +3121,9 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
2924
3121
  } : {},
2925
3122
  ...meta.enabled !== void 0 ? {
2926
3123
  enabled: meta.enabled
3124
+ } : {},
3125
+ ...meta.presentation !== void 0 ? {
3126
+ presentation: meta.presentation
2927
3127
  } : {}
2928
3128
  }, {
2929
3129
  execute: /* @__PURE__ */ __name((input, ctx) => instance.execute(input, ctx), "execute"),
@@ -2947,7 +3147,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
2947
3147
  let delegates = 0;
2948
3148
  for (const definition of this.agents.list()) {
2949
3149
  for (const edge of definition.delegatesTo ?? []) {
2950
- const { agent: target, detached } = (0, import_nestjs_agent_core18.normalizeDelegation)(edge);
3150
+ const { agent: target, detached } = (0, import_nestjs_agent_core19.normalizeDelegation)(edge);
2951
3151
  const targetDefinition = this.agents.get(target);
2952
3152
  if (targetDefinition === void 0) {
2953
3153
  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.`);
@@ -2997,13 +3197,13 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
2997
3197
  return true;
2998
3198
  }
2999
3199
  };
3000
- AiToolDiscoveryService = _ts_decorate17([
3001
- (0, import_common17.Injectable)(),
3002
- _ts_param15(1, (0, import_common17.Inject)(import_nestjs_agent_core18.AGENT_TOOL_REGISTRY)),
3003
- _ts_param15(2, (0, import_common17.Inject)(import_nestjs_agent_core18.AGENT_REGISTRY)),
3004
- _ts_param15(3, (0, import_common17.Inject)(import_nestjs_agent_core18.AGENT_OPTIONS)),
3005
- _ts_metadata16("design:type", Function),
3006
- _ts_metadata16("design:paramtypes", [
3200
+ AiToolDiscoveryService = _ts_decorate18([
3201
+ (0, import_common18.Injectable)(),
3202
+ _ts_param16(1, (0, import_common18.Inject)(import_nestjs_agent_core19.AGENT_TOOL_REGISTRY)),
3203
+ _ts_param16(2, (0, import_common18.Inject)(import_nestjs_agent_core19.AGENT_REGISTRY)),
3204
+ _ts_param16(3, (0, import_common18.Inject)(import_nestjs_agent_core19.AGENT_OPTIONS)),
3205
+ _ts_metadata17("design:type", Function),
3206
+ _ts_metadata17("design:paramtypes", [
3007
3207
  typeof import_core2.DiscoveryService === "undefined" ? Object : import_core2.DiscoveryService,
3008
3208
  typeof ToolRegistry === "undefined" ? Object : ToolRegistry,
3009
3209
  typeof AgentRegistry === "undefined" ? Object : AgentRegistry,
@@ -3012,25 +3212,25 @@ AiToolDiscoveryService = _ts_decorate17([
3012
3212
  ], AiToolDiscoveryService);
3013
3213
 
3014
3214
  // src/discovery/skill-discovery.service.ts
3015
- var import_nestjs_agent_core20 = require("@dudousxd/nestjs-agent-core");
3016
- var import_common18 = require("@nestjs/common");
3215
+ var import_nestjs_agent_core21 = require("@dudousxd/nestjs-agent-core");
3216
+ var import_common19 = require("@nestjs/common");
3017
3217
  var import_core3 = require("@nestjs/core");
3018
3218
 
3019
3219
  // src/decorator/skill.decorator.ts
3020
3220
  var import_reflect_metadata4 = require("reflect-metadata");
3021
- var import_nestjs_agent_core19 = require("@dudousxd/nestjs-agent-core");
3221
+ var import_nestjs_agent_core20 = require("@dudousxd/nestjs-agent-core");
3022
3222
  var SKILL_METADATA = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:skill-metadata");
3023
3223
  function readSkillMetadata(target) {
3024
3224
  return Reflect.getMetadata(SKILL_METADATA, target);
3025
3225
  }
3026
3226
  __name(readSkillMetadata, "readSkillMetadata");
3027
3227
  function skillScope(options) {
3028
- return options.scope ?? import_nestjs_agent_core19.GLOBAL_SCOPE;
3228
+ return options.scope ?? import_nestjs_agent_core20.GLOBAL_SCOPE;
3029
3229
  }
3030
3230
  __name(skillScope, "skillScope");
3031
3231
 
3032
3232
  // src/discovery/skill-discovery.service.ts
3033
- function _ts_decorate18(decorators, target, key, desc) {
3233
+ function _ts_decorate19(decorators, target, key, desc) {
3034
3234
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3035
3235
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3036
3236
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3043,26 +3243,26 @@ function _ts_decorate18(decorators, target, key, desc) {
3043
3243
  }
3044
3244
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3045
3245
  }
3046
- __name(_ts_decorate18, "_ts_decorate");
3047
- function _ts_metadata17(metadataKey, metadataValue) {
3246
+ __name(_ts_decorate19, "_ts_decorate");
3247
+ function _ts_metadata18(metadataKey, metadataValue) {
3048
3248
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3049
3249
  return Reflect.metadata(metadataKey, metadataValue);
3050
3250
  }
3051
3251
  }
3052
- __name(_ts_metadata17, "_ts_metadata");
3053
- function _ts_param16(paramIndex, decorator) {
3252
+ __name(_ts_metadata18, "_ts_metadata");
3253
+ function _ts_param17(paramIndex, decorator) {
3054
3254
  return function(target, key) {
3055
3255
  decorator(target, key, paramIndex);
3056
3256
  };
3057
3257
  }
3058
- __name(_ts_param16, "_ts_param");
3258
+ __name(_ts_param17, "_ts_param");
3059
3259
  var SkillDiscoveryService = class _SkillDiscoveryService {
3060
3260
  static {
3061
3261
  __name(this, "SkillDiscoveryService");
3062
3262
  }
3063
3263
  discovery;
3064
3264
  declared;
3065
- logger = new import_common18.Logger(_SkillDiscoveryService.name);
3265
+ logger = new import_common19.Logger(_SkillDiscoveryService.name);
3066
3266
  constructor(discovery, declared) {
3067
3267
  this.discovery = discovery;
3068
3268
  this.declared = declared;
@@ -3099,11 +3299,11 @@ var SkillDiscoveryService = class _SkillDiscoveryService {
3099
3299
  return flat === void 0 ? void 0 : () => flat;
3100
3300
  }
3101
3301
  };
3102
- SkillDiscoveryService = _ts_decorate18([
3103
- (0, import_common18.Injectable)(),
3104
- _ts_param16(1, (0, import_common18.Inject)(import_nestjs_agent_core20.AGENT_SKILL_SOURCES)),
3105
- _ts_metadata17("design:type", Function),
3106
- _ts_metadata17("design:paramtypes", [
3302
+ SkillDiscoveryService = _ts_decorate19([
3303
+ (0, import_common19.Injectable)(),
3304
+ _ts_param17(1, (0, import_common19.Inject)(import_nestjs_agent_core21.AGENT_SKILL_SOURCES)),
3305
+ _ts_metadata18("design:type", Function),
3306
+ _ts_metadata18("design:paramtypes", [
3107
3307
  typeof import_core3.DiscoveryService === "undefined" ? Object : import_core3.DiscoveryService,
3108
3308
  Array
3109
3309
  ])
@@ -3133,9 +3333,9 @@ var LedgerQuotaStore = class {
3133
3333
  };
3134
3334
 
3135
3335
  // src/runner/inline-agent-runner.ts
3136
- var import_nestjs_agent_core21 = require("@dudousxd/nestjs-agent-core");
3137
- var import_common19 = require("@nestjs/common");
3138
- function _ts_decorate19(decorators, target, key, desc) {
3336
+ var import_nestjs_agent_core22 = require("@dudousxd/nestjs-agent-core");
3337
+ var import_common20 = require("@nestjs/common");
3338
+ function _ts_decorate20(decorators, target, key, desc) {
3139
3339
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3140
3340
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3141
3341
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3148,26 +3348,26 @@ function _ts_decorate19(decorators, target, key, desc) {
3148
3348
  }
3149
3349
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3150
3350
  }
3151
- __name(_ts_decorate19, "_ts_decorate");
3152
- function _ts_metadata18(metadataKey, metadataValue) {
3351
+ __name(_ts_decorate20, "_ts_decorate");
3352
+ function _ts_metadata19(metadataKey, metadataValue) {
3153
3353
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3154
3354
  return Reflect.metadata(metadataKey, metadataValue);
3155
3355
  }
3156
3356
  }
3157
- __name(_ts_metadata18, "_ts_metadata");
3158
- function _ts_param17(paramIndex, decorator) {
3357
+ __name(_ts_metadata19, "_ts_metadata");
3358
+ function _ts_param18(paramIndex, decorator) {
3159
3359
  return function(target, key) {
3160
3360
  decorator(target, key, paramIndex);
3161
3361
  };
3162
3362
  }
3163
- __name(_ts_param17, "_ts_param");
3363
+ __name(_ts_param18, "_ts_param");
3164
3364
  var InlineAgentRunner = class _InlineAgentRunner {
3165
3365
  static {
3166
3366
  __name(this, "InlineAgentRunner");
3167
3367
  }
3168
3368
  factory;
3169
3369
  store;
3170
- logger = new import_common19.Logger(_InlineAgentRunner.name);
3370
+ logger = new import_common20.Logger(_InlineAgentRunner.name);
3171
3371
  pending = /* @__PURE__ */ new Map();
3172
3372
  /**
3173
3373
  * Runs someone has asked to stop. In-process, like `pending`, and for the same reason: this runner
@@ -3196,18 +3396,18 @@ var InlineAgentRunner = class _InlineAgentRunner {
3196
3396
  ] : []
3197
3397
  ]
3198
3398
  });
3199
- void (0, import_nestjs_agent_core21.runAgentLoop)({
3399
+ void (0, import_nestjs_agent_core22.runAgentLoop)({
3200
3400
  ...deps,
3201
3401
  day
3202
3402
  }, input, hooks).then(() => this.store.setActiveStream(input.threadId, null)).catch(async (error) => {
3203
- if (error instanceof import_nestjs_agent_core21.RunCancelledError) {
3403
+ if (error instanceof import_nestjs_agent_core22.RunCancelledError) {
3204
3404
  await this.settleCancelled(runId, input.threadId, deps);
3205
3405
  return;
3206
3406
  }
3207
3407
  const message = error instanceof Error ? error.message : String(error);
3208
- const code = (0, import_nestjs_agent_core21.agentFailureCode)(error);
3408
+ const code = (0, import_nestjs_agent_core22.agentFailureCode)(error);
3209
3409
  this.logger.error(`agent run ${runId} failed (${code}): ${message}`);
3210
- (0, import_nestjs_agent_core21.publishAgentRunFailed)({
3410
+ (0, import_nestjs_agent_core22.publishAgentRunFailed)({
3211
3411
  runId,
3212
3412
  code,
3213
3413
  message
@@ -3256,7 +3456,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3256
3456
  for (const [key, waiter] of this.pending) {
3257
3457
  if (key.startsWith(`${runId}:`)) {
3258
3458
  this.pending.delete(key);
3259
- waiter.reject(new import_nestjs_agent_core21.RunCancelledError());
3459
+ waiter.reject(new import_nestjs_agent_core22.RunCancelledError());
3260
3460
  }
3261
3461
  }
3262
3462
  await Promise.resolve();
@@ -3271,7 +3471,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3271
3471
  this.logger.log(`agent run ${runId} cancelled`);
3272
3472
  await this.store.setActiveStream(threadId, null);
3273
3473
  const writer = await deps.sink.open(runId);
3274
- await writer.write((0, import_nestjs_agent_core21.encodeStreamEvent)({
3474
+ await writer.write((0, import_nestjs_agent_core22.encodeStreamEvent)({
3275
3475
  kind: "cancelled"
3276
3476
  }));
3277
3477
  await writer.end();
@@ -3286,6 +3486,36 @@ var InlineAgentRunner = class _InlineAgentRunner {
3286
3486
  * shape it is delivering — the loop asked for one and only ever gets what the caller sent. A
3287
3487
  * cancel settles the wait too, by rejecting it.
3288
3488
  */
3489
+ /**
3490
+ * {@link park} for an approval, bounded by the policy's time to live when it has one: the timer
3491
+ * settles the wait as `expired` — the same Decision the durable runner builds from its signal
3492
+ * timeout — and a decision that arrives first disarms it.
3493
+ */
3494
+ parkApproval(runId, toolCallId2, timeoutMs) {
3495
+ const waiting = this.park(runId, toolCallId2);
3496
+ if (timeoutMs === void 0) {
3497
+ return waiting;
3498
+ }
3499
+ const key = `${runId}:${toolCallId2}`;
3500
+ let timer;
3501
+ const lapse = new Promise((resolve) => {
3502
+ timer = setTimeout(() => {
3503
+ const entry = this.pending.get(key);
3504
+ if (entry !== void 0) {
3505
+ this.pending.delete(key);
3506
+ resolve({
3507
+ approved: false,
3508
+ expired: true
3509
+ });
3510
+ }
3511
+ }, timeoutMs);
3512
+ timer.unref?.();
3513
+ });
3514
+ return Promise.race([
3515
+ waiting,
3516
+ lapse
3517
+ ]).finally(() => clearTimeout(timer));
3518
+ }
3289
3519
  park(runId, toolCallId2) {
3290
3520
  return new Promise((resolve, reject) => {
3291
3521
  this.pending.set(`${runId}:${toolCallId2}`, {
@@ -3299,10 +3529,10 @@ var InlineAgentRunner = class _InlineAgentRunner {
3299
3529
  return {
3300
3530
  runId,
3301
3531
  openSink: /* @__PURE__ */ __name(() => deps.sink.open(runId), "openSink"),
3302
- awaitApproval: /* @__PURE__ */ __name((call) => this.park(runId, call.id), "awaitApproval"),
3532
+ awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
3303
3533
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
3304
3534
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
3305
- parallel: import_nestjs_agent_core21.settleAll,
3535
+ parallel: import_nestjs_agent_core22.settleAll,
3306
3536
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
3307
3537
  runAgent: /* @__PURE__ */ __name((agentName, task) => this.runNested({
3308
3538
  agentName,
@@ -3350,10 +3580,10 @@ var InlineAgentRunner = class _InlineAgentRunner {
3350
3580
  const hooks = {
3351
3581
  runId,
3352
3582
  openSink: /* @__PURE__ */ __name(() => deps.sink.open(runId), "openSink"),
3353
- awaitApproval: /* @__PURE__ */ __name((call) => this.park(runId, call.id), "awaitApproval"),
3583
+ awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
3354
3584
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
3355
3585
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
3356
- parallel: import_nestjs_agent_core21.settleAll,
3586
+ parallel: import_nestjs_agent_core22.settleAll,
3357
3587
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
3358
3588
  runAgent: /* @__PURE__ */ __name((childName, childTask) => this.runNested({
3359
3589
  agentName: childName,
@@ -3386,7 +3616,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3386
3616
  }
3387
3617
  }), "startAgent")
3388
3618
  };
3389
- void (0, import_nestjs_agent_core21.runAgentLoop)({
3619
+ void (0, import_nestjs_agent_core22.runAgentLoop)({
3390
3620
  ...deps,
3391
3621
  day
3392
3622
  }, {
@@ -3400,13 +3630,13 @@ var InlineAgentRunner = class _InlineAgentRunner {
3400
3630
  parentRunId,
3401
3631
  deliverTo
3402
3632
  }, hooks).catch(async (error) => {
3403
- const cancelled = error instanceof import_nestjs_agent_core21.RunCancelledError;
3633
+ const cancelled = error instanceof import_nestjs_agent_core22.RunCancelledError;
3404
3634
  const message = error instanceof Error ? error.message : String(error);
3405
3635
  if (!cancelled) {
3406
3636
  this.logger.error(`detached agent run ${runId} failed: ${message}`);
3407
- (0, import_nestjs_agent_core21.publishAgentRunFailed)({
3637
+ (0, import_nestjs_agent_core22.publishAgentRunFailed)({
3408
3638
  runId,
3409
- code: (0, import_nestjs_agent_core21.agentFailureCode)(error),
3639
+ code: (0, import_nestjs_agent_core22.agentFailureCode)(error),
3410
3640
  message
3411
3641
  });
3412
3642
  }
@@ -3414,11 +3644,11 @@ var InlineAgentRunner = class _InlineAgentRunner {
3414
3644
  runId,
3415
3645
  status: cancelled ? "cancelled" : "failed",
3416
3646
  ...cancelled ? {} : {
3417
- errorCode: (0, import_nestjs_agent_core21.agentFailureCode)(error),
3647
+ errorCode: (0, import_nestjs_agent_core22.agentFailureCode)(error),
3418
3648
  errorMessage: message
3419
3649
  }
3420
3650
  });
3421
- await (0, import_nestjs_agent_core21.settleUnsettledDelegation)({
3651
+ await (0, import_nestjs_agent_core22.settleUnsettledDelegation)({
3422
3652
  store: this.store,
3423
3653
  delivery: deliverTo,
3424
3654
  agent: agentName,
@@ -3454,10 +3684,10 @@ var InlineAgentRunner = class _InlineAgentRunner {
3454
3684
  runId,
3455
3685
  // Forward into the top-level stream; the top-level run owns end/fail on that shared sink.
3456
3686
  openSink: /* @__PURE__ */ __name(async () => childSinkWriter(await deps.sink.open(sinkRunId)), "openSink"),
3457
- awaitApproval: /* @__PURE__ */ __name((call) => this.park(runId, call.id), "awaitApproval"),
3687
+ awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
3458
3688
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
3459
3689
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
3460
- parallel: import_nestjs_agent_core21.settleAll,
3690
+ parallel: import_nestjs_agent_core22.settleAll,
3461
3691
  // A child stops when it is cancelled OR when the run a human is actually watching is: the
3462
3692
  // canceller names the top-level run, which is the only id that ever left the server.
3463
3693
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId) || this.cancelled.has(sinkRunId), "cancelled"),
@@ -3492,7 +3722,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3492
3722
  }), "startAgent")
3493
3723
  };
3494
3724
  try {
3495
- return await (0, import_nestjs_agent_core21.runAgentLoop)({
3725
+ return await (0, import_nestjs_agent_core22.runAgentLoop)({
3496
3726
  ...deps,
3497
3727
  day
3498
3728
  }, {
@@ -3511,19 +3741,19 @@ var InlineAgentRunner = class _InlineAgentRunner {
3511
3741
  }
3512
3742
  }
3513
3743
  };
3514
- InlineAgentRunner = _ts_decorate19([
3515
- (0, import_common19.Injectable)(),
3516
- _ts_param17(0, (0, import_common19.Inject)(import_nestjs_agent_core21.AGENT_DEPS_FACTORY)),
3517
- _ts_param17(1, (0, import_common19.Inject)(import_nestjs_agent_core21.AGENT_STORE)),
3518
- _ts_metadata18("design:type", Function),
3519
- _ts_metadata18("design:paramtypes", [
3744
+ InlineAgentRunner = _ts_decorate20([
3745
+ (0, import_common20.Injectable)(),
3746
+ _ts_param18(0, (0, import_common20.Inject)(import_nestjs_agent_core22.AGENT_DEPS_FACTORY)),
3747
+ _ts_param18(1, (0, import_common20.Inject)(import_nestjs_agent_core22.AGENT_STORE)),
3748
+ _ts_metadata19("design:type", Function),
3749
+ _ts_metadata19("design:paramtypes", [
3520
3750
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
3521
3751
  typeof AgentStore === "undefined" ? Object : AgentStore
3522
3752
  ])
3523
3753
  ], InlineAgentRunner);
3524
3754
 
3525
3755
  // src/skills-config.ts
3526
- var import_nestjs_agent_core22 = require("@dudousxd/nestjs-agent-core");
3756
+ var import_nestjs_agent_core23 = require("@dudousxd/nestjs-agent-core");
3527
3757
  function declaredSkillProvider(declared) {
3528
3758
  return {
3529
3759
  list: /* @__PURE__ */ __name(({ scopes }) => declared.filter((skill) => scopes.includes(skill.scope)).map(({ name, description, scope }) => ({
@@ -3549,7 +3779,7 @@ function resolveSkillsConfig(options, declared) {
3549
3779
  declaredSkillProvider(declared)
3550
3780
  ];
3551
3781
  return {
3552
- provider: providers.length === 1 ? providers[0] : (0, import_nestjs_agent_core22.compositeSkillProvider)(providers),
3782
+ provider: providers.length === 1 ? providers[0] : (0, import_nestjs_agent_core23.compositeSkillProvider)(providers),
3553
3783
  ...options.scopes !== void 0 ? {
3554
3784
  scopes: options.scopes
3555
3785
  } : {},
@@ -3561,7 +3791,7 @@ function resolveSkillsConfig(options, declared) {
3561
3791
  __name(resolveSkillsConfig, "resolveSkillsConfig");
3562
3792
 
3563
3793
  // src/agent.module.ts
3564
- function _ts_decorate20(decorators, target, key, desc) {
3794
+ function _ts_decorate21(decorators, target, key, desc) {
3565
3795
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3566
3796
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3567
3797
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3574,92 +3804,92 @@ function _ts_decorate20(decorators, target, key, desc) {
3574
3804
  }
3575
3805
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3576
3806
  }
3577
- __name(_ts_decorate20, "_ts_decorate");
3807
+ __name(_ts_decorate21, "_ts_decorate");
3578
3808
  var DEFAULT_PATH = "agent";
3579
3809
  function sharedProviders(durable, includeStore) {
3580
3810
  const providers = [
3581
3811
  {
3582
- provide: import_nestjs_agent_core23.AGENT_TOOL_REGISTRY,
3583
- useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core23.ToolRegistry(), "useFactory")
3812
+ provide: import_nestjs_agent_core24.AGENT_TOOL_REGISTRY,
3813
+ useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core24.ToolRegistry(), "useFactory")
3584
3814
  },
3585
3815
  // Starts empty; AgentDiscoveryService populates it from `@Agent`-decorated providers at boot.
3586
3816
  {
3587
- provide: import_nestjs_agent_core23.AGENT_REGISTRY,
3588
- useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core23.AgentRegistry(), "useFactory")
3817
+ provide: import_nestjs_agent_core24.AGENT_REGISTRY,
3818
+ useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core24.AgentRegistry(), "useFactory")
3589
3819
  },
3590
3820
  // A shared, mutable list AgentDiscoveryService fills with `@SystemPromptContributor()` methods.
3591
3821
  {
3592
- provide: import_nestjs_agent_core23.AGENT_PROMPT_CONTRIBUTORS,
3822
+ provide: import_nestjs_agent_core24.AGENT_PROMPT_CONTRIBUTORS,
3593
3823
  useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
3594
3824
  },
3595
3825
  // Likewise for `@Skill`-decorated providers — filled by SkillDiscoveryService at onModuleInit,
3596
3826
  // read lazily by the AGENT_SKILLS provider below (which DI builds before discovery has run).
3597
3827
  {
3598
- provide: import_nestjs_agent_core23.AGENT_SKILL_SOURCES,
3828
+ provide: import_nestjs_agent_core24.AGENT_SKILL_SOURCES,
3599
3829
  useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
3600
3830
  },
3601
3831
  {
3602
3832
  // One resolution, shared by the loop's deps and the listing endpoint: a second one would
3603
3833
  // drift, and a user would be offered a skill the agent cannot reach. `undefined` when the
3604
3834
  // host configured none — which is what keeps the turn's checkpoint sequence unchanged.
3605
- provide: import_nestjs_agent_core23.AGENT_SKILLS,
3835
+ provide: import_nestjs_agent_core24.AGENT_SKILLS,
3606
3836
  useFactory: /* @__PURE__ */ __name((options, declared) => resolveSkillsConfig(options.skills, declared), "useFactory"),
3607
3837
  inject: [
3608
- import_nestjs_agent_core23.AGENT_OPTIONS,
3609
- import_nestjs_agent_core23.AGENT_SKILL_SOURCES
3838
+ import_nestjs_agent_core24.AGENT_OPTIONS,
3839
+ import_nestjs_agent_core24.AGENT_SKILL_SOURCES
3610
3840
  ]
3611
3841
  },
3612
3842
  {
3613
3843
  // One resolution, shared by the loop's deps and the read-back endpoint: a person has to be
3614
3844
  // shown what the model was shown, and two resolutions would eventually disagree about that.
3615
- provide: import_nestjs_agent_core23.AGENT_MEMORY,
3845
+ provide: import_nestjs_agent_core24.AGENT_MEMORY,
3616
3846
  useFactory: /* @__PURE__ */ __name((options) => options.memory, "useFactory"),
3617
3847
  inject: [
3618
- import_nestjs_agent_core23.AGENT_OPTIONS
3848
+ import_nestjs_agent_core24.AGENT_OPTIONS
3619
3849
  ]
3620
3850
  },
3621
3851
  {
3622
- provide: import_nestjs_agent_core23.AGENT_SINK,
3852
+ provide: import_nestjs_agent_core24.AGENT_SINK,
3623
3853
  useFactory: /* @__PURE__ */ __name((options) => options.sink ?? new InProcessTokenStreamSink(), "useFactory"),
3624
3854
  inject: [
3625
- import_nestjs_agent_core23.AGENT_OPTIONS
3855
+ import_nestjs_agent_core24.AGENT_OPTIONS
3626
3856
  ]
3627
3857
  },
3628
3858
  {
3629
- provide: import_nestjs_agent_core23.AGENT_ROLES_POLICY,
3630
- useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? new import_nestjs_agent_core23.DefaultRolesPolicy(options.defaultRoles), "useFactory"),
3859
+ provide: import_nestjs_agent_core24.AGENT_ROLES_POLICY,
3860
+ useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? new import_nestjs_agent_core24.DefaultRolesPolicy(options.defaultRoles), "useFactory"),
3631
3861
  inject: [
3632
- import_nestjs_agent_core23.AGENT_OPTIONS
3862
+ import_nestjs_agent_core24.AGENT_OPTIONS
3633
3863
  ]
3634
3864
  },
3635
3865
  {
3636
- provide: import_nestjs_agent_core23.AGENT_ACTOR_RESOLVER,
3866
+ provide: import_nestjs_agent_core24.AGENT_ACTOR_RESOLVER,
3637
3867
  useFactory: /* @__PURE__ */ __name((options) => options.actorResolver, "useFactory"),
3638
3868
  inject: [
3639
- import_nestjs_agent_core23.AGENT_OPTIONS
3869
+ import_nestjs_agent_core24.AGENT_OPTIONS
3640
3870
  ]
3641
3871
  },
3642
3872
  {
3643
- provide: import_nestjs_agent_core23.AGENT_MODEL,
3873
+ provide: import_nestjs_agent_core24.AGENT_MODEL,
3644
3874
  useFactory: /* @__PURE__ */ __name((o) => o.model, "useFactory"),
3645
3875
  inject: [
3646
- import_nestjs_agent_core23.AGENT_OPTIONS
3876
+ import_nestjs_agent_core24.AGENT_OPTIONS
3647
3877
  ]
3648
3878
  },
3649
3879
  {
3650
3880
  // An explicit `quota` wins; otherwise `quotaLimitTokens` binds the built-in ledger-backed
3651
3881
  // store; otherwise quotas are off (undefined). The ledger store reads the same usage rows
3652
3882
  // the loop already writes, so enforcement needs no extra shared state across replicas.
3653
- provide: import_nestjs_agent_core23.AGENT_QUOTA_STORE,
3883
+ provide: import_nestjs_agent_core24.AGENT_QUOTA_STORE,
3654
3884
  useFactory: /* @__PURE__ */ __name((o, store) => o.quota ?? (o.quotaLimitTokens !== void 0 ? new LedgerQuotaStore(store, o.quotaLimitTokens) : void 0), "useFactory"),
3655
3885
  inject: [
3656
- import_nestjs_agent_core23.AGENT_OPTIONS,
3657
- import_nestjs_agent_core23.AGENT_STORE
3886
+ import_nestjs_agent_core24.AGENT_OPTIONS,
3887
+ import_nestjs_agent_core24.AGENT_STORE
3658
3888
  ]
3659
3889
  },
3660
3890
  AgentDepsFactory2,
3661
3891
  {
3662
- provide: import_nestjs_agent_core23.AGENT_DEPS_FACTORY,
3892
+ provide: import_nestjs_agent_core24.AGENT_DEPS_FACTORY,
3663
3893
  useExisting: AgentDepsFactory2
3664
3894
  },
3665
3895
  // Populates the registry + contributors (onModuleInit) BEFORE AiToolDiscoveryService synthesizes
@@ -3673,22 +3903,22 @@ function sharedProviders(durable, includeStore) {
3673
3903
  // through AgentService.signalToolCall, which reaches whichever AGENT_RUNNER is bound above.
3674
3904
  AgentApprovalPortAdapter,
3675
3905
  {
3676
- provide: import_nestjs_agent_core23.AGENT_APPROVAL_PORT,
3906
+ provide: import_nestjs_agent_core24.AGENT_APPROVAL_PORT,
3677
3907
  useExisting: AgentApprovalPortAdapter
3678
3908
  }
3679
3909
  ];
3680
3910
  if (includeStore) {
3681
3911
  providers.push({
3682
- provide: import_nestjs_agent_core23.AGENT_STORE,
3912
+ provide: import_nestjs_agent_core24.AGENT_STORE,
3683
3913
  useFactory: /* @__PURE__ */ __name((o) => o.store, "useFactory"),
3684
3914
  inject: [
3685
- import_nestjs_agent_core23.AGENT_OPTIONS
3915
+ import_nestjs_agent_core24.AGENT_OPTIONS
3686
3916
  ]
3687
3917
  });
3688
3918
  }
3689
3919
  if (durable) {
3690
3920
  providers.push({
3691
- provide: import_nestjs_agent_core23.AGENT_RUNNER,
3921
+ provide: import_nestjs_agent_core24.AGENT_RUNNER,
3692
3922
  useFactory: /* @__PURE__ */ __name((durableRunner) => {
3693
3923
  if (durableRunner === void 0) {
3694
3924
  throw new Error("AgentModule.forRoot({ durable: true }) requires importing AgentDurableModule from '@dudousxd/nestjs-agent/durable' (alongside a configured DurableModule). It was not found.");
@@ -3697,14 +3927,14 @@ function sharedProviders(durable, includeStore) {
3697
3927
  }, "useFactory"),
3698
3928
  inject: [
3699
3929
  {
3700
- token: import_nestjs_agent_core23.AGENT_DURABLE_RUNNER,
3930
+ token: import_nestjs_agent_core24.AGENT_DURABLE_RUNNER,
3701
3931
  optional: true
3702
3932
  }
3703
3933
  ]
3704
3934
  });
3705
3935
  } else {
3706
3936
  providers.push({
3707
- provide: import_nestjs_agent_core23.AGENT_RUNNER,
3937
+ provide: import_nestjs_agent_core24.AGENT_RUNNER,
3708
3938
  useExisting: InlineAgentRunner
3709
3939
  });
3710
3940
  }
@@ -3713,25 +3943,25 @@ function sharedProviders(durable, includeStore) {
3713
3943
  __name(sharedProviders, "sharedProviders");
3714
3944
  function exportsFor(includeStore) {
3715
3945
  return [
3716
- import_nestjs_agent_core23.AGENT_OPTIONS,
3717
- import_nestjs_agent_core23.AGENT_TOOL_REGISTRY,
3718
- import_nestjs_agent_core23.AGENT_REGISTRY,
3719
- import_nestjs_agent_core23.AGENT_SINK,
3720
- import_nestjs_agent_core23.AGENT_ROLES_POLICY,
3721
- import_nestjs_agent_core23.AGENT_ACTOR_RESOLVER,
3722
- import_nestjs_agent_core23.AGENT_MODEL,
3946
+ import_nestjs_agent_core24.AGENT_OPTIONS,
3947
+ import_nestjs_agent_core24.AGENT_TOOL_REGISTRY,
3948
+ import_nestjs_agent_core24.AGENT_REGISTRY,
3949
+ import_nestjs_agent_core24.AGENT_SINK,
3950
+ import_nestjs_agent_core24.AGENT_ROLES_POLICY,
3951
+ import_nestjs_agent_core24.AGENT_ACTOR_RESOLVER,
3952
+ import_nestjs_agent_core24.AGENT_MODEL,
3723
3953
  ...includeStore ? [
3724
- import_nestjs_agent_core23.AGENT_STORE
3954
+ import_nestjs_agent_core24.AGENT_STORE
3725
3955
  ] : [],
3726
- import_nestjs_agent_core23.AGENT_QUOTA_STORE,
3727
- import_nestjs_agent_core23.AGENT_PROMPT_CONTRIBUTORS,
3728
- import_nestjs_agent_core23.AGENT_SKILLS,
3729
- import_nestjs_agent_core23.AGENT_MEMORY,
3730
- import_nestjs_agent_core23.AGENT_DEPS_FACTORY,
3956
+ import_nestjs_agent_core24.AGENT_QUOTA_STORE,
3957
+ import_nestjs_agent_core24.AGENT_PROMPT_CONTRIBUTORS,
3958
+ import_nestjs_agent_core24.AGENT_SKILLS,
3959
+ import_nestjs_agent_core24.AGENT_MEMORY,
3960
+ import_nestjs_agent_core24.AGENT_DEPS_FACTORY,
3731
3961
  AgentDepsFactory2,
3732
3962
  AgentService,
3733
3963
  InlineAgentRunner,
3734
- import_nestjs_agent_core23.AGENT_APPROVAL_PORT
3964
+ import_nestjs_agent_core24.AGENT_APPROVAL_PORT
3735
3965
  ];
3736
3966
  }
3737
3967
  __name(exportsFor, "exportsFor");
@@ -3742,7 +3972,8 @@ var BASE_CONTROLLERS = [
3742
3972
  QuotaController,
3743
3973
  AgentsController,
3744
3974
  SkillsController,
3745
- MemoriesController
3975
+ MemoriesController,
3976
+ ToolsController
3746
3977
  ];
3747
3978
  var GUARDABLE_CONTROLLERS = [
3748
3979
  ...BASE_CONTROLLERS,
@@ -3800,7 +4031,7 @@ var AgentModule = class _AgentModule {
3800
4031
  controllers: controllersForSurface(options.surface, options.attachments?.upload === true),
3801
4032
  providers: [
3802
4033
  {
3803
- provide: import_nestjs_agent_core23.AGENT_OPTIONS,
4034
+ provide: import_nestjs_agent_core24.AGENT_OPTIONS,
3804
4035
  useValue: options
3805
4036
  },
3806
4037
  ...sharedProviders(options.durable ?? false, includeStore),
@@ -3824,7 +4055,7 @@ var AgentModule = class _AgentModule {
3824
4055
  controllers: controllersForSurface(options.surface, options.attachmentsUpload === true),
3825
4056
  providers: [
3826
4057
  {
3827
- provide: import_nestjs_agent_core23.AGENT_OPTIONS,
4058
+ provide: import_nestjs_agent_core24.AGENT_OPTIONS,
3828
4059
  // Stamp the STATIC wiring flags onto the factory result: `durable`/`surface` are
3829
4060
  // authoritative on the async config object (they decided the actual wiring above), and
3830
4061
  // the durable module reads `durable` back off AGENT_OPTIONS. `surface` isn't read back by
@@ -3845,9 +4076,9 @@ var AgentModule = class _AgentModule {
3845
4076
  };
3846
4077
  }
3847
4078
  };
3848
- AgentModule = _ts_decorate20([
3849
- (0, import_common20.Global)(),
3850
- (0, import_common20.Module)({})
4079
+ AgentModule = _ts_decorate21([
4080
+ (0, import_common21.Global)(),
4081
+ (0, import_common21.Module)({})
3851
4082
  ], AgentModule);
3852
4083
 
3853
4084
  // src/durable/agent-durable.ts