@jeevanand/agent-browserbox-sdk 0.1.1 → 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 +19 -0
- package/dist/index.d.ts +92 -6
- package/dist/index.js +147 -9
- package/dist/index.js.map +1 -1
- package/dist/protocol.d.ts +82 -2
- package/package.json +1 -1
- package/src/index.ts +182 -16
- package/src/protocol.ts +73 -2
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,14 +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
4
|
/** This SDK's version. Always released together with the runtime of the same version. */
|
|
5
|
-
export declare const VERSION = "0.
|
|
5
|
+
export declare const VERSION = "0.2.0";
|
|
6
6
|
/**
|
|
7
7
|
* The hosted runtime of exactly this SDK's version. Released runtimes never
|
|
8
8
|
* change, so a newer runtime can never break an app on this SDK. Self-host it
|
|
9
9
|
* with @jeevanand/agent-browserbox-runtime.
|
|
10
10
|
*/
|
|
11
|
-
export declare const DEFAULT_RUNTIME_URL = "https://jeevanandmaurya.github.io/agent-browserbox/runtime/0.
|
|
11
|
+
export declare const DEFAULT_RUNTIME_URL = "https://jeevanandmaurya.github.io/agent-browserbox/runtime/0.2.0/";
|
|
12
12
|
export type PermissionHandler = (request: PermissionRequest) => PermissionDecision | Promise<PermissionDecision>;
|
|
13
13
|
export interface BootOptions {
|
|
14
14
|
/** Base URL of the runtime (the folder holding embed/, kernel/, assets/). Default: the hosted runtime. */
|
|
@@ -22,6 +22,13 @@ export interface BootOptions {
|
|
|
22
22
|
id?: string;
|
|
23
23
|
/** 'persistent' (default): files survive reloads. 'memory': everything is gone when the box is torn down. */
|
|
24
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;
|
|
25
32
|
/** Element the hidden runtime frame is added to. Default: document.body. */
|
|
26
33
|
container?: HTMLElement;
|
|
27
34
|
/**
|
|
@@ -41,7 +48,7 @@ interface Sink {
|
|
|
41
48
|
out: ReadableStreamDefaultController<string>[];
|
|
42
49
|
stdout: ReadableStreamDefaultController<string>[];
|
|
43
50
|
stderr: ReadableStreamDefaultController<string>[];
|
|
44
|
-
exit(code: number): void;
|
|
51
|
+
exit(code: number, cwd?: string): void;
|
|
45
52
|
}
|
|
46
53
|
/** A running command in the box. */
|
|
47
54
|
export declare class BoxProcess {
|
|
@@ -54,10 +61,31 @@ export declare class BoxProcess {
|
|
|
54
61
|
/** Resolves with the exit code (124: timed out, 130: killed). */
|
|
55
62
|
readonly exit: Promise<number>;
|
|
56
63
|
/** @internal */
|
|
57
|
-
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);
|
|
58
65
|
/** Stops the command. Resolves false if it had already finished. */
|
|
59
66
|
kill(): Promise<boolean>;
|
|
60
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
|
+
}
|
|
61
89
|
/** The box's filesystem. Paths are absolute, or relative to the box's home. */
|
|
62
90
|
export declare class BoxFs {
|
|
63
91
|
#private;
|
|
@@ -79,6 +107,35 @@ export declare class BoxFs {
|
|
|
79
107
|
}): Promise<void>;
|
|
80
108
|
rename(from: string, to: string): Promise<void>;
|
|
81
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[]>;
|
|
82
139
|
}
|
|
83
140
|
/**
|
|
84
141
|
* A sandboxed computer in the browser: a filesystem, a shell, and JavaScript,
|
|
@@ -92,6 +149,7 @@ export declare class BoxFs {
|
|
|
92
149
|
export declare class BrowserBox {
|
|
93
150
|
#private;
|
|
94
151
|
readonly fs: BoxFs;
|
|
152
|
+
readonly dev: BoxDev;
|
|
95
153
|
/** Runtime version. */
|
|
96
154
|
readonly version: string;
|
|
97
155
|
/** This box's id. */
|
|
@@ -109,6 +167,34 @@ export declare class BrowserBox {
|
|
|
109
167
|
exec(command: string, opts?: ExecOptions): Promise<ExecResult>;
|
|
110
168
|
/** Starts a shell command line and streams its output. */
|
|
111
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;
|
|
112
198
|
/** Shuts the box down: removes its frame and fails anything still pending. */
|
|
113
199
|
teardown(): void;
|
|
114
200
|
/** @internal Low-level call into the runtime. */
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PROTOCOL_VERSION, } from './protocol.js';
|
|
2
2
|
export { PROTOCOL_VERSION };
|
|
3
3
|
/** This SDK's version. Always released together with the runtime of the same version. */
|
|
4
|
-
export const VERSION = '0.
|
|
4
|
+
export const VERSION = '0.2.0';
|
|
5
5
|
/**
|
|
6
6
|
* The hosted runtime of exactly this SDK's version. Released runtimes never
|
|
7
7
|
* change, so a newer runtime can never break an app on this SDK. Self-host it
|
|
@@ -28,7 +28,7 @@ export class BoxProcess {
|
|
|
28
28
|
/** Resolves with the exit code (124: timed out, 130: killed). */
|
|
29
29
|
exit;
|
|
30
30
|
/** @internal */
|
|
31
|
-
constructor(pid, box, attach) {
|
|
31
|
+
constructor(pid, box, attach, onExit) {
|
|
32
32
|
this.pid = pid;
|
|
33
33
|
this.box = box;
|
|
34
34
|
const sink = { out: [], stdout: [], stderr: [], exit: () => undefined };
|
|
@@ -36,7 +36,7 @@ export class BoxProcess {
|
|
|
36
36
|
this.output = stream(sink.out);
|
|
37
37
|
this.stdout = stream(sink.stdout);
|
|
38
38
|
this.stderr = stream(sink.stderr);
|
|
39
|
-
this.exit = new Promise((resolve) => (sink.exit = resolve));
|
|
39
|
+
this.exit = new Promise((resolve) => (sink.exit = (code, cwd) => (onExit?.(code, cwd), resolve(code))));
|
|
40
40
|
attach(sink);
|
|
41
41
|
}
|
|
42
42
|
/** Stops the command. Resolves false if it had already finished. */
|
|
@@ -44,6 +44,55 @@ export class BoxProcess {
|
|
|
44
44
|
return this.box.call('kill', this.pid);
|
|
45
45
|
}
|
|
46
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
|
+
}
|
|
47
96
|
/** The box's filesystem. Paths are absolute, or relative to the box's home. */
|
|
48
97
|
export class BoxFs {
|
|
49
98
|
box;
|
|
@@ -87,6 +136,40 @@ export class BoxFs {
|
|
|
87
136
|
cp(from, to) {
|
|
88
137
|
return this.box.call('fs.cp', this.#abs(from), this.#abs(to));
|
|
89
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
|
+
}
|
|
90
173
|
}
|
|
91
174
|
/**
|
|
92
175
|
* A sandboxed computer in the browser: a filesystem, a shell, and JavaScript,
|
|
@@ -99,6 +182,7 @@ export class BoxFs {
|
|
|
99
182
|
*/
|
|
100
183
|
export class BrowserBox {
|
|
101
184
|
fs = new BoxFs(this);
|
|
185
|
+
dev = new BoxDev(this);
|
|
102
186
|
/** Runtime version. */
|
|
103
187
|
version;
|
|
104
188
|
/** This box's id. */
|
|
@@ -138,7 +222,7 @@ export class BrowserBox {
|
|
|
138
222
|
const id = opts.id ?? (memory ? `mem-${crypto.randomUUID()}` : 'default');
|
|
139
223
|
if (!/^[A-Za-z0-9_-]{1,64}$/.test(id))
|
|
140
224
|
return Promise.reject(new BoxError(`invalid box id "${id}": use letters, digits, '-' and '_' (at most 64)`));
|
|
141
|
-
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);
|
|
142
226
|
const permissions = typeof opts.permissions === 'function' ? opts.permissions : opts.permissions === 'allow' ? () => 'once' : () => 'deny';
|
|
143
227
|
const frame = document.createElement('iframe');
|
|
144
228
|
frame.src = src.href;
|
|
@@ -181,13 +265,67 @@ export class BrowserBox {
|
|
|
181
265
|
}
|
|
182
266
|
/** Starts a shell command line and streams its output. */
|
|
183
267
|
async spawn(command, opts) {
|
|
184
|
-
|
|
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) {
|
|
185
323
|
return new BoxProcess(pid, this, (sink) => {
|
|
186
324
|
this.#sinks.set(pid, sink);
|
|
187
325
|
for (const ev of this.#early.get(pid) ?? [])
|
|
188
326
|
this.#deliver(pid, ev);
|
|
189
327
|
this.#early.delete(pid);
|
|
190
|
-
});
|
|
328
|
+
}, onExit);
|
|
191
329
|
}
|
|
192
330
|
/** Shuts the box down: removes its frame and fails anything still pending. */
|
|
193
331
|
teardown() {
|
|
@@ -200,7 +338,7 @@ export class BrowserBox {
|
|
|
200
338
|
for (const pid of [...this.#sinks.keys()])
|
|
201
339
|
this.#deliver(pid, { t: 'exit', exitCode: 130 });
|
|
202
340
|
this.#port.close();
|
|
203
|
-
this.#frame
|
|
341
|
+
this.#frame?.remove();
|
|
204
342
|
}
|
|
205
343
|
/** @internal Low-level call into the runtime. */
|
|
206
344
|
call(method, ...args) {
|
|
@@ -226,7 +364,7 @@ export class BrowserBox {
|
|
|
226
364
|
case 'output':
|
|
227
365
|
return this.#route(msg.pid, { t: 'output', stream: msg.stream, data: msg.data });
|
|
228
366
|
case 'exit':
|
|
229
|
-
return this.#route(msg.pid, { t: 'exit', exitCode: msg.exitCode });
|
|
367
|
+
return this.#route(msg.pid, { t: 'exit', exitCode: msg.exitCode, cwd: msg.cwd });
|
|
230
368
|
case 'permission':
|
|
231
369
|
void Promise.resolve()
|
|
232
370
|
.then(() => this.#permissions(msg.request))
|
|
@@ -261,7 +399,7 @@ export class BrowserBox {
|
|
|
261
399
|
return each([...sink.out, ...sink[ev.stream]], (c) => c.enqueue(ev.data));
|
|
262
400
|
each([...sink.out, ...sink.stdout, ...sink.stderr], (c) => c.close());
|
|
263
401
|
this.#sinks.delete(pid);
|
|
264
|
-
sink.exit(ev.exitCode);
|
|
402
|
+
sink.exit(ev.exitCode, ev.cwd);
|
|
265
403
|
}
|
|
266
404
|
}
|
|
267
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,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B,yFAAyF;AACzF,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAE/B;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,8DAA8D,OAAO,GAAG,CAAC;AA2B5G,sFAAsF;AACtF,MAAM,OAAO,QAAS,SAAQ,KAAK;IAGtB,IAAI;IAFf,YACE,OAAe,EACN,IAAa;QAEtB,KAAK,CAAC,OAAO,CAAC,CAAC;oBAFN,IAAI;QAGb,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AAWD,oCAAoC;AACpC,MAAM,OAAO,UAAU;IAUV,GAAG;IACJ,GAAG;IAVb,kEAAkE;IACzD,MAAM,CAAyB;IAC/B,MAAM,CAAyB;IAC/B,MAAM,CAAyB;IACxC,iEAAiE;IACxD,IAAI,CAAkB;IAE/B,gBAAgB;IAChB,YACW,GAAW,EACZ,GAAe,EACvB,MAA4B;mBAFnB,GAAG;mBACJ,GAAG;QAGX,MAAM,IAAI,GAAS,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC;QAC9E,MAAM,MAAM,GAAG,CAAC,IAA+C,EAAE,EAAE,CAAC,IAAI,cAAc,CAAS,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,E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AAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;QACjG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;QACtE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;CACF"}
|
package/dist/protocol.d.ts
CHANGED
|
@@ -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.
|
|
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,11 @@ 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
22
|
/** This SDK's version. Always released together with the runtime of the same version. */
|
|
19
|
-
export const VERSION = '0.
|
|
23
|
+
export const VERSION = '0.2.0';
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
26
|
* The hosted runtime of exactly this SDK's version. Released runtimes never
|
|
@@ -39,6 +43,13 @@ export interface BootOptions {
|
|
|
39
43
|
id?: string;
|
|
40
44
|
/** 'persistent' (default): files survive reloads. 'memory': everything is gone when the box is torn down. */
|
|
41
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;
|
|
42
53
|
/** Element the hidden runtime frame is added to. Default: document.body. */
|
|
43
54
|
container?: HTMLElement;
|
|
44
55
|
/**
|
|
@@ -65,10 +76,10 @@ interface Sink {
|
|
|
65
76
|
out: ReadableStreamDefaultController<string>[];
|
|
66
77
|
stdout: ReadableStreamDefaultController<string>[];
|
|
67
78
|
stderr: ReadableStreamDefaultController<string>[];
|
|
68
|
-
exit(code: number): void;
|
|
79
|
+
exit(code: number, cwd?: string): void;
|
|
69
80
|
}
|
|
70
81
|
|
|
71
|
-
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 };
|
|
72
83
|
|
|
73
84
|
/** A running command in the box. */
|
|
74
85
|
export class BoxProcess {
|
|
@@ -84,13 +95,14 @@ export class BoxProcess {
|
|
|
84
95
|
readonly pid: number,
|
|
85
96
|
private box: BrowserBox,
|
|
86
97
|
attach: (sink: Sink) => void,
|
|
98
|
+
onExit?: (code: number, cwd?: string) => void,
|
|
87
99
|
) {
|
|
88
100
|
const sink: Sink = { out: [], stdout: [], stderr: [], exit: () => undefined };
|
|
89
101
|
const stream = (list: ReadableStreamDefaultController<string>[]) => new ReadableStream<string>({ start: (c) => void list.push(c) });
|
|
90
102
|
this.output = stream(sink.out);
|
|
91
103
|
this.stdout = stream(sink.stdout);
|
|
92
104
|
this.stderr = stream(sink.stderr);
|
|
93
|
-
this.exit = new Promise((resolve) => (sink.exit = resolve));
|
|
105
|
+
this.exit = new Promise((resolve) => (sink.exit = (code, cwd) => (onExit?.(code, cwd), resolve(code))));
|
|
94
106
|
attach(sink);
|
|
95
107
|
}
|
|
96
108
|
|
|
@@ -100,6 +112,61 @@ export class BoxProcess {
|
|
|
100
112
|
}
|
|
101
113
|
}
|
|
102
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
|
+
|
|
103
170
|
/** The box's filesystem. Paths are absolute, or relative to the box's home. */
|
|
104
171
|
export class BoxFs {
|
|
105
172
|
/** @internal */
|
|
@@ -142,6 +209,39 @@ export class BoxFs {
|
|
|
142
209
|
cp(from: string, to: string): Promise<void> {
|
|
143
210
|
return this.box.call('fs.cp', this.#abs(from), this.#abs(to));
|
|
144
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
|
+
}
|
|
145
245
|
}
|
|
146
246
|
|
|
147
247
|
/**
|
|
@@ -155,6 +255,7 @@ export class BoxFs {
|
|
|
155
255
|
*/
|
|
156
256
|
export class BrowserBox {
|
|
157
257
|
readonly fs = new BoxFs(this);
|
|
258
|
+
readonly dev = new BoxDev(this);
|
|
158
259
|
/** Runtime version. */
|
|
159
260
|
readonly version: string;
|
|
160
261
|
/** This box's id. */
|
|
@@ -167,7 +268,7 @@ export class BrowserBox {
|
|
|
167
268
|
readonly storage: 'opfs' | 'memory';
|
|
168
269
|
|
|
169
270
|
#port: MessagePort;
|
|
170
|
-
#frame: HTMLIFrameElement;
|
|
271
|
+
#frame: HTMLIFrameElement | null;
|
|
171
272
|
#permissions: PermissionHandler;
|
|
172
273
|
#nextId = 1;
|
|
173
274
|
#calls = new Map<number, { resolve(v: unknown): void; reject(e: Error): void }>();
|
|
@@ -176,7 +277,7 @@ export class BrowserBox {
|
|
|
176
277
|
#early = new Map<number, ProcEvent[]>();
|
|
177
278
|
#closed: BoxError | null = null;
|
|
178
279
|
|
|
179
|
-
private constructor(port: MessagePort, frame: HTMLIFrameElement, hello: Hello, permissions: PermissionHandler) {
|
|
280
|
+
private constructor(port: MessagePort, frame: HTMLIFrameElement | null, hello: Hello, permissions: PermissionHandler) {
|
|
180
281
|
this.#port = port;
|
|
181
282
|
this.#frame = frame;
|
|
182
283
|
this.#permissions = permissions;
|
|
@@ -195,7 +296,7 @@ export class BrowserBox {
|
|
|
195
296
|
const memory = opts.storage === 'memory';
|
|
196
297
|
const id = opts.id ?? (memory ? `mem-${crypto.randomUUID()}` : 'default');
|
|
197
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)`));
|
|
198
|
-
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);
|
|
199
300
|
const permissions: PermissionHandler = typeof opts.permissions === 'function' ? opts.permissions : opts.permissions === 'allow' ? () => 'once' : () => 'deny';
|
|
200
301
|
|
|
201
302
|
const frame = document.createElement('iframe');
|
|
@@ -239,14 +340,79 @@ export class BrowserBox {
|
|
|
239
340
|
|
|
240
341
|
/** Starts a shell command line and streams its output. */
|
|
241
342
|
async spawn(command: string, opts?: ExecOptions): Promise<BoxProcess> {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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();
|
|
247
366
|
});
|
|
248
367
|
}
|
|
249
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
|
+
|
|
250
416
|
/** Shuts the box down: removes its frame and fails anything still pending. */
|
|
251
417
|
teardown(): void {
|
|
252
418
|
if (this.#closed) return;
|
|
@@ -255,7 +421,7 @@ export class BrowserBox {
|
|
|
255
421
|
this.#calls.clear();
|
|
256
422
|
for (const pid of [...this.#sinks.keys()]) this.#deliver(pid, { t: 'exit', exitCode: 130 });
|
|
257
423
|
this.#port.close();
|
|
258
|
-
this.#frame
|
|
424
|
+
this.#frame?.remove();
|
|
259
425
|
}
|
|
260
426
|
|
|
261
427
|
/** @internal Low-level call into the runtime. */
|
|
@@ -280,7 +446,7 @@ export class BrowserBox {
|
|
|
280
446
|
case 'output':
|
|
281
447
|
return this.#route(msg.pid, { t: 'output', stream: msg.stream, data: msg.data });
|
|
282
448
|
case 'exit':
|
|
283
|
-
return this.#route(msg.pid, { t: 'exit', exitCode: msg.exitCode });
|
|
449
|
+
return this.#route(msg.pid, { t: 'exit', exitCode: msg.exitCode, cwd: msg.cwd });
|
|
284
450
|
case 'permission':
|
|
285
451
|
void Promise.resolve()
|
|
286
452
|
.then(() => this.#permissions(msg.request))
|
|
@@ -313,6 +479,6 @@ export class BrowserBox {
|
|
|
313
479
|
if (ev.t === 'output') return each([...sink.out, ...sink[ev.stream]], (c) => c.enqueue(ev.data));
|
|
314
480
|
each([...sink.out, ...sink.stdout, ...sink.stderr], (c) => c.close());
|
|
315
481
|
this.#sinks.delete(pid);
|
|
316
|
-
sink.exit(ev.exitCode);
|
|
482
|
+
sink.exit(ev.exitCode, ev.cwd);
|
|
317
483
|
}
|
|
318
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
|
-
|
|
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 };
|