-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: use custom base URL for all Requesty requests #7276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ import type { ModelInfo } from "@roo-code/types" | |
|
|
||
| import { parseApiPrice } from "../../../shared/cost" | ||
|
|
||
| export async function getRequestyModels(apiKey?: string): Promise<Record<string, ModelInfo>> { | ||
| export async function getRequestyModels(apiKey?: string, baseUrl?: string): Promise<Record<string, ModelInfo>> { | ||
| const models: Record<string, ModelInfo> = {} | ||
|
|
||
| try { | ||
|
|
@@ -14,7 +14,9 @@ export async function getRequestyModels(apiKey?: string): Promise<Record<string, | |
| headers["Authorization"] = `Bearer ${apiKey}` | ||
| } | ||
|
|
||
| const url = "https://router.requesty.ai/v1/models" | ||
| // Use the base URL if provided, otherwise default to the router endpoint | ||
| const apiUrl = baseUrl ? baseUrl.replace(/\/$/, "") : "https://router.requesty.ai" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding JSDoc comments to document the expected format of the baseUrl parameter and what transformations are applied. This would help future maintainers understand the URL handling logic. |
||
| const url = `${apiUrl}/v1/models` | ||
| const response = await axios.get(url, { headers }) | ||
| const rawModels = response.data.data | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,7 +65,10 @@ export const Requesty = ({ | |
| <div className="flex justify-between items-center mb-1"> | ||
| <label className="block font-medium">{t("settings:providers.requestyApiKey")}</label> | ||
| {apiConfiguration?.requestyApiKey && ( | ||
| <RequestyBalanceDisplay apiKey={apiConfiguration.requestyApiKey} /> | ||
| <RequestyBalanceDisplay | ||
| apiKey={apiConfiguration.requestyApiKey} | ||
| baseUrl={apiConfiguration?.requestyBaseUrl} | ||
| /> | ||
| )} | ||
| </div> | ||
| </VSCodeTextField> | ||
|
|
@@ -74,7 +77,16 @@ export const Requesty = ({ | |
| </div> | ||
| {!apiConfiguration?.requestyApiKey && ( | ||
| <VSCodeButtonLink | ||
| href="https://app.requesty.ai/api-keys" | ||
| href={(() => { | ||
| const baseUrl = apiConfiguration?.requestyBaseUrl || "https://app.requesty.ai" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no validation that the custom base URL is a valid URL format. Invalid URLs could cause runtime errors. Consider adding basic URL validation before using the value. |
||
| // Remove trailing slash if present and ensure we're using the app subdomain | ||
| const cleanBaseUrl = baseUrl.replace(/\/$/, "") | ||
| // If the base URL contains 'router' or 'api', replace with 'app' for web interface | ||
| const appUrl = cleanBaseUrl | ||
| .replace(/router\.requesty/, "app.requesty") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This URL transformation logic is duplicated in RequestyBalanceDisplay.tsx and urls.ts. Would it make sense to extract this into a shared utility function like |
||
| .replace(/api\.requesty/, "app.requesty") | ||
| return `${appUrl}/api-keys` | ||
| })()} | ||
| style={{ width: "100%" }} | ||
| appearance="primary"> | ||
| {t("settings:providers.getRequestyApiKey")} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,11 +14,16 @@ const requestyKeyInfoSchema = z.object({ | |
|
|
||
| export type RequestyKeyInfo = z.infer<typeof requestyKeyInfoSchema> | ||
|
|
||
| async function getRequestyKeyInfo(apiKey?: string) { | ||
| async function getRequestyKeyInfo(apiKey?: string, baseUrl?: string) { | ||
| if (!apiKey) return null | ||
|
|
||
| try { | ||
| const response = await axios.get("https://api.requesty.ai/x/apikey", { | ||
| // Use the base URL if provided, otherwise default to the standard API endpoint | ||
| const apiUrl = baseUrl ? baseUrl.replace(/\/$/, "") : "https://api.requesty.ai" | ||
| // Convert router.requesty.ai to api.requesty.ai for API calls | ||
| const cleanApiUrl = apiUrl.replace(/router\.requesty/, "api.requesty").replace(/app\.requesty/, "api.requesty") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if someone uses a completely custom domain that doesn't follow the .requesty. pattern (e.g., https://my-requesty-instance.com)? The current regex replacements might not handle this case correctly. |
||
|
|
||
| const response = await axios.get(`${cleanApiUrl}/x/apikey`, { | ||
| headers: { | ||
| Authorization: `Bearer ${apiKey}`, | ||
| "Content-Type": "application/json", | ||
|
|
@@ -39,10 +44,10 @@ async function getRequestyKeyInfo(apiKey?: string) { | |
| } | ||
|
|
||
| type UseRequestyKeyInfoOptions = Omit<UseQueryOptions<RequestyKeyInfo | null>, "queryKey" | "queryFn"> | ||
| export const useRequestyKeyInfo = (apiKey?: string, options?: UseRequestyKeyInfoOptions) => { | ||
| export const useRequestyKeyInfo = (apiKey?: string, baseUrl?: string, options?: UseRequestyKeyInfoOptions) => { | ||
| return useQuery<RequestyKeyInfo | null>({ | ||
| queryKey: ["requesty-key-info", apiKey], | ||
| queryFn: () => getRequestyKeyInfo(apiKey), | ||
| queryKey: ["requesty-key-info", apiKey, baseUrl], | ||
| queryFn: () => getRequestyKeyInfo(apiKey, baseUrl), | ||
| staleTime: 30 * 1000, // 30 seconds | ||
| enabled: !!apiKey, | ||
| ...options, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new baseUrl parameter works, but there's no test coverage for this functionality. Could we add unit tests to verify the URL transformations work correctly with different subdomain patterns (router/api/app)?