shipd 0.1.3 → 0.1.4
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/base-package/app/globals.css +126 -0
- package/base-package/app/layout.tsx +53 -0
- package/base-package/app/page.tsx +15 -0
- package/base-package/base.config.json +57 -0
- package/base-package/components/ui/avatar.tsx +53 -0
- package/base-package/components/ui/badge.tsx +46 -0
- package/base-package/components/ui/button.tsx +59 -0
- package/base-package/components/ui/card.tsx +92 -0
- package/base-package/components/ui/chart.tsx +353 -0
- package/base-package/components/ui/checkbox.tsx +32 -0
- package/base-package/components/ui/dialog.tsx +135 -0
- package/base-package/components/ui/dropdown-menu.tsx +257 -0
- package/base-package/components/ui/form.tsx +167 -0
- package/base-package/components/ui/input.tsx +21 -0
- package/base-package/components/ui/label.tsx +24 -0
- package/base-package/components/ui/progress.tsx +31 -0
- package/base-package/components/ui/resizable.tsx +56 -0
- package/base-package/components/ui/select.tsx +185 -0
- package/base-package/components/ui/separator.tsx +28 -0
- package/base-package/components/ui/sheet.tsx +139 -0
- package/base-package/components/ui/skeleton.tsx +13 -0
- package/base-package/components/ui/sonner.tsx +25 -0
- package/base-package/components/ui/switch.tsx +31 -0
- package/base-package/components/ui/tabs.tsx +66 -0
- package/base-package/components/ui/textarea.tsx +18 -0
- package/base-package/components/ui/toggle-group.tsx +73 -0
- package/base-package/components/ui/toggle.tsx +47 -0
- package/base-package/components/ui/tooltip.tsx +61 -0
- package/base-package/components.json +21 -0
- package/base-package/eslint.config.mjs +16 -0
- package/base-package/lib/utils.ts +6 -0
- package/base-package/middleware.ts +12 -0
- package/base-package/next.config.ts +27 -0
- package/base-package/package.json +49 -0
- package/base-package/postcss.config.mjs +5 -0
- package/base-package/public/favicon.svg +4 -0
- package/base-package/tailwind.config.ts +89 -0
- package/base-package/tsconfig.json +27 -0
- package/dist/index.js +1858 -956
- package/features/ai-chat/README.md +258 -0
- package/features/ai-chat/app/api/chat/route.ts +16 -0
- package/features/ai-chat/app/dashboard/_components/chatbot.tsx +39 -0
- package/features/ai-chat/app/dashboard/chat/page.tsx +73 -0
- package/features/ai-chat/feature.config.json +22 -0
- package/features/analytics/README.md +308 -0
- package/features/analytics/feature.config.json +20 -0
- package/features/analytics/lib/posthog.ts +36 -0
- package/features/auth/README.md +336 -0
- package/features/auth/app/api/auth/[...all]/route.ts +4 -0
- package/features/auth/app/dashboard/layout.tsx +15 -0
- package/features/auth/app/dashboard/page.tsx +140 -0
- package/features/auth/app/sign-in/page.tsx +228 -0
- package/features/auth/app/sign-up/page.tsx +243 -0
- package/features/auth/auth-schema.ts +47 -0
- package/features/auth/components/auth/setup-instructions.tsx +123 -0
- package/features/auth/feature.config.json +33 -0
- package/features/auth/lib/auth-client.ts +8 -0
- package/features/auth/lib/auth.ts +295 -0
- package/features/auth/lib/email-stub.ts +55 -0
- package/features/auth/lib/email.ts +47 -0
- package/features/auth/middleware.patch.ts +43 -0
- package/features/database/README.md +256 -0
- package/features/database/db/drizzle.ts +48 -0
- package/features/database/db/schema.ts +21 -0
- package/features/database/drizzle.config.ts +13 -0
- package/features/database/feature.config.json +30 -0
- package/features/email/README.md +282 -0
- package/features/email/emails/components/layout.tsx +181 -0
- package/features/email/emails/password-reset.tsx +67 -0
- package/features/email/emails/payment-failed.tsx +167 -0
- package/features/email/emails/subscription-confirmation.tsx +129 -0
- package/features/email/emails/welcome.tsx +100 -0
- package/features/email/feature.config.json +22 -0
- package/features/email/lib/email.ts +118 -0
- package/features/file-upload/README.md +271 -0
- package/features/file-upload/app/api/upload-image/route.ts +64 -0
- package/features/file-upload/app/dashboard/upload/page.tsx +324 -0
- package/features/file-upload/feature.config.json +23 -0
- package/features/file-upload/lib/upload-image.ts +28 -0
- package/features/marketing-landing/README.md +266 -0
- package/features/marketing-landing/app/page.tsx +25 -0
- package/features/marketing-landing/components/homepage/cli-workflow-section.tsx +231 -0
- package/features/marketing-landing/components/homepage/features-section.tsx +152 -0
- package/features/marketing-landing/components/homepage/footer.tsx +53 -0
- package/features/marketing-landing/components/homepage/hero-section.tsx +112 -0
- package/features/marketing-landing/components/homepage/integrations.tsx +124 -0
- package/features/marketing-landing/components/homepage/navigation.tsx +116 -0
- package/features/marketing-landing/components/homepage/news-section.tsx +82 -0
- package/features/marketing-landing/components/homepage/pricing-section.tsx +98 -0
- package/features/marketing-landing/components/homepage/testimonials-section.tsx +34 -0
- package/features/marketing-landing/components/logos/BetterAuth.tsx +21 -0
- package/features/marketing-landing/components/logos/NeonPostgres.tsx +41 -0
- package/features/marketing-landing/components/logos/Nextjs.tsx +72 -0
- package/features/marketing-landing/components/logos/Polar.tsx +7 -0
- package/features/marketing-landing/components/logos/TailwindCSS.tsx +27 -0
- package/features/marketing-landing/components/logos/index.ts +6 -0
- package/features/marketing-landing/components/logos/shadcnui.tsx +8 -0
- package/features/marketing-landing/feature.config.json +23 -0
- package/features/payments/README.md +306 -0
- package/features/payments/app/api/subscription/route.ts +25 -0
- package/features/payments/app/dashboard/payment/_components/manage-subscription.tsx +22 -0
- package/features/payments/app/dashboard/payment/page.tsx +126 -0
- package/features/payments/app/success/page.tsx +123 -0
- package/features/payments/feature.config.json +31 -0
- package/features/payments/lib/polar-products.ts +49 -0
- package/features/payments/lib/subscription.ts +148 -0
- package/features/payments/payments-schema.ts +30 -0
- package/features/seo/README.md +244 -0
- package/features/seo/app/blog/[slug]/page.tsx +314 -0
- package/features/seo/app/blog/page.tsx +107 -0
- package/features/seo/app/robots.txt +13 -0
- package/features/seo/app/sitemap.ts +70 -0
- package/features/seo/feature.config.json +19 -0
- package/features/seo/lib/seo-utils.ts +163 -0
- package/package.json +3 -1
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# AI Chat Module - Integration Guide
|
|
2
|
+
|
|
3
|
+
**Module Version:** 1.0.0
|
|
4
|
+
**Last Updated:** 2025-12-22
|
|
5
|
+
**Standalone:** ✅ Yes (can work independently)
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
This module adds AI-powered chat functionality using OpenAI's GPT-4o model. It includes a full chat interface with streaming responses, markdown rendering, and web search capabilities.
|
|
12
|
+
|
|
13
|
+
**Key Features:**
|
|
14
|
+
- OpenAI GPT-4o integration
|
|
15
|
+
- Streaming chat responses
|
|
16
|
+
- Markdown rendering with syntax highlighting
|
|
17
|
+
- Web search preview tool
|
|
18
|
+
- Full chat UI with message history
|
|
19
|
+
- Chatbot component for dashboard integration
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Files Added
|
|
24
|
+
|
|
25
|
+
### Pages/Routes
|
|
26
|
+
- `app/dashboard/chat/page.tsx` - Full chat interface page
|
|
27
|
+
- `app/api/chat/route.ts` - Chat API endpoint with streaming
|
|
28
|
+
|
|
29
|
+
### Components
|
|
30
|
+
- `app/dashboard/_components/chatbot.tsx` - Chatbot widget component (optional dashboard integration)
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Dependencies
|
|
35
|
+
|
|
36
|
+
### Package Dependencies
|
|
37
|
+
The following packages will be added to `package.json`:
|
|
38
|
+
- `@ai-sdk/openai@^1.3.22` - OpenAI SDK for AI SDK
|
|
39
|
+
- `ai@^4.3.16` - Vercel AI SDK
|
|
40
|
+
- `@ai-sdk/react@^1.0.0` - React hooks for AI SDK
|
|
41
|
+
|
|
42
|
+
**Note:** This module uses `react-markdown` and `remark-gfm` which may already be installed by the docs module. If not, they will be added automatically.
|
|
43
|
+
|
|
44
|
+
### Required Modules
|
|
45
|
+
- None - AI Chat module is standalone
|
|
46
|
+
|
|
47
|
+
### Optional Integration
|
|
48
|
+
- **Auth Module** - For protected chat routes (works without it, but chat should be protected)
|
|
49
|
+
- **Docs Module** - May share `react-markdown` dependency
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Environment Variables
|
|
54
|
+
|
|
55
|
+
Add these to your `.env.local`:
|
|
56
|
+
|
|
57
|
+
```env
|
|
58
|
+
# AI Chat (OpenAI)
|
|
59
|
+
OPENAI_API_KEY="sk-xxxxxxxxxxxxx" # Your OpenAI API key
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Required Variables:**
|
|
63
|
+
- `OPENAI_API_KEY` - Your OpenAI API key (get from [platform.openai.com](https://platform.openai.com))
|
|
64
|
+
|
|
65
|
+
**Where to get them:**
|
|
66
|
+
- **OpenAI**: [platform.openai.com](https://platform.openai.com) - Create account and generate API key
|
|
67
|
+
- Free tier available with limited credits
|
|
68
|
+
- Pay-as-you-go pricing for production use
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Manual Integration Steps
|
|
73
|
+
|
|
74
|
+
If you're appending this module to an existing project, follow these steps:
|
|
75
|
+
|
|
76
|
+
### Step 1: Install Dependencies
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npm install
|
|
80
|
+
# or
|
|
81
|
+
pnpm install
|
|
82
|
+
# or
|
|
83
|
+
yarn install
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The append command automatically adds missing dependencies to `package.json`, but you need to install them.
|
|
87
|
+
|
|
88
|
+
### Step 2: Add Environment Variables
|
|
89
|
+
|
|
90
|
+
1. Copy `.env.example` to `.env.local` (if not exists)
|
|
91
|
+
2. Add `OPENAI_API_KEY` with your OpenAI API key
|
|
92
|
+
3. Get your API key from [platform.openai.com](https://platform.openai.com)
|
|
93
|
+
|
|
94
|
+
### Step 3: Verify Installation
|
|
95
|
+
|
|
96
|
+
1. Check that `app/api/chat/route.ts` exists
|
|
97
|
+
2. Check that `app/dashboard/chat/page.tsx` exists
|
|
98
|
+
3. Start your dev server: `npm run dev`
|
|
99
|
+
4. Visit `http://localhost:3000/dashboard/chat` to test the chat interface
|
|
100
|
+
|
|
101
|
+
### Step 4: Protect Chat Route (Optional)
|
|
102
|
+
|
|
103
|
+
If you have the auth module installed, the chat route should already be protected. If not, consider adding authentication to protect the chat API endpoint.
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Usage Examples
|
|
108
|
+
|
|
109
|
+
### Using the Chat Page
|
|
110
|
+
|
|
111
|
+
1. Navigate to `/dashboard/chat`
|
|
112
|
+
2. Start typing messages
|
|
113
|
+
3. Receive streaming AI responses
|
|
114
|
+
4. Messages support markdown formatting
|
|
115
|
+
|
|
116
|
+
### Integrating Chatbot Component
|
|
117
|
+
|
|
118
|
+
The chatbot component can be added to any dashboard page:
|
|
119
|
+
|
|
120
|
+
```tsx
|
|
121
|
+
import Chatbot from "@/app/dashboard/_components/chatbot";
|
|
122
|
+
|
|
123
|
+
export default function DashboardPage() {
|
|
124
|
+
return (
|
|
125
|
+
<div>
|
|
126
|
+
{/* Your dashboard content */}
|
|
127
|
+
<Chatbot />
|
|
128
|
+
</div>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Customizing the Chat Model
|
|
134
|
+
|
|
135
|
+
Edit `app/api/chat/route.ts` to change the model:
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
const result = streamText({
|
|
139
|
+
model: openai("gpt-3.5-turbo"), // Change model here
|
|
140
|
+
messages,
|
|
141
|
+
tools: {
|
|
142
|
+
web_search_preview: openai.tools.webSearchPreview(),
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Adding Custom Tools
|
|
148
|
+
|
|
149
|
+
You can add custom tools to the chat:
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
const result = streamText({
|
|
153
|
+
model: openai("gpt-4o"),
|
|
154
|
+
messages,
|
|
155
|
+
tools: {
|
|
156
|
+
web_search_preview: openai.tools.webSearchPreview(),
|
|
157
|
+
// Add your custom tools here
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## Customization
|
|
165
|
+
|
|
166
|
+
### Styling
|
|
167
|
+
- Chat UI uses Tailwind CSS classes
|
|
168
|
+
- Customize colors in `tailwind.config.ts`
|
|
169
|
+
- Modify chat bubble styles in `app/dashboard/chat/page.tsx`
|
|
170
|
+
|
|
171
|
+
### Configuration
|
|
172
|
+
- Model selection in `app/api/chat/route.ts`
|
|
173
|
+
- Max steps configuration in `useChat` hook
|
|
174
|
+
- Customize chatbot component in `app/dashboard/_components/chatbot.tsx`
|
|
175
|
+
|
|
176
|
+
### Features
|
|
177
|
+
- Web search is enabled by default
|
|
178
|
+
- Streaming responses are automatic
|
|
179
|
+
- Markdown rendering is built-in
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## Integration Points
|
|
184
|
+
|
|
185
|
+
### Files That May Need Manual Updates
|
|
186
|
+
|
|
187
|
+
**app/dashboard/layout.tsx** (if you want chatbot in all dashboard pages):
|
|
188
|
+
- Import and add `<Chatbot />` component
|
|
189
|
+
- Position it as needed (bottom-right corner by default)
|
|
190
|
+
|
|
191
|
+
**Middleware** (if auth module installed):
|
|
192
|
+
- Chat routes should be protected
|
|
193
|
+
- Add `/dashboard/chat` to protected routes if needed
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Troubleshooting
|
|
198
|
+
|
|
199
|
+
### Common Issues
|
|
200
|
+
|
|
201
|
+
**Issue:** "OPENAI_API_KEY is not defined" error
|
|
202
|
+
**Solution:**
|
|
203
|
+
- Add `OPENAI_API_KEY` to `.env.local`
|
|
204
|
+
- Get API key from [platform.openai.com](https://platform.openai.com)
|
|
205
|
+
- Restart dev server after adding env var
|
|
206
|
+
|
|
207
|
+
**Issue:** Chat not responding
|
|
208
|
+
**Solution:**
|
|
209
|
+
- Check OpenAI API key is valid
|
|
210
|
+
- Verify API key has credits/quota
|
|
211
|
+
- Check browser console for errors
|
|
212
|
+
- Verify API route is accessible
|
|
213
|
+
|
|
214
|
+
**Issue:** Streaming not working
|
|
215
|
+
**Solution:**
|
|
216
|
+
- Ensure `ai` package is installed
|
|
217
|
+
- Check network tab for streaming responses
|
|
218
|
+
- Verify API route returns `toDataStreamResponse()`
|
|
219
|
+
|
|
220
|
+
**Issue:** Markdown not rendering
|
|
221
|
+
**Solution:**
|
|
222
|
+
- Ensure `react-markdown` and `remark-gfm` are installed
|
|
223
|
+
- Check that markdown is wrapped in proper components
|
|
224
|
+
- Verify Tailwind prose classes are configured
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Next Steps
|
|
229
|
+
|
|
230
|
+
After installing this module:
|
|
231
|
+
|
|
232
|
+
1. Get OpenAI API key from [platform.openai.com](https://platform.openai.com)
|
|
233
|
+
2. Add `OPENAI_API_KEY` to `.env.local`
|
|
234
|
+
3. Test chat interface at `/dashboard/chat`
|
|
235
|
+
4. Customize chat model and tools as needed
|
|
236
|
+
5. Integrate chatbot component into dashboard if desired
|
|
237
|
+
6. Set up rate limiting for production use
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## Related Modules
|
|
242
|
+
|
|
243
|
+
This module works well with:
|
|
244
|
+
- **Auth Module** - For protecting chat routes
|
|
245
|
+
- **Docs Module** - May share markdown dependencies
|
|
246
|
+
|
|
247
|
+
**Note:** AI Chat module is optional and standalone. No other modules are required.
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
## Module Status
|
|
252
|
+
|
|
253
|
+
✅ **Standalone Package** - Can be installed independently
|
|
254
|
+
✅ **Streaming Support** - Real-time streaming responses
|
|
255
|
+
✅ **Markdown Rendering** - Built-in markdown support
|
|
256
|
+
✅ **Web Search** - Includes web search preview tool
|
|
257
|
+
✅ **Well Documented** - Comprehensive integration guide
|
|
258
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { openai } from "@ai-sdk/openai";
|
|
2
|
+
import { streamText } from "ai";
|
|
3
|
+
|
|
4
|
+
export async function POST(req: Request) {
|
|
5
|
+
const { messages } = await req.json();
|
|
6
|
+
|
|
7
|
+
const result = streamText({
|
|
8
|
+
model: openai.responses("gpt-4o"),
|
|
9
|
+
messages,
|
|
10
|
+
tools: {
|
|
11
|
+
web_search_preview: openai.tools.webSearchPreview(),
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
return result.toDataStreamResponse();
|
|
16
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Input } from "@/components/ui/input";
|
|
3
|
+
import { Bot, X } from "lucide-react";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
|
|
6
|
+
export default function Chatbot() {
|
|
7
|
+
const [open, setOpen] = useState(false);
|
|
8
|
+
return (
|
|
9
|
+
<div className="absolute bottom-4 right-4 z-[99]">
|
|
10
|
+
<div
|
|
11
|
+
className="rounded-full bg-black/10 cursor-pointer border p-3"
|
|
12
|
+
onClick={() => setOpen(!open)}
|
|
13
|
+
>
|
|
14
|
+
<Bot className="w-4 h-4 transition-transform hover:scale-125 hover:rotate-12 duration-300 ease-in-out" />
|
|
15
|
+
</div>
|
|
16
|
+
{open && (
|
|
17
|
+
<div className="absolute bottom-12 right-4 w-80 z-[99] dark:bg-black bg-white">
|
|
18
|
+
<div className="flex flex-col items-start justify-between gap-3 rounded-lg border h-96 shadow-lg p-4">
|
|
19
|
+
<div className="w-full">
|
|
20
|
+
<div className="flex items-center justify-between">
|
|
21
|
+
<h3 className="text-lg font-semibold">Nextjs Starter Kit</h3>
|
|
22
|
+
<X
|
|
23
|
+
className="w-4 h-4 hover:cursor-pointer"
|
|
24
|
+
onClick={() => setOpen(false)}
|
|
25
|
+
/>
|
|
26
|
+
</div>
|
|
27
|
+
<p className="text-sm text-muted-foreground mt-1 mb-4">
|
|
28
|
+
Ask me anything about Nextjs Starter Kit
|
|
29
|
+
</p>
|
|
30
|
+
</div>
|
|
31
|
+
<div className="flex items-end justify-center gap-2 w-full">
|
|
32
|
+
<Input className="w-full" placeholder="Ask me anything" />
|
|
33
|
+
</div>
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
36
|
+
)}
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Button } from "@/components/ui/button";
|
|
4
|
+
import { Input } from "@/components/ui/input";
|
|
5
|
+
import { cn } from "@/lib/utils";
|
|
6
|
+
import { useChat } from "@ai-sdk/react";
|
|
7
|
+
import Markdown from "react-markdown";
|
|
8
|
+
|
|
9
|
+
export default function Chat() {
|
|
10
|
+
const { messages, input, handleInputChange, handleSubmit } = useChat({
|
|
11
|
+
maxSteps: 10,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<div className="flex flex-col w-full py-24 justify-center items-center">
|
|
16
|
+
<div className="w-full max-w-xl space-y-4 mb-20">
|
|
17
|
+
{messages.map((message, i) => (
|
|
18
|
+
<div
|
|
19
|
+
key={message.id}
|
|
20
|
+
className={cn(
|
|
21
|
+
"flex",
|
|
22
|
+
message.role === "user" ? "justify-end" : "justify-start",
|
|
23
|
+
)}
|
|
24
|
+
>
|
|
25
|
+
<div
|
|
26
|
+
className={cn(
|
|
27
|
+
"max-w-[65%] px-3 py-1.5 text-sm shadow-sm",
|
|
28
|
+
message.role === "user"
|
|
29
|
+
? "bg-[#0B93F6] text-white rounded-2xl rounded-br-sm"
|
|
30
|
+
: "bg-[#E9E9EB] text-black rounded-2xl rounded-bl-sm",
|
|
31
|
+
)}
|
|
32
|
+
>
|
|
33
|
+
{message.parts.map((part) => {
|
|
34
|
+
switch (part.type) {
|
|
35
|
+
case "text":
|
|
36
|
+
return (
|
|
37
|
+
<div
|
|
38
|
+
key={`${message.id}-${i}`}
|
|
39
|
+
className="prose-sm prose-p:my-0.5 prose-li:my-0.5 prose-ul:my-1 prose-ol:my-1"
|
|
40
|
+
>
|
|
41
|
+
<Markdown>{part.text}</Markdown>
|
|
42
|
+
</div>
|
|
43
|
+
);
|
|
44
|
+
default:
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
})}
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
))}
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
<form
|
|
54
|
+
className="flex gap-2 justify-center w-full items-center fixed bottom-0"
|
|
55
|
+
onSubmit={handleSubmit}
|
|
56
|
+
>
|
|
57
|
+
<div className="flex flex-col gap-2 justify-center items-start mb-8 max-w-xl w-full border p-2 rounded-lg bg-white ">
|
|
58
|
+
<Input
|
|
59
|
+
className="w-full border-0 shadow-none !ring-transparent "
|
|
60
|
+
value={input}
|
|
61
|
+
placeholder="Say something..."
|
|
62
|
+
onChange={handleInputChange}
|
|
63
|
+
/>
|
|
64
|
+
<div className="flex justify-end gap-3 items-center w-full">
|
|
65
|
+
<Button size="sm" className="text-xs">
|
|
66
|
+
Send
|
|
67
|
+
</Button>
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
</form>
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ai-chat",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "OpenAI chat integration with streaming responses and markdown rendering",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@ai-sdk/openai": "^1.3.22",
|
|
7
|
+
"ai": "^4.3.16",
|
|
8
|
+
"@ai-sdk/react": "^1.0.0"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {},
|
|
11
|
+
"envVars": [
|
|
12
|
+
"OPENAI_API_KEY"
|
|
13
|
+
],
|
|
14
|
+
"files": [
|
|
15
|
+
"app/api/chat/**/*",
|
|
16
|
+
"app/dashboard/chat/**/*",
|
|
17
|
+
"app/dashboard/_components/chatbot.tsx"
|
|
18
|
+
],
|
|
19
|
+
"requires": [],
|
|
20
|
+
"conflicts": []
|
|
21
|
+
}
|
|
22
|
+
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
# Analytics Module - Integration Guide
|
|
2
|
+
|
|
3
|
+
**Module Version:** 1.0.0
|
|
4
|
+
**Last Updated:** 2025-12-22
|
|
5
|
+
**Standalone:** ✅ Yes (can work independently)
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
This module adds PostHog analytics integration for event tracking, user analytics, feature flags, session recording, and heatmaps.
|
|
12
|
+
|
|
13
|
+
**Key Features:**
|
|
14
|
+
- PostHog integration
|
|
15
|
+
- Event tracking
|
|
16
|
+
- User analytics
|
|
17
|
+
- Feature flags
|
|
18
|
+
- Session recording
|
|
19
|
+
- Heatmaps
|
|
20
|
+
- Automatic pageview tracking
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Files Added
|
|
25
|
+
|
|
26
|
+
### Utilities/Libraries
|
|
27
|
+
- `lib/posthog.ts` - PostHog provider and initialization
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Dependencies
|
|
32
|
+
|
|
33
|
+
### Package Dependencies
|
|
34
|
+
The following packages will be added to `package.json`:
|
|
35
|
+
- `posthog-js@^1.248.1` - PostHog JavaScript SDK
|
|
36
|
+
- `posthog-node@^4.18.0` - PostHog Node.js SDK
|
|
37
|
+
|
|
38
|
+
### Required Modules
|
|
39
|
+
- None - Analytics module is standalone
|
|
40
|
+
|
|
41
|
+
### Optional Integration
|
|
42
|
+
- **Auth Module** - For user identification and tracking
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Environment Variables
|
|
47
|
+
|
|
48
|
+
Add these to your `.env.local`:
|
|
49
|
+
|
|
50
|
+
```env
|
|
51
|
+
# Analytics (PostHog)
|
|
52
|
+
NEXT_PUBLIC_POSTHOG_KEY="phc_xxxxxxxxxxxxx" # Your PostHog project API key
|
|
53
|
+
NEXT_PUBLIC_POSTHOG_HOST="https://app.posthog.com" # PostHog host (default: https://app.posthog.com)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Required Variables:**
|
|
57
|
+
- `NEXT_PUBLIC_POSTHOG_KEY` - Your PostHog project API key
|
|
58
|
+
|
|
59
|
+
**Optional Variables:**
|
|
60
|
+
- `NEXT_PUBLIC_POSTHOG_HOST` - PostHog host URL (defaults to `https://app.posthog.com`)
|
|
61
|
+
|
|
62
|
+
**Where to get them:**
|
|
63
|
+
- **PostHog**: [posthog.com](https://posthog.com) - Free tier available
|
|
64
|
+
- Create account and project
|
|
65
|
+
- Get API key from project settings
|
|
66
|
+
- Use self-hosted PostHog instance if preferred
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Manual Integration Steps
|
|
71
|
+
|
|
72
|
+
If you're appending this module to an existing project, follow these steps:
|
|
73
|
+
|
|
74
|
+
### Step 1: Install Dependencies
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npm install
|
|
78
|
+
# or
|
|
79
|
+
pnpm install
|
|
80
|
+
# or
|
|
81
|
+
yarn install
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The append command automatically adds missing dependencies to `package.json`, but you need to install them.
|
|
85
|
+
|
|
86
|
+
### Step 2: Add Environment Variables
|
|
87
|
+
|
|
88
|
+
1. Copy `.env.example` to `.env.local` (if not exists)
|
|
89
|
+
2. Add `NEXT_PUBLIC_POSTHOG_KEY` with your PostHog API key
|
|
90
|
+
3. Optionally set `NEXT_PUBLIC_POSTHOG_HOST` if using self-hosted PostHog
|
|
91
|
+
|
|
92
|
+
### Step 3: Integrate PostHog Provider
|
|
93
|
+
|
|
94
|
+
Add the PostHog provider to your root layout (`app/layout.tsx`):
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
import { PostHogProviderWrapper } from "@/lib/posthog";
|
|
98
|
+
|
|
99
|
+
export default function RootLayout({
|
|
100
|
+
children,
|
|
101
|
+
}: {
|
|
102
|
+
children: React.ReactNode;
|
|
103
|
+
}) {
|
|
104
|
+
return (
|
|
105
|
+
<html lang="en">
|
|
106
|
+
<body>
|
|
107
|
+
<PostHogProviderWrapper>
|
|
108
|
+
{children}
|
|
109
|
+
</PostHogProviderWrapper>
|
|
110
|
+
</body>
|
|
111
|
+
</html>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Step 4: Verify Installation
|
|
117
|
+
|
|
118
|
+
1. Check that `lib/posthog.ts` exists
|
|
119
|
+
2. Add PostHog provider to your layout
|
|
120
|
+
3. Start your dev server: `npm run dev`
|
|
121
|
+
4. Visit your site and check PostHog dashboard for events
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Usage Examples
|
|
126
|
+
|
|
127
|
+
### Tracking Custom Events
|
|
128
|
+
|
|
129
|
+
```tsx
|
|
130
|
+
'use client';
|
|
131
|
+
|
|
132
|
+
import { usePostHog } from 'posthog-js/react';
|
|
133
|
+
|
|
134
|
+
export function MyComponent() {
|
|
135
|
+
const posthog = usePostHog();
|
|
136
|
+
|
|
137
|
+
const handleButtonClick = () => {
|
|
138
|
+
posthog?.capture('button_clicked', {
|
|
139
|
+
button_name: 'signup',
|
|
140
|
+
location: 'homepage',
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
return <button onClick={handleButtonClick}>Sign Up</button>;
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Identifying Users
|
|
149
|
+
|
|
150
|
+
```tsx
|
|
151
|
+
'use client';
|
|
152
|
+
|
|
153
|
+
import { usePostHog } from 'posthog-js/react';
|
|
154
|
+
import { useEffect } from 'react';
|
|
155
|
+
|
|
156
|
+
export function UserTracker({ user }: { user: { id: string; email: string } }) {
|
|
157
|
+
const posthog = usePostHog();
|
|
158
|
+
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
if (posthog && user) {
|
|
161
|
+
posthog.identify(user.id, {
|
|
162
|
+
email: user.email,
|
|
163
|
+
// Add more user properties
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}, [posthog, user]);
|
|
167
|
+
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Using Feature Flags
|
|
173
|
+
|
|
174
|
+
```tsx
|
|
175
|
+
'use client';
|
|
176
|
+
|
|
177
|
+
import { usePostHog } from 'posthog-js/react';
|
|
178
|
+
import { useEffect, useState } from 'react';
|
|
179
|
+
|
|
180
|
+
export function FeatureFlagComponent() {
|
|
181
|
+
const posthog = usePostHog();
|
|
182
|
+
const [isEnabled, setIsEnabled] = useState(false);
|
|
183
|
+
|
|
184
|
+
useEffect(() => {
|
|
185
|
+
if (posthog) {
|
|
186
|
+
posthog.onFeatureFlags(() => {
|
|
187
|
+
const enabled = posthog.isFeatureEnabled('new-feature');
|
|
188
|
+
setIsEnabled(enabled || false);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}, [posthog]);
|
|
192
|
+
|
|
193
|
+
if (!isEnabled) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return <div>New Feature Content</div>;
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Server-Side Tracking
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
import { PostHog } from 'posthog-node';
|
|
205
|
+
|
|
206
|
+
const posthog = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
|
|
207
|
+
host: process.env.NEXT_PUBLIC_POSTHOG_HOST || 'https://app.posthog.com',
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// Track server-side events
|
|
211
|
+
export async function trackEvent(userId: string, eventName: string, properties?: Record<string, any>) {
|
|
212
|
+
posthog.capture({
|
|
213
|
+
distinctId: userId,
|
|
214
|
+
event: eventName,
|
|
215
|
+
properties,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## Customization
|
|
223
|
+
|
|
224
|
+
### Configuration
|
|
225
|
+
- PostHog initialization is in `lib/posthog.ts`
|
|
226
|
+
- Customize person profiles setting
|
|
227
|
+
- Add custom properties to all events
|
|
228
|
+
|
|
229
|
+
### Features
|
|
230
|
+
- Pageview tracking is automatic
|
|
231
|
+
- Custom event tracking is available
|
|
232
|
+
- Feature flags are supported
|
|
233
|
+
- Session recording can be enabled in PostHog dashboard
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Integration Points
|
|
238
|
+
|
|
239
|
+
### Files That May Need Manual Updates
|
|
240
|
+
|
|
241
|
+
**app/layout.tsx**:
|
|
242
|
+
- Wrap children with `PostHogProviderWrapper`
|
|
243
|
+
- Add PostHog provider to root layout
|
|
244
|
+
|
|
245
|
+
**Components**:
|
|
246
|
+
- Use `usePostHog` hook for event tracking
|
|
247
|
+
- Identify users when they sign in
|
|
248
|
+
- Track custom events throughout your app
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## Troubleshooting
|
|
253
|
+
|
|
254
|
+
### Common Issues
|
|
255
|
+
|
|
256
|
+
**Issue:** "NEXT_PUBLIC_POSTHOG_KEY is not defined" error
|
|
257
|
+
**Solution:**
|
|
258
|
+
- Add `NEXT_PUBLIC_POSTHOG_KEY` to `.env.local`
|
|
259
|
+
- Get API key from PostHog dashboard
|
|
260
|
+
- Restart dev server after adding env var
|
|
261
|
+
- Ensure variable name starts with `NEXT_PUBLIC_` for client-side access
|
|
262
|
+
|
|
263
|
+
**Issue:** Events not showing in PostHog
|
|
264
|
+
**Solution:**
|
|
265
|
+
- Verify API key is correct
|
|
266
|
+
- Check PostHog host is correct
|
|
267
|
+
- Check browser console for errors
|
|
268
|
+
- Verify PostHog provider is in root layout
|
|
269
|
+
|
|
270
|
+
**Issue:** Feature flags not working
|
|
271
|
+
**Solution:**
|
|
272
|
+
- Ensure feature flags are enabled in PostHog dashboard
|
|
273
|
+
- Check that user is identified before checking flags
|
|
274
|
+
- Use `posthog.onFeatureFlags()` to wait for flags to load
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## Next Steps
|
|
279
|
+
|
|
280
|
+
After installing this module:
|
|
281
|
+
|
|
282
|
+
1. Get PostHog API key from [posthog.com](https://posthog.com)
|
|
283
|
+
2. Add `NEXT_PUBLIC_POSTHOG_KEY` to `.env.local`
|
|
284
|
+
3. Integrate PostHog provider in `app/layout.tsx`
|
|
285
|
+
4. Test event tracking
|
|
286
|
+
5. Set up feature flags in PostHog dashboard
|
|
287
|
+
6. Identify users when they sign in
|
|
288
|
+
7. Track custom events throughout your app
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
## Related Modules
|
|
293
|
+
|
|
294
|
+
This module works well with:
|
|
295
|
+
- **Auth Module** - For user identification and tracking
|
|
296
|
+
|
|
297
|
+
**Note:** Analytics module is optional and standalone. No other modules are required.
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
## Module Status
|
|
302
|
+
|
|
303
|
+
✅ **Standalone Package** - Can be installed independently
|
|
304
|
+
✅ **Event Tracking** - Automatic and custom events
|
|
305
|
+
✅ **Feature Flags** - Built-in feature flag support
|
|
306
|
+
✅ **User Analytics** - User identification and tracking
|
|
307
|
+
✅ **Well Documented** - Comprehensive integration guide
|
|
308
|
+
|