@agentxjs/types 0.0.9 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Agent-BXUYGlWZ.d.cts +510 -0
- package/dist/Agent-CaSxMF_E.d.ts +510 -0
- package/dist/CommandEvent-CbXzPolX.d.ts +495 -0
- package/dist/CommandEvent-DCdk7lzX.d.cts +495 -0
- package/dist/Container-DR-1g44i.d.ts +641 -0
- package/dist/Container-dBDOcjhk.d.cts +641 -0
- package/dist/ContentPart-CqOh-rI1.d.ts +19 -0
- package/dist/ContentPart-DEFnYXCU.d.cts +19 -0
- package/dist/DriveableEvent-Bj7nn-Uk.d.ts +161 -0
- package/dist/DriveableEvent-CCMC1h_C.d.cts +161 -0
- package/dist/ErrorMessage-BoIh3MIO.d.cts +24 -0
- package/dist/ErrorMessage-BoIh3MIO.d.ts +24 -0
- package/dist/ImageRecord-Cn0VcJWk.d.cts +71 -0
- package/dist/ImageRecord-Cn0VcJWk.d.ts +71 -0
- package/dist/LoggerFactory-DZtw0M7U.d.cts +129 -0
- package/dist/LoggerFactory-DZtw0M7U.d.ts +129 -0
- package/dist/Message-Crh81uLL.d.cts +45 -0
- package/dist/Message-DWQUt647.d.ts +45 -0
- package/dist/Persistence-BQkdKomV.d.ts +230 -0
- package/dist/Persistence-Dr70FEBh.d.cts +230 -0
- package/dist/StopReason-D4DthB1h.d.cts +39 -0
- package/dist/StopReason-D4DthB1h.d.ts +39 -0
- package/dist/SystemEvent-CPvvxdMQ.d.cts +159 -0
- package/dist/SystemEvent-CPvvxdMQ.d.ts +159 -0
- package/dist/ToolResultMessage-CDG2L7Zv.d.ts +332 -0
- package/dist/ToolResultMessage-CRKMSf5d.d.cts +332 -0
- package/dist/agent-internal.cjs +19 -0
- package/dist/agent-internal.cjs.map +1 -0
- package/dist/agent-internal.d.cts +52 -0
- package/dist/agent-internal.d.ts +52 -0
- package/dist/agent-internal.js +1 -0
- package/dist/agent-internal.js.map +1 -0
- package/dist/agent.cjs +70 -0
- package/dist/agent.cjs.map +1 -0
- package/dist/agent.d.cts +229 -0
- package/dist/agent.d.ts +229 -0
- package/dist/agent.js +41 -0
- package/dist/agent.js.map +1 -0
- package/dist/agentx.cjs +38 -0
- package/dist/agentx.cjs.map +1 -0
- package/dist/agentx.d.cts +311 -0
- package/dist/agentx.d.ts +311 -0
- package/dist/agentx.js +12 -0
- package/dist/agentx.js.map +1 -0
- package/dist/chunk-2QHAIM3V.js +1 -0
- package/dist/chunk-2QHAIM3V.js.map +1 -0
- package/dist/common.cjs +19 -0
- package/dist/common.cjs.map +1 -0
- package/dist/common.d.cts +43 -0
- package/dist/common.d.ts +43 -0
- package/dist/common.js +2 -0
- package/dist/common.js.map +1 -0
- package/dist/event.cjs +184 -0
- package/dist/event.cjs.map +1 -0
- package/dist/event.d.cts +769 -0
- package/dist/event.d.ts +769 -0
- package/dist/event.js +134 -0
- package/dist/event.js.map +1 -0
- package/dist/index-CjFNcCxR.d.cts +299 -0
- package/dist/index-usKuk41S.d.ts +299 -0
- package/dist/index.cjs +2 -185
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -5267
- package/dist/index.d.ts +8 -5267
- package/dist/index.js +1 -150
- package/dist/index.js.map +1 -1
- package/dist/network.cjs +19 -0
- package/dist/network.cjs.map +1 -0
- package/dist/network.d.cts +168 -0
- package/dist/network.d.ts +168 -0
- package/dist/network.js +1 -0
- package/dist/network.js.map +1 -0
- package/dist/runtime-internal.cjs +19 -0
- package/dist/runtime-internal.cjs.map +1 -0
- package/dist/runtime-internal.d.cts +943 -0
- package/dist/runtime-internal.d.ts +943 -0
- package/dist/runtime-internal.js +1 -0
- package/dist/runtime-internal.js.map +1 -0
- package/dist/runtime.cjs +19 -0
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.cts +217 -0
- package/dist/runtime.d.ts +217 -0
- package/dist/runtime.js +1 -0
- package/dist/runtime.js.map +1 -0
- package/package.json +82 -10
- package/LICENSE +0 -21
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
import { S as SystemEvent } from './SystemEvent-CPvvxdMQ.js';
|
|
2
|
+
import { b as CommandEventMap, C as CommandRequestType, R as RequestDataFor, a as ResponseEventFor } from './CommandEvent-CbXzPolX.js';
|
|
3
|
+
import { I as ImageRecord } from './ImageRecord-Cn0VcJWk.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* SystemBusProducer - Write-only view of SystemBus
|
|
7
|
+
*
|
|
8
|
+
* Used by components that produce events:
|
|
9
|
+
* - Effector (emits DriveableEvents from Claude API)
|
|
10
|
+
* - Receptor (emits stream events)
|
|
11
|
+
* - Agent (emits state/message events)
|
|
12
|
+
*
|
|
13
|
+
* Producer can only emit events, cannot subscribe.
|
|
14
|
+
* This prevents accidental event loops and clarifies data flow.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* class Effector {
|
|
19
|
+
* constructor(private producer: SystemBusProducer) {}
|
|
20
|
+
*
|
|
21
|
+
* async sendMessage(message: UserMessage) {
|
|
22
|
+
* // Can only emit, cannot subscribe
|
|
23
|
+
* this.producer.emit({
|
|
24
|
+
* type: "message_start",
|
|
25
|
+
* source: "environment",
|
|
26
|
+
* category: "stream",
|
|
27
|
+
* ...
|
|
28
|
+
* });
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* SystemBusProducer interface - Write-only view
|
|
36
|
+
*
|
|
37
|
+
* Components receiving this interface can only emit events,
|
|
38
|
+
* preventing them from creating event loops by subscribing.
|
|
39
|
+
*/
|
|
40
|
+
interface SystemBusProducer {
|
|
41
|
+
/**
|
|
42
|
+
* Emit a single event to the bus
|
|
43
|
+
*
|
|
44
|
+
* @param event - The event to emit
|
|
45
|
+
*/
|
|
46
|
+
emit(event: SystemEvent): void;
|
|
47
|
+
/**
|
|
48
|
+
* Emit multiple events (batch operation)
|
|
49
|
+
*
|
|
50
|
+
* @param events - Array of events to emit
|
|
51
|
+
*/
|
|
52
|
+
emitBatch(events: SystemEvent[]): void;
|
|
53
|
+
/**
|
|
54
|
+
* Emit a typed command event
|
|
55
|
+
*
|
|
56
|
+
* @param type - The command event type
|
|
57
|
+
* @param data - Event data (type-checked)
|
|
58
|
+
*/
|
|
59
|
+
emitCommand<T extends keyof CommandEventMap>(type: T, data: CommandEventMap[T]["data"]): void;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* SystemBusConsumer - Read-only view of SystemBus
|
|
64
|
+
*
|
|
65
|
+
* Used by components that consume events:
|
|
66
|
+
* - BusDriver (subscribes to DriveableEvents)
|
|
67
|
+
* - UI components (subscribes to display events)
|
|
68
|
+
* - Presenters (subscribes to forward events)
|
|
69
|
+
*
|
|
70
|
+
* Consumer can only subscribe to events, cannot emit.
|
|
71
|
+
* This prevents accidental event emission and clarifies data flow.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* class BusDriver {
|
|
76
|
+
* constructor(private consumer: SystemBusConsumer) {}
|
|
77
|
+
*
|
|
78
|
+
* async *receive(message: UserMessage) {
|
|
79
|
+
* // Can only subscribe, cannot emit
|
|
80
|
+
* this.consumer.on('message_start', (event) => {
|
|
81
|
+
* console.log('Received:', event.type);
|
|
82
|
+
* });
|
|
83
|
+
* }
|
|
84
|
+
* }
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Unsubscribe function type
|
|
90
|
+
*/
|
|
91
|
+
type Unsubscribe$1 = () => void;
|
|
92
|
+
/**
|
|
93
|
+
* Event handler function type
|
|
94
|
+
*/
|
|
95
|
+
type BusEventHandler$1<E extends SystemEvent = SystemEvent> = (event: E) => void;
|
|
96
|
+
/**
|
|
97
|
+
* Subscription options for advanced event handling
|
|
98
|
+
*/
|
|
99
|
+
interface SubscribeOptions$1<E extends SystemEvent = SystemEvent> {
|
|
100
|
+
/**
|
|
101
|
+
* Event filter - only events returning true will trigger the handler
|
|
102
|
+
* Useful for filtering by agentId, sessionId, etc.
|
|
103
|
+
*/
|
|
104
|
+
filter?: (event: E) => boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Priority - higher numbers execute first (default: 0)
|
|
107
|
+
* Useful for ensuring certain handlers run before others
|
|
108
|
+
*/
|
|
109
|
+
priority?: number;
|
|
110
|
+
/**
|
|
111
|
+
* Whether to trigger only once then auto-unsubscribe
|
|
112
|
+
*/
|
|
113
|
+
once?: boolean;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* SystemBusConsumer interface - Read-only view
|
|
117
|
+
*
|
|
118
|
+
* Components receiving this interface can only subscribe to events,
|
|
119
|
+
* preventing them from emitting events.
|
|
120
|
+
*/
|
|
121
|
+
interface SystemBusConsumer {
|
|
122
|
+
/**
|
|
123
|
+
* Subscribe to a specific event type
|
|
124
|
+
*
|
|
125
|
+
* @param type - The event type to listen for
|
|
126
|
+
* @param handler - Callback invoked when event is received
|
|
127
|
+
* @param options - Subscription options (filter, priority, once)
|
|
128
|
+
* @returns Unsubscribe function
|
|
129
|
+
*/
|
|
130
|
+
on<T extends string>(type: T, handler: BusEventHandler$1<SystemEvent & {
|
|
131
|
+
type: T;
|
|
132
|
+
}>, options?: SubscribeOptions$1<SystemEvent & {
|
|
133
|
+
type: T;
|
|
134
|
+
}>): Unsubscribe$1;
|
|
135
|
+
/**
|
|
136
|
+
* Subscribe to multiple event types
|
|
137
|
+
*
|
|
138
|
+
* @param types - Array of event types to listen for
|
|
139
|
+
* @param handler - Callback invoked when any matching event is received
|
|
140
|
+
* @param options - Subscription options
|
|
141
|
+
* @returns Unsubscribe function
|
|
142
|
+
*/
|
|
143
|
+
on(types: string[], handler: BusEventHandler$1, options?: SubscribeOptions$1): Unsubscribe$1;
|
|
144
|
+
/**
|
|
145
|
+
* Subscribe to all events
|
|
146
|
+
*
|
|
147
|
+
* @param handler - Callback invoked for every event
|
|
148
|
+
* @param options - Subscription options
|
|
149
|
+
* @returns Unsubscribe function
|
|
150
|
+
*/
|
|
151
|
+
onAny(handler: BusEventHandler$1, options?: SubscribeOptions$1): Unsubscribe$1;
|
|
152
|
+
/**
|
|
153
|
+
* Subscribe to an event type once (auto-unsubscribes after first trigger)
|
|
154
|
+
*
|
|
155
|
+
* @param type - Event type to subscribe to
|
|
156
|
+
* @param handler - Callback function
|
|
157
|
+
* @returns Unsubscribe function
|
|
158
|
+
*/
|
|
159
|
+
once<T extends string>(type: T, handler: BusEventHandler$1<SystemEvent & {
|
|
160
|
+
type: T;
|
|
161
|
+
}>): Unsubscribe$1;
|
|
162
|
+
/**
|
|
163
|
+
* Subscribe to a CommandEvent with full type safety
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* consumer.onCommand("container_create_request", (event) => {
|
|
168
|
+
* event.data.requestId; // ✓ string
|
|
169
|
+
* event.data.containerId; // ✓ string
|
|
170
|
+
* });
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* @param type - The command event type
|
|
174
|
+
* @param handler - Callback with fully typed event
|
|
175
|
+
* @returns Unsubscribe function
|
|
176
|
+
*/
|
|
177
|
+
onCommand<T extends keyof CommandEventMap>(type: T, handler: (event: CommandEventMap[T]) => void): Unsubscribe$1;
|
|
178
|
+
/**
|
|
179
|
+
* Send a command request and wait for response
|
|
180
|
+
*
|
|
181
|
+
* Automatically generates requestId, emits request, waits for matching response.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* const response = await consumer.request("container_create_request", {
|
|
186
|
+
* containerId: "my-container"
|
|
187
|
+
* });
|
|
188
|
+
* // response is ContainerCreateResponse
|
|
189
|
+
* console.log(response.data.containerId);
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* @param type - The request event type
|
|
193
|
+
* @param data - Request data (without requestId)
|
|
194
|
+
* @param timeout - Timeout in milliseconds (default: 30000)
|
|
195
|
+
* @returns Promise of response event
|
|
196
|
+
*/
|
|
197
|
+
request<T extends CommandRequestType>(type: T, data: RequestDataFor<T>, timeout?: number): Promise<ResponseEventFor<T>>;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* SystemBus - Central event bus for the ecosystem.
|
|
202
|
+
*
|
|
203
|
+
* All components communicate through the SystemBus:
|
|
204
|
+
* - Environment emits EnvironmentEvents (text_chunk, stream_start, etc.)
|
|
205
|
+
* - Agent emits AgentEvents (state changes, messages, etc.)
|
|
206
|
+
* - Session, Container emit their respective events
|
|
207
|
+
*
|
|
208
|
+
* Features:
|
|
209
|
+
* - Type-safe event subscription
|
|
210
|
+
* - Custom filters
|
|
211
|
+
* - Priority-based execution order
|
|
212
|
+
* - One-time subscriptions
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```typescript
|
|
216
|
+
* const bus = new SystemBusImpl();
|
|
217
|
+
*
|
|
218
|
+
* // Subscribe to specific event type
|
|
219
|
+
* bus.on('text_chunk', (e) => {
|
|
220
|
+
* console.log('Received text:', e.data.text);
|
|
221
|
+
* });
|
|
222
|
+
*
|
|
223
|
+
* // Subscribe with options
|
|
224
|
+
* bus.on('text_delta', handler, {
|
|
225
|
+
* filter: (e) => e.agentId === 'agent-1',
|
|
226
|
+
* priority: 10,
|
|
227
|
+
* once: true
|
|
228
|
+
* });
|
|
229
|
+
*
|
|
230
|
+
* // Subscribe to all events
|
|
231
|
+
* bus.onAny((e) => {
|
|
232
|
+
* console.log('Event:', e.type);
|
|
233
|
+
* });
|
|
234
|
+
*
|
|
235
|
+
* // Emit event
|
|
236
|
+
* bus.emit({ type: 'text_chunk', data: { text: 'Hello' } });
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Unsubscribe function type.
|
|
242
|
+
*/
|
|
243
|
+
type Unsubscribe = () => void;
|
|
244
|
+
/**
|
|
245
|
+
* Event handler function type.
|
|
246
|
+
*/
|
|
247
|
+
type BusEventHandler<E extends SystemEvent = SystemEvent> = (event: E) => void;
|
|
248
|
+
/**
|
|
249
|
+
* Subscription options for advanced event handling.
|
|
250
|
+
*/
|
|
251
|
+
interface SubscribeOptions<E extends SystemEvent = SystemEvent> {
|
|
252
|
+
/**
|
|
253
|
+
* Event filter - only events returning true will trigger the handler.
|
|
254
|
+
* Useful for filtering by agentId, sessionId, etc.
|
|
255
|
+
*/
|
|
256
|
+
filter?: (event: E) => boolean;
|
|
257
|
+
/**
|
|
258
|
+
* Priority - higher numbers execute first (default: 0).
|
|
259
|
+
* Useful for ensuring certain handlers run before others.
|
|
260
|
+
*/
|
|
261
|
+
priority?: number;
|
|
262
|
+
/**
|
|
263
|
+
* Whether to trigger only once then auto-unsubscribe.
|
|
264
|
+
*/
|
|
265
|
+
once?: boolean;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* SystemBus interface - Central event bus for ecosystem communication.
|
|
269
|
+
*
|
|
270
|
+
* Extends both Producer and Consumer interfaces for internal use.
|
|
271
|
+
* External components should use restricted views via asProducer/asConsumer.
|
|
272
|
+
*/
|
|
273
|
+
interface SystemBus {
|
|
274
|
+
/**
|
|
275
|
+
* Emit an event to the bus.
|
|
276
|
+
*
|
|
277
|
+
* All subscribed handlers will receive this event.
|
|
278
|
+
*
|
|
279
|
+
* @param event - The event to emit
|
|
280
|
+
*/
|
|
281
|
+
emit(event: SystemEvent): void;
|
|
282
|
+
/**
|
|
283
|
+
* Emit multiple events (batch operation).
|
|
284
|
+
*
|
|
285
|
+
* @param events - Array of events to emit
|
|
286
|
+
*/
|
|
287
|
+
emitBatch(events: SystemEvent[]): void;
|
|
288
|
+
/**
|
|
289
|
+
* Subscribe to a specific event type.
|
|
290
|
+
*
|
|
291
|
+
* @param type - The event type to listen for
|
|
292
|
+
* @param handler - Callback invoked when event is received
|
|
293
|
+
* @param options - Subscription options (filter, priority, once)
|
|
294
|
+
* @returns Unsubscribe function
|
|
295
|
+
*/
|
|
296
|
+
on<T extends string>(type: T, handler: BusEventHandler<SystemEvent & {
|
|
297
|
+
type: T;
|
|
298
|
+
}>, options?: SubscribeOptions<SystemEvent & {
|
|
299
|
+
type: T;
|
|
300
|
+
}>): Unsubscribe;
|
|
301
|
+
/**
|
|
302
|
+
* Subscribe to multiple event types.
|
|
303
|
+
*
|
|
304
|
+
* @param types - Array of event types to listen for
|
|
305
|
+
* @param handler - Callback invoked when any matching event is received
|
|
306
|
+
* @param options - Subscription options
|
|
307
|
+
* @returns Unsubscribe function
|
|
308
|
+
*/
|
|
309
|
+
on(types: string[], handler: BusEventHandler, options?: SubscribeOptions): Unsubscribe;
|
|
310
|
+
/**
|
|
311
|
+
* Subscribe to all events.
|
|
312
|
+
*
|
|
313
|
+
* @param handler - Callback invoked for every event
|
|
314
|
+
* @param options - Subscription options
|
|
315
|
+
* @returns Unsubscribe function
|
|
316
|
+
*/
|
|
317
|
+
onAny(handler: BusEventHandler, options?: SubscribeOptions): Unsubscribe;
|
|
318
|
+
/**
|
|
319
|
+
* Subscribe to an event type once (auto-unsubscribes after first trigger).
|
|
320
|
+
*
|
|
321
|
+
* @param type - Event type to subscribe to
|
|
322
|
+
* @param handler - Callback function
|
|
323
|
+
* @returns Unsubscribe function
|
|
324
|
+
*/
|
|
325
|
+
once<T extends string>(type: T, handler: BusEventHandler<SystemEvent & {
|
|
326
|
+
type: T;
|
|
327
|
+
}>): Unsubscribe;
|
|
328
|
+
/**
|
|
329
|
+
* Subscribe to a CommandEvent with full type safety.
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* ```typescript
|
|
333
|
+
* bus.onCommand("container_create_request", (event) => {
|
|
334
|
+
* event.data.requestId; // ✓ string
|
|
335
|
+
* event.data.containerId; // ✓ string
|
|
336
|
+
* });
|
|
337
|
+
* ```
|
|
338
|
+
*
|
|
339
|
+
* @param type - The command event type
|
|
340
|
+
* @param handler - Callback with fully typed event
|
|
341
|
+
* @returns Unsubscribe function
|
|
342
|
+
*/
|
|
343
|
+
onCommand<T extends keyof CommandEventMap>(type: T, handler: (event: CommandEventMap[T]) => void): Unsubscribe;
|
|
344
|
+
/**
|
|
345
|
+
* Emit a CommandEvent with full type safety.
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* ```typescript
|
|
349
|
+
* bus.emitCommand("container_create_request", {
|
|
350
|
+
* requestId: "req_123",
|
|
351
|
+
* containerId: "my-container"
|
|
352
|
+
* });
|
|
353
|
+
* ```
|
|
354
|
+
*
|
|
355
|
+
* @param type - The command event type
|
|
356
|
+
* @param data - Event data (type-checked)
|
|
357
|
+
*/
|
|
358
|
+
emitCommand<T extends keyof CommandEventMap>(type: T, data: CommandEventMap[T]["data"]): void;
|
|
359
|
+
/**
|
|
360
|
+
* Send a command request and wait for response.
|
|
361
|
+
*
|
|
362
|
+
* Automatically generates requestId, emits request, waits for matching response.
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* ```typescript
|
|
366
|
+
* const response = await bus.request("container_create_request", {
|
|
367
|
+
* containerId: "my-container"
|
|
368
|
+
* });
|
|
369
|
+
* // response is ContainerCreateResponse
|
|
370
|
+
* console.log(response.data.containerId);
|
|
371
|
+
* ```
|
|
372
|
+
*
|
|
373
|
+
* @param type - The request event type
|
|
374
|
+
* @param data - Request data (without requestId)
|
|
375
|
+
* @param timeout - Timeout in milliseconds (default: 30000)
|
|
376
|
+
* @returns Promise of response event
|
|
377
|
+
*/
|
|
378
|
+
request<T extends CommandRequestType>(type: T, data: RequestDataFor<T>, timeout?: number): Promise<ResponseEventFor<T>>;
|
|
379
|
+
/**
|
|
380
|
+
* Get a read-only consumer view of the bus.
|
|
381
|
+
*
|
|
382
|
+
* Use this to safely expose event subscription to external code
|
|
383
|
+
* without allowing them to emit events.
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* ```typescript
|
|
387
|
+
* class BusDriver {
|
|
388
|
+
* constructor(consumer: SystemBusConsumer) {
|
|
389
|
+
* // Can only subscribe, cannot emit
|
|
390
|
+
* consumer.on('text_delta', ...);
|
|
391
|
+
* }
|
|
392
|
+
* }
|
|
393
|
+
* ```
|
|
394
|
+
*
|
|
395
|
+
* @returns SystemBusConsumer - Read-only view
|
|
396
|
+
*/
|
|
397
|
+
asConsumer(): SystemBusConsumer;
|
|
398
|
+
/**
|
|
399
|
+
* Get a write-only producer view of the bus.
|
|
400
|
+
*
|
|
401
|
+
* Use this to give components the ability to emit events
|
|
402
|
+
* without exposing subscription capabilities.
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```typescript
|
|
406
|
+
* class ClaudeReceptor {
|
|
407
|
+
* constructor(producer: SystemBusProducer) {
|
|
408
|
+
* // Can only emit, cannot subscribe
|
|
409
|
+
* producer.emit({ type: 'text_delta', ... });
|
|
410
|
+
* }
|
|
411
|
+
* }
|
|
412
|
+
* ```
|
|
413
|
+
*
|
|
414
|
+
* @returns SystemBusProducer - Write-only view
|
|
415
|
+
*/
|
|
416
|
+
asProducer(): SystemBusProducer;
|
|
417
|
+
/**
|
|
418
|
+
* Destroy the bus and clean up resources.
|
|
419
|
+
*
|
|
420
|
+
* All subscriptions will be terminated.
|
|
421
|
+
* After calling destroy():
|
|
422
|
+
* - All subscriptions are removed
|
|
423
|
+
* - New emissions are ignored
|
|
424
|
+
* - New subscriptions are no-ops
|
|
425
|
+
*/
|
|
426
|
+
destroy(): void;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* AgentLifecycle - Runtime Agent lifecycle states
|
|
431
|
+
*
|
|
432
|
+
* - running: Agent is active, can receive messages
|
|
433
|
+
* - stopped: Agent is paused, session data preserved, can resume
|
|
434
|
+
* - destroyed: Agent is removed, all data cleaned up
|
|
435
|
+
*/
|
|
436
|
+
type AgentLifecycle = "running" | "stopped" | "destroyed";
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Agent - Runtime Agent (Complete Runtime Entity)
|
|
440
|
+
*
|
|
441
|
+
* A complete runtime agent composed of:
|
|
442
|
+
* - LLM: Large Language Model connection
|
|
443
|
+
* - Sandbox: Isolated environment (filesystem, permissions, tools)
|
|
444
|
+
* - Engine: Event processing state machine
|
|
445
|
+
* - Session: Conversation history (persisted)
|
|
446
|
+
*
|
|
447
|
+
* Managed by Container, supports stop/resume lifecycle.
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
* ```typescript
|
|
451
|
+
* const agent = await runtime.agents.run(containerId, config);
|
|
452
|
+
*
|
|
453
|
+
* // Interact
|
|
454
|
+
* runtime.events.on("text_delta", (e) => console.log(e.data.text));
|
|
455
|
+
* await agent.receive("Hello!");
|
|
456
|
+
*
|
|
457
|
+
* // Pause (session preserved)
|
|
458
|
+
* await agent.stop();
|
|
459
|
+
*
|
|
460
|
+
* // Resume later
|
|
461
|
+
* await agent.resume();
|
|
462
|
+
*
|
|
463
|
+
* // Destroy (cleanup everything)
|
|
464
|
+
* await agent.destroy();
|
|
465
|
+
* ```
|
|
466
|
+
*/
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Runtime Agent interface
|
|
470
|
+
*/
|
|
471
|
+
interface Agent {
|
|
472
|
+
/**
|
|
473
|
+
* Unique agent identifier
|
|
474
|
+
*/
|
|
475
|
+
readonly agentId: string;
|
|
476
|
+
/**
|
|
477
|
+
* Agent name (from config or default)
|
|
478
|
+
*/
|
|
479
|
+
readonly name: string;
|
|
480
|
+
/**
|
|
481
|
+
* Parent container ID
|
|
482
|
+
*/
|
|
483
|
+
readonly containerId: string;
|
|
484
|
+
/**
|
|
485
|
+
* Current lifecycle state
|
|
486
|
+
*/
|
|
487
|
+
readonly lifecycle: AgentLifecycle;
|
|
488
|
+
/**
|
|
489
|
+
* Creation timestamp (Unix milliseconds)
|
|
490
|
+
*/
|
|
491
|
+
readonly createdAt: number;
|
|
492
|
+
/**
|
|
493
|
+
* Send a message to the agent
|
|
494
|
+
*
|
|
495
|
+
* @param message - User message content
|
|
496
|
+
* @param requestId - Optional request ID for event correlation
|
|
497
|
+
*/
|
|
498
|
+
receive(message: string, requestId?: string): Promise<void>;
|
|
499
|
+
/**
|
|
500
|
+
* Interrupt current processing
|
|
501
|
+
*
|
|
502
|
+
* Stops the current operation gracefully.
|
|
503
|
+
*
|
|
504
|
+
* @param requestId - Optional request ID for event correlation
|
|
505
|
+
*/
|
|
506
|
+
interrupt(requestId?: string): void;
|
|
507
|
+
/**
|
|
508
|
+
* Stop the agent
|
|
509
|
+
*
|
|
510
|
+
* Pauses the agent, preserving session data.
|
|
511
|
+
* Can be resumed later with resume().
|
|
512
|
+
*/
|
|
513
|
+
stop(): Promise<void>;
|
|
514
|
+
/**
|
|
515
|
+
* Resume a stopped agent
|
|
516
|
+
*
|
|
517
|
+
* Restores the agent from preserved session data.
|
|
518
|
+
*/
|
|
519
|
+
resume(): Promise<void>;
|
|
520
|
+
/**
|
|
521
|
+
* Destroy the agent
|
|
522
|
+
*
|
|
523
|
+
* Completely removes the agent and all associated data.
|
|
524
|
+
* Cannot be resumed after destruction.
|
|
525
|
+
*/
|
|
526
|
+
destroy(): Promise<void>;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Container - Runtime environment for Agent instances
|
|
531
|
+
*
|
|
532
|
+
* Container is a runtime isolation boundary where Agents live and work.
|
|
533
|
+
* Each Container manages multiple Agents, each with its own Sandbox.
|
|
534
|
+
*
|
|
535
|
+
* In the Image-First model:
|
|
536
|
+
* - Image is the persistent entity (conversation)
|
|
537
|
+
* - Agent is a transient runtime instance of an Image
|
|
538
|
+
* - Container tracks imageId → agentId mapping
|
|
539
|
+
*
|
|
540
|
+
* Architecture:
|
|
541
|
+
* ```
|
|
542
|
+
* Container
|
|
543
|
+
* └── Image 1 ──→ Agent 1 ─── Sandbox 1
|
|
544
|
+
* └── Image 2 ──→ (offline)
|
|
545
|
+
* └── Image 3 ──→ Agent 3 ─── Sandbox 3
|
|
546
|
+
* ```
|
|
547
|
+
*
|
|
548
|
+
* Container provides:
|
|
549
|
+
* - Image → Agent lifecycle management (runImage, stopImage)
|
|
550
|
+
* - Sandbox creation per Agent (encapsulated)
|
|
551
|
+
* - Runtime isolation between Containers
|
|
552
|
+
* - Foundation for multi-agent collaboration
|
|
553
|
+
*
|
|
554
|
+
* @example
|
|
555
|
+
* ```typescript
|
|
556
|
+
* // Create container via Runtime
|
|
557
|
+
* const container = await runtime.containers.create("container-1");
|
|
558
|
+
*
|
|
559
|
+
* // Run an agent from an image
|
|
560
|
+
* const { agent, reused } = await container.runImage(imageRecord);
|
|
561
|
+
*
|
|
562
|
+
* // Use the agent
|
|
563
|
+
* await agent.receive("Hello!");
|
|
564
|
+
*
|
|
565
|
+
* // Stop the image (destroys agent, keeps image)
|
|
566
|
+
* await container.stopImage(imageId);
|
|
567
|
+
*
|
|
568
|
+
* // Dispose container
|
|
569
|
+
* await container.dispose();
|
|
570
|
+
* ```
|
|
571
|
+
*/
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Container interface for managing Agent instances at runtime
|
|
575
|
+
*/
|
|
576
|
+
interface Container {
|
|
577
|
+
/**
|
|
578
|
+
* Unique container identifier
|
|
579
|
+
*/
|
|
580
|
+
readonly containerId: string;
|
|
581
|
+
/**
|
|
582
|
+
* Container creation timestamp
|
|
583
|
+
*/
|
|
584
|
+
readonly createdAt: number;
|
|
585
|
+
/**
|
|
586
|
+
* Run an Image - create or reuse an Agent for the given Image
|
|
587
|
+
*
|
|
588
|
+
* @param image - ImageRecord to run
|
|
589
|
+
* @returns { agent, reused } - the agent and whether it was reused
|
|
590
|
+
*/
|
|
591
|
+
runImage(image: ImageRecord): Promise<{
|
|
592
|
+
agent: Agent;
|
|
593
|
+
reused: boolean;
|
|
594
|
+
}>;
|
|
595
|
+
/**
|
|
596
|
+
* Stop an Image - destroy the Agent but keep the Image
|
|
597
|
+
*
|
|
598
|
+
* @param imageId - Image to stop
|
|
599
|
+
* @returns true if agent was found and destroyed
|
|
600
|
+
*/
|
|
601
|
+
stopImage(imageId: string): Promise<boolean>;
|
|
602
|
+
/**
|
|
603
|
+
* Get agent ID for an image (if running)
|
|
604
|
+
*/
|
|
605
|
+
getAgentIdForImage(imageId: string): string | undefined;
|
|
606
|
+
/**
|
|
607
|
+
* Check if an image has a running agent
|
|
608
|
+
*/
|
|
609
|
+
isImageOnline(imageId: string): boolean;
|
|
610
|
+
/**
|
|
611
|
+
* Get an Agent by ID
|
|
612
|
+
*/
|
|
613
|
+
getAgent(agentId: string): Agent | undefined;
|
|
614
|
+
/**
|
|
615
|
+
* List all Agents in this container
|
|
616
|
+
*/
|
|
617
|
+
listAgents(): Agent[];
|
|
618
|
+
/**
|
|
619
|
+
* Get the number of Agents in this container
|
|
620
|
+
*/
|
|
621
|
+
get agentCount(): number;
|
|
622
|
+
/**
|
|
623
|
+
* Destroy an Agent by ID
|
|
624
|
+
*
|
|
625
|
+
* Cleans up Agent resources and removes from container.
|
|
626
|
+
*
|
|
627
|
+
* @param agentId - Agent to destroy
|
|
628
|
+
* @returns true if agent was found and destroyed
|
|
629
|
+
*/
|
|
630
|
+
destroyAgent(agentId: string): Promise<boolean>;
|
|
631
|
+
/**
|
|
632
|
+
* Destroy all Agents in this container
|
|
633
|
+
*/
|
|
634
|
+
destroyAllAgents(): Promise<void>;
|
|
635
|
+
/**
|
|
636
|
+
* Dispose the container and all its Agents
|
|
637
|
+
*/
|
|
638
|
+
dispose(): Promise<void>;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
export type { Agent as A, BusEventHandler as B, Container as C, SystemBus as S, Unsubscribe as U, AgentLifecycle as a, SystemBusProducer as b, SystemBusConsumer as c, SubscribeOptions as d };
|