@easbot/gateway 0.1.11

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.
@@ -0,0 +1,2238 @@
1
+ import { IGatewayServer, GatewayConfig as GatewayConfig$1, GatewayServerConfig as GatewayServerConfig$1, PlatformType, GatewayMessage, SubAgentConfig, ChannelInfo } from '@easbot/types';
2
+ export { AgentInfo, ChannelInfo, GatewayMessage, GatewayMessagePromptPart, IGatewayServer, MessageContext, MessageMetadata, MessageType, PlatformType } from '@easbot/types';
3
+ import z from 'zod';
4
+ import { WSContext } from '@easbot/utils';
5
+
6
+ declare namespace Gateway {
7
+ export interface BootstrapConfig {
8
+ directory?: string;
9
+ printLogs?: boolean;
10
+ logLevel?: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
11
+ }
12
+ type StateResult = {
13
+ server: IGatewayServer | null;
14
+ config: GatewayConfig$1 | null;
15
+ initialized: boolean;
16
+ status: 'stopped' | 'starting' | 'running' | 'stopping' | 'error';
17
+ error?: string;
18
+ };
19
+ export function init(config?: BootstrapConfig): Promise<void>;
20
+ export function isInitialized(): boolean;
21
+ export function state(): Promise<StateResult>;
22
+ export function get(): Promise<IGatewayServer | null>;
23
+ export function isEnabled(): Promise<boolean>;
24
+ export function config(): Promise<GatewayConfig$1 | null>;
25
+ export function getStatus(): 'stopped' | 'starting' | 'running' | 'stopping' | 'error';
26
+ export function start(options?: Partial<GatewayServerConfig$1>): Promise<void>;
27
+ export function stop(): Promise<void>;
28
+ export function restart(options?: Partial<GatewayServerConfig$1>): Promise<void>;
29
+ export function reloadConfig(): Promise<GatewayConfig$1>;
30
+ export function createGatewayServer(config: GatewayServerConfig$1, options?: {
31
+ startupTimeout?: number;
32
+ onStarted?: (server: IGatewayServer) => void | Promise<void>;
33
+ }): Promise<IGatewayServer>;
34
+ export { };
35
+ }
36
+
37
+ declare const ChannelTypeSchema: z.ZodEnum<{
38
+ signal: "signal";
39
+ telegram: "telegram";
40
+ slack: "slack";
41
+ feishu: "feishu";
42
+ wechat: "wechat";
43
+ webchat: "webchat";
44
+ nostr: "nostr";
45
+ }>;
46
+ type ChannelType = z.infer<typeof ChannelTypeSchema>;
47
+ declare const MessagePrioritySchema: z.ZodEnum<{
48
+ low: "low";
49
+ medium: "medium";
50
+ high: "high";
51
+ critical: "critical";
52
+ }>;
53
+ type MessagePriority = z.infer<typeof MessagePrioritySchema>;
54
+ declare const TelegramChannelConfigSchema: z.ZodObject<{
55
+ enabled: z.ZodDefault<z.ZodBoolean>;
56
+ botToken: z.ZodString;
57
+ webhookUrl: z.ZodOptional<z.ZodString>;
58
+ maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
59
+ timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
60
+ }, z.core.$strip>;
61
+ type TelegramChannelConfig = z.infer<typeof TelegramChannelConfigSchema>;
62
+ declare const SlackChannelConfigSchema: z.ZodObject<{
63
+ enabled: z.ZodDefault<z.ZodBoolean>;
64
+ botToken: z.ZodString;
65
+ appToken: z.ZodOptional<z.ZodString>;
66
+ signingSecret: z.ZodOptional<z.ZodString>;
67
+ maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
68
+ timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
69
+ }, z.core.$strip>;
70
+ type SlackChannelConfig = z.infer<typeof SlackChannelConfigSchema>;
71
+ declare const FeishuChannelConfigSchema: z.ZodObject<{
72
+ enabled: z.ZodDefault<z.ZodBoolean>;
73
+ appId: z.ZodString;
74
+ appSecret: z.ZodString;
75
+ encryptKey: z.ZodOptional<z.ZodString>;
76
+ verificationToken: z.ZodOptional<z.ZodString>;
77
+ maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
78
+ timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
79
+ }, z.core.$strip>;
80
+ type FeishuChannelConfig = z.infer<typeof FeishuChannelConfigSchema>;
81
+ declare const WeChatChannelConfigSchema: z.ZodObject<{
82
+ enabled: z.ZodDefault<z.ZodBoolean>;
83
+ mode: z.ZodDefault<z.ZodEnum<{
84
+ official: "official";
85
+ wecom: "wecom";
86
+ }>>;
87
+ appId: z.ZodString;
88
+ appSecret: z.ZodString;
89
+ token: z.ZodOptional<z.ZodString>;
90
+ encodingAESKey: z.ZodOptional<z.ZodString>;
91
+ agentId: z.ZodOptional<z.ZodString>;
92
+ maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
93
+ timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
94
+ }, z.core.$strip>;
95
+ type WeChatChannelConfig = z.infer<typeof WeChatChannelConfigSchema>;
96
+ declare const WebChatChannelConfigSchema: z.ZodObject<{
97
+ enabled: z.ZodDefault<z.ZodBoolean>;
98
+ path: z.ZodDefault<z.ZodOptional<z.ZodString>>;
99
+ heartbeatInterval: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
100
+ connectionTimeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
101
+ maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
102
+ cors: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
103
+ }, z.core.$strip>;
104
+ type WebChatChannelConfig = z.infer<typeof WebChatChannelConfigSchema>;
105
+ declare const SignalChannelConfigSchema: z.ZodObject<{
106
+ enabled: z.ZodDefault<z.ZodBoolean>;
107
+ serviceUrl: z.ZodDefault<z.ZodOptional<z.ZodString>>;
108
+ phoneNumber: z.ZodString;
109
+ password: z.ZodOptional<z.ZodString>;
110
+ maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
111
+ timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
112
+ }, z.core.$strip>;
113
+ type SignalChannelConfig = z.infer<typeof SignalChannelConfigSchema>;
114
+ declare const NostrChannelConfigSchema: z.ZodObject<{
115
+ enabled: z.ZodDefault<z.ZodBoolean>;
116
+ relays: z.ZodArray<z.ZodString>;
117
+ privateKey: z.ZodOptional<z.ZodString>;
118
+ publicKey: z.ZodOptional<z.ZodString>;
119
+ maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
120
+ timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
121
+ }, z.core.$strip>;
122
+ type NostrChannelConfig = z.infer<typeof NostrChannelConfigSchema>;
123
+ declare const ChannelConfigSchema: z.ZodObject<{
124
+ telegram: z.ZodOptional<z.ZodObject<{
125
+ enabled: z.ZodDefault<z.ZodBoolean>;
126
+ botToken: z.ZodString;
127
+ webhookUrl: z.ZodOptional<z.ZodString>;
128
+ maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
129
+ timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
130
+ }, z.core.$strip>>;
131
+ slack: z.ZodOptional<z.ZodObject<{
132
+ enabled: z.ZodDefault<z.ZodBoolean>;
133
+ botToken: z.ZodString;
134
+ appToken: z.ZodOptional<z.ZodString>;
135
+ signingSecret: z.ZodOptional<z.ZodString>;
136
+ maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
137
+ timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
138
+ }, z.core.$strip>>;
139
+ feishu: z.ZodOptional<z.ZodObject<{
140
+ enabled: z.ZodDefault<z.ZodBoolean>;
141
+ appId: z.ZodString;
142
+ appSecret: z.ZodString;
143
+ encryptKey: z.ZodOptional<z.ZodString>;
144
+ verificationToken: z.ZodOptional<z.ZodString>;
145
+ maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
146
+ timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
147
+ }, z.core.$strip>>;
148
+ wechat: z.ZodOptional<z.ZodObject<{
149
+ enabled: z.ZodDefault<z.ZodBoolean>;
150
+ mode: z.ZodDefault<z.ZodEnum<{
151
+ official: "official";
152
+ wecom: "wecom";
153
+ }>>;
154
+ appId: z.ZodString;
155
+ appSecret: z.ZodString;
156
+ token: z.ZodOptional<z.ZodString>;
157
+ encodingAESKey: z.ZodOptional<z.ZodString>;
158
+ agentId: z.ZodOptional<z.ZodString>;
159
+ maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
160
+ timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
161
+ }, z.core.$strip>>;
162
+ webchat: z.ZodOptional<z.ZodObject<{
163
+ enabled: z.ZodDefault<z.ZodBoolean>;
164
+ path: z.ZodDefault<z.ZodOptional<z.ZodString>>;
165
+ heartbeatInterval: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
166
+ connectionTimeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
167
+ maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
168
+ cors: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
169
+ }, z.core.$strip>>;
170
+ signal: z.ZodOptional<z.ZodObject<{
171
+ enabled: z.ZodDefault<z.ZodBoolean>;
172
+ serviceUrl: z.ZodDefault<z.ZodOptional<z.ZodString>>;
173
+ phoneNumber: z.ZodString;
174
+ password: z.ZodOptional<z.ZodString>;
175
+ maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
176
+ timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
177
+ }, z.core.$strip>>;
178
+ nostr: z.ZodOptional<z.ZodObject<{
179
+ enabled: z.ZodDefault<z.ZodBoolean>;
180
+ relays: z.ZodArray<z.ZodString>;
181
+ privateKey: z.ZodOptional<z.ZodString>;
182
+ publicKey: z.ZodOptional<z.ZodString>;
183
+ maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
184
+ timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
185
+ }, z.core.$strip>>;
186
+ }, z.core.$strip>;
187
+ declare const HTTPSConfigSchema: z.ZodObject<{
188
+ enabled: z.ZodDefault<z.ZodBoolean>;
189
+ cert: z.ZodString;
190
+ key: z.ZodString;
191
+ certPath: z.ZodOptional<z.ZodString>;
192
+ keyPath: z.ZodOptional<z.ZodString>;
193
+ ca: z.ZodOptional<z.ZodString>;
194
+ forceRedirect: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
195
+ httpPort: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
196
+ }, z.core.$strip>;
197
+ type HTTPSConfig = z.infer<typeof HTTPSConfigSchema>;
198
+ declare const TokenAuthItemSchema: z.ZodObject<{
199
+ name: z.ZodString;
200
+ value: z.ZodString;
201
+ permissions: z.ZodDefault<z.ZodArray<z.ZodString>>;
202
+ expiresAt: z.ZodOptional<z.ZodNumber>;
203
+ description: z.ZodOptional<z.ZodString>;
204
+ }, z.core.$strip>;
205
+ type TokenAuthItem = z.infer<typeof TokenAuthItemSchema>;
206
+ declare const TokenAuthConfigSchema: z.ZodObject<{
207
+ enabled: z.ZodDefault<z.ZodBoolean>;
208
+ tokens: z.ZodDefault<z.ZodArray<z.ZodObject<{
209
+ name: z.ZodString;
210
+ value: z.ZodString;
211
+ permissions: z.ZodDefault<z.ZodArray<z.ZodString>>;
212
+ expiresAt: z.ZodOptional<z.ZodNumber>;
213
+ description: z.ZodOptional<z.ZodString>;
214
+ }, z.core.$strip>>>;
215
+ onInvalid: z.ZodDefault<z.ZodEnum<{
216
+ reject: "reject";
217
+ anonymous: "anonymous";
218
+ }>>;
219
+ allowAnonymous: z.ZodDefault<z.ZodBoolean>;
220
+ defaultPermissions: z.ZodDefault<z.ZodArray<z.ZodString>>;
221
+ }, z.core.$strip>;
222
+ type TokenAuthConfig = z.infer<typeof TokenAuthConfigSchema>;
223
+ declare const OAuth2AuthConfigSchema: z.ZodObject<{
224
+ enabled: z.ZodDefault<z.ZodBoolean>;
225
+ authorizationServer: z.ZodString;
226
+ clientId: z.ZodString;
227
+ clientSecret: z.ZodString;
228
+ tokenValidationEndpoint: z.ZodString;
229
+ scope: z.ZodDefault<z.ZodArray<z.ZodString>>;
230
+ }, z.core.$strip>;
231
+ type OAuth2AuthConfig = z.infer<typeof OAuth2AuthConfigSchema>;
232
+ declare const AuthConfigSchema: z.ZodObject<{
233
+ type: z.ZodDefault<z.ZodEnum<{
234
+ token: "token";
235
+ oauth2: "oauth2";
236
+ }>>;
237
+ token: z.ZodOptional<z.ZodObject<{
238
+ enabled: z.ZodDefault<z.ZodBoolean>;
239
+ tokens: z.ZodDefault<z.ZodArray<z.ZodObject<{
240
+ name: z.ZodString;
241
+ value: z.ZodString;
242
+ permissions: z.ZodDefault<z.ZodArray<z.ZodString>>;
243
+ expiresAt: z.ZodOptional<z.ZodNumber>;
244
+ description: z.ZodOptional<z.ZodString>;
245
+ }, z.core.$strip>>>;
246
+ onInvalid: z.ZodDefault<z.ZodEnum<{
247
+ reject: "reject";
248
+ anonymous: "anonymous";
249
+ }>>;
250
+ allowAnonymous: z.ZodDefault<z.ZodBoolean>;
251
+ defaultPermissions: z.ZodDefault<z.ZodArray<z.ZodString>>;
252
+ }, z.core.$strip>>;
253
+ oauth2: z.ZodOptional<z.ZodObject<{
254
+ enabled: z.ZodDefault<z.ZodBoolean>;
255
+ authorizationServer: z.ZodString;
256
+ clientId: z.ZodString;
257
+ clientSecret: z.ZodString;
258
+ tokenValidationEndpoint: z.ZodString;
259
+ scope: z.ZodDefault<z.ZodArray<z.ZodString>>;
260
+ }, z.core.$strip>>;
261
+ }, z.core.$strip>;
262
+ type AuthConfig = z.infer<typeof AuthConfigSchema>;
263
+ declare const AgentSyncConfigSchema: z.ZodObject<{
264
+ mode: z.ZodDefault<z.ZodEnum<{
265
+ push: "push";
266
+ pull: "pull";
267
+ both: "both";
268
+ }>>;
269
+ interval: z.ZodDefault<z.ZodNumber>;
270
+ pushEvents: z.ZodDefault<z.ZodArray<z.ZodEnum<{
271
+ register: "register";
272
+ deregister: "deregister";
273
+ heartbeat: "heartbeat";
274
+ status_change: "status_change";
275
+ }>>>;
276
+ conflictResolution: z.ZodDefault<z.ZodEnum<{
277
+ latest: "latest";
278
+ local: "local";
279
+ remote: "remote";
280
+ }>>;
281
+ }, z.core.$strip>;
282
+ type AgentSyncConfig = z.infer<typeof AgentSyncConfigSchema>;
283
+ declare const GatewayNodeConfigSchema: z.ZodObject<{
284
+ id: z.ZodString;
285
+ address: z.ZodString;
286
+ enabled: z.ZodDefault<z.ZodBoolean>;
287
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
288
+ }, z.core.$strip>;
289
+ type GatewayNodeConfig = z.infer<typeof GatewayNodeConfigSchema>;
290
+ declare const GatewayClusterConfigSchema: z.ZodObject<{
291
+ nodeId: z.ZodString;
292
+ nodes: z.ZodDefault<z.ZodArray<z.ZodObject<{
293
+ id: z.ZodString;
294
+ address: z.ZodString;
295
+ enabled: z.ZodDefault<z.ZodBoolean>;
296
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
297
+ }, z.core.$strip>>>;
298
+ sync: z.ZodOptional<z.ZodObject<{
299
+ mode: z.ZodDefault<z.ZodEnum<{
300
+ push: "push";
301
+ pull: "pull";
302
+ both: "both";
303
+ }>>;
304
+ interval: z.ZodDefault<z.ZodNumber>;
305
+ pushEvents: z.ZodDefault<z.ZodArray<z.ZodEnum<{
306
+ register: "register";
307
+ deregister: "deregister";
308
+ heartbeat: "heartbeat";
309
+ status_change: "status_change";
310
+ }>>>;
311
+ conflictResolution: z.ZodDefault<z.ZodEnum<{
312
+ latest: "latest";
313
+ local: "local";
314
+ remote: "remote";
315
+ }>>;
316
+ }, z.core.$strip>>;
317
+ }, z.core.$strip>;
318
+ type GatewayClusterConfig = z.infer<typeof GatewayClusterConfigSchema>;
319
+ declare const ConnectionPoolConfigSchema: z.ZodObject<{
320
+ maxConnectionsPerChannel: z.ZodDefault<z.ZodNumber>;
321
+ idleTimeout: z.ZodDefault<z.ZodNumber>;
322
+ reuseStrategy: z.ZodDefault<z.ZodEnum<{
323
+ lru: "lru";
324
+ fifo: "fifo";
325
+ random: "random";
326
+ }>>;
327
+ healthCheckInterval: z.ZodDefault<z.ZodNumber>;
328
+ acquireTimeout: z.ZodDefault<z.ZodNumber>;
329
+ warmupCount: z.ZodDefault<z.ZodNumber>;
330
+ }, z.core.$strip>;
331
+ type ConnectionPoolConfig = z.infer<typeof ConnectionPoolConfigSchema>;
332
+ declare const MessageQueueConfigSchema: z.ZodObject<{
333
+ maxLength: z.ZodDefault<z.ZodNumber>;
334
+ concurrency: z.ZodDefault<z.ZodNumber>;
335
+ batchSize: z.ZodDefault<z.ZodNumber>;
336
+ batchTimeout: z.ZodDefault<z.ZodNumber>;
337
+ priorityLevels: z.ZodDefault<z.ZodNumber>;
338
+ }, z.core.$strip>;
339
+ type MessageQueueConfig = z.infer<typeof MessageQueueConfigSchema>;
340
+ declare const CircuitBreakerConfigSchema: z.ZodObject<{
341
+ failureThreshold: z.ZodDefault<z.ZodNumber>;
342
+ successThreshold: z.ZodDefault<z.ZodNumber>;
343
+ timeout: z.ZodDefault<z.ZodNumber>;
344
+ halfOpenDuration: z.ZodDefault<z.ZodNumber>;
345
+ }, z.core.$strip>;
346
+ type CircuitBreakerConfig = z.infer<typeof CircuitBreakerConfigSchema>;
347
+ declare const AgentRegistryConfigSchema: z.ZodObject<{
348
+ heartbeatInterval: z.ZodDefault<z.ZodNumber>;
349
+ heartbeatTimeout: z.ZodDefault<z.ZodNumber>;
350
+ heartbeatCheckInterval: z.ZodDefault<z.ZodNumber>;
351
+ autoDeregisterTimeout: z.ZodDefault<z.ZodNumber>;
352
+ maxAgents: z.ZodDefault<z.ZodNumber>;
353
+ persistenceFile: z.ZodOptional<z.ZodString>;
354
+ maxRegistrations: z.ZodDefault<z.ZodNumber>;
355
+ }, z.core.$strip>;
356
+ type AgentRegistryConfig = z.infer<typeof AgentRegistryConfigSchema>;
357
+ declare const SessionConfigSchema: z.ZodObject<{
358
+ sessionTimeout: z.ZodDefault<z.ZodNumber>;
359
+ resumeGracePeriod: z.ZodDefault<z.ZodNumber>;
360
+ maxSessions: z.ZodDefault<z.ZodNumber>;
361
+ persistenceFile: z.ZodOptional<z.ZodString>;
362
+ }, z.core.$strip>;
363
+ type SessionConfig$1 = z.infer<typeof SessionConfigSchema>;
364
+ declare const GatewayServerConfigSchema: z.ZodObject<{
365
+ enabled: z.ZodDefault<z.ZodBoolean>;
366
+ port: z.ZodDefault<z.ZodNumber>;
367
+ hostname: z.ZodDefault<z.ZodString>;
368
+ path: z.ZodDefault<z.ZodOptional<z.ZodString>>;
369
+ maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
370
+ connectionTimeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
371
+ heartbeatInterval: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
372
+ sessionExpireMs: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
373
+ https: z.ZodOptional<z.ZodObject<{
374
+ enabled: z.ZodDefault<z.ZodBoolean>;
375
+ cert: z.ZodString;
376
+ key: z.ZodString;
377
+ certPath: z.ZodOptional<z.ZodString>;
378
+ keyPath: z.ZodOptional<z.ZodString>;
379
+ ca: z.ZodOptional<z.ZodString>;
380
+ forceRedirect: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
381
+ httpPort: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
382
+ }, z.core.$strip>>;
383
+ auth: z.ZodOptional<z.ZodObject<{
384
+ type: z.ZodDefault<z.ZodEnum<{
385
+ token: "token";
386
+ oauth2: "oauth2";
387
+ }>>;
388
+ token: z.ZodOptional<z.ZodObject<{
389
+ enabled: z.ZodDefault<z.ZodBoolean>;
390
+ tokens: z.ZodDefault<z.ZodArray<z.ZodObject<{
391
+ name: z.ZodString;
392
+ value: z.ZodString;
393
+ permissions: z.ZodDefault<z.ZodArray<z.ZodString>>;
394
+ expiresAt: z.ZodOptional<z.ZodNumber>;
395
+ description: z.ZodOptional<z.ZodString>;
396
+ }, z.core.$strip>>>;
397
+ onInvalid: z.ZodDefault<z.ZodEnum<{
398
+ reject: "reject";
399
+ anonymous: "anonymous";
400
+ }>>;
401
+ allowAnonymous: z.ZodDefault<z.ZodBoolean>;
402
+ defaultPermissions: z.ZodDefault<z.ZodArray<z.ZodString>>;
403
+ }, z.core.$strip>>;
404
+ oauth2: z.ZodOptional<z.ZodObject<{
405
+ enabled: z.ZodDefault<z.ZodBoolean>;
406
+ authorizationServer: z.ZodString;
407
+ clientId: z.ZodString;
408
+ clientSecret: z.ZodString;
409
+ tokenValidationEndpoint: z.ZodString;
410
+ scope: z.ZodDefault<z.ZodArray<z.ZodString>>;
411
+ }, z.core.$strip>>;
412
+ }, z.core.$strip>>;
413
+ cors: z.ZodDefault<z.ZodBoolean>;
414
+ corsOrigins: z.ZodOptional<z.ZodArray<z.ZodString>>;
415
+ mdns: z.ZodDefault<z.ZodBoolean>;
416
+ mdnsDomain: z.ZodDefault<z.ZodOptional<z.ZodString>>;
417
+ }, z.core.$strip>;
418
+ type GatewayServerConfig = z.infer<typeof GatewayServerConfigSchema>;
419
+ declare const GatewayConfigSchema: z.ZodObject<{
420
+ server: z.ZodOptional<z.ZodObject<{
421
+ enabled: z.ZodDefault<z.ZodBoolean>;
422
+ port: z.ZodDefault<z.ZodNumber>;
423
+ hostname: z.ZodDefault<z.ZodString>;
424
+ path: z.ZodDefault<z.ZodOptional<z.ZodString>>;
425
+ maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
426
+ connectionTimeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
427
+ heartbeatInterval: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
428
+ sessionExpireMs: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
429
+ https: z.ZodOptional<z.ZodObject<{
430
+ enabled: z.ZodDefault<z.ZodBoolean>;
431
+ cert: z.ZodString;
432
+ key: z.ZodString;
433
+ certPath: z.ZodOptional<z.ZodString>;
434
+ keyPath: z.ZodOptional<z.ZodString>;
435
+ ca: z.ZodOptional<z.ZodString>;
436
+ forceRedirect: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
437
+ httpPort: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
438
+ }, z.core.$strip>>;
439
+ auth: z.ZodOptional<z.ZodObject<{
440
+ type: z.ZodDefault<z.ZodEnum<{
441
+ token: "token";
442
+ oauth2: "oauth2";
443
+ }>>;
444
+ token: z.ZodOptional<z.ZodObject<{
445
+ enabled: z.ZodDefault<z.ZodBoolean>;
446
+ tokens: z.ZodDefault<z.ZodArray<z.ZodObject<{
447
+ name: z.ZodString;
448
+ value: z.ZodString;
449
+ permissions: z.ZodDefault<z.ZodArray<z.ZodString>>;
450
+ expiresAt: z.ZodOptional<z.ZodNumber>;
451
+ description: z.ZodOptional<z.ZodString>;
452
+ }, z.core.$strip>>>;
453
+ onInvalid: z.ZodDefault<z.ZodEnum<{
454
+ reject: "reject";
455
+ anonymous: "anonymous";
456
+ }>>;
457
+ allowAnonymous: z.ZodDefault<z.ZodBoolean>;
458
+ defaultPermissions: z.ZodDefault<z.ZodArray<z.ZodString>>;
459
+ }, z.core.$strip>>;
460
+ oauth2: z.ZodOptional<z.ZodObject<{
461
+ enabled: z.ZodDefault<z.ZodBoolean>;
462
+ authorizationServer: z.ZodString;
463
+ clientId: z.ZodString;
464
+ clientSecret: z.ZodString;
465
+ tokenValidationEndpoint: z.ZodString;
466
+ scope: z.ZodDefault<z.ZodArray<z.ZodString>>;
467
+ }, z.core.$strip>>;
468
+ }, z.core.$strip>>;
469
+ cors: z.ZodDefault<z.ZodBoolean>;
470
+ corsOrigins: z.ZodOptional<z.ZodArray<z.ZodString>>;
471
+ mdns: z.ZodDefault<z.ZodBoolean>;
472
+ mdnsDomain: z.ZodDefault<z.ZodOptional<z.ZodString>>;
473
+ }, z.core.$strip>>;
474
+ channels: z.ZodOptional<z.ZodObject<{
475
+ telegram: z.ZodOptional<z.ZodObject<{
476
+ enabled: z.ZodDefault<z.ZodBoolean>;
477
+ botToken: z.ZodString;
478
+ webhookUrl: z.ZodOptional<z.ZodString>;
479
+ maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
480
+ timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
481
+ }, z.core.$strip>>;
482
+ slack: z.ZodOptional<z.ZodObject<{
483
+ enabled: z.ZodDefault<z.ZodBoolean>;
484
+ botToken: z.ZodString;
485
+ appToken: z.ZodOptional<z.ZodString>;
486
+ signingSecret: z.ZodOptional<z.ZodString>;
487
+ maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
488
+ timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
489
+ }, z.core.$strip>>;
490
+ feishu: z.ZodOptional<z.ZodObject<{
491
+ enabled: z.ZodDefault<z.ZodBoolean>;
492
+ appId: z.ZodString;
493
+ appSecret: z.ZodString;
494
+ encryptKey: z.ZodOptional<z.ZodString>;
495
+ verificationToken: z.ZodOptional<z.ZodString>;
496
+ maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
497
+ timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
498
+ }, z.core.$strip>>;
499
+ wechat: z.ZodOptional<z.ZodObject<{
500
+ enabled: z.ZodDefault<z.ZodBoolean>;
501
+ mode: z.ZodDefault<z.ZodEnum<{
502
+ official: "official";
503
+ wecom: "wecom";
504
+ }>>;
505
+ appId: z.ZodString;
506
+ appSecret: z.ZodString;
507
+ token: z.ZodOptional<z.ZodString>;
508
+ encodingAESKey: z.ZodOptional<z.ZodString>;
509
+ agentId: z.ZodOptional<z.ZodString>;
510
+ maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
511
+ timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
512
+ }, z.core.$strip>>;
513
+ webchat: z.ZodOptional<z.ZodObject<{
514
+ enabled: z.ZodDefault<z.ZodBoolean>;
515
+ path: z.ZodDefault<z.ZodOptional<z.ZodString>>;
516
+ heartbeatInterval: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
517
+ connectionTimeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
518
+ maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
519
+ cors: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
520
+ }, z.core.$strip>>;
521
+ signal: z.ZodOptional<z.ZodObject<{
522
+ enabled: z.ZodDefault<z.ZodBoolean>;
523
+ serviceUrl: z.ZodDefault<z.ZodOptional<z.ZodString>>;
524
+ phoneNumber: z.ZodString;
525
+ password: z.ZodOptional<z.ZodString>;
526
+ maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
527
+ timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
528
+ }, z.core.$strip>>;
529
+ nostr: z.ZodOptional<z.ZodObject<{
530
+ enabled: z.ZodDefault<z.ZodBoolean>;
531
+ relays: z.ZodArray<z.ZodString>;
532
+ privateKey: z.ZodOptional<z.ZodString>;
533
+ publicKey: z.ZodOptional<z.ZodString>;
534
+ maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
535
+ timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
536
+ }, z.core.$strip>>;
537
+ }, z.core.$strip>>;
538
+ cluster: z.ZodOptional<z.ZodObject<{
539
+ nodeId: z.ZodString;
540
+ nodes: z.ZodDefault<z.ZodArray<z.ZodObject<{
541
+ id: z.ZodString;
542
+ address: z.ZodString;
543
+ enabled: z.ZodDefault<z.ZodBoolean>;
544
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
545
+ }, z.core.$strip>>>;
546
+ sync: z.ZodOptional<z.ZodObject<{
547
+ mode: z.ZodDefault<z.ZodEnum<{
548
+ push: "push";
549
+ pull: "pull";
550
+ both: "both";
551
+ }>>;
552
+ interval: z.ZodDefault<z.ZodNumber>;
553
+ pushEvents: z.ZodDefault<z.ZodArray<z.ZodEnum<{
554
+ register: "register";
555
+ deregister: "deregister";
556
+ heartbeat: "heartbeat";
557
+ status_change: "status_change";
558
+ }>>>;
559
+ conflictResolution: z.ZodDefault<z.ZodEnum<{
560
+ latest: "latest";
561
+ local: "local";
562
+ remote: "remote";
563
+ }>>;
564
+ }, z.core.$strip>>;
565
+ }, z.core.$strip>>;
566
+ connectionPool: z.ZodOptional<z.ZodObject<{
567
+ maxConnectionsPerChannel: z.ZodDefault<z.ZodNumber>;
568
+ idleTimeout: z.ZodDefault<z.ZodNumber>;
569
+ reuseStrategy: z.ZodDefault<z.ZodEnum<{
570
+ lru: "lru";
571
+ fifo: "fifo";
572
+ random: "random";
573
+ }>>;
574
+ healthCheckInterval: z.ZodDefault<z.ZodNumber>;
575
+ acquireTimeout: z.ZodDefault<z.ZodNumber>;
576
+ warmupCount: z.ZodDefault<z.ZodNumber>;
577
+ }, z.core.$strip>>;
578
+ messageQueue: z.ZodOptional<z.ZodObject<{
579
+ maxLength: z.ZodDefault<z.ZodNumber>;
580
+ concurrency: z.ZodDefault<z.ZodNumber>;
581
+ batchSize: z.ZodDefault<z.ZodNumber>;
582
+ batchTimeout: z.ZodDefault<z.ZodNumber>;
583
+ priorityLevels: z.ZodDefault<z.ZodNumber>;
584
+ }, z.core.$strip>>;
585
+ circuitBreaker: z.ZodOptional<z.ZodObject<{
586
+ failureThreshold: z.ZodDefault<z.ZodNumber>;
587
+ successThreshold: z.ZodDefault<z.ZodNumber>;
588
+ timeout: z.ZodDefault<z.ZodNumber>;
589
+ halfOpenDuration: z.ZodDefault<z.ZodNumber>;
590
+ }, z.core.$strip>>;
591
+ agentRegistry: z.ZodOptional<z.ZodObject<{
592
+ heartbeatInterval: z.ZodDefault<z.ZodNumber>;
593
+ heartbeatTimeout: z.ZodDefault<z.ZodNumber>;
594
+ heartbeatCheckInterval: z.ZodDefault<z.ZodNumber>;
595
+ autoDeregisterTimeout: z.ZodDefault<z.ZodNumber>;
596
+ maxAgents: z.ZodDefault<z.ZodNumber>;
597
+ persistenceFile: z.ZodOptional<z.ZodString>;
598
+ maxRegistrations: z.ZodDefault<z.ZodNumber>;
599
+ }, z.core.$strip>>;
600
+ session: z.ZodOptional<z.ZodObject<{
601
+ sessionTimeout: z.ZodDefault<z.ZodNumber>;
602
+ resumeGracePeriod: z.ZodDefault<z.ZodNumber>;
603
+ maxSessions: z.ZodDefault<z.ZodNumber>;
604
+ persistenceFile: z.ZodOptional<z.ZodString>;
605
+ }, z.core.$strip>>;
606
+ defaultAgent: z.ZodOptional<z.ZodString>;
607
+ logLevel: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
608
+ DEBUG: "DEBUG";
609
+ INFO: "INFO";
610
+ WARN: "WARN";
611
+ ERROR: "ERROR";
612
+ }>>>;
613
+ }, z.core.$catchall<z.ZodUnknown>>;
614
+ type GatewayConfig = z.infer<typeof GatewayConfigSchema>;
615
+ declare function validateConfig(config: unknown): GatewayConfig;
616
+ declare function parsePartialConfig(partial: unknown): GatewayConfig;
617
+
618
+ declare function loadConfig(directory?: string): Promise<GatewayConfig>;
619
+ declare function getConfig(): GatewayConfig | null;
620
+ declare function isConfigLoaded(): boolean;
621
+ declare function clearConfigCache(): void;
622
+ declare function getConfigDirectory(): string;
623
+ declare function getServerConfig(): Promise<GatewayServerConfig>;
624
+ declare function getChannelConfig<K extends keyof NonNullable<GatewayConfig['channels']>>(channelType: K): Promise<NonNullable<GatewayConfig['channels']>[K]>;
625
+ declare function getConnectionPoolConfig(): Promise<ConnectionPoolConfig>;
626
+ declare function getMessageQueueConfig(): Promise<MessageQueueConfig>;
627
+ declare function getCircuitBreakerConfig(): Promise<CircuitBreakerConfig>;
628
+ declare function getAgentRegistryConfig(): Promise<AgentRegistryConfig>;
629
+ declare function getSessionConfig(): Promise<SessionConfig$1>;
630
+ declare function getHTTPSConfig(): Promise<HTTPSConfig | undefined>;
631
+ declare function getAuthConfig(): Promise<AuthConfig | undefined>;
632
+ declare function getClusterConfig(): Promise<GatewayConfig['cluster'] | undefined>;
633
+ declare function getDefaultAgent(): Promise<string | undefined>;
634
+ declare function getLogLevel(): Promise<'DEBUG' | 'INFO' | 'WARN' | 'ERROR'>;
635
+
636
+ declare function createGatewayMessage(sessionId: string, type: 'input' | 'output' | 'system' | 'control', content: Array<{
637
+ type: 'text';
638
+ text: string;
639
+ } | {
640
+ type: 'image';
641
+ image: string | URL | Uint8Array;
642
+ mime?: string;
643
+ } | {
644
+ type: 'file';
645
+ data: string | URL | Uint8Array;
646
+ mime?: string;
647
+ }>, metadata?: {
648
+ channel?: {
649
+ platform?: PlatformType | string;
650
+ channelId?: string;
651
+ userId?: string;
652
+ chatId?: string;
653
+ [key: string]: unknown;
654
+ };
655
+ context?: Record<string, unknown>;
656
+ agent?: Record<string, unknown>;
657
+ }): GatewayMessage;
658
+ declare function createTextMessage(sessionId: string, type: 'input' | 'output' | 'system' | 'control', text: string, metadata?: {
659
+ channel?: {
660
+ platform?: PlatformType | string;
661
+ channelId?: string;
662
+ userId?: string;
663
+ chatId?: string;
664
+ [key: string]: unknown;
665
+ };
666
+ context?: Record<string, unknown>;
667
+ agent?: Record<string, unknown>;
668
+ }): GatewayMessage;
669
+
670
+ interface ChannelConfig {
671
+ enabled: boolean;
672
+ platform: Record<string, unknown>;
673
+ session: SessionConfig;
674
+ routing: RoutingConfig;
675
+ }
676
+ interface SessionConfig {
677
+ autoCreate: boolean;
678
+ resetPolicy: SessionResetPolicy;
679
+ timeout?: number;
680
+ }
681
+ type SessionResetPolicy = 'never' | 'onNewConversation' | 'timeout';
682
+ interface RoutingConfig {
683
+ broadcast: boolean;
684
+ dispatchToSubAgent: boolean;
685
+ subAgent?: SubAgentConfig;
686
+ }
687
+ interface ChannelPlugin {
688
+ readonly id: string;
689
+ readonly platform: PlatformType;
690
+ readonly name: string;
691
+ readonly version?: string;
692
+ start(config: ChannelConfig, messageHandler: MessageHandler): Promise<void>;
693
+ stop(): Promise<void>;
694
+ send(message: GatewayMessage): Promise<string>;
695
+ healthCheck(): Promise<ChannelHealth>;
696
+ getStatus(): ChannelStatus;
697
+ }
698
+ interface MessageHandler {
699
+ onMessage(message: GatewayMessage): Promise<void>;
700
+ onEvent(event: ChannelEvent): Promise<void>;
701
+ }
702
+ interface ChannelHealth {
703
+ healthy: boolean;
704
+ lastCheck: number;
705
+ error?: string;
706
+ details?: Record<string, unknown>;
707
+ }
708
+ interface ChannelStatus {
709
+ status: ChannelStatusType;
710
+ lastActivity?: number;
711
+ reconnectAttempts?: number;
712
+ error?: string;
713
+ }
714
+ type ChannelStatusType = 'starting' | 'running' | 'stopping' | 'stopped' | 'error' | 'reconnecting';
715
+ interface ChannelEvent {
716
+ type: ChannelEventType;
717
+ channelId: string;
718
+ data?: unknown;
719
+ timestamp: number;
720
+ }
721
+ type ChannelEventType = 'connected' | 'disconnected' | 'reconnecting' | 'error' | 'message_received' | 'message_sent' | 'user_joined' | 'user_left';
722
+
723
+ interface GatewaySession {
724
+ id: string;
725
+ channel: SessionChannelInfo;
726
+ backendSessionId: string | null;
727
+ subscribers: Set<string>;
728
+ state: SessionState;
729
+ createdAt: number;
730
+ lastActiveAt: number;
731
+ }
732
+ interface SessionChannelInfo {
733
+ platform: PlatformType;
734
+ channelId: string;
735
+ chatId?: string;
736
+ userId?: string;
737
+ }
738
+ interface SessionState {
739
+ status: SessionStatusType;
740
+ messageCount: number;
741
+ lastMessageAt: number | null;
742
+ }
743
+ type SessionStatusType = 'active' | 'idle' | 'closed';
744
+ interface SessionContext {
745
+ userId?: string;
746
+ chatId?: string;
747
+ threadId?: string;
748
+ [key: string]: unknown;
749
+ }
750
+ interface SessionFilter {
751
+ platform?: PlatformType;
752
+ channelId?: string;
753
+ userId?: string;
754
+ status?: SessionStatusType;
755
+ }
756
+ declare function generateSessionId(channel: SessionChannelInfo): string;
757
+ declare function createDefaultSessionState(): SessionState;
758
+
759
+ interface Subscriber {
760
+ id: string;
761
+ type: SubscriberType;
762
+ connection: SubscriberConnection;
763
+ sessions: Set<string>;
764
+ createdAt: number;
765
+ lastActiveAt: number;
766
+ }
767
+ type SubscriberType = 'subagent' | 'tui' | 'desktop' | 'browser' | 'mobile' | 'api';
768
+ interface SubscriberConnection {
769
+ send(message: GatewayMessage): Promise<void>;
770
+ close(): Promise<void>;
771
+ isConnected(): boolean;
772
+ }
773
+ interface Subscription {
774
+ id: string;
775
+ subscriberId: string;
776
+ sessionId: string;
777
+ createdAt: number;
778
+ options?: SubscriptionOptions;
779
+ }
780
+ interface SubscriptionOptions {
781
+ includeHistory?: boolean;
782
+ historyLimit?: number;
783
+ includeSystem?: boolean;
784
+ includeControl?: boolean;
785
+ }
786
+ interface RouteResult {
787
+ success: boolean;
788
+ broadcastCount: number;
789
+ dispatchedToSubAgent: boolean;
790
+ error?: string;
791
+ }
792
+ declare function generateSubscriptionId(subscriberId: string, sessionId: string): string;
793
+
794
+ declare const DEFAULT_WEBSOCKET_SERVER_CONFIG: Partial<{
795
+ enabled: boolean;
796
+ port: number;
797
+ hostname: string;
798
+ path: string;
799
+ maxConnections: number;
800
+ connectionTimeout: number;
801
+ heartbeatInterval: number;
802
+ sessionExpireMs: number;
803
+ cors: boolean;
804
+ mdns: boolean;
805
+ mdnsDomain: string;
806
+ https?: {
807
+ enabled: boolean;
808
+ cert: string;
809
+ key: string;
810
+ forceRedirect: boolean;
811
+ httpPort: number;
812
+ certPath?: string | undefined;
813
+ keyPath?: string | undefined;
814
+ ca?: string | undefined;
815
+ } | undefined;
816
+ auth?: {
817
+ type: "token" | "oauth2";
818
+ token?: {
819
+ enabled: boolean;
820
+ tokens: {
821
+ name: string;
822
+ value: string;
823
+ permissions: string[];
824
+ expiresAt?: number | undefined;
825
+ description?: string | undefined;
826
+ }[];
827
+ onInvalid: "reject" | "anonymous";
828
+ allowAnonymous: boolean;
829
+ defaultPermissions: string[];
830
+ } | undefined;
831
+ oauth2?: {
832
+ enabled: boolean;
833
+ authorizationServer: string;
834
+ clientId: string;
835
+ clientSecret: string;
836
+ tokenValidationEndpoint: string;
837
+ scope: string[];
838
+ } | undefined;
839
+ } | undefined;
840
+ corsOrigins?: string[] | undefined;
841
+ }>;
842
+ type ClientMessageType = 'initialize' | 'subscribe' | 'unsubscribe' | 'message' | 'ping' | 'interrupt' | 'releaseSubscription' | 'agent_list_request' | 'agent_subscribe';
843
+ type ServerMessageType = 'connected' | 'initialize_response' | 'subscribed' | 'unsubscribed' | 'event' | 'response' | 'error' | 'pong' | 'interrupted' | 'session_closed' | 'subscriptionReleased' | 'agent_list_response' | 'agent_update';
844
+ interface WebSocketMessageBase {
845
+ type: ClientMessageType | ServerMessageType;
846
+ sessionId?: string;
847
+ }
848
+ interface ClientInitializeMessage extends WebSocketMessageBase {
849
+ type: 'initialize';
850
+ payload?: {
851
+ name?: string;
852
+ version?: string;
853
+ capabilities?: string[];
854
+ };
855
+ }
856
+ interface ClientSubscribeMessage extends WebSocketMessageBase {
857
+ type: 'subscribe';
858
+ sessionId: string;
859
+ payload?: {
860
+ eventTypes?: string[];
861
+ };
862
+ }
863
+ interface ClientUnsubscribeMessage extends WebSocketMessageBase {
864
+ type: 'unsubscribe';
865
+ sessionId: string;
866
+ }
867
+ interface ClientMessageMessage extends WebSocketMessageBase {
868
+ type: 'message';
869
+ sessionId: string;
870
+ payload: {
871
+ content: string | Array<{
872
+ type: 'text';
873
+ text: string;
874
+ } | {
875
+ type: 'image';
876
+ image: string | URL | Uint8Array;
877
+ mime?: string;
878
+ }>;
879
+ [key: string]: unknown;
880
+ };
881
+ }
882
+ interface ClientPingMessage extends WebSocketMessageBase {
883
+ type: 'ping';
884
+ }
885
+ interface ClientInterruptMessage extends WebSocketMessageBase {
886
+ type: 'interrupt';
887
+ sessionId: string;
888
+ }
889
+ interface ClientReleaseSubscriptionMessage extends WebSocketMessageBase {
890
+ type: 'releaseSubscription';
891
+ sessionId: string;
892
+ }
893
+ interface ClientAgentListRequestMessage extends WebSocketMessageBase {
894
+ type: 'agent_list_request';
895
+ requestId: string;
896
+ }
897
+ interface ClientAgentSubscribeMessage extends WebSocketMessageBase {
898
+ type: 'agent_subscribe';
899
+ subscribe: boolean;
900
+ }
901
+ type ClientMessage = ClientInitializeMessage | ClientSubscribeMessage | ClientUnsubscribeMessage | ClientMessageMessage | ClientPingMessage | ClientInterruptMessage | ClientReleaseSubscriptionMessage | ClientAgentListRequestMessage | ClientAgentSubscribeMessage;
902
+ interface ServerConnectedMessage extends WebSocketMessageBase {
903
+ type: 'connected';
904
+ clientId: string;
905
+ payload?: {
906
+ version?: string;
907
+ capabilities?: string[];
908
+ };
909
+ }
910
+ interface ServerInitializeResponseMessage extends WebSocketMessageBase {
911
+ type: 'initialize_response';
912
+ success: boolean;
913
+ result?: {
914
+ sessionId?: string;
915
+ capabilities?: string[];
916
+ [key: string]: unknown;
917
+ };
918
+ error?: string;
919
+ }
920
+ interface ServerSubscribedMessage extends WebSocketMessageBase {
921
+ type: 'subscribed';
922
+ sessionId: string;
923
+ }
924
+ interface ServerUnsubscribedMessage extends WebSocketMessageBase {
925
+ type: 'unsubscribed';
926
+ sessionId: string;
927
+ }
928
+ interface ServerEventMessage extends WebSocketMessageBase {
929
+ type: 'event';
930
+ sessionId: string;
931
+ payload: {
932
+ eventType: string;
933
+ [key: string]: unknown;
934
+ };
935
+ }
936
+ interface ServerResponseMessage extends WebSocketMessageBase {
937
+ type: 'response';
938
+ sessionId: string;
939
+ result?: unknown;
940
+ success: boolean;
941
+ error?: string;
942
+ }
943
+ interface ServerErrorMessage extends WebSocketMessageBase {
944
+ type: 'error';
945
+ message: string;
946
+ code?: string;
947
+ sessionId?: string;
948
+ }
949
+ interface ServerPongMessage extends WebSocketMessageBase {
950
+ type: 'pong';
951
+ }
952
+ interface ServerInterruptedMessage extends WebSocketMessageBase {
953
+ type: 'interrupted';
954
+ sessionId: string;
955
+ success: boolean;
956
+ error?: string;
957
+ }
958
+ interface ServerSessionClosedMessage extends WebSocketMessageBase {
959
+ type: 'session_closed';
960
+ sessionId: string;
961
+ payload?: {
962
+ reason?: string;
963
+ };
964
+ }
965
+ interface ServerSubscriptionReleasedMessage extends WebSocketMessageBase {
966
+ type: 'subscriptionReleased';
967
+ sessionId: string;
968
+ }
969
+ interface ServerAgentListResponseMessage extends WebSocketMessageBase {
970
+ type: 'agent_list_response';
971
+ requestId: string;
972
+ agents: Array<{
973
+ id: string;
974
+ name: string;
975
+ sourceGatewayId: string;
976
+ address: string;
977
+ capabilities: string[];
978
+ status: 'healthy' | 'unhealthy' | 'offline';
979
+ updatedAt: number;
980
+ metadata?: Record<string, unknown>;
981
+ }>;
982
+ }
983
+ interface ServerAgentUpdateMessage extends WebSocketMessageBase {
984
+ type: 'agent_update';
985
+ action: 'add' | 'update' | 'remove';
986
+ agent: {
987
+ id: string;
988
+ name: string;
989
+ sourceGatewayId: string;
990
+ address: string;
991
+ capabilities: string[];
992
+ status: 'healthy' | 'unhealthy' | 'offline';
993
+ updatedAt: number;
994
+ metadata?: Record<string, unknown>;
995
+ };
996
+ }
997
+ type ServerMessage = ServerConnectedMessage | ServerInitializeResponseMessage | ServerSubscribedMessage | ServerUnsubscribedMessage | ServerEventMessage | ServerResponseMessage | ServerErrorMessage | ServerPongMessage | ServerInterruptedMessage | ServerSessionClosedMessage | ServerSubscriptionReleasedMessage | ServerAgentListResponseMessage | ServerAgentUpdateMessage;
998
+ type WebSocketMessage = ClientMessage | ServerMessage;
999
+ interface ClientSubscription {
1000
+ clientId: string;
1001
+ ws: WSContext;
1002
+ subscribedSessions: Set<string>;
1003
+ subscribedEventTypes: Set<string>;
1004
+ authInfo?: {
1005
+ tokenName: string;
1006
+ permissions: string[];
1007
+ };
1008
+ connectedAt: number;
1009
+ lastActivityAt: number;
1010
+ }
1011
+ type WebSocketConnectionState = 'connecting' | 'connected' | 'disconnecting' | 'disconnected';
1012
+ interface WebSocketConnectionInfo {
1013
+ clientId: string;
1014
+ state: WebSocketConnectionState;
1015
+ connectedAt: number;
1016
+ lastActivityAt: number;
1017
+ remoteAddress?: string;
1018
+ authInfo?: ClientSubscription['authInfo'];
1019
+ }
1020
+ type SessionEventType = 'message' | 'thinking' | 'tool_use' | 'tool_result' | 'error' | 'complete' | 'interrupted' | 'status_change';
1021
+ interface SessionEventPayload {
1022
+ type: SessionEventType | string;
1023
+ sessionId: string;
1024
+ properties: {
1025
+ [key: string]: unknown;
1026
+ };
1027
+ }
1028
+ interface HealthCheckResponse {
1029
+ status: 'healthy' | 'unhealthy';
1030
+ timestamp: number;
1031
+ version?: string;
1032
+ }
1033
+ interface ServerStatusResponse {
1034
+ status: 'running' | 'stopping' | 'stopped';
1035
+ connections: number;
1036
+ sessions: number;
1037
+ subscriptions: number;
1038
+ uptime: number;
1039
+ version?: string;
1040
+ }
1041
+ interface CreateSessionRequest {
1042
+ title?: string;
1043
+ channel?: {
1044
+ platform?: PlatformType | string;
1045
+ channelId?: string;
1046
+ userId?: string;
1047
+ chatId?: string;
1048
+ };
1049
+ context?: Record<string, unknown>;
1050
+ }
1051
+ interface CreateSessionResponse {
1052
+ id: string;
1053
+ createdAt: number;
1054
+ }
1055
+ interface SendMessageRequest {
1056
+ content: string | Array<{
1057
+ type: 'text';
1058
+ text: string;
1059
+ } | {
1060
+ type: 'image';
1061
+ image: string;
1062
+ mime?: string;
1063
+ }>;
1064
+ [key: string]: unknown;
1065
+ }
1066
+ interface SendMessageResponse {
1067
+ messageId: string;
1068
+ sessionId: string;
1069
+ createdAt: number;
1070
+ }
1071
+ interface SubscriptionsResponse {
1072
+ subscriptions: Array<{
1073
+ sessionId: string;
1074
+ subscriberCount: number;
1075
+ subscribers: string[];
1076
+ }>;
1077
+ total: number;
1078
+ }
1079
+
1080
+ interface TokenConfig {
1081
+ name: string;
1082
+ value: string;
1083
+ permissions: string[];
1084
+ expiresAt?: number;
1085
+ description?: string;
1086
+ }
1087
+ interface AuthResult {
1088
+ success: boolean;
1089
+ authInfo?: {
1090
+ tokenName: string;
1091
+ permissions: string[];
1092
+ };
1093
+ error?: string;
1094
+ }
1095
+ interface IAuthProvider {
1096
+ validateToken(token: string): Promise<AuthResult>;
1097
+ checkPermission(authInfo: AuthResult['authInfo'], permission: string): boolean;
1098
+ checkPermissions(authInfo: AuthResult['authInfo'], permissions: string[]): boolean;
1099
+ }
1100
+ declare const DEFAULT_TOKEN_AUTH_CONFIG: {
1101
+ type: "token";
1102
+ enabled: boolean;
1103
+ tokens: never[];
1104
+ onInvalid: "reject";
1105
+ allowAnonymous: boolean;
1106
+ defaultPermissions: never[];
1107
+ };
1108
+
1109
+ type AgentHealthStatus = 'healthy' | 'unhealthy' | 'offline';
1110
+ interface AgentRegistration {
1111
+ id: string;
1112
+ name: string;
1113
+ capabilities: string[];
1114
+ address: string;
1115
+ status: AgentHealthStatus;
1116
+ lastHeartbeat: number;
1117
+ registeredAt: number;
1118
+ connectionCount: number;
1119
+ metadata?: Record<string, unknown>;
1120
+ }
1121
+ type AgentRegistrationRequest = Omit<AgentRegistration, 'registeredAt' | 'lastHeartbeat' | 'connectionCount' | 'status'>;
1122
+ declare const DEFAULT_AGENT_REGISTRY_CONFIG: {
1123
+ readonly heartbeatInterval: 30000;
1124
+ readonly heartbeatTimeout: 90000;
1125
+ readonly heartbeatCheckInterval: 10000;
1126
+ readonly autoDeregisterTimeout: 300000;
1127
+ readonly maxAgents: 100;
1128
+ readonly maxRegistrations: 1000;
1129
+ };
1130
+ type AgentSelectionStrategy = 'random' | 'round-robin' | 'least-connections';
1131
+ interface AgentSelectionOptions {
1132
+ strategy: AgentSelectionStrategy;
1133
+ capabilities?: string[];
1134
+ healthyOnly?: boolean;
1135
+ }
1136
+ interface AgentHeartbeat {
1137
+ agentId: string;
1138
+ timestamp: number;
1139
+ status: AgentHealthStatus;
1140
+ metrics?: {
1141
+ cpuUsage?: number;
1142
+ memoryUsage?: number;
1143
+ connectionCount?: number;
1144
+ messageQueueLength?: number;
1145
+ };
1146
+ }
1147
+ interface AgentSelectionRecord {
1148
+ sessionId: string;
1149
+ messageId: string;
1150
+ agentId: string;
1151
+ selectedAt: number;
1152
+ strategy: AgentSelectionStrategy;
1153
+ }
1154
+ interface AgentRegistryStats {
1155
+ totalAgents: number;
1156
+ healthyAgents: number;
1157
+ unhealthyAgents: number;
1158
+ offlineAgents: number;
1159
+ totalConnections: number;
1160
+ }
1161
+
1162
+ interface GatewayNodeInfo {
1163
+ id: string;
1164
+ name: string;
1165
+ address: string;
1166
+ port: number;
1167
+ lastSyncAt: number;
1168
+ status: 'online' | 'offline' | 'unknown';
1169
+ metadata?: Record<string, unknown>;
1170
+ }
1171
+ interface AgentSyncInfo {
1172
+ id: string;
1173
+ name: string;
1174
+ sourceGatewayId: string;
1175
+ address: string;
1176
+ capabilities: string[];
1177
+ status: AgentHealthStatus;
1178
+ updatedAt: number;
1179
+ metadata?: Record<string, unknown>;
1180
+ }
1181
+ type SyncMode = 'pull' | 'push' | 'both';
1182
+ type PushEventType = 'register' | 'deregister' | 'heartbeat' | 'status_change';
1183
+ type ConflictResolutionStrategy = 'latest' | 'local' | 'remote';
1184
+ interface SyncConfig {
1185
+ mode: SyncMode;
1186
+ interval: number;
1187
+ pushEvents: PushEventType[];
1188
+ conflictResolution: ConflictResolutionStrategy;
1189
+ remoteNodes: Array<{
1190
+ id: string;
1191
+ address: string;
1192
+ port: number;
1193
+ }>;
1194
+ }
1195
+ declare const DEFAULT_SYNC_CONFIG: SyncConfig;
1196
+ interface AgentListRequestMessage {
1197
+ type: 'agent_list_request';
1198
+ requestId: string;
1199
+ sourceNodeId: string;
1200
+ timestamp: number;
1201
+ incremental?: boolean;
1202
+ lastSyncAt?: number;
1203
+ }
1204
+ interface AgentListResponseMessage {
1205
+ type: 'agent_list_response';
1206
+ requestId: string;
1207
+ sourceNodeId: string;
1208
+ timestamp: number;
1209
+ agents: AgentSyncInfo[];
1210
+ fullList: boolean;
1211
+ syncAt: number;
1212
+ }
1213
+ interface AgentRegisterMessage {
1214
+ type: 'agent_register';
1215
+ sourceNodeId: string;
1216
+ timestamp: number;
1217
+ agent: AgentSyncInfo;
1218
+ }
1219
+ interface AgentDeregisterMessage {
1220
+ type: 'agent_deregister';
1221
+ sourceNodeId: string;
1222
+ timestamp: number;
1223
+ agentId: string;
1224
+ }
1225
+ interface AgentHeartbeatSyncMessage {
1226
+ type: 'agent_heartbeat';
1227
+ sourceNodeId: string;
1228
+ timestamp: number;
1229
+ agentId: string;
1230
+ heartbeatAt: number;
1231
+ status: AgentHealthStatus;
1232
+ }
1233
+ interface AgentStatusChangeMessage {
1234
+ type: 'agent_status_change';
1235
+ sourceNodeId: string;
1236
+ timestamp: number;
1237
+ agentId: string;
1238
+ oldStatus: AgentHealthStatus;
1239
+ newStatus: AgentHealthStatus;
1240
+ changedAt: number;
1241
+ }
1242
+ type SyncMessage = AgentListRequestMessage | AgentListResponseMessage | AgentRegisterMessage | AgentDeregisterMessage | AgentHeartbeatSyncMessage | AgentStatusChangeMessage;
1243
+ interface SyncState {
1244
+ localNodeId: string;
1245
+ remoteNodes: Map<string, {
1246
+ info: GatewayNodeInfo;
1247
+ lastSyncAt: number;
1248
+ status: 'syncing' | 'synced' | 'error';
1249
+ error?: string;
1250
+ }>;
1251
+ localAgents: Map<string, AgentSyncInfo>;
1252
+ remoteAgents: Map<string, AgentSyncInfo>;
1253
+ }
1254
+ interface SyncStats {
1255
+ localAgentCount: number;
1256
+ remoteAgentCount: number;
1257
+ totalAgentCount: number;
1258
+ onlineNodeCount: number;
1259
+ offlineNodeCount: number;
1260
+ lastSyncAt: number | null;
1261
+ }
1262
+
1263
+ declare const DEFAULT_CONNECTION_POOL_CONFIG: {
1264
+ maxConnectionsPerChannel: number;
1265
+ idleTimeout: number;
1266
+ reuseStrategy: "lru";
1267
+ healthCheckInterval: number;
1268
+ acquireTimeout: number;
1269
+ warmupCount: number;
1270
+ };
1271
+ type ConnectionState$1 = 'idle' | 'active' | 'unhealthy' | 'closed';
1272
+ interface PooledConnection<T = unknown> {
1273
+ id: string;
1274
+ channelId: string;
1275
+ connection: T;
1276
+ state: ConnectionState$1;
1277
+ lastActivity: number;
1278
+ createdAt: number;
1279
+ useCount: number;
1280
+ }
1281
+ interface ConnectionPoolStats {
1282
+ activeConnections: number;
1283
+ idleConnections: number;
1284
+ totalConnections: number;
1285
+ waitingQueueLength: number;
1286
+ unhealthyConnections: number;
1287
+ }
1288
+ type ConnectionFactory<T = unknown> = (channelId: string) => Promise<T>;
1289
+ type ConnectionCloser<T = unknown> = (connection: T) => Promise<void>;
1290
+ type ConnectionHealthChecker<T = unknown> = (connection: T) => Promise<boolean>;
1291
+ type ConnectionPoolEventType = 'connection_created' | 'connection_acquired' | 'connection_released' | 'connection_closed' | 'connection_unhealthy' | 'pool_exhausted' | 'pool_warmed_up';
1292
+ interface ConnectionPoolEvent<T = unknown> {
1293
+ type: ConnectionPoolEventType;
1294
+ connectionId?: string;
1295
+ channelId?: string;
1296
+ connection?: PooledConnection<T>;
1297
+ timestamp: number;
1298
+ data?: Record<string, unknown>;
1299
+ }
1300
+ type ConnectionPoolEventCallback<T = unknown> = (event: ConnectionPoolEvent<T>) => void | Promise<void>;
1301
+
1302
+ interface LockState {
1303
+ sessionId: string;
1304
+ messageId: string;
1305
+ holderId: string;
1306
+ acquiredAt: number;
1307
+ timeout: number;
1308
+ }
1309
+ interface LockManagerConfig {
1310
+ defaultTimeout: number;
1311
+ checkInterval: number;
1312
+ }
1313
+ declare class MessageLockManager {
1314
+ private log;
1315
+ private config;
1316
+ private locks;
1317
+ private cleanupTimer;
1318
+ constructor(config?: Partial<LockManagerConfig>);
1319
+ tryAcquire(sessionId: string, messageId: string, subscriberId: string, timeout?: number): boolean;
1320
+ release(sessionId: string, subscriberId: string): boolean;
1321
+ forceRelease(sessionId: string): boolean;
1322
+ private isLockExpired;
1323
+ getLock(sessionId: string): LockState | undefined;
1324
+ isLocked(sessionId: string): boolean;
1325
+ getHolder(sessionId: string): string | undefined;
1326
+ startCleanup(): void;
1327
+ stopCleanup(): void;
1328
+ cleanupExpired(): number;
1329
+ getAllLocks(): LockState[];
1330
+ getLockCount(): number;
1331
+ }
1332
+
1333
+ interface RetryPolicy {
1334
+ maxRetries: number;
1335
+ initialDelay: number;
1336
+ maxDelay: number;
1337
+ backoffMultiplier: number;
1338
+ }
1339
+ interface RetryRecord {
1340
+ messageId: string;
1341
+ retryCount: number;
1342
+ nextRetryAt: number;
1343
+ errors: Array<{
1344
+ error: string;
1345
+ timestamp: number;
1346
+ }>;
1347
+ }
1348
+ type RetryHandler = (message: GatewayMessage) => Promise<void>;
1349
+ declare class MessageRetryManager {
1350
+ private log;
1351
+ private policy;
1352
+ private retryQueue;
1353
+ private retryTimer;
1354
+ private handlers;
1355
+ constructor(policy?: Partial<RetryPolicy>);
1356
+ registerHandler(messageId: string, handler: RetryHandler): void;
1357
+ unregisterHandler(messageId: string): void;
1358
+ scheduleRetry(message: GatewayMessage, error: Error): boolean;
1359
+ getPendingRetries(): RetryRecord[];
1360
+ executeRetry(record: RetryRecord): Promise<boolean>;
1361
+ clearRetry(messageId: string): void;
1362
+ startProcessing(): void;
1363
+ stopProcessing(): void;
1364
+ getStats(): {
1365
+ pendingCount: number;
1366
+ totalErrors: number;
1367
+ };
1368
+ }
1369
+
1370
+ interface CancelEvent {
1371
+ sessionId: string;
1372
+ messageId: string;
1373
+ processedBy: string;
1374
+ reason: 'completed' | 'failed' | 'timeout';
1375
+ timestamp: number;
1376
+ }
1377
+ type CancelEventHandler = (event: CancelEvent) => void | Promise<void>;
1378
+ declare class MessageRouter {
1379
+ private log;
1380
+ private subscribers;
1381
+ private subscriptions;
1382
+ private sessionSubscriptions;
1383
+ private channelPlugins;
1384
+ private lockManager;
1385
+ private retryManager;
1386
+ private cancelHandlers;
1387
+ constructor();
1388
+ onCancel(handler: CancelEventHandler): void;
1389
+ offCancel(handler: CancelEventHandler): void;
1390
+ private emitCancel;
1391
+ route(message: GatewayMessage): Promise<RouteResult>;
1392
+ completeMessage(sessionId: string, messageId: string, subscriberId: string, reason?: 'completed' | 'failed' | 'timeout'): Promise<void>;
1393
+ scheduleRetry(message: GatewayMessage, error: Error): boolean;
1394
+ subscribe(sessionId: string, subscriber: Subscriber): Promise<Subscription>;
1395
+ unsubscribe(subscriptionId: string): Promise<void>;
1396
+ unsubscribeAll(subscriberId: string): Promise<void>;
1397
+ registerChannel(plugin: ChannelPlugin): Promise<void>;
1398
+ unregisterChannel(pluginId: string): Promise<void>;
1399
+ getSubscriberCount(sessionId: string): number;
1400
+ getAllSubscribers(): Subscriber[];
1401
+ getChannelPlugin(pluginId: string): ChannelPlugin | undefined;
1402
+ getAllChannelPlugins(): ChannelPlugin[];
1403
+ getLockManager(): MessageLockManager;
1404
+ getRetryManager(): MessageRetryManager;
1405
+ shutdown(): Promise<void>;
1406
+ }
1407
+
1408
+ interface SessionManagerConfig {
1409
+ enablePersistence: boolean;
1410
+ storagePath: string;
1411
+ autoSaveInterval: number;
1412
+ maxRetentionDays: number;
1413
+ }
1414
+ declare class GatewaySessionManager {
1415
+ private log;
1416
+ private sessionStore;
1417
+ private config;
1418
+ private initialized;
1419
+ constructor(config?: Partial<SessionManagerConfig>);
1420
+ initialize(): Promise<void>;
1421
+ close(): Promise<void>;
1422
+ getOrCreate(channelInfo: SessionChannelInfo, context?: SessionContext): Promise<GatewaySession>;
1423
+ get(sessionId: string): GatewaySession | undefined;
1424
+ closeSession(sessionId: string): Promise<void>;
1425
+ closeById(sessionId: string): Promise<void>;
1426
+ bindBackendSession(gatewaySessionId: string, backendSessionId: string): Promise<void>;
1427
+ unbindBackendSession(gatewaySessionId: string): Promise<void>;
1428
+ getState(sessionId: string): SessionState | undefined;
1429
+ incrementMessageCountOrCreate(sessionId: string, channelInfo?: SessionChannelInfo): Promise<GatewaySession>;
1430
+ incrementMessageCount(sessionId: string): Promise<void>;
1431
+ addSubscriber(sessionId: string, subscriberId: string): Promise<void>;
1432
+ removeSubscriber(sessionId: string, subscriberId: string): Promise<void>;
1433
+ query(filter: SessionFilter): GatewaySession[];
1434
+ getSessionsByChannel(channelId: string): GatewaySession[];
1435
+ getAllSessions(): GatewaySession[];
1436
+ getSessionCount(): number;
1437
+ cleanupIdleSessions(idleTimeoutMs: number): Promise<number>;
1438
+ save(): Promise<void>;
1439
+ getStats(): {
1440
+ total: number;
1441
+ byStatus: Record<SessionStatusType, number>;
1442
+ byPlatform: Record<string, number>;
1443
+ };
1444
+ }
1445
+
1446
+ declare class AgentRegistry {
1447
+ private config;
1448
+ private agents;
1449
+ private heartbeatTimer;
1450
+ private roundRobinIndex;
1451
+ constructor(config?: Partial<AgentRegistryConfig>);
1452
+ register(agent: AgentRegistrationRequest): Promise<void>;
1453
+ deregister(agentId: string): Promise<void>;
1454
+ heartbeat(agentId: string, metrics?: AgentRegistration['metadata']): Promise<void>;
1455
+ getAgent(agentId: string): AgentRegistration | undefined;
1456
+ getAllAgents(): AgentRegistration[];
1457
+ getHealthyAgents(): AgentRegistration[];
1458
+ selectAgent(options: AgentSelectionOptions): AgentRegistration | undefined;
1459
+ incrementConnection(agentId: string): void;
1460
+ decrementConnection(agentId: string): void;
1461
+ startHeartbeatCheck(): void;
1462
+ stopHeartbeatCheck(): void;
1463
+ private checkHeartbeats;
1464
+ private selectRandom;
1465
+ private selectRoundRobin;
1466
+ private selectLeastConnections;
1467
+ getStats(): AgentRegistryStats;
1468
+ setAgentStatus(agentId: string, status: AgentHealthStatus): void;
1469
+ setLastHeartbeat(agentId: string, timestamp: number): void;
1470
+ }
1471
+
1472
+ declare class AgentSyncManager {
1473
+ private config;
1474
+ private registry;
1475
+ private localNodeId;
1476
+ private localNodeName;
1477
+ private remoteNodes;
1478
+ private remoteAgents;
1479
+ private syncTimer;
1480
+ private running;
1481
+ private httpClient;
1482
+ constructor(options: {
1483
+ registry: AgentRegistry;
1484
+ localNodeId: string;
1485
+ localNodeName: string;
1486
+ config?: Partial<SyncConfig>;
1487
+ httpClient?: {
1488
+ fetch: typeof fetch;
1489
+ };
1490
+ });
1491
+ start(): Promise<void>;
1492
+ stop(): Promise<void>;
1493
+ private pullFromAllNodes;
1494
+ pullFromNode(nodeId: string): Promise<AgentSyncInfo[]>;
1495
+ pushEvent(message: SyncMessage): Promise<void>;
1496
+ pushToNode(nodeId: string, message: SyncMessage): Promise<void>;
1497
+ handleSyncMessage(message: SyncMessage): Promise<void>;
1498
+ private handleAgentListRequest;
1499
+ private handleAgentListResponse;
1500
+ private handleAgentRegister;
1501
+ private handleAgentDeregister;
1502
+ private handleAgentHeartbeat;
1503
+ private handleAgentStatusChange;
1504
+ private resolveConflict;
1505
+ private getLocalAgentsForSync;
1506
+ getMergedAgentList(): AgentSyncInfo[];
1507
+ getRemoteAgents(): AgentSyncInfo[];
1508
+ getStats(): SyncStats;
1509
+ isRunning(): boolean;
1510
+ addRemoteNode(node: {
1511
+ id: string;
1512
+ address: string;
1513
+ port: number;
1514
+ }): void;
1515
+ removeRemoteNode(nodeId: string): void;
1516
+ }
1517
+
1518
+ declare namespace Log {
1519
+ const Level: z.ZodEnum<{
1520
+ DEBUG: "DEBUG";
1521
+ INFO: "INFO";
1522
+ WARN: "WARN";
1523
+ ERROR: "ERROR";
1524
+ }>;
1525
+ type Level = z.infer<typeof Level>;
1526
+ function getLevel(): Level;
1527
+ type Logger = {
1528
+ debug(message?: any, extra?: Record<string, any>): void;
1529
+ info(message?: any, extra?: Record<string, any>): void;
1530
+ error(message?: any, extra?: Record<string, any>): void;
1531
+ warn(message?: any, extra?: Record<string, any>): void;
1532
+ tag(key: string, value: string): Logger;
1533
+ clone(): Logger;
1534
+ time(message: string, extra?: Record<string, any>): {
1535
+ stop(): void;
1536
+ [Symbol.dispose](): void;
1537
+ };
1538
+ };
1539
+ const Default: Logger;
1540
+ interface Options {
1541
+ print: boolean;
1542
+ logDir: string;
1543
+ logFile?: string;
1544
+ dev?: boolean;
1545
+ level?: Level;
1546
+ }
1547
+ function file(): string;
1548
+ function init(options: Options): Promise<void>;
1549
+ function close(): Promise<void>;
1550
+ function create(tags?: Record<string, any>): Logger;
1551
+ }
1552
+
1553
+ declare abstract class BaseChannelPlugin implements ChannelPlugin {
1554
+ abstract readonly id: string;
1555
+ abstract readonly platform: PlatformType;
1556
+ abstract readonly name: string;
1557
+ readonly version?: string;
1558
+ protected log: ReturnType<typeof Log.create>;
1559
+ protected config: ChannelConfig | null;
1560
+ protected messageHandler: MessageHandler | null;
1561
+ protected _status: ChannelStatusType;
1562
+ protected lastActivity: number;
1563
+ constructor();
1564
+ protected initLog(): void;
1565
+ start(config: ChannelConfig, messageHandler: MessageHandler): Promise<void>;
1566
+ stop(): Promise<void>;
1567
+ healthCheck(): Promise<ChannelHealth>;
1568
+ getStatus(): ChannelStatus;
1569
+ abstract send(message: GatewayMessage): Promise<string>;
1570
+ protected abstract doStart(): Promise<void>;
1571
+ protected abstract doStop(): Promise<void>;
1572
+ protected doHealthCheck(): Promise<boolean>;
1573
+ protected updateActivity(): void;
1574
+ protected handleMessage(message: GatewayMessage): Promise<void>;
1575
+ protected handleEvent(type: string, data?: unknown): Promise<void>;
1576
+ }
1577
+
1578
+ interface MessageRecord {
1579
+ message: GatewayMessage;
1580
+ status: MessageStatus;
1581
+ processedBy: string | null;
1582
+ processedAt: number | null;
1583
+ retryCount: number;
1584
+ error: string | null;
1585
+ createdAt: number;
1586
+ updatedAt: number;
1587
+ }
1588
+ type MessageStatus = 'pending' | 'processing' | 'completed' | 'failed' | 'cancelled';
1589
+ interface MessageStoreConfig {
1590
+ storagePath: string;
1591
+ maxRetentionDays: number;
1592
+ maxRecords: number;
1593
+ }
1594
+ declare class MessageStore {
1595
+ private log;
1596
+ private config;
1597
+ private messages;
1598
+ private sessionMessages;
1599
+ constructor(config?: Partial<MessageStoreConfig>);
1600
+ store(message: GatewayMessage): Promise<MessageRecord>;
1601
+ get(messageId: string): MessageRecord | undefined;
1602
+ updateStatus(messageId: string, status: MessageStatus, options?: {
1603
+ processedBy?: string;
1604
+ error?: string;
1605
+ }): Promise<void>;
1606
+ incrementRetry(messageId: string): number;
1607
+ isProcessed(messageId: string): boolean;
1608
+ getSessionHistory(sessionId: string, limit?: number): MessageRecord[];
1609
+ getPendingMessages(sessionId?: string): MessageRecord[];
1610
+ getFailedMessages(maxRetries?: number): MessageRecord[];
1611
+ cleanup(): Promise<number>;
1612
+ getStats(): {
1613
+ total: number;
1614
+ pending: number;
1615
+ processing: number;
1616
+ completed: number;
1617
+ failed: number;
1618
+ cancelled: number;
1619
+ };
1620
+ }
1621
+
1622
+ interface SerializableSession {
1623
+ id: string;
1624
+ channel: SessionChannelInfo;
1625
+ backendSessionId: string | null;
1626
+ subscribers: string[];
1627
+ state: SessionState;
1628
+ createdAt: number;
1629
+ lastActiveAt: number;
1630
+ }
1631
+ interface SessionStoreConfig {
1632
+ storagePath: string;
1633
+ autoSaveInterval: number;
1634
+ maxRetentionDays: number;
1635
+ enablePersistence: boolean;
1636
+ }
1637
+ declare class SessionStore {
1638
+ private log;
1639
+ private config;
1640
+ private sessions;
1641
+ private channelSessions;
1642
+ private autoSaveTimer;
1643
+ private isDirty;
1644
+ constructor(config?: Partial<SessionStoreConfig>);
1645
+ initialize(): Promise<void>;
1646
+ close(): Promise<void>;
1647
+ set(session: GatewaySession): Promise<void>;
1648
+ get(sessionId: string): GatewaySession | undefined;
1649
+ delete(sessionId: string): Promise<void>;
1650
+ getAll(): GatewaySession[];
1651
+ getByChannel(channelId: string): GatewaySession[];
1652
+ size(): number;
1653
+ private markDirty;
1654
+ save(): Promise<void>;
1655
+ load(): Promise<void>;
1656
+ private serializeAll;
1657
+ private serialize;
1658
+ private getSessionFilePath;
1659
+ private ensureStorageDir;
1660
+ private startAutoSave;
1661
+ private stopAutoSave;
1662
+ cleanup(): Promise<number>;
1663
+ getStats(): {
1664
+ total: number;
1665
+ byStatus: Record<SessionStatusType, number>;
1666
+ byPlatform: Record<string, number>;
1667
+ };
1668
+ }
1669
+
1670
+ interface PluginLoaderConfig {
1671
+ pluginDir?: string;
1672
+ autoDiscover?: boolean;
1673
+ healthCheckInterval?: number;
1674
+ healthCheckTimeout?: number;
1675
+ }
1676
+ declare class ChannelPluginLoader {
1677
+ private log;
1678
+ private plugins;
1679
+ private messageHandler;
1680
+ private healthCheckTimer;
1681
+ private config;
1682
+ constructor(config?: PluginLoaderConfig);
1683
+ setMessageHandler(handler: MessageHandler): void;
1684
+ register(plugin: ChannelPlugin, config: ChannelConfig): Promise<void>;
1685
+ unregister(pluginId: string): Promise<void>;
1686
+ start(pluginId: string): Promise<void>;
1687
+ stop(pluginId: string): Promise<void>;
1688
+ startAll(): Promise<void>;
1689
+ stopAll(): Promise<void>;
1690
+ getPlugin(pluginId: string): ChannelPlugin | undefined;
1691
+ getAllPlugins(): ChannelPlugin[];
1692
+ getRunningPlugins(): ChannelPlugin[];
1693
+ isRunning(pluginId: string): boolean;
1694
+ healthCheck(pluginId: string): Promise<ChannelHealth>;
1695
+ healthCheckAll(): Promise<Map<string, ChannelHealth>>;
1696
+ startHealthCheckTimer(): void;
1697
+ stopHealthCheckTimer(): void;
1698
+ sendToPlugin(pluginId: string, message: GatewayMessage): Promise<string>;
1699
+ }
1700
+
1701
+ declare class GatewayWebSocketServer {
1702
+ private config;
1703
+ private server;
1704
+ private wss;
1705
+ private httpsServer;
1706
+ private httpRedirectServer;
1707
+ private connections;
1708
+ private subscriptions;
1709
+ private sessionSubscriptions;
1710
+ private sessionLastActivity;
1711
+ private cleanupInterval;
1712
+ private heartbeatInterval;
1713
+ private startTime;
1714
+ private running;
1715
+ constructor(config?: Partial<GatewayServerConfig>);
1716
+ start(): Promise<void>;
1717
+ private startHTTPServer;
1718
+ private startHTTPSServer;
1719
+ private loadSSLCertificates;
1720
+ private setupWebSocketUpgrade;
1721
+ private startHTTPRedirectServer;
1722
+ stop(): Promise<void>;
1723
+ broadcastToSession(sessionId: string, event: SessionEventPayload): void;
1724
+ getConnectionCount(): number;
1725
+ getSubscriptionCount(): number;
1726
+ getConnectionInfos(): WebSocketConnectionInfo[];
1727
+ isRunning(): boolean;
1728
+ private handleConnection;
1729
+ private handleDisconnection;
1730
+ private handleMessage;
1731
+ private handleInitialize;
1732
+ private handleSubscribe;
1733
+ private handleUnsubscribe;
1734
+ private handleMessageRequest;
1735
+ private handleInterrupt;
1736
+ private handleReleaseSubscription;
1737
+ private touchSession;
1738
+ private checkConnectionTimeout;
1739
+ private cleanupExpiredSessions;
1740
+ private releaseSessionResources;
1741
+ private sendMessage;
1742
+ private sendError;
1743
+ private createRoutes;
1744
+ }
1745
+
1746
+ declare class GatewayServer implements IGatewayServer {
1747
+ private log;
1748
+ private config;
1749
+ private router;
1750
+ private sessionManager;
1751
+ private pluginLoader;
1752
+ private messageStore;
1753
+ private running;
1754
+ private connections;
1755
+ constructor(config: GatewayServerConfig$1);
1756
+ start(): Promise<void>;
1757
+ stop(): Promise<void>;
1758
+ getStatus(): {
1759
+ running: boolean;
1760
+ port?: number;
1761
+ hostname?: string;
1762
+ connections?: number;
1763
+ };
1764
+ onMessage(message: GatewayMessage): Promise<void>;
1765
+ private storeMessage;
1766
+ processMessage(sessionId: string, messageId: string, processorId: string, options?: {
1767
+ processType?: 'subagent' | 'direct' | 'tool';
1768
+ agent?: string;
1769
+ }): Promise<void>;
1770
+ completeMessage(sessionId: string, messageId: string, processorId: string, options?: {
1771
+ success?: boolean;
1772
+ error?: string;
1773
+ responseMessageId?: string;
1774
+ tokens?: number;
1775
+ duration?: number;
1776
+ }): Promise<void>;
1777
+ onEvent(event: ChannelEvent): Promise<void>;
1778
+ registerChannel(plugin: ChannelPlugin, config?: ChannelConfig): Promise<void>;
1779
+ unregisterChannel(pluginId: string): Promise<void>;
1780
+ subscribe(sessionId: string, subscriber: Subscriber): Promise<void>;
1781
+ unsubscribe(subscriptionId: string): Promise<void>;
1782
+ send(message: GatewayMessage): Promise<void>;
1783
+ sendToChannel(pluginId: string, message: GatewayMessage, options?: {
1784
+ proactive?: boolean;
1785
+ replyToMessageId?: string;
1786
+ }): Promise<string>;
1787
+ sendProactiveMessage(pluginId: string, sessionId: string, content: GatewayMessage['content'], channel: ChannelInfo): Promise<string>;
1788
+ getSessionManager(): GatewaySessionManager;
1789
+ getRouter(): MessageRouter;
1790
+ getPluginLoader(): ChannelPluginLoader;
1791
+ getMessageStore(): MessageStore;
1792
+ getMessageHistory(sessionId: string, limit?: number): Promise<MessageRecord[]>;
1793
+ }
1794
+
1795
+ interface GatewayClientConfig {
1796
+ url: string;
1797
+ type: SubscriberType;
1798
+ id?: string;
1799
+ reconnect?: {
1800
+ enabled: boolean;
1801
+ maxAttempts: number;
1802
+ delay: number;
1803
+ };
1804
+ heartbeat?: {
1805
+ enabled: boolean;
1806
+ interval: number;
1807
+ };
1808
+ }
1809
+ type MessageCallback = (message: GatewayMessage) => void | Promise<void>;
1810
+ type AgentListChangeCallback = (agents: AgentSyncInfo[]) => void | Promise<void>;
1811
+ type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting';
1812
+ interface AgentListMergeOptions {
1813
+ localAgents?: AgentSyncInfo[];
1814
+ preferLocal?: boolean;
1815
+ filterOffline?: boolean;
1816
+ }
1817
+ declare class GatewayClient {
1818
+ private log;
1819
+ private config;
1820
+ private ws;
1821
+ private state;
1822
+ private subscriptions;
1823
+ private messageCallbacks;
1824
+ private agentListCallbacks;
1825
+ private cachedAgentList;
1826
+ private localAgentList;
1827
+ private reconnectAttempts;
1828
+ private reconnectTimer;
1829
+ private heartbeatTimer;
1830
+ private agentListRequestId;
1831
+ private agentListRequestResolve;
1832
+ constructor(config: GatewayClientConfig);
1833
+ connect(): Promise<void>;
1834
+ disconnect(): Promise<void>;
1835
+ subscribe(sessionId: string): Promise<void>;
1836
+ unsubscribe(sessionId: string): Promise<void>;
1837
+ send(message: GatewayMessage): Promise<void>;
1838
+ onMessage(callback: MessageCallback): void;
1839
+ offMessage(callback: MessageCallback): void;
1840
+ getState(): ConnectionState;
1841
+ getId(): string;
1842
+ getSubscriptions(): string[];
1843
+ setLocalAgents(agents: AgentSyncInfo[]): void;
1844
+ fetchAgentList(): Promise<AgentSyncInfo[]>;
1845
+ getConnectableAgents(options?: AgentListMergeOptions): AgentSyncInfo[];
1846
+ onAgentListChange(callback: AgentListChangeCallback): void;
1847
+ offAgentListChange(callback: AgentListChangeCallback): void;
1848
+ private mergeAgentLists;
1849
+ private updateMergedAgentList;
1850
+ private handleAgentListResponse;
1851
+ private sendData;
1852
+ private handleMessage;
1853
+ private handleAgentUpdate;
1854
+ private handleGatewayMessage;
1855
+ private handleClose;
1856
+ private scheduleReconnect;
1857
+ private stopReconnect;
1858
+ private startHeartbeat;
1859
+ private stopHeartbeat;
1860
+ private resubscribeAll;
1861
+ }
1862
+
1863
+ interface TelegramBotConfig {
1864
+ botToken: string;
1865
+ webhook?: {
1866
+ enabled: boolean;
1867
+ url: string;
1868
+ port?: number;
1869
+ };
1870
+ polling?: {
1871
+ enabled: boolean;
1872
+ interval?: number;
1873
+ };
1874
+ }
1875
+ declare class TelegramPlugin extends BaseChannelPlugin {
1876
+ readonly id: string;
1877
+ readonly platform: "telegram";
1878
+ readonly name = "Telegram Bot";
1879
+ private botConfig;
1880
+ private pollingInterval;
1881
+ private lastUpdateId;
1882
+ private baseUrl;
1883
+ constructor(id?: string);
1884
+ protected doStart(): Promise<void>;
1885
+ protected doStop(): Promise<void>;
1886
+ send(message: GatewayMessage): Promise<string>;
1887
+ private startPolling;
1888
+ private stopPolling;
1889
+ private poll;
1890
+ private handleTelegramMessage;
1891
+ private toGatewayMessage;
1892
+ private parseContent;
1893
+ private getSessionId;
1894
+ private extractText;
1895
+ private getMe;
1896
+ private getUpdates;
1897
+ private sendMessage;
1898
+ private request;
1899
+ }
1900
+
1901
+ interface DiscordBotConfig {
1902
+ botToken: string;
1903
+ applicationId?: string;
1904
+ gateway?: {
1905
+ enabled: boolean;
1906
+ intents: number[];
1907
+ };
1908
+ webhook?: {
1909
+ enabled: boolean;
1910
+ path: string;
1911
+ port?: number;
1912
+ };
1913
+ }
1914
+ declare class DiscordPlugin extends BaseChannelPlugin {
1915
+ readonly id: string;
1916
+ readonly platform: "discord";
1917
+ readonly name = "Discord Bot";
1918
+ private botConfig;
1919
+ private baseUrl;
1920
+ private gatewayWs;
1921
+ private heartbeatInterval;
1922
+ private sessionId;
1923
+ private sequenceNumber;
1924
+ constructor(id?: string);
1925
+ protected doStart(): Promise<void>;
1926
+ protected doStop(): Promise<void>;
1927
+ send(message: GatewayMessage): Promise<string>;
1928
+ private startGateway;
1929
+ private handleGatewayMessage;
1930
+ private handleHello;
1931
+ private handleDispatch;
1932
+ private handleDiscordMessage;
1933
+ private toGatewayMessage;
1934
+ private parseContent;
1935
+ private getSessionId;
1936
+ private extractText;
1937
+ private getCurrentUser;
1938
+ private getGatewayBot;
1939
+ private createMessage;
1940
+ private request;
1941
+ }
1942
+
1943
+ interface SlackBotConfig {
1944
+ botToken: string;
1945
+ appToken?: string;
1946
+ signingSecret?: string;
1947
+ socketMode?: boolean;
1948
+ webhook?: {
1949
+ enabled: boolean;
1950
+ path: string;
1951
+ port?: number;
1952
+ };
1953
+ }
1954
+ declare class SlackPlugin extends BaseChannelPlugin {
1955
+ readonly id: string;
1956
+ readonly platform: "slack";
1957
+ readonly name = "Slack Bot";
1958
+ private botConfig;
1959
+ private baseUrl;
1960
+ private socketModeClient;
1961
+ constructor(id?: string);
1962
+ protected doStart(): Promise<void>;
1963
+ protected doStop(): Promise<void>;
1964
+ send(message: GatewayMessage): Promise<string>;
1965
+ private startSocketMode;
1966
+ private handleSocketModeEvent;
1967
+ private handleSlackMessage;
1968
+ private toGatewayMessage;
1969
+ private parseContent;
1970
+ private getSessionId;
1971
+ private extractText;
1972
+ private authTest;
1973
+ private postMessage;
1974
+ private request;
1975
+ }
1976
+
1977
+ interface FeishuBotConfig {
1978
+ appId: string;
1979
+ appSecret: string;
1980
+ encryptKey?: string;
1981
+ verificationToken?: string;
1982
+ webhook?: {
1983
+ enabled: boolean;
1984
+ path: string;
1985
+ port?: number;
1986
+ };
1987
+ }
1988
+ interface FeishuMessageEvent {
1989
+ type: string;
1990
+ app_id: string;
1991
+ tenant_key: string;
1992
+ event: {
1993
+ type: string;
1994
+ message: {
1995
+ message_id: string;
1996
+ root_id?: string;
1997
+ parent_id?: string;
1998
+ chat_id: string;
1999
+ message_type: string;
2000
+ content: string;
2001
+ create_time: string;
2002
+ sender: {
2003
+ sender_id: {
2004
+ open_id: string;
2005
+ union_id: string;
2006
+ user_id: string;
2007
+ };
2008
+ sender_type: string;
2009
+ tenant_key: string;
2010
+ };
2011
+ };
2012
+ };
2013
+ }
2014
+ declare class FeishuPlugin extends BaseChannelPlugin {
2015
+ readonly id: string;
2016
+ readonly platform: "feishu";
2017
+ readonly name = "Feishu Bot";
2018
+ private botConfig;
2019
+ private baseUrl;
2020
+ private tenantAccessToken;
2021
+ private tokenExpireTime;
2022
+ constructor(id?: string);
2023
+ protected doStart(): Promise<void>;
2024
+ protected doStop(): Promise<void>;
2025
+ send(message: GatewayMessage): Promise<string>;
2026
+ handleWebhookEvent(event: FeishuMessageEvent): Promise<void>;
2027
+ private toGatewayMessage;
2028
+ private parseContent;
2029
+ private extractPostContent;
2030
+ private getSessionId;
2031
+ private extractText;
2032
+ private refreshTenantAccessToken;
2033
+ private ensureTokenValid;
2034
+ private sendMessage;
2035
+ }
2036
+
2037
+ interface WeChatBotConfig {
2038
+ mode: 'official' | 'wecom';
2039
+ appId: string;
2040
+ appSecret: string;
2041
+ token?: string;
2042
+ encodingAESKey?: string;
2043
+ agentId?: string;
2044
+ webhook?: {
2045
+ enabled: boolean;
2046
+ path: string;
2047
+ port?: number;
2048
+ };
2049
+ }
2050
+ declare class WeChatPlugin extends BaseChannelPlugin {
2051
+ readonly id: string;
2052
+ readonly platform: "wechat";
2053
+ readonly name = "WeChat Bot";
2054
+ private botConfig;
2055
+ private accessToken;
2056
+ private tokenExpireTime;
2057
+ constructor(id?: string);
2058
+ protected doStart(): Promise<void>;
2059
+ protected doStop(): Promise<void>;
2060
+ send(message: GatewayMessage): Promise<string>;
2061
+ handleWebhookMessage(xmlData: string): Promise<void>;
2062
+ private parseXmlMessage;
2063
+ private toGatewayMessage;
2064
+ private parseContent;
2065
+ private getSessionId;
2066
+ private extractText;
2067
+ private refreshAccessToken;
2068
+ private ensureTokenValid;
2069
+ private sendOfficialMessage;
2070
+ private sendWeComMessage;
2071
+ }
2072
+
2073
+ interface WebChatConfig {
2074
+ port: number;
2075
+ hostname: string;
2076
+ path: string;
2077
+ heartbeatInterval: number;
2078
+ connectionTimeout: number;
2079
+ sessionExpireMs: number;
2080
+ maxConnections: number;
2081
+ cors: boolean;
2082
+ https?: HTTPSConfig;
2083
+ }
2084
+ declare class WebChatPlugin extends BaseChannelPlugin {
2085
+ readonly id: string;
2086
+ readonly platform: "webchat";
2087
+ readonly name = "WebChat";
2088
+ private webChatConfig;
2089
+ private connections;
2090
+ private heartbeatInterval;
2091
+ private wsServer;
2092
+ constructor(id?: string);
2093
+ protected doStart(): Promise<void>;
2094
+ private startWebSocketServer;
2095
+ protected doStop(): Promise<void>;
2096
+ send(message: GatewayMessage): Promise<string>;
2097
+ pushEvent(sessionId: string, event: SessionEventPayload): void;
2098
+ getWebSocketServer(): GatewayWebSocketServer | null;
2099
+ handleConnection(ws: WebSocket, userId: string): Promise<void>;
2100
+ private handleWebSocketMessage;
2101
+ private handleChatMessage;
2102
+ private startHeartbeat;
2103
+ private findConnectionByUser;
2104
+ private generateConnectionId;
2105
+ getConnectionCount(): number;
2106
+ getWsServerConnectionCount(): number;
2107
+ }
2108
+
2109
+ interface SignalBotConfig {
2110
+ serviceUrl: string;
2111
+ phoneNumber: string;
2112
+ password?: string;
2113
+ webhook?: {
2114
+ enabled: boolean;
2115
+ path: string;
2116
+ port?: number;
2117
+ };
2118
+ }
2119
+ declare class SignalPlugin extends BaseChannelPlugin {
2120
+ readonly id: string;
2121
+ readonly platform: "signal";
2122
+ readonly name = "Signal Bot";
2123
+ private botConfig;
2124
+ private pollingInterval;
2125
+ private lastTimestamp;
2126
+ constructor(id?: string);
2127
+ protected doStart(): Promise<void>;
2128
+ protected doStop(): Promise<void>;
2129
+ send(message: GatewayMessage): Promise<string>;
2130
+ private startPolling;
2131
+ private poll;
2132
+ private handleSignalMessage;
2133
+ private toGatewayMessage;
2134
+ private parseContent;
2135
+ private getSessionId;
2136
+ private extractText;
2137
+ private getAccountInfo;
2138
+ private receiveMessages;
2139
+ private sendMessage;
2140
+ private request;
2141
+ }
2142
+
2143
+ interface NostrBotConfig {
2144
+ relays: string[];
2145
+ privateKey?: string;
2146
+ publicKey?: string;
2147
+ timeout: number;
2148
+ }
2149
+ declare class NostrPlugin extends BaseChannelPlugin {
2150
+ readonly id: string;
2151
+ readonly platform: "nostr";
2152
+ readonly name = "Nostr Bot";
2153
+ private botConfig;
2154
+ private relayConnections;
2155
+ private subscriptions;
2156
+ private eventHandlers;
2157
+ constructor(id?: string);
2158
+ protected doStart(): Promise<void>;
2159
+ protected doStop(): Promise<void>;
2160
+ send(message: GatewayMessage): Promise<string>;
2161
+ private connectToRelay;
2162
+ private handleRelayMessage;
2163
+ private handleNostrEvent;
2164
+ private toGatewayMessage;
2165
+ private parseContent;
2166
+ private findReplyTo;
2167
+ private getSessionId;
2168
+ private extractText;
2169
+ private subscribeToRelay;
2170
+ private createEvent;
2171
+ private computeEventId;
2172
+ private signEvent;
2173
+ private publishEvent;
2174
+ }
2175
+
2176
+ interface ChannelSetupAdapter {
2177
+ initialize?: () => Promise<void>;
2178
+ destroy?: () => Promise<void>;
2179
+ }
2180
+ interface ChannelMessagingAdapter {
2181
+ send: (message: GatewayMessage) => Promise<string>;
2182
+ transformMessage?: (message: unknown) => Promise<GatewayMessage | null>;
2183
+ }
2184
+ interface ChannelStatusAdapter<TConfig = unknown, TProbe = unknown> {
2185
+ healthCheck?: () => Promise<boolean>;
2186
+ getStatus?: () => Promise<{
2187
+ healthy: boolean;
2188
+ connections?: number;
2189
+ messages?: number;
2190
+ errors?: number;
2191
+ metadata?: Record<string, unknown>;
2192
+ }>;
2193
+ getConfig?: () => TConfig;
2194
+ probe?: () => Promise<TProbe>;
2195
+ }
2196
+ interface ChannelDirectoryAdapter {
2197
+ listSessions?: () => Promise<Array<{
2198
+ sessionId: string;
2199
+ userId?: string;
2200
+ createdAt: number;
2201
+ lastActivityAt: number;
2202
+ }>>;
2203
+ getSession?: (sessionId: string) => Promise<{
2204
+ sessionId: string;
2205
+ userId?: string;
2206
+ createdAt: number;
2207
+ lastActivityAt: number;
2208
+ } | null>;
2209
+ }
2210
+ interface ChannelMessageActionAdapter {
2211
+ beforeSend?: (message: GatewayMessage) => Promise<GatewayMessage>;
2212
+ afterSend?: (message: GatewayMessage, result: string) => Promise<void>;
2213
+ beforeReceive?: (message: GatewayMessage) => Promise<GatewayMessage>;
2214
+ afterReceive?: (message: GatewayMessage) => Promise<void>;
2215
+ }
2216
+ interface ChannelBindingsAdapter {
2217
+ bindUser?: (userId: string, sessionId: string) => Promise<void>;
2218
+ unbindUser?: (userId: string) => Promise<void>;
2219
+ getUserSession?: (userId: string) => Promise<string | null>;
2220
+ }
2221
+ interface CreateChannelPluginOptions<TConfig = unknown, TProbe = unknown> {
2222
+ id: string;
2223
+ platform: PlatformType | string;
2224
+ name: string;
2225
+ version?: string;
2226
+ setup?: ChannelSetupAdapter;
2227
+ messaging: ChannelMessagingAdapter;
2228
+ status?: ChannelStatusAdapter<TConfig, TProbe>;
2229
+ directory?: ChannelDirectoryAdapter;
2230
+ actions?: ChannelMessageActionAdapter;
2231
+ bindings?: ChannelBindingsAdapter;
2232
+ }
2233
+ declare function createChannelPlugin<TConfig = unknown, TProbe = unknown>(options: CreateChannelPluginOptions<TConfig, TProbe>): BaseChannelPlugin;
2234
+
2235
+ declare const ChannelPluginRegistry: Record<string, new (id?: string) => ChannelPlugin>;
2236
+ declare function getSupportedPlatforms(): string[];
2237
+
2238
+ export { type AgentDeregisterMessage, type AgentHealthStatus, type AgentHeartbeat, type AgentHeartbeatSyncMessage, type AgentListRequestMessage, type AgentListResponseMessage, type AgentRegisterMessage, type AgentRegistration, type AgentRegistrationRequest, AgentRegistry, type AgentRegistryConfig, AgentRegistryConfigSchema, type AgentRegistryStats, type AgentSelectionOptions, type AgentSelectionRecord, type AgentSelectionStrategy, type AgentStatusChangeMessage, type AgentSyncConfig, AgentSyncConfigSchema, type AgentSyncInfo, AgentSyncManager, type AuthConfig, AuthConfigSchema, type AuthResult, BaseChannelPlugin, type CancelEvent, type CancelEventHandler, type ChannelConfig, ChannelConfigSchema, type ChannelEvent, type ChannelEventType, type ChannelHealth, type ChannelPlugin, ChannelPluginLoader, ChannelPluginRegistry, type SessionConfig as ChannelSessionConfig, type ChannelStatus, type ChannelStatusType, type ChannelType, type CircuitBreakerConfig, CircuitBreakerConfigSchema, type ConnectionState as ClientConnectionState, type ClientInitializeMessage, type ClientInterruptMessage, type ClientMessage, type ClientMessageMessage, type ClientMessageType, type ClientPingMessage, type ClientReleaseSubscriptionMessage, type ClientSubscribeMessage, type ClientSubscription, type ClientUnsubscribeMessage, type ConflictResolutionStrategy, type ConnectionCloser, type ConnectionFactory, type ConnectionHealthChecker, type ConnectionPoolConfig, ConnectionPoolConfigSchema, type ConnectionPoolEvent, type ConnectionPoolEventCallback, type ConnectionPoolEventType, type ConnectionPoolStats, type ConnectionState$1 as ConnectionState, type CreateSessionRequest, type CreateSessionResponse, DEFAULT_AGENT_REGISTRY_CONFIG, DEFAULT_CONNECTION_POOL_CONFIG, DEFAULT_SYNC_CONFIG, DEFAULT_TOKEN_AUTH_CONFIG, DEFAULT_WEBSOCKET_SERVER_CONFIG, type DiscordBotConfig, DiscordPlugin, type FeishuBotConfig, type FeishuChannelConfig, FeishuChannelConfigSchema, FeishuPlugin, Gateway, GatewayClient, type GatewayClientConfig, type GatewayClusterConfig, GatewayClusterConfigSchema, type GatewayConfig, GatewayConfigSchema, type GatewayNodeConfig, type GatewayNodeInfo, GatewayServer, type GatewayServerConfig, GatewayServerConfigSchema, type GatewaySession, GatewaySessionManager, type HTTPSConfig, HTTPSConfigSchema, type HealthCheckResponse, type IAuthProvider, type MessageCallback, type MessageHandler, MessageLockManager, type MessagePriority, type MessageQueueConfig, MessageQueueConfigSchema, type MessageRecord, MessageRetryManager, MessageRouter, type MessageStatus, MessageStore, type MessageStoreConfig, type NostrBotConfig, type NostrChannelConfig, NostrChannelConfigSchema, NostrPlugin, type OAuth2AuthConfig, type PluginLoaderConfig, type PooledConnection, type PushEventType, type RouteResult, type RoutingConfig, type SendMessageRequest, type SendMessageResponse, type SerializableSession, type ServerConnectedMessage, type ServerErrorMessage, type ServerEventMessage, type ServerInitializeResponseMessage, type ServerInterruptedMessage, type ServerMessage, type ServerMessageType, type ServerPongMessage, type ServerResponseMessage, type ServerSessionClosedMessage, type ServerStatusResponse, type ServerSubscribedMessage, type ServerSubscriptionReleasedMessage, type ServerUnsubscribedMessage, type SessionChannelInfo, type SessionConfig$1 as SessionConfig, SessionConfigSchema, type SessionContext, type SessionEventPayload, type SessionEventType, type SessionFilter, type SessionManagerConfig, type SessionResetPolicy, type SessionState, type SessionStatusType, SessionStore, type SessionStoreConfig, type SignalBotConfig, type SignalChannelConfig, SignalChannelConfigSchema, SignalPlugin, type SlackBotConfig, type SlackChannelConfig, SlackChannelConfigSchema, SlackPlugin, type Subscriber, type SubscriberConnection, type SubscriberType, type Subscription, type SubscriptionOptions, type SubscriptionsResponse, type SyncConfig, type SyncMessage, type SyncMode, type SyncState, type SyncStats, type TelegramBotConfig, type TelegramChannelConfig, TelegramChannelConfigSchema, TelegramPlugin, type TokenAuthConfig, type TokenAuthItem, type TokenConfig, type WeChatBotConfig, type WeChatChannelConfig, WeChatChannelConfigSchema, WeChatPlugin, type WebChatChannelConfig, WebChatChannelConfigSchema, type WebChatConfig, WebChatPlugin, type WebSocketConnectionInfo, type WebSocketConnectionState, type WebSocketMessage, type WebSocketMessageBase, clearConfigCache, createChannelPlugin, createDefaultSessionState, createGatewayMessage, createTextMessage, generateSessionId, generateSubscriptionId, getAgentRegistryConfig, getAuthConfig, getChannelConfig, getCircuitBreakerConfig, getClusterConfig, getConfig, getConfigDirectory, getConnectionPoolConfig, getDefaultAgent, getHTTPSConfig, getLogLevel, getMessageQueueConfig, getServerConfig, getSessionConfig, getSupportedPlatforms, isConfigLoaded, loadConfig, parsePartialConfig, validateConfig };