floating-copilot-widget 1.4.4 → 1.5.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
  # Floating Copilot Widget
2
2
 
3
- A lightweight, highly configurable floating chat widget plugin for React websites. Drop it into any React application and get an instantly customizable chat interface that can be dragged, resized, minimized, and maximized.
3
+ A lightweight, highly configurable floating chat widget plugin for React websites with **GitHub Copilot AI integration** for intelligent message processing and API calling.
4
4
 
5
5
  ## Features
6
6
 
@@ -12,6 +12,22 @@ A lightweight, highly configurable floating chat widget plugin for React website
12
12
  🎯 **Feature Rich** - Minimize, maximize, close buttons with callbacks
13
13
  💬 **Chat Interface** - Built-in message display with auto-scroll
14
14
  ⚡ **Performance** - Lightweight with zero external dependencies
15
+ 🤖 **AI-Powered** - GitHub Copilot integration for intent analysis
16
+ 🔌 **API Integrations** - Easy framework to connect your own APIs
17
+ 🎪 **Smart Routing** - Automatically call APIs based on user intent
18
+ 📊 **Custom Formatting** - Format API responses beautifully
19
+
20
+ ## What's New in v1.5.0 🎉
21
+
22
+ - ✅ **GitHub Copilot Integration** - AI-powered intent analysis
23
+ - ✅ **API Integration Framework** - Simple interface to connect your APIs
24
+ - ✅ **Pre-built Integrations** - 7 example API integrations included
25
+ - ✅ **Intent Analysis** - Automatic parameter extraction from user messages
26
+ - ✅ **Auto API Calling** - Routes to correct API based on detected intent
27
+ - ✅ **Interactive Parameter Collection** - Asks for missing fields one by one
28
+ - ✅ **Automatic API Execution** - Triggers API call when all parameters are collected
29
+ - ✅ **Beautiful UI** - Fixed button visibility and improved text contrast (v1.4.4)
30
+ - ✅ **Professional Bot Avatar** - Custom SVG bot icon with gradient
15
31
 
16
32
  ## Installation
17
33
 
@@ -23,6 +39,7 @@ yarn add floating-copilot-widget
23
39
 
24
40
  ## Quick Start
25
41
 
42
+ ### Basic Usage
26
43
  ```jsx
27
44
  import React from 'react';
28
45
  import FloatingCopilot from 'floating-copilot-widget';
@@ -30,21 +47,433 @@ import 'floating-copilot-widget/dist/FloatingCopilot.css';
30
47
 
31
48
  function App() {
32
49
  return (
33
- <div>
34
- <FloatingCopilot
35
- config={{
36
- title: 'Chat Assistant',
37
- position: 'bottom-right',
38
- onMessage: (message) => console.log('User said:', message),
39
- }}
40
- />
41
- </div>
50
+ <FloatingCopilot
51
+ config={{
52
+ title: 'Chat Assistant',
53
+ position: 'bottom-right'
54
+ }}
55
+ />
42
56
  );
43
57
  }
58
+ ```
59
+
60
+ ### With Copilot Integration
61
+ ```jsx
62
+ import FloatingCopilot, {
63
+ createUserAPIIntegration
64
+ } from 'floating-copilot-widget';
65
+
66
+ function App() {
67
+ const apis = [
68
+ createUserAPIIntegration('https://api.example.com')
69
+ ];
70
+
71
+ return (
72
+ <FloatingCopilot
73
+ config={{
74
+ title: 'AI Assistant',
75
+ copilot: {
76
+ config: {
77
+ githubToken: process.env.REACT_APP_GITHUB_TOKEN
78
+ },
79
+ apiIntegrations: apis,
80
+ enabled: true
81
+ }
82
+ }}
83
+ />
84
+ );
85
+ }
86
+ ```
87
+
88
+ ### With Interactive Parameter Collection
89
+
90
+ User flow:
91
+ ```
92
+ User: "Create a customer"
93
+ Bot: "What is the customer's name?"
94
+ User: "John Doe"
95
+ Bot: "What is the email?"
96
+ User: "john@example.com"
97
+ Bot: "What is the phone?"
98
+ User: "123-456-7890"
99
+ Bot: ✓ "Customer created! ID: 12345"
100
+ ```
101
+
102
+ Implementation:
103
+ ```jsx
104
+ import FloatingCopilot, {
105
+ createCustomAPIIntegration
106
+ } from 'floating-copilot-widget';
107
+
108
+ function App() {
109
+ const createCustomerAPI = createCustomAPIIntegration({
110
+ id: 'create_customer',
111
+ name: 'Create Customer',
112
+ endpoint: 'https://api.example.com/customers',
113
+ method: 'POST',
114
+ intents: ['create_customer', 'add_customer', 'new_customer'],
115
+
116
+ // Define required parameters - system will ask for these one by one
117
+ requiredParameters: [
118
+ {
119
+ name: 'name',
120
+ description: 'Full name of the customer',
121
+ type: 'text',
122
+ required: true,
123
+ example: 'John Doe'
124
+ },
125
+ {
126
+ name: 'email',
127
+ description: 'Email address',
128
+ type: 'email',
129
+ required: true,
130
+ example: 'john@example.com'
131
+ },
132
+ {
133
+ name: 'phone',
134
+ description: 'Phone number',
135
+ type: 'phone',
136
+ required: true,
137
+ example: '(555) 123-4567'
138
+ }
139
+ ],
140
+
141
+ // Transform parameters into API request
142
+ buildRequest: (params) => ({
143
+ name: params.name,
144
+ email: params.email,
145
+ phone: params.phone
146
+ }),
147
+
148
+ // Format API response for display
149
+ formatResponse: (data) => {
150
+ return `✓ **Customer Created!**\n\n**ID:** ${data.id}\n**Name:** ${data.name}`;
151
+ }
152
+ });
153
+
154
+ return (
155
+ <FloatingCopilot
156
+ config={{
157
+ title: 'Smart Assistant',
158
+ copilot: {
159
+ config: {
160
+ githubToken: process.env.REACT_APP_GITHUB_TOKEN
161
+ },
162
+ apiIntegrations: [createCustomerAPI],
163
+ enabled: true
164
+ }
165
+ }}
166
+ />
167
+ );
168
+ }
169
+ ```
170
+
171
+ ## Advanced Usage Guide
172
+
173
+ ### Interactive Parameter Collection - Complete Example
174
+
175
+ This is the most powerful feature. Define what parameters your API needs, and the system automatically asks for them one by one.
176
+
177
+ **User Interaction Flow:**
178
+ ```
179
+ User: "Create a customer"
180
+ Bot: "What is the customer's name?"
181
+ User: "John Doe"
182
+ Bot: "What is the email?"
183
+ User: "john@example.com"
184
+ Bot: "What is the phone?"
185
+ User: "555-123-4567"
186
+ Bot: ✓ "Customer created! ID: 12345"
187
+ ```
188
+
189
+ **Implementation:**
190
+
191
+ Step 1 - Define your API with required parameters:
192
+ ```jsx
193
+ import { createCustomAPIIntegration } from 'floating-copilot-widget';
194
+
195
+ const createCustomerAPI = createCustomAPIIntegration({
196
+ id: 'create_customer',
197
+ name: 'Create Customer',
198
+ endpoint: 'https://api.example.com/customers',
199
+ method: 'POST',
200
+ intents: ['create_customer', 'add_customer', 'new_customer'],
201
+
202
+ // Define required parameters - system asks for each missing one
203
+ requiredParameters: [
204
+ {
205
+ name: 'name',
206
+ description: 'Full name of the customer',
207
+ type: 'text',
208
+ required: true,
209
+ example: 'John Doe'
210
+ },
211
+ {
212
+ name: 'email',
213
+ description: 'Email address',
214
+ type: 'email',
215
+ required: true,
216
+ example: 'john@example.com'
217
+ },
218
+ {
219
+ name: 'phone',
220
+ description: 'Phone number',
221
+ type: 'phone',
222
+ required: true,
223
+ example: '(555) 123-4567'
224
+ },
225
+ {
226
+ name: 'address',
227
+ description: 'Street address',
228
+ type: 'text',
229
+ required: false, // Optional parameters
230
+ example: '123 Main St'
231
+ }
232
+ ],
233
+
234
+ // Transform collected parameters into API request
235
+ buildRequest: (params) => ({
236
+ name: params.name,
237
+ email: params.email,
238
+ phone: params.phone,
239
+ address: params.address || ''
240
+ }),
241
+
242
+ // Format API response for beautiful display
243
+ formatResponse: (data) => {
244
+ return `✓ **Customer Created Successfully!**\n\n` +
245
+ `**ID:** ${data.id}\n` +
246
+ `**Name:** ${data.name}\n` +
247
+ `**Email:** ${data.email}`;
248
+ },
249
+
250
+ // Optional: Control when API should be called
251
+ shouldCall: (intent, params) => {
252
+ return !!params.name && !!params.email && !!params.phone;
253
+ }
254
+ });
255
+ ```
44
256
 
45
- export default App;
257
+ Step 2 - Use in FloatingCopilot:
258
+ ```jsx
259
+ <FloatingCopilot
260
+ config={{
261
+ title: 'Smart Assistant',
262
+ copilot: {
263
+ config: {
264
+ githubToken: process.env.REACT_APP_GITHUB_TOKEN
265
+ },
266
+ apiIntegrations: [createCustomerAPI],
267
+ enabled: true
268
+ }
269
+ }}
270
+ />
46
271
  ```
47
272
 
273
+ That's it! The system will:
274
+ 1. Detect user intent (create_customer)
275
+ 2. Ask for missing parameters one by one
276
+ 3. Validate each parameter (email format, phone format, etc.)
277
+ 4. When all required parameters are collected, automatically call your API
278
+ 5. Display the formatted response
279
+
280
+ ### Custom API Integration
281
+
282
+ Create completely custom APIs:
283
+
284
+ ```jsx
285
+ import type { APIIntegration } from 'floating-copilot-widget';
286
+
287
+ const customAPI: APIIntegration = {
288
+ id: 'my_api',
289
+ name: 'My Custom API',
290
+ endpoint: 'https://api.example.com/action',
291
+ method: 'POST',
292
+ intents: ['my_intent', 'alternative_intent'],
293
+
294
+ requiredParameters: [
295
+ {
296
+ name: 'userId',
297
+ description: 'The user ID',
298
+ type: 'text',
299
+ required: true,
300
+ example: 'user_123'
301
+ }
302
+ ],
303
+
304
+ headers: {
305
+ 'Authorization': 'Bearer YOUR_API_KEY'
306
+ },
307
+
308
+ buildRequest: (params, context) => ({
309
+ user_id: params.userId,
310
+ context_data: context?.userData
311
+ }),
312
+
313
+ formatResponse: (data) => {
314
+ return `Result: ${JSON.stringify(data, null, 2)}`;
315
+ },
316
+
317
+ shouldCall: (intent, params) => {
318
+ return !!params.userId;
319
+ }
320
+ };
321
+ ```
322
+
323
+ ### Parameter Types and Validation
324
+
325
+ Supported parameter types with automatic validation:
326
+
327
+ ```jsx
328
+ requiredParameters: [
329
+ {
330
+ name: 'userEmail',
331
+ type: 'email', // ✓ Validates email format
332
+ description: 'User email address',
333
+ example: 'user@example.com'
334
+ },
335
+ {
336
+ name: 'phoneNumber',
337
+ type: 'phone', // ✓ Validates phone format
338
+ description: 'User phone',
339
+ example: '(555) 123-4567'
340
+ },
341
+ {
342
+ name: 'quantity',
343
+ type: 'number', // ✓ Validates numeric input
344
+ description: 'Order quantity',
345
+ example: '5'
346
+ },
347
+ {
348
+ name: 'startDate',
349
+ type: 'date', // ✓ Validates date format
350
+ description: 'Start date',
351
+ example: '2026-02-15'
352
+ },
353
+ {
354
+ name: 'notes',
355
+ type: 'text', // ✓ Plain text (any value)
356
+ description: 'Additional notes',
357
+ example: 'Rush delivery'
358
+ }
359
+ ]
360
+ ```
361
+
362
+ ### Pre-built Integrations
363
+
364
+ Use 7 pre-built templates:
365
+
366
+ ```jsx
367
+ import {
368
+ createUserAPIIntegration,
369
+ createSearchAPIIntegration,
370
+ createAnalysisAPIIntegration,
371
+ createActionAPIIntegration,
372
+ createDatabaseAPIIntegration,
373
+ createWeatherAPIIntegration,
374
+ createCustomAPIIntegration
375
+ } from 'floating-copilot-widget';
376
+
377
+ const apis = [
378
+ createUserAPIIntegration('https://api.example.com'),
379
+ createSearchAPIIntegration('https://api.example.com'),
380
+ // ... more
381
+ ];
382
+ ```
383
+
384
+ ### Direct Copilot Functions
385
+
386
+ For advanced use cases, call Copilot functions directly:
387
+
388
+ ```jsx
389
+ import {
390
+ analyzeUserIntent,
391
+ callAPI,
392
+ generateParameterPromptOrCallAPI,
393
+ areAllParametersCollected,
394
+ validateParameter,
395
+ getNextMissingParameter
396
+ } from 'floating-copilot-widget';
397
+
398
+ // Analyze user intent
399
+ const intent = await analyzeUserIntent(
400
+ { userMessage: 'Create a customer' },
401
+ config,
402
+ apis
403
+ );
404
+
405
+ // Check if all parameters are collected
406
+ const complete = areAllParametersCollected(api, {
407
+ name: 'John',
408
+ email: 'john@example.com'
409
+ });
410
+
411
+ // Validate individual parameter
412
+ const validation = validateParameter('email', userInput, {
413
+ type: 'email'
414
+ });
415
+
416
+ // Get next parameter to ask for
417
+ const nextParam = getNextMissingParameter(api, {
418
+ name: 'John'
419
+ });
420
+
421
+ // Get prompt or trigger API
422
+ const result = await generateParameterPromptOrCallAPI(
423
+ api,
424
+ { name: 'John', email: 'john@example.com', phone: '555-1234' },
425
+ 'create_customer'
426
+ );
427
+
428
+ if (result.apiResponse) {
429
+ console.log('API called:', result.apiResponse.data);
430
+ } else {
431
+ console.log('Ask user:', result.prompt);
432
+ }
433
+ ```
434
+
435
+ ### GitHub Token Configuration
436
+
437
+ The widget automatically looks for your GitHub token in these locations (in order):
438
+
439
+ 1. **Explicit config**: `config.copilot.config.githubToken = 'ghp_...'`
440
+ 2. **Environment variables**:
441
+ - `GITHUB_TOKEN` (Node.js)
442
+ - `VITE_GITHUB_TOKEN` (Vite)
443
+ - `REACT_APP_GITHUB_TOKEN` (Create React App)
444
+ 3. **Global variable**: `window.__GITHUB_TOKEN__`
445
+
446
+ **Recommended approach - Use environment variables:**
447
+
448
+ ```bash
449
+ # .env.local
450
+ REACT_APP_GITHUB_TOKEN=ghp_your_token_here
451
+ ```
452
+
453
+ Then no need to pass it in config:
454
+ ```jsx
455
+ <FloatingCopilot
456
+ config={{
457
+ copilot: {
458
+ config: {
459
+ // Token loaded from environment automatically!
460
+ model: 'gpt-4o'
461
+ },
462
+ // ... rest of config
463
+ }
464
+ }}
465
+ />
466
+ ```
467
+
468
+ **To get a token:**
469
+ 1. Visit https://github.com/settings/tokens
470
+ 2. Click "Generate new token (classic)"
471
+ 3. Select scopes:
472
+ - `copilot` - for Copilot API access
473
+ - `read:user` - for user data
474
+ 4. Copy the token and save securely
475
+ 5. Add to `.env.local` file
476
+
48
477
  ## Configuration
49
478
 
50
479
  Pass a `config` object to customize the widget:
@@ -86,16 +515,29 @@ Pass a `config` object to customize the widget:
86
515
  // Layering
87
516
  zIndex: 9999,
88
517
 
518
+ // Copilot AI Configuration
519
+ copilot: {
520
+ config: {
521
+ // Token auto-loaded from environment
522
+ model: 'gpt-4o', // GPT model to use
523
+ maxTokens: 2000, // Max response length
524
+ temperature: 0.7 // Creativity (0-1)
525
+ },
526
+ apiIntegrations: [], // Your custom APIs
527
+ enabled: true, // Enable/disable AI
528
+ showIntentAnalysis: false // Show detected intent
529
+ },
530
+
89
531
  // Callbacks
90
- onMessage: (message) => handleMessage(message),
91
- onClose: () => handleClose(),
92
- onMinimize: () => handleMinimize(),
93
- onMaximize: () => handleMaximize(),
532
+ onMessage: (message) => console.log(message),
533
+ onClose: () => {},
534
+ onMinimize: () => {},
535
+ onMaximize: () => {},
94
536
  }}
95
537
  />
96
538
  ```
97
539
 
98
- ## Configuration Options
540
+ ## Configuration
99
541
 
100
542
  ### Position
101
543
  - `bottom-right` (default)
@@ -218,6 +660,14 @@ const config: FloatingCopilotConfig = {
218
660
  <FloatingCopilot config={config} />
219
661
  ```
220
662
 
663
+ ## Documentation
664
+
665
+ - **Quick Start**: Read this README for basic setup
666
+ - **Implementation Guide**: See `QUICK_IMPLEMENTATION_GUIDE.md` for step-by-step parameter collection examples
667
+ - **Full Documentation**: See `COPILOT_INTEGRATION.md` for comprehensive API reference
668
+ - **Setup Reference**: See `COPILOT_SETUP.md` for feature details and best practices
669
+ - **Working Examples**: See `examples/CopilotExample.tsx` for 6 complete working examples
670
+
221
671
  ## License
222
672
 
223
673
  MIT
@@ -229,3 +679,9 @@ Contributions are welcome! Please feel free to submit a Pull Request.
229
679
  ## Support
230
680
 
231
681
  For issues or questions, please open an issue on the GitHub repository.
682
+
683
+ **Quick Links:**
684
+ - [GitHub Token Setup](https://github.com/settings/tokens)
685
+ - [Copilot Documentation](https://docs.github.com/en/copilot)
686
+ - [Report Issue](https://github.com/your-org/floating-copilot-widget/issues)
687
+
package/dist/index.d.ts CHANGED
@@ -2,3 +2,5 @@ import './FloatingCopilot.css';
2
2
  export { FloatingCopilot, default } from './FloatingCopilot';
3
3
  export type { FloatingCopilotConfig } from './types';
4
4
  export { defaultConfig } from './types';
5
+ export { analyzeUserIntent, callAPI, processUserMessage, generateCopilotResponse, validateAPIIntegration, mergeAPIIntegrations, validateGithubToken, getMissingParameters, getNextMissingParameter, areAllParametersCollected, validateParameter, generateParameterPrompt, generateParameterPromptOrCallAPI, type CopilotConfig, type CopilotIntentRequest, type CopilotIntentResponse, type APIIntegration, type APICallRequest, type APICallResponse, type CopilotChatMessage, type ParameterDefinition } from './services/copilot';
6
+ export { createCustomerAPIIntegration, createUserAPIIntegration, createAnalysisAPIIntegration, createSearchAPIIntegration, createActionAPIIntegration, createDatabaseAPIIntegration, createWeatherAPIIntegration, createCustomAPIIntegration } from './services/integrations';