@lobehub/chat 0.63.0 → 0.63.2
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 +50 -0
- package/package.json +1 -1
- package/src/features/AgentSetting/AgentConfig/index.tsx +6 -8
- package/src/features/AgentSetting/AgentMeta/index.tsx +35 -50
- package/src/features/AgentSetting/AgentPlugin/index.tsx +9 -15
- package/src/features/AgentSetting/AgentPrompt/index.tsx +10 -11
- package/src/features/AgentSetting/StoreUpdater.tsx +22 -0
- package/src/features/AgentSetting/index.tsx +25 -0
- package/src/features/AgentSetting/store/action.ts +212 -0
- package/src/features/AgentSetting/store/index.ts +12 -0
- package/src/features/AgentSetting/store/initialState.ts +28 -0
- package/src/features/AgentSetting/store/reducers/config.ts +43 -0
- package/src/features/AgentSetting/store/reducers/meta.ts +21 -0
- package/src/helpers/export.ts +2 -1
- package/src/pages/chat/SessionList/List/Item/Actions.tsx +2 -1
- package/src/pages/chat/SessionList/List/Item/index.tsx +3 -2
- package/src/pages/chat/SessionList/List/index.tsx +2 -1
- package/src/pages/chat/[id]/index.page.tsx +2 -1
- package/src/pages/chat/[id]/setting/index.page.tsx +10 -16
- package/src/pages/chat/features/Conversation/ChatList/MessageExtra.tsx +2 -1
- package/src/pages/chat/features/Conversation/ChatList/index.tsx +2 -6
- package/src/pages/chat/features/Conversation/Input/Action.tsx +2 -1
- package/src/pages/chat/features/Conversation/Input/Token.tsx +2 -1
- package/src/pages/chat/features/Header/Mobile.tsx +2 -1
- package/src/pages/chat/features/Header/PC.tsx +2 -1
- package/src/pages/chat/features/Sidebar/SystemRole.tsx +2 -1
- package/src/pages/chat/features/Sidebar/Topic/index.tsx +2 -1
- package/src/pages/index.page.tsx +2 -1
- package/src/pages/settings/Settings/Agent.tsx +13 -12
- package/src/store/global/slices/agent.ts +6 -57
- package/src/store/session/index.ts +0 -1
- package/src/store/session/initialState.ts +1 -3
- package/src/store/session/slices/agentConfig/action.ts +0 -193
- package/src/store/session/slices/agentConfig/initialState.ts +0 -18
- package/src/store/session/slices/agentConfig/selectors.ts +0 -9
- package/src/store/session/slices/chat/actions/message.ts +6 -6
- package/src/types/session.ts +8 -1
- package/src/features/AgentSetting/index.ts +0 -4
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { produce } from 'immer';
|
|
2
|
+
import { merge } from 'lodash-es';
|
|
3
|
+
|
|
4
|
+
import { DEFAULT_AGENT_META } from '@/const/meta';
|
|
5
|
+
import { MetaData } from '@/types/meta';
|
|
6
|
+
|
|
7
|
+
export type MetaDataDispatch = { type: 'update'; value: Partial<MetaData> } | { type: 'reset' };
|
|
8
|
+
|
|
9
|
+
export const metaDataReducer = (state: MetaData, payload: MetaDataDispatch): MetaData => {
|
|
10
|
+
switch (payload.type) {
|
|
11
|
+
case 'update': {
|
|
12
|
+
return produce(state, (draftState) => {
|
|
13
|
+
return merge({}, draftState, payload.value);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
case 'reset': {
|
|
18
|
+
return DEFAULT_AGENT_META;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
package/src/helpers/export.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { settingsSelectors, useGlobalStore } from '@/store/global';
|
|
2
|
-
import {
|
|
2
|
+
import { useSessionStore } from '@/store/session';
|
|
3
|
+
import { sessionSelectors } from '@/store/session/selectors';
|
|
3
4
|
import { createConfigFile, exportConfigFile } from '@/utils/config';
|
|
4
5
|
|
|
5
6
|
const getSessions = () => sessionSelectors.exportSessions(useSessionStore.getState());
|
|
@@ -6,7 +6,8 @@ import { memo, useMemo } from 'react';
|
|
|
6
6
|
import { useTranslation } from 'react-i18next';
|
|
7
7
|
|
|
8
8
|
import { exportSingleAgent, exportSingleSession } from '@/helpers/export';
|
|
9
|
-
import {
|
|
9
|
+
import { useSessionStore } from '@/store/session';
|
|
10
|
+
import { sessionSelectors } from '@/store/session/selectors';
|
|
10
11
|
|
|
11
12
|
const useStyles = createStyles(({ css }) => ({
|
|
12
13
|
modalRoot: css`
|
|
@@ -7,7 +7,8 @@ import { Flexbox } from 'react-layout-kit';
|
|
|
7
7
|
import { shallow } from 'zustand/shallow';
|
|
8
8
|
|
|
9
9
|
import { settingsSelectors, useGlobalStore } from '@/store/global';
|
|
10
|
-
import {
|
|
10
|
+
import { useSessionStore } from '@/store/session';
|
|
11
|
+
import { agentSelectors, sessionSelectors } from '@/store/session/selectors';
|
|
11
12
|
|
|
12
13
|
import Actions from './Actions';
|
|
13
14
|
|
|
@@ -55,7 +56,7 @@ const SessionItem = memo<SessionItemProps>(({ id }) => {
|
|
|
55
56
|
|
|
56
57
|
return [
|
|
57
58
|
s.activeId === id,
|
|
58
|
-
s.
|
|
59
|
+
!!s.chatLoadingId && id === s.activeId,
|
|
59
60
|
session.pinned,
|
|
60
61
|
agentSelectors.getTitle(meta),
|
|
61
62
|
agentSelectors.getDescription(meta),
|
|
@@ -2,7 +2,8 @@ import isEqual from 'fast-deep-equal';
|
|
|
2
2
|
import Link from 'next/link';
|
|
3
3
|
import { memo } from 'react';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { useSessionHydrated, useSessionStore } from '@/store/session';
|
|
6
|
+
import { sessionSelectors } from '@/store/session/selectors';
|
|
6
7
|
|
|
7
8
|
import AddButton from './AddButton';
|
|
8
9
|
import SessionItem from './Item';
|
|
@@ -3,7 +3,8 @@ import Head from 'next/head';
|
|
|
3
3
|
import { memo } from 'react';
|
|
4
4
|
import { Flexbox } from 'react-layout-kit';
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { useSessionStore } from '@/store/session';
|
|
7
|
+
import { agentSelectors } from '@/store/session/selectors';
|
|
7
8
|
import { genSiteHeadTitle } from '@/utils/genSiteHeadTitle';
|
|
8
9
|
|
|
9
10
|
import Conversation from '../features/Conversation';
|
|
@@ -7,8 +7,9 @@ import { Flexbox } from 'react-layout-kit';
|
|
|
7
7
|
|
|
8
8
|
import SafeSpacing from '@/components/SafeSpacing';
|
|
9
9
|
import { HEADER_HEIGHT } from '@/const/layoutTokens';
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
10
|
+
import AgentSetting from '@/features/AgentSetting';
|
|
11
|
+
import { useSessionStore } from '@/store/session';
|
|
12
|
+
import { agentSelectors } from '@/store/session/selectors';
|
|
12
13
|
import { genSiteHeadTitle } from '@/utils/genSiteHeadTitle';
|
|
13
14
|
|
|
14
15
|
import ChatLayout from '../layout';
|
|
@@ -20,10 +21,8 @@ const EditPage = memo(() => {
|
|
|
20
21
|
const { t } = useTranslation('setting');
|
|
21
22
|
const config = useSessionStore(agentSelectors.currentAgentConfig, isEqual);
|
|
22
23
|
const meta = useSessionStore(agentSelectors.currentAgentMeta, isEqual);
|
|
23
|
-
const
|
|
24
|
-
const [updateAgentConfig, toggleAgentPlugin, updateAgentMeta, title] = useSessionStore((s) => [
|
|
24
|
+
const [updateAgentConfig, updateAgentMeta, title] = useSessionStore((s) => [
|
|
25
25
|
s.updateAgentConfig,
|
|
26
|
-
s.toggleAgentPlugin,
|
|
27
26
|
s.updateAgentMeta,
|
|
28
27
|
agentSelectors.currentAgentTitle(s),
|
|
29
28
|
]);
|
|
@@ -31,17 +30,12 @@ const EditPage = memo(() => {
|
|
|
31
30
|
const pageTitle = genSiteHeadTitle(t('header.sessionWithName', { name: title }));
|
|
32
31
|
|
|
33
32
|
const settings = (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
updateMeta={updateAgentMeta}
|
|
41
|
-
/>
|
|
42
|
-
<AgentConfig config={config} updateConfig={updateAgentConfig} />
|
|
43
|
-
<AgentPlugin config={config} updateConfig={toggleAgentPlugin} />
|
|
44
|
-
</>
|
|
33
|
+
<AgentSetting
|
|
34
|
+
config={config}
|
|
35
|
+
meta={meta}
|
|
36
|
+
onConfigChange={updateAgentConfig}
|
|
37
|
+
onMetaChange={updateAgentMeta}
|
|
38
|
+
/>
|
|
45
39
|
);
|
|
46
40
|
|
|
47
41
|
return (
|
|
@@ -4,7 +4,8 @@ import { createStyles } from 'antd-style';
|
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
5
|
import { Flexbox } from 'react-layout-kit';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { useSessionStore } from '@/store/session';
|
|
8
|
+
import { agentSelectors } from '@/store/session/selectors';
|
|
8
9
|
import { ChatMessage } from '@/types/chatMessage';
|
|
9
10
|
|
|
10
11
|
const useStyles = createStyles(({ css }) => ({
|
|
@@ -4,12 +4,8 @@ import { memo, useCallback } from 'react';
|
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
5
5
|
import { Flexbox } from 'react-layout-kit';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
chatSelectors,
|
|
10
|
-
useSessionChatInit,
|
|
11
|
-
useSessionStore,
|
|
12
|
-
} from '@/store/session';
|
|
7
|
+
import { useSessionChatInit, useSessionStore } from '@/store/session';
|
|
8
|
+
import { agentSelectors, chatSelectors } from '@/store/session/selectors';
|
|
13
9
|
import { ChatMessage } from '@/types/chatMessage';
|
|
14
10
|
import { isFunctionMessage } from '@/utils/message';
|
|
15
11
|
|
|
@@ -5,7 +5,8 @@ import { memo } from 'react';
|
|
|
5
5
|
import { useTranslation } from 'react-i18next';
|
|
6
6
|
import { Flexbox } from 'react-layout-kit';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { useSessionStore } from '@/store/session';
|
|
9
|
+
import { agentSelectors } from '@/store/session/selectors';
|
|
9
10
|
import { LanguageModel } from '@/types/llm';
|
|
10
11
|
|
|
11
12
|
const InputActions = memo(() => {
|
|
@@ -4,7 +4,8 @@ import { memo, useMemo } from 'react';
|
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
5
5
|
|
|
6
6
|
import { ModelTokens } from '@/const/modelTokens';
|
|
7
|
-
import {
|
|
7
|
+
import { useSessionStore } from '@/store/session';
|
|
8
|
+
import { agentSelectors, chatSelectors } from '@/store/session/selectors';
|
|
8
9
|
|
|
9
10
|
const Token = memo<{ input: string }>(({ input }) => {
|
|
10
11
|
const { t } = useTranslation('common');
|
|
@@ -6,7 +6,8 @@ import { useTranslation } from 'react-i18next';
|
|
|
6
6
|
|
|
7
7
|
import { INBOX_SESSION_ID } from '@/const/session';
|
|
8
8
|
import { useGlobalStore } from '@/store/global';
|
|
9
|
-
import {
|
|
9
|
+
import { useSessionStore } from '@/store/session';
|
|
10
|
+
import { agentSelectors } from '@/store/session/selectors';
|
|
10
11
|
|
|
11
12
|
const MobileHeader = memo<{ settings?: boolean }>(({ settings = true }) => {
|
|
12
13
|
const { t } = useTranslation('common');
|
|
@@ -9,7 +9,8 @@ import { Flexbox } from 'react-layout-kit';
|
|
|
9
9
|
|
|
10
10
|
import { INBOX_SESSION_ID } from '@/const/session';
|
|
11
11
|
import { useGlobalStore } from '@/store/global';
|
|
12
|
-
import {
|
|
12
|
+
import { useSessionChatInit, useSessionStore } from '@/store/session';
|
|
13
|
+
import { agentSelectors } from '@/store/session/selectors';
|
|
13
14
|
|
|
14
15
|
import PluginTag from './PluginTag';
|
|
15
16
|
import ShareButton from './ShareButton';
|
|
@@ -7,7 +7,8 @@ import { useTranslation } from 'react-i18next';
|
|
|
7
7
|
import { Flexbox } from 'react-layout-kit';
|
|
8
8
|
|
|
9
9
|
import Header from '@/pages/chat/features/Sidebar/Header';
|
|
10
|
-
import {
|
|
10
|
+
import { useSessionChatInit, useSessionStore } from '@/store/session';
|
|
11
|
+
import { agentSelectors } from '@/store/session/selectors';
|
|
11
12
|
|
|
12
13
|
const useStyles = createStyles(({ css, token }) => ({
|
|
13
14
|
prompt: css`
|
|
@@ -5,7 +5,8 @@ import { Flexbox } from 'react-layout-kit';
|
|
|
5
5
|
|
|
6
6
|
import Empty from '@/components/Empty';
|
|
7
7
|
import { useGlobalStore } from '@/store/global';
|
|
8
|
-
import {
|
|
8
|
+
import { useSessionChatInit, useSessionStore } from '@/store/session';
|
|
9
|
+
import { topicSelectors } from '@/store/session/selectors';
|
|
9
10
|
|
|
10
11
|
import SkeletonList from './SkeletonList';
|
|
11
12
|
import TopicItem from './TopicItem';
|
package/src/pages/index.page.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { memo } from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { useSessionHydrated, useSessionStore } from '@/store/session';
|
|
4
|
+
import { sessionSelectors } from '@/store/session/selectors';
|
|
4
5
|
|
|
5
6
|
import Chat from './chat/index.page';
|
|
6
7
|
import Loading from './index/Loading';
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import isEqual from 'fast-deep-equal';
|
|
2
2
|
import { memo } from 'react';
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import AgentSetting from '@/features/AgentSetting';
|
|
5
5
|
import { settingsSelectors, useGlobalStore } from '@/store/global';
|
|
6
6
|
|
|
7
7
|
const Agent = memo(() => {
|
|
8
8
|
const config = useGlobalStore(settingsSelectors.currentAgentConfig, isEqual);
|
|
9
9
|
const meta = useGlobalStore(settingsSelectors.currentAgentMeta, isEqual);
|
|
10
|
-
const [
|
|
11
|
-
|
|
12
|
-
s.setAgentMeta,
|
|
13
|
-
s.toggleAgentPlugin,
|
|
14
|
-
]);
|
|
10
|
+
const [updateAgent] = useGlobalStore((s) => [s.updateDefaultAgent]);
|
|
11
|
+
|
|
15
12
|
return (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
<AgentSetting
|
|
14
|
+
config={config}
|
|
15
|
+
meta={meta}
|
|
16
|
+
onConfigChange={(config) => {
|
|
17
|
+
updateAgent({ config });
|
|
18
|
+
}}
|
|
19
|
+
onMetaChange={(meta) => {
|
|
20
|
+
updateAgent({ meta });
|
|
21
|
+
}}
|
|
22
|
+
/>
|
|
22
23
|
);
|
|
23
24
|
});
|
|
24
25
|
|
|
@@ -2,10 +2,7 @@ import { produce } from 'immer';
|
|
|
2
2
|
import { merge } from 'lodash-es';
|
|
3
3
|
import type { StateCreator } from 'zustand/vanilla';
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import { MetaData } from '@/types/meta';
|
|
7
|
-
import type { LobeAgentSession } from '@/types/session';
|
|
8
|
-
import { LobeAgentConfig } from '@/types/session';
|
|
5
|
+
import { LobeAgentSettings } from '@/types/session';
|
|
9
6
|
import type { GlobalSettings } from '@/types/settings';
|
|
10
7
|
import { setNamespace } from '@/utils/storeDebug';
|
|
11
8
|
|
|
@@ -17,12 +14,7 @@ const t = setNamespace('settings');
|
|
|
17
14
|
* 设置操作
|
|
18
15
|
*/
|
|
19
16
|
export interface AgentAction {
|
|
20
|
-
|
|
21
|
-
resetAgentMeta: () => void;
|
|
22
|
-
resetDefaultAgent: () => void;
|
|
23
|
-
setAgentConfig: (config: Partial<LobeAgentSession['config']>) => void;
|
|
24
|
-
setAgentMeta: (meta: Partial<LobeAgentSession['meta']>) => void;
|
|
25
|
-
toggleAgentPlugin: (pluginId: string) => void;
|
|
17
|
+
updateDefaultAgent: (agent: Partial<LobeAgentSettings>) => void;
|
|
26
18
|
}
|
|
27
19
|
|
|
28
20
|
export const createAgentSlice: StateCreator<
|
|
@@ -31,55 +23,12 @@ export const createAgentSlice: StateCreator<
|
|
|
31
23
|
[],
|
|
32
24
|
AgentAction
|
|
33
25
|
> = (set, get) => ({
|
|
34
|
-
|
|
26
|
+
updateDefaultAgent: (agent) => {
|
|
35
27
|
const settings = produce(get().settings, (draft: GlobalSettings) => {
|
|
36
|
-
draft.defaultAgent
|
|
37
|
-
|
|
38
|
-
set({ settings }, false, t('resetAgentConfig'));
|
|
39
|
-
},
|
|
40
|
-
resetAgentMeta: () => {
|
|
41
|
-
const settings = produce(get().settings, (draft: GlobalSettings) => {
|
|
42
|
-
draft.defaultAgent.meta = DEFAULT_AGENT.meta;
|
|
43
|
-
});
|
|
44
|
-
set({ settings }, false, t('resetAgentMeta'));
|
|
45
|
-
},
|
|
46
|
-
resetDefaultAgent: () => {
|
|
47
|
-
const settings = produce(get().settings, (draft: GlobalSettings) => {
|
|
48
|
-
draft.defaultAgent = DEFAULT_AGENT;
|
|
49
|
-
});
|
|
50
|
-
set({ settings }, false, t('resetDefaultAgent'));
|
|
51
|
-
},
|
|
52
|
-
setAgentConfig: (config) => {
|
|
53
|
-
const settings = produce(get().settings, (draft: GlobalSettings) => {
|
|
54
|
-
const oldConfig = draft.defaultAgent.config as LobeAgentConfig;
|
|
55
|
-
draft.defaultAgent.config = merge({}, oldConfig, config);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
set({ settings }, false, t('setAgentConfig', config));
|
|
59
|
-
},
|
|
60
|
-
setAgentMeta: (meta) => {
|
|
61
|
-
const settings = produce(get().settings, (draft) => {
|
|
62
|
-
const oldMeta = draft.defaultAgent.meta as MetaData;
|
|
63
|
-
draft.defaultAgent.meta = merge({}, oldMeta, meta);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
set({ settings }, false, t('setAgentMeta', meta));
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
toggleAgentPlugin: (id: string) => {
|
|
70
|
-
const settings = produce(get().settings, (draft: GlobalSettings) => {
|
|
71
|
-
const oldConfig = draft.defaultAgent.config as LobeAgentConfig;
|
|
72
|
-
if (oldConfig.plugins === undefined) {
|
|
73
|
-
oldConfig.plugins = [id];
|
|
74
|
-
} else {
|
|
75
|
-
if (oldConfig.plugins.includes(id)) {
|
|
76
|
-
oldConfig.plugins.splice(oldConfig.plugins.indexOf(id), 1);
|
|
77
|
-
} else {
|
|
78
|
-
oldConfig.plugins.push(id);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
28
|
+
const oldAgent = draft.defaultAgent as LobeAgentSettings;
|
|
29
|
+
draft.defaultAgent = merge({}, oldAgent, agent);
|
|
81
30
|
});
|
|
82
31
|
|
|
83
|
-
set({ settings }, false, t('
|
|
32
|
+
set({ settings }, false, t('updateDefaultAgent', agent));
|
|
84
33
|
},
|
|
85
34
|
});
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { AgentConfigState, initialAgentConfigState } from './slices/agentConfig/initialState';
|
|
2
1
|
import { ChatState, initialChatState } from './slices/chat/initialState';
|
|
3
2
|
import { SessionState, initialSessionState } from './slices/session/initialState';
|
|
4
3
|
|
|
5
|
-
export type SessionStoreState = SessionState & ChatState
|
|
4
|
+
export type SessionStoreState = SessionState & ChatState;
|
|
6
5
|
|
|
7
6
|
export const initialState: SessionStoreState = {
|
|
8
7
|
...initialSessionState,
|
|
9
8
|
...initialChatState,
|
|
10
|
-
...initialAgentConfigState,
|
|
11
9
|
};
|
|
12
10
|
|
|
13
11
|
export { initialLobeAgentConfig } from './slices/agentConfig';
|
|
@@ -1,66 +1,21 @@
|
|
|
1
|
-
import { produce } from 'immer';
|
|
2
1
|
import { StateCreator } from 'zustand/vanilla';
|
|
3
2
|
|
|
4
|
-
import { promptPickEmoji, promptSummaryAgentName, promptSummaryDescription } from '@/prompts/agent';
|
|
5
3
|
import { MetaData } from '@/types/meta';
|
|
6
4
|
import { LobeAgentConfig } from '@/types/session';
|
|
7
|
-
import { fetchPresetTaskResult } from '@/utils/fetch';
|
|
8
|
-
import { setNamespace } from '@/utils/storeDebug';
|
|
9
5
|
|
|
10
6
|
import { SessionStore } from '../../store';
|
|
11
7
|
import { sessionSelectors } from '../session/selectors';
|
|
12
|
-
import { SessionLoadingState } from './initialState';
|
|
13
|
-
|
|
14
|
-
const t = setNamespace('agentConfig');
|
|
15
8
|
|
|
16
9
|
/**
|
|
17
10
|
* 代理行为接口
|
|
18
11
|
*/
|
|
19
12
|
export interface AgentAction {
|
|
20
|
-
/**
|
|
21
|
-
* 自动选择表情
|
|
22
|
-
* @param id - 表情的 ID
|
|
23
|
-
*/
|
|
24
|
-
autoPickEmoji: (id: string) => void;
|
|
25
|
-
/**
|
|
26
|
-
* 自动完成代理描述
|
|
27
|
-
* @param id - 代理的 ID
|
|
28
|
-
* @returns 一个 Promise,用于异步操作完成后的处理
|
|
29
|
-
*/
|
|
30
|
-
autocompleteAgentDescription: (id: string) => Promise<void>;
|
|
31
|
-
/**
|
|
32
|
-
* 自动完成代理标题
|
|
33
|
-
* @param id - 代理的 ID
|
|
34
|
-
* @returns 一个 Promise,用于异步操作完成后的处理
|
|
35
|
-
*/
|
|
36
|
-
autocompleteAgentTitle: (id: string) => Promise<void>;
|
|
37
|
-
autocompleteMeta: (key: keyof MetaData) => void;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 自动完成会话代理元数据
|
|
41
|
-
* @param id - 代理的 ID
|
|
42
|
-
*/
|
|
43
|
-
autocompleteSessionAgentMeta: (id: string, replace?: boolean) => void;
|
|
44
|
-
/**
|
|
45
|
-
* 内部更新代理元数据
|
|
46
|
-
* @param id - 代理的 ID
|
|
47
|
-
* @returns 任意类型的返回值
|
|
48
|
-
*/
|
|
49
|
-
internalUpdateAgentMeta: (id: string) => any;
|
|
50
|
-
|
|
51
|
-
toggleAgentPlugin: (pluginId: string, checked: boolean) => void;
|
|
52
13
|
/**
|
|
53
14
|
* 更新代理配置
|
|
54
15
|
* @param config - 部分 LobeAgentConfig 的配置
|
|
55
16
|
*/
|
|
56
17
|
updateAgentConfig: (config: Partial<LobeAgentConfig>) => void;
|
|
57
18
|
updateAgentMeta: (meta: Partial<MetaData>) => void;
|
|
58
|
-
/**
|
|
59
|
-
* 更新加载状态
|
|
60
|
-
* @param key - SessionLoadingState 的键
|
|
61
|
-
* @param value - 加载状态的值
|
|
62
|
-
*/
|
|
63
|
-
updateLoadingState: (key: keyof SessionLoadingState, value: boolean) => void;
|
|
64
19
|
}
|
|
65
20
|
|
|
66
21
|
export const createAgentSlice: StateCreator<
|
|
@@ -69,147 +24,6 @@ export const createAgentSlice: StateCreator<
|
|
|
69
24
|
[],
|
|
70
25
|
AgentAction
|
|
71
26
|
> = (set, get) => ({
|
|
72
|
-
autoPickEmoji: async (id) => {
|
|
73
|
-
const { dispatchSession } = get();
|
|
74
|
-
const session = sessionSelectors.getSessionById(id)(get());
|
|
75
|
-
if (!session) return;
|
|
76
|
-
|
|
77
|
-
const systemRole = session.config.systemRole;
|
|
78
|
-
|
|
79
|
-
const emoji = await fetchPresetTaskResult({
|
|
80
|
-
onLoadingChange: (loading) => {
|
|
81
|
-
get().updateLoadingState('avatar', loading);
|
|
82
|
-
},
|
|
83
|
-
params: promptPickEmoji(systemRole),
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
if (emoji) {
|
|
87
|
-
dispatchSession({ id, key: 'avatar', type: 'updateSessionMeta', value: emoji });
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
autocompleteAgentDescription: async (id) => {
|
|
92
|
-
const { dispatchSession, updateLoadingState, internalUpdateAgentMeta } = get();
|
|
93
|
-
const session = sessionSelectors.getSessionById(id)(get());
|
|
94
|
-
if (!session) return;
|
|
95
|
-
|
|
96
|
-
const systemRole = session.config.systemRole;
|
|
97
|
-
|
|
98
|
-
if (!systemRole) return;
|
|
99
|
-
|
|
100
|
-
const preValue = session.meta.description;
|
|
101
|
-
|
|
102
|
-
// 替换为 ...
|
|
103
|
-
dispatchSession({ id, key: 'description', type: 'updateSessionMeta', value: '...' });
|
|
104
|
-
|
|
105
|
-
fetchPresetTaskResult({
|
|
106
|
-
onError: () => {
|
|
107
|
-
dispatchSession({
|
|
108
|
-
id,
|
|
109
|
-
key: 'description',
|
|
110
|
-
type: 'updateSessionMeta',
|
|
111
|
-
value: preValue,
|
|
112
|
-
});
|
|
113
|
-
},
|
|
114
|
-
onLoadingChange: (loading) => {
|
|
115
|
-
updateLoadingState('description', loading);
|
|
116
|
-
},
|
|
117
|
-
onMessageHandle: internalUpdateAgentMeta(id)('description'),
|
|
118
|
-
params: promptSummaryDescription(systemRole),
|
|
119
|
-
});
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
autocompleteAgentTitle: async (id) => {
|
|
123
|
-
const { dispatchSession, updateLoadingState, internalUpdateAgentMeta } = get();
|
|
124
|
-
const session = sessionSelectors.getSessionById(id)(get());
|
|
125
|
-
if (!session) return;
|
|
126
|
-
|
|
127
|
-
const systemRole = session.config.systemRole;
|
|
128
|
-
|
|
129
|
-
if (!systemRole) return;
|
|
130
|
-
|
|
131
|
-
const previousTitle = session.meta.title;
|
|
132
|
-
|
|
133
|
-
// 替换为 ...
|
|
134
|
-
dispatchSession({ id, key: 'title', type: 'updateSessionMeta', value: '...' });
|
|
135
|
-
|
|
136
|
-
fetchPresetTaskResult({
|
|
137
|
-
onError: () => {
|
|
138
|
-
dispatchSession({ id, key: 'title', type: 'updateSessionMeta', value: previousTitle });
|
|
139
|
-
},
|
|
140
|
-
onLoadingChange: (loading) => {
|
|
141
|
-
updateLoadingState('title', loading);
|
|
142
|
-
},
|
|
143
|
-
onMessageHandle: internalUpdateAgentMeta(id)('title'),
|
|
144
|
-
params: promptSummaryAgentName(systemRole),
|
|
145
|
-
});
|
|
146
|
-
},
|
|
147
|
-
|
|
148
|
-
autocompleteMeta: (key) => {
|
|
149
|
-
const { activeId, autoPickEmoji, autocompleteAgentTitle, autocompleteAgentDescription } = get();
|
|
150
|
-
if (!activeId) return;
|
|
151
|
-
|
|
152
|
-
switch (key) {
|
|
153
|
-
case 'avatar': {
|
|
154
|
-
autoPickEmoji(activeId);
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
case 'description': {
|
|
159
|
-
autocompleteAgentDescription(activeId);
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
case 'title': {
|
|
164
|
-
autocompleteAgentTitle(activeId);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
|
|
169
|
-
autocompleteSessionAgentMeta: (id, replace) => {
|
|
170
|
-
const session = sessionSelectors.getSessionById(id)(get());
|
|
171
|
-
|
|
172
|
-
if (!session) return;
|
|
173
|
-
|
|
174
|
-
if (!session.meta.title || replace) {
|
|
175
|
-
get().autocompleteAgentTitle(id);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (!session.meta.description || replace) {
|
|
179
|
-
get().autocompleteAgentDescription(id);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (!session.meta.avatar || replace) {
|
|
183
|
-
get().autoPickEmoji(id);
|
|
184
|
-
}
|
|
185
|
-
},
|
|
186
|
-
internalUpdateAgentMeta: (id: string) => (key: keyof MetaData) => {
|
|
187
|
-
let value = '';
|
|
188
|
-
return (text: string) => {
|
|
189
|
-
value += text;
|
|
190
|
-
get().dispatchSession({ id, key, type: 'updateSessionMeta', value });
|
|
191
|
-
};
|
|
192
|
-
},
|
|
193
|
-
toggleAgentPlugin: (id: string) => {
|
|
194
|
-
const { activeId } = get();
|
|
195
|
-
const session = sessionSelectors.currentSession(get());
|
|
196
|
-
if (!activeId || !session) return;
|
|
197
|
-
|
|
198
|
-
const config = produce(session.config, (draft) => {
|
|
199
|
-
if (draft.plugins === undefined) {
|
|
200
|
-
draft.plugins = [id];
|
|
201
|
-
} else {
|
|
202
|
-
const plugins = draft.plugins;
|
|
203
|
-
if (plugins.includes(id)) {
|
|
204
|
-
plugins.splice(plugins.indexOf(id), 1);
|
|
205
|
-
} else {
|
|
206
|
-
plugins.push(id);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
get().dispatchSession({ config, id: activeId, type: 'updateSessionConfig' });
|
|
212
|
-
},
|
|
213
27
|
updateAgentConfig: (config) => {
|
|
214
28
|
const { activeId } = get();
|
|
215
29
|
const session = sessionSelectors.currentSession(get());
|
|
@@ -233,11 +47,4 @@ export const createAgentSlice: StateCreator<
|
|
|
233
47
|
}
|
|
234
48
|
}
|
|
235
49
|
},
|
|
236
|
-
updateLoadingState: (key, value) => {
|
|
237
|
-
set(
|
|
238
|
-
{ autocompleteLoading: { ...get().autocompleteLoading, [key]: value } },
|
|
239
|
-
false,
|
|
240
|
-
t('updateLoadingState', { key, value }),
|
|
241
|
-
);
|
|
242
|
-
},
|
|
243
50
|
});
|
|
@@ -1,22 +1,4 @@
|
|
|
1
1
|
import { DEFAULT_AGENT_CONFIG } from '@/const/settings';
|
|
2
|
-
import { MetaData } from '@/types/meta';
|
|
3
2
|
import { LobeAgentConfig } from '@/types/session';
|
|
4
3
|
|
|
5
|
-
export type SessionLoadingState = Record<Partial<keyof MetaData>, boolean>;
|
|
6
|
-
|
|
7
|
-
export interface AgentConfigState {
|
|
8
|
-
autocompleteLoading: SessionLoadingState;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
4
|
export const initialLobeAgentConfig: LobeAgentConfig = DEFAULT_AGENT_CONFIG;
|
|
12
|
-
|
|
13
|
-
export const initialAgentConfigState: AgentConfigState = {
|
|
14
|
-
// // loading 中间态
|
|
15
|
-
autocompleteLoading: {
|
|
16
|
-
avatar: false,
|
|
17
|
-
backgroundColor: false,
|
|
18
|
-
description: false,
|
|
19
|
-
tag: false,
|
|
20
|
-
title: false,
|
|
21
|
-
},
|
|
22
|
-
};
|
|
@@ -2,7 +2,6 @@ import { t } from 'i18next';
|
|
|
2
2
|
import { merge } from 'lodash-es';
|
|
3
3
|
|
|
4
4
|
import { DEFAULT_AVATAR, DEFAULT_BACKGROUND_COLOR } from '@/const/meta';
|
|
5
|
-
import { Autocomplete } from '@/features/AgentSetting/AgentMeta';
|
|
6
5
|
import { SessionStore } from '@/store/session';
|
|
7
6
|
import { LanguageModel } from '@/types/llm';
|
|
8
7
|
import { MetaData } from '@/types/meta';
|
|
@@ -16,13 +15,6 @@ const currentAgentMeta = (s: SessionStore): MetaData => {
|
|
|
16
15
|
return { avatar: DEFAULT_AVATAR, backgroundColor: DEFAULT_BACKGROUND_COLOR, ...session?.meta };
|
|
17
16
|
};
|
|
18
17
|
|
|
19
|
-
const currentAutocomplete = (s: SessionStore): Autocomplete => ({
|
|
20
|
-
autocompleteMeta: s.autocompleteMeta,
|
|
21
|
-
autocompleteSessionAgentMeta: s.autocompleteSessionAgentMeta,
|
|
22
|
-
id: s.activeId,
|
|
23
|
-
loading: s.autocompleteLoading,
|
|
24
|
-
});
|
|
25
|
-
|
|
26
18
|
const currentAgentTitle = (s: SessionStore) => currentAgentMeta(s)?.title || t('defaultSession');
|
|
27
19
|
|
|
28
20
|
const currentAgentConfig = (s: SessionStore) => {
|
|
@@ -84,7 +76,6 @@ export const agentSelectors = {
|
|
|
84
76
|
currentAgentPlugins,
|
|
85
77
|
currentAgentSystemRole,
|
|
86
78
|
currentAgentTitle,
|
|
87
|
-
currentAutocomplete,
|
|
88
79
|
getAvatar,
|
|
89
80
|
getDescription,
|
|
90
81
|
getTitle,
|