@dudousxd/nestjs-agent 1.19.2 → 1.20.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,7 +1,7 @@
1
1
  import { DynamicModule, Type, OnApplicationBootstrap, OnModuleInit, ConflictException } from '@nestjs/common';
2
- import { b as AgentModuleOptions, c as AgentModuleAsyncOptions, A as AgentDepsFactory, C as ChatQueueService, d as AgentProtocolAdapter, e as AgentSkillsOptions } from './chat-queue.service-CKZkjlMK.cjs';
3
- export { f as AGENT_TOOL_BRAND, g as AgentAttachmentsOptions, h as AgentDeps, i as AgentMemoryOptions, a as AgentSurface, F as FunctionalTool, L as LedgerQuotaProvider, Q as QueuePlan, j as QueueSettleOutcome, k as QueuedTurn, l as QueuedTurnStarter, m as QuotaLimits, n as QuotaWindowLimits, o as delegateToolName, p as provideAgentTool, q as provideAgentTools, u as utcDay } from './chat-queue.service-CKZkjlMK.cjs';
4
- import { AgentRunner, AgentStore, AttachmentStagingStore, ModelCatalog, QuotaProvider, Actor, QuotaReport, ModelCatalogView, AttachmentRef, PageContext, ChatQueueState, HumanReply, ThreadSummary, ThreadDetail, UpdateThreadInput, MessageFeedbackValue, MessageFeedback, StagedAttachment, ActorResolver, AgentApprovalPort, MessageAttachment, AgentAttachmentConfig, AgentClientConfig, ToolPresentation, AgentHistoryWindow, AgentIntake, SkillContext, ToolRegistry, AgentRegistry, PromptContributor, SkillsConfig, SkillCatalogEntry, ToolCatalogEntry, MemoryConfig, MemoryDigestEntry, SkillProvider, AgentRunInput, AgentRunStartOptions, TokenStreamSink, SinkWriter } from '@dudousxd/nestjs-agent-core';
2
+ import { b as AgentModuleOptions, c as AgentModuleAsyncOptions, A as AgentDepsFactory, C as ChatQueueService, d as AgentProtocolAdapter, e as AgentSkillsOptions } from './chat-queue.service-C0hr7dqx.cjs';
3
+ export { f as AGENT_TOOL_BRAND, g as AgentAttachmentsOptions, h as AgentDeps, i as AgentMemoryOptions, a as AgentSurface, F as FunctionalTool, L as LedgerQuotaProvider, Q as QueuePlan, j as QueueSettleOutcome, k as QueuedTurn, l as QueuedTurnStarter, m as QuotaLimits, n as QuotaWindowLimits, o as delegateToolName, p as provideAgentTool, q as provideAgentTools, u as utcDay } from './chat-queue.service-C0hr7dqx.cjs';
4
+ import { AgentRunner, AgentStore, AttachmentStagingStore, ModelCatalog, QuotaProvider, Actor, QuotaReport, ModelCatalogView, AttachmentRef, PageContext, ChatQueueState, HumanReply, ThreadSummary, ThreadDetail, UpdateThreadInput, MessageFeedbackValue, MessageFeedback, StagedAttachment, ActorResolver, AgentApprovalPort, MessageAttachment, AgentAttachmentConfig, AgentClientConfig, ToolPresentation, AgentHistoryWindow, AgentIntake, Persona, SkillContext, ToolRegistry, AgentRegistry, PromptContributor, SkillsConfig, SkillCatalogEntry, ToolCatalogEntry, MemoryConfig, MemoryDigestEntry, SkillProvider, AgentRunInput, AgentRunStartOptions, TokenStreamSink, SinkWriter } from '@dudousxd/nestjs-agent-core';
5
5
  export * from '@dudousxd/nestjs-agent-core';
6
6
  import { Request, Response } from 'express';
7
7
  import { StandardSchemaV1 } from '@standard-schema/spec';
@@ -45,6 +45,12 @@ interface ChatParams {
45
45
  message: string;
46
46
  threadId?: string;
47
47
  agentName?: string;
48
+ /**
49
+ * Run this turn under one of the agent's personas (`@Agent({ personas })`), and pin it on the
50
+ * thread so later sends that name none keep it. Refused (400 `persona_not_found`) unless the agent
51
+ * declares it. Omitted → the thread's pinned persona, else the agent's `defaultPersona`, else none.
52
+ */
53
+ personaId?: string;
48
54
  /**
49
55
  * Files attached to this message (image/PDF) for a vision-capable model, named by the `mediaId`
50
56
  * the upload returned. Only the id is read: the url, content type and name are resolved from the
@@ -293,6 +299,13 @@ declare class AgentService {
293
299
  * dropping the field.
294
300
  */
295
301
  updateThread(actor: Actor, threadId: string, patch: UpdateThreadInput): Promise<void>;
302
+ /**
303
+ * The persona this send runs under — see {@link AgentDepsFactory.resolvePersona}. The thread's
304
+ * pinned persona is read only when the send names none AND the agent has personas to pick from.
305
+ */
306
+ private resolvePersona;
307
+ /** Pin `persona` on the thread when it is not already — a no-op on a store that cannot. */
308
+ private pinThreadPersona;
296
309
  private validateTitle;
297
310
  /**
298
311
  * Agent-selection precedence for a `chat()` call with no explicit `agentName`: the thread's own
@@ -492,6 +505,19 @@ declare class AgentApprovalPortAdapter implements AgentApprovalPort {
492
505
  }): Promise<void>;
493
506
  }
494
507
 
508
+ /**
509
+ * A store that can answer a thread's pinned persona on its own, without materializing the thread —
510
+ * probed structurally, like `ThreadDefaultAgentReader`.
511
+ */
512
+ interface ThreadPersonaReader {
513
+ personaForThread(threadId: string): Promise<string | null>;
514
+ }
515
+ /**
516
+ * The thread's pinned persona: one column when the store projects it ({@link ThreadPersonaReader}),
517
+ * else through the full read.
518
+ */
519
+ declare function threadPersona(store: AgentStore, threadId: string): Promise<string | null>;
520
+
495
521
  /**
496
522
  * How many entries `GET /agent/attachments` returns. Fixed rather than caller-supplied: this route
497
523
  * exists so a composer can show the files someone has uploaded, and a host that needs real paging
@@ -744,6 +770,20 @@ interface AgentOptions {
744
770
  * module-wide setting.
745
771
  */
746
772
  ask?: boolean;
773
+ /**
774
+ * Named variants of THIS agent — a prompt and, optionally, a narrower tool allow-list — that a
775
+ * caller picks per send (`POST <base>/chat { persona }`) and that pin onto the thread. Everything
776
+ * else (model, access rules, handoffs, history) stays this agent's; a variant that needs those to
777
+ * differ is another `@Agent`.
778
+ *
779
+ * A persona's `systemPrompt` is static data. For a prompt built from injected services, leave it
780
+ * out and branch on `ctx.persona` in this class's `@SystemPrompt()` method instead.
781
+ *
782
+ * Omit → no personas, and nothing about a turn changes.
783
+ */
784
+ personas?: Persona[];
785
+ /** The persona a send runs under when neither it nor its thread names one. Omit → none. */
786
+ defaultPersona?: string;
747
787
  }
748
788
  declare const AGENT_METADATA: unique symbol;
749
789
  /** Marks a provider class as an agent. See {@link AgentOptions}. */
@@ -849,6 +889,12 @@ declare class AgentDiscoveryService implements OnModuleInit {
849
889
  onModuleInit(): void;
850
890
  /** Build the internal {@link AgentDefinition} from an `@Agent` instance and its options. */
851
891
  private definitionFrom;
892
+ /**
893
+ * Refuse to boot on a persona declaration that could only fail later, per request: a default that
894
+ * names no persona, an id declared twice, an alias two personas claim, or an alias that is a real
895
+ * agent's name (which would never be reached — a registered agent always wins).
896
+ */
897
+ private assertPersonas;
852
898
  /**
853
899
  * Resolve each handoff entry to an {@link AgentDelegation} — its target's registered name, plus
854
900
  * whether that edge detaches (skipping non-agent classes). A bare name is kept for a plain edge
@@ -1288,4 +1334,4 @@ declare class RunNotActiveException extends ConflictException {
1288
1334
  constructor(runId: string);
1289
1335
  }
1290
1336
 
1291
- export { AGENT_CHAT_QUEUE, AGENT_METADATA, AI_TOOL_METADATA, ATTACHMENT_PAGE_SIZE, type AgUiAdapterOptions, AgUiRunHandler, Agent, AgentApprovalPortAdapter, AgentDepsFactory, AgentDiscoveryService, AgentModule, AgentModuleAsyncOptions, AgentModuleOptions, type AgentOptions, AgentProtocolAdapter, AgentService, AgentSkillsOptions, AiTool, AiToolDiscoveryService, type AiToolOptions, type AnonymousActorOptions, AnonymousActorResolver, type AttachmentLimits, AttachmentsController, type ChatParams, ChatQueueService, type ChatSendMode, type ChatSendResult, ConfigController, DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, DEFAULT_MAX_ATTACHMENT_BYTES, type DeclaredSkill, HeaderActorResolver, InProcessTokenStreamSink, InlineAgentRunner, MAX_ATTACHMENTS_PER_MESSAGE, MemoriesController, MessagesController, ModelsController, QueueController, type QueuedSend, type RequestUserMapper, type ResolvedAiToolOptions, RunNotActiveException, SKILL_METADATA, SYSTEM_PROMPT_CONTRIBUTOR_METADATA, SYSTEM_PROMPT_METADATA, Skill, type SkillBody, SkillDiscoveryService, type SkillOptions, SkillsController, SystemPrompt, SystemPromptContributor, type ThreadDefaultAgentReader, type ThreadModelReader, ToolsController, agUiAdapter, attachmentLimits, declaredSkillProvider, defaultRequestUserMapper, readAgentMetadata, readAiToolMetadata, readSkillMetadata, requestUserActorResolver, resolveSkillsConfig, skillScope, toolNameFromClass };
1337
+ export { AGENT_CHAT_QUEUE, AGENT_METADATA, AI_TOOL_METADATA, ATTACHMENT_PAGE_SIZE, type AgUiAdapterOptions, AgUiRunHandler, Agent, AgentApprovalPortAdapter, AgentDepsFactory, AgentDiscoveryService, AgentModule, AgentModuleAsyncOptions, AgentModuleOptions, type AgentOptions, AgentProtocolAdapter, AgentService, AgentSkillsOptions, AiTool, AiToolDiscoveryService, type AiToolOptions, type AnonymousActorOptions, AnonymousActorResolver, type AttachmentLimits, AttachmentsController, type ChatParams, ChatQueueService, type ChatSendMode, type ChatSendResult, ConfigController, DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, DEFAULT_MAX_ATTACHMENT_BYTES, type DeclaredSkill, HeaderActorResolver, InProcessTokenStreamSink, InlineAgentRunner, MAX_ATTACHMENTS_PER_MESSAGE, MemoriesController, MessagesController, ModelsController, QueueController, type QueuedSend, type RequestUserMapper, type ResolvedAiToolOptions, RunNotActiveException, SKILL_METADATA, SYSTEM_PROMPT_CONTRIBUTOR_METADATA, SYSTEM_PROMPT_METADATA, Skill, type SkillBody, SkillDiscoveryService, type SkillOptions, SkillsController, SystemPrompt, SystemPromptContributor, type ThreadDefaultAgentReader, type ThreadModelReader, type ThreadPersonaReader, ToolsController, agUiAdapter, attachmentLimits, declaredSkillProvider, defaultRequestUserMapper, readAgentMetadata, readAiToolMetadata, readSkillMetadata, requestUserActorResolver, resolveSkillsConfig, skillScope, threadPersona, toolNameFromClass };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { DynamicModule, Type, OnApplicationBootstrap, OnModuleInit, ConflictException } from '@nestjs/common';
2
- import { b as AgentModuleOptions, c as AgentModuleAsyncOptions, A as AgentDepsFactory, C as ChatQueueService, d as AgentProtocolAdapter, e as AgentSkillsOptions } from './chat-queue.service-CKZkjlMK.js';
3
- export { f as AGENT_TOOL_BRAND, g as AgentAttachmentsOptions, h as AgentDeps, i as AgentMemoryOptions, a as AgentSurface, F as FunctionalTool, L as LedgerQuotaProvider, Q as QueuePlan, j as QueueSettleOutcome, k as QueuedTurn, l as QueuedTurnStarter, m as QuotaLimits, n as QuotaWindowLimits, o as delegateToolName, p as provideAgentTool, q as provideAgentTools, u as utcDay } from './chat-queue.service-CKZkjlMK.js';
4
- import { AgentRunner, AgentStore, AttachmentStagingStore, ModelCatalog, QuotaProvider, Actor, QuotaReport, ModelCatalogView, AttachmentRef, PageContext, ChatQueueState, HumanReply, ThreadSummary, ThreadDetail, UpdateThreadInput, MessageFeedbackValue, MessageFeedback, StagedAttachment, ActorResolver, AgentApprovalPort, MessageAttachment, AgentAttachmentConfig, AgentClientConfig, ToolPresentation, AgentHistoryWindow, AgentIntake, SkillContext, ToolRegistry, AgentRegistry, PromptContributor, SkillsConfig, SkillCatalogEntry, ToolCatalogEntry, MemoryConfig, MemoryDigestEntry, SkillProvider, AgentRunInput, AgentRunStartOptions, TokenStreamSink, SinkWriter } from '@dudousxd/nestjs-agent-core';
2
+ import { b as AgentModuleOptions, c as AgentModuleAsyncOptions, A as AgentDepsFactory, C as ChatQueueService, d as AgentProtocolAdapter, e as AgentSkillsOptions } from './chat-queue.service-C0hr7dqx.js';
3
+ export { f as AGENT_TOOL_BRAND, g as AgentAttachmentsOptions, h as AgentDeps, i as AgentMemoryOptions, a as AgentSurface, F as FunctionalTool, L as LedgerQuotaProvider, Q as QueuePlan, j as QueueSettleOutcome, k as QueuedTurn, l as QueuedTurnStarter, m as QuotaLimits, n as QuotaWindowLimits, o as delegateToolName, p as provideAgentTool, q as provideAgentTools, u as utcDay } from './chat-queue.service-C0hr7dqx.js';
4
+ import { AgentRunner, AgentStore, AttachmentStagingStore, ModelCatalog, QuotaProvider, Actor, QuotaReport, ModelCatalogView, AttachmentRef, PageContext, ChatQueueState, HumanReply, ThreadSummary, ThreadDetail, UpdateThreadInput, MessageFeedbackValue, MessageFeedback, StagedAttachment, ActorResolver, AgentApprovalPort, MessageAttachment, AgentAttachmentConfig, AgentClientConfig, ToolPresentation, AgentHistoryWindow, AgentIntake, Persona, SkillContext, ToolRegistry, AgentRegistry, PromptContributor, SkillsConfig, SkillCatalogEntry, ToolCatalogEntry, MemoryConfig, MemoryDigestEntry, SkillProvider, AgentRunInput, AgentRunStartOptions, TokenStreamSink, SinkWriter } from '@dudousxd/nestjs-agent-core';
5
5
  export * from '@dudousxd/nestjs-agent-core';
6
6
  import { Request, Response } from 'express';
7
7
  import { StandardSchemaV1 } from '@standard-schema/spec';
@@ -45,6 +45,12 @@ interface ChatParams {
45
45
  message: string;
46
46
  threadId?: string;
47
47
  agentName?: string;
48
+ /**
49
+ * Run this turn under one of the agent's personas (`@Agent({ personas })`), and pin it on the
50
+ * thread so later sends that name none keep it. Refused (400 `persona_not_found`) unless the agent
51
+ * declares it. Omitted → the thread's pinned persona, else the agent's `defaultPersona`, else none.
52
+ */
53
+ personaId?: string;
48
54
  /**
49
55
  * Files attached to this message (image/PDF) for a vision-capable model, named by the `mediaId`
50
56
  * the upload returned. Only the id is read: the url, content type and name are resolved from the
@@ -293,6 +299,13 @@ declare class AgentService {
293
299
  * dropping the field.
294
300
  */
295
301
  updateThread(actor: Actor, threadId: string, patch: UpdateThreadInput): Promise<void>;
302
+ /**
303
+ * The persona this send runs under — see {@link AgentDepsFactory.resolvePersona}. The thread's
304
+ * pinned persona is read only when the send names none AND the agent has personas to pick from.
305
+ */
306
+ private resolvePersona;
307
+ /** Pin `persona` on the thread when it is not already — a no-op on a store that cannot. */
308
+ private pinThreadPersona;
296
309
  private validateTitle;
297
310
  /**
298
311
  * Agent-selection precedence for a `chat()` call with no explicit `agentName`: the thread's own
@@ -492,6 +505,19 @@ declare class AgentApprovalPortAdapter implements AgentApprovalPort {
492
505
  }): Promise<void>;
493
506
  }
494
507
 
508
+ /**
509
+ * A store that can answer a thread's pinned persona on its own, without materializing the thread —
510
+ * probed structurally, like `ThreadDefaultAgentReader`.
511
+ */
512
+ interface ThreadPersonaReader {
513
+ personaForThread(threadId: string): Promise<string | null>;
514
+ }
515
+ /**
516
+ * The thread's pinned persona: one column when the store projects it ({@link ThreadPersonaReader}),
517
+ * else through the full read.
518
+ */
519
+ declare function threadPersona(store: AgentStore, threadId: string): Promise<string | null>;
520
+
495
521
  /**
496
522
  * How many entries `GET /agent/attachments` returns. Fixed rather than caller-supplied: this route
497
523
  * exists so a composer can show the files someone has uploaded, and a host that needs real paging
@@ -744,6 +770,20 @@ interface AgentOptions {
744
770
  * module-wide setting.
745
771
  */
746
772
  ask?: boolean;
773
+ /**
774
+ * Named variants of THIS agent — a prompt and, optionally, a narrower tool allow-list — that a
775
+ * caller picks per send (`POST <base>/chat { persona }`) and that pin onto the thread. Everything
776
+ * else (model, access rules, handoffs, history) stays this agent's; a variant that needs those to
777
+ * differ is another `@Agent`.
778
+ *
779
+ * A persona's `systemPrompt` is static data. For a prompt built from injected services, leave it
780
+ * out and branch on `ctx.persona` in this class's `@SystemPrompt()` method instead.
781
+ *
782
+ * Omit → no personas, and nothing about a turn changes.
783
+ */
784
+ personas?: Persona[];
785
+ /** The persona a send runs under when neither it nor its thread names one. Omit → none. */
786
+ defaultPersona?: string;
747
787
  }
748
788
  declare const AGENT_METADATA: unique symbol;
749
789
  /** Marks a provider class as an agent. See {@link AgentOptions}. */
@@ -849,6 +889,12 @@ declare class AgentDiscoveryService implements OnModuleInit {
849
889
  onModuleInit(): void;
850
890
  /** Build the internal {@link AgentDefinition} from an `@Agent` instance and its options. */
851
891
  private definitionFrom;
892
+ /**
893
+ * Refuse to boot on a persona declaration that could only fail later, per request: a default that
894
+ * names no persona, an id declared twice, an alias two personas claim, or an alias that is a real
895
+ * agent's name (which would never be reached — a registered agent always wins).
896
+ */
897
+ private assertPersonas;
852
898
  /**
853
899
  * Resolve each handoff entry to an {@link AgentDelegation} — its target's registered name, plus
854
900
  * whether that edge detaches (skipping non-agent classes). A bare name is kept for a plain edge
@@ -1288,4 +1334,4 @@ declare class RunNotActiveException extends ConflictException {
1288
1334
  constructor(runId: string);
1289
1335
  }
1290
1336
 
1291
- export { AGENT_CHAT_QUEUE, AGENT_METADATA, AI_TOOL_METADATA, ATTACHMENT_PAGE_SIZE, type AgUiAdapterOptions, AgUiRunHandler, Agent, AgentApprovalPortAdapter, AgentDepsFactory, AgentDiscoveryService, AgentModule, AgentModuleAsyncOptions, AgentModuleOptions, type AgentOptions, AgentProtocolAdapter, AgentService, AgentSkillsOptions, AiTool, AiToolDiscoveryService, type AiToolOptions, type AnonymousActorOptions, AnonymousActorResolver, type AttachmentLimits, AttachmentsController, type ChatParams, ChatQueueService, type ChatSendMode, type ChatSendResult, ConfigController, DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, DEFAULT_MAX_ATTACHMENT_BYTES, type DeclaredSkill, HeaderActorResolver, InProcessTokenStreamSink, InlineAgentRunner, MAX_ATTACHMENTS_PER_MESSAGE, MemoriesController, MessagesController, ModelsController, QueueController, type QueuedSend, type RequestUserMapper, type ResolvedAiToolOptions, RunNotActiveException, SKILL_METADATA, SYSTEM_PROMPT_CONTRIBUTOR_METADATA, SYSTEM_PROMPT_METADATA, Skill, type SkillBody, SkillDiscoveryService, type SkillOptions, SkillsController, SystemPrompt, SystemPromptContributor, type ThreadDefaultAgentReader, type ThreadModelReader, ToolsController, agUiAdapter, attachmentLimits, declaredSkillProvider, defaultRequestUserMapper, readAgentMetadata, readAiToolMetadata, readSkillMetadata, requestUserActorResolver, resolveSkillsConfig, skillScope, toolNameFromClass };
1337
+ export { AGENT_CHAT_QUEUE, AGENT_METADATA, AI_TOOL_METADATA, ATTACHMENT_PAGE_SIZE, type AgUiAdapterOptions, AgUiRunHandler, Agent, AgentApprovalPortAdapter, AgentDepsFactory, AgentDiscoveryService, AgentModule, AgentModuleAsyncOptions, AgentModuleOptions, type AgentOptions, AgentProtocolAdapter, AgentService, AgentSkillsOptions, AiTool, AiToolDiscoveryService, type AiToolOptions, type AnonymousActorOptions, AnonymousActorResolver, type AttachmentLimits, AttachmentsController, type ChatParams, ChatQueueService, type ChatSendMode, type ChatSendResult, ConfigController, DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, DEFAULT_MAX_ATTACHMENT_BYTES, type DeclaredSkill, HeaderActorResolver, InProcessTokenStreamSink, InlineAgentRunner, MAX_ATTACHMENTS_PER_MESSAGE, MemoriesController, MessagesController, ModelsController, QueueController, type QueuedSend, type RequestUserMapper, type ResolvedAiToolOptions, RunNotActiveException, SKILL_METADATA, SYSTEM_PROMPT_CONTRIBUTOR_METADATA, SYSTEM_PROMPT_METADATA, Skill, type SkillBody, SkillDiscoveryService, type SkillOptions, SkillsController, SystemPrompt, SystemPromptContributor, type ThreadDefaultAgentReader, type ThreadModelReader, type ThreadPersonaReader, ToolsController, agUiAdapter, attachmentLimits, declaredSkillProvider, defaultRequestUserMapper, readAgentMetadata, readAiToolMetadata, readSkillMetadata, requestUserActorResolver, resolveSkillsConfig, skillScope, threadPersona, toolNameFromClass };