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