@kite-copilot/chat-panel 0.1.2 → 0.2.1

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
@@ -1,6 +1,6 @@
1
1
  # @kite-copilot/chat-panel
2
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.
3
+ An AI-powered chat panel SDK for embedding intelligent chat assistants. This package provides a floating chat interface that integrates with any AI backend agent. Designed for PWAs, offline-capable apps, and traditional web applications.
4
4
 
5
5
  ## Features
6
6
 
@@ -9,7 +9,9 @@ An AI-powered chat panel component for React applications. This package provides
9
9
  - 🎯 **Interactive Guides**: Built-in guided tours with animated cursor
10
10
  - 🎨 **Customizable Themes**: Light and dark mode support
11
11
  - 📱 **Responsive Design**: Works on desktop and mobile
12
- - 🔌 **Easy Integration**: Simple props-based API with React Context for configuration
12
+ - 🔌 **Easy Integration**: Programmatic API or React component
13
+ - 📦 **PWA-Ready**: Fully bundled by your build tool, no CDN required
14
+ - 🌐 **Offline-Safe**: Works with service workers and precaching
13
15
 
14
16
  ## Installation
15
17
 
@@ -26,16 +28,187 @@ pnpm add @kite-copilot/chat-panel
26
28
  Make sure you have the following peer dependencies installed:
27
29
 
28
30
  ```bash
29
- npm install react react-dom lucide-react
31
+ npm install react react-dom
30
32
  ```
31
33
 
32
34
  ## Quick Start
33
35
 
34
- ### Basic Usage
36
+ ### Programmatic API (Recommended)
37
+
38
+ The programmatic API provides explicit lifecycle control - ideal for PWAs, Vue, Angular, or any framework.
39
+
40
+ ```ts
41
+ import { createKiteChat } from '@kite-copilot/chat-panel';
42
+ import '@kite-copilot/chat-panel/style.css';
43
+
44
+ // Create the chat instance
45
+ const chat = createKiteChat({
46
+ userId: 'user-123',
47
+ orgId: 'org-456',
48
+ agentUrl: 'https://your-api.example.com',
49
+ onNavigate: (page, subtab) => {
50
+ // Handle navigation requests from the chat
51
+ router.push(`/${page}${subtab ? `?tab=${subtab}` : ''}`);
52
+ },
53
+ onActionComplete: (actionType, data) => {
54
+ console.log('Action completed:', actionType, data);
55
+ },
56
+ });
57
+
58
+ // Mount into a container
59
+ chat.mount('#chat-container');
60
+
61
+ // Update state as needed
62
+ chat.setCurrentPage('settings');
63
+ chat.updateConfig({ theme: 'dark' });
64
+
65
+ // Clean up when done
66
+ chat.unmount();
67
+ ```
68
+
69
+ ### Auto-Mount Helper (Easy Mode)
70
+
71
+ For simpler use cases, use the auto-mount helper:
72
+
73
+ ```ts
74
+ import { mountKiteChat } from '@kite-copilot/chat-panel/auto';
75
+ import '@kite-copilot/chat-panel/style.css';
76
+
77
+ const chat = mountKiteChat({
78
+ container: '#chat-container',
79
+ userId: 'user-123',
80
+ orgId: 'org-456',
81
+ });
82
+
83
+ // Later, if needed:
84
+ chat.unmount();
85
+ ```
86
+
87
+ ### React Component
88
+
89
+ For React applications, use the component directly:
90
+
91
+ ```tsx
92
+ import { ChatPanel, ChatPanelProvider } from '@kite-copilot/chat-panel';
93
+ import '@kite-copilot/chat-panel/style.css';
94
+
95
+ function App() {
96
+ const { userId, orgId } = useAuth();
97
+
98
+ return (
99
+ <ChatPanelProvider config={{ userId, orgId }}>
100
+ <YourApp />
101
+ <ChatPanel />
102
+ </ChatPanelProvider>
103
+ );
104
+ }
105
+ ```
106
+
107
+ ## Framework Examples
108
+
109
+ ### Vue.js (PWA-Safe)
110
+
111
+ ```ts
112
+ // main.ts
113
+ import { createKiteChat } from '@kite-copilot/chat-panel';
114
+ import '@kite-copilot/chat-panel/style.css';
115
+ import { useRouter } from 'vue-router';
116
+
117
+ const router = useRouter();
118
+
119
+ const chat = createKiteChat({
120
+ userId: 'user-123',
121
+ orgId: 'org-456',
122
+ onNavigate: (page) => router.push(`/${page}`),
123
+ });
124
+
125
+ // Mount after Vue app is ready
126
+ app.mount('#app');
127
+ chat.mount('#kite-chat');
128
+ ```
129
+
130
+ ### Angular
131
+
132
+ ```ts
133
+ // chat.service.ts
134
+ import { Injectable, OnDestroy } from '@angular/core';
135
+ import { createKiteChat, KiteChatInstance } from '@kite-copilot/chat-panel';
136
+
137
+ @Injectable({ providedIn: 'root' })
138
+ export class ChatService implements OnDestroy {
139
+ private chat: KiteChatInstance;
140
+
141
+ constructor(private router: Router) {
142
+ this.chat = createKiteChat({
143
+ userId: 'user-123',
144
+ orgId: 'org-456',
145
+ onNavigate: (page) => this.router.navigate([page]),
146
+ });
147
+ }
148
+
149
+ mount(container: string) {
150
+ this.chat.mount(container);
151
+ }
152
+
153
+ ngOnDestroy() {
154
+ this.chat.unmount();
155
+ }
156
+ }
157
+ ```
158
+
159
+ ### Vanilla JavaScript
160
+
161
+ ```html
162
+ <div id="chat-container"></div>
163
+ <script type="module">
164
+ import { createKiteChat } from './node_modules/@kite-copilot/chat-panel/dist/index.js';
165
+
166
+ const chat = createKiteChat({
167
+ userId: 'user-123',
168
+ orgId: 'org-456',
169
+ });
170
+
171
+ chat.mount('#chat-container');
172
+ </script>
173
+ ```
174
+
175
+ ## API Reference
176
+
177
+ ### createKiteChat(config)
178
+
179
+ Creates a new chat instance with explicit lifecycle control.
180
+
181
+ #### KiteChatConfig
182
+
183
+ | Property | Type | Required | Description |
184
+ |----------|------|----------|-------------|
185
+ | `userId` | `string` | Yes | Unique identifier for the current user |
186
+ | `orgId` | `string` | Yes | Organization identifier |
187
+ | `agentUrl` | `string` | No | Backend agent API URL |
188
+ | `currentPage` | `string` | No | Current page context |
189
+ | `theme` | `'light' \| 'dark' \| 'system'` | No | Theme preference |
190
+ | `onNavigate` | `(page: string, subtab?: string) => void` | No | Navigation callback |
191
+ | `onActionComplete` | `(actionType: string, data: any) => void` | No | Action completion callback |
192
+
193
+ #### KiteChatInstance
194
+
195
+ | Method | Description |
196
+ |--------|-------------|
197
+ | `mount(container)` | Mount the chat widget into a container (selector or element) |
198
+ | `unmount()` | Unmount and clean up the chat widget |
199
+ | `setCurrentPage(page)` | Update the current page context |
200
+ | `updateConfig(config)` | Update configuration options |
201
+ | `isMounted()` | Check if the widget is currently mounted |
202
+
203
+ ---
204
+
205
+ ## React Component API
206
+
207
+ ### Basic Usage (React)
35
208
 
36
209
  ```tsx
37
210
  import { ChatPanel, ChatPanelProvider } from '@kite-copilot/chat-panel'
38
- import '@kite-copilot/chat-panel/styles.css'
211
+ import '@kite-copilot/chat-panel/style.css'
39
212
 
40
213
  function App() {
41
214
  // Get the current user from your authentication system
@@ -54,7 +227,7 @@ function App() {
54
227
 
55
228
  ```tsx
56
229
  import { ChatPanel, ChatPanelProvider } from '@kite-copilot/chat-panel'
57
- import '@kite-copilot/chat-panel/styles.css'
230
+ import '@kite-copilot/chat-panel/style.css'
58
231
  import { useRouter } from 'next/navigation'
59
232
 
60
233
  function App() {
@@ -235,7 +408,7 @@ const customFolders = [
235
408
  Import the CSS file in your app:
236
409
 
237
410
  ```tsx
238
- import '@kite-copilot/chat-panel/styles.css'
411
+ import '@kite-copilot/chat-panel/style.css'
239
412
  ```
240
413
 
241
414
  ### With Tailwind CSS
@@ -287,6 +460,10 @@ Full TypeScript support with exported types:
287
460
 
288
461
  ```tsx
289
462
  import type {
463
+ // Programmatic API types
464
+ KiteChatConfig,
465
+ KiteChatInstance,
466
+ // React component types
290
467
  ChatPanelConfig,
291
468
  ChatPanelProps,
292
469
  ActionType,
@@ -338,7 +515,7 @@ export function Providers({ children }) {
338
515
 
339
516
  // app/layout.tsx
340
517
  import { Providers } from './providers'
341
- import '@kite-copilot/chat-panel/styles.css'
518
+ import '@kite-copilot/chat-panel/style.css'
342
519
 
343
520
  export default function RootLayout({ children }) {
344
521
  return (
@@ -370,7 +547,7 @@ export default function Page() {
370
547
  ```tsx
371
548
  import { BrowserRouter, useLocation, useNavigate } from 'react-router-dom'
372
549
  import { ChatPanel, ChatPanelProvider } from '@kite-copilot/chat-panel'
373
- import '@kite-copilot/chat-panel/styles.css'
550
+ import '@kite-copilot/chat-panel/style.css'
374
551
  import { useAuth } from './auth' // Your auth provider
375
552
 
376
553
  function ChatPanelWithRouter() {