@lobehub/lobehub 2.0.0-next.266 → 2.0.0-next.268

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.
Files changed (136) hide show
  1. package/.cursor/rules/microcopy-cn.mdc +75 -63
  2. package/.cursor/rules/microcopy-en.mdc +4 -8
  3. package/CHANGELOG.md +50 -0
  4. package/README.md +8 -8
  5. package/README.zh-CN.md +8 -8
  6. package/apps/desktop/src/main/locales/default/common.ts +2 -2
  7. package/changelog/v1.json +10 -0
  8. package/docs/development/database-schema.dbml +4 -0
  9. package/e2e/CLAUDE.md +43 -81
  10. package/e2e/cucumber.config.js +1 -0
  11. package/e2e/docs/local-setup.md +67 -219
  12. package/e2e/scripts/setup.ts +529 -0
  13. package/e2e/src/features/home/sidebarAgent.feature +62 -0
  14. package/e2e/src/features/home/sidebarGroup.feature +62 -0
  15. package/e2e/src/features/page/README.md +118 -0
  16. package/e2e/src/features/page/crud.feature +62 -0
  17. package/e2e/src/features/page/editor-content.feature +93 -0
  18. package/e2e/src/features/page/editor-meta.feature +60 -0
  19. package/e2e/src/steps/agent/conversation.steps.ts +4 -4
  20. package/e2e/src/steps/home/sidebarAgent.steps.ts +370 -0
  21. package/e2e/src/steps/home/sidebarGroup.steps.ts +168 -0
  22. package/e2e/src/steps/hooks.ts +4 -0
  23. package/e2e/src/steps/page/editor-content.steps.ts +344 -0
  24. package/e2e/src/steps/page/editor-meta.steps.ts +410 -0
  25. package/e2e/src/steps/page/page-crud.steps.ts +363 -0
  26. package/e2e/src/support/world.ts +12 -0
  27. package/locales/ar/file.json +2 -0
  28. package/locales/bg-BG/file.json +2 -0
  29. package/locales/de-DE/file.json +2 -0
  30. package/locales/en-US/auth.json +1 -1
  31. package/locales/en-US/file.json +2 -0
  32. package/locales/en-US/metadata.json +2 -2
  33. package/locales/es-ES/file.json +2 -0
  34. package/locales/fa-IR/file.json +2 -0
  35. package/locales/fr-FR/file.json +2 -0
  36. package/locales/it-IT/file.json +2 -0
  37. package/locales/ja-JP/file.json +2 -0
  38. package/locales/ko-KR/file.json +2 -0
  39. package/locales/nl-NL/file.json +2 -0
  40. package/locales/pl-PL/file.json +2 -0
  41. package/locales/pt-BR/file.json +2 -0
  42. package/locales/ru-RU/file.json +2 -0
  43. package/locales/tr-TR/file.json +2 -0
  44. package/locales/vi-VN/file.json +2 -0
  45. package/locales/zh-CN/file.json +2 -0
  46. package/locales/zh-TW/file.json +2 -0
  47. package/package.json +3 -3
  48. package/packages/builtin-agents/src/agents/agent-builder/index.ts +1 -1
  49. package/packages/builtin-agents/src/agents/group-agent-builder/index.ts +1 -1
  50. package/packages/builtin-agents/src/agents/page-agent/index.ts +1 -1
  51. package/packages/const/src/settings/group.ts +0 -10
  52. package/packages/database/migrations/0068_update_group_data.sql +4 -0
  53. package/packages/database/migrations/meta/0068_snapshot.json +9588 -0
  54. package/packages/database/migrations/meta/_journal.json +7 -0
  55. package/packages/database/src/models/__tests__/chatGroup.test.ts +5 -7
  56. package/packages/database/src/models/__tests__/knowledgeBase.test.ts +185 -0
  57. package/packages/database/src/models/knowledgeBase.ts +67 -3
  58. package/packages/database/src/repositories/agentGroup/index.test.ts +23 -29
  59. package/packages/database/src/repositories/agentGroup/index.ts +4 -9
  60. package/packages/database/src/repositories/knowledge/index.ts +3 -3
  61. package/packages/database/src/schemas/chatGroup.ts +4 -3
  62. package/packages/database/src/types/chatGroup.ts +0 -7
  63. package/packages/types/src/agentGroup/index.ts +30 -9
  64. package/packages/utils/src/multimodalContent.test.ts +302 -0
  65. package/packages/utils/src/server/__tests__/sse.test.ts +353 -0
  66. package/src/app/[variants]/(main)/home/_layout/Body/Agent/List/AgentGroupItem/Editing.tsx +4 -11
  67. package/src/app/[variants]/(main)/home/_layout/Body/Agent/List/AgentGroupItem/index.tsx +3 -3
  68. package/src/app/[variants]/(main)/home/_layout/Body/Agent/ModalProvider.tsx +9 -32
  69. package/src/app/[variants]/(main)/home/_layout/hooks/useCreateMenuItems.tsx +3 -37
  70. package/src/app/[variants]/(main)/home/_layout/hooks/useSessionGroupMenuItems.tsx +7 -53
  71. package/src/app/[variants]/(main)/home/features/RecentPage/List.tsx +2 -1
  72. package/src/app/[variants]/(main)/resource/features/DndContextWrapper.tsx +1 -1
  73. package/src/app/[variants]/(main)/resource/library/_layout/Sidebar.tsx +2 -2
  74. package/src/app/[variants]/(main)/resource/library/features/LibraryMenu.tsx +2 -2
  75. package/src/app/[variants]/(mobile)/chat/settings/features/SettingButton.tsx +2 -12
  76. package/src/components/ChatGroupWizard/ChatGroupWizard.tsx +5 -27
  77. package/src/components/DragUpload/index.tsx +24 -27
  78. package/src/components/MemberSelectionModal/MemberSelectionModal.tsx +2 -11
  79. package/src/features/ChatInput/ActionBar/Params/Controls.tsx +42 -7
  80. package/src/features/CommandMenu/useCommandMenu.ts +4 -14
  81. package/src/features/ResourceManager/components/Editor/index.tsx +2 -3
  82. package/src/features/ResourceManager/components/Explorer/Header/index.tsx +13 -17
  83. package/src/features/ResourceManager/components/Explorer/ItemDropdown/useFileItemDropdown.tsx +1 -1
  84. package/src/features/ResourceManager/components/Explorer/ListView/ListItem/TruncatedFileName.tsx +130 -0
  85. package/src/features/ResourceManager/components/Explorer/ListView/ListItem/index.tsx +36 -4
  86. package/src/features/ResourceManager/components/Explorer/ListView/Skeleton.tsx +4 -3
  87. package/src/features/ResourceManager/components/Explorer/ListView/index.tsx +58 -2
  88. package/src/features/ResourceManager/components/Explorer/MasonryView/index.tsx +58 -6
  89. package/src/features/ResourceManager/components/Explorer/MoveToFolderModal.tsx +2 -5
  90. package/src/features/ResourceManager/components/Explorer/ToolBar/BatchActionsDropdown.tsx +9 -5
  91. package/src/features/ResourceManager/components/Explorer/index.tsx +11 -56
  92. package/src/features/ResourceManager/components/Header/AddButton.tsx +5 -6
  93. package/src/features/ResourceManager/components/LibraryHierarchy/HierarchyNode.tsx +382 -0
  94. package/src/features/ResourceManager/components/LibraryHierarchy/index.tsx +396 -0
  95. package/src/features/ResourceManager/components/LibraryHierarchy/styles.ts +19 -0
  96. package/src/features/ResourceManager/components/LibraryHierarchy/treeState.ts +178 -0
  97. package/src/features/ResourceManager/components/LibraryHierarchy/types.ts +10 -0
  98. package/src/features/ResourceManager/index.tsx +3 -0
  99. package/src/layout/GlobalProvider/GroupWizardProvider.tsx +6 -29
  100. package/src/locales/default/auth.ts +1 -1
  101. package/src/locales/default/file.ts +2 -0
  102. package/src/locales/default/metadata.ts +2 -2
  103. package/src/server/modules/AgentRuntime/AgentRuntimeCoordinator.ts +30 -30
  104. package/src/server/modules/AgentRuntime/AgentStateManager.ts +23 -23
  105. package/src/server/modules/AgentRuntime/InMemoryAgentStateManager.ts +16 -16
  106. package/src/server/modules/AgentRuntime/InMemoryStreamEventManager.ts +13 -13
  107. package/src/server/modules/AgentRuntime/RuntimeExecutors.ts +2 -2
  108. package/src/server/modules/AgentRuntime/StreamEventManager.ts +18 -18
  109. package/src/server/modules/AgentRuntime/types.ts +21 -21
  110. package/src/server/routers/lambda/__tests__/agentGroup.test.ts +8 -8
  111. package/src/server/routers/lambda/agentGroup.ts +10 -12
  112. package/src/server/services/document/index.ts +1 -0
  113. package/src/store/agentGroup/slices/curd.test.ts +4 -4
  114. package/src/store/file/slices/fileManager/action.ts +12 -4
  115. package/src/store/home/slices/homeInput/action.ts +0 -3
  116. package/src/store/home/slices/sidebarUI/action.ts +9 -0
  117. package/src/store/session/slices/session/action.ts +5 -9
  118. package/src/app/[variants]/(mobile)/chat/settings/features/AgentTeamSettings/index.tsx +0 -95
  119. package/src/features/GroupChatSettings/AgentCard.tsx +0 -154
  120. package/src/features/GroupChatSettings/AgentTeamChatSettings.tsx +0 -179
  121. package/src/features/GroupChatSettings/AgentTeamMembersSettings.tsx +0 -244
  122. package/src/features/GroupChatSettings/AgentTeamMetaSettings.tsx +0 -94
  123. package/src/features/GroupChatSettings/AgentTeamSettings.tsx +0 -54
  124. package/src/features/GroupChatSettings/GroupCategory/index.tsx +0 -30
  125. package/src/features/GroupChatSettings/GroupCategory/useGroupCategory.tsx +0 -42
  126. package/src/features/GroupChatSettings/GroupChatSettingsProvider.tsx +0 -19
  127. package/src/features/GroupChatSettings/HostMemberCard.tsx +0 -113
  128. package/src/features/GroupChatSettings/StoreUpdater.tsx +0 -34
  129. package/src/features/GroupChatSettings/hooks/useGroupChatSettings.ts +0 -25
  130. package/src/features/GroupChatSettings/index.ts +0 -16
  131. package/src/features/GroupChatSettings/store/action.ts +0 -105
  132. package/src/features/GroupChatSettings/store/index.ts +0 -18
  133. package/src/features/GroupChatSettings/store/initialState.ts +0 -23
  134. package/src/features/GroupChatSettings/store/selectors.ts +0 -13
  135. package/src/features/ResourceManager/components/Tree/index.tsx +0 -883
  136. /package/src/features/ResourceManager/components/{Tree → LibraryHierarchy}/TreeSkeleton.tsx +0 -0
@@ -1,54 +0,0 @@
1
- import { Skeleton } from '@lobehub/ui';
2
- import { type ReactNode, Suspense, memo } from 'react';
3
-
4
- import { GroupSettingsTabs } from '@/store/global/initialState';
5
- import { useServerConfigStore } from '@/store/serverConfig';
6
-
7
- import AgentTeamChatSettings from './AgentTeamChatSettings';
8
- import AgentTeamMembersSettings from './AgentTeamMembersSettings';
9
- import AgentTeamMetaSettings from './AgentTeamMetaSettings';
10
- import { GroupChatSettingsProvider } from './GroupChatSettingsProvider';
11
- import { type StoreUpdaterProps } from './StoreUpdater';
12
-
13
- export interface AgentTeamSettingsProps extends StoreUpdaterProps {
14
- tab?: GroupSettingsTabs;
15
- }
16
-
17
- export interface AgentTeamSettingsContentProps {
18
- loadingSkeleton?: ReactNode;
19
- tab: GroupSettingsTabs;
20
- }
21
-
22
- const AgentTeamSettingsContent = memo<AgentTeamSettingsContentProps>(({ tab }) => {
23
- return (
24
- <>
25
- {tab === GroupSettingsTabs.Settings && <AgentTeamMetaSettings />}
26
- {tab === GroupSettingsTabs.Members && <AgentTeamMembersSettings />}
27
- {tab === GroupSettingsTabs.Chat && <AgentTeamChatSettings />}
28
- </>
29
- );
30
- });
31
-
32
- const AgentTeamSettings = memo<AgentTeamSettingsProps>(
33
- ({ tab = GroupSettingsTabs.Settings, ...rest }) => {
34
- const isMobile = useServerConfigStore((s) => s.isMobile);
35
- const loadingSkeleton = (
36
- <Skeleton
37
- active
38
- paragraph={{ rows: 6 }}
39
- style={{ padding: isMobile ? 16 : 0 }}
40
- title={false}
41
- />
42
- );
43
-
44
- return (
45
- <GroupChatSettingsProvider {...rest}>
46
- <Suspense fallback={loadingSkeleton}>
47
- <AgentTeamSettingsContent tab={tab} />
48
- </Suspense>
49
- </GroupChatSettingsProvider>
50
- );
51
- },
52
- );
53
-
54
- export default AgentTeamSettings;
@@ -1,30 +0,0 @@
1
- 'use client';
2
-
3
- import { memo } from 'react';
4
-
5
- import Menu from '@/components/Menu';
6
- import { type GroupSettingsTabs } from '@/store/global/initialState';
7
-
8
- import { useChatGroupSettingsCategory } from './useGroupCategory';
9
-
10
- interface GroupCategoryProps {
11
- setTab: (tab: GroupSettingsTabs) => void;
12
- tab: string;
13
- }
14
-
15
- const GroupCategory = memo<GroupCategoryProps>(({ setTab, tab }) => {
16
- const cateItems = useChatGroupSettingsCategory();
17
- return (
18
- <Menu
19
- compact
20
- items={cateItems}
21
- onClick={({ key }) => {
22
- setTab(key as GroupSettingsTabs);
23
- }}
24
- selectable
25
- selectedKeys={[tab as any]}
26
- />
27
- );
28
- });
29
-
30
- export default GroupCategory;
@@ -1,42 +0,0 @@
1
- import { Icon } from '@lobehub/ui';
2
- import { MessagesSquare, Settings, Users } from 'lucide-react';
3
- import { useMemo } from 'react';
4
- import { useTranslation } from 'react-i18next';
5
-
6
- import type { MenuProps } from '@/components/Menu';
7
- import { GroupSettingsTabs } from '@/store/global/initialState';
8
-
9
- interface UseChatGroupSettingsCategoryOptions {
10
- mobile?: boolean;
11
- }
12
-
13
- export const useChatGroupSettingsCategory = ({
14
- mobile,
15
- }: UseChatGroupSettingsCategoryOptions = {}) => {
16
- const { t } = useTranslation('setting');
17
- const iconSize = mobile ? 20 : undefined;
18
-
19
- const cateItems: MenuProps['items'] = useMemo(
20
- () =>
21
- [
22
- {
23
- icon: <Icon icon={Settings} size={iconSize} />,
24
- key: GroupSettingsTabs.Settings,
25
- label: t('groupTab.meta'),
26
- },
27
- {
28
- icon: <Icon icon={MessagesSquare} size={iconSize} />,
29
- key: GroupSettingsTabs.Chat,
30
- label: t('groupTab.chat'),
31
- },
32
- {
33
- icon: <Icon icon={Users} size={iconSize} />,
34
- key: GroupSettingsTabs.Members,
35
- label: t('groupTab.members'),
36
- },
37
- ].filter(Boolean) as MenuProps['items'],
38
- [t, iconSize],
39
- );
40
-
41
- return cateItems;
42
- };
@@ -1,19 +0,0 @@
1
- import { type ReactNode, memo } from 'react';
2
-
3
- import StoreUpdater, { type StoreUpdaterProps } from './StoreUpdater';
4
- import { Provider, createStore } from './store';
5
-
6
- interface GroupChatSettingsProviderProps extends StoreUpdaterProps {
7
- children: ReactNode;
8
- }
9
-
10
- export const GroupChatSettingsProvider = memo<GroupChatSettingsProviderProps>(
11
- ({ children, ...props }) => {
12
- return (
13
- <Provider createStore={createStore}>
14
- <StoreUpdater {...props} />
15
- {children}
16
- </Provider>
17
- );
18
- },
19
- );
@@ -1,113 +0,0 @@
1
- 'use client';
2
-
3
- import { Avatar, Flexbox, Icon, Text, Tooltip } from '@lobehub/ui';
4
- import { Switch } from 'antd';
5
- import { createStaticStyles, cssVar, cx } from 'antd-style';
6
- import { Bot, Loader2 } from 'lucide-react';
7
- import { memo } from 'react';
8
- import { useTranslation } from 'react-i18next';
9
-
10
- import { DEFAULT_SUPERVISOR_AVATAR } from '@/const/meta';
11
- import { useIsDark } from '@/hooks/useIsDark';
12
-
13
- const styles = createStaticStyles(({ css }) => ({
14
- container: css`
15
- position: relative;
16
-
17
- overflow: hidden;
18
-
19
- height: 100%;
20
- border-radius: 12px;
21
-
22
- background: ${cssVar.colorBgContainer};
23
-
24
- transition: border-color 0.2s ${cssVar.motionEaseInOut};
25
-
26
- &:hover {
27
- border-color: ${cssVar.colorPrimary};
28
- }
29
- `,
30
- containerDark: css`
31
- border: 1px solid ${cssVar.colorBorder};
32
- `,
33
- containerLight: css`
34
- border: 1px solid ${cssVar.colorBorderSecondary};
35
- `,
36
- desc: css`
37
- overflow: hidden;
38
-
39
- height: 3em;
40
- margin-block-end: 0 !important;
41
-
42
- line-height: 1.5;
43
- color: ${cssVar.colorTextDescription};
44
- `,
45
- title: css`
46
- line-height: 1.3;
47
- `,
48
- }));
49
-
50
- interface HostMemberCardProps {
51
- checked: boolean;
52
- loading: boolean;
53
- onToggle: (checked: boolean) => void;
54
- }
55
-
56
- const HostMemberCard = memo<HostMemberCardProps>(({ checked, loading, onToggle }) => {
57
- const isDarkMode = useIsDark();
58
- const { t } = useTranslation('setting');
59
-
60
- const title = t('settingGroupMembers.host.title');
61
- const description = t('settingGroupMembers.host.description');
62
- const tooltip = checked
63
- ? t('settingGroupMembers.disableHost')
64
- : t('settingGroupMembers.enableHost');
65
-
66
- return (
67
- <Flexbox
68
- className={cx(styles.container, isDarkMode ? styles.containerDark : styles.containerLight)}
69
- gap={24}
70
- >
71
- <Flexbox gap={12} padding={16} width={'100%'}>
72
- <Flexbox gap={12} width={'100%'}>
73
- <Flexbox align={'center'} horizontal justify={'space-between'}>
74
- <Flexbox align={'center'} flex={1} gap={8} horizontal style={{ minWidth: 0 }}>
75
- <Avatar
76
- avatar={DEFAULT_SUPERVISOR_AVATAR}
77
- shape={'square'}
78
- size={24}
79
- style={{ flexShrink: 0 }}
80
- />
81
- <Text
82
- className={styles.title}
83
- ellipsis
84
- style={{ fontSize: 16, fontWeight: 'bold', minWidth: 0 }}
85
- >
86
- {title}
87
- </Text>
88
- <Tooltip title={t('settingGroupMembers.groupHost')}>
89
- <Icon icon={Bot} size="small" style={{ color: '#1890ff' }} />
90
- </Tooltip>
91
- </Flexbox>
92
- </Flexbox>
93
- <Text
94
- className={styles.desc}
95
- ellipsis={{
96
- rows: 2,
97
- }}
98
- >
99
- {description}
100
- </Text>
101
- </Flexbox>
102
- <Flexbox align="center" horizontal justify={'space-between'} width={'100%'}>
103
- <Icon icon={Loader2} size="small" spin style={{ opacity: loading ? 1 : 0 }} />
104
- <Tooltip title={tooltip}>
105
- <Switch checked={checked} disabled={loading} onChange={onToggle} size="small" />
106
- </Tooltip>
107
- </Flexbox>
108
- </Flexbox>
109
- </Flexbox>
110
- );
111
- });
112
-
113
- export default HostMemberCard;
@@ -1,34 +0,0 @@
1
- 'use client';
2
-
3
- import { type ForwardedRef, memo, useImperativeHandle } from 'react';
4
- import { createStoreUpdater } from 'zustand-utils';
5
-
6
- import { type GroupChatSettingsInstance, useGroupChatSettings } from './hooks/useGroupChatSettings';
7
- import { type State, useStoreApi } from './store';
8
-
9
- export interface StoreUpdaterProps extends Partial<
10
- Pick<State, 'onMetaChange' | 'onConfigChange' | 'meta' | 'config' | 'id' | 'loading'>
11
- > {
12
- instanceRef?: ForwardedRef<GroupChatSettingsInstance> | null;
13
- }
14
-
15
- const StoreUpdater = memo<StoreUpdaterProps>(
16
- ({ onConfigChange, instanceRef, id, onMetaChange, meta, config, loading }) => {
17
- const storeApi = useStoreApi();
18
- const useStoreUpdater = createStoreUpdater(storeApi);
19
-
20
- useStoreUpdater('meta', meta);
21
- useStoreUpdater('config', config);
22
- useStoreUpdater('onConfigChange', onConfigChange);
23
- useStoreUpdater('onMetaChange', onMetaChange);
24
- useStoreUpdater('loading', loading);
25
- useStoreUpdater('id', id);
26
-
27
- const instance = useGroupChatSettings();
28
- useImperativeHandle(instanceRef, () => instance);
29
-
30
- return null;
31
- },
32
- );
33
-
34
- export default StoreUpdater;
@@ -1,25 +0,0 @@
1
- 'use client';
2
-
3
- import { useMemo } from 'react';
4
-
5
- import { useStoreApi } from '../store';
6
- import { type PublicAction } from '../store/action';
7
-
8
- export type GroupChatSettingsInstance = PublicAction;
9
-
10
- export const useGroupChatSettings = (): GroupChatSettingsInstance => {
11
- const storeApi = useStoreApi();
12
-
13
- const { updateGroupConfig, updateGroupMeta, resetGroupConfig, resetGroupMeta } =
14
- storeApi.getState();
15
-
16
- return useMemo(
17
- () => ({
18
- resetGroupConfig,
19
- resetGroupMeta,
20
- updateGroupConfig,
21
- updateGroupMeta,
22
- }),
23
- [],
24
- );
25
- };
@@ -1,16 +0,0 @@
1
- export { default as AgentTeamChatSettings } from './AgentTeamChatSettings';
2
- export { default as GroupMembersConfig } from './AgentTeamMembersSettings';
3
- export { default as ChatGroupMeta } from './AgentTeamMetaSettings';
4
- export { default as AgentTeamSettings } from './AgentTeamSettings';
5
- export { default as GroupCategory } from './GroupCategory';
6
- export { GroupChatSettingsProvider } from './GroupChatSettingsProvider';
7
-
8
- // Hooks
9
- export type { GroupChatSettingsInstance } from './hooks/useGroupChatSettings';
10
- export { useGroupChatSettings } from './hooks/useGroupChatSettings';
11
-
12
- // Store
13
- export {
14
- selectors as groupChatSettingsSelectors,
15
- useStore as useGroupChatSettingsStore,
16
- } from './store';
@@ -1,105 +0,0 @@
1
- import type { PartialDeep } from 'type-fest';
2
- import { type StateCreator } from 'zustand/vanilla';
3
-
4
- import { DEFAULT_CHAT_GROUP_CHAT_CONFIG, DEFAULT_CHAT_GROUP_META_CONFIG } from '@/const/settings';
5
- import { type LobeChatGroupConfig, type LobeChatGroupMetaConfig } from '@/types/agentGroup';
6
- import { setNamespace } from '@/utils/storeDebug';
7
-
8
- import { type LoadingState, type State, initialState } from './initialState';
9
-
10
- export interface PublicAction {
11
- /**
12
- * Reset group configuration to default
13
- */
14
- resetGroupConfig: () => Promise<void>;
15
- /**
16
- * Reset group metadata to default
17
- */
18
- resetGroupMeta: () => Promise<void>;
19
- /**
20
- * Update group configuration
21
- */
22
- updateGroupConfig: (config: Partial<LobeChatGroupConfig>) => Promise<void>;
23
- /**
24
- * Update group metadata
25
- */
26
- updateGroupMeta: (meta: Partial<LobeChatGroupMetaConfig>) => Promise<void>;
27
- }
28
-
29
- export interface Action extends PublicAction {
30
- setGroupConfig: (config: PartialDeep<LobeChatGroupConfig>) => Promise<void>;
31
- setGroupMeta: (meta: Partial<LobeChatGroupMetaConfig>) => Promise<void>;
32
-
33
- /**
34
- * Update loading state
35
- * @param key - LoadingState key
36
- * @param value - Loading state value
37
- */
38
- updateLoadingState: (key: keyof LoadingState, value: boolean) => void;
39
- }
40
-
41
- export type Store = Action & State;
42
-
43
- const t = setNamespace('GroupChatSettings');
44
-
45
- export const store: StateCreator<Store, [['zustand/devtools', never]]> = (set, get) => ({
46
- ...initialState,
47
-
48
- resetGroupConfig: async () => {
49
- const { onConfigChange } = get();
50
-
51
- const defaultConfig = DEFAULT_CHAT_GROUP_CHAT_CONFIG;
52
-
53
- await onConfigChange?.(defaultConfig);
54
- set({ config: defaultConfig }, false, t('resetGroupConfig'));
55
- },
56
-
57
- resetGroupMeta: async () => {
58
- const { onMetaChange } = get();
59
-
60
- const defaultMeta = DEFAULT_CHAT_GROUP_META_CONFIG;
61
-
62
- await onMetaChange?.(defaultMeta);
63
- set({ meta: defaultMeta }, false, t('resetGroupMeta'));
64
- },
65
-
66
- setGroupConfig: async (config) => {
67
- const { onConfigChange } = get();
68
- const currentConfig = get().config || DEFAULT_CHAT_GROUP_CHAT_CONFIG;
69
- const newConfig = { ...currentConfig, ...config };
70
-
71
- await onConfigChange?.(newConfig);
72
- set({ config: newConfig }, false, t('setGroupConfig'));
73
- },
74
-
75
- setGroupMeta: async (meta) => {
76
- const { onMetaChange } = get();
77
- const currentMeta = get().meta || DEFAULT_CHAT_GROUP_META_CONFIG;
78
- const newMeta = { ...currentMeta, ...meta };
79
-
80
- await onMetaChange?.(newMeta);
81
- set({ meta: newMeta }, false, t('setGroupMeta'));
82
- },
83
-
84
- updateGroupConfig: async (config) => {
85
- await get().setGroupConfig(config);
86
- },
87
-
88
- updateGroupMeta: async (meta) => {
89
- await get().setGroupMeta(meta);
90
- },
91
-
92
- updateLoadingState: (key, value) => {
93
- const { loadingState } = get();
94
- set(
95
- {
96
- loadingState: {
97
- ...loadingState,
98
- [key]: value,
99
- },
100
- },
101
- false,
102
- t('updateLoadingState', { [key]: value }),
103
- );
104
- },
105
- });
@@ -1,18 +0,0 @@
1
- 'use client';
2
-
3
- import { createContext } from 'zustand-utils';
4
- import { subscribeWithSelector } from 'zustand/middleware';
5
- import { shallow } from 'zustand/shallow';
6
- import { createWithEqualityFn } from 'zustand/traditional';
7
-
8
- import { type StoreApiWithSelector } from '@/types/zustand';
9
-
10
- import { type Store, store } from './action';
11
-
12
- export type { State } from './initialState';
13
-
14
- export const createStore = () => createWithEqualityFn(subscribeWithSelector(store), shallow);
15
-
16
- export const { useStore, useStoreApi, Provider } = createContext<StoreApiWithSelector<Store>>();
17
-
18
- export { selectors } from './selectors';
@@ -1,23 +0,0 @@
1
- import { DEFAULT_CHAT_GROUP_CHAT_CONFIG, DEFAULT_CHAT_GROUP_META_CONFIG } from '@/const/settings';
2
- import { type LobeChatGroupConfig, type LobeChatGroupMetaConfig } from '@/types/agentGroup';
3
-
4
- export type LoadingState = Record<string, boolean>;
5
-
6
- export interface State {
7
- config?: LobeChatGroupConfig;
8
- id?: string;
9
- loading?: boolean;
10
- loadingState?: LoadingState;
11
- meta?: LobeChatGroupMetaConfig;
12
- onConfigChange?: (config: LobeChatGroupConfig) => void;
13
- onMetaChange?: (meta: LobeChatGroupMetaConfig) => void;
14
- }
15
-
16
- export const initialState: State = {
17
- config: DEFAULT_CHAT_GROUP_CHAT_CONFIG,
18
- loading: true,
19
- loadingState: {
20
- meta: false,
21
- },
22
- meta: DEFAULT_CHAT_GROUP_META_CONFIG,
23
- };
@@ -1,13 +0,0 @@
1
- import { DEFAULT_CHAT_GROUP_CHAT_CONFIG, DEFAULT_CHAT_GROUP_META_CONFIG } from '@/const/settings';
2
- import { merge } from '@/utils/merge';
3
-
4
- import { type State } from './initialState';
5
-
6
- const currentChatConfig = (s: State) => merge(DEFAULT_CHAT_GROUP_CHAT_CONFIG, s.config);
7
-
8
- const currentMetaConfig = (s: State) => merge(DEFAULT_CHAT_GROUP_META_CONFIG, s.meta);
9
-
10
- export const selectors = {
11
- currentChatConfig,
12
- currentMetaConfig,
13
- };