@lobehub/chat
Version:
Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.
63 lines (56 loc) • 1.98 kB
text/typescript
import { CategoryItem, CategoryListQuery } from '@lobehub/market-sdk';
import { type SWRResponse } from 'swr';
import type { StateCreator } from 'zustand/vanilla';
import { useClientDataSWR } from '@/libs/swr';
import { discoverService } from '@/services/discover';
import { DiscoverStore } from '@/store/discover';
import { globalHelpers } from '@/store/global/helpers';
import {
DiscoverMcpDetail,
McpListResponse,
McpQueryParams,
} from '@/types/discover';
export interface MCPAction {
useFetchMcpDetail: (params: {
identifier?: string;
version?: string;
}) => SWRResponse<DiscoverMcpDetail>;
useFetchMcpList: (params: McpQueryParams) => SWRResponse<McpListResponse>;
useMcpCategories: (params: CategoryListQuery) => SWRResponse<CategoryItem[]>;
}
export const createMCPSlice: StateCreator<
DiscoverStore,
[['zustand/devtools', never]],
[],
MCPAction
> = () => ({
useFetchMcpDetail: ({ identifier, version }) => {
const locale = globalHelpers.getCurrentLanguage();
return useClientDataSWR(
!identifier ? null : ['mcp-detail', locale, identifier, version].filter(Boolean).join('-'),
async () => discoverService.getMcpDetail({ identifier: identifier!, version }),
);
},
useFetchMcpList: (params: any) => {
const locale = globalHelpers.getCurrentLanguage();
return useClientDataSWR(
['mcp-list', locale, ...Object.values(params)].filter(Boolean).join('-'),
async () =>
discoverService.getMcpList({
...params,
page: params.page ? Number(params.page) : 1,
pageSize: params.pageSize ? Number(params.pageSize) : 21,
}),
);
},
useMcpCategories: (params) => {
const locale = globalHelpers.getCurrentLanguage();
return useClientDataSWR(
['mcp-categories', locale, ...Object.values(params)].join('-'),
async () => discoverService.getMcpCategories(params),
{
revalidateOnFocus: false,
},
);
},
});