@xcelsior/ui-chat 1.0.8 → 2.0.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/dist/index.d.mts +69 -69
- package/dist/index.d.ts +69 -69
- package/dist/index.js +2458 -627
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2457 -628
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -5
- package/src/components/BrandIcons.stories.tsx +95 -0
- package/src/components/BrandIcons.tsx +84 -0
- package/src/components/Chat.stories.tsx +149 -16
- package/src/components/Chat.tsx +116 -96
- package/src/components/ChatHeader.tsx +124 -69
- package/src/components/ChatInput.tsx +253 -104
- package/src/components/ChatWidget.tsx +209 -63
- package/src/components/ConversationRating.stories.tsx +33 -0
- package/src/components/ConversationRating.tsx +156 -0
- package/src/components/MarkdownMessage.tsx +202 -0
- package/src/components/MessageItem.stories.tsx +253 -55
- package/src/components/MessageItem.tsx +223 -60
- package/src/components/MessageList.tsx +164 -35
- package/src/components/PreChatForm.tsx +236 -96
- package/src/components/ThinkingIndicator.tsx +370 -0
- package/src/components/TypingIndicator.tsx +27 -11
- package/src/hooks/useDraggablePosition.ts +91 -0
- package/src/hooks/useMessages.ts +12 -13
- package/src/hooks/useResizableWidget.ts +324 -0
- package/src/index.tsx +5 -0
- package/src/types.ts +51 -5
- package/src/utils/markdown-styles.ts +140 -0
- package/storybook-static/assets/BrandIcons-Cjy5INAp.js +4 -0
- package/storybook-static/assets/BrandIcons.stories-BeVC6svr.js +64 -0
- package/storybook-static/assets/Chat.stories-J_Yp51wU.js +803 -0
- package/storybook-static/assets/Color-YHDXOIA2-BMnd3YrF.js +1 -0
- package/storybook-static/assets/ConversationRating.stories-B5_QddHN.js +12 -0
- package/storybook-static/assets/DocsRenderer-CFRXHY34-i_W8iCu9.js +575 -0
- package/storybook-static/assets/MessageItem-DAaKZ9s9.js +14 -0
- package/storybook-static/assets/MessageItem.stories-Ckr1_scc.js +255 -0
- package/storybook-static/assets/ToastContext-Bty1K7ya.js +1 -0
- package/storybook-static/assets/chunk-XP5HYGXS-BpfKkqn7.js +1 -0
- package/storybook-static/assets/en-US-BukEqXxE.js +1 -0
- package/storybook-static/assets/entry-preview-docs-DHohToDm.js +46 -0
- package/storybook-static/assets/entry-preview-oDnntGcx.js +2 -0
- package/storybook-static/assets/iframe-CGBtu2Se.js +211 -0
- package/storybook-static/assets/index--qcDGAq6.js +1 -0
- package/storybook-static/assets/index-BLHw34Di.js +24 -0
- package/storybook-static/assets/index-B_4m48Mv.js +1 -0
- package/storybook-static/assets/index-DgH-xKnr.js +11 -0
- package/storybook-static/assets/index-DrFu-skq.js +6 -0
- package/storybook-static/assets/index-DrdPSA1J.js +240 -0
- package/storybook-static/assets/index-jvNEZhzf.js +1 -0
- package/storybook-static/assets/index-yBjzXJbu.js +9 -0
- package/storybook-static/assets/jsx-runtime-Cf8x2fCZ.js +9 -0
- package/storybook-static/assets/preview-B8lJiyuQ.js +34 -0
- package/storybook-static/assets/preview-BBWR9nbA.js +1 -0
- package/storybook-static/assets/preview-BRpahs9B.js +2 -0
- package/storybook-static/assets/preview-BWzBA1C2.js +396 -0
- package/storybook-static/assets/preview-CvbIS5ZJ.js +1 -0
- package/storybook-static/assets/preview-DD_OYowb.js +1 -0
- package/storybook-static/assets/preview-DGUiP6tS.js +7 -0
- package/storybook-static/assets/preview-DHQbi4pV.js +1 -0
- package/storybook-static/assets/preview-DUOvJmsz.js +1 -0
- package/storybook-static/assets/preview-DcGwT3kv.css +1 -0
- package/storybook-static/assets/preview-DwI0w3cI.js +1 -0
- package/storybook-static/assets/react-18-CALspjOX.js +1 -0
- package/storybook-static/assets/test-utils-BE0XkMtV.js +9 -0
- package/storybook-static/favicon.svg +1 -0
- package/storybook-static/iframe.html +666 -0
- package/storybook-static/index.html +177 -0
- package/storybook-static/index.json +1 -0
- package/storybook-static/nunito-sans-bold-italic.woff2 +0 -0
- package/storybook-static/nunito-sans-bold.woff2 +0 -0
- package/storybook-static/nunito-sans-italic.woff2 +0 -0
- package/storybook-static/nunito-sans-regular.woff2 +0 -0
- package/storybook-static/project.json +1 -0
- package/storybook-static/sb-addons/essentials-actions-3/manager-bundle.js +3 -0
- package/storybook-static/sb-addons/essentials-backgrounds-5/manager-bundle.js +12 -0
- package/storybook-static/sb-addons/essentials-controls-2/manager-bundle.js +405 -0
- package/storybook-static/sb-addons/essentials-docs-4/manager-bundle.js +245 -0
- package/storybook-static/sb-addons/essentials-measure-8/manager-bundle.js +3 -0
- package/storybook-static/sb-addons/essentials-outline-9/manager-bundle.js +3 -0
- package/storybook-static/sb-addons/essentials-toolbars-7/manager-bundle.js +3 -0
- package/storybook-static/sb-addons/essentials-viewport-6/manager-bundle.js +3 -0
- package/storybook-static/sb-addons/interactions-10/manager-bundle.js +222 -0
- package/storybook-static/sb-addons/links-1/manager-bundle.js +3 -0
- package/storybook-static/sb-addons/storybook-core-core-server-presets-0/common-manager-bundle.js +3 -0
- package/storybook-static/sb-common-assets/favicon.svg +1 -0
- package/storybook-static/sb-common-assets/nunito-sans-bold-italic.woff2 +0 -0
- package/storybook-static/sb-common-assets/nunito-sans-bold.woff2 +0 -0
- package/storybook-static/sb-common-assets/nunito-sans-italic.woff2 +0 -0
- package/storybook-static/sb-common-assets/nunito-sans-regular.woff2 +0 -0
- package/storybook-static/sb-manager/globals-module-info.js +1052 -0
- package/storybook-static/sb-manager/globals-runtime.js +42127 -0
- package/storybook-static/sb-manager/globals.js +48 -0
- package/storybook-static/sb-manager/runtime.js +12048 -0
- package/.turbo/turbo-build.log +0 -22
- package/.turbo/turbo-lint.log +0 -5
package/dist/index.d.mts
CHANGED
|
@@ -13,14 +13,16 @@ interface IMessage {
|
|
|
13
13
|
id: string;
|
|
14
14
|
conversationId: string;
|
|
15
15
|
senderId: string;
|
|
16
|
-
senderType: 'customer' | 'agent' | 'system';
|
|
16
|
+
senderType: 'customer' | 'agent' | 'bot' | 'system';
|
|
17
17
|
content: string;
|
|
18
18
|
messageType: MessageType;
|
|
19
19
|
createdAt: string;
|
|
20
20
|
status: MessageStatus;
|
|
21
|
+
feedback?: 'good' | 'wrong' | 'corrected' | null;
|
|
22
|
+
confidence?: number | null;
|
|
21
23
|
metadata?: Record<string, unknown>;
|
|
22
24
|
}
|
|
23
|
-
type ConversationStatus = 'open' | 'pending' | 'closed' | 'archived';
|
|
25
|
+
type ConversationStatus = 'open' | 'pending' | 'closed' | 'archived' | 'bot_handling' | 'pending_agent' | 'agent_active';
|
|
24
26
|
type ConversationPriority = 'low' | 'medium' | 'high' | 'urgent';
|
|
25
27
|
type ConversationChannel = 'web' | 'mobile' | 'email';
|
|
26
28
|
interface IConversation {
|
|
@@ -42,7 +44,7 @@ interface IConversation {
|
|
|
42
44
|
metadata?: Record<string, unknown>;
|
|
43
45
|
}
|
|
44
46
|
interface IWebSocketMessage {
|
|
45
|
-
type: 'message' | 'typing' | 'read' | 'connected' | 'error' | 'system';
|
|
47
|
+
type: 'message' | 'typing' | 'read' | 'connected' | 'error' | 'system' | 'escalation_requested' | 'bot_response' | 'conversation_updated';
|
|
46
48
|
data: any;
|
|
47
49
|
}
|
|
48
50
|
interface ISendMessageData {
|
|
@@ -71,11 +73,25 @@ interface IUploadedFile {
|
|
|
71
73
|
type: string;
|
|
72
74
|
markdown?: string;
|
|
73
75
|
}
|
|
76
|
+
interface IChatTheme {
|
|
77
|
+
primary?: string;
|
|
78
|
+
primaryStrong?: string;
|
|
79
|
+
background?: string;
|
|
80
|
+
backgroundAlt?: string;
|
|
81
|
+
text?: string;
|
|
82
|
+
textMuted?: string;
|
|
83
|
+
statusPositive?: string;
|
|
84
|
+
statusCaution?: string;
|
|
85
|
+
statusNegative?: string;
|
|
86
|
+
borderColor?: string;
|
|
87
|
+
}
|
|
88
|
+
type WidgetPosition = 'left' | 'right' | 'auto';
|
|
89
|
+
type IdentityCollectionMode = 'progressive' | 'form' | 'none';
|
|
74
90
|
interface IChatConfig {
|
|
75
91
|
websocketUrl: string;
|
|
76
92
|
conversationId?: string;
|
|
77
93
|
apiKey: string;
|
|
78
|
-
currentUser
|
|
94
|
+
currentUser?: IUser;
|
|
79
95
|
fileUpload?: IFileUploadConfig;
|
|
80
96
|
httpApiUrl?: string;
|
|
81
97
|
headers?: Record<string, string>;
|
|
@@ -89,17 +105,33 @@ interface IChatConfig {
|
|
|
89
105
|
* @default false
|
|
90
106
|
*/
|
|
91
107
|
disableWebSocket?: boolean;
|
|
108
|
+
theme?: IChatTheme;
|
|
109
|
+
position?: WidgetPosition;
|
|
110
|
+
identityCollection?: IdentityCollectionMode;
|
|
92
111
|
onMessageSent?: (message: IMessage) => void;
|
|
93
112
|
onMessageReceived?: (message: IMessage) => void;
|
|
94
113
|
onConversationChange?: (conversation: IConversation) => void;
|
|
95
114
|
onConnectionChange?: (connected: boolean) => void;
|
|
96
115
|
onError?: (error: Error) => void;
|
|
116
|
+
onConversationRated?: (rating: 'positive' | 'negative') => void;
|
|
97
117
|
toast?: {
|
|
98
118
|
success: (message: string) => void;
|
|
99
119
|
error: (message: string) => void;
|
|
100
120
|
info: (message: string) => void;
|
|
101
121
|
};
|
|
102
122
|
}
|
|
123
|
+
interface UseMessagesReturn {
|
|
124
|
+
messages: IMessage[];
|
|
125
|
+
addMessage: (message: IMessage) => void;
|
|
126
|
+
updateMessageStatus: (messageId: string, status: IMessage['status']) => void;
|
|
127
|
+
clearMessages: () => void;
|
|
128
|
+
isLoading: boolean;
|
|
129
|
+
error: Error | null;
|
|
130
|
+
loadMore: () => Promise<void>;
|
|
131
|
+
hasMore: boolean;
|
|
132
|
+
isLoadingMore: boolean;
|
|
133
|
+
isBotThinking: boolean;
|
|
134
|
+
}
|
|
103
135
|
interface IApiResponse<T> {
|
|
104
136
|
success: boolean;
|
|
105
137
|
data?: T;
|
|
@@ -115,26 +147,14 @@ interface IApiResponse<T> {
|
|
|
115
147
|
interface ChatWidgetProps {
|
|
116
148
|
config: IChatConfig;
|
|
117
149
|
className?: string;
|
|
118
|
-
/**
|
|
119
|
-
* Variant of the chat widget:
|
|
120
|
-
* - 'popover': Fixed positioned floating widget (default)
|
|
121
|
-
* - 'fullPage': Full page layout that fills the container
|
|
122
|
-
*/
|
|
123
150
|
variant?: 'popover' | 'fullPage';
|
|
124
|
-
/**
|
|
125
|
-
* External WebSocket connection (for agents with global connection)
|
|
126
|
-
*/
|
|
127
151
|
externalWebSocket?: WebSocket | null;
|
|
128
|
-
/**
|
|
129
|
-
* Callback when user wants to minimize the widget
|
|
130
|
-
*/
|
|
131
152
|
onMinimize?: () => void;
|
|
132
|
-
/**
|
|
133
|
-
* Callback when user wants to close the widget
|
|
134
|
-
*/
|
|
135
153
|
onClose?: () => void;
|
|
154
|
+
/** Resolved position (left or right) from the parent Chat component */
|
|
155
|
+
resolvedPosition?: 'left' | 'right';
|
|
136
156
|
}
|
|
137
|
-
declare function ChatWidget({ config, className, variant, externalWebSocket, onMinimize, onClose, }: ChatWidgetProps): react_jsx_runtime.JSX.Element;
|
|
157
|
+
declare function ChatWidget({ config, className, variant, externalWebSocket, onMinimize, onClose, resolvedPosition, }: ChatWidgetProps): react_jsx_runtime.JSX.Element;
|
|
138
158
|
|
|
139
159
|
type ChatWidgetState = 'open' | 'minimized' | 'closed' | 'undefined';
|
|
140
160
|
interface UseChatWidgetStateOptions {
|
|
@@ -173,57 +193,25 @@ interface UseChatWidgetStateReturn {
|
|
|
173
193
|
declare function useChatWidgetState({ state: controlledState, defaultState, onStateChange, }: UseChatWidgetStateOptions): UseChatWidgetStateReturn;
|
|
174
194
|
|
|
175
195
|
interface ChatWidgetWrapperProps {
|
|
176
|
-
|
|
177
|
-
* Base configuration for the chat widget (without user info and conversationId)
|
|
178
|
-
*/
|
|
179
|
-
config: Omit<IChatConfig, 'currentUser' | 'conversationId' | 'userId'> & {
|
|
180
|
-
currentUser?: Partial<IUser>;
|
|
196
|
+
config: Omit<IChatConfig, 'conversationId'> & {
|
|
181
197
|
conversationId?: string;
|
|
182
198
|
};
|
|
183
|
-
/**
|
|
184
|
-
* Custom className for the wrapper
|
|
185
|
-
*/
|
|
186
199
|
className?: string;
|
|
187
|
-
/**
|
|
188
|
-
* Storage key prefix for persisting user data
|
|
189
|
-
* Defaults to 'xcelsior_chat'
|
|
190
|
-
*/
|
|
191
200
|
storageKeyPrefix?: string;
|
|
192
|
-
/**
|
|
193
|
-
* Callback when user submits the pre-chat form
|
|
194
|
-
*/
|
|
195
201
|
onPreChatSubmit?: (user: IUser) => void;
|
|
196
|
-
/**
|
|
197
|
-
* Controlled state. When provided, the component is controlled.
|
|
198
|
-
* - 'open': Fully open with chat interface
|
|
199
|
-
* - 'minimized': Show bubble button only
|
|
200
|
-
* - 'closed': Fully hidden
|
|
201
|
-
*/
|
|
202
202
|
state?: ChatWidgetState;
|
|
203
|
-
/**
|
|
204
|
-
* Default state for uncontrolled mode
|
|
205
|
-
* @default 'minimized'
|
|
206
|
-
*/
|
|
207
203
|
defaultState?: ChatWidgetState;
|
|
208
|
-
/**
|
|
209
|
-
* Callback when state changes
|
|
210
|
-
*/
|
|
211
204
|
onStateChange?: (state: ChatWidgetState) => void;
|
|
212
205
|
}
|
|
213
|
-
/**
|
|
214
|
-
* Chat component that handles:
|
|
215
|
-
* - Automatic conversation ID generation
|
|
216
|
-
* - Pre-chat form for collecting user information
|
|
217
|
-
* - Session persistence in localStorage
|
|
218
|
-
*/
|
|
219
206
|
declare function Chat({ config, className, storageKeyPrefix, onPreChatSubmit, state, defaultState, onStateChange, }: ChatWidgetWrapperProps): react_jsx_runtime.JSX.Element | null;
|
|
220
207
|
|
|
221
208
|
interface ChatHeaderProps {
|
|
222
209
|
agent?: IUser;
|
|
223
210
|
onClose?: () => void;
|
|
224
211
|
onMinimize?: () => void;
|
|
212
|
+
theme?: IChatTheme;
|
|
225
213
|
}
|
|
226
|
-
declare function ChatHeader({ agent, onClose, onMinimize }: ChatHeaderProps): react_jsx_runtime.JSX.Element;
|
|
214
|
+
declare function ChatHeader({ agent, onClose, onMinimize, theme }: ChatHeaderProps): react_jsx_runtime.JSX.Element;
|
|
227
215
|
|
|
228
216
|
interface UseFileUploadReturn {
|
|
229
217
|
uploadFile: (file: File) => Promise<IUploadedFile | null>;
|
|
@@ -243,13 +231,30 @@ interface ChatInputProps {
|
|
|
243
231
|
}
|
|
244
232
|
declare function ChatInput({ onSend, onTyping, config, fileUpload, disabled, }: ChatInputProps): react_jsx_runtime.JSX.Element;
|
|
245
233
|
|
|
234
|
+
interface MarkdownMessageProps {
|
|
235
|
+
content: string;
|
|
236
|
+
theme?: IChatTheme;
|
|
237
|
+
}
|
|
238
|
+
declare function MarkdownMessage({ content, theme }: MarkdownMessageProps): react_jsx_runtime.JSX.Element;
|
|
239
|
+
|
|
246
240
|
interface MessageItemProps {
|
|
247
241
|
message: IMessage;
|
|
248
242
|
currentUser: IUser;
|
|
249
243
|
showAvatar?: boolean;
|
|
250
244
|
showTimestamp?: boolean;
|
|
245
|
+
theme?: IChatTheme;
|
|
251
246
|
}
|
|
252
|
-
declare function MessageItem({ message, currentUser, showAvatar, showTimestamp, }: MessageItemProps): react_jsx_runtime.JSX.Element;
|
|
247
|
+
declare function MessageItem({ message, currentUser, showAvatar, showTimestamp, theme, }: MessageItemProps): react_jsx_runtime.JSX.Element;
|
|
248
|
+
|
|
249
|
+
interface ThinkingIndicatorProps {
|
|
250
|
+
/** Last message the user sent — used to pick contextual phrases */
|
|
251
|
+
lastUserMessage?: string;
|
|
252
|
+
/** Chat theme for color matching */
|
|
253
|
+
theme?: IChatTheme;
|
|
254
|
+
/** Show avatar next to the indicator */
|
|
255
|
+
showAvatar?: boolean;
|
|
256
|
+
}
|
|
257
|
+
declare function ThinkingIndicator({ lastUserMessage, theme, showAvatar, }: ThinkingIndicatorProps): react_jsx_runtime.JSX.Element;
|
|
253
258
|
|
|
254
259
|
interface MessageListProps {
|
|
255
260
|
messages: IMessage[];
|
|
@@ -261,8 +266,13 @@ interface MessageListProps {
|
|
|
261
266
|
onLoadMore?: () => void;
|
|
262
267
|
hasMore?: boolean;
|
|
263
268
|
isLoadingMore?: boolean;
|
|
269
|
+
theme?: IChatTheme;
|
|
270
|
+
/** Called when a quick-start action button is clicked — sends the text as a message */
|
|
271
|
+
onQuickAction?: (text: string) => void;
|
|
272
|
+
/** True when user sent a message and bot response hasn't arrived yet */
|
|
273
|
+
isBotThinking?: boolean;
|
|
264
274
|
}
|
|
265
|
-
declare function MessageList({ messages, currentUser, isLoading, isTyping, typingUser, autoScroll, onLoadMore, hasMore, isLoadingMore, }: MessageListProps): react_jsx_runtime.JSX.Element;
|
|
275
|
+
declare function MessageList({ messages, currentUser, isLoading, isTyping, typingUser, autoScroll, onLoadMore, hasMore, isLoadingMore, theme, onQuickAction, isBotThinking, }: MessageListProps): react_jsx_runtime.JSX.Element;
|
|
266
276
|
|
|
267
277
|
interface TypingIndicatorProps {
|
|
268
278
|
isTyping: boolean;
|
|
@@ -285,7 +295,8 @@ interface PreChatFormProps {
|
|
|
285
295
|
onClose: () => void;
|
|
286
296
|
}
|
|
287
297
|
/**
|
|
288
|
-
* PreChatForm component for collecting user information before starting chat
|
|
298
|
+
* PreChatForm component for collecting user information before starting chat.
|
|
299
|
+
* Styled to match the Xcelsior website design system.
|
|
289
300
|
*/
|
|
290
301
|
declare function PreChatForm({ onSubmit, className, initialName, initialEmail, onMinimize, onClose, }: PreChatFormProps): react_jsx_runtime.JSX.Element;
|
|
291
302
|
|
|
@@ -302,17 +313,6 @@ interface UseWebSocketReturn {
|
|
|
302
313
|
*/
|
|
303
314
|
declare function useWebSocket(config: IChatConfig, externalWebSocket?: WebSocket | null): UseWebSocketReturn;
|
|
304
315
|
|
|
305
|
-
interface UseMessagesReturn {
|
|
306
|
-
messages: IMessage[];
|
|
307
|
-
addMessage: (message: IMessage) => void;
|
|
308
|
-
updateMessageStatus: (messageId: string, status: IMessage['status']) => void;
|
|
309
|
-
clearMessages: () => void;
|
|
310
|
-
isLoading: boolean;
|
|
311
|
-
error: Error | null;
|
|
312
|
-
loadMore: () => Promise<void>;
|
|
313
|
-
hasMore: boolean;
|
|
314
|
-
isLoadingMore: boolean;
|
|
315
|
-
}
|
|
316
316
|
declare function useMessages(websocket: UseWebSocketReturn, config: IChatConfig): UseMessagesReturn;
|
|
317
317
|
|
|
318
318
|
interface UseTypingIndicatorReturn {
|
|
@@ -334,4 +334,4 @@ declare function fetchMessages(baseUrl: string, params: FetchMessagesParams, hea
|
|
|
334
334
|
nextPageToken: string | undefined;
|
|
335
335
|
}>;
|
|
336
336
|
|
|
337
|
-
export { Chat, ChatHeader, ChatInput, ChatWidget, type ChatWidgetProps, type ChatWidgetState, type ConversationChannel, type ConversationPriority, type ConversationStatus, type IApiResponse, type IChatConfig, type IConversation, type IFileUploadConfig, type IMessage, type IReadMessageData, type ISendMessageData, type ITypingData, type IUploadedFile, type IUser, type IWebSocketMessage, MessageItem, MessageList, type MessageStatus, type MessageType, PreChatForm, TypingIndicator, type UseChatWidgetStateOptions, type UseChatWidgetStateReturn, fetchMessages, useChatWidgetState, useFileUpload, useMessages, useTypingIndicator, useWebSocket };
|
|
337
|
+
export { Chat, ChatHeader, ChatInput, ChatWidget, type ChatWidgetProps, type ChatWidgetState, type ConversationChannel, type ConversationPriority, type ConversationStatus, type IApiResponse, type IChatConfig, type IConversation, type IFileUploadConfig, type IMessage, type IReadMessageData, type ISendMessageData, type ITypingData, type IUploadedFile, type IUser, type IWebSocketMessage, MarkdownMessage, MessageItem, MessageList, type MessageStatus, type MessageType, PreChatForm, ThinkingIndicator, type ThinkingIndicatorProps, TypingIndicator, type UseChatWidgetStateOptions, type UseChatWidgetStateReturn, type UseMessagesReturn, fetchMessages, useChatWidgetState, useFileUpload, useMessages, useTypingIndicator, useWebSocket };
|
package/dist/index.d.ts
CHANGED
|
@@ -13,14 +13,16 @@ interface IMessage {
|
|
|
13
13
|
id: string;
|
|
14
14
|
conversationId: string;
|
|
15
15
|
senderId: string;
|
|
16
|
-
senderType: 'customer' | 'agent' | 'system';
|
|
16
|
+
senderType: 'customer' | 'agent' | 'bot' | 'system';
|
|
17
17
|
content: string;
|
|
18
18
|
messageType: MessageType;
|
|
19
19
|
createdAt: string;
|
|
20
20
|
status: MessageStatus;
|
|
21
|
+
feedback?: 'good' | 'wrong' | 'corrected' | null;
|
|
22
|
+
confidence?: number | null;
|
|
21
23
|
metadata?: Record<string, unknown>;
|
|
22
24
|
}
|
|
23
|
-
type ConversationStatus = 'open' | 'pending' | 'closed' | 'archived';
|
|
25
|
+
type ConversationStatus = 'open' | 'pending' | 'closed' | 'archived' | 'bot_handling' | 'pending_agent' | 'agent_active';
|
|
24
26
|
type ConversationPriority = 'low' | 'medium' | 'high' | 'urgent';
|
|
25
27
|
type ConversationChannel = 'web' | 'mobile' | 'email';
|
|
26
28
|
interface IConversation {
|
|
@@ -42,7 +44,7 @@ interface IConversation {
|
|
|
42
44
|
metadata?: Record<string, unknown>;
|
|
43
45
|
}
|
|
44
46
|
interface IWebSocketMessage {
|
|
45
|
-
type: 'message' | 'typing' | 'read' | 'connected' | 'error' | 'system';
|
|
47
|
+
type: 'message' | 'typing' | 'read' | 'connected' | 'error' | 'system' | 'escalation_requested' | 'bot_response' | 'conversation_updated';
|
|
46
48
|
data: any;
|
|
47
49
|
}
|
|
48
50
|
interface ISendMessageData {
|
|
@@ -71,11 +73,25 @@ interface IUploadedFile {
|
|
|
71
73
|
type: string;
|
|
72
74
|
markdown?: string;
|
|
73
75
|
}
|
|
76
|
+
interface IChatTheme {
|
|
77
|
+
primary?: string;
|
|
78
|
+
primaryStrong?: string;
|
|
79
|
+
background?: string;
|
|
80
|
+
backgroundAlt?: string;
|
|
81
|
+
text?: string;
|
|
82
|
+
textMuted?: string;
|
|
83
|
+
statusPositive?: string;
|
|
84
|
+
statusCaution?: string;
|
|
85
|
+
statusNegative?: string;
|
|
86
|
+
borderColor?: string;
|
|
87
|
+
}
|
|
88
|
+
type WidgetPosition = 'left' | 'right' | 'auto';
|
|
89
|
+
type IdentityCollectionMode = 'progressive' | 'form' | 'none';
|
|
74
90
|
interface IChatConfig {
|
|
75
91
|
websocketUrl: string;
|
|
76
92
|
conversationId?: string;
|
|
77
93
|
apiKey: string;
|
|
78
|
-
currentUser
|
|
94
|
+
currentUser?: IUser;
|
|
79
95
|
fileUpload?: IFileUploadConfig;
|
|
80
96
|
httpApiUrl?: string;
|
|
81
97
|
headers?: Record<string, string>;
|
|
@@ -89,17 +105,33 @@ interface IChatConfig {
|
|
|
89
105
|
* @default false
|
|
90
106
|
*/
|
|
91
107
|
disableWebSocket?: boolean;
|
|
108
|
+
theme?: IChatTheme;
|
|
109
|
+
position?: WidgetPosition;
|
|
110
|
+
identityCollection?: IdentityCollectionMode;
|
|
92
111
|
onMessageSent?: (message: IMessage) => void;
|
|
93
112
|
onMessageReceived?: (message: IMessage) => void;
|
|
94
113
|
onConversationChange?: (conversation: IConversation) => void;
|
|
95
114
|
onConnectionChange?: (connected: boolean) => void;
|
|
96
115
|
onError?: (error: Error) => void;
|
|
116
|
+
onConversationRated?: (rating: 'positive' | 'negative') => void;
|
|
97
117
|
toast?: {
|
|
98
118
|
success: (message: string) => void;
|
|
99
119
|
error: (message: string) => void;
|
|
100
120
|
info: (message: string) => void;
|
|
101
121
|
};
|
|
102
122
|
}
|
|
123
|
+
interface UseMessagesReturn {
|
|
124
|
+
messages: IMessage[];
|
|
125
|
+
addMessage: (message: IMessage) => void;
|
|
126
|
+
updateMessageStatus: (messageId: string, status: IMessage['status']) => void;
|
|
127
|
+
clearMessages: () => void;
|
|
128
|
+
isLoading: boolean;
|
|
129
|
+
error: Error | null;
|
|
130
|
+
loadMore: () => Promise<void>;
|
|
131
|
+
hasMore: boolean;
|
|
132
|
+
isLoadingMore: boolean;
|
|
133
|
+
isBotThinking: boolean;
|
|
134
|
+
}
|
|
103
135
|
interface IApiResponse<T> {
|
|
104
136
|
success: boolean;
|
|
105
137
|
data?: T;
|
|
@@ -115,26 +147,14 @@ interface IApiResponse<T> {
|
|
|
115
147
|
interface ChatWidgetProps {
|
|
116
148
|
config: IChatConfig;
|
|
117
149
|
className?: string;
|
|
118
|
-
/**
|
|
119
|
-
* Variant of the chat widget:
|
|
120
|
-
* - 'popover': Fixed positioned floating widget (default)
|
|
121
|
-
* - 'fullPage': Full page layout that fills the container
|
|
122
|
-
*/
|
|
123
150
|
variant?: 'popover' | 'fullPage';
|
|
124
|
-
/**
|
|
125
|
-
* External WebSocket connection (for agents with global connection)
|
|
126
|
-
*/
|
|
127
151
|
externalWebSocket?: WebSocket | null;
|
|
128
|
-
/**
|
|
129
|
-
* Callback when user wants to minimize the widget
|
|
130
|
-
*/
|
|
131
152
|
onMinimize?: () => void;
|
|
132
|
-
/**
|
|
133
|
-
* Callback when user wants to close the widget
|
|
134
|
-
*/
|
|
135
153
|
onClose?: () => void;
|
|
154
|
+
/** Resolved position (left or right) from the parent Chat component */
|
|
155
|
+
resolvedPosition?: 'left' | 'right';
|
|
136
156
|
}
|
|
137
|
-
declare function ChatWidget({ config, className, variant, externalWebSocket, onMinimize, onClose, }: ChatWidgetProps): react_jsx_runtime.JSX.Element;
|
|
157
|
+
declare function ChatWidget({ config, className, variant, externalWebSocket, onMinimize, onClose, resolvedPosition, }: ChatWidgetProps): react_jsx_runtime.JSX.Element;
|
|
138
158
|
|
|
139
159
|
type ChatWidgetState = 'open' | 'minimized' | 'closed' | 'undefined';
|
|
140
160
|
interface UseChatWidgetStateOptions {
|
|
@@ -173,57 +193,25 @@ interface UseChatWidgetStateReturn {
|
|
|
173
193
|
declare function useChatWidgetState({ state: controlledState, defaultState, onStateChange, }: UseChatWidgetStateOptions): UseChatWidgetStateReturn;
|
|
174
194
|
|
|
175
195
|
interface ChatWidgetWrapperProps {
|
|
176
|
-
|
|
177
|
-
* Base configuration for the chat widget (without user info and conversationId)
|
|
178
|
-
*/
|
|
179
|
-
config: Omit<IChatConfig, 'currentUser' | 'conversationId' | 'userId'> & {
|
|
180
|
-
currentUser?: Partial<IUser>;
|
|
196
|
+
config: Omit<IChatConfig, 'conversationId'> & {
|
|
181
197
|
conversationId?: string;
|
|
182
198
|
};
|
|
183
|
-
/**
|
|
184
|
-
* Custom className for the wrapper
|
|
185
|
-
*/
|
|
186
199
|
className?: string;
|
|
187
|
-
/**
|
|
188
|
-
* Storage key prefix for persisting user data
|
|
189
|
-
* Defaults to 'xcelsior_chat'
|
|
190
|
-
*/
|
|
191
200
|
storageKeyPrefix?: string;
|
|
192
|
-
/**
|
|
193
|
-
* Callback when user submits the pre-chat form
|
|
194
|
-
*/
|
|
195
201
|
onPreChatSubmit?: (user: IUser) => void;
|
|
196
|
-
/**
|
|
197
|
-
* Controlled state. When provided, the component is controlled.
|
|
198
|
-
* - 'open': Fully open with chat interface
|
|
199
|
-
* - 'minimized': Show bubble button only
|
|
200
|
-
* - 'closed': Fully hidden
|
|
201
|
-
*/
|
|
202
202
|
state?: ChatWidgetState;
|
|
203
|
-
/**
|
|
204
|
-
* Default state for uncontrolled mode
|
|
205
|
-
* @default 'minimized'
|
|
206
|
-
*/
|
|
207
203
|
defaultState?: ChatWidgetState;
|
|
208
|
-
/**
|
|
209
|
-
* Callback when state changes
|
|
210
|
-
*/
|
|
211
204
|
onStateChange?: (state: ChatWidgetState) => void;
|
|
212
205
|
}
|
|
213
|
-
/**
|
|
214
|
-
* Chat component that handles:
|
|
215
|
-
* - Automatic conversation ID generation
|
|
216
|
-
* - Pre-chat form for collecting user information
|
|
217
|
-
* - Session persistence in localStorage
|
|
218
|
-
*/
|
|
219
206
|
declare function Chat({ config, className, storageKeyPrefix, onPreChatSubmit, state, defaultState, onStateChange, }: ChatWidgetWrapperProps): react_jsx_runtime.JSX.Element | null;
|
|
220
207
|
|
|
221
208
|
interface ChatHeaderProps {
|
|
222
209
|
agent?: IUser;
|
|
223
210
|
onClose?: () => void;
|
|
224
211
|
onMinimize?: () => void;
|
|
212
|
+
theme?: IChatTheme;
|
|
225
213
|
}
|
|
226
|
-
declare function ChatHeader({ agent, onClose, onMinimize }: ChatHeaderProps): react_jsx_runtime.JSX.Element;
|
|
214
|
+
declare function ChatHeader({ agent, onClose, onMinimize, theme }: ChatHeaderProps): react_jsx_runtime.JSX.Element;
|
|
227
215
|
|
|
228
216
|
interface UseFileUploadReturn {
|
|
229
217
|
uploadFile: (file: File) => Promise<IUploadedFile | null>;
|
|
@@ -243,13 +231,30 @@ interface ChatInputProps {
|
|
|
243
231
|
}
|
|
244
232
|
declare function ChatInput({ onSend, onTyping, config, fileUpload, disabled, }: ChatInputProps): react_jsx_runtime.JSX.Element;
|
|
245
233
|
|
|
234
|
+
interface MarkdownMessageProps {
|
|
235
|
+
content: string;
|
|
236
|
+
theme?: IChatTheme;
|
|
237
|
+
}
|
|
238
|
+
declare function MarkdownMessage({ content, theme }: MarkdownMessageProps): react_jsx_runtime.JSX.Element;
|
|
239
|
+
|
|
246
240
|
interface MessageItemProps {
|
|
247
241
|
message: IMessage;
|
|
248
242
|
currentUser: IUser;
|
|
249
243
|
showAvatar?: boolean;
|
|
250
244
|
showTimestamp?: boolean;
|
|
245
|
+
theme?: IChatTheme;
|
|
251
246
|
}
|
|
252
|
-
declare function MessageItem({ message, currentUser, showAvatar, showTimestamp, }: MessageItemProps): react_jsx_runtime.JSX.Element;
|
|
247
|
+
declare function MessageItem({ message, currentUser, showAvatar, showTimestamp, theme, }: MessageItemProps): react_jsx_runtime.JSX.Element;
|
|
248
|
+
|
|
249
|
+
interface ThinkingIndicatorProps {
|
|
250
|
+
/** Last message the user sent — used to pick contextual phrases */
|
|
251
|
+
lastUserMessage?: string;
|
|
252
|
+
/** Chat theme for color matching */
|
|
253
|
+
theme?: IChatTheme;
|
|
254
|
+
/** Show avatar next to the indicator */
|
|
255
|
+
showAvatar?: boolean;
|
|
256
|
+
}
|
|
257
|
+
declare function ThinkingIndicator({ lastUserMessage, theme, showAvatar, }: ThinkingIndicatorProps): react_jsx_runtime.JSX.Element;
|
|
253
258
|
|
|
254
259
|
interface MessageListProps {
|
|
255
260
|
messages: IMessage[];
|
|
@@ -261,8 +266,13 @@ interface MessageListProps {
|
|
|
261
266
|
onLoadMore?: () => void;
|
|
262
267
|
hasMore?: boolean;
|
|
263
268
|
isLoadingMore?: boolean;
|
|
269
|
+
theme?: IChatTheme;
|
|
270
|
+
/** Called when a quick-start action button is clicked — sends the text as a message */
|
|
271
|
+
onQuickAction?: (text: string) => void;
|
|
272
|
+
/** True when user sent a message and bot response hasn't arrived yet */
|
|
273
|
+
isBotThinking?: boolean;
|
|
264
274
|
}
|
|
265
|
-
declare function MessageList({ messages, currentUser, isLoading, isTyping, typingUser, autoScroll, onLoadMore, hasMore, isLoadingMore, }: MessageListProps): react_jsx_runtime.JSX.Element;
|
|
275
|
+
declare function MessageList({ messages, currentUser, isLoading, isTyping, typingUser, autoScroll, onLoadMore, hasMore, isLoadingMore, theme, onQuickAction, isBotThinking, }: MessageListProps): react_jsx_runtime.JSX.Element;
|
|
266
276
|
|
|
267
277
|
interface TypingIndicatorProps {
|
|
268
278
|
isTyping: boolean;
|
|
@@ -285,7 +295,8 @@ interface PreChatFormProps {
|
|
|
285
295
|
onClose: () => void;
|
|
286
296
|
}
|
|
287
297
|
/**
|
|
288
|
-
* PreChatForm component for collecting user information before starting chat
|
|
298
|
+
* PreChatForm component for collecting user information before starting chat.
|
|
299
|
+
* Styled to match the Xcelsior website design system.
|
|
289
300
|
*/
|
|
290
301
|
declare function PreChatForm({ onSubmit, className, initialName, initialEmail, onMinimize, onClose, }: PreChatFormProps): react_jsx_runtime.JSX.Element;
|
|
291
302
|
|
|
@@ -302,17 +313,6 @@ interface UseWebSocketReturn {
|
|
|
302
313
|
*/
|
|
303
314
|
declare function useWebSocket(config: IChatConfig, externalWebSocket?: WebSocket | null): UseWebSocketReturn;
|
|
304
315
|
|
|
305
|
-
interface UseMessagesReturn {
|
|
306
|
-
messages: IMessage[];
|
|
307
|
-
addMessage: (message: IMessage) => void;
|
|
308
|
-
updateMessageStatus: (messageId: string, status: IMessage['status']) => void;
|
|
309
|
-
clearMessages: () => void;
|
|
310
|
-
isLoading: boolean;
|
|
311
|
-
error: Error | null;
|
|
312
|
-
loadMore: () => Promise<void>;
|
|
313
|
-
hasMore: boolean;
|
|
314
|
-
isLoadingMore: boolean;
|
|
315
|
-
}
|
|
316
316
|
declare function useMessages(websocket: UseWebSocketReturn, config: IChatConfig): UseMessagesReturn;
|
|
317
317
|
|
|
318
318
|
interface UseTypingIndicatorReturn {
|
|
@@ -334,4 +334,4 @@ declare function fetchMessages(baseUrl: string, params: FetchMessagesParams, hea
|
|
|
334
334
|
nextPageToken: string | undefined;
|
|
335
335
|
}>;
|
|
336
336
|
|
|
337
|
-
export { Chat, ChatHeader, ChatInput, ChatWidget, type ChatWidgetProps, type ChatWidgetState, type ConversationChannel, type ConversationPriority, type ConversationStatus, type IApiResponse, type IChatConfig, type IConversation, type IFileUploadConfig, type IMessage, type IReadMessageData, type ISendMessageData, type ITypingData, type IUploadedFile, type IUser, type IWebSocketMessage, MessageItem, MessageList, type MessageStatus, type MessageType, PreChatForm, TypingIndicator, type UseChatWidgetStateOptions, type UseChatWidgetStateReturn, fetchMessages, useChatWidgetState, useFileUpload, useMessages, useTypingIndicator, useWebSocket };
|
|
337
|
+
export { Chat, ChatHeader, ChatInput, ChatWidget, type ChatWidgetProps, type ChatWidgetState, type ConversationChannel, type ConversationPriority, type ConversationStatus, type IApiResponse, type IChatConfig, type IConversation, type IFileUploadConfig, type IMessage, type IReadMessageData, type ISendMessageData, type ITypingData, type IUploadedFile, type IUser, type IWebSocketMessage, MarkdownMessage, MessageItem, MessageList, type MessageStatus, type MessageType, PreChatForm, ThinkingIndicator, type ThinkingIndicatorProps, TypingIndicator, type UseChatWidgetStateOptions, type UseChatWidgetStateReturn, type UseMessagesReturn, fetchMessages, useChatWidgetState, useFileUpload, useMessages, useTypingIndicator, useWebSocket };
|