11import { useInfiniteQuery , useMutation , useQuery , useQueryClient } from '@tanstack/react-query' ;
2+ import { useContext } from 'react' ;
23import { useGenAiAPI } from '~/app/hooks/useGenAiAPI' ;
4+ import { GenAiContext } from '~/app/context/GenAiContext' ;
35import {
46 MLflowPrompt ,
57 MLflowPromptsResponse ,
@@ -24,6 +26,7 @@ type UsePromptsListResult = {
2426export function usePromptsList ( options : UsePromptsListOptions = { } ) : UsePromptsListResult {
2527 const { api, apiAvailable } = useGenAiAPI ( ) ;
2628 const { maxResults, filterName } = options ;
29+ const { namespace } = useContext ( GenAiContext ) ;
2730
2831 const { data, isLoading, isFetchingNextPage, hasNextPage, fetchNextPage, error } =
2932 useInfiniteQuery <
@@ -33,7 +36,7 @@ export function usePromptsList(options: UsePromptsListOptions = {}): UsePromptsL
3336 [ string , string , { maxResults ?: number ; filterName ?: string } ] ,
3437 string | undefined
3538 > ( {
36- queryKey : [ 'prompts' , 'list' , { maxResults, filterName } ] ,
39+ queryKey : [ ` ${ namespace ?. name } _prompts` , 'list' , { maxResults, filterName } ] ,
3740 queryFn : async ( { pageParam } ) => {
3841 const queryParams : Record < string , unknown > = { } ;
3942 if ( maxResults !== undefined ) {
@@ -75,9 +78,10 @@ type UsePromptVersionsResult = {
7578
7679export function usePromptVersions ( promptName : string | null ) : UsePromptVersionsResult {
7780 const { api, apiAvailable } = useGenAiAPI ( ) ;
81+ const { namespace } = useContext ( GenAiContext ) ;
7882
7983 const { data, isLoading, error } = useQuery ( {
80- queryKey : [ 'prompts' , promptName , 'versions' ] ,
84+ queryKey : [ ` ${ namespace ?. name } _prompts` , promptName , 'versions' ] ,
8185 queryFn : async ( ) => {
8286 if ( ! promptName ) {
8387 return [ ] ;
@@ -109,9 +113,10 @@ type UseLatestPromptVersionResult = {
109113
110114export function useLatestPromptVersion ( promptName : string | null ) : UseLatestPromptVersionResult {
111115 const { api, apiAvailable } = useGenAiAPI ( ) ;
116+ const { namespace } = useContext ( GenAiContext ) ;
112117
113118 const { data, isLoading, error } = useQuery ( {
114- queryKey : [ 'prompts' , promptName , 'latest' ] ,
119+ queryKey : [ ` ${ namespace ?. name } _prompts` , promptName , 'latest' ] ,
115120 queryFn : ( ) => api . getMLflowPrompt ( { name : promptName ! } ) ,
116121 enabled : ! ! promptName && apiAvailable ,
117122 staleTime : 0 ,
@@ -138,6 +143,7 @@ type UseCreatePromptResult = {
138143export function useCreatePrompt ( options : UseCreatePromptOptions = { } ) : UseCreatePromptResult {
139144 const { api, apiAvailable } = useGenAiAPI ( ) ;
140145 const queryClient = useQueryClient ( ) ;
146+ const { namespace } = useContext ( GenAiContext ) ;
141147 const { onSuccess, onError } = options ;
142148
143149 const { mutate, isPending, error } = useMutation <
@@ -152,8 +158,10 @@ export function useCreatePrompt(options: UseCreatePromptOptions = {}): UseCreate
152158 return api . registerMLflowPrompt ( request ) ;
153159 } ,
154160 onSuccess : ( data ) => {
155- queryClient . invalidateQueries ( { queryKey : [ 'prompts' , 'list' ] } ) ;
156- queryClient . invalidateQueries ( { queryKey : [ 'prompts' , data . name , 'versions' ] } ) ;
161+ queryClient . invalidateQueries ( { queryKey : [ `${ namespace ?. name } _prompts` , 'list' ] } ) ;
162+ queryClient . invalidateQueries ( {
163+ queryKey : [ `${ namespace ?. name } _prompts` , data . name , 'versions' ] ,
164+ } ) ;
157165 onSuccess ?.( data ) ;
158166 } ,
159167 onError,
0 commit comments