|
| 1 | +import { useCallback } from "react" |
| 2 | +import { VSCodeTextField } from "@vscode/webview-ui-toolkit/react" |
| 3 | + |
| 4 | +import { type ProviderSettings, azureOpenAiDefaultApiVersion } from "@roo-code/types" |
| 5 | + |
| 6 | +import { useAppTranslation } from "@src/i18n/TranslationContext" |
| 7 | +import { VSCodeButtonLink } from "@src/components/common/VSCodeButtonLink" |
| 8 | + |
| 9 | +import { inputEventTransform } from "../transforms" |
| 10 | + |
| 11 | +type AzureProps = { |
| 12 | + apiConfiguration: ProviderSettings |
| 13 | + setApiConfigurationField: (field: keyof ProviderSettings, value: ProviderSettings[keyof ProviderSettings]) => void |
| 14 | + simplifySettings?: boolean |
| 15 | +} |
| 16 | + |
| 17 | +export const Azure = ({ apiConfiguration, setApiConfigurationField }: AzureProps) => { |
| 18 | + const { t } = useAppTranslation() |
| 19 | + |
| 20 | + const handleInputChange = useCallback( |
| 21 | + <K extends keyof ProviderSettings, E>( |
| 22 | + field: K, |
| 23 | + transform: (event: E) => ProviderSettings[K] = inputEventTransform, |
| 24 | + ) => |
| 25 | + (event: E | Event) => { |
| 26 | + setApiConfigurationField(field, transform(event as E)) |
| 27 | + }, |
| 28 | + [setApiConfigurationField], |
| 29 | + ) |
| 30 | + |
| 31 | + return ( |
| 32 | + <> |
| 33 | + <VSCodeTextField |
| 34 | + value={apiConfiguration?.azureResourceName || ""} |
| 35 | + onInput={handleInputChange("azureResourceName")} |
| 36 | + placeholder={t("settings:placeholders.azureResourceName")} |
| 37 | + className="w-full"> |
| 38 | + <label className="block font-medium mb-1">{t("settings:providers.azureResourceName")}</label> |
| 39 | + </VSCodeTextField> |
| 40 | + <div className="text-sm text-vscode-descriptionForeground -mt-2"> |
| 41 | + {t("settings:providers.azureResourceNameDescription")} |
| 42 | + </div> |
| 43 | + <VSCodeTextField |
| 44 | + value={apiConfiguration?.azureDeploymentName || ""} |
| 45 | + onInput={handleInputChange("azureDeploymentName")} |
| 46 | + placeholder={t("settings:placeholders.azureDeploymentName")} |
| 47 | + className="w-full"> |
| 48 | + <label className="block font-medium mb-1">{t("settings:providers.azureDeploymentName")}</label> |
| 49 | + </VSCodeTextField> |
| 50 | + <div className="text-sm text-vscode-descriptionForeground -mt-2"> |
| 51 | + {t("settings:providers.azureDeploymentNameDescription")} |
| 52 | + </div> |
| 53 | + <VSCodeTextField |
| 54 | + value={apiConfiguration?.azureApiKey || ""} |
| 55 | + type="password" |
| 56 | + onInput={handleInputChange("azureApiKey")} |
| 57 | + placeholder={t("settings:placeholders.apiKey")} |
| 58 | + className="w-full"> |
| 59 | + <label className="block font-medium mb-1">{t("settings:providers.azureApiKey")}</label> |
| 60 | + </VSCodeTextField> |
| 61 | + <div className="text-sm text-vscode-descriptionForeground -mt-2"> |
| 62 | + {t("settings:providers.apiKeyStorageNotice")} |
| 63 | + </div> |
| 64 | + <VSCodeTextField |
| 65 | + value={apiConfiguration?.azureApiVersion || ""} |
| 66 | + onInput={handleInputChange("azureApiVersion")} |
| 67 | + placeholder={`Default: ${azureOpenAiDefaultApiVersion}`} |
| 68 | + className="w-full"> |
| 69 | + <label className="block font-medium mb-1">{t("settings:providers.azureApiVersion")}</label> |
| 70 | + </VSCodeTextField> |
| 71 | + <div className="text-sm text-vscode-descriptionForeground -mt-2"> |
| 72 | + {t("settings:providers.azureApiVersionDescription")} |
| 73 | + </div> |
| 74 | + {!apiConfiguration?.azureApiKey && ( |
| 75 | + <VSCodeButtonLink |
| 76 | + href="https://azure.microsoft.com/en-us/products/ai-services/openai-service" |
| 77 | + appearance="secondary"> |
| 78 | + {t("settings:providers.getAzureApiKey")} |
| 79 | + </VSCodeButtonLink> |
| 80 | + )} |
| 81 | + </> |
| 82 | + ) |
| 83 | +} |
0 commit comments