@dudousxd/nestjs-agent 2.0.1 → 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.
package/dist/index.cjs CHANGED
@@ -11162,7 +11162,7 @@ __export(index_exports, {
11162
11162
  module.exports = __toCommonJS(index_exports);
11163
11163
 
11164
11164
  // src/agent.module.ts
11165
- var import_nestjs_agent_core40 = require("@dudousxd/nestjs-agent-core");
11165
+ var import_nestjs_agent_core41 = require("@dudousxd/nestjs-agent-core");
11166
11166
  var import_common32 = require("@nestjs/common");
11167
11167
  var import_core6 = require("@nestjs/core");
11168
11168
 
@@ -11993,9 +11993,11 @@ var ActionProposalService = class {
11993
11993
  }
11994
11994
  store;
11995
11995
  options;
11996
- constructor(store, options) {
11996
+ contextAccessor;
11997
+ constructor(store, options, contextAccessor) {
11997
11998
  this.store = store;
11998
11999
  this.options = options;
12000
+ this.contextAccessor = contextAccessor;
11999
12001
  const text = options.actionProposalText;
12000
12002
  this.vocabulary = {
12001
12003
  ...import_nestjs_agent_core5.DEFAULT_TEXT_ACTION_PROPOSAL_VOCABULARY,
@@ -12021,6 +12023,8 @@ var ActionProposalService = class {
12021
12023
  async scope(threadId, actor) {
12022
12024
  const scope = await this.capability().getThreadActionProposalScope(threadId);
12023
12025
  if (!scope) throw new import_common3.NotFoundException("Thread not found");
12026
+ const filter = (0, import_nestjs_agent_core5.tenantRowFilter)((0, import_nestjs_agent_core5.readTenancy)(this.options.tenancy ?? "inherit", this.contextAccessor), actor.tenantRef);
12027
+ if (filter !== void 0 && !(0, import_nestjs_agent_core5.tenantRowVisible)(filter, scope.tenantRef)) throw new import_common3.NotFoundException("Thread not found");
12024
12028
  if (scope.tenantRef !== (actor.tenantRef ?? null)) throw new import_common3.ForbiddenException("Wrong proposal tenant");
12025
12029
  return scope;
12026
12030
  }
@@ -12140,10 +12144,13 @@ ActionProposalService = _ts_decorate3([
12140
12144
  (0, import_common3.Injectable)(),
12141
12145
  _ts_param2(0, (0, import_common3.Inject)(import_nestjs_agent_core5.AGENT_STORE)),
12142
12146
  _ts_param2(1, (0, import_common3.Inject)(import_nestjs_agent_core5.AGENT_OPTIONS)),
12147
+ _ts_param2(2, (0, import_common3.Optional)()),
12148
+ _ts_param2(2, (0, import_common3.Inject)(import_nestjs_agent_core5.CONTEXT_ACCESSOR)),
12143
12149
  _ts_metadata2("design:type", Function),
12144
12150
  _ts_metadata2("design:paramtypes", [
12145
12151
  typeof AgentStore === "undefined" ? Object : AgentStore,
12146
- typeof Pick === "undefined" ? Object : Pick
12152
+ typeof Pick === "undefined" ? Object : Pick,
12153
+ Object
12147
12154
  ])
12148
12155
  ], ActionProposalService);
12149
12156
 
@@ -12778,7 +12785,8 @@ var AgentService2 = class {
12778
12785
  options;
12779
12786
  queue;
12780
12787
  proposals;
12781
- constructor(runner, store, deps, staging, models, quotaProvider, options, queue, proposals) {
12788
+ contextAccessor;
12789
+ constructor(runner, store, deps, staging, models, quotaProvider, options, queue, proposals, contextAccessor) {
12782
12790
  this.runner = runner;
12783
12791
  this.store = store;
12784
12792
  this.deps = deps;
@@ -12788,6 +12796,58 @@ var AgentService2 = class {
12788
12796
  this.options = options;
12789
12797
  this.queue = queue;
12790
12798
  this.proposals = proposals;
12799
+ this.contextAccessor = contextAccessor;
12800
+ }
12801
+ /**
12802
+ * With tenancy on, the store must be able to tell a thread's tenant: fail the boot with the fix
12803
+ * rather than answer every thread read `404` at runtime. Tenancy enabled explicitly with no
12804
+ * context accessor to read the tenant from fails the boot too.
12805
+ */
12806
+ onApplicationBootstrap() {
12807
+ if (!this.tenancy().enabled) {
12808
+ const option = this.options?.tenancy;
12809
+ if (typeof option === "object" && option.enabled === true) {
12810
+ 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`.");
12811
+ }
12812
+ return;
12813
+ }
12814
+ const missing = [
12815
+ "tenantOf",
12816
+ "listThreadsForTenant"
12817
+ ].filter((method) => typeof this.store[method] !== "function");
12818
+ if (missing.length > 0) {
12819
+ 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\`.`);
12820
+ }
12821
+ }
12822
+ /**
12823
+ * The matching rule for a decision that comes from outside the thread's own actor (the console's
12824
+ * approvals inbox): with tenancy on, a tool call on a thread the request's context tenant may not
12825
+ * see is not found. A no-op with tenancy off.
12826
+ */
12827
+ async assertToolCallInRequestTenant(toolCallId2) {
12828
+ const filter = (0, import_nestjs_agent_core9.tenantRowFilter)(this.tenancy());
12829
+ if (filter === void 0) return;
12830
+ const row = typeof this.store.tenantOf === "function" ? await this.store.tenantOf({
12831
+ toolCallId: toolCallId2
12832
+ }) : null;
12833
+ if (row === null || !(0, import_nestjs_agent_core9.tenantRowVisible)(filter, row.tenantRef)) {
12834
+ throw new import_common6.NotFoundException(`tool call ${toolCallId2} not found`);
12835
+ }
12836
+ }
12837
+ /** The agent's tenancy, read per call: the context's switch can be flipped at any time. */
12838
+ tenancy() {
12839
+ return (0, import_nestjs_agent_core9.readTenancy)(this.options?.tenancy ?? "inherit", this.contextAccessor);
12840
+ }
12841
+ /**
12842
+ * The matching rule for one thread, run or tool call: with tenancy on, a row of another tenant
12843
+ * (or, for a request with a tenant, one with no tenant unless `nullRows: 'shared'`) is not found.
12844
+ * The request's tenant is `actor.tenantRef` (the resolver's, else the context's), else none.
12845
+ */
12846
+ async assertTenantVisible(actor, target, notFound) {
12847
+ const filter = (0, import_nestjs_agent_core9.tenantRowFilter)(this.tenancy(), actor.tenantRef);
12848
+ if (filter === void 0) return;
12849
+ const row = typeof this.store.tenantOf === "function" ? await this.store.tenantOf(target) : null;
12850
+ if (row === null || !(0, import_nestjs_agent_core9.tenantRowVisible)(filter, row.tenantRef)) throw notFound();
12791
12851
  }
12792
12852
  /**
12793
12853
  * Decide one independent proposal through the scoped proposal service — what the native
@@ -13525,6 +13585,9 @@ var AgentService2 = class {
13525
13585
  if (owner === null) {
13526
13586
  throw new RunNotActiveException(runId);
13527
13587
  }
13588
+ await this.assertTenantVisible(actor, {
13589
+ runId
13590
+ }, () => new RunNotActiveException(runId));
13528
13591
  if (owner !== actor.id) {
13529
13592
  throw new import_common6.ForbiddenException("run belongs to another actor");
13530
13593
  }
@@ -13547,8 +13610,15 @@ var AgentService2 = class {
13547
13610
  await this.assertOwnsActiveStream(actor, runId);
13548
13611
  return this.runner.cancel(runId);
13549
13612
  }
13550
- async listThreads(actorRef) {
13551
- const threads = await this.store.listThreads(actorRef);
13613
+ /**
13614
+ * The actor's threads. With tenancy on, only those the request's tenant may see: pass the
13615
+ * {@link Actor} so a `tenantRef` its resolver set is the tenant; a bare `actorRef` uses the
13616
+ * context's.
13617
+ */
13618
+ async listThreads(actor) {
13619
+ const actorRef = typeof actor === "string" ? actor : actor.id;
13620
+ const filter = (0, import_nestjs_agent_core9.tenantRowFilter)(this.tenancy(), typeof actor === "string" ? void 0 : actor.tenantRef);
13621
+ const threads = filter === void 0 ? await this.store.listThreads(actorRef) : typeof this.store.listThreadsForTenant === "function" ? await this.store.listThreadsForTenant(actorRef, filter) : [];
13552
13622
  return Promise.all(threads.map((thread) => this.toSummaryView(thread)));
13553
13623
  }
13554
13624
  async getThread(actor, threadId) {
@@ -13570,6 +13640,9 @@ var AgentService2 = class {
13570
13640
  if (await this.store.ownerOfThread(threadId) === null) {
13571
13641
  throw new import_common6.NotFoundException(`thread ${threadId} not found`);
13572
13642
  }
13643
+ await this.assertTenantVisible(actor, {
13644
+ threadId
13645
+ }, () => new import_common6.NotFoundException(`thread ${threadId} not found`));
13573
13646
  } else {
13574
13647
  await this.assertOwnsThread(actor, threadId);
13575
13648
  }
@@ -13872,6 +13945,9 @@ var AgentService2 = class {
13872
13945
  if (owner === null) {
13873
13946
  throw new import_common6.NotFoundException(`thread ${threadId} not found`);
13874
13947
  }
13948
+ await this.assertTenantVisible(actor, {
13949
+ threadId
13950
+ }, () => new import_common6.NotFoundException(`thread ${threadId} not found`));
13875
13951
  if (owner !== actor.id) {
13876
13952
  throw new import_common6.ForbiddenException("thread belongs to another actor");
13877
13953
  }
@@ -13886,6 +13962,9 @@ var AgentService2 = class {
13886
13962
  if (owner === null) {
13887
13963
  throw new import_common6.NotFoundException(`tool call ${toolCallId2} not found`);
13888
13964
  }
13965
+ await this.assertTenantVisible(actor, {
13966
+ toolCallId: toolCallId2
13967
+ }, () => new import_common6.NotFoundException(`tool call ${toolCallId2} not found`));
13889
13968
  if (owner !== actor.id) {
13890
13969
  throw new import_common6.ForbiddenException("tool call belongs to another actor");
13891
13970
  }
@@ -13927,6 +14006,9 @@ var AgentService2 = class {
13927
14006
  if (requesterRef === null) {
13928
14007
  throw new import_common6.NotFoundException(`tool call ${toolCallId2} not found`);
13929
14008
  }
14009
+ await this.assertTenantVisible(actor, {
14010
+ toolCallId: toolCallId2
14011
+ }, () => new import_common6.NotFoundException(`tool call ${toolCallId2} not found`));
13930
14012
  const allowed = await (0, import_nestjs_agent_core9.mayDecideApproval)(this.deps.forAgent().approvalPolicy, actor, {
13931
14013
  toolCallId: toolCallId2,
13932
14014
  approver,
@@ -13972,6 +14054,9 @@ var AgentService2 = class {
13972
14054
  if (owner === null) {
13973
14055
  throw new import_common6.NotFoundException(`no active run ${runId}`);
13974
14056
  }
14057
+ await this.assertTenantVisible(actor, {
14058
+ runId
14059
+ }, () => new import_common6.NotFoundException(`no active run ${runId}`));
13975
14060
  if (owner !== actor.id) {
13976
14061
  throw new import_common6.ForbiddenException("run belongs to another actor");
13977
14062
  }
@@ -13992,11 +14077,15 @@ var AgentService2 = class {
13992
14077
  * against nobody.
13993
14078
  */
13994
14079
  recordUsage(input, options = {}) {
14080
+ const tenantRef = input.tenantRef ?? (0, import_nestjs_agent_core9.contextTenantRef)(this.tenancy());
13995
14081
  return (0, import_nestjs_agent_core9.recordAiUsage)({
13996
14082
  store: this.store,
13997
14083
  quota: this.deps.forAgent().quota,
13998
14084
  day: utcDay(),
13999
- input,
14085
+ input: tenantRef !== void 0 && input.tenantRef === void 0 ? {
14086
+ ...input,
14087
+ tenantRef
14088
+ } : input,
14000
14089
  options,
14001
14090
  warn: /* @__PURE__ */ __name((message) => usageLogger.warn(message), "warn")
14002
14091
  });
@@ -14017,6 +14106,8 @@ AgentService2 = _ts_decorate5([
14017
14106
  _ts_param4(6, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_OPTIONS)),
14018
14107
  _ts_param4(7, (0, import_common6.Optional)()),
14019
14108
  _ts_param4(8, (0, import_common6.Optional)()),
14109
+ _ts_param4(9, (0, import_common6.Optional)()),
14110
+ _ts_param4(9, (0, import_common6.Inject)(import_nestjs_agent_core9.CONTEXT_ACCESSOR)),
14020
14111
  _ts_metadata4("design:type", Function),
14021
14112
  _ts_metadata4("design:paramtypes", [
14022
14113
  typeof AgentRunner === "undefined" ? Object : AgentRunner,
@@ -14027,7 +14118,8 @@ AgentService2 = _ts_decorate5([
14027
14118
  typeof QuotaProvider === "undefined" ? Object : QuotaProvider,
14028
14119
  typeof Pick === "undefined" ? Object : Pick,
14029
14120
  typeof ChatQueueService === "undefined" ? Object : ChatQueueService,
14030
- typeof ActionProposalService === "undefined" ? Object : ActionProposalService
14121
+ typeof ActionProposalService === "undefined" ? Object : ActionProposalService,
14122
+ Object
14031
14123
  ])
14032
14124
  ], AgentService2);
14033
14125
 
@@ -14090,6 +14182,7 @@ var AgentApprovalPortAdapter = class {
14090
14182
  });
14091
14183
  }
14092
14184
  async approve(toolCallId2, opts) {
14185
+ await this.agent.assertToolCallInRequestTenant(toolCallId2);
14093
14186
  await this.agent.signalToolCall(toolCallId2, {
14094
14187
  approved: true,
14095
14188
  ...opts?.executedByRef !== void 0 ? {
@@ -14104,6 +14197,7 @@ var AgentApprovalPortAdapter = class {
14104
14197
  });
14105
14198
  }
14106
14199
  async reject(toolCallId2, opts) {
14200
+ await this.agent.assertToolCallInRequestTenant(toolCallId2);
14107
14201
  await this.agent.signalToolCall(toolCallId2, {
14108
14202
  approved: false,
14109
14203
  ...opts?.executedByRef !== void 0 ? {
@@ -15456,7 +15550,7 @@ var ThreadsController = class {
15456
15550
  }
15457
15551
  async list(req) {
15458
15552
  const actor = await this.actorResolver.resolve(req);
15459
- return this.agent.listThreads(actor.id);
15553
+ return this.agent.listThreads(actor);
15460
15554
  }
15461
15555
  async detail(req, id) {
15462
15556
  const actor = await this.actorResolver.resolve(req);
@@ -17023,6 +17117,10 @@ var LedgerQuotaProvider = class {
17023
17117
  this.store = store;
17024
17118
  this.limits = limits;
17025
17119
  this.options = options;
17120
+ const per = options.per ?? "actor";
17121
+ if (per !== "actor" && typeof store.usageWindowsForTenant !== "function") {
17122
+ 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.`);
17123
+ }
17026
17124
  }
17027
17125
  async report(query) {
17028
17126
  const now = query.now ?? /* @__PURE__ */ new Date();
@@ -17030,7 +17128,16 @@ var LedgerQuotaProvider = class {
17030
17128
  const day = (0, import_nestjs_agent_core31.quotaPeriodRange)("day", now);
17031
17129
  const month = (0, import_nestjs_agent_core31.quotaPeriodRange)("month", now);
17032
17130
  const windows = [];
17033
- if (this.store.usageWindows !== void 0) {
17131
+ const per = this.options.per ?? "actor";
17132
+ const tenantRef = query.actor.tenantRef;
17133
+ if (per !== "actor" && typeof tenantRef === "string" && tenantRef !== "" && this.store.usageWindowsForTenant !== void 0) {
17134
+ const [dayUsed, monthUsed] = await this.store.usageWindowsForTenant(tenantRef, [
17135
+ day,
17136
+ month
17137
+ ], per === "actor-in-tenant" ? actorRef : void 0);
17138
+ windows.push(this.usedWindow("day", dayUsed, day.resetsAt));
17139
+ windows.push(this.usedWindow("month", monthUsed, month.resetsAt));
17140
+ } else if (this.store.usageWindows !== void 0) {
17034
17141
  const [dayUsed, monthUsed] = await this.store.usageWindows(actorRef, [
17035
17142
  day,
17036
17143
  month
@@ -18070,8 +18177,21 @@ ActionProposalController = _ts_decorate27([
18070
18177
  // src/queue/chat-queue.token.ts
18071
18178
  var AGENT_CHAT_QUEUE = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:chat-queue");
18072
18179
 
18073
- // src/runner/inline-agent-runner.ts
18180
+ // src/resolver/tenant-filling-resolver.ts
18074
18181
  var import_nestjs_agent_core38 = require("@dudousxd/nestjs-agent-core");
18182
+ function tenantFillingResolver(resolver, tenancy, contextAccessor) {
18183
+ if (tenancy === false) return resolver;
18184
+ const wrapper = Object.create(resolver);
18185
+ Object.defineProperty(wrapper, "resolve", {
18186
+ value: /* @__PURE__ */ __name(async (req) => (0, import_nestjs_agent_core38.withContextTenant)(await resolver.resolve(req), (0, import_nestjs_agent_core38.readTenancy)(tenancy ?? "inherit", contextAccessor ?? void 0)), "value"),
18187
+ enumerable: false
18188
+ });
18189
+ return wrapper;
18190
+ }
18191
+ __name(tenantFillingResolver, "tenantFillingResolver");
18192
+
18193
+ // src/runner/inline-agent-runner.ts
18194
+ var import_nestjs_agent_core39 = require("@dudousxd/nestjs-agent-core");
18075
18195
  var import_common31 = require("@nestjs/common");
18076
18196
  function _ts_decorate28(decorators, target, key, desc) {
18077
18197
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -18162,30 +18282,30 @@ var InlineAgentRunner = class _InlineAgentRunner {
18162
18282
  ],
18163
18283
  input
18164
18284
  });
18165
- void (0, import_nestjs_agent_core38.runAgentLoop)({
18285
+ void (0, import_nestjs_agent_core39.runAgentLoop)({
18166
18286
  ...deps,
18167
18287
  day
18168
- }, input, hooks).then(() => (0, import_nestjs_agent_core38.releaseThreadRun)(this.store, input.threadId, runId)).catch(async (error) => {
18169
- const durationMs = (0, import_nestjs_agent_core38.runDurationMs)(error);
18288
+ }, input, hooks).then(() => (0, import_nestjs_agent_core39.releaseThreadRun)(this.store, input.threadId, runId)).catch(async (error) => {
18289
+ const durationMs = (0, import_nestjs_agent_core39.runDurationMs)(error);
18170
18290
  const timed = durationMs !== void 0 ? {
18171
18291
  durationMs
18172
18292
  } : {};
18173
- const measured = (0, import_nestjs_agent_core38.runEndTimings)(error);
18174
- if (error instanceof import_nestjs_agent_core38.RunCancelledError) {
18293
+ const measured = (0, import_nestjs_agent_core39.runEndTimings)(error);
18294
+ if (error instanceof import_nestjs_agent_core39.RunCancelledError) {
18175
18295
  await this.settleCancelled(runId, input, deps, durationMs, measured);
18176
18296
  return;
18177
18297
  }
18178
18298
  const message = error instanceof Error ? error.message : String(error);
18179
- const code = (0, import_nestjs_agent_core38.agentFailureCode)(error);
18299
+ const code = (0, import_nestjs_agent_core39.agentFailureCode)(error);
18180
18300
  this.logger.error(`agent run ${runId} failed (${code}): ${message}`);
18181
- (0, import_nestjs_agent_core38.publishAgentRunFailed)({
18301
+ (0, import_nestjs_agent_core39.publishAgentRunFailed)({
18182
18302
  runId,
18183
18303
  threadId: input.threadId,
18184
18304
  code,
18185
18305
  message,
18186
18306
  ...timed,
18187
18307
  ...measured,
18188
- context: (0, import_nestjs_agent_core38.agentRunContext)(input)
18308
+ context: (0, import_nestjs_agent_core39.agentRunContext)(input)
18189
18309
  });
18190
18310
  await this.store.recordRunEnd?.({
18191
18311
  runId,
@@ -18194,11 +18314,11 @@ var InlineAgentRunner = class _InlineAgentRunner {
18194
18314
  errorCode: code,
18195
18315
  errorMessage: message
18196
18316
  });
18197
- await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core38.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
18317
+ await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core39.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
18198
18318
  const writer = await deps.sink.open(runId);
18199
18319
  await this.settleQueue(writer, input, runId, "failed", message);
18200
- await (0, import_nestjs_agent_core38.releaseThreadRun)(this.store, input.threadId, runId);
18201
- await writer.fail((0, import_nestjs_agent_core38.streamFailure)(error));
18320
+ await (0, import_nestjs_agent_core39.releaseThreadRun)(this.store, input.threadId, runId);
18321
+ await writer.fail((0, import_nestjs_agent_core39.streamFailure)(error));
18202
18322
  }).finally(() => {
18203
18323
  this.forgetCancel(runId);
18204
18324
  this.live.delete(runId);
@@ -18233,11 +18353,11 @@ var InlineAgentRunner = class _InlineAgentRunner {
18233
18353
  */
18234
18354
  async cancel(runId) {
18235
18355
  this.cancelled.add(runId);
18236
- this.aborts.get(runId)?.abort(new import_nestjs_agent_core38.RunCancelledError());
18356
+ this.aborts.get(runId)?.abort(new import_nestjs_agent_core39.RunCancelledError());
18237
18357
  for (const [key, waiter] of this.pending) {
18238
18358
  if (key.startsWith(`${runId}:`)) {
18239
18359
  this.pending.delete(key);
18240
- waiter.reject(new import_nestjs_agent_core38.RunCancelledError());
18360
+ waiter.reject(new import_nestjs_agent_core39.RunCancelledError());
18241
18361
  }
18242
18362
  }
18243
18363
  await Promise.resolve();
@@ -18267,17 +18387,17 @@ var InlineAgentRunner = class _InlineAgentRunner {
18267
18387
  const timed = durationMs !== void 0 ? {
18268
18388
  durationMs
18269
18389
  } : {};
18270
- (0, import_nestjs_agent_core38.publishAgentRunCancelled)({
18390
+ (0, import_nestjs_agent_core39.publishAgentRunCancelled)({
18271
18391
  runId,
18272
18392
  threadId: input.threadId,
18273
18393
  ...timed,
18274
18394
  ...measured,
18275
- context: (0, import_nestjs_agent_core38.agentRunContext)(input)
18395
+ context: (0, import_nestjs_agent_core39.agentRunContext)(input)
18276
18396
  });
18277
18397
  const writer = await deps.sink.open(runId);
18278
18398
  await this.settleQueue(writer, input, runId, "cancelled");
18279
- await (0, import_nestjs_agent_core38.releaseThreadRun)(this.store, input.threadId, runId);
18280
- await writer.write((0, import_nestjs_agent_core38.encodeStreamEvent)({
18399
+ await (0, import_nestjs_agent_core39.releaseThreadRun)(this.store, input.threadId, runId);
18400
+ await writer.write((0, import_nestjs_agent_core39.encodeStreamEvent)({
18281
18401
  kind: "cancelled"
18282
18402
  }));
18283
18403
  await writer.end();
@@ -18313,7 +18433,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
18313
18433
  runId: nextRunId
18314
18434
  }));
18315
18435
  if (frame !== void 0) {
18316
- await writer.write((0, import_nestjs_agent_core38.encodeStreamEvent)(frame));
18436
+ await writer.write((0, import_nestjs_agent_core39.encodeStreamEvent)(frame));
18317
18437
  }
18318
18438
  } catch (failure) {
18319
18439
  this.logger.error(`could not advance the queue of thread ${input.threadId} after run ${runId}: ${failure instanceof Error ? failure.message : String(failure)}`);
@@ -18385,7 +18505,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
18385
18505
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
18386
18506
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
18387
18507
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
18388
- parallel: import_nestjs_agent_core38.settleAll,
18508
+ parallel: import_nestjs_agent_core39.settleAll,
18389
18509
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
18390
18510
  abortSignal: this.abortSignalFor(runId),
18391
18511
  runAgent: /* @__PURE__ */ __name((agentName, task) => this.runNested({
@@ -18437,7 +18557,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
18437
18557
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
18438
18558
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
18439
18559
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
18440
- parallel: import_nestjs_agent_core38.settleAll,
18560
+ parallel: import_nestjs_agent_core39.settleAll,
18441
18561
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
18442
18562
  abortSignal: this.abortSignalFor(runId),
18443
18563
  runAgent: /* @__PURE__ */ __name((childName, childTask) => this.runNested({
@@ -18482,31 +18602,31 @@ var InlineAgentRunner = class _InlineAgentRunner {
18482
18602
  parentRunId,
18483
18603
  deliverTo
18484
18604
  };
18485
- void (0, import_nestjs_agent_core38.runAgentLoop)({
18605
+ void (0, import_nestjs_agent_core39.runAgentLoop)({
18486
18606
  ...deps,
18487
18607
  day
18488
18608
  }, childInput, hooks).catch(async (error) => {
18489
- const cancelled = error instanceof import_nestjs_agent_core38.RunCancelledError;
18609
+ const cancelled = error instanceof import_nestjs_agent_core39.RunCancelledError;
18490
18610
  const message = error instanceof Error ? error.message : String(error);
18491
- const durationMs = (0, import_nestjs_agent_core38.runDurationMs)(error);
18611
+ const durationMs = (0, import_nestjs_agent_core39.runDurationMs)(error);
18492
18612
  const timed = durationMs !== void 0 ? {
18493
18613
  durationMs
18494
18614
  } : {};
18495
- const measured = (0, import_nestjs_agent_core38.runEndTimings)(error);
18615
+ const measured = (0, import_nestjs_agent_core39.runEndTimings)(error);
18496
18616
  const settled = {
18497
18617
  runId,
18498
18618
  threadId: subThread.id,
18499
18619
  ...timed,
18500
18620
  ...measured,
18501
- context: (0, import_nestjs_agent_core38.agentRunContext)(childInput)
18621
+ context: (0, import_nestjs_agent_core39.agentRunContext)(childInput)
18502
18622
  };
18503
18623
  if (cancelled) {
18504
- (0, import_nestjs_agent_core38.publishAgentRunCancelled)(settled);
18624
+ (0, import_nestjs_agent_core39.publishAgentRunCancelled)(settled);
18505
18625
  } else {
18506
18626
  this.logger.error(`detached agent run ${runId} failed: ${message}`);
18507
- (0, import_nestjs_agent_core38.publishAgentRunFailed)({
18627
+ (0, import_nestjs_agent_core39.publishAgentRunFailed)({
18508
18628
  ...settled,
18509
- code: (0, import_nestjs_agent_core38.agentFailureCode)(error),
18629
+ code: (0, import_nestjs_agent_core39.agentFailureCode)(error),
18510
18630
  message
18511
18631
  });
18512
18632
  }
@@ -18515,12 +18635,12 @@ var InlineAgentRunner = class _InlineAgentRunner {
18515
18635
  status: cancelled ? "cancelled" : "failed",
18516
18636
  ...timed,
18517
18637
  ...cancelled ? {} : {
18518
- errorCode: (0, import_nestjs_agent_core38.agentFailureCode)(error),
18638
+ errorCode: (0, import_nestjs_agent_core39.agentFailureCode)(error),
18519
18639
  errorMessage: message
18520
18640
  }
18521
18641
  });
18522
- await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core38.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
18523
- await (0, import_nestjs_agent_core38.settleUnsettledDelegation)({
18642
+ await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core39.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
18643
+ await (0, import_nestjs_agent_core39.settleUnsettledDelegation)({
18524
18644
  store: this.store,
18525
18645
  delivery: deliverTo,
18526
18646
  agent: agentName,
@@ -18559,7 +18679,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
18559
18679
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
18560
18680
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
18561
18681
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
18562
- parallel: import_nestjs_agent_core38.settleAll,
18682
+ parallel: import_nestjs_agent_core39.settleAll,
18563
18683
  // A child stops when it is cancelled OR when the run a human is actually watching is: the
18564
18684
  // canceller names the top-level run, which is the only id that ever left the server.
18565
18685
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId) || this.cancelled.has(sinkRunId), "cancelled"),
@@ -18596,7 +18716,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
18596
18716
  }), "startAgent")
18597
18717
  };
18598
18718
  try {
18599
- return await (0, import_nestjs_agent_core38.runAgentLoop)({
18719
+ return await (0, import_nestjs_agent_core39.runAgentLoop)({
18600
18720
  ...deps,
18601
18721
  day
18602
18722
  }, {
@@ -18617,8 +18737,8 @@ var InlineAgentRunner = class _InlineAgentRunner {
18617
18737
  };
18618
18738
  InlineAgentRunner = _ts_decorate28([
18619
18739
  (0, import_common31.Injectable)(),
18620
- _ts_param26(0, (0, import_common31.Inject)(import_nestjs_agent_core38.AGENT_DEPS_FACTORY)),
18621
- _ts_param26(1, (0, import_common31.Inject)(import_nestjs_agent_core38.AGENT_STORE)),
18740
+ _ts_param26(0, (0, import_common31.Inject)(import_nestjs_agent_core39.AGENT_DEPS_FACTORY)),
18741
+ _ts_param26(1, (0, import_common31.Inject)(import_nestjs_agent_core39.AGENT_STORE)),
18622
18742
  _ts_param26(2, (0, import_common31.Optional)()),
18623
18743
  _ts_metadata27("design:type", Function),
18624
18744
  _ts_metadata27("design:paramtypes", [
@@ -18633,7 +18753,7 @@ function isThreadTurn(input) {
18633
18753
  __name(isThreadTurn, "isThreadTurn");
18634
18754
 
18635
18755
  // src/skills-config.ts
18636
- var import_nestjs_agent_core39 = require("@dudousxd/nestjs-agent-core");
18756
+ var import_nestjs_agent_core40 = require("@dudousxd/nestjs-agent-core");
18637
18757
  function declaredSkillProvider(declared) {
18638
18758
  return {
18639
18759
  list: /* @__PURE__ */ __name(({ scopes }) => declared.filter((skill) => scopes.includes(skill.scope)).map(({ name, description, scope }) => ({
@@ -18659,7 +18779,7 @@ function resolveSkillsConfig(options, declared) {
18659
18779
  declaredSkillProvider(declared)
18660
18780
  ];
18661
18781
  return {
18662
- provider: providers.length === 1 ? providers[0] : (0, import_nestjs_agent_core39.compositeSkillProvider)(providers),
18782
+ provider: providers.length === 1 ? providers[0] : (0, import_nestjs_agent_core40.compositeSkillProvider)(providers),
18663
18783
  ...options.scopes !== void 0 ? {
18664
18784
  scopes: options.scopes
18665
18785
  } : {},
@@ -18718,14 +18838,14 @@ function forwardingStore(wrapper) {
18718
18838
  __name(forwardingStore, "forwardingStore");
18719
18839
  function resolveStore(options, modules) {
18720
18840
  if (options.store !== void 0) return options.store;
18721
- const external = externalWrapper(modules, import_nestjs_agent_core40.AGENT_STORE);
18841
+ const external = externalWrapper(modules, import_nestjs_agent_core41.AGENT_STORE);
18722
18842
  if (external !== void 0) return forwardingStore(external);
18723
18843
  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()).");
18724
- return new import_nestjs_agent_core40.InMemoryAgentStore();
18844
+ return new import_nestjs_agent_core41.InMemoryAgentStore();
18725
18845
  }
18726
18846
  __name(resolveStore, "resolveStore");
18727
18847
  function resolveRolesPolicy(options, modules) {
18728
- const external = externalWrapper(modules, import_nestjs_agent_core40.AGENT_ROLES_POLICY);
18848
+ const external = externalWrapper(modules, import_nestjs_agent_core41.AGENT_ROLES_POLICY);
18729
18849
  if (options.rolesPolicy !== void 0) {
18730
18850
  if (external !== void 0) {
18731
18851
  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.)");
@@ -18733,7 +18853,7 @@ function resolveRolesPolicy(options, modules) {
18733
18853
  return options.rolesPolicy;
18734
18854
  }
18735
18855
  if (external !== void 0) return forwardingPolicy(external);
18736
- return options.emptyRoles === "deny" ? new import_nestjs_agent_core40.ClosedRolesPolicy(options.defaultRoles) : new import_nestjs_agent_core40.DefaultRolesPolicy(options.defaultRoles);
18856
+ return options.emptyRoles === "deny" ? new import_nestjs_agent_core41.ClosedRolesPolicy(options.defaultRoles) : new import_nestjs_agent_core41.DefaultRolesPolicy(options.defaultRoles);
18737
18857
  }
18738
18858
  __name(resolveRolesPolicy, "resolveRolesPolicy");
18739
18859
  function forwardingPolicy(wrapper) {
@@ -18769,128 +18889,138 @@ function sharedProviders(durable, engine) {
18769
18889
  const durableEngine = durableEngineOf(durable);
18770
18890
  const providers = [
18771
18891
  {
18772
- provide: import_nestjs_agent_core40.AGENT_TOOL_REGISTRY,
18773
- useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core40.ToolRegistry(), "useFactory")
18892
+ provide: import_nestjs_agent_core41.AGENT_TOOL_REGISTRY,
18893
+ useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core41.ToolRegistry(), "useFactory")
18774
18894
  },
18775
18895
  // Starts empty; AgentDiscoveryService populates it from `@Agent`-decorated providers at boot.
18776
18896
  {
18777
- provide: import_nestjs_agent_core40.AGENT_REGISTRY,
18778
- useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core40.AgentRegistry(), "useFactory")
18897
+ provide: import_nestjs_agent_core41.AGENT_REGISTRY,
18898
+ useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core41.AgentRegistry(), "useFactory")
18779
18899
  },
18780
18900
  // A shared, mutable list AgentDiscoveryService fills with `@SystemPromptContributor()` methods.
18781
18901
  {
18782
- provide: import_nestjs_agent_core40.AGENT_PROMPT_CONTRIBUTORS,
18902
+ provide: import_nestjs_agent_core41.AGENT_PROMPT_CONTRIBUTORS,
18783
18903
  useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
18784
18904
  },
18785
18905
  // Likewise for `@Skill`-decorated providers — filled by SkillDiscoveryService at onModuleInit,
18786
18906
  // read lazily by the AGENT_SKILLS provider below (which DI builds before discovery has run).
18787
18907
  {
18788
- provide: import_nestjs_agent_core40.AGENT_SKILL_SOURCES,
18908
+ provide: import_nestjs_agent_core41.AGENT_SKILL_SOURCES,
18789
18909
  useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
18790
18910
  },
18791
18911
  {
18792
18912
  // One resolution, shared by the loop's deps and the listing endpoint: a second one would
18793
18913
  // drift, and a user would be offered a skill the agent cannot reach. `undefined` when the
18794
18914
  // host configured none — which is what keeps the turn's checkpoint sequence unchanged.
18795
- provide: import_nestjs_agent_core40.AGENT_SKILLS,
18915
+ provide: import_nestjs_agent_core41.AGENT_SKILLS,
18796
18916
  // Personal agents resolve no skill scope (`personalAgentScopes`): nothing of the app's to load.
18797
18917
  useFactory: /* @__PURE__ */ __name((options, declared) => {
18798
18918
  const skills = resolveSkillsConfig(options.skills, declared);
18799
18919
  return skills === void 0 ? void 0 : {
18800
18920
  ...skills,
18801
- scopes: (0, import_nestjs_agent_core40.personalAgentScopes)(skills.scopes)
18921
+ scopes: (0, import_nestjs_agent_core41.personalAgentScopes)(skills.scopes)
18802
18922
  };
18803
18923
  }, "useFactory"),
18804
18924
  inject: [
18805
- import_nestjs_agent_core40.AGENT_OPTIONS,
18806
- import_nestjs_agent_core40.AGENT_SKILL_SOURCES
18925
+ import_nestjs_agent_core41.AGENT_OPTIONS,
18926
+ import_nestjs_agent_core41.AGENT_SKILL_SOURCES
18807
18927
  ]
18808
18928
  },
18809
18929
  {
18810
18930
  // One resolution, shared by the loop's deps and the read-back endpoint: a person has to be
18811
18931
  // shown what the model was shown, and two resolutions would eventually disagree about that.
18812
- provide: import_nestjs_agent_core40.AGENT_MEMORY,
18932
+ provide: import_nestjs_agent_core41.AGENT_MEMORY,
18813
18933
  // Personal agents resolve no memory scope (`personalAgentScopes`): under a signed-in Poppy
18814
18934
  // conversation the actor is the account, and it must neither read nor write its memories.
18815
18935
  useFactory: /* @__PURE__ */ __name((options) => options.memory === void 0 ? void 0 : {
18816
18936
  ...options.memory,
18817
- scopes: (0, import_nestjs_agent_core40.personalAgentScopes)(options.memory.scopes)
18937
+ scopes: (0, import_nestjs_agent_core41.personalAgentScopes)(options.memory.scopes)
18818
18938
  }, "useFactory"),
18819
18939
  inject: [
18820
- import_nestjs_agent_core40.AGENT_OPTIONS
18940
+ import_nestjs_agent_core41.AGENT_OPTIONS
18821
18941
  ]
18822
18942
  },
18823
18943
  {
18824
- provide: import_nestjs_agent_core40.AGENT_SINK,
18944
+ provide: import_nestjs_agent_core41.AGENT_SINK,
18825
18945
  useFactory: /* @__PURE__ */ __name((options) => options.sink ?? new InProcessTokenStreamSink(), "useFactory"),
18826
18946
  inject: [
18827
- import_nestjs_agent_core40.AGENT_OPTIONS
18947
+ import_nestjs_agent_core41.AGENT_OPTIONS
18828
18948
  ]
18829
18949
  },
18830
18950
  // `@nestjs/authorization`'s AuthorizationService, when the app imports AuthorizationModule.
18831
18951
  NestAuthorizationBinding,
18832
18952
  {
18833
- provide: import_nestjs_agent_core40.AGENT_ROLES_POLICY,
18953
+ provide: import_nestjs_agent_core41.AGENT_ROLES_POLICY,
18834
18954
  // Personal agents (a Poppy conversation, a Poppy session's MCP token) reach only the tools
18835
18955
  // written for them, and run only those of the scopes their user granted. A no-op for every
18836
18956
  // other actor. Around the roles policy, a tool's `@Can()` abilities are asked of
18837
18957
  // `@nestjs/authorization`, for the user its agent function calls run as.
18838
- useFactory: /* @__PURE__ */ __name((options, modules, authorization) => (0, import_nestjs_agent_core40.personalAgentGate)(authorizationGate(resolveRolesPolicy(options, modules), () => authorization.service, (actor) => (options.agentFunctionCaller ?? defaultAgentFunctionCaller)(actor).user)), "useFactory"),
18958
+ useFactory: /* @__PURE__ */ __name((options, modules, authorization) => (0, import_nestjs_agent_core41.personalAgentGate)(authorizationGate(resolveRolesPolicy(options, modules), () => authorization.service, (actor) => (options.agentFunctionCaller ?? defaultAgentFunctionCaller)(actor).user)), "useFactory"),
18839
18959
  inject: [
18840
- import_nestjs_agent_core40.AGENT_OPTIONS,
18960
+ import_nestjs_agent_core41.AGENT_OPTIONS,
18841
18961
  import_core6.ModulesContainer,
18842
18962
  NestAuthorizationBinding
18843
18963
  ]
18844
18964
  },
18845
18965
  {
18846
- provide: import_nestjs_agent_core40.AGENT_ACTOR_RESOLVER,
18847
- useFactory: /* @__PURE__ */ __name((options) => {
18848
- if (options.actorResolver !== void 0) return options.actorResolver;
18966
+ provide: import_nestjs_agent_core41.AGENT_ACTOR_RESOLVER,
18967
+ // With tenancy on, an actor the resolver left without a `tenantRef` gets the context tenant's.
18968
+ useFactory: /* @__PURE__ */ __name((options, contextAccessor) => {
18969
+ if (options.actorResolver !== void 0) {
18970
+ return tenantFillingResolver(options.actorResolver, options.tenancy, contextAccessor);
18971
+ }
18849
18972
  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.");
18850
- return new AnonymousActorResolver();
18973
+ return tenantFillingResolver(new AnonymousActorResolver(), options.tenancy, contextAccessor);
18851
18974
  }, "useFactory"),
18852
18975
  inject: [
18853
- import_nestjs_agent_core40.AGENT_OPTIONS
18976
+ import_nestjs_agent_core41.AGENT_OPTIONS,
18977
+ {
18978
+ token: import_nestjs_agent_core41.CONTEXT_ACCESSOR,
18979
+ optional: true
18980
+ }
18854
18981
  ]
18855
18982
  },
18856
18983
  // No `model` (and no `engine`): the turns run on `@nestjs/ai`'s `AiModule` models.
18857
18984
  NestAiModelsBinding,
18858
18985
  {
18859
- provide: import_nestjs_agent_core40.AGENT_MODEL,
18986
+ provide: import_nestjs_agent_core41.AGENT_MODEL,
18860
18987
  useFactory: /* @__PURE__ */ __name((o, nestAi) => o.model ?? (nestAi.active ? nestAi : void 0), "useFactory"),
18861
18988
  inject: [
18862
- import_nestjs_agent_core40.AGENT_OPTIONS,
18989
+ import_nestjs_agent_core41.AGENT_OPTIONS,
18863
18990
  NestAiModelsBinding
18864
18991
  ]
18865
18992
  },
18866
18993
  {
18867
18994
  // `quota` is either a provider of the host's own or ceilings for the built-in ledger one;
18868
18995
  // omitted, the ledger provider still reports usage, with no ceiling to block on.
18869
- provide: import_nestjs_agent_core40.AGENT_QUOTA_PROVIDER,
18996
+ provide: import_nestjs_agent_core41.AGENT_QUOTA_PROVIDER,
18870
18997
  useFactory: /* @__PURE__ */ __name((o, store) => isQuotaProvider(o.quota) ? o.quota : new LedgerQuotaProvider(store, o.quota?.limits, {
18871
18998
  ...o.quota?.warnAt !== void 0 ? {
18872
18999
  warnAt: o.quota.warnAt
18873
19000
  } : {},
18874
19001
  ...o.quota?.countEstimatedCost !== void 0 ? {
18875
19002
  countEstimatedCost: o.quota.countEstimatedCost
19003
+ } : {},
19004
+ ...o.quota?.per !== void 0 ? {
19005
+ per: o.quota.per
18876
19006
  } : {}
18877
19007
  }), "useFactory"),
18878
19008
  inject: [
18879
- import_nestjs_agent_core40.AGENT_OPTIONS,
18880
- import_nestjs_agent_core40.AGENT_STORE
19009
+ import_nestjs_agent_core41.AGENT_OPTIONS,
19010
+ import_nestjs_agent_core41.AGENT_STORE
18881
19011
  ]
18882
19012
  },
18883
19013
  {
18884
- provide: import_nestjs_agent_core40.AGENT_MODEL_CATALOG,
19014
+ provide: import_nestjs_agent_core41.AGENT_MODEL_CATALOG,
18885
19015
  useFactory: /* @__PURE__ */ __name((o, model) => resolveCatalog(o, model), "useFactory"),
18886
19016
  inject: [
18887
- import_nestjs_agent_core40.AGENT_OPTIONS,
18888
- import_nestjs_agent_core40.AGENT_MODEL
19017
+ import_nestjs_agent_core41.AGENT_OPTIONS,
19018
+ import_nestjs_agent_core41.AGENT_MODEL
18889
19019
  ]
18890
19020
  },
18891
19021
  AgentDepsFactory2,
18892
19022
  {
18893
- provide: import_nestjs_agent_core40.AGENT_DEPS_FACTORY,
19023
+ provide: import_nestjs_agent_core41.AGENT_DEPS_FACTORY,
18894
19024
  useExisting: AgentDepsFactory2
18895
19025
  },
18896
19026
  // Seeds a configured model's missing price row from models.dev and warns about one that would
@@ -18920,26 +19050,26 @@ function sharedProviders(durable, engine) {
18920
19050
  // through AgentService.signalToolCall, which reaches whichever AGENT_RUNNER is bound above.
18921
19051
  AgentApprovalPortAdapter,
18922
19052
  {
18923
- provide: import_nestjs_agent_core40.AGENT_APPROVAL_PORT,
19053
+ provide: import_nestjs_agent_core41.AGENT_APPROVAL_PORT,
18924
19054
  useExisting: AgentApprovalPortAdapter
18925
19055
  }
18926
19056
  ];
18927
19057
  providers.push({
18928
- provide: import_nestjs_agent_core40.AGENT_STORE,
19058
+ provide: import_nestjs_agent_core41.AGENT_STORE,
18929
19059
  useFactory: /* @__PURE__ */ __name((o, modules) => resolveStore(o, modules), "useFactory"),
18930
19060
  inject: [
18931
- import_nestjs_agent_core40.AGENT_OPTIONS,
19061
+ import_nestjs_agent_core41.AGENT_OPTIONS,
18932
19062
  import_core6.ModulesContainer
18933
19063
  ]
18934
19064
  });
18935
19065
  if (engine !== void 0) {
18936
19066
  providers.push(...engine.providers, {
18937
- provide: import_nestjs_agent_core40.AGENT_RUNNER,
19067
+ provide: import_nestjs_agent_core41.AGENT_RUNNER,
18938
19068
  useExisting: engine.runner
18939
19069
  });
18940
19070
  } else if (durableEngine === "aviary") {
18941
19071
  providers.push({
18942
- provide: import_nestjs_agent_core40.AGENT_RUNNER,
19072
+ provide: import_nestjs_agent_core41.AGENT_RUNNER,
18943
19073
  useFactory: /* @__PURE__ */ __name((durableRunner) => {
18944
19074
  if (durableRunner === void 0) {
18945
19075
  throw new Error("AgentModule.forRoot({ durable: { engine: 'aviary' } }) requires importing AgentDurableModule from '@dudousxd/nestjs-agent/durable' (alongside a configured DurableModule). It was not found.");
@@ -18948,14 +19078,14 @@ function sharedProviders(durable, engine) {
18948
19078
  }, "useFactory"),
18949
19079
  inject: [
18950
19080
  {
18951
- token: import_nestjs_agent_core40.AGENT_DURABLE_RUNNER,
19081
+ token: import_nestjs_agent_core41.AGENT_DURABLE_RUNNER,
18952
19082
  optional: true
18953
19083
  }
18954
19084
  ]
18955
19085
  });
18956
19086
  } else if (durableEngine === "workflows") {
18957
19087
  providers.push({
18958
- provide: import_nestjs_agent_core40.AGENT_RUNNER,
19088
+ provide: import_nestjs_agent_core41.AGENT_RUNNER,
18959
19089
  useFactory: /* @__PURE__ */ __name((workflowsRunner) => {
18960
19090
  if (workflowsRunner === void 0) {
18961
19091
  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' }.)");
@@ -18964,14 +19094,14 @@ function sharedProviders(durable, engine) {
18964
19094
  }, "useFactory"),
18965
19095
  inject: [
18966
19096
  {
18967
- token: import_nestjs_agent_core40.AGENT_WORKFLOWS_RUNNER,
19097
+ token: import_nestjs_agent_core41.AGENT_WORKFLOWS_RUNNER,
18968
19098
  optional: true
18969
19099
  }
18970
19100
  ]
18971
19101
  });
18972
19102
  } else {
18973
19103
  providers.push({
18974
- provide: import_nestjs_agent_core40.AGENT_RUNNER,
19104
+ provide: import_nestjs_agent_core41.AGENT_RUNNER,
18975
19105
  useExisting: InlineAgentRunner
18976
19106
  });
18977
19107
  }
@@ -18981,20 +19111,20 @@ __name(sharedProviders, "sharedProviders");
18981
19111
  function exportsFor(engine) {
18982
19112
  return [
18983
19113
  ...engine?.exports ?? [],
18984
- import_nestjs_agent_core40.AGENT_OPTIONS,
18985
- import_nestjs_agent_core40.AGENT_TOOL_REGISTRY,
18986
- import_nestjs_agent_core40.AGENT_REGISTRY,
18987
- import_nestjs_agent_core40.AGENT_SINK,
18988
- import_nestjs_agent_core40.AGENT_ROLES_POLICY,
18989
- import_nestjs_agent_core40.AGENT_ACTOR_RESOLVER,
18990
- import_nestjs_agent_core40.AGENT_MODEL,
18991
- import_nestjs_agent_core40.AGENT_STORE,
18992
- import_nestjs_agent_core40.AGENT_MODEL_CATALOG,
18993
- import_nestjs_agent_core40.AGENT_QUOTA_PROVIDER,
18994
- import_nestjs_agent_core40.AGENT_PROMPT_CONTRIBUTORS,
18995
- import_nestjs_agent_core40.AGENT_SKILLS,
18996
- import_nestjs_agent_core40.AGENT_MEMORY,
18997
- import_nestjs_agent_core40.AGENT_DEPS_FACTORY,
19114
+ import_nestjs_agent_core41.AGENT_OPTIONS,
19115
+ import_nestjs_agent_core41.AGENT_TOOL_REGISTRY,
19116
+ import_nestjs_agent_core41.AGENT_REGISTRY,
19117
+ import_nestjs_agent_core41.AGENT_SINK,
19118
+ import_nestjs_agent_core41.AGENT_ROLES_POLICY,
19119
+ import_nestjs_agent_core41.AGENT_ACTOR_RESOLVER,
19120
+ import_nestjs_agent_core41.AGENT_MODEL,
19121
+ import_nestjs_agent_core41.AGENT_STORE,
19122
+ import_nestjs_agent_core41.AGENT_MODEL_CATALOG,
19123
+ import_nestjs_agent_core41.AGENT_QUOTA_PROVIDER,
19124
+ import_nestjs_agent_core41.AGENT_PROMPT_CONTRIBUTORS,
19125
+ import_nestjs_agent_core41.AGENT_SKILLS,
19126
+ import_nestjs_agent_core41.AGENT_MEMORY,
19127
+ import_nestjs_agent_core41.AGENT_DEPS_FACTORY,
18998
19128
  AgentDepsFactory2,
18999
19129
  AgentService2,
19000
19130
  AGENT_SERVICE,
@@ -19003,7 +19133,7 @@ function exportsFor(engine) {
19003
19133
  ChatQueueService,
19004
19134
  AGENT_CHAT_QUEUE,
19005
19135
  InlineAgentRunner,
19006
- import_nestjs_agent_core40.AGENT_APPROVAL_PORT
19136
+ import_nestjs_agent_core41.AGENT_APPROVAL_PORT
19007
19137
  ];
19008
19138
  }
19009
19139
  __name(exportsFor, "exportsFor");
@@ -19034,7 +19164,7 @@ __name(adapterProviders, "adapterProviders");
19034
19164
  function controllersForSurface(surface, adapters, engine, decorators, routes) {
19035
19165
  if (surface === "engine" || routes === false) return [];
19036
19166
  return [
19037
- ...(0, import_nestjs_agent_core40.withControllerDecorators)([
19167
+ ...(0, import_nestjs_agent_core41.withControllerDecorators)([
19038
19168
  ...BASE_CONTROLLERS,
19039
19169
  ...adapterControllers(adapters)
19040
19170
  ], decorators),
@@ -19074,7 +19204,7 @@ var AgentModule = class _AgentModule {
19074
19204
  controllers: controllersForSurface(options.surface, options.adapters, options.engine, options.decorators, options.routes),
19075
19205
  providers: [
19076
19206
  {
19077
- provide: import_nestjs_agent_core40.AGENT_OPTIONS,
19207
+ provide: import_nestjs_agent_core41.AGENT_OPTIONS,
19078
19208
  useValue: options
19079
19209
  },
19080
19210
  ...sharedProviders(options.durable, options.engine),
@@ -19102,7 +19232,7 @@ var AgentModule = class _AgentModule {
19102
19232
  controllers: controllersForSurface(options.surface, options.adapters, options.engine, options.decorators, options.routes),
19103
19233
  providers: [
19104
19234
  {
19105
- provide: import_nestjs_agent_core40.AGENT_OPTIONS,
19235
+ provide: import_nestjs_agent_core41.AGENT_OPTIONS,
19106
19236
  // Stamp the STATIC wiring flags onto the factory result: `durable`/`surface` are
19107
19237
  // authoritative on the async config object (they decided the actual wiring above), and
19108
19238
  // the durable module reads `durable` back off AGENT_OPTIONS. `surface` isn't read back by
@@ -19136,7 +19266,7 @@ AgentModule = _ts_decorate29([
19136
19266
  ], AgentModule);
19137
19267
 
19138
19268
  // src/ag-ui/ag-ui.adapter.ts
19139
- var import_nestjs_agent_core41 = require("@dudousxd/nestjs-agent-core");
19269
+ var import_nestjs_agent_core42 = require("@dudousxd/nestjs-agent-core");
19140
19270
  var import_a2ui = require("@dudousxd/nestjs-agent-core/a2ui");
19141
19271
  var import_ag_ui = require("@dudousxd/nestjs-agent-core/ag-ui");
19142
19272
  var import_genui3 = require("@dudousxd/nestjs-agent-core/genui");
@@ -19562,13 +19692,13 @@ function agUiAdapter(options = {}) {
19562
19692
  _ts_metadata28("design:returntype", typeof Promise === "undefined" ? Object : Promise)
19563
19693
  ], AgUiController.prototype, "run", null);
19564
19694
  AgUiController = _ts_decorate30([
19565
- (0, import_nestjs_agent_core41.CanAnyone)(),
19695
+ (0, import_nestjs_agent_core42.CanAnyone)(),
19566
19696
  (0, import_common33.Controller)(),
19567
19697
  _ts_param27(0, (0, import_common33.Inject)(AgentService2)),
19568
- _ts_param27(1, (0, import_common33.Inject)(import_nestjs_agent_core41.AGENT_ACTOR_RESOLVER)),
19569
- _ts_param27(2, (0, import_common33.Inject)(import_nestjs_agent_core41.AGENT_OPTIONS)),
19698
+ _ts_param27(1, (0, import_common33.Inject)(import_nestjs_agent_core42.AGENT_ACTOR_RESOLVER)),
19699
+ _ts_param27(2, (0, import_common33.Inject)(import_nestjs_agent_core42.AGENT_OPTIONS)),
19570
19700
  _ts_param27(3, (0, import_common33.Optional)()),
19571
- _ts_param27(3, (0, import_common33.Inject)(import_nestjs_agent_core41.AGENT_ATTACHMENT_STAGING)),
19701
+ _ts_param27(3, (0, import_common33.Inject)(import_nestjs_agent_core42.AGENT_ATTACHMENT_STAGING)),
19572
19702
  _ts_param27(4, (0, import_common33.Optional)()),
19573
19703
  _ts_param27(4, (0, import_common33.Inject)(GENUI_CATALOG)),
19574
19704
  _ts_metadata28("design:type", Function),
@@ -19598,7 +19728,7 @@ function withCatalog(options, catalog) {
19598
19728
  __name(withCatalog, "withCatalog");
19599
19729
 
19600
19730
  // src/a2ui/a2ui.adapter.ts
19601
- var import_nestjs_agent_core42 = require("@dudousxd/nestjs-agent-core");
19731
+ var import_nestjs_agent_core43 = require("@dudousxd/nestjs-agent-core");
19602
19732
  var import_a2ui2 = require("@dudousxd/nestjs-agent-core/a2ui");
19603
19733
  var import_ag_ui2 = require("@dudousxd/nestjs-agent-core/ag-ui");
19604
19734
  var import_genui4 = require("@dudousxd/nestjs-agent-core/genui");
@@ -19921,10 +20051,10 @@ function a2uiAdapter(options = {}) {
19921
20051
  _ts_metadata29("design:returntype", typeof Promise === "undefined" ? Object : Promise)
19922
20052
  ], A2uiController.prototype, "run", null);
19923
20053
  A2uiController = _ts_decorate31([
19924
- (0, import_nestjs_agent_core42.CanAnyone)(),
20054
+ (0, import_nestjs_agent_core43.CanAnyone)(),
19925
20055
  (0, import_common34.Controller)(),
19926
20056
  _ts_param28(0, (0, import_common34.Inject)(AGENT_SERVICE)),
19927
- _ts_param28(1, (0, import_common34.Inject)(import_nestjs_agent_core42.AGENT_ACTOR_RESOLVER)),
20057
+ _ts_param28(1, (0, import_common34.Inject)(import_nestjs_agent_core43.AGENT_ACTOR_RESOLVER)),
19928
20058
  _ts_param28(2, (0, import_common34.Optional)()),
19929
20059
  _ts_param28(2, (0, import_common34.Inject)(GENUI_CATALOG)),
19930
20060
  _ts_metadata29("design:type", Function),