@dudousxd/nestjs-agent 0.1.0 → 0.2.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.
@@ -68,7 +68,6 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
68
68
  const subThreadId = await ctx.step(`subthread:${agentName}`, async () => {
69
69
  const thread = await this.store.createThread({
70
70
  actor: input.actor,
71
- persona: "default",
72
71
  transient: true
73
72
  });
74
73
  return thread.id;
@@ -216,12 +215,12 @@ AgentDurableModule = _ts_decorate3([
216
215
  ], AgentDurableModule);
217
216
 
218
217
  // src/agent.module.ts
219
- import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER5, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY4, AGENT_DURABLE_RUNNER as AGENT_DURABLE_RUNNER2, AGENT_MODEL as AGENT_MODEL2, AGENT_OPTIONS as AGENT_OPTIONS3, AGENT_QUOTA_STORE as AGENT_QUOTA_STORE2, AGENT_REGISTRY as AGENT_REGISTRY3, AGENT_ROLES_POLICY as AGENT_ROLES_POLICY2, AGENT_RUNNER as AGENT_RUNNER2, AGENT_SINK as AGENT_SINK2, AGENT_STORE as AGENT_STORE5, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY3, AgentRegistry as AgentRegistry3, DefaultRolesPolicy, ToolRegistry as ToolRegistry3 } from "@dudousxd/nestjs-agent-core";
218
+ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER5, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY4, AGENT_DURABLE_RUNNER as AGENT_DURABLE_RUNNER2, AGENT_MODEL as AGENT_MODEL2, AGENT_OPTIONS as AGENT_OPTIONS3, AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS3, AGENT_QUOTA_STORE as AGENT_QUOTA_STORE2, AGENT_REGISTRY as AGENT_REGISTRY4, AGENT_ROLES_POLICY as AGENT_ROLES_POLICY2, AGENT_RUNNER as AGENT_RUNNER2, AGENT_SINK as AGENT_SINK2, AGENT_STORE as AGENT_STORE5, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY3, AgentRegistry as AgentRegistry4, DefaultRolesPolicy, ToolRegistry as ToolRegistry3 } from "@dudousxd/nestjs-agent-core";
220
219
  import { Global as Global2, Module as Module2 } from "@nestjs/common";
221
220
  import { DiscoveryModule, RouterModule } from "@nestjs/core";
222
221
 
223
222
  // src/agent-deps.factory.ts
224
- import { AGENT_MODEL, AGENT_QUOTA_STORE, AGENT_REGISTRY, AGENT_ROLES_POLICY, AGENT_SINK, AGENT_STORE as AGENT_STORE2, AGENT_TOOL_REGISTRY, AgentRegistry as AgentRegistry2, ToolRegistry as ToolRegistry2 } from "@dudousxd/nestjs-agent-core";
223
+ import { AGENT_MODEL, AGENT_PROMPT_CONTRIBUTORS, AGENT_QUOTA_STORE, AGENT_REGISTRY, AGENT_ROLES_POLICY, AGENT_SINK, AGENT_STORE as AGENT_STORE2, AGENT_TOOL_REGISTRY, AgentRegistry as AgentRegistry2, ToolRegistry as ToolRegistry2 } from "@dudousxd/nestjs-agent-core";
225
224
  import { AGENT_OPTIONS } from "@dudousxd/nestjs-agent-core";
226
225
  import { Inject as Inject2, Injectable as Injectable3 } from "@nestjs/common";
227
226
  function _ts_decorate4(decorators, target, key, desc) {
@@ -256,8 +255,9 @@ var AgentDepsFactory2 = class {
256
255
  rolesPolicy;
257
256
  registry;
258
257
  agents;
258
+ promptContributors;
259
259
  quota;
260
- constructor(options, model, store, sink, rolesPolicy, registry, agents, quota) {
260
+ constructor(options, model, store, sink, rolesPolicy, registry, agents, promptContributors, quota) {
261
261
  this.options = options;
262
262
  this.model = model;
263
263
  this.store = store;
@@ -265,10 +265,19 @@ var AgentDepsFactory2 = class {
265
265
  this.rolesPolicy = rolesPolicy;
266
266
  this.registry = registry;
267
267
  this.agents = agents;
268
+ this.promptContributors = promptContributors;
268
269
  this.quota = quota;
269
270
  }
271
+ /**
272
+ * The agent a turn uses when the caller names none: the explicit `defaultAgent` option, else the
273
+ * sole registered `@Agent` when there is exactly one, else `'default'` (a bare assistant).
274
+ */
270
275
  defaultAgentName() {
271
- return this.options.defaultAgent?.name ?? "default";
276
+ if (this.options.defaultAgent !== void 0) {
277
+ return this.options.defaultAgent;
278
+ }
279
+ const registered = this.agents.list();
280
+ return registered.length === 1 ? registered[0]?.name ?? "default" : "default";
272
281
  }
273
282
  effectiveTools(definition) {
274
283
  if (definition === void 0) {
@@ -286,10 +295,6 @@ var AgentDepsFactory2 = class {
286
295
  forAgent(agentName) {
287
296
  const name = agentName ?? this.defaultAgentName();
288
297
  const definition = this.agents.get(name);
289
- const personas = /* @__PURE__ */ new Map();
290
- for (const persona of definition?.personas ?? []) {
291
- personas.set(persona.id, persona);
292
- }
293
298
  const toolAllowList = this.effectiveTools(definition);
294
299
  const followUpsCount = this.followUpsCount();
295
300
  const retrieval = this.options.retrieval;
@@ -299,10 +304,9 @@ var AgentDepsFactory2 = class {
299
304
  sink: this.sink,
300
305
  rolesPolicy: this.rolesPolicy,
301
306
  registry: this.registry,
307
+ promptContributors: this.promptContributors,
302
308
  systemPrompt: definition?.systemPrompt ?? "You are a helpful assistant.",
303
309
  maxSteps: definition?.maxSteps ?? 8,
304
- personas,
305
- defaultPersona: definition?.defaultPersona ?? "default",
306
310
  ...definition?.modelId !== void 0 ? {
307
311
  modelId: definition.modelId
308
312
  } : {},
@@ -347,7 +351,8 @@ AgentDepsFactory2 = _ts_decorate4([
347
351
  _ts_param2(4, Inject2(AGENT_ROLES_POLICY)),
348
352
  _ts_param2(5, Inject2(AGENT_TOOL_REGISTRY)),
349
353
  _ts_param2(6, Inject2(AGENT_REGISTRY)),
350
- _ts_param2(7, Inject2(AGENT_QUOTA_STORE)),
354
+ _ts_param2(7, Inject2(AGENT_PROMPT_CONTRIBUTORS)),
355
+ _ts_param2(8, Inject2(AGENT_QUOTA_STORE)),
351
356
  _ts_metadata3("design:type", Function),
352
357
  _ts_metadata3("design:paramtypes", [
353
358
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
@@ -357,6 +362,7 @@ AgentDepsFactory2 = _ts_decorate4([
357
362
  typeof RolesPolicy === "undefined" ? Object : RolesPolicy,
358
363
  typeof ToolRegistry2 === "undefined" ? Object : ToolRegistry2,
359
364
  typeof AgentRegistry2 === "undefined" ? Object : AgentRegistry2,
365
+ Array,
360
366
  Object
361
367
  ])
362
368
  ], AgentDepsFactory2);
@@ -401,14 +407,12 @@ var AgentService = class {
401
407
  throw new BadRequestException("regenerate requires an existing threadId");
402
408
  }
403
409
  const created = await this.store.createThread({
404
- actor: params.actor,
405
- persona: params.personaId ?? this.deps.forAgent(agentName).defaultPersona
410
+ actor: params.actor
406
411
  });
407
412
  threadId = created.id;
408
413
  } else if (params.regenerate === true) {
409
414
  await this.assertOwnsThread(params.actor, threadId);
410
415
  }
411
- const persona = this.resolvePersona(agentName, params.personaId);
412
416
  const input = {
413
417
  threadId,
414
418
  actor: params.actor,
@@ -418,9 +422,6 @@ var AgentService = class {
418
422
  ...params.regenerate === true ? {
419
423
  regenerate: true
420
424
  } : {},
421
- ...persona !== void 0 ? {
422
- persona
423
- } : {},
424
425
  ...params.pageContext !== void 0 ? {
425
426
  pageContext: params.pageContext
426
427
  } : {}
@@ -454,18 +455,6 @@ var AgentService = class {
454
455
  await this.assertOwnsActiveStream(actor, runId);
455
456
  return this.runner.cancel(runId);
456
457
  }
457
- resolvePersona(agentName, id) {
458
- const deps = this.deps.forAgent(agentName);
459
- return deps.personas.get(id ?? deps.defaultPersona);
460
- }
461
- personaCatalog(agentName) {
462
- return [
463
- ...this.deps.forAgent(agentName).personas.values()
464
- ].map((persona) => ({
465
- id: persona.id,
466
- label: persona.label
467
- }));
468
- }
469
458
  listThreads(actorRef) {
470
459
  return this.store.listThreads(actorRef);
471
460
  }
@@ -582,9 +571,6 @@ var ChatController = class {
582
571
  ...body.agent !== void 0 ? {
583
572
  agentName: body.agent
584
573
  } : {},
585
- ...body.persona !== void 0 ? {
586
- personaId: body.persona
587
- } : {},
588
574
  ...body.pageContext !== void 0 ? {
589
575
  pageContext: body.pageContext
590
576
  } : {},
@@ -778,9 +764,6 @@ var ThreadsController = class {
778
764
  const actor = await this.actorResolver.resolve(req);
779
765
  return this.agent.listThreads(actor.id);
780
766
  }
781
- personas() {
782
- return this.agent.personaCatalog();
783
- }
784
767
  async detail(req, id) {
785
768
  const actor = await this.actorResolver.resolve(req);
786
769
  return this.agent.getThread(actor, id);
@@ -806,12 +789,6 @@ _ts_decorate8([
806
789
  ]),
807
790
  _ts_metadata7("design:returntype", Promise)
808
791
  ], ThreadsController.prototype, "list", null);
809
- _ts_decorate8([
810
- Get3("personas/catalog"),
811
- _ts_metadata7("design:type", Function),
812
- _ts_metadata7("design:paramtypes", []),
813
- _ts_metadata7("design:returntype", void 0)
814
- ], ThreadsController.prototype, "personas", null);
815
792
  _ts_decorate8([
816
793
  Get3(":id"),
817
794
  _ts_param6(0, Req3()),
@@ -934,10 +911,152 @@ ToolCallController = _ts_decorate9([
934
911
  ])
935
912
  ], ToolCallController);
936
913
 
937
- // src/discovery/ai-tool-discovery.service.ts
938
- import { AGENT_OPTIONS as AGENT_OPTIONS2, AGENT_REGISTRY as AGENT_REGISTRY2, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY2 } from "@dudousxd/nestjs-agent-core";
914
+ // src/discovery/agent-discovery.service.ts
915
+ import { AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS2, AGENT_REGISTRY as AGENT_REGISTRY2, AgentRegistry as AgentRegistry3 } from "@dudousxd/nestjs-agent-core";
939
916
  import { Inject as Inject8, Injectable as Injectable5, Logger } from "@nestjs/common";
940
- import { DiscoveryService } from "@nestjs/core";
917
+ import { DiscoveryService, MetadataScanner } from "@nestjs/core";
918
+
919
+ // src/decorator/agent.decorator.ts
920
+ import "reflect-metadata";
921
+ var AGENT_METADATA = Symbol.for("@dudousxd/nestjs-agent:agent-metadata");
922
+ function readAgentMetadata(target) {
923
+ return Reflect.getMetadata(AGENT_METADATA, target);
924
+ }
925
+ __name(readAgentMetadata, "readAgentMetadata");
926
+
927
+ // src/decorator/system-prompt.decorator.ts
928
+ import "reflect-metadata";
929
+ var SYSTEM_PROMPT_METADATA = Symbol.for("@dudousxd/nestjs-agent:system-prompt");
930
+ var SYSTEM_PROMPT_CONTRIBUTOR_METADATA = Symbol.for("@dudousxd/nestjs-agent:system-prompt-contributor");
931
+
932
+ // src/discovery/agent-discovery.service.ts
933
+ function _ts_decorate10(decorators, target, key, desc) {
934
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
935
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
936
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
937
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
938
+ }
939
+ __name(_ts_decorate10, "_ts_decorate");
940
+ function _ts_metadata9(k, v) {
941
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
942
+ }
943
+ __name(_ts_metadata9, "_ts_metadata");
944
+ function _ts_param8(paramIndex, decorator) {
945
+ return function(target, key) {
946
+ decorator(target, key, paramIndex);
947
+ };
948
+ }
949
+ __name(_ts_param8, "_ts_param");
950
+ var AgentDiscoveryService = class _AgentDiscoveryService {
951
+ static {
952
+ __name(this, "AgentDiscoveryService");
953
+ }
954
+ discovery;
955
+ scanner;
956
+ registry;
957
+ contributors;
958
+ logger = new Logger(_AgentDiscoveryService.name);
959
+ constructor(discovery, scanner, registry, contributors) {
960
+ this.discovery = discovery;
961
+ this.scanner = scanner;
962
+ this.registry = registry;
963
+ this.contributors = contributors;
964
+ }
965
+ onModuleInit() {
966
+ for (const wrapper of this.discovery.getProviders()) {
967
+ const instance = wrapper.instance;
968
+ if (instance === null || typeof instance !== "object") {
969
+ continue;
970
+ }
971
+ const meta = readAgentMetadata(instance.constructor);
972
+ if (meta !== void 0) {
973
+ this.registry.register(this.definitionFrom(instance, meta));
974
+ }
975
+ this.collectContributors(instance);
976
+ }
977
+ }
978
+ /** Build the internal {@link AgentDefinition} from an `@Agent` instance and its options. */
979
+ definitionFrom(instance, meta) {
980
+ const promptMethod = this.methodWith(instance, SYSTEM_PROMPT_METADATA);
981
+ const systemPrompt = promptMethod !== void 0 ? (ctx) => promptMethod(ctx) : meta.systemPrompt ?? "You are a helpful assistant.";
982
+ return {
983
+ name: meta.name,
984
+ systemPrompt,
985
+ ...meta.tools !== void 0 ? {
986
+ tools: meta.tools
987
+ } : {},
988
+ ...meta.model !== void 0 ? {
989
+ modelId: meta.model
990
+ } : {},
991
+ ...meta.maxSteps !== void 0 ? {
992
+ maxSteps: meta.maxSteps
993
+ } : {},
994
+ ...meta.handoff !== void 0 ? {
995
+ delegatesTo: this.handoffNames(meta)
996
+ } : {}
997
+ };
998
+ }
999
+ /** Resolve each handoff `@Agent` class to its registered name (skipping non-agent classes). */
1000
+ handoffNames(meta) {
1001
+ const names = [];
1002
+ for (const target of meta.handoff ?? []) {
1003
+ const targetMeta = readAgentMetadata(target);
1004
+ if (targetMeta === void 0) {
1005
+ this.logger.warn(`Agent "${meta.name}" hands off to ${target.name}, which is not an @Agent \u2014 skipped.`);
1006
+ continue;
1007
+ }
1008
+ names.push(targetMeta.name);
1009
+ }
1010
+ return names;
1011
+ }
1012
+ /** Push every `@SystemPromptContributor()` method on `instance` (bound) into the contributor list. */
1013
+ collectContributors(instance) {
1014
+ const prototype = Object.getPrototypeOf(instance);
1015
+ for (const name of this.scanner.getAllMethodNames(prototype)) {
1016
+ if (Reflect.getMetadata(SYSTEM_PROMPT_CONTRIBUTOR_METADATA, prototype, name) === true) {
1017
+ const method = this.boundMethod(instance, name);
1018
+ if (method !== void 0) {
1019
+ this.contributors.push((ctx) => method(ctx));
1020
+ }
1021
+ }
1022
+ }
1023
+ }
1024
+ /** The single method on `instance` carrying `metadataKey`, bound to the instance, or undefined. */
1025
+ methodWith(instance, metadataKey) {
1026
+ const prototype = Object.getPrototypeOf(instance);
1027
+ for (const name of this.scanner.getAllMethodNames(prototype)) {
1028
+ if (Reflect.getMetadata(metadataKey, prototype, name) === true) {
1029
+ return this.boundMethod(instance, name);
1030
+ }
1031
+ }
1032
+ return void 0;
1033
+ }
1034
+ /** Bind a named method to its instance, guarding that it is actually a function. */
1035
+ boundMethod(instance, name) {
1036
+ const candidate = instance[name];
1037
+ if (typeof candidate !== "function") {
1038
+ return void 0;
1039
+ }
1040
+ return (ctx) => candidate.call(instance, ctx);
1041
+ }
1042
+ };
1043
+ AgentDiscoveryService = _ts_decorate10([
1044
+ Injectable5(),
1045
+ _ts_param8(2, Inject8(AGENT_REGISTRY2)),
1046
+ _ts_param8(3, Inject8(AGENT_PROMPT_CONTRIBUTORS2)),
1047
+ _ts_metadata9("design:type", Function),
1048
+ _ts_metadata9("design:paramtypes", [
1049
+ typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
1050
+ typeof MetadataScanner === "undefined" ? Object : MetadataScanner,
1051
+ typeof AgentRegistry3 === "undefined" ? Object : AgentRegistry3,
1052
+ Array
1053
+ ])
1054
+ ], AgentDiscoveryService);
1055
+
1056
+ // src/discovery/ai-tool-discovery.service.ts
1057
+ import { AGENT_OPTIONS as AGENT_OPTIONS2, AGENT_REGISTRY as AGENT_REGISTRY3, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY2 } from "@dudousxd/nestjs-agent-core";
1058
+ import { Inject as Inject9, Injectable as Injectable6, Logger as Logger2 } from "@nestjs/common";
1059
+ import { DiscoveryService as DiscoveryService2 } from "@nestjs/core";
941
1060
  import { z } from "zod";
942
1061
 
943
1062
  // src/decorator/ai-tool.decorator.ts
@@ -956,23 +1075,23 @@ function isBrandedFunctionalTool(value) {
956
1075
  __name(isBrandedFunctionalTool, "isBrandedFunctionalTool");
957
1076
 
958
1077
  // src/discovery/ai-tool-discovery.service.ts
959
- function _ts_decorate10(decorators, target, key, desc) {
1078
+ function _ts_decorate11(decorators, target, key, desc) {
960
1079
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
961
1080
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
962
1081
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
963
1082
  return c > 3 && r && Object.defineProperty(target, key, r), r;
964
1083
  }
965
- __name(_ts_decorate10, "_ts_decorate");
966
- function _ts_metadata9(k, v) {
1084
+ __name(_ts_decorate11, "_ts_decorate");
1085
+ function _ts_metadata10(k, v) {
967
1086
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
968
1087
  }
969
- __name(_ts_metadata9, "_ts_metadata");
970
- function _ts_param8(paramIndex, decorator) {
1088
+ __name(_ts_metadata10, "_ts_metadata");
1089
+ function _ts_param9(paramIndex, decorator) {
971
1090
  return function(target, key) {
972
1091
  decorator(target, key, paramIndex);
973
1092
  };
974
1093
  }
975
- __name(_ts_param8, "_ts_param");
1094
+ __name(_ts_param9, "_ts_param");
976
1095
  var AiToolDiscoveryService = class _AiToolDiscoveryService {
977
1096
  static {
978
1097
  __name(this, "AiToolDiscoveryService");
@@ -981,7 +1100,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
981
1100
  registry;
982
1101
  agents;
983
1102
  options;
984
- logger = new Logger(_AiToolDiscoveryService.name);
1103
+ logger = new Logger2(_AiToolDiscoveryService.name);
985
1104
  constructor(discovery, registry, agents, options) {
986
1105
  this.discovery = discovery;
987
1106
  this.registry = registry;
@@ -1039,7 +1158,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
1039
1158
  for (const target of definition.delegatesTo ?? []) {
1040
1159
  const targetDefinition = this.agents.get(target);
1041
1160
  if (targetDefinition === void 0) {
1042
- throw new Error(`Agent "${definition.name}" delegatesTo "${target}", which is not a registered agent. Register it via AgentModule.forFeature([...]) or fix the name.`);
1161
+ 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.`);
1043
1162
  }
1044
1163
  const name = delegateToolName(target);
1045
1164
  if (this.registry.has(name)) {
@@ -1079,14 +1198,14 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
1079
1198
  return true;
1080
1199
  }
1081
1200
  };
1082
- AiToolDiscoveryService = _ts_decorate10([
1083
- Injectable5(),
1084
- _ts_param8(1, Inject8(AGENT_TOOL_REGISTRY2)),
1085
- _ts_param8(2, Inject8(AGENT_REGISTRY2)),
1086
- _ts_param8(3, Inject8(AGENT_OPTIONS2)),
1087
- _ts_metadata9("design:type", Function),
1088
- _ts_metadata9("design:paramtypes", [
1089
- typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
1201
+ AiToolDiscoveryService = _ts_decorate11([
1202
+ Injectable6(),
1203
+ _ts_param9(1, Inject9(AGENT_TOOL_REGISTRY2)),
1204
+ _ts_param9(2, Inject9(AGENT_REGISTRY3)),
1205
+ _ts_param9(3, Inject9(AGENT_OPTIONS2)),
1206
+ _ts_metadata10("design:type", Function),
1207
+ _ts_metadata10("design:paramtypes", [
1208
+ typeof DiscoveryService2 === "undefined" ? Object : DiscoveryService2,
1090
1209
  typeof ToolRegistry === "undefined" ? Object : ToolRegistry,
1091
1210
  typeof AgentRegistry === "undefined" ? Object : AgentRegistry,
1092
1211
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions
@@ -1186,31 +1305,31 @@ var LedgerQuotaStore = class {
1186
1305
 
1187
1306
  // src/runner/inline-agent-runner.ts
1188
1307
  import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY3, AGENT_STORE as AGENT_STORE4, QuotaExceededError as QuotaExceededError2, publishAgentRunFailed as publishAgentRunFailed2, runAgentLoop as runAgentLoop2 } from "@dudousxd/nestjs-agent-core";
1189
- import { Inject as Inject9, Injectable as Injectable6, Logger as Logger2 } from "@nestjs/common";
1190
- function _ts_decorate11(decorators, target, key, desc) {
1308
+ import { Inject as Inject10, Injectable as Injectable7, Logger as Logger3 } from "@nestjs/common";
1309
+ function _ts_decorate12(decorators, target, key, desc) {
1191
1310
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1192
1311
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1193
1312
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1194
1313
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1195
1314
  }
1196
- __name(_ts_decorate11, "_ts_decorate");
1197
- function _ts_metadata10(k, v) {
1315
+ __name(_ts_decorate12, "_ts_decorate");
1316
+ function _ts_metadata11(k, v) {
1198
1317
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1199
1318
  }
1200
- __name(_ts_metadata10, "_ts_metadata");
1201
- function _ts_param9(paramIndex, decorator) {
1319
+ __name(_ts_metadata11, "_ts_metadata");
1320
+ function _ts_param10(paramIndex, decorator) {
1202
1321
  return function(target, key) {
1203
1322
  decorator(target, key, paramIndex);
1204
1323
  };
1205
1324
  }
1206
- __name(_ts_param9, "_ts_param");
1325
+ __name(_ts_param10, "_ts_param");
1207
1326
  var InlineAgentRunner = class _InlineAgentRunner {
1208
1327
  static {
1209
1328
  __name(this, "InlineAgentRunner");
1210
1329
  }
1211
1330
  factory;
1212
1331
  store;
1213
- logger = new Logger2(_InlineAgentRunner.name);
1332
+ logger = new Logger3(_InlineAgentRunner.name);
1214
1333
  pending = /* @__PURE__ */ new Map();
1215
1334
  constructor(factory, store) {
1216
1335
  this.factory = factory;
@@ -1275,7 +1394,6 @@ var InlineAgentRunner = class _InlineAgentRunner {
1275
1394
  async runNested(agentName, task, actor, day, depth, sinkRunId) {
1276
1395
  const subThread = await this.store.createThread({
1277
1396
  actor,
1278
- persona: "default",
1279
1397
  transient: true
1280
1398
  });
1281
1399
  const runId = crypto.randomUUID();
@@ -1305,50 +1423,41 @@ var InlineAgentRunner = class _InlineAgentRunner {
1305
1423
  }, hooks);
1306
1424
  }
1307
1425
  };
1308
- InlineAgentRunner = _ts_decorate11([
1309
- Injectable6(),
1310
- _ts_param9(0, Inject9(AGENT_DEPS_FACTORY3)),
1311
- _ts_param9(1, Inject9(AGENT_STORE4)),
1312
- _ts_metadata10("design:type", Function),
1313
- _ts_metadata10("design:paramtypes", [
1426
+ InlineAgentRunner = _ts_decorate12([
1427
+ Injectable7(),
1428
+ _ts_param10(0, Inject10(AGENT_DEPS_FACTORY3)),
1429
+ _ts_param10(1, Inject10(AGENT_STORE4)),
1430
+ _ts_metadata11("design:type", Function),
1431
+ _ts_metadata11("design:paramtypes", [
1314
1432
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
1315
1433
  typeof AgentStore === "undefined" ? Object : AgentStore
1316
1434
  ])
1317
1435
  ], InlineAgentRunner);
1318
1436
 
1319
1437
  // src/agent.module.ts
1320
- function _ts_decorate12(decorators, target, key, desc) {
1438
+ function _ts_decorate13(decorators, target, key, desc) {
1321
1439
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1322
1440
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1323
1441
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1324
1442
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1325
1443
  }
1326
- __name(_ts_decorate12, "_ts_decorate");
1327
- var FEATURE_INIT = Symbol("nestjs-agent:feature-init");
1444
+ __name(_ts_decorate13, "_ts_decorate");
1328
1445
  var DEFAULT_PATH = "agent";
1329
- function defaultDefinition(options) {
1330
- return {
1331
- name: "default",
1332
- ...options.defaultAgent
1333
- };
1334
- }
1335
- __name(defaultDefinition, "defaultDefinition");
1336
1446
  function sharedProviders(durable, includeStore) {
1337
1447
  const providers = [
1338
1448
  {
1339
1449
  provide: AGENT_TOOL_REGISTRY3,
1340
1450
  useFactory: /* @__PURE__ */ __name(() => new ToolRegistry3(), "useFactory")
1341
1451
  },
1452
+ // Starts empty; AgentDiscoveryService populates it from `@Agent`-decorated providers at boot.
1342
1453
  {
1343
- provide: AGENT_REGISTRY3,
1344
- useFactory: /* @__PURE__ */ __name((options) => {
1345
- const registry = new AgentRegistry3();
1346
- registry.register(defaultDefinition(options));
1347
- return registry;
1348
- }, "useFactory"),
1349
- inject: [
1350
- AGENT_OPTIONS3
1351
- ]
1454
+ provide: AGENT_REGISTRY4,
1455
+ useFactory: /* @__PURE__ */ __name(() => new AgentRegistry4(), "useFactory")
1456
+ },
1457
+ // A shared, mutable list AgentDiscoveryService fills with `@SystemPromptContributor()` methods.
1458
+ {
1459
+ provide: AGENT_PROMPT_CONTRIBUTORS3,
1460
+ useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
1352
1461
  },
1353
1462
  {
1354
1463
  provide: AGENT_SINK2,
@@ -1394,6 +1503,9 @@ function sharedProviders(durable, includeStore) {
1394
1503
  provide: AGENT_DEPS_FACTORY4,
1395
1504
  useExisting: AgentDepsFactory2
1396
1505
  },
1506
+ // Populates the registry + contributors (onModuleInit) BEFORE AiToolDiscoveryService synthesizes
1507
+ // handoff tools (onApplicationBootstrap) reads the registry.
1508
+ AgentDiscoveryService,
1397
1509
  AiToolDiscoveryService,
1398
1510
  InlineAgentRunner,
1399
1511
  AgentService
@@ -1436,7 +1548,7 @@ function exportsFor(includeStore) {
1436
1548
  return [
1437
1549
  AGENT_OPTIONS3,
1438
1550
  AGENT_TOOL_REGISTRY3,
1439
- AGENT_REGISTRY3,
1551
+ AGENT_REGISTRY4,
1440
1552
  AGENT_SINK2,
1441
1553
  AGENT_ROLES_POLICY2,
1442
1554
  AGENT_ACTOR_RESOLVER5,
@@ -1445,6 +1557,7 @@ function exportsFor(includeStore) {
1445
1557
  AGENT_STORE5
1446
1558
  ] : [],
1447
1559
  AGENT_QUOTA_STORE2,
1560
+ AGENT_PROMPT_CONTRIBUTORS3,
1448
1561
  AGENT_DEPS_FACTORY4,
1449
1562
  AgentDepsFactory2,
1450
1563
  AgentService,
@@ -1516,28 +1629,8 @@ var AgentModule = class _AgentModule {
1516
1629
  exports: exportsFor(true)
1517
1630
  };
1518
1631
  }
1519
- /** Register additional named agents (an orchestrator + its sub-agents). */
1520
- static forFeature(definitions) {
1521
- return {
1522
- module: _AgentModule,
1523
- providers: [
1524
- {
1525
- provide: FEATURE_INIT,
1526
- useFactory: /* @__PURE__ */ __name((registry) => {
1527
- for (const definition of definitions) {
1528
- registry.register(definition);
1529
- }
1530
- return true;
1531
- }, "useFactory"),
1532
- inject: [
1533
- AGENT_REGISTRY3
1534
- ]
1535
- }
1536
- ]
1537
- };
1538
- }
1539
1632
  };
1540
- AgentModule = _ts_decorate12([
1633
+ AgentModule = _ts_decorate13([
1541
1634
  Global2(),
1542
1635
  Module2({})
1543
1636
  ], AgentModule);