@agentxjs/core 1.9.3-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/Processor-DT0N1qI6.d.ts +64 -0
- package/dist/agent/engine/internal/index.d.ts +223 -0
- package/dist/agent/engine/internal/index.js +24 -0
- package/dist/agent/engine/internal/index.js.map +1 -0
- package/dist/agent/engine/mealy/index.d.ts +157 -0
- package/dist/agent/engine/mealy/index.js +26 -0
- package/dist/agent/engine/mealy/index.js.map +1 -0
- package/dist/agent/index.d.ts +244 -0
- package/dist/agent/index.js +66 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/types/index.d.ts +322 -0
- package/dist/agent/types/index.js +12 -0
- package/dist/agent/types/index.js.map +1 -0
- package/dist/base-m40r3Qgu.d.ts +157 -0
- package/dist/bus-uF1DM2ox.d.ts +906 -0
- package/dist/chunk-7D4SUZUM.js +38 -0
- package/dist/chunk-7D4SUZUM.js.map +1 -0
- package/dist/chunk-7ZDX3O6I.js +173 -0
- package/dist/chunk-7ZDX3O6I.js.map +1 -0
- package/dist/chunk-AT5P47YA.js +543 -0
- package/dist/chunk-AT5P47YA.js.map +1 -0
- package/dist/chunk-E5FPOAPO.js +123 -0
- package/dist/chunk-E5FPOAPO.js.map +1 -0
- package/dist/chunk-EKHT54KN.js +272 -0
- package/dist/chunk-EKHT54KN.js.map +1 -0
- package/dist/chunk-I7GYR3MN.js +502 -0
- package/dist/chunk-I7GYR3MN.js.map +1 -0
- package/dist/chunk-K6WXQ2RW.js +38 -0
- package/dist/chunk-K6WXQ2RW.js.map +1 -0
- package/dist/chunk-RL3JRNXM.js +3 -0
- package/dist/chunk-RL3JRNXM.js.map +1 -0
- package/dist/combinators-nEa5dD0T.d.ts +271 -0
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.js +2 -0
- package/dist/common/index.js.map +1 -0
- package/dist/common/logger/index.d.ts +163 -0
- package/dist/common/logger/index.js +184 -0
- package/dist/common/logger/index.js.map +1 -0
- package/dist/container/index.d.ts +110 -0
- package/dist/container/index.js +127 -0
- package/dist/container/index.js.map +1 -0
- package/dist/driver/index.d.ts +266 -0
- package/dist/driver/index.js +1 -0
- package/dist/driver/index.js.map +1 -0
- package/dist/event/index.d.ts +55 -0
- package/dist/event/index.js +60 -0
- package/dist/event/index.js.map +1 -0
- package/dist/event/types/index.d.ts +1149 -0
- package/dist/event/types/index.js +56 -0
- package/dist/event/types/index.js.map +1 -0
- package/dist/event-CDuTzs__.d.ts +296 -0
- package/dist/image/index.d.ts +112 -0
- package/dist/image/index.js +151 -0
- package/dist/image/index.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +67 -0
- package/dist/index.js.map +1 -0
- package/dist/message-BMrMm1pq.d.ts +305 -0
- package/dist/mq/index.d.ts +165 -0
- package/dist/mq/index.js +37 -0
- package/dist/mq/index.js.map +1 -0
- package/dist/network/index.d.ts +567 -0
- package/dist/network/index.js +435 -0
- package/dist/network/index.js.map +1 -0
- package/dist/persistence/index.d.ts +155 -0
- package/dist/persistence/index.js +1 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/runtime/index.d.ts +240 -0
- package/dist/runtime/index.js +347 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/session/index.d.ts +92 -0
- package/dist/session/index.js +56 -0
- package/dist/session/index.js.map +1 -0
- package/dist/workspace/index.d.ts +111 -0
- package/dist/workspace/index.js +1 -0
- package/dist/workspace/index.js.map +1 -0
- package/dist/wrapper-Y3UTVU2E.js +3635 -0
- package/dist/wrapper-Y3UTVU2E.js.map +1 -0
- package/package.json +74 -14
- package/tsconfig.json +0 -10
|
@@ -0,0 +1,567 @@
|
|
|
1
|
+
import { JsonRpc, IParsedObject } from 'jsonrpc-lite';
|
|
2
|
+
export { JsonRpcError } from 'jsonrpc-lite';
|
|
3
|
+
import { S as SystemEvent } from '../base-m40r3Qgu.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Network Types - Channel interfaces for client-server communication
|
|
7
|
+
*
|
|
8
|
+
* Provides transport-agnostic interfaces that can be implemented with:
|
|
9
|
+
* - WebSocket (Node.js, Browser)
|
|
10
|
+
* - Durable Objects WebSocket (Cloudflare Workers)
|
|
11
|
+
* - HTTP/2, gRPC, etc.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Unsubscribe function type
|
|
15
|
+
*/
|
|
16
|
+
type Unsubscribe = () => void;
|
|
17
|
+
/**
|
|
18
|
+
* Minimal HTTP server interface for attaching WebSocket
|
|
19
|
+
* Avoids Node.js dependency in types package
|
|
20
|
+
*/
|
|
21
|
+
interface MinimalHTTPServer {
|
|
22
|
+
on(event: "upgrade", listener: (request: unknown, socket: unknown, head: unknown) => void): void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Options for reliable message sending
|
|
26
|
+
*/
|
|
27
|
+
interface SendReliableOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Callback when client acknowledges receipt
|
|
30
|
+
*/
|
|
31
|
+
onAck?: () => void;
|
|
32
|
+
/**
|
|
33
|
+
* Timeout in milliseconds (default: 5000)
|
|
34
|
+
*/
|
|
35
|
+
timeout?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Callback when ACK times out
|
|
38
|
+
*/
|
|
39
|
+
onTimeout?: () => void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* ChannelConnection - Server-side representation of a client connection
|
|
43
|
+
*/
|
|
44
|
+
interface ChannelConnection {
|
|
45
|
+
/**
|
|
46
|
+
* Unique connection ID
|
|
47
|
+
*/
|
|
48
|
+
readonly id: string;
|
|
49
|
+
/**
|
|
50
|
+
* Send message to this client (fire-and-forget)
|
|
51
|
+
*/
|
|
52
|
+
send(message: string): void;
|
|
53
|
+
/**
|
|
54
|
+
* Send message with acknowledgment
|
|
55
|
+
*
|
|
56
|
+
* The message is wrapped with a unique ID. Client automatically sends ACK
|
|
57
|
+
* when received. Server triggers onAck callback upon receiving ACK.
|
|
58
|
+
*
|
|
59
|
+
* This is handled transparently by the Network layer.
|
|
60
|
+
*/
|
|
61
|
+
sendReliable(message: string, options?: SendReliableOptions): void;
|
|
62
|
+
/**
|
|
63
|
+
* Register message handler
|
|
64
|
+
*/
|
|
65
|
+
onMessage(handler: (message: string) => void): Unsubscribe;
|
|
66
|
+
/**
|
|
67
|
+
* Register close handler
|
|
68
|
+
*/
|
|
69
|
+
onClose(handler: () => void): Unsubscribe;
|
|
70
|
+
/**
|
|
71
|
+
* Register error handler
|
|
72
|
+
*/
|
|
73
|
+
onError(handler: (error: Error) => void): Unsubscribe;
|
|
74
|
+
/**
|
|
75
|
+
* Close this connection
|
|
76
|
+
*/
|
|
77
|
+
close(): void;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* ChannelServer - Accepts client connections
|
|
81
|
+
*/
|
|
82
|
+
interface ChannelServer {
|
|
83
|
+
/**
|
|
84
|
+
* Start listening on a port (standalone mode)
|
|
85
|
+
*/
|
|
86
|
+
listen(port: number, host?: string): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Attach to an existing HTTP server
|
|
89
|
+
*/
|
|
90
|
+
attach(server: MinimalHTTPServer, path?: string): void;
|
|
91
|
+
/**
|
|
92
|
+
* Register connection handler
|
|
93
|
+
*/
|
|
94
|
+
onConnection(handler: (connection: ChannelConnection) => void): Unsubscribe;
|
|
95
|
+
/**
|
|
96
|
+
* Broadcast message to all connected clients
|
|
97
|
+
*/
|
|
98
|
+
broadcast(message: string): void;
|
|
99
|
+
/**
|
|
100
|
+
* Close server and all connections
|
|
101
|
+
*/
|
|
102
|
+
close(): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Dispose resources
|
|
105
|
+
*/
|
|
106
|
+
dispose(): Promise<void>;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* ChannelServerOptions - Server configuration
|
|
110
|
+
*/
|
|
111
|
+
interface ChannelServerOptions {
|
|
112
|
+
/**
|
|
113
|
+
* Enable heartbeat/ping-pong (default: true)
|
|
114
|
+
*/
|
|
115
|
+
heartbeat?: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Heartbeat interval in ms (default: 30000)
|
|
118
|
+
*/
|
|
119
|
+
heartbeatInterval?: number;
|
|
120
|
+
/**
|
|
121
|
+
* Enable debug logging (default: false)
|
|
122
|
+
*/
|
|
123
|
+
debug?: boolean;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Connection state
|
|
127
|
+
*/
|
|
128
|
+
type ConnectionState = "connecting" | "open" | "closing" | "closed";
|
|
129
|
+
/**
|
|
130
|
+
* ChannelClient - Connects to server
|
|
131
|
+
*/
|
|
132
|
+
interface ChannelClient {
|
|
133
|
+
/**
|
|
134
|
+
* Connection state
|
|
135
|
+
*/
|
|
136
|
+
readonly readyState: ConnectionState;
|
|
137
|
+
/**
|
|
138
|
+
* Connect to server
|
|
139
|
+
*/
|
|
140
|
+
connect(): Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* Send message to server
|
|
143
|
+
*/
|
|
144
|
+
send(message: string): void;
|
|
145
|
+
/**
|
|
146
|
+
* Register message handler
|
|
147
|
+
*/
|
|
148
|
+
onMessage(handler: (message: string) => void): Unsubscribe;
|
|
149
|
+
/**
|
|
150
|
+
* Register open handler
|
|
151
|
+
*/
|
|
152
|
+
onOpen(handler: () => void): Unsubscribe;
|
|
153
|
+
/**
|
|
154
|
+
* Register close handler
|
|
155
|
+
*/
|
|
156
|
+
onClose(handler: () => void): Unsubscribe;
|
|
157
|
+
/**
|
|
158
|
+
* Register error handler
|
|
159
|
+
*/
|
|
160
|
+
onError(handler: (error: Error) => void): Unsubscribe;
|
|
161
|
+
/**
|
|
162
|
+
* Close connection
|
|
163
|
+
*/
|
|
164
|
+
close(): void;
|
|
165
|
+
/**
|
|
166
|
+
* Dispose resources
|
|
167
|
+
*/
|
|
168
|
+
dispose(): void;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* ChannelClientOptions - Client configuration
|
|
172
|
+
*/
|
|
173
|
+
interface ChannelClientOptions {
|
|
174
|
+
/**
|
|
175
|
+
* Server URL
|
|
176
|
+
*/
|
|
177
|
+
serverUrl: string;
|
|
178
|
+
/**
|
|
179
|
+
* Enable auto-reconnect (default: true in browser, false in Node.js)
|
|
180
|
+
*/
|
|
181
|
+
autoReconnect?: boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Min reconnection delay in ms (default: 1000)
|
|
184
|
+
*/
|
|
185
|
+
minReconnectionDelay?: number;
|
|
186
|
+
/**
|
|
187
|
+
* Max reconnection delay in ms (default: 10000)
|
|
188
|
+
*/
|
|
189
|
+
maxReconnectionDelay?: number;
|
|
190
|
+
/**
|
|
191
|
+
* Max retry attempts (default: Infinity)
|
|
192
|
+
*/
|
|
193
|
+
maxRetries?: number;
|
|
194
|
+
/**
|
|
195
|
+
* Connection timeout in ms (default: 4000)
|
|
196
|
+
*/
|
|
197
|
+
connectionTimeout?: number;
|
|
198
|
+
/**
|
|
199
|
+
* Enable debug logging (default: false)
|
|
200
|
+
*/
|
|
201
|
+
debug?: boolean;
|
|
202
|
+
/**
|
|
203
|
+
* Custom headers for WebSocket connection
|
|
204
|
+
*
|
|
205
|
+
* - Node.js: Headers are sent during WebSocket handshake
|
|
206
|
+
* - Browser: Headers are sent in first authentication message
|
|
207
|
+
*/
|
|
208
|
+
headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* ChannelServerProvider - Factory for creating ChannelServer instances
|
|
212
|
+
*/
|
|
213
|
+
interface ChannelServerProvider {
|
|
214
|
+
createServer(options?: ChannelServerOptions): ChannelServer;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* ChannelClientProvider - Factory for creating ChannelClient instances
|
|
218
|
+
*/
|
|
219
|
+
interface ChannelClientProvider {
|
|
220
|
+
createClient(options: ChannelClientOptions): ChannelClient;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Reliable Message Protocol
|
|
225
|
+
*
|
|
226
|
+
* Internal protocol for message acknowledgment between server and client.
|
|
227
|
+
* This is transparent to the application layer.
|
|
228
|
+
*
|
|
229
|
+
* Flow:
|
|
230
|
+
* 1. Server sends: { __msgId: "xxx", __payload: "actual message" }
|
|
231
|
+
* 2. Client receives, extracts payload, sends: { __ack: "xxx" }
|
|
232
|
+
* 3. Server receives ACK, triggers onAck callback
|
|
233
|
+
*/
|
|
234
|
+
/**
|
|
235
|
+
* ReliableWrapper - Wrapper for reliable messages (server → client)
|
|
236
|
+
*
|
|
237
|
+
* Contains the original message payload with a unique ID for tracking.
|
|
238
|
+
*/
|
|
239
|
+
interface ReliableWrapper {
|
|
240
|
+
/** Unique message ID for tracking */
|
|
241
|
+
__msgId: string;
|
|
242
|
+
/** Original message payload */
|
|
243
|
+
__payload: string;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* AckMessage - Acknowledgment message (client → server)
|
|
247
|
+
*
|
|
248
|
+
* Sent automatically by client when receiving a reliable message.
|
|
249
|
+
*/
|
|
250
|
+
interface AckMessage {
|
|
251
|
+
/** Message ID being acknowledged */
|
|
252
|
+
__ack: string;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Check if data is a ReliableWrapper
|
|
256
|
+
*/
|
|
257
|
+
declare function isReliableWrapper(data: unknown): data is ReliableWrapper;
|
|
258
|
+
/**
|
|
259
|
+
* Check if data is an AckMessage
|
|
260
|
+
*/
|
|
261
|
+
declare function isAckMessage(data: unknown): data is AckMessage;
|
|
262
|
+
/**
|
|
263
|
+
* Wrap a message for reliable delivery
|
|
264
|
+
*/
|
|
265
|
+
declare function wrapMessage(msgId: string, payload: string): ReliableWrapper;
|
|
266
|
+
/**
|
|
267
|
+
* Create an ACK message
|
|
268
|
+
*/
|
|
269
|
+
declare function createAck(msgId: string): AckMessage;
|
|
270
|
+
/**
|
|
271
|
+
* Unwrap a reliable message, returning the original payload
|
|
272
|
+
*/
|
|
273
|
+
declare function unwrapMessage(wrapper: ReliableWrapper): string;
|
|
274
|
+
/**
|
|
275
|
+
* Generate a unique message ID
|
|
276
|
+
*/
|
|
277
|
+
declare function generateMessageId(): string;
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* JSON-RPC 2.0 Protocol for AgentX Network Communication
|
|
281
|
+
*
|
|
282
|
+
* Uses jsonrpc-lite for message parsing/serialization.
|
|
283
|
+
*
|
|
284
|
+
* Message Types:
|
|
285
|
+
* - Request: Client → Server (has id, expects response)
|
|
286
|
+
* - Response: Server → Client (success or error)
|
|
287
|
+
* - Notification: Server → Client (no id, stream events)
|
|
288
|
+
*
|
|
289
|
+
* @see https://www.jsonrpc.org/specification
|
|
290
|
+
*/
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* All RPC method names supported by AgentX
|
|
294
|
+
*/
|
|
295
|
+
type RpcMethod = "container.create" | "container.get" | "container.list" | "image.create" | "image.get" | "image.list" | "image.delete" | "image.run" | "image.stop" | "image.update" | "image.messages" | "agent.get" | "agent.list" | "agent.destroy" | "agent.destroyAll" | "agent.interrupt" | "message.send";
|
|
296
|
+
/**
|
|
297
|
+
* Notification method names (server push)
|
|
298
|
+
*/
|
|
299
|
+
type NotificationMethod = "stream.event" | "control.ack";
|
|
300
|
+
/**
|
|
301
|
+
* JSON-RPC Request structure
|
|
302
|
+
*/
|
|
303
|
+
interface RpcRequest<M extends RpcMethod = RpcMethod, P = unknown> {
|
|
304
|
+
jsonrpc: "2.0";
|
|
305
|
+
method: M;
|
|
306
|
+
params: P;
|
|
307
|
+
id: string | number;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* JSON-RPC Success Response structure
|
|
311
|
+
*/
|
|
312
|
+
interface RpcSuccessResponse<R = unknown> {
|
|
313
|
+
jsonrpc: "2.0";
|
|
314
|
+
result: R;
|
|
315
|
+
id: string | number;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* JSON-RPC Error Response structure
|
|
319
|
+
*/
|
|
320
|
+
interface RpcErrorResponse {
|
|
321
|
+
jsonrpc: "2.0";
|
|
322
|
+
error: {
|
|
323
|
+
code: number;
|
|
324
|
+
message: string;
|
|
325
|
+
data?: unknown;
|
|
326
|
+
};
|
|
327
|
+
id: string | number | null;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* JSON-RPC Notification structure (no id, no response expected)
|
|
331
|
+
*/
|
|
332
|
+
interface RpcNotification<M extends NotificationMethod = NotificationMethod, P = unknown> {
|
|
333
|
+
jsonrpc: "2.0";
|
|
334
|
+
method: M;
|
|
335
|
+
params: P;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Stream event notification params
|
|
339
|
+
*/
|
|
340
|
+
interface StreamEventParams {
|
|
341
|
+
topic: string;
|
|
342
|
+
event: SystemEvent;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Control ACK notification params
|
|
346
|
+
*/
|
|
347
|
+
interface ControlAckParams {
|
|
348
|
+
msgId: string;
|
|
349
|
+
}
|
|
350
|
+
declare const RpcErrorCodes: {
|
|
351
|
+
readonly PARSE_ERROR: -32700;
|
|
352
|
+
readonly INVALID_REQUEST: -32600;
|
|
353
|
+
readonly METHOD_NOT_FOUND: -32601;
|
|
354
|
+
readonly INVALID_PARAMS: -32602;
|
|
355
|
+
readonly INTERNAL_ERROR: -32603;
|
|
356
|
+
readonly SERVER_ERROR: -32000;
|
|
357
|
+
readonly NOT_FOUND: 404;
|
|
358
|
+
readonly UNAUTHORIZED: 401;
|
|
359
|
+
readonly FORBIDDEN: 403;
|
|
360
|
+
readonly TIMEOUT: 408;
|
|
361
|
+
};
|
|
362
|
+
/**
|
|
363
|
+
* Create a JSON-RPC request
|
|
364
|
+
*/
|
|
365
|
+
declare function createRequest(id: string | number, method: RpcMethod | string, params: unknown): JsonRpc;
|
|
366
|
+
/**
|
|
367
|
+
* Create a JSON-RPC notification (no response expected)
|
|
368
|
+
*/
|
|
369
|
+
declare function createNotification(method: NotificationMethod | string, params: unknown): JsonRpc;
|
|
370
|
+
/**
|
|
371
|
+
* Create a stream event notification
|
|
372
|
+
*/
|
|
373
|
+
declare function createStreamEvent(topic: string, event: SystemEvent): JsonRpc;
|
|
374
|
+
/**
|
|
375
|
+
* Create an ACK notification
|
|
376
|
+
*/
|
|
377
|
+
declare function createAckNotification(msgId: string): JsonRpc;
|
|
378
|
+
/**
|
|
379
|
+
* Create a success response
|
|
380
|
+
*/
|
|
381
|
+
declare function createSuccessResponse(id: string | number, result: unknown): JsonRpc;
|
|
382
|
+
/**
|
|
383
|
+
* Create an error response
|
|
384
|
+
*/
|
|
385
|
+
declare function createErrorResponse(id: string | number | null, code: number, message: string, data?: unknown): JsonRpc;
|
|
386
|
+
/**
|
|
387
|
+
* Parse a JSON-RPC message string
|
|
388
|
+
*/
|
|
389
|
+
declare function parseMessage(message: string): IParsedObject | IParsedObject[];
|
|
390
|
+
/**
|
|
391
|
+
* Parse a JSON-RPC message object
|
|
392
|
+
*/
|
|
393
|
+
declare function parseMessageObject(obj: unknown): IParsedObject;
|
|
394
|
+
/**
|
|
395
|
+
* Check if parsed message is a request
|
|
396
|
+
*/
|
|
397
|
+
declare function isRequest(parsed: IParsedObject): boolean;
|
|
398
|
+
/**
|
|
399
|
+
* Check if parsed message is a notification
|
|
400
|
+
*/
|
|
401
|
+
declare function isNotification(parsed: IParsedObject): boolean;
|
|
402
|
+
/**
|
|
403
|
+
* Check if parsed message is a success response
|
|
404
|
+
*/
|
|
405
|
+
declare function isSuccessResponse(parsed: IParsedObject): boolean;
|
|
406
|
+
/**
|
|
407
|
+
* Check if parsed message is an error response
|
|
408
|
+
*/
|
|
409
|
+
declare function isErrorResponse(parsed: IParsedObject): boolean;
|
|
410
|
+
/**
|
|
411
|
+
* Check if parsed message is invalid
|
|
412
|
+
*/
|
|
413
|
+
declare function isInvalid(parsed: IParsedObject): boolean;
|
|
414
|
+
/**
|
|
415
|
+
* Check if notification is a stream event
|
|
416
|
+
*/
|
|
417
|
+
declare function isStreamEvent(parsed: IParsedObject): parsed is IParsedObject & {
|
|
418
|
+
payload: RpcNotification<"stream.event", StreamEventParams>;
|
|
419
|
+
};
|
|
420
|
+
/**
|
|
421
|
+
* Check if notification is a control ACK
|
|
422
|
+
*/
|
|
423
|
+
declare function isControlAck(parsed: IParsedObject): parsed is IParsedObject & {
|
|
424
|
+
payload: RpcNotification<"control.ack", ControlAckParams>;
|
|
425
|
+
};
|
|
426
|
+
/**
|
|
427
|
+
* Map old event type names to new RPC method names
|
|
428
|
+
*/
|
|
429
|
+
declare const eventTypeToRpcMethod: Record<string, RpcMethod>;
|
|
430
|
+
/**
|
|
431
|
+
* Map RPC method names back to response event types
|
|
432
|
+
*/
|
|
433
|
+
declare const rpcMethodToResponseType: Record<RpcMethod, string>;
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* RpcClient - JSON-RPC 2.0 Client over WebSocket
|
|
437
|
+
*
|
|
438
|
+
* Provides:
|
|
439
|
+
* - Request/Response with automatic ID matching
|
|
440
|
+
* - Notification handling (stream events)
|
|
441
|
+
* - Timeout management
|
|
442
|
+
* - Reconnection support
|
|
443
|
+
*
|
|
444
|
+
* @example
|
|
445
|
+
* ```typescript
|
|
446
|
+
* const client = new RpcClient({ url: "ws://localhost:5200" });
|
|
447
|
+
* await client.connect();
|
|
448
|
+
*
|
|
449
|
+
* // RPC call
|
|
450
|
+
* const result = await client.call("container.list", {});
|
|
451
|
+
*
|
|
452
|
+
* // Stream events
|
|
453
|
+
* client.onNotification("stream.event", (params) => {
|
|
454
|
+
* console.log("Event:", params.event);
|
|
455
|
+
* });
|
|
456
|
+
*
|
|
457
|
+
* // Subscribe to topic
|
|
458
|
+
* client.notify("subscribe", { topic: "session-123" });
|
|
459
|
+
* ```
|
|
460
|
+
*/
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* RpcClient configuration
|
|
464
|
+
*/
|
|
465
|
+
interface RpcClientConfig {
|
|
466
|
+
/**
|
|
467
|
+
* WebSocket URL
|
|
468
|
+
*/
|
|
469
|
+
url: string;
|
|
470
|
+
/**
|
|
471
|
+
* Request timeout in milliseconds (default: 30000)
|
|
472
|
+
*/
|
|
473
|
+
timeout?: number;
|
|
474
|
+
/**
|
|
475
|
+
* Auto reconnect on disconnect (default: true)
|
|
476
|
+
*/
|
|
477
|
+
autoReconnect?: boolean;
|
|
478
|
+
/**
|
|
479
|
+
* Reconnect delay in milliseconds (default: 3000)
|
|
480
|
+
*/
|
|
481
|
+
reconnectDelay?: number;
|
|
482
|
+
/**
|
|
483
|
+
* Headers for authentication (Node.js only, sent in first message for browser)
|
|
484
|
+
*/
|
|
485
|
+
headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
486
|
+
/**
|
|
487
|
+
* Debug logging
|
|
488
|
+
*/
|
|
489
|
+
debug?: boolean;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Notification handler
|
|
493
|
+
*/
|
|
494
|
+
type NotificationHandler = (method: string, params: unknown) => void;
|
|
495
|
+
/**
|
|
496
|
+
* Stream event handler
|
|
497
|
+
*/
|
|
498
|
+
type StreamEventHandler = (topic: string, event: SystemEvent) => void;
|
|
499
|
+
/**
|
|
500
|
+
* Connection state
|
|
501
|
+
*/
|
|
502
|
+
type RpcClientState = "disconnected" | "connecting" | "connected";
|
|
503
|
+
/**
|
|
504
|
+
* JSON-RPC 2.0 Client
|
|
505
|
+
*/
|
|
506
|
+
declare class RpcClient {
|
|
507
|
+
private readonly config;
|
|
508
|
+
private readonly timeout;
|
|
509
|
+
private readonly pendingRequests;
|
|
510
|
+
private readonly notificationHandlers;
|
|
511
|
+
private readonly streamEventHandlers;
|
|
512
|
+
private ws;
|
|
513
|
+
private state;
|
|
514
|
+
private requestId;
|
|
515
|
+
private reconnectTimer;
|
|
516
|
+
private disposed;
|
|
517
|
+
constructor(config: RpcClientConfig);
|
|
518
|
+
/**
|
|
519
|
+
* Current connection state
|
|
520
|
+
*/
|
|
521
|
+
get connectionState(): RpcClientState;
|
|
522
|
+
/**
|
|
523
|
+
* Whether client is connected
|
|
524
|
+
*/
|
|
525
|
+
get connected(): boolean;
|
|
526
|
+
/**
|
|
527
|
+
* Connect to server
|
|
528
|
+
*/
|
|
529
|
+
connect(): Promise<void>;
|
|
530
|
+
/**
|
|
531
|
+
* Disconnect from server
|
|
532
|
+
*/
|
|
533
|
+
disconnect(): void;
|
|
534
|
+
/**
|
|
535
|
+
* Dispose client and clean up resources
|
|
536
|
+
*/
|
|
537
|
+
dispose(): void;
|
|
538
|
+
private scheduleReconnect;
|
|
539
|
+
/**
|
|
540
|
+
* Call an RPC method and wait for response
|
|
541
|
+
*/
|
|
542
|
+
call<T = unknown>(method: RpcMethod, params: unknown): Promise<T>;
|
|
543
|
+
/**
|
|
544
|
+
* Send a notification (no response expected)
|
|
545
|
+
*/
|
|
546
|
+
notify(method: NotificationMethod | string, params: unknown): void;
|
|
547
|
+
/**
|
|
548
|
+
* Subscribe to a topic (convenience method)
|
|
549
|
+
*/
|
|
550
|
+
subscribe(topic: string): void;
|
|
551
|
+
/**
|
|
552
|
+
* Unsubscribe from a topic (convenience method)
|
|
553
|
+
*/
|
|
554
|
+
unsubscribe(topic: string): void;
|
|
555
|
+
/**
|
|
556
|
+
* Register handler for all notifications
|
|
557
|
+
*/
|
|
558
|
+
onNotification(handler: NotificationHandler): () => void;
|
|
559
|
+
/**
|
|
560
|
+
* Register handler for stream events
|
|
561
|
+
*/
|
|
562
|
+
onStreamEvent(handler: StreamEventHandler): () => void;
|
|
563
|
+
private handleMessage;
|
|
564
|
+
private handleParsedMessage;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
export { type AckMessage, type ChannelClient, type ChannelClientOptions, type ChannelClientProvider, type ChannelConnection, type ChannelServer, type ChannelServerOptions, type ChannelServerProvider, type ConnectionState, type ControlAckParams, type MinimalHTTPServer, type NotificationMethod, type ReliableWrapper, RpcClient, type RpcClientConfig, type RpcClientState, RpcErrorCodes, type RpcErrorResponse, type RpcMethod, type RpcNotification, type RpcRequest, type RpcSuccessResponse, type SendReliableOptions, type StreamEventParams, type Unsubscribe, createAck, createAckNotification, createErrorResponse, createNotification, createRequest, createStreamEvent, createSuccessResponse, eventTypeToRpcMethod, generateMessageId, isAckMessage, isControlAck, isErrorResponse, isInvalid, isNotification, isReliableWrapper, isRequest, isStreamEvent, isSuccessResponse, parseMessage, parseMessageObject, rpcMethodToResponseType, unwrapMessage, wrapMessage };
|