@dudousxd/nestjs-agent 0.1.0 → 0.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/{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 +368 -162
- 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 +332 -126
- package/dist/durable/index.js.map +1 -1
- package/dist/index.cjs +402 -161
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +106 -18
- package/dist/index.d.ts +106 -18
- package/dist/index.js +358 -125
- 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, QuotaStore, Actor, PageContext, ThreadSummary, ThreadDetail, QuotaView, ToolRegistry, AgentRegistry, PromptContributor, AgentRunInput, Decision, TokenStreamSink, SinkWriter, 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,17 +16,22 @@ 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;
|
|
22
|
+
/**
|
|
23
|
+
* When creating a thread (no `threadId`), start it transient — a scratch conversation hidden from
|
|
24
|
+
* the thread list until the caller promotes it. Ignored when `threadId` is set.
|
|
25
|
+
*/
|
|
26
|
+
transient?: boolean;
|
|
25
27
|
}
|
|
26
28
|
/** The orchestration facade the controllers call. */
|
|
27
29
|
declare class AgentService {
|
|
28
30
|
private readonly runner;
|
|
29
31
|
private readonly store;
|
|
30
32
|
private readonly deps;
|
|
31
|
-
|
|
33
|
+
private readonly quota;
|
|
34
|
+
constructor(runner: AgentRunner, store: AgentStore, deps: AgentDepsFactory, quota: QuotaStore | undefined);
|
|
32
35
|
chat(params: ChatParams): Promise<{
|
|
33
36
|
runId: string;
|
|
34
37
|
threadId: string;
|
|
@@ -37,18 +40,24 @@ declare class AgentService {
|
|
|
37
40
|
approve(actor: Actor, toolCallId: string): Promise<void>;
|
|
38
41
|
reject(actor: Actor, toolCallId: string, reason?: string): Promise<void>;
|
|
39
42
|
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
43
|
listThreads(actorRef: string): Promise<ThreadSummary[]>;
|
|
46
44
|
getThread(actor: Actor, threadId: string): Promise<ThreadDetail | null>;
|
|
47
45
|
deleteThread(actor: Actor, threadId: string): Promise<void>;
|
|
48
46
|
forkThread(actor: Actor, threadId: string, fromMessageId: string): Promise<ThreadSummary>;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
renameThread(actor: Actor, threadId: string, title: string): Promise<void>;
|
|
48
|
+
promoteThread(actor: Actor, threadId: string): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Drop a message and everything after it — the "edit and resend" / "delete from here" primitive.
|
|
51
|
+
* The client then sends a fresh turn on the truncated thread. Ownership-gated like the other
|
|
52
|
+
* thread-scoped mutations.
|
|
53
|
+
*/
|
|
54
|
+
truncateThreadFrom(actor: Actor, threadId: string, messageId: string): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* The day's usage for the badge: tokens + summed USD cost from the store, and the configured
|
|
57
|
+
* limit from the quota store (null → unlimited). `withinLimit` comes from the quota store so it
|
|
58
|
+
* can never drift from what enforcement uses.
|
|
59
|
+
*/
|
|
60
|
+
quotaToday(actorRef: string): Promise<QuotaView>;
|
|
52
61
|
/**
|
|
53
62
|
* Authorization seam for thread-scoped endpoints: the caller must own the thread. A missing
|
|
54
63
|
* thread is a 404; someone else's thread is a 403 — one actor never touches another's thread.
|
|
@@ -102,6 +111,59 @@ interface AiToolOptions {
|
|
|
102
111
|
declare function AiTool(options: AiToolOptions): ClassDecorator;
|
|
103
112
|
declare function readAiToolMetadata(target: object): AiToolOptions | undefined;
|
|
104
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Declares a class as an agent. The class is discovered at boot (via `DiscoveryService`) and
|
|
116
|
+
* registered into the `AgentRegistry` — its name, base prompt, tool allow-list, and handoff targets
|
|
117
|
+
* become an internal `AgentDefinition` the loop consumes. The class is an ordinary provider, so it
|
|
118
|
+
* gets constructor DI (its retriever, schema service, policy) — the reason an agent is a class and
|
|
119
|
+
* not a config object.
|
|
120
|
+
*
|
|
121
|
+
* The base prompt is either the `systemPrompt` string here or, for a dynamic prompt, a
|
|
122
|
+
* `@SystemPrompt()` method on the class (which may inject services and read the turn's
|
|
123
|
+
* `PromptContext`). Tools are the global `@AiTool` providers named in `tools` (omit → all tools the
|
|
124
|
+
* actor's role allows); handoff targets are other `@Agent` classes.
|
|
125
|
+
*/
|
|
126
|
+
interface AgentOptions {
|
|
127
|
+
/** Unique agent name — how a turn selects it and how a message records its provenance. */
|
|
128
|
+
name: string;
|
|
129
|
+
/** Human-readable summary (shown to an orchestrator that may hand off to this agent). */
|
|
130
|
+
description?: string;
|
|
131
|
+
/** A flat base prompt. For a dynamic prompt, add a `@SystemPrompt()` method instead. */
|
|
132
|
+
systemPrompt?: string;
|
|
133
|
+
/** Accounting label for the model this agent uses (the model provider itself is shared). */
|
|
134
|
+
model?: string;
|
|
135
|
+
/** Max model→tool iterations for this agent's turn. Default 8. */
|
|
136
|
+
maxSteps?: number;
|
|
137
|
+
/** Allow-list of global tool names this agent may use. Omit → every tool its role allows. */
|
|
138
|
+
tools?: string[];
|
|
139
|
+
/** Other `@Agent` classes this agent may hand off to (auto-exposed as handoff tools). */
|
|
140
|
+
handoff?: Type[];
|
|
141
|
+
}
|
|
142
|
+
declare const AGENT_METADATA: unique symbol;
|
|
143
|
+
/** Marks a provider class as an agent. See {@link AgentOptions}. */
|
|
144
|
+
declare function Agent(options: AgentOptions): ClassDecorator;
|
|
145
|
+
/** Reads {@link AgentOptions} off a class (its constructor), or `undefined` if not an `@Agent`. */
|
|
146
|
+
declare function readAgentMetadata(target: Type | Function): AgentOptions | undefined;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Marks the method on an `@Agent` class that builds the agent's base system prompt. The method
|
|
150
|
+
* receives the turn's `PromptContext` and returns a string (optionally async); because it lives on a
|
|
151
|
+
* provider, it can inject services (e.g. describe a schema, read the actor). Exactly one per agent —
|
|
152
|
+
* it takes precedence over the `@Agent({ systemPrompt })` string.
|
|
153
|
+
*/
|
|
154
|
+
declare const SYSTEM_PROMPT_METADATA: unique symbol;
|
|
155
|
+
/**
|
|
156
|
+
* Marks a method on any provider as a cross-agent system-prompt contributor: it returns an ordered
|
|
157
|
+
* section appended to the composed prompt (after the selected agent's base), or `null` to contribute
|
|
158
|
+
* nothing this turn. This is the seam an app uses to inject domain sections (base scope, a mentions
|
|
159
|
+
* legend, schema hints) across every agent without forking the loop.
|
|
160
|
+
*/
|
|
161
|
+
declare const SYSTEM_PROMPT_CONTRIBUTOR_METADATA: unique symbol;
|
|
162
|
+
/** Marks an `@Agent` method as the agent's dynamic base prompt. See {@link SYSTEM_PROMPT_METADATA}. */
|
|
163
|
+
declare function SystemPrompt(): MethodDecorator;
|
|
164
|
+
/** Marks a provider method as a cross-agent prompt contributor. See {@link SYSTEM_PROMPT_CONTRIBUTOR_METADATA}. */
|
|
165
|
+
declare function SystemPromptContributor(): MethodDecorator;
|
|
166
|
+
|
|
105
167
|
/** Walks every provider at boot and registers `@AiTool` classes into the shared registry. */
|
|
106
168
|
declare class AiToolDiscoveryService implements OnApplicationBootstrap {
|
|
107
169
|
private readonly discovery;
|
|
@@ -118,6 +180,32 @@ declare class AiToolDiscoveryService implements OnApplicationBootstrap {
|
|
|
118
180
|
private registerFunctionalTool;
|
|
119
181
|
}
|
|
120
182
|
|
|
183
|
+
/**
|
|
184
|
+
* Populates the {@link AgentRegistry} from `@Agent`-decorated providers and collects every
|
|
185
|
+
* `@SystemPromptContributor()` method into the app-wide contributor list — the discovery counterpart
|
|
186
|
+
* to authoring agents as config objects. Runs on `onModuleInit`, so agents/contributors are in place
|
|
187
|
+
* before `AiToolDiscoveryService` (which synthesizes handoff tools) runs its `onApplicationBootstrap`.
|
|
188
|
+
*/
|
|
189
|
+
declare class AgentDiscoveryService implements OnModuleInit {
|
|
190
|
+
private readonly discovery;
|
|
191
|
+
private readonly scanner;
|
|
192
|
+
private readonly registry;
|
|
193
|
+
private readonly contributors;
|
|
194
|
+
private readonly logger;
|
|
195
|
+
constructor(discovery: DiscoveryService, scanner: MetadataScanner, registry: AgentRegistry, contributors: PromptContributor[]);
|
|
196
|
+
onModuleInit(): void;
|
|
197
|
+
/** Build the internal {@link AgentDefinition} from an `@Agent` instance and its options. */
|
|
198
|
+
private definitionFrom;
|
|
199
|
+
/** Resolve each handoff `@Agent` class to its registered name (skipping non-agent classes). */
|
|
200
|
+
private handoffNames;
|
|
201
|
+
/** Push every `@SystemPromptContributor()` method on `instance` (bound) into the contributor list. */
|
|
202
|
+
private collectContributors;
|
|
203
|
+
/** The single method on `instance` carrying `metadataKey`, bound to the instance, or undefined. */
|
|
204
|
+
private methodWith;
|
|
205
|
+
/** Bind a named method to its instance, guarding that it is actually a function. */
|
|
206
|
+
private boundMethod;
|
|
207
|
+
}
|
|
208
|
+
|
|
121
209
|
/**
|
|
122
210
|
* Runs the agent turn in-process. HITL approval resolves a pending promise keyed by
|
|
123
211
|
* `runId:toolCallId`. Sub-agent delegation runs a nested loop that streams into the top-level run's
|
|
@@ -192,4 +280,4 @@ declare class HeaderActorResolver implements ActorResolver {
|
|
|
192
280
|
resolve(req: unknown): Actor;
|
|
193
281
|
}
|
|
194
282
|
|
|
195
|
-
export { AI_TOOL_METADATA, AgentDepsFactory, AgentModule, AgentModuleAsyncOptions, AgentModuleOptions, AgentService, AiTool, AiToolDiscoveryService, type AiToolOptions, type ChatParams, HeaderActorResolver, InProcessTokenStreamSink, InlineAgentRunner, LedgerQuotaStore, readAiToolMetadata };
|
|
283
|
+
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 };
|