@igniter-js/agents 0.1.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/AGENTS.md +2913 -0
- package/CHANGELOG.md +5 -0
- package/README.md +1585 -0
- package/dist/adapters/index.d.mts +2 -0
- package/dist/adapters/index.d.ts +2 -0
- package/dist/adapters/index.js +1024 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/index.mjs +1021 -0
- package/dist/adapters/index.mjs.map +1 -0
- package/dist/index-CX4IgrRt.d.mts +2181 -0
- package/dist/index-CX4IgrRt.d.ts +2181 -0
- package/dist/index.d.mts +3170 -0
- package/dist/index.d.ts +3170 -0
- package/dist/index.js +4045 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4011 -0
- package/dist/index.mjs.map +1 -0
- package/dist/shim.d.mts +72 -0
- package/dist/shim.d.ts +72 -0
- package/dist/shim.js +105 -0
- package/dist/shim.js.map +1 -0
- package/dist/shim.mjs +89 -0
- package/dist/shim.mjs.map +1 -0
- package/dist/telemetry/index.d.mts +340 -0
- package/dist/telemetry/index.d.ts +340 -0
- package/dist/telemetry/index.js +157 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/telemetry/index.mjs +155 -0
- package/dist/telemetry/index.mjs.map +1 -0
- package/package.json +116 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3170 @@
|
|
|
1
|
+
import { ToolSet, LanguageModel, ToolLoopAgent, AgentCallParameters, AgentStreamParameters, Tool } from 'ai';
|
|
2
|
+
import { IgniterLogger, IgniterError } from '@igniter-js/core';
|
|
3
|
+
import { IgniterTelemetryManager } from '@igniter-js/telemetry';
|
|
4
|
+
import { I as IgniterAgentMemoryConfig, a as IgniterAgentMemoryRuntime, b as IgniterAgentWorkingMemoryParams, c as IgniterAgentWorkingMemory, d as IgniterAgentUpdateWorkingMemoryParams, e as IgniterAgentConversationMessage, f as IgniterAgentUIMessage, g as IgniterAgentGetMessagesParams, h as IgniterAgentChatSession, i as IgniterAgentGetChatsParams } from './index-CX4IgrRt.js';
|
|
5
|
+
export { z as IgniterAgentAdapterBatchResult, y as IgniterAgentAdapterFactory, u as IgniterAgentAdapterOptions, A as IgniterAgentAdapterStats, s as IgniterAgentChatsConfig, p as IgniterAgentGenerateSuggestionsConfig, o as IgniterAgentGenerateTitleConfig, r as IgniterAgentHistoryConfig, j as IgniterAgentInMemoryAdapter, v as IgniterAgentInMemoryAdapterOptions, l as IgniterAgentJSONFileAdapter, k as IgniterAgentJSONFileAdapterOptions, x as IgniterAgentMemoryAdapter, t as IgniterAgentMemoryProvider, n as IgniterAgentMemoryScope, m as IgniterAgentMessageRole, w as IgniterAgentRedisAdapterOptions, q as IgniterAgentWorkingMemoryConfig } from './index-CX4IgrRt.js';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
export { IgniterAgentTelemetryEvents, IgniterAgentTelemetryEventsType } from './telemetry/index.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @fileoverview Prompt types for IgniterAgent instructions.
|
|
11
|
+
* @module types/prompt
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Represents a prompt template that can be built with context.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
interface IgniterAgentPromptTemplate<TContext extends Record<string, unknown> = Record<string, unknown>> {
|
|
19
|
+
/**
|
|
20
|
+
* Builds the prompt string with the provided context.
|
|
21
|
+
*
|
|
22
|
+
* @param context - Context data used for interpolation
|
|
23
|
+
* @returns The built prompt string
|
|
24
|
+
*/
|
|
25
|
+
build(context: TContext): string;
|
|
26
|
+
/**
|
|
27
|
+
* Returns the raw prompt template.
|
|
28
|
+
*/
|
|
29
|
+
getTemplate(): string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @fileoverview Hook types for IgniterAgent lifecycle and execution events.
|
|
34
|
+
* @module types/hooks
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* Hooks emitted by IgniterAgent runtime.
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
interface IgniterAgentHooks {
|
|
42
|
+
/**
|
|
43
|
+
* Fired when an agent starts successfully.
|
|
44
|
+
*/
|
|
45
|
+
onAgentStart?: (name: string) => void;
|
|
46
|
+
/**
|
|
47
|
+
* Fired when an agent fails to start or errors.
|
|
48
|
+
*/
|
|
49
|
+
onAgentError?: (name: string, error: Error) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Fired when a tool call begins.
|
|
52
|
+
*/
|
|
53
|
+
onToolCallStart?: (agentName: string, toolName: string, input: unknown) => void;
|
|
54
|
+
/**
|
|
55
|
+
* Fired when a tool call completes successfully.
|
|
56
|
+
*/
|
|
57
|
+
onToolCallEnd?: (agentName: string, toolName: string, output: unknown) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Fired when a tool call fails.
|
|
60
|
+
*/
|
|
61
|
+
onToolCallError?: (agentName: string, toolName: string, error: Error) => void;
|
|
62
|
+
/**
|
|
63
|
+
* Fired before connecting to an MCP server.
|
|
64
|
+
*/
|
|
65
|
+
onMCPStart?: (agentName: string, mcpName: string) => void;
|
|
66
|
+
/**
|
|
67
|
+
* Fired when an MCP connection fails.
|
|
68
|
+
*/
|
|
69
|
+
onMCPError?: (agentName: string, mcpName: string, error: Error) => void;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @fileoverview Common type definitions used across the IgniterAgent library.
|
|
74
|
+
* This module contains foundational types that are shared between different parts of the agent system.
|
|
75
|
+
*
|
|
76
|
+
* @module types/common
|
|
77
|
+
* @packageDocumentation
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Represents the connection status of a toolset or MCP client.
|
|
82
|
+
*
|
|
83
|
+
* @description
|
|
84
|
+
* Used to track whether a toolset or MCP server is currently available for use.
|
|
85
|
+
* This status is automatically updated when connections are established or lost.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const checkToolsetStatus = (status: IgniterAgentConnectionStatus) => {
|
|
90
|
+
* if (status === 'connected') {
|
|
91
|
+
* console.log('Ready to use tools');
|
|
92
|
+
* } else {
|
|
93
|
+
* console.log('Toolset unavailable');
|
|
94
|
+
* }
|
|
95
|
+
* };
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
type IgniterAgentConnectionStatus = "connected" | "disconnected";
|
|
101
|
+
/**
|
|
102
|
+
* Represents the type of toolset transport protocol.
|
|
103
|
+
*
|
|
104
|
+
* @description
|
|
105
|
+
* Defines how the agent communicates with external tool providers:
|
|
106
|
+
* - `stdio`: Standard input/output (local process communication)
|
|
107
|
+
* - `http`: HTTP/HTTPS transport (remote server communication)
|
|
108
|
+
* - `custom`: User-defined custom tools (inline JavaScript functions)
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* // Using different transport types
|
|
113
|
+
* const stdioTransport: IgniterAgentToolsetType = 'stdio'; // Local MCP server
|
|
114
|
+
* const httpTransport: IgniterAgentToolsetType = 'http'; // Remote MCP server
|
|
115
|
+
* const customTransport: IgniterAgentToolsetType = 'custom'; // Inline tools
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @public
|
|
119
|
+
*/
|
|
120
|
+
type IgniterAgentToolsetType = "stdio" | "http" | "custom";
|
|
121
|
+
/**
|
|
122
|
+
* Utility type that flattens nested toolsets into a single object with prefixed keys.
|
|
123
|
+
*
|
|
124
|
+
* @description
|
|
125
|
+
* When multiple toolsets are registered with an agent, their tools are flattened
|
|
126
|
+
* into a single namespace using the pattern `{toolsetName}_{toolName}`.
|
|
127
|
+
* This ensures tool names are unique and identifiable by their source.
|
|
128
|
+
*
|
|
129
|
+
* @typeParam TToolsets - Record of toolset names to toolset configurations
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* // Given toolsets:
|
|
134
|
+
* // - github: { createIssue, listRepos }
|
|
135
|
+
* // - docker: { buildImage, runContainer }
|
|
136
|
+
*
|
|
137
|
+
* // Flattened result:
|
|
138
|
+
* // {
|
|
139
|
+
* // github_createIssue: Tool,
|
|
140
|
+
* // github_listRepos: Tool,
|
|
141
|
+
* // docker_buildImage: Tool,
|
|
142
|
+
* // docker_runContainer: Tool
|
|
143
|
+
* // }
|
|
144
|
+
* ```
|
|
145
|
+
*
|
|
146
|
+
* @public
|
|
147
|
+
*/
|
|
148
|
+
type IgniterAgentFlattenedToolSet<TToolsets extends Record<string, IgniterAgentToolset$1<IgniterAgentToolsetType, string>>> = {
|
|
149
|
+
[K in keyof TToolsets as `${K & string}_${keyof TToolsets[K]["tools"] & string}`]: TToolsets[K]["tools"][keyof TToolsets[K]["tools"]];
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Represents a collection of tools with metadata about their source and status.
|
|
153
|
+
*
|
|
154
|
+
* @description
|
|
155
|
+
* A toolset is a logical grouping of related tools that share a common purpose
|
|
156
|
+
* or source (e.g., all GitHub-related tools, all Docker-related tools).
|
|
157
|
+
*
|
|
158
|
+
* @typeParam TType - The transport type for this toolset
|
|
159
|
+
* @typeParam TName - The unique name identifier for this toolset
|
|
160
|
+
*
|
|
161
|
+
* @property name - Unique identifier for the toolset
|
|
162
|
+
* @property type - Transport protocol used ('stdio', 'http', or 'custom')
|
|
163
|
+
* @property tools - Collection of tool definitions
|
|
164
|
+
* @property status - Current connection status
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* const githubToolset: IgniterAgentToolset<'custom', 'github'> = {
|
|
169
|
+
* name: 'github',
|
|
170
|
+
* type: 'custom',
|
|
171
|
+
* status: 'connected',
|
|
172
|
+
* tools: {
|
|
173
|
+
* createIssue: createIssueTool,
|
|
174
|
+
* listRepos: listReposTool
|
|
175
|
+
* }
|
|
176
|
+
* };
|
|
177
|
+
* ```
|
|
178
|
+
*
|
|
179
|
+
* @public
|
|
180
|
+
*/
|
|
181
|
+
interface IgniterAgentToolset$1<TType extends IgniterAgentToolsetType = IgniterAgentToolsetType, TName extends string = string> {
|
|
182
|
+
/** Unique identifier for the toolset */
|
|
183
|
+
readonly name: TName;
|
|
184
|
+
/** Transport type used by this toolset */
|
|
185
|
+
readonly type: TType;
|
|
186
|
+
/** Collection of available tools */
|
|
187
|
+
readonly tools: ToolSet;
|
|
188
|
+
/** Current connection status */
|
|
189
|
+
readonly status: IgniterAgentConnectionStatus;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Complete configuration object for an IgniterAgent instance.
|
|
193
|
+
*
|
|
194
|
+
* @description
|
|
195
|
+
* This interface defines all the configuration options available when creating
|
|
196
|
+
* an agent. It supports strong typing through generics to ensure type safety
|
|
197
|
+
* when accessing toolsets, context, and other agent properties.
|
|
198
|
+
*
|
|
199
|
+
* @typeParam TAgentName - The agent's unique name type
|
|
200
|
+
* @typeParam TAgentModel - The language model type
|
|
201
|
+
* @typeParam TAgentInstructions - The prompt template type
|
|
202
|
+
* @typeParam TAgentToolsets - Record of all registered toolsets
|
|
203
|
+
* @typeParam TAgentMCPConfigs - Record of all MCP configurations
|
|
204
|
+
* @typeParam TAgentContextSchema - Zod schema for context validation
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* const config: IgniterAgentConfig<
|
|
209
|
+
* 'assistant',
|
|
210
|
+
* LanguageModel,
|
|
211
|
+
* IgniterAgentPromptTemplate,
|
|
212
|
+
* { github: GitHubToolset },
|
|
213
|
+
* { filesystem: FileSystemMCP },
|
|
214
|
+
* typeof contextSchema
|
|
215
|
+
* > = {
|
|
216
|
+
* name: 'assistant',
|
|
217
|
+
* model: openai('gpt-4'),
|
|
218
|
+
* instructions: prompt,
|
|
219
|
+
* toolsets: { github: githubToolset },
|
|
220
|
+
* configs: { filesystem: filesystemConfig },
|
|
221
|
+
* schema: contextSchema
|
|
222
|
+
* };
|
|
223
|
+
* ```
|
|
224
|
+
*
|
|
225
|
+
* @public
|
|
226
|
+
*/
|
|
227
|
+
interface IgniterAgentConfig<TAgentName extends string = string, TAgentModel extends LanguageModel = LanguageModel, TAgentInstructions extends IgniterAgentPromptTemplate = IgniterAgentPromptTemplate, TAgentToolsets extends Record<string, IgniterAgentToolset$1> = Record<string, IgniterAgentToolset$1>, TAgentMCPConfigs extends Record<string, IgniterAgentMCPConfigUnion> = Record<string, IgniterAgentMCPConfigUnion>, TAgentContextSchema extends z.ZodSchema = z.ZodSchema> {
|
|
228
|
+
/**
|
|
229
|
+
* Unique name identifier for the agent.
|
|
230
|
+
* Used for logging, debugging, and multi-agent orchestration.
|
|
231
|
+
*/
|
|
232
|
+
name: TAgentName;
|
|
233
|
+
/**
|
|
234
|
+
* Registered toolsets available to the agent.
|
|
235
|
+
* Each toolset contains related tools that the agent can invoke.
|
|
236
|
+
*/
|
|
237
|
+
toolsets: TAgentToolsets;
|
|
238
|
+
/**
|
|
239
|
+
* MCP server configurations for external tool providers.
|
|
240
|
+
* These are lazily initialized when the agent starts.
|
|
241
|
+
*/
|
|
242
|
+
configs: TAgentMCPConfigs;
|
|
243
|
+
/**
|
|
244
|
+
* Prompt instructions defining the agent's behavior and personality.
|
|
245
|
+
* Uses the IgniterAgentPrompt pattern for dynamic prompt generation.
|
|
246
|
+
*/
|
|
247
|
+
instructions: TAgentInstructions;
|
|
248
|
+
/**
|
|
249
|
+
* The language model used for inference.
|
|
250
|
+
* Supports any Vercel AI SDK compatible model provider.
|
|
251
|
+
*/
|
|
252
|
+
model: TAgentModel;
|
|
253
|
+
/**
|
|
254
|
+
* Zod schema for validating context passed to the agent.
|
|
255
|
+
* Ensures type-safe context access in prompt templates.
|
|
256
|
+
*/
|
|
257
|
+
schema: TAgentContextSchema;
|
|
258
|
+
/**
|
|
259
|
+
* Optional memory configuration.
|
|
260
|
+
*/
|
|
261
|
+
memory?: IgniterAgentMemoryConfig;
|
|
262
|
+
/**
|
|
263
|
+
* Optional logger instance for operational logs.
|
|
264
|
+
*/
|
|
265
|
+
logger?: IgniterLogger;
|
|
266
|
+
/**
|
|
267
|
+
* Optional telemetry manager for observability.
|
|
268
|
+
*/
|
|
269
|
+
telemetry?: IgniterTelemetryManager;
|
|
270
|
+
/**
|
|
271
|
+
* Optional hook callbacks for lifecycle/tool/mcp events.
|
|
272
|
+
*/
|
|
273
|
+
hooks?: IgniterAgentHooks;
|
|
274
|
+
/**
|
|
275
|
+
* Agent instance from AI SDK ToolLoopAgent.
|
|
276
|
+
* @internal
|
|
277
|
+
*/
|
|
278
|
+
instance?: ToolLoopAgent;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Base configuration interface for MCP (Model Context Protocol) clients.
|
|
282
|
+
*
|
|
283
|
+
* @description
|
|
284
|
+
* Contains common properties shared between all MCP transport types.
|
|
285
|
+
*
|
|
286
|
+
* @typeParam TName - The unique identifier for this MCP configuration
|
|
287
|
+
*
|
|
288
|
+
* @public
|
|
289
|
+
*/
|
|
290
|
+
interface IgniterAgentMCPConfigBase<TName extends string = string> {
|
|
291
|
+
/** Unique name identifier for the MCP configuration */
|
|
292
|
+
readonly name: TName;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Configuration for stdio-based MCP transport.
|
|
296
|
+
*
|
|
297
|
+
* @description
|
|
298
|
+
* Used when connecting to MCP servers via standard input/output streams.
|
|
299
|
+
* This is typically used for local MCP servers running as child processes.
|
|
300
|
+
*
|
|
301
|
+
* @typeParam TName - The unique identifier for this MCP configuration
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* ```typescript
|
|
305
|
+
* const filesystemMCP: IgniterAgentMCPStdioConfig<'filesystem'> = {
|
|
306
|
+
* type: 'stdio',
|
|
307
|
+
* name: 'filesystem',
|
|
308
|
+
* command: 'npx',
|
|
309
|
+
* args: ['-y', '@modelcontextprotocol/server-filesystem', '/tmp'],
|
|
310
|
+
* env: { DEBUG: 'true' }
|
|
311
|
+
* };
|
|
312
|
+
* ```
|
|
313
|
+
*
|
|
314
|
+
* @public
|
|
315
|
+
*/
|
|
316
|
+
interface IgniterAgentMCPStdioConfig<TName extends string = string> extends IgniterAgentMCPConfigBase<TName> {
|
|
317
|
+
/** Transport type identifier */
|
|
318
|
+
readonly type: "stdio";
|
|
319
|
+
/**
|
|
320
|
+
* Command to execute the MCP server.
|
|
321
|
+
* @example 'npx', 'node', 'python'
|
|
322
|
+
*/
|
|
323
|
+
readonly command: string;
|
|
324
|
+
/**
|
|
325
|
+
* Arguments to pass to the command.
|
|
326
|
+
* @example ['-y', '@modelcontextprotocol/server-filesystem']
|
|
327
|
+
*/
|
|
328
|
+
readonly args: string[];
|
|
329
|
+
/**
|
|
330
|
+
* Optional environment variables for the child process.
|
|
331
|
+
* @example { DEBUG: 'true', API_KEY: 'xxx' }
|
|
332
|
+
*/
|
|
333
|
+
readonly env?: Record<string, string>;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Configuration for HTTP-based MCP transport.
|
|
337
|
+
*
|
|
338
|
+
* @description
|
|
339
|
+
* Used when connecting to remote MCP servers over HTTP/HTTPS.
|
|
340
|
+
* Supports custom headers for authentication and other purposes.
|
|
341
|
+
*
|
|
342
|
+
* @typeParam TName - The unique identifier for this MCP configuration
|
|
343
|
+
*
|
|
344
|
+
* @example
|
|
345
|
+
* ```typescript
|
|
346
|
+
* const remoteMCP: IgniterAgentMCPHttpConfig<'remote-tools'> = {
|
|
347
|
+
* type: 'http',
|
|
348
|
+
* name: 'remote-tools',
|
|
349
|
+
* url: 'https://mcp.example.com/tools',
|
|
350
|
+
* headers: {
|
|
351
|
+
* 'Authorization': 'Bearer token123'
|
|
352
|
+
* }
|
|
353
|
+
* };
|
|
354
|
+
* ```
|
|
355
|
+
*
|
|
356
|
+
* @public
|
|
357
|
+
*/
|
|
358
|
+
interface IgniterAgentMCPHttpConfig<TName extends string = string> extends IgniterAgentMCPConfigBase<TName> {
|
|
359
|
+
/** Transport type identifier */
|
|
360
|
+
readonly type: "http";
|
|
361
|
+
/**
|
|
362
|
+
* URL of the remote MCP server.
|
|
363
|
+
* Must be a valid HTTP or HTTPS URL.
|
|
364
|
+
*/
|
|
365
|
+
readonly url: string;
|
|
366
|
+
/**
|
|
367
|
+
* Optional HTTP headers to include in requests.
|
|
368
|
+
* Useful for authentication, API keys, etc.
|
|
369
|
+
*/
|
|
370
|
+
readonly headers?: Record<string, string>;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Union type for all supported MCP configuration types.
|
|
374
|
+
*
|
|
375
|
+
* @description
|
|
376
|
+
* Discriminated union based on the `type` property, allowing TypeScript
|
|
377
|
+
* to narrow the type based on runtime checks.
|
|
378
|
+
*
|
|
379
|
+
* @typeParam TName - The unique identifier for this MCP configuration
|
|
380
|
+
*
|
|
381
|
+
* @example
|
|
382
|
+
* ```typescript
|
|
383
|
+
* function handleMCPConfig(config: IgniterAgentMCPConfigUnion) {
|
|
384
|
+
* if (config.type === 'stdio') {
|
|
385
|
+
* console.log('Command:', config.command);
|
|
386
|
+
* } else if (config.type === 'http') {
|
|
387
|
+
* console.log('URL:', config.url);
|
|
388
|
+
* }
|
|
389
|
+
* }
|
|
390
|
+
* ```
|
|
391
|
+
*
|
|
392
|
+
* @public
|
|
393
|
+
*/
|
|
394
|
+
type IgniterAgentMCPConfigUnion<TName extends string = string> = IgniterAgentMCPStdioConfig<TName> | IgniterAgentMCPHttpConfig<TName>;
|
|
395
|
+
/**
|
|
396
|
+
* Fluent builder interface for MCP client configuration.
|
|
397
|
+
*
|
|
398
|
+
* @description
|
|
399
|
+
* Provides a type-safe fluent API for building MCP configurations.
|
|
400
|
+
* The interface changes based on the transport type selected.
|
|
401
|
+
*
|
|
402
|
+
* @typeParam TType - The transport type ('stdio' or 'http')
|
|
403
|
+
* @typeParam TName - The configuration name
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
* ```typescript
|
|
407
|
+
* // Stdio configuration
|
|
408
|
+
* const stdioConfig = IgniterAgent
|
|
409
|
+
* .mcp('filesystem')
|
|
410
|
+
* .withType('stdio')
|
|
411
|
+
* .withCommand('npx')
|
|
412
|
+
* .withArgs(['-y', '@mcp/server-filesystem'])
|
|
413
|
+
* .build();
|
|
414
|
+
*
|
|
415
|
+
* // HTTP configuration
|
|
416
|
+
* const httpConfig = IgniterAgent
|
|
417
|
+
* .mcp('remote')
|
|
418
|
+
* .withType('http')
|
|
419
|
+
* .withURL('https://mcp.example.com')
|
|
420
|
+
* .withHeaders({ Authorization: 'Bearer xxx' })
|
|
421
|
+
* .build();
|
|
422
|
+
* ```
|
|
423
|
+
*
|
|
424
|
+
* @public
|
|
425
|
+
*/
|
|
426
|
+
type IgniterAgentMCPClientInterface<TType extends IgniterAgentToolsetType, TName extends string> = TType extends "stdio" ? IgniterAgentMCPStdioClientInterface<TName> : IgniterAgentMCPHttpClientInterface<TName>;
|
|
427
|
+
/**
|
|
428
|
+
* Fluent builder interface for stdio MCP configuration.
|
|
429
|
+
*
|
|
430
|
+
* @typeParam TName - The configuration name
|
|
431
|
+
* @internal
|
|
432
|
+
*/
|
|
433
|
+
interface IgniterAgentMCPStdioClientInterface<TName extends string> {
|
|
434
|
+
/** Set the command to execute */
|
|
435
|
+
withCommand(command: string): IgniterAgentMCPStdioClientInterface<TName>;
|
|
436
|
+
/** Set the command arguments */
|
|
437
|
+
withArgs(args: string[]): IgniterAgentMCPStdioClientInterface<TName>;
|
|
438
|
+
/** Set environment variables */
|
|
439
|
+
withEnv(env: Record<string, string>): IgniterAgentMCPStdioClientInterface<TName>;
|
|
440
|
+
/** Build and return the configuration object */
|
|
441
|
+
build(): IgniterAgentMCPStdioConfig<TName>;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Fluent builder interface for HTTP MCP configuration.
|
|
445
|
+
*
|
|
446
|
+
* @typeParam TName - The configuration name
|
|
447
|
+
* @internal
|
|
448
|
+
*/
|
|
449
|
+
interface IgniterAgentMCPHttpClientInterface<TName extends string> {
|
|
450
|
+
/** Set the configuration name */
|
|
451
|
+
withName<TNewName extends string>(name: TNewName): IgniterAgentMCPHttpClientInterface<TNewName>;
|
|
452
|
+
/** Set the transport type */
|
|
453
|
+
withType(type: IgniterAgentToolsetType): IgniterAgentMCPHttpClientInterface<TName>;
|
|
454
|
+
/** Set the server URL */
|
|
455
|
+
withURL(url: string): IgniterAgentMCPHttpClientInterface<TName>;
|
|
456
|
+
/** Set HTTP headers */
|
|
457
|
+
withHeaders(headers: Record<string, string>): IgniterAgentMCPHttpClientInterface<TName>;
|
|
458
|
+
/** Build and return the configuration object */
|
|
459
|
+
build(): IgniterAgentMCPHttpConfig<TName>;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Constructor parameters for creating a new Toolset instance.
|
|
463
|
+
*
|
|
464
|
+
* @typeParam TToolsetName - The toolset's unique name
|
|
465
|
+
* @typeParam TTools - The tools collection type
|
|
466
|
+
*
|
|
467
|
+
* @example
|
|
468
|
+
* ```typescript
|
|
469
|
+
* const params: IgniterAgentToolsetParams<'github', GithubTools> = {
|
|
470
|
+
* name: 'github',
|
|
471
|
+
* tools: githubTools
|
|
472
|
+
* };
|
|
473
|
+
* ```
|
|
474
|
+
*
|
|
475
|
+
* @public
|
|
476
|
+
*/
|
|
477
|
+
interface IgniterAgentToolsetParams<TToolsetName extends string = string, TTools extends ToolSet = ToolSet> {
|
|
478
|
+
/** Unique name identifier for the toolset */
|
|
479
|
+
name: TToolsetName;
|
|
480
|
+
/** Collection of tools in this toolset */
|
|
481
|
+
tools: TTools;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Represents a successful tool execution result.
|
|
485
|
+
*
|
|
486
|
+
* @typeParam TData - The type of data returned by the tool
|
|
487
|
+
*
|
|
488
|
+
* @example
|
|
489
|
+
* ```typescript
|
|
490
|
+
* const successResult: IgniterAgentToolSuccessResult<User> = {
|
|
491
|
+
* success: true,
|
|
492
|
+
* data: { id: '123', name: 'John' }
|
|
493
|
+
* };
|
|
494
|
+
* ```
|
|
495
|
+
*
|
|
496
|
+
* @public
|
|
497
|
+
*/
|
|
498
|
+
interface IgniterAgentToolSuccessResult<TData = unknown> {
|
|
499
|
+
/** Indicates the tool executed successfully */
|
|
500
|
+
readonly success: true;
|
|
501
|
+
/** The data returned by the tool */
|
|
502
|
+
readonly data: TData;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Represents a failed tool execution result.
|
|
506
|
+
*
|
|
507
|
+
* @example
|
|
508
|
+
* ```typescript
|
|
509
|
+
* const errorResult: IgniterAgentToolErrorResult = {
|
|
510
|
+
* success: false,
|
|
511
|
+
* error: 'Failed to connect to database'
|
|
512
|
+
* };
|
|
513
|
+
* ```
|
|
514
|
+
*
|
|
515
|
+
* @public
|
|
516
|
+
*/
|
|
517
|
+
interface IgniterAgentToolErrorResult {
|
|
518
|
+
/** Indicates the tool execution failed */
|
|
519
|
+
readonly success: false;
|
|
520
|
+
/** Error message describing what went wrong */
|
|
521
|
+
readonly error: string;
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Union type for tool execution results.
|
|
525
|
+
*
|
|
526
|
+
* @description
|
|
527
|
+
* All tools wrapped by IgniterAgent return this type, providing a consistent
|
|
528
|
+
* error handling pattern across all tool invocations.
|
|
529
|
+
*
|
|
530
|
+
* @typeParam TData - The type of data returned on success
|
|
531
|
+
*
|
|
532
|
+
* @example
|
|
533
|
+
* ```typescript
|
|
534
|
+
* const handleResult = (result: IgniterAgentToolResult<User>) => {
|
|
535
|
+
* if (result.success) {
|
|
536
|
+
* console.log('User:', result.data);
|
|
537
|
+
* } else {
|
|
538
|
+
* console.error('Error:', result.error);
|
|
539
|
+
* }
|
|
540
|
+
* };
|
|
541
|
+
* ```
|
|
542
|
+
*
|
|
543
|
+
* @public
|
|
544
|
+
*/
|
|
545
|
+
type IgniterAgentToolResult<TData = unknown> = IgniterAgentToolSuccessResult<TData> | IgniterAgentToolErrorResult;
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* @fileoverview Type definitions for IgniterAgent Builder pattern classes.
|
|
549
|
+
* This module contains all interfaces for the fluent builder API.
|
|
550
|
+
*
|
|
551
|
+
* @module types/builder
|
|
552
|
+
* @packageDocumentation
|
|
553
|
+
*/
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* Interface for the built toolset result.
|
|
557
|
+
*
|
|
558
|
+
* @description
|
|
559
|
+
* Represents the final product of the Toolset builder, containing
|
|
560
|
+
* all configured tools and metadata.
|
|
561
|
+
*
|
|
562
|
+
* @typeParam TName - The toolset's unique name
|
|
563
|
+
* @typeParam TTools - The tools collection type
|
|
564
|
+
*
|
|
565
|
+
* @example
|
|
566
|
+
* ```typescript
|
|
567
|
+
* const toolset: IgniterAgentBuiltToolset<'github', GithubTools> = {
|
|
568
|
+
* type: 'custom',
|
|
569
|
+
* name: 'github',
|
|
570
|
+
* toolset: tools,
|
|
571
|
+
* status: 'connected',
|
|
572
|
+
* tools: tools
|
|
573
|
+
* };
|
|
574
|
+
* ```
|
|
575
|
+
*
|
|
576
|
+
* @public
|
|
577
|
+
*/
|
|
578
|
+
interface IgniterAgentBuiltToolset<TName extends string = string, TTools extends Record<string, Tool> = Record<string, Tool>> extends IgniterAgentToolset$1<'custom', TName> {
|
|
579
|
+
/** The raw toolset object */
|
|
580
|
+
readonly toolset: TTools;
|
|
581
|
+
/** Typed tools collection */
|
|
582
|
+
readonly tools: TTools;
|
|
583
|
+
readonly $Infer: {
|
|
584
|
+
Name: TName;
|
|
585
|
+
Tools: TTools;
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Interface for the built tool result.
|
|
590
|
+
*
|
|
591
|
+
* @description
|
|
592
|
+
* Represents a finalized tool definition with its assigned name.
|
|
593
|
+
*
|
|
594
|
+
* @typeParam TName - The tool's unique name
|
|
595
|
+
* @typeParam TInputSchema - The tool parameters type
|
|
596
|
+
* @typeParam TOutputSchema - The tool result type
|
|
597
|
+
* @typeParam TExecute - The tool execute function type
|
|
598
|
+
*
|
|
599
|
+
* @public
|
|
600
|
+
*/
|
|
601
|
+
interface IgniterAgentBuiltTool<TName extends string = string, TInputSchema = unknown, TOutputSchema = undefined, TExecute = (params: TInputSchema, options: IgniterAgentToolExecuteOptions) => TOutputSchema extends undefined ? Promise<unknown> : Promise<TOutputSchema>> {
|
|
602
|
+
/** The tool's unique name */
|
|
603
|
+
readonly name: TName;
|
|
604
|
+
/**
|
|
605
|
+
* Human-readable description of what the tool does.
|
|
606
|
+
*
|
|
607
|
+
* @description
|
|
608
|
+
* This is shown to the AI model to help it decide when to use the tool.
|
|
609
|
+
* Should be clear, concise, and explain the tool's purpose and capabilities.
|
|
610
|
+
*/
|
|
611
|
+
description: string;
|
|
612
|
+
/**
|
|
613
|
+
* Zod schema defining the tool's input parameters.
|
|
614
|
+
*
|
|
615
|
+
* @description
|
|
616
|
+
* The schema is used for validation and also informs the AI model
|
|
617
|
+
* about what parameters are available and their types.
|
|
618
|
+
*/
|
|
619
|
+
inputSchema: z.ZodSchema<TInputSchema>;
|
|
620
|
+
/**
|
|
621
|
+
* (Optional) Zod schema defining the tool's output/result.
|
|
622
|
+
*
|
|
623
|
+
* @description
|
|
624
|
+
* If provided, the tool's output will be validated against this schema.
|
|
625
|
+
* Helps ensure consistent and expected results from tool execution.
|
|
626
|
+
*/
|
|
627
|
+
outputSchema?: z.ZodSchema<TOutputSchema>;
|
|
628
|
+
/**
|
|
629
|
+
* The function that executes the tool's logic.
|
|
630
|
+
*
|
|
631
|
+
* @description
|
|
632
|
+
* Receives the validated parameters and optional execution options.
|
|
633
|
+
* Can be async for operations that require waiting.
|
|
634
|
+
*
|
|
635
|
+
* @param params - The validated input parameters
|
|
636
|
+
* @param options - Execution options including abort signal
|
|
637
|
+
* @returns The tool's result
|
|
638
|
+
*/
|
|
639
|
+
execute: TExecute;
|
|
640
|
+
$Infer: {
|
|
641
|
+
Name: TName;
|
|
642
|
+
Description: string;
|
|
643
|
+
Input: TInputSchema;
|
|
644
|
+
Output: TOutputSchema;
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Partial configuration for MCP client during construction.
|
|
649
|
+
*
|
|
650
|
+
* @description
|
|
651
|
+
* Used internally by the MCP builder to track partial configuration
|
|
652
|
+
* before all required fields are set.
|
|
653
|
+
*
|
|
654
|
+
* @typeParam TType - The transport type
|
|
655
|
+
* @typeParam TName - The configuration name
|
|
656
|
+
*
|
|
657
|
+
* @internal
|
|
658
|
+
*/
|
|
659
|
+
type IgniterAgentMCPPartialConfig<TType extends IgniterAgentToolsetType = IgniterAgentToolsetType, TName extends string = string> = Partial<IgniterAgentMCPConfigUnion<TName>> & {
|
|
660
|
+
type?: TType;
|
|
661
|
+
};
|
|
662
|
+
/**
|
|
663
|
+
* Result object returned by the Agent builder's build() method.
|
|
664
|
+
*
|
|
665
|
+
* @description
|
|
666
|
+
* Provides the runtime interface for interacting with a built agent.
|
|
667
|
+
* Includes methods for starting the agent, generating responses,
|
|
668
|
+
* and accessing configuration.
|
|
669
|
+
*
|
|
670
|
+
* @typeParam TContextSchema - The context schema type
|
|
671
|
+
* @typeParam TToolsets - The toolsets record type
|
|
672
|
+
* @typeParam TModel - The language model type
|
|
673
|
+
* @typeParam TInstructions - The prompt template type
|
|
674
|
+
*
|
|
675
|
+
* @example
|
|
676
|
+
* ```typescript
|
|
677
|
+
* const agent = IgniterAgent.create('assistant')
|
|
678
|
+
* .withModel(openai('gpt-4'))
|
|
679
|
+
* .build();
|
|
680
|
+
*
|
|
681
|
+
* // Start the agent (initializes MCP connections)
|
|
682
|
+
* await agent.start();
|
|
683
|
+
*
|
|
684
|
+
* // Generate a response
|
|
685
|
+
* const result = await agent.generate({
|
|
686
|
+
* messages: [{ role: 'user', content: 'Hello!' }]
|
|
687
|
+
* });
|
|
688
|
+
*
|
|
689
|
+
* // Stream a response
|
|
690
|
+
* const stream = await agent.stream({
|
|
691
|
+
* messages: [{ role: 'user', content: 'Tell me a story' }]
|
|
692
|
+
* });
|
|
693
|
+
* ```
|
|
694
|
+
*
|
|
695
|
+
* @public
|
|
696
|
+
*/
|
|
697
|
+
interface IgniterAgentBuiltAgent<TContextSchema extends z.ZodSchema = z.ZodSchema, TToolsets extends Record<string, IgniterAgentToolset$1> = Record<string, IgniterAgentToolset$1>, TModel extends LanguageModel = LanguageModel, TInstructions extends IgniterAgentPromptTemplate = IgniterAgentPromptTemplate> {
|
|
698
|
+
/**
|
|
699
|
+
* Attaches a logger instance to the agent.
|
|
700
|
+
*/
|
|
701
|
+
attachLogger(logger?: IgniterLogger): void;
|
|
702
|
+
/**
|
|
703
|
+
* Attaches a telemetry manager to the agent.
|
|
704
|
+
*/
|
|
705
|
+
attachTelemetry(telemetry?: IgniterTelemetryManager): void;
|
|
706
|
+
/**
|
|
707
|
+
* Attaches hook callbacks to the agent.
|
|
708
|
+
*/
|
|
709
|
+
attachHooks(hooks?: IgniterAgentHooks): void;
|
|
710
|
+
/**
|
|
711
|
+
* Returns the agent name.
|
|
712
|
+
*/
|
|
713
|
+
getName(): string;
|
|
714
|
+
/**
|
|
715
|
+
* Starts the agent and initializes all MCP connections.
|
|
716
|
+
*
|
|
717
|
+
* @description
|
|
718
|
+
* Must be called before using the agent if MCP toolsets are configured.
|
|
719
|
+
* Establishes connections to all configured MCP servers and populates
|
|
720
|
+
* the toolsets with available tools.
|
|
721
|
+
*
|
|
722
|
+
* @returns The initialized toolsets record
|
|
723
|
+
*
|
|
724
|
+
* @example
|
|
725
|
+
* ```typescript
|
|
726
|
+
* const toolsets = await agent.start();
|
|
727
|
+
* console.log('Connected toolsets:', Object.keys(toolsets));
|
|
728
|
+
* ```
|
|
729
|
+
*/
|
|
730
|
+
start(): Promise<void>;
|
|
731
|
+
/**
|
|
732
|
+
* Stops the agent and disconnects MCP toolsets.
|
|
733
|
+
*/
|
|
734
|
+
stop(): Promise<void>;
|
|
735
|
+
/**
|
|
736
|
+
* Generates a single response from the agent.
|
|
737
|
+
*
|
|
738
|
+
* @description
|
|
739
|
+
* Sends messages to the agent and waits for a complete response.
|
|
740
|
+
* Supports context options for dynamic prompt generation.
|
|
741
|
+
*
|
|
742
|
+
* @param input - The call parameters including messages and options
|
|
743
|
+
* @returns The generation result with response and tool calls
|
|
744
|
+
*
|
|
745
|
+
* @example
|
|
746
|
+
* ```typescript
|
|
747
|
+
* const result = await agent.generate({
|
|
748
|
+
* messages: [
|
|
749
|
+
* { role: 'user', content: 'What is TypeScript?' }
|
|
750
|
+
* ],
|
|
751
|
+
* options: { userId: 'user_123' }
|
|
752
|
+
* });
|
|
753
|
+
*
|
|
754
|
+
* console.log('Response:', result.text);
|
|
755
|
+
* ```
|
|
756
|
+
*/
|
|
757
|
+
generate(input: AgentCallParameters<z.infer<TContextSchema>>): Promise<unknown>;
|
|
758
|
+
/**
|
|
759
|
+
* Streams a response from the agent.
|
|
760
|
+
*
|
|
761
|
+
* @description
|
|
762
|
+
* Sends messages to the agent and returns a stream of response chunks.
|
|
763
|
+
* Ideal for real-time UI updates and long responses.
|
|
764
|
+
*
|
|
765
|
+
* @param input - The stream parameters including messages and options
|
|
766
|
+
* @returns A stream of response chunks
|
|
767
|
+
*
|
|
768
|
+
* @example
|
|
769
|
+
* ```typescript
|
|
770
|
+
* const stream = await agent.stream({
|
|
771
|
+
* messages: [
|
|
772
|
+
* { role: 'user', content: 'Write a poem about coding' }
|
|
773
|
+
* ]
|
|
774
|
+
* });
|
|
775
|
+
*
|
|
776
|
+
* for await (const chunk of stream) {
|
|
777
|
+
* process.stdout.write(chunk);
|
|
778
|
+
* }
|
|
779
|
+
* ```
|
|
780
|
+
*/
|
|
781
|
+
stream(input: AgentStreamParameters<z.infer<TContextSchema>, ToolSet>): Promise<unknown>;
|
|
782
|
+
/**
|
|
783
|
+
* Gets all registered toolsets.
|
|
784
|
+
*
|
|
785
|
+
* @returns The toolsets record
|
|
786
|
+
*/
|
|
787
|
+
getToolsets(): TToolsets;
|
|
788
|
+
/**
|
|
789
|
+
* Gets the configured language model.
|
|
790
|
+
*
|
|
791
|
+
* @returns The language model instance
|
|
792
|
+
*/
|
|
793
|
+
getModel(): TModel;
|
|
794
|
+
/**
|
|
795
|
+
* Gets the configured instructions.
|
|
796
|
+
*
|
|
797
|
+
* @returns The prompt template instance
|
|
798
|
+
*/
|
|
799
|
+
getInstructions(): TInstructions;
|
|
800
|
+
/**
|
|
801
|
+
* Gets the context schema.
|
|
802
|
+
*
|
|
803
|
+
* @returns The Zod schema for context validation
|
|
804
|
+
*/
|
|
805
|
+
getContextSchema(): TContextSchema;
|
|
806
|
+
/**
|
|
807
|
+
* Optional memory runtime for persistence operations.
|
|
808
|
+
*/
|
|
809
|
+
memory?: IgniterAgentMemoryRuntime;
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Options passed to tool execution handlers.
|
|
813
|
+
*
|
|
814
|
+
* @description
|
|
815
|
+
* Contains metadata and utilities available during tool execution.
|
|
816
|
+
*
|
|
817
|
+
* @public
|
|
818
|
+
*/
|
|
819
|
+
interface IgniterAgentToolExecuteOptions {
|
|
820
|
+
/**
|
|
821
|
+
* Abort signal for cancellation support.
|
|
822
|
+
*
|
|
823
|
+
* @description
|
|
824
|
+
* Can be used to abort long-running operations when the
|
|
825
|
+
* agent request is cancelled.
|
|
826
|
+
*/
|
|
827
|
+
abortSignal?: AbortSignal;
|
|
828
|
+
/**
|
|
829
|
+
* Additional context from the agent runtime.
|
|
830
|
+
*/
|
|
831
|
+
[key: string]: unknown;
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Tool definition for adding to a Toolset.
|
|
835
|
+
*
|
|
836
|
+
* @description
|
|
837
|
+
* Defines the structure of a tool that can be built with
|
|
838
|
+
* {@link IgniterAgentToolBuilder} and added to a toolset.
|
|
839
|
+
*
|
|
840
|
+
* @typeParam TInputSchema - The parameters schema type
|
|
841
|
+
* @typeParam TOutputSchema - The return type of the tool
|
|
842
|
+
*
|
|
843
|
+
* @example
|
|
844
|
+
* ```typescript
|
|
845
|
+
* const weatherTool: IgniterAgentToolDefinition = {
|
|
846
|
+
* description: 'Gets current weather for a city',
|
|
847
|
+
* inputSchema: z.object({
|
|
848
|
+
* city: z.string().describe('City name'),
|
|
849
|
+
* units: z.enum(['celsius', 'fahrenheit']).optional()
|
|
850
|
+
* }),
|
|
851
|
+
* execute: async ({ city, units }) => {
|
|
852
|
+
* const weather = await fetchWeather(city, units);
|
|
853
|
+
* return { temperature: weather.temp, conditions: weather.desc };
|
|
854
|
+
* }
|
|
855
|
+
* };
|
|
856
|
+
* ```
|
|
857
|
+
*
|
|
858
|
+
* @public
|
|
859
|
+
*/
|
|
860
|
+
interface IgniterAgentToolDefinition<TInputSchema = unknown, TOutputSchema = unknown> {
|
|
861
|
+
/**
|
|
862
|
+
* Human-readable description of what the tool does.
|
|
863
|
+
*
|
|
864
|
+
* @description
|
|
865
|
+
* This is shown to the AI model to help it decide when to use the tool.
|
|
866
|
+
* Should be clear, concise, and explain the tool's purpose and capabilities.
|
|
867
|
+
*/
|
|
868
|
+
description: string;
|
|
869
|
+
/**
|
|
870
|
+
* Zod schema defining the tool's input parameters.
|
|
871
|
+
*
|
|
872
|
+
* @description
|
|
873
|
+
* The schema is used for validation and also informs the AI model
|
|
874
|
+
* about what parameters are available and their types.
|
|
875
|
+
*/
|
|
876
|
+
inputSchema: z.ZodSchema<TInputSchema>;
|
|
877
|
+
/**
|
|
878
|
+
* (Optional) Zod schema defining the tool's output/result.
|
|
879
|
+
*
|
|
880
|
+
* @description
|
|
881
|
+
* If provided, the tool's output will be validated against this schema.
|
|
882
|
+
* Helps ensure consistent and expected results from tool execution.
|
|
883
|
+
*/
|
|
884
|
+
outputSchema?: z.ZodSchema<TOutputSchema>;
|
|
885
|
+
/**
|
|
886
|
+
* The function that executes the tool's logic.
|
|
887
|
+
*
|
|
888
|
+
* @description
|
|
889
|
+
* Receives the validated parameters and optional execution options.
|
|
890
|
+
* Can be async for operations that require waiting.
|
|
891
|
+
*
|
|
892
|
+
* @param params - The validated input parameters
|
|
893
|
+
* @param options - Execution options including abort signal
|
|
894
|
+
* @returns The tool's result
|
|
895
|
+
*/
|
|
896
|
+
execute: (params: TInputSchema, options?: IgniterAgentToolExecuteOptions) => TOutputSchema | Promise<TOutputSchema>;
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
/**
|
|
900
|
+
* Status of an agent in the manager.
|
|
901
|
+
*
|
|
902
|
+
* @public
|
|
903
|
+
*/
|
|
904
|
+
type IgniterAgentStatus = "idle" | "starting" | "running" | "stopped" | "error";
|
|
905
|
+
/**
|
|
906
|
+
* Information about a registered agent.
|
|
907
|
+
*
|
|
908
|
+
* @public
|
|
909
|
+
*/
|
|
910
|
+
interface IgniterAgentInfo {
|
|
911
|
+
/** The agent's unique name */
|
|
912
|
+
name: string;
|
|
913
|
+
/** Current status */
|
|
914
|
+
status: IgniterAgentStatus;
|
|
915
|
+
/** When the agent was registered */
|
|
916
|
+
registeredAt: Date;
|
|
917
|
+
/** When the agent was last started */
|
|
918
|
+
startedAt?: Date;
|
|
919
|
+
/** Error if agent failed */
|
|
920
|
+
error?: Error;
|
|
921
|
+
/** Number of registered toolsets */
|
|
922
|
+
toolsetCount: number;
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* Options for the agent manager.
|
|
926
|
+
*
|
|
927
|
+
* @public
|
|
928
|
+
*/
|
|
929
|
+
interface IgniterAgentManagerOptions<TAgentRegistry extends Record<string, IgniterAgentBuiltAgent> = Record<string, IgniterAgentBuiltAgent>> extends IgniterAgentHooks {
|
|
930
|
+
/**
|
|
931
|
+
* Pre-registered agents.
|
|
932
|
+
* @defaultValue {}
|
|
933
|
+
*/
|
|
934
|
+
agents: TAgentRegistry;
|
|
935
|
+
/**
|
|
936
|
+
* Whether to auto-start agents when registered.
|
|
937
|
+
* @defaultValue false
|
|
938
|
+
*/
|
|
939
|
+
autoStart?: boolean;
|
|
940
|
+
/**
|
|
941
|
+
* Whether to continue starting other agents if one fails.
|
|
942
|
+
* @defaultValue true
|
|
943
|
+
*/
|
|
944
|
+
continueOnError?: boolean;
|
|
945
|
+
/**
|
|
946
|
+
* Logger instance for logging.
|
|
947
|
+
* @defaultValue undefined
|
|
948
|
+
*/
|
|
949
|
+
logger?: IgniterLogger;
|
|
950
|
+
/**
|
|
951
|
+
* Optional telemetry manager for observability.
|
|
952
|
+
*/
|
|
953
|
+
telemetry?: IgniterTelemetryManager;
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
/**
|
|
957
|
+
* Shared type utilities for `@igniter-js/agents`.
|
|
958
|
+
*/
|
|
959
|
+
|
|
960
|
+
/**
|
|
961
|
+
* Extracts the inferred type from a Zod schema.
|
|
962
|
+
*
|
|
963
|
+
* @public
|
|
964
|
+
*/
|
|
965
|
+
type InferZodSchema<T extends z.ZodSchema> = z.infer<T>;
|
|
966
|
+
/**
|
|
967
|
+
* Makes all properties in T optional recursively.
|
|
968
|
+
*
|
|
969
|
+
* @public
|
|
970
|
+
*/
|
|
971
|
+
type DeepPartial<T> = {
|
|
972
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
973
|
+
};
|
|
974
|
+
/**
|
|
975
|
+
* Makes all properties in T required recursively.
|
|
976
|
+
*
|
|
977
|
+
* @public
|
|
978
|
+
*/
|
|
979
|
+
type DeepRequired<T> = {
|
|
980
|
+
[P in keyof T]-?: T[P] extends object ? DeepRequired<T[P]> : T[P];
|
|
981
|
+
};
|
|
982
|
+
/**
|
|
983
|
+
* Extracts keys from T that have values of type V.
|
|
984
|
+
*
|
|
985
|
+
* @public
|
|
986
|
+
*/
|
|
987
|
+
type KeysOfType<T, V> = {
|
|
988
|
+
[K in keyof T]: T[K] extends V ? K : never;
|
|
989
|
+
}[keyof T];
|
|
990
|
+
|
|
991
|
+
/**
|
|
992
|
+
* @fileoverview Core agent manager for lifecycle and orchestration.
|
|
993
|
+
* This module provides centralized management for IgniterAgent instances.
|
|
994
|
+
*
|
|
995
|
+
* @description
|
|
996
|
+
* The IgniterAgentManager provides utilities for:
|
|
997
|
+
* - Managing multiple agent instances
|
|
998
|
+
* - Coordinating agent lifecycle (start, stop)
|
|
999
|
+
* - Monitoring agent health and status
|
|
1000
|
+
* - Routing requests to appropriate agents
|
|
1001
|
+
*
|
|
1002
|
+
* @example
|
|
1003
|
+
* ```typescript
|
|
1004
|
+
* import { IgniterAgentManager } from '@igniter-js/agents';
|
|
1005
|
+
*
|
|
1006
|
+
* // Create a manager
|
|
1007
|
+
* const manager = new IgniterAgentManager();
|
|
1008
|
+
*
|
|
1009
|
+
* // Register agents
|
|
1010
|
+
* manager.register('support', supportAgent);
|
|
1011
|
+
* manager.register('sales', salesAgent);
|
|
1012
|
+
*
|
|
1013
|
+
* // Start all agents
|
|
1014
|
+
* await manager.startAll();
|
|
1015
|
+
*
|
|
1016
|
+
* // Route to specific agent
|
|
1017
|
+
* const agent = manager.get('support');
|
|
1018
|
+
* const response = await agent.generate({ messages: [...] });
|
|
1019
|
+
* ```
|
|
1020
|
+
*
|
|
1021
|
+
* @module core/manager
|
|
1022
|
+
* @packageDocumentation
|
|
1023
|
+
*/
|
|
1024
|
+
|
|
1025
|
+
/**
|
|
1026
|
+
* Manager for coordinating multiple IgniterAgent instances.
|
|
1027
|
+
*
|
|
1028
|
+
* @description
|
|
1029
|
+
* The IgniterAgentManager provides a centralized way to manage multiple
|
|
1030
|
+
* agent instances, handling their lifecycle and providing routing capabilities.
|
|
1031
|
+
*
|
|
1032
|
+
* **Key Features:**
|
|
1033
|
+
* - Register and manage multiple agents
|
|
1034
|
+
* - Batch start/stop operations
|
|
1035
|
+
* - Health monitoring
|
|
1036
|
+
* - Request routing
|
|
1037
|
+
*
|
|
1038
|
+
* @example
|
|
1039
|
+
* ```typescript
|
|
1040
|
+
* import { IgniterAgentManager, IgniterAgent } from '@igniter-js/agents';
|
|
1041
|
+
*
|
|
1042
|
+
* // Create agents
|
|
1043
|
+
* const supportAgent = IgniterAgent.create('support')
|
|
1044
|
+
* .withModel(openai('gpt-4'))
|
|
1045
|
+
* .build();
|
|
1046
|
+
*
|
|
1047
|
+
* const codeAgent = IgniterAgent.create('code')
|
|
1048
|
+
* .withModel(openai('gpt-4-turbo'))
|
|
1049
|
+
* .addToolset(codeToolset)
|
|
1050
|
+
* .build();
|
|
1051
|
+
*
|
|
1052
|
+
* // Create manager and register agents
|
|
1053
|
+
* const manager = new IgniterAgentManager({
|
|
1054
|
+
* continueOnError: true,
|
|
1055
|
+
* onAgentStart: (name) => console.log(`Agent ${name} started`),
|
|
1056
|
+
* onAgentError: (name, err) => console.error(`Agent ${name} failed:`, err)
|
|
1057
|
+
* });
|
|
1058
|
+
*
|
|
1059
|
+
* manager.register('support', supportAgent);
|
|
1060
|
+
* manager.register('code', codeAgent);
|
|
1061
|
+
*
|
|
1062
|
+
* // Start all agents
|
|
1063
|
+
* await manager.startAll();
|
|
1064
|
+
*
|
|
1065
|
+
* // Use specific agent
|
|
1066
|
+
* const agent = manager.get('code');
|
|
1067
|
+
* const result = await agent.generate({
|
|
1068
|
+
* messages: [{ role: 'user', content: 'Write a test' }]
|
|
1069
|
+
* });
|
|
1070
|
+
*
|
|
1071
|
+
* // Get status
|
|
1072
|
+
* console.log(manager.getStatus());
|
|
1073
|
+
* ```
|
|
1074
|
+
*
|
|
1075
|
+
* @public
|
|
1076
|
+
*/
|
|
1077
|
+
declare class IgniterAgentManagerCore<TAgentRegistry extends Record<string, IgniterAgentBuiltAgent> = Record<string, IgniterAgentBuiltAgent>> {
|
|
1078
|
+
/**
|
|
1079
|
+
* Agent statuses.
|
|
1080
|
+
* @internal
|
|
1081
|
+
*/
|
|
1082
|
+
private readonly _statuses;
|
|
1083
|
+
/**
|
|
1084
|
+
* Manager options.
|
|
1085
|
+
* @internal
|
|
1086
|
+
*/
|
|
1087
|
+
private readonly _options;
|
|
1088
|
+
/**
|
|
1089
|
+
* Creates a new IgniterAgentManager.
|
|
1090
|
+
*
|
|
1091
|
+
* @param options - Manager configuration options
|
|
1092
|
+
*
|
|
1093
|
+
* @example
|
|
1094
|
+
* ```typescript
|
|
1095
|
+
* const manager = new IgniterAgentManager({
|
|
1096
|
+
* autoStart: false,
|
|
1097
|
+
* continueOnError: true
|
|
1098
|
+
* });
|
|
1099
|
+
* ```
|
|
1100
|
+
*/
|
|
1101
|
+
constructor(options: IgniterAgentManagerOptions<TAgentRegistry>);
|
|
1102
|
+
private applyManagerContext;
|
|
1103
|
+
/**
|
|
1104
|
+
* Creates a new IgniterAgentManager with default options.
|
|
1105
|
+
* @param options - Manager configuration options
|
|
1106
|
+
* @returns A new IgniterAgentManager instance
|
|
1107
|
+
* @example
|
|
1108
|
+
* ```typescript
|
|
1109
|
+
* const manager = IgniterAgentManager.create({
|
|
1110
|
+
* autoStart: true
|
|
1111
|
+
* });
|
|
1112
|
+
* ```
|
|
1113
|
+
*/
|
|
1114
|
+
static create(): IgniterAgentManagerCore;
|
|
1115
|
+
/**
|
|
1116
|
+
* Registers an agent with the manager.
|
|
1117
|
+
*
|
|
1118
|
+
* @description
|
|
1119
|
+
* Adds an agent to the manager's registry. If `autoStart` is enabled,
|
|
1120
|
+
* the agent will be started immediately after registration.
|
|
1121
|
+
*
|
|
1122
|
+
* @param name - Unique name for the agent
|
|
1123
|
+
* @param agent - The built agent instance
|
|
1124
|
+
* @returns This manager for chaining
|
|
1125
|
+
* @throws {IgniterAgentError} If an agent with the name already exists
|
|
1126
|
+
*
|
|
1127
|
+
* @example
|
|
1128
|
+
* ```typescript
|
|
1129
|
+
* manager
|
|
1130
|
+
* .register('support', supportAgent)
|
|
1131
|
+
* .register('sales', salesAgent);
|
|
1132
|
+
* ```
|
|
1133
|
+
*/
|
|
1134
|
+
register(name: string, agent: IgniterAgentBuiltAgent): this;
|
|
1135
|
+
/**
|
|
1136
|
+
* Unregisters an agent from the manager.
|
|
1137
|
+
*
|
|
1138
|
+
* @param name - The agent name to unregister
|
|
1139
|
+
* @returns True if the agent was unregistered
|
|
1140
|
+
*
|
|
1141
|
+
* @example
|
|
1142
|
+
* ```typescript
|
|
1143
|
+
* manager.unregister('old-agent');
|
|
1144
|
+
* ```
|
|
1145
|
+
*/
|
|
1146
|
+
unregister(name: string): boolean;
|
|
1147
|
+
/**
|
|
1148
|
+
* Checks if an agent is registered.
|
|
1149
|
+
*
|
|
1150
|
+
* @param name - The agent name to check
|
|
1151
|
+
* @returns True if the agent is registered
|
|
1152
|
+
*/
|
|
1153
|
+
has(name: string): boolean;
|
|
1154
|
+
/**
|
|
1155
|
+
* Starts a specific agent.
|
|
1156
|
+
*
|
|
1157
|
+
* @description
|
|
1158
|
+
* Initializes the agent's MCP connections and prepares it for use.
|
|
1159
|
+
*
|
|
1160
|
+
* @param name - The agent name to start
|
|
1161
|
+
* @returns The agent's toolsets after initialization
|
|
1162
|
+
* @throws {IgniterAgentError} If the agent is not found
|
|
1163
|
+
*
|
|
1164
|
+
* @example
|
|
1165
|
+
* ```typescript
|
|
1166
|
+
* const toolsets = await manager.start('support');
|
|
1167
|
+
* console.log('Connected toolsets:', Object.keys(toolsets));
|
|
1168
|
+
* ```
|
|
1169
|
+
*/
|
|
1170
|
+
start(name: string): Promise<IgniterAgentBuiltAgent>;
|
|
1171
|
+
/**
|
|
1172
|
+
* Starts all registered agents.
|
|
1173
|
+
*
|
|
1174
|
+
* @description
|
|
1175
|
+
* Initializes all agents in parallel. If `continueOnError` is true,
|
|
1176
|
+
* failed agents won't prevent others from starting.
|
|
1177
|
+
*
|
|
1178
|
+
* @returns Map of agent names to their results (toolsets or errors)
|
|
1179
|
+
*
|
|
1180
|
+
* @example
|
|
1181
|
+
* ```typescript
|
|
1182
|
+
* const results = await manager.startAll();
|
|
1183
|
+
*
|
|
1184
|
+
* for (const [name, result] of results) {
|
|
1185
|
+
* if (result instanceof Error) {
|
|
1186
|
+
* console.error(`${name} failed:`, result.message);
|
|
1187
|
+
* } else {
|
|
1188
|
+
* console.log(`${name} started with ${Object.keys(result).length} toolsets`);
|
|
1189
|
+
* }
|
|
1190
|
+
* }
|
|
1191
|
+
* ```
|
|
1192
|
+
*/
|
|
1193
|
+
startAll(): Promise<Map<string, Record<string, IgniterAgentToolset$1> | Error>>;
|
|
1194
|
+
/**
|
|
1195
|
+
* Gets a registered agent by name.
|
|
1196
|
+
*
|
|
1197
|
+
* @param name - The agent name
|
|
1198
|
+
* @returns The agent instance
|
|
1199
|
+
* @throws {IgniterAgentError} If the agent is not found
|
|
1200
|
+
*
|
|
1201
|
+
* @example
|
|
1202
|
+
* ```typescript
|
|
1203
|
+
* const agent = manager.get('support');
|
|
1204
|
+
* const response = await agent.generate({ messages: [...] });
|
|
1205
|
+
* ```
|
|
1206
|
+
*/
|
|
1207
|
+
get<TName extends string>(name: TName): TAgentRegistry[TName];
|
|
1208
|
+
/**
|
|
1209
|
+
* Gets an agent if it exists, undefined otherwise.
|
|
1210
|
+
*
|
|
1211
|
+
* @param name - The agent name
|
|
1212
|
+
* @returns The agent instance or undefined
|
|
1213
|
+
*/
|
|
1214
|
+
tryGet<TName extends string>(name: TName): TAgentRegistry[TName] | undefined;
|
|
1215
|
+
/**
|
|
1216
|
+
* Gets all registered agent names.
|
|
1217
|
+
*
|
|
1218
|
+
* @returns Array of agent names
|
|
1219
|
+
*/
|
|
1220
|
+
getNames(): string[];
|
|
1221
|
+
/**
|
|
1222
|
+
* Gets the number of registered agents.
|
|
1223
|
+
*
|
|
1224
|
+
* @returns Agent count
|
|
1225
|
+
*/
|
|
1226
|
+
get size(): number;
|
|
1227
|
+
/**
|
|
1228
|
+
* Gets information about a specific agent.
|
|
1229
|
+
*
|
|
1230
|
+
* @param name - The agent name
|
|
1231
|
+
* @returns Agent information or undefined
|
|
1232
|
+
*/
|
|
1233
|
+
getInfo(name: string): IgniterAgentInfo | undefined;
|
|
1234
|
+
/**
|
|
1235
|
+
* Gets status information for all agents.
|
|
1236
|
+
*
|
|
1237
|
+
* @returns Array of agent information objects
|
|
1238
|
+
*
|
|
1239
|
+
* @example
|
|
1240
|
+
* ```typescript
|
|
1241
|
+
* const status = manager.getStatus();
|
|
1242
|
+
*
|
|
1243
|
+
* for (const info of status) {
|
|
1244
|
+
* console.log(`${info.name}: ${info.status}`);
|
|
1245
|
+
* }
|
|
1246
|
+
* ```
|
|
1247
|
+
*/
|
|
1248
|
+
getStatus(): IgniterAgentInfo[];
|
|
1249
|
+
/**
|
|
1250
|
+
* Checks if all agents are running.
|
|
1251
|
+
*
|
|
1252
|
+
* @returns True if all agents are in 'running' status
|
|
1253
|
+
*/
|
|
1254
|
+
isAllRunning(): boolean;
|
|
1255
|
+
/**
|
|
1256
|
+
* Gets agents that are in error state.
|
|
1257
|
+
*
|
|
1258
|
+
* @returns Array of agent info for failed agents
|
|
1259
|
+
*/
|
|
1260
|
+
getFailedAgents(): IgniterAgentInfo[];
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
/**
|
|
1264
|
+
* @fileoverview Memory runtime for IgniterAgent.
|
|
1265
|
+
* @module core/memory
|
|
1266
|
+
*/
|
|
1267
|
+
|
|
1268
|
+
/**
|
|
1269
|
+
* Memory runtime wrapper that adds logging and telemetry to provider operations.
|
|
1270
|
+
*
|
|
1271
|
+
* @public
|
|
1272
|
+
*/
|
|
1273
|
+
declare class IgniterAgentMemoryCore implements IgniterAgentMemoryRuntime {
|
|
1274
|
+
private readonly provider;
|
|
1275
|
+
private readonly agentName;
|
|
1276
|
+
private readonly logger?;
|
|
1277
|
+
private readonly telemetry?;
|
|
1278
|
+
constructor(config: IgniterAgentMemoryConfig, agentName: string, logger?: IgniterLogger, telemetry?: IgniterTelemetryManager);
|
|
1279
|
+
private getBaseAttributes;
|
|
1280
|
+
private emitStart;
|
|
1281
|
+
private emitSuccess;
|
|
1282
|
+
private emitError;
|
|
1283
|
+
private runOperation;
|
|
1284
|
+
getWorkingMemory(params: IgniterAgentWorkingMemoryParams): Promise<IgniterAgentWorkingMemory | null>;
|
|
1285
|
+
updateWorkingMemory(params: IgniterAgentUpdateWorkingMemoryParams): Promise<void>;
|
|
1286
|
+
saveMessage(message: IgniterAgentConversationMessage): Promise<void>;
|
|
1287
|
+
getMessages<T = IgniterAgentUIMessage>(params: IgniterAgentGetMessagesParams): Promise<T[]>;
|
|
1288
|
+
saveChat(chat: IgniterAgentChatSession): Promise<void>;
|
|
1289
|
+
getChats(params: IgniterAgentGetChatsParams): Promise<IgniterAgentChatSession[]>;
|
|
1290
|
+
getChat(chatId: string): Promise<IgniterAgentChatSession | null>;
|
|
1291
|
+
updateChatTitle(chatId: string, title: string): Promise<void>;
|
|
1292
|
+
deleteChat(chatId: string): Promise<void>;
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
declare class IgniterAgentCore<TAgentName extends string = string, TAgentModel extends LanguageModel = LanguageModel, TAgentInstructions extends IgniterAgentPromptTemplate = IgniterAgentPromptTemplate, TAgentToolsets extends Record<string, IgniterAgentToolset$1> = Record<string, IgniterAgentToolset$1>, TAgentMCPConfigs extends Record<string, IgniterAgentMCPConfigUnion> = Record<string, IgniterAgentMCPConfigUnion>, TAgentContextSchema extends z.ZodSchema = z.ZodSchema> {
|
|
1296
|
+
private _agent;
|
|
1297
|
+
private logger?;
|
|
1298
|
+
private telemetry?;
|
|
1299
|
+
private hooks;
|
|
1300
|
+
memory?: IgniterAgentMemoryCore;
|
|
1301
|
+
constructor(agent: IgniterAgentConfig<TAgentName, TAgentModel, TAgentInstructions, TAgentToolsets, TAgentMCPConfigs, TAgentContextSchema>);
|
|
1302
|
+
/**
|
|
1303
|
+
* Attaches a logger instance to the agent.
|
|
1304
|
+
*/
|
|
1305
|
+
attachLogger(logger?: IgniterLogger): void;
|
|
1306
|
+
/**
|
|
1307
|
+
* Attaches a telemetry manager to the agent.
|
|
1308
|
+
*/
|
|
1309
|
+
attachTelemetry(telemetry?: IgniterTelemetryManager): void;
|
|
1310
|
+
/**
|
|
1311
|
+
* Attaches hook callbacks to the agent.
|
|
1312
|
+
*/
|
|
1313
|
+
attachHooks(hooks?: IgniterAgentHooks): void;
|
|
1314
|
+
/**
|
|
1315
|
+
* Returns the agent name.
|
|
1316
|
+
*/
|
|
1317
|
+
getName(): string;
|
|
1318
|
+
/**
|
|
1319
|
+
* Starts the agent by initializing all MCP connections.
|
|
1320
|
+
*/
|
|
1321
|
+
start(): Promise<void>;
|
|
1322
|
+
/**
|
|
1323
|
+
* Stops the agent by disconnecting MCP toolsets.
|
|
1324
|
+
*/
|
|
1325
|
+
stop(): Promise<void>;
|
|
1326
|
+
/**
|
|
1327
|
+
* Generates a response from the agent.
|
|
1328
|
+
*/
|
|
1329
|
+
generate(input: AgentCallParameters<z.infer<TAgentContextSchema>>): Promise<any>;
|
|
1330
|
+
/**
|
|
1331
|
+
* Streams a response from the agent.
|
|
1332
|
+
*/
|
|
1333
|
+
stream(input: AgentStreamParameters<z.infer<TAgentContextSchema>, ToolSet>): Promise<any>;
|
|
1334
|
+
/**
|
|
1335
|
+
* Gets all registered toolsets.
|
|
1336
|
+
*/
|
|
1337
|
+
getToolsets(): TAgentToolsets;
|
|
1338
|
+
/**
|
|
1339
|
+
* Gets the configured model.
|
|
1340
|
+
*/
|
|
1341
|
+
getModel(): TAgentModel;
|
|
1342
|
+
/**
|
|
1343
|
+
* Gets the configured instructions.
|
|
1344
|
+
*/
|
|
1345
|
+
getInstructions(): TAgentInstructions;
|
|
1346
|
+
/**
|
|
1347
|
+
* Gets the context schema.
|
|
1348
|
+
*/
|
|
1349
|
+
getContextSchema(): TAgentContextSchema;
|
|
1350
|
+
/**
|
|
1351
|
+
* Gets all registered tools from all toolsets.
|
|
1352
|
+
*/
|
|
1353
|
+
getTools(): ToolSet;
|
|
1354
|
+
private wrapToolExecution;
|
|
1355
|
+
private wrapStreamResult;
|
|
1356
|
+
private getErrorAttributes;
|
|
1357
|
+
private getAgentInstanceWithContext;
|
|
1358
|
+
private initializeMCPClient;
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
declare class IgniterAgentManagerBuilder<TAgentRegistry extends Record<string, IgniterAgentBuiltAgent> = Record<string, IgniterAgentBuiltAgent>> {
|
|
1362
|
+
private readonly _manager;
|
|
1363
|
+
private constructor();
|
|
1364
|
+
addAgent<TName extends string, TAgent extends IgniterAgentBuiltAgent>(name: TName, agent: TAgent): IgniterAgentManagerBuilder<TAgentRegistry & {
|
|
1365
|
+
[K in TName]: TAgent;
|
|
1366
|
+
}>;
|
|
1367
|
+
withLogger(logger: IgniterLogger): IgniterAgentManagerBuilder<TAgentRegistry>;
|
|
1368
|
+
withTelemetry(telemetry: IgniterTelemetryManager): IgniterAgentManagerBuilder<TAgentRegistry>;
|
|
1369
|
+
withAutoStart(autoStart: boolean): IgniterAgentManagerBuilder<TAgentRegistry>;
|
|
1370
|
+
withContinueOnError(continueOnError: boolean): IgniterAgentManagerBuilder<TAgentRegistry>;
|
|
1371
|
+
onAgentStart(callback: IgniterAgentHooks["onAgentStart"]): IgniterAgentManagerBuilder<TAgentRegistry>;
|
|
1372
|
+
onAgentError(callback: IgniterAgentHooks["onAgentError"]): IgniterAgentManagerBuilder<TAgentRegistry>;
|
|
1373
|
+
onToolCallStart(callback: (agentName: keyof TAgentRegistry, toolName: string, input: unknown) => void): IgniterAgentManagerBuilder<TAgentRegistry>;
|
|
1374
|
+
onToolCallEnd(callback: (agentName: keyof TAgentRegistry, toolName: string, output: unknown) => void): IgniterAgentManagerBuilder<TAgentRegistry>;
|
|
1375
|
+
onToolCallError(callback: (agentName: keyof TAgentRegistry, toolName: string, error: Error) => void): IgniterAgentManagerBuilder<TAgentRegistry>;
|
|
1376
|
+
onMCPStart(callback: (agentName: keyof TAgentRegistry, mcpName: string) => void): IgniterAgentManagerBuilder<TAgentRegistry>;
|
|
1377
|
+
onMCPError(callback: (agentName: string, mcpName: string, error: Error) => void): IgniterAgentManagerBuilder<TAgentRegistry>;
|
|
1378
|
+
static create(): IgniterAgentManagerBuilder<{}>;
|
|
1379
|
+
build(): IgniterAgentManagerCore<TAgentRegistry>;
|
|
1380
|
+
}
|
|
1381
|
+
/**
|
|
1382
|
+
* Alias for IgniterAgentManager for cleaner API.
|
|
1383
|
+
*
|
|
1384
|
+
* @description
|
|
1385
|
+
* Use `IgniterAgentManager.create()` as the primary entry point for managing agents.
|
|
1386
|
+
*
|
|
1387
|
+
* @example
|
|
1388
|
+
* ```typescript
|
|
1389
|
+
* import { IgniterAgentManager } from '@igniter-js/agents';
|
|
1390
|
+
*
|
|
1391
|
+
* const manager = IgniterAgentManager
|
|
1392
|
+
* .create()
|
|
1393
|
+
* .addAgent('assistant', assistantAgent)
|
|
1394
|
+
* .addAgent('code-helper', codeHelperAgent)
|
|
1395
|
+
* .withLogger(customLogger)
|
|
1396
|
+
* .onToolCallStart((agentName, toolName, input) => {
|
|
1397
|
+
* console.log(`[${agentName}] Tool ${toolName} called with input:`, input);
|
|
1398
|
+
* })
|
|
1399
|
+
* .build();
|
|
1400
|
+
* ```
|
|
1401
|
+
*
|
|
1402
|
+
* @public
|
|
1403
|
+
*/
|
|
1404
|
+
declare const IgniterAgentManager: {
|
|
1405
|
+
create: typeof IgniterAgentManagerBuilder.create;
|
|
1406
|
+
};
|
|
1407
|
+
/**
|
|
1408
|
+
* Type alias for the IgniterAgent class.
|
|
1409
|
+
* @public
|
|
1410
|
+
*/
|
|
1411
|
+
type IgniterAgentManager = typeof IgniterAgentManagerBuilder;
|
|
1412
|
+
|
|
1413
|
+
/**
|
|
1414
|
+
* @fileoverview Main Agent Builder for creating AI agents with tools and MCP support.
|
|
1415
|
+
* This module provides the primary fluent API for building IgniterAgent instances.
|
|
1416
|
+
*
|
|
1417
|
+
* @description
|
|
1418
|
+
* The IgniterAgentBuilder is the central class for creating AI agents. It provides
|
|
1419
|
+
* a type-safe fluent API for configuring all aspects of an agent including:
|
|
1420
|
+
* - Language model selection
|
|
1421
|
+
* - Custom toolsets
|
|
1422
|
+
* - MCP server connections
|
|
1423
|
+
* - Context schema validation
|
|
1424
|
+
* - Prompt instructions
|
|
1425
|
+
*
|
|
1426
|
+
* @example
|
|
1427
|
+
* ```typescript
|
|
1428
|
+
* import { IgniterAgent } from '@igniter-js/agents';
|
|
1429
|
+
* import { openai } from '@ai-sdk/openai';
|
|
1430
|
+
* import { z } from 'zod';
|
|
1431
|
+
*
|
|
1432
|
+
* const agent = IgniterAgent
|
|
1433
|
+
* .create('assistant')
|
|
1434
|
+
* .withModel(openai('gpt-4'))
|
|
1435
|
+
* .withContextSchema(z.object({
|
|
1436
|
+
* userId: z.string(),
|
|
1437
|
+
* chatId: z.string()
|
|
1438
|
+
* }))
|
|
1439
|
+
* .addToolset(myCustomToolset)
|
|
1440
|
+
* .addMCP(filesystemMCP)
|
|
1441
|
+
* .build();
|
|
1442
|
+
*
|
|
1443
|
+
* // Start the agent (initializes MCP connections)
|
|
1444
|
+
* await agent.start();
|
|
1445
|
+
*
|
|
1446
|
+
* // Generate a response
|
|
1447
|
+
* const result = await agent.generate({
|
|
1448
|
+
* messages: [{ role: 'user', content: 'Hello!' }],
|
|
1449
|
+
* options: { userId: 'user_123', chatId: 'chat_456' }
|
|
1450
|
+
* });
|
|
1451
|
+
* ```
|
|
1452
|
+
*
|
|
1453
|
+
* @module builders/agent
|
|
1454
|
+
* @packageDocumentation
|
|
1455
|
+
*/
|
|
1456
|
+
|
|
1457
|
+
/**
|
|
1458
|
+
* Fluent builder for creating AI agents.
|
|
1459
|
+
*
|
|
1460
|
+
* @description
|
|
1461
|
+
* The IgniterAgentBuilder provides a comprehensive fluent API for creating
|
|
1462
|
+
* AI agents with full TypeScript type inference. It supports:
|
|
1463
|
+
*
|
|
1464
|
+
* - **Multiple Language Models**: Works with any Vercel AI SDK compatible model
|
|
1465
|
+
* - **Custom Toolsets**: Register your own tools with automatic error handling
|
|
1466
|
+
* - **MCP Integration**: Connect to MCP servers for external tool providers
|
|
1467
|
+
* - **Context Schema**: Type-safe context validation with Zod
|
|
1468
|
+
* - **Dynamic Prompts**: Template-based prompt generation
|
|
1469
|
+
*
|
|
1470
|
+
* **Lifecycle:**
|
|
1471
|
+
* 1. Create the builder with `IgniterAgent.create()`
|
|
1472
|
+
* 2. Configure using fluent methods (`withModel`, etc.)
|
|
1473
|
+
* 3. Build with `.build()` to get the runtime agent
|
|
1474
|
+
* 4. Call `.start()` to initialize MCP connections
|
|
1475
|
+
* 5. Use `.generate()` or `.stream()` to interact with the agent
|
|
1476
|
+
*
|
|
1477
|
+
* @typeParam TAgentName - The agent's unique name type
|
|
1478
|
+
* @typeParam TAgentModel - The language model type
|
|
1479
|
+
* @typeParam TAgentInstructions - The prompt template type
|
|
1480
|
+
* @typeParam TAgentToolsets - Record of registered toolsets
|
|
1481
|
+
* @typeParam TAgentMCPConfigs - Record of MCP configurations
|
|
1482
|
+
* @typeParam TAgentContextSchema - The context schema type
|
|
1483
|
+
*
|
|
1484
|
+
* @example
|
|
1485
|
+
* ```typescript
|
|
1486
|
+
* import {
|
|
1487
|
+
* IgniterAgent,
|
|
1488
|
+
* IgniterAgentPrompt,
|
|
1489
|
+
* IgniterAgentToolset,
|
|
1490
|
+
* IgniterAgentTool,
|
|
1491
|
+
* IgniterAgentMCPClient,
|
|
1492
|
+
* } from '@igniter-js/agents';
|
|
1493
|
+
* import { openai } from '@ai-sdk/openai';
|
|
1494
|
+
* import { z } from 'zod';
|
|
1495
|
+
*
|
|
1496
|
+
* const runCodeTool = IgniterAgentTool
|
|
1497
|
+
* .create('runCode')
|
|
1498
|
+
* .withDescription('Runs code')
|
|
1499
|
+
* .withInput(z.object({ code: z.string() }))
|
|
1500
|
+
* .withExecute(async ({ code }) => codeRunner(code))
|
|
1501
|
+
* .build();
|
|
1502
|
+
*
|
|
1503
|
+
* const searchDocsTool = IgniterAgentTool
|
|
1504
|
+
* .create('searchDocs')
|
|
1505
|
+
* .withDescription('Searches docs')
|
|
1506
|
+
* .withInput(z.object({ query: z.string() }))
|
|
1507
|
+
* .withExecute(async ({ query }) => docSearcher(query))
|
|
1508
|
+
* .build();
|
|
1509
|
+
*
|
|
1510
|
+
* // Create a fully-configured agent
|
|
1511
|
+
* const agent = IgniterAgent
|
|
1512
|
+
* .create('code-assistant')
|
|
1513
|
+
* .withModel(openai('gpt-4-turbo'))
|
|
1514
|
+
* .withContextSchema(z.object({
|
|
1515
|
+
* userId: z.string(),
|
|
1516
|
+
* projectId: z.string()
|
|
1517
|
+
* }))
|
|
1518
|
+
* .withPrompt(
|
|
1519
|
+
* IgniterAgentPrompt.create('You are a helpful coding assistant...')
|
|
1520
|
+
* )
|
|
1521
|
+
* .addToolset(
|
|
1522
|
+
* IgniterAgentToolset.create('code')
|
|
1523
|
+
* .addTool(runCodeTool)
|
|
1524
|
+
* .addTool(searchDocsTool)
|
|
1525
|
+
* .build()
|
|
1526
|
+
* )
|
|
1527
|
+
* .addMCP(
|
|
1528
|
+
* IgniterAgentMCPClient.create('filesystem')
|
|
1529
|
+
* .withType('stdio')
|
|
1530
|
+
* .withCommand('npx')
|
|
1531
|
+
* .withArgs(['-y', '@mcp/server-filesystem'])
|
|
1532
|
+
* .build()
|
|
1533
|
+
* )
|
|
1534
|
+
* .build();
|
|
1535
|
+
*
|
|
1536
|
+
* // Initialize and use
|
|
1537
|
+
* await agent.start();
|
|
1538
|
+
*
|
|
1539
|
+
* const response = await agent.generate({
|
|
1540
|
+
* messages: [{ role: 'user', content: 'Help me write a test' }],
|
|
1541
|
+
* options: { userId: 'user_123', projectId: 'proj_456' }
|
|
1542
|
+
* });
|
|
1543
|
+
* ```
|
|
1544
|
+
*
|
|
1545
|
+
* @public
|
|
1546
|
+
*/
|
|
1547
|
+
declare class IgniterAgentBuilder<TAgentName extends string = string, TAgentModel extends LanguageModel = LanguageModel, TAgentInstructions extends IgniterAgentPromptTemplate = IgniterAgentPromptTemplate, TAgentToolsets extends Record<string, IgniterAgentToolset$1> = Record<string, IgniterAgentToolset$1>, TAgentMCPConfigs extends Record<string, IgniterAgentMCPConfigUnion> = Record<string, IgniterAgentMCPConfigUnion>, TAgentContextSchema extends z.ZodSchema = z.ZodSchema> {
|
|
1548
|
+
/**
|
|
1549
|
+
* The agent configuration being built.
|
|
1550
|
+
* @internal
|
|
1551
|
+
*/
|
|
1552
|
+
private readonly _config;
|
|
1553
|
+
/**
|
|
1554
|
+
* Creates a new IgniterAgentBuilder instance.
|
|
1555
|
+
*
|
|
1556
|
+
* @param config - Initial configuration
|
|
1557
|
+
* @internal
|
|
1558
|
+
*/
|
|
1559
|
+
private constructor();
|
|
1560
|
+
/**
|
|
1561
|
+
* Creates a new agent builder.
|
|
1562
|
+
*
|
|
1563
|
+
* @description
|
|
1564
|
+
* Primary entry point for creating an agent. Returns a new builder
|
|
1565
|
+
* instance that can be configured using fluent methods.
|
|
1566
|
+
*
|
|
1567
|
+
* @returns A new IgniterAgentBuilder instance
|
|
1568
|
+
*
|
|
1569
|
+
* @example
|
|
1570
|
+
* ```typescript
|
|
1571
|
+
* const agent = IgniterAgent.create('my-agent')
|
|
1572
|
+
* .withModel(openai('gpt-4'))
|
|
1573
|
+
* .build();
|
|
1574
|
+
* ```
|
|
1575
|
+
*
|
|
1576
|
+
* @public
|
|
1577
|
+
*/
|
|
1578
|
+
static create<TNewName extends string = string>(name?: TNewName): IgniterAgentBuilder<TNewName, LanguageModel, IgniterAgentPromptTemplate, {}, {}, z.ZodSchema>;
|
|
1579
|
+
/**
|
|
1580
|
+
* Sets the language model.
|
|
1581
|
+
*
|
|
1582
|
+
* @description
|
|
1583
|
+
* Configures the AI model that powers the agent. Supports any model
|
|
1584
|
+
* provider compatible with the Vercel AI SDK.
|
|
1585
|
+
*
|
|
1586
|
+
* @typeParam TNewModel - The new model type
|
|
1587
|
+
* @param model - The language model instance
|
|
1588
|
+
* @returns A new builder with the model set
|
|
1589
|
+
*
|
|
1590
|
+
* @example
|
|
1591
|
+
* ```typescript
|
|
1592
|
+
* import { openai } from '@ai-sdk/openai';
|
|
1593
|
+
* import { anthropic } from '@ai-sdk/anthropic';
|
|
1594
|
+
* import { google } from '@ai-sdk/google';
|
|
1595
|
+
*
|
|
1596
|
+
* // Using OpenAI
|
|
1597
|
+
* const agent1 = IgniterAgent.create()
|
|
1598
|
+
* .withModel(openai('gpt-4-turbo'))
|
|
1599
|
+
* .build();
|
|
1600
|
+
*
|
|
1601
|
+
* // Using Anthropic
|
|
1602
|
+
* const agent2 = IgniterAgent.create()
|
|
1603
|
+
* .withModel(anthropic('claude-3-opus'))
|
|
1604
|
+
* .build();
|
|
1605
|
+
*
|
|
1606
|
+
* // Using Google
|
|
1607
|
+
* const agent3 = IgniterAgent.create()
|
|
1608
|
+
* .withModel(google('gemini-pro'))
|
|
1609
|
+
* .build();
|
|
1610
|
+
* ```
|
|
1611
|
+
*
|
|
1612
|
+
* @public
|
|
1613
|
+
*/
|
|
1614
|
+
withModel<TNewModel extends LanguageModel>(model: TNewModel): IgniterAgentBuilder<TAgentName, TNewModel, TAgentInstructions, TAgentToolsets, TAgentMCPConfigs, TAgentContextSchema>;
|
|
1615
|
+
/**
|
|
1616
|
+
* Sets the prompt instructions.
|
|
1617
|
+
*
|
|
1618
|
+
* @description
|
|
1619
|
+
* Configures the agent's system prompt using an IgniterAgentPrompt template.
|
|
1620
|
+
* The prompt defines the agent's behavior, personality, and capabilities.
|
|
1621
|
+
*
|
|
1622
|
+
* @typeParam TNewInstructions - The new instructions type
|
|
1623
|
+
* @param instructions - The prompt template instance
|
|
1624
|
+
* @returns A new builder with the instructions set
|
|
1625
|
+
*
|
|
1626
|
+
* @example
|
|
1627
|
+
* ```typescript
|
|
1628
|
+
* const agent = IgniterAgent.create()
|
|
1629
|
+
* .withPrompt(
|
|
1630
|
+
* IgniterAgentPrompt.create(`
|
|
1631
|
+
* You are a helpful coding assistant specialized in TypeScript.
|
|
1632
|
+
*
|
|
1633
|
+
* Guidelines:
|
|
1634
|
+
* - Always provide type-safe code
|
|
1635
|
+
* - Include JSDoc comments
|
|
1636
|
+
* - Follow best practices
|
|
1637
|
+
* `)
|
|
1638
|
+
* )
|
|
1639
|
+
* .build();
|
|
1640
|
+
* ```
|
|
1641
|
+
*
|
|
1642
|
+
* @public
|
|
1643
|
+
*/
|
|
1644
|
+
withPrompt<TNewInstructions extends IgniterAgentPromptTemplate>(instructions: TNewInstructions): IgniterAgentBuilder<TAgentName, TAgentModel, TNewInstructions, TAgentToolsets, TAgentMCPConfigs, TAgentContextSchema>;
|
|
1645
|
+
/**
|
|
1646
|
+
* Attaches a logger instance for operational logs.
|
|
1647
|
+
*/
|
|
1648
|
+
withLogger(logger: IgniterLogger): IgniterAgentBuilder<TAgentName, TAgentModel, TAgentInstructions, TAgentToolsets, TAgentMCPConfigs, TAgentContextSchema>;
|
|
1649
|
+
/**
|
|
1650
|
+
* Attaches a telemetry manager for observability.
|
|
1651
|
+
*/
|
|
1652
|
+
withTelemetry(telemetry: IgniterTelemetryManager): IgniterAgentBuilder<TAgentName, TAgentModel, TAgentInstructions, TAgentToolsets, TAgentMCPConfigs, TAgentContextSchema>;
|
|
1653
|
+
/**
|
|
1654
|
+
* Configures persistent memory for the agent.
|
|
1655
|
+
*/
|
|
1656
|
+
withMemory(memory: IgniterAgentMemoryConfig): IgniterAgentBuilder<TAgentName, TAgentModel, TAgentInstructions, TAgentToolsets, TAgentMCPConfigs, TAgentContextSchema>;
|
|
1657
|
+
/**
|
|
1658
|
+
* Callback when the agent starts.
|
|
1659
|
+
*/
|
|
1660
|
+
onAgentStart(callback: IgniterAgentHooks["onAgentStart"]): IgniterAgentBuilder<TAgentName, TAgentModel, TAgentInstructions, TAgentToolsets, TAgentMCPConfigs, TAgentContextSchema>;
|
|
1661
|
+
/**
|
|
1662
|
+
* Callback when the agent errors.
|
|
1663
|
+
*/
|
|
1664
|
+
onAgentError(callback: IgniterAgentHooks["onAgentError"]): IgniterAgentBuilder<TAgentName, TAgentModel, TAgentInstructions, TAgentToolsets, TAgentMCPConfigs, TAgentContextSchema>;
|
|
1665
|
+
/**
|
|
1666
|
+
* Callback when a tool call starts.
|
|
1667
|
+
*/
|
|
1668
|
+
onToolCallStart(callback: IgniterAgentHooks["onToolCallStart"]): IgniterAgentBuilder<TAgentName, TAgentModel, TAgentInstructions, TAgentToolsets, TAgentMCPConfigs, TAgentContextSchema>;
|
|
1669
|
+
/**
|
|
1670
|
+
* Callback when a tool call completes.
|
|
1671
|
+
*/
|
|
1672
|
+
onToolCallEnd(callback: IgniterAgentHooks["onToolCallEnd"]): IgniterAgentBuilder<TAgentName, TAgentModel, TAgentInstructions, TAgentToolsets, TAgentMCPConfigs, TAgentContextSchema>;
|
|
1673
|
+
/**
|
|
1674
|
+
* Callback when a tool call fails.
|
|
1675
|
+
*/
|
|
1676
|
+
onToolCallError(callback: IgniterAgentHooks["onToolCallError"]): IgniterAgentBuilder<TAgentName, TAgentModel, TAgentInstructions, TAgentToolsets, TAgentMCPConfigs, TAgentContextSchema>;
|
|
1677
|
+
/**
|
|
1678
|
+
* Callback when an MCP connection starts.
|
|
1679
|
+
*/
|
|
1680
|
+
onMCPStart(callback: IgniterAgentHooks["onMCPStart"]): IgniterAgentBuilder<TAgentName, TAgentModel, TAgentInstructions, TAgentToolsets, TAgentMCPConfigs, TAgentContextSchema>;
|
|
1681
|
+
/**
|
|
1682
|
+
* Callback when an MCP connection fails.
|
|
1683
|
+
*/
|
|
1684
|
+
onMCPError(callback: IgniterAgentHooks["onMCPError"]): IgniterAgentBuilder<TAgentName, TAgentModel, TAgentInstructions, TAgentToolsets, TAgentMCPConfigs, TAgentContextSchema>;
|
|
1685
|
+
/**
|
|
1686
|
+
* Sets the context schema.
|
|
1687
|
+
*
|
|
1688
|
+
* @description
|
|
1689
|
+
* Configures a Zod schema for validating context passed to the agent.
|
|
1690
|
+
* The context is available in prompt templates and can be used to
|
|
1691
|
+
* customize agent behavior per-request.
|
|
1692
|
+
*
|
|
1693
|
+
* @typeParam TNewSchema - The new schema type
|
|
1694
|
+
* @param schema - The Zod schema for context validation
|
|
1695
|
+
* @returns A new builder with the schema set
|
|
1696
|
+
*
|
|
1697
|
+
* @example
|
|
1698
|
+
* ```typescript
|
|
1699
|
+
* import { z } from 'zod';
|
|
1700
|
+
*
|
|
1701
|
+
* const contextSchema = z.object({
|
|
1702
|
+
* userId: z.string(),
|
|
1703
|
+
* chatId: z.string(),
|
|
1704
|
+
* userRole: z.enum(['admin', 'user', 'guest']),
|
|
1705
|
+
* preferences: z.object({
|
|
1706
|
+
* language: z.string().default('en'),
|
|
1707
|
+
* theme: z.string().optional()
|
|
1708
|
+
* })
|
|
1709
|
+
* });
|
|
1710
|
+
*
|
|
1711
|
+
* const agent = IgniterAgent.create()
|
|
1712
|
+
* .withContextSchema(contextSchema)
|
|
1713
|
+
* .build();
|
|
1714
|
+
*
|
|
1715
|
+
* // Context is type-safe when calling generate
|
|
1716
|
+
* await agent.generate({
|
|
1717
|
+
* messages: [...],
|
|
1718
|
+
* options: {
|
|
1719
|
+
* userId: 'user_123',
|
|
1720
|
+
* chatId: 'chat_456',
|
|
1721
|
+
* userRole: 'admin',
|
|
1722
|
+
* preferences: { language: 'pt' }
|
|
1723
|
+
* }
|
|
1724
|
+
* });
|
|
1725
|
+
* ```
|
|
1726
|
+
*
|
|
1727
|
+
* @public
|
|
1728
|
+
*/
|
|
1729
|
+
withContextSchema<TNewSchema extends z.ZodSchema>(schema: TNewSchema): IgniterAgentBuilder<TAgentName, TAgentModel, TAgentInstructions, TAgentToolsets, TAgentMCPConfigs, TNewSchema>;
|
|
1730
|
+
/**
|
|
1731
|
+
* Adds a toolset to the agent.
|
|
1732
|
+
*
|
|
1733
|
+
* @description
|
|
1734
|
+
* Registers a toolset with the agent. The toolset's tools become available
|
|
1735
|
+
* for the AI to invoke. Multiple toolsets can be added to a single agent.
|
|
1736
|
+
*
|
|
1737
|
+
* Tool names are prefixed with the toolset name to avoid collisions:
|
|
1738
|
+
* `{toolsetName}_{toolName}`
|
|
1739
|
+
*
|
|
1740
|
+
* @typeParam TNewToolset - The toolset type
|
|
1741
|
+
* @param toolset - The toolset to register
|
|
1742
|
+
* @returns A new builder with the toolset added
|
|
1743
|
+
*
|
|
1744
|
+
* @example
|
|
1745
|
+
* ```typescript
|
|
1746
|
+
* const githubToolset = IgniterAgentToolset.create('github')
|
|
1747
|
+
* .addTool(createIssueTool)
|
|
1748
|
+
* .addTool(listReposTool)
|
|
1749
|
+
* .build();
|
|
1750
|
+
*
|
|
1751
|
+
* const dockerToolset = IgniterAgentToolset.create('docker')
|
|
1752
|
+
* .addTool(buildImageTool)
|
|
1753
|
+
* .addTool(runContainerTool)
|
|
1754
|
+
* .build();
|
|
1755
|
+
*
|
|
1756
|
+
* const agent = IgniterAgent.create()
|
|
1757
|
+
* .addToolset(githubToolset) // Adds github_createIssue, github_listRepos
|
|
1758
|
+
* .addToolset(dockerToolset) // Adds docker_build, docker_run
|
|
1759
|
+
* .build();
|
|
1760
|
+
* ```
|
|
1761
|
+
*
|
|
1762
|
+
* @public
|
|
1763
|
+
*/
|
|
1764
|
+
addToolset<TNewToolset extends IgniterAgentToolset$1>(toolset: TNewToolset): IgniterAgentBuilder<TAgentName, TAgentModel, TAgentInstructions, TAgentToolsets & {
|
|
1765
|
+
[K in TNewToolset["name"]]: TNewToolset;
|
|
1766
|
+
}, TAgentMCPConfigs, TAgentContextSchema>;
|
|
1767
|
+
/**
|
|
1768
|
+
* Adds an MCP configuration to the agent.
|
|
1769
|
+
*
|
|
1770
|
+
* @description
|
|
1771
|
+
* Registers an MCP server configuration with the agent. The MCP server
|
|
1772
|
+
* will be connected when `agent.start()` is called, and its tools will
|
|
1773
|
+
* become available for the AI to invoke.
|
|
1774
|
+
*
|
|
1775
|
+
* @typeParam TMCPType - The MCP transport type
|
|
1776
|
+
* @typeParam TMCPName - The MCP configuration name
|
|
1777
|
+
* @param config - The MCP configuration
|
|
1778
|
+
* @returns A new builder with the MCP config added
|
|
1779
|
+
*
|
|
1780
|
+
* @example
|
|
1781
|
+
* ```typescript
|
|
1782
|
+
* const filesystemMCP = IgniterAgentMCPClient.create('filesystem')
|
|
1783
|
+
* .withType('stdio')
|
|
1784
|
+
* .withCommand('npx')
|
|
1785
|
+
* .withArgs(['-y', '@modelcontextprotocol/server-filesystem', '/tmp'])
|
|
1786
|
+
* .build();
|
|
1787
|
+
*
|
|
1788
|
+
* const remoteMCP = IgniterAgentMCPClient.create('remote-api')
|
|
1789
|
+
* .withType('http')
|
|
1790
|
+
* .withURL('https://api.example.com/mcp')
|
|
1791
|
+
* .withHeaders({ 'Authorization': 'Bearer xxx' })
|
|
1792
|
+
* .build();
|
|
1793
|
+
*
|
|
1794
|
+
* const agent = IgniterAgent.create()
|
|
1795
|
+
* .addMCP(filesystemMCP)
|
|
1796
|
+
* .addMCP(remoteMCP)
|
|
1797
|
+
* .build();
|
|
1798
|
+
*
|
|
1799
|
+
* // MCP connections are established here
|
|
1800
|
+
* await agent.start();
|
|
1801
|
+
* ```
|
|
1802
|
+
*
|
|
1803
|
+
* @public
|
|
1804
|
+
*/
|
|
1805
|
+
addMCP<TMCPName extends string>(config: IgniterAgentMCPConfigUnion<TMCPName>): IgniterAgentBuilder<TAgentName, TAgentModel, TAgentInstructions, TAgentToolsets, TAgentMCPConfigs & {
|
|
1806
|
+
[K in TMCPName]: typeof config;
|
|
1807
|
+
}, TAgentContextSchema>;
|
|
1808
|
+
/**
|
|
1809
|
+
* Builds and returns the completed agent.
|
|
1810
|
+
*
|
|
1811
|
+
* @description
|
|
1812
|
+
* Finalizes the agent configuration and returns a runtime agent object.
|
|
1813
|
+
* The agent provides methods for:
|
|
1814
|
+
* - `start()`: Initialize MCP connections
|
|
1815
|
+
* - `generate()`: Generate a single response
|
|
1816
|
+
* - `stream()`: Stream a response
|
|
1817
|
+
* - Accessors for configuration
|
|
1818
|
+
*
|
|
1819
|
+
* @returns The built agent runtime object
|
|
1820
|
+
*
|
|
1821
|
+
* @example
|
|
1822
|
+
* ```typescript
|
|
1823
|
+
* const agent = IgniterAgent.create('assistant')
|
|
1824
|
+
* .withModel(openai('gpt-4'))
|
|
1825
|
+
* .addToolset(myToolset)
|
|
1826
|
+
* .build();
|
|
1827
|
+
*
|
|
1828
|
+
* // Start the agent
|
|
1829
|
+
* await agent.start();
|
|
1830
|
+
*
|
|
1831
|
+
* // Generate a response
|
|
1832
|
+
* const result = await agent.generate({
|
|
1833
|
+
* messages: [{ role: 'user', content: 'Hello!' }]
|
|
1834
|
+
* });
|
|
1835
|
+
*
|
|
1836
|
+
* // Access configuration
|
|
1837
|
+
* console.log('Model:', agent.getModel());
|
|
1838
|
+
* console.log('Toolsets:', agent.getToolsets());
|
|
1839
|
+
* ```
|
|
1840
|
+
*
|
|
1841
|
+
* @public
|
|
1842
|
+
*/
|
|
1843
|
+
build(): IgniterAgentBuiltAgent<TAgentContextSchema, TAgentToolsets, TAgentModel, TAgentInstructions>;
|
|
1844
|
+
/**
|
|
1845
|
+
* Gets the current configuration (partial).
|
|
1846
|
+
*
|
|
1847
|
+
* @returns The current configuration state
|
|
1848
|
+
* @public
|
|
1849
|
+
*/
|
|
1850
|
+
getConfig(): Partial<IgniterAgentConfig<TAgentName, TAgentModel, TAgentInstructions, TAgentToolsets, TAgentMCPConfigs, TAgentContextSchema>>;
|
|
1851
|
+
/**
|
|
1852
|
+
* Gets the agent name.
|
|
1853
|
+
*
|
|
1854
|
+
* @returns The agent's name
|
|
1855
|
+
* @public
|
|
1856
|
+
*/
|
|
1857
|
+
getName(): TAgentName;
|
|
1858
|
+
}
|
|
1859
|
+
/**
|
|
1860
|
+
* Alias for IgniterAgentBuilder for cleaner API.
|
|
1861
|
+
*
|
|
1862
|
+
* @description
|
|
1863
|
+
* Use `IgniterAgent.create()` as the primary entry point for building agents.
|
|
1864
|
+
*
|
|
1865
|
+
* @example
|
|
1866
|
+
* ```typescript
|
|
1867
|
+
* import { IgniterAgent } from '@igniter-js/agents';
|
|
1868
|
+
*
|
|
1869
|
+
* const agent = IgniterAgent.create('assistant')
|
|
1870
|
+
* .withModel(openai('gpt-4'))
|
|
1871
|
+
* .build();
|
|
1872
|
+
* ```
|
|
1873
|
+
*
|
|
1874
|
+
* @public
|
|
1875
|
+
*/
|
|
1876
|
+
declare const IgniterAgent: {
|
|
1877
|
+
create: typeof IgniterAgentBuilder.create;
|
|
1878
|
+
};
|
|
1879
|
+
/**
|
|
1880
|
+
* Type alias for the IgniterAgent class.
|
|
1881
|
+
* @public
|
|
1882
|
+
*/
|
|
1883
|
+
type IgniterAgent = typeof IgniterAgentBuilder;
|
|
1884
|
+
|
|
1885
|
+
/**
|
|
1886
|
+
* @fileoverview Toolset Builder for creating custom tool collections.
|
|
1887
|
+
* This module provides a fluent API for building toolsets with type safety.
|
|
1888
|
+
*
|
|
1889
|
+
* @description
|
|
1890
|
+
* The IgniterAgentToolsetBuilder allows you to create collections of related
|
|
1891
|
+
* tools that can be registered with an agent. Each toolset has a unique name
|
|
1892
|
+
* and contains one or more tools that the AI can invoke.
|
|
1893
|
+
*
|
|
1894
|
+
* @example
|
|
1895
|
+
* ```typescript
|
|
1896
|
+
* import { IgniterAgentToolsetBuilder, IgniterAgentTool } from '@igniter-js/agents/builders';
|
|
1897
|
+
* import { z } from 'zod';
|
|
1898
|
+
*
|
|
1899
|
+
* const createIssue = IgniterAgentTool
|
|
1900
|
+
* .create('createIssue')
|
|
1901
|
+
* .withDescription('Creates a new issue in a GitHub repository')
|
|
1902
|
+
* .withInput(z.object({
|
|
1903
|
+
* repo: z.string().describe('Repository name (owner/repo)'),
|
|
1904
|
+
* title: z.string().describe('Issue title'),
|
|
1905
|
+
* body: z.string().optional().describe('Issue body')
|
|
1906
|
+
* }))
|
|
1907
|
+
* .withExecute(async ({ repo, title, body }) => {
|
|
1908
|
+
* return await github.createIssue(repo, title, body);
|
|
1909
|
+
* })
|
|
1910
|
+
* .build();
|
|
1911
|
+
*
|
|
1912
|
+
* const listRepos = IgniterAgentTool
|
|
1913
|
+
* .create('listRepos')
|
|
1914
|
+
* .withDescription('Lists repositories for a user')
|
|
1915
|
+
* .withInputect({
|
|
1916
|
+
* username: z.string().describe('GitHub username')
|
|
1917
|
+
* }))
|
|
1918
|
+
* .withExecute(async ({ username }) => {
|
|
1919
|
+
* return await github.listRepos(username);
|
|
1920
|
+
* })
|
|
1921
|
+
* .build();
|
|
1922
|
+
*
|
|
1923
|
+
* const githubToolset = IgniterAgentToolsetBuilder
|
|
1924
|
+
* .create('github')
|
|
1925
|
+
* .addTool(createIssue)
|
|
1926
|
+
* .addTool(listRepos)
|
|
1927
|
+
* .build();
|
|
1928
|
+
* ```
|
|
1929
|
+
*
|
|
1930
|
+
* @module builders/toolset
|
|
1931
|
+
* @packageDocumentation
|
|
1932
|
+
*/
|
|
1933
|
+
|
|
1934
|
+
/**
|
|
1935
|
+
* Fluent builder for creating custom toolsets.
|
|
1936
|
+
*
|
|
1937
|
+
* @description
|
|
1938
|
+
* The IgniterAgentToolsetBuilder provides a type-safe fluent API for creating
|
|
1939
|
+
* collections of related tools. Tools are wrapped with error handling and
|
|
1940
|
+
* result normalization to ensure consistent behavior.
|
|
1941
|
+
*
|
|
1942
|
+
* **Key Features:**
|
|
1943
|
+
* - Fluent chainable API
|
|
1944
|
+
* - Full TypeScript type inference for tool parameters
|
|
1945
|
+
* - Automatic error handling and result wrapping
|
|
1946
|
+
* - Tool execution logging
|
|
1947
|
+
*
|
|
1948
|
+
* @typeParam TToolsetName - The unique name for this toolset
|
|
1949
|
+
* @typeParam TTools - The accumulated tools collection type
|
|
1950
|
+
*
|
|
1951
|
+
* @example
|
|
1952
|
+
* ```typescript
|
|
1953
|
+
* // Create tools
|
|
1954
|
+
* const getCurrent = IgniterAgentTool
|
|
1955
|
+
* .create('getCurrent')
|
|
1956
|
+
* .withDescription('Gets current weather for a location')
|
|
1957
|
+
* .withInputect({
|
|
1958
|
+
* city: z.string(),
|
|
1959
|
+
* units: z.enum(['celsius', 'fahrenheit']).default('celsius')
|
|
1960
|
+
* }))
|
|
1961
|
+
* .withExecute(async ({ city, units }) => {
|
|
1962
|
+
* const weather = await weatherApi.getCurrent(city, units);
|
|
1963
|
+
* return {
|
|
1964
|
+
* temperature: weather.temp,
|
|
1965
|
+
* conditions: weather.description,
|
|
1966
|
+
* humidity: weather.humidity
|
|
1967
|
+
* };
|
|
1968
|
+
* })
|
|
1969
|
+
* .build();
|
|
1970
|
+
*
|
|
1971
|
+
* const getForecast = IgniterAgentTool
|
|
1972
|
+
* .create('getForecast')
|
|
1973
|
+
* .withDescription('Gets 5-day weather forecast')
|
|
1974
|
+
* .withInputect({
|
|
1975
|
+
* city: z.string(),
|
|
1976
|
+
* days: z.number().min(1).max(7).default(5)
|
|
1977
|
+
* }))
|
|
1978
|
+
* .withExecute(async ({ city, days }) => {
|
|
1979
|
+
* return await weatherApi.getForecast(city, days);
|
|
1980
|
+
* })
|
|
1981
|
+
* .build();
|
|
1982
|
+
*
|
|
1983
|
+
* // Create a toolset with multiple tools
|
|
1984
|
+
* const weatherToolset = IgniterAgentToolsetBuilder
|
|
1985
|
+
* .create('weather')
|
|
1986
|
+
* .addTool(getCurrent)
|
|
1987
|
+
* .addTool(getForecast)
|
|
1988
|
+
* .build();
|
|
1989
|
+
*
|
|
1990
|
+
* // Register with an agent
|
|
1991
|
+
* const agent = IgniterAgent.create('assistant')
|
|
1992
|
+
* .addToolset(weatherToolset)
|
|
1993
|
+
* .build();
|
|
1994
|
+
* ```
|
|
1995
|
+
*
|
|
1996
|
+
* @public
|
|
1997
|
+
*/
|
|
1998
|
+
declare class IgniterAgentToolsetBuilder<TToolsetName extends string = string, TTools extends ToolSet = Record<string, never>> {
|
|
1999
|
+
/**
|
|
2000
|
+
* The toolset's unique name.
|
|
2001
|
+
* @internal
|
|
2002
|
+
*/
|
|
2003
|
+
private readonly _name;
|
|
2004
|
+
/**
|
|
2005
|
+
* The accumulated tools collection.
|
|
2006
|
+
* @internal
|
|
2007
|
+
*/
|
|
2008
|
+
private readonly _tools;
|
|
2009
|
+
/**
|
|
2010
|
+
* Creates a new IgniterAgentToolsetBuilder instance.
|
|
2011
|
+
*
|
|
2012
|
+
* @param params - The toolset name and initial tools
|
|
2013
|
+
* @internal
|
|
2014
|
+
*/
|
|
2015
|
+
constructor(params: IgniterAgentToolsetParams<TToolsetName, TTools>);
|
|
2016
|
+
/**
|
|
2017
|
+
* Creates a new toolset builder with the given name.
|
|
2018
|
+
*
|
|
2019
|
+
* @description
|
|
2020
|
+
* This is the primary entry point for creating a new toolset.
|
|
2021
|
+
* The name must be unique within an agent and is used as a prefix
|
|
2022
|
+
* for tool names when the toolset is registered.
|
|
2023
|
+
*
|
|
2024
|
+
* @typeParam TName - The toolset name type
|
|
2025
|
+
* @param name - Unique name for the toolset
|
|
2026
|
+
* @returns A new IgniterAgentToolsetBuilder instance
|
|
2027
|
+
*
|
|
2028
|
+
* @example
|
|
2029
|
+
* ```typescript
|
|
2030
|
+
* const tool = IgniterAgentTool
|
|
2031
|
+
* .create('doSomething')
|
|
2032
|
+
* .withDescription('Does something')
|
|
2033
|
+
* .withInputect({}))
|
|
2034
|
+
* .withExecute(async () => ({ ok: true }))
|
|
2035
|
+
* .build();
|
|
2036
|
+
*
|
|
2037
|
+
* const toolset = IgniterAgentToolset
|
|
2038
|
+
* .create('myTools')
|
|
2039
|
+
* .addTool(tool)
|
|
2040
|
+
* .build();
|
|
2041
|
+
* ```
|
|
2042
|
+
*
|
|
2043
|
+
* @public
|
|
2044
|
+
*/
|
|
2045
|
+
static create<TName extends string>(name: TName): IgniterAgentToolsetBuilder<TName, {}>;
|
|
2046
|
+
/**
|
|
2047
|
+
* Changes the toolset name.
|
|
2048
|
+
*
|
|
2049
|
+
* @description
|
|
2050
|
+
* Allows renaming the toolset during the building process.
|
|
2051
|
+
* This creates a new builder instance with the new name.
|
|
2052
|
+
*
|
|
2053
|
+
* @typeParam TNewName - The new name type
|
|
2054
|
+
* @param name - The new name for the toolset
|
|
2055
|
+
* @returns A new builder with the updated name
|
|
2056
|
+
*
|
|
2057
|
+
* @example
|
|
2058
|
+
* ```typescript
|
|
2059
|
+
* const toolset = IgniterAgentToolset
|
|
2060
|
+
* .create('temp')
|
|
2061
|
+
* .withName('production') // Rename to 'production'
|
|
2062
|
+
* .addTool(myTool)
|
|
2063
|
+
* .build();
|
|
2064
|
+
* ```
|
|
2065
|
+
*
|
|
2066
|
+
* @public
|
|
2067
|
+
*/
|
|
2068
|
+
withName<TNewName extends string>(name: TNewName): IgniterAgentToolsetBuilder<TNewName, TTools>;
|
|
2069
|
+
/**
|
|
2070
|
+
* Adds a tool to the toolset.
|
|
2071
|
+
*
|
|
2072
|
+
* @description
|
|
2073
|
+
* Adds a built tool definition to the toolset. The tool is automatically
|
|
2074
|
+
* wrapped with error handling that returns a consistent result format
|
|
2075
|
+
* (`{ success: true, data: ... }` or `{ success: false, error: ... }`).
|
|
2076
|
+
*
|
|
2077
|
+
* @typeParam TToolName - The tool name type
|
|
2078
|
+
* @param dto - The built tool definition
|
|
2079
|
+
* @returns A new builder with the tool added
|
|
2080
|
+
*
|
|
2081
|
+
* @example
|
|
2082
|
+
* ```typescript
|
|
2083
|
+
* const greetTool = IgniterAgentTool.create('greet')
|
|
2084
|
+
* .withDescription('Greets a user')
|
|
2085
|
+
* .withInputect({ name: z.string() }))
|
|
2086
|
+
* .withExecute(async ({ name }) => `Hello, ${name}!`)
|
|
2087
|
+
* .build();
|
|
2088
|
+
*
|
|
2089
|
+
* const toolset = IgniterAgentToolset.create('utils')
|
|
2090
|
+
* .addTool(greetTool)
|
|
2091
|
+
* .build();
|
|
2092
|
+
* ```
|
|
2093
|
+
*
|
|
2094
|
+
* @public
|
|
2095
|
+
*/
|
|
2096
|
+
addTool<TTool extends IgniterAgentBuiltTool<any, any, any>>(dto: TTool): IgniterAgentToolsetBuilder<TToolsetName, TTools & {
|
|
2097
|
+
[K in TTool['$Infer']['Name']]: Tool<TTool['$Infer']['Input'], TTool['$Infer']['Output']>;
|
|
2098
|
+
}>;
|
|
2099
|
+
/**
|
|
2100
|
+
* Builds and returns the completed toolset.
|
|
2101
|
+
*
|
|
2102
|
+
* @description
|
|
2103
|
+
* Finalizes the toolset configuration and returns an object that can
|
|
2104
|
+
* be registered with an agent using `addToolset()`.
|
|
2105
|
+
*
|
|
2106
|
+
* The returned object includes:
|
|
2107
|
+
* - `name`: The toolset's unique identifier
|
|
2108
|
+
* - `type`: Always `'custom'` for user-defined toolsets
|
|
2109
|
+
* - `status`: Always `'connected'` for custom toolsets
|
|
2110
|
+
* - `tools`: The tools collection
|
|
2111
|
+
* - `toolset`: Reference to the raw tools object
|
|
2112
|
+
*
|
|
2113
|
+
* @returns The completed toolset configuration
|
|
2114
|
+
*
|
|
2115
|
+
* @example
|
|
2116
|
+
* ```typescript
|
|
2117
|
+
* const toolset = IgniterAgentToolset
|
|
2118
|
+
* .create('utils')
|
|
2119
|
+
* .addTool(formatDateTool)
|
|
2120
|
+
* .addTool(parseJsonTool)
|
|
2121
|
+
* .build();
|
|
2122
|
+
*
|
|
2123
|
+
* console.log(toolset.name); // 'utils'
|
|
2124
|
+
* console.log(toolset.type); // 'custom'
|
|
2125
|
+
* console.log(toolset.status); // 'connected'
|
|
2126
|
+
* console.log(Object.keys(toolset.tools)); // ['formatDate', 'parseJSON']
|
|
2127
|
+
* ```
|
|
2128
|
+
*
|
|
2129
|
+
* @public
|
|
2130
|
+
*/
|
|
2131
|
+
build(): IgniterAgentBuiltToolset<TToolsetName, TTools>;
|
|
2132
|
+
/**
|
|
2133
|
+
* Gets the current toolset name.
|
|
2134
|
+
*
|
|
2135
|
+
* @returns The toolset's name
|
|
2136
|
+
* @public
|
|
2137
|
+
*/
|
|
2138
|
+
getName(): TToolsetName;
|
|
2139
|
+
/**
|
|
2140
|
+
* Gets the current tools collection.
|
|
2141
|
+
*
|
|
2142
|
+
* @returns The tools object
|
|
2143
|
+
* @public
|
|
2144
|
+
*/
|
|
2145
|
+
getTools(): TTools;
|
|
2146
|
+
/**
|
|
2147
|
+
* Gets the number of tools in the toolset.
|
|
2148
|
+
*
|
|
2149
|
+
* @returns The tool count
|
|
2150
|
+
* @public
|
|
2151
|
+
*/
|
|
2152
|
+
getToolCount(): number;
|
|
2153
|
+
}
|
|
2154
|
+
/**
|
|
2155
|
+
* Factory function to create a new toolset builder.
|
|
2156
|
+
*
|
|
2157
|
+
* @description
|
|
2158
|
+
* Convenience function that wraps `IgniterAgentToolsetBuilder.create()`.
|
|
2159
|
+
* Useful for more concise code or functional programming patterns.
|
|
2160
|
+
*
|
|
2161
|
+
* @typeParam TName - The toolset name type
|
|
2162
|
+
* @param name - Unique name for the toolset
|
|
2163
|
+
* @returns A new IgniterAgentToolsetBuilder instance
|
|
2164
|
+
*
|
|
2165
|
+
* @example
|
|
2166
|
+
* ```typescript
|
|
2167
|
+
* import { IgniterAgentToolset, IgniterAgentTool } from '@igniter-js/agents';
|
|
2168
|
+
*
|
|
2169
|
+
* const sayHello = IgniterAgentTool
|
|
2170
|
+
* .create('sayHello')
|
|
2171
|
+
* .withDescription('Says hello')
|
|
2172
|
+
* .withInputect({ name: z.string() }))
|
|
2173
|
+
* .withExecute(async ({ name }) => `Hello, ${name}!`)
|
|
2174
|
+
* .build();
|
|
2175
|
+
*
|
|
2176
|
+
* const myToolset = IgniterAgentToolset.create('myTools')
|
|
2177
|
+
* .addTool(sayHello)
|
|
2178
|
+
* .build();
|
|
2179
|
+
* ```
|
|
2180
|
+
*
|
|
2181
|
+
* @public
|
|
2182
|
+
*/
|
|
2183
|
+
declare const IgniterAgentToolset: {
|
|
2184
|
+
create: typeof IgniterAgentToolsetBuilder.create;
|
|
2185
|
+
};
|
|
2186
|
+
|
|
2187
|
+
/**
|
|
2188
|
+
* @fileoverview Tool Builder for creating individual tool definitions.
|
|
2189
|
+
* This module provides a fluent API for building single tools with type safety.
|
|
2190
|
+
*
|
|
2191
|
+
* @description
|
|
2192
|
+
* The IgniterAgentToolBuilder allows you to define a single tool using a
|
|
2193
|
+
* fluent builder pattern. The resulting tool definition can be added to a
|
|
2194
|
+
* toolset builder for registration with an agent.
|
|
2195
|
+
*
|
|
2196
|
+
* @example
|
|
2197
|
+
* ```typescript
|
|
2198
|
+
* import { IgniterAgentTool } from '@igniter-js/agents';
|
|
2199
|
+
* import { z } from 'zod';
|
|
2200
|
+
*
|
|
2201
|
+
* const greetTool = IgniterAgentTool
|
|
2202
|
+
* .create('greet')
|
|
2203
|
+
* .withDescription('Greets a user by name')
|
|
2204
|
+
* .withInput(z.object({ name: z.string() }))
|
|
2205
|
+
* .withExecute(async ({ name }) => `Hello, ${name}!`)
|
|
2206
|
+
* .build();
|
|
2207
|
+
* ```
|
|
2208
|
+
*
|
|
2209
|
+
* @module builders/tool
|
|
2210
|
+
* @packageDocumentation
|
|
2211
|
+
*/
|
|
2212
|
+
|
|
2213
|
+
/**
|
|
2214
|
+
* Fluent builder for creating a single tool definition.
|
|
2215
|
+
*
|
|
2216
|
+
* @description
|
|
2217
|
+
* The IgniterAgentToolBuilder provides a type-safe fluent API for defining
|
|
2218
|
+
* a tool's metadata, input schema, and execution handler.
|
|
2219
|
+
*
|
|
2220
|
+
* @typeParam TName - The tool's unique name
|
|
2221
|
+
* @typeParam TInputSchema - The tool parameters type
|
|
2222
|
+
* @typeParam TOutputSchema - The tool result type
|
|
2223
|
+
*
|
|
2224
|
+
* @public
|
|
2225
|
+
*/
|
|
2226
|
+
declare class IgniterAgentToolBuilder<TName extends string = string, TInputSchema = unknown, TOutputSchema = undefined, TExecute extends (params: TInputSchema, options: IgniterAgentToolExecuteOptions) => Promise<unknown> = any> {
|
|
2227
|
+
/**
|
|
2228
|
+
* The accumulated tool definition.
|
|
2229
|
+
* @internal
|
|
2230
|
+
*/
|
|
2231
|
+
private readonly _definition;
|
|
2232
|
+
/**
|
|
2233
|
+
* Creates a new IgniterAgentToolBuilder instance.
|
|
2234
|
+
*
|
|
2235
|
+
* @param name - The tool name
|
|
2236
|
+
* @param definition - Partial tool definition
|
|
2237
|
+
* @internal
|
|
2238
|
+
*/
|
|
2239
|
+
private constructor();
|
|
2240
|
+
/**
|
|
2241
|
+
* Creates a new tool builder with the given name.
|
|
2242
|
+
*
|
|
2243
|
+
* @description
|
|
2244
|
+
* The name must be unique within a toolset.
|
|
2245
|
+
*
|
|
2246
|
+
* @typeParam TNewName - The tool name type
|
|
2247
|
+
* @param name - Unique name for the tool
|
|
2248
|
+
* @returns A new IgniterAgentToolBuilder instance
|
|
2249
|
+
*
|
|
2250
|
+
* @public
|
|
2251
|
+
*/
|
|
2252
|
+
static create<TNewName extends string>(name: TNewName): IgniterAgentToolBuilder<TNewName, unknown, unknown>;
|
|
2253
|
+
/**
|
|
2254
|
+
* Sets the tool description.
|
|
2255
|
+
*
|
|
2256
|
+
* @param description - Human-readable description shown to the AI
|
|
2257
|
+
* @returns A new builder with the description set
|
|
2258
|
+
*
|
|
2259
|
+
* @public
|
|
2260
|
+
*/
|
|
2261
|
+
withDescription(description: string): IgniterAgentToolBuilder<TName, TInputSchema, TOutputSchema>;
|
|
2262
|
+
/**
|
|
2263
|
+
* Sets the tool parameters schema.
|
|
2264
|
+
*
|
|
2265
|
+
* @typeParam TNewParams - The new parameters type
|
|
2266
|
+
* @param parameters - Zod schema defining input parameters
|
|
2267
|
+
* @returns A new builder with the parameters set
|
|
2268
|
+
*
|
|
2269
|
+
* @public
|
|
2270
|
+
*/
|
|
2271
|
+
withInput<TNewParams>(inputSchema: z.ZodSchema<TNewParams>): IgniterAgentToolBuilder<TName, TNewParams, TOutputSchema>;
|
|
2272
|
+
/**
|
|
2273
|
+
* Sets the tool output schema.
|
|
2274
|
+
*
|
|
2275
|
+
* @typeParam TNewResult - The new result type
|
|
2276
|
+
* @param outputSchema - Zod schema defining the tool's output
|
|
2277
|
+
* @returns A new builder with the output schema set
|
|
2278
|
+
*
|
|
2279
|
+
* @public
|
|
2280
|
+
*/
|
|
2281
|
+
withOutput<TNewResult>(outputSchema: z.ZodSchema<TNewResult>): IgniterAgentToolBuilder<TName, TInputSchema, TNewResult>;
|
|
2282
|
+
/**
|
|
2283
|
+
* Sets the tool execution handler.
|
|
2284
|
+
*
|
|
2285
|
+
* @typeParam TNewResult - The new result type
|
|
2286
|
+
* @param execute - Function that performs the tool's logic
|
|
2287
|
+
* @returns A new builder with the execute handler set
|
|
2288
|
+
*
|
|
2289
|
+
* @public
|
|
2290
|
+
*/
|
|
2291
|
+
withExecute<TNewExecute extends (params: TInputSchema, options: IgniterAgentToolExecuteOptions) => TOutputSchema extends undefined ? Promise<unknown> : Promise<TOutputSchema>, TNewResult = Awaited<ReturnType<TNewExecute>>>(execute: TNewExecute): IgniterAgentToolBuilder<TName, TInputSchema, TNewResult, TNewExecute>;
|
|
2292
|
+
/**
|
|
2293
|
+
* Builds and returns the completed tool definition.
|
|
2294
|
+
*
|
|
2295
|
+
* @returns The completed tool definition with its name
|
|
2296
|
+
*
|
|
2297
|
+
* @public
|
|
2298
|
+
*/
|
|
2299
|
+
build(): IgniterAgentBuiltTool<TName, TInputSchema, TOutputSchema>;
|
|
2300
|
+
}
|
|
2301
|
+
/**
|
|
2302
|
+
* Factory function to create a new tool builder.
|
|
2303
|
+
*
|
|
2304
|
+
* @description
|
|
2305
|
+
* Convenience function that wraps `IgniterAgentTool.create('toolName')`.
|
|
2306
|
+
*
|
|
2307
|
+
* @typeParam TName - The tool name type
|
|
2308
|
+
* @param name - Unique name for the tool
|
|
2309
|
+
* @returns A new IgniterAgentToolBuilder instance
|
|
2310
|
+
*
|
|
2311
|
+
* @public
|
|
2312
|
+
*/
|
|
2313
|
+
declare const IgniterAgentTool: {
|
|
2314
|
+
create: typeof IgniterAgentToolBuilder.create;
|
|
2315
|
+
};
|
|
2316
|
+
|
|
2317
|
+
/**
|
|
2318
|
+
* @fileoverview MCP (Model Context Protocol) Client Builder.
|
|
2319
|
+
* This module provides a fluent API for configuring MCP server connections.
|
|
2320
|
+
*
|
|
2321
|
+
* @description
|
|
2322
|
+
* The IgniterAgentMCPBuilder allows you to configure connections to MCP servers
|
|
2323
|
+
* using either stdio (local process) or HTTP (remote server) transport.
|
|
2324
|
+
*
|
|
2325
|
+
* MCP servers provide tools that the agent can invoke, similar to custom toolsets,
|
|
2326
|
+
* but the tools are hosted externally and discovered at runtime.
|
|
2327
|
+
*
|
|
2328
|
+
* @see {@link https://modelcontextprotocol.io/ | Model Context Protocol}
|
|
2329
|
+
*
|
|
2330
|
+
* @example
|
|
2331
|
+
* ```typescript
|
|
2332
|
+
* import { IgniterAgentMCPBuilder } from '@igniter-js/agents/builders';
|
|
2333
|
+
*
|
|
2334
|
+
* // Configure a stdio MCP server (local process)
|
|
2335
|
+
* const filesystemMCP = IgniterAgentMCPBuilder
|
|
2336
|
+
* .create('filesystem')
|
|
2337
|
+
* .withType('stdio')
|
|
2338
|
+
* .withCommand('npx')
|
|
2339
|
+
* .withArgs(['-y', '@modelcontextprotocol/server-filesystem', '/tmp'])
|
|
2340
|
+
* .withEnv({ DEBUG: 'true' })
|
|
2341
|
+
* .build();
|
|
2342
|
+
*
|
|
2343
|
+
* // Configure an HTTP MCP server (remote)
|
|
2344
|
+
* const remoteMCP = IgniterAgentMCPBuilder
|
|
2345
|
+
* .create('remote-tools')
|
|
2346
|
+
* .withType('http')
|
|
2347
|
+
* .withURL('https://mcp.example.com/api')
|
|
2348
|
+
* .withHeaders({ 'Authorization': 'Bearer token123' })
|
|
2349
|
+
* .build();
|
|
2350
|
+
* ```
|
|
2351
|
+
*
|
|
2352
|
+
* @module builders/mcp
|
|
2353
|
+
* @packageDocumentation
|
|
2354
|
+
*/
|
|
2355
|
+
|
|
2356
|
+
/**
|
|
2357
|
+
* Fluent builder for configuring MCP server connections.
|
|
2358
|
+
*
|
|
2359
|
+
* @description
|
|
2360
|
+
* The IgniterAgentMCPBuilder provides a type-safe fluent API for creating
|
|
2361
|
+
* MCP server configurations. The builder adapts its available methods based
|
|
2362
|
+
* on the transport type selected.
|
|
2363
|
+
*
|
|
2364
|
+
* **Transport Types:**
|
|
2365
|
+
* - `stdio`: For local MCP servers running as child processes
|
|
2366
|
+
* - `http`: For remote MCP servers accessed over HTTP/HTTPS
|
|
2367
|
+
*
|
|
2368
|
+
* **Key Features:**
|
|
2369
|
+
* - Type-safe configuration based on transport type
|
|
2370
|
+
* - Validation of required fields
|
|
2371
|
+
* - Environment variable support for stdio
|
|
2372
|
+
* - Header support for HTTP authentication
|
|
2373
|
+
*
|
|
2374
|
+
* @typeParam TType - The transport type ('stdio' | 'http')
|
|
2375
|
+
* @typeParam TName - The unique configuration name
|
|
2376
|
+
*
|
|
2377
|
+
* @example
|
|
2378
|
+
* ```typescript
|
|
2379
|
+
* // Stdio transport (local process)
|
|
2380
|
+
* const localMCP = IgniterAgentMCPBuilder
|
|
2381
|
+
* .create('github')
|
|
2382
|
+
* .withType('stdio')
|
|
2383
|
+
* .withCommand('npx')
|
|
2384
|
+
* .withArgs(['-y', '@modelcontextprotocol/server-github'])
|
|
2385
|
+
* .withEnv({ GITHUB_TOKEN: process.env.GITHUB_TOKEN! })
|
|
2386
|
+
* .build();
|
|
2387
|
+
*
|
|
2388
|
+
* // HTTP transport (remote server)
|
|
2389
|
+
* const remoteMCP = IgniterAgentMCPBuilder
|
|
2390
|
+
* .create('opencode')
|
|
2391
|
+
* .withType('http')
|
|
2392
|
+
* .withURL('https://sandbox.example.com/mcp')
|
|
2393
|
+
* .withHeaders({
|
|
2394
|
+
* 'X-API-Key': process.env.API_KEY!,
|
|
2395
|
+
* 'Content-Type': 'application/json'
|
|
2396
|
+
* })
|
|
2397
|
+
* .build();
|
|
2398
|
+
*
|
|
2399
|
+
* // Register with an agent
|
|
2400
|
+
* const agent = IgniterAgent.create('my-agent')
|
|
2401
|
+
* .addMCP(localMCP)
|
|
2402
|
+
* .addMCP(remoteMCP)
|
|
2403
|
+
* .build();
|
|
2404
|
+
* ```
|
|
2405
|
+
*
|
|
2406
|
+
* @public
|
|
2407
|
+
*/
|
|
2408
|
+
declare class IgniterAgentMCPBuilder<TType extends IgniterAgentToolsetType = IgniterAgentToolsetType, TName extends string = string> {
|
|
2409
|
+
/**
|
|
2410
|
+
* The configuration being built.
|
|
2411
|
+
* @internal
|
|
2412
|
+
*/
|
|
2413
|
+
private readonly _config;
|
|
2414
|
+
/**
|
|
2415
|
+
* Creates a new IgniterAgentMCPBuilder instance.
|
|
2416
|
+
*
|
|
2417
|
+
* @param config - Initial configuration
|
|
2418
|
+
* @internal
|
|
2419
|
+
*/
|
|
2420
|
+
private constructor();
|
|
2421
|
+
/**
|
|
2422
|
+
* Creates a new MCP builder with the given name.
|
|
2423
|
+
*
|
|
2424
|
+
* @description
|
|
2425
|
+
* This is the primary entry point for creating an MCP configuration.
|
|
2426
|
+
* The name must be unique within an agent and is used to identify
|
|
2427
|
+
* the MCP server and its tools.
|
|
2428
|
+
*
|
|
2429
|
+
* After calling `create()`, you must call `withType()` to specify
|
|
2430
|
+
* the transport type before configuring transport-specific options.
|
|
2431
|
+
*
|
|
2432
|
+
* @typeParam TNewName - The configuration name type
|
|
2433
|
+
* @param name - Unique name for the MCP configuration
|
|
2434
|
+
* @returns A new IgniterAgentMCPBuilder instance
|
|
2435
|
+
*
|
|
2436
|
+
* @example
|
|
2437
|
+
* ```typescript
|
|
2438
|
+
* const mcpConfig = IgniterAgentMCPBuilder
|
|
2439
|
+
* .create('my-mcp')
|
|
2440
|
+
* .withType('stdio') // or 'http'
|
|
2441
|
+
* .withCommand('...') // available after withType('stdio')
|
|
2442
|
+
* .build();
|
|
2443
|
+
* ```
|
|
2444
|
+
*
|
|
2445
|
+
* @public
|
|
2446
|
+
*/
|
|
2447
|
+
static create<TNewName extends string>(name: TNewName): IgniterAgentMCPBuilder<IgniterAgentToolsetType, TNewName>;
|
|
2448
|
+
/**
|
|
2449
|
+
* Sets the configuration name.
|
|
2450
|
+
*
|
|
2451
|
+
* @description
|
|
2452
|
+
* Allows changing the configuration name during the building process.
|
|
2453
|
+
*
|
|
2454
|
+
* @typeParam TNewName - The new name type
|
|
2455
|
+
* @param name - The new name for the configuration
|
|
2456
|
+
* @returns A new builder with the updated name
|
|
2457
|
+
*
|
|
2458
|
+
* @public
|
|
2459
|
+
*/
|
|
2460
|
+
withName<TNewName extends string>(name: TNewName): IgniterAgentMCPBuilder<TType, TNewName>;
|
|
2461
|
+
/**
|
|
2462
|
+
* Sets the transport type for the MCP connection.
|
|
2463
|
+
*
|
|
2464
|
+
* @description
|
|
2465
|
+
* Specifies how the agent will communicate with the MCP server:
|
|
2466
|
+
* - `stdio`: Spawns a local process and communicates via stdin/stdout
|
|
2467
|
+
* - `http`: Connects to a remote server via HTTP/HTTPS
|
|
2468
|
+
*
|
|
2469
|
+
* After calling this method, transport-specific methods become available:
|
|
2470
|
+
* - For `stdio`: `withCommand()`, `withArgs()`, `withEnv()`
|
|
2471
|
+
* - For `http`: `withURL()`, `withHeaders()`
|
|
2472
|
+
*
|
|
2473
|
+
* @typeParam TNewType - The transport type
|
|
2474
|
+
* @param type - The transport type to use
|
|
2475
|
+
* @returns A new builder configured for the specified transport
|
|
2476
|
+
*
|
|
2477
|
+
* @example
|
|
2478
|
+
* ```typescript
|
|
2479
|
+
* // Stdio transport
|
|
2480
|
+
* const stdioConfig = IgniterAgentMCPBuilder
|
|
2481
|
+
* .create('local')
|
|
2482
|
+
* .withType('stdio')
|
|
2483
|
+
* .withCommand('python')
|
|
2484
|
+
* .withArgs(['mcp_server.py'])
|
|
2485
|
+
* .build();
|
|
2486
|
+
*
|
|
2487
|
+
* // HTTP transport
|
|
2488
|
+
* const httpConfig = IgniterAgentMCPBuilder
|
|
2489
|
+
* .create('remote')
|
|
2490
|
+
* .withType('http')
|
|
2491
|
+
* .withURL('https://api.example.com/mcp')
|
|
2492
|
+
* .build();
|
|
2493
|
+
* ```
|
|
2494
|
+
*
|
|
2495
|
+
* @public
|
|
2496
|
+
*/
|
|
2497
|
+
withType<TNewType extends IgniterAgentToolsetType>(type: TNewType): IgniterAgentMCPBuilder<TNewType, TName>;
|
|
2498
|
+
/**
|
|
2499
|
+
* Sets the command to execute for stdio transport.
|
|
2500
|
+
*
|
|
2501
|
+
* @description
|
|
2502
|
+
* Specifies the executable to run when starting the MCP server process.
|
|
2503
|
+
* Common values include `npx`, `node`, `python`, `deno`, etc.
|
|
2504
|
+
*
|
|
2505
|
+
* @param command - The command to execute
|
|
2506
|
+
* @returns A new builder with the command set
|
|
2507
|
+
* @throws {IgniterAgentConfigError} If transport type is not 'stdio'
|
|
2508
|
+
*
|
|
2509
|
+
* @example
|
|
2510
|
+
* ```typescript
|
|
2511
|
+
* const config = IgniterAgentMCPBuilder
|
|
2512
|
+
* .create('filesystem')
|
|
2513
|
+
* .withType('stdio')
|
|
2514
|
+
* .withCommand('npx')
|
|
2515
|
+
* .withArgs(['-y', '@modelcontextprotocol/server-filesystem'])
|
|
2516
|
+
* .build();
|
|
2517
|
+
* ```
|
|
2518
|
+
*
|
|
2519
|
+
* @public
|
|
2520
|
+
*/
|
|
2521
|
+
withCommand(command: string): IgniterAgentMCPBuilder<TType, TName>;
|
|
2522
|
+
/**
|
|
2523
|
+
* Sets the arguments to pass to the command.
|
|
2524
|
+
*
|
|
2525
|
+
* @description
|
|
2526
|
+
* Specifies command-line arguments for the MCP server process.
|
|
2527
|
+
*
|
|
2528
|
+
* @param args - Array of command arguments
|
|
2529
|
+
* @returns A new builder with the arguments set
|
|
2530
|
+
* @throws {IgniterAgentConfigError} If transport type is not 'stdio'
|
|
2531
|
+
*
|
|
2532
|
+
* @example
|
|
2533
|
+
* ```typescript
|
|
2534
|
+
* const config = IgniterAgentMCPBuilder
|
|
2535
|
+
* .create('filesystem')
|
|
2536
|
+
* .withType('stdio')
|
|
2537
|
+
* .withCommand('npx')
|
|
2538
|
+
* .withArgs([
|
|
2539
|
+
* '-y',
|
|
2540
|
+
* '@modelcontextprotocol/server-filesystem',
|
|
2541
|
+
* '/home/user/documents',
|
|
2542
|
+
* '--read-only'
|
|
2543
|
+
* ])
|
|
2544
|
+
* .build();
|
|
2545
|
+
* ```
|
|
2546
|
+
*
|
|
2547
|
+
* @public
|
|
2548
|
+
*/
|
|
2549
|
+
withArgs(args: string[]): IgniterAgentMCPBuilder<TType, TName>;
|
|
2550
|
+
/**
|
|
2551
|
+
* Sets environment variables for the command process.
|
|
2552
|
+
*
|
|
2553
|
+
* @description
|
|
2554
|
+
* Specifies environment variables to pass to the MCP server process.
|
|
2555
|
+
* Useful for passing API keys, configuration, or feature flags.
|
|
2556
|
+
*
|
|
2557
|
+
* @param env - Record of environment variable names to values
|
|
2558
|
+
* @returns A new builder with the environment variables set
|
|
2559
|
+
* @throws {IgniterAgentConfigError} If transport type is not 'stdio'
|
|
2560
|
+
*
|
|
2561
|
+
* @example
|
|
2562
|
+
* ```typescript
|
|
2563
|
+
* const config = IgniterAgentMCPBuilder
|
|
2564
|
+
* .create('github')
|
|
2565
|
+
* .withType('stdio')
|
|
2566
|
+
* .withCommand('npx')
|
|
2567
|
+
* .withArgs(['-y', '@modelcontextprotocol/server-github'])
|
|
2568
|
+
* .withEnv({
|
|
2569
|
+
* GITHUB_TOKEN: process.env.GITHUB_TOKEN!,
|
|
2570
|
+
* GITHUB_ORG: 'my-organization',
|
|
2571
|
+
* DEBUG: 'mcp:*'
|
|
2572
|
+
* })
|
|
2573
|
+
* .build();
|
|
2574
|
+
* ```
|
|
2575
|
+
*
|
|
2576
|
+
* @public
|
|
2577
|
+
*/
|
|
2578
|
+
withEnv(env: Record<string, string>): IgniterAgentMCPBuilder<TType, TName>;
|
|
2579
|
+
/**
|
|
2580
|
+
* Sets the URL for HTTP transport.
|
|
2581
|
+
*
|
|
2582
|
+
* @description
|
|
2583
|
+
* Specifies the endpoint URL for the remote MCP server.
|
|
2584
|
+
* Must be a valid HTTP or HTTPS URL.
|
|
2585
|
+
*
|
|
2586
|
+
* @param url - The MCP server URL
|
|
2587
|
+
* @returns A new builder with the URL set
|
|
2588
|
+
* @throws {IgniterAgentConfigError} If transport type is not 'http' or URL is invalid
|
|
2589
|
+
*
|
|
2590
|
+
* @example
|
|
2591
|
+
* ```typescript
|
|
2592
|
+
* const config = IgniterAgentMCPBuilder
|
|
2593
|
+
* .create('opencode')
|
|
2594
|
+
* .withType('http')
|
|
2595
|
+
* .withURL('https://sandbox.example.com/mcp/v1')
|
|
2596
|
+
* .build();
|
|
2597
|
+
* ```
|
|
2598
|
+
*
|
|
2599
|
+
* @public
|
|
2600
|
+
*/
|
|
2601
|
+
withURL(url: string): IgniterAgentMCPBuilder<TType, TName>;
|
|
2602
|
+
/**
|
|
2603
|
+
* Sets HTTP headers for requests to the MCP server.
|
|
2604
|
+
*
|
|
2605
|
+
* @description
|
|
2606
|
+
* Specifies headers to include in all HTTP requests to the MCP server.
|
|
2607
|
+
* Commonly used for authentication, API keys, or content type.
|
|
2608
|
+
*
|
|
2609
|
+
* @param headers - Record of header names to values
|
|
2610
|
+
* @returns A new builder with the headers set
|
|
2611
|
+
* @throws {IgniterAgentConfigError} If transport type is not 'http'
|
|
2612
|
+
*
|
|
2613
|
+
* @example
|
|
2614
|
+
* ```typescript
|
|
2615
|
+
* const config = IgniterAgentMCPBuilder
|
|
2616
|
+
* .create('authenticated-mcp')
|
|
2617
|
+
* .withType('http')
|
|
2618
|
+
* .withURL('https://api.example.com/mcp')
|
|
2619
|
+
* .withHeaders({
|
|
2620
|
+
* 'Authorization': `Bearer ${process.env.API_TOKEN}`,
|
|
2621
|
+
* 'X-Client-ID': 'my-app',
|
|
2622
|
+
* 'Content-Type': 'application/json'
|
|
2623
|
+
* })
|
|
2624
|
+
* .build();
|
|
2625
|
+
* ```
|
|
2626
|
+
*
|
|
2627
|
+
* @public
|
|
2628
|
+
*/
|
|
2629
|
+
withHeaders(headers: Record<string, string>): IgniterAgentMCPBuilder<TType, TName>;
|
|
2630
|
+
/**
|
|
2631
|
+
* Builds and returns the completed MCP configuration.
|
|
2632
|
+
*
|
|
2633
|
+
* @description
|
|
2634
|
+
* Validates the configuration and returns a typed configuration object
|
|
2635
|
+
* that can be registered with an agent using `addMCP()`.
|
|
2636
|
+
*
|
|
2637
|
+
* @returns The completed MCP configuration
|
|
2638
|
+
* @throws {IgniterAgentConfigError} If required fields are missing
|
|
2639
|
+
*
|
|
2640
|
+
* @example
|
|
2641
|
+
* ```typescript
|
|
2642
|
+
* const mcpConfig = IgniterAgentMCPBuilder
|
|
2643
|
+
* .create('filesystem')
|
|
2644
|
+
* .withType('stdio')
|
|
2645
|
+
* .withCommand('npx')
|
|
2646
|
+
* .withArgs(['-y', '@modelcontextprotocol/server-filesystem', '/tmp'])
|
|
2647
|
+
* .build();
|
|
2648
|
+
*
|
|
2649
|
+
* // Use with an agent
|
|
2650
|
+
* const agent = IgniterAgent.create()
|
|
2651
|
+
* .addMCP(mcpConfig)
|
|
2652
|
+
* .build();
|
|
2653
|
+
* ```
|
|
2654
|
+
*
|
|
2655
|
+
* @public
|
|
2656
|
+
*/
|
|
2657
|
+
build(): TType extends "stdio" ? IgniterAgentMCPStdioConfig<TName> : TType extends "http" ? IgniterAgentMCPHttpConfig<TName> : IgniterAgentMCPConfigUnion<TName>;
|
|
2658
|
+
/**
|
|
2659
|
+
* Asserts that the current transport type is 'stdio'.
|
|
2660
|
+
* @internal
|
|
2661
|
+
*/
|
|
2662
|
+
private _assertStdioType;
|
|
2663
|
+
/**
|
|
2664
|
+
* Asserts that the current transport type is 'http'.
|
|
2665
|
+
* @internal
|
|
2666
|
+
*/
|
|
2667
|
+
private _assertHttpType;
|
|
2668
|
+
}
|
|
2669
|
+
/**
|
|
2670
|
+
* Factory function to create a new MCP builder.
|
|
2671
|
+
*
|
|
2672
|
+
* @description
|
|
2673
|
+
* Convenience function that wraps `IgniterAgentMCPBuilder.create()`.
|
|
2674
|
+
*
|
|
2675
|
+
* @typeParam TName - The configuration name type
|
|
2676
|
+
* @param name - Unique name for the MCP configuration
|
|
2677
|
+
* @returns A new IgniterAgentMCPBuilder instance
|
|
2678
|
+
*
|
|
2679
|
+
* @example
|
|
2680
|
+
* ```typescript
|
|
2681
|
+
* import { IgniterAgentMCPClient } from '@igniter-js/agents';
|
|
2682
|
+
*
|
|
2683
|
+
* const filesystemMCP = IgniterAgentMCPClient.create('filesystem')
|
|
2684
|
+
* .withType('stdio')
|
|
2685
|
+
* .withCommand('npx')
|
|
2686
|
+
* .withArgs(['-y', '@modelcontextprotocol/server-filesystem', '/tmp'])
|
|
2687
|
+
* .build();
|
|
2688
|
+
* ```
|
|
2689
|
+
*
|
|
2690
|
+
* @public
|
|
2691
|
+
*/
|
|
2692
|
+
declare const IgniterAgentMCPClient: {
|
|
2693
|
+
create: typeof IgniterAgentMCPBuilder.create;
|
|
2694
|
+
};
|
|
2695
|
+
|
|
2696
|
+
/**
|
|
2697
|
+
* @fileoverview Prompt builder for IgniterAgent instructions.
|
|
2698
|
+
*
|
|
2699
|
+
* @description
|
|
2700
|
+
* Provides a lightweight template interpolation utility to build
|
|
2701
|
+
* prompt strings with context data.
|
|
2702
|
+
*
|
|
2703
|
+
* @module builders/prompt
|
|
2704
|
+
* @packageDocumentation
|
|
2705
|
+
*/
|
|
2706
|
+
|
|
2707
|
+
/**
|
|
2708
|
+
* Fluent prompt builder for agent instructions.
|
|
2709
|
+
*
|
|
2710
|
+
* @example
|
|
2711
|
+
* ```typescript
|
|
2712
|
+
* const prompt = IgniterAgentPrompt.create(
|
|
2713
|
+
* "You are {{agentName}}. User: {{user.name}}"
|
|
2714
|
+
* );
|
|
2715
|
+
*
|
|
2716
|
+
* const result = prompt.build({ agentName: "assistant", user: { name: "Ada" } });
|
|
2717
|
+
* // "You are assistant. User: Ada"
|
|
2718
|
+
* ```
|
|
2719
|
+
*
|
|
2720
|
+
* @public
|
|
2721
|
+
*/
|
|
2722
|
+
declare class IgniterAgentPromptBuilder<TTemplate extends string = string, TContext extends Record<string, unknown> = Record<string, unknown>> implements IgniterAgentPromptTemplate<TContext> {
|
|
2723
|
+
private readonly template;
|
|
2724
|
+
private constructor();
|
|
2725
|
+
/**
|
|
2726
|
+
* Creates a new prompt builder.
|
|
2727
|
+
*
|
|
2728
|
+
* @param template - Prompt template string with {{placeholders}}
|
|
2729
|
+
* @returns A new prompt builder instance
|
|
2730
|
+
*/
|
|
2731
|
+
static create<TNewTemplate extends string>(template: TNewTemplate): IgniterAgentPromptBuilder<TNewTemplate, Record<string, unknown>>;
|
|
2732
|
+
/**
|
|
2733
|
+
* Builds the prompt string with the provided context.
|
|
2734
|
+
*
|
|
2735
|
+
* @param context - Context data used for interpolation
|
|
2736
|
+
* @returns The resolved prompt string
|
|
2737
|
+
*/
|
|
2738
|
+
build(context: TContext): string;
|
|
2739
|
+
/**
|
|
2740
|
+
* Returns the raw prompt template string.
|
|
2741
|
+
*/
|
|
2742
|
+
getTemplate(): string;
|
|
2743
|
+
}
|
|
2744
|
+
/**
|
|
2745
|
+
* Alias for IgniterAgentPromptBuilder for cleaner API.
|
|
2746
|
+
*
|
|
2747
|
+
* @public
|
|
2748
|
+
*/
|
|
2749
|
+
declare const IgniterAgentPrompt: typeof IgniterAgentPromptBuilder;
|
|
2750
|
+
/**
|
|
2751
|
+
* Type alias for the prompt builder constructor.
|
|
2752
|
+
*
|
|
2753
|
+
* @public
|
|
2754
|
+
*/
|
|
2755
|
+
type IgniterAgentPrompt = typeof IgniterAgentPromptBuilder;
|
|
2756
|
+
|
|
2757
|
+
/**
|
|
2758
|
+
* @fileoverview Custom error classes for the IgniterAgent library.
|
|
2759
|
+
* This module provides a hierarchy of error types for precise error handling.
|
|
2760
|
+
*
|
|
2761
|
+
* @description
|
|
2762
|
+
* The error system in IgniterAgent follows these principles:
|
|
2763
|
+
* - All errors extend IgniterError from @igniter-js/core for consistency
|
|
2764
|
+
* - Errors include rich context for debugging
|
|
2765
|
+
* - Error codes enable programmatic error handling
|
|
2766
|
+
* - Stack traces are preserved for debugging
|
|
2767
|
+
*
|
|
2768
|
+
* @example
|
|
2769
|
+
* ```typescript
|
|
2770
|
+
* import {
|
|
2771
|
+
* IgniterAgentError,
|
|
2772
|
+
* IgniterAgentMCPError,
|
|
2773
|
+
* IgniterAgentToolError,
|
|
2774
|
+
* isIgniterAgentError
|
|
2775
|
+
* } from '@igniter-js/agents';
|
|
2776
|
+
*
|
|
2777
|
+
* try {
|
|
2778
|
+
* await agent.generate({ messages: [] });
|
|
2779
|
+
* } catch (error) {
|
|
2780
|
+
* if (isIgniterAgentError(error)) {
|
|
2781
|
+
* console.error(`[${error.code}] ${error.message}`);
|
|
2782
|
+
* }
|
|
2783
|
+
* }
|
|
2784
|
+
* ```
|
|
2785
|
+
*
|
|
2786
|
+
* @module errors
|
|
2787
|
+
* @packageDocumentation
|
|
2788
|
+
*/
|
|
2789
|
+
|
|
2790
|
+
/**
|
|
2791
|
+
* Error codes for categorizing IgniterAgent errors.
|
|
2792
|
+
*
|
|
2793
|
+
* @description
|
|
2794
|
+
* Each error code represents a specific type of failure.
|
|
2795
|
+
* Use these codes for programmatic error handling.
|
|
2796
|
+
*
|
|
2797
|
+
* @example
|
|
2798
|
+
* ```typescript
|
|
2799
|
+
* if (error.code === IgniterAgentErrorCode.MCP_CONNECTION_FAILED) {
|
|
2800
|
+
* // Handle MCP connection failure
|
|
2801
|
+
* await retryMCPConnection();
|
|
2802
|
+
* }
|
|
2803
|
+
* ```
|
|
2804
|
+
*
|
|
2805
|
+
* @public
|
|
2806
|
+
*/
|
|
2807
|
+
declare enum IgniterAgentErrorCode {
|
|
2808
|
+
/** Generic/unknown error */
|
|
2809
|
+
UNKNOWN = "IGNITER_AGENT_UNKNOWN_ERROR",
|
|
2810
|
+
/** Invalid configuration provided */
|
|
2811
|
+
INVALID_CONFIG = "IGNITER_AGENT_INVALID_CONFIG",
|
|
2812
|
+
/** Required value is missing */
|
|
2813
|
+
MISSING_REQUIRED = "IGNITER_AGENT_MISSING_REQUIRED",
|
|
2814
|
+
/** Agent not initialized */
|
|
2815
|
+
AGENT_NOT_INITIALIZED = "IGNITER_AGENT_NOT_INITIALIZED",
|
|
2816
|
+
/** Model not configured */
|
|
2817
|
+
AGENT_MODEL_MISSING = "IGNITER_AGENT_MODEL_MISSING",
|
|
2818
|
+
/** Agent build failed */
|
|
2819
|
+
AGENT_BUILD_FAILED = "IGNITER_AGENT_BUILD_FAILED",
|
|
2820
|
+
/** MCP connection failed */
|
|
2821
|
+
MCP_CONNECTION_FAILED = "IGNITER_AGENT_MCP_CONNECTION_FAILED",
|
|
2822
|
+
/** MCP client not found */
|
|
2823
|
+
MCP_CLIENT_NOT_FOUND = "IGNITER_AGENT_MCP_CLIENT_NOT_FOUND",
|
|
2824
|
+
/** MCP tool execution failed */
|
|
2825
|
+
MCP_TOOL_ERROR = "IGNITER_AGENT_MCP_TOOL_ERROR",
|
|
2826
|
+
/** Invalid MCP configuration */
|
|
2827
|
+
MCP_INVALID_CONFIG = "IGNITER_AGENT_MCP_INVALID_CONFIG",
|
|
2828
|
+
/** Tool execution failed */
|
|
2829
|
+
TOOL_EXECUTION_FAILED = "IGNITER_AGENT_TOOL_EXECUTION_FAILED",
|
|
2830
|
+
/** Tool not found */
|
|
2831
|
+
TOOL_NOT_FOUND = "IGNITER_AGENT_TOOL_NOT_FOUND",
|
|
2832
|
+
/** Tool validation failed */
|
|
2833
|
+
TOOL_VALIDATION_FAILED = "IGNITER_AGENT_TOOL_VALIDATION_FAILED",
|
|
2834
|
+
/** Invalid agent context schema */
|
|
2835
|
+
AGENT_CONTEXT_SCHEMA_INVALID = "IGNITER_AGENT_CONTEXT_SCHEMA_INVALID",
|
|
2836
|
+
/** Memory provider error */
|
|
2837
|
+
MEMORY_PROVIDER_ERROR = "IGNITER_AGENT_MEMORY_PROVIDER_ERROR",
|
|
2838
|
+
/** Memory not found */
|
|
2839
|
+
MEMORY_NOT_FOUND = "IGNITER_AGENT_MEMORY_NOT_FOUND",
|
|
2840
|
+
/** Memory update failed */
|
|
2841
|
+
MEMORY_UPDATE_FAILED = "IGNITER_AGENT_MEMORY_UPDATE_FAILED",
|
|
2842
|
+
/** Adapter connection failed */
|
|
2843
|
+
ADAPTER_CONNECTION_FAILED = "IGNITER_AGENT_ADAPTER_CONNECTION_FAILED",
|
|
2844
|
+
/** Adapter operation failed */
|
|
2845
|
+
ADAPTER_OPERATION_FAILED = "IGNITER_AGENT_ADAPTER_OPERATION_FAILED",
|
|
2846
|
+
/** Adapter not initialized */
|
|
2847
|
+
ADAPTER_NOT_INITIALIZED = "IGNITER_AGENT_ADAPTER_NOT_INITIALIZED"
|
|
2848
|
+
}
|
|
2849
|
+
/**
|
|
2850
|
+
* Options for creating an IgniterAgentError.
|
|
2851
|
+
*
|
|
2852
|
+
* @public
|
|
2853
|
+
*/
|
|
2854
|
+
interface IgniterAgentErrorOptions {
|
|
2855
|
+
/** Human-readable error message */
|
|
2856
|
+
message: string;
|
|
2857
|
+
/** Error code for categorization */
|
|
2858
|
+
code: IgniterAgentErrorCode;
|
|
2859
|
+
/** HTTP status code (defaults to 500) */
|
|
2860
|
+
statusCode?: number;
|
|
2861
|
+
/** The component that threw the error */
|
|
2862
|
+
causer?: string;
|
|
2863
|
+
/** Additional details about the error */
|
|
2864
|
+
details?: unknown;
|
|
2865
|
+
/** Additional metadata */
|
|
2866
|
+
metadata?: Record<string, unknown>;
|
|
2867
|
+
/** Logger instance for automatic logging */
|
|
2868
|
+
logger?: IgniterLogger;
|
|
2869
|
+
/** Original error if this wraps another error */
|
|
2870
|
+
cause?: Error;
|
|
2871
|
+
}
|
|
2872
|
+
/**
|
|
2873
|
+
* Base error class for all IgniterAgent errors.
|
|
2874
|
+
*
|
|
2875
|
+
* @description
|
|
2876
|
+
* All custom errors in the IgniterAgent library extend this class,
|
|
2877
|
+
* which itself extends IgniterError from @igniter-js/core.
|
|
2878
|
+
* It provides a consistent interface for error handling, including
|
|
2879
|
+
* error codes, context, and cause tracking.
|
|
2880
|
+
*
|
|
2881
|
+
* @example
|
|
2882
|
+
* ```typescript
|
|
2883
|
+
* // Throwing a base error
|
|
2884
|
+
* throw new IgniterAgentError({
|
|
2885
|
+
* message: 'Something went wrong',
|
|
2886
|
+
* code: IgniterAgentErrorCode.UNKNOWN,
|
|
2887
|
+
* causer: 'Agent',
|
|
2888
|
+
* metadata: { operation: 'generate' }
|
|
2889
|
+
* });
|
|
2890
|
+
*
|
|
2891
|
+
* // Catching and handling
|
|
2892
|
+
* try {
|
|
2893
|
+
* await agent.start();
|
|
2894
|
+
* } catch (error) {
|
|
2895
|
+
* if (error instanceof IgniterAgentError) {
|
|
2896
|
+
* logger.error({
|
|
2897
|
+
* code: error.code,
|
|
2898
|
+
* message: error.message,
|
|
2899
|
+
* details: error.details
|
|
2900
|
+
* });
|
|
2901
|
+
* }
|
|
2902
|
+
* }
|
|
2903
|
+
* ```
|
|
2904
|
+
*
|
|
2905
|
+
* @public
|
|
2906
|
+
*/
|
|
2907
|
+
declare class IgniterAgentError extends IgniterError {
|
|
2908
|
+
/**
|
|
2909
|
+
* Creates a new IgniterAgentError.
|
|
2910
|
+
*
|
|
2911
|
+
* @param options - Error configuration options
|
|
2912
|
+
*/
|
|
2913
|
+
constructor(options: IgniterAgentErrorOptions);
|
|
2914
|
+
}
|
|
2915
|
+
/**
|
|
2916
|
+
* Error thrown when agent configuration is invalid.
|
|
2917
|
+
*
|
|
2918
|
+
* @example
|
|
2919
|
+
* ```typescript
|
|
2920
|
+
* throw new IgniterAgentConfigError({
|
|
2921
|
+
* message: 'Model is required but was not provided',
|
|
2922
|
+
* field: 'model'
|
|
2923
|
+
* });
|
|
2924
|
+
* ```
|
|
2925
|
+
*
|
|
2926
|
+
* @public
|
|
2927
|
+
*/
|
|
2928
|
+
declare class IgniterAgentConfigError extends IgniterAgentError {
|
|
2929
|
+
/**
|
|
2930
|
+
* The configuration field that caused the error.
|
|
2931
|
+
*/
|
|
2932
|
+
readonly field?: string;
|
|
2933
|
+
constructor(options: Omit<IgniterAgentErrorOptions, "code"> & {
|
|
2934
|
+
field?: string;
|
|
2935
|
+
});
|
|
2936
|
+
}
|
|
2937
|
+
/**
|
|
2938
|
+
* Error thrown when an MCP operation fails.
|
|
2939
|
+
*
|
|
2940
|
+
* @description
|
|
2941
|
+
* Covers all MCP-related failures including connection errors,
|
|
2942
|
+
* tool execution errors, and configuration errors.
|
|
2943
|
+
*
|
|
2944
|
+
* @example
|
|
2945
|
+
* ```typescript
|
|
2946
|
+
* throw new IgniterAgentMCPError({
|
|
2947
|
+
* message: 'Failed to connect to MCP server',
|
|
2948
|
+
* code: IgniterAgentErrorCode.MCP_CONNECTION_FAILED,
|
|
2949
|
+
* mcpName: 'filesystem'
|
|
2950
|
+
* });
|
|
2951
|
+
* ```
|
|
2952
|
+
*
|
|
2953
|
+
* @public
|
|
2954
|
+
*/
|
|
2955
|
+
declare class IgniterAgentMCPError extends IgniterAgentError {
|
|
2956
|
+
/**
|
|
2957
|
+
* The name of the MCP configuration that caused the error.
|
|
2958
|
+
*/
|
|
2959
|
+
readonly mcpName?: string;
|
|
2960
|
+
constructor(options: IgniterAgentErrorOptions & {
|
|
2961
|
+
mcpName?: string;
|
|
2962
|
+
});
|
|
2963
|
+
}
|
|
2964
|
+
/**
|
|
2965
|
+
* Error thrown when a tool execution fails.
|
|
2966
|
+
*
|
|
2967
|
+
* @example
|
|
2968
|
+
* ```typescript
|
|
2969
|
+
* throw new IgniterAgentToolError({
|
|
2970
|
+
* message: 'Tool execution timed out',
|
|
2971
|
+
* toolName: 'github_createIssue',
|
|
2972
|
+
* metadata: { timeout: 30000 }
|
|
2973
|
+
* });
|
|
2974
|
+
* ```
|
|
2975
|
+
*
|
|
2976
|
+
* @public
|
|
2977
|
+
*/
|
|
2978
|
+
declare class IgniterAgentToolError extends IgniterAgentError {
|
|
2979
|
+
/**
|
|
2980
|
+
* The name of the tool that caused the error.
|
|
2981
|
+
*/
|
|
2982
|
+
readonly toolName: string;
|
|
2983
|
+
constructor(options: Omit<IgniterAgentErrorOptions, "code"> & {
|
|
2984
|
+
toolName: string;
|
|
2985
|
+
});
|
|
2986
|
+
}
|
|
2987
|
+
/**
|
|
2988
|
+
* Error thrown when a memory operation fails.
|
|
2989
|
+
*
|
|
2990
|
+
* @example
|
|
2991
|
+
* ```typescript
|
|
2992
|
+
* throw new IgniterAgentMemoryError({
|
|
2993
|
+
* message: 'Failed to save message to history',
|
|
2994
|
+
* code: IgniterAgentErrorCode.MEMORY_UPDATE_FAILED,
|
|
2995
|
+
* metadata: { chatId: 'chat_123' }
|
|
2996
|
+
* });
|
|
2997
|
+
* ```
|
|
2998
|
+
*
|
|
2999
|
+
* @public
|
|
3000
|
+
*/
|
|
3001
|
+
declare class IgniterAgentMemoryError extends IgniterAgentError {
|
|
3002
|
+
constructor(options: IgniterAgentErrorOptions);
|
|
3003
|
+
}
|
|
3004
|
+
/**
|
|
3005
|
+
* Error thrown when an adapter operation fails.
|
|
3006
|
+
*
|
|
3007
|
+
* @example
|
|
3008
|
+
* ```typescript
|
|
3009
|
+
* throw new IgniterAgentAdapterError({
|
|
3010
|
+
* message: 'Redis connection lost',
|
|
3011
|
+
* code: IgniterAgentErrorCode.ADAPTER_CONNECTION_FAILED,
|
|
3012
|
+
* adapterName: 'redis'
|
|
3013
|
+
* });
|
|
3014
|
+
* ```
|
|
3015
|
+
*
|
|
3016
|
+
* @public
|
|
3017
|
+
*/
|
|
3018
|
+
declare class IgniterAgentAdapterError extends IgniterAgentError {
|
|
3019
|
+
/**
|
|
3020
|
+
* The name of the adapter that caused the error.
|
|
3021
|
+
*/
|
|
3022
|
+
readonly adapterName?: string;
|
|
3023
|
+
constructor(options: IgniterAgentErrorOptions & {
|
|
3024
|
+
adapterName?: string;
|
|
3025
|
+
});
|
|
3026
|
+
}
|
|
3027
|
+
/**
|
|
3028
|
+
* Type guard to check if an error is an IgniterAgentError.
|
|
3029
|
+
*
|
|
3030
|
+
* @description
|
|
3031
|
+
* Use this function to safely narrow error types in catch blocks.
|
|
3032
|
+
*
|
|
3033
|
+
* @param error - The error to check
|
|
3034
|
+
* @returns True if the error is an IgniterAgentError
|
|
3035
|
+
*
|
|
3036
|
+
* @example
|
|
3037
|
+
* ```typescript
|
|
3038
|
+
* try {
|
|
3039
|
+
* await agent.generate({ messages: [] });
|
|
3040
|
+
* } catch (error) {
|
|
3041
|
+
* if (isIgniterAgentError(error)) {
|
|
3042
|
+
* // TypeScript knows error is IgniterAgentError
|
|
3043
|
+
* console.log(error.code, error.details);
|
|
3044
|
+
* }
|
|
3045
|
+
* }
|
|
3046
|
+
* ```
|
|
3047
|
+
*
|
|
3048
|
+
* @public
|
|
3049
|
+
*/
|
|
3050
|
+
declare function isIgniterAgentError(error: unknown): error is IgniterAgentError;
|
|
3051
|
+
/**
|
|
3052
|
+
* Type guard to check if an error is an MCP error.
|
|
3053
|
+
*
|
|
3054
|
+
* @param error - The error to check
|
|
3055
|
+
* @returns True if the error is an IgniterAgentMCPError
|
|
3056
|
+
*
|
|
3057
|
+
* @public
|
|
3058
|
+
*/
|
|
3059
|
+
declare function isIgniterAgentMCPError(error: unknown): error is IgniterAgentMCPError;
|
|
3060
|
+
/**
|
|
3061
|
+
* Type guard to check if an error is a tool error.
|
|
3062
|
+
*
|
|
3063
|
+
* @param error - The error to check
|
|
3064
|
+
* @returns True if the error is an IgniterAgentToolError
|
|
3065
|
+
*
|
|
3066
|
+
* @public
|
|
3067
|
+
*/
|
|
3068
|
+
declare function isIgniterAgentToolError(error: unknown): error is IgniterAgentToolError;
|
|
3069
|
+
/**
|
|
3070
|
+
* Wraps an unknown error in an IgniterAgentError.
|
|
3071
|
+
*
|
|
3072
|
+
* @description
|
|
3073
|
+
* Useful for normalizing errors from external sources into
|
|
3074
|
+
* the IgniterAgent error format.
|
|
3075
|
+
*
|
|
3076
|
+
* @param error - The error to wrap
|
|
3077
|
+
* @param options - Additional options to add
|
|
3078
|
+
* @returns An IgniterAgentError wrapping the original
|
|
3079
|
+
*
|
|
3080
|
+
* @example
|
|
3081
|
+
* ```typescript
|
|
3082
|
+
* try {
|
|
3083
|
+
* await externalService.call();
|
|
3084
|
+
* } catch (error) {
|
|
3085
|
+
* throw wrapError(error, { causer: 'ExternalService' });
|
|
3086
|
+
* }
|
|
3087
|
+
* ```
|
|
3088
|
+
*
|
|
3089
|
+
* @public
|
|
3090
|
+
*/
|
|
3091
|
+
declare function wrapError(error: unknown, options?: Partial<IgniterAgentErrorOptions>): IgniterAgentError;
|
|
3092
|
+
|
|
3093
|
+
/**
|
|
3094
|
+
* String utilities for `@igniter-js/agents`.
|
|
3095
|
+
*/
|
|
3096
|
+
declare class IgniterAgentStringUtils {
|
|
3097
|
+
/**
|
|
3098
|
+
* Generates a unique identifier.
|
|
3099
|
+
*/
|
|
3100
|
+
static generateId(prefix?: string): string;
|
|
3101
|
+
/**
|
|
3102
|
+
* Truncates a string to a maximum length.
|
|
3103
|
+
*/
|
|
3104
|
+
static truncate(str: string, maxLength: number, suffix?: string): string;
|
|
3105
|
+
/**
|
|
3106
|
+
* Converts a string to snake_case.
|
|
3107
|
+
*/
|
|
3108
|
+
static toSnakeCase(str: string): string;
|
|
3109
|
+
/**
|
|
3110
|
+
* Converts a string to camelCase.
|
|
3111
|
+
*/
|
|
3112
|
+
static toCamelCase(str: string): string;
|
|
3113
|
+
}
|
|
3114
|
+
|
|
3115
|
+
/**
|
|
3116
|
+
* Object utilities for `@igniter-js/agents`.
|
|
3117
|
+
*/
|
|
3118
|
+
declare class IgniterAgentObjectUtils {
|
|
3119
|
+
/**
|
|
3120
|
+
* Deep merges two objects.
|
|
3121
|
+
*/
|
|
3122
|
+
static deepMerge<T extends Record<string, unknown>>(target: T, source: Partial<T>): T;
|
|
3123
|
+
/**
|
|
3124
|
+
* Picks specified keys from an object.
|
|
3125
|
+
*/
|
|
3126
|
+
static pick<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
3127
|
+
/**
|
|
3128
|
+
* Omits specified keys from an object.
|
|
3129
|
+
*/
|
|
3130
|
+
static omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
|
|
3131
|
+
}
|
|
3132
|
+
|
|
3133
|
+
/**
|
|
3134
|
+
* Async utilities for `@igniter-js/agents`.
|
|
3135
|
+
*/
|
|
3136
|
+
declare class IgniterAgentAsyncUtils {
|
|
3137
|
+
/**
|
|
3138
|
+
* Delays execution for a specified duration.
|
|
3139
|
+
*/
|
|
3140
|
+
static delay(ms: number): Promise<void>;
|
|
3141
|
+
/**
|
|
3142
|
+
* Retries an async function with exponential backoff.
|
|
3143
|
+
*/
|
|
3144
|
+
static retry<T>(fn: () => Promise<T>, options?: {
|
|
3145
|
+
maxAttempts?: number;
|
|
3146
|
+
baseDelay?: number;
|
|
3147
|
+
maxDelay?: number;
|
|
3148
|
+
onRetry?: (attempt: number, error: Error) => void;
|
|
3149
|
+
}): Promise<T>;
|
|
3150
|
+
}
|
|
3151
|
+
|
|
3152
|
+
/**
|
|
3153
|
+
* Validation utilities for `@igniter-js/agents`.
|
|
3154
|
+
*/
|
|
3155
|
+
declare class IgniterAgentValidationUtils {
|
|
3156
|
+
/**
|
|
3157
|
+
* Checks if a value is defined (not null or undefined).
|
|
3158
|
+
*/
|
|
3159
|
+
static isDefined<T>(value: T | null | undefined): value is T;
|
|
3160
|
+
/**
|
|
3161
|
+
* Checks if a value is a non-empty string.
|
|
3162
|
+
*/
|
|
3163
|
+
static isNonEmptyString(value: unknown): value is string;
|
|
3164
|
+
/**
|
|
3165
|
+
* Checks if a value is a plain object.
|
|
3166
|
+
*/
|
|
3167
|
+
static isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
3168
|
+
}
|
|
3169
|
+
|
|
3170
|
+
export { type DeepPartial, type DeepRequired, IgniterAgent, IgniterAgentAdapterError, IgniterAgentAsyncUtils, IgniterAgentBuilder, type IgniterAgentBuiltAgent, type IgniterAgentBuiltTool, type IgniterAgentBuiltToolset, IgniterAgentChatSession, type IgniterAgentConfig, IgniterAgentConfigError, type IgniterAgentConnectionStatus, IgniterAgentConversationMessage, IgniterAgentCore, IgniterAgentError, IgniterAgentErrorCode, type IgniterAgentErrorOptions, type IgniterAgentFlattenedToolSet, IgniterAgentGetChatsParams, IgniterAgentGetMessagesParams, type IgniterAgentHooks, type IgniterAgentInfo, IgniterAgentMCPBuilder, IgniterAgentMCPClient, type IgniterAgentMCPClientInterface, type IgniterAgentMCPConfigBase, type IgniterAgentMCPConfigUnion, IgniterAgentMCPError, type IgniterAgentMCPHttpClientInterface, type IgniterAgentMCPHttpConfig, type IgniterAgentMCPPartialConfig, type IgniterAgentMCPStdioClientInterface, type IgniterAgentMCPStdioConfig, IgniterAgentManager, IgniterAgentManagerBuilder, IgniterAgentManagerCore, type IgniterAgentManagerOptions, IgniterAgentMemoryConfig, IgniterAgentMemoryCore, IgniterAgentMemoryError, IgniterAgentMemoryRuntime, IgniterAgentObjectUtils, IgniterAgentPrompt, IgniterAgentPromptBuilder, type IgniterAgentPromptTemplate, type IgniterAgentStatus, IgniterAgentStringUtils, IgniterAgentTool, IgniterAgentToolBuilder, type IgniterAgentToolDefinition, IgniterAgentToolError, type IgniterAgentToolErrorResult, type IgniterAgentToolExecuteOptions, type IgniterAgentToolResult, type IgniterAgentToolSuccessResult, IgniterAgentToolset, IgniterAgentToolsetBuilder, type IgniterAgentToolsetParams, type IgniterAgentToolsetType, IgniterAgentUIMessage, IgniterAgentUpdateWorkingMemoryParams, IgniterAgentValidationUtils, IgniterAgentWorkingMemory, IgniterAgentWorkingMemoryParams, type InferZodSchema, type KeysOfType, isIgniterAgentError, isIgniterAgentMCPError, isIgniterAgentToolError, wrapError };
|