@lobehub/chat 0.68.0 → 0.69.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.
@@ -2,14 +2,14 @@ import { Avatar, Form, Icon, Tooltip } from '@lobehub/ui';
2
2
  import { Button, Skeleton, Switch, Tag } from 'antd';
3
3
  import { createStyles } from 'antd-style';
4
4
  import isEqual from 'fast-deep-equal';
5
- import { LucideBlocks, LucideStore } from 'lucide-react';
5
+ import { LucideBlocks, LucideStore, LucideTrash2 } from 'lucide-react';
6
6
  import { memo, useState } from 'react';
7
7
  import { useTranslation } from 'react-i18next';
8
8
  import { Flexbox } from 'react-layout-kit';
9
9
  import DevModal from 'src/features/PluginDevModal';
10
10
 
11
11
  import { FORM_STYLE } from '@/const/layoutTokens';
12
- import { pluginHelpers, usePluginStore } from '@/store/plugin';
12
+ import { pluginHelpers, pluginSelectors, usePluginStore } from '@/store/plugin';
13
13
 
14
14
  import { useStore } from '../store';
15
15
  import LocalPluginItem from './LocalPluginItem';
@@ -37,11 +37,7 @@ const MarketList = memo(() => {
37
37
 
38
38
  const [showModal, setModal] = useState(false);
39
39
 
40
- // useEffect(() => {
41
- // setModal(true);
42
- // }, []);
43
-
44
- const [plugins, hasPlugin, toggleAgentPlugin] = useStore((s) => [
40
+ const [userEnabledPlugins, hasPlugin, toggleAgentPlugin] = useStore((s) => [
45
41
  s.config.plugins || [],
46
42
  !!s.config.plugins,
47
43
  s.toggleAgentPlugin,
@@ -57,6 +53,7 @@ const MarketList = memo(() => {
57
53
  const pluginManifestLoading = usePluginStore((s) => s.pluginManifestLoading, isEqual);
58
54
  const pluginList = usePluginStore((s) => s.pluginList, isEqual);
59
55
  const customPluginList = usePluginStore((s) => s.customPluginList, isEqual);
56
+ const totalList = usePluginStore(pluginSelectors.pluginList, isEqual);
60
57
 
61
58
  useFetchPluginList();
62
59
 
@@ -100,7 +97,9 @@ const MarketList = memo(() => {
100
97
  <Switch
101
98
  checked={
102
99
  // 如果在加载中,说明激活了
103
- pluginManifestLoading[identifier] || !hasPlugin ? false : plugins.includes(identifier)
100
+ pluginManifestLoading[identifier] || !hasPlugin
101
+ ? false
102
+ : userEnabledPlugins.includes(identifier)
104
103
  }
105
104
  loading={pluginManifestLoading[identifier]}
106
105
  onChange={(checked) => {
@@ -132,6 +131,35 @@ const MarketList = memo(() => {
132
131
  tag: identifier,
133
132
  }));
134
133
 
134
+ // =========== Deprecated Plugin List =========== //
135
+
136
+ // 基于 userEnabledPlugins 和完整的 totalList,检查出不在 totalList 中的插件
137
+ const deprecatedList = userEnabledPlugins
138
+ .filter((pluginId) => totalList.findIndex((p) => p.identifier === pluginId) < 0)
139
+ .map((id) => ({
140
+ avatar: <Avatar avatar={'♻️'} />,
141
+ children: (
142
+ <Switch
143
+ checked={true}
144
+ onChange={(checked) => {
145
+ togglePlugin(id, checked);
146
+ }}
147
+ />
148
+ ),
149
+ label: (
150
+ <Flexbox align={'center'} gap={8} horizontal>
151
+ {id}
152
+ <Tag bordered={false} color={'red'}>
153
+ {t('list.item.deprecated.title', { ns: 'plugin' })}
154
+ </Tag>
155
+ </Flexbox>
156
+ ),
157
+ minWidth: undefined,
158
+ tag: id,
159
+ }));
160
+
161
+ const hasDeprecated = deprecatedList.length > 0;
162
+
135
163
  return (
136
164
  <>
137
165
  <DevModal
@@ -148,27 +176,44 @@ const MarketList = memo(() => {
148
176
  <Form
149
177
  items={[
150
178
  {
151
- children: isEmpty ? loadingList : [...customList, ...list],
179
+ children: isEmpty ? loadingList : [...deprecatedList, ...customList, ...list],
152
180
  extra: (
153
- <Tooltip title={t('settingPlugin.addTooltip')}>
154
- <Button
155
- icon={<Icon icon={LucideBlocks} />}
156
- onClick={(e) => {
157
- e.stopPropagation();
158
- setModal(true);
159
- }}
160
- size={'small'}
161
- >
162
- {t('settingPlugin.add')}
163
- </Button>
164
- </Tooltip>
181
+ <Flexbox gap={8} horizontal>
182
+ {hasDeprecated ? (
183
+ <Tooltip title={t('settingPlugin.clearDeprecated')}>
184
+ <Button
185
+ icon={<Icon icon={LucideTrash2} />}
186
+ onClick={(e) => {
187
+ e.stopPropagation();
188
+ for (const i of deprecatedList) {
189
+ togglePlugin(i.tag as string, false);
190
+ }
191
+ }}
192
+ size={'small'}
193
+ type={'text'}
194
+ ></Button>
195
+ </Tooltip>
196
+ ) : null}
197
+ <Tooltip title={t('settingPlugin.addTooltip')}>
198
+ <Button
199
+ icon={<Icon icon={LucideBlocks} />}
200
+ onClick={(e) => {
201
+ e.stopPropagation();
202
+ setModal(true);
203
+ }}
204
+ size={'small'}
205
+ >
206
+ {t('settingPlugin.add')}
207
+ </Button>
208
+ </Tooltip>
209
+ </Flexbox>
165
210
  ),
166
211
  icon: LucideStore,
167
212
  title: t('settingPlugin.title'),
168
213
  },
169
214
  ]}
170
215
  {...FORM_STYLE}
171
- />{' '}
216
+ />
172
217
  </>
173
218
  );
174
219
  });
@@ -1,8 +1,8 @@
1
1
  import { produce } from 'immer';
2
- import { merge } from 'lodash-es';
3
2
 
4
3
  import { DEFAULT_AGENT_CONFIG } from '@/const/settings';
5
4
  import { LobeAgentConfig } from '@/types/session';
5
+ import { merge } from '@/utils/merge';
6
6
 
7
7
  export type ConfigDispatch =
8
8
  | { config: Partial<any>; type: 'update' }
@@ -13,7 +13,7 @@ export const configReducer = (state: LobeAgentConfig, payload: ConfigDispatch):
13
13
  switch (payload.type) {
14
14
  case 'update': {
15
15
  return produce(state, (draftState) => {
16
- return merge({}, draftState, payload.config);
16
+ return merge(draftState, payload.config);
17
17
  });
18
18
  }
19
19
 
@@ -1,8 +1,8 @@
1
1
  import { produce } from 'immer';
2
- import { merge } from 'lodash-es';
3
2
 
4
3
  import { DEFAULT_AGENT_META } from '@/const/meta';
5
4
  import { MetaData } from '@/types/meta';
5
+ import { merge } from '@/utils/merge';
6
6
 
7
7
  export type MetaDataDispatch = { type: 'update'; value: Partial<MetaData> } | { type: 'reset' };
8
8
 
@@ -10,7 +10,7 @@ export const metaDataReducer = (state: MetaData, payload: MetaDataDispatch): Met
10
10
  switch (payload.type) {
11
11
  case 'update': {
12
12
  return produce(state, (draftState) => {
13
- return merge({}, draftState, payload.value);
13
+ return merge(draftState, payload.value);
14
14
  });
15
15
  }
16
16
 
@@ -10,7 +10,9 @@ const useStyle = createStyles(
10
10
  ({ css, token }) => css`
11
11
  cursor: pointer;
12
12
  border-radius: 50%;
13
- transition: scale 400ms ${token.motionEaseOut}, box-shadow 100ms ${token.motionEaseOut};
13
+ transition:
14
+ scale 400ms ${token.motionEaseOut},
15
+ box-shadow 100ms ${token.motionEaseOut};
14
16
 
15
17
  &:hover {
16
18
  box-shadow: 0 0 0 3px ${token.colorText};
@@ -21,7 +21,7 @@ const useStyles = createStyles(({ css, token, prefixCls }) => ({
21
21
  }
22
22
  `,
23
23
  root: css`
24
- backdrop-filter: blur(5px);
24
+ backdrop-filter: blur(2px);
25
25
  `,
26
26
  }));
27
27
 
@@ -82,6 +82,7 @@ export default {
82
82
  },
83
83
  list: {
84
84
  item: {
85
+ 'deprecated.title': '已删除',
85
86
  'local.config': '配置',
86
87
  'local.title': '自定义',
87
88
  },
@@ -1,4 +1,3 @@
1
-
2
1
  export default {
3
2
  danger: {
4
3
  clear: {
@@ -131,6 +130,7 @@ export default {
131
130
  settingPlugin: {
132
131
  add: '添加',
133
132
  addTooltip: '添加自定义插件',
133
+ clearDeprecated: '移除无效插件',
134
134
  config: '{{id}} 插件配置',
135
135
  title: '插件列表',
136
136
  },
@@ -5,12 +5,11 @@ import Document, { DocumentContext, Head, Html, Main, NextScript } from 'next/do
5
5
  class MyDocument extends Document {
6
6
  static async getInitialProps(ctx: DocumentContext) {
7
7
  const page = await ctx.renderPage({
8
- enhanceApp: (App) => (props) =>
9
- (
10
- <StyleProvider cache={extractStaticStyle.cache}>
11
- <App {...props} />
12
- </StyleProvider>
13
- ),
8
+ enhanceApp: (App) => (props) => (
9
+ <StyleProvider cache={extractStaticStyle.cache}>
10
+ <App {...props} />
11
+ </StyleProvider>
12
+ ),
14
13
  });
15
14
 
16
15
  const styles = extractStaticStyle(page.html).map((item) => item.style);
@@ -63,8 +63,10 @@ const Header = memo<{ mobile?: 'navbar' | 'search' }>(({ mobile }) => {
63
63
  </Flexbox>
64
64
  <SearchBar
65
65
  allowClear
66
+ enableShortKey
66
67
  onChange={(e) => useSessionStore.setState({ searchKeywords: e.target.value })}
67
68
  placeholder={t('searchAgentPlaceholder')}
69
+ shortKey={'k'}
68
70
  spotlight
69
71
  type={'ghost'}
70
72
  value={keywords}
@@ -11,7 +11,9 @@ const Footer = memo(() => {
11
11
 
12
12
  return (
13
13
  <Flexbox align={'center'} horizontal justify={'space-between'} style={{ padding: 16 }}>
14
- <span style={{ color: theme.colorTextDescription }}>©{new Date().getFullYear()} LobeHub</span>
14
+ <span style={{ color: theme.colorTextDescription }}>
15
+ ©{new Date().getFullYear()} LobeHub
16
+ </span>
15
17
  <Flexbox horizontal>
16
18
  <ActionIcon
17
19
  icon={DiscordIcon}
@@ -1,10 +1,10 @@
1
1
  import { t } from 'i18next';
2
- import { merge } from 'lodash-es';
3
2
 
4
3
  import { DEFAULT_AVATAR, DEFAULT_BACKGROUND_COLOR } from '@/const/meta';
5
4
  import { SessionStore } from '@/store/session';
6
5
  import { LanguageModel } from '@/types/llm';
7
6
  import { MetaData } from '@/types/meta';
7
+ import { merge } from '@/utils/merge';
8
8
 
9
9
  import { sessionSelectors } from '../session/selectors';
10
10
  import { initialLobeAgentConfig } from './initialState';
@@ -19,7 +19,7 @@ const currentAgentTitle = (s: SessionStore) => currentAgentMeta(s)?.title || t('
19
19
 
20
20
  const currentAgentConfig = (s: SessionStore) => {
21
21
  const session = sessionSelectors.currentSession(s);
22
- return merge({}, initialLobeAgentConfig, session?.config);
22
+ return merge(initialLobeAgentConfig, session?.config);
23
23
  };
24
24
 
25
25
  const currentAgentSystemRole = (s: SessionStore) => {
@@ -0,0 +1,11 @@
1
+ import { merge as _merge, mergeWith } from 'lodash-es';
2
+
3
+ /**
4
+ * 用于合并对象,如果是数组则直接替换
5
+ * @param target
6
+ * @param source
7
+ */
8
+ export const merge: typeof _merge = <T = object>(target: T, source: T) =>
9
+ mergeWith({}, target, source, (obj, src) => {
10
+ if (Array.isArray(obj)) return src;
11
+ });