agentxjs 1.9.10-dev → 2.0.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/src/types.ts CHANGED
@@ -3,6 +3,9 @@
3
3
  */
4
4
 
5
5
  import type { BusEvent, EventBus, Unsubscribe, BusEventHandler } from "@agentxjs/core/event";
6
+ import type { CreateDriver } from "@agentxjs/core/driver";
7
+ import type { AgentXPlatform } from "@agentxjs/core/runtime";
8
+ import type { Message } from "@agentxjs/core/agent";
6
9
  import type { Presentation, PresentationOptions } from "./presentation";
7
10
 
8
11
  // ============================================================================
@@ -15,27 +18,90 @@ import type { Presentation, PresentationOptions } from "./presentation";
15
18
  export type MaybeAsync<T> = T | (() => T) | (() => Promise<T>);
16
19
 
17
20
  /**
18
- * AgentX client configuration
21
+ * LLM provider identifier
22
+ */
23
+ export type LLMProvider = "anthropic" | "openai" | "google" | "xai" | "deepseek" | "mistral";
24
+
25
+ /**
26
+ * AgentX unified configuration
27
+ *
28
+ * Supports two modes:
29
+ * - **Local mode**: `apiKey` present → embedded Runtime + MonoDriver
30
+ * - **Remote mode**: `serverUrl` present → WebSocket client
19
31
  */
20
32
  export interface AgentXConfig {
33
+ // ===== Local Mode =====
34
+
35
+ /**
36
+ * API key for LLM provider (local mode)
37
+ * If present, enables local mode with embedded Runtime
38
+ */
39
+ apiKey?: string;
40
+
41
+ /**
42
+ * LLM provider (local mode)
43
+ * @default "anthropic"
44
+ */
45
+ provider?: LLMProvider;
46
+
47
+ /**
48
+ * Model ID (local mode)
49
+ */
50
+ model?: string;
51
+
52
+ /**
53
+ * Base URL for API endpoint (local mode, for proxy/private deployments)
54
+ */
55
+ baseUrl?: string;
56
+
57
+ /**
58
+ * Data storage path (local mode)
59
+ * @default ":memory:" (in-memory storage)
60
+ */
61
+ dataPath?: string;
62
+
63
+ /**
64
+ * Custom CreateDriver factory (local mode, advanced)
65
+ * If provided, overrides the default MonoDriver
66
+ */
67
+ createDriver?: CreateDriver;
68
+
69
+ /**
70
+ * Custom AgentXPlatform (local mode, advanced)
71
+ * If provided, overrides the default NodePlatform
72
+ */
73
+ customPlatform?: AgentXPlatform;
74
+
75
+ // ===== Remote Mode =====
76
+
21
77
  /**
22
- * WebSocket server URL
78
+ * WebSocket server URL (remote mode)
79
+ * If present, enables remote mode
23
80
  */
24
- serverUrl: string;
81
+ serverUrl?: string;
25
82
 
26
83
  /**
27
- * Headers for authentication (static or dynamic)
84
+ * Headers for authentication (remote mode, static or dynamic)
28
85
  * In Node.js: sent during WebSocket handshake
29
86
  * In browsers: sent as first auth message (WebSocket API limitation)
30
87
  */
31
88
  headers?: MaybeAsync<Record<string, string>>;
32
89
 
33
90
  /**
34
- * Business context injected into all requests
91
+ * Business context injected into all requests (remote mode)
35
92
  * Useful for passing userId, tenantId, permissions, etc.
36
93
  */
37
94
  context?: MaybeAsync<Record<string, unknown>>;
38
95
 
96
+ // ===== Common =====
97
+
98
+ /**
99
+ * Log level for AgentX runtime
100
+ * Controls verbosity of console/file logging.
101
+ * @default "info"
102
+ */
103
+ logLevel?: "debug" | "info" | "warn" | "error" | "silent";
104
+
39
105
  /**
40
106
  * Request timeout in milliseconds (default: 30000)
41
107
  */
@@ -43,11 +109,12 @@ export interface AgentXConfig {
43
109
 
44
110
  /**
45
111
  * Enable debug logging
112
+ * @deprecated Use `logLevel: "debug"` instead
46
113
  */
47
114
  debug?: boolean;
48
115
 
49
116
  /**
50
- * Auto reconnect on connection loss (default: true)
117
+ * Auto reconnect on connection loss (default: true, remote mode only)
51
118
  */
52
119
  autoReconnect?: boolean;
53
120
  }
@@ -77,6 +144,7 @@ export interface ImageRecord {
77
144
  name?: string;
78
145
  description?: string;
79
146
  systemPrompt?: string;
147
+ customData?: Record<string, unknown>;
80
148
  createdAt: number;
81
149
  updatedAt: number;
82
150
  }
@@ -149,6 +217,13 @@ export interface ImageListResponse extends BaseResponse {
149
217
  __subscriptions?: string[];
150
218
  }
151
219
 
220
+ /**
221
+ * Image update response
222
+ */
223
+ export interface ImageUpdateResponse extends BaseResponse {
224
+ record: ImageRecord;
225
+ }
226
+
152
227
  /**
153
228
  * Container create response
154
229
  */
@@ -179,101 +254,183 @@ export interface MessageSendResponse extends BaseResponse {
179
254
  }
180
255
 
181
256
  // ============================================================================
182
- // AgentX Client Interface
257
+ // Namespace Interfaces
183
258
  // ============================================================================
184
259
 
185
260
  /**
186
- * AgentX Client SDK
261
+ * Container operations namespace
187
262
  */
188
- export interface AgentX {
263
+ export interface ContainerNamespace {
189
264
  /**
190
- * Check if connected to server
265
+ * Create or get container
191
266
  */
192
- readonly connected: boolean;
267
+ create(containerId: string): Promise<ContainerCreateResponse>;
193
268
 
194
269
  /**
195
- * Event bus for subscribing to events
270
+ * Get container
196
271
  */
197
- readonly events: EventBus;
272
+ get(containerId: string): Promise<ContainerGetResponse>;
273
+
274
+ /**
275
+ * List containers
276
+ */
277
+ list(): Promise<ContainerListResponse>;
278
+ }
279
+
280
+ /**
281
+ * Image operations namespace
282
+ */
283
+ export interface ImageNamespace {
284
+ /**
285
+ * Create a new image
286
+ */
287
+ create(params: {
288
+ containerId: string;
289
+ name?: string;
290
+ description?: string;
291
+ systemPrompt?: string;
292
+ mcpServers?: Record<string, unknown>;
293
+ customData?: Record<string, unknown>;
294
+ }): Promise<ImageCreateResponse>;
295
+
296
+ /**
297
+ * Get image by ID
298
+ */
299
+ get(imageId: string): Promise<ImageGetResponse>;
198
300
 
199
- // ==================== Agent Operations ====================
301
+ /**
302
+ * List images
303
+ */
304
+ list(containerId?: string): Promise<ImageListResponse>;
200
305
 
306
+ /**
307
+ * Update image
308
+ */
309
+ update(
310
+ imageId: string,
311
+ updates: {
312
+ name?: string;
313
+ description?: string;
314
+ customData?: Record<string, unknown>;
315
+ }
316
+ ): Promise<ImageUpdateResponse>;
317
+
318
+ /**
319
+ * Delete image
320
+ */
321
+ delete(imageId: string): Promise<BaseResponse>;
322
+ }
323
+
324
+ /**
325
+ * Agent operations namespace
326
+ */
327
+ export interface AgentNamespace {
201
328
  /**
202
329
  * Create a new agent
203
330
  */
204
- createAgent(params: { imageId: string; agentId?: string }): Promise<AgentCreateResponse>;
331
+ create(params: { imageId: string; agentId?: string }): Promise<AgentCreateResponse>;
205
332
 
206
333
  /**
207
334
  * Get agent by ID
208
335
  */
209
- getAgent(agentId: string): Promise<AgentGetResponse>;
336
+ get(agentId: string): Promise<AgentGetResponse>;
210
337
 
211
338
  /**
212
339
  * List agents
213
340
  */
214
- listAgents(containerId?: string): Promise<AgentListResponse>;
341
+ list(containerId?: string): Promise<AgentListResponse>;
215
342
 
216
343
  /**
217
344
  * Destroy an agent
218
345
  */
219
- destroyAgent(agentId: string): Promise<BaseResponse>;
220
-
221
- // ==================== Message Operations ====================
346
+ destroy(agentId: string): Promise<BaseResponse>;
347
+ }
222
348
 
349
+ /**
350
+ * Session operations namespace (messaging)
351
+ */
352
+ export interface SessionNamespace {
223
353
  /**
224
354
  * Send message to agent
225
355
  */
226
- sendMessage(agentId: string, content: string | unknown[]): Promise<MessageSendResponse>;
356
+ send(agentId: string, content: string | unknown[]): Promise<MessageSendResponse>;
227
357
 
228
358
  /**
229
359
  * Interrupt agent
230
360
  */
231
361
  interrupt(agentId: string): Promise<BaseResponse>;
232
362
 
233
- // ==================== Image Operations ====================
363
+ /**
364
+ * Get message history for an agent's session
365
+ */
366
+ getMessages(agentId: string): Promise<Message[]>;
367
+ }
234
368
 
369
+ /**
370
+ * Presentation operations namespace
371
+ */
372
+ export interface PresentationNamespace {
235
373
  /**
236
- * Create a new image
374
+ * Create a presentation for UI integration
375
+ *
376
+ * @example
377
+ * ```typescript
378
+ * const pres = agentx.presentations.create(agentId, {
379
+ * onUpdate: (state) => renderUI(state),
380
+ * onError: (error) => console.error(error),
381
+ * });
382
+ *
383
+ * await pres.send("Hello!");
384
+ * pres.dispose();
385
+ * ```
237
386
  */
238
- createImage(params: {
239
- containerId: string;
240
- name?: string;
241
- description?: string;
242
- systemPrompt?: string;
243
- mcpServers?: Record<string, unknown>;
244
- }): Promise<ImageCreateResponse>;
387
+ create(agentId: string, options?: PresentationOptions): Promise<Presentation>;
388
+ }
245
389
 
390
+ // ============================================================================
391
+ // AgentX Client Interface
392
+ // ============================================================================
393
+
394
+ /**
395
+ * AgentX Client SDK
396
+ */
397
+ export interface AgentX {
246
398
  /**
247
- * Get image by ID
399
+ * Check if connected to server
248
400
  */
249
- getImage(imageId: string): Promise<ImageGetResponse>;
401
+ readonly connected: boolean;
250
402
 
251
403
  /**
252
- * List images
404
+ * Event bus for subscribing to events
253
405
  */
254
- listImages(containerId?: string): Promise<ImageListResponse>;
406
+ readonly events: EventBus;
407
+
408
+ // ==================== Namespaced Operations ====================
255
409
 
256
410
  /**
257
- * Delete image
411
+ * Container operations
258
412
  */
259
- deleteImage(imageId: string): Promise<BaseResponse>;
413
+ readonly containers: ContainerNamespace;
260
414
 
261
- // ==================== Container Operations ====================
415
+ /**
416
+ * Image operations
417
+ */
418
+ readonly images: ImageNamespace;
262
419
 
263
420
  /**
264
- * Create or get container
421
+ * Agent operations
265
422
  */
266
- createContainer(containerId: string): Promise<ContainerCreateResponse>;
423
+ readonly agents: AgentNamespace;
267
424
 
268
425
  /**
269
- * Get container
426
+ * Session operations (messaging)
270
427
  */
271
- getContainer(containerId: string): Promise<ContainerGetResponse>;
428
+ readonly sessions: SessionNamespace;
272
429
 
273
430
  /**
274
- * List containers
431
+ * Presentation operations (UI integration)
275
432
  */
276
- listContainers(): Promise<ContainerListResponse>;
433
+ readonly presentations: PresentationNamespace;
277
434
 
278
435
  // ==================== Event Subscription ====================
279
436
 
@@ -292,24 +449,6 @@ export interface AgentX {
292
449
  */
293
450
  subscribe(sessionId: string): void;
294
451
 
295
- // ==================== Presentation ====================
296
-
297
- /**
298
- * Create a presentation for UI integration
299
- *
300
- * @example
301
- * ```typescript
302
- * const presentation = agentx.presentation(agentId);
303
- *
304
- * presentation.onUpdate((state) => {
305
- * render(state.conversations);
306
- * });
307
- *
308
- * await presentation.send("Hello!");
309
- * ```
310
- */
311
- presentation(agentId: string, options?: PresentationOptions): Presentation;
312
-
313
452
  // ==================== Lifecycle ====================
314
453
 
315
454
  /**