@lobehub/chat 0.94.5 → 0.95.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/.github/workflows/pr-welcome.yml +1 -1
- package/CHANGELOG.md +35 -0
- 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/{FunctionCall.tsx → Inspector/index.tsx} +53 -25
- package/src/app/chat/features/Conversation/ChatList/Plugins/{IFrameRender → Render/DefaultType/IFrameRender}/index.tsx +5 -16
- package/src/app/chat/features/Conversation/ChatList/Plugins/{PluginMessage.tsx → Render/DefaultType/index.tsx} +3 -3
- 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/store/plugin/selectors.ts +10 -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/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/{PluginResultRender.tsx → Inspector/PluginResultJSON.tsx} +0 -0
- /package/src/app/chat/features/Conversation/ChatList/Plugins/{style.ts → Inspector/style.ts} +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,8 +1,10 @@
|
|
|
1
|
+
import isEqual from 'fast-deep-equal';
|
|
1
2
|
import { produce } from 'immer';
|
|
2
3
|
|
|
3
4
|
import { ChatMessage, ChatMessageMap } from '@/types/chatMessage';
|
|
4
5
|
import { LLMRoleType } from '@/types/llm';
|
|
5
6
|
import { MetaData } from '@/types/meta';
|
|
7
|
+
import { merge } from '@/utils/merge';
|
|
6
8
|
import { nanoid } from '@/utils/uuid';
|
|
7
9
|
|
|
8
10
|
interface AddMessage {
|
|
@@ -38,12 +40,20 @@ interface UpdateMessageExtra {
|
|
|
38
40
|
value: any;
|
|
39
41
|
}
|
|
40
42
|
|
|
43
|
+
interface UpdatePluginState {
|
|
44
|
+
id: string;
|
|
45
|
+
key: string;
|
|
46
|
+
type: 'updatePluginState';
|
|
47
|
+
value: any;
|
|
48
|
+
}
|
|
49
|
+
|
|
41
50
|
export type MessageDispatch =
|
|
42
51
|
| AddMessage
|
|
43
52
|
| DeleteMessage
|
|
44
53
|
| ResetMessages
|
|
45
54
|
| UpdateMessage
|
|
46
|
-
| UpdateMessageExtra
|
|
55
|
+
| UpdateMessageExtra
|
|
56
|
+
| UpdatePluginState;
|
|
47
57
|
|
|
48
58
|
export const messagesReducer = (
|
|
49
59
|
state: ChatMessageMap,
|
|
@@ -101,6 +111,26 @@ export const messagesReducer = (
|
|
|
101
111
|
});
|
|
102
112
|
}
|
|
103
113
|
|
|
114
|
+
case 'updatePluginState': {
|
|
115
|
+
return produce(state, (draftState) => {
|
|
116
|
+
const { id, key, value } = payload;
|
|
117
|
+
const message = draftState[id];
|
|
118
|
+
if (!message) return;
|
|
119
|
+
|
|
120
|
+
let newState;
|
|
121
|
+
if (!message.pluginState) {
|
|
122
|
+
newState = { [key]: value } as any;
|
|
123
|
+
} else {
|
|
124
|
+
newState = merge(message.pluginState, { [key]: value });
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (isEqual(message.pluginState, newState)) return;
|
|
128
|
+
|
|
129
|
+
message.pluginState = newState;
|
|
130
|
+
message.updateAt = Date.now();
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
104
134
|
case 'resetMessages': {
|
|
105
135
|
return produce(state, (draftState) => {
|
|
106
136
|
const { topicId } = payload;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { LobePluginType } from '@lobehub/chat-plugin-sdk';
|
|
1
2
|
import { t } from 'i18next';
|
|
2
3
|
|
|
3
|
-
import { FunctionCallProps } from '@/app/chat/features/Conversation/ChatList/Plugins/FunctionCall';
|
|
4
4
|
import { DEFAULT_INBOX_AVATAR, DEFAULT_USER_AVATAR } from '@/const/meta';
|
|
5
5
|
import { INBOX_SESSION_ID } from '@/const/session';
|
|
6
6
|
import { useGlobalStore } from '@/store/global';
|
|
@@ -92,22 +92,19 @@ export const chatsMessageString = (s: SessionStore): string => {
|
|
|
92
92
|
return chats.map((m) => m.content).join('');
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
export const
|
|
96
|
-
(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
loading: id === s.chatLoadingId,
|
|
112
|
-
};
|
|
113
|
-
};
|
|
95
|
+
export const getFunctionMessageProps =
|
|
96
|
+
({ plugin, content, id }: Pick<ChatMessage, 'plugin' | 'content' | 'id'>) =>
|
|
97
|
+
(s: SessionStore) => ({
|
|
98
|
+
arguments: plugin?.arguments,
|
|
99
|
+
command: plugin,
|
|
100
|
+
content,
|
|
101
|
+
id: plugin?.identifier,
|
|
102
|
+
loading: id === s.chatLoadingId,
|
|
103
|
+
type: plugin?.type as LobePluginType,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
export const getMessageById = (id: string) => (s: SessionStore) => {
|
|
107
|
+
for (const e of Object.values(s.sessions)) {
|
|
108
|
+
if (e.chats[id]) return e.chats[id];
|
|
109
|
+
}
|
|
110
|
+
};
|
|
@@ -4,7 +4,8 @@ import {
|
|
|
4
4
|
currentChatsWithGuideMessage,
|
|
5
5
|
currentChatsWithHistoryConfig,
|
|
6
6
|
getChatsById,
|
|
7
|
-
|
|
7
|
+
getFunctionMessageProps,
|
|
8
|
+
getMessageById,
|
|
8
9
|
} from './chat';
|
|
9
10
|
import { currentTopics, getTopicMessages } from './topic';
|
|
10
11
|
|
|
@@ -14,7 +15,8 @@ export const chatSelectors = {
|
|
|
14
15
|
currentChatsWithGuideMessage,
|
|
15
16
|
currentChatsWithHistoryConfig,
|
|
16
17
|
getChatsById,
|
|
17
|
-
|
|
18
|
+
getFunctionMessageProps,
|
|
19
|
+
getMessageById,
|
|
18
20
|
};
|
|
19
21
|
|
|
20
22
|
export const topicSelectors = {
|
package/src/types/chatMessage.ts
CHANGED
package/src/utils/message.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { FUNCTION_MESSAGE_FLAG } from '@/const/message';
|
|
2
2
|
|
|
3
|
-
export const
|
|
3
|
+
export const isFunctionMessageAtStart = (content: string) => {
|
|
4
4
|
return content.startsWith(FUNCTION_MESSAGE_FLAG);
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
+
export const testFunctionMessageAtEnd = (content: string) => {
|
|
8
|
+
const regExp = /{"function_call":.*?}}/;
|
|
9
|
+
const match = content.match(regExp);
|
|
10
|
+
|
|
11
|
+
return { content: match ? match[0] : '', valid: match };
|
|
12
|
+
};
|
|
13
|
+
|
|
7
14
|
// export const createFunctionCallMessage = () => {
|
|
8
15
|
// return [
|
|
9
16
|
// {
|
|
@@ -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
|
-
};
|
|
File without changes
|
/package/src/app/chat/features/Conversation/ChatList/Plugins/{style.ts → Inspector/style.ts}
RENAMED
|
File without changes
|
|
File without changes
|