@kite-copilot/chat-panel 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 +408 -0
- package/dist/index.d.mts +376 -0
- package/dist/index.d.ts +376 -0
- package/dist/index.js +2738 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2692 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +74 -0
package/README.md
ADDED
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
# @kite/chat-panel
|
|
2
|
+
|
|
3
|
+
An AI-powered chat panel component for React applications. This package provides a floating chat interface that can integrate with any AI backend agent to provide intelligent assistance to users.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🤖 **AI-Powered Chat**: Connects to your AI backend agent for intelligent responses
|
|
8
|
+
- 📂 **CSV Bulk Operations**: Upload CSV files for bulk data processing
|
|
9
|
+
- 🎯 **Interactive Guides**: Built-in guided tours with animated cursor
|
|
10
|
+
- 🎨 **Customizable Themes**: Light and dark mode support
|
|
11
|
+
- 📱 **Responsive Design**: Works on desktop and mobile
|
|
12
|
+
- 🔌 **Easy Integration**: Simple props-based API with React Context for configuration
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @kite/chat-panel
|
|
18
|
+
# or
|
|
19
|
+
yarn add @kite/chat-panel
|
|
20
|
+
# or
|
|
21
|
+
pnpm add @kite/chat-panel
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Peer Dependencies
|
|
25
|
+
|
|
26
|
+
Make sure you have the following peer dependencies installed:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install react react-dom lucide-react
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
### Basic Usage
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
import { ChatPanel, ChatPanelProvider } from '@kite/chat-panel'
|
|
38
|
+
import '@kite/chat-panel/styles.css'
|
|
39
|
+
|
|
40
|
+
function App() {
|
|
41
|
+
// Get the current user from your authentication system
|
|
42
|
+
const { userId, orgId } = useAuth()
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<ChatPanelProvider config={{ userId, orgId }}>
|
|
46
|
+
<YourApp />
|
|
47
|
+
<ChatPanel />
|
|
48
|
+
</ChatPanelProvider>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### With Navigation Integration
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
import { ChatPanel, ChatPanelProvider } from '@kite/chat-panel'
|
|
57
|
+
import '@kite/chat-panel/styles.css'
|
|
58
|
+
import { useRouter } from 'next/navigation'
|
|
59
|
+
|
|
60
|
+
function App() {
|
|
61
|
+
const router = useRouter()
|
|
62
|
+
const { userId, orgId } = useAuth() // Your auth system
|
|
63
|
+
const [currentPage, setCurrentPage] = useState('dashboard')
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<ChatPanelProvider
|
|
67
|
+
config={{
|
|
68
|
+
userId,
|
|
69
|
+
orgId,
|
|
70
|
+
theme: 'light',
|
|
71
|
+
position: 'bottom-right',
|
|
72
|
+
}}
|
|
73
|
+
>
|
|
74
|
+
<YourApp />
|
|
75
|
+
<ChatPanel
|
|
76
|
+
currentPage={currentPage}
|
|
77
|
+
onNavigate={(page, subtab) => {
|
|
78
|
+
setCurrentPage(page)
|
|
79
|
+
router.push(`/${page}${subtab ? `?tab=${subtab}` : ''}`)
|
|
80
|
+
}}
|
|
81
|
+
onActionComplete={(actionType, data) => {
|
|
82
|
+
console.log('Action completed:', actionType, data)
|
|
83
|
+
// Refresh your data or perform other side effects
|
|
84
|
+
}}
|
|
85
|
+
/>
|
|
86
|
+
</ChatPanelProvider>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Configuration
|
|
92
|
+
|
|
93
|
+
### ChatPanelProvider Props
|
|
94
|
+
|
|
95
|
+
| Prop | Type | Description |
|
|
96
|
+
|------|------|-------------|
|
|
97
|
+
| `config` | `ChatPanelConfig` | Configuration object (see below) |
|
|
98
|
+
|
|
99
|
+
### ChatPanelConfig
|
|
100
|
+
|
|
101
|
+
| Property | Type | Default | Description |
|
|
102
|
+
|----------|------|---------|-------------|
|
|
103
|
+
| `userId` | `string` | **Required** | User ID of the end user querying the chat panel |
|
|
104
|
+
| `orgId` | `string` | **Required** | Organization ID the user belongs to |
|
|
105
|
+
| `agentUrl` | `string` | Built-in URL | Optional override for agent backend URL (for development/testing only) |
|
|
106
|
+
| `theme` | `'light' \| 'dark' \| 'system'` | `'light'` | Theme preference |
|
|
107
|
+
| `position` | `'bottom-right' \| 'bottom-left' \| 'custom'` | `'bottom-right'` | Panel position |
|
|
108
|
+
| `guides` | `Record<string, GuideWithSteps>` | - | Custom interactive guides |
|
|
109
|
+
| `folders` | `Folder[]` | - | Custom help topic folders |
|
|
110
|
+
| `showDefaultFolders` | `boolean` | `true` | Show default help topics |
|
|
111
|
+
| `enableGuideCursor` | `boolean` | `true` | Enable animated guide cursor |
|
|
112
|
+
| `className` | `string` | - | Custom CSS class |
|
|
113
|
+
|
|
114
|
+
### ChatPanel Props
|
|
115
|
+
|
|
116
|
+
| Prop | Type | Description |
|
|
117
|
+
|------|------|-------------|
|
|
118
|
+
| `currentPage` | `string` | Current page for context |
|
|
119
|
+
| `onNavigate` | `(page: string, subtab?: string) => void` | Navigation callback |
|
|
120
|
+
| `onActionComplete` | `(actionType: ActionType, data: ActionData) => void` | Action completion callback |
|
|
121
|
+
| `onAgentAction` | `(event: AgentActionCompleteEvent) => void` | Agent action callback |
|
|
122
|
+
| `onBack` | `() => void` | Back button callback |
|
|
123
|
+
| `config` | `ChatPanelConfig` | Override provider config |
|
|
124
|
+
|
|
125
|
+
## Backend Integration
|
|
126
|
+
|
|
127
|
+
The ChatPanel expects your backend agent to expose the following SSE endpoints. All requests include `user_id` and `org_id` in the request body.
|
|
128
|
+
|
|
129
|
+
### `/chat/stream` (POST)
|
|
130
|
+
|
|
131
|
+
Main chat endpoint for streaming responses.
|
|
132
|
+
|
|
133
|
+
**Request Body:**
|
|
134
|
+
```json
|
|
135
|
+
{
|
|
136
|
+
"session_id": "uuid",
|
|
137
|
+
"user_id": "user-123",
|
|
138
|
+
"org_id": "org-456",
|
|
139
|
+
"message": "user message",
|
|
140
|
+
"current_page": "dashboard"
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
**SSE Events:**
|
|
145
|
+
- `progress`: Processing status updates
|
|
146
|
+
- `response`: AI response with optional actions
|
|
147
|
+
- `error`: Error messages
|
|
148
|
+
- `done`: Stream completion
|
|
149
|
+
|
|
150
|
+
### `/chat/bulk/stream` (POST)
|
|
151
|
+
|
|
152
|
+
CSV file upload endpoint for bulk operations.
|
|
153
|
+
|
|
154
|
+
**Request:** FormData with `file`, `message`, `session_id`, `user_id`, `org_id`, `current_page`
|
|
155
|
+
|
|
156
|
+
**SSE Events:**
|
|
157
|
+
- `preview`: CSV preview with row count and sample data
|
|
158
|
+
- `error`: Error messages
|
|
159
|
+
|
|
160
|
+
### `/chat/bulk/confirm` (POST)
|
|
161
|
+
|
|
162
|
+
Confirm and execute bulk operation.
|
|
163
|
+
|
|
164
|
+
**Request Body:**
|
|
165
|
+
```json
|
|
166
|
+
{
|
|
167
|
+
"session_id": "uuid",
|
|
168
|
+
"user_id": "user-123",
|
|
169
|
+
"org_id": "org-456",
|
|
170
|
+
"bulk_session_id": "bulk-uuid"
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**SSE Events:**
|
|
175
|
+
- `progress`: Row-by-row processing updates
|
|
176
|
+
- `summary`: Final results with success/failure counts
|
|
177
|
+
- `error`: Error messages
|
|
178
|
+
|
|
179
|
+
## Custom Guides
|
|
180
|
+
|
|
181
|
+
You can add custom interactive guides:
|
|
182
|
+
|
|
183
|
+
```tsx
|
|
184
|
+
const customGuides = {
|
|
185
|
+
'my-guide': {
|
|
186
|
+
id: 'my-guide',
|
|
187
|
+
title: 'My Custom Guide',
|
|
188
|
+
steps: [
|
|
189
|
+
{
|
|
190
|
+
text: 'Step 1: Click the button below',
|
|
191
|
+
navigation: { page: 'settings' },
|
|
192
|
+
cursorTarget: {
|
|
193
|
+
selector: '[data-testid="my-button"]',
|
|
194
|
+
onClick: true
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
// More steps...
|
|
198
|
+
]
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
<ChatPanelProvider config={{ userId, orgId, guides: customGuides }}>
|
|
203
|
+
...
|
|
204
|
+
</ChatPanelProvider>
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Custom Help Topics
|
|
208
|
+
|
|
209
|
+
Add custom help topic folders:
|
|
210
|
+
|
|
211
|
+
```tsx
|
|
212
|
+
const customFolders = [
|
|
213
|
+
{
|
|
214
|
+
id: 'support',
|
|
215
|
+
title: 'Support',
|
|
216
|
+
topics: [
|
|
217
|
+
{
|
|
218
|
+
id: 'contact',
|
|
219
|
+
label: 'Contact Us',
|
|
220
|
+
prompt: 'How can I contact support?'
|
|
221
|
+
}
|
|
222
|
+
]
|
|
223
|
+
}
|
|
224
|
+
]
|
|
225
|
+
|
|
226
|
+
<ChatPanelProvider config={{ userId, orgId, folders: customFolders }}>
|
|
227
|
+
...
|
|
228
|
+
</ChatPanelProvider>
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Styling
|
|
232
|
+
|
|
233
|
+
### Using the Default Styles
|
|
234
|
+
|
|
235
|
+
Import the CSS file in your app:
|
|
236
|
+
|
|
237
|
+
```tsx
|
|
238
|
+
import '@kite/chat-panel/styles.css'
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### With Tailwind CSS
|
|
242
|
+
|
|
243
|
+
If you're using Tailwind, extend your config with our preset:
|
|
244
|
+
|
|
245
|
+
```js
|
|
246
|
+
// tailwind.config.js
|
|
247
|
+
module.exports = {
|
|
248
|
+
content: [
|
|
249
|
+
// ... your paths
|
|
250
|
+
'./node_modules/@kite/chat-panel/dist/**/*.{js,mjs}'
|
|
251
|
+
],
|
|
252
|
+
theme: {
|
|
253
|
+
extend: {
|
|
254
|
+
colors: {
|
|
255
|
+
background: "var(--background)",
|
|
256
|
+
foreground: "var(--foreground)",
|
|
257
|
+
// ... other theme colors
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### CSS Variables
|
|
265
|
+
|
|
266
|
+
The component uses CSS variables for theming. Override them in your CSS:
|
|
267
|
+
|
|
268
|
+
```css
|
|
269
|
+
:root {
|
|
270
|
+
--background: oklch(1 0 0);
|
|
271
|
+
--foreground: oklch(0.145 0 0);
|
|
272
|
+
--primary: oklch(0.205 0 0);
|
|
273
|
+
--primary-foreground: oklch(0.985 0 0);
|
|
274
|
+
/* ... more variables */
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
.dark {
|
|
278
|
+
--background: oklch(0.145 0 0);
|
|
279
|
+
--foreground: oklch(0.985 0 0);
|
|
280
|
+
/* ... dark mode overrides */
|
|
281
|
+
}
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## TypeScript
|
|
285
|
+
|
|
286
|
+
Full TypeScript support with exported types:
|
|
287
|
+
|
|
288
|
+
```tsx
|
|
289
|
+
import type {
|
|
290
|
+
ChatPanelConfig,
|
|
291
|
+
ChatPanelProps,
|
|
292
|
+
ActionType,
|
|
293
|
+
ActionData,
|
|
294
|
+
Message,
|
|
295
|
+
GuideWithSteps,
|
|
296
|
+
Folder,
|
|
297
|
+
} from '@kite/chat-panel'
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
## Events
|
|
301
|
+
|
|
302
|
+
The ChatPanel dispatches window events for backward compatibility:
|
|
303
|
+
|
|
304
|
+
- `agentActionComplete`: Fired when the agent completes an action
|
|
305
|
+
- `integrationTabClicked`: Listen for this to trigger contextual messages
|
|
306
|
+
|
|
307
|
+
```tsx
|
|
308
|
+
window.addEventListener('agentActionComplete', (e) => {
|
|
309
|
+
console.log('Agent action:', e.detail.result)
|
|
310
|
+
})
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
## Examples
|
|
314
|
+
|
|
315
|
+
### Next.js App Router
|
|
316
|
+
|
|
317
|
+
```tsx
|
|
318
|
+
// app/providers.tsx
|
|
319
|
+
'use client'
|
|
320
|
+
|
|
321
|
+
import { ChatPanelProvider } from '@kite/chat-panel'
|
|
322
|
+
import { useAuth } from './auth' // Your auth provider
|
|
323
|
+
|
|
324
|
+
export function Providers({ children }) {
|
|
325
|
+
const { userId, orgId } = useAuth()
|
|
326
|
+
|
|
327
|
+
return (
|
|
328
|
+
<ChatPanelProvider
|
|
329
|
+
config={{
|
|
330
|
+
userId,
|
|
331
|
+
orgId,
|
|
332
|
+
}}
|
|
333
|
+
>
|
|
334
|
+
{children}
|
|
335
|
+
</ChatPanelProvider>
|
|
336
|
+
)
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// app/layout.tsx
|
|
340
|
+
import { Providers } from './providers'
|
|
341
|
+
import '@kite/chat-panel/styles.css'
|
|
342
|
+
|
|
343
|
+
export default function RootLayout({ children }) {
|
|
344
|
+
return (
|
|
345
|
+
<html>
|
|
346
|
+
<body>
|
|
347
|
+
<Providers>{children}</Providers>
|
|
348
|
+
</body>
|
|
349
|
+
</html>
|
|
350
|
+
)
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// app/page.tsx
|
|
354
|
+
'use client'
|
|
355
|
+
|
|
356
|
+
import { ChatPanel } from '@kite/chat-panel'
|
|
357
|
+
|
|
358
|
+
export default function Page() {
|
|
359
|
+
return (
|
|
360
|
+
<main>
|
|
361
|
+
<h1>My App</h1>
|
|
362
|
+
<ChatPanel currentPage="home" />
|
|
363
|
+
</main>
|
|
364
|
+
)
|
|
365
|
+
}
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
### React with React Router
|
|
369
|
+
|
|
370
|
+
```tsx
|
|
371
|
+
import { BrowserRouter, useLocation, useNavigate } from 'react-router-dom'
|
|
372
|
+
import { ChatPanel, ChatPanelProvider } from '@kite/chat-panel'
|
|
373
|
+
import '@kite/chat-panel/styles.css'
|
|
374
|
+
import { useAuth } from './auth' // Your auth provider
|
|
375
|
+
|
|
376
|
+
function ChatPanelWithRouter() {
|
|
377
|
+
const location = useLocation()
|
|
378
|
+
const navigate = useNavigate()
|
|
379
|
+
const currentPage = location.pathname.slice(1) || 'dashboard'
|
|
380
|
+
|
|
381
|
+
return (
|
|
382
|
+
<ChatPanel
|
|
383
|
+
currentPage={currentPage}
|
|
384
|
+
onNavigate={(page) => navigate(`/${page}`)}
|
|
385
|
+
/>
|
|
386
|
+
)
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function App() {
|
|
390
|
+
const { userId, orgId } = useAuth()
|
|
391
|
+
|
|
392
|
+
return (
|
|
393
|
+
<BrowserRouter>
|
|
394
|
+
<ChatPanelProvider config={{ userId, orgId }}>
|
|
395
|
+
<Routes>
|
|
396
|
+
{/* Your routes */}
|
|
397
|
+
</Routes>
|
|
398
|
+
<ChatPanelWithRouter />
|
|
399
|
+
</ChatPanelProvider>
|
|
400
|
+
</BrowserRouter>
|
|
401
|
+
)
|
|
402
|
+
}
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
## License
|
|
406
|
+
|
|
407
|
+
MIT © kite
|
|
408
|
+
|