@easbot/gateway 0.2.40 → 0.2.42
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-4M2Z52JY.cjs +30 -0
- package/dist/chunks/chunk-BXHBTEOU.mjs +30 -0
- package/dist/chunks/server-E6BWQJZS.cjs +1 -0
- package/dist/chunks/server-YT53T4VR.mjs +1 -0
- package/dist/index.cjs +1 -2
- package/dist/index.d.cts +611 -262
- package/dist/index.d.ts +611 -262
- package/dist/index.mjs +1 -2
- package/package.json +5 -5
- package/dist/chunks/chunk-BVJ3UMFP.cjs +0 -26
- package/dist/chunks/chunk-SPCU5JL2.mjs +0 -26
- package/dist/chunks/server-D6N6P2NV.mjs +0 -1
- package/dist/chunks/server-JPVKX37A.cjs +0 -1
package/dist/index.d.ts
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 {
|
|
@@ -42,6 +43,7 @@ declare const ChannelTypeSchema: z.ZodEnum<{
|
|
|
42
43
|
webchat: "webchat";
|
|
43
44
|
signal: "signal";
|
|
44
45
|
nostr: "nostr";
|
|
46
|
+
dingtalk: "dingtalk";
|
|
45
47
|
}>;
|
|
46
48
|
type ChannelType = z.infer<typeof ChannelTypeSchema>;
|
|
47
49
|
declare const MessagePrioritySchema: z.ZodEnum<{
|
|
@@ -193,6 +195,20 @@ declare const ChannelConfigSchema: z.ZodObject<{
|
|
|
193
195
|
maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
194
196
|
timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
195
197
|
}, z.core.$strip>>;
|
|
198
|
+
dingtalk: z.ZodOptional<z.ZodObject<{
|
|
199
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
200
|
+
appKey: z.ZodString;
|
|
201
|
+
appSecret: z.ZodString;
|
|
202
|
+
token: z.ZodOptional<z.ZodString>;
|
|
203
|
+
encryptKey: z.ZodOptional<z.ZodString>;
|
|
204
|
+
webhook: z.ZodOptional<z.ZodObject<{
|
|
205
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
206
|
+
path: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
207
|
+
port: z.ZodOptional<z.ZodNumber>;
|
|
208
|
+
}, z.core.$strip>>;
|
|
209
|
+
maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
210
|
+
timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
211
|
+
}, z.core.$strip>>;
|
|
196
212
|
}, z.core.$strip>;
|
|
197
213
|
declare const HTTPSConfigSchema: z.ZodObject<{
|
|
198
214
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
@@ -426,6 +442,14 @@ declare const GatewayServerConfigSchema: z.ZodObject<{
|
|
|
426
442
|
mdnsDomain: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
427
443
|
}, z.core.$strip>;
|
|
428
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>;
|
|
429
453
|
declare const GatewayConfigSchema: z.ZodObject<{
|
|
430
454
|
server: z.ZodOptional<z.ZodObject<{
|
|
431
455
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
@@ -549,6 +573,20 @@ declare const GatewayConfigSchema: z.ZodObject<{
|
|
|
549
573
|
maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
550
574
|
timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
551
575
|
}, z.core.$strip>>;
|
|
576
|
+
dingtalk: z.ZodOptional<z.ZodObject<{
|
|
577
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
578
|
+
appKey: z.ZodString;
|
|
579
|
+
appSecret: z.ZodString;
|
|
580
|
+
token: z.ZodOptional<z.ZodString>;
|
|
581
|
+
encryptKey: z.ZodOptional<z.ZodString>;
|
|
582
|
+
webhook: z.ZodOptional<z.ZodObject<{
|
|
583
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
584
|
+
path: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
585
|
+
port: z.ZodOptional<z.ZodNumber>;
|
|
586
|
+
}, z.core.$strip>>;
|
|
587
|
+
maxConnections: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
588
|
+
timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
589
|
+
}, z.core.$strip>>;
|
|
552
590
|
}, z.core.$strip>>;
|
|
553
591
|
cluster: z.ZodOptional<z.ZodObject<{
|
|
554
592
|
nodeId: z.ZodString;
|
|
@@ -633,6 +671,13 @@ declare const GatewayConfigSchema: z.ZodObject<{
|
|
|
633
671
|
timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
634
672
|
retryOnFailure: z.ZodDefault<z.ZodBoolean>;
|
|
635
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>>;
|
|
636
681
|
defaultAgent: z.ZodOptional<z.ZodString>;
|
|
637
682
|
logLevel: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
638
683
|
DEBUG: "DEBUG";
|
|
@@ -657,6 +702,8 @@ declare function getMessageQueueConfig(): Promise<MessageQueueConfig>;
|
|
|
657
702
|
declare function getCircuitBreakerConfig(): Promise<CircuitBreakerConfig>;
|
|
658
703
|
declare function getAgentRegistryConfig(): Promise<AgentRegistryConfig>;
|
|
659
704
|
declare function getSessionConfig(): Promise<SessionConfig$1>;
|
|
705
|
+
declare function getGatewayClientConfig(): Promise<GatewayClientConfig | undefined>;
|
|
706
|
+
declare function getGatewayClientUrl(): Promise<string | undefined>;
|
|
660
707
|
declare function getHTTPSConfig(): Promise<HTTPSConfig | undefined>;
|
|
661
708
|
declare function getAuthConfig(): Promise<AuthConfig | undefined>;
|
|
662
709
|
declare function getClusterConfig(): Promise<GatewayConfig['cluster'] | undefined>;
|
|
@@ -705,6 +752,9 @@ interface ChannelCapabilities {
|
|
|
705
752
|
supportsHtml: boolean;
|
|
706
753
|
supportsDeliveryReceipt: boolean;
|
|
707
754
|
supportsReadReceipt: boolean;
|
|
755
|
+
supportsSlashCommands: boolean;
|
|
756
|
+
supportsNativeCommands: boolean;
|
|
757
|
+
commandPrefix: string;
|
|
708
758
|
maxMessageLength: number;
|
|
709
759
|
maxMediaCount: number;
|
|
710
760
|
}
|
|
@@ -738,9 +788,16 @@ interface ChannelPlugin {
|
|
|
738
788
|
getStatus(): ChannelStatus;
|
|
739
789
|
getCapabilities(): ChannelCapabilities;
|
|
740
790
|
}
|
|
791
|
+
interface SessionOperations {
|
|
792
|
+
getSession(sessionId: string): {
|
|
793
|
+
backendSessionId: string | null;
|
|
794
|
+
} | undefined;
|
|
795
|
+
unbindBackendSession(gatewaySessionId: string): Promise<void>;
|
|
796
|
+
}
|
|
741
797
|
interface MessageHandler {
|
|
742
798
|
onMessage(message: GatewayMessage): Promise<void>;
|
|
743
799
|
onEvent(event: ChannelEvent): Promise<void>;
|
|
800
|
+
session?: SessionOperations;
|
|
744
801
|
}
|
|
745
802
|
interface ChannelHealth {
|
|
746
803
|
healthy: boolean;
|
|
@@ -852,11 +909,10 @@ interface Subscriber {
|
|
|
852
909
|
id: string;
|
|
853
910
|
type: SubscriberType;
|
|
854
911
|
connection: SubscriberConnection;
|
|
855
|
-
sessions: Set<string>;
|
|
856
912
|
createdAt: number;
|
|
857
913
|
lastActiveAt: number;
|
|
858
914
|
}
|
|
859
|
-
type SubscriberType = 'subagent' | 'tui' | 'desktop' | 'browser' | 'mobile' | 'api';
|
|
915
|
+
type SubscriberType = 'subagent' | 'tui' | 'desktop' | 'browser' | 'mobile' | 'api' | 'acp';
|
|
860
916
|
interface SubscriberConnection {
|
|
861
917
|
send(message: GatewayMessage): Promise<void>;
|
|
862
918
|
close(): Promise<void>;
|
|
@@ -884,24 +940,17 @@ interface RouteResult {
|
|
|
884
940
|
declare function generateSubscriptionId(subscriberId: string, sessionId: string): string;
|
|
885
941
|
|
|
886
942
|
declare const DEFAULT_WEBSOCKET_SERVER_CONFIG: GatewayServerConfig;
|
|
887
|
-
type ClientMessageType = '
|
|
888
|
-
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';
|
|
889
945
|
interface WebSocketMessageBase {
|
|
890
946
|
type: ClientMessageType | ServerMessageType;
|
|
891
947
|
sessionId?: string;
|
|
892
948
|
}
|
|
893
|
-
interface ClientInitializeMessage extends WebSocketMessageBase {
|
|
894
|
-
type: 'initialize';
|
|
895
|
-
payload?: {
|
|
896
|
-
name?: string;
|
|
897
|
-
version?: string;
|
|
898
|
-
capabilities?: string[];
|
|
899
|
-
};
|
|
900
|
-
}
|
|
901
949
|
interface ClientSubscribeMessage extends WebSocketMessageBase {
|
|
902
950
|
type: 'subscribe';
|
|
903
951
|
sessionId: string;
|
|
904
952
|
backendSessionId?: string;
|
|
953
|
+
clientId?: string;
|
|
905
954
|
payload?: {
|
|
906
955
|
eventTypes?: string[];
|
|
907
956
|
};
|
|
@@ -943,8 +992,25 @@ interface ClientAgentListRequestMessage extends WebSocketMessageBase {
|
|
|
943
992
|
interface ClientAgentSubscribeMessage extends WebSocketMessageBase {
|
|
944
993
|
type: 'agent_subscribe';
|
|
945
994
|
subscribe: boolean;
|
|
995
|
+
clientId?: string;
|
|
946
996
|
}
|
|
947
|
-
|
|
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;
|
|
948
1014
|
interface ServerConnectedMessage extends WebSocketMessageBase {
|
|
949
1015
|
type: 'connected';
|
|
950
1016
|
clientId: string;
|
|
@@ -953,16 +1019,6 @@ interface ServerConnectedMessage extends WebSocketMessageBase {
|
|
|
953
1019
|
capabilities?: string[];
|
|
954
1020
|
};
|
|
955
1021
|
}
|
|
956
|
-
interface ServerInitializeResponseMessage extends WebSocketMessageBase {
|
|
957
|
-
type: 'initialize_response';
|
|
958
|
-
success: boolean;
|
|
959
|
-
result?: {
|
|
960
|
-
sessionId?: string;
|
|
961
|
-
capabilities?: string[];
|
|
962
|
-
[key: string]: unknown;
|
|
963
|
-
};
|
|
964
|
-
error?: string;
|
|
965
|
-
}
|
|
966
1022
|
interface ServerSubscribedMessage extends WebSocketMessageBase {
|
|
967
1023
|
type: 'subscribed';
|
|
968
1024
|
sessionId: string;
|
|
@@ -1001,13 +1057,6 @@ interface ServerInterruptedMessage extends WebSocketMessageBase {
|
|
|
1001
1057
|
success: boolean;
|
|
1002
1058
|
error?: string;
|
|
1003
1059
|
}
|
|
1004
|
-
interface ServerSessionClosedMessage extends WebSocketMessageBase {
|
|
1005
|
-
type: 'session_closed';
|
|
1006
|
-
sessionId: string;
|
|
1007
|
-
payload?: {
|
|
1008
|
-
reason?: string;
|
|
1009
|
-
};
|
|
1010
|
-
}
|
|
1011
1060
|
interface ServerSubscriptionReleasedMessage extends WebSocketMessageBase {
|
|
1012
1061
|
type: 'subscriptionReleased';
|
|
1013
1062
|
sessionId: string;
|
|
@@ -1040,7 +1089,29 @@ interface ServerAgentUpdateMessage extends WebSocketMessageBase {
|
|
|
1040
1089
|
metadata?: Record<string, unknown>;
|
|
1041
1090
|
};
|
|
1042
1091
|
}
|
|
1043
|
-
|
|
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;
|
|
1044
1115
|
type WebSocketMessage = ClientMessage | ServerMessage;
|
|
1045
1116
|
interface ClientSubscription {
|
|
1046
1117
|
clientId: string;
|
|
@@ -1063,9 +1134,9 @@ interface WebSocketConnectionInfo {
|
|
|
1063
1134
|
remoteAddress?: string;
|
|
1064
1135
|
authInfo?: ClientSubscription['authInfo'];
|
|
1065
1136
|
}
|
|
1066
|
-
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';
|
|
1067
1138
|
interface SessionEventPayload {
|
|
1068
|
-
type: SessionEventType | string;
|
|
1139
|
+
type: SessionEventType$1 | string;
|
|
1069
1140
|
sessionId: string;
|
|
1070
1141
|
properties: {
|
|
1071
1142
|
[key: string]: unknown;
|
|
@@ -1080,9 +1151,15 @@ interface ServerStatusResponse {
|
|
|
1080
1151
|
status: 'running' | 'stopping' | 'stopped';
|
|
1081
1152
|
connections: number;
|
|
1082
1153
|
sessions: number;
|
|
1083
|
-
|
|
1154
|
+
messageSubscriptions: number;
|
|
1155
|
+
agentSubscriptions: number;
|
|
1084
1156
|
uptime: number;
|
|
1085
1157
|
version?: string;
|
|
1158
|
+
agents?: {
|
|
1159
|
+
total: number;
|
|
1160
|
+
healthy: number;
|
|
1161
|
+
unhealthy: number;
|
|
1162
|
+
};
|
|
1086
1163
|
}
|
|
1087
1164
|
interface CreateSessionRequest {
|
|
1088
1165
|
title?: string;
|
|
@@ -1094,7 +1171,7 @@ interface CreateSessionRequest {
|
|
|
1094
1171
|
};
|
|
1095
1172
|
context?: Record<string, unknown>;
|
|
1096
1173
|
}
|
|
1097
|
-
interface CreateSessionResponse
|
|
1174
|
+
interface CreateSessionResponse {
|
|
1098
1175
|
id: string;
|
|
1099
1176
|
createdAt: number;
|
|
1100
1177
|
}
|
|
@@ -1109,7 +1186,7 @@ interface SendMessageRequest {
|
|
|
1109
1186
|
}>;
|
|
1110
1187
|
[key: string]: unknown;
|
|
1111
1188
|
}
|
|
1112
|
-
interface SendMessageResponse
|
|
1189
|
+
interface SendMessageResponse {
|
|
1113
1190
|
messageId: string;
|
|
1114
1191
|
sessionId: string;
|
|
1115
1192
|
createdAt: number;
|
|
@@ -1119,11 +1196,16 @@ interface SendMessageResponse$1 {
|
|
|
1119
1196
|
channelInfo?: ChannelInfo;
|
|
1120
1197
|
};
|
|
1121
1198
|
}
|
|
1199
|
+
type SubscriptionType = 'message' | 'agent';
|
|
1122
1200
|
interface SubscriptionsResponse {
|
|
1123
1201
|
subscriptions: Array<{
|
|
1202
|
+
type: SubscriptionType;
|
|
1124
1203
|
sessionId: string;
|
|
1125
1204
|
subscriberCount: number;
|
|
1126
|
-
subscribers:
|
|
1205
|
+
subscribers: Array<{
|
|
1206
|
+
id: string;
|
|
1207
|
+
subscriptionId: string;
|
|
1208
|
+
}>;
|
|
1127
1209
|
}>;
|
|
1128
1210
|
total: number;
|
|
1129
1211
|
}
|
|
@@ -1171,10 +1253,10 @@ interface AgentRegistration {
|
|
|
1171
1253
|
}
|
|
1172
1254
|
type AgentRegistrationRequest = Omit<AgentRegistration, 'registeredAt' | 'lastHeartbeat' | 'connectionCount' | 'status'>;
|
|
1173
1255
|
declare const DEFAULT_AGENT_REGISTRY_CONFIG: {
|
|
1174
|
-
readonly heartbeatInterval:
|
|
1175
|
-
readonly heartbeatTimeout:
|
|
1176
|
-
readonly heartbeatCheckInterval:
|
|
1177
|
-
readonly autoDeregisterTimeout:
|
|
1256
|
+
readonly heartbeatInterval: 60000;
|
|
1257
|
+
readonly heartbeatTimeout: 300000;
|
|
1258
|
+
readonly heartbeatCheckInterval: 300000;
|
|
1259
|
+
readonly autoDeregisterTimeout: 600000;
|
|
1178
1260
|
readonly maxAgents: 100;
|
|
1179
1261
|
readonly maxRegistrations: 1000;
|
|
1180
1262
|
};
|
|
@@ -1319,12 +1401,12 @@ declare const DEFAULT_CONNECTION_POOL_CONFIG: {
|
|
|
1319
1401
|
acquireTimeout: number;
|
|
1320
1402
|
warmupCount: number;
|
|
1321
1403
|
};
|
|
1322
|
-
type ConnectionState
|
|
1404
|
+
type ConnectionState = 'idle' | 'active' | 'unhealthy' | 'closed';
|
|
1323
1405
|
interface PooledConnection<T = unknown> {
|
|
1324
1406
|
id: string;
|
|
1325
1407
|
channelId: string;
|
|
1326
1408
|
connection: T;
|
|
1327
|
-
state: ConnectionState
|
|
1409
|
+
state: ConnectionState;
|
|
1328
1410
|
lastActivity: number;
|
|
1329
1411
|
createdAt: number;
|
|
1330
1412
|
useCount: number;
|
|
@@ -1358,21 +1440,30 @@ interface CancelEvent {
|
|
|
1358
1440
|
timestamp: number;
|
|
1359
1441
|
}
|
|
1360
1442
|
type CancelEventHandler = (event: CancelEvent) => void | Promise<void>;
|
|
1443
|
+
interface RouterSessionManager {
|
|
1444
|
+
get(sessionId: string): {
|
|
1445
|
+
backendSessionId?: string | null;
|
|
1446
|
+
} | undefined;
|
|
1447
|
+
bindBackendSession(gatewaySessionId: string, backendSessionId: string): Promise<void>;
|
|
1448
|
+
}
|
|
1361
1449
|
declare class MessageRouter {
|
|
1362
1450
|
private log;
|
|
1363
1451
|
private subscribers;
|
|
1364
1452
|
private subscriptions;
|
|
1365
|
-
private
|
|
1453
|
+
private messageSubscriptions;
|
|
1366
1454
|
private channelPlugins;
|
|
1367
1455
|
private cancelHandlers;
|
|
1368
1456
|
private processingMessages;
|
|
1369
1457
|
private hookRegistry;
|
|
1370
|
-
|
|
1458
|
+
private sessionManager;
|
|
1459
|
+
constructor(hookRegistry?: typeof this.hookRegistry, sessionManager?: RouterSessionManager);
|
|
1460
|
+
setSessionManager(sessionManager: RouterSessionManager): void;
|
|
1371
1461
|
private triggerHook;
|
|
1372
1462
|
private triggerBeforeSend;
|
|
1373
1463
|
onCancel(handler: CancelEventHandler): void;
|
|
1374
1464
|
offCancel(handler: CancelEventHandler): void;
|
|
1375
1465
|
private emitCancel;
|
|
1466
|
+
private selectSubscriber;
|
|
1376
1467
|
route(message: GatewayMessage): Promise<RouteResult>;
|
|
1377
1468
|
completeMessage(sessionId: string, messageId: string, subscriberId: string, reason?: 'completed' | 'failed' | 'timeout'): Promise<void>;
|
|
1378
1469
|
subscribe(sessionId: string, subscriber: Subscriber): Promise<Subscription>;
|
|
@@ -1382,6 +1473,7 @@ declare class MessageRouter {
|
|
|
1382
1473
|
unregisterChannel(pluginId: string): void;
|
|
1383
1474
|
getSubscriber(subscriberId: string): Subscriber | undefined;
|
|
1384
1475
|
getSubscription(subscriptionId: string): Subscription | undefined;
|
|
1476
|
+
getMessageSubscriptions(): Map<string, Set<string>>;
|
|
1385
1477
|
getSubscriberCount(sessionId: string): number;
|
|
1386
1478
|
getStats(): {
|
|
1387
1479
|
subscribers: number;
|
|
@@ -1411,6 +1503,7 @@ declare class GatewaySessionManager {
|
|
|
1411
1503
|
closeById(sessionId: string): Promise<void>;
|
|
1412
1504
|
bindBackendSession(gatewaySessionId: string, backendSessionId: string): Promise<void>;
|
|
1413
1505
|
unbindBackendSession(gatewaySessionId: string): Promise<void>;
|
|
1506
|
+
findByBackendSessionId(backendSessionId: string): GatewaySession | undefined;
|
|
1414
1507
|
getState(sessionId: string): SessionState | undefined;
|
|
1415
1508
|
incrementMessageCountOrCreate(sessionId: string, channelInfo?: SessionChannelInfo): Promise<GatewaySession>;
|
|
1416
1509
|
incrementMessageCount(sessionId: string): Promise<void>;
|
|
@@ -1429,15 +1522,28 @@ declare class GatewaySessionManager {
|
|
|
1429
1522
|
};
|
|
1430
1523
|
}
|
|
1431
1524
|
|
|
1525
|
+
type AgentEventType = 'register' | 'deregister' | 'heartbeat' | 'status_change';
|
|
1526
|
+
interface AgentEvent {
|
|
1527
|
+
type: AgentEventType;
|
|
1528
|
+
agent: AgentRegistration;
|
|
1529
|
+
oldStatus?: AgentHealthStatus;
|
|
1530
|
+
}
|
|
1531
|
+
type AgentEventCallback = (event: AgentEvent) => void | Promise<void>;
|
|
1432
1532
|
declare class AgentRegistry {
|
|
1433
1533
|
private config;
|
|
1434
1534
|
private agents;
|
|
1435
1535
|
private heartbeatTimer;
|
|
1436
1536
|
private roundRobinIndex;
|
|
1437
|
-
|
|
1537
|
+
private store;
|
|
1538
|
+
private eventCallbacks;
|
|
1539
|
+
constructor(config?: Partial<AgentRegistryConfig & {
|
|
1540
|
+
dataDir?: string;
|
|
1541
|
+
}>);
|
|
1542
|
+
load(): Promise<void>;
|
|
1438
1543
|
register(agent: AgentRegistrationRequest): Promise<void>;
|
|
1439
1544
|
deregister(agentId: string): Promise<void>;
|
|
1440
1545
|
heartbeat(agentId: string, metrics?: AgentRegistration['metadata']): Promise<void>;
|
|
1546
|
+
setStatus(agentId: string, status: AgentHealthStatus): void;
|
|
1441
1547
|
getAgent(agentId: string): AgentRegistration | undefined;
|
|
1442
1548
|
getAllAgents(): AgentRegistration[];
|
|
1443
1549
|
getHealthyAgents(): AgentRegistration[];
|
|
@@ -1447,6 +1553,9 @@ declare class AgentRegistry {
|
|
|
1447
1553
|
startHeartbeatCheck(): void;
|
|
1448
1554
|
stopHeartbeatCheck(): void;
|
|
1449
1555
|
private checkHeartbeats;
|
|
1556
|
+
onEvent(callback: AgentEventCallback): void;
|
|
1557
|
+
offEvent(callback: AgentEventCallback): void;
|
|
1558
|
+
private emitEvent;
|
|
1450
1559
|
private selectRandom;
|
|
1451
1560
|
private selectRoundRobin;
|
|
1452
1561
|
private selectLeastConnections;
|
|
@@ -1455,15 +1564,21 @@ declare class AgentRegistry {
|
|
|
1455
1564
|
setLastHeartbeat(agentId: string, timestamp: number): void;
|
|
1456
1565
|
}
|
|
1457
1566
|
|
|
1567
|
+
type AgentListChangeCallback = (agents: AgentSyncInfo[], action: 'add' | 'update' | 'remove', agent: AgentSyncInfo) => void | Promise<void>;
|
|
1458
1568
|
declare class AgentSyncManager {
|
|
1459
1569
|
private config;
|
|
1570
|
+
private internalConfig;
|
|
1460
1571
|
private registry;
|
|
1461
1572
|
private localNodeId;
|
|
1462
1573
|
private localNodeName;
|
|
1463
1574
|
private remoteNodes;
|
|
1464
1575
|
private remoteAgents;
|
|
1465
1576
|
private syncTimer;
|
|
1577
|
+
private cleanupTimer;
|
|
1578
|
+
private reconnectTimer;
|
|
1579
|
+
private heartbeatTimer;
|
|
1466
1580
|
private running;
|
|
1581
|
+
private agentListChangeCallbacks;
|
|
1467
1582
|
constructor(options: {
|
|
1468
1583
|
registry: AgentRegistry;
|
|
1469
1584
|
localNodeId: string;
|
|
@@ -1474,6 +1589,7 @@ declare class AgentSyncManager {
|
|
|
1474
1589
|
stop(): Promise<void>;
|
|
1475
1590
|
private pullFromAllNodes;
|
|
1476
1591
|
pullFromNode(nodeId: string): Promise<AgentSyncInfo[]>;
|
|
1592
|
+
private calculateRetryDelay;
|
|
1477
1593
|
pushEvent(message: SyncMessage): Promise<void>;
|
|
1478
1594
|
pushToNode(nodeId: string, message: SyncMessage): Promise<void>;
|
|
1479
1595
|
handleSyncMessage(message: SyncMessage): Promise<void>;
|
|
@@ -1483,8 +1599,16 @@ declare class AgentSyncManager {
|
|
|
1483
1599
|
private handleAgentDeregister;
|
|
1484
1600
|
private handleAgentHeartbeat;
|
|
1485
1601
|
private handleAgentStatusChange;
|
|
1602
|
+
private cleanupStaleAgents;
|
|
1603
|
+
private reconnectFailedNodes;
|
|
1604
|
+
private checkNodeHealth;
|
|
1605
|
+
private handleLocalAgentEvent;
|
|
1606
|
+
private agentToSyncInfo;
|
|
1486
1607
|
private resolveConflict;
|
|
1487
1608
|
private getLocalAgentsForSync;
|
|
1609
|
+
private notifyAgentListChange;
|
|
1610
|
+
onAgentListChange(callback: AgentListChangeCallback): void;
|
|
1611
|
+
offAgentListChange(callback: AgentListChangeCallback): void;
|
|
1488
1612
|
getMergedAgentList(): AgentSyncInfo[];
|
|
1489
1613
|
getRemoteAgents(): AgentSyncInfo[];
|
|
1490
1614
|
getStats(): SyncStats;
|
|
@@ -1532,6 +1656,11 @@ declare namespace Log {
|
|
|
1532
1656
|
function create(tags?: Record<string, any>): Logger;
|
|
1533
1657
|
}
|
|
1534
1658
|
|
|
1659
|
+
interface LocalCommandResult {
|
|
1660
|
+
handled: boolean;
|
|
1661
|
+
reply?: string;
|
|
1662
|
+
continueProcessing?: boolean;
|
|
1663
|
+
}
|
|
1535
1664
|
declare abstract class BaseChannelPlugin implements ChannelPlugin {
|
|
1536
1665
|
abstract readonly id: string;
|
|
1537
1666
|
abstract readonly platform: PlatformType;
|
|
@@ -1562,12 +1691,12 @@ declare abstract class BaseChannelPlugin implements ChannelPlugin {
|
|
|
1562
1691
|
protected buildSessionId(channelId: string, chatId: string, userId?: string): string;
|
|
1563
1692
|
protected handleMessage(message: GatewayMessage): Promise<void>;
|
|
1564
1693
|
protected handleEvent(type: string, data?: unknown): Promise<void>;
|
|
1565
|
-
protected getCommandList(): Promise<
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1694
|
+
protected getCommandList(): Promise<Command[]>;
|
|
1695
|
+
protected processLocalCommand(command: string, sessionId: string, chatId: string): Promise<LocalCommandResult>;
|
|
1696
|
+
private handleNewCommand;
|
|
1697
|
+
private handleStatusCommand;
|
|
1698
|
+
private formatStatusReport;
|
|
1699
|
+
private formatUptime;
|
|
1571
1700
|
}
|
|
1572
1701
|
|
|
1573
1702
|
interface PluginLoaderConfig {
|
|
@@ -1589,6 +1718,7 @@ declare class ChannelPluginLoader {
|
|
|
1589
1718
|
private backoffPolicy;
|
|
1590
1719
|
constructor(config?: PluginLoaderConfig);
|
|
1591
1720
|
setMessageHandler(handler: MessageHandler): void;
|
|
1721
|
+
updateSessionHandler(session: NonNullable<MessageHandler['session']>): void;
|
|
1592
1722
|
register(plugin: ChannelPlugin, config: ChannelConfig): Promise<void>;
|
|
1593
1723
|
unregister(pluginId: string): Promise<void>;
|
|
1594
1724
|
start(pluginId: string): Promise<void>;
|
|
@@ -1769,6 +1899,7 @@ interface ResolveChannelParams {
|
|
|
1769
1899
|
get(sessionId: string): GatewaySession | undefined;
|
|
1770
1900
|
getOrCreate(channelInfo: SessionChannelInfo, context?: Record<string, unknown>): Promise<GatewaySession>;
|
|
1771
1901
|
bindBackendSession(gatewaySessionId: string, backendSessionId: string): Promise<void>;
|
|
1902
|
+
findByBackendSessionId(backendSessionId: string): GatewaySession | undefined;
|
|
1772
1903
|
getAll?(): GatewaySession[];
|
|
1773
1904
|
};
|
|
1774
1905
|
pluginLoader?: {
|
|
@@ -1818,6 +1949,38 @@ interface ResolveChannelParams {
|
|
|
1818
1949
|
};
|
|
1819
1950
|
}
|
|
1820
1951
|
|
|
1952
|
+
declare class WebSocketServerAgentSync {
|
|
1953
|
+
private wsServer;
|
|
1954
|
+
private syncManager;
|
|
1955
|
+
private gatewayId;
|
|
1956
|
+
private subscribers;
|
|
1957
|
+
private getClientWs;
|
|
1958
|
+
constructor(options: {
|
|
1959
|
+
wsServer: GatewayWebSocketServer;
|
|
1960
|
+
syncManager: AgentSyncManager;
|
|
1961
|
+
getClientWs: (clientId: string) => WSContext | undefined;
|
|
1962
|
+
});
|
|
1963
|
+
handleAgentListRequest(clientId: string, requestId: string): Promise<void>;
|
|
1964
|
+
handleAgentSubscribe(clientId: string, subscribe: boolean): Promise<void>;
|
|
1965
|
+
broadcastAgentUpdate(action: 'add' | 'update' | 'remove', agent: AgentSyncInfo): void;
|
|
1966
|
+
broadcastAgentList(): void;
|
|
1967
|
+
cleanupClientSubscription(clientId: string): void;
|
|
1968
|
+
getSubscriberCount(): number;
|
|
1969
|
+
getSubscribers(): string[];
|
|
1970
|
+
private sendMessage;
|
|
1971
|
+
handleAgentRegister(clientId: string, payload: {
|
|
1972
|
+
agentId: string;
|
|
1973
|
+
name: string;
|
|
1974
|
+
address: string;
|
|
1975
|
+
capabilities?: string[];
|
|
1976
|
+
metadata?: Record<string, unknown>;
|
|
1977
|
+
}): Promise<void>;
|
|
1978
|
+
handleAgentDeregister(clientId: string, payload: {
|
|
1979
|
+
agentId: string;
|
|
1980
|
+
}): Promise<void>;
|
|
1981
|
+
cleanupClient(clientId: string): Promise<void>;
|
|
1982
|
+
}
|
|
1983
|
+
|
|
1821
1984
|
type MessageSender = (pluginId: string, message: GatewayMessage, options?: SendOptions) => Promise<string>;
|
|
1822
1985
|
interface SendOptions extends Record<string, unknown> {
|
|
1823
1986
|
}
|
|
@@ -1829,8 +1992,7 @@ declare class GatewayWebSocketServer {
|
|
|
1829
1992
|
private httpRedirectServer;
|
|
1830
1993
|
private connections;
|
|
1831
1994
|
private subscriptions;
|
|
1832
|
-
private
|
|
1833
|
-
private sessionLastActivity;
|
|
1995
|
+
private clientLastActivity;
|
|
1834
1996
|
private cleanupInterval;
|
|
1835
1997
|
private heartbeatInterval;
|
|
1836
1998
|
private startTime;
|
|
@@ -1840,6 +2002,20 @@ declare class GatewayWebSocketServer {
|
|
|
1840
2002
|
setChannelResolveDeps(params: ResolveChannelParams): void;
|
|
1841
2003
|
private pluginLoaderRef;
|
|
1842
2004
|
setPluginLoader(sender: MessageSender): void;
|
|
2005
|
+
private agentSyncRef;
|
|
2006
|
+
getGatewayId(): string;
|
|
2007
|
+
setAgentSync(agentSync: WebSocketServerAgentSync): void;
|
|
2008
|
+
private agentRegistryRef;
|
|
2009
|
+
setAgentRegistry(registry: {
|
|
2010
|
+
getStats(): {
|
|
2011
|
+
totalAgents: number;
|
|
2012
|
+
healthyAgents: number;
|
|
2013
|
+
unhealthyAgents: number;
|
|
2014
|
+
};
|
|
2015
|
+
}): void;
|
|
2016
|
+
private routerRef;
|
|
2017
|
+
setRouter(router: MessageRouter): void;
|
|
2018
|
+
private subscribers;
|
|
1843
2019
|
private getChannelResolveParams;
|
|
1844
2020
|
start(): Promise<void>;
|
|
1845
2021
|
private startHTTPServer;
|
|
@@ -1848,27 +2024,32 @@ declare class GatewayWebSocketServer {
|
|
|
1848
2024
|
private setupWebSocketUpgrade;
|
|
1849
2025
|
private startHTTPRedirectServer;
|
|
1850
2026
|
stop(): Promise<void>;
|
|
1851
|
-
|
|
2027
|
+
private touchClient;
|
|
1852
2028
|
getConnectionCount(): number;
|
|
2029
|
+
getStartTime(): number;
|
|
1853
2030
|
getSubscriptionCount(): number;
|
|
1854
2031
|
getConnectionInfos(): WebSocketConnectionInfo[];
|
|
1855
2032
|
isRunning(): boolean;
|
|
1856
2033
|
private handleConnection;
|
|
1857
2034
|
private handleDisconnection;
|
|
2035
|
+
private cleanupClientResources;
|
|
1858
2036
|
private handleMessage;
|
|
1859
|
-
private handleInitialize;
|
|
1860
2037
|
private handleSubscribe;
|
|
1861
2038
|
private handleUnsubscribe;
|
|
1862
2039
|
private handleMessageRequest;
|
|
2040
|
+
private getClientIdByWs;
|
|
2041
|
+
getClientWs(clientId: string): WSContext | undefined;
|
|
1863
2042
|
private handleInterrupt;
|
|
1864
2043
|
private handleReleaseSubscription;
|
|
1865
|
-
private touchSession;
|
|
1866
2044
|
private checkConnectionTimeout;
|
|
1867
|
-
private
|
|
1868
|
-
private releaseSessionResources;
|
|
2045
|
+
private cleanupInactiveClients;
|
|
1869
2046
|
private sendMessage;
|
|
1870
2047
|
private sendError;
|
|
1871
2048
|
private createRoutes;
|
|
2049
|
+
private handleAgentListRequest;
|
|
2050
|
+
private handleAgentSubscribe;
|
|
2051
|
+
private handleAgentRegister;
|
|
2052
|
+
private handleAgentDeregister;
|
|
1872
2053
|
}
|
|
1873
2054
|
|
|
1874
2055
|
declare class GatewayServer implements IGatewayServer {
|
|
@@ -1882,6 +2063,9 @@ declare class GatewayServer implements IGatewayServer {
|
|
|
1882
2063
|
private messageStore;
|
|
1883
2064
|
private contactStore;
|
|
1884
2065
|
private wsServer;
|
|
2066
|
+
private agentRegistry;
|
|
2067
|
+
private agentSyncManager;
|
|
2068
|
+
private wsAgentSync;
|
|
1885
2069
|
private running;
|
|
1886
2070
|
private connections;
|
|
1887
2071
|
private gatewayAgent;
|
|
@@ -1894,6 +2078,11 @@ declare class GatewayServer implements IGatewayServer {
|
|
|
1894
2078
|
port?: number;
|
|
1895
2079
|
hostname?: string;
|
|
1896
2080
|
connections?: number;
|
|
2081
|
+
agents?: {
|
|
2082
|
+
total: number;
|
|
2083
|
+
healthy: number;
|
|
2084
|
+
unhealthy: number;
|
|
2085
|
+
};
|
|
1897
2086
|
};
|
|
1898
2087
|
onMessage(message: GatewayMessage): Promise<void>;
|
|
1899
2088
|
private saveContactFromMessage;
|
|
@@ -1925,184 +2114,6 @@ declare class GatewayServer implements IGatewayServer {
|
|
|
1925
2114
|
getMessageHistory(sessionId: string, limit?: number): Promise<MessageRecord[]>;
|
|
1926
2115
|
}
|
|
1927
2116
|
|
|
1928
|
-
interface GatewayClientConfig {
|
|
1929
|
-
url: string;
|
|
1930
|
-
type: SubscriberType;
|
|
1931
|
-
id?: string;
|
|
1932
|
-
reconnect?: {
|
|
1933
|
-
enabled: boolean;
|
|
1934
|
-
maxAttempts: number;
|
|
1935
|
-
delay: number;
|
|
1936
|
-
};
|
|
1937
|
-
heartbeat?: {
|
|
1938
|
-
enabled: boolean;
|
|
1939
|
-
interval: number;
|
|
1940
|
-
};
|
|
1941
|
-
}
|
|
1942
|
-
type MessageCallback = (message: GatewayMessage) => void | Promise<void>;
|
|
1943
|
-
type AgentListChangeCallback = (agents: AgentSyncInfo[]) => void | Promise<void>;
|
|
1944
|
-
interface HealthResponse {
|
|
1945
|
-
status: string;
|
|
1946
|
-
timestamp: number;
|
|
1947
|
-
version: string;
|
|
1948
|
-
}
|
|
1949
|
-
interface StatusResponse {
|
|
1950
|
-
status: string;
|
|
1951
|
-
connections: number;
|
|
1952
|
-
sessions: number;
|
|
1953
|
-
subscriptions: number;
|
|
1954
|
-
uptime: number;
|
|
1955
|
-
version: string;
|
|
1956
|
-
}
|
|
1957
|
-
interface ContactInfo {
|
|
1958
|
-
uid: string;
|
|
1959
|
-
platform: string;
|
|
1960
|
-
stableId: string;
|
|
1961
|
-
profile: {
|
|
1962
|
-
displayName?: string;
|
|
1963
|
-
username?: string;
|
|
1964
|
-
};
|
|
1965
|
-
lastSeenAt: number;
|
|
1966
|
-
createdAt: number;
|
|
1967
|
-
}
|
|
1968
|
-
interface ContactListResponse {
|
|
1969
|
-
contacts: ContactInfo[];
|
|
1970
|
-
total: number;
|
|
1971
|
-
hasMore: boolean;
|
|
1972
|
-
}
|
|
1973
|
-
interface SessionInfo {
|
|
1974
|
-
id: string;
|
|
1975
|
-
platform?: string;
|
|
1976
|
-
channelId?: string;
|
|
1977
|
-
userId?: string;
|
|
1978
|
-
chatId?: string;
|
|
1979
|
-
chatType?: string;
|
|
1980
|
-
chatTitle?: string;
|
|
1981
|
-
state: string;
|
|
1982
|
-
createdAt: number;
|
|
1983
|
-
lastActiveAt: number;
|
|
1984
|
-
}
|
|
1985
|
-
interface SessionListResponse {
|
|
1986
|
-
sessions: SessionInfo[];
|
|
1987
|
-
total: number;
|
|
1988
|
-
hasMore: boolean;
|
|
1989
|
-
}
|
|
1990
|
-
interface CreateSessionResponse {
|
|
1991
|
-
id: string;
|
|
1992
|
-
createdAt: number;
|
|
1993
|
-
}
|
|
1994
|
-
interface SendMessageResponse {
|
|
1995
|
-
success: boolean;
|
|
1996
|
-
messageId?: string;
|
|
1997
|
-
}
|
|
1998
|
-
type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting';
|
|
1999
|
-
interface AgentListMergeOptions {
|
|
2000
|
-
localAgents?: AgentSyncInfo[];
|
|
2001
|
-
preferLocal?: boolean;
|
|
2002
|
-
filterOffline?: boolean;
|
|
2003
|
-
}
|
|
2004
|
-
declare class GatewayClient {
|
|
2005
|
-
private log;
|
|
2006
|
-
private config;
|
|
2007
|
-
private ws;
|
|
2008
|
-
private state;
|
|
2009
|
-
private subscriptions;
|
|
2010
|
-
private messageCallbacks;
|
|
2011
|
-
private agentListCallbacks;
|
|
2012
|
-
private cachedAgentList;
|
|
2013
|
-
private localAgentList;
|
|
2014
|
-
private reconnectAttempts;
|
|
2015
|
-
private reconnectTimer;
|
|
2016
|
-
private heartbeatTimer;
|
|
2017
|
-
private agentListRequestId;
|
|
2018
|
-
private agentListRequestResolve;
|
|
2019
|
-
constructor(config: GatewayClientConfig);
|
|
2020
|
-
connect(): Promise<void>;
|
|
2021
|
-
disconnect(): Promise<void>;
|
|
2022
|
-
subscribe(sessionId: string, backendSessionId?: string): Promise<void>;
|
|
2023
|
-
unsubscribe(sessionId: string): Promise<void>;
|
|
2024
|
-
send(message: GatewayMessage): Promise<void>;
|
|
2025
|
-
onMessage(callback: MessageCallback): void;
|
|
2026
|
-
offMessage(callback: MessageCallback): void;
|
|
2027
|
-
getState(): ConnectionState;
|
|
2028
|
-
getId(): string;
|
|
2029
|
-
getSubscriptions(): string[];
|
|
2030
|
-
setLocalAgents(agents: AgentSyncInfo[]): void;
|
|
2031
|
-
fetchAgentList(): Promise<AgentSyncInfo[]>;
|
|
2032
|
-
getConnectableAgents(options?: AgentListMergeOptions): AgentSyncInfo[];
|
|
2033
|
-
onAgentListChange(callback: AgentListChangeCallback): void;
|
|
2034
|
-
offAgentListChange(callback: AgentListChangeCallback): void;
|
|
2035
|
-
private mergeAgentLists;
|
|
2036
|
-
private updateMergedAgentList;
|
|
2037
|
-
private handleAgentListResponse;
|
|
2038
|
-
private sendData;
|
|
2039
|
-
private handleMessage;
|
|
2040
|
-
private handleAgentUpdate;
|
|
2041
|
-
private handleGatewayMessage;
|
|
2042
|
-
private handleClose;
|
|
2043
|
-
private scheduleReconnect;
|
|
2044
|
-
private stopReconnect;
|
|
2045
|
-
private startHeartbeat;
|
|
2046
|
-
private stopHeartbeat;
|
|
2047
|
-
private resubscribeAll;
|
|
2048
|
-
private getHttpUrl;
|
|
2049
|
-
private httpRequest;
|
|
2050
|
-
healthCheck(): Promise<HealthResponse>;
|
|
2051
|
-
getStatus(): Promise<StatusResponse>;
|
|
2052
|
-
listChannels(): Promise<ChannelListResponse>;
|
|
2053
|
-
listContacts(platform: string, options?: {
|
|
2054
|
-
limit?: number;
|
|
2055
|
-
offset?: number;
|
|
2056
|
-
}): Promise<ContactListResponse>;
|
|
2057
|
-
getContact(uid: string): Promise<ContactInfo & {
|
|
2058
|
-
aliases?: Record<string, unknown>;
|
|
2059
|
-
}>;
|
|
2060
|
-
getSession(sessionId: string): Promise<SessionInfo & {
|
|
2061
|
-
subscriberCount?: number;
|
|
2062
|
-
}>;
|
|
2063
|
-
createSession(params?: {
|
|
2064
|
-
title?: string;
|
|
2065
|
-
channel?: {
|
|
2066
|
-
platform?: string;
|
|
2067
|
-
channelId?: string;
|
|
2068
|
-
userId?: string;
|
|
2069
|
-
chatId?: string;
|
|
2070
|
-
};
|
|
2071
|
-
}): Promise<CreateSessionResponse>;
|
|
2072
|
-
getOrCreateSession(options: {
|
|
2073
|
-
sessionId?: string;
|
|
2074
|
-
channel?: string;
|
|
2075
|
-
userId?: string;
|
|
2076
|
-
chatId?: string;
|
|
2077
|
-
platform?: string;
|
|
2078
|
-
}): Promise<{
|
|
2079
|
-
sessionId: string;
|
|
2080
|
-
created: boolean;
|
|
2081
|
-
}>;
|
|
2082
|
-
listSessions(options?: {
|
|
2083
|
-
limit?: number;
|
|
2084
|
-
offset?: number;
|
|
2085
|
-
platform?: string;
|
|
2086
|
-
channelId?: string;
|
|
2087
|
-
userId?: string;
|
|
2088
|
-
chatId?: string;
|
|
2089
|
-
}): Promise<SessionListResponse>;
|
|
2090
|
-
sendMessage(sessionId: string, message: {
|
|
2091
|
-
content: Array<{
|
|
2092
|
-
type: string;
|
|
2093
|
-
text?: string;
|
|
2094
|
-
image?: string;
|
|
2095
|
-
data?: string;
|
|
2096
|
-
}>;
|
|
2097
|
-
channel?: string;
|
|
2098
|
-
userId?: string;
|
|
2099
|
-
chatId?: string;
|
|
2100
|
-
messageType?: string;
|
|
2101
|
-
processorId?: string;
|
|
2102
|
-
agent?: string;
|
|
2103
|
-
}): Promise<SendMessageResponse>;
|
|
2104
|
-
}
|
|
2105
|
-
|
|
2106
2117
|
interface TelegramBotConfig {
|
|
2107
2118
|
botToken: string;
|
|
2108
2119
|
webhook?: {
|
|
@@ -2195,6 +2206,9 @@ declare class TelegramPlugin extends BaseChannelPlugin {
|
|
|
2195
2206
|
supportsHtml: boolean;
|
|
2196
2207
|
supportsDeliveryReceipt: boolean;
|
|
2197
2208
|
supportsReadReceipt: boolean;
|
|
2209
|
+
supportsSlashCommands: boolean;
|
|
2210
|
+
supportsNativeCommands: boolean;
|
|
2211
|
+
commandPrefix: string;
|
|
2198
2212
|
maxMessageLength: number;
|
|
2199
2213
|
maxMediaCount: number;
|
|
2200
2214
|
};
|
|
@@ -2232,13 +2246,39 @@ interface DiscordBotConfig {
|
|
|
2232
2246
|
applicationId?: string;
|
|
2233
2247
|
gateway?: {
|
|
2234
2248
|
enabled: boolean;
|
|
2235
|
-
intents
|
|
2249
|
+
intents?: number[];
|
|
2236
2250
|
};
|
|
2237
2251
|
webhook?: {
|
|
2238
2252
|
enabled: boolean;
|
|
2239
2253
|
path: string;
|
|
2240
2254
|
port?: number;
|
|
2241
2255
|
};
|
|
2256
|
+
commands?: DiscordCommand[];
|
|
2257
|
+
retry?: {
|
|
2258
|
+
maxAttempts?: number;
|
|
2259
|
+
initialDelay?: number;
|
|
2260
|
+
maxDelay?: number;
|
|
2261
|
+
};
|
|
2262
|
+
}
|
|
2263
|
+
interface DiscordCommand {
|
|
2264
|
+
name: string;
|
|
2265
|
+
description: string;
|
|
2266
|
+
options?: Array<{
|
|
2267
|
+
name: string;
|
|
2268
|
+
description: string;
|
|
2269
|
+
type: number;
|
|
2270
|
+
required?: boolean;
|
|
2271
|
+
}>;
|
|
2272
|
+
handler: (ctx: DiscordCommandContext) => Promise<void>;
|
|
2273
|
+
}
|
|
2274
|
+
interface DiscordCommandContext {
|
|
2275
|
+
userId: string;
|
|
2276
|
+
guildId?: string;
|
|
2277
|
+
channelId: string;
|
|
2278
|
+
messageId: string;
|
|
2279
|
+
commandName: string;
|
|
2280
|
+
options: Record<string, unknown>;
|
|
2281
|
+
reply?: (text: string) => Promise<string>;
|
|
2242
2282
|
}
|
|
2243
2283
|
declare class DiscordPlugin extends BaseChannelPlugin {
|
|
2244
2284
|
readonly id: string;
|
|
@@ -2251,12 +2291,20 @@ declare class DiscordPlugin extends BaseChannelPlugin {
|
|
|
2251
2291
|
private sessionId;
|
|
2252
2292
|
private sequenceNumber;
|
|
2253
2293
|
private abortController;
|
|
2294
|
+
private processedMessageIds;
|
|
2295
|
+
private sentMessages;
|
|
2296
|
+
private sessionIdMap;
|
|
2297
|
+
private commandRouter;
|
|
2254
2298
|
private reconnectAttempts;
|
|
2255
2299
|
private maxReconnectAttempts;
|
|
2300
|
+
private retryState;
|
|
2256
2301
|
constructor(id?: string);
|
|
2257
2302
|
protected doStart(): Promise<void>;
|
|
2258
2303
|
protected doStop(): Promise<void>;
|
|
2304
|
+
protected doHealthCheck(): Promise<boolean>;
|
|
2259
2305
|
send(message: GatewayMessage): Promise<string>;
|
|
2306
|
+
private createMessage;
|
|
2307
|
+
private syncCommands;
|
|
2260
2308
|
getCapabilities(): {
|
|
2261
2309
|
supportsText: boolean;
|
|
2262
2310
|
supportsMedia: boolean;
|
|
@@ -2270,6 +2318,9 @@ declare class DiscordPlugin extends BaseChannelPlugin {
|
|
|
2270
2318
|
supportsHtml: boolean;
|
|
2271
2319
|
supportsDeliveryReceipt: boolean;
|
|
2272
2320
|
supportsReadReceipt: boolean;
|
|
2321
|
+
supportsSlashCommands: boolean;
|
|
2322
|
+
supportsNativeCommands: boolean;
|
|
2323
|
+
commandPrefix: string;
|
|
2273
2324
|
maxMessageLength: number;
|
|
2274
2325
|
maxMediaCount: number;
|
|
2275
2326
|
};
|
|
@@ -2277,14 +2328,17 @@ declare class DiscordPlugin extends BaseChannelPlugin {
|
|
|
2277
2328
|
private handleGatewayMessage;
|
|
2278
2329
|
private handleHello;
|
|
2279
2330
|
private handleDispatch;
|
|
2331
|
+
private handleReactionEvent;
|
|
2332
|
+
private findSentMessageEntry;
|
|
2280
2333
|
private handleDiscordMessage;
|
|
2281
2334
|
private toGatewayMessage;
|
|
2282
2335
|
private parseContent;
|
|
2336
|
+
private downloadFile;
|
|
2337
|
+
private downloadTextFile;
|
|
2283
2338
|
protected buildSessionId(channelId: string, chatId: string, userId?: string): string;
|
|
2284
2339
|
private processMessageAndGetSessionId;
|
|
2285
2340
|
private getCurrentUser;
|
|
2286
2341
|
private getGatewayBot;
|
|
2287
|
-
private createMessage;
|
|
2288
2342
|
private request;
|
|
2289
2343
|
}
|
|
2290
2344
|
|
|
@@ -2298,6 +2352,24 @@ interface SlackBotConfig {
|
|
|
2298
2352
|
path: string;
|
|
2299
2353
|
port?: number;
|
|
2300
2354
|
};
|
|
2355
|
+
commands?: SlackBotCommand[];
|
|
2356
|
+
retry?: {
|
|
2357
|
+
maxAttempts?: number;
|
|
2358
|
+
initialDelay?: number;
|
|
2359
|
+
maxDelay?: number;
|
|
2360
|
+
};
|
|
2361
|
+
}
|
|
2362
|
+
interface SlackBotCommand {
|
|
2363
|
+
command: string;
|
|
2364
|
+
description: string;
|
|
2365
|
+
handler: (ctx: SlackCommandContext) => Promise<void>;
|
|
2366
|
+
}
|
|
2367
|
+
interface SlackCommandContext {
|
|
2368
|
+
channelId: string;
|
|
2369
|
+
userId: string;
|
|
2370
|
+
args: string[];
|
|
2371
|
+
ts: string;
|
|
2372
|
+
reply?: (text: string) => Promise<string>;
|
|
2301
2373
|
}
|
|
2302
2374
|
declare class SlackPlugin extends BaseChannelPlugin {
|
|
2303
2375
|
readonly id: string;
|
|
@@ -2307,10 +2379,22 @@ declare class SlackPlugin extends BaseChannelPlugin {
|
|
|
2307
2379
|
private baseUrl;
|
|
2308
2380
|
private socketModeClient;
|
|
2309
2381
|
private abortController;
|
|
2382
|
+
private processedMessageIds;
|
|
2383
|
+
private sentMessages;
|
|
2384
|
+
private sessionIdMap;
|
|
2385
|
+
private commandRouter;
|
|
2386
|
+
private retryState;
|
|
2387
|
+
private socketReconnectAttempts;
|
|
2388
|
+
private maxSocketReconnectAttempts;
|
|
2310
2389
|
constructor(id?: string);
|
|
2311
2390
|
protected doStart(): Promise<void>;
|
|
2312
2391
|
protected doStop(): Promise<void>;
|
|
2392
|
+
protected doHealthCheck(): Promise<boolean>;
|
|
2313
2393
|
send(message: GatewayMessage): Promise<string>;
|
|
2394
|
+
private postMessage;
|
|
2395
|
+
private postImage;
|
|
2396
|
+
private postFile;
|
|
2397
|
+
private uploadFile;
|
|
2314
2398
|
getCapabilities(): {
|
|
2315
2399
|
supportsText: boolean;
|
|
2316
2400
|
supportsMedia: boolean;
|
|
@@ -2324,18 +2408,31 @@ declare class SlackPlugin extends BaseChannelPlugin {
|
|
|
2324
2408
|
supportsHtml: boolean;
|
|
2325
2409
|
supportsDeliveryReceipt: boolean;
|
|
2326
2410
|
supportsReadReceipt: boolean;
|
|
2411
|
+
supportsSlashCommands: boolean;
|
|
2412
|
+
supportsNativeCommands: boolean;
|
|
2413
|
+
commandPrefix: string;
|
|
2327
2414
|
maxMessageLength: number;
|
|
2328
2415
|
maxMediaCount: number;
|
|
2329
2416
|
};
|
|
2330
2417
|
private startSocketMode;
|
|
2331
2418
|
private handleSocketModeEvent;
|
|
2419
|
+
private handleReactionEvent;
|
|
2420
|
+
private findSentMessageEntry;
|
|
2332
2421
|
private handleSlackMessage;
|
|
2422
|
+
private handleCommand;
|
|
2423
|
+
protected getCommandList(): Promise<Array<{
|
|
2424
|
+
name: string;
|
|
2425
|
+
description?: string;
|
|
2426
|
+
agent?: string;
|
|
2427
|
+
model?: string;
|
|
2428
|
+
}>>;
|
|
2429
|
+
private syncBotCommands;
|
|
2333
2430
|
private toGatewayMessage;
|
|
2334
2431
|
private parseContent;
|
|
2432
|
+
private downloadFile;
|
|
2433
|
+
private downloadTextFile;
|
|
2335
2434
|
protected buildSessionId(channelId: string, chatId: string, userId?: string): string;
|
|
2336
|
-
private processMessageAndGetSessionId;
|
|
2337
2435
|
private authTest;
|
|
2338
|
-
private postMessage;
|
|
2339
2436
|
private request;
|
|
2340
2437
|
}
|
|
2341
2438
|
|
|
@@ -2349,6 +2446,11 @@ interface FeishuBotConfig {
|
|
|
2349
2446
|
path: string;
|
|
2350
2447
|
port?: number;
|
|
2351
2448
|
};
|
|
2449
|
+
retry?: {
|
|
2450
|
+
maxAttempts?: number;
|
|
2451
|
+
initialDelay?: number;
|
|
2452
|
+
maxDelay?: number;
|
|
2453
|
+
};
|
|
2352
2454
|
}
|
|
2353
2455
|
interface FeishuMessageEvent {
|
|
2354
2456
|
type: string;
|
|
@@ -2385,9 +2487,12 @@ declare class FeishuPlugin extends BaseChannelPlugin {
|
|
|
2385
2487
|
private tenantAccessToken;
|
|
2386
2488
|
private tokenExpireTime;
|
|
2387
2489
|
private abortController;
|
|
2490
|
+
private processedMessageIds;
|
|
2491
|
+
private retryState;
|
|
2388
2492
|
constructor(id?: string);
|
|
2389
2493
|
protected doStart(): Promise<void>;
|
|
2390
2494
|
protected doStop(): Promise<void>;
|
|
2495
|
+
protected doHealthCheck(): Promise<boolean>;
|
|
2391
2496
|
send(message: GatewayMessage): Promise<string>;
|
|
2392
2497
|
getCapabilities(): {
|
|
2393
2498
|
supportsText: boolean;
|
|
@@ -2402,18 +2507,26 @@ declare class FeishuPlugin extends BaseChannelPlugin {
|
|
|
2402
2507
|
supportsHtml: boolean;
|
|
2403
2508
|
supportsDeliveryReceipt: boolean;
|
|
2404
2509
|
supportsReadReceipt: boolean;
|
|
2510
|
+
supportsSlashCommands: boolean;
|
|
2511
|
+
supportsNativeCommands: boolean;
|
|
2512
|
+
commandPrefix: string;
|
|
2405
2513
|
maxMessageLength: number;
|
|
2406
2514
|
maxMediaCount: number;
|
|
2407
2515
|
};
|
|
2408
2516
|
handleWebhookEvent(event: FeishuMessageEvent): Promise<void>;
|
|
2517
|
+
private refreshTenantAccessToken;
|
|
2518
|
+
private ensureTokenValid;
|
|
2519
|
+
private sendMessage;
|
|
2520
|
+
private sendImage;
|
|
2521
|
+
private sendFile;
|
|
2522
|
+
private uploadImage;
|
|
2523
|
+
private uploadFile;
|
|
2409
2524
|
private toGatewayMessage;
|
|
2410
2525
|
private parseContent;
|
|
2526
|
+
private downloadImage;
|
|
2527
|
+
private downloadFile;
|
|
2411
2528
|
private extractPostContent;
|
|
2412
2529
|
protected buildSessionId(channelId: string, chatId: string, userId?: string): string;
|
|
2413
|
-
private processMessageAndGetSessionId;
|
|
2414
|
-
private refreshTenantAccessToken;
|
|
2415
|
-
private ensureTokenValid;
|
|
2416
|
-
private sendMessage;
|
|
2417
2530
|
}
|
|
2418
2531
|
|
|
2419
2532
|
interface WeChatBotConfig {
|
|
@@ -2428,6 +2541,11 @@ interface WeChatBotConfig {
|
|
|
2428
2541
|
path: string;
|
|
2429
2542
|
port?: number;
|
|
2430
2543
|
};
|
|
2544
|
+
retry?: {
|
|
2545
|
+
maxAttempts?: number;
|
|
2546
|
+
initialDelay?: number;
|
|
2547
|
+
maxDelay?: number;
|
|
2548
|
+
};
|
|
2431
2549
|
}
|
|
2432
2550
|
declare class WeChatPlugin extends BaseChannelPlugin {
|
|
2433
2551
|
readonly id: string;
|
|
@@ -2437,9 +2555,12 @@ declare class WeChatPlugin extends BaseChannelPlugin {
|
|
|
2437
2555
|
private accessToken;
|
|
2438
2556
|
private tokenExpireTime;
|
|
2439
2557
|
private abortController;
|
|
2558
|
+
private processedMessageIds;
|
|
2559
|
+
private retryState;
|
|
2440
2560
|
constructor(id?: string);
|
|
2441
2561
|
protected doStart(): Promise<void>;
|
|
2442
2562
|
protected doStop(): Promise<void>;
|
|
2563
|
+
protected doHealthCheck(): Promise<boolean>;
|
|
2443
2564
|
send(message: GatewayMessage): Promise<string>;
|
|
2444
2565
|
getCapabilities(): {
|
|
2445
2566
|
supportsText: boolean;
|
|
@@ -2454,19 +2575,23 @@ declare class WeChatPlugin extends BaseChannelPlugin {
|
|
|
2454
2575
|
supportsHtml: boolean;
|
|
2455
2576
|
supportsDeliveryReceipt: boolean;
|
|
2456
2577
|
supportsReadReceipt: boolean;
|
|
2578
|
+
supportsSlashCommands: boolean;
|
|
2579
|
+
supportsNativeCommands: boolean;
|
|
2580
|
+
commandPrefix: string;
|
|
2457
2581
|
maxMessageLength: number;
|
|
2458
2582
|
maxMediaCount: number;
|
|
2459
2583
|
};
|
|
2460
2584
|
handleWebhookMessage(xmlData: string): Promise<void>;
|
|
2461
|
-
private parseXmlMessage;
|
|
2462
|
-
private toGatewayMessage;
|
|
2463
|
-
private parseContent;
|
|
2464
|
-
protected buildSessionId(channelId: string, chatId: string, userId?: string): string;
|
|
2465
|
-
private processMessageAndGetSessionId;
|
|
2466
2585
|
private refreshAccessToken;
|
|
2467
2586
|
private ensureTokenValid;
|
|
2468
2587
|
private sendOfficialMessage;
|
|
2469
2588
|
private sendWeComMessage;
|
|
2589
|
+
private sendImage;
|
|
2590
|
+
private uploadImage;
|
|
2591
|
+
private parseXmlMessage;
|
|
2592
|
+
private toGatewayMessage;
|
|
2593
|
+
private parseContent;
|
|
2594
|
+
protected buildSessionId(channelId: string, chatId: string, userId?: string): string;
|
|
2470
2595
|
}
|
|
2471
2596
|
|
|
2472
2597
|
interface WebChatConfig {
|
|
@@ -2488,11 +2613,13 @@ declare class WebChatPlugin extends BaseChannelPlugin {
|
|
|
2488
2613
|
private connections;
|
|
2489
2614
|
private heartbeatInterval;
|
|
2490
2615
|
private abortController;
|
|
2616
|
+
private processedMessageIds;
|
|
2617
|
+
private sentMessages;
|
|
2491
2618
|
private wsServer;
|
|
2492
2619
|
constructor(id?: string);
|
|
2493
2620
|
protected doStart(): Promise<void>;
|
|
2494
|
-
private startWebSocketServer;
|
|
2495
2621
|
protected doStop(): Promise<void>;
|
|
2622
|
+
protected doHealthCheck(): Promise<boolean>;
|
|
2496
2623
|
send(message: GatewayMessage): Promise<string>;
|
|
2497
2624
|
getCapabilities(): {
|
|
2498
2625
|
supportsText: boolean;
|
|
@@ -2507,20 +2634,23 @@ declare class WebChatPlugin extends BaseChannelPlugin {
|
|
|
2507
2634
|
supportsHtml: boolean;
|
|
2508
2635
|
supportsDeliveryReceipt: boolean;
|
|
2509
2636
|
supportsReadReceipt: boolean;
|
|
2637
|
+
supportsSlashCommands: boolean;
|
|
2638
|
+
supportsNativeCommands: boolean;
|
|
2639
|
+
commandPrefix: string;
|
|
2510
2640
|
maxMessageLength: number;
|
|
2511
2641
|
maxMediaCount: number;
|
|
2512
2642
|
};
|
|
2513
|
-
pushEvent(sessionId: string, event: SessionEventPayload): void;
|
|
2514
2643
|
getWebSocketServer(): GatewayWebSocketServer | null;
|
|
2515
2644
|
handleConnection(ws: WebSocket, userId: string): Promise<void>;
|
|
2645
|
+
getConnectionCount(): number;
|
|
2646
|
+
getWsServerConnectionCount(): number;
|
|
2647
|
+
private startWebSocketServer;
|
|
2516
2648
|
private handleWebSocketMessage;
|
|
2517
2649
|
private handleMessageAcknowledgment;
|
|
2518
2650
|
private handleChatMessage;
|
|
2519
2651
|
private startHeartbeat;
|
|
2520
2652
|
private findConnectionByUser;
|
|
2521
2653
|
private generateConnectionId;
|
|
2522
|
-
getConnectionCount(): number;
|
|
2523
|
-
getWsServerConnectionCount(): number;
|
|
2524
2654
|
}
|
|
2525
2655
|
|
|
2526
2656
|
interface SignalBotConfig {
|
|
@@ -2532,6 +2662,15 @@ interface SignalBotConfig {
|
|
|
2532
2662
|
path: string;
|
|
2533
2663
|
port?: number;
|
|
2534
2664
|
};
|
|
2665
|
+
polling?: {
|
|
2666
|
+
enabled: boolean;
|
|
2667
|
+
interval?: number;
|
|
2668
|
+
};
|
|
2669
|
+
retry?: {
|
|
2670
|
+
maxAttempts?: number;
|
|
2671
|
+
initialDelay?: number;
|
|
2672
|
+
maxDelay?: number;
|
|
2673
|
+
};
|
|
2535
2674
|
}
|
|
2536
2675
|
declare class SignalPlugin extends BaseChannelPlugin {
|
|
2537
2676
|
readonly id: string;
|
|
@@ -2541,9 +2680,13 @@ declare class SignalPlugin extends BaseChannelPlugin {
|
|
|
2541
2680
|
private abortController;
|
|
2542
2681
|
private lastTimestamp;
|
|
2543
2682
|
private pollingIntervalMs;
|
|
2683
|
+
private processedMessageIds;
|
|
2684
|
+
private sentMessages;
|
|
2685
|
+
private retryState;
|
|
2544
2686
|
constructor(id?: string);
|
|
2545
2687
|
protected doStart(): Promise<void>;
|
|
2546
2688
|
protected doStop(): Promise<void>;
|
|
2689
|
+
protected doHealthCheck(): Promise<boolean>;
|
|
2547
2690
|
send(message: GatewayMessage): Promise<string>;
|
|
2548
2691
|
getCapabilities(): {
|
|
2549
2692
|
supportsText: boolean;
|
|
@@ -2558,6 +2701,9 @@ declare class SignalPlugin extends BaseChannelPlugin {
|
|
|
2558
2701
|
supportsHtml: boolean;
|
|
2559
2702
|
supportsDeliveryReceipt: boolean;
|
|
2560
2703
|
supportsReadReceipt: boolean;
|
|
2704
|
+
supportsSlashCommands: boolean;
|
|
2705
|
+
supportsNativeCommands: boolean;
|
|
2706
|
+
commandPrefix: string;
|
|
2561
2707
|
maxMessageLength: number;
|
|
2562
2708
|
maxMediaCount: number;
|
|
2563
2709
|
};
|
|
@@ -2568,7 +2714,6 @@ declare class SignalPlugin extends BaseChannelPlugin {
|
|
|
2568
2714
|
private toGatewayMessage;
|
|
2569
2715
|
private parseContent;
|
|
2570
2716
|
protected buildSessionId(channelId: string, chatId: string, userId?: string): string;
|
|
2571
|
-
private processMessageAndGetSessionId;
|
|
2572
2717
|
private getAccountInfo;
|
|
2573
2718
|
private receiveMessages;
|
|
2574
2719
|
private sendMessage;
|
|
@@ -2580,6 +2725,11 @@ interface NostrBotConfig {
|
|
|
2580
2725
|
privateKey?: string;
|
|
2581
2726
|
publicKey?: string;
|
|
2582
2727
|
timeout: number;
|
|
2728
|
+
retry?: {
|
|
2729
|
+
maxAttempts?: number;
|
|
2730
|
+
initialDelay?: number;
|
|
2731
|
+
maxDelay?: number;
|
|
2732
|
+
};
|
|
2583
2733
|
}
|
|
2584
2734
|
declare class NostrPlugin extends BaseChannelPlugin {
|
|
2585
2735
|
readonly id: string;
|
|
@@ -2588,13 +2738,16 @@ declare class NostrPlugin extends BaseChannelPlugin {
|
|
|
2588
2738
|
private botConfig;
|
|
2589
2739
|
private relayConnections;
|
|
2590
2740
|
private subscriptions;
|
|
2591
|
-
private eventHandlers;
|
|
2592
2741
|
private abortController;
|
|
2742
|
+
private processedEventIds;
|
|
2743
|
+
private sentMessages;
|
|
2593
2744
|
private relayReconnectAttempts;
|
|
2594
2745
|
private maxReconnectAttempts;
|
|
2746
|
+
private retryState;
|
|
2595
2747
|
constructor(id?: string);
|
|
2596
2748
|
protected doStart(): Promise<void>;
|
|
2597
2749
|
protected doStop(): Promise<void>;
|
|
2750
|
+
protected doHealthCheck(): Promise<boolean>;
|
|
2598
2751
|
send(message: GatewayMessage): Promise<string>;
|
|
2599
2752
|
getCapabilities(): {
|
|
2600
2753
|
supportsText: boolean;
|
|
@@ -2609,6 +2762,9 @@ declare class NostrPlugin extends BaseChannelPlugin {
|
|
|
2609
2762
|
supportsHtml: boolean;
|
|
2610
2763
|
supportsDeliveryReceipt: boolean;
|
|
2611
2764
|
supportsReadReceipt: boolean;
|
|
2765
|
+
supportsSlashCommands: boolean;
|
|
2766
|
+
supportsNativeCommands: boolean;
|
|
2767
|
+
commandPrefix: string;
|
|
2612
2768
|
maxMessageLength: number;
|
|
2613
2769
|
maxMediaCount: number;
|
|
2614
2770
|
};
|
|
@@ -2619,8 +2775,8 @@ declare class NostrPlugin extends BaseChannelPlugin {
|
|
|
2619
2775
|
private parseContent;
|
|
2620
2776
|
private findReplyTo;
|
|
2621
2777
|
protected buildSessionId(channelId: string, chatId: string, userId?: string): string;
|
|
2622
|
-
private processMessageAndGetSessionId;
|
|
2623
2778
|
private subscribeToRelay;
|
|
2779
|
+
private unsubscribeFromRelay;
|
|
2624
2780
|
private createEvent;
|
|
2625
2781
|
private computeEventId;
|
|
2626
2782
|
private signEvent;
|
|
@@ -2689,7 +2845,200 @@ declare function createChannelPlugin<TConfig = unknown, TProbe = unknown>(option
|
|
|
2689
2845
|
declare const ChannelPluginRegistry: Record<string, new (id?: string) => ChannelPlugin>;
|
|
2690
2846
|
declare function getSupportedPlatforms(): string[];
|
|
2691
2847
|
|
|
2692
|
-
declare
|
|
2848
|
+
declare enum SdkEventType {
|
|
2849
|
+
SDK_SESSION_STATUS = "agent.status",
|
|
2850
|
+
SDK_ERROR = "sdk.error",
|
|
2851
|
+
SDK_SESSION_UPDATE = "sdk.session_update",
|
|
2852
|
+
SDK_PERMISSION_REQUEST = "sdk.permission_request",
|
|
2853
|
+
SDK_SESSION_DELETED = "sdk.session_deleted"
|
|
2854
|
+
}
|
|
2855
|
+
declare const SdkSessionStatusSchema: z$1.ZodObject<{
|
|
2856
|
+
sessionId: z$1.ZodString;
|
|
2857
|
+
status: z$1.ZodEnum<{
|
|
2858
|
+
idle: "idle";
|
|
2859
|
+
busy: "busy";
|
|
2860
|
+
retry: "retry";
|
|
2861
|
+
}>;
|
|
2862
|
+
timestamp: z$1.ZodNumber;
|
|
2863
|
+
}, z$1.core.$strip>;
|
|
2864
|
+
type SdkSessionStatusProps = z$1.infer<typeof SdkSessionStatusSchema>;
|
|
2865
|
+
declare const SdkErrorSchema: z$1.ZodObject<{
|
|
2866
|
+
error: z$1.ZodString;
|
|
2867
|
+
context: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodAny>>;
|
|
2868
|
+
timestamp: z$1.ZodNumber;
|
|
2869
|
+
}, z$1.core.$strip>;
|
|
2870
|
+
type SdkErrorProps = z$1.infer<typeof SdkErrorSchema>;
|
|
2871
|
+
declare const SdkSessionUpdateSchema: z$1.ZodObject<{
|
|
2872
|
+
sessionId: z$1.ZodString;
|
|
2873
|
+
update: z$1.ZodRecord<z$1.ZodString, z$1.ZodAny>;
|
|
2874
|
+
timestamp: z$1.ZodNumber;
|
|
2875
|
+
}, z$1.core.$strip>;
|
|
2876
|
+
type SdkSessionUpdateProps = z$1.infer<typeof SdkSessionUpdateSchema>;
|
|
2877
|
+
declare const SdkPermissionRequestSchema: z$1.ZodObject<{
|
|
2878
|
+
requestId: z$1.ZodString;
|
|
2879
|
+
sessionId: z$1.ZodString;
|
|
2880
|
+
permission: z$1.ZodString;
|
|
2881
|
+
tool: z$1.ZodOptional<z$1.ZodObject<{
|
|
2882
|
+
callId: z$1.ZodOptional<z$1.ZodString>;
|
|
2883
|
+
}, z$1.core.$strip>>;
|
|
2884
|
+
metadata: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodAny>>;
|
|
2885
|
+
timestamp: z$1.ZodNumber;
|
|
2886
|
+
}, z$1.core.$strip>;
|
|
2887
|
+
type SdkPermissionRequestProps = z$1.infer<typeof SdkPermissionRequestSchema>;
|
|
2888
|
+
declare const SdkSessionDeletedSchema: z$1.ZodObject<{
|
|
2889
|
+
sessionId: z$1.ZodString;
|
|
2890
|
+
timestamp: z$1.ZodNumber;
|
|
2891
|
+
}, z$1.core.$strip>;
|
|
2892
|
+
type SdkSessionDeletedProps = z$1.infer<typeof SdkSessionDeletedSchema>;
|
|
2893
|
+
type LocalEventProperties = SdkSessionStatusProps | SdkErrorProps | SdkSessionUpdateProps | SdkPermissionRequestProps | SdkSessionDeletedProps;
|
|
2894
|
+
interface LocalEvent<T extends SdkEventType = SdkEventType> {
|
|
2895
|
+
type: T;
|
|
2896
|
+
properties: LocalEventProperties;
|
|
2897
|
+
}
|
|
2898
|
+
type LocalEventCallback = (event: LocalEvent) => void | Promise<void>;
|
|
2899
|
+
declare class SdkEventBus {
|
|
2900
|
+
private subscriptions;
|
|
2901
|
+
private wildcardSubscriptions;
|
|
2902
|
+
private destroyed;
|
|
2903
|
+
subscribe(eventType: SdkEventType, callback: LocalEventCallback): () => void;
|
|
2904
|
+
subscribeAll(callback: LocalEventCallback): () => void;
|
|
2905
|
+
publish(event: LocalEvent): Promise<void>;
|
|
2906
|
+
publishSync(event: LocalEvent): void;
|
|
2907
|
+
subscriberCount(eventType?: SdkEventType): number;
|
|
2908
|
+
totalSubscribers(): number;
|
|
2909
|
+
hasSubscribers(eventType?: SdkEventType): boolean;
|
|
2910
|
+
clear(): void;
|
|
2911
|
+
destroy(): void;
|
|
2912
|
+
isDestroyed(): boolean;
|
|
2913
|
+
}
|
|
2914
|
+
|
|
2915
|
+
declare class SdkEventBridge {
|
|
2916
|
+
private sdk;
|
|
2917
|
+
private sdkEventBus?;
|
|
2918
|
+
private abortController;
|
|
2919
|
+
private started;
|
|
2920
|
+
private readonly sessionFilter?;
|
|
2921
|
+
constructor(sdk: EasbotClient, localEventBus?: SdkEventBus, sessionFilter?: (sessionId: string) => boolean);
|
|
2922
|
+
private pushEvent;
|
|
2923
|
+
start(): Promise<void>;
|
|
2924
|
+
stop(): Promise<void>;
|
|
2925
|
+
isStarted(): boolean;
|
|
2926
|
+
private runEventLoop;
|
|
2927
|
+
private handleEvent;
|
|
2928
|
+
private handleSessionDeleted;
|
|
2929
|
+
private handlePermissionAsked;
|
|
2930
|
+
private handleMessagePartUpdated;
|
|
2931
|
+
private handleToolPart;
|
|
2932
|
+
private handleTextPart;
|
|
2933
|
+
private handleStepStartPart;
|
|
2934
|
+
private handleStepFinishPart;
|
|
2935
|
+
private handleReasoningPart;
|
|
2936
|
+
private handleSessionStatus;
|
|
2937
|
+
}
|
|
2938
|
+
|
|
2939
|
+
interface AgentClientFilterConfig {
|
|
2940
|
+
includeThinking: boolean;
|
|
2941
|
+
includeToolDetails: boolean;
|
|
2942
|
+
includeToolOutput: boolean;
|
|
2943
|
+
includeSteps: boolean;
|
|
2944
|
+
}
|
|
2945
|
+
declare const DEFAULT_AGENT_FILTER: AgentClientFilterConfig;
|
|
2946
|
+
declare const DEBUG_AGENT_FILTER: AgentClientFilterConfig;
|
|
2947
|
+
interface AgentMessage {
|
|
2948
|
+
role: 'user' | 'assistant';
|
|
2949
|
+
text: string;
|
|
2950
|
+
thinking?: string;
|
|
2951
|
+
tools?: Array<{
|
|
2952
|
+
name: string;
|
|
2953
|
+
status: 'completed' | 'error';
|
|
2954
|
+
output?: unknown;
|
|
2955
|
+
error?: string;
|
|
2956
|
+
}>;
|
|
2957
|
+
metadata: {
|
|
2958
|
+
sessionId: string;
|
|
2959
|
+
sessionStatus?: 'idle' | 'busy' | 'retry' | 'error';
|
|
2960
|
+
messageId: string;
|
|
2961
|
+
timestamp: number;
|
|
2962
|
+
tokens?: {
|
|
2963
|
+
input: number;
|
|
2964
|
+
output: number;
|
|
2965
|
+
total: number;
|
|
2966
|
+
};
|
|
2967
|
+
error?: string;
|
|
2968
|
+
};
|
|
2969
|
+
}
|
|
2970
|
+
type SessionEventType = 'part.updated' | 'session.status' | 'message.updated' | 'message.part.updated' | 'session.error';
|
|
2971
|
+
interface SessionError {
|
|
2972
|
+
name: string;
|
|
2973
|
+
data: {
|
|
2974
|
+
message?: string;
|
|
2975
|
+
providerId?: string;
|
|
2976
|
+
statusCode?: number;
|
|
2977
|
+
isRetryable?: boolean;
|
|
2978
|
+
responseHeaders?: Record<string, string>;
|
|
2979
|
+
metadata?: Record<string, unknown>;
|
|
2980
|
+
retries?: number;
|
|
2981
|
+
[key: string]: unknown;
|
|
2982
|
+
};
|
|
2983
|
+
}
|
|
2984
|
+
interface SessionEvent {
|
|
2985
|
+
type: SessionEventType;
|
|
2986
|
+
properties: {
|
|
2987
|
+
sessionId?: string;
|
|
2988
|
+
info?: {
|
|
2989
|
+
id?: string;
|
|
2990
|
+
};
|
|
2991
|
+
part?: PartData;
|
|
2992
|
+
status?: {
|
|
2993
|
+
type?: string;
|
|
2994
|
+
};
|
|
2995
|
+
error?: SessionError;
|
|
2996
|
+
};
|
|
2997
|
+
}
|
|
2998
|
+
interface PartData {
|
|
2999
|
+
type: 'text' | 'reasoning' | 'tool' | 'step-start' | 'step-finish';
|
|
3000
|
+
text?: string;
|
|
3001
|
+
messageId?: string;
|
|
3002
|
+
time?: {
|
|
3003
|
+
start?: number;
|
|
3004
|
+
end?: number;
|
|
3005
|
+
};
|
|
3006
|
+
tool?: string;
|
|
3007
|
+
state?: {
|
|
3008
|
+
status?: 'running' | 'completed' | 'error';
|
|
3009
|
+
output?: unknown;
|
|
3010
|
+
error?: string;
|
|
3011
|
+
};
|
|
3012
|
+
tokens?: {
|
|
3013
|
+
input: number;
|
|
3014
|
+
output: number;
|
|
3015
|
+
reasoning: number;
|
|
3016
|
+
};
|
|
3017
|
+
}
|
|
3018
|
+
declare class SdkMessagetCollector {
|
|
3019
|
+
private filterConfig;
|
|
3020
|
+
events: SessionEvent[];
|
|
3021
|
+
isComplete: boolean;
|
|
3022
|
+
private hasTextEnd;
|
|
3023
|
+
private hasStepFinish;
|
|
3024
|
+
private error;
|
|
3025
|
+
private sessionStatus;
|
|
3026
|
+
private sessionId;
|
|
3027
|
+
private messageId;
|
|
3028
|
+
constructor(filterConfig?: AgentClientFilterConfig);
|
|
3029
|
+
addEvent(event: SessionEvent): void;
|
|
3030
|
+
private shouldIncludeEvent;
|
|
3031
|
+
private checkCompletion;
|
|
3032
|
+
checkComplete(): boolean;
|
|
3033
|
+
hasTextEndReady(): boolean;
|
|
3034
|
+
isTextOnlyComplete(): boolean;
|
|
3035
|
+
resetForNextMessage(): void;
|
|
3036
|
+
getCurrentMessageId(): string;
|
|
3037
|
+
assembleMessage(): AgentMessage;
|
|
3038
|
+
reset(): void;
|
|
3039
|
+
}
|
|
3040
|
+
|
|
3041
|
+
declare function setAgentAdapter(adapter: AgentAdapter | undefined): void;
|
|
2693
3042
|
declare function getAgentAdapter(): AgentAdapter | undefined;
|
|
2694
3043
|
declare function hasAgentAdapter(): boolean;
|
|
2695
3044
|
declare function requireAgentAdapter(): AgentAdapter;
|
|
@@ -2702,4 +3051,4 @@ declare function initLog(options: {
|
|
|
2702
3051
|
level?: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
|
|
2703
3052
|
}): Promise<void>;
|
|
2704
3053
|
|
|
2705
|
-
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
|
|
3054
|
+
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 };
|