@eloquentai/chat-sdk 0.29.0-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-DaMnFGD6.js +0 -18793
- package/dist/index-DaMnFGD6.js.map +0 -1
- package/dist/index-DySyj7Hm.js +0 -30694
- package/dist/index-DySyj7Hm.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
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ React SDK for integrating Eloquent AI's chat functionality into your application
|
|
|
4
4
|
|
|
5
5
|
## Prerequisites
|
|
6
6
|
|
|
7
|
-
- React 18 or higher
|
|
7
|
+
- React 18 or higher (only for the React implementation)
|
|
8
8
|
- Node.js 18 or higher
|
|
9
9
|
- A modern browser that supports ES6+
|
|
10
10
|
|
|
@@ -25,7 +25,7 @@ pnpm add @eloquentai/chat-sdk
|
|
|
25
25
|
|
|
26
26
|
### React Implementation
|
|
27
27
|
|
|
28
|
-
To use the SDK in a React application,
|
|
28
|
+
To use the SDK in a React application, import the `Chat` component from the SDK.
|
|
29
29
|
|
|
30
30
|
```jsx
|
|
31
31
|
import { Chat } from "@eloquentai/chat-sdk";
|
|
@@ -35,28 +35,168 @@ function App() {
|
|
|
35
35
|
<Chat
|
|
36
36
|
// REQUIRED - Your Eloquent AI app ID
|
|
37
37
|
appId="YOUR_APP_ID"
|
|
38
|
-
// OPTIONAL - You can provide
|
|
38
|
+
// OPTIONAL - You can provide a unique id that should be used to identify the user
|
|
39
39
|
userId={crypto.randomUUID()}
|
|
40
40
|
/>
|
|
41
41
|
);
|
|
42
42
|
}
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
+
Don't forget to import the base styles once, somewhere in your app:
|
|
46
|
+
|
|
47
|
+
```jsx
|
|
48
|
+
import "@eloquentai/chat-sdk/index.css";
|
|
49
|
+
```
|
|
50
|
+
|
|
45
51
|
### Vanilla Implementation
|
|
46
52
|
|
|
47
|
-
To use the SDK in a vanilla environment,
|
|
53
|
+
To use the SDK in a vanilla environment, include the script tag in your HTML file and call `renderChat`.
|
|
48
54
|
|
|
49
55
|
```html
|
|
50
56
|
<script src="https://unpkg.com/@eloquentai/chat-sdk"></script>
|
|
51
57
|
|
|
52
|
-
<div id="chat"></div>
|
|
58
|
+
<div id="chat-container"></div>
|
|
53
59
|
|
|
54
60
|
<script>
|
|
55
61
|
EloquentChatSDK.renderChat(document.getElementById("chat-container"), {
|
|
56
62
|
// REQUIRED - Your Eloquent AI app ID
|
|
57
63
|
appId: "YOUR_APP_ID",
|
|
58
|
-
// OPTIONAL - You can provide
|
|
64
|
+
// OPTIONAL - You can provide a unique id that should be used to identify the user
|
|
59
65
|
userId: crypto.randomUUID(),
|
|
60
66
|
});
|
|
61
67
|
</script>
|
|
62
68
|
```
|
|
69
|
+
|
|
70
|
+
`renderChat` returns an unmount function you can call to remove the chat widget:
|
|
71
|
+
|
|
72
|
+
```html
|
|
73
|
+
<script>
|
|
74
|
+
const unmount = EloquentChatSDK.renderChat(
|
|
75
|
+
document.getElementById("chat-container"),
|
|
76
|
+
{ appId: "YOUR_APP_ID" },
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
// Later, to remove the widget:
|
|
80
|
+
unmount();
|
|
81
|
+
</script>
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Features
|
|
85
|
+
|
|
86
|
+
- **Floating chat widget** — a launcher bubble plus chat window, rendered in an isolated iframe so host page styles never leak in or out.
|
|
87
|
+
- **Real-time messaging** — assistant replies stream in over a WebSocket connection (AWS AppSync), with automatic reconnect and a backup polling fallback if the socket drops.
|
|
88
|
+
- **Conversation persistence** — the active conversation is restored automatically (e.g. on page reload) via local storage.
|
|
89
|
+
- **User identification** — supports anonymous device-based identity as well as an optional external user ID and custom user metadata.
|
|
90
|
+
- **Proactive/welcome messages** — an optional message bubble can appear automatically to invite users to start a conversation.
|
|
91
|
+
- **Chat ratings** — users can rate a conversation after it's closed or escalated.
|
|
92
|
+
- **Human handoff / escalation** — the SDK recognizes when a conversation is escalated to a human agent and closes the AI chat session accordingly.
|
|
93
|
+
- **Theming** — customize bubble colors and legal text to match your brand.
|
|
94
|
+
- **Mobile responsive** — automatically adapts layout for mobile viewports.
|
|
95
|
+
|
|
96
|
+
## Configuration
|
|
97
|
+
|
|
98
|
+
### `Chat` component props
|
|
99
|
+
|
|
100
|
+
| Prop | Type | Required | Description |
|
|
101
|
+
| --------------------------- | --------------------------------------------- | -------- | -------------------------------------------------------------------------------------- |
|
|
102
|
+
| `appId` | `string` | Yes | Your Eloquent AI application ID. |
|
|
103
|
+
| `userId` | `string` | No | A unique identifier for the user. If omitted, an anonymous device ID is used instead. |
|
|
104
|
+
| `userName` | `string` | No | A display name for the user. |
|
|
105
|
+
| `userData` | `Record<string, string \| number \| boolean>` | No | Arbitrary metadata attached to the user/conversation (e.g. plan, account type). |
|
|
106
|
+
| `theme` | `Partial<ThemeContextType>` | No | Theming overrides — see [Theming](#theming) below. |
|
|
107
|
+
| `chatProps` | `Partial<ChatInterfaceProps>` | No | Fine-grained UI configuration — see [Chat interface options](#chat-interface-options). |
|
|
108
|
+
| `isMobile` | `boolean` | No | Force mobile layout instead of relying on automatic viewport detection. |
|
|
109
|
+
| `closeButton` | `boolean` (default: `true`) | No | Show/hide the close button in the chat header. |
|
|
110
|
+
| `cleanChatButton` | `boolean` (default: `true`) | No | Show/hide the "start new chat" button. |
|
|
111
|
+
| `initialOpen` | `boolean` (default: `false`) | No | Whether the chat window is open by default. |
|
|
112
|
+
| `proactiveMessageHideDelay` | `number` (default: `5000`) | No | Milliseconds before the proactive/welcome message auto-hides. |
|
|
113
|
+
|
|
114
|
+
### Chat interface options
|
|
115
|
+
|
|
116
|
+
Passed via the `chatProps` prop.
|
|
117
|
+
|
|
118
|
+
| Prop | Type | Description |
|
|
119
|
+
| ------------------------ | -------------------------------- | ----------------------------------------------------- |
|
|
120
|
+
| `displayWelcomeMessages` | `boolean` | Enable the proactive welcome message bubble. |
|
|
121
|
+
| `assistantName` | `string` | Name shown for the assistant in the chat header. |
|
|
122
|
+
| `assistantLogo` | `string` | URL of the logo shown for the assistant. |
|
|
123
|
+
| `legalText` | `string` | Legal/disclaimer text shown in the chat window. |
|
|
124
|
+
| `hasCopyButton` | `boolean` | Show the "copy message" button on assistant messages. |
|
|
125
|
+
| `collectUserFeedback` | `boolean` | Enable thumbs up/down feedback on assistant messages. |
|
|
126
|
+
| `suggestedMessages` | `boolean` | Show suggested message chips to the user. |
|
|
127
|
+
| `title` | `string` | Title shown in the chat header. |
|
|
128
|
+
| `subtitle` | `string` | Subtitle shown in the chat header. |
|
|
129
|
+
| `onMessageClick` | `(message: MessageData) => void` | Callback fired when a message is clicked. |
|
|
130
|
+
|
|
131
|
+
### Theming
|
|
132
|
+
|
|
133
|
+
```jsx
|
|
134
|
+
<Chat
|
|
135
|
+
appId="YOUR_APP_ID"
|
|
136
|
+
theme={{
|
|
137
|
+
userBubbleColor: "#6f34b7",
|
|
138
|
+
legalText: "Powered by Eloquent AI",
|
|
139
|
+
}}
|
|
140
|
+
/>
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
| Property | Description |
|
|
144
|
+
| ----------------- | ------------------------------------------------ |
|
|
145
|
+
| `userBubbleColor` | Background color of the end-user's chat bubbles. |
|
|
146
|
+
| `legalText` | Legal/disclaimer text rendered below the input. |
|
|
147
|
+
|
|
148
|
+
## Advanced usage
|
|
149
|
+
|
|
150
|
+
### `renderChat`
|
|
151
|
+
|
|
152
|
+
Programmatically mount the chat widget into any DOM element — used internally by the vanilla/UMD build, but also available from the ES module for non-JSX setups:
|
|
153
|
+
|
|
154
|
+
```js
|
|
155
|
+
import { renderChat } from "@eloquentai/chat-sdk";
|
|
156
|
+
|
|
157
|
+
const unmount = renderChat(document.getElementById("chat-container"), {
|
|
158
|
+
appId: "YOUR_APP_ID",
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### `ChatInterface`
|
|
163
|
+
|
|
164
|
+
The chat window UI without the floating launcher bubble or iframe isolation, for embedding the chat directly into your own layout (e.g. a dedicated support page).
|
|
165
|
+
|
|
166
|
+
```jsx
|
|
167
|
+
import { ChatInterface } from "@eloquentai/chat-sdk";
|
|
168
|
+
|
|
169
|
+
<ChatInterface
|
|
170
|
+
isOpen
|
|
171
|
+
closeButton={false}
|
|
172
|
+
cleanChatButton
|
|
173
|
+
messages={messages}
|
|
174
|
+
onSendMessage={onSendMessage}
|
|
175
|
+
/>;
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### `useRealtimeSocket`
|
|
179
|
+
|
|
180
|
+
A lower-level hook for subscribing directly to the real-time conversation event stream, if you need custom message handling outside of the provided components.
|
|
181
|
+
|
|
182
|
+
```jsx
|
|
183
|
+
import { useRealtimeSocket } from "@eloquentai/chat-sdk";
|
|
184
|
+
|
|
185
|
+
const { connect, disconnect, clearProcessedIds } = useRealtimeSocket({
|
|
186
|
+
chatSettings,
|
|
187
|
+
chatId,
|
|
188
|
+
messages,
|
|
189
|
+
onMessage: (response, chatId) => {
|
|
190
|
+
/* handle incoming assistant message */
|
|
191
|
+
},
|
|
192
|
+
onCognition: (content) => {
|
|
193
|
+
/* assistant is "thinking" */
|
|
194
|
+
},
|
|
195
|
+
onCognitionComplete: () => {},
|
|
196
|
+
fetchHistory: async (chatId) => [],
|
|
197
|
+
});
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Support
|
|
201
|
+
|
|
202
|
+
For issues, feature requests, or questions, please contact the Eloquent AI team.
|
|
@@ -2,5 +2,5 @@ interface BannerProps {
|
|
|
2
2
|
message: string;
|
|
3
3
|
type: "warning" | "error" | "info" | "success";
|
|
4
4
|
}
|
|
5
|
-
export declare const Banner: ({ message, type }: BannerProps) => import("react
|
|
5
|
+
export declare const Banner: ({ message, type }: BannerProps) => import("react").JSX.Element;
|
|
6
6
|
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Message } from '../../types/message';
|
|
2
|
+
import { UseChatProps } from './hooks/use-chat';
|
|
3
|
+
/** @internal */
|
|
4
|
+
type InternalChatProps = {
|
|
5
|
+
INTERNAL_ONLY_CHAT_INTERFACE_ONLY?: boolean;
|
|
6
|
+
INTERNAL_ONLY_BLOCK_STYLE?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Force the clear-chat button on or off, winning over both the boot
|
|
9
|
+
* `chat_settings.clean_chat_button` and the public `hasCleanChatButton`
|
|
10
|
+
* prop. Leave unset to keep the normal boot ?? prop resolution.
|
|
11
|
+
*/
|
|
12
|
+
INTERNAL_ONLY_SHOW_CLEAN_CHAT_BUTTON?: boolean;
|
|
13
|
+
/** Show the copy-message button on assistant messages (default false). */
|
|
14
|
+
INTERNAL_ONLY_SHOW_COPY_BUTTON?: boolean;
|
|
15
|
+
INTERNAL_ONLY_ENVIRONMENT?: "test" | "live";
|
|
16
|
+
INTERNAL_ONLY_API_URL?: string;
|
|
17
|
+
INTERNAL_ONLY_FEATURE_MESSAGE_CLICK?: (message: Message) => void;
|
|
18
|
+
INTERNAL_ONLY_FEATURE_CLEAR_CHAT_CLICK?: () => void;
|
|
19
|
+
};
|
|
20
|
+
export type ChatProps = UseChatProps & InternalChatProps;
|
|
21
|
+
export declare function Chat(props: Readonly<ChatProps>): import("react").JSX.Element;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Message, MessageData } from '../../../types/message';
|
|
2
|
+
import { ThemeContextType } from '../../../contexts/theme.context';
|
|
3
|
+
import { ChatInterfaceProps } from '../../chat-interface';
|
|
4
|
+
export interface UseChatProps {
|
|
5
|
+
appId: string;
|
|
6
|
+
userId?: string;
|
|
7
|
+
userName?: string;
|
|
8
|
+
userData?: Record<string, string | number | boolean>;
|
|
9
|
+
theme?: Partial<ThemeContextType>;
|
|
10
|
+
chatProps?: Partial<ChatInterfaceProps>;
|
|
11
|
+
isMobile?: boolean;
|
|
12
|
+
/** Show the close (X) button in the chat header. */
|
|
13
|
+
hasCloseButton?: boolean;
|
|
14
|
+
/** Show the clear-conversation button in the chat header. */
|
|
15
|
+
hasCleanChatButton?: boolean;
|
|
16
|
+
/** Open the chat window on load (desktop only). */
|
|
17
|
+
isInitiallyOpen?: boolean;
|
|
18
|
+
/** @deprecated Use `hasCloseButton` instead. Ignored when `hasCloseButton` is set. */
|
|
19
|
+
closeButton?: boolean;
|
|
20
|
+
/** @deprecated Use `hasCleanChatButton` instead. Ignored when `hasCleanChatButton` is set. */
|
|
21
|
+
cleanChatButton?: boolean;
|
|
22
|
+
/** @deprecated Use `isInitiallyOpen` instead. Ignored when `isInitiallyOpen` is set. */
|
|
23
|
+
initialOpen?: boolean;
|
|
24
|
+
proactiveMessageHideDelay?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface UseChatReturn {
|
|
27
|
+
isReady: boolean;
|
|
28
|
+
isChatActive: boolean;
|
|
29
|
+
/** Effective initial-open (boot chat_settings.initial_open ?? prop). */
|
|
30
|
+
isInitiallyOpen: boolean;
|
|
31
|
+
/** Effective close-button visibility (boot chat_settings.close_button ?? prop). */
|
|
32
|
+
hasCloseButton: boolean;
|
|
33
|
+
/** Effective clear-chat-button visibility (boot chat_settings.clean_chat_button ?? prop). */
|
|
34
|
+
hasCleanChatButton: boolean;
|
|
35
|
+
isMobile: boolean;
|
|
36
|
+
chatInterfaceProps: Partial<ChatInterfaceProps>;
|
|
37
|
+
chatOpen: boolean;
|
|
38
|
+
chatOpenDebounced: boolean;
|
|
39
|
+
messages: Message[];
|
|
40
|
+
portalContainer: HTMLElement | null;
|
|
41
|
+
onSendMessage: (message: MessageData) => Promise<void>;
|
|
42
|
+
setChatOpen: (value: boolean | ((prev: boolean) => boolean)) => void;
|
|
43
|
+
onCleanMessages: () => void;
|
|
44
|
+
proactiveMessage?: {
|
|
45
|
+
text: string;
|
|
46
|
+
isVisible: boolean;
|
|
47
|
+
autoHideDelay: number;
|
|
48
|
+
};
|
|
49
|
+
hideProactiveMessage: () => void;
|
|
50
|
+
isChatClosed: boolean;
|
|
51
|
+
onStartNewChat: () => void;
|
|
52
|
+
onRateChat: (rating: number) => Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The primary chat hook, responsible for managing the chat state and operations.
|
|
56
|
+
* @param options The hook parameters
|
|
57
|
+
* @returns The chat hook return type
|
|
58
|
+
*/
|
|
59
|
+
export declare function useChat({ environment, apiUrl, appId, userId: initialUserId, userName, userData, chatProps, isMobile: propIsMobile, isInitiallyOpen: propIsInitiallyOpen, hasCloseButton: propHasCloseButton, hasCleanChatButton: propHasCleanChatButton, initialOpen: deprecatedInitialOpen, closeButton: deprecatedCloseButton, cleanChatButton: deprecatedCleanChatButton, proactiveMessageHideDelay: propProactiveMessageHideDelay, isAlwaysOpen, hasCleanChatButtonOverride, }: Readonly<Partial<UseChatProps> & {
|
|
60
|
+
environment: "test" | "live";
|
|
61
|
+
apiUrl?: string;
|
|
62
|
+
appId: string;
|
|
63
|
+
/**
|
|
64
|
+
* Internal-only kill-switch (INTERNAL_ONLY_SHOW_CLEAN_CHAT_BUTTON): when
|
|
65
|
+
* set, wins over both the boot `chat_settings.clean_chat_button` and the
|
|
66
|
+
* `hasCleanChatButton` prop. Leave undefined for the normal boot ?? prop
|
|
67
|
+
* resolution.
|
|
68
|
+
*/
|
|
69
|
+
hasCleanChatButtonOverride?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Embedded mode (INTERNAL_ONLY_CHAT_INTERFACE_ONLY): the interface is the
|
|
72
|
+
* page content and there is no launcher bubble to reopen a closed chat, so
|
|
73
|
+
* open/close state does not apply — not the isInitiallyOpen prop, not the
|
|
74
|
+
* boot `chat_settings.initial_open`, and not the closed-cookie. Without
|
|
75
|
+
* this, a boot `initial_open: false` closes the widget from under the
|
|
76
|
+
* host page a moment after it renders.
|
|
77
|
+
*/
|
|
78
|
+
isAlwaysOpen?: boolean;
|
|
79
|
+
}>): UseChatReturn;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BootResponse } from '
|
|
2
|
-
import { ChatInterfaceProps } from '
|
|
1
|
+
import { BootResponse } from '../../../lib/eloquent-ai-api-client';
|
|
2
|
+
import { ChatInterfaceProps } from '../../chat-interface';
|
|
3
3
|
export interface UseInterfacePropsParams {
|
|
4
4
|
chatProps?: Partial<ChatInterfaceProps>;
|
|
5
5
|
chatSettings: BootResponse["chat_settings"] | null;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tracks how much the on-screen keyboard overlaps the layout viewport, using
|
|
3
|
+
* the VisualViewport API. Used to lift the chat input above the keyboard
|
|
4
|
+
* without moving/resizing the rest of the chat window.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useKeyboardInset(enabled: boolean): number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Message, MessageData } from '
|
|
3
|
-
import { BootResponse, EloquentAiApiClient } from '
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import { Message, MessageData } from '../../../types/message';
|
|
3
|
+
import { BootResponse, EloquentAiApiClient } from '../../../lib/eloquent-ai-api-client';
|
|
4
4
|
export interface UseMessageEventsProps {
|
|
5
5
|
appId: string;
|
|
6
6
|
userId: string;
|
|
@@ -11,11 +11,11 @@ export interface UseMessageEventsProps {
|
|
|
11
11
|
apiClient: EloquentAiApiClient | null;
|
|
12
12
|
chatSettings: BootResponse["chat_settings"] | null;
|
|
13
13
|
messages: Message[];
|
|
14
|
-
setMessages:
|
|
14
|
+
setMessages: Dispatch<SetStateAction<Message[]>>;
|
|
15
15
|
currentChat: {
|
|
16
16
|
id: string;
|
|
17
17
|
} | null;
|
|
18
|
-
setCurrentChat:
|
|
18
|
+
setCurrentChat: Dispatch<SetStateAction<{
|
|
19
19
|
id: string;
|
|
20
20
|
} | null>>;
|
|
21
21
|
onChatClosed?: () => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Message } from '
|
|
1
|
+
import { Message } from '../../../types/message';
|
|
2
2
|
export interface ChatData {
|
|
3
3
|
conversationId: string | null;
|
|
4
4
|
userId: string | null;
|
|
@@ -6,6 +6,8 @@ export interface ChatData {
|
|
|
6
6
|
deviceId: string | null;
|
|
7
7
|
messages: Message[];
|
|
8
8
|
lastActivity?: number;
|
|
9
|
+
isChatClosed?: boolean;
|
|
10
|
+
chatToken?: string | null;
|
|
9
11
|
}
|
|
10
12
|
/**
|
|
11
13
|
* Hook to manage persistence of chat data, including conversation ID, user ID, last activity time, and messages.
|
|
@@ -15,8 +17,9 @@ export declare function usePersistence({ appId }: {
|
|
|
15
17
|
appId: string;
|
|
16
18
|
}): {
|
|
17
19
|
isChatExpired: () => boolean;
|
|
18
|
-
saveChatData: (conversationId: string, userId: string, messages: Message[], deviceId: string) => void;
|
|
20
|
+
saveChatData: (conversationId: string, userId: string, messages: Message[], deviceId: string, chatToken?: string | null) => void;
|
|
19
21
|
clearChatData: () => void;
|
|
20
22
|
getSavedChatData: () => ChatData;
|
|
21
23
|
updateLastActivity: () => void;
|
|
24
|
+
markChatClosed: () => void;
|
|
22
25
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BootResponse, MessageResponse } from '
|
|
2
|
-
import { Message } from '
|
|
3
|
-
import { ChatResponse } from '
|
|
1
|
+
import { BootResponse, MessageResponse } from '../../../lib/eloquent-ai-api-client';
|
|
2
|
+
import { Message } from '../../../types/message';
|
|
3
|
+
import { ChatResponse } from '../validations';
|
|
4
4
|
export type UseRealtimeSocketOptions = {
|
|
5
5
|
chatSettings: BootResponse["chat_settings"] | null;
|
|
6
6
|
chatId: string | null;
|
|
@@ -16,6 +16,7 @@ export type UseRealtimeSocketOptions = {
|
|
|
16
16
|
onRatingRequest?: () => void;
|
|
17
17
|
onBreadcrumb?: () => void;
|
|
18
18
|
fetchHistory: (chatId: string) => Promise<MessageResponse[]>;
|
|
19
|
+
getChatToken: () => string | null;
|
|
19
20
|
backupPollingInterval?: number;
|
|
20
21
|
};
|
|
21
22
|
export type UseRealtimeSocketReturn = {
|
|
@@ -23,4 +24,4 @@ export type UseRealtimeSocketReturn = {
|
|
|
23
24
|
disconnect: () => void;
|
|
24
25
|
clearProcessedIds: () => void;
|
|
25
26
|
};
|
|
26
|
-
export declare function useRealtimeSocket({ chatSettings, chatId, messages, onMessage, onCognition, onCognitionComplete, onError, onChatClosed, onAgentCapturedUrl, onAgentTopic, onAgentSummary, onRatingRequest, onBreadcrumb, fetchHistory, backupPollingInterval, }: UseRealtimeSocketOptions): UseRealtimeSocketReturn;
|
|
27
|
+
export declare function useRealtimeSocket({ chatSettings, chatId, messages, onMessage, onCognition, onCognitionComplete, onError, onChatClosed, onAgentCapturedUrl, onAgentTopic, onAgentSummary, onRatingRequest, onBreadcrumb, fetchHistory, getChatToken, backupPollingInterval, }: UseRealtimeSocketOptions): UseRealtimeSocketReturn;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locks scrolling on the host page while active. Uses the fixed-body trick
|
|
3
|
+
* (rather than plain `overflow: hidden`) so it also holds on iOS Safari,
|
|
4
|
+
* which otherwise still allows background scroll/bounce behind the chat.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useScrollLock(locked: boolean): void;
|
package/dist/components/chat/{sdk-initialization.hook.d.ts → hooks/use-sdk-initialization.d.ts}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Message } from '
|
|
2
|
-
import { BootResponse, EloquentAiApiClient } from '
|
|
1
|
+
import { Message } from '../../../types/message';
|
|
2
|
+
import { BootResponse, EloquentAiApiClient } from '../../../lib/eloquent-ai-api-client';
|
|
3
3
|
export interface UseSdkInitializationProps {
|
|
4
4
|
environment: "test" | "live";
|
|
5
5
|
apiUrl?: string;
|
|
@@ -21,6 +21,8 @@ export interface UseSdkInitializationReturn {
|
|
|
21
21
|
} | null;
|
|
22
22
|
messages: Message[];
|
|
23
23
|
isReady: boolean;
|
|
24
|
+
isChatClosed: boolean;
|
|
25
|
+
isChatActive: boolean;
|
|
24
26
|
}
|
|
25
27
|
/**
|
|
26
28
|
* Hook to handle SDK initialization for the EloquentAI Chat SDK
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ChatResponse } from './validations';
|
|
2
|
+
import { Message } from '../../types/message';
|
|
3
|
+
/**
|
|
4
|
+
* The single place where API/wire shapes become domain `Message`s.
|
|
5
|
+
*
|
|
6
|
+
* Everything here is a pure function: the hooks own state and timing, this
|
|
7
|
+
* module owns shape. A backend field change should only ever touch this file
|
|
8
|
+
* (and validations.ts), not the hooks.
|
|
9
|
+
*/
|
|
10
|
+
/** A realtime/polled assistant reply, as appended to the transcript. */
|
|
11
|
+
export declare function messageFromChatResponse(response: ChatResponse): Message;
|
|
12
|
+
/** The configured welcome message, shown before any conversation exists. */
|
|
13
|
+
export declare function createWelcomeMessage(content: string): Message;
|
|
14
|
+
/** The star-rating prompt appended when the server requests feedback. */
|
|
15
|
+
export declare function createRatingRequestMessage(): Message;
|
|
16
|
+
/** The notice shown when the user writes into a closed conversation. */
|
|
17
|
+
export declare function createChatClosedNoticeMessage(): Message;
|
|
@@ -1,60 +1,67 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare const chatResponseApiSchema: z.
|
|
3
|
-
message_id: z.
|
|
4
|
-
created_at: z.
|
|
5
|
-
data: z.
|
|
6
|
-
type: z.
|
|
7
|
-
content: z.
|
|
8
|
-
role: z.
|
|
1
|
+
import * as z from "zod/mini";
|
|
2
|
+
export declare const chatResponseApiSchema: z.ZodMiniUnion<readonly [z.ZodMiniObject<{
|
|
3
|
+
message_id: z.ZodMiniNullable<z.ZodMiniString<string>>;
|
|
4
|
+
created_at: z.ZodMiniString<string>;
|
|
5
|
+
data: z.ZodMiniObject<{
|
|
6
|
+
type: z.ZodMiniLiteral<"utterance">;
|
|
7
|
+
content: z.ZodMiniString<string>;
|
|
8
|
+
role: z.ZodMiniString<string>;
|
|
9
9
|
}, z.core.$strip>;
|
|
10
|
-
}, z.core.$strip>, z.
|
|
11
|
-
created_at: z.
|
|
12
|
-
data: z.
|
|
13
|
-
type: z.
|
|
14
|
-
code: z.
|
|
10
|
+
}, z.core.$strip>, z.ZodMiniObject<{
|
|
11
|
+
created_at: z.ZodMiniString<string>;
|
|
12
|
+
data: z.ZodMiniObject<{
|
|
13
|
+
type: z.ZodMiniLiteral<"error">;
|
|
14
|
+
code: z.ZodMiniString<string>;
|
|
15
15
|
}, z.core.$strip>;
|
|
16
|
-
}, z.core.$strip>, z.
|
|
17
|
-
created_at: z.
|
|
18
|
-
data: z.
|
|
19
|
-
type: z.
|
|
20
|
-
content: z.
|
|
16
|
+
}, z.core.$strip>, z.ZodMiniObject<{
|
|
17
|
+
created_at: z.ZodMiniString<string>;
|
|
18
|
+
data: z.ZodMiniObject<{
|
|
19
|
+
type: z.ZodMiniLiteral<"agent_cognition">;
|
|
20
|
+
content: z.ZodMiniString<string>;
|
|
21
21
|
}, z.core.$strip>;
|
|
22
|
-
}, z.core.$strip>, z.
|
|
23
|
-
created_at: z.
|
|
24
|
-
data: z.
|
|
25
|
-
type: z.
|
|
26
|
-
content: z.
|
|
22
|
+
}, z.core.$strip>, z.ZodMiniObject<{
|
|
23
|
+
created_at: z.ZodMiniString<string>;
|
|
24
|
+
data: z.ZodMiniObject<{
|
|
25
|
+
type: z.ZodMiniLiteral<"agent_captured_url">;
|
|
26
|
+
content: z.ZodMiniString<string>;
|
|
27
27
|
}, z.core.$strip>;
|
|
28
|
-
}, z.core.$strip>, z.
|
|
29
|
-
created_at: z.
|
|
30
|
-
data: z.
|
|
31
|
-
type: z.
|
|
32
|
-
content: z.
|
|
28
|
+
}, z.core.$strip>, z.ZodMiniObject<{
|
|
29
|
+
created_at: z.ZodMiniString<string>;
|
|
30
|
+
data: z.ZodMiniObject<{
|
|
31
|
+
type: z.ZodMiniLiteral<"agent_topic">;
|
|
32
|
+
content: z.ZodMiniString<string>;
|
|
33
33
|
}, z.core.$strip>;
|
|
34
|
-
}, z.core.$strip>, z.
|
|
35
|
-
created_at: z.
|
|
36
|
-
data: z.
|
|
37
|
-
type: z.
|
|
38
|
-
content: z.
|
|
34
|
+
}, z.core.$strip>, z.ZodMiniObject<{
|
|
35
|
+
created_at: z.ZodMiniString<string>;
|
|
36
|
+
data: z.ZodMiniObject<{
|
|
37
|
+
type: z.ZodMiniLiteral<"agent_summary">;
|
|
38
|
+
content: z.ZodMiniString<string>;
|
|
39
39
|
}, z.core.$strip>;
|
|
40
|
-
}, z.core.$strip>, z.
|
|
41
|
-
message_id: z.
|
|
42
|
-
created_at: z.
|
|
43
|
-
data: z.
|
|
44
|
-
type: z.
|
|
45
|
-
content: z.
|
|
40
|
+
}, z.core.$strip>, z.ZodMiniObject<{
|
|
41
|
+
message_id: z.ZodMiniNullable<z.ZodMiniString<string>>;
|
|
42
|
+
created_at: z.ZodMiniString<string>;
|
|
43
|
+
data: z.ZodMiniObject<{
|
|
44
|
+
type: z.ZodMiniLiteral<"chat_closed_expired">;
|
|
45
|
+
content: z.ZodMiniString<string>;
|
|
46
46
|
}, z.core.$strip>;
|
|
47
|
-
}, z.core.$strip>, z.
|
|
48
|
-
created_at: z.
|
|
49
|
-
data: z.
|
|
50
|
-
type: z.
|
|
51
|
-
content: z.
|
|
47
|
+
}, z.core.$strip>, z.ZodMiniObject<{
|
|
48
|
+
created_at: z.ZodMiniString<string>;
|
|
49
|
+
data: z.ZodMiniObject<{
|
|
50
|
+
type: z.ZodMiniLiteral<"chat_rating">;
|
|
51
|
+
content: z.ZodMiniString<string>;
|
|
52
52
|
}, z.core.$strip>;
|
|
53
|
-
}, z.core.$strip>, z.
|
|
54
|
-
created_at: z.
|
|
55
|
-
data: z.
|
|
56
|
-
type: z.
|
|
57
|
-
content: z.
|
|
53
|
+
}, z.core.$strip>, z.ZodMiniObject<{
|
|
54
|
+
created_at: z.ZodMiniString<string>;
|
|
55
|
+
data: z.ZodMiniObject<{
|
|
56
|
+
type: z.ZodMiniLiteral<"breadcrumb">;
|
|
57
|
+
content: z.ZodMiniString<string>;
|
|
58
|
+
}, z.core.$strip>;
|
|
59
|
+
}, z.core.$strip>, z.ZodMiniObject<{
|
|
60
|
+
message_id: z.ZodMiniNullable<z.ZodMiniString<string>>;
|
|
61
|
+
created_at: z.ZodMiniString<string>;
|
|
62
|
+
data: z.ZodMiniObject<{
|
|
63
|
+
type: z.ZodMiniLiteral<"chat_escalated">;
|
|
64
|
+
content: z.ZodMiniNull;
|
|
58
65
|
}, z.core.$strip>;
|
|
59
66
|
}, z.core.$strip>]>;
|
|
60
67
|
export type ChatResponseApi = z.infer<typeof chatResponseApiSchema>;
|
|
@@ -96,31 +103,12 @@ export type AgentSummaryNotification = {
|
|
|
96
103
|
type: "agent_summary";
|
|
97
104
|
}>;
|
|
98
105
|
};
|
|
99
|
-
export
|
|
100
|
-
message_id: string
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
type:
|
|
104
|
-
|
|
105
|
-
};
|
|
106
|
-
export type ChatRatingNotification = {
|
|
107
|
-
created_at: string;
|
|
108
|
-
data: Extract<NotificationData, {
|
|
109
|
-
type: "chat_rating";
|
|
110
|
-
}>;
|
|
111
|
-
};
|
|
112
|
-
export type BreadcrumbNotification = {
|
|
113
|
-
created_at: string;
|
|
114
|
-
data: Extract<NotificationData, {
|
|
115
|
-
type: "breadcrumb";
|
|
116
|
-
}>;
|
|
117
|
-
};
|
|
118
|
-
export declare const chatResponseSchema: z.ZodObject<{
|
|
119
|
-
message_id: z.ZodString;
|
|
120
|
-
response: z.ZodObject<{
|
|
121
|
-
id: z.ZodString;
|
|
122
|
-
type: z.ZodString;
|
|
123
|
-
content: z.ZodString;
|
|
106
|
+
export declare const chatResponseSchema: z.ZodMiniObject<{
|
|
107
|
+
message_id: z.ZodMiniString<string>;
|
|
108
|
+
response: z.ZodMiniObject<{
|
|
109
|
+
id: z.ZodMiniString<string>;
|
|
110
|
+
type: z.ZodMiniString<string>;
|
|
111
|
+
content: z.ZodMiniString<string>;
|
|
124
112
|
}, z.core.$strip>;
|
|
125
113
|
}, z.core.$strip>;
|
|
126
114
|
export type ChatResponse = z.infer<typeof chatResponseSchema>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function ChatInterfaceContent(): import("react
|
|
1
|
+
export declare function ChatInterfaceContent(): import("react").JSX.Element;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
|
-
import { ChatInterfaceProps } from '
|
|
2
|
+
import { ChatInterfaceProps } from './types';
|
|
3
3
|
declare const ChatContext: import('react').Context<ChatInterfaceProps | undefined>;
|
|
4
|
-
export declare function ChatInterfaceProvider({ children, ...props }: PropsWithChildren<ChatInterfaceProps>): import("react
|
|
4
|
+
export declare function ChatInterfaceProvider({ children, ...props }: PropsWithChildren<ChatInterfaceProps>): import("react").JSX.Element;
|
|
5
5
|
export declare function useChatInterfaceContext(): ChatInterfaceProps;
|
|
6
6
|
export { ChatContext, type ChatInterfaceProps };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function ChatInterfaceFooter(): import("react
|
|
1
|
+
export declare function ChatInterfaceFooter(): import("react").JSX.Element;
|