@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.
Files changed (141) hide show
  1. package/README.md +37 -0
  2. package/dist/_shared/crypto.d.ts +15 -0
  3. package/dist/_shared/crypto.d.ts.map +1 -0
  4. package/dist/_shared/crypto.js +122 -0
  5. package/dist/facets/manager.d.ts +24 -0
  6. package/dist/facets/manager.d.ts.map +1 -1
  7. package/dist/facets/manager.js +279 -70
  8. package/dist/facets/process.d.ts +11 -2
  9. package/dist/facets/process.d.ts.map +1 -1
  10. package/dist/facets/process.js +187 -21
  11. package/dist/facets/vite-dev-server.d.ts +2 -0
  12. package/dist/facets/vite-dev-server.d.ts.map +1 -1
  13. package/dist/facets/vite-dev-server.js +39 -12
  14. package/dist/index.d.ts +2 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +2 -0
  17. package/dist/loaders/child-process/spawn-facet.d.ts +1 -3
  18. package/dist/loaders/child-process/spawn-facet.d.ts.map +1 -1
  19. package/dist/loaders/child-process/spawn-facet.js +1 -12
  20. package/dist/loaders/child-process/spawn-pool.d.ts +1 -1
  21. package/dist/loaders/child-process/spawn-pool.d.ts.map +1 -1
  22. package/dist/loaders/child-process/spawn-pool.js +1 -6
  23. package/dist/loaders/loader-pool.d.ts +7 -0
  24. package/dist/loaders/loader-pool.d.ts.map +1 -1
  25. package/dist/loaders/loader-pool.js +3 -1
  26. package/dist/npm/installer.d.ts.map +1 -1
  27. package/dist/npm/installer.js +47 -27
  28. package/dist/npm/pre-bundle-facet.d.ts.map +1 -1
  29. package/dist/npm/pre-bundle-facet.js +2 -1
  30. package/dist/npm/resolve-one-facet.d.ts.map +1 -1
  31. package/dist/npm/resolve-one-facet.js +41 -13
  32. package/dist/npm/resolver.d.ts.map +1 -1
  33. package/dist/npm/resolver.js +70 -35
  34. package/dist/router/index.d.ts.map +1 -1
  35. package/dist/router/index.js +45 -21
  36. package/dist/router/remote-api.d.ts.map +1 -1
  37. package/dist/router/remote-api.js +29 -8
  38. package/dist/runtime/barrel-synthesizer.d.ts +7 -0
  39. package/dist/runtime/barrel-synthesizer.d.ts.map +1 -1
  40. package/dist/runtime/barrel-synthesizer.js +11 -0
  41. package/dist/runtime/clang-runner.d.ts +2 -2
  42. package/dist/runtime/clang-runner.d.ts.map +1 -1
  43. package/dist/runtime/clang-runner.js +64 -47
  44. package/dist/runtime/esbuild-service.d.ts +12 -5
  45. package/dist/runtime/esbuild-service.d.ts.map +1 -1
  46. package/dist/runtime/esbuild-service.js +28 -14
  47. package/dist/runtime/node-runner.d.ts +2 -0
  48. package/dist/runtime/node-runner.d.ts.map +1 -1
  49. package/dist/runtime/node-shims.d.ts +4 -2
  50. package/dist/runtime/node-shims.d.ts.map +1 -1
  51. package/dist/runtime/node-shims.js +404 -55
  52. package/dist/runtime/os-contracts.d.ts +128 -0
  53. package/dist/runtime/os-contracts.d.ts.map +1 -0
  54. package/dist/runtime/os-contracts.js +1 -0
  55. package/dist/runtime/package-manager.d.ts +31 -0
  56. package/dist/runtime/package-manager.d.ts.map +1 -1
  57. package/dist/runtime/package-manager.js +162 -15
  58. package/dist/runtime/port-registry.d.ts +5 -0
  59. package/dist/runtime/port-registry.d.ts.map +1 -1
  60. package/dist/runtime/port-registry.js +22 -1
  61. package/dist/runtime/pyodide-runtime-assets.d.ts +19 -0
  62. package/dist/runtime/pyodide-runtime-assets.d.ts.map +1 -0
  63. package/dist/runtime/pyodide-runtime-assets.js +44 -0
  64. package/dist/runtime/python-repl.d.ts +3 -0
  65. package/dist/runtime/python-repl.d.ts.map +1 -1
  66. package/dist/runtime/python-repl.js +18 -32
  67. package/dist/runtime/python-runner.d.ts +8 -9
  68. package/dist/runtime/python-runner.d.ts.map +1 -1
  69. package/dist/runtime/python-runner.js +958 -118
  70. package/dist/runtime/python-socket-shim.d.ts +11 -0
  71. package/dist/runtime/python-socket-shim.d.ts.map +1 -0
  72. package/dist/runtime/python-socket-shim.js +526 -0
  73. package/dist/runtime/require-resolver.d.ts.map +1 -1
  74. package/dist/runtime/require-resolver.js +2 -11
  75. package/dist/runtime/ruby-gems.d.ts +25 -0
  76. package/dist/runtime/ruby-gems.d.ts.map +1 -0
  77. package/dist/runtime/ruby-gems.js +582 -0
  78. package/dist/runtime/ruby-runner.d.ts +2 -4
  79. package/dist/runtime/ruby-runner.d.ts.map +1 -1
  80. package/dist/runtime/ruby-runner.js +335 -34
  81. package/dist/runtime/runtime-catalog.d.ts +16 -4
  82. package/dist/runtime/runtime-catalog.d.ts.map +1 -1
  83. package/dist/runtime/runtime-catalog.js +21 -10
  84. package/dist/runtime/runtime-registry.d.ts +3 -0
  85. package/dist/runtime/runtime-registry.d.ts.map +1 -1
  86. package/dist/runtime/runtime-registry.js +4 -0
  87. package/dist/runtime/sqlite-runtime-fs-bridge.d.ts +43 -0
  88. package/dist/runtime/sqlite-runtime-fs-bridge.d.ts.map +1 -0
  89. package/dist/runtime/sqlite-runtime-fs-bridge.js +224 -0
  90. package/dist/runtime/static-server.d.ts +3 -0
  91. package/dist/runtime/static-server.d.ts.map +1 -0
  92. package/dist/runtime/static-server.js +121 -0
  93. package/dist/runtime/vfs-snapshot.d.ts +57 -0
  94. package/dist/runtime/vfs-snapshot.d.ts.map +1 -0
  95. package/dist/runtime/vfs-snapshot.js +141 -0
  96. package/dist/runtime/virtual-socket-kernel.d.ts +16 -0
  97. package/dist/runtime/virtual-socket-kernel.d.ts.map +1 -0
  98. package/dist/runtime/virtual-socket-kernel.js +360 -0
  99. package/dist/runtime/wasi-instance.d.ts +6 -3
  100. package/dist/runtime/wasi-instance.d.ts.map +1 -1
  101. package/dist/runtime/wasm-runner.d.ts +1 -25
  102. package/dist/runtime/wasm-runner.d.ts.map +1 -1
  103. package/dist/runtime/wasm-runner.js +1 -160
  104. package/dist/session/agent.d.ts +43 -0
  105. package/dist/session/agent.d.ts.map +1 -0
  106. package/dist/session/agent.js +1252 -0
  107. package/dist/session/init.d.ts.map +1 -1
  108. package/dist/session/init.js +64 -19
  109. package/dist/session/nimbus-session.d.ts +14 -2
  110. package/dist/session/nimbus-session.d.ts.map +1 -1
  111. package/dist/session/nimbus-session.js +104 -30
  112. package/dist/session/programmatic.d.ts +10 -0
  113. package/dist/session/programmatic.d.ts.map +1 -1
  114. package/dist/session/programmatic.js +121 -0
  115. package/dist/session/routes.d.ts.map +1 -1
  116. package/dist/session/routes.js +19 -1
  117. package/dist/session/rpc.d.ts +11 -0
  118. package/dist/session/rpc.d.ts.map +1 -1
  119. package/dist/session/rpc.js +56 -43
  120. package/dist/session/supervisor-rpc.d.ts +15 -0
  121. package/dist/session/supervisor-rpc.d.ts.map +1 -1
  122. package/dist/session/supervisor-rpc.js +32 -0
  123. package/dist/session/ws.d.ts +4 -3
  124. package/dist/session/ws.d.ts.map +1 -1
  125. package/dist/session/ws.js +11 -1
  126. package/dist/shell/unix-commands.d.ts.map +1 -1
  127. package/dist/shell/unix-commands.js +52 -51
  128. package/dist/vfs/path.d.ts +8 -4
  129. package/dist/vfs/path.d.ts.map +1 -1
  130. package/dist/vfs/path.js +16 -4
  131. package/dist/vfs/sqlite-vfs.d.ts +2 -0
  132. package/dist/vfs/sqlite-vfs.d.ts.map +1 -1
  133. package/dist/vfs/sqlite-vfs.js +11 -0
  134. package/dist/vfs/symlink-registry.d.ts +7 -1
  135. package/dist/vfs/symlink-registry.d.ts.map +1 -1
  136. package/dist/vfs/symlink-registry.js +16 -11
  137. package/package.json +4 -1
  138. package/public/index.html +240 -0
  139. package/public/s/index.html +1316 -128
  140. package/runtime-contracts/pyodide-workerd-adapter.json +18 -0
  141. 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 wasmBytes = vfs.readFile(wasmPath);
128
- const jsBytes = vfs.readFile(jsPath);
129
- const stdlibBytes = vfs.readFile(stdlibPath);
130
- // Apply the same asm.js source-patches python-runner.ts:317-331 does.
131
- let asmJsSrc = new TextDecoder('utf-8').decode(jsBytes);
132
- const PATCH_NEEDLE = 'else throw new Error("Cannot determine runtime environment")';
133
- const PATCH_REPLACE = '/* nimbus-patch: was: ' + PATCH_NEEDLE + ' */';
134
- if (asmJsSrc.includes(PATCH_NEEDLE)) {
135
- asmJsSrc = asmJsSrc.replace(PATCH_NEEDLE, PATCH_REPLACE);
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
- * Out of v1 (queued for v2/v3):
11
+ * Current limits:
12
12
  * - REPL mode (`python` with no args)
13
- * - File I/O beyond reading the entry script
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 + stdlib zip ride via the loader-pool
21
- * `context` field (JSON-stringified into the inner worker.js at
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 pyodide.asm.js source
43
- * verbatim ahead of the __pyodideRun helper. Workerd compiles this
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;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CA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