@ihoomanai/chat-widget 2.0.0

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/src/types.ts ADDED
@@ -0,0 +1,301 @@
1
+ /**
2
+ * Type definitions for @ihooman/chat-widget
3
+ */
4
+
5
+ /**
6
+ * Theme configuration for the widget appearance
7
+ */
8
+ export interface ThemeConfig {
9
+ /** Primary brand color */
10
+ primaryColor?: string;
11
+ /** Gradient start color */
12
+ gradientFrom?: string;
13
+ /** Gradient end color */
14
+ gradientTo?: string;
15
+ /** Header background color */
16
+ headerBackground?: string;
17
+ /** Header text color */
18
+ headerTextColor?: string;
19
+ /** User message background */
20
+ userMessageBg?: string;
21
+ /** User message text color */
22
+ userMessageText?: string;
23
+ /** Bot message background */
24
+ botMessageBg?: string;
25
+ /** Bot message text color */
26
+ botMessageText?: string;
27
+ /** Font family */
28
+ fontFamily?: string;
29
+ /** Border radius for UI elements */
30
+ borderRadius?: string;
31
+ }
32
+
33
+ /**
34
+ * Behavior configuration for widget functionality
35
+ */
36
+ export interface BehaviorConfig {
37
+ /** Whether to start with the widget open */
38
+ startOpen?: boolean;
39
+ /** Show typing indicator when bot is responding */
40
+ showTypingIndicator?: boolean;
41
+ /** Show timestamps on messages */
42
+ showTimestamps?: boolean;
43
+ /** Enable notification sounds */
44
+ enableSounds?: boolean;
45
+ /** Enable file upload functionality */
46
+ enableFileUpload?: boolean;
47
+ /** Persist chat session across page reloads */
48
+ persistSession?: boolean;
49
+ }
50
+
51
+ /**
52
+ * Branding configuration
53
+ */
54
+ export interface BrandingConfig {
55
+ /** Custom logo URL */
56
+ logoUrl?: string | null;
57
+ /** Custom avatar URL for bot messages */
58
+ avatarUrl?: string | null;
59
+ /** Show "Powered by Ihooman" branding */
60
+ poweredBy?: boolean;
61
+ }
62
+
63
+ /**
64
+ * Main widget configuration options
65
+ */
66
+ export interface WidgetConfig {
67
+ /**
68
+ * Widget ID for initialization (required)
69
+ * Format: wgt_[12-alphanumeric-characters]
70
+ * Obtain from your Ihooman dashboard
71
+ */
72
+ widgetId: string;
73
+
74
+ /**
75
+ * Server URL for the widget API
76
+ * Defaults to production Ihooman API
77
+ */
78
+ serverUrl?: string;
79
+
80
+ /** Widget color theme */
81
+ theme?: 'light' | 'dark';
82
+
83
+ /** Widget position on the page */
84
+ position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
85
+
86
+ /** Widget title displayed in header */
87
+ title?: string;
88
+
89
+ /** Subtitle displayed in header */
90
+ subtitle?: string;
91
+
92
+ /** Welcome message shown when chat opens */
93
+ welcomeMessage?: string;
94
+
95
+ /** Placeholder text for input field */
96
+ placeholder?: string;
97
+
98
+ /** Primary brand color */
99
+ primaryColor?: string;
100
+
101
+ /** Gradient start color */
102
+ gradientFrom?: string;
103
+
104
+ /** Gradient end color */
105
+ gradientTo?: string;
106
+
107
+ /** Show timestamps on messages */
108
+ showTimestamps?: boolean;
109
+
110
+ /** Show typing indicator */
111
+ showTypingIndicator?: boolean;
112
+
113
+ /** Enable notification sounds */
114
+ enableSounds?: boolean;
115
+
116
+ /** Enable file upload */
117
+ enableFileUpload?: boolean;
118
+
119
+ /** Start with widget open */
120
+ startOpen?: boolean;
121
+
122
+ /** Persist session across page reloads */
123
+ persistSession?: boolean;
124
+
125
+ /** Z-index for widget positioning */
126
+ zIndex?: number;
127
+
128
+ /** Widget width in pixels */
129
+ width?: number;
130
+
131
+ /** Widget height in pixels */
132
+ height?: number;
133
+
134
+ /** Toggle button size in pixels */
135
+ buttonSize?: number;
136
+
137
+ /** Border radius in pixels */
138
+ borderRadius?: number;
139
+
140
+ /** Font family */
141
+ fontFamily?: string;
142
+
143
+ /** Custom avatar URL */
144
+ avatarUrl?: string;
145
+
146
+ /** Show powered by branding */
147
+ poweredBy?: boolean;
148
+
149
+ /** Callback when widget is ready */
150
+ onReady?: () => void;
151
+
152
+ /** Callback when widget opens */
153
+ onOpen?: () => void;
154
+
155
+ /** Callback when widget closes */
156
+ onClose?: () => void;
157
+
158
+ /** Callback when a message is sent or received */
159
+ onMessage?: (message: Message) => void;
160
+
161
+ /** Callback when an error occurs */
162
+ onError?: (error: Error) => void;
163
+ }
164
+
165
+ /**
166
+ * User information for personalization
167
+ */
168
+ export interface UserInfo {
169
+ /** User's display name */
170
+ name?: string;
171
+ /** User's email address */
172
+ email?: string;
173
+ /** Additional metadata */
174
+ metadata?: Record<string, string>;
175
+ }
176
+
177
+ /**
178
+ * Chat message structure
179
+ */
180
+ export interface Message {
181
+ /** Unique message ID */
182
+ id: string;
183
+ /** Message content */
184
+ content: string;
185
+ /** Message sender type */
186
+ sender: 'user' | 'bot';
187
+ /** Message timestamp */
188
+ timestamp: Date;
189
+ /** Additional message metadata */
190
+ metadata?: {
191
+ /** Source documents for RAG responses */
192
+ sources?: Array<{
193
+ title: string;
194
+ url?: string;
195
+ }>;
196
+ /** Confidence score for AI responses */
197
+ confidence?: number;
198
+ };
199
+ }
200
+
201
+ /**
202
+ * Widget state information
203
+ */
204
+ export interface WidgetState {
205
+ /** Whether the widget window is open */
206
+ isOpen: boolean;
207
+ /** Whether connected to the server */
208
+ isConnected: boolean;
209
+ /** Chat message history */
210
+ messages: Message[];
211
+ /** Current session ID */
212
+ sessionId: string | null;
213
+ /** Visitor ID */
214
+ visitorId: string | null;
215
+ /** Number of unread messages */
216
+ unreadCount: number;
217
+ }
218
+
219
+ /**
220
+ * Widget event types
221
+ */
222
+ export type WidgetEvent = 'ready' | 'open' | 'close' | 'message' | 'error';
223
+
224
+ /**
225
+ * Event callback function type
226
+ */
227
+ export type EventCallback = (data?: unknown) => void;
228
+
229
+ /**
230
+ * Public API interface for the Ihooman Chat Widget
231
+ */
232
+ export interface IhoomanChatAPI {
233
+ /**
234
+ * Initialize the widget with configuration
235
+ * @param config - Widget configuration options
236
+ * @returns Promise that resolves when widget is ready
237
+ */
238
+ init(config: WidgetConfig): Promise<IhoomanChatAPI | null>;
239
+
240
+ /**
241
+ * Open the chat widget window
242
+ */
243
+ open(): void;
244
+
245
+ /**
246
+ * Close the chat widget window
247
+ */
248
+ close(): void;
249
+
250
+ /**
251
+ * Toggle the chat widget window open/closed
252
+ */
253
+ toggle(): void;
254
+
255
+ /**
256
+ * Destroy the widget and clean up resources
257
+ */
258
+ destroy(): void;
259
+
260
+ /**
261
+ * Send a message programmatically
262
+ * @param content - Message content to send
263
+ */
264
+ sendMessage(content: string): void;
265
+
266
+ /**
267
+ * Set user information for personalization
268
+ * @param user - User information
269
+ */
270
+ setUser(user: UserInfo): void;
271
+
272
+ /**
273
+ * Clear chat history and start a new conversation
274
+ */
275
+ clearHistory(): void;
276
+
277
+ /**
278
+ * Subscribe to widget events
279
+ * @param event - Event type to listen for
280
+ * @param callback - Callback function
281
+ */
282
+ on(event: WidgetEvent, callback: EventCallback): void;
283
+
284
+ /**
285
+ * Unsubscribe from widget events
286
+ * @param event - Event type
287
+ * @param callback - Callback function to remove
288
+ */
289
+ off(event: WidgetEvent, callback: EventCallback): void;
290
+
291
+ /**
292
+ * Get current widget state
293
+ * @returns Current widget state
294
+ */
295
+ getState(): WidgetState;
296
+
297
+ /**
298
+ * Widget version
299
+ */
300
+ readonly version: string;
301
+ }