From 937cebc7de8895f397fec5bf4ca0d30ac52a670e Mon Sep 17 00:00:00 2001 From: Toshii <94262432+0xToshii@users.noreply.github.com> Date: Thu, 26 Jun 2025 15:01:31 -0700 Subject: [PATCH] refactor vertex and doubao provider ui (#4474) * doubao * vertex Co-authored-by: StvLz * ui --------- Co-authored-by: StvLz --- .../src/components/settings/ApiOptions.tsx | 115 +++-------------- .../settings/providers/DoubaoProvider.tsx | 47 +++++++ .../settings/providers/VertexProvider.tsx | 121 ++++++++++++++++++ 3 files changed, 188 insertions(+), 95 deletions(-) create mode 100644 webview-ui/src/components/settings/providers/DoubaoProvider.tsx create mode 100644 webview-ui/src/components/settings/providers/VertexProvider.tsx diff --git a/webview-ui/src/components/settings/ApiOptions.tsx b/webview-ui/src/components/settings/ApiOptions.tsx index 85ef3245..198532e6 100644 --- a/webview-ui/src/components/settings/ApiOptions.tsx +++ b/webview-ui/src/components/settings/ApiOptions.tsx @@ -7,15 +7,12 @@ import { bedrockModels, cerebrasModels, claudeCodeModels, - doubaoModels, geminiModels, internationalQwenModels, liteLlmModelInfoSaneDefaults, mainlandQwenModels, ModelInfo, nebiusModels, - vertexGlobalModels, - vertexModels, xaiModels, sapAiCoreModels, } from "@shared/api" @@ -54,6 +51,8 @@ import { AnthropicProvider } from "./providers/AnthropicProvider" import { AskSageProvider } from "./providers/AskSageProvider" import { OpenAINativeProvider } from "./providers/OpenAINative" import { GeminiProvider } from "./providers/GeminiProvider" +import { DoubaoProvider } from "./providers/DoubaoProvider" +import { VertexProvider } from "./providers/VertexProvider" import GeminiCliProvider from "./providers/GeminiCliProvider" interface ApiOptionsProps { @@ -65,14 +64,6 @@ interface ApiOptionsProps { } const SUPPORTED_THINKING_MODELS: Record = { - vertex: [ - "claude-3-7-sonnet@20250219", - "claude-sonnet-4@20250514", - "claude-opus-4@20250514", - "gemini-2.5-flash-preview-05-20", - "gemini-2.5-flash-preview-04-17", - "gemini-2.5-pro-preview-06-05", - ], qwen: [ "qwen3-235b-a22b", "qwen3-32b", @@ -88,7 +79,7 @@ const SUPPORTED_THINKING_MODELS: Record = { } // This is necessary to ensure dropdown opens downward, important for when this is used in popup -const DROPDOWN_Z_INDEX = OPENROUTER_MODEL_PICKER_Z_INDEX + 2 // Higher than the OpenRouterModelPicker's and ModelSelectorTooltip's z-index +export const DROPDOWN_Z_INDEX = OPENROUTER_MODEL_PICKER_Z_INDEX + 2 // Higher than the OpenRouterModelPicker's and ModelSelectorTooltip's z-index export const DropdownContainer = styled.div<{ zIndex?: number }>` position: relative; @@ -403,35 +394,13 @@ const ApiOptions = ({ )} - {selectedProvider === "doubao" && ( -
- - Doubao API Key - -

- This key is stored locally and only used to make API requests from this extension. - {!apiConfiguration?.doubaoApiKey && ( - - You can get a Doubao API key by signing up here. - - )} -

-
+ {apiConfiguration && selectedProvider === "doubao" && ( + )} {apiConfiguration && selectedProvider === "mistral" && ( @@ -760,57 +729,14 @@ const ApiOptions = ({ )} - {apiConfiguration?.apiProvider === "vertex" && ( -
- - Google Cloud Project ID - - - - - Select a region... - us-east5 - us-central1 - europe-west1 - europe-west4 - asia-southeast1 - global - - -

- To use Google Cloud Vertex AI, you need to - - {"1) create a Google Cloud account › enable the Vertex AI API › enable the desired Claude models,"} - {" "} - - {"2) install the Google Cloud CLI › configure Application Default Credentials."} - -

-
+ {apiConfiguration && selectedProvider === "vertex" && ( + )} {apiConfiguration && selectedProvider === "gemini" && ( @@ -1602,6 +1528,8 @@ const ApiOptions = ({ selectedProvider !== "sambanova" && selectedProvider !== "openai-native" && selectedProvider !== "gemini" && + selectedProvider !== "doubao" && + selectedProvider !== "vertex" && selectedProvider !== "gemini-cli" && showModelOptions && ( <> @@ -1610,13 +1538,10 @@ const ApiOptions = ({ Model {selectedProvider === "claude-code" && createDropdown(claudeCodeModels)} - {selectedProvider === "vertex" && - createDropdown(apiConfiguration?.vertexRegion === "global" ? vertexGlobalModels : vertexModels)} {selectedProvider === "qwen" && createDropdown( apiConfiguration?.qwenApiLine === "china" ? mainlandQwenModels : internationalQwenModels, )} - {selectedProvider === "doubao" && createDropdown(doubaoModels)} {selectedProvider === "xai" && createDropdown(xaiModels)} {selectedProvider === "cerebras" && createDropdown(cerebrasModels)} {selectedProvider === "nebius" && createDropdown(nebiusModels)} diff --git a/webview-ui/src/components/settings/providers/DoubaoProvider.tsx b/webview-ui/src/components/settings/providers/DoubaoProvider.tsx new file mode 100644 index 00000000..76e3d8a8 --- /dev/null +++ b/webview-ui/src/components/settings/providers/DoubaoProvider.tsx @@ -0,0 +1,47 @@ +import { ApiConfiguration, doubaoModels } from "@shared/api" +import { ApiKeyField } from "../common/ApiKeyField" +import { ModelSelector } from "../common/ModelSelector" +import { ModelInfoView } from "../common/ModelInfoView" +import { normalizeApiConfiguration } from "../utils/providerUtils" + +/** + * Props for the DoubaoProvider component + */ +interface DoubaoProviderProps { + apiConfiguration: ApiConfiguration + handleInputChange: (field: keyof ApiConfiguration) => (event: any) => void + showModelOptions: boolean + isPopup?: boolean +} + +/** + * The ByteDance Doubao provider configuration component + */ +export const DoubaoProvider = ({ apiConfiguration, handleInputChange, showModelOptions, isPopup }: DoubaoProviderProps) => { + // Get the normalized configuration + const { selectedModelId, selectedModelInfo } = normalizeApiConfiguration(apiConfiguration) + + return ( +
+ + + {showModelOptions && ( + <> + + + + + )} +
+ ) +} diff --git a/webview-ui/src/components/settings/providers/VertexProvider.tsx b/webview-ui/src/components/settings/providers/VertexProvider.tsx new file mode 100644 index 00000000..8768c840 --- /dev/null +++ b/webview-ui/src/components/settings/providers/VertexProvider.tsx @@ -0,0 +1,121 @@ +import { ApiConfiguration, vertexGlobalModels, vertexModels } from "@shared/api" +import { VSCodeTextField, VSCodeDropdown, VSCodeOption, VSCodeLink } from "@vscode/webview-ui-toolkit/react" +import { ModelSelector } from "../common/ModelSelector" +import { ModelInfoView } from "../common/ModelInfoView" +import { normalizeApiConfiguration } from "../utils/providerUtils" +import { DropdownContainer, DROPDOWN_Z_INDEX } from "../ApiOptions" +import ThinkingBudgetSlider from "../ThinkingBudgetSlider" + +/** + * Props for the VertexProvider component + */ +interface VertexProviderProps { + apiConfiguration: ApiConfiguration + handleInputChange: (field: keyof ApiConfiguration) => (event: any) => void + showModelOptions: boolean + isPopup?: boolean + setApiConfiguration: (config: ApiConfiguration) => void +} + +// Vertex models that support thinking +const SUPPORTED_THINKING_MODELS = [ + "claude-3-7-sonnet@20250219", + "claude-sonnet-4@20250514", + "claude-opus-4@20250514", + "gemini-2.5-flash", + "gemini-2.5-pro", +] + +/** + * The GCP Vertex AI provider configuration component + */ +export const VertexProvider = ({ + apiConfiguration, + handleInputChange, + showModelOptions, + isPopup, + setApiConfiguration, +}: VertexProviderProps) => { + // Get the normalized configuration + const { selectedModelId, selectedModelInfo } = normalizeApiConfiguration(apiConfiguration) + + // Determine which models to use based on region + const modelsToUse = apiConfiguration?.vertexRegion === "global" ? vertexGlobalModels : vertexModels + + return ( +
+ + Google Cloud Project ID + + + + + + Select a region... + us-east5 + us-central1 + europe-west1 + europe-west4 + asia-southeast1 + global + + + +

+ To use Google Cloud Vertex AI, you need to + + {"1) create a Google Cloud account › enable the Vertex AI API › enable the desired Claude models,"} + {" "} + + {"2) install the Google Cloud CLI › configure Application Default Credentials."} + +

+ + {showModelOptions && ( + <> + + + {SUPPORTED_THINKING_MODELS.includes(selectedModelId) && ( + + )} + + + + )} +
+ ) +}