wasm-idle 0.7.2 → 1.0.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.
Files changed (386) hide show
  1. package/README.md +760 -81
  2. package/dist/index.d.ts +4 -9
  3. package/dist/index.js +2 -4
  4. package/dist/playground/applicationAssets.d.ts +4 -0
  5. package/dist/playground/applicationAssets.js +277 -0
  6. package/dist/playground/assemblyscript.d.ts +41 -0
  7. package/dist/playground/assemblyscript.js +630 -0
  8. package/dist/playground/assetBridge.d.ts +18 -7
  9. package/dist/playground/assetBridge.js +824 -100
  10. package/dist/playground/assets.d.ts +813 -19
  11. package/dist/playground/assets.js +2096 -156
  12. package/dist/playground/awk.d.ts +5 -0
  13. package/dist/playground/awk.js +60 -0
  14. package/dist/playground/bash.d.ts +53 -0
  15. package/dist/playground/bash.js +1096 -0
  16. package/dist/playground/bashWorkerProtocol.d.ts +88 -0
  17. package/dist/playground/bashWorkerProtocol.js +135 -0
  18. package/dist/playground/bqn.d.ts +5 -0
  19. package/dist/playground/bqn.js +57 -0
  20. package/dist/playground/bqnPreflight.d.ts +26 -0
  21. package/dist/playground/bqnPreflight.js +399 -0
  22. package/dist/playground/c3.d.ts +15 -0
  23. package/dist/playground/c3.js +154 -0
  24. package/dist/playground/clang.d.ts +35 -19
  25. package/dist/playground/clang.js +241 -52
  26. package/dist/playground/clangAssetIntegrity.d.ts +32 -0
  27. package/dist/playground/clangAssetIntegrity.js +8 -0
  28. package/dist/playground/clojurescript.d.ts +5 -0
  29. package/dist/playground/clojurescript.js +59 -0
  30. package/dist/playground/clojurescriptPreflight.d.ts +26 -0
  31. package/dist/playground/clojurescriptPreflight.js +383 -0
  32. package/dist/playground/cobol.d.ts +46 -0
  33. package/dist/playground/cobol.js +703 -0
  34. package/dist/playground/d.d.ts +47 -0
  35. package/dist/playground/d.js +644 -0
  36. package/dist/playground/dOuterAssets.d.ts +16 -0
  37. package/dist/playground/dOuterAssets.js +163 -0
  38. package/dist/playground/dotnet.d.ts +99 -0
  39. package/dist/playground/dotnet.js +1131 -0
  40. package/dist/playground/duckdb.d.ts +36 -0
  41. package/dist/playground/duckdb.js +542 -0
  42. package/dist/playground/elixir.d.ts +18 -10
  43. package/dist/playground/elixir.js +630 -96
  44. package/dist/playground/elixirAssets.d.ts +6 -0
  45. package/dist/playground/elixirAssets.js +33 -0
  46. package/dist/playground/executionObservation.d.ts +22 -0
  47. package/dist/playground/executionObservation.js +65 -0
  48. package/dist/playground/forth.d.ts +5 -0
  49. package/dist/playground/forth.js +53 -0
  50. package/dist/playground/forthPreflight.d.ts +24 -0
  51. package/dist/playground/forthPreflight.js +198 -0
  52. package/dist/playground/fortran.d.ts +47 -0
  53. package/dist/playground/fortran.js +651 -0
  54. package/dist/playground/fortranAssets.d.ts +6 -0
  55. package/dist/playground/fortranAssets.js +27 -0
  56. package/dist/playground/gleam.d.ts +6 -0
  57. package/dist/playground/gleam.js +33 -0
  58. package/dist/playground/go.d.ts +17 -11
  59. package/dist/playground/go.js +376 -72
  60. package/dist/playground/goDebugInstrumentation.d.ts +1 -0
  61. package/dist/playground/goDebugInstrumentation.js +229 -0
  62. package/dist/playground/haskell.d.ts +44 -0
  63. package/dist/playground/haskell.js +678 -0
  64. package/dist/playground/haskellAssets.d.ts +24 -0
  65. package/dist/playground/haskellAssets.js +93 -0
  66. package/dist/playground/index.d.ts +1 -1
  67. package/dist/playground/index.js +360 -111
  68. package/dist/playground/j.d.ts +5 -0
  69. package/dist/playground/j.js +60 -0
  70. package/dist/playground/jPreflight.d.ts +26 -0
  71. package/dist/playground/jPreflight.js +372 -0
  72. package/dist/playground/janet.d.ts +5 -0
  73. package/dist/playground/janet.js +64 -0
  74. package/dist/playground/java.d.ts +24 -10
  75. package/dist/playground/java.js +706 -84
  76. package/dist/playground/javaSource.d.ts +5 -0
  77. package/dist/playground/javaSource.js +16 -0
  78. package/dist/playground/javaStdin.d.ts +1 -1
  79. package/dist/playground/javaStdin.js +13 -4
  80. package/dist/playground/julia.d.ts +5 -0
  81. package/dist/playground/julia.js +64 -0
  82. package/dist/playground/lfortran.d.ts +8 -0
  83. package/dist/playground/lfortran.js +30 -0
  84. package/dist/playground/lfortranAssets.d.ts +21 -0
  85. package/dist/playground/lfortranAssets.js +118 -0
  86. package/dist/playground/lisp.d.ts +45 -0
  87. package/dist/playground/lisp.js +640 -0
  88. package/dist/playground/lispAssets.d.ts +9 -0
  89. package/dist/playground/lispAssets.js +74 -0
  90. package/dist/playground/lldbManifest.d.ts +3 -0
  91. package/dist/playground/lldbManifest.js +155 -0
  92. package/dist/playground/lldbSession.d.ts +115 -0
  93. package/dist/playground/lldbSession.js +1347 -0
  94. package/dist/playground/loadingProgress.d.ts +16 -0
  95. package/dist/playground/loadingProgress.js +166 -0
  96. package/dist/playground/lua.d.ts +44 -0
  97. package/dist/playground/lua.js +630 -0
  98. package/dist/playground/nim.d.ts +5 -0
  99. package/dist/playground/nim.js +76 -0
  100. package/dist/playground/objectivec.d.ts +39 -0
  101. package/dist/playground/objectivec.js +288 -0
  102. package/dist/playground/ocaml.d.ts +28 -10
  103. package/dist/playground/ocaml.js +815 -253
  104. package/dist/playground/octave.d.ts +43 -0
  105. package/dist/playground/octave.js +783 -0
  106. package/dist/playground/options.d.ts +19 -40
  107. package/dist/playground/options.js +2 -1
  108. package/dist/playground/pascal.d.ts +5 -0
  109. package/dist/playground/pascal.js +60 -0
  110. package/dist/playground/perl.d.ts +5 -0
  111. package/dist/playground/perl.js +61 -0
  112. package/dist/playground/php.d.ts +44 -0
  113. package/dist/playground/php.js +665 -0
  114. package/dist/playground/prolog.d.ts +6 -0
  115. package/dist/playground/prolog.js +75 -0
  116. package/dist/playground/python.d.ts +20 -14
  117. package/dist/playground/python.js +445 -101
  118. package/dist/playground/pythonPackageLock.d.ts +6 -0
  119. package/dist/playground/pythonPackageLock.js +56 -0
  120. package/dist/playground/r.d.ts +44 -0
  121. package/dist/playground/r.js +637 -0
  122. package/dist/playground/ruby.d.ts +46 -0
  123. package/dist/playground/ruby.js +732 -0
  124. package/dist/playground/rubyAssets.d.ts +23 -0
  125. package/dist/playground/rubyAssets.js +68 -0
  126. package/dist/playground/rubyTestPreflight.d.ts +2 -0
  127. package/dist/playground/rubyTestPreflight.js +18 -0
  128. package/dist/playground/runtimeModule.d.ts +1 -0
  129. package/dist/playground/runtimeModule.js +5 -0
  130. package/dist/playground/rust.d.ts +44 -13
  131. package/dist/playground/rust.js +714 -76
  132. package/dist/playground/rustExecutableGraph.d.ts +85 -0
  133. package/dist/playground/rustExecutableGraph.js +946 -0
  134. package/dist/playground/rustWorkerLimits.d.ts +17 -0
  135. package/dist/playground/rustWorkerLimits.js +34 -0
  136. package/dist/playground/sandbox.d.ts +16 -10
  137. package/dist/playground/sharedBuffer.d.ts +6 -0
  138. package/dist/playground/sharedBuffer.js +12 -0
  139. package/dist/playground/sqlite.d.ts +38 -0
  140. package/dist/playground/sqlite.js +550 -0
  141. package/dist/playground/staticRuntimeModuleVersion.d.ts +1 -0
  142. package/dist/playground/staticRuntimeModuleVersion.js +2 -0
  143. package/dist/playground/staticRuntimePreflight.d.ts +13 -0
  144. package/dist/playground/staticRuntimePreflight.js +231 -0
  145. package/dist/playground/staticRuntimePreflightExecute.d.ts +8 -0
  146. package/dist/playground/staticRuntimePreflightExecute.js +66 -0
  147. package/dist/playground/staticRuntimePreflightProtocol.d.ts +68 -0
  148. package/dist/playground/staticRuntimePreflightProtocol.js +339 -0
  149. package/dist/playground/staticStdinRing.d.ts +45 -0
  150. package/dist/playground/staticStdinRing.js +158 -0
  151. package/dist/playground/staticWorkerRuntime.d.ts +154 -0
  152. package/dist/playground/staticWorkerRuntime.js +1917 -0
  153. package/dist/playground/stdinBuffer.d.ts +9 -7
  154. package/dist/playground/stdinBuffer.js +9 -18
  155. package/dist/playground/swift.d.ts +5 -0
  156. package/dist/playground/swift.js +17 -0
  157. package/dist/playground/tcl.d.ts +5 -0
  158. package/dist/playground/tcl.js +62 -0
  159. package/dist/playground/teavmConfig.d.ts +1 -1
  160. package/dist/playground/teavmConfig.js +2 -2
  161. package/dist/playground/tinygo.d.ts +48 -18
  162. package/dist/playground/tinygo.js +1202 -329
  163. package/dist/playground/tinygoExecutableGraph.d.ts +44 -0
  164. package/dist/playground/tinygoExecutableGraph.js +449 -0
  165. package/dist/playground/typescript.d.ts +55 -0
  166. package/dist/playground/typescript.js +924 -0
  167. package/dist/playground/wasm.d.ts +43 -0
  168. package/dist/playground/wasm.js +608 -0
  169. package/dist/playground/wasmAwkVersion.d.ts +59 -0
  170. package/dist/playground/wasmAwkVersion.js +31 -0
  171. package/dist/playground/wasmBashVersion.d.ts +63 -0
  172. package/dist/playground/wasmBashVersion.js +36 -0
  173. package/dist/playground/wasmBqnVersion.d.ts +24 -0
  174. package/dist/playground/wasmBqnVersion.js +24 -0
  175. package/dist/playground/wasmC3Version.d.ts +20 -0
  176. package/dist/playground/wasmC3Version.js +21 -0
  177. package/dist/playground/wasmClojureScriptVersion.d.ts +21 -0
  178. package/dist/playground/wasmClojureScriptVersion.js +21 -0
  179. package/dist/playground/wasmDIntegrity.d.ts +15 -0
  180. package/dist/playground/wasmDIntegrity.js +15 -0
  181. package/dist/playground/wasmDVersion.d.ts +1 -0
  182. package/dist/playground/wasmDVersion.js +1 -0
  183. package/dist/playground/wasmDebugVersion.d.ts +6 -0
  184. package/dist/playground/wasmDebugVersion.js +6 -0
  185. package/dist/playground/wasmDotnetVersion.d.ts +1 -0
  186. package/dist/playground/wasmDotnetVersion.js +1 -0
  187. package/dist/playground/wasmElixirVersion.d.ts +21 -1
  188. package/dist/playground/wasmElixirVersion.js +21 -1
  189. package/dist/playground/wasmForthVersion.d.ts +18 -0
  190. package/dist/playground/wasmForthVersion.js +18 -0
  191. package/dist/playground/wasmFortranExecutionAssets.d.ts +15 -0
  192. package/dist/playground/wasmFortranExecutionAssets.js +15 -0
  193. package/dist/playground/wasmFortranVersion.d.ts +1 -0
  194. package/dist/playground/wasmFortranVersion.js +1 -0
  195. package/dist/playground/wasmGleamVersion.d.ts +5 -0
  196. package/dist/playground/wasmGleamVersion.js +5 -0
  197. package/dist/playground/wasmGoVersion.d.ts +1 -1
  198. package/dist/playground/wasmGoVersion.js +1 -1
  199. package/dist/playground/wasmHaskellVersion.d.ts +1 -0
  200. package/dist/playground/wasmHaskellVersion.js +1 -0
  201. package/dist/playground/wasmJVersion.d.ts +24 -0
  202. package/dist/playground/wasmJVersion.js +24 -0
  203. package/dist/playground/wasmJanetVersion.d.ts +53 -0
  204. package/dist/playground/wasmJanetVersion.js +30 -0
  205. package/dist/playground/wasmJuliaVersion.d.ts +71 -0
  206. package/dist/playground/wasmJuliaVersion.js +39 -0
  207. package/dist/playground/wasmLfortranVersion.d.ts +28 -0
  208. package/dist/playground/wasmLfortranVersion.js +29 -0
  209. package/dist/playground/wasmLispVersion.d.ts +1 -0
  210. package/dist/playground/wasmLispVersion.js +1 -0
  211. package/dist/playground/wasmLuaVersion.d.ts +1 -0
  212. package/dist/playground/wasmLuaVersion.js +1 -0
  213. package/dist/playground/wasmNimVersion.d.ts +125 -0
  214. package/dist/playground/wasmNimVersion.js +66 -0
  215. package/dist/playground/wasmObjectiveCVersion.d.ts +27 -0
  216. package/dist/playground/wasmObjectiveCVersion.js +27 -0
  217. package/dist/playground/wasmOcamlVersion.d.ts +12 -1
  218. package/dist/playground/wasmOcamlVersion.js +12 -1
  219. package/dist/playground/wasmOctaveVersion.d.ts +1 -0
  220. package/dist/playground/wasmOctaveVersion.js +1 -0
  221. package/dist/playground/wasmPascalVersion.d.ts +61 -0
  222. package/dist/playground/wasmPascalVersion.js +34 -0
  223. package/dist/playground/wasmPerlVersion.d.ts +71 -0
  224. package/dist/playground/wasmPerlVersion.js +39 -0
  225. package/dist/playground/wasmPrologVersion.d.ts +31 -0
  226. package/dist/playground/wasmPrologVersion.js +31 -0
  227. package/dist/playground/wasmRVersion.d.ts +1 -0
  228. package/dist/playground/wasmRVersion.js +1 -0
  229. package/dist/playground/wasmRustVersion.d.ts +1306 -1
  230. package/dist/playground/wasmRustVersion.js +1458 -1
  231. package/dist/playground/wasmSwiftVersion.d.ts +1 -0
  232. package/dist/playground/wasmSwiftVersion.js +1 -0
  233. package/dist/playground/wasmTclVersion.d.ts +85 -0
  234. package/dist/playground/wasmTclVersion.js +46 -0
  235. package/dist/playground/wasmTinyGoVersion.d.ts +98 -1
  236. package/dist/playground/wasmTinyGoVersion.js +107 -1
  237. package/dist/playground/wasmTypeScriptVersion.d.ts +5 -0
  238. package/dist/playground/wasmTypeScriptVersion.js +5 -0
  239. package/dist/playground/wasmWatVersion.d.ts +1 -0
  240. package/dist/playground/wasmWatVersion.js +1 -0
  241. package/dist/playground/wasmZigVersion.d.ts +13 -0
  242. package/dist/playground/wasmZigVersion.js +13 -0
  243. package/dist/playground/wat.d.ts +44 -0
  244. package/dist/playground/wat.js +622 -0
  245. package/dist/playground/worker/assemblyscript.js +339 -0
  246. package/dist/playground/worker/assets.d.ts +7 -0
  247. package/dist/playground/worker/assets.js +288 -39
  248. package/dist/playground/worker/bash.js +338 -0
  249. package/dist/playground/worker/bashNestedBootstrap.d.ts +6 -0
  250. package/dist/playground/worker/bashNestedBootstrap.js +59 -0
  251. package/dist/playground/worker/bashRuntime.d.ts +89 -0
  252. package/dist/playground/worker/bashRuntime.js +982 -0
  253. package/dist/playground/worker/clang.js +92 -13
  254. package/dist/playground/worker/cobol.js +107 -0
  255. package/dist/playground/worker/d.js +199 -0
  256. package/dist/playground/worker/dotnet.js +141 -0
  257. package/dist/playground/worker/duckdb.d.ts +1 -0
  258. package/dist/playground/worker/duckdb.js +136 -0
  259. package/dist/playground/worker/elixir.js +307 -41
  260. package/dist/playground/worker/fortran.d.ts +1 -0
  261. package/dist/playground/worker/fortran.js +295 -0
  262. package/dist/playground/worker/go.js +246 -40
  263. package/dist/playground/worker/haskell.d.ts +7 -0
  264. package/dist/playground/worker/haskell.js +465 -0
  265. package/dist/playground/worker/java.js +59 -20
  266. package/dist/playground/worker/lisp.d.ts +1 -0
  267. package/dist/playground/worker/lisp.js +195 -0
  268. package/dist/playground/worker/lua.d.ts +1 -0
  269. package/dist/playground/worker/lua.js +163 -0
  270. package/dist/playground/worker/objectivec.d.ts +1 -0
  271. package/dist/playground/worker/objectivec.js +10 -0
  272. package/dist/playground/worker/ocaml.js +206 -58
  273. package/dist/playground/worker/php.d.ts +1 -0
  274. package/dist/playground/worker/php.js +261 -0
  275. package/dist/playground/worker/python.js +201 -44
  276. package/dist/playground/worker/r.d.ts +1 -0
  277. package/dist/playground/worker/r.js +192 -0
  278. package/dist/playground/worker/ruby.d.ts +1 -0
  279. package/dist/playground/worker/ruby.js +248 -0
  280. package/dist/playground/worker/runtimeAssetFetch.d.ts +15 -0
  281. package/dist/playground/worker/runtimeAssetFetch.js +375 -0
  282. package/dist/playground/worker/rust.js +546 -20
  283. package/dist/playground/worker/sqlite.d.ts +1 -0
  284. package/dist/playground/worker/sqlite.js +112 -0
  285. package/dist/playground/worker/staticRuntimePreflight.d.ts +1 -0
  286. package/dist/playground/worker/staticRuntimePreflight.js +56 -0
  287. package/dist/playground/worker/tinygo.js +34 -9
  288. package/dist/playground/worker/typescript.d.ts +1 -0
  289. package/dist/playground/worker/typescript.js +251 -0
  290. package/dist/playground/worker/wasm.d.ts +1 -0
  291. package/dist/playground/worker/wasm.js +273 -0
  292. package/dist/playground/worker/wat.d.ts +1 -0
  293. package/dist/playground/worker/wat.js +188 -0
  294. package/dist/playground/worker/zig.d.ts +8 -0
  295. package/dist/playground/worker/zig.js +578 -0
  296. package/dist/playground/workerProgress.d.ts +15 -0
  297. package/dist/playground/workerProgress.js +72 -0
  298. package/dist/playground/workerSession.d.ts +28 -0
  299. package/dist/playground/workerSession.js +164 -0
  300. package/dist/playground/zig.d.ts +46 -0
  301. package/dist/playground/zig.js +690 -0
  302. package/dist/playground/zigAssets.d.ts +6 -0
  303. package/dist/playground/zigAssets.js +49 -0
  304. package/package.json +234 -105
  305. package/dist/clang/app.d.ts +0 -75
  306. package/dist/clang/app.js +0 -744
  307. package/dist/clang/apply.d.ts +0 -2
  308. package/dist/clang/apply.js +0 -11
  309. package/dist/clang/color.d.ts +0 -3
  310. package/dist/clang/color.js +0 -3
  311. package/dist/clang/encode.d.ts +0 -4
  312. package/dist/clang/encode.js +0 -20
  313. package/dist/clang/error.d.ts +0 -14
  314. package/dist/clang/error.js +0 -27
  315. package/dist/clang/gccCompat.d.ts +0 -15
  316. package/dist/clang/gccCompat.js +0 -767
  317. package/dist/clang/index.d.ts +0 -85
  318. package/dist/clang/index.js +0 -1077
  319. package/dist/clang/memory/index.d.ts +0 -4
  320. package/dist/clang/memory/index.js +0 -4
  321. package/dist/clang/memory/memFs.d.ts +0 -35
  322. package/dist/clang/memory/memFs.js +0 -132
  323. package/dist/clang/memory/memory.d.ts +0 -22
  324. package/dist/clang/memory/memory.js +0 -73
  325. package/dist/clang/memory/tar.d.ts +0 -2
  326. package/dist/clang/memory/tar.js +0 -59
  327. package/dist/clang/url.d.ts +0 -4
  328. package/dist/clang/url.js +0 -5
  329. package/dist/clang/wasm.d.ts +0 -4
  330. package/dist/clang/wasm.js +0 -50
  331. package/dist/clangd/config.d.ts +0 -18
  332. package/dist/clangd/config.js +0 -14
  333. package/dist/clangd/jsonStream.d.ts +0 -9
  334. package/dist/clangd/jsonStream.js +0 -48
  335. package/dist/clangd/session.d.ts +0 -18
  336. package/dist/clangd/session.js +0 -112
  337. package/dist/clangd/worker.js +0 -131
  338. package/dist/debug/controller.svelte.d.ts +0 -43
  339. package/dist/debug/controller.svelte.js +0 -268
  340. package/dist/debug/editor/index.d.ts +0 -2
  341. package/dist/debug/editor/index.js +0 -1
  342. package/dist/debug/editor/monaco.d.ts +0 -26
  343. package/dist/debug/editor/monaco.js +0 -128
  344. package/dist/debug/expression.d.ts +0 -26
  345. package/dist/debug/expression.js +0 -547
  346. package/dist/debug/index.d.ts +0 -8
  347. package/dist/debug/index.js +0 -5
  348. package/dist/debug/language/cpp.d.ts +0 -2
  349. package/dist/debug/language/cpp.js +0 -7
  350. package/dist/debug/language/index.d.ts +0 -3
  351. package/dist/debug/language/index.js +0 -2
  352. package/dist/debug/language/python.d.ts +0 -2
  353. package/dist/debug/language/python.js +0 -14
  354. package/dist/debug/language/types.d.ts +0 -6
  355. package/dist/debug/locals.d.ts +0 -2
  356. package/dist/debug/locals.js +0 -8
  357. package/dist/lsp/cpp/server.d.ts +0 -2
  358. package/dist/lsp/cpp/server.js +0 -68
  359. package/dist/lsp/index.d.ts +0 -5
  360. package/dist/lsp/index.js +0 -4
  361. package/dist/lsp/python/main.worker.js +0 -92
  362. package/dist/lsp/python/package/arcturus_python_lsp/__init__.py +0 -3
  363. package/dist/lsp/python/package/arcturus_python_lsp/server.py +0 -462
  364. package/dist/lsp/python/server.d.ts +0 -2
  365. package/dist/lsp/python/server.js +0 -54
  366. package/dist/lsp/registry.d.ts +0 -2
  367. package/dist/lsp/registry.js +0 -12
  368. package/dist/lsp/runtime.d.ts +0 -5
  369. package/dist/lsp/runtime.js +0 -31
  370. package/dist/lsp/types.d.ts +0 -17
  371. package/dist/terminal/Terminal.svelte +0 -422
  372. package/dist/terminal/Terminal.svelte.d.ts +0 -26
  373. package/dist/terminal/index.d.ts +0 -7
  374. package/dist/terminal/index.js +0 -5
  375. package/dist/terminal/plugin/index.d.ts +0 -9
  376. package/dist/terminal/plugin/index.js +0 -19
  377. package/dist/terminal/theme.d.ts +0 -49
  378. package/dist/terminal/theme.js +0 -49
  379. package/dist/terminal/types.d.ts +0 -18
  380. package/dist/utils/vscodeJsonrpcBrowser.d.ts +0 -5
  381. package/dist/utils/vscodeJsonrpcBrowser.js +0 -4
  382. /package/dist/{clangd/worker.d.ts → playground/worker/assemblyscript.d.ts} +0 -0
  383. /package/dist/{debug/language/types.js → playground/worker/bash.d.ts} +0 -0
  384. /package/dist/{lsp/python/main.worker.d.ts → playground/worker/cobol.d.ts} +0 -0
  385. /package/dist/{lsp/types.js → playground/worker/d.d.ts} +0 -0
  386. /package/dist/{terminal/types.js → playground/worker/dotnet.d.ts} +0 -0
@@ -0,0 +1,982 @@
1
+ import {} from '../options';
2
+ import { createBashNestedBootstrapSource } from './bashNestedBootstrap';
3
+ import { BusyError, DEFAULT_WORKSPACE_LIMITS, OutputLimitError, RuntimeConfigurationError, TimeoutError, resolveExecutionLimits, verifyBashRuntimePreflightPayload, validateExecutionWorkspace } from '@wasm-idle/core';
4
+ const abortReason = (signal, phase) => {
5
+ const reason = signal.reason;
6
+ return reason !== undefined
7
+ ? reason
8
+ : new DOMException(phase === 'startup' ? 'Bash runtime startup aborted' : 'Bash execution aborted', 'AbortError');
9
+ };
10
+ const EXECUTION_LIMIT_KEYS = [
11
+ 'assetTimeoutMs',
12
+ 'startupTimeoutMs',
13
+ 'compileTimeoutMs',
14
+ 'runTimeoutMs',
15
+ 'maxOutputBytes',
16
+ 'maxDiagnostics',
17
+ 'maxWorkspaceBytes',
18
+ 'maxAssetBytes',
19
+ 'maxWasmMemoryBytes',
20
+ 'maxWorkers',
21
+ 'maxThreads'
22
+ ];
23
+ class BashWorkerRuntime {
24
+ output;
25
+ outputBytes;
26
+ oncompilerdiagnostic;
27
+ webcUrl = '';
28
+ runtimePackage = null;
29
+ instance = null;
30
+ stdinWriter = null;
31
+ outputController = null;
32
+ pendingInput = [];
33
+ pendingEof = false;
34
+ activeLoadReject = null;
35
+ activeLoadCleanup = null;
36
+ loadGeneration = 0;
37
+ sdkModule = null;
38
+ sdkRuntime = null;
39
+ sdkBlobUrl = '';
40
+ nestedWorkerBlobUrl = '';
41
+ activeReject = null;
42
+ activeRunCleanup = null;
43
+ begin = 0;
44
+ elapse = 0;
45
+ uid = 0;
46
+ exit = true;
47
+ activeOperation = null;
48
+ importVerifiedSdkModule;
49
+ constructor(dependencies = {}) {
50
+ this.importVerifiedSdkModule =
51
+ dependencies.importVerifiedSdkModule ??
52
+ ((url) => import(/* @vite-ignore */ url));
53
+ }
54
+ beginOperation(phase) {
55
+ if (this.activeOperation) {
56
+ throw new BusyError('Bash runtime already has an active operation', {
57
+ runtimeId: 'BASH',
58
+ phase: this.activeOperation.phase
59
+ });
60
+ }
61
+ const operation = {
62
+ token: Symbol(phase),
63
+ phase,
64
+ cancelled: false,
65
+ cleanedUp: false,
66
+ cleanups: [],
67
+ abortController: new AbortController()
68
+ };
69
+ this.activeOperation = operation;
70
+ return operation;
71
+ }
72
+ isOperationActive(operation) {
73
+ return this.activeOperation?.token === operation.token && !operation.cancelled;
74
+ }
75
+ requireOperationActive(operation) {
76
+ if (this.isOperationActive(operation))
77
+ return;
78
+ throw operation.cancelled
79
+ ? operation.cancellationReason
80
+ : operation.phase === 'startup'
81
+ ? 'Bash runtime startup cancelled'
82
+ : 'Bash execution cancelled';
83
+ }
84
+ snapshotExecutionLimits(operation, source) {
85
+ const snapshot = {};
86
+ if (source) {
87
+ for (const key of EXECUTION_LIMIT_KEYS) {
88
+ this.requireOperationActive(operation);
89
+ const value = source[key];
90
+ this.requireOperationActive(operation);
91
+ if (value !== undefined) {
92
+ snapshot[key] = value;
93
+ }
94
+ }
95
+ }
96
+ const limits = resolveExecutionLimits(snapshot);
97
+ this.requireOperationActive(operation);
98
+ return limits;
99
+ }
100
+ releaseOperation(operation) {
101
+ if (this.activeOperation?.token !== operation.token)
102
+ return false;
103
+ this.activeOperation = null;
104
+ return true;
105
+ }
106
+ cleanupOperation(operation) {
107
+ if (operation.cleanedUp)
108
+ return;
109
+ operation.cleanedUp = true;
110
+ const cleanups = operation.cleanups.splice(0);
111
+ for (const cleanup of cleanups) {
112
+ try {
113
+ cleanup();
114
+ }
115
+ catch {
116
+ // Caller-owned cleanup must not replace the operation result.
117
+ }
118
+ }
119
+ }
120
+ abortOperationSignal(operation, reason) {
121
+ try {
122
+ operation.abortController.abort(reason);
123
+ }
124
+ catch {
125
+ // Internal abort cleanup must not replace the operation result.
126
+ }
127
+ }
128
+ bindOperationTimeout(operation, timeoutMs) {
129
+ if (!this.isOperationActive(operation))
130
+ return;
131
+ let timeout;
132
+ operation.cleanups.push(() => {
133
+ if (timeout !== undefined)
134
+ clearTimeout(timeout);
135
+ });
136
+ try {
137
+ timeout = setTimeout(() => {
138
+ if (!this.isOperationActive(operation))
139
+ return;
140
+ const label = operation.phase === 'startup' ? 'startup' : 'execution';
141
+ this.terminate(new TimeoutError(`Bash ${label} timed out after ${timeoutMs} ms`, {
142
+ phase: operation.phase,
143
+ runtimeId: 'BASH',
144
+ timeoutMs
145
+ }));
146
+ }, timeoutMs);
147
+ if (operation.cleanedUp)
148
+ clearTimeout(timeout);
149
+ }
150
+ catch (error) {
151
+ if (this.isOperationActive(operation))
152
+ this.terminate(error);
153
+ }
154
+ }
155
+ releaseBeforeSession(operation, reason) {
156
+ const outcome = operation.cancelled ? operation.cancellationReason : reason;
157
+ this.releaseOperation(operation);
158
+ this.cleanupOperation(operation);
159
+ return outcome;
160
+ }
161
+ bindPreSessionAbort(operation, signal) {
162
+ if (!signal || !this.isOperationActive(operation))
163
+ return () => undefined;
164
+ let registered = false;
165
+ let unbound = false;
166
+ const unbind = () => {
167
+ if (unbound)
168
+ return;
169
+ unbound = true;
170
+ if (registered)
171
+ signal.removeEventListener('abort', onAbort);
172
+ };
173
+ const onAbort = () => {
174
+ if (!this.isOperationActive(operation))
175
+ return;
176
+ let reason;
177
+ try {
178
+ reason = abortReason(signal, operation.phase);
179
+ }
180
+ catch (error) {
181
+ reason = error;
182
+ }
183
+ if (!this.isOperationActive(operation))
184
+ return;
185
+ operation.cancelled = true;
186
+ operation.cancellationReason = reason;
187
+ this.releaseOperation(operation);
188
+ this.cleanupOperation(operation);
189
+ this.abortOperationSignal(operation, reason);
190
+ };
191
+ operation.cleanups.push(unbind);
192
+ try {
193
+ const alreadyAborted = signal.aborted;
194
+ if (!this.isOperationActive(operation))
195
+ return unbind;
196
+ if (alreadyAborted) {
197
+ onAbort();
198
+ return unbind;
199
+ }
200
+ registered = true;
201
+ signal.addEventListener('abort', onAbort, { once: true });
202
+ if (!this.isOperationActive(operation))
203
+ return unbind;
204
+ const abortedAfterBinding = signal.aborted;
205
+ if (!this.isOperationActive(operation))
206
+ return unbind;
207
+ if (abortedAfterBinding)
208
+ onAbort();
209
+ }
210
+ catch (error) {
211
+ if (this.isOperationActive(operation)) {
212
+ operation.cancelled = true;
213
+ operation.cancellationReason = error;
214
+ this.releaseOperation(operation);
215
+ this.cleanupOperation(operation);
216
+ this.abortOperationSignal(operation, error);
217
+ }
218
+ }
219
+ return unbind;
220
+ }
221
+ load(_runtimeAssets = '', _code = '', _log = true, _args = [], _options = {}, _progress) {
222
+ return Promise.reject(new RuntimeConfigurationError('Bash worker runtime requires a verified page-host preflight payload', { phase: 'startup', runtimeId: 'BASH' }));
223
+ }
224
+ loadVerified(runtimePreflight, _log = true, options = {}, progress) {
225
+ let activeOperation;
226
+ try {
227
+ activeOperation = this.beginOperation('startup');
228
+ }
229
+ catch (error) {
230
+ return Promise.reject(error);
231
+ }
232
+ let signal;
233
+ let limits;
234
+ let unbindPreSessionAbort = () => undefined;
235
+ try {
236
+ signal = options.signal;
237
+ unbindPreSessionAbort = this.bindPreSessionAbort(activeOperation, signal);
238
+ this.requireOperationActive(activeOperation);
239
+ const limitSource = options.limits;
240
+ this.requireOperationActive(activeOperation);
241
+ limits = this.snapshotExecutionLimits(activeOperation, limitSource);
242
+ unbindPreSessionAbort();
243
+ this.requireOperationActive(activeOperation);
244
+ }
245
+ catch (error) {
246
+ return Promise.reject(this.releaseBeforeSession(activeOperation, error));
247
+ }
248
+ const timeoutMs = Math.min(2_147_483_647, limits.assetTimeoutMs + limits.startupTimeoutMs);
249
+ const loadGeneration = ++this.loadGeneration;
250
+ return new Promise((resolve, reject) => {
251
+ let onAbort;
252
+ let settleRejectedLoad;
253
+ let cleanedUp = false;
254
+ const cleanup = () => {
255
+ if (cleanedUp)
256
+ return;
257
+ cleanedUp = true;
258
+ if (signal && onAbort) {
259
+ try {
260
+ signal.removeEventListener('abort', onAbort);
261
+ }
262
+ catch {
263
+ // Cleanup must not replace the startup result.
264
+ }
265
+ }
266
+ if (this.activeLoadCleanup === cleanup)
267
+ this.activeLoadCleanup = null;
268
+ if (this.activeLoadReject === settleRejectedLoad)
269
+ this.activeLoadReject = null;
270
+ this.releaseOperation(activeOperation);
271
+ this.cleanupOperation(activeOperation);
272
+ };
273
+ settleRejectedLoad = (reason) => {
274
+ cleanup();
275
+ reject(reason);
276
+ };
277
+ const rejectLoad = (reason) => {
278
+ if (!this.isOperationActive(activeOperation))
279
+ return;
280
+ settleRejectedLoad(reason);
281
+ this.abortOperationSignal(activeOperation, reason);
282
+ };
283
+ onAbort = signal
284
+ ? () => {
285
+ if (!this.isOperationActive(activeOperation) ||
286
+ loadGeneration !== this.loadGeneration) {
287
+ cleanup();
288
+ return;
289
+ }
290
+ let reason;
291
+ try {
292
+ reason = abortReason(signal, 'startup');
293
+ }
294
+ catch (error) {
295
+ reason = error;
296
+ }
297
+ if (!this.isOperationActive(activeOperation) ||
298
+ loadGeneration !== this.loadGeneration) {
299
+ return;
300
+ }
301
+ this.terminate(reason);
302
+ }
303
+ : undefined;
304
+ this.activeLoadCleanup = cleanup;
305
+ this.activeLoadReject = settleRejectedLoad;
306
+ try {
307
+ if (signal && onAbort) {
308
+ signal.addEventListener('abort', onAbort, { once: true });
309
+ if (!this.isOperationActive(activeOperation))
310
+ return;
311
+ const abortedAfterBinding = signal.aborted;
312
+ if (!this.isOperationActive(activeOperation))
313
+ return;
314
+ if (abortedAfterBinding)
315
+ onAbort();
316
+ }
317
+ }
318
+ catch (error) {
319
+ if (this.isOperationActive(activeOperation))
320
+ this.terminate(error);
321
+ }
322
+ this.bindOperationTimeout(activeOperation, timeoutMs);
323
+ if (!this.isOperationActive(activeOperation))
324
+ return;
325
+ void (async () => {
326
+ let nextPackage = null;
327
+ let nextSdk = null;
328
+ let nextSdkRuntime = null;
329
+ let nextSdkBlobUrl = '';
330
+ let nextNestedWorkerBlobUrl = '';
331
+ let adopted = false;
332
+ const revokeCandidateUrls = () => {
333
+ for (const url of [nextNestedWorkerBlobUrl, nextSdkBlobUrl]) {
334
+ if (!url)
335
+ continue;
336
+ try {
337
+ URL.revokeObjectURL(url);
338
+ }
339
+ catch {
340
+ // Preserve startup ownership and failure semantics.
341
+ }
342
+ }
343
+ nextNestedWorkerBlobUrl = '';
344
+ nextSdkBlobUrl = '';
345
+ };
346
+ try {
347
+ if (!this.isOperationActive(activeOperation) ||
348
+ loadGeneration !== this.loadGeneration) {
349
+ return;
350
+ }
351
+ this.pendingInput = [];
352
+ this.pendingEof = false;
353
+ progress?.set?.(0.1, 'Verifying Bash runtime payload');
354
+ if (!this.isOperationActive(activeOperation) ||
355
+ loadGeneration !== this.loadGeneration) {
356
+ return;
357
+ }
358
+ const verified = await verifyBashRuntimePreflightPayload(runtimePreflight, {
359
+ maxAssetBytes: limits.maxAssetBytes,
360
+ signal: activeOperation.abortController.signal
361
+ });
362
+ this.requireOperationActive(activeOperation);
363
+ const realmUrl = typeof globalThis.location?.href === 'string'
364
+ ? globalThis.location.href
365
+ : 'https://wasm-idle.invalid/bash-outer-worker.js';
366
+ const sdkSentinelUrl = new URL(`/__wasm_idle/bash-sdk/${verified.manifestFingerprint}/index.mjs`, realmUrl).href;
367
+ nextSdkBlobUrl = URL.createObjectURL(new Blob([Uint8Array.from(verified.sdkJavaScriptBytes).buffer], {
368
+ type: 'text/javascript'
369
+ }));
370
+ const nestedBootstrapSource = createBashNestedBootstrapSource({
371
+ sdkModuleUrl: nextSdkBlobUrl,
372
+ sentinelUrl: sdkSentinelUrl,
373
+ realmUrl
374
+ });
375
+ nextNestedWorkerBlobUrl = URL.createObjectURL(new Blob([nestedBootstrapSource], { type: 'text/javascript' }));
376
+ nextSdk = await this.importVerifiedSdkModule(nextSdkBlobUrl);
377
+ if (!this.isOperationActive(activeOperation) ||
378
+ loadGeneration !== this.loadGeneration) {
379
+ return;
380
+ }
381
+ await nextSdk.init({
382
+ module: verified.wasmerWasmBytes,
383
+ sdkUrl: sdkSentinelUrl,
384
+ workerUrl: nextNestedWorkerBlobUrl
385
+ });
386
+ if (!this.isOperationActive(activeOperation) ||
387
+ loadGeneration !== this.loadGeneration) {
388
+ return;
389
+ }
390
+ nextSdkRuntime = new nextSdk.Runtime({ registry: null });
391
+ if (!this.isOperationActive(activeOperation) ||
392
+ loadGeneration !== this.loadGeneration) {
393
+ return;
394
+ }
395
+ nextPackage = await nextSdk.Wasmer.fromFile(verified.webcBytes, nextSdkRuntime);
396
+ if (!this.isOperationActive(activeOperation) ||
397
+ loadGeneration !== this.loadGeneration) {
398
+ const stalePackage = nextPackage;
399
+ nextPackage = null;
400
+ try {
401
+ stalePackage.free();
402
+ }
403
+ catch {
404
+ // Cleanup must not replace the startup result.
405
+ }
406
+ return;
407
+ }
408
+ progress?.set?.(1, 'Bash runtime ready');
409
+ if (!this.isOperationActive(activeOperation) ||
410
+ loadGeneration !== this.loadGeneration) {
411
+ const stalePackage = nextPackage;
412
+ nextPackage = null;
413
+ try {
414
+ stalePackage.free();
415
+ }
416
+ catch {
417
+ // Cleanup must not replace the startup result.
418
+ }
419
+ return;
420
+ }
421
+ const previousPackage = this.runtimePackage;
422
+ const previousSdkRuntime = this.sdkRuntime;
423
+ const previousSdkBlobUrl = this.sdkBlobUrl;
424
+ const previousNestedWorkerBlobUrl = this.nestedWorkerBlobUrl;
425
+ this.runtimePackage = nextPackage;
426
+ nextPackage = null;
427
+ this.sdkModule = nextSdk;
428
+ nextSdk = null;
429
+ this.sdkRuntime = nextSdkRuntime;
430
+ nextSdkRuntime = null;
431
+ this.sdkBlobUrl = nextSdkBlobUrl;
432
+ nextSdkBlobUrl = '';
433
+ this.nestedWorkerBlobUrl = nextNestedWorkerBlobUrl;
434
+ nextNestedWorkerBlobUrl = '';
435
+ this.webcUrl = `verified:${verified.profileId}:bash.webc`;
436
+ adopted = true;
437
+ try {
438
+ previousPackage?.free();
439
+ }
440
+ catch {
441
+ // Releasing the previous package must not replace startup success.
442
+ }
443
+ try {
444
+ previousSdkRuntime?.free?.();
445
+ }
446
+ catch {
447
+ // Releasing the previous isolated SDK runtime remains best effort.
448
+ }
449
+ for (const url of [previousNestedWorkerBlobUrl, previousSdkBlobUrl]) {
450
+ if (!url)
451
+ continue;
452
+ try {
453
+ URL.revokeObjectURL(url);
454
+ }
455
+ catch {
456
+ // Blob URL cleanup remains best effort after activation.
457
+ }
458
+ }
459
+ cleanup();
460
+ resolve();
461
+ }
462
+ catch (error) {
463
+ if (!this.isOperationActive(activeOperation) ||
464
+ loadGeneration !== this.loadGeneration) {
465
+ return;
466
+ }
467
+ rejectLoad(error);
468
+ }
469
+ finally {
470
+ if (!adopted) {
471
+ const failedPackage = nextPackage;
472
+ nextPackage = null;
473
+ try {
474
+ failedPackage?.free();
475
+ }
476
+ catch {
477
+ // Preserve the startup result.
478
+ }
479
+ const failedRuntime = nextSdkRuntime;
480
+ nextSdkRuntime = null;
481
+ try {
482
+ failedRuntime?.free?.();
483
+ }
484
+ catch {
485
+ // Preserve the startup result.
486
+ }
487
+ revokeCandidateUrls();
488
+ }
489
+ }
490
+ })();
491
+ });
492
+ }
493
+ write(input) {
494
+ this.pendingInput.push(input);
495
+ this.pendingEof = false;
496
+ void this.flushPendingInput().catch(() => undefined);
497
+ }
498
+ eof() {
499
+ this.pendingEof = true;
500
+ void this.flushPendingInput().catch(() => undefined);
501
+ }
502
+ async flushPendingInput() {
503
+ const writer = this.stdinWriter;
504
+ if (!writer)
505
+ return;
506
+ const pending = this.pendingInput.splice(0);
507
+ for (const input of pending) {
508
+ await writer.write(new TextEncoder().encode(input));
509
+ if (this.stdinWriter !== writer)
510
+ return;
511
+ }
512
+ if (this.pendingEof && this.stdinWriter === writer) {
513
+ this.pendingEof = false;
514
+ await writer.close();
515
+ if (this.stdinWriter === writer) {
516
+ this.stdinWriter = null;
517
+ try {
518
+ writer.releaseLock();
519
+ }
520
+ catch {
521
+ // The completed stream may already have released its writer.
522
+ }
523
+ }
524
+ }
525
+ }
526
+ disposeRunHandles(instance, writer, outputController, reason) {
527
+ try {
528
+ outputController?.abort(reason);
529
+ }
530
+ catch {
531
+ // Preserve the operation result.
532
+ }
533
+ if (writer) {
534
+ const releaseWriter = () => {
535
+ try {
536
+ writer.releaseLock();
537
+ }
538
+ catch {
539
+ // Pending stream operations may still own the writer lock.
540
+ }
541
+ };
542
+ try {
543
+ void Promise.resolve(writer.abort(reason))
544
+ .catch(() => undefined)
545
+ .finally(releaseWriter);
546
+ }
547
+ catch {
548
+ releaseWriter();
549
+ }
550
+ }
551
+ try {
552
+ instance?.free();
553
+ }
554
+ catch {
555
+ // Preserve the operation result.
556
+ }
557
+ }
558
+ async run(code, prepare, _log = true, progress, args = [], options = {}) {
559
+ const activeOperation = this.beginOperation('execute');
560
+ if (prepare) {
561
+ this.releaseOperation(activeOperation);
562
+ this.cleanupOperation(activeOperation);
563
+ return true;
564
+ }
565
+ const runtimePackage = this.runtimePackage;
566
+ if (!runtimePackage) {
567
+ throw this.releaseBeforeSession(activeOperation, new Error('Bash runtime is not loaded'));
568
+ }
569
+ let signal;
570
+ let programArgs;
571
+ let limits;
572
+ let workspace;
573
+ let stdin;
574
+ let unbindPreSessionAbort = () => undefined;
575
+ try {
576
+ signal = options.signal;
577
+ unbindPreSessionAbort = this.bindPreSessionAbort(activeOperation, signal);
578
+ this.requireOperationActive(activeOperation);
579
+ const configuredProgramArgs = options.programArgs;
580
+ this.requireOperationActive(activeOperation);
581
+ const programArgsSource = configuredProgramArgs ?? args;
582
+ programArgs = [];
583
+ if (Array.isArray(programArgsSource)) {
584
+ const programArgCount = programArgsSource.length;
585
+ this.requireOperationActive(activeOperation);
586
+ for (let index = 0; index < programArgCount; index += 1) {
587
+ const argument = programArgsSource[index];
588
+ this.requireOperationActive(activeOperation);
589
+ programArgs.push(argument);
590
+ }
591
+ }
592
+ const limitSource = options.limits;
593
+ this.requireOperationActive(activeOperation);
594
+ limits = this.snapshotExecutionLimits(activeOperation, limitSource);
595
+ const workspaceFilesSource = options.workspaceFiles ?? [];
596
+ this.requireOperationActive(activeOperation);
597
+ if (!Array.isArray(workspaceFilesSource)) {
598
+ throw new TypeError('Bash workspace files must be an array');
599
+ }
600
+ const workspaceFileCount = workspaceFilesSource.length;
601
+ this.requireOperationActive(activeOperation);
602
+ const workspaceFiles = [];
603
+ for (let index = 0; index < workspaceFileCount; index += 1) {
604
+ const file = workspaceFilesSource[index];
605
+ this.requireOperationActive(activeOperation);
606
+ const path = file.path;
607
+ this.requireOperationActive(activeOperation);
608
+ const content = file.content;
609
+ this.requireOperationActive(activeOperation);
610
+ workspaceFiles.push({ path, content });
611
+ }
612
+ const activePath = options.activePath ?? 'main.sh';
613
+ this.requireOperationActive(activeOperation);
614
+ const workspaceLimitsSource = options.workspaceLimits;
615
+ this.requireOperationActive(activeOperation);
616
+ let workspaceLimits = {};
617
+ if (workspaceLimitsSource) {
618
+ const maxFiles = workspaceLimitsSource.maxFiles;
619
+ this.requireOperationActive(activeOperation);
620
+ const maxFileBytes = workspaceLimitsSource.maxFileBytes;
621
+ this.requireOperationActive(activeOperation);
622
+ const maxTotalBytes = workspaceLimitsSource.maxTotalBytes;
623
+ this.requireOperationActive(activeOperation);
624
+ const maxPathBytes = workspaceLimitsSource.maxPathBytes;
625
+ this.requireOperationActive(activeOperation);
626
+ const caseSensitive = workspaceLimitsSource.caseSensitive;
627
+ this.requireOperationActive(activeOperation);
628
+ workspaceLimits = {
629
+ maxFiles,
630
+ maxFileBytes,
631
+ maxTotalBytes,
632
+ maxPathBytes,
633
+ caseSensitive
634
+ };
635
+ }
636
+ workspace = validateExecutionWorkspace(code, workspaceFiles, activePath, {
637
+ ...workspaceLimits,
638
+ maxFileBytes: Math.min(workspaceLimits.maxFileBytes ?? DEFAULT_WORKSPACE_LIMITS.maxFileBytes, limits.maxWorkspaceBytes),
639
+ maxTotalBytes: Math.min(workspaceLimits.maxTotalBytes ?? DEFAULT_WORKSPACE_LIMITS.maxTotalBytes, limits.maxWorkspaceBytes)
640
+ });
641
+ this.requireOperationActive(activeOperation);
642
+ stdin = options.stdin;
643
+ this.requireOperationActive(activeOperation);
644
+ unbindPreSessionAbort();
645
+ this.requireOperationActive(activeOperation);
646
+ }
647
+ catch (error) {
648
+ throw this.releaseBeforeSession(activeOperation, error);
649
+ }
650
+ const timeoutMs = Math.min(2_147_483_647, limits.compileTimeoutMs + limits.runTimeoutMs);
651
+ const mountedFiles = Object.fromEntries(workspace.workspaceFiles.map((file) => [file.path, file.content]));
652
+ const mountedActivePath = workspace.activePath ?? 'main.sh';
653
+ mountedFiles[mountedActivePath] = code;
654
+ const hasExplicitStdin = stdin !== undefined;
655
+ const queuedStdin = this.pendingInput.length > 0 ? this.pendingInput.join('') : undefined;
656
+ const suppliedStdin = stdin ?? (this.pendingEof ? queuedStdin || '' : undefined);
657
+ this.requireOperationActive(activeOperation);
658
+ this.exit = false;
659
+ this.begin = Date.now();
660
+ const runUid = ++this.uid;
661
+ if (suppliedStdin !== undefined) {
662
+ this.pendingInput = [];
663
+ this.pendingEof = false;
664
+ }
665
+ return new Promise((resolve, reject) => {
666
+ let outputBytes = 0;
667
+ let settleRejectedRun;
668
+ let cleanedUp = false;
669
+ const cleanup = () => {
670
+ if (cleanedUp)
671
+ return;
672
+ cleanedUp = true;
673
+ if (hasExplicitStdin && this.activeOperation?.token === activeOperation.token) {
674
+ this.pendingInput = [];
675
+ this.pendingEof = false;
676
+ }
677
+ if (signal && onAbort) {
678
+ try {
679
+ signal.removeEventListener('abort', onAbort);
680
+ }
681
+ catch {
682
+ // Cleanup must not replace the execution result.
683
+ }
684
+ }
685
+ if (this.activeRunCleanup === cleanup)
686
+ this.activeRunCleanup = null;
687
+ if (this.activeReject === settleRejectedRun)
688
+ this.activeReject = null;
689
+ this.releaseOperation(activeOperation);
690
+ this.cleanupOperation(activeOperation);
691
+ };
692
+ settleRejectedRun = (reason) => {
693
+ cleanup();
694
+ reject(reason);
695
+ };
696
+ const onAbort = signal
697
+ ? () => {
698
+ if (!this.isOperationActive(activeOperation) || runUid !== this.uid) {
699
+ cleanup();
700
+ return;
701
+ }
702
+ let reason;
703
+ try {
704
+ reason = abortReason(signal, 'execute');
705
+ }
706
+ catch (error) {
707
+ reason = error;
708
+ }
709
+ if (!this.isOperationActive(activeOperation) || runUid !== this.uid) {
710
+ return;
711
+ }
712
+ this.terminate(reason);
713
+ }
714
+ : undefined;
715
+ this.activeReject = settleRejectedRun;
716
+ this.activeRunCleanup = cleanup;
717
+ try {
718
+ if (signal && onAbort) {
719
+ signal.addEventListener('abort', onAbort, { once: true });
720
+ if (!this.isOperationActive(activeOperation))
721
+ return;
722
+ const abortedAfterBinding = signal.aborted;
723
+ if (!this.isOperationActive(activeOperation))
724
+ return;
725
+ if (abortedAfterBinding)
726
+ onAbort();
727
+ }
728
+ }
729
+ catch (error) {
730
+ if (this.isOperationActive(activeOperation))
731
+ this.terminate(error);
732
+ }
733
+ this.bindOperationTimeout(activeOperation, timeoutMs);
734
+ if (!this.isOperationActive(activeOperation) || runUid !== this.uid)
735
+ return;
736
+ void (async () => {
737
+ const ownsRun = () => this.isOperationActive(activeOperation) && runUid === this.uid;
738
+ try {
739
+ const command = runtimePackage.entrypoint;
740
+ if (!command)
741
+ throw new Error('Bash WEBc package has no entrypoint');
742
+ let instance;
743
+ try {
744
+ instance = await command.run({
745
+ args: ['-c', code, mountedActivePath, ...programArgs],
746
+ mount: { '/workspace': mountedFiles },
747
+ cwd: '/workspace',
748
+ ...(suppliedStdin === undefined ? {} : { stdin: suppliedStdin })
749
+ });
750
+ }
751
+ finally {
752
+ try {
753
+ command.free();
754
+ }
755
+ catch {
756
+ // Command cleanup must not replace the execution result.
757
+ }
758
+ }
759
+ if (!ownsRun()) {
760
+ this.disposeRunHandles(instance, null, null, activeOperation.cancellationReason);
761
+ return;
762
+ }
763
+ try {
764
+ progress?.report?.({
765
+ kind: 'ready',
766
+ state: 'running',
767
+ reason: 'started',
768
+ label: 'Bash process started'
769
+ });
770
+ }
771
+ catch (error) {
772
+ this.disposeRunHandles(instance, null, null, error);
773
+ if (!ownsRun())
774
+ return;
775
+ throw error;
776
+ }
777
+ if (!ownsRun()) {
778
+ this.disposeRunHandles(instance, null, null, activeOperation.cancellationReason);
779
+ return;
780
+ }
781
+ let writer = null;
782
+ try {
783
+ writer =
784
+ suppliedStdin === undefined
785
+ ? instance.stdin?.getWriter() || null
786
+ : null;
787
+ }
788
+ catch (error) {
789
+ this.disposeRunHandles(instance, null, null, error);
790
+ throw error;
791
+ }
792
+ if (!ownsRun()) {
793
+ this.disposeRunHandles(instance, writer, null, activeOperation.cancellationReason);
794
+ return;
795
+ }
796
+ this.instance = instance;
797
+ this.stdinWriter = writer;
798
+ await this.flushPendingInput();
799
+ if (!ownsRun())
800
+ return;
801
+ const outputController = new AbortController();
802
+ this.outputController = outputController;
803
+ const outputPipes = [];
804
+ const writeOutput = (stream, chunk) => {
805
+ if (!ownsRun())
806
+ return;
807
+ const actual = outputBytes + chunk.byteLength;
808
+ if (actual > limits.maxOutputBytes) {
809
+ this.terminate(new OutputLimitError(`Bash output exceeded ${limits.maxOutputBytes} bytes`, {
810
+ actual,
811
+ limit: limits.maxOutputBytes,
812
+ phase: 'execute',
813
+ runtimeId: 'BASH'
814
+ }));
815
+ return;
816
+ }
817
+ outputBytes = actual;
818
+ if (this.outputBytes) {
819
+ this.outputBytes(stream, chunk);
820
+ }
821
+ else {
822
+ this.output?.(new TextDecoder().decode(chunk));
823
+ }
824
+ };
825
+ try {
826
+ outputPipes.push(instance.stdout.pipeTo(new WritableStream({
827
+ write: (chunk) => writeOutput('stdout', chunk)
828
+ }), { signal: outputController.signal }));
829
+ outputPipes.push(instance.stderr.pipeTo(new WritableStream({
830
+ write: (chunk) => writeOutput('stderr', chunk)
831
+ }), { signal: outputController.signal }));
832
+ }
833
+ catch (error) {
834
+ void Promise.allSettled(outputPipes);
835
+ throw error;
836
+ }
837
+ const outputDone = Promise.allSettled(outputPipes);
838
+ if (!ownsRun())
839
+ return;
840
+ this.instance = null;
841
+ const result = await instance.wait();
842
+ await outputDone;
843
+ if (!ownsRun())
844
+ return;
845
+ this.elapse = Date.now() - this.begin;
846
+ this.exit = true;
847
+ const settledWriter = this.stdinWriter;
848
+ this.stdinWriter = null;
849
+ this.instance = null;
850
+ if (this.outputController === outputController) {
851
+ this.outputController = null;
852
+ }
853
+ try {
854
+ settledWriter?.releaseLock();
855
+ }
856
+ catch {
857
+ // The completed stream may already have released its writer.
858
+ }
859
+ if (!result.ok) {
860
+ settleRejectedRun(`Bash exited with status ${result.code}.`);
861
+ return;
862
+ }
863
+ cleanup();
864
+ resolve(true);
865
+ }
866
+ catch (error) {
867
+ if (!ownsRun())
868
+ return;
869
+ this.exit = true;
870
+ const writer = this.stdinWriter;
871
+ const instance = this.instance;
872
+ const outputController = this.outputController;
873
+ this.stdinWriter = null;
874
+ this.instance = null;
875
+ this.outputController = null;
876
+ this.disposeRunHandles(instance, writer, outputController, error);
877
+ settleRejectedRun(error instanceof Error ? error.message : String(error));
878
+ }
879
+ finally {
880
+ cleanup();
881
+ }
882
+ })();
883
+ });
884
+ }
885
+ kill() {
886
+ this.terminate();
887
+ }
888
+ terminate(reason = 'Process terminated') {
889
+ const activeOperation = this.activeOperation;
890
+ if (activeOperation) {
891
+ const loadReject = this.activeLoadReject;
892
+ const loadCleanup = this.activeLoadCleanup;
893
+ const reject = this.activeReject;
894
+ const cleanup = this.activeRunCleanup;
895
+ const writer = this.stdinWriter;
896
+ const instance = this.instance;
897
+ const outputController = this.outputController;
898
+ activeOperation.cancelled = true;
899
+ activeOperation.cancellationReason = reason;
900
+ this.activeOperation = null;
901
+ this.activeLoadReject = null;
902
+ this.activeLoadCleanup = null;
903
+ this.activeReject = null;
904
+ this.activeRunCleanup = null;
905
+ this.loadGeneration += 1;
906
+ this.uid += 1;
907
+ this.stdinWriter = null;
908
+ this.instance = null;
909
+ this.outputController = null;
910
+ this.pendingInput = [];
911
+ this.pendingEof = false;
912
+ this.exit = true;
913
+ this.cleanupOperation(activeOperation);
914
+ loadCleanup?.();
915
+ cleanup?.();
916
+ loadReject?.(reason);
917
+ reject?.(reason);
918
+ this.abortOperationSignal(activeOperation, reason);
919
+ this.disposeRunHandles(instance, writer, outputController, reason);
920
+ return;
921
+ }
922
+ const loadReject = this.activeLoadReject;
923
+ const loadCleanup = this.activeLoadCleanup;
924
+ const reject = this.activeReject;
925
+ const cleanup = this.activeRunCleanup;
926
+ const writer = this.stdinWriter;
927
+ const instance = this.instance;
928
+ const outputController = this.outputController;
929
+ this.activeLoadReject = null;
930
+ this.activeLoadCleanup = null;
931
+ this.activeReject = null;
932
+ this.activeRunCleanup = null;
933
+ this.loadGeneration += 1;
934
+ this.uid += 1;
935
+ this.stdinWriter = null;
936
+ this.instance = null;
937
+ this.outputController = null;
938
+ this.pendingInput = [];
939
+ this.pendingEof = false;
940
+ this.exit = true;
941
+ loadCleanup?.();
942
+ cleanup?.();
943
+ loadReject?.(reason);
944
+ reject?.(reason);
945
+ this.disposeRunHandles(instance, writer, outputController, reason);
946
+ }
947
+ async clear() {
948
+ this.terminate();
949
+ const runtimePackage = this.runtimePackage;
950
+ const sdkRuntime = this.sdkRuntime;
951
+ const urls = [this.nestedWorkerBlobUrl, this.sdkBlobUrl];
952
+ this.runtimePackage = null;
953
+ this.sdkRuntime = null;
954
+ this.sdkModule = null;
955
+ this.nestedWorkerBlobUrl = '';
956
+ this.sdkBlobUrl = '';
957
+ this.webcUrl = '';
958
+ try {
959
+ runtimePackage?.free();
960
+ }
961
+ catch {
962
+ // The sandbox is cleared even when the SDK cleanup hook fails.
963
+ }
964
+ try {
965
+ sdkRuntime?.free?.();
966
+ }
967
+ catch {
968
+ // The sandbox is cleared even when the isolated runtime cleanup fails.
969
+ }
970
+ for (const url of urls) {
971
+ if (!url)
972
+ continue;
973
+ try {
974
+ URL.revokeObjectURL(url);
975
+ }
976
+ catch {
977
+ // Blob URL cleanup is best effort during realm teardown.
978
+ }
979
+ }
980
+ }
981
+ }
982
+ export default BashWorkerRuntime;