@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.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DynamicModule, OnModuleInit, Type, OnApplicationBootstrap, ConflictException, OnModuleDestroy } from '@nestjs/common';
2
- import { b as AgentModuleOptions, c as AgentModuleAsyncOptions, d as AgentProtocolAdapter, A as AgentDepsFactory, e as AgentSkillsOptions, C as ChatQueueService } from './chat-queue.service-C49HIuEV.cjs';
3
- export { f as AGENT_TOOL_BRAND, g as AgentAttachmentsOptions, h as AgentDeps, i as AgentDurableOptions, j as AgentEngine, k as AgentFunctionCaller, l as AgentMemoryOptions, a as AgentSurface, F as FunctionalTool, L as LedgerQuotaProvider, Q as QueuePlan, m as QueueSettleOutcome, n as QueuedTurn, o as QueuedTurnStarter, p as QuotaLimits, q as QuotaWindowLimits, r as defaultAgentFunctionCaller, s as defineTool, t as delegateToolName, u as durableEngineOf, v as provideAgentTool, w as provideAgentTools, x as utcDay } from './chat-queue.service-C49HIuEV.cjs';
2
+ import { b as AgentModuleOptions, c as AgentModuleAsyncOptions, d as AgentProtocolAdapter, A as AgentDepsFactory, e as AgentSkillsOptions, C as ChatQueueService } from './chat-queue.service-OY6mUgB9.cjs';
3
+ export { f as AGENT_TOOL_BRAND, g as AgentAttachmentsOptions, h as AgentDeps, i as AgentDurableOptions, j as AgentEngine, k as AgentFunctionCaller, l as AgentMemoryOptions, a as AgentSurface, F as FunctionalTool, L as LedgerQuotaProvider, Q as QueuePlan, m as QueueSettleOutcome, n as QueuedTurn, o as QueuedTurnStarter, p as QuotaLimits, q as QuotaWindowLimits, r as defaultAgentFunctionCaller, s as defineTool, t as delegateToolName, u as durableEngineOf, v as provideAgentTool, w as provideAgentTools, x as utcDay } from './chat-queue.service-OY6mUgB9.cjs';
4
4
  import * as _dudousxd_nestjs_agent_core from '@dudousxd/nestjs-agent-core';
5
5
  import { ModelProvider, ModelCatalog, ModelTurnArgs, ModelTurnResult, DescribedModel, PriceCatalogEntry, ToolPresentation, ToolSpec, RolesPolicy, Actor, ActorResolver, AttachmentStagingStore, AgentApprovalPort, AgentStore, StagedAttachment, MessageAttachment, AgentClientConfig, ToolCanRequirement, AgentHistoryWindow, AgentIntake, Persona, SkillContext, ToolRegistry, AgentRegistry, PromptContributor, SkillsConfig, SkillCatalogEntry, MessageFeedbackValue, MessageFeedback, ModelCatalogView, ToolCatalogEntry, MemoryConfig, MemoryDigestEntry, SkillProvider, AgentRunner, AgentRunInput, AgentRunStartOptions, HumanReply, ChatQueueState, TokenStreamSink, SinkWriter, SubscribeOptions, ActionProposalOutcome, ActionProposal, PageContext, AgentCatalogEntry } from '@dudousxd/nestjs-agent-core';
6
6
  export * from '@dudousxd/nestjs-agent-core';
@@ -11,8 +11,8 @@ import { ResilienceService } from '@nestjs/resilience';
11
11
  import { AuthorizationService } from '@nestjs/authorization';
12
12
  import { A2uiOptions } from '@dudousxd/nestjs-agent-core/a2ui';
13
13
  import { Request, Response } from 'express';
14
- import { A as AgentService, a as ActionProposalService } from './index-BBkyvNUi.cjs';
15
- export { b as A2uiAdapterOptions, c as A2uiRunHandler, d as AttachmentLimits, C as ChatParams, e as ChatSendMode, f as ChatSendResult, D as DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, g as DEFAULT_MAX_ATTACHMENT_BYTES, F as ForkThreadParams, M as MAX_ATTACHMENTS_PER_MESSAGE, N as NO_USER_MESSAGE_CODE, Q as QueuedSend, T as ThreadDefaultAgentReader, h as ThreadModelReader, i as a2uiAdapter, j as attachmentLimits } from './index-BBkyvNUi.cjs';
14
+ import { A as AgentService, a as ActionProposalService } from './index-QYQiIXCI.cjs';
15
+ export { b as A2uiAdapterOptions, c as A2uiRunHandler, d as AttachmentLimits, C as ChatParams, e as ChatSendMode, f as ChatSendResult, D as DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, g as DEFAULT_MAX_ATTACHMENT_BYTES, F as ForkThreadParams, M as MAX_ATTACHMENTS_PER_MESSAGE, N as NO_USER_MESSAGE_CODE, Q as QueuedSend, T as ThreadDefaultAgentReader, h as ThreadModelReader, i as a2uiAdapter, j as attachmentLimits } from './index-QYQiIXCI.cjs';
16
16
  import { AgentGenui } from './genui/index.cjs';
17
17
  import { StandardSchemaV1 } from '@standard-schema/spec';
18
18
  import '@dudousxd/nestjs-agent-core/genui';
@@ -228,7 +228,8 @@ declare function agUiAdapter(options?: AgUiAdapterOptions): AgentProtocolAdapter
228
228
  * Deliberately WITHOUT `AgentService.approve`/`reject`'s ownership check: a console caller reaches
229
229
  * this port only through the dashboard's own guards (already authorized), not as the thread's own
230
230
  * actor — re-deriving "does this actor own the thread" here would reject a legitimate operator
231
- * decision. `opts.executedByRef` is an OPAQUE decider ref, not re-authorized against anything: it
231
+ * decision. With the agent's tenancy on, a tool call outside the request's context tenant is not
232
+ * found (`404`). `opts.executedByRef` is an OPAQUE decider ref, not re-authorized against anything: it
232
233
  * rides the `Decision` and the loop records it as the tool call's decider
233
234
  * (`decision.executedByRef ?? input.actor.id`, on both the executed and rejected paths).
234
235
  */
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DynamicModule, OnModuleInit, Type, OnApplicationBootstrap, ConflictException, OnModuleDestroy } from '@nestjs/common';
2
- import { b as AgentModuleOptions, c as AgentModuleAsyncOptions, d as AgentProtocolAdapter, A as AgentDepsFactory, e as AgentSkillsOptions, C as ChatQueueService } from './chat-queue.service-BjPCw4Pf.js';
3
- export { f as AGENT_TOOL_BRAND, g as AgentAttachmentsOptions, h as AgentDeps, i as AgentDurableOptions, j as AgentEngine, k as AgentFunctionCaller, l as AgentMemoryOptions, a as AgentSurface, F as FunctionalTool, L as LedgerQuotaProvider, Q as QueuePlan, m as QueueSettleOutcome, n as QueuedTurn, o as QueuedTurnStarter, p as QuotaLimits, q as QuotaWindowLimits, r as defaultAgentFunctionCaller, s as defineTool, t as delegateToolName, u as durableEngineOf, v as provideAgentTool, w as provideAgentTools, x as utcDay } from './chat-queue.service-BjPCw4Pf.js';
2
+ import { b as AgentModuleOptions, c as AgentModuleAsyncOptions, d as AgentProtocolAdapter, A as AgentDepsFactory, e as AgentSkillsOptions, C as ChatQueueService } from './chat-queue.service-MYNBAY3P.js';
3
+ export { f as AGENT_TOOL_BRAND, g as AgentAttachmentsOptions, h as AgentDeps, i as AgentDurableOptions, j as AgentEngine, k as AgentFunctionCaller, l as AgentMemoryOptions, a as AgentSurface, F as FunctionalTool, L as LedgerQuotaProvider, Q as QueuePlan, m as QueueSettleOutcome, n as QueuedTurn, o as QueuedTurnStarter, p as QuotaLimits, q as QuotaWindowLimits, r as defaultAgentFunctionCaller, s as defineTool, t as delegateToolName, u as durableEngineOf, v as provideAgentTool, w as provideAgentTools, x as utcDay } from './chat-queue.service-MYNBAY3P.js';
4
4
  import * as _dudousxd_nestjs_agent_core from '@dudousxd/nestjs-agent-core';
5
5
  import { ModelProvider, ModelCatalog, ModelTurnArgs, ModelTurnResult, DescribedModel, PriceCatalogEntry, ToolPresentation, ToolSpec, RolesPolicy, Actor, ActorResolver, AttachmentStagingStore, AgentApprovalPort, AgentStore, StagedAttachment, MessageAttachment, AgentClientConfig, ToolCanRequirement, AgentHistoryWindow, AgentIntake, Persona, SkillContext, ToolRegistry, AgentRegistry, PromptContributor, SkillsConfig, SkillCatalogEntry, MessageFeedbackValue, MessageFeedback, ModelCatalogView, ToolCatalogEntry, MemoryConfig, MemoryDigestEntry, SkillProvider, AgentRunner, AgentRunInput, AgentRunStartOptions, HumanReply, ChatQueueState, TokenStreamSink, SinkWriter, SubscribeOptions, ActionProposalOutcome, ActionProposal, PageContext, AgentCatalogEntry } from '@dudousxd/nestjs-agent-core';
6
6
  export * from '@dudousxd/nestjs-agent-core';
@@ -11,8 +11,8 @@ import { ResilienceService } from '@nestjs/resilience';
11
11
  import { AuthorizationService } from '@nestjs/authorization';
12
12
  import { A2uiOptions } from '@dudousxd/nestjs-agent-core/a2ui';
13
13
  import { Request, Response } from 'express';
14
- import { A as AgentService, a as ActionProposalService } from './index-CRCbsO6E.js';
15
- export { b as A2uiAdapterOptions, c as A2uiRunHandler, d as AttachmentLimits, C as ChatParams, e as ChatSendMode, f as ChatSendResult, D as DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, g as DEFAULT_MAX_ATTACHMENT_BYTES, F as ForkThreadParams, M as MAX_ATTACHMENTS_PER_MESSAGE, N as NO_USER_MESSAGE_CODE, Q as QueuedSend, T as ThreadDefaultAgentReader, h as ThreadModelReader, i as a2uiAdapter, j as attachmentLimits } from './index-CRCbsO6E.js';
14
+ import { A as AgentService, a as ActionProposalService } from './index-Ba_0o9Ze.js';
15
+ export { b as A2uiAdapterOptions, c as A2uiRunHandler, d as AttachmentLimits, C as ChatParams, e as ChatSendMode, f as ChatSendResult, D as DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, g as DEFAULT_MAX_ATTACHMENT_BYTES, F as ForkThreadParams, M as MAX_ATTACHMENTS_PER_MESSAGE, N as NO_USER_MESSAGE_CODE, Q as QueuedSend, T as ThreadDefaultAgentReader, h as ThreadModelReader, i as a2uiAdapter, j as attachmentLimits } from './index-Ba_0o9Ze.js';
16
16
  import { AgentGenui } from './genui/index.js';
17
17
  import { StandardSchemaV1 } from '@standard-schema/spec';
18
18
  import '@dudousxd/nestjs-agent-core/genui';
@@ -228,7 +228,8 @@ declare function agUiAdapter(options?: AgUiAdapterOptions): AgentProtocolAdapter
228
228
  * Deliberately WITHOUT `AgentService.approve`/`reject`'s ownership check: a console caller reaches
229
229
  * this port only through the dashboard's own guards (already authorized), not as the thread's own
230
230
  * actor — re-deriving "does this actor own the thread" here would reject a legitimate operator
231
- * decision. `opts.executedByRef` is an OPAQUE decider ref, not re-authorized against anything: it
231
+ * decision. With the agent's tenancy on, a tool call outside the request's context tenant is not
232
+ * found (`404`). `opts.executedByRef` is an OPAQUE decider ref, not re-authorized against anything: it
232
233
  * rides the `Decision` and the loop records it as the tool call's decider
233
234
  * (`decision.executedByRef ?? input.actor.id`, on both the executed and rejected paths).
234
235
  */
package/dist/index.js CHANGED
@@ -11079,7 +11079,7 @@ var require_cjs = __commonJS({
11079
11079
  });
11080
11080
 
11081
11081
  // src/agent.module.ts
11082
- import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER14, AGENT_APPROVAL_PORT, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY7, AGENT_DURABLE_RUNNER, AGENT_MEMORY as AGENT_MEMORY3, AGENT_MODEL as AGENT_MODEL3, AGENT_MODEL_CATALOG as AGENT_MODEL_CATALOG3, AGENT_OPTIONS as AGENT_OPTIONS11, AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS3, AGENT_QUOTA_PROVIDER as AGENT_QUOTA_PROVIDER3, AGENT_REGISTRY as AGENT_REGISTRY6, AGENT_ROLES_POLICY as AGENT_ROLES_POLICY2, AGENT_RUNNER as AGENT_RUNNER2, AGENT_SINK as AGENT_SINK3, AGENT_SKILLS as AGENT_SKILLS3, AGENT_SKILL_SOURCES as AGENT_SKILL_SOURCES2, AGENT_STORE as AGENT_STORE7, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY3, AGENT_WORKFLOWS_RUNNER, AgentRegistry as AgentRegistry6, ClosedRolesPolicy, DefaultRolesPolicy, InMemoryAgentStore, ToolRegistry as ToolRegistry3, personalAgentGate, personalAgentScopes, withControllerDecorators } from "@dudousxd/nestjs-agent-core";
11082
+ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER14, AGENT_APPROVAL_PORT, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY7, AGENT_DURABLE_RUNNER, AGENT_MEMORY as AGENT_MEMORY3, AGENT_MODEL as AGENT_MODEL3, AGENT_MODEL_CATALOG as AGENT_MODEL_CATALOG3, AGENT_OPTIONS as AGENT_OPTIONS11, AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS3, AGENT_QUOTA_PROVIDER as AGENT_QUOTA_PROVIDER3, AGENT_REGISTRY as AGENT_REGISTRY6, AGENT_ROLES_POLICY as AGENT_ROLES_POLICY2, AGENT_RUNNER as AGENT_RUNNER2, AGENT_SINK as AGENT_SINK3, AGENT_SKILLS as AGENT_SKILLS3, AGENT_SKILL_SOURCES as AGENT_SKILL_SOURCES2, AGENT_STORE as AGENT_STORE7, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY3, AGENT_WORKFLOWS_RUNNER, AgentRegistry as AgentRegistry6, CONTEXT_ACCESSOR as CONTEXT_ACCESSOR3, ClosedRolesPolicy, DefaultRolesPolicy, InMemoryAgentStore, ToolRegistry as ToolRegistry3, personalAgentGate, personalAgentScopes, withControllerDecorators } from "@dudousxd/nestjs-agent-core";
11083
11083
  import { Global, Logger as Logger11, Module as Module2 } from "@nestjs/common";
11084
11084
  import { DiscoveryModule, ModulesContainer, RouterModule } from "@nestjs/core";
11085
11085
 
@@ -11825,8 +11825,8 @@ function durableEngineOf(durable) {
11825
11825
  __name(durableEngineOf, "durableEngineOf");
11826
11826
 
11827
11827
  // src/agent.service.ts
11828
- import { AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING2, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY2, AGENT_MODEL_CATALOG, AGENT_OPTIONS as AGENT_OPTIONS4, AGENT_QUOTA_PROVIDER as AGENT_QUOTA_PROVIDER2, AGENT_RUNNER, AGENT_STORE as AGENT_STORE4, DEFAULT_TEXT_ACTION_PROPOSAL_VOCABULARY as DEFAULT_TEXT_ACTION_PROPOSAL_VOCABULARY2, REQUESTER_APPROVER, findCatalogModel, mayDecideApproval as mayDecideApproval2, readElicitationQuestions, recordAiUsage, settleDeadRun, textActionProposalReply as textActionProposalReply2, validateElicitationAnswer } from "@dudousxd/nestjs-agent-core";
11829
- import { BadRequestException as BadRequestException2, ConflictException as ConflictException2, ForbiddenException as ForbiddenException2, GoneException, HttpException, HttpStatus, Inject as Inject5, Injectable as Injectable4, Logger as Logger2, NotFoundException as NotFoundException2, NotImplementedException as NotImplementedException3, Optional as Optional3, PayloadTooLargeException, UnsupportedMediaTypeException } from "@nestjs/common";
11828
+ import { AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING2, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY2, AGENT_MODEL_CATALOG, AGENT_OPTIONS as AGENT_OPTIONS4, AGENT_QUOTA_PROVIDER as AGENT_QUOTA_PROVIDER2, AGENT_RUNNER, AGENT_STORE as AGENT_STORE4, CONTEXT_ACCESSOR as CONTEXT_ACCESSOR2, DEFAULT_TEXT_ACTION_PROPOSAL_VOCABULARY as DEFAULT_TEXT_ACTION_PROPOSAL_VOCABULARY2, REQUESTER_APPROVER, contextTenantRef, findCatalogModel, mayDecideApproval as mayDecideApproval2, readElicitationQuestions, readTenancy as readTenancy2, recordAiUsage, settleDeadRun, tenantRowFilter as tenantRowFilter2, tenantRowVisible as tenantRowVisible2, textActionProposalReply as textActionProposalReply2, validateElicitationAnswer } from "@dudousxd/nestjs-agent-core";
11829
+ import { BadRequestException as BadRequestException2, ConflictException as ConflictException2, ForbiddenException as ForbiddenException2, GoneException, HttpException, HttpStatus, Inject as Inject5, Injectable as Injectable4, Logger as Logger2, NotFoundException as NotFoundException2, NotImplementedException as NotImplementedException3, Optional as Optional4, PayloadTooLargeException, UnsupportedMediaTypeException } from "@nestjs/common";
11830
11830
 
11831
11831
  // src/agent-deps.ts
11832
11832
  function utcDay(date = /* @__PURE__ */ new Date()) {
@@ -11876,8 +11876,8 @@ function attachmentLimits(options, staging) {
11876
11876
  __name(attachmentLimits, "attachmentLimits");
11877
11877
 
11878
11878
  // src/proposals/action-proposal.service.ts
11879
- import { AGENT_OPTIONS as AGENT_OPTIONS2, AGENT_STORE as AGENT_STORE2, DEFAULT_TEXT_ACTION_PROPOSAL_REPLIES, DEFAULT_TEXT_ACTION_PROPOSAL_VOCABULARY, mayDecideApproval, parseTextActionProposalCommand, resolveTextActionProposalDecision, textActionProposalReply, toActionProposalMutationView, toActionProposalView } from "@dudousxd/nestjs-agent-core";
11880
- import { ForbiddenException, Inject as Inject3, Injectable as Injectable2, NotFoundException, NotImplementedException } from "@nestjs/common";
11879
+ import { AGENT_OPTIONS as AGENT_OPTIONS2, AGENT_STORE as AGENT_STORE2, CONTEXT_ACCESSOR, DEFAULT_TEXT_ACTION_PROPOSAL_REPLIES, DEFAULT_TEXT_ACTION_PROPOSAL_VOCABULARY, mayDecideApproval, parseTextActionProposalCommand, readTenancy, resolveTextActionProposalDecision, tenantRowFilter, tenantRowVisible, textActionProposalReply, toActionProposalMutationView, toActionProposalView } from "@dudousxd/nestjs-agent-core";
11880
+ import { ForbiddenException, Inject as Inject3, Injectable as Injectable2, NotFoundException, NotImplementedException, Optional as Optional2 } from "@nestjs/common";
11881
11881
  function _ts_decorate3(decorators, target, key, desc) {
11882
11882
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
11883
11883
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -11910,9 +11910,11 @@ var ActionProposalService = class {
11910
11910
  }
11911
11911
  store;
11912
11912
  options;
11913
- constructor(store, options) {
11913
+ contextAccessor;
11914
+ constructor(store, options, contextAccessor) {
11914
11915
  this.store = store;
11915
11916
  this.options = options;
11917
+ this.contextAccessor = contextAccessor;
11916
11918
  const text = options.actionProposalText;
11917
11919
  this.vocabulary = {
11918
11920
  ...DEFAULT_TEXT_ACTION_PROPOSAL_VOCABULARY,
@@ -11938,6 +11940,8 @@ var ActionProposalService = class {
11938
11940
  async scope(threadId, actor) {
11939
11941
  const scope = await this.capability().getThreadActionProposalScope(threadId);
11940
11942
  if (!scope) throw new NotFoundException("Thread not found");
11943
+ const filter = tenantRowFilter(readTenancy(this.options.tenancy ?? "inherit", this.contextAccessor), actor.tenantRef);
11944
+ if (filter !== void 0 && !tenantRowVisible(filter, scope.tenantRef)) throw new NotFoundException("Thread not found");
11941
11945
  if (scope.tenantRef !== (actor.tenantRef ?? null)) throw new ForbiddenException("Wrong proposal tenant");
11942
11946
  return scope;
11943
11947
  }
@@ -12057,16 +12061,19 @@ ActionProposalService = _ts_decorate3([
12057
12061
  Injectable2(),
12058
12062
  _ts_param2(0, Inject3(AGENT_STORE2)),
12059
12063
  _ts_param2(1, Inject3(AGENT_OPTIONS2)),
12064
+ _ts_param2(2, Optional2()),
12065
+ _ts_param2(2, Inject3(CONTEXT_ACCESSOR)),
12060
12066
  _ts_metadata2("design:type", Function),
12061
12067
  _ts_metadata2("design:paramtypes", [
12062
12068
  typeof AgentStore === "undefined" ? Object : AgentStore,
12063
- typeof Pick === "undefined" ? Object : Pick
12069
+ typeof Pick === "undefined" ? Object : Pick,
12070
+ Object
12064
12071
  ])
12065
12072
  ], ActionProposalService);
12066
12073
 
12067
12074
  // src/queue/chat-queue.service.ts
12068
12075
  import { AGENT_ATTACHMENT_STAGING, AGENT_DEPS_FACTORY, AGENT_OPTIONS as AGENT_OPTIONS3, AGENT_QUOTA_PROVIDER, AGENT_SINK as AGENT_SINK2, AGENT_STORE as AGENT_STORE3, encodeStreamEvent, isChatQueueStore, queuedMessageView } from "@dudousxd/nestjs-agent-core";
12069
- import { Inject as Inject4, Injectable as Injectable3, Logger, NotImplementedException as NotImplementedException2, Optional as Optional2 } from "@nestjs/common";
12076
+ import { Inject as Inject4, Injectable as Injectable3, Logger, NotImplementedException as NotImplementedException2, Optional as Optional3 } from "@nestjs/common";
12070
12077
 
12071
12078
  // src/quota-exceeded.ts
12072
12079
  import { publishAgentQuotaExceeded } from "@dudousxd/nestjs-agent-core";
@@ -12542,13 +12549,13 @@ ChatQueueService = _ts_decorate4([
12542
12549
  Injectable3(),
12543
12550
  _ts_param3(0, Inject4(AGENT_STORE3)),
12544
12551
  _ts_param3(1, Inject4(AGENT_SINK2)),
12545
- _ts_param3(2, Optional2()),
12552
+ _ts_param3(2, Optional3()),
12546
12553
  _ts_param3(2, Inject4(AGENT_QUOTA_PROVIDER)),
12547
- _ts_param3(3, Optional2()),
12554
+ _ts_param3(3, Optional3()),
12548
12555
  _ts_param3(3, Inject4(AGENT_OPTIONS3)),
12549
- _ts_param3(4, Optional2()),
12556
+ _ts_param3(4, Optional3()),
12550
12557
  _ts_param3(4, Inject4(AGENT_ATTACHMENT_STAGING)),
12551
- _ts_param3(5, Optional2()),
12558
+ _ts_param3(5, Optional3()),
12552
12559
  _ts_param3(5, Inject4(AGENT_DEPS_FACTORY)),
12553
12560
  _ts_metadata3("design:type", Function),
12554
12561
  _ts_metadata3("design:paramtypes", [
@@ -12695,7 +12702,8 @@ var AgentService2 = class {
12695
12702
  options;
12696
12703
  queue;
12697
12704
  proposals;
12698
- constructor(runner, store, deps, staging, models, quotaProvider, options, queue, proposals) {
12705
+ contextAccessor;
12706
+ constructor(runner, store, deps, staging, models, quotaProvider, options, queue, proposals, contextAccessor) {
12699
12707
  this.runner = runner;
12700
12708
  this.store = store;
12701
12709
  this.deps = deps;
@@ -12705,6 +12713,58 @@ var AgentService2 = class {
12705
12713
  this.options = options;
12706
12714
  this.queue = queue;
12707
12715
  this.proposals = proposals;
12716
+ this.contextAccessor = contextAccessor;
12717
+ }
12718
+ /**
12719
+ * With tenancy on, the store must be able to tell a thread's tenant: fail the boot with the fix
12720
+ * rather than answer every thread read `404` at runtime. Tenancy enabled explicitly with no
12721
+ * context accessor to read the tenant from fails the boot too.
12722
+ */
12723
+ onApplicationBootstrap() {
12724
+ if (!this.tenancy().enabled) {
12725
+ const option = this.options?.tenancy;
12726
+ if (typeof option === "object" && option.enabled === true) {
12727
+ 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`.");
12728
+ }
12729
+ return;
12730
+ }
12731
+ const missing = [
12732
+ "tenantOf",
12733
+ "listThreadsForTenant"
12734
+ ].filter((method) => typeof this.store[method] !== "function");
12735
+ if (missing.length > 0) {
12736
+ 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\`.`);
12737
+ }
12738
+ }
12739
+ /**
12740
+ * The matching rule for a decision that comes from outside the thread's own actor (the console's
12741
+ * approvals inbox): with tenancy on, a tool call on a thread the request's context tenant may not
12742
+ * see is not found. A no-op with tenancy off.
12743
+ */
12744
+ async assertToolCallInRequestTenant(toolCallId2) {
12745
+ const filter = tenantRowFilter2(this.tenancy());
12746
+ if (filter === void 0) return;
12747
+ const row = typeof this.store.tenantOf === "function" ? await this.store.tenantOf({
12748
+ toolCallId: toolCallId2
12749
+ }) : null;
12750
+ if (row === null || !tenantRowVisible2(filter, row.tenantRef)) {
12751
+ throw new NotFoundException2(`tool call ${toolCallId2} not found`);
12752
+ }
12753
+ }
12754
+ /** The agent's tenancy, read per call: the context's switch can be flipped at any time. */
12755
+ tenancy() {
12756
+ return readTenancy2(this.options?.tenancy ?? "inherit", this.contextAccessor);
12757
+ }
12758
+ /**
12759
+ * The matching rule for one thread, run or tool call: with tenancy on, a row of another tenant
12760
+ * (or, for a request with a tenant, one with no tenant unless `nullRows: 'shared'`) is not found.
12761
+ * The request's tenant is `actor.tenantRef` (the resolver's, else the context's), else none.
12762
+ */
12763
+ async assertTenantVisible(actor, target, notFound) {
12764
+ const filter = tenantRowFilter2(this.tenancy(), actor.tenantRef);
12765
+ if (filter === void 0) return;
12766
+ const row = typeof this.store.tenantOf === "function" ? await this.store.tenantOf(target) : null;
12767
+ if (row === null || !tenantRowVisible2(filter, row.tenantRef)) throw notFound();
12708
12768
  }
12709
12769
  /**
12710
12770
  * Decide one independent proposal through the scoped proposal service — what the native
@@ -13442,6 +13502,9 @@ var AgentService2 = class {
13442
13502
  if (owner === null) {
13443
13503
  throw new RunNotActiveException(runId);
13444
13504
  }
13505
+ await this.assertTenantVisible(actor, {
13506
+ runId
13507
+ }, () => new RunNotActiveException(runId));
13445
13508
  if (owner !== actor.id) {
13446
13509
  throw new ForbiddenException2("run belongs to another actor");
13447
13510
  }
@@ -13464,8 +13527,15 @@ var AgentService2 = class {
13464
13527
  await this.assertOwnsActiveStream(actor, runId);
13465
13528
  return this.runner.cancel(runId);
13466
13529
  }
13467
- async listThreads(actorRef) {
13468
- const threads = await this.store.listThreads(actorRef);
13530
+ /**
13531
+ * The actor's threads. With tenancy on, only those the request's tenant may see: pass the
13532
+ * {@link Actor} so a `tenantRef` its resolver set is the tenant; a bare `actorRef` uses the
13533
+ * context's.
13534
+ */
13535
+ async listThreads(actor) {
13536
+ const actorRef = typeof actor === "string" ? actor : actor.id;
13537
+ const filter = tenantRowFilter2(this.tenancy(), typeof actor === "string" ? void 0 : actor.tenantRef);
13538
+ const threads = filter === void 0 ? await this.store.listThreads(actorRef) : typeof this.store.listThreadsForTenant === "function" ? await this.store.listThreadsForTenant(actorRef, filter) : [];
13469
13539
  return Promise.all(threads.map((thread) => this.toSummaryView(thread)));
13470
13540
  }
13471
13541
  async getThread(actor, threadId) {
@@ -13487,6 +13557,9 @@ var AgentService2 = class {
13487
13557
  if (await this.store.ownerOfThread(threadId) === null) {
13488
13558
  throw new NotFoundException2(`thread ${threadId} not found`);
13489
13559
  }
13560
+ await this.assertTenantVisible(actor, {
13561
+ threadId
13562
+ }, () => new NotFoundException2(`thread ${threadId} not found`));
13490
13563
  } else {
13491
13564
  await this.assertOwnsThread(actor, threadId);
13492
13565
  }
@@ -13789,6 +13862,9 @@ var AgentService2 = class {
13789
13862
  if (owner === null) {
13790
13863
  throw new NotFoundException2(`thread ${threadId} not found`);
13791
13864
  }
13865
+ await this.assertTenantVisible(actor, {
13866
+ threadId
13867
+ }, () => new NotFoundException2(`thread ${threadId} not found`));
13792
13868
  if (owner !== actor.id) {
13793
13869
  throw new ForbiddenException2("thread belongs to another actor");
13794
13870
  }
@@ -13803,6 +13879,9 @@ var AgentService2 = class {
13803
13879
  if (owner === null) {
13804
13880
  throw new NotFoundException2(`tool call ${toolCallId2} not found`);
13805
13881
  }
13882
+ await this.assertTenantVisible(actor, {
13883
+ toolCallId: toolCallId2
13884
+ }, () => new NotFoundException2(`tool call ${toolCallId2} not found`));
13806
13885
  if (owner !== actor.id) {
13807
13886
  throw new ForbiddenException2("tool call belongs to another actor");
13808
13887
  }
@@ -13844,6 +13923,9 @@ var AgentService2 = class {
13844
13923
  if (requesterRef === null) {
13845
13924
  throw new NotFoundException2(`tool call ${toolCallId2} not found`);
13846
13925
  }
13926
+ await this.assertTenantVisible(actor, {
13927
+ toolCallId: toolCallId2
13928
+ }, () => new NotFoundException2(`tool call ${toolCallId2} not found`));
13847
13929
  const allowed = await mayDecideApproval2(this.deps.forAgent().approvalPolicy, actor, {
13848
13930
  toolCallId: toolCallId2,
13849
13931
  approver,
@@ -13889,6 +13971,9 @@ var AgentService2 = class {
13889
13971
  if (owner === null) {
13890
13972
  throw new NotFoundException2(`no active run ${runId}`);
13891
13973
  }
13974
+ await this.assertTenantVisible(actor, {
13975
+ runId
13976
+ }, () => new NotFoundException2(`no active run ${runId}`));
13892
13977
  if (owner !== actor.id) {
13893
13978
  throw new ForbiddenException2("run belongs to another actor");
13894
13979
  }
@@ -13909,11 +13994,15 @@ var AgentService2 = class {
13909
13994
  * against nobody.
13910
13995
  */
13911
13996
  recordUsage(input, options = {}) {
13997
+ const tenantRef = input.tenantRef ?? contextTenantRef(this.tenancy());
13912
13998
  return recordAiUsage({
13913
13999
  store: this.store,
13914
14000
  quota: this.deps.forAgent().quota,
13915
14001
  day: utcDay(),
13916
- input,
14002
+ input: tenantRef !== void 0 && input.tenantRef === void 0 ? {
14003
+ ...input,
14004
+ tenantRef
14005
+ } : input,
13917
14006
  options,
13918
14007
  warn: /* @__PURE__ */ __name((message) => usageLogger.warn(message), "warn")
13919
14008
  });
@@ -13924,16 +14013,18 @@ AgentService2 = _ts_decorate5([
13924
14013
  _ts_param4(0, Inject5(AGENT_RUNNER)),
13925
14014
  _ts_param4(1, Inject5(AGENT_STORE4)),
13926
14015
  _ts_param4(2, Inject5(AGENT_DEPS_FACTORY2)),
13927
- _ts_param4(3, Optional3()),
14016
+ _ts_param4(3, Optional4()),
13928
14017
  _ts_param4(3, Inject5(AGENT_ATTACHMENT_STAGING2)),
13929
- _ts_param4(4, Optional3()),
14018
+ _ts_param4(4, Optional4()),
13930
14019
  _ts_param4(4, Inject5(AGENT_MODEL_CATALOG)),
13931
- _ts_param4(5, Optional3()),
14020
+ _ts_param4(5, Optional4()),
13932
14021
  _ts_param4(5, Inject5(AGENT_QUOTA_PROVIDER2)),
13933
- _ts_param4(6, Optional3()),
14022
+ _ts_param4(6, Optional4()),
13934
14023
  _ts_param4(6, Inject5(AGENT_OPTIONS4)),
13935
- _ts_param4(7, Optional3()),
13936
- _ts_param4(8, Optional3()),
14024
+ _ts_param4(7, Optional4()),
14025
+ _ts_param4(8, Optional4()),
14026
+ _ts_param4(9, Optional4()),
14027
+ _ts_param4(9, Inject5(CONTEXT_ACCESSOR2)),
13937
14028
  _ts_metadata4("design:type", Function),
13938
14029
  _ts_metadata4("design:paramtypes", [
13939
14030
  typeof AgentRunner === "undefined" ? Object : AgentRunner,
@@ -13944,12 +14035,13 @@ AgentService2 = _ts_decorate5([
13944
14035
  typeof QuotaProvider === "undefined" ? Object : QuotaProvider,
13945
14036
  typeof Pick === "undefined" ? Object : Pick,
13946
14037
  typeof ChatQueueService === "undefined" ? Object : ChatQueueService,
13947
- typeof ActionProposalService === "undefined" ? Object : ActionProposalService
14038
+ typeof ActionProposalService === "undefined" ? Object : ActionProposalService,
14039
+ Object
13948
14040
  ])
13949
14041
  ], AgentService2);
13950
14042
 
13951
14043
  // src/approval-port.adapter.ts
13952
- import { Injectable as Injectable5, NotImplementedException as NotImplementedException4, Optional as Optional4 } from "@nestjs/common";
14044
+ import { Injectable as Injectable5, NotImplementedException as NotImplementedException4, Optional as Optional5 } from "@nestjs/common";
13953
14045
  function _ts_decorate6(decorators, target, key, desc) {
13954
14046
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
13955
14047
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -14007,6 +14099,7 @@ var AgentApprovalPortAdapter = class {
14007
14099
  });
14008
14100
  }
14009
14101
  async approve(toolCallId2, opts) {
14102
+ await this.agent.assertToolCallInRequestTenant(toolCallId2);
14010
14103
  await this.agent.signalToolCall(toolCallId2, {
14011
14104
  approved: true,
14012
14105
  ...opts?.executedByRef !== void 0 ? {
@@ -14021,6 +14114,7 @@ var AgentApprovalPortAdapter = class {
14021
14114
  });
14022
14115
  }
14023
14116
  async reject(toolCallId2, opts) {
14117
+ await this.agent.assertToolCallInRequestTenant(toolCallId2);
14024
14118
  await this.agent.signalToolCall(toolCallId2, {
14025
14119
  approved: false,
14026
14120
  ...opts?.executedByRef !== void 0 ? {
@@ -14037,7 +14131,7 @@ var AgentApprovalPortAdapter = class {
14037
14131
  };
14038
14132
  AgentApprovalPortAdapter = _ts_decorate6([
14039
14133
  Injectable5(),
14040
- _ts_param5(1, Optional4()),
14134
+ _ts_param5(1, Optional5()),
14041
14135
  _ts_metadata5("design:type", Function),
14042
14136
  _ts_metadata5("design:paramtypes", [
14043
14137
  typeof AgentService2 === "undefined" ? Object : AgentService2,
@@ -14124,7 +14218,7 @@ AgentsController = _ts_decorate7([
14124
14218
 
14125
14219
  // src/controller/attachments.controller.ts
14126
14220
  import { AGENT_ACTOR_RESOLVER, AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING3, AGENT_OPTIONS as AGENT_OPTIONS5, CanAnyone as CanAnyone2 } from "@dudousxd/nestjs-agent-core";
14127
- import { BadRequestException as BadRequestException3, Controller as Controller2, Get as Get2, Inject as Inject7, NotImplementedException as NotImplementedException5, Optional as Optional5, PayloadTooLargeException as PayloadTooLargeException2, Post, Req, UnsupportedMediaTypeException as UnsupportedMediaTypeException2, UploadedFile, UseInterceptors } from "@nestjs/common";
14221
+ import { BadRequestException as BadRequestException3, Controller as Controller2, Get as Get2, Inject as Inject7, NotImplementedException as NotImplementedException5, Optional as Optional6, PayloadTooLargeException as PayloadTooLargeException2, Post, Req, UnsupportedMediaTypeException as UnsupportedMediaTypeException2, UploadedFile, UseInterceptors } from "@nestjs/common";
14128
14222
  import { FileInterceptor } from "@nestjs/platform-express";
14129
14223
  function _ts_decorate8(decorators, target, key, desc) {
14130
14224
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -14237,7 +14331,7 @@ AttachmentsController = _ts_decorate8([
14237
14331
  Controller2("attachments"),
14238
14332
  _ts_param7(0, Inject7(AGENT_OPTIONS5)),
14239
14333
  _ts_param7(1, Inject7(AGENT_ACTOR_RESOLVER)),
14240
- _ts_param7(3, Optional5()),
14334
+ _ts_param7(3, Optional6()),
14241
14335
  _ts_param7(3, Inject7(AGENT_ATTACHMENT_STAGING3)),
14242
14336
  _ts_metadata7("design:type", Function),
14243
14337
  _ts_metadata7("design:paramtypes", [
@@ -14558,7 +14652,7 @@ __name(parseCursor, "parseCursor");
14558
14652
 
14559
14653
  // src/controller/config.controller.ts
14560
14654
  import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER3, AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING4, AGENT_MODEL_CATALOG as AGENT_MODEL_CATALOG2, AGENT_OPTIONS as AGENT_OPTIONS6, CanAnyone as CanAnyone4 } from "@dudousxd/nestjs-agent-core";
14561
- import { Controller as Controller4, Get as Get4, Inject as Inject9, Optional as Optional6, Req as Req3 } from "@nestjs/common";
14655
+ import { Controller as Controller4, Get as Get4, Inject as Inject9, Optional as Optional7, Req as Req3 } from "@nestjs/common";
14562
14656
 
14563
14657
  // src/resolver/anonymous-actor-resolver.ts
14564
14658
  import { createHash, randomBytes } from "crypto";
@@ -14725,11 +14819,11 @@ ConfigController = _ts_decorate10([
14725
14819
  Controller4("config"),
14726
14820
  _ts_param9(0, Inject9(AGENT_OPTIONS6)),
14727
14821
  _ts_param9(1, Inject9(AGENT_ACTOR_RESOLVER3)),
14728
- _ts_param9(2, Optional6()),
14822
+ _ts_param9(2, Optional7()),
14729
14823
  _ts_param9(2, Inject9(AGENT_ATTACHMENT_STAGING4)),
14730
- _ts_param9(3, Optional6()),
14824
+ _ts_param9(3, Optional7()),
14731
14825
  _ts_param9(3, Inject9(AGENT_MODEL_CATALOG2)),
14732
- _ts_param9(4, Optional6()),
14826
+ _ts_param9(4, Optional7()),
14733
14827
  _ts_param9(4, Inject9(AGENT_GENUI)),
14734
14828
  _ts_metadata9("design:type", Function),
14735
14829
  _ts_metadata9("design:paramtypes", [
@@ -14743,7 +14837,7 @@ ConfigController = _ts_decorate10([
14743
14837
 
14744
14838
  // src/controller/memories.controller.ts
14745
14839
  import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER4, AGENT_MEMORY as AGENT_MEMORY2, CanAnyone as CanAnyone5, memoryForgetVerdict, offerMemories } from "@dudousxd/nestjs-agent-core";
14746
- import { Controller as Controller5, Delete, ForbiddenException as ForbiddenException3, Get as Get5, Inject as Inject10, NotFoundException as NotFoundException3, Optional as Optional7, Param as Param2, Query as Query2, Req as Req4 } from "@nestjs/common";
14840
+ import { Controller as Controller5, Delete, ForbiddenException as ForbiddenException3, Get as Get5, Inject as Inject10, NotFoundException as NotFoundException3, Optional as Optional8, Param as Param2, Query as Query2, Req as Req4 } from "@nestjs/common";
14747
14841
  function _ts_decorate11(decorators, target, key, desc) {
14748
14842
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
14749
14843
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -14868,7 +14962,7 @@ MemoriesController = _ts_decorate11([
14868
14962
  CanAnyone5(),
14869
14963
  Controller5("memories"),
14870
14964
  _ts_param10(0, Inject10(AGENT_ACTOR_RESOLVER4)),
14871
- _ts_param10(1, Optional7()),
14965
+ _ts_param10(1, Optional8()),
14872
14966
  _ts_param10(1, Inject10(AGENT_MEMORY2)),
14873
14967
  _ts_metadata10("design:type", Function),
14874
14968
  _ts_metadata10("design:paramtypes", [
@@ -15259,7 +15353,7 @@ QuotaController = _ts_decorate15([
15259
15353
 
15260
15354
  // src/controller/skills.controller.ts
15261
15355
  import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER9, AGENT_SKILLS as AGENT_SKILLS2, CanAnyone as CanAnyone10, offerSkills } from "@dudousxd/nestjs-agent-core";
15262
- import { Controller as Controller10, Get as Get9, Inject as Inject15, Optional as Optional8, Query as Query4, Req as Req9 } from "@nestjs/common";
15356
+ import { Controller as Controller10, Get as Get9, Inject as Inject15, Optional as Optional9, Query as Query4, Req as Req9 } from "@nestjs/common";
15263
15357
  function _ts_decorate16(decorators, target, key, desc) {
15264
15358
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
15265
15359
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -15323,7 +15417,7 @@ SkillsController = _ts_decorate16([
15323
15417
  CanAnyone10(),
15324
15418
  Controller10("skills"),
15325
15419
  _ts_param15(0, Inject15(AGENT_ACTOR_RESOLVER9)),
15326
- _ts_param15(1, Optional8()),
15420
+ _ts_param15(1, Optional9()),
15327
15421
  _ts_param15(1, Inject15(AGENT_SKILLS2)),
15328
15422
  _ts_metadata15("design:type", Function),
15329
15423
  _ts_metadata15("design:paramtypes", [
@@ -15373,7 +15467,7 @@ var ThreadsController = class {
15373
15467
  }
15374
15468
  async list(req) {
15375
15469
  const actor = await this.actorResolver.resolve(req);
15376
- return this.agent.listThreads(actor.id);
15470
+ return this.agent.listThreads(actor);
15377
15471
  }
15378
15472
  async detail(req, id) {
15379
15473
  const actor = await this.actorResolver.resolve(req);
@@ -16940,6 +17034,10 @@ var LedgerQuotaProvider = class {
16940
17034
  this.store = store;
16941
17035
  this.limits = limits;
16942
17036
  this.options = options;
17037
+ const per = options.per ?? "actor";
17038
+ if (per !== "actor" && typeof store.usageWindowsForTenant !== "function") {
17039
+ 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.`);
17040
+ }
16943
17041
  }
16944
17042
  async report(query) {
16945
17043
  const now = query.now ?? /* @__PURE__ */ new Date();
@@ -16947,7 +17045,16 @@ var LedgerQuotaProvider = class {
16947
17045
  const day = quotaPeriodRange("day", now);
16948
17046
  const month = quotaPeriodRange("month", now);
16949
17047
  const windows = [];
16950
- if (this.store.usageWindows !== void 0) {
17048
+ const per = this.options.per ?? "actor";
17049
+ const tenantRef = query.actor.tenantRef;
17050
+ if (per !== "actor" && typeof tenantRef === "string" && tenantRef !== "" && this.store.usageWindowsForTenant !== void 0) {
17051
+ const [dayUsed, monthUsed] = await this.store.usageWindowsForTenant(tenantRef, [
17052
+ day,
17053
+ month
17054
+ ], per === "actor-in-tenant" ? actorRef : void 0);
17055
+ windows.push(this.usedWindow("day", dayUsed, day.resetsAt));
17056
+ windows.push(this.usedWindow("month", monthUsed, month.resetsAt));
17057
+ } else if (this.store.usageWindows !== void 0) {
16951
17058
  const [dayUsed, monthUsed] = await this.store.usageWindows(actorRef, [
16952
17059
  day,
16953
17060
  month
@@ -17592,7 +17699,7 @@ NestAiModelsBinding = _ts_decorate24([
17592
17699
 
17593
17700
  // src/pricing-boot.service.ts
17594
17701
  import { AGENT_MODEL as AGENT_MODEL2, AGENT_OPTIONS as AGENT_OPTIONS9, AGENT_PRICING_STORE as AGENT_PRICING_STORE2, ensureModelPricing } from "@dudousxd/nestjs-agent-core";
17595
- import { Inject as Inject23, Injectable as Injectable11, Logger as Logger8, Optional as Optional9 } from "@nestjs/common";
17702
+ import { Inject as Inject23, Injectable as Injectable11, Logger as Logger8, Optional as Optional10 } from "@nestjs/common";
17596
17703
  function _ts_decorate25(decorators, target, key, desc) {
17597
17704
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
17598
17705
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -17677,9 +17784,9 @@ var PricingBootService = class {
17677
17784
  PricingBootService = _ts_decorate25([
17678
17785
  Injectable11(),
17679
17786
  _ts_param23(0, Inject23(AGENT_OPTIONS9)),
17680
- _ts_param23(1, Optional9()),
17787
+ _ts_param23(1, Optional10()),
17681
17788
  _ts_param23(1, Inject23(AGENT_MODEL2)),
17682
- _ts_param23(2, Optional9()),
17789
+ _ts_param23(2, Optional10()),
17683
17790
  _ts_param23(2, Inject23(AGENT_PRICING_STORE2)),
17684
17791
  _ts_metadata24("design:type", Function),
17685
17792
  _ts_metadata24("design:paramtypes", [
@@ -17987,9 +18094,22 @@ ActionProposalController = _ts_decorate27([
17987
18094
  // src/queue/chat-queue.token.ts
17988
18095
  var AGENT_CHAT_QUEUE = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:chat-queue");
17989
18096
 
18097
+ // src/resolver/tenant-filling-resolver.ts
18098
+ import { readTenancy as readTenancy3, withContextTenant } from "@dudousxd/nestjs-agent-core";
18099
+ function tenantFillingResolver(resolver, tenancy, contextAccessor) {
18100
+ if (tenancy === false) return resolver;
18101
+ const wrapper = Object.create(resolver);
18102
+ Object.defineProperty(wrapper, "resolve", {
18103
+ value: /* @__PURE__ */ __name(async (req) => withContextTenant(await resolver.resolve(req), readTenancy3(tenancy ?? "inherit", contextAccessor ?? void 0)), "value"),
18104
+ enumerable: false
18105
+ });
18106
+ return wrapper;
18107
+ }
18108
+ __name(tenantFillingResolver, "tenantFillingResolver");
18109
+
17990
18110
  // src/runner/inline-agent-runner.ts
17991
18111
  import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY6, AGENT_STORE as AGENT_STORE6, RUN_ENDED_BEFORE_TOOL_CALL, RunCancelledError, agentFailureCode, agentRunContext, encodeStreamEvent as encodeStreamEvent2, publishAgentRunCancelled, publishAgentRunFailed, releaseThreadRun, runAgentLoop, runDurationMs, runEndTimings, settleAll, settleUnsettledDelegation, streamFailure as streamFailure2 } from "@dudousxd/nestjs-agent-core";
17992
- import { Inject as Inject26, Injectable as Injectable13, Logger as Logger10, Optional as Optional10 } from "@nestjs/common";
18112
+ import { Inject as Inject26, Injectable as Injectable13, Logger as Logger10, Optional as Optional11 } from "@nestjs/common";
17993
18113
  function _ts_decorate28(decorators, target, key, desc) {
17994
18114
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
17995
18115
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -18536,7 +18656,7 @@ InlineAgentRunner = _ts_decorate28([
18536
18656
  Injectable13(),
18537
18657
  _ts_param26(0, Inject26(AGENT_DEPS_FACTORY6)),
18538
18658
  _ts_param26(1, Inject26(AGENT_STORE6)),
18539
- _ts_param26(2, Optional10()),
18659
+ _ts_param26(2, Optional11()),
18540
18660
  _ts_metadata27("design:type", Function),
18541
18661
  _ts_metadata27("design:paramtypes", [
18542
18662
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
@@ -18761,13 +18881,20 @@ function sharedProviders(durable, engine) {
18761
18881
  },
18762
18882
  {
18763
18883
  provide: AGENT_ACTOR_RESOLVER14,
18764
- useFactory: /* @__PURE__ */ __name((options) => {
18765
- if (options.actorResolver !== void 0) return options.actorResolver;
18884
+ // With tenancy on, an actor the resolver left without a `tenantRef` gets the context tenant's.
18885
+ useFactory: /* @__PURE__ */ __name((options, contextAccessor) => {
18886
+ if (options.actorResolver !== void 0) {
18887
+ return tenantFillingResolver(options.actorResolver, options.tenancy, contextAccessor);
18888
+ }
18766
18889
  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.");
18767
- return new AnonymousActorResolver();
18890
+ return tenantFillingResolver(new AnonymousActorResolver(), options.tenancy, contextAccessor);
18768
18891
  }, "useFactory"),
18769
18892
  inject: [
18770
- AGENT_OPTIONS11
18893
+ AGENT_OPTIONS11,
18894
+ {
18895
+ token: CONTEXT_ACCESSOR3,
18896
+ optional: true
18897
+ }
18771
18898
  ]
18772
18899
  },
18773
18900
  // No `model` (and no `engine`): the turns run on `@nestjs/ai`'s `AiModule` models.
@@ -18790,6 +18917,9 @@ function sharedProviders(durable, engine) {
18790
18917
  } : {},
18791
18918
  ...o.quota?.countEstimatedCost !== void 0 ? {
18792
18919
  countEstimatedCost: o.quota.countEstimatedCost
18920
+ } : {},
18921
+ ...o.quota?.per !== void 0 ? {
18922
+ per: o.quota.per
18793
18923
  } : {}
18794
18924
  }), "useFactory"),
18795
18925
  inject: [
@@ -19057,7 +19187,7 @@ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER15, AGENT_ATTACHMENT_STAGIN
19057
19187
  import { A2UI_LEGACY_BASIC_CATALOG_ID, negotiateA2uiCatalog, readAgUiA2uiCatalogIds } from "@dudousxd/nestjs-agent-core/a2ui";
19058
19188
  import { AG_UI_CUSTOM, actionProposalDecisionEvents, agUiEvents, agUiFramesFromNdjson, agUiSse, parseRunInput, planResume, readAnswersPayload, readApprovalPayload, readContext, readForwardedProps, readUserTurn } from "@dudousxd/nestjs-agent-core/ag-ui";
19059
19189
  import { uiActionText } from "@dudousxd/nestjs-agent-core/genui";
19060
- import { BadRequestException as BadRequestException8, Body as Body7, Controller as Controller15, ForbiddenException as ForbiddenException5, HttpCode as HttpCode2, Inject as Inject27, Optional as Optional11, Post as Post8, Req as Req14, Res as Res3 } from "@nestjs/common";
19190
+ import { BadRequestException as BadRequestException8, Body as Body7, Controller as Controller15, ForbiddenException as ForbiddenException5, HttpCode as HttpCode2, Inject as Inject27, Optional as Optional12, Post as Post8, Req as Req14, Res as Res3 } from "@nestjs/common";
19061
19191
  function _ts_decorate30(decorators, target, key, desc) {
19062
19192
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19063
19193
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -19484,9 +19614,9 @@ function agUiAdapter(options = {}) {
19484
19614
  _ts_param27(0, Inject27(AgentService2)),
19485
19615
  _ts_param27(1, Inject27(AGENT_ACTOR_RESOLVER15)),
19486
19616
  _ts_param27(2, Inject27(AGENT_OPTIONS12)),
19487
- _ts_param27(3, Optional11()),
19617
+ _ts_param27(3, Optional12()),
19488
19618
  _ts_param27(3, Inject27(AGENT_ATTACHMENT_STAGING5)),
19489
- _ts_param27(4, Optional11()),
19619
+ _ts_param27(4, Optional12()),
19490
19620
  _ts_param27(4, Inject27(GENUI_CATALOG)),
19491
19621
  _ts_metadata28("design:type", Function),
19492
19622
  _ts_metadata28("design:paramtypes", [
@@ -19519,7 +19649,7 @@ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER16, CanAnyone as CanAnyone1
19519
19649
  import { A2UI_APPROVE_ACTION, A2UI_REJECT_ACTION, A2uiProjector, a2uiThreadReplay, negotiateA2uiCatalog as negotiateA2uiCatalog2, readA2uiAction, readA2uiClientCapabilities } from "@dudousxd/nestjs-agent-core/a2ui";
19520
19650
  import { agUiEvents as agUiEvents2, agUiFramesFromNdjson as agUiFramesFromNdjson2, decodeInterruptId } from "@dudousxd/nestjs-agent-core/ag-ui";
19521
19651
  import { uiActionText as uiActionText2, validateUiCapabilities as validateUiCapabilities2 } from "@dudousxd/nestjs-agent-core/genui";
19522
- import { BadRequestException as BadRequestException9, Body as Body8, Controller as Controller16, ForbiddenException as ForbiddenException6, Get as Get13, HttpCode as HttpCode3, Inject as Inject28, Optional as Optional12, Param as Param7, Post as Post9, Query as Query7, Req as Req15, Res as Res4 } from "@nestjs/common";
19652
+ import { BadRequestException as BadRequestException9, Body as Body8, Controller as Controller16, ForbiddenException as ForbiddenException6, Get as Get13, HttpCode as HttpCode3, Inject as Inject28, Optional as Optional13, Param as Param7, Post as Post9, Query as Query7, Req as Req15, Res as Res4 } from "@nestjs/common";
19523
19653
  function _ts_decorate31(decorators, target, key, desc) {
19524
19654
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19525
19655
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -19842,7 +19972,7 @@ function a2uiAdapter(options = {}) {
19842
19972
  Controller16(),
19843
19973
  _ts_param28(0, Inject28(AGENT_SERVICE)),
19844
19974
  _ts_param28(1, Inject28(AGENT_ACTOR_RESOLVER16)),
19845
- _ts_param28(2, Optional12()),
19975
+ _ts_param28(2, Optional13()),
19846
19976
  _ts_param28(2, Inject28(GENUI_CATALOG)),
19847
19977
  _ts_metadata29("design:type", Function),
19848
19978
  _ts_metadata29("design:paramtypes", [