From f0a5bd68da622cb278fa354d53e0e16660d6aa42 Mon Sep 17 00:00:00 2001 From: Thibault Jaigu Date: Tue, 19 Aug 2025 11:32:17 +0100 Subject: [PATCH] added configurations for base url api keys fixed URL construction for models and balance endpoints --- src/core/webview/webviewMessageHandler.ts | 9 ++++- src/shared/utils/requesty.ts | 8 ++++- .../src/components/settings/ApiOptions.tsx | 1 + .../settings/providers/Requesty.tsx | 36 +++++++++++++++---- 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/core/webview/webviewMessageHandler.ts b/src/core/webview/webviewMessageHandler.ts index d16ed06132..e302108b67 100644 --- a/src/core/webview/webviewMessageHandler.ts +++ b/src/core/webview/webviewMessageHandler.ts @@ -548,7 +548,14 @@ export const webviewMessageHandler = async ( const modelFetchPromises: Array<{ key: RouterName; options: GetModelsOptions }> = [ { key: "openrouter", options: { provider: "openrouter" } }, - { key: "requesty", options: { provider: "requesty", apiKey: apiConfiguration.requestyApiKey } }, + { + key: "requesty", + options: { + provider: "requesty", + apiKey: apiConfiguration.requestyApiKey, + baseUrl: apiConfiguration.requestyBaseUrl, + }, + }, { key: "glama", options: { provider: "glama" } }, { key: "unbound", options: { provider: "unbound", apiKey: apiConfiguration.unboundApiKey } }, ] diff --git a/src/shared/utils/requesty.ts b/src/shared/utils/requesty.ts index 6b7b4c8788..78fcfc4e87 100644 --- a/src/shared/utils/requesty.ts +++ b/src/shared/utils/requesty.ts @@ -13,5 +13,11 @@ const replaceCname = (baseUrl: string, type: URLType): string => { export const toRequestyServiceUrl = (baseUrl?: string, service: URLType = "router"): string => { let url = replaceCname(baseUrl ?? REQUESTY_BASE_URL, service) - return new URL(url).toString() + try { + return new URL(url).toString() + } catch (error) { + // If the provided baseUrl is invalid, fall back to the default + console.warn(`Invalid base URL "${baseUrl}", falling back to default`) + return new URL(replaceCname(REQUESTY_BASE_URL, service)).toString() + } } diff --git a/webview-ui/src/components/settings/ApiOptions.tsx b/webview-ui/src/components/settings/ApiOptions.tsx index b51b171354..fbb729f9d2 100644 --- a/webview-ui/src/components/settings/ApiOptions.tsx +++ b/webview-ui/src/components/settings/ApiOptions.tsx @@ -419,6 +419,7 @@ const ApiOptions = ({ {selectedProvider === "requesty" && ( void organizationAllowList: OrganizationAllowList modelValidationError?: string + uriScheme?: string } export const Requesty = ({ @@ -31,6 +33,7 @@ export const Requesty = ({ refetchRouterModels, organizationAllowList, modelValidationError, + uriScheme, }: RequestyProps) => { const { t } = useAppTranslation() @@ -54,6 +57,15 @@ export const Requesty = ({ [setApiConfigurationField], ) + const getApiKeyUrl = () => { + const callbackUrl = getCallbackUrl("requesty", uriScheme) + const baseUrl = toRequestyServiceUrl(apiConfiguration.requestyBaseUrl, "app") + + const authUrl = new URL(`oauth/authorize?callback_url=${callbackUrl}`, baseUrl) + + return authUrl.toString() + } + return ( <> {apiConfiguration?.requestyApiKey && ( - + )} @@ -73,12 +88,19 @@ export const Requesty = ({ {t("settings:providers.apiKeyStorageNotice")} {!apiConfiguration?.requestyApiKey && ( - + {t("settings:providers.getRequestyApiKey")} - + )}