@vezlo/assistant-chat 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.
@@ -0,0 +1,255 @@
1
+ # Vezlo Assistant Chat Widget - NPM Package
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@vezlo/assistant-chat.svg)](https://www.npmjs.com/package/@vezlo/assistant-chat) [![license](https://img.shields.io/badge/license-AGPL--3.0-blue.svg)](https://opensource.org/licenses/AGPL-3.0)
4
+
5
+ A React component library for integrating AI assistant chat functionality into web applications.
6
+
7
+ > **📦 This is the NPM package documentation**
8
+ > **🏠 Repository**: [assistant-chat](https://github.com/vezlo/assistant-chat) - Contains both this NPM package and a standalone admin application
9
+ > **🖥️ Standalone App**: Want to run the admin dashboard? Visit the [main repository](https://github.com/vezlo/assistant-chat) for setup instructions
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install @vezlo/assistant-chat
15
+ ```
16
+
17
+ ## Requirements
18
+
19
+ - React 18 or higher
20
+ - Tailwind CSS (for styling)
21
+ - Assistant Server running (see [Assistant Server](https://github.com/vezlo/assistant-server))
22
+
23
+ ## Quick Start
24
+
25
+ ```tsx
26
+ import { Widget } from '@vezlo/assistant-chat';
27
+
28
+ function App() {
29
+ const widgetConfig = {
30
+ uuid: 'your-widget-uuid',
31
+ title: 'AI Assistant',
32
+ subtitle: 'How can I help you?',
33
+ placeholder: 'Type your message...',
34
+ welcomeMessage: 'Hello! How can I assist you today?',
35
+ themeColor: '#10b981',
36
+ position: 'bottom-right',
37
+ size: { width: 400, height: 600 },
38
+ defaultOpen: false
39
+ };
40
+
41
+ return <Widget config={widgetConfig} />;
42
+ }
43
+ ```
44
+
45
+ ## Configuration
46
+
47
+ The `WidgetConfig` interface includes:
48
+
49
+ - `uuid`: Unique identifier for your widget
50
+ - `title`: Header title
51
+ - `subtitle`: Subtitle text
52
+ - `placeholder`: Input placeholder text
53
+ - `welcomeMessage`: Initial message shown to users
54
+ - `themeColor`: Primary color for the widget
55
+ - `position`: Widget position ('bottom-right', 'bottom-left', 'top-right', 'top-left')
56
+ - `size`: Widget dimensions
57
+ - `defaultOpen`: Whether widget opens by default
58
+
59
+ ### Configuration Options Table
60
+
61
+ | Option | Type | Default | Description |
62
+ |--------|------|---------|-------------|
63
+ | `uuid` | string | Required | Unique identifier for the widget |
64
+ | `title` | string | `'AI Assistant'` | Widget header title |
65
+ | `subtitle` | string | `'How can I help you today?'` | Widget header subtitle |
66
+ | `placeholder` | string | `'Type your message...'` | Input placeholder text |
67
+ | `welcomeMessage` | string | `'Hello! I\'m your AI assistant...'` | Initial message shown to users |
68
+ | `themeColor` | string | `'#059669'` | Primary color for the widget |
69
+ | `position` | string | `'bottom-right'` | Position: `bottom-right`, `bottom-left`, `top-right`, `top-left` |
70
+ | `size` | object | `{ width: 420, height: 600 }` | Widget dimensions |
71
+ | `defaultOpen` | boolean | `false` | Whether widget opens by default |
72
+ | `apiUrl` | string | Required | Assistant Server API URL |
73
+ | `apiKey` | string | Required | API key for authentication |
74
+
75
+ ## API Integration
76
+
77
+ This widget requires a running Assistant Server instance. The widget will:
78
+
79
+ 1. Create conversations automatically
80
+ 2. Send user messages to the server
81
+ 3. Stream AI responses in real-time
82
+
83
+ Configure your Assistant Server URL in your application:
84
+
85
+ ```tsx
86
+ // The widget uses the API services included in this package
87
+ import { createConversation, createUserMessage, generateAIResponse } from '@vezlo/assistant-chat';
88
+ ```
89
+
90
+ For detailed API integration documentation, see [API Integration Guide](docs/API_INTEGRATION.md).
91
+
92
+ ## Knowledge Base Integration
93
+
94
+ To enable AI-powered code analysis and intelligent responses, integrate with [@vezlo/src-to-kb](https://www.npmjs.com/package/@vezlo/src-to-kb):
95
+
96
+ ```bash
97
+ npm install -g @vezlo/src-to-kb
98
+ src-to-kb /path/to/your/codebase --output ./knowledge-base
99
+ ```
100
+
101
+ The Assistant Server will automatically use this knowledge base to provide intelligent answers about your codebase.
102
+
103
+ ## Styling
104
+
105
+ The widget uses Tailwind CSS classes. Ensure your application has Tailwind CSS configured for proper styling.
106
+
107
+ ## Props
108
+
109
+ ### WidgetProps
110
+
111
+ - `config`: WidgetConfig - Configuration object
112
+ - `isPlayground?`: boolean - Internal use for playground mode
113
+ - `onOpen?`: () => void - Callback when widget opens
114
+ - `onClose?`: () => void - Callback when widget closes
115
+ - `onMessage?`: (message: ChatMessage) => void - Callback for new messages
116
+ - `onError?`: (error: string) => void - Callback for errors
117
+ - `useShadowRoot?`: boolean - Use Shadow DOM for style isolation
118
+
119
+ ## Examples
120
+
121
+ ### Basic Usage
122
+
123
+ ```tsx
124
+ import { Widget } from '@vezlo/assistant-chat';
125
+
126
+ function MyApp() {
127
+ return (
128
+ <div>
129
+ <h1>My Website</h1>
130
+ <Widget config={{
131
+ uuid: 'my-widget-123',
132
+ title: 'Support Chat',
133
+ themeColor: '#3b82f6',
134
+ position: 'bottom-right',
135
+ defaultOpen: false
136
+ }} />
137
+ </div>
138
+ );
139
+ }
140
+ ```
141
+
142
+ ### With Callbacks
143
+
144
+ ```tsx
145
+ import { Widget, type ChatMessage } from '@vezlo/assistant-chat';
146
+
147
+ function MyApp() {
148
+ const handleMessage = (message: ChatMessage) => {
149
+ console.log('New message:', message);
150
+ };
151
+
152
+ const handleError = (error: string) => {
153
+ console.error('Widget error:', error);
154
+ };
155
+
156
+ return (
157
+ <Widget
158
+ config={{
159
+ uuid: 'my-widget-123',
160
+ title: 'Support Chat',
161
+ themeColor: '#3b82f6'
162
+ }}
163
+ onMessage={handleMessage}
164
+ onError={handleError}
165
+ />
166
+ );
167
+ }
168
+ ```
169
+
170
+ ### Shadow DOM for Style Isolation
171
+
172
+ ```tsx
173
+ import { Widget } from '@vezlo/assistant-chat';
174
+
175
+ function MyApp() {
176
+ return (
177
+ <Widget
178
+ config={{
179
+ uuid: 'my-widget-123',
180
+ title: 'Support Chat',
181
+ themeColor: '#3b82f6'
182
+ }}
183
+ useShadowRoot={true} // Isolates styles from host app
184
+ />
185
+ );
186
+ }
187
+ ```
188
+
189
+ ## Troubleshooting
190
+
191
+ ### Widget Not Showing
192
+ - Ensure Tailwind CSS is configured in your app
193
+ - Check that the Assistant Server is running
194
+ - Verify the `uuid` is unique
195
+
196
+ ### Style Conflicts
197
+ - Use `useShadowRoot={true}` for style isolation
198
+ - Ensure Tailwind CSS is properly configured
199
+ - Check for conflicting CSS in your host application
200
+
201
+ ### API Errors
202
+ - Verify Assistant Server is running and accessible
203
+ - Check CORS settings on your Assistant Server
204
+ - Ensure the server URL is correct
205
+
206
+ ## Issues & Support
207
+
208
+ - **Package Issues**: [Assistant Chat Issues](https://github.com/vezlo/assistant-chat/issues)
209
+ - **Server Issues**: [Assistant Server Issues](https://github.com/vezlo/assistant-server/issues)
210
+ - **General Questions**: [Assistant Server Discussions](https://github.com/vezlo/assistant-server/discussions)
211
+
212
+ ## Contributing
213
+
214
+ We welcome contributions! Please see our contributing guidelines:
215
+
216
+ 1. **Fork the repository**
217
+ 2. **Create a feature branch**: `git checkout -b feature/amazing-feature`
218
+ 3. **Commit your changes**: `git commit -m 'Add amazing feature'`
219
+ 4. **Push to the branch**: `git push origin feature/amazing-feature`
220
+ 5. **Open a Pull Request**
221
+
222
+ ### Development Setup
223
+
224
+ ```bash
225
+ # Clone the repository
226
+ git clone https://github.com/vezlo/assistant-chat.git
227
+ cd assistant-chat
228
+
229
+ # Install dependencies
230
+ npm install
231
+
232
+ # Start development server
233
+ npm run dev
234
+
235
+ # Build the package
236
+ npm run build
237
+ ```
238
+
239
+ ### Code Style
240
+
241
+ - Use TypeScript for all new code
242
+ - Follow existing code patterns
243
+ - Add tests for new features
244
+ - Update documentation as needed
245
+
246
+ ## 📄 License
247
+
248
+ This project is dual-licensed:
249
+
250
+ - **Non-Commercial Use**: Free under AGPL-3.0 license
251
+ - **Commercial Use**: Requires a commercial license - contact us for details
252
+
253
+ ---
254
+
255
+ Made with Love by [Vezlo](https://www.vezlo.org/)
package/README.md ADDED
@@ -0,0 +1,241 @@
1
+ # Vezlo Assistant Chat
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@vezlo/assistant-chat.svg)](https://www.npmjs.com/package/@vezlo/assistant-chat) [![license](https://img.shields.io/badge/license-AGPL--3.0-blue.svg)](https://opensource.org/licenses/AGPL-3.0)
4
+
5
+ A complete chat widget solution with both a React component library and standalone admin application for AI-powered customer support.
6
+
7
+ ## What's Included
8
+
9
+ ### 📦 NPM Package
10
+ - **Reusable React Widget**: Install via `npm install @vezlo/assistant-chat`
11
+ - **TypeScript Support**: Full type definitions included
12
+ - **Customizable**: Themes, colors, positioning, and behavior
13
+ - **Real-time Streaming**: Live AI responses with streaming support
14
+ - **Style Isolation**: Shadow DOM support for conflict-free integration
15
+ - **📖 [Complete Package Documentation](PACKAGE_README.md)**
16
+
17
+ ### 🖥️ Standalone Application
18
+ - **Admin Dashboard**: Configure widgets with live preview
19
+ - **Playground**: Test widgets in isolated environment
20
+ - **Embed Code Generator**: Get ready-to-use embed codes
21
+ - **Docker Support**: Easy deployment with Docker Compose
22
+ - **Vercel Ready**: One-click deployment to Vercel
23
+
24
+ ## Quick Start
25
+
26
+ ### For Developers (NPM Package)
27
+
28
+ ```bash
29
+ npm install @vezlo/assistant-chat
30
+ ```
31
+
32
+ ```tsx
33
+ import { Widget } from '@vezlo/assistant-chat';
34
+
35
+ function App() {
36
+ const config = {
37
+ uuid: 'your-widget-uuid',
38
+ title: 'AI Assistant',
39
+ themeColor: '#10b981',
40
+ // ... other config
41
+ };
42
+
43
+ return <Widget config={config} />;
44
+ }
45
+ ```
46
+
47
+ **📖 [Complete NPM Package Documentation](PACKAGE_README.md)**
48
+
49
+ ### For Administrators (Standalone App)
50
+
51
+ This repository also contains a standalone admin application for configuring and managing widgets.
52
+
53
+ ```bash
54
+ # Clone and run the standalone app
55
+ git clone https://github.com/vezlo/assistant-chat.git
56
+ cd assistant-chat
57
+ npm install
58
+ npm run dev
59
+ ```
60
+
61
+ **Features:**
62
+ - Admin dashboard for widget configuration
63
+ - Live preview and playground
64
+ - Embed code generation
65
+ - Docker and Vercel deployment support
66
+
67
+ ## Prerequisites
68
+
69
+ - **Assistant Server**: Both components require a running Assistant Server
70
+ - Node.js 18+ and npm
71
+ - React 18+ (for package usage)
72
+
73
+ ## Features
74
+
75
+ ### Package Features
76
+ - ✅ React component library
77
+ - ✅ TypeScript support
78
+ - ✅ Tailwind CSS styling
79
+ - ✅ Real-time streaming
80
+ - ✅ Customizable themes
81
+ - ✅ Shadow DOM support
82
+ - ✅ API integration included
83
+
84
+ ### App Features
85
+ - ✅ Admin dashboard
86
+ - ✅ Live widget preview
87
+ - ✅ Playground testing
88
+ - ✅ Embed code generation
89
+ - ✅ Multiple widget management
90
+ - ✅ Docker support
91
+ - ✅ Vercel deployment
92
+
93
+ ## Deployment Options
94
+
95
+ ### Package (NPM)
96
+ ```bash
97
+ npm run build
98
+ npm pack # Test locally
99
+ npm publish # Publish to NPM
100
+ ```
101
+
102
+ ### App (Vercel)
103
+
104
+ #### One-Click Deploy
105
+ [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/vezlo/assistant-chat)
106
+
107
+ #### Manual Vercel CLI Deployment
108
+ ```bash
109
+ # Install Vercel CLI
110
+ npm i -g vercel
111
+
112
+ # Deploy from local directory
113
+ vercel
114
+
115
+ # Set environment variables (required)
116
+ vercel env add VITE_ASSISTANT_SERVER_URL
117
+ vercel env add VITE_ASSISTANT_SERVER_API_KEY
118
+
119
+ # Optional environment variables
120
+ vercel env add VITE_DEFAULT_USER_UUID
121
+ vercel env add VITE_DEFAULT_COMPANY_UUID
122
+ vercel env add VITE_WIDGET_DEFAULT_THEME
123
+ vercel env add VITE_WIDGET_DEFAULT_POSITION
124
+ vercel env add VITE_WIDGET_DEFAULT_SIZE
125
+
126
+ # Deploy to production
127
+ vercel --prod
128
+ ```
129
+
130
+ ### App (Docker)
131
+ ```bash
132
+ docker-compose up
133
+ ```
134
+
135
+ ## Repository Structure
136
+
137
+ This repository contains both the NPM package and standalone application:
138
+
139
+ ```
140
+ assistant-chat/
141
+ ├── src/
142
+ │ ├── components/Widget.tsx # Main widget component (used by both)
143
+ │ ├── api/ # API services
144
+ │ ├── types/ # TypeScript definitions
145
+ │ ├── utils/ # Utility functions
146
+ │ ├── config/ # Configuration
147
+ │ └── routes/ # Standalone app pages
148
+ ├── public/
149
+ │ └── widget.js # Embed script
150
+ ├── docs/ # Documentation
151
+ ├── README.md # This file (project overview)
152
+ ├── PACKAGE_README.md # NPM package documentation
153
+ └── package.json # Package configuration
154
+ ```
155
+
156
+ ### How It Works
157
+
158
+ - **Same Widget Code**: Both the NPM package and standalone app use the same `Widget.tsx` component
159
+ - **NPM Package**: Publishes the widget component as a reusable library
160
+ - **Standalone App**: Uses the widget component directly for admin interface and playground
161
+ - **No Duplication**: Single source of truth for the widget component
162
+
163
+ ## Architecture
164
+
165
+ ```
166
+ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
167
+ │ Codebase │───▶│ src-to-kb │───▶│ Knowledge Base │
168
+ │ (Your Code) │ │ (Analysis) │ │ (Vector DB) │
169
+ └─────────────────┘ └─────────────────┘ └─────────────────┘
170
+
171
+
172
+ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
173
+ │ Chat Widget │◄───│ Assistant Server│◀───│ AI Queries │
174
+ │ (This Package) │ │ (Backend) │ │ (RAG System) │
175
+ └─────────────────┘ └─────────────────┘ └─────────────────┘
176
+ ```
177
+
178
+ ## Knowledge Base Integration
179
+
180
+ To enable AI-powered code analysis and intelligent responses, integrate with [@vezlo/src-to-kb](https://www.npmjs.com/package/@vezlo/src-to-kb):
181
+
182
+ ```bash
183
+ npm install -g @vezlo/src-to-kb
184
+ src-to-kb /path/to/your/codebase --output ./knowledge-base
185
+ ```
186
+
187
+ The Assistant Server will automatically use this knowledge base to provide intelligent answers about your codebase.
188
+
189
+ ## API Integration
190
+
191
+ For detailed API integration documentation, see [API Integration Guide](docs/API_INTEGRATION.md).
192
+
193
+ ## Related Projects
194
+
195
+ - [@vezlo/assistant-server](https://www.npmjs.com/package/@vezlo/assistant-server) - Backend API server
196
+ - [@vezlo/src-to-kb](https://www.npmjs.com/package/@vezlo/src-to-kb) - NPM package for code analysis
197
+ - [@vezlo/ai-validator](https://www.npmjs.com/package/@vezlo/ai-validator) - AI validation tools
198
+
199
+ ## Contributing
200
+
201
+ We welcome contributions! Please see our contributing guidelines:
202
+
203
+ 1. **Fork the repository**
204
+ 2. **Create a feature branch**: `git checkout -b feature/amazing-feature`
205
+ 3. **Commit your changes**: `git commit -m 'Add amazing feature'`
206
+ 4. **Push to the branch**: `git push origin feature/amazing-feature`
207
+ 5. **Open a Pull Request**
208
+
209
+ ### Development Setup
210
+
211
+ ```bash
212
+ # Clone the repository
213
+ git clone https://github.com/vezlo/assistant-chat.git
214
+ cd assistant-chat
215
+
216
+ # Install dependencies
217
+ npm install
218
+
219
+ # Start development server
220
+ npm run dev
221
+
222
+ # Build the package
223
+ npm run build
224
+ ```
225
+
226
+ ## Issues & Support
227
+
228
+ - **Package Issues**: [Assistant Chat Issues](https://github.com/vezlo/assistant-chat/issues)
229
+ - **Server Issues**: [Assistant Server Issues](https://github.com/vezlo/assistant-server/issues)
230
+ - **General Questions**: [Assistant Server Discussions](https://github.com/vezlo/assistant-server/discussions)
231
+
232
+ ## 📄 License
233
+
234
+ This project is dual-licensed:
235
+
236
+ - **Non-Commercial Use**: Free under AGPL-3.0 license
237
+ - **Commercial Use**: Requires a commercial license - contact us for details
238
+
239
+ ---
240
+
241
+ Made with Love by [Vezlo](https://www.vezlo.org/)
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Conversation API Service
3
+ * Handles conversation creation and management
4
+ */
5
+ export interface CreateConversationRequest {
6
+ title: string;
7
+ user_uuid: string;
8
+ company_uuid: string;
9
+ }
10
+ export interface ConversationResponse {
11
+ uuid: string;
12
+ title: string;
13
+ user_uuid: string;
14
+ company_uuid: string;
15
+ message_count: number;
16
+ created_at: string;
17
+ updated_at: string;
18
+ }
19
+ /**
20
+ * Create a new conversation
21
+ */
22
+ export declare function createConversation(request: CreateConversationRequest): Promise<ConversationResponse>;
23
+ /**
24
+ * Get conversation by UUID
25
+ */
26
+ export declare function getConversation(uuid: string): Promise<ConversationResponse>;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Conversation API Service
3
+ * Handles conversation creation and management
4
+ */
5
+ const API_BASE_URL = import.meta.env.VITE_ASSISTANT_SERVER_URL || 'http://localhost:3000';
6
+ /**
7
+ * Create a new conversation
8
+ */
9
+ export async function createConversation(request) {
10
+ try {
11
+ const response = await fetch(`${API_BASE_URL}/api/conversations`, {
12
+ method: 'POST',
13
+ headers: {
14
+ 'Content-Type': 'application/json',
15
+ 'Accept': 'application/json',
16
+ },
17
+ body: JSON.stringify(request),
18
+ });
19
+ if (!response.ok) {
20
+ const errorData = await response.json().catch(() => ({}));
21
+ throw new Error(errorData.message || `Failed to create conversation: ${response.status}`);
22
+ }
23
+ const data = await response.json();
24
+ return data;
25
+ }
26
+ catch (error) {
27
+ console.error('[Conversation API] Error creating conversation:', error);
28
+ throw error;
29
+ }
30
+ }
31
+ /**
32
+ * Get conversation by UUID
33
+ */
34
+ export async function getConversation(uuid) {
35
+ try {
36
+ const response = await fetch(`${API_BASE_URL}/api/conversations/${uuid}`, {
37
+ method: 'GET',
38
+ headers: {
39
+ 'Accept': 'application/json',
40
+ },
41
+ });
42
+ if (!response.ok) {
43
+ throw new Error(`Failed to get conversation: ${response.status}`);
44
+ }
45
+ const data = await response.json();
46
+ return data;
47
+ }
48
+ catch (error) {
49
+ console.error('[Conversation API] Error getting conversation:', error);
50
+ throw error;
51
+ }
52
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * API Entry Point
3
+ * Central export for all API services
4
+ */
5
+ export * from './conversation.js';
6
+ export * from './message.js';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * API Entry Point
3
+ * Central export for all API services
4
+ */
5
+ export * from './conversation.js';
6
+ export * from './message.js';
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Message API Service
3
+ * Handles message creation and AI response generation
4
+ */
5
+ export interface CreateMessageRequest {
6
+ content: string;
7
+ }
8
+ export interface MessageResponse {
9
+ uuid: string;
10
+ conversation_uuid: string;
11
+ type: 'user' | 'assistant';
12
+ content: string;
13
+ created_at: string;
14
+ }
15
+ export interface GenerateMessageResponse {
16
+ uuid: string;
17
+ parent_message_uuid: string;
18
+ type: 'assistant';
19
+ content: string;
20
+ status: 'completed' | 'pending' | 'error';
21
+ created_at: string;
22
+ }
23
+ /**
24
+ * Create a user message in a conversation
25
+ */
26
+ export declare function createUserMessage(conversationUuid: string, request: CreateMessageRequest): Promise<MessageResponse>;
27
+ /**
28
+ * Generate AI response for a user message
29
+ */
30
+ export declare function generateAIResponse(userMessageUuid: string): Promise<GenerateMessageResponse>;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Message API Service
3
+ * Handles message creation and AI response generation
4
+ */
5
+ const API_BASE_URL = import.meta.env.VITE_ASSISTANT_SERVER_URL || 'http://localhost:3000';
6
+ /**
7
+ * Create a user message in a conversation
8
+ */
9
+ export async function createUserMessage(conversationUuid, request) {
10
+ try {
11
+ const response = await fetch(`${API_BASE_URL}/api/conversations/${conversationUuid}/messages`, {
12
+ method: 'POST',
13
+ headers: {
14
+ 'Content-Type': 'application/json',
15
+ 'Accept': 'application/json',
16
+ },
17
+ body: JSON.stringify(request),
18
+ });
19
+ if (!response.ok) {
20
+ const errorData = await response.json().catch(() => ({}));
21
+ throw new Error(errorData.message || `Failed to create message: ${response.status}`);
22
+ }
23
+ const data = await response.json();
24
+ return data;
25
+ }
26
+ catch (error) {
27
+ console.error('[Message API] Error creating user message:', error);
28
+ throw error;
29
+ }
30
+ }
31
+ /**
32
+ * Generate AI response for a user message
33
+ */
34
+ export async function generateAIResponse(userMessageUuid) {
35
+ try {
36
+ const response = await fetch(`${API_BASE_URL}/api/messages/${userMessageUuid}/generate`, {
37
+ method: 'POST',
38
+ headers: {
39
+ 'Accept': 'application/json',
40
+ },
41
+ });
42
+ if (!response.ok) {
43
+ const errorData = await response.json().catch(() => ({}));
44
+ throw new Error(errorData.message || `Failed to generate response: ${response.status}`);
45
+ }
46
+ const data = await response.json();
47
+ return data;
48
+ }
49
+ catch (error) {
50
+ console.error('[Message API] Error generating AI response:', error);
51
+ throw error;
52
+ }
53
+ }
@@ -0,0 +1,11 @@
1
+ import type { ChatMessage, WidgetConfig } from '../types/index.js';
2
+ export interface WidgetProps {
3
+ config: WidgetConfig;
4
+ isPlayground?: boolean;
5
+ onOpen?: () => void;
6
+ onClose?: () => void;
7
+ onMessage?: (message: ChatMessage) => void;
8
+ onError?: (error: string) => void;
9
+ useShadowRoot?: boolean;
10
+ }
11
+ export declare function Widget({ config, isPlayground, onOpen, onClose, onMessage, onError, useShadowRoot, }: WidgetProps): import("react/jsx-runtime").JSX.Element;