@webpodjs/sdk 0.1.4 → 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 +12 -0
- package/dist/agent/backend.d.ts +13 -0
- package/dist/agent/backend.js +63 -0
- package/dist/agent/backend.js.map +1 -1
- package/dist/agent/protocol.d.ts +104 -1
- package/dist/agent/protocol.js +90 -0
- package/dist/agent/protocol.js.map +1 -1
- package/dist/exec/client.d.ts +41 -0
- package/dist/exec/client.js +401 -0
- package/dist/exec/client.js.map +1 -0
- package/dist/exec/frame.d.ts +1 -0
- package/dist/exec/frame.js +236 -0
- package/dist/exec/frame.js.map +1 -0
- package/dist/exec/options.d.ts +39 -0
- package/dist/exec/options.js +113 -0
- package/dist/exec/options.js.map +1 -0
- package/dist/exec/protocol.d.ts +2 -0
- package/dist/exec/protocol.js +3 -0
- package/dist/exec/protocol.js.map +1 -0
- package/dist/exec/wire.d.ts +49 -0
- package/dist/exec/wire.js +333 -0
- package/dist/exec/wire.js.map +1 -0
- package/dist/exec-frame.html +10 -0
- package/dist/fs/workspace.js +32 -7
- package/dist/fs/workspace.js.map +1 -1
- package/dist/host/backend.d.ts +14 -2
- package/dist/host/backend.js +69 -15
- package/dist/host/backend.js.map +1 -1
- package/dist/host/controller.d.ts +9 -0
- package/dist/host/controller.js +13 -3
- package/dist/host/controller.js.map +1 -1
- package/dist/host/devices.d.ts +29 -0
- package/dist/host/devices.js +102 -4
- package/dist/host/devices.js.map +1 -1
- package/dist/host-exec/controller.d.ts +255 -0
- package/dist/host-exec/controller.js +1176 -0
- package/dist/host-exec/controller.js.map +1 -0
- package/dist/host-exec/pipe.d.ts +21 -0
- package/dist/host-exec/pipe.js +83 -0
- package/dist/host-exec/pipe.js.map +1 -0
- package/dist/host-exec/preflight.d.ts +6 -0
- package/dist/host-exec/preflight.js +15 -0
- package/dist/host-exec/preflight.js.map +1 -0
- package/dist/host-exec/protocol.d.ts +340 -0
- package/dist/host-exec/protocol.js +16 -0
- package/dist/host-exec/protocol.js.map +1 -0
- package/dist/host-exec/route.d.ts +22 -0
- package/dist/host-exec/route.js +37 -0
- package/dist/host-exec/route.js.map +1 -0
- package/dist/host-exec/shim.d.ts +28 -0
- package/dist/host-exec/shim.js +456 -0
- package/dist/host-exec/shim.js.map +1 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/net/preview.d.ts +10 -2
- package/dist/net/preview.js +8 -0
- package/dist/net/preview.js.map +1 -1
- package/dist/pod.d.ts +22 -0
- package/dist/pod.js +129 -11
- package/dist/pod.js.map +1 -1
- package/dist/types.d.ts +35 -2
- package/dist/version.d.ts +1 -0
- package/dist/version.js +4 -0
- package/dist/version.js.map +1 -0
- package/package.json +6 -4
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
// The app's side of an execution origin (BootOptions.executionOrigin): a hidden cross-origin
|
|
2
|
+
// iframe (exec/frame.ts) runs the pods, and the Pod the app gets is backed by RemoteBackend, which
|
|
3
|
+
// forwards over the frame's control port. One frame per executionOrigin URL, shared by the pods
|
|
4
|
+
// booted with it, removed with the last one.
|
|
5
|
+
import { WebPodError } from "../errors.js";
|
|
6
|
+
import { visibleTimeout } from "../timers.js";
|
|
7
|
+
import { splitBootOptions } from "./options.js";
|
|
8
|
+
import { EXEC_PROTOCOL } from "./protocol.js";
|
|
9
|
+
import { routeTopLevel } from "../host-exec/route.js";
|
|
10
|
+
import { Rpc, readableFromPort, writableToPort } from "./wire.js";
|
|
11
|
+
/**
|
|
12
|
+
* pod.hostExec for a pod in an execution origin: the controller runs there (host Workers, their
|
|
13
|
+
* sessions, the shared node lib and wasm Modules); this side mirrors its status, sets `enabled`
|
|
14
|
+
* over the control port and relays its fallback events. The backend's spawn runs a request there,
|
|
15
|
+
* where the controller routes it; `runnerOf` tells the same route here for PodProcess.runner.
|
|
16
|
+
*/
|
|
17
|
+
class RemoteHostExec {
|
|
18
|
+
#listeners = new Set();
|
|
19
|
+
#state;
|
|
20
|
+
#setEnabled;
|
|
21
|
+
constructor(state, setEnabled) {
|
|
22
|
+
this.#state = state;
|
|
23
|
+
this.#setEnabled = setEnabled;
|
|
24
|
+
}
|
|
25
|
+
get status() {
|
|
26
|
+
return { ...this.#state.status, runners: [...this.#state.status.runners] };
|
|
27
|
+
}
|
|
28
|
+
get enabled() {
|
|
29
|
+
return this.#state.enabled;
|
|
30
|
+
}
|
|
31
|
+
set enabled(on) {
|
|
32
|
+
on = on === true && this.#state.status.node === "on";
|
|
33
|
+
if (on === this.#state.enabled)
|
|
34
|
+
return;
|
|
35
|
+
// At once here (spawns after this follow it), then confirmed by the execution origin.
|
|
36
|
+
this.#state = { ...this.#state, enabled: on };
|
|
37
|
+
void this.#setEnabled(on).then((s) => (this.#state = s), () => { });
|
|
38
|
+
}
|
|
39
|
+
on(event, listener) {
|
|
40
|
+
if (event !== "fallback")
|
|
41
|
+
throw new WebPodError("EINVAL", `unknown hostExec event: ${String(event)}`);
|
|
42
|
+
this.#listeners.add(listener);
|
|
43
|
+
return () => this.#listeners.delete(listener);
|
|
44
|
+
}
|
|
45
|
+
/** @internal A fallback event of the execution origin's controller. */
|
|
46
|
+
_fallback(e) {
|
|
47
|
+
for (const l of this.#listeners) {
|
|
48
|
+
try {
|
|
49
|
+
l(e);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// a listener's error is its own
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
spawn() {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
runnerOf(req) {
|
|
60
|
+
const { route } = this.#state;
|
|
61
|
+
if (!this.#state.enabled || !route)
|
|
62
|
+
return "guest";
|
|
63
|
+
return routeTopLevel(req, route)?.runner === "host" ? "host" : "guest";
|
|
64
|
+
}
|
|
65
|
+
async dispose() {
|
|
66
|
+
this.#listeners.clear();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const frames = new Map();
|
|
70
|
+
let nextKey = 1;
|
|
71
|
+
/** Milliseconds of visible time without an answer after which the frame counts as gone (crashed, hung). */
|
|
72
|
+
const PING_EVERY = 2000;
|
|
73
|
+
const DEAD_AFTER = 20000;
|
|
74
|
+
const ATTACH_TIMEOUT = 30000;
|
|
75
|
+
function hostOf(origin) {
|
|
76
|
+
return new URL(origin).hostname.replace(/^\[|\]$/g, "").toLowerCase();
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Same site as the app (a subdomain, another port of the same host)? Such an origin gets the app's
|
|
80
|
+
* SameSite cookies with its requests: refused. Without a public suffix list, two hosts that end in
|
|
81
|
+
* the same two labels are taken for one site unless the second last is short (co.uk, com.au, ...),
|
|
82
|
+
* which only warns.
|
|
83
|
+
*/
|
|
84
|
+
export function checkSite(appOrigin, execOrigin) {
|
|
85
|
+
const a = hostOf(appOrigin);
|
|
86
|
+
const b = hostOf(execOrigin);
|
|
87
|
+
if (a === b)
|
|
88
|
+
return "same";
|
|
89
|
+
const ip = (h) => /^[\d.]+$/.test(h) || h.includes(":");
|
|
90
|
+
if (ip(a) || ip(b))
|
|
91
|
+
return "other";
|
|
92
|
+
const la = a.split(".");
|
|
93
|
+
const lb = b.split(".");
|
|
94
|
+
if (la.length < 2 || lb.length < 2)
|
|
95
|
+
return "other";
|
|
96
|
+
const tail = (l) => l.slice(-2).join(".");
|
|
97
|
+
if (tail(la) !== tail(lb))
|
|
98
|
+
return "other";
|
|
99
|
+
const second = la[la.length - 2];
|
|
100
|
+
if (second.length <= 3 && la[la.length - 1].length === 2) {
|
|
101
|
+
// e.g. app.example.co.uk and exec.other.co.uk: one site only if the third last label matches too.
|
|
102
|
+
if (la.length < 3 || lb.length < 3)
|
|
103
|
+
return "unsure";
|
|
104
|
+
return la.slice(-3).join(".") === lb.slice(-3).join(".") ? "unsure" : "other";
|
|
105
|
+
}
|
|
106
|
+
return "same";
|
|
107
|
+
}
|
|
108
|
+
function attachFrame(url) {
|
|
109
|
+
const existing = frames.get(url);
|
|
110
|
+
if (existing)
|
|
111
|
+
return existing;
|
|
112
|
+
const p = openFrame(url);
|
|
113
|
+
frames.set(url, p);
|
|
114
|
+
p.catch(() => frames.delete(url));
|
|
115
|
+
return p;
|
|
116
|
+
}
|
|
117
|
+
async function openFrame(url) {
|
|
118
|
+
const doc = globalThis.document;
|
|
119
|
+
if (!doc)
|
|
120
|
+
throw new WebPodError("UNSUPPORTED", "executionOrigin needs a page (an iframe of the execution origin)");
|
|
121
|
+
const origin = new URL(url, location.href).origin;
|
|
122
|
+
if (origin === "null")
|
|
123
|
+
throw new WebPodError("EINVAL", `executionOrigin ${url}: not an http(s) URL`);
|
|
124
|
+
const site = checkSite(location.origin, origin);
|
|
125
|
+
if (site === "same")
|
|
126
|
+
throw new WebPodError("EINVAL", `executionOrigin ${origin} is the same site as this app (${location.origin}): it would get the app's cookies with its requests; use a site of its own`);
|
|
127
|
+
if (site === "unsure")
|
|
128
|
+
console.warn(`webpod: executionOrigin ${origin} may be the same site as ${location.origin}; use a site of its own`);
|
|
129
|
+
const iframe = doc.createElement("iframe");
|
|
130
|
+
iframe.title = "webpod execution origin";
|
|
131
|
+
iframe.allow = "cross-origin-isolated";
|
|
132
|
+
iframe.setAttribute("aria-hidden", "true");
|
|
133
|
+
iframe.style.cssText = "position:absolute;width:0;height:0;border:0;visibility:hidden";
|
|
134
|
+
iframe.src = new URL(url, location.href).href;
|
|
135
|
+
const { port1, port2 } = new MessageChannel();
|
|
136
|
+
let cleanup = () => { };
|
|
137
|
+
const ready = new Promise((resolve, reject) => {
|
|
138
|
+
const cancel = visibleTimeout(ATTACH_TIMEOUT, () => {
|
|
139
|
+
cleanup();
|
|
140
|
+
reject(new WebPodError("ENGINE_UNAVAILABLE", `execution origin ${url} did not answer (is it served, with CORP cross-origin and COEP, and does its CSP frame-ancestors list ${location.origin}?)`));
|
|
141
|
+
});
|
|
142
|
+
const onWindow = (event) => {
|
|
143
|
+
// Only that frame, from that origin; the attach message goes to that origin only.
|
|
144
|
+
if (event.source !== iframe.contentWindow || event.origin !== origin || event.data?.type !== "webpod-exec-loaded")
|
|
145
|
+
return;
|
|
146
|
+
removeEventListener("message", onWindow);
|
|
147
|
+
iframe.contentWindow.postMessage({ type: "webpod-exec-attach", version: EXEC_PROTOCOL }, origin, [port2]);
|
|
148
|
+
};
|
|
149
|
+
port1.onmessage = (e) => {
|
|
150
|
+
cleanup();
|
|
151
|
+
if (e.data?.type === "ready")
|
|
152
|
+
resolve({ crossOriginIsolated: e.data.crossOriginIsolated === true });
|
|
153
|
+
else
|
|
154
|
+
reject(new WebPodError("UNSUPPORTED", `execution origin ${url} refused this app: ${e.data?.message ?? "no reason"}`));
|
|
155
|
+
};
|
|
156
|
+
cleanup = () => {
|
|
157
|
+
cancel();
|
|
158
|
+
removeEventListener("message", onWindow);
|
|
159
|
+
};
|
|
160
|
+
addEventListener("message", onWindow);
|
|
161
|
+
});
|
|
162
|
+
doc.body.appendChild(iframe);
|
|
163
|
+
let info;
|
|
164
|
+
try {
|
|
165
|
+
info = await ready;
|
|
166
|
+
}
|
|
167
|
+
catch (e) {
|
|
168
|
+
iframe.remove();
|
|
169
|
+
port1.close();
|
|
170
|
+
throw e;
|
|
171
|
+
}
|
|
172
|
+
const lifetime = new Set();
|
|
173
|
+
const pods = new Map();
|
|
174
|
+
const frame = {
|
|
175
|
+
url,
|
|
176
|
+
origin,
|
|
177
|
+
iframe,
|
|
178
|
+
lifetime,
|
|
179
|
+
pods,
|
|
180
|
+
crossOriginIsolated: info.crossOriginIsolated,
|
|
181
|
+
stopPing: () => { },
|
|
182
|
+
rpc: new Rpc(port1, {
|
|
183
|
+
// The only thing the frame may ask of this page: a relay token from the app's getToken.
|
|
184
|
+
async getToken([key]) {
|
|
185
|
+
const get = pods.get(String(key))?.callbacks["network.relay.getToken"];
|
|
186
|
+
if (!get)
|
|
187
|
+
throw new WebPodError("EINVAL", "no getToken configured");
|
|
188
|
+
return String(await get());
|
|
189
|
+
},
|
|
190
|
+
}, (event) => {
|
|
191
|
+
const link = pods.get(String(event.key));
|
|
192
|
+
if (!link)
|
|
193
|
+
return;
|
|
194
|
+
if (event.ev === "log") {
|
|
195
|
+
const cb = link.callbacks[`${event.source === "engine" ? "engine" : `engine.${String(event.source)}.options`}.onLog`];
|
|
196
|
+
cb?.(String(event.level), String(event.text));
|
|
197
|
+
}
|
|
198
|
+
else if (event.ev === "console")
|
|
199
|
+
link.callbacks["engine.onConsole"]?.(event.bytes);
|
|
200
|
+
else if (event.ev === "exited")
|
|
201
|
+
link.exited(event.exit);
|
|
202
|
+
else if (event.ev === "fallback")
|
|
203
|
+
link.fallback?.(event.event);
|
|
204
|
+
else if (event.ev === "hostExecLog")
|
|
205
|
+
link.callbacks["hostExec.onLog"]?.(String(event.level), String(event.text));
|
|
206
|
+
}),
|
|
207
|
+
};
|
|
208
|
+
frame.stopPing = watchFrame(frame);
|
|
209
|
+
return frame;
|
|
210
|
+
}
|
|
211
|
+
/** Pings the frame; one that stops answering (crashed, hung, removed) fails its pods. */
|
|
212
|
+
function watchFrame(frame) {
|
|
213
|
+
let lastPong = performance.now();
|
|
214
|
+
let hiddenAt = 0;
|
|
215
|
+
const timer = setInterval(() => {
|
|
216
|
+
const hidden = globalThis.document?.visibilityState === "hidden";
|
|
217
|
+
if (hidden) {
|
|
218
|
+
hiddenAt ||= performance.now();
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
if (hiddenAt) {
|
|
222
|
+
// Hidden time does not count: the frame may have been throttled or frozen with the page.
|
|
223
|
+
lastPong += performance.now() - hiddenAt;
|
|
224
|
+
hiddenAt = 0;
|
|
225
|
+
}
|
|
226
|
+
if (performance.now() - lastPong > DEAD_AFTER)
|
|
227
|
+
return void killFrame(frame, new WebPodError("ENGINE_UNAVAILABLE", `execution origin ${frame.url} stopped answering (crashed or hung)`));
|
|
228
|
+
frame.rpc.call("ping").then(() => (lastPong = performance.now()), () => { });
|
|
229
|
+
}, PING_EVERY);
|
|
230
|
+
return () => clearInterval(timer);
|
|
231
|
+
}
|
|
232
|
+
function killFrame(frame, error) {
|
|
233
|
+
frame.stopPing();
|
|
234
|
+
frames.delete(frame.url);
|
|
235
|
+
frame.rpc.close(error);
|
|
236
|
+
for (const fail of [...frame.lifetime])
|
|
237
|
+
fail(error);
|
|
238
|
+
for (const link of frame.pods.values())
|
|
239
|
+
link.exited({ reason: "error", message: error.message });
|
|
240
|
+
frame.pods.clear();
|
|
241
|
+
frame.iframe.remove();
|
|
242
|
+
}
|
|
243
|
+
/** Boots a pod in the execution origin `options.executionOrigin`. */
|
|
244
|
+
export async function bootRemote(options) {
|
|
245
|
+
const url = options.executionOrigin;
|
|
246
|
+
const { spec, callbacks } = splitBootOptions(options, new URL(url, location.href).origin);
|
|
247
|
+
const frame = await attachFrame(url);
|
|
248
|
+
const key = `p${nextKey++}`;
|
|
249
|
+
let exited;
|
|
250
|
+
const exitedP = new Promise((resolve) => (exited = resolve));
|
|
251
|
+
frame.pods.set(key, { callbacks, exited });
|
|
252
|
+
let reply;
|
|
253
|
+
try {
|
|
254
|
+
reply = await frame.rpc.call("boot", [key, spec, Object.keys(callbacks)]);
|
|
255
|
+
}
|
|
256
|
+
catch (e) {
|
|
257
|
+
release(frame, key);
|
|
258
|
+
throw e;
|
|
259
|
+
}
|
|
260
|
+
const backend = remoteBackend(frame, key, reply, exitedP);
|
|
261
|
+
frame.pods.get(key).fallback = (e) => backend.hostExec._fallback(e);
|
|
262
|
+
return backend;
|
|
263
|
+
}
|
|
264
|
+
function release(frame, key) {
|
|
265
|
+
frame.pods.delete(key);
|
|
266
|
+
if (frame.pods.size > 0 || frames.get(frame.url) === undefined)
|
|
267
|
+
return;
|
|
268
|
+
frame.stopPing();
|
|
269
|
+
frames.delete(frame.url);
|
|
270
|
+
frame.rpc.close(new WebPodError("DISPOSED", "pod has been disposed"));
|
|
271
|
+
frame.iframe.remove();
|
|
272
|
+
}
|
|
273
|
+
function remoteBackend(frame, key, reply, exited) {
|
|
274
|
+
const { rpc, lifetime } = frame;
|
|
275
|
+
const call = (op, args = [], transfer = []) => rpc.call(op, [key, ...args], transfer);
|
|
276
|
+
const channel = () => new MessageChannel();
|
|
277
|
+
let console_;
|
|
278
|
+
const readFile = (async (path, encoding) => call("fs.readFile", [path, encoding]));
|
|
279
|
+
const fs = {
|
|
280
|
+
readFile,
|
|
281
|
+
createReadStream(path) {
|
|
282
|
+
const ch = channel();
|
|
283
|
+
const stream = readableFromPort(ch.port1, lifetime);
|
|
284
|
+
call("fs.createReadStream", [path], [ch.port2]).catch((e) => void stream.cancel(e).catch(() => { }));
|
|
285
|
+
return stream;
|
|
286
|
+
},
|
|
287
|
+
async writeFile(path, data, options) {
|
|
288
|
+
if (data instanceof ReadableStream) {
|
|
289
|
+
const ch = channel();
|
|
290
|
+
const done = call("fs.writeFile", [path, null, options], [ch.port2]);
|
|
291
|
+
await Promise.all([data.pipeTo(writableToPort(ch.port1, lifetime)), done]);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
await call("fs.writeFile", [path, data, options]);
|
|
295
|
+
},
|
|
296
|
+
readdir: (path) => call("fs.readdir", [path]),
|
|
297
|
+
mkdir: (path, options) => call("fs.mkdir", [path, options]),
|
|
298
|
+
rm: (path, options) => call("fs.rm", [path, options]),
|
|
299
|
+
stat: (path) => call("fs.stat", [path]),
|
|
300
|
+
lstat: (path) => call("fs.lstat", [path]),
|
|
301
|
+
rename: (from, to) => call("fs.rename", [from, to]),
|
|
302
|
+
chmod: (path, mode) => call("fs.chmod", [path, mode]),
|
|
303
|
+
symlink: (target, path) => call("fs.symlink", [target, path]),
|
|
304
|
+
readlink: (path) => call("fs.readlink", [path]),
|
|
305
|
+
async watch(path, listener, options) {
|
|
306
|
+
const ch = channel();
|
|
307
|
+
ch.port1.onmessage = (e) => listener(e.data);
|
|
308
|
+
const id = await call("fs.watch", [path, options], [ch.port2]);
|
|
309
|
+
return {
|
|
310
|
+
close: async () => {
|
|
311
|
+
ch.port1.close();
|
|
312
|
+
await rpc.call("fs.unwatch", [id]);
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
},
|
|
316
|
+
sync: () => call("fs.sync"),
|
|
317
|
+
};
|
|
318
|
+
const net = reply.has.net
|
|
319
|
+
? {
|
|
320
|
+
openPort(port) {
|
|
321
|
+
call("net.open", [], [port]).catch(() => port.close());
|
|
322
|
+
},
|
|
323
|
+
}
|
|
324
|
+
: null;
|
|
325
|
+
const snapshots = reply.has.snapshots
|
|
326
|
+
? {
|
|
327
|
+
take: (name, meta) => call("snapshots.take", [name, meta]),
|
|
328
|
+
list: () => call("snapshots.list"),
|
|
329
|
+
delete: (name) => call("snapshots.delete", [name]),
|
|
330
|
+
export: (name) => call("snapshots.export", [name]),
|
|
331
|
+
import: (file, name) => call("snapshots.import", [file, name]),
|
|
332
|
+
}
|
|
333
|
+
: null;
|
|
334
|
+
let timeline = reply.timeline;
|
|
335
|
+
const hostExec = new RemoteHostExec(reply.hostExec, (on) => call("hostExec.enabled", [on]));
|
|
336
|
+
return {
|
|
337
|
+
executionOrigin: frame.url,
|
|
338
|
+
hostExec,
|
|
339
|
+
config: reply.config,
|
|
340
|
+
agent: reply.agent,
|
|
341
|
+
bootedFrom: reply.bootedFrom,
|
|
342
|
+
storage: reply.storage,
|
|
343
|
+
get timeline() {
|
|
344
|
+
return timeline;
|
|
345
|
+
},
|
|
346
|
+
async refreshTimeline() {
|
|
347
|
+
timeline = await call("timeline");
|
|
348
|
+
return timeline;
|
|
349
|
+
},
|
|
350
|
+
host: reply.host,
|
|
351
|
+
exited,
|
|
352
|
+
fs,
|
|
353
|
+
net,
|
|
354
|
+
snapshots,
|
|
355
|
+
get console() {
|
|
356
|
+
if (!reply.has.console)
|
|
357
|
+
return undefined;
|
|
358
|
+
if (!console_) {
|
|
359
|
+
const out = channel();
|
|
360
|
+
const inp = channel();
|
|
361
|
+
console_ = { readable: readableFromPort(out.port1, lifetime), writable: writableToPort(inp.port1, lifetime) };
|
|
362
|
+
call("console.open", [], [out.port2, inp.port2]).catch(() => { });
|
|
363
|
+
}
|
|
364
|
+
return console_;
|
|
365
|
+
},
|
|
366
|
+
snapshotMemory(name, meta) {
|
|
367
|
+
return call("snapshotMemory", [name, meta]);
|
|
368
|
+
},
|
|
369
|
+
caCertificate: () => call("net.caCertificate"),
|
|
370
|
+
spawn(request) {
|
|
371
|
+
const stdin = channel();
|
|
372
|
+
const stdout = channel();
|
|
373
|
+
const stderr = channel();
|
|
374
|
+
const id = call("spawn", [request], [stdin.port2, stdout.port2, stderr.port2]);
|
|
375
|
+
// Both asked for at once: the frame forgets the process once it answered both.
|
|
376
|
+
const exit = id.then((i) => rpc.call("proc.exit", [i]));
|
|
377
|
+
const pid = id.then((i) => rpc.call("proc.pid", [i]));
|
|
378
|
+
exit.catch(() => { });
|
|
379
|
+
pid.catch(() => { });
|
|
380
|
+
return {
|
|
381
|
+
pid,
|
|
382
|
+
stdin: writableToPort(stdin.port1, lifetime),
|
|
383
|
+
stdout: readableFromPort(stdout.port1, lifetime),
|
|
384
|
+
stderr: readableFromPort(stderr.port1, lifetime),
|
|
385
|
+
exit,
|
|
386
|
+
kill: async (signal) => void (await rpc.call("proc.kill", [await id, signal])),
|
|
387
|
+
resize: async (size) => void (await rpc.call("proc.resize", [await id, size])),
|
|
388
|
+
};
|
|
389
|
+
},
|
|
390
|
+
async dispose() {
|
|
391
|
+
try {
|
|
392
|
+
if (!rpc.closed)
|
|
393
|
+
await call("dispose");
|
|
394
|
+
}
|
|
395
|
+
finally {
|
|
396
|
+
release(frame, key);
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/exec/client.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,mGAAmG;AACnG,gGAAgG;AAChG,6CAA6C;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,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,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
// The execution origin's page (dist/exec-frame.html loads this): pods run here, in a cross-origin,
|
|
2
|
+
// cross-origin isolated iframe on a site of its own, apart from the app that embeds it. The app
|
|
3
|
+
// reaches them over one MessagePort (the control channel, exec/client.ts); nothing else of this
|
|
4
|
+
// origin is reachable from the app, nor the app's storage, cookies or DOM from here.
|
|
5
|
+
//
|
|
6
|
+
// Handshake (like preview-relay.ts): this page posts "webpod-exec-loaded" to its parent (nothing
|
|
7
|
+
// secret); the parent posts "webpod-exec-attach" with the control port. Only a parent whose origin
|
|
8
|
+
// is listed in webpod-exec.json next to this page ({ "hosts": ["https://app.example"] }, or "*" for
|
|
9
|
+
// a shared execution origin: browsers partition its storage by the embedding site) is answered;
|
|
10
|
+
// the page also sends Content-Security-Policy: frame-ancestors with the same origins.
|
|
11
|
+
//
|
|
12
|
+
// On the port the app may only call the ops below; this side only answers them, emits events
|
|
13
|
+
// (logs, console bytes, engine exit) and asks for relay tokens (the app's getToken).
|
|
14
|
+
import { Pod } from "../pod.js";
|
|
15
|
+
import { WebPodError } from "../errors.js";
|
|
16
|
+
import { engineFromSpecs, frameHostExec } from "./options.js";
|
|
17
|
+
import { Rpc, WithTransfer, portToWritable, readableToPort } from "./wire.js";
|
|
18
|
+
import { EXEC_PROTOCOL } from "./protocol.js";
|
|
19
|
+
const here = new URL(location.href);
|
|
20
|
+
const hosts = fetch(new URL("./webpod-exec.json", here), { cache: "no-store" })
|
|
21
|
+
.then((r) => (r.ok ? r.json() : {}))
|
|
22
|
+
.then((j) => (Array.isArray(j.hosts) ? j.hosts.filter((h) => typeof h === "string") : []))
|
|
23
|
+
.catch(() => []);
|
|
24
|
+
let attached = false;
|
|
25
|
+
window.addEventListener("message", (event) => {
|
|
26
|
+
const d = event.data;
|
|
27
|
+
if (event.source !== parent || d?.type !== "webpod-exec-attach" || !event.ports[0])
|
|
28
|
+
return;
|
|
29
|
+
const port = event.ports[0];
|
|
30
|
+
void hosts.then((allowed) => {
|
|
31
|
+
if (!allowed.includes(event.origin) && !allowed.includes("*")) {
|
|
32
|
+
port.postMessage({ type: "refused", message: `${event.origin} is not in ${new URL("./webpod-exec.json", here).href}` });
|
|
33
|
+
return port.close();
|
|
34
|
+
}
|
|
35
|
+
if (attached) {
|
|
36
|
+
port.postMessage({ type: "refused", message: "this execution frame is attached already" });
|
|
37
|
+
return port.close();
|
|
38
|
+
}
|
|
39
|
+
if (d.version !== EXEC_PROTOCOL) {
|
|
40
|
+
port.postMessage({ type: "refused", message: `protocol ${d.version} (this execution origin speaks ${EXEC_PROTOCOL}): serve the SDK version the app uses` });
|
|
41
|
+
return port.close();
|
|
42
|
+
}
|
|
43
|
+
attached = true;
|
|
44
|
+
serve(port, event.origin);
|
|
45
|
+
port.postMessage({ type: "ready", crossOriginIsolated: globalThis.crossOriginIsolated === true, protocol: EXEC_PROTOCOL });
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
function serve(port, appOrigin) {
|
|
49
|
+
const pods = new Map();
|
|
50
|
+
const nets = new Map();
|
|
51
|
+
// A process stays here until the app has asked for its pid and its exit (it does right after spawn).
|
|
52
|
+
const procs = new Map();
|
|
53
|
+
const watchers = new Map();
|
|
54
|
+
let nextId = 1;
|
|
55
|
+
const pod = (key) => {
|
|
56
|
+
const p = pods.get(String(key));
|
|
57
|
+
if (!p)
|
|
58
|
+
throw new WebPodError("DISPOSED", `no pod ${String(key)} in this execution frame`);
|
|
59
|
+
return p;
|
|
60
|
+
};
|
|
61
|
+
const engine = (key) => pod(key).backend;
|
|
62
|
+
const settle = async (id, get) => {
|
|
63
|
+
const e = procs.get(Number(id));
|
|
64
|
+
if (!e)
|
|
65
|
+
throw new WebPodError("EINVAL", `no process ${String(id)}`);
|
|
66
|
+
try {
|
|
67
|
+
return await get(e.proc);
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
if (++e.asked === 2)
|
|
71
|
+
procs.delete(Number(id));
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const fsOp = (name) => ([key, ...args]) => pod(key).fs[name](...args);
|
|
75
|
+
const rpc = new Rpc(port, {
|
|
76
|
+
ping: () => "pong",
|
|
77
|
+
async boot([key, spec, callbacks]) {
|
|
78
|
+
const k = String(key);
|
|
79
|
+
if (pods.has(k))
|
|
80
|
+
throw new WebPodError("EINVAL", `pod ${k} exists`);
|
|
81
|
+
const has = new Set(callbacks);
|
|
82
|
+
const options = bootOptions(k, spec, has);
|
|
83
|
+
const p = await Pod.boot(options);
|
|
84
|
+
pods.set(k, p);
|
|
85
|
+
const hx = p.hostExec;
|
|
86
|
+
hx.on("fallback", (event) => rpc.emit("fallback", { key: k, event }));
|
|
87
|
+
const net = options.engine?.net;
|
|
88
|
+
if (net)
|
|
89
|
+
nets.set(k, net);
|
|
90
|
+
const b = p.backend;
|
|
91
|
+
void b.exited?.then((exit) => rpc.emit("exited", { key: k, exit }));
|
|
92
|
+
return {
|
|
93
|
+
config: p.config,
|
|
94
|
+
agent: b.agent ?? null,
|
|
95
|
+
bootedFrom: b.bootedFrom ?? null,
|
|
96
|
+
storage: b.storage ?? null,
|
|
97
|
+
timeline: b.timeline ?? [],
|
|
98
|
+
host: b.host ? { boot: b.host.boot, devices: b.host.devices, manifest: b.host.manifest } : null,
|
|
99
|
+
has: { console: !!b.console, net: !!b.net, snapshots: !!b.snapshots, snapshotMemory: typeof b.snapshotMemory === "function" },
|
|
100
|
+
hostExec: hostExecState(p),
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
"hostExec.enabled"([key, on]) {
|
|
104
|
+
const p = pod(key);
|
|
105
|
+
p.hostExec.enabled = on === true;
|
|
106
|
+
return hostExecState(p);
|
|
107
|
+
},
|
|
108
|
+
async dispose([key]) {
|
|
109
|
+
const p = pods.get(String(key));
|
|
110
|
+
if (!p)
|
|
111
|
+
return;
|
|
112
|
+
pods.delete(String(key));
|
|
113
|
+
nets.delete(String(key));
|
|
114
|
+
await p.dispose();
|
|
115
|
+
},
|
|
116
|
+
timeline: ([key]) => engine(key).timeline ?? [],
|
|
117
|
+
"console.open"([key], ports) {
|
|
118
|
+
const c = pod(key).console;
|
|
119
|
+
readableToPort(c.readable, ports[0]);
|
|
120
|
+
portToWritable(ports[1], c.writable);
|
|
121
|
+
},
|
|
122
|
+
spawn([key, request], ports) {
|
|
123
|
+
const r = request;
|
|
124
|
+
const req = { command: String(r.command), args: (r.args ?? []).map(String), cwd: r.cwd, env: r.env, pty: r.pty, user: r.user };
|
|
125
|
+
// The pod's hostExec controller routes it (host node, or the guest), as Pod.spawn does.
|
|
126
|
+
const pp = pod(key);
|
|
127
|
+
const p = pp.hostExec.spawn(req) ?? pp.backend.spawn(req);
|
|
128
|
+
const id = nextId++;
|
|
129
|
+
procs.set(id, { proc: p, asked: 0 });
|
|
130
|
+
portToWritable(ports[0], p.stdin);
|
|
131
|
+
readableToPort(p.stdout, ports[1]);
|
|
132
|
+
readableToPort(p.stderr, ports[2]);
|
|
133
|
+
return id;
|
|
134
|
+
},
|
|
135
|
+
"proc.pid": ([id]) => settle(id, (p) => p.pid),
|
|
136
|
+
"proc.exit": ([id]) => settle(id, (p) => p.exit),
|
|
137
|
+
"proc.kill": ([id, signal]) => procs.get(Number(id))?.proc.kill(signal),
|
|
138
|
+
"proc.resize": ([id, size]) => procs.get(Number(id))?.proc.resize(size),
|
|
139
|
+
async "fs.readFile"([key, path, encoding]) {
|
|
140
|
+
const data = await pod(key).fs.readFile(String(path));
|
|
141
|
+
if (encoding === "utf8")
|
|
142
|
+
return new TextDecoder().decode(data);
|
|
143
|
+
return new WithTransfer(data, data.buffer instanceof ArrayBuffer && data.byteLength === data.buffer.byteLength ? [data.buffer] : []);
|
|
144
|
+
},
|
|
145
|
+
"fs.createReadStream"([key, path], ports) {
|
|
146
|
+
readableToPort(pod(key).fs.createReadStream(String(path)), ports[0]);
|
|
147
|
+
},
|
|
148
|
+
async "fs.writeFile"([key, path, data, options], ports) {
|
|
149
|
+
const body = ports[0] ? streamFrom(ports[0]) : data;
|
|
150
|
+
await pod(key).fs.writeFile(String(path), body, options);
|
|
151
|
+
},
|
|
152
|
+
"fs.readdir": fsOp("readdir"),
|
|
153
|
+
"fs.mkdir": fsOp("mkdir"),
|
|
154
|
+
"fs.rm": fsOp("rm"),
|
|
155
|
+
"fs.stat": fsOp("stat"),
|
|
156
|
+
"fs.lstat": fsOp("lstat"),
|
|
157
|
+
"fs.rename": fsOp("rename"),
|
|
158
|
+
"fs.chmod": fsOp("chmod"),
|
|
159
|
+
"fs.symlink": fsOp("symlink"),
|
|
160
|
+
"fs.readlink": fsOp("readlink"),
|
|
161
|
+
"fs.sync": ([key]) => pod(key).fs.sync?.(),
|
|
162
|
+
async "fs.watch"([key, path, options], ports) {
|
|
163
|
+
const events = ports[0];
|
|
164
|
+
const w = await pod(key).fs.watch(String(path), (e) => events.postMessage(e), options);
|
|
165
|
+
const id = nextId++;
|
|
166
|
+
watchers.set(id, {
|
|
167
|
+
close: async () => {
|
|
168
|
+
events.close();
|
|
169
|
+
await w.close();
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
return id;
|
|
173
|
+
},
|
|
174
|
+
async "fs.unwatch"([id]) {
|
|
175
|
+
const w = watchers.get(Number(id));
|
|
176
|
+
watchers.delete(Number(id));
|
|
177
|
+
await w?.close();
|
|
178
|
+
},
|
|
179
|
+
"net.caCertificate": ([key]) => (pod(key), nets.get(String(key))?.caCertificate?.() ?? null),
|
|
180
|
+
"net.open"([key], ports) {
|
|
181
|
+
const net = pod(key).backend.net;
|
|
182
|
+
if (!net)
|
|
183
|
+
throw new WebPodError("UNSUPPORTED", "this pod has no inbound networking");
|
|
184
|
+
net.openPort(ports[0]);
|
|
185
|
+
},
|
|
186
|
+
"snapshots.take": ([key, name, meta]) => pod(key).snapshot(String(name), meta),
|
|
187
|
+
"snapshots.list": ([key]) => pod(key).snapshots.list(),
|
|
188
|
+
"snapshots.delete": ([key, name]) => pod(key).snapshots.delete(String(name)),
|
|
189
|
+
"snapshots.export": ([key, name]) => pod(key).snapshots.export(String(name)),
|
|
190
|
+
"snapshots.import": ([key, file, name]) => pod(key).snapshots.import(file, name === undefined ? undefined : String(name)),
|
|
191
|
+
snapshotMemory([key, name, meta]) {
|
|
192
|
+
const b = engine(key);
|
|
193
|
+
if (typeof b.snapshotMemory !== "function")
|
|
194
|
+
throw new WebPodError("UNSUPPORTED", "this backend cannot take memory snapshots");
|
|
195
|
+
return b.snapshotMemory(String(name), meta);
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
// Turns the boot spec back into BootOptions: callbacks become events and calls to the app; the
|
|
199
|
+
// guest may not reach the app's origin (its requests leave from here, but its WebSockets would
|
|
200
|
+
// still carry the app's SameSite-less cookies on Firefox), unless the app routes it explicitly.
|
|
201
|
+
function bootOptions(key, spec, has) {
|
|
202
|
+
const log = (source) => (level, text) => rpc.emit("log", { key, source, level, text });
|
|
203
|
+
// Host processes run here, next to the pod (executionOrigin: false: not another frame), on this
|
|
204
|
+
// origin's host-exec/ unless the app names another (frameHostExec).
|
|
205
|
+
const hostExec = spec.hostExec && frameHostExec({ ...spec.hostExec, ...(has.has("hostExec.onLog") ? { onLog: (level, text) => rpc.emit("hostExecLog", { key, level, text }) } : {}) }, location.href);
|
|
206
|
+
const e = { ...(spec.engine ?? { manifestUrl: "" }) };
|
|
207
|
+
if (has.has("engine.onLog"))
|
|
208
|
+
e.onLog = log("engine");
|
|
209
|
+
if (has.has("engine.onConsole"))
|
|
210
|
+
e.onConsole = (bytes) => rpc.emit("console", { key, bytes: new Uint8Array(bytes) });
|
|
211
|
+
const fs = e.fs;
|
|
212
|
+
if (fs && has.has("engine.fs.options.onLog"))
|
|
213
|
+
e.fs = { ...fs, options: { ...fs.options, onLog: log("fs") } };
|
|
214
|
+
const net = e.net;
|
|
215
|
+
if (net && has.has("engine.net.options.onLog"))
|
|
216
|
+
e.net = { ...net, options: { ...net.options, onLog: log("net") } };
|
|
217
|
+
const app = new URL(appOrigin);
|
|
218
|
+
const deny = { host: app.hostname.replace(/^\[|\]$/g, ""), ports: Number(app.port || (app.protocol === "https:" ? 443 : 80)), via: "deny" };
|
|
219
|
+
const network = { ...spec.network, routes: [...(spec.network?.routes ?? []), deny] };
|
|
220
|
+
if (spec.network?.relay && has.has("network.relay.getToken"))
|
|
221
|
+
network.relay = { ...spec.network.relay, getToken: () => rpc.call("getToken", [key]) };
|
|
222
|
+
return { ...spec, executionOrigin: false, network, ...(hostExec ? { hostExec } : {}), engine: engineFromSpecs(e) };
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
function hostExecState(p) {
|
|
226
|
+
const hx = p.hostExec;
|
|
227
|
+
return { status: hx.status, enabled: hx.enabled, route: hx.routeContext };
|
|
228
|
+
}
|
|
229
|
+
function streamFrom(port) {
|
|
230
|
+
const { readable, writable } = new TransformStream();
|
|
231
|
+
portToWritable(port, writable);
|
|
232
|
+
return readable;
|
|
233
|
+
}
|
|
234
|
+
// Nothing secret here: tells the embedding page it can attach now.
|
|
235
|
+
parent.postMessage({ type: "webpod-exec-loaded" }, "*");
|
|
236
|
+
//# sourceMappingURL=frame.js.map
|