@lobehub/chat 0.55.1 → 0.57.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/CHANGELOG.md +71 -0
- package/package.json +3 -3
- package/src/const/fetch.ts +2 -0
- package/src/const/plugin.ts +1 -0
- package/src/features/AgentSetting/AgentPlugin/index.tsx +107 -60
- package/src/features/PluginSettings/PluginSettingRender.tsx +65 -0
- package/src/features/PluginSettings/index.tsx +65 -0
- package/src/hooks/useImportConfig.ts +7 -0
- package/src/locales/default/error.ts +30 -2
- package/src/locales/default/plugin.ts +1 -1
- package/src/locales/default/setting.ts +1 -0
- package/src/pages/api/auth.ts +2 -2
- package/src/pages/api/error.ts +3 -3
- package/src/pages/api/openai.ts +3 -3
- package/src/pages/chat/SessionList/List/Item/index.tsx +2 -2
- package/src/pages/chat/features/Conversation/ChatList/Error/Plugin/PluginError.tsx +28 -0
- package/src/pages/chat/features/Conversation/ChatList/Error/Plugin/PluginSettings.tsx +61 -0
- package/src/pages/chat/features/Conversation/ChatList/Error/index.tsx +42 -0
- package/src/pages/chat/features/Conversation/ChatList/Plugins/FunctionCall.tsx +62 -58
- package/src/pages/chat/features/Conversation/ChatList/index.tsx +15 -25
- package/src/pages/chat/features/Header/PluginTag.tsx +1 -1
- package/src/services/plugin.ts +11 -14
- package/src/services/pluginMarket.ts +10 -0
- package/src/store/global/selectors.ts +2 -2
- package/src/store/global/store.ts +7 -0
- package/src/store/plugin/action.ts +18 -7
- package/src/store/plugin/initialState.ts +3 -0
- package/src/store/plugin/reducers/manifest.ts +2 -2
- package/src/store/plugin/selectors.ts +17 -5
- package/src/store/plugin/store.ts +3 -1
- package/src/store/session/slices/chat/actions/message.ts +30 -21
- package/src/store/session/slices/chat/selectors/utils.test.ts +4 -2
- package/src/store/session/slices/chat/selectors/utils.ts +2 -2
- package/src/types/chatMessage.ts +9 -0
- package/src/types/fetch.ts +18 -14
- package/src/types/plugin.ts +2 -2
- package/src/utils/fetch.ts +24 -18
|
@@ -342,14 +342,16 @@ describe('organizeChats', () => {
|
|
|
342
342
|
...params,
|
|
343
343
|
pluginList: [
|
|
344
344
|
{
|
|
345
|
-
|
|
345
|
+
identifier: 'realtimeWeather',
|
|
346
|
+
author: '123',
|
|
346
347
|
meta: {
|
|
347
348
|
avatar: '🧩',
|
|
349
|
+
title: '天气预报',
|
|
348
350
|
},
|
|
349
351
|
createAt: 'abc',
|
|
350
352
|
manifest: '',
|
|
351
353
|
homepage: '',
|
|
352
|
-
schemaVersion:
|
|
354
|
+
schemaVersion: 1,
|
|
353
355
|
},
|
|
354
356
|
],
|
|
355
357
|
});
|
|
@@ -38,11 +38,11 @@ export const organizeChats = (
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
case 'function': {
|
|
41
|
-
const plugin = (pluginList || []).find((m) => m.
|
|
41
|
+
const plugin = (pluginList || []).find((m) => m.identifier === message.name);
|
|
42
42
|
|
|
43
43
|
return {
|
|
44
44
|
avatar: '🧩',
|
|
45
|
-
title: plugin?.
|
|
45
|
+
title: plugin?.identifier || 'plugin-unknown',
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
}
|
package/src/types/chatMessage.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { PluginRequestPayload } from '@lobehub/chat-plugin-sdk';
|
|
2
|
+
|
|
1
3
|
import { ErrorType } from '@/types/fetch';
|
|
2
4
|
|
|
3
5
|
import { LLMRoleType } from './llm';
|
|
@@ -33,10 +35,17 @@ export interface ChatMessage extends BaseDataModel {
|
|
|
33
35
|
};
|
|
34
36
|
} & Record<string, any>;
|
|
35
37
|
|
|
38
|
+
/**
|
|
39
|
+
* replace with plugin
|
|
40
|
+
* @deprecated
|
|
41
|
+
*/
|
|
36
42
|
function_call?: OpenAIFunctionCall;
|
|
37
43
|
name?: string;
|
|
38
44
|
|
|
39
45
|
parentId?: string;
|
|
46
|
+
|
|
47
|
+
plugin?: PluginRequestPayload;
|
|
48
|
+
|
|
40
49
|
// 引用
|
|
41
50
|
quotaId?: string;
|
|
42
51
|
/**
|
package/src/types/fetch.ts
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
|
2
|
+
export const ChatErrorType = {
|
|
2
3
|
// ******* 业务错误语义 ******* //
|
|
3
4
|
|
|
4
5
|
// 密码无效
|
|
5
|
-
InvalidAccessCode
|
|
6
|
+
InvalidAccessCode: 'InvalidAccessCode',
|
|
6
7
|
// OpenAI 返回的业务错误
|
|
7
|
-
OpenAIBizError
|
|
8
|
+
OpenAIBizError: 'OpenAIBizError',
|
|
8
9
|
|
|
9
10
|
// ******* 客户端错误 ******* //
|
|
10
|
-
BadRequest
|
|
11
|
-
Unauthorized
|
|
12
|
-
Forbidden
|
|
13
|
-
ContentNotFound
|
|
14
|
-
MethodNotAllowed
|
|
15
|
-
TooManyRequests
|
|
11
|
+
BadRequest: 400,
|
|
12
|
+
Unauthorized: 401,
|
|
13
|
+
Forbidden: 403,
|
|
14
|
+
ContentNotFound: 404, // 没找到接口
|
|
15
|
+
MethodNotAllowed: 405, // 不支持
|
|
16
|
+
TooManyRequests: 429,
|
|
16
17
|
|
|
17
18
|
// ******* 服务端错误 ******* //
|
|
18
|
-
InternalServerError
|
|
19
|
-
BadGateway
|
|
20
|
-
ServiceUnavailable
|
|
21
|
-
GatewayTimeout
|
|
22
|
-
}
|
|
19
|
+
InternalServerError: 500,
|
|
20
|
+
BadGateway: 502,
|
|
21
|
+
ServiceUnavailable: 503,
|
|
22
|
+
GatewayTimeout: 504,
|
|
23
|
+
} as const;
|
|
24
|
+
/* eslint-enable */
|
|
25
|
+
|
|
26
|
+
export type ErrorType = (typeof ChatErrorType)[keyof typeof ChatErrorType];
|
|
23
27
|
|
|
24
28
|
export interface ErrorResponse {
|
|
25
29
|
body: any;
|
package/src/types/plugin.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LobeChatPluginManifest } from '@lobehub/chat-plugin-sdk';
|
|
2
2
|
|
|
3
|
-
export type PluginManifestMap = Record<string,
|
|
3
|
+
export type PluginManifestMap = Record<string, LobeChatPluginManifest>;
|
package/src/utils/fetch.ts
CHANGED
|
@@ -2,7 +2,29 @@ import { t } from 'i18next';
|
|
|
2
2
|
|
|
3
3
|
import { fetchChatModel } from '@/services/chatModel';
|
|
4
4
|
import { ChatMessageError } from '@/types/chatMessage';
|
|
5
|
-
import { ErrorResponse } from '@/types/fetch';
|
|
5
|
+
import { ErrorResponse, ErrorType } from '@/types/fetch';
|
|
6
|
+
|
|
7
|
+
export const getMessageError = async (response: Response) => {
|
|
8
|
+
let chatMessageError: ChatMessageError;
|
|
9
|
+
|
|
10
|
+
// 尝试取一波业务错误语义
|
|
11
|
+
try {
|
|
12
|
+
const data = (await response.json()) as ErrorResponse;
|
|
13
|
+
chatMessageError = {
|
|
14
|
+
body: data.body,
|
|
15
|
+
message: t(`response.${data.errorType}`),
|
|
16
|
+
type: data.errorType,
|
|
17
|
+
};
|
|
18
|
+
} catch {
|
|
19
|
+
// 如果无法正常返回,说明是常规报错
|
|
20
|
+
chatMessageError = {
|
|
21
|
+
message: t(`response.${response.status}`),
|
|
22
|
+
type: response.status as ErrorType,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return chatMessageError;
|
|
27
|
+
};
|
|
6
28
|
|
|
7
29
|
export interface FetchSSEOptions {
|
|
8
30
|
onErrorHandle?: (error: ChatMessageError) => void;
|
|
@@ -19,23 +41,7 @@ export const fetchSSE = async (fetchFn: () => Promise<Response>, options: FetchS
|
|
|
19
41
|
|
|
20
42
|
// 如果不 ok 说明有请求错误
|
|
21
43
|
if (!response.ok) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// 尝试取一波业务错误语义
|
|
25
|
-
try {
|
|
26
|
-
const data = (await response.json()) as ErrorResponse;
|
|
27
|
-
chatMessageError = {
|
|
28
|
-
body: data.body,
|
|
29
|
-
message: t(`response.${data.errorType}`),
|
|
30
|
-
type: data.errorType,
|
|
31
|
-
};
|
|
32
|
-
} catch {
|
|
33
|
-
// 如果无法正常返回,说明是常规报错
|
|
34
|
-
chatMessageError = {
|
|
35
|
-
message: t(`response.${response.status}`),
|
|
36
|
-
type: response.status,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
44
|
+
const chatMessageError = await getMessageError(response);
|
|
39
45
|
|
|
40
46
|
options.onErrorHandle?.(chatMessageError);
|
|
41
47
|
return;
|