@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.
@@ -2,7 +2,8 @@ import { A2uiStreamOptions, a2uiThreadReplay } from '@dudousxd/nestjs-agent-core
2
2
  import { AgentAttachmentConfig, AttachmentStagingStore, AgentStore, Actor, ListActionProposals, ActionProposalView, ActionProposalMutationView, TextActionProposalVocabulary, AgentRunner, ModelCatalog, QuotaProvider, ActionApprovalMode, MessageAttachment, QuotaReport, ModelCatalogView, AgentHostContext, AttachmentRef, PageContext, ChatQueueState, SubscribeOptions, HumanReply, ThreadSummary, ThreadDetail, UpdateThreadInput, MessageFeedbackValue, MessageFeedback, StagedAttachment, AiUsageInput, AiUsageOptions, AiUsageResult, ActorResolver } from '@dudousxd/nestjs-agent-core';
3
3
  import { Request, Response } from 'express';
4
4
  import { UiCapabilities } from '@dudousxd/nestjs-agent-core/genui';
5
- import { b as AgentModuleOptions, A as AgentDepsFactory, C as ChatQueueService, d as AgentProtocolAdapter } from './chat-queue.service-C49HIuEV.cjs';
5
+ import { OnApplicationBootstrap } from '@nestjs/common';
6
+ import { b as AgentModuleOptions, A as AgentDepsFactory, C as ChatQueueService, d as AgentProtocolAdapter } from './chat-queue.service-MYNBAY3P.js';
6
7
 
7
8
  /** Default per-file size cap (20 MiB). */
8
9
  declare const DEFAULT_MAX_ATTACHMENT_BYTES: number;
@@ -21,7 +22,8 @@ declare function attachmentLimits(options: Pick<AgentModuleOptions, 'attachments
21
22
  declare class ActionProposalService {
22
23
  private readonly store;
23
24
  private readonly options;
24
- constructor(store: AgentStore, options: Pick<AgentModuleOptions, 'approvalPolicy' | 'actionProposalText'>);
25
+ private readonly contextAccessor?;
26
+ constructor(store: AgentStore, options: Pick<AgentModuleOptions, 'approvalPolicy' | 'actionProposalText' | 'tenancy'>, contextAccessor?: unknown | undefined);
25
27
  /** The words a text decision is made of, and what the agent answers — English unless configured. */
26
28
  private readonly vocabulary;
27
29
  private readonly replies;
@@ -188,7 +190,7 @@ interface ThreadModelReader {
188
190
  modelForThread(threadId: string): Promise<string | null>;
189
191
  }
190
192
  /** The orchestration facade the controllers call. */
191
- declare class AgentService {
193
+ declare class AgentService implements OnApplicationBootstrap {
192
194
  private readonly runner;
193
195
  private readonly store;
194
196
  private readonly deps;
@@ -198,7 +200,28 @@ declare class AgentService {
198
200
  private readonly options?;
199
201
  private readonly queue?;
200
202
  private readonly proposals?;
201
- constructor(runner: AgentRunner, store: AgentStore, deps: AgentDepsFactory, staging?: AttachmentStagingStore | undefined, models?: ModelCatalog | undefined, quotaProvider?: QuotaProvider | undefined, options?: Pick<AgentModuleOptions, "quota" | "actionApprovalMode" | "attachments"> | undefined, queue?: ChatQueueService | undefined, proposals?: ActionProposalService | undefined);
203
+ private readonly contextAccessor?;
204
+ constructor(runner: AgentRunner, store: AgentStore, deps: AgentDepsFactory, staging?: AttachmentStagingStore | undefined, models?: ModelCatalog | undefined, quotaProvider?: QuotaProvider | undefined, options?: Pick<AgentModuleOptions, "quota" | "actionApprovalMode" | "attachments" | "tenancy"> | undefined, queue?: ChatQueueService | undefined, proposals?: ActionProposalService | undefined, contextAccessor?: unknown | undefined);
205
+ /**
206
+ * With tenancy on, the store must be able to tell a thread's tenant: fail the boot with the fix
207
+ * rather than answer every thread read `404` at runtime. Tenancy enabled explicitly with no
208
+ * context accessor to read the tenant from fails the boot too.
209
+ */
210
+ onApplicationBootstrap(): void;
211
+ /**
212
+ * The matching rule for a decision that comes from outside the thread's own actor (the console's
213
+ * approvals inbox): with tenancy on, a tool call on a thread the request's context tenant may not
214
+ * see is not found. A no-op with tenancy off.
215
+ */
216
+ assertToolCallInRequestTenant(toolCallId: string): Promise<void>;
217
+ /** The agent's tenancy, read per call: the context's switch can be flipped at any time. */
218
+ private tenancy;
219
+ /**
220
+ * The matching rule for one thread, run or tool call: with tenancy on, a row of another tenant
221
+ * (or, for a request with a tenant, one with no tenant unless `nullRows: 'shared'`) is not found.
222
+ * The request's tenant is `actor.tenantRef` (the resolver's, else the context's), else none.
223
+ */
224
+ private assertTenantVisible;
202
225
  /**
203
226
  * Decide one independent proposal through the scoped proposal service — what the native
204
227
  * `action-proposals/:id/approve|reject` routes call — and the reply to show for it. `404` when
@@ -443,7 +466,12 @@ declare class AgentService {
443
466
  /** Everything {@link answer} checks before it signals, without signalling — see {@link checkDecision}. */
444
467
  checkAnswer(actor: Actor, toolCallId: string, answers: Record<string, string[]>): Promise<void>;
445
468
  cancel(actor: Actor, runId: string): Promise<void>;
446
- listThreads(actorRef: string): Promise<ThreadSummary[]>;
469
+ /**
470
+ * The actor's threads. With tenancy on, only those the request's tenant may see: pass the
471
+ * {@link Actor} so a `tenantRef` its resolver set is the tenant; a bare `actorRef` uses the
472
+ * context's.
473
+ */
474
+ listThreads(actor: Actor | string): Promise<ThreadSummary[]>;
447
475
  getThread(actor: Actor, threadId: string): Promise<ThreadDetail | null>;
448
476
  deleteThread(actor: Actor, threadId: string): Promise<void>;
449
477
  /**
@@ -2,7 +2,8 @@ import { A2uiStreamOptions, a2uiThreadReplay } from '@dudousxd/nestjs-agent-core
2
2
  import { AgentAttachmentConfig, AttachmentStagingStore, AgentStore, Actor, ListActionProposals, ActionProposalView, ActionProposalMutationView, TextActionProposalVocabulary, AgentRunner, ModelCatalog, QuotaProvider, ActionApprovalMode, MessageAttachment, QuotaReport, ModelCatalogView, AgentHostContext, AttachmentRef, PageContext, ChatQueueState, SubscribeOptions, HumanReply, ThreadSummary, ThreadDetail, UpdateThreadInput, MessageFeedbackValue, MessageFeedback, StagedAttachment, AiUsageInput, AiUsageOptions, AiUsageResult, ActorResolver } from '@dudousxd/nestjs-agent-core';
3
3
  import { Request, Response } from 'express';
4
4
  import { UiCapabilities } from '@dudousxd/nestjs-agent-core/genui';
5
- import { b as AgentModuleOptions, A as AgentDepsFactory, C as ChatQueueService, d as AgentProtocolAdapter } from './chat-queue.service-BjPCw4Pf.js';
5
+ import { OnApplicationBootstrap } from '@nestjs/common';
6
+ import { b as AgentModuleOptions, A as AgentDepsFactory, C as ChatQueueService, d as AgentProtocolAdapter } from './chat-queue.service-OY6mUgB9.cjs';
6
7
 
7
8
  /** Default per-file size cap (20 MiB). */
8
9
  declare const DEFAULT_MAX_ATTACHMENT_BYTES: number;
@@ -21,7 +22,8 @@ declare function attachmentLimits(options: Pick<AgentModuleOptions, 'attachments
21
22
  declare class ActionProposalService {
22
23
  private readonly store;
23
24
  private readonly options;
24
- constructor(store: AgentStore, options: Pick<AgentModuleOptions, 'approvalPolicy' | 'actionProposalText'>);
25
+ private readonly contextAccessor?;
26
+ constructor(store: AgentStore, options: Pick<AgentModuleOptions, 'approvalPolicy' | 'actionProposalText' | 'tenancy'>, contextAccessor?: unknown | undefined);
25
27
  /** The words a text decision is made of, and what the agent answers — English unless configured. */
26
28
  private readonly vocabulary;
27
29
  private readonly replies;
@@ -188,7 +190,7 @@ interface ThreadModelReader {
188
190
  modelForThread(threadId: string): Promise<string | null>;
189
191
  }
190
192
  /** The orchestration facade the controllers call. */
191
- declare class AgentService {
193
+ declare class AgentService implements OnApplicationBootstrap {
192
194
  private readonly runner;
193
195
  private readonly store;
194
196
  private readonly deps;
@@ -198,7 +200,28 @@ declare class AgentService {
198
200
  private readonly options?;
199
201
  private readonly queue?;
200
202
  private readonly proposals?;
201
- constructor(runner: AgentRunner, store: AgentStore, deps: AgentDepsFactory, staging?: AttachmentStagingStore | undefined, models?: ModelCatalog | undefined, quotaProvider?: QuotaProvider | undefined, options?: Pick<AgentModuleOptions, "quota" | "actionApprovalMode" | "attachments"> | undefined, queue?: ChatQueueService | undefined, proposals?: ActionProposalService | undefined);
203
+ private readonly contextAccessor?;
204
+ constructor(runner: AgentRunner, store: AgentStore, deps: AgentDepsFactory, staging?: AttachmentStagingStore | undefined, models?: ModelCatalog | undefined, quotaProvider?: QuotaProvider | undefined, options?: Pick<AgentModuleOptions, "quota" | "actionApprovalMode" | "attachments" | "tenancy"> | undefined, queue?: ChatQueueService | undefined, proposals?: ActionProposalService | undefined, contextAccessor?: unknown | undefined);
205
+ /**
206
+ * With tenancy on, the store must be able to tell a thread's tenant: fail the boot with the fix
207
+ * rather than answer every thread read `404` at runtime. Tenancy enabled explicitly with no
208
+ * context accessor to read the tenant from fails the boot too.
209
+ */
210
+ onApplicationBootstrap(): void;
211
+ /**
212
+ * The matching rule for a decision that comes from outside the thread's own actor (the console's
213
+ * approvals inbox): with tenancy on, a tool call on a thread the request's context tenant may not
214
+ * see is not found. A no-op with tenancy off.
215
+ */
216
+ assertToolCallInRequestTenant(toolCallId: string): Promise<void>;
217
+ /** The agent's tenancy, read per call: the context's switch can be flipped at any time. */
218
+ private tenancy;
219
+ /**
220
+ * The matching rule for one thread, run or tool call: with tenancy on, a row of another tenant
221
+ * (or, for a request with a tenant, one with no tenant unless `nullRows: 'shared'`) is not found.
222
+ * The request's tenant is `actor.tenantRef` (the resolver's, else the context's), else none.
223
+ */
224
+ private assertTenantVisible;
202
225
  /**
203
226
  * Decide one independent proposal through the scoped proposal service — what the native
204
227
  * `action-proposals/:id/approve|reject` routes call — and the reply to show for it. `404` when
@@ -443,7 +466,12 @@ declare class AgentService {
443
466
  /** Everything {@link answer} checks before it signals, without signalling — see {@link checkDecision}. */
444
467
  checkAnswer(actor: Actor, toolCallId: string, answers: Record<string, string[]>): Promise<void>;
445
468
  cancel(actor: Actor, runId: string): Promise<void>;
446
- listThreads(actorRef: string): Promise<ThreadSummary[]>;
469
+ /**
470
+ * The actor's threads. With tenancy on, only those the request's tenant may see: pass the
471
+ * {@link Actor} so a `tenantRef` its resolver set is the tenant; a bare `actorRef` uses the
472
+ * context's.
473
+ */
474
+ listThreads(actor: Actor | string): Promise<ThreadSummary[]>;
447
475
  getThread(actor: Actor, threadId: string): Promise<ThreadDetail | null>;
448
476
  deleteThread(actor: Actor, threadId: string): Promise<void>;
449
477
  /**