@velanir/openclaw-browserbase 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,134 @@
1
+ # @velanir/openclaw-browserbase
2
+
3
+ OpenClaw gateway plugin that puts a session broker between the bundled
4
+ `browser` tool and [Browserbase](https://www.browserbase.com). The agent keeps
5
+ using the normal `browser` tool; this plugin owns the Browserbase session
6
+ lifecycle that a static `wss://connect.browserbase.com?apiKey=…` profile cannot
7
+ provide: explicit session creation with the right options, a persistent
8
+ per-coworker browser context (durable logins), deterministic release, idle
9
+ disconnect, and stale-session reaping.
10
+
11
+ Canonical design: `docs/plans/openclaw-browserbase-session-broker-design.md`
12
+ in the platform repo (architecture, mint policy, edge-case matrix, decisions).
13
+
14
+ ## How it works
15
+
16
+ ```
17
+ browser tool ──cdpUrl http://127.0.0.1:<port>/?token=…──> broker (this plugin)
18
+ │ mint on WS connect
19
+
20
+ Browserbase POST /v1/sessions + CDP pipe
21
+ ```
22
+
23
+ - `GET /json/version` never creates a session — discovery and `browser status`
24
+ probes are free. A Browserbase session is minted only when OpenClaw opens
25
+ the advertised WebSocket (first real browser action), then CDP frames are
26
+ piped byte-for-byte.
27
+ - Every session is created with the coworker's persistent context
28
+ (`persist: true`), the configured timeout/viewport/captcha/recording policy,
29
+ and `userMetadata` tagging for observability and reaping.
30
+ - Disconnect (task end, idle, gateway restart) releases the session. Login
31
+ state survives in the context; the next browser action gets a fresh session
32
+ that is already logged in.
33
+ - One session per coworker context at a time (Browserbase forbids concurrent
34
+ sessions on one context), with a short cooldown after release.
35
+
36
+ ## OpenClaw config
37
+
38
+ ```json5
39
+ {
40
+ browser: {
41
+ enabled: true,
42
+ defaultProfile: "browserbase",
43
+ remoteCdpTimeoutMs: 5000,
44
+ remoteCdpHandshakeTimeoutMs: 20000,
45
+ profiles: {
46
+ browserbase: {
47
+ cdpUrl: "http://127.0.0.1:18920/?token=${OCT8_BB_BROKER_TOKEN}",
48
+ attachOnly: true,
49
+ color: "#F97316"
50
+ },
51
+ main: { cdpPort: 18910, color: "#EF4444" }
52
+ }
53
+ },
54
+ plugins: {
55
+ allow: ["browser", "velanir-browserbase"],
56
+ entries: {
57
+ "velanir-browserbase": {
58
+ enabled: true,
59
+ config: {
60
+ projectId: "<browserbase project id>",
61
+ apiKey: "${OCT8_BROWSERBASE_API_KEY}",
62
+ listenPort: 18920,
63
+ token: "${OCT8_BB_BROKER_TOKEN}"
64
+ }
65
+ }
66
+ }
67
+ }
68
+ }
69
+ ```
70
+
71
+ Notes:
72
+
73
+ - `attachOnly: true` is mandatory: a loopback `cdpUrl` without it is treated
74
+ as an OpenClaw-managed local browser.
75
+ - `apiKey` and `token` must use `${ENV}` substitution so no secret lives in
76
+ `openclaw.json` on disk. Both env vars belong in the gateway service
77
+ environment (EC2: `/etc/oct8/<profile>.env`, mode 0600).
78
+ - The broker `token` must be **URL-safe** (`[A-Za-z0-9._~-]`) because it rides
79
+ in the cdpUrl query string on both the profile and the broker-advertised
80
+ WebSocket URL. Generate it with base64url or hex; reserved characters like
81
+ `+ & # = /` change meaning across the URL parse boundaries and break auth.
82
+ The broker refuses to start with a non-URL-safe token.
83
+ - The broker binds `127.0.0.1` only and requires the token on every request
84
+ and WebSocket upgrade.
85
+ - Keep a local Chrome profile (`main` above) as fallback; OpenClaw never
86
+ auto-falls back — switching profiles is a model decision.
87
+
88
+ ## Config reference
89
+
90
+ See `openclaw.plugin.json` for the full schema. Defaults implement the locked
91
+ v1 policy: timeout 3600 s, viewport 1280×900, captcha solving on, recording on,
92
+ `ignoreCertificateErrors: false`, per-coworker context with `persist: true`,
93
+ cooldown 10 s, idle disconnect 15 min, reaper every 5 min, no proxies
94
+ (`proxies: []` passes through to session creation when set).
95
+
96
+ ## Agent tools
97
+
98
+ - `browserbase_session_status` — session id, expiry, idle time, context id.
99
+ - `browserbase_live_view` — interactive Live View URL for human 2FA/SSO
100
+ handoff. The URL controls the browser; share it only with the human who
101
+ must act.
102
+ - `browserbase_session_release` — release the session when browser work is
103
+ done; logins persist in the context.
104
+
105
+ ## Operations
106
+
107
+ - Sessions carry `userMetadata`: `broker: "velanir-browserbase"`, a stable
108
+ per-gateway `instance` key, `bootId`, `leaseId`, plus any configured
109
+ `metadata` tags (org, coworker). The reaper only ever touches sessions whose
110
+ `instance` matches its own gateway.
111
+ - Gateway stop releases the active session (bounded); a boot-time sweep plus
112
+ the interval reaper release crash leftovers.
113
+ - The per-coworker context id persists in
114
+ `<state-dir>/velanir-browserbase/state.json` (0600). Deleting it forces a
115
+ fresh context (one-time re-login on every site).
116
+ - Logs redact the API key, broker token, and URL secrets.
117
+ - Known limitation: `/json/list` responses carry no per-target
118
+ `webSocketDebuggerUrl` (the broker exposes one multiplexed connection), so
119
+ OpenClaw's per-target JS-termination recovery path no-ops on this profile.
120
+ Tab management itself is unaffected — OpenClaw drives tabs Playwright-first
121
+ over the piped connection, with these HTTP endpoints as fallback.
122
+
123
+ ## Development
124
+
125
+ ```bash
126
+ pnpm --filter @velanir/openclaw-browserbase build
127
+ pnpm --filter @velanir/openclaw-browserbase check-types
128
+ pnpm --filter @velanir/openclaw-browserbase test
129
+ ```
130
+
131
+ Live integration tests are skipped unless `BROWSERBASE_API_KEY`,
132
+ `BROWSERBASE_PROJECT_ID` (and optionally `BROWSERBASE_API_URL`) are set in the
133
+ environment. They mint real (billed) sessions tagged `broker: "velanir-browserbase"`
134
+ with a dedicated test instance key and release them on completion.
@@ -0,0 +1,46 @@
1
+ type PluginLogger = {
2
+ debug?: (message: string) => void;
3
+ info?: (message: string) => void;
4
+ warn?: (message: string) => void;
5
+ error?: (message: string) => void;
6
+ };
7
+ type OpenClawPluginToolResult = {
8
+ content: Array<{
9
+ type: "text";
10
+ text: string;
11
+ }>;
12
+ };
13
+ type OpenClawPluginTool = {
14
+ name: string;
15
+ label?: string;
16
+ description: string;
17
+ parameters: unknown;
18
+ execute: (toolCallId: string, params: Record<string, unknown>) => Promise<OpenClawPluginToolResult> | OpenClawPluginToolResult;
19
+ };
20
+ type OpenClawPluginServiceContext = {
21
+ stateDir: string;
22
+ logger: PluginLogger;
23
+ };
24
+ type OpenClawPluginService = {
25
+ id: string;
26
+ start: (ctx: OpenClawPluginServiceContext) => void | Promise<void>;
27
+ stop?: (ctx: OpenClawPluginServiceContext) => void | Promise<void>;
28
+ };
29
+ type OpenClawPluginApi = {
30
+ pluginConfig?: Record<string, unknown>;
31
+ logger: PluginLogger;
32
+ registerService: (service: OpenClawPluginService) => void;
33
+ registerTool: (tool: OpenClawPluginTool, opts?: {
34
+ optional?: boolean;
35
+ }) => void;
36
+ };
37
+
38
+ declare const PLUGIN_ID = "velanir-browserbase";
39
+ declare const _default: {
40
+ id: string;
41
+ name: string;
42
+ description: string;
43
+ register(api: OpenClawPluginApi): void;
44
+ };
45
+
46
+ export { PLUGIN_ID, _default as default };