@lobehub/chat 0.162.24 → 0.162.25
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/CHANGELOG.md +25 -0
- package/README.md +8 -8
- package/README.zh-CN.md +8 -8
- package/docs/self-hosting/platform/zeabur.mdx +1 -1
- package/docs/self-hosting/platform/zeabur.zh-CN.mdx +1 -1
- package/package.json +2 -2
- package/src/app/(main)/settings/llm/components/ProviderConfig/index.tsx +11 -1
- package/src/app/api/middleware/auth/index.ts +1 -1
- package/src/features/AgentSetting/AgentModal/index.tsx +6 -7
- package/src/store/user/slices/modelList/selectors/keyVaults.test.ts +201 -0
- package/src/store/user/slices/modelList/selectors/keyVaults.ts +15 -3
- package/src/store/user/slices/modelList/selectors/modelConfig.test.ts +29 -1
- package/src/store/user/slices/modelList/selectors/modelConfig.ts +21 -1
- package/src/types/user/settings/keyVaults.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.162.25](https://github.com/lobehub/lobe-chat/compare/v0.162.24...v0.162.25)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2024-06-16**</sup>
|
|
8
|
+
|
|
9
|
+
#### 🐛 Bug Fixes
|
|
10
|
+
|
|
11
|
+
- **misc**: Fix issues for client fetch.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### What's fixed
|
|
19
|
+
|
|
20
|
+
- **misc**: Fix issues for client fetch, closes [#2753](https://github.com/lobehub/lobe-chat/issues/2753) ([6f5be5d](https://github.com/lobehub/lobe-chat/commit/6f5be5d))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
5
30
|
### [Version 0.162.24](https://github.com/lobehub/lobe-chat/compare/v0.162.23...v0.162.24)
|
|
6
31
|
|
|
7
32
|
<sup>Released on **2024-06-14**</sup>
|
package/README.md
CHANGED
|
@@ -263,14 +263,14 @@ Our marketplace is not just a showcase platform but also a collaborative space.
|
|
|
263
263
|
|
|
264
264
|
<!-- AGENT LIST -->
|
|
265
265
|
|
|
266
|
-
| Recent Submits
|
|
267
|
-
|
|
|
268
|
-
| [
|
|
269
|
-
| [
|
|
270
|
-
| [
|
|
271
|
-
| [
|
|
272
|
-
|
|
273
|
-
> 📊 Total agents: [<kbd>**
|
|
266
|
+
| Recent Submits | Description |
|
|
267
|
+
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
268
|
+
| [Pseudo Code Prompt Word Generator Expert](https://chat-preview.lobehub.com/market?agent=pseudocode-prompt-master)<br/><sup>By **[yayoinoyume](https://github.com/yayoinoyume)** on **2024-06-16**</sup> | Pseudo Code Prompt Word Generator Expert allows users to directly input prompt word design requirements and returns designed pseudo code prompt words directly.<br/>`prompt` `prompt-word` `pseudo-code` |
|
|
269
|
+
| [Mr. MySQL](https://chat-preview.lobehub.com/market?agent=mysql-haoteacher)<br/><sup>By **[yayoinoyume](https://github.com/yayoinoyume)** on **2024-06-09**</sup> | Mr. MySQL is a great teacher to help everyone learn MySQL<br/>`mysql` `programming` `learning` |
|
|
270
|
+
| [Popular Science Writing Assistant](https://chat-preview.lobehub.com/market?agent=popular-science-writer)<br/><sup>By **[ShinChven](https://github.com/ShinChven)** on **2024-06-08**</sup> | The popular science writing assistant uses everyday language to explain scientific concepts, tells stories, uses examples and metaphors to spark interest, and emphasizes importance.<br/>`science-writing` `science-popularization` `creative-expression` |
|
|
271
|
+
| [Expert Response to Reviewer](https://chat-preview.lobehub.com/market?agent=academic-editor-en)<br/><sup>By **[Starlitnightly](https://github.com/Starlitnightly)** on **2024-06-03**</sup> | Specializing in natural academic editing, assisting authors in responding to reviewer comments in a scientific, courteous, and point-by-point manner.<br/>`academic-editing` `response-to-reviewer-comments` `scientific-writing` |
|
|
272
|
+
|
|
273
|
+
> 📊 Total agents: [<kbd>**288**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
|
|
274
274
|
|
|
275
275
|
<!-- AGENT LIST -->
|
|
276
276
|
|
package/README.zh-CN.md
CHANGED
|
@@ -251,14 +251,14 @@ LobeChat 的插件生态系统是其核心功能的重要扩展,它极大地
|
|
|
251
251
|
|
|
252
252
|
<!-- AGENT LIST -->
|
|
253
253
|
|
|
254
|
-
| 最近新增
|
|
255
|
-
|
|
|
256
|
-
| [
|
|
257
|
-
| [
|
|
258
|
-
| [
|
|
259
|
-
| [
|
|
260
|
-
|
|
261
|
-
> 📊 Total agents: [<kbd>**
|
|
254
|
+
| 最近新增 | 助手说明 |
|
|
255
|
+
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------- |
|
|
256
|
+
| [伪代码提示词生成专家](https://chat-preview.lobehub.com/market?agent=pseudocode-prompt-master)<br/><sup>By **[yayoinoyume](https://github.com/yayoinoyume)** on **2024-06-16**</sup> | 伪代码提示词生成专家,用户直接输入提示词设计需求,直接返还设计的伪代码提示词<br/>`prompt` `提示词` `伪代码` |
|
|
257
|
+
| [Mysql 好先生](https://chat-preview.lobehub.com/market?agent=mysql-haoteacher)<br/><sup>By **[yayoinoyume](https://github.com/yayoinoyume)** on **2024-06-09**</sup> | mysql 好先生是帮助所有人学习 mysql 的好老师<br/>`mysql` `编程` `学习` |
|
|
258
|
+
| [通俗科普创作助手](https://chat-preview.lobehub.com/market?agent=popular-science-writer)<br/><sup>By **[ShinChven](https://github.com/ShinChven)** on **2024-06-08**</sup> | 通俗科普创作助手,用生活化语言讲科学概念,讲故事、使用例子和比喻,激发兴趣,强调重要性。<br/>`科普写作` `科学普及` `创意表达` |
|
|
259
|
+
| [审稿回复专家](https://chat-preview.lobehub.com/market?agent=academic-editor-en)<br/><sup>By **[Starlitnightly](https://github.com/Starlitnightly)** on **2024-06-03**</sup> | 擅长自然学术编辑,协助作者回复审稿人意见,科学、礼貌、逐点回应。<br/>`学术编辑` `审稿意见回复` `科学写作` |
|
|
260
|
+
|
|
261
|
+
> 📊 Total agents: [<kbd>**288**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
|
|
262
262
|
|
|
263
263
|
<!-- AGENT LIST -->
|
|
264
264
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/chat",
|
|
3
|
-
"version": "0.162.
|
|
3
|
+
"version": "0.162.25",
|
|
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",
|
|
@@ -170,7 +170,7 @@
|
|
|
170
170
|
"url-join": "^5.0.0",
|
|
171
171
|
"use-merge-value": "^1.2.0",
|
|
172
172
|
"utility-types": "^3.11.0",
|
|
173
|
-
"uuid": "^
|
|
173
|
+
"uuid": "^10.0.0",
|
|
174
174
|
"y-protocols": "^1.0.6",
|
|
175
175
|
"y-webrtc": "^10.3.0",
|
|
176
176
|
"yaml": "^2.4.2",
|
|
@@ -87,12 +87,14 @@ const ProviderConfig = memo<ProviderConfigProps>(
|
|
|
87
87
|
enabled,
|
|
88
88
|
isFetchOnClient,
|
|
89
89
|
isProviderEndpointNotEmpty,
|
|
90
|
+
isProviderApiKeyNotEmpty,
|
|
90
91
|
] = useUserStore((s) => [
|
|
91
92
|
s.toggleProviderEnabled,
|
|
92
93
|
s.setSettings,
|
|
93
94
|
modelConfigSelectors.isProviderEnabled(id)(s),
|
|
94
95
|
modelConfigSelectors.isProviderFetchOnClient(id)(s),
|
|
95
96
|
keyVaultsConfigSelectors.isProviderEndpointNotEmpty(id)(s),
|
|
97
|
+
keyVaultsConfigSelectors.isProviderApiKeyNotEmpty(id)(s),
|
|
96
98
|
]);
|
|
97
99
|
|
|
98
100
|
useSyncSettings(form);
|
|
@@ -122,7 +124,15 @@ const ProviderConfig = memo<ProviderConfigProps>(
|
|
|
122
124
|
label: proxyUrl?.title || t('llm.proxyUrl.title'),
|
|
123
125
|
name: [KeyVaultsConfigKey, id, LLMProviderBaseUrlKey],
|
|
124
126
|
},
|
|
125
|
-
|
|
127
|
+
/*
|
|
128
|
+
* Conditions to show Client Fetch Switch
|
|
129
|
+
* 1. Component props
|
|
130
|
+
* 2. Provider allow to edit endpoint and the value of endpoint is not empty
|
|
131
|
+
* 3. There is an apikey provided by user
|
|
132
|
+
*/
|
|
133
|
+
(showBrowserRequest ||
|
|
134
|
+
(showEndpoint && isProviderEndpointNotEmpty) ||
|
|
135
|
+
(showApiKey && isProviderApiKeyNotEmpty)) && {
|
|
126
136
|
children: (
|
|
127
137
|
<Switch
|
|
128
138
|
onChange={(enabled) => {
|
|
@@ -10,7 +10,7 @@ import { ChatErrorType } from '@/types/fetch';
|
|
|
10
10
|
import { checkAuthMethod, getJWTPayload } from './utils';
|
|
11
11
|
|
|
12
12
|
type CreateRuntime = (jwtPayload: JWTPayload) => AgentRuntime;
|
|
13
|
-
type RequestOptions = { createRuntime?: CreateRuntime
|
|
13
|
+
type RequestOptions = { createRuntime?: CreateRuntime; params: { provider: string } };
|
|
14
14
|
|
|
15
15
|
export type RequestHandler = (
|
|
16
16
|
req: Request,
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import { Form, ItemGroup, SliderWithInput } from '@lobehub/ui';
|
|
4
4
|
import { Switch } from 'antd';
|
|
5
|
-
import { debounce } from 'lodash-es';
|
|
6
5
|
import { memo } from 'react';
|
|
7
6
|
import { useTranslation } from 'react-i18next';
|
|
8
7
|
|
|
@@ -17,10 +16,10 @@ const AgentModal = memo(() => {
|
|
|
17
16
|
const { t } = useTranslation('setting');
|
|
18
17
|
const [form] = Form.useForm();
|
|
19
18
|
|
|
20
|
-
const [enableMaxTokens, updateConfig] = useStore((s) =>
|
|
21
|
-
selectors.chatConfig(s)
|
|
22
|
-
s.setAgentConfig
|
|
23
|
-
|
|
19
|
+
const [enableMaxTokens, updateConfig] = useStore((s) => {
|
|
20
|
+
const config = selectors.chatConfig(s);
|
|
21
|
+
return [config.enableMaxTokens, s.setAgentConfig];
|
|
22
|
+
});
|
|
24
23
|
|
|
25
24
|
useAgentSyncSettings(form);
|
|
26
25
|
|
|
@@ -65,7 +64,7 @@ const AgentModal = memo(() => {
|
|
|
65
64
|
children: <Switch />,
|
|
66
65
|
label: t('settingModel.enableMaxTokens.title'),
|
|
67
66
|
minWidth: undefined,
|
|
68
|
-
name: 'enableMaxTokens',
|
|
67
|
+
name: ['chatConfig', 'enableMaxTokens'],
|
|
69
68
|
valuePropName: 'checked',
|
|
70
69
|
},
|
|
71
70
|
{
|
|
@@ -86,7 +85,7 @@ const AgentModal = memo(() => {
|
|
|
86
85
|
form={form}
|
|
87
86
|
items={[model]}
|
|
88
87
|
itemsType={'group'}
|
|
89
|
-
onValuesChange={
|
|
88
|
+
onValuesChange={updateConfig}
|
|
90
89
|
variant={'pure'}
|
|
91
90
|
{...FORM_STYLE}
|
|
92
91
|
/>
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { UserStore } from '@/store/user';
|
|
4
|
+
import {
|
|
5
|
+
AWSBedrockKeyVault,
|
|
6
|
+
AzureOpenAIKeyVault,
|
|
7
|
+
OpenAICompatibleKeyVault,
|
|
8
|
+
} from '@/types/user/settings';
|
|
9
|
+
import { merge } from '@/utils/merge';
|
|
10
|
+
|
|
11
|
+
import { initialSettingsState } from '../../settings/initialState';
|
|
12
|
+
import { keyVaultsConfigSelectors } from './keyVaults';
|
|
13
|
+
|
|
14
|
+
describe('keyVaultsConfigSelectors', () => {
|
|
15
|
+
describe('isProviderEndpointNotEmpty', () => {
|
|
16
|
+
describe('OpenAICompatibleKeyVault', () => {
|
|
17
|
+
it('should return true if provider endpoint is not empty', () => {
|
|
18
|
+
const s = merge(initialSettingsState, {
|
|
19
|
+
settings: {
|
|
20
|
+
keyVaults: {
|
|
21
|
+
openai: {
|
|
22
|
+
endpoint: 'endpoint',
|
|
23
|
+
} as OpenAICompatibleKeyVault,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
}) as unknown as UserStore;
|
|
27
|
+
expect(keyVaultsConfigSelectors.isProviderEndpointNotEmpty('openai')(s)).toBe(true);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should return false if provider endpoint is empty', () => {
|
|
31
|
+
const s = merge(initialSettingsState, {
|
|
32
|
+
settings: {
|
|
33
|
+
keyVaults: {
|
|
34
|
+
openai: {
|
|
35
|
+
endpoint: undefined,
|
|
36
|
+
} as OpenAICompatibleKeyVault,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
}) as unknown as UserStore;
|
|
40
|
+
expect(keyVaultsConfigSelectors.isProviderEndpointNotEmpty('openai')(s)).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('AzureOpenAIKeyVault', () => {
|
|
45
|
+
it('should return true if provider endpoint is not empty', () => {
|
|
46
|
+
const s = merge(initialSettingsState, {
|
|
47
|
+
settings: {
|
|
48
|
+
keyVaults: {
|
|
49
|
+
azure: {
|
|
50
|
+
baseURL: 'baseURL',
|
|
51
|
+
} as AzureOpenAIKeyVault,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
}) as unknown as UserStore;
|
|
55
|
+
expect(keyVaultsConfigSelectors.isProviderEndpointNotEmpty('azure')(s)).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should return false if provider endpoint is empty', () => {
|
|
59
|
+
const s = merge(initialSettingsState, {
|
|
60
|
+
settings: {
|
|
61
|
+
keyVaults: {
|
|
62
|
+
azure: {
|
|
63
|
+
baseURL: undefined,
|
|
64
|
+
} as AzureOpenAIKeyVault,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
}) as unknown as UserStore;
|
|
68
|
+
expect(keyVaultsConfigSelectors.isProviderEndpointNotEmpty('azure')(s)).toBe(false);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Always return false for AWSBedrockKeyVault
|
|
73
|
+
describe('AWSBedrockKeyVault', () => {
|
|
74
|
+
it('should return false if provider region is not empty for AWSBedrockKeyVault', () => {
|
|
75
|
+
const s = merge(initialSettingsState, {
|
|
76
|
+
settings: {
|
|
77
|
+
keyVaults: {
|
|
78
|
+
bedrock: {
|
|
79
|
+
region: 'region',
|
|
80
|
+
} as AWSBedrockKeyVault,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
}) as unknown as UserStore;
|
|
84
|
+
expect(keyVaultsConfigSelectors.isProviderEndpointNotEmpty('bedrock')(s)).toBe(false);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should return false if provider region is empty for AWSBedrockKeyVault', () => {
|
|
88
|
+
const s = merge(initialSettingsState, {
|
|
89
|
+
settings: {
|
|
90
|
+
keyVaults: {
|
|
91
|
+
bedrock: {
|
|
92
|
+
region: undefined,
|
|
93
|
+
} as AWSBedrockKeyVault,
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
}) as unknown as UserStore;
|
|
97
|
+
expect(keyVaultsConfigSelectors.isProviderEndpointNotEmpty('bedrock')(s)).toBe(false);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('isProviderApiKeyNotEmpty', () => {
|
|
103
|
+
describe('OpenAICompatibleKeyVault', () => {
|
|
104
|
+
it('should return true if provider apikey is not empty', () => {
|
|
105
|
+
const s = merge(initialSettingsState, {
|
|
106
|
+
settings: {
|
|
107
|
+
keyVaults: {
|
|
108
|
+
openai: {
|
|
109
|
+
apiKey: 'apikey',
|
|
110
|
+
} as OpenAICompatibleKeyVault,
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
}) as unknown as UserStore;
|
|
114
|
+
expect(keyVaultsConfigSelectors.isProviderApiKeyNotEmpty('openai')(s)).toBe(true);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('should return false if provider apikey is empty', () => {
|
|
118
|
+
const s = merge(initialSettingsState, {
|
|
119
|
+
settings: {
|
|
120
|
+
keyVaults: {
|
|
121
|
+
openai: {
|
|
122
|
+
apiKey: undefined,
|
|
123
|
+
} as OpenAICompatibleKeyVault,
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
}) as unknown as UserStore;
|
|
127
|
+
expect(keyVaultsConfigSelectors.isProviderApiKeyNotEmpty('openai')(s)).toBe(false);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe('AzureOpenAIKeyVault', () => {
|
|
132
|
+
it('should return true if provider apikey is not empty', () => {
|
|
133
|
+
const s = merge(initialSettingsState, {
|
|
134
|
+
settings: {
|
|
135
|
+
keyVaults: {
|
|
136
|
+
azure: {
|
|
137
|
+
apiKey: 'apikey',
|
|
138
|
+
} as AzureOpenAIKeyVault,
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
}) as unknown as UserStore;
|
|
142
|
+
expect(keyVaultsConfigSelectors.isProviderApiKeyNotEmpty('azure')(s)).toBe(true);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('should return false if provider apikey is empty', () => {
|
|
146
|
+
const s = merge(initialSettingsState, {
|
|
147
|
+
settings: {
|
|
148
|
+
keyVaults: {
|
|
149
|
+
azure: {
|
|
150
|
+
apiKey: undefined,
|
|
151
|
+
} as AzureOpenAIKeyVault,
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
}) as unknown as UserStore;
|
|
155
|
+
expect(keyVaultsConfigSelectors.isProviderApiKeyNotEmpty('azure')(s)).toBe(false);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
describe('AWSBedrockKeyVault', () => {
|
|
160
|
+
it('should return true if provider accessKeyId is not empty for AWSBedrockKeyVault', () => {
|
|
161
|
+
const s = merge(initialSettingsState, {
|
|
162
|
+
settings: {
|
|
163
|
+
keyVaults: {
|
|
164
|
+
bedrock: {
|
|
165
|
+
accessKeyId: 'accessKeyId',
|
|
166
|
+
} as AWSBedrockKeyVault,
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
}) as unknown as UserStore;
|
|
170
|
+
expect(keyVaultsConfigSelectors.isProviderApiKeyNotEmpty('bedrock')(s)).toBe(true);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('should return true if provider secretAccessKey is not empty for AWSBedrockKeyVault', () => {
|
|
174
|
+
const s = merge(initialSettingsState, {
|
|
175
|
+
settings: {
|
|
176
|
+
keyVaults: {
|
|
177
|
+
bedrock: {
|
|
178
|
+
secretAccessKey: 'secretAccessKey',
|
|
179
|
+
} as AWSBedrockKeyVault,
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
}) as unknown as UserStore;
|
|
183
|
+
expect(keyVaultsConfigSelectors.isProviderApiKeyNotEmpty('bedrock')(s)).toBe(true);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('should return false if provider accessKeyId and secretAccessKey are both empty for AWSBedrockKeyVault', () => {
|
|
187
|
+
const s = merge(initialSettingsState, {
|
|
188
|
+
settings: {
|
|
189
|
+
keyVaults: {
|
|
190
|
+
bedrock: {
|
|
191
|
+
accessKeyId: undefined,
|
|
192
|
+
secretAccessKey: undefined,
|
|
193
|
+
} as AWSBedrockKeyVault,
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
}) as unknown as UserStore;
|
|
197
|
+
expect(keyVaultsConfigSelectors.isProviderApiKeyNotEmpty('bedrock')(s)).toBe(false);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
});
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { UserStore } from '@/store/user';
|
|
2
2
|
import {
|
|
3
|
+
AWSBedrockKeyVault,
|
|
4
|
+
AzureOpenAIKeyVault,
|
|
3
5
|
GlobalLLMProviderKey,
|
|
4
6
|
OpenAICompatibleKeyVault,
|
|
5
7
|
UserKeyVaults,
|
|
@@ -15,10 +17,19 @@ const bedrockConfig = (s: UserStore) => keyVaultsSettings(s).bedrock || {};
|
|
|
15
17
|
const ollamaConfig = (s: UserStore) => keyVaultsSettings(s).ollama || {};
|
|
16
18
|
const azureConfig = (s: UserStore) => keyVaultsSettings(s).azure || {};
|
|
17
19
|
const getVaultByProvider = (provider: GlobalLLMProviderKey) => (s: UserStore) =>
|
|
18
|
-
(keyVaultsSettings(s)[provider] || {}) as OpenAICompatibleKeyVault
|
|
20
|
+
(keyVaultsSettings(s)[provider] || {}) as OpenAICompatibleKeyVault &
|
|
21
|
+
AzureOpenAIKeyVault &
|
|
22
|
+
AWSBedrockKeyVault;
|
|
19
23
|
|
|
20
|
-
const isProviderEndpointNotEmpty = (provider: string) => (s: UserStore) =>
|
|
21
|
-
|
|
24
|
+
const isProviderEndpointNotEmpty = (provider: string) => (s: UserStore) => {
|
|
25
|
+
const vault = getVaultByProvider(provider as GlobalLLMProviderKey)(s);
|
|
26
|
+
return !!vault?.baseURL || !!vault?.endpoint;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const isProviderApiKeyNotEmpty = (provider: string) => (s: UserStore) => {
|
|
30
|
+
const vault = getVaultByProvider(provider as GlobalLLMProviderKey)(s);
|
|
31
|
+
return !!vault?.apiKey || !!vault?.accessKeyId || !!vault?.secretAccessKey;
|
|
32
|
+
};
|
|
22
33
|
|
|
23
34
|
const password = (s: UserStore) => keyVaultsSettings(s).password || '';
|
|
24
35
|
|
|
@@ -26,6 +37,7 @@ export const keyVaultsConfigSelectors = {
|
|
|
26
37
|
azureConfig,
|
|
27
38
|
bedrockConfig,
|
|
28
39
|
getVaultByProvider,
|
|
40
|
+
isProviderApiKeyNotEmpty,
|
|
29
41
|
isProviderEndpointNotEmpty,
|
|
30
42
|
ollamaConfig,
|
|
31
43
|
openAIConfig,
|
|
@@ -35,6 +35,7 @@ describe('modelConfigSelectors', () => {
|
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
describe('isProviderFetchOnClient', () => {
|
|
38
|
+
// The next 4 case are base on the rules on https://github.com/lobehub/lobe-chat/pull/2753
|
|
38
39
|
it('client fetch should disabled on default', () => {
|
|
39
40
|
const s = merge(initialSettingsState, {
|
|
40
41
|
settings: {
|
|
@@ -46,16 +47,43 @@ describe('modelConfigSelectors', () => {
|
|
|
46
47
|
},
|
|
47
48
|
},
|
|
48
49
|
} as UserSettingsState) as unknown as UserStore;
|
|
50
|
+
expect(modelConfigSelectors.isProviderFetchOnClient('azure')(s)).toBe(false);
|
|
51
|
+
});
|
|
49
52
|
|
|
53
|
+
it('client fetch should disabled if no apikey or endpoint provided even user set it enabled', () => {
|
|
54
|
+
const s = merge(initialSettingsState, {
|
|
55
|
+
settings: {
|
|
56
|
+
languageModel: {
|
|
57
|
+
azure: { fetchOnClient: true },
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
} as UserSettingsState) as unknown as UserStore;
|
|
50
61
|
expect(modelConfigSelectors.isProviderFetchOnClient('azure')(s)).toBe(false);
|
|
51
62
|
});
|
|
52
63
|
|
|
53
|
-
it('client fetch should
|
|
64
|
+
it('client fetch should enable if only endpoint provided', () => {
|
|
65
|
+
const s = merge(initialSettingsState, {
|
|
66
|
+
settings: {
|
|
67
|
+
languageModel: {
|
|
68
|
+
azure: { fetchOnClient: false },
|
|
69
|
+
},
|
|
70
|
+
keyVaults: {
|
|
71
|
+
azure: { endpoint: 'https://example.com' },
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
} as UserSettingsState) as unknown as UserStore;
|
|
75
|
+
expect(modelConfigSelectors.isProviderFetchOnClient('azure')(s)).toBe(true);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('client fetch should control by user when a apikey or endpoint provided', () => {
|
|
54
79
|
const s = merge(initialSettingsState, {
|
|
55
80
|
settings: {
|
|
56
81
|
languageModel: {
|
|
57
82
|
azure: { fetchOnClient: true },
|
|
58
83
|
},
|
|
84
|
+
keyVaults: {
|
|
85
|
+
azure: { apiKey: 'some-key' },
|
|
86
|
+
},
|
|
59
87
|
},
|
|
60
88
|
} as UserSettingsState) as unknown as UserStore;
|
|
61
89
|
expect(modelConfigSelectors.isProviderFetchOnClient('azure')(s)).toBe(true);
|
|
@@ -1,15 +1,35 @@
|
|
|
1
|
+
import { UserStore } from '@/store/user';
|
|
1
2
|
import { GlobalLLMProviderKey } from '@/types/user/settings';
|
|
2
3
|
|
|
3
|
-
import { UserStore } from '../../../store';
|
|
4
4
|
import { currentLLMSettings, getProviderConfigById } from '../../settings/selectors/settings';
|
|
5
|
+
import { keyVaultsConfigSelectors } from './keyVaults';
|
|
5
6
|
|
|
6
7
|
const isProviderEnabled = (provider: GlobalLLMProviderKey) => (s: UserStore) =>
|
|
7
8
|
getProviderConfigById(provider)(s)?.enabled || false;
|
|
8
9
|
|
|
10
|
+
/**
|
|
11
|
+
* @description The conditions to enable client fetch
|
|
12
|
+
* 1. If no baseUrl and apikey input, force on Server.
|
|
13
|
+
* 2. If only contains baseUrl, force on Client
|
|
14
|
+
* 3. Follow the user settings.
|
|
15
|
+
* 4. On Server, by default.
|
|
16
|
+
*/
|
|
9
17
|
const isProviderFetchOnClient = (provider: GlobalLLMProviderKey | string) => (s: UserStore) => {
|
|
10
18
|
const config = getProviderConfigById(provider)(s);
|
|
19
|
+
|
|
20
|
+
// 1. If no baseUrl and apikey input, force on Server.
|
|
21
|
+
const isProviderEndpointNotEmpty =
|
|
22
|
+
keyVaultsConfigSelectors.isProviderEndpointNotEmpty(provider)(s);
|
|
23
|
+
const isProviderApiKeyNotEmpty = keyVaultsConfigSelectors.isProviderApiKeyNotEmpty(provider)(s);
|
|
24
|
+
if (!isProviderEndpointNotEmpty && !isProviderApiKeyNotEmpty) return false;
|
|
25
|
+
|
|
26
|
+
// 2. If only contains baseUrl, force on Client
|
|
27
|
+
if (isProviderEndpointNotEmpty && !isProviderApiKeyNotEmpty) return true;
|
|
28
|
+
|
|
29
|
+
// 3. Follow the user settings.
|
|
11
30
|
if (typeof config?.fetchOnClient !== 'undefined') return config?.fetchOnClient;
|
|
12
31
|
|
|
32
|
+
// 4. On Server, by default.
|
|
13
33
|
return false;
|
|
14
34
|
};
|
|
15
35
|
|