@foisit/react-wrapper 2.0.0 β†’ 2.1.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.
Files changed (2) hide show
  1. package/README.md +639 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,639 @@
1
+ # @foisit/react-wrapper
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@foisit/react-wrapper.svg)](https://www.npmjs.com/package/@foisit/react-wrapper)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ > **The AI-Powered Conversational Assistant for React Applications**
7
+
8
+ Transform your React app into an intelligent, voice-ready platform. Foisit provides a drop-in AI layer that understands natural language, manages multi-step workflows, and executes actionsβ€”all with zero backend required.
9
+
10
+ > [!NOTE]
11
+ > πŸŽ™οΈ **Voice Support Status**: Voice recognition and responses are currently in development and will be released in a future update. The current version focuses on high-performance text-based interactions and AI intent matching.
12
+
13
+ ---
14
+
15
+ ## πŸ“‹ Table of Contents
16
+
17
+ - [Features](#-features)
18
+ - [Installation](#-installation)
19
+ - [Quick Start](#-quick-start)
20
+ - [Core Concepts](#-core-concepts)
21
+ - [API Reference](#-api-reference)
22
+ - [Advanced Usage](#-advanced-usage)
23
+ - [Examples](#-examples)
24
+ - [TypeScript Support](#-typescript-support)
25
+ - [Best Practices](#-best-practices)
26
+
27
+ ---
28
+
29
+ ## ✨ Features
30
+
31
+ - **🧠 Natural Language Understanding** - AI-powered intent matching using GPT-4o mini (proxied securely)
32
+ - **πŸ“ Smart Slot Filling** - Auto-generates forms for missing parameters
33
+ - **⚠️ Critical Action Protection** - Built-in confirmation dialogs for dangerous operations
34
+ - **🎨 Premium UI** - Glassmorphic overlay with dark/light mode support
35
+ - **πŸ”’ Zero Backend Required** - Secure proxy architecture keeps API keys server-side
36
+ - **⚑ React Native** - Uses Hooks, Context API, and modern React patterns
37
+ - **🎯 Type-Safe** - Full TypeScript support with comprehensive types
38
+ - **πŸ“± Responsive** - Works flawlessly on desktop and mobile
39
+
40
+ ---
41
+
42
+ ## πŸš€ Installation
43
+
44
+ ```bash
45
+ npm install @foisit/react-wrapper
46
+ ```
47
+
48
+ ### Peer Dependencies
49
+
50
+ ```json
51
+ {
52
+ "react": "^18.0.0",
53
+ "react-dom": "^18.0.0"
54
+ }
55
+ ```
56
+
57
+ ---
58
+
59
+ ## 🏁 Quick Start
60
+
61
+ ### Step 1: Wrap Your App
62
+
63
+ ```tsx
64
+ import React from 'react';
65
+ import { AssistantProvider } from '@foisit/react-wrapper';
66
+
67
+ const config = {
68
+ introMessage: 'Welcome! How can I assist you today?',
69
+ enableSmartIntent: true,
70
+ commands: [
71
+ {
72
+ command: 'navigate to profile',
73
+ action: () => {
74
+ window.location.href = '/profile';
75
+ return 'Navigating to profile...';
76
+ },
77
+ },
78
+ ],
79
+ };
80
+
81
+ function App() {
82
+ return (
83
+ <AssistantProvider config={config}>
84
+ <YourApp />
85
+ </AssistantProvider>
86
+ );
87
+ }
88
+
89
+ export default App;
90
+ ```
91
+
92
+ ### Step 2: Use the Hook
93
+
94
+ ```tsx
95
+ import React from 'react';
96
+ import { useAssistant } from '@foisit/react-wrapper';
97
+
98
+ function MyComponent() {
99
+ const assistant = useAssistant();
100
+
101
+ return <button onClick={() => assistant.toggle()}>Open Assistant</button>;
102
+ }
103
+ ```
104
+
105
+ ---
106
+
107
+ ## 🎯 Core Concepts
108
+
109
+ ### 1. Commands
110
+
111
+ Commands are the building blocks of your assistant. Each command represents an action users can trigger through natural language.
112
+
113
+ ```tsx
114
+ {
115
+ command: 'delete account',
116
+ description: 'Permanently delete user account',
117
+ action: () => accountService.delete()
118
+ }
119
+ ```
120
+
121
+ ### 2. Parameters (Slot Filling)
122
+
123
+ Define parameters and Foisit will automatically generate forms to collect them:
124
+
125
+ ```tsx
126
+ {
127
+ command: 'create user',
128
+ description: 'Create a new user account',
129
+ parameters: [
130
+ { name: 'username', type: 'string', required: true },
131
+ { name: 'email', type: 'string', required: true },
132
+ { name: 'age', type: 'number', required: false }
133
+ ],
134
+ action: (params) => userService.create(params)
135
+ }
136
+ ```
137
+
138
+ **Supported Parameter Types:**
139
+
140
+ - `string` - Text input
141
+ - `number` - Numeric input
142
+ - `date` - Date picker
143
+ - `select` - Dropdown (static or async options)
144
+
145
+ ### 3. Critical Actions
146
+
147
+ Protect dangerous operations with automatic confirmation dialogs:
148
+
149
+ ```tsx
150
+ {
151
+ command: 'delete all data',
152
+ critical: true, // πŸ”’ Requires confirmation
153
+ description: 'Permanently delete all application data',
154
+ action: async () => {
155
+ await dataService.deleteAll();
156
+ return 'βœ… All data deleted successfully.';
157
+ }
158
+ }
159
+ ```
160
+
161
+ ### 4. Select Parameters (Static)
162
+
163
+ Provide predefined options:
164
+
165
+ ```tsx
166
+ {
167
+ command: 'set theme',
168
+ parameters: [{
169
+ name: 'theme',
170
+ type: 'select',
171
+ options: [
172
+ { label: 'Light Mode', value: 'light' },
173
+ { label: 'Dark Mode', value: 'dark' },
174
+ { label: 'Auto', value: 'auto' }
175
+ ]
176
+ }],
177
+ action: (params) => setTheme(params.theme)
178
+ }
179
+ ```
180
+
181
+ ### 5. Dynamic Select Parameters
182
+
183
+ Load options from APIs:
184
+
185
+ ```tsx
186
+ {
187
+ command: 'assign to user',
188
+ parameters: [{
189
+ name: 'userId',
190
+ type: 'select',
191
+ getOptions: async () => {
192
+ const users = await userService.getAll();
193
+ return users.map(u => ({
194
+ label: `${u.name} (${u.email})`,
195
+ value: u.id
196
+ }));
197
+ }
198
+ }],
199
+ action: (params) => taskService.assign(params.userId)
200
+ }
201
+ ```
202
+
203
+ ---
204
+
205
+ ## πŸ“˜ API Reference
206
+
207
+ ### `useAssistant()` Hook
208
+
209
+ React hook for programmatic control:
210
+
211
+ #### Methods
212
+
213
+ ##### `toggle(onSubmit?, onClose?)`
214
+
215
+ Opens or closes the assistant overlay.
216
+
217
+ ```tsx
218
+ const assistant = useAssistant();
219
+
220
+ // Basic usage
221
+ assistant.toggle();
222
+
223
+ // With callbacks
224
+ assistant.toggle(
225
+ (userInput) => console.log('User said:', userInput),
226
+ () => console.log('Assistant closed')
227
+ );
228
+ ```
229
+
230
+ ##### `addCommand(command, action?)`
231
+
232
+ Dynamically add a command at runtime.
233
+
234
+ ```tsx
235
+ // Add a simple command
236
+ assistant.addCommand('refresh data', async () => {
237
+ await dataService.refresh();
238
+ return 'Data refreshed!';
239
+ });
240
+
241
+ // Add a command with full config
242
+ assistant.addCommand({
243
+ command: 'export report',
244
+ description: 'Export data as PDF',
245
+ parameters: [
246
+ {
247
+ name: 'format',
248
+ type: 'select',
249
+ options: [
250
+ { label: 'PDF', value: 'pdf' },
251
+ { label: 'Excel', value: 'xlsx' },
252
+ ],
253
+ },
254
+ ],
255
+ action: async (params) => {
256
+ await reportService.export(params.format);
257
+ return `Report exported as ${params.format}`;
258
+ },
259
+ });
260
+ ```
261
+
262
+ ##### `removeCommand(commandPhrase)`
263
+
264
+ Remove a registered command.
265
+
266
+ ```tsx
267
+ assistant.removeCommand('delete account');
268
+ ```
269
+
270
+ ##### `getCommands()`
271
+
272
+ Get list of all registered command names.
273
+
274
+ ```tsx
275
+ const commands = assistant.getCommands();
276
+ console.log('Available commands:', commands);
277
+ ```
278
+
279
+ ---
280
+
281
+ ## πŸ”§ Configuration Options
282
+
283
+ ### `AssistantConfig`
284
+
285
+ ```typescript
286
+ interface AssistantConfig {
287
+ // Activation keyword (optional)
288
+ activationCommand?: string;
289
+
290
+ // Welcome message shown when assistant opens
291
+ introMessage?: string;
292
+
293
+ // Response for unrecognized inputs
294
+ fallbackResponse?: string;
295
+
296
+ // Enable AI-powered natural language understanding
297
+ enableSmartIntent?: boolean;
298
+
299
+ // Input field placeholder text
300
+ inputPlaceholder?: string;
301
+
302
+ // List of commands
303
+ commands: AssistantCommand[];
304
+
305
+ // Floating button configuration
306
+ floatingButton?: {
307
+ visible?: boolean;
308
+ tooltip?: string;
309
+ customHtml?: string;
310
+ position?: { bottom: string; right: string };
311
+ };
312
+ }
313
+ ```
314
+
315
+ ---
316
+
317
+ ## 🎨 Advanced Usage
318
+
319
+ ### Example 1: Multi-Step Booking System with State
320
+
321
+ ```tsx
322
+ import React, { useState } from 'react';
323
+ import { useAssistant, AssistantProvider } from '@foisit/react-wrapper';
324
+
325
+ function BookingApp() {
326
+ const [bookings, setBookings] = useState([]);
327
+ const assistant = useAssistant();
328
+
329
+ React.useEffect(() => {
330
+ assistant.addCommand({
331
+ command: 'book appointment',
332
+ description: 'Schedule a new appointment',
333
+ parameters: [
334
+ {
335
+ name: 'service',
336
+ type: 'select',
337
+ required: true,
338
+ getOptions: async () => {
339
+ const services = await fetch('/api/services').then((r) => r.json());
340
+ return services.map((s) => ({
341
+ label: s.name,
342
+ value: s.id,
343
+ }));
344
+ },
345
+ },
346
+ {
347
+ name: 'date',
348
+ type: 'date',
349
+ required: true,
350
+ },
351
+ {
352
+ name: 'notes',
353
+ type: 'string',
354
+ required: false,
355
+ },
356
+ ],
357
+ action: async (params) => {
358
+ const booking = await fetch('/api/bookings', {
359
+ method: 'POST',
360
+ body: JSON.stringify(params),
361
+ }).then((r) => r.json());
362
+
363
+ setBookings((prev) => [...prev, booking]);
364
+ return {
365
+ type: 'success',
366
+ message: `βœ… Appointment booked for ${params.date}!`,
367
+ };
368
+ },
369
+ });
370
+ }, [assistant]);
371
+
372
+ return (
373
+ <div>
374
+ <h1>My Bookings: {bookings.length}</h1>
375
+ <button onClick={() => assistant.toggle()}>Book New Appointment</button>
376
+ </div>
377
+ );
378
+ }
379
+ ```
380
+
381
+ ### Example 2: E-Commerce with React Router
382
+
383
+ ```tsx
384
+ import { useNavigate } from 'react-router-dom';
385
+ import { useAssistant } from '@foisit/react-wrapper';
386
+
387
+ function ProductSearch() {
388
+ const navigate = useNavigate();
389
+ const assistant = useAssistant();
390
+
391
+ React.useEffect(() => {
392
+ assistant.addCommand({
393
+ command: 'search products',
394
+ parameters: [
395
+ { name: 'query', type: 'string', required: true },
396
+ {
397
+ name: 'category',
398
+ type: 'select',
399
+ required: false,
400
+ options: [
401
+ { label: 'Electronics', value: 'electronics' },
402
+ { label: 'Clothing', value: 'clothing' },
403
+ { label: 'Books', value: 'books' },
404
+ ],
405
+ },
406
+ { name: 'minPrice', type: 'number', required: false },
407
+ ],
408
+ action: async (params) => {
409
+ const results = await searchProducts(params);
410
+ navigate(`/products?q=${params.query}`);
411
+ return `Found ${results.length} products matching "${params.query}"`;
412
+ },
413
+ });
414
+ }, [assistant, navigate]);
415
+
416
+ return <div>Search component</div>;
417
+ }
418
+ ```
419
+
420
+ ### Example 3: Form Validation with State Management
421
+
422
+ ```tsx
423
+ import { useState } from 'react';
424
+ import { useAssistant } from '@foisit/react-wrapper';
425
+
426
+ function AccountManager() {
427
+ const [user, setUser] = useState(null);
428
+ const assistant = useAssistant();
429
+
430
+ React.useEffect(() => {
431
+ assistant.addCommand({
432
+ command: 'create account',
433
+ parameters: [
434
+ { name: 'email', type: 'string', required: true },
435
+ { name: 'password', type: 'string', required: true },
436
+ { name: 'age', type: 'number', required: true },
437
+ ],
438
+ action: async (params) => {
439
+ // Validation
440
+ if (params.age < 18) {
441
+ return {
442
+ type: 'error',
443
+ message: '❌ You must be 18 or older to create an account.',
444
+ };
445
+ }
446
+
447
+ if (!params.email.includes('@')) {
448
+ return {
449
+ type: 'error',
450
+ message: '❌ Please provide a valid email address.',
451
+ };
452
+ }
453
+
454
+ // Create account
455
+ try {
456
+ const newUser = await authService.register(params);
457
+ setUser(newUser);
458
+ return {
459
+ type: 'success',
460
+ message: 'βœ… Account created successfully! You can now log in.',
461
+ };
462
+ } catch (error) {
463
+ return {
464
+ type: 'error',
465
+ message: `❌ Registration failed: ${error.message}`,
466
+ };
467
+ }
468
+ },
469
+ });
470
+ }, [assistant]);
471
+
472
+ return <div>{user ? `Welcome ${user.email}` : 'No user'}</div>;
473
+ }
474
+ ```
475
+
476
+ ---
477
+
478
+ ## πŸ“ TypeScript Support
479
+
480
+ ### Full Type Definitions
481
+
482
+ ```tsx
483
+ import { AssistantCommand, InteractiveResponse } from '@foisit/core';
484
+
485
+ // Type-safe command definition
486
+ const myCommand: AssistantCommand = {
487
+ command: 'update settings',
488
+ description: 'Update user preferences',
489
+ parameters: [
490
+ {
491
+ name: 'theme',
492
+ type: 'select',
493
+ required: true,
494
+ options: [
495
+ { label: 'Light', value: 'light' },
496
+ { label: 'Dark', value: 'dark' },
497
+ ],
498
+ },
499
+ ],
500
+ action: async (params: { theme: string }): Promise<InteractiveResponse> => {
501
+ await settingsService.update(params.theme);
502
+ return {
503
+ type: 'success',
504
+ message: `Theme updated to ${params.theme}`,
505
+ };
506
+ },
507
+ };
508
+ ```
509
+
510
+ ### Hook Types
511
+
512
+ ```tsx
513
+ import { useAssistant } from '@foisit/react-wrapper';
514
+
515
+ const assistant = useAssistant();
516
+ // assistant is typed as AssistantServiceType
517
+ ```
518
+
519
+ ---
520
+
521
+ ## 🎯 Best Practices
522
+
523
+ ### 1. Cleanup Effects
524
+
525
+ Always clean up commands when components unmount:
526
+
527
+ ```tsx
528
+ useEffect(() => {
529
+ assistant.addCommand('temp command', () => 'Done');
530
+
531
+ return () => {
532
+ assistant.removeCommand('temp command');
533
+ };
534
+ }, [assistant]);
535
+ ```
536
+
537
+ ### 2. Dependency Management
538
+
539
+ Include all dependencies in `useEffect`:
540
+
541
+ ```tsx
542
+ useEffect(() => {
543
+ assistant.addCommand('navigate', () => {
544
+ navigate('/page'); // Uses navigate from React Router
545
+ });
546
+ }, [assistant, navigate]); // βœ… Include navigate
547
+ ```
548
+
549
+ ### 3. State Updates
550
+
551
+ Use functional updates for state changes:
552
+
553
+ ```tsx
554
+ action: async () => {
555
+ setItems((prev) => [...prev, newItem]); // βœ… Functional update
556
+ return 'Item added';
557
+ };
558
+ ```
559
+
560
+ ### 4. Error Boundaries
561
+
562
+ Wrap your app with error boundaries:
563
+
564
+ ```tsx
565
+ <ErrorBoundary>
566
+ <AssistantProvider config={config}>
567
+ <App />
568
+ </AssistantProvider>
569
+ </ErrorBoundary>
570
+ ```
571
+
572
+ ---
573
+
574
+ ## πŸ§ͺ Testing
575
+
576
+ ### Unit Testing with React Testing Library
577
+
578
+ ```tsx
579
+ import { render, screen } from '@testing-library/react';
580
+ import { AssistantProvider } from '@foisit/react-wrapper';
581
+
582
+ test('renders assistant', () => {
583
+ render(
584
+ <AssistantProvider config={{ commands: [] }}>
585
+ <App />
586
+ </AssistantProvider>
587
+ );
588
+
589
+ // Test your app with assistant
590
+ });
591
+ ```
592
+
593
+ ---
594
+
595
+ ## πŸ”— Related Packages
596
+
597
+ - **[@foisit/core](../core)** - Core engine (auto-installed)
598
+ - **[@foisit/angular-wrapper](../angular-wrapper)** - Angular integration
599
+ - **[@foisit/vue-wrapper](../vue-wrapper)** - Vue integration
600
+
601
+ ---
602
+
603
+ ## πŸ› Troubleshooting
604
+
605
+ ### Hook error: "useAssistant must be used within AssistantProvider"
606
+
607
+ Make sure your component is wrapped with `<AssistantProvider>`.
608
+
609
+ ### Commands not executing
610
+
611
+ Check browser console for errors. Ensure `action` functions are returning values or promises.
612
+
613
+ ### TypeScript errors
614
+
615
+ Make sure you're using React 18+ and have proper type definitions.
616
+
617
+ ---
618
+
619
+ ## πŸ“„ License
620
+
621
+ MIT Β© [Foisit](https://github.com/boluwatifee4/foisit)
622
+
623
+ ---
624
+
625
+ ## 🀝 Contributing
626
+
627
+ Contributions are welcome! Please read our [Contributing Guide](../../CONTRIBUTING.md) first.
628
+
629
+ ---
630
+
631
+ ## πŸ“¬ Support
632
+
633
+ - πŸ“§ Email: support@foisit.com
634
+ - πŸ’¬ Discord: [Join our community](https://discord.gg/foisit)
635
+ - πŸ› Issues: [GitHub Issues](https://github.com/boluwatifee4/foisit/issues)
636
+
637
+ ---
638
+
639
+ **Made with ❀️ by the Foisit Team**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foisit/react-wrapper",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "main": "./index.js",
5
5
  "types": "./index.d.ts",
6
6
  "exports": {