@dudousxd/nestjs-agent 2.0.2 → 2.1.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.
@@ -12506,7 +12506,7 @@ AgentDurableModule = _ts_decorate4([
12506
12506
  ], AgentDurableModule);
12507
12507
 
12508
12508
  // src/agent.module.ts
12509
- var import_nestjs_agent_core47 = require("@dudousxd/nestjs-agent-core");
12509
+ var import_nestjs_agent_core48 = require("@dudousxd/nestjs-agent-core");
12510
12510
  var import_common36 = require("@nestjs/common");
12511
12511
  var import_core6 = require("@nestjs/core");
12512
12512
 
@@ -13299,9 +13299,11 @@ var ActionProposalService = class {
13299
13299
  }
13300
13300
  store;
13301
13301
  options;
13302
- constructor(store, options) {
13302
+ contextAccessor;
13303
+ constructor(store, options, contextAccessor) {
13303
13304
  this.store = store;
13304
13305
  this.options = options;
13306
+ this.contextAccessor = contextAccessor;
13305
13307
  const text = options.actionProposalText;
13306
13308
  this.vocabulary = {
13307
13309
  ...import_nestjs_agent_core13.DEFAULT_TEXT_ACTION_PROPOSAL_VOCABULARY,
@@ -13327,6 +13329,8 @@ var ActionProposalService = class {
13327
13329
  async scope(threadId, actor) {
13328
13330
  const scope = await this.capability().getThreadActionProposalScope(threadId);
13329
13331
  if (!scope) throw new import_common7.NotFoundException("Thread not found");
13332
+ const filter = (0, import_nestjs_agent_core13.tenantRowFilter)((0, import_nestjs_agent_core13.readTenancy)(this.options.tenancy ?? "inherit", this.contextAccessor), actor.tenantRef);
13333
+ if (filter !== void 0 && !(0, import_nestjs_agent_core13.tenantRowVisible)(filter, scope.tenantRef)) throw new import_common7.NotFoundException("Thread not found");
13330
13334
  if (scope.tenantRef !== (actor.tenantRef ?? null)) throw new import_common7.ForbiddenException("Wrong proposal tenant");
13331
13335
  return scope;
13332
13336
  }
@@ -13446,10 +13450,13 @@ ActionProposalService = _ts_decorate7([
13446
13450
  (0, import_common7.Injectable)(),
13447
13451
  _ts_param5(0, (0, import_common7.Inject)(import_nestjs_agent_core13.AGENT_STORE)),
13448
13452
  _ts_param5(1, (0, import_common7.Inject)(import_nestjs_agent_core13.AGENT_OPTIONS)),
13453
+ _ts_param5(2, (0, import_common7.Optional)()),
13454
+ _ts_param5(2, (0, import_common7.Inject)(import_nestjs_agent_core13.CONTEXT_ACCESSOR)),
13449
13455
  _ts_metadata5("design:type", Function),
13450
13456
  _ts_metadata5("design:paramtypes", [
13451
13457
  typeof AgentStore === "undefined" ? Object : AgentStore,
13452
- typeof Pick === "undefined" ? Object : Pick
13458
+ typeof Pick === "undefined" ? Object : Pick,
13459
+ Object
13453
13460
  ])
13454
13461
  ], ActionProposalService);
13455
13462
 
@@ -14084,7 +14091,8 @@ var AgentService = class {
14084
14091
  options;
14085
14092
  queue;
14086
14093
  proposals;
14087
- constructor(runner, store, deps, staging, models, quotaProvider, options, queue, proposals) {
14094
+ contextAccessor;
14095
+ constructor(runner, store, deps, staging, models, quotaProvider, options, queue, proposals, contextAccessor) {
14088
14096
  this.runner = runner;
14089
14097
  this.store = store;
14090
14098
  this.deps = deps;
@@ -14094,6 +14102,58 @@ var AgentService = class {
14094
14102
  this.options = options;
14095
14103
  this.queue = queue;
14096
14104
  this.proposals = proposals;
14105
+ this.contextAccessor = contextAccessor;
14106
+ }
14107
+ /**
14108
+ * With tenancy on, the store must be able to tell a thread's tenant: fail the boot with the fix
14109
+ * rather than answer every thread read `404` at runtime. Tenancy enabled explicitly with no
14110
+ * context accessor to read the tenant from fails the boot too.
14111
+ */
14112
+ onApplicationBootstrap() {
14113
+ if (!this.tenancy().enabled) {
14114
+ const option = this.options?.tenancy;
14115
+ if (typeof option === "object" && option.enabled === true) {
14116
+ throw new Error("AgentModule tenancy is enabled explicitly, but no `@dudousxd/nestjs-context` accessor (1.2.0 or later) is available to read the tenant from, so every read would be unscoped. Import `ContextModule`, or remove `tenancy.enabled: true`.");
14117
+ }
14118
+ return;
14119
+ }
14120
+ const missing = [
14121
+ "tenantOf",
14122
+ "listThreadsForTenant"
14123
+ ].filter((method) => typeof this.store[method] !== "function");
14124
+ if (missing.length > 0) {
14125
+ throw new Error(`AgentModule tenancy is on, and ${this.store.constructor.name} does not implement ${missing.join(" / ")}, so thread reads cannot be scoped by tenant. Use a store that does (in-memory, Drizzle, MikroORM), implement them, or set AgentModule's \`tenancy: false\`.`);
14126
+ }
14127
+ }
14128
+ /**
14129
+ * The matching rule for a decision that comes from outside the thread's own actor (the console's
14130
+ * approvals inbox): with tenancy on, a tool call on a thread the request's context tenant may not
14131
+ * see is not found. A no-op with tenancy off.
14132
+ */
14133
+ async assertToolCallInRequestTenant(toolCallId2) {
14134
+ const filter = (0, import_nestjs_agent_core17.tenantRowFilter)(this.tenancy());
14135
+ if (filter === void 0) return;
14136
+ const row = typeof this.store.tenantOf === "function" ? await this.store.tenantOf({
14137
+ toolCallId: toolCallId2
14138
+ }) : null;
14139
+ if (row === null || !(0, import_nestjs_agent_core17.tenantRowVisible)(filter, row.tenantRef)) {
14140
+ throw new import_common10.NotFoundException(`tool call ${toolCallId2} not found`);
14141
+ }
14142
+ }
14143
+ /** The agent's tenancy, read per call: the context's switch can be flipped at any time. */
14144
+ tenancy() {
14145
+ return (0, import_nestjs_agent_core17.readTenancy)(this.options?.tenancy ?? "inherit", this.contextAccessor);
14146
+ }
14147
+ /**
14148
+ * The matching rule for one thread, run or tool call: with tenancy on, a row of another tenant
14149
+ * (or, for a request with a tenant, one with no tenant unless `nullRows: 'shared'`) is not found.
14150
+ * The request's tenant is `actor.tenantRef` (the resolver's, else the context's), else none.
14151
+ */
14152
+ async assertTenantVisible(actor, target, notFound) {
14153
+ const filter = (0, import_nestjs_agent_core17.tenantRowFilter)(this.tenancy(), actor.tenantRef);
14154
+ if (filter === void 0) return;
14155
+ const row = typeof this.store.tenantOf === "function" ? await this.store.tenantOf(target) : null;
14156
+ if (row === null || !(0, import_nestjs_agent_core17.tenantRowVisible)(filter, row.tenantRef)) throw notFound();
14097
14157
  }
14098
14158
  /**
14099
14159
  * Decide one independent proposal through the scoped proposal service — what the native
@@ -14831,6 +14891,9 @@ var AgentService = class {
14831
14891
  if (owner === null) {
14832
14892
  throw new RunNotActiveException(runId);
14833
14893
  }
14894
+ await this.assertTenantVisible(actor, {
14895
+ runId
14896
+ }, () => new RunNotActiveException(runId));
14834
14897
  if (owner !== actor.id) {
14835
14898
  throw new import_common10.ForbiddenException("run belongs to another actor");
14836
14899
  }
@@ -14853,8 +14916,15 @@ var AgentService = class {
14853
14916
  await this.assertOwnsActiveStream(actor, runId);
14854
14917
  return this.runner.cancel(runId);
14855
14918
  }
14856
- async listThreads(actorRef) {
14857
- const threads = await this.store.listThreads(actorRef);
14919
+ /**
14920
+ * The actor's threads. With tenancy on, only those the request's tenant may see: pass the
14921
+ * {@link Actor} so a `tenantRef` its resolver set is the tenant; a bare `actorRef` uses the
14922
+ * context's.
14923
+ */
14924
+ async listThreads(actor) {
14925
+ const actorRef = typeof actor === "string" ? actor : actor.id;
14926
+ const filter = (0, import_nestjs_agent_core17.tenantRowFilter)(this.tenancy(), typeof actor === "string" ? void 0 : actor.tenantRef);
14927
+ const threads = filter === void 0 ? await this.store.listThreads(actorRef) : typeof this.store.listThreadsForTenant === "function" ? await this.store.listThreadsForTenant(actorRef, filter) : [];
14858
14928
  return Promise.all(threads.map((thread) => this.toSummaryView(thread)));
14859
14929
  }
14860
14930
  async getThread(actor, threadId) {
@@ -14876,6 +14946,9 @@ var AgentService = class {
14876
14946
  if (await this.store.ownerOfThread(threadId) === null) {
14877
14947
  throw new import_common10.NotFoundException(`thread ${threadId} not found`);
14878
14948
  }
14949
+ await this.assertTenantVisible(actor, {
14950
+ threadId
14951
+ }, () => new import_common10.NotFoundException(`thread ${threadId} not found`));
14879
14952
  } else {
14880
14953
  await this.assertOwnsThread(actor, threadId);
14881
14954
  }
@@ -15178,6 +15251,9 @@ var AgentService = class {
15178
15251
  if (owner === null) {
15179
15252
  throw new import_common10.NotFoundException(`thread ${threadId} not found`);
15180
15253
  }
15254
+ await this.assertTenantVisible(actor, {
15255
+ threadId
15256
+ }, () => new import_common10.NotFoundException(`thread ${threadId} not found`));
15181
15257
  if (owner !== actor.id) {
15182
15258
  throw new import_common10.ForbiddenException("thread belongs to another actor");
15183
15259
  }
@@ -15192,6 +15268,9 @@ var AgentService = class {
15192
15268
  if (owner === null) {
15193
15269
  throw new import_common10.NotFoundException(`tool call ${toolCallId2} not found`);
15194
15270
  }
15271
+ await this.assertTenantVisible(actor, {
15272
+ toolCallId: toolCallId2
15273
+ }, () => new import_common10.NotFoundException(`tool call ${toolCallId2} not found`));
15195
15274
  if (owner !== actor.id) {
15196
15275
  throw new import_common10.ForbiddenException("tool call belongs to another actor");
15197
15276
  }
@@ -15233,6 +15312,9 @@ var AgentService = class {
15233
15312
  if (requesterRef === null) {
15234
15313
  throw new import_common10.NotFoundException(`tool call ${toolCallId2} not found`);
15235
15314
  }
15315
+ await this.assertTenantVisible(actor, {
15316
+ toolCallId: toolCallId2
15317
+ }, () => new import_common10.NotFoundException(`tool call ${toolCallId2} not found`));
15236
15318
  const allowed = await (0, import_nestjs_agent_core17.mayDecideApproval)(this.deps.forAgent().approvalPolicy, actor, {
15237
15319
  toolCallId: toolCallId2,
15238
15320
  approver,
@@ -15278,6 +15360,9 @@ var AgentService = class {
15278
15360
  if (owner === null) {
15279
15361
  throw new import_common10.NotFoundException(`no active run ${runId}`);
15280
15362
  }
15363
+ await this.assertTenantVisible(actor, {
15364
+ runId
15365
+ }, () => new import_common10.NotFoundException(`no active run ${runId}`));
15281
15366
  if (owner !== actor.id) {
15282
15367
  throw new import_common10.ForbiddenException("run belongs to another actor");
15283
15368
  }
@@ -15298,11 +15383,15 @@ var AgentService = class {
15298
15383
  * against nobody.
15299
15384
  */
15300
15385
  recordUsage(input, options = {}) {
15386
+ const tenantRef = input.tenantRef ?? (0, import_nestjs_agent_core17.contextTenantRef)(this.tenancy());
15301
15387
  return (0, import_nestjs_agent_core17.recordAiUsage)({
15302
15388
  store: this.store,
15303
15389
  quota: this.deps.forAgent().quota,
15304
15390
  day: utcDay(),
15305
- input,
15391
+ input: tenantRef !== void 0 && input.tenantRef === void 0 ? {
15392
+ ...input,
15393
+ tenantRef
15394
+ } : input,
15306
15395
  options,
15307
15396
  warn: /* @__PURE__ */ __name((message) => usageLogger.warn(message), "warn")
15308
15397
  });
@@ -15323,6 +15412,8 @@ AgentService = _ts_decorate9([
15323
15412
  _ts_param7(6, (0, import_common10.Inject)(import_nestjs_agent_core17.AGENT_OPTIONS)),
15324
15413
  _ts_param7(7, (0, import_common10.Optional)()),
15325
15414
  _ts_param7(8, (0, import_common10.Optional)()),
15415
+ _ts_param7(9, (0, import_common10.Optional)()),
15416
+ _ts_param7(9, (0, import_common10.Inject)(import_nestjs_agent_core17.CONTEXT_ACCESSOR)),
15326
15417
  _ts_metadata7("design:type", Function),
15327
15418
  _ts_metadata7("design:paramtypes", [
15328
15419
  typeof AgentRunner === "undefined" ? Object : AgentRunner,
@@ -15333,7 +15424,8 @@ AgentService = _ts_decorate9([
15333
15424
  typeof QuotaProvider === "undefined" ? Object : QuotaProvider,
15334
15425
  typeof Pick === "undefined" ? Object : Pick,
15335
15426
  typeof ChatQueueService2 === "undefined" ? Object : ChatQueueService2,
15336
- typeof ActionProposalService === "undefined" ? Object : ActionProposalService
15427
+ typeof ActionProposalService === "undefined" ? Object : ActionProposalService,
15428
+ Object
15337
15429
  ])
15338
15430
  ], AgentService);
15339
15431
 
@@ -15396,6 +15488,7 @@ var AgentApprovalPortAdapter = class {
15396
15488
  });
15397
15489
  }
15398
15490
  async approve(toolCallId2, opts) {
15491
+ await this.agent.assertToolCallInRequestTenant(toolCallId2);
15399
15492
  await this.agent.signalToolCall(toolCallId2, {
15400
15493
  approved: true,
15401
15494
  ...opts?.executedByRef !== void 0 ? {
@@ -15410,6 +15503,7 @@ var AgentApprovalPortAdapter = class {
15410
15503
  });
15411
15504
  }
15412
15505
  async reject(toolCallId2, opts) {
15506
+ await this.agent.assertToolCallInRequestTenant(toolCallId2);
15413
15507
  await this.agent.signalToolCall(toolCallId2, {
15414
15508
  approved: false,
15415
15509
  ...opts?.executedByRef !== void 0 ? {
@@ -16762,7 +16856,7 @@ var ThreadsController = class {
16762
16856
  }
16763
16857
  async list(req) {
16764
16858
  const actor = await this.actorResolver.resolve(req);
16765
- return this.agent.listThreads(actor.id);
16859
+ return this.agent.listThreads(actor);
16766
16860
  }
16767
16861
  async detail(req, id) {
16768
16862
  const actor = await this.actorResolver.resolve(req);
@@ -17973,6 +18067,10 @@ var LedgerQuotaProvider = class {
17973
18067
  this.store = store;
17974
18068
  this.limits = limits;
17975
18069
  this.options = options;
18070
+ const per = options.per ?? "actor";
18071
+ if (per !== "actor" && typeof store.usageWindowsForTenant !== "function") {
18072
+ throw new Error(`quota.per: '${per}' sums the usage ledger by tenant, and ${store.constructor.name} does not implement usageWindowsForTenant. Use a store that does (in-memory, Drizzle, MikroORM) or a QuotaProvider of your own.`);
18073
+ }
17976
18074
  }
17977
18075
  async report(query) {
17978
18076
  const now = query.now ?? /* @__PURE__ */ new Date();
@@ -17980,7 +18078,16 @@ var LedgerQuotaProvider = class {
17980
18078
  const day = (0, import_nestjs_agent_core38.quotaPeriodRange)("day", now);
17981
18079
  const month = (0, import_nestjs_agent_core38.quotaPeriodRange)("month", now);
17982
18080
  const windows = [];
17983
- if (this.store.usageWindows !== void 0) {
18081
+ const per = this.options.per ?? "actor";
18082
+ const tenantRef = query.actor.tenantRef;
18083
+ if (per !== "actor" && typeof tenantRef === "string" && tenantRef !== "" && this.store.usageWindowsForTenant !== void 0) {
18084
+ const [dayUsed, monthUsed] = await this.store.usageWindowsForTenant(tenantRef, [
18085
+ day,
18086
+ month
18087
+ ], per === "actor-in-tenant" ? actorRef : void 0);
18088
+ windows.push(this.usedWindow("day", dayUsed, day.resetsAt));
18089
+ windows.push(this.usedWindow("month", monthUsed, month.resetsAt));
18090
+ } else if (this.store.usageWindows !== void 0) {
17984
18091
  const [dayUsed, monthUsed] = await this.store.usageWindows(actorRef, [
17985
18092
  day,
17986
18093
  month
@@ -19017,8 +19124,21 @@ ActionProposalController = _ts_decorate31([
19017
19124
  ])
19018
19125
  ], ActionProposalController);
19019
19126
 
19020
- // src/runner/inline-agent-runner.ts
19127
+ // src/resolver/tenant-filling-resolver.ts
19021
19128
  var import_nestjs_agent_core45 = require("@dudousxd/nestjs-agent-core");
19129
+ function tenantFillingResolver(resolver, tenancy, contextAccessor) {
19130
+ if (tenancy === false) return resolver;
19131
+ const wrapper = Object.create(resolver);
19132
+ Object.defineProperty(wrapper, "resolve", {
19133
+ value: /* @__PURE__ */ __name(async (req) => (0, import_nestjs_agent_core45.withContextTenant)(await resolver.resolve(req), (0, import_nestjs_agent_core45.readTenancy)(tenancy ?? "inherit", contextAccessor ?? void 0)), "value"),
19134
+ enumerable: false
19135
+ });
19136
+ return wrapper;
19137
+ }
19138
+ __name(tenantFillingResolver, "tenantFillingResolver");
19139
+
19140
+ // src/runner/inline-agent-runner.ts
19141
+ var import_nestjs_agent_core46 = require("@dudousxd/nestjs-agent-core");
19022
19142
  var import_common35 = require("@nestjs/common");
19023
19143
  function _ts_decorate32(decorators, target, key, desc) {
19024
19144
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -19109,30 +19229,30 @@ var InlineAgentRunner = class _InlineAgentRunner {
19109
19229
  ],
19110
19230
  input
19111
19231
  });
19112
- void (0, import_nestjs_agent_core45.runAgentLoop)({
19232
+ void (0, import_nestjs_agent_core46.runAgentLoop)({
19113
19233
  ...deps,
19114
19234
  day
19115
- }, input, hooks).then(() => (0, import_nestjs_agent_core45.releaseThreadRun)(this.store, input.threadId, runId)).catch(async (error) => {
19116
- const durationMs = (0, import_nestjs_agent_core45.runDurationMs)(error);
19235
+ }, input, hooks).then(() => (0, import_nestjs_agent_core46.releaseThreadRun)(this.store, input.threadId, runId)).catch(async (error) => {
19236
+ const durationMs = (0, import_nestjs_agent_core46.runDurationMs)(error);
19117
19237
  const timed = durationMs !== void 0 ? {
19118
19238
  durationMs
19119
19239
  } : {};
19120
- const measured = (0, import_nestjs_agent_core45.runEndTimings)(error);
19121
- if (error instanceof import_nestjs_agent_core45.RunCancelledError) {
19240
+ const measured = (0, import_nestjs_agent_core46.runEndTimings)(error);
19241
+ if (error instanceof import_nestjs_agent_core46.RunCancelledError) {
19122
19242
  await this.settleCancelled(runId, input, deps, durationMs, measured);
19123
19243
  return;
19124
19244
  }
19125
19245
  const message = error instanceof Error ? error.message : String(error);
19126
- const code = (0, import_nestjs_agent_core45.agentFailureCode)(error);
19246
+ const code = (0, import_nestjs_agent_core46.agentFailureCode)(error);
19127
19247
  this.logger.error(`agent run ${runId} failed (${code}): ${message}`);
19128
- (0, import_nestjs_agent_core45.publishAgentRunFailed)({
19248
+ (0, import_nestjs_agent_core46.publishAgentRunFailed)({
19129
19249
  runId,
19130
19250
  threadId: input.threadId,
19131
19251
  code,
19132
19252
  message,
19133
19253
  ...timed,
19134
19254
  ...measured,
19135
- context: (0, import_nestjs_agent_core45.agentRunContext)(input)
19255
+ context: (0, import_nestjs_agent_core46.agentRunContext)(input)
19136
19256
  });
19137
19257
  await this.store.recordRunEnd?.({
19138
19258
  runId,
@@ -19141,11 +19261,11 @@ var InlineAgentRunner = class _InlineAgentRunner {
19141
19261
  errorCode: code,
19142
19262
  errorMessage: message
19143
19263
  });
19144
- await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core45.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
19264
+ await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core46.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
19145
19265
  const writer = await deps.sink.open(runId);
19146
19266
  await this.settleQueue(writer, input, runId, "failed", message);
19147
- await (0, import_nestjs_agent_core45.releaseThreadRun)(this.store, input.threadId, runId);
19148
- await writer.fail((0, import_nestjs_agent_core45.streamFailure)(error));
19267
+ await (0, import_nestjs_agent_core46.releaseThreadRun)(this.store, input.threadId, runId);
19268
+ await writer.fail((0, import_nestjs_agent_core46.streamFailure)(error));
19149
19269
  }).finally(() => {
19150
19270
  this.forgetCancel(runId);
19151
19271
  this.live.delete(runId);
@@ -19180,11 +19300,11 @@ var InlineAgentRunner = class _InlineAgentRunner {
19180
19300
  */
19181
19301
  async cancel(runId) {
19182
19302
  this.cancelled.add(runId);
19183
- this.aborts.get(runId)?.abort(new import_nestjs_agent_core45.RunCancelledError());
19303
+ this.aborts.get(runId)?.abort(new import_nestjs_agent_core46.RunCancelledError());
19184
19304
  for (const [key, waiter] of this.pending) {
19185
19305
  if (key.startsWith(`${runId}:`)) {
19186
19306
  this.pending.delete(key);
19187
- waiter.reject(new import_nestjs_agent_core45.RunCancelledError());
19307
+ waiter.reject(new import_nestjs_agent_core46.RunCancelledError());
19188
19308
  }
19189
19309
  }
19190
19310
  await Promise.resolve();
@@ -19214,17 +19334,17 @@ var InlineAgentRunner = class _InlineAgentRunner {
19214
19334
  const timed = durationMs !== void 0 ? {
19215
19335
  durationMs
19216
19336
  } : {};
19217
- (0, import_nestjs_agent_core45.publishAgentRunCancelled)({
19337
+ (0, import_nestjs_agent_core46.publishAgentRunCancelled)({
19218
19338
  runId,
19219
19339
  threadId: input.threadId,
19220
19340
  ...timed,
19221
19341
  ...measured,
19222
- context: (0, import_nestjs_agent_core45.agentRunContext)(input)
19342
+ context: (0, import_nestjs_agent_core46.agentRunContext)(input)
19223
19343
  });
19224
19344
  const writer = await deps.sink.open(runId);
19225
19345
  await this.settleQueue(writer, input, runId, "cancelled");
19226
- await (0, import_nestjs_agent_core45.releaseThreadRun)(this.store, input.threadId, runId);
19227
- await writer.write((0, import_nestjs_agent_core45.encodeStreamEvent)({
19346
+ await (0, import_nestjs_agent_core46.releaseThreadRun)(this.store, input.threadId, runId);
19347
+ await writer.write((0, import_nestjs_agent_core46.encodeStreamEvent)({
19228
19348
  kind: "cancelled"
19229
19349
  }));
19230
19350
  await writer.end();
@@ -19260,7 +19380,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
19260
19380
  runId: nextRunId
19261
19381
  }));
19262
19382
  if (frame !== void 0) {
19263
- await writer.write((0, import_nestjs_agent_core45.encodeStreamEvent)(frame));
19383
+ await writer.write((0, import_nestjs_agent_core46.encodeStreamEvent)(frame));
19264
19384
  }
19265
19385
  } catch (failure) {
19266
19386
  this.logger.error(`could not advance the queue of thread ${input.threadId} after run ${runId}: ${failure instanceof Error ? failure.message : String(failure)}`);
@@ -19332,7 +19452,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
19332
19452
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
19333
19453
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
19334
19454
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
19335
- parallel: import_nestjs_agent_core45.settleAll,
19455
+ parallel: import_nestjs_agent_core46.settleAll,
19336
19456
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
19337
19457
  abortSignal: this.abortSignalFor(runId),
19338
19458
  runAgent: /* @__PURE__ */ __name((agentName, task) => this.runNested({
@@ -19384,7 +19504,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
19384
19504
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
19385
19505
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
19386
19506
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
19387
- parallel: import_nestjs_agent_core45.settleAll,
19507
+ parallel: import_nestjs_agent_core46.settleAll,
19388
19508
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
19389
19509
  abortSignal: this.abortSignalFor(runId),
19390
19510
  runAgent: /* @__PURE__ */ __name((childName, childTask) => this.runNested({
@@ -19429,31 +19549,31 @@ var InlineAgentRunner = class _InlineAgentRunner {
19429
19549
  parentRunId,
19430
19550
  deliverTo
19431
19551
  };
19432
- void (0, import_nestjs_agent_core45.runAgentLoop)({
19552
+ void (0, import_nestjs_agent_core46.runAgentLoop)({
19433
19553
  ...deps,
19434
19554
  day
19435
19555
  }, childInput, hooks).catch(async (error) => {
19436
- const cancelled = error instanceof import_nestjs_agent_core45.RunCancelledError;
19556
+ const cancelled = error instanceof import_nestjs_agent_core46.RunCancelledError;
19437
19557
  const message = error instanceof Error ? error.message : String(error);
19438
- const durationMs = (0, import_nestjs_agent_core45.runDurationMs)(error);
19558
+ const durationMs = (0, import_nestjs_agent_core46.runDurationMs)(error);
19439
19559
  const timed = durationMs !== void 0 ? {
19440
19560
  durationMs
19441
19561
  } : {};
19442
- const measured = (0, import_nestjs_agent_core45.runEndTimings)(error);
19562
+ const measured = (0, import_nestjs_agent_core46.runEndTimings)(error);
19443
19563
  const settled = {
19444
19564
  runId,
19445
19565
  threadId: subThread.id,
19446
19566
  ...timed,
19447
19567
  ...measured,
19448
- context: (0, import_nestjs_agent_core45.agentRunContext)(childInput)
19568
+ context: (0, import_nestjs_agent_core46.agentRunContext)(childInput)
19449
19569
  };
19450
19570
  if (cancelled) {
19451
- (0, import_nestjs_agent_core45.publishAgentRunCancelled)(settled);
19571
+ (0, import_nestjs_agent_core46.publishAgentRunCancelled)(settled);
19452
19572
  } else {
19453
19573
  this.logger.error(`detached agent run ${runId} failed: ${message}`);
19454
- (0, import_nestjs_agent_core45.publishAgentRunFailed)({
19574
+ (0, import_nestjs_agent_core46.publishAgentRunFailed)({
19455
19575
  ...settled,
19456
- code: (0, import_nestjs_agent_core45.agentFailureCode)(error),
19576
+ code: (0, import_nestjs_agent_core46.agentFailureCode)(error),
19457
19577
  message
19458
19578
  });
19459
19579
  }
@@ -19462,12 +19582,12 @@ var InlineAgentRunner = class _InlineAgentRunner {
19462
19582
  status: cancelled ? "cancelled" : "failed",
19463
19583
  ...timed,
19464
19584
  ...cancelled ? {} : {
19465
- errorCode: (0, import_nestjs_agent_core45.agentFailureCode)(error),
19585
+ errorCode: (0, import_nestjs_agent_core46.agentFailureCode)(error),
19466
19586
  errorMessage: message
19467
19587
  }
19468
19588
  });
19469
- await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core45.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
19470
- await (0, import_nestjs_agent_core45.settleUnsettledDelegation)({
19589
+ await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core46.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
19590
+ await (0, import_nestjs_agent_core46.settleUnsettledDelegation)({
19471
19591
  store: this.store,
19472
19592
  delivery: deliverTo,
19473
19593
  agent: agentName,
@@ -19506,7 +19626,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
19506
19626
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
19507
19627
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
19508
19628
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
19509
- parallel: import_nestjs_agent_core45.settleAll,
19629
+ parallel: import_nestjs_agent_core46.settleAll,
19510
19630
  // A child stops when it is cancelled OR when the run a human is actually watching is: the
19511
19631
  // canceller names the top-level run, which is the only id that ever left the server.
19512
19632
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId) || this.cancelled.has(sinkRunId), "cancelled"),
@@ -19543,7 +19663,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
19543
19663
  }), "startAgent")
19544
19664
  };
19545
19665
  try {
19546
- return await (0, import_nestjs_agent_core45.runAgentLoop)({
19666
+ return await (0, import_nestjs_agent_core46.runAgentLoop)({
19547
19667
  ...deps,
19548
19668
  day
19549
19669
  }, {
@@ -19564,8 +19684,8 @@ var InlineAgentRunner = class _InlineAgentRunner {
19564
19684
  };
19565
19685
  InlineAgentRunner = _ts_decorate32([
19566
19686
  (0, import_common35.Injectable)(),
19567
- _ts_param29(0, (0, import_common35.Inject)(import_nestjs_agent_core45.AGENT_DEPS_FACTORY)),
19568
- _ts_param29(1, (0, import_common35.Inject)(import_nestjs_agent_core45.AGENT_STORE)),
19687
+ _ts_param29(0, (0, import_common35.Inject)(import_nestjs_agent_core46.AGENT_DEPS_FACTORY)),
19688
+ _ts_param29(1, (0, import_common35.Inject)(import_nestjs_agent_core46.AGENT_STORE)),
19569
19689
  _ts_param29(2, (0, import_common35.Optional)()),
19570
19690
  _ts_metadata30("design:type", Function),
19571
19691
  _ts_metadata30("design:paramtypes", [
@@ -19580,7 +19700,7 @@ function isThreadTurn2(input) {
19580
19700
  __name(isThreadTurn2, "isThreadTurn");
19581
19701
 
19582
19702
  // src/skills-config.ts
19583
- var import_nestjs_agent_core46 = require("@dudousxd/nestjs-agent-core");
19703
+ var import_nestjs_agent_core47 = require("@dudousxd/nestjs-agent-core");
19584
19704
  function declaredSkillProvider(declared) {
19585
19705
  return {
19586
19706
  list: /* @__PURE__ */ __name(({ scopes }) => declared.filter((skill) => scopes.includes(skill.scope)).map(({ name, description, scope }) => ({
@@ -19606,7 +19726,7 @@ function resolveSkillsConfig(options, declared) {
19606
19726
  declaredSkillProvider(declared)
19607
19727
  ];
19608
19728
  return {
19609
- provider: providers.length === 1 ? providers[0] : (0, import_nestjs_agent_core46.compositeSkillProvider)(providers),
19729
+ provider: providers.length === 1 ? providers[0] : (0, import_nestjs_agent_core47.compositeSkillProvider)(providers),
19610
19730
  ...options.scopes !== void 0 ? {
19611
19731
  scopes: options.scopes
19612
19732
  } : {},
@@ -19665,14 +19785,14 @@ function forwardingStore(wrapper) {
19665
19785
  __name(forwardingStore, "forwardingStore");
19666
19786
  function resolveStore(options, modules) {
19667
19787
  if (options.store !== void 0) return options.store;
19668
- const external = externalWrapper(modules, import_nestjs_agent_core47.AGENT_STORE);
19788
+ const external = externalWrapper(modules, import_nestjs_agent_core48.AGENT_STORE);
19669
19789
  if (external !== void 0) return forwardingStore(external);
19670
19790
  logger4.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()).");
19671
- return new import_nestjs_agent_core47.InMemoryAgentStore();
19791
+ return new import_nestjs_agent_core48.InMemoryAgentStore();
19672
19792
  }
19673
19793
  __name(resolveStore, "resolveStore");
19674
19794
  function resolveRolesPolicy(options, modules) {
19675
- const external = externalWrapper(modules, import_nestjs_agent_core47.AGENT_ROLES_POLICY);
19795
+ const external = externalWrapper(modules, import_nestjs_agent_core48.AGENT_ROLES_POLICY);
19676
19796
  if (options.rolesPolicy !== void 0) {
19677
19797
  if (external !== void 0) {
19678
19798
  logger4.warn("Both a `rolesPolicy` option and a module binding AGENT_ROLES_POLICY are configured \u2014 the `rolesPolicy` option wins. (For ability checks, use `@Can()` from @nestjs/authorization on the tool instead of a roles policy.)");
@@ -19680,7 +19800,7 @@ function resolveRolesPolicy(options, modules) {
19680
19800
  return options.rolesPolicy;
19681
19801
  }
19682
19802
  if (external !== void 0) return forwardingPolicy(external);
19683
- return options.emptyRoles === "deny" ? new import_nestjs_agent_core47.ClosedRolesPolicy(options.defaultRoles) : new import_nestjs_agent_core47.DefaultRolesPolicy(options.defaultRoles);
19803
+ return options.emptyRoles === "deny" ? new import_nestjs_agent_core48.ClosedRolesPolicy(options.defaultRoles) : new import_nestjs_agent_core48.DefaultRolesPolicy(options.defaultRoles);
19684
19804
  }
19685
19805
  __name(resolveRolesPolicy, "resolveRolesPolicy");
19686
19806
  function forwardingPolicy(wrapper) {
@@ -19716,128 +19836,138 @@ function sharedProviders(durable, engine) {
19716
19836
  const durableEngine = durableEngineOf(durable);
19717
19837
  const providers = [
19718
19838
  {
19719
- provide: import_nestjs_agent_core47.AGENT_TOOL_REGISTRY,
19720
- useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core47.ToolRegistry(), "useFactory")
19839
+ provide: import_nestjs_agent_core48.AGENT_TOOL_REGISTRY,
19840
+ useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core48.ToolRegistry(), "useFactory")
19721
19841
  },
19722
19842
  // Starts empty; AgentDiscoveryService populates it from `@Agent`-decorated providers at boot.
19723
19843
  {
19724
- provide: import_nestjs_agent_core47.AGENT_REGISTRY,
19725
- useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core47.AgentRegistry(), "useFactory")
19844
+ provide: import_nestjs_agent_core48.AGENT_REGISTRY,
19845
+ useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core48.AgentRegistry(), "useFactory")
19726
19846
  },
19727
19847
  // A shared, mutable list AgentDiscoveryService fills with `@SystemPromptContributor()` methods.
19728
19848
  {
19729
- provide: import_nestjs_agent_core47.AGENT_PROMPT_CONTRIBUTORS,
19849
+ provide: import_nestjs_agent_core48.AGENT_PROMPT_CONTRIBUTORS,
19730
19850
  useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
19731
19851
  },
19732
19852
  // Likewise for `@Skill`-decorated providers — filled by SkillDiscoveryService at onModuleInit,
19733
19853
  // read lazily by the AGENT_SKILLS provider below (which DI builds before discovery has run).
19734
19854
  {
19735
- provide: import_nestjs_agent_core47.AGENT_SKILL_SOURCES,
19855
+ provide: import_nestjs_agent_core48.AGENT_SKILL_SOURCES,
19736
19856
  useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
19737
19857
  },
19738
19858
  {
19739
19859
  // One resolution, shared by the loop's deps and the listing endpoint: a second one would
19740
19860
  // drift, and a user would be offered a skill the agent cannot reach. `undefined` when the
19741
19861
  // host configured none — which is what keeps the turn's checkpoint sequence unchanged.
19742
- provide: import_nestjs_agent_core47.AGENT_SKILLS,
19862
+ provide: import_nestjs_agent_core48.AGENT_SKILLS,
19743
19863
  // Personal agents resolve no skill scope (`personalAgentScopes`): nothing of the app's to load.
19744
19864
  useFactory: /* @__PURE__ */ __name((options, declared) => {
19745
19865
  const skills = resolveSkillsConfig(options.skills, declared);
19746
19866
  return skills === void 0 ? void 0 : {
19747
19867
  ...skills,
19748
- scopes: (0, import_nestjs_agent_core47.personalAgentScopes)(skills.scopes)
19868
+ scopes: (0, import_nestjs_agent_core48.personalAgentScopes)(skills.scopes)
19749
19869
  };
19750
19870
  }, "useFactory"),
19751
19871
  inject: [
19752
- import_nestjs_agent_core47.AGENT_OPTIONS,
19753
- import_nestjs_agent_core47.AGENT_SKILL_SOURCES
19872
+ import_nestjs_agent_core48.AGENT_OPTIONS,
19873
+ import_nestjs_agent_core48.AGENT_SKILL_SOURCES
19754
19874
  ]
19755
19875
  },
19756
19876
  {
19757
19877
  // One resolution, shared by the loop's deps and the read-back endpoint: a person has to be
19758
19878
  // shown what the model was shown, and two resolutions would eventually disagree about that.
19759
- provide: import_nestjs_agent_core47.AGENT_MEMORY,
19879
+ provide: import_nestjs_agent_core48.AGENT_MEMORY,
19760
19880
  // Personal agents resolve no memory scope (`personalAgentScopes`): under a signed-in Poppy
19761
19881
  // conversation the actor is the account, and it must neither read nor write its memories.
19762
19882
  useFactory: /* @__PURE__ */ __name((options) => options.memory === void 0 ? void 0 : {
19763
19883
  ...options.memory,
19764
- scopes: (0, import_nestjs_agent_core47.personalAgentScopes)(options.memory.scopes)
19884
+ scopes: (0, import_nestjs_agent_core48.personalAgentScopes)(options.memory.scopes)
19765
19885
  }, "useFactory"),
19766
19886
  inject: [
19767
- import_nestjs_agent_core47.AGENT_OPTIONS
19887
+ import_nestjs_agent_core48.AGENT_OPTIONS
19768
19888
  ]
19769
19889
  },
19770
19890
  {
19771
- provide: import_nestjs_agent_core47.AGENT_SINK,
19891
+ provide: import_nestjs_agent_core48.AGENT_SINK,
19772
19892
  useFactory: /* @__PURE__ */ __name((options) => options.sink ?? new InProcessTokenStreamSink(), "useFactory"),
19773
19893
  inject: [
19774
- import_nestjs_agent_core47.AGENT_OPTIONS
19894
+ import_nestjs_agent_core48.AGENT_OPTIONS
19775
19895
  ]
19776
19896
  },
19777
19897
  // `@nestjs/authorization`'s AuthorizationService, when the app imports AuthorizationModule.
19778
19898
  NestAuthorizationBinding,
19779
19899
  {
19780
- provide: import_nestjs_agent_core47.AGENT_ROLES_POLICY,
19900
+ provide: import_nestjs_agent_core48.AGENT_ROLES_POLICY,
19781
19901
  // Personal agents (a Poppy conversation, a Poppy session's MCP token) reach only the tools
19782
19902
  // written for them, and run only those of the scopes their user granted. A no-op for every
19783
19903
  // other actor. Around the roles policy, a tool's `@Can()` abilities are asked of
19784
19904
  // `@nestjs/authorization`, for the user its agent function calls run as.
19785
- useFactory: /* @__PURE__ */ __name((options, modules, authorization) => (0, import_nestjs_agent_core47.personalAgentGate)(authorizationGate(resolveRolesPolicy(options, modules), () => authorization.service, (actor) => (options.agentFunctionCaller ?? defaultAgentFunctionCaller)(actor).user)), "useFactory"),
19905
+ useFactory: /* @__PURE__ */ __name((options, modules, authorization) => (0, import_nestjs_agent_core48.personalAgentGate)(authorizationGate(resolveRolesPolicy(options, modules), () => authorization.service, (actor) => (options.agentFunctionCaller ?? defaultAgentFunctionCaller)(actor).user)), "useFactory"),
19786
19906
  inject: [
19787
- import_nestjs_agent_core47.AGENT_OPTIONS,
19907
+ import_nestjs_agent_core48.AGENT_OPTIONS,
19788
19908
  import_core6.ModulesContainer,
19789
19909
  NestAuthorizationBinding
19790
19910
  ]
19791
19911
  },
19792
19912
  {
19793
- provide: import_nestjs_agent_core47.AGENT_ACTOR_RESOLVER,
19794
- useFactory: /* @__PURE__ */ __name((options) => {
19795
- if (options.actorResolver !== void 0) return options.actorResolver;
19913
+ provide: import_nestjs_agent_core48.AGENT_ACTOR_RESOLVER,
19914
+ // With tenancy on, an actor the resolver left without a `tenantRef` gets the context tenant's.
19915
+ useFactory: /* @__PURE__ */ __name((options, contextAccessor) => {
19916
+ if (options.actorResolver !== void 0) {
19917
+ return tenantFillingResolver(options.actorResolver, options.tenancy, contextAccessor);
19918
+ }
19796
19919
  logger4.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.");
19797
- return new AnonymousActorResolver();
19920
+ return tenantFillingResolver(new AnonymousActorResolver(), options.tenancy, contextAccessor);
19798
19921
  }, "useFactory"),
19799
19922
  inject: [
19800
- import_nestjs_agent_core47.AGENT_OPTIONS
19923
+ import_nestjs_agent_core48.AGENT_OPTIONS,
19924
+ {
19925
+ token: import_nestjs_agent_core48.CONTEXT_ACCESSOR,
19926
+ optional: true
19927
+ }
19801
19928
  ]
19802
19929
  },
19803
19930
  // No `model` (and no `engine`): the turns run on `@nestjs/ai`'s `AiModule` models.
19804
19931
  NestAiModelsBinding,
19805
19932
  {
19806
- provide: import_nestjs_agent_core47.AGENT_MODEL,
19933
+ provide: import_nestjs_agent_core48.AGENT_MODEL,
19807
19934
  useFactory: /* @__PURE__ */ __name((o, nestAi) => o.model ?? (nestAi.active ? nestAi : void 0), "useFactory"),
19808
19935
  inject: [
19809
- import_nestjs_agent_core47.AGENT_OPTIONS,
19936
+ import_nestjs_agent_core48.AGENT_OPTIONS,
19810
19937
  NestAiModelsBinding
19811
19938
  ]
19812
19939
  },
19813
19940
  {
19814
19941
  // `quota` is either a provider of the host's own or ceilings for the built-in ledger one;
19815
19942
  // omitted, the ledger provider still reports usage, with no ceiling to block on.
19816
- provide: import_nestjs_agent_core47.AGENT_QUOTA_PROVIDER,
19943
+ provide: import_nestjs_agent_core48.AGENT_QUOTA_PROVIDER,
19817
19944
  useFactory: /* @__PURE__ */ __name((o, store) => isQuotaProvider(o.quota) ? o.quota : new LedgerQuotaProvider(store, o.quota?.limits, {
19818
19945
  ...o.quota?.warnAt !== void 0 ? {
19819
19946
  warnAt: o.quota.warnAt
19820
19947
  } : {},
19821
19948
  ...o.quota?.countEstimatedCost !== void 0 ? {
19822
19949
  countEstimatedCost: o.quota.countEstimatedCost
19950
+ } : {},
19951
+ ...o.quota?.per !== void 0 ? {
19952
+ per: o.quota.per
19823
19953
  } : {}
19824
19954
  }), "useFactory"),
19825
19955
  inject: [
19826
- import_nestjs_agent_core47.AGENT_OPTIONS,
19827
- import_nestjs_agent_core47.AGENT_STORE
19956
+ import_nestjs_agent_core48.AGENT_OPTIONS,
19957
+ import_nestjs_agent_core48.AGENT_STORE
19828
19958
  ]
19829
19959
  },
19830
19960
  {
19831
- provide: import_nestjs_agent_core47.AGENT_MODEL_CATALOG,
19961
+ provide: import_nestjs_agent_core48.AGENT_MODEL_CATALOG,
19832
19962
  useFactory: /* @__PURE__ */ __name((o, model) => resolveCatalog(o, model), "useFactory"),
19833
19963
  inject: [
19834
- import_nestjs_agent_core47.AGENT_OPTIONS,
19835
- import_nestjs_agent_core47.AGENT_MODEL
19964
+ import_nestjs_agent_core48.AGENT_OPTIONS,
19965
+ import_nestjs_agent_core48.AGENT_MODEL
19836
19966
  ]
19837
19967
  },
19838
19968
  AgentDepsFactory2,
19839
19969
  {
19840
- provide: import_nestjs_agent_core47.AGENT_DEPS_FACTORY,
19970
+ provide: import_nestjs_agent_core48.AGENT_DEPS_FACTORY,
19841
19971
  useExisting: AgentDepsFactory2
19842
19972
  },
19843
19973
  // Seeds a configured model's missing price row from models.dev and warns about one that would
@@ -19867,26 +19997,26 @@ function sharedProviders(durable, engine) {
19867
19997
  // through AgentService.signalToolCall, which reaches whichever AGENT_RUNNER is bound above.
19868
19998
  AgentApprovalPortAdapter,
19869
19999
  {
19870
- provide: import_nestjs_agent_core47.AGENT_APPROVAL_PORT,
20000
+ provide: import_nestjs_agent_core48.AGENT_APPROVAL_PORT,
19871
20001
  useExisting: AgentApprovalPortAdapter
19872
20002
  }
19873
20003
  ];
19874
20004
  providers.push({
19875
- provide: import_nestjs_agent_core47.AGENT_STORE,
20005
+ provide: import_nestjs_agent_core48.AGENT_STORE,
19876
20006
  useFactory: /* @__PURE__ */ __name((o, modules) => resolveStore(o, modules), "useFactory"),
19877
20007
  inject: [
19878
- import_nestjs_agent_core47.AGENT_OPTIONS,
20008
+ import_nestjs_agent_core48.AGENT_OPTIONS,
19879
20009
  import_core6.ModulesContainer
19880
20010
  ]
19881
20011
  });
19882
20012
  if (engine !== void 0) {
19883
20013
  providers.push(...engine.providers, {
19884
- provide: import_nestjs_agent_core47.AGENT_RUNNER,
20014
+ provide: import_nestjs_agent_core48.AGENT_RUNNER,
19885
20015
  useExisting: engine.runner
19886
20016
  });
19887
20017
  } else if (durableEngine === "aviary") {
19888
20018
  providers.push({
19889
- provide: import_nestjs_agent_core47.AGENT_RUNNER,
20019
+ provide: import_nestjs_agent_core48.AGENT_RUNNER,
19890
20020
  useFactory: /* @__PURE__ */ __name((durableRunner) => {
19891
20021
  if (durableRunner === void 0) {
19892
20022
  throw new Error("AgentModule.forRoot({ durable: { engine: 'aviary' } }) requires importing AgentDurableModule from '@dudousxd/nestjs-agent/durable' (alongside a configured DurableModule). It was not found.");
@@ -19895,14 +20025,14 @@ function sharedProviders(durable, engine) {
19895
20025
  }, "useFactory"),
19896
20026
  inject: [
19897
20027
  {
19898
- token: import_nestjs_agent_core47.AGENT_DURABLE_RUNNER,
20028
+ token: import_nestjs_agent_core48.AGENT_DURABLE_RUNNER,
19899
20029
  optional: true
19900
20030
  }
19901
20031
  ]
19902
20032
  });
19903
20033
  } else if (durableEngine === "workflows") {
19904
20034
  providers.push({
19905
- provide: import_nestjs_agent_core47.AGENT_RUNNER,
20035
+ provide: import_nestjs_agent_core48.AGENT_RUNNER,
19906
20036
  useFactory: /* @__PURE__ */ __name((workflowsRunner) => {
19907
20037
  if (workflowsRunner === void 0) {
19908
20038
  throw new Error("AgentModule.forRoot({ durable: true }) runs turns on @nestjs/workflows: import WorkflowsModule.forRoot() from '@nestjs/workflows' and AgentWorkflowsModule from '@dudousxd/nestjs-agent/workflows'. AgentWorkflowsModule was not found. (For the @dudousxd/nestjs-durable engine, set durable: { engine: 'aviary' }.)");
@@ -19911,14 +20041,14 @@ function sharedProviders(durable, engine) {
19911
20041
  }, "useFactory"),
19912
20042
  inject: [
19913
20043
  {
19914
- token: import_nestjs_agent_core47.AGENT_WORKFLOWS_RUNNER,
20044
+ token: import_nestjs_agent_core48.AGENT_WORKFLOWS_RUNNER,
19915
20045
  optional: true
19916
20046
  }
19917
20047
  ]
19918
20048
  });
19919
20049
  } else {
19920
20050
  providers.push({
19921
- provide: import_nestjs_agent_core47.AGENT_RUNNER,
20051
+ provide: import_nestjs_agent_core48.AGENT_RUNNER,
19922
20052
  useExisting: InlineAgentRunner
19923
20053
  });
19924
20054
  }
@@ -19928,20 +20058,20 @@ __name(sharedProviders, "sharedProviders");
19928
20058
  function exportsFor(engine) {
19929
20059
  return [
19930
20060
  ...engine?.exports ?? [],
19931
- import_nestjs_agent_core47.AGENT_OPTIONS,
19932
- import_nestjs_agent_core47.AGENT_TOOL_REGISTRY,
19933
- import_nestjs_agent_core47.AGENT_REGISTRY,
19934
- import_nestjs_agent_core47.AGENT_SINK,
19935
- import_nestjs_agent_core47.AGENT_ROLES_POLICY,
19936
- import_nestjs_agent_core47.AGENT_ACTOR_RESOLVER,
19937
- import_nestjs_agent_core47.AGENT_MODEL,
19938
- import_nestjs_agent_core47.AGENT_STORE,
19939
- import_nestjs_agent_core47.AGENT_MODEL_CATALOG,
19940
- import_nestjs_agent_core47.AGENT_QUOTA_PROVIDER,
19941
- import_nestjs_agent_core47.AGENT_PROMPT_CONTRIBUTORS,
19942
- import_nestjs_agent_core47.AGENT_SKILLS,
19943
- import_nestjs_agent_core47.AGENT_MEMORY,
19944
- import_nestjs_agent_core47.AGENT_DEPS_FACTORY,
20061
+ import_nestjs_agent_core48.AGENT_OPTIONS,
20062
+ import_nestjs_agent_core48.AGENT_TOOL_REGISTRY,
20063
+ import_nestjs_agent_core48.AGENT_REGISTRY,
20064
+ import_nestjs_agent_core48.AGENT_SINK,
20065
+ import_nestjs_agent_core48.AGENT_ROLES_POLICY,
20066
+ import_nestjs_agent_core48.AGENT_ACTOR_RESOLVER,
20067
+ import_nestjs_agent_core48.AGENT_MODEL,
20068
+ import_nestjs_agent_core48.AGENT_STORE,
20069
+ import_nestjs_agent_core48.AGENT_MODEL_CATALOG,
20070
+ import_nestjs_agent_core48.AGENT_QUOTA_PROVIDER,
20071
+ import_nestjs_agent_core48.AGENT_PROMPT_CONTRIBUTORS,
20072
+ import_nestjs_agent_core48.AGENT_SKILLS,
20073
+ import_nestjs_agent_core48.AGENT_MEMORY,
20074
+ import_nestjs_agent_core48.AGENT_DEPS_FACTORY,
19945
20075
  AgentDepsFactory2,
19946
20076
  AgentService,
19947
20077
  AGENT_SERVICE,
@@ -19950,7 +20080,7 @@ function exportsFor(engine) {
19950
20080
  ChatQueueService2,
19951
20081
  AGENT_CHAT_QUEUE,
19952
20082
  InlineAgentRunner,
19953
- import_nestjs_agent_core47.AGENT_APPROVAL_PORT
20083
+ import_nestjs_agent_core48.AGENT_APPROVAL_PORT
19954
20084
  ];
19955
20085
  }
19956
20086
  __name(exportsFor, "exportsFor");
@@ -19981,7 +20111,7 @@ __name(adapterProviders, "adapterProviders");
19981
20111
  function controllersForSurface(surface, adapters, engine, decorators, routes) {
19982
20112
  if (surface === "engine" || routes === false) return [];
19983
20113
  return [
19984
- ...(0, import_nestjs_agent_core47.withControllerDecorators)([
20114
+ ...(0, import_nestjs_agent_core48.withControllerDecorators)([
19985
20115
  ...BASE_CONTROLLERS,
19986
20116
  ...adapterControllers(adapters)
19987
20117
  ], decorators),
@@ -20021,7 +20151,7 @@ var AgentModule = class _AgentModule {
20021
20151
  controllers: controllersForSurface(options.surface, options.adapters, options.engine, options.decorators, options.routes),
20022
20152
  providers: [
20023
20153
  {
20024
- provide: import_nestjs_agent_core47.AGENT_OPTIONS,
20154
+ provide: import_nestjs_agent_core48.AGENT_OPTIONS,
20025
20155
  useValue: options
20026
20156
  },
20027
20157
  ...sharedProviders(options.durable, options.engine),
@@ -20049,7 +20179,7 @@ var AgentModule = class _AgentModule {
20049
20179
  controllers: controllersForSurface(options.surface, options.adapters, options.engine, options.decorators, options.routes),
20050
20180
  providers: [
20051
20181
  {
20052
- provide: import_nestjs_agent_core47.AGENT_OPTIONS,
20182
+ provide: import_nestjs_agent_core48.AGENT_OPTIONS,
20053
20183
  // Stamp the STATIC wiring flags onto the factory result: `durable`/`surface` are
20054
20184
  // authoritative on the async config object (they decided the actual wiring above), and
20055
20185
  // the durable module reads `durable` back off AGENT_OPTIONS. `surface` isn't read back by