Skip to content

🤯 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.

1.1 KB
Raw Blame
import { shallow } from 'zustand/shallow';
import { createWithEqualityFn } from 'zustand/traditional';
import { type StateCreator } from 'zustand/vanilla';

import { createDevtools } from '../middleware/createDevtools';
import { expose } from '../middleware/expose';
import { flattenActions } from '../utils/flattenActions';
import { type ChatGroupAction } from './action';
import { chatGroupAction } from './action';
import { type ChatGroupState } from './initialState';
import { initialChatGroupState } from './initialState';

export type ChatGroupStore = ChatGroupState & ChatGroupAction;

const createStore: StateCreator<ChatGroupStore, [['zustand/devtools', never]]> = (
  ...params: Parameters<StateCreator<ChatGroupStore, [['zustand/devtools', never]]>>
) => ({
  ...initialChatGroupState,
  ...flattenActions<ChatGroupAction>([chatGroupAction(...params)]),
});

const devtools = createDevtools('agentGroup');

export const useAgentGroupStore = createWithEqualityFn<ChatGroupStore>()(
  devtools(createStore),
  shallow,
);

expose('agentGroup', useAgentGroupStore);

export const getChatGroupStoreState = () => useAgentGroupStore.getState();