agentxjs 1.9.5-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 +499 -0
- package/dist/index.js +632 -0
- package/dist/index.js.map +1 -0
- package/package.json +9 -4
- package/build.ts +0 -26
- package/tsconfig.json +0 -11
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,499 @@
|
|
|
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
|
+
|
|
435
|
+
/**
|
|
436
|
+
* agentxjs - AgentX Client SDK
|
|
437
|
+
*
|
|
438
|
+
* Connect to AgentX servers from Node.js and browsers.
|
|
439
|
+
*
|
|
440
|
+
* @example
|
|
441
|
+
* ```typescript
|
|
442
|
+
* import { createAgentX } from "agentxjs";
|
|
443
|
+
*
|
|
444
|
+
* // Connect to server
|
|
445
|
+
* const agentx = await createAgentX({
|
|
446
|
+
* serverUrl: "ws://localhost:5200",
|
|
447
|
+
* headers: { Authorization: "Bearer sk-xxx" },
|
|
448
|
+
* context: { userId: "123", tenantId: "abc" },
|
|
449
|
+
* });
|
|
450
|
+
*
|
|
451
|
+
* // Create container and image
|
|
452
|
+
* await agentx.createContainer("my-container");
|
|
453
|
+
* const { record: image } = await agentx.createImage({
|
|
454
|
+
* containerId: "my-container",
|
|
455
|
+
* name: "Assistant",
|
|
456
|
+
* systemPrompt: "You are a helpful assistant",
|
|
457
|
+
* });
|
|
458
|
+
*
|
|
459
|
+
* // Create agent and send message
|
|
460
|
+
* const { agentId } = await agentx.createAgent({ imageId: image.imageId });
|
|
461
|
+
*
|
|
462
|
+
* // Subscribe to events
|
|
463
|
+
* agentx.on("text_delta", (event) => {
|
|
464
|
+
* process.stdout.write(event.data.text);
|
|
465
|
+
* });
|
|
466
|
+
*
|
|
467
|
+
* agentx.on("assistant_message", (event) => {
|
|
468
|
+
* console.log("Complete:", event.data.content);
|
|
469
|
+
* });
|
|
470
|
+
*
|
|
471
|
+
* // Send message
|
|
472
|
+
* await agentx.sendMessage(agentId, "Hello!");
|
|
473
|
+
*
|
|
474
|
+
* // Cleanup
|
|
475
|
+
* await agentx.dispose();
|
|
476
|
+
* ```
|
|
477
|
+
*
|
|
478
|
+
* @example Dynamic headers and context
|
|
479
|
+
* ```typescript
|
|
480
|
+
* const agentx = await createAgentX({
|
|
481
|
+
* serverUrl: "ws://localhost:5200",
|
|
482
|
+
* headers: () => ({ Authorization: `Bearer ${getToken()}` }),
|
|
483
|
+
* context: async () => ({
|
|
484
|
+
* userId: await getUserId(),
|
|
485
|
+
* permissions: await getPermissions(),
|
|
486
|
+
* }),
|
|
487
|
+
* });
|
|
488
|
+
* ```
|
|
489
|
+
*/
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Create an AgentX client
|
|
493
|
+
*
|
|
494
|
+
* @param config - Client configuration
|
|
495
|
+
* @returns Connected AgentX client
|
|
496
|
+
*/
|
|
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 };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
// src/RemoteClient.ts
|
|
2
|
+
import { EventBusImpl } from "@agentxjs/core/event";
|
|
3
|
+
import { RpcClient } from "@agentxjs/core/network";
|
|
4
|
+
|
|
5
|
+
// ../../node_modules/commonxjs/dist/logger/index.js
|
|
6
|
+
var ConsoleLogger = class _ConsoleLogger {
|
|
7
|
+
name;
|
|
8
|
+
level;
|
|
9
|
+
colors;
|
|
10
|
+
timestamps;
|
|
11
|
+
static COLORS = {
|
|
12
|
+
DEBUG: "\x1B[36m",
|
|
13
|
+
INFO: "\x1B[32m",
|
|
14
|
+
WARN: "\x1B[33m",
|
|
15
|
+
ERROR: "\x1B[31m",
|
|
16
|
+
RESET: "\x1B[0m"
|
|
17
|
+
};
|
|
18
|
+
constructor(name, options = {}) {
|
|
19
|
+
this.name = name;
|
|
20
|
+
this.level = options.level ?? "info";
|
|
21
|
+
this.colors = options.colors ?? this.isNodeEnvironment();
|
|
22
|
+
this.timestamps = options.timestamps ?? true;
|
|
23
|
+
}
|
|
24
|
+
debug(message, context) {
|
|
25
|
+
if (this.isDebugEnabled()) {
|
|
26
|
+
this.log("DEBUG", message, context);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
info(message, context) {
|
|
30
|
+
if (this.isInfoEnabled()) {
|
|
31
|
+
this.log("INFO", message, context);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
warn(message, context) {
|
|
35
|
+
if (this.isWarnEnabled()) {
|
|
36
|
+
this.log("WARN", message, context);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
error(message, context) {
|
|
40
|
+
if (this.isErrorEnabled()) {
|
|
41
|
+
if (message instanceof Error) {
|
|
42
|
+
this.log("ERROR", message.message, { ...context, stack: message.stack });
|
|
43
|
+
} else {
|
|
44
|
+
this.log("ERROR", message, context);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
isDebugEnabled() {
|
|
49
|
+
return this.getLevelValue(this.level) <= this.getLevelValue("debug");
|
|
50
|
+
}
|
|
51
|
+
isInfoEnabled() {
|
|
52
|
+
return this.getLevelValue(this.level) <= this.getLevelValue("info");
|
|
53
|
+
}
|
|
54
|
+
isWarnEnabled() {
|
|
55
|
+
return this.getLevelValue(this.level) <= this.getLevelValue("warn");
|
|
56
|
+
}
|
|
57
|
+
isErrorEnabled() {
|
|
58
|
+
return this.getLevelValue(this.level) <= this.getLevelValue("error");
|
|
59
|
+
}
|
|
60
|
+
getLevelValue(level) {
|
|
61
|
+
const levels = {
|
|
62
|
+
debug: 0,
|
|
63
|
+
info: 1,
|
|
64
|
+
warn: 2,
|
|
65
|
+
error: 3,
|
|
66
|
+
silent: 4
|
|
67
|
+
};
|
|
68
|
+
return levels[level];
|
|
69
|
+
}
|
|
70
|
+
log(level, message, context) {
|
|
71
|
+
const parts = [];
|
|
72
|
+
if (this.timestamps) {
|
|
73
|
+
parts.push((/* @__PURE__ */ new Date()).toISOString());
|
|
74
|
+
}
|
|
75
|
+
if (this.colors) {
|
|
76
|
+
const color = _ConsoleLogger.COLORS[level];
|
|
77
|
+
parts.push(`${color}${level.padEnd(5)}${_ConsoleLogger.COLORS.RESET}`);
|
|
78
|
+
} else {
|
|
79
|
+
parts.push(level.padEnd(5));
|
|
80
|
+
}
|
|
81
|
+
parts.push(`[${this.name}]`);
|
|
82
|
+
parts.push(message);
|
|
83
|
+
const logLine = parts.join(" ");
|
|
84
|
+
const consoleMethod = this.getConsoleMethod(level);
|
|
85
|
+
if (context && Object.keys(context).length > 0) {
|
|
86
|
+
consoleMethod(logLine, context);
|
|
87
|
+
} else {
|
|
88
|
+
consoleMethod(logLine);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
getConsoleMethod(level) {
|
|
92
|
+
switch (level) {
|
|
93
|
+
case "DEBUG":
|
|
94
|
+
return console.debug.bind(console);
|
|
95
|
+
case "INFO":
|
|
96
|
+
return console.info.bind(console);
|
|
97
|
+
case "WARN":
|
|
98
|
+
return console.warn.bind(console);
|
|
99
|
+
case "ERROR":
|
|
100
|
+
return console.error.bind(console);
|
|
101
|
+
default:
|
|
102
|
+
return console.log.bind(console);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
isNodeEnvironment() {
|
|
106
|
+
return typeof process !== "undefined" && process.versions?.node !== void 0;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
var externalFactory = null;
|
|
110
|
+
var factoryVersion = 0;
|
|
111
|
+
var LoggerFactoryImpl = class {
|
|
112
|
+
static loggers = /* @__PURE__ */ new Map();
|
|
113
|
+
static config = {
|
|
114
|
+
defaultLevel: "info"
|
|
115
|
+
};
|
|
116
|
+
static getLogger(nameOrClass) {
|
|
117
|
+
const name = typeof nameOrClass === "string" ? nameOrClass : nameOrClass.name;
|
|
118
|
+
if (this.loggers.has(name)) {
|
|
119
|
+
return this.loggers.get(name);
|
|
120
|
+
}
|
|
121
|
+
const lazyLogger = this.createLazyLogger(name);
|
|
122
|
+
this.loggers.set(name, lazyLogger);
|
|
123
|
+
return lazyLogger;
|
|
124
|
+
}
|
|
125
|
+
static configure(config) {
|
|
126
|
+
this.config = { ...this.config, ...config };
|
|
127
|
+
}
|
|
128
|
+
static reset() {
|
|
129
|
+
this.loggers.clear();
|
|
130
|
+
this.config = { defaultLevel: "info" };
|
|
131
|
+
externalFactory = null;
|
|
132
|
+
factoryVersion++;
|
|
133
|
+
}
|
|
134
|
+
static createLazyLogger(name) {
|
|
135
|
+
let realLogger = null;
|
|
136
|
+
let loggerVersion = -1;
|
|
137
|
+
const getRealLogger = () => {
|
|
138
|
+
if (!realLogger || loggerVersion !== factoryVersion) {
|
|
139
|
+
realLogger = this.createLogger(name);
|
|
140
|
+
loggerVersion = factoryVersion;
|
|
141
|
+
}
|
|
142
|
+
return realLogger;
|
|
143
|
+
};
|
|
144
|
+
return {
|
|
145
|
+
name,
|
|
146
|
+
level: this.config.defaultLevel || "info",
|
|
147
|
+
debug: (message, context) => getRealLogger().debug(message, context),
|
|
148
|
+
info: (message, context) => getRealLogger().info(message, context),
|
|
149
|
+
warn: (message, context) => getRealLogger().warn(message, context),
|
|
150
|
+
error: (message, context) => getRealLogger().error(message, context),
|
|
151
|
+
isDebugEnabled: () => getRealLogger().isDebugEnabled(),
|
|
152
|
+
isInfoEnabled: () => getRealLogger().isInfoEnabled(),
|
|
153
|
+
isWarnEnabled: () => getRealLogger().isWarnEnabled(),
|
|
154
|
+
isErrorEnabled: () => getRealLogger().isErrorEnabled()
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
static createLogger(name) {
|
|
158
|
+
if (externalFactory) {
|
|
159
|
+
return externalFactory.getLogger(name);
|
|
160
|
+
}
|
|
161
|
+
if (this.config.defaultImplementation) {
|
|
162
|
+
return this.config.defaultImplementation(name);
|
|
163
|
+
}
|
|
164
|
+
return new ConsoleLogger(name, {
|
|
165
|
+
level: this.config.defaultLevel,
|
|
166
|
+
...this.config.consoleOptions
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
function createLogger(name) {
|
|
171
|
+
return LoggerFactoryImpl.getLogger(name);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// src/presentation/types.ts
|
|
175
|
+
var initialPresentationState = {
|
|
176
|
+
conversations: [],
|
|
177
|
+
streaming: null,
|
|
178
|
+
status: "idle"
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// src/presentation/reducer.ts
|
|
182
|
+
function presentationReducer(state, event) {
|
|
183
|
+
switch (event.type) {
|
|
184
|
+
case "message_start":
|
|
185
|
+
return handleMessageStart(state, event.data);
|
|
186
|
+
case "text_delta":
|
|
187
|
+
return handleTextDelta(state, event.data);
|
|
188
|
+
case "tool_use_start":
|
|
189
|
+
return handleToolUseStart(state, event.data);
|
|
190
|
+
case "input_json_delta":
|
|
191
|
+
return handleInputJsonDelta(state, event.data);
|
|
192
|
+
case "tool_result":
|
|
193
|
+
return handleToolResult(state, event.data);
|
|
194
|
+
case "message_stop":
|
|
195
|
+
return handleMessageStop(state, event.data);
|
|
196
|
+
case "error":
|
|
197
|
+
return handleError(state, event.data);
|
|
198
|
+
default:
|
|
199
|
+
return state;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function handleMessageStart(state, _data) {
|
|
203
|
+
const streaming = {
|
|
204
|
+
role: "assistant",
|
|
205
|
+
blocks: [],
|
|
206
|
+
isStreaming: true
|
|
207
|
+
};
|
|
208
|
+
return {
|
|
209
|
+
...state,
|
|
210
|
+
streaming,
|
|
211
|
+
status: "thinking"
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function handleTextDelta(state, data) {
|
|
215
|
+
if (!state.streaming) {
|
|
216
|
+
return state;
|
|
217
|
+
}
|
|
218
|
+
const blocks = [...state.streaming.blocks];
|
|
219
|
+
const lastBlock = blocks[blocks.length - 1];
|
|
220
|
+
if (lastBlock && lastBlock.type === "text") {
|
|
221
|
+
blocks[blocks.length - 1] = {
|
|
222
|
+
...lastBlock,
|
|
223
|
+
content: lastBlock.content + data.text
|
|
224
|
+
};
|
|
225
|
+
} else {
|
|
226
|
+
blocks.push({
|
|
227
|
+
type: "text",
|
|
228
|
+
content: data.text
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
...state,
|
|
233
|
+
streaming: {
|
|
234
|
+
...state.streaming,
|
|
235
|
+
blocks
|
|
236
|
+
},
|
|
237
|
+
status: "responding"
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
function handleToolUseStart(state, data) {
|
|
241
|
+
if (!state.streaming) {
|
|
242
|
+
return state;
|
|
243
|
+
}
|
|
244
|
+
const toolBlock = {
|
|
245
|
+
type: "tool",
|
|
246
|
+
toolUseId: data.toolUseId,
|
|
247
|
+
toolName: data.toolName,
|
|
248
|
+
toolInput: {},
|
|
249
|
+
status: "pending"
|
|
250
|
+
};
|
|
251
|
+
return {
|
|
252
|
+
...state,
|
|
253
|
+
streaming: {
|
|
254
|
+
...state.streaming,
|
|
255
|
+
blocks: [...state.streaming.blocks, toolBlock]
|
|
256
|
+
},
|
|
257
|
+
status: "executing"
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
function handleInputJsonDelta(state, data) {
|
|
261
|
+
if (!state.streaming) {
|
|
262
|
+
return state;
|
|
263
|
+
}
|
|
264
|
+
const blocks = [...state.streaming.blocks];
|
|
265
|
+
const lastBlock = blocks[blocks.length - 1];
|
|
266
|
+
if (lastBlock && lastBlock.type === "tool") {
|
|
267
|
+
const currentInput = lastBlock._rawInput || "";
|
|
268
|
+
const newInput = currentInput + data.delta;
|
|
269
|
+
let toolInput = lastBlock.toolInput;
|
|
270
|
+
try {
|
|
271
|
+
toolInput = JSON.parse(newInput);
|
|
272
|
+
} catch {
|
|
273
|
+
}
|
|
274
|
+
blocks[blocks.length - 1] = {
|
|
275
|
+
...lastBlock,
|
|
276
|
+
toolInput,
|
|
277
|
+
_rawInput: newInput,
|
|
278
|
+
status: "running"
|
|
279
|
+
};
|
|
280
|
+
return {
|
|
281
|
+
...state,
|
|
282
|
+
streaming: {
|
|
283
|
+
...state.streaming,
|
|
284
|
+
blocks
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
return state;
|
|
289
|
+
}
|
|
290
|
+
function handleToolResult(state, data) {
|
|
291
|
+
if (!state.streaming) {
|
|
292
|
+
return state;
|
|
293
|
+
}
|
|
294
|
+
const blocks = state.streaming.blocks.map((block) => {
|
|
295
|
+
if (block.type === "tool" && block.toolUseId === data.toolUseId) {
|
|
296
|
+
return {
|
|
297
|
+
...block,
|
|
298
|
+
toolResult: data.result,
|
|
299
|
+
status: data.isError ? "error" : "completed"
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
return block;
|
|
303
|
+
});
|
|
304
|
+
return {
|
|
305
|
+
...state,
|
|
306
|
+
streaming: {
|
|
307
|
+
...state.streaming,
|
|
308
|
+
blocks
|
|
309
|
+
},
|
|
310
|
+
status: "responding"
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
function handleMessageStop(state, _data) {
|
|
314
|
+
if (!state.streaming) {
|
|
315
|
+
return state;
|
|
316
|
+
}
|
|
317
|
+
const completedConversation = {
|
|
318
|
+
...state.streaming,
|
|
319
|
+
isStreaming: false
|
|
320
|
+
};
|
|
321
|
+
return {
|
|
322
|
+
...state,
|
|
323
|
+
conversations: [...state.conversations, completedConversation],
|
|
324
|
+
streaming: null,
|
|
325
|
+
status: "idle"
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
function handleError(state, data) {
|
|
329
|
+
return {
|
|
330
|
+
...state,
|
|
331
|
+
conversations: [
|
|
332
|
+
...state.conversations,
|
|
333
|
+
{
|
|
334
|
+
role: "error",
|
|
335
|
+
message: data.message
|
|
336
|
+
}
|
|
337
|
+
],
|
|
338
|
+
streaming: null,
|
|
339
|
+
status: "idle"
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
function addUserConversation(state, content) {
|
|
343
|
+
return {
|
|
344
|
+
...state,
|
|
345
|
+
conversations: [
|
|
346
|
+
...state.conversations,
|
|
347
|
+
{
|
|
348
|
+
role: "user",
|
|
349
|
+
blocks: [{ type: "text", content }]
|
|
350
|
+
}
|
|
351
|
+
]
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
function createInitialState() {
|
|
355
|
+
return { ...initialPresentationState };
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// src/presentation/Presentation.ts
|
|
359
|
+
var Presentation = class {
|
|
360
|
+
agentx;
|
|
361
|
+
agentId;
|
|
362
|
+
state;
|
|
363
|
+
updateHandlers = /* @__PURE__ */ new Set();
|
|
364
|
+
errorHandlers = /* @__PURE__ */ new Set();
|
|
365
|
+
eventUnsubscribe = null;
|
|
366
|
+
constructor(agentx, agentId, options) {
|
|
367
|
+
this.agentx = agentx;
|
|
368
|
+
this.agentId = agentId;
|
|
369
|
+
this.state = createInitialState();
|
|
370
|
+
if (options?.onUpdate) {
|
|
371
|
+
this.updateHandlers.add(options.onUpdate);
|
|
372
|
+
}
|
|
373
|
+
if (options?.onError) {
|
|
374
|
+
this.errorHandlers.add(options.onError);
|
|
375
|
+
}
|
|
376
|
+
this.subscribeToEvents();
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Get current state
|
|
380
|
+
*/
|
|
381
|
+
getState() {
|
|
382
|
+
return this.state;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Subscribe to state updates
|
|
386
|
+
*/
|
|
387
|
+
onUpdate(handler) {
|
|
388
|
+
this.updateHandlers.add(handler);
|
|
389
|
+
handler(this.state);
|
|
390
|
+
return () => {
|
|
391
|
+
this.updateHandlers.delete(handler);
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Subscribe to errors
|
|
396
|
+
*/
|
|
397
|
+
onError(handler) {
|
|
398
|
+
this.errorHandlers.add(handler);
|
|
399
|
+
return () => {
|
|
400
|
+
this.errorHandlers.delete(handler);
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Send a message
|
|
405
|
+
*/
|
|
406
|
+
async send(content) {
|
|
407
|
+
this.state = addUserConversation(this.state, content);
|
|
408
|
+
this.notify();
|
|
409
|
+
try {
|
|
410
|
+
await this.agentx.sendMessage(this.agentId, content);
|
|
411
|
+
} catch (error) {
|
|
412
|
+
this.notifyError(error instanceof Error ? error : new Error(String(error)));
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Interrupt current response
|
|
417
|
+
*/
|
|
418
|
+
async interrupt() {
|
|
419
|
+
try {
|
|
420
|
+
await this.agentx.interrupt(this.agentId);
|
|
421
|
+
} catch (error) {
|
|
422
|
+
this.notifyError(error instanceof Error ? error : new Error(String(error)));
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Reset state
|
|
427
|
+
*/
|
|
428
|
+
reset() {
|
|
429
|
+
this.state = createInitialState();
|
|
430
|
+
this.notify();
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Dispose and cleanup
|
|
434
|
+
*/
|
|
435
|
+
dispose() {
|
|
436
|
+
if (this.eventUnsubscribe) {
|
|
437
|
+
this.eventUnsubscribe();
|
|
438
|
+
this.eventUnsubscribe = null;
|
|
439
|
+
}
|
|
440
|
+
this.updateHandlers.clear();
|
|
441
|
+
this.errorHandlers.clear();
|
|
442
|
+
}
|
|
443
|
+
// ==================== Private ====================
|
|
444
|
+
subscribeToEvents() {
|
|
445
|
+
this.eventUnsubscribe = this.agentx.onAny((event) => {
|
|
446
|
+
const eventWithContext = event;
|
|
447
|
+
const eventAgentId = eventWithContext.context?.agentId;
|
|
448
|
+
if (eventAgentId && eventAgentId !== this.agentId) {
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
const newState = presentationReducer(this.state, event);
|
|
452
|
+
if (newState !== this.state) {
|
|
453
|
+
this.state = newState;
|
|
454
|
+
this.notify();
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
notify() {
|
|
459
|
+
for (const handler of this.updateHandlers) {
|
|
460
|
+
try {
|
|
461
|
+
handler(this.state);
|
|
462
|
+
} catch (error) {
|
|
463
|
+
console.error("Presentation update handler error:", error);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
notifyError(error) {
|
|
468
|
+
for (const handler of this.errorHandlers) {
|
|
469
|
+
try {
|
|
470
|
+
handler(error);
|
|
471
|
+
} catch (e) {
|
|
472
|
+
console.error("Presentation error handler error:", e);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
// src/RemoteClient.ts
|
|
479
|
+
var logger = createLogger("agentx/RemoteClient");
|
|
480
|
+
var RemoteClient = class {
|
|
481
|
+
config;
|
|
482
|
+
eventBus;
|
|
483
|
+
rpcClient;
|
|
484
|
+
constructor(config) {
|
|
485
|
+
this.config = config;
|
|
486
|
+
this.eventBus = new EventBusImpl();
|
|
487
|
+
this.rpcClient = new RpcClient({
|
|
488
|
+
url: config.serverUrl,
|
|
489
|
+
timeout: config.timeout ?? 3e4,
|
|
490
|
+
autoReconnect: config.autoReconnect ?? true,
|
|
491
|
+
headers: config.headers,
|
|
492
|
+
debug: false
|
|
493
|
+
});
|
|
494
|
+
this.rpcClient.onStreamEvent((topic, event) => {
|
|
495
|
+
logger.debug("Received stream event", { topic, type: event.type });
|
|
496
|
+
this.eventBus.emit(event);
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
// ==================== Properties ====================
|
|
500
|
+
get connected() {
|
|
501
|
+
return this.rpcClient.connected;
|
|
502
|
+
}
|
|
503
|
+
get events() {
|
|
504
|
+
return this.eventBus;
|
|
505
|
+
}
|
|
506
|
+
// ==================== Connection ====================
|
|
507
|
+
async connect() {
|
|
508
|
+
await this.rpcClient.connect();
|
|
509
|
+
logger.info("Connected to server", { url: this.config.serverUrl });
|
|
510
|
+
}
|
|
511
|
+
async disconnect() {
|
|
512
|
+
this.rpcClient.disconnect();
|
|
513
|
+
logger.info("Disconnected from server");
|
|
514
|
+
}
|
|
515
|
+
async dispose() {
|
|
516
|
+
this.rpcClient.dispose();
|
|
517
|
+
this.eventBus.destroy();
|
|
518
|
+
logger.info("RemoteClient disposed");
|
|
519
|
+
}
|
|
520
|
+
// ==================== Container Operations ====================
|
|
521
|
+
async createContainer(containerId) {
|
|
522
|
+
const result = await this.rpcClient.call("container.create", {
|
|
523
|
+
containerId
|
|
524
|
+
});
|
|
525
|
+
return { ...result, requestId: "" };
|
|
526
|
+
}
|
|
527
|
+
async getContainer(containerId) {
|
|
528
|
+
const result = await this.rpcClient.call("container.get", {
|
|
529
|
+
containerId
|
|
530
|
+
});
|
|
531
|
+
return { ...result, requestId: "" };
|
|
532
|
+
}
|
|
533
|
+
async listContainers() {
|
|
534
|
+
const result = await this.rpcClient.call("container.list", {});
|
|
535
|
+
return { ...result, requestId: "" };
|
|
536
|
+
}
|
|
537
|
+
// ==================== Image Operations ====================
|
|
538
|
+
async createImage(params) {
|
|
539
|
+
const result = await this.rpcClient.call("image.create", params);
|
|
540
|
+
if (result.__subscriptions) {
|
|
541
|
+
for (const sessionId of result.__subscriptions) {
|
|
542
|
+
this.subscribe(sessionId);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
return { ...result, requestId: "" };
|
|
546
|
+
}
|
|
547
|
+
async getImage(imageId) {
|
|
548
|
+
const result = await this.rpcClient.call("image.get", { imageId });
|
|
549
|
+
if (result.__subscriptions) {
|
|
550
|
+
for (const sessionId of result.__subscriptions) {
|
|
551
|
+
this.subscribe(sessionId);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return { ...result, requestId: "" };
|
|
555
|
+
}
|
|
556
|
+
async listImages(containerId) {
|
|
557
|
+
const result = await this.rpcClient.call("image.list", { containerId });
|
|
558
|
+
if (result.__subscriptions) {
|
|
559
|
+
for (const sessionId of result.__subscriptions) {
|
|
560
|
+
this.subscribe(sessionId);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
return { ...result, requestId: "" };
|
|
564
|
+
}
|
|
565
|
+
async deleteImage(imageId) {
|
|
566
|
+
const result = await this.rpcClient.call("image.delete", { imageId });
|
|
567
|
+
return { ...result, requestId: "" };
|
|
568
|
+
}
|
|
569
|
+
// ==================== Agent Operations ====================
|
|
570
|
+
async createAgent(params) {
|
|
571
|
+
const result = await this.rpcClient.call("image.run", {
|
|
572
|
+
imageId: params.imageId,
|
|
573
|
+
agentId: params.agentId
|
|
574
|
+
});
|
|
575
|
+
return { ...result, requestId: "" };
|
|
576
|
+
}
|
|
577
|
+
async getAgent(agentId) {
|
|
578
|
+
const result = await this.rpcClient.call("agent.get", { agentId });
|
|
579
|
+
return { ...result, requestId: "" };
|
|
580
|
+
}
|
|
581
|
+
async listAgents(containerId) {
|
|
582
|
+
const result = await this.rpcClient.call("agent.list", { containerId });
|
|
583
|
+
return { ...result, requestId: "" };
|
|
584
|
+
}
|
|
585
|
+
async destroyAgent(agentId) {
|
|
586
|
+
const result = await this.rpcClient.call("agent.destroy", { agentId });
|
|
587
|
+
return { ...result, requestId: "" };
|
|
588
|
+
}
|
|
589
|
+
// ==================== Message Operations ====================
|
|
590
|
+
async sendMessage(agentId, content) {
|
|
591
|
+
const result = await this.rpcClient.call("message.send", {
|
|
592
|
+
agentId,
|
|
593
|
+
content
|
|
594
|
+
});
|
|
595
|
+
return { ...result, requestId: "" };
|
|
596
|
+
}
|
|
597
|
+
async interrupt(agentId) {
|
|
598
|
+
const result = await this.rpcClient.call("agent.interrupt", { agentId });
|
|
599
|
+
return { ...result, requestId: "" };
|
|
600
|
+
}
|
|
601
|
+
// ==================== Event Subscription ====================
|
|
602
|
+
on(type, handler) {
|
|
603
|
+
return this.eventBus.on(type, handler);
|
|
604
|
+
}
|
|
605
|
+
onAny(handler) {
|
|
606
|
+
return this.eventBus.onAny(handler);
|
|
607
|
+
}
|
|
608
|
+
subscribe(sessionId) {
|
|
609
|
+
this.rpcClient.subscribe(sessionId);
|
|
610
|
+
logger.debug("Subscribed to session", { sessionId });
|
|
611
|
+
}
|
|
612
|
+
// ==================== Presentation ====================
|
|
613
|
+
presentation(agentId, options) {
|
|
614
|
+
return new Presentation(this, agentId, options);
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
// src/index.ts
|
|
619
|
+
async function createAgentX(config) {
|
|
620
|
+
const client = new RemoteClient(config);
|
|
621
|
+
await client.connect();
|
|
622
|
+
return client;
|
|
623
|
+
}
|
|
624
|
+
export {
|
|
625
|
+
Presentation,
|
|
626
|
+
addUserConversation,
|
|
627
|
+
createAgentX,
|
|
628
|
+
createInitialState,
|
|
629
|
+
initialPresentationState,
|
|
630
|
+
presentationReducer
|
|
631
|
+
};
|
|
632
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/RemoteClient.ts","../../../node_modules/commonxjs/dist/src/logger/ConsoleLogger.ts","../../../node_modules/commonxjs/dist/src/logger/LoggerFactoryImpl.ts","../src/presentation/types.ts","../src/presentation/reducer.ts","../src/presentation/Presentation.ts","../src/index.ts"],"sourcesContent":["/**\n * RemoteClient - AgentX client for remote server\n *\n * Uses RpcClient from @agentxjs/core/network for JSON-RPC communication.\n * This class focuses on business logic, not protocol details.\n */\n\nimport type { BusEvent, EventBus, BusEventHandler, Unsubscribe } from \"@agentxjs/core/event\";\nimport { EventBusImpl } from \"@agentxjs/core/event\";\nimport { RpcClient, type RpcMethod } from \"@agentxjs/core/network\";\nimport { createLogger } from \"commonxjs/logger\";\nimport type {\n AgentX,\n AgentXConfig,\n AgentCreateResponse,\n AgentGetResponse,\n AgentListResponse,\n ImageCreateResponse,\n ImageGetResponse,\n ImageListResponse,\n ContainerCreateResponse,\n ContainerGetResponse,\n ContainerListResponse,\n MessageSendResponse,\n BaseResponse,\n} from \"./types\";\nimport { Presentation, type PresentationOptions } from \"./presentation\";\n\nconst logger = createLogger(\"agentx/RemoteClient\");\n\n/**\n * RemoteClient implementation using JSON-RPC 2.0\n */\nexport class RemoteClient implements AgentX {\n private readonly config: AgentXConfig;\n private readonly eventBus: EventBus;\n private readonly rpcClient: RpcClient;\n\n constructor(config: AgentXConfig) {\n this.config = config;\n this.eventBus = new EventBusImpl();\n\n // Create RPC client\n this.rpcClient = new RpcClient({\n url: config.serverUrl,\n timeout: config.timeout ?? 30000,\n autoReconnect: config.autoReconnect ?? true,\n headers: config.headers as Record<string, string> | undefined,\n debug: false,\n });\n\n // Forward stream events to internal event bus\n this.rpcClient.onStreamEvent((topic, event) => {\n logger.debug(\"Received stream event\", { topic, type: event.type });\n this.eventBus.emit(event as BusEvent);\n });\n }\n\n // ==================== Properties ====================\n\n get connected(): boolean {\n return this.rpcClient.connected;\n }\n\n get events(): EventBus {\n return this.eventBus;\n }\n\n // ==================== Connection ====================\n\n async connect(): Promise<void> {\n await this.rpcClient.connect();\n logger.info(\"Connected to server\", { url: this.config.serverUrl });\n }\n\n async disconnect(): Promise<void> {\n this.rpcClient.disconnect();\n logger.info(\"Disconnected from server\");\n }\n\n async dispose(): Promise<void> {\n this.rpcClient.dispose();\n this.eventBus.destroy();\n logger.info(\"RemoteClient disposed\");\n }\n\n // ==================== Container Operations ====================\n\n async createContainer(containerId: string): Promise<ContainerCreateResponse> {\n const result = await this.rpcClient.call<ContainerCreateResponse>(\"container.create\", {\n containerId,\n });\n return { ...result, requestId: \"\" };\n }\n\n async getContainer(containerId: string): Promise<ContainerGetResponse> {\n const result = await this.rpcClient.call<ContainerGetResponse>(\"container.get\", {\n containerId,\n });\n return { ...result, requestId: \"\" };\n }\n\n async listContainers(): Promise<ContainerListResponse> {\n const result = await this.rpcClient.call<ContainerListResponse>(\"container.list\", {});\n return { ...result, requestId: \"\" };\n }\n\n // ==================== Image Operations ====================\n\n async createImage(params: {\n containerId: string;\n name?: string;\n description?: string;\n systemPrompt?: string;\n mcpServers?: Record<string, unknown>;\n }): Promise<ImageCreateResponse> {\n const result = await this.rpcClient.call<ImageCreateResponse>(\"image.create\", params);\n\n // Auto subscribe to session events\n if (result.__subscriptions) {\n for (const sessionId of result.__subscriptions) {\n this.subscribe(sessionId);\n }\n }\n\n return { ...result, requestId: \"\" };\n }\n\n async getImage(imageId: string): Promise<ImageGetResponse> {\n const result = await this.rpcClient.call<ImageGetResponse>(\"image.get\", { imageId });\n\n // Auto subscribe\n if (result.__subscriptions) {\n for (const sessionId of result.__subscriptions) {\n this.subscribe(sessionId);\n }\n }\n\n return { ...result, requestId: \"\" };\n }\n\n async listImages(containerId?: string): Promise<ImageListResponse> {\n const result = await this.rpcClient.call<ImageListResponse>(\"image.list\", { containerId });\n\n // Auto subscribe\n if (result.__subscriptions) {\n for (const sessionId of result.__subscriptions) {\n this.subscribe(sessionId);\n }\n }\n\n return { ...result, requestId: \"\" };\n }\n\n async deleteImage(imageId: string): Promise<BaseResponse> {\n const result = await this.rpcClient.call<BaseResponse>(\"image.delete\", { imageId });\n return { ...result, requestId: \"\" };\n }\n\n // ==================== Agent Operations ====================\n\n async createAgent(params: { imageId: string; agentId?: string }): Promise<AgentCreateResponse> {\n // Agent creation via image.run RPC\n const result = await this.rpcClient.call<AgentCreateResponse>(\"image.run\" as RpcMethod, {\n imageId: params.imageId,\n agentId: params.agentId,\n });\n return { ...result, requestId: \"\" };\n }\n\n async getAgent(agentId: string): Promise<AgentGetResponse> {\n const result = await this.rpcClient.call<AgentGetResponse>(\"agent.get\", { agentId });\n return { ...result, requestId: \"\" };\n }\n\n async listAgents(containerId?: string): Promise<AgentListResponse> {\n const result = await this.rpcClient.call<AgentListResponse>(\"agent.list\", { containerId });\n return { ...result, requestId: \"\" };\n }\n\n async destroyAgent(agentId: string): Promise<BaseResponse> {\n const result = await this.rpcClient.call<BaseResponse>(\"agent.destroy\", { agentId });\n return { ...result, requestId: \"\" };\n }\n\n // ==================== Message Operations ====================\n\n async sendMessage(agentId: string, content: string | unknown[]): Promise<MessageSendResponse> {\n const result = await this.rpcClient.call<MessageSendResponse>(\"message.send\", {\n agentId,\n content,\n });\n return { ...result, requestId: \"\" };\n }\n\n async interrupt(agentId: string): Promise<BaseResponse> {\n const result = await this.rpcClient.call<BaseResponse>(\"agent.interrupt\", { agentId });\n return { ...result, requestId: \"\" };\n }\n\n // ==================== Event Subscription ====================\n\n on<T extends string>(type: T, handler: BusEventHandler<BusEvent & { type: T }>): Unsubscribe {\n return this.eventBus.on(type, handler);\n }\n\n onAny(handler: BusEventHandler): Unsubscribe {\n return this.eventBus.onAny(handler);\n }\n\n subscribe(sessionId: string): void {\n this.rpcClient.subscribe(sessionId);\n logger.debug(\"Subscribed to session\", { sessionId });\n }\n\n // ==================== Presentation ====================\n\n presentation(agentId: string, options?: PresentationOptions): Presentation {\n return new Presentation(this, agentId, options);\n }\n}\n","/**\n * ConsoleLogger - Default logger implementation\n *\n * Simple console-based logger with color support.\n * Used as fallback when no custom LoggerFactory is provided.\n */\n\nimport type { Logger, LogContext, LogLevel } from \"./types\";\n\nexport interface ConsoleLoggerOptions {\n level?: LogLevel;\n colors?: boolean;\n timestamps?: boolean;\n}\n\nexport class ConsoleLogger implements Logger {\n readonly name: string;\n readonly level: LogLevel;\n private readonly colors: boolean;\n private readonly timestamps: boolean;\n\n private static readonly COLORS = {\n DEBUG: \"\\x1b[36m\",\n INFO: \"\\x1b[32m\",\n WARN: \"\\x1b[33m\",\n ERROR: \"\\x1b[31m\",\n RESET: \"\\x1b[0m\",\n };\n\n constructor(name: string, options: ConsoleLoggerOptions = {}) {\n this.name = name;\n this.level = options.level ?? \"info\";\n this.colors = options.colors ?? this.isNodeEnvironment();\n this.timestamps = options.timestamps ?? true;\n }\n\n debug(message: string, context?: LogContext): void {\n if (this.isDebugEnabled()) {\n this.log(\"DEBUG\", message, context);\n }\n }\n\n info(message: string, context?: LogContext): void {\n if (this.isInfoEnabled()) {\n this.log(\"INFO\", message, context);\n }\n }\n\n warn(message: string, context?: LogContext): void {\n if (this.isWarnEnabled()) {\n this.log(\"WARN\", message, context);\n }\n }\n\n error(message: string | Error, context?: LogContext): void {\n if (this.isErrorEnabled()) {\n if (message instanceof Error) {\n this.log(\"ERROR\", message.message, { ...context, stack: message.stack });\n } else {\n this.log(\"ERROR\", message, context);\n }\n }\n }\n\n isDebugEnabled(): boolean {\n return this.getLevelValue(this.level) <= this.getLevelValue(\"debug\");\n }\n\n isInfoEnabled(): boolean {\n return this.getLevelValue(this.level) <= this.getLevelValue(\"info\");\n }\n\n isWarnEnabled(): boolean {\n return this.getLevelValue(this.level) <= this.getLevelValue(\"warn\");\n }\n\n isErrorEnabled(): boolean {\n return this.getLevelValue(this.level) <= this.getLevelValue(\"error\");\n }\n\n private getLevelValue(level: LogLevel): number {\n const levels: Record<LogLevel, number> = {\n debug: 0,\n info: 1,\n warn: 2,\n error: 3,\n silent: 4,\n };\n return levels[level];\n }\n\n private log(level: string, message: string, context?: LogContext): void {\n const parts: string[] = [];\n\n if (this.timestamps) {\n parts.push(new Date().toISOString());\n }\n\n if (this.colors) {\n const color = ConsoleLogger.COLORS[level as keyof typeof ConsoleLogger.COLORS];\n parts.push(`${color}${level.padEnd(5)}${ConsoleLogger.COLORS.RESET}`);\n } else {\n parts.push(level.padEnd(5));\n }\n\n parts.push(`[${this.name}]`);\n parts.push(message);\n\n const logLine = parts.join(\" \");\n const consoleMethod = this.getConsoleMethod(level);\n\n if (context && Object.keys(context).length > 0) {\n consoleMethod(logLine, context);\n } else {\n consoleMethod(logLine);\n }\n }\n\n private getConsoleMethod(level: string): (...args: unknown[]) => void {\n switch (level) {\n case \"DEBUG\":\n return console.debug.bind(console);\n case \"INFO\":\n return console.info.bind(console);\n case \"WARN\":\n return console.warn.bind(console);\n case \"ERROR\":\n return console.error.bind(console);\n default:\n return console.log.bind(console);\n }\n }\n\n private isNodeEnvironment(): boolean {\n return typeof process !== \"undefined\" && process.versions?.node !== undefined;\n }\n}\n","/**\n * LoggerFactoryImpl - Central factory for creating logger instances\n *\n * Implements lazy initialization pattern:\n * - createLogger() can be called at module level (before config)\n * - Real logger is created on first use\n * - External LoggerFactory can be injected via Runtime\n */\n\nimport type { Logger, LoggerFactory, LogContext, LogLevel } from \"./types\";\nimport { ConsoleLogger, type ConsoleLoggerOptions } from \"./ConsoleLogger\";\n\n// External factory injected via Runtime\nlet externalFactory: LoggerFactory | null = null;\n\n// Version counter to invalidate cached real loggers\nlet factoryVersion = 0;\n\nexport interface LoggerFactoryConfig {\n defaultImplementation?: (name: string) => Logger;\n defaultLevel?: LogLevel;\n consoleOptions?: Omit<ConsoleLoggerOptions, \"level\">;\n}\n\n/**\n * Internal LoggerFactory implementation\n *\n * Uses lazy proxy pattern to allow module-level createLogger() calls.\n */\nexport class LoggerFactoryImpl {\n private static loggers: Map<string, Logger> = new Map();\n private static config: LoggerFactoryConfig = {\n defaultLevel: \"info\",\n };\n\n static getLogger(nameOrClass: string | (new (...args: unknown[]) => unknown)): Logger {\n const name = typeof nameOrClass === \"string\" ? nameOrClass : nameOrClass.name;\n\n if (this.loggers.has(name)) {\n return this.loggers.get(name)!;\n }\n\n const lazyLogger = this.createLazyLogger(name);\n this.loggers.set(name, lazyLogger);\n return lazyLogger;\n }\n\n static configure(config: LoggerFactoryConfig): void {\n this.config = { ...this.config, ...config };\n }\n\n static reset(): void {\n this.loggers.clear();\n this.config = { defaultLevel: \"info\" };\n externalFactory = null;\n factoryVersion++; // Invalidate all cached real loggers\n }\n\n private static createLazyLogger(name: string): Logger {\n let realLogger: Logger | null = null;\n let loggerVersion = -1; // Track which factory version created this logger\n\n const getRealLogger = (): Logger => {\n // Recreate logger if factory version changed (setLoggerFactory was called)\n if (!realLogger || loggerVersion !== factoryVersion) {\n realLogger = this.createLogger(name);\n loggerVersion = factoryVersion;\n }\n return realLogger;\n };\n\n return {\n name,\n level: this.config.defaultLevel || \"info\",\n debug: (message: string, context?: LogContext) => getRealLogger().debug(message, context),\n info: (message: string, context?: LogContext) => getRealLogger().info(message, context),\n warn: (message: string, context?: LogContext) => getRealLogger().warn(message, context),\n error: (message: string | Error, context?: LogContext) =>\n getRealLogger().error(message, context),\n isDebugEnabled: () => getRealLogger().isDebugEnabled(),\n isInfoEnabled: () => getRealLogger().isInfoEnabled(),\n isWarnEnabled: () => getRealLogger().isWarnEnabled(),\n isErrorEnabled: () => getRealLogger().isErrorEnabled(),\n };\n }\n\n private static createLogger(name: string): Logger {\n if (externalFactory) {\n return externalFactory.getLogger(name);\n }\n\n if (this.config.defaultImplementation) {\n return this.config.defaultImplementation(name);\n }\n\n return new ConsoleLogger(name, {\n level: this.config.defaultLevel,\n ...this.config.consoleOptions,\n });\n }\n}\n\n/**\n * Set external LoggerFactory (called by Runtime initialization)\n */\nexport function setLoggerFactory(factory: LoggerFactory): void {\n externalFactory = factory;\n LoggerFactoryImpl.reset();\n externalFactory = factory;\n}\n\n/**\n * Create a logger instance\n *\n * Safe to call at module level before Runtime is configured.\n * Uses lazy initialization - actual logger is created on first use.\n *\n * @param name - Logger name (hierarchical, e.g., \"engine/AgentEngine\")\n * @returns Logger instance (lazy proxy)\n */\nexport function createLogger(name: string): Logger {\n return LoggerFactoryImpl.getLogger(name);\n}\n","/**\n * Presentation Types\n *\n * UI-friendly data model aggregated from stream events.\n * This implements the Presentation Model pattern.\n */\n\n// ============================================================================\n// Block Types - Basic content units\n// ============================================================================\n\n/**\n * Text block\n */\nexport interface TextBlock {\n type: \"text\";\n content: string;\n}\n\n/**\n * Tool block - represents a tool call and its result\n */\nexport interface ToolBlock {\n type: \"tool\";\n toolUseId: string;\n toolName: string;\n toolInput: Record<string, unknown>;\n toolResult?: string;\n status: \"pending\" | \"running\" | \"completed\" | \"error\";\n}\n\n/**\n * Image block\n */\nexport interface ImageBlock {\n type: \"image\";\n url: string;\n alt?: string;\n}\n\n/**\n * All block types\n */\nexport type Block = TextBlock | ToolBlock | ImageBlock;\n\n// ============================================================================\n// Conversation Types - A single turn in the conversation\n// ============================================================================\n\n/**\n * User conversation\n */\nexport interface UserConversation {\n role: \"user\";\n blocks: Block[];\n}\n\n/**\n * Assistant conversation\n */\nexport interface AssistantConversation {\n role: \"assistant\";\n blocks: Block[];\n isStreaming: boolean;\n}\n\n/**\n * Error conversation\n */\nexport interface ErrorConversation {\n role: \"error\";\n message: string;\n}\n\n/**\n * All conversation types\n */\nexport type Conversation = UserConversation | AssistantConversation | ErrorConversation;\n\n// ============================================================================\n// Presentation State\n// ============================================================================\n\n/**\n * Presentation state - the complete UI state\n */\nexport interface PresentationState {\n /**\n * All completed conversations\n */\n conversations: Conversation[];\n\n /**\n * Current streaming conversation (null if not streaming)\n */\n streaming: AssistantConversation | null;\n\n /**\n * Current status\n */\n status: \"idle\" | \"thinking\" | \"responding\" | \"executing\";\n}\n\n/**\n * Initial presentation state\n */\nexport const initialPresentationState: PresentationState = {\n conversations: [],\n streaming: null,\n status: \"idle\",\n};\n","/**\n * Presentation Reducer\n *\n * Aggregates stream events into PresentationState.\n * Pure function: (state, event) => newState\n */\n\nimport type { BusEvent } from \"@agentxjs/core/event\";\nimport type {\n PresentationState,\n AssistantConversation,\n TextBlock,\n ToolBlock,\n Block,\n} from \"./types\";\nimport { initialPresentationState } from \"./types\";\n\n// ============================================================================\n// Event Data Types (from stream events)\n// ============================================================================\n\ninterface MessageStartData {\n messageId?: string;\n model?: string;\n}\n\ninterface TextDeltaData {\n text: string;\n}\n\ninterface ToolUseStartData {\n toolUseId: string;\n toolName: string;\n}\n\ninterface InputJsonDeltaData {\n delta: string;\n}\n\ninterface ToolResultData {\n toolUseId: string;\n result: string;\n isError?: boolean;\n}\n\ninterface MessageStopData {\n stopReason?: string;\n}\n\ninterface ErrorData {\n message: string;\n code?: string;\n}\n\n// ============================================================================\n// Reducer\n// ============================================================================\n\n/**\n * Reduce a stream event into presentation state\n */\nexport function presentationReducer(\n state: PresentationState,\n event: BusEvent\n): PresentationState {\n switch (event.type) {\n case \"message_start\":\n return handleMessageStart(state, event.data as MessageStartData);\n\n case \"text_delta\":\n return handleTextDelta(state, event.data as TextDeltaData);\n\n case \"tool_use_start\":\n return handleToolUseStart(state, event.data as ToolUseStartData);\n\n case \"input_json_delta\":\n return handleInputJsonDelta(state, event.data as InputJsonDeltaData);\n\n case \"tool_result\":\n return handleToolResult(state, event.data as ToolResultData);\n\n case \"message_stop\":\n return handleMessageStop(state, event.data as MessageStopData);\n\n case \"error\":\n return handleError(state, event.data as ErrorData);\n\n default:\n return state;\n }\n}\n\n// ============================================================================\n// Handlers\n// ============================================================================\n\nfunction handleMessageStart(\n state: PresentationState,\n _data: MessageStartData\n): PresentationState {\n // Start a new streaming assistant conversation\n const streaming: AssistantConversation = {\n role: \"assistant\",\n blocks: [],\n isStreaming: true,\n };\n\n return {\n ...state,\n streaming,\n status: \"thinking\",\n };\n}\n\nfunction handleTextDelta(\n state: PresentationState,\n data: TextDeltaData\n): PresentationState {\n if (!state.streaming) {\n return state;\n }\n\n const blocks = [...state.streaming.blocks];\n const lastBlock = blocks[blocks.length - 1];\n\n // Append to existing TextBlock or create new one\n if (lastBlock && lastBlock.type === \"text\") {\n blocks[blocks.length - 1] = {\n ...lastBlock,\n content: lastBlock.content + data.text,\n };\n } else {\n blocks.push({\n type: \"text\",\n content: data.text,\n } as TextBlock);\n }\n\n return {\n ...state,\n streaming: {\n ...state.streaming,\n blocks,\n },\n status: \"responding\",\n };\n}\n\nfunction handleToolUseStart(\n state: PresentationState,\n data: ToolUseStartData\n): PresentationState {\n if (!state.streaming) {\n return state;\n }\n\n const toolBlock: ToolBlock = {\n type: \"tool\",\n toolUseId: data.toolUseId,\n toolName: data.toolName,\n toolInput: {},\n status: \"pending\",\n };\n\n return {\n ...state,\n streaming: {\n ...state.streaming,\n blocks: [...state.streaming.blocks, toolBlock],\n },\n status: \"executing\",\n };\n}\n\nfunction handleInputJsonDelta(\n state: PresentationState,\n data: InputJsonDeltaData\n): PresentationState {\n if (!state.streaming) {\n return state;\n }\n\n const blocks = [...state.streaming.blocks];\n const lastBlock = blocks[blocks.length - 1];\n\n // Find the last tool block and update its input\n if (lastBlock && lastBlock.type === \"tool\") {\n // Accumulate JSON delta (will be parsed when complete)\n const currentInput = (lastBlock as ToolBlock & { _rawInput?: string })._rawInput || \"\";\n const newInput = currentInput + data.delta;\n\n // Try to parse the accumulated JSON\n let toolInput = lastBlock.toolInput;\n try {\n toolInput = JSON.parse(newInput);\n } catch {\n // Not yet valid JSON, keep accumulating\n }\n\n blocks[blocks.length - 1] = {\n ...lastBlock,\n toolInput,\n _rawInput: newInput,\n status: \"running\",\n } as ToolBlock & { _rawInput?: string };\n\n return {\n ...state,\n streaming: {\n ...state.streaming,\n blocks,\n },\n };\n }\n\n return state;\n}\n\nfunction handleToolResult(\n state: PresentationState,\n data: ToolResultData\n): PresentationState {\n if (!state.streaming) {\n return state;\n }\n\n const blocks = state.streaming.blocks.map((block): Block => {\n if (block.type === \"tool\" && block.toolUseId === data.toolUseId) {\n return {\n ...block,\n toolResult: data.result,\n status: data.isError ? \"error\" : \"completed\",\n };\n }\n return block;\n });\n\n return {\n ...state,\n streaming: {\n ...state.streaming,\n blocks,\n },\n status: \"responding\",\n };\n}\n\nfunction handleMessageStop(\n state: PresentationState,\n _data: MessageStopData\n): PresentationState {\n if (!state.streaming) {\n return state;\n }\n\n // Move streaming to conversations\n const completedConversation: AssistantConversation = {\n ...state.streaming,\n isStreaming: false,\n };\n\n return {\n ...state,\n conversations: [...state.conversations, completedConversation],\n streaming: null,\n status: \"idle\",\n };\n}\n\nfunction handleError(\n state: PresentationState,\n data: ErrorData\n): PresentationState {\n // Add error conversation\n return {\n ...state,\n conversations: [\n ...state.conversations,\n {\n role: \"error\",\n message: data.message,\n },\n ],\n streaming: null,\n status: \"idle\",\n };\n}\n\n// ============================================================================\n// Helper: Add user conversation\n// ============================================================================\n\n/**\n * Add a user conversation to state\n */\nexport function addUserConversation(\n state: PresentationState,\n content: string\n): PresentationState {\n return {\n ...state,\n conversations: [\n ...state.conversations,\n {\n role: \"user\",\n blocks: [{ type: \"text\", content }],\n },\n ],\n };\n}\n\n/**\n * Create initial state\n */\nexport function createInitialState(): PresentationState {\n return { ...initialPresentationState };\n}\n","/**\n * Presentation Class\n *\n * High-level API for UI integration.\n * Wraps AgentX client and provides presentation state management.\n */\n\nimport type { AgentX } from \"../types\";\nimport type { Unsubscribe, BusEvent } from \"@agentxjs/core/event\";\nimport type { PresentationState } from \"./types\";\nimport {\n presentationReducer,\n addUserConversation,\n createInitialState,\n} from \"./reducer\";\n\n/**\n * Presentation update handler\n */\nexport type PresentationUpdateHandler = (state: PresentationState) => void;\n\n/**\n * Presentation error handler\n */\nexport type PresentationErrorHandler = (error: Error) => void;\n\n/**\n * Presentation options\n */\nexport interface PresentationOptions {\n /**\n * Called on every state update\n */\n onUpdate?: PresentationUpdateHandler;\n\n /**\n * Called on errors\n */\n onError?: PresentationErrorHandler;\n}\n\n/**\n * Presentation - UI-friendly wrapper for AgentX\n */\nexport class Presentation {\n private agentx: AgentX;\n private agentId: string;\n private state: PresentationState;\n private updateHandlers: Set<PresentationUpdateHandler> = new Set();\n private errorHandlers: Set<PresentationErrorHandler> = new Set();\n private eventUnsubscribe: Unsubscribe | null = null;\n\n constructor(agentx: AgentX, agentId: string, options?: PresentationOptions) {\n this.agentx = agentx;\n this.agentId = agentId;\n this.state = createInitialState();\n\n // Register initial handlers\n if (options?.onUpdate) {\n this.updateHandlers.add(options.onUpdate);\n }\n if (options?.onError) {\n this.errorHandlers.add(options.onError);\n }\n\n // Subscribe to all events\n this.subscribeToEvents();\n }\n\n /**\n * Get current state\n */\n getState(): PresentationState {\n return this.state;\n }\n\n /**\n * Subscribe to state updates\n */\n onUpdate(handler: PresentationUpdateHandler): Unsubscribe {\n this.updateHandlers.add(handler);\n // Immediately call with current state\n handler(this.state);\n return () => {\n this.updateHandlers.delete(handler);\n };\n }\n\n /**\n * Subscribe to errors\n */\n onError(handler: PresentationErrorHandler): Unsubscribe {\n this.errorHandlers.add(handler);\n return () => {\n this.errorHandlers.delete(handler);\n };\n }\n\n /**\n * Send a message\n */\n async send(content: string): Promise<void> {\n // Add user conversation\n this.state = addUserConversation(this.state, content);\n this.notify();\n\n try {\n // Send message via agentx\n await this.agentx.sendMessage(this.agentId, content);\n } catch (error) {\n this.notifyError(error instanceof Error ? error : new Error(String(error)));\n }\n }\n\n /**\n * Interrupt current response\n */\n async interrupt(): Promise<void> {\n try {\n await this.agentx.interrupt(this.agentId);\n } catch (error) {\n this.notifyError(error instanceof Error ? error : new Error(String(error)));\n }\n }\n\n /**\n * Reset state\n */\n reset(): void {\n this.state = createInitialState();\n this.notify();\n }\n\n /**\n * Dispose and cleanup\n */\n dispose(): void {\n if (this.eventUnsubscribe) {\n this.eventUnsubscribe();\n this.eventUnsubscribe = null;\n }\n this.updateHandlers.clear();\n this.errorHandlers.clear();\n }\n\n // ==================== Private ====================\n\n private subscribeToEvents(): void {\n // Subscribe to all events and filter by agentId\n this.eventUnsubscribe = this.agentx.onAny((event: BusEvent) => {\n // Filter events for this agent (if context is available)\n // Note: Events from server may or may not include context with agentId\n const eventWithContext = event as BusEvent & { context?: { agentId?: string } };\n const eventAgentId = eventWithContext.context?.agentId;\n\n // Only filter if event has agentId and it doesn't match\n if (eventAgentId && eventAgentId !== this.agentId) {\n return;\n }\n\n // Reduce event into state\n const newState = presentationReducer(this.state, event);\n if (newState !== this.state) {\n this.state = newState;\n this.notify();\n }\n });\n }\n\n private notify(): void {\n for (const handler of this.updateHandlers) {\n try {\n handler(this.state);\n } catch (error) {\n console.error(\"Presentation update handler error:\", error);\n }\n }\n }\n\n private notifyError(error: Error): void {\n for (const handler of this.errorHandlers) {\n try {\n handler(error);\n } catch (e) {\n console.error(\"Presentation error handler error:\", e);\n }\n }\n }\n}\n","/**\n * agentxjs - AgentX Client SDK\n *\n * Connect to AgentX servers from Node.js and browsers.\n *\n * @example\n * ```typescript\n * import { createAgentX } from \"agentxjs\";\n *\n * // Connect to server\n * const agentx = await createAgentX({\n * serverUrl: \"ws://localhost:5200\",\n * headers: { Authorization: \"Bearer sk-xxx\" },\n * context: { userId: \"123\", tenantId: \"abc\" },\n * });\n *\n * // Create container and image\n * await agentx.createContainer(\"my-container\");\n * const { record: image } = await agentx.createImage({\n * containerId: \"my-container\",\n * name: \"Assistant\",\n * systemPrompt: \"You are a helpful assistant\",\n * });\n *\n * // Create agent and send message\n * const { agentId } = await agentx.createAgent({ imageId: image.imageId });\n *\n * // Subscribe to events\n * agentx.on(\"text_delta\", (event) => {\n * process.stdout.write(event.data.text);\n * });\n *\n * agentx.on(\"assistant_message\", (event) => {\n * console.log(\"Complete:\", event.data.content);\n * });\n *\n * // Send message\n * await agentx.sendMessage(agentId, \"Hello!\");\n *\n * // Cleanup\n * await agentx.dispose();\n * ```\n *\n * @example Dynamic headers and context\n * ```typescript\n * const agentx = await createAgentX({\n * serverUrl: \"ws://localhost:5200\",\n * headers: () => ({ Authorization: `Bearer ${getToken()}` }),\n * context: async () => ({\n * userId: await getUserId(),\n * permissions: await getPermissions(),\n * }),\n * });\n * ```\n */\n\nimport { RemoteClient } from \"./RemoteClient\";\nimport type { AgentX, AgentXConfig } from \"./types\";\n\n/**\n * Create an AgentX client\n *\n * @param config - Client configuration\n * @returns Connected AgentX client\n */\nexport async function createAgentX(config: AgentXConfig): Promise<AgentX> {\n const client = new RemoteClient(config);\n await client.connect();\n return client;\n}\n\n// Re-export types\nexport type {\n AgentX,\n AgentXConfig,\n MaybeAsync,\n AgentInfo,\n ImageRecord,\n ContainerInfo,\n AgentCreateResponse,\n AgentGetResponse,\n AgentListResponse,\n ImageCreateResponse,\n ImageGetResponse,\n ImageListResponse,\n ContainerCreateResponse,\n ContainerGetResponse,\n ContainerListResponse,\n MessageSendResponse,\n BaseResponse,\n} from \"./types\";\n\n// Re-export Presentation types and classes\nexport type {\n Block,\n TextBlock,\n ToolBlock,\n ImageBlock,\n Conversation,\n UserConversation,\n AssistantConversation,\n ErrorConversation,\n PresentationState,\n PresentationOptions,\n PresentationUpdateHandler,\n PresentationErrorHandler,\n} from \"./presentation\";\n\nexport {\n Presentation,\n presentationReducer,\n addUserConversation,\n createInitialState,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AE,UAAU,CAAC;AAAA,EACrD;AAAA;AAAA,EAIA,aAAa,SAAiB,SAA6C;AACzE,WAAO,IAAI,aAAa,MAAM,SAAS,OAAO;AAAA,EAChD;AACF;;;AM3JA,eAAsB,aAAa,QAAuC;AACxE,QAAM,SAAS,IAAI,aAAa,MAAM;AACtC,QAAM,OAAO,QAAQ;AACrB,SAAO;AACT;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentxjs",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.6-dev",
|
|
4
4
|
"description": "AgentX Client SDK - Connect to AgentX servers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -8,12 +8,17 @@
|
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"types": "./
|
|
12
|
-
"
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
13
14
|
}
|
|
14
15
|
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"src"
|
|
19
|
+
],
|
|
15
20
|
"scripts": {
|
|
16
|
-
"build": "
|
|
21
|
+
"build": "tsup",
|
|
17
22
|
"typecheck": "tsc --noEmit",
|
|
18
23
|
"test": "bun test"
|
|
19
24
|
},
|
package/build.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Build script for agentxjs
|
|
3
|
-
*
|
|
4
|
-
* Generates dist/ with JS and .d.ts files
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { $ } from "bun";
|
|
8
|
-
|
|
9
|
-
console.log("Building agentxjs...");
|
|
10
|
-
|
|
11
|
-
// Clean dist
|
|
12
|
-
await $`rm -rf dist`;
|
|
13
|
-
|
|
14
|
-
// Generate .d.ts using tsc
|
|
15
|
-
await $`tsc --emitDeclarationOnly --outDir dist`;
|
|
16
|
-
|
|
17
|
-
// Build with bun
|
|
18
|
-
await Bun.build({
|
|
19
|
-
entrypoints: ["./src/index.ts"],
|
|
20
|
-
outdir: "./dist",
|
|
21
|
-
format: "esm",
|
|
22
|
-
target: "node",
|
|
23
|
-
sourcemap: "external",
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
console.log("Build complete!");
|
package/tsconfig.json
DELETED