@nimbus-sh/worker 0.1.4 → 0.1.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/README.md +37 -0
- package/dist/_shared/crypto.d.ts +15 -0
- package/dist/_shared/crypto.d.ts.map +1 -0
- package/dist/_shared/crypto.js +122 -0
- package/dist/facets/manager.d.ts +24 -0
- package/dist/facets/manager.d.ts.map +1 -1
- package/dist/facets/manager.js +279 -70
- package/dist/facets/process.d.ts +11 -2
- package/dist/facets/process.d.ts.map +1 -1
- package/dist/facets/process.js +187 -21
- package/dist/facets/vite-dev-server.d.ts +2 -0
- package/dist/facets/vite-dev-server.d.ts.map +1 -1
- package/dist/facets/vite-dev-server.js +39 -12
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/loaders/child-process/spawn-facet.d.ts +1 -3
- package/dist/loaders/child-process/spawn-facet.d.ts.map +1 -1
- package/dist/loaders/child-process/spawn-facet.js +1 -12
- package/dist/loaders/child-process/spawn-pool.d.ts +1 -1
- package/dist/loaders/child-process/spawn-pool.d.ts.map +1 -1
- package/dist/loaders/child-process/spawn-pool.js +1 -6
- package/dist/loaders/loader-pool.d.ts +7 -0
- package/dist/loaders/loader-pool.d.ts.map +1 -1
- package/dist/loaders/loader-pool.js +3 -1
- package/dist/npm/installer.d.ts.map +1 -1
- package/dist/npm/installer.js +47 -27
- package/dist/npm/pre-bundle-facet.d.ts.map +1 -1
- package/dist/npm/pre-bundle-facet.js +2 -1
- package/dist/npm/resolve-one-facet.d.ts.map +1 -1
- package/dist/npm/resolve-one-facet.js +41 -13
- package/dist/npm/resolver.d.ts.map +1 -1
- package/dist/npm/resolver.js +70 -35
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +45 -21
- package/dist/router/remote-api.d.ts.map +1 -1
- package/dist/router/remote-api.js +29 -8
- package/dist/runtime/barrel-synthesizer.d.ts +7 -0
- package/dist/runtime/barrel-synthesizer.d.ts.map +1 -1
- package/dist/runtime/barrel-synthesizer.js +11 -0
- package/dist/runtime/clang-runner.d.ts +2 -2
- package/dist/runtime/clang-runner.d.ts.map +1 -1
- package/dist/runtime/clang-runner.js +64 -47
- package/dist/runtime/esbuild-service.d.ts +12 -5
- package/dist/runtime/esbuild-service.d.ts.map +1 -1
- package/dist/runtime/esbuild-service.js +28 -14
- package/dist/runtime/node-runner.d.ts +2 -0
- package/dist/runtime/node-runner.d.ts.map +1 -1
- package/dist/runtime/node-shims.d.ts +4 -2
- package/dist/runtime/node-shims.d.ts.map +1 -1
- package/dist/runtime/node-shims.js +404 -55
- package/dist/runtime/os-contracts.d.ts +128 -0
- package/dist/runtime/os-contracts.d.ts.map +1 -0
- package/dist/runtime/os-contracts.js +1 -0
- package/dist/runtime/package-manager.d.ts +31 -0
- package/dist/runtime/package-manager.d.ts.map +1 -1
- package/dist/runtime/package-manager.js +162 -15
- package/dist/runtime/port-registry.d.ts +5 -0
- package/dist/runtime/port-registry.d.ts.map +1 -1
- package/dist/runtime/port-registry.js +22 -1
- package/dist/runtime/pyodide-runtime-assets.d.ts +19 -0
- package/dist/runtime/pyodide-runtime-assets.d.ts.map +1 -0
- package/dist/runtime/pyodide-runtime-assets.js +44 -0
- package/dist/runtime/python-repl.d.ts +3 -0
- package/dist/runtime/python-repl.d.ts.map +1 -1
- package/dist/runtime/python-repl.js +18 -32
- package/dist/runtime/python-runner.d.ts +8 -9
- package/dist/runtime/python-runner.d.ts.map +1 -1
- package/dist/runtime/python-runner.js +958 -118
- package/dist/runtime/python-socket-shim.d.ts +11 -0
- package/dist/runtime/python-socket-shim.d.ts.map +1 -0
- package/dist/runtime/python-socket-shim.js +526 -0
- package/dist/runtime/require-resolver.d.ts.map +1 -1
- package/dist/runtime/require-resolver.js +2 -11
- package/dist/runtime/ruby-gems.d.ts +25 -0
- package/dist/runtime/ruby-gems.d.ts.map +1 -0
- package/dist/runtime/ruby-gems.js +582 -0
- package/dist/runtime/ruby-runner.d.ts +2 -4
- package/dist/runtime/ruby-runner.d.ts.map +1 -1
- package/dist/runtime/ruby-runner.js +335 -34
- package/dist/runtime/runtime-catalog.d.ts +16 -4
- package/dist/runtime/runtime-catalog.d.ts.map +1 -1
- package/dist/runtime/runtime-catalog.js +21 -10
- package/dist/runtime/runtime-registry.d.ts +3 -0
- package/dist/runtime/runtime-registry.d.ts.map +1 -1
- package/dist/runtime/runtime-registry.js +4 -0
- package/dist/runtime/sqlite-runtime-fs-bridge.d.ts +43 -0
- package/dist/runtime/sqlite-runtime-fs-bridge.d.ts.map +1 -0
- package/dist/runtime/sqlite-runtime-fs-bridge.js +224 -0
- package/dist/runtime/static-server.d.ts +3 -0
- package/dist/runtime/static-server.d.ts.map +1 -0
- package/dist/runtime/static-server.js +121 -0
- package/dist/runtime/vfs-snapshot.d.ts +57 -0
- package/dist/runtime/vfs-snapshot.d.ts.map +1 -0
- package/dist/runtime/vfs-snapshot.js +141 -0
- package/dist/runtime/virtual-socket-kernel.d.ts +16 -0
- package/dist/runtime/virtual-socket-kernel.d.ts.map +1 -0
- package/dist/runtime/virtual-socket-kernel.js +360 -0
- package/dist/runtime/wasi-instance.d.ts +6 -3
- package/dist/runtime/wasi-instance.d.ts.map +1 -1
- package/dist/runtime/wasm-runner.d.ts +1 -25
- package/dist/runtime/wasm-runner.d.ts.map +1 -1
- package/dist/runtime/wasm-runner.js +1 -160
- package/dist/session/agent.d.ts +43 -0
- package/dist/session/agent.d.ts.map +1 -0
- package/dist/session/agent.js +1252 -0
- package/dist/session/init.d.ts.map +1 -1
- package/dist/session/init.js +64 -19
- package/dist/session/nimbus-session.d.ts +14 -2
- package/dist/session/nimbus-session.d.ts.map +1 -1
- package/dist/session/nimbus-session.js +104 -30
- package/dist/session/programmatic.d.ts +10 -0
- package/dist/session/programmatic.d.ts.map +1 -1
- package/dist/session/programmatic.js +121 -0
- package/dist/session/routes.d.ts.map +1 -1
- package/dist/session/routes.js +19 -1
- package/dist/session/rpc.d.ts +11 -0
- package/dist/session/rpc.d.ts.map +1 -1
- package/dist/session/rpc.js +56 -43
- package/dist/session/supervisor-rpc.d.ts +15 -0
- package/dist/session/supervisor-rpc.d.ts.map +1 -1
- package/dist/session/supervisor-rpc.js +32 -0
- package/dist/session/ws.d.ts +4 -3
- package/dist/session/ws.d.ts.map +1 -1
- package/dist/session/ws.js +11 -1
- package/dist/shell/unix-commands.d.ts.map +1 -1
- package/dist/shell/unix-commands.js +52 -51
- package/dist/vfs/path.d.ts +8 -4
- package/dist/vfs/path.d.ts.map +1 -1
- package/dist/vfs/path.js +16 -4
- package/dist/vfs/sqlite-vfs.d.ts +2 -0
- package/dist/vfs/sqlite-vfs.d.ts.map +1 -1
- package/dist/vfs/sqlite-vfs.js +11 -0
- package/dist/vfs/symlink-registry.d.ts +7 -1
- package/dist/vfs/symlink-registry.d.ts.map +1 -1
- package/dist/vfs/symlink-registry.js +16 -11
- package/package.json +4 -1
- package/public/index.html +240 -0
- package/public/s/index.html +1316 -128
- package/runtime-contracts/pyodide-workerd-adapter.json +18 -0
- package/scripts/bundle-runtime.mjs +99 -24
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
*/
|
|
29
29
|
import { ReplSession } from './repl-session.js';
|
|
30
30
|
import { buildPyodidePreamble } from './python-runner.js';
|
|
31
|
+
import { readPyodideRuntimeFiles } from './pyodide-runtime-assets.js';
|
|
31
32
|
/**
|
|
32
33
|
* Adapter that owns a NimbusLoaderPool for the lifetime of the REPL
|
|
33
34
|
* session. Each push(line) is a fresh pool.submit() into the cached
|
|
@@ -124,24 +125,15 @@ class PythonReplAdapter {
|
|
|
124
125
|
if (!vfs.exists(stdlibPath)) {
|
|
125
126
|
throw new Error(`python_stdlib.zip missing at ${stdlibPath}`);
|
|
126
127
|
}
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
const HEAD_NEEDLE = 'if(d.IN_BROWSER_MAIN_THREAD)';
|
|
138
|
-
const HEAD_REPLACE = 'if(true||d.IN_BROWSER_MAIN_THREAD)';
|
|
139
|
-
if (asmJsSrc.includes(HEAD_NEEDLE)) {
|
|
140
|
-
asmJsSrc = asmJsSrc.replace(HEAD_NEEDLE, HEAD_REPLACE);
|
|
141
|
-
}
|
|
142
|
-
// Encode stdlib bytes to base64 for splice into preamble.
|
|
143
|
-
const stdlibB64 = uint8ToBase64(stdlibBytes);
|
|
144
|
-
const preamble = buildPyodidePreamble(asmJsSrc, stdlibB64);
|
|
128
|
+
const files = readPyodideRuntimeFiles({
|
|
129
|
+
asmWasmVfs: wasmPath,
|
|
130
|
+
asmJsVfs: jsPath,
|
|
131
|
+
stdlibVfs: stdlibPath,
|
|
132
|
+
lockfileVfs: `${installRoot}/share/pyodide/pyodide-lock.json`,
|
|
133
|
+
manifest: this.deps.manifest,
|
|
134
|
+
vfs,
|
|
135
|
+
});
|
|
136
|
+
const preamble = buildPyodidePreamble(files.asmJsSrc, files.stdlibB64, files.lockfileText);
|
|
145
137
|
// Create the pool. Tag MUST differ from 'python-runner' so REPL
|
|
146
138
|
// sessions don't collide with one-shot dispatches in the loader
|
|
147
139
|
// slot cache (different fnHash + different tag = separate slot).
|
|
@@ -153,14 +145,13 @@ class PythonReplAdapter {
|
|
|
153
145
|
concurrency: 1,
|
|
154
146
|
omitSupervisor: true,
|
|
155
147
|
preamble,
|
|
148
|
+
wasmModules: {
|
|
149
|
+
'pyodide.asm.wasm': toAB(files.asmWasmBytes),
|
|
150
|
+
},
|
|
156
151
|
});
|
|
157
|
-
// Stash the wasm bytes for first submit's wasmModules.
|
|
158
|
-
this.__wasmBytesAB = toAB(wasmBytes);
|
|
159
152
|
}
|
|
160
153
|
async submitFacetFn(args) {
|
|
161
|
-
const wasmModules = { 'pyodide.asm.wasm': this.__wasmBytesAB };
|
|
162
154
|
return await this.pool.submit(replStepFacetFn, args, {
|
|
163
|
-
wasmModules,
|
|
164
155
|
timeoutMs: 60_000,
|
|
165
156
|
});
|
|
166
157
|
}
|
|
@@ -535,16 +526,6 @@ function replStepFacetFn(args) {
|
|
|
535
526
|
function toAB(u8) {
|
|
536
527
|
return u8.buffer.slice(u8.byteOffset, u8.byteOffset + u8.byteLength);
|
|
537
528
|
}
|
|
538
|
-
/** Encode Uint8Array → base64 in chunks to avoid stack overflow on
|
|
539
|
-
* ~2 MiB stdlib payload. Mirrors python-runner.ts's helper. */
|
|
540
|
-
function uint8ToBase64(u8) {
|
|
541
|
-
const CHUNK = 0x8000;
|
|
542
|
-
let s = '';
|
|
543
|
-
for (let i = 0; i < u8.length; i += CHUNK) {
|
|
544
|
-
s += String.fromCharCode.apply(null, Array.from(u8.subarray(i, Math.min(i + CHUNK, u8.length))));
|
|
545
|
-
}
|
|
546
|
-
return btoa(s);
|
|
547
|
-
}
|
|
548
529
|
/**
|
|
549
530
|
* Top-level wrapper: builds a Python REPL adapter, drives a
|
|
550
531
|
* ReplSession to completion, returns the exit code.
|
|
@@ -560,3 +541,8 @@ export async function runPythonRepl(deps) {
|
|
|
560
541
|
const session = new ReplSession(adapter, deps.terminal, deps.shell);
|
|
561
542
|
return await session.run();
|
|
562
543
|
}
|
|
544
|
+
export async function warmPythonRepl(deps) {
|
|
545
|
+
const adapter = new PythonReplAdapter(deps);
|
|
546
|
+
await adapter.push('');
|
|
547
|
+
await adapter.close();
|
|
548
|
+
}
|
|
@@ -8,18 +8,17 @@
|
|
|
8
8
|
* - exit code via sys.exit(N) or unhandled exception → 1
|
|
9
9
|
* - argv passed through to sys.argv
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* Current limits:
|
|
12
12
|
* - REPL mode (`python` with no args)
|
|
13
|
-
* -
|
|
14
|
-
* - `pip install` / `loadPackage` / native-extension packages
|
|
13
|
+
* - Native Linux wheels, runtime-loaded extension modules, and extension builds
|
|
15
14
|
* - Sync HTTP (urllib3 / requests blocked without JSPI)
|
|
16
15
|
*
|
|
17
16
|
* Architecture: SAME LOADER-modules transport as clang-runner/wasm-
|
|
18
17
|
* runner. The Pyodide wasm bytes ship via the LOADER `modules` map
|
|
19
18
|
* (CSP allows wasm code-gen at module-load time, not at request
|
|
20
|
-
* time). The Pyodide.asm.js
|
|
21
|
-
* `context` field (JSON-stringified into the inner worker.js
|
|
22
|
-
* module-load).
|
|
19
|
+
* time). The workerd-adapted Pyodide.asm.js artifact and stdlib zip ride via
|
|
20
|
+
* the loader-pool `context` field (JSON-stringified into the inner worker.js
|
|
21
|
+
* at module-load).
|
|
23
22
|
*
|
|
24
23
|
* Per wasm-csp/findings.md §4b: Pyodide.asm.wasm (10.1 MB on disk)
|
|
25
24
|
* compiles in 314 ms via LOADER on PROD. With our v1 deployment of
|
|
@@ -39,11 +38,11 @@ export declare function makePythonRunnerFactory(deps: {
|
|
|
39
38
|
vfs: SqliteVFS;
|
|
40
39
|
}): (manifest: RuntimeManifest, installRoot: string, binName: string, binKind: string | undefined) => (ctx: any) => Promise<number>;
|
|
41
40
|
/**
|
|
42
|
-
* Compose the per-call preamble by splicing the
|
|
43
|
-
*
|
|
41
|
+
* Compose the per-call preamble by splicing the workerd-adapted
|
|
42
|
+
* pyodide.asm.js source ahead of the __pyodideRun helper. Workerd compiles this
|
|
44
43
|
* blob as JS at module-load time (where `var` declarations + globals
|
|
45
44
|
* assignment are allowed), then the asm.js's `var _createPyodideModule`
|
|
46
45
|
* is hoisted onto globalThis.
|
|
47
46
|
*/
|
|
48
|
-
export declare function buildPyodidePreamble(asmJsSrc: string, stdlibB64: string): string;
|
|
47
|
+
export declare function buildPyodidePreamble(asmJsSrc: string, stdlibB64: string, lockfileContents?: string): string;
|
|
49
48
|
//# sourceMappingURL=python-runner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"python-runner.d.ts","sourceRoot":"","sources":["../../src/runtime/python-runner.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"python-runner.d.ts","sourceRoot":"","sources":["../../src/runtime/python-runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAsCzD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE;IAC5C,QAAQ,EAAE,YAAY,CAAC;IACvB,GAAG,EAAE,SAAS,CAAC;CAChB,GAAG,CAAC,QAAQ,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,KAC7F,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,MAAM,CAAC,CAgNhC;AAqzBD;;;;;;GAMG;AAKH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,SAAoB,GAAG,MAAM,CAyFtH"}
|