@easbot/gateway 0.2.41 → 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 +414 -243
- package/dist/index.d.ts +414 -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,15 @@ 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
|
+
};
|
|
1118
1163
|
}
|
|
1119
1164
|
interface CreateSessionRequest {
|
|
1120
1165
|
title?: string;
|
|
@@ -1126,7 +1171,7 @@ interface CreateSessionRequest {
|
|
|
1126
1171
|
};
|
|
1127
1172
|
context?: Record<string, unknown>;
|
|
1128
1173
|
}
|
|
1129
|
-
interface CreateSessionResponse
|
|
1174
|
+
interface CreateSessionResponse {
|
|
1130
1175
|
id: string;
|
|
1131
1176
|
createdAt: number;
|
|
1132
1177
|
}
|
|
@@ -1141,7 +1186,7 @@ interface SendMessageRequest {
|
|
|
1141
1186
|
}>;
|
|
1142
1187
|
[key: string]: unknown;
|
|
1143
1188
|
}
|
|
1144
|
-
interface SendMessageResponse
|
|
1189
|
+
interface SendMessageResponse {
|
|
1145
1190
|
messageId: string;
|
|
1146
1191
|
sessionId: string;
|
|
1147
1192
|
createdAt: number;
|
|
@@ -1151,11 +1196,16 @@ interface SendMessageResponse$1 {
|
|
|
1151
1196
|
channelInfo?: ChannelInfo;
|
|
1152
1197
|
};
|
|
1153
1198
|
}
|
|
1199
|
+
type SubscriptionType = 'message' | 'agent';
|
|
1154
1200
|
interface SubscriptionsResponse {
|
|
1155
1201
|
subscriptions: Array<{
|
|
1202
|
+
type: SubscriptionType;
|
|
1156
1203
|
sessionId: string;
|
|
1157
1204
|
subscriberCount: number;
|
|
1158
|
-
subscribers:
|
|
1205
|
+
subscribers: Array<{
|
|
1206
|
+
id: string;
|
|
1207
|
+
subscriptionId: string;
|
|
1208
|
+
}>;
|
|
1159
1209
|
}>;
|
|
1160
1210
|
total: number;
|
|
1161
1211
|
}
|
|
@@ -1203,10 +1253,10 @@ interface AgentRegistration {
|
|
|
1203
1253
|
}
|
|
1204
1254
|
type AgentRegistrationRequest = Omit<AgentRegistration, 'registeredAt' | 'lastHeartbeat' | 'connectionCount' | 'status'>;
|
|
1205
1255
|
declare const DEFAULT_AGENT_REGISTRY_CONFIG: {
|
|
1206
|
-
readonly heartbeatInterval:
|
|
1207
|
-
readonly heartbeatTimeout:
|
|
1208
|
-
readonly heartbeatCheckInterval:
|
|
1209
|
-
readonly autoDeregisterTimeout:
|
|
1256
|
+
readonly heartbeatInterval: 60000;
|
|
1257
|
+
readonly heartbeatTimeout: 300000;
|
|
1258
|
+
readonly heartbeatCheckInterval: 300000;
|
|
1259
|
+
readonly autoDeregisterTimeout: 600000;
|
|
1210
1260
|
readonly maxAgents: 100;
|
|
1211
1261
|
readonly maxRegistrations: 1000;
|
|
1212
1262
|
};
|
|
@@ -1351,12 +1401,12 @@ declare const DEFAULT_CONNECTION_POOL_CONFIG: {
|
|
|
1351
1401
|
acquireTimeout: number;
|
|
1352
1402
|
warmupCount: number;
|
|
1353
1403
|
};
|
|
1354
|
-
type ConnectionState
|
|
1404
|
+
type ConnectionState = 'idle' | 'active' | 'unhealthy' | 'closed';
|
|
1355
1405
|
interface PooledConnection<T = unknown> {
|
|
1356
1406
|
id: string;
|
|
1357
1407
|
channelId: string;
|
|
1358
1408
|
connection: T;
|
|
1359
|
-
state: ConnectionState
|
|
1409
|
+
state: ConnectionState;
|
|
1360
1410
|
lastActivity: number;
|
|
1361
1411
|
createdAt: number;
|
|
1362
1412
|
useCount: number;
|
|
@@ -1390,21 +1440,30 @@ interface CancelEvent {
|
|
|
1390
1440
|
timestamp: number;
|
|
1391
1441
|
}
|
|
1392
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
|
+
}
|
|
1393
1449
|
declare class MessageRouter {
|
|
1394
1450
|
private log;
|
|
1395
1451
|
private subscribers;
|
|
1396
1452
|
private subscriptions;
|
|
1397
|
-
private
|
|
1453
|
+
private messageSubscriptions;
|
|
1398
1454
|
private channelPlugins;
|
|
1399
1455
|
private cancelHandlers;
|
|
1400
1456
|
private processingMessages;
|
|
1401
1457
|
private hookRegistry;
|
|
1402
|
-
|
|
1458
|
+
private sessionManager;
|
|
1459
|
+
constructor(hookRegistry?: typeof this.hookRegistry, sessionManager?: RouterSessionManager);
|
|
1460
|
+
setSessionManager(sessionManager: RouterSessionManager): void;
|
|
1403
1461
|
private triggerHook;
|
|
1404
1462
|
private triggerBeforeSend;
|
|
1405
1463
|
onCancel(handler: CancelEventHandler): void;
|
|
1406
1464
|
offCancel(handler: CancelEventHandler): void;
|
|
1407
1465
|
private emitCancel;
|
|
1466
|
+
private selectSubscriber;
|
|
1408
1467
|
route(message: GatewayMessage): Promise<RouteResult>;
|
|
1409
1468
|
completeMessage(sessionId: string, messageId: string, subscriberId: string, reason?: 'completed' | 'failed' | 'timeout'): Promise<void>;
|
|
1410
1469
|
subscribe(sessionId: string, subscriber: Subscriber): Promise<Subscription>;
|
|
@@ -1414,6 +1473,7 @@ declare class MessageRouter {
|
|
|
1414
1473
|
unregisterChannel(pluginId: string): void;
|
|
1415
1474
|
getSubscriber(subscriberId: string): Subscriber | undefined;
|
|
1416
1475
|
getSubscription(subscriptionId: string): Subscription | undefined;
|
|
1476
|
+
getMessageSubscriptions(): Map<string, Set<string>>;
|
|
1417
1477
|
getSubscriberCount(sessionId: string): number;
|
|
1418
1478
|
getStats(): {
|
|
1419
1479
|
subscribers: number;
|
|
@@ -1443,6 +1503,7 @@ declare class GatewaySessionManager {
|
|
|
1443
1503
|
closeById(sessionId: string): Promise<void>;
|
|
1444
1504
|
bindBackendSession(gatewaySessionId: string, backendSessionId: string): Promise<void>;
|
|
1445
1505
|
unbindBackendSession(gatewaySessionId: string): Promise<void>;
|
|
1506
|
+
findByBackendSessionId(backendSessionId: string): GatewaySession | undefined;
|
|
1446
1507
|
getState(sessionId: string): SessionState | undefined;
|
|
1447
1508
|
incrementMessageCountOrCreate(sessionId: string, channelInfo?: SessionChannelInfo): Promise<GatewaySession>;
|
|
1448
1509
|
incrementMessageCount(sessionId: string): Promise<void>;
|
|
@@ -1461,15 +1522,28 @@ declare class GatewaySessionManager {
|
|
|
1461
1522
|
};
|
|
1462
1523
|
}
|
|
1463
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>;
|
|
1464
1532
|
declare class AgentRegistry {
|
|
1465
1533
|
private config;
|
|
1466
1534
|
private agents;
|
|
1467
1535
|
private heartbeatTimer;
|
|
1468
1536
|
private roundRobinIndex;
|
|
1469
|
-
|
|
1537
|
+
private store;
|
|
1538
|
+
private eventCallbacks;
|
|
1539
|
+
constructor(config?: Partial<AgentRegistryConfig & {
|
|
1540
|
+
dataDir?: string;
|
|
1541
|
+
}>);
|
|
1542
|
+
load(): Promise<void>;
|
|
1470
1543
|
register(agent: AgentRegistrationRequest): Promise<void>;
|
|
1471
1544
|
deregister(agentId: string): Promise<void>;
|
|
1472
1545
|
heartbeat(agentId: string, metrics?: AgentRegistration['metadata']): Promise<void>;
|
|
1546
|
+
setStatus(agentId: string, status: AgentHealthStatus): void;
|
|
1473
1547
|
getAgent(agentId: string): AgentRegistration | undefined;
|
|
1474
1548
|
getAllAgents(): AgentRegistration[];
|
|
1475
1549
|
getHealthyAgents(): AgentRegistration[];
|
|
@@ -1479,6 +1553,9 @@ declare class AgentRegistry {
|
|
|
1479
1553
|
startHeartbeatCheck(): void;
|
|
1480
1554
|
stopHeartbeatCheck(): void;
|
|
1481
1555
|
private checkHeartbeats;
|
|
1556
|
+
onEvent(callback: AgentEventCallback): void;
|
|
1557
|
+
offEvent(callback: AgentEventCallback): void;
|
|
1558
|
+
private emitEvent;
|
|
1482
1559
|
private selectRandom;
|
|
1483
1560
|
private selectRoundRobin;
|
|
1484
1561
|
private selectLeastConnections;
|
|
@@ -1487,15 +1564,21 @@ declare class AgentRegistry {
|
|
|
1487
1564
|
setLastHeartbeat(agentId: string, timestamp: number): void;
|
|
1488
1565
|
}
|
|
1489
1566
|
|
|
1567
|
+
type AgentListChangeCallback = (agents: AgentSyncInfo[], action: 'add' | 'update' | 'remove', agent: AgentSyncInfo) => void | Promise<void>;
|
|
1490
1568
|
declare class AgentSyncManager {
|
|
1491
1569
|
private config;
|
|
1570
|
+
private internalConfig;
|
|
1492
1571
|
private registry;
|
|
1493
1572
|
private localNodeId;
|
|
1494
1573
|
private localNodeName;
|
|
1495
1574
|
private remoteNodes;
|
|
1496
1575
|
private remoteAgents;
|
|
1497
1576
|
private syncTimer;
|
|
1577
|
+
private cleanupTimer;
|
|
1578
|
+
private reconnectTimer;
|
|
1579
|
+
private heartbeatTimer;
|
|
1498
1580
|
private running;
|
|
1581
|
+
private agentListChangeCallbacks;
|
|
1499
1582
|
constructor(options: {
|
|
1500
1583
|
registry: AgentRegistry;
|
|
1501
1584
|
localNodeId: string;
|
|
@@ -1506,6 +1589,7 @@ declare class AgentSyncManager {
|
|
|
1506
1589
|
stop(): Promise<void>;
|
|
1507
1590
|
private pullFromAllNodes;
|
|
1508
1591
|
pullFromNode(nodeId: string): Promise<AgentSyncInfo[]>;
|
|
1592
|
+
private calculateRetryDelay;
|
|
1509
1593
|
pushEvent(message: SyncMessage): Promise<void>;
|
|
1510
1594
|
pushToNode(nodeId: string, message: SyncMessage): Promise<void>;
|
|
1511
1595
|
handleSyncMessage(message: SyncMessage): Promise<void>;
|
|
@@ -1515,8 +1599,16 @@ declare class AgentSyncManager {
|
|
|
1515
1599
|
private handleAgentDeregister;
|
|
1516
1600
|
private handleAgentHeartbeat;
|
|
1517
1601
|
private handleAgentStatusChange;
|
|
1602
|
+
private cleanupStaleAgents;
|
|
1603
|
+
private reconnectFailedNodes;
|
|
1604
|
+
private checkNodeHealth;
|
|
1605
|
+
private handleLocalAgentEvent;
|
|
1606
|
+
private agentToSyncInfo;
|
|
1518
1607
|
private resolveConflict;
|
|
1519
1608
|
private getLocalAgentsForSync;
|
|
1609
|
+
private notifyAgentListChange;
|
|
1610
|
+
onAgentListChange(callback: AgentListChangeCallback): void;
|
|
1611
|
+
offAgentListChange(callback: AgentListChangeCallback): void;
|
|
1520
1612
|
getMergedAgentList(): AgentSyncInfo[];
|
|
1521
1613
|
getRemoteAgents(): AgentSyncInfo[];
|
|
1522
1614
|
getStats(): SyncStats;
|
|
@@ -1564,6 +1656,11 @@ declare namespace Log {
|
|
|
1564
1656
|
function create(tags?: Record<string, any>): Logger;
|
|
1565
1657
|
}
|
|
1566
1658
|
|
|
1659
|
+
interface LocalCommandResult {
|
|
1660
|
+
handled: boolean;
|
|
1661
|
+
reply?: string;
|
|
1662
|
+
continueProcessing?: boolean;
|
|
1663
|
+
}
|
|
1567
1664
|
declare abstract class BaseChannelPlugin implements ChannelPlugin {
|
|
1568
1665
|
abstract readonly id: string;
|
|
1569
1666
|
abstract readonly platform: PlatformType;
|
|
@@ -1594,12 +1691,12 @@ declare abstract class BaseChannelPlugin implements ChannelPlugin {
|
|
|
1594
1691
|
protected buildSessionId(channelId: string, chatId: string, userId?: string): string;
|
|
1595
1692
|
protected handleMessage(message: GatewayMessage): Promise<void>;
|
|
1596
1693
|
protected handleEvent(type: string, data?: unknown): Promise<void>;
|
|
1597
|
-
protected getCommandList(): Promise<
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
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;
|
|
1603
1700
|
}
|
|
1604
1701
|
|
|
1605
1702
|
interface PluginLoaderConfig {
|
|
@@ -1621,6 +1718,7 @@ declare class ChannelPluginLoader {
|
|
|
1621
1718
|
private backoffPolicy;
|
|
1622
1719
|
constructor(config?: PluginLoaderConfig);
|
|
1623
1720
|
setMessageHandler(handler: MessageHandler): void;
|
|
1721
|
+
updateSessionHandler(session: NonNullable<MessageHandler['session']>): void;
|
|
1624
1722
|
register(plugin: ChannelPlugin, config: ChannelConfig): Promise<void>;
|
|
1625
1723
|
unregister(pluginId: string): Promise<void>;
|
|
1626
1724
|
start(pluginId: string): Promise<void>;
|
|
@@ -1801,6 +1899,7 @@ interface ResolveChannelParams {
|
|
|
1801
1899
|
get(sessionId: string): GatewaySession | undefined;
|
|
1802
1900
|
getOrCreate(channelInfo: SessionChannelInfo, context?: Record<string, unknown>): Promise<GatewaySession>;
|
|
1803
1901
|
bindBackendSession(gatewaySessionId: string, backendSessionId: string): Promise<void>;
|
|
1902
|
+
findByBackendSessionId(backendSessionId: string): GatewaySession | undefined;
|
|
1804
1903
|
getAll?(): GatewaySession[];
|
|
1805
1904
|
};
|
|
1806
1905
|
pluginLoader?: {
|
|
@@ -1850,6 +1949,38 @@ interface ResolveChannelParams {
|
|
|
1850
1949
|
};
|
|
1851
1950
|
}
|
|
1852
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
|
+
|
|
1853
1984
|
type MessageSender = (pluginId: string, message: GatewayMessage, options?: SendOptions) => Promise<string>;
|
|
1854
1985
|
interface SendOptions extends Record<string, unknown> {
|
|
1855
1986
|
}
|
|
@@ -1861,8 +1992,7 @@ declare class GatewayWebSocketServer {
|
|
|
1861
1992
|
private httpRedirectServer;
|
|
1862
1993
|
private connections;
|
|
1863
1994
|
private subscriptions;
|
|
1864
|
-
private
|
|
1865
|
-
private sessionLastActivity;
|
|
1995
|
+
private clientLastActivity;
|
|
1866
1996
|
private cleanupInterval;
|
|
1867
1997
|
private heartbeatInterval;
|
|
1868
1998
|
private startTime;
|
|
@@ -1872,6 +2002,20 @@ declare class GatewayWebSocketServer {
|
|
|
1872
2002
|
setChannelResolveDeps(params: ResolveChannelParams): void;
|
|
1873
2003
|
private pluginLoaderRef;
|
|
1874
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;
|
|
1875
2019
|
private getChannelResolveParams;
|
|
1876
2020
|
start(): Promise<void>;
|
|
1877
2021
|
private startHTTPServer;
|
|
@@ -1880,27 +2024,32 @@ declare class GatewayWebSocketServer {
|
|
|
1880
2024
|
private setupWebSocketUpgrade;
|
|
1881
2025
|
private startHTTPRedirectServer;
|
|
1882
2026
|
stop(): Promise<void>;
|
|
1883
|
-
|
|
2027
|
+
private touchClient;
|
|
1884
2028
|
getConnectionCount(): number;
|
|
2029
|
+
getStartTime(): number;
|
|
1885
2030
|
getSubscriptionCount(): number;
|
|
1886
2031
|
getConnectionInfos(): WebSocketConnectionInfo[];
|
|
1887
2032
|
isRunning(): boolean;
|
|
1888
2033
|
private handleConnection;
|
|
1889
2034
|
private handleDisconnection;
|
|
2035
|
+
private cleanupClientResources;
|
|
1890
2036
|
private handleMessage;
|
|
1891
|
-
private handleInitialize;
|
|
1892
2037
|
private handleSubscribe;
|
|
1893
2038
|
private handleUnsubscribe;
|
|
1894
2039
|
private handleMessageRequest;
|
|
2040
|
+
private getClientIdByWs;
|
|
2041
|
+
getClientWs(clientId: string): WSContext | undefined;
|
|
1895
2042
|
private handleInterrupt;
|
|
1896
2043
|
private handleReleaseSubscription;
|
|
1897
|
-
private touchSession;
|
|
1898
2044
|
private checkConnectionTimeout;
|
|
1899
|
-
private
|
|
1900
|
-
private releaseSessionResources;
|
|
2045
|
+
private cleanupInactiveClients;
|
|
1901
2046
|
private sendMessage;
|
|
1902
2047
|
private sendError;
|
|
1903
2048
|
private createRoutes;
|
|
2049
|
+
private handleAgentListRequest;
|
|
2050
|
+
private handleAgentSubscribe;
|
|
2051
|
+
private handleAgentRegister;
|
|
2052
|
+
private handleAgentDeregister;
|
|
1904
2053
|
}
|
|
1905
2054
|
|
|
1906
2055
|
declare class GatewayServer implements IGatewayServer {
|
|
@@ -1914,6 +2063,9 @@ declare class GatewayServer implements IGatewayServer {
|
|
|
1914
2063
|
private messageStore;
|
|
1915
2064
|
private contactStore;
|
|
1916
2065
|
private wsServer;
|
|
2066
|
+
private agentRegistry;
|
|
2067
|
+
private agentSyncManager;
|
|
2068
|
+
private wsAgentSync;
|
|
1917
2069
|
private running;
|
|
1918
2070
|
private connections;
|
|
1919
2071
|
private gatewayAgent;
|
|
@@ -1926,6 +2078,11 @@ declare class GatewayServer implements IGatewayServer {
|
|
|
1926
2078
|
port?: number;
|
|
1927
2079
|
hostname?: string;
|
|
1928
2080
|
connections?: number;
|
|
2081
|
+
agents?: {
|
|
2082
|
+
total: number;
|
|
2083
|
+
healthy: number;
|
|
2084
|
+
unhealthy: number;
|
|
2085
|
+
};
|
|
1929
2086
|
};
|
|
1930
2087
|
onMessage(message: GatewayMessage): Promise<void>;
|
|
1931
2088
|
private saveContactFromMessage;
|
|
@@ -1957,184 +2114,6 @@ declare class GatewayServer implements IGatewayServer {
|
|
|
1957
2114
|
getMessageHistory(sessionId: string, limit?: number): Promise<MessageRecord[]>;
|
|
1958
2115
|
}
|
|
1959
2116
|
|
|
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
2117
|
interface TelegramBotConfig {
|
|
2139
2118
|
botToken: string;
|
|
2140
2119
|
webhook?: {
|
|
@@ -2661,7 +2640,6 @@ declare class WebChatPlugin extends BaseChannelPlugin {
|
|
|
2661
2640
|
maxMessageLength: number;
|
|
2662
2641
|
maxMediaCount: number;
|
|
2663
2642
|
};
|
|
2664
|
-
pushEvent(sessionId: string, event: SessionEventPayload): void;
|
|
2665
2643
|
getWebSocketServer(): GatewayWebSocketServer | null;
|
|
2666
2644
|
handleConnection(ws: WebSocket, userId: string): Promise<void>;
|
|
2667
2645
|
getConnectionCount(): number;
|
|
@@ -2867,7 +2845,200 @@ declare function createChannelPlugin<TConfig = unknown, TProbe = unknown>(option
|
|
|
2867
2845
|
declare const ChannelPluginRegistry: Record<string, new (id?: string) => ChannelPlugin>;
|
|
2868
2846
|
declare function getSupportedPlatforms(): string[];
|
|
2869
2847
|
|
|
2870
|
-
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;
|
|
2871
3042
|
declare function getAgentAdapter(): AgentAdapter | undefined;
|
|
2872
3043
|
declare function hasAgentAdapter(): boolean;
|
|
2873
3044
|
declare function requireAgentAdapter(): AgentAdapter;
|
|
@@ -2880,4 +3051,4 @@ declare function initLog(options: {
|
|
|
2880
3051
|
level?: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
|
|
2881
3052
|
}): Promise<void>;
|
|
2882
3053
|
|
|
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
|
|
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 };
|