🤯 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: clean up unused sessionStore selectors and slices (#13738)
Arvin Xu732a3ae54a4e
diff --git a/src/store/session/initialState.ts b/src/store/session/initialState.tsindex 33becb59711..a21033f0ba9 100644--- a/src/store/session/initialState.ts+++ b/src/store/session/initialState.ts@@ -1,18 +1,11 @@-import { type HomeInputState } from './slices/homeInput/initialState';-import { initialHomeInputState } from './slices/homeInput/initialState';-import { type RecentState } from './slices/recent/initialState';-import { initialRecentState } from './slices/recent/initialState';import { type SessionState } from './slices/session/initialState';import { initialSessionState } from './slices/session/initialState';import { type SessionGroupState } from './slices/sessionGroup/initialState';import { initSessionGroupState } from './slices/sessionGroup/initialState';-export interface SessionStoreState- extends SessionGroupState, SessionState, RecentState, HomeInputState {}+export interface SessionStoreState extends SessionGroupState, SessionState {}export const initialState: SessionStoreState = {...initSessionGroupState,...initialSessionState,- ...initialRecentState,- ...initialHomeInputState,};diff --git a/src/store/session/selectors.ts b/src/store/session/selectors.tsindex c4d0d6c945e..aa133e89e8c 100644--- a/src/store/session/selectors.ts+++ b/src/store/session/selectors.ts@@ -1,3 +1,2 @@-export { recentSelectors } from './slices/recent/selectors';export { sessionMetaSelectors, sessionSelectors } from './slices/session/selectors';export { sessionGroupSelectors } from './slices/sessionGroup/selectors';diff --git a/src/store/session/slices/homeInput/action.test.ts b/src/store/session/slices/homeInput/action.test.tsdeleted file mode 100644index 9d01050aec6..00000000000--- a/src/store/session/slices/homeInput/action.test.ts+++ /dev/null@@ -1,449 +0,0 @@-import { act, renderHook } from '@testing-library/react';-import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';--import { documentService } from '@/services/document';-import { sessionService } from '@/services/session';-import { useChatStore } from '@/store/chat';-import { useGlobalStore } from '@/store/global';-import { useSessionStore } from '@/store/session';--// Mock dependencies-vi.mock('@/services/document', () => ({- documentService: {- createDocument: vi.fn(),- },-}));--vi.mock('@/services/session', () => ({- sessionService: {- createSession: vi.fn(),- },-}));--vi.mock('@/store/chat', () => ({- useChatStore: {- getState: vi.fn(),- },-}));--vi.mock('@/store/global', () => ({- useGlobalStore: {- getState: vi.fn(),- },-}));--describe('HomeInputAction', () => {- const mockNavigate = vi.fn();- const mockSendMessage = vi.fn().mockResolvedValue({});- const mockRefreshSessions = vi.fn().mockResolvedValue(undefined);-- beforeEach(() => {- vi.clearAllMocks();-- // Setup default mocks- vi.mocked(useGlobalStore.getState).mockReturnValue({- navigate: mockNavigate,- } as any);-- vi.mocked(useChatStore.getState).mockReturnValue({- sendMessage: mockSendMessage,- } as any);-- // Mock sessionService.createSession to return new agent id- vi.mocked(sessionService.createSession).mockResolvedValue('new-agent-id');-- // Reset store state with mocked refreshSessions- useSessionStore.setState({- homeInputLoading: false,- inputActiveMode: null,- refreshSessions: mockRefreshSessions,- });- });-- afterEach(() => {- vi.restoreAllMocks();- });-- describe('setInputActiveMode', () => {- it('should set inputActiveMode to agent', () => {- const { result } = renderHook(() => useSessionStore());-- act(() => {- result.current.setInputActiveMode('agent');- });-- expect(result.current.inputActiveMode).toBe('agent');- });-- it('should set inputActiveMode to write', () => {- const { result } = renderHook(() => useSessionStore());-- act(() => {- result.current.setInputActiveMode('write');- });-- expect(result.current.inputActiveMode).toBe('write');- });-- it('should set inputActiveMode to image', () => {- const { result } = renderHook(() => useSessionStore());-- act(() => {- result.current.setInputActiveMode('image');- });-- expect(result.current.inputActiveMode).toBe('image');- });-- it('should set inputActiveMode to research', () => {- const { result } = renderHook(() => useSessionStore());-- act(() => {- result.current.setInputActiveMode('research');- });-- expect(result.current.inputActiveMode).toBe('research');- });-- it('should allow switching between modes', () => {- const { result } = renderHook(() => useSessionStore());-- act(() => {- result.current.setInputActiveMode('agent');- });- expect(result.current.inputActiveMode).toBe('agent');-- act(() => {- result.current.setInputActiveMode('write');- });- expect(result.current.inputActiveMode).toBe('write');- });- });-- describe('clearInputMode', () => {- it('should clear inputActiveMode to null', () => {- const { result } = renderHook(() => useSessionStore());-- act(() => {- result.current.setInputActiveMode('agent');- });- expect(result.current.inputActiveMode).toBe('agent');-- act(() => {- result.current.clearInputMode();- });- expect(result.current.inputActiveMode).toBeNull();- });-- it('should work when mode is already null', () => {- const { result } = renderHook(() => useSessionStore());-- act(() => {- result.current.clearInputMode();- });-- expect(result.current.inputActiveMode).toBeNull();- });- });-- describe('sendAsAgent', () => {- it('should create agent with correct params', async () => {- const { result } = renderHook(() => useSessionStore());-- await act(async () => {- await result.current.sendAsAgent({ message: 'Test prompt' });- });-- // createSession is called internally via the store action- // which eventually calls sessionService.createSession- expect(sessionService.createSession).toHaveBeenCalled();- });-- it('should truncate long titles to 50 characters', async () => {- const { result } = renderHook(() => useSessionStore());- const longMessage = 'A'.repeat(100);-- await act(async () => {- await result.current.sendAsAgent({ message: longMessage });- });-- expect(sessionService.createSession).toHaveBeenCalled();- });-- it('should navigate to agent profile page', async () => {- const { result } = renderHook(() => useSessionStore());-- await act(async () => {- await result.current.sendAsAgent({ message: 'Test' });- });-- expect(mockNavigate).toHaveBeenCalledWith('/agent/new-agent-id/profile');- });-- it('should send message with agentId context', async () => {- const { result } = renderHook(() => useSessionStore());-- await act(async () => {- await result.current.sendAsAgent({ message: 'Test message' });- });-- expect(mockSendMessage).toHaveBeenCalledWith({- context: { agentId: 'new-agent-id', scope: 'agent_builder' },- message: 'Test message',- });- });-- it('should clear mode after success', async () => {- const { result } = renderHook(() => useSessionStore());-- act(() => {- result.current.setInputActiveMode('agent');- });-- await act(async () => {- await result.current.sendAsAgent({ message: 'Test' });- });-- expect(result.current.inputActiveMode).toBeNull();- });-- it('should return agentId', async () => {- const { result } = renderHook(() => useSessionStore());-- let agentId: string | undefined;- await act(async () => {- agentId = await result.current.sendAsAgent({ message: 'Test' });- });-- expect(agentId).toBe('new-agent-id');- });-- it('should set loading to false after completion', async () => {- const { result } = renderHook(() => useSessionStore());-- await act(async () => {- await result.current.sendAsAgent({ message: 'Test' });- });-- expect(result.current.homeInputLoading).toBe(false);- });-- it('should set loading to false even if operation fails', async () => {- vi.mocked(sessionService.createSession).mockRejectedValueOnce(new Error('Failed'));- const { result } = renderHook(() => useSessionStore());-- await act(async () => {- try {- await result.current.sendAsAgent({ message: 'Test' });- } catch {- // Expected error- }- });-- expect(result.current.homeInputLoading).toBe(false);- });-- it('should not throw when navigate is undefined', async () => {- vi.mocked(useGlobalStore.getState).mockReturnValue({- navigate: undefined,- } as any);-- const { result } = renderHook(() => useSessionStore());-- await expect(- act(async () => {- await result.current.sendAsAgent({ message: 'Test' });- }),- ).resolves.not.toThrow();- });- });-- describe('sendAsWrite', () => {- beforeEach(() => {- vi.mocked(documentService.createDocument).mockResolvedValue({- id: 'new-doc-id',- } as any);- });-- it('should create document with correct title', async () => {- const { result } = renderHook(() => useSessionStore());-- await act(async () => {- await result.current.sendAsWrite({ message: 'Document content' });- });-- expect(documentService.createDocument).toHaveBeenCalledWith({- editorData: '',- title: 'Document content',- });- });-- it('should truncate long titles to 50 characters', async () => {- const { result } = renderHook(() => useSessionStore());- const longMessage = 'B'.repeat(100);-- await act(async () => {- await result.current.sendAsWrite({ message: longMessage });- });-- expect(documentService.createDocument).toHaveBeenCalledWith({- editorData: '',- title: 'B'.repeat(50),- });- });-- it('should navigate to page', async () => {- const { result } = renderHook(() => useSessionStore());-- await act(async () => {- await result.current.sendAsWrite({ message: 'Content' });- });-- expect(mockNavigate).toHaveBeenCalledWith('/page/new-doc-id');- });-- it('should send message with page scope context', async () => {- const { result } = renderHook(() => useSessionStore());-- await act(async () => {- await result.current.sendAsWrite({ message: 'Content' });- });-- expect(mockSendMessage).toHaveBeenCalledWith({- context: {- agentId: 'new-doc-id',- scope: 'page',- },- message: 'Content',- });- });-- it('should clear mode after success', async () => {- const { result } = renderHook(() => useSessionStore());-- act(() => {- result.current.setInputActiveMode('write');- });-- await act(async () => {- await result.current.sendAsWrite({ message: 'Content' });- });-- expect(result.current.inputActiveMode).toBeNull();- });-- it('should return documentId', async () => {- const { result } = renderHook(() => useSessionStore());-- let docId: string | undefined;- await act(async () => {- docId = await result.current.sendAsWrite({ message: 'Content' });- });-- expect(docId).toBe('new-doc-id');- });-- it('should set loading to false after completion', async () => {- const { result } = renderHook(() => useSessionStore());-- await act(async () => {- await result.current.sendAsWrite({ message: 'Content' });- });-- expect(result.current.homeInputLoading).toBe(false);- });-- it('should set loading to false even if operation fails', async () => {- vi.mocked(documentService.createDocument).mockRejectedValueOnce(new Error('Failed'));- const { result } = renderHook(() => useSessionStore());-- await act(async () => {- try {- await result.current.sendAsWrite({ message: 'Content' });- } catch {- // Expected error- }- });-- expect(result.current.homeInputLoading).toBe(false);- });- });-- describe('sendAsImage', () => {- it('should navigate to /image', () => {- const { result } = renderHook(() => useSessionStore());-- act(() => {- result.current.sendAsImage();- });-- expect(mockNavigate).toHaveBeenCalledWith('/image');- });-- it('should clear mode', () => {- const { result } = renderHook(() => useSessionStore());-- act(() => {- result.current.setInputActiveMode('image');- });-- act(() => {- result.current.sendAsImage();- });-- expect(result.current.inputActiveMode).toBeNull();- });-- it('should not throw when navigate is undefined', () => {- vi.mocked(useGlobalStore.getState).mockReturnValue({- navigate: undefined,- } as any);-- const { result } = renderHook(() => useSessionStore());-- expect(() => {- act(() => {- result.current.sendAsImage();- });- }).not.toThrow();- });- });-- describe('sendAsResearch', () => {- it('should log message to console', async () => {- const consoleSpy = vi.spyOn(console, 'info').mockImplementation(() => {});-- const { result } = renderHook(() => useSessionStore());-- await act(async () => {- await result.current.sendAsResearch('Research query');- });-- expect(consoleSpy).toHaveBeenCalledWith('sendAsResearch:', 'Research query');-- consoleSpy.mockRestore();- });-- it('should clear mode', async () => {- const { result } = renderHook(() => useSessionStore());-- act(() => {- result.current.setInputActiveMode('research');- });-- await act(async () => {- await result.current.sendAsResearch('Query');- });-- expect(result.current.inputActiveMode).toBeNull();- });- });-- describe('homeInputLoading', () => {- it('should be false initially', () => {- const { result } = renderHook(() => useSessionStore());-- expect(result.current.homeInputLoading).toBe(false);- });- });-});diff --git a/src/store/session/slices/homeInput/action.ts b/src/store/session/slices/homeInput/action.tsdeleted file mode 100644index 777918f75c8..00000000000--- a/src/store/session/slices/homeInput/action.ts+++ /dev/null@@ -1,131 +0,0 @@-import { documentService } from '@/services/document';-import { useChatStore } from '@/store/chat';-import { useGlobalStore } from '@/store/global';-import { type SessionStore } from '@/store/session/store';-import { type StoreSetter } from '@/store/types';-import { setNamespace } from '@/utils/storeDebug';--import { type StarterMode } from './initialState';--const n = setNamespace('homeInput');--interface SendMessageWithEditorParams {- editorData?: Record<string, any>;- message: string;-}--type Setter = StoreSetter<SessionStore>;-export const createHomeInputSlice = (set: Setter, get: () => SessionStore, _api?: unknown) =>- new HomeInputActionImpl(set, get, _api);--export class HomeInputActionImpl {- readonly #get: () => SessionStore;- readonly #set: Setter;-- constructor(set: Setter, get: () => SessionStore, _api?: unknown) {- void _api;- this.#set = set;- this.#get = get;- }-- clearInputMode = (): void => {- this.#set({ inputActiveMode: null }, false, n('clearInputMode'));- };-- sendAsAgent = async ({ editorData, message }: SendMessageWithEditorParams): Promise<string> => {- this.#set({ homeInputLoading: true }, false, n('sendAsAgent/start'));-- try {- // 1. Create new Agent using existing createSession action- const newAgentId = await this.#get().createSession(- {- config: { systemRole: message },- meta: { title: message?.slice(0, 50) || 'New Agent' },- },- false, // Don't switch session, we'll navigate manually- );-- // 2. Navigate to Agent profile page- const navigate = useGlobalStore.getState().navigate;- if (navigate) {- navigate(`/agent/${newAgentId}/profile`);- }-- // 3. Send initial message with agentId context- const { sendMessage } = useChatStore.getState();- await sendMessage({- context: { agentId: newAgentId, scope: 'agent_builder' },- editorData,- message,- });-- // 4. Clear mode- this.#set({ inputActiveMode: null }, false, n('sendAsAgent/clearMode'));-- return newAgentId;- } finally {- this.#set({ homeInputLoading: false }, false, n('sendAsAgent/end'));- }- };-- sendAsImage = (): void => {- // Navigate to /image page- const navigate = useGlobalStore.getState().navigate;- if (navigate) {- navigate('/image');- }-- // Clear mode- this.#set({ inputActiveMode: null }, false, n('sendAsImage'));- };-- sendAsResearch = async (message: string): Promise<void> => {- // TODO: Implement DeepResearch mode- console.info('sendAsResearch:', message);-- // Clear mode- this.#set({ inputActiveMode: null }, false, n('sendAsResearch'));- };-- sendAsWrite = async ({ editorData, message }: SendMessageWithEditorParams): Promise<string> => {- this.#set({ homeInputLoading: true }, false, n('sendAsWrite/start'));-- try {- // 1. Create new Document- const newDoc = await documentService.createDocument({- editorData: '',- title: message?.slice(0, 50) || 'Untitled',- });-- // 2. Navigate to Page- const navigate = useGlobalStore.getState().navigate;- if (navigate) {- navigate(`/page/${newDoc.id}`);- }-- // 3. Send message with document scope context- const { sendMessage } = useChatStore.getState();- await sendMessage({- context: {- agentId: newDoc.id,- scope: 'page',- },- editorData,- message,- });-- // 4. Clear mode- this.#set({ inputActiveMode: null }, false, n('sendAsWrite/clearMode'));-- return newDoc.id;- } finally {- this.#set({ homeInputLoading: false }, false, n('sendAsWrite/end'));- }- };-- setInputActiveMode = (mode: StarterMode): void => {- this.#set({ inputActiveMode: mode }, false, n('setInputActiveMode', mode));- };-}--export type HomeInputAction = Pick<HomeInputActionImpl, keyof HomeInputActionImpl>;diff --git a/src/store/session/slices/homeInput/index.ts b/src/store/session/slices/homeInput/index.tsdeleted file mode 100644index fae5655d5df..00000000000--- a/src/store/session/slices/homeInput/index.ts+++ /dev/null@@ -1,2 +0,0 @@-export { createHomeInputSlice, type HomeInputAction } from './action';-export { type HomeInputState, initialHomeInputState, type StarterMode } from './initialState';diff --git a/src/store/session/slices/homeInput/initialState.ts b/src/store/session/slices/homeInput/initialState.tsdeleted file mode 100644index fbc0e991cad..00000000000--- a/src/store/session/slices/homeInput/initialState.ts+++ /dev/null@@ -1,11 +0,0 @@-export type StarterMode = 'agent' | 'write' | 'image' | 'research' | null;--export interface HomeInputState {- homeInputLoading: boolean;- inputActiveMode: StarterMode;-}--export const initialHomeInputState: HomeInputState = {- homeInputLoading: false,- inputActiveMode: null,-};diff --git a/src/store/session/slices/recent/action.ts b/src/store/session/slices/recent/action.tsdeleted file mode 100644index 30309fb8dbf..00000000000--- a/src/store/session/slices/recent/action.ts+++ /dev/null@@ -1,93 +0,0 @@-import isEqual from 'fast-deep-equal';-import { type SWRResponse } from 'swr';--import { useClientDataSWR } from '@/libs/swr';-import { fileService } from '@/services/file';-import { topicService } from '@/services/topic';-import { type StoreSetter } from '@/store/types';-import { type FileListItem } from '@/types/files';-import { type RecentTopic } from '@/types/topic';-import { setNamespace } from '@/utils/storeDebug';--import { type SessionStore } from '../../store';--const n = setNamespace('recent');--const FETCH_RECENT_TOPICS_KEY = 'fetchRecentTopics';-const FETCH_RECENT_RESOURCES_KEY = 'fetchRecentResources';-const FETCH_RECENT_PAGES_KEY = 'fetchRecentPages';--type Setter = StoreSetter<SessionStore>;-export const createRecentSlice = (set: Setter, get: () => SessionStore, _api?: unknown) =>- new RecentActionImpl(set, get, _api);--export class RecentActionImpl {- readonly #get: () => SessionStore;- readonly #set: Setter;-- constructor(set: Setter, get: () => SessionStore, _api?: unknown) {- void _api;- this.#set = set;- this.#get = get;- }-- useFetchRecentPages = (isLogin: boolean | undefined): SWRResponse<any[]> => {- return useClientDataSWR<any[]>(- // Only fetch when login status is explicitly true (not null/undefined)- isLogin === true ? [FETCH_RECENT_PAGES_KEY, isLogin] : null,- async () => fileService.getRecentPages(12),- {- onSuccess: (data) => {- if (this.#get().isRecentPagesInit && isEqual(this.#get().recentPages, data)) return;-- this.#set(- { isRecentPagesInit: true, recentPages: data },- false,- n('useFetchRecentPages/onSuccess'),- );- },- },- );- };-- useFetchRecentResources = (isLogin: boolean | undefined): SWRResponse<FileListItem[]> => {- return useClientDataSWR<FileListItem[]>(- // Only fetch when login status is explicitly true (not null/undefined)- isLogin === true ? [FETCH_RECENT_RESOURCES_KEY, isLogin] : null,- async () => fileService.getRecentFiles(12),- {- onSuccess: (data) => {- if (this.#get().isRecentResourcesInit && isEqual(this.#get().recentResources, data))- return;-- this.#set(- { isRecentResourcesInit: true, recentResources: data },- false,- n('useFetchRecentResources/onSuccess'),- );- },- },- );- };-- useFetchRecentTopics = (isLogin: boolean | undefined): SWRResponse<RecentTopic[]> => {- return useClientDataSWR<RecentTopic[]>(- // Only fetch when login status is explicitly true (not null/undefined)- isLogin === true ? [FETCH_RECENT_TOPICS_KEY, isLogin] : null,- async () => topicService.getRecentTopics(12),- {- onSuccess: (data) => {- if (this.#get().isRecentTopicsInit && isEqual(this.#get().recentTopics, data)) return;-- this.#set(- { isRecentTopicsInit: true, recentTopics: data },- false,- n('useFetchRecentTopics/onSuccess'),- );- },- },- );- };-}--export type RecentAction = Pick<RecentActionImpl, keyof RecentActionImpl>;diff --git a/src/store/session/slices/recent/initialState.ts b/src/store/session/slices/recent/initialState.tsdeleted file mode 100644index d8a5917cd66..00000000000--- a/src/store/session/slices/recent/initialState.ts+++ /dev/null@@ -1,20 +0,0 @@-import { type FileListItem } from '@/types/files';-import { type RecentTopic } from '@/types/topic';--export interface RecentState {- isRecentPagesInit: boolean;- isRecentResourcesInit: boolean;- isRecentTopicsInit: boolean;- recentPages: any[];- recentResources: FileListItem[];- recentTopics: RecentTopic[];-}--export const initialRecentState: RecentState = {- isRecentPagesInit: false,- isRecentResourcesInit: false,- isRecentTopicsInit: false,- recentPages: [],- recentResources: [],- recentTopics: [],-};diff --git a/src/store/session/slices/recent/selectors.ts b/src/store/session/slices/recent/selectors.tsdeleted file mode 100644index 0e8671086d5..00000000000--- a/src/store/session/slices/recent/selectors.ts+++ /dev/null@@ -1,18 +0,0 @@-import { type SessionStoreState } from '../../initialState';--const isRecentTopicsInit = (s: SessionStoreState) => s.isRecentTopicsInit;-const isRecentResourcesInit = (s: SessionStoreState) => s.isRecentResourcesInit;-const isRecentPagesInit = (s: SessionStoreState) => s.isRecentPagesInit;--const recentTopics = (s: SessionStoreState) => s.recentTopics;-const recentResources = (s: SessionStoreState) => s.recentResources;-const recentPages = (s: SessionStoreState) => s.recentPages;--export const recentSelectors = {- isRecentPagesInit,- isRecentResourcesInit,- isRecentTopicsInit,- recentPages,- recentResources,- recentTopics,-};diff --git a/src/store/session/slices/session/selectors/list.test.ts b/src/store/session/slices/session/selectors/list.test.tsindex 95eacc1cf1f..5e71ff153f6 100644--- a/src/store/session/slices/session/selectors/list.test.ts+++ b/src/store/session/slices/session/selectors/list.test.ts@@ -1,4 +1,3 @@-import { DEFAULT_AGENT_LOBE_SESSION } from '@/const/session';import { type SessionStore } from '@/store/session';import { type LobeAgentSession } from '@/types/session';import { LobeSessionType } from '@/types/session';@@ -39,42 +38,6 @@ describe('currentSession', () => {});});-describe('currentSessionSafe', () => {- const s = {- activeId: '1',- sessions: [- {- id: '1',- config: {- model: 'gpt-3.5-turbo',- params: {},- systemRole: 'system-role',- },- type: LobeSessionType.Agent,- } as LobeAgentSession,- {- id: '2',- config: {- model: 'gpt-3.5-turbo',- params: {},- systemRole: 'system-role',- },- type: LobeSessionType.Agent,- } as LobeAgentSession,- ],- } as unknown as SessionStore;-- it('should return initLobeSession when currentSession(s) returns undefined', () => {- expect(sessionSelectors.currentSessionSafe({ sessions: {} } as any)).toEqual(- DEFAULT_AGENT_LOBE_SESSION,- );- });-- it('should return the result of currentSession(s) when it returns a non-undefined value', () => {- expect(sessionSelectors.currentSessionSafe(s)).toEqual(s.sessions[0]);- });-});-describe('getSessionById', () => {const s = {activeId: '1',@@ -103,25 +66,4 @@ describe('getSessionById', () => {it('should return the session with the specified id when id is not equal to INBOX_SESSION_ID', () => {expect(sessionSelectors.getSessionById('1')(s)).toEqual(s.sessions[0]);});-- it('should return initLobeSession when the session with the specified id does not exist', () => {- expect(sessionSelectors.getSessionById('3')(s)).toEqual(DEFAULT_AGENT_LOBE_SESSION);- });-});--describe('getSessionMetaById', () => {- const s: SessionStore = {- sessions: [- { id: '1', meta: { title: 'Session 1' } },- { id: '2', meta: { title: 'Session 2' } },- ],- } as unknown as SessionStore;-- it('should return the meta data of the session with the specified id', () => {- expect(sessionSelectors.getSessionMetaById('1')(s)).toEqual({ title: 'Session 1' });- });-- it('should return an empty object when the session with the specified id does not exist', () => {- expect(sessionSelectors.getSessionMetaById('3')(s)).toEqual({});- });});diff --git a/src/store/session/slices/session/selectors/list.ts b/src/store/session/slices/session/selectors/list.tsindex cf7ff2034db..23ad06d392b 100644--- a/src/store/session/slices/session/selectors/list.ts+++ b/src/store/session/slices/session/selectors/list.ts@@ -1,6 +1,5 @@-import { DEFAULT_AGENT_LOBE_SESSION, INBOX_SESSION_ID } from '@/const/session';+import { INBOX_SESSION_ID } from '@/const/session';import { sessionHelpers } from '@/store/session/slices/session/helpers';-import { type MetaData } from '@/types/meta';import {type CustomSessionGroup,type GroupMemberWithAgent,@@ -13,14 +12,6 @@ import { type SessionStore } from '../../../store';const defaultSessions = (s: SessionStore): LobeSessions => s.defaultSessions;-// Limit default sessions for sidebar display based on page size-const defaultSessionsLimited =- (pageSize: number) =>- (s: SessionStore): LobeSessions =>- s.defaultSessions.slice(0, pageSize);--const defaultSessionsCount = (s: SessionStore): number => s.defaultSessions.length;-const pinnedSessions = (s: SessionStore): LobeSessions => s.pinnedSessions;const customSessionGroups = (s: SessionStore): CustomSessionGroup[] => s.customSessionGroups;@@ -31,27 +22,12 @@ const getSessionById =(s: SessionStore): LobeSession =>sessionHelpers.getSessionById(id, allSessions(s));-const getSessionMetaById =- (id: string) =>- (s: SessionStore): MetaData => {- const session = getSessionById(id)(s);-- if (!session) return {};- return session.meta;- };-const currentSession = (s: SessionStore): LobeSession | undefined => {if (!s.activeId) return;return allSessions(s).find((i) => i.id === s.activeId);};-const currentSessionSafe = (s: SessionStore): LobeSession => {- return currentSession(s) || DEFAULT_AGENT_LOBE_SESSION;-};--const hasCustomAgents = (s: SessionStore) => defaultSessions(s).length > 0;-const isInboxSession = (s: SessionStore) => s.activeId === INBOX_SESSION_ID;const isCurrentSessionGroupSession = (s: SessionStore): boolean => {@@ -69,20 +45,14 @@ const currentGroupAgents = (s: SessionStore): GroupMemberWithAgent[] => {const isSessionListInit = (s: SessionStore) => s.isSessionsFirstFetchFinished;-// use to judge whether a session is fully activatedconst isSomeSessionActive = (s: SessionStore) => !!s.activeId && isSessionListInit(s);export const sessionSelectors = {currentGroupAgents,currentSession,- currentSessionSafe,customSessionGroups,defaultSessions,- defaultSessionsCount,- defaultSessionsLimited,getSessionById,- getSessionMetaById,- hasCustomAgents,isCurrentSessionGroupSession,isInboxSession,isSessionListInit,diff --git a/src/store/session/slices/session/selectors/meta.test.ts b/src/store/session/slices/session/selectors/meta.test.tsindex 1aaae81ca3e..1b515edf43e 100644--- a/src/store/session/slices/session/selectors/meta.test.ts+++ b/src/store/session/slices/session/selectors/meta.test.ts@@ -42,18 +42,4 @@ describe('sessionMetaSelectors', () => {expect(title).toBe('defaultSession'); // Assuming translation returns this key});});-- describe('getDescription', () => {- it('should return the description from the meta data', () => {- const meta: MetaData = { description: 'Custom Description' };- const description = sessionMetaSelectors.getDescription(meta);- expect(description).toBe(meta.description);- });-- it('should return the default description if none is defined in the meta data', () => {- const meta: MetaData = {};- const description = sessionMetaSelectors.getDescription(meta);- expect(description).toBe(undefined); // Assuming translation returns this key- });- });});diff --git a/src/store/session/slices/session/selectors/meta.ts b/src/store/session/slices/session/selectors/meta.tsindex 27b1c958a55..da57fee61f1 100644--- a/src/store/session/slices/session/selectors/meta.ts+++ b/src/store/session/slices/session/selectors/meta.ts@@ -1,37 +1,12 @@import { t } from 'i18next';import { DEFAULT_AVATAR } from '@/const/meta';-import { type SessionStore } from '@/store/session';import { type MetaData } from '@/types/meta';-import { merge } from '@/utils/merge';--import { sessionSelectors } from './list';--// ========== Meta ============== //--/**- * Get group chat meta data- * Note: For agent-related meta, use agentSelectors from @/store/agent/selectors instead- */-const currentGroupMeta = (s: SessionStore): MetaData => {- const defaultMeta = {- description: t('group.desc', { ns: 'chat' }),- title: t('group.title', { ns: 'chat' }),- };-- const session = sessionSelectors.currentSession(s);-- return merge(defaultMeta, session?.meta);-};const getAvatar = (s: MetaData) => s.avatar || DEFAULT_AVATAR;const getTitle = (s: MetaData) => s.title || t('defaultSession', { ns: 'common' });-// New session do not show 'noDescription'-export const getDescription = (s: MetaData) => s.description;export const sessionMetaSelectors = {- currentGroupMeta,getAvatar,- getDescription,getTitle,};diff --git a/src/store/session/store.ts b/src/store/session/store.tsindex 683a7100023..707ab4cd594 100644--- a/src/store/session/store.ts+++ b/src/store/session/store.ts@@ -11,10 +11,6 @@ import { flattenActions } from '../utils/flattenActions';import { type ResetableStore, ResetableStoreAction } from '../utils/resetableStore';import { type SessionStoreState } from './initialState';import { initialState } from './initialState';-import { type HomeInputAction } from './slices/homeInput/action';-import { createHomeInputSlice } from './slices/homeInput/action';-import { type RecentAction } from './slices/recent/action';-import { createRecentSlice } from './slices/recent/action';import { type SessionAction } from './slices/session/action';import { createSessionSlice } from './slices/session/action';import { type SessionGroupAction } from './slices/sessionGroup/action';@@ -23,19 +19,9 @@ import { createSessionGroupSlice } from './slices/sessionGroup/action';// =============== Aggregate createStoreFn ============ //export interface SessionStore- extends- SessionAction,- SessionGroupAction,- RecentAction,- HomeInputAction,- ResetableStore,- SessionStoreState {}+ extends SessionAction, SessionGroupAction, ResetableStore, SessionStoreState {}-type SessionStoreAction = SessionAction &- SessionGroupAction &- RecentAction &- HomeInputAction &- ResetableStore;+type SessionStoreAction = SessionAction & SessionGroupAction & ResetableStore;class SessionStoreResetAction extends ResetableStoreAction<SessionStore> {protected readonly resetActionName = 'resetSessionStore';@@ -48,8 +34,6 @@ const createStore: StateCreator<SessionStore, [['zustand/devtools', never]]> = (...flattenActions<SessionStoreAction>([createSessionSlice(...parameters),createSessionGroupSlice(...parameters),- createRecentSlice(...parameters),- createHomeInputSlice(...parameters),new SessionStoreResetAction(...parameters),]),});