11import axios from "axios"
22import { z } from "zod"
33import { useQuery , UseQueryOptions } from "@tanstack/react-query"
4+ import { toRequestyServiceUrl } from "@roo/utils/requesty"
45
56const requestyKeyInfoSchema = z . object ( {
67 name : z . string ( ) ,
@@ -14,11 +15,14 @@ const requestyKeyInfoSchema = z.object({
1415
1516export type RequestyKeyInfo = z . infer < typeof requestyKeyInfoSchema >
1617
17- async function getRequestyKeyInfo ( apiKey ?: string ) {
18+ async function getRequestyKeyInfo ( baseUrl ?: string , apiKey ?: string ) {
1819 if ( ! apiKey ) return null
1920
21+ const url = toRequestyServiceUrl ( baseUrl , "api" )
22+ const apiKeyUrl = new URL ( "x/apikey" , url )
23+
2024 try {
21- const response = await axios . get ( "https://api.requesty.ai/x/apikey" , {
25+ const response = await axios . get ( apiKeyUrl . toString ( ) , {
2226 headers : {
2327 Authorization : `Bearer ${ apiKey } ` ,
2428 "Content-Type" : "application/json" ,
@@ -39,10 +43,10 @@ async function getRequestyKeyInfo(apiKey?: string) {
3943}
4044
4145type UseRequestyKeyInfoOptions = Omit < UseQueryOptions < RequestyKeyInfo | null > , "queryKey" | "queryFn" >
42- export const useRequestyKeyInfo = ( apiKey ?: string , options ?: UseRequestyKeyInfoOptions ) => {
46+ export const useRequestyKeyInfo = ( baseUrl ?: string , apiKey ?: string , options ?: UseRequestyKeyInfoOptions ) => {
4347 return useQuery < RequestyKeyInfo | null > ( {
4448 queryKey : [ "requesty-key-info" , apiKey ] ,
45- queryFn : ( ) => getRequestyKeyInfo ( apiKey ) ,
49+ queryFn : ( ) => getRequestyKeyInfo ( baseUrl , apiKey ) ,
4650 staleTime : 30 * 1000 , // 30 seconds
4751 enabled : ! ! apiKey ,
4852 ...options ,
0 commit comments