File tree Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import { Input } from "@/components/ui/input";
11
11
import { ScrollArea } from "@/components/ui/scroll-area" ;
12
12
import { MessageCircle , Send , X } from "lucide-react" ;
13
13
import { ChatMessage , ChatState } from "../client" ;
14
- import { useCompletionMutation } from "../queries/ai" ;
14
+ import { useCompletionMutation , useFetchAiFlagsQuery } from "../queries/ai" ;
15
15
import ReactMarkdown from "react-markdown" ;
16
16
17
17
interface Conversation {
@@ -35,8 +35,8 @@ export function AIAssistantProvider({
35
35
} : {
36
36
children : React . ReactNode ;
37
37
} ) {
38
- // todo: querying the API to see if the feature is enabled.
39
- const [ isEnabled ] = useState ( true ) ;
38
+ const aiFlags = useFetchAiFlagsQuery ( ) ;
39
+ const isEnabled = aiFlags . data ?. completions || false ;
40
40
41
41
const [ isOpen , setIsOpen ] = useState ( false ) ;
42
42
const [ chatState , setChatState ] = useState ( { messages : [ ] } as ChatState ) ;
Original file line number Diff line number Diff line change 1
- import { useMutation } from "@tanstack/react-query" ;
1
+ import { useMutation , useQuery } from "@tanstack/react-query" ;
2
2
import { AxiosError } from "axios" ;
3
3
import { client } from "@app/axios-config/apiInit" ;
4
- import { ChatState , completions } from "@app/client" ;
4
+ import { aiFlags , ChatState , completions } from "@app/client" ;
5
+ import { dataOf } from "./dataOf" ;
5
6
6
7
export const useCompletionMutation = (
7
8
onError ?: ( err : AxiosError , next : ChatState ) => void ,
@@ -16,3 +17,13 @@ export const useCompletionMutation = (
16
17
onError,
17
18
} ) ;
18
19
} ;
20
+
21
+ export const useFetchAiFlagsQuery = ( ) => {
22
+ return useQuery ( {
23
+ queryKey : [ "ai/flags" ] ,
24
+ queryFn : ( ) => {
25
+ return dataOf ( aiFlags ( { client } ) ) ;
26
+ } ,
27
+ refetchInterval : false ,
28
+ } ) ;
29
+ } ;
You can’t perform that action at this time.
0 commit comments