@volter/browser-substrate 0.1.121 → 0.1.122

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 (112) hide show
  1. package/catalog/demand-input.json +9 -9
  2. package/catalog/published/profile.json +2 -2
  3. package/catalog/published/v1/artifacts/sha256/{d9dddf83dfd2af98c525007dc494d564b9ffa1f5f393c564334dcb5137e99330 → 28e84e7eb19a7f6770ba9715d8416391e8a62689332e939a795c23e99096123e} +1 -1
  4. package/catalog/published/v1/artifacts/sha256/{23a82cc8afdf35d48f0f9ef66f53ff6d7a8b3a641b7ef86e9b81ce04551ee954 → 9b545d88dd03ffbdfcba2f81a8ac6224a30828c0a0e094a944cd92509f75a15d} +43 -24
  5. package/catalog/published/v1/artifacts/sha256/{1d9fc30121217ec1c2161e79c3df3e27047a786b8eb33ee6a218a887d794fa88 → bba5ff50dabd2d35433f206c077e8dafc050daea4530fe4673935e45b344fee1} +16 -7
  6. package/catalog/published/v1/artifacts/sha256/{301eea90d7061167d148cc37016a0dd77b58ca86d378ee27f720ef1ea62df9e8 → c67a2d53f01e10acf2e02e1bcd4cbd194fd94dd392e3c791a86236f73e178fd0} +0 -0
  7. package/catalog/published/v1/catalog.json +1 -1
  8. package/catalog/published/v1/catalogs/sha256/{ba2ed522ac281012a19ff5a94ca87b3bb4bdf230bb941220de5491513d2a57ea.json → 6ae27784c6ce675992d1deabf401c9799e32ab183ff724cef38913047116874b.json} +1 -1
  9. package/catalog/published/v1/locks/sha256/51c71d0ed3e83b0818e74a8f66c9136245ed3ac5d51b9f323aea2bdc3a476be2.json +1 -0
  10. package/catalog/published/v1/locks/sha256/73f287d58b9b2f2a2b6e92fa08aaaf4d4ea52d32a871edc73bd3038441dc5b89.json +1 -0
  11. package/catalog/published/v1/locks/sha256/7b62ee6c5f79edcb5fd02f6fabddbcf43ac7d94b5b11158e069c9756fadb163c.json +1 -0
  12. package/catalog/published/v1/locks/sha256/8f97719076ed975cf64092771118b6bd2ac1d16fd1f2a3d8068255edf24b17cb.json +1 -0
  13. package/catalog/published/v1/locks/sha256/a02aae67b4c34afcf5eef76da8798af0b3617f2899bc13134f850ae600d15ded.json +1 -0
  14. package/catalog/published/v1/locks/sha256/c3e3838c6a5fe95f0eb080ecc1dd1270f706a86f0c09306ca1447e9c6b46e1b2.json +1 -0
  15. package/catalog/published/v1/locks/sha256/c4e2ee1b2616ed593a2f6a3c3017f2567f6b682bc4a54572800ed9bf3a6293f1.json +1 -0
  16. package/catalog/published/v1/locks/sha256/f025299950d217fcae1380d35675d0ddc5dbbf4bb904aa2417edd7516b86ba35.json +1 -0
  17. package/catalog/published/v1/manifests/sha256/22bbb8c6725fd5c44ad01c34a293f258f91592c886229df11d06240bcd3515d5.json +1 -0
  18. package/catalog/published/v1/manifests/sha256/{c5ebb33c1959713cf4dee3482dde9b95a87fe1c6dd9e947c013018254cd2a371.json → 939c6b6cf3d34df0d8b9d8d0569874d9bef7c0f6763d3e81d8fa5a89812926cc.json} +1 -1
  19. package/catalog/published/v1/manifests/sha256/{026eef1bad61aa255defe8115c2daae7a739657aebe1cff1df31712d98606cd3.json → a6e54a6a42361758808f5bb8354f4def793274937eb3840e4b52eb9df0fd61e5.json} +1 -1
  20. package/catalog/published/v1/manifests/sha256/{566b3535719ba2aa5f2f437939174189b7b195e161890a5b792667633e9d7fc5.json → b29ec4b3dc6f26d982f634788da6d6cc4316b318797d8d3fa79bddbcdf6a1992.json} +1 -1
  21. package/catalog/published/v1/manifests/sha256/{64a81cb05980cf4e83f77244ee540b7fbc9e2e8bd8673614fff938a6a21de822.json → b52889855e9b68de41ec778c1cc788063f53159e74b739918a5c25e94ddbdb1e.json} +1 -1
  22. package/catalog/published/v1/manifests/sha256/{05781228ef0c812f61bf957a9ce2ee58544c4a6c010be46228ec8505a5a1f978.json → ca12242429a17998c7e49674bdad647da1a329cdaf432100acd42a69c9bfe4e8.json} +1 -1
  23. package/catalog/published/v1/manifests/sha256/{03503c6f6d9142dce3f1d6eb5105b909fe0a2b16189bd58b9c8971ca588d3e61.json → fc947fe6f42d963e6d4757bf0d7a764961d5239e6dfe476b2fb47eb38a5972eb.json} +1 -1
  24. package/catalog/published/v1/manifests/sha256/{e9c4da2392cebaa5377154b7fe0e72d7d943032e41cf775d0158df5808d1e38f.json → fe56c670dc0bbcce9641daddc123124cd50562c628f72bfbc32df6d89070675a.json} +1 -1
  25. package/dist/cli/catalog-variants.d.ts +2 -10
  26. package/dist/cli/catalog-variants.d.ts.map +1 -1
  27. package/dist/cli/catalog-variants.js +2 -31
  28. package/dist/cli/catalog-variants.js.map +1 -1
  29. package/dist/cli/dependency-plan-build.d.ts +9 -2
  30. package/dist/cli/dependency-plan-build.d.ts.map +1 -1
  31. package/dist/cli/dependency-plan-build.js +25 -12
  32. package/dist/cli/dependency-plan-build.js.map +1 -1
  33. package/dist/cli/generated-code.d.ts +1 -0
  34. package/dist/cli/generated-code.d.ts.map +1 -1
  35. package/dist/cli/generated-code.js +44 -12
  36. package/dist/cli/generated-code.js.map +1 -1
  37. package/dist/cli/main.d.ts +7 -1
  38. package/dist/cli/main.d.ts.map +1 -1
  39. package/dist/cli/main.js +23 -34
  40. package/dist/cli/main.js.map +1 -1
  41. package/dist/cli/project-build.d.ts +1 -0
  42. package/dist/cli/project-build.d.ts.map +1 -1
  43. package/dist/cli/project-build.js +1 -1
  44. package/dist/cli/project-build.js.map +1 -1
  45. package/dist/cli/provision-catalog.d.ts +43 -1
  46. package/dist/cli/provision-catalog.d.ts.map +1 -1
  47. package/dist/cli/provision-catalog.js +146 -15
  48. package/dist/cli/provision-catalog.js.map +1 -1
  49. package/dist/dependency-plan.js +2 -2
  50. package/dist/dependency-plan.js.map +1 -1
  51. package/dist/image.d.ts +6 -0
  52. package/dist/image.d.ts.map +1 -1
  53. package/dist/image.js +24 -8
  54. package/dist/image.js.map +1 -1
  55. package/dist/index.js +21 -11
  56. package/dist/index.js.map +1 -1
  57. package/dist/shell/assets/{node-execution-worker-f95a35f14c4e92be.js → node-execution-worker-45b54413ee36e6fd.js} +4 -4
  58. package/dist/shell/assets/{runtime-worker-4ta5HAH6.js → runtime-worker-VllmNZ2p.js} +46 -34
  59. package/dist/shell/assets/{shell-kBI0ZgOO.js → shell-DXJv7EqZ.js} +2 -2
  60. package/dist/shell/bundler-worker.js +2 -2
  61. package/dist/shell/index.html +1 -1
  62. package/dist/shell/node-execution-worker.js +1 -1
  63. package/package.json +1 -1
  64. package/catalog/published/v1/locks/sha256/09a6c49b4a0e11a111cecfcf6b4afd63b97efcb6439bed0401f60be6d9246780.json +0 -1
  65. package/catalog/published/v1/locks/sha256/4d2b82aaf0610359bf0e757e4e63100576687880f65d1fb093625301021fc61c.json +0 -1
  66. package/catalog/published/v1/locks/sha256/5292658503e248418d24e005942a3adc9ca79af135c8f8fa20659b048df93e0b.json +0 -1
  67. package/catalog/published/v1/locks/sha256/65e508124330a0cb0455ac06ce274ed9a47b7d720290b24146cf16f1153ad0a0.json +0 -1
  68. package/catalog/published/v1/locks/sha256/91621a0164f2a8d1a149034353e8679547e3269f7329a049006ae6e069fc41ff.json +0 -1
  69. package/catalog/published/v1/locks/sha256/bf650fdc44f5297175d58f3248b31768573a23484719f455c4e9c24502c41648.json +0 -1
  70. package/catalog/published/v1/locks/sha256/f5c7caac5e06541e998fa1c6d6ef1d50c8c146af161bcf5c1c0a828c0dcedaea.json +0 -1
  71. package/catalog/published/v1/locks/sha256/fba31e0e4cf54807389170be745fe505628d9af5cb2dc3223df1508bbde3973e.json +0 -1
  72. package/catalog/published/v1/manifests/sha256/fd500c4047bcddcc3d16d4a98ac7d1d0f887e0669a6ae8fa1f391a8b16a8abb9.json +0 -1
  73. /package/catalog/published/v1/artifacts/sha256/{301eea90d7061167d148cc37016a0dd77b58ca86d378ee27f720ef1ea62df9e8.headers.json → 28e84e7eb19a7f6770ba9715d8416391e8a62689332e939a795c23e99096123e.headers.json} +0 -0
  74. /package/catalog/published/v1/artifacts/sha256/{1d9fc30121217ec1c2161e79c3df3e27047a786b8eb33ee6a218a887d794fa88.headers.json → 9b545d88dd03ffbdfcba2f81a8ac6224a30828c0a0e094a944cd92509f75a15d.headers.json} +0 -0
  75. /package/catalog/published/v1/artifacts/sha256/{23a82cc8afdf35d48f0f9ef66f53ff6d7a8b3a641b7ef86e9b81ce04551ee954.headers.json → bba5ff50dabd2d35433f206c077e8dafc050daea4530fe4673935e45b344fee1.headers.json} +0 -0
  76. /package/catalog/published/v1/artifacts/sha256/{d9dddf83dfd2af98c525007dc494d564b9ffa1f5f393c564334dcb5137e99330.headers.json → c67a2d53f01e10acf2e02e1bcd4cbd194fd94dd392e3c791a86236f73e178fd0.headers.json} +0 -0
  77. /package/catalog/published/v1/catalogs/sha256/{ba2ed522ac281012a19ff5a94ca87b3bb4bdf230bb941220de5491513d2a57ea.json.headers.json → 6ae27784c6ce675992d1deabf401c9799e32ab183ff724cef38913047116874b.json.headers.json} +0 -0
  78. /package/catalog/published/v1/locks/sha256/{09a6c49b4a0e11a111cecfcf6b4afd63b97efcb6439bed0401f60be6d9246780.json.headers.json → 51c71d0ed3e83b0818e74a8f66c9136245ed3ac5d51b9f323aea2bdc3a476be2.json.headers.json} +0 -0
  79. /package/catalog/published/v1/locks/sha256/{4d2b82aaf0610359bf0e757e4e63100576687880f65d1fb093625301021fc61c.json.headers.json → 73f287d58b9b2f2a2b6e92fa08aaaf4d4ea52d32a871edc73bd3038441dc5b89.json.headers.json} +0 -0
  80. /package/catalog/published/v1/locks/sha256/{5292658503e248418d24e005942a3adc9ca79af135c8f8fa20659b048df93e0b.json.headers.json → 7b62ee6c5f79edcb5fd02f6fabddbcf43ac7d94b5b11158e069c9756fadb163c.json.headers.json} +0 -0
  81. /package/catalog/published/v1/locks/sha256/{65e508124330a0cb0455ac06ce274ed9a47b7d720290b24146cf16f1153ad0a0.json.headers.json → 8f97719076ed975cf64092771118b6bd2ac1d16fd1f2a3d8068255edf24b17cb.json.headers.json} +0 -0
  82. /package/catalog/published/v1/locks/sha256/{91621a0164f2a8d1a149034353e8679547e3269f7329a049006ae6e069fc41ff.json.headers.json → a02aae67b4c34afcf5eef76da8798af0b3617f2899bc13134f850ae600d15ded.json.headers.json} +0 -0
  83. /package/catalog/published/v1/locks/sha256/{bf650fdc44f5297175d58f3248b31768573a23484719f455c4e9c24502c41648.json.headers.json → c3e3838c6a5fe95f0eb080ecc1dd1270f706a86f0c09306ca1447e9c6b46e1b2.json.headers.json} +0 -0
  84. /package/catalog/published/v1/locks/sha256/{f5c7caac5e06541e998fa1c6d6ef1d50c8c146af161bcf5c1c0a828c0dcedaea.json.headers.json → c4e2ee1b2616ed593a2f6a3c3017f2567f6b682bc4a54572800ed9bf3a6293f1.json.headers.json} +0 -0
  85. /package/catalog/published/v1/locks/sha256/{fba31e0e4cf54807389170be745fe505628d9af5cb2dc3223df1508bbde3973e.json.headers.json → f025299950d217fcae1380d35675d0ddc5dbbf4bb904aa2417edd7516b86ba35.json.headers.json} +0 -0
  86. /package/catalog/published/v1/manifests/sha256/{026eef1bad61aa255defe8115c2daae7a739657aebe1cff1df31712d98606cd3.json.headers.json → 22bbb8c6725fd5c44ad01c34a293f258f91592c886229df11d06240bcd3515d5.json.headers.json} +0 -0
  87. /package/catalog/published/v1/manifests/sha256/{03503c6f6d9142dce3f1d6eb5105b909fe0a2b16189bd58b9c8971ca588d3e61.json.headers.json → 939c6b6cf3d34df0d8b9d8d0569874d9bef7c0f6763d3e81d8fa5a89812926cc.json.headers.json} +0 -0
  88. /package/catalog/published/v1/manifests/sha256/{05781228ef0c812f61bf957a9ce2ee58544c4a6c010be46228ec8505a5a1f978.json.headers.json → a6e54a6a42361758808f5bb8354f4def793274937eb3840e4b52eb9df0fd61e5.json.headers.json} +0 -0
  89. /package/catalog/published/v1/manifests/sha256/{566b3535719ba2aa5f2f437939174189b7b195e161890a5b792667633e9d7fc5.json.headers.json → b29ec4b3dc6f26d982f634788da6d6cc4316b318797d8d3fa79bddbcdf6a1992.json.headers.json} +0 -0
  90. /package/catalog/published/v1/manifests/sha256/{64a81cb05980cf4e83f77244ee540b7fbc9e2e8bd8673614fff938a6a21de822.json.headers.json → b52889855e9b68de41ec778c1cc788063f53159e74b739918a5c25e94ddbdb1e.json.headers.json} +0 -0
  91. /package/catalog/published/v1/manifests/sha256/{c5ebb33c1959713cf4dee3482dde9b95a87fe1c6dd9e947c013018254cd2a371.json.headers.json → ca12242429a17998c7e49674bdad647da1a329cdaf432100acd42a69c9bfe4e8.json.headers.json} +0 -0
  92. /package/catalog/published/v1/manifests/sha256/{e9c4da2392cebaa5377154b7fe0e72d7d943032e41cf775d0158df5808d1e38f.json.headers.json → fc947fe6f42d963e6d4757bf0d7a764961d5239e6dfe476b2fb47eb38a5972eb.json.headers.json} +0 -0
  93. /package/catalog/published/v1/manifests/sha256/{fd500c4047bcddcc3d16d4a98ac7d1d0f887e0669a6ae8fa1f391a8b16a8abb9.json.headers.json → fe56c670dc0bbcce9641daddc123124cd50562c628f72bfbc32df6d89070675a.json.headers.json} +0 -0
  94. /package/dist/shell/substrate/shell.compilers/{c5ebb33c1959713cf4dee3482dde9b95a87fe1c6dd9e947c013018254cd2a371 → 939c6b6cf3d34df0d8b9d8d0569874d9bef7c0f6763d3e81d8fa5a89812926cc}/LICENSE.md +0 -0
  95. /package/dist/shell/substrate/shell.compilers/{c5ebb33c1959713cf4dee3482dde9b95a87fe1c6dd9e947c013018254cd2a371 → 939c6b6cf3d34df0d8b9d8d0569874d9bef7c0f6763d3e81d8fa5a89812926cc}/README.md +0 -0
  96. /package/dist/shell/substrate/shell.compilers/{c5ebb33c1959713cf4dee3482dde9b95a87fe1c6dd9e947c013018254cd2a371 → 939c6b6cf3d34df0d8b9d8d0569874d9bef7c0f6763d3e81d8fa5a89812926cc}/bin/esbuild +0 -0
  97. /package/dist/shell/substrate/shell.compilers/{c5ebb33c1959713cf4dee3482dde9b95a87fe1c6dd9e947c013018254cd2a371 → 939c6b6cf3d34df0d8b9d8d0569874d9bef7c0f6763d3e81d8fa5a89812926cc}/esbuild.wasm +0 -0
  98. /package/dist/shell/substrate/shell.compilers/{c5ebb33c1959713cf4dee3482dde9b95a87fe1c6dd9e947c013018254cd2a371 → 939c6b6cf3d34df0d8b9d8d0569874d9bef7c0f6763d3e81d8fa5a89812926cc}/esm/browser.d.ts +0 -0
  99. /package/dist/shell/substrate/shell.compilers/{c5ebb33c1959713cf4dee3482dde9b95a87fe1c6dd9e947c013018254cd2a371 → 939c6b6cf3d34df0d8b9d8d0569874d9bef7c0f6763d3e81d8fa5a89812926cc}/esm/browser.js +0 -0
  100. /package/dist/shell/substrate/shell.compilers/{c5ebb33c1959713cf4dee3482dde9b95a87fe1c6dd9e947c013018254cd2a371 → 939c6b6cf3d34df0d8b9d8d0569874d9bef7c0f6763d3e81d8fa5a89812926cc}/esm/browser.min.js +0 -0
  101. /package/dist/shell/substrate/shell.compilers/{c5ebb33c1959713cf4dee3482dde9b95a87fe1c6dd9e947c013018254cd2a371 → 939c6b6cf3d34df0d8b9d8d0569874d9bef7c0f6763d3e81d8fa5a89812926cc}/lib/browser.d.ts +0 -0
  102. /package/dist/shell/substrate/shell.compilers/{c5ebb33c1959713cf4dee3482dde9b95a87fe1c6dd9e947c013018254cd2a371 → 939c6b6cf3d34df0d8b9d8d0569874d9bef7c0f6763d3e81d8fa5a89812926cc}/lib/browser.js +0 -0
  103. /package/dist/shell/substrate/shell.compilers/{c5ebb33c1959713cf4dee3482dde9b95a87fe1c6dd9e947c013018254cd2a371 → 939c6b6cf3d34df0d8b9d8d0569874d9bef7c0f6763d3e81d8fa5a89812926cc}/lib/browser.min.js +0 -0
  104. /package/dist/shell/substrate/shell.compilers/{c5ebb33c1959713cf4dee3482dde9b95a87fe1c6dd9e947c013018254cd2a371 → 939c6b6cf3d34df0d8b9d8d0569874d9bef7c0f6763d3e81d8fa5a89812926cc}/lib/main.d.ts +0 -0
  105. /package/dist/shell/substrate/shell.compilers/{c5ebb33c1959713cf4dee3482dde9b95a87fe1c6dd9e947c013018254cd2a371 → 939c6b6cf3d34df0d8b9d8d0569874d9bef7c0f6763d3e81d8fa5a89812926cc}/lib/main.js +0 -0
  106. /package/dist/shell/substrate/shell.compilers/{c5ebb33c1959713cf4dee3482dde9b95a87fe1c6dd9e947c013018254cd2a371 → 939c6b6cf3d34df0d8b9d8d0569874d9bef7c0f6763d3e81d8fa5a89812926cc}/package.json +0 -0
  107. /package/dist/shell/substrate/shell.compilers/{c5ebb33c1959713cf4dee3482dde9b95a87fe1c6dd9e947c013018254cd2a371 → 939c6b6cf3d34df0d8b9d8d0569874d9bef7c0f6763d3e81d8fa5a89812926cc}/wasm_exec.js +0 -0
  108. /package/dist/shell/substrate/shell.compilers/{c5ebb33c1959713cf4dee3482dde9b95a87fe1c6dd9e947c013018254cd2a371 → 939c6b6cf3d34df0d8b9d8d0569874d9bef7c0f6763d3e81d8fa5a89812926cc}/wasm_exec_node.js +0 -0
  109. /package/dist/shell/substrate/shell.compilers/{05781228ef0c812f61bf957a9ce2ee58544c4a6c010be46228ec8505a5a1f978 → ca12242429a17998c7e49674bdad647da1a329cdaf432100acd42a69c9bfe4e8}/bindings_wasm_bg.wasm +0 -0
  110. /package/dist/shell/substrate/shell.compilers/{05781228ef0c812f61bf957a9ce2ee58544c4a6c010be46228ec8505a5a1f978 → ca12242429a17998c7e49674bdad647da1a329cdaf432100acd42a69c9bfe4e8}/package.json +0 -0
  111. /package/dist/shell/substrate/shell.compilers/{05781228ef0c812f61bf957a9ce2ee58544c4a6c010be46228ec8505a5a1f978 → ca12242429a17998c7e49674bdad647da1a329cdaf432100acd42a69c9bfe4e8}/rollup.browser.js +0 -0
  112. /package/dist/shell/substrate/shell.compilers/{e9c4da2392cebaa5377154b7fe0e72d7d943032e41cf775d0158df5808d1e38f → fe56c670dc0bbcce9641daddc123124cd50562c628f72bfbc32df6d89070675a}/amaro.js +0 -0
@@ -18060,17 +18060,35 @@ function nodeLibBinding(name) {
18060
18060
  });
18061
18061
  return __table$1[name];
18062
18062
  }
18063
+ function notFound(hostname2, syscall = "getaddrinfo") {
18064
+ return Object.assign(new Error(`${syscall} ENOTFOUND ${hostname2}`), { code: "ENOTFOUND", errno: -3008, syscall, hostname: hostname2 });
18065
+ }
18063
18066
  function literalFamily(hostname2) {
18064
18067
  const bare = hostname2.startsWith("[") && hostname2.endsWith("]") ? hostname2.slice(1, -1) : hostname2;
18065
- if (/^(25[0-5]|2[0-4]\d|1?\d?\d)(\.(25[0-5]|2[0-4]\d|1?\d?\d)){3}$/.test(bare)) return 4;
18068
+ if (/^(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}$/.test(bare)) return 4;
18066
18069
  const host = bare.split("%")[0];
18067
- if (host.includes(":") && /^[0-9a-fA-F:.]+$/.test(host)) return 6;
18070
+ if (host.includes(":")) {
18071
+ try {
18072
+ new URL(`http://[${host}]/`);
18073
+ return 6;
18074
+ } catch {
18075
+ }
18076
+ }
18068
18077
  return 0;
18069
18078
  }
18070
18079
  function lookup(hostname2, optionsOrCallback, callback) {
18071
18080
  const cb2 = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
18072
- const options = typeof optionsOrCallback === "object" ? optionsOrCallback : {};
18081
+ const options = typeof optionsOrCallback === "number" ? { family: optionsOrCallback } : typeof optionsOrCallback === "object" && optionsOrCallback ? optionsOrCallback : {};
18082
+ if (typeof cb2 !== "function") throw Object.assign(new TypeError("The callback argument must be a function"), { code: "ERR_INVALID_ARG_TYPE" });
18083
+ if (hostname2 && typeof hostname2 !== "string") throw Object.assign(new TypeError("The hostname argument must be a string"), { code: "ERR_INVALID_ARG_TYPE" });
18084
+ const requested = options.family === "IPv4" ? 4 : options.family === "IPv6" ? 6 : options.family ?? 0;
18085
+ if (![0, 4, 6].includes(requested)) throw Object.assign(new TypeError(`Invalid address family: ${requested}`), { code: "ERR_INVALID_ARG_VALUE" });
18073
18086
  setImmediate(() => {
18087
+ if (!hostname2) {
18088
+ if (options.all) cb2(null, []);
18089
+ else cb2(null, void 0, requested === 6 ? 6 : 4);
18090
+ return;
18091
+ }
18074
18092
  const family = literalFamily(hostname2);
18075
18093
  if (family) {
18076
18094
  const address = hostname2.startsWith("[") && hostname2.endsWith("]") ? hostname2.slice(1, -1) : hostname2;
@@ -18078,24 +18096,19 @@ function lookup(hostname2, optionsOrCallback, callback) {
18078
18096
  else cb2(null, address, family);
18079
18097
  return;
18080
18098
  }
18081
- if (hostname2 === "localhost") {
18082
- if (options.all) {
18083
- cb2(null, [{ address: "127.0.0.1", family: 4 }]);
18084
- } else {
18085
- cb2(null, "127.0.0.1", 4);
18086
- }
18099
+ if (hostname2.toLowerCase().replace(/\.$/, "") === "localhost") {
18100
+ const families = requested ? [requested] : options.order === "ipv6first" ? [6, 4] : [4, 6];
18101
+ const addresses = families.map((family2) => ({ address: family2 === 6 ? "::1" : "127.0.0.1", family: family2 }));
18102
+ if (options.all) cb2(null, addresses);
18103
+ else cb2(null, addresses[0].address, addresses[0].family);
18087
18104
  } else {
18088
- if (options.all) {
18089
- cb2(null, [{ address: "0.0.0.0", family: 4 }]);
18090
- } else {
18091
- cb2(null, "0.0.0.0", 4);
18092
- }
18105
+ cb2(notFound(hostname2));
18093
18106
  }
18094
18107
  });
18095
18108
  }
18096
18109
  function resolve$1(hostname2, callback) {
18097
18110
  setImmediate(() => {
18098
- callback(null, ["0.0.0.0"]);
18111
+ callback(notFound(hostname2, "queryA"));
18099
18112
  });
18100
18113
  }
18101
18114
  function resolve4(hostname2, callback) {
@@ -18103,12 +18116,12 @@ function resolve4(hostname2, callback) {
18103
18116
  }
18104
18117
  function resolve6(hostname2, callback) {
18105
18118
  setImmediate(() => {
18106
- callback(null, ["::1"]);
18119
+ callback(notFound(hostname2, "queryAaaa"));
18107
18120
  });
18108
18121
  }
18109
18122
  function reverse(ip2, callback) {
18110
18123
  setImmediate(() => {
18111
- callback(null, ["localhost"]);
18124
+ callback(notFound(ip2, "getHostByAddr"));
18112
18125
  });
18113
18126
  }
18114
18127
  function setServers(_servers) {
@@ -18124,14 +18137,14 @@ function getDefaultResultOrder() {
18124
18137
  const promises = {
18125
18138
  lookup: (hostname2, options) => {
18126
18139
  return new Promise((resolve2, reject) => {
18127
- if (options == null ? void 0 : options.all) {
18140
+ if (typeof options === "object" && (options == null ? void 0 : options.all)) {
18128
18141
  lookup(hostname2, options, (err2, addresses) => {
18129
18142
  if (err2) reject(err2);
18130
18143
  else resolve2(addresses || []);
18131
18144
  });
18132
18145
  return;
18133
18146
  }
18134
- lookup(hostname2, options || {}, (err2, address, family) => {
18147
+ lookup(hostname2, options ?? {}, (err2, address, family) => {
18135
18148
  if (err2) reject(err2);
18136
18149
  else resolve2({ address, family });
18137
18150
  });
@@ -18147,13 +18160,19 @@ const promises = {
18147
18160
  },
18148
18161
  resolve4: (hostname2) => promises.resolve(hostname2),
18149
18162
  resolve6: (hostname2) => {
18150
- return new Promise((resolve2) => {
18151
- resolve2(["::1"]);
18163
+ return new Promise((resolve2, reject) => {
18164
+ resolve6(hostname2, (err2, addresses) => {
18165
+ if (err2) reject(err2);
18166
+ else resolve2(addresses || []);
18167
+ });
18152
18168
  });
18153
18169
  },
18154
18170
  reverse: (ip2) => {
18155
- return new Promise((resolve2) => {
18156
- resolve2(["localhost"]);
18171
+ return new Promise((resolve2, reject) => {
18172
+ reverse(ip2, (err2, hostnames) => {
18173
+ if (err2) reject(err2);
18174
+ else resolve2(hostnames || []);
18175
+ });
18157
18176
  });
18158
18177
  },
18159
18178
  setServers: (_servers) => {
@@ -21264,17 +21283,10 @@ var implementation$1 = function bind2(that) {
21264
21283
  var implementation = implementation$1;
21265
21284
  var functionBind = Function.prototype.bind || implementation;
21266
21285
  var functionCall = Function.prototype.call;
21267
- var functionApply;
21268
- var hasRequiredFunctionApply;
21269
- function requireFunctionApply() {
21270
- if (hasRequiredFunctionApply) return functionApply;
21271
- hasRequiredFunctionApply = 1;
21272
- functionApply = Function.prototype.apply;
21273
- return functionApply;
21274
- }
21286
+ var functionApply = Function.prototype.apply;
21275
21287
  var reflectApply = typeof Reflect !== "undefined" && Reflect && Reflect.apply;
21276
21288
  var bind$2 = functionBind;
21277
- var $apply$1 = requireFunctionApply();
21289
+ var $apply$1 = functionApply;
21278
21290
  var $call$2 = functionCall;
21279
21291
  var $reflectApply = reflectApply;
21280
21292
  var actualApply = $reflectApply || bind$2.call($call$2, $apply$1);
@@ -21394,7 +21406,7 @@ var hasSymbols = requireHasSymbols()();
21394
21406
  var getProto = requireGetProto();
21395
21407
  var $ObjectGPO = requireObject_getPrototypeOf();
21396
21408
  var $ReflectGPO = requireReflect_getPrototypeOf();
21397
- var $apply = requireFunctionApply();
21409
+ var $apply = functionApply;
21398
21410
  var $call = functionCall;
21399
21411
  var needsEval = {};
21400
21412
  var TypedArray = typeof Uint8Array === "undefined" || !getProto ? undefined$1 : getProto(Uint8Array);
@@ -22035,7 +22047,7 @@ function requireApplyBind() {
22035
22047
  if (hasRequiredApplyBind) return applyBind;
22036
22048
  hasRequiredApplyBind = 1;
22037
22049
  var bind3 = functionBind;
22038
- var $apply2 = requireFunctionApply();
22050
+ var $apply2 = functionApply;
22039
22051
  var actualApply$1 = actualApply;
22040
22052
  applyBind = function applyBind2() {
22041
22053
  return actualApply$1(bind3, $apply2, arguments);
@@ -1911,7 +1911,7 @@ ${Object.entries(a).map(([c,u])=>`${c}: ${u}`).join(`\r
1911
1911
  \r
1912
1912
  `),l=new Uint8Array(o.byteLength+s.byteLength);return l.set(o),l.set(s,o.byteLength),l}function k$(e,t,r,n){const i=gE(t,r),s=gp(i,[13,10,13,10]);if(s<0)return;const o=new TextDecoder("utf-8",{fatal:!0}).decode(i.subarray(0,s)).split(`\r
1913
1913
  `),l=/^HTTP\/1\.[01] ([1-5][0-9]{2})(?: (.*))?$/u.exec(o.shift()??"");if(!l)throw new Error("WALI loopback server returned an invalid HTTP status line.");const c={};for(const b of o){const w=b.indexOf(":");if(w<=0)throw new Error("WALI loopback server returned an invalid HTTP header.");const S=b.slice(0,w).trim().toLowerCase(),x=b.slice(w+1).trim(),E=c[S];c[S]=E===void 0?x:Array.isArray(E)?[...E,x]:[E,x]}const u=Number(l[1]),d=s+4;if(e==="HEAD"||u<200||u===204||u===304)return{statusCode:u,statusMessage:l[2]||"",headers:c};if(A$(c,"transfer-encoding")?.toLowerCase()?.includes("chunked")){const b=iB(i.subarray(d));return b?{statusCode:u,statusMessage:l[2]||"",headers:c,body:b}:void 0}const g=A$(c,"content-length");if(g!==void 0){const b=Number(g);if(!Number.isSafeInteger(b)||b<0||b>Uc)throw new Error("Invalid WALI loopback Content-Length.");return i.byteLength-d<b?void 0:{statusCode:u,statusMessage:l[2]||"",headers:c,body:i.slice(d,d+b)}}if(n)return{statusCode:u,statusMessage:l[2]||"",headers:c,body:i.slice(d)}}function iB(e){const t=[];let r=0,n=0;for(;;){const i=gp(e,[13,10],n);if(i<0)return;const s=new TextDecoder().decode(e.subarray(n,i)).split(";",1)[0]??"",a=Number.parseInt(s,16);if(!Number.isSafeInteger(a)||a<0)throw new Error("Invalid WALI loopback chunk length.");if(n=i+2,a===0)return e.byteLength<n+2?void 0:gE(t,r);if(e.byteLength<n+a+2)return;if(t.push(e.slice(n,n+a)),r+=a,r>Uc||e[n+a]!==13||e[n+a+1]!==10)throw new Error("Invalid WALI loopback chunked response.");n+=a+2}}function gE(e,t){const r=new Uint8Array(t);let n=0;for(const i of e)r.set(i,n),n+=i.byteLength;return r}function gp(e,t,r=0){e:for(let n=r;n<=e.byteLength-t.length;n+=1){for(let i=0;i<t.length;i+=1)if(e[n+i]!==t[i])continue e;return n}return-1}function A$(e,t){const r=e[t];return Array.isArray(r)?r[0]:r}function l2(e){return Number.isSafeInteger(e)&&e>0&&e<=65535}var C$;(function(e){e[e.Socket=1]="Socket",e[e.Connect=2]="Connect",e[e.Send=3]="Send",e[e.Receive=4]="Receive",e[e.Close=5]="Close",e[e.Fcntl=6]="Fcntl",e[e.Poll=7]="Poll",e[e.Shutdown=8]="Shutdown",e[e.Duplicate=9]="Duplicate",e[e.SocketName=10]="SocketName",e[e.EpollControl=11]="EpollControl",e[e.EpollWait=12]="EpollWait",e[e.EpollCreate=13]="EpollCreate",e[e.EventFd=14]="EventFd",e[e.SocketPair=15]="SocketPair",e[e.TimerFdCreate=16]="TimerFdCreate",e[e.TimerFdSetTime=17]="TimerFdSetTime",e[e.Bind=18]="Bind",e[e.Listen=19]="Listen",e[e.Accept=20]="Accept",e[e.ChildRegister=21]="ChildRegister",e[e.ChildForget=22]="ChildForget",e[e.ChildWait=23]="ChildWait",e[e.ChildExists=24]="ChildExists",e[e.PidFdOpen=25]="PidFdOpen",e[e.PollMany=26]="PollMany"})(C$||(C$={}));new TextEncoder;var T$;(function(e){e[e.Exists=1]="Exists",e[e.Stat=2]="Stat",e[e.Lstat=3]="Lstat",e[e.ReadFile=4]="ReadFile",e[e.WriteFile=5]="WriteFile",e[e.Mkdir=6]="Mkdir",e[e.Readdir=7]="Readdir",e[e.Unlink=8]="Unlink",e[e.Rmdir=9]="Rmdir",e[e.Rename=10]="Rename",e[e.Snapshot=11]="Snapshot",e[e.ReplaceSnapshot=12]="ReplaceSnapshot",e[e.Syscall=13]="Syscall",e[e.ReadForMapping=14]="ReadForMapping",e[e.SnapshotSize=15]="SnapshotSize",e[e.SnapshotChunk=16]="SnapshotChunk",e[e.ReplaceSnapshotStart=17]="ReplaceSnapshotStart",e[e.ReplaceSnapshotChunk=18]="ReplaceSnapshotChunk",e[e.MappingPath=19]="MappingPath",e[e.WriteForMapping=20]="WriteForMapping",e[e.FinalSnapshotSize=21]="FinalSnapshotSize",e[e.ImportPeerPatch=22]="ImportPeerPatch",e[e.ImportPeerPatchStart=23]="ImportPeerPatchStart",e[e.ImportPeerPatchChunk=24]="ImportPeerPatchChunk",e[e.PrepareSpawn=25]="PrepareSpawn",e[e.ReadRange=26]="ReadRange",e[e.WriteRange=27]="WriteRange",e[e.CopyForExec=28]="CopyForExec",e[e.CloseProcess=29]="CloseProcess",e[e.CopyForFork=30]="CopyForFork",e[e.GetCwd=31]="GetCwd",e[e.SyscallBinary=32]="SyscallBinary",e[e.ReadForMappingBinary=33]="ReadForMappingBinary",e[e.WriteForMappingBinary=34]="WriteForMappingBinary"})(T$||(T$={}));var $$;(function(e){e[e.Query=1]="Query",e[e.Open=2]="Open",e[e.Push=3]="Push",e[e.Pull=4]="Pull",e[e.Flush=5]="Flush",e[e.Close=6]="Close"})($$||($$={}));var N$;(function(e){e[e.VideoDecoder=0]="VideoDecoder",e[e.VideoEncoder=1]="VideoEncoder",e[e.AudioDecoder=2]="AudioDecoder",e[e.AudioEncoder=3]="AudioEncoder"})(N$||(N$={}));var R$;(function(e){e[e.State=0]="State",e[e.Operation=1]="Operation",e[e.Result=2]="Result",e[e.Argument0=3]="Argument0",e[e.Argument1=4]="Argument1",e[e.Argument2=5]="Argument2",e[e.Argument3=6]="Argument3",e[e.Argument4=7]="Argument4",e[e.Argument5=8]="Argument5"})(R$||(R$={}));new TextEncoder;new TextDecoder;const O$="/opt/programs/bin",Yme="supercode-browser-credentials",Xme="credentials",sB=1024*1024;class Kme{shared;files;constructor(t,r){this.shared=t,this.files=r}existsSync(t){const r=this.privateFile(t);return r?r.bytes!==void 0:this.shared.existsSync(t)}statSync(t){const r=this.privateFile(t);if(!r)return this.shared.statSync(t);if(!r.bytes)throw new Error(`Private file does not exist: ${t}`);return{isDirectory:()=>!1,mode:r.mode,mtimeMs:r.mtimeMs}}async readFile(t){const r=this.privateFile(t);if(!r)return this.shared.readFile(t);if(!r.bytes)throw new Error(`Private file does not exist: ${t}`);return r.bytes.slice()}writeFileSync(t,r){const n=this.privateFile(t);if(!n){this.shared.writeFileSync(t,r);return}const i=typeof r=="string"?new TextEncoder().encode(r):Uint8Array.from(r);if(i.byteLength===0||i.byteLength>sB)throw new DOMException("Private file exceeds its configured vault bound.","QuotaExceededError");n.bytes=i,n.mode=n.mode||384,n.mtimeMs=Gh()}mkdirSync(t,r){this.shared.mkdirSync(t,r)}unlinkSync(t){const r=this.privateFile(t);if(!r){this.shared.unlinkSync(t);return}if(!r.bytes)throw new Error(`Private file does not exist: ${t}`);r.bytes=void 0,r.mtimeMs=Gh()}rmdirSync(t){this.shared.rmdirSync(t)}chmodSync(t,r){const n=this.privateFile(t);if(!n){this.shared.chmodSync?.(t,r);return}n.mode=r}utimesSync(t,r,n){const i=this.privateFile(t);if(!i){this.shared.utimesSync?.(t,r,n);return}i.mtimeMs=typeof n=="number"?n:Number(n)}privateFile(t){return this.files.find(r=>r.path===t)}}class Qme{filesystem;processHost;manifest;options;capabilities=Object.freeze({filesystemPolicy:!0});worker;privateFiles;privateOverlay;active=!1;constructor(t,r,n,i={}){if(this.filesystem=t,this.processHost=r,this.manifest=n,this.options=i,n.engine!=="wali")throw new Error(`${n.id} is not a WALI program.`);const s=i.vaultNamespace??"default",a=[...new Set(i.sourceVaultNamespaces??[])].filter(l=>l!==s),o=i.createVault??r1e;this.privateFiles=n.storage.privateFiles.map(l=>({path:this.expand(l.path),vault:o(_$(s,l.vault)),sourceVaults:a.map(c=>o(_$(c,l.vault))),...l.defaultContent!==void 0?{defaultContent:l.defaultContent}:{},clearOnActions:new Set(l.clearOnActions??[]),available:!1,presentAfterRun:void 0,bytes:void 0,mode:384,mtimeMs:Gh()})),this.privateOverlay=new Kme(t,this.privateFiles),this.worker=this.createWorker()}get command(){return this.manifest.executable}get displayName(){return this.manifest.displayName}get running(){return this.worker.running}action(t){const r=this.manifest.actions[t];if(!r)throw new Error(`${this.manifest.id} has no ${t} action.`);return r}hasPrivateState(t){return this.privateFiles.some((r,n)=>r.available&&(t===void 0||this.manifest.storage.privateFiles[n]?.vault===t))}acceptsOpenUrl(t){let r;try{r=t instanceof URL?t:new URL(t)}catch{return!1}return this.manifest.openUrls.some(n=>r.protocol===n.protocol&&r.hostname===n.hostname&&r.pathname===n.pathname)}setOpenUrlHandler(t){this.worker.setOpenUrlHandler(t?r=>{this.acceptsOpenUrl(r)&&t(r)}:void 0)}sendInput(t){return this.worker.sendInput(Jme(this.manifest.terminal.input,t))}resize(t,r){this.worker.resize(t,r)}terminate(){this.worker.terminate()}async restoreState(){for(const t of this.privateFiles){await this.filePresent(t.path)&&await t.vault.save(await this.filesystem.readFile(t.path)),this.unmount(t.path);let r=await this.loadPrivateFile(t);!r&&t.defaultContent!==void 0&&(r=new TextEncoder().encode(t.defaultContent),await t.vault.save(r)),t.available=!!r}this.options.onStateChange?.()}get busy(){return this.active}async run(t,r={}){if(r.filesystemPolicy!==void 0&&(r={...r,filesystemPolicy:li(r.filesystemPolicy)}),this.active)throw new Error(`${this.manifest.displayName} is already running.`);const n=t.length===1&&t[0]===this.manifest.executable?this.action("start"):t,i=this.actionName(n);this.active=!0;let s;try{this.options.onStateChange?.(),await this.installResources(),await this.preparePrivateFiles();const a=await this.worker.run(n,r);return a.exitCode===0&&(s=i),a}finally{await this.finalizePrivateFiles(s),this.active=!1,this.options.onStateChange?.()}}async installResources(){await eG(this.filesystem,this.manifest,{...this.options.resourcesUrl?{url:this.options.resourcesUrl}:{},...this.options.resourcesIntegrity?{integrity:this.options.resourcesIntegrity}:{},...this.options.onResourcesProgress?{onProgress:this.options.onResourcesProgress}:{}})}createWorker(){const t=this.options.policy?.programNetwork(this.manifest.id,this.manifest.network.allowedHosts)??{allowedHosts:this.manifest.network.allowedHosts,maxConnections:16,maxBytes:67108864};return new Ame(this.filesystem,{url:this.options.artifactUrl??this.manifest.artifact.url,integrity:this.options.artifactIntegrity??this.manifest.artifact.integrity,cwd:"/workspace",env:Object.fromEntries(Object.entries(this.manifest.environment).map(([r,n])=>[r,this.expand(n)])),threadPoolSize:this.manifest.requirements.workers??18,...this.manifest.requirements.capabilities.includes("media.webcodecs")?{codec:{version:1}}:{},network:{...this.options.relayUrl?{relayUrl:this.options.relayUrl}:{},...t},...this.options.loopback?{loopback:this.options.loopback}:{},spawn:this.options.spawn??this.processHost,excludedImagePaths:()=>[...this.otherProgramTrees(),...this.options.unreadTrees??[]],prepareFilesystem:r=>this.preparePrivateFilesystem(r),sanitizeFilesystem:r=>this.sanitizePrivateFilesystem(r),sanitizeFilesystemPatch:r=>this.sanitizePrivatePatch(r),coherenceFilesystem:this.privateOverlay,onFilesystemCommit:async()=>{await this.persistPrivateOverlay(),await this.options.onFilesystemCommit?.(),this.options.onStateChange?.()}})}expand(t){return t.replaceAll("${HOME}",this.options.userHome??"/home/browser")}actionName(t){return Object.entries(this.manifest.actions).find(([,r])=>e1e(t,r))?.[0]}async preparePrivateFiles(){for(const t of this.privateFiles){const r=await this.loadPrivateFile(t);t.available=!!r,t.presentAfterRun=void 0,t.bytes=r?.slice(),t.mode=384,t.mtimeMs=Gh(),r&&t1e(this.filesystem,t.path)}}otherProgramTrees(){const r=this.manifest.resources?.root?.split("/").filter(Boolean)??[],n=r.indexOf(this.manifest.id),i=n>0?`/${r.slice(0,n).join("/")}`:O$.slice(0,O$.lastIndexOf("/"));return this.filesystem.existsSync(i)?this.filesystem.readdirSync(i).filter(s=>s!==this.manifest.id&&s!=="bin").map(s=>`${i}/${s}`):[]}async preparePrivateFilesystem(t){const r=t.files.filter(n=>!this.privateFiles.some(i=>i.path===n.path));for(const n of this.privateFiles)n.bytes&&r.push({path:n.path,type:"file",content:Ii(n.bytes),mode:n.mode,mtimeMs:n.mtimeMs});return{files:r}}async sanitizePrivateFilesystem(t){return await Promise.all(this.privateFiles.map(r=>this.capturePrivateEntry(r,t.files.find(n=>n.path===r.path)))),{files:t.files.filter(r=>!this.privateFiles.some(n=>n.path===r.path))}}async sanitizePrivatePatch(t){return await Promise.all(this.privateFiles.map(async r=>{const n=t.files.find(i=>i.path===r.path);n?await this.capturePrivateEntry(r,n):t.removed.includes(r.path)&&(r.presentAfterRun=!1,r.bytes=void 0)})),{files:t.files.filter(r=>!this.privateFiles.some(n=>n.path===r.path)),removed:t.removed.filter(r=>!this.privateFiles.some(n=>n.path===r))}}async capturePrivateEntry(t,r){if(r?.type!=="file"){t.presentAfterRun=!1,t.bytes=void 0;return}const n=to(r.content??"");if(n.byteLength===0){t.presentAfterRun=!1,t.bytes=void 0;return}await t.vault.save(n),t.bytes=n,t.mode=r.mode??384,t.mtimeMs=r.mtimeMs??Gh(),t.available=!0,t.presentAfterRun=!0}async finalizePrivateFiles(t){await Promise.all(this.privateFiles.map(async r=>{r.presentAfterRun===!1&&t!==void 0&&r.clearOnActions.has(t)&&(await Promise.all([r.vault,...r.sourceVaults].map(n=>n.clear())),r.available=!1,r.bytes=void 0),r.presentAfterRun=void 0}))}async persistPrivateOverlay(){await Promise.all(this.privateFiles.map(async t=>{if(!t.bytes||t.bytes.byteLength===0){t.presentAfterRun=!1;return}await t.vault.save(t.bytes),t.available=!0,t.presentAfterRun=!0}))}async loadPrivateFile(t){const r=await t.vault.load();if(r)return r;for(const n of t.sourceVaults){const i=await n.load();if(i)return await t.vault.save(i),i}}async filePresent(t){try{return this.filesystem.existsSync(t)&&this.filesystem.statSync(t).isFile()&&(await this.filesystem.readFile(t)).byteLength>0}catch{return!1}}unmount(t){this.filesystem.existsSync(t)&&this.filesystem.statSync(t).isFile()&&this.filesystem.unlinkSync(t)}}function Jme(e,t){if(e==="canonical-lines")return t.replaceAll("\r",`
1914
- `);if(e==="kitty-key-events"){if(/^[^\u0000-\u001f\u007f]+$/u.test(t))return[...t].map(r=>`\x1B[${r.codePointAt(0)};1:2u`).join("");if(t==="\r")return"\x1B[13;1:2u";if(t===" ")return"\x1B[9;1:2u"}return t}function e1e(e,t){return e.length===t.length&&e.every((r,n)=>r===t[n])}function t1e(e,t){const r=t.split("/").filter(Boolean);let n="";for(const i of r.slice(0,-1)){if(n+=`/${i}`,e.existsSync(n)){if(!e.statSync(n).isDirectory())throw new Error(`Private file parent is not a directory: ${n}`);continue}e.mkdirSync(n),e.chmodSync?.(n,448)}}function r1e(e){return new k6({databaseName:Yme,storeName:Xme,primaryKey:e,backupKey:`${e}-backup`,minimumBytes:1,maximumBytes:sB})}function _$(e,t){return e==="default"?t:`${e}-${t}`}const I$="browser-substrate-dependency-plan",M$=1;function n1e(e){if(!Gr(e)||typeof e.url!="string"||!e.url.startsWith("/")||e.url.startsWith("//"))return!1;const t=e.artifact;return Gr(t)&&typeof t.role=="string"&&typeof t.mediaType=="string"&&typeof t.digest=="string"&&/^sha256:[0-9a-f]{64}$/u.test(t.digest)&&(t.archive==="tar"||t.archive==="tar+gzip"||t.archive==="zip")&&[t.bytes,t.expandedBytes,t.files].every(r=>Number.isSafeInteger(r)&&r>=0)}const qa=/^(?!\/)(?!.*(?:^|\/)\.\.(?:\/|$))[^\0]+$/u;function aB(e){if(e!==void 0&&(!Gr(e)||Object.entries(e).some(([t,r])=>!qa.test(t)||!t.includes("node_modules/")||typeof r!="string"||!r.trim())))throw new Error("Malformed exact module refusal map.")}function r0(e){if(!Gr(e)||e.kind!==I$||e.version!==M$)throw new Error("The dependency plan has an unsupported shape or version.");if(typeof e.key!="string"||!e.key)throw new Error("The dependency plan has no key.");if(typeof e.command!="string")throw new Error("The dependency plan names no install command.");if(typeof e.resolver!="string")throw new Error("The dependency plan names no resolver.");if(e.environment!==void 0&&(!Gr(e.environment)||Object.entries(e.environment).some(([a,o])=>!/^[A-Za-z_][A-Za-z0-9_]*$/u.test(a)||typeof o!="string")))throw new Error("Malformed prepared environment.");if(e.nativeBindings!==void 0&&(!Gr(e.nativeBindings)||Object.entries(e.nativeBindings).some(([a,o])=>!qa.test(a)||!a.endsWith(".node")||typeof o!="string"||!qa.test(o)||!o.endsWith(".cjs"))))throw new Error("Malformed exact prepared native binding map.");aB(e.moduleRefusals);const t=e.packages;if(!Array.isArray(t))throw new Error("The dependency plan lists no packages.");for(const a of t)if(!Gr(a)||typeof a.name!="string"||!a.name||typeof a.version!="string"||!a.version||typeof a.tarball!="string"||!a.tarball||a.integrity!==void 0&&(typeof a.integrity!="string"||!/^sha(?:1|256|384|512)-[A-Za-z0-9+/=]+$/u.test(a.integrity))||a.placed!==void 0&&typeof a.placed!="boolean"||a.linuxX64!==void 0&&typeof a.linuxX64!="boolean"||a.pack!==void 0&&!n1e(a.pack))throw new Error("The dependency plan lists a malformed package.");const r=e.links;if(!Array.isArray(r))throw new Error("The dependency plan lists no links.");for(const a of r)if(!Gr(a)||typeof a.path!="string"||!qa.test(a.path)||!Number.isInteger(a.package)||a.package<0||a.package>=t.length)throw new Error("The dependency plan lists a malformed link.");const n=e.instances??[];if(!Array.isArray(n))throw new Error("The dependency plan lists malformed instances.");const i=new Set;for(const a of n){if(!Gr(a)||!Number.isInteger(a.link)||a.link<0||a.link>=r.length||!Array.isArray(a.dependencies))throw new Error("The dependency plan lists a malformed instance.");if(i.has(a.link))throw new Error("The dependency plan lists an instance twice.");i.add(a.link);const o=new Set;for(const l of a.dependencies){if(!Gr(l)||typeof l.slot!="string"||!l.slot||typeof l.request!="string"||!l.request||l.kind!=="runtime"&&l.kind!=="peer"||typeof l.optional!="boolean")throw new Error("The dependency plan lists a malformed dependency binding.");if(o.has(l.slot))throw new Error("The dependency plan lists a dependency slot twice.");o.add(l.slot);const c=l.target;if(c!==null&&(!Gr(c)||"link"in c=="workspace"in c))throw new Error("The dependency plan lists a malformed dependency target.");if(c!==null&&"link"in c&&(!Number.isInteger(c.link)||c.link<0||c.link>=r.length))throw new Error("The dependency plan points at a missing package instance.");if(c!==null&&"workspace"in c&&(typeof c.workspace!="string"||!qa.test(c.workspace)))throw new Error("The dependency plan points at a malformed workspace.")}}const s=e.entries??[];if(!Array.isArray(s))throw new Error("The dependency plan lists no entries.");for(const a of s)if(!Gr(a)||typeof a.path!="string"||!qa.test(a.path)||typeof a.content!="string")throw new Error("The dependency plan lists a malformed entry.");for(const a of["bins","aliases"]){const o=e[a];if(!Array.isArray(o))throw new Error(`The dependency plan lists no ${a}.`);for(const l of o)if(!Gr(l)||typeof l.path!="string"||!qa.test(l.path)||typeof l.target!="string"||!qa.test(l.target)||a==="aliases"&&l.coordinate!==void 0&&(typeof l.coordinate!="string"||!l.coordinate))throw new Error(`The dependency plan lists a malformed ${a.slice(0,-1)}.`)}return{kind:I$,version:M$,key:e.key,command:e.command,resolver:e.resolver,...e.moduleRefusals?{moduleRefusals:{...e.moduleRefusals}}:{},...e.nativeBindings?{nativeBindings:{...e.nativeBindings}}:{},...e.environment?{environment:{...e.environment}}:{},packages:t.map(a=>({name:a.name,version:a.version,tarball:a.tarball,...a.integrity!==void 0?{integrity:a.integrity}:{},...a.placed!==void 0?{placed:a.placed}:{},...a.linuxX64!==void 0?{linuxX64:a.linuxX64}:{},...a.pack!==void 0?{pack:{url:a.pack.url,artifact:{...a.pack.artifact}}}:{}})),links:r.map(a=>({path:a.path,package:a.package})),instances:n.map(a=>({link:a.link,dependencies:a.dependencies.map(o=>({slot:o.slot,request:o.request,kind:o.kind,optional:o.optional,target:o.target===null?null:"link"in o.target?{link:o.target.link}:{workspace:o.target.workspace}}))})),bins:e.bins.map(a=>({path:a.path,target:a.target})),aliases:e.aliases.map(a=>({path:a.path,target:a.target,...a.coordinate!==void 0?{coordinate:a.coordinate}:{}})),entries:s.map(a=>({path:a.path,content:a.content}))}}function i1e(e){if(!Gr(e)||typeof e.url!="string"||typeof e.key!="string"||!e.key||!Number.isInteger(e.packages)||!Number.isInteger(e.links))throw new Error("The image manifest's dependencies block is malformed.");if(e.environment!==void 0&&(!Gr(e.environment)||Object.entries(e.environment).some(([t,r])=>!/^[A-Za-z_][A-Za-z0-9_]*$/u.test(t)||typeof r!="string")))throw new Error("Malformed image dependency environment.");if(e.nativeBindings!==void 0&&(!Gr(e.nativeBindings)||Object.entries(e.nativeBindings).some(([t,r])=>!qa.test(t)||!t.endsWith(".node")||typeof r!="string"||!qa.test(r)||!r.endsWith(".cjs"))))throw new Error("Malformed exact prepared native binding map.");return aB(e.moduleRefusals),{...e.moduleRefusals?{moduleRefusals:{...e.moduleRefusals}}:{},...e.nativeBindings?{nativeBindings:{...e.nativeBindings}}:{},...e.environment?{environment:{...e.environment}}:{},url:e.url,key:e.key,packages:e.packages,links:e.links}}function Gr(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function s1e(e){if(!Gr(e)||e.version!==1||!Gr(e.inputs)||!Gr(e.files)||!Array.isArray(e.outputs))throw new Error("Incomplete prepared project document.");const t=e.inputs,r=e.files;if(typeof t.sourcePin!="string"||!/^[a-f0-9]{40}$/u.test(t.sourcePin)||typeof t.image!="string"||!/^[a-z0-9][a-z0-9._-]{0,63}$/u.test(t.image)||["source","dependencies","build","environment","world","capture","toolchain","recipe","abi"].some(s=>typeof t[s]!="string"||s!=="build"&&!t[s]))throw new Error("Prepared project context is incomplete.");const n=r0(e.plan),i=e.packs;if(!Gr(i)||i.kind!==fhe||i.version!==dhe||i.key!==n.key||!Array.isArray(i.packs)||i.modules!==void 0&&!Array.isArray(i.modules))throw new Error("Prepared browser index differs from its project plan.");for(const[s,a]of Object.entries(r))if(!s.startsWith(`/substrate/${t.image}.`)||/[\\?#]|%2e/iu.test(s)||s.split("/").some(o=>o==="."||o==="..")||typeof a!="string"||!/^sha256:[a-f0-9]{64}$/u.test(a))throw new Error("Invalid project transport binding.");for(const s of[...i.packs,...i.modules??[]])if(!Gr(s)||typeof s.key!="string"||!/^[a-f0-9]{64}$/u.test(s.key)||typeof s.path!="string"||!r[s.path])throw new Error("Unbound prepared browser output.");for(const s of n.packages)if(!s.pack||r[s.pack.url]!==s.pack.artifact.digest)throw new Error("Project package archive is absent from its document.");if(!e.outputs.length||e.outputs.some(s=>!Gr(s)||typeof s.name!="string"||!s.name||typeof s.digest!="string"||!/^sha256:[a-f0-9]{64}$/u.test(s.digest)||typeof s.inputs!="string"||!/^sha256:[a-f0-9]{64}$/u.test(s.inputs)))throw new Error("Unbound project output context.");if(e.warm!==void 0){if(!Gr(e.warm)||!Array.isArray(e.warm.files))throw new Error("Incomplete warm output.");for(const s of e.warm.files)if(!Gr(s)||typeof s.path!="string"||!s.path.startsWith("/workspace/app/")||s.path.split("/").some(a=>a==="."||a==="..")||typeof s.integrity!="string"||!/^sha256-[A-Za-z0-9+/]{43}=$/u.test(s.integrity)||!Number.isSafeInteger(s.bytes)||s.bytes<0||!Number.isSafeInteger(s.mode))throw new Error("Invalid warm output path/bytes.")}if(e.caches!==void 0){if(!Gr(e.caches))throw new Error("Incomplete project cache document.");for(const s of NF(e.caches))if(!r[s.file])throw new Error("Unbound project cache body.")}return e}const D$="browser-substrate-image",L$=1,P$="/_registry",a1e=["pids","pids.identity","logs","tls","consumers","instance.json","stopped.json","booting.json","foreground-run.json","last-use.json","proxy.json","proxy-env.json","proxy-starting.json",".locks","world.env"];function o1e(e){return`/substrate/${e}.image.json`}function l1e(e){return/^[a-z0-9][a-z0-9._-]{0,63}$/u.test(e)}function c1e(e){if(!Ur(e)||e.kind!==D$||e.version!==L$)throw new Error("The image manifest has an unsupported shape or version.");if(typeof e.name!="string"||!l1e(e.name))throw new Error("The image manifest names no valid image.");if(e.project!==void 0&&(typeof e.project!="string"||!/^[a-z0-9](?:[a-z0-9._-]*[a-z0-9])?$/u.test(e.project)))throw new Error("The image manifest's project is not a valid project identity.");const t=e.archive;if(!Ur(t)||typeof t.url!="string"||typeof t.blobs!="string"||typeof t.integrity!="string"||!/^sha256-[A-Za-z0-9+/]+=*$/u.test(t.integrity)||typeof t.entries!="number"||typeof t.fileBytes!="number")throw new Error("The image manifest's archive is incomplete.");const r=e.setup;if(!Ur(r)||!["dockerfile","manifests","image","compose"].includes(r.kind)||typeof r.source!="string"||!Array.isArray(r.ports)||!r.ports.every(d=>Number.isInteger(d)&&d>0&&d<65536)||typeof r.playground!="boolean"||r.browserTests!==void 0&&r.browserTests!==!0||r.install!==void 0&&typeof r.install!="string"||r.build!==void 0&&typeof r.build!="string"||r.dev!==void 0&&typeof r.dev!="string"||r.directory!==void 0&&typeof r.directory!="string")throw new Error("The image manifest's setup is incomplete.");const n=r.image;if(r.kind==="image"&&(!Ur(n)||typeof n.command!="string"||typeof n.workdir!="string"||!Ur(n.env)))throw new Error("The image manifest's prebuilt image is incomplete.");const i=Ur(e.settings)?e.settings:{};for(const d of["sandboxOrigin","relayOrigin","artifactBaseUrl"])if(i[d]!==void 0&&typeof i[d]!="string")throw new Error(`The image manifest's ${d} must be a string.`);if(typeof e.builtAt!="string")throw new Error("The image manifest carries no build time.");const s=e.preparation;if(s!==void 0&&(!Ur(s)||!["none","host"].includes(s.location)||s.engine!==void 0&&!["node-host","docker"].includes(s.engine)||s.installObserved!==void 0&&typeof s.installObserved!="boolean"||s.location==="none"&&(s.engine!==void 0||s.installObserved===!0)))throw new Error("The image manifest's execution preparation is malformed.");const a=e.dev;if(a!==void 0&&(!Ur(a)||typeof a.eventsUrl!="string"||a.startupUrl!==void 0&&(typeof a.startupUrl!="string"||!a.startupUrl.startsWith("/substrate/"))))throw new Error("The image manifest's dev block is malformed.");if(e.rolldown!==void 0)throw new Error("An image must select exact catalog compiler assets; regenerate it with those selections.");const o=e.compilers===void 0?void 0:_q(e.compilers),l=e.registry;if(l!==void 0&&(!Ur(l)||l.path!==P$||!Array.isArray(l.scopes)||!l.scopes.every(d=>typeof d=="string"&&/^@[a-z0-9][a-z0-9._-]*$/u.test(d))||!Array.isArray(l.names)||!l.names.every(d=>typeof d=="string"&&/^[a-z0-9][a-z0-9._-]*$/u.test(d))))throw new Error("The image manifest's registry is malformed.");let c;if(e.outputs!==void 0){if(!Ur(e.outputs))throw new Error("Invalid project output selection.");const d=h0(e.outputs.request);if(d.kind!=="runtime"||d.name!=="project-output"||d.backend!=="tab"||d.phase!=="run"||d.export!=="prepared-output"||!/^[a-f0-9]{40}$/u.test(d.version)||!/^sha256:[a-f0-9]{64}$/u.test(d.instance??"")||d.features.length)throw new Error("Project outputs require an exact source/context selection.");c={request:d}}const u=e.dependencies===void 0?void 0:i1e(e.dependencies);return{kind:D$,version:L$,name:e.name,...typeof e.project=="string"?{project:e.project}:{},...o?{compilers:o}:{},...e.packs!==void 0?{packs:ghe(e.packs)}:{},...e.layers!==void 0?{layers:hhe(e.layers)}:{},...e.warm!==void 0?{warm:mhe(e.warm)}:{},...e.caches!==void 0?{caches:phe(e.caches)}:{},...e.startup!==void 0?{startup:d1e(e.startup)}:{},archive:{url:t.url,blobs:t.blobs,integrity:t.integrity,entries:t.entries,fileBytes:t.fileBytes},setup:{kind:r.kind,source:r.source,...r.install!==void 0?{install:r.install}:{},...r.build!==void 0?{build:r.build}:{},...r.dev!==void 0?{dev:r.dev}:{},...typeof r.devScript=="string"?{devScript:r.devScript}:{},...typeof r.directory=="string"?{directory:r.directory}:{},...typeof r.target=="string"?{target:r.target}:{},...typeof r.context=="string"?{context:r.context}:{},...Array.isArray(r.watch)?{watch:r.watch}:{},...Ur(n)?{image:{command:n.command,workdir:n.workdir,env:{...n.env}}}:{},ports:[...r.ports],playground:r.playground,...r.browserTests===!0?{browserTests:!0}:{}},settings:{...i.sandboxOrigin!==void 0?{sandboxOrigin:i.sandboxOrigin}:{},...i.relayOrigin!==void 0?{relayOrigin:i.relayOrigin}:{},...i.artifactBaseUrl!==void 0?{artifactBaseUrl:i.artifactBaseUrl}:{}},builtAt:e.builtAt,...s!==void 0?{preparation:{...s}}:{},...Ur(a)?{dev:{eventsUrl:a.eventsUrl,...typeof a.startupUrl=="string"?{startupUrl:a.startupUrl}:{}}}:{},...Ur(l)?{registry:{path:P$,scopes:[...l.scopes],names:[...l.names]}}:{},...u!==void 0?{dependencies:u}:{},...c?{outputs:c}:{},...Ur(e.world)?{world:f1e(e.world)}:{},...e.provisions!==void 0?{provisions:u1e(e.provisions)}:{}}}function u1e(e){if(!Ur(e)||typeof e.base!="string"||!/^\/substrate\/[a-z0-9._-]+\.provisions$/u.test(e.base)||typeof e.digest!="string"||!/^sha256:[a-f0-9]{64}$/u.test(e.digest)||!Ur(e.profile)||!Ur(e.types))throw new Error("Image provision descriptor is malformed.");for(const r of["name","version","abi"])if(typeof e.profile[r]!="string"||!e.profile[r])throw new Error("Image provisions need an exact runtime profile.");if(!Array.isArray(e.profile.capabilities)||e.profile.capabilities.some(r=>typeof r!="string"))throw new Error("Image provision capabilities are malformed.");for(const[r,n]of Object.entries(e.types))if(!r.startsWith(e.base+"/v1/")&&!new RegExp("^"+e.base.replaceAll(".","\\.")+"/baseline/[a-f0-9]{64}/").test(r)||r.includes("..")||typeof n!="string"||!/^[a-z0-9.+-]+\/[a-z0-9.+-]+$/u.test(n))throw new Error("Image provision media metadata is malformed.");if(e.commands!==void 0&&(!Array.isArray(e.commands)||e.commands.some(r=>!Ur(r)||r.kind!=="command"||r.phase!=="run"||r.backend!=="tab"||typeof r.name!="string"||typeof r.version!="string"||typeof r.abi!="string"||!Array.isArray(r.features))))throw new Error("Image command requests are malformed.");if(e.baselines!==void 0&&(!Array.isArray(e.baselines)||e.baselines.some(r=>!Ur(r)||r.kind!=="runtime"||r.phase!=="run"||r.backend!=="tab"||r.export!=="runtime-baseline")))throw new Error("Image baseline requests are malformed.");const t=Array.isArray(e.baselines)?e.baselines.map(r=>h0(r)):void 0;if(e.unavailable!==void 0&&(!Array.isArray(e.unavailable)||e.unavailable.some(r=>!Ur(r)||typeof r.provider!="string"||!r.provider.trim()||/[\x00-\x1f]/u.test(r.provider)||typeof r.reason!="string"||!r.reason.trim()||!Array.isArray(r.commands)||r.commands.some(n=>typeof n!="string"||!/^[a-z0-9][a-z0-9._-]*$/iu.test(n)))))throw new Error("Image capability refusals are malformed.");for(const r of e.unavailable??[]){if(r.chromium===void 0)continue;const n=r.chromium;if(!Ur(n)||!Array.isArray(n.revisions)||n.revisions.some(i=>typeof i!="string"||!/^\d+$/u.test(i))||!Array.isArray(n.placements)||n.placements.some(i=>!Ur(i)||typeof i.directory!="string"||!/^[a-z0-9_-]+$/iu.test(i.directory)||typeof i.executable!="string"||!/^[a-z0-9._/-]+$/iu.test(i.executable)||i.executable.split("/").includes("..")))throw new Error("Image Chromium refusal placements are malformed.")}return{...e.unavailable?{unavailable:e.unavailable}:{},...t?{baselines:t}:{},...e.commands?{commands:e.commands}:{},base:e.base,digest:e.digest,profile:e.profile,types:e.types}}function f1e(e){const t=e.archive;if(typeof e.name!="string"||typeof e.config!="string"||!Ur(t)||typeof t.url!="string"||typeof t.blobs!="string"||typeof t.integrity!="string")throw new Error("The image manifest's world is malformed.");if(e.outputs!==void 0){if(!Ur(e.outputs))throw new Error("Invalid project output selection.");const n=h0(e.outputs.request);if(n.kind!=="runtime"||n.name!=="project-output"||n.backend!=="tab"||n.phase!=="run"||n.export!=="prepared-output"||!/^[a-f0-9]{40}$/u.test(n.version)||!/^sha256:[a-f0-9]{64}$/u.test(n.instance??"")||n.features.length)throw new Error("Project outputs require an exact source/context selection.")}const r=e.dependencies;if(e.environmentOutputFlag!==void 0&&e.environmentOutputFlag!=="--env-file"&&e.environmentOutputFlag!=="--env-out")throw new Error("The image manifest's World environment output flag is unsupported.");if(e.runtimeVersion!==void 0&&(typeof e.runtimeVersion!="string"||!/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/u.test(e.runtimeVersion)))throw new Error("Image World runtime pin is malformed.");return{name:e.name,...e.runtimeVersion?{runtimeVersion:e.runtimeVersion}:{},...e.environmentOutputFlag?{environmentOutputFlag:e.environmentOutputFlag}:{},config:e.config,archive:{url:t.url,blobs:t.blobs,integrity:t.integrity,entries:Number(t.entries??0),fileBytes:Number(t.fileBytes??0)},...Ur(r)&&typeof r.url=="string"&&typeof r.key=="string"?{dependencies:{url:r.url,key:r.key,packages:Number(r.packages??0),links:Number(r.links??0)}}:{}}}function Ur(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function d1e(e){if(!Ur(e)||typeof e.url!="string"||!/^\/substrate\/[A-Za-z0-9._-]+\.startup\.json$/u.test(e.url)||!Number.isSafeInteger(e.ranges)||e.ranges<0)throw new Error("The image manifest's startup set is malformed.");const t=e.streams;if(t!==void 0&&(!Array.isArray(t)||t.length>8||!t.every(r=>Ur(r)&&typeof r.url=="string"&&/^\/substrate\/[A-Za-z0-9._-]+\.startup\/[a-f0-9]{64}\.bin$/u.test(r.url)&&Number.isSafeInteger(r.bytes)&&r.bytes>=0&&Number.isSafeInteger(r.ranges)&&r.ranges>=0)))throw new Error("The image manifest's startup streams are malformed.");return{url:e.url,ranges:e.ranges,...t?{streams:t.map(r=>({url:r.url,bytes:r.bytes,ranges:r.ranges}))}:{}}}function h1e(e){return{version:1,preparation:e?.location??"unknown",phases:{install:e?.installObserved?["host"]:[],build:e?.location==="host"?["host"]:[],devServer:[],agentTools:[]}}}function Wa(e,t,r){e.phases[t].includes(r)||e.phases[t].push(r)}function p1e(e,t){t?.location==="host"?(e.preparation="host",Wa(e,"build","host"),t.installObserved&&Wa(e,"install","host")):!t&&e.preparation!=="host"&&(e.preparation="unknown")}function m1e(e){return/(?:^|[;&|]\s*|\s)(?:npm|pnpm|yarn|pip3?|uv)\s+(?:install|ci|sync|pip\s+install)(?:\s|$)/u.test(e)}function g1e(e){const t=n=>n.length===0?"not run yet":n.map(i=>i==="browser"?"in this browser":"on a host").join(" and "),r=e.preparation==="none"?"no host prepared the image":e.preparation==="host"?"a host prepared the image":"the image's preparation is unknown";return`Where it ran: install ${t(e.phases.install)}, build ${t(e.phases.build)}, dev server ${t(e.phases.devServer)}, agent tools ${t(e.phases.agentTools)}; ${r}`}function oB(e,t){if(!e.image)throw new Error(`${e.name}: no image request.`);return{kind:"image",...cR(e.image.raw),backend:"tab",phase:"run",abi:t.abi,export:"compose-service",features:[...e.volumes.some(n=>!n.readOnly)?["persistent-data"]:[],...Object.keys(e.environment).map(n=>`environment:${n}`),...[...e.command??[],...e.entrypoint??[]].filter(n=>/^--/u.test(n)).map(n=>`argument:${n.split("=")[0]}`)]}}function y1e(e,t){const r={},n=[];for(const i of e.services){if(i.build||!i.image)continue;const s=oB(i,t.runtime),a=t.rows.filter(d=>d.request.kind===s.kind&&d.request.name===s.name&&d.request.version===s.version&&d.request.backend===s.backend&&d.request.phase===s.phase&&d.request.abi===s.abi&&d.request.export===s.export&&s.features.every(p=>d.request.features.includes(p))),o=a[0];if(a.some(d=>d.selection?.entry.manifest!==o?.selection?.entry.manifest||d.selection?.entry.closure!==o?.selection?.entry.closure))throw new Error(`${i.name}: inconsistent catalog service selections.`);if(!o||o.status!=="resolved"||!o.selection||o.provision?.disposition!=="pack"||o.provision.contract.kind!=="service")throw new Error(`${i.name}: ${o?.reason??"No authenticated exact service provision"}. ${o?.prepare??"Prepare and publish the qualified engine/World closure on a host."}`);const l=o.provision.contract,c=o.provision;if(!s.features.every(d=>c.features.includes(d)))throw new Error(`${i.name}: service feature contract does not cover this request.`);if(![...o.selection.manifests.values()].some(d=>d.integration.kind==="program"&&d.integration.executable===l.program))throw new Error(`${i.name}: selected closure does not export ${l.program}.`);r[i.image.raw]={program:l.program},n.push({service:i.name,image:i.image.raw,contract:l,selection:o.selection})}return{images:r,bindings:n}}async function lB(e,t,r){const n=e.services.filter(i=>!i.build&&i.image).map(i=>oB(i,r));return y1e(e,await t.planProvisions(n,r))}function b1e(e,t,r){const n={};for(const i of e.bindings)n[i.contract.program]=(s,a)=>{const o=e.bindings.find(p=>p.service===s.name);if(!o)throw new Error(`${s.name}: missing exact prepared service binding.`);const l=o.contract;if(l.owner==="world"&&!t)throw new Error(`${s.name}: the selected World-owned engine requires its existing pinned World attachment.`);if(l.owner==="world"&&(!l.worldRuntime||l.worldRuntime!==r))throw new Error(`${s.name}: World runtime must be the selected pin ${l.worldRuntime??"missing"}.`);if(s.entrypoint||s.command)throw new Error(`${s.name}: overridden entrypoint/command requires an explicitly prepared command contract.`);const c=a.ports[0];if(!c)throw new Error(`${s.name}: declare its loopback port explicitly.`);const d=[l.program,...l.argv.map(p=>p==="${PORT}"?String(c):p)].map(w1e).join(" ");return{command:l.owner==="world"?t(d):d,env:Object.fromEntries(l.environment.filter(p=>a.env[p]!==void 0).map(p=>[p,a.env[p]])),ports:[c]}};return n}function w1e(e){return`'${e.replaceAll("'","'\\''")}'`}const v1e=["compose.yaml","compose.yml","docker-compose.yaml","docker-compose.yml"];async function cB(e,t){const r=e.filesystem,n=`${t.root}/${t.source}`,i=HN(await r.readFile(n,"utf8"),{environment:t.env}),s={};for(const c of i.services){if(!c.build)continue;const u=c.build.context.replace(/^\.\/?/u,"").replace(/\/$/u,""),d=`${t.root}${u?`/${u}`:""}/${c.build.dockerfile}`;if(!r.existsSync(d))throw new Error(`Service ${c.name} builds from ${d}, which is not in the project.`);s[c.name]=Kh(await r.readFile(d,"utf8"),{buildArgs:c.build.args})}const a=t.services?await lB(i,t.services.catalog,t.services.profile):{images:{},bindings:[]};for(const c of a.bindings)await t.services.materialize(c.selection);const o=I6(e,{images:a.images}),l=sH(i,o,{resolveBuild:c=>s[c.name]});if(l.verdict!=="native"){const c=l.blocking.map(u=>`${u.service}: ${u.reason}`).join("; ");throw new Error(`Only what runs in the tab can run here, and this stack has more: ${c}`)}return vH(e,l,{lanes:o,context:t.root,stagesRoot:t.stagesRoot,builds:s,programs:b1e(a,t.services?.attachWorld,t.services?.worldRuntime),environment:t.env,portTimeoutMs:t.portTimeoutMs??18e4,...t.forward.signal?{signal:t.forward.signal}:{},onStdout:(c,u)=>t.forward.onStdout?.(`${c} | ${u}`),onStderr:(c,u)=>t.forward.onStderr?.(`${c} | ${u}`)})}const x1e="browser-substrate.playground",S1e=[".devcontainer/devcontainer.json",".devcontainer.json"],E1e=["dev","development","devel","builder-dev"],k1e=["@playwright/test","playwright","playwright-core","puppeteer","puppeteer-core"];class el extends Error{}async function A1e(e,t={}){const r=await C1e(e,t);if(!r||!e.exists("package.json"))return r;try{const n=JSON.parse(await e.read("package.json")??"{}"),i=new Set([...Object.keys(n.dependencies??{}),...Object.keys(n.devDependencies??{})]);if(k1e.some(s=>i.has(s)))return{...r,browserTests:!0}}catch{}return r}async function C1e(e,t){if(t.serve){const o=await e.read("package.json"),l=o!==void 0?await F$(o,e,{lenient:!0,served:!0}):{kind:"manifests",source:"package.json",ports:[],playground:!1},{devScript:c,directory:u,...d}=l;return{...d,source:"command line",dev:t.serve,...t.directory?{directory:t.directory}:{}}}const r=await e.read("Dockerfile"),n=await L1e(e);for(const o of v1e){const l=await e.read(o);if(l===void 0)continue;const c=HN(l,{}),u=t.serviceImages?await t.serviceImages(c):{},d=c.services.filter(g=>g.build===void 0&&g.image!==void 0&&!u[g.image.raw]&&!u[g.image.repository]);if(d.length>0&&r!==void 0)break;if(d.length>0){const g=d.map(b=>`${b.name} (${b.image.repository})`).join(", ");throw new el(`${o} needs a qualified catalog service provision: ${g}. Prepare and publish its real engine/driver-protocol closure on a host. Missing initialization, extensions or storage contracts are refused; a catalog match never grants a World lifecycle.`)}const p=[...new Set(c.services.flatMap(g=>g.ports.map(b=>b.host??b.container)))],m=c.services.flatMap(g=>g.develop?.watch??[]);return{kind:"compose",source:o,ports:p,playground:!1,...m.length>0?{watch:m}:{}}}if(n?.dockerfile){const o=await e.read(n.dockerfile);if(o===void 0)throw new el(`${n.source} names ${n.dockerfile}, which is not in the project.`);return{...U$(Kh(o)),source:n.dockerfile,...n.target?{target:n.target}:{},context:n.context??(n.dockerfile.includes("/")?n.dockerfile.slice(0,n.dockerfile.lastIndexOf("/")):"")}}if(r!==void 0){const o=Kh(r),l=U$(o),c=o.stages.map(u=>u.name).find(u=>E1e.includes(u));return c?{...l,target:c}:l}const i=await e.read("package.json");if(i!==void 0){const o=await F$(i,e),l=await l6(e);if(l===void 0)return o;const{devScript:c,directory:u,...d}=o;return{...d,source:"Procfile",dev:l}}const s=await $1e(e);if(s)return s;const a=await l6(e);if(a)return{kind:"manifests",source:"Procfile",dev:a,ports:[],playground:!1}}async function l6(e){const t=await e.read("Procfile");if(t!==void 0)for(const r of t.split(`
1914
+ `);if(e==="kitty-key-events"){if(/^[^\u0000-\u001f\u007f]+$/u.test(t))return[...t].map(r=>`\x1B[${r.codePointAt(0)};1:2u`).join("");if(t==="\r")return"\x1B[13;1:2u";if(t===" ")return"\x1B[9;1:2u"}return t}function e1e(e,t){return e.length===t.length&&e.every((r,n)=>r===t[n])}function t1e(e,t){const r=t.split("/").filter(Boolean);let n="";for(const i of r.slice(0,-1)){if(n+=`/${i}`,e.existsSync(n)){if(!e.statSync(n).isDirectory())throw new Error(`Private file parent is not a directory: ${n}`);continue}e.mkdirSync(n),e.chmodSync?.(n,448)}}function r1e(e){return new k6({databaseName:Yme,storeName:Xme,primaryKey:e,backupKey:`${e}-backup`,minimumBytes:1,maximumBytes:sB})}function _$(e,t){return e==="default"?t:`${e}-${t}`}const I$="browser-substrate-dependency-plan",M$=1;function n1e(e){if(!Gr(e)||typeof e.url!="string"||!e.url.startsWith("/")||e.url.startsWith("//"))return!1;const t=e.artifact;return Gr(t)&&typeof t.role=="string"&&typeof t.mediaType=="string"&&typeof t.digest=="string"&&/^sha256:[0-9a-f]{64}$/u.test(t.digest)&&(t.archive==="tar"||t.archive==="tar+gzip"||t.archive==="zip")&&[t.bytes,t.expandedBytes,t.files].every(r=>Number.isSafeInteger(r)&&r>=0)}const qa=/^(?!\/)(?!.*(?:^|\/)\.\.(?:\/|$))[^\0]+$/u;function aB(e){if(e!==void 0&&(!Gr(e)||Object.entries(e).some(([t,r])=>!qa.test(t)||!t.includes("node_modules/")||typeof r!="string"||!r.trim())))throw new Error("Malformed exact module refusal map.")}function r0(e){if(!Gr(e)||e.kind!==I$||e.version!==M$)throw new Error("The dependency plan has an unsupported shape or version.");if(typeof e.key!="string"||!e.key)throw new Error("The dependency plan has no key.");if(typeof e.command!="string")throw new Error("The dependency plan names no install command.");if(typeof e.resolver!="string")throw new Error("The dependency plan names no resolver.");if(e.environment!==void 0&&(!Gr(e.environment)||Object.entries(e.environment).some(([a,o])=>!/^[A-Za-z_][A-Za-z0-9_]*$/u.test(a)||typeof o!="string")))throw new Error("Malformed prepared environment.");if(e.nativeBindings!==void 0&&(!Gr(e.nativeBindings)||Object.entries(e.nativeBindings).some(([a,o])=>!qa.test(a)||!a.endsWith(".node")||typeof o!="string"||!qa.test(o)||!o.endsWith(".cjs"))))throw new Error("Malformed exact prepared native binding map.");aB(e.moduleRefusals);const t=e.packages;if(!Array.isArray(t))throw new Error("The dependency plan lists no packages.");for(const a of t)if(!Gr(a)||typeof a.name!="string"||!a.name||typeof a.version!="string"||!a.version||typeof a.tarball!="string"||!a.tarball||a.integrity!==void 0&&(typeof a.integrity!="string"||!/^sha(?:1|256|384|512)-[A-Za-z0-9+/=]+$/u.test(a.integrity))||a.placed!==void 0&&typeof a.placed!="boolean"||a.linuxX64!==void 0&&typeof a.linuxX64!="boolean"||a.pack!==void 0&&!n1e(a.pack))throw new Error("The dependency plan lists a malformed package.");const r=e.links;if(!Array.isArray(r))throw new Error("The dependency plan lists no links.");for(const a of r)if(!Gr(a)||typeof a.path!="string"||!qa.test(a.path)||!Number.isInteger(a.package)||a.package<0||a.package>=t.length)throw new Error("The dependency plan lists a malformed link.");const n=e.instances??[];if(!Array.isArray(n))throw new Error("The dependency plan lists malformed instances.");const i=new Set;for(const a of n){if(!Gr(a)||!Number.isInteger(a.link)||a.link<0||a.link>=r.length||!Array.isArray(a.dependencies))throw new Error("The dependency plan lists a malformed instance.");if(i.has(a.link))throw new Error("The dependency plan lists an instance twice.");i.add(a.link);const o=new Set;for(const l of a.dependencies){if(!Gr(l)||typeof l.slot!="string"||!l.slot||typeof l.request!="string"||!l.request||l.kind!=="runtime"&&l.kind!=="peer"||typeof l.optional!="boolean")throw new Error("The dependency plan lists a malformed dependency binding.");if(o.has(l.slot))throw new Error("The dependency plan lists a dependency slot twice.");o.add(l.slot);const c=l.target;if(c!==null&&(!Gr(c)||"link"in c=="workspace"in c))throw new Error("The dependency plan lists a malformed dependency target.");if(c!==null&&"link"in c&&(!Number.isInteger(c.link)||c.link<0||c.link>=r.length))throw new Error("The dependency plan points at a missing package instance.");if(c!==null&&"workspace"in c&&(typeof c.workspace!="string"||!qa.test(c.workspace)))throw new Error("The dependency plan points at a malformed workspace.")}}const s=e.entries??[];if(!Array.isArray(s))throw new Error("The dependency plan lists no entries.");for(const a of s)if(!Gr(a)||typeof a.path!="string"||!qa.test(a.path)||typeof a.content!="string")throw new Error("The dependency plan lists a malformed entry.");for(const a of["bins","aliases"]){const o=e[a];if(!Array.isArray(o))throw new Error(`The dependency plan lists no ${a}.`);for(const l of o)if(!Gr(l)||typeof l.path!="string"||!qa.test(l.path)||typeof l.target!="string"||!qa.test(l.target)||a==="aliases"&&l.coordinate!==void 0&&(typeof l.coordinate!="string"||!l.coordinate))throw new Error(`The dependency plan lists a malformed ${a.slice(0,-1)}.`)}return{kind:I$,version:M$,key:e.key,command:e.command,resolver:e.resolver,...e.moduleRefusals?{moduleRefusals:{...e.moduleRefusals}}:{},...e.nativeBindings?{nativeBindings:{...e.nativeBindings}}:{},...e.environment?{environment:{...e.environment}}:{},packages:t.map(a=>({name:a.name,version:a.version,tarball:a.tarball,...a.integrity!==void 0?{integrity:a.integrity}:{},...a.placed!==void 0?{placed:a.placed}:{},...a.linuxX64!==void 0?{linuxX64:a.linuxX64}:{},...a.pack!==void 0?{pack:{url:a.pack.url,artifact:{...a.pack.artifact}}}:{}})),links:r.map(a=>({path:a.path,package:a.package})),instances:n.map(a=>({link:a.link,dependencies:a.dependencies.map(o=>({slot:o.slot,request:o.request,kind:o.kind,optional:o.optional,target:o.target===null?null:"link"in o.target?{link:o.target.link}:{workspace:o.target.workspace}}))})),bins:e.bins.map(a=>({path:a.path,target:a.target})),aliases:e.aliases.map(a=>({path:a.path,target:a.target,...a.coordinate!==void 0?{coordinate:a.coordinate}:{}})),entries:s.map(a=>({path:a.path,content:a.content}))}}function i1e(e){if(!Gr(e)||typeof e.url!="string"||typeof e.key!="string"||!e.key||!Number.isInteger(e.packages)||!Number.isInteger(e.links))throw new Error("The image manifest's dependencies block is malformed.");if(e.environment!==void 0&&(!Gr(e.environment)||Object.entries(e.environment).some(([t,r])=>!/^[A-Za-z_][A-Za-z0-9_]*$/u.test(t)||typeof r!="string")))throw new Error("Malformed image dependency environment.");if(e.nativeBindings!==void 0&&(!Gr(e.nativeBindings)||Object.entries(e.nativeBindings).some(([t,r])=>!qa.test(t)||!t.endsWith(".node")||typeof r!="string"||!qa.test(r)||!r.endsWith(".cjs"))))throw new Error("Malformed exact prepared native binding map.");return aB(e.moduleRefusals),{...e.moduleRefusals?{moduleRefusals:{...e.moduleRefusals}}:{},...e.nativeBindings?{nativeBindings:{...e.nativeBindings}}:{},...e.environment?{environment:{...e.environment}}:{},url:e.url,key:e.key,packages:e.packages,links:e.links}}function Gr(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function s1e(e){if(!Gr(e)||e.version!==1||!Gr(e.inputs)||!Gr(e.files)||!Array.isArray(e.outputs))throw new Error("Incomplete prepared project document.");const t=e.inputs,r=e.files;if(typeof t.sourcePin!="string"||!/^(?:[a-f0-9]{40}|sha256:[a-f0-9]{64})$/u.test(t.sourcePin)||typeof t.image!="string"||!/^[a-z0-9][a-z0-9._-]{0,63}$/u.test(t.image)||["source","dependencies","build","environment","world","capture","toolchain","recipe","abi"].some(s=>typeof t[s]!="string"||s!=="build"&&!t[s]))throw new Error("Prepared project context is incomplete.");const n=r0(e.plan),i=e.packs;if(!Gr(i)||i.kind!==fhe||i.version!==dhe||i.key!==n.key||!Array.isArray(i.packs)||i.modules!==void 0&&!Array.isArray(i.modules))throw new Error("Prepared browser index differs from its project plan.");for(const[s,a]of Object.entries(r))if(!s.startsWith(`/substrate/${t.image}.`)||/[\\?#]|%2e/iu.test(s)||s.split("/").some(o=>o==="."||o==="..")||typeof a!="string"||!/^sha256:[a-f0-9]{64}$/u.test(a))throw new Error("Invalid project transport binding.");for(const s of[...i.packs,...i.modules??[]])if(!Gr(s)||typeof s.key!="string"||!/^[a-f0-9]{64}$/u.test(s.key)||typeof s.path!="string"||!r[s.path])throw new Error("Unbound prepared browser output.");for(const s of n.packages)if(!s.pack||r[s.pack.url]!==s.pack.artifact.digest)throw new Error("Project package archive is absent from its document.");if(!e.outputs.length||e.outputs.some(s=>!Gr(s)||typeof s.name!="string"||!s.name||typeof s.digest!="string"||!/^sha256:[a-f0-9]{64}$/u.test(s.digest)||typeof s.inputs!="string"||!/^sha256:[a-f0-9]{64}$/u.test(s.inputs)||!Object.values(r).includes(s.digest)))throw new Error("Unbound project output context.");if(e.warm!==void 0){if(!Gr(e.warm)||!Array.isArray(e.warm.files))throw new Error("Incomplete warm output.");for(const s of e.warm.files)if(!Gr(s)||typeof s.path!="string"||!s.path.startsWith("/workspace/app/")||s.path.split("/").some(a=>a==="."||a==="..")||typeof s.integrity!="string"||!/^sha256-[A-Za-z0-9+/]{43}=$/u.test(s.integrity)||!Number.isSafeInteger(s.bytes)||s.bytes<0||!Number.isSafeInteger(s.mode))throw new Error("Invalid warm output path/bytes.")}if(e.caches!==void 0){if(!Gr(e.caches))throw new Error("Incomplete project cache document.");for(const s of NF(e.caches))if(!r[s.file])throw new Error("Unbound project cache body.")}return e}const D$="browser-substrate-image",L$=1,P$="/_registry",a1e=["pids","pids.identity","logs","tls","consumers","instance.json","stopped.json","booting.json","foreground-run.json","last-use.json","proxy.json","proxy-env.json","proxy-starting.json",".locks","world.env"];function o1e(e){return`/substrate/${e}.image.json`}function l1e(e){return/^[a-z0-9][a-z0-9._-]{0,63}$/u.test(e)}function c1e(e){if(!Ur(e)||e.kind!==D$||e.version!==L$)throw new Error("The image manifest has an unsupported shape or version.");if(typeof e.name!="string"||!l1e(e.name))throw new Error("The image manifest names no valid image.");if(e.project!==void 0&&(typeof e.project!="string"||!/^[a-z0-9](?:[a-z0-9._-]*[a-z0-9])?$/u.test(e.project)))throw new Error("The image manifest's project is not a valid project identity.");const t=e.archive;if(!Ur(t)||typeof t.url!="string"||typeof t.blobs!="string"||typeof t.integrity!="string"||!/^sha256-[A-Za-z0-9+/]+=*$/u.test(t.integrity)||typeof t.entries!="number"||typeof t.fileBytes!="number")throw new Error("The image manifest's archive is incomplete.");const r=e.setup;if(!Ur(r)||!["dockerfile","manifests","image","compose"].includes(r.kind)||typeof r.source!="string"||!Array.isArray(r.ports)||!r.ports.every(d=>Number.isInteger(d)&&d>0&&d<65536)||typeof r.playground!="boolean"||r.browserTests!==void 0&&r.browserTests!==!0||r.install!==void 0&&typeof r.install!="string"||r.build!==void 0&&typeof r.build!="string"||r.dev!==void 0&&typeof r.dev!="string"||r.directory!==void 0&&typeof r.directory!="string")throw new Error("The image manifest's setup is incomplete.");const n=r.image;if(r.kind==="image"&&(!Ur(n)||typeof n.command!="string"||typeof n.workdir!="string"||!Ur(n.env)))throw new Error("The image manifest's prebuilt image is incomplete.");const i=Ur(e.settings)?e.settings:{};for(const d of["sandboxOrigin","relayOrigin","artifactBaseUrl"])if(i[d]!==void 0&&typeof i[d]!="string")throw new Error(`The image manifest's ${d} must be a string.`);if(typeof e.builtAt!="string")throw new Error("The image manifest carries no build time.");const s=e.preparation;if(s!==void 0&&(!Ur(s)||!["none","host"].includes(s.location)||s.engine!==void 0&&!["node-host","docker"].includes(s.engine)||s.installObserved!==void 0&&typeof s.installObserved!="boolean"||s.location==="none"&&(s.engine!==void 0||s.installObserved===!0)))throw new Error("The image manifest's execution preparation is malformed.");const a=e.dev;if(a!==void 0&&(!Ur(a)||typeof a.eventsUrl!="string"||a.startupUrl!==void 0&&(typeof a.startupUrl!="string"||!a.startupUrl.startsWith("/substrate/"))))throw new Error("The image manifest's dev block is malformed.");if(e.rolldown!==void 0)throw new Error("An image must select exact catalog compiler assets; regenerate it with those selections.");const o=e.compilers===void 0?void 0:_q(e.compilers),l=e.registry;if(l!==void 0&&(!Ur(l)||l.path!==P$||!Array.isArray(l.scopes)||!l.scopes.every(d=>typeof d=="string"&&/^@[a-z0-9][a-z0-9._-]*$/u.test(d))||!Array.isArray(l.names)||!l.names.every(d=>typeof d=="string"&&/^[a-z0-9][a-z0-9._-]*$/u.test(d))))throw new Error("The image manifest's registry is malformed.");let c;if(e.outputs!==void 0){if(!Ur(e.outputs))throw new Error("Invalid project output selection.");if(e.outputs.url!==void 0){const d=e.outputs;if(typeof d.url!="string"||!d.url.startsWith(`/substrate/${e.name}.outputs/`)||/[\\?#]|%2e/iu.test(d.url)||d.url.split("/").some(p=>p==="."||p==="..")||!/^sha256:[a-f0-9]{64}$/u.test(String(d.digest))||!/^sha256:[a-f0-9]{64}$/u.test(String(d.inputs))||!/^(?:[a-f0-9]{40}|sha256:[a-f0-9]{64})$/u.test(String(d.sourcePin))||!Number.isSafeInteger(d.bytes)||d.bytes<0)throw new Error("Invalid carried project output descriptor.");c={url:d.url,digest:d.digest,bytes:d.bytes,inputs:d.inputs,sourcePin:d.sourcePin}}else{const d=h0(e.outputs.request);if(d.kind!=="runtime"||d.name!=="project-output"||d.backend!=="tab"||d.phase!=="run"||d.export!=="prepared-output"||!/^[a-f0-9]{40}$/u.test(d.version)||!/^sha256:[a-f0-9]{64}$/u.test(d.instance??"")||d.features.length)throw new Error("Project outputs require an exact source/context selection.");c={request:d}}}const u=e.dependencies===void 0?void 0:i1e(e.dependencies);return{kind:D$,version:L$,name:e.name,...typeof e.project=="string"?{project:e.project}:{},...o?{compilers:o}:{},...e.packs!==void 0?{packs:ghe(e.packs)}:{},...e.layers!==void 0?{layers:hhe(e.layers)}:{},...e.warm!==void 0?{warm:mhe(e.warm)}:{},...e.caches!==void 0?{caches:phe(e.caches)}:{},...e.startup!==void 0?{startup:d1e(e.startup)}:{},archive:{url:t.url,blobs:t.blobs,integrity:t.integrity,entries:t.entries,fileBytes:t.fileBytes},setup:{kind:r.kind,source:r.source,...r.install!==void 0?{install:r.install}:{},...r.build!==void 0?{build:r.build}:{},...r.dev!==void 0?{dev:r.dev}:{},...typeof r.devScript=="string"?{devScript:r.devScript}:{},...typeof r.directory=="string"?{directory:r.directory}:{},...typeof r.target=="string"?{target:r.target}:{},...typeof r.context=="string"?{context:r.context}:{},...Array.isArray(r.watch)?{watch:r.watch}:{},...Ur(n)?{image:{command:n.command,workdir:n.workdir,env:{...n.env}}}:{},ports:[...r.ports],playground:r.playground,...r.browserTests===!0?{browserTests:!0}:{}},settings:{...i.sandboxOrigin!==void 0?{sandboxOrigin:i.sandboxOrigin}:{},...i.relayOrigin!==void 0?{relayOrigin:i.relayOrigin}:{},...i.artifactBaseUrl!==void 0?{artifactBaseUrl:i.artifactBaseUrl}:{}},builtAt:e.builtAt,...s!==void 0?{preparation:{...s}}:{},...Ur(a)?{dev:{eventsUrl:a.eventsUrl,...typeof a.startupUrl=="string"?{startupUrl:a.startupUrl}:{}}}:{},...Ur(l)?{registry:{path:P$,scopes:[...l.scopes],names:[...l.names]}}:{},...u!==void 0?{dependencies:u}:{},...c?{outputs:c}:{},...Ur(e.world)?{world:f1e(e.world)}:{},...e.provisions!==void 0?{provisions:u1e(e.provisions)}:{}}}function u1e(e){if(!Ur(e)||typeof e.base!="string"||!/^\/substrate\/[a-z0-9._-]+\.provisions$/u.test(e.base)||typeof e.digest!="string"||!/^sha256:[a-f0-9]{64}$/u.test(e.digest)||!Ur(e.profile)||!Ur(e.types))throw new Error("Image provision descriptor is malformed.");for(const r of["name","version","abi"])if(typeof e.profile[r]!="string"||!e.profile[r])throw new Error("Image provisions need an exact runtime profile.");if(!Array.isArray(e.profile.capabilities)||e.profile.capabilities.some(r=>typeof r!="string"))throw new Error("Image provision capabilities are malformed.");for(const[r,n]of Object.entries(e.types))if(!r.startsWith(e.base+"/v1/")&&!new RegExp("^"+e.base.replaceAll(".","\\.")+"/baseline/[a-f0-9]{64}/").test(r)||r.includes("..")||typeof n!="string"||!/^[a-z0-9.+-]+\/[a-z0-9.+-]+$/u.test(n))throw new Error("Image provision media metadata is malformed.");if(e.commands!==void 0&&(!Array.isArray(e.commands)||e.commands.some(r=>!Ur(r)||r.kind!=="command"||r.phase!=="run"||r.backend!=="tab"||typeof r.name!="string"||typeof r.version!="string"||typeof r.abi!="string"||!Array.isArray(r.features))))throw new Error("Image command requests are malformed.");if(e.baselines!==void 0&&(!Array.isArray(e.baselines)||e.baselines.some(r=>!Ur(r)||r.kind!=="runtime"||r.phase!=="run"||r.backend!=="tab"||r.export!=="runtime-baseline")))throw new Error("Image baseline requests are malformed.");const t=Array.isArray(e.baselines)?e.baselines.map(r=>h0(r)):void 0;if(e.unavailable!==void 0&&(!Array.isArray(e.unavailable)||e.unavailable.some(r=>!Ur(r)||typeof r.provider!="string"||!r.provider.trim()||/[\x00-\x1f]/u.test(r.provider)||typeof r.reason!="string"||!r.reason.trim()||!Array.isArray(r.commands)||r.commands.some(n=>typeof n!="string"||!/^[a-z0-9][a-z0-9._-]*$/iu.test(n)))))throw new Error("Image capability refusals are malformed.");for(const r of e.unavailable??[]){if(r.chromium===void 0)continue;const n=r.chromium;if(!Ur(n)||!Array.isArray(n.revisions)||n.revisions.some(i=>typeof i!="string"||!/^\d+$/u.test(i))||!Array.isArray(n.placements)||n.placements.some(i=>!Ur(i)||typeof i.directory!="string"||!/^[a-z0-9_-]+$/iu.test(i.directory)||typeof i.executable!="string"||!/^[a-z0-9._/-]+$/iu.test(i.executable)||i.executable.split("/").includes("..")))throw new Error("Image Chromium refusal placements are malformed.")}return{...e.unavailable?{unavailable:e.unavailable}:{},...t?{baselines:t}:{},...e.commands?{commands:e.commands}:{},base:e.base,digest:e.digest,profile:e.profile,types:e.types}}function f1e(e){const t=e.archive;if(typeof e.name!="string"||typeof e.config!="string"||!Ur(t)||typeof t.url!="string"||typeof t.blobs!="string"||typeof t.integrity!="string")throw new Error("The image manifest's world is malformed.");if(e.outputs!==void 0){if(!Ur(e.outputs))throw new Error("Invalid project output selection.");if(e.outputs.url!==void 0){const n=e.outputs;if(typeof n.url!="string"||!n.url.startsWith(`/substrate/${e.name}.outputs/`)||/[\\?#]|%2e/iu.test(n.url)||n.url.split("/").some(i=>i==="."||i==="..")||!/^sha256:[a-f0-9]{64}$/u.test(String(n.digest))||!/^sha256:[a-f0-9]{64}$/u.test(String(n.inputs))||!/^(?:[a-f0-9]{40}|sha256:[a-f0-9]{64})$/u.test(String(n.sourcePin))||!Number.isSafeInteger(n.bytes)||n.bytes<0)throw new Error("Invalid carried project output descriptor.");n.url,n.digest,n.bytes,n.inputs,n.sourcePin}else{const n=h0(e.outputs.request);if(n.kind!=="runtime"||n.name!=="project-output"||n.backend!=="tab"||n.phase!=="run"||n.export!=="prepared-output"||!/^[a-f0-9]{40}$/u.test(n.version)||!/^sha256:[a-f0-9]{64}$/u.test(n.instance??"")||n.features.length)throw new Error("Project outputs require an exact source/context selection.")}}const r=e.dependencies;if(e.environmentOutputFlag!==void 0&&e.environmentOutputFlag!=="--env-file"&&e.environmentOutputFlag!=="--env-out")throw new Error("The image manifest's World environment output flag is unsupported.");if(e.runtimeVersion!==void 0&&(typeof e.runtimeVersion!="string"||!/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/u.test(e.runtimeVersion)))throw new Error("Image World runtime pin is malformed.");return{name:e.name,...e.runtimeVersion?{runtimeVersion:e.runtimeVersion}:{},...e.environmentOutputFlag?{environmentOutputFlag:e.environmentOutputFlag}:{},config:e.config,archive:{url:t.url,blobs:t.blobs,integrity:t.integrity,entries:Number(t.entries??0),fileBytes:Number(t.fileBytes??0)},...Ur(r)&&typeof r.url=="string"&&typeof r.key=="string"?{dependencies:{url:r.url,key:r.key,packages:Number(r.packages??0),links:Number(r.links??0)}}:{}}}function Ur(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function d1e(e){if(!Ur(e)||typeof e.url!="string"||!/^\/substrate\/[A-Za-z0-9._-]+\.startup\.json$/u.test(e.url)||!Number.isSafeInteger(e.ranges)||e.ranges<0)throw new Error("The image manifest's startup set is malformed.");const t=e.streams;if(t!==void 0&&(!Array.isArray(t)||t.length>8||!t.every(r=>Ur(r)&&typeof r.url=="string"&&/^\/substrate\/[A-Za-z0-9._-]+\.startup\/[a-f0-9]{64}\.bin$/u.test(r.url)&&Number.isSafeInteger(r.bytes)&&r.bytes>=0&&Number.isSafeInteger(r.ranges)&&r.ranges>=0)))throw new Error("The image manifest's startup streams are malformed.");return{url:e.url,ranges:e.ranges,...t?{streams:t.map(r=>({url:r.url,bytes:r.bytes,ranges:r.ranges}))}:{}}}function h1e(e){return{version:1,preparation:e?.location??"unknown",phases:{install:e?.installObserved?["host"]:[],build:e?.location==="host"?["host"]:[],devServer:[],agentTools:[]}}}function Wa(e,t,r){e.phases[t].includes(r)||e.phases[t].push(r)}function p1e(e,t){t?.location==="host"?(e.preparation="host",Wa(e,"build","host"),t.installObserved&&Wa(e,"install","host")):!t&&e.preparation!=="host"&&(e.preparation="unknown")}function m1e(e){return/(?:^|[;&|]\s*|\s)(?:npm|pnpm|yarn|pip3?|uv)\s+(?:install|ci|sync|pip\s+install)(?:\s|$)/u.test(e)}function g1e(e){const t=n=>n.length===0?"not run yet":n.map(i=>i==="browser"?"in this browser":"on a host").join(" and "),r=e.preparation==="none"?"no host prepared the image":e.preparation==="host"?"a host prepared the image":"the image's preparation is unknown";return`Where it ran: install ${t(e.phases.install)}, build ${t(e.phases.build)}, dev server ${t(e.phases.devServer)}, agent tools ${t(e.phases.agentTools)}; ${r}`}function oB(e,t){if(!e.image)throw new Error(`${e.name}: no image request.`);return{kind:"image",...cR(e.image.raw),backend:"tab",phase:"run",abi:t.abi,export:"compose-service",features:[...e.volumes.some(n=>!n.readOnly)?["persistent-data"]:[],...Object.keys(e.environment).map(n=>`environment:${n}`),...[...e.command??[],...e.entrypoint??[]].filter(n=>/^--/u.test(n)).map(n=>`argument:${n.split("=")[0]}`)]}}function y1e(e,t){const r={},n=[];for(const i of e.services){if(i.build||!i.image)continue;const s=oB(i,t.runtime),a=t.rows.filter(d=>d.request.kind===s.kind&&d.request.name===s.name&&d.request.version===s.version&&d.request.backend===s.backend&&d.request.phase===s.phase&&d.request.abi===s.abi&&d.request.export===s.export&&s.features.every(p=>d.request.features.includes(p))),o=a[0];if(a.some(d=>d.selection?.entry.manifest!==o?.selection?.entry.manifest||d.selection?.entry.closure!==o?.selection?.entry.closure))throw new Error(`${i.name}: inconsistent catalog service selections.`);if(!o||o.status!=="resolved"||!o.selection||o.provision?.disposition!=="pack"||o.provision.contract.kind!=="service")throw new Error(`${i.name}: ${o?.reason??"No authenticated exact service provision"}. ${o?.prepare??"Prepare and publish the qualified engine/World closure on a host."}`);const l=o.provision.contract,c=o.provision;if(!s.features.every(d=>c.features.includes(d)))throw new Error(`${i.name}: service feature contract does not cover this request.`);if(![...o.selection.manifests.values()].some(d=>d.integration.kind==="program"&&d.integration.executable===l.program))throw new Error(`${i.name}: selected closure does not export ${l.program}.`);r[i.image.raw]={program:l.program},n.push({service:i.name,image:i.image.raw,contract:l,selection:o.selection})}return{images:r,bindings:n}}async function lB(e,t,r){const n=e.services.filter(i=>!i.build&&i.image).map(i=>oB(i,r));return y1e(e,await t.planProvisions(n,r))}function b1e(e,t,r){const n={};for(const i of e.bindings)n[i.contract.program]=(s,a)=>{const o=e.bindings.find(p=>p.service===s.name);if(!o)throw new Error(`${s.name}: missing exact prepared service binding.`);const l=o.contract;if(l.owner==="world"&&!t)throw new Error(`${s.name}: the selected World-owned engine requires its existing pinned World attachment.`);if(l.owner==="world"&&(!l.worldRuntime||l.worldRuntime!==r))throw new Error(`${s.name}: World runtime must be the selected pin ${l.worldRuntime??"missing"}.`);if(s.entrypoint||s.command)throw new Error(`${s.name}: overridden entrypoint/command requires an explicitly prepared command contract.`);const c=a.ports[0];if(!c)throw new Error(`${s.name}: declare its loopback port explicitly.`);const d=[l.program,...l.argv.map(p=>p==="${PORT}"?String(c):p)].map(w1e).join(" ");return{command:l.owner==="world"?t(d):d,env:Object.fromEntries(l.environment.filter(p=>a.env[p]!==void 0).map(p=>[p,a.env[p]])),ports:[c]}};return n}function w1e(e){return`'${e.replaceAll("'","'\\''")}'`}const v1e=["compose.yaml","compose.yml","docker-compose.yaml","docker-compose.yml"];async function cB(e,t){const r=e.filesystem,n=`${t.root}/${t.source}`,i=HN(await r.readFile(n,"utf8"),{environment:t.env}),s={};for(const c of i.services){if(!c.build)continue;const u=c.build.context.replace(/^\.\/?/u,"").replace(/\/$/u,""),d=`${t.root}${u?`/${u}`:""}/${c.build.dockerfile}`;if(!r.existsSync(d))throw new Error(`Service ${c.name} builds from ${d}, which is not in the project.`);s[c.name]=Kh(await r.readFile(d,"utf8"),{buildArgs:c.build.args})}const a=t.services?await lB(i,t.services.catalog,t.services.profile):{images:{},bindings:[]};for(const c of a.bindings)await t.services.materialize(c.selection);const o=I6(e,{images:a.images}),l=sH(i,o,{resolveBuild:c=>s[c.name]});if(l.verdict!=="native"){const c=l.blocking.map(u=>`${u.service}: ${u.reason}`).join("; ");throw new Error(`Only what runs in the tab can run here, and this stack has more: ${c}`)}return vH(e,l,{lanes:o,context:t.root,stagesRoot:t.stagesRoot,builds:s,programs:b1e(a,t.services?.attachWorld,t.services?.worldRuntime),environment:t.env,portTimeoutMs:t.portTimeoutMs??18e4,...t.forward.signal?{signal:t.forward.signal}:{},onStdout:(c,u)=>t.forward.onStdout?.(`${c} | ${u}`),onStderr:(c,u)=>t.forward.onStderr?.(`${c} | ${u}`)})}const x1e="browser-substrate.playground",S1e=[".devcontainer/devcontainer.json",".devcontainer.json"],E1e=["dev","development","devel","builder-dev"],k1e=["@playwright/test","playwright","playwright-core","puppeteer","puppeteer-core"];class el extends Error{}async function A1e(e,t={}){const r=await C1e(e,t);if(!r||!e.exists("package.json"))return r;try{const n=JSON.parse(await e.read("package.json")??"{}"),i=new Set([...Object.keys(n.dependencies??{}),...Object.keys(n.devDependencies??{})]);if(k1e.some(s=>i.has(s)))return{...r,browserTests:!0}}catch{}return r}async function C1e(e,t){if(t.serve){const o=await e.read("package.json"),l=o!==void 0?await F$(o,e,{lenient:!0,served:!0}):{kind:"manifests",source:"package.json",ports:[],playground:!1},{devScript:c,directory:u,...d}=l;return{...d,source:"command line",dev:t.serve,...t.directory?{directory:t.directory}:{}}}const r=await e.read("Dockerfile"),n=await L1e(e);for(const o of v1e){const l=await e.read(o);if(l===void 0)continue;const c=HN(l,{}),u=t.serviceImages?await t.serviceImages(c):{},d=c.services.filter(g=>g.build===void 0&&g.image!==void 0&&!u[g.image.raw]&&!u[g.image.repository]);if(d.length>0&&r!==void 0)break;if(d.length>0){const g=d.map(b=>`${b.name} (${b.image.repository})`).join(", ");throw new el(`${o} needs a qualified catalog service provision: ${g}. Prepare and publish its real engine/driver-protocol closure on a host. Missing initialization, extensions or storage contracts are refused; a catalog match never grants a World lifecycle.`)}const p=[...new Set(c.services.flatMap(g=>g.ports.map(b=>b.host??b.container)))],m=c.services.flatMap(g=>g.develop?.watch??[]);return{kind:"compose",source:o,ports:p,playground:!1,...m.length>0?{watch:m}:{}}}if(n?.dockerfile){const o=await e.read(n.dockerfile);if(o===void 0)throw new el(`${n.source} names ${n.dockerfile}, which is not in the project.`);return{...U$(Kh(o)),source:n.dockerfile,...n.target?{target:n.target}:{},context:n.context??(n.dockerfile.includes("/")?n.dockerfile.slice(0,n.dockerfile.lastIndexOf("/")):"")}}if(r!==void 0){const o=Kh(r),l=U$(o),c=o.stages.map(u=>u.name).find(u=>E1e.includes(u));return c?{...l,target:c}:l}const i=await e.read("package.json");if(i!==void 0){const o=await F$(i,e),l=await l6(e);if(l===void 0)return o;const{devScript:c,directory:u,...d}=o;return{...d,source:"Procfile",dev:l}}const s=await $1e(e);if(s)return s;const a=await l6(e);if(a)return{kind:"manifests",source:"Procfile",dev:a,ports:[],playground:!1}}async function l6(e){const t=await e.read("Procfile");if(t!==void 0)for(const r of t.split(`
1915
1915
  `)){const n=/^\s*web\s*:\s*(.+?)\s*$/u.exec(r);if(n)return n[1]}}async function T1e(e){const t=await e.read("manage.py");if(t===void 0)return;const r=/DJANGO_SETTINGS_MODULE["']\s*,\s*["']([\w.]+)["']/u.exec(t)?.[1],n=r?.includes(".")?r.slice(0,r.lastIndexOf(".")):void 0,i=n?await e.read(`${n.replace(/\./gu,"/")}/wsgi.py`):void 0;if(n&&i!==void 0){const s=/^application\s*=/mu.test(i)?"application":/^app\s*=/mu.test(i)?"app":"application";return`gunicorn ${n}.wsgi:${s}`}return"python manage.py runserver --noreload --nothreading 0.0.0.0:8000"}async function $1e(e){const t=e.exists("requirements.txt"),r=e.exists("pyproject.toml");if(!t&&!r)return;const n=t?"pip install -r requirements.txt":"pip install .",i=await l6(e)??await T1e(e);if(!i)throw new el(`${t?"requirements.txt":"pyproject.toml"} says how to install, not how to serve; add a Procfile with a \`web:\` line, or a Dockerfile with a CMD.`);return{kind:"manifests",source:t?"requirements.txt":"pyproject.toml",install:n,dev:i,ports:[],playground:!1}}function U$(e){const t=e.stages.at(-1),r=[];let n=!1;for(const i of t?.instructions??[]){if(i.kind==="expose")for(const s of i.ports)r.includes(s.port)||r.push(s.port);i.kind==="label"&&P1e(i.value,x1e)==="true"&&(n=!0)}return{kind:"dockerfile",source:"Dockerfile",ports:r,playground:n}}async function F$(e,t,r={}){let n;try{n=JSON.parse(e)}catch{throw new el("package.json is not valid JSON.")}const i=n.scripts??{},s=t.exists("pnpm-workspace.yaml")&&_1e(await t.read("pnpm-workspace.yaml")??"").some(d=>!/^\.\/?$/u.test(d)),a=s||t.exists("pnpm-lock.yaml")?"pnpm":t.exists("yarn.lock")?"yarn":t.exists("bun.lock")||t.exists("bun.lockb")?"bun":"npm",o=i.dev?`${a} run dev`:i.start?`${a} start`:void 0;if(!o&&!r.lenient)throw new el("package.json has neither a dev nor a start script; add one, or a Dockerfile with a CMD.");const l=i.dev??i.start,c=s||t.exists("pnpm-lock.yaml")?"pnpm install --frozen-lockfile":t.exists("yarn.lock")?"yarn install --frozen-lockfile":t.exists("bun.lock")||t.exists("bun.lockb")?"bun install --frozen-lockfile":t.exists("package-lock.json")?"npm ci":"npm install",u=s&&l&&!r.served?await I1e(l,t):void 0;return o?{kind:"manifests",source:"package.json",install:u?`${c} --filter ${u.filter}... --filter .`:c,...s&&i.build&&!u?{build:"pnpm run build"}:{},dev:u?.dev??o,...u?{devScript:u.devScript,directory:u.directory}:l?{devScript:l}:{},ports:[],playground:!1}:{kind:"manifests",source:"package.json",install:c,ports:[],playground:!1}}const N1e=new Set(["node","npm","npx","pnpm","vite","next"]),R1e=[["next","dev"],["vite"]],O1e=new Set(["&&","||",";","|"]);function _1e(e){const t=e.split(`
1916
1916
  `),r=t.findIndex(a=>/^packages:/u.test(a));if(r<0)return[];const n=/^packages:\s*\[(.*)\]\s*$/u.exec(t[r]),i=a=>a.trim().replace(/^['"]|['"]$/gu,"");if(n)return n[1].split(",").map(i).filter(Boolean);const s=[];for(const a of t.slice(r+1)){if(/^\s*#/u.test(a)||a.trim()==="")continue;const o=/^\s+-\s*(.+)$/u.exec(a);if(!o)break;s.push(i(o[1].replace(/\s+#.*$/u,"")))}return s}async function I1e(e,t){let r;try{r=c6(e)}catch{return}const n=r[0];if(!n||N1e.has(n))return;const i=await t.read("pnpm-lock.yaml"),s=i===void 0?[]:M1e(i).filter(l=>l!=="."&&t.exists(`${l}/package.json`)),a=[];for(const l of s){const c=await t.read(`${l}/package.json`);if(c===void 0)continue;let u;try{u=JSON.parse(c)}catch{continue}const d=u.scripts?.dev??u.scripts?.start;if(!d)continue;const p=D1e(d);p&&a.push({directory:l,dev:p,devScript:d,filter:typeof u.name=="string"&&u.name?u.name:`{${l}}`})}if(a.length===1)return a[0];const o=s.length===0?"pnpm-lock.yaml names no workspace packages":`none of ${s.join(", ")} has a dev script that runs one`;throw a.length===0?new el(`package.json's dev script runs \`${n}\`, which the tab has no program for, and ${o} (next dev, vite).`):new el(`package.json's dev script runs \`${n}\`, which the tab has no program for, and ${a.map(l=>l.directory).join(", ")} each run a dev server; the tab serves one workspace package.`)}function M1e(e){const t=[];let r=!1;for(const n of e.split(`
1917
1917
  `)){if(/^importers:\s*$/u.test(n)){r=!0;continue}if(r&&/^\S/u.test(n))break;const i=r?/^ (?:'([^']+)'|"([^"]+)"|([^\s'":][^:]*)):\s*$/u.exec(n):null;i&&t.push(i[1]??i[2]??i[3])}return t}function D1e(e){let t;try{t=c6(e)}catch{return}const r=n=>R1e.findIndex(i=>i.every((s,a)=>n[a]===s));for(let n=0;n<t.length;n+=1){if(r(t.slice(n))>=0){const i=t.findIndex((s,a)=>a>n&&O1e.has(s));return B$(t.slice(n,i<0?void 0:i))}if(/\s/u.test(t[n])){let i;try{i=c6(t[n])}catch{continue}if(r(i)>=0)return B$(i)}}}function c6(e){const t=[];let r="",n="",i=!1;const s=()=>{r&&(t.push(r),r="")},a=[...e.trim()];for(let o=0;o<a.length;o+=1){const l=a[o];if(i){r+=l,i=!1;continue}if(l==="\\"&&n!=="'"){i=!0;continue}if(n){l===n?n="":r+=l;continue}if(l==="'"||l==='"'){n=l;continue}if(/\s/u.test(l)){s();continue}if(l==="&"||l==="|"||l===";"){s();const c=`${l}${a[o+1]??""}`;c==="&&"||c==="||"?(t.push(c),o+=1):t.push(l);continue}r+=l}if(i||n)throw new Error("Unterminated command quoting.");return s(),t}function B$(e){return e.map(t=>/[\s"']/u.test(t)?JSON.stringify(t):t).join(" ")}async function L1e(e){for(const t of S1e){const r=await e.read(t);if(r===void 0)continue;let n;try{n=JSON.parse(r.replace(/\/\*[\s\S]*?\*\//gu,"").replace(/(^|\s)\/\/.*$/gmu,"$1").replace(/,(\s*[}\]])/gu,"$1"))}catch{throw new el(`${t} is not valid JSON with comments.`)}const i=t.includes("/")?t.slice(0,t.lastIndexOf("/")):"",s=n.build?.dockerfile??n.dockerFile,a=l=>{const c=i?`${i}/${l}`:l,u=[];for(const d of c.split("/"))d===""||d==="."||(d===".."?u.pop():u.push(d));return u.join("/")},o=n.build?.context??n.context;return{source:t,...s?{dockerfile:a(s)}:{},...n.build?.target?{target:n.build.target}:{},...o?{context:a(o)}:{}}}}function P1e(e,t){const r=/([^\s=]+)=("([^"]*)"|'([^']*)'|(\S*))/gu;for(const n of e.matchAll(r))if(n[1]===t)return n[3]??n[4]??n[5]??""}const U1e="browser-substrate",z$=`usage: browser-substrate dev
@@ -2009,7 +2009,7 @@ setup stopped: ${m6(Ce)}
2009
2009
  `})})};wn===void 0?ho(!1):(Kn=jge(wn),sl(Kn));const _n=async()=>{if(yt)return;if(fn){const Ae=fn;fn=void 0,It=void 0,await Ae.stop().catch(()=>{})}else It&&Yn.add(It),It?.kill(),await It?.result.catch(()=>{}),It=void 0;if(yt)return;for(const Ae of gt.lifecycle.processes)gt.lifecycle.forgetProcess(Ae.id);const re=`${Fl}/${i}`;if(B.existsSync(re)&&zs(B,re),vr=void 0,Xn=Ft,wn=void 0,w("The image changed; running the setup again"),await fo(!0),!yt){if(wn!==void 0){u({stream:"stderr",text:`setup failed: ${wn instanceof Error?wn.message:String(wn)}
2010
2010
  `});return}B.existsSync(zo)&&B.unlinkSync(zo),await gt.flush(),ho(!0)}};if(o.dev){const re=async()=>{if(yt)return!1;const Ae=new Map(Qe);try{const Ce=await eN(i,s);p1e(Ue,Ce.preparation),Ce.dependencies?o.dependencies=Ce.dependencies:delete o.dependencies,B.writeFileSync(zo,"pending");const Le=await Qge(B,Ce.archive,Qe),et=Le.paths.map(Fe=>({...Fe,path:`${Ft}/${Fe.path}`}));if(wn===void 0){let Fe=!1;if(o.setup.kind==="dockerfile"&&Le.paths.length>0&&(!vr||Le.paths.some(({path:dn})=>dn===o.setup.source)||(await pH(Z,vr,lo(),et)).rebuild)&&(await Ia(),Fe=!0),(o.setup.watch??[]).some(xr=>xr.action!=="sync"&&Le.paths.some(({path:dn})=>Jge(dn,xr.path)))&&fi&&(w("A watched path changed; the deployment file asks for a rebuild"),await fi()),!Fe&&Le.paths.length>0&&o.setup.kind!=="compose"){const xr=await Tt(),dn=Yt=>xr.some(Gt=>Yt===Gt.path||(Gt.recursive?Yt.startsWith(`${Gt.path}/`):Yt.slice(0,Yt.lastIndexOf("/"))===Gt.path));et.every(({path:Yt})=>dn(Yt))?w(`Synced ${Le.paths.length} changed file${Le.paths.length===1?"":"s"} into the running program's watch`):await is()}}return Le.integrity&&(J=rN(B,Le.integrity,Qe,J)),B.unlinkSync(zo),await gt.flush(),Le.written+Le.removed>0?w(`Synced ${Le.written} changed, ${Le.removed} removed`):Le.integrity&&Le.integrity!==Rt&&w("Synced the image; no served file differs"),Le.integrity&&(Rt=Le.integrity),Le.paths.length>0}catch(Ce){Qe.clear();for(const[Le,et]of Ae)Qe.set(Le,et);return u({stream:"stderr",text:`sync failed: ${Ce instanceof Error?Ce.message:String(Ce)}
2011
2011
  `}),!1}};$t=oge(o.dev.eventsUrl,{apply:re,failed:()=>wn!==void 0,rerun:_n})}let po,vu,oa,la;const xu={manifest:o,execution:Ue,runtime:Z,workspace:gt,toolbelt:Se,relay:S,packs:rt,root:Ft,get cwd(){return Xn},isolated:E,sandboxOrigin:A,get process(){return It},get world(){return nl},resumed:xi,get ready(){return Kn},get previewUrl(){const re=P??ar()[0];return re===void 0||E?void 0:Z.portUrl(re)},ports:()=>Z.ports(),storage:async()=>H.workspaceStore?.stats(),attachPreview(re,Ae,Ce){E||spe(re,Z,()=>P);const Le=()=>({bridge:n6(j.serverBridge,Me),hostFetchServices:fe,policy:Z.policy,webSocketRegistry:Z.webSockets,...Z.host.webSocketConnector?{webSocketConnector:Z.host.webSocketConnector}:{}}),et=()=>{if(vu||oa)return;const He=j.listenNet?.bind(j);if(!Z.baselines.some(ir=>ir.provider.name==="chromium")||!E||!A||!He){oa=Rpe({runtime:Z,home:xh,roots:[Ft],...o.provisions?.unavailable?.find(ir=>ir.provider==="chromium")?{unavailable:o.provisions.unavailable.find(ir=>ir.provider==="chromium")}:{},reason:Z.baselines.some(ir=>ir.provider.name==="chromium")?"this page runs the project in-page, where the tab has no Chromium to launch; open it with ?isolated=1 to run Playwright against the tab's Chromium.":"Chromium provider closure is unpublished; prepare and publish it through publish-demand-catalog.mjs on a machine."});return}const Nt=document.createElement("div");Nt.style.cssText="position:fixed;left:0;top:0;width:0;height:0;overflow:visible;opacity:0.01;pointer-events:none;z-index:2147483647",Nt.setAttribute("aria-hidden","true"),document.body.append(Nt),vu=Npe({runtime:Z,listen:(ir,an)=>He(ir,st=>an(LT(st))),browser:{mount:Nt,sandboxOrigin:A,bridge:Le()},home:xh,roots:[Ft],discoveryTable:{port:FF,ports:j.serverBridge}})},Fe=He=>{if(P=He,!E||!A){j.serverBridge.setPrimaryPort?.(He);const ir=new URL(Ce??"/",location.origin);ir.searchParams.set(mg,location.host),(async()=>{const an=Date.now()+15e3;for(;Date.now()<an&&P===He;)try{await j.serverBridge.handleRequest(He,"GET","/",{accept:"text/html",host:location.host});break}catch{await new Promise(st=>setTimeout(st,250))}P===He&&(re.addEventListener("load",de,{once:!0}),re.src=ir.href)})();return}po?po.setPort(He):po=new RN({...Le(),preview:re,origin:A,nonce:Ge,port:He});const Nt=new URL("/sandbox.html",A);Nt.searchParams.set("parentOrigin",location.origin),Nt.searchParams.set("nonce",Ge),Nt.searchParams.set("port",String(He)),re.src=Nt.href},Ge=crypto.randomUUID();et();const xr=()=>$r.find(He=>ar().includes(He)),dn=async He=>{try{const Nt=await j.serverBridge.handleRequest(He,"GET","/",{accept:"text/html"}),ir=Nt.headers,an=String(ir["content-type"]??ir["Content-Type"]??"");return Nt.statusCode<400&&an.includes("text/html")}catch{return!1}};let Yt=!1,Gt=!1;const sn=()=>{if(!(Ae!==void 0||xr()!==void 0)){if(Yt){Gt=!0;return}Yt=!0,(async()=>{try{for(const He of ar()){if(He===P&&await dn(He))return;if(He!==P&&await dn(He)){Fe(He);return}}}finally{Yt=!1,Gt&&(Gt=!1,sn())}})()}},Ts=Ae??P??xr()??ar()[0];Ts!==void 0&&Fe(Ts),sn(),ao=He=>{Ae===void 0&&He!==P&&ar().includes(He)&&Fe(He)},Nn.add((He,Nt)=>{if(Nt==="close"&&He===P){P=void 0;return}if(!(Nt!=="open"||nr.has(He))){if(P===void 0||!ar().includes(P)){Fe(xr()??He),sn();return}if(Ae===void 0&&$r.includes(He)&&!$r.includes(P)){Fe(He);return}sn()}})},async connectPreviewProtocol(re="screen"){if(!po)throw new Error("Screen sharing needs an attached isolated preview.");return po.connectProtocol(re)},onPort(re){return Nn.add(re),()=>Nn.delete(re)},registerHostFetchService(re){if(yt)throw new Error("Project is disposed.");const Ae=Z.policy.limits.maxVirtualRequestBytes;if(re.maxRequestBytes!==void 0&&re.maxRequestBytes>Ae)throw new Error(`Host Fetch-service upload limit exceeds runtime policy limit ${Ae}.`);const Ce=re.maxRequestBytes??Math.min(Ae,Jj),Le=nr.has(re.port);nr.add(re.port);const et=()=>{Le||nr.delete(re.port)};let Fe;try{Fe=fe.register({...re,maxRequestBytes:Ce})}catch(Gt){throw et(),Gt}re.lifetime?.addEventListener("abort",et,{once:!0});const Ge={...Fe,close:async()=>{try{await Fe.close()}finally{et()}}};if(E)return Ge;const xr=j.listenNet,dn=vg(j.serverBridge,re.port)?.fetch;if(!xr||!dn)return Ge;let Yt;try{Yt=xr.call(j,re.port,Gt=>dpe(Gt,re.port,dn,Ce))}catch{return Ge}return re.lifetime?.addEventListener("abort",()=>{Yt?.(),Yt=void 0},{once:!0}),{port:Ge.port,ready:Ge.ready,close:async()=>{Yt?.(),Yt=void 0,await Ge.close()}}},async shutdown(re=()=>{}){await xu.ready.catch(()=>{}),await F,Ut.abort(new Error("The project is shutting down.")),await $t?.close(),await $t?.idle,re("Stopping the application"),await fn?.stop(),It?.kill(),await It?.result.catch(()=>{}),nn&&(re("Stopping the World"),await nn(re)),re("Closing runtime and storage workers"),await xu.dispose()},dispose(){return la||(yt=!0,la=(async()=>{const re=[],Ae=async Ce=>{try{await Ce()}catch(Le){re.push(Le)}};if(Ut.abort(new Error("The project was closed.")),await Ae(()=>$t?.close()),await Ae(async()=>{await $t?.idle}),await Ae(async()=>{await fn?.stop()}),await Ae(bu),await Ae(Ye),await Ae(()=>Se.dispose()),await Ae(()=>fe.dispose()),await Ae(async()=>{await De?.dispose()}),await Ae(async()=>{await vu?.dispose()}),await Ae(()=>{oa?.()}),await Ae(()=>po?.dispose()),await Ae(()=>Z.dispose()),await Ae(async()=>{await W?.()}),re.length===1)throw re[0];if(re.length>1)throw new AggregateError(re,"Project disposal failed.")})(),la)}};return globalThis.addEventListener("pagehide",()=>{xu.dispose()},{once:!0}),xu}function m2(e,t,r,n,i){return new Promise((s,a)=>{const o=()=>t.length>0?t.every(p=>e().includes(p)):e().length>0;if(o()){s({ports:[...e()]});return}const l=setTimeout(()=>{d(),a(new Error(`No port opened within ${J$/1e3} s.`))},J$);let c;const u=()=>{if(o()){d(),s({ports:[...e()]});return}e().length>0&&c===void 0&&(c=setTimeout(()=>{e().length>0&&(d(),s({ports:[...e()]}))},3e3))},d=()=>{clearTimeout(l),c!==void 0&&clearTimeout(c),n.delete(u)};n.add(u),e().length>0&&u(),r?.result.then(p=>{o()||i.has(r)||(d(),a(new Error(age(p.exitCode,p.stderr))))}).catch(p=>{d(),a(p)})})}const qge=["/sandbox.html","/node-host.html","/python-host.html"];function Gge(e){if(e)return new URL(e).origin;const{protocol:t,hostname:r,port:n}=location,i=n?`:${n}`:"";return r==="127.0.0.1"?`${t}//localhost${i}`:r==="localhost"?`${t}//127.0.0.1${i}`:`${t}//sandbox.${r}${i}`}const Vge="volter-browser-image-index";async function g6(e,t){const r=await vs(e,{cache:"no-store"});if(!r.ok)throw new Error(`The image index ${e} answered ${r.status}.`);const n=await r.json();if(n.kind!==Vge||n.version!==1||!Array.isArray(n.entries)||typeof n.integrity!="string")throw new Error(`The image index ${e} has an unsupported shape.`);const i=n.entries;if(n.bundles!==void 0&&(!n.bundles||typeof n.bundles!="object"||Array.isArray(n.bundles)))throw new Error(`The image index ${e} has an invalid bundle table.`);for(const a of i){if(typeof a.path!="string"||a.type!=="file"&&a.type!=="directory"||a.type==="file"&&typeof a.integrity!="string")throw new Error(`The image index ${e} names an entry it does not describe.`);const o=a.integrity?n.bundles?.[a.integrity]:void 0;if(o!==void 0&&(a.type!=="file"||!Array.isArray(o)||o.length!==2||typeof o[0]!="string"||!/^sha256-[A-Za-z0-9+/]{43}=$/u.test(o[0])||!Number.isSafeInteger(o[1])||o[1]<0||!Number.isSafeInteger(a.bytes)||a.bytes<0||a.bytes>128*1024||o[1]+a.bytes>2*1024*1024))throw new Error(`The image index ${e} names an invalid source bundle extent.`)}const s=await y6(new TextEncoder().encode(JSON.stringify({kind:n.kind,version:n.version,entries:n.entries})));if(s!==n.integrity)throw new Error(`The image index ${e} failed its integrity check.`);if(t!==void 0&&s!==t)throw new Error(`Image integrity mismatch: expected ${t}, the index is ${s}.`);return{integrity:s,entries:i.map(a=>{const o=a.integrity?n.bundles?.[a.integrity]:void 0,{bundle:l,...c}=a;return o?{...c,bundle:o}:c})}}function bg(e,t){const r=new Map;for(const s of t??[])s.integrity&&s.bundle&&r.set(s.integrity,{bundle:s.bundle[0],offset:s.bundle[1],length:s.bytes});const n=new Map,i=async(s,a=!1)=>{const o=new URL(`${e}${Kge(s)}`,location.href).href,l=await vs(o,{cache:"no-store"});if(!l.ok)throw new Error(`The image file ${o} answered ${l.status}.`);const c=new Uint8Array(await l.arrayBuffer());if(a&&c.byteLength>2*1024*1024)throw new Error(`The image source bundle ${o} exceeds its bound.`);if(await y6(c)!==s)throw new Error(`The image file ${o} is not the bytes its index names; it changed on disk while it was fetched, and the next sync takes it.`);return c};return async s=>{const a=r.get(s);if(!a)return i(s);let o=n.get(a.bundle);o?(n.delete(a.bundle),n.set(a.bundle,o)):(o=i(a.bundle,!0),n.set(a.bundle,o),n.size>8&&n.delete(n.keys().next().value));const l=await o;if(a.offset+a.length>l.byteLength)throw new Error("An image file extends beyond its source bundle.");const c=l.subarray(a.offset,a.offset+a.length);if(await y6(c)!==s)throw new Error("An image source bundle does not hold the file its index names.");return c}}function Zge(e){let t=0;return(r,n,i)=>{const s=Date.now();s-t<300&&r<n||(t=s,e(`Applying the image: ${r} of ${n} files, ${(i/1048576).toFixed(1)} MiB`))}}async function y6(e){const t=new Uint8Array(await crypto.subtle.digest("SHA-256",e.slice().buffer));let r="";for(const n of t)r+=String.fromCharCode(n);return`sha256-${btoa(r)}`}function Yge(e){return["REFUSED: this project's dev server is Next's (`"+e+"`), and the image carries no warmed compile for it.","","Next's dev server compiles the application on its first requests: every route and the thousands of modules","they import. The tab never compiles an application; the machine that prepares the image does, and the tab","runs Next's own dev server over that compile, recompiling only the file you edit (ADR-0018). Compiling here","instead takes minutes and gigabytes of this tab's memory, and that is what browser-substrate exists to avoid.","","browser-substrate does not prepare Next's warmed compile yet (ROADMAP W30), so a Next application cannot","run in the tab until it does. The dependency link before this point completed; the World was not started."].join(`
2012
- `)}const Xge=5e3;function tN(e,t,r){if(r.length===0)return`Linked ${e} of ${t}; no package is being made, so the link waits on the tree itself`;const n=r.slice(0,8).join(", ");return`Linked ${e} of ${t}; waiting on ${r.length}: ${n}${r.length>8?", …":""}`}function Kge(e){const t=atob(e.slice(7));let r="";for(let n=0;n<t.length;n+=1)r+=t.charCodeAt(n).toString(16).padStart(2,"0");return r}async function Qge(e,t,r){const n=await g6(t.url);return{...await h6(e,Ft,n.entries,r,bg(t.blobs)),integrity:n.integrity}}function Jge(e,t){const r=t.replace(/^\.\/?/u,"").replace(/\/$/u,"");return r===""||r==="."?!0:e===r||e.startsWith(`${r}/`)}async function e0e(e){try{if(!e.existsSync(Yh))return;const t=JSON.parse(await e.readFile(Yh,"utf8"));if(typeof t.integrity!="string")return;const r=typeof t.files=="object"&&t.files!==null?t.files:{},n=typeof t.since=="string"?t.since:typeof t.appliedAt=="string"?t.appliedAt:void 0;return{integrity:t.integrity,files:r,...n?{since:n}:{}}}catch{return}}async function t0e(e,t){if(!e.existsSync(Bc))return;let r;try{r=JSON.parse(await e.readFile(Bc,"utf8"))}catch{throw new Error("The workspace live-pack selection record is not valid JSON.")}if(!r||typeof r!="object"||Array.isArray(r))throw new Error("The workspace live-pack selection record has an unsupported shape.");const n=r,i=s=>typeof s=="string"&&/^sha256:[a-f0-9]{64}$/u.test(s);if(n.kind!=="browser-substrate.live-pack-selection"||n.version!==1||n.environment!==t||typeof n.name!="string"||n.name.length===0||typeof n.buildKey!="string"||n.buildKey.length===0||!i(n.manifest)||!i(n.closure))throw new Error(`The workspace live-pack selection record does not describe environment ${t}.`);return{name:n.name,buildKey:n.buildKey,manifest:n.manifest,closure:n.closure}}function r0e(e,t,r){if(!r){e.existsSync(Bc)&&e.unlinkSync(Bc);return}const n=Bc.slice(0,Bc.lastIndexOf("/"));e.existsSync(n)||e.mkdirSync(n,{recursive:!0});const i={kind:"browser-substrate.live-pack-selection",version:1,environment:t,...r};e.writeFileSync(Bc,JSON.stringify(i,null,2))}function rN(e,t,r,n){const i=Yh.slice(0,Yh.lastIndexOf("/"));e.existsSync(i)||e.mkdirSync(i,{recursive:!0});const s=new Date().toISOString();return e.writeFileSync(Yh,JSON.stringify({integrity:t,files:Object.fromEntries(r),appliedAt:s,since:n??s},null,2)),n??s}function n0e(e){e.existsSync(Fl)&&(zs(e,Fl),e.rmdirSync(Fl))}async function i0e(e,t,r){if(typeof caches>"u")return;const i=await(await r(e,{cache:"no-cache"})).text(),s=new URL(`/__browser-substrate-restored/${await nN(new TextEncoder().encode(i))}`,location.origin).href,a=await caches.open(pB);if(await a.match(s))return;const o=NF(JSON.parse(i)).filter(u=>s0e(u,t));o.sort((u,d)=>d.bytes-u.bytes);let l=0;const c=async()=>{for(;l<o.length;){const u=o[l++],d=await caches.open(u.cache),p=new URL(u.url,location.origin).href;if(await d.match(p))continue;const m=await r(new URL(u.file,location.href).href);if(!m.ok||!m.body)continue;const g=await new Response(m.body.pipeThrough(new DecompressionStream("gzip"))).arrayBuffer();g.byteLength!==u.bytes||await nN(new Uint8Array(g))!==u.sha256||await d.put(p,new Response(g,{status:u.status,headers:u.headers}))}};await Promise.all([c(),c(),c()]),await a.put(s,new Response(""));for(const u of o){const d=u.headers.find(([m])=>m.toLowerCase()==="content-type")?.[1]??"";if(!/^application\/wasm\b/iu.test(d))continue;const p=await(await caches.open(u.cache)).match(new URL(u.url,location.origin).href);p&&await WebAssembly.compileStreaming(p).catch(()=>{})}}const pB="browser-substrate-restored-caches";function s0e(e,t){if(e.cache.startsWith("browser-substrate-offline")||e.cache===pB)return!1;if(e.cache.startsWith("tabnode-http")){if(!e.url.startsWith(`/__tabnode_http_cache__/${encodeURIComponent(t)}/`))return!1;const r=s=>e.headers.find(([a])=>a.toLowerCase()===s)?.[1],n=Number(r("x-tabnode-stored-at")),i=Number(/(?:^|,)\s*max-age=(\d+)/iu.exec(r("cache-control")??"")?.[1]??0);if(!Number.isFinite(n)||Date.now()-n>=i*1e3)return!1}return!0}async function nN(e){return[...new Uint8Array(await crypto.subtle.digest("SHA-256",e))].map(t=>t.toString(16).padStart(2,"0")).join("")}function g2(){return Reflect.get(globalThis,Symbol.for("browser-substrate.dry-run"))===!0}async function a0e(e){const t=e.compilers,r=e.provisions;if(!t||!r||t.catalog!==r.digest||t.abi!==r.profile.abi)throw new Error("This image lacks exact catalog compiler assets; prepare and publish them through the demand pipeline, then regenerate the image.");const n=new URL(r.base,location.href),i=new Tg({endpoints:[{baseUrl:n.href}],trustedOrigins:[n.origin],pinnedCatalog:r.digest,fetch:vs,allowInsecureLocalhost:!0}),s=await i.planProvisions(t.bindings.map(c=>c.request),r.profile);if(Ti(Zq(s,e.name))!==Ti(t))throw new Error("Compiler projection differs from its authenticated exact catalog selection.");const a=new Set(t.bindings.filter(c=>c.request.kind==="runtime").flatMap(c=>[...Object.keys(t.files).filter(u=>u.startsWith(`/substrate/${e.name}.compilers/${c.manifest.slice(7)}/`)),...Object.keys(c.contract.aliases)]));for(const[c,u]of Object.entries(t.files)){if(!a.has(c))continue;const d=await vs(new URL(c,location.href));if(!d.ok)throw new Error(`Compiler file unavailable: ${c}`);const p=new Uint8Array(await d.arrayBuffer());if(p.byteLength!==u.bytes||await Xo(p)!==u.digest)throw new Error(`Compiler file corrupt: ${c}`)}const o={},l={};for(const c of t.bindings)if(c.request.kind==="runtime")for(const[u,d]of Object.entries(c.assets)){if(o[u])throw new Error(`Duplicate runtime compiler role: ${u}`);o[u]=d}else{if(!c.request.instance||!c.assets.rolldownModule)throw new Error("Compiler binding lacks its exact parent instance/factory.");l[`${Ft}/${c.request.instance}`]={url:c.assets.rolldownModule,version:c.contract.version}}for(const c of["esbuildModule","esbuildWasm","rollupModule","typeStripper"])if(!o[c])throw new Error(`Runtime compiler role ${c} is unpublished.`);return{catalog:i,assets:o,instances:l}}async function o0e(e,t){if(!e.dependencies&&!e.outputs)return;if(!e.outputs||!e.provisions)throw new Error("This image lacks published project outputs; use the demand pipeline's project-output handler on a machine.");const r=await t.planProvisions([e.outputs.request],e.provisions.profile),n=r.rows[0];if(n?.status!=="resolved"||n.provision?.disposition!=="pack"||n.provision.contract.kind!=="project-output"||!n.selection)throw new Error(n?.reason??"Exact project output context is unpublished.");const i=n.provision.contract,s=[...n.selection.manifests.values()].flatMap(p=>p.artifacts).find(p=>p.digest===i.document);if(!s||s.parts||i.inputs!==e.outputs.request.instance||i.sourcePin!==e.outputs.request.version)throw new Error("Project document is not bound by its selected closure.");const a=new URL(e.provisions.base+U1("artifacts",i.document),location.href);if(a.origin!==location.origin)throw new Error("Project document must be carried by the image origin.");const o=await vs(a),l=new Uint8Array(await o.arrayBuffer());if(!o.ok||l.byteLength!==s.bytes||await Xo(l)!==i.document)throw new Error("Project document missing/corrupt.");const c=s1e(JSON.parse(new TextDecoder().decode(l))),u=await Xo(new TextEncoder().encode(Ti(c.inputs)));if(u!==i.inputs||c.inputs.sourcePin!==i.sourcePin||c.inputs.image!==e.name||c.inputs.abi!==e.provisions.profile.abi||c.inputs.source!==e.archive.integrity||c.inputs.world!==(e.world?.archive.integrity??"none")||c.plan.key!==e.dependencies?.key)throw new Error("Prepared outputs differ from the image's source/World/dependency context.");for(const p of c.outputs)if(p.inputs!==u||!n.selection.closure.preparedOutputs.some(m=>Ti(m)===Ti(p)))throw new Error("Prepared output lock binding changed.");if(!e.packs||c.packs.packs.length!==e.packs.count)throw new Error("Prepared browser outputs are missing.");const d=r0(await(await vs(e.dependencies.url,{cache:"no-store"})).json());if(Ti(d)!==Ti(c.plan))throw new Error("Prepared dependency document was substituted.");return c}function mB(e){const t=e.base.replace(/\/$/u,""),r=e.headers??{},n=e.bufferBytes??256*1024,i=e.socket??(g=>new WebSocket(g.replace(/^http/u,"ws")));let s={available:!0,canOpenLocal:!1,error:null,sessions:[],attachment:null};const a=new Set,o=g=>{s={...s,...g};for(const b of a)b()},l=new Map;let c=0;const u=(g,b,w)=>{fetch(`${t}/exec/${g}/resize?h=${w}&w=${b}`,{method:"POST",headers:r}).catch(()=>{})},d=g=>o({attachment:{id:`${g}:${Date.now()}`,baseUrl:t,mode:"control",sessionId:g}}),p=(g,b,w)=>{const S=g.sessionId??g.id,x=l.get(S);return x?(b.onOpen(),x.output&&b.onOutput(x.output),x.exited?b.onExit():u(S,w.cols,w.rows),x.views.add(b),{write(E){!x.exited&&x.socket.readyState===1&&x.socket.send(E)},resize(E,A){x.exited||u(S,E,A)},close(){x.views.delete(b)}}):(b.onError("This shell has ended."),{write(){},resize(){},close(){}})};async function m(g){const b=l.get(g);l.delete(g),b?.socket.close(),o({sessions:s.sessions.filter(w=>w.id!==g),attachment:s.attachment?.sessionId===g?null:s.attachment})}return{getState:()=>s,subscribe(g){return a.add(g),()=>{a.delete(g)}},connector:p,attach:d,stop:m,async create(g={}){const b=g.cwd??e.cwd,w={...e.env??{},...g.env??{}},S=await fetch(`${t}/containers/${e.containerId}/exec`,{method:"POST",headers:{"Content-Type":"application/json",...r},body:JSON.stringify({Cmd:e.shell??["sh"],Tty:!0,AttachStdin:!0,AttachStdout:!0,AttachStderr:!0,...b?{WorkingDir:b}:{},Env:["TERM=xterm-256color",...Object.entries(w).map(([O,F])=>`${O}=${F}`)]})}),x=await S.json().catch(()=>({}));if(!S.ok||!x.Id)throw new Error(x.message??`The container refused a shell (${S.status}).`);const E=x.Id,A=i(`${t}/exec/${E}/start?h=24&w=80`);A.binaryType="arraybuffer";const T={socket:A,output:"",exited:!1,views:new Set},D=new TextDecoder;return l.set(E,T),A.addEventListener("message",O=>{const F=O.data,_=typeof F=="string"?F:D.decode(F,{stream:!0});T.output=(T.output+_).slice(-n);for(const I of T.views)I.onOutput(_)}),A.addEventListener("error",()=>{for(const O of T.views)O.onError("The shell's connection failed.")}),A.addEventListener("close",()=>{if(l.get(E)===T){T.exited=!0,o({sessions:s.sessions.map(O=>O.id===E?{...O,activeCommand:"exited"}:O)});for(const O of T.views)O.onExit()}}),o({sessions:[...s.sessions,{id:E,label:g.label??`Shell ${++c}`,cwd:b??null,activeCommand:null,owned:!0}],error:null}),d(E),E},dispose(){for(const g of[...l.keys()])m(g)}}}const l0e=`.bs-toolbar, .bs-toolbar-drawer { --bs-bg: var(--volter-surface-raised, light-dark(#fbfaf7, #16252c)); --bs-fg: var(--volter-text-primary, light-dark(#16252c, #f3f2ec)); --bs-muted: var(--volter-text-muted, light-dark(#5d6970, #a9b0ad)); --bs-line: var(--volter-border-default, light-dark(#d9dad3, #2c3d45)); --bs-accent: var(--volter-action-default, light-dark(#16252c, #e4f09c)); --bs-on-accent: var(--volter-text-on-strong, light-dark(#ffffff, #16252c)); --bs-ready: var(--volter-status-healthy-base, light-dark(#3f7a55, #6fbf8e)); --bs-busy: var(--volter-status-attention-base, light-dark(#c7641a, #ec9a52)); --bs-error: var(--volter-status-danger-base, light-dark(#d24a1f, #f07650)); --bs-hover: var(--volter-overlay-hover, light-dark(rgba(22, 37, 44, 0.05), rgba(243, 242, 236, 0.06))); --bs-selected: var(--volter-selection-soft, light-dark(#eef4c4, rgba(228, 240, 156, 0.14))); --bs-selected-fg: var(--volter-selection-text, light-dark(#16252c, #f3f2ec)); color-scheme: light dark; --bs-radius: 999px; font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif; color: var(--bs-fg); }
2012
+ `)}const Xge=5e3;function tN(e,t,r){if(r.length===0)return`Linked ${e} of ${t}; no package is being made, so the link waits on the tree itself`;const n=r.slice(0,8).join(", ");return`Linked ${e} of ${t}; waiting on ${r.length}: ${n}${r.length>8?", …":""}`}function Kge(e){const t=atob(e.slice(7));let r="";for(let n=0;n<t.length;n+=1)r+=t.charCodeAt(n).toString(16).padStart(2,"0");return r}async function Qge(e,t,r){const n=await g6(t.url);return{...await h6(e,Ft,n.entries,r,bg(t.blobs)),integrity:n.integrity}}function Jge(e,t){const r=t.replace(/^\.\/?/u,"").replace(/\/$/u,"");return r===""||r==="."?!0:e===r||e.startsWith(`${r}/`)}async function e0e(e){try{if(!e.existsSync(Yh))return;const t=JSON.parse(await e.readFile(Yh,"utf8"));if(typeof t.integrity!="string")return;const r=typeof t.files=="object"&&t.files!==null?t.files:{},n=typeof t.since=="string"?t.since:typeof t.appliedAt=="string"?t.appliedAt:void 0;return{integrity:t.integrity,files:r,...n?{since:n}:{}}}catch{return}}async function t0e(e,t){if(!e.existsSync(Bc))return;let r;try{r=JSON.parse(await e.readFile(Bc,"utf8"))}catch{throw new Error("The workspace live-pack selection record is not valid JSON.")}if(!r||typeof r!="object"||Array.isArray(r))throw new Error("The workspace live-pack selection record has an unsupported shape.");const n=r,i=s=>typeof s=="string"&&/^sha256:[a-f0-9]{64}$/u.test(s);if(n.kind!=="browser-substrate.live-pack-selection"||n.version!==1||n.environment!==t||typeof n.name!="string"||n.name.length===0||typeof n.buildKey!="string"||n.buildKey.length===0||!i(n.manifest)||!i(n.closure))throw new Error(`The workspace live-pack selection record does not describe environment ${t}.`);return{name:n.name,buildKey:n.buildKey,manifest:n.manifest,closure:n.closure}}function r0e(e,t,r){if(!r){e.existsSync(Bc)&&e.unlinkSync(Bc);return}const n=Bc.slice(0,Bc.lastIndexOf("/"));e.existsSync(n)||e.mkdirSync(n,{recursive:!0});const i={kind:"browser-substrate.live-pack-selection",version:1,environment:t,...r};e.writeFileSync(Bc,JSON.stringify(i,null,2))}function rN(e,t,r,n){const i=Yh.slice(0,Yh.lastIndexOf("/"));e.existsSync(i)||e.mkdirSync(i,{recursive:!0});const s=new Date().toISOString();return e.writeFileSync(Yh,JSON.stringify({integrity:t,files:Object.fromEntries(r),appliedAt:s,since:n??s},null,2)),n??s}function n0e(e){e.existsSync(Fl)&&(zs(e,Fl),e.rmdirSync(Fl))}async function i0e(e,t,r){if(typeof caches>"u")return;const i=await(await r(e,{cache:"no-cache"})).text(),s=new URL(`/__browser-substrate-restored/${await nN(new TextEncoder().encode(i))}`,location.origin).href,a=await caches.open(pB);if(await a.match(s))return;const o=NF(JSON.parse(i)).filter(u=>s0e(u,t));o.sort((u,d)=>d.bytes-u.bytes);let l=0;const c=async()=>{for(;l<o.length;){const u=o[l++],d=await caches.open(u.cache),p=new URL(u.url,location.origin).href;if(await d.match(p))continue;const m=await r(new URL(u.file,location.href).href);if(!m.ok||!m.body)continue;const g=await new Response(m.body.pipeThrough(new DecompressionStream("gzip"))).arrayBuffer();g.byteLength!==u.bytes||await nN(new Uint8Array(g))!==u.sha256||await d.put(p,new Response(g,{status:u.status,headers:u.headers}))}};await Promise.all([c(),c(),c()]),await a.put(s,new Response(""));for(const u of o){const d=u.headers.find(([m])=>m.toLowerCase()==="content-type")?.[1]??"";if(!/^application\/wasm\b/iu.test(d))continue;const p=await(await caches.open(u.cache)).match(new URL(u.url,location.origin).href);p&&await WebAssembly.compileStreaming(p).catch(()=>{})}}const pB="browser-substrate-restored-caches";function s0e(e,t){if(e.cache.startsWith("browser-substrate-offline")||e.cache===pB)return!1;if(e.cache.startsWith("tabnode-http")){if(!e.url.startsWith(`/__tabnode_http_cache__/${encodeURIComponent(t)}/`))return!1;const r=s=>e.headers.find(([a])=>a.toLowerCase()===s)?.[1],n=Number(r("x-tabnode-stored-at")),i=Number(/(?:^|,)\s*max-age=(\d+)/iu.exec(r("cache-control")??"")?.[1]??0);if(!Number.isFinite(n)||Date.now()-n>=i*1e3)return!1}return!0}async function nN(e){return[...new Uint8Array(await crypto.subtle.digest("SHA-256",e))].map(t=>t.toString(16).padStart(2,"0")).join("")}function g2(){return Reflect.get(globalThis,Symbol.for("browser-substrate.dry-run"))===!0}async function a0e(e){const t=e.compilers,r=e.provisions;if(!t||!r||t.catalog!==r.digest||t.abi!==r.profile.abi)throw new Error("This image lacks exact catalog compiler assets; prepare and publish them through the demand pipeline, then regenerate the image.");const n=new URL(r.base,location.href),i=new Tg({endpoints:[{baseUrl:n.href}],trustedOrigins:[n.origin],pinnedCatalog:r.digest,fetch:vs,allowInsecureLocalhost:!0}),s=await i.planProvisions(t.bindings.map(c=>c.request),r.profile);if(Ti(Zq(s,e.name))!==Ti(t))throw new Error("Compiler projection differs from its authenticated exact catalog selection.");const a=new Set(t.bindings.filter(c=>c.request.kind==="runtime").flatMap(c=>[...Object.keys(t.files).filter(u=>u.startsWith(`/substrate/${e.name}.compilers/${c.manifest.slice(7)}/`)),...Object.keys(c.contract.aliases)]));for(const[c,u]of Object.entries(t.files)){if(!a.has(c))continue;const d=await vs(new URL(c,location.href));if(!d.ok)throw new Error(`Compiler file unavailable: ${c}`);const p=new Uint8Array(await d.arrayBuffer());if(p.byteLength!==u.bytes||await Xo(p)!==u.digest)throw new Error(`Compiler file corrupt: ${c}`)}const o={},l={};for(const c of t.bindings)if(c.request.kind==="runtime")for(const[u,d]of Object.entries(c.assets)){if(o[u])throw new Error(`Duplicate runtime compiler role: ${u}`);o[u]=d}else{if(!c.request.instance||!c.assets.rolldownModule)throw new Error("Compiler binding lacks its exact parent instance/factory.");l[`${Ft}/${c.request.instance}`]={url:c.assets.rolldownModule,version:c.contract.version}}for(const c of["esbuildModule","esbuildWasm","rollupModule","typeStripper"])if(!o[c])throw new Error(`Runtime compiler role ${c} is unpublished.`);return{catalog:i,assets:o,instances:l}}async function o0e(e,t){if(!e.dependencies&&!e.outputs)return;if(!e.outputs||!e.provisions)throw new Error("This image lacks prepared project outputs; prepare it on a machine with browser-substrate build.");let r,n,i;if("url"in e.outputs)r=e.outputs,n=new URL(e.outputs.url,location.href);else{const u=await t.planProvisions([e.outputs.request],e.provisions.profile),d=u.rows[0];if(d?.status!=="resolved"||d.provision?.disposition!=="pack"||d.provision.contract.kind!=="project-output"||!d.selection)throw new Error(d?.reason??"Exact project output context is unpublished.");const p=d.provision.contract,m=[...d.selection.manifests.values()].flatMap(g=>g.artifacts).find(g=>g.digest===p.document);if(!m||m.parts||p.inputs!==e.outputs.request.instance||p.sourcePin!==e.outputs.request.version)throw new Error("Project document is not bound by its selected closure.");r={digest:p.document,bytes:m.bytes,inputs:p.inputs,sourcePin:p.sourcePin},n=new URL(e.provisions.base+U1("artifacts",r.digest),location.href),i=d.selection.closure.preparedOutputs}if(n.origin!==location.origin)throw new Error("Project document must be carried by the image origin.");const s=await vs(n),a=new Uint8Array(await s.arrayBuffer());if(!s.ok||a.byteLength!==r.bytes||await Xo(a)!==r.digest)throw new Error("Project document missing/corrupt.");const o=s1e(JSON.parse(new TextDecoder().decode(a))),l=await Xo(new TextEncoder().encode(Ti(o.inputs)));if(l!==r.inputs||o.inputs.sourcePin!==r.sourcePin||o.inputs.image!==e.name||o.inputs.abi!==e.provisions.profile.abi||o.inputs.source!==e.archive.integrity||o.inputs.world!==(e.world?.archive.integrity??"none")||o.plan.key!==e.dependencies?.key)throw new Error("Prepared outputs differ from the image's source/World/dependency context.");for(const u of o.outputs)if(u.inputs!==l||i!==void 0&&!i.some(d=>Ti(d)===Ti(u)))throw new Error("Prepared output lock binding changed.");if(!e.packs||o.packs.packs.length!==e.packs.count)throw new Error("Prepared browser outputs are missing.");const c=r0(await(await vs(e.dependencies.url,{cache:"no-store"})).json());if(Ti(c)!==Ti(o.plan))throw new Error("Prepared dependency document was substituted.");return o}function mB(e){const t=e.base.replace(/\/$/u,""),r=e.headers??{},n=e.bufferBytes??256*1024,i=e.socket??(g=>new WebSocket(g.replace(/^http/u,"ws")));let s={available:!0,canOpenLocal:!1,error:null,sessions:[],attachment:null};const a=new Set,o=g=>{s={...s,...g};for(const b of a)b()},l=new Map;let c=0;const u=(g,b,w)=>{fetch(`${t}/exec/${g}/resize?h=${w}&w=${b}`,{method:"POST",headers:r}).catch(()=>{})},d=g=>o({attachment:{id:`${g}:${Date.now()}`,baseUrl:t,mode:"control",sessionId:g}}),p=(g,b,w)=>{const S=g.sessionId??g.id,x=l.get(S);return x?(b.onOpen(),x.output&&b.onOutput(x.output),x.exited?b.onExit():u(S,w.cols,w.rows),x.views.add(b),{write(E){!x.exited&&x.socket.readyState===1&&x.socket.send(E)},resize(E,A){x.exited||u(S,E,A)},close(){x.views.delete(b)}}):(b.onError("This shell has ended."),{write(){},resize(){},close(){}})};async function m(g){const b=l.get(g);l.delete(g),b?.socket.close(),o({sessions:s.sessions.filter(w=>w.id!==g),attachment:s.attachment?.sessionId===g?null:s.attachment})}return{getState:()=>s,subscribe(g){return a.add(g),()=>{a.delete(g)}},connector:p,attach:d,stop:m,async create(g={}){const b=g.cwd??e.cwd,w={...e.env??{},...g.env??{}},S=await fetch(`${t}/containers/${e.containerId}/exec`,{method:"POST",headers:{"Content-Type":"application/json",...r},body:JSON.stringify({Cmd:e.shell??["sh"],Tty:!0,AttachStdin:!0,AttachStdout:!0,AttachStderr:!0,...b?{WorkingDir:b}:{},Env:["TERM=xterm-256color",...Object.entries(w).map(([O,F])=>`${O}=${F}`)]})}),x=await S.json().catch(()=>({}));if(!S.ok||!x.Id)throw new Error(x.message??`The container refused a shell (${S.status}).`);const E=x.Id,A=i(`${t}/exec/${E}/start?h=24&w=80`);A.binaryType="arraybuffer";const T={socket:A,output:"",exited:!1,views:new Set},D=new TextDecoder;return l.set(E,T),A.addEventListener("message",O=>{const F=O.data,_=typeof F=="string"?F:D.decode(F,{stream:!0});T.output=(T.output+_).slice(-n);for(const I of T.views)I.onOutput(_)}),A.addEventListener("error",()=>{for(const O of T.views)O.onError("The shell's connection failed.")}),A.addEventListener("close",()=>{if(l.get(E)===T){T.exited=!0,o({sessions:s.sessions.map(O=>O.id===E?{...O,activeCommand:"exited"}:O)});for(const O of T.views)O.onExit()}}),o({sessions:[...s.sessions,{id:E,label:g.label??`Shell ${++c}`,cwd:b??null,activeCommand:null,owned:!0}],error:null}),d(E),E},dispose(){for(const g of[...l.keys()])m(g)}}}const l0e=`.bs-toolbar, .bs-toolbar-drawer { --bs-bg: var(--volter-surface-raised, light-dark(#fbfaf7, #16252c)); --bs-fg: var(--volter-text-primary, light-dark(#16252c, #f3f2ec)); --bs-muted: var(--volter-text-muted, light-dark(#5d6970, #a9b0ad)); --bs-line: var(--volter-border-default, light-dark(#d9dad3, #2c3d45)); --bs-accent: var(--volter-action-default, light-dark(#16252c, #e4f09c)); --bs-on-accent: var(--volter-text-on-strong, light-dark(#ffffff, #16252c)); --bs-ready: var(--volter-status-healthy-base, light-dark(#3f7a55, #6fbf8e)); --bs-busy: var(--volter-status-attention-base, light-dark(#c7641a, #ec9a52)); --bs-error: var(--volter-status-danger-base, light-dark(#d24a1f, #f07650)); --bs-hover: var(--volter-overlay-hover, light-dark(rgba(22, 37, 44, 0.05), rgba(243, 242, 236, 0.06))); --bs-selected: var(--volter-selection-soft, light-dark(#eef4c4, rgba(228, 240, 156, 0.14))); --bs-selected-fg: var(--volter-selection-text, light-dark(#16252c, #f3f2ec)); color-scheme: light dark; --bs-radius: 999px; font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif; color: var(--bs-fg); }
2013
2013
  .bs-toolbar { position: fixed; z-index: 2147483000; display: flex; flex-direction: column-reverse; gap: 8px; touch-action: none; --bs-drawer: 0px; }
2014
2014
  .bs-toolbar[data-corner^="bottom"] { bottom: calc(16px + var(--bs-drawer)); }
2015
2015
  .bs-toolbar[data-corner^="top"] { top: 16px; flex-direction: column; }