@sksharma72000/ai-chat-websdk 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.
- package/README.md +129 -0
- package/ai-chat-websdk.es.js +31786 -0
- package/ai-chat-websdk.umd.js +66 -0
- package/components/ChatWindow.d.ts +8 -0
- package/components/RichContentRenderer.d.ts +9 -0
- package/hooks/useAIChat.d.ts +30 -0
- package/hooks/useChatMode.d.ts +20 -0
- package/index.d.ts +79 -0
- package/package.json +38 -0
- package/style.css +1 -0
- package/types/config.d.ts +63 -0
- package/types/message.d.ts +91 -0
- package/utils/correlationId.d.ts +7 -0
package/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# @sksharma72000/ai-chat-websdk
|
|
2
|
+
|
|
3
|
+
An embeddable, fully themeable AI chat widget for web applications.
|
|
4
|
+
Drop it into any page with a single `initialize()` call — no framework required.
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
|
|
8
|
+
- 🔐 **JWT Authentication** — pass a token on init, update it at any time, or auto-refresh on 401
|
|
9
|
+
- 🎨 **Fully Themeable** — colors, fonts, border-radius via CSS custom properties
|
|
10
|
+
- 📊 **Rich Content** — tables, code blocks, markdown, clarification flows & execution plans
|
|
11
|
+
- 📝 **Chat History** — loads and replays earlier conversations automatically
|
|
12
|
+
- ⚡ **Edit & Retry** — edit previous messages and regenerate responses inline
|
|
13
|
+
- 🔴 **Connection Monitor** — live online/offline indicator
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @sksharma72000/ai-chat-websdk
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
> **Peer dependencies** — React 18 and ReactDOM 18 must be present in your host application.
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install react react-dom
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import AIChatSDK from '@sksharma72000/ai-chat-websdk';
|
|
31
|
+
import '@sksharma72000/ai-chat-websdk/style.css';
|
|
32
|
+
|
|
33
|
+
// 1. Mount the widget
|
|
34
|
+
AIChatSDK.initialize({
|
|
35
|
+
// Required
|
|
36
|
+
apiUrl: 'https://api.example.com',
|
|
37
|
+
|
|
38
|
+
// Auth — omit for public endpoints
|
|
39
|
+
jwtToken: 'Bearer eyJ...',
|
|
40
|
+
|
|
41
|
+
// Auto-refresh token on 401 — SDK retries the failed request automatically
|
|
42
|
+
onTokenExpired: async () => {
|
|
43
|
+
const res = await fetch('/auth/refresh', { method: 'POST' });
|
|
44
|
+
const { token } = await res.json();
|
|
45
|
+
return token; // 'Bearer ' prefix is optional — the SDK normalises it
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
// Branding
|
|
49
|
+
title: 'Support Chat',
|
|
50
|
+
logo: 'https://example.com/logo.png',
|
|
51
|
+
welcomeMessage: '## 👋 Hi there!\nHow can I help you today?',
|
|
52
|
+
|
|
53
|
+
// Pre-fill input on first open (user can edit or send immediately)
|
|
54
|
+
initialMessage: 'Show me the latest reports',
|
|
55
|
+
|
|
56
|
+
// Theme — all fields optional, defaults to indigo/violet palette
|
|
57
|
+
theme: {
|
|
58
|
+
primaryColor: '#6366f1', // accent: buttons, header gradient start
|
|
59
|
+
secondaryColor: '#8b5cf6', // header gradient end
|
|
60
|
+
backgroundColor: '#f8fafc', // chat message area background
|
|
61
|
+
fontFamily: "'Inter', sans-serif",
|
|
62
|
+
borderRadius: '12px', // message bubble corner radius
|
|
63
|
+
userBubbleColor: '#6366f1', // user message bubble fill
|
|
64
|
+
userBubbleTextColor: '#ffffff', // user message bubble text
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
// Mount target — CSS selector or DOM element.
|
|
68
|
+
// Omit to render as a floating FAB in the bottom-right corner.
|
|
69
|
+
container: '#chat-widget-root',
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// 2. Update token after silent refresh / login
|
|
73
|
+
AIChatSDK.setToken('Bearer eyJnew...');
|
|
74
|
+
|
|
75
|
+
// 3. Tear down on logout / page unload
|
|
76
|
+
AIChatSDK.destroy();
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Configuration Reference
|
|
80
|
+
|
|
81
|
+
| Option | Type | Default | Description |
|
|
82
|
+
|---|---|---|---|
|
|
83
|
+
| `apiUrl` | `string` | **required** | Base URL of the AI server |
|
|
84
|
+
| `jwtToken` | `string` | — | JWT token (with or without `Bearer ` prefix) |
|
|
85
|
+
| `onTokenExpired` | `() => Promise<string>` | — | Called on 401; return new token; SDK retries automatically |
|
|
86
|
+
| `title` | `string` | `'AI Assistant'` | Header title |
|
|
87
|
+
| `logo` | `string` | — | URL or base64 of logo image |
|
|
88
|
+
| `welcomeMessage` | `string` | — | Markdown string shown as the first AI message |
|
|
89
|
+
| `initialMessage` | `string` | — | Pre-fills the input when the widget first opens |
|
|
90
|
+
| `container` | `string \| HTMLElement` | `document.body` | Mount target; omit for floating FAB |
|
|
91
|
+
| `theme` | `SDKTheme` | — | See theme options below |
|
|
92
|
+
|
|
93
|
+
### Theme Options
|
|
94
|
+
|
|
95
|
+
| Option | Default | Description |
|
|
96
|
+
|---|---|---|
|
|
97
|
+
| `primaryColor` | `#6366f1` | Accent color — buttons, header gradient start |
|
|
98
|
+
| `secondaryColor` | `#8b5cf6` | Header gradient end |
|
|
99
|
+
| `backgroundColor` | `#f8fafc` | Chat message area background |
|
|
100
|
+
| `fontFamily` | system-ui | CSS font-family string |
|
|
101
|
+
| `borderRadius` | `12px` | Message bubble corner radius |
|
|
102
|
+
| `userBubbleColor` | `#6366f1` | User message bubble fill |
|
|
103
|
+
| `userBubbleTextColor` | `#ffffff` | User message bubble text |
|
|
104
|
+
|
|
105
|
+
## React Usage
|
|
106
|
+
|
|
107
|
+
```tsx
|
|
108
|
+
import { ChatWindow } from '@sksharma72000/ai-chat-websdk';
|
|
109
|
+
import '@sksharma72000/ai-chat-websdk/style.css';
|
|
110
|
+
|
|
111
|
+
function App() {
|
|
112
|
+
return (
|
|
113
|
+
<ChatWindow config={{
|
|
114
|
+
apiUrl: 'https://api.example.com',
|
|
115
|
+
jwtToken: token,
|
|
116
|
+
title: 'Support Chat',
|
|
117
|
+
}} />
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Chat Mode
|
|
123
|
+
|
|
124
|
+
The chat mode (FAQ / client / database) is determined **server-side** via the JWT claims.
|
|
125
|
+
No manual mode selector is exposed — the server routes queries automatically based on the token.
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
MIT © Shree Krishna Acharya
|