@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.cjs CHANGED
@@ -50,6 +50,7 @@ __export(index_exports, {
50
50
  SkillsController: () => SkillsController,
51
51
  SystemPrompt: () => SystemPrompt,
52
52
  SystemPromptContributor: () => SystemPromptContributor,
53
+ ToolsController: () => ToolsController,
53
54
  declaredSkillProvider: () => declaredSkillProvider,
54
55
  delegateToolName: () => delegateToolName,
55
56
  provideAgentTool: () => provideAgentTool,
@@ -63,8 +64,8 @@ __export(index_exports, {
63
64
  module.exports = __toCommonJS(index_exports);
64
65
 
65
66
  // src/agent.module.ts
66
- var import_nestjs_agent_core19 = require("@dudousxd/nestjs-agent-core");
67
- var import_common16 = require("@nestjs/common");
67
+ var import_nestjs_agent_core20 = require("@dudousxd/nestjs-agent-core");
68
+ var import_common17 = require("@nestjs/common");
68
69
  var import_core4 = require("@nestjs/core");
69
70
 
70
71
  // src/agent-deps.factory.ts
@@ -183,6 +184,9 @@ var AgentDepsFactory2 = class {
183
184
  store: this.store,
184
185
  sink: this.sink,
185
186
  rolesPolicy: this.rolesPolicy,
187
+ ...this.options.approvalPolicy !== void 0 ? {
188
+ approvalPolicy: this.options.approvalPolicy
189
+ } : {},
186
190
  registry: this.registry,
187
191
  promptContributors: this.promptContributors,
188
192
  systemPrompt: definition?.systemPrompt ?? "You are a helpful assistant.",
@@ -484,18 +488,35 @@ var AgentService = class {
484
488
  await this.assertOwnsActiveStream(actor, runId);
485
489
  return this.subscribe(runId);
486
490
  }
487
- async approve(actor, toolCallId2) {
488
- await this.assertOwnsToolCall(actor, toolCallId2);
491
+ /**
492
+ * Approve a parked action call as `actor`. Who may is the call's recorded approver's business
493
+ * (see {@link assertMayDecide}); `remember` approves later calls of the same tool in the same
494
+ * thread, and `via` names the surface the decision came through (`'web'`, `'slack'`, …) — both
495
+ * persisted with the call.
496
+ */
497
+ async approve(actor, toolCallId2, opts = {}) {
498
+ await this.assertMayDecide(actor, toolCallId2);
489
499
  return this.signalToolCall(toolCallId2, {
490
- approved: true
500
+ approved: true,
501
+ executedByRef: actor.id,
502
+ ...opts.remember === true ? {
503
+ remember: true
504
+ } : {},
505
+ ...opts.via !== void 0 ? {
506
+ decidedVia: opts.via
507
+ } : {}
491
508
  });
492
509
  }
493
- async reject(actor, toolCallId2, reason) {
494
- await this.assertOwnsToolCall(actor, toolCallId2);
510
+ async reject(actor, toolCallId2, reason, opts = {}) {
511
+ await this.assertMayDecide(actor, toolCallId2);
495
512
  return this.signalToolCall(toolCallId2, {
496
513
  approved: false,
514
+ executedByRef: actor.id,
497
515
  ...reason !== void 0 ? {
498
516
  reason
517
+ } : {},
518
+ ...opts.via !== void 0 ? {
519
+ decidedVia: opts.via
499
520
  } : {}
500
521
  });
501
522
  }
@@ -536,6 +557,7 @@ var AgentService = class {
536
557
  * not the thread's own actor).
537
558
  */
538
559
  async signalToolCall(toolCallId2, reply) {
560
+ await this.assertNotExpired(toolCallId2);
539
561
  const runId = await this.resolveRunForToolCall(toolCallId2);
540
562
  return this.runner.signal(runId, toolCallId2, reply);
541
563
  }
@@ -774,6 +796,47 @@ var AgentService = class {
774
796
  }
775
797
  }
776
798
  /**
799
+ * Authorization seam for approve/reject. The call's recorded approver decides who may settle it:
800
+ * the requester (the default, and every call recorded before approvers existed) is the thread's
801
+ * own actor — the ownership check this always was; any other approver goes through the policy's
802
+ * `canDecide`, which by default asks whether the actor holds that role.
803
+ */
804
+ async assertMayDecide(actor, toolCallId2) {
805
+ const approval = await this.store.toolCallApproval?.(toolCallId2);
806
+ const approver = approval?.approver ?? import_nestjs_agent_core3.REQUESTER_APPROVER;
807
+ if (approver === import_nestjs_agent_core3.REQUESTER_APPROVER) {
808
+ return this.assertOwnsToolCall(actor, toolCallId2);
809
+ }
810
+ const requesterRef = await this.store.ownerOfToolCall(toolCallId2);
811
+ if (requesterRef === null) {
812
+ throw new import_common2.NotFoundException(`tool call ${toolCallId2} not found`);
813
+ }
814
+ const allowed = await (0, import_nestjs_agent_core3.mayDecideApproval)(this.deps.forAgent().approvalPolicy, actor, {
815
+ toolCallId: toolCallId2,
816
+ approver,
817
+ requesterRef
818
+ });
819
+ if (!allowed) {
820
+ throw new import_common2.ForbiddenException(`this approval is for ${approver}`);
821
+ }
822
+ }
823
+ /**
824
+ * Refuse a decision on a request that has already lapsed — recorded `expired`, or past its
825
+ * `expiresAt` with the run's own timer about to fire. Signalling it anyway would race the timeout:
826
+ * a durable runtime buffers a signal nobody is waiting on, and a late approval must not be what a
827
+ * later replay of the run reads back.
828
+ */
829
+ async assertNotExpired(toolCallId2) {
830
+ const approval = await this.store.toolCallApproval?.(toolCallId2);
831
+ if (approval === null || approval === void 0) {
832
+ return;
833
+ }
834
+ const lapsed = approval.status === "expired" || approval.status === "pending_approval" && approval.expiresAt !== null && Date.parse(approval.expiresAt) <= Date.now();
835
+ if (lapsed) {
836
+ throw new import_common2.GoneException(`the approval request for tool call ${toolCallId2} has expired`);
837
+ }
838
+ }
839
+ /**
777
840
  * Resolve the run awaiting `toolCallId`. Derived server-side from the tool call alone — the client
778
841
  * never knows or supplies a runId, and that run is the sub-agent's own child run when the pending
779
842
  * call belongs to a delegated agent. The store answers from the CALL'S OWN `runId` where it has
@@ -851,6 +914,12 @@ var AgentApprovalPortAdapter = class {
851
914
  approved: true,
852
915
  ...opts?.executedByRef !== void 0 ? {
853
916
  executedByRef: opts.executedByRef
917
+ } : {},
918
+ ...opts?.remember === true ? {
919
+ remember: true
920
+ } : {},
921
+ ...opts?.decidedVia !== void 0 ? {
922
+ decidedVia: opts.decidedVia
854
923
  } : {}
855
924
  });
856
925
  }
@@ -862,6 +931,9 @@ var AgentApprovalPortAdapter = class {
862
931
  } : {},
863
932
  ...opts?.reason !== void 0 ? {
864
933
  reason: opts.reason
934
+ } : {},
935
+ ...opts?.decidedVia !== void 0 ? {
936
+ decidedVia: opts.decidedVia
865
937
  } : {}
866
938
  });
867
939
  }
@@ -1781,6 +1853,8 @@ var MAX_ANSWERED_QUESTIONS = 100;
1781
1853
  var MAX_VALUES_PER_QUESTION = 100;
1782
1854
  var MAX_ANSWER_VALUE_LENGTH = 4096;
1783
1855
  var MAX_REJECT_REASON_LENGTH = 4096;
1856
+ var MAX_VIA_LENGTH = 64;
1857
+ var DEFAULT_VIA = "web";
1784
1858
  function toolCallId(claimed) {
1785
1859
  if (typeof claimed !== "string" || claimed.length === 0) {
1786
1860
  throw new import_common11.BadRequestException("toolCallId must be a non-empty string");
@@ -1801,6 +1875,26 @@ function rejectReason(claimed) {
1801
1875
  return claimed;
1802
1876
  }
1803
1877
  __name(rejectReason, "rejectReason");
1878
+ function remember(claimed) {
1879
+ if (claimed === void 0) {
1880
+ return false;
1881
+ }
1882
+ if (typeof claimed !== "boolean") {
1883
+ throw new import_common11.BadRequestException("remember must be a boolean");
1884
+ }
1885
+ return claimed;
1886
+ }
1887
+ __name(remember, "remember");
1888
+ function via(claimed) {
1889
+ if (claimed === void 0) {
1890
+ return DEFAULT_VIA;
1891
+ }
1892
+ if (typeof claimed !== "string" || claimed.length === 0 || claimed.length > MAX_VIA_LENGTH) {
1893
+ throw new import_common11.BadRequestException(`via must be a string of 1-${MAX_VIA_LENGTH} characters`);
1894
+ }
1895
+ return claimed;
1896
+ }
1897
+ __name(via, "via");
1804
1898
  function answers(claimed) {
1805
1899
  if (claimed === void 0) {
1806
1900
  return void 0;
@@ -1845,14 +1939,19 @@ var ToolCallController = class {
1845
1939
  }
1846
1940
  async approve(req, body) {
1847
1941
  const actor = await this.actorResolver.resolve(req);
1848
- await this.agent.approve(actor, toolCallId(body.toolCallId));
1942
+ await this.agent.approve(actor, toolCallId(body.toolCallId), {
1943
+ remember: remember(body.remember),
1944
+ via: via(body.via)
1945
+ });
1849
1946
  return {
1850
1947
  ok: true
1851
1948
  };
1852
1949
  }
1853
1950
  async reject(req, body) {
1854
1951
  const actor = await this.actorResolver.resolve(req);
1855
- await this.agent.reject(actor, toolCallId(body.toolCallId), rejectReason(body.reason));
1952
+ await this.agent.reject(actor, toolCallId(body.toolCallId), rejectReason(body.reason), {
1953
+ via: via(body.via)
1954
+ });
1856
1955
  return {
1857
1956
  ok: true
1858
1957
  };
@@ -1918,7 +2017,7 @@ _ts_decorate11([
1918
2017
  _ts_metadata11("design:type", Function),
1919
2018
  _ts_metadata11("design:paramtypes", [
1920
2019
  typeof Request === "undefined" ? Object : Request,
1921
- typeof ApproveBody === "undefined" ? Object : ApproveBody
2020
+ Object
1922
2021
  ]),
1923
2022
  _ts_metadata11("design:returntype", Promise)
1924
2023
  ], ToolCallController.prototype, "skip", null);
@@ -1932,9 +2031,90 @@ ToolCallController = _ts_decorate11([
1932
2031
  ])
1933
2032
  ], ToolCallController);
1934
2033
 
1935
- // src/discovery/agent-discovery.service.ts
2034
+ // src/controller/tools.controller.ts
1936
2035
  var import_nestjs_agent_core12 = require("@dudousxd/nestjs-agent-core");
1937
2036
  var import_common12 = require("@nestjs/common");
2037
+ function _ts_decorate12(decorators, target, key, desc) {
2038
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2039
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2040
+ r = Reflect.decorate(decorators, target, key, desc);
2041
+ } else {
2042
+ for (var i = decorators.length - 1; i >= 0; i--) {
2043
+ if (d = decorators[i]) {
2044
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2045
+ }
2046
+ }
2047
+ }
2048
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2049
+ }
2050
+ __name(_ts_decorate12, "_ts_decorate");
2051
+ function _ts_metadata12(metadataKey, metadataValue) {
2052
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2053
+ return Reflect.metadata(metadataKey, metadataValue);
2054
+ }
2055
+ }
2056
+ __name(_ts_metadata12, "_ts_metadata");
2057
+ function _ts_param11(paramIndex, decorator) {
2058
+ return function(target, key) {
2059
+ decorator(target, key, paramIndex);
2060
+ };
2061
+ }
2062
+ __name(_ts_param11, "_ts_param");
2063
+ var ToolsController = class {
2064
+ static {
2065
+ __name(this, "ToolsController");
2066
+ }
2067
+ actorResolver;
2068
+ depsFactory;
2069
+ agents;
2070
+ constructor(actorResolver, depsFactory, agents) {
2071
+ this.actorResolver = actorResolver;
2072
+ this.depsFactory = depsFactory;
2073
+ this.agents = agents;
2074
+ }
2075
+ async list(req, agent) {
2076
+ if (agent !== void 0 && this.agents.get(agent) === void 0) {
2077
+ throw new import_common12.NotFoundException(`No agent named "${agent}"`);
2078
+ }
2079
+ const actor = await this.actorResolver.resolve(req);
2080
+ const deps = this.depsFactory.forAgent(agent);
2081
+ const specs = await deps.registry.visibleSpecs(actor, deps.rolesPolicy, deps.toolAllowList);
2082
+ return specs.map((spec) => ({
2083
+ name: spec.name,
2084
+ kind: spec.kind,
2085
+ ...spec.presentation !== void 0 ? {
2086
+ presentation: spec.presentation
2087
+ } : {}
2088
+ }));
2089
+ }
2090
+ };
2091
+ _ts_decorate12([
2092
+ (0, import_common12.Get)(),
2093
+ _ts_param11(0, (0, import_common12.Req)()),
2094
+ _ts_param11(1, (0, import_common12.Query)("agent")),
2095
+ _ts_metadata12("design:type", Function),
2096
+ _ts_metadata12("design:paramtypes", [
2097
+ typeof Request === "undefined" ? Object : Request,
2098
+ String
2099
+ ]),
2100
+ _ts_metadata12("design:returntype", Promise)
2101
+ ], ToolsController.prototype, "list", null);
2102
+ ToolsController = _ts_decorate12([
2103
+ (0, import_common12.Controller)("tools"),
2104
+ _ts_param11(0, (0, import_common12.Inject)(import_nestjs_agent_core12.AGENT_ACTOR_RESOLVER)),
2105
+ _ts_param11(1, (0, import_common12.Inject)(import_nestjs_agent_core12.AGENT_DEPS_FACTORY)),
2106
+ _ts_param11(2, (0, import_common12.Inject)(import_nestjs_agent_core12.AGENT_REGISTRY)),
2107
+ _ts_metadata12("design:type", Function),
2108
+ _ts_metadata12("design:paramtypes", [
2109
+ typeof ActorResolver === "undefined" ? Object : ActorResolver,
2110
+ typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
2111
+ typeof import_nestjs_agent_core12.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core12.AgentRegistry
2112
+ ])
2113
+ ], ToolsController);
2114
+
2115
+ // src/discovery/agent-discovery.service.ts
2116
+ var import_nestjs_agent_core13 = require("@dudousxd/nestjs-agent-core");
2117
+ var import_common13 = require("@nestjs/common");
1938
2118
  var import_core = require("@nestjs/core");
1939
2119
 
1940
2120
  // src/decorator/agent.decorator.ts
@@ -1969,7 +2149,7 @@ function SystemPromptContributor() {
1969
2149
  __name(SystemPromptContributor, "SystemPromptContributor");
1970
2150
 
1971
2151
  // src/discovery/agent-discovery.service.ts
1972
- function _ts_decorate12(decorators, target, key, desc) {
2152
+ function _ts_decorate13(decorators, target, key, desc) {
1973
2153
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1974
2154
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1975
2155
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1982,19 +2162,19 @@ function _ts_decorate12(decorators, target, key, desc) {
1982
2162
  }
1983
2163
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1984
2164
  }
1985
- __name(_ts_decorate12, "_ts_decorate");
1986
- function _ts_metadata12(metadataKey, metadataValue) {
2165
+ __name(_ts_decorate13, "_ts_decorate");
2166
+ function _ts_metadata13(metadataKey, metadataValue) {
1987
2167
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1988
2168
  return Reflect.metadata(metadataKey, metadataValue);
1989
2169
  }
1990
2170
  }
1991
- __name(_ts_metadata12, "_ts_metadata");
1992
- function _ts_param11(paramIndex, decorator) {
2171
+ __name(_ts_metadata13, "_ts_metadata");
2172
+ function _ts_param12(paramIndex, decorator) {
1993
2173
  return function(target, key) {
1994
2174
  decorator(target, key, paramIndex);
1995
2175
  };
1996
2176
  }
1997
- __name(_ts_param11, "_ts_param");
2177
+ __name(_ts_param12, "_ts_param");
1998
2178
  var AgentDiscoveryService = class _AgentDiscoveryService {
1999
2179
  static {
2000
2180
  __name(this, "AgentDiscoveryService");
@@ -2003,7 +2183,7 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
2003
2183
  scanner;
2004
2184
  registry;
2005
2185
  contributors;
2006
- logger = new import_common12.Logger(_AgentDiscoveryService.name);
2186
+ logger = new import_common13.Logger(_AgentDiscoveryService.name);
2007
2187
  constructor(discovery, scanner, registry, contributors) {
2008
2188
  this.discovery = discovery;
2009
2189
  this.scanner = scanner;
@@ -2121,22 +2301,22 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
2121
2301
  return (ctx) => candidate.call(instance, ctx);
2122
2302
  }
2123
2303
  };
2124
- AgentDiscoveryService = _ts_decorate12([
2125
- (0, import_common12.Injectable)(),
2126
- _ts_param11(2, (0, import_common12.Inject)(import_nestjs_agent_core12.AGENT_REGISTRY)),
2127
- _ts_param11(3, (0, import_common12.Inject)(import_nestjs_agent_core12.AGENT_PROMPT_CONTRIBUTORS)),
2128
- _ts_metadata12("design:type", Function),
2129
- _ts_metadata12("design:paramtypes", [
2304
+ AgentDiscoveryService = _ts_decorate13([
2305
+ (0, import_common13.Injectable)(),
2306
+ _ts_param12(2, (0, import_common13.Inject)(import_nestjs_agent_core13.AGENT_REGISTRY)),
2307
+ _ts_param12(3, (0, import_common13.Inject)(import_nestjs_agent_core13.AGENT_PROMPT_CONTRIBUTORS)),
2308
+ _ts_metadata13("design:type", Function),
2309
+ _ts_metadata13("design:paramtypes", [
2130
2310
  typeof import_core.DiscoveryService === "undefined" ? Object : import_core.DiscoveryService,
2131
2311
  typeof import_core.MetadataScanner === "undefined" ? Object : import_core.MetadataScanner,
2132
- typeof import_nestjs_agent_core12.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core12.AgentRegistry,
2312
+ typeof import_nestjs_agent_core13.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core13.AgentRegistry,
2133
2313
  Array
2134
2314
  ])
2135
2315
  ], AgentDiscoveryService);
2136
2316
 
2137
2317
  // src/discovery/ai-tool-discovery.service.ts
2138
- var import_nestjs_agent_core13 = require("@dudousxd/nestjs-agent-core");
2139
- var import_common13 = require("@nestjs/common");
2318
+ var import_nestjs_agent_core14 = require("@dudousxd/nestjs-agent-core");
2319
+ var import_common14 = require("@nestjs/common");
2140
2320
  var import_core2 = require("@nestjs/core");
2141
2321
  var import_zod = require("zod");
2142
2322
 
@@ -2185,7 +2365,7 @@ function provideAgentTool(factoryOrTool, inject) {
2185
2365
  __name(provideAgentTool, "provideAgentTool");
2186
2366
 
2187
2367
  // src/discovery/ai-tool-discovery.service.ts
2188
- function _ts_decorate13(decorators, target, key, desc) {
2368
+ function _ts_decorate14(decorators, target, key, desc) {
2189
2369
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2190
2370
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2191
2371
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2198,19 +2378,19 @@ function _ts_decorate13(decorators, target, key, desc) {
2198
2378
  }
2199
2379
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2200
2380
  }
2201
- __name(_ts_decorate13, "_ts_decorate");
2202
- function _ts_metadata13(metadataKey, metadataValue) {
2381
+ __name(_ts_decorate14, "_ts_decorate");
2382
+ function _ts_metadata14(metadataKey, metadataValue) {
2203
2383
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2204
2384
  return Reflect.metadata(metadataKey, metadataValue);
2205
2385
  }
2206
2386
  }
2207
- __name(_ts_metadata13, "_ts_metadata");
2208
- function _ts_param12(paramIndex, decorator) {
2387
+ __name(_ts_metadata14, "_ts_metadata");
2388
+ function _ts_param13(paramIndex, decorator) {
2209
2389
  return function(target, key) {
2210
2390
  decorator(target, key, paramIndex);
2211
2391
  };
2212
2392
  }
2213
- __name(_ts_param12, "_ts_param");
2393
+ __name(_ts_param13, "_ts_param");
2214
2394
  var AiToolDiscoveryService = class _AiToolDiscoveryService {
2215
2395
  static {
2216
2396
  __name(this, "AiToolDiscoveryService");
@@ -2219,7 +2399,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
2219
2399
  registry;
2220
2400
  agents;
2221
2401
  options;
2222
- logger = new import_common13.Logger(_AiToolDiscoveryService.name);
2402
+ logger = new import_common14.Logger(_AiToolDiscoveryService.name);
2223
2403
  constructor(discovery, registry, agents, options) {
2224
2404
  this.discovery = discovery;
2225
2405
  this.registry = registry;
@@ -2264,6 +2444,9 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
2264
2444
  } : {},
2265
2445
  ...meta.enabled !== void 0 ? {
2266
2446
  enabled: meta.enabled
2447
+ } : {},
2448
+ ...meta.presentation !== void 0 ? {
2449
+ presentation: meta.presentation
2267
2450
  } : {}
2268
2451
  }, {
2269
2452
  execute: /* @__PURE__ */ __name((input, ctx) => instance.execute(input, ctx), "execute"),
@@ -2287,7 +2470,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
2287
2470
  let delegates = 0;
2288
2471
  for (const definition of this.agents.list()) {
2289
2472
  for (const edge of definition.delegatesTo ?? []) {
2290
- const { agent: target, detached } = (0, import_nestjs_agent_core13.normalizeDelegation)(edge);
2473
+ const { agent: target, detached } = (0, import_nestjs_agent_core14.normalizeDelegation)(edge);
2291
2474
  const targetDefinition = this.agents.get(target);
2292
2475
  if (targetDefinition === void 0) {
2293
2476
  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.`);
@@ -2337,13 +2520,13 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
2337
2520
  return true;
2338
2521
  }
2339
2522
  };
2340
- AiToolDiscoveryService = _ts_decorate13([
2341
- (0, import_common13.Injectable)(),
2342
- _ts_param12(1, (0, import_common13.Inject)(import_nestjs_agent_core13.AGENT_TOOL_REGISTRY)),
2343
- _ts_param12(2, (0, import_common13.Inject)(import_nestjs_agent_core13.AGENT_REGISTRY)),
2344
- _ts_param12(3, (0, import_common13.Inject)(import_nestjs_agent_core13.AGENT_OPTIONS)),
2345
- _ts_metadata13("design:type", Function),
2346
- _ts_metadata13("design:paramtypes", [
2523
+ AiToolDiscoveryService = _ts_decorate14([
2524
+ (0, import_common14.Injectable)(),
2525
+ _ts_param13(1, (0, import_common14.Inject)(import_nestjs_agent_core14.AGENT_TOOL_REGISTRY)),
2526
+ _ts_param13(2, (0, import_common14.Inject)(import_nestjs_agent_core14.AGENT_REGISTRY)),
2527
+ _ts_param13(3, (0, import_common14.Inject)(import_nestjs_agent_core14.AGENT_OPTIONS)),
2528
+ _ts_metadata14("design:type", Function),
2529
+ _ts_metadata14("design:paramtypes", [
2347
2530
  typeof import_core2.DiscoveryService === "undefined" ? Object : import_core2.DiscoveryService,
2348
2531
  typeof ToolRegistry === "undefined" ? Object : ToolRegistry,
2349
2532
  typeof AgentRegistry === "undefined" ? Object : AgentRegistry,
@@ -2352,13 +2535,13 @@ AiToolDiscoveryService = _ts_decorate13([
2352
2535
  ], AiToolDiscoveryService);
2353
2536
 
2354
2537
  // src/discovery/skill-discovery.service.ts
2355
- var import_nestjs_agent_core15 = require("@dudousxd/nestjs-agent-core");
2356
- var import_common14 = require("@nestjs/common");
2538
+ var import_nestjs_agent_core16 = require("@dudousxd/nestjs-agent-core");
2539
+ var import_common15 = require("@nestjs/common");
2357
2540
  var import_core3 = require("@nestjs/core");
2358
2541
 
2359
2542
  // src/decorator/skill.decorator.ts
2360
2543
  var import_reflect_metadata4 = require("reflect-metadata");
2361
- var import_nestjs_agent_core14 = require("@dudousxd/nestjs-agent-core");
2544
+ var import_nestjs_agent_core15 = require("@dudousxd/nestjs-agent-core");
2362
2545
  var SKILL_METADATA = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:skill-metadata");
2363
2546
  function Skill(options) {
2364
2547
  return (target) => {
@@ -2371,12 +2554,12 @@ function readSkillMetadata(target) {
2371
2554
  }
2372
2555
  __name(readSkillMetadata, "readSkillMetadata");
2373
2556
  function skillScope(options) {
2374
- return options.scope ?? import_nestjs_agent_core14.GLOBAL_SCOPE;
2557
+ return options.scope ?? import_nestjs_agent_core15.GLOBAL_SCOPE;
2375
2558
  }
2376
2559
  __name(skillScope, "skillScope");
2377
2560
 
2378
2561
  // src/discovery/skill-discovery.service.ts
2379
- function _ts_decorate14(decorators, target, key, desc) {
2562
+ function _ts_decorate15(decorators, target, key, desc) {
2380
2563
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2381
2564
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2382
2565
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2389,26 +2572,26 @@ function _ts_decorate14(decorators, target, key, desc) {
2389
2572
  }
2390
2573
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2391
2574
  }
2392
- __name(_ts_decorate14, "_ts_decorate");
2393
- function _ts_metadata14(metadataKey, metadataValue) {
2575
+ __name(_ts_decorate15, "_ts_decorate");
2576
+ function _ts_metadata15(metadataKey, metadataValue) {
2394
2577
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2395
2578
  return Reflect.metadata(metadataKey, metadataValue);
2396
2579
  }
2397
2580
  }
2398
- __name(_ts_metadata14, "_ts_metadata");
2399
- function _ts_param13(paramIndex, decorator) {
2581
+ __name(_ts_metadata15, "_ts_metadata");
2582
+ function _ts_param14(paramIndex, decorator) {
2400
2583
  return function(target, key) {
2401
2584
  decorator(target, key, paramIndex);
2402
2585
  };
2403
2586
  }
2404
- __name(_ts_param13, "_ts_param");
2587
+ __name(_ts_param14, "_ts_param");
2405
2588
  var SkillDiscoveryService = class _SkillDiscoveryService {
2406
2589
  static {
2407
2590
  __name(this, "SkillDiscoveryService");
2408
2591
  }
2409
2592
  discovery;
2410
2593
  declared;
2411
- logger = new import_common14.Logger(_SkillDiscoveryService.name);
2594
+ logger = new import_common15.Logger(_SkillDiscoveryService.name);
2412
2595
  constructor(discovery, declared) {
2413
2596
  this.discovery = discovery;
2414
2597
  this.declared = declared;
@@ -2445,18 +2628,18 @@ var SkillDiscoveryService = class _SkillDiscoveryService {
2445
2628
  return flat === void 0 ? void 0 : () => flat;
2446
2629
  }
2447
2630
  };
2448
- SkillDiscoveryService = _ts_decorate14([
2449
- (0, import_common14.Injectable)(),
2450
- _ts_param13(1, (0, import_common14.Inject)(import_nestjs_agent_core15.AGENT_SKILL_SOURCES)),
2451
- _ts_metadata14("design:type", Function),
2452
- _ts_metadata14("design:paramtypes", [
2631
+ SkillDiscoveryService = _ts_decorate15([
2632
+ (0, import_common15.Injectable)(),
2633
+ _ts_param14(1, (0, import_common15.Inject)(import_nestjs_agent_core16.AGENT_SKILL_SOURCES)),
2634
+ _ts_metadata15("design:type", Function),
2635
+ _ts_metadata15("design:paramtypes", [
2453
2636
  typeof import_core3.DiscoveryService === "undefined" ? Object : import_core3.DiscoveryService,
2454
2637
  Array
2455
2638
  ])
2456
2639
  ], SkillDiscoveryService);
2457
2640
 
2458
2641
  // src/in-process-sink.ts
2459
- var import_nestjs_agent_core16 = require("@dudousxd/nestjs-agent-core");
2642
+ var import_nestjs_agent_core17 = require("@dudousxd/nestjs-agent-core");
2460
2643
  var InProcessTokenStreamSink = class {
2461
2644
  static {
2462
2645
  __name(this, "InProcessTokenStreamSink");
@@ -2511,7 +2694,7 @@ var InProcessTokenStreamSink = class {
2511
2694
  }
2512
2695
  if (buf.ended) {
2513
2696
  if (buf.failure !== void 0) {
2514
- throw new import_nestjs_agent_core16.AgentStreamError(buf.failure);
2697
+ throw new import_nestjs_agent_core17.AgentStreamError(buf.failure);
2515
2698
  }
2516
2699
  return;
2517
2700
  }
@@ -2547,9 +2730,9 @@ var LedgerQuotaStore = class {
2547
2730
  };
2548
2731
 
2549
2732
  // src/runner/inline-agent-runner.ts
2550
- var import_nestjs_agent_core17 = require("@dudousxd/nestjs-agent-core");
2551
- var import_common15 = require("@nestjs/common");
2552
- function _ts_decorate15(decorators, target, key, desc) {
2733
+ var import_nestjs_agent_core18 = require("@dudousxd/nestjs-agent-core");
2734
+ var import_common16 = require("@nestjs/common");
2735
+ function _ts_decorate16(decorators, target, key, desc) {
2553
2736
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2554
2737
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2555
2738
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2562,26 +2745,26 @@ function _ts_decorate15(decorators, target, key, desc) {
2562
2745
  }
2563
2746
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2564
2747
  }
2565
- __name(_ts_decorate15, "_ts_decorate");
2566
- function _ts_metadata15(metadataKey, metadataValue) {
2748
+ __name(_ts_decorate16, "_ts_decorate");
2749
+ function _ts_metadata16(metadataKey, metadataValue) {
2567
2750
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2568
2751
  return Reflect.metadata(metadataKey, metadataValue);
2569
2752
  }
2570
2753
  }
2571
- __name(_ts_metadata15, "_ts_metadata");
2572
- function _ts_param14(paramIndex, decorator) {
2754
+ __name(_ts_metadata16, "_ts_metadata");
2755
+ function _ts_param15(paramIndex, decorator) {
2573
2756
  return function(target, key) {
2574
2757
  decorator(target, key, paramIndex);
2575
2758
  };
2576
2759
  }
2577
- __name(_ts_param14, "_ts_param");
2760
+ __name(_ts_param15, "_ts_param");
2578
2761
  var InlineAgentRunner = class _InlineAgentRunner {
2579
2762
  static {
2580
2763
  __name(this, "InlineAgentRunner");
2581
2764
  }
2582
2765
  factory;
2583
2766
  store;
2584
- logger = new import_common15.Logger(_InlineAgentRunner.name);
2767
+ logger = new import_common16.Logger(_InlineAgentRunner.name);
2585
2768
  pending = /* @__PURE__ */ new Map();
2586
2769
  /**
2587
2770
  * Runs someone has asked to stop. In-process, like `pending`, and for the same reason: this runner
@@ -2610,18 +2793,18 @@ var InlineAgentRunner = class _InlineAgentRunner {
2610
2793
  ] : []
2611
2794
  ]
2612
2795
  });
2613
- void (0, import_nestjs_agent_core17.runAgentLoop)({
2796
+ void (0, import_nestjs_agent_core18.runAgentLoop)({
2614
2797
  ...deps,
2615
2798
  day
2616
2799
  }, input, hooks).then(() => this.store.setActiveStream(input.threadId, null)).catch(async (error) => {
2617
- if (error instanceof import_nestjs_agent_core17.RunCancelledError) {
2800
+ if (error instanceof import_nestjs_agent_core18.RunCancelledError) {
2618
2801
  await this.settleCancelled(runId, input.threadId, deps);
2619
2802
  return;
2620
2803
  }
2621
2804
  const message = error instanceof Error ? error.message : String(error);
2622
- const code = (0, import_nestjs_agent_core17.agentFailureCode)(error);
2805
+ const code = (0, import_nestjs_agent_core18.agentFailureCode)(error);
2623
2806
  this.logger.error(`agent run ${runId} failed (${code}): ${message}`);
2624
- (0, import_nestjs_agent_core17.publishAgentRunFailed)({
2807
+ (0, import_nestjs_agent_core18.publishAgentRunFailed)({
2625
2808
  runId,
2626
2809
  code,
2627
2810
  message
@@ -2670,7 +2853,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
2670
2853
  for (const [key, waiter] of this.pending) {
2671
2854
  if (key.startsWith(`${runId}:`)) {
2672
2855
  this.pending.delete(key);
2673
- waiter.reject(new import_nestjs_agent_core17.RunCancelledError());
2856
+ waiter.reject(new import_nestjs_agent_core18.RunCancelledError());
2674
2857
  }
2675
2858
  }
2676
2859
  await Promise.resolve();
@@ -2685,7 +2868,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
2685
2868
  this.logger.log(`agent run ${runId} cancelled`);
2686
2869
  await this.store.setActiveStream(threadId, null);
2687
2870
  const writer = await deps.sink.open(runId);
2688
- await writer.write((0, import_nestjs_agent_core17.encodeStreamEvent)({
2871
+ await writer.write((0, import_nestjs_agent_core18.encodeStreamEvent)({
2689
2872
  kind: "cancelled"
2690
2873
  }));
2691
2874
  await writer.end();
@@ -2700,6 +2883,36 @@ var InlineAgentRunner = class _InlineAgentRunner {
2700
2883
  * shape it is delivering — the loop asked for one and only ever gets what the caller sent. A
2701
2884
  * cancel settles the wait too, by rejecting it.
2702
2885
  */
2886
+ /**
2887
+ * {@link park} for an approval, bounded by the policy's time to live when it has one: the timer
2888
+ * settles the wait as `expired` — the same Decision the durable runner builds from its signal
2889
+ * timeout — and a decision that arrives first disarms it.
2890
+ */
2891
+ parkApproval(runId, toolCallId2, timeoutMs) {
2892
+ const waiting = this.park(runId, toolCallId2);
2893
+ if (timeoutMs === void 0) {
2894
+ return waiting;
2895
+ }
2896
+ const key = `${runId}:${toolCallId2}`;
2897
+ let timer;
2898
+ const lapse = new Promise((resolve) => {
2899
+ timer = setTimeout(() => {
2900
+ const entry = this.pending.get(key);
2901
+ if (entry !== void 0) {
2902
+ this.pending.delete(key);
2903
+ resolve({
2904
+ approved: false,
2905
+ expired: true
2906
+ });
2907
+ }
2908
+ }, timeoutMs);
2909
+ timer.unref?.();
2910
+ });
2911
+ return Promise.race([
2912
+ waiting,
2913
+ lapse
2914
+ ]).finally(() => clearTimeout(timer));
2915
+ }
2703
2916
  park(runId, toolCallId2) {
2704
2917
  return new Promise((resolve, reject) => {
2705
2918
  this.pending.set(`${runId}:${toolCallId2}`, {
@@ -2713,10 +2926,10 @@ var InlineAgentRunner = class _InlineAgentRunner {
2713
2926
  return {
2714
2927
  runId,
2715
2928
  openSink: /* @__PURE__ */ __name(() => deps.sink.open(runId), "openSink"),
2716
- awaitApproval: /* @__PURE__ */ __name((call) => this.park(runId, call.id), "awaitApproval"),
2929
+ awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
2717
2930
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
2718
2931
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
2719
- parallel: import_nestjs_agent_core17.settleAll,
2932
+ parallel: import_nestjs_agent_core18.settleAll,
2720
2933
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
2721
2934
  runAgent: /* @__PURE__ */ __name((agentName, task) => this.runNested({
2722
2935
  agentName,
@@ -2764,10 +2977,10 @@ var InlineAgentRunner = class _InlineAgentRunner {
2764
2977
  const hooks = {
2765
2978
  runId,
2766
2979
  openSink: /* @__PURE__ */ __name(() => deps.sink.open(runId), "openSink"),
2767
- awaitApproval: /* @__PURE__ */ __name((call) => this.park(runId, call.id), "awaitApproval"),
2980
+ awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
2768
2981
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
2769
2982
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
2770
- parallel: import_nestjs_agent_core17.settleAll,
2983
+ parallel: import_nestjs_agent_core18.settleAll,
2771
2984
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
2772
2985
  runAgent: /* @__PURE__ */ __name((childName, childTask) => this.runNested({
2773
2986
  agentName: childName,
@@ -2800,7 +3013,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
2800
3013
  }
2801
3014
  }), "startAgent")
2802
3015
  };
2803
- void (0, import_nestjs_agent_core17.runAgentLoop)({
3016
+ void (0, import_nestjs_agent_core18.runAgentLoop)({
2804
3017
  ...deps,
2805
3018
  day
2806
3019
  }, {
@@ -2814,13 +3027,13 @@ var InlineAgentRunner = class _InlineAgentRunner {
2814
3027
  parentRunId,
2815
3028
  deliverTo
2816
3029
  }, hooks).catch(async (error) => {
2817
- const cancelled = error instanceof import_nestjs_agent_core17.RunCancelledError;
3030
+ const cancelled = error instanceof import_nestjs_agent_core18.RunCancelledError;
2818
3031
  const message = error instanceof Error ? error.message : String(error);
2819
3032
  if (!cancelled) {
2820
3033
  this.logger.error(`detached agent run ${runId} failed: ${message}`);
2821
- (0, import_nestjs_agent_core17.publishAgentRunFailed)({
3034
+ (0, import_nestjs_agent_core18.publishAgentRunFailed)({
2822
3035
  runId,
2823
- code: (0, import_nestjs_agent_core17.agentFailureCode)(error),
3036
+ code: (0, import_nestjs_agent_core18.agentFailureCode)(error),
2824
3037
  message
2825
3038
  });
2826
3039
  }
@@ -2828,11 +3041,11 @@ var InlineAgentRunner = class _InlineAgentRunner {
2828
3041
  runId,
2829
3042
  status: cancelled ? "cancelled" : "failed",
2830
3043
  ...cancelled ? {} : {
2831
- errorCode: (0, import_nestjs_agent_core17.agentFailureCode)(error),
3044
+ errorCode: (0, import_nestjs_agent_core18.agentFailureCode)(error),
2832
3045
  errorMessage: message
2833
3046
  }
2834
3047
  });
2835
- await (0, import_nestjs_agent_core17.settleUnsettledDelegation)({
3048
+ await (0, import_nestjs_agent_core18.settleUnsettledDelegation)({
2836
3049
  store: this.store,
2837
3050
  delivery: deliverTo,
2838
3051
  agent: agentName,
@@ -2868,10 +3081,10 @@ var InlineAgentRunner = class _InlineAgentRunner {
2868
3081
  runId,
2869
3082
  // Forward into the top-level stream; the top-level run owns end/fail on that shared sink.
2870
3083
  openSink: /* @__PURE__ */ __name(async () => childSinkWriter(await deps.sink.open(sinkRunId)), "openSink"),
2871
- awaitApproval: /* @__PURE__ */ __name((call) => this.park(runId, call.id), "awaitApproval"),
3084
+ awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
2872
3085
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
2873
3086
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
2874
- parallel: import_nestjs_agent_core17.settleAll,
3087
+ parallel: import_nestjs_agent_core18.settleAll,
2875
3088
  // A child stops when it is cancelled OR when the run a human is actually watching is: the
2876
3089
  // canceller names the top-level run, which is the only id that ever left the server.
2877
3090
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId) || this.cancelled.has(sinkRunId), "cancelled"),
@@ -2906,7 +3119,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
2906
3119
  }), "startAgent")
2907
3120
  };
2908
3121
  try {
2909
- return await (0, import_nestjs_agent_core17.runAgentLoop)({
3122
+ return await (0, import_nestjs_agent_core18.runAgentLoop)({
2910
3123
  ...deps,
2911
3124
  day
2912
3125
  }, {
@@ -2925,19 +3138,19 @@ var InlineAgentRunner = class _InlineAgentRunner {
2925
3138
  }
2926
3139
  }
2927
3140
  };
2928
- InlineAgentRunner = _ts_decorate15([
2929
- (0, import_common15.Injectable)(),
2930
- _ts_param14(0, (0, import_common15.Inject)(import_nestjs_agent_core17.AGENT_DEPS_FACTORY)),
2931
- _ts_param14(1, (0, import_common15.Inject)(import_nestjs_agent_core17.AGENT_STORE)),
2932
- _ts_metadata15("design:type", Function),
2933
- _ts_metadata15("design:paramtypes", [
3141
+ InlineAgentRunner = _ts_decorate16([
3142
+ (0, import_common16.Injectable)(),
3143
+ _ts_param15(0, (0, import_common16.Inject)(import_nestjs_agent_core18.AGENT_DEPS_FACTORY)),
3144
+ _ts_param15(1, (0, import_common16.Inject)(import_nestjs_agent_core18.AGENT_STORE)),
3145
+ _ts_metadata16("design:type", Function),
3146
+ _ts_metadata16("design:paramtypes", [
2934
3147
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
2935
3148
  typeof AgentStore === "undefined" ? Object : AgentStore
2936
3149
  ])
2937
3150
  ], InlineAgentRunner);
2938
3151
 
2939
3152
  // src/skills-config.ts
2940
- var import_nestjs_agent_core18 = require("@dudousxd/nestjs-agent-core");
3153
+ var import_nestjs_agent_core19 = require("@dudousxd/nestjs-agent-core");
2941
3154
  function declaredSkillProvider(declared) {
2942
3155
  return {
2943
3156
  list: /* @__PURE__ */ __name(({ scopes }) => declared.filter((skill) => scopes.includes(skill.scope)).map(({ name, description, scope }) => ({
@@ -2963,7 +3176,7 @@ function resolveSkillsConfig(options, declared) {
2963
3176
  declaredSkillProvider(declared)
2964
3177
  ];
2965
3178
  return {
2966
- provider: providers.length === 1 ? providers[0] : (0, import_nestjs_agent_core18.compositeSkillProvider)(providers),
3179
+ provider: providers.length === 1 ? providers[0] : (0, import_nestjs_agent_core19.compositeSkillProvider)(providers),
2967
3180
  ...options.scopes !== void 0 ? {
2968
3181
  scopes: options.scopes
2969
3182
  } : {},
@@ -2975,7 +3188,7 @@ function resolveSkillsConfig(options, declared) {
2975
3188
  __name(resolveSkillsConfig, "resolveSkillsConfig");
2976
3189
 
2977
3190
  // src/agent.module.ts
2978
- function _ts_decorate16(decorators, target, key, desc) {
3191
+ function _ts_decorate17(decorators, target, key, desc) {
2979
3192
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2980
3193
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2981
3194
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2988,92 +3201,92 @@ function _ts_decorate16(decorators, target, key, desc) {
2988
3201
  }
2989
3202
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2990
3203
  }
2991
- __name(_ts_decorate16, "_ts_decorate");
3204
+ __name(_ts_decorate17, "_ts_decorate");
2992
3205
  var DEFAULT_PATH = "agent";
2993
3206
  function sharedProviders(durable, includeStore) {
2994
3207
  const providers = [
2995
3208
  {
2996
- provide: import_nestjs_agent_core19.AGENT_TOOL_REGISTRY,
2997
- useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core19.ToolRegistry(), "useFactory")
3209
+ provide: import_nestjs_agent_core20.AGENT_TOOL_REGISTRY,
3210
+ useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core20.ToolRegistry(), "useFactory")
2998
3211
  },
2999
3212
  // Starts empty; AgentDiscoveryService populates it from `@Agent`-decorated providers at boot.
3000
3213
  {
3001
- provide: import_nestjs_agent_core19.AGENT_REGISTRY,
3002
- useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core19.AgentRegistry(), "useFactory")
3214
+ provide: import_nestjs_agent_core20.AGENT_REGISTRY,
3215
+ useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core20.AgentRegistry(), "useFactory")
3003
3216
  },
3004
3217
  // A shared, mutable list AgentDiscoveryService fills with `@SystemPromptContributor()` methods.
3005
3218
  {
3006
- provide: import_nestjs_agent_core19.AGENT_PROMPT_CONTRIBUTORS,
3219
+ provide: import_nestjs_agent_core20.AGENT_PROMPT_CONTRIBUTORS,
3007
3220
  useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
3008
3221
  },
3009
3222
  // Likewise for `@Skill`-decorated providers — filled by SkillDiscoveryService at onModuleInit,
3010
3223
  // read lazily by the AGENT_SKILLS provider below (which DI builds before discovery has run).
3011
3224
  {
3012
- provide: import_nestjs_agent_core19.AGENT_SKILL_SOURCES,
3225
+ provide: import_nestjs_agent_core20.AGENT_SKILL_SOURCES,
3013
3226
  useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
3014
3227
  },
3015
3228
  {
3016
3229
  // One resolution, shared by the loop's deps and the listing endpoint: a second one would
3017
3230
  // drift, and a user would be offered a skill the agent cannot reach. `undefined` when the
3018
3231
  // host configured none — which is what keeps the turn's checkpoint sequence unchanged.
3019
- provide: import_nestjs_agent_core19.AGENT_SKILLS,
3232
+ provide: import_nestjs_agent_core20.AGENT_SKILLS,
3020
3233
  useFactory: /* @__PURE__ */ __name((options, declared) => resolveSkillsConfig(options.skills, declared), "useFactory"),
3021
3234
  inject: [
3022
- import_nestjs_agent_core19.AGENT_OPTIONS,
3023
- import_nestjs_agent_core19.AGENT_SKILL_SOURCES
3235
+ import_nestjs_agent_core20.AGENT_OPTIONS,
3236
+ import_nestjs_agent_core20.AGENT_SKILL_SOURCES
3024
3237
  ]
3025
3238
  },
3026
3239
  {
3027
3240
  // One resolution, shared by the loop's deps and the read-back endpoint: a person has to be
3028
3241
  // shown what the model was shown, and two resolutions would eventually disagree about that.
3029
- provide: import_nestjs_agent_core19.AGENT_MEMORY,
3242
+ provide: import_nestjs_agent_core20.AGENT_MEMORY,
3030
3243
  useFactory: /* @__PURE__ */ __name((options) => options.memory, "useFactory"),
3031
3244
  inject: [
3032
- import_nestjs_agent_core19.AGENT_OPTIONS
3245
+ import_nestjs_agent_core20.AGENT_OPTIONS
3033
3246
  ]
3034
3247
  },
3035
3248
  {
3036
- provide: import_nestjs_agent_core19.AGENT_SINK,
3249
+ provide: import_nestjs_agent_core20.AGENT_SINK,
3037
3250
  useFactory: /* @__PURE__ */ __name((options) => options.sink ?? new InProcessTokenStreamSink(), "useFactory"),
3038
3251
  inject: [
3039
- import_nestjs_agent_core19.AGENT_OPTIONS
3252
+ import_nestjs_agent_core20.AGENT_OPTIONS
3040
3253
  ]
3041
3254
  },
3042
3255
  {
3043
- provide: import_nestjs_agent_core19.AGENT_ROLES_POLICY,
3044
- useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? new import_nestjs_agent_core19.DefaultRolesPolicy(options.defaultRoles), "useFactory"),
3256
+ provide: import_nestjs_agent_core20.AGENT_ROLES_POLICY,
3257
+ useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? new import_nestjs_agent_core20.DefaultRolesPolicy(options.defaultRoles), "useFactory"),
3045
3258
  inject: [
3046
- import_nestjs_agent_core19.AGENT_OPTIONS
3259
+ import_nestjs_agent_core20.AGENT_OPTIONS
3047
3260
  ]
3048
3261
  },
3049
3262
  {
3050
- provide: import_nestjs_agent_core19.AGENT_ACTOR_RESOLVER,
3263
+ provide: import_nestjs_agent_core20.AGENT_ACTOR_RESOLVER,
3051
3264
  useFactory: /* @__PURE__ */ __name((options) => options.actorResolver, "useFactory"),
3052
3265
  inject: [
3053
- import_nestjs_agent_core19.AGENT_OPTIONS
3266
+ import_nestjs_agent_core20.AGENT_OPTIONS
3054
3267
  ]
3055
3268
  },
3056
3269
  {
3057
- provide: import_nestjs_agent_core19.AGENT_MODEL,
3270
+ provide: import_nestjs_agent_core20.AGENT_MODEL,
3058
3271
  useFactory: /* @__PURE__ */ __name((o) => o.model, "useFactory"),
3059
3272
  inject: [
3060
- import_nestjs_agent_core19.AGENT_OPTIONS
3273
+ import_nestjs_agent_core20.AGENT_OPTIONS
3061
3274
  ]
3062
3275
  },
3063
3276
  {
3064
3277
  // An explicit `quota` wins; otherwise `quotaLimitTokens` binds the built-in ledger-backed
3065
3278
  // store; otherwise quotas are off (undefined). The ledger store reads the same usage rows
3066
3279
  // the loop already writes, so enforcement needs no extra shared state across replicas.
3067
- provide: import_nestjs_agent_core19.AGENT_QUOTA_STORE,
3280
+ provide: import_nestjs_agent_core20.AGENT_QUOTA_STORE,
3068
3281
  useFactory: /* @__PURE__ */ __name((o, store) => o.quota ?? (o.quotaLimitTokens !== void 0 ? new LedgerQuotaStore(store, o.quotaLimitTokens) : void 0), "useFactory"),
3069
3282
  inject: [
3070
- import_nestjs_agent_core19.AGENT_OPTIONS,
3071
- import_nestjs_agent_core19.AGENT_STORE
3283
+ import_nestjs_agent_core20.AGENT_OPTIONS,
3284
+ import_nestjs_agent_core20.AGENT_STORE
3072
3285
  ]
3073
3286
  },
3074
3287
  AgentDepsFactory2,
3075
3288
  {
3076
- provide: import_nestjs_agent_core19.AGENT_DEPS_FACTORY,
3289
+ provide: import_nestjs_agent_core20.AGENT_DEPS_FACTORY,
3077
3290
  useExisting: AgentDepsFactory2
3078
3291
  },
3079
3292
  // Populates the registry + contributors (onModuleInit) BEFORE AiToolDiscoveryService synthesizes
@@ -3087,22 +3300,22 @@ function sharedProviders(durable, includeStore) {
3087
3300
  // through AgentService.signalToolCall, which reaches whichever AGENT_RUNNER is bound above.
3088
3301
  AgentApprovalPortAdapter,
3089
3302
  {
3090
- provide: import_nestjs_agent_core19.AGENT_APPROVAL_PORT,
3303
+ provide: import_nestjs_agent_core20.AGENT_APPROVAL_PORT,
3091
3304
  useExisting: AgentApprovalPortAdapter
3092
3305
  }
3093
3306
  ];
3094
3307
  if (includeStore) {
3095
3308
  providers.push({
3096
- provide: import_nestjs_agent_core19.AGENT_STORE,
3309
+ provide: import_nestjs_agent_core20.AGENT_STORE,
3097
3310
  useFactory: /* @__PURE__ */ __name((o) => o.store, "useFactory"),
3098
3311
  inject: [
3099
- import_nestjs_agent_core19.AGENT_OPTIONS
3312
+ import_nestjs_agent_core20.AGENT_OPTIONS
3100
3313
  ]
3101
3314
  });
3102
3315
  }
3103
3316
  if (durable) {
3104
3317
  providers.push({
3105
- provide: import_nestjs_agent_core19.AGENT_RUNNER,
3318
+ provide: import_nestjs_agent_core20.AGENT_RUNNER,
3106
3319
  useFactory: /* @__PURE__ */ __name((durableRunner) => {
3107
3320
  if (durableRunner === void 0) {
3108
3321
  throw new Error("AgentModule.forRoot({ durable: true }) requires importing AgentDurableModule from '@dudousxd/nestjs-agent/durable' (alongside a configured DurableModule). It was not found.");
@@ -3111,14 +3324,14 @@ function sharedProviders(durable, includeStore) {
3111
3324
  }, "useFactory"),
3112
3325
  inject: [
3113
3326
  {
3114
- token: import_nestjs_agent_core19.AGENT_DURABLE_RUNNER,
3327
+ token: import_nestjs_agent_core20.AGENT_DURABLE_RUNNER,
3115
3328
  optional: true
3116
3329
  }
3117
3330
  ]
3118
3331
  });
3119
3332
  } else {
3120
3333
  providers.push({
3121
- provide: import_nestjs_agent_core19.AGENT_RUNNER,
3334
+ provide: import_nestjs_agent_core20.AGENT_RUNNER,
3122
3335
  useExisting: InlineAgentRunner
3123
3336
  });
3124
3337
  }
@@ -3127,25 +3340,25 @@ function sharedProviders(durable, includeStore) {
3127
3340
  __name(sharedProviders, "sharedProviders");
3128
3341
  function exportsFor(includeStore) {
3129
3342
  return [
3130
- import_nestjs_agent_core19.AGENT_OPTIONS,
3131
- import_nestjs_agent_core19.AGENT_TOOL_REGISTRY,
3132
- import_nestjs_agent_core19.AGENT_REGISTRY,
3133
- import_nestjs_agent_core19.AGENT_SINK,
3134
- import_nestjs_agent_core19.AGENT_ROLES_POLICY,
3135
- import_nestjs_agent_core19.AGENT_ACTOR_RESOLVER,
3136
- import_nestjs_agent_core19.AGENT_MODEL,
3343
+ import_nestjs_agent_core20.AGENT_OPTIONS,
3344
+ import_nestjs_agent_core20.AGENT_TOOL_REGISTRY,
3345
+ import_nestjs_agent_core20.AGENT_REGISTRY,
3346
+ import_nestjs_agent_core20.AGENT_SINK,
3347
+ import_nestjs_agent_core20.AGENT_ROLES_POLICY,
3348
+ import_nestjs_agent_core20.AGENT_ACTOR_RESOLVER,
3349
+ import_nestjs_agent_core20.AGENT_MODEL,
3137
3350
  ...includeStore ? [
3138
- import_nestjs_agent_core19.AGENT_STORE
3351
+ import_nestjs_agent_core20.AGENT_STORE
3139
3352
  ] : [],
3140
- import_nestjs_agent_core19.AGENT_QUOTA_STORE,
3141
- import_nestjs_agent_core19.AGENT_PROMPT_CONTRIBUTORS,
3142
- import_nestjs_agent_core19.AGENT_SKILLS,
3143
- import_nestjs_agent_core19.AGENT_MEMORY,
3144
- import_nestjs_agent_core19.AGENT_DEPS_FACTORY,
3353
+ import_nestjs_agent_core20.AGENT_QUOTA_STORE,
3354
+ import_nestjs_agent_core20.AGENT_PROMPT_CONTRIBUTORS,
3355
+ import_nestjs_agent_core20.AGENT_SKILLS,
3356
+ import_nestjs_agent_core20.AGENT_MEMORY,
3357
+ import_nestjs_agent_core20.AGENT_DEPS_FACTORY,
3145
3358
  AgentDepsFactory2,
3146
3359
  AgentService,
3147
3360
  InlineAgentRunner,
3148
- import_nestjs_agent_core19.AGENT_APPROVAL_PORT
3361
+ import_nestjs_agent_core20.AGENT_APPROVAL_PORT
3149
3362
  ];
3150
3363
  }
3151
3364
  __name(exportsFor, "exportsFor");
@@ -3156,7 +3369,8 @@ var BASE_CONTROLLERS = [
3156
3369
  QuotaController,
3157
3370
  AgentsController,
3158
3371
  SkillsController,
3159
- MemoriesController
3372
+ MemoriesController,
3373
+ ToolsController
3160
3374
  ];
3161
3375
  var GUARDABLE_CONTROLLERS = [
3162
3376
  ...BASE_CONTROLLERS,
@@ -3214,7 +3428,7 @@ var AgentModule = class _AgentModule {
3214
3428
  controllers: controllersForSurface(options.surface, options.attachments?.upload === true),
3215
3429
  providers: [
3216
3430
  {
3217
- provide: import_nestjs_agent_core19.AGENT_OPTIONS,
3431
+ provide: import_nestjs_agent_core20.AGENT_OPTIONS,
3218
3432
  useValue: options
3219
3433
  },
3220
3434
  ...sharedProviders(options.durable ?? false, includeStore),
@@ -3238,7 +3452,7 @@ var AgentModule = class _AgentModule {
3238
3452
  controllers: controllersForSurface(options.surface, options.attachmentsUpload === true),
3239
3453
  providers: [
3240
3454
  {
3241
- provide: import_nestjs_agent_core19.AGENT_OPTIONS,
3455
+ provide: import_nestjs_agent_core20.AGENT_OPTIONS,
3242
3456
  // Stamp the STATIC wiring flags onto the factory result: `durable`/`surface` are
3243
3457
  // authoritative on the async config object (they decided the actual wiring above), and
3244
3458
  // the durable module reads `durable` back off AGENT_OPTIONS. `surface` isn't read back by
@@ -3259,13 +3473,13 @@ var AgentModule = class _AgentModule {
3259
3473
  };
3260
3474
  }
3261
3475
  };
3262
- AgentModule = _ts_decorate16([
3263
- (0, import_common16.Global)(),
3264
- (0, import_common16.Module)({})
3476
+ AgentModule = _ts_decorate17([
3477
+ (0, import_common17.Global)(),
3478
+ (0, import_common17.Module)({})
3265
3479
  ], AgentModule);
3266
3480
 
3267
3481
  // src/resolver/header-actor-resolver.ts
3268
- var import_common17 = require("@nestjs/common");
3482
+ var import_common18 = require("@nestjs/common");
3269
3483
  function readHeader(req, name) {
3270
3484
  if (typeof req !== "object" || req === null || !("headers" in req)) return void 0;
3271
3485
  const { headers } = req;
@@ -3281,7 +3495,7 @@ var HeaderActorResolver = class {
3281
3495
  resolve(req) {
3282
3496
  const id = readHeader(req, "x-actor-id");
3283
3497
  if (id === void 0 || id.length === 0) {
3284
- throw new import_common17.UnauthorizedException("HeaderActorResolver: missing x-actor-id header. No default actor is fabricated. Send x-actor-id from a trusted gateway, or configure AgentModule.forRoot({ actorResolver }) with a resolver that reads your authenticated principal.");
3498
+ throw new import_common18.UnauthorizedException("HeaderActorResolver: missing x-actor-id header. No default actor is fabricated. Send x-actor-id from a trusted gateway, or configure AgentModule.forRoot({ actorResolver }) with a resolver that reads your authenticated principal.");
3285
3499
  }
3286
3500
  const roles = (readHeader(req, "x-actor-role") ?? "").split(",").map((role) => role.trim()).filter((role) => role.length > 0);
3287
3501
  const tenantRef = readHeader(req, "x-tenant-ref");
@@ -3327,6 +3541,7 @@ __reExport(index_exports, require("@dudousxd/nestjs-agent-core"), module.exports
3327
3541
  SkillsController,
3328
3542
  SystemPrompt,
3329
3543
  SystemPromptContributor,
3544
+ ToolsController,
3330
3545
  declaredSkillProvider,
3331
3546
  delegateToolName,
3332
3547
  provideAgentTool,