@nimbusai/webchat-sdk 1.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.
@@ -0,0 +1,406 @@
1
+ type ChatPosition = "bottom-right" | "bottom-left" | "sidepanel-left" | "sidepanel-right";
2
+ type BubblePosition = "bottom-right" | "bottom-left";
3
+ /** Reusable text configuration used throughout the SDK. */
4
+ interface TextConfig {
5
+ /** Whether to display this text element. Not used everywhere. */
6
+ display?: boolean;
7
+ /** The text value / content. */
8
+ value?: string;
9
+ /** Text color (CSS color string). */
10
+ color?: string;
11
+ /** Font family override. */
12
+ font?: string;
13
+ /** Font size in px. */
14
+ size?: number;
15
+ }
16
+ /** Unified text element with value and nested styling */
17
+ interface TextElement {
18
+ /** The text value / content. */
19
+ value?: string;
20
+ /** Text styling configuration */
21
+ text?: TextConfig;
22
+ }
23
+ /** Reusable color pair configuration for primary/secondary colors */
24
+ interface ColorPair {
25
+ /** Primary color (usually background or main color) */
26
+ primary?: string;
27
+ /** Secondary color (usually foreground or accent color) */
28
+ secondary?: string;
29
+ }
30
+ /**
31
+ * Icon configuration used throughout the SDK.
32
+ * Pass `null` to explicitly hide an icon.
33
+ */
34
+ interface IconConfig {
35
+ /** Image URL for the icon. */
36
+ img?: string;
37
+ /** Size of the icon with width and height in pixels. */
38
+ size?: {
39
+ width: number;
40
+ height: number;
41
+ };
42
+ /** Icon stroke/fill color (CSS color string). Only applies to Lucide icons, ignored for image URLs. */
43
+ color?: string;
44
+ }
45
+ interface ThemeConfig {
46
+ /** Primary theme color — send button bg, header bg, bubble bg. */
47
+ primary: string;
48
+ /** Secondary theme color — send button icon, header text, bubble icon. */
49
+ secondary: string;
50
+ }
51
+ interface HeaderConfig {
52
+ /** Icon configuration for the header. Not shown if omitted/null. */
53
+ icon?: IconConfig | null;
54
+ /** Header text configuration. */
55
+ text?: TextConfig;
56
+ /** Header color configuration (primary = background, secondary = close icon). */
57
+ color?: ColorPair;
58
+ }
59
+ interface WelcomeConfig {
60
+ /** Whether to display the welcome message. Default: true */
61
+ display?: boolean;
62
+ /** Pre-title text (e.g. "Welcome to "). */
63
+ preTitle?: TextElement | TextConfig;
64
+ /** Title text (e.g. "Nimbus"). */
65
+ title?: TextElement | TextConfig;
66
+ /** Subtitle text (e.g. "Send a message to start a conversation"). */
67
+ subtitle?: TextElement | TextConfig;
68
+ }
69
+ interface MessageConfig {
70
+ /** Bubble background color. */
71
+ background?: string;
72
+ /** Width of the message bubble (e.g. "90%", "300px"). Default: "70%" */
73
+ width?: string;
74
+ /** Text configuration for the message. */
75
+ text?: TextConfig;
76
+ /** Avatar icon configuration. Pass null to hide, omit to not show. */
77
+ icon?: IconConfig | null;
78
+ }
79
+ interface TypingIndicatorConfig {
80
+ /** Where to display the indicator: "top" = header status area, "bottom" = above input. Default: "top" */
81
+ position?: "top" | "bottom";
82
+ /** Title configuration for typing indicator */
83
+ title?: {
84
+ value?: string;
85
+ text?: TextConfig;
86
+ };
87
+ }
88
+ interface WaitForReplyConfig {
89
+ /** Timeout in milliseconds. Default: 10000 (10 seconds) */
90
+ timeout?: number;
91
+ /** Wait for bot's first message before allowing user to type in new conversation. Default: false */
92
+ firstReply?: boolean;
93
+ }
94
+ interface MobileConfig {
95
+ /** Widget position on mobile devices. If not set, uses the regular position. */
96
+ position?: ChatPosition;
97
+ /** Viewport width breakpoint to consider as mobile (e.g. "480px"). If set, overrides user-agent detection. */
98
+ breakpoint?: string;
99
+ }
100
+ interface StyleConfig {
101
+ /** Width of the chat window/sidepanel (e.g. "380px", "100%"). Default: "380px" */
102
+ width?: string;
103
+ /** Height of the chat window (e.g. "560px", "100%"). Only applies to window mode. Default: "560px" */
104
+ height?: string;
105
+ /** Widget position on the page. Default: "bottom-right" */
106
+ position?: ChatPosition;
107
+ /** Mobile-specific overrides */
108
+ mobile?: MobileConfig;
109
+ /** Global font family for the entire chat widget. No default (uses system font). */
110
+ font?: string;
111
+ /** Chat body background — can be a CSS color or an image URL. Default: "#ffffff" */
112
+ background?: string;
113
+ }
114
+ interface ReconnectConfig {
115
+ /** Maximum number of reconnection attempts. Default: 5 */
116
+ attempts?: number;
117
+ /** Delay between reconnection attempts in ms. Default: 5000 (5 seconds) */
118
+ timeout?: number;
119
+ }
120
+ interface ShowMoreConfig {
121
+ /** Button text. Default: "Show More" */
122
+ value?: string;
123
+ /** Whether button should be sticky at top. Default: true */
124
+ sticky?: boolean;
125
+ /** Button background color. Default: theme.secondary */
126
+ background?: string;
127
+ /** Text styling for the button */
128
+ text?: TextConfig;
129
+ /** Icon configuration for the button */
130
+ icon?: IconConfig;
131
+ }
132
+ interface UploadConfig {
133
+ /** Maximum file size in bytes. Default: 5MB */
134
+ maxFileSize?: number;
135
+ /** Array of allowed MIME types. */
136
+ allowedFileTypes?: string[];
137
+ /** Icon configuration for the upload button. */
138
+ icon?: IconConfig | null;
139
+ /** Duration in milliseconds for error message display. Default: 2000 */
140
+ errorDisplayDuration?: number;
141
+ }
142
+ interface MaxCharactersConfig {
143
+ /** Maximum number of characters allowed. If null/undefined, unlimited */
144
+ limit: number;
145
+ /** Text styling configuration */
146
+ text?: TextConfig;
147
+ }
148
+ interface InputConfig {
149
+ /** Placeholder text for the input. Default: "Ask Nimbus" */
150
+ placeholder?: string;
151
+ /** If true, the input expands to a textarea. Default: false */
152
+ expandable?: boolean;
153
+ /** Text styling for the input field. */
154
+ text?: TextConfig;
155
+ /** Background colors for the input (primary = input area, secondary = container). */
156
+ background?: ColorPair;
157
+ /** File upload configuration */
158
+ upload?: UploadConfig;
159
+ /** Character limit configuration with counter display */
160
+ maxCharacters?: MaxCharactersConfig;
161
+ }
162
+ interface SendButtonConfig {
163
+ /** Custom icon configuration. Pass null to hide, omit for default. */
164
+ icon?: IconConfig | null;
165
+ /** If true, align input and send button horizontally on the same row. Default: false */
166
+ align?: boolean;
167
+ }
168
+ interface ErrorButtonConfig {
169
+ /** Background color of the button */
170
+ background?: string;
171
+ /** Text configuration for the button */
172
+ text?: TextConfig;
173
+ /** Icon configuration for the button. Pass null to hide. */
174
+ icon?: IconConfig | null;
175
+ }
176
+ interface ErrorStyleConfig {
177
+ /** Background color for the error message */
178
+ background?: string;
179
+ /** Title configuration for the error message. Pass null to use default. */
180
+ title?: TextElement | null;
181
+ /** Subtitle configuration for the error message. Pass null to use default. */
182
+ subtitle?: TextElement | null;
183
+ /** Button configuration for the error */
184
+ button?: ErrorButtonConfig;
185
+ }
186
+ interface ErrorConfig {
187
+ /** Styling for inactivity timeout errors */
188
+ inactivity?: ErrorStyleConfig;
189
+ /** Styling for session conflict errors */
190
+ conflict?: ErrorStyleConfig;
191
+ /** Styling for session TTL expiration errors */
192
+ session_ttl?: ErrorStyleConfig;
193
+ /** Styling for unauthorized access errors */
194
+ unauthorized?: ErrorStyleConfig;
195
+ }
196
+ interface BubbleConfig {
197
+ /** Position of the floating bubble. Default: "bottom-right" */
198
+ position?: BubblePosition;
199
+ /** If true, hide the bubble when the chat panel is open. Default: false */
200
+ autoHide?: boolean;
201
+ /** Custom icon configuration. Pass null to hide custom, omit for default. */
202
+ icon?: IconConfig | null;
203
+ }
204
+ interface NimbusChatConfig {
205
+ /** Required — the agent ID (UUID) for this chat instance */
206
+ agent_id: string;
207
+ /** DNS endpoint for chat services. Default: "api.nimbus.ai/api/v1/webchat" */
208
+ dns?: string;
209
+ /** Whether to resume previous conversation on reconnect. Default: false */
210
+ resumeConversation?: boolean;
211
+ /** Style configuration (position, dimensions, font, background, mobile) */
212
+ style?: StyleConfig;
213
+ /** Number of messages to load per page. Default: 10 */
214
+ messagesPerPage?: number;
215
+ /** Bubble configuration (position, autoHide, icon) */
216
+ bubble?: BubbleConfig;
217
+ /** Theme colors (primary, secondary) */
218
+ theme?: Partial<ThemeConfig>;
219
+ /** User message styling */
220
+ userMessage?: MessageConfig;
221
+ /** Bot message styling */
222
+ botMessage?: MessageConfig;
223
+ /** Header configuration (icon, text, color) */
224
+ header?: HeaderConfig;
225
+ /** Input field configuration */
226
+ input?: InputConfig;
227
+ /** Send button configuration */
228
+ sendButton?: SendButtonConfig;
229
+ /** Welcome message configuration shown when chat is empty. */
230
+ welcome?: WelcomeConfig;
231
+ /** Error styling configuration for conflict and inactivity errors */
232
+ error?: ErrorConfig;
233
+ /** Enable debug logging to console. Default: false */
234
+ debug?: boolean;
235
+ /** Reconnection configuration for unexpected disconnections */
236
+ reconnect?: ReconnectConfig;
237
+ /** Show new chat button in header. Default: false */
238
+ allowNewChat?: boolean;
239
+ /** Wait for bot reply before allowing next user message */
240
+ waitForReply?: WaitForReplyConfig;
241
+ /** Typing indicator configuration. Independent from waitForReply. */
242
+ isTypingIndicator?: TypingIndicatorConfig;
243
+ /** Show More button styling */
244
+ showMore?: ShowMoreConfig;
245
+ }
246
+ interface ResolvedConfig {
247
+ agent_id: string;
248
+ dns: string;
249
+ resumeConversation: boolean;
250
+ style: {
251
+ position: ChatPosition;
252
+ mobile?: {
253
+ position?: ChatPosition;
254
+ breakpoint?: string;
255
+ };
256
+ width: string;
257
+ height: string;
258
+ font?: string;
259
+ background: string;
260
+ };
261
+ messagesPerPage: number;
262
+ bubble: Required<Pick<BubbleConfig, "position" | "autoHide">> & Pick<BubbleConfig, "icon">;
263
+ theme: ThemeConfig;
264
+ userMessage: {
265
+ background: string;
266
+ width: string;
267
+ text: TextConfig;
268
+ icon?: IconConfig | null;
269
+ };
270
+ botMessage: {
271
+ background: string;
272
+ width: string;
273
+ text: TextConfig;
274
+ icon?: IconConfig | null;
275
+ };
276
+ header: HeaderConfig;
277
+ input: {
278
+ placeholder: string;
279
+ expandable: boolean;
280
+ text?: TextConfig;
281
+ background?: ColorPair;
282
+ upload?: UploadConfig;
283
+ maxCharacters?: MaxCharactersConfig;
284
+ };
285
+ sendButton: Required<Pick<SendButtonConfig, "align">> & Pick<SendButtonConfig, "icon">;
286
+ welcome: WelcomeConfig;
287
+ error: Required<ErrorConfig>;
288
+ debug: boolean;
289
+ reconnect: ReconnectConfig;
290
+ allowNewChat: boolean;
291
+ waitForReply?: WaitForReplyConfig;
292
+ isTypingIndicator?: TypingIndicatorConfig;
293
+ showMore: ShowMoreConfig;
294
+ }
295
+ /** Standard icon names used throughout the SDK */
296
+ declare const ICON_NAMES: {
297
+ readonly MESSAGE_CIRCLE: "message-circle";
298
+ readonly SEND: "send";
299
+ readonly CLOSE: "x";
300
+ readonly NEW_CHAT: "rotate-cw";
301
+ readonly CHEVRON_DOWN: "chevron-down";
302
+ readonly PAPERCLIP: "paperclip";
303
+ readonly TYPE: "type";
304
+ };
305
+ /** Standard icon sizes used throughout the SDK */
306
+ declare const ICON_SIZES: {
307
+ readonly BUTTON_SMALL: 16;
308
+ readonly BUTTON_MEDIUM: 18;
309
+ readonly AVATAR: 28;
310
+ readonly BUBBLE_OPEN: 26;
311
+ };
312
+
313
+ /**
314
+ * Main SDK orchestrator.
315
+ *
316
+ * Usage (npm):
317
+ * const chat = new NimbusChat({ agent_id: "550e8400-e29b-41d4-a716-446655440000" });
318
+ * chat.open();
319
+ *
320
+ * Usage (CDN):
321
+ * NimbusChat.init({ agent_id: "550e8400-e29b-41d4-a716-446655440000" });
322
+ */
323
+ declare class NimbusChat {
324
+ private config;
325
+ private eventBus;
326
+ private session;
327
+ private wsManager;
328
+ private apiClient;
329
+ private ui;
330
+ private logger;
331
+ private destroyed;
332
+ private messageLimit;
333
+ private hasMoreMessages;
334
+ private perf;
335
+ constructor(config: NimbusChatConfig);
336
+ private setupEventHandlers;
337
+ private handleServerEvent;
338
+ /** Show the chat widget */
339
+ open(): void;
340
+ /** Hide the chat widget */
341
+ close(): void;
342
+ /** Toggle chat visibility */
343
+ toggle(): void;
344
+ /**
345
+ * Completely remove the widget from the page and disconnect WebSocket.
346
+ * After calling destroy(), this instance cannot be reused.
347
+ */
348
+ destroy(): void;
349
+ private fetchAndDisplayHistory;
350
+ }
351
+
352
+ /** Message types supported by the protocol */
353
+ type MessageType = "text" | "file" | "json";
354
+ /** Message direction for history */
355
+ type MessageDirection = "INBOUND" | "OUTBOUND";
356
+ /** Message from server (simplified schema) */
357
+ interface ServerMessage {
358
+ type: "message";
359
+ direction: "outbound";
360
+ content: string;
361
+ }
362
+ /** Base message interface */
363
+ interface BaseUserMessage {
364
+ type: "message";
365
+ }
366
+ /** Text message sent by user (simplified schema) */
367
+ interface TextUserMessage extends BaseUserMessage {
368
+ direction: "inbound";
369
+ content: string;
370
+ }
371
+ /** Union type for all user messages */
372
+ type UserMessage = TextUserMessage;
373
+ /** Chat message used throughout the app */
374
+ interface ChatMessage {
375
+ id: string;
376
+ direction: MessageDirection;
377
+ message_type: MessageType;
378
+ content: string | object;
379
+ created_at: number;
380
+ filename?: string | null;
381
+ filetype?: string | null;
382
+ filesize?: number | null;
383
+ description?: string | null;
384
+ }
385
+ /** Connection states for the WebSocket */
386
+ type ConnectionState = "idle" | "connecting" | "connected" | "disconnected";
387
+
388
+ /**
389
+ * Initialize the NimbusChat widget (singleton pattern).
390
+ * Use this when loading via CDN <script> tag.
391
+ *
392
+ * NimbusChat.init({ agent_id: "550e8400-e29b-41d4-a716-446655440000" });
393
+ */
394
+ declare function init(config: NimbusChatConfig): NimbusChat;
395
+ /**
396
+ * Get the existing singleton instance (or null if not initialized).
397
+ */
398
+ declare function getInstance(): NimbusChat | null;
399
+
400
+ declare const _default: {
401
+ NimbusChat: typeof NimbusChat;
402
+ init: typeof init;
403
+ getInstance: typeof getInstance;
404
+ };
405
+
406
+ export { type BubbleConfig, type BubblePosition, type ChatMessage, type ChatPosition, type ColorPair, type ConnectionState, type ErrorButtonConfig, type ErrorConfig, type ErrorStyleConfig, type HeaderConfig, ICON_NAMES, ICON_SIZES, type IconConfig, type InputConfig, type MessageConfig, type MessageType, NimbusChat, type NimbusChatConfig, type ResolvedConfig, type SendButtonConfig, type ServerMessage, type TextConfig, type TextElement, type ThemeConfig, type UserMessage, type WelcomeConfig, _default as default, getInstance, init };