@lobehub/chat 1.96.17 → 1.96.19

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.
@@ -3,52 +3,52 @@ description: i18n workflow and troubleshooting
3
3
  globs:
4
4
  alwaysApply: false
5
5
  ---
6
- # LobeChat Internationalization (i18n) Guide
6
+ # LobeChat 国际化指南
7
7
 
8
- ## Architecture Overview
8
+ ## 架构概览
9
9
 
10
- LobeChat uses **react-i18next** for internationalization with a well-structured namespace approach:
10
+ LobeChat 使用 react-i18next 进行国际化,采用良好的命名空间架构:
11
11
 
12
- - **Default language**: Chinese (zh-CN) - serves as the source language
13
- - **Supported locales**: 18 languages including English, Japanese, Korean, Arabic, etc.
14
- - **Framework**: react-i18next with Next.js app router
15
- - **Translation automation**: [@lobehub/i18n-cli](mdc:package.json) for automated translations, config file: .i18nrc.js
12
+ - 默认语言:中文(zh-CN),作为源语言
13
+ - 支持语言:18 种语言,包括英语、日语、韩语、阿拉伯语等
14
+ - 框架:react-i18next 配合 Next.js app router
15
+ - 翻译自动化:@lobehub/i18n-cli 用于自动翻译,配置文件:.i18nrc.js
16
16
 
17
- ## Directory Structure
17
+ ## 目录结构
18
18
 
19
19
  ```
20
20
  src/locales/
21
- ├── default/ # Source language files (zh-CN)
22
- │ ├── index.ts # Namespace exports
23
- │ ├── common.ts # Common translations
24
- │ ├── chat.ts # Chat-related translations
25
- │ ├── setting.ts # Settings translations
26
- │ └── ... # Other namespace files
27
- └── resources.ts # Type definitions and locale config
28
-
29
- locales/ # Translated files
30
- ├── en-US/ # English translations
31
- │ ├── common.json # Common translations
32
- │ ├── chat.json # Chat translations
33
- │ ├── setting.json # Settings translations
34
- │ └── ... # Other namespace JSON files
35
- ├── ja-JP/ # Japanese translations
21
+ ├── default/ # 源语言文件(zh-CN
22
+ │ ├── index.ts # 命名空间导出
23
+ │ ├── common.ts # 通用翻译
24
+ │ ├── chat.ts # 聊天相关翻译
25
+ │ ├── setting.ts # 设置翻译
26
+ │ └── ... # 其他命名空间文件
27
+ └── resources.ts # 类型定义和语言配置
28
+
29
+ locales/ # 翻译文件
30
+ ├── en-US/ # 英语翻译
31
+ │ ├── common.json # 通用翻译
32
+ │ ├── chat.json # 聊天翻译
33
+ │ ├── setting.json # 设置翻译
34
+ │ └── ... # 其他命名空间 JSON 文件
35
+ ├── ja-JP/ # 日语翻译
36
36
  │ ├── common.json
37
37
  │ ├── chat.json
38
38
  │ └── ...
39
- └── ... # Other language folders
39
+ └── ... # 其他语言文件夹
40
40
  ```
41
41
 
42
- ## Workflow for Adding New Translations
42
+ ## 添加新翻译的工作流程
43
43
 
44
- ### 1. Add New Translation Keys
44
+ ### 1. 添加新的翻译键
45
45
 
46
- **Step 1**: Add translation key to the appropriate namespace file in [src/locales/default/](mdc:src/locales/default)
46
+ 第一步:在 src/locales/default 目录下的相应命名空间文件中添加翻译键
47
47
 
48
48
  ```typescript
49
- // Example: src/locales/default/common.ts
49
+ // 示例:src/locales/default/common.ts
50
50
  export default {
51
- // ... existing keys
51
+ // ... 现有键
52
52
  newFeature: {
53
53
  title: "新功能标题",
54
54
  description: "功能描述文案",
@@ -57,40 +57,40 @@ export default {
57
57
  };
58
58
  ```
59
59
 
60
- **Step 2**: If creating a new namespace, export it in [src/locales/default/index.ts](mdc:src/locales/default/index.ts)
60
+ 第二步:如果创建新命名空间,需要在 src/locales/default/index.ts 中导出
61
61
 
62
62
  ```typescript
63
63
  import newNamespace from "./newNamespace";
64
64
 
65
65
  const resources = {
66
- // ... existing namespaces
66
+ // ... 现有命名空间
67
67
  newNamespace,
68
68
  } as const;
69
69
  ```
70
70
 
71
- ### 2. Translation Process
71
+ ### 2. 翻译过程
72
72
 
73
- **Development Mode** (Recommended):
73
+ 开发模式:
74
74
 
75
- - Manually add Chinese translations to corresponding JSON files in `locales/zh-CN/namespace.json`, this avoids running slow automation during development
76
- - Don't auto add translations for other language like English etc, most of developer is Chinese,
75
+ 一般情况下不需要你帮我跑自动翻译工具,跑一次很久,需要的时候我会自己跑。
76
+ 但是为了立马能看到效果,还是需要先翻译 `locales/zh-CN/namespace.json`,不需要翻译其它语言。
77
77
 
78
- **Production Mode**:
78
+ 生产模式:
79
79
 
80
80
  ```bash
81
- # Generate translations for all languages
81
+ # 为所有语言生成翻译
82
82
  npm run i18n
83
83
  ```
84
84
 
85
- ## Usage in Components
85
+ ## 在组件中使用
86
86
 
87
- ### Basic Usage with Hooks
87
+ ### 基本用法
88
88
 
89
89
  ```tsx
90
90
  import { useTranslation } from "react-i18next";
91
91
 
92
92
  const MyComponent = () => {
93
- const { t } = useTranslation("common"); // namespace
93
+ const { t } = useTranslation("common");
94
94
 
95
95
  return (
96
96
  <div>
@@ -102,58 +102,56 @@ const MyComponent = () => {
102
102
  };
103
103
  ```
104
104
 
105
- ### With Parameters
105
+ ### 带参数的用法
106
106
 
107
107
  ```tsx
108
108
  const { t } = useTranslation("common");
109
109
 
110
- // Translation key with interpolation
111
110
  <p>{t("welcome.message", { name: "John" })}</p>;
112
111
 
113
- // Corresponding locale file:
112
+ // 对应的语言文件:
114
113
  // welcome: { message: '欢迎 {{name}} 使用!' }
115
114
  ```
116
115
 
117
- ### Multiple Namespaces
116
+ ### 多个命名空间
118
117
 
119
118
  ```tsx
120
119
  const { t } = useTranslation(['common', 'chat']);
121
120
 
122
- // Access different namespaces
123
121
  <button>{t('common:save')}</button>
124
122
  <span>{t('chat:typing')}</span>
125
123
  ```
126
124
 
127
- ## Type Safety
125
+ ## 类型安全
128
126
 
129
- The project uses TypeScript for type-safe translations with auto-generated types from [src/locales/resources.ts](mdc:src/locales/resources.ts):
127
+ 项目使用 TypeScript 实现类型安全的翻译,类型从 src/locales/resources.ts 自动生成:
130
128
 
131
129
  ```typescript
132
130
  import type { DefaultResources, NS, Locales } from "@/locales/resources";
133
131
 
134
- // Available types:
135
- // - NS: Available namespace keys ('common' | 'chat' | 'setting' | ...)
136
- // - Locales: Supported locale codes ('en-US' | 'zh-CN' | 'ja-JP' | ...)
132
+ // 可用类型:
133
+ // - NS: 可用命名空间键 ('common' | 'chat' | 'setting' | ...)
134
+ // - Locales: 支持的语言代码 ('en-US' | 'zh-CN' | 'ja-JP' | ...)
137
135
 
138
- // Type-safe namespace usage
139
- const namespace: NS = "common"; // ✅ Valid
140
- const locale: Locales = "en-US"; // ✅ Valid
136
+ const namespace: NS = "common";
137
+ const locale: Locales = "en-US";
141
138
  ```
142
139
 
143
- ## Best Practices
140
+ ## 最佳实践
144
141
 
145
- ### 1. Namespace Organization
142
+ ### 1. 命名空间组织
146
143
 
147
- - **common**: Shared UI elements (buttons, labels, actions)
148
- - **chat**: Chat-specific features
149
- - **setting**: Configuration and settings
150
- - **error**: Error messages and handling
151
- - **[feature]**: Feature-specific or page specific namespaces
144
+ - common: 共享 UI 元素(按钮、标签、操作)
145
+ - chat: 聊天特定功能
146
+ - setting: 配置和设置
147
+ - error: 错误消息和处理
148
+ - [feature]: 功能特定或页面特定的命名空间
149
+ - components: 可复用组件文案
152
150
 
153
- ### 2. Key Naming Conventions
151
+ ### 2. 键命名约定
154
152
 
155
153
  ```typescript
156
- // ✅ Good: Hierarchical structure
154
+ // ✅ 好:层次结构
157
155
  export default {
158
156
  modal: {
159
157
  confirm: {
@@ -167,17 +165,17 @@ export default {
167
165
  },
168
166
  };
169
167
 
170
- // ❌ Avoid: Flat structure
168
+ // ❌ 避免:扁平结构
171
169
  export default {
172
170
  modalConfirmTitle: "确认操作",
173
171
  modalConfirmMessage: "确定要执行此操作吗?",
174
172
  };
175
173
  ```
176
174
 
177
- ## Troubleshooting
175
+ ## 故障排除
178
176
 
179
- ### Missing Translation Keys
177
+ ### 缺少翻译键
180
178
 
181
- - Check if the key exists in src/locales/default/namespace.ts
182
- - Ensure proper namespace import in component
183
- - Ensure new namespaces are exported in [src/locales/default/index.ts](mdc:src/locales/default/index.ts)
179
+ - 检查键是否存在于 src/locales/default/namespace.ts
180
+ - 确保在组件中正确导入命名空间
181
+ - 确保新命名空间已在 src/locales/default/index.ts 中导出
@@ -5,11 +5,11 @@ alwaysApply: false
5
5
  ---
6
6
  # React Layout Kit 使用指南
7
7
 
8
- `react-layout-kit` 是一个功能丰富的 React flex 布局组件库,在 lobe-chat 项目中被广泛使用。以下是重点组件的使用方法:
8
+ react-layout-kit 是一个功能丰富的 React flex 布局组件库,在 lobe-chat 项目中被广泛使用。以下是重点组件的使用方法:
9
9
 
10
10
  ## Flexbox 组件
11
11
 
12
- Flexbox 是最常用的布局组件,用于创建弹性布局,类似于 CSS 的 `display: flex`。
12
+ Flexbox 是最常用的布局组件,用于创建弹性布局,类似于 CSS 的 display: flex
13
13
 
14
14
  ### 基本用法
15
15
 
@@ -31,16 +31,16 @@ import { Flexbox } from 'react-layout-kit';
31
31
 
32
32
  ### 常用属性
33
33
 
34
- - `horizontal`: 布尔值,设置为水平方向布局
35
- - `flex`: 数值或字符串,控制 flex 属性
36
- - `gap`: 数值,设置子元素之间的间距
37
- - `align`: 对齐方式,如 'center', 'flex-start' 等
38
- - `justify`: 主轴对齐方式,如 'space-between', 'center' 等
39
- - `padding`: 内边距值
40
- - `paddingInline`: 水平内边距值
41
- - `paddingBlock`: 垂直内边距值
42
- - `width/height`: 设置宽高,通常用 `'100%'` 或具体像素值
43
- - `style`: 自定义样式对象
34
+ - horizontal: 布尔值,设置为水平方向布局
35
+ - flex: 数值或字符串,控制 flex 属性
36
+ - gap: 数值,设置子元素之间的间距
37
+ - align: 对齐方式,如 'center', 'flex-start' 等
38
+ - justify: 主轴对齐方式,如 'space-between', 'center' 等
39
+ - padding: 内边距值
40
+ - paddingInline: 水平内边距值
41
+ - paddingBlock: 垂直内边距值
42
+ - width/height: 设置宽高,通常用 '100%' 或具体像素值
43
+ - style: 自定义样式对象
44
44
 
45
45
  ### 实际应用示例
46
46
 
@@ -60,12 +60,7 @@ import { Flexbox } from 'react-layout-kit';
60
60
  </Flexbox>
61
61
 
62
62
  {/* 中间内容区 */}
63
- <Flexbox
64
- flex={1}
65
- style={{
66
- height: '100%',
67
- }}
68
- >
63
+ <Flexbox flex={1} style={{ height: '100%' }}>
69
64
  {/* 主要内容 */}
70
65
  <Flexbox flex={1} padding={24} style={{ overflowY: 'auto' }}>
71
66
  <MainContent />
@@ -91,8 +86,6 @@ Center 是对 Flexbox 的封装,使子元素水平和垂直居中。
91
86
  ### 基本用法
92
87
 
93
88
  ```jsx
94
- import { Center } from 'react-layout-kit';
95
-
96
89
  <Center width={'100%'} height={'100%'}>
97
90
  <Content />
98
91
  </Center>
@@ -118,9 +111,9 @@ Center 组件继承了 Flexbox 的所有属性,同时默认设置了居中对
118
111
 
119
112
  ## 最佳实践
120
113
 
121
- 1. 使用 `flex={1}` 让组件填充可用空间
122
- 2. 使用 `gap` 代替传统的 margin 设置元素间距
123
- 3. 嵌套 Flexbox 创建复杂布局
124
- 4. 设置 `overflow: 'auto'` 使内容可滚动
125
- 5. 使用 `horizontal` 创建水平布局,默认为垂直布局
126
- 6.`antd-style``useTheme` hook 配合使用创建主题响应式的布局
114
+ - 使用 flex={1} 让组件填充可用空间
115
+ - 使用 gap 代替传统的 margin 设置元素间距
116
+ - 嵌套 Flexbox 创建复杂布局
117
+ - 设置 overflow: 'auto' 使内容可滚动
118
+ - 使用 horizontal 创建水平布局,默认为垂直布局
119
+ - 与 antd-style 的 useTheme hook 配合使用创建主题响应式的布局
@@ -6,12 +6,14 @@ alwaysApply: false
6
6
  # react component 编写指南
7
7
 
8
8
  - 如果要写复杂样式的话用 antd-style ,简单的话可以用 style 属性直接写内联样式
9
- - 如果需要 flex 布局或者居中布局应该使用 react-layout-kit
10
- - 选择组件库中的组件时优先使用 [lobe-ui.mdc](mdc:.cursor/rules/package-usage/lobe-ui.mdc) 有的,然后才是 antd 的,不知道 @lobehub/ui 的组件怎么用,有哪些属性,就自己搜下这个项目其它地方怎么用的,不要瞎猜
9
+ - 如果需要 flex 布局或者居中布局应该使用 react-layout-kit 的 Flexbox 和 Center 组件
10
+ - 选择组件时优先顺序应该是 src/components > 安装的组件 package > lobe-ui > antd
11
11
 
12
- ## 访问 theme 的两种方式
12
+ ## antd-style token system
13
13
 
14
- ### 使用 antd-style useTheme hook
14
+ ### 访问 token system 的两种方式
15
+
16
+ #### 使用 antd-style 的 useTheme hook
15
17
 
16
18
  ```tsx
17
19
  import { useTheme } from 'antd-style';
@@ -32,7 +34,7 @@ const MyComponent = () => {
32
34
  }
33
35
  ```
34
36
 
35
- ### 使用 antd-style 的 createStyles
37
+ #### 使用 antd-style 的 createStyles
36
38
 
37
39
  ```tsx
38
40
  const useStyles = createStyles(({ css, token }) => {
@@ -65,4 +67,87 @@ const Card: FC<CardProps> = ({ title, content }) => {
65
67
  </Flexbox>
66
68
  );
67
69
  };
68
- ```
70
+ ```
71
+
72
+ ### 一些你经常会忘记使用的 token
73
+
74
+ 请注意使用下面的 token 而不是 css 字面值。可以访问 https://ant.design/docs/react/customize-theme-cn 了解所有 token
75
+
76
+ - 动画类
77
+ - token.motionDurationMid
78
+ - token.motionEaseInOut
79
+ - 包围盒属性
80
+ - token.paddingSM
81
+ - token.marginLG
82
+
83
+
84
+ ## Lobe UI 包含的组件
85
+
86
+ - 不知道 @lobehub/ui 的组件怎么用,有哪些属性,就自己搜下这个项目其它地方怎么用的,不要瞎猜,大部分组件都是在 antd 的基础上扩展了属性
87
+ - 具体用法不懂可以联网搜索,例如 ActionIcon 就爬取 https://ui.lobehub.com/components/action-icon
88
+
89
+ - General
90
+ ActionIcon
91
+ ActionIconGroup
92
+ Block
93
+ Button
94
+ Icon
95
+ - Data Display
96
+ Avatar
97
+ Collapse
98
+ FileTypeIcon
99
+ FluentEmoji
100
+ GuideCard
101
+ Highlighter
102
+ Hotkey
103
+ Image
104
+ List
105
+ Markdown
106
+ MaterialFileTypeIcon
107
+ Mermaid
108
+ Segmented
109
+ Snippet
110
+ SortableList
111
+ Tag
112
+ Tooltip
113
+ Video
114
+ - Data Entry
115
+ AutoComplete
116
+ CodeEditor
117
+ ColorSwatches
118
+ CopyButton
119
+ DatePicker
120
+ EditableText
121
+ EmojiPicker
122
+ Form
123
+ FormModal
124
+ HotkeyInput
125
+ ImageSelect
126
+ Input
127
+ SearchBar
128
+ Select
129
+ SliderWithInput
130
+ ThemeSwitch
131
+ - Feedback
132
+ Alert
133
+ Drawer
134
+ Modal
135
+ - Layout
136
+ DraggablePanel
137
+ Footer
138
+ Grid
139
+ Header
140
+ Layout
141
+ MaskShadow
142
+ ScrollShadow
143
+ - Navigation
144
+ Burger
145
+ Dropdown
146
+ Menu
147
+ SideNav
148
+ Tabs
149
+ Toc
150
+ - Theme
151
+ ConfigProvider
152
+ FontLoader
153
+ ThemeProvider
@@ -0,0 +1,76 @@
1
+ ---
2
+ description:
3
+ globs:
4
+ alwaysApply: true
5
+ ---
6
+ # LobeChat Cursor Rules System Guide
7
+
8
+ This document explains how the LobeChat project's Cursor rules system works and serves as an index for manually accessible rules.
9
+
10
+ ## 🎯 Core Principle
11
+
12
+ **All rules are equal** - there are no priorities or "recommendations" between different rule sources. You should follow all applicable rules simultaneously.
13
+
14
+ ## 📚 Four Ways to Access Rules
15
+
16
+ ### 1. **Always Applied Rules** - `always_applied_workspace_rules`
17
+ - **What**: Core project guidelines that are always active
18
+ - **Content**: Project tech stack, basic coding standards, output formatting rules
19
+ - **Access**: No tools needed - automatically provided in every conversation
20
+
21
+ ### 2. **Dynamic Context Rules** - `cursor_rules_context`
22
+ - **What**: Rules automatically matched based on files referenced in the conversation
23
+ - **Trigger**: Only when user **explicitly @ mentions files** or **opens files in Cursor**
24
+ - **Content**: May include brief descriptions or full rule content, depending on relevance
25
+ - **Access**: No tools needed - automatically updated when files are referenced
26
+
27
+ ### 3. **Agent Requestable Rules** - `agent_requestable_workspace_rules`
28
+ - **What**: Detailed operational guides that can be requested on-demand
29
+ - **Access**: Use `fetch_rules` tool with rule names
30
+ - **Examples**: `debug`, `i18n/i18n`, `code-review`
31
+
32
+ ### 4. **Manual Rules Index** - This file + `read_file`
33
+ - **What**: Additional rules not covered by the above mechanisms
34
+ - **Why needed**: Cursor's rule system only supports "agent request" or "auto attach" modes
35
+ - **Access**: Use `read_file` tool to read specific `.mdc` files
36
+
37
+ ## 🔧 When to Use `read_file` for Rules
38
+
39
+ Use `read_file` to access rules from the index below when:
40
+
41
+ 1. **Gap identification**: You determine a rule is needed for the current task
42
+ 2. **No auto-trigger**: The rule isn't provided in `cursor_rules_context` (because relevant files weren't @ mentioned)
43
+ 3. **Not agent-requestable**: The rule isn't available via `fetch_rules`
44
+
45
+ ## 📋 Available Rules Index
46
+
47
+ The following rules are available via `read_file` from the `.cursor/rules/` directory:
48
+
49
+ - `backend-architecture.mdc` – Backend layer architecture and design guidelines
50
+ - `zustand-action-patterns.mdc` – Recommended patterns for organizing Zustand actions
51
+ - `zustand-slice-organization.mdc` – Best practices for structuring Zustand slices
52
+ - `drizzle-schema-style-guide.mdc` – Style guide for defining Drizzle ORM schemas
53
+ - `react-component.mdc` – React component style guide and conventions
54
+
55
+ ## ❌ Common Misunderstandings to Avoid
56
+
57
+ 1. **"Priority confusion"**: There's no hierarchy between rule sources - they're complementary, not competitive
58
+ 2. **"Dynamic expectations"**: `cursor_rules_context` only updates when you @ files - it won't automatically include rules for tasks you're thinking about
59
+ 3. **"Tool redundancy"**: Each access method serves a different purpose - they're not alternatives to choose from
60
+
61
+ ## 🛠️ Practical Workflow
62
+
63
+ ```
64
+ 1. Start with always_applied_workspace_rules (automatic)
65
+ 2. Check cursor_rules_context for auto-matched rules (automatic)
66
+ 3. If you need specific guides: fetch_rules (manual)
67
+ 4. If you identify gaps: consult this index → read_file (manual)
68
+ ```
69
+
70
+ ## Example Decision Flow
71
+
72
+ **Scenario**: Working on a new Zustand store slice
73
+ 1. Follow always_applied_workspace_rules ✅
74
+ 2. If store files were @ mentioned → use cursor_rules_context rules ✅
75
+ 3. Need detailed Zustand guidance → `read_file('.cursor/rules/zustand-slice-organization.mdc')` ✅
76
+ 4. All rules apply simultaneously - no conflicts ✅
@@ -14,9 +14,9 @@ You are an expert in UI/UX design, proficient in web interaction patterns, respo
14
14
 
15
15
  ## Problem Solving
16
16
 
17
+ - Before formulating any response, you must first gather context by using tools like codebase_search, grep_search, file_search, web_search, fetch_rules, context7, and read_file to avoid making assumptions.
17
18
  - When modifying existing code, clearly describe the differences and reasons for the changes
18
19
  - Provide alternative solutions that may be better overall or superior in specific aspects
19
- - Always consider using the latest technologies, standards, and APIs to strive for code optimization, not just the conventional wisdom
20
20
  - Provide optimization suggestions for deprecated API usage
21
21
  - Cite sources whenever possible at the end, not inline
22
22
  - When you provide multiple solutions, provide the recommended solution first, and note it as `Recommended`
@@ -25,18 +25,14 @@ You are an expert in UI/UX design, proficient in web interaction patterns, respo
25
25
 
26
26
  ## Code Implementation
27
27
 
28
- - Write minimal code changes that are ONLY directly related to the requirements
29
28
  - Write correct, up-to-date, bug-free, fully functional, secure, maintainable and efficient code
30
29
  - First, think step-by-step: describe your plan in detailed pseudocode before implementation
31
30
  - Confirm the plan before writing code
32
31
  - Focus on maintainable over being performant
33
32
  - Leave NO TODOs, placeholders, or missing pieces
34
33
  - Be sure to reference file names
35
- - Please respect my prettier preferences when you provide code
36
34
  - When you notice I have manually modified the code, that was definitely on purpose and do not revert them
37
- - Don't remove meaningful code comments, be sure to keep original comments when providing applied code
38
- - Update the code comments when needed after you modify the related code
39
35
  - If documentation links or required files are missing, ask for them before proceeding with the task rather than making assumptions
40
36
  - If you're unable to access or retrieve content from websites, please inform me immediately and request the specific information needed rather than making assumptions
41
- - Sometimes ESLint errors may not be reasonable, and making changes could introduce logical bugs. If you find an ESLint rule unreasonable, disable it directly. For example, with the 'prefer-dom-node-text-content' rule, there are actual differences between innerText and textContent
42
37
  - You can use emojis, npm packages like `chalk`/`chalk-animation`/`terminal-link`/`gradient-string`/`log-symbols`/`boxen`/`consola`/`@clack/prompts` to create beautiful terminal output
38
+ - Don't run `tsc --noEmit` to check ts syntax error, because our project is very large and the validate very slow