diff --git a/apps/docs/app/assets/css/main.css b/apps/docs/app/assets/css/main.css index aa4db66..98714e0 100644 --- a/apps/docs/app/assets/css/main.css +++ b/apps/docs/app/assets/css/main.css @@ -1,6 +1,8 @@ @import "tailwindcss"; @import "@nuxt/ui"; +@source "../../../"; + :root { --ui-radius: 0; --ui-bg: var(--color-white); diff --git a/apps/docs/app/components/DocsAsideRightBottom.vue b/apps/docs/app/components/DocsAsideRightBottom.vue index 1b8cd76..d14423c 100644 --- a/apps/docs/app/components/DocsAsideRightBottom.vue +++ b/apps/docs/app/components/DocsAsideRightBottom.vue @@ -3,6 +3,33 @@ const route = useRoute() const pageUrl = route.path const { open } = useAIChat() + +const faqQuestions = [ + { + category: 'Getting Started', + items: [ + 'What is Nuxt MCP Toolkit?', + 'How do I install the module?', + 'How do I use the DevTools?', + ], + }, + { + category: 'Core Features', + items: [ + 'How do I create a new MCP Tool?', + 'How do I add an MCP Resource?', + 'How do I configure Prompts?', + ], + }, + { + category: 'Advanced', + items: [ + 'Can I expose my API routes as MCP Tools?', + 'Does it support TypeScript?', + 'How do I add a custom MCP server?', + ], + }, +] diff --git a/apps/docs/modules/ai-chat/README.md b/apps/docs/modules/ai-chat/README.md new file mode 100644 index 0000000..3377c55 --- /dev/null +++ b/apps/docs/modules/ai-chat/README.md @@ -0,0 +1,161 @@ +# AI Chat Module + +A Nuxt module that provides an AI-powered chat interface using MCP (Model Context Protocol) tools. + +## Features + +- AI chat slideover component with streaming responses +- MCP tools integration for documentation search +- Syntax highlighting for code blocks +- FAQ suggestions +- Persistent chat state + +## Installation + +1. Copy the `modules/ai-chat` folder to your Nuxt project +2. Install the required dependencies: + +```bash +pnpm add @ai-sdk/mcp @ai-sdk/vue @ai-sdk/gateway ai motion-v shiki shiki-stream +``` + +3. Add the module to your `nuxt.config.ts`: + +```ts +export default defineNuxtConfig({ + modules: ['./modules/ai-chat'], + + aiChat: { + apiPath: '/api/ai-chat', + mcpPath: '/mcp', + model: 'moonshotai/kimi-k2-turbo', + } +}) +``` + +## Usage + +Add the components to your app: + +```vue + + + +``` + +### Programmatic Control + +Use the `useAIChat` composable to control the chat: + +```vue + +``` + +## Module Options + +| Option | Type | Default | Description | +|--------|------|---------|-------------| +| `apiPath` | `string` | `/api/ai-chat` | API endpoint path for the chat | +| `mcpPath` | `string` | `/mcp` | MCP server path to connect to | +| `model` | `string` | `moonshotai/kimi-k2-turbo` | AI model identifier for AI SDK Gateway | + +## Component Props + +### `` + +| Prop | Type | Default | Description | +|------|------|---------|-------------| +| `tooltipText` | `string` | `Ask AI a question` | Tooltip text on hover | + +### `` + +| Prop | Type | Default | Description | +|------|------|---------|-------------| +| `title` | `string` | `Ask AI` | Title displayed in the header | +| `placeholder` | `string` | `Ask a question...` | Input placeholder text | +| `faqQuestions` | `FaqCategory[]` | `undefined` | FAQ categories to display when chat is empty | + +#### FaqCategory Type + +```ts +interface FaqCategory { + category: string + items: string[] +} +``` + +## Requirements + +- Nuxt 4.x +- Nuxt UI 3.x (for `USlideover`, `UButton`, `UTextarea`, `UChatMessages`, etc.) +- An MCP server running (path configurable via `mcpPath`) +- AI SDK Gateway Key + +## Components + +- `AiChat` - Button to toggle the chat slideover +- `AiChatSlideover` - Main chat interface +- `AiChatToolCall` - Displays MCP tool invocations +- `AiChatPreStream` - Code block with streaming syntax highlighting + +## Customization + +### System Prompt + +To customize the AI's behavior, edit the system prompt in: +`runtime/server/api/search.ts` + +### Styling + +The components use Nuxt UI and Tailwind CSS design tokens. Customize the appearance by modifying the component files or overriding the UI props. + +## Dependencies + +```json +{ + "@ai-sdk/mcp": "^0.0.8", + "@ai-sdk/vue": "3.0.0-beta.105", + "@ai-sdk/gateway": "^1.0.0", + "ai": "6.0.0-beta.105", + "motion-v": "^1.7.4", + "shiki": "^3.0.0", + "shiki-stream": "^0.1.2" +} +``` diff --git a/apps/docs/modules/ai-chat/index.ts b/apps/docs/modules/ai-chat/index.ts new file mode 100644 index 0000000..0fbae04 --- /dev/null +++ b/apps/docs/modules/ai-chat/index.ts @@ -0,0 +1,86 @@ +import { addComponent, addImports, addServerHandler, createResolver, defineNuxtModule } from '@nuxt/kit' + +export interface AiChatModuleOptions { + /** + * API endpoint path for the chat + * @default '/api/ai-chat' + */ + apiPath?: string + /** + * MCP server path to connect to + * @default '/mcp' + */ + mcpPath?: string + /** + * AI model to use via AI SDK Gateway + * @default 'moonshotai/kimi-k2-turbo' + */ + model?: string +} + +export default defineNuxtModule({ + meta: { + name: 'ai-chat', + configKey: 'aiChat', + }, + defaults: { + apiPath: '/api/ai-chat', + mcpPath: '/mcp', + model: ' moonshotai/kimi-k2-turbo', + }, + setup(options, nuxt) { + const { resolve } = createResolver(import.meta.url) + + nuxt.options.runtimeConfig.public.aiChat = { + apiPath: options.apiPath!, + } + nuxt.options.runtimeConfig.aiChat = { + mcpPath: options.mcpPath!, + model: options.model!, + } + + addComponent({ + name: 'AiChat', + filePath: resolve('./runtime/components/AiChat.vue'), + }) + addComponent({ + name: 'AiChatSlideover', + filePath: resolve('./runtime/components/AiChatSlideover.vue'), + }) + addComponent({ + name: 'AiChatToolCall', + filePath: resolve('./runtime/components/AiChatToolCall.vue'), + }) + + addImports([ + { + name: 'useAIChat', + from: resolve('./runtime/composables/useAIChat'), + }, + { + name: 'useHighlighter', + from: resolve('./runtime/composables/useHighlighter'), + }, + ]) + + const routePath = options.apiPath!.replace(/^\//, '') + addServerHandler({ + route: `/${routePath}`, + handler: resolve('./runtime/server/api/search'), + }) + }, +}) + +declare module 'nuxt/schema' { + interface PublicRuntimeConfig { + aiChat: { + apiPath: string + } + } + interface RuntimeConfig { + aiChat: { + mcpPath: string + model: string + } + } +} diff --git a/apps/docs/app/components/AiChat.vue b/apps/docs/modules/ai-chat/runtime/components/AiChat.vue similarity index 63% rename from apps/docs/app/components/AiChat.vue rename to apps/docs/modules/ai-chat/runtime/components/AiChat.vue index 9c2ffbd..df63a08 100644 --- a/apps/docs/app/components/AiChat.vue +++ b/apps/docs/modules/ai-chat/runtime/components/AiChat.vue @@ -1,9 +1,15 @@