{"version":3,"file":"useConversationQueries-CWHHbZeG.js","sources":["../../../packs/frontend/composables/ai-chat/useConversationQueries.ts"],"sourcesContent":["import {\n AppNamespaceEnum,\n AiConversationInput,\n} from \"@/services/fobizzToolsApi\";\n\nconst PAGINATION_LIMIT = 16;\n\nexport function useConversationQueries() {\n const queryClient = useQueryClient();\n const { aiConversations } = useApiClient();\n\n const isConversationsLoading = useIsFetching({ queryKey: [\"conversations\"] });\n\n const indexQuery = (query: Ref, assistantCategory?: string) => {\n return useInfiniteQuery({\n queryKey: [\"conversations\", query, assistantCategory],\n queryFn: ({ pageParam }) => {\n if (query.value.length > 0) {\n return aiConversations.searchAiConversations({\n page: pageParam,\n limit: PAGINATION_LIMIT,\n query: query.value,\n });\n } else {\n return aiConversations.listAiConversations({\n page: pageParam,\n limit: PAGINATION_LIMIT,\n query: query.value,\n ...(assistantCategory && { assistantCategory: assistantCategory }),\n });\n }\n },\n initialPageParam: 0,\n getPreviousPageParam: (lastPage, _pages) => lastPage.prevPage,\n getNextPageParam: (lastPage, _pages) => lastPage.nextPage,\n });\n };\n\n const getQuery = (conversationId: Ref) => {\n return useQuery(\n {\n queryKey: [\"conversation\", conversationId],\n queryFn: () =>\n aiConversations.getAiConversation({\n id: conversationId.value,\n }),\n },\n queryClient\n );\n };\n\n const useDeleteMutation = (id: string) => {\n return useMutation(\n {\n mutationFn: () => aiConversations.deleteAiConversation({ id: id }),\n onSuccess: () => {\n queryClient.invalidateQueries({\n queryKey: [\"conversations\"],\n });\n },\n },\n queryClient\n );\n };\n\n const useCreateMutation = () => {\n return useMutation(\n {\n mutationFn: (params: Partial) =>\n aiConversations.createAiConversation({\n requestBody: { conversation: params },\n }),\n onSuccess: () => {\n queryClient.invalidateQueries({\n queryKey: [\"conversations\"],\n });\n queryClient.invalidateQueries({\n queryKey: [AppNamespaceEnum.AI_ASSISTANT, \"recentlyUsed\"],\n });\n },\n },\n queryClient\n );\n };\n\n const useUpdateMutation = (conversationId: string) => {\n return useMutation(\n {\n mutationFn: (params: Partial) =>\n aiConversations.updateAiConversation({\n id: conversationId,\n requestBody: { conversation: params },\n }),\n onSuccess: () => {\n queryClient.invalidateQueries({\n queryKey: [\"conversations\"],\n });\n queryClient.invalidateQueries({\n queryKey: [\"conversation\", conversationId],\n });\n },\n },\n queryClient\n );\n };\n\n return {\n indexQuery,\n getQuery,\n useCreateMutation,\n useUpdateMutation,\n useDeleteMutation,\n isConversationsLoading,\n };\n}\n"],"names":["PAGINATION_LIMIT","useConversationQueries","queryClient","useQueryClient","aiConversations","useApiClient","isConversationsLoading","useIsFetching","query","assistantCategory","useInfiniteQuery","pageParam","lastPage","_pages","conversationId","useQuery","useMutation","params","AppNamespaceEnum","id"],"mappings":"4RAKA,MAAMA,EAAmB,GAElB,SAASC,GAAyB,CACvC,MAAMC,EAAcC,EAAe,EAC7B,CAAE,gBAAAC,CAAgB,EAAIC,EAAa,EAEnCC,EAAyBC,EAAc,CAAE,SAAU,CAAC,eAAe,EAAG,EA+FrE,MAAA,CACL,WA9FiB,CAACC,EAAoBC,IAC/BC,EAAiB,CACtB,SAAU,CAAC,gBAAiBF,EAAOC,CAAiB,EACpD,QAAS,CAAC,CAAE,UAAAE,KACNH,EAAM,MAAM,OAAS,EAChBJ,EAAgB,sBAAsB,CAC3C,KAAMO,EACN,MAAOX,EACP,MAAOQ,EAAM,KAAA,CACd,EAEMJ,EAAgB,oBAAoB,CACzC,KAAMO,EACN,MAAOX,EACP,MAAOQ,EAAM,MACb,GAAIC,GAAqB,CAAE,kBAAAA,CAAqC,CAAA,CACjE,EAGL,iBAAkB,EAClB,qBAAsB,CAACG,EAAUC,IAAWD,EAAS,SACrD,iBAAkB,CAACA,EAAUC,IAAWD,EAAS,QAAA,CAClD,EAyED,SAtEgBE,GACTC,EACL,CACE,SAAU,CAAC,eAAgBD,CAAc,EACzC,QAAS,IACPV,EAAgB,kBAAkB,CAChC,GAAIU,EAAe,KACpB,CAAA,CACL,EACAZ,CACF,EA6DA,kBA5CwB,IAC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