@easbot/gateway 0.2.41 → 0.2.43
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/chunks/chunk-MURSGSGX.mjs +30 -0
- package/dist/chunks/chunk-OKAA7SZE.cjs +30 -0
- package/dist/chunks/server-3EDAJA5R.mjs +1 -0
- package/dist/chunks/server-IEPHSA6A.cjs +1 -0
- package/dist/index.cjs +1 -2
- package/dist/index.d.cts +420 -243
- package/dist/index.d.ts +420 -243
- package/dist/index.mjs +1 -2
- package/package.json +5 -5
- package/dist/chunks/chunk-OBFSXYWV.mjs +0 -30
- package/dist/chunks/chunk-RFOEJ3A2.cjs +0 -30
- package/dist/chunks/server-3QASQ56E.cjs +0 -1
- package/dist/chunks/server-54GY5XXD.mjs +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { IGatewayServer, GatewayConfig as GatewayConfig$1, GatewayServerConfig as GatewayServerConfig$1, GatewayMessageReceiveInput, GatewayMessage, GatewayMessagePromptPart, PlatformType, SubAgentConfig, ChannelInfo,
|
|
2
|
-
export { AgentAdapter, AgentInfo, ChannelInfo, GatewayMessage, GatewayMessagePromptPart, IGatewayServer, IGlobal, IHookRegistry, IInstance, ISubAgentRunner, MessageContext, MessageMetadata, MessageStorage, MessageType, PlatformType } from '@easbot/types';
|
|
3
|
-
import z from 'zod';
|
|
1
|
+
import { IGatewayServer, GatewayConfig as GatewayConfig$1, GatewayServerConfig as GatewayServerConfig$1, GatewayMessageReceiveInput, GatewayMessage, GatewayMessagePromptPart, PlatformType, SubAgentConfig, ChannelInfo, AgentPromptPart, AgentAdapter } from '@easbot/types';
|
|
2
|
+
export { AgentAdapter, AgentInfo, ChannelInfo, ChannelListResponse, GatewayMessage, GatewayMessagePromptPart, IGatewayServer, IGlobal, IHookRegistry, IInstance, ISubAgentRunner, MessageContext, MessageMetadata, MessageStorage, MessageType, PlatformType } from '@easbot/types';
|
|
3
|
+
import z, { z as z$1 } from 'zod';
|
|
4
4
|
import { WSContext } from '@easbot/utils';
|
|
5
|
+
import { Command, EasbotClient } from '@easbot/sdk';
|
|
5
6
|
|
|
6
7
|
declare namespace Gateway {
|
|
7
8
|
export interface BootstrapConfig {
|
|
@@ -441,6 +442,14 @@ declare const GatewayServerConfigSchema: z.ZodObject<{
|
|
|
441
442
|
mdnsDomain: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
442
443
|
}, z.core.$strip>;
|
|
443
444
|
type GatewayServerConfig = z.infer<typeof GatewayServerConfigSchema>;
|
|
445
|
+
declare const GatewayClientConfigSchema: z.ZodObject<{
|
|
446
|
+
autoRegister: z.ZodDefault<z.ZodBoolean>;
|
|
447
|
+
heartbeatInterval: z.ZodDefault<z.ZodNumber>;
|
|
448
|
+
maxReconnectAttempts: z.ZodDefault<z.ZodNumber>;
|
|
449
|
+
reconnectDelay: z.ZodDefault<z.ZodNumber>;
|
|
450
|
+
heartbeatTimeout: z.ZodDefault<z.ZodNumber>;
|
|
451
|
+
}, z.core.$strip>;
|
|
452
|
+
type GatewayClientConfig = z.infer<typeof GatewayClientConfigSchema>;
|
|
444
453
|
declare const GatewayConfigSchema: z.ZodObject<{
|
|
445
454
|
server: z.ZodOptional<z.ZodObject<{
|
|
446
455
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
@@ -662,6 +671,13 @@ declare const GatewayConfigSchema: z.ZodObject<{
|
|
|
662
671
|
timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
663
672
|
retryOnFailure: z.ZodDefault<z.ZodBoolean>;
|
|
664
673
|
}, z.core.$strip>>;
|
|
674
|
+
client: z.ZodOptional<z.ZodObject<{
|
|
675
|
+
autoRegister: z.ZodDefault<z.ZodBoolean>;
|
|
676
|
+
heartbeatInterval: z.ZodDefault<z.ZodNumber>;
|
|
677
|
+
maxReconnectAttempts: z.ZodDefault<z.ZodNumber>;
|
|
678
|
+
reconnectDelay: z.ZodDefault<z.ZodNumber>;
|
|
679
|
+
heartbeatTimeout: z.ZodDefault<z.ZodNumber>;
|
|
680
|
+
}, z.core.$strip>>;
|
|
665
681
|
defaultAgent: z.ZodOptional<z.ZodString>;
|
|
666
682
|
logLevel: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
667
683
|
DEBUG: "DEBUG";
|
|
@@ -686,6 +702,8 @@ declare function getMessageQueueConfig(): Promise<MessageQueueConfig>;
|
|
|
686
702
|
declare function getCircuitBreakerConfig(): Promise<CircuitBreakerConfig>;
|
|
687
703
|
declare function getAgentRegistryConfig(): Promise<AgentRegistryConfig>;
|
|
688
704
|
declare function getSessionConfig(): Promise<SessionConfig$1>;
|
|
705
|
+
declare function getGatewayClientConfig(): Promise<GatewayClientConfig | undefined>;
|
|
706
|
+
declare function getGatewayClientUrl(): Promise<string | undefined>;
|
|
689
707
|
declare function getHTTPSConfig(): Promise<HTTPSConfig | undefined>;
|
|
690
708
|
declare function getAuthConfig(): Promise<AuthConfig | undefined>;
|
|
691
709
|
declare function getClusterConfig(): Promise<GatewayConfig['cluster'] | undefined>;
|
|
@@ -770,9 +788,16 @@ interface ChannelPlugin {
|
|
|
770
788
|
getStatus(): ChannelStatus;
|
|
771
789
|
getCapabilities(): ChannelCapabilities;
|
|
772
790
|
}
|
|
791
|
+
interface SessionOperations {
|
|
792
|
+
getSession(sessionId: string): {
|
|
793
|
+
backendSessionId: string | null;
|
|
794
|
+
} | undefined;
|
|
795
|
+
unbindBackendSession(gatewaySessionId: string): Promise<void>;
|
|
796
|
+
}
|
|
773
797
|
interface MessageHandler {
|
|
774
798
|
onMessage(message: GatewayMessage): Promise<void>;
|
|
775
799
|
onEvent(event: ChannelEvent): Promise<void>;
|
|
800
|
+
session?: SessionOperations;
|
|
776
801
|
}
|
|
777
802
|
interface ChannelHealth {
|
|
778
803
|
healthy: boolean;
|
|
@@ -884,11 +909,10 @@ interface Subscriber {
|
|
|
884
909
|
id: string;
|
|
885
910
|
type: SubscriberType;
|
|
886
911
|
connection: SubscriberConnection;
|
|
887
|
-
sessions: Set<string>;
|
|
888
912
|
createdAt: number;
|
|
889
913
|
lastActiveAt: number;
|
|
890
914
|
}
|
|
891
|
-
type SubscriberType = 'subagent' | 'tui' | 'desktop' | 'browser' | 'mobile' | 'api';
|
|
915
|
+
type SubscriberType = 'subagent' | 'tui' | 'desktop' | 'browser' | 'mobile' | 'api' | 'acp';
|
|
892
916
|
interface SubscriberConnection {
|
|
893
917
|
send(message: GatewayMessage): Promise<void>;
|
|
894
918
|
close(): Promise<void>;
|
|
@@ -916,24 +940,17 @@ interface RouteResult {
|
|
|
916
940
|
declare function generateSubscriptionId(subscriberId: string, sessionId: string): string;
|
|
917
941
|
|
|
918
942
|
declare const DEFAULT_WEBSOCKET_SERVER_CONFIG: GatewayServerConfig;
|
|
919
|
-
type ClientMessageType = '
|
|
920
|
-
type ServerMessageType = 'connected' | '
|
|
943
|
+
type ClientMessageType = 'subscribe' | 'unsubscribe' | 'message' | 'ping' | 'interrupt' | 'releaseSubscription' | 'agent_list_request' | 'agent_subscribe' | 'agent_register' | 'agent_deregister';
|
|
944
|
+
type ServerMessageType = 'connected' | 'subscribed' | 'unsubscribed' | 'event' | 'response' | 'error' | 'pong' | 'interrupted' | 'subscriptionReleased' | 'agent_list_response' | 'agent_update';
|
|
921
945
|
interface WebSocketMessageBase {
|
|
922
946
|
type: ClientMessageType | ServerMessageType;
|
|
923
947
|
sessionId?: string;
|
|
924
948
|
}
|
|
925
|
-
interface ClientInitializeMessage extends WebSocketMessageBase {
|
|
926
|
-
type: 'initialize';
|
|
927
|
-
payload?: {
|
|
928
|
-
name?: string;
|
|
929
|
-
version?: string;
|
|
930
|
-
capabilities?: string[];
|
|
931
|
-
};
|
|
932
|
-
}
|
|
933
949
|
interface ClientSubscribeMessage extends WebSocketMessageBase {
|
|
934
950
|
type: 'subscribe';
|
|
935
951
|
sessionId: string;
|
|
936
952
|
backendSessionId?: string;
|
|
953
|
+
clientId?: string;
|
|
937
954
|
payload?: {
|
|
938
955
|
eventTypes?: string[];
|
|
939
956
|
};
|
|
@@ -975,8 +992,25 @@ interface ClientAgentListRequestMessage extends WebSocketMessageBase {
|
|
|
975
992
|
interface ClientAgentSubscribeMessage extends WebSocketMessageBase {
|
|
976
993
|
type: 'agent_subscribe';
|
|
977
994
|
subscribe: boolean;
|
|
995
|
+
clientId?: string;
|
|
978
996
|
}
|
|
979
|
-
|
|
997
|
+
interface ClientAgentRegisterMessage extends WebSocketMessageBase {
|
|
998
|
+
type: 'agent_register';
|
|
999
|
+
payload: {
|
|
1000
|
+
agentId: string;
|
|
1001
|
+
name: string;
|
|
1002
|
+
address: string;
|
|
1003
|
+
capabilities?: string[];
|
|
1004
|
+
metadata?: Record<string, unknown>;
|
|
1005
|
+
};
|
|
1006
|
+
}
|
|
1007
|
+
interface ClientAgentDeregisterMessage extends WebSocketMessageBase {
|
|
1008
|
+
type: 'agent_deregister';
|
|
1009
|
+
payload: {
|
|
1010
|
+
agentId: string;
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
type ClientMessage = ClientSubscribeMessage | ClientUnsubscribeMessage | ClientMessageMessage | ClientPingMessage | ClientInterruptMessage | ClientReleaseSubscriptionMessage | ClientAgentListRequestMessage | ClientAgentSubscribeMessage | ClientAgentRegisterMessage | ClientAgentDeregisterMessage;
|
|
980
1014
|
interface ServerConnectedMessage extends WebSocketMessageBase {
|
|
981
1015
|
type: 'connected';
|
|
982
1016
|
clientId: string;
|
|
@@ -985,16 +1019,6 @@ interface ServerConnectedMessage extends WebSocketMessageBase {
|
|
|
985
1019
|
capabilities?: string[];
|
|
986
1020
|
};
|
|
987
1021
|
}
|
|
988
|
-
interface ServerInitializeResponseMessage extends WebSocketMessageBase {
|
|
989
|
-
type: 'initialize_response';
|
|
990
|
-
success: boolean;
|
|
991
|
-
result?: {
|
|
992
|
-
sessionId?: string;
|
|
993
|
-
capabilities?: string[];
|
|
994
|
-
[key: string]: unknown;
|
|
995
|
-
};
|
|
996
|
-
error?: string;
|
|
997
|
-
}
|
|
998
1022
|
interface ServerSubscribedMessage extends WebSocketMessageBase {
|
|
999
1023
|
type: 'subscribed';
|
|
1000
1024
|
sessionId: string;
|
|
@@ -1033,13 +1057,6 @@ interface ServerInterruptedMessage extends WebSocketMessageBase {
|
|
|
1033
1057
|
success: boolean;
|
|
1034
1058
|
error?: string;
|
|
1035
1059
|
}
|
|
1036
|
-
interface ServerSessionClosedMessage extends WebSocketMessageBase {
|
|
1037
|
-
type: 'session_closed';
|
|
1038
|
-
sessionId: string;
|
|
1039
|
-
payload?: {
|
|
1040
|
-
reason?: string;
|
|
1041
|
-
};
|
|
1042
|
-
}
|
|
1043
1060
|
interface ServerSubscriptionReleasedMessage extends WebSocketMessageBase {
|
|
1044
1061
|
type: 'subscriptionReleased';
|
|
1045
1062
|
sessionId: string;
|
|
@@ -1072,7 +1089,29 @@ interface ServerAgentUpdateMessage extends WebSocketMessageBase {
|
|
|
1072
1089
|
metadata?: Record<string, unknown>;
|
|
1073
1090
|
};
|
|
1074
1091
|
}
|
|
1075
|
-
|
|
1092
|
+
interface ServerMessagePushMessage extends WebSocketMessageBase {
|
|
1093
|
+
type: 'message';
|
|
1094
|
+
sessionId: string;
|
|
1095
|
+
payload: {
|
|
1096
|
+
id: string;
|
|
1097
|
+
type: 'input' | 'output' | 'system' | 'control';
|
|
1098
|
+
content: AgentPromptPart[];
|
|
1099
|
+
metadata?: {
|
|
1100
|
+
channel?: {
|
|
1101
|
+
platform: string;
|
|
1102
|
+
channelId?: string;
|
|
1103
|
+
userId?: string;
|
|
1104
|
+
chatId?: string;
|
|
1105
|
+
};
|
|
1106
|
+
processorId?: string;
|
|
1107
|
+
proactive?: boolean;
|
|
1108
|
+
replyToMessageId?: string;
|
|
1109
|
+
};
|
|
1110
|
+
timestamp: number;
|
|
1111
|
+
[key: string]: unknown;
|
|
1112
|
+
};
|
|
1113
|
+
}
|
|
1114
|
+
type ServerMessage = ServerConnectedMessage | ServerSubscribedMessage | ServerUnsubscribedMessage | ServerEventMessage | ServerResponseMessage | ServerErrorMessage | ServerPongMessage | ServerInterruptedMessage | ServerSubscriptionReleasedMessage | ServerAgentListResponseMessage | ServerAgentUpdateMessage | ServerMessagePushMessage;
|
|
1076
1115
|
type WebSocketMessage = ClientMessage | ServerMessage;
|
|
1077
1116
|
interface ClientSubscription {
|
|
1078
1117
|
clientId: string;
|
|
@@ -1095,9 +1134,9 @@ interface WebSocketConnectionInfo {
|
|
|
1095
1134
|
remoteAddress?: string;
|
|
1096
1135
|
authInfo?: ClientSubscription['authInfo'];
|
|
1097
1136
|
}
|
|
1098
|
-
type SessionEventType = 'message' | 'thinking' | 'tool_use' | 'tool_result' | 'error' | 'complete' | 'interrupted' | 'status_change';
|
|
1137
|
+
type SessionEventType$1 = 'message' | 'thinking' | 'tool_use' | 'tool_result' | 'error' | 'complete' | 'interrupted' | 'status_change';
|
|
1099
1138
|
interface SessionEventPayload {
|
|
1100
|
-
type: SessionEventType | string;
|
|
1139
|
+
type: SessionEventType$1 | string;
|
|
1101
1140
|
sessionId: string;
|
|
1102
1141
|
properties: {
|
|
1103
1142
|
[key: string]: unknown;
|
|
@@ -1112,9 +1151,21 @@ interface ServerStatusResponse {
|
|
|
1112
1151
|
status: 'running' | 'stopping' | 'stopped';
|
|
1113
1152
|
connections: number;
|
|
1114
1153
|
sessions: number;
|
|
1115
|
-
|
|
1154
|
+
messageSubscriptions: number;
|
|
1155
|
+
agentSubscriptions: number;
|
|
1116
1156
|
uptime: number;
|
|
1117
1157
|
version?: string;
|
|
1158
|
+
agents?: {
|
|
1159
|
+
total: number;
|
|
1160
|
+
healthy: number;
|
|
1161
|
+
unhealthy: number;
|
|
1162
|
+
};
|
|
1163
|
+
channels?: Array<{
|
|
1164
|
+
id: string;
|
|
1165
|
+
platform: string;
|
|
1166
|
+
name: string;
|
|
1167
|
+
version?: string;
|
|
1168
|
+
}>;
|
|
1118
1169
|
}
|
|
1119
1170
|
interface CreateSessionRequest {
|
|
1120
1171
|
title?: string;
|
|
@@ -1126,7 +1177,7 @@ interface CreateSessionRequest {
|
|
|
1126
1177
|
};
|
|
1127
1178
|
context?: Record<string, unknown>;
|
|
1128
1179
|
}
|
|
1129
|
-
interface CreateSessionResponse
|
|
1180
|
+
interface CreateSessionResponse {
|
|
1130
1181
|
id: string;
|
|
1131
1182
|
createdAt: number;
|
|
1132
1183
|
}
|
|
@@ -1141,7 +1192,7 @@ interface SendMessageRequest {
|
|
|
1141
1192
|
}>;
|
|
1142
1193
|
[key: string]: unknown;
|
|
1143
1194
|
}
|
|
1144
|
-
interface SendMessageResponse
|
|
1195
|
+
interface SendMessageResponse {
|
|
1145
1196
|
messageId: string;
|
|
1146
1197
|
sessionId: string;
|
|
1147
1198
|
createdAt: number;
|
|
@@ -1151,11 +1202,16 @@ interface SendMessageResponse$1 {
|
|
|
1151
1202
|
channelInfo?: ChannelInfo;
|
|
1152
1203
|
};
|
|
1153
1204
|
}
|
|
1205
|
+
type SubscriptionType = 'message' | 'agent';
|
|
1154
1206
|
interface SubscriptionsResponse {
|
|
1155
1207
|
subscriptions: Array<{
|
|
1208
|
+
type: SubscriptionType;
|
|
1156
1209
|
sessionId: string;
|
|
1157
1210
|
subscriberCount: number;
|
|
1158
|
-
subscribers:
|
|
1211
|
+
subscribers: Array<{
|
|
1212
|
+
id: string;
|
|
1213
|
+
subscriptionId: string;
|
|
1214
|
+
}>;
|
|
1159
1215
|
}>;
|
|
1160
1216
|
total: number;
|
|
1161
1217
|
}
|
|
@@ -1203,10 +1259,10 @@ interface AgentRegistration {
|
|
|
1203
1259
|
}
|
|
1204
1260
|
type AgentRegistrationRequest = Omit<AgentRegistration, 'registeredAt' | 'lastHeartbeat' | 'connectionCount' | 'status'>;
|
|
1205
1261
|
declare const DEFAULT_AGENT_REGISTRY_CONFIG: {
|
|
1206
|
-
readonly heartbeatInterval:
|
|
1207
|
-
readonly heartbeatTimeout:
|
|
1208
|
-
readonly heartbeatCheckInterval:
|
|
1209
|
-
readonly autoDeregisterTimeout:
|
|
1262
|
+
readonly heartbeatInterval: 60000;
|
|
1263
|
+
readonly heartbeatTimeout: 300000;
|
|
1264
|
+
readonly heartbeatCheckInterval: 300000;
|
|
1265
|
+
readonly autoDeregisterTimeout: 600000;
|
|
1210
1266
|
readonly maxAgents: 100;
|
|
1211
1267
|
readonly maxRegistrations: 1000;
|
|
1212
1268
|
};
|
|
@@ -1351,12 +1407,12 @@ declare const DEFAULT_CONNECTION_POOL_CONFIG: {
|
|
|
1351
1407
|
acquireTimeout: number;
|
|
1352
1408
|
warmupCount: number;
|
|
1353
1409
|
};
|
|
1354
|
-
type ConnectionState
|
|
1410
|
+
type ConnectionState = 'idle' | 'active' | 'unhealthy' | 'closed';
|
|
1355
1411
|
interface PooledConnection<T = unknown> {
|
|
1356
1412
|
id: string;
|
|
1357
1413
|
channelId: string;
|
|
1358
1414
|
connection: T;
|
|
1359
|
-
state: ConnectionState
|
|
1415
|
+
state: ConnectionState;
|
|
1360
1416
|
lastActivity: number;
|
|
1361
1417
|
createdAt: number;
|
|
1362
1418
|
useCount: number;
|
|
@@ -1390,21 +1446,30 @@ interface CancelEvent {
|
|
|
1390
1446
|
timestamp: number;
|
|
1391
1447
|
}
|
|
1392
1448
|
type CancelEventHandler = (event: CancelEvent) => void | Promise<void>;
|
|
1449
|
+
interface RouterSessionManager {
|
|
1450
|
+
get(sessionId: string): {
|
|
1451
|
+
backendSessionId?: string | null;
|
|
1452
|
+
} | undefined;
|
|
1453
|
+
bindBackendSession(gatewaySessionId: string, backendSessionId: string): Promise<void>;
|
|
1454
|
+
}
|
|
1393
1455
|
declare class MessageRouter {
|
|
1394
1456
|
private log;
|
|
1395
1457
|
private subscribers;
|
|
1396
1458
|
private subscriptions;
|
|
1397
|
-
private
|
|
1459
|
+
private messageSubscriptions;
|
|
1398
1460
|
private channelPlugins;
|
|
1399
1461
|
private cancelHandlers;
|
|
1400
1462
|
private processingMessages;
|
|
1401
1463
|
private hookRegistry;
|
|
1402
|
-
|
|
1464
|
+
private sessionManager;
|
|
1465
|
+
constructor(hookRegistry?: typeof this.hookRegistry, sessionManager?: RouterSessionManager);
|
|
1466
|
+
setSessionManager(sessionManager: RouterSessionManager): void;
|
|
1403
1467
|
private triggerHook;
|
|
1404
1468
|
private triggerBeforeSend;
|
|
1405
1469
|
onCancel(handler: CancelEventHandler): void;
|
|
1406
1470
|
offCancel(handler: CancelEventHandler): void;
|
|
1407
1471
|
private emitCancel;
|
|
1472
|
+
private selectSubscriber;
|
|
1408
1473
|
route(message: GatewayMessage): Promise<RouteResult>;
|
|
1409
1474
|
completeMessage(sessionId: string, messageId: string, subscriberId: string, reason?: 'completed' | 'failed' | 'timeout'): Promise<void>;
|
|
1410
1475
|
subscribe(sessionId: string, subscriber: Subscriber): Promise<Subscription>;
|
|
@@ -1414,6 +1479,7 @@ declare class MessageRouter {
|
|
|
1414
1479
|
unregisterChannel(pluginId: string): void;
|
|
1415
1480
|
getSubscriber(subscriberId: string): Subscriber | undefined;
|
|
1416
1481
|
getSubscription(subscriptionId: string): Subscription | undefined;
|
|
1482
|
+
getMessageSubscriptions(): Map<string, Set<string>>;
|
|
1417
1483
|
getSubscriberCount(sessionId: string): number;
|
|
1418
1484
|
getStats(): {
|
|
1419
1485
|
subscribers: number;
|
|
@@ -1443,6 +1509,7 @@ declare class GatewaySessionManager {
|
|
|
1443
1509
|
closeById(sessionId: string): Promise<void>;
|
|
1444
1510
|
bindBackendSession(gatewaySessionId: string, backendSessionId: string): Promise<void>;
|
|
1445
1511
|
unbindBackendSession(gatewaySessionId: string): Promise<void>;
|
|
1512
|
+
findByBackendSessionId(backendSessionId: string): GatewaySession | undefined;
|
|
1446
1513
|
getState(sessionId: string): SessionState | undefined;
|
|
1447
1514
|
incrementMessageCountOrCreate(sessionId: string, channelInfo?: SessionChannelInfo): Promise<GatewaySession>;
|
|
1448
1515
|
incrementMessageCount(sessionId: string): Promise<void>;
|
|
@@ -1461,15 +1528,28 @@ declare class GatewaySessionManager {
|
|
|
1461
1528
|
};
|
|
1462
1529
|
}
|
|
1463
1530
|
|
|
1531
|
+
type AgentEventType = 'register' | 'deregister' | 'heartbeat' | 'status_change';
|
|
1532
|
+
interface AgentEvent {
|
|
1533
|
+
type: AgentEventType;
|
|
1534
|
+
agent: AgentRegistration;
|
|
1535
|
+
oldStatus?: AgentHealthStatus;
|
|
1536
|
+
}
|
|
1537
|
+
type AgentEventCallback = (event: AgentEvent) => void | Promise<void>;
|
|
1464
1538
|
declare class AgentRegistry {
|
|
1465
1539
|
private config;
|
|
1466
1540
|
private agents;
|
|
1467
1541
|
private heartbeatTimer;
|
|
1468
1542
|
private roundRobinIndex;
|
|
1469
|
-
|
|
1543
|
+
private store;
|
|
1544
|
+
private eventCallbacks;
|
|
1545
|
+
constructor(config?: Partial<AgentRegistryConfig & {
|
|
1546
|
+
dataDir?: string;
|
|
1547
|
+
}>);
|
|
1548
|
+
load(): Promise<void>;
|
|
1470
1549
|
register(agent: AgentRegistrationRequest): Promise<void>;
|
|
1471
1550
|
deregister(agentId: string): Promise<void>;
|
|
1472
1551
|
heartbeat(agentId: string, metrics?: AgentRegistration['metadata']): Promise<void>;
|
|
1552
|
+
setStatus(agentId: string, status: AgentHealthStatus): void;
|
|
1473
1553
|
getAgent(agentId: string): AgentRegistration | undefined;
|
|
1474
1554
|
getAllAgents(): AgentRegistration[];
|
|
1475
1555
|
getHealthyAgents(): AgentRegistration[];
|
|
@@ -1479,6 +1559,9 @@ declare class AgentRegistry {
|
|
|
1479
1559
|
startHeartbeatCheck(): void;
|
|
1480
1560
|
stopHeartbeatCheck(): void;
|
|
1481
1561
|
private checkHeartbeats;
|
|
1562
|
+
onEvent(callback: AgentEventCallback): void;
|
|
1563
|
+
offEvent(callback: AgentEventCallback): void;
|
|
1564
|
+
private emitEvent;
|
|
1482
1565
|
private selectRandom;
|
|
1483
1566
|
private selectRoundRobin;
|
|
1484
1567
|
private selectLeastConnections;
|
|
@@ -1487,15 +1570,21 @@ declare class AgentRegistry {
|
|
|
1487
1570
|
setLastHeartbeat(agentId: string, timestamp: number): void;
|
|
1488
1571
|
}
|
|
1489
1572
|
|
|
1573
|
+
type AgentListChangeCallback = (agents: AgentSyncInfo[], action: 'add' | 'update' | 'remove', agent: AgentSyncInfo) => void | Promise<void>;
|
|
1490
1574
|
declare class AgentSyncManager {
|
|
1491
1575
|
private config;
|
|
1576
|
+
private internalConfig;
|
|
1492
1577
|
private registry;
|
|
1493
1578
|
private localNodeId;
|
|
1494
1579
|
private localNodeName;
|
|
1495
1580
|
private remoteNodes;
|
|
1496
1581
|
private remoteAgents;
|
|
1497
1582
|
private syncTimer;
|
|
1583
|
+
private cleanupTimer;
|
|
1584
|
+
private reconnectTimer;
|
|
1585
|
+
private heartbeatTimer;
|
|
1498
1586
|
private running;
|
|
1587
|
+
private agentListChangeCallbacks;
|
|
1499
1588
|
constructor(options: {
|
|
1500
1589
|
registry: AgentRegistry;
|
|
1501
1590
|
localNodeId: string;
|
|
@@ -1506,6 +1595,7 @@ declare class AgentSyncManager {
|
|
|
1506
1595
|
stop(): Promise<void>;
|
|
1507
1596
|
private pullFromAllNodes;
|
|
1508
1597
|
pullFromNode(nodeId: string): Promise<AgentSyncInfo[]>;
|
|
1598
|
+
private calculateRetryDelay;
|
|
1509
1599
|
pushEvent(message: SyncMessage): Promise<void>;
|
|
1510
1600
|
pushToNode(nodeId: string, message: SyncMessage): Promise<void>;
|
|
1511
1601
|
handleSyncMessage(message: SyncMessage): Promise<void>;
|
|
@@ -1515,8 +1605,16 @@ declare class AgentSyncManager {
|
|
|
1515
1605
|
private handleAgentDeregister;
|
|
1516
1606
|
private handleAgentHeartbeat;
|
|
1517
1607
|
private handleAgentStatusChange;
|
|
1608
|
+
private cleanupStaleAgents;
|
|
1609
|
+
private reconnectFailedNodes;
|
|
1610
|
+
private checkNodeHealth;
|
|
1611
|
+
private handleLocalAgentEvent;
|
|
1612
|
+
private agentToSyncInfo;
|
|
1518
1613
|
private resolveConflict;
|
|
1519
1614
|
private getLocalAgentsForSync;
|
|
1615
|
+
private notifyAgentListChange;
|
|
1616
|
+
onAgentListChange(callback: AgentListChangeCallback): void;
|
|
1617
|
+
offAgentListChange(callback: AgentListChangeCallback): void;
|
|
1520
1618
|
getMergedAgentList(): AgentSyncInfo[];
|
|
1521
1619
|
getRemoteAgents(): AgentSyncInfo[];
|
|
1522
1620
|
getStats(): SyncStats;
|
|
@@ -1564,6 +1662,11 @@ declare namespace Log {
|
|
|
1564
1662
|
function create(tags?: Record<string, any>): Logger;
|
|
1565
1663
|
}
|
|
1566
1664
|
|
|
1665
|
+
interface LocalCommandResult {
|
|
1666
|
+
handled: boolean;
|
|
1667
|
+
reply?: string;
|
|
1668
|
+
continueProcessing?: boolean;
|
|
1669
|
+
}
|
|
1567
1670
|
declare abstract class BaseChannelPlugin implements ChannelPlugin {
|
|
1568
1671
|
abstract readonly id: string;
|
|
1569
1672
|
abstract readonly platform: PlatformType;
|
|
@@ -1594,12 +1697,12 @@ declare abstract class BaseChannelPlugin implements ChannelPlugin {
|
|
|
1594
1697
|
protected buildSessionId(channelId: string, chatId: string, userId?: string): string;
|
|
1595
1698
|
protected handleMessage(message: GatewayMessage): Promise<void>;
|
|
1596
1699
|
protected handleEvent(type: string, data?: unknown): Promise<void>;
|
|
1597
|
-
protected getCommandList(): Promise<
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1700
|
+
protected getCommandList(): Promise<Command[]>;
|
|
1701
|
+
protected processLocalCommand(command: string, sessionId: string, chatId: string): Promise<LocalCommandResult>;
|
|
1702
|
+
private handleNewCommand;
|
|
1703
|
+
private handleStatusCommand;
|
|
1704
|
+
private formatStatusReport;
|
|
1705
|
+
private formatUptime;
|
|
1603
1706
|
}
|
|
1604
1707
|
|
|
1605
1708
|
interface PluginLoaderConfig {
|
|
@@ -1621,6 +1724,7 @@ declare class ChannelPluginLoader {
|
|
|
1621
1724
|
private backoffPolicy;
|
|
1622
1725
|
constructor(config?: PluginLoaderConfig);
|
|
1623
1726
|
setMessageHandler(handler: MessageHandler): void;
|
|
1727
|
+
updateSessionHandler(session: NonNullable<MessageHandler['session']>): void;
|
|
1624
1728
|
register(plugin: ChannelPlugin, config: ChannelConfig): Promise<void>;
|
|
1625
1729
|
unregister(pluginId: string): Promise<void>;
|
|
1626
1730
|
start(pluginId: string): Promise<void>;
|
|
@@ -1801,6 +1905,7 @@ interface ResolveChannelParams {
|
|
|
1801
1905
|
get(sessionId: string): GatewaySession | undefined;
|
|
1802
1906
|
getOrCreate(channelInfo: SessionChannelInfo, context?: Record<string, unknown>): Promise<GatewaySession>;
|
|
1803
1907
|
bindBackendSession(gatewaySessionId: string, backendSessionId: string): Promise<void>;
|
|
1908
|
+
findByBackendSessionId(backendSessionId: string): GatewaySession | undefined;
|
|
1804
1909
|
getAll?(): GatewaySession[];
|
|
1805
1910
|
};
|
|
1806
1911
|
pluginLoader?: {
|
|
@@ -1850,6 +1955,38 @@ interface ResolveChannelParams {
|
|
|
1850
1955
|
};
|
|
1851
1956
|
}
|
|
1852
1957
|
|
|
1958
|
+
declare class WebSocketServerAgentSync {
|
|
1959
|
+
private wsServer;
|
|
1960
|
+
private syncManager;
|
|
1961
|
+
private gatewayId;
|
|
1962
|
+
private subscribers;
|
|
1963
|
+
private getClientWs;
|
|
1964
|
+
constructor(options: {
|
|
1965
|
+
wsServer: GatewayWebSocketServer;
|
|
1966
|
+
syncManager: AgentSyncManager;
|
|
1967
|
+
getClientWs: (clientId: string) => WSContext | undefined;
|
|
1968
|
+
});
|
|
1969
|
+
handleAgentListRequest(clientId: string, requestId: string): Promise<void>;
|
|
1970
|
+
handleAgentSubscribe(clientId: string, subscribe: boolean): Promise<void>;
|
|
1971
|
+
broadcastAgentUpdate(action: 'add' | 'update' | 'remove', agent: AgentSyncInfo): void;
|
|
1972
|
+
broadcastAgentList(): void;
|
|
1973
|
+
cleanupClientSubscription(clientId: string): void;
|
|
1974
|
+
getSubscriberCount(): number;
|
|
1975
|
+
getSubscribers(): string[];
|
|
1976
|
+
private sendMessage;
|
|
1977
|
+
handleAgentRegister(clientId: string, payload: {
|
|
1978
|
+
agentId: string;
|
|
1979
|
+
name: string;
|
|
1980
|
+
address: string;
|
|
1981
|
+
capabilities?: string[];
|
|
1982
|
+
metadata?: Record<string, unknown>;
|
|
1983
|
+
}): Promise<void>;
|
|
1984
|
+
handleAgentDeregister(clientId: string, payload: {
|
|
1985
|
+
agentId: string;
|
|
1986
|
+
}): Promise<void>;
|
|
1987
|
+
cleanupClient(clientId: string): Promise<void>;
|
|
1988
|
+
}
|
|
1989
|
+
|
|
1853
1990
|
type MessageSender = (pluginId: string, message: GatewayMessage, options?: SendOptions) => Promise<string>;
|
|
1854
1991
|
interface SendOptions extends Record<string, unknown> {
|
|
1855
1992
|
}
|
|
@@ -1861,8 +1998,7 @@ declare class GatewayWebSocketServer {
|
|
|
1861
1998
|
private httpRedirectServer;
|
|
1862
1999
|
private connections;
|
|
1863
2000
|
private subscriptions;
|
|
1864
|
-
private
|
|
1865
|
-
private sessionLastActivity;
|
|
2001
|
+
private clientLastActivity;
|
|
1866
2002
|
private cleanupInterval;
|
|
1867
2003
|
private heartbeatInterval;
|
|
1868
2004
|
private startTime;
|
|
@@ -1872,6 +2008,20 @@ declare class GatewayWebSocketServer {
|
|
|
1872
2008
|
setChannelResolveDeps(params: ResolveChannelParams): void;
|
|
1873
2009
|
private pluginLoaderRef;
|
|
1874
2010
|
setPluginLoader(sender: MessageSender): void;
|
|
2011
|
+
private agentSyncRef;
|
|
2012
|
+
getGatewayId(): string;
|
|
2013
|
+
setAgentSync(agentSync: WebSocketServerAgentSync): void;
|
|
2014
|
+
private agentRegistryRef;
|
|
2015
|
+
setAgentRegistry(registry: {
|
|
2016
|
+
getStats(): {
|
|
2017
|
+
totalAgents: number;
|
|
2018
|
+
healthyAgents: number;
|
|
2019
|
+
unhealthyAgents: number;
|
|
2020
|
+
};
|
|
2021
|
+
}): void;
|
|
2022
|
+
private routerRef;
|
|
2023
|
+
setRouter(router: MessageRouter): void;
|
|
2024
|
+
private subscribers;
|
|
1875
2025
|
private getChannelResolveParams;
|
|
1876
2026
|
start(): Promise<void>;
|
|
1877
2027
|
private startHTTPServer;
|
|
@@ -1880,27 +2030,32 @@ declare class GatewayWebSocketServer {
|
|
|
1880
2030
|
private setupWebSocketUpgrade;
|
|
1881
2031
|
private startHTTPRedirectServer;
|
|
1882
2032
|
stop(): Promise<void>;
|
|
1883
|
-
|
|
2033
|
+
private touchClient;
|
|
1884
2034
|
getConnectionCount(): number;
|
|
2035
|
+
getStartTime(): number;
|
|
1885
2036
|
getSubscriptionCount(): number;
|
|
1886
2037
|
getConnectionInfos(): WebSocketConnectionInfo[];
|
|
1887
2038
|
isRunning(): boolean;
|
|
1888
2039
|
private handleConnection;
|
|
1889
2040
|
private handleDisconnection;
|
|
2041
|
+
private cleanupClientResources;
|
|
1890
2042
|
private handleMessage;
|
|
1891
|
-
private handleInitialize;
|
|
1892
2043
|
private handleSubscribe;
|
|
1893
2044
|
private handleUnsubscribe;
|
|
1894
2045
|
private handleMessageRequest;
|
|
2046
|
+
private getClientIdByWs;
|
|
2047
|
+
getClientWs(clientId: string): WSContext | undefined;
|
|
1895
2048
|
private handleInterrupt;
|
|
1896
2049
|
private handleReleaseSubscription;
|
|
1897
|
-
private touchSession;
|
|
1898
2050
|
private checkConnectionTimeout;
|
|
1899
|
-
private
|
|
1900
|
-
private releaseSessionResources;
|
|
2051
|
+
private cleanupInactiveClients;
|
|
1901
2052
|
private sendMessage;
|
|
1902
2053
|
private sendError;
|
|
1903
2054
|
private createRoutes;
|
|
2055
|
+
private handleAgentListRequest;
|
|
2056
|
+
private handleAgentSubscribe;
|
|
2057
|
+
private handleAgentRegister;
|
|
2058
|
+
private handleAgentDeregister;
|
|
1904
2059
|
}
|
|
1905
2060
|
|
|
1906
2061
|
declare class GatewayServer implements IGatewayServer {
|
|
@@ -1914,6 +2069,9 @@ declare class GatewayServer implements IGatewayServer {
|
|
|
1914
2069
|
private messageStore;
|
|
1915
2070
|
private contactStore;
|
|
1916
2071
|
private wsServer;
|
|
2072
|
+
private agentRegistry;
|
|
2073
|
+
private agentSyncManager;
|
|
2074
|
+
private wsAgentSync;
|
|
1917
2075
|
private running;
|
|
1918
2076
|
private connections;
|
|
1919
2077
|
private gatewayAgent;
|
|
@@ -1926,6 +2084,11 @@ declare class GatewayServer implements IGatewayServer {
|
|
|
1926
2084
|
port?: number;
|
|
1927
2085
|
hostname?: string;
|
|
1928
2086
|
connections?: number;
|
|
2087
|
+
agents?: {
|
|
2088
|
+
total: number;
|
|
2089
|
+
healthy: number;
|
|
2090
|
+
unhealthy: number;
|
|
2091
|
+
};
|
|
1929
2092
|
};
|
|
1930
2093
|
onMessage(message: GatewayMessage): Promise<void>;
|
|
1931
2094
|
private saveContactFromMessage;
|
|
@@ -1957,184 +2120,6 @@ declare class GatewayServer implements IGatewayServer {
|
|
|
1957
2120
|
getMessageHistory(sessionId: string, limit?: number): Promise<MessageRecord[]>;
|
|
1958
2121
|
}
|
|
1959
2122
|
|
|
1960
|
-
interface GatewayClientConfig {
|
|
1961
|
-
url: string;
|
|
1962
|
-
type: SubscriberType;
|
|
1963
|
-
id?: string;
|
|
1964
|
-
reconnect?: {
|
|
1965
|
-
enabled: boolean;
|
|
1966
|
-
maxAttempts: number;
|
|
1967
|
-
delay: number;
|
|
1968
|
-
};
|
|
1969
|
-
heartbeat?: {
|
|
1970
|
-
enabled: boolean;
|
|
1971
|
-
interval: number;
|
|
1972
|
-
};
|
|
1973
|
-
}
|
|
1974
|
-
type MessageCallback = (message: GatewayMessage) => void | Promise<void>;
|
|
1975
|
-
type AgentListChangeCallback = (agents: AgentSyncInfo[]) => void | Promise<void>;
|
|
1976
|
-
interface HealthResponse {
|
|
1977
|
-
status: string;
|
|
1978
|
-
timestamp: number;
|
|
1979
|
-
version: string;
|
|
1980
|
-
}
|
|
1981
|
-
interface StatusResponse {
|
|
1982
|
-
status: string;
|
|
1983
|
-
connections: number;
|
|
1984
|
-
sessions: number;
|
|
1985
|
-
subscriptions: number;
|
|
1986
|
-
uptime: number;
|
|
1987
|
-
version: string;
|
|
1988
|
-
}
|
|
1989
|
-
interface ContactInfo {
|
|
1990
|
-
uid: string;
|
|
1991
|
-
platform: string;
|
|
1992
|
-
stableId: string;
|
|
1993
|
-
profile: {
|
|
1994
|
-
displayName?: string;
|
|
1995
|
-
username?: string;
|
|
1996
|
-
};
|
|
1997
|
-
lastSeenAt: number;
|
|
1998
|
-
createdAt: number;
|
|
1999
|
-
}
|
|
2000
|
-
interface ContactListResponse {
|
|
2001
|
-
contacts: ContactInfo[];
|
|
2002
|
-
total: number;
|
|
2003
|
-
hasMore: boolean;
|
|
2004
|
-
}
|
|
2005
|
-
interface SessionInfo {
|
|
2006
|
-
id: string;
|
|
2007
|
-
platform?: string;
|
|
2008
|
-
channelId?: string;
|
|
2009
|
-
userId?: string;
|
|
2010
|
-
chatId?: string;
|
|
2011
|
-
chatType?: string;
|
|
2012
|
-
chatTitle?: string;
|
|
2013
|
-
state: string;
|
|
2014
|
-
createdAt: number;
|
|
2015
|
-
lastActiveAt: number;
|
|
2016
|
-
}
|
|
2017
|
-
interface SessionListResponse {
|
|
2018
|
-
sessions: SessionInfo[];
|
|
2019
|
-
total: number;
|
|
2020
|
-
hasMore: boolean;
|
|
2021
|
-
}
|
|
2022
|
-
interface CreateSessionResponse {
|
|
2023
|
-
id: string;
|
|
2024
|
-
createdAt: number;
|
|
2025
|
-
}
|
|
2026
|
-
interface SendMessageResponse {
|
|
2027
|
-
success: boolean;
|
|
2028
|
-
messageId?: string;
|
|
2029
|
-
}
|
|
2030
|
-
type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting';
|
|
2031
|
-
interface AgentListMergeOptions {
|
|
2032
|
-
localAgents?: AgentSyncInfo[];
|
|
2033
|
-
preferLocal?: boolean;
|
|
2034
|
-
filterOffline?: boolean;
|
|
2035
|
-
}
|
|
2036
|
-
declare class GatewayClient {
|
|
2037
|
-
private log;
|
|
2038
|
-
private config;
|
|
2039
|
-
private ws;
|
|
2040
|
-
private state;
|
|
2041
|
-
private subscriptions;
|
|
2042
|
-
private messageCallbacks;
|
|
2043
|
-
private agentListCallbacks;
|
|
2044
|
-
private cachedAgentList;
|
|
2045
|
-
private localAgentList;
|
|
2046
|
-
private reconnectAttempts;
|
|
2047
|
-
private reconnectTimer;
|
|
2048
|
-
private heartbeatTimer;
|
|
2049
|
-
private agentListRequestId;
|
|
2050
|
-
private agentListRequestResolve;
|
|
2051
|
-
constructor(config: GatewayClientConfig);
|
|
2052
|
-
connect(): Promise<void>;
|
|
2053
|
-
disconnect(): Promise<void>;
|
|
2054
|
-
subscribe(sessionId: string, backendSessionId?: string): Promise<void>;
|
|
2055
|
-
unsubscribe(sessionId: string): Promise<void>;
|
|
2056
|
-
send(message: GatewayMessage): Promise<void>;
|
|
2057
|
-
onMessage(callback: MessageCallback): void;
|
|
2058
|
-
offMessage(callback: MessageCallback): void;
|
|
2059
|
-
getState(): ConnectionState;
|
|
2060
|
-
getId(): string;
|
|
2061
|
-
getSubscriptions(): string[];
|
|
2062
|
-
setLocalAgents(agents: AgentSyncInfo[]): void;
|
|
2063
|
-
fetchAgentList(): Promise<AgentSyncInfo[]>;
|
|
2064
|
-
getConnectableAgents(options?: AgentListMergeOptions): AgentSyncInfo[];
|
|
2065
|
-
onAgentListChange(callback: AgentListChangeCallback): void;
|
|
2066
|
-
offAgentListChange(callback: AgentListChangeCallback): void;
|
|
2067
|
-
private mergeAgentLists;
|
|
2068
|
-
private updateMergedAgentList;
|
|
2069
|
-
private handleAgentListResponse;
|
|
2070
|
-
private sendData;
|
|
2071
|
-
private handleMessage;
|
|
2072
|
-
private handleAgentUpdate;
|
|
2073
|
-
private handleGatewayMessage;
|
|
2074
|
-
private handleClose;
|
|
2075
|
-
private scheduleReconnect;
|
|
2076
|
-
private stopReconnect;
|
|
2077
|
-
private startHeartbeat;
|
|
2078
|
-
private stopHeartbeat;
|
|
2079
|
-
private resubscribeAll;
|
|
2080
|
-
private getHttpUrl;
|
|
2081
|
-
private httpRequest;
|
|
2082
|
-
healthCheck(): Promise<HealthResponse>;
|
|
2083
|
-
getStatus(): Promise<StatusResponse>;
|
|
2084
|
-
listChannels(): Promise<ChannelListResponse>;
|
|
2085
|
-
listContacts(platform: string, options?: {
|
|
2086
|
-
limit?: number;
|
|
2087
|
-
offset?: number;
|
|
2088
|
-
}): Promise<ContactListResponse>;
|
|
2089
|
-
getContact(uid: string): Promise<ContactInfo & {
|
|
2090
|
-
aliases?: Record<string, unknown>;
|
|
2091
|
-
}>;
|
|
2092
|
-
getSession(sessionId: string): Promise<SessionInfo & {
|
|
2093
|
-
subscriberCount?: number;
|
|
2094
|
-
}>;
|
|
2095
|
-
createSession(params?: {
|
|
2096
|
-
title?: string;
|
|
2097
|
-
channel?: {
|
|
2098
|
-
platform?: string;
|
|
2099
|
-
channelId?: string;
|
|
2100
|
-
userId?: string;
|
|
2101
|
-
chatId?: string;
|
|
2102
|
-
};
|
|
2103
|
-
}): Promise<CreateSessionResponse>;
|
|
2104
|
-
getOrCreateSession(options: {
|
|
2105
|
-
sessionId?: string;
|
|
2106
|
-
channel?: string;
|
|
2107
|
-
userId?: string;
|
|
2108
|
-
chatId?: string;
|
|
2109
|
-
platform?: string;
|
|
2110
|
-
}): Promise<{
|
|
2111
|
-
sessionId: string;
|
|
2112
|
-
created: boolean;
|
|
2113
|
-
}>;
|
|
2114
|
-
listSessions(options?: {
|
|
2115
|
-
limit?: number;
|
|
2116
|
-
offset?: number;
|
|
2117
|
-
platform?: string;
|
|
2118
|
-
channelId?: string;
|
|
2119
|
-
userId?: string;
|
|
2120
|
-
chatId?: string;
|
|
2121
|
-
}): Promise<SessionListResponse>;
|
|
2122
|
-
sendMessage(sessionId: string, message: {
|
|
2123
|
-
content: Array<{
|
|
2124
|
-
type: string;
|
|
2125
|
-
text?: string;
|
|
2126
|
-
image?: string;
|
|
2127
|
-
data?: string;
|
|
2128
|
-
}>;
|
|
2129
|
-
channel?: string;
|
|
2130
|
-
userId?: string;
|
|
2131
|
-
chatId?: string;
|
|
2132
|
-
messageType?: string;
|
|
2133
|
-
processorId?: string;
|
|
2134
|
-
agent?: string;
|
|
2135
|
-
}): Promise<SendMessageResponse>;
|
|
2136
|
-
}
|
|
2137
|
-
|
|
2138
2123
|
interface TelegramBotConfig {
|
|
2139
2124
|
botToken: string;
|
|
2140
2125
|
webhook?: {
|
|
@@ -2661,7 +2646,6 @@ declare class WebChatPlugin extends BaseChannelPlugin {
|
|
|
2661
2646
|
maxMessageLength: number;
|
|
2662
2647
|
maxMediaCount: number;
|
|
2663
2648
|
};
|
|
2664
|
-
pushEvent(sessionId: string, event: SessionEventPayload): void;
|
|
2665
2649
|
getWebSocketServer(): GatewayWebSocketServer | null;
|
|
2666
2650
|
handleConnection(ws: WebSocket, userId: string): Promise<void>;
|
|
2667
2651
|
getConnectionCount(): number;
|
|
@@ -2867,7 +2851,200 @@ declare function createChannelPlugin<TConfig = unknown, TProbe = unknown>(option
|
|
|
2867
2851
|
declare const ChannelPluginRegistry: Record<string, new (id?: string) => ChannelPlugin>;
|
|
2868
2852
|
declare function getSupportedPlatforms(): string[];
|
|
2869
2853
|
|
|
2870
|
-
declare
|
|
2854
|
+
declare enum SdkEventType {
|
|
2855
|
+
SDK_SESSION_STATUS = "agent.status",
|
|
2856
|
+
SDK_ERROR = "sdk.error",
|
|
2857
|
+
SDK_SESSION_UPDATE = "sdk.session_update",
|
|
2858
|
+
SDK_PERMISSION_REQUEST = "sdk.permission_request",
|
|
2859
|
+
SDK_SESSION_DELETED = "sdk.session_deleted"
|
|
2860
|
+
}
|
|
2861
|
+
declare const SdkSessionStatusSchema: z$1.ZodObject<{
|
|
2862
|
+
sessionId: z$1.ZodString;
|
|
2863
|
+
status: z$1.ZodEnum<{
|
|
2864
|
+
idle: "idle";
|
|
2865
|
+
busy: "busy";
|
|
2866
|
+
retry: "retry";
|
|
2867
|
+
}>;
|
|
2868
|
+
timestamp: z$1.ZodNumber;
|
|
2869
|
+
}, z$1.core.$strip>;
|
|
2870
|
+
type SdkSessionStatusProps = z$1.infer<typeof SdkSessionStatusSchema>;
|
|
2871
|
+
declare const SdkErrorSchema: z$1.ZodObject<{
|
|
2872
|
+
error: z$1.ZodString;
|
|
2873
|
+
context: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodAny>>;
|
|
2874
|
+
timestamp: z$1.ZodNumber;
|
|
2875
|
+
}, z$1.core.$strip>;
|
|
2876
|
+
type SdkErrorProps = z$1.infer<typeof SdkErrorSchema>;
|
|
2877
|
+
declare const SdkSessionUpdateSchema: z$1.ZodObject<{
|
|
2878
|
+
sessionId: z$1.ZodString;
|
|
2879
|
+
update: z$1.ZodRecord<z$1.ZodString, z$1.ZodAny>;
|
|
2880
|
+
timestamp: z$1.ZodNumber;
|
|
2881
|
+
}, z$1.core.$strip>;
|
|
2882
|
+
type SdkSessionUpdateProps = z$1.infer<typeof SdkSessionUpdateSchema>;
|
|
2883
|
+
declare const SdkPermissionRequestSchema: z$1.ZodObject<{
|
|
2884
|
+
requestId: z$1.ZodString;
|
|
2885
|
+
sessionId: z$1.ZodString;
|
|
2886
|
+
permission: z$1.ZodString;
|
|
2887
|
+
tool: z$1.ZodOptional<z$1.ZodObject<{
|
|
2888
|
+
callId: z$1.ZodOptional<z$1.ZodString>;
|
|
2889
|
+
}, z$1.core.$strip>>;
|
|
2890
|
+
metadata: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodAny>>;
|
|
2891
|
+
timestamp: z$1.ZodNumber;
|
|
2892
|
+
}, z$1.core.$strip>;
|
|
2893
|
+
type SdkPermissionRequestProps = z$1.infer<typeof SdkPermissionRequestSchema>;
|
|
2894
|
+
declare const SdkSessionDeletedSchema: z$1.ZodObject<{
|
|
2895
|
+
sessionId: z$1.ZodString;
|
|
2896
|
+
timestamp: z$1.ZodNumber;
|
|
2897
|
+
}, z$1.core.$strip>;
|
|
2898
|
+
type SdkSessionDeletedProps = z$1.infer<typeof SdkSessionDeletedSchema>;
|
|
2899
|
+
type LocalEventProperties = SdkSessionStatusProps | SdkErrorProps | SdkSessionUpdateProps | SdkPermissionRequestProps | SdkSessionDeletedProps;
|
|
2900
|
+
interface LocalEvent<T extends SdkEventType = SdkEventType> {
|
|
2901
|
+
type: T;
|
|
2902
|
+
properties: LocalEventProperties;
|
|
2903
|
+
}
|
|
2904
|
+
type LocalEventCallback = (event: LocalEvent) => void | Promise<void>;
|
|
2905
|
+
declare class SdkEventBus {
|
|
2906
|
+
private subscriptions;
|
|
2907
|
+
private wildcardSubscriptions;
|
|
2908
|
+
private destroyed;
|
|
2909
|
+
subscribe(eventType: SdkEventType, callback: LocalEventCallback): () => void;
|
|
2910
|
+
subscribeAll(callback: LocalEventCallback): () => void;
|
|
2911
|
+
publish(event: LocalEvent): Promise<void>;
|
|
2912
|
+
publishSync(event: LocalEvent): void;
|
|
2913
|
+
subscriberCount(eventType?: SdkEventType): number;
|
|
2914
|
+
totalSubscribers(): number;
|
|
2915
|
+
hasSubscribers(eventType?: SdkEventType): boolean;
|
|
2916
|
+
clear(): void;
|
|
2917
|
+
destroy(): void;
|
|
2918
|
+
isDestroyed(): boolean;
|
|
2919
|
+
}
|
|
2920
|
+
|
|
2921
|
+
declare class SdkEventBridge {
|
|
2922
|
+
private sdk;
|
|
2923
|
+
private sdkEventBus?;
|
|
2924
|
+
private abortController;
|
|
2925
|
+
private started;
|
|
2926
|
+
private readonly sessionFilter?;
|
|
2927
|
+
constructor(sdk: EasbotClient, localEventBus?: SdkEventBus, sessionFilter?: (sessionId: string) => boolean);
|
|
2928
|
+
private pushEvent;
|
|
2929
|
+
start(): Promise<void>;
|
|
2930
|
+
stop(): Promise<void>;
|
|
2931
|
+
isStarted(): boolean;
|
|
2932
|
+
private runEventLoop;
|
|
2933
|
+
private handleEvent;
|
|
2934
|
+
private handleSessionDeleted;
|
|
2935
|
+
private handlePermissionAsked;
|
|
2936
|
+
private handleMessagePartUpdated;
|
|
2937
|
+
private handleToolPart;
|
|
2938
|
+
private handleTextPart;
|
|
2939
|
+
private handleStepStartPart;
|
|
2940
|
+
private handleStepFinishPart;
|
|
2941
|
+
private handleReasoningPart;
|
|
2942
|
+
private handleSessionStatus;
|
|
2943
|
+
}
|
|
2944
|
+
|
|
2945
|
+
interface AgentClientFilterConfig {
|
|
2946
|
+
includeThinking: boolean;
|
|
2947
|
+
includeToolDetails: boolean;
|
|
2948
|
+
includeToolOutput: boolean;
|
|
2949
|
+
includeSteps: boolean;
|
|
2950
|
+
}
|
|
2951
|
+
declare const DEFAULT_AGENT_FILTER: AgentClientFilterConfig;
|
|
2952
|
+
declare const DEBUG_AGENT_FILTER: AgentClientFilterConfig;
|
|
2953
|
+
interface AgentMessage {
|
|
2954
|
+
role: 'user' | 'assistant';
|
|
2955
|
+
text: string;
|
|
2956
|
+
thinking?: string;
|
|
2957
|
+
tools?: Array<{
|
|
2958
|
+
name: string;
|
|
2959
|
+
status: 'completed' | 'error';
|
|
2960
|
+
output?: unknown;
|
|
2961
|
+
error?: string;
|
|
2962
|
+
}>;
|
|
2963
|
+
metadata: {
|
|
2964
|
+
sessionId: string;
|
|
2965
|
+
sessionStatus?: 'idle' | 'busy' | 'retry' | 'error';
|
|
2966
|
+
messageId: string;
|
|
2967
|
+
timestamp: number;
|
|
2968
|
+
tokens?: {
|
|
2969
|
+
input: number;
|
|
2970
|
+
output: number;
|
|
2971
|
+
total: number;
|
|
2972
|
+
};
|
|
2973
|
+
error?: string;
|
|
2974
|
+
};
|
|
2975
|
+
}
|
|
2976
|
+
type SessionEventType = 'part.updated' | 'session.status' | 'message.updated' | 'message.part.updated' | 'session.error';
|
|
2977
|
+
interface SessionError {
|
|
2978
|
+
name: string;
|
|
2979
|
+
data: {
|
|
2980
|
+
message?: string;
|
|
2981
|
+
providerId?: string;
|
|
2982
|
+
statusCode?: number;
|
|
2983
|
+
isRetryable?: boolean;
|
|
2984
|
+
responseHeaders?: Record<string, string>;
|
|
2985
|
+
metadata?: Record<string, unknown>;
|
|
2986
|
+
retries?: number;
|
|
2987
|
+
[key: string]: unknown;
|
|
2988
|
+
};
|
|
2989
|
+
}
|
|
2990
|
+
interface SessionEvent {
|
|
2991
|
+
type: SessionEventType;
|
|
2992
|
+
properties: {
|
|
2993
|
+
sessionId?: string;
|
|
2994
|
+
info?: {
|
|
2995
|
+
id?: string;
|
|
2996
|
+
};
|
|
2997
|
+
part?: PartData;
|
|
2998
|
+
status?: {
|
|
2999
|
+
type?: string;
|
|
3000
|
+
};
|
|
3001
|
+
error?: SessionError;
|
|
3002
|
+
};
|
|
3003
|
+
}
|
|
3004
|
+
interface PartData {
|
|
3005
|
+
type: 'text' | 'reasoning' | 'tool' | 'step-start' | 'step-finish';
|
|
3006
|
+
text?: string;
|
|
3007
|
+
messageId?: string;
|
|
3008
|
+
time?: {
|
|
3009
|
+
start?: number;
|
|
3010
|
+
end?: number;
|
|
3011
|
+
};
|
|
3012
|
+
tool?: string;
|
|
3013
|
+
state?: {
|
|
3014
|
+
status?: 'running' | 'completed' | 'error';
|
|
3015
|
+
output?: unknown;
|
|
3016
|
+
error?: string;
|
|
3017
|
+
};
|
|
3018
|
+
tokens?: {
|
|
3019
|
+
input: number;
|
|
3020
|
+
output: number;
|
|
3021
|
+
reasoning: number;
|
|
3022
|
+
};
|
|
3023
|
+
}
|
|
3024
|
+
declare class SdkMessagetCollector {
|
|
3025
|
+
private filterConfig;
|
|
3026
|
+
events: SessionEvent[];
|
|
3027
|
+
isComplete: boolean;
|
|
3028
|
+
private hasTextEnd;
|
|
3029
|
+
private hasStepFinish;
|
|
3030
|
+
private error;
|
|
3031
|
+
private sessionStatus;
|
|
3032
|
+
private sessionId;
|
|
3033
|
+
private messageId;
|
|
3034
|
+
constructor(filterConfig?: AgentClientFilterConfig);
|
|
3035
|
+
addEvent(event: SessionEvent): void;
|
|
3036
|
+
private shouldIncludeEvent;
|
|
3037
|
+
private checkCompletion;
|
|
3038
|
+
checkComplete(): boolean;
|
|
3039
|
+
hasTextEndReady(): boolean;
|
|
3040
|
+
isTextOnlyComplete(): boolean;
|
|
3041
|
+
resetForNextMessage(): void;
|
|
3042
|
+
getCurrentMessageId(): string;
|
|
3043
|
+
assembleMessage(): AgentMessage;
|
|
3044
|
+
reset(): void;
|
|
3045
|
+
}
|
|
3046
|
+
|
|
3047
|
+
declare function setAgentAdapter(adapter: AgentAdapter | undefined): void;
|
|
2871
3048
|
declare function getAgentAdapter(): AgentAdapter | undefined;
|
|
2872
3049
|
declare function hasAgentAdapter(): boolean;
|
|
2873
3050
|
declare function requireAgentAdapter(): AgentAdapter;
|
|
@@ -2880,4 +3057,4 @@ declare function initLog(options: {
|
|
|
2880
3057
|
level?: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
|
|
2881
3058
|
}): Promise<void>;
|
|
2882
3059
|
|
|
2883
|
-
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
|
|
3060
|
+
export { type AgentClientFilterConfig, type AgentDeregisterMessage, type AgentHealthStatus, type AgentHeartbeat, type AgentHeartbeatSyncMessage, type AgentListRequestMessage, type AgentListResponseMessage, type AgentMessage, 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 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, type CreateSessionRequest, type CreateSessionResponse, DEBUG_AGENT_FILTER, DEFAULT_AGENT_FILTER, 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, type GatewayClientConfig, GatewayClientConfigSchema, 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 MessageHandler, type MessagePriority, type MessageQueueConfig, MessageQueueConfigSchema, type MessageRecord, MessageRouter, type MessageStatus, MessageStore, type MessageStoreConfig, type NostrBotConfig, type NostrChannelConfig, NostrChannelConfigSchema, NostrPlugin, type OAuth2AuthConfig, type PluginLoaderConfig, type PooledConnection, type PushEventType, type RouteResult, type RoutingConfig, SdkEventBridge, SdkEventBus, SdkEventType, SdkMessagetCollector, type SdkSessionStatusProps, type SendMessageRequest, type SendMessageResponse, type SerializableSession, type ServerConnectedMessage, type ServerErrorMessage, type ServerEventMessage, type ServerInterruptedMessage, type ServerMessage, type ServerMessageType, type ServerPongMessage, type ServerResponseMessage, type ServerStatusResponse, type ServerSubscribedMessage, type ServerSubscriptionReleasedMessage, type ServerUnsubscribedMessage, type SessionChannelInfo, type SessionConfig$1 as SessionConfig, SessionConfigSchema, type SessionContext, type SessionEventPayload, type SessionEventType$1 as 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, convertToGatewayMessage, createChannelPlugin, createDefaultSessionState, createGatewayMessage, createTextMessage, generateSessionId, generateSubscriptionId, getAgentAdapter, getAgentRegistryConfig, getAuthConfig, getChannelConfig, getCircuitBreakerConfig, getClusterConfig, getConfig, getConfigDirectory, getConnectionPoolConfig, getDefaultAgent, getGatewayClientConfig, getGatewayClientUrl, getHTTPSConfig, getLogLevel, getMessageQueueConfig, getServerConfig, getSessionConfig, getSupportedPlatforms, hasAgentAdapter, initLog, isConfigLoaded, loadConfig, parsePartialConfig, requireAgentAdapter, setAgentAdapter, validateConfig };
|