@agentxjs/types 0.0.9 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Agent-BXUYGlWZ.d.cts +510 -0
- package/dist/Agent-CaSxMF_E.d.ts +510 -0
- package/dist/CommandEvent-CbXzPolX.d.ts +495 -0
- package/dist/CommandEvent-DCdk7lzX.d.cts +495 -0
- package/dist/Container-DR-1g44i.d.ts +641 -0
- package/dist/Container-dBDOcjhk.d.cts +641 -0
- package/dist/ContentPart-CqOh-rI1.d.ts +19 -0
- package/dist/ContentPart-DEFnYXCU.d.cts +19 -0
- package/dist/DriveableEvent-Bj7nn-Uk.d.ts +161 -0
- package/dist/DriveableEvent-CCMC1h_C.d.cts +161 -0
- package/dist/ErrorMessage-BoIh3MIO.d.cts +24 -0
- package/dist/ErrorMessage-BoIh3MIO.d.ts +24 -0
- package/dist/ImageRecord-Cn0VcJWk.d.cts +71 -0
- package/dist/ImageRecord-Cn0VcJWk.d.ts +71 -0
- package/dist/LoggerFactory-DZtw0M7U.d.cts +129 -0
- package/dist/LoggerFactory-DZtw0M7U.d.ts +129 -0
- package/dist/Message-Crh81uLL.d.cts +45 -0
- package/dist/Message-DWQUt647.d.ts +45 -0
- package/dist/Persistence-BQkdKomV.d.ts +230 -0
- package/dist/Persistence-Dr70FEBh.d.cts +230 -0
- package/dist/StopReason-D4DthB1h.d.cts +39 -0
- package/dist/StopReason-D4DthB1h.d.ts +39 -0
- package/dist/SystemEvent-CPvvxdMQ.d.cts +159 -0
- package/dist/SystemEvent-CPvvxdMQ.d.ts +159 -0
- package/dist/ToolResultMessage-CDG2L7Zv.d.ts +332 -0
- package/dist/ToolResultMessage-CRKMSf5d.d.cts +332 -0
- package/dist/agent-internal.cjs +19 -0
- package/dist/agent-internal.cjs.map +1 -0
- package/dist/agent-internal.d.cts +52 -0
- package/dist/agent-internal.d.ts +52 -0
- package/dist/agent-internal.js +1 -0
- package/dist/agent-internal.js.map +1 -0
- package/dist/agent.cjs +70 -0
- package/dist/agent.cjs.map +1 -0
- package/dist/agent.d.cts +229 -0
- package/dist/agent.d.ts +229 -0
- package/dist/agent.js +41 -0
- package/dist/agent.js.map +1 -0
- package/dist/agentx.cjs +38 -0
- package/dist/agentx.cjs.map +1 -0
- package/dist/agentx.d.cts +311 -0
- package/dist/agentx.d.ts +311 -0
- package/dist/agentx.js +12 -0
- package/dist/agentx.js.map +1 -0
- package/dist/chunk-2QHAIM3V.js +1 -0
- package/dist/chunk-2QHAIM3V.js.map +1 -0
- package/dist/common.cjs +19 -0
- package/dist/common.cjs.map +1 -0
- package/dist/common.d.cts +43 -0
- package/dist/common.d.ts +43 -0
- package/dist/common.js +2 -0
- package/dist/common.js.map +1 -0
- package/dist/event.cjs +184 -0
- package/dist/event.cjs.map +1 -0
- package/dist/event.d.cts +769 -0
- package/dist/event.d.ts +769 -0
- package/dist/event.js +134 -0
- package/dist/event.js.map +1 -0
- package/dist/index-CjFNcCxR.d.cts +299 -0
- package/dist/index-usKuk41S.d.ts +299 -0
- package/dist/index.cjs +2 -185
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -5267
- package/dist/index.d.ts +8 -5267
- package/dist/index.js +1 -150
- package/dist/index.js.map +1 -1
- package/dist/network.cjs +19 -0
- package/dist/network.cjs.map +1 -0
- package/dist/network.d.cts +168 -0
- package/dist/network.d.ts +168 -0
- package/dist/network.js +1 -0
- package/dist/network.js.map +1 -0
- package/dist/runtime-internal.cjs +19 -0
- package/dist/runtime-internal.cjs.map +1 -0
- package/dist/runtime-internal.d.cts +943 -0
- package/dist/runtime-internal.d.ts +943 -0
- package/dist/runtime-internal.js +1 -0
- package/dist/runtime-internal.js.map +1 -0
- package/dist/runtime.cjs +19 -0
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.cts +217 -0
- package/dist/runtime.d.ts +217 -0
- package/dist/runtime.js +1 -0
- package/dist/runtime.js.map +1 -0
- package/package.json +82 -10
- package/LICENSE +0 -21
|
@@ -0,0 +1,943 @@
|
|
|
1
|
+
import { b as SystemBusProducer, c as SystemBusConsumer } from './Container-DR-1g44i.js';
|
|
2
|
+
export { B as BusEventHandler, C as Container, d as SubscribeOptions, S as SystemBus, U as Unsubscribe } from './Container-DR-1g44i.js';
|
|
3
|
+
import { M as Message } from './Message-DWQUt647.js';
|
|
4
|
+
import { M as MessageRole, C as ContentPart } from './ContentPart-CqOh-rI1.js';
|
|
5
|
+
import { S as StopReason } from './StopReason-D4DthB1h.js';
|
|
6
|
+
import { E as EventSource } from './SystemEvent-CPvvxdMQ.js';
|
|
7
|
+
import { C as ContainerRepository, I as ImageRepository, S as SessionRepository } from './Persistence-BQkdKomV.js';
|
|
8
|
+
export { c as ContainerConfig, a as ContainerRecord, P as Persistence, b as SessionRecord } from './Persistence-BQkdKomV.js';
|
|
9
|
+
export { a as ImageMetadata, I as ImageRecord } from './ImageRecord-Cn0VcJWk.js';
|
|
10
|
+
import './CommandEvent-CbXzPolX.js';
|
|
11
|
+
import './ToolResultMessage-CDG2L7Zv.js';
|
|
12
|
+
import './ErrorMessage-BoIh3MIO.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Repository - Unified persistence interface for AgentX
|
|
16
|
+
*
|
|
17
|
+
* Combines all domain-specific repositories into a single interface.
|
|
18
|
+
* Implementations can be local (SQLite) or remote (HTTP API).
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // Local implementation (node-runtime)
|
|
23
|
+
* const repository = new SQLiteRepository(dbPath);
|
|
24
|
+
*
|
|
25
|
+
* // Remote implementation (browser)
|
|
26
|
+
* const repository = new RemoteRepository({ serverUrl: "http://..." });
|
|
27
|
+
*
|
|
28
|
+
* // Use with runtime
|
|
29
|
+
* const runtime = createRuntime({ repository });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Repository - Unified persistence interface
|
|
35
|
+
*
|
|
36
|
+
* Combines all domain repositories for convenient single-point configuration.
|
|
37
|
+
*/
|
|
38
|
+
interface Repository extends ContainerRepository, ImageRepository, SessionRepository {
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* MessageRecord - Storage schema for Message persistence
|
|
43
|
+
*
|
|
44
|
+
* Pure data type representing a message in storage.
|
|
45
|
+
* Content is stored as JSON to accommodate different message types.
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Message storage record
|
|
50
|
+
*/
|
|
51
|
+
interface MessageRecord {
|
|
52
|
+
/**
|
|
53
|
+
* Unique message identifier
|
|
54
|
+
*/
|
|
55
|
+
messageId: string;
|
|
56
|
+
/**
|
|
57
|
+
* Associated session identifier
|
|
58
|
+
*/
|
|
59
|
+
sessionId: string;
|
|
60
|
+
/**
|
|
61
|
+
* Message role: user, assistant, tool-call, tool-result
|
|
62
|
+
*/
|
|
63
|
+
role: MessageRole;
|
|
64
|
+
/**
|
|
65
|
+
* Serialized message content (JSON)
|
|
66
|
+
* Structure varies by role type
|
|
67
|
+
*/
|
|
68
|
+
content: Record<string, unknown>;
|
|
69
|
+
/**
|
|
70
|
+
* Creation timestamp (Unix milliseconds)
|
|
71
|
+
*/
|
|
72
|
+
createdAt: number;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* EnvironmentRecord - Storage for Environment implementation private state
|
|
77
|
+
*
|
|
78
|
+
* Used by Environment implementations (Receptor + Effector) to store
|
|
79
|
+
* their private state that maps to our Session. The business layer
|
|
80
|
+
* doesn't care about the internal structure of `state`.
|
|
81
|
+
*
|
|
82
|
+
* Examples:
|
|
83
|
+
* - ClaudeEnvironment: { sdkSessionId: "claude_xxx" }
|
|
84
|
+
* - OpenAIEnvironment: { threadId: "thread_xxx" }
|
|
85
|
+
* - CustomEnvironment: any implementation-specific data
|
|
86
|
+
*
|
|
87
|
+
* Relationship:
|
|
88
|
+
* ```
|
|
89
|
+
* SessionRecord (business layer)
|
|
90
|
+
* │
|
|
91
|
+
* │ sessionId
|
|
92
|
+
* ▼
|
|
93
|
+
* EnvironmentRecord (implementation layer)
|
|
94
|
+
* │
|
|
95
|
+
* │ state (opaque to business layer)
|
|
96
|
+
* ▼
|
|
97
|
+
* External SDK/API state
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
/**
|
|
101
|
+
* EnvironmentRecord - Environment implementation private state storage
|
|
102
|
+
*/
|
|
103
|
+
interface EnvironmentRecord {
|
|
104
|
+
/**
|
|
105
|
+
* Associated session ID (foreign key to SessionRecord)
|
|
106
|
+
*/
|
|
107
|
+
sessionId: string;
|
|
108
|
+
/**
|
|
109
|
+
* Environment type identifier
|
|
110
|
+
* Examples: "claude", "openai", "custom"
|
|
111
|
+
*/
|
|
112
|
+
environmentType: string;
|
|
113
|
+
/**
|
|
114
|
+
* Environment private state (opaque to business layer)
|
|
115
|
+
* Structure is defined by each Environment implementation
|
|
116
|
+
*/
|
|
117
|
+
state: Record<string, unknown>;
|
|
118
|
+
/**
|
|
119
|
+
* Creation timestamp (Unix milliseconds)
|
|
120
|
+
*/
|
|
121
|
+
createdAt: number;
|
|
122
|
+
/**
|
|
123
|
+
* Last update timestamp (Unix milliseconds)
|
|
124
|
+
*/
|
|
125
|
+
updatedAt: number;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Workdir - Working Directory
|
|
130
|
+
*
|
|
131
|
+
* Represents an isolated working directory for an Agent.
|
|
132
|
+
* The actual path is determined by Runtime, not defined here.
|
|
133
|
+
*
|
|
134
|
+
* Workdir is a location declaration, not an operation interface.
|
|
135
|
+
* Claude SDK has its own tools (Bash, file operations), we just
|
|
136
|
+
* tell it where to work (cwd).
|
|
137
|
+
*/
|
|
138
|
+
interface Workdir {
|
|
139
|
+
/**
|
|
140
|
+
* Unique workdir identifier
|
|
141
|
+
*/
|
|
142
|
+
readonly id: string;
|
|
143
|
+
/**
|
|
144
|
+
* Human-readable workdir name
|
|
145
|
+
*/
|
|
146
|
+
readonly name: string;
|
|
147
|
+
/**
|
|
148
|
+
* Absolute path to working directory
|
|
149
|
+
*
|
|
150
|
+
* Examples:
|
|
151
|
+
* - NodeRuntime: ~/.agentx/workdirs/{id}/
|
|
152
|
+
* - CloudRuntime: /workdir/ (in container)
|
|
153
|
+
*/
|
|
154
|
+
readonly path: string;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Sandbox
|
|
159
|
+
*
|
|
160
|
+
* Pure resource isolation layer for an Agent.
|
|
161
|
+
* Isolates external tool resources: Workdir and MCP.
|
|
162
|
+
*
|
|
163
|
+
* Architecture:
|
|
164
|
+
* ```
|
|
165
|
+
* ┌─────────────────────────────────────────────────────────┐
|
|
166
|
+
* │ Container │
|
|
167
|
+
* │ ┌───────────────────────────────────────────────────┐ │
|
|
168
|
+
* │ │ Agent ──→ Sandbox (Workdir + MCP) │ │
|
|
169
|
+
* │ │ ──→ LLM (separate from Sandbox) │ │
|
|
170
|
+
* │ └───────────────────────────────────────────────────┘ │
|
|
171
|
+
* └─────────────────────────────────────────────────────────┘
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
174
|
+
* Note: LLM is at the same level as Sandbox, not inside it.
|
|
175
|
+
* Sandbox focuses on external tool isolation (workdir, MCP tools).
|
|
176
|
+
*/
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Sandbox - External tool resource isolation
|
|
180
|
+
*
|
|
181
|
+
* Isolates external tool resources for an Agent:
|
|
182
|
+
* - Workdir: Isolated working directory
|
|
183
|
+
* - MCP: Model Context Protocol tools (future)
|
|
184
|
+
*
|
|
185
|
+
* Note: LLM is NOT part of Sandbox - it's at container level.
|
|
186
|
+
*/
|
|
187
|
+
interface Sandbox {
|
|
188
|
+
/** Sandbox identifier */
|
|
189
|
+
readonly name: string;
|
|
190
|
+
/** Isolated working directory for file operations */
|
|
191
|
+
readonly workdir: Workdir;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
declare const SUPPORTED_PROTOCOL_VERSIONS: readonly ["2025-06-18", "2025-03-26", "2024-11-05"];
|
|
195
|
+
type McpProtocolVersion = (typeof SUPPORTED_PROTOCOL_VERSIONS)[number];
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* MCP Tool Types
|
|
199
|
+
*
|
|
200
|
+
* Tool definitions and execution results for Model Context Protocol.
|
|
201
|
+
*/
|
|
202
|
+
/**
|
|
203
|
+
* JSON Schema Definition
|
|
204
|
+
*
|
|
205
|
+
* Simplified JSON Schema for tool input parameters.
|
|
206
|
+
* Based on JSON Schema Draft 7.
|
|
207
|
+
*/
|
|
208
|
+
interface JsonSchema {
|
|
209
|
+
/** Schema type (always "object" for MCP tools) */
|
|
210
|
+
type: "object";
|
|
211
|
+
/** Property definitions */
|
|
212
|
+
properties?: Record<string, JsonSchemaProperty>;
|
|
213
|
+
/** Required property names */
|
|
214
|
+
required?: string[];
|
|
215
|
+
/** Additional properties allowed */
|
|
216
|
+
additionalProperties?: boolean;
|
|
217
|
+
/** Schema description */
|
|
218
|
+
description?: string;
|
|
219
|
+
}
|
|
220
|
+
interface JsonSchemaProperty {
|
|
221
|
+
type: "string" | "number" | "boolean" | "object" | "array" | "null";
|
|
222
|
+
description?: string;
|
|
223
|
+
enum?: unknown[];
|
|
224
|
+
items?: JsonSchemaProperty;
|
|
225
|
+
properties?: Record<string, JsonSchemaProperty>;
|
|
226
|
+
required?: string[];
|
|
227
|
+
default?: unknown;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Tool Definition
|
|
231
|
+
*
|
|
232
|
+
* Defines a tool that can be invoked by the LLM.
|
|
233
|
+
*/
|
|
234
|
+
interface McpTool {
|
|
235
|
+
/** Tool name (unique identifier) */
|
|
236
|
+
name: string;
|
|
237
|
+
/** Human-readable description of what the tool does */
|
|
238
|
+
description?: string;
|
|
239
|
+
/** JSON Schema for input parameters */
|
|
240
|
+
inputSchema: JsonSchema;
|
|
241
|
+
/** Optional annotations (e.g., UI hints) */
|
|
242
|
+
annotations?: {
|
|
243
|
+
/** Display title */
|
|
244
|
+
title?: string;
|
|
245
|
+
/** Additional metadata */
|
|
246
|
+
[key: string]: unknown;
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* MCP Resource Types
|
|
252
|
+
*
|
|
253
|
+
* Resource definitions for Model Context Protocol.
|
|
254
|
+
* Resources are static data sources (files, documents, etc.) that can be read by the LLM.
|
|
255
|
+
*/
|
|
256
|
+
/**
|
|
257
|
+
* Resource Definition
|
|
258
|
+
*
|
|
259
|
+
* Defines a resource that can be accessed by the LLM.
|
|
260
|
+
*/
|
|
261
|
+
interface McpResource {
|
|
262
|
+
/** Unique resource identifier (URI) */
|
|
263
|
+
uri: string;
|
|
264
|
+
/** Resource name */
|
|
265
|
+
name: string;
|
|
266
|
+
/** Optional human-readable title */
|
|
267
|
+
title?: string;
|
|
268
|
+
/** Optional description */
|
|
269
|
+
description?: string;
|
|
270
|
+
/** MIME type of the resource */
|
|
271
|
+
mimeType?: string;
|
|
272
|
+
/** Optional resource size in bytes */
|
|
273
|
+
size?: number;
|
|
274
|
+
/** Optional metadata */
|
|
275
|
+
annotations?: Record<string, unknown>;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* MCP Prompt Types
|
|
280
|
+
*
|
|
281
|
+
* Prompt templates for Model Context Protocol.
|
|
282
|
+
* Prompts are reusable message templates that can be parameterized.
|
|
283
|
+
*/
|
|
284
|
+
/**
|
|
285
|
+
* Prompt Argument
|
|
286
|
+
*
|
|
287
|
+
* Defines a parameter for a prompt template.
|
|
288
|
+
*/
|
|
289
|
+
interface McpPromptArgument {
|
|
290
|
+
/** Argument name */
|
|
291
|
+
name: string;
|
|
292
|
+
/** Optional description */
|
|
293
|
+
description?: string;
|
|
294
|
+
/** Whether this argument is required */
|
|
295
|
+
required?: boolean;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Prompt Definition
|
|
299
|
+
*
|
|
300
|
+
* Defines a reusable prompt template.
|
|
301
|
+
*/
|
|
302
|
+
interface McpPrompt {
|
|
303
|
+
/** Prompt name (unique identifier) */
|
|
304
|
+
name: string;
|
|
305
|
+
/** Optional display title */
|
|
306
|
+
title?: string;
|
|
307
|
+
/** Optional description */
|
|
308
|
+
description?: string;
|
|
309
|
+
/** Prompt arguments/parameters */
|
|
310
|
+
arguments?: McpPromptArgument[];
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Server Information
|
|
315
|
+
*
|
|
316
|
+
* Metadata about the MCP server.
|
|
317
|
+
*/
|
|
318
|
+
interface McpServerInfo {
|
|
319
|
+
/** Server name */
|
|
320
|
+
name: string;
|
|
321
|
+
/** Server version */
|
|
322
|
+
version: string;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* MCP Transport Types
|
|
327
|
+
*
|
|
328
|
+
* Transport layer configuration for Model Context Protocol.
|
|
329
|
+
* Defines how to connect to MCP servers via different protocols.
|
|
330
|
+
*/
|
|
331
|
+
/**
|
|
332
|
+
* Stdio Transport Configuration
|
|
333
|
+
*
|
|
334
|
+
* Connect to MCP server via standard input/output (spawned process).
|
|
335
|
+
* Common for local MCP servers.
|
|
336
|
+
*/
|
|
337
|
+
interface McpStdioTransport {
|
|
338
|
+
/** Transport type discriminator */
|
|
339
|
+
type: "stdio";
|
|
340
|
+
/** Command to execute */
|
|
341
|
+
command: string;
|
|
342
|
+
/** Command arguments */
|
|
343
|
+
args?: string[];
|
|
344
|
+
/** Environment variables */
|
|
345
|
+
env?: Record<string, string>;
|
|
346
|
+
/** Working directory */
|
|
347
|
+
cwd?: string;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* SSE Transport Configuration
|
|
351
|
+
*
|
|
352
|
+
* Connect to MCP server via Server-Sent Events.
|
|
353
|
+
* Common for remote MCP servers with streaming support.
|
|
354
|
+
*/
|
|
355
|
+
interface McpSseTransport {
|
|
356
|
+
/** Transport type discriminator */
|
|
357
|
+
type: "sse";
|
|
358
|
+
/** Server URL */
|
|
359
|
+
url: string;
|
|
360
|
+
/** HTTP headers */
|
|
361
|
+
headers?: Record<string, string>;
|
|
362
|
+
/** Request timeout in milliseconds */
|
|
363
|
+
timeout?: number;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* HTTP Transport Configuration
|
|
367
|
+
*
|
|
368
|
+
* Connect to MCP server via HTTP requests.
|
|
369
|
+
* Common for stateless remote MCP servers.
|
|
370
|
+
*/
|
|
371
|
+
interface McpHttpTransport {
|
|
372
|
+
/** Transport type discriminator */
|
|
373
|
+
type: "http";
|
|
374
|
+
/** Server URL */
|
|
375
|
+
url: string;
|
|
376
|
+
/** HTTP headers */
|
|
377
|
+
headers?: Record<string, string>;
|
|
378
|
+
/** Request timeout in milliseconds */
|
|
379
|
+
timeout?: number;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* SDK Transport Configuration
|
|
383
|
+
*
|
|
384
|
+
* Use an in-process MCP server instance.
|
|
385
|
+
* Common for embedded MCP servers in the same application.
|
|
386
|
+
*/
|
|
387
|
+
interface McpSdkTransport {
|
|
388
|
+
/** Transport type discriminator */
|
|
389
|
+
type: "sdk";
|
|
390
|
+
/** Server name */
|
|
391
|
+
name: string;
|
|
392
|
+
/** Server instance (implementation-specific) */
|
|
393
|
+
instance: unknown;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* MCP Transport Config
|
|
397
|
+
*
|
|
398
|
+
* Union of all transport configuration types.
|
|
399
|
+
*/
|
|
400
|
+
type McpTransportConfig = McpStdioTransport | McpSseTransport | McpHttpTransport | McpSdkTransport;
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* MCP Request Types
|
|
404
|
+
*
|
|
405
|
+
* Request/response types for JSON-RPC based MCP communication.
|
|
406
|
+
*/
|
|
407
|
+
/**
|
|
408
|
+
* Base Request Parameters
|
|
409
|
+
*
|
|
410
|
+
* Common parameters for all MCP requests.
|
|
411
|
+
*/
|
|
412
|
+
interface McpBaseParams {
|
|
413
|
+
/** Optional metadata */
|
|
414
|
+
_meta?: Record<string, unknown>;
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* MCP Request
|
|
418
|
+
*
|
|
419
|
+
* Generic request structure.
|
|
420
|
+
*/
|
|
421
|
+
interface McpRequest {
|
|
422
|
+
/** RPC method name */
|
|
423
|
+
method: string;
|
|
424
|
+
/** Request parameters */
|
|
425
|
+
params?: McpBaseParams;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* LLM - Large Language Model definition
|
|
430
|
+
*
|
|
431
|
+
* Defines the capabilities and metadata of a language model.
|
|
432
|
+
* Provider-agnostic design allows supporting multiple LLM vendors.
|
|
433
|
+
*/
|
|
434
|
+
interface LLM {
|
|
435
|
+
/**
|
|
436
|
+
* Provider name (e.g., "anthropic", "openai", "custom")
|
|
437
|
+
*/
|
|
438
|
+
provider: string;
|
|
439
|
+
/**
|
|
440
|
+
* Provider-specific model identifier
|
|
441
|
+
* Examples: "claude-3-5-sonnet-20241022", "gpt-4-turbo"
|
|
442
|
+
*/
|
|
443
|
+
modelId: string;
|
|
444
|
+
/**
|
|
445
|
+
* Whether the model supports streaming output
|
|
446
|
+
*/
|
|
447
|
+
supportsStreaming: boolean;
|
|
448
|
+
/**
|
|
449
|
+
* Whether the model supports tool calling
|
|
450
|
+
*/
|
|
451
|
+
supportsTools: boolean;
|
|
452
|
+
/**
|
|
453
|
+
* Whether the model supports vision/image inputs
|
|
454
|
+
*/
|
|
455
|
+
supportsVision: boolean;
|
|
456
|
+
/**
|
|
457
|
+
* Whether the model supports prompt caching
|
|
458
|
+
*/
|
|
459
|
+
supportsCaching: boolean;
|
|
460
|
+
/**
|
|
461
|
+
* Whether the model supports extended thinking
|
|
462
|
+
*/
|
|
463
|
+
supportsThinking?: boolean;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* LLM inference configuration
|
|
468
|
+
*
|
|
469
|
+
* Parameters that control how the language model generates responses.
|
|
470
|
+
* These are the standard parameters supported by most LLM providers.
|
|
471
|
+
*/
|
|
472
|
+
interface LLMConfig {
|
|
473
|
+
/**
|
|
474
|
+
* Model identifier to use for inference
|
|
475
|
+
* Examples: "claude-3-5-sonnet-20241022", "gpt-4-turbo"
|
|
476
|
+
*/
|
|
477
|
+
model: string;
|
|
478
|
+
/**
|
|
479
|
+
* Sampling temperature (0-2)
|
|
480
|
+
* Higher values make output more random, lower values more deterministic
|
|
481
|
+
* @default 1.0
|
|
482
|
+
*/
|
|
483
|
+
temperature?: number;
|
|
484
|
+
/**
|
|
485
|
+
* Maximum number of tokens to generate
|
|
486
|
+
*/
|
|
487
|
+
maxTokens?: number;
|
|
488
|
+
/**
|
|
489
|
+
* Top-p sampling (nucleus sampling)
|
|
490
|
+
* Range: 0-1
|
|
491
|
+
*/
|
|
492
|
+
topP?: number;
|
|
493
|
+
/**
|
|
494
|
+
* Top-k sampling
|
|
495
|
+
* Only consider the top k tokens
|
|
496
|
+
*/
|
|
497
|
+
topK?: number;
|
|
498
|
+
/**
|
|
499
|
+
* Presence penalty (-2.0 to 2.0)
|
|
500
|
+
* Penalize tokens that have already appeared
|
|
501
|
+
*/
|
|
502
|
+
presencePenalty?: number;
|
|
503
|
+
/**
|
|
504
|
+
* Frequency penalty (-2.0 to 2.0)
|
|
505
|
+
* Penalize tokens based on their frequency
|
|
506
|
+
*/
|
|
507
|
+
frequencyPenalty?: number;
|
|
508
|
+
/**
|
|
509
|
+
* Stop sequences
|
|
510
|
+
* Generation stops when any of these sequences is encountered
|
|
511
|
+
*/
|
|
512
|
+
stopSequences?: string[];
|
|
513
|
+
/**
|
|
514
|
+
* Maximum number of thinking tokens (for models with extended thinking)
|
|
515
|
+
*/
|
|
516
|
+
maxThinkingTokens?: number;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Complete LLM inference request (stateless)
|
|
521
|
+
*
|
|
522
|
+
* Contains everything needed for a single LLM inference call.
|
|
523
|
+
* The LLM is stateless - all context must be provided in messages.
|
|
524
|
+
*
|
|
525
|
+
* IMPORTANT: This does NOT include tool definitions.
|
|
526
|
+
* Tools are external capabilities provided by the runtime environment.
|
|
527
|
+
*/
|
|
528
|
+
interface LLMRequest {
|
|
529
|
+
/**
|
|
530
|
+
* Context messages
|
|
531
|
+
* All conversation history that the LLM should consider
|
|
532
|
+
*/
|
|
533
|
+
messages: Message[];
|
|
534
|
+
/**
|
|
535
|
+
* Inference configuration
|
|
536
|
+
* Controls how the model generates responses
|
|
537
|
+
*/
|
|
538
|
+
config: LLMConfig;
|
|
539
|
+
/**
|
|
540
|
+
* System prompt (optional)
|
|
541
|
+
* High-level instructions that guide the model's behavior
|
|
542
|
+
*/
|
|
543
|
+
systemPrompt?: string;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Token Usage
|
|
548
|
+
*
|
|
549
|
+
* Tracks token consumption for AI messages.
|
|
550
|
+
*/
|
|
551
|
+
interface TokenUsage {
|
|
552
|
+
/** Input tokens used */
|
|
553
|
+
input: number;
|
|
554
|
+
/** Output tokens generated */
|
|
555
|
+
output: number;
|
|
556
|
+
/** Tokens read from cache (optional) */
|
|
557
|
+
cacheRead?: number;
|
|
558
|
+
/** Tokens written to cache (optional) */
|
|
559
|
+
cacheWrite?: number;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Complete LLM inference response (stateless)
|
|
564
|
+
*
|
|
565
|
+
* Contains everything returned from a single LLM inference call.
|
|
566
|
+
* Given the same LLMRequest (with temperature=0), the response should be reproducible.
|
|
567
|
+
*/
|
|
568
|
+
interface LLMResponse {
|
|
569
|
+
/**
|
|
570
|
+
* Generated content
|
|
571
|
+
* Can be text, thinking, tool calls, etc.
|
|
572
|
+
*/
|
|
573
|
+
content: string | ContentPart[];
|
|
574
|
+
/**
|
|
575
|
+
* Why the model stopped generating
|
|
576
|
+
*/
|
|
577
|
+
stopReason: StopReason;
|
|
578
|
+
/**
|
|
579
|
+
* Token usage statistics
|
|
580
|
+
*/
|
|
581
|
+
usage: TokenUsage;
|
|
582
|
+
/**
|
|
583
|
+
* When the generation finished
|
|
584
|
+
*/
|
|
585
|
+
finishTime: Date;
|
|
586
|
+
/**
|
|
587
|
+
* Model that generated this response
|
|
588
|
+
*/
|
|
589
|
+
model?: string;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Streaming output chunk types
|
|
594
|
+
*
|
|
595
|
+
* When LLM generates responses in streaming mode, it emits chunks of different types.
|
|
596
|
+
* This allows real-time display of the generation process.
|
|
597
|
+
*/
|
|
598
|
+
/**
|
|
599
|
+
* Text content chunk
|
|
600
|
+
*/
|
|
601
|
+
interface TextChunk {
|
|
602
|
+
type: "text";
|
|
603
|
+
/**
|
|
604
|
+
* Text delta (incremental content)
|
|
605
|
+
*/
|
|
606
|
+
delta: string;
|
|
607
|
+
/**
|
|
608
|
+
* Cumulative index of this chunk
|
|
609
|
+
*/
|
|
610
|
+
index: number;
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Thinking process chunk (for models with extended thinking)
|
|
614
|
+
*/
|
|
615
|
+
interface ThinkingChunk {
|
|
616
|
+
type: "thinking";
|
|
617
|
+
/**
|
|
618
|
+
* Thinking delta (incremental reasoning)
|
|
619
|
+
*/
|
|
620
|
+
delta: string;
|
|
621
|
+
/**
|
|
622
|
+
* Cumulative index of this chunk
|
|
623
|
+
*/
|
|
624
|
+
index: number;
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Tool use chunk (when model requests tool usage)
|
|
628
|
+
*/
|
|
629
|
+
interface ToolUseChunk {
|
|
630
|
+
type: "tool-use";
|
|
631
|
+
/**
|
|
632
|
+
* Tool name
|
|
633
|
+
*/
|
|
634
|
+
name: string;
|
|
635
|
+
/**
|
|
636
|
+
* Tool call ID
|
|
637
|
+
*/
|
|
638
|
+
id: string;
|
|
639
|
+
/**
|
|
640
|
+
* Partial input (may be incomplete JSON)
|
|
641
|
+
*/
|
|
642
|
+
inputDelta?: string;
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Union type of all streaming chunks
|
|
646
|
+
*/
|
|
647
|
+
type StreamChunk = TextChunk | ThinkingChunk | ToolUseChunk;
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* LLMProvider - Large Language Model Supply Service
|
|
651
|
+
*
|
|
652
|
+
* Provides LLM invocation capabilities to Drivers.
|
|
653
|
+
* This is a resource component managed by Runtime.
|
|
654
|
+
*
|
|
655
|
+
* ## Architecture Decision Record (ADR)
|
|
656
|
+
*
|
|
657
|
+
* ### Context
|
|
658
|
+
*
|
|
659
|
+
* AgentX separates "business components" from "resource components":
|
|
660
|
+
*
|
|
661
|
+
* - **Business Components**: Agent-specific logic (Driver, Presenter, Middleware)
|
|
662
|
+
* - **Resource Components**: Infrastructure capabilities (LLM, FileSystem, Process)
|
|
663
|
+
*
|
|
664
|
+
* LLM access (apiKey, baseUrl, model) is a resource that:
|
|
665
|
+
* 1. Should not be exposed to Agent business code
|
|
666
|
+
* 2. Can be shared across multiple Agents
|
|
667
|
+
* 3. May have different supply strategies (static, pooled, proxy)
|
|
668
|
+
* 4. Needs unified management (quota, billing, load balancing)
|
|
669
|
+
*
|
|
670
|
+
* ### Decision
|
|
671
|
+
*
|
|
672
|
+
* Create `LLMProvider` as a minimal generic interface:
|
|
673
|
+
*
|
|
674
|
+
* ```typescript
|
|
675
|
+
* interface LLMProvider<TSupply = unknown> {
|
|
676
|
+
* readonly name: string;
|
|
677
|
+
* provide(): TSupply;
|
|
678
|
+
* }
|
|
679
|
+
* ```
|
|
680
|
+
*
|
|
681
|
+
* - `name`: Provider identifier (for logging, debugging)
|
|
682
|
+
* - `provide()`: Returns whatever the Driver needs
|
|
683
|
+
* - `TSupply`: User-defined, can be anything (config, client, token, etc.)
|
|
684
|
+
*
|
|
685
|
+
* ### Usage
|
|
686
|
+
*
|
|
687
|
+
* ```typescript
|
|
688
|
+
* // User defines their own supply type
|
|
689
|
+
* interface MyLLMSupply {
|
|
690
|
+
* apiKey: string;
|
|
691
|
+
* baseUrl?: string;
|
|
692
|
+
* }
|
|
693
|
+
*
|
|
694
|
+
* // Create provider
|
|
695
|
+
* const provider: LLMProvider<MyLLMSupply> = {
|
|
696
|
+
* name: "claude",
|
|
697
|
+
* provide: () => ({
|
|
698
|
+
* apiKey: process.env.ANTHROPIC_API_KEY!,
|
|
699
|
+
* }),
|
|
700
|
+
* };
|
|
701
|
+
*
|
|
702
|
+
* // Driver uses it
|
|
703
|
+
* const supply = runtime.llm.provide();
|
|
704
|
+
* ```
|
|
705
|
+
*
|
|
706
|
+
* ### Status
|
|
707
|
+
*
|
|
708
|
+
* **Accepted** - 2024-11-30
|
|
709
|
+
*/
|
|
710
|
+
/**
|
|
711
|
+
* LLMProvider - Large Language Model supply service
|
|
712
|
+
*
|
|
713
|
+
* @typeParam TSupply - User-defined supply type (config, client, token, etc.)
|
|
714
|
+
*/
|
|
715
|
+
interface LLMProvider<TSupply = unknown> {
|
|
716
|
+
/**
|
|
717
|
+
* Provider identifier
|
|
718
|
+
*/
|
|
719
|
+
readonly name: string;
|
|
720
|
+
/**
|
|
721
|
+
* Provide LLM access
|
|
722
|
+
*/
|
|
723
|
+
provide(): TSupply;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* Receptor - Perceives the external world and emits to SystemBus
|
|
728
|
+
*
|
|
729
|
+
* From systems theory:
|
|
730
|
+
* - A receptor is a sensory component that detects stimuli from outside
|
|
731
|
+
* - It transforms external signals into events the system can process
|
|
732
|
+
*
|
|
733
|
+
* In our architecture:
|
|
734
|
+
* - Receptor perceives external world (LLM API, Network, etc.)
|
|
735
|
+
* - Emits events to SystemBus
|
|
736
|
+
*
|
|
737
|
+
* ```
|
|
738
|
+
* External World
|
|
739
|
+
* │
|
|
740
|
+
* │ perceive
|
|
741
|
+
* ▼
|
|
742
|
+
* Receptor
|
|
743
|
+
* │
|
|
744
|
+
* │ emit
|
|
745
|
+
* ▼
|
|
746
|
+
* SystemBus
|
|
747
|
+
* ```
|
|
748
|
+
*
|
|
749
|
+
* @see issues/030-ecosystem-architecture.md
|
|
750
|
+
*/
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* Receptor - Perceives external world and emits events to SystemBus
|
|
754
|
+
*/
|
|
755
|
+
interface Receptor {
|
|
756
|
+
/**
|
|
757
|
+
* Connect to SystemBus producer to emit events
|
|
758
|
+
*
|
|
759
|
+
* Receptor only needs Producer (write-only) because it only emits events.
|
|
760
|
+
*/
|
|
761
|
+
connect(producer: SystemBusProducer): void;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* Effector - Listens to SystemBus and acts upon external world
|
|
766
|
+
*
|
|
767
|
+
* From systems theory:
|
|
768
|
+
* - An effector is a component that produces an effect on the environment
|
|
769
|
+
* - It transforms internal signals into external actions
|
|
770
|
+
*
|
|
771
|
+
* In our architecture:
|
|
772
|
+
* - Effector subscribes to SystemBus
|
|
773
|
+
* - Sends commands/events to external world (LLM API, Network, other systems)
|
|
774
|
+
*
|
|
775
|
+
* ```
|
|
776
|
+
* SystemBus
|
|
777
|
+
* │
|
|
778
|
+
* │ subscribe
|
|
779
|
+
* ▼
|
|
780
|
+
* Effector
|
|
781
|
+
* │
|
|
782
|
+
* │ send
|
|
783
|
+
* ▼
|
|
784
|
+
* External World
|
|
785
|
+
* ```
|
|
786
|
+
*
|
|
787
|
+
* @see issues/030-ecosystem-architecture.md
|
|
788
|
+
*/
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* Effector - Subscribes to SystemBus and acts upon external world
|
|
792
|
+
*/
|
|
793
|
+
interface Effector {
|
|
794
|
+
/**
|
|
795
|
+
* Connect to SystemBus consumer to subscribe to events
|
|
796
|
+
*
|
|
797
|
+
* Effector only needs Consumer (read-only) because it only subscribes to events.
|
|
798
|
+
*/
|
|
799
|
+
connect(consumer: SystemBusConsumer): void;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* Environment - External world interface (Receptor + Effector)
|
|
804
|
+
*
|
|
805
|
+
* From systems theory:
|
|
806
|
+
* - Environment is everything outside the system boundary
|
|
807
|
+
* - Receptor perceives the environment (input)
|
|
808
|
+
* - Effector acts upon the environment (output)
|
|
809
|
+
*
|
|
810
|
+
* Environment combines both:
|
|
811
|
+
* - Perceives external world (Claude API, Network) → emits to SystemBus
|
|
812
|
+
* - Receives from SystemBus → sends to external world
|
|
813
|
+
*
|
|
814
|
+
* ```
|
|
815
|
+
* SystemBus
|
|
816
|
+
* ▲ │
|
|
817
|
+
* emit │ │ subscribe
|
|
818
|
+
* │ ▼
|
|
819
|
+
* ┌─────┴───────────┐
|
|
820
|
+
* │ Environment │
|
|
821
|
+
* │ │
|
|
822
|
+
* │ ┌───────────┐ │
|
|
823
|
+
* │ │ Receptor │──┼──► emit to bus
|
|
824
|
+
* │ └───────────┘ │
|
|
825
|
+
* │ │
|
|
826
|
+
* │ External World │
|
|
827
|
+
* │ (Claude SDK) │
|
|
828
|
+
* │ │
|
|
829
|
+
* │ ┌───────────┐ │
|
|
830
|
+
* │ │ Effector │◄─┼── subscribe from bus
|
|
831
|
+
* │ └───────────┘ │
|
|
832
|
+
* └─────────────────┘
|
|
833
|
+
* ```
|
|
834
|
+
*
|
|
835
|
+
* Implementations:
|
|
836
|
+
* - ClaudeEnvironment: Claude SDK (Node.js)
|
|
837
|
+
* - RemoteEnvironment: Network SSE/WebSocket (Browser)
|
|
838
|
+
*
|
|
839
|
+
* @see issues/030-ecosystem-architecture.md
|
|
840
|
+
*/
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Environment - External world interface
|
|
844
|
+
*/
|
|
845
|
+
interface Environment {
|
|
846
|
+
/**
|
|
847
|
+
* Environment name
|
|
848
|
+
*/
|
|
849
|
+
readonly name: string;
|
|
850
|
+
/**
|
|
851
|
+
* Receptor - perceives external world, emits to SystemBus
|
|
852
|
+
*/
|
|
853
|
+
readonly receptor: Receptor;
|
|
854
|
+
/**
|
|
855
|
+
* Effector - subscribes to SystemBus, acts on external world
|
|
856
|
+
*/
|
|
857
|
+
readonly effector: Effector;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
/**
|
|
861
|
+
* Session - Message collector and storage
|
|
862
|
+
*
|
|
863
|
+
* Session is responsible for:
|
|
864
|
+
* - Listening to messages from Agent/Bus
|
|
865
|
+
* - Persisting messages to storage
|
|
866
|
+
*
|
|
867
|
+
* Session is created per Image and stores the conversation history.
|
|
868
|
+
* In the Image-First model, Session persists across Agent restarts.
|
|
869
|
+
*/
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* Session - Collects and stores messages
|
|
873
|
+
*/
|
|
874
|
+
interface Session {
|
|
875
|
+
/**
|
|
876
|
+
* Unique session identifier
|
|
877
|
+
*/
|
|
878
|
+
readonly sessionId: string;
|
|
879
|
+
/**
|
|
880
|
+
* Associated image ID (persistent conversation entity)
|
|
881
|
+
*/
|
|
882
|
+
readonly imageId: string;
|
|
883
|
+
/**
|
|
884
|
+
* Associated container ID
|
|
885
|
+
*/
|
|
886
|
+
readonly containerId: string;
|
|
887
|
+
/**
|
|
888
|
+
* Session creation timestamp (Unix ms)
|
|
889
|
+
*/
|
|
890
|
+
readonly createdAt: number;
|
|
891
|
+
/**
|
|
892
|
+
* Add a message to the session
|
|
893
|
+
*/
|
|
894
|
+
addMessage(message: Message): Promise<void>;
|
|
895
|
+
/**
|
|
896
|
+
* Get all messages
|
|
897
|
+
*/
|
|
898
|
+
getMessages(): Promise<Message[]>;
|
|
899
|
+
/**
|
|
900
|
+
* Clear all messages
|
|
901
|
+
*/
|
|
902
|
+
clear(): Promise<void>;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* EventHandler - Event handler related types
|
|
907
|
+
*
|
|
908
|
+
* Types for the event handler system.
|
|
909
|
+
*/
|
|
910
|
+
|
|
911
|
+
/**
|
|
912
|
+
* Error context for error handling
|
|
913
|
+
*
|
|
914
|
+
* Provides context information when handling errors in event handlers.
|
|
915
|
+
*/
|
|
916
|
+
interface ErrorContext {
|
|
917
|
+
/**
|
|
918
|
+
* Event source that triggered the error
|
|
919
|
+
*/
|
|
920
|
+
source?: EventSource;
|
|
921
|
+
/**
|
|
922
|
+
* Request ID (if error is related to a request)
|
|
923
|
+
*/
|
|
924
|
+
requestId?: string;
|
|
925
|
+
/**
|
|
926
|
+
* Error severity
|
|
927
|
+
*/
|
|
928
|
+
severity?: "info" | "warn" | "error" | "fatal";
|
|
929
|
+
/**
|
|
930
|
+
* Operation name (for logging and debugging)
|
|
931
|
+
*/
|
|
932
|
+
operation?: string;
|
|
933
|
+
/**
|
|
934
|
+
* Additional error details
|
|
935
|
+
*/
|
|
936
|
+
details?: Record<string, unknown>;
|
|
937
|
+
/**
|
|
938
|
+
* Optional callback to handle error (e.g., emit error response)
|
|
939
|
+
*/
|
|
940
|
+
onError?: (err: unknown) => void;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
export { ContainerRepository, type Effector, type Environment, type EnvironmentRecord, type ErrorContext, ImageRepository, type LLM, type LLMConfig, type LLMProvider, type LLMRequest, type LLMResponse, type McpPrompt, type McpProtocolVersion, type McpRequest, type McpResource, type McpServerInfo, type McpTool, type McpTransportConfig, type MessageRecord, type Receptor, type Repository, type Sandbox, type Session, SessionRepository, StopReason, type StreamChunk, SystemBusConsumer, SystemBusProducer, type TokenUsage, type Workdir };
|