@agentxjs/types 0.0.6 → 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.
Files changed (86) hide show
  1. package/dist/Agent-BXUYGlWZ.d.cts +510 -0
  2. package/dist/Agent-CaSxMF_E.d.ts +510 -0
  3. package/dist/CommandEvent-CbXzPolX.d.ts +495 -0
  4. package/dist/CommandEvent-DCdk7lzX.d.cts +495 -0
  5. package/dist/Container-DR-1g44i.d.ts +641 -0
  6. package/dist/Container-dBDOcjhk.d.cts +641 -0
  7. package/dist/ContentPart-CqOh-rI1.d.ts +19 -0
  8. package/dist/ContentPart-DEFnYXCU.d.cts +19 -0
  9. package/dist/DriveableEvent-Bj7nn-Uk.d.ts +161 -0
  10. package/dist/DriveableEvent-CCMC1h_C.d.cts +161 -0
  11. package/dist/ErrorMessage-BoIh3MIO.d.cts +24 -0
  12. package/dist/ErrorMessage-BoIh3MIO.d.ts +24 -0
  13. package/dist/ImageRecord-Cn0VcJWk.d.cts +71 -0
  14. package/dist/ImageRecord-Cn0VcJWk.d.ts +71 -0
  15. package/dist/LoggerFactory-DZtw0M7U.d.cts +129 -0
  16. package/dist/LoggerFactory-DZtw0M7U.d.ts +129 -0
  17. package/dist/Message-Crh81uLL.d.cts +45 -0
  18. package/dist/Message-DWQUt647.d.ts +45 -0
  19. package/dist/Persistence-BQkdKomV.d.ts +230 -0
  20. package/dist/Persistence-Dr70FEBh.d.cts +230 -0
  21. package/dist/StopReason-D4DthB1h.d.cts +39 -0
  22. package/dist/StopReason-D4DthB1h.d.ts +39 -0
  23. package/dist/SystemEvent-CPvvxdMQ.d.cts +159 -0
  24. package/dist/SystemEvent-CPvvxdMQ.d.ts +159 -0
  25. package/dist/ToolResultMessage-CDG2L7Zv.d.ts +332 -0
  26. package/dist/ToolResultMessage-CRKMSf5d.d.cts +332 -0
  27. package/dist/agent-internal.cjs +19 -0
  28. package/dist/agent-internal.cjs.map +1 -0
  29. package/dist/agent-internal.d.cts +52 -0
  30. package/dist/agent-internal.d.ts +52 -0
  31. package/dist/agent-internal.js +1 -0
  32. package/dist/agent-internal.js.map +1 -0
  33. package/dist/agent.cjs +70 -0
  34. package/dist/agent.cjs.map +1 -0
  35. package/dist/agent.d.cts +229 -0
  36. package/dist/agent.d.ts +229 -0
  37. package/dist/agent.js +41 -0
  38. package/dist/agent.js.map +1 -0
  39. package/dist/agentx.cjs +38 -0
  40. package/dist/agentx.cjs.map +1 -0
  41. package/dist/agentx.d.cts +311 -0
  42. package/dist/agentx.d.ts +311 -0
  43. package/dist/agentx.js +12 -0
  44. package/dist/agentx.js.map +1 -0
  45. package/dist/chunk-2QHAIM3V.js +1 -0
  46. package/dist/chunk-2QHAIM3V.js.map +1 -0
  47. package/dist/common.cjs +19 -0
  48. package/dist/common.cjs.map +1 -0
  49. package/dist/common.d.cts +43 -0
  50. package/dist/common.d.ts +43 -0
  51. package/dist/common.js +2 -0
  52. package/dist/common.js.map +1 -0
  53. package/dist/event.cjs +184 -0
  54. package/dist/event.cjs.map +1 -0
  55. package/dist/event.d.cts +769 -0
  56. package/dist/event.d.ts +769 -0
  57. package/dist/event.js +134 -0
  58. package/dist/event.js.map +1 -0
  59. package/dist/index-CjFNcCxR.d.cts +299 -0
  60. package/dist/index-usKuk41S.d.ts +299 -0
  61. package/dist/index.cjs +2 -185
  62. package/dist/index.cjs.map +1 -1
  63. package/dist/index.d.cts +8 -5267
  64. package/dist/index.d.ts +8 -5267
  65. package/dist/index.js +1 -150
  66. package/dist/index.js.map +1 -1
  67. package/dist/network.cjs +19 -0
  68. package/dist/network.cjs.map +1 -0
  69. package/dist/network.d.cts +168 -0
  70. package/dist/network.d.ts +168 -0
  71. package/dist/network.js +1 -0
  72. package/dist/network.js.map +1 -0
  73. package/dist/runtime-internal.cjs +19 -0
  74. package/dist/runtime-internal.cjs.map +1 -0
  75. package/dist/runtime-internal.d.cts +943 -0
  76. package/dist/runtime-internal.d.ts +943 -0
  77. package/dist/runtime-internal.js +1 -0
  78. package/dist/runtime-internal.js.map +1 -0
  79. package/dist/runtime.cjs +19 -0
  80. package/dist/runtime.cjs.map +1 -0
  81. package/dist/runtime.d.cts +217 -0
  82. package/dist/runtime.d.ts +217 -0
  83. package/dist/runtime.js +1 -0
  84. package/dist/runtime.js.map +1 -0
  85. package/package.json +82 -10
  86. package/LICENSE +0 -21
@@ -0,0 +1,311 @@
1
+ import { S as SystemEvent } from './SystemEvent-CPvvxdMQ.cjs';
2
+ import { C as CommandRequestType, R as RequestDataFor, a as ResponseEventFor, b as CommandEventMap } from './CommandEvent-DCdk7lzX.cjs';
3
+ import { L as LogLevel, c as LoggerFactory } from './LoggerFactory-DZtw0M7U.cjs';
4
+ import './ImageRecord-Cn0VcJWk.cjs';
5
+
6
+ /**
7
+ * AgentX - Unified High-Level API for AI Agents
8
+ *
9
+ * AgentX provides a simple, consistent API for both local and remote modes.
10
+ * It wraps Runtime and provides the same interface regardless of deployment.
11
+ *
12
+ * ## Two Modes
13
+ *
14
+ * ```
15
+ * Local Mode Remote Mode
16
+ * ─────────────────────────────────────────────────────────
17
+ * AgentX AgentX
18
+ * │ │
19
+ * └── Runtime (embedded) └── WebSocket ──→ Server
20
+ * │ │
21
+ * └── LLM, Storage └── Runtime
22
+ * ```
23
+ *
24
+ * ## API Design
25
+ *
26
+ * All operations use CommandEvent pattern:
27
+ * - `request(type, data)` - Send request, wait for response
28
+ * - `on(type, handler)` - Subscribe to events
29
+ * - `onCommand(type, handler)` - Type-safe command subscription
30
+ *
31
+ * ## Usage
32
+ *
33
+ * ```typescript
34
+ * // Local mode (default)
35
+ * const agentx = await createAgentX();
36
+ *
37
+ * // Local mode with custom LLM and storage
38
+ * const agentx = await createAgentX({
39
+ * llm: { apiKey: "sk-...", model: "claude-opus-4-20250514" },
40
+ * storage: { driver: "postgresql", url: "postgres://..." },
41
+ * });
42
+ *
43
+ * // Remote mode
44
+ * const agentx = await createAgentX({ server: "ws://localhost:5200" });
45
+ *
46
+ * // Same API for both modes!
47
+ * const res = await agentx.request("container_create_request", {
48
+ * containerId: "my-container"
49
+ * });
50
+ *
51
+ * agentx.on("text_delta", (e) => console.log(e.data.text));
52
+ *
53
+ * await agentx.dispose();
54
+ * ```
55
+ *
56
+ * @packageDocumentation
57
+ */
58
+
59
+ /**
60
+ * LLM configuration
61
+ */
62
+ interface LLMConfig {
63
+ /**
64
+ * Anthropic API key (required)
65
+ */
66
+ apiKey: string;
67
+ /**
68
+ * API base URL
69
+ * @default "https://api.anthropic.com"
70
+ */
71
+ baseUrl?: string;
72
+ /**
73
+ * Model name
74
+ * @default "claude-sonnet-4-20250514"
75
+ */
76
+ model?: string;
77
+ }
78
+ /**
79
+ * Storage driver type
80
+ */
81
+ type StorageDriver = "memory" | "fs" | "redis" | "mongodb" | "sqlite" | "mysql" | "postgresql";
82
+ /**
83
+ * Storage configuration
84
+ */
85
+ interface StorageConfig {
86
+ /**
87
+ * Storage driver
88
+ * @default "memory"
89
+ */
90
+ driver?: StorageDriver;
91
+ /**
92
+ * File path (for sqlite, fs drivers)
93
+ * @example "./data.db" for sqlite
94
+ * @example "./data" for fs
95
+ */
96
+ path?: string;
97
+ /**
98
+ * Connection URL (for redis, mongodb, mysql, postgresql)
99
+ * @example "redis://localhost:6379"
100
+ * @example "mongodb://localhost:27017/agentx"
101
+ * @example "mysql://user:pass@localhost:3306/agentx"
102
+ * @example "postgres://user:pass@localhost:5432/agentx"
103
+ */
104
+ url?: string;
105
+ }
106
+ /**
107
+ * Logger configuration
108
+ */
109
+ interface LoggerConfig {
110
+ /**
111
+ * Log level
112
+ * @default LogLevel.INFO
113
+ */
114
+ level?: LogLevel;
115
+ /**
116
+ * Custom logger factory implementation
117
+ * If provided, this factory will be used to create all logger instances.
118
+ * If not provided, uses ConsoleLogger with console options.
119
+ */
120
+ factory?: LoggerFactory;
121
+ /**
122
+ * Console logger options (only used when factory is not provided)
123
+ */
124
+ console?: {
125
+ /**
126
+ * Enable colored output
127
+ * @default true (Node.js), false (browser)
128
+ */
129
+ colors?: boolean;
130
+ /**
131
+ * Include timestamps in log output
132
+ * @default true
133
+ */
134
+ timestamps?: boolean;
135
+ };
136
+ }
137
+ /**
138
+ * Local mode configuration
139
+ *
140
+ * Runs AgentX with local runtime, connecting directly to LLM API.
141
+ */
142
+ interface LocalConfig {
143
+ /**
144
+ * LLM configuration
145
+ */
146
+ llm?: LLMConfig;
147
+ /**
148
+ * Logger configuration
149
+ */
150
+ logger?: LoggerConfig;
151
+ /**
152
+ * AgentX base directory for runtime data (containers, workdirs, storage, logs)
153
+ * @default "~/.agentx" (user's home directory)
154
+ * @example "/var/lib/agentx"
155
+ * @example "/Users/john/.agentx"
156
+ *
157
+ * Directory structure:
158
+ * - {agentxDir}/data/agentx.db - SQLite database (auto-configured)
159
+ * - {agentxDir}/logs/ - Log files (if configured)
160
+ * - {agentxDir}/containers/ - Agent workdirs
161
+ */
162
+ agentxDir?: string;
163
+ /**
164
+ * HTTP server to attach WebSocket to.
165
+ * If provided, WebSocket upgrade will be handled on the same port.
166
+ * The server should handle authentication before upgrading.
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * import { createServer } from "http";
171
+ * import { Hono } from "hono";
172
+ *
173
+ * const app = new Hono();
174
+ * // ... add auth middleware
175
+ *
176
+ * const server = createServer(app.fetch);
177
+ * const agentx = await createAgentX({ server });
178
+ *
179
+ * server.listen(5200);
180
+ * ```
181
+ */
182
+ server?: {
183
+ on(event: "upgrade", listener: (request: {
184
+ url?: string;
185
+ headers: {
186
+ host?: string;
187
+ };
188
+ }, socket: unknown, head: unknown) => void): void;
189
+ };
190
+ }
191
+ /**
192
+ * Remote mode configuration
193
+ *
194
+ * Connects to a remote AgentX server via WebSocket.
195
+ */
196
+ interface RemoteConfig {
197
+ /**
198
+ * Remote server URL (WebSocket)
199
+ * @example "ws://localhost:5200"
200
+ */
201
+ serverUrl: string;
202
+ }
203
+ /**
204
+ * AgentX configuration
205
+ *
206
+ * - LocalConfig: Run with local runtime (default)
207
+ * - RemoteConfig: Connect to remote server
208
+ */
209
+ type AgentXConfig = LocalConfig | RemoteConfig;
210
+ /**
211
+ * Type guard: is this a remote config?
212
+ */
213
+ declare function isRemoteConfig(config: AgentXConfig): config is RemoteConfig;
214
+ /**
215
+ * Type guard: is this a local config?
216
+ */
217
+ declare function isLocalConfig(config: AgentXConfig): config is LocalConfig;
218
+ /**
219
+ * Unsubscribe function
220
+ */
221
+ type Unsubscribe = () => void;
222
+ /**
223
+ * AgentX - Main API interface
224
+ *
225
+ * Unified API for both local and remote modes.
226
+ */
227
+ interface AgentX {
228
+ /**
229
+ * Send a command request and wait for response.
230
+ *
231
+ * @example
232
+ * ```typescript
233
+ * const res = await agentx.request("container_create_request", {
234
+ * containerId: "my-container"
235
+ * });
236
+ * console.log(res.data.containerId);
237
+ * ```
238
+ */
239
+ request<T extends CommandRequestType>(type: T, data: RequestDataFor<T>, timeout?: number): Promise<ResponseEventFor<T>>;
240
+ /**
241
+ * Subscribe to events.
242
+ *
243
+ * @example
244
+ * ```typescript
245
+ * agentx.on("text_delta", (e) => {
246
+ * process.stdout.write(e.data.text);
247
+ * });
248
+ * ```
249
+ */
250
+ on<T extends string>(type: T, handler: (event: SystemEvent & {
251
+ type: T;
252
+ }) => void): Unsubscribe;
253
+ /**
254
+ * Subscribe to command events with full type safety.
255
+ *
256
+ * @example
257
+ * ```typescript
258
+ * agentx.onCommand("container_create_response", (e) => {
259
+ * console.log(e.data.containerId);
260
+ * });
261
+ * ```
262
+ */
263
+ onCommand<T extends keyof CommandEventMap>(type: T, handler: (event: CommandEventMap[T]) => void): Unsubscribe;
264
+ /**
265
+ * Emit a command event.
266
+ *
267
+ * For fine-grained control. Usually prefer `request()`.
268
+ */
269
+ emitCommand<T extends keyof CommandEventMap>(type: T, data: CommandEventMap[T]["data"]): void;
270
+ /**
271
+ * Start listening for remote connections.
272
+ *
273
+ * Only available in local mode.
274
+ *
275
+ * @example
276
+ * ```typescript
277
+ * await agentx.listen(5200);
278
+ * console.log("Server running on ws://localhost:5200");
279
+ * ```
280
+ */
281
+ listen(port: number, host?: string): Promise<void>;
282
+ /**
283
+ * Stop listening for remote connections.
284
+ */
285
+ close(): Promise<void>;
286
+ /**
287
+ * Dispose AgentX and release all resources.
288
+ */
289
+ dispose(): Promise<void>;
290
+ }
291
+ /**
292
+ * Create AgentX instance
293
+ *
294
+ * @example
295
+ * ```typescript
296
+ * // Local mode (default)
297
+ * const agentx = await createAgentX();
298
+ *
299
+ * // Local mode with config
300
+ * const agentx = await createAgentX({
301
+ * llm: { apiKey: "sk-..." },
302
+ * storage: { driver: "sqlite", path: "./data.db" },
303
+ * });
304
+ *
305
+ * // Remote mode
306
+ * const agentx = await createAgentX({ server: "ws://localhost:5200" });
307
+ * ```
308
+ */
309
+ declare function createAgentX(config?: AgentXConfig): Promise<AgentX>;
310
+
311
+ export { type AgentX, type AgentXConfig, type LLMConfig, type LocalConfig, type LoggerConfig, type RemoteConfig, type StorageConfig, type StorageDriver, type Unsubscribe, createAgentX, isLocalConfig, isRemoteConfig };
@@ -0,0 +1,311 @@
1
+ import { S as SystemEvent } from './SystemEvent-CPvvxdMQ.js';
2
+ import { C as CommandRequestType, R as RequestDataFor, a as ResponseEventFor, b as CommandEventMap } from './CommandEvent-CbXzPolX.js';
3
+ import { L as LogLevel, c as LoggerFactory } from './LoggerFactory-DZtw0M7U.js';
4
+ import './ImageRecord-Cn0VcJWk.js';
5
+
6
+ /**
7
+ * AgentX - Unified High-Level API for AI Agents
8
+ *
9
+ * AgentX provides a simple, consistent API for both local and remote modes.
10
+ * It wraps Runtime and provides the same interface regardless of deployment.
11
+ *
12
+ * ## Two Modes
13
+ *
14
+ * ```
15
+ * Local Mode Remote Mode
16
+ * ─────────────────────────────────────────────────────────
17
+ * AgentX AgentX
18
+ * │ │
19
+ * └── Runtime (embedded) └── WebSocket ──→ Server
20
+ * │ │
21
+ * └── LLM, Storage └── Runtime
22
+ * ```
23
+ *
24
+ * ## API Design
25
+ *
26
+ * All operations use CommandEvent pattern:
27
+ * - `request(type, data)` - Send request, wait for response
28
+ * - `on(type, handler)` - Subscribe to events
29
+ * - `onCommand(type, handler)` - Type-safe command subscription
30
+ *
31
+ * ## Usage
32
+ *
33
+ * ```typescript
34
+ * // Local mode (default)
35
+ * const agentx = await createAgentX();
36
+ *
37
+ * // Local mode with custom LLM and storage
38
+ * const agentx = await createAgentX({
39
+ * llm: { apiKey: "sk-...", model: "claude-opus-4-20250514" },
40
+ * storage: { driver: "postgresql", url: "postgres://..." },
41
+ * });
42
+ *
43
+ * // Remote mode
44
+ * const agentx = await createAgentX({ server: "ws://localhost:5200" });
45
+ *
46
+ * // Same API for both modes!
47
+ * const res = await agentx.request("container_create_request", {
48
+ * containerId: "my-container"
49
+ * });
50
+ *
51
+ * agentx.on("text_delta", (e) => console.log(e.data.text));
52
+ *
53
+ * await agentx.dispose();
54
+ * ```
55
+ *
56
+ * @packageDocumentation
57
+ */
58
+
59
+ /**
60
+ * LLM configuration
61
+ */
62
+ interface LLMConfig {
63
+ /**
64
+ * Anthropic API key (required)
65
+ */
66
+ apiKey: string;
67
+ /**
68
+ * API base URL
69
+ * @default "https://api.anthropic.com"
70
+ */
71
+ baseUrl?: string;
72
+ /**
73
+ * Model name
74
+ * @default "claude-sonnet-4-20250514"
75
+ */
76
+ model?: string;
77
+ }
78
+ /**
79
+ * Storage driver type
80
+ */
81
+ type StorageDriver = "memory" | "fs" | "redis" | "mongodb" | "sqlite" | "mysql" | "postgresql";
82
+ /**
83
+ * Storage configuration
84
+ */
85
+ interface StorageConfig {
86
+ /**
87
+ * Storage driver
88
+ * @default "memory"
89
+ */
90
+ driver?: StorageDriver;
91
+ /**
92
+ * File path (for sqlite, fs drivers)
93
+ * @example "./data.db" for sqlite
94
+ * @example "./data" for fs
95
+ */
96
+ path?: string;
97
+ /**
98
+ * Connection URL (for redis, mongodb, mysql, postgresql)
99
+ * @example "redis://localhost:6379"
100
+ * @example "mongodb://localhost:27017/agentx"
101
+ * @example "mysql://user:pass@localhost:3306/agentx"
102
+ * @example "postgres://user:pass@localhost:5432/agentx"
103
+ */
104
+ url?: string;
105
+ }
106
+ /**
107
+ * Logger configuration
108
+ */
109
+ interface LoggerConfig {
110
+ /**
111
+ * Log level
112
+ * @default LogLevel.INFO
113
+ */
114
+ level?: LogLevel;
115
+ /**
116
+ * Custom logger factory implementation
117
+ * If provided, this factory will be used to create all logger instances.
118
+ * If not provided, uses ConsoleLogger with console options.
119
+ */
120
+ factory?: LoggerFactory;
121
+ /**
122
+ * Console logger options (only used when factory is not provided)
123
+ */
124
+ console?: {
125
+ /**
126
+ * Enable colored output
127
+ * @default true (Node.js), false (browser)
128
+ */
129
+ colors?: boolean;
130
+ /**
131
+ * Include timestamps in log output
132
+ * @default true
133
+ */
134
+ timestamps?: boolean;
135
+ };
136
+ }
137
+ /**
138
+ * Local mode configuration
139
+ *
140
+ * Runs AgentX with local runtime, connecting directly to LLM API.
141
+ */
142
+ interface LocalConfig {
143
+ /**
144
+ * LLM configuration
145
+ */
146
+ llm?: LLMConfig;
147
+ /**
148
+ * Logger configuration
149
+ */
150
+ logger?: LoggerConfig;
151
+ /**
152
+ * AgentX base directory for runtime data (containers, workdirs, storage, logs)
153
+ * @default "~/.agentx" (user's home directory)
154
+ * @example "/var/lib/agentx"
155
+ * @example "/Users/john/.agentx"
156
+ *
157
+ * Directory structure:
158
+ * - {agentxDir}/data/agentx.db - SQLite database (auto-configured)
159
+ * - {agentxDir}/logs/ - Log files (if configured)
160
+ * - {agentxDir}/containers/ - Agent workdirs
161
+ */
162
+ agentxDir?: string;
163
+ /**
164
+ * HTTP server to attach WebSocket to.
165
+ * If provided, WebSocket upgrade will be handled on the same port.
166
+ * The server should handle authentication before upgrading.
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * import { createServer } from "http";
171
+ * import { Hono } from "hono";
172
+ *
173
+ * const app = new Hono();
174
+ * // ... add auth middleware
175
+ *
176
+ * const server = createServer(app.fetch);
177
+ * const agentx = await createAgentX({ server });
178
+ *
179
+ * server.listen(5200);
180
+ * ```
181
+ */
182
+ server?: {
183
+ on(event: "upgrade", listener: (request: {
184
+ url?: string;
185
+ headers: {
186
+ host?: string;
187
+ };
188
+ }, socket: unknown, head: unknown) => void): void;
189
+ };
190
+ }
191
+ /**
192
+ * Remote mode configuration
193
+ *
194
+ * Connects to a remote AgentX server via WebSocket.
195
+ */
196
+ interface RemoteConfig {
197
+ /**
198
+ * Remote server URL (WebSocket)
199
+ * @example "ws://localhost:5200"
200
+ */
201
+ serverUrl: string;
202
+ }
203
+ /**
204
+ * AgentX configuration
205
+ *
206
+ * - LocalConfig: Run with local runtime (default)
207
+ * - RemoteConfig: Connect to remote server
208
+ */
209
+ type AgentXConfig = LocalConfig | RemoteConfig;
210
+ /**
211
+ * Type guard: is this a remote config?
212
+ */
213
+ declare function isRemoteConfig(config: AgentXConfig): config is RemoteConfig;
214
+ /**
215
+ * Type guard: is this a local config?
216
+ */
217
+ declare function isLocalConfig(config: AgentXConfig): config is LocalConfig;
218
+ /**
219
+ * Unsubscribe function
220
+ */
221
+ type Unsubscribe = () => void;
222
+ /**
223
+ * AgentX - Main API interface
224
+ *
225
+ * Unified API for both local and remote modes.
226
+ */
227
+ interface AgentX {
228
+ /**
229
+ * Send a command request and wait for response.
230
+ *
231
+ * @example
232
+ * ```typescript
233
+ * const res = await agentx.request("container_create_request", {
234
+ * containerId: "my-container"
235
+ * });
236
+ * console.log(res.data.containerId);
237
+ * ```
238
+ */
239
+ request<T extends CommandRequestType>(type: T, data: RequestDataFor<T>, timeout?: number): Promise<ResponseEventFor<T>>;
240
+ /**
241
+ * Subscribe to events.
242
+ *
243
+ * @example
244
+ * ```typescript
245
+ * agentx.on("text_delta", (e) => {
246
+ * process.stdout.write(e.data.text);
247
+ * });
248
+ * ```
249
+ */
250
+ on<T extends string>(type: T, handler: (event: SystemEvent & {
251
+ type: T;
252
+ }) => void): Unsubscribe;
253
+ /**
254
+ * Subscribe to command events with full type safety.
255
+ *
256
+ * @example
257
+ * ```typescript
258
+ * agentx.onCommand("container_create_response", (e) => {
259
+ * console.log(e.data.containerId);
260
+ * });
261
+ * ```
262
+ */
263
+ onCommand<T extends keyof CommandEventMap>(type: T, handler: (event: CommandEventMap[T]) => void): Unsubscribe;
264
+ /**
265
+ * Emit a command event.
266
+ *
267
+ * For fine-grained control. Usually prefer `request()`.
268
+ */
269
+ emitCommand<T extends keyof CommandEventMap>(type: T, data: CommandEventMap[T]["data"]): void;
270
+ /**
271
+ * Start listening for remote connections.
272
+ *
273
+ * Only available in local mode.
274
+ *
275
+ * @example
276
+ * ```typescript
277
+ * await agentx.listen(5200);
278
+ * console.log("Server running on ws://localhost:5200");
279
+ * ```
280
+ */
281
+ listen(port: number, host?: string): Promise<void>;
282
+ /**
283
+ * Stop listening for remote connections.
284
+ */
285
+ close(): Promise<void>;
286
+ /**
287
+ * Dispose AgentX and release all resources.
288
+ */
289
+ dispose(): Promise<void>;
290
+ }
291
+ /**
292
+ * Create AgentX instance
293
+ *
294
+ * @example
295
+ * ```typescript
296
+ * // Local mode (default)
297
+ * const agentx = await createAgentX();
298
+ *
299
+ * // Local mode with config
300
+ * const agentx = await createAgentX({
301
+ * llm: { apiKey: "sk-..." },
302
+ * storage: { driver: "sqlite", path: "./data.db" },
303
+ * });
304
+ *
305
+ * // Remote mode
306
+ * const agentx = await createAgentX({ server: "ws://localhost:5200" });
307
+ * ```
308
+ */
309
+ declare function createAgentX(config?: AgentXConfig): Promise<AgentX>;
310
+
311
+ export { type AgentX, type AgentXConfig, type LLMConfig, type LocalConfig, type LoggerConfig, type RemoteConfig, type StorageConfig, type StorageDriver, type Unsubscribe, createAgentX, isLocalConfig, isRemoteConfig };
package/dist/agentx.js ADDED
@@ -0,0 +1,12 @@
1
+ // src/agentx/index.ts
2
+ function isRemoteConfig(config) {
3
+ return "serverUrl" in config && typeof config.serverUrl === "string";
4
+ }
5
+ function isLocalConfig(config) {
6
+ return !isRemoteConfig(config);
7
+ }
8
+ export {
9
+ isLocalConfig,
10
+ isRemoteConfig
11
+ };
12
+ //# sourceMappingURL=agentx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/agentx/index.ts"],"sourcesContent":["/**\n * AgentX - Unified High-Level API for AI Agents\n *\n * AgentX provides a simple, consistent API for both local and remote modes.\n * It wraps Runtime and provides the same interface regardless of deployment.\n *\n * ## Two Modes\n *\n * ```\n * Local Mode Remote Mode\n * ─────────────────────────────────────────────────────────\n * AgentX AgentX\n * │ │\n * └── Runtime (embedded) └── WebSocket ──→ Server\n * │ │\n * └── LLM, Storage └── Runtime\n * ```\n *\n * ## API Design\n *\n * All operations use CommandEvent pattern:\n * - `request(type, data)` - Send request, wait for response\n * - `on(type, handler)` - Subscribe to events\n * - `onCommand(type, handler)` - Type-safe command subscription\n *\n * ## Usage\n *\n * ```typescript\n * // Local mode (default)\n * const agentx = await createAgentX();\n *\n * // Local mode with custom LLM and storage\n * const agentx = await createAgentX({\n * llm: { apiKey: \"sk-...\", model: \"claude-opus-4-20250514\" },\n * storage: { driver: \"postgresql\", url: \"postgres://...\" },\n * });\n *\n * // Remote mode\n * const agentx = await createAgentX({ server: \"ws://localhost:5200\" });\n *\n * // Same API for both modes!\n * const res = await agentx.request(\"container_create_request\", {\n * containerId: \"my-container\"\n * });\n *\n * agentx.on(\"text_delta\", (e) => console.log(e.data.text));\n *\n * await agentx.dispose();\n * ```\n *\n * @packageDocumentation\n */\n\nimport type { SystemEvent } from \"~/event/base\";\nimport type {\n CommandEventMap,\n CommandRequestType,\n ResponseEventFor,\n RequestDataFor,\n} from \"~/event/command\";\nimport type { LogLevel, LoggerFactory } from \"~/common/logger\";\n\n// ============================================================================\n// Configuration - Local Mode\n// ============================================================================\n\n/**\n * LLM configuration\n */\nexport interface LLMConfig {\n /**\n * Anthropic API key (required)\n */\n apiKey: string;\n\n /**\n * API base URL\n * @default \"https://api.anthropic.com\"\n */\n baseUrl?: string;\n\n /**\n * Model name\n * @default \"claude-sonnet-4-20250514\"\n */\n model?: string;\n}\n\n/**\n * Storage driver type\n */\nexport type StorageDriver =\n | \"memory\"\n | \"fs\"\n | \"redis\"\n | \"mongodb\"\n | \"sqlite\"\n | \"mysql\"\n | \"postgresql\";\n\n/**\n * Storage configuration\n */\nexport interface StorageConfig {\n /**\n * Storage driver\n * @default \"memory\"\n */\n driver?: StorageDriver;\n\n /**\n * File path (for sqlite, fs drivers)\n * @example \"./data.db\" for sqlite\n * @example \"./data\" for fs\n */\n path?: string;\n\n /**\n * Connection URL (for redis, mongodb, mysql, postgresql)\n * @example \"redis://localhost:6379\"\n * @example \"mongodb://localhost:27017/agentx\"\n * @example \"mysql://user:pass@localhost:3306/agentx\"\n * @example \"postgres://user:pass@localhost:5432/agentx\"\n */\n url?: string;\n}\n\n/**\n * Logger configuration\n */\nexport interface LoggerConfig {\n /**\n * Log level\n * @default LogLevel.INFO\n */\n level?: LogLevel;\n\n /**\n * Custom logger factory implementation\n * If provided, this factory will be used to create all logger instances.\n * If not provided, uses ConsoleLogger with console options.\n */\n factory?: LoggerFactory;\n\n /**\n * Console logger options (only used when factory is not provided)\n */\n console?: {\n /**\n * Enable colored output\n * @default true (Node.js), false (browser)\n */\n colors?: boolean;\n\n /**\n * Include timestamps in log output\n * @default true\n */\n timestamps?: boolean;\n };\n}\n\n/**\n * Local mode configuration\n *\n * Runs AgentX with local runtime, connecting directly to LLM API.\n */\nexport interface LocalConfig {\n /**\n * LLM configuration\n */\n llm?: LLMConfig;\n\n /**\n * Logger configuration\n */\n logger?: LoggerConfig;\n\n /**\n * AgentX base directory for runtime data (containers, workdirs, storage, logs)\n * @default \"~/.agentx\" (user's home directory)\n * @example \"/var/lib/agentx\"\n * @example \"/Users/john/.agentx\"\n *\n * Directory structure:\n * - {agentxDir}/data/agentx.db - SQLite database (auto-configured)\n * - {agentxDir}/logs/ - Log files (if configured)\n * - {agentxDir}/containers/ - Agent workdirs\n */\n agentxDir?: string;\n\n /**\n * HTTP server to attach WebSocket to.\n * If provided, WebSocket upgrade will be handled on the same port.\n * The server should handle authentication before upgrading.\n *\n * @example\n * ```typescript\n * import { createServer } from \"http\";\n * import { Hono } from \"hono\";\n *\n * const app = new Hono();\n * // ... add auth middleware\n *\n * const server = createServer(app.fetch);\n * const agentx = await createAgentX({ server });\n *\n * server.listen(5200);\n * ```\n */\n server?: {\n on(\n event: \"upgrade\",\n listener: (\n request: { url?: string; headers: { host?: string } },\n socket: unknown,\n head: unknown\n ) => void\n ): void;\n };\n}\n\n// ============================================================================\n// Configuration - Remote Mode\n// ============================================================================\n\n/**\n * Remote mode configuration\n *\n * Connects to a remote AgentX server via WebSocket.\n */\nexport interface RemoteConfig {\n /**\n * Remote server URL (WebSocket)\n * @example \"ws://localhost:5200\"\n */\n serverUrl: string;\n}\n\n// ============================================================================\n// Union Type\n// ============================================================================\n\n/**\n * AgentX configuration\n *\n * - LocalConfig: Run with local runtime (default)\n * - RemoteConfig: Connect to remote server\n */\nexport type AgentXConfig = LocalConfig | RemoteConfig;\n\n/**\n * Type guard: is this a remote config?\n */\nexport function isRemoteConfig(config: AgentXConfig): config is RemoteConfig {\n return \"serverUrl\" in config && typeof config.serverUrl === \"string\";\n}\n\n/**\n * Type guard: is this a local config?\n */\nexport function isLocalConfig(config: AgentXConfig): config is LocalConfig {\n return !isRemoteConfig(config);\n}\n\n// ============================================================================\n// Unsubscribe\n// ============================================================================\n\n/**\n * Unsubscribe function\n */\nexport type Unsubscribe = () => void;\n\n// ============================================================================\n// AgentX Interface\n// ============================================================================\n\n/**\n * AgentX - Main API interface\n *\n * Unified API for both local and remote modes.\n */\nexport interface AgentX {\n // ==================== Core API ====================\n\n /**\n * Send a command request and wait for response.\n *\n * @example\n * ```typescript\n * const res = await agentx.request(\"container_create_request\", {\n * containerId: \"my-container\"\n * });\n * console.log(res.data.containerId);\n * ```\n */\n request<T extends CommandRequestType>(\n type: T,\n data: RequestDataFor<T>,\n timeout?: number\n ): Promise<ResponseEventFor<T>>;\n\n /**\n * Subscribe to events.\n *\n * @example\n * ```typescript\n * agentx.on(\"text_delta\", (e) => {\n * process.stdout.write(e.data.text);\n * });\n * ```\n */\n on<T extends string>(type: T, handler: (event: SystemEvent & { type: T }) => void): Unsubscribe;\n\n /**\n * Subscribe to command events with full type safety.\n *\n * @example\n * ```typescript\n * agentx.onCommand(\"container_create_response\", (e) => {\n * console.log(e.data.containerId);\n * });\n * ```\n */\n onCommand<T extends keyof CommandEventMap>(\n type: T,\n handler: (event: CommandEventMap[T]) => void\n ): Unsubscribe;\n\n /**\n * Emit a command event.\n *\n * For fine-grained control. Usually prefer `request()`.\n */\n emitCommand<T extends keyof CommandEventMap>(type: T, data: CommandEventMap[T][\"data\"]): void;\n\n // ==================== Server API (local mode only) ====================\n\n /**\n * Start listening for remote connections.\n *\n * Only available in local mode.\n *\n * @example\n * ```typescript\n * await agentx.listen(5200);\n * console.log(\"Server running on ws://localhost:5200\");\n * ```\n */\n listen(port: number, host?: string): Promise<void>;\n\n /**\n * Stop listening for remote connections.\n */\n close(): Promise<void>;\n\n // ==================== Lifecycle ====================\n\n /**\n * Dispose AgentX and release all resources.\n */\n dispose(): Promise<void>;\n}\n\n// ============================================================================\n// Factory Function\n// ============================================================================\n\n/**\n * Create AgentX instance\n *\n * @example\n * ```typescript\n * // Local mode (default)\n * const agentx = await createAgentX();\n *\n * // Local mode with config\n * const agentx = await createAgentX({\n * llm: { apiKey: \"sk-...\" },\n * storage: { driver: \"sqlite\", path: \"./data.db\" },\n * });\n *\n * // Remote mode\n * const agentx = await createAgentX({ server: \"ws://localhost:5200\" });\n * ```\n */\nexport declare function createAgentX(config?: AgentXConfig): Promise<AgentX>;\n"],"mappings":";AA8PO,SAAS,eAAe,QAA8C;AAC3E,SAAO,eAAe,UAAU,OAAO,OAAO,cAAc;AAC9D;AAKO,SAAS,cAAc,QAA6C;AACzE,SAAO,CAAC,eAAe,MAAM;AAC/B;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-2QHAIM3V.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/common/index.ts
17
+ var common_exports = {};
18
+ module.exports = __toCommonJS(common_exports);
19
+ //# sourceMappingURL=common.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/common/index.ts"],"sourcesContent":["/**\n * Common Module - Shared Infrastructure Types\n *\n * Infrastructure types shared across all AgentX packages.\n *\n * ## Why Types Here, Implementation in @agentxjs/common?\n *\n * - @agentxjs/types has zero dependencies (pure types)\n * - @agentxjs/common has runtime dependencies (pino, etc.)\n * - All packages depend on types, not all need common's implementation\n *\n * ## Module Structure\n *\n * | Module | Purpose |\n * |----------|-----------------------------------|\n * | logger/ | Logger interface (SLF4J-style) |\n *\n * @packageDocumentation\n */\n\nexport * from \"./logger\";\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}