ai-site-pilot 0.2.0 → 0.2.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 (3) hide show
  1. package/CLAUDE.md +486 -0
  2. package/README.md +10 -1
  3. package/package.json +3 -2
package/CLAUDE.md ADDED
@@ -0,0 +1,486 @@
1
+ # AI Instructions for ai-site-pilot
2
+
3
+ This file provides instructions for AI coding assistants (Claude, GPT, Copilot, etc.) on how to integrate ai-site-pilot into projects.
4
+
5
+ ## What is ai-site-pilot?
6
+
7
+ A drop-in AI chat widget that can **control and navigate websites**. It's not just a chatbot - the AI can execute tools to filter content, open modals, navigate sections, and more.
8
+
9
+ ## ⚠️ IMPORTANT: How the AI Learns Your Site
10
+
11
+ The package provides chat UI and streaming. **The AI doesn't automatically know your site structure.** You must:
12
+
13
+ 1. **Tell it what exists** - In the system prompt, list your sections, data, categories
14
+ 2. **Define tools** - Create tools that match your site's DOM and state
15
+ 3. **Write handlers** - Client-side code that executes the actual actions
16
+
17
+ ### Example: Teaching the AI About Your Site
18
+
19
+ ```typescript
20
+ // In your API route - this is the MOST IMPORTANT part
21
+ const SYSTEM_PROMPT = `You are an AI assistant for MyStore.
22
+
23
+ ## SITE STRUCTURE
24
+ The page has these sections (use navigate_to_section tool):
25
+ - hero: Top of page with tagline
26
+ - products: Product grid (id="products")
27
+ - about: About us section (id="about")
28
+ - contact: Contact form (id="contact")
29
+
30
+ ## AVAILABLE DATA
31
+ Products on this site:
32
+ - Electronics: laptops, phones, tablets
33
+ - Clothing: shirts, pants, shoes
34
+ - Home: furniture, decor, kitchen
35
+
36
+ Categories for filtering: electronics, clothing, home, all
37
+
38
+ ## YOUR TOOLS
39
+ - navigate_to_section: Scroll to a section by ID
40
+ - filter_products: Filter the product grid by category
41
+ - open_product_modal: Show details for a specific product (use product slug)
42
+ - open_contact: Open the contact modal
43
+
44
+ ## BEHAVIOR
45
+ - When users ask about products, use filter_products to show relevant category
46
+ - When users want details, use open_product_modal
47
+ - When users want to buy/contact, use open_contact
48
+ - Always be helpful and proactively use tools to show relevant content`;
49
+ ```
50
+
51
+ The system prompt teaches the AI:
52
+ - What sections exist and their IDs
53
+ - What data/content is available
54
+ - What tools it can use and when
55
+ - How to behave (proactively use tools)
56
+
57
+ ## Quick Setup (Copy-Paste Ready)
58
+
59
+ ### 1. Install the package
60
+
61
+ ```bash
62
+ npm install ai-site-pilot
63
+ ```
64
+
65
+ ### 2. Create the API route
66
+
67
+ Create `app/api/chat/route.ts` (Next.js App Router):
68
+
69
+ ```typescript
70
+ import { streamText } from 'ai';
71
+ import { google } from '@ai-sdk/google';
72
+ // Or use any Vercel AI SDK provider:
73
+ // import { openai } from '@ai-sdk/openai';
74
+ // import { anthropic } from '@ai-sdk/anthropic';
75
+
76
+ const SYSTEM_PROMPT = `You are a helpful AI assistant for this website. You can help users navigate and find information.
77
+
78
+ ## YOUR CAPABILITIES
79
+ You have access to tools that control the website:
80
+ - navigate_to_section: Scroll to different sections
81
+ - open_modal: Open detail modals
82
+ - filter_content: Filter displayed content
83
+ - search: Search the site
84
+
85
+ Use these tools proactively when relevant to the user's request.`;
86
+
87
+ export async function POST(req: Request) {
88
+ const { messages } = await req.json();
89
+
90
+ const result = streamText({
91
+ model: google('gemini-2.0-flash'),
92
+ system: SYSTEM_PROMPT,
93
+ messages,
94
+ tools: {
95
+ // Define your site-specific tools here
96
+ navigate_to_section: {
97
+ description: 'Scroll to a section of the page',
98
+ parameters: {
99
+ type: 'object',
100
+ properties: {
101
+ section: { type: 'string', enum: ['hero', 'features', 'pricing', 'contact'] }
102
+ },
103
+ required: ['section']
104
+ }
105
+ },
106
+ // Add more tools as needed
107
+ },
108
+ });
109
+
110
+ return result.toDataStreamResponse();
111
+ }
112
+ ```
113
+
114
+ ### 3. Add the chat widget
115
+
116
+ In your layout or page component:
117
+
118
+ ```tsx
119
+ 'use client';
120
+
121
+ import { SitePilot } from 'ai-site-pilot';
122
+ import 'ai-site-pilot/styles.css';
123
+
124
+ export function ChatWidget() {
125
+ const handleToolCall = (name: string, args: Record<string, unknown>) => {
126
+ // Handle tool execution - this runs on the client
127
+ switch (name) {
128
+ case 'navigate_to_section':
129
+ document.getElementById(args.section as string)?.scrollIntoView({ behavior: 'smooth' });
130
+ break;
131
+ case 'open_modal':
132
+ // Your modal logic
133
+ break;
134
+ // Handle other tools
135
+ }
136
+ };
137
+
138
+ return (
139
+ <SitePilot
140
+ apiEndpoint="/api/chat"
141
+ onToolCall={handleToolCall}
142
+ suggestions={[
143
+ { text: 'Show me features', icon: '✨' },
144
+ { text: 'How does pricing work?', icon: '💰' },
145
+ { text: 'Contact sales', icon: '📞' },
146
+ ]}
147
+ welcomeMessage="Hi! I can help you explore this site. What would you like to know?"
148
+ theme={{
149
+ accentColor: '#3b82f6', // Your brand color
150
+ backgroundColor: '#0f172a', // Dark background
151
+ // See full theme options below
152
+ }}
153
+ />
154
+ );
155
+ }
156
+ ```
157
+
158
+ ## Theme Customization
159
+
160
+ All colors accept any CSS color value (hex, rgb, hsl, etc.):
161
+
162
+ ```tsx
163
+ <SitePilot
164
+ theme={{
165
+ // Position
166
+ position: 'bottom-right', // 'bottom-left', 'top-right', 'top-left'
167
+ borderRadius: 24, // pixels
168
+
169
+ // Colors
170
+ accentColor: '#f59e0b', // Primary accent (buttons, highlights)
171
+ accentColorDark: '#d97706', // Gradient end color
172
+ backgroundColor: '#0F0720', // Panel background
173
+ textColor: '#ffffff', // Primary text
174
+ textMutedColor: '#a1a1aa', // Secondary text
175
+ borderColor: 'rgba(255,255,255,0.1)',
176
+
177
+ // Message bubbles
178
+ userMessageBg: 'linear-gradient(135deg, #f59e0b, #d97706)',
179
+ assistantMessageBg: 'rgba(255,255,255,0.05)',
180
+ }}
181
+ />
182
+ ```
183
+
184
+ ## Feature Toggles
185
+
186
+ ```tsx
187
+ <SitePilot
188
+ features={{
189
+ speech: true, // Voice input (microphone)
190
+ tts: true, // Text-to-speech for responses
191
+ fullscreen: true, // Fullscreen toggle button
192
+ suggestions: true, // Show suggestion chips
193
+ }}
194
+ />
195
+ ```
196
+
197
+ ## Tool System
198
+
199
+ Define tools that the AI can call to control your site:
200
+
201
+ ```typescript
202
+ // Using the defineTool helper (optional, for type safety)
203
+ import { defineTool } from 'ai-site-pilot/tools';
204
+
205
+ const filterProductsTool = defineTool({
206
+ name: 'filter_products',
207
+ description: 'Filter products by category',
208
+ parameters: {
209
+ type: 'object',
210
+ properties: {
211
+ category: {
212
+ type: 'string',
213
+ description: 'Product category',
214
+ enum: ['electronics', 'clothing', 'home', 'all']
215
+ }
216
+ },
217
+ required: ['category']
218
+ }
219
+ });
220
+ ```
221
+
222
+ ## Environment Variables
223
+
224
+ For the API route, you'll need your AI provider's API key:
225
+
226
+ ```env
227
+ # For Google Gemini
228
+ GOOGLE_GENERATIVE_AI_API_KEY=your-key-here
229
+
230
+ # Or for OpenAI
231
+ OPENAI_API_KEY=your-key-here
232
+
233
+ # Or for Anthropic
234
+ ANTHROPIC_API_KEY=your-key-here
235
+ ```
236
+
237
+ ## Complete Real-World Example
238
+
239
+ Here's a full implementation for a portfolio site showing all three parts:
240
+
241
+ ### Part 1: System Prompt (teaches the AI what exists)
242
+
243
+ ```typescript
244
+ // app/api/chat/route.ts
245
+ const PROJECTS = `
246
+ Available projects (use open_project_modal with these IDs):
247
+ - acme-dashboard: Acme Dashboard (SaaS, Live) - Analytics platform
248
+ - mobile-app: FitTrack (Mobile, Live) - Fitness tracking app
249
+ - ecommerce: ShopFlow (E-commerce, In Progress) - Online store template
250
+ - api-service: DataSync API (Backend, Live) - Data synchronization service
251
+
252
+ Categories: All, SaaS, Mobile, E-commerce, Backend
253
+ Statuses: Live, In Progress, Concept
254
+ `;
255
+
256
+ const SYSTEM_PROMPT = `You are a portfolio assistant for Jane Developer.
257
+
258
+ ## SITE SECTIONS
259
+ - hero: Landing section with intro (id="hero")
260
+ - projects: Project showcase grid (id="projects")
261
+ - about: About section (id="about")
262
+ - contact: Contact form (id="contact")
263
+
264
+ ## PROJECT DATA
265
+ ${PROJECTS}
266
+
267
+ ## YOUR TOOLS
268
+ - navigate_to_section: Scroll to hero, projects, about, or contact
269
+ - filter_by_category: Filter projects (SaaS, Mobile, E-commerce, Backend, All)
270
+ - filter_by_status: Filter by status (Live, In Progress, Concept)
271
+ - open_project_modal: Open project details (use project ID like "acme-dashboard")
272
+ - highlight_project: Pulse animation on a project card
273
+ - open_contact: Open contact/hire modal
274
+
275
+ ## WHEN TO USE TOOLS
276
+ - "Show me your work" → navigate_to_section("projects")
277
+ - "Any mobile apps?" → filter_by_category("Mobile")
278
+ - "What's live?" → filter_by_status("Live")
279
+ - "Tell me about Acme" → open_project_modal("acme-dashboard")
280
+ - "I want to hire you" → open_contact()
281
+
282
+ Be conversational but proactively use tools to make the site interactive.`;
283
+ ```
284
+
285
+ ### Part 2: Tool Definitions (what the AI can call)
286
+
287
+ ```typescript
288
+ // app/api/chat/route.ts (continued)
289
+ export async function POST(req: Request) {
290
+ const { messages } = await req.json();
291
+
292
+ const result = streamText({
293
+ model: google('gemini-2.0-flash'),
294
+ system: SYSTEM_PROMPT,
295
+ messages,
296
+ tools: {
297
+ navigate_to_section: {
298
+ description: 'Scroll to a page section',
299
+ parameters: {
300
+ type: 'object',
301
+ properties: {
302
+ section: { type: 'string', enum: ['hero', 'projects', 'about', 'contact'] }
303
+ },
304
+ required: ['section']
305
+ }
306
+ },
307
+ filter_by_category: {
308
+ description: 'Filter projects by category',
309
+ parameters: {
310
+ type: 'object',
311
+ properties: {
312
+ category: { type: 'string', enum: ['All', 'SaaS', 'Mobile', 'E-commerce', 'Backend'] }
313
+ },
314
+ required: ['category']
315
+ }
316
+ },
317
+ open_project_modal: {
318
+ description: 'Open project detail modal',
319
+ parameters: {
320
+ type: 'object',
321
+ properties: {
322
+ projectId: { type: 'string', description: 'Project ID like acme-dashboard' }
323
+ },
324
+ required: ['projectId']
325
+ }
326
+ },
327
+ open_contact: {
328
+ description: 'Open the contact/hire modal',
329
+ parameters: { type: 'object', properties: {}, required: [] }
330
+ }
331
+ },
332
+ });
333
+
334
+ return result.toDataStreamResponse();
335
+ }
336
+ ```
337
+
338
+ ### Part 3: Client Handler (executes the actions)
339
+
340
+ ```tsx
341
+ // components/ChatWidget.tsx
342
+ 'use client';
343
+
344
+ import { SitePilot } from 'ai-site-pilot';
345
+ import 'ai-site-pilot/styles.css';
346
+
347
+ export function ChatWidget() {
348
+ const handleToolCall = (name: string, args: Record<string, unknown>) => {
349
+ switch (name) {
350
+ case 'navigate_to_section':
351
+ document.getElementById(args.section as string)?.scrollIntoView({
352
+ behavior: 'smooth'
353
+ });
354
+ break;
355
+
356
+ case 'filter_by_category':
357
+ // Dispatch custom event for your page to handle
358
+ window.dispatchEvent(new CustomEvent('filter-projects', {
359
+ detail: { category: args.category }
360
+ }));
361
+ break;
362
+
363
+ case 'open_project_modal':
364
+ window.dispatchEvent(new CustomEvent('open-project', {
365
+ detail: { projectId: args.projectId }
366
+ }));
367
+ break;
368
+
369
+ case 'open_contact':
370
+ window.dispatchEvent(new CustomEvent('open-contact'));
371
+ break;
372
+ }
373
+ };
374
+
375
+ return (
376
+ <SitePilot
377
+ apiEndpoint="/api/chat"
378
+ onToolCall={handleToolCall}
379
+ suggestions={[
380
+ { text: "Show me your work", icon: "💼" },
381
+ { text: "What's live?", icon: "🚀" },
382
+ { text: "I want to hire you", icon: "💡" },
383
+ ]}
384
+ theme={{
385
+ accentColor: '#8b5cf6',
386
+ backgroundColor: '#0f0f23',
387
+ }}
388
+ />
389
+ );
390
+ }
391
+ ```
392
+
393
+ ### Part 4: Page Listens for Events
394
+
395
+ ```tsx
396
+ // app/page.tsx or components/HomePage.tsx
397
+ 'use client';
398
+
399
+ import { useEffect, useState } from 'react';
400
+
401
+ export function HomePage() {
402
+ const [filter, setFilter] = useState('All');
403
+ const [selectedProject, setSelectedProject] = useState(null);
404
+ const [showContact, setShowContact] = useState(false);
405
+
406
+ useEffect(() => {
407
+ const handleFilter = (e: CustomEvent) => setFilter(e.detail.category);
408
+ const handleProject = (e: CustomEvent) => setSelectedProject(e.detail.projectId);
409
+ const handleContact = () => setShowContact(true);
410
+
411
+ window.addEventListener('filter-projects', handleFilter as EventListener);
412
+ window.addEventListener('open-project', handleProject as EventListener);
413
+ window.addEventListener('open-contact', handleContact);
414
+
415
+ return () => {
416
+ window.removeEventListener('filter-projects', handleFilter as EventListener);
417
+ window.removeEventListener('open-project', handleProject as EventListener);
418
+ window.removeEventListener('open-contact', handleContact);
419
+ };
420
+ }, []);
421
+
422
+ // Your page components use filter, selectedProject, showContact state...
423
+ }
424
+ ```
425
+
426
+ ## Common Patterns
427
+
428
+ ### E-commerce Site
429
+ ```tsx
430
+ const tools = {
431
+ search_products: { /* search inventory */ },
432
+ filter_by_category: { /* filter product grid */ },
433
+ add_to_cart: { /* add item to cart */ },
434
+ open_product: { /* show product details */ },
435
+ };
436
+ ```
437
+
438
+ ### Documentation Site
439
+ ```tsx
440
+ const tools = {
441
+ search_docs: { /* search documentation */ },
442
+ navigate_to_page: { /* go to specific doc page */ },
443
+ show_code_example: { /* display code snippet */ },
444
+ };
445
+ ```
446
+
447
+ ### Portfolio Site
448
+ ```tsx
449
+ const tools = {
450
+ filter_projects: { /* filter by category/status */ },
451
+ open_project_modal: { /* show project details */ },
452
+ navigate_to_section: { /* scroll to section */ },
453
+ open_contact: { /* open contact form */ },
454
+ };
455
+ ```
456
+
457
+ ## Troubleshooting
458
+
459
+ **Chat not appearing?**
460
+ - Make sure you imported the CSS: `import 'ai-site-pilot/styles.css'`
461
+ - Check that the component is rendered (use React DevTools)
462
+
463
+ **Tools not executing?**
464
+ - Verify `onToolCall` is passed to SitePilot
465
+ - Check browser console for the tool calls
466
+ - Make sure tool names match between API and client
467
+
468
+ **Styling issues?**
469
+ - CSS variables can be overridden in your global CSS
470
+ - The component uses `z-index: 200` - adjust if needed
471
+
472
+ ## Full Props Reference
473
+
474
+ ```typescript
475
+ interface SitePilotProps {
476
+ apiEndpoint: string; // Required: Your chat API endpoint
477
+ theme?: SitePilotTheme; // Theme customization
478
+ suggestions?: Suggestion[]; // Suggestion chips
479
+ features?: SitePilotFeatures; // Feature toggles
480
+ onToolCall?: (name: string, args: Record<string, unknown>) => void;
481
+ defaultOpen?: boolean; // Start with chat open
482
+ placeholder?: string; // Input placeholder
483
+ welcomeMessage?: string; // Initial greeting
484
+ className?: string; // Additional CSS class
485
+ }
486
+ ```
package/README.md CHANGED
@@ -101,9 +101,18 @@ Main chat widget component.
101
101
 
102
102
  ```typescript
103
103
  interface SitePilotTheme {
104
- accent?: string; // 'amber', 'blue', or CSS color
105
104
  position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
106
105
  borderRadius?: number;
106
+
107
+ // Colors - all accept CSS color values (hex, rgb, hsl)
108
+ accentColor?: string; // Primary accent '#f59e0b'
109
+ accentColorDark?: string; // Gradient end '#d97706'
110
+ backgroundColor?: string; // Panel background '#0F0720'
111
+ textColor?: string; // Primary text '#ffffff'
112
+ textMutedColor?: string; // Secondary text '#a1a1aa'
113
+ borderColor?: string; // Border 'rgba(255,255,255,0.1)'
114
+ userMessageBg?: string; // User message bubble
115
+ assistantMessageBg?: string; // Assistant message bubble
107
116
  }
108
117
  ```
109
118
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-site-pilot",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "AI chat widget that can control and navigate your website. Full-stack solution with streaming, tool system, and polished UI.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -30,7 +30,8 @@
30
30
  },
31
31
  "files": [
32
32
  "dist",
33
- "README.md"
33
+ "README.md",
34
+ "CLAUDE.md"
34
35
  ],
35
36
  "scripts": {
36
37
  "build": "tsup && cp src/styles.css dist/styles.css",