agentxjs 1.9.4-dev → 1.9.6-dev

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/index.d.ts CHANGED
@@ -1,3 +1,437 @@
1
+ import { BusEvent, Unsubscribe, EventBus, BusEventHandler } from '@agentxjs/core/event';
2
+
3
+ /**
4
+ * Presentation Types
5
+ *
6
+ * UI-friendly data model aggregated from stream events.
7
+ * This implements the Presentation Model pattern.
8
+ */
9
+ /**
10
+ * Text block
11
+ */
12
+ interface TextBlock {
13
+ type: "text";
14
+ content: string;
15
+ }
16
+ /**
17
+ * Tool block - represents a tool call and its result
18
+ */
19
+ interface ToolBlock {
20
+ type: "tool";
21
+ toolUseId: string;
22
+ toolName: string;
23
+ toolInput: Record<string, unknown>;
24
+ toolResult?: string;
25
+ status: "pending" | "running" | "completed" | "error";
26
+ }
27
+ /**
28
+ * Image block
29
+ */
30
+ interface ImageBlock {
31
+ type: "image";
32
+ url: string;
33
+ alt?: string;
34
+ }
35
+ /**
36
+ * All block types
37
+ */
38
+ type Block = TextBlock | ToolBlock | ImageBlock;
39
+ /**
40
+ * User conversation
41
+ */
42
+ interface UserConversation {
43
+ role: "user";
44
+ blocks: Block[];
45
+ }
46
+ /**
47
+ * Assistant conversation
48
+ */
49
+ interface AssistantConversation {
50
+ role: "assistant";
51
+ blocks: Block[];
52
+ isStreaming: boolean;
53
+ }
54
+ /**
55
+ * Error conversation
56
+ */
57
+ interface ErrorConversation {
58
+ role: "error";
59
+ message: string;
60
+ }
61
+ /**
62
+ * All conversation types
63
+ */
64
+ type Conversation = UserConversation | AssistantConversation | ErrorConversation;
65
+ /**
66
+ * Presentation state - the complete UI state
67
+ */
68
+ interface PresentationState {
69
+ /**
70
+ * All completed conversations
71
+ */
72
+ conversations: Conversation[];
73
+ /**
74
+ * Current streaming conversation (null if not streaming)
75
+ */
76
+ streaming: AssistantConversation | null;
77
+ /**
78
+ * Current status
79
+ */
80
+ status: "idle" | "thinking" | "responding" | "executing";
81
+ }
82
+ /**
83
+ * Initial presentation state
84
+ */
85
+ declare const initialPresentationState: PresentationState;
86
+
87
+ /**
88
+ * Presentation Reducer
89
+ *
90
+ * Aggregates stream events into PresentationState.
91
+ * Pure function: (state, event) => newState
92
+ */
93
+
94
+ /**
95
+ * Reduce a stream event into presentation state
96
+ */
97
+ declare function presentationReducer(state: PresentationState, event: BusEvent): PresentationState;
98
+ /**
99
+ * Add a user conversation to state
100
+ */
101
+ declare function addUserConversation(state: PresentationState, content: string): PresentationState;
102
+ /**
103
+ * Create initial state
104
+ */
105
+ declare function createInitialState(): PresentationState;
106
+
107
+ /**
108
+ * Presentation Class
109
+ *
110
+ * High-level API for UI integration.
111
+ * Wraps AgentX client and provides presentation state management.
112
+ */
113
+
114
+ /**
115
+ * Presentation update handler
116
+ */
117
+ type PresentationUpdateHandler = (state: PresentationState) => void;
118
+ /**
119
+ * Presentation error handler
120
+ */
121
+ type PresentationErrorHandler = (error: Error) => void;
122
+ /**
123
+ * Presentation options
124
+ */
125
+ interface PresentationOptions {
126
+ /**
127
+ * Called on every state update
128
+ */
129
+ onUpdate?: PresentationUpdateHandler;
130
+ /**
131
+ * Called on errors
132
+ */
133
+ onError?: PresentationErrorHandler;
134
+ }
135
+ /**
136
+ * Presentation - UI-friendly wrapper for AgentX
137
+ */
138
+ declare class Presentation {
139
+ private agentx;
140
+ private agentId;
141
+ private state;
142
+ private updateHandlers;
143
+ private errorHandlers;
144
+ private eventUnsubscribe;
145
+ constructor(agentx: AgentX, agentId: string, options?: PresentationOptions);
146
+ /**
147
+ * Get current state
148
+ */
149
+ getState(): PresentationState;
150
+ /**
151
+ * Subscribe to state updates
152
+ */
153
+ onUpdate(handler: PresentationUpdateHandler): Unsubscribe;
154
+ /**
155
+ * Subscribe to errors
156
+ */
157
+ onError(handler: PresentationErrorHandler): Unsubscribe;
158
+ /**
159
+ * Send a message
160
+ */
161
+ send(content: string): Promise<void>;
162
+ /**
163
+ * Interrupt current response
164
+ */
165
+ interrupt(): Promise<void>;
166
+ /**
167
+ * Reset state
168
+ */
169
+ reset(): void;
170
+ /**
171
+ * Dispose and cleanup
172
+ */
173
+ dispose(): void;
174
+ private subscribeToEvents;
175
+ private notify;
176
+ private notifyError;
177
+ }
178
+
179
+ /**
180
+ * AgentX Client SDK Types
181
+ */
182
+
183
+ /**
184
+ * Static or dynamic value
185
+ */
186
+ type MaybeAsync<T> = T | (() => T) | (() => Promise<T>);
187
+ /**
188
+ * AgentX client configuration
189
+ */
190
+ interface AgentXConfig {
191
+ /**
192
+ * WebSocket server URL
193
+ */
194
+ serverUrl: string;
195
+ /**
196
+ * Headers for authentication (static or dynamic)
197
+ * In Node.js: sent during WebSocket handshake
198
+ * In browsers: sent as first auth message (WebSocket API limitation)
199
+ */
200
+ headers?: MaybeAsync<Record<string, string>>;
201
+ /**
202
+ * Business context injected into all requests
203
+ * Useful for passing userId, tenantId, permissions, etc.
204
+ */
205
+ context?: MaybeAsync<Record<string, unknown>>;
206
+ /**
207
+ * Request timeout in milliseconds (default: 30000)
208
+ */
209
+ timeout?: number;
210
+ /**
211
+ * Enable debug logging
212
+ */
213
+ debug?: boolean;
214
+ /**
215
+ * Auto reconnect on connection loss (default: true)
216
+ */
217
+ autoReconnect?: boolean;
218
+ }
219
+ /**
220
+ * Agent info returned from server
221
+ */
222
+ interface AgentInfo {
223
+ agentId: string;
224
+ imageId: string;
225
+ containerId: string;
226
+ sessionId: string;
227
+ lifecycle?: string;
228
+ }
229
+ /**
230
+ * Image record from server
231
+ */
232
+ interface ImageRecord {
233
+ imageId: string;
234
+ containerId: string;
235
+ sessionId: string;
236
+ name?: string;
237
+ description?: string;
238
+ systemPrompt?: string;
239
+ createdAt: number;
240
+ updatedAt: number;
241
+ }
242
+ /**
243
+ * Container info
244
+ */
245
+ interface ContainerInfo {
246
+ containerId: string;
247
+ }
248
+ /**
249
+ * Base response with requestId
250
+ */
251
+ interface BaseResponse {
252
+ requestId: string;
253
+ error?: string;
254
+ }
255
+ /**
256
+ * Agent create response
257
+ */
258
+ interface AgentCreateResponse extends BaseResponse {
259
+ agentId: string;
260
+ imageId: string;
261
+ containerId: string;
262
+ sessionId: string;
263
+ }
264
+ /**
265
+ * Agent get response
266
+ */
267
+ interface AgentGetResponse extends BaseResponse {
268
+ agent: AgentInfo | null;
269
+ exists: boolean;
270
+ }
271
+ /**
272
+ * Agent list response
273
+ */
274
+ interface AgentListResponse extends BaseResponse {
275
+ agents: AgentInfo[];
276
+ }
277
+ /**
278
+ * Image create response
279
+ */
280
+ interface ImageCreateResponse extends BaseResponse {
281
+ record: ImageRecord;
282
+ __subscriptions?: string[];
283
+ }
284
+ /**
285
+ * Image get response
286
+ */
287
+ interface ImageGetResponse extends BaseResponse {
288
+ record: ImageRecord | null;
289
+ __subscriptions?: string[];
290
+ }
291
+ /**
292
+ * Image list response
293
+ */
294
+ interface ImageListResponse extends BaseResponse {
295
+ records: ImageRecord[];
296
+ __subscriptions?: string[];
297
+ }
298
+ /**
299
+ * Container create response
300
+ */
301
+ interface ContainerCreateResponse extends BaseResponse {
302
+ containerId: string;
303
+ }
304
+ /**
305
+ * Container get response
306
+ */
307
+ interface ContainerGetResponse extends BaseResponse {
308
+ containerId: string;
309
+ exists: boolean;
310
+ }
311
+ /**
312
+ * Container list response
313
+ */
314
+ interface ContainerListResponse extends BaseResponse {
315
+ containerIds: string[];
316
+ }
317
+ /**
318
+ * Message send response
319
+ */
320
+ interface MessageSendResponse extends BaseResponse {
321
+ agentId: string;
322
+ }
323
+ /**
324
+ * AgentX Client SDK
325
+ */
326
+ interface AgentX {
327
+ /**
328
+ * Check if connected to server
329
+ */
330
+ readonly connected: boolean;
331
+ /**
332
+ * Event bus for subscribing to events
333
+ */
334
+ readonly events: EventBus;
335
+ /**
336
+ * Create a new agent
337
+ */
338
+ createAgent(params: {
339
+ imageId: string;
340
+ agentId?: string;
341
+ }): Promise<AgentCreateResponse>;
342
+ /**
343
+ * Get agent by ID
344
+ */
345
+ getAgent(agentId: string): Promise<AgentGetResponse>;
346
+ /**
347
+ * List agents
348
+ */
349
+ listAgents(containerId?: string): Promise<AgentListResponse>;
350
+ /**
351
+ * Destroy an agent
352
+ */
353
+ destroyAgent(agentId: string): Promise<BaseResponse>;
354
+ /**
355
+ * Send message to agent
356
+ */
357
+ sendMessage(agentId: string, content: string | unknown[]): Promise<MessageSendResponse>;
358
+ /**
359
+ * Interrupt agent
360
+ */
361
+ interrupt(agentId: string): Promise<BaseResponse>;
362
+ /**
363
+ * Create a new image
364
+ */
365
+ createImage(params: {
366
+ containerId: string;
367
+ name?: string;
368
+ description?: string;
369
+ systemPrompt?: string;
370
+ mcpServers?: Record<string, unknown>;
371
+ }): Promise<ImageCreateResponse>;
372
+ /**
373
+ * Get image by ID
374
+ */
375
+ getImage(imageId: string): Promise<ImageGetResponse>;
376
+ /**
377
+ * List images
378
+ */
379
+ listImages(containerId?: string): Promise<ImageListResponse>;
380
+ /**
381
+ * Delete image
382
+ */
383
+ deleteImage(imageId: string): Promise<BaseResponse>;
384
+ /**
385
+ * Create or get container
386
+ */
387
+ createContainer(containerId: string): Promise<ContainerCreateResponse>;
388
+ /**
389
+ * Get container
390
+ */
391
+ getContainer(containerId: string): Promise<ContainerGetResponse>;
392
+ /**
393
+ * List containers
394
+ */
395
+ listContainers(): Promise<ContainerListResponse>;
396
+ /**
397
+ * Subscribe to specific event type
398
+ */
399
+ on<T extends string>(type: T, handler: BusEventHandler<BusEvent & {
400
+ type: T;
401
+ }>): Unsubscribe;
402
+ /**
403
+ * Subscribe to all events
404
+ */
405
+ onAny(handler: BusEventHandler): Unsubscribe;
406
+ /**
407
+ * Subscribe to session events
408
+ */
409
+ subscribe(sessionId: string): void;
410
+ /**
411
+ * Create a presentation for UI integration
412
+ *
413
+ * @example
414
+ * ```typescript
415
+ * const presentation = agentx.presentation(agentId);
416
+ *
417
+ * presentation.onUpdate((state) => {
418
+ * render(state.conversations);
419
+ * });
420
+ *
421
+ * await presentation.send("Hello!");
422
+ * ```
423
+ */
424
+ presentation(agentId: string, options?: PresentationOptions): Presentation;
425
+ /**
426
+ * Disconnect from server
427
+ */
428
+ disconnect(): Promise<void>;
429
+ /**
430
+ * Dispose and cleanup
431
+ */
432
+ dispose(): Promise<void>;
433
+ }
434
+
1
435
  /**
2
436
  * agentxjs - AgentX Client SDK
3
437
  *
@@ -53,14 +487,13 @@
53
487
  * });
54
488
  * ```
55
489
  */
56
- import type { AgentX, AgentXConfig } from "./types";
490
+
57
491
  /**
58
492
  * Create an AgentX client
59
493
  *
60
494
  * @param config - Client configuration
61
495
  * @returns Connected AgentX client
62
496
  */
63
- export declare function createAgentX(config: AgentXConfig): Promise<AgentX>;
64
- export type { AgentX, AgentXConfig, MaybeAsync, AgentInfo, ImageRecord, ContainerInfo, AgentCreateResponse, AgentGetResponse, AgentListResponse, ImageCreateResponse, ImageGetResponse, ImageListResponse, ContainerCreateResponse, ContainerGetResponse, ContainerListResponse, MessageSendResponse, BaseResponse, } from "./types";
65
- export type { Block, TextBlock, ToolBlock, ImageBlock, Conversation, UserConversation, AssistantConversation, ErrorConversation, PresentationState, PresentationOptions, PresentationUpdateHandler, PresentationErrorHandler, } from "./presentation";
66
- export { Presentation, presentationReducer, addUserConversation, createInitialState, initialPresentationState, } from "./presentation";
497
+ declare function createAgentX(config: AgentXConfig): Promise<AgentX>;
498
+
499
+ export { type AgentCreateResponse, type AgentGetResponse, type AgentInfo, type AgentListResponse, type AgentX, type AgentXConfig, type AssistantConversation, type BaseResponse, type Block, type ContainerCreateResponse, type ContainerGetResponse, type ContainerInfo, type ContainerListResponse, type Conversation, type ErrorConversation, type ImageBlock, type ImageCreateResponse, type ImageGetResponse, type ImageListResponse, type ImageRecord, type MaybeAsync, type MessageSendResponse, Presentation, type PresentationErrorHandler, type PresentationOptions, type PresentationState, type PresentationUpdateHandler, type TextBlock, type ToolBlock, type UserConversation, addUserConversation, createAgentX, createInitialState, initialPresentationState, presentationReducer };