@lobehub/chat 1.114.6 → 1.115.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.
Files changed (59) hide show
  1. package/.cursor/rules/project-introduce.mdc +1 -15
  2. package/.cursor/rules/project-structure.mdc +227 -0
  3. package/.cursor/rules/testing-guide/db-model-test.mdc +5 -3
  4. package/.cursor/rules/testing-guide/testing-guide.mdc +153 -168
  5. package/.github/workflows/claude.yml +1 -1
  6. package/.github/workflows/test.yml +9 -0
  7. package/CHANGELOG.md +25 -0
  8. package/CLAUDE.md +11 -27
  9. package/changelog/v1.json +5 -0
  10. package/docs/development/basic/feature-development.mdx +1 -1
  11. package/docs/development/basic/feature-development.zh-CN.mdx +1 -1
  12. package/package.json +4 -4
  13. package/packages/const/src/image.ts +28 -0
  14. package/packages/const/src/index.ts +1 -0
  15. package/packages/database/package.json +4 -2
  16. package/packages/database/src/repositories/aiInfra/index.ts +1 -1
  17. package/packages/database/tests/setup-db.ts +3 -0
  18. package/packages/database/vitest.config.mts +33 -0
  19. package/packages/model-runtime/src/utils/modelParse.ts +1 -1
  20. package/packages/utils/src/client/imageDimensions.test.ts +95 -0
  21. package/packages/utils/src/client/imageDimensions.ts +54 -0
  22. package/packages/utils/src/number.test.ts +3 -1
  23. package/packages/utils/src/number.ts +1 -2
  24. package/src/app/[variants]/(main)/image/@menu/components/SeedNumberInput/index.tsx +1 -1
  25. package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/DimensionControlGroup.tsx +0 -1
  26. package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/ImageUpload.tsx +16 -6
  27. package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/ImageUrl.tsx +14 -2
  28. package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/ImageUrlsUpload.tsx +27 -2
  29. package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/MultiImagesUpload/index.tsx +23 -5
  30. package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/hooks/useAutoDimensions.ts +56 -0
  31. package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/index.tsx +82 -5
  32. package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/utils/__tests__/dimensionConstraints.test.ts +235 -0
  33. package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/utils/__tests__/imageValidation.test.ts +401 -0
  34. package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/utils/dimensionConstraints.ts +54 -0
  35. package/src/app/[variants]/(main)/image/@topic/features/Topics/TopicItem.tsx +3 -1
  36. package/src/app/[variants]/(main)/image/@topic/features/Topics/TopicList.tsx +15 -2
  37. package/src/app/[variants]/(main)/image/features/GenerationFeed/GenerationItem/utils.ts +5 -4
  38. package/src/libs/standard-parameters/index.ts +1 -1
  39. package/src/server/services/generation/index.ts +1 -1
  40. package/src/store/chat/slices/builtinTool/actions/dalle.test.ts +20 -13
  41. package/src/store/file/slices/upload/action.ts +18 -7
  42. package/src/store/image/slices/generationConfig/hooks.ts +1 -1
  43. package/tsconfig.json +1 -10
  44. package/packages/const/src/imageGeneration.ts +0 -16
  45. package/src/app/(backend)/trpc/desktop/[trpc]/route.ts +0 -26
  46. package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/AspectRatioSelect.tsx +0 -24
  47. package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/SizeSliderInput.tsx +0 -15
  48. package/src/app/[variants]/(main)/image/@topic/features/Topics/TopicItemContainer.tsx +0 -91
  49. package/src/app/desktop/devtools/page.tsx +0 -89
  50. package/src/app/desktop/layout.tsx +0 -31
  51. /package/apps/desktop/{vitest.config.ts → vitest.config.mts} +0 -0
  52. /package/packages/database/{vitest.config.ts → vitest.config.server.mts} +0 -0
  53. /package/packages/electron-server-ipc/{vitest.config.ts → vitest.config.mts} +0 -0
  54. /package/packages/file-loaders/{vitest.config.ts → vitest.config.mts} +0 -0
  55. /package/packages/model-runtime/{vitest.config.ts → vitest.config.mts} +0 -0
  56. /package/packages/prompts/{vitest.config.ts → vitest.config.mts} +0 -0
  57. /package/packages/utils/{vitest.config.ts → vitest.config.mts} +0 -0
  58. /package/packages/web-crawler/{vitest.config.ts → vitest.config.mts} +0 -0
  59. /package/{vitest.config.ts → vitest.config.mts} +0 -0
@@ -10,7 +10,7 @@ Emoji logo: 🤯
10
10
 
11
11
  ## Project Technologies Stack
12
12
 
13
- read [package.json](mdc:package.json) to know all npm packages you can use. read [folder-structure.mdx](mdc:docs/development/basic/folder-structure.mdx) to learn project structure.
13
+ read [package.json](mdc:package.json) to know all npm packages you can use.
14
14
 
15
15
  The project uses the following technologies:
16
16
 
@@ -42,17 +42,3 @@ The project uses the following technologies:
42
42
  - Cursor AI for code editing and AI coding assistance
43
43
 
44
44
  Note: All tools and libraries used are the latest versions. The application only needs to be compatible with the latest browsers;
45
-
46
- ## Often used npm scripts and commands
47
-
48
- ```bash
49
- # !: don't any build script to check weather code can work after modify
50
- # type check
51
- bun run type-check
52
-
53
- # install dependencies
54
- pnpm install
55
-
56
- # run tests
57
- npx vitest run --config vitest.config.ts '[file-path-pattern]'
58
- ```
@@ -0,0 +1,227 @@
1
+ ---
2
+ description: Project directory structure overview
3
+ alwaysApply: false
4
+ ---
5
+
6
+ # LobeChat Project Structure
7
+
8
+ ## Directory Structure
9
+
10
+ note: some files are not shown for simplicity.
11
+
12
+ ```plaintext
13
+ lobe-chat/
14
+ ├── apps/ # Applications directory
15
+ │ └── desktop/ # Electron desktop application
16
+ │ ├── src/ # Desktop app source code
17
+ │ └── resources/ # Desktop app resources
18
+ ├── docs/ # Project documentation
19
+ │ ├── development/ # Development docs
20
+ │ ├── self-hosting/ # Self-hosting docs
21
+ │ └── usage/ # Usage guides
22
+ ├── locales/ # Internationalization files
23
+ │ ├── en-US/ # English
24
+ │ └── zh-CN/ # Simplified Chinese
25
+ ├── packages/ # Monorepo packages directory
26
+ │ ├── const/ # Constants definition package
27
+ │ ├── database/ # Database related package
28
+ │ ├── model-runtime/ # AI model runtime package
29
+ │ ├── types/ # TypeScript type definitions
30
+ │ ├── utils/ # Utility functions package
31
+ │ ├── file-loaders/ # File processing packages
32
+ │ ├── prompts/ # AI prompt management
33
+ │ └── web-crawler/ # Web crawling functionality
34
+ ├── public/ # Static assets
35
+ │ ├── icons/ # Application icons
36
+ │ ├── images/ # Image resources
37
+ │ └── screenshots/ # Application screenshots
38
+ ├── scripts/ # Build and tool scripts
39
+ ├── src/ # Main application source code (see below)
40
+ ├── tests/ # Test configuration
41
+ ├── .cursor/ # Cursor AI configuration
42
+ ├── docker-compose/ # Docker configuration
43
+ ├── package.json # Project dependencies
44
+ ├── pnpm-workspace.yaml # pnpm monorepo configuration
45
+ ├── next.config.ts # Next.js configuration
46
+ ├── drizzle.config.ts # Drizzle ORM configuration
47
+ └── tsconfig.json # TypeScript configuration
48
+ ```
49
+
50
+ ## Core Source Directory (`src/`)
51
+
52
+ ```plaintext
53
+ src/
54
+ ├── app/ # Next.js App Router routes
55
+ │ ├── (backend)/ # Backend API routes
56
+ │ │ ├── api/ # REST API endpoints
57
+ │ │ │ ├── auth/ # Authentication endpoints
58
+ │ │ │ └── webhooks/ # Webhook handlers for various auth providers
59
+ │ │ ├── middleware/ # Request middleware
60
+ │ │ ├── oidc/ # OpenID Connect endpoints
61
+ │ │ ├── trpc/ # tRPC API routes
62
+ │ │ │ ├── async/ # Async tRPC endpoints
63
+ │ │ │ ├── edge/ # Edge runtime endpoints
64
+ │ │ │ ├── lambda/ # Lambda runtime endpoints
65
+ │ │ │ └── tools/ # Tools-specific endpoints
66
+ │ │ └── webapi/ # Web API endpoints
67
+ │ │ ├── chat/ # Chat-related APIs for various providers
68
+ │ │ ├── models/ # Model management APIs
69
+ │ │ ├── plugin/ # Plugin system APIs
70
+ │ │ ├── stt/ # Speech-to-text APIs
71
+ │ │ ├── text-to-image/ # Image generation APIs
72
+ │ │ └── tts/ # Text-to-speech APIs
73
+ │ ├── [variants]/ # Page route variants
74
+ │ │ ├── (main)/ # Main application routes
75
+ │ │ │ ├── chat/ # Chat interface and workspace
76
+ │ │ │ ├── discover/ # Discover page (assistants, models, providers)
77
+ │ │ │ ├── files/ # File management interface
78
+ │ │ │ ├── image/ # Image generation interface
79
+ │ │ │ ├── profile/ # User profile and stats
80
+ │ │ │ ├── repos/ # Knowledge base repositories
81
+ │ │ │ └── settings/ # Application settings
82
+ │ │ └── @modal/ # Modal routes
83
+ │ └── manifest.ts # PWA configuration
84
+ ├── components/ # Global shared components
85
+ │ ├── Analytics/ # Analytics tracking components
86
+ │ ├── Error/ # Error handling components
87
+ │ └── Loading/ # Loading state components
88
+ ├── config/ # Application configuration
89
+ │ ├── aiModels/ # AI model configurations
90
+ │ └── modelProviders/ # Model provider configurations
91
+ ├── features/ # Feature components (UI Layer)
92
+ │ ├── AgentSetting/ # Agent configuration and management
93
+ │ ├── ChatInput/ # Chat input with file upload and tools
94
+ │ ├── Conversation/ # Message display and interaction
95
+ │ ├── FileManager/ # File upload and knowledge base
96
+ │ └── PluginStore/ # Plugin marketplace and management
97
+ ├── hooks/ # Custom React hooks
98
+ ├── layout/ # Global layout components
99
+ │ ├── AuthProvider/ # Authentication provider
100
+ │ └── GlobalProvider/ # Global state provider
101
+ ├── libs/ # External library integrations
102
+ │ ├── analytics/ # Analytics services integration
103
+ │ ├── next-auth/ # NextAuth.js configuration
104
+ │ └── oidc-provider/ # OIDC provider implementation
105
+ ├── locales/ # Internationalization resources
106
+ │ └── default/ # Default language definitions
107
+ ├── migrations/ # Client-side data migrations
108
+ ├── server/ # Server-side code
109
+ │ ├── modules/ # Server modules
110
+ │ ├── routers/ # tRPC routers
111
+ │ └── services/ # Server services
112
+ ├── services/ # Client service layer
113
+ │ ├── aiModel/ # AI model services
114
+ │ ├── session/ # Session services
115
+ │ └── message/ # Message services
116
+ ├── store/ # Zustand state management
117
+ │ ├── agent/ # Agent state
118
+ │ ├── chat/ # Chat state
119
+ │ └── user/ # User state
120
+ ├── styles/ # Global styles
121
+ ├── tools/ # Built-in tool system
122
+ │ ├── artifacts/ # Code artifacts and preview
123
+ │ └── web-browsing/ # Web search and browsing
124
+ ├── types/ # TypeScript type definitions
125
+ └── utils/ # Utility functions
126
+ ├── client/ # Client-side utilities
127
+ └── server/ # Server-side utilities
128
+ ```
129
+
130
+ ## Key Monorepo Packages
131
+
132
+ ```plaintext
133
+ packages/
134
+ ├── const/ # Global constants and configurations
135
+ ├── database/ # Database schemas and models
136
+ │ ├── src/models/ # Data models (CRUD operations)
137
+ │ ├── src/schemas/ # Drizzle database schemas
138
+ │ ├── src/repositories/ # Complex query layer
139
+ │ └── migrations/ # Database migration files
140
+ ├── model-runtime/ # AI model runtime
141
+ │ └── src/
142
+ │ ├── openai/ # OpenAI provider integration
143
+ │ ├── anthropic/ # Anthropic provider integration
144
+ │ ├── google/ # Google AI provider integration
145
+ │ ├── ollama/ # Ollama local model integration
146
+ │ ├── types/ # Runtime type definitions
147
+ │ └── utils/ # Runtime utilities
148
+ ├── types/ # Shared TypeScript type definitions
149
+ │ └── src/
150
+ │ ├── agent/ # Agent-related types
151
+ │ ├── message/ # Message and chat types
152
+ │ ├── user/ # User and session types
153
+ │ └── tool/ # Tool and plugin types
154
+ ├── utils/ # Shared utility functions
155
+ │ └── src/
156
+ │ ├── client/ # Client-side utilities
157
+ │ ├── server/ # Server-side utilities
158
+ │ ├── fetch/ # HTTP request utilities
159
+ │ └── tokenizer/ # Token counting utilities
160
+ ├── file-loaders/ # File loaders (PDF, DOCX, etc.)
161
+ ├── prompts/ # AI prompt management
162
+ └── web-crawler/ # Web crawling functionality
163
+ ```
164
+
165
+ ## Architecture Layers
166
+
167
+ ### 1. **Presentation Layer**
168
+
169
+ - Business-specific feature components and reusable UI components
170
+ - Global layout providers and responsive design wrappers
171
+
172
+ ### 2. **State Management Layer**
173
+
174
+ - Zustand-based client state with domain-specific slices
175
+ - Actions and selectors for predictable state updates
176
+
177
+ ### 3. **Client Service Layer**
178
+
179
+ - Environment-adaptive services (local Model vs remote tRPC)
180
+ - Dual implementation pattern for multi-runtime compatibility
181
+
182
+ ### 4. **API Interface Layer**
183
+
184
+ - Type-safe tRPC routers organized by runtime environment
185
+ - Request routing and validation
186
+
187
+ ### 5. **Server Service Layer**
188
+
189
+ - Platform-agnostic business logic with implementation abstractions
190
+ - Reusable, testable service composition
191
+
192
+ ### 6. **Data Access Layer**
193
+
194
+ - **Repository**: Complex queries, joins, and transaction management
195
+ - **Model**: Basic CRUD operations and single-table queries
196
+ - **Schema**: Drizzle ORM definitions and migration management
197
+
198
+ ### 7. **Integration & Extensions**
199
+
200
+ - **External**: Third-party service integrations and library wrappers
201
+ - **Built-in**: AI runtime, tool system, file processing, and web crawling
202
+
203
+ ## Data Flow Architecture
204
+
205
+ ### Unified Flow Pattern
206
+
207
+ ```
208
+ UI Layer → State Management → Client Service → [Environment Branch] → Database
209
+ ↓ ↓ ↓ ↓ ↓
210
+ React Zustand Environment Local/Remote PGLite/
211
+ Components Store Adaptation Routing PostgreSQL
212
+ ```
213
+
214
+ ### Environment-Specific Routing
215
+
216
+ | Mode | UI | Service Route | Database |
217
+ | --------------- | -------- | ---------------------- | ------------------- |
218
+ | **Browser/PWA** | React | Direct Model Access | PGLite (Local) |
219
+ | **Server** | React | tRPC → Server Services | PostgreSQL (Remote) |
220
+ | **Desktop** | Electron | tRPC → Local Node.js | PGLite/PostgreSQL\* |
221
+
222
+ _\*Depends on cloud sync configuration_
223
+
224
+ ### Key Characteristics
225
+
226
+ - **Type Safety**: End-to-end type safety via tRPC and Drizzle ORM
227
+ - **Local/Remote Dual Mode**: PGLite enables user data ownership and local control
@@ -5,6 +5,8 @@ alwaysApply: false
5
5
 
6
6
  ## 🗃️ 数据库 Model 测试指南
7
7
 
8
+ 测试 `packages/database` 下的数据库 Model 层。
9
+
8
10
  ### 测试环境选择 💡
9
11
 
10
12
  数据库 Model 层通过环境变量控制数据库类型,在两种测试环境下有不同的数据库后端:客户端环境 (PGLite) 和 服务端环境 (PostgreSQL)
@@ -17,10 +19,10 @@ alwaysApply: false
17
19
 
18
20
  ```bash
19
21
  # 1. 先在客户端环境测试(快速验证)
20
- npx vitest run --config vitest.config.ts src/database/models/__tests__/myModel.test.ts
22
+ cd packages/database && TEST_SERVER_DB=0 bunx vitest run --silent='passed-only' src/database/models/__tests__/myModel.test.ts
21
23
 
22
- # 2. 再在服务端环境测试(兼容性验证)
23
- npx vitest run --config vitest.config.server.ts src/database/models/__tests__/myModel.test.ts
24
+ # 2. 再在服务端环境测试(兼容性验证), 需要设置环境变量 `TEST_SERVER_DB=1`
25
+ cd packages/database && TEST_SERVER_DB=1 bunx vitest run --silent='passed-only' src/database/models/__tests__/myModel.test.ts #
24
26
  ```
25
27
 
26
28
  ### 创建新 Model 测试的最佳实践 📋