@eloquentai/chat-sdk 0.28.29-dev → 0.29.0-dev.1
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/README.md +146 -6
- package/dist/components/banner.d.ts +1 -1
- package/dist/components/chat/chat.d.ts +22 -0
- package/dist/components/chat/hooks/use-chat.d.ts +79 -0
- package/dist/components/chat/{interface-props.hook.d.ts → hooks/use-interface-props.d.ts} +2 -2
- package/dist/components/chat/hooks/use-keyboard-inset.d.ts +6 -0
- package/dist/components/chat/{message-events.hook.d.ts → hooks/use-message-events.d.ts} +5 -5
- package/dist/components/chat/{persistence.hook.d.ts → hooks/use-persistence.d.ts} +5 -2
- package/dist/components/chat/{realtime-socket.hook.d.ts → hooks/use-realtime-socket.d.ts} +5 -4
- package/dist/components/chat/hooks/use-scroll-lock.d.ts +6 -0
- package/dist/components/chat/{sdk-initialization.hook.d.ts → hooks/use-sdk-initialization.d.ts} +4 -2
- package/dist/components/chat/index.d.ts +1 -3
- package/dist/components/chat/message-mapping.d.ts +17 -0
- package/dist/components/chat/validations.d.ts +62 -74
- package/dist/components/chat-interface/chat-interface.d.ts +2 -0
- package/dist/components/chat-interface/content.d.ts +1 -1
- package/dist/components/chat-interface/context.d.ts +2 -2
- package/dist/components/chat-interface/footer.d.ts +1 -1
- package/dist/components/chat-interface/header.d.ts +1 -1
- package/dist/components/chat-interface/index.d.ts +2 -27
- package/dist/components/chat-interface/message-bubble/message-action-buttons.d.ts +6 -0
- package/dist/components/chat-interface/message-bubble/message-animation-state.d.ts +2 -0
- package/dist/components/chat-interface/message-bubble/message-bubble-item.d.ts +7 -0
- package/dist/components/{chat-message-bubble.d.ts → chat-interface/message-bubble/message-bubble.d.ts} +2 -2
- package/dist/components/{chat-rating-bubble.d.ts → chat-interface/rating-message-bubble.d.ts} +1 -1
- package/dist/components/chat-interface/shared.d.ts +11 -1
- package/dist/components/chat-interface/skeleton.d.ts +4 -2
- package/dist/components/chat-interface/suggested-messages.d.ts +20 -0
- package/dist/components/chat-interface/types.d.ts +56 -0
- package/dist/components/embed/chat-bubble.d.ts +6 -0
- package/dist/components/{iframe.d.ts → embed/iframe.d.ts} +1 -1
- package/dist/components/{portal.d.ts → embed/portal.d.ts} +2 -1
- package/dist/components/{chat → embed}/proactive-message.d.ts +1 -1
- package/dist/components/{render-chat.d.ts → embed/render-chat.d.ts} +1 -1
- package/dist/components/index.d.ts +2 -2
- package/dist/components/logo.d.ts +1 -1
- package/dist/components/ui/avatar.d.ts +3 -4
- package/dist/components/ui/card.d.ts +7 -7
- package/dist/components/ui/dialog.d.ts +11 -12
- package/dist/components/ui/markdown-viewer.d.ts +1 -1
- package/dist/components/ui/scroll-area.d.ts +5 -5
- package/dist/components/ui/skeleton.d.ts +2 -1
- package/dist/components/ui/star-rating.d.ts +1 -1
- package/dist/components/ui/textarea.d.ts +1 -2
- package/dist/contexts/{agent-cognition-context-definition.d.ts → agent-cognition/agent-cognition-context.d.ts} +1 -1
- package/dist/contexts/{agent-cognition.context.d.ts → agent-cognition/agent-cognition-provider.d.ts} +1 -1
- package/dist/contexts/{error-handling.utils.d.ts → error-handling/error-context.d.ts} +1 -1
- package/dist/contexts/{constants.d.ts → error-handling/error-messages.d.ts} +4 -0
- package/dist/contexts/error-handling/error-provider.d.ts +4 -0
- package/dist/contexts/theme.context.d.ts +14 -1
- package/dist/embed-loader.d.ts +35 -0
- package/dist/embed-loader.entry.d.ts +1 -0
- package/dist/hooks/use-debounce.d.ts +6 -0
- package/dist/hooks/use-drag-scroll.d.ts +5 -4
- package/dist/hooks/use-latest-ref.d.ts +9 -0
- package/dist/hooks/use-typed-text.d.ts +11 -0
- package/dist/index-hFbiYJI3.js +4165 -0
- package/dist/index-hFbiYJI3.js.map +1 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +2288 -7
- package/dist/index.mjs.map +1 -1
- package/dist/lib/appsync-events-client.d.ts +71 -0
- package/dist/lib/color-aura.d.ts +23 -0
- package/dist/lib/color-contrast.d.ts +13 -0
- package/dist/lib/config.d.ts +0 -15
- package/dist/lib/cookies.d.ts +13 -0
- package/dist/lib/eloquent-ai-api-client.d.ts +20 -2
- package/dist/lib/http.d.ts +3 -0
- package/dist/lib/retry.d.ts +10 -0
- package/dist/lib/utils.d.ts +0 -7
- package/dist/lib/wrap-promise.d.ts +7 -0
- package/dist/skeleton-ebiDTqw5.js +18959 -0
- package/dist/skeleton-ebiDTqw5.js.map +1 -0
- package/dist/ui.d.ts +10 -0
- package/dist/ui.mjs +19 -0
- package/dist/ui.mjs.map +1 -0
- package/package.json +59 -31
- package/dist/components/chat/chat.hook.d.ts +0 -47
- package/dist/components/chat-bubble.d.ts +0 -4
- package/dist/components/logo-animated.d.ts +0 -6
- package/dist/components/logo-squared.d.ts +0 -5
- package/dist/components/ui/input.d.ts +0 -3
- package/dist/components/ui/loading-ellipsis.d.ts +0 -1
- package/dist/components/ui/popover.d.ts +0 -6
- package/dist/contexts/error-handling.context.d.ts +0 -4
- package/dist/contexts/utils.d.ts +0 -2
- package/dist/hooks/useTypewriter.d.ts +0 -1
- package/dist/index-3AnUoCpF.js +0 -30693
- package/dist/index-3AnUoCpF.js.map +0 -1
- package/dist/index-DmtNxqna.js +0 -18793
- package/dist/index-DmtNxqna.js.map +0 -1
- /package/dist/components/chat/{ui-initialization.hook.d.ts → hooks/use-ui-initialization.d.ts} +0 -0
- /package/dist/components/chat/{user-identity.hook.d.ts → hooks/use-user-identity.d.ts} +0 -0
- /package/dist/{hooks → contexts/agent-cognition}/use-agent-cognition-context.d.ts +0 -0
- /package/dist/{hooks → contexts/agent-cognition}/use-agent-cognition.d.ts +0 -0
- /package/dist/hooks/{useFetch.d.ts → use-fetch.d.ts} +0 -0
- /package/dist/{type.d.ts → types/message.d.ts} +0 -0
|
@@ -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>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derives the two gradient stops for the suggested-message "aura" ring from a
|
|
3
|
+
* base color: one more saturated, one softer (less saturated, slightly
|
|
4
|
+
* lighter). The rotating conic gradient between them reads as an animated
|
|
5
|
+
* frame in the same hue family as the bubble background.
|
|
6
|
+
*/
|
|
7
|
+
export interface AuraColors {
|
|
8
|
+
/** More saturated variant of the base color. */
|
|
9
|
+
strong: string;
|
|
10
|
+
/** Softer (desaturated, lighter) variant of the base color. */
|
|
11
|
+
soft: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Returns the aura gradient stops for a base color. Both stops keep the base
|
|
15
|
+
* hue but are LIGHTER than the base — a saturation shift alone is invisible
|
|
16
|
+
* on already-saturated colors, where the ring would match the pill exactly,
|
|
17
|
+
* and a darkening ring reads as a shadow, which looks off in the chat UI.
|
|
18
|
+
* The lightness shift is capped near white so very light pills still get a
|
|
19
|
+
* (subtle) ring. Near-gray bases (e.g. the default muted pill background)
|
|
20
|
+
* also get a saturation nudge so the ring reads as a colour, not a shadow.
|
|
21
|
+
* Falls back to a neutral gray pair when the color cannot be parsed.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getAuraColors(baseColor: string | undefined | null): AuraColors;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WCAG-based text color selection: given a background color, returns black or
|
|
3
|
+
* white, whichever has the higher contrast ratio (WCAG 2.x relative
|
|
4
|
+
* luminance, https://www.w3.org/TR/WCAG21/#dfn-relative-luminance).
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Returns "#000000" or "#ffffff", whichever contrasts more with the given
|
|
8
|
+
* background color (WCAG 2.x relative luminance, biased toward white for
|
|
9
|
+
* saturated mid-tones — see BLACK_PREFERENCE_THRESHOLD). Supports #rgb,
|
|
10
|
+
* #rrggbb and rgb()/rgba() strings; falls back to black (the safer choice on
|
|
11
|
+
* light UI defaults) when unparseable.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getContrastingTextColor(backgroundColor: string | undefined | null): "#000000" | "#ffffff";
|
package/dist/lib/config.d.ts
CHANGED
|
@@ -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
|
-
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read a cookie value by name.
|
|
3
|
+
* @returns The decoded cookie value, or null if it doesn't exist or there's no document.
|
|
4
|
+
*/
|
|
5
|
+
export declare function getCookie(name: string): string | null;
|
|
6
|
+
/**
|
|
7
|
+
* Set a cookie with a given name, value, and TTL in hours.
|
|
8
|
+
*/
|
|
9
|
+
export declare function setCookie(name: string, value: string, hours: number): void;
|
|
10
|
+
/**
|
|
11
|
+
* Delete a cookie by name.
|
|
12
|
+
*/
|
|
13
|
+
export declare function deleteCookie(name: string): void;
|
|
@@ -10,6 +10,7 @@ export interface ConversationApiResponse {
|
|
|
10
10
|
}
|
|
11
11
|
export interface CreateConversationApiResponse {
|
|
12
12
|
chat_id: string;
|
|
13
|
+
chat_token: string;
|
|
13
14
|
}
|
|
14
15
|
export interface IdentifyUserApiResponse {
|
|
15
16
|
result: string;
|
|
@@ -41,20 +42,35 @@ export interface BootResponse {
|
|
|
41
42
|
welcome_message?: string | null;
|
|
42
43
|
footer_html?: string | null;
|
|
43
44
|
suggested_messages: boolean;
|
|
45
|
+
suggested_message_texts?: string[] | null;
|
|
46
|
+
suggested_message_aura?: boolean | null;
|
|
47
|
+
suggested_message_shine?: boolean | null;
|
|
44
48
|
auto_display_welcome_message: boolean;
|
|
45
49
|
collect_user_feedback: boolean;
|
|
46
50
|
theme: "light" | "dark";
|
|
47
51
|
avatar_url?: string | null;
|
|
48
52
|
user_bubble_color?: string | null;
|
|
53
|
+
bot_bubble_color?: string | null;
|
|
54
|
+
suggested_message_bubble_color?: string | null;
|
|
55
|
+
user_bubble_text_color?: string | null;
|
|
56
|
+
bot_bubble_text_color?: string | null;
|
|
57
|
+
suggested_message_bubble_text_color?: string | null;
|
|
49
58
|
app_sync_api_key: string;
|
|
50
|
-
app_sync_token?: string;
|
|
51
59
|
app_sync_url: string;
|
|
52
60
|
app_sync_region: string;
|
|
53
61
|
title?: string;
|
|
54
62
|
subtitle?: string;
|
|
63
|
+
is_active?: boolean;
|
|
64
|
+
/** Open the chat window on load (desktop only). Wins over the isInitiallyOpen prop, but a `true` here never overrides the user's closed-cookie. */
|
|
65
|
+
initial_open?: boolean | null;
|
|
66
|
+
/** Show the close (X) button in the chat header. Always wins over the hasCloseButton prop. */
|
|
67
|
+
close_button?: boolean | null;
|
|
68
|
+
/** Show the clear-conversation button in the chat header. Always wins over the hasCleanChatButton prop. */
|
|
69
|
+
clean_chat_button?: boolean | null;
|
|
70
|
+
/** Auto-hide delay for the proactive message, in milliseconds. Always wins over the proactiveMessageHideDelay prop. */
|
|
71
|
+
proactive_message_hide_delay?: number | null;
|
|
55
72
|
};
|
|
56
73
|
}
|
|
57
|
-
export declare function isChatClosedMessage(msg: MessageResponse): boolean;
|
|
58
74
|
export declare class EloquentAiApiClient {
|
|
59
75
|
private httpClient;
|
|
60
76
|
private userId;
|
|
@@ -69,6 +85,8 @@ export declare class EloquentAiApiClient {
|
|
|
69
85
|
*/
|
|
70
86
|
reset(): void;
|
|
71
87
|
setRegion(region: string): void;
|
|
88
|
+
getChatToken(): string | null;
|
|
89
|
+
setChatToken(token: string | null): void;
|
|
72
90
|
/**
|
|
73
91
|
* Get organization data by app ID
|
|
74
92
|
*/
|
package/dist/lib/http.d.ts
CHANGED
|
@@ -15,8 +15,11 @@ export declare class HttpClient {
|
|
|
15
15
|
private baseURL;
|
|
16
16
|
private headers;
|
|
17
17
|
private region;
|
|
18
|
+
private chatToken;
|
|
18
19
|
constructor(config: HttpClientConfig);
|
|
19
20
|
setRegion(region: string): void;
|
|
21
|
+
setChatToken(token: string | null): void;
|
|
22
|
+
getChatToken(): string | null;
|
|
20
23
|
private request;
|
|
21
24
|
get<T>(url: string): Promise<T>;
|
|
22
25
|
post<T, D>(url: string, data: D): Promise<T>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface WithRetryOptions {
|
|
2
|
+
retries?: number;
|
|
3
|
+
minDelayMs?: number;
|
|
4
|
+
maxDelayMs?: number;
|
|
5
|
+
factor?: number;
|
|
6
|
+
}
|
|
7
|
+
/** Retries on network errors and 5xx/429 responses; other errors bail immediately. */
|
|
8
|
+
export declare function isRetryableError(error: unknown): boolean;
|
|
9
|
+
export declare function withRetry<T>(operation: () => Promise<T>, options?: WithRetryOptions): Promise<T>;
|
|
10
|
+
export {};
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
1
|
import { ClassValue } from 'clsx';
|
|
2
|
-
import { ServerError } from './http';
|
|
3
2
|
export declare function cn(...inputs: ClassValue[]): string;
|
|
4
|
-
/**
|
|
5
|
-
* Wraps a Promise and returns a tuple containing the result or error
|
|
6
|
-
* @param promise Promise to wrap
|
|
7
|
-
* @returns [result, error] - result is null if error occurred, error is null if no error occurred
|
|
8
|
-
*/
|
|
9
|
-
export declare function wrapPromise<T, E = ServerError>(promise: Promise<T>): Promise<[T, null] | [null, E]>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ServerError } from './http';
|
|
2
|
+
/**
|
|
3
|
+
* Wraps a Promise and returns a tuple containing the result or error
|
|
4
|
+
* @param promise Promise to wrap
|
|
5
|
+
* @returns [result, error] - result is null if error occurred, error is null if no error occurred
|
|
6
|
+
*/
|
|
7
|
+
export declare function wrapPromise<T, E = ServerError>(promise: Promise<T>): Promise<[T, null] | [null, E]>;
|