@scelar/nodepod 1.0.4 → 1.0.6
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/dist/{child_process-53fMkug_.js → child_process-4ZrgCVFu.js} +8234 -8233
- package/dist/{child_process-53fMkug_.js.map → child_process-4ZrgCVFu.js.map} +1 -1
- package/dist/{child_process-lxSKECHq.cjs → child_process-Cao4lyrb.cjs} +7435 -7434
- package/dist/{child_process-lxSKECHq.cjs.map → child_process-Cao4lyrb.cjs.map} +1 -1
- package/dist/{index-C-TQIrdG.cjs → index-DuYo2yDs.cjs} +38842 -38005
- package/dist/index-DuYo2yDs.cjs.map +1 -0
- package/dist/{index-B8lyh_ti.js → index-HkVqijtm.js} +36923 -36065
- package/dist/index-HkVqijtm.js.map +1 -0
- package/dist/index.cjs +67 -65
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +61 -59
- package/dist/memory-handler.d.ts +57 -0
- package/dist/memory-volume.d.ts +12 -2
- package/dist/packages/installer.d.ts +3 -0
- package/dist/persistence/idb-cache.d.ts +7 -0
- package/dist/polyfills/readline.d.ts +108 -87
- package/dist/script-engine.d.ts +3 -0
- package/dist/sdk/nodepod-process.d.ts +2 -1
- package/dist/sdk/nodepod.d.ts +20 -1
- package/dist/sdk/types.d.ts +5 -0
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/memory-handler.ts +168 -0
- package/src/memory-volume.ts +72 -8
- package/src/packages/installer.ts +49 -1
- package/src/packages/version-resolver.ts +421 -421
- package/src/persistence/idb-cache.ts +107 -0
- package/src/polyfills/child_process.ts +3 -0
- package/src/polyfills/events.ts +22 -4
- package/src/polyfills/readline.ts +593 -71
- package/src/polyfills/stream.ts +46 -0
- package/src/polyfills/wasi.ts +1306 -1306
- package/src/polyfills/zlib.ts +881 -881
- package/src/script-engine.ts +3722 -3694
- package/src/sdk/nodepod-process.ts +94 -86
- package/src/sdk/nodepod.ts +52 -6
- package/src/sdk/types.ts +82 -77
- package/src/threading/process-manager.ts +11 -0
- package/src/threading/worker-protocol.ts +358 -358
- package/dist/index-B8lyh_ti.js.map +0 -1
- package/dist/index-C-TQIrdG.cjs.map +0 -1
|
@@ -1,358 +1,358 @@
|
|
|
1
|
-
// Worker Protocol — typed messages for main<->worker communication.
|
|
2
|
-
// Flows via postMessage. Binary data (VFS snapshots) transferred zero-copy.
|
|
3
|
-
|
|
4
|
-
// --- VFS snapshot (binary transfer) ---
|
|
5
|
-
|
|
6
|
-
export interface VFSBinarySnapshot {
|
|
7
|
-
manifest: VFSSnapshotEntry[];
|
|
8
|
-
data: ArrayBuffer;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface VFSSnapshotEntry {
|
|
12
|
-
path: string;
|
|
13
|
-
offset: number;
|
|
14
|
-
length: number;
|
|
15
|
-
isDirectory: boolean;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// --- Main -> Worker messages ---
|
|
19
|
-
|
|
20
|
-
export interface MainToWorker_Init {
|
|
21
|
-
type: "init";
|
|
22
|
-
pid: number;
|
|
23
|
-
cwd: string;
|
|
24
|
-
env: Record<string, string>;
|
|
25
|
-
snapshot: VFSBinarySnapshot;
|
|
26
|
-
sharedBuffer?: SharedArrayBuffer;
|
|
27
|
-
syncBuffer?: SharedArrayBuffer;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface MainToWorker_Exec {
|
|
31
|
-
type: "exec";
|
|
32
|
-
filePath: string;
|
|
33
|
-
args: string[];
|
|
34
|
-
cwd?: string;
|
|
35
|
-
env?: Record<string, string>;
|
|
36
|
-
isShell?: boolean;
|
|
37
|
-
shellCommand?: string;
|
|
38
|
-
isFork?: boolean;
|
|
39
|
-
// If true, worker sends "shell-done" instead of "exit" and stays alive
|
|
40
|
-
persistent?: boolean;
|
|
41
|
-
isWorkerThread?: boolean;
|
|
42
|
-
workerData?: unknown;
|
|
43
|
-
threadId?: number;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface MainToWorker_Stdin {
|
|
47
|
-
type: "stdin";
|
|
48
|
-
data: string;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export interface MainToWorker_Signal {
|
|
52
|
-
type: "signal";
|
|
53
|
-
signal: string;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface MainToWorker_Resize {
|
|
57
|
-
type: "resize";
|
|
58
|
-
cols: number;
|
|
59
|
-
rows: number;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export interface MainToWorker_VFSSync {
|
|
63
|
-
type: "vfs-sync";
|
|
64
|
-
path: string;
|
|
65
|
-
content: ArrayBuffer | null; // null = deleted
|
|
66
|
-
isDirectory: boolean;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export interface MainToWorker_VFSChunk {
|
|
70
|
-
type: "vfs-chunk";
|
|
71
|
-
chunkIndex: number;
|
|
72
|
-
totalChunks: number;
|
|
73
|
-
data: ArrayBuffer;
|
|
74
|
-
manifest: VFSSnapshotEntry[];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export interface MainToWorker_SpawnResult {
|
|
78
|
-
type: "spawn-result";
|
|
79
|
-
requestId: number;
|
|
80
|
-
pid: number;
|
|
81
|
-
error?: string;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export interface MainToWorker_ChildOutput {
|
|
85
|
-
type: "child-output";
|
|
86
|
-
requestId: number;
|
|
87
|
-
stream: "stdout" | "stderr";
|
|
88
|
-
data: string;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export interface MainToWorker_ChildExit {
|
|
92
|
-
type: "child-exit";
|
|
93
|
-
requestId: number;
|
|
94
|
-
exitCode: number;
|
|
95
|
-
stdout: string;
|
|
96
|
-
stderr: string;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export interface MainToWorker_HttpRequest {
|
|
100
|
-
type: "http-request";
|
|
101
|
-
requestId: number;
|
|
102
|
-
port: number;
|
|
103
|
-
method: string;
|
|
104
|
-
path: string;
|
|
105
|
-
headers: Record<string, string>;
|
|
106
|
-
body: string | null;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export interface MainToWorker_IPC {
|
|
110
|
-
type: "ipc-message";
|
|
111
|
-
data: unknown;
|
|
112
|
-
// Routes to a specific fork callback when sent to a parent worker
|
|
113
|
-
targetRequestId?: number;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export interface MainToWorker_WsUpgrade {
|
|
117
|
-
type: "ws-upgrade";
|
|
118
|
-
uid: string;
|
|
119
|
-
port: number;
|
|
120
|
-
path: string;
|
|
121
|
-
headers: Record<string, string>;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export interface MainToWorker_WsData {
|
|
125
|
-
type: "ws-data";
|
|
126
|
-
uid: string;
|
|
127
|
-
frame: number[]; // encoded WS frame bytes (number[] for postMessage)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export interface MainToWorker_WsClose {
|
|
131
|
-
type: "ws-close";
|
|
132
|
-
uid: string;
|
|
133
|
-
code: number;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export type MainToWorkerMessage =
|
|
137
|
-
| MainToWorker_Init
|
|
138
|
-
| MainToWorker_Exec
|
|
139
|
-
| MainToWorker_Stdin
|
|
140
|
-
| MainToWorker_Signal
|
|
141
|
-
| MainToWorker_Resize
|
|
142
|
-
| MainToWorker_VFSSync
|
|
143
|
-
| MainToWorker_VFSChunk
|
|
144
|
-
| MainToWorker_SpawnResult
|
|
145
|
-
| MainToWorker_ChildOutput
|
|
146
|
-
| MainToWorker_ChildExit
|
|
147
|
-
| MainToWorker_HttpRequest
|
|
148
|
-
| MainToWorker_IPC
|
|
149
|
-
| MainToWorker_WsUpgrade
|
|
150
|
-
| MainToWorker_WsData
|
|
151
|
-
| MainToWorker_WsClose;
|
|
152
|
-
|
|
153
|
-
// --- Worker -> Main messages ---
|
|
154
|
-
|
|
155
|
-
export interface WorkerToMain_Ready {
|
|
156
|
-
type: "ready";
|
|
157
|
-
pid: number;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export interface WorkerToMain_Stdout {
|
|
161
|
-
type: "stdout";
|
|
162
|
-
data: string;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export interface WorkerToMain_Stderr {
|
|
166
|
-
type: "stderr";
|
|
167
|
-
data: string;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export interface WorkerToMain_Exit {
|
|
171
|
-
type: "exit";
|
|
172
|
-
exitCode: number;
|
|
173
|
-
stdout: string;
|
|
174
|
-
stderr: string;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export interface WorkerToMain_Console {
|
|
178
|
-
type: "console";
|
|
179
|
-
method: string;
|
|
180
|
-
args: string[];
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export interface WorkerToMain_VFSWrite {
|
|
184
|
-
type: "vfs-write";
|
|
185
|
-
path: string;
|
|
186
|
-
content: ArrayBuffer;
|
|
187
|
-
isDirectory: boolean;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export interface WorkerToMain_VFSDelete {
|
|
191
|
-
type: "vfs-delete";
|
|
192
|
-
path: string;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
export interface WorkerToMain_VFSRead {
|
|
196
|
-
type: "vfs-read";
|
|
197
|
-
requestId: number;
|
|
198
|
-
path: string;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export interface WorkerToMain_SpawnRequest {
|
|
202
|
-
type: "spawn-request";
|
|
203
|
-
requestId: number;
|
|
204
|
-
command: string;
|
|
205
|
-
args: string[];
|
|
206
|
-
cwd: string;
|
|
207
|
-
env: Record<string, string>;
|
|
208
|
-
stdio: "pipe" | "inherit";
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export interface WorkerToMain_ForkRequest {
|
|
212
|
-
type: "fork-request";
|
|
213
|
-
requestId: number;
|
|
214
|
-
modulePath: string;
|
|
215
|
-
args: string[];
|
|
216
|
-
cwd: string;
|
|
217
|
-
env: Record<string, string>;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
export interface WorkerToMain_WorkerThreadRequest {
|
|
221
|
-
type: "workerthread-request";
|
|
222
|
-
requestId: number;
|
|
223
|
-
modulePath: string; // absolute path, or inline code if isEval
|
|
224
|
-
isEval?: boolean;
|
|
225
|
-
args: string[];
|
|
226
|
-
cwd: string;
|
|
227
|
-
env: Record<string, string>;
|
|
228
|
-
workerData: unknown;
|
|
229
|
-
threadId: number;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
export interface WorkerToMain_SpawnSync {
|
|
233
|
-
type: "spawn-sync";
|
|
234
|
-
requestId: number;
|
|
235
|
-
command: string;
|
|
236
|
-
args: string[];
|
|
237
|
-
cwd: string;
|
|
238
|
-
env: Record<string, string>;
|
|
239
|
-
syncSlot: number; // index in the sync SAB for Atomics.wait/notify
|
|
240
|
-
shellCommand?: string;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export interface WorkerToMain_ServerListen {
|
|
244
|
-
type: "server-listen";
|
|
245
|
-
port: number;
|
|
246
|
-
hostname: string;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
export interface WorkerToMain_ServerClose {
|
|
250
|
-
type: "server-close";
|
|
251
|
-
port: number;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
export interface WorkerToMain_HttpRequest {
|
|
255
|
-
type: "http-request";
|
|
256
|
-
requestId: number;
|
|
257
|
-
port: number;
|
|
258
|
-
method: string;
|
|
259
|
-
path: string;
|
|
260
|
-
headers: Record<string, string>;
|
|
261
|
-
body: string | null;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
export interface WorkerToMain_CwdChange {
|
|
265
|
-
type: "cwd-change";
|
|
266
|
-
cwd: string;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
export interface WorkerToMain_StdinRawStatus {
|
|
270
|
-
type: "stdin-raw-status";
|
|
271
|
-
isRaw: boolean;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
export interface WorkerToMain_HttpResponse {
|
|
275
|
-
type: "http-response";
|
|
276
|
-
requestId: number;
|
|
277
|
-
statusCode: number;
|
|
278
|
-
statusMessage: string;
|
|
279
|
-
headers: Record<string, string>;
|
|
280
|
-
body: string | ArrayBuffer;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
export interface WorkerToMain_IPC {
|
|
284
|
-
type: "ipc-message";
|
|
285
|
-
data: unknown;
|
|
286
|
-
targetRequestId?: number;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
export interface WorkerToMain_ShellDone {
|
|
290
|
-
type: "shell-done";
|
|
291
|
-
exitCode: number;
|
|
292
|
-
stdout: string;
|
|
293
|
-
stderr: string;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
export interface WorkerToMain_Error {
|
|
297
|
-
type: "error";
|
|
298
|
-
message: string;
|
|
299
|
-
stack?: string;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
export interface WorkerToMain_WsFrame {
|
|
303
|
-
type: "ws-frame";
|
|
304
|
-
uid: string;
|
|
305
|
-
kind: string; // "open" | "text" | "binary" | "close" | "error"
|
|
306
|
-
data?: string;
|
|
307
|
-
bytes?: number[];
|
|
308
|
-
code?: number;
|
|
309
|
-
message?: string;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
export type WorkerToMainMessage =
|
|
313
|
-
| WorkerToMain_Ready
|
|
314
|
-
| WorkerToMain_Stdout
|
|
315
|
-
| WorkerToMain_Stderr
|
|
316
|
-
| WorkerToMain_Exit
|
|
317
|
-
| WorkerToMain_Console
|
|
318
|
-
| WorkerToMain_VFSWrite
|
|
319
|
-
| WorkerToMain_VFSDelete
|
|
320
|
-
| WorkerToMain_VFSRead
|
|
321
|
-
| WorkerToMain_SpawnRequest
|
|
322
|
-
| WorkerToMain_ForkRequest
|
|
323
|
-
| WorkerToMain_WorkerThreadRequest
|
|
324
|
-
| WorkerToMain_SpawnSync
|
|
325
|
-
| WorkerToMain_ServerListen
|
|
326
|
-
| WorkerToMain_ServerClose
|
|
327
|
-
| WorkerToMain_HttpRequest
|
|
328
|
-
| WorkerToMain_CwdChange
|
|
329
|
-
| WorkerToMain_StdinRawStatus
|
|
330
|
-
| WorkerToMain_HttpResponse
|
|
331
|
-
| WorkerToMain_IPC
|
|
332
|
-
| WorkerToMain_ShellDone
|
|
333
|
-
| WorkerToMain_Error
|
|
334
|
-
| WorkerToMain_WsFrame;
|
|
335
|
-
|
|
336
|
-
// --- Spawn config ---
|
|
337
|
-
|
|
338
|
-
export interface SpawnConfig {
|
|
339
|
-
command: string;
|
|
340
|
-
args: string[];
|
|
341
|
-
cwd: string;
|
|
342
|
-
env: Record<string, string>;
|
|
343
|
-
snapshot: VFSBinarySnapshot;
|
|
344
|
-
sharedBuffer?: SharedArrayBuffer;
|
|
345
|
-
syncBuffer?: SharedArrayBuffer;
|
|
346
|
-
parentPid?: number;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
// --- Process info ---
|
|
350
|
-
|
|
351
|
-
export interface ProcessInfo {
|
|
352
|
-
pid: number;
|
|
353
|
-
command: string;
|
|
354
|
-
args: string[];
|
|
355
|
-
state: "starting" | "running" | "exited";
|
|
356
|
-
exitCode?: number;
|
|
357
|
-
parentPid?: number;
|
|
358
|
-
}
|
|
1
|
+
// Worker Protocol — typed messages for main<->worker communication.
|
|
2
|
+
// Flows via postMessage. Binary data (VFS snapshots) transferred zero-copy.
|
|
3
|
+
|
|
4
|
+
// --- VFS snapshot (binary transfer) ---
|
|
5
|
+
|
|
6
|
+
export interface VFSBinarySnapshot {
|
|
7
|
+
manifest: VFSSnapshotEntry[];
|
|
8
|
+
data: ArrayBuffer;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface VFSSnapshotEntry {
|
|
12
|
+
path: string;
|
|
13
|
+
offset: number;
|
|
14
|
+
length: number;
|
|
15
|
+
isDirectory: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// --- Main -> Worker messages ---
|
|
19
|
+
|
|
20
|
+
export interface MainToWorker_Init {
|
|
21
|
+
type: "init";
|
|
22
|
+
pid: number;
|
|
23
|
+
cwd: string;
|
|
24
|
+
env: Record<string, string>;
|
|
25
|
+
snapshot: VFSBinarySnapshot;
|
|
26
|
+
sharedBuffer?: SharedArrayBuffer;
|
|
27
|
+
syncBuffer?: SharedArrayBuffer;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface MainToWorker_Exec {
|
|
31
|
+
type: "exec";
|
|
32
|
+
filePath: string;
|
|
33
|
+
args: string[];
|
|
34
|
+
cwd?: string;
|
|
35
|
+
env?: Record<string, string>;
|
|
36
|
+
isShell?: boolean;
|
|
37
|
+
shellCommand?: string;
|
|
38
|
+
isFork?: boolean;
|
|
39
|
+
// If true, worker sends "shell-done" instead of "exit" and stays alive
|
|
40
|
+
persistent?: boolean;
|
|
41
|
+
isWorkerThread?: boolean;
|
|
42
|
+
workerData?: unknown;
|
|
43
|
+
threadId?: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface MainToWorker_Stdin {
|
|
47
|
+
type: "stdin";
|
|
48
|
+
data: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface MainToWorker_Signal {
|
|
52
|
+
type: "signal";
|
|
53
|
+
signal: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface MainToWorker_Resize {
|
|
57
|
+
type: "resize";
|
|
58
|
+
cols: number;
|
|
59
|
+
rows: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface MainToWorker_VFSSync {
|
|
63
|
+
type: "vfs-sync";
|
|
64
|
+
path: string;
|
|
65
|
+
content: ArrayBuffer | null; // null = deleted
|
|
66
|
+
isDirectory: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface MainToWorker_VFSChunk {
|
|
70
|
+
type: "vfs-chunk";
|
|
71
|
+
chunkIndex: number;
|
|
72
|
+
totalChunks: number;
|
|
73
|
+
data: ArrayBuffer;
|
|
74
|
+
manifest: VFSSnapshotEntry[];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface MainToWorker_SpawnResult {
|
|
78
|
+
type: "spawn-result";
|
|
79
|
+
requestId: number;
|
|
80
|
+
pid: number;
|
|
81
|
+
error?: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface MainToWorker_ChildOutput {
|
|
85
|
+
type: "child-output";
|
|
86
|
+
requestId: number;
|
|
87
|
+
stream: "stdout" | "stderr";
|
|
88
|
+
data: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface MainToWorker_ChildExit {
|
|
92
|
+
type: "child-exit";
|
|
93
|
+
requestId: number;
|
|
94
|
+
exitCode: number;
|
|
95
|
+
stdout: string;
|
|
96
|
+
stderr: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface MainToWorker_HttpRequest {
|
|
100
|
+
type: "http-request";
|
|
101
|
+
requestId: number;
|
|
102
|
+
port: number;
|
|
103
|
+
method: string;
|
|
104
|
+
path: string;
|
|
105
|
+
headers: Record<string, string>;
|
|
106
|
+
body: string | null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface MainToWorker_IPC {
|
|
110
|
+
type: "ipc-message";
|
|
111
|
+
data: unknown;
|
|
112
|
+
// Routes to a specific fork callback when sent to a parent worker
|
|
113
|
+
targetRequestId?: number;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface MainToWorker_WsUpgrade {
|
|
117
|
+
type: "ws-upgrade";
|
|
118
|
+
uid: string;
|
|
119
|
+
port: number;
|
|
120
|
+
path: string;
|
|
121
|
+
headers: Record<string, string>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface MainToWorker_WsData {
|
|
125
|
+
type: "ws-data";
|
|
126
|
+
uid: string;
|
|
127
|
+
frame: number[]; // encoded WS frame bytes (number[] for postMessage)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface MainToWorker_WsClose {
|
|
131
|
+
type: "ws-close";
|
|
132
|
+
uid: string;
|
|
133
|
+
code: number;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export type MainToWorkerMessage =
|
|
137
|
+
| MainToWorker_Init
|
|
138
|
+
| MainToWorker_Exec
|
|
139
|
+
| MainToWorker_Stdin
|
|
140
|
+
| MainToWorker_Signal
|
|
141
|
+
| MainToWorker_Resize
|
|
142
|
+
| MainToWorker_VFSSync
|
|
143
|
+
| MainToWorker_VFSChunk
|
|
144
|
+
| MainToWorker_SpawnResult
|
|
145
|
+
| MainToWorker_ChildOutput
|
|
146
|
+
| MainToWorker_ChildExit
|
|
147
|
+
| MainToWorker_HttpRequest
|
|
148
|
+
| MainToWorker_IPC
|
|
149
|
+
| MainToWorker_WsUpgrade
|
|
150
|
+
| MainToWorker_WsData
|
|
151
|
+
| MainToWorker_WsClose;
|
|
152
|
+
|
|
153
|
+
// --- Worker -> Main messages ---
|
|
154
|
+
|
|
155
|
+
export interface WorkerToMain_Ready {
|
|
156
|
+
type: "ready";
|
|
157
|
+
pid: number;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export interface WorkerToMain_Stdout {
|
|
161
|
+
type: "stdout";
|
|
162
|
+
data: string;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export interface WorkerToMain_Stderr {
|
|
166
|
+
type: "stderr";
|
|
167
|
+
data: string;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface WorkerToMain_Exit {
|
|
171
|
+
type: "exit";
|
|
172
|
+
exitCode: number;
|
|
173
|
+
stdout: string;
|
|
174
|
+
stderr: string;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export interface WorkerToMain_Console {
|
|
178
|
+
type: "console";
|
|
179
|
+
method: string;
|
|
180
|
+
args: string[];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export interface WorkerToMain_VFSWrite {
|
|
184
|
+
type: "vfs-write";
|
|
185
|
+
path: string;
|
|
186
|
+
content: ArrayBuffer;
|
|
187
|
+
isDirectory: boolean;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export interface WorkerToMain_VFSDelete {
|
|
191
|
+
type: "vfs-delete";
|
|
192
|
+
path: string;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export interface WorkerToMain_VFSRead {
|
|
196
|
+
type: "vfs-read";
|
|
197
|
+
requestId: number;
|
|
198
|
+
path: string;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export interface WorkerToMain_SpawnRequest {
|
|
202
|
+
type: "spawn-request";
|
|
203
|
+
requestId: number;
|
|
204
|
+
command: string;
|
|
205
|
+
args: string[];
|
|
206
|
+
cwd: string;
|
|
207
|
+
env: Record<string, string>;
|
|
208
|
+
stdio: "pipe" | "inherit";
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export interface WorkerToMain_ForkRequest {
|
|
212
|
+
type: "fork-request";
|
|
213
|
+
requestId: number;
|
|
214
|
+
modulePath: string;
|
|
215
|
+
args: string[];
|
|
216
|
+
cwd: string;
|
|
217
|
+
env: Record<string, string>;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export interface WorkerToMain_WorkerThreadRequest {
|
|
221
|
+
type: "workerthread-request";
|
|
222
|
+
requestId: number;
|
|
223
|
+
modulePath: string; // absolute path, or inline code if isEval
|
|
224
|
+
isEval?: boolean;
|
|
225
|
+
args: string[];
|
|
226
|
+
cwd: string;
|
|
227
|
+
env: Record<string, string>;
|
|
228
|
+
workerData: unknown;
|
|
229
|
+
threadId: number;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export interface WorkerToMain_SpawnSync {
|
|
233
|
+
type: "spawn-sync";
|
|
234
|
+
requestId: number;
|
|
235
|
+
command: string;
|
|
236
|
+
args: string[];
|
|
237
|
+
cwd: string;
|
|
238
|
+
env: Record<string, string>;
|
|
239
|
+
syncSlot: number; // index in the sync SAB for Atomics.wait/notify
|
|
240
|
+
shellCommand?: string;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export interface WorkerToMain_ServerListen {
|
|
244
|
+
type: "server-listen";
|
|
245
|
+
port: number;
|
|
246
|
+
hostname: string;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export interface WorkerToMain_ServerClose {
|
|
250
|
+
type: "server-close";
|
|
251
|
+
port: number;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export interface WorkerToMain_HttpRequest {
|
|
255
|
+
type: "http-request";
|
|
256
|
+
requestId: number;
|
|
257
|
+
port: number;
|
|
258
|
+
method: string;
|
|
259
|
+
path: string;
|
|
260
|
+
headers: Record<string, string>;
|
|
261
|
+
body: string | null;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export interface WorkerToMain_CwdChange {
|
|
265
|
+
type: "cwd-change";
|
|
266
|
+
cwd: string;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export interface WorkerToMain_StdinRawStatus {
|
|
270
|
+
type: "stdin-raw-status";
|
|
271
|
+
isRaw: boolean;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export interface WorkerToMain_HttpResponse {
|
|
275
|
+
type: "http-response";
|
|
276
|
+
requestId: number;
|
|
277
|
+
statusCode: number;
|
|
278
|
+
statusMessage: string;
|
|
279
|
+
headers: Record<string, string>;
|
|
280
|
+
body: string | ArrayBuffer;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export interface WorkerToMain_IPC {
|
|
284
|
+
type: "ipc-message";
|
|
285
|
+
data: unknown;
|
|
286
|
+
targetRequestId?: number;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export interface WorkerToMain_ShellDone {
|
|
290
|
+
type: "shell-done";
|
|
291
|
+
exitCode: number;
|
|
292
|
+
stdout: string;
|
|
293
|
+
stderr: string;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export interface WorkerToMain_Error {
|
|
297
|
+
type: "error";
|
|
298
|
+
message: string;
|
|
299
|
+
stack?: string;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export interface WorkerToMain_WsFrame {
|
|
303
|
+
type: "ws-frame";
|
|
304
|
+
uid: string;
|
|
305
|
+
kind: string; // "open" | "text" | "binary" | "close" | "error"
|
|
306
|
+
data?: string;
|
|
307
|
+
bytes?: number[];
|
|
308
|
+
code?: number;
|
|
309
|
+
message?: string;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export type WorkerToMainMessage =
|
|
313
|
+
| WorkerToMain_Ready
|
|
314
|
+
| WorkerToMain_Stdout
|
|
315
|
+
| WorkerToMain_Stderr
|
|
316
|
+
| WorkerToMain_Exit
|
|
317
|
+
| WorkerToMain_Console
|
|
318
|
+
| WorkerToMain_VFSWrite
|
|
319
|
+
| WorkerToMain_VFSDelete
|
|
320
|
+
| WorkerToMain_VFSRead
|
|
321
|
+
| WorkerToMain_SpawnRequest
|
|
322
|
+
| WorkerToMain_ForkRequest
|
|
323
|
+
| WorkerToMain_WorkerThreadRequest
|
|
324
|
+
| WorkerToMain_SpawnSync
|
|
325
|
+
| WorkerToMain_ServerListen
|
|
326
|
+
| WorkerToMain_ServerClose
|
|
327
|
+
| WorkerToMain_HttpRequest
|
|
328
|
+
| WorkerToMain_CwdChange
|
|
329
|
+
| WorkerToMain_StdinRawStatus
|
|
330
|
+
| WorkerToMain_HttpResponse
|
|
331
|
+
| WorkerToMain_IPC
|
|
332
|
+
| WorkerToMain_ShellDone
|
|
333
|
+
| WorkerToMain_Error
|
|
334
|
+
| WorkerToMain_WsFrame;
|
|
335
|
+
|
|
336
|
+
// --- Spawn config ---
|
|
337
|
+
|
|
338
|
+
export interface SpawnConfig {
|
|
339
|
+
command: string;
|
|
340
|
+
args: string[];
|
|
341
|
+
cwd: string;
|
|
342
|
+
env: Record<string, string>;
|
|
343
|
+
snapshot: VFSBinarySnapshot;
|
|
344
|
+
sharedBuffer?: SharedArrayBuffer;
|
|
345
|
+
syncBuffer?: SharedArrayBuffer;
|
|
346
|
+
parentPid?: number;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// --- Process info ---
|
|
350
|
+
|
|
351
|
+
export interface ProcessInfo {
|
|
352
|
+
pid: number;
|
|
353
|
+
command: string;
|
|
354
|
+
args: string[];
|
|
355
|
+
state: "starting" | "running" | "exited";
|
|
356
|
+
exitCode?: number;
|
|
357
|
+
parentPid?: number;
|
|
358
|
+
}
|