@chatwidgetai/chat-widget 0.1.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 +168 -0
- package/dist/ai-chat-widget.umd.js +65851 -0
- package/dist/ai-chat-widget.umd.js.map +1 -0
- package/dist/api/client.d.ts +48 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/components/ChatWidget.d.ts +9 -0
- package/dist/components/ChatWidget.d.ts.map +1 -0
- package/dist/components/ChatWindow.d.ts +20 -0
- package/dist/components/ChatWindow.d.ts.map +1 -0
- package/dist/components/FeedbackButtons.d.ts +12 -0
- package/dist/components/FeedbackButtons.d.ts.map +1 -0
- package/dist/components/Message.d.ts +17 -0
- package/dist/components/Message.d.ts.map +1 -0
- package/dist/components/MessageInput.d.ts +13 -0
- package/dist/components/MessageInput.d.ts.map +1 -0
- package/dist/components/MessageList.d.ts +19 -0
- package/dist/components/MessageList.d.ts.map +1 -0
- package/dist/components/Sources.d.ts +12 -0
- package/dist/components/Sources.d.ts.map +1 -0
- package/dist/components/SuggestedQuestions.d.ts +11 -0
- package/dist/components/SuggestedQuestions.d.ts.map +1 -0
- package/dist/components/TypingIndicator.d.ts +7 -0
- package/dist/components/TypingIndicator.d.ts.map +1 -0
- package/dist/hooks/useChat.d.ts +35 -0
- package/dist/hooks/useChat.d.ts.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +21669 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +21672 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +143 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/umd.d.ts +25 -0
- package/dist/umd.d.ts.map +1 -0
- package/dist/utils/actionExecutor.d.ts +18 -0
- package/dist/utils/actionExecutor.d.ts.map +1 -0
- package/dist/utils/session.d.ts +12 -0
- package/dist/utils/session.d.ts.map +1 -0
- package/dist/utils/storage.d.ts +28 -0
- package/dist/utils/storage.d.ts.map +1 -0
- package/package.json +56 -0
package/README.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# chat-widget
|
|
2
|
+
|
|
3
|
+
Embeddable AI assistant widget for React applications. The package wraps the AI Chat Widget used in the AI Console projects and exposes both a plug-and-play `<ChatWidget />` component and a lower-level `useChat()` hook for custom UIs. It speaks to a compatible RAG backend, streams responses, surfaces knowledge-base citations, and handles feedback/actions out of the box.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Drop-in widget** with launcher button, conversation history, file uploads, and light/dark themes.
|
|
10
|
+
- **Auto-configuration** – widget appearance/behavior is loaded from your backend (`/api/widget/:id/config`).
|
|
11
|
+
- **Persistent conversations** backed by existing widget sessions and local storage.
|
|
12
|
+
- **Agent support** – seamlessly handles widgets with custom actions and follow-up approvals.
|
|
13
|
+
- **Hook-first API** for building bespoke chat surfaces while reusing the data flows.
|
|
14
|
+
- **Browser friendly** UMD bundle (`window.AIChatWidget.mount`) for non-React hosts.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# with npm
|
|
22
|
+
npm install @chatwidgetai/chat-widget
|
|
23
|
+
|
|
24
|
+
# or with pnpm / yarn
|
|
25
|
+
pnpm add @chatwidgetai/chat-widget
|
|
26
|
+
yarn add @chatwidgetai/chat-widget
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
> **Peer dependencies**
|
|
30
|
+
> Your project must provide `react` and `react-dom` (v18 or v19).
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Quick start (React)
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
import { ChatWidget } from '@chatwidgetai/chat-widget';
|
|
38
|
+
|
|
39
|
+
export function SupportChat() {
|
|
40
|
+
return (
|
|
41
|
+
<ChatWidget
|
|
42
|
+
widgetId="64f6e3e4d12b4a9c8f3c1234"
|
|
43
|
+
apiKey="sk_live_example-key"
|
|
44
|
+
apiUrl="https://api.my-rag-backend.com"
|
|
45
|
+
position="bottom-right"
|
|
46
|
+
theme="auto"
|
|
47
|
+
onMessage={(message) => console.log('New message:', message)}
|
|
48
|
+
onError={(error) => console.error('Chat error', error)}
|
|
49
|
+
/>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The widget automatically pulls its configuration (branding, behavior, suggestions, etc.) from your backend. Only `widgetId` and `apiKey` are required; `apiUrl` defaults to `window.location.origin`.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Props
|
|
59
|
+
|
|
60
|
+
| Prop | Type | Required | Description |
|
|
61
|
+
| -------------- | --------------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------ |
|
|
62
|
+
| `widgetId` | `string` | ✅ | Widget identifier created in the AI Console. |
|
|
63
|
+
| `apiKey` | `string` | ✅ | Public API key with `widget:*` access. |
|
|
64
|
+
| `apiUrl` | `string` | ❌ | Base URL of your widget API. Defaults to `window.location.origin`. |
|
|
65
|
+
| `position` | `'bottom-right' \| 'bottom-left' \| 'top-right' \| 'top-left'` | ❌ | Launcher position (overridden by backend appearance settings). |
|
|
66
|
+
| `theme` | `'light' \| 'dark' \| 'auto'` | ❌ | Force a theme instead of the configured one. |
|
|
67
|
+
| `primaryColor` | `string` | ❌ | Override the accent color (CSS color string). |
|
|
68
|
+
| `onOpen` | `() => void` | ❌ | Fired when the chat window opens. |
|
|
69
|
+
| `onClose` | `() => void` | ❌ | Fired when the chat window closes. |
|
|
70
|
+
| `onMessage` | `(message: ConversationMessage) => void` | ❌ | Called for every new message, including the user’s own messages. |
|
|
71
|
+
| `onError` | `(error: Error) => void` | ❌ | Called when an API error or transport failure occurs. |
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Building your own UI with `useChat`
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
import { useChat } from '@chatwidgetai/chat-widget';
|
|
79
|
+
|
|
80
|
+
export function CustomChat({ widgetId, apiKey }: { widgetId: string; apiKey: string }) {
|
|
81
|
+
const {
|
|
82
|
+
messages,
|
|
83
|
+
isLoading,
|
|
84
|
+
isTyping,
|
|
85
|
+
error,
|
|
86
|
+
config,
|
|
87
|
+
sendMessage,
|
|
88
|
+
approveAction,
|
|
89
|
+
rejectAction,
|
|
90
|
+
submitFeedback,
|
|
91
|
+
} = useChat({
|
|
92
|
+
widgetId,
|
|
93
|
+
apiKey,
|
|
94
|
+
apiUrl: 'https://api.my-rag-backend.com',
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// render messages however you like…
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`useChat` handles configuration, conversation persistence, agent actions, file uploads, and feedback submission. See TypeScript definitions in `@chatwidgetai/chat-widget/dist/index.d.ts` (or `src/hooks/useChat.ts`) for the full return signature and helper types.
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Vanilla / script-tag usage
|
|
106
|
+
|
|
107
|
+
A bundled UMD build is published as `dist/ai-chat-widget.umd.js`. After including the script on a page, a global helper becomes available:
|
|
108
|
+
|
|
109
|
+
```html
|
|
110
|
+
<script src="https://unpkg.com/@chatwidgetai/chat-widget/dist/ai-chat-widget.umd.js"></script>
|
|
111
|
+
<script>
|
|
112
|
+
window.AIChatWidget.mount({
|
|
113
|
+
widgetId: '64f6e3e4d12b4a9c8f3c1234',
|
|
114
|
+
apiKey: 'sk_live_example-key',
|
|
115
|
+
apiUrl: 'https://api.my-rag-backend.com',
|
|
116
|
+
position: 'bottom-right',
|
|
117
|
+
theme: 'auto',
|
|
118
|
+
});
|
|
119
|
+
</script>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
You can pass `container` to mount inside an existing element and call the returned `destroy()` method to unmount programmatically.
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Styling
|
|
127
|
+
|
|
128
|
+
Default styles are bundled and injected automatically via Rollup’s PostCSS pipeline. To override the look & feel, update the widget’s appearance in the console or provide a custom `primaryColor`, `fontFamily`, or `borderRadius` from the backend configuration. For heavy customization, define a custom theme in your backend and serve additional CSS through the `customCSS` field—those rules are appended inside the widget root.
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Backend contract
|
|
133
|
+
|
|
134
|
+
The widget expects the following endpoints (see `src/api` for details):
|
|
135
|
+
|
|
136
|
+
| Endpoint | Purpose |
|
|
137
|
+
| ----------------------------------------------- | ----------------------------------------- |
|
|
138
|
+
| `GET /api/widget/:widgetId/config` | Returns appearance/behavior configuration |
|
|
139
|
+
| `GET /api/widget/:widgetId/conversation/:id` | Fetch existing conversation (or create) |
|
|
140
|
+
| `POST /api/widget/:widgetId/chat` | Standard chat message flow |
|
|
141
|
+
| `POST /api/widget/:widgetId/agent` | Agent/Tools conversation flow |
|
|
142
|
+
| `POST /api/widget/:widgetId/upload` | Secure file uploads |
|
|
143
|
+
| `POST /api/widget/:widgetId/feedback` | Capture thumbs-up / thumbs-down feedback |
|
|
144
|
+
|
|
145
|
+
Adjust the API paths on the client (override `apiUrl`) if your deployment differs.
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Development
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
pnpm install
|
|
153
|
+
pnpm build # creates CJS, ESM, and UMD bundles in dist/
|
|
154
|
+
pnpm lint
|
|
155
|
+
pnpm typecheck
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Rollup outputs:
|
|
159
|
+
|
|
160
|
+
- `dist/index.js` – CommonJS build (Node/SSR)
|
|
161
|
+
- `dist/index.esm.js` – ES module build (modern bundlers)
|
|
162
|
+
- `dist/ai-chat-widget.umd.js` – Browser-ready bundle exposing `window.AIChatWidget`
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## License
|
|
167
|
+
|
|
168
|
+
MIT © 2024 AI Chat Widget contributors
|