@aiassist-secure/vanilla 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.
package/LICENSE ADDED
@@ -0,0 +1,40 @@
1
+ AiAssist Commercial Use License
2
+
3
+ Copyright (c) 2025 AiAssist. All rights reserved.
4
+
5
+ TERMS AND CONDITIONS
6
+
7
+ 1. PERMITTED USE
8
+ You are granted a non-exclusive, non-transferable license to:
9
+ - Use this software for personal or commercial purposes
10
+ - Integrate this software into your own applications and products
11
+ - Modify this software for your own use
12
+
13
+ 2. RESTRICTIONS
14
+ You may NOT:
15
+ - Sell, sublicense, or distribute this software as a standalone product
16
+ - Reproduce, copy, or redistribute this software for profit
17
+ - Offer this software as a service to third parties without prior written permission
18
+ - Remove or alter any copyright notices or this license
19
+
20
+ 3. REDISTRIBUTION
21
+ If you distribute applications or products that incorporate this software,
22
+ you must include this license file and the following attribution:
23
+ "Powered by AiAssist - https://aiassist.net" unless you are a subscriber,
24
+ then the attribution is not required
25
+
26
+ 4. COMMERCIAL RESALE
27
+ Commercial resale, white-labeling, or redistribution of this software
28
+ requires a separate commercial license agreement. Contact the copyright
29
+ holder for licensing inquiries.
30
+
31
+ 5. NO WARRANTY
32
+ THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
35
+
36
+ 6. LIMITATION OF LIABILITY
37
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM,
38
+ DAMAGES OR OTHER LIABILITY ARISING FROM THE USE OF THIS SOFTWARE.
39
+
40
+ For licensing inquiries: dev@interchained.org
package/README.md ADDED
@@ -0,0 +1,416 @@
1
+ # @aiassist-secure/vanilla
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@aiassist-secure/vanilla.svg)](https://www.npmjs.com/package/@aiassist-secure/vanilla)
4
+ [![CDN](https://img.shields.io/badge/CDN-Available-success.svg)](https://cdn.aiassist.net/widget.js)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
6
+ [![Bundle Size](https://img.shields.io/badge/minified-35KB-blue.svg)]()
7
+
8
+ **Drop-in AI chat widget for any website** - No framework required. Add enterprise AI support to any site with a single script tag.
9
+
10
+ Works with **WordPress, Shopify, Squarespace, Webflow, static HTML**, and more.
11
+
12
+ ---
13
+
14
+ ## Features
15
+
16
+ - **Zero Dependencies** - Single script, no build step required
17
+ - **Shadow DOM** - Styles isolated from your site
18
+ - **Shadow Mode** - AI drafts require human approval
19
+ - **Human Handoff** - Seamless AI-to-human transition
20
+ - **Lead Capture** - Collect emails before chat starts
21
+ - **Dark/Light Themes** - Built-in theme support
22
+ - **TypeScript** - Full type definitions included
23
+ - **CDN + npm** - Use via CDN or install via npm
24
+
25
+ ---
26
+
27
+ ## Quick Start (CDN)
28
+
29
+ Add two lines to your HTML:
30
+
31
+ ```html
32
+ <script src="https://cdn.aiassist.net/widget.js"></script>
33
+ <script>
34
+ AiAssist.init({
35
+ apiKey: 'your-api-key'
36
+ });
37
+ </script>
38
+ ```
39
+
40
+ **That's it!** A chat bubble appears in the bottom-right corner.
41
+
42
+ ---
43
+
44
+ ## Installation via npm
45
+
46
+ ```bash
47
+ npm install @aiassist-secure/vanilla
48
+ ```
49
+
50
+ ```javascript
51
+ import AiAssist from '@aiassist-secure/vanilla';
52
+
53
+ AiAssist.init({
54
+ apiKey: 'your-api-key',
55
+ position: 'bottom-right'
56
+ });
57
+ ```
58
+
59
+ ---
60
+
61
+ ## Full Example
62
+
63
+ ```html
64
+ <!DOCTYPE html>
65
+ <html lang="en">
66
+ <head>
67
+ <meta charset="UTF-8">
68
+ <title>My Website</title>
69
+ </head>
70
+ <body>
71
+ <h1>Welcome to My Site</h1>
72
+ <p>We're here to help 24/7</p>
73
+
74
+ <!-- AiAssist Chat Widget -->
75
+ <script src="https://cdn.aiassist.net/widget.js"></script>
76
+ <script>
77
+ AiAssist.init({
78
+ apiKey: 'your-api-key',
79
+
80
+ // Branding
81
+ title: 'Acme Support',
82
+ subtitle: 'We typically reply in minutes',
83
+ greeting: 'Hi there! How can I help you today?',
84
+
85
+ // Behavior
86
+ position: 'bottom-right',
87
+ theme: 'dark',
88
+ autoOpen: false,
89
+ requireEmail: true,
90
+
91
+ // AI Configuration
92
+ systemPrompt: 'You are a friendly support agent for Acme Inc. Be helpful, concise, and professional.',
93
+
94
+ // Callbacks
95
+ onReady: () => console.log('Chat widget loaded'),
96
+ onMessage: (msg) => console.log('New message:', msg),
97
+ onLeadCapture: (lead) => {
98
+ // Send to your CRM
99
+ fetch('/api/leads', {
100
+ method: 'POST',
101
+ body: JSON.stringify(lead)
102
+ });
103
+ }
104
+ });
105
+ </script>
106
+ </body>
107
+ </html>
108
+ ```
109
+
110
+ ---
111
+
112
+ ## Shadow Mode (Enterprise)
113
+
114
+ AI drafts are reviewed by a human before being sent:
115
+
116
+ ```javascript
117
+ AiAssist.init({
118
+ apiKey: 'your-api-key',
119
+
120
+ onMessage: (message) => {
121
+ // Check if message is pending approval
122
+ if (message.pending_approval) {
123
+ console.log('AI draft awaiting supervisor approval');
124
+ // The message shows a "pending" indicator in the UI
125
+ }
126
+ },
127
+
128
+ onModeChange: (mode) => {
129
+ switch (mode) {
130
+ case 'ai':
131
+ console.log('AI is responding');
132
+ break;
133
+ case 'shadow':
134
+ console.log('AI drafts being supervised');
135
+ break;
136
+ case 'takeover':
137
+ console.log('Human agent has taken over');
138
+ // Widget automatically shows "Speaking with Agent"
139
+ break;
140
+ }
141
+ }
142
+ });
143
+ ```
144
+
145
+ ---
146
+
147
+ ## Human-in-the-Loop
148
+
149
+ Detect when a human agent joins the conversation:
150
+
151
+ ```javascript
152
+ AiAssist.init({
153
+ apiKey: 'your-api-key',
154
+
155
+ onModeChange: (mode) => {
156
+ if (mode === 'takeover') {
157
+ // Update your page to show human support is active
158
+ document.getElementById('support-status').textContent =
159
+ 'You are now speaking with a human agent';
160
+ }
161
+ }
162
+ });
163
+ ```
164
+
165
+ ---
166
+
167
+ ## Lead Capture
168
+
169
+ Collect customer emails before starting the chat:
170
+
171
+ ```javascript
172
+ AiAssist.init({
173
+ apiKey: 'your-api-key',
174
+ requireEmail: true, // Show email form first
175
+
176
+ onLeadCapture: (lead) => {
177
+ console.log('Captured lead:', lead.email);
178
+
179
+ // Send to your CRM, email service, or database
180
+ fetch('https://your-api.com/leads', {
181
+ method: 'POST',
182
+ headers: { 'Content-Type': 'application/json' },
183
+ body: JSON.stringify({
184
+ email: lead.email,
185
+ source: 'chat_widget',
186
+ timestamp: new Date().toISOString()
187
+ })
188
+ });
189
+ }
190
+ });
191
+ ```
192
+
193
+ ---
194
+
195
+ ## Programmatic Control
196
+
197
+ Control the widget from your JavaScript:
198
+
199
+ ```javascript
200
+ // Get widget instance
201
+ const widget = AiAssist.getInstance();
202
+
203
+ // Open/close/toggle the chat
204
+ widget.open();
205
+ widget.close();
206
+ widget.toggle();
207
+
208
+ // Send a message programmatically
209
+ await widget.send('I need help with my order #12345');
210
+
211
+ // Get current conversation info
212
+ const workspaceId = widget.getWorkspaceId();
213
+ const messages = widget.getMessages();
214
+ const isOpen = widget.isOpen();
215
+
216
+ // End the conversation
217
+ await widget.endConversation();
218
+
219
+ // Destroy the widget completely
220
+ AiAssist.destroy();
221
+ ```
222
+
223
+ ---
224
+
225
+ ## DOM Events
226
+
227
+ Listen for widget events on the document:
228
+
229
+ ```javascript
230
+ // Widget fully loaded and ready
231
+ document.addEventListener('aiassist:ready', () => {
232
+ console.log('Widget initialized');
233
+ });
234
+
235
+ // Chat window opened
236
+ document.addEventListener('aiassist:open', () => {
237
+ console.log('User opened chat');
238
+ analytics.track('chat_opened');
239
+ });
240
+
241
+ // Chat window closed
242
+ document.addEventListener('aiassist:close', () => {
243
+ console.log('User closed chat');
244
+ });
245
+
246
+ // New message received
247
+ document.addEventListener('aiassist:message', (e) => {
248
+ const message = e.detail;
249
+ console.log(`${message.role}: ${message.content}`);
250
+
251
+ if (message.pending_approval) {
252
+ console.log('Message pending approval');
253
+ }
254
+ });
255
+
256
+ // Mode changed (AI/Shadow/Human)
257
+ document.addEventListener('aiassist:mode:change', (e) => {
258
+ console.log('Mode changed to:', e.detail.mode);
259
+ });
260
+
261
+ // Lead captured
262
+ document.addEventListener('aiassist:lead:capture', (e) => {
263
+ console.log('Lead email:', e.detail.email);
264
+ });
265
+
266
+ // Conversation ended
267
+ document.addEventListener('aiassist:conversation:end', () => {
268
+ console.log('Conversation ended');
269
+ });
270
+ ```
271
+
272
+ ---
273
+
274
+ ## Configuration Reference
275
+
276
+ ```javascript
277
+ AiAssist.init({
278
+ // Required
279
+ apiKey: 'your-api-key',
280
+
281
+ // API Settings
282
+ endpoint: 'https://api.aiassist.net', // Custom endpoint
283
+
284
+ // Position & Appearance
285
+ position: 'bottom-right', // bottom-right, bottom-left, top-right, top-left
286
+ theme: 'dark', // 'dark' or 'light'
287
+ zIndex: 999999, // CSS z-index
288
+
289
+ // Branding
290
+ title: 'AI Assistant', // Header title
291
+ subtitle: 'Ask me anything', // Header subtitle
292
+ placeholder: 'Type your message...', // Input placeholder
293
+ poweredBy: true, // Show "Powered by AiAssist"
294
+
295
+ // Behavior
296
+ greeting: null, // Initial greeting message
297
+ systemPrompt: null, // AI system prompt
298
+ context: {}, // Additional context object
299
+ autoOpen: false, // Auto-open on page load
300
+ autoOpenDelay: 3000, // Delay before auto-open (ms)
301
+ requireEmail: true, // Require email before chat
302
+
303
+ // Callbacks
304
+ onReady: () => {}, // Widget initialized
305
+ onOpen: () => {}, // Chat opened
306
+ onClose: () => {}, // Chat closed
307
+ onMessage: (message) => {}, // New message
308
+ onError: (error) => {}, // Error occurred
309
+ onConversationStart: (workspaceId) => {}, // Conversation started
310
+ onConversationEnd: () => {}, // Conversation ended
311
+ onModeChange: (mode) => {}, // Mode changed (ai/shadow/takeover)
312
+ onLeadCapture: (lead) => {} // Email captured
313
+ });
314
+ ```
315
+
316
+ ---
317
+
318
+ ## WordPress Integration
319
+
320
+ For WordPress sites, you can add the widget via:
321
+
322
+ ### Option 1: Theme Footer
323
+
324
+ Add to your theme's `footer.php` or via **Appearance > Theme Editor**:
325
+
326
+ ```php
327
+ <script src="https://cdn.aiassist.net/widget.js"></script>
328
+ <script>
329
+ AiAssist.init({
330
+ apiKey: '<?php echo get_option("aiassist_api_key"); ?>',
331
+ title: '<?php bloginfo("name"); ?> Support'
332
+ });
333
+ </script>
334
+ ```
335
+
336
+ ### Option 2: Plugin
337
+
338
+ Use our official WordPress plugin:
339
+
340
+ 1. Download from [aiassist.net/wordpress](https://aiassist.net/wordpress)
341
+ 2. Upload to `/wp-content/plugins/`
342
+ 3. Activate and configure in **Settings > AiAssist**
343
+
344
+ ---
345
+
346
+ ## TypeScript Support
347
+
348
+ Type definitions are included:
349
+
350
+ ```typescript
351
+ import AiAssist, {
352
+ AiAssistConfig,
353
+ Message,
354
+ Mode
355
+ } from '@aiassist-secure/vanilla';
356
+
357
+ const config: AiAssistConfig = {
358
+ apiKey: 'your-api-key',
359
+ onMessage: (message: Message) => {
360
+ console.log(message.content);
361
+ if (message.pending_approval) {
362
+ console.log('Pending approval');
363
+ }
364
+ },
365
+ onModeChange: (mode: Mode) => {
366
+ console.log('Mode:', mode); // 'ai' | 'shadow' | 'takeover'
367
+ }
368
+ };
369
+
370
+ AiAssist.init(config);
371
+ ```
372
+
373
+ **CDN users:** Download type definitions from `https://cdn.aiassist.net/widget.d.ts`
374
+
375
+ ---
376
+
377
+ ## Browser Support
378
+
379
+ | Browser | Version |
380
+ |---------|---------|
381
+ | Chrome | 80+ |
382
+ | Firefox | 75+ |
383
+ | Safari | 14+ |
384
+ | Edge | 80+ |
385
+
386
+ ---
387
+
388
+ ## Related Packages
389
+
390
+ | Package | Description |
391
+ |---------|-------------|
392
+ | [@aiassist-secure/react](https://www.npmjs.com/package/@aiassist-secure/react) | React components |
393
+ | [@aiassist-secure/core](https://www.npmjs.com/package/@aiassist-secure/core) | TypeScript API client |
394
+
395
+ ---
396
+
397
+ ## Links
398
+
399
+ - [Documentation](https://aiassist.net/developer-docs/vanilla)
400
+ - [Live Demo](https://aiassist.net/demo)
401
+ - [CDN Setup Guide](https://aiassist.net/developer-docs/cdn)
402
+ - [WordPress Plugin](https://aiassist.net/wordpress)
403
+
404
+ ---
405
+
406
+ ## Support
407
+
408
+ - Documentation: [aiassist.net/docs](https://aiassist.net/docs)
409
+ - Developer Docs: [aiassist.net/developer-docs](https://aiassist.net/developer-docs)
410
+ - Email: support@aiassist.net
411
+
412
+ ---
413
+
414
+ ## License
415
+
416
+ MIT License - [Interchained LLC](https://interchained.com)
@@ -0,0 +1,66 @@
1
+ /**
2
+ * AiAssist Vanilla Widget TypeScript Definitions
3
+ */
4
+
5
+ export interface AiAssistConfig {
6
+ apiKey: string;
7
+ endpoint?: string;
8
+ position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
9
+ theme?: 'dark' | 'light';
10
+ title?: string;
11
+ subtitle?: string;
12
+ placeholder?: string;
13
+ greeting?: string;
14
+ systemPrompt?: string;
15
+ poweredBy?: boolean;
16
+ autoOpen?: boolean;
17
+ autoOpenDelay?: number;
18
+ zIndex?: number;
19
+ requireEmail?: boolean;
20
+ onReady?: () => void;
21
+ onOpen?: () => void;
22
+ onClose?: () => void;
23
+ onMessage?: (message: Message) => void;
24
+ onError?: (error: Error) => void;
25
+ onConversationStart?: (workspaceId: string) => void;
26
+ onConversationEnd?: () => void;
27
+ onModeChange?: (mode: 'ai' | 'human') => void;
28
+ onLeadCapture?: (lead: LeadInfo) => void;
29
+ }
30
+
31
+ export interface Message {
32
+ id: string;
33
+ role: 'user' | 'ai' | 'human' | 'system';
34
+ content: string;
35
+ timestamp?: string;
36
+ }
37
+
38
+ export interface LeadInfo {
39
+ leadId: string;
40
+ email: string;
41
+ }
42
+
43
+ export interface AiAssistInstance {
44
+ open(): void;
45
+ close(): void;
46
+ toggle(): void;
47
+ send(message: string): Promise<void>;
48
+ destroy(): void;
49
+ getWorkspaceId(): string | null;
50
+ getMessages(): Message[];
51
+ }
52
+
53
+ export interface AiAssist {
54
+ init(config: AiAssistConfig): AiAssistInstance;
55
+ getInstance(): AiAssistInstance | null;
56
+ destroy(): void;
57
+ }
58
+
59
+ declare global {
60
+ interface Window {
61
+ AiAssist: AiAssist;
62
+ }
63
+ }
64
+
65
+ declare const AiAssist: AiAssist;
66
+ export default AiAssist;