@jeevanand/agent-browserbox-sdk 0.1.0 → 0.2.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 CHANGED
@@ -78,6 +78,25 @@ Commands run in BrowserBox's shell (`help` lists them): files and text (`ls`,
78
78
  load from esm.sh) and `pkg install python|git|sqlite|zip|esbuild` for more.
79
79
  It is not bash, and there is no Node.js.
80
80
 
81
+ ### Shell sessions
82
+
83
+ ```ts
84
+ const sh = await box.openShell({ cwd: 'project' });
85
+ await sh.exec('cd src && export MODE=dev');
86
+ await sh.exec('pwd && echo $MODE'); // "…/project/src", "dev"; sh.cwd follows
87
+ ```
88
+
89
+ `sh.run(command)` streams like `box.spawn()`. One command at a time per session.
90
+
91
+ ### More
92
+
93
+ - `box.fs.glob('**/*.ts', { cwd })` → absolute paths · `box.fs.appendFile(path, data)`
94
+ - `box.dev.start('site')` → `{ port, url, root }` · `box.dev.logs(port)` · `box.dev.list()` · `box.dev.stop(port)`
95
+ - `box.processes()` → the process table · `box.killProcess(pid)`
96
+ - `box.share()` → a port for a worker, which calls `BrowserBox.attach(port)` (its own shells, processes and permission answers)
97
+ - `BrowserBox.boot({ site: true })` → the site's own kernel (the one a BrowserBox app on this site uses) instead of a box
98
+ - `box.kernelPort()` → a channel to the kernel's full internal protocol, for app UIs; versioned with the runtime
99
+
81
100
  ### `box.teardown()`
82
101
 
83
102
  Removes the frame and fails any call still pending.
package/dist/index.d.ts CHANGED
@@ -1,8 +1,14 @@
1
- import { PROTOCOL_VERSION, type ExecOptions, type ExecResult, type FileStat, type Method, type Methods, type PermissionDecision, type PermissionRequest } from './protocol.js';
2
- export type { ExecOptions, ExecResult, FileStat, PermissionDecision, PermissionRequest };
1
+ import { PROTOCOL_VERSION, type DevLogEntry, type DevServer, type ExecOptions, type ExecResult, type FileStat, type ProcessInfo, type KernelChannel, type Method, type Methods, type PermissionDecision, type PermissionRequest } from './protocol.js';
2
+ export type { DevLogEntry, DevServer, ExecOptions, ExecResult, FileStat, KernelChannel, PermissionDecision, PermissionRequest, ProcessInfo };
3
3
  export { PROTOCOL_VERSION };
4
- /** Where the hosted runtime lives. Self-host it with @jeevanand/agent-browserbox-runtime. */
5
- export declare const DEFAULT_RUNTIME_URL = "https://jeevanandmaurya.github.io/agent-browserbox/runtime/";
4
+ /** This SDK's version. Always released together with the runtime of the same version. */
5
+ export declare const VERSION = "0.2.0";
6
+ /**
7
+ * The hosted runtime of exactly this SDK's version. Released runtimes never
8
+ * change, so a newer runtime can never break an app on this SDK. Self-host it
9
+ * with @jeevanand/agent-browserbox-runtime.
10
+ */
11
+ export declare const DEFAULT_RUNTIME_URL = "https://jeevanandmaurya.github.io/agent-browserbox/runtime/0.2.0/";
6
12
  export type PermissionHandler = (request: PermissionRequest) => PermissionDecision | Promise<PermissionDecision>;
7
13
  export interface BootOptions {
8
14
  /** Base URL of the runtime (the folder holding embed/, kernel/, assets/). Default: the hosted runtime. */
@@ -16,6 +22,13 @@ export interface BootOptions {
16
22
  id?: string;
17
23
  /** 'persistent' (default): files survive reloads. 'memory': everything is gone when the box is torn down. */
18
24
  storage?: 'persistent' | 'memory';
25
+ /**
26
+ * Drive the site's own kernel instead of a box of its own: the one a
27
+ * BrowserBox app hosted on the same site uses, with its files, settings and
28
+ * keys. `id` and `storage` are ignored. (Other sites always get their own,
29
+ * separate storage: browsers partition it by the top-level site.)
30
+ */
31
+ site?: boolean;
19
32
  /** Element the hidden runtime frame is added to. Default: document.body. */
20
33
  container?: HTMLElement;
21
34
  /**
@@ -35,7 +48,7 @@ interface Sink {
35
48
  out: ReadableStreamDefaultController<string>[];
36
49
  stdout: ReadableStreamDefaultController<string>[];
37
50
  stderr: ReadableStreamDefaultController<string>[];
38
- exit(code: number): void;
51
+ exit(code: number, cwd?: string): void;
39
52
  }
40
53
  /** A running command in the box. */
41
54
  export declare class BoxProcess {
@@ -48,10 +61,31 @@ export declare class BoxProcess {
48
61
  /** Resolves with the exit code (124: timed out, 130: killed). */
49
62
  readonly exit: Promise<number>;
50
63
  /** @internal */
51
- constructor(pid: number, box: BrowserBox, attach: (sink: Sink) => void);
64
+ constructor(pid: number, box: BrowserBox, attach: (sink: Sink) => void, onExit?: (code: number, cwd?: string) => void);
52
65
  /** Stops the command. Resolves false if it had already finished. */
53
66
  kill(): Promise<boolean>;
54
67
  }
68
+ /**
69
+ * A shell session in the box: like a terminal, it keeps its working folder
70
+ * and variables between commands (`cd`, `export`).
71
+ */
72
+ export declare class BoxShell {
73
+ readonly id: number;
74
+ private box;
75
+ /** The working folder, as of the last command. */
76
+ cwd: string;
77
+ /** @internal */
78
+ constructor(id: number, cwd: string, box: BrowserBox);
79
+ /** Starts a command line and streams its output. One command at a time per session. */
80
+ run(command: string, opts?: {
81
+ timeoutMs?: number;
82
+ }): Promise<BoxProcess>;
83
+ /** Runs a command line to completion and returns its output. */
84
+ exec(command: string, opts?: {
85
+ timeoutMs?: number;
86
+ }): Promise<ExecResult>;
87
+ close(): Promise<void>;
88
+ }
55
89
  /** The box's filesystem. Paths are absolute, or relative to the box's home. */
56
90
  export declare class BoxFs {
57
91
  #private;
@@ -73,6 +107,35 @@ export declare class BoxFs {
73
107
  }): Promise<void>;
74
108
  rename(from: string, to: string): Promise<void>;
75
109
  cp(from: string, to: string): Promise<void>;
110
+ /** Creates the file if needed. */
111
+ appendFile(path: string, data: string | Uint8Array): Promise<void>;
112
+ /** Absolute paths of the files under `cwd` (default: home) that match a glob ('**', '*', '?', '{a,b}'). */
113
+ glob(pattern: string, opts?: {
114
+ cwd?: string;
115
+ limit?: number;
116
+ }): Promise<string[]>;
117
+ }
118
+ /**
119
+ * Dev servers for project folders: bundling TS/JSX, reloading on save, and a
120
+ * backend (server.ts) when the project has one. Nothing listens on a real
121
+ * port; the app shows a server's pages through the runtime.
122
+ */
123
+ export declare class BoxDev {
124
+ private box;
125
+ /** @internal */
126
+ constructor(box: BrowserBox);
127
+ /** Starts a server for a project folder, or returns the one already serving it. */
128
+ start(root: string, opts?: {
129
+ port?: number;
130
+ network?: boolean;
131
+ }): Promise<DevServer>;
132
+ stop(port: number): Promise<boolean>;
133
+ list(): Promise<DevServer[]>;
134
+ /** Console output, server logs, build errors and failed requests, oldest first. */
135
+ logs(port: number, opts?: {
136
+ after?: number;
137
+ limit?: number;
138
+ }): Promise<DevLogEntry[]>;
76
139
  }
77
140
  /**
78
141
  * A sandboxed computer in the browser: a filesystem, a shell, and JavaScript,
@@ -86,6 +149,7 @@ export declare class BoxFs {
86
149
  export declare class BrowserBox {
87
150
  #private;
88
151
  readonly fs: BoxFs;
152
+ readonly dev: BoxDev;
89
153
  /** Runtime version. */
90
154
  readonly version: string;
91
155
  /** This box's id. */
@@ -103,6 +167,34 @@ export declare class BrowserBox {
103
167
  exec(command: string, opts?: ExecOptions): Promise<ExecResult>;
104
168
  /** Starts a shell command line and streams its output. */
105
169
  spawn(command: string, opts?: ExecOptions): Promise<BoxProcess>;
170
+ /**
171
+ * Connects to a box shared with you (`box.share()`), e.g. from a worker,
172
+ * which cannot create the runtime's frame itself. `teardown()` then closes
173
+ * only this connection.
174
+ */
175
+ static attach(port: MessagePort, opts?: Pick<BootOptions, 'permissions' | 'timeoutMs'>): Promise<BrowserBox>;
176
+ /**
177
+ * A second connection to this box, with its own shells and processes, to
178
+ * hand to a worker (transfer the port, then `BrowserBox.attach(port)` there).
179
+ */
180
+ share(): Promise<MessagePort>;
181
+ /**
182
+ * A port to the box's kernel itself, speaking its full internal protocol,
183
+ * for app UIs that need more than this API (the BrowserBox app uses it).
184
+ * The protocol is versioned with the runtime: pin the runtime version.
185
+ */
186
+ kernelPort(): Promise<KernelChannel>;
187
+ /** Opens a shell session that keeps its working folder and variables between commands. */
188
+ openShell(opts?: {
189
+ cwd?: string;
190
+ env?: Record<string, string>;
191
+ }): Promise<BoxShell>;
192
+ /** The box's process table: shells, sandboxes, dev servers and so on. */
193
+ processes(): Promise<ProcessInfo[]>;
194
+ /** Stops a process from `processes()`. Resolves false if there was none with that id. */
195
+ killProcess(pid: number): Promise<boolean>;
196
+ /** @internal Wraps a runtime process id whose events are routed here. */
197
+ _process(pid: number, onExit?: (code: number, cwd?: string) => void): BoxProcess;
106
198
  /** Shuts the box down: removes its frame and fails anything still pending. */
107
199
  teardown(): void;
108
200
  /** @internal Low-level call into the runtime. */
package/dist/index.js CHANGED
@@ -1,7 +1,13 @@
1
1
  import { PROTOCOL_VERSION, } from './protocol.js';
2
2
  export { PROTOCOL_VERSION };
3
- /** Where the hosted runtime lives. Self-host it with @jeevanand/agent-browserbox-runtime. */
4
- export const DEFAULT_RUNTIME_URL = 'https://jeevanandmaurya.github.io/agent-browserbox/runtime/';
3
+ /** This SDK's version. Always released together with the runtime of the same version. */
4
+ export const VERSION = '0.2.0';
5
+ /**
6
+ * The hosted runtime of exactly this SDK's version. Released runtimes never
7
+ * change, so a newer runtime can never break an app on this SDK. Self-host it
8
+ * with @jeevanand/agent-browserbox-runtime.
9
+ */
10
+ export const DEFAULT_RUNTIME_URL = `https://jeevanandmaurya.github.io/agent-browserbox/runtime/${VERSION}/`;
5
11
  /** An error from the box. `code` is set for filesystem errors (ENOENT, EEXIST, …). */
6
12
  export class BoxError extends Error {
7
13
  code;
@@ -22,7 +28,7 @@ export class BoxProcess {
22
28
  /** Resolves with the exit code (124: timed out, 130: killed). */
23
29
  exit;
24
30
  /** @internal */
25
- constructor(pid, box, attach) {
31
+ constructor(pid, box, attach, onExit) {
26
32
  this.pid = pid;
27
33
  this.box = box;
28
34
  const sink = { out: [], stdout: [], stderr: [], exit: () => undefined };
@@ -30,7 +36,7 @@ export class BoxProcess {
30
36
  this.output = stream(sink.out);
31
37
  this.stdout = stream(sink.stdout);
32
38
  this.stderr = stream(sink.stderr);
33
- this.exit = new Promise((resolve) => (sink.exit = resolve));
39
+ this.exit = new Promise((resolve) => (sink.exit = (code, cwd) => (onExit?.(code, cwd), resolve(code))));
34
40
  attach(sink);
35
41
  }
36
42
  /** Stops the command. Resolves false if it had already finished. */
@@ -38,6 +44,55 @@ export class BoxProcess {
38
44
  return this.box.call('kill', this.pid);
39
45
  }
40
46
  }
47
+ /** Reads a stream to the end. */
48
+ async function readAll(stream) {
49
+ let text = '';
50
+ const reader = stream.getReader();
51
+ for (;;) {
52
+ const { value, done } = await reader.read();
53
+ if (done)
54
+ return text;
55
+ text += value;
56
+ }
57
+ }
58
+ /** Collapses progress bars redrawn with \r to their final state, as exec() does. */
59
+ const settle = (text) => text
60
+ .split('\n')
61
+ .map((l) => l.slice(l.lastIndexOf('\r') + 1))
62
+ .join('\n');
63
+ /**
64
+ * A shell session in the box: like a terminal, it keeps its working folder
65
+ * and variables between commands (`cd`, `export`).
66
+ */
67
+ export class BoxShell {
68
+ id;
69
+ box;
70
+ /** The working folder, as of the last command. */
71
+ cwd;
72
+ /** @internal */
73
+ constructor(id, cwd, box) {
74
+ this.id = id;
75
+ this.box = box;
76
+ this.cwd = cwd;
77
+ }
78
+ /** Starts a command line and streams its output. One command at a time per session. */
79
+ async run(command, opts = {}) {
80
+ const pid = await this.box.call('shell.run', this.id, command, opts);
81
+ return this.box._process(pid, (_code, cwd) => {
82
+ if (cwd)
83
+ this.cwd = cwd;
84
+ });
85
+ }
86
+ /** Runs a command line to completion and returns its output. */
87
+ async exec(command, opts = {}) {
88
+ const p = await this.run(command, opts);
89
+ const [stdout, stderr, exitCode] = await Promise.all([readAll(p.stdout), readAll(p.stderr), p.exit]);
90
+ return { exitCode, stdout: settle(stdout), stderr: settle(stderr) };
91
+ }
92
+ close() {
93
+ return this.box.call('shell.close', this.id);
94
+ }
95
+ }
41
96
  /** The box's filesystem. Paths are absolute, or relative to the box's home. */
42
97
  export class BoxFs {
43
98
  box;
@@ -81,6 +136,40 @@ export class BoxFs {
81
136
  cp(from, to) {
82
137
  return this.box.call('fs.cp', this.#abs(from), this.#abs(to));
83
138
  }
139
+ /** Creates the file if needed. */
140
+ appendFile(path, data) {
141
+ return this.box.call('fs.appendFile', this.#abs(path), data);
142
+ }
143
+ /** Absolute paths of the files under `cwd` (default: home) that match a glob ('**', '*', '?', '{a,b}'). */
144
+ glob(pattern, opts = {}) {
145
+ return this.box.call('fs.glob', pattern, this.#abs(opts.cwd ?? '.'), opts.limit);
146
+ }
147
+ }
148
+ /**
149
+ * Dev servers for project folders: bundling TS/JSX, reloading on save, and a
150
+ * backend (server.ts) when the project has one. Nothing listens on a real
151
+ * port; the app shows a server's pages through the runtime.
152
+ */
153
+ export class BoxDev {
154
+ box;
155
+ /** @internal */
156
+ constructor(box) {
157
+ this.box = box;
158
+ }
159
+ /** Starts a server for a project folder, or returns the one already serving it. */
160
+ start(root, opts = {}) {
161
+ return this.box.call('dev.start', { root: root.startsWith('/') ? root : `${this.box.home.replace(/\/$/, '')}/${root}`, ...opts });
162
+ }
163
+ stop(port) {
164
+ return this.box.call('dev.stop', port);
165
+ }
166
+ list() {
167
+ return this.box.call('dev.list');
168
+ }
169
+ /** Console output, server logs, build errors and failed requests, oldest first. */
170
+ logs(port, opts = {}) {
171
+ return this.box.call('dev.logs', port, opts);
172
+ }
84
173
  }
85
174
  /**
86
175
  * A sandboxed computer in the browser: a filesystem, a shell, and JavaScript,
@@ -93,6 +182,7 @@ export class BoxFs {
93
182
  */
94
183
  export class BrowserBox {
95
184
  fs = new BoxFs(this);
185
+ dev = new BoxDev(this);
96
186
  /** Runtime version. */
97
187
  version;
98
188
  /** This box's id. */
@@ -132,7 +222,7 @@ export class BrowserBox {
132
222
  const id = opts.id ?? (memory ? `mem-${crypto.randomUUID()}` : 'default');
133
223
  if (!/^[A-Za-z0-9_-]{1,64}$/.test(id))
134
224
  return Promise.reject(new BoxError(`invalid box id "${id}": use letters, digits, '-' and '_' (at most 64)`));
135
- const src = new URL(`embed/?box=${encodeURIComponent(id)}&storage=${memory ? 'memory' : 'opfs'}`, base);
225
+ const src = new URL(opts.site ? 'embed/?site=1' : `embed/?box=${encodeURIComponent(id)}&storage=${memory ? 'memory' : 'opfs'}`, base);
136
226
  const permissions = typeof opts.permissions === 'function' ? opts.permissions : opts.permissions === 'allow' ? () => 'once' : () => 'deny';
137
227
  const frame = document.createElement('iframe');
138
228
  frame.src = src.href;
@@ -175,13 +265,67 @@ export class BrowserBox {
175
265
  }
176
266
  /** Starts a shell command line and streams its output. */
177
267
  async spawn(command, opts) {
178
- const pid = await this.call('spawn', command, opts);
268
+ return this._process(await this.call('spawn', command, opts));
269
+ }
270
+ /**
271
+ * Connects to a box shared with you (`box.share()`), e.g. from a worker,
272
+ * which cannot create the runtime's frame itself. `teardown()` then closes
273
+ * only this connection.
274
+ */
275
+ static attach(port, opts = {}) {
276
+ const permissions = typeof opts.permissions === 'function' ? opts.permissions : opts.permissions === 'allow' ? () => 'once' : () => 'deny';
277
+ return new Promise((resolve, reject) => {
278
+ const timer = setTimeout(() => reject(new BoxError(`the shared box did not respond within ${opts.timeoutMs ?? 30000} ms`)), opts.timeoutMs ?? 30000);
279
+ port.onmessage = (m) => {
280
+ const msg = m.data;
281
+ if (msg.t === 'refused') {
282
+ clearTimeout(timer);
283
+ reject(new BoxError(`the shared box refused: ${msg.error}`));
284
+ }
285
+ else if (msg.t === 'hello') {
286
+ clearTimeout(timer);
287
+ resolve(new BrowserBox(port, null, msg, permissions));
288
+ }
289
+ };
290
+ port.start();
291
+ });
292
+ }
293
+ /**
294
+ * A second connection to this box, with its own shells and processes, to
295
+ * hand to a worker (transfer the port, then `BrowserBox.attach(port)` there).
296
+ */
297
+ share() {
298
+ return this.call('share');
299
+ }
300
+ /**
301
+ * A port to the box's kernel itself, speaking its full internal protocol,
302
+ * for app UIs that need more than this API (the BrowserBox app uses it).
303
+ * The protocol is versioned with the runtime: pin the runtime version.
304
+ */
305
+ kernelPort() {
306
+ return this.call('kernel.connect');
307
+ }
308
+ /** Opens a shell session that keeps its working folder and variables between commands. */
309
+ async openShell(opts = {}) {
310
+ const { id, cwd } = await this.call('shell.open', opts);
311
+ return new BoxShell(id, cwd, this);
312
+ }
313
+ /** The box's process table: shells, sandboxes, dev servers and so on. */
314
+ processes() {
315
+ return this.call('procs.list');
316
+ }
317
+ /** Stops a process from `processes()`. Resolves false if there was none with that id. */
318
+ killProcess(pid) {
319
+ return this.call('procs.kill', pid);
320
+ }
321
+ /** @internal Wraps a runtime process id whose events are routed here. */
322
+ _process(pid, onExit) {
179
323
  return new BoxProcess(pid, this, (sink) => {
180
324
  this.#sinks.set(pid, sink);
181
325
  for (const ev of this.#early.get(pid) ?? [])
182
326
  this.#deliver(pid, ev);
183
327
  this.#early.delete(pid);
184
- });
328
+ }, onExit);
185
329
  }
186
330
  /** Shuts the box down: removes its frame and fails anything still pending. */
187
331
  teardown() {
@@ -194,7 +338,7 @@ export class BrowserBox {
194
338
  for (const pid of [...this.#sinks.keys()])
195
339
  this.#deliver(pid, { t: 'exit', exitCode: 130 });
196
340
  this.#port.close();
197
- this.#frame.remove();
341
+ this.#frame?.remove();
198
342
  }
199
343
  /** @internal Low-level call into the runtime. */
200
344
  call(method, ...args) {
@@ -220,7 +364,7 @@ export class BrowserBox {
220
364
  case 'output':
221
365
  return this.#route(msg.pid, { t: 'output', stream: msg.stream, data: msg.data });
222
366
  case 'exit':
223
- return this.#route(msg.pid, { t: 'exit', exitCode: msg.exitCode });
367
+ return this.#route(msg.pid, { t: 'exit', exitCode: msg.exitCode, cwd: msg.cwd });
224
368
  case 'permission':
225
369
  void Promise.resolve()
226
370
  .then(() => this.#permissions(msg.request))
@@ -255,7 +399,7 @@ export class BrowserBox {
255
399
  return each([...sink.out, ...sink[ev.stream]], (c) => c.enqueue(ev.data));
256
400
  each([...sink.out, ...sink.stdout, ...sink.stderr], (c) => c.close());
257
401
  this.#sinks.delete(pid);
258
- sink.exit(ev.exitCode);
402
+ sink.exit(ev.exitCode, ev.cwd);
259
403
  }
260
404
  }
261
405
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,GAWjB,M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CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;CACF"}
@@ -15,7 +15,7 @@ export interface Hello {
15
15
  protocol: number;
16
16
  /** Runtime version. */
17
17
  version: string;
18
- /** The box's id. */
18
+ /** The box's id ('site' for the site's own kernel). */
19
19
  id: string;
20
20
  /** The default working directory for commands. */
21
21
  home: string;
@@ -60,6 +60,51 @@ export interface PermissionRequest {
60
60
  /** The exact thing being approved (command, path, URL). */
61
61
  detail: string;
62
62
  }
63
+ /** A shell session: keeps its working folder and variables between commands. */
64
+ export interface ShellInfo {
65
+ id: number;
66
+ cwd: string;
67
+ }
68
+ /** A process in the box's process table (shells, sandboxes, dev servers, …). */
69
+ export interface ProcessInfo {
70
+ pid: number;
71
+ ppid?: number;
72
+ name: string;
73
+ kind: string;
74
+ /** 'running', 'idle', … */
75
+ state: string;
76
+ detail: string;
77
+ /** When it started, ms since the epoch. */
78
+ started: number;
79
+ cpuMs: number;
80
+ memBytes: number;
81
+ }
82
+ /** A dev server the box runs for a project folder. Nothing listens on a real port: `url` is virtual. */
83
+ export interface DevServer {
84
+ port: number;
85
+ root: string;
86
+ url: string;
87
+ /** The project's request handler (server.ts, …), if it has one. */
88
+ backend: string | null;
89
+ network: boolean;
90
+ }
91
+ export interface DevLogEntry {
92
+ /** Increasing per server; pass the last one as `after` to get newer entries. */
93
+ seq: number;
94
+ t: number;
95
+ level: 'log' | 'info' | 'warn' | 'error' | 'debug';
96
+ /** page: the app's console · server: the backend · build: bundling · network: failed requests. */
97
+ source: 'page' | 'server' | 'build' | 'network';
98
+ text: string;
99
+ }
100
+ /** A port to the kernel, and what its client needs to know. */
101
+ export interface KernelChannel {
102
+ port: MessagePort;
103
+ /** The Web Lock the runtime holds while this connection lives. */
104
+ lock: string;
105
+ /** False when the browser has no SharedWorker (one kernel per page). */
106
+ shared: boolean;
107
+ }
63
108
  /** Calls the SDK can make, with their arguments and results. */
64
109
  export interface Methods {
65
110
  info(): Hello;
@@ -75,6 +120,38 @@ export interface Methods {
75
120
  }): void;
76
121
  'fs.rename'(from: string, to: string): void;
77
122
  'fs.cp'(from: string, to: string): void;
123
+ 'fs.appendFile'(path: string, data: string | Uint8Array): void;
124
+ /** Absolute paths of the files under `cwd` that match a glob ('**', '*', '?', '{a,b}'). */
125
+ 'fs.glob'(pattern: string, cwd?: string, limit?: number): string[];
126
+ 'shell.open'(opts?: {
127
+ cwd?: string;
128
+ env?: Record<string, string>;
129
+ }): ShellInfo;
130
+ /** Runs a command line in a shell session; output and exit (with the new cwd) arrive as events. Returns its process id. */
131
+ 'shell.run'(id: number, command: string, opts?: {
132
+ timeoutMs?: number;
133
+ }): number;
134
+ 'shell.close'(id: number): void;
135
+ 'dev.start'(opts: {
136
+ root: string;
137
+ port?: number;
138
+ network?: boolean;
139
+ }): DevServer;
140
+ 'dev.stop'(port: number): boolean;
141
+ 'dev.list'(): DevServer[];
142
+ 'dev.logs'(port: number, opts?: {
143
+ after?: number;
144
+ limit?: number;
145
+ }): DevLogEntry[];
146
+ 'procs.list'(): ProcessInfo[];
147
+ 'procs.kill'(pid: number): boolean;
148
+ /**
149
+ * A port to the box's kernel itself, speaking its full internal protocol:
150
+ * for app UIs that need more than this API. Versioned with the runtime.
151
+ */
152
+ 'kernel.connect'(): KernelChannel;
153
+ /** A second connection to this box (its own shells and processes), e.g. for a worker. */
154
+ share(): MessagePort;
78
155
  exec(command: string, opts?: ExecOptions): ExecResult;
79
156
  /** Starts a command; its output and exit arrive as events. Returns its process id. */
80
157
  spawn(command: string, opts?: ExecOptions): number;
@@ -109,10 +186,13 @@ export type FromRuntime = Hello | Refused | {
109
186
  pid: number;
110
187
  stream: 'stdout' | 'stderr';
111
188
  data: string;
112
- } | {
189
+ }
190
+ /** `cwd`: for commands run in a shell session, its working folder afterwards. */
191
+ | {
113
192
  t: 'exit';
114
193
  pid: number;
115
194
  exitCode: number;
195
+ cwd?: string;
116
196
  } | {
117
197
  t: 'permission';
118
198
  id: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jeevanand/agent-browserbox-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "A sandboxed computer in the browser for AI agents: filesystem, shell, JavaScript, Python and WebAssembly, isolated in its own origin. No backend.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/index.ts CHANGED
@@ -1,10 +1,14 @@
1
1
  import {
2
2
  PROTOCOL_VERSION,
3
+ type DevLogEntry,
4
+ type DevServer,
3
5
  type ExecOptions,
4
6
  type ExecResult,
5
7
  type FileStat,
8
+ type ProcessInfo,
6
9
  type FromRuntime,
7
10
  type Hello,
11
+ type KernelChannel,
8
12
  type Method,
9
13
  type Methods,
10
14
  type PermissionDecision,
@@ -12,11 +16,18 @@ import {
12
16
  type ToRuntime,
13
17
  } from './protocol.js';
14
18
 
15
- export type { ExecOptions, ExecResult, FileStat, PermissionDecision, PermissionRequest };
19
+ export type { DevLogEntry, DevServer, ExecOptions, ExecResult, FileStat, KernelChannel, PermissionDecision, PermissionRequest, ProcessInfo };
16
20
  export { PROTOCOL_VERSION };
17
21
 
18
- /** Where the hosted runtime lives. Self-host it with @jeevanand/agent-browserbox-runtime. */
19
- export const DEFAULT_RUNTIME_URL = 'https://jeevanandmaurya.github.io/agent-browserbox/runtime/';
22
+ /** This SDK's version. Always released together with the runtime of the same version. */
23
+ export const VERSION = '0.2.0';
24
+
25
+ /**
26
+ * The hosted runtime of exactly this SDK's version. Released runtimes never
27
+ * change, so a newer runtime can never break an app on this SDK. Self-host it
28
+ * with @jeevanand/agent-browserbox-runtime.
29
+ */
30
+ export const DEFAULT_RUNTIME_URL = `https://jeevanandmaurya.github.io/agent-browserbox/runtime/${VERSION}/`;
20
31
 
21
32
  export type PermissionHandler = (request: PermissionRequest) => PermissionDecision | Promise<PermissionDecision>;
22
33
 
@@ -32,6 +43,13 @@ export interface BootOptions {
32
43
  id?: string;
33
44
  /** 'persistent' (default): files survive reloads. 'memory': everything is gone when the box is torn down. */
34
45
  storage?: 'persistent' | 'memory';
46
+ /**
47
+ * Drive the site's own kernel instead of a box of its own: the one a
48
+ * BrowserBox app hosted on the same site uses, with its files, settings and
49
+ * keys. `id` and `storage` are ignored. (Other sites always get their own,
50
+ * separate storage: browsers partition it by the top-level site.)
51
+ */
52
+ site?: boolean;
35
53
  /** Element the hidden runtime frame is added to. Default: document.body. */
36
54
  container?: HTMLElement;
37
55
  /**
@@ -58,10 +76,10 @@ interface Sink {
58
76
  out: ReadableStreamDefaultController<string>[];
59
77
  stdout: ReadableStreamDefaultController<string>[];
60
78
  stderr: ReadableStreamDefaultController<string>[];
61
- exit(code: number): void;
79
+ exit(code: number, cwd?: string): void;
62
80
  }
63
81
 
64
- type ProcEvent = { t: 'output'; stream: 'stdout' | 'stderr'; data: string } | { t: 'exit'; exitCode: number };
82
+ type ProcEvent = { t: 'output'; stream: 'stdout' | 'stderr'; data: string } | { t: 'exit'; exitCode: number; cwd?: string };
65
83
 
66
84
  /** A running command in the box. */
67
85
  export class BoxProcess {
@@ -77,13 +95,14 @@ export class BoxProcess {
77
95
  readonly pid: number,
78
96
  private box: BrowserBox,
79
97
  attach: (sink: Sink) => void,
98
+ onExit?: (code: number, cwd?: string) => void,
80
99
  ) {
81
100
  const sink: Sink = { out: [], stdout: [], stderr: [], exit: () => undefined };
82
101
  const stream = (list: ReadableStreamDefaultController<string>[]) => new ReadableStream<string>({ start: (c) => void list.push(c) });
83
102
  this.output = stream(sink.out);
84
103
  this.stdout = stream(sink.stdout);
85
104
  this.stderr = stream(sink.stderr);
86
- this.exit = new Promise((resolve) => (sink.exit = resolve));
105
+ this.exit = new Promise((resolve) => (sink.exit = (code, cwd) => (onExit?.(code, cwd), resolve(code))));
87
106
  attach(sink);
88
107
  }
89
108
 
@@ -93,6 +112,61 @@ export class BoxProcess {
93
112
  }
94
113
  }
95
114
 
115
+ /** Reads a stream to the end. */
116
+ async function readAll(stream: ReadableStream<string>): Promise<string> {
117
+ let text = '';
118
+ const reader = stream.getReader();
119
+ for (;;) {
120
+ const { value, done } = await reader.read();
121
+ if (done) return text;
122
+ text += value;
123
+ }
124
+ }
125
+
126
+ /** Collapses progress bars redrawn with \r to their final state, as exec() does. */
127
+ const settle = (text: string) =>
128
+ text
129
+ .split('\n')
130
+ .map((l) => l.slice(l.lastIndexOf('\r') + 1))
131
+ .join('\n');
132
+
133
+ /**
134
+ * A shell session in the box: like a terminal, it keeps its working folder
135
+ * and variables between commands (`cd`, `export`).
136
+ */
137
+ export class BoxShell {
138
+ /** The working folder, as of the last command. */
139
+ cwd: string;
140
+
141
+ /** @internal */
142
+ constructor(
143
+ readonly id: number,
144
+ cwd: string,
145
+ private box: BrowserBox,
146
+ ) {
147
+ this.cwd = cwd;
148
+ }
149
+
150
+ /** Starts a command line and streams its output. One command at a time per session. */
151
+ async run(command: string, opts: { timeoutMs?: number } = {}): Promise<BoxProcess> {
152
+ const pid = await this.box.call('shell.run', this.id, command, opts);
153
+ return this.box._process(pid, (_code, cwd) => {
154
+ if (cwd) this.cwd = cwd;
155
+ });
156
+ }
157
+
158
+ /** Runs a command line to completion and returns its output. */
159
+ async exec(command: string, opts: { timeoutMs?: number } = {}): Promise<ExecResult> {
160
+ const p = await this.run(command, opts);
161
+ const [stdout, stderr, exitCode] = await Promise.all([readAll(p.stdout), readAll(p.stderr), p.exit]);
162
+ return { exitCode, stdout: settle(stdout), stderr: settle(stderr) };
163
+ }
164
+
165
+ close(): Promise<void> {
166
+ return this.box.call('shell.close', this.id);
167
+ }
168
+ }
169
+
96
170
  /** The box's filesystem. Paths are absolute, or relative to the box's home. */
97
171
  export class BoxFs {
98
172
  /** @internal */
@@ -135,6 +209,39 @@ export class BoxFs {
135
209
  cp(from: string, to: string): Promise<void> {
136
210
  return this.box.call('fs.cp', this.#abs(from), this.#abs(to));
137
211
  }
212
+ /** Creates the file if needed. */
213
+ appendFile(path: string, data: string | Uint8Array): Promise<void> {
214
+ return this.box.call('fs.appendFile', this.#abs(path), data);
215
+ }
216
+ /** Absolute paths of the files under `cwd` (default: home) that match a glob ('**', '*', '?', '{a,b}'). */
217
+ glob(pattern: string, opts: { cwd?: string; limit?: number } = {}): Promise<string[]> {
218
+ return this.box.call('fs.glob', pattern, this.#abs(opts.cwd ?? '.'), opts.limit);
219
+ }
220
+ }
221
+
222
+ /**
223
+ * Dev servers for project folders: bundling TS/JSX, reloading on save, and a
224
+ * backend (server.ts) when the project has one. Nothing listens on a real
225
+ * port; the app shows a server's pages through the runtime.
226
+ */
227
+ export class BoxDev {
228
+ /** @internal */
229
+ constructor(private box: BrowserBox) {}
230
+
231
+ /** Starts a server for a project folder, or returns the one already serving it. */
232
+ start(root: string, opts: { port?: number; network?: boolean } = {}): Promise<DevServer> {
233
+ return this.box.call('dev.start', { root: root.startsWith('/') ? root : `${this.box.home.replace(/\/$/, '')}/${root}`, ...opts });
234
+ }
235
+ stop(port: number): Promise<boolean> {
236
+ return this.box.call('dev.stop', port);
237
+ }
238
+ list(): Promise<DevServer[]> {
239
+ return this.box.call('dev.list');
240
+ }
241
+ /** Console output, server logs, build errors and failed requests, oldest first. */
242
+ logs(port: number, opts: { after?: number; limit?: number } = {}): Promise<DevLogEntry[]> {
243
+ return this.box.call('dev.logs', port, opts);
244
+ }
138
245
  }
139
246
 
140
247
  /**
@@ -148,6 +255,7 @@ export class BoxFs {
148
255
  */
149
256
  export class BrowserBox {
150
257
  readonly fs = new BoxFs(this);
258
+ readonly dev = new BoxDev(this);
151
259
  /** Runtime version. */
152
260
  readonly version: string;
153
261
  /** This box's id. */
@@ -160,7 +268,7 @@ export class BrowserBox {
160
268
  readonly storage: 'opfs' | 'memory';
161
269
 
162
270
  #port: MessagePort;
163
- #frame: HTMLIFrameElement;
271
+ #frame: HTMLIFrameElement | null;
164
272
  #permissions: PermissionHandler;
165
273
  #nextId = 1;
166
274
  #calls = new Map<number, { resolve(v: unknown): void; reject(e: Error): void }>();
@@ -169,7 +277,7 @@ export class BrowserBox {
169
277
  #early = new Map<number, ProcEvent[]>();
170
278
  #closed: BoxError | null = null;
171
279
 
172
- private constructor(port: MessagePort, frame: HTMLIFrameElement, hello: Hello, permissions: PermissionHandler) {
280
+ private constructor(port: MessagePort, frame: HTMLIFrameElement | null, hello: Hello, permissions: PermissionHandler) {
173
281
  this.#port = port;
174
282
  this.#frame = frame;
175
283
  this.#permissions = permissions;
@@ -188,7 +296,7 @@ export class BrowserBox {
188
296
  const memory = opts.storage === 'memory';
189
297
  const id = opts.id ?? (memory ? `mem-${crypto.randomUUID()}` : 'default');
190
298
  if (!/^[A-Za-z0-9_-]{1,64}$/.test(id)) return Promise.reject(new BoxError(`invalid box id "${id}": use letters, digits, '-' and '_' (at most 64)`));
191
- const src = new URL(`embed/?box=${encodeURIComponent(id)}&storage=${memory ? 'memory' : 'opfs'}`, base);
299
+ const src = new URL(opts.site ? 'embed/?site=1' : `embed/?box=${encodeURIComponent(id)}&storage=${memory ? 'memory' : 'opfs'}`, base);
192
300
  const permissions: PermissionHandler = typeof opts.permissions === 'function' ? opts.permissions : opts.permissions === 'allow' ? () => 'once' : () => 'deny';
193
301
 
194
302
  const frame = document.createElement('iframe');
@@ -232,14 +340,79 @@ export class BrowserBox {
232
340
 
233
341
  /** Starts a shell command line and streams its output. */
234
342
  async spawn(command: string, opts?: ExecOptions): Promise<BoxProcess> {
235
- const pid = await this.call('spawn', command, opts);
236
- return new BoxProcess(pid, this, (sink) => {
237
- this.#sinks.set(pid, sink);
238
- for (const ev of this.#early.get(pid) ?? []) this.#deliver(pid, ev);
239
- this.#early.delete(pid);
343
+ return this._process(await this.call('spawn', command, opts));
344
+ }
345
+
346
+ /**
347
+ * Connects to a box shared with you (`box.share()`), e.g. from a worker,
348
+ * which cannot create the runtime's frame itself. `teardown()` then closes
349
+ * only this connection.
350
+ */
351
+ static attach(port: MessagePort, opts: Pick<BootOptions, 'permissions' | 'timeoutMs'> = {}): Promise<BrowserBox> {
352
+ const permissions: PermissionHandler = typeof opts.permissions === 'function' ? opts.permissions : opts.permissions === 'allow' ? () => 'once' : () => 'deny';
353
+ return new Promise((resolve, reject) => {
354
+ const timer = setTimeout(() => reject(new BoxError(`the shared box did not respond within ${opts.timeoutMs ?? 30000} ms`)), opts.timeoutMs ?? 30000);
355
+ port.onmessage = (m: MessageEvent<FromRuntime>) => {
356
+ const msg = m.data;
357
+ if (msg.t === 'refused') {
358
+ clearTimeout(timer);
359
+ reject(new BoxError(`the shared box refused: ${msg.error}`));
360
+ } else if (msg.t === 'hello') {
361
+ clearTimeout(timer);
362
+ resolve(new BrowserBox(port, null, msg, permissions));
363
+ }
364
+ };
365
+ port.start();
240
366
  });
241
367
  }
242
368
 
369
+ /**
370
+ * A second connection to this box, with its own shells and processes, to
371
+ * hand to a worker (transfer the port, then `BrowserBox.attach(port)` there).
372
+ */
373
+ share(): Promise<MessagePort> {
374
+ return this.call('share');
375
+ }
376
+
377
+ /**
378
+ * A port to the box's kernel itself, speaking its full internal protocol,
379
+ * for app UIs that need more than this API (the BrowserBox app uses it).
380
+ * The protocol is versioned with the runtime: pin the runtime version.
381
+ */
382
+ kernelPort(): Promise<KernelChannel> {
383
+ return this.call('kernel.connect');
384
+ }
385
+
386
+ /** Opens a shell session that keeps its working folder and variables between commands. */
387
+ async openShell(opts: { cwd?: string; env?: Record<string, string> } = {}): Promise<BoxShell> {
388
+ const { id, cwd } = await this.call('shell.open', opts);
389
+ return new BoxShell(id, cwd, this);
390
+ }
391
+
392
+ /** The box's process table: shells, sandboxes, dev servers and so on. */
393
+ processes(): Promise<ProcessInfo[]> {
394
+ return this.call('procs.list');
395
+ }
396
+
397
+ /** Stops a process from `processes()`. Resolves false if there was none with that id. */
398
+ killProcess(pid: number): Promise<boolean> {
399
+ return this.call('procs.kill', pid);
400
+ }
401
+
402
+ /** @internal Wraps a runtime process id whose events are routed here. */
403
+ _process(pid: number, onExit?: (code: number, cwd?: string) => void): BoxProcess {
404
+ return new BoxProcess(
405
+ pid,
406
+ this,
407
+ (sink) => {
408
+ this.#sinks.set(pid, sink);
409
+ for (const ev of this.#early.get(pid) ?? []) this.#deliver(pid, ev);
410
+ this.#early.delete(pid);
411
+ },
412
+ onExit,
413
+ );
414
+ }
415
+
243
416
  /** Shuts the box down: removes its frame and fails anything still pending. */
244
417
  teardown(): void {
245
418
  if (this.#closed) return;
@@ -248,7 +421,7 @@ export class BrowserBox {
248
421
  this.#calls.clear();
249
422
  for (const pid of [...this.#sinks.keys()]) this.#deliver(pid, { t: 'exit', exitCode: 130 });
250
423
  this.#port.close();
251
- this.#frame.remove();
424
+ this.#frame?.remove();
252
425
  }
253
426
 
254
427
  /** @internal Low-level call into the runtime. */
@@ -273,7 +446,7 @@ export class BrowserBox {
273
446
  case 'output':
274
447
  return this.#route(msg.pid, { t: 'output', stream: msg.stream, data: msg.data });
275
448
  case 'exit':
276
- return this.#route(msg.pid, { t: 'exit', exitCode: msg.exitCode });
449
+ return this.#route(msg.pid, { t: 'exit', exitCode: msg.exitCode, cwd: msg.cwd });
277
450
  case 'permission':
278
451
  void Promise.resolve()
279
452
  .then(() => this.#permissions(msg.request))
@@ -306,6 +479,6 @@ export class BrowserBox {
306
479
  if (ev.t === 'output') return each([...sink.out, ...sink[ev.stream]], (c) => c.enqueue(ev.data));
307
480
  each([...sink.out, ...sink.stdout, ...sink.stderr], (c) => c.close());
308
481
  this.#sinks.delete(pid);
309
- sink.exit(ev.exitCode);
482
+ sink.exit(ev.exitCode, ev.cwd);
310
483
  }
311
484
  }
package/src/protocol.ts CHANGED
@@ -16,7 +16,7 @@ export interface Hello {
16
16
  protocol: number;
17
17
  /** Runtime version. */
18
18
  version: string;
19
- /** The box's id. */
19
+ /** The box's id ('site' for the site's own kernel). */
20
20
  id: string;
21
21
  /** The default working directory for commands. */
22
22
  home: string;
@@ -68,6 +68,56 @@ export interface PermissionRequest {
68
68
  detail: string;
69
69
  }
70
70
 
71
+ /** A shell session: keeps its working folder and variables between commands. */
72
+ export interface ShellInfo {
73
+ id: number;
74
+ cwd: string;
75
+ }
76
+
77
+ /** A process in the box's process table (shells, sandboxes, dev servers, …). */
78
+ export interface ProcessInfo {
79
+ pid: number;
80
+ ppid?: number;
81
+ name: string;
82
+ kind: string;
83
+ /** 'running', 'idle', … */
84
+ state: string;
85
+ detail: string;
86
+ /** When it started, ms since the epoch. */
87
+ started: number;
88
+ cpuMs: number;
89
+ memBytes: number;
90
+ }
91
+
92
+ /** A dev server the box runs for a project folder. Nothing listens on a real port: `url` is virtual. */
93
+ export interface DevServer {
94
+ port: number;
95
+ root: string;
96
+ url: string;
97
+ /** The project's request handler (server.ts, …), if it has one. */
98
+ backend: string | null;
99
+ network: boolean;
100
+ }
101
+
102
+ export interface DevLogEntry {
103
+ /** Increasing per server; pass the last one as `after` to get newer entries. */
104
+ seq: number;
105
+ t: number;
106
+ level: 'log' | 'info' | 'warn' | 'error' | 'debug';
107
+ /** page: the app's console · server: the backend · build: bundling · network: failed requests. */
108
+ source: 'page' | 'server' | 'build' | 'network';
109
+ text: string;
110
+ }
111
+
112
+ /** A port to the kernel, and what its client needs to know. */
113
+ export interface KernelChannel {
114
+ port: MessagePort;
115
+ /** The Web Lock the runtime holds while this connection lives. */
116
+ lock: string;
117
+ /** False when the browser has no SharedWorker (one kernel per page). */
118
+ shared: boolean;
119
+ }
120
+
71
121
  /** Calls the SDK can make, with their arguments and results. */
72
122
  export interface Methods {
73
123
  info(): Hello;
@@ -81,6 +131,26 @@ export interface Methods {
81
131
  'fs.rm'(path: string, opts?: { recursive?: boolean }): void;
82
132
  'fs.rename'(from: string, to: string): void;
83
133
  'fs.cp'(from: string, to: string): void;
134
+ 'fs.appendFile'(path: string, data: string | Uint8Array): void;
135
+ /** Absolute paths of the files under `cwd` that match a glob ('**', '*', '?', '{a,b}'). */
136
+ 'fs.glob'(pattern: string, cwd?: string, limit?: number): string[];
137
+ 'shell.open'(opts?: { cwd?: string; env?: Record<string, string> }): ShellInfo;
138
+ /** Runs a command line in a shell session; output and exit (with the new cwd) arrive as events. Returns its process id. */
139
+ 'shell.run'(id: number, command: string, opts?: { timeoutMs?: number }): number;
140
+ 'shell.close'(id: number): void;
141
+ 'dev.start'(opts: { root: string; port?: number; network?: boolean }): DevServer;
142
+ 'dev.stop'(port: number): boolean;
143
+ 'dev.list'(): DevServer[];
144
+ 'dev.logs'(port: number, opts?: { after?: number; limit?: number }): DevLogEntry[];
145
+ 'procs.list'(): ProcessInfo[];
146
+ 'procs.kill'(pid: number): boolean;
147
+ /**
148
+ * A port to the box's kernel itself, speaking its full internal protocol:
149
+ * for app UIs that need more than this API. Versioned with the runtime.
150
+ */
151
+ 'kernel.connect'(): KernelChannel;
152
+ /** A second connection to this box (its own shells and processes), e.g. for a worker. */
153
+ share(): MessagePort;
84
154
  exec(command: string, opts?: ExecOptions): ExecResult;
85
155
  /** Starts a command; its output and exit arrive as events. Returns its process id. */
86
156
  spawn(command: string, opts?: ExecOptions): number;
@@ -101,5 +171,6 @@ export type FromRuntime =
101
171
  | { t: 'result'; id: number; ok: true; value: unknown }
102
172
  | { t: 'result'; id: number; ok: false; error: string; code?: string }
103
173
  | { t: 'output'; pid: number; stream: 'stdout' | 'stderr'; data: string }
104
- | { t: 'exit'; pid: number; exitCode: number }
174
+ /** `cwd`: for commands run in a shell session, its working folder afterwards. */
175
+ | { t: 'exit'; pid: number; exitCode: number; cwd?: string }
105
176
  | { t: 'permission'; id: number; request: PermissionRequest };