@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.
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
4
  // src/agent.module.ts
5
- import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER8, AGENT_APPROVAL_PORT, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY4, AGENT_DURABLE_RUNNER, 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_SINK2, AGENT_SKILLS as AGENT_SKILLS3, AGENT_SKILL_SOURCES as AGENT_SKILL_SOURCES2, AGENT_STORE as AGENT_STORE4, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY3, AgentRegistry as AgentRegistry5, DefaultRolesPolicy, ToolRegistry as ToolRegistry3 } from "@dudousxd/nestjs-agent-core";
5
+ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER9, AGENT_APPROVAL_PORT, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY5, AGENT_DURABLE_RUNNER, 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_SINK2, AGENT_SKILLS as AGENT_SKILLS3, AGENT_SKILL_SOURCES as AGENT_SKILL_SOURCES2, AGENT_STORE as AGENT_STORE4, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY3, AgentRegistry as AgentRegistry6, DefaultRolesPolicy, ToolRegistry as ToolRegistry3 } from "@dudousxd/nestjs-agent-core";
6
6
  import { Global, Module } from "@nestjs/common";
7
7
  import { DiscoveryModule, RouterModule } from "@nestjs/core";
8
8
 
@@ -122,6 +122,9 @@ var AgentDepsFactory2 = class {
122
122
  store: this.store,
123
123
  sink: this.sink,
124
124
  rolesPolicy: this.rolesPolicy,
125
+ ...this.options.approvalPolicy !== void 0 ? {
126
+ approvalPolicy: this.options.approvalPolicy
127
+ } : {},
125
128
  registry: this.registry,
126
129
  promptContributors: this.promptContributors,
127
130
  systemPrompt: definition?.systemPrompt ?? "You are a helpful assistant.",
@@ -269,8 +272,8 @@ AgentDepsFactory2 = _ts_decorate([
269
272
  ], AgentDepsFactory2);
270
273
 
271
274
  // src/agent.service.ts
272
- import { AGENT_ATTACHMENT_STAGING, AGENT_DEPS_FACTORY, AGENT_QUOTA_STORE as AGENT_QUOTA_STORE2, AGENT_RUNNER, AGENT_STORE as AGENT_STORE2 } from "@dudousxd/nestjs-agent-core";
273
- import { BadRequestException, ForbiddenException, Inject as Inject2, Injectable as Injectable2, NotFoundException, NotImplementedException, Optional as Optional2 } from "@nestjs/common";
275
+ import { AGENT_ATTACHMENT_STAGING, AGENT_DEPS_FACTORY, AGENT_QUOTA_STORE as AGENT_QUOTA_STORE2, AGENT_RUNNER, AGENT_STORE as AGENT_STORE2, REQUESTER_APPROVER, mayDecideApproval } from "@dudousxd/nestjs-agent-core";
276
+ import { BadRequestException, ForbiddenException, GoneException, Inject as Inject2, Injectable as Injectable2, NotFoundException, NotImplementedException, Optional as Optional2 } from "@nestjs/common";
274
277
 
275
278
  // src/agent-deps.ts
276
279
  function utcDay(date = /* @__PURE__ */ new Date()) {
@@ -423,18 +426,35 @@ var AgentService = class {
423
426
  await this.assertOwnsActiveStream(actor, runId);
424
427
  return this.subscribe(runId);
425
428
  }
426
- async approve(actor, toolCallId2) {
427
- await this.assertOwnsToolCall(actor, toolCallId2);
429
+ /**
430
+ * Approve a parked action call as `actor`. Who may is the call's recorded approver's business
431
+ * (see {@link assertMayDecide}); `remember` approves later calls of the same tool in the same
432
+ * thread, and `via` names the surface the decision came through (`'web'`, `'slack'`, …) — both
433
+ * persisted with the call.
434
+ */
435
+ async approve(actor, toolCallId2, opts = {}) {
436
+ await this.assertMayDecide(actor, toolCallId2);
428
437
  return this.signalToolCall(toolCallId2, {
429
- approved: true
438
+ approved: true,
439
+ executedByRef: actor.id,
440
+ ...opts.remember === true ? {
441
+ remember: true
442
+ } : {},
443
+ ...opts.via !== void 0 ? {
444
+ decidedVia: opts.via
445
+ } : {}
430
446
  });
431
447
  }
432
- async reject(actor, toolCallId2, reason) {
433
- await this.assertOwnsToolCall(actor, toolCallId2);
448
+ async reject(actor, toolCallId2, reason, opts = {}) {
449
+ await this.assertMayDecide(actor, toolCallId2);
434
450
  return this.signalToolCall(toolCallId2, {
435
451
  approved: false,
452
+ executedByRef: actor.id,
436
453
  ...reason !== void 0 ? {
437
454
  reason
455
+ } : {},
456
+ ...opts.via !== void 0 ? {
457
+ decidedVia: opts.via
438
458
  } : {}
439
459
  });
440
460
  }
@@ -475,6 +495,7 @@ var AgentService = class {
475
495
  * not the thread's own actor).
476
496
  */
477
497
  async signalToolCall(toolCallId2, reply) {
498
+ await this.assertNotExpired(toolCallId2);
478
499
  const runId = await this.resolveRunForToolCall(toolCallId2);
479
500
  return this.runner.signal(runId, toolCallId2, reply);
480
501
  }
@@ -713,6 +734,47 @@ var AgentService = class {
713
734
  }
714
735
  }
715
736
  /**
737
+ * Authorization seam for approve/reject. The call's recorded approver decides who may settle it:
738
+ * the requester (the default, and every call recorded before approvers existed) is the thread's
739
+ * own actor — the ownership check this always was; any other approver goes through the policy's
740
+ * `canDecide`, which by default asks whether the actor holds that role.
741
+ */
742
+ async assertMayDecide(actor, toolCallId2) {
743
+ const approval = await this.store.toolCallApproval?.(toolCallId2);
744
+ const approver = approval?.approver ?? REQUESTER_APPROVER;
745
+ if (approver === REQUESTER_APPROVER) {
746
+ return this.assertOwnsToolCall(actor, toolCallId2);
747
+ }
748
+ const requesterRef = await this.store.ownerOfToolCall(toolCallId2);
749
+ if (requesterRef === null) {
750
+ throw new NotFoundException(`tool call ${toolCallId2} not found`);
751
+ }
752
+ const allowed = await mayDecideApproval(this.deps.forAgent().approvalPolicy, actor, {
753
+ toolCallId: toolCallId2,
754
+ approver,
755
+ requesterRef
756
+ });
757
+ if (!allowed) {
758
+ throw new ForbiddenException(`this approval is for ${approver}`);
759
+ }
760
+ }
761
+ /**
762
+ * Refuse a decision on a request that has already lapsed — recorded `expired`, or past its
763
+ * `expiresAt` with the run's own timer about to fire. Signalling it anyway would race the timeout:
764
+ * a durable runtime buffers a signal nobody is waiting on, and a late approval must not be what a
765
+ * later replay of the run reads back.
766
+ */
767
+ async assertNotExpired(toolCallId2) {
768
+ const approval = await this.store.toolCallApproval?.(toolCallId2);
769
+ if (approval === null || approval === void 0) {
770
+ return;
771
+ }
772
+ const lapsed = approval.status === "expired" || approval.status === "pending_approval" && approval.expiresAt !== null && Date.parse(approval.expiresAt) <= Date.now();
773
+ if (lapsed) {
774
+ throw new GoneException(`the approval request for tool call ${toolCallId2} has expired`);
775
+ }
776
+ }
777
+ /**
716
778
  * Resolve the run awaiting `toolCallId`. Derived server-side from the tool call alone — the client
717
779
  * never knows or supplies a runId, and that run is the sub-agent's own child run when the pending
718
780
  * call belongs to a delegated agent. The store answers from the CALL'S OWN `runId` where it has
@@ -790,6 +852,12 @@ var AgentApprovalPortAdapter = class {
790
852
  approved: true,
791
853
  ...opts?.executedByRef !== void 0 ? {
792
854
  executedByRef: opts.executedByRef
855
+ } : {},
856
+ ...opts?.remember === true ? {
857
+ remember: true
858
+ } : {},
859
+ ...opts?.decidedVia !== void 0 ? {
860
+ decidedVia: opts.decidedVia
793
861
  } : {}
794
862
  });
795
863
  }
@@ -801,6 +869,9 @@ var AgentApprovalPortAdapter = class {
801
869
  } : {},
802
870
  ...opts?.reason !== void 0 ? {
803
871
  reason: opts.reason
872
+ } : {},
873
+ ...opts?.decidedVia !== void 0 ? {
874
+ decidedVia: opts.decidedVia
804
875
  } : {}
805
876
  });
806
877
  }
@@ -1720,6 +1791,8 @@ var MAX_ANSWERED_QUESTIONS = 100;
1720
1791
  var MAX_VALUES_PER_QUESTION = 100;
1721
1792
  var MAX_ANSWER_VALUE_LENGTH = 4096;
1722
1793
  var MAX_REJECT_REASON_LENGTH = 4096;
1794
+ var MAX_VIA_LENGTH = 64;
1795
+ var DEFAULT_VIA = "web";
1723
1796
  function toolCallId(claimed) {
1724
1797
  if (typeof claimed !== "string" || claimed.length === 0) {
1725
1798
  throw new BadRequestException4("toolCallId must be a non-empty string");
@@ -1740,6 +1813,26 @@ function rejectReason(claimed) {
1740
1813
  return claimed;
1741
1814
  }
1742
1815
  __name(rejectReason, "rejectReason");
1816
+ function remember(claimed) {
1817
+ if (claimed === void 0) {
1818
+ return false;
1819
+ }
1820
+ if (typeof claimed !== "boolean") {
1821
+ throw new BadRequestException4("remember must be a boolean");
1822
+ }
1823
+ return claimed;
1824
+ }
1825
+ __name(remember, "remember");
1826
+ function via(claimed) {
1827
+ if (claimed === void 0) {
1828
+ return DEFAULT_VIA;
1829
+ }
1830
+ if (typeof claimed !== "string" || claimed.length === 0 || claimed.length > MAX_VIA_LENGTH) {
1831
+ throw new BadRequestException4(`via must be a string of 1-${MAX_VIA_LENGTH} characters`);
1832
+ }
1833
+ return claimed;
1834
+ }
1835
+ __name(via, "via");
1743
1836
  function answers(claimed) {
1744
1837
  if (claimed === void 0) {
1745
1838
  return void 0;
@@ -1784,14 +1877,19 @@ var ToolCallController = class {
1784
1877
  }
1785
1878
  async approve(req, body) {
1786
1879
  const actor = await this.actorResolver.resolve(req);
1787
- await this.agent.approve(actor, toolCallId(body.toolCallId));
1880
+ await this.agent.approve(actor, toolCallId(body.toolCallId), {
1881
+ remember: remember(body.remember),
1882
+ via: via(body.via)
1883
+ });
1788
1884
  return {
1789
1885
  ok: true
1790
1886
  };
1791
1887
  }
1792
1888
  async reject(req, body) {
1793
1889
  const actor = await this.actorResolver.resolve(req);
1794
- await this.agent.reject(actor, toolCallId(body.toolCallId), rejectReason(body.reason));
1890
+ await this.agent.reject(actor, toolCallId(body.toolCallId), rejectReason(body.reason), {
1891
+ via: via(body.via)
1892
+ });
1795
1893
  return {
1796
1894
  ok: true
1797
1895
  };
@@ -1857,7 +1955,7 @@ _ts_decorate11([
1857
1955
  _ts_metadata11("design:type", Function),
1858
1956
  _ts_metadata11("design:paramtypes", [
1859
1957
  typeof Request === "undefined" ? Object : Request,
1860
- typeof ApproveBody === "undefined" ? Object : ApproveBody
1958
+ Object
1861
1959
  ]),
1862
1960
  _ts_metadata11("design:returntype", Promise)
1863
1961
  ], ToolCallController.prototype, "skip", null);
@@ -1871,9 +1969,90 @@ ToolCallController = _ts_decorate11([
1871
1969
  ])
1872
1970
  ], ToolCallController);
1873
1971
 
1972
+ // src/controller/tools.controller.ts
1973
+ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER8, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY3, AGENT_REGISTRY as AGENT_REGISTRY3, AgentRegistry as AgentRegistry4 } from "@dudousxd/nestjs-agent-core";
1974
+ import { Controller as Controller9, Get as Get8, Inject as Inject11, NotFoundException as NotFoundException3, Query as Query3, Req as Req8 } from "@nestjs/common";
1975
+ function _ts_decorate12(decorators, target, key, desc) {
1976
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1977
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1978
+ r = Reflect.decorate(decorators, target, key, desc);
1979
+ } else {
1980
+ for (var i = decorators.length - 1; i >= 0; i--) {
1981
+ if (d = decorators[i]) {
1982
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1983
+ }
1984
+ }
1985
+ }
1986
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1987
+ }
1988
+ __name(_ts_decorate12, "_ts_decorate");
1989
+ function _ts_metadata12(metadataKey, metadataValue) {
1990
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1991
+ return Reflect.metadata(metadataKey, metadataValue);
1992
+ }
1993
+ }
1994
+ __name(_ts_metadata12, "_ts_metadata");
1995
+ function _ts_param11(paramIndex, decorator) {
1996
+ return function(target, key) {
1997
+ decorator(target, key, paramIndex);
1998
+ };
1999
+ }
2000
+ __name(_ts_param11, "_ts_param");
2001
+ var ToolsController = class {
2002
+ static {
2003
+ __name(this, "ToolsController");
2004
+ }
2005
+ actorResolver;
2006
+ depsFactory;
2007
+ agents;
2008
+ constructor(actorResolver, depsFactory, agents) {
2009
+ this.actorResolver = actorResolver;
2010
+ this.depsFactory = depsFactory;
2011
+ this.agents = agents;
2012
+ }
2013
+ async list(req, agent) {
2014
+ if (agent !== void 0 && this.agents.get(agent) === void 0) {
2015
+ throw new NotFoundException3(`No agent named "${agent}"`);
2016
+ }
2017
+ const actor = await this.actorResolver.resolve(req);
2018
+ const deps = this.depsFactory.forAgent(agent);
2019
+ const specs = await deps.registry.visibleSpecs(actor, deps.rolesPolicy, deps.toolAllowList);
2020
+ return specs.map((spec) => ({
2021
+ name: spec.name,
2022
+ kind: spec.kind,
2023
+ ...spec.presentation !== void 0 ? {
2024
+ presentation: spec.presentation
2025
+ } : {}
2026
+ }));
2027
+ }
2028
+ };
2029
+ _ts_decorate12([
2030
+ Get8(),
2031
+ _ts_param11(0, Req8()),
2032
+ _ts_param11(1, Query3("agent")),
2033
+ _ts_metadata12("design:type", Function),
2034
+ _ts_metadata12("design:paramtypes", [
2035
+ typeof Request === "undefined" ? Object : Request,
2036
+ String
2037
+ ]),
2038
+ _ts_metadata12("design:returntype", Promise)
2039
+ ], ToolsController.prototype, "list", null);
2040
+ ToolsController = _ts_decorate12([
2041
+ Controller9("tools"),
2042
+ _ts_param11(0, Inject11(AGENT_ACTOR_RESOLVER8)),
2043
+ _ts_param11(1, Inject11(AGENT_DEPS_FACTORY3)),
2044
+ _ts_param11(2, Inject11(AGENT_REGISTRY3)),
2045
+ _ts_metadata12("design:type", Function),
2046
+ _ts_metadata12("design:paramtypes", [
2047
+ typeof ActorResolver === "undefined" ? Object : ActorResolver,
2048
+ typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
2049
+ typeof AgentRegistry4 === "undefined" ? Object : AgentRegistry4
2050
+ ])
2051
+ ], ToolsController);
2052
+
1874
2053
  // src/discovery/agent-discovery.service.ts
1875
- import { AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS2, AGENT_REGISTRY as AGENT_REGISTRY3, AgentRegistry as AgentRegistry4 } from "@dudousxd/nestjs-agent-core";
1876
- import { Inject as Inject11, Injectable as Injectable4, Logger } from "@nestjs/common";
2054
+ import { AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS2, AGENT_REGISTRY as AGENT_REGISTRY4, AgentRegistry as AgentRegistry5 } from "@dudousxd/nestjs-agent-core";
2055
+ import { Inject as Inject12, Injectable as Injectable4, Logger } from "@nestjs/common";
1877
2056
  import { DiscoveryService, MetadataScanner } from "@nestjs/core";
1878
2057
 
1879
2058
  // src/decorator/agent.decorator.ts
@@ -1908,7 +2087,7 @@ function SystemPromptContributor() {
1908
2087
  __name(SystemPromptContributor, "SystemPromptContributor");
1909
2088
 
1910
2089
  // src/discovery/agent-discovery.service.ts
1911
- function _ts_decorate12(decorators, target, key, desc) {
2090
+ function _ts_decorate13(decorators, target, key, desc) {
1912
2091
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1913
2092
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1914
2093
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1921,19 +2100,19 @@ function _ts_decorate12(decorators, target, key, desc) {
1921
2100
  }
1922
2101
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1923
2102
  }
1924
- __name(_ts_decorate12, "_ts_decorate");
1925
- function _ts_metadata12(metadataKey, metadataValue) {
2103
+ __name(_ts_decorate13, "_ts_decorate");
2104
+ function _ts_metadata13(metadataKey, metadataValue) {
1926
2105
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1927
2106
  return Reflect.metadata(metadataKey, metadataValue);
1928
2107
  }
1929
2108
  }
1930
- __name(_ts_metadata12, "_ts_metadata");
1931
- function _ts_param11(paramIndex, decorator) {
2109
+ __name(_ts_metadata13, "_ts_metadata");
2110
+ function _ts_param12(paramIndex, decorator) {
1932
2111
  return function(target, key) {
1933
2112
  decorator(target, key, paramIndex);
1934
2113
  };
1935
2114
  }
1936
- __name(_ts_param11, "_ts_param");
2115
+ __name(_ts_param12, "_ts_param");
1937
2116
  var AgentDiscoveryService = class _AgentDiscoveryService {
1938
2117
  static {
1939
2118
  __name(this, "AgentDiscoveryService");
@@ -2060,22 +2239,22 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
2060
2239
  return (ctx) => candidate.call(instance, ctx);
2061
2240
  }
2062
2241
  };
2063
- AgentDiscoveryService = _ts_decorate12([
2242
+ AgentDiscoveryService = _ts_decorate13([
2064
2243
  Injectable4(),
2065
- _ts_param11(2, Inject11(AGENT_REGISTRY3)),
2066
- _ts_param11(3, Inject11(AGENT_PROMPT_CONTRIBUTORS2)),
2067
- _ts_metadata12("design:type", Function),
2068
- _ts_metadata12("design:paramtypes", [
2244
+ _ts_param12(2, Inject12(AGENT_REGISTRY4)),
2245
+ _ts_param12(3, Inject12(AGENT_PROMPT_CONTRIBUTORS2)),
2246
+ _ts_metadata13("design:type", Function),
2247
+ _ts_metadata13("design:paramtypes", [
2069
2248
  typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
2070
2249
  typeof MetadataScanner === "undefined" ? Object : MetadataScanner,
2071
- typeof AgentRegistry4 === "undefined" ? Object : AgentRegistry4,
2250
+ typeof AgentRegistry5 === "undefined" ? Object : AgentRegistry5,
2072
2251
  Array
2073
2252
  ])
2074
2253
  ], AgentDiscoveryService);
2075
2254
 
2076
2255
  // src/discovery/ai-tool-discovery.service.ts
2077
- 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";
2078
- import { Inject as Inject12, Injectable as Injectable5, Logger as Logger2 } from "@nestjs/common";
2256
+ 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";
2257
+ import { Inject as Inject13, Injectable as Injectable5, Logger as Logger2 } from "@nestjs/common";
2079
2258
  import { DiscoveryService as DiscoveryService2 } from "@nestjs/core";
2080
2259
  import { z } from "zod";
2081
2260
 
@@ -2124,7 +2303,7 @@ function provideAgentTool(factoryOrTool, inject) {
2124
2303
  __name(provideAgentTool, "provideAgentTool");
2125
2304
 
2126
2305
  // src/discovery/ai-tool-discovery.service.ts
2127
- function _ts_decorate13(decorators, target, key, desc) {
2306
+ function _ts_decorate14(decorators, target, key, desc) {
2128
2307
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2129
2308
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2130
2309
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2137,19 +2316,19 @@ function _ts_decorate13(decorators, target, key, desc) {
2137
2316
  }
2138
2317
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2139
2318
  }
2140
- __name(_ts_decorate13, "_ts_decorate");
2141
- function _ts_metadata13(metadataKey, metadataValue) {
2319
+ __name(_ts_decorate14, "_ts_decorate");
2320
+ function _ts_metadata14(metadataKey, metadataValue) {
2142
2321
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2143
2322
  return Reflect.metadata(metadataKey, metadataValue);
2144
2323
  }
2145
2324
  }
2146
- __name(_ts_metadata13, "_ts_metadata");
2147
- function _ts_param12(paramIndex, decorator) {
2325
+ __name(_ts_metadata14, "_ts_metadata");
2326
+ function _ts_param13(paramIndex, decorator) {
2148
2327
  return function(target, key) {
2149
2328
  decorator(target, key, paramIndex);
2150
2329
  };
2151
2330
  }
2152
- __name(_ts_param12, "_ts_param");
2331
+ __name(_ts_param13, "_ts_param");
2153
2332
  var AiToolDiscoveryService = class _AiToolDiscoveryService {
2154
2333
  static {
2155
2334
  __name(this, "AiToolDiscoveryService");
@@ -2203,6 +2382,9 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
2203
2382
  } : {},
2204
2383
  ...meta.enabled !== void 0 ? {
2205
2384
  enabled: meta.enabled
2385
+ } : {},
2386
+ ...meta.presentation !== void 0 ? {
2387
+ presentation: meta.presentation
2206
2388
  } : {}
2207
2389
  }, {
2208
2390
  execute: /* @__PURE__ */ __name((input, ctx) => instance.execute(input, ctx), "execute"),
@@ -2276,13 +2458,13 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
2276
2458
  return true;
2277
2459
  }
2278
2460
  };
2279
- AiToolDiscoveryService = _ts_decorate13([
2461
+ AiToolDiscoveryService = _ts_decorate14([
2280
2462
  Injectable5(),
2281
- _ts_param12(1, Inject12(AGENT_TOOL_REGISTRY2)),
2282
- _ts_param12(2, Inject12(AGENT_REGISTRY4)),
2283
- _ts_param12(3, Inject12(AGENT_OPTIONS3)),
2284
- _ts_metadata13("design:type", Function),
2285
- _ts_metadata13("design:paramtypes", [
2463
+ _ts_param13(1, Inject13(AGENT_TOOL_REGISTRY2)),
2464
+ _ts_param13(2, Inject13(AGENT_REGISTRY5)),
2465
+ _ts_param13(3, Inject13(AGENT_OPTIONS3)),
2466
+ _ts_metadata14("design:type", Function),
2467
+ _ts_metadata14("design:paramtypes", [
2286
2468
  typeof DiscoveryService2 === "undefined" ? Object : DiscoveryService2,
2287
2469
  typeof ToolRegistry === "undefined" ? Object : ToolRegistry,
2288
2470
  typeof AgentRegistry === "undefined" ? Object : AgentRegistry,
@@ -2292,7 +2474,7 @@ AiToolDiscoveryService = _ts_decorate13([
2292
2474
 
2293
2475
  // src/discovery/skill-discovery.service.ts
2294
2476
  import { AGENT_SKILL_SOURCES } from "@dudousxd/nestjs-agent-core";
2295
- import { Inject as Inject13, Injectable as Injectable6, Logger as Logger3 } from "@nestjs/common";
2477
+ import { Inject as Inject14, Injectable as Injectable6, Logger as Logger3 } from "@nestjs/common";
2296
2478
  import { DiscoveryService as DiscoveryService3 } from "@nestjs/core";
2297
2479
 
2298
2480
  // src/decorator/skill.decorator.ts
@@ -2315,7 +2497,7 @@ function skillScope(options) {
2315
2497
  __name(skillScope, "skillScope");
2316
2498
 
2317
2499
  // src/discovery/skill-discovery.service.ts
2318
- function _ts_decorate14(decorators, target, key, desc) {
2500
+ function _ts_decorate15(decorators, target, key, desc) {
2319
2501
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2320
2502
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2321
2503
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2328,19 +2510,19 @@ function _ts_decorate14(decorators, target, key, desc) {
2328
2510
  }
2329
2511
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2330
2512
  }
2331
- __name(_ts_decorate14, "_ts_decorate");
2332
- function _ts_metadata14(metadataKey, metadataValue) {
2513
+ __name(_ts_decorate15, "_ts_decorate");
2514
+ function _ts_metadata15(metadataKey, metadataValue) {
2333
2515
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2334
2516
  return Reflect.metadata(metadataKey, metadataValue);
2335
2517
  }
2336
2518
  }
2337
- __name(_ts_metadata14, "_ts_metadata");
2338
- function _ts_param13(paramIndex, decorator) {
2519
+ __name(_ts_metadata15, "_ts_metadata");
2520
+ function _ts_param14(paramIndex, decorator) {
2339
2521
  return function(target, key) {
2340
2522
  decorator(target, key, paramIndex);
2341
2523
  };
2342
2524
  }
2343
- __name(_ts_param13, "_ts_param");
2525
+ __name(_ts_param14, "_ts_param");
2344
2526
  var SkillDiscoveryService = class _SkillDiscoveryService {
2345
2527
  static {
2346
2528
  __name(this, "SkillDiscoveryService");
@@ -2384,11 +2566,11 @@ var SkillDiscoveryService = class _SkillDiscoveryService {
2384
2566
  return flat === void 0 ? void 0 : () => flat;
2385
2567
  }
2386
2568
  };
2387
- SkillDiscoveryService = _ts_decorate14([
2569
+ SkillDiscoveryService = _ts_decorate15([
2388
2570
  Injectable6(),
2389
- _ts_param13(1, Inject13(AGENT_SKILL_SOURCES)),
2390
- _ts_metadata14("design:type", Function),
2391
- _ts_metadata14("design:paramtypes", [
2571
+ _ts_param14(1, Inject14(AGENT_SKILL_SOURCES)),
2572
+ _ts_metadata15("design:type", Function),
2573
+ _ts_metadata15("design:paramtypes", [
2392
2574
  typeof DiscoveryService3 === "undefined" ? Object : DiscoveryService3,
2393
2575
  Array
2394
2576
  ])
@@ -2486,9 +2668,9 @@ var LedgerQuotaStore = class {
2486
2668
  };
2487
2669
 
2488
2670
  // src/runner/inline-agent-runner.ts
2489
- import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY3, AGENT_STORE as AGENT_STORE3, RunCancelledError, agentFailureCode, encodeStreamEvent, publishAgentRunFailed, runAgentLoop, settleAll, settleUnsettledDelegation } from "@dudousxd/nestjs-agent-core";
2490
- import { Inject as Inject14, Injectable as Injectable7, Logger as Logger4 } from "@nestjs/common";
2491
- function _ts_decorate15(decorators, target, key, desc) {
2671
+ import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY4, AGENT_STORE as AGENT_STORE3, RunCancelledError, agentFailureCode, encodeStreamEvent, publishAgentRunFailed, runAgentLoop, settleAll, settleUnsettledDelegation } from "@dudousxd/nestjs-agent-core";
2672
+ import { Inject as Inject15, Injectable as Injectable7, Logger as Logger4 } from "@nestjs/common";
2673
+ function _ts_decorate16(decorators, target, key, desc) {
2492
2674
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2493
2675
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2494
2676
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2501,19 +2683,19 @@ function _ts_decorate15(decorators, target, key, desc) {
2501
2683
  }
2502
2684
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2503
2685
  }
2504
- __name(_ts_decorate15, "_ts_decorate");
2505
- function _ts_metadata15(metadataKey, metadataValue) {
2686
+ __name(_ts_decorate16, "_ts_decorate");
2687
+ function _ts_metadata16(metadataKey, metadataValue) {
2506
2688
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2507
2689
  return Reflect.metadata(metadataKey, metadataValue);
2508
2690
  }
2509
2691
  }
2510
- __name(_ts_metadata15, "_ts_metadata");
2511
- function _ts_param14(paramIndex, decorator) {
2692
+ __name(_ts_metadata16, "_ts_metadata");
2693
+ function _ts_param15(paramIndex, decorator) {
2512
2694
  return function(target, key) {
2513
2695
  decorator(target, key, paramIndex);
2514
2696
  };
2515
2697
  }
2516
- __name(_ts_param14, "_ts_param");
2698
+ __name(_ts_param15, "_ts_param");
2517
2699
  var InlineAgentRunner = class _InlineAgentRunner {
2518
2700
  static {
2519
2701
  __name(this, "InlineAgentRunner");
@@ -2639,6 +2821,36 @@ var InlineAgentRunner = class _InlineAgentRunner {
2639
2821
  * shape it is delivering — the loop asked for one and only ever gets what the caller sent. A
2640
2822
  * cancel settles the wait too, by rejecting it.
2641
2823
  */
2824
+ /**
2825
+ * {@link park} for an approval, bounded by the policy's time to live when it has one: the timer
2826
+ * settles the wait as `expired` — the same Decision the durable runner builds from its signal
2827
+ * timeout — and a decision that arrives first disarms it.
2828
+ */
2829
+ parkApproval(runId, toolCallId2, timeoutMs) {
2830
+ const waiting = this.park(runId, toolCallId2);
2831
+ if (timeoutMs === void 0) {
2832
+ return waiting;
2833
+ }
2834
+ const key = `${runId}:${toolCallId2}`;
2835
+ let timer;
2836
+ const lapse = new Promise((resolve) => {
2837
+ timer = setTimeout(() => {
2838
+ const entry = this.pending.get(key);
2839
+ if (entry !== void 0) {
2840
+ this.pending.delete(key);
2841
+ resolve({
2842
+ approved: false,
2843
+ expired: true
2844
+ });
2845
+ }
2846
+ }, timeoutMs);
2847
+ timer.unref?.();
2848
+ });
2849
+ return Promise.race([
2850
+ waiting,
2851
+ lapse
2852
+ ]).finally(() => clearTimeout(timer));
2853
+ }
2642
2854
  park(runId, toolCallId2) {
2643
2855
  return new Promise((resolve, reject) => {
2644
2856
  this.pending.set(`${runId}:${toolCallId2}`, {
@@ -2652,7 +2864,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
2652
2864
  return {
2653
2865
  runId,
2654
2866
  openSink: /* @__PURE__ */ __name(() => deps.sink.open(runId), "openSink"),
2655
- awaitApproval: /* @__PURE__ */ __name((call) => this.park(runId, call.id), "awaitApproval"),
2867
+ awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
2656
2868
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
2657
2869
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
2658
2870
  parallel: settleAll,
@@ -2703,7 +2915,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
2703
2915
  const hooks = {
2704
2916
  runId,
2705
2917
  openSink: /* @__PURE__ */ __name(() => deps.sink.open(runId), "openSink"),
2706
- awaitApproval: /* @__PURE__ */ __name((call) => this.park(runId, call.id), "awaitApproval"),
2918
+ awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
2707
2919
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
2708
2920
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
2709
2921
  parallel: settleAll,
@@ -2807,7 +3019,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
2807
3019
  runId,
2808
3020
  // Forward into the top-level stream; the top-level run owns end/fail on that shared sink.
2809
3021
  openSink: /* @__PURE__ */ __name(async () => childSinkWriter(await deps.sink.open(sinkRunId)), "openSink"),
2810
- awaitApproval: /* @__PURE__ */ __name((call) => this.park(runId, call.id), "awaitApproval"),
3022
+ awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
2811
3023
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
2812
3024
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
2813
3025
  parallel: settleAll,
@@ -2864,12 +3076,12 @@ var InlineAgentRunner = class _InlineAgentRunner {
2864
3076
  }
2865
3077
  }
2866
3078
  };
2867
- InlineAgentRunner = _ts_decorate15([
3079
+ InlineAgentRunner = _ts_decorate16([
2868
3080
  Injectable7(),
2869
- _ts_param14(0, Inject14(AGENT_DEPS_FACTORY3)),
2870
- _ts_param14(1, Inject14(AGENT_STORE3)),
2871
- _ts_metadata15("design:type", Function),
2872
- _ts_metadata15("design:paramtypes", [
3081
+ _ts_param15(0, Inject15(AGENT_DEPS_FACTORY4)),
3082
+ _ts_param15(1, Inject15(AGENT_STORE3)),
3083
+ _ts_metadata16("design:type", Function),
3084
+ _ts_metadata16("design:paramtypes", [
2873
3085
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
2874
3086
  typeof AgentStore === "undefined" ? Object : AgentStore
2875
3087
  ])
@@ -2914,7 +3126,7 @@ function resolveSkillsConfig(options, declared) {
2914
3126
  __name(resolveSkillsConfig, "resolveSkillsConfig");
2915
3127
 
2916
3128
  // src/agent.module.ts
2917
- function _ts_decorate16(decorators, target, key, desc) {
3129
+ function _ts_decorate17(decorators, target, key, desc) {
2918
3130
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2919
3131
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2920
3132
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2927,7 +3139,7 @@ function _ts_decorate16(decorators, target, key, desc) {
2927
3139
  }
2928
3140
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2929
3141
  }
2930
- __name(_ts_decorate16, "_ts_decorate");
3142
+ __name(_ts_decorate17, "_ts_decorate");
2931
3143
  var DEFAULT_PATH = "agent";
2932
3144
  function sharedProviders(durable, includeStore) {
2933
3145
  const providers = [
@@ -2937,8 +3149,8 @@ function sharedProviders(durable, includeStore) {
2937
3149
  },
2938
3150
  // Starts empty; AgentDiscoveryService populates it from `@Agent`-decorated providers at boot.
2939
3151
  {
2940
- provide: AGENT_REGISTRY5,
2941
- useFactory: /* @__PURE__ */ __name(() => new AgentRegistry5(), "useFactory")
3152
+ provide: AGENT_REGISTRY6,
3153
+ useFactory: /* @__PURE__ */ __name(() => new AgentRegistry6(), "useFactory")
2942
3154
  },
2943
3155
  // A shared, mutable list AgentDiscoveryService fills with `@SystemPromptContributor()` methods.
2944
3156
  {
@@ -2986,7 +3198,7 @@ function sharedProviders(durable, includeStore) {
2986
3198
  ]
2987
3199
  },
2988
3200
  {
2989
- provide: AGENT_ACTOR_RESOLVER8,
3201
+ provide: AGENT_ACTOR_RESOLVER9,
2990
3202
  useFactory: /* @__PURE__ */ __name((options) => options.actorResolver, "useFactory"),
2991
3203
  inject: [
2992
3204
  AGENT_OPTIONS4
@@ -3012,7 +3224,7 @@ function sharedProviders(durable, includeStore) {
3012
3224
  },
3013
3225
  AgentDepsFactory2,
3014
3226
  {
3015
- provide: AGENT_DEPS_FACTORY4,
3227
+ provide: AGENT_DEPS_FACTORY5,
3016
3228
  useExisting: AgentDepsFactory2
3017
3229
  },
3018
3230
  // Populates the registry + contributors (onModuleInit) BEFORE AiToolDiscoveryService synthesizes
@@ -3068,10 +3280,10 @@ function exportsFor(includeStore) {
3068
3280
  return [
3069
3281
  AGENT_OPTIONS4,
3070
3282
  AGENT_TOOL_REGISTRY3,
3071
- AGENT_REGISTRY5,
3283
+ AGENT_REGISTRY6,
3072
3284
  AGENT_SINK2,
3073
3285
  AGENT_ROLES_POLICY2,
3074
- AGENT_ACTOR_RESOLVER8,
3286
+ AGENT_ACTOR_RESOLVER9,
3075
3287
  AGENT_MODEL2,
3076
3288
  ...includeStore ? [
3077
3289
  AGENT_STORE4
@@ -3080,7 +3292,7 @@ function exportsFor(includeStore) {
3080
3292
  AGENT_PROMPT_CONTRIBUTORS3,
3081
3293
  AGENT_SKILLS3,
3082
3294
  AGENT_MEMORY3,
3083
- AGENT_DEPS_FACTORY4,
3295
+ AGENT_DEPS_FACTORY5,
3084
3296
  AgentDepsFactory2,
3085
3297
  AgentService,
3086
3298
  InlineAgentRunner,
@@ -3095,7 +3307,8 @@ var BASE_CONTROLLERS = [
3095
3307
  QuotaController,
3096
3308
  AgentsController,
3097
3309
  SkillsController,
3098
- MemoriesController
3310
+ MemoriesController,
3311
+ ToolsController
3099
3312
  ];
3100
3313
  var GUARDABLE_CONTROLLERS = [
3101
3314
  ...BASE_CONTROLLERS,
@@ -3198,7 +3411,7 @@ var AgentModule = class _AgentModule {
3198
3411
  };
3199
3412
  }
3200
3413
  };
3201
- AgentModule = _ts_decorate16([
3414
+ AgentModule = _ts_decorate17([
3202
3415
  Global(),
3203
3416
  Module({})
3204
3417
  ], AgentModule);
@@ -3265,6 +3478,7 @@ export {
3265
3478
  SkillsController,
3266
3479
  SystemPrompt,
3267
3480
  SystemPromptContributor,
3481
+ ToolsController,
3268
3482
  declaredSkillProvider,
3269
3483
  delegateToolName,
3270
3484
  provideAgentTool,