Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • upgraded stagehand sdk to remove deps incomptaible with bun runtime

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Dec 11, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Dec 11, 2025 7:20am

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 11, 2025

Greptile Overview

Greptile Summary

This PR upgrades the Stagehand SDK from v2.0.0 to v3.0.5 to remove dependencies incompatible with the bun runtime.

Key Changes:

  • Updated Stagehand constructor configuration: Changed from modelName/modelClientOptions to new model object format
  • Changed page access pattern from stagehand.page to stagehand.context.pages()[0]
  • Updated method calls: stagehand.page.act()stagehand.act(), stagehand.page.observe()stagehand.observe()
  • Removed monkey-patching of page.act method (variable substitution now passed directly to stagehand.act())
  • Replaced page.waitForTimeout() with native Promise-based delays
  • Updated agent initialization to use new model format (anthropic/claude-sonnet-4-20250514) with systemPrompt instead of separate instructions and options
  • Added wandConfig with AI-assisted JSON schema generation prompts for improved UX in both Stagehand blocks

Confidence Score: 4/5

  • This PR is safe to merge - it's a straightforward SDK upgrade with API migration that has been manually tested.
  • Score of 4 reflects that this is a well-executed SDK migration with proper API updates. The changes are consistent with Stagehand v3 patterns. Minor deduction because SDK upgrades can have subtle behavioral differences that only surface in edge cases during production usage.
  • The agent route (apps/sim/app/api/tools/stagehand/agent/route.ts) has the most complex changes and should be tested thoroughly with various login scenarios.

Important Files Changed

File Analysis

Filename Score Overview
apps/sim/app/api/tools/stagehand/agent/route.ts 4/5 Migrated from Stagehand SDK v2 to v3 API: Changed stagehand.page.act() to stagehand.act(), stagehand.page to stagehand.context.pages()[0], removed monkey-patching of page.act, updated agent initialization with new model configuration, and replaced page.waitForTimeout() with Promise-based delays.
apps/sim/app/api/tools/stagehand/extract/route.ts 5/5 Updated to Stagehand SDK v3: Changed page access from stagehand.page to stagehand.context.pages()[0], updated Stagehand constructor model configuration format.
apps/sim/blocks/blocks/stagehand.ts 5/5 Added wandConfig with AI-powered JSON schema generation prompts and examples for the schema subBlock to improve UX.
apps/sim/blocks/blocks/stagehand_agent.ts 5/5 Added wandConfig with AI-powered JSON schema generation prompts and examples for the outputSchema subBlock to improve UX.
apps/sim/package.json 5/5 Upgraded @browserbasehq/stagehand from ^2.0.0 to ^3.0.5 to remove dependencies incompatible with bun runtime.
bun.lock 5/5 Updated lockfile to reflect the Stagehand SDK upgrade and its transitive dependencies.

Sequence Diagram

sequenceDiagram
    participant Client
    participant AgentRoute as Agent API Route
    participant Stagehand as Stagehand SDK v3
    participant Browserbase
    participant Page as Browser Page

    Client->>AgentRoute: POST /api/tools/stagehand/agent
    AgentRoute->>Stagehand: new Stagehand({ model: {...} })
    AgentRoute->>Stagehand: stagehand.init()
    Stagehand->>Browserbase: Connect to remote browser
    Browserbase-->>Stagehand: Browser context
    AgentRoute->>Stagehand: stagehand.context.pages()[0]
    Stagehand-->>AgentRoute: Page instance
    AgentRoute->>Page: page.goto(startUrl)
    
    alt Has login variables
        AgentRoute->>Stagehand: stagehand.observe('Find login...')
        Stagehand-->>AgentRoute: Login elements
        AgentRoute->>Stagehand: stagehand.act('Click login')
        AgentRoute->>Page: Direct DOM login attempt
    end
    
    AgentRoute->>Stagehand: stagehand.agent({ model, systemPrompt })
    AgentRoute->>Stagehand: agent.execute({ instruction })
    Stagehand->>Browserbase: Execute agent task
    Browserbase-->>Stagehand: Agent result
    Stagehand-->>AgentRoute: { success, message, actions }
    AgentRoute-->>Client: JSON response
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, 1 comment

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@greptile

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, no comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1 waleedlatif1 merged commit 7fd912d into staging Dec 11, 2025
9 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/stagehand branch December 11, 2025 07:42
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.

2 participants