agentxjs 2.0.2 → 2.0.4
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/chunk-ZFL27HK7.js +467 -0
- package/dist/chunk-ZFL27HK7.js.map +1 -0
- package/dist/index.d.ts +181 -140
- package/dist/index.js +115 -84
- package/dist/index.js.map +1 -1
- package/dist/server-IFVYHIJF.js +7 -0
- package/dist/server-IFVYHIJF.js.map +1 -0
- package/package.json +4 -6
- package/src/CommandHandler.ts +424 -0
- package/src/LocalClient.ts +10 -10
- package/src/RemoteClient.ts +14 -14
- package/src/index.ts +125 -110
- package/src/namespaces/presentations.ts +1 -1
- package/src/presentation/Presentation.ts +2 -2
- package/src/server.ts +346 -0
- package/src/types.ts +84 -137
package/src/types.ts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import type { Message } from "@agentxjs/core/agent";
|
|
6
|
-
import type { CreateDriver } from "@agentxjs/core/driver";
|
|
7
6
|
import type { BusEvent, BusEventHandler, EventBus, Unsubscribe } from "@agentxjs/core/event";
|
|
8
7
|
import type { AgentXPlatform } from "@agentxjs/core/runtime";
|
|
9
8
|
import type { Presentation, PresentationOptions } from "./presentation";
|
|
@@ -18,105 +17,16 @@ import type { Presentation, PresentationOptions } from "./presentation";
|
|
|
18
17
|
export type MaybeAsync<T> = T | (() => T) | (() => Promise<T>);
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
|
-
*
|
|
20
|
+
* Internal config passed to RemoteClient
|
|
21
|
+
* @internal
|
|
22
22
|
*/
|
|
23
|
-
export
|
|
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
|
|
31
|
-
*/
|
|
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
|
-
|
|
77
|
-
/**
|
|
78
|
-
* WebSocket server URL (remote mode)
|
|
79
|
-
* If present, enables remote mode
|
|
80
|
-
*/
|
|
81
|
-
serverUrl?: string;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Headers for authentication (remote mode, static or dynamic)
|
|
85
|
-
* In Node.js: sent during WebSocket handshake
|
|
86
|
-
* In browsers: sent as first auth message (WebSocket API limitation)
|
|
87
|
-
*/
|
|
23
|
+
export interface RemoteClientConfig {
|
|
24
|
+
serverUrl: string;
|
|
88
25
|
headers?: MaybeAsync<Record<string, string>>;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Business context injected into all requests (remote mode)
|
|
92
|
-
* Useful for passing userId, tenantId, permissions, etc.
|
|
93
|
-
*/
|
|
94
26
|
context?: MaybeAsync<Record<string, unknown>>;
|
|
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
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Request timeout in milliseconds (default: 30000)
|
|
107
|
-
*/
|
|
108
27
|
timeout?: number;
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Enable debug logging
|
|
112
|
-
* @deprecated Use `logLevel: "debug"` instead
|
|
113
|
-
*/
|
|
114
|
-
debug?: boolean;
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Auto reconnect on connection loss (default: true, remote mode only)
|
|
118
|
-
*/
|
|
119
28
|
autoReconnect?: boolean;
|
|
29
|
+
customPlatform?: AgentXPlatform;
|
|
120
30
|
}
|
|
121
31
|
|
|
122
32
|
// ============================================================================
|
|
@@ -375,7 +285,7 @@ export interface PresentationNamespace {
|
|
|
375
285
|
*
|
|
376
286
|
* @example
|
|
377
287
|
* ```typescript
|
|
378
|
-
* const pres = agentx.
|
|
288
|
+
* const pres = agentx.presentation.create(agentId, {
|
|
379
289
|
* onUpdate: (state) => renderUI(state),
|
|
380
290
|
* onError: (error) => console.error(error),
|
|
381
291
|
* });
|
|
@@ -392,11 +302,11 @@ export interface PresentationNamespace {
|
|
|
392
302
|
// ============================================================================
|
|
393
303
|
|
|
394
304
|
/**
|
|
395
|
-
* AgentX Client SDK
|
|
305
|
+
* AgentX Client SDK — unified interface for local, remote, and server modes
|
|
396
306
|
*/
|
|
397
307
|
export interface AgentX {
|
|
398
308
|
/**
|
|
399
|
-
* Check if connected
|
|
309
|
+
* Check if connected/active
|
|
400
310
|
*/
|
|
401
311
|
readonly connected: boolean;
|
|
402
312
|
|
|
@@ -407,59 +317,96 @@ export interface AgentX {
|
|
|
407
317
|
|
|
408
318
|
// ==================== Namespaced Operations ====================
|
|
409
319
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
readonly
|
|
414
|
-
|
|
415
|
-
/**
|
|
416
|
-
* Image operations
|
|
417
|
-
*/
|
|
418
|
-
readonly images: ImageNamespace;
|
|
419
|
-
|
|
420
|
-
/**
|
|
421
|
-
* Agent operations
|
|
422
|
-
*/
|
|
423
|
-
readonly agents: AgentNamespace;
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* Session operations (messaging)
|
|
427
|
-
*/
|
|
428
|
-
readonly sessions: SessionNamespace;
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
* Presentation operations (UI integration)
|
|
432
|
-
*/
|
|
433
|
-
readonly presentations: PresentationNamespace;
|
|
320
|
+
readonly container: ContainerNamespace;
|
|
321
|
+
readonly image: ImageNamespace;
|
|
322
|
+
readonly agent: AgentNamespace;
|
|
323
|
+
readonly session: SessionNamespace;
|
|
324
|
+
readonly presentation: PresentationNamespace;
|
|
434
325
|
|
|
435
326
|
// ==================== Event Subscription ====================
|
|
436
327
|
|
|
437
|
-
/**
|
|
438
|
-
* Subscribe to specific event type
|
|
439
|
-
*/
|
|
440
328
|
on<T extends string>(type: T, handler: BusEventHandler<BusEvent & { type: T }>): Unsubscribe;
|
|
441
|
-
|
|
442
|
-
/**
|
|
443
|
-
* Subscribe to all events
|
|
444
|
-
*/
|
|
445
329
|
onAny(handler: BusEventHandler): Unsubscribe;
|
|
446
|
-
|
|
447
|
-
/**
|
|
448
|
-
* Subscribe to session events
|
|
449
|
-
*/
|
|
450
330
|
subscribe(sessionId: string): void;
|
|
451
331
|
|
|
452
332
|
// ==================== Lifecycle ====================
|
|
453
333
|
|
|
334
|
+
disconnect(): Promise<void>;
|
|
335
|
+
dispose(): Promise<void>;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// ============================================================================
|
|
339
|
+
// Fluent Builder Interface
|
|
340
|
+
// ============================================================================
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Options for connecting to a remote AgentX server
|
|
344
|
+
*/
|
|
345
|
+
export interface ConnectOptions {
|
|
346
|
+
/** Authentication headers */
|
|
347
|
+
headers?: MaybeAsync<Record<string, string>>;
|
|
348
|
+
/** Business context injected into requests */
|
|
349
|
+
context?: MaybeAsync<Record<string, unknown>>;
|
|
350
|
+
/** Request timeout in ms (default: 30000) */
|
|
351
|
+
timeout?: number;
|
|
352
|
+
/** Auto reconnect on disconnect (default: true) */
|
|
353
|
+
autoReconnect?: boolean;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Configuration for serving as an AgentX server
|
|
358
|
+
*/
|
|
359
|
+
export interface ServeConfig {
|
|
360
|
+
/** Port to listen on (default: 5200) */
|
|
361
|
+
port?: number;
|
|
362
|
+
/** Host to bind to (default: "0.0.0.0") */
|
|
363
|
+
host?: string;
|
|
364
|
+
/** Existing HTTP server to attach to */
|
|
365
|
+
server?: unknown;
|
|
366
|
+
/** WebSocket path when attached (default: "/ws") */
|
|
367
|
+
wsPath?: string;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Server instance returned by serve()
|
|
372
|
+
*/
|
|
373
|
+
export interface AgentXServer {
|
|
374
|
+
listen(port?: number, host?: string): Promise<void>;
|
|
375
|
+
close(): Promise<void>;
|
|
376
|
+
dispose(): Promise<void>;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* AgentXBuilder — fluent API entry point
|
|
381
|
+
*
|
|
382
|
+
* Created by `createAgentX(platform?)`. The builder itself is an AgentX
|
|
383
|
+
* instance (local mode). Call `.connect()` to get a remote client,
|
|
384
|
+
* or `.serve()` to start a server.
|
|
385
|
+
*
|
|
386
|
+
* @example
|
|
387
|
+
* ```typescript
|
|
388
|
+
* const ax = createAgentX(node({ createDriver }))
|
|
389
|
+
*
|
|
390
|
+
* // Local use
|
|
391
|
+
* await ax.agent.create({ imageId: "..." })
|
|
392
|
+
*
|
|
393
|
+
* // Connect to remote server
|
|
394
|
+
* const client = await ax.connect("wss://...")
|
|
395
|
+
*
|
|
396
|
+
* // Serve as server
|
|
397
|
+
* const server = await ax.serve({ port: 3100 })
|
|
398
|
+
* ```
|
|
399
|
+
*/
|
|
400
|
+
export interface AgentXBuilder extends AgentX {
|
|
454
401
|
/**
|
|
455
|
-
*
|
|
402
|
+
* Connect to a remote AgentX server
|
|
456
403
|
*/
|
|
457
|
-
|
|
404
|
+
connect(serverUrl: string, options?: ConnectOptions): Promise<AgentX>;
|
|
458
405
|
|
|
459
406
|
/**
|
|
460
|
-
*
|
|
407
|
+
* Start serving as an AgentX server
|
|
461
408
|
*/
|
|
462
|
-
|
|
409
|
+
serve(config?: ServeConfig): Promise<AgentXServer>;
|
|
463
410
|
}
|
|
464
411
|
|
|
465
412
|
// ============================================================================
|