@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
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
|
-
|
|
3
|
-
import { onPluginFetchMessage, onPluginReady } from './utils';
|
|
4
|
-
|
|
5
|
-
export const useOnPluginReady = (onReady: () => void) => {
|
|
6
|
-
useEffect(() => {
|
|
7
|
-
const fn = (e: MessageEvent) => {
|
|
8
|
-
onPluginReady(e, onReady);
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
window.addEventListener('message', fn);
|
|
12
|
-
return () => {
|
|
13
|
-
window.removeEventListener('message', fn);
|
|
14
|
-
};
|
|
15
|
-
}, []);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const useOnPluginFetchMessage = (onRequest: (data: any) => void, deps: any[] = []) => {
|
|
19
|
-
useEffect(() => {
|
|
20
|
-
const fn = (e: MessageEvent) => {
|
|
21
|
-
onPluginFetchMessage(e, onRequest);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
window.addEventListener('message', fn);
|
|
25
|
-
return () => {
|
|
26
|
-
window.removeEventListener('message', fn);
|
|
27
|
-
};
|
|
28
|
-
}, deps);
|
|
29
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { PluginChannel } from '@lobehub/chat-plugin-sdk/client';
|
|
2
|
-
|
|
3
|
-
export const onPluginReady = (e: MessageEvent, onReady: () => void) => {
|
|
4
|
-
if (e.data.type === PluginChannel.pluginReadyForRender) {
|
|
5
|
-
onReady();
|
|
6
|
-
}
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const onPluginFetchMessage = (e: MessageEvent, onRequest: (data: any) => void) => {
|
|
10
|
-
if (e.data.type === PluginChannel.fetchPluginMessage) {
|
|
11
|
-
onRequest(e.data);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const sendMessageToPlugin = (window: Window, props: any) => {
|
|
16
|
-
window.postMessage({ props, type: PluginChannel.renderPlugin }, '*');
|
|
17
|
-
};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { Loading3QuartersOutlined } from '@ant-design/icons';
|
|
2
|
-
import { Skeleton } from 'antd';
|
|
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
|
-
export interface FunctionMessageProps {
|
|
15
|
-
content: string;
|
|
16
|
-
loading?: boolean;
|
|
17
|
-
name?: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const PluginMessage = memo<FunctionMessageProps>(({ content, name }) => {
|
|
21
|
-
const { t } = useTranslation('plugin');
|
|
22
|
-
|
|
23
|
-
const manifest = usePluginStore((s) => s.pluginManifestMap[name || '']);
|
|
24
|
-
let isJSON = true;
|
|
25
|
-
try {
|
|
26
|
-
JSON.parse(content);
|
|
27
|
-
} catch {
|
|
28
|
-
isJSON = false;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const contentObj = useMemo(() => (isJSON ? JSON.parse(content) : content), [content]);
|
|
32
|
-
|
|
33
|
-
if (!isJSON) {
|
|
34
|
-
return (
|
|
35
|
-
<Flexbox gap={8} horizontal>
|
|
36
|
-
<div>
|
|
37
|
-
<Loading3QuartersOutlined spin />
|
|
38
|
-
</div>
|
|
39
|
-
{t('loading.content')}
|
|
40
|
-
</Flexbox>
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (!manifest?.ui) return;
|
|
45
|
-
|
|
46
|
-
const ui = manifest.ui;
|
|
47
|
-
|
|
48
|
-
if (!ui.url) return;
|
|
49
|
-
|
|
50
|
-
if (ui.mode === 'module')
|
|
51
|
-
return (
|
|
52
|
-
<Suspense fallback={<Skeleton active style={{ width: 300 }} />}>
|
|
53
|
-
<SystemJsRender content={contentObj} name={name || 'unknown'} url={ui.url} />
|
|
54
|
-
</Suspense>
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
return (
|
|
58
|
-
<IFrameRender
|
|
59
|
-
content={contentObj}
|
|
60
|
-
height={ui.height}
|
|
61
|
-
name={name || 'unknown'}
|
|
62
|
-
url={ui.url}
|
|
63
|
-
width={ui.width}
|
|
64
|
-
/>
|
|
65
|
-
);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
export default PluginMessage;
|
|
File without changes
|
|
File without changes
|