@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.
@@ -276,7 +276,21 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
276
276
  runId: ctx.runId,
277
277
  // A child forwards into the top-level sink but must not end/fail it (the top-level run owns it).
278
278
  openSink: /* @__PURE__ */ __name(async () => input.sinkRunId !== void 0 ? childSinkWriter(await deps.sink.open(sinkRunId)) : deps.sink.open(ctx.runId), "openSink"),
279
- awaitApproval: /* @__PURE__ */ __name((call) => ctx.waitForSignal(`tool:${ctx.runId}:${call.id}`), "awaitApproval"),
279
+ // A policy's time to live becomes the signal wait's own timeout: the runtime journals the
280
+ // deadline on the first call (a position of its own, reached only for a call the journal says
281
+ // has a ttl) and wakes the run when it passes. The lapse comes back as a Decision rather than a
282
+ // throw, so the loop settles the call `expired` on its ordinary rejection checkpoint.
283
+ awaitApproval: /* @__PURE__ */ __name((call, _toolCtx, opts) => opts?.timeoutMs === void 0 ? ctx.waitForSignal(`tool:${ctx.runId}:${call.id}`) : ctx.waitForSignal(`tool:${ctx.runId}:${call.id}`, {
284
+ timeoutMs: opts.timeoutMs
285
+ }).catch((error) => {
286
+ if (isSignalTimeout(error)) {
287
+ return {
288
+ approved: false,
289
+ expired: true
290
+ };
291
+ }
292
+ throw error;
293
+ }), "awaitApproval"),
280
294
  // The same wait, on the same signal key, carrying a typed answer instead of a yes/no — so a
281
295
  // question set and an approval reach a parked run through one path, and the HTTP surface that
282
296
  // settles either one is the same `POST /agent/tool-call/*` family.
@@ -450,6 +464,10 @@ AgentRunWorkflow = _ts_decorate2([
450
464
  typeof RunGateway === "undefined" ? Object : RunGateway
451
465
  ])
452
466
  ], AgentRunWorkflow);
467
+ function isSignalTimeout(error) {
468
+ return error instanceof Error && error.name === "SignalTimeoutError";
469
+ }
470
+ __name(isSignalTimeout, "isSignalTimeout");
453
471
 
454
472
  // src/durable/durable-agent-runner.ts
455
473
  import { randomUUID } from "crypto";
@@ -760,7 +778,7 @@ AgentDurableModule = _ts_decorate4([
760
778
  ], AgentDurableModule);
761
779
 
762
780
  // src/agent.module.ts
763
- import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER8, AGENT_APPROVAL_PORT, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY6, AGENT_DURABLE_RUNNER as AGENT_DURABLE_RUNNER2, AGENT_MEMORY as AGENT_MEMORY3, AGENT_MODEL as AGENT_MODEL2, AGENT_OPTIONS as AGENT_OPTIONS4, AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS3, AGENT_QUOTA_STORE as AGENT_QUOTA_STORE3, AGENT_REGISTRY as AGENT_REGISTRY5, AGENT_ROLES_POLICY as AGENT_ROLES_POLICY2, AGENT_RUNNER as AGENT_RUNNER2, AGENT_SINK as AGENT_SINK3, AGENT_SKILLS as AGENT_SKILLS3, AGENT_SKILL_SOURCES as AGENT_SKILL_SOURCES2, AGENT_STORE as AGENT_STORE6, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY3, AgentRegistry as AgentRegistry5, DefaultRolesPolicy, ToolRegistry as ToolRegistry3 } from "@dudousxd/nestjs-agent-core";
781
+ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER9, AGENT_APPROVAL_PORT, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY7, AGENT_DURABLE_RUNNER as AGENT_DURABLE_RUNNER2, AGENT_MEMORY as AGENT_MEMORY3, AGENT_MODEL as AGENT_MODEL2, AGENT_OPTIONS as AGENT_OPTIONS4, AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS3, AGENT_QUOTA_STORE as AGENT_QUOTA_STORE3, AGENT_REGISTRY as AGENT_REGISTRY6, AGENT_ROLES_POLICY as AGENT_ROLES_POLICY2, AGENT_RUNNER as AGENT_RUNNER2, AGENT_SINK as AGENT_SINK3, AGENT_SKILLS as AGENT_SKILLS3, AGENT_SKILL_SOURCES as AGENT_SKILL_SOURCES2, AGENT_STORE as AGENT_STORE6, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY3, AgentRegistry as AgentRegistry6, DefaultRolesPolicy, ToolRegistry as ToolRegistry3 } from "@dudousxd/nestjs-agent-core";
764
782
  import { Global as Global2, Module as Module2 } from "@nestjs/common";
765
783
  import { DiscoveryModule, RouterModule } from "@nestjs/core";
766
784
 
@@ -880,6 +898,9 @@ var AgentDepsFactory2 = class {
880
898
  store: this.store,
881
899
  sink: this.sink,
882
900
  rolesPolicy: this.rolesPolicy,
901
+ ...this.options.approvalPolicy !== void 0 ? {
902
+ approvalPolicy: this.options.approvalPolicy
903
+ } : {},
883
904
  registry: this.registry,
884
905
  promptContributors: this.promptContributors,
885
906
  systemPrompt: definition?.systemPrompt ?? "You are a helpful assistant.",
@@ -1027,8 +1048,8 @@ AgentDepsFactory2 = _ts_decorate5([
1027
1048
  ], AgentDepsFactory2);
1028
1049
 
1029
1050
  // src/agent.service.ts
1030
- import { AGENT_ATTACHMENT_STAGING, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY3, AGENT_QUOTA_STORE as AGENT_QUOTA_STORE2, AGENT_RUNNER, AGENT_STORE as AGENT_STORE4 } from "@dudousxd/nestjs-agent-core";
1031
- import { BadRequestException, ForbiddenException, Inject as Inject5, Injectable as Injectable5, NotFoundException, NotImplementedException, Optional as Optional3 } from "@nestjs/common";
1051
+ import { AGENT_ATTACHMENT_STAGING, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY3, AGENT_QUOTA_STORE as AGENT_QUOTA_STORE2, AGENT_RUNNER, AGENT_STORE as AGENT_STORE4, REQUESTER_APPROVER, mayDecideApproval } from "@dudousxd/nestjs-agent-core";
1052
+ import { BadRequestException, ForbiddenException, GoneException, Inject as Inject5, Injectable as Injectable5, NotFoundException, NotImplementedException, Optional as Optional3 } from "@nestjs/common";
1032
1053
  function _ts_decorate6(decorators, target, key, desc) {
1033
1054
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1034
1055
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -1163,18 +1184,35 @@ var AgentService = class {
1163
1184
  await this.assertOwnsActiveStream(actor, runId);
1164
1185
  return this.subscribe(runId);
1165
1186
  }
1166
- async approve(actor, toolCallId2) {
1167
- await this.assertOwnsToolCall(actor, toolCallId2);
1187
+ /**
1188
+ * Approve a parked action call as `actor`. Who may is the call's recorded approver's business
1189
+ * (see {@link assertMayDecide}); `remember` approves later calls of the same tool in the same
1190
+ * thread, and `via` names the surface the decision came through (`'web'`, `'slack'`, …) — both
1191
+ * persisted with the call.
1192
+ */
1193
+ async approve(actor, toolCallId2, opts = {}) {
1194
+ await this.assertMayDecide(actor, toolCallId2);
1168
1195
  return this.signalToolCall(toolCallId2, {
1169
- approved: true
1196
+ approved: true,
1197
+ executedByRef: actor.id,
1198
+ ...opts.remember === true ? {
1199
+ remember: true
1200
+ } : {},
1201
+ ...opts.via !== void 0 ? {
1202
+ decidedVia: opts.via
1203
+ } : {}
1170
1204
  });
1171
1205
  }
1172
- async reject(actor, toolCallId2, reason) {
1173
- await this.assertOwnsToolCall(actor, toolCallId2);
1206
+ async reject(actor, toolCallId2, reason, opts = {}) {
1207
+ await this.assertMayDecide(actor, toolCallId2);
1174
1208
  return this.signalToolCall(toolCallId2, {
1175
1209
  approved: false,
1210
+ executedByRef: actor.id,
1176
1211
  ...reason !== void 0 ? {
1177
1212
  reason
1213
+ } : {},
1214
+ ...opts.via !== void 0 ? {
1215
+ decidedVia: opts.via
1178
1216
  } : {}
1179
1217
  });
1180
1218
  }
@@ -1215,6 +1253,7 @@ var AgentService = class {
1215
1253
  * not the thread's own actor).
1216
1254
  */
1217
1255
  async signalToolCall(toolCallId2, reply) {
1256
+ await this.assertNotExpired(toolCallId2);
1218
1257
  const runId = await this.resolveRunForToolCall(toolCallId2);
1219
1258
  return this.runner.signal(runId, toolCallId2, reply);
1220
1259
  }
@@ -1453,6 +1492,47 @@ var AgentService = class {
1453
1492
  }
1454
1493
  }
1455
1494
  /**
1495
+ * Authorization seam for approve/reject. The call's recorded approver decides who may settle it:
1496
+ * the requester (the default, and every call recorded before approvers existed) is the thread's
1497
+ * own actor — the ownership check this always was; any other approver goes through the policy's
1498
+ * `canDecide`, which by default asks whether the actor holds that role.
1499
+ */
1500
+ async assertMayDecide(actor, toolCallId2) {
1501
+ const approval = await this.store.toolCallApproval?.(toolCallId2);
1502
+ const approver = approval?.approver ?? REQUESTER_APPROVER;
1503
+ if (approver === REQUESTER_APPROVER) {
1504
+ return this.assertOwnsToolCall(actor, toolCallId2);
1505
+ }
1506
+ const requesterRef = await this.store.ownerOfToolCall(toolCallId2);
1507
+ if (requesterRef === null) {
1508
+ throw new NotFoundException(`tool call ${toolCallId2} not found`);
1509
+ }
1510
+ const allowed = await mayDecideApproval(this.deps.forAgent().approvalPolicy, actor, {
1511
+ toolCallId: toolCallId2,
1512
+ approver,
1513
+ requesterRef
1514
+ });
1515
+ if (!allowed) {
1516
+ throw new ForbiddenException(`this approval is for ${approver}`);
1517
+ }
1518
+ }
1519
+ /**
1520
+ * Refuse a decision on a request that has already lapsed — recorded `expired`, or past its
1521
+ * `expiresAt` with the run's own timer about to fire. Signalling it anyway would race the timeout:
1522
+ * a durable runtime buffers a signal nobody is waiting on, and a late approval must not be what a
1523
+ * later replay of the run reads back.
1524
+ */
1525
+ async assertNotExpired(toolCallId2) {
1526
+ const approval = await this.store.toolCallApproval?.(toolCallId2);
1527
+ if (approval === null || approval === void 0) {
1528
+ return;
1529
+ }
1530
+ const lapsed = approval.status === "expired" || approval.status === "pending_approval" && approval.expiresAt !== null && Date.parse(approval.expiresAt) <= Date.now();
1531
+ if (lapsed) {
1532
+ throw new GoneException(`the approval request for tool call ${toolCallId2} has expired`);
1533
+ }
1534
+ }
1535
+ /**
1456
1536
  * Resolve the run awaiting `toolCallId`. Derived server-side from the tool call alone — the client
1457
1537
  * never knows or supplies a runId, and that run is the sub-agent's own child run when the pending
1458
1538
  * call belongs to a delegated agent. The store answers from the CALL'S OWN `runId` where it has
@@ -1530,6 +1610,12 @@ var AgentApprovalPortAdapter = class {
1530
1610
  approved: true,
1531
1611
  ...opts?.executedByRef !== void 0 ? {
1532
1612
  executedByRef: opts.executedByRef
1613
+ } : {},
1614
+ ...opts?.remember === true ? {
1615
+ remember: true
1616
+ } : {},
1617
+ ...opts?.decidedVia !== void 0 ? {
1618
+ decidedVia: opts.decidedVia
1533
1619
  } : {}
1534
1620
  });
1535
1621
  }
@@ -1541,6 +1627,9 @@ var AgentApprovalPortAdapter = class {
1541
1627
  } : {},
1542
1628
  ...opts?.reason !== void 0 ? {
1543
1629
  reason: opts.reason
1630
+ } : {},
1631
+ ...opts?.decidedVia !== void 0 ? {
1632
+ decidedVia: opts.decidedVia
1544
1633
  } : {}
1545
1634
  });
1546
1635
  }
@@ -2460,6 +2549,8 @@ var MAX_ANSWERED_QUESTIONS = 100;
2460
2549
  var MAX_VALUES_PER_QUESTION = 100;
2461
2550
  var MAX_ANSWER_VALUE_LENGTH = 4096;
2462
2551
  var MAX_REJECT_REASON_LENGTH = 4096;
2552
+ var MAX_VIA_LENGTH = 64;
2553
+ var DEFAULT_VIA = "web";
2463
2554
  function toolCallId(claimed) {
2464
2555
  if (typeof claimed !== "string" || claimed.length === 0) {
2465
2556
  throw new BadRequestException4("toolCallId must be a non-empty string");
@@ -2480,6 +2571,26 @@ function rejectReason(claimed) {
2480
2571
  return claimed;
2481
2572
  }
2482
2573
  __name(rejectReason, "rejectReason");
2574
+ function remember(claimed) {
2575
+ if (claimed === void 0) {
2576
+ return false;
2577
+ }
2578
+ if (typeof claimed !== "boolean") {
2579
+ throw new BadRequestException4("remember must be a boolean");
2580
+ }
2581
+ return claimed;
2582
+ }
2583
+ __name(remember, "remember");
2584
+ function via(claimed) {
2585
+ if (claimed === void 0) {
2586
+ return DEFAULT_VIA;
2587
+ }
2588
+ if (typeof claimed !== "string" || claimed.length === 0 || claimed.length > MAX_VIA_LENGTH) {
2589
+ throw new BadRequestException4(`via must be a string of 1-${MAX_VIA_LENGTH} characters`);
2590
+ }
2591
+ return claimed;
2592
+ }
2593
+ __name(via, "via");
2483
2594
  function answers(claimed) {
2484
2595
  if (claimed === void 0) {
2485
2596
  return void 0;
@@ -2524,14 +2635,19 @@ var ToolCallController = class {
2524
2635
  }
2525
2636
  async approve(req, body) {
2526
2637
  const actor = await this.actorResolver.resolve(req);
2527
- await this.agent.approve(actor, toolCallId(body.toolCallId));
2638
+ await this.agent.approve(actor, toolCallId(body.toolCallId), {
2639
+ remember: remember(body.remember),
2640
+ via: via(body.via)
2641
+ });
2528
2642
  return {
2529
2643
  ok: true
2530
2644
  };
2531
2645
  }
2532
2646
  async reject(req, body) {
2533
2647
  const actor = await this.actorResolver.resolve(req);
2534
- await this.agent.reject(actor, toolCallId(body.toolCallId), rejectReason(body.reason));
2648
+ await this.agent.reject(actor, toolCallId(body.toolCallId), rejectReason(body.reason), {
2649
+ via: via(body.via)
2650
+ });
2535
2651
  return {
2536
2652
  ok: true
2537
2653
  };
@@ -2597,7 +2713,7 @@ _ts_decorate15([
2597
2713
  _ts_metadata14("design:type", Function),
2598
2714
  _ts_metadata14("design:paramtypes", [
2599
2715
  typeof Request === "undefined" ? Object : Request,
2600
- typeof ApproveBody === "undefined" ? Object : ApproveBody
2716
+ Object
2601
2717
  ]),
2602
2718
  _ts_metadata14("design:returntype", Promise)
2603
2719
  ], ToolCallController.prototype, "skip", null);
@@ -2611,9 +2727,90 @@ ToolCallController = _ts_decorate15([
2611
2727
  ])
2612
2728
  ], ToolCallController);
2613
2729
 
2730
+ // src/controller/tools.controller.ts
2731
+ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER8, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY5, AGENT_REGISTRY as AGENT_REGISTRY3, AgentRegistry as AgentRegistry4 } from "@dudousxd/nestjs-agent-core";
2732
+ import { Controller as Controller9, Get as Get8, Inject as Inject14, NotFoundException as NotFoundException3, Query as Query3, Req as Req8 } from "@nestjs/common";
2733
+ function _ts_decorate16(decorators, target, key, desc) {
2734
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2735
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2736
+ r = Reflect.decorate(decorators, target, key, desc);
2737
+ } else {
2738
+ for (var i = decorators.length - 1; i >= 0; i--) {
2739
+ if (d = decorators[i]) {
2740
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2741
+ }
2742
+ }
2743
+ }
2744
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2745
+ }
2746
+ __name(_ts_decorate16, "_ts_decorate");
2747
+ function _ts_metadata15(metadataKey, metadataValue) {
2748
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2749
+ return Reflect.metadata(metadataKey, metadataValue);
2750
+ }
2751
+ }
2752
+ __name(_ts_metadata15, "_ts_metadata");
2753
+ function _ts_param14(paramIndex, decorator) {
2754
+ return function(target, key) {
2755
+ decorator(target, key, paramIndex);
2756
+ };
2757
+ }
2758
+ __name(_ts_param14, "_ts_param");
2759
+ var ToolsController = class {
2760
+ static {
2761
+ __name(this, "ToolsController");
2762
+ }
2763
+ actorResolver;
2764
+ depsFactory;
2765
+ agents;
2766
+ constructor(actorResolver, depsFactory, agents) {
2767
+ this.actorResolver = actorResolver;
2768
+ this.depsFactory = depsFactory;
2769
+ this.agents = agents;
2770
+ }
2771
+ async list(req, agent) {
2772
+ if (agent !== void 0 && this.agents.get(agent) === void 0) {
2773
+ throw new NotFoundException3(`No agent named "${agent}"`);
2774
+ }
2775
+ const actor = await this.actorResolver.resolve(req);
2776
+ const deps = this.depsFactory.forAgent(agent);
2777
+ const specs = await deps.registry.visibleSpecs(actor, deps.rolesPolicy, deps.toolAllowList);
2778
+ return specs.map((spec) => ({
2779
+ name: spec.name,
2780
+ kind: spec.kind,
2781
+ ...spec.presentation !== void 0 ? {
2782
+ presentation: spec.presentation
2783
+ } : {}
2784
+ }));
2785
+ }
2786
+ };
2787
+ _ts_decorate16([
2788
+ Get8(),
2789
+ _ts_param14(0, Req8()),
2790
+ _ts_param14(1, Query3("agent")),
2791
+ _ts_metadata15("design:type", Function),
2792
+ _ts_metadata15("design:paramtypes", [
2793
+ typeof Request === "undefined" ? Object : Request,
2794
+ String
2795
+ ]),
2796
+ _ts_metadata15("design:returntype", Promise)
2797
+ ], ToolsController.prototype, "list", null);
2798
+ ToolsController = _ts_decorate16([
2799
+ Controller9("tools"),
2800
+ _ts_param14(0, Inject14(AGENT_ACTOR_RESOLVER8)),
2801
+ _ts_param14(1, Inject14(AGENT_DEPS_FACTORY5)),
2802
+ _ts_param14(2, Inject14(AGENT_REGISTRY3)),
2803
+ _ts_metadata15("design:type", Function),
2804
+ _ts_metadata15("design:paramtypes", [
2805
+ typeof ActorResolver === "undefined" ? Object : ActorResolver,
2806
+ typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
2807
+ typeof AgentRegistry4 === "undefined" ? Object : AgentRegistry4
2808
+ ])
2809
+ ], ToolsController);
2810
+
2614
2811
  // src/discovery/agent-discovery.service.ts
2615
- import { AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS2, AGENT_REGISTRY as AGENT_REGISTRY3, AgentRegistry as AgentRegistry4 } from "@dudousxd/nestjs-agent-core";
2616
- import { Inject as Inject14, Injectable as Injectable7, Logger as Logger2 } from "@nestjs/common";
2812
+ import { AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS2, AGENT_REGISTRY as AGENT_REGISTRY4, AgentRegistry as AgentRegistry5 } from "@dudousxd/nestjs-agent-core";
2813
+ import { Inject as Inject15, Injectable as Injectable7, Logger as Logger2 } from "@nestjs/common";
2617
2814
  import { DiscoveryService, MetadataScanner } from "@nestjs/core";
2618
2815
 
2619
2816
  // src/decorator/agent.decorator.ts
@@ -2630,7 +2827,7 @@ var SYSTEM_PROMPT_METADATA = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:
2630
2827
  var SYSTEM_PROMPT_CONTRIBUTOR_METADATA = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:system-prompt-contributor");
2631
2828
 
2632
2829
  // src/discovery/agent-discovery.service.ts
2633
- function _ts_decorate16(decorators, target, key, desc) {
2830
+ function _ts_decorate17(decorators, target, key, desc) {
2634
2831
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2635
2832
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2636
2833
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2643,19 +2840,19 @@ function _ts_decorate16(decorators, target, key, desc) {
2643
2840
  }
2644
2841
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2645
2842
  }
2646
- __name(_ts_decorate16, "_ts_decorate");
2647
- function _ts_metadata15(metadataKey, metadataValue) {
2843
+ __name(_ts_decorate17, "_ts_decorate");
2844
+ function _ts_metadata16(metadataKey, metadataValue) {
2648
2845
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2649
2846
  return Reflect.metadata(metadataKey, metadataValue);
2650
2847
  }
2651
2848
  }
2652
- __name(_ts_metadata15, "_ts_metadata");
2653
- function _ts_param14(paramIndex, decorator) {
2849
+ __name(_ts_metadata16, "_ts_metadata");
2850
+ function _ts_param15(paramIndex, decorator) {
2654
2851
  return function(target, key) {
2655
2852
  decorator(target, key, paramIndex);
2656
2853
  };
2657
2854
  }
2658
- __name(_ts_param14, "_ts_param");
2855
+ __name(_ts_param15, "_ts_param");
2659
2856
  var AgentDiscoveryService = class _AgentDiscoveryService {
2660
2857
  static {
2661
2858
  __name(this, "AgentDiscoveryService");
@@ -2782,22 +2979,22 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
2782
2979
  return (ctx) => candidate.call(instance, ctx);
2783
2980
  }
2784
2981
  };
2785
- AgentDiscoveryService = _ts_decorate16([
2982
+ AgentDiscoveryService = _ts_decorate17([
2786
2983
  Injectable7(),
2787
- _ts_param14(2, Inject14(AGENT_REGISTRY3)),
2788
- _ts_param14(3, Inject14(AGENT_PROMPT_CONTRIBUTORS2)),
2789
- _ts_metadata15("design:type", Function),
2790
- _ts_metadata15("design:paramtypes", [
2984
+ _ts_param15(2, Inject15(AGENT_REGISTRY4)),
2985
+ _ts_param15(3, Inject15(AGENT_PROMPT_CONTRIBUTORS2)),
2986
+ _ts_metadata16("design:type", Function),
2987
+ _ts_metadata16("design:paramtypes", [
2791
2988
  typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
2792
2989
  typeof MetadataScanner === "undefined" ? Object : MetadataScanner,
2793
- typeof AgentRegistry4 === "undefined" ? Object : AgentRegistry4,
2990
+ typeof AgentRegistry5 === "undefined" ? Object : AgentRegistry5,
2794
2991
  Array
2795
2992
  ])
2796
2993
  ], AgentDiscoveryService);
2797
2994
 
2798
2995
  // src/discovery/ai-tool-discovery.service.ts
2799
- import { AGENT_OPTIONS as AGENT_OPTIONS3, AGENT_REGISTRY as AGENT_REGISTRY4, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY2, normalizeDelegation as normalizeDelegation2 } from "@dudousxd/nestjs-agent-core";
2800
- import { Inject as Inject15, Injectable as Injectable8, Logger as Logger3 } from "@nestjs/common";
2996
+ import { AGENT_OPTIONS as AGENT_OPTIONS3, AGENT_REGISTRY as AGENT_REGISTRY5, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY2, normalizeDelegation as normalizeDelegation2 } from "@dudousxd/nestjs-agent-core";
2997
+ import { Inject as Inject16, Injectable as Injectable8, Logger as Logger3 } from "@nestjs/common";
2801
2998
  import { DiscoveryService as DiscoveryService2 } from "@nestjs/core";
2802
2999
  import { z } from "zod";
2803
3000
 
@@ -2817,7 +3014,7 @@ function isBrandedFunctionalTool(value) {
2817
3014
  __name(isBrandedFunctionalTool, "isBrandedFunctionalTool");
2818
3015
 
2819
3016
  // src/discovery/ai-tool-discovery.service.ts
2820
- function _ts_decorate17(decorators, target, key, desc) {
3017
+ function _ts_decorate18(decorators, target, key, desc) {
2821
3018
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2822
3019
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2823
3020
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2830,19 +3027,19 @@ function _ts_decorate17(decorators, target, key, desc) {
2830
3027
  }
2831
3028
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2832
3029
  }
2833
- __name(_ts_decorate17, "_ts_decorate");
2834
- function _ts_metadata16(metadataKey, metadataValue) {
3030
+ __name(_ts_decorate18, "_ts_decorate");
3031
+ function _ts_metadata17(metadataKey, metadataValue) {
2835
3032
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2836
3033
  return Reflect.metadata(metadataKey, metadataValue);
2837
3034
  }
2838
3035
  }
2839
- __name(_ts_metadata16, "_ts_metadata");
2840
- function _ts_param15(paramIndex, decorator) {
3036
+ __name(_ts_metadata17, "_ts_metadata");
3037
+ function _ts_param16(paramIndex, decorator) {
2841
3038
  return function(target, key) {
2842
3039
  decorator(target, key, paramIndex);
2843
3040
  };
2844
3041
  }
2845
- __name(_ts_param15, "_ts_param");
3042
+ __name(_ts_param16, "_ts_param");
2846
3043
  var AiToolDiscoveryService = class _AiToolDiscoveryService {
2847
3044
  static {
2848
3045
  __name(this, "AiToolDiscoveryService");
@@ -2896,6 +3093,9 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
2896
3093
  } : {},
2897
3094
  ...meta.enabled !== void 0 ? {
2898
3095
  enabled: meta.enabled
3096
+ } : {},
3097
+ ...meta.presentation !== void 0 ? {
3098
+ presentation: meta.presentation
2899
3099
  } : {}
2900
3100
  }, {
2901
3101
  execute: /* @__PURE__ */ __name((input, ctx) => instance.execute(input, ctx), "execute"),
@@ -2969,13 +3169,13 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
2969
3169
  return true;
2970
3170
  }
2971
3171
  };
2972
- AiToolDiscoveryService = _ts_decorate17([
3172
+ AiToolDiscoveryService = _ts_decorate18([
2973
3173
  Injectable8(),
2974
- _ts_param15(1, Inject15(AGENT_TOOL_REGISTRY2)),
2975
- _ts_param15(2, Inject15(AGENT_REGISTRY4)),
2976
- _ts_param15(3, Inject15(AGENT_OPTIONS3)),
2977
- _ts_metadata16("design:type", Function),
2978
- _ts_metadata16("design:paramtypes", [
3174
+ _ts_param16(1, Inject16(AGENT_TOOL_REGISTRY2)),
3175
+ _ts_param16(2, Inject16(AGENT_REGISTRY5)),
3176
+ _ts_param16(3, Inject16(AGENT_OPTIONS3)),
3177
+ _ts_metadata17("design:type", Function),
3178
+ _ts_metadata17("design:paramtypes", [
2979
3179
  typeof DiscoveryService2 === "undefined" ? Object : DiscoveryService2,
2980
3180
  typeof ToolRegistry === "undefined" ? Object : ToolRegistry,
2981
3181
  typeof AgentRegistry === "undefined" ? Object : AgentRegistry,
@@ -2985,7 +3185,7 @@ AiToolDiscoveryService = _ts_decorate17([
2985
3185
 
2986
3186
  // src/discovery/skill-discovery.service.ts
2987
3187
  import { AGENT_SKILL_SOURCES } from "@dudousxd/nestjs-agent-core";
2988
- import { Inject as Inject16, Injectable as Injectable9, Logger as Logger4 } from "@nestjs/common";
3188
+ import { Inject as Inject17, Injectable as Injectable9, Logger as Logger4 } from "@nestjs/common";
2989
3189
  import { DiscoveryService as DiscoveryService3 } from "@nestjs/core";
2990
3190
 
2991
3191
  // src/decorator/skill.decorator.ts
@@ -3002,7 +3202,7 @@ function skillScope(options) {
3002
3202
  __name(skillScope, "skillScope");
3003
3203
 
3004
3204
  // src/discovery/skill-discovery.service.ts
3005
- function _ts_decorate18(decorators, target, key, desc) {
3205
+ function _ts_decorate19(decorators, target, key, desc) {
3006
3206
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3007
3207
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3008
3208
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3015,19 +3215,19 @@ function _ts_decorate18(decorators, target, key, desc) {
3015
3215
  }
3016
3216
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3017
3217
  }
3018
- __name(_ts_decorate18, "_ts_decorate");
3019
- function _ts_metadata17(metadataKey, metadataValue) {
3218
+ __name(_ts_decorate19, "_ts_decorate");
3219
+ function _ts_metadata18(metadataKey, metadataValue) {
3020
3220
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3021
3221
  return Reflect.metadata(metadataKey, metadataValue);
3022
3222
  }
3023
3223
  }
3024
- __name(_ts_metadata17, "_ts_metadata");
3025
- function _ts_param16(paramIndex, decorator) {
3224
+ __name(_ts_metadata18, "_ts_metadata");
3225
+ function _ts_param17(paramIndex, decorator) {
3026
3226
  return function(target, key) {
3027
3227
  decorator(target, key, paramIndex);
3028
3228
  };
3029
3229
  }
3030
- __name(_ts_param16, "_ts_param");
3230
+ __name(_ts_param17, "_ts_param");
3031
3231
  var SkillDiscoveryService = class _SkillDiscoveryService {
3032
3232
  static {
3033
3233
  __name(this, "SkillDiscoveryService");
@@ -3071,11 +3271,11 @@ var SkillDiscoveryService = class _SkillDiscoveryService {
3071
3271
  return flat === void 0 ? void 0 : () => flat;
3072
3272
  }
3073
3273
  };
3074
- SkillDiscoveryService = _ts_decorate18([
3274
+ SkillDiscoveryService = _ts_decorate19([
3075
3275
  Injectable9(),
3076
- _ts_param16(1, Inject16(AGENT_SKILL_SOURCES)),
3077
- _ts_metadata17("design:type", Function),
3078
- _ts_metadata17("design:paramtypes", [
3276
+ _ts_param17(1, Inject17(AGENT_SKILL_SOURCES)),
3277
+ _ts_metadata18("design:type", Function),
3278
+ _ts_metadata18("design:paramtypes", [
3079
3279
  typeof DiscoveryService3 === "undefined" ? Object : DiscoveryService3,
3080
3280
  Array
3081
3281
  ])
@@ -3105,9 +3305,9 @@ var LedgerQuotaStore = class {
3105
3305
  };
3106
3306
 
3107
3307
  // src/runner/inline-agent-runner.ts
3108
- import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY5, AGENT_STORE as AGENT_STORE5, RunCancelledError as RunCancelledError2, agentFailureCode as agentFailureCode2, encodeStreamEvent as encodeStreamEvent2, publishAgentRunFailed as publishAgentRunFailed2, runAgentLoop as runAgentLoop2, settleAll as settleAll2, settleUnsettledDelegation as settleUnsettledDelegation2 } from "@dudousxd/nestjs-agent-core";
3109
- import { Inject as Inject17, Injectable as Injectable10, Logger as Logger5 } from "@nestjs/common";
3110
- function _ts_decorate19(decorators, target, key, desc) {
3308
+ import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY6, AGENT_STORE as AGENT_STORE5, RunCancelledError as RunCancelledError2, agentFailureCode as agentFailureCode2, encodeStreamEvent as encodeStreamEvent2, publishAgentRunFailed as publishAgentRunFailed2, runAgentLoop as runAgentLoop2, settleAll as settleAll2, settleUnsettledDelegation as settleUnsettledDelegation2 } from "@dudousxd/nestjs-agent-core";
3309
+ import { Inject as Inject18, Injectable as Injectable10, Logger as Logger5 } from "@nestjs/common";
3310
+ function _ts_decorate20(decorators, target, key, desc) {
3111
3311
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3112
3312
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3113
3313
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3120,19 +3320,19 @@ function _ts_decorate19(decorators, target, key, desc) {
3120
3320
  }
3121
3321
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3122
3322
  }
3123
- __name(_ts_decorate19, "_ts_decorate");
3124
- function _ts_metadata18(metadataKey, metadataValue) {
3323
+ __name(_ts_decorate20, "_ts_decorate");
3324
+ function _ts_metadata19(metadataKey, metadataValue) {
3125
3325
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3126
3326
  return Reflect.metadata(metadataKey, metadataValue);
3127
3327
  }
3128
3328
  }
3129
- __name(_ts_metadata18, "_ts_metadata");
3130
- function _ts_param17(paramIndex, decorator) {
3329
+ __name(_ts_metadata19, "_ts_metadata");
3330
+ function _ts_param18(paramIndex, decorator) {
3131
3331
  return function(target, key) {
3132
3332
  decorator(target, key, paramIndex);
3133
3333
  };
3134
3334
  }
3135
- __name(_ts_param17, "_ts_param");
3335
+ __name(_ts_param18, "_ts_param");
3136
3336
  var InlineAgentRunner = class _InlineAgentRunner {
3137
3337
  static {
3138
3338
  __name(this, "InlineAgentRunner");
@@ -3258,6 +3458,36 @@ var InlineAgentRunner = class _InlineAgentRunner {
3258
3458
  * shape it is delivering — the loop asked for one and only ever gets what the caller sent. A
3259
3459
  * cancel settles the wait too, by rejecting it.
3260
3460
  */
3461
+ /**
3462
+ * {@link park} for an approval, bounded by the policy's time to live when it has one: the timer
3463
+ * settles the wait as `expired` — the same Decision the durable runner builds from its signal
3464
+ * timeout — and a decision that arrives first disarms it.
3465
+ */
3466
+ parkApproval(runId, toolCallId2, timeoutMs) {
3467
+ const waiting = this.park(runId, toolCallId2);
3468
+ if (timeoutMs === void 0) {
3469
+ return waiting;
3470
+ }
3471
+ const key = `${runId}:${toolCallId2}`;
3472
+ let timer;
3473
+ const lapse = new Promise((resolve) => {
3474
+ timer = setTimeout(() => {
3475
+ const entry = this.pending.get(key);
3476
+ if (entry !== void 0) {
3477
+ this.pending.delete(key);
3478
+ resolve({
3479
+ approved: false,
3480
+ expired: true
3481
+ });
3482
+ }
3483
+ }, timeoutMs);
3484
+ timer.unref?.();
3485
+ });
3486
+ return Promise.race([
3487
+ waiting,
3488
+ lapse
3489
+ ]).finally(() => clearTimeout(timer));
3490
+ }
3261
3491
  park(runId, toolCallId2) {
3262
3492
  return new Promise((resolve, reject) => {
3263
3493
  this.pending.set(`${runId}:${toolCallId2}`, {
@@ -3271,7 +3501,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3271
3501
  return {
3272
3502
  runId,
3273
3503
  openSink: /* @__PURE__ */ __name(() => deps.sink.open(runId), "openSink"),
3274
- awaitApproval: /* @__PURE__ */ __name((call) => this.park(runId, call.id), "awaitApproval"),
3504
+ awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
3275
3505
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
3276
3506
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
3277
3507
  parallel: settleAll2,
@@ -3322,7 +3552,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3322
3552
  const hooks = {
3323
3553
  runId,
3324
3554
  openSink: /* @__PURE__ */ __name(() => deps.sink.open(runId), "openSink"),
3325
- awaitApproval: /* @__PURE__ */ __name((call) => this.park(runId, call.id), "awaitApproval"),
3555
+ awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
3326
3556
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
3327
3557
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
3328
3558
  parallel: settleAll2,
@@ -3426,7 +3656,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3426
3656
  runId,
3427
3657
  // Forward into the top-level stream; the top-level run owns end/fail on that shared sink.
3428
3658
  openSink: /* @__PURE__ */ __name(async () => childSinkWriter(await deps.sink.open(sinkRunId)), "openSink"),
3429
- awaitApproval: /* @__PURE__ */ __name((call) => this.park(runId, call.id), "awaitApproval"),
3659
+ awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
3430
3660
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
3431
3661
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
3432
3662
  parallel: settleAll2,
@@ -3483,12 +3713,12 @@ var InlineAgentRunner = class _InlineAgentRunner {
3483
3713
  }
3484
3714
  }
3485
3715
  };
3486
- InlineAgentRunner = _ts_decorate19([
3716
+ InlineAgentRunner = _ts_decorate20([
3487
3717
  Injectable10(),
3488
- _ts_param17(0, Inject17(AGENT_DEPS_FACTORY5)),
3489
- _ts_param17(1, Inject17(AGENT_STORE5)),
3490
- _ts_metadata18("design:type", Function),
3491
- _ts_metadata18("design:paramtypes", [
3718
+ _ts_param18(0, Inject18(AGENT_DEPS_FACTORY6)),
3719
+ _ts_param18(1, Inject18(AGENT_STORE5)),
3720
+ _ts_metadata19("design:type", Function),
3721
+ _ts_metadata19("design:paramtypes", [
3492
3722
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
3493
3723
  typeof AgentStore === "undefined" ? Object : AgentStore
3494
3724
  ])
@@ -3533,7 +3763,7 @@ function resolveSkillsConfig(options, declared) {
3533
3763
  __name(resolveSkillsConfig, "resolveSkillsConfig");
3534
3764
 
3535
3765
  // src/agent.module.ts
3536
- function _ts_decorate20(decorators, target, key, desc) {
3766
+ function _ts_decorate21(decorators, target, key, desc) {
3537
3767
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3538
3768
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3539
3769
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3546,7 +3776,7 @@ function _ts_decorate20(decorators, target, key, desc) {
3546
3776
  }
3547
3777
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3548
3778
  }
3549
- __name(_ts_decorate20, "_ts_decorate");
3779
+ __name(_ts_decorate21, "_ts_decorate");
3550
3780
  var DEFAULT_PATH = "agent";
3551
3781
  function sharedProviders(durable, includeStore) {
3552
3782
  const providers = [
@@ -3556,8 +3786,8 @@ function sharedProviders(durable, includeStore) {
3556
3786
  },
3557
3787
  // Starts empty; AgentDiscoveryService populates it from `@Agent`-decorated providers at boot.
3558
3788
  {
3559
- provide: AGENT_REGISTRY5,
3560
- useFactory: /* @__PURE__ */ __name(() => new AgentRegistry5(), "useFactory")
3789
+ provide: AGENT_REGISTRY6,
3790
+ useFactory: /* @__PURE__ */ __name(() => new AgentRegistry6(), "useFactory")
3561
3791
  },
3562
3792
  // A shared, mutable list AgentDiscoveryService fills with `@SystemPromptContributor()` methods.
3563
3793
  {
@@ -3605,7 +3835,7 @@ function sharedProviders(durable, includeStore) {
3605
3835
  ]
3606
3836
  },
3607
3837
  {
3608
- provide: AGENT_ACTOR_RESOLVER8,
3838
+ provide: AGENT_ACTOR_RESOLVER9,
3609
3839
  useFactory: /* @__PURE__ */ __name((options) => options.actorResolver, "useFactory"),
3610
3840
  inject: [
3611
3841
  AGENT_OPTIONS4
@@ -3631,7 +3861,7 @@ function sharedProviders(durable, includeStore) {
3631
3861
  },
3632
3862
  AgentDepsFactory2,
3633
3863
  {
3634
- provide: AGENT_DEPS_FACTORY6,
3864
+ provide: AGENT_DEPS_FACTORY7,
3635
3865
  useExisting: AgentDepsFactory2
3636
3866
  },
3637
3867
  // Populates the registry + contributors (onModuleInit) BEFORE AiToolDiscoveryService synthesizes
@@ -3687,10 +3917,10 @@ function exportsFor(includeStore) {
3687
3917
  return [
3688
3918
  AGENT_OPTIONS4,
3689
3919
  AGENT_TOOL_REGISTRY3,
3690
- AGENT_REGISTRY5,
3920
+ AGENT_REGISTRY6,
3691
3921
  AGENT_SINK3,
3692
3922
  AGENT_ROLES_POLICY2,
3693
- AGENT_ACTOR_RESOLVER8,
3923
+ AGENT_ACTOR_RESOLVER9,
3694
3924
  AGENT_MODEL2,
3695
3925
  ...includeStore ? [
3696
3926
  AGENT_STORE6
@@ -3699,7 +3929,7 @@ function exportsFor(includeStore) {
3699
3929
  AGENT_PROMPT_CONTRIBUTORS3,
3700
3930
  AGENT_SKILLS3,
3701
3931
  AGENT_MEMORY3,
3702
- AGENT_DEPS_FACTORY6,
3932
+ AGENT_DEPS_FACTORY7,
3703
3933
  AgentDepsFactory2,
3704
3934
  AgentService,
3705
3935
  InlineAgentRunner,
@@ -3714,7 +3944,8 @@ var BASE_CONTROLLERS = [
3714
3944
  QuotaController,
3715
3945
  AgentsController,
3716
3946
  SkillsController,
3717
- MemoriesController
3947
+ MemoriesController,
3948
+ ToolsController
3718
3949
  ];
3719
3950
  var GUARDABLE_CONTROLLERS = [
3720
3951
  ...BASE_CONTROLLERS,
@@ -3817,7 +4048,7 @@ var AgentModule = class _AgentModule {
3817
4048
  };
3818
4049
  }
3819
4050
  };
3820
- AgentModule = _ts_decorate20([
4051
+ AgentModule = _ts_decorate21([
3821
4052
  Global2(),
3822
4053
  Module2({})
3823
4054
  ], AgentModule);