@dudousxd/nestjs-agent 1.10.0 → 1.12.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
@@ -34,14 +34,16 @@ __export(index_exports, {
34
34
  AgentService: () => AgentService,
35
35
  AiTool: () => AiTool,
36
36
  AiToolDiscoveryService: () => AiToolDiscoveryService,
37
+ AnonymousActorResolver: () => AnonymousActorResolver,
37
38
  AttachmentsController: () => AttachmentsController,
39
+ ConfigController: () => ConfigController,
38
40
  DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES: () => DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES,
39
41
  DEFAULT_MAX_ATTACHMENT_BYTES: () => DEFAULT_MAX_ATTACHMENT_BYTES,
40
42
  HeaderActorResolver: () => HeaderActorResolver,
41
43
  InProcessTokenStreamSink: () => InProcessTokenStreamSink,
42
44
  InlineAgentRunner: () => InlineAgentRunner,
43
45
  LedgerQuotaProvider: () => LedgerQuotaProvider,
44
- LedgerQuotaStore: () => LedgerQuotaStore,
46
+ MAX_ATTACHMENTS_PER_MESSAGE: () => MAX_ATTACHMENTS_PER_MESSAGE,
45
47
  MemoriesController: () => MemoriesController,
46
48
  MessagesController: () => MessagesController,
47
49
  ModelsController: () => ModelsController,
@@ -54,22 +56,26 @@ __export(index_exports, {
54
56
  SystemPrompt: () => SystemPrompt,
55
57
  SystemPromptContributor: () => SystemPromptContributor,
56
58
  ToolsController: () => ToolsController,
59
+ attachmentLimits: () => attachmentLimits,
57
60
  declaredSkillProvider: () => declaredSkillProvider,
61
+ defaultRequestUserMapper: () => defaultRequestUserMapper,
58
62
  delegateToolName: () => delegateToolName,
59
63
  provideAgentTool: () => provideAgentTool,
60
64
  provideAgentTools: () => provideAgentTools,
61
65
  readAgentMetadata: () => readAgentMetadata,
62
66
  readAiToolMetadata: () => readAiToolMetadata,
63
67
  readSkillMetadata: () => readSkillMetadata,
68
+ requestUserActorResolver: () => requestUserActorResolver,
64
69
  resolveSkillsConfig: () => resolveSkillsConfig,
65
70
  skillScope: () => skillScope,
71
+ toolNameFromClass: () => toolNameFromClass,
66
72
  utcDay: () => utcDay
67
73
  });
68
74
  module.exports = __toCommonJS(index_exports);
69
75
 
70
76
  // src/agent.module.ts
71
- var import_nestjs_agent_core23 = require("@dudousxd/nestjs-agent-core");
72
- var import_common19 = require("@nestjs/common");
77
+ var import_nestjs_agent_core24 = require("@dudousxd/nestjs-agent-core");
78
+ var import_common20 = require("@nestjs/common");
73
79
  var import_core4 = require("@nestjs/core");
74
80
 
75
81
  // src/agent-deps.factory.ts
@@ -119,11 +125,10 @@ var AgentDepsFactory2 = class {
119
125
  registry;
120
126
  agents;
121
127
  promptContributors;
122
- quota;
123
128
  pricingStore;
124
129
  skills;
125
130
  memory;
126
- constructor(options, model, store, sink, rolesPolicy, registry, agents, promptContributors, quota, pricingStore, skills, memory) {
131
+ constructor(options, model, store, sink, rolesPolicy, registry, agents, promptContributors, pricingStore, skills, memory) {
127
132
  this.options = options;
128
133
  this.model = model;
129
134
  this.store = store;
@@ -132,7 +137,6 @@ var AgentDepsFactory2 = class {
132
137
  this.registry = registry;
133
138
  this.agents = agents;
134
139
  this.promptContributors = promptContributors;
135
- this.quota = quota;
136
140
  this.pricingStore = pricingStore;
137
141
  this.skills = skills;
138
142
  this.memory = memory;
@@ -193,7 +197,7 @@ var AgentDepsFactory2 = class {
193
197
  } : {},
194
198
  registry: this.registry,
195
199
  promptContributors: this.promptContributors,
196
- systemPrompt: definition?.systemPrompt ?? "You are a helpful assistant.",
200
+ systemPrompt: definition?.systemPrompt ?? this.options.systemPrompt ?? "You are a helpful assistant.",
197
201
  maxSteps: definition?.maxSteps ?? 8,
198
202
  ...definition?.maxDelegationDepth !== void 0 ? {
199
203
  maxDelegationDepth: definition.maxDelegationDepth
@@ -204,9 +208,6 @@ var AgentDepsFactory2 = class {
204
208
  ...definition?.modelId !== void 0 ? {
205
209
  modelId: definition.modelId
206
210
  } : {},
207
- ...this.quota !== void 0 ? {
208
- quota: this.quota
209
- } : {},
210
211
  ...this.pricingStore !== void 0 ? {
211
212
  pricingStore: this.pricingStore
212
213
  } : {},
@@ -313,13 +314,12 @@ AgentDepsFactory2 = _ts_decorate([
313
314
  _ts_param(5, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_TOOL_REGISTRY)),
314
315
  _ts_param(6, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_REGISTRY)),
315
316
  _ts_param(7, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_PROMPT_CONTRIBUTORS)),
316
- _ts_param(8, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_QUOTA_STORE)),
317
+ _ts_param(8, (0, import_common.Optional)()),
318
+ _ts_param(8, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_PRICING_STORE)),
317
319
  _ts_param(9, (0, import_common.Optional)()),
318
- _ts_param(9, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_PRICING_STORE)),
320
+ _ts_param(9, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_SKILLS)),
319
321
  _ts_param(10, (0, import_common.Optional)()),
320
- _ts_param(10, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_SKILLS)),
321
- _ts_param(11, (0, import_common.Optional)()),
322
- _ts_param(11, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_MEMORY)),
322
+ _ts_param(10, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_MEMORY)),
323
323
  _ts_metadata("design:type", Function),
324
324
  _ts_metadata("design:paramtypes", [
325
325
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
@@ -332,7 +332,6 @@ AgentDepsFactory2 = _ts_decorate([
332
332
  Array,
333
333
  Object,
334
334
  Object,
335
- Object,
336
335
  Object
337
336
  ])
338
337
  ], AgentDepsFactory2);
@@ -391,16 +390,14 @@ var AgentService = class {
391
390
  runner;
392
391
  store;
393
392
  deps;
394
- quota;
395
393
  staging;
396
394
  models;
397
395
  quotaProvider;
398
396
  options;
399
- constructor(runner, store, deps, quota, staging, models, quotaProvider, options) {
397
+ constructor(runner, store, deps, staging, models, quotaProvider, options) {
400
398
  this.runner = runner;
401
399
  this.store = store;
402
400
  this.deps = deps;
403
- this.quota = quota;
404
401
  this.staging = staging;
405
402
  this.models = models;
406
403
  this.quotaProvider = quotaProvider;
@@ -416,33 +413,23 @@ var AgentService = class {
416
413
  actor
417
414
  });
418
415
  }
419
- const today = await this.quotaToday(actor.id);
416
+ const { usedTokens, costUsd } = await this.store.quotaToday(actor.id, utcDay());
420
417
  return {
421
418
  windows: [
422
419
  {
423
420
  period: "day",
424
- usedTokens: today.usedTokens,
425
- ...today.limitTokens !== null ? {
426
- limitTokens: today.limitTokens
427
- } : {},
428
- usedUsd: today.costUsd
429
- }
430
- ],
431
- ...today.withinLimit ? {} : {
432
- blocked: {
433
- period: "day"
421
+ usedTokens,
422
+ usedUsd: costUsd
434
423
  }
435
- }
424
+ ]
436
425
  };
437
426
  }
438
427
  /**
439
428
  * Refuse a turn the actor's budget no longer covers — only when the host configured one
440
- * (`quotaProvider` or `quotaLimits`): the default report is informational, and the daily token
441
- * quota the loop enforces keeps working as it always has.
429
+ * (`quota`): the default report is informational.
442
430
  */
443
431
  async assertWithinQuota(actor) {
444
- const gated = this.options?.quotaProvider !== void 0 || this.options?.quotaLimits !== void 0;
445
- if (!gated || this.quotaProvider === void 0) {
432
+ if (this.options?.quota === void 0 || this.quotaProvider === void 0) {
446
433
  return;
447
434
  }
448
435
  const { blocked } = await this.quotaProvider.report({
@@ -693,7 +680,7 @@ var AgentService = class {
693
680
  async getThread(actor, threadId) {
694
681
  await this.assertOwnsThread(actor, threadId);
695
682
  const thread = await this.store.getThread(threadId);
696
- return thread === null ? null : this.toDetailView(thread);
683
+ return thread === null ? null : this.toDetailView(thread, actor);
697
684
  }
698
685
  async deleteThread(actor, threadId) {
699
686
  await this.assertOwnsThread(actor, threadId);
@@ -785,19 +772,46 @@ var AgentService = class {
785
772
  ...thread,
786
773
  defaultAgent: thread.defaultAgent ?? null,
787
774
  model: thread.model ?? null,
788
- activeRunId: await this.store.activeRunForThread?.(thread.id) ?? null
775
+ activeRunId: await this.store.activeRunForThread?.(thread.id) ?? thread.activeRunId ?? null
789
776
  };
790
777
  }
791
- async toDetailView(thread) {
778
+ async toDetailView(thread, actor) {
792
779
  const summary = await this.toSummaryView(thread);
793
780
  return {
794
781
  ...summary,
795
- messages: thread.messages,
796
- ...thread.activeStreamId !== void 0 ? {
797
- activeStreamId: thread.activeStreamId
798
- } : {}
782
+ messages: await this.freshAttachmentUrls(thread.messages, actor)
799
783
  };
800
784
  }
785
+ /**
786
+ * Re-mint each replayed attachment's url from the staging store, by `mediaId`: the url persisted
787
+ * with the message was minted for THAT turn (a presigned url with an expiry), so an old turn would
788
+ * otherwise show a dead link. The store's own access check applies — an attachment it will not
789
+ * resolve for this actor keeps the url it was stored with.
790
+ */
791
+ async freshAttachmentUrls(messages, actor) {
792
+ const staging = this.staging;
793
+ if (staging === void 0 || !messages.some((message) => message.attachments?.length)) {
794
+ return messages;
795
+ }
796
+ return Promise.all(messages.map(async (message) => {
797
+ if (message.attachments === void 0 || message.attachments.length === 0) return message;
798
+ const attachments = await Promise.all(message.attachments.map(async (attachment) => {
799
+ try {
800
+ const fresh = await staging.resolve({
801
+ mediaId: attachment.mediaId,
802
+ actor
803
+ });
804
+ return fresh ?? attachment;
805
+ } catch {
806
+ return attachment;
807
+ }
808
+ }));
809
+ return {
810
+ ...message,
811
+ attachments
812
+ };
813
+ }));
814
+ }
801
815
  async promoteThread(actor, threadId) {
802
816
  await this.assertOwnsThread(actor, threadId);
803
817
  return this.store.promoteThread(threadId);
@@ -907,30 +921,6 @@ var AgentService = class {
907
921
  return list;
908
922
  }
909
923
  /**
910
- * The day's usage for the badge: tokens + summed USD cost from the store, and the configured
911
- * limit from the quota store (null → unlimited). `withinLimit` comes from the quota store so it
912
- * can never drift from what enforcement uses.
913
- */
914
- async quotaToday(actorRef) {
915
- const day = utcDay();
916
- const { usedTokens, costUsd } = await this.store.quotaToday(actorRef, day);
917
- if (this.quota === void 0) {
918
- return {
919
- usedTokens,
920
- costUsd,
921
- limitTokens: null,
922
- withinLimit: true
923
- };
924
- }
925
- const state = await this.quota.check(actorRef, day);
926
- return {
927
- usedTokens: state.usedTokens,
928
- costUsd,
929
- limitTokens: state.limitTokens,
930
- withinLimit: state.withinLimit
931
- };
932
- }
933
- /**
934
924
  * Authorization seam for thread-scoped endpoints: the caller must own the thread. A missing
935
925
  * thread is a 404; someone else's thread is a 403 — one actor never touches another's thread.
936
926
  */
@@ -1049,21 +1039,19 @@ AgentService = _ts_decorate2([
1049
1039
  _ts_param2(0, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_RUNNER)),
1050
1040
  _ts_param2(1, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_STORE)),
1051
1041
  _ts_param2(2, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_DEPS_FACTORY)),
1052
- _ts_param2(3, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_QUOTA_STORE)),
1042
+ _ts_param2(3, (0, import_common2.Optional)()),
1043
+ _ts_param2(3, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_ATTACHMENT_STAGING)),
1053
1044
  _ts_param2(4, (0, import_common2.Optional)()),
1054
- _ts_param2(4, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_ATTACHMENT_STAGING)),
1045
+ _ts_param2(4, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_MODEL_CATALOG)),
1055
1046
  _ts_param2(5, (0, import_common2.Optional)()),
1056
- _ts_param2(5, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_MODEL_CATALOG)),
1047
+ _ts_param2(5, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_QUOTA_PROVIDER)),
1057
1048
  _ts_param2(6, (0, import_common2.Optional)()),
1058
- _ts_param2(6, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_QUOTA_PROVIDER)),
1059
- _ts_param2(7, (0, import_common2.Optional)()),
1060
- _ts_param2(7, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_OPTIONS)),
1049
+ _ts_param2(6, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_OPTIONS)),
1061
1050
  _ts_metadata2("design:type", Function),
1062
1051
  _ts_metadata2("design:paramtypes", [
1063
1052
  typeof AgentRunner === "undefined" ? Object : AgentRunner,
1064
1053
  typeof AgentStore === "undefined" ? Object : AgentStore,
1065
1054
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
1066
- Object,
1067
1055
  typeof AttachmentStagingStore === "undefined" ? Object : AttachmentStagingStore,
1068
1056
  typeof ModelCatalog === "undefined" ? Object : ModelCatalog,
1069
1057
  typeof QuotaProvider === "undefined" ? Object : QuotaProvider,
@@ -1209,6 +1197,33 @@ AgentsController = _ts_decorate4([
1209
1197
  var import_nestjs_agent_core5 = require("@dudousxd/nestjs-agent-core");
1210
1198
  var import_common5 = require("@nestjs/common");
1211
1199
  var import_platform_express = require("@nestjs/platform-express");
1200
+
1201
+ // src/attachment-limits.ts
1202
+ var DEFAULT_MAX_ATTACHMENT_BYTES = 20 * 1024 * 1024;
1203
+ var DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES = [
1204
+ "image/png",
1205
+ "image/jpeg",
1206
+ "image/gif",
1207
+ "image/webp",
1208
+ "application/pdf",
1209
+ "text/plain",
1210
+ "text/csv"
1211
+ ];
1212
+ var MAX_ATTACHMENTS_PER_MESSAGE = 10;
1213
+ function attachmentLimits(options, staging) {
1214
+ const declared = staging?.describe?.();
1215
+ const own = options?.attachments;
1216
+ return {
1217
+ enabled: staging !== void 0,
1218
+ upload: staging === void 0 ? null : declared?.upload ?? "multipart",
1219
+ maxBytes: declared?.maxBytes ?? own?.maxBytes ?? DEFAULT_MAX_ATTACHMENT_BYTES,
1220
+ allowedContentTypes: declared?.allowedContentTypes ?? own?.allowedContentTypes ?? DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES,
1221
+ maxPerMessage: MAX_ATTACHMENTS_PER_MESSAGE
1222
+ };
1223
+ }
1224
+ __name(attachmentLimits, "attachmentLimits");
1225
+
1226
+ // src/controller/attachments.controller.ts
1212
1227
  function _ts_decorate5(decorators, target, key, desc) {
1213
1228
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1214
1229
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -1235,18 +1250,8 @@ function _ts_param4(paramIndex, decorator) {
1235
1250
  };
1236
1251
  }
1237
1252
  __name(_ts_param4, "_ts_param");
1238
- var DEFAULT_MAX_ATTACHMENT_BYTES = 20 * 1024 * 1024;
1239
1253
  var HARD_MAX_ATTACHMENT_BYTES = 32 * 1024 * 1024;
1240
1254
  var ATTACHMENT_PAGE_SIZE = 50;
1241
- var DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES = [
1242
- "image/png",
1243
- "image/jpeg",
1244
- "image/gif",
1245
- "image/webp",
1246
- "application/pdf",
1247
- "text/plain",
1248
- "text/csv"
1249
- ];
1250
1255
  var AttachmentsController = class {
1251
1256
  static {
1252
1257
  __name(this, "AttachmentsController");
@@ -1262,17 +1267,6 @@ var AttachmentsController = class {
1262
1267
  this.staging = staging;
1263
1268
  }
1264
1269
  /**
1265
- * `attachments.upload: true` is what mounts this controller at all (see `agent.module.ts`), so by
1266
- * the time an instance exists the host clearly intends uploads to work. Fail boot loudly rather
1267
- * than mounting a controller that would 501 on every single request because nobody bound
1268
- * `AGENT_ATTACHMENT_STAGING`.
1269
- */
1270
- onModuleInit() {
1271
- if (this.options.attachments?.upload === true && this.staging === void 0) {
1272
- throw new Error("AgentModule: attachments.upload is true but no AGENT_ATTACHMENT_STAGING provider is bound. Bind one (e.g. `{ provide: AGENT_ATTACHMENT_STAGING, useClass: MyStagingStore }`) in a module imported alongside AgentModule, or set attachments.upload to false.");
1273
- }
1274
- }
1275
- /**
1276
1270
  * The caller's own staged files, newest first — the one question `GET /agent/threads/:id` cannot
1277
1271
  * answer, since an upload that was never sent belongs to no thread.
1278
1272
  *
@@ -1289,16 +1283,15 @@ var AttachmentsController = class {
1289
1283
  }
1290
1284
  async upload(req, file) {
1291
1285
  if (this.staging === void 0) {
1292
- throw new import_common5.NotImplementedException("Attachment upload is not configured on this server.");
1286
+ throw new import_common5.NotImplementedException("Attachment upload is not configured on this server: bind AGENT_ATTACHMENT_STAGING (e.g. import AgentMediaAttachmentsModule).");
1293
1287
  }
1294
1288
  if (file === void 0) {
1295
1289
  throw new import_common5.BadRequestException('multipart field "file" is required');
1296
1290
  }
1297
- const allowedContentTypes = this.options.attachments?.allowedContentTypes ?? DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES;
1291
+ const { allowedContentTypes, maxBytes } = attachmentLimits(this.options, this.staging);
1298
1292
  if (!allowedContentTypes.includes(file.mimetype)) {
1299
1293
  throw new import_common5.UnsupportedMediaTypeException(`content type "${file.mimetype}" is not allowed (allowed: ${allowedContentTypes.join(", ")})`);
1300
1294
  }
1301
- const maxBytes = this.options.attachments?.maxBytes ?? DEFAULT_MAX_ATTACHMENT_BYTES;
1302
1295
  if (file.size > maxBytes) {
1303
1296
  throw new import_common5.PayloadTooLargeException(`file exceeds the ${maxBytes}-byte limit`);
1304
1297
  }
@@ -1381,7 +1374,6 @@ function _ts_param5(paramIndex, decorator) {
1381
1374
  };
1382
1375
  }
1383
1376
  __name(_ts_param5, "_ts_param");
1384
- var MAX_ATTACHMENTS_PER_MESSAGE = 10;
1385
1377
  function attachmentRefs(claimed) {
1386
1378
  if (claimed === void 0) {
1387
1379
  return [];
@@ -1396,6 +1388,9 @@ function attachmentRefs(claimed) {
1396
1388
  if (typeof entry !== "object" || entry === null || !("mediaId" in entry)) {
1397
1389
  throw new import_common6.BadRequestException("each attachment must be an object with a mediaId");
1398
1390
  }
1391
+ if (Object.keys(entry).some((key) => key !== "mediaId")) {
1392
+ throw new import_common6.BadRequestException("attachments are { mediaId } refs \u2014 send nothing but the id");
1393
+ }
1399
1394
  const { mediaId } = entry;
1400
1395
  if (typeof mediaId !== "string" || mediaId.length === 0) {
1401
1396
  throw new import_common6.BadRequestException("each attachment must carry a non-empty string mediaId");
@@ -1591,9 +1586,98 @@ function parseCursor(raw) {
1591
1586
  }
1592
1587
  __name(parseCursor, "parseCursor");
1593
1588
 
1594
- // src/controller/memories.controller.ts
1589
+ // src/controller/config.controller.ts
1595
1590
  var import_nestjs_agent_core7 = require("@dudousxd/nestjs-agent-core");
1596
1591
  var import_common7 = require("@nestjs/common");
1592
+
1593
+ // src/resolver/anonymous-actor-resolver.ts
1594
+ var import_node_crypto = require("crypto");
1595
+ var TOKEN_PATTERN = /^[A-Za-z0-9_-]{43}$/;
1596
+ var MINTED = /* @__PURE__ */ Symbol("nestjs-agent:anonymous-token");
1597
+ function readCookie(req, name) {
1598
+ const header = req.headers?.cookie;
1599
+ const raw = Array.isArray(header) ? header.join("; ") : header;
1600
+ if (raw === void 0) return void 0;
1601
+ for (const pair of raw.split(";")) {
1602
+ const index = pair.indexOf("=");
1603
+ if (index === -1) continue;
1604
+ if (pair.slice(0, index).trim() === name) {
1605
+ try {
1606
+ return decodeURIComponent(pair.slice(index + 1).trim());
1607
+ } catch {
1608
+ return void 0;
1609
+ }
1610
+ }
1611
+ }
1612
+ return void 0;
1613
+ }
1614
+ __name(readCookie, "readCookie");
1615
+ function isHttps(req) {
1616
+ if (req.secure === true) return true;
1617
+ const forwarded = req.headers?.["x-forwarded-proto"];
1618
+ const proto = Array.isArray(forwarded) ? forwarded[0] : forwarded;
1619
+ return proto?.split(",")[0]?.trim() === "https";
1620
+ }
1621
+ __name(isHttps, "isHttps");
1622
+ var AnonymousActorResolver = class {
1623
+ static {
1624
+ __name(this, "AnonymousActorResolver");
1625
+ }
1626
+ options;
1627
+ cookieName;
1628
+ roles;
1629
+ constructor(options = {}) {
1630
+ this.options = options;
1631
+ this.cookieName = options.cookieName ?? "agent_anon";
1632
+ this.roles = options.roles ?? [
1633
+ "anonymous"
1634
+ ];
1635
+ }
1636
+ resolve(request) {
1637
+ const req = typeof request === "object" && request !== null ? request : {};
1638
+ let token = req[MINTED] ?? readCookie(req, this.cookieName);
1639
+ if (token === void 0 || !TOKEN_PATTERN.test(token)) {
1640
+ token = (0, import_node_crypto.randomBytes)(32).toString("base64url");
1641
+ req[MINTED] = token;
1642
+ this.setCookie(req, token);
1643
+ }
1644
+ const digest = (0, import_node_crypto.createHash)("sha256").update(token).digest("base64url").slice(0, 32);
1645
+ return {
1646
+ id: `anon:${digest}`,
1647
+ roles: [
1648
+ ...this.roles
1649
+ ]
1650
+ };
1651
+ }
1652
+ setCookie(req, token) {
1653
+ const res = req.res;
1654
+ if (res?.setHeader === void 0 || res.headersSent === true) return;
1655
+ const sameSite = this.options.sameSite ?? "lax";
1656
+ const secureOption = this.options.secure ?? "auto";
1657
+ const secure = sameSite === "none" || (secureOption === "auto" ? isHttps(req) : secureOption);
1658
+ const maxAge = Math.round((this.options.maxAgeDays ?? 365) * 24 * 60 * 60);
1659
+ const cookie = [
1660
+ `${this.cookieName}=${token}`,
1661
+ `Path=${this.options.path ?? "/"}`,
1662
+ `Max-Age=${maxAge}`,
1663
+ "HttpOnly",
1664
+ `SameSite=${sameSite === "none" ? "None" : sameSite === "strict" ? "Strict" : "Lax"}`,
1665
+ ...secure ? [
1666
+ "Secure"
1667
+ ] : []
1668
+ ].join("; ");
1669
+ const existing = res.getHeader?.("Set-Cookie");
1670
+ const list = Array.isArray(existing) ? existing.map(String) : existing !== void 0 ? [
1671
+ String(existing)
1672
+ ] : [];
1673
+ res.setHeader("Set-Cookie", [
1674
+ ...list,
1675
+ cookie
1676
+ ]);
1677
+ }
1678
+ };
1679
+
1680
+ // src/controller/config.controller.ts
1597
1681
  function _ts_decorate7(decorators, target, key, desc) {
1598
1682
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1599
1683
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -1620,6 +1704,91 @@ function _ts_param6(paramIndex, decorator) {
1620
1704
  };
1621
1705
  }
1622
1706
  __name(_ts_param6, "_ts_param");
1707
+ var ConfigController = class {
1708
+ static {
1709
+ __name(this, "ConfigController");
1710
+ }
1711
+ options;
1712
+ actorResolver;
1713
+ staging;
1714
+ models;
1715
+ constructor(options, actorResolver, staging, models) {
1716
+ this.options = options;
1717
+ this.actorResolver = actorResolver;
1718
+ this.staging = staging;
1719
+ this.models = models;
1720
+ }
1721
+ async config(req) {
1722
+ await this.actorResolver.resolve(req);
1723
+ return {
1724
+ attachments: attachmentLimits(this.options, this.staging),
1725
+ models: {
1726
+ enabled: this.models !== void 0
1727
+ },
1728
+ quota: {
1729
+ enforced: this.options.quota !== void 0
1730
+ },
1731
+ identity: {
1732
+ anonymous: this.actorResolver instanceof AnonymousActorResolver
1733
+ }
1734
+ };
1735
+ }
1736
+ };
1737
+ _ts_decorate7([
1738
+ (0, import_common7.Get)(),
1739
+ _ts_param6(0, (0, import_common7.Req)()),
1740
+ _ts_metadata7("design:type", Function),
1741
+ _ts_metadata7("design:paramtypes", [
1742
+ typeof Request === "undefined" ? Object : Request
1743
+ ]),
1744
+ _ts_metadata7("design:returntype", Promise)
1745
+ ], ConfigController.prototype, "config", null);
1746
+ ConfigController = _ts_decorate7([
1747
+ (0, import_common7.Controller)("config"),
1748
+ _ts_param6(0, (0, import_common7.Inject)(import_nestjs_agent_core7.AGENT_OPTIONS)),
1749
+ _ts_param6(1, (0, import_common7.Inject)(import_nestjs_agent_core7.AGENT_ACTOR_RESOLVER)),
1750
+ _ts_param6(2, (0, import_common7.Optional)()),
1751
+ _ts_param6(2, (0, import_common7.Inject)(import_nestjs_agent_core7.AGENT_ATTACHMENT_STAGING)),
1752
+ _ts_param6(3, (0, import_common7.Optional)()),
1753
+ _ts_param6(3, (0, import_common7.Inject)(import_nestjs_agent_core7.AGENT_MODEL_CATALOG)),
1754
+ _ts_metadata7("design:type", Function),
1755
+ _ts_metadata7("design:paramtypes", [
1756
+ typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
1757
+ typeof ActorResolver === "undefined" ? Object : ActorResolver,
1758
+ Object,
1759
+ Object
1760
+ ])
1761
+ ], ConfigController);
1762
+
1763
+ // src/controller/memories.controller.ts
1764
+ var import_nestjs_agent_core8 = require("@dudousxd/nestjs-agent-core");
1765
+ var import_common8 = require("@nestjs/common");
1766
+ function _ts_decorate8(decorators, target, key, desc) {
1767
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1768
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1769
+ r = Reflect.decorate(decorators, target, key, desc);
1770
+ } else {
1771
+ for (var i = decorators.length - 1; i >= 0; i--) {
1772
+ if (d = decorators[i]) {
1773
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1774
+ }
1775
+ }
1776
+ }
1777
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1778
+ }
1779
+ __name(_ts_decorate8, "_ts_decorate");
1780
+ function _ts_metadata8(metadataKey, metadataValue) {
1781
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1782
+ return Reflect.metadata(metadataKey, metadataValue);
1783
+ }
1784
+ }
1785
+ __name(_ts_metadata8, "_ts_metadata");
1786
+ function _ts_param7(paramIndex, decorator) {
1787
+ return function(target, key) {
1788
+ decorator(target, key, paramIndex);
1789
+ };
1790
+ }
1791
+ __name(_ts_param7, "_ts_param");
1623
1792
  var MemoriesController = class {
1624
1793
  static {
1625
1794
  __name(this, "MemoriesController");
@@ -1653,20 +1822,20 @@ var MemoriesController = class {
1653
1822
  */
1654
1823
  async forget(req, id) {
1655
1824
  if (this.memory === void 0) {
1656
- throw new import_common7.NotFoundException("No memory is configured in this deployment.");
1825
+ throw new import_common8.NotFoundException("No memory is configured in this deployment.");
1657
1826
  }
1658
1827
  const actor = await this.actorResolver.resolve(req);
1659
1828
  const digest = await this.unbounded("", actor);
1660
1829
  const entry = digest.entries.find((candidate) => candidate.id === id);
1661
1830
  if (entry === void 0) {
1662
- throw new import_common7.NotFoundException(`No memory with id "${id}".`);
1831
+ throw new import_common8.NotFoundException(`No memory with id "${id}".`);
1663
1832
  }
1664
- const verdict = (0, import_nestjs_agent_core7.memoryForgetVerdict)({
1833
+ const verdict = (0, import_nestjs_agent_core8.memoryForgetVerdict)({
1665
1834
  record: entry,
1666
1835
  actor
1667
1836
  });
1668
1837
  if (!verdict.allowed) {
1669
- throw new import_common7.ForbiddenException(verdict.reason);
1838
+ throw new import_common8.ForbiddenException(verdict.reason);
1670
1839
  }
1671
1840
  return {
1672
1841
  forgotten: await this.memory.provider.forget({
@@ -1680,7 +1849,7 @@ var MemoriesController = class {
1680
1849
  }
1681
1850
  async unbounded(threadId, actor) {
1682
1851
  const config = this.memory;
1683
- return await (0, import_nestjs_agent_core7.offerMemories)({
1852
+ return await (0, import_nestjs_agent_core8.offerMemories)({
1684
1853
  config: {
1685
1854
  ...config,
1686
1855
  maxMemories: Number.POSITIVE_INFINITY
@@ -1692,44 +1861,44 @@ var MemoriesController = class {
1692
1861
  });
1693
1862
  }
1694
1863
  };
1695
- _ts_decorate7([
1696
- (0, import_common7.Get)(),
1697
- _ts_param6(0, (0, import_common7.Req)()),
1698
- _ts_param6(1, (0, import_common7.Query)("threadId")),
1699
- _ts_metadata7("design:type", Function),
1700
- _ts_metadata7("design:paramtypes", [
1864
+ _ts_decorate8([
1865
+ (0, import_common8.Get)(),
1866
+ _ts_param7(0, (0, import_common8.Req)()),
1867
+ _ts_param7(1, (0, import_common8.Query)("threadId")),
1868
+ _ts_metadata8("design:type", Function),
1869
+ _ts_metadata8("design:paramtypes", [
1701
1870
  typeof Request === "undefined" ? Object : Request,
1702
1871
  String
1703
1872
  ]),
1704
- _ts_metadata7("design:returntype", Promise)
1873
+ _ts_metadata8("design:returntype", Promise)
1705
1874
  ], MemoriesController.prototype, "list", null);
1706
- _ts_decorate7([
1707
- (0, import_common7.Delete)(":id"),
1708
- _ts_param6(0, (0, import_common7.Req)()),
1709
- _ts_param6(1, (0, import_common7.Param)("id")),
1710
- _ts_metadata7("design:type", Function),
1711
- _ts_metadata7("design:paramtypes", [
1875
+ _ts_decorate8([
1876
+ (0, import_common8.Delete)(":id"),
1877
+ _ts_param7(0, (0, import_common8.Req)()),
1878
+ _ts_param7(1, (0, import_common8.Param)("id")),
1879
+ _ts_metadata8("design:type", Function),
1880
+ _ts_metadata8("design:paramtypes", [
1712
1881
  typeof Request === "undefined" ? Object : Request,
1713
1882
  String
1714
1883
  ]),
1715
- _ts_metadata7("design:returntype", Promise)
1884
+ _ts_metadata8("design:returntype", Promise)
1716
1885
  ], MemoriesController.prototype, "forget", null);
1717
- MemoriesController = _ts_decorate7([
1718
- (0, import_common7.Controller)("memories"),
1719
- _ts_param6(0, (0, import_common7.Inject)(import_nestjs_agent_core7.AGENT_ACTOR_RESOLVER)),
1720
- _ts_param6(1, (0, import_common7.Optional)()),
1721
- _ts_param6(1, (0, import_common7.Inject)(import_nestjs_agent_core7.AGENT_MEMORY)),
1722
- _ts_metadata7("design:type", Function),
1723
- _ts_metadata7("design:paramtypes", [
1886
+ MemoriesController = _ts_decorate8([
1887
+ (0, import_common8.Controller)("memories"),
1888
+ _ts_param7(0, (0, import_common8.Inject)(import_nestjs_agent_core8.AGENT_ACTOR_RESOLVER)),
1889
+ _ts_param7(1, (0, import_common8.Optional)()),
1890
+ _ts_param7(1, (0, import_common8.Inject)(import_nestjs_agent_core8.AGENT_MEMORY)),
1891
+ _ts_metadata8("design:type", Function),
1892
+ _ts_metadata8("design:paramtypes", [
1724
1893
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
1725
1894
  Object
1726
1895
  ])
1727
1896
  ], MemoriesController);
1728
1897
 
1729
1898
  // src/controller/messages.controller.ts
1730
- var import_nestjs_agent_core8 = require("@dudousxd/nestjs-agent-core");
1731
- var import_common8 = require("@nestjs/common");
1732
- function _ts_decorate8(decorators, target, key, desc) {
1899
+ var import_nestjs_agent_core9 = require("@dudousxd/nestjs-agent-core");
1900
+ var import_common9 = require("@nestjs/common");
1901
+ function _ts_decorate9(decorators, target, key, desc) {
1733
1902
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1734
1903
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1735
1904
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1742,19 +1911,19 @@ function _ts_decorate8(decorators, target, key, desc) {
1742
1911
  }
1743
1912
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1744
1913
  }
1745
- __name(_ts_decorate8, "_ts_decorate");
1746
- function _ts_metadata8(metadataKey, metadataValue) {
1914
+ __name(_ts_decorate9, "_ts_decorate");
1915
+ function _ts_metadata9(metadataKey, metadataValue) {
1747
1916
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1748
1917
  return Reflect.metadata(metadataKey, metadataValue);
1749
1918
  }
1750
1919
  }
1751
- __name(_ts_metadata8, "_ts_metadata");
1752
- function _ts_param7(paramIndex, decorator) {
1920
+ __name(_ts_metadata9, "_ts_metadata");
1921
+ function _ts_param8(paramIndex, decorator) {
1753
1922
  return function(target, key) {
1754
1923
  decorator(target, key, paramIndex);
1755
1924
  };
1756
1925
  }
1757
- __name(_ts_param7, "_ts_param");
1926
+ __name(_ts_param8, "_ts_param");
1758
1927
  var MessagesController = class {
1759
1928
  static {
1760
1929
  __name(this, "MessagesController");
@@ -1782,34 +1951,34 @@ var MessagesController = class {
1782
1951
  };
1783
1952
  }
1784
1953
  };
1785
- _ts_decorate8([
1786
- (0, import_common8.Post)(":id/feedback"),
1787
- (0, import_common8.HttpCode)(200),
1788
- _ts_param7(0, (0, import_common8.Req)()),
1789
- _ts_param7(1, (0, import_common8.Param)("id")),
1790
- _ts_param7(2, (0, import_common8.Body)()),
1791
- _ts_metadata8("design:type", Function),
1792
- _ts_metadata8("design:paramtypes", [
1954
+ _ts_decorate9([
1955
+ (0, import_common9.Post)(":id/feedback"),
1956
+ (0, import_common9.HttpCode)(200),
1957
+ _ts_param8(0, (0, import_common9.Req)()),
1958
+ _ts_param8(1, (0, import_common9.Param)("id")),
1959
+ _ts_param8(2, (0, import_common9.Body)()),
1960
+ _ts_metadata9("design:type", Function),
1961
+ _ts_metadata9("design:paramtypes", [
1793
1962
  typeof Request === "undefined" ? Object : Request,
1794
1963
  String,
1795
1964
  typeof FeedbackBody === "undefined" ? Object : FeedbackBody
1796
1965
  ]),
1797
- _ts_metadata8("design:returntype", Promise)
1966
+ _ts_metadata9("design:returntype", Promise)
1798
1967
  ], MessagesController.prototype, "feedback", null);
1799
- MessagesController = _ts_decorate8([
1800
- (0, import_common8.Controller)("messages"),
1801
- _ts_param7(1, (0, import_common8.Inject)(import_nestjs_agent_core8.AGENT_ACTOR_RESOLVER)),
1802
- _ts_metadata8("design:type", Function),
1803
- _ts_metadata8("design:paramtypes", [
1968
+ MessagesController = _ts_decorate9([
1969
+ (0, import_common9.Controller)("messages"),
1970
+ _ts_param8(1, (0, import_common9.Inject)(import_nestjs_agent_core9.AGENT_ACTOR_RESOLVER)),
1971
+ _ts_metadata9("design:type", Function),
1972
+ _ts_metadata9("design:paramtypes", [
1804
1973
  typeof AgentService === "undefined" ? Object : AgentService,
1805
1974
  typeof ActorResolver === "undefined" ? Object : ActorResolver
1806
1975
  ])
1807
1976
  ], MessagesController);
1808
1977
 
1809
1978
  // src/controller/models.controller.ts
1810
- var import_nestjs_agent_core9 = require("@dudousxd/nestjs-agent-core");
1811
- var import_common9 = require("@nestjs/common");
1812
- function _ts_decorate9(decorators, target, key, desc) {
1979
+ var import_nestjs_agent_core10 = require("@dudousxd/nestjs-agent-core");
1980
+ var import_common10 = require("@nestjs/common");
1981
+ function _ts_decorate10(decorators, target, key, desc) {
1813
1982
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1814
1983
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1815
1984
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1822,19 +1991,19 @@ function _ts_decorate9(decorators, target, key, desc) {
1822
1991
  }
1823
1992
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1824
1993
  }
1825
- __name(_ts_decorate9, "_ts_decorate");
1826
- function _ts_metadata9(metadataKey, metadataValue) {
1994
+ __name(_ts_decorate10, "_ts_decorate");
1995
+ function _ts_metadata10(metadataKey, metadataValue) {
1827
1996
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1828
1997
  return Reflect.metadata(metadataKey, metadataValue);
1829
1998
  }
1830
1999
  }
1831
- __name(_ts_metadata9, "_ts_metadata");
1832
- function _ts_param8(paramIndex, decorator) {
2000
+ __name(_ts_metadata10, "_ts_metadata");
2001
+ function _ts_param9(paramIndex, decorator) {
1833
2002
  return function(target, key) {
1834
2003
  decorator(target, key, paramIndex);
1835
2004
  };
1836
2005
  }
1837
- __name(_ts_param8, "_ts_param");
2006
+ __name(_ts_param9, "_ts_param");
1838
2007
  var ModelsController = class {
1839
2008
  static {
1840
2009
  __name(this, "ModelsController");
@@ -1854,31 +2023,31 @@ var ModelsController = class {
1854
2023
  return this.agent.listModels(actor, agent);
1855
2024
  }
1856
2025
  };
1857
- _ts_decorate9([
1858
- (0, import_common9.Get)(),
1859
- _ts_param8(0, (0, import_common9.Req)()),
1860
- _ts_param8(1, (0, import_common9.Query)("agent")),
1861
- _ts_metadata9("design:type", Function),
1862
- _ts_metadata9("design:paramtypes", [
2026
+ _ts_decorate10([
2027
+ (0, import_common10.Get)(),
2028
+ _ts_param9(0, (0, import_common10.Req)()),
2029
+ _ts_param9(1, (0, import_common10.Query)("agent")),
2030
+ _ts_metadata10("design:type", Function),
2031
+ _ts_metadata10("design:paramtypes", [
1863
2032
  typeof Request === "undefined" ? Object : Request,
1864
2033
  String
1865
2034
  ]),
1866
- _ts_metadata9("design:returntype", Promise)
2035
+ _ts_metadata10("design:returntype", Promise)
1867
2036
  ], ModelsController.prototype, "list", null);
1868
- ModelsController = _ts_decorate9([
1869
- (0, import_common9.Controller)("models"),
1870
- _ts_param8(1, (0, import_common9.Inject)(import_nestjs_agent_core9.AGENT_ACTOR_RESOLVER)),
1871
- _ts_metadata9("design:type", Function),
1872
- _ts_metadata9("design:paramtypes", [
2037
+ ModelsController = _ts_decorate10([
2038
+ (0, import_common10.Controller)("models"),
2039
+ _ts_param9(1, (0, import_common10.Inject)(import_nestjs_agent_core10.AGENT_ACTOR_RESOLVER)),
2040
+ _ts_metadata10("design:type", Function),
2041
+ _ts_metadata10("design:paramtypes", [
1873
2042
  typeof AgentService === "undefined" ? Object : AgentService,
1874
2043
  typeof ActorResolver === "undefined" ? Object : ActorResolver
1875
2044
  ])
1876
2045
  ], ModelsController);
1877
2046
 
1878
2047
  // src/controller/quota.controller.ts
1879
- var import_nestjs_agent_core10 = require("@dudousxd/nestjs-agent-core");
1880
- var import_common10 = require("@nestjs/common");
1881
- function _ts_decorate10(decorators, target, key, desc) {
2048
+ var import_nestjs_agent_core11 = require("@dudousxd/nestjs-agent-core");
2049
+ var import_common11 = require("@nestjs/common");
2050
+ function _ts_decorate11(decorators, target, key, desc) {
1882
2051
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1883
2052
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1884
2053
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1891,19 +2060,19 @@ function _ts_decorate10(decorators, target, key, desc) {
1891
2060
  }
1892
2061
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1893
2062
  }
1894
- __name(_ts_decorate10, "_ts_decorate");
1895
- function _ts_metadata10(metadataKey, metadataValue) {
2063
+ __name(_ts_decorate11, "_ts_decorate");
2064
+ function _ts_metadata11(metadataKey, metadataValue) {
1896
2065
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1897
2066
  return Reflect.metadata(metadataKey, metadataValue);
1898
2067
  }
1899
2068
  }
1900
- __name(_ts_metadata10, "_ts_metadata");
1901
- function _ts_param9(paramIndex, decorator) {
2069
+ __name(_ts_metadata11, "_ts_metadata");
2070
+ function _ts_param10(paramIndex, decorator) {
1902
2071
  return function(target, key) {
1903
2072
  decorator(target, key, paramIndex);
1904
2073
  };
1905
2074
  }
1906
- __name(_ts_param9, "_ts_param");
2075
+ __name(_ts_param10, "_ts_param");
1907
2076
  var QuotaController = class {
1908
2077
  static {
1909
2078
  __name(this, "QuotaController");
@@ -1922,43 +2091,30 @@ var QuotaController = class {
1922
2091
  const actor = await this.actorResolver.resolve(req);
1923
2092
  return this.agent.quotaReport(actor);
1924
2093
  }
1925
- async today(req) {
1926
- const actor = await this.actorResolver.resolve(req);
1927
- return this.agent.quotaToday(actor.id);
1928
- }
1929
2094
  };
1930
- _ts_decorate10([
1931
- (0, import_common10.Get)(),
1932
- _ts_param9(0, (0, import_common10.Req)()),
1933
- _ts_metadata10("design:type", Function),
1934
- _ts_metadata10("design:paramtypes", [
2095
+ _ts_decorate11([
2096
+ (0, import_common11.Get)(),
2097
+ _ts_param10(0, (0, import_common11.Req)()),
2098
+ _ts_metadata11("design:type", Function),
2099
+ _ts_metadata11("design:paramtypes", [
1935
2100
  typeof Request === "undefined" ? Object : Request
1936
2101
  ]),
1937
- _ts_metadata10("design:returntype", Promise)
2102
+ _ts_metadata11("design:returntype", Promise)
1938
2103
  ], QuotaController.prototype, "report", null);
1939
- _ts_decorate10([
1940
- (0, import_common10.Get)("today"),
1941
- _ts_param9(0, (0, import_common10.Req)()),
1942
- _ts_metadata10("design:type", Function),
1943
- _ts_metadata10("design:paramtypes", [
1944
- typeof Request === "undefined" ? Object : Request
1945
- ]),
1946
- _ts_metadata10("design:returntype", Promise)
1947
- ], QuotaController.prototype, "today", null);
1948
- QuotaController = _ts_decorate10([
1949
- (0, import_common10.Controller)("quota"),
1950
- _ts_param9(1, (0, import_common10.Inject)(import_nestjs_agent_core10.AGENT_ACTOR_RESOLVER)),
1951
- _ts_metadata10("design:type", Function),
1952
- _ts_metadata10("design:paramtypes", [
2104
+ QuotaController = _ts_decorate11([
2105
+ (0, import_common11.Controller)("quota"),
2106
+ _ts_param10(1, (0, import_common11.Inject)(import_nestjs_agent_core11.AGENT_ACTOR_RESOLVER)),
2107
+ _ts_metadata11("design:type", Function),
2108
+ _ts_metadata11("design:paramtypes", [
1953
2109
  typeof AgentService === "undefined" ? Object : AgentService,
1954
2110
  typeof ActorResolver === "undefined" ? Object : ActorResolver
1955
2111
  ])
1956
2112
  ], QuotaController);
1957
2113
 
1958
2114
  // src/controller/skills.controller.ts
1959
- var import_nestjs_agent_core11 = require("@dudousxd/nestjs-agent-core");
1960
- var import_common11 = require("@nestjs/common");
1961
- function _ts_decorate11(decorators, target, key, desc) {
2115
+ var import_nestjs_agent_core12 = require("@dudousxd/nestjs-agent-core");
2116
+ var import_common12 = require("@nestjs/common");
2117
+ function _ts_decorate12(decorators, target, key, desc) {
1962
2118
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1963
2119
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1964
2120
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1971,19 +2127,19 @@ function _ts_decorate11(decorators, target, key, desc) {
1971
2127
  }
1972
2128
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1973
2129
  }
1974
- __name(_ts_decorate11, "_ts_decorate");
1975
- function _ts_metadata11(metadataKey, metadataValue) {
2130
+ __name(_ts_decorate12, "_ts_decorate");
2131
+ function _ts_metadata12(metadataKey, metadataValue) {
1976
2132
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1977
2133
  return Reflect.metadata(metadataKey, metadataValue);
1978
2134
  }
1979
2135
  }
1980
- __name(_ts_metadata11, "_ts_metadata");
1981
- function _ts_param10(paramIndex, decorator) {
2136
+ __name(_ts_metadata12, "_ts_metadata");
2137
+ function _ts_param11(paramIndex, decorator) {
1982
2138
  return function(target, key) {
1983
2139
  decorator(target, key, paramIndex);
1984
2140
  };
1985
2141
  }
1986
- __name(_ts_param10, "_ts_param");
2142
+ __name(_ts_param11, "_ts_param");
1987
2143
  var SkillsController = class {
1988
2144
  static {
1989
2145
  __name(this, "SkillsController");
@@ -1999,40 +2155,40 @@ var SkillsController = class {
1999
2155
  return [];
2000
2156
  }
2001
2157
  const actor = await this.actorResolver.resolve(req);
2002
- const offer = await (0, import_nestjs_agent_core11.offerSkills)(this.skills, {
2158
+ const offer = await (0, import_nestjs_agent_core12.offerSkills)(this.skills, {
2003
2159
  actor,
2004
2160
  threadId: threadId ?? ""
2005
2161
  });
2006
2162
  return offer.entries;
2007
2163
  }
2008
2164
  };
2009
- _ts_decorate11([
2010
- (0, import_common11.Get)(),
2011
- _ts_param10(0, (0, import_common11.Req)()),
2012
- _ts_param10(1, (0, import_common11.Query)("threadId")),
2013
- _ts_metadata11("design:type", Function),
2014
- _ts_metadata11("design:paramtypes", [
2165
+ _ts_decorate12([
2166
+ (0, import_common12.Get)(),
2167
+ _ts_param11(0, (0, import_common12.Req)()),
2168
+ _ts_param11(1, (0, import_common12.Query)("threadId")),
2169
+ _ts_metadata12("design:type", Function),
2170
+ _ts_metadata12("design:paramtypes", [
2015
2171
  typeof Request === "undefined" ? Object : Request,
2016
2172
  String
2017
2173
  ]),
2018
- _ts_metadata11("design:returntype", Promise)
2174
+ _ts_metadata12("design:returntype", Promise)
2019
2175
  ], SkillsController.prototype, "list", null);
2020
- SkillsController = _ts_decorate11([
2021
- (0, import_common11.Controller)("skills"),
2022
- _ts_param10(0, (0, import_common11.Inject)(import_nestjs_agent_core11.AGENT_ACTOR_RESOLVER)),
2023
- _ts_param10(1, (0, import_common11.Optional)()),
2024
- _ts_param10(1, (0, import_common11.Inject)(import_nestjs_agent_core11.AGENT_SKILLS)),
2025
- _ts_metadata11("design:type", Function),
2026
- _ts_metadata11("design:paramtypes", [
2176
+ SkillsController = _ts_decorate12([
2177
+ (0, import_common12.Controller)("skills"),
2178
+ _ts_param11(0, (0, import_common12.Inject)(import_nestjs_agent_core12.AGENT_ACTOR_RESOLVER)),
2179
+ _ts_param11(1, (0, import_common12.Optional)()),
2180
+ _ts_param11(1, (0, import_common12.Inject)(import_nestjs_agent_core12.AGENT_SKILLS)),
2181
+ _ts_metadata12("design:type", Function),
2182
+ _ts_metadata12("design:paramtypes", [
2027
2183
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
2028
2184
  Object
2029
2185
  ])
2030
2186
  ], SkillsController);
2031
2187
 
2032
2188
  // src/controller/threads.controller.ts
2033
- var import_nestjs_agent_core12 = require("@dudousxd/nestjs-agent-core");
2034
- var import_common12 = require("@nestjs/common");
2035
- function _ts_decorate12(decorators, target, key, desc) {
2189
+ var import_nestjs_agent_core13 = require("@dudousxd/nestjs-agent-core");
2190
+ var import_common13 = require("@nestjs/common");
2191
+ function _ts_decorate13(decorators, target, key, desc) {
2036
2192
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2037
2193
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2038
2194
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2045,19 +2201,19 @@ function _ts_decorate12(decorators, target, key, desc) {
2045
2201
  }
2046
2202
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2047
2203
  }
2048
- __name(_ts_decorate12, "_ts_decorate");
2049
- function _ts_metadata12(metadataKey, metadataValue) {
2204
+ __name(_ts_decorate13, "_ts_decorate");
2205
+ function _ts_metadata13(metadataKey, metadataValue) {
2050
2206
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2051
2207
  return Reflect.metadata(metadataKey, metadataValue);
2052
2208
  }
2053
2209
  }
2054
- __name(_ts_metadata12, "_ts_metadata");
2055
- function _ts_param11(paramIndex, decorator) {
2210
+ __name(_ts_metadata13, "_ts_metadata");
2211
+ function _ts_param12(paramIndex, decorator) {
2056
2212
  return function(target, key) {
2057
2213
  decorator(target, key, paramIndex);
2058
2214
  };
2059
2215
  }
2060
- __name(_ts_param11, "_ts_param");
2216
+ __name(_ts_param12, "_ts_param");
2061
2217
  var ThreadsController = class {
2062
2218
  static {
2063
2219
  __name(this, "ThreadsController");
@@ -2124,101 +2280,101 @@ var ThreadsController = class {
2124
2280
  };
2125
2281
  }
2126
2282
  };
2127
- _ts_decorate12([
2128
- (0, import_common12.Get)(),
2129
- _ts_param11(0, (0, import_common12.Req)()),
2130
- _ts_metadata12("design:type", Function),
2131
- _ts_metadata12("design:paramtypes", [
2283
+ _ts_decorate13([
2284
+ (0, import_common13.Get)(),
2285
+ _ts_param12(0, (0, import_common13.Req)()),
2286
+ _ts_metadata13("design:type", Function),
2287
+ _ts_metadata13("design:paramtypes", [
2132
2288
  typeof Request === "undefined" ? Object : Request
2133
2289
  ]),
2134
- _ts_metadata12("design:returntype", Promise)
2290
+ _ts_metadata13("design:returntype", Promise)
2135
2291
  ], ThreadsController.prototype, "list", null);
2136
- _ts_decorate12([
2137
- (0, import_common12.Get)(":id"),
2138
- _ts_param11(0, (0, import_common12.Req)()),
2139
- _ts_param11(1, (0, import_common12.Param)("id")),
2140
- _ts_metadata12("design:type", Function),
2141
- _ts_metadata12("design:paramtypes", [
2292
+ _ts_decorate13([
2293
+ (0, import_common13.Get)(":id"),
2294
+ _ts_param12(0, (0, import_common13.Req)()),
2295
+ _ts_param12(1, (0, import_common13.Param)("id")),
2296
+ _ts_metadata13("design:type", Function),
2297
+ _ts_metadata13("design:paramtypes", [
2142
2298
  typeof Request === "undefined" ? Object : Request,
2143
2299
  String
2144
2300
  ]),
2145
- _ts_metadata12("design:returntype", Promise)
2301
+ _ts_metadata13("design:returntype", Promise)
2146
2302
  ], ThreadsController.prototype, "detail", null);
2147
- _ts_decorate12([
2148
- (0, import_common12.Delete)(":id"),
2149
- _ts_param11(0, (0, import_common12.Req)()),
2150
- _ts_param11(1, (0, import_common12.Param)("id")),
2151
- _ts_metadata12("design:type", Function),
2152
- _ts_metadata12("design:paramtypes", [
2303
+ _ts_decorate13([
2304
+ (0, import_common13.Delete)(":id"),
2305
+ _ts_param12(0, (0, import_common13.Req)()),
2306
+ _ts_param12(1, (0, import_common13.Param)("id")),
2307
+ _ts_metadata13("design:type", Function),
2308
+ _ts_metadata13("design:paramtypes", [
2153
2309
  typeof Request === "undefined" ? Object : Request,
2154
2310
  String
2155
2311
  ]),
2156
- _ts_metadata12("design:returntype", Promise)
2312
+ _ts_metadata13("design:returntype", Promise)
2157
2313
  ], ThreadsController.prototype, "remove", null);
2158
- _ts_decorate12([
2159
- (0, import_common12.Post)(":id/fork-from/:messageId"),
2160
- _ts_param11(0, (0, import_common12.Req)()),
2161
- _ts_param11(1, (0, import_common12.Param)("id")),
2162
- _ts_param11(2, (0, import_common12.Param)("messageId")),
2163
- _ts_metadata12("design:type", Function),
2164
- _ts_metadata12("design:paramtypes", [
2314
+ _ts_decorate13([
2315
+ (0, import_common13.Post)(":id/fork-from/:messageId"),
2316
+ _ts_param12(0, (0, import_common13.Req)()),
2317
+ _ts_param12(1, (0, import_common13.Param)("id")),
2318
+ _ts_param12(2, (0, import_common13.Param)("messageId")),
2319
+ _ts_metadata13("design:type", Function),
2320
+ _ts_metadata13("design:paramtypes", [
2165
2321
  typeof Request === "undefined" ? Object : Request,
2166
2322
  String,
2167
2323
  String
2168
2324
  ]),
2169
- _ts_metadata12("design:returntype", Promise)
2325
+ _ts_metadata13("design:returntype", Promise)
2170
2326
  ], ThreadsController.prototype, "fork", null);
2171
- _ts_decorate12([
2172
- (0, import_common12.Patch)(":id"),
2173
- _ts_param11(0, (0, import_common12.Req)()),
2174
- _ts_param11(1, (0, import_common12.Param)("id")),
2175
- _ts_param11(2, (0, import_common12.Body)()),
2176
- _ts_metadata12("design:type", Function),
2177
- _ts_metadata12("design:paramtypes", [
2327
+ _ts_decorate13([
2328
+ (0, import_common13.Patch)(":id"),
2329
+ _ts_param12(0, (0, import_common13.Req)()),
2330
+ _ts_param12(1, (0, import_common13.Param)("id")),
2331
+ _ts_param12(2, (0, import_common13.Body)()),
2332
+ _ts_metadata13("design:type", Function),
2333
+ _ts_metadata13("design:paramtypes", [
2178
2334
  typeof Request === "undefined" ? Object : Request,
2179
2335
  String,
2180
2336
  typeof UpdateThreadBody === "undefined" ? Object : UpdateThreadBody
2181
2337
  ]),
2182
- _ts_metadata12("design:returntype", Promise)
2338
+ _ts_metadata13("design:returntype", Promise)
2183
2339
  ], ThreadsController.prototype, "update", null);
2184
- _ts_decorate12([
2185
- (0, import_common12.Post)(":id/promote"),
2186
- _ts_param11(0, (0, import_common12.Req)()),
2187
- _ts_param11(1, (0, import_common12.Param)("id")),
2188
- _ts_metadata12("design:type", Function),
2189
- _ts_metadata12("design:paramtypes", [
2340
+ _ts_decorate13([
2341
+ (0, import_common13.Post)(":id/promote"),
2342
+ _ts_param12(0, (0, import_common13.Req)()),
2343
+ _ts_param12(1, (0, import_common13.Param)("id")),
2344
+ _ts_metadata13("design:type", Function),
2345
+ _ts_metadata13("design:paramtypes", [
2190
2346
  typeof Request === "undefined" ? Object : Request,
2191
2347
  String
2192
2348
  ]),
2193
- _ts_metadata12("design:returntype", Promise)
2349
+ _ts_metadata13("design:returntype", Promise)
2194
2350
  ], ThreadsController.prototype, "promote", null);
2195
- _ts_decorate12([
2196
- (0, import_common12.Delete)(":id/from/:messageId"),
2197
- _ts_param11(0, (0, import_common12.Req)()),
2198
- _ts_param11(1, (0, import_common12.Param)("id")),
2199
- _ts_param11(2, (0, import_common12.Param)("messageId")),
2200
- _ts_metadata12("design:type", Function),
2201
- _ts_metadata12("design:paramtypes", [
2351
+ _ts_decorate13([
2352
+ (0, import_common13.Delete)(":id/from/:messageId"),
2353
+ _ts_param12(0, (0, import_common13.Req)()),
2354
+ _ts_param12(1, (0, import_common13.Param)("id")),
2355
+ _ts_param12(2, (0, import_common13.Param)("messageId")),
2356
+ _ts_metadata13("design:type", Function),
2357
+ _ts_metadata13("design:paramtypes", [
2202
2358
  typeof Request === "undefined" ? Object : Request,
2203
2359
  String,
2204
2360
  String
2205
2361
  ]),
2206
- _ts_metadata12("design:returntype", Promise)
2362
+ _ts_metadata13("design:returntype", Promise)
2207
2363
  ], ThreadsController.prototype, "truncateFrom", null);
2208
- ThreadsController = _ts_decorate12([
2209
- (0, import_common12.Controller)("threads"),
2210
- _ts_param11(1, (0, import_common12.Inject)(import_nestjs_agent_core12.AGENT_ACTOR_RESOLVER)),
2211
- _ts_metadata12("design:type", Function),
2212
- _ts_metadata12("design:paramtypes", [
2364
+ ThreadsController = _ts_decorate13([
2365
+ (0, import_common13.Controller)("threads"),
2366
+ _ts_param12(1, (0, import_common13.Inject)(import_nestjs_agent_core13.AGENT_ACTOR_RESOLVER)),
2367
+ _ts_metadata13("design:type", Function),
2368
+ _ts_metadata13("design:paramtypes", [
2213
2369
  typeof AgentService === "undefined" ? Object : AgentService,
2214
2370
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2215
2371
  ])
2216
2372
  ], ThreadsController);
2217
2373
 
2218
2374
  // src/controller/tool-call.controller.ts
2219
- var import_nestjs_agent_core13 = require("@dudousxd/nestjs-agent-core");
2220
- var import_common13 = require("@nestjs/common");
2221
- function _ts_decorate13(decorators, target, key, desc) {
2375
+ var import_nestjs_agent_core14 = require("@dudousxd/nestjs-agent-core");
2376
+ var import_common14 = require("@nestjs/common");
2377
+ function _ts_decorate14(decorators, target, key, desc) {
2222
2378
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2223
2379
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2224
2380
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2231,19 +2387,19 @@ function _ts_decorate13(decorators, target, key, desc) {
2231
2387
  }
2232
2388
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2233
2389
  }
2234
- __name(_ts_decorate13, "_ts_decorate");
2235
- function _ts_metadata13(metadataKey, metadataValue) {
2390
+ __name(_ts_decorate14, "_ts_decorate");
2391
+ function _ts_metadata14(metadataKey, metadataValue) {
2236
2392
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2237
2393
  return Reflect.metadata(metadataKey, metadataValue);
2238
2394
  }
2239
2395
  }
2240
- __name(_ts_metadata13, "_ts_metadata");
2241
- function _ts_param12(paramIndex, decorator) {
2396
+ __name(_ts_metadata14, "_ts_metadata");
2397
+ function _ts_param13(paramIndex, decorator) {
2242
2398
  return function(target, key) {
2243
2399
  decorator(target, key, paramIndex);
2244
2400
  };
2245
2401
  }
2246
- __name(_ts_param12, "_ts_param");
2402
+ __name(_ts_param13, "_ts_param");
2247
2403
  var MAX_ANSWERED_QUESTIONS = 100;
2248
2404
  var MAX_VALUES_PER_QUESTION = 100;
2249
2405
  var MAX_ANSWER_VALUE_LENGTH = 4096;
@@ -2252,7 +2408,7 @@ var MAX_VIA_LENGTH = 64;
2252
2408
  var DEFAULT_VIA = "web";
2253
2409
  function toolCallId(claimed) {
2254
2410
  if (typeof claimed !== "string" || claimed.length === 0) {
2255
- throw new import_common13.BadRequestException("toolCallId must be a non-empty string");
2411
+ throw new import_common14.BadRequestException("toolCallId must be a non-empty string");
2256
2412
  }
2257
2413
  return claimed;
2258
2414
  }
@@ -2262,10 +2418,10 @@ function rejectReason(claimed) {
2262
2418
  return void 0;
2263
2419
  }
2264
2420
  if (typeof claimed !== "string") {
2265
- throw new import_common13.BadRequestException("reason must be a string");
2421
+ throw new import_common14.BadRequestException("reason must be a string");
2266
2422
  }
2267
2423
  if (claimed.length > MAX_REJECT_REASON_LENGTH) {
2268
- throw new import_common13.BadRequestException(`reason must be at most ${MAX_REJECT_REASON_LENGTH} characters`);
2424
+ throw new import_common14.BadRequestException(`reason must be at most ${MAX_REJECT_REASON_LENGTH} characters`);
2269
2425
  }
2270
2426
  return claimed;
2271
2427
  }
@@ -2275,7 +2431,7 @@ function remember(claimed) {
2275
2431
  return false;
2276
2432
  }
2277
2433
  if (typeof claimed !== "boolean") {
2278
- throw new import_common13.BadRequestException("remember must be a boolean");
2434
+ throw new import_common14.BadRequestException("remember must be a boolean");
2279
2435
  }
2280
2436
  return claimed;
2281
2437
  }
@@ -2285,7 +2441,7 @@ function via(claimed) {
2285
2441
  return DEFAULT_VIA;
2286
2442
  }
2287
2443
  if (typeof claimed !== "string" || claimed.length === 0 || claimed.length > MAX_VIA_LENGTH) {
2288
- throw new import_common13.BadRequestException(`via must be a string of 1-${MAX_VIA_LENGTH} characters`);
2444
+ throw new import_common14.BadRequestException(`via must be a string of 1-${MAX_VIA_LENGTH} characters`);
2289
2445
  }
2290
2446
  return claimed;
2291
2447
  }
@@ -2295,26 +2451,26 @@ function answers(claimed) {
2295
2451
  return void 0;
2296
2452
  }
2297
2453
  if (typeof claimed !== "object" || claimed === null || Array.isArray(claimed)) {
2298
- throw new import_common13.BadRequestException("answers must be an object of questionId \u2192 chosen values");
2454
+ throw new import_common14.BadRequestException("answers must be an object of questionId \u2192 chosen values");
2299
2455
  }
2300
2456
  const entries = Object.entries(claimed);
2301
2457
  if (entries.length > MAX_ANSWERED_QUESTIONS) {
2302
- throw new import_common13.BadRequestException(`answers may cover at most ${MAX_ANSWERED_QUESTIONS} questions`);
2458
+ throw new import_common14.BadRequestException(`answers may cover at most ${MAX_ANSWERED_QUESTIONS} questions`);
2303
2459
  }
2304
2460
  const validated = /* @__PURE__ */ Object.create(null);
2305
2461
  for (const [questionId, values] of entries) {
2306
2462
  if (!Array.isArray(values)) {
2307
- throw new import_common13.BadRequestException(`answers["${questionId}"] must be an array of chosen values`);
2463
+ throw new import_common14.BadRequestException(`answers["${questionId}"] must be an array of chosen values`);
2308
2464
  }
2309
2465
  if (values.length > MAX_VALUES_PER_QUESTION) {
2310
- throw new import_common13.BadRequestException(`answers["${questionId}"] may carry at most ${MAX_VALUES_PER_QUESTION} values`);
2466
+ throw new import_common14.BadRequestException(`answers["${questionId}"] may carry at most ${MAX_VALUES_PER_QUESTION} values`);
2311
2467
  }
2312
2468
  for (const value of values) {
2313
2469
  if (typeof value !== "string") {
2314
- throw new import_common13.BadRequestException(`answers["${questionId}"] must contain only strings`);
2470
+ throw new import_common14.BadRequestException(`answers["${questionId}"] must contain only strings`);
2315
2471
  }
2316
2472
  if (value.length > MAX_ANSWER_VALUE_LENGTH) {
2317
- throw new import_common13.BadRequestException(`answers["${questionId}"] values must be at most ${MAX_ANSWER_VALUE_LENGTH} characters`);
2473
+ throw new import_common14.BadRequestException(`answers["${questionId}"] values must be at most ${MAX_ANSWER_VALUE_LENGTH} characters`);
2318
2474
  }
2319
2475
  }
2320
2476
  validated[questionId] = values;
@@ -2372,64 +2528,64 @@ var ToolCallController = class {
2372
2528
  };
2373
2529
  }
2374
2530
  };
2375
- _ts_decorate13([
2376
- (0, import_common13.Post)("approve"),
2377
- _ts_param12(0, (0, import_common13.Req)()),
2378
- _ts_param12(1, (0, import_common13.Body)()),
2379
- _ts_metadata13("design:type", Function),
2380
- _ts_metadata13("design:paramtypes", [
2531
+ _ts_decorate14([
2532
+ (0, import_common14.Post)("approve"),
2533
+ _ts_param13(0, (0, import_common14.Req)()),
2534
+ _ts_param13(1, (0, import_common14.Body)()),
2535
+ _ts_metadata14("design:type", Function),
2536
+ _ts_metadata14("design:paramtypes", [
2381
2537
  typeof Request === "undefined" ? Object : Request,
2382
2538
  typeof ApproveBody === "undefined" ? Object : ApproveBody
2383
2539
  ]),
2384
- _ts_metadata13("design:returntype", Promise)
2540
+ _ts_metadata14("design:returntype", Promise)
2385
2541
  ], ToolCallController.prototype, "approve", null);
2386
- _ts_decorate13([
2387
- (0, import_common13.Post)("reject"),
2388
- _ts_param12(0, (0, import_common13.Req)()),
2389
- _ts_param12(1, (0, import_common13.Body)()),
2390
- _ts_metadata13("design:type", Function),
2391
- _ts_metadata13("design:paramtypes", [
2542
+ _ts_decorate14([
2543
+ (0, import_common14.Post)("reject"),
2544
+ _ts_param13(0, (0, import_common14.Req)()),
2545
+ _ts_param13(1, (0, import_common14.Body)()),
2546
+ _ts_metadata14("design:type", Function),
2547
+ _ts_metadata14("design:paramtypes", [
2392
2548
  typeof Request === "undefined" ? Object : Request,
2393
2549
  typeof RejectBody === "undefined" ? Object : RejectBody
2394
2550
  ]),
2395
- _ts_metadata13("design:returntype", Promise)
2551
+ _ts_metadata14("design:returntype", Promise)
2396
2552
  ], ToolCallController.prototype, "reject", null);
2397
- _ts_decorate13([
2398
- (0, import_common13.Post)("answer"),
2399
- _ts_param12(0, (0, import_common13.Req)()),
2400
- _ts_param12(1, (0, import_common13.Body)()),
2401
- _ts_metadata13("design:type", Function),
2402
- _ts_metadata13("design:paramtypes", [
2553
+ _ts_decorate14([
2554
+ (0, import_common14.Post)("answer"),
2555
+ _ts_param13(0, (0, import_common14.Req)()),
2556
+ _ts_param13(1, (0, import_common14.Body)()),
2557
+ _ts_metadata14("design:type", Function),
2558
+ _ts_metadata14("design:paramtypes", [
2403
2559
  typeof Request === "undefined" ? Object : Request,
2404
2560
  typeof AnswerBody === "undefined" ? Object : AnswerBody
2405
2561
  ]),
2406
- _ts_metadata13("design:returntype", Promise)
2562
+ _ts_metadata14("design:returntype", Promise)
2407
2563
  ], ToolCallController.prototype, "answer", null);
2408
- _ts_decorate13([
2409
- (0, import_common13.Post)("skip"),
2410
- _ts_param12(0, (0, import_common13.Req)()),
2411
- _ts_param12(1, (0, import_common13.Body)()),
2412
- _ts_metadata13("design:type", Function),
2413
- _ts_metadata13("design:paramtypes", [
2564
+ _ts_decorate14([
2565
+ (0, import_common14.Post)("skip"),
2566
+ _ts_param13(0, (0, import_common14.Req)()),
2567
+ _ts_param13(1, (0, import_common14.Body)()),
2568
+ _ts_metadata14("design:type", Function),
2569
+ _ts_metadata14("design:paramtypes", [
2414
2570
  typeof Request === "undefined" ? Object : Request,
2415
2571
  Object
2416
2572
  ]),
2417
- _ts_metadata13("design:returntype", Promise)
2573
+ _ts_metadata14("design:returntype", Promise)
2418
2574
  ], ToolCallController.prototype, "skip", null);
2419
- ToolCallController = _ts_decorate13([
2420
- (0, import_common13.Controller)("tool-call"),
2421
- _ts_param12(1, (0, import_common13.Inject)(import_nestjs_agent_core13.AGENT_ACTOR_RESOLVER)),
2422
- _ts_metadata13("design:type", Function),
2423
- _ts_metadata13("design:paramtypes", [
2575
+ ToolCallController = _ts_decorate14([
2576
+ (0, import_common14.Controller)("tool-call"),
2577
+ _ts_param13(1, (0, import_common14.Inject)(import_nestjs_agent_core14.AGENT_ACTOR_RESOLVER)),
2578
+ _ts_metadata14("design:type", Function),
2579
+ _ts_metadata14("design:paramtypes", [
2424
2580
  typeof AgentService === "undefined" ? Object : AgentService,
2425
2581
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2426
2582
  ])
2427
2583
  ], ToolCallController);
2428
2584
 
2429
2585
  // src/controller/tools.controller.ts
2430
- var import_nestjs_agent_core14 = require("@dudousxd/nestjs-agent-core");
2431
- var import_common14 = require("@nestjs/common");
2432
- function _ts_decorate14(decorators, target, key, desc) {
2586
+ var import_nestjs_agent_core15 = require("@dudousxd/nestjs-agent-core");
2587
+ var import_common15 = require("@nestjs/common");
2588
+ function _ts_decorate15(decorators, target, key, desc) {
2433
2589
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2434
2590
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2435
2591
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2442,19 +2598,19 @@ function _ts_decorate14(decorators, target, key, desc) {
2442
2598
  }
2443
2599
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2444
2600
  }
2445
- __name(_ts_decorate14, "_ts_decorate");
2446
- function _ts_metadata14(metadataKey, metadataValue) {
2601
+ __name(_ts_decorate15, "_ts_decorate");
2602
+ function _ts_metadata15(metadataKey, metadataValue) {
2447
2603
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2448
2604
  return Reflect.metadata(metadataKey, metadataValue);
2449
2605
  }
2450
2606
  }
2451
- __name(_ts_metadata14, "_ts_metadata");
2452
- function _ts_param13(paramIndex, decorator) {
2607
+ __name(_ts_metadata15, "_ts_metadata");
2608
+ function _ts_param14(paramIndex, decorator) {
2453
2609
  return function(target, key) {
2454
2610
  decorator(target, key, paramIndex);
2455
2611
  };
2456
2612
  }
2457
- __name(_ts_param13, "_ts_param");
2613
+ __name(_ts_param14, "_ts_param");
2458
2614
  var ToolsController = class {
2459
2615
  static {
2460
2616
  __name(this, "ToolsController");
@@ -2469,7 +2625,7 @@ var ToolsController = class {
2469
2625
  }
2470
2626
  async list(req, agent) {
2471
2627
  if (agent !== void 0 && this.agents.get(agent) === void 0) {
2472
- throw new import_common14.NotFoundException(`No agent named "${agent}"`);
2628
+ throw new import_common15.NotFoundException(`No agent named "${agent}"`);
2473
2629
  }
2474
2630
  const actor = await this.actorResolver.resolve(req);
2475
2631
  const deps = this.depsFactory.forAgent(agent);
@@ -2483,33 +2639,33 @@ var ToolsController = class {
2483
2639
  }));
2484
2640
  }
2485
2641
  };
2486
- _ts_decorate14([
2487
- (0, import_common14.Get)(),
2488
- _ts_param13(0, (0, import_common14.Req)()),
2489
- _ts_param13(1, (0, import_common14.Query)("agent")),
2490
- _ts_metadata14("design:type", Function),
2491
- _ts_metadata14("design:paramtypes", [
2642
+ _ts_decorate15([
2643
+ (0, import_common15.Get)(),
2644
+ _ts_param14(0, (0, import_common15.Req)()),
2645
+ _ts_param14(1, (0, import_common15.Query)("agent")),
2646
+ _ts_metadata15("design:type", Function),
2647
+ _ts_metadata15("design:paramtypes", [
2492
2648
  typeof Request === "undefined" ? Object : Request,
2493
2649
  String
2494
2650
  ]),
2495
- _ts_metadata14("design:returntype", Promise)
2651
+ _ts_metadata15("design:returntype", Promise)
2496
2652
  ], ToolsController.prototype, "list", null);
2497
- ToolsController = _ts_decorate14([
2498
- (0, import_common14.Controller)("tools"),
2499
- _ts_param13(0, (0, import_common14.Inject)(import_nestjs_agent_core14.AGENT_ACTOR_RESOLVER)),
2500
- _ts_param13(1, (0, import_common14.Inject)(import_nestjs_agent_core14.AGENT_DEPS_FACTORY)),
2501
- _ts_param13(2, (0, import_common14.Inject)(import_nestjs_agent_core14.AGENT_REGISTRY)),
2502
- _ts_metadata14("design:type", Function),
2503
- _ts_metadata14("design:paramtypes", [
2653
+ ToolsController = _ts_decorate15([
2654
+ (0, import_common15.Controller)("tools"),
2655
+ _ts_param14(0, (0, import_common15.Inject)(import_nestjs_agent_core15.AGENT_ACTOR_RESOLVER)),
2656
+ _ts_param14(1, (0, import_common15.Inject)(import_nestjs_agent_core15.AGENT_DEPS_FACTORY)),
2657
+ _ts_param14(2, (0, import_common15.Inject)(import_nestjs_agent_core15.AGENT_REGISTRY)),
2658
+ _ts_metadata15("design:type", Function),
2659
+ _ts_metadata15("design:paramtypes", [
2504
2660
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
2505
2661
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
2506
- typeof import_nestjs_agent_core14.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core14.AgentRegistry
2662
+ typeof import_nestjs_agent_core15.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core15.AgentRegistry
2507
2663
  ])
2508
2664
  ], ToolsController);
2509
2665
 
2510
2666
  // src/discovery/agent-discovery.service.ts
2511
- var import_nestjs_agent_core15 = require("@dudousxd/nestjs-agent-core");
2512
- var import_common15 = require("@nestjs/common");
2667
+ var import_nestjs_agent_core16 = require("@dudousxd/nestjs-agent-core");
2668
+ var import_common16 = require("@nestjs/common");
2513
2669
  var import_core = require("@nestjs/core");
2514
2670
 
2515
2671
  // src/decorator/agent.decorator.ts
@@ -2544,7 +2700,7 @@ function SystemPromptContributor() {
2544
2700
  __name(SystemPromptContributor, "SystemPromptContributor");
2545
2701
 
2546
2702
  // src/discovery/agent-discovery.service.ts
2547
- function _ts_decorate15(decorators, target, key, desc) {
2703
+ function _ts_decorate16(decorators, target, key, desc) {
2548
2704
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2549
2705
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2550
2706
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2557,19 +2713,19 @@ function _ts_decorate15(decorators, target, key, desc) {
2557
2713
  }
2558
2714
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2559
2715
  }
2560
- __name(_ts_decorate15, "_ts_decorate");
2561
- function _ts_metadata15(metadataKey, metadataValue) {
2716
+ __name(_ts_decorate16, "_ts_decorate");
2717
+ function _ts_metadata16(metadataKey, metadataValue) {
2562
2718
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2563
2719
  return Reflect.metadata(metadataKey, metadataValue);
2564
2720
  }
2565
2721
  }
2566
- __name(_ts_metadata15, "_ts_metadata");
2567
- function _ts_param14(paramIndex, decorator) {
2722
+ __name(_ts_metadata16, "_ts_metadata");
2723
+ function _ts_param15(paramIndex, decorator) {
2568
2724
  return function(target, key) {
2569
2725
  decorator(target, key, paramIndex);
2570
2726
  };
2571
2727
  }
2572
- __name(_ts_param14, "_ts_param");
2728
+ __name(_ts_param15, "_ts_param");
2573
2729
  var AgentDiscoveryService = class _AgentDiscoveryService {
2574
2730
  static {
2575
2731
  __name(this, "AgentDiscoveryService");
@@ -2578,7 +2734,7 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
2578
2734
  scanner;
2579
2735
  registry;
2580
2736
  contributors;
2581
- logger = new import_common15.Logger(_AgentDiscoveryService.name);
2737
+ logger = new import_common16.Logger(_AgentDiscoveryService.name);
2582
2738
  constructor(discovery, scanner, registry, contributors) {
2583
2739
  this.discovery = discovery;
2584
2740
  this.scanner = scanner;
@@ -2696,31 +2852,45 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
2696
2852
  return (ctx) => candidate.call(instance, ctx);
2697
2853
  }
2698
2854
  };
2699
- AgentDiscoveryService = _ts_decorate15([
2700
- (0, import_common15.Injectable)(),
2701
- _ts_param14(2, (0, import_common15.Inject)(import_nestjs_agent_core15.AGENT_REGISTRY)),
2702
- _ts_param14(3, (0, import_common15.Inject)(import_nestjs_agent_core15.AGENT_PROMPT_CONTRIBUTORS)),
2703
- _ts_metadata15("design:type", Function),
2704
- _ts_metadata15("design:paramtypes", [
2855
+ AgentDiscoveryService = _ts_decorate16([
2856
+ (0, import_common16.Injectable)(),
2857
+ _ts_param15(2, (0, import_common16.Inject)(import_nestjs_agent_core16.AGENT_REGISTRY)),
2858
+ _ts_param15(3, (0, import_common16.Inject)(import_nestjs_agent_core16.AGENT_PROMPT_CONTRIBUTORS)),
2859
+ _ts_metadata16("design:type", Function),
2860
+ _ts_metadata16("design:paramtypes", [
2705
2861
  typeof import_core.DiscoveryService === "undefined" ? Object : import_core.DiscoveryService,
2706
2862
  typeof import_core.MetadataScanner === "undefined" ? Object : import_core.MetadataScanner,
2707
- typeof import_nestjs_agent_core15.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core15.AgentRegistry,
2863
+ typeof import_nestjs_agent_core16.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core16.AgentRegistry,
2708
2864
  Array
2709
2865
  ])
2710
2866
  ], AgentDiscoveryService);
2711
2867
 
2712
2868
  // src/discovery/ai-tool-discovery.service.ts
2713
- var import_nestjs_agent_core16 = require("@dudousxd/nestjs-agent-core");
2714
- var import_common16 = require("@nestjs/common");
2869
+ var import_nestjs_agent_core17 = require("@dudousxd/nestjs-agent-core");
2870
+ var import_common17 = require("@nestjs/common");
2715
2871
  var import_core2 = require("@nestjs/core");
2716
2872
  var import_zod = require("zod");
2717
2873
 
2718
2874
  // src/decorator/ai-tool.decorator.ts
2719
2875
  var import_reflect_metadata3 = require("reflect-metadata");
2720
2876
  var AI_TOOL_METADATA = /* @__PURE__ */ Symbol("nestjs-agent:ai-tool");
2877
+ function toolNameFromClass(className) {
2878
+ const base = className.replace(/Tool$/, "") || className;
2879
+ const leadingCaps = /^[A-Z]+(?=[A-Z][a-z]|$)/.exec(base)?.[0];
2880
+ if (leadingCaps !== void 0 && leadingCaps.length > 1) {
2881
+ return leadingCaps.toLowerCase() + base.slice(leadingCaps.length);
2882
+ }
2883
+ return base.charAt(0).toLowerCase() + base.slice(1);
2884
+ }
2885
+ __name(toolNameFromClass, "toolNameFromClass");
2721
2886
  function AiTool(options) {
2722
2887
  return (target) => {
2723
- Reflect.defineMetadata(AI_TOOL_METADATA, options, target);
2888
+ const resolved = {
2889
+ ...options,
2890
+ name: options.name ?? toolNameFromClass(target.name),
2891
+ kind: options.kind ?? "read"
2892
+ };
2893
+ Reflect.defineMetadata(AI_TOOL_METADATA, resolved, target);
2724
2894
  };
2725
2895
  }
2726
2896
  __name(AiTool, "AiTool");
@@ -2768,7 +2938,7 @@ function provideAgentTools(factory, inject) {
2768
2938
  __name(provideAgentTools, "provideAgentTools");
2769
2939
 
2770
2940
  // src/discovery/ai-tool-discovery.service.ts
2771
- function _ts_decorate16(decorators, target, key, desc) {
2941
+ function _ts_decorate17(decorators, target, key, desc) {
2772
2942
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2773
2943
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2774
2944
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2781,19 +2951,19 @@ function _ts_decorate16(decorators, target, key, desc) {
2781
2951
  }
2782
2952
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2783
2953
  }
2784
- __name(_ts_decorate16, "_ts_decorate");
2785
- function _ts_metadata16(metadataKey, metadataValue) {
2954
+ __name(_ts_decorate17, "_ts_decorate");
2955
+ function _ts_metadata17(metadataKey, metadataValue) {
2786
2956
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2787
2957
  return Reflect.metadata(metadataKey, metadataValue);
2788
2958
  }
2789
2959
  }
2790
- __name(_ts_metadata16, "_ts_metadata");
2791
- function _ts_param15(paramIndex, decorator) {
2960
+ __name(_ts_metadata17, "_ts_metadata");
2961
+ function _ts_param16(paramIndex, decorator) {
2792
2962
  return function(target, key) {
2793
2963
  decorator(target, key, paramIndex);
2794
2964
  };
2795
2965
  }
2796
- __name(_ts_param15, "_ts_param");
2966
+ __name(_ts_param16, "_ts_param");
2797
2967
  var AiToolDiscoveryService = class _AiToolDiscoveryService {
2798
2968
  static {
2799
2969
  __name(this, "AiToolDiscoveryService");
@@ -2802,7 +2972,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
2802
2972
  registry;
2803
2973
  agents;
2804
2974
  options;
2805
- logger = new import_common16.Logger(_AiToolDiscoveryService.name);
2975
+ logger = new import_common17.Logger(_AiToolDiscoveryService.name);
2806
2976
  constructor(discovery, registry, agents, options) {
2807
2977
  this.discovery = discovery;
2808
2978
  this.registry = registry;
@@ -2887,7 +3057,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
2887
3057
  let delegates = 0;
2888
3058
  for (const definition of this.agents.list()) {
2889
3059
  for (const edge of definition.delegatesTo ?? []) {
2890
- const { agent: target, detached } = (0, import_nestjs_agent_core16.normalizeDelegation)(edge);
3060
+ const { agent: target, detached } = (0, import_nestjs_agent_core17.normalizeDelegation)(edge);
2891
3061
  const targetDefinition = this.agents.get(target);
2892
3062
  if (targetDefinition === void 0) {
2893
3063
  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.`);
@@ -2937,13 +3107,13 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
2937
3107
  return true;
2938
3108
  }
2939
3109
  };
2940
- AiToolDiscoveryService = _ts_decorate16([
2941
- (0, import_common16.Injectable)(),
2942
- _ts_param15(1, (0, import_common16.Inject)(import_nestjs_agent_core16.AGENT_TOOL_REGISTRY)),
2943
- _ts_param15(2, (0, import_common16.Inject)(import_nestjs_agent_core16.AGENT_REGISTRY)),
2944
- _ts_param15(3, (0, import_common16.Inject)(import_nestjs_agent_core16.AGENT_OPTIONS)),
2945
- _ts_metadata16("design:type", Function),
2946
- _ts_metadata16("design:paramtypes", [
3110
+ AiToolDiscoveryService = _ts_decorate17([
3111
+ (0, import_common17.Injectable)(),
3112
+ _ts_param16(1, (0, import_common17.Inject)(import_nestjs_agent_core17.AGENT_TOOL_REGISTRY)),
3113
+ _ts_param16(2, (0, import_common17.Inject)(import_nestjs_agent_core17.AGENT_REGISTRY)),
3114
+ _ts_param16(3, (0, import_common17.Inject)(import_nestjs_agent_core17.AGENT_OPTIONS)),
3115
+ _ts_metadata17("design:type", Function),
3116
+ _ts_metadata17("design:paramtypes", [
2947
3117
  typeof import_core2.DiscoveryService === "undefined" ? Object : import_core2.DiscoveryService,
2948
3118
  typeof ToolRegistry === "undefined" ? Object : ToolRegistry,
2949
3119
  typeof AgentRegistry === "undefined" ? Object : AgentRegistry,
@@ -2952,13 +3122,13 @@ AiToolDiscoveryService = _ts_decorate16([
2952
3122
  ], AiToolDiscoveryService);
2953
3123
 
2954
3124
  // src/discovery/skill-discovery.service.ts
2955
- var import_nestjs_agent_core18 = require("@dudousxd/nestjs-agent-core");
2956
- var import_common17 = require("@nestjs/common");
3125
+ var import_nestjs_agent_core19 = require("@dudousxd/nestjs-agent-core");
3126
+ var import_common18 = require("@nestjs/common");
2957
3127
  var import_core3 = require("@nestjs/core");
2958
3128
 
2959
3129
  // src/decorator/skill.decorator.ts
2960
3130
  var import_reflect_metadata4 = require("reflect-metadata");
2961
- var import_nestjs_agent_core17 = require("@dudousxd/nestjs-agent-core");
3131
+ var import_nestjs_agent_core18 = require("@dudousxd/nestjs-agent-core");
2962
3132
  var SKILL_METADATA = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:skill-metadata");
2963
3133
  function Skill(options) {
2964
3134
  return (target) => {
@@ -2971,12 +3141,12 @@ function readSkillMetadata(target) {
2971
3141
  }
2972
3142
  __name(readSkillMetadata, "readSkillMetadata");
2973
3143
  function skillScope(options) {
2974
- return options.scope ?? import_nestjs_agent_core17.GLOBAL_SCOPE;
3144
+ return options.scope ?? import_nestjs_agent_core18.GLOBAL_SCOPE;
2975
3145
  }
2976
3146
  __name(skillScope, "skillScope");
2977
3147
 
2978
3148
  // src/discovery/skill-discovery.service.ts
2979
- function _ts_decorate17(decorators, target, key, desc) {
3149
+ function _ts_decorate18(decorators, target, key, desc) {
2980
3150
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2981
3151
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2982
3152
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2989,26 +3159,26 @@ function _ts_decorate17(decorators, target, key, desc) {
2989
3159
  }
2990
3160
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2991
3161
  }
2992
- __name(_ts_decorate17, "_ts_decorate");
2993
- function _ts_metadata17(metadataKey, metadataValue) {
3162
+ __name(_ts_decorate18, "_ts_decorate");
3163
+ function _ts_metadata18(metadataKey, metadataValue) {
2994
3164
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2995
3165
  return Reflect.metadata(metadataKey, metadataValue);
2996
3166
  }
2997
3167
  }
2998
- __name(_ts_metadata17, "_ts_metadata");
2999
- function _ts_param16(paramIndex, decorator) {
3168
+ __name(_ts_metadata18, "_ts_metadata");
3169
+ function _ts_param17(paramIndex, decorator) {
3000
3170
  return function(target, key) {
3001
3171
  decorator(target, key, paramIndex);
3002
3172
  };
3003
3173
  }
3004
- __name(_ts_param16, "_ts_param");
3174
+ __name(_ts_param17, "_ts_param");
3005
3175
  var SkillDiscoveryService = class _SkillDiscoveryService {
3006
3176
  static {
3007
3177
  __name(this, "SkillDiscoveryService");
3008
3178
  }
3009
3179
  discovery;
3010
3180
  declared;
3011
- logger = new import_common17.Logger(_SkillDiscoveryService.name);
3181
+ logger = new import_common18.Logger(_SkillDiscoveryService.name);
3012
3182
  constructor(discovery, declared) {
3013
3183
  this.discovery = discovery;
3014
3184
  this.declared = declared;
@@ -3045,18 +3215,18 @@ var SkillDiscoveryService = class _SkillDiscoveryService {
3045
3215
  return flat === void 0 ? void 0 : () => flat;
3046
3216
  }
3047
3217
  };
3048
- SkillDiscoveryService = _ts_decorate17([
3049
- (0, import_common17.Injectable)(),
3050
- _ts_param16(1, (0, import_common17.Inject)(import_nestjs_agent_core18.AGENT_SKILL_SOURCES)),
3051
- _ts_metadata17("design:type", Function),
3052
- _ts_metadata17("design:paramtypes", [
3218
+ SkillDiscoveryService = _ts_decorate18([
3219
+ (0, import_common18.Injectable)(),
3220
+ _ts_param17(1, (0, import_common18.Inject)(import_nestjs_agent_core19.AGENT_SKILL_SOURCES)),
3221
+ _ts_metadata18("design:type", Function),
3222
+ _ts_metadata18("design:paramtypes", [
3053
3223
  typeof import_core3.DiscoveryService === "undefined" ? Object : import_core3.DiscoveryService,
3054
3224
  Array
3055
3225
  ])
3056
3226
  ], SkillDiscoveryService);
3057
3227
 
3058
3228
  // src/in-process-sink.ts
3059
- var import_nestjs_agent_core19 = require("@dudousxd/nestjs-agent-core");
3229
+ var import_nestjs_agent_core20 = require("@dudousxd/nestjs-agent-core");
3060
3230
  var InProcessTokenStreamSink = class {
3061
3231
  static {
3062
3232
  __name(this, "InProcessTokenStreamSink");
@@ -3111,7 +3281,7 @@ var InProcessTokenStreamSink = class {
3111
3281
  }
3112
3282
  if (buf.ended) {
3113
3283
  if (buf.failure !== void 0) {
3114
- throw new import_nestjs_agent_core19.AgentStreamError(buf.failure);
3284
+ throw new import_nestjs_agent_core20.AgentStreamError(buf.failure);
3115
3285
  }
3116
3286
  return;
3117
3287
  }
@@ -3124,17 +3294,15 @@ var InProcessTokenStreamSink = class {
3124
3294
  };
3125
3295
 
3126
3296
  // src/ledger-quota-provider.ts
3127
- var import_nestjs_agent_core20 = require("@dudousxd/nestjs-agent-core");
3297
+ var import_nestjs_agent_core21 = require("@dudousxd/nestjs-agent-core");
3128
3298
  var LedgerQuotaProvider = class {
3129
3299
  static {
3130
3300
  __name(this, "LedgerQuotaProvider");
3131
3301
  }
3132
3302
  store;
3133
- quota;
3134
3303
  limits;
3135
- constructor(store, quota, limits = {}) {
3304
+ constructor(store, limits = {}) {
3136
3305
  this.store = store;
3137
- this.quota = quota;
3138
3306
  this.limits = limits;
3139
3307
  }
3140
3308
  async report(query) {
@@ -3144,11 +3312,11 @@ var LedgerQuotaProvider = class {
3144
3312
  await this.dayWindow(actorRef, now)
3145
3313
  ];
3146
3314
  if (this.store.usageBetween !== void 0) {
3147
- const range = (0, import_nestjs_agent_core20.quotaPeriodRange)("month", now);
3315
+ const range = (0, import_nestjs_agent_core21.quotaPeriodRange)("month", now);
3148
3316
  const used = await this.store.usageBetween(actorRef, range.fromDay, range.toDay);
3149
3317
  windows.push(this.window("month", used.usedTokens, used.costUsd, range.resetsAt));
3150
3318
  }
3151
- const blocked = (0, import_nestjs_agent_core20.exhaustedWindow)(windows);
3319
+ const blocked = (0, import_nestjs_agent_core21.exhaustedWindow)(windows);
3152
3320
  return {
3153
3321
  windows,
3154
3322
  ...blocked !== void 0 ? {
@@ -3157,17 +3325,9 @@ var LedgerQuotaProvider = class {
3157
3325
  };
3158
3326
  }
3159
3327
  async dayWindow(actorRef, now) {
3160
- const range = (0, import_nestjs_agent_core20.quotaPeriodRange)("day", now);
3328
+ const range = (0, import_nestjs_agent_core21.quotaPeriodRange)("day", now);
3161
3329
  const { usedTokens, costUsd } = await this.store.quotaToday(actorRef, range.fromDay);
3162
- if (this.quota === void 0) {
3163
- return this.window("day", usedTokens, costUsd, range.resetsAt);
3164
- }
3165
- const state = await this.quota.check(actorRef, range.fromDay);
3166
- const window = this.window("day", state.usedTokens, costUsd, range.resetsAt);
3167
- if (window.limitTokens === void 0) {
3168
- window.limitTokens = state.limitTokens;
3169
- }
3170
- return window;
3330
+ return this.window("day", usedTokens, costUsd, range.resetsAt);
3171
3331
  }
3172
3332
  window(period, usedTokens, usedUsd, resetsAt) {
3173
3333
  const limits = this.limits[period] ?? {};
@@ -3186,33 +3346,10 @@ var LedgerQuotaProvider = class {
3186
3346
  }
3187
3347
  };
3188
3348
 
3189
- // src/ledger-quota-store.ts
3190
- var LedgerQuotaStore = class {
3191
- static {
3192
- __name(this, "LedgerQuotaStore");
3193
- }
3194
- store;
3195
- limitTokens;
3196
- constructor(store, limitTokens) {
3197
- this.store = store;
3198
- this.limitTokens = limitTokens;
3199
- }
3200
- async check(actorRef, day) {
3201
- const { usedTokens } = await this.store.quotaToday(actorRef, day);
3202
- return {
3203
- usedTokens,
3204
- limitTokens: this.limitTokens,
3205
- withinLimit: usedTokens < this.limitTokens
3206
- };
3207
- }
3208
- async bump(_actorRef, _day, _tokens) {
3209
- }
3210
- };
3211
-
3212
3349
  // src/runner/inline-agent-runner.ts
3213
- var import_nestjs_agent_core21 = require("@dudousxd/nestjs-agent-core");
3214
- var import_common18 = require("@nestjs/common");
3215
- function _ts_decorate18(decorators, target, key, desc) {
3350
+ var import_nestjs_agent_core22 = require("@dudousxd/nestjs-agent-core");
3351
+ var import_common19 = require("@nestjs/common");
3352
+ function _ts_decorate19(decorators, target, key, desc) {
3216
3353
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3217
3354
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3218
3355
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3225,26 +3362,26 @@ function _ts_decorate18(decorators, target, key, desc) {
3225
3362
  }
3226
3363
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3227
3364
  }
3228
- __name(_ts_decorate18, "_ts_decorate");
3229
- function _ts_metadata18(metadataKey, metadataValue) {
3365
+ __name(_ts_decorate19, "_ts_decorate");
3366
+ function _ts_metadata19(metadataKey, metadataValue) {
3230
3367
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3231
3368
  return Reflect.metadata(metadataKey, metadataValue);
3232
3369
  }
3233
3370
  }
3234
- __name(_ts_metadata18, "_ts_metadata");
3235
- function _ts_param17(paramIndex, decorator) {
3371
+ __name(_ts_metadata19, "_ts_metadata");
3372
+ function _ts_param18(paramIndex, decorator) {
3236
3373
  return function(target, key) {
3237
3374
  decorator(target, key, paramIndex);
3238
3375
  };
3239
3376
  }
3240
- __name(_ts_param17, "_ts_param");
3377
+ __name(_ts_param18, "_ts_param");
3241
3378
  var InlineAgentRunner = class _InlineAgentRunner {
3242
3379
  static {
3243
3380
  __name(this, "InlineAgentRunner");
3244
3381
  }
3245
3382
  factory;
3246
3383
  store;
3247
- logger = new import_common18.Logger(_InlineAgentRunner.name);
3384
+ logger = new import_common19.Logger(_InlineAgentRunner.name);
3248
3385
  pending = /* @__PURE__ */ new Map();
3249
3386
  /**
3250
3387
  * Runs someone has asked to stop. In-process, like `pending`, and for the same reason: this runner
@@ -3273,18 +3410,18 @@ var InlineAgentRunner = class _InlineAgentRunner {
3273
3410
  ] : []
3274
3411
  ]
3275
3412
  });
3276
- void (0, import_nestjs_agent_core21.runAgentLoop)({
3413
+ void (0, import_nestjs_agent_core22.runAgentLoop)({
3277
3414
  ...deps,
3278
3415
  day
3279
3416
  }, input, hooks).then(() => this.store.setActiveStream(input.threadId, null)).catch(async (error) => {
3280
- if (error instanceof import_nestjs_agent_core21.RunCancelledError) {
3417
+ if (error instanceof import_nestjs_agent_core22.RunCancelledError) {
3281
3418
  await this.settleCancelled(runId, input.threadId, deps);
3282
3419
  return;
3283
3420
  }
3284
3421
  const message = error instanceof Error ? error.message : String(error);
3285
- const code = (0, import_nestjs_agent_core21.agentFailureCode)(error);
3422
+ const code = (0, import_nestjs_agent_core22.agentFailureCode)(error);
3286
3423
  this.logger.error(`agent run ${runId} failed (${code}): ${message}`);
3287
- (0, import_nestjs_agent_core21.publishAgentRunFailed)({
3424
+ (0, import_nestjs_agent_core22.publishAgentRunFailed)({
3288
3425
  runId,
3289
3426
  code,
3290
3427
  message
@@ -3333,7 +3470,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3333
3470
  for (const [key, waiter] of this.pending) {
3334
3471
  if (key.startsWith(`${runId}:`)) {
3335
3472
  this.pending.delete(key);
3336
- waiter.reject(new import_nestjs_agent_core21.RunCancelledError());
3473
+ waiter.reject(new import_nestjs_agent_core22.RunCancelledError());
3337
3474
  }
3338
3475
  }
3339
3476
  await Promise.resolve();
@@ -3348,7 +3485,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3348
3485
  this.logger.log(`agent run ${runId} cancelled`);
3349
3486
  await this.store.setActiveStream(threadId, null);
3350
3487
  const writer = await deps.sink.open(runId);
3351
- await writer.write((0, import_nestjs_agent_core21.encodeStreamEvent)({
3488
+ await writer.write((0, import_nestjs_agent_core22.encodeStreamEvent)({
3352
3489
  kind: "cancelled"
3353
3490
  }));
3354
3491
  await writer.end();
@@ -3409,7 +3546,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3409
3546
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
3410
3547
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
3411
3548
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
3412
- parallel: import_nestjs_agent_core21.settleAll,
3549
+ parallel: import_nestjs_agent_core22.settleAll,
3413
3550
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
3414
3551
  runAgent: /* @__PURE__ */ __name((agentName, task) => this.runNested({
3415
3552
  agentName,
@@ -3460,7 +3597,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3460
3597
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
3461
3598
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
3462
3599
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
3463
- parallel: import_nestjs_agent_core21.settleAll,
3600
+ parallel: import_nestjs_agent_core22.settleAll,
3464
3601
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
3465
3602
  runAgent: /* @__PURE__ */ __name((childName, childTask) => this.runNested({
3466
3603
  agentName: childName,
@@ -3493,7 +3630,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3493
3630
  }
3494
3631
  }), "startAgent")
3495
3632
  };
3496
- void (0, import_nestjs_agent_core21.runAgentLoop)({
3633
+ void (0, import_nestjs_agent_core22.runAgentLoop)({
3497
3634
  ...deps,
3498
3635
  day
3499
3636
  }, {
@@ -3507,13 +3644,13 @@ var InlineAgentRunner = class _InlineAgentRunner {
3507
3644
  parentRunId,
3508
3645
  deliverTo
3509
3646
  }, hooks).catch(async (error) => {
3510
- const cancelled = error instanceof import_nestjs_agent_core21.RunCancelledError;
3647
+ const cancelled = error instanceof import_nestjs_agent_core22.RunCancelledError;
3511
3648
  const message = error instanceof Error ? error.message : String(error);
3512
3649
  if (!cancelled) {
3513
3650
  this.logger.error(`detached agent run ${runId} failed: ${message}`);
3514
- (0, import_nestjs_agent_core21.publishAgentRunFailed)({
3651
+ (0, import_nestjs_agent_core22.publishAgentRunFailed)({
3515
3652
  runId,
3516
- code: (0, import_nestjs_agent_core21.agentFailureCode)(error),
3653
+ code: (0, import_nestjs_agent_core22.agentFailureCode)(error),
3517
3654
  message
3518
3655
  });
3519
3656
  }
@@ -3521,11 +3658,11 @@ var InlineAgentRunner = class _InlineAgentRunner {
3521
3658
  runId,
3522
3659
  status: cancelled ? "cancelled" : "failed",
3523
3660
  ...cancelled ? {} : {
3524
- errorCode: (0, import_nestjs_agent_core21.agentFailureCode)(error),
3661
+ errorCode: (0, import_nestjs_agent_core22.agentFailureCode)(error),
3525
3662
  errorMessage: message
3526
3663
  }
3527
3664
  });
3528
- await (0, import_nestjs_agent_core21.settleUnsettledDelegation)({
3665
+ await (0, import_nestjs_agent_core22.settleUnsettledDelegation)({
3529
3666
  store: this.store,
3530
3667
  delivery: deliverTo,
3531
3668
  agent: agentName,
@@ -3564,7 +3701,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3564
3701
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
3565
3702
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
3566
3703
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
3567
- parallel: import_nestjs_agent_core21.settleAll,
3704
+ parallel: import_nestjs_agent_core22.settleAll,
3568
3705
  // A child stops when it is cancelled OR when the run a human is actually watching is: the
3569
3706
  // canceller names the top-level run, which is the only id that ever left the server.
3570
3707
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId) || this.cancelled.has(sinkRunId), "cancelled"),
@@ -3599,7 +3736,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
3599
3736
  }), "startAgent")
3600
3737
  };
3601
3738
  try {
3602
- return await (0, import_nestjs_agent_core21.runAgentLoop)({
3739
+ return await (0, import_nestjs_agent_core22.runAgentLoop)({
3603
3740
  ...deps,
3604
3741
  day
3605
3742
  }, {
@@ -3618,19 +3755,19 @@ var InlineAgentRunner = class _InlineAgentRunner {
3618
3755
  }
3619
3756
  }
3620
3757
  };
3621
- InlineAgentRunner = _ts_decorate18([
3622
- (0, import_common18.Injectable)(),
3623
- _ts_param17(0, (0, import_common18.Inject)(import_nestjs_agent_core21.AGENT_DEPS_FACTORY)),
3624
- _ts_param17(1, (0, import_common18.Inject)(import_nestjs_agent_core21.AGENT_STORE)),
3625
- _ts_metadata18("design:type", Function),
3626
- _ts_metadata18("design:paramtypes", [
3758
+ InlineAgentRunner = _ts_decorate19([
3759
+ (0, import_common19.Injectable)(),
3760
+ _ts_param18(0, (0, import_common19.Inject)(import_nestjs_agent_core22.AGENT_DEPS_FACTORY)),
3761
+ _ts_param18(1, (0, import_common19.Inject)(import_nestjs_agent_core22.AGENT_STORE)),
3762
+ _ts_metadata19("design:type", Function),
3763
+ _ts_metadata19("design:paramtypes", [
3627
3764
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
3628
3765
  typeof AgentStore === "undefined" ? Object : AgentStore
3629
3766
  ])
3630
3767
  ], InlineAgentRunner);
3631
3768
 
3632
3769
  // src/skills-config.ts
3633
- var import_nestjs_agent_core22 = require("@dudousxd/nestjs-agent-core");
3770
+ var import_nestjs_agent_core23 = require("@dudousxd/nestjs-agent-core");
3634
3771
  function declaredSkillProvider(declared) {
3635
3772
  return {
3636
3773
  list: /* @__PURE__ */ __name(({ scopes }) => declared.filter((skill) => scopes.includes(skill.scope)).map(({ name, description, scope }) => ({
@@ -3656,7 +3793,7 @@ function resolveSkillsConfig(options, declared) {
3656
3793
  declaredSkillProvider(declared)
3657
3794
  ];
3658
3795
  return {
3659
- provider: providers.length === 1 ? providers[0] : (0, import_nestjs_agent_core22.compositeSkillProvider)(providers),
3796
+ provider: providers.length === 1 ? providers[0] : (0, import_nestjs_agent_core23.compositeSkillProvider)(providers),
3660
3797
  ...options.scopes !== void 0 ? {
3661
3798
  scopes: options.scopes
3662
3799
  } : {},
@@ -3668,7 +3805,7 @@ function resolveSkillsConfig(options, declared) {
3668
3805
  __name(resolveSkillsConfig, "resolveSkillsConfig");
3669
3806
 
3670
3807
  // src/agent.module.ts
3671
- function _ts_decorate19(decorators, target, key, desc) {
3808
+ function _ts_decorate20(decorators, target, key, desc) {
3672
3809
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3673
3810
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3674
3811
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3681,108 +3818,150 @@ function _ts_decorate19(decorators, target, key, desc) {
3681
3818
  }
3682
3819
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3683
3820
  }
3684
- __name(_ts_decorate19, "_ts_decorate");
3821
+ __name(_ts_decorate20, "_ts_decorate");
3685
3822
  var DEFAULT_PATH = "agent";
3686
- function sharedProviders(durable, includeStore) {
3823
+ var logger = new import_common20.Logger("AgentModule");
3824
+ function externalStoreWrapper(modules) {
3825
+ for (const module2 of modules.values()) {
3826
+ if (module2.metatype === AgentModule) continue;
3827
+ const wrapper = module2.providers.get(import_nestjs_agent_core24.AGENT_STORE);
3828
+ if (wrapper !== void 0) return wrapper;
3829
+ }
3830
+ return void 0;
3831
+ }
3832
+ __name(externalStoreWrapper, "externalStoreWrapper");
3833
+ function forwardingStore(wrapper) {
3834
+ const target = /* @__PURE__ */ __name(() => {
3835
+ const instance = wrapper.instance;
3836
+ if (instance === void 0 || instance === null) {
3837
+ throw new Error("AgentModule: the AGENT_STORE bound by another module is not ready yet");
3838
+ }
3839
+ return instance;
3840
+ }, "target");
3841
+ return new Proxy({}, {
3842
+ get(_, property) {
3843
+ const store = target();
3844
+ const value = store[property];
3845
+ return typeof value === "function" ? value.bind(store) : value;
3846
+ },
3847
+ has(_, property) {
3848
+ return property in target();
3849
+ }
3850
+ });
3851
+ }
3852
+ __name(forwardingStore, "forwardingStore");
3853
+ function resolveStore(options, modules) {
3854
+ if (options.store !== void 0) return options.store;
3855
+ const external = externalStoreWrapper(modules);
3856
+ if (external !== void 0) return forwardingStore(external);
3857
+ logger.warn("No `store` configured and no store module imported \u2014 using the in-memory store. Threads are lost on restart and not shared between processes: not for production. Pass `store`, or import a store module (e.g. MikroOrmAgentStoreModule.forFeature()).");
3858
+ return new import_nestjs_agent_core24.InMemoryAgentStore();
3859
+ }
3860
+ __name(resolveStore, "resolveStore");
3861
+ function isQuotaProvider(quota) {
3862
+ return quota !== void 0 && typeof quota.report === "function";
3863
+ }
3864
+ __name(isQuotaProvider, "isQuotaProvider");
3865
+ function resolveCatalog(options) {
3866
+ if (options.models !== void 0) return options.models;
3867
+ const carried = options.model.catalog;
3868
+ return carried !== void 0 && typeof carried.list === "function" ? carried : void 0;
3869
+ }
3870
+ __name(resolveCatalog, "resolveCatalog");
3871
+ function sharedProviders(durable) {
3687
3872
  const providers = [
3688
3873
  {
3689
- provide: import_nestjs_agent_core23.AGENT_TOOL_REGISTRY,
3690
- useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core23.ToolRegistry(), "useFactory")
3874
+ provide: import_nestjs_agent_core24.AGENT_TOOL_REGISTRY,
3875
+ useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core24.ToolRegistry(), "useFactory")
3691
3876
  },
3692
3877
  // Starts empty; AgentDiscoveryService populates it from `@Agent`-decorated providers at boot.
3693
3878
  {
3694
- provide: import_nestjs_agent_core23.AGENT_REGISTRY,
3695
- useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core23.AgentRegistry(), "useFactory")
3879
+ provide: import_nestjs_agent_core24.AGENT_REGISTRY,
3880
+ useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core24.AgentRegistry(), "useFactory")
3696
3881
  },
3697
3882
  // A shared, mutable list AgentDiscoveryService fills with `@SystemPromptContributor()` methods.
3698
3883
  {
3699
- provide: import_nestjs_agent_core23.AGENT_PROMPT_CONTRIBUTORS,
3884
+ provide: import_nestjs_agent_core24.AGENT_PROMPT_CONTRIBUTORS,
3700
3885
  useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
3701
3886
  },
3702
3887
  // Likewise for `@Skill`-decorated providers — filled by SkillDiscoveryService at onModuleInit,
3703
3888
  // read lazily by the AGENT_SKILLS provider below (which DI builds before discovery has run).
3704
3889
  {
3705
- provide: import_nestjs_agent_core23.AGENT_SKILL_SOURCES,
3890
+ provide: import_nestjs_agent_core24.AGENT_SKILL_SOURCES,
3706
3891
  useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
3707
3892
  },
3708
3893
  {
3709
3894
  // One resolution, shared by the loop's deps and the listing endpoint: a second one would
3710
3895
  // drift, and a user would be offered a skill the agent cannot reach. `undefined` when the
3711
3896
  // host configured none — which is what keeps the turn's checkpoint sequence unchanged.
3712
- provide: import_nestjs_agent_core23.AGENT_SKILLS,
3897
+ provide: import_nestjs_agent_core24.AGENT_SKILLS,
3713
3898
  useFactory: /* @__PURE__ */ __name((options, declared) => resolveSkillsConfig(options.skills, declared), "useFactory"),
3714
3899
  inject: [
3715
- import_nestjs_agent_core23.AGENT_OPTIONS,
3716
- import_nestjs_agent_core23.AGENT_SKILL_SOURCES
3900
+ import_nestjs_agent_core24.AGENT_OPTIONS,
3901
+ import_nestjs_agent_core24.AGENT_SKILL_SOURCES
3717
3902
  ]
3718
3903
  },
3719
3904
  {
3720
3905
  // One resolution, shared by the loop's deps and the read-back endpoint: a person has to be
3721
3906
  // shown what the model was shown, and two resolutions would eventually disagree about that.
3722
- provide: import_nestjs_agent_core23.AGENT_MEMORY,
3907
+ provide: import_nestjs_agent_core24.AGENT_MEMORY,
3723
3908
  useFactory: /* @__PURE__ */ __name((options) => options.memory, "useFactory"),
3724
3909
  inject: [
3725
- import_nestjs_agent_core23.AGENT_OPTIONS
3910
+ import_nestjs_agent_core24.AGENT_OPTIONS
3726
3911
  ]
3727
3912
  },
3728
3913
  {
3729
- provide: import_nestjs_agent_core23.AGENT_SINK,
3914
+ provide: import_nestjs_agent_core24.AGENT_SINK,
3730
3915
  useFactory: /* @__PURE__ */ __name((options) => options.sink ?? new InProcessTokenStreamSink(), "useFactory"),
3731
3916
  inject: [
3732
- import_nestjs_agent_core23.AGENT_OPTIONS
3917
+ import_nestjs_agent_core24.AGENT_OPTIONS
3733
3918
  ]
3734
3919
  },
3735
3920
  {
3736
- provide: import_nestjs_agent_core23.AGENT_ROLES_POLICY,
3737
- useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? new import_nestjs_agent_core23.DefaultRolesPolicy(options.defaultRoles), "useFactory"),
3921
+ provide: import_nestjs_agent_core24.AGENT_ROLES_POLICY,
3922
+ useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? new import_nestjs_agent_core24.DefaultRolesPolicy(options.defaultRoles), "useFactory"),
3738
3923
  inject: [
3739
- import_nestjs_agent_core23.AGENT_OPTIONS
3924
+ import_nestjs_agent_core24.AGENT_OPTIONS
3740
3925
  ]
3741
3926
  },
3742
3927
  {
3743
- provide: import_nestjs_agent_core23.AGENT_ACTOR_RESOLVER,
3744
- useFactory: /* @__PURE__ */ __name((options) => options.actorResolver, "useFactory"),
3928
+ provide: import_nestjs_agent_core24.AGENT_ACTOR_RESOLVER,
3929
+ useFactory: /* @__PURE__ */ __name((options) => {
3930
+ if (options.actorResolver !== void 0) return options.actorResolver;
3931
+ logger.warn("No `actorResolver` configured \u2014 the agent endpoints are PUBLIC: every browser gets its own anonymous identity (an HttpOnly cookie). Set `actorResolver: requestUserActorResolver()` (or your own) to require login.");
3932
+ return new AnonymousActorResolver();
3933
+ }, "useFactory"),
3745
3934
  inject: [
3746
- import_nestjs_agent_core23.AGENT_OPTIONS
3935
+ import_nestjs_agent_core24.AGENT_OPTIONS
3747
3936
  ]
3748
3937
  },
3749
3938
  {
3750
- provide: import_nestjs_agent_core23.AGENT_MODEL,
3939
+ provide: import_nestjs_agent_core24.AGENT_MODEL,
3751
3940
  useFactory: /* @__PURE__ */ __name((o) => o.model, "useFactory"),
3752
3941
  inject: [
3753
- import_nestjs_agent_core23.AGENT_OPTIONS
3942
+ import_nestjs_agent_core24.AGENT_OPTIONS
3754
3943
  ]
3755
3944
  },
3756
3945
  {
3757
- // An explicit `quota` wins; otherwise `quotaLimitTokens` binds the built-in ledger-backed
3758
- // store; otherwise quotas are off (undefined). The ledger store reads the same usage rows
3759
- // the loop already writes, so enforcement needs no extra shared state across replicas.
3760
- provide: import_nestjs_agent_core23.AGENT_QUOTA_STORE,
3761
- useFactory: /* @__PURE__ */ __name((o, store) => o.quota ?? (o.quotaLimitTokens !== void 0 ? new LedgerQuotaStore(store, o.quotaLimitTokens) : void 0), "useFactory"),
3946
+ // `quota` is either a provider of the host's own or ceilings for the built-in ledger one;
3947
+ // omitted, the ledger provider still reports usage, with no ceiling to block on.
3948
+ provide: import_nestjs_agent_core24.AGENT_QUOTA_PROVIDER,
3949
+ useFactory: /* @__PURE__ */ __name((o, store) => isQuotaProvider(o.quota) ? o.quota : new LedgerQuotaProvider(store, o.quota?.limits), "useFactory"),
3762
3950
  inject: [
3763
- import_nestjs_agent_core23.AGENT_OPTIONS,
3764
- import_nestjs_agent_core23.AGENT_STORE
3951
+ import_nestjs_agent_core24.AGENT_OPTIONS,
3952
+ import_nestjs_agent_core24.AGENT_STORE
3765
3953
  ]
3766
3954
  },
3767
3955
  {
3768
- provide: import_nestjs_agent_core23.AGENT_QUOTA_PROVIDER,
3769
- useFactory: /* @__PURE__ */ __name((o, store, quota) => o.quotaProvider ?? new LedgerQuotaProvider(store, quota, o.quotaLimits), "useFactory"),
3956
+ provide: import_nestjs_agent_core24.AGENT_MODEL_CATALOG,
3957
+ useFactory: /* @__PURE__ */ __name((o) => resolveCatalog(o), "useFactory"),
3770
3958
  inject: [
3771
- import_nestjs_agent_core23.AGENT_OPTIONS,
3772
- import_nestjs_agent_core23.AGENT_STORE,
3773
- import_nestjs_agent_core23.AGENT_QUOTA_STORE
3774
- ]
3775
- },
3776
- {
3777
- provide: import_nestjs_agent_core23.AGENT_MODEL_CATALOG,
3778
- useFactory: /* @__PURE__ */ __name((o) => o.models, "useFactory"),
3779
- inject: [
3780
- import_nestjs_agent_core23.AGENT_OPTIONS
3959
+ import_nestjs_agent_core24.AGENT_OPTIONS
3781
3960
  ]
3782
3961
  },
3783
3962
  AgentDepsFactory2,
3784
3963
  {
3785
- provide: import_nestjs_agent_core23.AGENT_DEPS_FACTORY,
3964
+ provide: import_nestjs_agent_core24.AGENT_DEPS_FACTORY,
3786
3965
  useExisting: AgentDepsFactory2
3787
3966
  },
3788
3967
  // Populates the registry + contributors (onModuleInit) BEFORE AiToolDiscoveryService synthesizes
@@ -3796,22 +3975,21 @@ function sharedProviders(durable, includeStore) {
3796
3975
  // through AgentService.signalToolCall, which reaches whichever AGENT_RUNNER is bound above.
3797
3976
  AgentApprovalPortAdapter,
3798
3977
  {
3799
- provide: import_nestjs_agent_core23.AGENT_APPROVAL_PORT,
3978
+ provide: import_nestjs_agent_core24.AGENT_APPROVAL_PORT,
3800
3979
  useExisting: AgentApprovalPortAdapter
3801
3980
  }
3802
3981
  ];
3803
- if (includeStore) {
3804
- providers.push({
3805
- provide: import_nestjs_agent_core23.AGENT_STORE,
3806
- useFactory: /* @__PURE__ */ __name((o) => o.store, "useFactory"),
3807
- inject: [
3808
- import_nestjs_agent_core23.AGENT_OPTIONS
3809
- ]
3810
- });
3811
- }
3982
+ providers.push({
3983
+ provide: import_nestjs_agent_core24.AGENT_STORE,
3984
+ useFactory: /* @__PURE__ */ __name((o, modules) => resolveStore(o, modules), "useFactory"),
3985
+ inject: [
3986
+ import_nestjs_agent_core24.AGENT_OPTIONS,
3987
+ import_core4.ModulesContainer
3988
+ ]
3989
+ });
3812
3990
  if (durable) {
3813
3991
  providers.push({
3814
- provide: import_nestjs_agent_core23.AGENT_RUNNER,
3992
+ provide: import_nestjs_agent_core24.AGENT_RUNNER,
3815
3993
  useFactory: /* @__PURE__ */ __name((durableRunner) => {
3816
3994
  if (durableRunner === void 0) {
3817
3995
  throw new Error("AgentModule.forRoot({ durable: true }) requires importing AgentDurableModule from '@dudousxd/nestjs-agent/durable' (alongside a configured DurableModule). It was not found.");
@@ -3820,43 +3998,40 @@ function sharedProviders(durable, includeStore) {
3820
3998
  }, "useFactory"),
3821
3999
  inject: [
3822
4000
  {
3823
- token: import_nestjs_agent_core23.AGENT_DURABLE_RUNNER,
4001
+ token: import_nestjs_agent_core24.AGENT_DURABLE_RUNNER,
3824
4002
  optional: true
3825
4003
  }
3826
4004
  ]
3827
4005
  });
3828
4006
  } else {
3829
4007
  providers.push({
3830
- provide: import_nestjs_agent_core23.AGENT_RUNNER,
4008
+ provide: import_nestjs_agent_core24.AGENT_RUNNER,
3831
4009
  useExisting: InlineAgentRunner
3832
4010
  });
3833
4011
  }
3834
4012
  return providers;
3835
4013
  }
3836
4014
  __name(sharedProviders, "sharedProviders");
3837
- function exportsFor(includeStore) {
4015
+ function exportsFor() {
3838
4016
  return [
3839
- import_nestjs_agent_core23.AGENT_OPTIONS,
3840
- import_nestjs_agent_core23.AGENT_TOOL_REGISTRY,
3841
- import_nestjs_agent_core23.AGENT_REGISTRY,
3842
- import_nestjs_agent_core23.AGENT_SINK,
3843
- import_nestjs_agent_core23.AGENT_ROLES_POLICY,
3844
- import_nestjs_agent_core23.AGENT_ACTOR_RESOLVER,
3845
- import_nestjs_agent_core23.AGENT_MODEL,
3846
- ...includeStore ? [
3847
- import_nestjs_agent_core23.AGENT_STORE
3848
- ] : [],
3849
- import_nestjs_agent_core23.AGENT_QUOTA_STORE,
3850
- import_nestjs_agent_core23.AGENT_MODEL_CATALOG,
3851
- import_nestjs_agent_core23.AGENT_QUOTA_PROVIDER,
3852
- import_nestjs_agent_core23.AGENT_PROMPT_CONTRIBUTORS,
3853
- import_nestjs_agent_core23.AGENT_SKILLS,
3854
- import_nestjs_agent_core23.AGENT_MEMORY,
3855
- import_nestjs_agent_core23.AGENT_DEPS_FACTORY,
4017
+ import_nestjs_agent_core24.AGENT_OPTIONS,
4018
+ import_nestjs_agent_core24.AGENT_TOOL_REGISTRY,
4019
+ import_nestjs_agent_core24.AGENT_REGISTRY,
4020
+ import_nestjs_agent_core24.AGENT_SINK,
4021
+ import_nestjs_agent_core24.AGENT_ROLES_POLICY,
4022
+ import_nestjs_agent_core24.AGENT_ACTOR_RESOLVER,
4023
+ import_nestjs_agent_core24.AGENT_MODEL,
4024
+ import_nestjs_agent_core24.AGENT_STORE,
4025
+ import_nestjs_agent_core24.AGENT_MODEL_CATALOG,
4026
+ import_nestjs_agent_core24.AGENT_QUOTA_PROVIDER,
4027
+ import_nestjs_agent_core24.AGENT_PROMPT_CONTRIBUTORS,
4028
+ import_nestjs_agent_core24.AGENT_SKILLS,
4029
+ import_nestjs_agent_core24.AGENT_MEMORY,
4030
+ import_nestjs_agent_core24.AGENT_DEPS_FACTORY,
3856
4031
  AgentDepsFactory2,
3857
4032
  AgentService,
3858
4033
  InlineAgentRunner,
3859
- import_nestjs_agent_core23.AGENT_APPROVAL_PORT
4034
+ import_nestjs_agent_core24.AGENT_APPROVAL_PORT
3860
4035
  ];
3861
4036
  }
3862
4037
  __name(exportsFor, "exportsFor");
@@ -3870,21 +4045,13 @@ var BASE_CONTROLLERS = [
3870
4045
  MemoriesController,
3871
4046
  ToolsController,
3872
4047
  MessagesController,
3873
- ModelsController
3874
- ];
3875
- var GUARDABLE_CONTROLLERS = [
3876
- ...BASE_CONTROLLERS,
4048
+ ModelsController,
4049
+ ConfigController,
3877
4050
  AttachmentsController
3878
4051
  ];
3879
- function controllersFor(mountAttachments) {
3880
- return mountAttachments ? [
3881
- ...BASE_CONTROLLERS,
3882
- AttachmentsController
3883
- ] : BASE_CONTROLLERS;
3884
- }
3885
- __name(controllersFor, "controllersFor");
3886
- function controllersForSurface(surface, mountAttachments) {
3887
- return surface === "engine" ? [] : controllersFor(mountAttachments);
4052
+ var GUARDABLE_CONTROLLERS = BASE_CONTROLLERS;
4053
+ function controllersForSurface(surface) {
4054
+ return surface === "engine" ? [] : BASE_CONTROLLERS;
3888
4055
  }
3889
4056
  __name(controllersForSurface, "controllersForSurface");
3890
4057
  var GUARDS_METADATA = "__guards__";
@@ -3916,7 +4083,6 @@ var AgentModule = class _AgentModule {
3916
4083
  }
3917
4084
  static forRoot(options) {
3918
4085
  const path = options.path ?? DEFAULT_PATH;
3919
- const includeStore = options.store !== void 0;
3920
4086
  applyGuards(options.guards);
3921
4087
  return {
3922
4088
  module: _AgentModule,
@@ -3925,21 +4091,20 @@ var AgentModule = class _AgentModule {
3925
4091
  import_core4.DiscoveryModule,
3926
4092
  routerFor(path)
3927
4093
  ],
3928
- controllers: controllersForSurface(options.surface, options.attachments?.upload === true),
4094
+ controllers: controllersForSurface(options.surface),
3929
4095
  providers: [
3930
4096
  {
3931
- provide: import_nestjs_agent_core23.AGENT_OPTIONS,
4097
+ provide: import_nestjs_agent_core24.AGENT_OPTIONS,
3932
4098
  useValue: options
3933
4099
  },
3934
- ...sharedProviders(options.durable ?? false, includeStore),
4100
+ ...sharedProviders(options.durable ?? false),
3935
4101
  ...guardProviders(options.guards)
3936
4102
  ],
3937
- exports: exportsFor(includeStore)
4103
+ exports: exportsFor()
3938
4104
  };
3939
4105
  }
3940
4106
  static forRootAsync(options) {
3941
4107
  const path = options.path ?? DEFAULT_PATH;
3942
- const includeStore = options.externalStore !== true;
3943
4108
  applyGuards(options.guards);
3944
4109
  return {
3945
4110
  module: _AgentModule,
@@ -3949,10 +4114,10 @@ var AgentModule = class _AgentModule {
3949
4114
  routerFor(path),
3950
4115
  ...options.imports ?? []
3951
4116
  ],
3952
- controllers: controllersForSurface(options.surface, options.attachmentsUpload === true),
4117
+ controllers: controllersForSurface(options.surface),
3953
4118
  providers: [
3954
4119
  {
3955
- provide: import_nestjs_agent_core23.AGENT_OPTIONS,
4120
+ provide: import_nestjs_agent_core24.AGENT_OPTIONS,
3956
4121
  // Stamp the STATIC wiring flags onto the factory result: `durable`/`surface` are
3957
4122
  // authoritative on the async config object (they decided the actual wiring above), and
3958
4123
  // the durable module reads `durable` back off AGENT_OPTIONS. `surface` isn't read back by
@@ -3966,20 +4131,20 @@ var AgentModule = class _AgentModule {
3966
4131
  }), "useFactory"),
3967
4132
  inject: options.inject ?? []
3968
4133
  },
3969
- ...sharedProviders(options.durable ?? false, includeStore),
4134
+ ...sharedProviders(options.durable ?? false),
3970
4135
  ...guardProviders(options.guards)
3971
4136
  ],
3972
- exports: exportsFor(includeStore)
4137
+ exports: exportsFor()
3973
4138
  };
3974
4139
  }
3975
4140
  };
3976
- AgentModule = _ts_decorate19([
3977
- (0, import_common19.Global)(),
3978
- (0, import_common19.Module)({})
4141
+ AgentModule = _ts_decorate20([
4142
+ (0, import_common20.Global)(),
4143
+ (0, import_common20.Module)({})
3979
4144
  ], AgentModule);
3980
4145
 
3981
4146
  // src/resolver/header-actor-resolver.ts
3982
- var import_common20 = require("@nestjs/common");
4147
+ var import_common21 = require("@nestjs/common");
3983
4148
  function readHeader(req, name) {
3984
4149
  if (typeof req !== "object" || req === null || !("headers" in req)) return void 0;
3985
4150
  const { headers } = req;
@@ -3995,7 +4160,7 @@ var HeaderActorResolver = class {
3995
4160
  resolve(req) {
3996
4161
  const id = readHeader(req, "x-actor-id");
3997
4162
  if (id === void 0 || id.length === 0) {
3998
- throw new import_common20.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.");
4163
+ throw new import_common21.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.");
3999
4164
  }
4000
4165
  const roles = (readHeader(req, "x-actor-role") ?? "").split(",").map((role) => role.trim()).filter((role) => role.length > 0);
4001
4166
  const tenantRef = readHeader(req, "x-tenant-ref");
@@ -4009,6 +4174,49 @@ var HeaderActorResolver = class {
4009
4174
  }
4010
4175
  };
4011
4176
 
4177
+ // src/resolver/request-user-actor-resolver.ts
4178
+ var import_common22 = require("@nestjs/common");
4179
+ function field(user, ...names) {
4180
+ for (const name of names) {
4181
+ const value = user[name];
4182
+ if (value !== void 0 && value !== null && value !== "") return value;
4183
+ }
4184
+ return void 0;
4185
+ }
4186
+ __name(field, "field");
4187
+ function defaultRequestUserMapper(user) {
4188
+ const id = field(user, "id", "sub", "_id", "userId");
4189
+ if (id === void 0) {
4190
+ throw new import_common22.UnauthorizedException("requestUserActorResolver: req.user has no id/sub/_id/userId \u2014 pass a mapper: requestUserActorResolver((user) => ({ id: \u2026, roles: \u2026 }))");
4191
+ }
4192
+ const rawRoles = field(user, "roles", "role");
4193
+ const roles = Array.isArray(rawRoles) ? rawRoles.map(String) : typeof rawRoles === "string" ? [
4194
+ rawRoles
4195
+ ] : [];
4196
+ const tenant = field(user, "tenantRef", "tenantId", "orgId");
4197
+ return {
4198
+ id: String(id),
4199
+ roles,
4200
+ ...tenant !== void 0 ? {
4201
+ tenantRef: String(tenant)
4202
+ } : {}
4203
+ };
4204
+ }
4205
+ __name(defaultRequestUserMapper, "defaultRequestUserMapper");
4206
+ function requestUserActorResolver(map) {
4207
+ return {
4208
+ async resolve(req) {
4209
+ const user = typeof req === "object" && req !== null ? req.user : void 0;
4210
+ if (user === void 0 || user === null || user === false) {
4211
+ throw new import_common22.UnauthorizedException("Sign in to use the agent.");
4212
+ }
4213
+ if (map !== void 0) return map(user, req);
4214
+ return defaultRequestUserMapper(user);
4215
+ }
4216
+ };
4217
+ }
4218
+ __name(requestUserActorResolver, "requestUserActorResolver");
4219
+
4012
4220
  // src/index.ts
4013
4221
  __reExport(index_exports, require("@dudousxd/nestjs-agent-core"), module.exports);
4014
4222
  // Annotate the CommonJS export names for ESM import in node:
@@ -4025,14 +4233,16 @@ __reExport(index_exports, require("@dudousxd/nestjs-agent-core"), module.exports
4025
4233
  AgentService,
4026
4234
  AiTool,
4027
4235
  AiToolDiscoveryService,
4236
+ AnonymousActorResolver,
4028
4237
  AttachmentsController,
4238
+ ConfigController,
4029
4239
  DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES,
4030
4240
  DEFAULT_MAX_ATTACHMENT_BYTES,
4031
4241
  HeaderActorResolver,
4032
4242
  InProcessTokenStreamSink,
4033
4243
  InlineAgentRunner,
4034
4244
  LedgerQuotaProvider,
4035
- LedgerQuotaStore,
4245
+ MAX_ATTACHMENTS_PER_MESSAGE,
4036
4246
  MemoriesController,
4037
4247
  MessagesController,
4038
4248
  ModelsController,
@@ -4045,15 +4255,19 @@ __reExport(index_exports, require("@dudousxd/nestjs-agent-core"), module.exports
4045
4255
  SystemPrompt,
4046
4256
  SystemPromptContributor,
4047
4257
  ToolsController,
4258
+ attachmentLimits,
4048
4259
  declaredSkillProvider,
4260
+ defaultRequestUserMapper,
4049
4261
  delegateToolName,
4050
4262
  provideAgentTool,
4051
4263
  provideAgentTools,
4052
4264
  readAgentMetadata,
4053
4265
  readAiToolMetadata,
4054
4266
  readSkillMetadata,
4267
+ requestUserActorResolver,
4055
4268
  resolveSkillsConfig,
4056
4269
  skillScope,
4270
+ toolNameFromClass,
4057
4271
  utcDay,
4058
4272
  ...require("@dudousxd/nestjs-agent-core")
4059
4273
  });