Skip to content

feat(sdk-ts): env overrides for extension asset paths - #2676

Merged
seanmcguire12 merged 2 commits into
mainfrom
miguel/extension-asset-env
Aug 10, 2026
Merged

feat(sdk-ts): env overrides for extension asset paths#2676
seanmcguire12 merged 2 commits into
mainfrom
miguel/extension-asset-env

Conversation

@miguelg719

@miguelg719 miguelg719 commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Small targeted change: STAGEHAND_EXTENSION_ARCHIVE_PATH / STAGEHAND_EXTENSION_DIRECTORY_PATH env overrides for the two derived asset constants.

Why: bundlers that inline the SDK re-anchor import.meta.url, breaking the derived paths. Hit twice in the Eve integration: eve build (nitro bundle missing the zip → 'Failed to upload the Stagehand extension') and now eve dev (authored-module bundle → CDP Extensions.loadUnpacked fails with 'File path cannot be resolved' for local browsers). The env override is the standard escape hatch; the Eve example sets them from a tiny wrapper that resolves the real installed paths outside any bundle.

Gate: build, typecheck, 186/186 unit tests.


Summary by cubic

Adds env overrides for extension asset paths in @browserbasehq/stagehand so bundled builds can point to real assets. Trims whitespace so empty override values are ignored.

  • New Features
    • Support STAGEHAND_EXTENSION_ARCHIVE_PATH and STAGEHAND_EXTENSION_DIRECTORY_PATH via process.env, falling back to import.meta.url-derived paths when unset or blank.

Written for commit c614548. Summary will update on new commits.

Review in cubic

@changeset-bot

changeset-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: c614548

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 changesets to release 5 packages
Name Type
@browserbasehq/stagehand Patch
@browserbasehq/stagehand-integrations Patch
@browserbasehq/stagehand-integrations-example-eve-facade Patch
@browserbasehq/stagehand-integrations-example-mastra-facade Patch
@browserbasehq/stagehand-integrations-example-vercel-ai-facade Patch

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 2 files

Architecture diagram
sequenceDiagram
    participant Caller as Host Code
    participant Assets as extensionAssets.ts
    participant Env as process.env
    participant FS as File System

    Note over Caller,FS: NEW: Resolve extension asset paths with env overrides

    Caller->>Assets: get extension asset path (archive or directory)
    Assets->>Env: Check corresponding STAGEHAND_EXTENSION_*_PATH
    alt Env var set (e.g., bundler inlined, import.meta.url broken)
        Env-->>Assets: real path
        Assets-->>Caller: return env override path
    else Env var not set
        Env-->>Assets: undefined
        Assets->>Assets: derive from import.meta.url (packageRoot)
        Assets-->>Caller: return derived path (default)
    end

    Note over Caller,FS: Same logic for both ARCHIVE and DIRECTORY constants
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/sdk-ts/src/extensionAssets.ts Outdated
@miguelg719
miguelg719 changed the base branch from v4-spike to main August 10, 2026 07:10
@miguelg719
miguelg719 requested a review from a team as a code owner August 10, 2026 07:10
@miguelg719
miguelg719 force-pushed the miguel/extension-asset-env branch from d2be814 to cc7b8ba Compare August 10, 2026 07:11
Comment thread .changeset/extension-asset-env.md Outdated

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 1 file (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread .changeset/extension-asset-env.md

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Confidence score: 4/5

  • In packages/sdk-ts/src/extensionAssets.ts, the new environment-override logic (including the nonEmpty empty/whitespace-as-unset edge case) is untested, so a subtle regression in override precedence or value parsing could slip through and cause incorrect extension asset resolution at runtime — add focused unit tests for unset, empty, whitespace-only, and valid env values plus precedence behavior.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/sdk-ts/src/extensionAssets.ts">

<violation number="1" location="packages/sdk-ts/src/extensionAssets.ts:9">
P2: The new env-override behavior (including the `nonEmpty` edge-case handling that treats empty/whitespace-only values as unset, which was a dedicated fix commit) has no unit-test coverage. The existing 186 tests pass but none import `extensionAssets` or set these env vars, so the override path, the trim fallback, and the module-load-time env read can regress silently. Consider adding focused tests covering: env set → uses override, env unset → derived path, env empty/whitespace-only → derived path, and env with surrounding whitespace → trimmed value.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread packages/sdk-ts/src/extensionAssets.ts
@mintlify

mintlify Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
stagehand 🟢 Ready View Preview Aug 10, 2026, 8:45 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

shrey150 added a commit that referenced this pull request Aug 10, 2026
Eve example for the Stagehand facade tool surface, using Eve-native
authored tools (`defineTool`) instead of an MCP connection.

- **Tools:** `run` / `snapshot` / `screenshot` — the shared facade
contract; descriptions, schemas, and system prompt imported from
`@browserbasehq/stagehand-integrations/facade`, never restated.
- **Transport:** none — tools run in-process in the Eve world. Browser
session is a module-level singleton with keep-alive +
reconnect-by-session-id (`browser.sessionId`).
- **Run:** `packages/integrations/eve/README.md`. `pnpm dev` / `pnpm
start` route through a wrapper that forwards the SDK extension asset
paths (needs #2676's env overrides, merged into this branch).

Verified: contract test in CI; Browserbase smoke passed (agent cited
snapshot ID `[0-19]`, heading "Example Domain"); local `eve dev` browser
flow verified end-to-end.

Stacked on #2665.

---------

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
Co-authored-by: Shrey Pandya <shrey@browserbase.com>
@seanmcguire12
seanmcguire12 force-pushed the miguel/extension-asset-env branch from f10d2ad to 5c092e4 Compare August 10, 2026 16:45
@seanmcguire12
seanmcguire12 merged commit a466766 into main Aug 10, 2026
19 checks passed
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