Skip to content

Conversation

@tkattkat
Copy link
Collaborator

@tkattkat tkattkat commented Dec 1, 2025

Why

Adding Vertex AI support to Stagehand.

What changed

  • Added GoogleVertexProviderSettings from @ai-sdk/google-vertex to ClientOptions type
  • Kept consistent with how we import types from @anthropic-ai/sdk and openai packages
  • Fixed typing in model utils

Test plan

  • tested locally
  • tested existing model format on api

Summary by cubic

Adds Vertex AI as a supported provider with typed client options, including service account credentials, and an env var for the API key.

Why:

  • Enable Vertex models as a first-class provider.
  • Keep client options typing consistent across providers.

What:

  • Added Vertex provider to AISDK maps and model creation flow.
  • Extended ClientOptions to include GoogleVertexProviderSettings and googleAuthOptions.credentials.
  • Updated getAISDKLanguageModel to take ClientOptions directly.
  • Mapped env var: GOOGLE_VERTEX_AI_API_KEY.
  • Normalized clientOptions typing across agent clients and model utils.
  • Added @ai-sdk/google-vertex dependency and changeset entry.

Test Plan:

  • Set GOOGLE_VERTEX_AI_API_KEY in your environment.
  • Configure a model with provider: "vertex" and a valid Vertex model name; pass any needed clientOptions.
  • Optionally pass service account JSON via clientOptions.googleAuthOptions.credentials and verify auth works.
  • Call the API and confirm responses; smoke test other providers to ensure no regressions.

Written for commit 415d8f4. Summary will update automatically on new commits.

@changeset-bot
Copy link

changeset-bot bot commented Dec 1, 2025

🦋 Changeset detected

Latest commit: 415d8f4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@browserbasehq/stagehand Patch
@browserbasehq/stagehand-evals Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 1, 2025

Greptile Overview

Greptile Summary

Adds Google Vertex AI as a supported model provider alongside existing OpenAI, Anthropic, and other providers. This enables users to leverage Vertex AI models through the AI SDK.

Key Changes:

  • Added GoogleVertexProviderSettings to ClientOptions type union for proper Vertex-specific configuration
  • Registered vertex provider in AISDK provider maps (AISDKProviders and AISDKProvidersWithAPIKey)
  • Added GOOGLE_VERTEX_AI_API_KEY environment variable mapping in providerEnvVarMap
  • Improved type safety across the codebase by replacing generic Record<string, unknown> with strongly-typed ClientOptions for all agent clients and model utilities
  • Refactored getAISDKLanguageModel to accept ClientOptions object instead of separate apiKey and baseURL parameters for cleaner API
  • Fixed Anthropic client to use correct baseURL property name (was incorrectly baseUrl)
  • Removed obsolete @ts-expect-error directives that are no longer needed due to improved typing
  • Added @ai-sdk/google-vertex dependency (version ^3.0.70) as optional dependency
  • Corrected zod peer dependency semver syntax from 3.25.76 || 4.1.8 to ^3.25.76 || ^4.1.8

Impact:
Users can now specify Vertex models using the format vertex/model-name with appropriate client options, following the same pattern as other AISDK providers. The typing improvements provide better autocomplete and compile-time validation for all model provider configurations.

Confidence Score: 5/5

  • This PR is safe to merge with no blocking issues - it follows established patterns and improves type safety
  • The changes are well-structured and follow the existing pattern for adding new providers. The typing improvements enhance code safety across the entire codebase. The semver syntax fix and removal of @ts-expect-error comments indicate better code health. The Anthropic baseURL fix corrects a typo. All changes are additive (no breaking changes) and have been tested locally per the PR description.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
packages/core/lib/v3/types/public/model.ts 5/5 Added GoogleVertexProviderSettings type import and expanded ClientOptions union type to include Vertex provider settings
packages/core/lib/v3/llm/LLMProvider.ts 5/5 Added vertex provider to AISDK provider maps and updated getAISDKLanguageModel to accept ClientOptions instead of separate params
packages/core/lib/modelUtils.ts 5/5 Updated clientOptions return type from generic Record<string, unknown> to strongly-typed ClientOptions
packages/core/lib/utils.ts 5/5 Added GOOGLE_VERTEX_AI_API_KEY environment variable mapping for vertex provider
packages/core/package.json 5/5 Added @ai-sdk/google-vertex dependency and fixed zod semver syntax

Sequence Diagram

sequenceDiagram
    participant User
    participant Stagehand
    participant LLMProvider
    participant getAISDKLanguageModel
    participant createVertex
    participant VertexModel
    
    User->>Stagehand: Initialize with model config
    Note over User,Stagehand: model: "vertex/gemini-1.5-pro"<br/>clientOptions: { apiKey: "..." }
    
    Stagehand->>LLMProvider: getClient(modelName, clientOptions)
    Note over LLMProvider: Detects "/" in model name<br/>Splits into provider & model
    
    LLMProvider->>getAISDKLanguageModel: ("vertex", "gemini-1.5-pro", clientOptions)
    Note over getAISDKLanguageModel: Check if clientOptions provided
    
    getAISDKLanguageModel->>createVertex: createVertex(clientOptions)
    Note over createVertex: Creates Vertex provider with<br/>GoogleVertexProviderSettings
    
    createVertex-->>getAISDKLanguageModel: vertexProvider
    getAISDKLanguageModel->>VertexModel: vertexProvider("gemini-1.5-pro")
    VertexModel-->>getAISDKLanguageModel: languageModel instance
    getAISDKLanguageModel-->>LLMProvider: languageModel
    
    LLMProvider->>LLMProvider: new AISdkClient(languageModel)
    LLMProvider-->>Stagehand: LLMClient instance
    Stagehand-->>User: Ready to use Vertex models
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 6 files

Prompt for AI agents (all 1 issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="packages/core/package.json">

<violation number="1" location="packages/core/package.json:43">
P0: Invalid semver syntax: the caret (`^`) must be placed BEFORE the version number, not after. `3.25.76^` should be `^3.25.76`. This will cause package installation to fail or behave unexpectedly.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

@tkattkat tkattkat marked this pull request as draft December 1, 2025 19:16
@tkattkat tkattkat marked this pull request as ready for review December 1, 2025 19:27
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

13 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 14 files

@miguelg719 miguelg719 mentioned this pull request Dec 2, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants