shipd 0.1.3 → 0.2.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/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/docs-template/README.md +74 -0
- package/features/ai-chat/README.md +316 -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 +364 -0
- package/features/analytics/feature.config.json +20 -0
- package/features/analytics/lib/posthog.ts +36 -0
- package/features/auth/README.md +409 -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 +312 -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 +341 -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 +329 -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 +333 -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 +375 -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 +302 -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
package/docs-template/README.md
CHANGED
|
@@ -253,3 +253,77 @@ This module works independently and doesn't require other modules. However, it c
|
|
|
253
253
|
✅ **Well Documented** - Comprehensive integration guide
|
|
254
254
|
✅ **Smart Deduplication** - Won't overwrite existing components
|
|
255
255
|
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## AI Integration Prompt
|
|
259
|
+
|
|
260
|
+
**For AI Assistants:** Use this prompt to understand and integrate the Documentation Pages module into an existing Next.js application.
|
|
261
|
+
|
|
262
|
+
```
|
|
263
|
+
The Documentation Pages module has been appended to this Next.js project. Your task is to ensure it's properly integrated and functional.
|
|
264
|
+
|
|
265
|
+
**Installed Packages:**
|
|
266
|
+
- @radix-ui/react-slot@^1.1.0 - UI component primitives
|
|
267
|
+
- @radix-ui/react-dialog@^1.1.0 - Dialog component
|
|
268
|
+
- class-variance-authority@^0.7.0 - Component variant utilities
|
|
269
|
+
- clsx@^2.1.1 - Conditional class names
|
|
270
|
+
- tailwind-merge@^2.5.4 - Tailwind class merging
|
|
271
|
+
- lucide-react@^0.469.0 - Icon library
|
|
272
|
+
- react-markdown@^10.1.0 - Markdown rendering
|
|
273
|
+
- remark-gfm@^4.0.1 - GitHub Flavored Markdown support
|
|
274
|
+
|
|
275
|
+
**Files Added:**
|
|
276
|
+
- app/docs/page.tsx - Documentation home page
|
|
277
|
+
- app/docs/layout.tsx - Documentation layout with sidebar
|
|
278
|
+
- app/docs/[slug]/page.tsx - Category documentation pages
|
|
279
|
+
- app/docs/[slug]/[subslug]/page.tsx - Subcategory documentation pages
|
|
280
|
+
- app/docs/api/page.tsx - API documentation page
|
|
281
|
+
- app/docs/documentation/page.tsx - General documentation page
|
|
282
|
+
- components/docs/docs-sidebar.tsx - Documentation sidebar navigation
|
|
283
|
+
- components/docs/docs-header.tsx - Documentation page header
|
|
284
|
+
- components/docs/docs-toc.tsx - Table of contents component
|
|
285
|
+
- components/docs/docs-category-page.tsx - Category page layout
|
|
286
|
+
- components/docs/docs-code-card.tsx - Code example card component
|
|
287
|
+
- components/docs/docs-nav.ts - Navigation data structure
|
|
288
|
+
- components/ui/* - UI components (button, card, badge, sheet) if not exist
|
|
289
|
+
- lib/utils.ts - Utility functions (cn helper) if not exist
|
|
290
|
+
|
|
291
|
+
**Environment Variables Required:**
|
|
292
|
+
- None (module is self-contained)
|
|
293
|
+
|
|
294
|
+
**Integration Steps:**
|
|
295
|
+
1. Verify app/docs/ directory exists with all page files
|
|
296
|
+
2. Check that components/docs/ directory exists with all docs components
|
|
297
|
+
3. Verify components/ui/ directory has required UI components (button, card, badge, sheet)
|
|
298
|
+
4. Check that lib/utils.ts exists with cn() function
|
|
299
|
+
5. Verify components/docs/docs-nav.ts has navigation structure
|
|
300
|
+
6. Test docs pages: Visit /docs, /docs/api, /docs/[category], etc.
|
|
301
|
+
7. Check sidebar navigation works and highlights current page
|
|
302
|
+
|
|
303
|
+
**Key Integration Points:**
|
|
304
|
+
- Navigation: components/docs/docs-nav.ts defines the documentation structure
|
|
305
|
+
- Layout: app/docs/layout.tsx provides sidebar and page structure
|
|
306
|
+
- Routing: Uses Next.js dynamic routes [slug] and [subslug] for nested pages
|
|
307
|
+
- Markdown: Pages can use react-markdown for content rendering
|
|
308
|
+
- Sidebar: components/docs/docs-sidebar.tsx reads from docs-nav.ts
|
|
309
|
+
- TOC: components/docs/docs-toc.tsx generates table of contents from headings
|
|
310
|
+
- Smart deduplication: UI components won't overwrite if they already exist
|
|
311
|
+
|
|
312
|
+
**Dependencies:**
|
|
313
|
+
- No dependencies on other Shipd modules
|
|
314
|
+
- Can be installed standalone
|
|
315
|
+
|
|
316
|
+
**Common Issues to Check:**
|
|
317
|
+
- If docs pages show 404: Verify app/docs/ directory structure and page.tsx files exist
|
|
318
|
+
- If UI components not found: Check components/ui/ directory, install missing dependencies
|
|
319
|
+
- If navigation not showing: Verify docs-nav.ts structure and sidebar imports
|
|
320
|
+
- If markdown not rendering: Ensure react-markdown and remark-gfm are installed
|
|
321
|
+
|
|
322
|
+
**Next Steps After Integration:**
|
|
323
|
+
- Customize navigation structure in components/docs/docs-nav.ts
|
|
324
|
+
- Update documentation content in app/docs/ pages
|
|
325
|
+
- Add your own documentation pages following the [slug]/[subslug] pattern
|
|
326
|
+
- Customize sidebar styling in docs-sidebar.tsx
|
|
327
|
+
- Update header content in docs-header.tsx
|
|
328
|
+
- Add code examples using docs-code-card.tsx component
|
|
329
|
+
```
|
|
@@ -0,0 +1,316 @@
|
|
|
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
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## AI Integration Prompt
|
|
262
|
+
|
|
263
|
+
**For AI Assistants:** Use this prompt to understand and integrate the AI Chat module into an existing Next.js application.
|
|
264
|
+
|
|
265
|
+
```
|
|
266
|
+
The AI Chat module has been appended to this Next.js project. Your task is to ensure it's properly integrated and functional.
|
|
267
|
+
|
|
268
|
+
**Installed Packages:**
|
|
269
|
+
- ai@^4.3.16 - Vercel AI SDK for streaming responses
|
|
270
|
+
- @ai-sdk/openai@^1.3.22 - OpenAI provider for AI SDK
|
|
271
|
+
- react-markdown@^10.1.0 - Markdown rendering for chat messages
|
|
272
|
+
- remark-gfm@^4.0.1 - GitHub Flavored Markdown support
|
|
273
|
+
|
|
274
|
+
**Files Added:**
|
|
275
|
+
- app/api/chat/route.ts - API route for streaming chat responses (POST handler)
|
|
276
|
+
- app/dashboard/chat/page.tsx - Full chat interface page with message history
|
|
277
|
+
- app/dashboard/_components/chatbot.tsx - Reusable chatbot widget component
|
|
278
|
+
|
|
279
|
+
**Environment Variables Required:**
|
|
280
|
+
- OPENAI_API_KEY - OpenAI API key (get from platform.openai.com)
|
|
281
|
+
|
|
282
|
+
**Integration Steps:**
|
|
283
|
+
1. Verify app/api/chat/route.ts exists and exports POST handler
|
|
284
|
+
2. Check that chat page exists: app/dashboard/chat/page.tsx
|
|
285
|
+
3. Verify chatbot component exists: app/dashboard/_components/chatbot.tsx
|
|
286
|
+
4. Ensure OPENAI_API_KEY is set in .env.local
|
|
287
|
+
5. Test chat API: POST to /api/chat with messages array
|
|
288
|
+
6. Test chat page: Visit /dashboard/chat
|
|
289
|
+
7. If auth module installed: Verify chat routes are protected
|
|
290
|
+
|
|
291
|
+
**Key Integration Points:**
|
|
292
|
+
- API route: app/api/chat/route.ts uses streamText from ai SDK with OpenAI provider
|
|
293
|
+
- Streaming: Responses use toDataStreamResponse() for real-time streaming
|
|
294
|
+
- Chat UI: Uses useChat hook from ai/react for message management
|
|
295
|
+
- Markdown: Chat messages are rendered with react-markdown and remark-gfm
|
|
296
|
+
- Web search: Includes openai.tools.webSearchPreview() by default
|
|
297
|
+
- Model: Uses gpt-4o by default (configurable in route.ts)
|
|
298
|
+
|
|
299
|
+
**Dependencies:**
|
|
300
|
+
- OPTIONAL: Auth module (for protecting chat routes)
|
|
301
|
+
- No hard dependencies on other Shipd modules
|
|
302
|
+
|
|
303
|
+
**Common Issues to Check:**
|
|
304
|
+
- If "OPENAI_API_KEY is not defined": Add API key to .env.local
|
|
305
|
+
- If streaming not working: Check API route returns toDataStreamResponse()
|
|
306
|
+
- If markdown not rendering: Ensure react-markdown and remark-gfm are installed
|
|
307
|
+
- If chat not responding: Verify OpenAI API key is valid and has credits
|
|
308
|
+
|
|
309
|
+
**Next Steps After Integration:**
|
|
310
|
+
- Get OpenAI API key from platform.openai.com
|
|
311
|
+
- Add OPENAI_API_KEY to .env.local
|
|
312
|
+
- Test chat interface at /dashboard/chat
|
|
313
|
+
- Customize model in app/api/chat/route.ts (default: gpt-4o)
|
|
314
|
+
- Add chatbot widget to other pages if desired
|
|
315
|
+
- Configure rate limiting for production
|
|
316
|
+
```
|
|
@@ -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
|
+
|