@jeevanand/agent-browserbox-runtime 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 +18 -0
- package/dist/assets/{bridge-DY2WnNx7.js → bridge-BEwLXp_5.js} +2 -2
- package/dist/assets/{build-BNa5TW3M.js → build-DqisMe_5.js} +2 -2
- package/dist/assets/bundle-qe7w2kMM.js +1 -0
- package/dist/assets/{dev-impl-BRiXVAGb.js → dev-impl-DLIrrRxu.js} +4 -4
- package/dist/assets/embed-CqexLx9X.js +3 -0
- package/dist/assets/{html-R2xYS1Rp.js → html-BggiUWIu.js} +3 -3
- package/dist/assets/{instance-CppC8T8t.js → instance-6eYt0v1_.js} +1 -1
- package/dist/assets/main-DzFuvDws.js +371 -0
- package/dist/assets/path-DGG-Mxbd.js +1 -0
- package/dist/assets/{pkg-esbuild-BuQjm7dB.js → pkg-esbuild-QrU0ybpL.js} +1 -1
- package/dist/assets/{pkg-git-jawfIVoq.js → pkg-git-BQFdAkWZ.js} +9 -9
- package/dist/assets/pkg-python-ytZLbJ8W.js +6 -0
- package/dist/assets/{pkg-sqlite-BexM5lLo.js → pkg-sqlite-CKGWzcwt.js} +1 -1
- package/dist/assets/pkg-zip-CL-568aV.js +1 -0
- package/dist/assets/rolldown-runtime-WkwZ5CU-.js +1 -0
- package/dist/assets/server-B0hTONK2.js +4 -0
- package/dist/embed/index.html +5 -5
- package/dist/kernel/bridge.html +2 -2
- package/dist/kernel/packages.json +1 -1
- package/lib/client/connect.d.ts +23 -0
- package/lib/client/connect.js +64 -0
- package/lib/client/index.d.ts +23 -0
- package/lib/client/index.js +16 -0
- package/lib/client/remote-kernel.d.ts +53 -0
- package/lib/client/remote-kernel.js +315 -0
- package/lib/config/origins.d.ts +13 -0
- package/lib/config/origins.js +35 -0
- package/lib/kernel/api.d.ts +145 -0
- package/lib/kernel/api.js +1 -0
- package/lib/kernel/bus.d.ts +6 -0
- package/lib/kernel/bus.js +24 -0
- package/lib/kernel/caps.d.ts +10 -0
- package/lib/kernel/caps.js +50 -0
- package/lib/kernel/dev/types.d.ts +71 -0
- package/lib/kernel/dev/types.js +8 -0
- package/lib/kernel/filetypes.d.ts +9 -0
- package/lib/kernel/filetypes.js +74 -0
- package/lib/kernel/format.d.ts +3 -0
- package/lib/kernel/format.js +23 -0
- package/lib/kernel/instance.d.ts +22 -0
- package/lib/kernel/instance.js +29 -0
- package/lib/kernel/kcore.d.ts +26 -0
- package/lib/kernel/kcore.js +105 -0
- package/lib/kernel/kcore.wasm +0 -0
- package/lib/kernel/paths.d.ts +3 -0
- package/lib/kernel/paths.js +3 -0
- package/lib/kernel/perms.d.ts +35 -0
- package/lib/kernel/perms.js +42 -0
- package/lib/kernel/proc.d.ts +45 -0
- package/lib/kernel/proc.js +69 -0
- package/lib/kernel/settings.d.ts +29 -0
- package/lib/kernel/settings.js +94 -0
- package/lib/kernel/types.d.ts +48 -0
- package/lib/kernel/types.js +1 -0
- package/lib/kernel/vfs/path.d.ts +11 -0
- package/lib/kernel/vfs/path.js +72 -0
- package/lib/kernel/vfs/types.d.ts +34 -0
- package/lib/kernel/vfs/types.js +17 -0
- package/lib/kernel-worker/wire.d.ts +38 -0
- package/lib/kernel-worker/wire.js +2 -0
- package/lib/rpc/peer.d.ts +12 -0
- package/lib/rpc/peer.js +85 -0
- package/lib/sandbox/isolation.d.ts +8 -0
- package/lib/sandbox/isolation.js +12 -0
- package/lib/shell/ansi.d.ts +15 -0
- package/lib/shell/ansi.js +23 -0
- package/package.json +8 -3
- package/dist/assets/anthropic-S3ckT02t.js +0 -17
- package/dist/assets/bundle-8opp8__C.js +0 -1
- package/dist/assets/embed-CMbAHE2J.js +0 -3
- package/dist/assets/github-Dwhv0h55.js +0 -2
- package/dist/assets/lib-aA6_aWm_.js +0 -68
- package/dist/assets/main-VEpSfsM_.js +0 -482
- package/dist/assets/node.browser-1OJr47If.js +0 -1
- package/dist/assets/node.browser-cOXEGsLT.js +0 -1
- package/dist/assets/openai-CThAXVqN.js +0 -3
- package/dist/assets/pkg-python-CoNK0IjJ.js +0 -6
- package/dist/assets/pkg-zip-BdZ_Lkdk.js +0 -1
- package/dist/assets/publish-CHt_Qrq5.js +0 -2
- package/dist/assets/publish-impl-BqjdM7Ux.js +0 -7
- package/dist/assets/rolldown-runtime-XKyaHtl9.js +0 -1
- package/dist/assets/server-C5Sd62CK.js +0 -4
- package/dist/assets/webllm-wsrhCAP4.js +0 -11
- package/dist/icon.svg +0 -1
- package/dist/manifest.webmanifest +0 -10
- package/dist/preview/frame.html +0 -27
- package/dist/sw.js +0 -73
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settings: small JSON values, readable synchronously from an in-memory map.
|
|
3
|
+
* The kernel persists them (IndexedDB); each window holds a replica that is
|
|
4
|
+
* hydrated on connect and kept current by change events.
|
|
5
|
+
*/
|
|
6
|
+
export class Settings {
|
|
7
|
+
bus;
|
|
8
|
+
onWrite;
|
|
9
|
+
#values = new Map();
|
|
10
|
+
constructor(bus,
|
|
11
|
+
/** Called for local writes: the kernel persists, a window forwards to the kernel. */
|
|
12
|
+
onWrite) {
|
|
13
|
+
this.bus = bus;
|
|
14
|
+
this.onWrite = onWrite;
|
|
15
|
+
}
|
|
16
|
+
/** Replaces all values without firing per-key writes. */
|
|
17
|
+
hydrate(entries) {
|
|
18
|
+
this.#values = new Map(entries);
|
|
19
|
+
for (const [key, value] of entries)
|
|
20
|
+
this.bus.emit('settings:change', { key, value });
|
|
21
|
+
}
|
|
22
|
+
entries() {
|
|
23
|
+
return [...this.#values];
|
|
24
|
+
}
|
|
25
|
+
get(key, fallback) {
|
|
26
|
+
return this.#values.has(key) ? this.#values.get(key) : fallback;
|
|
27
|
+
}
|
|
28
|
+
set(key, value) {
|
|
29
|
+
this.applyRemote(key, value);
|
|
30
|
+
this.onWrite?.(key, value);
|
|
31
|
+
}
|
|
32
|
+
delete(key) {
|
|
33
|
+
this.set(key, undefined);
|
|
34
|
+
}
|
|
35
|
+
/** Applies a change that originated elsewhere (no write-back). */
|
|
36
|
+
applyRemote(key, value) {
|
|
37
|
+
if (value === undefined)
|
|
38
|
+
this.#values.delete(key);
|
|
39
|
+
else
|
|
40
|
+
this.#values.set(key, value);
|
|
41
|
+
this.bus.emit('settings:change', { key, value });
|
|
42
|
+
}
|
|
43
|
+
keys() {
|
|
44
|
+
return [...this.#values.keys()];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// ---- Persistence (kernel side) ------------------------------------------------
|
|
48
|
+
export const SETTINGS_DB = 'bbx-settings';
|
|
49
|
+
const STORE = 'kv';
|
|
50
|
+
function open(db) {
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
const req = indexedDB.open(db, 1);
|
|
53
|
+
req.onupgradeneeded = () => req.result.createObjectStore(STORE);
|
|
54
|
+
req.onsuccess = () => resolve(req.result);
|
|
55
|
+
req.onerror = () => reject(req.error);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/** `db` null: nothing is stored (an in-memory box). */
|
|
59
|
+
export async function loadSettings(dbName = SETTINGS_DB) {
|
|
60
|
+
if (dbName === null)
|
|
61
|
+
return [];
|
|
62
|
+
try {
|
|
63
|
+
const db = await open(dbName);
|
|
64
|
+
return await new Promise((resolve, reject) => {
|
|
65
|
+
const out = [];
|
|
66
|
+
const req = db.transaction(STORE, 'readonly').objectStore(STORE).openCursor();
|
|
67
|
+
req.onsuccess = () => {
|
|
68
|
+
const c = req.result;
|
|
69
|
+
if (!c)
|
|
70
|
+
return resolve(out);
|
|
71
|
+
out.push([String(c.key), c.value]);
|
|
72
|
+
c.continue();
|
|
73
|
+
};
|
|
74
|
+
req.onerror = () => reject(req.error);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return []; // storage unavailable: settings last for this session only
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export async function persistSetting(key, value, dbName = SETTINGS_DB) {
|
|
82
|
+
if (dbName === null)
|
|
83
|
+
return;
|
|
84
|
+
try {
|
|
85
|
+
const store = (await open(dbName)).transaction(STORE, 'readwrite').objectStore(STORE);
|
|
86
|
+
if (value === undefined)
|
|
87
|
+
store.delete(key);
|
|
88
|
+
else
|
|
89
|
+
store.put(value, key);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
/* not persisted */
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { DevInfo, DevLog } from './dev/types';
|
|
2
|
+
import type { Proc } from './proc';
|
|
3
|
+
export interface FsChange {
|
|
4
|
+
path: string;
|
|
5
|
+
type: 'write' | 'remove' | 'mkdir' | 'mount';
|
|
6
|
+
}
|
|
7
|
+
export interface KernelLogLine {
|
|
8
|
+
/** Milliseconds since the kernel started. */
|
|
9
|
+
t: number;
|
|
10
|
+
src: string;
|
|
11
|
+
msg: string;
|
|
12
|
+
}
|
|
13
|
+
export interface Notice {
|
|
14
|
+
title: string;
|
|
15
|
+
body?: string;
|
|
16
|
+
level?: 'info' | 'ok' | 'warn' | 'error';
|
|
17
|
+
}
|
|
18
|
+
/** Every event that can cross module boundaries. */
|
|
19
|
+
export interface KernelEvents extends Record<string, unknown> {
|
|
20
|
+
'fs:change': FsChange;
|
|
21
|
+
'proc:spawn': Proc;
|
|
22
|
+
'proc:update': Proc;
|
|
23
|
+
'proc:exit': {
|
|
24
|
+
proc: Proc;
|
|
25
|
+
reason: string;
|
|
26
|
+
};
|
|
27
|
+
'settings:change': {
|
|
28
|
+
key: string;
|
|
29
|
+
value: unknown;
|
|
30
|
+
};
|
|
31
|
+
notify: Notice;
|
|
32
|
+
/** A line was added to the kernel log. */
|
|
33
|
+
kmsg: KernelLogLine;
|
|
34
|
+
/** Ask the shell UI to launch an app. */
|
|
35
|
+
/** `fromWindow`: raised by a GUI window (e.g. the desktop), not by the kernel, the shell or the agent. */
|
|
36
|
+
'app:open': {
|
|
37
|
+
id: string;
|
|
38
|
+
args?: Record<string, unknown>;
|
|
39
|
+
fromWindow?: boolean;
|
|
40
|
+
};
|
|
41
|
+
/** Dev servers started or stopped. */
|
|
42
|
+
'dev:update': DevInfo[];
|
|
43
|
+
/** A dev server recorded output (page console, backend, build, network). */
|
|
44
|
+
'dev:log': {
|
|
45
|
+
port: number;
|
|
46
|
+
entry: DevLog;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** POSIX-style path helpers. All VFS paths are absolute and normalized. */
|
|
2
|
+
export declare function normalize(path: string): string;
|
|
3
|
+
export declare function resolve(cwd: string, path: string): string;
|
|
4
|
+
export declare function dirname(path: string): string;
|
|
5
|
+
export declare function basename(path: string): string;
|
|
6
|
+
export declare function extname(path: string): string;
|
|
7
|
+
export declare function join(...parts: string[]): string;
|
|
8
|
+
/** True when `path` is `root` or lives underneath it. */
|
|
9
|
+
export declare function isInside(root: string, path: string): boolean;
|
|
10
|
+
/** Converts a glob (`*`, `**`, `?`, `{a,b}`) to a RegExp over normalized paths. */
|
|
11
|
+
export declare function globToRegExp(glob: string): RegExp;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/** POSIX-style path helpers. All VFS paths are absolute and normalized. */
|
|
2
|
+
export function normalize(path) {
|
|
3
|
+
const out = [];
|
|
4
|
+
for (const part of path.split('/')) {
|
|
5
|
+
if (!part || part === '.')
|
|
6
|
+
continue;
|
|
7
|
+
if (part === '..')
|
|
8
|
+
out.pop();
|
|
9
|
+
else
|
|
10
|
+
out.push(part);
|
|
11
|
+
}
|
|
12
|
+
return '/' + out.join('/');
|
|
13
|
+
}
|
|
14
|
+
export function resolve(cwd, path) {
|
|
15
|
+
if (!path)
|
|
16
|
+
return normalize(cwd);
|
|
17
|
+
return normalize(path.startsWith('/') ? path : `${cwd}/${path}`);
|
|
18
|
+
}
|
|
19
|
+
export function dirname(path) {
|
|
20
|
+
const p = normalize(path);
|
|
21
|
+
const i = p.lastIndexOf('/');
|
|
22
|
+
return i <= 0 ? '/' : p.slice(0, i);
|
|
23
|
+
}
|
|
24
|
+
export function basename(path) {
|
|
25
|
+
const p = normalize(path);
|
|
26
|
+
return p.slice(p.lastIndexOf('/') + 1);
|
|
27
|
+
}
|
|
28
|
+
export function extname(path) {
|
|
29
|
+
const b = basename(path);
|
|
30
|
+
const i = b.lastIndexOf('.');
|
|
31
|
+
return i <= 0 ? '' : b.slice(i + 1).toLowerCase();
|
|
32
|
+
}
|
|
33
|
+
export function join(...parts) {
|
|
34
|
+
return normalize(parts.join('/'));
|
|
35
|
+
}
|
|
36
|
+
/** True when `path` is `root` or lives underneath it. */
|
|
37
|
+
export function isInside(root, path) {
|
|
38
|
+
const r = normalize(root);
|
|
39
|
+
const p = normalize(path);
|
|
40
|
+
return r === '/' || p === r || p.startsWith(r + '/');
|
|
41
|
+
}
|
|
42
|
+
/** Converts a glob (`*`, `**`, `?`, `{a,b}`) to a RegExp over normalized paths. */
|
|
43
|
+
export function globToRegExp(glob) {
|
|
44
|
+
let re = '';
|
|
45
|
+
for (let i = 0; i < glob.length; i++) {
|
|
46
|
+
const c = glob[i];
|
|
47
|
+
if (c === '*') {
|
|
48
|
+
if (glob[i + 1] === '*') {
|
|
49
|
+
i++;
|
|
50
|
+
if (glob[i + 1] === '/') {
|
|
51
|
+
i++;
|
|
52
|
+
re += '(?:.*/)?';
|
|
53
|
+
}
|
|
54
|
+
else
|
|
55
|
+
re += '.*';
|
|
56
|
+
}
|
|
57
|
+
else
|
|
58
|
+
re += '[^/]*';
|
|
59
|
+
}
|
|
60
|
+
else if (c === '?')
|
|
61
|
+
re += '[^/]';
|
|
62
|
+
else if (c === '{')
|
|
63
|
+
re += '(?:';
|
|
64
|
+
else if (c === '}')
|
|
65
|
+
re += ')';
|
|
66
|
+
else if (c === ',')
|
|
67
|
+
re += '|';
|
|
68
|
+
else
|
|
69
|
+
re += /[.+^$()|[\]\\]/.test(c) ? `\\${c}` : c;
|
|
70
|
+
}
|
|
71
|
+
return new RegExp(`^${re}$`);
|
|
72
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface Stat {
|
|
2
|
+
path: string;
|
|
3
|
+
name: string;
|
|
4
|
+
kind: 'file' | 'dir';
|
|
5
|
+
size: number;
|
|
6
|
+
mtime: number;
|
|
7
|
+
}
|
|
8
|
+
export declare class FsError extends Error {
|
|
9
|
+
readonly code: 'ENOENT' | 'EEXIST' | 'ENOTDIR' | 'EISDIR' | 'EACCES' | 'ENOTEMPTY' | 'EIO';
|
|
10
|
+
constructor(code: 'ENOENT' | 'EEXIST' | 'ENOTDIR' | 'EISDIR' | 'EACCES' | 'ENOTEMPTY' | 'EIO', path: string, detail?: string);
|
|
11
|
+
static text: {
|
|
12
|
+
readonly ENOENT: 'no such file or directory';
|
|
13
|
+
readonly EEXIST: 'file already exists';
|
|
14
|
+
readonly ENOTDIR: 'not a directory';
|
|
15
|
+
readonly EISDIR: 'is a directory';
|
|
16
|
+
readonly EACCES: 'permission denied';
|
|
17
|
+
readonly ENOTEMPTY: 'directory not empty';
|
|
18
|
+
readonly EIO: 'i/o error';
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A storage backend mounted somewhere in the VFS tree. Paths passed to a
|
|
23
|
+
* backend are relative to its mount point, normalized, and start with '/'.
|
|
24
|
+
*/
|
|
25
|
+
export interface FsBackend {
|
|
26
|
+
readonly label: string;
|
|
27
|
+
readonly readonly?: boolean;
|
|
28
|
+
readFile(path: string): Promise<Uint8Array>;
|
|
29
|
+
writeFile(path: string, data: Uint8Array): Promise<void>;
|
|
30
|
+
readdir(path: string): Promise<Stat[]>;
|
|
31
|
+
stat(path: string): Promise<Stat | null>;
|
|
32
|
+
mkdir(path: string): Promise<void>;
|
|
33
|
+
remove(path: string, recursive: boolean): Promise<void>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export class FsError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
constructor(code, path, detail) {
|
|
4
|
+
super(`${code}: ${detail ?? FsError.text[code]}, '${path}'`);
|
|
5
|
+
this.code = code;
|
|
6
|
+
this.name = 'FsError';
|
|
7
|
+
}
|
|
8
|
+
static text = {
|
|
9
|
+
ENOENT: 'no such file or directory',
|
|
10
|
+
EEXIST: 'file already exists',
|
|
11
|
+
ENOTDIR: 'not a directory',
|
|
12
|
+
EISDIR: 'is a directory',
|
|
13
|
+
EACCES: 'permission denied',
|
|
14
|
+
ENOTEMPTY: 'directory not empty',
|
|
15
|
+
EIO: 'i/o error',
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Proc } from '../kernel/proc';
|
|
2
|
+
import type { KernelLogLine } from '../kernel/types';
|
|
3
|
+
/**
|
|
4
|
+
* The kernel protocol's message types, shared by the kernel server and its
|
|
5
|
+
* clients (RemoteKernel). Types only, so a client does not pull in the kernel.
|
|
6
|
+
*/
|
|
7
|
+
/** What a window receives when it connects. */
|
|
8
|
+
export interface Hello {
|
|
9
|
+
clientId: number;
|
|
10
|
+
/** Pids this client may allocate for its own processes start here. */
|
|
11
|
+
pidBase: number;
|
|
12
|
+
version: string;
|
|
13
|
+
rootKind: 'opfs' | 'memory';
|
|
14
|
+
shared: boolean;
|
|
15
|
+
settings: Array<[string, unknown]>;
|
|
16
|
+
procs: WireProc[];
|
|
17
|
+
mounts: Array<{
|
|
18
|
+
point: string;
|
|
19
|
+
label: string;
|
|
20
|
+
readonly: boolean;
|
|
21
|
+
}>;
|
|
22
|
+
bootMarks: Array<{
|
|
23
|
+
name: string;
|
|
24
|
+
at: number;
|
|
25
|
+
}>;
|
|
26
|
+
log: KernelLogLine[];
|
|
27
|
+
}
|
|
28
|
+
/** Each window allocates pids for its own processes from a private block. */
|
|
29
|
+
export declare const PID_BLOCK = 100000;
|
|
30
|
+
export type WireProc = Omit<Proc, 'signal'>;
|
|
31
|
+
export type AskKind = 'perm' | 'user' | 'tty' | 'ui';
|
|
32
|
+
export interface Ask {
|
|
33
|
+
askId: number;
|
|
34
|
+
kind: AskKind;
|
|
35
|
+
sid?: string;
|
|
36
|
+
shellId?: string;
|
|
37
|
+
payload: unknown;
|
|
38
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type Handlers = Record<string, (...args: never[]) => unknown>;
|
|
2
|
+
export declare class Peer {
|
|
3
|
+
#private;
|
|
4
|
+
private port;
|
|
5
|
+
closed: boolean;
|
|
6
|
+
constructor(port: MessagePort);
|
|
7
|
+
handle(handlers: Handlers): this;
|
|
8
|
+
call<T = unknown>(method: string, ...args: unknown[]): Promise<T>;
|
|
9
|
+
emit(name: string, payload?: unknown): void;
|
|
10
|
+
on<P = unknown>(name: string, fn: (payload: P) => void): () => void;
|
|
11
|
+
close(): void;
|
|
12
|
+
}
|
package/lib/rpc/peer.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export class Peer {
|
|
2
|
+
port;
|
|
3
|
+
#next = 1;
|
|
4
|
+
#pending = new Map();
|
|
5
|
+
#handlers = {};
|
|
6
|
+
#listeners = new Map();
|
|
7
|
+
closed = false;
|
|
8
|
+
constructor(port) {
|
|
9
|
+
this.port = port;
|
|
10
|
+
port.onmessage = (e) => void this.#receive(e.data);
|
|
11
|
+
}
|
|
12
|
+
handle(handlers) {
|
|
13
|
+
Object.assign(this.#handlers, handlers);
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
call(method, ...args) {
|
|
17
|
+
if (this.closed)
|
|
18
|
+
return Promise.reject(new Error('connection closed'));
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
const id = this.#next++;
|
|
21
|
+
this.#pending.set(id, { resolve: resolve, reject });
|
|
22
|
+
this.port.postMessage({ k: 'call', id, m: method, a: args });
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
emit(name, payload) {
|
|
26
|
+
if (!this.closed)
|
|
27
|
+
this.port.postMessage({ k: 'evt', n: name, p: payload });
|
|
28
|
+
}
|
|
29
|
+
on(name, fn) {
|
|
30
|
+
let set = this.#listeners.get(name);
|
|
31
|
+
if (!set)
|
|
32
|
+
this.#listeners.set(name, (set = new Set()));
|
|
33
|
+
set.add(fn);
|
|
34
|
+
return () => set.delete(fn);
|
|
35
|
+
}
|
|
36
|
+
close() {
|
|
37
|
+
if (this.closed)
|
|
38
|
+
return;
|
|
39
|
+
this.closed = true;
|
|
40
|
+
this.port.close();
|
|
41
|
+
for (const p of this.#pending.values())
|
|
42
|
+
p.reject(new Error('connection closed'));
|
|
43
|
+
this.#pending.clear();
|
|
44
|
+
}
|
|
45
|
+
async #receive(msg) {
|
|
46
|
+
if (msg.k === 'call') {
|
|
47
|
+
const fn = Object.hasOwn(this.#handlers, msg.m) ? this.#handlers[msg.m] : undefined;
|
|
48
|
+
try {
|
|
49
|
+
if (!fn)
|
|
50
|
+
throw new Error(`unknown method: ${msg.m}`);
|
|
51
|
+
const v = await fn(...msg.a);
|
|
52
|
+
if (!this.closed)
|
|
53
|
+
this.port.postMessage({ k: 'ok', id: msg.id, v });
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
const e = err;
|
|
57
|
+
if (!this.closed)
|
|
58
|
+
this.port.postMessage({ k: 'err', id: msg.id, e: { name: e?.name ?? 'Error', message: e?.message ?? String(err) } });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else if (msg.k === 'ok' || msg.k === 'err') {
|
|
62
|
+
const p = this.#pending.get(msg.id);
|
|
63
|
+
this.#pending.delete(msg.id);
|
|
64
|
+
if (!p)
|
|
65
|
+
return;
|
|
66
|
+
if (msg.k === 'ok')
|
|
67
|
+
p.resolve(msg.v);
|
|
68
|
+
else {
|
|
69
|
+
const e = new Error(msg.e.message);
|
|
70
|
+
e.name = msg.e.name;
|
|
71
|
+
p.reject(e);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else if (msg.k === 'evt') {
|
|
75
|
+
for (const fn of [...(this.#listeners.get(msg.n) ?? [])]) {
|
|
76
|
+
try {
|
|
77
|
+
fn(msg.p);
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
console.error(`[rpc] listener for "${msg.n}" threw`, err);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frames inside a cross-origin isolated page (Settings → Environment) must be
|
|
3
|
+
* isolated too, or they do not load. Sandboxes, previews and web pages we
|
|
4
|
+
* embed are not, so they are marked credentialless (no cookies or storage of
|
|
5
|
+
* their own), which lets an isolated page embed them.
|
|
6
|
+
* Call before setting src; pass the URL when it is known.
|
|
7
|
+
*/
|
|
8
|
+
export declare function embeddable<T extends HTMLIFrameElement>(frame: T, _url?: string): T;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frames inside a cross-origin isolated page (Settings → Environment) must be
|
|
3
|
+
* isolated too, or they do not load. Sandboxes, previews and web pages we
|
|
4
|
+
* embed are not, so they are marked credentialless (no cookies or storage of
|
|
5
|
+
* their own), which lets an isolated page embed them.
|
|
6
|
+
* Call before setting src; pass the URL when it is known.
|
|
7
|
+
*/
|
|
8
|
+
export function embeddable(frame, _url) {
|
|
9
|
+
if (globalThis.crossOriginIsolated)
|
|
10
|
+
frame.setAttribute('credentialless', '');
|
|
11
|
+
return frame;
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** ANSI SGR colour codes understood by the Terminal app. */
|
|
2
|
+
export declare const C: {
|
|
3
|
+
readonly reset: '\u001B[0m';
|
|
4
|
+
readonly bold: '\u001B[1m';
|
|
5
|
+
readonly dim: '\u001B[2m';
|
|
6
|
+
readonly red: '\u001B[31m';
|
|
7
|
+
readonly green: '\u001B[32m';
|
|
8
|
+
readonly yellow: '\u001B[33m';
|
|
9
|
+
readonly blue: '\u001B[34m';
|
|
10
|
+
readonly magenta: '\u001B[35m';
|
|
11
|
+
readonly cyan: '\u001B[36m';
|
|
12
|
+
};
|
|
13
|
+
export declare function stripAnsi(text: string): string;
|
|
14
|
+
/** Removes colour codes and applies carriage returns, giving the text a program would read. */
|
|
15
|
+
export declare function plainText(text: string): string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** ANSI SGR colour codes understood by the Terminal app. */
|
|
2
|
+
export const C = {
|
|
3
|
+
reset: '\x1b[0m',
|
|
4
|
+
bold: '\x1b[1m',
|
|
5
|
+
dim: '\x1b[2m',
|
|
6
|
+
red: '\x1b[31m',
|
|
7
|
+
green: '\x1b[32m',
|
|
8
|
+
yellow: '\x1b[33m',
|
|
9
|
+
blue: '\x1b[34m',
|
|
10
|
+
magenta: '\x1b[35m',
|
|
11
|
+
cyan: '\x1b[36m',
|
|
12
|
+
};
|
|
13
|
+
export function stripAnsi(text) {
|
|
14
|
+
return text.replace(/\x1b\[[0-9;]*m/g, '');
|
|
15
|
+
}
|
|
16
|
+
/** Removes colour codes and applies carriage returns, giving the text a program would read. */
|
|
17
|
+
export function plainText(text) {
|
|
18
|
+
return text
|
|
19
|
+
.replace(/\x1b\[[0-9;]*m/g, '')
|
|
20
|
+
.split('\n')
|
|
21
|
+
.map((l) => l.slice(l.lastIndexOf('\r') + 1))
|
|
22
|
+
.join('\n');
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jeevanand/agent-browserbox-runtime",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "The
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "The runtime for @jeevanand/agent-browserbox-sdk: static files to serve (kernel, filesystem, shell, sandboxes), and a client library for app UIs that drive its kernel (/client).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
7
7
|
"types": "./index.d.ts",
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./index.d.ts",
|
|
11
11
|
"import": "./index.js"
|
|
12
|
+
},
|
|
13
|
+
"./client": {
|
|
14
|
+
"types": "./lib/client/index.d.ts",
|
|
15
|
+
"import": "./lib/client/index.js"
|
|
12
16
|
}
|
|
13
17
|
},
|
|
14
18
|
"bin": {
|
|
@@ -16,6 +20,7 @@
|
|
|
16
20
|
},
|
|
17
21
|
"files": [
|
|
18
22
|
"dist",
|
|
23
|
+
"lib",
|
|
19
24
|
"bin",
|
|
20
25
|
"index.js",
|
|
21
26
|
"index.d.ts",
|
|
@@ -47,7 +52,7 @@
|
|
|
47
52
|
"node": ">=18"
|
|
48
53
|
},
|
|
49
54
|
"scripts": {
|
|
50
|
-
"build": "
|
|
55
|
+
"build": "vite build --config vite.config.ts && rm -rf lib && tsc -p tsconfig.client.json && node -e \"require('fs').copyFileSync('src/kernel/kcore.wasm','lib/kernel/kcore.wasm')\"",
|
|
51
56
|
"prepack": "npm run build"
|
|
52
57
|
}
|
|
53
58
|
}
|