@lobehub/chat 0.94.5 → 0.95.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/.github/workflows/pr-welcome.yml +1 -1
- package/CHANGELOG.md +60 -0
- package/README.md +4 -4
- package/docs/Lighthouse.md +8 -8
- package/docs/Lighthouse.zh-CN.md +8 -8
- package/package.json +4 -4
- package/src/app/chat/(desktop)/features/ChatInput.tsx +0 -1
- package/src/app/chat/features/Conversation/ChatList/Error/Plugin/PluginSettings.tsx +1 -1
- package/src/app/chat/features/Conversation/ChatList/Messages/Assistant.tsx +12 -15
- package/src/app/chat/features/Conversation/ChatList/Messages/Function.tsx +26 -15
- package/src/app/chat/features/Conversation/ChatList/Plugins/Inspector/Settings.tsx +36 -0
- package/src/app/chat/features/Conversation/ChatList/Plugins/Inspector/index.tsx +126 -0
- package/src/app/chat/features/Conversation/ChatList/Plugins/{style.ts → Inspector/style.ts} +1 -0
- package/src/app/chat/features/Conversation/ChatList/Plugins/{IFrameRender → Render/DefaultType/IFrameRender}/index.tsx +5 -16
- package/src/app/chat/features/Conversation/ChatList/Plugins/Render/DefaultType/index.tsx +117 -0
- package/src/app/chat/features/Conversation/ChatList/Plugins/Render/StandaloneType/Iframe.tsx +136 -0
- package/src/app/chat/features/Conversation/ChatList/Plugins/Render/StandaloneType/index.tsx +28 -0
- package/src/app/chat/features/Conversation/ChatList/Plugins/Render/index.tsx +28 -0
- package/src/app/chat/features/Conversation/ChatList/Plugins/Render/utils/iframeOnReady.ts +23 -0
- package/src/app/chat/features/Conversation/ChatList/Plugins/Render/utils/listenToPlugin.ts +65 -0
- package/src/app/chat/features/Conversation/ChatList/Plugins/Render/utils/pluginSettings.ts +17 -0
- package/src/app/chat/features/Conversation/ChatList/Plugins/Render/utils/pluginState.ts +20 -0
- package/src/app/chat/features/Conversation/ChatList/Plugins/Render/utils/postMessage.ts +17 -0
- package/src/const/plugin.ts +1 -1
- package/src/features/PluginSettings/index.tsx +5 -3
- package/src/features/PluginSettingsModal/index.tsx +45 -0
- package/src/locales/default/plugin.ts +3 -2
- package/src/store/plugin/selectors.ts +17 -4
- package/src/store/session/slices/chat/actions/index.ts +4 -1
- package/src/store/session/slices/chat/actions/message.ts +102 -117
- package/src/store/session/slices/chat/actions/plugin.ts +109 -0
- package/src/store/session/slices/chat/reducers/message.ts +31 -1
- package/src/store/session/slices/chat/selectors/chat.ts +17 -20
- package/src/store/session/slices/chat/selectors/index.ts +4 -2
- package/src/types/chatMessage.ts +1 -0
- package/src/utils/message.ts +8 -1
- package/src/app/chat/features/Conversation/ChatList/Plugins/FunctionCall.tsx +0 -90
- package/src/app/chat/features/Conversation/ChatList/Plugins/IFrameRender/hooks.ts +0 -29
- package/src/app/chat/features/Conversation/ChatList/Plugins/IFrameRender/utils.ts +0 -17
- package/src/app/chat/features/Conversation/ChatList/Plugins/PluginMessage.tsx +0 -68
- /package/src/app/chat/features/Conversation/ChatList/Plugins/{PluginResultRender.tsx → Inspector/PluginResultJSON.tsx} +0 -0
- /package/src/app/chat/features/Conversation/ChatList/Plugins/{SystemJsRender → Render/DefaultType/SystemJsRender}/index.tsx +0 -0
- /package/src/app/chat/features/Conversation/ChatList/Plugins/{SystemJsRender → Render/DefaultType/SystemJsRender}/utils.ts +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,66 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.95.1](https://github.com/lobehub/lobe-chat/compare/v0.95.0...v0.95.1)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2023-10-25**</sup>
|
|
8
|
+
|
|
9
|
+
#### 💄 Styles
|
|
10
|
+
|
|
11
|
+
- **misc**: Improve plugin message ui.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### Styles
|
|
19
|
+
|
|
20
|
+
- **misc**: Improve plugin message ui ([6edd25b](https://github.com/lobehub/lobe-chat/commit/6edd25b))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
## [Version 0.95.0](https://github.com/lobehub/lobe-chat/compare/v0.94.5...v0.95.0)
|
|
31
|
+
|
|
32
|
+
<sup>Released on **2023-10-24**</sup>
|
|
33
|
+
|
|
34
|
+
#### ♻ Code Refactoring
|
|
35
|
+
|
|
36
|
+
- **misc**: 优化 plugin 文件夹命名以支持 standalone 类型的插件.
|
|
37
|
+
|
|
38
|
+
#### ✨ Features
|
|
39
|
+
|
|
40
|
+
- **misc**: Support function call at message end, support plugin settings modal, support plugin state and settings.
|
|
41
|
+
|
|
42
|
+
<br/>
|
|
43
|
+
|
|
44
|
+
<details>
|
|
45
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
46
|
+
|
|
47
|
+
#### Code refactoring
|
|
48
|
+
|
|
49
|
+
- **misc**: 优化 plugin 文件夹命名以支持 standalone 类型的插件 ([98860a8](https://github.com/lobehub/lobe-chat/commit/98860a8))
|
|
50
|
+
|
|
51
|
+
#### What's improved
|
|
52
|
+
|
|
53
|
+
- **misc**: Support function call at message end, closes [#357](https://github.com/lobehub/lobe-chat/issues/357) ([e195fdb](https://github.com/lobehub/lobe-chat/commit/e195fdb))
|
|
54
|
+
- **misc**: Support plugin settings modal ([f47b6fa](https://github.com/lobehub/lobe-chat/commit/f47b6fa))
|
|
55
|
+
- **misc**: Support plugin state and settings ([10829a4](https://github.com/lobehub/lobe-chat/commit/10829a4))
|
|
56
|
+
|
|
57
|
+
</details>
|
|
58
|
+
|
|
59
|
+
<div align="right">
|
|
60
|
+
|
|
61
|
+
[](#readme-top)
|
|
62
|
+
|
|
63
|
+
</div>
|
|
64
|
+
|
|
5
65
|
### [Version 0.94.5](https://github.com/lobehub/lobe-chat/compare/v0.94.4...v0.94.5)
|
|
6
66
|
|
|
7
67
|
<sup>Released on **2023-10-22**</sup>
|
package/README.md
CHANGED
|
@@ -131,10 +131,10 @@ Utilize the Progressive Web Application ([PWA](https://support.google.com/chrome
|
|
|
131
131
|
> **Note**\
|
|
132
132
|
> If you are unfamiliar with the installation process of PWA, you can add LobeChat as your desktop application (also applicable to mobile devices) by following these steps:
|
|
133
133
|
>
|
|
134
|
-
> - Launch the Chrome or Edge browser on your computer
|
|
135
|
-
> - Visit the LobeChat webpage
|
|
136
|
-
> - In the upper right corner of the address bar, click on the <kbd>Install</kbd> icon
|
|
137
|
-
> - Follow the instructions on the screen to complete the PWA installation
|
|
134
|
+
> - Launch the Chrome or Edge browser on your computer.
|
|
135
|
+
> - Visit the LobeChat webpage.
|
|
136
|
+
> - In the upper right corner of the address bar, click on the <kbd>Install</kbd> icon.
|
|
137
|
+
> - Follow the instructions on the screen to complete the PWA installation.
|
|
138
138
|
|
|
139
139
|
<br/>
|
|
140
140
|
|
package/docs/Lighthouse.md
CHANGED
|
@@ -48,18 +48,18 @@
|
|
|
48
48
|
| [⚡️ Lighthouse Report][settings-desktop-report] | [⚡️ Lighthouse Report][settings-mobile-report] |
|
|
49
49
|
|
|
50
50
|
[chat-desktop]: https://raw.githubusercontent.com/lobehub/lobe-chat/lighthouse/lighthouse/chat/desktop/pagespeed.svg
|
|
51
|
-
[chat-desktop-report]: https://lobehub.github.io/lobe-chat/lighthouse/chat/desktop/
|
|
51
|
+
[chat-desktop-report]: https://lobehub.github.io/lobe-chat/lighthouse/chat/desktop/chat_preivew_lobehub_com_chat.html
|
|
52
52
|
[chat-mobile]: https://raw.githubusercontent.com/lobehub/lobe-chat/lighthouse/lighthouse/chat/mobile/pagespeed.svg
|
|
53
|
-
[chat-mobile-report]: https://lobehub.github.io/lobe-chat/lighthouse/chat/mobile/
|
|
53
|
+
[chat-mobile-report]: https://lobehub.github.io/lobe-chat/lighthouse/chat/mobile/chat_preivew_lobehub_com_chat.html
|
|
54
54
|
[market-desktop]: https://raw.githubusercontent.com/lobehub/lobe-chat/lighthouse/lighthouse/market/desktop/pagespeed.svg
|
|
55
|
-
[market-desktop-report]: https://lobehub.github.io/lobe-chat/lighthouse/market/desktop/
|
|
55
|
+
[market-desktop-report]: https://lobehub.github.io/lobe-chat/lighthouse/market/desktop/chat_preivew_lobehub_com_market.html
|
|
56
56
|
[market-mobile]: https://raw.githubusercontent.com/lobehub/lobe-chat/lighthouse/lighthouse/market/mobile/pagespeed.svg
|
|
57
|
-
[market-mobile-report]: https://lobehub.github.io/lobe-chat/lighthouse/market/mobile/
|
|
57
|
+
[market-mobile-report]: https://lobehub.github.io/lobe-chat/lighthouse/market/mobile/chat_preivew_lobehub_com_market.html
|
|
58
58
|
[settings-desktop]: https://raw.githubusercontent.com/lobehub/lobe-chat/lighthouse/lighthouse/settings/desktop/pagespeed.svg
|
|
59
|
-
[settings-desktop-report]: https://lobehub.github.io/lobe-chat/lighthouse/settings/desktop/
|
|
59
|
+
[settings-desktop-report]: https://lobehub.github.io/lobe-chat/lighthouse/settings/desktop/chat_preivew_lobehub_com_settings.html
|
|
60
60
|
[settings-mobile]: https://raw.githubusercontent.com/lobehub/lobe-chat/lighthouse/lighthouse/settings/mobile/pagespeed.svg
|
|
61
|
-
[settings-mobile-report]: https://lobehub.github.io/lobe-chat/lighthouse/settings/mobile/
|
|
61
|
+
[settings-mobile-report]: https://lobehub.github.io/lobe-chat/lighthouse/settings/mobile/chat_preivew_lobehub_com_settings.html
|
|
62
62
|
[welcome-desktop]: https://raw.githubusercontent.com/lobehub/lobe-chat/lighthouse/lighthouse/welcome/desktop/pagespeed.svg
|
|
63
|
-
[welcome-desktop-report]: https://lobehub.github.io/lobe-chat/lighthouse/welcome/desktop/
|
|
63
|
+
[welcome-desktop-report]: https://lobehub.github.io/lobe-chat/lighthouse/welcome/desktop/chat_preivew_lobehub_com_welcome.html
|
|
64
64
|
[welcome-mobile]: https://raw.githubusercontent.com/lobehub/lobe-chat/lighthouse/lighthouse/welcome/mobile/pagespeed.svg
|
|
65
|
-
[welcome-mobile-report]: https://lobehub.github.io/lobe-chat/lighthouse/welcome/mobile/
|
|
65
|
+
[welcome-mobile-report]: https://lobehub.github.io/lobe-chat/lighthouse/welcome/mobile/chat_preivew_lobehub_com_welcome.html
|
package/docs/Lighthouse.zh-CN.md
CHANGED
|
@@ -48,18 +48,18 @@
|
|
|
48
48
|
| [⚡️ Lighthouse Report][settings-desktop-report] | [⚡️ Lighthouse Report][settings-mobile-report] |
|
|
49
49
|
|
|
50
50
|
[chat-desktop]: https://raw.githubusercontent.com/lobehub/lobe-chat/lighthouse/lighthouse/chat/desktop/pagespeed.svg
|
|
51
|
-
[chat-desktop-report]: https://lobehub.github.io/lobe-chat/lighthouse/chat/desktop/
|
|
51
|
+
[chat-desktop-report]: https://lobehub.github.io/lobe-chat/lighthouse/chat/desktop/chat_preview_lobehub_com_chat.html
|
|
52
52
|
[chat-mobile]: https://raw.githubusercontent.com/lobehub/lobe-chat/lighthouse/lighthouse/chat/mobile/pagespeed.svg
|
|
53
|
-
[chat-mobile-report]: https://lobehub.github.io/lobe-chat/lighthouse/chat/mobile/
|
|
53
|
+
[chat-mobile-report]: https://lobehub.github.io/lobe-chat/lighthouse/chat/mobile/chat_preview_lobehub_com_chat.html
|
|
54
54
|
[market-desktop]: https://raw.githubusercontent.com/lobehub/lobe-chat/lighthouse/lighthouse/market/desktop/pagespeed.svg
|
|
55
|
-
[market-desktop-report]: https://lobehub.github.io/lobe-chat/lighthouse/market/desktop/
|
|
55
|
+
[market-desktop-report]: https://lobehub.github.io/lobe-chat/lighthouse/market/desktop/chat_preview_lobehub_com_market.html
|
|
56
56
|
[market-mobile]: https://raw.githubusercontent.com/lobehub/lobe-chat/lighthouse/lighthouse/market/mobile/pagespeed.svg
|
|
57
|
-
[market-mobile-report]: https://lobehub.github.io/lobe-chat/lighthouse/market/mobile/
|
|
57
|
+
[market-mobile-report]: https://lobehub.github.io/lobe-chat/lighthouse/market/mobile/chat_preview_lobehub_com_market.html
|
|
58
58
|
[settings-desktop]: https://raw.githubusercontent.com/lobehub/lobe-chat/lighthouse/lighthouse/settings/desktop/pagespeed.svg
|
|
59
|
-
[settings-desktop-report]: https://lobehub.github.io/lobe-chat/lighthouse/settings/desktop/
|
|
59
|
+
[settings-desktop-report]: https://lobehub.github.io/lobe-chat/lighthouse/settings/desktop/chat_preview_lobehub_com_settings.html
|
|
60
60
|
[settings-mobile]: https://raw.githubusercontent.com/lobehub/lobe-chat/lighthouse/lighthouse/settings/mobile/pagespeed.svg
|
|
61
|
-
[settings-mobile-report]: https://lobehub.github.io/lobe-chat/lighthouse/settings/mobile/
|
|
61
|
+
[settings-mobile-report]: https://lobehub.github.io/lobe-chat/lighthouse/settings/mobile/chat_preview_lobehub_com_settings.html
|
|
62
62
|
[welcome-desktop]: https://raw.githubusercontent.com/lobehub/lobe-chat/lighthouse/lighthouse/welcome/desktop/pagespeed.svg
|
|
63
|
-
[welcome-desktop-report]: https://lobehub.github.io/lobe-chat/lighthouse/welcome/desktop/
|
|
63
|
+
[welcome-desktop-report]: https://lobehub.github.io/lobe-chat/lighthouse/welcome/desktop/chat_preview_lobehub_com_welcome.html
|
|
64
64
|
[welcome-mobile]: https://raw.githubusercontent.com/lobehub/lobe-chat/lighthouse/lighthouse/welcome/mobile/pagespeed.svg
|
|
65
|
-
[welcome-mobile-report]: https://lobehub.github.io/lobe-chat/lighthouse/welcome/mobile/
|
|
65
|
+
[welcome-mobile-report]: https://lobehub.github.io/lobe-chat/lighthouse/welcome/mobile/chat_preview_lobehub_com_welcome.html
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/chat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.95.1",
|
|
4
4
|
"description": "An open-source, extensible (Function Calling), high-performance chatbot framework. It supports one-click free deployment of your private ChatGPT/LLM web application",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chatbot",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"ahooks": "^3",
|
|
77
77
|
"ai": "^2",
|
|
78
78
|
"antd": "^5",
|
|
79
|
-
"antd-style": "^3
|
|
79
|
+
"antd-style": "^3",
|
|
80
80
|
"brotli-wasm": "^1",
|
|
81
81
|
"chroma-js": "^2",
|
|
82
82
|
"copy-to-clipboard": "^3",
|
|
@@ -122,7 +122,7 @@
|
|
|
122
122
|
"zustand-utils": "^1"
|
|
123
123
|
},
|
|
124
124
|
"devDependencies": {
|
|
125
|
-
"@commitlint/cli": "^
|
|
125
|
+
"@commitlint/cli": "^18",
|
|
126
126
|
"@lobehub/i18n-cli": "latest",
|
|
127
127
|
"@lobehub/lint": "latest",
|
|
128
128
|
"@next/bundle-analyzer": "^13",
|
|
@@ -141,7 +141,7 @@
|
|
|
141
141
|
"@types/uuid": "^9",
|
|
142
142
|
"@umijs/lint": "^4",
|
|
143
143
|
"@vitest/coverage-v8": "latest",
|
|
144
|
-
"commitlint": "^
|
|
144
|
+
"commitlint": "^18",
|
|
145
145
|
"consola": "^3",
|
|
146
146
|
"dpdm": "^3",
|
|
147
147
|
"eslint": "^8",
|
|
@@ -36,7 +36,7 @@ const PluginSettings: RenderErrorMessage = memo(({ id, plugin }) => {
|
|
|
36
36
|
<Flexbox className={styles.desc}>{t('pluginSettings.desc')}</Flexbox>
|
|
37
37
|
<Divider style={{ margin: '0 16px' }} />
|
|
38
38
|
{manifest.settings && (
|
|
39
|
-
<PluginSettingsConfig id={manifest.identifier}
|
|
39
|
+
<PluginSettingsConfig id={manifest.identifier} schema={manifest.settings} />
|
|
40
40
|
)}
|
|
41
41
|
<Button
|
|
42
42
|
block
|
|
@@ -3,23 +3,20 @@ import { memo } from 'react';
|
|
|
3
3
|
|
|
4
4
|
import { useSessionStore } from '@/store/session';
|
|
5
5
|
import { chatSelectors } from '@/store/session/selectors';
|
|
6
|
-
import {
|
|
6
|
+
import { isFunctionMessageAtStart } from '@/utils/message';
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import Inspector from '../Plugins/Inspector';
|
|
9
9
|
import { DefaultMessage } from './Default';
|
|
10
10
|
|
|
11
|
-
export const AssistantMessage: RenderMessage = memo(
|
|
12
|
-
({ id, plugin
|
|
13
|
-
const genFunctionCallProps = useSessionStore(chatSelectors.getFunctionMessageParams);
|
|
11
|
+
export const AssistantMessage: RenderMessage = memo(({ id, plugin, content, ...props }) => {
|
|
12
|
+
const fcProps = useSessionStore(chatSelectors.getFunctionMessageProps({ content, id, plugin }));
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
if (!isFunctionMessageAtStart(content))
|
|
15
|
+
return <DefaultMessage content={content} id={id} {...props} />;
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
);
|
|
24
|
-
},
|
|
25
|
-
);
|
|
17
|
+
return (
|
|
18
|
+
<div id={id}>
|
|
19
|
+
<Inspector {...fcProps} />
|
|
20
|
+
</div>
|
|
21
|
+
);
|
|
22
|
+
});
|
|
@@ -1,23 +1,34 @@
|
|
|
1
1
|
import { RenderMessage } from '@lobehub/ui';
|
|
2
|
-
import
|
|
2
|
+
import isEqual from 'fast-deep-equal';
|
|
3
|
+
import { memo, useState } from 'react';
|
|
3
4
|
import { Flexbox } from 'react-layout-kit';
|
|
4
5
|
|
|
5
6
|
import { useSessionStore } from '@/store/session';
|
|
6
7
|
import { chatSelectors } from '@/store/session/selectors';
|
|
7
8
|
|
|
8
|
-
import
|
|
9
|
-
import
|
|
9
|
+
import Inspector from '../Plugins/Inspector';
|
|
10
|
+
import PluginRender from '../Plugins/Render';
|
|
10
11
|
|
|
11
|
-
export const FunctionMessage: RenderMessage = memo(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
export const FunctionMessage: RenderMessage = memo(({ id, content, plugin, name }) => {
|
|
13
|
+
const fcProps = useSessionStore(
|
|
14
|
+
chatSelectors.getFunctionMessageProps({ content, id, plugin }),
|
|
15
|
+
isEqual,
|
|
16
|
+
);
|
|
17
|
+
const [showRender, setShow] = useState(true);
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
return (
|
|
20
|
+
<Flexbox gap={12} id={id}>
|
|
21
|
+
<Inspector showRender={showRender} {...fcProps} setShow={setShow} />
|
|
22
|
+
{showRender && (
|
|
23
|
+
<PluginRender
|
|
24
|
+
content={content}
|
|
25
|
+
id={id}
|
|
26
|
+
loading={fcProps.loading}
|
|
27
|
+
name={name}
|
|
28
|
+
payload={fcProps.command}
|
|
29
|
+
type={fcProps.type}
|
|
30
|
+
/>
|
|
31
|
+
)}
|
|
32
|
+
</Flexbox>
|
|
33
|
+
);
|
|
34
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ActionIcon } from '@lobehub/ui';
|
|
2
|
+
import { LucideSettings } from 'lucide-react';
|
|
3
|
+
import { memo, useState } from 'react';
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
5
|
+
|
|
6
|
+
import PluginSettingsModal from '@/features/PluginSettingsModal';
|
|
7
|
+
import { pluginSelectors, usePluginStore } from '@/store/plugin';
|
|
8
|
+
|
|
9
|
+
const Settings = memo<{ id: string }>(({ id }) => {
|
|
10
|
+
const item = usePluginStore(pluginSelectors.getPluginManifestById(id));
|
|
11
|
+
const [open, setOpen] = useState(false);
|
|
12
|
+
const { t } = useTranslation('plugin');
|
|
13
|
+
return (
|
|
14
|
+
item?.settings && (
|
|
15
|
+
<>
|
|
16
|
+
<ActionIcon
|
|
17
|
+
icon={LucideSettings}
|
|
18
|
+
onClick={() => {
|
|
19
|
+
setOpen(true);
|
|
20
|
+
}}
|
|
21
|
+
title={t('setting')}
|
|
22
|
+
/>
|
|
23
|
+
<PluginSettingsModal
|
|
24
|
+
id={id}
|
|
25
|
+
onClose={() => {
|
|
26
|
+
setOpen(false);
|
|
27
|
+
}}
|
|
28
|
+
open={open}
|
|
29
|
+
schema={item.settings}
|
|
30
|
+
/>
|
|
31
|
+
</>
|
|
32
|
+
)
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export default Settings;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { Loading3QuartersOutlined } from '@ant-design/icons';
|
|
2
|
+
import { LobePluginType } from '@lobehub/chat-plugin-sdk';
|
|
3
|
+
import { ActionIcon, Avatar, Highlighter, Icon } from '@lobehub/ui';
|
|
4
|
+
import { Tabs } from 'antd';
|
|
5
|
+
import isEqual from 'fast-deep-equal';
|
|
6
|
+
import {
|
|
7
|
+
LucideBug,
|
|
8
|
+
LucideBugOff,
|
|
9
|
+
LucideChevronDown,
|
|
10
|
+
LucideChevronUp,
|
|
11
|
+
LucideToyBrick,
|
|
12
|
+
} from 'lucide-react';
|
|
13
|
+
import { memo, useState } from 'react';
|
|
14
|
+
import { useTranslation } from 'react-i18next';
|
|
15
|
+
import { Flexbox } from 'react-layout-kit';
|
|
16
|
+
|
|
17
|
+
import { pluginHelpers, pluginSelectors, usePluginStore } from '@/store/plugin';
|
|
18
|
+
|
|
19
|
+
import PluginResult from './PluginResultJSON';
|
|
20
|
+
import Settings from './Settings';
|
|
21
|
+
import { useStyles } from './style';
|
|
22
|
+
|
|
23
|
+
export interface InspectorProps {
|
|
24
|
+
arguments?: string;
|
|
25
|
+
command?: any;
|
|
26
|
+
content: string;
|
|
27
|
+
id?: string;
|
|
28
|
+
loading?: boolean;
|
|
29
|
+
setShow?: (showRender: boolean) => void;
|
|
30
|
+
showRender?: boolean;
|
|
31
|
+
type?: LobePluginType;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const Inspector = memo<InspectorProps>(
|
|
35
|
+
({
|
|
36
|
+
arguments: requestArgs = '{}',
|
|
37
|
+
command,
|
|
38
|
+
showRender,
|
|
39
|
+
loading,
|
|
40
|
+
setShow,
|
|
41
|
+
content,
|
|
42
|
+
id = 'unknown',
|
|
43
|
+
// type,
|
|
44
|
+
}) => {
|
|
45
|
+
const { t } = useTranslation('plugin');
|
|
46
|
+
const { styles } = useStyles();
|
|
47
|
+
const [open, setOpen] = useState(false);
|
|
48
|
+
|
|
49
|
+
const item = usePluginStore(pluginSelectors.getPluginMetaById(id), isEqual);
|
|
50
|
+
const showRightAction = usePluginStore(pluginSelectors.hasPluginUI(id));
|
|
51
|
+
const pluginAvatar = pluginHelpers.getPluginAvatar(item?.meta);
|
|
52
|
+
const pluginTitle = pluginHelpers.getPluginTitle(item?.meta);
|
|
53
|
+
|
|
54
|
+
const avatar = pluginAvatar ? (
|
|
55
|
+
<Avatar avatar={pluginAvatar} size={32} />
|
|
56
|
+
) : (
|
|
57
|
+
<Icon icon={LucideToyBrick} />
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const args = JSON.stringify(command, null, 2);
|
|
61
|
+
const params = JSON.stringify(JSON.parse(requestArgs), null, 2);
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<Flexbox gap={8}>
|
|
65
|
+
<Flexbox align={'center'} distribution={'space-between'} gap={24} horizontal>
|
|
66
|
+
<Flexbox
|
|
67
|
+
align={'center'}
|
|
68
|
+
className={styles.container}
|
|
69
|
+
gap={8}
|
|
70
|
+
horizontal
|
|
71
|
+
onClick={() => {
|
|
72
|
+
setShow?.(!showRender);
|
|
73
|
+
}}
|
|
74
|
+
>
|
|
75
|
+
{loading ? (
|
|
76
|
+
<div>
|
|
77
|
+
<Loading3QuartersOutlined spin />
|
|
78
|
+
</div>
|
|
79
|
+
) : (
|
|
80
|
+
avatar
|
|
81
|
+
)}
|
|
82
|
+
{pluginTitle ?? t('plugins.unknown')}
|
|
83
|
+
{showRightAction && <Icon icon={showRender ? LucideChevronUp : LucideChevronDown} />}
|
|
84
|
+
</Flexbox>
|
|
85
|
+
{
|
|
86
|
+
<Flexbox horizontal>
|
|
87
|
+
{/*{type === 'standalone' && <ActionIcon icon={LucideOrbit} />}*/}
|
|
88
|
+
<ActionIcon
|
|
89
|
+
icon={open ? LucideBugOff : LucideBug}
|
|
90
|
+
onClick={() => {
|
|
91
|
+
setOpen(!open);
|
|
92
|
+
}}
|
|
93
|
+
title={t(open ? 'debug.off' : 'debug.on')}
|
|
94
|
+
/>
|
|
95
|
+
<Settings id={id} />
|
|
96
|
+
</Flexbox>
|
|
97
|
+
}
|
|
98
|
+
</Flexbox>
|
|
99
|
+
{open && (
|
|
100
|
+
<Tabs
|
|
101
|
+
items={[
|
|
102
|
+
{
|
|
103
|
+
children: <Highlighter language={'json'}>{args}</Highlighter>,
|
|
104
|
+
key: 'function_call',
|
|
105
|
+
label: t('debug.function_call'),
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
children: <Highlighter language={'json'}>{params}</Highlighter>,
|
|
109
|
+
key: 'arguments',
|
|
110
|
+
label: t('debug.arguments'),
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
children: <PluginResult content={content} />,
|
|
114
|
+
key: 'response',
|
|
115
|
+
label: t('debug.response'),
|
|
116
|
+
},
|
|
117
|
+
]}
|
|
118
|
+
style={{ maxWidth: 800 }}
|
|
119
|
+
/>
|
|
120
|
+
)}
|
|
121
|
+
</Flexbox>
|
|
122
|
+
);
|
|
123
|
+
},
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
export default Inspector;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { PluginRenderProps } from '@lobehub/chat-plugin-sdk/client';
|
|
2
2
|
import { Skeleton } from 'antd';
|
|
3
|
-
import { memo,
|
|
3
|
+
import { memo, useRef, useState } from 'react';
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import { sendMessageToPlugin } from '
|
|
5
|
+
import { useOnPluginReadyForInteraction } from '../../utils/iframeOnReady';
|
|
6
|
+
import { sendMessageToPlugin } from '../../utils/postMessage';
|
|
7
7
|
|
|
8
8
|
interface IFrameRenderProps extends PluginRenderProps {
|
|
9
9
|
height?: number;
|
|
@@ -12,24 +12,13 @@ interface IFrameRenderProps extends PluginRenderProps {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
const IFrameRender = memo<IFrameRenderProps>(({ url, width = 800, height = 300, ...props }) => {
|
|
15
|
-
const [loading, setLoading] = useState(true);
|
|
16
|
-
const [readyForRender, setReady] = useState(false);
|
|
17
15
|
const iframeRef = useRef<HTMLIFrameElement>(null);
|
|
18
|
-
|
|
19
|
-
useOnPluginReady(() => setReady(true));
|
|
16
|
+
const [loading, setLoading] = useState(true);
|
|
20
17
|
|
|
21
18
|
// 当 props 发生变化时,主动向 iframe 发送数据
|
|
22
|
-
|
|
19
|
+
useOnPluginReadyForInteraction(() => {
|
|
23
20
|
const iframeWin = iframeRef.current?.contentWindow;
|
|
24
21
|
|
|
25
|
-
if (iframeWin && readyForRender) {
|
|
26
|
-
sendMessageToPlugin(iframeWin, props);
|
|
27
|
-
}
|
|
28
|
-
}, [readyForRender, props]);
|
|
29
|
-
|
|
30
|
-
// 当接收到来自 iframe 的请求时,触发发送数据
|
|
31
|
-
useOnPluginFetchMessage(() => {
|
|
32
|
-
const iframeWin = iframeRef.current?.contentWindow;
|
|
33
22
|
if (iframeWin) {
|
|
34
23
|
sendMessageToPlugin(iframeWin, props);
|
|
35
24
|
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Skeleton } from 'antd';
|
|
2
|
+
import { createStyles } from 'antd-style';
|
|
3
|
+
import dynamic from 'next/dynamic';
|
|
4
|
+
import { Suspense, memo, useMemo } from 'react';
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
import { Flexbox } from 'react-layout-kit';
|
|
7
|
+
|
|
8
|
+
import { usePluginStore } from '@/store/plugin';
|
|
9
|
+
|
|
10
|
+
import IFrameRender from './IFrameRender';
|
|
11
|
+
|
|
12
|
+
const SystemJsRender = dynamic(() => import('./SystemJsRender'), { ssr: false });
|
|
13
|
+
|
|
14
|
+
const useStyles = createStyles(
|
|
15
|
+
({ css, token }) => css`
|
|
16
|
+
position: relative;
|
|
17
|
+
|
|
18
|
+
overflow: hidden;
|
|
19
|
+
display: block;
|
|
20
|
+
|
|
21
|
+
width: 300px;
|
|
22
|
+
height: 12px;
|
|
23
|
+
|
|
24
|
+
border: 1px solid ${token.colorBorder};
|
|
25
|
+
border-radius: 10px;
|
|
26
|
+
|
|
27
|
+
&::after {
|
|
28
|
+
content: '';
|
|
29
|
+
|
|
30
|
+
position: absolute;
|
|
31
|
+
top: 0;
|
|
32
|
+
left: 0;
|
|
33
|
+
|
|
34
|
+
box-sizing: border-box;
|
|
35
|
+
width: 40%;
|
|
36
|
+
height: 100%;
|
|
37
|
+
|
|
38
|
+
background: ${token.colorPrimary};
|
|
39
|
+
|
|
40
|
+
animation: animloader 2s linear infinite;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@keyframes animloader {
|
|
44
|
+
0% {
|
|
45
|
+
left: 0;
|
|
46
|
+
transform: translateX(-100%);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
100% {
|
|
50
|
+
left: 100%;
|
|
51
|
+
transform: translateX(0%);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
`,
|
|
55
|
+
);
|
|
56
|
+
const Loading = () => {
|
|
57
|
+
const { t } = useTranslation('plugin');
|
|
58
|
+
const { styles } = useStyles();
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<Flexbox align={'center'} gap={8} padding={16}>
|
|
62
|
+
<span className={styles} />
|
|
63
|
+
{t('loading.content')}
|
|
64
|
+
</Flexbox>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export interface PluginDefaultTypeProps {
|
|
69
|
+
content: string;
|
|
70
|
+
loading?: boolean;
|
|
71
|
+
name?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const PluginDefaultType = memo<PluginDefaultTypeProps>(({ content, name }) => {
|
|
75
|
+
const manifest = usePluginStore((s) => s.pluginManifestMap[name || '']);
|
|
76
|
+
let isJSON = true;
|
|
77
|
+
try {
|
|
78
|
+
JSON.parse(content);
|
|
79
|
+
} catch {
|
|
80
|
+
isJSON = false;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const contentObj = useMemo<object>(() => (isJSON ? JSON.parse(content) : content), [content]);
|
|
84
|
+
|
|
85
|
+
if (!isJSON) {
|
|
86
|
+
return (
|
|
87
|
+
<Flexbox gap={8}>
|
|
88
|
+
<Loading />
|
|
89
|
+
</Flexbox>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!manifest?.ui) return;
|
|
94
|
+
|
|
95
|
+
const ui = manifest.ui;
|
|
96
|
+
|
|
97
|
+
if (!ui.url) return;
|
|
98
|
+
|
|
99
|
+
if (ui.mode === 'module')
|
|
100
|
+
return (
|
|
101
|
+
<Suspense fallback={<Skeleton active style={{ width: 400 }} />}>
|
|
102
|
+
<SystemJsRender content={contentObj} name={name || 'unknown'} url={ui.url} />
|
|
103
|
+
</Suspense>
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<IFrameRender
|
|
108
|
+
content={contentObj}
|
|
109
|
+
height={ui.height}
|
|
110
|
+
name={name || 'unknown'}
|
|
111
|
+
url={ui.url}
|
|
112
|
+
width={ui.width}
|
|
113
|
+
/>
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
export default PluginDefaultType;
|