@dudousxd/nestjs-agent 1.1.2 → 1.3.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-OjrLyAZo.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-OjrLyAZo.cjs';
4
- import { AgentRunner, AgentStore, QuotaStore, AttachmentStagingStore, Actor, AttachmentRef, PageContext, HumanReply, ThreadSummary, ThreadDetail, UpdateThreadInput, StagedAttachment, QuotaView, AgentApprovalPort, ActorResolver, MessageAttachment, AgentHistoryWindow, AgentIntake, SkillContext, ToolRegistry, AgentRegistry, PromptContributor, SkillsConfig, SkillCatalogEntry, 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-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, 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';
@@ -80,8 +80,19 @@ declare class AgentService {
80
80
  * ownership is derived from.
81
81
  */
82
82
  subscribeAs(actor: Actor, runId: string): Promise<AsyncIterable<Uint8Array>>;
83
- approve(actor: Actor, toolCallId: string): Promise<void>;
84
- reject(actor: Actor, toolCallId: string, reason?: string): Promise<void>;
83
+ /**
84
+ * Approve a parked action call as `actor`. Who may is the call's recorded approver's business
85
+ * (see {@link assertMayDecide}); `remember` approves later calls of the same tool in the same
86
+ * thread, and `via` names the surface the decision came through (`'web'`, `'slack'`, …) — both
87
+ * persisted with the call.
88
+ */
89
+ approve(actor: Actor, toolCallId: string, opts?: {
90
+ remember?: boolean;
91
+ via?: string;
92
+ }): Promise<void>;
93
+ reject(actor: Actor, toolCallId: string, reason?: string, opts?: {
94
+ via?: string;
95
+ }): Promise<void>;
85
96
  /**
86
97
  * Answer a parked question set. An omitted question takes the request's own pre-picked default —
87
98
  * resolved by the LOOP against the request it already holds, so "the user just submitted" and
@@ -193,6 +204,20 @@ declare class AgentService {
193
204
  * adapter can resolve+signal a decision WITHOUT this check — it is authorized upstream instead.
194
205
  */
195
206
  private assertOwnsToolCall;
207
+ /**
208
+ * Authorization seam for approve/reject. The call's recorded approver decides who may settle it:
209
+ * the requester (the default, and every call recorded before approvers existed) is the thread's
210
+ * own actor — the ownership check this always was; any other approver goes through the policy's
211
+ * `canDecide`, which by default asks whether the actor holds that role.
212
+ */
213
+ private assertMayDecide;
214
+ /**
215
+ * Refuse a decision on a request that has already lapsed — recorded `expired`, or past its
216
+ * `expiresAt` with the run's own timer about to fire. Signalling it anyway would race the timeout:
217
+ * a durable runtime buffers a signal nobody is waiting on, and a late approval must not be what a
218
+ * later replay of the run reads back.
219
+ */
220
+ private assertNotExpired;
196
221
  /**
197
222
  * Resolve the run awaiting `toolCallId`. Derived server-side from the tool call alone — the client
198
223
  * never knows or supplies a runId, and that run is the sub-agent's own child run when the pending
@@ -223,10 +248,13 @@ declare class AgentApprovalPortAdapter implements AgentApprovalPort {
223
248
  constructor(agent: AgentService);
224
249
  approve(toolCallId: string, opts?: {
225
250
  executedByRef?: string;
251
+ remember?: boolean;
252
+ decidedVia?: string;
226
253
  }): Promise<void>;
227
254
  reject(toolCallId: string, opts?: {
228
255
  executedByRef?: string;
229
256
  reason?: string;
257
+ decidedVia?: string;
230
258
  }): Promise<void>;
231
259
  }
232
260
 
@@ -315,6 +343,22 @@ interface AiToolOptions {
315
343
  * role-based policy, which uses `roles`.
316
344
  */
317
345
  ability?: string;
346
+ /**
347
+ * How a chat surface talks about this tool without naming it — sentence templates over the
348
+ * call's input, an icon key, the approval prompt's wording, and how its output reads. Never shown
349
+ * to the model. Served by `GET <base>/tools` to the actors who can reach the tool:
350
+ *
351
+ * ```ts
352
+ * @AiTool({
353
+ * name: 'purgeCache', kind: 'action', description: '…', input,
354
+ * presentation: {
355
+ * label: 'Cache purge', running: 'Purging {key}', done: 'Purged {key}', icon: 'cache',
356
+ * tone: 'destructive', confirm: { title: 'Purge {key}?', verb: 'Purge' },
357
+ * },
358
+ * })
359
+ * ```
360
+ */
361
+ presentation?: ToolPresentation;
318
362
  }
319
363
  /**
320
364
  * Marks a provider class as an AI tool. The class must implement `execute(input, ctx)`.
@@ -610,6 +654,30 @@ declare class SkillsController {
610
654
  threadId?: string): Promise<SkillCatalogEntry[]>;
611
655
  }
612
656
 
657
+ /**
658
+ * The tools THIS caller can reach through an agent, with how a chat surface should talk about each
659
+ * one (`@AiTool({ presentation })`) — so a client narrates "Querying orders" instead of printing
660
+ * `executeSql`, from words declared beside the tool's input schema rather than a client-side map
661
+ * that goes stale on the next rename.
662
+ *
663
+ * THE SAME LIST THE MODEL IS OFFERED: built by `ToolRegistry.visibleSpecs`, the call behind
664
+ * `definitionsFor`, against the agent's own allow-list, the roles policy and each tool's
665
+ * `isEnabled`/`canUse`. Built-in tools the loop serves itself (`ask`, `skill`, `remember`) are not
666
+ * registry tools and are not listed.
667
+ *
668
+ * Posture mirrors `GET /agent/skills`: a plain array, and nothing the caller can pass to widen it —
669
+ * the actor comes from the resolver, and `agent` only ever narrows to that agent's allow-list.
670
+ */
671
+ declare class ToolsController {
672
+ private readonly actorResolver;
673
+ private readonly depsFactory;
674
+ private readonly agents;
675
+ constructor(actorResolver: ActorResolver, depsFactory: AgentDepsFactory, agents: AgentRegistry);
676
+ list(req: Request,
677
+ /** The agent whose tools to list. Omitted → the default agent, the one a turn naming none uses. */
678
+ agent?: string): Promise<ToolCatalogEntry[]>;
679
+ }
680
+
613
681
  /**
614
682
  * What the assistant believes about THIS caller — and how they take one of those beliefs back.
615
683
  *
@@ -714,6 +782,12 @@ declare class InlineAgentRunner implements AgentRunner {
714
782
  * shape it is delivering — the loop asked for one and only ever gets what the caller sent. A
715
783
  * cancel settles the wait too, by rejecting it.
716
784
  */
785
+ /**
786
+ * {@link park} for an approval, bounded by the policy's time to live when it has one: the timer
787
+ * settles the wait as `expired` — the same Decision the durable runner builds from its signal
788
+ * timeout — and a decision that arrives first disarms it.
789
+ */
790
+ private parkApproval;
717
791
  private park;
718
792
  private topLevelHooks;
719
793
  /**
@@ -783,4 +857,4 @@ declare class HeaderActorResolver implements ActorResolver {
783
857
  resolve(req: unknown): Actor;
784
858
  }
785
859
 
786
- 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, SKILL_METADATA, SYSTEM_PROMPT_CONTRIBUTOR_METADATA, SYSTEM_PROMPT_METADATA, Skill, type SkillBody, SkillDiscoveryService, type SkillOptions, SkillsController, SystemPrompt, SystemPromptContributor, type ThreadDefaultAgentReader, declaredSkillProvider, readAgentMetadata, readAiToolMetadata, readSkillMetadata, resolveSkillsConfig, skillScope };
860
+ 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, 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 };
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-OjrLyAZo.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-OjrLyAZo.js';
4
- import { AgentRunner, AgentStore, QuotaStore, AttachmentStagingStore, Actor, AttachmentRef, PageContext, HumanReply, ThreadSummary, ThreadDetail, UpdateThreadInput, StagedAttachment, QuotaView, AgentApprovalPort, ActorResolver, MessageAttachment, AgentHistoryWindow, AgentIntake, SkillContext, ToolRegistry, AgentRegistry, PromptContributor, SkillsConfig, SkillCatalogEntry, 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-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, 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';
@@ -80,8 +80,19 @@ declare class AgentService {
80
80
  * ownership is derived from.
81
81
  */
82
82
  subscribeAs(actor: Actor, runId: string): Promise<AsyncIterable<Uint8Array>>;
83
- approve(actor: Actor, toolCallId: string): Promise<void>;
84
- reject(actor: Actor, toolCallId: string, reason?: string): Promise<void>;
83
+ /**
84
+ * Approve a parked action call as `actor`. Who may is the call's recorded approver's business
85
+ * (see {@link assertMayDecide}); `remember` approves later calls of the same tool in the same
86
+ * thread, and `via` names the surface the decision came through (`'web'`, `'slack'`, …) — both
87
+ * persisted with the call.
88
+ */
89
+ approve(actor: Actor, toolCallId: string, opts?: {
90
+ remember?: boolean;
91
+ via?: string;
92
+ }): Promise<void>;
93
+ reject(actor: Actor, toolCallId: string, reason?: string, opts?: {
94
+ via?: string;
95
+ }): Promise<void>;
85
96
  /**
86
97
  * Answer a parked question set. An omitted question takes the request's own pre-picked default —
87
98
  * resolved by the LOOP against the request it already holds, so "the user just submitted" and
@@ -193,6 +204,20 @@ declare class AgentService {
193
204
  * adapter can resolve+signal a decision WITHOUT this check — it is authorized upstream instead.
194
205
  */
195
206
  private assertOwnsToolCall;
207
+ /**
208
+ * Authorization seam for approve/reject. The call's recorded approver decides who may settle it:
209
+ * the requester (the default, and every call recorded before approvers existed) is the thread's
210
+ * own actor — the ownership check this always was; any other approver goes through the policy's
211
+ * `canDecide`, which by default asks whether the actor holds that role.
212
+ */
213
+ private assertMayDecide;
214
+ /**
215
+ * Refuse a decision on a request that has already lapsed — recorded `expired`, or past its
216
+ * `expiresAt` with the run's own timer about to fire. Signalling it anyway would race the timeout:
217
+ * a durable runtime buffers a signal nobody is waiting on, and a late approval must not be what a
218
+ * later replay of the run reads back.
219
+ */
220
+ private assertNotExpired;
196
221
  /**
197
222
  * Resolve the run awaiting `toolCallId`. Derived server-side from the tool call alone — the client
198
223
  * never knows or supplies a runId, and that run is the sub-agent's own child run when the pending
@@ -223,10 +248,13 @@ declare class AgentApprovalPortAdapter implements AgentApprovalPort {
223
248
  constructor(agent: AgentService);
224
249
  approve(toolCallId: string, opts?: {
225
250
  executedByRef?: string;
251
+ remember?: boolean;
252
+ decidedVia?: string;
226
253
  }): Promise<void>;
227
254
  reject(toolCallId: string, opts?: {
228
255
  executedByRef?: string;
229
256
  reason?: string;
257
+ decidedVia?: string;
230
258
  }): Promise<void>;
231
259
  }
232
260
 
@@ -315,6 +343,22 @@ interface AiToolOptions {
315
343
  * role-based policy, which uses `roles`.
316
344
  */
317
345
  ability?: string;
346
+ /**
347
+ * How a chat surface talks about this tool without naming it — sentence templates over the
348
+ * call's input, an icon key, the approval prompt's wording, and how its output reads. Never shown
349
+ * to the model. Served by `GET <base>/tools` to the actors who can reach the tool:
350
+ *
351
+ * ```ts
352
+ * @AiTool({
353
+ * name: 'purgeCache', kind: 'action', description: '…', input,
354
+ * presentation: {
355
+ * label: 'Cache purge', running: 'Purging {key}', done: 'Purged {key}', icon: 'cache',
356
+ * tone: 'destructive', confirm: { title: 'Purge {key}?', verb: 'Purge' },
357
+ * },
358
+ * })
359
+ * ```
360
+ */
361
+ presentation?: ToolPresentation;
318
362
  }
319
363
  /**
320
364
  * Marks a provider class as an AI tool. The class must implement `execute(input, ctx)`.
@@ -610,6 +654,30 @@ declare class SkillsController {
610
654
  threadId?: string): Promise<SkillCatalogEntry[]>;
611
655
  }
612
656
 
657
+ /**
658
+ * The tools THIS caller can reach through an agent, with how a chat surface should talk about each
659
+ * one (`@AiTool({ presentation })`) — so a client narrates "Querying orders" instead of printing
660
+ * `executeSql`, from words declared beside the tool's input schema rather than a client-side map
661
+ * that goes stale on the next rename.
662
+ *
663
+ * THE SAME LIST THE MODEL IS OFFERED: built by `ToolRegistry.visibleSpecs`, the call behind
664
+ * `definitionsFor`, against the agent's own allow-list, the roles policy and each tool's
665
+ * `isEnabled`/`canUse`. Built-in tools the loop serves itself (`ask`, `skill`, `remember`) are not
666
+ * registry tools and are not listed.
667
+ *
668
+ * Posture mirrors `GET /agent/skills`: a plain array, and nothing the caller can pass to widen it —
669
+ * the actor comes from the resolver, and `agent` only ever narrows to that agent's allow-list.
670
+ */
671
+ declare class ToolsController {
672
+ private readonly actorResolver;
673
+ private readonly depsFactory;
674
+ private readonly agents;
675
+ constructor(actorResolver: ActorResolver, depsFactory: AgentDepsFactory, agents: AgentRegistry);
676
+ list(req: Request,
677
+ /** The agent whose tools to list. Omitted → the default agent, the one a turn naming none uses. */
678
+ agent?: string): Promise<ToolCatalogEntry[]>;
679
+ }
680
+
613
681
  /**
614
682
  * What the assistant believes about THIS caller — and how they take one of those beliefs back.
615
683
  *
@@ -714,6 +782,12 @@ declare class InlineAgentRunner implements AgentRunner {
714
782
  * shape it is delivering — the loop asked for one and only ever gets what the caller sent. A
715
783
  * cancel settles the wait too, by rejecting it.
716
784
  */
785
+ /**
786
+ * {@link park} for an approval, bounded by the policy's time to live when it has one: the timer
787
+ * settles the wait as `expired` — the same Decision the durable runner builds from its signal
788
+ * timeout — and a decision that arrives first disarms it.
789
+ */
790
+ private parkApproval;
717
791
  private park;
718
792
  private topLevelHooks;
719
793
  /**
@@ -783,4 +857,4 @@ declare class HeaderActorResolver implements ActorResolver {
783
857
  resolve(req: unknown): Actor;
784
858
  }
785
859
 
786
- 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, SKILL_METADATA, SYSTEM_PROMPT_CONTRIBUTOR_METADATA, SYSTEM_PROMPT_METADATA, Skill, type SkillBody, SkillDiscoveryService, type SkillOptions, SkillsController, SystemPrompt, SystemPromptContributor, type ThreadDefaultAgentReader, declaredSkillProvider, readAgentMetadata, readAiToolMetadata, readSkillMetadata, resolveSkillsConfig, skillScope };
860
+ 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, 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 };