|
| 1 | +import { |
| 2 | + type ProviderSettings, |
| 3 | + type OrganizationAllowList, |
| 4 | + type RouterModels, |
| 5 | + zooGatewayDefaultModelId, |
| 6 | +} from "@roo-code/types" |
| 7 | + |
| 8 | +import { useExtensionState } from "@src/context/ExtensionStateContext" |
| 9 | +import { getZooCodeAuthUrl } from "@src/oauth/urls" |
| 10 | +import { useAppTranslation } from "@src/i18n/TranslationContext" |
| 11 | + |
| 12 | +import { ModelPicker } from "../ModelPicker" |
| 13 | + |
| 14 | +type ZooGatewayProps = { |
| 15 | + apiConfiguration: ProviderSettings |
| 16 | + setApiConfigurationField: (field: keyof ProviderSettings, value: ProviderSettings[keyof ProviderSettings]) => void |
| 17 | + routerModels?: RouterModels |
| 18 | + organizationAllowList: OrganizationAllowList |
| 19 | + modelValidationError?: string |
| 20 | + simplifySettings?: boolean |
| 21 | +} |
| 22 | + |
| 23 | +export const ZooGateway = ({ |
| 24 | + apiConfiguration, |
| 25 | + setApiConfigurationField, |
| 26 | + routerModels, |
| 27 | + organizationAllowList, |
| 28 | + modelValidationError, |
| 29 | + simplifySettings, |
| 30 | +}: ZooGatewayProps) => { |
| 31 | + const { t } = useAppTranslation() |
| 32 | + const { zooCodeIsAuthenticated, zooCodeUserEmail, zooCodeUserName, zooCodeBaseUrl, uriScheme, deviceName } = |
| 33 | + useExtensionState() |
| 34 | + |
| 35 | + const authUrl = getZooCodeAuthUrl(uriScheme, zooCodeBaseUrl, deviceName) |
| 36 | + |
| 37 | + return ( |
| 38 | + <> |
| 39 | + {/* Zoo Code Authentication Section */} |
| 40 | + <div className="flex flex-col gap-1 rounded-md border border-vscode-panel-border p-2"> |
| 41 | + <div className="flex items-center justify-between"> |
| 42 | + <label className="block text-sm font-medium">{t("settings:providers.zooGateway.account")}</label> |
| 43 | + {zooCodeIsAuthenticated && zooCodeUserEmail && ( |
| 44 | + <span className="text-xs text-vscode-descriptionForeground">{zooCodeUserEmail}</span> |
| 45 | + )} |
| 46 | + </div> |
| 47 | + {!zooCodeIsAuthenticated ? ( |
| 48 | + <div className="flex flex-col gap-1"> |
| 49 | + <p className="text-xs text-vscode-descriptionForeground"> |
| 50 | + {t("settings:providers.zooGateway.signInDescription")} |
| 51 | + </p> |
| 52 | + <a |
| 53 | + href={authUrl} |
| 54 | + className="inline-flex w-fit items-center rounded-sm bg-vscode-button-background px-3 py-1 text-xs text-vscode-button-foreground no-underline hover:bg-vscode-button-hoverBackground"> |
| 55 | + {t("settings:providers.zooGateway.signInButton")} |
| 56 | + </a> |
| 57 | + </div> |
| 58 | + ) : ( |
| 59 | + <div className="flex items-center gap-1"> |
| 60 | + <span className="codicon codicon-check text-vscode-charts-green" /> |
| 61 | + <span className="text-xs text-vscode-descriptionForeground"> |
| 62 | + {zooCodeUserName |
| 63 | + ? t("settings:providers.zooGateway.authenticatedAs", { name: zooCodeUserName }) |
| 64 | + : t("settings:providers.zooGateway.authenticated")} |
| 65 | + </span> |
| 66 | + </div> |
| 67 | + )} |
| 68 | + </div> |
| 69 | + <ModelPicker |
| 70 | + apiConfiguration={apiConfiguration} |
| 71 | + setApiConfigurationField={setApiConfigurationField} |
| 72 | + defaultModelId={zooGatewayDefaultModelId} |
| 73 | + models={routerModels?.["zoo-gateway"] ?? {}} |
| 74 | + modelIdKey="zooGatewayModelId" |
| 75 | + serviceName="Zoo Gateway" |
| 76 | + serviceUrl="https://www.zoocode.dev/dashboard/models" |
| 77 | + organizationAllowList={organizationAllowList} |
| 78 | + errorMessage={modelValidationError} |
| 79 | + simplifySettings={simplifySettings} |
| 80 | + /> |
| 81 | + </> |
| 82 | + ) |
| 83 | +} |
0 commit comments