🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
♻️ refactor(group): scope group reads to explicit groupId (#16152)
Arvin Xuca1875fa9fe7
diff --git a/packages/builtin-tool-group-agent-builder/src/ExecutionRuntime/index.ts b/packages/builtin-tool-group-agent-builder/src/ExecutionRuntime/index.tsindex e7ea8daccfd..1a7b9fa8661 100644--- a/packages/builtin-tool-group-agent-builder/src/ExecutionRuntime/index.ts+++ b/packages/builtin-tool-group-agent-builder/src/ExecutionRuntime/index.ts@@ -680,7 +680,9 @@ export class GroupAgentBuilderExecutionRuntime {private async resolveGroupTarget(groupId?: string) {const state = getChatGroupStoreState();- const currentGroup = agentGroupSelectors.currentGroup(state);+ const currentGroup = state.activeGroupId+ ? agentGroupSelectors.getGroupById(state.activeGroupId)(state)+ : undefined;const targetGroupId = groupId ?? currentGroup?.id;if (!targetGroupId) {diff --git a/packages/builtin-tool-group-agent-builder/src/client/Inspector/UpdateAgentPrompt/index.tsx b/packages/builtin-tool-group-agent-builder/src/client/Inspector/UpdateAgentPrompt/index.tsxindex 4fad43b6e2c..6e50e050833 100644--- a/packages/builtin-tool-group-agent-builder/src/client/Inspector/UpdateAgentPrompt/index.tsx+++ b/packages/builtin-tool-group-agent-builder/src/client/Inspector/UpdateAgentPrompt/index.tsx@@ -47,7 +47,7 @@ export const UpdateAgentPromptInspector = memo<// Get agent info from the current groupconst agent = useAgentGroupStore((s) => {- const agents = agentGroupSelectors.currentGroupAgents(s);+ const agents = s.activeGroupId ? agentGroupSelectors.getGroupAgents(s.activeGroupId)(s) : [];return agents.find((a) => a.id === agentId);});diff --git a/src/features/Conversation/Messages/Supervisor/index.tsx b/src/features/Conversation/Messages/Supervisor/index.tsxindex 20b21918a90..5293b8e508d 100644--- a/src/features/Conversation/Messages/Supervisor/index.tsx+++ b/src/features/Conversation/Messages/Supervisor/index.tsx@@ -17,7 +17,7 @@ import { userGeneralSettingsSelectors, userProfileSelectors } from '@/store/userimport { ReactionDisplay } from '../../components/Reaction';import { useAgentMeta } from '../../hooks';-import { dataSelectors, useConversationStore } from '../../store';+import { contextSelectors, dataSelectors, useConversationStore } from '../../store';import Usage from '../components/Extras/Usage';import MessageBranch from '../components/MessageBranch';import {@@ -49,14 +49,16 @@ const GroupMessage = memo<GroupMessageProps>(({ id, index, disableEditing }) =>item;const avatar = useAgentMeta(agentId);+ const groupId = useConversationStore(contextSelectors.groupId);+// Get group member avatars for GroupAvatarconst memberAvatars = useAgentGroupStore(- (s) => agentGroupSelectors.currentGroupMemberAvatars(s),+ (s) => agentGroupSelectors.getGroupMemberAvatars(groupId ?? '')(s),isEqual,);// Get group meta for title- const groupMeta = useAgentGroupStore(agentGroupSelectors.currentGroupMeta);+ const groupMeta = useAgentGroupStore((s) => agentGroupSelectors.getGroupMeta(groupId ?? '')(s));// Get editing state from ConversationStoreconst isDevMode = useUserStore((s) => userGeneralSettingsSelectors.config(s).isDevMode);diff --git a/src/features/Conversation/store/slices/context/selectors.ts b/src/features/Conversation/store/slices/context/selectors.tsindex 86dd25828f0..7b939b2996c 100644--- a/src/features/Conversation/store/slices/context/selectors.ts+++ b/src/features/Conversation/store/slices/context/selectors.ts@@ -4,6 +4,7 @@ import { type State } from '../../initialState';const context = (s: State) => s.context;const agentId = (s: State) => s.context.agentId;+const groupId = (s: State) => s.context.groupId;const topicId = (s: State) => s.context.topicId;const threadId = (s: State) => s.context.threadId;const isThread = (s: State) => !!s.context.threadId;@@ -29,6 +30,7 @@ export const contextSelectors = {agentId,context,conversationKey,+ groupId,hook,hooks,isThread,diff --git a/src/routes/(main)/group/_layout/Sidebar/GroupConfig/GroupRole.tsx b/src/routes/(main)/group/_layout/Sidebar/GroupConfig/GroupRole.tsxindex d815bb69ff9..13a088f13af 100644--- a/src/routes/(main)/group/_layout/Sidebar/GroupConfig/GroupRole.tsx+++ b/src/routes/(main)/group/_layout/Sidebar/GroupConfig/GroupRole.tsx@@ -5,6 +5,7 @@ import { EditableMessage } from '@lobehub/ui/chat';import { type MouseEvent } from 'react';import { memo } from 'react';import { useTranslation } from 'react-i18next';+import { useParams } from 'react-router';import GroupInfo from '@/features/GroupInfo';import { usePermission } from '@/hooks/usePermission';@@ -27,9 +28,10 @@ const GroupRole = memo<GroupRoleProps>(const { t } = useTranslation('chat');const { allowed: canEdit } = usePermission('edit_own_content');+ const { gid } = useParams<{ gid: string }>();const activeGroupId = useAgentGroupStore((s) => s.activeGroupId);const updateGroupConfig = useAgentGroupStore((s) => s.updateGroupConfig);- const groupConfig = useAgentGroupStore(agentGroupSelectors.currentGroupConfig);+ const groupConfig = useAgentGroupStore((s) => agentGroupSelectors.getGroupConfig(gid ?? '')(s));const handleSystemPromptChange = async (value: string) => {if (!canEdit) return;diff --git a/src/routes/(main)/group/_layout/Sidebar/GroupConfig/Header/index.tsx b/src/routes/(main)/group/_layout/Sidebar/GroupConfig/Header/index.tsxindex 57bab4c6624..ca435bdba42 100644--- a/src/routes/(main)/group/_layout/Sidebar/GroupConfig/Header/index.tsx+++ b/src/routes/(main)/group/_layout/Sidebar/GroupConfig/Header/index.tsx@@ -3,6 +3,7 @@import { Flexbox, Text } from '@lobehub/ui';import { memo } from 'react';import { useTranslation } from 'react-i18next';+import { useParams } from 'react-router';import { useAgentGroupStore } from '@/store/agentGroup';import { agentGroupSelectors } from '@/store/agentGroup/selectors';@@ -11,7 +12,8 @@ import Avatar from './Avatar';const HeaderInfo = memo(() => {const { t } = useTranslation('chat');- const groupMeta = useAgentGroupStore(agentGroupSelectors.currentGroupMeta);+ const { gid } = useParams<{ gid: string }>();+ const groupMeta = useAgentGroupStore((s) => agentGroupSelectors.getGroupMeta(gid ?? '')(s));const displayTitle = groupMeta.title || t('untitledGroup');diff --git a/src/routes/(main)/group/_layout/Sidebar/Header/Agent/index.tsx b/src/routes/(main)/group/_layout/Sidebar/Header/Agent/index.tsxindex 91efc6880e8..3271de98bc9 100644--- a/src/routes/(main)/group/_layout/Sidebar/Header/Agent/index.tsx+++ b/src/routes/(main)/group/_layout/Sidebar/Header/Agent/index.tsx@@ -5,6 +5,7 @@ import { ChevronsUpDownIcon } from 'lucide-react';import { type PropsWithChildren } from 'react';import React, { memo } from 'react';import { useTranslation } from 'react-i18next';+import { useParams } from 'react-router';import { SkeletonItem } from '@/features/NavPanel/components/SkeletonList';import SupervisorAvatar from '@/routes/(main)/group/features/GroupAvatar';@@ -16,9 +17,10 @@ import SwitchPanel from './SwitchPanel';const Agent = memo<PropsWithChildren>(() => {const { t } = useTranslation(['chat', 'common']);+ const { gid } = useParams<{ gid: string }>();const [isGroupsInit, groupMeta] = useAgentGroupStore((s) => [agentGroupSelectors.isGroupsInit(s),- agentGroupSelectors.currentGroupMeta(s),+ agentGroupSelectors.getGroupMeta(gid ?? '')(s),]);const displayTitle = groupMeta?.title || t('untitledGroup', { ns: 'chat' });diff --git a/src/routes/(main)/group/features/Conversation/AgentWelcome/index.tsx b/src/routes/(main)/group/features/Conversation/AgentWelcome/index.tsxindex b7384889a37..795c021d217 100644--- a/src/routes/(main)/group/features/Conversation/AgentWelcome/index.tsx+++ b/src/routes/(main)/group/features/Conversation/AgentWelcome/index.tsx@@ -5,6 +5,8 @@ import isEqual from 'fast-deep-equal';import React, { memo, useMemo } from 'react';import { useTranslation } from 'react-i18next';+import { useConversationStore } from '@/features/Conversation';+import { contextSelectors } from '@/features/Conversation/store';import { useIsMobile } from '@/hooks/useIsMobile';import SupervisorAvatar from '@/routes/(main)/group/features/GroupAvatar';import { useAgentStore } from '@/store/agent';@@ -22,12 +24,17 @@ const InboxWelcome = memo(() => {const isInbox = useAgentStore(builtinAgentSelectors.isInboxAgent);const fontSize = useUserStore(userGeneralSettingsSelectors.fontSize);const meta = useAgentStore(agentSelectors.currentAgentMeta, isEqual);- const [groupMeta] = useAgentGroupStore((s) => [agentGroupSelectors.currentGroupMeta(s)]);+ const groupId = useConversationStore(contextSelectors.groupId);+ const [groupMeta] = useAgentGroupStore((s) => [+ agentGroupSelectors.getGroupMeta(groupId ?? '')(s),+ ]);// Use group config for opening message and questions- const groupOpeningMessage = useAgentGroupStore(agentGroupSelectors.currentGroupOpeningMessage);+ const groupOpeningMessage = useAgentGroupStore((s) =>+ agentGroupSelectors.getGroupOpeningMessage(groupId ?? '')(s),+ );const groupOpeningQuestions = useAgentGroupStore(- agentGroupSelectors.currentGroupOpeningQuestions,+ (s) => agentGroupSelectors.getGroupOpeningQuestions(groupId ?? '')(s),isEqual,);diff --git a/src/routes/(main)/group/features/Conversation/Header/Tags/MemberCountTag.tsx b/src/routes/(main)/group/features/Conversation/Header/Tags/MemberCountTag.tsxindex 8d5fee530a4..68388f673fa 100644--- a/src/routes/(main)/group/features/Conversation/Header/Tags/MemberCountTag.tsx+++ b/src/routes/(main)/group/features/Conversation/Header/Tags/MemberCountTag.tsx@@ -3,12 +3,17 @@ import { Users } from 'lucide-react';import { memo } from 'react';import { useTranslation } from 'react-i18next';+import { useConversationStore } from '@/features/Conversation';+import { contextSelectors } from '@/features/Conversation/store';import { useAgentGroupStore } from '@/store/agentGroup';import { agentGroupSelectors } from '@/store/agentGroup/selectors';const MemberCountTag = memo(() => {const { t } = useTranslation('chat');- const currentGroupAgents = useAgentGroupStore(agentGroupSelectors.currentGroupAgents);+ const groupId = useConversationStore(contextSelectors.groupId);+ const currentGroupAgents = useAgentGroupStore((s) =>+ agentGroupSelectors.getGroupAgents(groupId ?? '')(s),+ );const memberCount = currentGroupAgents?.length ?? 0;diff --git a/src/routes/(main)/group/features/Conversation/MainChatInput/GroupChat.tsx b/src/routes/(main)/group/features/Conversation/MainChatInput/GroupChat.tsxindex ba3f181f0da..a6b661cea85 100644--- a/src/routes/(main)/group/features/Conversation/MainChatInput/GroupChat.tsx+++ b/src/routes/(main)/group/features/Conversation/MainChatInput/GroupChat.tsx@@ -9,6 +9,8 @@ import { useTranslation } from 'react-i18next';import { DEFAULT_AVATAR } from '@/const/meta';import { type ActionKeys } from '@/features/ChatInput';import { ChatInputProvider, DesktopChatInput } from '@/features/ChatInput';+import { useConversationStore } from '@/features/Conversation';+import { contextSelectors } from '@/features/Conversation/store';import GroupAvatar from '@/features/GroupAvatar';import WideScreenContainer from '@/features/WideScreenContainer';import { useAgentGroupStore } from '@/store/agentGroup';@@ -32,7 +34,11 @@ const Desktop = memo((props: { targetMemberId?: string }) => {const { t } = useTranslation('chat');const isDMPortal = !!props.targetMemberId;- const currentGroupMembers = useAgentGroupStore(agentGroupSelectors.currentGroupAgents, isEqual);+ const groupId = useConversationStore(contextSelectors.groupId);+ const currentGroupMembers = useAgentGroupStore(+ (s) => agentGroupSelectors.getGroupAgents(groupId ?? '')(s),+ isEqual,+ );const isGroupConfigLoading = useAgentGroupStore(agentGroupSelectors.isGroupsInit);const [mainInputSendErrorMsg, clearSendMessageError] = useChatStore((s) => [diff --git a/src/routes/(main)/group/features/Conversation/useGroupContext.ts b/src/routes/(main)/group/features/Conversation/useGroupContext.tsindex 28c297bec4c..4146ed605b3 100644--- a/src/routes/(main)/group/features/Conversation/useGroupContext.ts+++ b/src/routes/(main)/group/features/Conversation/useGroupContext.ts@@ -19,7 +19,9 @@ export function useGroupContext(): ConversationContext {s.activeGroupId ?? null,]);- const currentGroup = useAgentGroupStore(agentGroupSelectors.currentGroup);+ const currentGroup = useAgentGroupStore((s) =>+ s.activeGroupId ? agentGroupSelectors.getGroupById(s.activeGroupId)(s) : undefined,+ );const supervisorAgentId = currentGroup?.supervisorAgentId;// Group context uses supervisorAgentId as agentId for message storagediff --git a/src/routes/(main)/group/features/GroupAvatar.tsx b/src/routes/(main)/group/features/GroupAvatar.tsxindex 1770c6a16cc..c95d55a4de7 100644--- a/src/routes/(main)/group/features/GroupAvatar.tsx+++ b/src/routes/(main)/group/features/GroupAvatar.tsx@@ -2,6 +2,7 @@import isEqual from 'fast-deep-equal';import { memo } from 'react';+import { useParams } from 'react-router';import AgentGroupAvatar from '@/features/AgentGroupAvatar';import { useAgentGroupStore } from '@/store/agentGroup';@@ -11,8 +12,15 @@ import { agentGroupSelectors } from '@/store/agentGroup/selectors';* Connected AgentGroupAvatar that reads from agentGroup store*/const CurrentAgentGroupAvatar = memo<{ size?: number }>(({ size = 28 }) => {- const groupMeta = useAgentGroupStore(agentGroupSelectors.currentGroupMeta, isEqual);- const memberAvatars = useAgentGroupStore(agentGroupSelectors.currentGroupMemberAvatars, isEqual);+ const { gid } = useParams<{ gid: string }>();+ const groupMeta = useAgentGroupStore(+ (s) => agentGroupSelectors.getGroupMeta(gid ?? '')(s),+ isEqual,+ );+ const memberAvatars = useAgentGroupStore(+ (s) => agentGroupSelectors.getGroupMemberAvatars(gid ?? '')(s),+ isEqual,+ );return (<AgentGroupAvatardiff --git a/src/routes/(main)/group/profile/features/AgentSettings/Content.tsx b/src/routes/(main)/group/profile/features/AgentSettings/Content.tsxindex e3cb5c1b9b5..64b47917046 100644--- a/src/routes/(main)/group/profile/features/AgentSettings/Content.tsx+++ b/src/routes/(main)/group/profile/features/AgentSettings/Content.tsx@@ -6,6 +6,7 @@ import { useTheme } from 'antd-style';import { MessageSquareHeartIcon } from 'lucide-react';import { memo, useMemo, useState } from 'react';import { useTranslation } from 'react-i18next';+import { useParams } from 'react-router';import Menu from '@/components/Menu';import { DEFAULT_AVATAR } from '@/const/meta';@@ -19,8 +20,9 @@ const Content = memo(() => {const { t } = useTranslation('setting');const theme = useTheme();const { allowed: canEdit } = usePermission('edit_own_content');+ const { gid } = useParams<{ gid: string }>();const groupId = useAgentGroupStore(agentGroupSelectors.activeGroupId);- const currentGroup = useAgentGroupStore(agentGroupSelectors.currentGroup);+ const currentGroup = useAgentGroupStore((s) => agentGroupSelectors.getGroupById(gid ?? '')(s));const [tab] = useState(ChatSettingsTabs.Opening);const updateGroupConfig = async (config: any) => {diff --git a/src/routes/(main)/group/profile/features/GroupProfile/GroupForkTag.tsx b/src/routes/(main)/group/profile/features/GroupProfile/GroupForkTag.tsxindex d2f3d965214..059d3319160 100644--- a/src/routes/(main)/group/profile/features/GroupProfile/GroupForkTag.tsx+++ b/src/routes/(main)/group/profile/features/GroupProfile/GroupForkTag.tsx@@ -4,6 +4,7 @@ import { Icon, Tag } from '@lobehub/ui';import { GitFork } from 'lucide-react';import { memo, useEffect, useState } from 'react';import { useTranslation } from 'react-i18next';+import { useParams } from 'react-router';import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';import { marketApiService } from '@/services/marketApi';@@ -21,7 +22,8 @@ const GroupForkTag = memo(() => {const [forkSource, setForkSource] = useState<AgentGroupForkSourceResponse['source']>(null);const [loading, setLoading] = useState(false);- const groupMeta = useAgentGroupStore(agentGroupSelectors.currentGroupMeta);+ const { gid } = useParams<{ gid: string }>();+ const groupMeta = useAgentGroupStore((s) => agentGroupSelectors.getGroupMeta(gid ?? '')(s));const marketIdentifier = groupMeta?.marketIdentifier;useEffect(() => {diff --git a/src/routes/(main)/group/profile/features/GroupProfile/GroupHeader.tsx b/src/routes/(main)/group/profile/features/GroupProfile/GroupHeader.tsxindex a821267ebca..94c03b29a7c 100644--- a/src/routes/(main)/group/profile/features/GroupProfile/GroupHeader.tsx+++ b/src/routes/(main)/group/profile/features/GroupProfile/GroupHeader.tsx@@ -8,6 +8,7 @@ import isEqual from 'fast-deep-equal';import { PaletteIcon } from 'lucide-react';import { memo, Suspense, useCallback, useEffect, useState } from 'react';import { useTranslation } from 'react-i18next';+import { useParams } from 'react-router';import EmojiPicker from '@/components/EmojiPicker';import BackgroundSwatches from '@/features/AgentSetting/AgentMeta/BackgroundSwatches';@@ -27,7 +28,11 @@ const GroupHeader = memo(() => {const locale = useGlobalStore(globalGeneralSelectors.currentLanguage);// Get group meta from agentGroup store- const groupMeta = useAgentGroupStore(agentGroupSelectors.currentGroupMeta, isEqual);+ const { gid } = useParams<{ gid: string }>();+ const groupMeta = useAgentGroupStore(+ (s) => agentGroupSelectors.getGroupMeta(gid ?? '')(s),+ isEqual,+ );const updateGroupMeta = useAgentGroupStore((s) => s.updateGroupMeta);// File uploaddiff --git a/src/routes/(main)/group/profile/features/GroupProfile/GroupStatusTag.tsx b/src/routes/(main)/group/profile/features/GroupProfile/GroupStatusTag.tsxindex 678fddce6e6..94c07ebb7a8 100644--- a/src/routes/(main)/group/profile/features/GroupProfile/GroupStatusTag.tsx+++ b/src/routes/(main)/group/profile/features/GroupProfile/GroupStatusTag.tsx@@ -3,6 +3,7 @@import { Tag } from '@lobehub/ui';import { memo, useEffect, useMemo, useState } from 'react';import { useTranslation } from 'react-i18next';+import { useParams } from 'react-router';import { useAgentGroupStore } from '@/store/agentGroup';import { agentGroupSelectors } from '@/store/agentGroup/selectors';@@ -17,7 +18,8 @@ const GroupStatusTag = memo(() => {const [status, setStatus] = useState<AgentStatus | null>(null);const [loading, setLoading] = useState(false);- const meta = useAgentGroupStore(agentGroupSelectors.currentGroupMeta);+ const { gid } = useParams<{ gid: string }>();+ const meta = useAgentGroupStore((s) => agentGroupSelectors.getGroupMeta(gid ?? '')(s));const marketIdentifier = meta?.marketIdentifier;useEffect(() => {diff --git a/src/routes/(main)/group/profile/features/GroupProfile/GroupVersionReviewTag.tsx b/src/routes/(main)/group/profile/features/GroupProfile/GroupVersionReviewTag.tsxindex e82945c6ccb..6c2f6177d58 100644--- a/src/routes/(main)/group/profile/features/GroupProfile/GroupVersionReviewTag.tsx+++ b/src/routes/(main)/group/profile/features/GroupProfile/GroupVersionReviewTag.tsx@@ -3,6 +3,7 @@import { Tag } from '@lobehub/ui';import { memo, useEffect, useMemo, useState } from 'react';import { useTranslation } from 'react-i18next';+import { useParams } from 'react-router';import { marketApiService } from '@/services/marketApi';import { useAgentGroupStore } from '@/store/agentGroup';@@ -26,7 +27,8 @@ const GroupVersionReviewTag = memo(() => {const [versions, setVersions] = useState<GroupVersion[] | null>(null);const [loading, setLoading] = useState(false);- const meta = useAgentGroupStore(agentGroupSelectors.currentGroupMeta);+ const { gid } = useParams<{ gid: string }>();+ const meta = useAgentGroupStore((s) => agentGroupSelectors.getGroupMeta(gid ?? '')(s));const marketIdentifier = meta?.marketIdentifier;useEffect(() => {@@ -78,7 +80,8 @@ export const useGroupVersionReviewStatus = () => {const [isUnderReview, setIsUnderReview] = useState(false);const [loading, setLoading] = useState(false);- const meta = useAgentGroupStore(agentGroupSelectors.currentGroupMeta);+ const { gid } = useParams<{ gid: string }>();+ const meta = useAgentGroupStore((s) => agentGroupSelectors.getGroupMeta(gid ?? '')(s));const marketIdentifier = meta?.marketIdentifier;useEffect(() => {diff --git a/src/routes/(main)/group/profile/features/GroupProfile/index.tsx b/src/routes/(main)/group/profile/features/GroupProfile/index.tsxindex ed74fb09290..b26bb67b00b 100644--- a/src/routes/(main)/group/profile/features/GroupProfile/index.tsx+++ b/src/routes/(main)/group/profile/features/GroupProfile/index.tsx@@ -6,6 +6,7 @@ import { useTheme } from 'antd-style';import { MoreHorizontalIcon, PlayIcon, Settings2Icon } from 'lucide-react';import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';import { useTranslation } from 'react-i18next';+import { useParams } from 'react-router';import urlJoin from 'url-join';import { useAgentGroupTransferMenuItem } from '@/business/client/hooks/useAgentGroupTransferMenuItem';@@ -39,8 +40,9 @@ const GroupProfile = memo(() => {const { allowed: canEdit } = usePermission('edit_own_content');const theme = useTheme();const [showAgentSetting, setShowAgentSetting] = useState(false);+ const { gid } = useParams<{ gid: string }>();const groupId = useAgentGroupStore(agentGroupSelectors.activeGroupId);- const currentGroup = useAgentGroupStore(agentGroupSelectors.currentGroup);+ const currentGroup = useAgentGroupStore((s) => agentGroupSelectors.getGroupById(gid ?? '')(s));const updateGroup = useAgentGroupStore((s) => s.updateGroup);const router = useQueryRoute();const transferMenuItems = useAgentGroupTransferMenuItem(groupId ?? undefined);diff --git a/src/routes/(main)/group/profile/features/Header/index.tsx b/src/routes/(main)/group/profile/features/Header/index.tsxindex 58fbfa521c5..d8b13b1baed 100644--- a/src/routes/(main)/group/profile/features/Header/index.tsx+++ b/src/routes/(main)/group/profile/features/Header/index.tsx@@ -5,6 +5,7 @@ import { createStaticStyles } from 'antd-style';import { Crown, Users } from 'lucide-react';import { memo, useMemo, useState } from 'react';import { useTranslation } from 'react-i18next';+import { useParams } from 'react-router';import ToggleLeftPanelButton from '@/features/NavPanel/ToggleLeftPanelButton';import { usePermission } from '@/hooks/usePermission';@@ -48,7 +49,8 @@ const Header = memo(() => {const [showAddModal, setShowAddModal] = useState(false);- const members = useAgentGroupStore(agentGroupSelectors.currentGroupAgents);+ const { gid } = useParams<{ gid: string }>();+ const members = useAgentGroupStore((s) => agentGroupSelectors.getGroupAgents(gid ?? '')(s));const activeGroupId = useAgentGroupStore(agentGroupSelectors.activeGroupId);const addAgentsToGroup = useAgentGroupStore((s) => s.addAgentsToGroup);const showLeftPanel = useGlobalStore(systemStatusSelectors.showLeftPanel);diff --git a/src/routes/(main)/group/profile/features/MemberProfile/index.tsx b/src/routes/(main)/group/profile/features/MemberProfile/index.tsxindex cc6d632c781..836c2ee9551 100644--- a/src/routes/(main)/group/profile/features/MemberProfile/index.tsx+++ b/src/routes/(main)/group/profile/features/MemberProfile/index.tsx@@ -6,6 +6,7 @@ import isEqual from 'fast-deep-equal';import { InfoIcon, PlayIcon } from 'lucide-react';import React, { memo, useCallback, useEffect, useMemo } from 'react';import { useTranslation } from 'react-i18next';+import { useParams } from 'react-router';import urlJoin from 'url-join';import { EditorCanvas } from '@/features/EditorCanvas';@@ -37,9 +38,16 @@ const MemberProfile = memo(() => {const config = useAgentStore(agentByIdSelectors.getAgentConfigById(agentId), isEqual);const updateAgentConfigById = useAgentStore((s) => s.updateAgentConfigById);+ const { gid } = useParams<{ gid: string }>();const groupId = useAgentGroupStore(agentGroupSelectors.activeGroupId);- const currentGroup = useAgentGroupStore(agentGroupSelectors.currentGroup, isEqual);- const currentGroupAgents = useAgentGroupStore(agentGroupSelectors.currentGroupAgents, isEqual);+ const currentGroup = useAgentGroupStore(+ (s) => agentGroupSelectors.getGroupById(gid ?? '')(s),+ isEqual,+ );+ const currentGroupAgents = useAgentGroupStore(+ (s) => agentGroupSelectors.getGroupAgents(gid ?? '')(s),+ isEqual,+ );const router = useQueryRoute();// Check if the current agent is the supervisordiff --git a/src/store/agentGroup/selectors/byId.ts b/src/store/agentGroup/selectors/byId.tsindex 558c4492c25..ed8839f0b92 100644--- a/src/store/agentGroup/selectors/byId.ts+++ b/src/store/agentGroup/selectors/byId.ts@@ -1,3 +1,4 @@+import { DEFAULT_AVATAR } from '@lobechat/const';import { type AgentGroupDetail, type AgentGroupMember, type AgentItem } from '@lobechat/types';import { DEFAULT_CHAT_GROUP_CHAT_CONFIG, DEFAULT_CHAT_GROUP_META_CONFIG } from '@/const/settings';@@ -46,6 +47,24 @@ const groupMembers =return agents.filter((agent) => !agent.isSupervisor);};+const groupMemberAvatars =+ (groupId: string) =>+ (s: ChatGroupStore): { avatar: string; background?: string }[] =>+ groupMembers(groupId)(s).map((agent) => ({+ avatar: agent.avatar || DEFAULT_AVATAR,+ background: agent.backgroundColor || undefined,+ }));++const groupOpeningMessage =+ (groupId: string) =>+ (s: ChatGroupStore): string | undefined =>+ groupConfig(groupId)(s)?.openingMessage;++const groupOpeningQuestions =+ (groupId: string) =>+ (s: ChatGroupStore): string[] =>+ groupConfig(groupId)(s)?.openingQuestions || [];+const groupAgentCount =(groupId: string) =>(s: ChatGroupStore): number =>@@ -80,7 +99,10 @@ export const agentGroupByIdSelectors = {groupById,groupBySupervisorAgentId,groupConfig,+ groupMemberAvatars,groupMemberCount,groupMembers,groupMeta,+ groupOpeningMessage,+ groupOpeningQuestions,};diff --git a/src/store/agentGroup/selectors/current.ts b/src/store/agentGroup/selectors/current.tsindex 99eb3465ddf..7d89226fc87 100644--- a/src/store/agentGroup/selectors/current.ts+++ b/src/store/agentGroup/selectors/current.ts@@ -1,59 +1,9 @@-import {- DEFAULT_AVATAR,- DEFAULT_CHAT_GROUP_CHAT_CONFIG,- DEFAULT_CHAT_GROUP_META_CONFIG,-} from '@lobechat/const';-import { type AgentGroupDetail, type AgentGroupMember } from '@lobechat/types';+import { type AgentGroupDetail } from '@lobechat/types';import { type ChatGroupState } from '../initialState';-import { type ChatGroupStore } from '../store';-import { agentGroupByIdSelectors } from './byId';const activeGroupId = (s: ChatGroupState): string | undefined => s.activeGroupId;-const currentGroup = (s: ChatGroupStore): AgentGroupDetail | undefined => {- const groupId = activeGroupId(s);- return groupId ? agentGroupByIdSelectors.groupById(groupId)(s) : undefined;-};--const currentGroupConfig = (s: ChatGroupStore) => {- const groupId = activeGroupId(s);- return groupId ? agentGroupByIdSelectors.groupConfig(groupId)(s) : DEFAULT_CHAT_GROUP_CHAT_CONFIG;-};--const currentGroupOpeningMessage = (s: ChatGroupStore): string | undefined => {- const config = currentGroupConfig(s);- return config?.openingMessage;-};--const currentGroupOpeningQuestions = (s: ChatGroupStore): string[] => {- const config = currentGroupConfig(s);- return config?.openingQuestions || [];-};--const currentGroupMeta = (s: ChatGroupStore) => {- const groupId = activeGroupId(s);- return groupId ? agentGroupByIdSelectors.groupMeta(groupId)(s) : DEFAULT_CHAT_GROUP_META_CONFIG;-};--const currentGroupAgents = (s: ChatGroupStore): AgentGroupMember[] => {- const groupId = activeGroupId(s);- return groupId ? agentGroupByIdSelectors.groupAgents(groupId)(s) : [];-};--const currentGroupMembers = (s: ChatGroupStore): AgentGroupMember[] => {- const groupId = activeGroupId(s);- return groupId ? agentGroupByIdSelectors.groupMembers(groupId)(s) : [];-};--const currentGroupMemberAvatars = (s: ChatGroupStore) => {- const members = currentGroupMembers(s);- return members.map((agent) => ({- avatar: agent.avatar || DEFAULT_AVATAR,- background: agent.backgroundColor || undefined,- }));-};-const getAllGroups = (s: ChatGroupState): AgentGroupDetail[] => Object.values(s.groupMap);/**@@ -67,14 +17,6 @@ const isGroupsInitialized = (s: ChatGroupState): boolean => s.groupsInit;export const currentSelectors = {activeGroupId,- currentGroup,- currentGroupAgents,- currentGroupConfig,- currentGroupMemberAvatars,- currentGroupMembers,- currentGroupMeta,- currentGroupOpeningMessage,- currentGroupOpeningQuestions,getAllGroups,isGroupsInit,isGroupsInitialized,diff --git a/src/store/agentGroup/selectors/index.ts b/src/store/agentGroup/selectors/index.tsindex d0e48efb875..37f75d2e943 100644--- a/src/store/agentGroup/selectors/index.ts+++ b/src/store/agentGroup/selectors/index.ts@@ -11,7 +11,10 @@ export const agentGroupSelectors = {getGroupById: agentGroupByIdSelectors.groupById,getGroupBySupervisorAgentId: agentGroupByIdSelectors.groupBySupervisorAgentId,getGroupConfig: agentGroupByIdSelectors.groupConfig,+ getGroupMemberAvatars: agentGroupByIdSelectors.groupMemberAvatars,getGroupMemberCount: agentGroupByIdSelectors.groupMemberCount,getGroupMembers: agentGroupByIdSelectors.groupMembers,getGroupMeta: agentGroupByIdSelectors.groupMeta,+ getGroupOpeningMessage: agentGroupByIdSelectors.groupOpeningMessage,+ getGroupOpeningQuestions: agentGroupByIdSelectors.groupOpeningQuestions,};diff --git a/src/store/agentGroup/slices/curd.ts b/src/store/agentGroup/slices/curd.tsindex 980dc8c9c98..e703a40d04f 100644--- a/src/store/agentGroup/slices/curd.ts+++ b/src/store/agentGroup/slices/curd.ts@@ -88,7 +88,10 @@ export class ChatGroupCurdAction {};updateGroupConfig = async (config: Partial<LobeChatGroupConfig>) => {- const group = agentGroupSelectors.currentGroup(this.#get());+ const s = this.#get();+ const group = s.activeGroupId+ ? agentGroupSelectors.getGroupById(s.activeGroupId)(s)+ : undefined;if (!group) return;const mergedConfig = {@@ -112,7 +115,10 @@ export class ChatGroupCurdAction {};updateGroupMeta = async (meta: Partial<ChatGroupItem>) => {- const group = agentGroupSelectors.currentGroup(this.#get());+ const s = this.#get();+ const group = s.activeGroupId+ ? agentGroupSelectors.getGroupById(s.activeGroupId)(s)+ : undefined;if (!group) return;const id = group.id;