-
Notifications
You must be signed in to change notification settings - Fork 84
feat(zoo-gateway): settings UI, validation, and i18n #345
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
Open
JamesRobert20
wants to merge
8
commits into
feat/zoo-gateway-types-core
Choose a base branch
from
feat/zoo-gateway-settings-ui
base: feat/zoo-gateway-types-core
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1743ce2
feat(zoo-gateway): add settings UI, validation, and i18n
54e9af8
fix(zoo-gateway): dynamic dashboard URL and cached-token fallback
54da799
fix(deps): drop stale webview-ui package.json drift that broke frozen…
577ef59
fix(i18n): restore googleCloudCredentialsPathWarning and automaticFet…
aa7b3b2
fix(zoo-gateway): pick default model from fetched list, prefer Sonnet…
e70d680
test(zoo-gateway): cover dynamic default model picker for codecov patch
51ce450
fix(i18n): restore UTF-8 for Google Cloud warning and model picker st…
2e677ba
fix(zoo-gateway): settings UI sign-in button, validation tests, defer…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
webview-ui/src/components/settings/providers/ZooGateway.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| import { useEffect, useMemo } from "react" | ||
| import { | ||
| type ProviderSettings, | ||
| type OrganizationAllowList, | ||
| type RouterModels, | ||
| zooGatewayDefaultModelId, | ||
| } from "@roo-code/types" | ||
|
|
||
| import { useExtensionState } from "@src/context/ExtensionStateContext" | ||
| import { getZooCodeAuthUrl } from "@src/oauth/urls" | ||
| import { useAppTranslation } from "@src/i18n/TranslationContext" | ||
| import { VSCodeButtonLink } from "@src/components/common/VSCodeButtonLink" | ||
|
|
||
| import { ModelPicker } from "../ModelPicker" | ||
|
|
||
| type ZooGatewayProps = { | ||
| apiConfiguration: ProviderSettings | ||
| setApiConfigurationField: (field: keyof ProviderSettings, value: ProviderSettings[keyof ProviderSettings]) => void | ||
| routerModels?: RouterModels | ||
| organizationAllowList: OrganizationAllowList | ||
| modelValidationError?: string | ||
| simplifySettings?: boolean | ||
| } | ||
|
|
||
| function isSonnet45ModelId(id: string) { | ||
|
Contributor
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. Not your fault because it's the standard, but putting numbers for function names feels so so wrong 😂😂 |
||
| return /sonnet-4[.-]5|sonnet-4\.5/i.test(id) | ||
| } | ||
|
|
||
| // Exported for unit tests. | ||
| export function pickZooGatewayDefaultModelId(modelIds: string[]) { | ||
| if (modelIds.length === 0) { | ||
| return zooGatewayDefaultModelId | ||
| } | ||
|
|
||
| const sonnet45 = modelIds.filter(isSonnet45ModelId) | ||
| if (sonnet45.length > 0) { | ||
| return ( | ||
| sonnet45.find((id) => id === "anthropic/claude-sonnet-4.5") ?? | ||
| sonnet45.find((id) => id.includes("claude-sonnet-4.5")) ?? | ||
| sonnet45[0] | ||
| ) | ||
| } | ||
|
|
||
| const sonnet4 = modelIds.filter((id) => /claude/i.test(id) && /sonnet/i.test(id) && /sonnet-4/i.test(id)) | ||
| if (sonnet4.length > 0) { | ||
| return sonnet4[0] | ||
| } | ||
|
|
||
| return modelIds[0] | ||
| } | ||
|
|
||
| export const ZooGateway = ({ | ||
| apiConfiguration, | ||
| setApiConfigurationField, | ||
| routerModels, | ||
| organizationAllowList, | ||
| modelValidationError, | ||
| simplifySettings, | ||
| }: ZooGatewayProps) => { | ||
| const { t } = useAppTranslation() | ||
| const { zooCodeIsAuthenticated, zooCodeUserEmail, zooCodeUserName, zooCodeBaseUrl, uriScheme, deviceName } = | ||
| useExtensionState() | ||
|
|
||
| const authUrl = getZooCodeAuthUrl(uriScheme, zooCodeBaseUrl, deviceName) | ||
| const resolvedDashboardBase = zooCodeBaseUrl?.replace(/\/$/, "") || "https://www.zoocode.dev" | ||
|
|
||
| const zooModels = useMemo(() => routerModels?.["zoo-gateway"] ?? {}, [routerModels]) | ||
| const modelIds = useMemo(() => Object.keys(zooModels), [zooModels]) | ||
| const resolvedDefaultModelId = useMemo(() => pickZooGatewayDefaultModelId(modelIds), [modelIds]) | ||
|
|
||
| useEffect(() => { | ||
| if (modelIds.length === 0) { | ||
| return | ||
| } | ||
|
|
||
| const current = apiConfiguration.zooGatewayModelId | ||
| if (!current || !modelIds.includes(current)) { | ||
| setApiConfigurationField("zooGatewayModelId", resolvedDefaultModelId) | ||
| } | ||
| }, [apiConfiguration.zooGatewayModelId, modelIds, resolvedDefaultModelId, setApiConfigurationField]) | ||
|
|
||
| return ( | ||
| <> | ||
| <div className="flex flex-col gap-1 rounded-md border border-vscode-panel-border p-2"> | ||
| <div className="flex items-center justify-between"> | ||
| <label className="block text-sm font-medium">{t("settings:providers.zooGateway.account")}</label> | ||
| {zooCodeIsAuthenticated && zooCodeUserEmail && ( | ||
| <span className="text-xs text-vscode-descriptionForeground">{zooCodeUserEmail}</span> | ||
| )} | ||
| </div> | ||
| {!zooCodeIsAuthenticated ? ( | ||
| <div className="flex flex-col gap-1"> | ||
| <p className="text-xs text-vscode-descriptionForeground"> | ||
| {t("settings:providers.zooGateway.signInDescription")} | ||
| </p> | ||
| <VSCodeButtonLink href={authUrl} appearance="primary"> | ||
| {t("settings:providers.zooGateway.signInButton")} | ||
| </VSCodeButtonLink> | ||
| </div> | ||
| ) : ( | ||
| <div className="flex items-center gap-1"> | ||
| <span className="codicon codicon-check text-vscode-charts-green" /> | ||
| <span className="text-xs text-vscode-descriptionForeground"> | ||
| {zooCodeUserName | ||
| ? t("settings:providers.zooGateway.authenticatedAs", { name: zooCodeUserName }) | ||
| : t("settings:providers.zooGateway.authenticated")} | ||
| </span> | ||
| </div> | ||
| )} | ||
| </div> | ||
| <ModelPicker | ||
| apiConfiguration={apiConfiguration} | ||
| setApiConfigurationField={setApiConfigurationField} | ||
| defaultModelId={resolvedDefaultModelId} | ||
| models={zooModels} | ||
| modelIdKey="zooGatewayModelId" | ||
| serviceName="Zoo Gateway" | ||
| serviceUrl={`${resolvedDashboardBase}/dashboard/models`} | ||
| organizationAllowList={organizationAllowList} | ||
| errorMessage={modelValidationError} | ||
| simplifySettings={simplifySettings} | ||
| /> | ||
| </> | ||
| ) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
As @edelauna mentioned below, we should be wary of pumping
zooCodeIsAuthenticatedin the useEffect here as well. , I don't think we should be pumpingzooCodeIsAuthenticatedhere in the useEffect through here. if you remove it, then addYou will get a generic error message if something goes wrong.
If you want to add specific error messaging you can add it on the UI side in webview-
ui/src/components/settings/providers/ZooGateway.tsxwithApiErrorMessagecomponent