@eloquentai/chat-sdk 0.33.9-dev → 0.33.11-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,71 @@
1
+ /** Lambda-authorizer token (the chat token) or the API key fallback. */
2
+ export type AppSyncEventsAuth = {
3
+ authorizationToken: string;
4
+ } | {
5
+ apiKey: string;
6
+ };
7
+ export type AppSyncEventsConnection = {
8
+ /** Sends unsubscribe, closes the socket, and suppresses onDisconnect. */
9
+ close: () => void;
10
+ };
11
+ export type WebSocketLike = {
12
+ readyState: number;
13
+ send: (data: string) => void;
14
+ close: () => void;
15
+ addEventListener: (type: "open" | "message" | "close" | "error", listener: (event: {
16
+ data?: unknown;
17
+ }) => void) => void;
18
+ };
19
+ export type ConnectAppSyncEventsOptions = {
20
+ /** The HTTP Events endpoint from boot settings (chat_settings.app_sync_url). */
21
+ httpEndpoint: string;
22
+ auth: AppSyncEventsAuth;
23
+ /** Channel path, e.g. "/default/chat/<chatId>". */
24
+ channel: string;
25
+ /** Called once per published event, with the payload already JSON-parsed. */
26
+ onEvent: (event: unknown) => void;
27
+ /**
28
+ * Called exactly once when an established connection dies (server close,
29
+ * network drop, keep-alive timeout). NOT called after close(), and not
30
+ * called for connections that never established (connect() rejects there).
31
+ */
32
+ onDisconnect: (reason: string) => void;
33
+ /** Injectable for tests; defaults to the global WebSocket constructor. */
34
+ createWebSocket?: (url: string, protocols: string[]) => WebSocketLike;
35
+ };
36
+ export declare const APPSYNC_EVENTS_SUBPROTOCOL = "aws-appsync-event-ws";
37
+ /** connection_init → connection_ack and subscribe → subscribe_success wait. */
38
+ export declare const HANDSHAKE_TIMEOUT_MILLISECONDS = 15000;
39
+ /** Fallback keep-alive death window when the ack doesn't carry one. */
40
+ export declare const DEFAULT_CONNECTION_TIMEOUT_MILLISECONDS = 300000;
41
+ /** How often the keep-alive clock is checked. */
42
+ export declare const KEEP_ALIVE_CHECK_INTERVAL_MILLISECONDS = 5000;
43
+ /**
44
+ * Derives the realtime WebSocket URL from the HTTP Events endpoint.
45
+ * Standard AWS domains swap the service subdomain; custom domains keep the
46
+ * host and only append the path.
47
+ * https://xxx.appsync-api.us-east-1.amazonaws.com/event
48
+ * → wss://xxx.appsync-realtime-api.us-east-1.amazonaws.com/event/realtime
49
+ * https://events.example.com/event
50
+ * → wss://events.example.com/event/realtime
51
+ */
52
+ export declare function deriveRealtimeUrl(httpEndpoint: string): string;
53
+ /**
54
+ * The authorization object embedded both in the connect subprotocol header
55
+ * and in every subscribe message. `host` is always the HTTP endpoint's host
56
+ * (not the realtime host), per the protocol.
57
+ */
58
+ export declare function buildAuthorization(httpEndpoint: string, auth: AppSyncEventsAuth): Record<string, string>;
59
+ /**
60
+ * Encodes the authorization object into the `header-…` subprotocol value:
61
+ * base64url (`+`→`-`, `/`→`_`) with padding stripped — `=` is not a legal
62
+ * character in a Sec-WebSocket-Protocol token and fails the handshake.
63
+ */
64
+ export declare function encodeAuthProtocol(authorization: Record<string, string>): string;
65
+ /**
66
+ * Opens a connection and subscribes to one channel. Resolves once the
67
+ * subscription is confirmed; rejects if any handshake step fails or times
68
+ * out (the socket is closed in that case). After resolution, connection
69
+ * death is reported via onDisconnect exactly once.
70
+ */
71
+ export declare function connectAppSyncEvents(options: ConnectAppSyncEventsOptions): Promise<AppSyncEventsConnection>;
@@ -1,4 +1,3 @@
1
- export declare const LOGO_ANIMATED_URL: string;
2
1
  /**
3
2
  * Returns the API URL based on the provided custom URL or the default API URL.
4
3
  * @returns The API URL.
@@ -9,17 +8,3 @@ export declare function getApiUrl(): string;
9
8
  * @returns The Region API URL.
10
9
  */
11
10
  export declare function getRegionApiUrl(): string;
12
- /**
13
- * Returns the Amplify configuration for the API.
14
- * @returns The Amplify configuration.
15
- */
16
- export declare function amplifyConfig(appSyncUrl?: string | null, appSyncApiKey?: string | null, appSyncRegion?: string | null): {
17
- readonly API: {
18
- readonly Events: {
19
- readonly endpoint: string;
20
- readonly region: string;
21
- readonly defaultAuthMode: "apiKey";
22
- readonly apiKey: string;
23
- };
24
- };
25
- };