@agentxjs/core 1.9.1-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/package.json +31 -0
- package/src/agent/AgentStateMachine.ts +151 -0
- package/src/agent/README.md +296 -0
- package/src/agent/__tests__/AgentStateMachine.test.ts +346 -0
- package/src/agent/__tests__/createAgent.test.ts +728 -0
- package/src/agent/__tests__/engine/internal/messageAssemblerProcessor.test.ts +567 -0
- package/src/agent/__tests__/engine/internal/stateEventProcessor.test.ts +315 -0
- package/src/agent/__tests__/engine/internal/turnTrackerProcessor.test.ts +340 -0
- package/src/agent/__tests__/engine/mealy/Mealy.test.ts +370 -0
- package/src/agent/__tests__/engine/mealy/Store.test.ts +123 -0
- package/src/agent/__tests__/engine/mealy/combinators.test.ts +322 -0
- package/src/agent/createAgent.ts +467 -0
- package/src/agent/engine/AgentProcessor.ts +106 -0
- package/src/agent/engine/MealyMachine.ts +184 -0
- package/src/agent/engine/internal/index.ts +35 -0
- package/src/agent/engine/internal/messageAssemblerProcessor.ts +550 -0
- package/src/agent/engine/internal/stateEventProcessor.ts +313 -0
- package/src/agent/engine/internal/turnTrackerProcessor.ts +239 -0
- package/src/agent/engine/mealy/Mealy.ts +308 -0
- package/src/agent/engine/mealy/Processor.ts +70 -0
- package/src/agent/engine/mealy/Sink.ts +56 -0
- package/src/agent/engine/mealy/Source.ts +51 -0
- package/src/agent/engine/mealy/Store.ts +98 -0
- package/src/agent/engine/mealy/combinators.ts +176 -0
- package/src/agent/engine/mealy/index.ts +45 -0
- package/src/agent/index.ts +106 -0
- package/src/agent/types/engine.ts +395 -0
- package/src/agent/types/event.ts +478 -0
- package/src/agent/types/index.ts +197 -0
- package/src/agent/types/message.ts +387 -0
- package/src/common/index.ts +8 -0
- package/src/common/logger/ConsoleLogger.ts +137 -0
- package/src/common/logger/LoggerFactoryImpl.ts +123 -0
- package/src/common/logger/index.ts +26 -0
- package/src/common/logger/types.ts +98 -0
- package/src/container/Container.ts +185 -0
- package/src/container/index.ts +44 -0
- package/src/container/types.ts +71 -0
- package/src/driver/index.ts +42 -0
- package/src/driver/types.ts +363 -0
- package/src/event/EventBus.ts +260 -0
- package/src/event/README.md +237 -0
- package/src/event/__tests__/EventBus.test.ts +251 -0
- package/src/event/index.ts +46 -0
- package/src/event/types/agent.ts +512 -0
- package/src/event/types/base.ts +241 -0
- package/src/event/types/bus.ts +429 -0
- package/src/event/types/command.ts +749 -0
- package/src/event/types/container.ts +471 -0
- package/src/event/types/driver.ts +452 -0
- package/src/event/types/index.ts +26 -0
- package/src/event/types/session.ts +314 -0
- package/src/image/Image.ts +203 -0
- package/src/image/index.ts +36 -0
- package/src/image/types.ts +77 -0
- package/src/index.ts +20 -0
- package/src/mq/OffsetGenerator.ts +48 -0
- package/src/mq/README.md +166 -0
- package/src/mq/__tests__/OffsetGenerator.test.ts +121 -0
- package/src/mq/index.ts +18 -0
- package/src/mq/types.ts +172 -0
- package/src/network/RpcClient.ts +455 -0
- package/src/network/index.ts +76 -0
- package/src/network/jsonrpc.ts +336 -0
- package/src/network/protocol.ts +90 -0
- package/src/network/types.ts +284 -0
- package/src/persistence/index.ts +27 -0
- package/src/persistence/types.ts +226 -0
- package/src/runtime/AgentXRuntime.ts +501 -0
- package/src/runtime/index.ts +56 -0
- package/src/runtime/types.ts +236 -0
- package/src/session/Session.ts +71 -0
- package/src/session/index.ts +25 -0
- package/src/session/types.ts +77 -0
- package/src/workspace/index.ts +27 -0
- package/src/workspace/types.ts +131 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,749 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command Events - API operations (request/response)
|
|
3
|
+
*
|
|
4
|
+
* Command events for the EventBus system.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { SystemEvent } from "./base";
|
|
8
|
+
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// Content Part Types (Self-contained)
|
|
11
|
+
// ============================================================================
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Text content part for user messages
|
|
15
|
+
*/
|
|
16
|
+
export interface TextPart {
|
|
17
|
+
type: "text";
|
|
18
|
+
text: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Image content part for user messages
|
|
23
|
+
*/
|
|
24
|
+
export interface ImagePart {
|
|
25
|
+
type: "image";
|
|
26
|
+
data: string;
|
|
27
|
+
mediaType: "image/jpeg" | "image/png" | "image/gif" | "image/webp";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* File content part for user messages
|
|
32
|
+
*/
|
|
33
|
+
export interface FilePart {
|
|
34
|
+
type: "file";
|
|
35
|
+
data: string;
|
|
36
|
+
filename: string;
|
|
37
|
+
mediaType: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* User content part - content that users can send in messages
|
|
42
|
+
*/
|
|
43
|
+
export type UserContentPart = TextPart | ImagePart | FilePart;
|
|
44
|
+
|
|
45
|
+
// ============================================================================
|
|
46
|
+
// Response Types (Self-contained)
|
|
47
|
+
// ============================================================================
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* AgentXResponse - Base interface for all command response data
|
|
51
|
+
*
|
|
52
|
+
* All command response data types should extend this interface
|
|
53
|
+
* to ensure consistent structure and enable automatic client-side handling.
|
|
54
|
+
*/
|
|
55
|
+
export interface AgentXResponse {
|
|
56
|
+
/**
|
|
57
|
+
* Request ID for correlation and tracking
|
|
58
|
+
*/
|
|
59
|
+
requestId: string;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Error message if the request failed
|
|
63
|
+
*/
|
|
64
|
+
error?: string;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Session IDs that the client should subscribe to
|
|
68
|
+
*/
|
|
69
|
+
__subscriptions?: string[];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ============================================================================
|
|
73
|
+
// Record Types (Self-contained)
|
|
74
|
+
// ============================================================================
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* MCP Server Configuration
|
|
78
|
+
*/
|
|
79
|
+
export interface McpServerConfig {
|
|
80
|
+
command?: string;
|
|
81
|
+
args?: string[];
|
|
82
|
+
env?: Record<string, string>;
|
|
83
|
+
url?: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Image metadata for storing provider-specific data
|
|
88
|
+
*/
|
|
89
|
+
export interface ImageMetadata {
|
|
90
|
+
claudeSdkSessionId?: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Image storage record
|
|
95
|
+
*/
|
|
96
|
+
export interface ImageRecord {
|
|
97
|
+
imageId: string;
|
|
98
|
+
containerId: string;
|
|
99
|
+
sessionId: string;
|
|
100
|
+
name: string;
|
|
101
|
+
description?: string;
|
|
102
|
+
systemPrompt?: string;
|
|
103
|
+
parentImageId?: string;
|
|
104
|
+
mcpServers?: Record<string, McpServerConfig>;
|
|
105
|
+
metadata?: ImageMetadata;
|
|
106
|
+
createdAt: number;
|
|
107
|
+
updatedAt: number;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Image list item with online status
|
|
112
|
+
*/
|
|
113
|
+
export interface ImageListItem extends ImageRecord {
|
|
114
|
+
/** Whether an agent is currently running for this image */
|
|
115
|
+
online: boolean;
|
|
116
|
+
/** Current agent ID if online */
|
|
117
|
+
agentId?: string;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ============================================================================
|
|
121
|
+
// Command Base Types
|
|
122
|
+
// ============================================================================
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Base interface for Command request events
|
|
126
|
+
*/
|
|
127
|
+
interface BaseCommandRequest<T extends string, D = unknown> extends SystemEvent<
|
|
128
|
+
T,
|
|
129
|
+
D,
|
|
130
|
+
"command",
|
|
131
|
+
"request",
|
|
132
|
+
"request"
|
|
133
|
+
> {}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Base interface for Command response events
|
|
137
|
+
*
|
|
138
|
+
* All response data types must extend AgentXResponse to ensure:
|
|
139
|
+
* - Consistent structure (requestId, error)
|
|
140
|
+
* - Automatic client-side handling (__subscriptions, etc.)
|
|
141
|
+
*/
|
|
142
|
+
interface BaseCommandResponse<
|
|
143
|
+
T extends string,
|
|
144
|
+
D extends AgentXResponse = AgentXResponse,
|
|
145
|
+
> extends SystemEvent<T, D, "command", "response", "result"> {}
|
|
146
|
+
|
|
147
|
+
// ============================================================================
|
|
148
|
+
// Container Commands
|
|
149
|
+
// ============================================================================
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Request to create a container
|
|
153
|
+
*/
|
|
154
|
+
export interface ContainerCreateRequest extends BaseCommandRequest<
|
|
155
|
+
"container_create_request",
|
|
156
|
+
{
|
|
157
|
+
requestId: string;
|
|
158
|
+
containerId: string;
|
|
159
|
+
}
|
|
160
|
+
> {}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Response to container creation
|
|
164
|
+
*/
|
|
165
|
+
export interface ContainerCreateResponse extends BaseCommandResponse<
|
|
166
|
+
"container_create_response",
|
|
167
|
+
AgentXResponse & {
|
|
168
|
+
containerId: string;
|
|
169
|
+
}
|
|
170
|
+
> {}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Request to get a container
|
|
174
|
+
*/
|
|
175
|
+
export interface ContainerGetRequest extends BaseCommandRequest<
|
|
176
|
+
"container_get_request",
|
|
177
|
+
{
|
|
178
|
+
requestId: string;
|
|
179
|
+
containerId: string;
|
|
180
|
+
}
|
|
181
|
+
> {}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Response to container get
|
|
185
|
+
*/
|
|
186
|
+
export interface ContainerGetResponse extends BaseCommandResponse<
|
|
187
|
+
"container_get_response",
|
|
188
|
+
AgentXResponse & {
|
|
189
|
+
containerId?: string;
|
|
190
|
+
exists: boolean;
|
|
191
|
+
}
|
|
192
|
+
> {}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Request to list containers
|
|
196
|
+
*/
|
|
197
|
+
export interface ContainerListRequest extends BaseCommandRequest<
|
|
198
|
+
"container_list_request",
|
|
199
|
+
{
|
|
200
|
+
requestId: string;
|
|
201
|
+
}
|
|
202
|
+
> {}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Response to container list
|
|
206
|
+
*/
|
|
207
|
+
export interface ContainerListResponse extends BaseCommandResponse<
|
|
208
|
+
"container_list_response",
|
|
209
|
+
AgentXResponse & {
|
|
210
|
+
containerIds: string[];
|
|
211
|
+
}
|
|
212
|
+
> {}
|
|
213
|
+
|
|
214
|
+
// ============================================================================
|
|
215
|
+
// Agent Commands
|
|
216
|
+
// ============================================================================
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Request to get an agent
|
|
220
|
+
*/
|
|
221
|
+
export interface AgentGetRequest extends BaseCommandRequest<
|
|
222
|
+
"agent_get_request",
|
|
223
|
+
{
|
|
224
|
+
requestId: string;
|
|
225
|
+
agentId: string;
|
|
226
|
+
}
|
|
227
|
+
> {}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Response to agent get
|
|
231
|
+
*/
|
|
232
|
+
export interface AgentGetResponse extends BaseCommandResponse<
|
|
233
|
+
"agent_get_response",
|
|
234
|
+
AgentXResponse & {
|
|
235
|
+
agentId?: string;
|
|
236
|
+
containerId?: string;
|
|
237
|
+
exists: boolean;
|
|
238
|
+
}
|
|
239
|
+
> {}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Request to list agents
|
|
243
|
+
*/
|
|
244
|
+
export interface AgentListRequest extends BaseCommandRequest<
|
|
245
|
+
"agent_list_request",
|
|
246
|
+
{
|
|
247
|
+
requestId: string;
|
|
248
|
+
containerId: string;
|
|
249
|
+
}
|
|
250
|
+
> {}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Response to agent list
|
|
254
|
+
*/
|
|
255
|
+
export interface AgentListResponse extends BaseCommandResponse<
|
|
256
|
+
"agent_list_response",
|
|
257
|
+
AgentXResponse & {
|
|
258
|
+
agents: Array<{ agentId: string; containerId: string; imageId: string }>;
|
|
259
|
+
}
|
|
260
|
+
> {}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Request to destroy an agent
|
|
264
|
+
*/
|
|
265
|
+
export interface AgentDestroyRequest extends BaseCommandRequest<
|
|
266
|
+
"agent_destroy_request",
|
|
267
|
+
{
|
|
268
|
+
requestId: string;
|
|
269
|
+
agentId: string;
|
|
270
|
+
}
|
|
271
|
+
> {}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Response to agent destroy
|
|
275
|
+
*/
|
|
276
|
+
export interface AgentDestroyResponse extends BaseCommandResponse<
|
|
277
|
+
"agent_destroy_response",
|
|
278
|
+
AgentXResponse & {
|
|
279
|
+
agentId: string;
|
|
280
|
+
success: boolean;
|
|
281
|
+
}
|
|
282
|
+
> {}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Request to destroy all agents in a container
|
|
286
|
+
*/
|
|
287
|
+
export interface AgentDestroyAllRequest extends BaseCommandRequest<
|
|
288
|
+
"agent_destroy_all_request",
|
|
289
|
+
{
|
|
290
|
+
requestId: string;
|
|
291
|
+
containerId: string;
|
|
292
|
+
}
|
|
293
|
+
> {}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Response to destroy all agents
|
|
297
|
+
*/
|
|
298
|
+
export interface AgentDestroyAllResponse extends BaseCommandResponse<
|
|
299
|
+
"agent_destroy_all_response",
|
|
300
|
+
AgentXResponse & {
|
|
301
|
+
containerId: string;
|
|
302
|
+
}
|
|
303
|
+
> {}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Request to send a message
|
|
307
|
+
* Can use either imageId (preferred) or agentId
|
|
308
|
+
* If using imageId and agent is not running, it will be auto-activated
|
|
309
|
+
*/
|
|
310
|
+
export interface MessageSendRequest extends BaseCommandRequest<
|
|
311
|
+
"message_send_request",
|
|
312
|
+
{
|
|
313
|
+
requestId: string;
|
|
314
|
+
/** Image ID (preferred) - will auto-activate if offline */
|
|
315
|
+
imageId?: string;
|
|
316
|
+
/** Agent ID (legacy) - must be already running */
|
|
317
|
+
agentId?: string;
|
|
318
|
+
/** Message content (text-only or multimodal) */
|
|
319
|
+
content: string | UserContentPart[];
|
|
320
|
+
}
|
|
321
|
+
> {}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Response to message send (acknowledges message received, not completion)
|
|
325
|
+
*/
|
|
326
|
+
export interface MessageSendResponse extends BaseCommandResponse<
|
|
327
|
+
"message_send_response",
|
|
328
|
+
AgentXResponse & {
|
|
329
|
+
imageId?: string;
|
|
330
|
+
agentId: string;
|
|
331
|
+
}
|
|
332
|
+
> {}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Request to interrupt an agent
|
|
336
|
+
* Can use either imageId or agentId
|
|
337
|
+
*/
|
|
338
|
+
export interface AgentInterruptRequest extends BaseCommandRequest<
|
|
339
|
+
"agent_interrupt_request",
|
|
340
|
+
{
|
|
341
|
+
requestId: string;
|
|
342
|
+
/** Image ID (preferred) */
|
|
343
|
+
imageId?: string;
|
|
344
|
+
/** Agent ID (legacy) */
|
|
345
|
+
agentId?: string;
|
|
346
|
+
}
|
|
347
|
+
> {}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Response to agent interrupt
|
|
351
|
+
*/
|
|
352
|
+
export interface AgentInterruptResponse extends BaseCommandResponse<
|
|
353
|
+
"agent_interrupt_response",
|
|
354
|
+
AgentXResponse & {
|
|
355
|
+
imageId?: string;
|
|
356
|
+
agentId?: string;
|
|
357
|
+
}
|
|
358
|
+
> {}
|
|
359
|
+
|
|
360
|
+
// ============================================================================
|
|
361
|
+
// Image Commands
|
|
362
|
+
// ============================================================================
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Request to create a new image (conversation)
|
|
366
|
+
*/
|
|
367
|
+
export interface ImageCreateRequest extends BaseCommandRequest<
|
|
368
|
+
"image_create_request",
|
|
369
|
+
{
|
|
370
|
+
requestId: string;
|
|
371
|
+
containerId: string;
|
|
372
|
+
config: {
|
|
373
|
+
name?: string;
|
|
374
|
+
description?: string;
|
|
375
|
+
systemPrompt?: string;
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
> {}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Response to image creation
|
|
382
|
+
*
|
|
383
|
+
* Includes __subscriptions with the new image's sessionId for auto-subscription.
|
|
384
|
+
* Note: record is optional because it may be undefined on error.
|
|
385
|
+
*/
|
|
386
|
+
export interface ImageCreateResponse extends BaseCommandResponse<
|
|
387
|
+
"image_create_response",
|
|
388
|
+
AgentXResponse & {
|
|
389
|
+
record?: ImageRecord;
|
|
390
|
+
}
|
|
391
|
+
> {}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Request to run an image (create or reuse agent)
|
|
395
|
+
*/
|
|
396
|
+
export interface ImageRunRequest extends BaseCommandRequest<
|
|
397
|
+
"image_run_request",
|
|
398
|
+
{
|
|
399
|
+
requestId: string;
|
|
400
|
+
imageId: string;
|
|
401
|
+
}
|
|
402
|
+
> {}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Response to image run
|
|
406
|
+
*/
|
|
407
|
+
export interface ImageRunResponse extends BaseCommandResponse<
|
|
408
|
+
"image_run_response",
|
|
409
|
+
AgentXResponse & {
|
|
410
|
+
imageId: string;
|
|
411
|
+
agentId: string;
|
|
412
|
+
/** true if reusing existing agent, false if newly created */
|
|
413
|
+
reused: boolean;
|
|
414
|
+
}
|
|
415
|
+
> {}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Request to stop an image (destroy agent, keep image)
|
|
419
|
+
*/
|
|
420
|
+
export interface ImageStopRequest extends BaseCommandRequest<
|
|
421
|
+
"image_stop_request",
|
|
422
|
+
{
|
|
423
|
+
requestId: string;
|
|
424
|
+
imageId: string;
|
|
425
|
+
}
|
|
426
|
+
> {}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Response to image stop
|
|
430
|
+
*/
|
|
431
|
+
export interface ImageStopResponse extends BaseCommandResponse<
|
|
432
|
+
"image_stop_response",
|
|
433
|
+
AgentXResponse & {
|
|
434
|
+
imageId: string;
|
|
435
|
+
}
|
|
436
|
+
> {}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Request to update an image (name, description, etc.)
|
|
440
|
+
*/
|
|
441
|
+
export interface ImageUpdateRequest extends BaseCommandRequest<
|
|
442
|
+
"image_update_request",
|
|
443
|
+
{
|
|
444
|
+
requestId: string;
|
|
445
|
+
imageId: string;
|
|
446
|
+
updates: {
|
|
447
|
+
name?: string;
|
|
448
|
+
description?: string;
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
> {}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Response to image update
|
|
455
|
+
*
|
|
456
|
+
* Note: record is optional because it may be undefined on error.
|
|
457
|
+
*/
|
|
458
|
+
export interface ImageUpdateResponse extends BaseCommandResponse<
|
|
459
|
+
"image_update_response",
|
|
460
|
+
AgentXResponse & {
|
|
461
|
+
record?: ImageRecord;
|
|
462
|
+
}
|
|
463
|
+
> {}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Request to list all images
|
|
467
|
+
*/
|
|
468
|
+
export interface ImageListRequest extends BaseCommandRequest<
|
|
469
|
+
"image_list_request",
|
|
470
|
+
{
|
|
471
|
+
requestId: string;
|
|
472
|
+
containerId?: string;
|
|
473
|
+
}
|
|
474
|
+
> {}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Response to image list
|
|
478
|
+
*
|
|
479
|
+
* Includes __subscriptions with all images' sessionIds for auto-subscription.
|
|
480
|
+
*/
|
|
481
|
+
export interface ImageListResponse extends BaseCommandResponse<
|
|
482
|
+
"image_list_response",
|
|
483
|
+
AgentXResponse & {
|
|
484
|
+
records: ImageListItem[];
|
|
485
|
+
}
|
|
486
|
+
> {}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Request to get an image by ID
|
|
490
|
+
*/
|
|
491
|
+
export interface ImageGetRequest extends BaseCommandRequest<
|
|
492
|
+
"image_get_request",
|
|
493
|
+
{
|
|
494
|
+
requestId: string;
|
|
495
|
+
imageId: string;
|
|
496
|
+
}
|
|
497
|
+
> {}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Response to image get
|
|
501
|
+
*
|
|
502
|
+
* Includes __subscriptions with the image's sessionId for auto-subscription.
|
|
503
|
+
*/
|
|
504
|
+
export interface ImageGetResponse extends BaseCommandResponse<
|
|
505
|
+
"image_get_response",
|
|
506
|
+
AgentXResponse & {
|
|
507
|
+
record?: ImageListItem | null;
|
|
508
|
+
}
|
|
509
|
+
> {}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Request to delete an image
|
|
513
|
+
*/
|
|
514
|
+
export interface ImageDeleteRequest extends BaseCommandRequest<
|
|
515
|
+
"image_delete_request",
|
|
516
|
+
{
|
|
517
|
+
requestId: string;
|
|
518
|
+
imageId: string;
|
|
519
|
+
}
|
|
520
|
+
> {}
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* Response to image delete
|
|
524
|
+
*/
|
|
525
|
+
export interface ImageDeleteResponse extends BaseCommandResponse<
|
|
526
|
+
"image_delete_response",
|
|
527
|
+
AgentXResponse & {
|
|
528
|
+
imageId: string;
|
|
529
|
+
}
|
|
530
|
+
> {}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Request to get messages for an image
|
|
534
|
+
*/
|
|
535
|
+
export interface ImageMessagesRequest extends BaseCommandRequest<
|
|
536
|
+
"image_messages_request",
|
|
537
|
+
{
|
|
538
|
+
requestId: string;
|
|
539
|
+
imageId: string;
|
|
540
|
+
}
|
|
541
|
+
> {}
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* Response to image messages request
|
|
545
|
+
*/
|
|
546
|
+
export interface ImageMessagesResponse extends BaseCommandResponse<
|
|
547
|
+
"image_messages_response",
|
|
548
|
+
AgentXResponse & {
|
|
549
|
+
imageId: string;
|
|
550
|
+
messages: Array<{
|
|
551
|
+
id: string;
|
|
552
|
+
role: "user" | "assistant" | "tool_call" | "tool_result";
|
|
553
|
+
content: unknown;
|
|
554
|
+
timestamp: number;
|
|
555
|
+
}>;
|
|
556
|
+
}
|
|
557
|
+
> {}
|
|
558
|
+
|
|
559
|
+
// ============================================================================
|
|
560
|
+
// Command Union Types
|
|
561
|
+
// ============================================================================
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* All Command request events
|
|
565
|
+
*/
|
|
566
|
+
export type CommandRequest =
|
|
567
|
+
// Container
|
|
568
|
+
| ContainerCreateRequest
|
|
569
|
+
| ContainerGetRequest
|
|
570
|
+
| ContainerListRequest
|
|
571
|
+
// Agent
|
|
572
|
+
| AgentGetRequest
|
|
573
|
+
| AgentListRequest
|
|
574
|
+
| AgentDestroyRequest
|
|
575
|
+
| AgentDestroyAllRequest
|
|
576
|
+
| MessageSendRequest
|
|
577
|
+
| AgentInterruptRequest
|
|
578
|
+
// Image
|
|
579
|
+
| ImageCreateRequest
|
|
580
|
+
| ImageRunRequest
|
|
581
|
+
| ImageStopRequest
|
|
582
|
+
| ImageUpdateRequest
|
|
583
|
+
| ImageListRequest
|
|
584
|
+
| ImageGetRequest
|
|
585
|
+
| ImageDeleteRequest
|
|
586
|
+
| ImageMessagesRequest;
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* All Command response events
|
|
590
|
+
*/
|
|
591
|
+
export type CommandResponse =
|
|
592
|
+
// Container
|
|
593
|
+
| ContainerCreateResponse
|
|
594
|
+
| ContainerGetResponse
|
|
595
|
+
| ContainerListResponse
|
|
596
|
+
// Agent
|
|
597
|
+
| AgentGetResponse
|
|
598
|
+
| AgentListResponse
|
|
599
|
+
| AgentDestroyResponse
|
|
600
|
+
| AgentDestroyAllResponse
|
|
601
|
+
| MessageSendResponse
|
|
602
|
+
| AgentInterruptResponse
|
|
603
|
+
// Image
|
|
604
|
+
| ImageCreateResponse
|
|
605
|
+
| ImageRunResponse
|
|
606
|
+
| ImageStopResponse
|
|
607
|
+
| ImageUpdateResponse
|
|
608
|
+
| ImageListResponse
|
|
609
|
+
| ImageGetResponse
|
|
610
|
+
| ImageDeleteResponse
|
|
611
|
+
| ImageMessagesResponse;
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* All Command events (requests + responses)
|
|
615
|
+
*/
|
|
616
|
+
export type CommandEvent = CommandRequest | CommandResponse;
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Command event type strings
|
|
620
|
+
*/
|
|
621
|
+
export type CommandEventType = CommandEvent["type"];
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Type guard: is this a CommandEvent?
|
|
625
|
+
*/
|
|
626
|
+
export function isCommandEvent(event: { source?: string }): event is CommandEvent {
|
|
627
|
+
return event.source === "command";
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* Type guard: is this a Command request event?
|
|
632
|
+
*/
|
|
633
|
+
export function isCommandRequest(event: {
|
|
634
|
+
source?: string;
|
|
635
|
+
category?: string;
|
|
636
|
+
}): event is CommandRequest {
|
|
637
|
+
return event.source === "command" && event.category === "request";
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* Type guard: is this a Command response event?
|
|
642
|
+
*/
|
|
643
|
+
export function isCommandResponse(event: {
|
|
644
|
+
source?: string;
|
|
645
|
+
category?: string;
|
|
646
|
+
}): event is CommandResponse {
|
|
647
|
+
return event.source === "command" && event.category === "response";
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// ============================================================================
|
|
651
|
+
// Command Event Map
|
|
652
|
+
// ============================================================================
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* CommandEventMap - Maps event type string to event interface
|
|
656
|
+
*
|
|
657
|
+
* Enables type-safe event handling:
|
|
658
|
+
* ```typescript
|
|
659
|
+
* bus.onCommand("container_create_request", (event) => {
|
|
660
|
+
* event.data.requestId; // string
|
|
661
|
+
* event.data.containerId; // string
|
|
662
|
+
* });
|
|
663
|
+
* ```
|
|
664
|
+
*/
|
|
665
|
+
export interface CommandEventMap {
|
|
666
|
+
// Container
|
|
667
|
+
container_create_request: ContainerCreateRequest;
|
|
668
|
+
container_create_response: ContainerCreateResponse;
|
|
669
|
+
container_get_request: ContainerGetRequest;
|
|
670
|
+
container_get_response: ContainerGetResponse;
|
|
671
|
+
container_list_request: ContainerListRequest;
|
|
672
|
+
container_list_response: ContainerListResponse;
|
|
673
|
+
// Agent
|
|
674
|
+
agent_get_request: AgentGetRequest;
|
|
675
|
+
agent_get_response: AgentGetResponse;
|
|
676
|
+
agent_list_request: AgentListRequest;
|
|
677
|
+
agent_list_response: AgentListResponse;
|
|
678
|
+
agent_destroy_request: AgentDestroyRequest;
|
|
679
|
+
agent_destroy_response: AgentDestroyResponse;
|
|
680
|
+
agent_destroy_all_request: AgentDestroyAllRequest;
|
|
681
|
+
agent_destroy_all_response: AgentDestroyAllResponse;
|
|
682
|
+
message_send_request: MessageSendRequest;
|
|
683
|
+
message_send_response: MessageSendResponse;
|
|
684
|
+
agent_interrupt_request: AgentInterruptRequest;
|
|
685
|
+
agent_interrupt_response: AgentInterruptResponse;
|
|
686
|
+
// Image
|
|
687
|
+
image_create_request: ImageCreateRequest;
|
|
688
|
+
image_create_response: ImageCreateResponse;
|
|
689
|
+
image_run_request: ImageRunRequest;
|
|
690
|
+
image_run_response: ImageRunResponse;
|
|
691
|
+
image_stop_request: ImageStopRequest;
|
|
692
|
+
image_stop_response: ImageStopResponse;
|
|
693
|
+
image_update_request: ImageUpdateRequest;
|
|
694
|
+
image_update_response: ImageUpdateResponse;
|
|
695
|
+
image_list_request: ImageListRequest;
|
|
696
|
+
image_list_response: ImageListResponse;
|
|
697
|
+
image_get_request: ImageGetRequest;
|
|
698
|
+
image_get_response: ImageGetResponse;
|
|
699
|
+
image_delete_request: ImageDeleteRequest;
|
|
700
|
+
image_delete_response: ImageDeleteResponse;
|
|
701
|
+
image_messages_request: ImageMessagesRequest;
|
|
702
|
+
image_messages_response: ImageMessagesResponse;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* Maps request event type to its corresponding response event type
|
|
707
|
+
*/
|
|
708
|
+
export interface CommandRequestResponseMap {
|
|
709
|
+
container_create_request: "container_create_response";
|
|
710
|
+
container_get_request: "container_get_response";
|
|
711
|
+
container_list_request: "container_list_response";
|
|
712
|
+
agent_get_request: "agent_get_response";
|
|
713
|
+
agent_list_request: "agent_list_response";
|
|
714
|
+
agent_destroy_request: "agent_destroy_response";
|
|
715
|
+
agent_destroy_all_request: "agent_destroy_all_response";
|
|
716
|
+
message_send_request: "message_send_response";
|
|
717
|
+
agent_interrupt_request: "agent_interrupt_response";
|
|
718
|
+
image_create_request: "image_create_response";
|
|
719
|
+
image_run_request: "image_run_response";
|
|
720
|
+
image_stop_request: "image_stop_response";
|
|
721
|
+
image_update_request: "image_update_response";
|
|
722
|
+
image_list_request: "image_list_response";
|
|
723
|
+
image_get_request: "image_get_response";
|
|
724
|
+
image_delete_request: "image_delete_response";
|
|
725
|
+
image_messages_request: "image_messages_response";
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
/**
|
|
729
|
+
* All command request types
|
|
730
|
+
*/
|
|
731
|
+
export type CommandRequestType = keyof CommandRequestResponseMap;
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* Get response type for a request type
|
|
735
|
+
*/
|
|
736
|
+
export type ResponseTypeFor<T extends CommandRequestType> = CommandRequestResponseMap[T];
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* Get response event for a request type
|
|
740
|
+
*/
|
|
741
|
+
export type ResponseEventFor<T extends CommandRequestType> = CommandEventMap[ResponseTypeFor<T>];
|
|
742
|
+
|
|
743
|
+
/**
|
|
744
|
+
* Get request data type (without requestId, as it's auto-generated)
|
|
745
|
+
*/
|
|
746
|
+
export type RequestDataFor<T extends CommandRequestType> = Omit<
|
|
747
|
+
CommandEventMap[T]["data"],
|
|
748
|
+
"requestId"
|
|
749
|
+
>;
|