@lobehub/chat 0.127.2 → 0.128.1
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/.eslintrc.js +2 -0
- package/CHANGELOG.md +50 -0
- package/docs/Deployment/Environment-Variable.md +26 -0
- package/docs/Deployment/Environment-Variable.zh-CN.md +26 -0
- package/package.json +1 -1
- package/src/app/api/config/parseDefaultAgent.test.ts +181 -0
- package/src/app/api/config/parseDefaultAgent.ts +42 -0
- package/src/app/api/config/route.ts +6 -0
- package/src/config/server/app.ts +4 -0
- package/src/features/AgentSetting/AgentConfig/index.tsx +1 -1
- package/src/layout/GlobalLayout/Locale.tsx +0 -9
- package/src/layout/GlobalLayout/StoreHydration.tsx +2 -1
- package/src/store/global/index.ts +0 -1
- package/src/store/global/slices/common/action.ts +8 -0
- package/src/store/global/hooks/index.ts +0 -3
- package/src/store/global/hooks/useOnFinishHydrationGlobal.ts +0 -16
package/.eslintrc.js
CHANGED
|
@@ -15,5 +15,7 @@ config.rules['react/no-unknown-property'] = 0;
|
|
|
15
15
|
config.rules['unicorn/prefer-ternary'] = 0;
|
|
16
16
|
config.rules['unicorn/prefer-spread'] = 0;
|
|
17
17
|
config.rules['unicorn/catch-error-name'] = 0;
|
|
18
|
+
config.rules['unicorn/no-array-for-each'] = 0;
|
|
19
|
+
config.rules['unicorn/prefer-number-properties'] = 0;
|
|
18
20
|
|
|
19
21
|
module.exports = config;
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,56 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.128.1](https://github.com/lobehub/lobe-chat/compare/v0.128.0...v0.128.1)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2024-02-15**</sup>
|
|
8
|
+
|
|
9
|
+
#### 🐛 Bug Fixes
|
|
10
|
+
|
|
11
|
+
- **misc**: Fix auto lang switch.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### What's fixed
|
|
19
|
+
|
|
20
|
+
- **misc**: Fix auto lang switch, closes [#1305](https://github.com/lobehub/lobe-chat/issues/1305) ([7a51329](https://github.com/lobehub/lobe-chat/commit/7a51329))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
## [Version 0.128.0](https://github.com/lobehub/lobe-chat/compare/v0.127.2...v0.128.0)
|
|
31
|
+
|
|
32
|
+
<sup>Released on **2024-02-14**</sup>
|
|
33
|
+
|
|
34
|
+
#### ✨ Features
|
|
35
|
+
|
|
36
|
+
- **misc**: Support define default agent config with `DEFAULT_AGENT_CONFIG` ENV.
|
|
37
|
+
|
|
38
|
+
<br/>
|
|
39
|
+
|
|
40
|
+
<details>
|
|
41
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
42
|
+
|
|
43
|
+
#### What's improved
|
|
44
|
+
|
|
45
|
+
- **misc**: Support define default agent config with `DEFAULT_AGENT_CONFIG` ENV, closes [#1291](https://github.com/lobehub/lobe-chat/issues/1291) ([c7c096e](https://github.com/lobehub/lobe-chat/commit/c7c096e))
|
|
46
|
+
|
|
47
|
+
</details>
|
|
48
|
+
|
|
49
|
+
<div align="right">
|
|
50
|
+
|
|
51
|
+
[](#readme-top)
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
|
|
5
55
|
### [Version 0.127.2](https://github.com/lobehub/lobe-chat/compare/v0.127.1...v0.127.2)
|
|
6
56
|
|
|
7
57
|
<sup>Released on **2024-02-14**</sup>
|
|
@@ -52,6 +52,32 @@ LobeChat provides additional configuration options during deployment, which can
|
|
|
52
52
|
- Default: `-`
|
|
53
53
|
- Example: `/test`
|
|
54
54
|
|
|
55
|
+
#### `DEFAULT_AGENT_CONFIG`
|
|
56
|
+
|
|
57
|
+
- Type: Optional
|
|
58
|
+
- Description: Used to configure the default configuration of the LobeChat default assistant. It supports various data types and structures, including key-value pairs, nested fields, array values, etc.
|
|
59
|
+
- Default Value: `-`
|
|
60
|
+
- Example: `'model=gpt-4-1106-preview;params.max_tokens=300;plugins=search-engine,lobe-image-designer`
|
|
61
|
+
|
|
62
|
+
`DEFAULT_AGENT_CONFIG` is used to configure the default configuration of the LobeChat default agent. It supports various data types and structures, including key-value pairs, nested fields, array values, etc. The table below provides detailed explanations of the configuration options, examples, and corresponding explanations for the `DEFAULT_AGENT_CONFIG` environment variable:
|
|
63
|
+
|
|
64
|
+
| Configuration Type | Example | Explanation |
|
|
65
|
+
| ----------------------- | -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
|
66
|
+
| Basic Key-Value Pair | `model=gpt-4` | Set the model to `gpt-4`. |
|
|
67
|
+
| Nested Field | `tts.sttLocale=en-US` | Set the language region for the text-to-speech service to `en-US`. |
|
|
68
|
+
| Array | `plugins=search-engine,lobe-image-designer` | Enable the `search-engine` and `lobe-image-designer` plugins. |
|
|
69
|
+
| Chinese Comma | `plugins=search-engine,lobe-image-designer` | The same as above, demonstrating support for Chinese comma separation. |
|
|
70
|
+
| Multiple Configurations | `model=glm-4;provider=zhipu` | Set the model to `glm-4` and the model provider to `zhipu`. |
|
|
71
|
+
| Numeric Value | `params.max_tokens=300` | Set the maximum number of tokens to `300`. |
|
|
72
|
+
| Boolean Value | `enableAutoCreateTopic=true` | Enable automatic topic creation. |
|
|
73
|
+
| Special Characters | `inputTemplate="Hello; I am a bot;"` | Set the input template to `Hello; I am a bot;`. |
|
|
74
|
+
| Error Handling | `model=gpt-4;maxToken` | Ignore the invalid entry `maxToken` and only parse out `model=gpt-4`. |
|
|
75
|
+
| Value Overriding | `model=gpt-4;model=gpt-4-1106-preview` | If the key is duplicated, use the value that appears last, in this case, the value of `model` is `gpt-4-1106-preview`. |
|
|
76
|
+
|
|
77
|
+
Related discussions:
|
|
78
|
+
|
|
79
|
+
- [\[RFC\] 022 - Default Helper Parameters for Environment Variable Configuration](https://github.com/lobehub/lobe-chat/discussions/913)
|
|
80
|
+
|
|
55
81
|
## Authentication Service Providers
|
|
56
82
|
|
|
57
83
|
### Common Settings
|
|
@@ -52,6 +52,32 @@ LobeChat 在部署时提供了一些额外的配置项,使用环境变量进
|
|
|
52
52
|
- 默认值: `-`
|
|
53
53
|
- 示例: `/test`
|
|
54
54
|
|
|
55
|
+
#### `DEFAULT_AGENT_CONFIG`
|
|
56
|
+
|
|
57
|
+
- 类型:可选
|
|
58
|
+
- 描述:用于配置 LobeChat 默认助理的默认配置。它支持多种数据类型和结构,包括键值对、嵌套字段、数组值等。
|
|
59
|
+
- 默认值:`-`
|
|
60
|
+
- 示例:`'model=gpt-4-1106-preview;params.max_tokens=300;plugins=search-engine,lobe-image-designer`
|
|
61
|
+
|
|
62
|
+
`DEFAULT_AGENT_CONFIG` 用于配置 LobeChat 默认助理的默认配置。它支持多种数据类型和结构,包括键值对、嵌套字段、数组值等。下表详细说明了 `DEFAULT_AGENT_CONFIG` 环境变量的配置项、示例以及相应解释:
|
|
63
|
+
|
|
64
|
+
| 配置项类型 | 示例 | 解释 |
|
|
65
|
+
| ---------- | -------------------------------------------- | ---------------------------------------------------------------------------- |
|
|
66
|
+
| 基本键值对 | `model=gpt-4` | 设置模型为 `gpt-4`。 |
|
|
67
|
+
| 嵌套字段 | `tts.sttLocale=en-US` | 设置文本到语音服务的语言区域为 `en-US`。 |
|
|
68
|
+
| 数组 | `plugins=search-engine,lobe-image-designer` | 启用 `search-engine` 和 `lobe-image-designer` 插件。 |
|
|
69
|
+
| 中文逗号 | `plugins=search-engine,lobe-image-designer` | 同上,演示支持中文逗号分隔。 |
|
|
70
|
+
| 多个配置项 | `model=glm-4;provider=zhipu` | 设置模型为 `glm-4` 且模型服务商为 `zhipu`。 |
|
|
71
|
+
| 数字值 | `params.max_tokens=300` | 设置最大令牌数为 `300`。 |
|
|
72
|
+
| 布尔值 | `enableAutoCreateTopic=true` | 启用自动创建主题。 |
|
|
73
|
+
| 特殊字符 | `inputTemplate="Hello; I am a bot;"` | 设置输入模板为 `Hello; I am a bot;`。 |
|
|
74
|
+
| 错误处理 | `model=gpt-4;maxToken` | 忽略无效条目 `maxToken`,仅解析出 `model=gpt-4`。 |
|
|
75
|
+
| 值覆盖 | `model=gpt-4;model=gpt-4-1106-preview` | 如果键重复,使用最后一次出现的值,此处 `model` 的值为 `gpt-4-1106-preview`。 |
|
|
76
|
+
|
|
77
|
+
相关阅读:
|
|
78
|
+
|
|
79
|
+
- [\[RFC\] 022 - 环境变量配置默认助手参数](https://github.com/lobehub/lobe-chat/discussions/913)
|
|
80
|
+
|
|
55
81
|
## 身份验证服务
|
|
56
82
|
|
|
57
83
|
### 通用设置
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/chat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.128.1",
|
|
4
4
|
"description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"framework",
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { parseAgentConfig } from './parseDefaultAgent';
|
|
4
|
+
|
|
5
|
+
describe('parseAgentConfig', () => {
|
|
6
|
+
describe('single functional feature', () => {
|
|
7
|
+
it('parses single key-value pair correctly', () => {
|
|
8
|
+
const envStr = 'model=gpt-4';
|
|
9
|
+
const expected = { model: 'gpt-4' };
|
|
10
|
+
expect(parseAgentConfig(envStr)).toEqual(expected);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('parses nested fields correctly', () => {
|
|
14
|
+
const envStr = 'tts.sttLocale=en-US';
|
|
15
|
+
const expected = { tts: { sttLocale: 'en-US' } };
|
|
16
|
+
expect(parseAgentConfig(envStr)).toEqual(expected);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('parses array values with commas correctly', () => {
|
|
20
|
+
const envStr = 'plugins=search-engine,lobe-image-designer';
|
|
21
|
+
const expected = { plugins: ['search-engine', 'lobe-image-designer'] };
|
|
22
|
+
expect(parseAgentConfig(envStr)).toEqual(expected);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('parses array values with Chinese commas correctly', () => {
|
|
26
|
+
const envStr = 'plugins=search-engine,lobe-image-designer';
|
|
27
|
+
const expected = { plugins: ['search-engine', 'lobe-image-designer'] };
|
|
28
|
+
expect(parseAgentConfig(envStr)).toEqual(expected);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('parses multiple key-value pairs correctly', () => {
|
|
32
|
+
const envStr = 'model=gpt-4;version=1.0.0';
|
|
33
|
+
const expected = { model: 'gpt-4', version: '1.0.0' };
|
|
34
|
+
expect(parseAgentConfig(envStr)).toEqual(expected);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// 测试数字值是否被正确解析为数字
|
|
38
|
+
it('parses numerical values correctly', () => {
|
|
39
|
+
const envStr = 'params.max_tokens=300';
|
|
40
|
+
const expected = { params: { max_tokens: 300 } };
|
|
41
|
+
expect(parseAgentConfig(envStr)).toEqual(expected);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// 测试多级嵌套属性是否被正确解析
|
|
45
|
+
it('parses deeply nested fields correctly', () => {
|
|
46
|
+
const envStr = 'tts.voice.openai=english-voice';
|
|
47
|
+
const expected = { tts: { voice: { openai: 'english-voice' } } };
|
|
48
|
+
expect(parseAgentConfig(envStr)).toEqual(expected);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('parses boolean values correctly', () => {
|
|
52
|
+
const envStr = 'enableAutoCreateTopic=true;enableCompressThreshold=false';
|
|
53
|
+
const expected = {
|
|
54
|
+
enableAutoCreateTopic: true,
|
|
55
|
+
enableCompressThreshold: false,
|
|
56
|
+
};
|
|
57
|
+
expect(parseAgentConfig(envStr)).toEqual(expected);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('parses fewShots array with cascading keys correctly', () => {
|
|
61
|
+
const envStr =
|
|
62
|
+
'fewShots.0.content=Hello;fewShots.0.role=user;fewShots.1.content=Hi;fewShots.1.role=system';
|
|
63
|
+
const expected = {
|
|
64
|
+
fewShots: [
|
|
65
|
+
{ content: 'Hello', role: 'user' },
|
|
66
|
+
{ content: 'Hi', role: 'system' },
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// Assuming parseAgentConfig function has been implemented to understand and correctly parse the cascading keys format for fewShots
|
|
71
|
+
expect(parseAgentConfig(envStr)).toEqual(expected);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('parses tts voice configuration correctly', () => {
|
|
75
|
+
const envStr = 'tts.voice.openai=english-voice;tts.voice.microsoft=spanish-voice';
|
|
76
|
+
const expected = {
|
|
77
|
+
tts: { voice: { openai: 'english-voice', microsoft: 'spanish-voice' } },
|
|
78
|
+
};
|
|
79
|
+
expect(parseAgentConfig(envStr)).toEqual(expected);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('parses inputTemplate with special characters correctly', () => {
|
|
83
|
+
const envStr = 'inputTemplate="Hello, I am {name}"';
|
|
84
|
+
const expected = { inputTemplate: 'Hello, I am {name}' };
|
|
85
|
+
expect(parseAgentConfig(envStr)).toEqual(expected);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('complex environment', () => {
|
|
90
|
+
it.skip('parses a complete environment variable string correctly', () => {
|
|
91
|
+
const envStr =
|
|
92
|
+
'model=gpt-4-1106-preview;params.max_tokens=300;plugins=search-engine,lobe-image-designer';
|
|
93
|
+
const expected = {
|
|
94
|
+
model: 'gpt-4-1106-preview',
|
|
95
|
+
params: { max_tokens: 300 },
|
|
96
|
+
plugins: ['search-engine', 'lobe-image-designer'],
|
|
97
|
+
};
|
|
98
|
+
expect(parseAgentConfig(envStr)).toEqual(expected);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// 测试当配置字符串包含所有可能字段时的行为
|
|
102
|
+
it('parses a complex environment variable string correctly', () => {
|
|
103
|
+
const envStr =
|
|
104
|
+
'model=gpt-4-1106-preview;params.max_tokens=300;params.temperature=0.7;plugins=search-engine,lobe-image-designer;tts.voice.openai=english-voice';
|
|
105
|
+
const expected = {
|
|
106
|
+
model: 'gpt-4-1106-preview',
|
|
107
|
+
params: { max_tokens: 300, temperature: 0.7 },
|
|
108
|
+
plugins: ['search-engine', 'lobe-image-designer'],
|
|
109
|
+
tts: { voice: { openai: 'english-voice' } },
|
|
110
|
+
};
|
|
111
|
+
expect(parseAgentConfig(envStr)).toEqual(expected);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe('Error Boundary', () => {
|
|
116
|
+
it('handles empty string input', () => {
|
|
117
|
+
const envStr = '';
|
|
118
|
+
const expected = {};
|
|
119
|
+
expect(parseAgentConfig(envStr)).toEqual(expected);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('ignores entries without an equal sign', () => {
|
|
123
|
+
const envStr = 'model=gpt-4;invalidentry';
|
|
124
|
+
const expected = { model: 'gpt-4' };
|
|
125
|
+
expect(parseAgentConfig(envStr)).toEqual(expected);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('handles entries with missing value', () => {
|
|
129
|
+
const envStr = 'model=gpt-4;version=';
|
|
130
|
+
const expected = { model: 'gpt-4', version: undefined };
|
|
131
|
+
expect(parseAgentConfig(envStr)).toEqual(expected);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('handles entries with missing key', () => {
|
|
135
|
+
const envStr = '=gpt-4;version=1.0.0';
|
|
136
|
+
const expected = { version: '1.0.0' }; // Assuming the parser ignores entries with no key
|
|
137
|
+
expect(parseAgentConfig(envStr)).toEqual(expected);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('handles multiple consecutive semicolons', () => {
|
|
141
|
+
const envStr = 'model=gpt-4;;version=1.0.0';
|
|
142
|
+
const expected = { model: 'gpt-4', version: '1.0.0' };
|
|
143
|
+
expect(parseAgentConfig(envStr)).toEqual(expected);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// 测试键重复时的覆盖行为
|
|
147
|
+
it('overrides duplicate keys with the last occurrence', () => {
|
|
148
|
+
const envStr = 'model=gpt-4;model=gpt-4-1106-preview';
|
|
149
|
+
const expected = { model: 'gpt-4-1106-preview' };
|
|
150
|
+
expect(parseAgentConfig(envStr)).toEqual(expected);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// 测试未提供的数组值是否返回空数组
|
|
154
|
+
it('parses missing array values as undefined', () => {
|
|
155
|
+
const envStr = 'plugins=';
|
|
156
|
+
const expected = {};
|
|
157
|
+
expect(parseAgentConfig(envStr)).toEqual(expected);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// 测试值中包含分号的情况
|
|
162
|
+
it('handles values with semicolons correctly', () => {
|
|
163
|
+
const envStr = 'inputTemplate="Hello; I am a bot;"';
|
|
164
|
+
const expected = { inputTemplate: 'Hello; I am a bot;' };
|
|
165
|
+
expect(parseAgentConfig(envStr)).toEqual(expected);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// 测试值中包含等号的情况
|
|
169
|
+
it('handles values with equals signs correctly', () => {
|
|
170
|
+
const envStr = 'inputTemplate="Hello=world"';
|
|
171
|
+
const expected = { inputTemplate: 'Hello=world' };
|
|
172
|
+
expect(parseAgentConfig(envStr)).toEqual(expected);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// 测试空值是否返回undefined或空字符串
|
|
176
|
+
it('parses empty values as undefined or empty string', () => {
|
|
177
|
+
const envStr = 'model=';
|
|
178
|
+
const expected = { model: undefined }; // 或 { model: '' },取决于应用逻辑
|
|
179
|
+
expect(parseAgentConfig(envStr)).toEqual(expected);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { set } from 'lodash-es';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Improved parsing function that handles numbers, booleans, semicolons, and equals signs in values.
|
|
5
|
+
* @param {string} envStr - The environment variable string to be parsed.
|
|
6
|
+
*/
|
|
7
|
+
export const parseAgentConfig = (envStr: string) => {
|
|
8
|
+
const config = {};
|
|
9
|
+
// use regex to match key-value pairs, considering the possibility of semicolons in values
|
|
10
|
+
const regex = /([^;=]+)=("[^"]+"|[^;]+)/g;
|
|
11
|
+
let match;
|
|
12
|
+
|
|
13
|
+
while ((match = regex.exec(envStr)) !== null) {
|
|
14
|
+
const key = match[1].trim();
|
|
15
|
+
let value = match[2].trim();
|
|
16
|
+
if (!key || !value) return;
|
|
17
|
+
|
|
18
|
+
let finalValue: any = value;
|
|
19
|
+
|
|
20
|
+
// Handle string value
|
|
21
|
+
if (value.startsWith('"') && value.endsWith('"')) {
|
|
22
|
+
finalValue = value.slice(1, -1);
|
|
23
|
+
}
|
|
24
|
+
// Handle numeric values
|
|
25
|
+
else if (!isNaN(value as any)) {
|
|
26
|
+
finalValue = Number(value);
|
|
27
|
+
}
|
|
28
|
+
// Handle boolean values
|
|
29
|
+
else if (value.toLowerCase() === 'true' || value.toLowerCase() === 'false') {
|
|
30
|
+
finalValue = value.toLowerCase() === 'true';
|
|
31
|
+
}
|
|
32
|
+
// Handle arrays
|
|
33
|
+
else if (value.includes(',') || value.includes(',')) {
|
|
34
|
+
const array = value.replaceAll(',', ',').split(',');
|
|
35
|
+
finalValue = array.map((item) => (isNaN(item as any) ? item : Number(item)));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
set(config, key, finalValue);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return config;
|
|
42
|
+
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { getServerConfig } from '@/config/server';
|
|
2
2
|
import { GlobalServerConfig } from '@/types/settings';
|
|
3
3
|
|
|
4
|
+
import { parseAgentConfig } from './parseDefaultAgent';
|
|
5
|
+
|
|
4
6
|
export const runtime = 'edge';
|
|
5
7
|
|
|
6
8
|
/**
|
|
@@ -15,10 +17,14 @@ export const GET = async () => {
|
|
|
15
17
|
ENABLED_GOOGLE,
|
|
16
18
|
ENABLE_OAUTH_SSO,
|
|
17
19
|
ENABLE_OLLAMA,
|
|
20
|
+
DEFAULT_AGENT_CONFIG,
|
|
18
21
|
} = getServerConfig();
|
|
19
22
|
|
|
20
23
|
const config: GlobalServerConfig = {
|
|
21
24
|
customModelName: CUSTOM_MODELS,
|
|
25
|
+
defaultAgent: {
|
|
26
|
+
config: parseAgentConfig(DEFAULT_AGENT_CONFIG),
|
|
27
|
+
},
|
|
22
28
|
enabledOAuthSSO: ENABLE_OAUTH_SSO,
|
|
23
29
|
languageModel: {
|
|
24
30
|
bedrock: { enabled: ENABLED_AWS_BEDROCK },
|
package/src/config/server/app.ts
CHANGED
|
@@ -14,6 +14,8 @@ declare global {
|
|
|
14
14
|
|
|
15
15
|
PLUGINS_INDEX_URL?: string;
|
|
16
16
|
PLUGIN_SETTINGS?: string;
|
|
17
|
+
|
|
18
|
+
DEFAULT_AGENT_CONFIG?: string;
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
}
|
|
@@ -32,6 +34,8 @@ export const getAppConfig = () => {
|
|
|
32
34
|
return {
|
|
33
35
|
ACCESS_CODES,
|
|
34
36
|
|
|
37
|
+
DEFAULT_AGENT_CONFIG: process.env.DEFAULT_AGENT_CONFIG || '',
|
|
38
|
+
|
|
35
39
|
SHOW_ACCESS_CODE_CONFIG: !!ACCESS_CODES.length,
|
|
36
40
|
|
|
37
41
|
METADATA_BASE_URL: process.env.METADATA_BASE_URL,
|
|
@@ -5,10 +5,7 @@ import useSWR from 'swr';
|
|
|
5
5
|
|
|
6
6
|
import { createI18nNext } from '@/locales/create';
|
|
7
7
|
import { normalizeLocale } from '@/locales/resources';
|
|
8
|
-
import { useOnFinishHydrationGlobal } from '@/store/global';
|
|
9
|
-
import { settingsSelectors } from '@/store/global/selectors';
|
|
10
8
|
import { isOnServerSide } from '@/utils/env';
|
|
11
|
-
import { switchLang } from '@/utils/switchLang';
|
|
12
9
|
|
|
13
10
|
const getAntdLocale = async (lang?: string) => {
|
|
14
11
|
let normalLang = normalizeLocale(lang);
|
|
@@ -50,12 +47,6 @@ const Locale = memo<LocaleLayoutProps>(({ children, defaultLang }) => {
|
|
|
50
47
|
});
|
|
51
48
|
}
|
|
52
49
|
|
|
53
|
-
useOnFinishHydrationGlobal((s) => {
|
|
54
|
-
if (settingsSelectors.currentSettings(s).language === 'auto') {
|
|
55
|
-
switchLang('auto');
|
|
56
|
-
}
|
|
57
|
-
}, []);
|
|
58
|
-
|
|
59
50
|
// handle i18n instance language change
|
|
60
51
|
useEffect(() => {
|
|
61
52
|
const handleLang = (e: string) => {
|
|
@@ -2,7 +2,8 @@ import { useResponsive } from 'antd-style';
|
|
|
2
2
|
import { useRouter } from 'next/navigation';
|
|
3
3
|
import { memo, useEffect } from 'react';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { useGlobalStore } from '@/store/global';
|
|
6
|
+
import { useEffectAfterGlobalHydrated } from '@/store/global/hooks/useEffectAfterHydrated';
|
|
6
7
|
|
|
7
8
|
const StoreHydration = memo(() => {
|
|
8
9
|
const [useFetchServerConfig, useFetchUserConfig] = useGlobalStore((s) => [
|
|
@@ -12,6 +12,9 @@ import type { GlobalStore } from '@/store/global';
|
|
|
12
12
|
import type { GlobalServerConfig, GlobalSettings } from '@/types/settings';
|
|
13
13
|
import { merge } from '@/utils/merge';
|
|
14
14
|
import { setNamespace } from '@/utils/storeDebug';
|
|
15
|
+
import { switchLang } from '@/utils/switchLang';
|
|
16
|
+
|
|
17
|
+
import { settingsSelectors } from '../settings/selectors';
|
|
15
18
|
|
|
16
19
|
const n = setNamespace('common');
|
|
17
20
|
|
|
@@ -82,6 +85,11 @@ export const createCommonSlice: StateCreator<
|
|
|
82
85
|
if (!data) return;
|
|
83
86
|
|
|
84
87
|
set({ avatar: data.avatar, settings: data.settings }, false, n('fetchUserConfig', data));
|
|
88
|
+
|
|
89
|
+
const { language } = settingsSelectors.currentSettings(get());
|
|
90
|
+
if (language === 'auto') {
|
|
91
|
+
switchLang('auto');
|
|
92
|
+
}
|
|
85
93
|
},
|
|
86
94
|
revalidateOnFocus: false,
|
|
87
95
|
},
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
|
-
|
|
3
|
-
import { GlobalStore, useGlobalStore } from '../store';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 当 Session 水合完毕后才会执行的 useEffect
|
|
7
|
-
* @param fn
|
|
8
|
-
* @param deps
|
|
9
|
-
*/
|
|
10
|
-
export const useOnFinishHydrationGlobal = (fn: (state: GlobalStore) => void, deps: any[] = []) => {
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
useGlobalStore.persist.onFinishHydration(() => {
|
|
13
|
-
fn(useGlobalStore.getState());
|
|
14
|
-
});
|
|
15
|
-
}, deps);
|
|
16
|
-
};
|