Skip to content

Upgrade AI SDK and its providers#1689

Draft
dylnslck wants to merge 1 commit intobrowserbase:mainfrom
dylnslck:main
Draft

Upgrade AI SDK and its providers#1689
dylnslck wants to merge 1 commit intobrowserbase:mainfrom
dylnslck:main

Conversation

@dylnslck
Copy link

@dylnslck dylnslck commented Feb 16, 2026

why

Updates the ai SDK and all of its providers to the latest versions. This fixes #1645.

what changed

  • Dependencies: Upgraded ai from ^5.0.133 to ^6.0.0, @ai-sdk/provider from ^2.0.0 to ^3.0.0, and all optional AI provider packages (anthropic, openai, google, etc.) to their v3/v4 counterparts.

  • Language model migration: Migrated from LanguageModelV2 to LanguageModelV3 across AISdkClient, LLMClient, and related typings.

  • API changes: Replaced deprecated generateObject / streamObject with generateText / streamText using Output.object({ schema }). Added objectShims.ts to preserve the { object } and partialObjectStream shapes for callers.

  • Tool integration: Updated all agent tools (click, type, scroll, dragAndDrop, fillFormVision, screenshot, ariaTree, wait) to use the new tool result shape: toModelOutput callbacks now receive { output } instead of result.

  • Message types: Switched from CoreSystemMessage, CoreUserMessage, and CoreAssistantMessage to ModelMessage.

  • Flow logger: Added specificationVersion: "v3" to the LLM logging middleware.

  • Usage handling: Updated usage token access for the new structure (outputTokenDetails?.reasoningTokens, inputTokenDetails?.cacheReadTokens, etc.).

backwards compatibility

LLMClient keeps the old generateObject and streamObject API surface. objectShims.ts implements these by wrapping generateText / streamText with Output.object({ schema }) and mapping the results:

  • generateObjectShim returns { object, ...rest } (instead of { output }) so callers that destructure { object } still work
  • streamObjectShim exposes partialObjectStream as an alias for partialOutputStream

No changes required for code that uses llmClient.generateObject() or llmClient.streamObject().

test plan

  • pnpm install and pnpm build succeed
  • pnpm test passes (unit/vitest tests)
  • pnpm e2e:local or pnpm e2e passes to verify agent flows with the upgraded SDK
  • Verified that AISdkClient accepts LanguageModelV3 models from current provider packages (e.g. @ai-sdk/openai ^3.x) without TypeScript errors

Summary by cubic

Upgrade the AI SDK to v6 and all providers to their latest major versions, migrating to LanguageModelV3 and the new structured output API while keeping our public LLMClient API intact. This improves provider compatibility and fixes #1645.

  • Dependencies

    • Bump ai to ^6.0.0 and @ai-sdk/provider to ^3.0.0; upgrade provider packages (openai, anthropic, google, vertex, groq, etc.).
    • Switch to generateImage (stable) and align evals/core wrappers.
  • Migration

    • Move to LanguageModelV3 and ModelMessage across clients.
    • Replace generateObject/streamObject with generateText/streamText + Output.object; add objectShims to keep generateObject, streamObject, { object }, and partialObjectStream working.
    • Update agent tools to toModelOutput({ output }) (click, type, scroll, dragAndDrop, fillFormVision, screenshot, ariaTree, wait).
    • Adjust usage to new fields (outputTokenDetails.reasoningTokens, inputTokenDetails.cacheReadTokens).
    • Set flow logger specificationVersion to "v3" and log token totals accordingly.

Written for commit ff7bbd8. Summary will update on new commits. Review in cubic

@changeset-bot
Copy link

changeset-bot bot commented Feb 16, 2026

⚠️ No Changeset found

Latest commit: ff7bbd8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@dylnslck
Copy link
Author

dylnslck commented Feb 16, 2026

Couldn't run the e2e tests. Got this issue running pnpm e2e:local:

@browserbasehq/stagehand:e2e:local: Error: require() of ES Module /Users/dylan/src/dylnslck/stagehand/node_modules/.pnpm/chrome-launcher@1.2.0/node_modules/chrome-launcher/dist/index.js from /Users/dylan/src/dylnslck/stagehand/packages/core/lib/v3/launch/local.ts not supported.
@browserbasehq/stagehand:e2e:local: Instead change the require of index.js in /Users/dylan/src/dylnslck/stagehand/packages/core/lib/v3/launch/local.ts to a dynamic import() which is available in all CommonJS modules.
@browserbasehq/stagehand:e2e:local: 
@browserbasehq/stagehand:e2e:local:    at ../launch/local.ts:7
@browserbasehq/stagehand:e2e:local: 
@browserbasehq/stagehand:e2e:local:    5 |   chromePath?: string;
@browserbasehq/stagehand:e2e:local:    6 |   chromeFlags?: string[];
@browserbasehq/stagehand:e2e:local: >  7 |   headless?: boolean;
@browserbasehq/stagehand:e2e:local:      |                       ^
@browserbasehq/stagehand:e2e:local:    8 |   userDataDir?: string;
@browserbasehq/stagehand:e2e:local:    9 |   port?: number;
@browserbasehq/stagehand:e2e:local:   10 |   connectTimeoutMs?: number;
@browserbasehq/stagehand:e2e:local:     at Object.<anonymous> (/Users/dylan/src/dylnslck/stagehand/packages/core/lib/v3/launch/local.ts:7:23)
@browserbasehq/stagehand:e2e:local:     at Object.<anonymous> (/Users/dylan/src/dylnslck/stagehand/packages/core/lib/v3/v3.ts:26:14)
@browserbasehq/stagehand:e2e:local:     at Object.<anonymous> (/Users/dylan/src/dylnslck/stagehand/packages/core/lib/v3/tests/cdp-session-detached.spec.ts:5:11)

If this PR looks alright, I'd appreciate if it a maintainer could run the e2e tests. I'm also happy to put a changeset if this PR is in the right direction.

Cheers

shrey150 added a commit that referenced this pull request Feb 18, 2026
Based on #1689 by @dylnslck. Adds optional chaining and deprecated
property fallbacks to token detail access across both generateObject
and generateText code paths, matching the safe pattern already used
in the generateObject path of aisdk.ts. Renames `u` to `usage` for
consistency with the rest of the codebase.

Co-Authored-By: Dylan Slack <dylnslck@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
shrey150 added a commit that referenced this pull request Feb 18, 2026
Based on #1689 by @dylnslck. Adds optional chaining and deprecated
property fallbacks to token detail access across both generateObject
and generateText code paths, matching the safe pattern already used
in the generateObject path of aisdk.ts. Renames `u` to `usage` for
consistency with the rest of the codebase.

Co-Authored-By: Dylan Slack <dylnslck@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
shrey150 added a commit that referenced this pull request Feb 20, 2026
Based on #1689 by @dylnslck. Adds optional chaining and deprecated
property fallbacks to token detail access across both generateObject
and generateText code paths, matching the safe pattern already used
in the generateObject path of aisdk.ts. Renames `u` to `usage` for
consistency with the rest of the codebase.

Co-Authored-By: Dylan Slack <dylnslck@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Support latest Vercel AI SDK (LanguageModelV3) in AISdkClient / Stagehand

1 participant