@dudousxd/nestjs-agent 0.1.0 → 0.2.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/{agent-deps.factory-D9BHJJqm.d.cts → agent-deps.factory-DpVkZYCy.d.cts} +17 -20
- package/dist/{agent-deps.factory-D9BHJJqm.d.ts → agent-deps.factory-DpVkZYCy.d.ts} +17 -20
- package/dist/durable/index.cjs +253 -160
- package/dist/durable/index.cjs.map +1 -1
- package/dist/durable/index.d.cts +1 -1
- package/dist/durable/index.d.ts +1 -1
- package/dist/durable/index.js +210 -117
- package/dist/durable/index.js.map +1 -1
- package/dist/index.cjs +287 -159
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +85 -14
- package/dist/index.d.ts +85 -14
- package/dist/index.js +236 -116
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DynamicModule, Type, OnApplicationBootstrap, OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { a as AgentModuleOptions, b as AgentModuleAsyncOptions, A as AgentDepsFactory } from './agent-deps.factory-DpVkZYCy.js';
|
|
3
|
+
export { c as AGENT_TOOL_BRAND, d as AgentDeps, F as FunctionalTool, e as delegateToolName, p as provideAgentTool, u as utcDay } from './agent-deps.factory-DpVkZYCy.js';
|
|
4
|
+
import { AgentRunner, AgentStore, Actor, PageContext, ThreadSummary, ThreadDetail, ToolRegistry, AgentRegistry, PromptContributor, AgentRunInput, Decision, TokenStreamSink, SinkWriter, QuotaStore, QuotaState, ActorResolver } from '@dudousxd/nestjs-agent-core';
|
|
2
5
|
export * from '@dudousxd/nestjs-agent-core';
|
|
3
|
-
import { DynamicModule, OnApplicationBootstrap } from '@nestjs/common';
|
|
4
|
-
import { a as AgentModuleOptions, b as AgentModuleAsyncOptions, A as AgentDepsFactory } from './agent-deps.factory-D9BHJJqm.js';
|
|
5
|
-
export { c as AGENT_TOOL_BRAND, d as AgentDeps, D as DefaultAgentOptions, F as FunctionalTool, e as delegateToolName, p as provideAgentTool, u as utcDay } from './agent-deps.factory-D9BHJJqm.js';
|
|
6
6
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
7
|
-
import { DiscoveryService } from '@nestjs/core';
|
|
7
|
+
import { DiscoveryService, MetadataScanner } from '@nestjs/core';
|
|
8
8
|
|
|
9
9
|
declare class AgentModule {
|
|
10
10
|
static forRoot(options: AgentModuleOptions): DynamicModule;
|
|
11
11
|
static forRootAsync(options: AgentModuleAsyncOptions): DynamicModule;
|
|
12
|
-
/** Register additional named agents (an orchestrator + its sub-agents). */
|
|
13
|
-
static forFeature(definitions: AgentDefinition[]): DynamicModule;
|
|
14
12
|
}
|
|
15
13
|
|
|
16
14
|
interface ChatParams {
|
|
@@ -18,7 +16,6 @@ interface ChatParams {
|
|
|
18
16
|
message: string;
|
|
19
17
|
threadId?: string;
|
|
20
18
|
agentName?: string;
|
|
21
|
-
personaId?: string;
|
|
22
19
|
pageContext?: PageContext;
|
|
23
20
|
/** Re-run the last exchange instead of adding a new message. Requires an existing `threadId`. */
|
|
24
21
|
regenerate?: boolean;
|
|
@@ -37,11 +34,6 @@ declare class AgentService {
|
|
|
37
34
|
approve(actor: Actor, toolCallId: string): Promise<void>;
|
|
38
35
|
reject(actor: Actor, toolCallId: string, reason?: string): Promise<void>;
|
|
39
36
|
cancel(actor: Actor, runId: string): Promise<void>;
|
|
40
|
-
resolvePersona(agentName?: string, id?: string): Persona | undefined;
|
|
41
|
-
personaCatalog(agentName?: string): {
|
|
42
|
-
id: string;
|
|
43
|
-
label: string;
|
|
44
|
-
}[];
|
|
45
37
|
listThreads(actorRef: string): Promise<ThreadSummary[]>;
|
|
46
38
|
getThread(actor: Actor, threadId: string): Promise<ThreadDetail | null>;
|
|
47
39
|
deleteThread(actor: Actor, threadId: string): Promise<void>;
|
|
@@ -102,6 +94,59 @@ interface AiToolOptions {
|
|
|
102
94
|
declare function AiTool(options: AiToolOptions): ClassDecorator;
|
|
103
95
|
declare function readAiToolMetadata(target: object): AiToolOptions | undefined;
|
|
104
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Declares a class as an agent. The class is discovered at boot (via `DiscoveryService`) and
|
|
99
|
+
* registered into the `AgentRegistry` — its name, base prompt, tool allow-list, and handoff targets
|
|
100
|
+
* become an internal `AgentDefinition` the loop consumes. The class is an ordinary provider, so it
|
|
101
|
+
* gets constructor DI (its retriever, schema service, policy) — the reason an agent is a class and
|
|
102
|
+
* not a config object.
|
|
103
|
+
*
|
|
104
|
+
* The base prompt is either the `systemPrompt` string here or, for a dynamic prompt, a
|
|
105
|
+
* `@SystemPrompt()` method on the class (which may inject services and read the turn's
|
|
106
|
+
* `PromptContext`). Tools are the global `@AiTool` providers named in `tools` (omit → all tools the
|
|
107
|
+
* actor's role allows); handoff targets are other `@Agent` classes.
|
|
108
|
+
*/
|
|
109
|
+
interface AgentOptions {
|
|
110
|
+
/** Unique agent name — how a turn selects it and how a message records its provenance. */
|
|
111
|
+
name: string;
|
|
112
|
+
/** Human-readable summary (shown to an orchestrator that may hand off to this agent). */
|
|
113
|
+
description?: string;
|
|
114
|
+
/** A flat base prompt. For a dynamic prompt, add a `@SystemPrompt()` method instead. */
|
|
115
|
+
systemPrompt?: string;
|
|
116
|
+
/** Accounting label for the model this agent uses (the model provider itself is shared). */
|
|
117
|
+
model?: string;
|
|
118
|
+
/** Max model→tool iterations for this agent's turn. Default 8. */
|
|
119
|
+
maxSteps?: number;
|
|
120
|
+
/** Allow-list of global tool names this agent may use. Omit → every tool its role allows. */
|
|
121
|
+
tools?: string[];
|
|
122
|
+
/** Other `@Agent` classes this agent may hand off to (auto-exposed as handoff tools). */
|
|
123
|
+
handoff?: Type[];
|
|
124
|
+
}
|
|
125
|
+
declare const AGENT_METADATA: unique symbol;
|
|
126
|
+
/** Marks a provider class as an agent. See {@link AgentOptions}. */
|
|
127
|
+
declare function Agent(options: AgentOptions): ClassDecorator;
|
|
128
|
+
/** Reads {@link AgentOptions} off a class (its constructor), or `undefined` if not an `@Agent`. */
|
|
129
|
+
declare function readAgentMetadata(target: Type | Function): AgentOptions | undefined;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Marks the method on an `@Agent` class that builds the agent's base system prompt. The method
|
|
133
|
+
* receives the turn's `PromptContext` and returns a string (optionally async); because it lives on a
|
|
134
|
+
* provider, it can inject services (e.g. describe a schema, read the actor). Exactly one per agent —
|
|
135
|
+
* it takes precedence over the `@Agent({ systemPrompt })` string.
|
|
136
|
+
*/
|
|
137
|
+
declare const SYSTEM_PROMPT_METADATA: unique symbol;
|
|
138
|
+
/**
|
|
139
|
+
* Marks a method on any provider as a cross-agent system-prompt contributor: it returns an ordered
|
|
140
|
+
* section appended to the composed prompt (after the selected agent's base), or `null` to contribute
|
|
141
|
+
* nothing this turn. This is the seam an app uses to inject domain sections (base scope, a mentions
|
|
142
|
+
* legend, schema hints) across every agent without forking the loop.
|
|
143
|
+
*/
|
|
144
|
+
declare const SYSTEM_PROMPT_CONTRIBUTOR_METADATA: unique symbol;
|
|
145
|
+
/** Marks an `@Agent` method as the agent's dynamic base prompt. See {@link SYSTEM_PROMPT_METADATA}. */
|
|
146
|
+
declare function SystemPrompt(): MethodDecorator;
|
|
147
|
+
/** Marks a provider method as a cross-agent prompt contributor. See {@link SYSTEM_PROMPT_CONTRIBUTOR_METADATA}. */
|
|
148
|
+
declare function SystemPromptContributor(): MethodDecorator;
|
|
149
|
+
|
|
105
150
|
/** Walks every provider at boot and registers `@AiTool` classes into the shared registry. */
|
|
106
151
|
declare class AiToolDiscoveryService implements OnApplicationBootstrap {
|
|
107
152
|
private readonly discovery;
|
|
@@ -118,6 +163,32 @@ declare class AiToolDiscoveryService implements OnApplicationBootstrap {
|
|
|
118
163
|
private registerFunctionalTool;
|
|
119
164
|
}
|
|
120
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Populates the {@link AgentRegistry} from `@Agent`-decorated providers and collects every
|
|
168
|
+
* `@SystemPromptContributor()` method into the app-wide contributor list — the discovery counterpart
|
|
169
|
+
* to authoring agents as config objects. Runs on `onModuleInit`, so agents/contributors are in place
|
|
170
|
+
* before `AiToolDiscoveryService` (which synthesizes handoff tools) runs its `onApplicationBootstrap`.
|
|
171
|
+
*/
|
|
172
|
+
declare class AgentDiscoveryService implements OnModuleInit {
|
|
173
|
+
private readonly discovery;
|
|
174
|
+
private readonly scanner;
|
|
175
|
+
private readonly registry;
|
|
176
|
+
private readonly contributors;
|
|
177
|
+
private readonly logger;
|
|
178
|
+
constructor(discovery: DiscoveryService, scanner: MetadataScanner, registry: AgentRegistry, contributors: PromptContributor[]);
|
|
179
|
+
onModuleInit(): void;
|
|
180
|
+
/** Build the internal {@link AgentDefinition} from an `@Agent` instance and its options. */
|
|
181
|
+
private definitionFrom;
|
|
182
|
+
/** Resolve each handoff `@Agent` class to its registered name (skipping non-agent classes). */
|
|
183
|
+
private handoffNames;
|
|
184
|
+
/** Push every `@SystemPromptContributor()` method on `instance` (bound) into the contributor list. */
|
|
185
|
+
private collectContributors;
|
|
186
|
+
/** The single method on `instance` carrying `metadataKey`, bound to the instance, or undefined. */
|
|
187
|
+
private methodWith;
|
|
188
|
+
/** Bind a named method to its instance, guarding that it is actually a function. */
|
|
189
|
+
private boundMethod;
|
|
190
|
+
}
|
|
191
|
+
|
|
121
192
|
/**
|
|
122
193
|
* Runs the agent turn in-process. HITL approval resolves a pending promise keyed by
|
|
123
194
|
* `runId:toolCallId`. Sub-agent delegation runs a nested loop that streams into the top-level run's
|
|
@@ -192,4 +263,4 @@ declare class HeaderActorResolver implements ActorResolver {
|
|
|
192
263
|
resolve(req: unknown): Actor;
|
|
193
264
|
}
|
|
194
265
|
|
|
195
|
-
export { AI_TOOL_METADATA, AgentDepsFactory, AgentModule, AgentModuleAsyncOptions, AgentModuleOptions, AgentService, AiTool, AiToolDiscoveryService, type AiToolOptions, type ChatParams, HeaderActorResolver, InProcessTokenStreamSink, InlineAgentRunner, LedgerQuotaStore, readAiToolMetadata };
|
|
266
|
+
export { AGENT_METADATA, AI_TOOL_METADATA, Agent, AgentDepsFactory, AgentDiscoveryService, AgentModule, AgentModuleAsyncOptions, AgentModuleOptions, type AgentOptions, AgentService, AiTool, AiToolDiscoveryService, type AiToolOptions, type ChatParams, HeaderActorResolver, InProcessTokenStreamSink, InlineAgentRunner, LedgerQuotaStore, SYSTEM_PROMPT_CONTRIBUTOR_METADATA, SYSTEM_PROMPT_METADATA, SystemPrompt, SystemPromptContributor, readAgentMetadata, readAiToolMetadata };
|