A minimalist, modern AI chat web application template built with Nuxt 3, Vue 3, Tailwind CSS v4, Pinia, and Zod. It connects seamlessly to local Ollama models via Nitro server streaming, featuring macOS Terminal-style code blocks, smooth Motion animations, Light/Dark themes, and bilingual support (简体中文 / English).
| Light Mode | Dark Mode |
|---|---|
![]() |
![]() |
简体中文文档(点击展开 / 收起)
基于 Nuxt 3、Vue 3、Tailwind CSS v4、Pinia 与 Zod 构建的极简现代本地 AI 对话 Web 模板,采用双栏对话布局与克制干净的交互界面。通过 Nitro 服务端流式代理连接本地 Ollama 模型,内置 macOS 终端风格代码块、Motion 交互动效、深浅色主题及中英双语切换。
- 本地大模型真实流式对话:通过 Nuxt 3 Nitro 服务端接口(
/api/chat)代理请求至本地 Ollama(默认deepseek-coder:1.3b),彻底规避跨域(CORS)限制,支持逐字流式输出与随时中断生成(AbortController)。 - 极简现代双栏交互:克制、高对比度的纯粹界面设计,全站独立控件统一采用
rounded-2xl圆角与1px细边框分区,移动端适配抽屉式侧边栏。 - Markdown 与 macOS 终端风格代码块:内置
markdown-it+highlight.js+isomorphic-dompurify安全富文本渲染,自动将代码块包装为带有红黄绿三色圆点、语言标识及独立“复制代码”按钮的 macOS Terminal 窗口。 - 精致微动效与思考加载器:基于
motion-v实现侧边栏抽屉滑入滑出、消息气泡登场过渡;在等待本地模型响应首个 Token(TTFT)期间展示三层渐变呼吸加载指示器。 - 中英双语与深浅色主题切换:集成
@nuxtjs/i18nv9(no_prefix无前缀路由策略)与 Tailwind CSS v4@custom-variant dark,支持一键切换简体中文 / English及Light / Dark模式(仅 UI 偏好存入 Cookie)。 - 防竞态与内存态安全设计:采用三重任务 ID(
generationId、sessionId、assistantMessageId)与 Stop-First 策略防止异步流串台;所有聊天会话数据仅保存在 Pinia 运行时内存中,刷新即焚,保障本地隐私。
| 类别 | 技术选型 | 说明 |
|---|---|---|
| 核心框架 | Nuxt 3 / Vue 3 | 统一 <script setup lang="ts">,启用严格 TypeScript 模式 |
| 样式方案 | Tailwind CSS v4 | 基于 @tailwindcss/vite,全局设计令牌集中于 assets/css/global.css |
| 状态管理 | Pinia (@pinia/nuxt) |
集中管理会话列表、消息流状态与活动生成任务元数据 |
| 表单校验 | Zod | 统一校验所有用户输入与空状态示例提示词 |
| 富文本与安全 | markdown-it + highlight.js + isomorphic-dompurify |
同步语法高亮与严格 XSS 消毒过滤 |
| 交互动效 | motion-v |
轻量级组件过渡与抽屉动画 |
| 国际化 | @nuxtjs/i18n v9 |
支持 zh-CN 与 en 实时切换 |
| 图标与包管理 | lucide-vue-next / pnpm |
统一线性图标与高效依赖管理 |
请确保本地已安装并启动 Ollama 服务(默认监听 http://127.0.0.1:11434),并拉取默认模型:
# 拉取模型
ollama pull deepseek-coder:1.3b
# 启动 Ollama 服务(若尚未在后台运行)
ollama serve提示:如需更换其他本地模型,可直接修改
server/api/chat.post.ts中的model字段。
# 安装依赖
pnpm install
# 启动开发服务器(默认访问 http://localhost:3000)
pnpm dev# 运行 Nuxt TypeScript 严格类型检查
pnpm nuxi typecheck
# 构建生产版本
pnpm build
# 本地预览生产构建
pnpm preview| 路由路径 | 页面文件 | 功能描述 |
|---|---|---|
/ |
pages/index.vue |
主对话工作区,支持新建会话、流式问答与重新生成 |
/chat-history |
pages/chat-history.page.vue |
历史会话管理页(通过 nuxt.config.ts 的 pages:extend 映射规范路径) |
ai-chat-template/
├── app.vue # 应用根入口
├── nuxt.config.ts # Nuxt 3、i18n 与自定义路由配置
├── assets/
│ └── css/
│ └── global.css # Tailwind v4 入口、深浅色变量、Markdown 与代码高亮主题
├── components/
│ └── chat/
│ ├── chat-header.component.vue # 顶部导航栏(含主题切换与中英语言切换按钮)
│ ├── chat-input.component.vue # 自适应高度输入框、Zod 校验提示与发送/停止控制
│ ├── conversation-panel.component.vue # 主对话区容器
│ ├── empty-state.component.vue # 空会话欢迎页与快捷示例提示词
│ ├── generation-indicator.component.vue # 生成状态提示条
│ ├── message-bubble.component.vue # 消息气泡(含三层思考加载器、macOS 代码块与复制交互)
│ ├── message-list.component.vue # 消息列表与自动滚动跟随
│ ├── session-list-item.component.vue # 侧边栏会话项(支持原地二次确认删除)
│ └── session-sidebar.component.vue # 响应式侧边栏(桌面端常驻 / 移动端 Motion 抽屉)
├── composables/
│ ├── use-auto-scroll.composable.ts # 流式输出智能滚动跟随逻辑
│ ├── use-mock-stream.composable.ts # 流式对话核心编排(三重 ID 校验与 AbortController 控制)
│ └── use-theme.composable.ts # Light / Dark 主题状态与 Cookie 持久化
├── i18n/
│ └── locales/
│ ├── en.json # 英文语言包
│ └── zh-CN.json # 简体中文语言包
├── layouts/
│ └── default-chat.layout.vue # 全站聊天布局骨架与 Stop-First 会话调度
├── pages/
│ ├── chat-history.page.vue # 历史对话列表页面
│ └── index.vue # 首页对话页面
├── schemas/
│ └── prompt-input.schema.ts # Zod 输入校验规则
├── server/
│ └── api/
│ └── chat.post.ts # Nitro 服务端 Ollama 流式代理接口
├── services/
│ ├── mock-ai-stream.service.ts # 早期本地模拟流服务(保留备用)
│ └── ollama-chat.service.ts # 前端 NDJSON 流式解析与错误封装
├── stores/
│ └── chat-session.store.ts # Pinia 纯内存会话状态仓库
├── types/
│ ├── chat-message.type.ts # 会话与消息核心类型定义
│ └── ollama-chat.type.ts # Ollama 接口请求/响应类型
└── utils/
├── chat-title.util.ts # 会话自动标题生成工具
├── id-generator.util.ts # 唯一 ID 生成器
├── markdown-renderer.util.ts # Markdown 解析、XSS 过滤与 macOS 终端代码块渲染器
└── time-format.util.ts # 相对时间格式化工具
本项目基于 MIT License 开源发布。您可以自由地将本模板用于商业项目开发、个人学习研究、修改与二次分发,仅需在分发时保留原始版权声明与许可声明即可。
English Documentation (Click to expand / collapse)
A minimalist, modern local AI chat web template built with Nuxt 3, Vue 3, Tailwind CSS v4, Pinia, and Zod. It connects to local Ollama models via a Nitro server streaming proxy, featuring macOS Terminal-style code blocks, smooth Motion animations, Light/Dark themes, and bilingual support (简体中文 / English).
- Real-Time Local LLM Streaming: Proxies browser requests to a local Ollama instance (defaulting to
deepseek-coder:1.3b) via a Nuxt 3 Nitro server route (/api/chat), avoiding CORS issues while supporting token-by-token streaming and instant cancellation (AbortController). - Minimalist Dual-Pane UI: Clean, high-contrast layout featuring unified
rounded-2xlcontrols, crisp1pxstructural borders, and a responsive mobile drawer sidebar. - Markdown & macOS Terminal Code Blocks: Renders assistant responses safely using
markdown-it,highlight.js, andisomorphic-dompurify. Fenced code blocks are styled as macOS Terminal windows complete with traffic-light dots, language labels, and one-click code copying. - Fluid Motion & 3-Tier Thinking Loader: Powered by
motion-vfor smooth sidebar drawer transitions and message bubble entrance animations, paired with a 3-tier gradient breathing loader while waiting for the first token (TTFT). - Bilingual (EN / 简体中文) & Dark / Light Themes: Built-in
@nuxtjs/i18nv9 (no_prefixrouting strategy) and Tailwind CSS v4@custom-variant darkallow instant switching between English/Chinese and Light/Dark modes (UI preferences persisted via Cookie). - Race-Condition Safe & Memory-Only Chat State: Uses triple task ID verification (
generationId,sessionId,assistantMessageId) and a Stop-First policy to prevent cross-session stream leaks. All conversation data stays strictly in Pinia runtime memory and clears upon page refresh.
| Category | Technology | Purpose |
|---|---|---|
| Framework | Nuxt 3 / Vue 3 | Unified <script setup lang="ts"> with strict TypeScript |
| Styling | Tailwind CSS v4 | Configured via @tailwindcss/vite with tokens in assets/css/global.css |
| State Management | Pinia (@pinia/nuxt) |
Manages active sessions, messages, and generation metadata |
| Validation | Zod | Validates all user prompts and empty-state sample prompts |
| Markdown & Security | markdown-it + highlight.js + isomorphic-dompurify |
Syntax highlighting and strict XSS sanitization |
| Animations | motion-v |
Smooth drawer and message bubble transitions |
| Internationalization | @nuxtjs/i18n v9 |
Seamless zh-CN and en locale switching |
| Icons & Package Manager | lucide-vue-next / pnpm |
Clean linear icons and fast dependency management |
Make sure Ollama is installed and running locally at http://127.0.0.1:11434, then pull the default model:
# Pull the model
ollama pull deepseek-coder:1.3b
# Start Ollama server (if not already running)
ollama serveNote: To use a different local Ollama model, update the
modelfield insideserver/api/chat.post.ts.
# Install packages
pnpm install
# Run development server (http://localhost:3000)
pnpm dev# Run strict Nuxt TypeScript check
pnpm nuxi typecheck
# Build for production
pnpm build
# Preview production build locally
pnpm preview| Path | Page File | Description |
|---|---|---|
/ |
pages/index.vue |
Primary chat workspace with streaming responses & prompt suggestions |
/chat-history |
pages/chat-history.page.vue |
Session history management (mapped via pages:extend in nuxt.config.ts) |
ai-chat-template/
├── app.vue # Root application wrapper
├── nuxt.config.ts # Nuxt 3, i18n, and custom route configuration
├── assets/
│ └── css/
│ └── global.css # Tailwind v4 entry, theme variables, Markdown & code styles
├── components/
│ └── chat/
│ ├── chat-header.component.vue # Top bar with theme & language toggles
│ ├── chat-input.component.vue # Auto-resizing textarea, Zod validation & send/stop controls
│ ├── conversation-panel.component.vue # Main conversation layout container
│ ├── empty-state.component.vue # Empty session view with sample prompt pills
│ ├── generation-indicator.component.vue # Streaming status indicator
│ ├── message-bubble.component.vue # Message bubble (3-tier loader, macOS code blocks & copy actions)
│ ├── message-list.component.vue # Scrollable message feed
│ ├── session-list-item.component.vue # Sidebar session item with inline delete confirmation
│ └── session-sidebar.component.vue # Responsive sidebar (fixed desktop / Motion mobile drawer)
├── composables/
│ ├── use-auto-scroll.composable.ts # Smart auto-scrolling during token streaming
│ ├── use-mock-stream.composable.ts # Stream orchestration with triple ID checks & AbortController
│ └── use-theme.composable.ts # Light / Dark mode state & Cookie persistence
├── i18n/
│ └── locales/
│ ├── en.json # English translations
│ └── zh-CN.json # Simplified Chinese translations
├── layouts/
│ └── default-chat.layout.vue # Global chat shell & stop-first session lifecycle handling
├── pages/
│ ├── chat-history.page.vue # Chat history overview page
│ └── index.vue # Main chat page
├── schemas/
│ └── prompt-input.schema.ts # Zod prompt validation schema
├── server/
│ └── api/
│ └── chat.post.ts # Nitro server streaming proxy for local Ollama
├── services/
│ ├── mock-ai-stream.service.ts # Legacy local mock stream service (kept for fallback)
│ └── ollama-chat.service.ts # Client-side NDJSON stream parser & error handler
├── stores/
│ └── chat-session.store.ts # Pinia in-memory session & message store
├── types/
│ ├── chat-message.type.ts # Session & message TypeScript definitions
│ └── ollama-chat.type.ts # Ollama API payload types
└── utils/
├── chat-title.util.ts # Automatic session title generator
├── id-generator.util.ts # Unique ID generator
├── markdown-renderer.util.ts # Markdown parser, XSS sanitizer & macOS terminal renderer
└── time-format.util.ts # Relative timestamp formatter
This project is licensed under the MIT License. You are free to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of this software for both commercial and educational purposes, provided that the copyright notice and permission notice are included in all copies.
เอกสารภาษาไทย (คลิกเพื่อเปิด / ปิด)
เทมเพลตเว็บแอปพลิเคชันแชท AI แบบมินิมอลสมัยใหม่ พัฒนาด้วย Nuxt 3, Vue 3, Tailwind CSS v4, Pinia และ Zod เชื่อมต่อกับโมเดล Ollama ในเครื่องผ่าน Nitro Server Streaming รองรับการแสดงผลกล่องโค้ดทรง macOS Terminal แอนิเมชันจาก Motion โหมดสว่าง-มืด และระบบสองภาษา (简体中文 / English)
- สตรีมข้อความจาก Local LLM แบบเรียลไทม์: ส่งคำขอจากหน้าเว็บผ่าน Nitro Server Route (
/api/chat) ไปยัง Ollama ในเครื่อง (ค่าเริ่มต้นdeepseek-coder:1.3b) เพื่อหลีกเลี่ยงปัญหา CORS รองรับการแสดงผลทีละตัวอักษรและการกดหยุดสร้างคำตอบได้ทันที (AbortController) - ดีไซน์มินิมอลแบบสองคอลัมน์: อินเทอร์เฟซสะอาดตา คอนทราสต์ชัดเจน ควบคุมขอบโค้งมนของปุ่มและการ์ดทั้งหมดด้วย
rounded-2xlแบ่งสัดส่วนด้วยเส้นขอบ1pxและรองรับแถบเมนูเลื่อนด้านข้างบนมือถือ - รองรับ Markdown และกล่องโค้ดทรง macOS Terminal: แปลงข้อความตอบกลับของ AI อย่างปลอดภัยด้วย
markdown-it+highlight.js+isomorphic-dompurifyโดยจัดรูปแบบบล็อกโค้ดให้เป็นหน้าต่าง macOS Terminal พร้อมปุ่มจุดสามสี ป้ายชื่อภาษา และปุ่มคัดลอกโค้ดแยกแต่ละกล่อง - แอนิเมชันลื่นไหลและตัวโหลด 3 ระดับ: ใช้
motion-vสร้างแอนิเมชันเปิด-ปิดแถบด้านข้างและการปรากฏของกล่องข้อความ พร้อมแถบโหลดไล่ระดับสี 3 ชั้นระหว่างรอ Token แรกจากโมเดล (TTFT) - สลับภาษา (จีน / อังกฤษ) และธีม (สว่าง / มืด): ผสานการทำงานของ
@nuxtjs/i18nv9 (โหมดno_prefixไม่กระทบเส้นทาง URL) และ Tailwind CSS v4@custom-variant darkสลับภาษาและธีมได้ทันที (บันทึกเฉพาะค่าตั้งค่า UI ลงใน Cookie) - ป้องกันข้อมูลชนกันและเก็บประวัติในหน่วยความจำเท่านั้น: ใช้ระบบตรวจสอบรหัสงาน 3 ชั้น (
generationId,sessionId,assistantMessageId) ร่วมกับกลยุทธ์ Stop-First เพื่อป้องกันข้อความสตรีมข้ามห้องแชท ข้อมูลการสนทนาทั้งหมดเก็บในหน่วยความจำชั่วคราวของ Pinia และจะถูกล้างเมื่อรีเฟรชหน้าเว็บเพื่อความเป็นส่วนตัว
| หมวดหมู่ | เทคโนโลยี | รายละเอียด |
|---|---|---|
| เฟรมเวิร์กหลัก | Nuxt 3 / Vue 3 | ใช้ <script setup lang="ts"> ร่วมกับ TypeScript โหมดเข้มงวด |
| จัดการสไตล์ | Tailwind CSS v4 | ติดตั้งผ่าน @tailwindcss/vite และรวมตัวแปรดีไซน์ไว้ที่ assets/css/global.css |
| จัดการสถานะ | Pinia (@pinia/nuxt) |
จัดการรายการห้องแชท ข้อความ และสถานะการสตรีม |
| ตรวจสอบข้อมูล | Zod | ตรวจสอบความถูกต้องของข้อความผู้ใช้และคำถามตัวอย่างทั้งหมด |
| Markdown และความปลอดภัย | markdown-it + highlight.js + isomorphic-dompurify |
ไฮไลต์ไวยากรณ์โค้ดและกรองความปลอดภัย XSS |
| แอนิเมชัน | motion-v |
แอนิเมชันการเปิดแถบเมนูและกล่องข้อความ |
| ระบบหลายภาษา | @nuxtjs/i18n v9 |
สลับภาษาระหว่าง zh-CN และ en ได้ทันที |
| ไอคอนและตัวจัดการแพ็กเกจ | lucide-vue-next / pnpm |
ไอคอนลายเส้นมินิมอลและการจัดการแพ็กเกจที่รวดเร็ว |
ตรวจสอบให้แน่ใจว่าได้ติดตั้งและเปิดใช้งาน Ollama ในเครื่องเรียบร้อยแล้ว (พอร์ตเริ่มต้น http://127.0.0.1:11434) จากนั้นดาวน์โหลดโมเดลเริ่มต้น:
# ดาวน์โหลดโมเดล
ollama pull deepseek-coder:1.3b
# เริ่มต้นเซิร์ฟเวอร์ Ollama (หากยังไม่ได้รันอยู่เบื้องหลัง)
ollama serveหมายเหตุ: หากต้องการเปลี่ยนไปใช้โมเดลอื่นในเครื่อง สามารถแก้ไขค่า
modelในไฟล์server/api/chat.post.tsได้โดยตรง
# ติดตั้งแพ็กเกจทั้งหมด
pnpm install
# เปิดเซิร์ฟเวอร์พัฒนา (เข้าใช้งานที่ http://localhost:3000)
pnpm dev# ตรวจสอบ TypeScript ทั้งโปรเจกต์
pnpm nuxi typecheck
# สร้างไฟล์สำหรับ Production
pnpm build
# ทดสอบพรีวิวเวอร์ชัน Production ในเครื่อง
pnpm preview| เส้นทาง (Path) | ไฟล์หน้าเว็บ | คำอธิบาย |
|---|---|---|
/ |
pages/index.vue |
หน้าหลักสำหรับสนทนากับ AI สร้างห้องแชทใหม่ และเลือกคำถามตัวอย่าง |
/chat-history |
pages/chat-history.page.vue |
หน้าจัดการประวัติการสนทนา (กำหนดเส้นทางผ่าน pages:extend ใน nuxt.config.ts) |
ai-chat-template/
├── app.vue # ไฟล์เริ่มต้นหลักของแอปพลิเคชัน
├── nuxt.config.ts # การตั้งค่า Nuxt 3, i18n และเส้นทาง URL
├── assets/
│ └── css/
│ └── global.css # ไฟล์หลัก Tailwind v4, ตัวแปรธีม, สไตล์ Markdown และธีมโค้ด
├── components/
│ └── chat/
│ ├── chat-header.component.vue # แถบด้านบน (รวมปุ่มสลับธีมและปุ่มสลับภาษา)
│ ├── chat-input.component.vue # ช่องพิมพ์ข้อความขยายอัตโนมัติ การตรวจสอบ Zod และปุ่มส่ง/หยุด
│ ├── conversation-panel.component.vue # พื้นที่แสดงผลหลักของการสนทนา
│ ├── empty-state.component.vue # หน้าจอเริ่มต้นเมื่อยังไม่มีข้อความ พร้อมปุ่มคำถามตัวอย่าง
│ ├── generation-indicator.component.vue # แถบแจ้งสถานะกำลังสร้างคำตอบ
│ ├── message-bubble.component.vue # กล่องข้อความแชท (ตัวโหลด 3 ชั้น, กล่องโค้ด macOS และปุ่มคัดลอก)
│ ├── message-list.component.vue # รายการข้อความพร้อมระบบเลื่อนอัตโนมัติ
│ ├── session-list-item.component.vue # รายการห้องแชทในแถบด้านข้าง (รองรับการยืนยันลบในตัว)
│ └── session-sidebar.component.vue # แถบด้านข้าง (แสดงถาวรบนเดสก์ท็อป / ลิ้นชัก Motion บนมือถือ)
├── composables/
│ ├── use-auto-scroll.composable.ts # ระบบเลื่อนหน้าจอตามข้อความที่กำลังสตรีม
│ ├── use-mock-stream.composable.ts # ตัวควบคุมหลักของการสตรีม (ตรวจสอบ ID 3 ชั้นและ AbortController)
│ └── use-theme.composable.ts # จัดการสถานะธีม Light / Dark และบันทึกลง Cookie
├── i18n/
│ └── locales/
│ ├── en.json # ไฟล์แปลภาษาอังกฤษ
│ └── zh-CN.json # ไฟล์แปลภาษาจีนตัวย่อ
├── layouts/
│ └── default-chat.layout.vue # โครงสร้างหน้าเว็บหลักและการจัดการวงจรชีวิตห้องแชท (Stop-First)
├── pages/
│ ├── chat-history.page.vue # หน้าประวัติการสนทนาทั้งหมด
│ └── index.vue # หน้าหลักของระบบแชท
├── schemas/
│ └── prompt-input.schema.ts # กฎการตรวจสอบข้อมูลนำเข้าด้วย Zod
├── server/
│ └── api/
│ └── chat.post.ts # Nitro Server API สำหรับเชื่อมต่อสตรีมกับ Ollama ในเครื่อง
├── services/
│ ├── mock-ai-stream.service.ts # บริการจำลองข้อความสตรีมยุคแรก (เก็บไว้เป็นตัวสำรอง)
│ └── ollama-chat.service.ts # ตัวอ่านข้อมูลสตรีม NDJSON ฝั่งหน้าเว็บและจัดการข้อผิดพลาด
├── stores/
│ └── chat-session.store.ts # Pinia Store สำหรับเก็บข้อมูลห้องแชทในหน่วยความจำ
├── types/
│ ├── chat-message.type.ts # นิยาม TypeScript Types ของห้องแชทและข้อความ
│ └── ollama-chat.type.ts # นิยาม Types สำหรับรับ-ส่งข้อมูลกับ Ollama API
└── utils/
├── chat-title.util.ts # ฟังก์ชันสร้างชื่อหัวข้อห้องแชทอัตโนมัติ
├── id-generator.util.ts # ฟังก์ชันสร้างรหัสอ้างอิงเฉพาะ (Unique ID)
├── markdown-renderer.util.ts # ตัวแปลง Markdown, กรอง XSS และสร้างกล่องโค้ด macOS Terminal
└── time-format.util.ts # ฟังก์ชันจัดรูปแบบการแสดงเวลา
โปรเจกต์นี้เผยแพร่ภายใต้สัญญาอนุญาต MIT License คุณสามารถนำซอร์สโค้ดนี้ไปใช้งาน คัดลอก ดัดแปลง ผสานรวม เผยแพร่ แจกจ่าย หรือจำหน่ายได้ทั้งในเชิงพาณิชย์และเพื่อการศึกษาเรียนรู้ โดยไม่เสียค่าใช้จ่าย เพียงคงข้อความประกาศลิขสิทธิ์และข้อความอนุญาตต้นฉบับไว้ในสำเนาซอร์สโค้ด
本项目基于 MIT License 开源,允许个人或企业自由用于商业应用、修改、分发与学习测试;软件按“原样”提供,作者不承担使用风险责任。

