@lobehub/chat 1.114.6 → 1.116.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/.cursor/rules/add-provider-doc.mdc +183 -0
- package/.cursor/rules/project-introduce.mdc +1 -15
- package/.cursor/rules/project-structure.mdc +227 -0
- package/.cursor/rules/testing-guide/db-model-test.mdc +5 -3
- package/.cursor/rules/testing-guide/testing-guide.mdc +153 -168
- package/.env.example +8 -0
- package/.github/workflows/claude.yml +1 -1
- package/.github/workflows/release.yml +3 -3
- package/.github/workflows/test.yml +10 -5
- package/CHANGELOG.md +50 -0
- package/CLAUDE.md +17 -33
- package/Dockerfile +5 -1
- package/Dockerfile.database +5 -1
- package/Dockerfile.pglite +5 -1
- package/changelog/v1.json +14 -0
- package/docs/development/basic/feature-development.mdx +1 -1
- package/docs/development/basic/feature-development.zh-CN.mdx +1 -1
- package/docs/development/basic/setup-development.mdx +10 -13
- package/docs/development/basic/setup-development.zh-CN.mdx +9 -12
- package/docs/self-hosting/environment-variables/model-provider.mdx +27 -2
- package/docs/self-hosting/environment-variables/model-provider.zh-CN.mdx +27 -2
- package/docs/usage/providers/bfl.mdx +68 -0
- package/docs/usage/providers/bfl.zh-CN.mdx +67 -0
- package/locales/ar/components.json +11 -0
- package/locales/ar/error.json +11 -0
- package/locales/ar/models.json +64 -4
- package/locales/ar/providers.json +3 -0
- package/locales/bg-BG/components.json +11 -0
- package/locales/bg-BG/error.json +11 -0
- package/locales/bg-BG/models.json +64 -4
- package/locales/bg-BG/providers.json +3 -0
- package/locales/de-DE/components.json +11 -0
- package/locales/de-DE/error.json +11 -12
- package/locales/de-DE/models.json +64 -4
- package/locales/de-DE/providers.json +3 -0
- package/locales/en-US/components.json +6 -0
- package/locales/en-US/error.json +11 -12
- package/locales/en-US/models.json +64 -4
- package/locales/en-US/providers.json +3 -0
- package/locales/es-ES/components.json +11 -0
- package/locales/es-ES/error.json +11 -0
- package/locales/es-ES/models.json +64 -6
- package/locales/es-ES/providers.json +3 -0
- package/locales/fa-IR/components.json +11 -0
- package/locales/fa-IR/error.json +11 -0
- package/locales/fa-IR/models.json +64 -4
- package/locales/fa-IR/providers.json +3 -0
- package/locales/fr-FR/components.json +11 -0
- package/locales/fr-FR/error.json +11 -12
- package/locales/fr-FR/models.json +64 -4
- package/locales/fr-FR/providers.json +3 -0
- package/locales/it-IT/components.json +11 -0
- package/locales/it-IT/error.json +11 -0
- package/locales/it-IT/models.json +64 -4
- package/locales/it-IT/providers.json +3 -0
- package/locales/ja-JP/components.json +11 -0
- package/locales/ja-JP/error.json +11 -12
- package/locales/ja-JP/models.json +64 -4
- package/locales/ja-JP/providers.json +3 -0
- package/locales/ko-KR/components.json +11 -0
- package/locales/ko-KR/error.json +11 -12
- package/locales/ko-KR/models.json +64 -6
- package/locales/ko-KR/providers.json +3 -0
- package/locales/nl-NL/components.json +11 -0
- package/locales/nl-NL/error.json +11 -0
- package/locales/nl-NL/models.json +62 -4
- package/locales/nl-NL/providers.json +3 -0
- package/locales/pl-PL/components.json +11 -0
- package/locales/pl-PL/error.json +11 -0
- package/locales/pl-PL/models.json +64 -4
- package/locales/pl-PL/providers.json +3 -0
- package/locales/pt-BR/components.json +11 -0
- package/locales/pt-BR/error.json +11 -0
- package/locales/pt-BR/models.json +64 -4
- package/locales/pt-BR/providers.json +3 -0
- package/locales/ru-RU/components.json +11 -0
- package/locales/ru-RU/error.json +11 -0
- package/locales/ru-RU/models.json +64 -4
- package/locales/ru-RU/providers.json +3 -0
- package/locales/tr-TR/components.json +11 -0
- package/locales/tr-TR/error.json +11 -0
- package/locales/tr-TR/models.json +64 -4
- package/locales/tr-TR/providers.json +3 -0
- package/locales/vi-VN/components.json +11 -0
- package/locales/vi-VN/error.json +11 -0
- package/locales/vi-VN/models.json +64 -4
- package/locales/vi-VN/providers.json +3 -0
- package/locales/zh-CN/components.json +6 -0
- package/locales/zh-CN/error.json +11 -0
- package/locales/zh-CN/models.json +64 -4
- package/locales/zh-CN/providers.json +3 -0
- package/locales/zh-TW/components.json +11 -0
- package/locales/zh-TW/error.json +11 -12
- package/locales/zh-TW/models.json +64 -6
- package/locales/zh-TW/providers.json +3 -0
- package/package.json +4 -4
- package/packages/const/src/image.ts +28 -0
- package/packages/const/src/index.ts +1 -0
- package/packages/database/package.json +4 -2
- package/packages/database/src/repositories/aiInfra/index.ts +1 -1
- package/packages/database/tests/setup-db.ts +3 -0
- package/packages/database/vitest.config.mts +33 -0
- package/packages/model-runtime/src/google/index.ts +3 -0
- package/packages/model-runtime/src/qwen/createImage.test.ts +0 -19
- package/packages/model-runtime/src/qwen/createImage.ts +1 -27
- package/packages/model-runtime/src/utils/modelParse.ts +1 -1
- package/packages/model-runtime/src/utils/streams/google-ai.ts +26 -14
- package/packages/types/src/aiModel.ts +2 -1
- package/packages/utils/src/client/imageDimensions.test.ts +95 -0
- package/packages/utils/src/client/imageDimensions.ts +54 -0
- package/packages/utils/src/number.test.ts +3 -1
- package/packages/utils/src/number.ts +1 -2
- package/src/app/[variants]/(main)/image/@menu/components/SeedNumberInput/index.tsx +1 -1
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/DimensionControlGroup.tsx +0 -1
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/ImageUpload.tsx +16 -6
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/ImageUrl.tsx +14 -2
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/ImageUrlsUpload.tsx +27 -2
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/MultiImagesUpload/index.tsx +23 -5
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/hooks/useAutoDimensions.ts +56 -0
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/index.tsx +82 -5
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/utils/__tests__/dimensionConstraints.test.ts +235 -0
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/utils/__tests__/imageValidation.test.ts +401 -0
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/utils/dimensionConstraints.ts +54 -0
- package/src/app/[variants]/(main)/image/@topic/features/Topics/TopicItem.tsx +3 -1
- package/src/app/[variants]/(main)/image/@topic/features/Topics/TopicList.tsx +15 -2
- package/src/app/[variants]/(main)/image/features/GenerationFeed/GenerationItem/utils.ts +5 -4
- package/src/config/aiModels/google.ts +22 -1
- package/src/config/aiModels/qwen.ts +2 -2
- package/src/config/aiModels/vertexai.ts +22 -0
- package/src/libs/standard-parameters/index.ts +1 -1
- package/src/server/services/generation/index.ts +1 -1
- package/src/store/chat/slices/builtinTool/actions/dalle.test.ts +20 -13
- package/src/store/file/slices/upload/action.ts +18 -7
- package/src/store/image/slices/generationConfig/hooks.ts +1 -1
- package/tsconfig.json +1 -10
- package/.cursor/rules/debug.mdc +0 -193
- package/packages/const/src/imageGeneration.ts +0 -16
- package/src/app/(backend)/trpc/desktop/[trpc]/route.ts +0 -26
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/AspectRatioSelect.tsx +0 -24
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/SizeSliderInput.tsx +0 -15
- package/src/app/[variants]/(main)/image/@topic/features/Topics/TopicItemContainer.tsx +0 -91
- package/src/app/desktop/devtools/page.tsx +0 -89
- package/src/app/desktop/layout.tsx +0 -31
- /package/apps/desktop/{vitest.config.ts → vitest.config.mts} +0 -0
- /package/packages/database/{vitest.config.ts → vitest.config.server.mts} +0 -0
- /package/packages/electron-server-ipc/{vitest.config.ts → vitest.config.mts} +0 -0
- /package/packages/file-loaders/{vitest.config.ts → vitest.config.mts} +0 -0
- /package/packages/model-runtime/{vitest.config.ts → vitest.config.mts} +0 -0
- /package/packages/prompts/{vitest.config.ts → vitest.config.mts} +0 -0
- /package/packages/utils/{vitest.config.ts → vitest.config.mts} +0 -0
- /package/packages/web-crawler/{vitest.config.ts → vitest.config.mts} +0 -0
- /package/{vitest.config.ts → vitest.config.mts} +0 -0
@@ -0,0 +1,183 @@
|
|
1
|
+
---
|
2
|
+
description: Complete guide for adding a new AI provider documentation to LobeChat
|
3
|
+
alwaysApply: false
|
4
|
+
---
|
5
|
+
|
6
|
+
# Adding New AI Provider Documentation
|
7
|
+
|
8
|
+
This document provides a step-by-step guide for adding documentation for a new AI provider to LobeChat, based on the complete workflow used for adding providers like BFL (Black Forest Labs) and FAL.
|
9
|
+
|
10
|
+
## Overview
|
11
|
+
|
12
|
+
Adding a new provider requires creating both user-facing documentation and technical configuration files. The process involves:
|
13
|
+
|
14
|
+
1. Creating usage documentation (EN + CN)
|
15
|
+
2. Adding environment variable documentation (EN + CN)
|
16
|
+
3. Updating Docker configuration files
|
17
|
+
4. Updating .env.example file
|
18
|
+
5. Preparing image resources
|
19
|
+
|
20
|
+
## Step 1: Create Provider Usage Documentation
|
21
|
+
|
22
|
+
Create user-facing documentation that explains how to use the new provider.
|
23
|
+
|
24
|
+
### Required Files
|
25
|
+
|
26
|
+
Create both English and Chinese versions:
|
27
|
+
- `docs/usage/providers/{provider-name}.mdx` (English)
|
28
|
+
- `docs/usage/providers/{provider-name}.zh-CN.mdx` (Chinese)
|
29
|
+
|
30
|
+
### Documentation Structure
|
31
|
+
|
32
|
+
Follow the structure and format used in existing provider documentation. For reference, see:
|
33
|
+
- `docs/usage/providers/fal.mdx` (English template)
|
34
|
+
- `docs/usage/providers/fal.zh-CN.mdx` (Chinese template)
|
35
|
+
|
36
|
+
### Key Requirements
|
37
|
+
|
38
|
+
- **Images**: Prepare 5-6 screenshots showing the process
|
39
|
+
- **Cover Image**: Create or obtain a cover image for the provider
|
40
|
+
- **Accurate URLs**: Use real registration and dashboard URLs
|
41
|
+
- **Service Type**: Specify whether it's for image generation, text generation, etc.
|
42
|
+
- **Pricing Warning**: Include pricing information callout
|
43
|
+
|
44
|
+
### Important Notes
|
45
|
+
|
46
|
+
- **🔒 API Key Security**: Never include real API keys in documentation. Always use placeholder format (e.g., `bfl-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`)
|
47
|
+
- **🖼️ Image Hosting**: Use LobeHub's CDN for all images: `hub-apac-1.lobeobjects.space`
|
48
|
+
|
49
|
+
## Step 2: Update Environment Variables Documentation
|
50
|
+
|
51
|
+
Add the new provider's environment variables to the self-hosting documentation.
|
52
|
+
|
53
|
+
### Files to Update
|
54
|
+
|
55
|
+
- `docs/self-hosting/environment-variables/model-provider.mdx` (English)
|
56
|
+
- `docs/self-hosting/environment-variables/model-provider.zh-CN.mdx` (Chinese)
|
57
|
+
|
58
|
+
### Content to Add
|
59
|
+
|
60
|
+
Add two sections for each provider:
|
61
|
+
|
62
|
+
```markdown
|
63
|
+
### `{PROVIDER}_API_KEY`
|
64
|
+
|
65
|
+
- Type: Required
|
66
|
+
- Description: This is the API key you applied for in the {Provider Name} service.
|
67
|
+
- Default: -
|
68
|
+
- Example: `{api-key-format-example}`
|
69
|
+
|
70
|
+
### `{PROVIDER}_MODEL_LIST`
|
71
|
+
|
72
|
+
- Type: Optional
|
73
|
+
- Description: Used to control the {Provider Name} model list. Use `+` to add a model, `-` to hide a model, and `model_name=display_name` to customize the display name of a model. Separate multiple entries with commas. The definition syntax follows the same rules as other providers' model lists.
|
74
|
+
- Default: `-`
|
75
|
+
- Example: `-all,+{model-id-1},+{model-id-2}={display-name}`
|
76
|
+
|
77
|
+
The above example disables all models first, then enables `{model-id-1}` and `{model-id-2}` (displayed as `{display-name}`).
|
78
|
+
|
79
|
+
[model-list]: /docs/self-hosting/advanced/model-list
|
80
|
+
```
|
81
|
+
|
82
|
+
### Important Notes
|
83
|
+
|
84
|
+
- **API Key Format**: Use proper UUID format for examples (e.g., `12345678-1234-1234-1234-123456789abc`)
|
85
|
+
- **Real Model IDs**: Use actual model IDs from the codebase, not placeholders
|
86
|
+
- **Consistent Naming**: Follow the pattern `{PROVIDER}_API_KEY` and `{PROVIDER}_MODEL_LIST`
|
87
|
+
|
88
|
+
## Step 3: Update Docker Configuration Files
|
89
|
+
|
90
|
+
Add environment variables to all Docker configuration files to ensure the provider works in containerized deployments.
|
91
|
+
|
92
|
+
### Files to Update
|
93
|
+
|
94
|
+
All Dockerfile variants must be updated:
|
95
|
+
- `Dockerfile`
|
96
|
+
- `Dockerfile.database`
|
97
|
+
- `Dockerfile.pglite`
|
98
|
+
|
99
|
+
### Changes Required
|
100
|
+
|
101
|
+
Add the new provider's environment variables at the **end** of the ENV section, just before the final line:
|
102
|
+
|
103
|
+
```dockerfile
|
104
|
+
# Previous providers...
|
105
|
+
# 302.AI
|
106
|
+
AI302_API_KEY="" AI302_MODEL_LIST="" \
|
107
|
+
# {New Provider 1}
|
108
|
+
{PROVIDER1}_API_KEY="" {PROVIDER1}_MODEL_LIST="" \
|
109
|
+
# {New Provider 2}
|
110
|
+
{PROVIDER2}_API_KEY="" {PROVIDER2}_MODEL_LIST=""
|
111
|
+
```
|
112
|
+
|
113
|
+
### Important Rules
|
114
|
+
|
115
|
+
- **Position**: Add new providers at the **end** of the list
|
116
|
+
- **Ordering**: When adding multiple providers, use alphabetical order (e.g., FAL before BFL)
|
117
|
+
- **Consistency**: Maintain identical ordering across all Dockerfile variants
|
118
|
+
- **Format**: Follow the pattern `{PROVIDER}_API_KEY="" {PROVIDER}_MODEL_LIST="" \`
|
119
|
+
|
120
|
+
## Step 4: Update .env.example File
|
121
|
+
|
122
|
+
Add example configuration entries to help users understand how to configure the provider locally.
|
123
|
+
|
124
|
+
### File to Update
|
125
|
+
|
126
|
+
- `.env.example`
|
127
|
+
|
128
|
+
### Content to Add
|
129
|
+
|
130
|
+
Add new sections before the "Market Service" section:
|
131
|
+
|
132
|
+
```bash
|
133
|
+
### {Provider Name} ###
|
134
|
+
|
135
|
+
# {PROVIDER}_API_KEY={provider-prefix}-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
136
|
+
```
|
137
|
+
|
138
|
+
### Format Guidelines
|
139
|
+
|
140
|
+
- **Section Header**: Use `### {Provider Name} ###` format
|
141
|
+
- **Commented Example**: Use `#` to comment out the example
|
142
|
+
- **Key Format**: Use appropriate prefix for the provider (e.g., `bfl-`, `fal-`, `sk-`)
|
143
|
+
- **Position**: Add before the Market Service section
|
144
|
+
- **Spacing**: Maintain consistent spacing with existing entries
|
145
|
+
|
146
|
+
## Step 5: Image Resources
|
147
|
+
|
148
|
+
Prepare all necessary image resources for the documentation.
|
149
|
+
|
150
|
+
### Required Images
|
151
|
+
|
152
|
+
1. **Cover Image**: Provider logo or branded image
|
153
|
+
2. **API Dashboard Screenshots**: 3-4 screenshots showing API key creation process
|
154
|
+
3. **LobeChat Configuration Screenshots**: 2-3 screenshots showing provider setup in LobeChat
|
155
|
+
|
156
|
+
### Image Guidelines
|
157
|
+
|
158
|
+
- **Quality**: Use high-resolution screenshots
|
159
|
+
- **Consistency**: Maintain consistent styling across all screenshots
|
160
|
+
- **Privacy**: Remove or blur any sensitive information
|
161
|
+
- **Format**: Use PNG format for screenshots
|
162
|
+
- **Hosting**: Use LobeHub's CDN (`hub-apac-1.lobeobjects.space`) for all images
|
163
|
+
|
164
|
+
## Checklist
|
165
|
+
|
166
|
+
Before submitting your provider documentation:
|
167
|
+
|
168
|
+
- [ ] Created both English and Chinese usage documentation
|
169
|
+
- [ ] Added environment variable documentation (EN + CN)
|
170
|
+
- [ ] Updated all 3 Dockerfile variants with consistent ordering
|
171
|
+
- [ ] Updated .env.example with proper key format
|
172
|
+
- [ ] Prepared all required screenshots and images
|
173
|
+
- [ ] Used actual model IDs from the codebase
|
174
|
+
- [ ] Verified no real API keys are included in documentation
|
175
|
+
- [ ] Used LobeHub CDN for all image hosting
|
176
|
+
- [ ] Tested the documentation for clarity and accuracy
|
177
|
+
|
178
|
+
## Reference
|
179
|
+
|
180
|
+
This guide was created based on the implementation of BFL (Black Forest Labs) provider documentation. For a complete example, refer to:
|
181
|
+
- Commits: `d2da03e1a` (documentation) and `6a2e95868` (environment variables)
|
182
|
+
- Files: `docs/usage/providers/bfl.mdx`, `docs/usage/providers/bfl.zh-CN.mdx`
|
183
|
+
- PR: Current branch `tj/feat/bfl-docs`
|
@@ -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.
|
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
|
-
|
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
|
-
|
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 测试的最佳实践 📋
|