@astermind/chatbot-template 1.0.3 → 2.2.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/README.md CHANGED
@@ -9,11 +9,12 @@ Embeddable AI chatbot widget for [AsterMind](https://astermind.ai) RAG - a drop-
9
9
 
10
10
  ## Table of Contents
11
11
 
12
+ - [Architecture](#architecture)
12
13
  - [Features](#features)
13
14
  - [Installation](#installation)
14
15
  - [Quick Start](#quick-start)
16
+ - [Configuration in Your Application](#configuration-in-your-application)
15
17
  - [Configuration Reference](#configuration-reference)
16
- - [Cybernetic Chatbot Integration](#cybernetic-chatbot-integration)
17
18
  - [Theming](#theming)
18
19
  - [React Hooks API](#react-hooks-api)
19
20
  - [Components API](#components-api)
@@ -24,24 +25,63 @@ Embeddable AI chatbot widget for [AsterMind](https://astermind.ai) RAG - a drop-
24
25
 
25
26
  ---
26
27
 
28
+ ## Architecture
29
+
30
+ This package is the **UI layer** for the AsterMind Chatbot system. It provides pre-built React components and hooks for embedding a chatbot in your application.
31
+
32
+ ### Package Dependencies
33
+
34
+ ```
35
+ Your Application
36
+
37
+ └── @astermind/chatbot-template (this package - UI components)
38
+
39
+ └── @astermind/cybernetic-chatbot-client (required - API client)
40
+ ```
41
+
42
+ **Important**: `@astermind/cybernetic-chatbot-client` is automatically installed as a dependency. It provides:
43
+
44
+ - **API Communication** - Connects to your AsterMind backend
45
+ - **Streaming Responses** - SSE-based token-by-token message display
46
+ - **Offline Fallback** - Local RAG processing with IndexedDB cache
47
+ - **Agentic Capabilities** - DOM interactions (optional, tree-shakeable)
48
+
49
+ ### Where to Configure
50
+
51
+ All configuration is done in **your application code**, not in node_modules:
52
+
53
+ | Configuration Method | Where to Set |
54
+ |---------------------|--------------|
55
+ | React Props | In your component: `<ChatbotWidget apiKey="..." />` |
56
+ | Environment Variables | In your `.env` file |
57
+ | SSR Injection | In your server template |
58
+ | Global Object | In your HTML/JS before loading |
59
+ | Data Attributes | On your script tag |
60
+
61
+ ---
62
+
27
63
  ## Features
28
64
 
29
- ### Core Widget Features
65
+ ### Core Widget Features (this package)
30
66
 
31
67
  - **Embeddable Floating Chat Bubble** - Position anywhere on the page (4 corners)
32
68
  - **React Components Library** - 11 fully customizable components
33
69
  - **Vanilla JS Standalone Bundle** - IIFE format with React bundled for non-React sites
34
70
  - **Full TypeScript Support** - Complete type definitions exported
71
+ - **Theming System** - 20+ CSS custom properties for full visual customization
35
72
 
36
- ### RAG Integration
73
+ ### RAG & Backend Features (via cybernetic-chatbot-client)
37
74
 
38
75
  - **AsterMind Backend Integration** - Connects to `/api/external/chat` endpoints
39
76
  - **Streaming Responses** - SSE-based token-by-token message display
40
77
  - **Source Citations** - Collapsible source references with confidence levels
41
78
  - **Session Management** - Automatic sessionId handling across conversations
42
- - **Confidence Indicators** - Visual display of high/medium/low/none confidence
79
+ - **Offline Fallback** - Local RAG processing when backend is unavailable
80
+ - **Connection Status** - Automatic online/offline/connecting/error states
81
+
82
+ ### Agentic Capabilities (via cybernetic-chatbot-client)
43
83
 
44
- ### Agentic Capabilities
84
+ When enabled, the chatbot can perform actions on your page:
45
85
 
46
86
  - **Navigation Actions** - Navigate users to specific pages
47
87
  - **Form Filling** - Auto-fill form fields with suggested values
@@ -50,26 +90,8 @@ Embeddable AI chatbot widget for [AsterMind](https://astermind.ai) RAG - a drop-
50
90
  - **Scrolling** - Scroll to specific elements
51
91
  - **Element Highlighting** - Draw attention to page elements
52
92
  - **Custom Action Handlers** - Define your own action types
53
- - **Action Cards UI** - Confirm/cancel interface for proposed actions
54
- - **Confidence Thresholds** - Auto-execute high-confidence actions
55
- - **Site Map Configuration** - Define navigable pages for the agent
56
-
57
- ### Offline & Fallback
58
-
59
- - **Graceful Degradation** - Works when connection is lost
60
- - **Custom Offline Message** - Configure what users see offline
61
- - **Connection Status Indicator** - Shows online/offline/connecting/error states
62
- - **Optional Local RAG Fallback** - Use Cybernetic RAG locally when offline
63
93
 
64
- ### Theming & Customization
65
-
66
- - **20+ CSS Custom Properties** - Full visual customization via CSS variables
67
- - **JavaScript Theme Object** - Configure themes programmatically
68
- - **4 Position Options** - bottom-right, bottom-left, top-right, top-left
69
- - **Configurable Dimensions** - Width, height, bubble size
70
- - **Full Color Customization** - Every color is customizable
71
- - **Typography Settings** - Font family and size
72
- - **Border Radius & Shadows** - Visual effects customization
94
+ Agentic capabilities are tree-shakeable - they're only included in your bundle if you import and use them.
73
95
 
74
96
  ---
75
97
 
@@ -81,6 +103,8 @@ Embeddable AI chatbot widget for [AsterMind](https://astermind.ai) RAG - a drop-
81
103
  npm install @astermind/chatbot-template
82
104
  ```
83
105
 
106
+ This automatically installs `@astermind/cybernetic-chatbot-client` as a dependency.
107
+
84
108
  ### CDN (Vanilla JS)
85
109
 
86
110
  ```html
@@ -134,14 +158,108 @@ function App() {
134
158
 
135
159
  ---
136
160
 
161
+ ## Configuration in Your Application
162
+
163
+ All configuration is done in **your application code**. The chatbot-template reads configuration from several sources in your project.
164
+
165
+ ### React Applications
166
+
167
+ **Option 1: Pass props directly**
168
+ ```tsx
169
+ <ChatbotWidget
170
+ apiUrl="https://api.astermind.ai"
171
+ apiKey="am_your-api-key"
172
+ position="bottom-right"
173
+ />
174
+ ```
175
+
176
+ **Option 2: Use environment variables**
177
+
178
+ Create a `.env` file in your project root:
179
+
180
+ ```env
181
+ # Vite projects
182
+ VITE_ASTERMIND_RAG_API_KEY=am_your_api_key
183
+ VITE_ASTERMIND_RAG_API_SERVER_URL=https://api.astermind.ai
184
+
185
+ # Create React App projects
186
+ REACT_APP_ASTERMIND_RAG_API_KEY=am_your_api_key
187
+ REACT_APP_ASTERMIND_RAG_API_SERVER_URL=https://api.astermind.ai
188
+ ```
189
+
190
+ Then use the widget without explicit props:
191
+ ```tsx
192
+ <ChatbotWidget position="bottom-right" />
193
+ ```
194
+
195
+ ### Vanilla JS Applications
196
+
197
+ **Option 1: Pass config to init()**
198
+ ```javascript
199
+ AsterMindChatbot.init({
200
+ apiKey: 'am_your_api_key',
201
+ apiUrl: 'https://api.astermind.ai',
202
+ position: 'bottom-right'
203
+ });
204
+ ```
205
+
206
+ **Option 2: Global config object**
207
+ ```html
208
+ <script>
209
+ window.astermindConfig = {
210
+ apiKey: 'am_your_api_key',
211
+ apiUrl: 'https://api.astermind.ai'
212
+ };
213
+ </script>
214
+ <script src="astermind-chatbot.min.js"></script>
215
+ <script>
216
+ AsterMindChatbot.init();
217
+ </script>
218
+ ```
219
+
220
+ **Option 3: Script data attributes**
221
+ ```html
222
+ <script
223
+ src="astermind-chatbot.min.js"
224
+ data-astermind-key="am_your_api_key"
225
+ data-astermind-url="https://api.astermind.ai"
226
+ ></script>
227
+ ```
228
+
229
+ ### SSR / Server-Side Rendering
230
+
231
+ For Next.js, Nuxt, or other SSR frameworks:
232
+
233
+ ```html
234
+ <script>
235
+ window.__ASTERMIND_CONFIG__ = {
236
+ apiKey: '<%= process.env.ASTERMIND_RAG_API_KEY %>',
237
+ apiUrl: '<%= process.env.ASTERMIND_RAG_API_SERVER_URL %>'
238
+ };
239
+ </script>
240
+ ```
241
+
242
+ ---
243
+
137
244
  ## Configuration Reference
138
245
 
139
- ### Required Options
246
+ ### Configuration Priority
140
247
 
141
- | Option | Type | Description |
142
- |--------|------|-------------|
143
- | `apiKey` | `string` | Your AsterMind API key (starts with `am_`) |
144
- | `apiUrl` | `string` | Backend API URL (e.g., `https://api.example.com`) |
248
+ The widget supports multiple configuration methods with this priority (highest to lowest):
249
+
250
+ 1. **Props / init() config** - Direct configuration passed to the component or `init()` function
251
+ 2. **Environment variables** - `VITE_ASTERMIND_RAG_API_KEY`, `REACT_APP_ASTERMIND_RAG_API_KEY`
252
+ 3. **SSR-injected config** - `window.__ASTERMIND_CONFIG__`
253
+ 4. **Global object** - `window.astermindConfig`
254
+ 5. **Script data attributes** - `data-astermind-key`, `data-astermind-url`
255
+
256
+ ### API Key and URL
257
+
258
+ | Option | Type | Default | Description |
259
+ |--------|------|---------|-------------|
260
+ | `apiKey` | `string` | (from env) | Your AsterMind API key (starts with `am_`). Falls back to environment variables. |
261
+ | `apiUrl` | `string` | `'https://api.astermind.ai'` | Backend API URL. Falls back to environment variables. |
262
+ | `throwOnMissingKey` | `boolean` | `true` | Throw error if API key is missing. Set to `false` to log warning instead. |
145
263
 
146
264
  ### Widget Options
147
265
 
@@ -163,21 +281,21 @@ Customize appearance via the `theme` object:
163
281
  ```javascript
164
282
  {
165
283
  theme: {
166
- primaryColor: '#4F46E5', // Primary brand color
167
- primaryHover: '#4338CA', // Primary color on hover
168
- backgroundColor: '#ffffff', // Background color
169
- surfaceColor: '#f3f4f6', // Surface/card background
170
- textColor: '#1f2937', // Primary text color
171
- textMuted: '#6b7280', // Muted/secondary text
172
- borderColor: '#e5e7eb', // Border color
173
- userBubbleBackground: '#4F46E5', // User message background
174
- userBubbleText: '#ffffff', // User message text
175
- botBubbleBackground: '#f3f4f6', // Bot message background
176
- botBubbleText: '#1f2937', // Bot message text
177
- widgetWidth: '380px', // Widget width
178
- widgetHeight: '520px', // Widget height
179
- bubbleSize: '60px', // Trigger bubble size
180
- borderRadius: '12px', // Border radius
284
+ primaryColor: '#4F46E5',
285
+ primaryHover: '#4338CA',
286
+ backgroundColor: '#ffffff',
287
+ surfaceColor: '#f3f4f6',
288
+ textColor: '#1f2937',
289
+ textMuted: '#6b7280',
290
+ borderColor: '#e5e7eb',
291
+ userBubbleBackground: '#4F46E5',
292
+ userBubbleText: '#ffffff',
293
+ botBubbleBackground: '#f3f4f6',
294
+ botBubbleText: '#1f2937',
295
+ widgetWidth: '380px',
296
+ widgetHeight: '520px',
297
+ bubbleSize: '60px',
298
+ borderRadius: '12px',
181
299
  fontFamily: "'Inter', system-ui, sans-serif",
182
300
  fontSize: '14px',
183
301
  shadow: '0 4px 20px rgba(0, 0, 0, 0.15)'
@@ -187,26 +305,20 @@ Customize appearance via the `theme` object:
187
305
 
188
306
  ### Agent Configuration
189
307
 
190
- Enable agentic capabilities:
308
+ Enable agentic capabilities (powered by cybernetic-chatbot-client):
191
309
 
192
310
  ```javascript
193
311
  {
194
312
  agent: {
195
313
  enabled: true,
196
- confidenceThreshold: 0.8, // Minimum confidence for auto-execution
314
+ confidenceThreshold: 0.8,
197
315
  siteMap: [
198
316
  { path: '/products', name: 'Products', description: 'View products' },
199
- { path: '/contact', name: 'Contact', description: 'Contact us' },
200
- { path: '/pricing', name: 'Pricing', description: 'View pricing plans' }
317
+ { path: '/contact', name: 'Contact', description: 'Contact us' }
201
318
  ],
202
319
  customActions: {
203
320
  openModal: async (params) => {
204
- // Custom action handler - open a modal
205
321
  document.getElementById(params.modalId).showModal();
206
- },
207
- trackEvent: async (params) => {
208
- // Custom analytics tracking
209
- analytics.track(params.eventName, params.data);
210
322
  }
211
323
  }
212
324
  }
@@ -238,48 +350,6 @@ Configure offline behavior:
238
350
 
239
351
  ---
240
352
 
241
- ## Cybernetic Chatbot Integration
242
-
243
- This widget is designed to work seamlessly with the `@astermind/cybernetic-chatbot-client` for advanced RAG capabilities.
244
-
245
- ### How It Works
246
-
247
- 1. **Widget sends messages** to your AsterMind backend via the configured `apiUrl`
248
- 2. **Backend processes queries** using your RAG pipeline and returns responses
249
- 3. **Streaming responses** arrive via Server-Sent Events (SSE) for real-time display
250
- 4. **Agentic actions** are proposed by the AI and confirmed via Action Cards
251
-
252
- ### API Endpoints
253
-
254
- The widget connects to these backend endpoints:
255
-
256
- | Endpoint | Method | Description |
257
- |----------|--------|-------------|
258
- | `/api/external/health` | GET | Health check, verifies connection |
259
- | `/api/external/chat` | POST | Non-streaming chat endpoint |
260
- | `/api/external/chat/stream` | POST | Streaming chat endpoint (SSE) |
261
-
262
- ### SSE Event Format
263
-
264
- ```
265
- data: {"type": "chunk", "content": "Hello"}
266
- data: {"type": "chunk", "content": " there!"}
267
- data: {"type": "sources", "sources": [{"title": "Doc", "url": "..."}]}
268
- data: {"type": "action", "action": {"type": "navigate", "path": "/products"}}
269
- data: {"type": "done", "sessionId": "sess_xxx"}
270
- data: {"type": "error", "error": "Error message"}
271
- ```
272
-
273
- ### Offline Fallback
274
-
275
- When offline or disconnected:
276
-
277
- 1. Widget shows connection status indicator
278
- 2. Custom offline message is displayed
279
- 3. If `@astermind/cybernetic-chatbot-client` is installed with local RAG enabled, queries can still be processed locally
280
-
281
- ---
282
-
283
353
  ## Theming
284
354
 
285
355
  ### CSS Variables
@@ -288,7 +358,6 @@ Override CSS variables in your stylesheet for quick customization:
288
358
 
289
359
  ```css
290
360
  :root {
291
- /* Colors */
292
361
  --astermind-primary: #10B981;
293
362
  --astermind-primary-hover: #059669;
294
363
  --astermind-background: #ffffff;
@@ -296,25 +365,15 @@ Override CSS variables in your stylesheet for quick customization:
296
365
  --astermind-text: #1f2937;
297
366
  --astermind-text-muted: #6b7280;
298
367
  --astermind-border: #e5e7eb;
299
-
300
- /* User messages */
301
368
  --astermind-user-bubble-bg: #10B981;
302
369
  --astermind-user-bubble-text: #ffffff;
303
-
304
- /* Bot messages */
305
370
  --astermind-bot-bubble-bg: #f3f4f6;
306
371
  --astermind-bot-bubble-text: #1f2937;
307
-
308
- /* Dimensions */
309
372
  --astermind-widget-width: 400px;
310
373
  --astermind-widget-height: 600px;
311
374
  --astermind-bubble-size: 64px;
312
-
313
- /* Effects */
314
375
  --astermind-border-radius: 16px;
315
376
  --astermind-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
316
-
317
- /* Typography */
318
377
  --astermind-font-family: 'Inter', system-ui, sans-serif;
319
378
  --astermind-font-size: 14px;
320
379
  }
@@ -322,7 +381,7 @@ Override CSS variables in your stylesheet for quick customization:
322
381
 
323
382
  ### CSS Classes
324
383
 
325
- All elements use the `astermind-` prefix for easy targeting:
384
+ All elements use the `astermind-` prefix:
326
385
 
327
386
  | Class | Element |
328
387
  |-------|---------|
@@ -343,12 +402,12 @@ All elements use the `astermind-` prefix for easy targeting:
343
402
 
344
403
  ## React Hooks API
345
404
 
346
- ### useOmega
405
+ ### useCybernetic
347
406
 
348
407
  Direct API client access for custom implementations:
349
408
 
350
409
  ```tsx
351
- import { useOmega } from '@astermind/chatbot-template';
410
+ import { useCybernetic } from '@astermind/chatbot-template';
352
411
 
353
412
  function MyComponent() {
354
413
  const {
@@ -358,8 +417,10 @@ function MyComponent() {
358
417
  isProcessing, // Whether a request is in progress
359
418
  lastError, // Last error that occurred
360
419
  sessionId, // Current session ID
361
- clearSession // Clear the current session
362
- } = useOmega({
420
+ clearSession, // Clear the current session
421
+ syncCache, // Sync cache for offline use
422
+ client // Underlying CyberneticClient instance
423
+ } = useCybernetic({
363
424
  apiUrl: 'https://api.example.com',
364
425
  apiKey: 'am_your-api-key'
365
426
  });
@@ -368,15 +429,6 @@ function MyComponent() {
368
429
  const response = await sendMessage('Hello!');
369
430
  console.log(response.reply, response.sources);
370
431
  };
371
-
372
- const handleStreamingSend = () => {
373
- sendMessageStream('Tell me about...', {
374
- onChunk: (chunk) => console.log('Chunk:', chunk),
375
- onSources: (sources) => console.log('Sources:', sources),
376
- onDone: (sessionId) => console.log('Done:', sessionId),
377
- onError: (error) => console.error('Error:', error)
378
- });
379
- };
380
432
  }
381
433
  ```
382
434
 
@@ -412,7 +464,6 @@ function MyComponent() {
412
464
  borderRadius: '16px'
413
465
  });
414
466
 
415
- // cssVariables contains the CSS custom property declarations
416
467
  return <div style={cssVariables}>...</div>;
417
468
  }
418
469
  ```
@@ -457,48 +508,6 @@ import {
457
508
  } from '@astermind/chatbot-template';
458
509
  ```
459
510
 
460
- ### Component Example
461
-
462
- Build a custom chat interface:
463
-
464
- ```tsx
465
- import {
466
- ChatWindow,
467
- ChatHeader,
468
- MessageList,
469
- MessageBubble,
470
- ChatInput,
471
- StatusIndicator
472
- } from '@astermind/chatbot-template';
473
- import '@astermind/chatbot-template/styles';
474
-
475
- function CustomChat({ messages, onSend, status }) {
476
- return (
477
- <ChatWindow>
478
- <ChatHeader
479
- title="Support Bot"
480
- subtitle="Always here to help"
481
- />
482
- <StatusIndicator status={status} />
483
- <MessageList>
484
- {messages.map(msg => (
485
- <MessageBubble
486
- key={msg.id}
487
- content={msg.content}
488
- role={msg.role}
489
- timestamp={msg.timestamp}
490
- />
491
- ))}
492
- </MessageList>
493
- <ChatInput
494
- onSend={onSend}
495
- placeholder="Ask a question..."
496
- />
497
- </ChatWindow>
498
- );
499
- }
500
- ```
501
-
502
511
  ---
503
512
 
504
513
  ## TypeScript Support
@@ -507,33 +516,35 @@ Full TypeScript support with exported types:
507
516
 
508
517
  ```typescript
509
518
  import type {
510
- // Configuration
511
- ChatbotConfig,
512
- ThemeConfig,
513
- AgentConfig,
514
- FallbackConfig,
515
-
516
- // Messages
519
+ // Template-specific types
520
+ AsterMindChatbotProps,
521
+ ChatbotTheme,
517
522
  ChatMessage,
518
- MessageRole,
519
-
520
- // Actions
521
523
  AgentAction,
522
- ActionType,
523
- NavigateAction,
524
- FormFillAction,
525
- ClickAction,
526
-
527
- // Sources
524
+ ChatState,
525
+ WidgetPosition,
526
+ AgentConfig,
527
+ FallbackConfig,
528
+ SiteMapEntry,
529
+ VanillaInitConfig,
530
+ SendOptions,
531
+
532
+ // Re-exported from @astermind/cybernetic-chatbot-client
533
+ CyberneticConfig,
534
+ CyberneticResponse,
535
+ CyberneticError,
528
536
  Source,
529
- SourceCitation,
530
-
531
- // Status
532
537
  ConnectionStatus,
533
-
534
- // Events
535
- ChatbotCallbacks
538
+ ConfidenceLevel,
539
+ StreamCallbacks,
540
+ AskOptions,
541
+ CachedDocument,
542
+ CacheStatus,
543
+ AgenticConfig
536
544
  } from '@astermind/chatbot-template';
545
+
546
+ // CyberneticClient class is also re-exported for advanced usage
547
+ import { CyberneticClient } from '@astermind/chatbot-template';
537
548
  ```
538
549
 
539
550
  ---