Skip to content

Commit 9cfe085

Browse files
committed
Move openrouter provider routing into advanced settings too
1 parent f1906c4 commit 9cfe085

File tree

2 files changed

+55
-50
lines changed

2 files changed

+55
-50
lines changed

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { memo, useCallback, useEffect, useMemo, useState } from "react"
22
import { convertHeadersToObject } from "./utils/headers"
33
import { useDebounce } from "react-use"
44
import { VSCodeLink } from "@vscode/webview-ui-toolkit/react"
5+
import { ExternalLinkIcon } from "@radix-ui/react-icons"
56

67
import {
78
type ProviderName,
@@ -31,6 +32,10 @@ import { useAppTranslation } from "@src/i18n/TranslationContext"
3132
import { useRouterModels } from "@src/components/ui/hooks/useRouterModels"
3233
import { useSelectedModel } from "@src/components/ui/hooks/useSelectedModel"
3334
import { useExtensionState } from "@src/context/ExtensionStateContext"
35+
import {
36+
useOpenRouterModelProviders,
37+
OPENROUTER_DEFAULT_PROVIDER_NAME,
38+
} from "@src/components/ui/hooks/useOpenRouterModelProviders"
3439
import { filterProviders, filterModels } from "./utils/organizationFilters"
3540
import {
3641
Select,
@@ -152,6 +157,14 @@ const ApiOptions = ({
152157

153158
const { data: routerModels, refetch: refetchRouterModels } = useRouterModels()
154159

160+
const { data: openRouterModelProviders } = useOpenRouterModelProviders(apiConfiguration?.openRouterModelId, {
161+
enabled:
162+
!!apiConfiguration?.openRouterModelId &&
163+
routerModels?.openrouter &&
164+
Object.keys(routerModels.openrouter).length > 1 &&
165+
apiConfiguration.openRouterModelId in routerModels.openrouter,
166+
})
167+
155168
// Update `apiModelId` whenever `selectedModelId` changes.
156169
useEffect(() => {
157170
if (selectedModelId) {
@@ -573,6 +586,48 @@ const ApiOptions = ({
573586
}
574587
onChange={(value) => setApiConfigurationField("consecutiveMistakeLimit", value)}
575588
/>
589+
{selectedProvider === "openrouter" &&
590+
openRouterModelProviders &&
591+
Object.keys(openRouterModelProviders).length > 0 && (
592+
<div>
593+
<div className="flex items-center gap-1">
594+
<label className="block font-medium mb-1">
595+
{t("settings:providers.openRouter.providerRouting.title")}
596+
</label>
597+
<a href={`https://openrouter.ai/${selectedModelId}/providers`}>
598+
<ExternalLinkIcon className="w-4 h-4" />
599+
</a>
600+
</div>
601+
<Select
602+
value={
603+
apiConfiguration?.openRouterSpecificProvider ||
604+
OPENROUTER_DEFAULT_PROVIDER_NAME
605+
}
606+
onValueChange={(value) =>
607+
setApiConfigurationField("openRouterSpecificProvider", value)
608+
}>
609+
<SelectTrigger className="w-full">
610+
<SelectValue placeholder={t("settings:common.select")} />
611+
</SelectTrigger>
612+
<SelectContent>
613+
<SelectItem value={OPENROUTER_DEFAULT_PROVIDER_NAME}>
614+
{OPENROUTER_DEFAULT_PROVIDER_NAME}
615+
</SelectItem>
616+
{Object.entries(openRouterModelProviders).map(([value, { label }]) => (
617+
<SelectItem key={value} value={value}>
618+
{label}
619+
</SelectItem>
620+
))}
621+
</SelectContent>
622+
</Select>
623+
<div className="text-sm text-vscode-descriptionForeground mt-1">
624+
{t("settings:providers.openRouter.providerRouting.description")}{" "}
625+
<a href="https://openrouter.ai/docs/features/provider-routing">
626+
{t("settings:providers.openRouter.providerRouting.learnMore")}.
627+
</a>
628+
</div>
629+
</div>
630+
)}
576631
</CollapsibleContent>
577632
</Collapsible>
578633
)}

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

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@ import { useCallback, useState } from "react"
22
import { Trans } from "react-i18next"
33
import { Checkbox } from "vscrui"
44
import { VSCodeTextField } from "@vscode/webview-ui-toolkit/react"
5-
import { ExternalLinkIcon } from "@radix-ui/react-icons"
65

76
import { type ProviderSettings, type OrganizationAllowList, openRouterDefaultModelId } from "@roo-code/types"
87

98
import type { RouterModels } from "@roo/api"
109

1110
import { useAppTranslation } from "@src/i18n/TranslationContext"
1211
import { getOpenRouterAuthUrl } from "@src/oauth/urls"
13-
import {
14-
useOpenRouterModelProviders,
15-
OPENROUTER_DEFAULT_PROVIDER_NAME,
16-
} from "@src/components/ui/hooks/useOpenRouterModelProviders"
1712
import { VSCodeButtonLink } from "@src/components/common/VSCodeButtonLink"
18-
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@src/components/ui"
1913

2014
import { inputEventTransform, noTransform } from "../transforms"
2115

@@ -37,7 +31,6 @@ export const OpenRouter = ({
3731
apiConfiguration,
3832
setApiConfigurationField,
3933
routerModels,
40-
selectedModelId,
4134
uriScheme,
4235
fromWelcomeView,
4336
organizationAllowList,
@@ -58,14 +51,6 @@ export const OpenRouter = ({
5851
[setApiConfigurationField],
5952
)
6053

61-
const { data: openRouterModelProviders } = useOpenRouterModelProviders(apiConfiguration?.openRouterModelId, {
62-
enabled:
63-
!!apiConfiguration?.openRouterModelId &&
64-
routerModels?.openrouter &&
65-
Object.keys(routerModels.openrouter).length > 1 &&
66-
apiConfiguration.openRouterModelId in routerModels.openrouter,
67-
})
68-
6954
return (
7055
<>
7156
<VSCodeTextField
@@ -139,41 +124,6 @@ export const OpenRouter = ({
139124
organizationAllowList={organizationAllowList}
140125
errorMessage={modelValidationError}
141126
/>
142-
{openRouterModelProviders && Object.keys(openRouterModelProviders).length > 0 && (
143-
<div>
144-
<div className="flex items-center gap-1">
145-
<label className="block font-medium mb-1">
146-
{t("settings:providers.openRouter.providerRouting.title")}
147-
</label>
148-
<a href={`https://openrouter.ai/${selectedModelId}/providers`}>
149-
<ExternalLinkIcon className="w-4 h-4" />
150-
</a>
151-
</div>
152-
<Select
153-
value={apiConfiguration?.openRouterSpecificProvider || OPENROUTER_DEFAULT_PROVIDER_NAME}
154-
onValueChange={(value) => setApiConfigurationField("openRouterSpecificProvider", value)}>
155-
<SelectTrigger className="w-full">
156-
<SelectValue placeholder={t("settings:common.select")} />
157-
</SelectTrigger>
158-
<SelectContent>
159-
<SelectItem value={OPENROUTER_DEFAULT_PROVIDER_NAME}>
160-
{OPENROUTER_DEFAULT_PROVIDER_NAME}
161-
</SelectItem>
162-
{Object.entries(openRouterModelProviders).map(([value, { label }]) => (
163-
<SelectItem key={value} value={value}>
164-
{label}
165-
</SelectItem>
166-
))}
167-
</SelectContent>
168-
</Select>
169-
<div className="text-sm text-vscode-descriptionForeground mt-1">
170-
{t("settings:providers.openRouter.providerRouting.description")}{" "}
171-
<a href="https://openrouter.ai/docs/features/provider-routing">
172-
{t("settings:providers.openRouter.providerRouting.learnMore")}.
173-
</a>
174-
</div>
175-
</div>
176-
)}
177127
</>
178128
)
179129
}

0 commit comments

Comments
 (0)