import { useEffect, useState } from "react"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { type ProviderConnectFormProps, VERTEX_AUTH_SERVICE_ACCOUNT, VERTEX_AUTH_WORKLOAD_IDENTITY, VERTEX_DEFAULT_LOCATION, } from "./provider-metadata"; /** * Google Vertex AI (Gemini) connect form. Service-account auth uploads a * credentials JSON file (read into a string); workload identity collects a * project id. Credentials ride along in `extra.litellm_params`. */ export function VertexConnectForm({ onDraftChange }: ProviderConnectFormProps) { const [authMethod, setAuthMethod] = useState(VERTEX_AUTH_SERVICE_ACCOUNT); const [location, setLocation] = useState(VERTEX_DEFAULT_LOCATION); const [credentials, setCredentials] = useState(""); const [project, setProject] = useState(""); const canSubmit = authMethod === VERTEX_AUTH_SERVICE_ACCOUNT ? Boolean(credentials) : Boolean(project); async function handleCredentialsFile(file: File | undefined) { if (!file) return; setCredentials(await file.text()); } useEffect(() => { const params: Record = {}; if (location) params.vertex_location = location; if (authMethod === VERTEX_AUTH_SERVICE_ACCOUNT) { if (credentials) params.vertex_credentials = credentials; } else if (project) { params.vertex_project = project; } onDraftChange({ base_url: null, api_key: null, extra: { litellm_params: params } }, canSubmit); }, [authMethod, canSubmit, credentials, location, onDraftChange, project]); return (
setLocation(event.target.value)} placeholder={VERTEX_DEFAULT_LOCATION} />

Region where your Google Vertex AI models are hosted.

{authMethod === VERTEX_AUTH_SERVICE_ACCOUNT ? (
handleCredentialsFile(event.target.files?.[0])} />

{credentials ? "Credentials file loaded." : "Attach your service account key JSON from Google Cloud."}

) : (
setProject(event.target.value)} placeholder="my-vertex-project" />

The GCP project where Vertex AI is enabled.

)}

Add Vertex AI model IDs from the provider's settings after connecting.

); }