@holoscript/core 8.0.7 → 8.0.9

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 (462) hide show
  1. package/bin/holoscript.cjs +5 -1
  2. package/dist/GLTFPipeline-L76YTXKA.js +15 -0
  3. package/dist/GLTFPipeline-ZWJN7GI6.cjs +36 -0
  4. package/dist/HoloCompositionParser-K76KTEEE.js +12 -0
  5. package/dist/HoloCompositionParser-UZH6Y4HO.cjs +45 -0
  6. package/dist/HoloScriptCodeParser-2D4ERFUZ.js +6 -0
  7. package/dist/HoloScriptCodeParser-UDRLDA7I.cjs +23 -0
  8. package/dist/HoloScriptPlusParser-FTMCGWXD.js +13 -0
  9. package/dist/HoloScriptPlusParser-LQR5GIKF.cjs +30 -0
  10. package/dist/HoloScriptRuntime-UTRLJI5L.js +12 -0
  11. package/dist/HoloScriptRuntime-YBYXJHJN.cjs +21 -0
  12. package/dist/SceneIRCompiler-63KA3M2F.js +17 -0
  13. package/dist/SceneIRCompiler-KWUFHZ4O.cjs +42 -0
  14. package/dist/{USDZExporter-AUHZODOF.cjs → USDZExporter-ML4UMIGC.cjs} +3 -3
  15. package/dist/{USDZExporter-GXB4AUSG.js → USDZExporter-ZFKLQ76G.js} +3 -3
  16. package/dist/agents/index.cjs +1 -1
  17. package/dist/agents/index.js +1 -1
  18. package/dist/audit/AuditLogger.d.ts +106 -0
  19. package/dist/audit/AuditQueryBuilder.d.ts +79 -0
  20. package/dist/audit/ComplianceReporter.d.ts +90 -0
  21. package/dist/audit/index.d.ts +13 -0
  22. package/dist/{chunk-FGMDMJM7.js → chunk-2BYAUHBO.js} +3 -3
  23. package/dist/{chunk-EDPYCLRC.cjs → chunk-2E6PP5UE.cjs} +83 -59
  24. package/dist/{chunk-GASCWJK5.js → chunk-2EGGAZT3.js} +65 -287
  25. package/dist/{chunk-SIEXCILW.js → chunk-2I3XAGMF.js} +3 -3
  26. package/dist/{chunk-OS533P33.cjs → chunk-2KKOYZYI.cjs} +1074 -1655
  27. package/dist/chunk-2MQKNDNH.js +51 -0
  28. package/dist/{chunk-7DMMMBCY.cjs → chunk-2X3IPCBK.cjs} +10 -10
  29. package/dist/chunk-2ZOTBO25.cjs +202 -0
  30. package/dist/chunk-356N4NPM.cjs +152 -0
  31. package/dist/{chunk-X3GJPRVK.cjs → chunk-36NPLOI4.cjs} +92 -81
  32. package/dist/{chunk-SLU6UPJI.cjs → chunk-37HHY7RH.cjs} +5 -5
  33. package/dist/{chunk-YDPEHCCI.cjs → chunk-3CDDRUER.cjs} +3 -118
  34. package/dist/chunk-3F7ZZWIN.js +1651 -0
  35. package/dist/chunk-3ILD7TKP.cjs +187 -0
  36. package/dist/{chunk-X27QRG4C.cjs → chunk-3IUHTGDD.cjs} +153 -41
  37. package/dist/{chunk-PXNZ6TME.js → chunk-4376VHNJ.js} +60 -36
  38. package/dist/{chunk-YKGPCZEE.cjs → chunk-4FIBOJW6.cjs} +10 -10
  39. package/dist/chunk-4Q7RKQQI.cjs +14195 -0
  40. package/dist/{chunk-YCM6QQRT.cjs → chunk-566ZB4LZ.cjs} +180 -8
  41. package/dist/{chunk-2Y3V22SG.js → chunk-5CURIYGT.js} +3 -3
  42. package/dist/{chunk-QBWNJXNR.js → chunk-5FYMCVBY.js} +5 -5
  43. package/dist/{chunk-ZA34AN3R.js → chunk-5LVFTGKH.js} +841 -12
  44. package/dist/chunk-63AUAIL6.js +48 -0
  45. package/dist/chunk-655FATJU.js +110 -0
  46. package/dist/{chunk-TQ377OLB.cjs → chunk-65S62L4D.cjs} +28 -22
  47. package/dist/chunk-6NTAZN5Z.cjs +502 -0
  48. package/dist/chunk-6TRX6AR2.js +9376 -0
  49. package/dist/chunk-6ZCCLKS2.cjs +51 -0
  50. package/dist/{chunk-MDR235RZ.js → chunk-734OB5SK.js} +721 -8
  51. package/dist/{chunk-Q2Q34NF3.js → chunk-77QI552M.js} +6 -6
  52. package/dist/{chunk-WKX5AMOY.js → chunk-7I74JWPW.js} +3 -3
  53. package/dist/{chunk-5FSKKMR7.cjs → chunk-7IDJDMPU.cjs} +232 -4
  54. package/dist/chunk-7VBKRGIZ.cjs +847 -0
  55. package/dist/{chunk-KCPHASCO.js → chunk-AATYYLYK.js} +5 -5
  56. package/dist/{chunk-WFKVS2K4.cjs → chunk-AUZRKIHQ.cjs} +1101 -55
  57. package/dist/{chunk-DTGBOSEM.cjs → chunk-AWXFEAQL.cjs} +12 -12
  58. package/dist/{chunk-THCK6ECW.js → chunk-B3CWTCK2.js} +231 -3
  59. package/dist/chunk-BCP4E7MD.cjs +997 -0
  60. package/dist/chunk-BG7RPYJP.js +91 -0
  61. package/dist/{chunk-VF257YKO.js → chunk-BP4KTMLY.js} +117 -5
  62. package/dist/{chunk-YN6IETRZ.js → chunk-BQJ3YBF3.js} +6424 -987
  63. package/dist/{chunk-KOUAQL2B.cjs → chunk-CANAL6CT.cjs} +1569 -168
  64. package/dist/{chunk-FDSGHPAK.js → chunk-CBSDJF3B.js} +3 -3
  65. package/dist/{chunk-FEWUHQNM.cjs → chunk-CFVK26P4.cjs} +4 -4
  66. package/dist/{chunk-M7K4LE66.cjs → chunk-CI33NINL.cjs} +4 -4
  67. package/dist/{chunk-2OWDB4FB.js → chunk-CKV5NYAE.js} +6 -6
  68. package/dist/{chunk-LPS5AMQD.cjs → chunk-CM4NHXVO.cjs} +24 -24
  69. package/dist/chunk-D3HSRXYB.js +115 -0
  70. package/dist/{chunk-FNHJRI32.js → chunk-DBH3D2MU.js} +1561 -160
  71. package/dist/{chunk-GW3LKD5C.js → chunk-DJNH4HFW.js} +3 -3
  72. package/dist/{chunk-2GCNOI2U.cjs → chunk-DN6F4DHH.cjs} +9 -3
  73. package/dist/chunk-DQRJ5RJG.js +432 -0
  74. package/dist/{chunk-C7ZBSV2Q.js → chunk-DUG3OQAS.js} +106 -43
  75. package/dist/chunk-ECUYJOJ2.cjs +199 -0
  76. package/dist/chunk-EEMTCAK7.js +182 -0
  77. package/dist/{chunk-3SKLAUDD.cjs → chunk-EI3J6LTW.cjs} +359 -581
  78. package/dist/{chunk-SSSN7VAM.js → chunk-EM2OGPYE.js} +4 -4
  79. package/dist/{chunk-56VOWURB.cjs → chunk-ENZCIQZC.cjs} +522 -453
  80. package/dist/chunk-ESBXUYOC.cjs +836 -0
  81. package/dist/{chunk-L5U4W6JC.js → chunk-ESSEF6U2.js} +4 -4
  82. package/dist/chunk-ET3AN4W3.js +824 -0
  83. package/dist/chunk-EXKSFGSX.cjs +14 -14
  84. package/dist/{chunk-I76GIKN7.cjs → chunk-F3YT6GUF.cjs} +17 -17
  85. package/dist/{chunk-WRWEX5ZF.js → chunk-F75DZBBI.js} +3 -3
  86. package/dist/{chunk-4JGRWHZJ.js → chunk-FG6PYGIZ.js} +12 -6
  87. package/dist/chunk-FGGJQRLZ.js +14 -14
  88. package/dist/{chunk-SXOSDZD6.js → chunk-FWCHPCD4.js} +128 -10
  89. package/dist/{chunk-XW6IXEQH.cjs → chunk-G35CAQ7I.cjs} +5 -5
  90. package/dist/{chunk-7VMGP2FW.js → chunk-G6KACNMO.js} +132 -188
  91. package/dist/{chunk-FJPADH77.cjs → chunk-GAWJJAGT.cjs} +6 -6
  92. package/dist/chunk-GGR7QUKK.cjs +4724 -0
  93. package/dist/chunk-GIBF4BHH.js +14098 -0
  94. package/dist/{chunk-AWB7QYY6.cjs → chunk-GILYQ5VH.cjs} +6 -6
  95. package/dist/{chunk-FWVYAMNW.cjs → chunk-GKFCHGCM.cjs} +4 -4
  96. package/dist/{chunk-Y3ZFVUUU.js → chunk-GLEJ2TLS.js} +3 -3
  97. package/dist/{chunk-3GWWJT7L.js → chunk-GP3OKSKT.js} +13 -13
  98. package/dist/chunk-GTIPOEHN.js +196 -0
  99. package/dist/{chunk-LMJ5EBV7.cjs → chunk-GZPUA2TL.cjs} +16 -15
  100. package/dist/{chunk-IELX2OKI.js → chunk-H4LJ4HEA.js} +3 -115
  101. package/dist/{chunk-ACVWFGBI.cjs → chunk-HCX4SMFK.cjs} +3 -3
  102. package/dist/{chunk-HYNTS5CP.js → chunk-HHRZ6STP.js} +24 -2
  103. package/dist/chunk-HIDEIEFG.js +48 -0
  104. package/dist/{chunk-W6RW64BB.cjs → chunk-HSWBIDZM.cjs} +228 -5
  105. package/dist/{chunk-GSOUNWEL.js → chunk-HVX7QQYK.js} +1035 -1616
  106. package/dist/{chunk-TRCGG42I.cjs → chunk-IFW5IW4L.cjs} +6502 -1019
  107. package/dist/{chunk-F5LKJ6F5.cjs → chunk-IJU6AS67.cjs} +32 -28
  108. package/dist/{chunk-TVANHNJ7.js → chunk-IK6Z2HNC.js} +173 -3
  109. package/dist/{chunk-QGMUTVVH.cjs → chunk-IS7NTKY5.cjs} +20 -20
  110. package/dist/{chunk-YFVQWSNJ.js → chunk-IXWGYWH6.js} +3 -3
  111. package/dist/chunk-J2DAS2PL.js +148 -0
  112. package/dist/chunk-JBQXZIWB.js +148 -0
  113. package/dist/chunk-JBYBMBMW.js +261 -0
  114. package/dist/{chunk-LWUOUCYL.js → chunk-JEJ7TT54.js} +5 -5
  115. package/dist/{chunk-DUCB6LGL.js → chunk-JOTCTHN5.js} +211 -5
  116. package/dist/{chunk-47RUFYKR.js → chunk-K56UVEXV.js} +3 -3
  117. package/dist/{chunk-XSFNHP2E.js → chunk-KB26H447.js} +3 -3
  118. package/dist/{chunk-3NGDZZR4.js → chunk-KEYG7HGY.js} +430 -37
  119. package/dist/{chunk-DY72BMU5.js → chunk-KFVNCW4Q.js} +4 -4
  120. package/dist/chunk-KPGC7SK2.js +192 -0
  121. package/dist/chunk-KROXXBK5.cjs +53 -0
  122. package/dist/{chunk-ZPZAVHXL.cjs → chunk-LB3ZZMKT.cjs} +137 -19
  123. package/dist/chunk-LDYZWNJW.cjs +1654 -0
  124. package/dist/{chunk-ULMSSHCJ.cjs → chunk-LMB555QB.cjs} +405 -38
  125. package/dist/{chunk-CBJY23VL.js → chunk-MD4IVS42.js} +3 -3
  126. package/dist/{chunk-VMLKSV26.js → chunk-MDDWEBCX.js} +226 -3
  127. package/dist/chunk-MUWH4QK5.cjs +94 -0
  128. package/dist/{chunk-T6W3Z3SH.cjs → chunk-N2ILK7BF.cjs} +4 -4
  129. package/dist/{chunk-6EX3I5P4.cjs → chunk-N74QRJGP.cjs} +6 -6
  130. package/dist/chunk-NFFHLX37.cjs +132 -0
  131. package/dist/chunk-NJSYWX7H.js +190 -0
  132. package/dist/{chunk-SH5PPVK7.cjs → chunk-NQN5LFN4.cjs} +165 -221
  133. package/dist/chunk-NTQRFOPP.cjs +56 -0
  134. package/dist/{chunk-YFWRJW4B.js → chunk-NWMJPTVL.js} +51 -55
  135. package/dist/{chunk-63ZGNR2T.cjs → chunk-OC6GV5QH.cjs} +42 -42
  136. package/dist/{chunk-7E7GCQCK.js → chunk-OG3MBHM3.js} +9 -3
  137. package/dist/chunk-OMNHTCS4.cjs +264 -0
  138. package/dist/chunk-OQXB6NNC.cjs +117 -0
  139. package/dist/{chunk-Y57W2CT5.cjs → chunk-OV46CCA2.cjs} +51 -55
  140. package/dist/{chunk-6PRZIHGL.cjs → chunk-OV6HHKLE.cjs} +21 -266
  141. package/dist/{chunk-C37BHB7N.cjs → chunk-P26YYPOO.cjs} +5 -5
  142. package/dist/{chunk-2BZHWUSR.cjs → chunk-P7JEKJTZ.cjs} +16 -16
  143. package/dist/{chunk-NGBXXZLL.cjs → chunk-PDXX5UI4.cjs} +45 -45
  144. package/dist/{chunk-FHQFPYV4.js → chunk-PJFTTSKE.js} +8 -7
  145. package/dist/{chunk-GVFJ6T4S.cjs → chunk-PVODJEJ7.cjs} +721 -8
  146. package/dist/{chunk-ZZ7RO2UQ.js → chunk-Q265VZJ4.js} +3 -3
  147. package/dist/{chunk-E7JP3BS3.cjs → chunk-Q47JEE2C.cjs} +4 -4
  148. package/dist/chunk-QBY7LRN2.js +281 -0
  149. package/dist/{chunk-Z6PMDS4G.js → chunk-QDQWKSU3.js} +1090 -53
  150. package/dist/{chunk-GH6C2QGW.cjs → chunk-QEDMOGF3.cjs} +857 -16
  151. package/dist/{chunk-5WUNN6ZN.cjs → chunk-QHSAVOOL.cjs} +24 -2
  152. package/dist/chunk-QJNCDVYM.cjs +137 -0
  153. package/dist/chunk-QM7FJB5W.js +4717 -0
  154. package/dist/chunk-QQFB4RT2.cjs +448 -0
  155. package/dist/chunk-QSYBHQAD.cjs +196 -0
  156. package/dist/{chunk-UGXHYIWT.cjs → chunk-QUJ3ZB55.cjs} +28 -28
  157. package/dist/{chunk-2YSNA2F2.cjs → chunk-QVJMDVYZ.cjs} +5 -5
  158. package/dist/chunk-RAJMAX6D.js +131 -0
  159. package/dist/{chunk-VVKVQZI6.js → chunk-RAN3ECAS.js} +3 -3
  160. package/dist/chunk-RKGUZBOC.js +79 -0
  161. package/dist/{chunk-HLFDZ35S.cjs → chunk-RRQIAJLQ.cjs} +8 -8
  162. package/dist/{chunk-PABONWKI.js → chunk-RXQNRZ5F.js} +3 -3
  163. package/dist/{chunk-7ZHYEITD.cjs → chunk-S4O7CFHQ.cjs} +10 -11
  164. package/dist/chunk-SE7ANBGN.js +128 -0
  165. package/dist/{chunk-X2AVEAZM.cjs → chunk-SJIRCTIS.cjs} +176 -2
  166. package/dist/{chunk-WXQ57LAO.js → chunk-SQXAZHDG.js} +4 -4
  167. package/dist/chunk-SR73L5ZP.cjs +84 -0
  168. package/dist/{chunk-OABEO6HH.js → chunk-SZOLTWWD.js} +2349 -214
  169. package/dist/{chunk-5JEU52DW.js → chunk-TPZ3BN2D.js} +3 -3
  170. package/dist/{chunk-QFU53KRH.js → chunk-TSTFYGGX.js} +4 -5
  171. package/dist/{chunk-EBS32AJI.cjs → chunk-TZCFKZ6Z.cjs} +5 -5
  172. package/dist/chunk-UCVZXQ63.js +724 -0
  173. package/dist/chunk-UGQ3QNV6.js +992 -0
  174. package/dist/chunk-UNMVGZVW.js +142 -0
  175. package/dist/{chunk-TEVX443G.js → chunk-UTUD6GJI.js} +178 -6
  176. package/dist/chunk-UXBYA7DV.cjs +155 -0
  177. package/dist/chunk-V6GXFSK7.cjs +443 -0
  178. package/dist/chunk-VHORVGCG.cjs +761 -0
  179. package/dist/{chunk-B4EKV6HQ.js → chunk-VKCTYLDN.js} +500 -442
  180. package/dist/{chunk-O3MGZDCT.cjs → chunk-VTEXJOSD.cjs} +63 -63
  181. package/dist/chunk-VVAAZITA.cjs +287 -0
  182. package/dist/{chunk-V7AKE5VT.cjs → chunk-W2GA3EQB.cjs} +435 -42
  183. package/dist/chunk-W4GABFCR.js +37 -0
  184. package/dist/chunk-WKEK4NCA.js +490 -0
  185. package/dist/{chunk-5A4TCHOC.cjs → chunk-WNYXT4TE.cjs} +4 -4
  186. package/dist/{chunk-S762UEV5.js → chunk-WTH23ISI.js} +6 -6
  187. package/dist/{chunk-BTKZGHAV.js → chunk-WWNCM473.js} +10 -6
  188. package/dist/{chunk-7X5PNIQJ.js → chunk-X3YFRH6K.js} +27 -25
  189. package/dist/{chunk-4YNYPHH3.cjs → chunk-X75H75UY.cjs} +2351 -213
  190. package/dist/{chunk-LYJJI7ZK.cjs → chunk-XCUDDFKC.cjs} +216 -9
  191. package/dist/chunk-YAO4HPJL.cjs +120 -0
  192. package/dist/chunk-YKY2JBER.cjs +9443 -0
  193. package/dist/chunk-YP5CHEYU.cjs +154 -0
  194. package/dist/{chunk-WRNEH5MO.js → chunk-YW3I2FQL.js} +18 -7
  195. package/dist/{chunk-BRNUPDHJ.js → chunk-Z557DVYN.js} +386 -19
  196. package/dist/{chunk-VSACG2AR.js → chunk-Z6LZUYZF.js} +21 -264
  197. package/dist/chunk-ZHPMP447.cjs +43 -0
  198. package/dist/{chunk-LODTHGST.cjs → chunk-ZK7KX5CD.cjs} +133 -70
  199. package/dist/{chunk-CCPSNT6B.cjs → chunk-ZRPALBQB.cjs} +5 -5
  200. package/dist/chunk-ZVFHPMC5.js +824 -0
  201. package/dist/chunk-ZVQMKUGJ.js +443 -0
  202. package/dist/cli/holoscript-runner.cjs +86 -48
  203. package/dist/cli/holoscript-runner.js +54 -16
  204. package/dist/codebase/index.cjs +1 -1
  205. package/dist/codebase/index.js +1 -1
  206. package/dist/compiler/agent-inference.cjs +11 -11
  207. package/dist/compiler/agent-inference.js +9 -6
  208. package/dist/compiler/android-xr.cjs +13 -12
  209. package/dist/compiler/android-xr.js +11 -10
  210. package/dist/compiler/android.cjs +12 -12
  211. package/dist/compiler/android.js +10 -10
  212. package/dist/compiler/business-quest.cjs +10 -10
  213. package/dist/compiler/business-quest.js +2 -2
  214. package/dist/compiler/coco.cjs +1 -1
  215. package/dist/compiler/coco.js +1 -1
  216. package/dist/compiler/context.cjs +9 -9
  217. package/dist/compiler/context.js +6 -6
  218. package/dist/compiler/daimon-seed.cjs +36 -0
  219. package/dist/compiler/daimon-seed.js +12 -0
  220. package/dist/compiler/domain-block-utils.cjs +205 -156
  221. package/dist/compiler/domain-block-utils.js +8 -7
  222. package/dist/compiler/dtdl.cjs +10 -10
  223. package/dist/compiler/dtdl.js +7 -7
  224. package/dist/compiler/gltf-pipeline.cjs +9 -9
  225. package/dist/compiler/gltf-pipeline.js +2 -2
  226. package/dist/compiler/godot.cjs +10 -9
  227. package/dist/compiler/godot.js +9 -8
  228. package/dist/compiler/incremental.cjs +11 -11
  229. package/dist/compiler/incremental.js +6 -6
  230. package/dist/compiler/index.cjs +2585 -3273
  231. package/dist/compiler/index.d.ts +149 -35
  232. package/dist/compiler/index.js +2197 -3102
  233. package/dist/compiler/ios.cjs +11 -11
  234. package/dist/compiler/ios.js +9 -9
  235. package/dist/compiler/llm-provider-capabilities.cjs +9 -9
  236. package/dist/compiler/llm-provider-capabilities.js +6 -6
  237. package/dist/compiler/nodetoy.cjs +1 -1
  238. package/dist/compiler/nodetoy.js +1 -1
  239. package/dist/compiler/openxr.cjs +11 -10
  240. package/dist/compiler/openxr.js +10 -9
  241. package/dist/compiler/remotion.cjs +1 -1
  242. package/dist/compiler/remotion.js +1 -1
  243. package/dist/compiler/reproducibility.cjs +1 -1
  244. package/dist/compiler/reproducibility.js +1 -1
  245. package/dist/compiler/sdf.cjs +11 -10
  246. package/dist/compiler/sdf.js +9 -8
  247. package/dist/compiler/semantic-scene.cjs +7 -7
  248. package/dist/compiler/semantic-scene.js +2 -2
  249. package/dist/compiler/state.cjs +9 -9
  250. package/dist/compiler/state.js +7 -7
  251. package/dist/compiler/trait-composition.cjs +11 -11
  252. package/dist/compiler/trait-composition.js +7 -7
  253. package/dist/compiler/traits/ProvenanceSemiring.d.ts +167 -0
  254. package/dist/compiler/traits/Semiring.d.ts +26 -0
  255. package/dist/compiler/unity.cjs +11 -10
  256. package/dist/compiler/unity.js +10 -9
  257. package/dist/compiler/unreal.cjs +12 -11
  258. package/dist/compiler/unreal.js +10 -9
  259. package/dist/compiler/urdf.cjs +18 -17
  260. package/dist/compiler/urdf.js +9 -8
  261. package/dist/compiler/usd-physics.cjs +11 -10
  262. package/dist/compiler/usd-physics.js +8 -7
  263. package/dist/compiler/visionos.cjs +11 -10
  264. package/dist/compiler/visionos.js +10 -9
  265. package/dist/compiler/vrchat.cjs +11 -10
  266. package/dist/compiler/vrchat.js +9 -8
  267. package/dist/compiler/wasm.cjs +14 -13
  268. package/dist/compiler/wasm.js +9 -8
  269. package/dist/compiler/webgpu.cjs +10 -9
  270. package/dist/compiler/webgpu.js +9 -8
  271. package/dist/constants.cjs +398 -0
  272. package/dist/constants.js +9 -0
  273. package/dist/coordinators/index.cjs +4 -1
  274. package/dist/coordinators/index.js +4 -1
  275. package/dist/debugger.cjs +11 -9
  276. package/dist/debugger.js +9 -7
  277. package/dist/{dist-ACXG6IH5.cjs → dist-GRMOP2UL.cjs} +341 -65
  278. package/dist/{dist-VD4L6V7Q.js → dist-ZBUKU2JG.js} +333 -63
  279. package/dist/entries/interop.cjs +23 -23
  280. package/dist/entries/interop.js +3 -3
  281. package/dist/entries/scripting.cjs +12 -11
  282. package/dist/entries/scripting.js +8 -7
  283. package/dist/evolution/index.cjs +66 -0
  284. package/dist/evolution/index.d.ts +162 -0
  285. package/dist/evolution/index.js +17 -0
  286. package/dist/hololand/index.cjs +41 -37
  287. package/dist/hololand/index.js +3 -3
  288. package/dist/index.cjs +12394 -3224
  289. package/dist/index.d.ts +260 -18
  290. package/dist/index.js +10755 -2182
  291. package/dist/keyword-registry/PluginKeywordRegistry.d.ts +138 -0
  292. package/dist/keyword-registry/index.cjs +29 -0
  293. package/dist/keyword-registry/index.d.ts +1 -0
  294. package/dist/keyword-registry/index.js +4 -0
  295. package/dist/math/tropical-spmv.cjs +11 -11
  296. package/dist/math/tropical-spmv.d.ts +1 -0
  297. package/dist/math/tropical-spmv.js +2 -2
  298. package/dist/math/tropicalSpmv.d.ts +43 -0
  299. package/dist/math/vec3.cjs +1 -1
  300. package/dist/math/vec3.js +1 -1
  301. package/dist/matter/StagedMatter.d.ts +82 -0
  302. package/dist/matter/index.cjs +17 -0
  303. package/dist/matter/index.d.ts +1 -0
  304. package/dist/matter/index.js +4 -0
  305. package/dist/{ml-dsa-Z7JDKW4L.js → ml-dsa-J6VKVT4K.js} +3 -3
  306. package/dist/{ml-dsa-FSKBTE3W.cjs → ml-dsa-MTIK4ZUQ.cjs} +23 -23
  307. package/dist/paper-0c-spike/index.cjs +1 -1
  308. package/dist/paper-0c-spike/index.js +1 -1
  309. package/dist/parameter-envelope/ParameterEnvelope.d.ts +128 -0
  310. package/dist/parameter-envelope/index.cjs +17 -0
  311. package/dist/parameter-envelope/index.d.ts +2 -0
  312. package/dist/parameter-envelope/index.js +4 -0
  313. package/dist/parser/HoloCompositionTypes.d.ts +2013 -0
  314. package/dist/parser/PipelineParser.d.ts +162 -0
  315. package/dist/parser.cjs +36 -20
  316. package/dist/parser.js +13 -9
  317. package/dist/plugin-manifest/ManifestAutoLoader.d.ts +35 -0
  318. package/dist/plugin-manifest/PluginManifest.d.ts +156 -0
  319. package/dist/plugin-manifest/index.cjs +25 -0
  320. package/dist/plugin-manifest/index.d.ts +2 -0
  321. package/dist/plugin-manifest/index.js +4 -0
  322. package/dist/plugin-solver-contract/PluginSolverContract.d.ts +288 -0
  323. package/dist/plugin-solver-contract/index.cjs +41 -0
  324. package/dist/plugin-solver-contract/index.d.ts +1 -0
  325. package/dist/plugin-solver-contract/index.js +4 -0
  326. package/dist/policy/ContentPolicyGate.d.ts +51 -0
  327. package/dist/policy/PolicyPack.d.ts +120 -0
  328. package/dist/policy/blocklist.d.ts +32 -0
  329. package/dist/policy/defaults.d.ts +44 -0
  330. package/dist/policy/index.cjs +106 -0
  331. package/dist/policy/index.d.ts +17 -0
  332. package/dist/policy/index.js +5 -0
  333. package/dist/policy/jsonLogic.d.ts +31 -0
  334. package/dist/policy/types.d.ts +174 -0
  335. package/dist/proof-composition/ProofCompositionLaw.d.ts +93 -0
  336. package/dist/proof-composition/index.cjs +25 -0
  337. package/dist/proof-composition/index.d.ts +1 -0
  338. package/dist/proof-composition/index.js +4 -0
  339. package/dist/receipts/hash-policy.d.ts +85 -0
  340. package/dist/reconstruction/index.cjs +75 -47
  341. package/dist/reconstruction/index.js +5 -5
  342. package/dist/runtime/plugin-trait-registrar.d.ts +36 -0
  343. package/dist/runtime.cjs +81 -79
  344. package/dist/runtime.js +9 -7
  345. package/dist/scene-presets-EDKYZ5GW.js +4 -0
  346. package/dist/scene-presets-NCW2CFRS.cjs +17 -0
  347. package/dist/self-improvement/index.cjs +1 -1
  348. package/dist/self-improvement/index.js +1 -1
  349. package/dist/{src-PT2FERDV.cjs → src-G3D7ZATQ.cjs} +545 -21
  350. package/dist/{src-J6CM4AUR.js → src-UXYA7HM6.js} +539 -16
  351. package/dist/storage/index.cjs +10 -10
  352. package/dist/storage/index.js +3 -3
  353. package/dist/testing.cjs +1 -1
  354. package/dist/testing.js +1 -1
  355. package/dist/tools/index.cjs +3631 -0
  356. package/dist/tools/index.js +3581 -0
  357. package/dist/traitDocs/traitDocs.cjs +9 -9
  358. package/dist/traitDocs/traitDocs.d.ts +1 -0
  359. package/dist/traitDocs/traitDocs.js +3 -3
  360. package/dist/traits/ControlLoopTrait.d.ts +154 -0
  361. package/dist/traits/KinematicChainTrait.d.ts +116 -0
  362. package/dist/traits/SensorSamplingTrait.d.ts +154 -0
  363. package/dist/traits/TraitTypes.d.ts +270 -0
  364. package/dist/traits/TransactionTrait.d.ts +121 -0
  365. package/dist/traits/botanical-lotus.cjs +54 -50
  366. package/dist/traits/botanical-lotus.js +2 -5
  367. package/dist/traits/control-loop.cjs +21 -0
  368. package/dist/traits/control-loop.d.ts +1 -0
  369. package/dist/traits/control-loop.js +4 -0
  370. package/dist/traits/engines/cloth-verlet.d.ts +65 -0
  371. package/dist/traits/engines/index.cjs +19 -19
  372. package/dist/traits/engines/index.d.ts +15 -275
  373. package/dist/traits/engines/index.js +3 -3
  374. package/dist/traits/engines/motion-data-schema.d.ts +119 -0
  375. package/dist/traits/engines/motion-matching.d.ts +102 -0
  376. package/dist/traits/engines/noise.d.ts +25 -0
  377. package/dist/traits/engines/onnx-adapter.d.ts +173 -0
  378. package/dist/traits/engines/onnx-motion-matching.d.ts +163 -0
  379. package/dist/traits/engines/pfnn-network.d.ts +92 -0
  380. package/dist/traits/engines/synthetic-walk-cycle.d.ts +38 -0
  381. package/dist/traits/engines/tensor-ops.d.ts +15 -0
  382. package/dist/traits/index.cjs +2789 -1259
  383. package/dist/traits/index.d.ts +35 -0
  384. package/dist/traits/index.js +1692 -411
  385. package/dist/traits/kinematic-chain.cjs +25 -0
  386. package/dist/traits/kinematic-chain.d.ts +1 -0
  387. package/dist/traits/kinematic-chain.js +4 -0
  388. package/dist/traits/sensor-sampling.cjs +33 -0
  389. package/dist/traits/sensor-sampling.d.ts +1 -0
  390. package/dist/traits/sensor-sampling.js +4 -0
  391. package/dist/traits/simulation-solver-factory.cjs +1 -1
  392. package/dist/traits/simulation-solver-factory.js +1 -1
  393. package/dist/traits/transaction.cjs +29 -0
  394. package/dist/traits/transaction.d.ts +1 -0
  395. package/dist/traits/transaction.js +4 -0
  396. package/dist/traits/webcam-gaze.cjs +1 -1
  397. package/dist/traits/webcam-gaze.js +1 -1
  398. package/dist/type-checker.cjs +7 -6
  399. package/dist/type-checker.js +5 -4
  400. package/dist/types/AdvancedTypeSystem.d.ts +489 -0
  401. package/dist/types/HoloScriptPlus.d.ts +810 -0
  402. package/dist/types/base.d.ts +248 -0
  403. package/dist/types.d.ts +799 -0
  404. package/dist/world/index.cjs +3 -4
  405. package/dist/world/index.js +3 -4
  406. package/dist/world-model/index.cjs +1 -1
  407. package/dist/world-model/index.js +1 -1
  408. package/dist/wot/index.cjs +1 -1
  409. package/dist/wot/index.js +1 -1
  410. package/package.json +80 -13
  411. package/dist/GLTFPipeline-3EJLL3TS.cjs +0 -38
  412. package/dist/GLTFPipeline-3OWJV2VK.js +0 -17
  413. package/dist/HoloScriptPlusParser-ADWRY5OS.cjs +0 -698
  414. package/dist/HoloScriptPlusParser-JLJDXHSC.js +0 -693
  415. package/dist/HoloScriptPlusParser-QCGFPWIL.cjs +0 -27
  416. package/dist/HoloScriptPlusParser-WENAFEFV.js +0 -10
  417. package/dist/HoloScriptRuntime-GGRVEU4T.cjs +0 -19
  418. package/dist/HoloScriptRuntime-GJK6VJPH.js +0 -10
  419. package/dist/chunk-22Q5A6RV.js +0 -979
  420. package/dist/chunk-4C57PR42.js +0 -468
  421. package/dist/chunk-4W5G5QVL.cjs +0 -847
  422. package/dist/chunk-5ET6L4NS.js +0 -487
  423. package/dist/chunk-C4GSLCHE.cjs +0 -7153
  424. package/dist/chunk-F2G6CWFT.js +0 -7089
  425. package/dist/chunk-G6PNEASF.cjs +0 -814
  426. package/dist/chunk-GTA4Q3A3.js +0 -1491
  427. package/dist/chunk-HCCQLAA4.cjs +0 -74
  428. package/dist/chunk-HFSVMKM3.cjs +0 -72
  429. package/dist/chunk-KAIVDEIG.cjs +0 -4539
  430. package/dist/chunk-KQU64CIX.cjs +0 -1508
  431. package/dist/chunk-MSYSQ2AJ.js +0 -4533
  432. package/dist/chunk-NHJLP37F.js +0 -70
  433. package/dist/chunk-NHYRRAGI.cjs +0 -490
  434. package/dist/chunk-OIQYIIO3.cjs +0 -473
  435. package/dist/chunk-OL46QLBJ.js +0 -61
  436. package/dist/chunk-SKZPC5AG.cjs +0 -984
  437. package/dist/chunk-SLHLXUMO.js +0 -445
  438. package/dist/chunk-UOIGFQXC.cjs +0 -9750
  439. package/dist/chunk-UOL6Y5TD.cjs +0 -759
  440. package/dist/chunk-UVFI7XIR.cjs +0 -452
  441. package/dist/chunk-VEPGBETF.js +0 -844
  442. package/dist/chunk-XQ5MWMP2.js +0 -756
  443. package/dist/chunk-XT6JY5W5.js +0 -9684
  444. package/dist/chunk-YRRAUB35.js +0 -811
  445. package/dist/compiler/GasOptimizationAnalyzer.d.ts +0 -73
  446. package/dist/compiler/NFTMarketplaceCompiler.d.ts +0 -23
  447. package/dist/compiler/ar.cjs +0 -23
  448. package/dist/compiler/ar.js +0 -11
  449. package/dist/compiler/babylon.cjs +0 -21
  450. package/dist/compiler/babylon.js +0 -15
  451. package/dist/compiler/multi-layer.cjs +0 -24
  452. package/dist/compiler/multi-layer.js +0 -15
  453. package/dist/compiler/playcanvas.cjs +0 -19
  454. package/dist/compiler/playcanvas.js +0 -13
  455. package/dist/compiler/r3f.cjs +0 -39
  456. package/dist/compiler/r3f.d.ts +0 -22
  457. package/dist/compiler/r3f.js +0 -17
  458. package/dist/compiler/vrr.cjs +0 -24
  459. package/dist/compiler/vrr.js +0 -12
  460. package/dist/parser/NFTMarketplaceTypes.d.ts +0 -191
  461. package/dist/playwright-3AT3AKTV.cjs +0 -98673
  462. package/dist/playwright-VZPDVUEQ.js +0 -98660
@@ -1,12 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkLM2VU56C_cjs = require('./chunk-LM2VU56C.cjs');
4
- var chunkT6W3Z3SH_cjs = require('./chunk-T6W3Z3SH.cjs');
4
+ var chunkN2ILK7BF_cjs = require('./chunk-N2ILK7BF.cjs');
5
5
 
6
6
  // src/version.ts
7
- var HOLOSCRIPT_VERSION = "8.0.6" ;
8
- var GIT_COMMIT_SHA = "33f2b3e49" ;
9
- var BUILD_TIMESTAMP = "2026-06-08T22:53:19.715Z" ;
7
+ var HOLOSCRIPT_VERSION = "8.0.9" ;
8
+ var GIT_COMMIT_SHA = "67dd1e5dd" ;
9
+ var BUILD_TIMESTAMP = "2026-07-05T21:49:25.063Z" ;
10
10
  function getVersionString() {
11
11
  const sha = `+${GIT_COMMIT_SHA}` ;
12
12
  return `${HOLOSCRIPT_VERSION}${sha}`;
@@ -281,7 +281,7 @@ function createLayerNormKernel(device) {
281
281
  usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC
282
282
  });
283
283
  const paramsBuf = createParamsBuffer(device, rows, dModel, eps);
284
- const readback = device.createBuffer({
284
+ const readback2 = device.createBuffer({
285
285
  size: input.byteLength,
286
286
  usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ
287
287
  });
@@ -303,18 +303,18 @@ function createLayerNormKernel(device) {
303
303
  pass.dispatchWorkgroups(rows, 1, 1);
304
304
  pass.end();
305
305
  }
306
- encoder.copyBufferToBuffer(outputBuf, 0, readback, 0, input.byteLength);
306
+ encoder.copyBufferToBuffer(outputBuf, 0, readback2, 0, input.byteLength);
307
307
  device.queue.submit([encoder.finish()]);
308
- await readback.mapAsync(GPUMapMode.READ);
309
- const bytes = readback.getMappedRange();
308
+ await readback2.mapAsync(GPUMapMode.READ);
309
+ const bytes = readback2.getMappedRange();
310
310
  const out = new Float32Array(bytes.slice(0));
311
- readback.unmap();
311
+ readback2.unmap();
312
312
  inputBuf.destroy();
313
313
  gammaBuf.destroy();
314
314
  betaBuf.destroy();
315
315
  outputBuf.destroy();
316
316
  paramsBuf.destroy();
317
- readback.destroy();
317
+ readback2.destroy();
318
318
  return out;
319
319
  }
320
320
  };
@@ -791,7 +791,7 @@ function createGeluKernel(device) {
791
791
  usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC
792
792
  });
793
793
  const paramsBuf = createParamsBuffer3(device, input.length);
794
- const readback = device.createBuffer({
794
+ const readback2 = device.createBuffer({
795
795
  size: input.byteLength,
796
796
  usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ
797
797
  });
@@ -811,16 +811,16 @@ function createGeluKernel(device) {
811
811
  pass.dispatchWorkgroups(1, 1, 1);
812
812
  pass.end();
813
813
  }
814
- encoder.copyBufferToBuffer(outputBuf, 0, readback, 0, input.byteLength);
814
+ encoder.copyBufferToBuffer(outputBuf, 0, readback2, 0, input.byteLength);
815
815
  device.queue.submit([encoder.finish()]);
816
- await readback.mapAsync(GPUMapMode.READ);
817
- const bytes = readback.getMappedRange();
816
+ await readback2.mapAsync(GPUMapMode.READ);
817
+ const bytes = readback2.getMappedRange();
818
818
  const out = new Float32Array(bytes.slice(0));
819
- readback.unmap();
819
+ readback2.unmap();
820
820
  inputBuf.destroy();
821
821
  outputBuf.destroy();
822
822
  paramsBuf.destroy();
823
- readback.destroy();
823
+ readback2.destroy();
824
824
  return out;
825
825
  }
826
826
  };
@@ -833,6 +833,7 @@ var NUM_HEADS = 4;
833
833
  var HEAD_DIM = 8;
834
834
  var PATCH_LEN = MICRO * MICRO * 3;
835
835
  var weightCache = /* @__PURE__ */ new Map();
836
+ var weightBlobKeyCache = /* @__PURE__ */ new WeakMap();
836
837
  function hashConfigSeed(config) {
837
838
  let h = config.seed >>> 0;
838
839
  const s = config.modelHash || "";
@@ -856,7 +857,99 @@ function fillGaussian2D(out, rng, scale) {
856
857
  function microWeightKey(config) {
857
858
  return `${config.seed}\0${config.modelHash || ""}`;
858
859
  }
860
+ var MICRO_WEIGHT_MAGIC = [72, 77, 87, 49];
861
+ var MICRO_WEIGHT_VERSION = 1;
862
+ var MICRO_WEIGHT_FLOATS = EMBED_DIM * PATCH_LEN + // proj
863
+ 3 * EMBED_DIM * EMBED_DIM + // Wq, Wk, Wv
864
+ EMBED_DIM * 3 + // Wxyz
865
+ 4 * EMBED_DIM;
866
+ var MICRO_WEIGHT_BYTES = 8 + MICRO_WEIGHT_FLOATS * 4;
867
+ function toUint8(bytes) {
868
+ return bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
869
+ }
870
+ function fnv1a(bytes) {
871
+ let h = 2166136261;
872
+ for (let i = 0; i < bytes.length; i += 1) {
873
+ h ^= bytes[i];
874
+ h = Math.imul(h, 16777619);
875
+ }
876
+ return (h >>> 0).toString(16);
877
+ }
878
+ function cachedWeightBlobKey(input) {
879
+ const bytes = toUint8(input);
880
+ const cached = weightBlobKeyCache.get(input);
881
+ if (cached) return { bytes, key: cached };
882
+ const key = `${bytes.byteLength}:${fnv1a(bytes)}`;
883
+ weightBlobKeyCache.set(input, key);
884
+ return { bytes, key };
885
+ }
886
+ function serializeMicroWeights(w) {
887
+ const bytes = new Uint8Array(MICRO_WEIGHT_BYTES);
888
+ bytes.set(MICRO_WEIGHT_MAGIC, 0);
889
+ const view = new DataView(bytes.buffer);
890
+ view.setUint32(4, MICRO_WEIGHT_VERSION, true);
891
+ let off = 8;
892
+ const put = (arr) => {
893
+ for (let i = 0; i < arr.length; i += 1) {
894
+ view.setFloat32(off, arr[i], true);
895
+ off += 4;
896
+ }
897
+ };
898
+ put(w.proj);
899
+ put(w.Wq);
900
+ put(w.Wk);
901
+ put(w.Wv);
902
+ put(w.Wxyz);
903
+ put(w.gamma1);
904
+ put(w.beta1);
905
+ put(w.gamma2);
906
+ put(w.beta2);
907
+ return bytes;
908
+ }
909
+ function deserializeMicroWeights(input) {
910
+ const bytes = toUint8(input);
911
+ if (bytes.byteLength !== MICRO_WEIGHT_BYTES) return null;
912
+ for (let i = 0; i < 4; i += 1) {
913
+ if (bytes[i] !== MICRO_WEIGHT_MAGIC[i]) return null;
914
+ }
915
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
916
+ if (view.getUint32(4, true) !== MICRO_WEIGHT_VERSION) return null;
917
+ let off = 8;
918
+ const take = (count) => {
919
+ const out = new Float32Array(count);
920
+ for (let i = 0; i < count; i += 1) {
921
+ out[i] = view.getFloat32(off, true);
922
+ off += 4;
923
+ }
924
+ return out;
925
+ };
926
+ return {
927
+ proj: take(EMBED_DIM * PATCH_LEN),
928
+ Wq: take(EMBED_DIM * EMBED_DIM),
929
+ Wk: take(EMBED_DIM * EMBED_DIM),
930
+ Wv: take(EMBED_DIM * EMBED_DIM),
931
+ Wxyz: take(EMBED_DIM * 3),
932
+ gamma1: take(EMBED_DIM),
933
+ beta1: take(EMBED_DIM),
934
+ gamma2: take(EMBED_DIM),
935
+ beta2: take(EMBED_DIM)
936
+ };
937
+ }
859
938
  function getMicroWeights(config) {
939
+ if (config.weightBytes) {
940
+ const { bytes: wb, key: blobKey } = cachedWeightBlobKey(config.weightBytes);
941
+ const ckptKey = `${microWeightKey(config)}\0ckpt:${blobKey}`;
942
+ const cachedReal = weightCache.get(ckptKey);
943
+ if (cachedReal) return cachedReal;
944
+ const real = deserializeMicroWeights(wb);
945
+ if (real) {
946
+ weightCache.set(ckptKey, real);
947
+ return real;
948
+ }
949
+ console.warn(
950
+ `[holoMapMicroEncoder] weightBytes present (${wb.byteLength} B) but not a valid HMW1 checkpoint (expected ${MICRO_WEIGHT_BYTES} B + magic) \u2014 falling back to PRNG-synthesized weights.`
951
+ );
952
+ }
860
953
  const key = microWeightKey(config);
861
954
  const cached = weightCache.get(key);
862
955
  if (cached) return cached;
@@ -1449,6 +1542,615 @@ async function putCachedWeightBlob(weightCid, value) {
1449
1542
  }
1450
1543
  }
1451
1544
 
1545
+ // src/reconstruction/holoMapAnchoredManifest.ts
1546
+ function mergeAnchoredProvenance(manifest, urls) {
1547
+ return {
1548
+ ...manifest,
1549
+ provenance: {
1550
+ ...manifest.provenance,
1551
+ anchorHash: urls.anchorHash,
1552
+ opentimestampsProof: urls.opentimestampsProof,
1553
+ baseCalldataTx: urls.baseCalldataTx,
1554
+ capturedAtIso: manifest.provenance.capturedAtIso
1555
+ }
1556
+ };
1557
+ }
1558
+ function stripAnchoredProvenance(manifest) {
1559
+ return {
1560
+ ...manifest,
1561
+ provenance: {
1562
+ capturedAtIso: manifest.provenance.capturedAtIso
1563
+ }
1564
+ };
1565
+ }
1566
+ function selfAttestReconstructionManifest(manifest) {
1567
+ const stripped = stripAnchoredProvenance(manifest);
1568
+ return {
1569
+ ...stripped,
1570
+ provenance: {
1571
+ ...stripped.provenance,
1572
+ anchorHash: `self-attested:${stripped.replayHash}`
1573
+ }
1574
+ };
1575
+ }
1576
+ async function computeReconstructionManifestDigest(manifest) {
1577
+ const canonical = stableStringify(stripAnchoredProvenance(manifest));
1578
+ return `sha256:${await sha256Hex(canonical)}`;
1579
+ }
1580
+ async function anchorReconstructionManifest(manifest, provider) {
1581
+ const stripped = stripAnchoredProvenance(manifest);
1582
+ if (!provider) return selfAttestReconstructionManifest(stripped);
1583
+ const manifestDigest = await computeReconstructionManifestDigest(stripped);
1584
+ const urls = await provider.anchorManifest({
1585
+ manifestDigest,
1586
+ replayHash: stripped.replayHash,
1587
+ replayFingerprint: stripped.simulationContract.replayFingerprint,
1588
+ capturedAtIso: stripped.provenance.capturedAtIso,
1589
+ manifest: stripped
1590
+ });
1591
+ if (!urls) return selfAttestReconstructionManifest(stripped);
1592
+ return mergeAnchoredProvenance(stripped, urls);
1593
+ }
1594
+ function stableStringify(value) {
1595
+ if (value === null || typeof value !== "object") return JSON.stringify(value);
1596
+ if (Array.isArray(value)) return `[${value.map((item) => stableStringify(item)).join(",")}]`;
1597
+ const entries = Object.entries(value).filter(([, entryValue]) => entryValue !== void 0).sort(([a], [b]) => a.localeCompare(b));
1598
+ return `{${entries.map(([key, entryValue]) => `${JSON.stringify(key)}:${stableStringify(entryValue)}`).join(",")}}`;
1599
+ }
1600
+ async function sha256Hex(input) {
1601
+ const bytes = new TextEncoder().encode(input);
1602
+ const subtle = globalThis.crypto?.subtle;
1603
+ if (subtle) {
1604
+ const digest = await subtle.digest("SHA-256", bytes);
1605
+ return Array.from(new Uint8Array(digest)).map((byte) => byte.toString(16).padStart(2, "0")).join("");
1606
+ }
1607
+ const { createHash } = await import('crypto');
1608
+ return createHash("sha256").update(bytes).digest("hex");
1609
+ }
1610
+
1611
+ // src/reconstruction/pagedKVKernels.ts
1612
+ var WGSL_PAGED_KV_APPEND = `
1613
+ struct AppendParams {
1614
+ numVecs: u32, // number of NEW vectors to append
1615
+ headDim: u32, // dimension of each vector
1616
+ pageSize: u32, // vectors per page
1617
+ }
1618
+ // kv_pages: flat storage for all pages. page p, slot s, dim d:
1619
+ // index = pageTable[p] * pageSize * headDim + s * headDim + d
1620
+ @group(0) @binding(0) var<storage, read> newVecs: array<f32>; // [numVecs * headDim]
1621
+ @group(0) @binding(1) var<storage, read> pageTable: array<u32>; // logical page \u2192 base offset in kv_pages (in elements)
1622
+ @group(0) @binding(2) var<storage, read> slotMap: array<u32>; // per-vector: (logicalPage << 16 | slotInPage)
1623
+ @group(0) @binding(3) var<storage, read_write> kvPages: array<f32>; // output KV store
1624
+ @group(0) @binding(4) var<uniform> p: AppendParams;
1625
+ @compute @workgroup_size(64, 1, 1)
1626
+ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
1627
+ // gid.x spans numVecs * headDim
1628
+ let total = p.numVecs * p.headDim;
1629
+ if (gid.x >= total) { return; }
1630
+ let vecIdx = gid.x / p.headDim;
1631
+ let dimIdx = gid.x % p.headDim;
1632
+ let slot = slotMap[vecIdx];
1633
+ let logPage = slot >> 16u;
1634
+ let inPage = slot & 0xFFFFu;
1635
+ let base = pageTable[logPage] * p.pageSize * p.headDim;
1636
+ kvPages[base + inPage * p.headDim + dimIdx] = newVecs[vecIdx * p.headDim + dimIdx];
1637
+ }
1638
+ `;
1639
+ var WGSL_PAGED_KV_LOOKUP = `
1640
+ struct LookupParams {
1641
+ numVecs: u32, // number of vectors to read
1642
+ headDim: u32,
1643
+ pageSize: u32,
1644
+ startSlot: u32, // logical first slot (token offset)
1645
+ }
1646
+ @group(0) @binding(0) var<storage, read> kvPages: array<f32>;
1647
+ @group(0) @binding(1) var<storage, read> pageTable: array<u32>; // logical page \u2192 base offset (in elements)
1648
+ @group(0) @binding(2) var<storage, read_write> out: array<f32>; // [numVecs * headDim]
1649
+ @group(0) @binding(3) var<uniform> p: LookupParams;
1650
+ @compute @workgroup_size(64, 1, 1)
1651
+ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
1652
+ let total = p.numVecs * p.headDim;
1653
+ if (gid.x >= total) { return; }
1654
+ let vecIdx = gid.x / p.headDim;
1655
+ let dimIdx = gid.x % p.headDim;
1656
+ let logSlot = (vecIdx + p.startSlot);
1657
+ let logPage = logSlot / p.pageSize;
1658
+ let inPage = logSlot % p.pageSize;
1659
+ let base = pageTable[logPage] * p.pageSize * p.headDim;
1660
+ out[gid.x] = kvPages[base + inPage * p.headDim + dimIdx];
1661
+ }
1662
+ `;
1663
+ function storageBuffer4(device, data) {
1664
+ const buf = device.createBuffer({
1665
+ size: data.byteLength,
1666
+ usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST
1667
+ });
1668
+ device.queue.writeBuffer(buf, 0, data.buffer, data.byteOffset, data.byteLength);
1669
+ return buf;
1670
+ }
1671
+ function outputBuffer(device, bytes) {
1672
+ return device.createBuffer({
1673
+ size: bytes,
1674
+ usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC
1675
+ });
1676
+ }
1677
+ function uniformBuffer(device, data) {
1678
+ const buf = device.createBuffer({
1679
+ size: data.byteLength,
1680
+ usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
1681
+ });
1682
+ device.queue.writeBuffer(buf, 0, data);
1683
+ return buf;
1684
+ }
1685
+ async function readback(device, src, bytes) {
1686
+ const staging = device.createBuffer({
1687
+ size: bytes,
1688
+ usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST
1689
+ });
1690
+ const enc = device.createCommandEncoder();
1691
+ enc.copyBufferToBuffer(src, 0, staging, 0, bytes);
1692
+ device.queue.submit([enc.finish()]);
1693
+ await staging.mapAsync(GPUMapMode.READ);
1694
+ const result = new Float32Array(staging.getMappedRange().slice(0));
1695
+ staging.unmap();
1696
+ staging.destroy();
1697
+ return result;
1698
+ }
1699
+ function createPagedKVAppendKernel(device) {
1700
+ const shader = device.createShaderModule({ code: WGSL_PAGED_KV_APPEND });
1701
+ const pipeline = device.createComputePipeline({
1702
+ layout: "auto",
1703
+ compute: { module: shader, entryPoint: "main" }
1704
+ });
1705
+ return {
1706
+ async run(kvPagesData, pageTableData, slotMapData, newVectors, pageSize, headDim) {
1707
+ const numVecs = newVectors.length / headDim;
1708
+ const kvBuf = device.createBuffer({
1709
+ size: kvPagesData.byteLength,
1710
+ usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC
1711
+ });
1712
+ device.queue.writeBuffer(
1713
+ kvBuf,
1714
+ 0,
1715
+ kvPagesData.buffer,
1716
+ kvPagesData.byteOffset,
1717
+ kvPagesData.byteLength
1718
+ );
1719
+ const newVecsBuf = storageBuffer4(device, newVectors);
1720
+ const pageTableBuf = storageBuffer4(device, pageTableData);
1721
+ const slotMapBuf = storageBuffer4(device, slotMapData);
1722
+ const paramAB = new ArrayBuffer(16);
1723
+ new Uint32Array(paramAB)[0] = numVecs;
1724
+ new Uint32Array(paramAB)[1] = headDim;
1725
+ new Uint32Array(paramAB)[2] = pageSize;
1726
+ const paramsBuf = uniformBuffer(device, paramAB);
1727
+ const bg = device.createBindGroup({
1728
+ layout: pipeline.getBindGroupLayout(0),
1729
+ entries: [
1730
+ { binding: 0, resource: { buffer: newVecsBuf } },
1731
+ { binding: 1, resource: { buffer: pageTableBuf } },
1732
+ { binding: 2, resource: { buffer: slotMapBuf } },
1733
+ { binding: 3, resource: { buffer: kvBuf } },
1734
+ { binding: 4, resource: { buffer: paramsBuf } }
1735
+ ]
1736
+ });
1737
+ const total = numVecs * headDim;
1738
+ const workgroups = Math.ceil(total / 64);
1739
+ const enc = device.createCommandEncoder();
1740
+ const pass = enc.beginComputePass();
1741
+ pass.setPipeline(pipeline);
1742
+ pass.setBindGroup(0, bg);
1743
+ pass.dispatchWorkgroups(workgroups);
1744
+ pass.end();
1745
+ device.queue.submit([enc.finish()]);
1746
+ const result = await readback(device, kvBuf, kvPagesData.byteLength);
1747
+ newVecsBuf.destroy();
1748
+ pageTableBuf.destroy();
1749
+ slotMapBuf.destroy();
1750
+ kvBuf.destroy();
1751
+ paramsBuf.destroy();
1752
+ return result;
1753
+ }
1754
+ };
1755
+ }
1756
+ function createPagedKVLookupKernel(device) {
1757
+ const shader = device.createShaderModule({ code: WGSL_PAGED_KV_LOOKUP });
1758
+ const pipeline = device.createComputePipeline({
1759
+ layout: "auto",
1760
+ compute: { module: shader, entryPoint: "main" }
1761
+ });
1762
+ return {
1763
+ async run(kvPagesData, pageTableData, numVecs, startSlot, pageSize, headDim) {
1764
+ const outBytes = numVecs * headDim * 4;
1765
+ const kvBuf = storageBuffer4(device, kvPagesData);
1766
+ const pageTableBuf = storageBuffer4(device, pageTableData);
1767
+ const outBuf = outputBuffer(device, outBytes);
1768
+ const paramAB = new ArrayBuffer(16);
1769
+ const pu = new Uint32Array(paramAB);
1770
+ pu[0] = numVecs;
1771
+ pu[1] = headDim;
1772
+ pu[2] = pageSize;
1773
+ pu[3] = startSlot;
1774
+ const paramsBuf = uniformBuffer(device, paramAB);
1775
+ const bg = device.createBindGroup({
1776
+ layout: pipeline.getBindGroupLayout(0),
1777
+ entries: [
1778
+ { binding: 0, resource: { buffer: kvBuf } },
1779
+ { binding: 1, resource: { buffer: pageTableBuf } },
1780
+ { binding: 2, resource: { buffer: outBuf } },
1781
+ { binding: 3, resource: { buffer: paramsBuf } }
1782
+ ]
1783
+ });
1784
+ const total = numVecs * headDim;
1785
+ const enc = device.createCommandEncoder();
1786
+ const pass = enc.beginComputePass();
1787
+ pass.setPipeline(pipeline);
1788
+ pass.setBindGroup(0, bg);
1789
+ pass.dispatchWorkgroups(Math.ceil(total / 64));
1790
+ pass.end();
1791
+ device.queue.submit([enc.finish()]);
1792
+ const result = await readback(device, outBuf, outBytes);
1793
+ kvBuf.destroy();
1794
+ pageTableBuf.destroy();
1795
+ outBuf.destroy();
1796
+ paramsBuf.destroy();
1797
+ return result;
1798
+ }
1799
+ };
1800
+ }
1801
+
1802
+ // src/reconstruction/PagedKVCache.ts
1803
+ var PAGE_TABLE_EMPTY = 4294967295;
1804
+ function createPagedKVCache(config) {
1805
+ validateConfig(config);
1806
+ const layers = Array.from({ length: config.numLayers }, () => ({
1807
+ pages: /* @__PURE__ */ new Map(),
1808
+ nextToken: 0
1809
+ }));
1810
+ const pageBytes = config.pageSize * config.hiddenDim * Float32Array.BYTES_PER_ELEMENT;
1811
+ const keyPages = new Float32Array(config.maxResidentPages * config.pageSize * config.hiddenDim);
1812
+ const valuePages = new Float32Array(config.maxResidentPages * config.pageSize * config.hiddenDim);
1813
+ const freePhysicalPages = Array.from({ length: config.maxResidentPages }, (_, i) => i).reverse();
1814
+ const appendKernel = config.device ? createPagedKVAppendKernel(config.device) : null;
1815
+ const lookupKernel = config.device ? createPagedKVLookupKernel(config.device) : null;
1816
+ let disposed = false;
1817
+ let nextPageId = 0;
1818
+ let accessClock = 0;
1819
+ function assertLive() {
1820
+ if (disposed) throw new Error("PagedKVCache has been disposed.");
1821
+ }
1822
+ function validateLayer(layer) {
1823
+ if (!Number.isInteger(layer) || layer < 0 || layer >= config.numLayers) {
1824
+ throw new Error(`PagedKVCache layer ${layer} out of range 0..${config.numLayers - 1}`);
1825
+ }
1826
+ }
1827
+ function pageSnapshot(page) {
1828
+ return {
1829
+ pageId: page.pageId,
1830
+ layer: page.layer,
1831
+ residency: page.residency,
1832
+ firstToken: page.firstToken,
1833
+ lastToken: page.lastToken
1834
+ };
1835
+ }
1836
+ function pageOffset(physicalPage) {
1837
+ return physicalPage * config.pageSize * config.hiddenDim;
1838
+ }
1839
+ function copyResidentPage(page, keys, values) {
1840
+ if (page.physicalPage === null) return;
1841
+ const offset = pageOffset(page.physicalPage);
1842
+ const end = offset + config.pageSize * config.hiddenDim;
1843
+ keys.set(keyPages.subarray(offset, end));
1844
+ values.set(valuePages.subarray(offset, end));
1845
+ }
1846
+ function zeroPhysicalPage(physicalPage) {
1847
+ const offset = pageOffset(physicalPage);
1848
+ const end = offset + config.pageSize * config.hiddenDim;
1849
+ keyPages.fill(0, offset, end);
1850
+ valuePages.fill(0, offset, end);
1851
+ }
1852
+ function residentPages() {
1853
+ return layers.flatMap(
1854
+ (layer) => Array.from(layer.pages.values()).filter((page) => page.residency === "device")
1855
+ );
1856
+ }
1857
+ function evictPage(page) {
1858
+ if (page.physicalPage === null) return pageSnapshot(page);
1859
+ const hostKeys = new Float32Array(config.pageSize * config.hiddenDim);
1860
+ const hostValues = new Float32Array(config.pageSize * config.hiddenDim);
1861
+ copyResidentPage(page, hostKeys, hostValues);
1862
+ zeroPhysicalPage(page.physicalPage);
1863
+ freePhysicalPages.push(page.physicalPage);
1864
+ page.physicalPage = null;
1865
+ page.hostKeys = hostKeys;
1866
+ page.hostValues = hostValues;
1867
+ page.residency = "host";
1868
+ return pageSnapshot(page);
1869
+ }
1870
+ function evictOldestInternal(count, protectedPage) {
1871
+ if (count <= 0) return [];
1872
+ const victims = residentPages().filter((page) => page !== protectedPage).sort((a, b) => a.lastAccess - b.lastAccess).slice(0, count);
1873
+ return victims.map((page) => evictPage(page));
1874
+ }
1875
+ function allocatePhysicalPage(protectedPage) {
1876
+ if (freePhysicalPages.length === 0) {
1877
+ evictOldestInternal(1, protectedPage);
1878
+ }
1879
+ const physicalPage = freePhysicalPages.pop();
1880
+ if (physicalPage === void 0) {
1881
+ throw new Error("PagedKVCache could not allocate a resident page.");
1882
+ }
1883
+ zeroPhysicalPage(physicalPage);
1884
+ return physicalPage;
1885
+ }
1886
+ function ensurePageResident(page) {
1887
+ if (page.residency === "device" && page.physicalPage !== null) {
1888
+ page.lastAccess = ++accessClock;
1889
+ return;
1890
+ }
1891
+ const physicalPage = allocatePhysicalPage(page);
1892
+ page.physicalPage = physicalPage;
1893
+ page.residency = "device";
1894
+ page.lastAccess = ++accessClock;
1895
+ if (page.hostKeys) {
1896
+ keyPages.set(page.hostKeys, pageOffset(physicalPage));
1897
+ page.hostKeys = void 0;
1898
+ }
1899
+ if (page.hostValues) {
1900
+ valuePages.set(page.hostValues, pageOffset(physicalPage));
1901
+ page.hostValues = void 0;
1902
+ }
1903
+ }
1904
+ function allocatePageInternal(layer, logicalPage) {
1905
+ const layerState = layers[layer];
1906
+ const existing = layerState.pages.get(logicalPage);
1907
+ if (existing) {
1908
+ ensurePageResident(existing);
1909
+ return existing;
1910
+ }
1911
+ const physicalPage = allocatePhysicalPage();
1912
+ const page = {
1913
+ pageId: nextPageId++,
1914
+ logicalPage,
1915
+ layer,
1916
+ residency: "device",
1917
+ firstToken: logicalPage * config.pageSize,
1918
+ lastToken: logicalPage * config.pageSize + config.pageSize - 1,
1919
+ physicalPage,
1920
+ lastAccess: ++accessClock
1921
+ };
1922
+ layerState.pages.set(logicalPage, page);
1923
+ return page;
1924
+ }
1925
+ function buildPageTable(layer, logicalPages) {
1926
+ const requiredPages = Array.from(new Set(logicalPages)).sort((a, b) => a - b);
1927
+ const maxLogicalPage = requiredPages[requiredPages.length - 1] ?? 0;
1928
+ const pageTable = new Uint32Array(maxLogicalPage + 1);
1929
+ pageTable.fill(PAGE_TABLE_EMPTY);
1930
+ const layerState = layers[layer];
1931
+ for (const logicalPage of requiredPages) {
1932
+ const page = layerState.pages.get(logicalPage);
1933
+ if (page) {
1934
+ ensurePageResident(page);
1935
+ pageTable[logicalPage] = page.physicalPage ?? PAGE_TABLE_EMPTY;
1936
+ }
1937
+ }
1938
+ return pageTable;
1939
+ }
1940
+ function appendCpu(pages, pageTable, slotMap, vectors) {
1941
+ const out = new Float32Array(pages);
1942
+ const numVecs = vectors.length / config.hiddenDim;
1943
+ for (let v = 0; v < numVecs; v += 1) {
1944
+ const logicalPage = slotMap[v] >>> 16;
1945
+ const inPage = slotMap[v] & 65535;
1946
+ const physicalPage = pageTable[logicalPage];
1947
+ const base = physicalPage * config.pageSize * config.hiddenDim;
1948
+ for (let d = 0; d < config.hiddenDim; d += 1) {
1949
+ out[base + inPage * config.hiddenDim + d] = vectors[v * config.hiddenDim + d];
1950
+ }
1951
+ }
1952
+ return out;
1953
+ }
1954
+ function lookupCpu(pages, pageTable, tokenCount, startToken) {
1955
+ const out = new Float32Array(tokenCount * config.hiddenDim);
1956
+ for (let v = 0; v < tokenCount; v += 1) {
1957
+ const logicalSlot = startToken + v;
1958
+ const logicalPage = Math.floor(logicalSlot / config.pageSize);
1959
+ const inPage = logicalSlot % config.pageSize;
1960
+ const physicalPage = pageTable[logicalPage];
1961
+ const base = physicalPage * config.pageSize * config.hiddenDim;
1962
+ for (let d = 0; d < config.hiddenDim; d += 1) {
1963
+ out[v * config.hiddenDim + d] = pages[base + inPage * config.hiddenDim + d];
1964
+ }
1965
+ }
1966
+ return out;
1967
+ }
1968
+ return {
1969
+ config,
1970
+ allocatePage(layer, firstToken) {
1971
+ assertLive();
1972
+ validateLayer(layer);
1973
+ if (!Number.isInteger(firstToken) || firstToken < 0) {
1974
+ throw new Error(`PagedKVCache firstToken must be a non-negative integer, got ${firstToken}`);
1975
+ }
1976
+ const logicalPage = Math.floor(firstToken / config.pageSize);
1977
+ return pageSnapshot(allocatePageInternal(layer, logicalPage));
1978
+ },
1979
+ residentPagesForLayer(layer) {
1980
+ assertLive();
1981
+ validateLayer(layer);
1982
+ return Array.from(layers[layer].pages.values()).filter((page) => page.residency === "device").sort((a, b) => a.firstToken - b.firstToken).map((page) => pageSnapshot(page));
1983
+ },
1984
+ evictOldest(count) {
1985
+ assertLive();
1986
+ if (!Number.isInteger(count) || count < 0) {
1987
+ throw new Error(`PagedKVCache evict count must be a non-negative integer, got ${count}`);
1988
+ }
1989
+ return evictOldestInternal(count);
1990
+ },
1991
+ memoryUsage() {
1992
+ assertLive();
1993
+ let devicePages = 0;
1994
+ let hostPages = 0;
1995
+ for (const layer of layers) {
1996
+ for (const page of layer.pages.values()) {
1997
+ if (page.residency === "device") devicePages += 1;
1998
+ if (page.residency === "host") hostPages += 1;
1999
+ }
2000
+ }
2001
+ return {
2002
+ device: devicePages * pageBytes * 2,
2003
+ host: hostPages * pageBytes * 2
2004
+ };
2005
+ },
2006
+ async dispose() {
2007
+ disposed = true;
2008
+ for (const layer of layers) layer.pages.clear();
2009
+ freePhysicalPages.length = 0;
2010
+ },
2011
+ async append(layer, keyVectors, valueVectors = keyVectors, firstToken) {
2012
+ assertLive();
2013
+ validateLayer(layer);
2014
+ if (keyVectors.length !== valueVectors.length) {
2015
+ throw new Error("PagedKVCache append requires key/value vectors with equal length.");
2016
+ }
2017
+ if (keyVectors.length % config.hiddenDim !== 0) {
2018
+ throw new Error(
2019
+ `PagedKVCache append vector length ${keyVectors.length} is not divisible by hiddenDim=${config.hiddenDim}`
2020
+ );
2021
+ }
2022
+ const tokenCount = keyVectors.length / config.hiddenDim;
2023
+ if (tokenCount === 0) return [];
2024
+ const startToken = firstToken ?? layers[layer].nextToken;
2025
+ if (!Number.isInteger(startToken) || startToken < 0) {
2026
+ throw new Error(`PagedKVCache append firstToken must be non-negative, got ${startToken}`);
2027
+ }
2028
+ const touchedPages = /* @__PURE__ */ new Map();
2029
+ const slotMap = new Uint32Array(tokenCount);
2030
+ const requiredPages = /* @__PURE__ */ new Set();
2031
+ for (let i = 0; i < tokenCount; i += 1) {
2032
+ const token = startToken + i;
2033
+ const logicalPage = Math.floor(token / config.pageSize);
2034
+ const slot = token % config.pageSize;
2035
+ requiredPages.add(logicalPage);
2036
+ slotMap[i] = logicalPage << 16 | slot;
2037
+ }
2038
+ if (requiredPages.size > config.maxResidentPages) {
2039
+ throw new Error(
2040
+ `PagedKVCache append touches ${requiredPages.size} pages but only ${config.maxResidentPages} can be resident.`
2041
+ );
2042
+ }
2043
+ for (const logicalPage of requiredPages) {
2044
+ const page = allocatePageInternal(layer, logicalPage);
2045
+ touchedPages.set(logicalPage, page);
2046
+ }
2047
+ const pageTable = buildPageTable(layer, touchedPages.keys());
2048
+ if (appendKernel) {
2049
+ keyPages.set(
2050
+ await appendKernel.run(
2051
+ keyPages,
2052
+ pageTable,
2053
+ slotMap,
2054
+ keyVectors,
2055
+ config.pageSize,
2056
+ config.hiddenDim
2057
+ )
2058
+ );
2059
+ valuePages.set(
2060
+ await appendKernel.run(
2061
+ valuePages,
2062
+ pageTable,
2063
+ slotMap,
2064
+ valueVectors,
2065
+ config.pageSize,
2066
+ config.hiddenDim
2067
+ )
2068
+ );
2069
+ } else {
2070
+ keyPages.set(appendCpu(keyPages, pageTable, slotMap, keyVectors));
2071
+ valuePages.set(appendCpu(valuePages, pageTable, slotMap, valueVectors));
2072
+ }
2073
+ for (const page of touchedPages.values()) page.lastAccess = ++accessClock;
2074
+ layers[layer].nextToken = Math.max(layers[layer].nextToken, startToken + tokenCount);
2075
+ return Array.from(touchedPages.values()).sort((a, b) => a.firstToken - b.firstToken).map((page) => pageSnapshot(page));
2076
+ },
2077
+ async lookup(layer, startToken, tokenCount) {
2078
+ assertLive();
2079
+ validateLayer(layer);
2080
+ if (!Number.isInteger(startToken) || startToken < 0) {
2081
+ throw new Error(`PagedKVCache lookup startToken must be non-negative, got ${startToken}`);
2082
+ }
2083
+ if (!Number.isInteger(tokenCount) || tokenCount < 0) {
2084
+ throw new Error(`PagedKVCache lookup tokenCount must be non-negative, got ${tokenCount}`);
2085
+ }
2086
+ if (tokenCount === 0) {
2087
+ return { keys: new Float32Array(), values: new Float32Array() };
2088
+ }
2089
+ const endToken = startToken + tokenCount - 1;
2090
+ const firstLogicalPage = Math.floor(startToken / config.pageSize);
2091
+ const maxLogicalPage = Math.floor(endToken / config.pageSize);
2092
+ const requiredPages = [];
2093
+ for (let logicalPage = firstLogicalPage; logicalPage <= maxLogicalPage; logicalPage += 1) {
2094
+ const page = layers[layer].pages.get(logicalPage);
2095
+ if (!page) {
2096
+ throw new Error(`PagedKVCache lookup misses layer ${layer} logical page ${logicalPage}.`);
2097
+ }
2098
+ requiredPages.push(logicalPage);
2099
+ }
2100
+ if (requiredPages.length > config.maxResidentPages) {
2101
+ throw new Error(
2102
+ `PagedKVCache lookup needs ${requiredPages.length} pages but only ${config.maxResidentPages} can be resident.`
2103
+ );
2104
+ }
2105
+ for (const logicalPage of requiredPages) {
2106
+ ensurePageResident(layers[layer].pages.get(logicalPage));
2107
+ }
2108
+ const pageTable = buildPageTable(layer, requiredPages);
2109
+ if (lookupKernel) {
2110
+ return {
2111
+ keys: await lookupKernel.run(
2112
+ keyPages,
2113
+ pageTable,
2114
+ tokenCount,
2115
+ startToken,
2116
+ config.pageSize,
2117
+ config.hiddenDim
2118
+ ),
2119
+ values: await lookupKernel.run(
2120
+ valuePages,
2121
+ pageTable,
2122
+ tokenCount,
2123
+ startToken,
2124
+ config.pageSize,
2125
+ config.hiddenDim
2126
+ )
2127
+ };
2128
+ }
2129
+ return {
2130
+ keys: lookupCpu(keyPages, pageTable, tokenCount, startToken),
2131
+ values: lookupCpu(valuePages, pageTable, tokenCount, startToken)
2132
+ };
2133
+ }
2134
+ };
2135
+ }
2136
+ function validateConfig(config) {
2137
+ const fields = [
2138
+ ["pageSize", config.pageSize],
2139
+ ["maxResidentPages", config.maxResidentPages],
2140
+ ["hiddenDim", config.hiddenDim],
2141
+ ["numHeads", config.numHeads],
2142
+ ["numLayers", config.numLayers]
2143
+ ];
2144
+ for (const [field, value] of fields) {
2145
+ if (!Number.isInteger(value) || value <= 0) {
2146
+ throw new Error(`PagedKVCache config ${String(field)} must be a positive integer.`);
2147
+ }
2148
+ }
2149
+ if (config.pageSize > 65535) {
2150
+ throw new Error("PagedKVCache pageSize must fit the 16-bit slot packing used by WGSL kernels.");
2151
+ }
2152
+ }
2153
+
1452
2154
  // src/reconstruction/HoloMapRuntime.ts
1453
2155
  var HOLOMAP_DEFAULTS = {
1454
2156
  inputResolution: { width: 518, height: 378 },
@@ -1459,8 +2161,14 @@ var HOLOMAP_DEFAULTS = {
1459
2161
  tileGrid: 4,
1460
2162
  cpuOffload: false,
1461
2163
  weightStrategy: "distill",
2164
+ reconstructionMode: "preview",
1462
2165
  allowCpuFallback: true
1463
2166
  };
2167
+ var HOLOMAP_DENSE_PROOF_DEFAULTS = {
2168
+ ...HOLOMAP_DEFAULTS,
2169
+ tileGrid: 16,
2170
+ reconstructionMode: "dense-proof"
2171
+ };
1464
2172
  var _HoloMapRuntimeImpl = class _HoloMapRuntimeImpl {
1465
2173
  constructor() {
1466
2174
  this.config = { ...HOLOMAP_DEFAULTS };
@@ -1472,6 +2180,10 @@ var _HoloMapRuntimeImpl = class _HoloMapRuntimeImpl {
1472
2180
  this.microEncoder = null;
1473
2181
  /** Loaded weight blob (optional; GPU upload wiring follows R3+). */
1474
2182
  this.weightBytes = null;
2183
+ this.weightVerified = false;
2184
+ this.weightSource = null;
2185
+ this.streamingKVCache = null;
2186
+ this.streamingKVNextToken = 0;
1475
2187
  // ── Sprint-3 performance / determinism state ──
1476
2188
  /** Running bounding box (updated incrementally per step). */
1477
2189
  this.boundsMin = [0, 0, 0];
@@ -1524,6 +2236,131 @@ var _HoloMapRuntimeImpl = class _HoloMapRuntimeImpl {
1524
2236
  const v = depth[py * width + px];
1525
2237
  return Number.isFinite(v) ? Math.min(1, Math.max(0, v)) : 0.5;
1526
2238
  }
2239
+ static sampleMetricDepthNearestUv(depthMeters, width, height, uv) {
2240
+ const px = Math.min(width - 1, Math.max(0, Math.round(uv[0] * (width - 1))));
2241
+ const py = Math.min(height - 1, Math.max(0, Math.round(uv[1] * (height - 1))));
2242
+ const v = depthMeters[py * width + px];
2243
+ return Number.isFinite(v) && v > 0 ? v : void 0;
2244
+ }
2245
+ static hasUsableIntrinsics(intrinsics) {
2246
+ return !!intrinsics && Number.isFinite(intrinsics.width) && Number.isFinite(intrinsics.height) && Number.isFinite(intrinsics.fx) && Number.isFinite(intrinsics.fy) && Number.isFinite(intrinsics.cx) && Number.isFinite(intrinsics.cy) && intrinsics.width > 0 && intrinsics.height > 0 && intrinsics.fx > 0 && intrinsics.fy > 0;
2247
+ }
2248
+ static normalizeQuaternion(q) {
2249
+ const len = Math.hypot(q[0], q[1], q[2], q[3]);
2250
+ if (len <= 1e-12) return [0, 0, 0, 1];
2251
+ return [q[0] / len, q[1] / len, q[2] / len, q[3] / len];
2252
+ }
2253
+ static rotateByQuaternion(v, q) {
2254
+ const [x, y, z, w] = _HoloMapRuntimeImpl.normalizeQuaternion(q);
2255
+ const [vx, vy, vz] = v;
2256
+ const tx = 2 * (y * vz - z * vy);
2257
+ const ty = 2 * (z * vx - x * vz);
2258
+ const tz = 2 * (x * vy - y * vx);
2259
+ return [
2260
+ vx + w * tx + (y * tz - z * ty),
2261
+ vy + w * ty + (z * tx - x * tz),
2262
+ vz + w * tz + (x * ty - y * tx)
2263
+ ];
2264
+ }
2265
+ static projectMetricDepthToWorld(uv, depthMeters, intrinsics, pose) {
2266
+ const pixelX = uv[0] * intrinsics.width;
2267
+ const pixelY = uv[1] * intrinsics.height;
2268
+ const local = [
2269
+ (pixelX - intrinsics.cx) * depthMeters / intrinsics.fx,
2270
+ (intrinsics.cy - pixelY) * depthMeters / intrinsics.fy,
2271
+ -depthMeters
2272
+ ];
2273
+ if (!pose) return local;
2274
+ const rotated = _HoloMapRuntimeImpl.rotateByQuaternion(local, pose.rotation);
2275
+ return [
2276
+ pose.position[0] + rotated[0],
2277
+ pose.position[1] + rotated[1],
2278
+ pose.position[2] + rotated[2]
2279
+ ];
2280
+ }
2281
+ static fitShiftScaleDepth(samples) {
2282
+ const paired = samples.filter((sample) => sample.metricDepthMeters !== void 0).map((sample) => ({
2283
+ x: sample.rawDepthSignal,
2284
+ y: sample.metricDepthMeters
2285
+ }));
2286
+ if (paired.length === 0) return void 0;
2287
+ let meanX = 0;
2288
+ let meanY = 0;
2289
+ for (const sample of paired) {
2290
+ meanX += sample.x;
2291
+ meanY += sample.y;
2292
+ }
2293
+ meanX /= paired.length;
2294
+ meanY /= paired.length;
2295
+ let varianceX = 0;
2296
+ let covariance = 0;
2297
+ for (const sample of paired) {
2298
+ const dx = sample.x - meanX;
2299
+ varianceX += dx * dx;
2300
+ covariance += dx * (sample.y - meanY);
2301
+ }
2302
+ const scale = varianceX > 1e-12 ? covariance / varianceX : 0;
2303
+ const shift = meanY - scale * meanX;
2304
+ let squared = 0;
2305
+ for (const sample of paired) {
2306
+ const err = scale * sample.x + shift - sample.y;
2307
+ squared += err * err;
2308
+ }
2309
+ return {
2310
+ kind: "shift-scale",
2311
+ sampleCount: paired.length,
2312
+ scale,
2313
+ shift,
2314
+ rmseMeters: Math.sqrt(squared / paired.length)
2315
+ };
2316
+ }
2317
+ static alignedDepthMeters(sample, fit) {
2318
+ if (fit) {
2319
+ const aligned = fit.scale * sample.rawDepthSignal + fit.shift;
2320
+ if (Number.isFinite(aligned) && aligned > 0) return aligned;
2321
+ }
2322
+ return sample.metricDepthMeters;
2323
+ }
2324
+ static buildLoopClosureDescriptor(samples) {
2325
+ if (samples.length === 0) return new Float32Array([0, 0, 0, 0, 0, 0]);
2326
+ let r = 0;
2327
+ let g = 0;
2328
+ let b = 0;
2329
+ let luma = 0;
2330
+ let texture = 0;
2331
+ let depth = 0;
2332
+ let depthCount = 0;
2333
+ for (const sample of samples) {
2334
+ r += sample.meanColor[0] / 255;
2335
+ g += sample.meanColor[1] / 255;
2336
+ b += sample.meanColor[2] / 255;
2337
+ luma += sample.luminance;
2338
+ texture += sample.texture;
2339
+ if (sample.metricDepthMeters !== void 0) {
2340
+ depth += Math.min(1, sample.metricDepthMeters / 10);
2341
+ depthCount += 1;
2342
+ }
2343
+ }
2344
+ const inv = 1 / samples.length;
2345
+ return new Float32Array([
2346
+ r * inv,
2347
+ g * inv,
2348
+ b * inv,
2349
+ luma * inv,
2350
+ texture * inv,
2351
+ depthCount > 0 ? depth / depthCount : 0
2352
+ ]);
2353
+ }
2354
+ static descriptorDistance(a, b) {
2355
+ const n = Math.min(a.length, b.length);
2356
+ if (n === 0) return Number.POSITIVE_INFINITY;
2357
+ let squared = 0;
2358
+ for (let i = 0; i < n; i += 1) {
2359
+ const d = (a[i] ?? 0) - (b[i] ?? 0);
2360
+ squared += d * d;
2361
+ }
2362
+ return Math.sqrt(squared / n);
2363
+ }
1527
2364
  static computeBounds(steps) {
1528
2365
  if (steps.length === 0) {
1529
2366
  return {
@@ -1597,6 +2434,10 @@ var _HoloMapRuntimeImpl = class _HoloMapRuntimeImpl {
1597
2434
  }
1598
2435
  return _HoloMapRuntimeImpl.computeBounds(this.steps);
1599
2436
  }
2437
+ static *retainedPositionChunks(steps, current) {
2438
+ for (const step of steps) yield step.points.positions;
2439
+ yield current;
2440
+ }
1600
2441
  static estimatePrincipalAxisRotation(chunks, centroid) {
1601
2442
  let xx = 0;
1602
2443
  let zz = 0;
@@ -1670,10 +2511,22 @@ var _HoloMapRuntimeImpl = class _HoloMapRuntimeImpl {
1670
2511
  }
1671
2512
  }
1672
2513
  async init(config) {
1673
- this.config = { ...config };
2514
+ this.config = {
2515
+ ...config,
2516
+ reconstructionMode: config.reconstructionMode ?? "preview"
2517
+ };
2518
+ if (this.config.reconstructionMode === "dense-proof") {
2519
+ this.config.tileGrid = Math.max(
2520
+ this.config.tileGrid ?? _HoloMapRuntimeImpl.GRID_N,
2521
+ _HoloMapRuntimeImpl.DENSE_PROOF_GRID_N
2522
+ );
2523
+ }
1674
2524
  this.config.tileGrid = _HoloMapRuntimeImpl.normalizeTileGrid(this.config.tileGrid);
2525
+ if (this.config.reconstructionMode === "dense-proof") {
2526
+ _HoloMapRuntimeImpl.assertDenseProofConfig(this.config);
2527
+ }
1675
2528
  const allowCpu = this.config.allowCpuFallback !== false;
1676
- if (!allowCpu && !chunkT6W3Z3SH_cjs.isWebGpuEnvironmentPresent()) {
2529
+ if (!allowCpu && !chunkN2ILK7BF_cjs.isWebGpuEnvironmentPresent()) {
1677
2530
  const err = "HoloMap: native reconstruction requires WebGPU (allowCpuFallback=false). Run in a WebGPU-capable browser, or set allowCpuFallback=true for CPU fallback, or use compatibility scene ingest (Marble) for headless benchmarks.";
1678
2531
  logHoloMapEvent(this.runId, "error", { message: err });
1679
2532
  throw new Error(err);
@@ -1711,25 +2564,56 @@ var _HoloMapRuntimeImpl = class _HoloMapRuntimeImpl {
1711
2564
  verticalProfile: this.config.verticalProfile
1712
2565
  });
1713
2566
  this.weightBytes = null;
1714
- if (this.config.weightUrl) {
2567
+ this.weightVerified = false;
2568
+ this.weightSource = null;
2569
+ const weightUrl = this.config.weightUrl ?? (this.config.weightCid && this.config.localResolver ? `holomap-local://${this.config.weightCid}` : void 0);
2570
+ if (weightUrl) {
1715
2571
  const result = await loadHoloMapWeightBlob({
1716
- weightUrl: this.config.weightUrl,
2572
+ weightUrl,
1717
2573
  weightUrls: this.config.weightUrls,
1718
- weightCid: this.config.weightCid
2574
+ weightCid: this.config.weightCid,
2575
+ localResolver: this.config.localResolver
1719
2576
  });
1720
2577
  this.weightBytes = result.bytes;
2578
+ this.weightVerified = result.verified;
2579
+ this.weightSource = result.source;
2580
+ }
2581
+ if (this.config.reconstructionMode === "dense-proof" && (!this.weightBytes || !this.weightVerified)) {
2582
+ throw new Error(
2583
+ "HoloMap dense-proof mode requires verified checkpoint bytes; preview mode is the only mode allowed to fall back to PRNG weights."
2584
+ );
1721
2585
  }
1722
2586
  this.encoderDevice = await tryCreateHoloMapEncoderDevice();
1723
2587
  this.microEncoder = this.encoderDevice ? createHoloMapMicroEncoder(this.encoderDevice) : null;
2588
+ const streamingTokens = Math.max(
2589
+ 1,
2590
+ this.config.maxSequenceLength * (this.config.tileGrid ?? _HoloMapRuntimeImpl.GRID_N) ** 2
2591
+ );
2592
+ const streamingPageSize = Math.max(
2593
+ 1,
2594
+ Math.min(64, this.config.tileGrid ?? _HoloMapRuntimeImpl.GRID_N)
2595
+ );
2596
+ this.streamingKVCache = createPagedKVCache({
2597
+ pageSize: streamingPageSize,
2598
+ maxResidentPages: Math.max(1, Math.min(256, Math.ceil(streamingTokens / streamingPageSize))),
2599
+ hiddenDim: 3,
2600
+ numHeads: 1,
2601
+ numLayers: 1,
2602
+ device: this.encoderDevice
2603
+ });
2604
+ this.streamingKVNextToken = 0;
1724
2605
  this.initialized = true;
1725
2606
  logHoloMapEvent(this.runId, "init", {
1726
2607
  modelHash: this.config.modelHash,
1727
2608
  seed: this.config.seed,
1728
2609
  allowCpuFallback: allowCpu,
1729
- webgpu: chunkT6W3Z3SH_cjs.isWebGpuEnvironmentPresent(),
2610
+ webgpu: chunkN2ILK7BF_cjs.isWebGpuEnvironmentPresent(),
1730
2611
  microEncoder: this.microEncoder ? "webgpu" : "cpu",
2612
+ reconstructionMode: this.config.reconstructionMode,
1731
2613
  tileGrid: this.config.tileGrid,
1732
2614
  weightLoadedBytes: this.weightBytes?.byteLength ?? 0,
2615
+ weightVerified: this.weightVerified,
2616
+ weightSource: this.weightSource,
1733
2617
  replayFingerprint: this.replayKey
1734
2618
  });
1735
2619
  }
@@ -1746,6 +2630,19 @@ var _HoloMapRuntimeImpl = class _HoloMapRuntimeImpl {
1746
2630
  }
1747
2631
  return tileGrid;
1748
2632
  }
2633
+ static assertDenseProofConfig(config) {
2634
+ const missing = [];
2635
+ if (!config.modelHash || config.modelHash === "unset") missing.push("modelHash");
2636
+ if (!config.weightCid) missing.push("weightCid");
2637
+ if (!config.weightUrl && !config.localResolver) missing.push("weightUrl or localResolver");
2638
+ if (missing.length > 0) {
2639
+ throw new Error(
2640
+ `HoloMap dense-proof mode requires ${missing.join(
2641
+ ", "
2642
+ )}; preview mode is the only mode allowed to use PRNG/default weights.`
2643
+ );
2644
+ }
2645
+ }
1749
2646
  /**
1750
2647
  * Carve `frame` into gridN×gridN tiles. Each tile carries its own
1751
2648
  * (rgb, width, height, stride, index) and the mean RGB color over its
@@ -1841,6 +2738,35 @@ var _HoloMapRuntimeImpl = class _HoloMapRuntimeImpl {
1841
2738
  return runHoloMapMicroEncoderCpu(tile, microCfg);
1842
2739
  }
1843
2740
  }
2741
+ async updateStreamingKVCache(encodedTiles) {
2742
+ if (!this.streamingKVCache || encodedTiles.length === 0) return void 0;
2743
+ const keys = new Float32Array(encodedTiles.length * 3);
2744
+ const values = new Float32Array(encodedTiles.length * 3);
2745
+ for (let i = 0; i < encodedTiles.length; i += 1) {
2746
+ const sample = encodedTiles[i];
2747
+ keys.set(sample.latent, i * 3);
2748
+ values[i * 3] = sample.rawDepthSignal;
2749
+ values[i * 3 + 1] = sample.texture;
2750
+ values[i * 3 + 2] = sample.luminance;
2751
+ }
2752
+ const firstToken = this.streamingKVNextToken;
2753
+ await this.streamingKVCache.append(0, keys, values, firstToken);
2754
+ this.streamingKVNextToken += encodedTiles.length;
2755
+ const retainedTokenCapacity = this.streamingKVCache.config.pageSize * this.streamingKVCache.config.maxResidentPages;
2756
+ const kLen = Math.min(this.streamingKVNextToken, 128, retainedTokenCapacity);
2757
+ const lookupStart = this.streamingKVNextToken - kLen;
2758
+ const lookup = await this.streamingKVCache.lookup(0, lookupStart, kLen);
2759
+ let checksum = 0;
2760
+ for (let i = 0; i < lookup.keys.length; i += 1) checksum += lookup.keys[i] ?? 0;
2761
+ for (let i = 0; i < lookup.values.length; i += 1) checksum += lookup.values[i] ?? 0;
2762
+ return {
2763
+ layer: 0,
2764
+ kLen,
2765
+ cachedPages: this.streamingKVCache.residentPagesForLayer(0).length,
2766
+ lookupChecksum: checksum,
2767
+ memory: this.streamingKVCache.memoryUsage()
2768
+ };
2769
+ }
1844
2770
  async step(frame) {
1845
2771
  if (!this.initialized) {
1846
2772
  throw new Error("HoloMapRuntime not initialized. Call init(config) before step(frame).");
@@ -1859,6 +2785,11 @@ var _HoloMapRuntimeImpl = class _HoloMapRuntimeImpl {
1859
2785
  `HoloMapRuntime.step invalid measured depth length: got ${frame.depth.length}, expected ${frame.width * frame.height} (w=${frame.width}, h=${frame.height})`
1860
2786
  );
1861
2787
  }
2788
+ if (frame.depthMeters && frame.depthMeters.length !== frame.width * frame.height) {
2789
+ throw new Error(
2790
+ `HoloMapRuntime.step invalid metric depth length: got ${frame.depthMeters.length}, expected ${frame.width * frame.height} (w=${frame.width}, h=${frame.height})`
2791
+ );
2792
+ }
1862
2793
  if (frame.depthConfidence && frame.depthConfidence.length !== frame.width * frame.height) {
1863
2794
  throw new Error(
1864
2795
  `HoloMapRuntime.step invalid measured depth confidence length: got ${frame.depthConfidence.length}, expected ${frame.width * frame.height} (w=${frame.width}, h=${frame.height})`
@@ -1893,12 +2824,19 @@ var _HoloMapRuntimeImpl = class _HoloMapRuntimeImpl {
1893
2824
  this.updateBounds(s.points.positions);
1894
2825
  }
1895
2826
  logHoloMapEvent(this.runId, "step_evict", {
1896
- frameIndex: evicted.frame.index,
2827
+ frameIndex: evicted.frameIndex,
1897
2828
  evictedPoints,
1898
2829
  retainedSteps: this.steps.length
1899
2830
  });
1900
2831
  }
1901
- const microCfg = { seed: this.config.seed, modelHash: this.config.modelHash };
2832
+ const microCfg = {
2833
+ seed: this.config.seed,
2834
+ modelHash: this.config.modelHash,
2835
+ // Wire the loaded checkpoint through to the encoder. Previously weightBytes
2836
+ // was fetched + verified in init() then never passed here, so the encoder
2837
+ // always ran on PRNG weights even when a real checkpoint was provided.
2838
+ weightBytes: this.weightBytes
2839
+ };
1902
2840
  const configuredGrid = this.config.tileGrid ?? _HoloMapRuntimeImpl.GRID_N;
1903
2841
  const gridN = Math.max(1, Math.min(configuredGrid, frame.width, frame.height));
1904
2842
  const tiles = _HoloMapRuntimeImpl.tileFrame(frame, gridN);
@@ -1907,22 +2845,83 @@ var _HoloMapRuntimeImpl = class _HoloMapRuntimeImpl {
1907
2845
  const colors = new Uint8Array(numPoints * 3);
1908
2846
  const confidence = new Float32Array(numPoints);
1909
2847
  const aspect = frame.width / Math.max(1, frame.height);
2848
+ const metricIntrinsics = _HoloMapRuntimeImpl.hasUsableIntrinsics(frame.cameraIntrinsics) ? frame.cameraIntrinsics : void 0;
2849
+ const encodedTiles = [];
2850
+ for (let t = 0; t < numPoints; t += 1) {
2851
+ const sample = tiles[t];
2852
+ const xyz = await this.encodeTile(sample.tile, microCfg);
2853
+ const latentX = xyz[0] ?? 0;
2854
+ const latentY = xyz[1] ?? 0;
2855
+ const latentZ = xyz[2] ?? 0;
2856
+ const depthHint = (sample.luminance - 0.5) * 0.34 + sample.texture * 0.24;
2857
+ encodedTiles.push({
2858
+ ...sample,
2859
+ latent: [latentX, latentY, latentZ],
2860
+ rawDepthSignal: depthHint + latentZ * 0.12,
2861
+ metricDepthMeters: frame.depthMeters ? _HoloMapRuntimeImpl.sampleMetricDepthNearestUv(
2862
+ frame.depthMeters,
2863
+ frame.width,
2864
+ frame.height,
2865
+ sample.centerUv
2866
+ ) : void 0
2867
+ });
2868
+ }
2869
+ const streamingKV = await this.updateStreamingKVCache(encodedTiles);
2870
+ const depthAlignment = _HoloMapRuntimeImpl.fitShiftScaleDepth(encodedTiles);
2871
+ const loopDescriptor = _HoloMapRuntimeImpl.buildLoopClosureDescriptor(encodedTiles);
2872
+ const rawDevicePose = frame.devicePose ? {
2873
+ position: [...frame.devicePose.position],
2874
+ rotation: [...frame.devicePose.rotation],
2875
+ confidence: frame.devicePose.confidence
2876
+ } : void 0;
2877
+ let loopCorrectedPose;
2878
+ if (frame.depthMeters && metricIntrinsics) {
2879
+ for (const kf of this.poseHistory) {
2880
+ if (frame.index - kf.frameIndex < _HoloMapRuntimeImpl.LOOP_CLOSURE_MIN_GAP) continue;
2881
+ const descriptorDistance = _HoloMapRuntimeImpl.descriptorDistance(
2882
+ loopDescriptor,
2883
+ kf.descriptor
2884
+ );
2885
+ if (descriptorDistance <= _HoloMapRuntimeImpl.LOOP_CLOSURE_DESCRIPTOR_DISTANCE) {
2886
+ this.lastLoopClosureFrameIdx = frame.index;
2887
+ if (rawDevicePose) {
2888
+ loopCorrectedPose = {
2889
+ ...rawDevicePose,
2890
+ position: [...kf.position],
2891
+ confidence: Math.min(1, Math.max(rawDevicePose.confidence, 0.9))
2892
+ };
2893
+ }
2894
+ break;
2895
+ }
2896
+ }
2897
+ }
2898
+ const metricProjectionPose = loopCorrectedPose ?? rawDevicePose;
1910
2899
  let centroidX = 0;
1911
2900
  let centroidY = 0;
1912
2901
  let centroidZ = 0;
1913
2902
  let confidenceSum = 0;
1914
2903
  for (let t = 0; t < numPoints; t += 1) {
1915
- const { tile, meanColor, centerUv, luminance, texture } = tiles[t];
1916
- const xyz = await this.encodeTile(tile, microCfg);
1917
- const latentX = xyz[0] ?? 0;
1918
- const latentY = xyz[1] ?? 0;
1919
- const latentZ = xyz[2] ?? 0;
2904
+ const { meanColor, centerUv, texture, latent, rawDepthSignal } = encodedTiles[t];
2905
+ const [latentX, latentY, latentZ] = latent;
1920
2906
  const planeX = (centerUv[0] - 0.5) * 2 * aspect;
1921
2907
  const planeY = (0.5 - centerUv[1]) * 2;
1922
- const px = planeX + latentX * 0.08;
1923
- const py = planeY + latentY * 0.08;
2908
+ let px = planeX + latentX * 0.08;
2909
+ let py = planeY + latentY * 0.08;
1924
2910
  let pz;
1925
- if (frame.depth) {
2911
+ const metricDepth = _HoloMapRuntimeImpl.alignedDepthMeters(encodedTiles[t], depthAlignment);
2912
+ if (metricDepth !== void 0 && metricIntrinsics) {
2913
+ const worldPoint = _HoloMapRuntimeImpl.projectMetricDepthToWorld(
2914
+ centerUv,
2915
+ metricDepth,
2916
+ metricIntrinsics,
2917
+ metricProjectionPose
2918
+ );
2919
+ px = worldPoint[0];
2920
+ py = worldPoint[1];
2921
+ pz = worldPoint[2];
2922
+ } else if (metricDepth !== void 0) {
2923
+ pz = -metricDepth;
2924
+ } else if (frame.depth) {
1926
2925
  const measured = _HoloMapRuntimeImpl.sampleDepthNearestUv(
1927
2926
  frame.depth,
1928
2927
  frame.width,
@@ -1931,8 +2930,7 @@ var _HoloMapRuntimeImpl = class _HoloMapRuntimeImpl {
1931
2930
  );
1932
2931
  pz = (0.5 - measured) * _HoloMapRuntimeImpl.DEPTH_Z_SCALE;
1933
2932
  } else {
1934
- const depthHint = (luminance - 0.5) * 0.34 + texture * 0.24;
1935
- pz = depthHint + latentZ * 0.12;
2933
+ pz = rawDepthSignal;
1936
2934
  }
1937
2935
  positions[t * 3] = px;
1938
2936
  positions[t * 3 + 1] = py;
@@ -1968,10 +2966,10 @@ var _HoloMapRuntimeImpl = class _HoloMapRuntimeImpl {
1968
2966
  const meanConfidence = confidenceSum * inv;
1969
2967
  const derivedPosition = [poseX, poseY, poseZ];
1970
2968
  const poseConfidence = Math.max(0, Math.min(1, meanConfidence));
1971
- const cameraPose = frame.devicePose ? {
1972
- position: [...frame.devicePose.position],
1973
- rotation: [...frame.devicePose.rotation],
1974
- confidence: frame.devicePose.confidence
2969
+ const cameraPose = metricProjectionPose ? {
2970
+ position: [...metricProjectionPose.position],
2971
+ rotation: [...metricProjectionPose.rotation],
2972
+ confidence: metricProjectionPose.confidence
1975
2973
  } : {
1976
2974
  position: derivedPosition,
1977
2975
  rotation: _HoloMapRuntimeImpl.estimatePrincipalAxisRotation([positions], derivedPosition),
@@ -2018,17 +3016,23 @@ var _HoloMapRuntimeImpl = class _HoloMapRuntimeImpl {
2018
3016
  }
2019
3017
  this.prevPose = curPose;
2020
3018
  this.prevCameraPose = cameraPose;
2021
- for (const kf of this.poseHistory) {
2022
- if (frame.index - kf.frameIndex < _HoloMapRuntimeImpl.LOOP_CLOSURE_MIN_GAP) continue;
2023
- const dx = curPose[0] - kf.position[0];
2024
- const dy = curPose[1] - kf.position[1];
2025
- const dz = curPose[2] - kf.position[2];
2026
- if (Math.sqrt(dx * dx + dy * dy + dz * dz) < _HoloMapRuntimeImpl.LOOP_CLOSURE_RADIUS) {
2027
- this.lastLoopClosureFrameIdx = frame.index;
2028
- break;
3019
+ if (this.lastLoopClosureFrameIdx !== frame.index) {
3020
+ for (const kf of this.poseHistory) {
3021
+ if (frame.index - kf.frameIndex < _HoloMapRuntimeImpl.LOOP_CLOSURE_MIN_GAP) continue;
3022
+ const dx = curPose[0] - kf.position[0];
3023
+ const dy = curPose[1] - kf.position[1];
3024
+ const dz = curPose[2] - kf.position[2];
3025
+ if (Math.sqrt(dx * dx + dy * dy + dz * dz) < _HoloMapRuntimeImpl.LOOP_CLOSURE_RADIUS) {
3026
+ this.lastLoopClosureFrameIdx = frame.index;
3027
+ break;
3028
+ }
2029
3029
  }
2030
3030
  }
2031
- this.poseHistory.push({ frameIndex: frame.index, position: curPose });
3031
+ this.poseHistory.push({
3032
+ frameIndex: frame.index,
3033
+ position: curPose,
3034
+ descriptor: loopDescriptor
3035
+ });
2032
3036
  if (this.poseHistory.length > _HoloMapRuntimeImpl.POSE_HISTORY_CAP) this.poseHistory.shift();
2033
3037
  this.updateBounds(positions);
2034
3038
  this.globalPosSum[0] += centroidX;
@@ -2048,7 +3052,7 @@ var _HoloMapRuntimeImpl = class _HoloMapRuntimeImpl {
2048
3052
  const extentY = b.max[1] - b.min[1];
2049
3053
  const extentZ = b.max[2] - b.min[2];
2050
3054
  const anchorRotation = _HoloMapRuntimeImpl.estimatePrincipalAxisRotation(
2051
- [...this.steps.map((s) => s.points.positions), positions],
3055
+ _HoloMapRuntimeImpl.retainedPositionChunks(this.steps, positions),
2052
3056
  anchorCenter
2053
3057
  );
2054
3058
  const anchorDescriptor = new Float32Array([extentX, extentY, extentZ, globalMeanConfidence]);
@@ -2074,6 +3078,7 @@ var _HoloMapRuntimeImpl = class _HoloMapRuntimeImpl {
2074
3078
  colors,
2075
3079
  confidence
2076
3080
  },
3081
+ ...streamingKV ? { streamingKV } : {},
2077
3082
  trajectory: {
2078
3083
  keyframes: trajectoryKeyframes,
2079
3084
  estimatedDriftMeters: this.cumulativeDriftMeters,
@@ -2089,9 +3094,16 @@ var _HoloMapRuntimeImpl = class _HoloMapRuntimeImpl {
2089
3094
  },
2090
3095
  anchorDescriptor,
2091
3096
  revision: frame.index + 1
2092
- }
3097
+ },
3098
+ ...depthAlignment ? { depthAlignment } : {}
2093
3099
  };
2094
- this.steps.push(step);
3100
+ this.steps.push({
3101
+ frameIndex: frame.index,
3102
+ points: {
3103
+ positions,
3104
+ confidence
3105
+ }
3106
+ });
2095
3107
  this.totalPointCount += numPoints;
2096
3108
  const stepMs = performance.now() - stepStartMs;
2097
3109
  this.perfMetrics.stepCount += 1;
@@ -2124,7 +3136,16 @@ var _HoloMapRuntimeImpl = class _HoloMapRuntimeImpl {
2124
3136
  throttledCount: this.perfMetrics.throttledCount,
2125
3137
  sessionDurationMs: Math.round(performance.now() - this.sessionStartMs)
2126
3138
  });
2127
- return {
3139
+ const reconstruction = {
3140
+ mode: this.config.reconstructionMode ?? "preview",
3141
+ modelHash: this.config.modelHash,
3142
+ tileGrid: this.config.tileGrid ?? _HoloMapRuntimeImpl.GRID_N,
3143
+ weightLoadedBytes: this.weightBytes?.byteLength ?? 0,
3144
+ weightVerified: this.weightVerified,
3145
+ ...this.config.weightCid ? { weightCid: this.config.weightCid } : {},
3146
+ ...this.weightSource ? { weightSource: this.weightSource } : {}
3147
+ };
3148
+ const manifest = {
2128
3149
  version: "1.0.0",
2129
3150
  worldId: `holomap-${this.replayKey}`,
2130
3151
  displayName: "HoloMap Reconstruction",
@@ -2133,7 +3154,7 @@ var _HoloMapRuntimeImpl = class _HoloMapRuntimeImpl {
2133
3154
  bounds,
2134
3155
  replayHash: this.replayKey,
2135
3156
  simulationContract: {
2136
- kind: chunkT6W3Z3SH_cjs.HOLOMAP_SIMULATION_CONTRACT_KIND,
3157
+ kind: chunkN2ILK7BF_cjs.HOLOMAP_SIMULATION_CONTRACT_KIND,
2137
3158
  replayFingerprint: this.replayKey,
2138
3159
  holoScriptBuild: getVersionString()
2139
3160
  },
@@ -2146,8 +3167,17 @@ var _HoloMapRuntimeImpl = class _HoloMapRuntimeImpl {
2146
3167
  trajectory: "reconstruction.trajectory.json",
2147
3168
  anchors: "reconstruction.anchors.json"
2148
3169
  },
2149
- weightStrategy: this.config.weightStrategy ?? "distill"
3170
+ weightStrategy: this.config.weightStrategy ?? "distill",
3171
+ reconstruction
2150
3172
  };
3173
+ try {
3174
+ return await anchorReconstructionManifest(manifest, this.config.provenanceAnchorProvider);
3175
+ } catch (error) {
3176
+ logHoloMapEvent(this.runId, "anchor_failed", {
3177
+ reason: error instanceof Error ? error.message : String(error)
3178
+ });
3179
+ return selfAttestReconstructionManifest(manifest);
3180
+ }
2151
3181
  }
2152
3182
  replayHash() {
2153
3183
  return this.replayKey;
@@ -2162,7 +3192,12 @@ var _HoloMapRuntimeImpl = class _HoloMapRuntimeImpl {
2162
3192
  this.steps.length = 0;
2163
3193
  this.microEncoder = null;
2164
3194
  this.encoderDevice = null;
3195
+ await this.streamingKVCache?.dispose();
3196
+ this.streamingKVCache = null;
3197
+ this.streamingKVNextToken = 0;
2165
3198
  this.weightBytes = null;
3199
+ this.weightVerified = false;
3200
+ this.weightSource = null;
2166
3201
  this.totalPointCount = 0;
2167
3202
  this.cumulativeDriftMeters = 0;
2168
3203
  this.prevPose = null;
@@ -2192,6 +3227,7 @@ _HoloMapRuntimeImpl.TRAJECTORY_KEYFRAME_CAP = 512;
2192
3227
  * the monocular estimate's spread (±~0.17), so sensor and estimate paths
2193
3228
  * produce geometry in the same coordinate scale. */
2194
3229
  _HoloMapRuntimeImpl.DEPTH_Z_SCALE = 0.34;
3230
+ _HoloMapRuntimeImpl.LOOP_CLOSURE_DESCRIPTOR_DISTANCE = 0.015;
2195
3231
  /**
2196
3232
  * Default number of tiles per axis used to fan the encoder across the frame.
2197
3233
  * Total points emitted = tileGrid * tileGrid (one per tile).
@@ -2201,6 +3237,7 @@ _HoloMapRuntimeImpl.DEPTH_Z_SCALE = 0.34;
2201
3237
  * for future streaming kLen>1 paths.
2202
3238
  */
2203
3239
  _HoloMapRuntimeImpl.GRID_N = 4;
3240
+ _HoloMapRuntimeImpl.DENSE_PROOF_GRID_N = 16;
2204
3241
  _HoloMapRuntimeImpl.MAX_GRID_N = 32;
2205
3242
  var HoloMapRuntimeImpl = _HoloMapRuntimeImpl;
2206
3243
  function createHoloMapRuntime(_config) {
@@ -2214,21 +3251,30 @@ function createHoloMapRuntime(_config) {
2214
3251
  exports.BUILD_TIMESTAMP = BUILD_TIMESTAMP;
2215
3252
  exports.GIT_COMMIT_SHA = GIT_COMMIT_SHA;
2216
3253
  exports.HOLOMAP_DEFAULTS = HOLOMAP_DEFAULTS;
3254
+ exports.HOLOMAP_DENSE_PROOF_DEFAULTS = HOLOMAP_DENSE_PROOF_DEFAULTS;
2217
3255
  exports.HOLOSCRIPT_VERSION = HOLOSCRIPT_VERSION;
3256
+ exports.anchorReconstructionManifest = anchorReconstructionManifest;
2218
3257
  exports.assertWeightCid = assertWeightCid;
3258
+ exports.computeReconstructionManifestDigest = computeReconstructionManifestDigest;
2219
3259
  exports.createHoloMapMicroEncoder = createHoloMapMicroEncoder;
2220
3260
  exports.createHoloMapRunId = createHoloMapRunId;
2221
3261
  exports.createHoloMapRuntime = createHoloMapRuntime;
3262
+ exports.createPagedKVCache = createPagedKVCache;
3263
+ exports.deserializeMicroWeights = deserializeMicroWeights;
2222
3264
  exports.frameToMicroImage = frameToMicroImage;
2223
3265
  exports.getCachedWeightBlob = getCachedWeightBlob;
2224
3266
  exports.getVersionInfo = getVersionInfo;
2225
3267
  exports.getVersionString = getVersionString;
2226
3268
  exports.loadHoloMapWeightBlob = loadHoloMapWeightBlob;
2227
3269
  exports.logHoloMapEvent = logHoloMapEvent;
3270
+ exports.mergeAnchoredProvenance = mergeAnchoredProvenance;
2228
3271
  exports.normalizeWeightCidDigest = normalizeWeightCidDigest;
2229
3272
  exports.putCachedWeightBlob = putCachedWeightBlob;
2230
3273
  exports.resetHoloMapTelemetryForTests = resetHoloMapTelemetryForTests;
2231
3274
  exports.runHoloMapMicroEncoderCpu = runHoloMapMicroEncoderCpu;
3275
+ exports.selfAttestReconstructionManifest = selfAttestReconstructionManifest;
3276
+ exports.serializeMicroWeights = serializeMicroWeights;
3277
+ exports.stripAnchoredProvenance = stripAnchoredProvenance;
2232
3278
  exports.tryCreateHoloMapEncoderDevice = tryCreateHoloMapEncoderDevice;
2233
- //# sourceMappingURL=chunk-WFKVS2K4.cjs.map
2234
- //# sourceMappingURL=chunk-WFKVS2K4.cjs.map
3279
+ //# sourceMappingURL=chunk-AUZRKIHQ.cjs.map
3280
+ //# sourceMappingURL=chunk-AUZRKIHQ.cjs.map