@dudousxd/nestjs-agent 1.6.0 → 1.8.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, OnModuleInit, Type, OnApplicationBootstrap } from '@nestjs/common';
2
- import { b as AgentModuleOptions, c as AgentModuleAsyncOptions, A as AgentDepsFactory, d as AgentSkillsOptions } from './agent-deps.factory-CUyVPsa1.cjs';
3
- export { e as AGENT_TOOL_BRAND, f as AgentAttachmentsOptions, g as AgentDeps, h as AgentMemoryOptions, a as AgentSurface, F as FunctionalTool, i as delegateToolName, p as provideAgentTool, u as utcDay } from './agent-deps.factory-CUyVPsa1.cjs';
4
- import { AgentRunner, AgentStore, QuotaStore, AttachmentStagingStore, Actor, AttachmentRef, PageContext, HumanReply, ThreadSummary, ThreadDetail, UpdateThreadInput, MessageFeedbackValue, MessageFeedback, StagedAttachment, QuotaView, AgentApprovalPort, ActorResolver, MessageAttachment, ToolPresentation, AgentHistoryWindow, AgentIntake, SkillContext, ToolRegistry, AgentRegistry, PromptContributor, SkillsConfig, SkillCatalogEntry, ToolCatalogEntry, MemoryConfig, MemoryDigestEntry, SkillProvider, AgentRunInput, TokenStreamSink, SinkWriter, QuotaState } from '@dudousxd/nestjs-agent-core';
2
+ import { b as AgentModuleOptions, c as AgentModuleAsyncOptions, A as AgentDepsFactory, d as AgentSkillsOptions } from './agent-deps.factory-Cus_RqwJ.cjs';
3
+ export { e as AGENT_TOOL_BRAND, f as AgentAttachmentsOptions, g as AgentDeps, h as AgentMemoryOptions, a as AgentSurface, F as FunctionalTool, L as LedgerQuotaProvider, Q as QuotaLimits, i as QuotaWindowLimits, j as delegateToolName, p as provideAgentTool, u as utcDay } from './agent-deps.factory-Cus_RqwJ.cjs';
4
+ import { AgentRunner, AgentStore, QuotaStore, AttachmentStagingStore, ModelCatalog, QuotaProvider, Actor, QuotaReport, ModelCatalogView, AttachmentRef, PageContext, HumanReply, ThreadSummary, ThreadDetail, UpdateThreadInput, MessageFeedbackValue, MessageFeedback, StagedAttachment, QuotaView, AgentApprovalPort, ActorResolver, MessageAttachment, ToolPresentation, AgentHistoryWindow, AgentIntake, SkillContext, ToolRegistry, AgentRegistry, PromptContributor, SkillsConfig, SkillCatalogEntry, ToolCatalogEntry, MemoryConfig, MemoryDigestEntry, SkillProvider, AgentRunInput, TokenStreamSink, SinkWriter, QuotaState } from '@dudousxd/nestjs-agent-core';
5
5
  export * from '@dudousxd/nestjs-agent-core';
6
6
  import { Request } from 'express';
7
7
  import { StandardSchemaV1 } from '@standard-schema/spec';
@@ -26,6 +26,11 @@ interface ChatParams {
26
26
  pageContext?: PageContext;
27
27
  /** Re-run the last exchange instead of adding a new message. Requires an existing `threadId`. */
28
28
  regenerate?: boolean;
29
+ /**
30
+ * Run this turn on a catalog model instead of the thread's pinned one (or the provider default).
31
+ * Refused (400) unless the bound `ModelCatalog` lists it as available to this actor and agent.
32
+ */
33
+ model?: string;
29
34
  /**
30
35
  * When creating a thread (no `threadId`), start it transient — a scratch conversation hidden from
31
36
  * the thread list until the caller promotes it. Ignored when `threadId` is set.
@@ -42,6 +47,10 @@ interface ChatParams {
42
47
  interface ThreadDefaultAgentReader {
43
48
  defaultAgentForThread(threadId: string): Promise<string | null>;
44
49
  }
50
+ /** Like {@link ThreadDefaultAgentReader}, for the thread's pinned model. */
51
+ interface ThreadModelReader {
52
+ modelForThread(threadId: string): Promise<string | null>;
53
+ }
45
54
  /** The orchestration facade the controllers call. */
46
55
  declare class AgentService {
47
56
  private readonly runner;
@@ -49,7 +58,35 @@ declare class AgentService {
49
58
  private readonly deps;
50
59
  private readonly quota;
51
60
  private readonly staging?;
52
- constructor(runner: AgentRunner, store: AgentStore, deps: AgentDepsFactory, quota: QuotaStore | undefined, staging?: AttachmentStagingStore | undefined);
61
+ private readonly models?;
62
+ private readonly quotaProvider?;
63
+ private readonly options?;
64
+ constructor(runner: AgentRunner, store: AgentStore, deps: AgentDepsFactory, quota: QuotaStore | undefined, staging?: AttachmentStagingStore | undefined, models?: ModelCatalog | undefined, quotaProvider?: QuotaProvider | undefined, options?: Pick<AgentModuleOptions, "quotaProvider" | "quotaLimits"> | undefined);
65
+ /**
66
+ * The actor's budget across windows (`GET <base>/quota`) — the bound {@link QuotaProvider}'s
67
+ * report. Without one (a service built outside the module), a day window from the ledger.
68
+ */
69
+ quotaReport(actor: Actor): Promise<QuotaReport>;
70
+ /**
71
+ * Refuse a turn the actor's budget no longer covers — only when the host configured one
72
+ * (`quotaProvider` or `quotaLimits`): the default report is informational, and the daily token
73
+ * quota the loop enforces keeps working as it always has.
74
+ */
75
+ private assertWithinQuota;
76
+ /**
77
+ * The models `actor` may pick for `agent` (`GET <base>/models`). An empty catalog when none is
78
+ * bound, so a picker simply has nothing to offer.
79
+ */
80
+ listModels(actor: Actor, agent?: string): Promise<ModelCatalogView>;
81
+ /**
82
+ * `model` if the catalog offers it to this actor and agent right now, else a 400 naming why. The
83
+ * one gate every model choice passes — a send's own, and a thread's pinned one at the moment it is
84
+ * pinned and again at every turn that runs on it (availability can change in between).
85
+ */
86
+ private assertModelAllowed;
87
+ /** The model a turn runs on: the send's own, else the thread's pinned one, else none. */
88
+ private resolveModel;
89
+ private threadModel;
53
90
  chat(params: ChatParams): Promise<{
54
91
  runId: string;
55
92
  threadId: string;
@@ -695,6 +732,17 @@ declare class MessagesController {
695
732
  }>;
696
733
  }
697
734
 
735
+ declare class ModelsController {
736
+ private readonly agent;
737
+ private readonly actorResolver;
738
+ constructor(agent: AgentService, actorResolver: ActorResolver);
739
+ /**
740
+ * The models the caller may pick for `agent` (the default agent when omitted), grouped by
741
+ * provider, with badges and availability — the bound `ModelCatalog`'s answer, or an empty one.
742
+ */
743
+ list(req: Request, agent?: string): Promise<ModelCatalogView>;
744
+ }
745
+
698
746
  /**
699
747
  * The tools THIS caller can reach through an agent, with how a chat surface should talk about each
700
748
  * one (`@AiTool({ presentation })`) — so a client narrates "Querying orders" instead of printing
@@ -898,4 +946,4 @@ declare class HeaderActorResolver implements ActorResolver {
898
946
  resolve(req: unknown): Actor;
899
947
  }
900
948
 
901
- export { AGENT_METADATA, AI_TOOL_METADATA, ATTACHMENT_PAGE_SIZE, Agent, AgentApprovalPortAdapter, AgentDepsFactory, AgentDiscoveryService, AgentModule, AgentModuleAsyncOptions, AgentModuleOptions, type AgentOptions, AgentService, AgentSkillsOptions, AiTool, AiToolDiscoveryService, type AiToolOptions, AttachmentsController, type ChatParams, DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, DEFAULT_MAX_ATTACHMENT_BYTES, type DeclaredSkill, HeaderActorResolver, InProcessTokenStreamSink, InlineAgentRunner, LedgerQuotaStore, MemoriesController, MessagesController, SKILL_METADATA, SYSTEM_PROMPT_CONTRIBUTOR_METADATA, SYSTEM_PROMPT_METADATA, Skill, type SkillBody, SkillDiscoveryService, type SkillOptions, SkillsController, SystemPrompt, SystemPromptContributor, type ThreadDefaultAgentReader, ToolsController, declaredSkillProvider, readAgentMetadata, readAiToolMetadata, readSkillMetadata, resolveSkillsConfig, skillScope };
949
+ export { AGENT_METADATA, AI_TOOL_METADATA, ATTACHMENT_PAGE_SIZE, Agent, AgentApprovalPortAdapter, AgentDepsFactory, AgentDiscoveryService, AgentModule, AgentModuleAsyncOptions, AgentModuleOptions, type AgentOptions, AgentService, AgentSkillsOptions, AiTool, AiToolDiscoveryService, type AiToolOptions, AttachmentsController, type ChatParams, DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, DEFAULT_MAX_ATTACHMENT_BYTES, type DeclaredSkill, HeaderActorResolver, InProcessTokenStreamSink, InlineAgentRunner, LedgerQuotaStore, MemoriesController, MessagesController, ModelsController, SKILL_METADATA, SYSTEM_PROMPT_CONTRIBUTOR_METADATA, SYSTEM_PROMPT_METADATA, Skill, type SkillBody, SkillDiscoveryService, type SkillOptions, SkillsController, SystemPrompt, SystemPromptContributor, type ThreadDefaultAgentReader, type ThreadModelReader, ToolsController, declaredSkillProvider, readAgentMetadata, readAiToolMetadata, readSkillMetadata, resolveSkillsConfig, skillScope };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { DynamicModule, OnModuleInit, Type, OnApplicationBootstrap } from '@nestjs/common';
2
- import { b as AgentModuleOptions, c as AgentModuleAsyncOptions, A as AgentDepsFactory, d as AgentSkillsOptions } from './agent-deps.factory-CUyVPsa1.js';
3
- export { e as AGENT_TOOL_BRAND, f as AgentAttachmentsOptions, g as AgentDeps, h as AgentMemoryOptions, a as AgentSurface, F as FunctionalTool, i as delegateToolName, p as provideAgentTool, u as utcDay } from './agent-deps.factory-CUyVPsa1.js';
4
- import { AgentRunner, AgentStore, QuotaStore, AttachmentStagingStore, Actor, AttachmentRef, PageContext, HumanReply, ThreadSummary, ThreadDetail, UpdateThreadInput, MessageFeedbackValue, MessageFeedback, StagedAttachment, QuotaView, AgentApprovalPort, ActorResolver, MessageAttachment, ToolPresentation, AgentHistoryWindow, AgentIntake, SkillContext, ToolRegistry, AgentRegistry, PromptContributor, SkillsConfig, SkillCatalogEntry, ToolCatalogEntry, MemoryConfig, MemoryDigestEntry, SkillProvider, AgentRunInput, TokenStreamSink, SinkWriter, QuotaState } from '@dudousxd/nestjs-agent-core';
2
+ import { b as AgentModuleOptions, c as AgentModuleAsyncOptions, A as AgentDepsFactory, d as AgentSkillsOptions } from './agent-deps.factory-Cus_RqwJ.js';
3
+ export { e as AGENT_TOOL_BRAND, f as AgentAttachmentsOptions, g as AgentDeps, h as AgentMemoryOptions, a as AgentSurface, F as FunctionalTool, L as LedgerQuotaProvider, Q as QuotaLimits, i as QuotaWindowLimits, j as delegateToolName, p as provideAgentTool, u as utcDay } from './agent-deps.factory-Cus_RqwJ.js';
4
+ import { AgentRunner, AgentStore, QuotaStore, AttachmentStagingStore, ModelCatalog, QuotaProvider, Actor, QuotaReport, ModelCatalogView, AttachmentRef, PageContext, HumanReply, ThreadSummary, ThreadDetail, UpdateThreadInput, MessageFeedbackValue, MessageFeedback, StagedAttachment, QuotaView, AgentApprovalPort, ActorResolver, MessageAttachment, ToolPresentation, AgentHistoryWindow, AgentIntake, SkillContext, ToolRegistry, AgentRegistry, PromptContributor, SkillsConfig, SkillCatalogEntry, ToolCatalogEntry, MemoryConfig, MemoryDigestEntry, SkillProvider, AgentRunInput, TokenStreamSink, SinkWriter, QuotaState } from '@dudousxd/nestjs-agent-core';
5
5
  export * from '@dudousxd/nestjs-agent-core';
6
6
  import { Request } from 'express';
7
7
  import { StandardSchemaV1 } from '@standard-schema/spec';
@@ -26,6 +26,11 @@ interface ChatParams {
26
26
  pageContext?: PageContext;
27
27
  /** Re-run the last exchange instead of adding a new message. Requires an existing `threadId`. */
28
28
  regenerate?: boolean;
29
+ /**
30
+ * Run this turn on a catalog model instead of the thread's pinned one (or the provider default).
31
+ * Refused (400) unless the bound `ModelCatalog` lists it as available to this actor and agent.
32
+ */
33
+ model?: string;
29
34
  /**
30
35
  * When creating a thread (no `threadId`), start it transient — a scratch conversation hidden from
31
36
  * the thread list until the caller promotes it. Ignored when `threadId` is set.
@@ -42,6 +47,10 @@ interface ChatParams {
42
47
  interface ThreadDefaultAgentReader {
43
48
  defaultAgentForThread(threadId: string): Promise<string | null>;
44
49
  }
50
+ /** Like {@link ThreadDefaultAgentReader}, for the thread's pinned model. */
51
+ interface ThreadModelReader {
52
+ modelForThread(threadId: string): Promise<string | null>;
53
+ }
45
54
  /** The orchestration facade the controllers call. */
46
55
  declare class AgentService {
47
56
  private readonly runner;
@@ -49,7 +58,35 @@ declare class AgentService {
49
58
  private readonly deps;
50
59
  private readonly quota;
51
60
  private readonly staging?;
52
- constructor(runner: AgentRunner, store: AgentStore, deps: AgentDepsFactory, quota: QuotaStore | undefined, staging?: AttachmentStagingStore | undefined);
61
+ private readonly models?;
62
+ private readonly quotaProvider?;
63
+ private readonly options?;
64
+ constructor(runner: AgentRunner, store: AgentStore, deps: AgentDepsFactory, quota: QuotaStore | undefined, staging?: AttachmentStagingStore | undefined, models?: ModelCatalog | undefined, quotaProvider?: QuotaProvider | undefined, options?: Pick<AgentModuleOptions, "quotaProvider" | "quotaLimits"> | undefined);
65
+ /**
66
+ * The actor's budget across windows (`GET <base>/quota`) — the bound {@link QuotaProvider}'s
67
+ * report. Without one (a service built outside the module), a day window from the ledger.
68
+ */
69
+ quotaReport(actor: Actor): Promise<QuotaReport>;
70
+ /**
71
+ * Refuse a turn the actor's budget no longer covers — only when the host configured one
72
+ * (`quotaProvider` or `quotaLimits`): the default report is informational, and the daily token
73
+ * quota the loop enforces keeps working as it always has.
74
+ */
75
+ private assertWithinQuota;
76
+ /**
77
+ * The models `actor` may pick for `agent` (`GET <base>/models`). An empty catalog when none is
78
+ * bound, so a picker simply has nothing to offer.
79
+ */
80
+ listModels(actor: Actor, agent?: string): Promise<ModelCatalogView>;
81
+ /**
82
+ * `model` if the catalog offers it to this actor and agent right now, else a 400 naming why. The
83
+ * one gate every model choice passes — a send's own, and a thread's pinned one at the moment it is
84
+ * pinned and again at every turn that runs on it (availability can change in between).
85
+ */
86
+ private assertModelAllowed;
87
+ /** The model a turn runs on: the send's own, else the thread's pinned one, else none. */
88
+ private resolveModel;
89
+ private threadModel;
53
90
  chat(params: ChatParams): Promise<{
54
91
  runId: string;
55
92
  threadId: string;
@@ -695,6 +732,17 @@ declare class MessagesController {
695
732
  }>;
696
733
  }
697
734
 
735
+ declare class ModelsController {
736
+ private readonly agent;
737
+ private readonly actorResolver;
738
+ constructor(agent: AgentService, actorResolver: ActorResolver);
739
+ /**
740
+ * The models the caller may pick for `agent` (the default agent when omitted), grouped by
741
+ * provider, with badges and availability — the bound `ModelCatalog`'s answer, or an empty one.
742
+ */
743
+ list(req: Request, agent?: string): Promise<ModelCatalogView>;
744
+ }
745
+
698
746
  /**
699
747
  * The tools THIS caller can reach through an agent, with how a chat surface should talk about each
700
748
  * one (`@AiTool({ presentation })`) — so a client narrates "Querying orders" instead of printing
@@ -898,4 +946,4 @@ declare class HeaderActorResolver implements ActorResolver {
898
946
  resolve(req: unknown): Actor;
899
947
  }
900
948
 
901
- export { AGENT_METADATA, AI_TOOL_METADATA, ATTACHMENT_PAGE_SIZE, Agent, AgentApprovalPortAdapter, AgentDepsFactory, AgentDiscoveryService, AgentModule, AgentModuleAsyncOptions, AgentModuleOptions, type AgentOptions, AgentService, AgentSkillsOptions, AiTool, AiToolDiscoveryService, type AiToolOptions, AttachmentsController, type ChatParams, DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, DEFAULT_MAX_ATTACHMENT_BYTES, type DeclaredSkill, HeaderActorResolver, InProcessTokenStreamSink, InlineAgentRunner, LedgerQuotaStore, MemoriesController, MessagesController, SKILL_METADATA, SYSTEM_PROMPT_CONTRIBUTOR_METADATA, SYSTEM_PROMPT_METADATA, Skill, type SkillBody, SkillDiscoveryService, type SkillOptions, SkillsController, SystemPrompt, SystemPromptContributor, type ThreadDefaultAgentReader, ToolsController, declaredSkillProvider, readAgentMetadata, readAiToolMetadata, readSkillMetadata, resolveSkillsConfig, skillScope };
949
+ export { AGENT_METADATA, AI_TOOL_METADATA, ATTACHMENT_PAGE_SIZE, Agent, AgentApprovalPortAdapter, AgentDepsFactory, AgentDiscoveryService, AgentModule, AgentModuleAsyncOptions, AgentModuleOptions, type AgentOptions, AgentService, AgentSkillsOptions, AiTool, AiToolDiscoveryService, type AiToolOptions, AttachmentsController, type ChatParams, DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, DEFAULT_MAX_ATTACHMENT_BYTES, type DeclaredSkill, HeaderActorResolver, InProcessTokenStreamSink, InlineAgentRunner, LedgerQuotaStore, MemoriesController, MessagesController, ModelsController, SKILL_METADATA, SYSTEM_PROMPT_CONTRIBUTOR_METADATA, SYSTEM_PROMPT_METADATA, Skill, type SkillBody, SkillDiscoveryService, type SkillOptions, SkillsController, SystemPrompt, SystemPromptContributor, type ThreadDefaultAgentReader, type ThreadModelReader, ToolsController, declaredSkillProvider, readAgentMetadata, readAiToolMetadata, readSkillMetadata, resolveSkillsConfig, skillScope };