diff --git a/src/api/providers/fetchers/modelCache.ts b/src/api/providers/fetchers/modelCache.ts index a21e75ded9..f4c240a61c 100644 --- a/src/api/providers/fetchers/modelCache.ts +++ b/src/api/providers/fetchers/modelCache.ts @@ -59,7 +59,7 @@ export const getModels = async (options: GetModelsOptions): Promise break case "requesty": // Requesty models endpoint requires an API key for per-user custom policies - models = await getRequestyModels(options.apiKey) + models = await getRequestyModels(options.baseUrl, options.apiKey) break case "glama": models = await getGlamaModels() diff --git a/src/api/providers/fetchers/requesty.ts b/src/api/providers/fetchers/requesty.ts index e339dae1aa..308539f2e4 100644 --- a/src/api/providers/fetchers/requesty.ts +++ b/src/api/providers/fetchers/requesty.ts @@ -3,8 +3,9 @@ import axios from "axios" import type { ModelInfo } from "@roo-code/types" import { parseApiPrice } from "../../../shared/cost" +import { toRequestyServiceUrl } from "../../../shared/utils/requesty" -export async function getRequestyModels(apiKey?: string): Promise> { +export async function getRequestyModels(baseUrl?: string, apiKey?: string): Promise> { const models: Record = {} try { @@ -14,8 +15,10 @@ export async function getRequestyModels(apiKey?: string): Promise { + if (type === "router") { + return baseUrl + } else { + return baseUrl.replace("router", type).replace("v1", "") + } +} + +export const toRequestyServiceUrl = (baseUrl?: string, service: URLType = "router"): string => { + let url = replaceCname(baseUrl ?? REQUESTY_BASE_URL, service) + + return new URL(url).toString() +} diff --git a/webview-ui/src/components/settings/providers/RequestyBalanceDisplay.tsx b/webview-ui/src/components/settings/providers/RequestyBalanceDisplay.tsx index 9eb9734499..8c77c35ed6 100644 --- a/webview-ui/src/components/settings/providers/RequestyBalanceDisplay.tsx +++ b/webview-ui/src/components/settings/providers/RequestyBalanceDisplay.tsx @@ -1,9 +1,15 @@ import { VSCodeLink } from "@vscode/webview-ui-toolkit/react" import { useRequestyKeyInfo } from "@/components/ui/hooks/useRequestyKeyInfo" +import { toRequestyServiceUrl } from "@roo/utils/requesty" -export const RequestyBalanceDisplay = ({ apiKey }: { apiKey: string }) => { - const { data: keyInfo } = useRequestyKeyInfo(apiKey) +type RequestyBalanceDisplayProps = { + apiKey: string + baseUrl?: string +} + +export const RequestyBalanceDisplay = ({ baseUrl, apiKey }: RequestyBalanceDisplayProps) => { + const { data: keyInfo } = useRequestyKeyInfo(baseUrl, apiKey) if (!keyInfo) { return null @@ -13,8 +19,11 @@ export const RequestyBalanceDisplay = ({ apiKey }: { apiKey: string }) => { const balance = parseFloat(keyInfo.org_balance) const formattedBalance = balance.toFixed(2) + const resolvedBaseUrl = toRequestyServiceUrl(baseUrl, "app") + const settingsUrl = new URL("settings", resolvedBaseUrl) + return ( - + ${formattedBalance} ) diff --git a/webview-ui/src/components/ui/hooks/useRequestyKeyInfo.ts b/webview-ui/src/components/ui/hooks/useRequestyKeyInfo.ts index e44aa5fcd1..8505157a0f 100644 --- a/webview-ui/src/components/ui/hooks/useRequestyKeyInfo.ts +++ b/webview-ui/src/components/ui/hooks/useRequestyKeyInfo.ts @@ -1,6 +1,7 @@ import axios from "axios" import { z } from "zod" import { useQuery, UseQueryOptions } from "@tanstack/react-query" +import { toRequestyServiceUrl } from "@roo/utils/requesty" const requestyKeyInfoSchema = z.object({ name: z.string(), @@ -14,11 +15,14 @@ const requestyKeyInfoSchema = z.object({ export type RequestyKeyInfo = z.infer -async function getRequestyKeyInfo(apiKey?: string) { +async function getRequestyKeyInfo(baseUrl?: string, apiKey?: string) { if (!apiKey) return null + const url = toRequestyServiceUrl(baseUrl, "api") + const apiKeyUrl = new URL("x/apikey", url) + try { - const response = await axios.get("https://api.requesty.ai/x/apikey", { + const response = await axios.get(apiKeyUrl.toString(), { headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", @@ -39,10 +43,10 @@ async function getRequestyKeyInfo(apiKey?: string) { } type UseRequestyKeyInfoOptions = Omit, "queryKey" | "queryFn"> -export const useRequestyKeyInfo = (apiKey?: string, options?: UseRequestyKeyInfoOptions) => { +export const useRequestyKeyInfo = (baseUrl?: string, apiKey?: string, options?: UseRequestyKeyInfoOptions) => { return useQuery({ queryKey: ["requesty-key-info", apiKey], - queryFn: () => getRequestyKeyInfo(apiKey), + queryFn: () => getRequestyKeyInfo(baseUrl, apiKey), staleTime: 30 * 1000, // 30 seconds enabled: !!apiKey, ...options,