diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 00000000..64652d3b --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,66 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Build Commands + +### Go Backend (api/) +- **Development**: `cd api && go run main.go` (uses config.toml) +- **Build**: `cd api && make` (builds both amd64 and arm64 binaries) +- **Individual builds**: `make amd64` or `make arm64` +- **Clean**: `make clean` +- **Config**: Copy `config.sample.toml` to `config.toml` and configure + +### Web Frontend (web/) +- **Development**: `cd web && npm run dev` (runs on Vite dev server with --host) +- **Build**: `cd web && npm run build` +- **Lint**: `cd web && npm run lint` (ESLint with auto-fix) + +### Testing +- Backend tests: `cd api/test && bash run_crawler_test.sh` +- No specific frontend test configuration found + +## Project Architecture + +### Backend (Go) +- **Framework**: Gin web framework with dependency injection via uber-go/fx +- **Database**: GORM with MySQL, Redis for caching, LevelDB for local storage +- **Authentication**: JWT tokens with Redis session storage +- **Middleware**: CORS, authorization, parameter handling, static resource serving +- **Structure**: + - `handler/`: HTTP request handlers (REST API endpoints) + - `service/`: Business logic services (AI integrations, payments, etc.) + - `store/`: Database models and data access layer + - `core/`: Application server and middleware configuration + - `utils/`: Utility functions and helpers + +### Frontend (Vue.js) +- **Framework**: Vue 3 with Composition API +- **UI Components**: Element Plus + Vant (mobile components) +- **State Management**: Pinia +- **Routing**: Vue Router with nested routes +- **Build Tool**: Vite +- **CSS**: Stylus preprocessor with Tailwind CSS utilities +- **Features**: Responsive design (desktop/mobile views), theme switching (dark/light) + +### Key Features +- **AI Chat**: Multiple chat models and conversation management +- **Image Generation**: MidJourney, Stable Diffusion, DALL-E integration +- **Audio/Video**: Suno music creation, Luma/KeLing video generation +- **User Management**: Authentication, payments, power logs, invitations +- **Admin Panel**: Comprehensive management interface + +### Database Models +Key entities: User, ChatItem, ChatMessage, ChatRole, ChatModel, Order, Product, AdminUser, and various job types for AI services. + +### API Structure +- User APIs: `/api/user/*` (auth, profile, settings) +- Chat APIs: `/api/chat/*` (conversations, messages) +- AI Service APIs: `/api/mj/*`, `/api/sd/*`, `/api/dall/*`, `/api/suno/*`, `/api/video/*` +- Admin APIs: `/api/admin/*` (management functions) + +### Configuration +- Backend: TOML configuration file (`config.toml`) +- Database: MySQL with automatic migrations +- Services: Redis, various AI API integrations +- File Storage: Local, Aliyun OSS, MinIO, Qiniu options \ No newline at end of file diff --git a/api/handler/chat_handler.go b/api/handler/chat_handler.go index caa6bd33..406df3de 100644 --- a/api/handler/chat_handler.go +++ b/api/handler/chat_handler.go @@ -95,6 +95,15 @@ func (h *ChatHandler) Chat(c *gin.Context) { ctx, cancel := context.WithCancel(c.Request.Context()) defer cancel() + // 这里做个全局的异常处理,防止整个请求异常,导致 SSE 连接断开 + defer func() { + if err := recover(); err != nil { + logger.Errorf("chat handler error: %v", err) + pushMessage(c, ChatEventError, err) + c.Abort() + } + }() + // 使用旧的聊天数据覆盖模型和角色ID var chat model.ChatItem h.DB.Where("chat_id", input.ChatId).First(&chat) diff --git a/web/.env.development b/web/.env.development index 058389fa..e56329b9 100644 --- a/web/.env.development +++ b/web/.env.development @@ -6,7 +6,7 @@ VITE_ADMIN_USER=admin VITE_ADMIN_PASS=admin123 VITE_KEY_PREFIX=GeekAI_DEV_ VITE_TITLE="Geek-AI 创作系统" -VITE_VERSION=v4.2.4 +VITE_VERSION=v4.2.5 VITE_DOCS_URL=https://docs.geekai.me VITE_GITHUB_URL=https://github.com/yangjian102621/geekai VITE_GITEE_URL=https://gitee.com/blackfox/geekai diff --git a/web/.env.production b/web/.env.production index a3b495e0..108dda66 100644 --- a/web/.env.production +++ b/web/.env.production @@ -1,7 +1,7 @@ VITE_API_HOST= VITE_WS_HOST= VITE_KEY_PREFIX=GeekAI_ -VITE_VERSION=v4.2.4 +VITE_VERSION=v4.2.5 VITE_DOCS_URL=https://docs.geekai.me VITE_GITHUB_URL=https://github.com/yangjian102621/geekai VITE_GITEE_URL=https://gitee.com/blackfox/geekai