-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(pi): publish the native Stagehand extension as a Pi package #2970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@browserbasehq/pi": minor | ||
| --- | ||
|
|
||
| Publish the native Pi extension as an installable Pi package, bundling the private facade implementation. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,49 +1,26 @@ | ||
| # pi + Stagehand facade (native tools) | ||
| # Stagehand for Pi | ||
|
|
||
| [pi](https://pi.dev) has no built-in MCP by design — extensions register tools directly. This | ||
| package is a pi extension exposing the Stagehand facade tools (`run`, `snapshot`, | ||
| `screenshot`) natively, with descriptions, validation, and agent guidance imported from | ||
| `@browserbasehq/stagehand-integrations/facade`. | ||
| Install the native extension with Pi’s package manager: | ||
|
|
||
| ## Setup | ||
|
|
||
| Use Node.js 24 or later. From the repository root, build the integrations package first: | ||
|
|
||
| ```bash | ||
| pnpm install | ||
| pnpm exec turbo run build --filter @browserbasehq/stagehand-integrations | ||
| ```sh | ||
| pi install npm:@browserbasehq/pi | ||
| pi | ||
| ``` | ||
|
|
||
| Export the browser credentials (Browserbase is the default and recommended backend) and a model | ||
| key pi supports: | ||
| Requires Node.js 24+, an authenticated Pi model provider, and local Chrome (or `BROWSERBASE_API_KEY` for Browserbase). The initial npm release is pending; before publishing, use the development build below. No private workspace dependency is needed by the installed package. | ||
|
|
||
| ```bash | ||
| export BROWSERBASE_API_KEY=bb_live_... | ||
| export OPENAI_API_KEY=sk-... # or ANTHROPIC_API_KEY | ||
| ``` | ||
| The extension registers `run`, `snapshot`, and `screenshot` directly through Pi’s extension API. It launches a browser on the first call, reuses it throughout the session, and closes it on shutdown. | ||
|
|
||
| ## Run | ||
| ## Develop from source | ||
|
|
||
| One-off, pointing pi at the extension file (no install needed; pi loads TypeScript directly and | ||
| resolves `@browserbasehq/stagehand-integrations` through the workspace): | ||
| From the Stagehand repository root: | ||
|
|
||
| ```bash | ||
| cd packages/integrations/pi | ||
| pi -e ./extensions/stagehand.ts --no-session -p "Use your browser tools: open https://example.com, snapshot it, and report the heading citing the snapshot ID." </dev/null | ||
| ```sh | ||
| pnpm install --frozen-lockfile | ||
| pnpm exec turbo run build --filter @browserbasehq/pi | ||
| pi install ./packages/integrations/pi | ||
| ``` | ||
|
|
||
| Two headless gotchas: print mode reads piped stdin (always redirect `</dev/null`), and | ||
| non-interactive runs never show the project-trust prompt — use `-e` as above, or `-a` after | ||
| trusting the project. | ||
|
|
||
| To install permanently instead: `pi install ./packages/integrations/pi` (the `pi` manifest key | ||
| in `package.json` points at the extension). | ||
|
|
||
| ## Security model | ||
| The package uses the official `pi.extensions` manifest and `pi-package` catalog keyword. The build bundles the private Core facade and leaves Stagehand (including its browser extension assets) as a runtime dependency. | ||
|
|
||
| The `run` tool executes model-authored JavaScript inside the Stagehand browser extension's | ||
| service worker — browser-side, never in the pi process. Browserbase is the recommended | ||
| isolation boundary: the privileged execution environment is a disposable cloud browser. The | ||
| browser launches lazily on first tool use and closes on session shutdown; only | ||
| `STAGEHAND_*`/`BROWSERBASE_*` variables configure it, and pi's model credentials never reach | ||
| the browser session. | ||
| [Setup and configuration](https://docs.stagehand.dev/v4/integrations/pi) · [Pi package format](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/docs/packages.md) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { defineConfig } from "tsdown"; | ||
|
|
||
| export default defineConfig({ | ||
| entry: { stagehand: "extensions/stagehand.ts" }, | ||
| format: ["esm"], | ||
| platform: "node", | ||
| target: "node24", | ||
| // Core is private. Bundle its implementation, while preserving the SDK's assets. | ||
| deps: { alwaysBundle: [/@browserbasehq\/stagehand-integrations/] }, | ||
| sourcemap: true, | ||
| outDir: "dist", | ||
| }); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,10 @@ import { pathToFileURL } from "node:url"; | |
| const repositoryRoot = path.resolve(import.meta.dirname, "../.."); | ||
| const rootChangelogPath = path.join(repositoryRoot, "CHANGELOG.md"); | ||
| const packageChangelogs = [ | ||
| { | ||
| label: "Pi extension", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The new Pi changelog entry has no regression coverage. Add a release-helper test that exercises a Pi package changelog through this package list and verifies the Prompt for AI agents |
||
| path: path.join(repositoryRoot, "packages/integrations/pi/CHANGELOG.md"), | ||
| }, | ||
| { | ||
| label: "TypeScript SDK", | ||
| path: path.join(repositoryRoot, "packages/sdk-ts/CHANGELOG.md"), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.