fix(cli): Functions CLI updates for `init` and `publish`
Merged
AK
2mo ago+332+332+012345678901234567890123456789-27-27-01234567890123456789
why
- Before Browserbase had secrets support,
functions initwould install a playwright template. But now we support secrets so we can update the starter template to showcase Stagehand. - There were some rough edges around the
functions publishcommand related to pnpm 11. Added a few updates so that the functions CLI works out of the box.
what changed
test plan
It works if nothing in this path errors:
- [in stagehand repo]
pnpm build && cd packages/cli alias browse-dev="node $HOME/[your dev path]/stagehand/packages/cli/bin/run.js"to set a local version of thebrowsecli calledbrowse-devcd [your dev path, _not_ in stagehand repo] && browse-dev functions init branch-test && cd branch-testbrowse-dev cloud extensions upload node_modules/@browserbasehq/stagehand/dist/assets/stagehand-extension.zipand then replaceyour-extension-idinindex.tsbrowse-dev cloud secrets create BROWSERBASE_API_KEY --env BROWSERBASE_API_KEYto store your secret API key for use in the deployed functionbrowse-dev functions dev index.ts- (in a new terminal)
curl -X POST http://127.0.0.1:14113/v1/functions/my-function/invoke -H 'Content-Type: application/json' --data '{}'to make sure it works locally npm_config_min_release_age=0 browse-dev functions publish index.tsbrowse-dev functions secrets attach <functionId> <secretId>browse-dev functions invoke <functionId>to make sure you got the same result as (7) above- Success!
Summary by cubic
Swaps the Playwright starter in functions init for a Stagehand one, and fixes functions init and functions publish on pnpm 11 and private npm registries.
- Local dev now sends an empty
secretsobject to invocations, matching production, so the starter'scontext.secrets.BROWSERBASE_API_KEYlookup needs no null check and falls back toprocess.env.BROWSERBASE_API_KEY. functions initinstalls@browserbasehq/stagehandinstead ofplaywright-core, pins zod to Stagehand's version so schemas pass type checks, and writes a Stagehand starter that extracts Hacker News top stories through the Model Gateway.- The starter connects with
browserbase.connectintoStagehand.createand expects you to upload the Stagehand extension and paste its ID intoindex.ts. functions initwritespnpm-workspace.yamlso pnpm 11 allows esbuild's build script, and its next steps usebrowsecommands.functions publishbuildspackage-lock.jsonfrom the uploaded files (so localfile:dependencies resolve), omits registry-resolved URLs for private registries, checks for an existing lockfile, and prints npm output when generation fails.