Skip to content

Commit 0bfa63a

Browse files
Thibault00daniel-lxs
authored andcommitted
added configurations for base url api keys
fixed URL construction for models and balance endpoints
1 parent 29d782f commit 0bfa63a

File tree

4 files changed

+45
-9
lines changed

4 files changed

+45
-9
lines changed

src/core/webview/webviewMessageHandler.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,14 @@ export const webviewMessageHandler = async (
565565

566566
const modelFetchPromises: Array<{ key: RouterName; options: GetModelsOptions }> = [
567567
{ key: "openrouter", options: { provider: "openrouter" } },
568-
{ key: "requesty", options: { provider: "requesty", apiKey: apiConfiguration.requestyApiKey } },
568+
{
569+
key: "requesty",
570+
options: {
571+
provider: "requesty",
572+
apiKey: apiConfiguration.requestyApiKey,
573+
baseUrl: apiConfiguration.requestyBaseUrl,
574+
},
575+
},
569576
{ key: "glama", options: { provider: "glama" } },
570577
{ key: "unbound", options: { provider: "unbound", apiKey: apiConfiguration.unboundApiKey } },
571578
]

src/shared/utils/requesty.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,11 @@ const replaceCname = (baseUrl: string, type: URLType): string => {
1313
export const toRequestyServiceUrl = (baseUrl?: string, service: URLType = "router"): string => {
1414
let url = replaceCname(baseUrl ?? REQUESTY_BASE_URL, service)
1515

16-
return new URL(url).toString()
16+
try {
17+
return new URL(url).toString()
18+
} catch (error) {
19+
// If the provided baseUrl is invalid, fall back to the default
20+
console.warn(`Invalid base URL "${baseUrl}", falling back to default`)
21+
return new URL(replaceCname(REQUESTY_BASE_URL, service)).toString()
22+
}
1723
}

webview-ui/src/components/settings/ApiOptions.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ const ApiOptions = ({
424424

425425
{selectedProvider === "requesty" && (
426426
<Requesty
427+
uriScheme={uriScheme}
427428
apiConfiguration={apiConfiguration}
428429
setApiConfigurationField={setApiConfigurationField}
429430
routerModels={routerModels}

webview-ui/src/components/settings/providers/Requesty.tsx

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import type { RouterModels } from "@roo/api"
88

99
import { vscode } from "@src/utils/vscode"
1010
import { useAppTranslation } from "@src/i18n/TranslationContext"
11-
import { VSCodeButtonLink } from "@src/components/common/VSCodeButtonLink"
1211
import { Button } from "@src/components/ui"
1312

1413
import { inputEventTransform } from "../transforms"
1514
import { ModelPicker } from "../ModelPicker"
1615
import { RequestyBalanceDisplay } from "./RequestyBalanceDisplay"
16+
import { getCallbackUrl } from "@/oauth/urls"
17+
import { toRequestyServiceUrl } from "@roo/utils/requesty"
1718

1819
type RequestyProps = {
1920
apiConfiguration: ProviderSettings
@@ -22,6 +23,7 @@ type RequestyProps = {
2223
refetchRouterModels: () => void
2324
organizationAllowList: OrganizationAllowList
2425
modelValidationError?: string
26+
uriScheme?: string
2527
}
2628

2729
export const Requesty = ({
@@ -31,6 +33,7 @@ export const Requesty = ({
3133
refetchRouterModels,
3234
organizationAllowList,
3335
modelValidationError,
36+
uriScheme,
3437
}: RequestyProps) => {
3538
const { t } = useAppTranslation()
3639

@@ -54,6 +57,15 @@ export const Requesty = ({
5457
[setApiConfigurationField],
5558
)
5659

60+
const getApiKeyUrl = () => {
61+
const callbackUrl = getCallbackUrl("requesty", uriScheme)
62+
const baseUrl = toRequestyServiceUrl(apiConfiguration.requestyBaseUrl, "app")
63+
64+
const authUrl = new URL(`oauth/authorize?callback_url=${callbackUrl}`, baseUrl)
65+
66+
return authUrl.toString()
67+
}
68+
5769
return (
5870
<>
5971
<VSCodeTextField
@@ -65,20 +77,30 @@ export const Requesty = ({
6577
<div className="flex justify-between items-center mb-1">
6678
<label className="block font-medium">{t("settings:providers.requestyApiKey")}</label>
6779
{apiConfiguration?.requestyApiKey && (
68-
<RequestyBalanceDisplay apiKey={apiConfiguration.requestyApiKey} />
80+
<RequestyBalanceDisplay
81+
baseUrl={apiConfiguration.requestyBaseUrl}
82+
apiKey={apiConfiguration.requestyApiKey}
83+
/>
6984
)}
7085
</div>
7186
</VSCodeTextField>
7287
<div className="text-sm text-vscode-descriptionForeground -mt-2">
7388
{t("settings:providers.apiKeyStorageNotice")}
7489
</div>
7590
{!apiConfiguration?.requestyApiKey && (
76-
<VSCodeButtonLink
77-
href="https://app.requesty.ai/api-keys"
78-
style={{ width: "100%" }}
79-
appearance="primary">
91+
<a
92+
href={getApiKeyUrl()}
93+
target="_blank"
94+
rel="noopener noreferrer"
95+
className="inline-flex items-center justify-center whitespace-nowrap text-sm font-medium focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground shadow hover:bg-primary/90 h-9 rounded-md px-3 w-full"
96+
style={{
97+
width: "100%",
98+
textDecoration: "none",
99+
color: "var(--vscode-button-foreground)",
100+
backgroundColor: "var(--vscode-button-background)",
101+
}}>
80102
{t("settings:providers.getRequestyApiKey")}
81-
</VSCodeButtonLink>
103+
</a>
82104
)}
83105

84106
<VSCodeCheckbox

0 commit comments

Comments
 (0)