@foisit/react-wrapper 2.0.1 β 2.1.2
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 +571 -29
- package/index.d.ts +6 -0
- package/index.js +412 -0
- package/index.mjs +1084 -0
- package/lib/components/AssistantActivator.d.ts +8 -0
- package/lib/components/AssistantProvider.d.ts +9 -0
- package/lib/hooks/useAssistant.d.ts +3 -0
- package/lib/hooks/useAssistantState.d.ts +3 -0
- package/lib/react-wrapper.d.ts +2 -0
- package/lib/services/AssistantService.d.ts +39 -0
- package/lib/types/index.d.ts +0 -0
- package/lib/utils/index.d.ts +0 -0
- package/package.json +6 -2
- package/style.css +0 -0
package/README.md
CHANGED
|
@@ -1,9 +1,41 @@
|
|
|
1
1
|
# @foisit/react-wrapper
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@foisit/react-wrapper)
|
|
4
|
+
[](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.
|
|
4
9
|
|
|
5
10
|
> [!NOTE]
|
|
6
|
-
> ποΈ **
|
|
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
|
|
7
39
|
|
|
8
40
|
---
|
|
9
41
|
|
|
@@ -13,22 +45,35 @@ Power your React apps with an AI-driven text assistant.
|
|
|
13
45
|
npm install @foisit/react-wrapper
|
|
14
46
|
```
|
|
15
47
|
|
|
48
|
+
### Peer Dependencies
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"react": "^18.0.0",
|
|
53
|
+
"react-dom": "^18.0.0"
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
16
57
|
---
|
|
17
58
|
|
|
18
|
-
##
|
|
59
|
+
## π Quick Start
|
|
19
60
|
|
|
20
|
-
|
|
61
|
+
### Step 1: Wrap Your App
|
|
21
62
|
|
|
22
63
|
```tsx
|
|
64
|
+
import React from 'react';
|
|
23
65
|
import { AssistantProvider } from '@foisit/react-wrapper';
|
|
24
66
|
|
|
25
67
|
const config = {
|
|
26
|
-
introMessage: '
|
|
68
|
+
introMessage: 'Welcome! How can I assist you today?',
|
|
27
69
|
enableSmartIntent: true,
|
|
28
70
|
commands: [
|
|
29
71
|
{
|
|
30
|
-
command: '
|
|
31
|
-
action: () =>
|
|
72
|
+
command: 'navigate to profile',
|
|
73
|
+
action: () => {
|
|
74
|
+
window.location.href = '/profile';
|
|
75
|
+
return 'Navigating to profile...';
|
|
76
|
+
},
|
|
32
77
|
},
|
|
33
78
|
],
|
|
34
79
|
};
|
|
@@ -40,58 +85,555 @@ function App() {
|
|
|
40
85
|
</AssistantProvider>
|
|
41
86
|
);
|
|
42
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
|
+
}
|
|
43
103
|
```
|
|
44
104
|
|
|
45
105
|
---
|
|
46
106
|
|
|
47
|
-
##
|
|
107
|
+
## π― Core Concepts
|
|
108
|
+
|
|
109
|
+
### 1. Commands
|
|
48
110
|
|
|
49
|
-
Commands
|
|
111
|
+
Commands are the building blocks of your assistant. Each command represents an action users can trigger through natural language.
|
|
50
112
|
|
|
51
113
|
```tsx
|
|
52
|
-
|
|
53
|
-
|
|
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: [
|
|
54
246
|
{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
247
|
+
name: 'format',
|
|
248
|
+
type: 'select',
|
|
249
|
+
options: [
|
|
250
|
+
{ label: 'PDF', value: 'pdf' },
|
|
251
|
+
{ label: 'Excel', value: 'xlsx' },
|
|
252
|
+
],
|
|
59
253
|
},
|
|
60
254
|
],
|
|
61
|
-
|
|
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);
|
|
62
277
|
```
|
|
63
278
|
|
|
64
279
|
---
|
|
65
280
|
|
|
66
|
-
##
|
|
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;
|
|
67
292
|
|
|
68
|
-
|
|
293
|
+
// Response for unrecognized inputs
|
|
294
|
+
fallbackResponse?: string;
|
|
69
295
|
|
|
70
|
-
|
|
71
|
-
|
|
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
|
+
```
|
|
72
314
|
|
|
73
315
|
---
|
|
74
316
|
|
|
75
|
-
##
|
|
317
|
+
## π¨ Advanced Usage
|
|
76
318
|
|
|
77
|
-
|
|
319
|
+
### Example 1: Multi-Step Booking System with State
|
|
78
320
|
|
|
79
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';
|
|
80
385
|
import { useAssistant } from '@foisit/react-wrapper';
|
|
81
386
|
|
|
82
|
-
function
|
|
387
|
+
function ProductSearch() {
|
|
388
|
+
const navigate = useNavigate();
|
|
83
389
|
const assistant = useAssistant();
|
|
84
390
|
|
|
85
|
-
|
|
86
|
-
assistant.addCommand(
|
|
87
|
-
|
|
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]);
|
|
88
415
|
|
|
89
|
-
return <
|
|
416
|
+
return <div>Search component</div>;
|
|
90
417
|
}
|
|
91
418
|
```
|
|
92
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
|
+
|
|
93
593
|
---
|
|
94
594
|
|
|
95
|
-
##
|
|
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
|
+
---
|
|
96
638
|
|
|
97
|
-
|
|
639
|
+
**Made with β€οΈ by the Foisit Team**
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './lib/react-wrapper';
|
|
2
|
+
export * from './lib/components/AssistantProvider';
|
|
3
|
+
export * from './lib/components/AssistantActivator';
|
|
4
|
+
export * from './lib/hooks/useAssistant';
|
|
5
|
+
export * from './lib/hooks/useAssistantState';
|
|
6
|
+
export * from './lib/services/AssistantService';
|