Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,37 @@ defineFn(

The `bb` CLI is included with the package.

## Programmatic core

CLI hosts can reuse the same scaffold, local-development, publishing, and
invocation implementation without invoking the `bb` executable:

```ts
import {
invokeFunction,
publishFunction,
} from "@browserbasehq/sdk-functions/core";

const published = await publishFunction({
apiKey: process.env.BROWSERBASE_API_KEY,
entrypoint: "index.ts",
});

if (!published.dryRun) {
const functionId = published.build.builtFunctions?.[0]?.id;
if (functionId) {
const invocation = await invokeFunction({ functionId });
console.log(invocation.results);
}
}
```

The core API returns typed values and throws `FunctionsCoreError`; it does not
parse CLI arguments, format terminal output, install signal handlers, call
`process.exit()`, or emit telemetry. Those concerns remain with the importing
CLI. `startDevServer()` returns a handle with an idempotent `close()` method so
the host owns its process lifecycle.

| Command | Description |
| ------------------------- | -------------------------------------------------------------- |
| `bb init [project-name]` | Scaffold a new project (defaults to `my-browserbase-function`) |
Expand Down
17 changes: 12 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"types": "./dist/types/index.d.ts",
"require": "./dist/index.cjs",
"import": "./dist/index.js"
},
"./core": {
"types": "./dist/types/core/index.d.ts",
"require": "./dist/core.cjs",
"import": "./dist/core.js"
}
},
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"types": "./dist/types/index.d.ts",
"bin": {
"bb": "dist/cli.js"
},
Expand All @@ -23,21 +28,22 @@
"./dist/index.js"
],
"scripts": {
"build": "rm -rf dist && tsup",
"build": "rm -rf dist && tsup && tsc --project tsconfig.build.json",
"build:tests": "tsc --project tsconfig.test.json",
"eslint": "eslint ./src",
"eslint:fix": "eslint --fix ./src",
"lint": "$npm_execpath run eslint && $npm_execpath run prettier && $npm_execpath run typecheck",
"prettier": "prettier . --check --cache",
"prettier:fix": "prettier . --write --cache",
"prepare": "pnpm build",
"test": "$npm_execpath build:tests && node --test dist-test/**/*.test.js",
"test:only": "$npm_execpath build:tests && node --test-only --test dist-test/**/*.test.js",
"build:integration": "tsc --project tsconfig.integration.json",
"pretest:integration": "$npm_execpath run build && pnpm pack",
"test:integration": "$npm_execpath run build:integration && node --test --test-timeout 120000 dist-integration-test/tests/integration/**/*.test.js",
"test:integration": "$npm_execpath run build:integration && node --test --test-timeout 120000 dist-integration-test/tests/integration/build-flow.test.js dist-integration-test/tests/integration/manifest-generation.test.js dist-integration-test/tests/integration/cli/*.test.js",
"posttest:integration": "rm -f browserbasehq-sdk-functions-*.tgz",
"pretest:e2e": "$npm_execpath run build && pnpm pack",
"test:e2e": "$npm_execpath run build:integration && node --test --test-timeout 300000 dist-integration-test/tests/e2e/**/*.test.js",
"test:e2e": "$npm_execpath run build:integration && node --test --test-timeout 300000 dist-integration-test/tests/e2e/e2e.test.js",
"posttest:e2e": "rm -f browserbasehq-sdk-functions-*.tgz",
"typecheck": "tsc --noEmit"
},
Expand Down Expand Up @@ -65,6 +71,7 @@
"chalk": "^5.6.2",
"commander": "^14.0.2",
"dotenv": "^17.2.3",
"ignore": "^7.0.5",
"tsx": "^4.20.5",
"zod": "^4.1.5"
}
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading