@lobehub/chat 0.122.3 → 0.122.5

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 CHANGED
@@ -2,6 +2,56 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 0.122.5](https://github.com/lobehub/lobe-chat/compare/v0.122.4...v0.122.5)
6
+
7
+ <sup>Released on **2024-01-31**</sup>
8
+
9
+ #### 🐛 Bug Fixes
10
+
11
+ - **misc**: The plugin has a hallucination and gets stuck.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's fixed
19
+
20
+ - **misc**: The plugin has a hallucination and gets stuck, closes [#1191](https://github.com/lobehub/lobe-chat/issues/1191) ([0189759](https://github.com/lobehub/lobe-chat/commit/0189759))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
30
+ ### [Version 0.122.4](https://github.com/lobehub/lobe-chat/compare/v0.122.3...v0.122.4)
31
+
32
+ <sup>Released on **2024-01-30**</sup>
33
+
34
+ #### 🐛 Bug Fixes
35
+
36
+ - **misc**: Fix plugin gateway auth.
37
+
38
+ <br/>
39
+
40
+ <details>
41
+ <summary><kbd>Improvements and Fixes</kbd></summary>
42
+
43
+ #### What's fixed
44
+
45
+ - **misc**: Fix plugin gateway auth, closes [#1195](https://github.com/lobehub/lobe-chat/issues/1195) ([2184167](https://github.com/lobehub/lobe-chat/commit/2184167))
46
+
47
+ </details>
48
+
49
+ <div align="right">
50
+
51
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
52
+
53
+ </div>
54
+
5
55
  ### [Version 0.122.3](https://github.com/lobehub/lobe-chat/compare/v0.122.2...v0.122.3)
6
56
 
7
57
  <sup>Released on **2024-01-30**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.122.3",
3
+ "version": "0.122.5",
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",
@@ -4,7 +4,7 @@ import OpenAI from 'openai';
4
4
  import { ChatErrorType } from '@/types/fetch';
5
5
  import { OpenAIChatStreamPayload } from '@/types/openai/chat';
6
6
 
7
- import { createErrorResponse } from '../errorResponse';
7
+ import { createErrorResponse } from '../../errorResponse';
8
8
  import { desensitizeUrl } from './desensitizeUrl';
9
9
 
10
10
  interface CreateChatCompletionOptions {
@@ -5,7 +5,7 @@ import { getServerConfig } from '@/config/server';
5
5
  import { getOpenAIAuthFromRequest } from '@/const/fetch';
6
6
  import { ChatErrorType, ErrorType } from '@/types/fetch';
7
7
 
8
- import { createErrorResponse } from '../errorResponse';
8
+ import { createErrorResponse } from '../../errorResponse';
9
9
  import { createAzureOpenai } from './createAzureOpenai';
10
10
  import { createOpenai } from './createOpenai';
11
11
 
@@ -1,13 +1,39 @@
1
1
  import { createGatewayOnEdgeRuntime } from '@lobehub/chat-plugins-gateway';
2
2
 
3
- import { parserPluginSettings } from '@/app/api/plugin/gateway/settings';
3
+ import { createErrorResponse } from '@/app/api/errorResponse';
4
4
  import { getServerConfig } from '@/config/server';
5
+ import { getOpenAIAuthFromRequest } from '@/const/fetch';
6
+ import { ChatErrorType, ErrorType } from '@/types/fetch';
7
+
8
+ import { parserPluginSettings } from './settings';
9
+
10
+ const checkAuth = (accessCode: string | null) => {
11
+ const { ACCESS_CODES } = getServerConfig();
12
+
13
+ // if accessCode doesn't exist
14
+ if (!ACCESS_CODES.length) return { auth: true };
15
+
16
+ if (!accessCode || !ACCESS_CODES.includes(accessCode)) {
17
+ return { auth: false, error: ChatErrorType.InvalidAccessCode };
18
+ }
19
+
20
+ return { auth: true };
21
+ };
5
22
 
6
23
  const { PLUGINS_INDEX_URL: pluginsIndexUrl, PLUGIN_SETTINGS } = getServerConfig();
7
24
 
8
25
  const defaultPluginSettings = parserPluginSettings(PLUGIN_SETTINGS);
9
26
 
10
- export const POST = createGatewayOnEdgeRuntime({
11
- defaultPluginSettings,
12
- pluginsIndexUrl,
13
- });
27
+ const handler = createGatewayOnEdgeRuntime({ defaultPluginSettings, pluginsIndexUrl });
28
+
29
+ export const POST = async (req: Request) => {
30
+ const { accessCode } = getOpenAIAuthFromRequest(req);
31
+
32
+ const result = checkAuth(accessCode);
33
+
34
+ if (!result.auth) {
35
+ return createErrorResponse(result.error as ErrorType);
36
+ }
37
+
38
+ return handler(req);
39
+ };
@@ -27,7 +27,7 @@ const SettingButton = memo<{ mobile?: boolean }>(({ mobile }) => {
27
27
  });
28
28
  router.push('/settings/agent');
29
29
  } else {
30
- router.push(pathString('/chat/settings', { hash: location.hash }));
30
+ router.push(pathString('/chat/settings', { search: location.search }));
31
31
  }
32
32
  }}
33
33
  size={mobile ? MOBILE_HEADER_ICON_SIZE : DESKTOP_HEADER_ICON_SIZE}
@@ -3,6 +3,7 @@
3
3
  import dynamic from 'next/dynamic';
4
4
  import { FC, memo } from 'react';
5
5
 
6
+ import SessionHydration from '@/app/chat/components/SessionHydration';
6
7
  import ResponsiveIndex from '@/components/ResponsiveIndex';
7
8
 
8
9
  import EditPage from '../features/EditPage';
@@ -11,11 +12,14 @@ import Layout from './layout.desktop';
11
12
  const Mobile: FC = dynamic(() => import('../(mobile)'), { ssr: false }) as FC;
12
13
 
13
14
  const ChatSettings = memo(() => (
14
- <ResponsiveIndex Mobile={Mobile}>
15
- <Layout>
16
- <EditPage />
17
- </Layout>
18
- </ResponsiveIndex>
15
+ <>
16
+ <ResponsiveIndex Mobile={Mobile}>
17
+ <Layout>
18
+ <EditPage />
19
+ </Layout>
20
+ </ResponsiveIndex>
21
+ <SessionHydration />
22
+ </>
19
23
  ));
20
24
 
21
25
  export default ChatSettings;
@@ -91,7 +91,8 @@ class ChatService {
91
91
 
92
92
  const res = await fetch(gatewayURL ?? PLUGINS_URLS.gateway, {
93
93
  body: JSON.stringify({ ...params, manifest }),
94
- headers: createHeadersWithPluginSettings(settings),
94
+ // TODO: we can have a better auth way
95
+ headers: createHeadersWithPluginSettings(settings, createHeaderWithOpenAI()),
95
96
  method: 'POST',
96
97
  signal: options?.signal,
97
98
  });
@@ -177,6 +177,8 @@ export const chatPlugin: StateCreator<
177
177
  invokeStandaloneTypePlugin,
178
178
  invokeBuiltinTool,
179
179
  refreshMessages,
180
+ resendMessage,
181
+ deleteMessage,
180
182
  } = get();
181
183
 
182
184
  let payload = { apiName: '', identifier: '' } as ChatPluginPayload;
@@ -199,6 +201,13 @@ export const chatPlugin: StateCreator<
199
201
  type: (type ?? 'default') as any,
200
202
  };
201
203
 
204
+ // fix https://github.com/lobehub/lobe-chat/issues/1094, remove and retry after experiencing plugin illusion
205
+ if (!apiName) {
206
+ resendMessage(id);
207
+ deleteMessage(id);
208
+ return;
209
+ }
210
+
202
211
  // if the apiName is md5, try to find the correct apiName in the plugins
203
212
  if (apiName.startsWith(PLUGIN_SCHEMA_API_MD5_PREFIX)) {
204
213
  const md5 = apiName.replace(PLUGIN_SCHEMA_API_MD5_PREFIX, '');
@@ -1,246 +0,0 @@
1
- // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
-
3
- exports[`settingsSelectors > CUSTOM_MODELS > custom deletion, addition, and renaming of models 1`] = `
4
- [
5
- {
6
- "displayName": "llama",
7
- "name": "llama",
8
- },
9
- {
10
- "displayName": "claude-2",
11
- "name": "claude-2",
12
- },
13
- {
14
- "displayName": "gpt-4-32k",
15
- "name": "gpt-4-1106-preview",
16
- },
17
- ]
18
- `;
19
-
20
- exports[`settingsSelectors > CUSTOM_MODELS > duplicate naming model 1`] = `
21
- [
22
- {
23
- "displayName": "gpt-3.5-turbo",
24
- "name": "gpt-3.5-turbo",
25
- },
26
- {
27
- "displayName": "gpt-3.5-turbo-1106",
28
- "name": "gpt-3.5-turbo-1106",
29
- },
30
- {
31
- "displayName": "gpt-3.5-turbo-16k",
32
- "name": "gpt-3.5-turbo-16k",
33
- },
34
- {
35
- "displayName": "gpt-4",
36
- "name": "gpt-4",
37
- },
38
- {
39
- "displayName": "gpt-4-32k",
40
- "name": "gpt-4-32k",
41
- },
42
- {
43
- "displayName": "gpt-4-vision-preview",
44
- "name": "gpt-4-vision-preview",
45
- },
46
- {
47
- "displayName": "gpt-4-32k",
48
- "name": "gpt-4-1106-preview",
49
- },
50
- ]
51
- `;
52
-
53
- exports[`settingsSelectors > CUSTOM_MODELS > only add the model 1`] = `
54
- [
55
- {
56
- "displayName": "gpt-3.5-turbo",
57
- "name": "gpt-3.5-turbo",
58
- },
59
- {
60
- "displayName": "gpt-3.5-turbo-1106",
61
- "name": "gpt-3.5-turbo-1106",
62
- },
63
- {
64
- "displayName": "gpt-3.5-turbo-16k",
65
- "name": "gpt-3.5-turbo-16k",
66
- },
67
- {
68
- "displayName": "gpt-4",
69
- "name": "gpt-4",
70
- },
71
- {
72
- "displayName": "gpt-4-32k",
73
- "name": "gpt-4-32k",
74
- },
75
- {
76
- "displayName": "gpt-4-1106-preview",
77
- "name": "gpt-4-1106-preview",
78
- },
79
- {
80
- "displayName": "gpt-4-vision-preview",
81
- "name": "gpt-4-vision-preview",
82
- },
83
- {
84
- "displayName": "model1",
85
- "name": "model1",
86
- },
87
- {
88
- "displayName": "model2",
89
- "name": "model2",
90
- },
91
- {
92
- "displayName": "model3",
93
- "name": "model3",
94
- },
95
- {
96
- "displayName": "model4",
97
- "name": "model4",
98
- },
99
- ]
100
- `;
101
-
102
- exports[`settingsSelectors > currentSettings > should merge DEFAULT_SETTINGS and s.settings correctly 1`] = `
103
- {
104
- "avatar": "avatar.jpg",
105
- "defaultAgent": {
106
- "config": {
107
- "autoCreateTopicThreshold": 2,
108
- "displayMode": "chat",
109
- "enableAutoCreateTopic": true,
110
- "historyCount": 1,
111
- "model": "gpt-3.5-turbo",
112
- "params": {
113
- "frequency_penalty": 0,
114
- "presence_penalty": 0,
115
- "temperature": 0.6,
116
- "top_p": 1,
117
- },
118
- "plugins": [],
119
- "systemRole": "",
120
- "tts": {
121
- "showAllLocaleVoice": false,
122
- "sttLocale": "auto",
123
- "ttsService": "openai",
124
- "voice": {
125
- "openai": "alloy",
126
- },
127
- },
128
- },
129
- "meta": {
130
- "avatar": "Default Agent",
131
- "description": "Default agent for testing",
132
- },
133
- },
134
- "fontSize": 14,
135
- "language": "en-US",
136
- "languageModel": {
137
- "openAI": {
138
- "OPENAI_API_KEY": "openai-api-key",
139
- "endpoint": "https://openai-endpoint.com",
140
- "models": [
141
- "gpt-3.5-turbo",
142
- ],
143
- },
144
- },
145
- "neutralColor": "sand",
146
- "password": "password123",
147
- "primaryColor": "blue",
148
- "themeMode": "light",
149
- "tool": {
150
- "dalle": {
151
- "autoGenerate": false,
152
- },
153
- },
154
- "tts": {
155
- "openAI": {
156
- "sttModel": "whisper-1",
157
- "ttsModel": "tts-1",
158
- },
159
- "sttAutoStop": true,
160
- "sttServer": "openai",
161
- },
162
- }
163
- `;
164
-
165
- exports[`settingsSelectors > currentTTS > should merge DEFAULT_TTS_CONFIG and s.settings.tts correctly 1`] = `
166
- {
167
- "openAI": {
168
- "sttModel": "whisper-2",
169
- "ttsModel": "tts-1",
170
- },
171
- "sttAutoStop": false,
172
- "sttServer": "openai",
173
- }
174
- `;
175
-
176
- exports[`settingsSelectors > dalleConfig > should return the dalle configuration 1`] = `
177
- {
178
- "apiKey": "dalle-api-key",
179
- "autoGenerate": true,
180
- }
181
- `;
182
-
183
- exports[`settingsSelectors > defaultAgent > should merge DEFAULT_AGENT and s.settings.defaultAgent correctly 1`] = `
184
- {
185
- "config": {
186
- "autoCreateTopicThreshold": 2,
187
- "displayMode": "chat",
188
- "enableAutoCreateTopic": true,
189
- "historyCount": 1,
190
- "model": "gpt-3.5-turbo",
191
- "params": {
192
- "frequency_penalty": 0,
193
- "presence_penalty": 0,
194
- "temperature": 0.6,
195
- "top_p": 1,
196
- },
197
- "plugins": [],
198
- "systemRole": "user",
199
- "tts": {
200
- "showAllLocaleVoice": false,
201
- "sttLocale": "auto",
202
- "ttsService": "openai",
203
- "voice": {
204
- "openai": "alloy",
205
- },
206
- },
207
- },
208
- "meta": {
209
- "avatar": "agent-avatar.jpg",
210
- "description": "Test agent",
211
- },
212
- }
213
- `;
214
-
215
- exports[`settingsSelectors > defaultAgentConfig > should merge DEFAULT_AGENT_CONFIG and defaultAgent(s).config correctly 1`] = `
216
- {
217
- "autoCreateTopicThreshold": 2,
218
- "displayMode": "chat",
219
- "enableAutoCreateTopic": true,
220
- "historyCount": 1,
221
- "model": "gpt-3.5-turbo",
222
- "params": {
223
- "frequency_penalty": 0,
224
- "presence_penalty": 0,
225
- "temperature": 0.7,
226
- "top_p": 1,
227
- },
228
- "plugins": [],
229
- "systemRole": "user",
230
- "tts": {
231
- "showAllLocaleVoice": false,
232
- "sttLocale": "auto",
233
- "ttsService": "openai",
234
- "voice": {
235
- "openai": "alloy",
236
- },
237
- },
238
- }
239
- `;
240
-
241
- exports[`settingsSelectors > defaultAgentMeta > should merge DEFAULT_AGENT_META and defaultAgent(s).meta correctly 1`] = `
242
- {
243
- "avatar": "agent-avatar.jpg",
244
- "description": "Test agent",
245
- }
246
- `;