@air-jam/sdk 0.9.3 → 1.0.0-beta.1

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 (594) hide show
  1. package/README.md +168 -205
  2. package/dist/actions-D4eh6Xaa.d.cts +72 -0
  3. package/dist/actions-D4eh6Xaa.d.ts +72 -0
  4. package/dist/{agent-contract-CD2QnbBJ.d.cts → agent-contract-DfLm4Mf-.d.ts} +3 -19
  5. package/dist/{agent-contract-CD2QnbBJ.d.ts → agent-contract-TINzp-5Y.d.cts} +3 -19
  6. package/dist/agent-tooling.cjs +135 -46
  7. package/dist/agent-tooling.cjs.map +1 -1
  8. package/dist/agent-tooling.d.cts +96 -5
  9. package/dist/agent-tooling.d.ts +96 -5
  10. package/dist/agent-tooling.js +15 -14
  11. package/dist/agent-tooling.js.map +1 -1
  12. package/dist/{use-air-jam-host-COLy8t4s.d.ts → air-jam-context-BCVCWiaT.d.ts} +121 -114
  13. package/dist/{use-air-jam-host-DM-ybB3C.d.cts → air-jam-context-DavligpM.d.cts} +121 -114
  14. package/dist/arcade/bridge/controller.cjs +873 -603
  15. package/dist/arcade/bridge/controller.cjs.map +1 -1
  16. package/dist/arcade/bridge/controller.d.cts +28 -76
  17. package/dist/arcade/bridge/controller.d.ts +28 -76
  18. package/dist/arcade/bridge/controller.js +27 -28
  19. package/dist/arcade/bridge/controller.js.map +1 -1
  20. package/dist/arcade/bridge/host.cjs +1017 -252
  21. package/dist/arcade/bridge/host.cjs.map +1 -1
  22. package/dist/arcade/bridge/host.d.cts +6 -72
  23. package/dist/arcade/bridge/host.d.ts +6 -72
  24. package/dist/arcade/bridge/host.js +19 -22
  25. package/dist/arcade/bridge/host.js.map +1 -1
  26. package/dist/arcade/bridge/iframe.cjs +3 -31
  27. package/dist/arcade/bridge/iframe.cjs.map +1 -1
  28. package/dist/arcade/bridge/iframe.d.cts +4 -46
  29. package/dist/arcade/bridge/iframe.d.ts +4 -46
  30. package/dist/arcade/bridge/iframe.js +6 -18
  31. package/dist/arcade/bridge/iframe.js.map +1 -1
  32. package/dist/arcade/host.cjs +0 -502
  33. package/dist/arcade/host.cjs.map +1 -1
  34. package/dist/arcade/host.d.cts +1 -19
  35. package/dist/arcade/host.d.ts +1 -19
  36. package/dist/arcade/host.js +0 -14
  37. package/dist/arcade/host.js.map +1 -1
  38. package/dist/arcade/runtime.cjs +10354 -4690
  39. package/dist/arcade/runtime.cjs.map +1 -1
  40. package/dist/arcade/runtime.d.cts +45 -13
  41. package/dist/arcade/runtime.d.ts +45 -13
  42. package/dist/arcade/runtime.js +37 -24
  43. package/dist/arcade/runtime.js.map +1 -1
  44. package/dist/arcade/surface.cjs +3 -35
  45. package/dist/arcade/surface.cjs.map +1 -1
  46. package/dist/arcade/surface.d.cts +14 -2
  47. package/dist/arcade/surface.d.ts +14 -2
  48. package/dist/arcade/surface.js +7 -13
  49. package/dist/arcade/surface.js.map +1 -1
  50. package/dist/arcade/url.cjs +45 -283
  51. package/dist/arcade/url.cjs.map +1 -1
  52. package/dist/arcade/url.d.cts +3 -56
  53. package/dist/arcade/url.d.ts +3 -56
  54. package/dist/arcade/url.js +33 -16
  55. package/dist/arcade/url.js.map +1 -1
  56. package/dist/chunk-24NZZOIO.js +700 -0
  57. package/dist/chunk-24NZZOIO.js.map +1 -0
  58. package/dist/chunk-27QLKLZL.js +469 -0
  59. package/dist/chunk-27QLKLZL.js.map +1 -0
  60. package/dist/{chunk-UWJOIVON.js → chunk-2H2FGF3H.js} +3 -6
  61. package/dist/chunk-2H2FGF3H.js.map +1 -0
  62. package/dist/chunk-2QZADUGA.js +188 -0
  63. package/dist/chunk-2QZADUGA.js.map +1 -0
  64. package/dist/chunk-3LDQCQL2.js +307 -0
  65. package/dist/chunk-3LDQCQL2.js.map +1 -0
  66. package/dist/chunk-3M7656SU.js +389 -0
  67. package/dist/chunk-3M7656SU.js.map +1 -0
  68. package/dist/{chunk-K4OZ54UD.js → chunk-5CRZFIN6.js} +2 -55
  69. package/dist/chunk-5CRZFIN6.js.map +1 -0
  70. package/dist/chunk-5TVVPBQI.js +7 -0
  71. package/dist/chunk-5TVVPBQI.js.map +1 -0
  72. package/dist/chunk-6Y3F6Y2K.js +343 -0
  73. package/dist/chunk-6Y3F6Y2K.js.map +1 -0
  74. package/dist/{chunk-EVZJA6RN.js → chunk-6ZJUA63D.js} +183 -2
  75. package/dist/chunk-6ZJUA63D.js.map +1 -0
  76. package/dist/chunk-A6EOGRRG.js +49 -0
  77. package/dist/chunk-A6EOGRRG.js.map +1 -0
  78. package/dist/chunk-BEM77SVQ.js +57 -0
  79. package/dist/chunk-BEM77SVQ.js.map +1 -0
  80. package/dist/chunk-C5722GTG.js +176 -0
  81. package/dist/chunk-C5722GTG.js.map +1 -0
  82. package/dist/{chunk-CV3PBXPT.js → chunk-C5GS2GMK.js} +99 -105
  83. package/dist/chunk-C5GS2GMK.js.map +1 -0
  84. package/dist/chunk-CDL7LYZH.js +19 -0
  85. package/dist/chunk-CDL7LYZH.js.map +1 -0
  86. package/dist/{chunk-PSUYTD2L.js → chunk-DA3TE4OP.js} +1 -1
  87. package/dist/chunk-DA3TE4OP.js.map +1 -0
  88. package/dist/chunk-DBF7NJ3S.js +72 -0
  89. package/dist/chunk-DBF7NJ3S.js.map +1 -0
  90. package/dist/chunk-DHFKL3DI.js +2477 -0
  91. package/dist/chunk-DHFKL3DI.js.map +1 -0
  92. package/dist/chunk-DRBPVG47.js +89 -0
  93. package/dist/chunk-DRBPVG47.js.map +1 -0
  94. package/dist/{chunk-MIMPMB7O.js → chunk-EG25EXSA.js} +24 -3
  95. package/dist/chunk-EG25EXSA.js.map +1 -0
  96. package/dist/chunk-FCG42U7D.js +131 -0
  97. package/dist/chunk-FCG42U7D.js.map +1 -0
  98. package/dist/chunk-FJ4J2BEC.js +26 -0
  99. package/dist/chunk-FJ4J2BEC.js.map +1 -0
  100. package/dist/chunk-H4DEVMTO.js +221 -0
  101. package/dist/chunk-H4DEVMTO.js.map +1 -0
  102. package/dist/{chunk-X35LLCWV.js → chunk-I6TSHJF7.js} +6 -8
  103. package/dist/chunk-I6TSHJF7.js.map +1 -0
  104. package/dist/{chunk-IG6GZZSS.js → chunk-JCGTL77W.js} +1 -1
  105. package/dist/chunk-JCGTL77W.js.map +1 -0
  106. package/dist/chunk-JJVCBUYM.js +98 -0
  107. package/dist/chunk-JJVCBUYM.js.map +1 -0
  108. package/dist/chunk-K6BJJJJM.js +138 -0
  109. package/dist/chunk-K6BJJJJM.js.map +1 -0
  110. package/dist/chunk-KSYN4I5Y.js +50 -0
  111. package/dist/chunk-KSYN4I5Y.js.map +1 -0
  112. package/dist/chunk-KUGROY5S.js +265 -0
  113. package/dist/chunk-KUGROY5S.js.map +1 -0
  114. package/dist/chunk-LX6CTPDW.js +16 -0
  115. package/dist/chunk-LX6CTPDW.js.map +1 -0
  116. package/dist/{chunk-BE6Z4SIT.js → chunk-M5553I2G.js} +2 -11
  117. package/dist/chunk-M5553I2G.js.map +1 -0
  118. package/dist/{chunk-X24K52DG.js → chunk-MD25536W.js} +1 -1
  119. package/dist/chunk-MD25536W.js.map +1 -0
  120. package/dist/{chunk-3USU7GY2.js → chunk-MJAWAHLT.js} +1 -1
  121. package/dist/chunk-MJAWAHLT.js.map +1 -0
  122. package/dist/chunk-OAXCFPZ7.js +14 -0
  123. package/dist/chunk-OAXCFPZ7.js.map +1 -0
  124. package/dist/{chunk-D4VDEVTZ.js → chunk-QHBRHYMV.js} +18 -17
  125. package/dist/chunk-QHBRHYMV.js.map +1 -0
  126. package/dist/chunk-QTNYGAZ7.js +45 -0
  127. package/dist/chunk-QTNYGAZ7.js.map +1 -0
  128. package/dist/chunk-S3TN7Y7L.js +921 -0
  129. package/dist/chunk-S3TN7Y7L.js.map +1 -0
  130. package/dist/chunk-SMKD4JY3.js +129 -0
  131. package/dist/chunk-SMKD4JY3.js.map +1 -0
  132. package/dist/{chunk-O6X7FJ6N.js → chunk-TFW4NJW2.js} +619 -643
  133. package/dist/chunk-TFW4NJW2.js.map +1 -0
  134. package/dist/chunk-UBBP2UY3.js +83 -0
  135. package/dist/chunk-UBBP2UY3.js.map +1 -0
  136. package/dist/chunk-URVBMQCK.js +802 -0
  137. package/dist/chunk-URVBMQCK.js.map +1 -0
  138. package/dist/chunk-VGX2274F.js +1995 -0
  139. package/dist/chunk-VGX2274F.js.map +1 -0
  140. package/dist/chunk-WAFGYJZN.js +1513 -0
  141. package/dist/chunk-WAFGYJZN.js.map +1 -0
  142. package/dist/chunk-WGHNGQUS.js +78 -0
  143. package/dist/chunk-WGHNGQUS.js.map +1 -0
  144. package/dist/chunk-XLY44PXZ.js +46 -0
  145. package/dist/chunk-XLY44PXZ.js.map +1 -0
  146. package/dist/connection-store-BYpQ50W2.d.ts +41 -0
  147. package/dist/connection-store-D6QqzXU1.d.cts +41 -0
  148. package/dist/control-Bv8dWjyp.d.ts +1400 -0
  149. package/dist/control-CNzybWMd.d.cts +1400 -0
  150. package/dist/controller-0CVO1t_3.d.cts +26 -0
  151. package/dist/controller-agent-vOiuK7T6.d.cts +130 -0
  152. package/dist/controller-agent-vOiuK7T6.d.ts +130 -0
  153. package/dist/controller-bridge.cjs +992 -0
  154. package/dist/controller-bridge.cjs.map +1 -0
  155. package/dist/controller-bridge.d.cts +52 -0
  156. package/dist/controller-bridge.d.ts +52 -0
  157. package/dist/controller-bridge.js +23 -0
  158. package/dist/controller-bridge.js.map +1 -0
  159. package/dist/controller-capture-2GKKGHJ2.js +8 -0
  160. package/dist/controller-capture-2GKKGHJ2.js.map +1 -0
  161. package/dist/controller-h9M2Nngd.d.ts +26 -0
  162. package/dist/controller-press-EWWIMVXP.js +231 -0
  163. package/dist/controller-press-EWWIMVXP.js.map +1 -0
  164. package/dist/core-BAO0pHrJ.d.cts +15 -0
  165. package/dist/core-BAO0pHrJ.d.ts +15 -0
  166. package/dist/core.cjs +5931 -0
  167. package/dist/core.cjs.map +1 -0
  168. package/dist/core.d.cts +232 -0
  169. package/dist/core.d.ts +232 -0
  170. package/dist/core.js +906 -0
  171. package/dist/core.js.map +1 -0
  172. package/dist/dev-events-BffobOfb.d.ts +31 -0
  173. package/dist/dev-events-Ct7QEgKb.d.cts +31 -0
  174. package/dist/dev-log-events-B1_B3guZ.d.cts +47 -0
  175. package/dist/dev-log-events-B1_B3guZ.d.ts +47 -0
  176. package/dist/frames-D-xKuODS.d.cts +686 -0
  177. package/dist/frames-D-xKuODS.d.ts +686 -0
  178. package/dist/game-Db58JNk3.d.cts +77 -0
  179. package/dist/game-bySEy-QO.d.ts +77 -0
  180. package/dist/host-runtime-BuLhGQx5.d.ts +399 -0
  181. package/dist/host-runtime-_06jpW5v.d.cts +399 -0
  182. package/dist/index.cjs +11580 -7584
  183. package/dist/index.cjs.map +1 -1
  184. package/dist/index.d.cts +100 -358
  185. package/dist/index.d.ts +100 -358
  186. package/dist/index.js +414 -1903
  187. package/dist/index.js.map +1 -1
  188. package/dist/input-Xvs80gqG.d.cts +92 -0
  189. package/dist/input-Xvs80gqG.d.ts +92 -0
  190. package/dist/input-bindings-BaEFrgRb.d.cts +129 -0
  191. package/dist/input-bindings-BgsJRLPm.d.ts +129 -0
  192. package/dist/leased-control-BEg4JuXA.d.cts +158 -0
  193. package/dist/leased-control-BEg4JuXA.d.ts +158 -0
  194. package/dist/metadata.cjs +3 -9
  195. package/dist/metadata.cjs.map +1 -1
  196. package/dist/metadata.d.cts +6 -16
  197. package/dist/metadata.d.ts +6 -16
  198. package/dist/metadata.js +8 -76
  199. package/dist/metadata.js.map +1 -1
  200. package/dist/phone-room-session-Ca6rlxJr.d.ts +439 -0
  201. package/dist/phone-room-session-DkPR-K6e.d.cts +439 -0
  202. package/dist/platform-machine.cjs +133 -3
  203. package/dist/platform-machine.cjs.map +1 -1
  204. package/dist/platform-machine.d.cts +525 -27
  205. package/dist/platform-machine.d.ts +525 -27
  206. package/dist/platform-machine.js +119 -4
  207. package/dist/platform-machine.js.map +1 -1
  208. package/dist/{platform-settings-DUWs4JTy.d.cts → platform-settings-Yb0fQ1dl.d.cts} +1 -3
  209. package/dist/{platform-settings-DUWs4JTy.d.ts → platform-settings-Yb0fQ1dl.d.ts} +1 -3
  210. package/dist/prefabs.cjs +134 -3
  211. package/dist/prefabs.cjs.map +1 -1
  212. package/dist/prefabs.d.cts +23 -47
  213. package/dist/prefabs.d.ts +23 -47
  214. package/dist/prefabs.js +23 -4
  215. package/dist/prefabs.js.map +1 -1
  216. package/dist/preview.cjs +2214 -767
  217. package/dist/preview.cjs.map +1 -1
  218. package/dist/preview.d.cts +193 -38
  219. package/dist/preview.d.ts +193 -38
  220. package/dist/preview.js +478 -254
  221. package/dist/preview.js.map +1 -1
  222. package/dist/protocol.cjs +585 -391
  223. package/dist/protocol.cjs.map +1 -1
  224. package/dist/protocol.d.cts +13 -117
  225. package/dist/protocol.d.ts +13 -117
  226. package/dist/protocol.js +43 -80
  227. package/dist/protocol.js.map +1 -1
  228. package/dist/release.cjs.map +1 -1
  229. package/dist/release.d.cts +2 -2
  230. package/dist/release.d.ts +2 -2
  231. package/dist/release.js +1 -1
  232. package/dist/release.js.map +1 -1
  233. package/dist/replay-input-log-BvX4As2f.d.ts +31 -0
  234. package/dist/replay-input-log-Vcl0VDIy.d.cts +31 -0
  235. package/dist/room-protocol.cjs +794 -0
  236. package/dist/room-protocol.cjs.map +1 -0
  237. package/dist/room-protocol.d.cts +63 -0
  238. package/dist/room-protocol.d.ts +63 -0
  239. package/dist/room-protocol.js +143 -0
  240. package/dist/room-protocol.js.map +1 -0
  241. package/dist/room-session.cjs +2336 -0
  242. package/dist/room-session.cjs.map +1 -0
  243. package/dist/room-session.d.cts +77 -0
  244. package/dist/room-session.d.ts +77 -0
  245. package/dist/room-session.js +103 -0
  246. package/dist/room-session.js.map +1 -0
  247. package/dist/runtime/prefab-inspection-bridge.cjs +207 -0
  248. package/dist/runtime/prefab-inspection-bridge.cjs.map +1 -0
  249. package/dist/runtime/prefab-inspection-bridge.d.cts +156 -0
  250. package/dist/runtime/prefab-inspection-bridge.d.ts +156 -0
  251. package/dist/runtime/prefab-inspection-bridge.js +22 -0
  252. package/dist/runtime/prefab-inspection-bridge.js.map +1 -0
  253. package/dist/runtime-control.cjs +2112 -8
  254. package/dist/runtime-control.cjs.map +1 -1
  255. package/dist/runtime-control.d.cts +980 -12
  256. package/dist/runtime-control.d.ts +980 -12
  257. package/dist/runtime-control.js +264 -4
  258. package/dist/runtime-control.js.map +1 -1
  259. package/dist/runtime-inspection.cjs +1222 -558
  260. package/dist/runtime-inspection.cjs.map +1 -1
  261. package/dist/runtime-inspection.d.cts +530 -22
  262. package/dist/runtime-inspection.d.ts +530 -22
  263. package/dist/runtime-inspection.js +21 -22
  264. package/dist/runtime-inspection.js.map +1 -1
  265. package/dist/runtime-reporting-K_ZXpubu.d.cts +43 -0
  266. package/dist/runtime-reporting-K_ZXpubu.d.ts +43 -0
  267. package/dist/runtime-topology.cjs +2 -5
  268. package/dist/runtime-topology.cjs.map +1 -1
  269. package/dist/runtime-topology.d.cts +1 -1
  270. package/dist/runtime-topology.d.ts +1 -1
  271. package/dist/runtime-topology.js +1 -1
  272. package/dist/runtime-topology.js.map +1 -1
  273. package/dist/scoped-connector-CiiWu06D.d.ts +66 -0
  274. package/dist/scoped-connector-D7252pn0.d.cts +66 -0
  275. package/dist/sdk-channels-S6j6AH8v.d.cts +103 -0
  276. package/dist/sdk-channels-S6j6AH8v.d.ts +103 -0
  277. package/dist/simulation-BfRnC4rg.d.ts +782 -0
  278. package/dist/simulation-BwZx2pgt.d.cts +782 -0
  279. package/dist/{standard-match-phase-BzSgBYFg.d.ts → standard-match-phase-D4N-AU0d.d.cts} +3 -13
  280. package/dist/{standard-match-phase-CvJUW8Oe.d.cts → standard-match-phase-abt8ZjCh.d.ts} +3 -13
  281. package/dist/transport-CWF29jU6.d.cts +173 -0
  282. package/dist/transport-CWF29jU6.d.ts +173 -0
  283. package/dist/types-p28maMEo.d.cts +102 -0
  284. package/dist/types-p28maMEo.d.ts +102 -0
  285. package/dist/ui.cjs +2182 -892
  286. package/dist/ui.cjs.map +1 -1
  287. package/dist/ui.d.cts +75 -17
  288. package/dist/ui.d.ts +75 -17
  289. package/dist/ui.js +554 -393
  290. package/dist/ui.js.map +1 -1
  291. package/package.json +38 -21
  292. package/src/agent/agent-action.ts +0 -39
  293. package/src/agent/agent-contract-conformance.ts +8 -1
  294. package/src/agent/agent-contract.ts +2 -4
  295. package/src/agent/agent-evaluator.ts +95 -0
  296. package/src/agent/capture-canvas.ts +79 -0
  297. package/src/agent/host-canvas-capture.ts +189 -0
  298. package/src/agent-tooling.ts +5 -20
  299. package/src/arcade/bridge/controller.ts +8 -11
  300. package/src/arcade/bridge/host.ts +6 -11
  301. package/src/arcade/bridge/iframe.ts +1 -50
  302. package/src/arcade/host.ts +0 -1
  303. package/src/arcade/surface.ts +5 -1
  304. package/src/arcade/url.ts +2 -9
  305. package/src/audio/audio-manager.ts +23 -47
  306. package/src/audio/hooks.tsx +59 -72
  307. package/src/components/controller-player-name-field.tsx +2 -2
  308. package/src/components/controller-primary-action.tsx +1 -1
  309. package/src/components/controls.tsx +398 -0
  310. package/src/components/gamepad-layout.tsx +69 -0
  311. package/src/components/join-url-controls.tsx +5 -1
  312. package/src/components/lifecycle-action-group.tsx +1 -1
  313. package/src/components/player-avatar.tsx +50 -3
  314. package/src/components/room-qr-code.tsx +36 -77
  315. package/src/components/stage-capture-surface.tsx +91 -0
  316. package/src/components/surface-viewport.tsx +16 -3
  317. package/src/components/ui/button.tsx +1 -1
  318. package/src/constants.ts +0 -15
  319. package/src/context/air-jam-context.tsx +56 -187
  320. package/src/context/session-providers.tsx +13 -10
  321. package/src/controller-bridge.ts +7 -0
  322. package/src/core/assets.ts +48 -0
  323. package/src/core/config.ts +70 -0
  324. package/src/core/connection-store.ts +77 -0
  325. package/src/core/controller-input.ts +147 -0
  326. package/src/core/controller-runtime.ts +427 -0
  327. package/src/core/dev-events.ts +18 -0
  328. package/src/core/environment.ts +132 -0
  329. package/src/core/game-description.ts +44 -0
  330. package/src/core/game.ts +130 -0
  331. package/src/core/host-input.ts +207 -0
  332. package/src/core/host-runtime.ts +988 -0
  333. package/src/core/hosted-rooms.ts +26 -0
  334. package/src/core/input-bindings.ts +180 -0
  335. package/src/core/input-log.ts +144 -0
  336. package/src/core/input.ts +228 -0
  337. package/src/core/local-input.ts +319 -0
  338. package/src/core/replay-input-log.ts +298 -0
  339. package/src/core/replicated-store.ts +1178 -0
  340. package/src/core/room-action-ack.ts +43 -0
  341. package/src/core/settings.ts +202 -0
  342. package/src/core/simulation.ts +307 -0
  343. package/src/core/theme.ts +33 -0
  344. package/src/core.ts +162 -0
  345. package/src/dev/browser-log-sink.ts +35 -12
  346. package/src/diagnostics.ts +5 -6
  347. package/src/hooks/internal/use-controller-runtime-api.ts +58 -925
  348. package/src/hooks/internal/use-host-runtime-api.ts +98 -1270
  349. package/src/hooks/internal/use-runtime-inspection-contract.ts +14 -2
  350. package/src/hooks/use-air-jam-controller.ts +32 -53
  351. package/src/hooks/use-air-jam-host.ts +59 -100
  352. package/src/hooks/use-air-jam-settings.ts +27 -0
  353. package/src/hooks/use-controller-toasts.ts +16 -19
  354. package/src/hooks/use-host-agent-capture.ts +31 -0
  355. package/src/hooks/use-lifecycle-action-group-model.ts +1 -1
  356. package/src/hooks/use-send-signal.ts +23 -156
  357. package/src/hooks/use-simulation.ts +83 -0
  358. package/src/index.ts +24 -85
  359. package/src/lifecycle/index.ts +0 -4
  360. package/src/lifecycle/standard-match-phase.ts +1 -22
  361. package/src/metadata/manifest.ts +8 -19
  362. package/src/metadata.ts +1 -1
  363. package/src/platform-machine.ts +127 -3
  364. package/src/prefabs/types.ts +91 -20
  365. package/src/prefabs/view.ts +82 -0
  366. package/src/prefabs.ts +19 -0
  367. package/src/preview/host-workspace.tsx +4 -9
  368. package/src/preview/identity.ts +31 -23
  369. package/src/preview/layout.ts +5 -1
  370. package/src/preview/manager.ts +205 -78
  371. package/src/preview/messages.ts +47 -0
  372. package/src/preview/ownership.ts +6 -1
  373. package/src/preview/url.ts +46 -23
  374. package/src/preview/window.tsx +26 -69
  375. package/src/preview/workspace-local-seats.ts +166 -0
  376. package/src/preview/workspace.tsx +89 -37
  377. package/src/preview.ts +27 -15
  378. package/src/protocol/actions.ts +58 -0
  379. package/src/protocol/arcade-platform-actions.ts +2 -16
  380. package/src/protocol/controller.ts +14 -174
  381. package/src/protocol/core.ts +8 -15
  382. package/src/protocol/dev-log-events.ts +5 -81
  383. package/src/protocol/leased-control.ts +177 -0
  384. package/src/protocol/room/addressing.ts +35 -0
  385. package/src/protocol/room/close-codes.ts +33 -0
  386. package/src/protocol/room/frames.ts +343 -0
  387. package/src/protocol/room/input-codec.ts +182 -0
  388. package/src/protocol/room/limits.ts +58 -0
  389. package/src/protocol/room/patch.ts +135 -0
  390. package/src/protocol/room/sdk-channels.ts +81 -0
  391. package/src/protocol/room/seat-id.ts +31 -0
  392. package/src/protocol/room/transport.ts +63 -0
  393. package/src/protocol/room/weight.ts +58 -0
  394. package/src/protocol/runtime-reporting.ts +56 -10
  395. package/src/protocol.ts +2 -7
  396. package/src/qrcode.d.ts +3 -13
  397. package/src/room-protocol.ts +10 -0
  398. package/src/room-session/browser-wake-events.ts +14 -0
  399. package/src/room-session/channel-state.ts +293 -0
  400. package/src/room-session/clock.ts +24 -0
  401. package/src/room-session/host-room-session.ts +379 -0
  402. package/src/room-session/input-lane.ts +125 -0
  403. package/src/room-session/listeners.ts +22 -0
  404. package/src/room-session/loopback-link.ts +58 -0
  405. package/src/room-session/phone-room-session.ts +368 -0
  406. package/src/room-session/port-link.ts +116 -0
  407. package/src/room-session/room-key.ts +9 -0
  408. package/src/room-session/roster.ts +23 -0
  409. package/src/room-session/scoped-connector.ts +577 -0
  410. package/src/room-session/session-link.ts +306 -0
  411. package/src/room-session/web-socket-link.ts +57 -0
  412. package/src/room-session.ts +12 -0
  413. package/src/runtime/air-jam-config.ts +49 -37
  414. package/src/runtime/air-jam-error-boundary.tsx +9 -3
  415. package/src/runtime/arcade-runtime-url.ts +8 -9
  416. package/src/runtime/browser-controller-environment.ts +116 -0
  417. package/src/runtime/browser-host-environment.ts +137 -0
  418. package/src/runtime/browser-replay.ts +211 -0
  419. package/src/runtime/browser-room.ts +41 -0
  420. package/src/runtime/connected-runtime-error-boundary.tsx +35 -8
  421. package/src/runtime/contracts/agent-control.ts +195 -0
  422. package/src/runtime/contracts/clip.ts +169 -0
  423. package/src/runtime/contracts/control.ts +653 -16
  424. package/src/runtime/contracts/controller-agent.ts +130 -0
  425. package/src/runtime/contracts/input-log.ts +38 -0
  426. package/src/runtime/contracts/inspection.ts +25 -22
  427. package/src/runtime/contracts/observation.ts +186 -0
  428. package/src/runtime/contracts/runtime-identity.ts +43 -0
  429. package/src/runtime/contracts/timeline.ts +59 -0
  430. package/src/runtime/controller-agent-bridge.ts +152 -0
  431. package/src/runtime/controller-bridge-context.ts +29 -0
  432. package/src/runtime/controller-capture.ts +50 -0
  433. package/src/runtime/controller-identity.ts +53 -142
  434. package/src/runtime/controller-presentation.ts +47 -17
  435. package/src/runtime/controller-press.ts +271 -0
  436. package/src/runtime/create-air-jam-app.tsx +103 -74
  437. package/src/runtime/dev-runtime-events.ts +6 -18
  438. package/src/runtime/embedded-parent.ts +22 -0
  439. package/src/runtime/embedded-runtime-adapters.ts +10 -9
  440. package/src/runtime/host-agent-bridge.ts +127 -0
  441. package/src/runtime/host-capture-boundary.tsx +92 -0
  442. package/src/runtime/host-capture-context.ts +7 -0
  443. package/src/runtime/host-clip-reader.ts +93 -0
  444. package/src/runtime/host-clip-recorder.ts +342 -0
  445. package/src/runtime/host-input-log-reader.ts +120 -0
  446. package/src/runtime/host-observation.ts +207 -0
  447. package/src/runtime/host-pace.ts +36 -0
  448. package/src/runtime/host-runtime-fault.ts +51 -0
  449. package/src/runtime/host-timeline.ts +152 -0
  450. package/src/runtime/local-players.tsx +96 -0
  451. package/src/runtime/local-seats.ts +612 -0
  452. package/src/runtime/participant-control.ts +162 -0
  453. package/src/runtime/prefab-inspection-bridge.ts +174 -0
  454. package/src/runtime/prefab-inspection-clock.ts +12 -0
  455. package/src/runtime/prefab-inspection-context.ts +20 -0
  456. package/src/runtime/prefab-inspection-runtime.tsx +328 -0
  457. package/src/runtime/preview-inspection-bridge.ts +130 -0
  458. package/src/runtime/replay-runtime.tsx +101 -0
  459. package/src/runtime/room-bridge.ts +110 -0
  460. package/src/runtime/runtime-owner-contexts.tsx +9 -0
  461. package/src/runtime/runtime-session-params.ts +20 -23
  462. package/src/runtime/session-runtimes.tsx +231 -64
  463. package/src/runtime/stage-capture.ts +25 -0
  464. package/src/runtime-control.ts +41 -0
  465. package/src/runtime-inspection.ts +14 -7
  466. package/src/runtime-topology.ts +7 -8
  467. package/src/settings/platform-settings-runtime.tsx +47 -2
  468. package/src/settings/platform-settings.ts +0 -65
  469. package/src/store/use-air-jam-store.ts +73 -0
  470. package/src/ui.ts +3 -3
  471. package/src/utils/is-rpc-serializable.ts +11 -19
  472. package/src/utils/url-builder.ts +0 -7
  473. package/dist/air-jam-context-BlLPvCup.d.cts +0 -175
  474. package/dist/air-jam-context-DTsxF-tP.d.ts +0 -175
  475. package/dist/arcade/bridge.cjs +0 -1087
  476. package/dist/arcade/bridge.cjs.map +0 -1
  477. package/dist/arcade/bridge.d.cts +0 -11
  478. package/dist/arcade/bridge.d.ts +0 -11
  479. package/dist/arcade/bridge.js +0 -78
  480. package/dist/arcade/bridge.js.map +0 -1
  481. package/dist/arcade-runtime-url-BW-MUAOY.d.cts +0 -28
  482. package/dist/arcade-runtime-url-l8qj01Pg.d.ts +0 -28
  483. package/dist/arcade.cjs +0 -1767
  484. package/dist/arcade.cjs.map +0 -1
  485. package/dist/arcade.d.cts +0 -18
  486. package/dist/arcade.d.ts +0 -18
  487. package/dist/arcade.js +0 -129
  488. package/dist/arcade.js.map +0 -1
  489. package/dist/chunk-2SZ2YYGJ.js +0 -280
  490. package/dist/chunk-2SZ2YYGJ.js.map +0 -1
  491. package/dist/chunk-32RSSFSF.js +0 -214
  492. package/dist/chunk-32RSSFSF.js.map +0 -1
  493. package/dist/chunk-3USU7GY2.js.map +0 -1
  494. package/dist/chunk-3YMUAKPU.js +0 -10
  495. package/dist/chunk-3YMUAKPU.js.map +0 -1
  496. package/dist/chunk-56DM2KEW.js +0 -14
  497. package/dist/chunk-56DM2KEW.js.map +0 -1
  498. package/dist/chunk-BE6Z4SIT.js.map +0 -1
  499. package/dist/chunk-CM53YLT5.js +0 -59
  500. package/dist/chunk-CM53YLT5.js.map +0 -1
  501. package/dist/chunk-CV3PBXPT.js.map +0 -1
  502. package/dist/chunk-D4VDEVTZ.js.map +0 -1
  503. package/dist/chunk-EVZJA6RN.js.map +0 -1
  504. package/dist/chunk-FUA6EMSJ.js +0 -90
  505. package/dist/chunk-FUA6EMSJ.js.map +0 -1
  506. package/dist/chunk-GMLU7RI5.js +0 -70
  507. package/dist/chunk-GMLU7RI5.js.map +0 -1
  508. package/dist/chunk-IG6GZZSS.js.map +0 -1
  509. package/dist/chunk-IKKDONQL.js +0 -1
  510. package/dist/chunk-IKKDONQL.js.map +0 -1
  511. package/dist/chunk-ITMQSBTH.js +0 -26
  512. package/dist/chunk-ITMQSBTH.js.map +0 -1
  513. package/dist/chunk-J5MCII33.js +0 -620
  514. package/dist/chunk-J5MCII33.js.map +0 -1
  515. package/dist/chunk-JTF47B56.js +0 -1
  516. package/dist/chunk-JTF47B56.js.map +0 -1
  517. package/dist/chunk-K4OZ54UD.js.map +0 -1
  518. package/dist/chunk-LIHEEAVE.js +0 -191
  519. package/dist/chunk-LIHEEAVE.js.map +0 -1
  520. package/dist/chunk-LIXPF4P6.js +0 -22
  521. package/dist/chunk-LIXPF4P6.js.map +0 -1
  522. package/dist/chunk-MIMPMB7O.js.map +0 -1
  523. package/dist/chunk-MPDMJIX5.js +0 -1
  524. package/dist/chunk-MPDMJIX5.js.map +0 -1
  525. package/dist/chunk-O6X7FJ6N.js.map +0 -1
  526. package/dist/chunk-PSUYTD2L.js.map +0 -1
  527. package/dist/chunk-QO4KFUEI.js +0 -32
  528. package/dist/chunk-QO4KFUEI.js.map +0 -1
  529. package/dist/chunk-QTLYZADF.js +0 -125
  530. package/dist/chunk-QTLYZADF.js.map +0 -1
  531. package/dist/chunk-TGRTEWYV.js +0 -195
  532. package/dist/chunk-TGRTEWYV.js.map +0 -1
  533. package/dist/chunk-TTQDHKXL.js +0 -3017
  534. package/dist/chunk-TTQDHKXL.js.map +0 -1
  535. package/dist/chunk-UCPY7UJC.js +0 -8
  536. package/dist/chunk-UCPY7UJC.js.map +0 -1
  537. package/dist/chunk-UPV6YWT5.js +0 -43
  538. package/dist/chunk-UPV6YWT5.js.map +0 -1
  539. package/dist/chunk-UWJOIVON.js.map +0 -1
  540. package/dist/chunk-W2VK36RO.js +0 -11
  541. package/dist/chunk-W2VK36RO.js.map +0 -1
  542. package/dist/chunk-X24K52DG.js.map +0 -1
  543. package/dist/chunk-X35LLCWV.js.map +0 -1
  544. package/dist/chunk-YXHH3MQT.js +0 -230
  545. package/dist/chunk-YXHH3MQT.js.map +0 -1
  546. package/dist/controller-PZEM_1cH.d.ts +0 -176
  547. package/dist/controller-vj82tKm4.d.cts +0 -176
  548. package/dist/dev-log-events-BCJKmygo.d.cts +0 -120
  549. package/dist/dev-log-events-BCJKmygo.d.ts +0 -120
  550. package/dist/handshake-CC_LrK5g.d.cts +0 -31
  551. package/dist/handshake-CC_LrK5g.d.ts +0 -31
  552. package/dist/host-B9pRy0Aa.d.cts +0 -122
  553. package/dist/host-DylGsX7p.d.ts +0 -122
  554. package/dist/notices-C4bao3oi.d.ts +0 -38
  555. package/dist/notices-DNdOjwtj.d.cts +0 -38
  556. package/dist/realtime-client-Cu8yVJFw.d.cts +0 -15
  557. package/dist/realtime-client-Cu8yVJFw.d.ts +0 -15
  558. package/dist/runtime-reporting-pe-eryVz.d.cts +0 -27
  559. package/dist/runtime-reporting-pe-eryVz.d.ts +0 -27
  560. package/dist/signals-ZHftIKuc.d.cts +0 -33
  561. package/dist/signals-ZHftIKuc.d.ts +0 -33
  562. package/dist/sync-xtPfWhif.d.cts +0 -81
  563. package/dist/sync-xtPfWhif.d.ts +0 -81
  564. package/src/arcade/bridge.ts +0 -3
  565. package/src/arcade.ts +0 -4
  566. package/src/context/socket-manager.ts +0 -72
  567. package/src/events.ts +0 -119
  568. package/src/hooks/use-connection-status.ts +0 -8
  569. package/src/hooks/use-controller-tick.ts +0 -65
  570. package/src/hooks/use-get-input.ts +0 -100
  571. package/src/hooks/use-host-arcade-restore.ts +0 -35
  572. package/src/hooks/use-host-tick.ts +0 -171
  573. package/src/hooks/use-input-writer.ts +0 -83
  574. package/src/hooks/use-players.ts +0 -12
  575. package/src/internal/input-manager.ts +0 -356
  576. package/src/protocol/errors.ts +0 -21
  577. package/src/protocol/host-grant.ts +0 -103
  578. package/src/protocol/host.ts +0 -150
  579. package/src/protocol/notices.ts +0 -43
  580. package/src/protocol/signals.ts +0 -38
  581. package/src/protocol/socket-events.ts +0 -152
  582. package/src/protocol/sync.ts +0 -105
  583. package/src/runtime/admission-retry.ts +0 -62
  584. package/src/runtime/bridge-envelope-args.ts +0 -21
  585. package/src/runtime/controller-bridge.ts +0 -439
  586. package/src/runtime/controller-realtime-client.ts +0 -552
  587. package/src/runtime/host-bridge.ts +0 -380
  588. package/src/runtime/host-realtime-client.ts +0 -550
  589. package/src/runtime/realtime-client.ts +0 -20
  590. package/src/runtime/validate-arcade-bridge-attach.ts +0 -14
  591. package/src/state/connection-store.ts +0 -159
  592. package/src/store/create-air-jam-store.ts +0 -1193
  593. package/src/store/index.ts +0 -1
  594. package/src/utils/ids.ts +0 -58
package/dist/index.js CHANGED
@@ -1,83 +1,86 @@
1
- import {
2
- isRpcSerializable,
3
- registerHostRuntimeActionStore
4
- } from "./chunk-QTLYZADF.js";
5
1
  import {
6
2
  AirJamControllerRuntime,
3
+ AirJamErrorBoundary,
7
4
  AirJamHostRuntime,
8
- getControllerRealtimeClient,
9
- getHostRealtimeClient
10
- } from "./chunk-TTQDHKXL.js";
11
- import "./chunk-GMLU7RI5.js";
12
- import "./chunk-D4VDEVTZ.js";
5
+ captureAgentCanvas,
6
+ devLogRuntimeErrorReporter,
7
+ drawAgentCanvas,
8
+ hostCaptureContext,
9
+ usePrefabInspection
10
+ } from "./chunk-DHFKL3DI.js";
11
+ import "./chunk-OAXCFPZ7.js";
12
+ import "./chunk-K6BJJJJM.js";
13
+ import "./chunk-S3TN7Y7L.js";
14
+ import "./chunk-3M7656SU.js";
15
+ import "./chunk-JJVCBUYM.js";
13
16
  import {
14
17
  useAirJamController
15
- } from "./chunk-X35LLCWV.js";
18
+ } from "./chunk-I6TSHJF7.js";
19
+ import "./chunk-UBBP2UY3.js";
20
+ import "./chunk-3LDQCQL2.js";
16
21
  import {
17
- agentAction,
18
- agentActionInput,
19
- agentStore,
20
- defineAirJamAgentContract,
21
- defineAirJamAgentStores
22
- } from "./chunk-TGRTEWYV.js";
23
- import "./chunk-YXHH3MQT.js";
24
- import "./chunk-LIHEEAVE.js";
25
- import "./chunk-32RSSFSF.js";
26
- import "./chunk-56DM2KEW.js";
27
- import "./chunk-X24K52DG.js";
28
- import "./chunk-FUA6EMSJ.js";
22
+ isAirJamGame
23
+ } from "./chunk-SMKD4JY3.js";
24
+ import "./chunk-VGX2274F.js";
25
+ import "./chunk-XLY44PXZ.js";
26
+ import {
27
+ fixedControllerOrientation
28
+ } from "./chunk-WGHNGQUS.js";
29
+ import "./chunk-FCG42U7D.js";
29
30
  import {
30
31
  useAirJamHost
31
- } from "./chunk-CM53YLT5.js";
32
+ } from "./chunk-URVBMQCK.js";
33
+ import "./chunk-BEM77SVQ.js";
32
34
  import {
33
- PlatformSettingsBoundary,
34
35
  PlatformSettingsRuntime,
36
+ controllerRuntimeContext,
37
+ declaredStoresContext,
38
+ hostRuntimeContext,
39
+ resolveEnvironmentRuntimeTopology,
40
+ useAirJamContext,
41
+ useAssertSessionScope,
35
42
  useInheritedPlatformSettings,
36
43
  usePlatformAudioSettings,
37
44
  usePlatformSettings,
38
45
  usePlatformSettingsRuntimeStatus,
39
46
  useResolvedPlatformSettingsSnapshot
40
- } from "./chunk-2SZ2YYGJ.js";
41
- import "./chunk-3YMUAKPU.js";
47
+ } from "./chunk-TFW4NJW2.js";
48
+ import "./chunk-QHBRHYMV.js";
49
+ import "./chunk-M5553I2G.js";
50
+ import "./chunk-EG25EXSA.js";
51
+ import "./chunk-2QZADUGA.js";
52
+ import "./chunk-LX6CTPDW.js";
53
+ import "./chunk-FJ4J2BEC.js";
54
+ import "./chunk-MD25536W.js";
55
+ import "./chunk-C5GS2GMK.js";
56
+ import "./chunk-5TVVPBQI.js";
57
+ import "./chunk-DRBPVG47.js";
42
58
  import {
43
- AIR_JAM_ARCADE_SURFACE_STORE_DOMAIN,
44
- AIR_JAM_DEFAULT_STORE_DOMAIN,
45
- resolveImplicitReplicatedStoreDomainFromWindow
46
- } from "./chunk-BE6Z4SIT.js";
47
- import "./chunk-MIMPMB7O.js";
48
- import "./chunk-CV3PBXPT.js";
49
- import {
50
- emitAirJamDiagnostic,
59
+ createAirJamDiagnosticError,
51
60
  onAirJamDiagnostic,
52
- setAirJamDiagnosticsEnabled,
53
- useAirJamContext,
54
- useAirJamSocket,
55
- useAirJamState,
56
- useAssertSessionScope
57
- } from "./chunk-O6X7FJ6N.js";
58
- import {
59
- CONTROLLER_PATH
60
- } from "./chunk-W2VK36RO.js";
61
+ setAirJamDiagnosticsEnabled
62
+ } from "./chunk-DBF7NJ3S.js";
63
+ import "./chunk-KUGROY5S.js";
64
+ import "./chunk-MJAWAHLT.js";
65
+ import "./chunk-6Y3F6Y2K.js";
66
+ import "./chunk-KSYN4I5Y.js";
67
+ import "./chunk-CDL7LYZH.js";
68
+ import "./chunk-WAFGYJZN.js";
69
+ import "./chunk-H4DEVMTO.js";
61
70
  import {
71
+ parseRuntimeTopology,
62
72
  resolveProjectRuntimeTopology
63
- } from "./chunk-UWJOIVON.js";
64
- import {
65
- emitAirJamDevRuntimeEvent
66
- } from "./chunk-LIXPF4P6.js";
67
- import {
68
- AIRJAM_DEV_LOG_EVENTS,
69
- AIRJAM_RUNTIME_ERROR_REPORT_CONTRACT_VERSION,
70
- controllerInputSchema
71
- } from "./chunk-J5MCII33.js";
72
- import "./chunk-3USU7GY2.js";
73
+ } from "./chunk-2H2FGF3H.js";
74
+ import "./chunk-C5722GTG.js";
73
75
  import {
74
76
  DEFAULT_PLATFORM_SETTINGS,
75
77
  DEFAULT_ROOM_PLATFORM_SETTINGS,
76
78
  getEffectiveAudioVolume,
77
- mergeRoomPlatformSettingsSnapshot,
78
79
  toRoomPlatformSettingsSnapshot
79
- } from "./chunk-K4OZ54UD.js";
80
- import "./chunk-UCPY7UJC.js";
80
+ } from "./chunk-5CRZFIN6.js";
81
+ import {
82
+ parseAirJamSignal
83
+ } from "./chunk-24NZZOIO.js";
81
84
 
82
85
  // src/audio/hooks.tsx
83
86
  import {
@@ -85,10 +88,9 @@ import {
85
88
  useCallback,
86
89
  useContext,
87
90
  useEffect,
88
- useMemo,
91
+ useLayoutEffect,
89
92
  useState
90
93
  } from "react";
91
- import { useStore } from "zustand";
92
94
 
93
95
  // src/audio/audio-manager.ts
94
96
  import { Howl, Howler } from "howler";
@@ -106,9 +108,8 @@ var AudioManager = class {
106
108
  categories = /* @__PURE__ */ new Map();
107
109
  manifest = {};
108
110
  _muted = false;
109
- socket = null;
110
- roomId = null;
111
- role = null;
111
+ /** Plays a sound on players' phones; set only on a host while its room runs. */
112
+ sendToControllers = null;
112
113
  activeSoundIds = /* @__PURE__ */ new Map();
113
114
  audioSettings = DEFAULT_PLATFORM_SETTINGS.audio;
114
115
  constructor(manifest) {
@@ -117,14 +118,17 @@ var AudioManager = class {
117
118
  }
118
119
  }
119
120
  destroy() {
121
+ this.sounds.forEach((sound) => sound.unload());
122
+ this.sounds.clear();
123
+ this.categories.clear();
124
+ this.activeSoundIds.clear();
125
+ this.manifest = {};
120
126
  }
121
127
  getCategory(soundId) {
122
128
  return this.categories.get(soundId) ?? "sfx";
123
129
  }
124
- setSocket(socket, roomId, role) {
125
- this.socket = socket;
126
- if (roomId) this.roomId = roomId;
127
- if (role) this.role = role;
130
+ setControllerSounds(send) {
131
+ this.sendToControllers = send;
128
132
  }
129
133
  async init() {
130
134
  if (!Howler.ctx) {
@@ -240,26 +244,14 @@ var AudioManager = class {
240
244
  return soundId;
241
245
  }
242
246
  playRemote(id, target, volume, loop) {
243
- if (!this.socket || !this.roomId) return;
244
- if (this.isHost()) {
245
- this.socket.emit("host:play_sound", {
246
- roomId: this.roomId,
247
- targetControllerId: target,
247
+ this.sendToControllers?.(
248
+ {
248
249
  soundId: id,
249
- volume,
250
- loop
251
- });
252
- return;
253
- }
254
- this.socket.emit("controller:play_sound", {
255
- roomId: this.roomId,
256
- soundId: id,
257
- volume,
258
- loop
259
- });
260
- }
261
- isHost() {
262
- return this.role === "host";
250
+ ...volume === void 0 ? {} : { volume },
251
+ ...loop === void 0 ? {} : { loop }
252
+ },
253
+ target
254
+ );
263
255
  }
264
256
  playSpatial(id, pos, sprite) {
265
257
  void this.init();
@@ -369,7 +361,25 @@ function AudioRuntime({
369
361
  manifest,
370
362
  children
371
363
  }) {
372
- const { manager, status, controls } = useOwnedAudio(manifest);
364
+ const [manager, setManager] = useState(
365
+ null
366
+ );
367
+ useLayoutEffect(() => {
368
+ const manager2 = new AudioManager(manifest);
369
+ setManager(manager2);
370
+ return () => manager2.destroy();
371
+ }, [manifest]);
372
+ if (!manager) {
373
+ return null;
374
+ }
375
+ return /* @__PURE__ */ jsx(MountedAudioRuntime, { manifest, manager, children });
376
+ }
377
+ function MountedAudioRuntime({
378
+ manifest,
379
+ manager,
380
+ children
381
+ }) {
382
+ const { status, controls } = useAudioRuntimeState(manager);
373
383
  useRemoteSound(manifest, manager);
374
384
  return /* @__PURE__ */ jsx(audioRuntimeStatusContext.Provider, { value: status, children: /* @__PURE__ */ jsx(audioRuntimeControlsContext.Provider, { value: controls, children: /* @__PURE__ */ jsx(audioManagerContext.Provider, { value: manager, children }) }) });
375
385
  }
@@ -398,17 +408,13 @@ function useAudioRuntimeControls() {
398
408
  }
399
409
  return controls;
400
410
  }
401
- function useOwnedAudio(manifest) {
402
- const { store, getSocket } = useAirJamContext();
403
- const roomId = useStore(store, (state) => state.roomId);
404
- const role = useStore(store, (state) => state.role);
411
+ function useAudioRuntimeState(manager) {
412
+ const host = useContext(
413
+ hostRuntimeContext
414
+ );
405
415
  const platformSettings = useResolvedPlatformSettingsSnapshot();
406
416
  const platformSettingsStatus = usePlatformSettingsRuntimeStatus();
407
417
  const platformSettingsReady = platformSettingsStatus === "ready";
408
- const manager = useMemo(
409
- () => new AudioManager(manifest),
410
- [manifest]
411
- );
412
418
  const [status, setStatus] = useState(
413
419
  () => globalInitialized && platformSettingsReady ? "ready" : "idle"
414
420
  );
@@ -439,21 +445,9 @@ function useOwnedAudio(manifest) {
439
445
  setStatus("idle");
440
446
  }, [platformSettingsReady]);
441
447
  useEffect(() => {
442
- if (role && roomId) {
443
- const directSocket = getSocket(role);
444
- if (!directSocket) {
445
- manager.setSocket(null, roomId, role);
446
- return;
447
- }
448
- const realtimeClient = role === "controller" ? getControllerRealtimeClient(() => directSocket) : getHostRealtimeClient(() => directSocket);
449
- manager.setSocket(realtimeClient, roomId, role);
450
- }
451
- }, [manager, role, roomId, getSocket]);
452
- useEffect(() => {
453
- return () => {
454
- manager.destroy();
455
- };
456
- }, [manager]);
448
+ manager.setControllerSounds(host?.playSoundOnControllers ?? null);
449
+ return () => manager.setControllerSounds(null);
450
+ }, [manager, host]);
457
451
  useEffect(() => {
458
452
  void retry();
459
453
  }, [retry]);
@@ -478,7 +472,6 @@ function useOwnedAudio(manifest) {
478
472
  };
479
473
  }, [retry, status]);
480
474
  return {
481
- manager,
482
475
  status,
483
476
  controls: {
484
477
  retry
@@ -487,42 +480,27 @@ function useOwnedAudio(manifest) {
487
480
  }
488
481
  var isManifestSoundId = (manifest, soundId) => typeof soundId === "string" && Object.prototype.hasOwnProperty.call(manifest, soundId);
489
482
  function useRemoteSound(manifest, audio) {
490
- const { getSocket, store } = useAirJamContext();
491
- const role = useStore(store, (state) => state.role);
492
- const connectionStatus = useStore(store, (state) => state.connectionStatus);
493
- const socket = useMemo(() => {
494
- if (role !== "controller") {
495
- return null;
496
- }
497
- const directSocket = getSocket("controller");
498
- if (!directSocket) {
499
- return null;
500
- }
501
- return getControllerRealtimeClient(() => directSocket);
502
- }, [getSocket, role]);
503
- const enabled = role === "controller" && connectionStatus === "connected";
483
+ const session = useContext(
484
+ controllerRuntimeContext
485
+ )?.session ?? null;
504
486
  useEffect(() => {
505
- if (!socket || !enabled) {
487
+ if (!session) {
506
488
  return;
507
489
  }
508
- const handlePlaySound = (payload) => {
509
- if (!isManifestSoundId(manifest, payload.id)) {
510
- return;
511
- }
512
- audio.play(payload.id, {
513
- volume: payload.volume,
514
- loop: payload.loop
490
+ return session.on("signal", (received) => {
491
+ const signal = parseAirJamSignal(received);
492
+ if (signal?.kind !== "sound") return;
493
+ if (!isManifestSoundId(manifest, signal.payload.soundId)) return;
494
+ audio.play(signal.payload.soundId, {
495
+ volume: signal.payload.volume,
496
+ loop: signal.payload.loop
515
497
  });
516
- };
517
- socket.on("server:playSound", handlePlaySound);
518
- return () => {
519
- socket.off("server:playSound", handlePlaySound);
520
- };
521
- }, [audio, enabled, manifest, socket]);
498
+ });
499
+ }, [audio, manifest, session]);
522
500
  }
523
501
 
524
502
  // src/audio/music.tsx
525
- import { useEffect as useEffect2, useMemo as useMemo2, useRef } from "react";
503
+ import { useEffect as useEffect2, useMemo, useRef } from "react";
526
504
  function useAudioCategoryVolume(category) {
527
505
  const settingsStatus = usePlatformSettingsRuntimeStatus();
528
506
  const settings = useResolvedPlatformSettingsSnapshot();
@@ -549,7 +527,7 @@ function MusicPlaylist({
549
527
  const activeRef = useRef(null);
550
528
  const generationRef = useRef(0);
551
529
  const tracksRef = useRef(tracks);
552
- const tracksKey = useMemo2(() => tracks.join("\0"), [tracks]);
530
+ const tracksKey = useMemo(() => tracks.join("\0"), [tracks]);
553
531
  tracksRef.current = tracks;
554
532
  useEffect2(() => {
555
533
  const generation = generationRef.current + 1;
@@ -611,66 +589,20 @@ function MusicPlaylist({
611
589
  return null;
612
590
  }
613
591
 
614
- // src/hooks/use-connection-status.ts
615
- import { useStore as useStore2 } from "zustand";
616
- var useConnectionStatus = () => {
617
- const { store } = useAirJamContext();
618
- return useStore2(store, (state) => state.connectionStatus);
619
- };
620
-
621
- // src/hooks/use-controller-tick.ts
622
- import { useEffect as useEffect3, useRef as useRef2 } from "react";
623
- var DEFAULT_CONTROLLER_TICK_MS = 16;
624
- var useControllerTick = (callback, options = {}) => {
625
- useAssertSessionScope("controller", "useControllerTick");
626
- const { enabled = true, intervalMs = DEFAULT_CONTROLLER_TICK_MS } = options;
627
- const callbackRef = useRef2(callback);
628
- useEffect3(() => {
629
- callbackRef.current = callback;
630
- }, [callback]);
631
- useEffect3(() => {
632
- if (!enabled) {
633
- return;
634
- }
635
- if (typeof window === "undefined") {
636
- return;
637
- }
638
- let tick = 0;
639
- let lastTime = performance.now();
640
- const intervalId = window.setInterval(() => {
641
- const now = performance.now();
642
- const deltaMs = now - lastTime;
643
- lastTime = now;
644
- tick += 1;
645
- callbackRef.current({
646
- now,
647
- deltaMs,
648
- deltaSeconds: deltaMs / 1e3,
649
- tick
650
- });
651
- }, intervalMs);
652
- return () => {
653
- window.clearInterval(intervalId);
654
- };
655
- }, [enabled, intervalMs]);
656
- };
657
-
658
592
  // src/hooks/use-controller-toasts.ts
659
- import { useCallback as useCallback2, useEffect as useEffect4, useMemo as useMemo3, useRef as useRef3, useState as useState2 } from "react";
593
+ import { useCallback as useCallback2, useContext as useContext2, useEffect as useEffect3, useRef as useRef2, useState as useState2 } from "react";
660
594
  var DEFAULT_MAX_TOASTS = 3;
661
595
  var DEFAULT_TOAST_DURATION_MS = 2200;
662
596
  var buildToastId = () => `toast_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
663
597
  var useControllerToasts = (options = {}) => {
664
598
  useAssertSessionScope("controller", "useControllerToasts");
665
- const { getSocket } = useAirJamContext();
666
- const socket = useMemo3(
667
- () => getControllerRealtimeClient((role) => getSocket(role)),
668
- [getSocket]
669
- );
599
+ const session = useContext2(
600
+ controllerRuntimeContext
601
+ )?.session ?? null;
670
602
  const maxToasts = options.maxToasts ?? DEFAULT_MAX_TOASTS;
671
603
  const defaultDurationMs = options.defaultDurationMs ?? DEFAULT_TOAST_DURATION_MS;
672
604
  const [toasts, setToasts] = useState2([]);
673
- const toastTimeoutsRef = useRef3(
605
+ const toastTimeoutsRef = useRef2(
674
606
  /* @__PURE__ */ new Map()
675
607
  );
676
608
  const dismissToast = useCallback2((toastId) => {
@@ -688,12 +620,13 @@ var useControllerToasts = (options = {}) => {
688
620
  toastTimeoutsRef.current.clear();
689
621
  setToasts([]);
690
622
  }, []);
691
- useEffect4(() => {
692
- if (!socket) {
623
+ useEffect3(() => {
624
+ if (!session) {
693
625
  return;
694
626
  }
695
- const handleSignal = (signal) => {
696
- if (signal.type !== "TOAST") {
627
+ return session.on("signal", (received) => {
628
+ const signal = parseAirJamSignal(received);
629
+ if (signal?.kind !== "toast") {
697
630
  return;
698
631
  }
699
632
  const toast = {
@@ -710,13 +643,9 @@ var useControllerToasts = (options = {}) => {
710
643
  dismissToast(toast.id);
711
644
  }, duration);
712
645
  toastTimeoutsRef.current.set(toast.id, timeout);
713
- };
714
- socket.on("server:signal", handleSignal);
715
- return () => {
716
- socket.off("server:signal", handleSignal);
717
- };
718
- }, [defaultDurationMs, dismissToast, maxToasts, socket]);
719
- useEffect4(
646
+ });
647
+ }, [defaultDurationMs, dismissToast, maxToasts, session]);
648
+ useEffect3(
720
649
  () => () => {
721
650
  for (const timeout of toastTimeoutsRef.current.values()) {
722
651
  clearTimeout(timeout);
@@ -733,24 +662,33 @@ var useControllerToasts = (options = {}) => {
733
662
  };
734
663
  };
735
664
 
736
- // src/hooks/use-get-input.ts
737
- import { useCallback as useCallback3 } from "react";
738
- var useGetInput = () => {
739
- useAssertSessionScope("host", "useGetInput");
740
- const { inputManager } = useAirJamContext();
741
- return useCallback3(
742
- (controllerId) => {
743
- if (!inputManager) {
744
- return void 0;
665
+ // src/hooks/use-host-agent-capture.ts
666
+ import { useCallback as useCallback3, useContext as useContext3, useLayoutEffect as useLayoutEffect2, useRef as useRef3 } from "react";
667
+ function useHostAgentCapture(capture) {
668
+ const owner = useContext3(hostCaptureContext);
669
+ if (!owner)
670
+ throw createAirJamDiagnosticError(
671
+ "AJ_SCOPE_MISMATCH",
672
+ "useHostAgentCapture requires a mounted host runtime boundary. Wrap the host tree with <airjam.Host>.",
673
+ {
674
+ hookName: "useHostAgentCapture",
675
+ expectedScope: "host",
676
+ receivedScope: "host"
745
677
  }
746
- return inputManager.getInput(controllerId);
747
- },
748
- [inputManager]
749
- );
750
- };
678
+ );
679
+ const current = useRef3(capture);
680
+ useLayoutEffect2(() => {
681
+ current.current = capture;
682
+ });
683
+ useLayoutEffect2(() => {
684
+ owner.setDraw((canvas, options) => current.current(canvas, options));
685
+ return () => owner.setDraw(null);
686
+ }, [owner]);
687
+ return useCallback3(() => owner.rendered(), [owner]);
688
+ }
751
689
 
752
690
  // src/hooks/use-host-audio-mute-preference.ts
753
- import { useCallback as useCallback4, useEffect as useEffect5, useMemo as useMemo4, useState as useState3 } from "react";
691
+ import { useCallback as useCallback4, useEffect as useEffect4, useMemo as useMemo2, useState as useState3 } from "react";
754
692
  var HOST_AUDIO_MUTE_STORAGE_KEY_PREFIX = "air-jam-host-audio-muted:";
755
693
  var getHostAudioMuteStorageKey = (scope) => `${HOST_AUDIO_MUTE_STORAGE_KEY_PREFIX}${scope}`;
756
694
  var readHostAudioMutePreference = (storageKey, fallback) => {
@@ -773,14 +711,14 @@ var persistHostAudioMutePreference = (storageKey, muted) => {
773
711
  window.localStorage.setItem(storageKey, muted ? "true" : "false");
774
712
  };
775
713
  var useHostAudioMutePreference = (scope, defaultMuted = false) => {
776
- const storageKey = useMemo4(() => getHostAudioMuteStorageKey(scope), [scope]);
714
+ const storageKey = useMemo2(() => getHostAudioMuteStorageKey(scope), [scope]);
777
715
  const [muted, setMutedState] = useState3(
778
716
  () => readHostAudioMutePreference(storageKey, defaultMuted)
779
717
  );
780
- useEffect5(() => {
718
+ useEffect4(() => {
781
719
  setMutedState(readHostAudioMutePreference(storageKey, defaultMuted));
782
720
  }, [defaultMuted, storageKey]);
783
- useEffect5(() => {
721
+ useEffect4(() => {
784
722
  if (typeof window === "undefined") {
785
723
  return;
786
724
  }
@@ -819,202 +757,14 @@ var useHostAudioMutePreference = (scope, defaultMuted = false) => {
819
757
  };
820
758
  };
821
759
 
822
- // src/hooks/use-host-tick.ts
823
- import { useEffect as useEffect6, useRef as useRef4 } from "react";
824
- var DEFAULT_HOST_TICK_MS = 16;
825
- var DEFAULT_HOST_MAX_DELTA_MS = 250;
826
- var DEFAULT_HOST_MAX_STEPS_PER_FRAME = 5;
827
- var useHostTick = (options) => {
828
- useAssertSessionScope("host", "useHostTick");
829
- const {
830
- onTick,
831
- enabled = true,
832
- mode = "raf",
833
- intervalMs = DEFAULT_HOST_TICK_MS,
834
- maxDeltaMs = DEFAULT_HOST_MAX_DELTA_MS,
835
- maxStepsPerFrame = DEFAULT_HOST_MAX_STEPS_PER_FRAME,
836
- onFrame
837
- } = options;
838
- const tickIntervalMs = Math.max(1, intervalMs);
839
- const frameDeltaCapMs = Math.max(tickIntervalMs, maxDeltaMs);
840
- const frameStepCap = Math.max(1, maxStepsPerFrame);
841
- const onTickRef = useRef4(onTick);
842
- const onFrameRef = useRef4(onFrame);
843
- useEffect6(() => {
844
- onTickRef.current = onTick;
845
- }, [onTick]);
846
- useEffect6(() => {
847
- onFrameRef.current = onFrame;
848
- }, [onFrame]);
849
- useEffect6(() => {
850
- if (!enabled) {
851
- return;
852
- }
853
- if (typeof window === "undefined") {
854
- return;
855
- }
856
- let tick = 0;
857
- let frameCount = 0;
858
- let lastTime = performance.now();
859
- if (mode === "interval") {
860
- const intervalId = window.setInterval(() => {
861
- const now = performance.now();
862
- const deltaMs = now - lastTime;
863
- lastTime = now;
864
- tick += 1;
865
- onTickRef.current({
866
- now,
867
- deltaMs,
868
- deltaSeconds: deltaMs / 1e3,
869
- tick
870
- });
871
- }, tickIntervalMs);
872
- return () => {
873
- window.clearInterval(intervalId);
874
- };
875
- }
876
- let rafId = 0;
877
- if (mode === "fixed") {
878
- let accumulatorMs = 0;
879
- const frame2 = (now) => {
880
- const frameDeltaMs = Math.max(
881
- 0,
882
- Math.min(now - lastTime, frameDeltaCapMs)
883
- );
884
- frameCount += 1;
885
- lastTime = now;
886
- accumulatorMs += frameDeltaMs;
887
- let stepsThisFrame = 0;
888
- while (accumulatorMs >= tickIntervalMs && stepsThisFrame < frameStepCap) {
889
- tick += 1;
890
- onTickRef.current({
891
- now,
892
- deltaMs: tickIntervalMs,
893
- deltaSeconds: tickIntervalMs / 1e3,
894
- tick
895
- });
896
- accumulatorMs -= tickIntervalMs;
897
- stepsThisFrame += 1;
898
- }
899
- if (stepsThisFrame === frameStepCap) {
900
- accumulatorMs = 0;
901
- }
902
- onFrameRef.current?.({
903
- now,
904
- deltaMs: frameDeltaMs,
905
- deltaSeconds: frameDeltaMs / 1e3,
906
- frame: frameCount,
907
- fixedStepAlpha: Math.min(1, accumulatorMs / tickIntervalMs)
908
- });
909
- rafId = window.requestAnimationFrame(frame2);
910
- };
911
- rafId = window.requestAnimationFrame(frame2);
912
- return () => {
913
- window.cancelAnimationFrame(rafId);
914
- };
915
- }
916
- const frame = (now) => {
917
- const deltaMs = now - lastTime;
918
- lastTime = now;
919
- tick += 1;
920
- onTickRef.current({
921
- now,
922
- deltaMs,
923
- deltaSeconds: deltaMs / 1e3,
924
- tick
925
- });
926
- rafId = window.requestAnimationFrame(frame);
927
- };
928
- rafId = window.requestAnimationFrame(frame);
929
- return () => {
930
- window.cancelAnimationFrame(rafId);
931
- };
932
- }, [enabled, mode, tickIntervalMs, frameDeltaCapMs, frameStepCap]);
933
- };
934
-
935
- // src/hooks/use-input-writer.ts
936
- import { useCallback as useCallback5 } from "react";
937
- var useInputWriter = () => {
938
- useAssertSessionScope("controller", "useInputWriter");
939
- const { store, getSocket } = useAirJamContext();
940
- return useCallback5(
941
- (input) => {
942
- if (typeof input !== "object" || input === null || Array.isArray(input)) {
943
- emitAirJamDiagnostic({
944
- code: "AJ_INPUT_WRITER_INVALID_SHAPE",
945
- severity: "warn",
946
- message: "Input writer payload must be a plain object."
947
- });
948
- return false;
949
- }
950
- if (!isRpcSerializable(input)) {
951
- emitAirJamDiagnostic({
952
- code: "AJ_INPUT_WRITER_NOT_SERIALIZABLE",
953
- severity: "warn",
954
- message: "Input writer payload must be RPC-serializable."
955
- });
956
- return false;
957
- }
958
- const state = store.getState();
959
- if (!state.roomId || !state.controllerId) {
960
- emitAirJamDiagnostic({
961
- code: "AJ_INPUT_WRITER_SESSION_NOT_READY",
962
- severity: "warn",
963
- message: "Input writer blocked: room/controller session is not ready."
964
- });
965
- return false;
966
- }
967
- const socket = getControllerRealtimeClient((role) => getSocket(role));
968
- if (!socket.connected) {
969
- emitAirJamDiagnostic({
970
- code: "AJ_INPUT_WRITER_SOCKET_DISCONNECTED",
971
- severity: "warn",
972
- message: "Input writer blocked: controller socket is disconnected."
973
- });
974
- return false;
975
- }
976
- const payload = controllerInputSchema.safeParse({
977
- roomId: state.roomId,
978
- controllerId: state.controllerId,
979
- input
980
- });
981
- if (!payload.success) {
982
- emitAirJamDiagnostic({
983
- code: "AJ_INPUT_WRITER_SCHEMA_INVALID",
984
- severity: "warn",
985
- message: "Input writer payload failed controller input schema validation.",
986
- details: {
987
- issueCount: payload.error.issues.length
988
- }
989
- });
990
- return false;
991
- }
992
- socket.emit("controller:input", payload.data);
993
- return true;
994
- },
995
- [getSocket, store]
996
- );
997
- };
998
-
999
- // src/hooks/use-players.ts
1000
- import { useStore as useStore3 } from "zustand";
1001
- import { useShallow } from "zustand/react/shallow";
1002
- var usePlayers = () => {
1003
- const { store } = useAirJamContext();
1004
- return useStore3(
1005
- store,
1006
- useShallow((state) => state.players)
1007
- );
1008
- };
1009
-
1010
760
  // src/hooks/use-room.ts
1011
- import { useStore as useStore4 } from "zustand";
1012
- import { useShallow as useShallow2 } from "zustand/react/shallow";
761
+ import { useStore } from "zustand";
762
+ import { useShallow } from "zustand/react/shallow";
1013
763
  var useRoom = () => {
1014
764
  const { store } = useAirJamContext();
1015
- return useStore4(
765
+ return useStore(
1016
766
  store,
1017
- useShallow2((state) => ({
767
+ useShallow((state) => ({
1018
768
  roomId: state.roomId,
1019
769
  runtimeState: state.runtimeState,
1020
770
  mode: state.mode
@@ -1023,44 +773,26 @@ var useRoom = () => {
1023
773
  };
1024
774
 
1025
775
  // src/hooks/use-send-signal.ts
1026
- import { useCallback as useCallback6 } from "react";
776
+ import { useContext as useContext4 } from "react";
1027
777
  var useSendSignal = () => {
1028
778
  useAssertSessionScope("host", "useSendSignal");
1029
- const { getSocket } = useAirJamContext();
1030
- const sendSignal = useCallback6(
1031
- (type, payload, targetId) => {
1032
- const socket = getHostRealtimeClient((role) => getSocket(role));
1033
- if (!socket || !socket.connected) {
1034
- return;
1035
- }
1036
- const signal = {
1037
- targetId,
1038
- type,
1039
- payload
1040
- };
1041
- socket.emit("host:signal", signal);
1042
- },
1043
- [getSocket]
779
+ const runtime = useContext4(
780
+ hostRuntimeContext
1044
781
  );
1045
- return sendSignal;
782
+ if (!runtime)
783
+ throw createAirJamDiagnosticError(
784
+ "AJ_SCOPE_MISMATCH",
785
+ "useSendSignal requires a mounted host runtime boundary. Wrap the host tree with <airjam.Host>.",
786
+ {
787
+ hookName: "useSendSignal",
788
+ expectedScope: "host",
789
+ receivedScope: "host"
790
+ }
791
+ );
792
+ return runtime.sendSignal;
1046
793
  };
1047
794
 
1048
795
  // src/lifecycle/standard-match-phase.ts
1049
- var standardMatchPhases = [
1050
- "lobby",
1051
- "countdown",
1052
- "playing",
1053
- "ended"
1054
- ];
1055
- var isStandardMatchPhase = (value) => {
1056
- return standardMatchPhases.includes(value);
1057
- };
1058
- var isActiveMatchPhase = (phase) => {
1059
- return phase === "countdown" || phase === "playing";
1060
- };
1061
- var isEndedMatchPhase = (phase) => {
1062
- return phase === "ended";
1063
- };
1064
796
  var toShellMatchPhase = (phase) => {
1065
797
  if (phase === "countdown") {
1066
798
  return "playing";
@@ -1068,696 +800,41 @@ var toShellMatchPhase = (phase) => {
1068
800
  return phase;
1069
801
  };
1070
802
 
1071
- // src/runtime/air-jam-error-boundary.tsx
1072
- import {
1073
- Check,
1074
- Copy,
1075
- Maximize2,
1076
- Minimize2,
1077
- RefreshCw,
1078
- RotateCcw
1079
- } from "lucide-react";
1080
- import { Component, useCallback as useCallback7, useEffect as useEffect7, useRef as useRef5, useState as useState4 } from "react";
1081
- import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
1082
- var toError = (value) => {
1083
- if (value instanceof Error) {
1084
- return value;
1085
- }
1086
- if (typeof value === "string") {
1087
- return new Error(value);
1088
- }
1089
- return new Error("Unknown runtime error");
1090
- };
1091
- var isEmbeddedRuntime = () => typeof window !== "undefined" && typeof window.parent !== "undefined" && window.parent !== window;
1092
- var roleLabel = (role) => role === "host" ? "Host runtime" : "Controller runtime";
1093
- var mono = "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, monospace";
1094
- var errorSurface = {
1095
- bg: "#0a0a0a",
1096
- panel: "#141414",
1097
- panelBorder: "rgba(255, 255, 255, 0.08)",
1098
- inset: "#0c0c0c",
1099
- insetBorder: "rgba(255, 255, 255, 0.06)",
1100
- text: "#fafafa",
1101
- muted: "#a3a3a3",
1102
- dim: "#737373",
1103
- zOverlay: 2147483e3
1104
- };
1105
- var iconSize = 16;
1106
- var createErrorDigest = (error) => {
1107
- const input = `${error.name}:${error.message}:${error.stack ?? ""}`;
1108
- let hash = 0;
1109
- for (let index = 0; index < input.length; index += 1) {
1110
- hash = hash * 31 + input.charCodeAt(index) >>> 0;
1111
- }
1112
- return hash.toString(16).padStart(8, "0");
1113
- };
1114
- var createRuntimeReportId = () => {
1115
- const direct = globalThis.crypto?.randomUUID?.();
1116
- if (direct) return direct;
1117
- const bytes = new Uint8Array(16);
1118
- if (globalThis.crypto?.getRandomValues) {
1119
- globalThis.crypto.getRandomValues(bytes);
1120
- } else {
1121
- for (let index = 0; index < bytes.length; index += 1) {
1122
- bytes[index] = Math.floor(Math.random() * 256);
1123
- }
1124
- }
1125
- bytes[6] = bytes[6] & 15 | 64;
1126
- bytes[8] = bytes[8] & 63 | 128;
1127
- const hex = Array.from(
1128
- bytes,
1129
- (value) => value.toString(16).padStart(2, "0")
1130
- ).join("");
1131
- return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
1132
- };
1133
- var copyTextToClipboard = async (text) => {
1134
- if (typeof navigator !== "undefined" && navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
1135
- await navigator.clipboard.writeText(text);
1136
- return;
1137
- }
1138
- if (typeof document === "undefined") {
1139
- throw new Error("Clipboard is unavailable");
1140
- }
1141
- const textarea = document.createElement("textarea");
1142
- textarea.value = text;
1143
- textarea.style.position = "fixed";
1144
- textarea.style.opacity = "0";
1145
- textarea.style.pointerEvents = "none";
1146
- document.body.appendChild(textarea);
1147
- textarea.focus();
1148
- textarea.select();
1149
- const succeeded = typeof document.execCommand === "function" ? document.execCommand("copy") : false;
1150
- document.body.removeChild(textarea);
1151
- if (!succeeded) {
1152
- throw new Error("Copy command failed");
1153
- }
1154
- };
1155
- var createCopyPayload = ({
1156
- role,
1157
- roomId,
1158
- appId,
1159
- error,
1160
- digest,
1161
- isEmbedded
1162
- }) => {
1163
- const lines = [
1164
- "AirJam Runtime Error",
1165
- `Role: ${role}`,
1166
- `Digest: ${digest}`,
1167
- `Embedded: ${isEmbedded ? "yes" : "no"}`,
1168
- roomId ? `Room: ${roomId}` : null,
1169
- appId ? `App ID: ${appId}` : null,
1170
- `Error: ${error.message || "Unknown error"}`,
1171
- "",
1172
- "Stack:",
1173
- error.stack ?? "(no stack)"
1174
- ].filter((line) => line !== null);
1175
- return lines.join("\n");
1176
- };
1177
- var btnRow = {
1178
- display: "inline-flex",
1179
- alignItems: "center",
1180
- justifyContent: "center",
1181
- gap: "0.35rem",
1182
- borderRadius: "0.5rem",
1183
- padding: "0.5rem 0.75rem",
1184
- fontSize: "0.8125rem",
1185
- fontWeight: 600,
1186
- cursor: "pointer",
1187
- fontFamily: "ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif"
1188
- };
1189
- var DefaultFallback = ({
1190
- role,
1191
- roomId,
1192
- appId,
1193
- error,
1194
- reset,
1195
- reload,
1196
- isEmbedded
1197
- }) => {
1198
- const digest = createErrorDigest(error);
1199
- const [isMinimized, setIsMinimized] = useState4(false);
1200
- const [copyState, setCopyState] = useState4(
1201
- "idle"
1202
- );
1203
- const copyResetTimeoutRef = useRef5(null);
1204
- useEffect7(() => {
1205
- return () => {
1206
- if (copyResetTimeoutRef.current !== null && typeof window !== "undefined") {
1207
- window.clearTimeout(copyResetTimeoutRef.current);
1208
- }
1209
- };
1210
- }, []);
1211
- const scheduleCopyStatusReset = useCallback7(() => {
1212
- if (typeof window === "undefined") {
1213
- return;
1214
- }
1215
- if (copyResetTimeoutRef.current !== null) {
1216
- window.clearTimeout(copyResetTimeoutRef.current);
1217
- }
1218
- copyResetTimeoutRef.current = window.setTimeout(() => {
1219
- setCopyState("idle");
1220
- copyResetTimeoutRef.current = null;
1221
- }, 1800);
1222
- }, []);
1223
- const handleCopy = useCallback7(async () => {
1224
- try {
1225
- await copyTextToClipboard(
1226
- createCopyPayload({
1227
- role,
1228
- roomId,
1229
- appId,
1230
- error,
1231
- isEmbedded,
1232
- digest
1233
- })
1234
- );
1235
- setCopyState("copied");
1236
- scheduleCopyStatusReset();
1237
- } catch {
1238
- setCopyState("failed");
1239
- scheduleCopyStatusReset();
1240
- }
1241
- }, [appId, digest, error, isEmbedded, role, roomId, scheduleCopyStatusReset]);
1242
- const copyButtonLabel = copyState === "copied" ? "Copied" : copyState === "failed" ? "Copy failed" : "Copy details";
1243
- const CopyGlyph = copyState === "copied" ? /* @__PURE__ */ jsx2(Check, { size: iconSize, strokeWidth: 2, "aria-hidden": true }) : /* @__PURE__ */ jsx2(Copy, { size: iconSize, strokeWidth: 2, "aria-hidden": true });
1244
- if (isMinimized) {
1245
- return /* @__PURE__ */ jsxs(Fragment, { children: [
1246
- /* @__PURE__ */ jsx2(
1247
- "div",
1248
- {
1249
- "aria-hidden": true,
1250
- style: {
1251
- position: "fixed",
1252
- inset: 0,
1253
- zIndex: errorSurface.zOverlay,
1254
- background: "rgba(10, 10, 10, 0.72)"
1255
- }
1256
- }
1257
- ),
1258
- /* @__PURE__ */ jsxs(
1259
- "div",
1260
- {
1261
- style: {
1262
- position: "fixed",
1263
- bottom: "1rem",
1264
- right: "1rem",
1265
- zIndex: errorSurface.zOverlay + 1,
1266
- maxWidth: "min(22rem, calc(100vw - 2rem))",
1267
- borderRadius: "0.625rem",
1268
- border: `1px solid ${errorSurface.panelBorder}`,
1269
- background: errorSurface.panel,
1270
- boxShadow: "0 16px 48px rgba(0, 0, 0, 0.55)",
1271
- padding: "0.75rem 0.85rem"
1272
- },
1273
- children: [
1274
- /* @__PURE__ */ jsxs(
1275
- "div",
1276
- {
1277
- style: {
1278
- display: "flex",
1279
- alignItems: "flex-start",
1280
- justifyContent: "space-between",
1281
- gap: "0.5rem"
1282
- },
1283
- children: [
1284
- /* @__PURE__ */ jsxs("div", { style: { minWidth: 0 }, children: [
1285
- /* @__PURE__ */ jsx2(
1286
- "div",
1287
- {
1288
- style: {
1289
- fontSize: "0.6875rem",
1290
- fontWeight: 600,
1291
- letterSpacing: "0.02em",
1292
- color: errorSurface.dim,
1293
- textTransform: "uppercase"
1294
- },
1295
- children: "AirJam \xB7 runtime error"
1296
- }
1297
- ),
1298
- /* @__PURE__ */ jsxs(
1299
- "div",
1300
- {
1301
- style: {
1302
- marginTop: "0.25rem",
1303
- fontSize: "0.75rem",
1304
- color: errorSurface.muted,
1305
- fontFamily: mono,
1306
- lineHeight: 1.4,
1307
- wordBreak: "break-word"
1308
- },
1309
- children: [
1310
- role,
1311
- " \xB7 ",
1312
- digest
1313
- ]
1314
- }
1315
- )
1316
- ] }),
1317
- /* @__PURE__ */ jsx2(
1318
- "button",
1319
- {
1320
- type: "button",
1321
- onClick: () => setIsMinimized(false),
1322
- "aria-label": "Expand error panel",
1323
- title: "Expand error panel",
1324
- style: {
1325
- ...btnRow,
1326
- flexShrink: 0,
1327
- border: `1px solid ${errorSurface.panelBorder}`,
1328
- background: errorSurface.inset,
1329
- color: errorSurface.text,
1330
- padding: "0.4rem"
1331
- },
1332
- children: /* @__PURE__ */ jsx2(Maximize2, { size: iconSize, strokeWidth: 2, "aria-hidden": true })
1333
- }
1334
- )
1335
- ]
1336
- }
1337
- ),
1338
- /* @__PURE__ */ jsxs(
1339
- "div",
1340
- {
1341
- style: {
1342
- marginTop: "0.65rem",
1343
- display: "flex",
1344
- flexWrap: "wrap",
1345
- gap: "0.4rem"
1346
- },
1347
- children: [
1348
- /* @__PURE__ */ jsxs(
1349
- "button",
1350
- {
1351
- type: "button",
1352
- onClick: () => {
1353
- void handleCopy();
1354
- },
1355
- style: {
1356
- ...btnRow,
1357
- border: `1px solid ${errorSurface.panelBorder}`,
1358
- background: "transparent",
1359
- color: errorSurface.muted
1360
- },
1361
- children: [
1362
- CopyGlyph,
1363
- copyButtonLabel
1364
- ]
1365
- }
1366
- ),
1367
- /* @__PURE__ */ jsxs(
1368
- "button",
1369
- {
1370
- type: "button",
1371
- onClick: reload,
1372
- style: {
1373
- ...btnRow,
1374
- border: "none",
1375
- background: errorSurface.text,
1376
- color: errorSurface.bg
1377
- },
1378
- children: [
1379
- /* @__PURE__ */ jsx2(RefreshCw, { size: iconSize, strokeWidth: 2, "aria-hidden": true }),
1380
- "Reload"
1381
- ]
1382
- }
1383
- )
1384
- ]
1385
- }
1386
- )
1387
- ]
1388
- }
1389
- )
1390
- ] });
1391
- }
1392
- return /* @__PURE__ */ jsx2(
1393
- "div",
1394
- {
1395
- style: {
1396
- minHeight: "100vh",
1397
- width: "100%",
1398
- display: "flex",
1399
- alignItems: "center",
1400
- justifyContent: "center",
1401
- background: errorSurface.bg,
1402
- padding: "1.5rem 1rem",
1403
- boxSizing: "border-box"
1404
- },
1405
- children: /* @__PURE__ */ jsxs(
1406
- "div",
1407
- {
1408
- style: {
1409
- position: "relative",
1410
- width: "100%",
1411
- maxWidth: "42rem",
1412
- borderRadius: "0.625rem",
1413
- border: `1px solid ${errorSurface.panelBorder}`,
1414
- background: errorSurface.panel,
1415
- boxShadow: "0 24px 64px rgba(0, 0, 0, 0.45)",
1416
- padding: "1.25rem 1.35rem",
1417
- boxSizing: "border-box"
1418
- },
1419
- children: [
1420
- /* @__PURE__ */ jsx2(
1421
- "button",
1422
- {
1423
- type: "button",
1424
- onClick: () => setIsMinimized(true),
1425
- "aria-label": "Minimize error panel",
1426
- title: "Minimize error panel",
1427
- style: {
1428
- ...btnRow,
1429
- position: "absolute",
1430
- top: "0.85rem",
1431
- right: "0.85rem",
1432
- padding: "0.4rem",
1433
- border: `1px solid ${errorSurface.panelBorder}`,
1434
- background: errorSurface.inset,
1435
- color: errorSurface.muted
1436
- },
1437
- children: /* @__PURE__ */ jsx2(Minimize2, { size: iconSize, strokeWidth: 2, "aria-hidden": true })
1438
- }
1439
- ),
1440
- /* @__PURE__ */ jsxs(
1441
- "div",
1442
- {
1443
- style: {
1444
- fontSize: "0.6875rem",
1445
- fontWeight: 500,
1446
- letterSpacing: "0.04em",
1447
- color: errorSurface.dim,
1448
- textTransform: "uppercase",
1449
- paddingRight: "2.5rem"
1450
- },
1451
- children: [
1452
- "AirJam \xB7 runtime error \xB7 ",
1453
- role
1454
- ]
1455
- }
1456
- ),
1457
- /* @__PURE__ */ jsx2(
1458
- "h1",
1459
- {
1460
- style: {
1461
- marginTop: "0.65rem",
1462
- marginBottom: 0,
1463
- fontSize: "1.25rem",
1464
- lineHeight: 1.25,
1465
- fontWeight: 600,
1466
- color: errorSurface.text,
1467
- fontFamily: "ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif"
1468
- },
1469
- children: "Something went wrong"
1470
- }
1471
- ),
1472
- /* @__PURE__ */ jsxs(
1473
- "p",
1474
- {
1475
- style: {
1476
- marginTop: "0.45rem",
1477
- marginBottom: 0,
1478
- fontSize: "0.8125rem",
1479
- color: errorSurface.muted,
1480
- lineHeight: 1.45
1481
- },
1482
- children: [
1483
- roleLabel(role),
1484
- " hit an error. Details below."
1485
- ]
1486
- }
1487
- ),
1488
- /* @__PURE__ */ jsxs(
1489
- "div",
1490
- {
1491
- style: {
1492
- marginTop: "1rem",
1493
- border: `1px solid ${errorSurface.insetBorder}`,
1494
- borderRadius: "0.5rem",
1495
- background: errorSurface.inset,
1496
- padding: "0.75rem 0.85rem",
1497
- fontSize: "0.75rem",
1498
- color: errorSurface.muted,
1499
- fontFamily: mono,
1500
- lineHeight: 1.5,
1501
- wordBreak: "break-word"
1502
- },
1503
- children: [
1504
- /* @__PURE__ */ jsxs("div", { children: [
1505
- /* @__PURE__ */ jsx2("span", { style: { color: errorSurface.dim }, children: "Digest " }),
1506
- digest
1507
- ] }),
1508
- roomId ? /* @__PURE__ */ jsxs("div", { style: { marginTop: "0.35rem" }, children: [
1509
- /* @__PURE__ */ jsx2("span", { style: { color: errorSurface.dim }, children: "Room " }),
1510
- roomId
1511
- ] }) : null,
1512
- /* @__PURE__ */ jsxs("div", { style: { marginTop: "0.35rem" }, children: [
1513
- /* @__PURE__ */ jsx2("span", { style: { color: errorSurface.dim }, children: "Error " }),
1514
- error.message || "Unknown error"
1515
- ] })
1516
- ]
1517
- }
1518
- ),
1519
- /* @__PURE__ */ jsxs(
1520
- "details",
1521
- {
1522
- style: {
1523
- marginTop: "0.75rem",
1524
- fontSize: "0.75rem",
1525
- color: errorSurface.muted
1526
- },
1527
- children: [
1528
- /* @__PURE__ */ jsx2(
1529
- "summary",
1530
- {
1531
- style: {
1532
- cursor: "pointer",
1533
- fontWeight: 500,
1534
- color: errorSurface.muted,
1535
- listStyle: "none"
1536
- },
1537
- children: "Stack trace"
1538
- }
1539
- ),
1540
- /* @__PURE__ */ jsx2(
1541
- "pre",
1542
- {
1543
- style: {
1544
- marginTop: "0.5rem",
1545
- marginBottom: 0,
1546
- overflowX: "auto",
1547
- whiteSpace: "pre-wrap",
1548
- wordBreak: "break-word",
1549
- border: `1px solid ${errorSurface.insetBorder}`,
1550
- borderRadius: "0.45rem",
1551
- background: errorSurface.inset,
1552
- padding: "0.65rem 0.75rem",
1553
- color: errorSurface.muted,
1554
- fontFamily: mono,
1555
- fontSize: "0.6875rem",
1556
- lineHeight: 1.45
1557
- },
1558
- children: error.stack ?? error.message
1559
- }
1560
- )
1561
- ]
1562
- }
1563
- ),
1564
- /* @__PURE__ */ jsxs(
1565
- "div",
1566
- {
1567
- style: {
1568
- marginTop: "1.1rem",
1569
- display: "flex",
1570
- flexWrap: "wrap",
1571
- alignItems: "center",
1572
- gap: "0.45rem"
1573
- },
1574
- children: [
1575
- /* @__PURE__ */ jsxs(
1576
- "button",
1577
- {
1578
- type: "button",
1579
- onClick: reload,
1580
- style: {
1581
- ...btnRow,
1582
- border: "none",
1583
- background: errorSurface.text,
1584
- color: errorSurface.bg
1585
- },
1586
- children: [
1587
- /* @__PURE__ */ jsx2(RefreshCw, { size: iconSize, strokeWidth: 2, "aria-hidden": true }),
1588
- "Reload"
1589
- ]
1590
- }
1591
- ),
1592
- /* @__PURE__ */ jsxs(
1593
- "button",
1594
- {
1595
- type: "button",
1596
- onClick: reset,
1597
- style: {
1598
- ...btnRow,
1599
- border: `1px solid ${errorSurface.panelBorder}`,
1600
- background: "transparent",
1601
- color: errorSurface.text
1602
- },
1603
- children: [
1604
- /* @__PURE__ */ jsx2(RotateCcw, { size: iconSize, strokeWidth: 2, "aria-hidden": true }),
1605
- "Try again"
1606
- ]
1607
- }
1608
- ),
1609
- /* @__PURE__ */ jsxs(
1610
- "button",
1611
- {
1612
- type: "button",
1613
- onClick: () => {
1614
- void handleCopy();
1615
- },
1616
- style: {
1617
- ...btnRow,
1618
- border: `1px solid ${errorSurface.panelBorder}`,
1619
- background: "transparent",
1620
- color: errorSurface.muted
1621
- },
1622
- children: [
1623
- CopyGlyph,
1624
- copyButtonLabel
1625
- ]
1626
- }
1627
- )
1628
- ]
1629
- }
1630
- ),
1631
- isEmbedded ? /* @__PURE__ */ jsx2(
1632
- "p",
1633
- {
1634
- style: {
1635
- marginTop: "0.85rem",
1636
- marginBottom: 0,
1637
- fontSize: "0.6875rem",
1638
- color: errorSurface.dim,
1639
- lineHeight: 1.4,
1640
- fontFamily: mono
1641
- },
1642
- children: "Embedded: if reload loops, exit and relaunch from the Arcade shell."
1643
- }
1644
- ) : null
1645
- ]
1646
- }
1647
- )
1648
- }
1649
- );
1650
- };
1651
- var AirJamErrorBoundary = class extends Component {
1652
- state = {
1653
- error: null
1654
- };
1655
- static getDerivedStateFromError(error) {
1656
- return {
1657
- error: toError(error)
1658
- };
1659
- }
1660
- componentDidCatch(error, errorInfo) {
1661
- const { role, roomId, appId, onError, reportError } = this.props;
1662
- const details = {
1663
- role,
1664
- roomId,
1665
- appId,
1666
- name: error.name,
1667
- message: error.message,
1668
- stack: error.stack,
1669
- componentStack: errorInfo.componentStack
1670
- };
1671
- emitAirJamDiagnostic({
1672
- code: "AJ_RUNTIME_RENDER_CRASH",
1673
- severity: "error",
1674
- message: `[AirJam] ${role} runtime crashed during render.`,
1675
- details
1676
- });
1677
- emitAirJamDevRuntimeEvent({
1678
- event: AIRJAM_DEV_LOG_EVENTS.browser.runtime,
1679
- level: "error",
1680
- message: `AirJam ${role} runtime crashed during render`,
1681
- role,
1682
- roomId,
1683
- code: "AJ_RUNTIME_RENDER_CRASH",
1684
- data: details
1685
- });
1686
- if (roomId && reportError) {
1687
- try {
1688
- reportError({
1689
- contractVersion: AIRJAM_RUNTIME_ERROR_REPORT_CONTRACT_VERSION,
1690
- reportId: createRuntimeReportId(),
1691
- roomId,
1692
- role,
1693
- code: "AJ_RUNTIME_RENDER_CRASH",
1694
- errorName: /^[A-Za-z][A-Za-z0-9._-]{0,79}$/u.test(error.name) ? error.name : "Error",
1695
- digest: createErrorDigest(error),
1696
- occurredAt: (/* @__PURE__ */ new Date()).toISOString()
1697
- });
1698
- } catch {
1699
- }
1700
- }
1701
- onError?.(error, errorInfo, {
1702
- role,
1703
- roomId,
1704
- appId
1705
- });
1706
- }
1707
- handleReset = () => {
1708
- this.setState({ error: null });
1709
- };
1710
- handleReload = () => {
1711
- if (typeof window !== "undefined") {
1712
- window.location.reload();
1713
- }
1714
- };
1715
- render() {
1716
- const { error } = this.state;
1717
- const { children, role, roomId, appId, renderFallback } = this.props;
1718
- if (!error) {
1719
- return /* @__PURE__ */ jsx2(Fragment, { children });
1720
- }
1721
- const fallbackProps = {
1722
- role,
1723
- roomId,
1724
- appId,
1725
- error,
1726
- reset: this.handleReset,
1727
- reload: this.handleReload,
1728
- isEmbedded: isEmbeddedRuntime()
1729
- };
1730
- if (renderFallback) {
1731
- return renderFallback(fallbackProps);
1732
- }
1733
- return /* @__PURE__ */ jsx2(DefaultFallback, { ...fallbackProps });
1734
- }
1735
- };
1736
-
1737
803
  // src/runtime/connected-runtime-error-boundary.tsx
1738
- import { useCallback as useCallback8 } from "react";
1739
- import { jsx as jsx3 } from "react/jsx-runtime";
804
+ import { useCallback as useCallback5, useContext as useContext5 } from "react";
805
+ import { jsx as jsx2 } from "react/jsx-runtime";
1740
806
  var ConnectedRuntimeErrorBoundary = ({
1741
807
  role,
1742
808
  ...props
1743
809
  }) => {
1744
- const socket = useAirJamSocket(role);
1745
- const reportError = useCallback8(
1746
- (report) => {
1747
- socket.emit("runtime:error_report", report, () => {
810
+ const { config } = useAirJamContext();
811
+ const host = useContext5(
812
+ hostRuntimeContext
813
+ );
814
+ const controller = useContext5(
815
+ controllerRuntimeContext
816
+ );
817
+ const reportError = useCallback5(
818
+ (draft) => {
819
+ const room = role === "host" ? host?.room : controller?.session;
820
+ const code = room?.code;
821
+ const instance = room?.instance;
822
+ if (!code || !instance) return;
823
+ const seat = controller?.session?.seat ?? void 0;
824
+ (config.reportError ?? devLogRuntimeErrorReporter)({
825
+ ...draft,
826
+ roomId: code,
827
+ instance,
828
+ ...role === "controller" && seat ? { seat } : {}
1748
829
  });
1749
830
  },
1750
- [socket]
831
+ [config.reportError, controller, host, role]
1751
832
  );
1752
- return /* @__PURE__ */ jsx3(AirJamErrorBoundary, { ...props, role, reportError });
833
+ return /* @__PURE__ */ jsx2(AirJamErrorBoundary, { ...props, role, reportError });
1753
834
  };
1754
835
 
1755
836
  // src/runtime/create-air-jam-app.tsx
1756
- import { jsx as jsx4 } from "react/jsx-runtime";
1757
- var resolveControllerPath = (controllerPath) => {
1758
- const normalized = controllerPath ?? CONTROLLER_PATH;
1759
- return normalized.startsWith("/") ? normalized : `/${normalized}`;
1760
- };
837
+ import { jsx as jsx3, jsxs } from "react/jsx-runtime";
1761
838
  var toViteEnvLike = (source) => {
1762
839
  if (!source) {
1763
840
  return void 0;
@@ -1794,9 +871,7 @@ var env = {
1794
871
  }),
1795
872
  vite: (viteEnvInput) => {
1796
873
  const viteEnv = toViteEnvLike(viteEnvInput) ?? readViteEnv();
1797
- const explicitTopology = viteEnv?.VITE_AIR_JAM_RUNTIME_TOPOLOGY ? JSON.parse(
1798
- viteEnv.VITE_AIR_JAM_RUNTIME_TOPOLOGY
1799
- ) : null;
874
+ const explicitTopology = viteEnv?.VITE_AIR_JAM_RUNTIME_TOPOLOGY ? parseRuntimeTopology(viteEnv.VITE_AIR_JAM_RUNTIME_TOPOLOGY) : null;
1800
875
  const projectTopology = !explicitTopology && viteEnv?.VITE_AIR_JAM_PUBLIC_HOST ? resolveProjectRuntimeTopology({
1801
876
  runtimeMode: viteEnv.DEV ? viteEnv.VITE_AIR_JAM_PUBLIC_HOST.startsWith("https://") ? "standalone-secure" : "standalone-dev" : "self-hosted-production",
1802
877
  surfaceRole: "host",
@@ -1805,11 +880,15 @@ var env = {
1805
880
  publicHost: viteEnv.VITE_AIR_JAM_PUBLIC_HOST,
1806
881
  secureTransport: viteEnv.VITE_AIR_JAM_PUBLIC_HOST.startsWith("https://")
1807
882
  }) : null;
883
+ const topology = resolveEnvironmentRuntimeTopology(
884
+ explicitTopology ?? projectTopology,
885
+ viteEnv?.DEV === true
886
+ );
1808
887
  return {
1809
- ...explicitTopology || projectTopology ? { topology: explicitTopology ?? projectTopology ?? void 0 } : {},
888
+ ...topology ? { topology } : {},
1810
889
  appId: viteEnv?.VITE_AIR_JAM_APP_ID,
1811
890
  hostGrantEndpoint: viteEnv?.VITE_AIR_JAM_HOST_GRANT_ENDPOINT,
1812
- resolveEnv: explicitTopology || projectTopology ? false : true
891
+ resolveEnv: topology ? false : true
1813
892
  };
1814
893
  },
1815
894
  next: () => ({
@@ -1820,22 +899,37 @@ var env = {
1820
899
  resolveEnv: false
1821
900
  })
1822
901
  };
1823
- var createAirJamApp = ({
1824
- runtime = {},
1825
- metadata,
1826
- controllerPath: requestedControllerPath,
1827
- agent,
1828
- input,
1829
- errorBoundary
1830
- } = {}) => {
1831
- const controllerPath = resolveControllerPath(requestedControllerPath);
1832
- const hostSession = input ? {
1833
- ...runtime,
1834
- hostSessionKind: runtime.hostSessionKind ?? "game",
1835
- input
1836
- } : {
902
+ var createAirJamApp = (game, { runtime = {}, errorBoundary } = {}) => {
903
+ if (!isAirJamGame(game))
904
+ throw new Error(
905
+ "createAirJamApp requires a game from defineAirJamGame in @air-jam/sdk/core; pass runtime options as the second argument."
906
+ );
907
+ const {
908
+ metadata,
909
+ controllerPath,
910
+ agent,
911
+ stores,
912
+ simulation,
913
+ settings,
914
+ input,
915
+ inputBindings
916
+ } = game;
917
+ const soundsFor = (surface) => Object.fromEntries(
918
+ Object.entries(game.assets?.sounds ?? {}).filter(
919
+ ([, sound]) => !sound.surface || sound.surface === surface
920
+ )
921
+ );
922
+ const hostSounds = soundsFor("host");
923
+ const controllerSounds = soundsFor("controller");
924
+ const themeProperties = Object.entries(game.theme ?? {}).flatMap(
925
+ ([kind, tokens]) => Object.entries(tokens).map(
926
+ ([id, value]) => `--airjam-${kind === "colors" ? "color" : "font"}-${id.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)}:${value};`
927
+ )
928
+ ).join("");
929
+ const themeStyle = `:root{${themeProperties}}`;
930
+ const hostSession = {
1837
931
  ...runtime,
1838
- hostSessionKind: runtime.hostSessionKind ?? "game"
932
+ maxPlayers: metadata.maxPlayers
1839
933
  };
1840
934
  const controllerSession = {
1841
935
  ...runtime
@@ -1845,7 +939,7 @@ var createAirJamApp = ({
1845
939
  ...runtimeOptions
1846
940
  }) => {
1847
941
  const hostErrorBoundary = errorBoundary?.host;
1848
- return /* @__PURE__ */ jsx4(
942
+ return /* @__PURE__ */ jsx3(
1849
943
  AirJamErrorBoundary,
1850
944
  {
1851
945
  role: "host",
@@ -1853,17 +947,38 @@ var createAirJamApp = ({
1853
947
  appId: hostSession.appId,
1854
948
  renderFallback: hostErrorBoundary?.renderFallback,
1855
949
  onError: hostErrorBoundary?.onError,
1856
- children: /* @__PURE__ */ jsx4(AirJamHostRuntime, { ...hostSession, ...runtimeOptions, children: /* @__PURE__ */ jsx4(
1857
- ConnectedRuntimeErrorBoundary,
950
+ children: /* @__PURE__ */ jsx3(
951
+ AirJamHostRuntime,
1858
952
  {
1859
- role: "host",
1860
- roomId: runtimeOptions.roomId,
1861
- appId: hostSession.appId,
1862
- renderFallback: hostErrorBoundary?.renderFallback,
1863
- onError: hostErrorBoundary?.onError,
1864
- children
953
+ ...hostSession,
954
+ ...runtimeOptions,
955
+ prefabs: game.prefabs,
956
+ agent,
957
+ gameId: metadata.slug,
958
+ fixedControllerOrientation: fixedControllerOrientation(
959
+ metadata.inputModalities
960
+ ),
961
+ stores,
962
+ simulation,
963
+ settings,
964
+ input,
965
+ inputBindings,
966
+ children: /* @__PURE__ */ jsxs(
967
+ ConnectedRuntimeErrorBoundary,
968
+ {
969
+ role: "host",
970
+ roomId: runtimeOptions.roomId,
971
+ appId: hostSession.appId,
972
+ renderFallback: hostErrorBoundary?.renderFallback,
973
+ onError: hostErrorBoundary?.onError,
974
+ children: [
975
+ /* @__PURE__ */ jsx3("style", { children: themeStyle }),
976
+ /* @__PURE__ */ jsx3(AudioRuntime, { manifest: hostSounds, children })
977
+ ]
978
+ }
979
+ )
1865
980
  }
1866
- ) })
981
+ )
1867
982
  }
1868
983
  );
1869
984
  };
@@ -1872,7 +987,7 @@ var createAirJamApp = ({
1872
987
  ...runtimeOptions
1873
988
  }) => {
1874
989
  const controllerErrorBoundary = errorBoundary?.controller;
1875
- return /* @__PURE__ */ jsx4(
990
+ return /* @__PURE__ */ jsx3(
1876
991
  AirJamErrorBoundary,
1877
992
  {
1878
993
  role: "controller",
@@ -1880,17 +995,32 @@ var createAirJamApp = ({
1880
995
  appId: controllerSession.appId,
1881
996
  renderFallback: controllerErrorBoundary?.renderFallback,
1882
997
  onError: controllerErrorBoundary?.onError,
1883
- children: /* @__PURE__ */ jsx4(AirJamControllerRuntime, { ...controllerSession, ...runtimeOptions, children: /* @__PURE__ */ jsx4(
1884
- ConnectedRuntimeErrorBoundary,
998
+ children: /* @__PURE__ */ jsx3(
999
+ AirJamControllerRuntime,
1885
1000
  {
1886
- role: "controller",
1887
- roomId: runtimeOptions.roomId,
1888
- appId: controllerSession.appId,
1889
- renderFallback: controllerErrorBoundary?.renderFallback,
1890
- onError: controllerErrorBoundary?.onError,
1891
- children
1001
+ ...controllerSession,
1002
+ ...runtimeOptions,
1003
+ fixedControllerOrientation: fixedControllerOrientation(
1004
+ metadata.inputModalities
1005
+ ),
1006
+ stores,
1007
+ input,
1008
+ children: /* @__PURE__ */ jsxs(
1009
+ ConnectedRuntimeErrorBoundary,
1010
+ {
1011
+ role: "controller",
1012
+ roomId: runtimeOptions.roomId,
1013
+ appId: controllerSession.appId,
1014
+ renderFallback: controllerErrorBoundary?.renderFallback,
1015
+ onError: controllerErrorBoundary?.onError,
1016
+ children: [
1017
+ /* @__PURE__ */ jsx3("style", { children: themeStyle }),
1018
+ /* @__PURE__ */ jsx3(AudioRuntime, { manifest: controllerSounds, children })
1019
+ ]
1020
+ }
1021
+ )
1892
1022
  }
1893
- ) })
1023
+ )
1894
1024
  }
1895
1025
  );
1896
1026
  };
@@ -1903,11 +1033,7 @@ var createAirJamApp = ({
1903
1033
  session: {
1904
1034
  host: hostSession,
1905
1035
  controller: controllerSession
1906
- },
1907
- runtime,
1908
- metadata,
1909
- controllerPath,
1910
- agent
1036
+ }
1911
1037
  };
1912
1038
  };
1913
1039
 
@@ -1928,773 +1054,158 @@ var resolveAirJamBrowserRouterBasename = () => {
1928
1054
  return typeof rawBase === "string" && rawBase.trim() ? normalizeBase(rawBase.trim()) : "/";
1929
1055
  };
1930
1056
 
1931
- // src/store/create-air-jam-store.ts
1932
- import { useEffect as useEffect8, useMemo as useMemo5, useRef as useRef6 } from "react";
1933
- import { create } from "zustand";
1934
- var INTERNAL_ACTION_PREFIX = "_";
1935
- var UNRESOLVED_ACTOR_ID = "unknown";
1936
- var isEventLikePayload = (payload) => {
1937
- if (payload === null || typeof payload !== "object") {
1938
- return false;
1939
- }
1940
- const candidate = payload;
1941
- return typeof candidate.preventDefault === "function" || typeof candidate.stopPropagation === "function" || typeof candidate.persist === "function" || "nativeEvent" in candidate && ("target" in candidate || "currentTarget" in candidate);
1057
+ // src/hooks/use-simulation.ts
1058
+ import {
1059
+ useCallback as useCallback6,
1060
+ useContext as useContext6,
1061
+ useEffect as useEffect5,
1062
+ useRef as useRef4,
1063
+ useSyncExternalStore
1064
+ } from "react";
1065
+ var useSimulation = () => {
1066
+ const runtime = useContext6(hostRuntimeContext);
1067
+ if (!runtime?.simulation)
1068
+ throw createAirJamDiagnosticError(
1069
+ "AJ_SIMULATION_NOT_DECLARED",
1070
+ "This host component reads the game simulation, but the host runs none. Declare it with defineAirJamGame({ simulation })."
1071
+ );
1072
+ return runtime.simulation;
1942
1073
  };
1943
- var isPlainActionPayload = (payload) => {
1944
- if (payload === null || typeof payload !== "object" || Array.isArray(payload)) {
1945
- return false;
1946
- }
1947
- const prototype = Object.getPrototypeOf(payload);
1948
- return prototype === Object.prototype || prototype === null;
1074
+ var useSimulationFrame = (onFrame) => {
1075
+ const clock = useSimulation();
1076
+ const onFrameRef = useRef4(onFrame);
1077
+ useEffect5(() => {
1078
+ onFrameRef.current = onFrame;
1079
+ });
1080
+ useEffect5(() => {
1081
+ const draw = (frame) => onFrameRef.current(frame);
1082
+ draw(clock.readFrame());
1083
+ return clock.onFrame(draw);
1084
+ }, [clock]);
1949
1085
  };
1950
- var isInternalActionName = (actionName) => actionName.startsWith(INTERNAL_ACTION_PREFIX);
1951
- var acceptAirJamAction = (result) => ({
1952
- __airJamActionAcceptance: true,
1953
- ...result !== void 0 ? { result } : {}
1954
- });
1955
- var rejectAirJamAction = (reason, message, details) => ({
1956
- __airJamActionRejection: true,
1957
- reason,
1958
- message,
1959
- ...details ? { details } : {}
1960
- });
1961
- var isAirJamActionAcceptance = (value) => typeof value === "object" && value !== null && value.__airJamActionAcceptance === true;
1962
- var isAirJamActionRejection = (value) => typeof value === "object" && value !== null && value.__airJamActionRejection === true;
1963
- var createClientRejectedActionResult = (reason, message, details) => ({
1964
- ok: false,
1965
- status: "rejected",
1966
- source: "client",
1967
- reason,
1968
- message,
1969
- ...details ? { details } : {}
1970
- });
1971
- var createServerRejectedActionResult = (reason, message, details) => ({
1972
- ok: false,
1973
- status: "rejected",
1974
- source: "server",
1975
- reason,
1976
- message,
1977
- ...details ? { details } : {}
1978
- });
1979
- var normalizeAirJamActionInvocationResult = (value, source) => {
1980
- if (isAirJamActionRejection(value)) {
1981
- return {
1982
- ok: false,
1983
- status: "rejected",
1984
- source,
1985
- reason: value.reason,
1986
- message: value.message,
1987
- ...value.details ? { details: value.details } : {}
1988
- };
1989
- }
1990
- if (isAirJamActionAcceptance(value)) {
1991
- return {
1992
- ok: true,
1993
- status: "accepted",
1994
- source,
1995
- ...value.result !== void 0 ? { result: value.result } : {}
1996
- };
1997
- }
1998
- return {
1999
- ok: true,
2000
- status: "accepted",
2001
- source,
2002
- ...value !== void 0 ? { result: value } : {}
2003
- };
1086
+ var useSimulationEvents = (listener) => {
1087
+ const clock = useSimulation();
1088
+ const listenerRef = useRef4(listener);
1089
+ useEffect5(() => {
1090
+ listenerRef.current = listener;
1091
+ });
1092
+ useEffect5(
1093
+ () => clock.onEvent((event) => listenerRef.current(event)),
1094
+ [clock]
1095
+ );
2004
1096
  };
2005
- var stripActionsFromState = (data) => {
2006
- const { actions: _ignored, ...stateData } = data;
2007
- return stateData;
1097
+ var useSimulationSelector = (selector, isEqual = Object.is) => {
1098
+ const clock = useSimulation();
1099
+ const selectedRef = useRef4(null);
1100
+ const subscribe = useCallback6(
1101
+ (onChange) => clock.onFrame(onChange),
1102
+ [clock]
1103
+ );
1104
+ const read = useCallback6(() => {
1105
+ const next = selector(clock.sim);
1106
+ const previous = selectedRef.current;
1107
+ if (previous && isEqual(previous.value, next)) return previous.value;
1108
+ selectedRef.current = { value: next };
1109
+ return next;
1110
+ }, [clock, selector, isEqual]);
1111
+ return useSyncExternalStore(subscribe, read, read);
2008
1112
  };
2009
- var toActionContext = (payload, connectedPlayerIds) => ({
2010
- actorId: payload.actor.id || UNRESOLVED_ACTOR_ID,
2011
- role: payload.actor.role,
2012
- connectedPlayerIds
2013
- });
2014
- function createAirJamStore(initializer, options) {
2015
- const store = create((set, get, api) => initializer(set, get, api));
2016
- const runtimeSnapshotRef = {
2017
- current: {
2018
- socket: null,
2019
- role: null,
2020
- roomId: null,
2021
- resolvedStoreDomain: AIR_JAM_DEFAULT_STORE_DOMAIN,
2022
- connectionStatus: null,
2023
- canBroadcastHostState: false,
2024
- hostStateSyncBlocked: false,
2025
- hostStateRevisionFloor: 0,
2026
- connectedPlayerIds: []
2027
- }
2028
- };
2029
- const runtimeBindings = /* @__PURE__ */ new Map();
2030
- const hostActionListeners = /* @__PURE__ */ new Set();
2031
- const createDispatchedActions = (mode) => {
2032
- const sourceActions = store.getState().actions;
2033
- const actionDispatch = {};
2034
- for (const actionName of Object.keys(sourceActions)) {
2035
- if (isInternalActionName(actionName)) {
2036
- continue;
2037
- }
2038
- const sourceAction = sourceActions[actionName];
2039
- actionDispatch[actionName] = async (payload) => {
2040
- const normalizedPayload = isEventLikePayload(payload) ? void 0 : payload;
2041
- if (normalizedPayload !== payload) {
2042
- emitAirJamDiagnostic({
2043
- code: "AJ_STORE_ACTION_EVENT_PAYLOAD_DROPPED",
2044
- severity: "warn",
2045
- message: `[AirJamStore] Action "${actionName}" received an event-like payload. Dropping payload and continuing.`,
2046
- details: { actionName }
2047
- });
2048
- }
2049
- const runtime = runtimeSnapshotRef.current;
2050
- if (mode.kind === "player" && runtime.role !== "host") {
2051
- emitAirJamDiagnostic({
2052
- code: "AJ_STORE_PLAYER_ACTIONS_HOST_ONLY",
2053
- severity: "warn",
2054
- message: `[AirJamStore] Player impersonation for action "${actionName}" is host-only.`,
2055
- details: {
2056
- actionName,
2057
- role: runtime.role,
2058
- controllerId: mode.controllerId
2059
- }
2060
- });
2061
- return createClientRejectedActionResult(
2062
- "player_actions_host_only",
2063
- `Store action "${actionName}" cannot impersonate a player outside the host runtime.`,
2064
- {
2065
- actionName,
2066
- ...runtime.role ? { role: runtime.role } : {},
2067
- controllerId: mode.controllerId
2068
- }
2069
- );
2070
- }
2071
- if (mode.kind === "player") {
2072
- const normalizedControllerId = mode.controllerId.trim();
2073
- if (normalizedControllerId.length === 0) {
2074
- emitAirJamDiagnostic({
2075
- code: "AJ_STORE_PLAYER_ACTIONS_INVALID_ACTOR_ID",
2076
- severity: "warn",
2077
- message: `[AirJamStore] Player impersonation for action "${actionName}" requires a non-empty controller id.`,
2078
- details: {
2079
- actionName
2080
- }
2081
- });
2082
- return createClientRejectedActionResult(
2083
- "player_actor_id_invalid",
2084
- `Store action "${actionName}" requires a non-empty controller id for player impersonation.`,
2085
- {
2086
- actionName
2087
- }
2088
- );
2089
- }
2090
- if (!runtime.connectedPlayerIds.includes(normalizedControllerId)) {
2091
- emitAirJamDiagnostic({
2092
- code: "AJ_STORE_PLAYER_ACTIONS_PLAYER_NOT_CONNECTED",
2093
- severity: "warn",
2094
- message: `[AirJamStore] Player impersonation for action "${actionName}" requires a currently connected controller.`,
2095
- details: {
2096
- actionName,
2097
- controllerId: normalizedControllerId,
2098
- connectedPlayerIds: runtime.connectedPlayerIds
2099
- }
2100
- });
2101
- return createClientRejectedActionResult(
2102
- "player_not_connected",
2103
- `Store action "${actionName}" cannot impersonate controller "${normalizedControllerId}" because it is not currently connected.`,
2104
- {
2105
- actionName,
2106
- controllerId: normalizedControllerId
2107
- }
2108
- );
2109
- }
2110
- }
2111
- if (runtime.role === "host") {
2112
- try {
2113
- const context = mode.kind === "player" ? {
2114
- actorId: mode.controllerId.trim(),
2115
- role: "controller",
2116
- connectedPlayerIds: runtime.connectedPlayerIds
2117
- } : {
2118
- actorId: "host",
2119
- role: "host",
2120
- connectedPlayerIds: runtime.connectedPlayerIds
2121
- };
2122
- const result = sourceAction(context, normalizedPayload);
2123
- const acknowledgement = normalizeAirJamActionInvocationResult(
2124
- result,
2125
- "host"
2126
- );
2127
- const typedActionName = actionName;
2128
- notifyHostActionListeners({
2129
- actionName: typedActionName,
2130
- payload: normalizedPayload,
2131
- context,
2132
- acknowledgement,
2133
- invocationKind: "local",
2134
- roomId: runtime.roomId,
2135
- storeDomain: runtime.resolvedStoreDomain
2136
- });
2137
- return acknowledgement;
2138
- } catch (error) {
2139
- const acknowledgement = {
2140
- ok: false,
2141
- status: "rejected",
2142
- source: "host",
2143
- reason: "handler_error",
2144
- message: error instanceof Error ? error.message : String(error)
2145
- };
2146
- const typedActionName = actionName;
2147
- notifyHostActionListeners({
2148
- actionName: typedActionName,
2149
- payload: normalizedPayload,
2150
- context: {
2151
- actorId: mode.kind === "player" ? mode.controllerId.trim() : "host",
2152
- role: mode.kind === "player" ? "controller" : "host",
2153
- connectedPlayerIds: runtime.connectedPlayerIds
2154
- },
2155
- acknowledgement,
2156
- invocationKind: "local",
2157
- roomId: runtime.roomId,
2158
- storeDomain: runtime.resolvedStoreDomain
2159
- });
2160
- return acknowledgement;
2161
- }
2162
- }
2163
- if (runtime.role !== "controller" || !runtime.roomId) {
2164
- emitAirJamDiagnostic({
2165
- code: "AJ_STORE_ACTION_SESSION_NOT_READY",
2166
- severity: "warn",
2167
- message: `[AirJamStore] Action "${actionName}" blocked: session role not ready.`,
2168
- details: {
2169
- actionName,
2170
- role: runtime.role,
2171
- roomId: runtime.roomId
2172
- }
2173
- });
2174
- return createClientRejectedActionResult(
2175
- "session_not_ready",
2176
- `Store action "${actionName}" cannot run because the controller session is not ready.`,
2177
- {
2178
- actionName,
2179
- ...runtime.role ? { role: runtime.role } : {},
2180
- ...runtime.roomId ? { roomId: runtime.roomId } : {}
2181
- }
2182
- );
2183
- }
2184
- const activeSocket = runtime.socket;
2185
- if (!activeSocket || !activeSocket.connected) {
2186
- emitAirJamDiagnostic({
2187
- code: "AJ_STORE_ACTION_SOCKET_DISCONNECTED",
2188
- severity: "warn",
2189
- message: `[AirJamStore] Action "${actionName}" blocked: Socket disconnected.`,
2190
- details: { actionName }
2191
- });
2192
- return createClientRejectedActionResult(
2193
- "socket_disconnected",
2194
- `Store action "${actionName}" cannot run because the controller socket is disconnected.`,
2195
- {
2196
- actionName
2197
- }
2198
- );
2199
- }
2200
- if (!isRpcSerializable(normalizedPayload)) {
2201
- emitAirJamDiagnostic({
2202
- code: "AJ_STORE_ACTION_PAYLOAD_NOT_SERIALIZABLE",
2203
- severity: "warn",
2204
- message: `[AirJamStore] Action "${actionName}" blocked: payload must be RPC-serializable.`,
2205
- details: { actionName }
2206
- });
2207
- return createClientRejectedActionResult(
2208
- "payload_not_serializable",
2209
- `Store action "${actionName}" requires an RPC-serializable payload.`,
2210
- {
2211
- actionName
2212
- }
2213
- );
2214
- }
2215
- if (normalizedPayload !== void 0 && !isPlainActionPayload(normalizedPayload)) {
2216
- emitAirJamDiagnostic({
2217
- code: "AJ_STORE_ACTION_PAYLOAD_INVALID_SHAPE",
2218
- severity: "warn",
2219
- message: `[AirJamStore] Action "${actionName}" blocked: payload must be omitted or a plain object.`,
2220
- details: { actionName }
2221
- });
2222
- return createClientRejectedActionResult(
2223
- "payload_invalid_shape",
2224
- `Store action "${actionName}" requires an omitted payload or a plain object payload.`,
2225
- {
2226
- actionName
2227
- }
2228
- );
2229
- }
2230
- return await activeSocket.emitWithAck(
2231
- "controller:action_rpc",
2232
- {
2233
- roomId: runtime.roomId,
2234
- actionName,
2235
- payload: normalizedPayload,
2236
- storeDomain: runtime.resolvedStoreDomain
2237
- }
2238
- );
2239
- };
2240
- }
2241
- return actionDispatch;
2242
- };
2243
- const notifyHostActionListeners = (event) => {
2244
- for (const registration of hostActionListeners) {
2245
- if (registration.actionNames && !registration.actionNames.has(event.actionName)) {
2246
- continue;
2247
- }
2248
- if (!registration.includeRejected && event.acknowledgement.status === "rejected") {
2249
- continue;
2250
- }
2251
- try {
2252
- registration.listener(event);
2253
- } catch (error) {
2254
- console.error(
2255
- `[AirJamStore] Host action listener for "${event.actionName}" threw.`,
2256
- error
2257
- );
2258
- }
2259
- }
2260
- };
2261
- const createRuntimeBinding = ({
2262
- socket,
2263
- role,
2264
- roomId,
2265
- resolvedStoreDomain
2266
- }) => {
2267
- if (role === "host") {
2268
- let syncedStateData = stripActionsFromState(store.getState());
2269
- let syncedStateSignature = JSON.stringify(syncedStateData);
2270
- let syncRevision = runtimeSnapshotRef.current.hostStateRevisionFloor;
2271
- const emitHostStateSync = (requestId) => {
2272
- const runtime = runtimeSnapshotRef.current;
2273
- if (runtime.role !== "host" || runtime.roomId !== roomId || runtime.resolvedStoreDomain !== resolvedStoreDomain || !runtime.canBroadcastHostState || !runtime.socket) {
2274
- return;
2275
- }
2276
- syncRevision = Math.max(syncRevision, runtime.hostStateRevisionFloor);
2277
- runtime.socket.emit("host:state_sync", {
2278
- roomId,
2279
- data: syncedStateData,
2280
- storeDomain: resolvedStoreDomain,
2281
- revision: syncRevision,
2282
- ...requestId ? { requestId } : {}
2283
- });
2284
- };
2285
- const flushHostStateSync = (requestId) => {
2286
- emitHostStateSync(requestId);
2287
- };
2288
- const handleControllerJoined = () => {
2289
- flushHostStateSync();
2290
- };
2291
- const unsubscribe = store.subscribe((newState) => {
2292
- const runtime = runtimeSnapshotRef.current;
2293
- if (runtime.role !== "host" || runtime.roomId !== roomId || runtime.resolvedStoreDomain !== resolvedStoreDomain) {
2294
- return;
2295
- }
2296
- const stateData = stripActionsFromState(newState);
2297
- const nextSignature = JSON.stringify(stateData);
2298
- if (nextSignature === syncedStateSignature) {
2299
- return;
2300
- }
2301
- syncedStateData = stateData;
2302
- syncedStateSignature = nextSignature;
2303
- syncRevision = Math.max(syncRevision, runtime.hostStateRevisionFloor);
2304
- syncRevision += 1;
2305
- if (runtime.canBroadcastHostState && runtime.socket) {
2306
- emitHostStateSync();
2307
- }
2308
- });
2309
- const handleAction = (payload, callback) => {
2310
- if (payload.storeDomain !== resolvedStoreDomain) {
2311
- return;
2312
- }
2313
- const { actionName } = payload;
2314
- if (isInternalActionName(actionName)) {
2315
- return;
2316
- }
2317
- const runtime = runtimeSnapshotRef.current;
2318
- const actionFn = store.getState().actions[actionName];
2319
- if (typeof actionFn !== "function") {
2320
- callback?.(
2321
- createServerRejectedActionResult(
2322
- "action_not_found",
2323
- `Store action "${actionName}" is not registered on the host.`,
2324
- {
2325
- actionName,
2326
- storeDomain: resolvedStoreDomain
2327
- }
2328
- )
2329
- );
2330
- return;
2331
- }
2332
- try {
2333
- const context = toActionContext(payload, runtime.connectedPlayerIds);
2334
- const result = actionFn(context, payload.payload);
2335
- const acknowledgement = normalizeAirJamActionInvocationResult(
2336
- result,
2337
- "host"
2338
- );
2339
- const actionName2 = payload.actionName;
2340
- notifyHostActionListeners({
2341
- actionName: actionName2,
2342
- payload: payload.payload,
2343
- context,
2344
- acknowledgement,
2345
- invocationKind: "rpc",
2346
- roomId,
2347
- storeDomain: resolvedStoreDomain
2348
- });
2349
- callback?.(acknowledgement);
2350
- } catch (error) {
2351
- const acknowledgement = {
2352
- ok: false,
2353
- status: "rejected",
2354
- source: "host",
2355
- reason: "handler_error",
2356
- message: error instanceof Error ? error.message : String(error)
2357
- };
2358
- const actionName2 = payload.actionName;
2359
- notifyHostActionListeners({
2360
- actionName: actionName2,
2361
- payload: payload.payload,
2362
- context: toActionContext(payload, runtime.connectedPlayerIds),
2363
- acknowledgement,
2364
- invocationKind: "rpc",
2365
- roomId,
2366
- storeDomain: resolvedStoreDomain
2367
- });
2368
- callback?.(acknowledgement);
2369
- }
2370
- };
2371
- const handleStateSyncRequest = (payload) => {
2372
- if (payload.roomId !== roomId) {
2373
- return;
2374
- }
2375
- if (payload.storeDomain !== resolvedStoreDomain) {
2376
- return;
2377
- }
2378
- flushHostStateSync(payload.requestId);
2379
- };
2380
- const handleSync2 = (payload) => {
2381
- if (payload.roomId !== roomId) {
2382
- return;
2383
- }
2384
- if (payload.storeDomain !== resolvedStoreDomain) {
2385
- return;
2386
- }
2387
- if (runtimeSnapshotRef.current.hostStateSyncBlocked) {
2388
- return;
2389
- }
2390
- if (payload.revision < syncRevision) {
2391
- return;
2392
- }
2393
- const nextStateData = stripActionsFromState(payload.data);
2394
- const nextSignature = JSON.stringify(nextStateData);
2395
- const currentSignature = JSON.stringify(
2396
- stripActionsFromState(store.getState())
2397
- );
2398
- syncRevision = payload.revision;
2399
- syncedStateData = nextStateData;
2400
- syncedStateSignature = nextSignature;
2401
- if (nextSignature === currentSignature) {
2402
- return;
2403
- }
2404
- store.setState(nextStateData);
2405
- };
2406
- socket.on("server:controllerJoined", handleControllerJoined);
2407
- socket.on("airjam:state_sync", handleSync2);
2408
- socket.on("airjam:state_sync_request", handleStateSyncRequest);
2409
- socket.on("airjam:action_rpc", handleAction);
2410
- const unregisterControl = typeof window === "undefined" ? void 0 : registerHostRuntimeActionStore(window, {
2411
- roomId,
2412
- storeDomain: resolvedStoreDomain,
2413
- invoke: async ({ actionName, payload }) => {
2414
- const runtime = runtimeSnapshotRef.current;
2415
- if (runtime.role !== "host" || runtime.roomId !== roomId || runtime.resolvedStoreDomain !== resolvedStoreDomain || runtime.socket !== socket || !runtime.canBroadcastHostState) {
2416
- return createClientRejectedActionResult(
2417
- "host_runtime_not_ready",
2418
- "The owning host runtime is not ready for actions."
2419
- );
2420
- }
2421
- const actions = createDispatchedActions({ kind: "default" });
2422
- if (!Object.hasOwn(actions, actionName)) {
2423
- return createClientRejectedActionResult(
2424
- "action_not_found",
2425
- "The requested public action is not registered on this host store."
2426
- );
2427
- }
2428
- const invoke = actions[actionName];
2429
- return invoke(payload);
2430
- }
2431
- });
2432
- return {
2433
- refCount: 0,
2434
- flushHostStateSync,
2435
- cleanup: () => {
2436
- unregisterControl?.();
2437
- unsubscribe();
2438
- socket.off("server:controllerJoined", handleControllerJoined);
2439
- socket.off("airjam:state_sync", handleSync2);
2440
- socket.off("airjam:state_sync_request", handleStateSyncRequest);
2441
- socket.off("airjam:action_rpc", handleAction);
2442
- }
2443
- };
2444
- }
2445
- let latestSyncRevision = -1;
2446
- const handleSync = (payload) => {
2447
- if (payload.storeDomain !== resolvedStoreDomain) {
2448
- return;
2449
- }
2450
- if (payload.revision < latestSyncRevision) {
2451
- return;
2452
- }
2453
- latestSyncRevision = payload.revision;
2454
- const stateData = stripActionsFromState(payload.data);
2455
- store.setState(stateData);
2456
- };
2457
- socket.on("airjam:state_sync", handleSync);
2458
- if (runtimeSnapshotRef.current.connectionStatus === "connected") {
2459
- socket.emit("controller:state_sync_request", {
2460
- roomId,
2461
- storeDomain: resolvedStoreDomain
2462
- });
2463
- }
2464
- return {
2465
- refCount: 0,
2466
- cleanup: () => {
2467
- socket.off("airjam:state_sync", handleSync);
2468
- }
2469
- };
2470
- };
2471
- const useSyncedStore = (selector = (state) => state) => {
2472
- const slice = store(selector);
2473
- const explicitDomain = options?.storeDomain;
2474
- let resolvedStoreDomain;
2475
- if (typeof explicitDomain === "string" && explicitDomain.trim().length > 0) {
2476
- const trimmed = explicitDomain.trim();
2477
- resolvedStoreDomain = trimmed.length > 128 ? trimmed.slice(0, 128) : trimmed;
2478
- } else {
2479
- resolvedStoreDomain = resolveImplicitReplicatedStoreDomainFromWindow();
2480
- }
2481
- const { getSocket } = useAirJamContext();
2482
- const role = useAirJamState((state) => state.role);
2483
- const roomId = useAirJamState((state) => state.roomId);
2484
- const registeredRoomId = useAirJamState((state) => state.registeredRoomId);
2485
- const connectionStatus = useAirJamState((state) => state.connectionStatus);
2486
- const players = useAirJamState((state) => state.players);
2487
- const hostArcadeRestore = useAirJamState(
2488
- (state) => state.hostArcadeRestore
2489
- );
2490
- const blockArcadeShellHostStateSync = resolvedStoreDomain === AIR_JAM_ARCADE_SURFACE_STORE_DOMAIN && hostArcadeRestore.phase !== "idle";
2491
- const hostStateRevisionFloor = resolvedStoreDomain === AIR_JAM_ARCADE_SURFACE_STORE_DOMAIN ? hostArcadeRestore.surfaceCheckpoint?.revision ?? 0 : 0;
2492
- const canBroadcastHostState = role === "host" && !!roomId && registeredRoomId === roomId && !blockArcadeShellHostStateSync;
2493
- const connectedPlayerIds = useMemo5(
2494
- () => Array.from(new Set(players.map((player) => player.id))).sort(),
2495
- [players]
2496
- );
2497
- const playerRosterKey = useMemo5(
2498
- () => players.map((player) => player.id).sort().join(","),
2499
- [players]
2500
- );
2501
- const socket = role === "host" ? getHostRealtimeClient((runtimeRole) => getSocket(runtimeRole)) : getControllerRealtimeClient((runtimeRole) => getSocket(runtimeRole));
2502
- runtimeSnapshotRef.current = {
2503
- socket,
2504
- role,
2505
- roomId,
2506
- resolvedStoreDomain,
2507
- connectionStatus,
2508
- canBroadcastHostState,
2509
- hostStateSyncBlocked: blockArcadeShellHostStateSync,
2510
- hostStateRevisionFloor,
2511
- connectedPlayerIds
2512
- };
2513
- const runtimeBindingKey = socket && roomId && role ? [
2514
- role,
2515
- roomId,
2516
- resolvedStoreDomain,
2517
- socket.id ?? "socket",
2518
- role === "controller" ? connectionStatus : "host"
2519
- ].join(":") : null;
2520
- useEffect8(() => {
2521
- if (!runtimeBindingKey || !socket || !roomId || !role) {
2522
- return;
2523
- }
2524
- let binding = runtimeBindings.get(runtimeBindingKey);
2525
- if (!binding) {
2526
- binding = createRuntimeBinding({
2527
- socket,
2528
- role,
2529
- roomId,
2530
- resolvedStoreDomain
2531
- });
2532
- runtimeBindings.set(runtimeBindingKey, binding);
2533
- }
2534
- binding.refCount += 1;
2535
- return () => {
2536
- const currentBinding = runtimeBindings.get(runtimeBindingKey);
2537
- if (!currentBinding) {
2538
- return;
2539
- }
2540
- currentBinding.refCount -= 1;
2541
- if (currentBinding.refCount > 0) {
2542
- return;
2543
- }
2544
- currentBinding.cleanup();
2545
- runtimeBindings.delete(runtimeBindingKey);
2546
- };
2547
- }, [
2548
- runtimeBindingKey,
2549
- socket,
2550
- role,
2551
- roomId,
2552
- socket?.id,
2553
- resolvedStoreDomain
2554
- ]);
2555
- useEffect8(() => {
2556
- if (!runtimeBindingKey || role !== "host" || !canBroadcastHostState || !roomId) {
2557
- return;
2558
- }
2559
- const binding = runtimeBindings.get(runtimeBindingKey);
2560
- if (!binding?.flushHostStateSync) {
2561
- return;
2562
- }
2563
- const flushKey = [
2564
- roomId,
2565
- registeredRoomId,
2566
- socket?.id ?? "socket",
2567
- resolvedStoreDomain,
2568
- playerRosterKey,
2569
- canBroadcastHostState ? "broadcast" : "blocked"
2570
- ].join(":");
2571
- if (binding.lastHostFlushKey === flushKey) {
2572
- return;
2573
- }
2574
- binding.lastHostFlushKey = flushKey;
2575
- binding.flushHostStateSync();
2576
- }, [
2577
- role,
2578
- roomId,
2579
- registeredRoomId,
2580
- socket?.id,
2581
- playerRosterKey,
2582
- resolvedStoreDomain,
2583
- canBroadcastHostState,
2584
- runtimeBindingKey
2585
- ]);
2586
- const dispatchedActions = useMemo5(
2587
- () => createDispatchedActions({ kind: "default" }),
2588
- []
1113
+
1114
+ // src/store/use-air-jam-store.ts
1115
+ import { useContext as useContext7, useEffect as useEffect6, useRef as useRef5 } from "react";
1116
+ import { useStore as useStore2 } from "zustand";
1117
+ var useRequireDeclaredStore = (store) => {
1118
+ const declared = useContext7(declaredStoresContext);
1119
+ if (!declared?.has(store))
1120
+ throw createAirJamDiagnosticError(
1121
+ "AJ_STORE_NOT_DECLARED",
1122
+ "This Air Jam store is used in a host or controller that does not declare it, so it would never sync with the room. Add it to defineAirJamGame({ stores: [yourStore] })."
2589
1123
  );
2590
- const stateActions = store.getState().actions;
2591
- if (slice === stateActions) {
2592
- return dispatchedActions;
2593
- }
2594
- if (typeof slice === "object" && slice !== null && "actions" in slice && slice.actions === stateActions) {
2595
- return {
2596
- ...slice,
2597
- actions: dispatchedActions
2598
- };
2599
- }
2600
- return slice;
2601
- };
2602
- const syncedStore = useSyncedStore;
2603
- const useActions = () => useSyncedStore((state) => state.actions);
2604
- const asPlayer = (controllerId) => createDispatchedActions({
2605
- kind: "player",
2606
- controllerId
1124
+ };
1125
+ function useAirJamStore(store, selector = (state) => state) {
1126
+ useRequireDeclaredStore(store);
1127
+ return useStore2(store.api, selector);
1128
+ }
1129
+ function useAirJamPrivateState(store) {
1130
+ useRequireDeclaredStore(store);
1131
+ return useStore2(store.api, () => store.getPrivateState());
1132
+ }
1133
+ function useHostActionListener(store, listener, options) {
1134
+ const listenerRef = useRef5(listener);
1135
+ const actionNamesRef = useRef5(options?.actionNames);
1136
+ useEffect6(() => {
1137
+ listenerRef.current = listener;
1138
+ actionNamesRef.current = options?.actionNames;
2607
1139
  });
2608
- const subscribeHostActions = (listener, options2) => {
2609
- const actionNames = options2?.actionNames && options2.actionNames.length > 0 ? new Set(options2.actionNames) : null;
2610
- const registration = {
2611
- actionNames,
2612
- includeRejected: options2?.includeRejected ?? false,
2613
- listener
2614
- };
2615
- hostActionListeners.add(registration);
2616
- return () => {
2617
- hostActionListeners.delete(registration);
2618
- };
2619
- };
2620
- const useHostActionListener = (listener, options2) => {
2621
- const listenerRef = useRef6(listener);
2622
- useEffect8(() => {
2623
- listenerRef.current = listener;
2624
- }, [listener]);
2625
- const includeRejected = options2?.includeRejected ?? false;
2626
- const actionNamesKey = options2?.actionNames?.join("\0") ?? "";
2627
- useEffect8(() => {
2628
- return subscribeHostActions((event) => {
2629
- listenerRef.current(event);
2630
- }, options2);
2631
- }, [actionNamesKey, includeRejected, options2]);
2632
- };
2633
- const useLiveStateRef = () => {
2634
- const latestState = useSyncedStore((state) => state);
2635
- const stateRef = useRef6(latestState);
2636
- useEffect8(() => {
2637
- stateRef.current = latestState;
2638
- }, [latestState]);
2639
- return stateRef;
2640
- };
2641
- syncedStore.useActions = useActions;
2642
- syncedStore.asPlayer = asPlayer;
2643
- syncedStore.getState = store.getState;
2644
- syncedStore.subscribe = store.subscribe;
2645
- syncedStore.subscribeHostActions = subscribeHostActions;
2646
- syncedStore.useHostActionListener = useHostActionListener;
2647
- syncedStore.useLiveStateRef = useLiveStateRef;
2648
- return syncedStore;
1140
+ const includeRejected = options?.includeRejected ?? false;
1141
+ const actionNamesKey = options?.actionNames?.join("\0") ?? "";
1142
+ useEffect6(
1143
+ () => store.subscribeHostActions((event) => listenerRef.current(event), {
1144
+ includeRejected,
1145
+ actionNames: actionNamesRef.current
1146
+ }),
1147
+ // The names are read through a ref; their joined key decides resubscription.
1148
+ [store, actionNamesKey, includeRejected]
1149
+ );
1150
+ }
1151
+
1152
+ // src/hooks/use-air-jam-settings.ts
1153
+ import { useContext as useContext8, useSyncExternalStore as useSyncExternalStore2 } from "react";
1154
+ function useAirJamSettings(declaration) {
1155
+ useAssertSessionScope("host", "useAirJamSettings");
1156
+ const runtime = useContext8(
1157
+ hostRuntimeContext
1158
+ );
1159
+ if (!runtime)
1160
+ throw new Error("useAirJamSettings requires a mounted game Host.");
1161
+ if (runtime.settings.declaration !== declaration)
1162
+ throw new Error(
1163
+ "useAirJamSettings must read this game's declared settings."
1164
+ );
1165
+ const snapshot = useSyncExternalStore2(
1166
+ runtime.settings.subscribe,
1167
+ runtime.settings.read,
1168
+ runtime.settings.read
1169
+ );
1170
+ return snapshot.values;
2649
1171
  }
2650
1172
  export {
2651
- AirJamErrorBoundary,
2652
1173
  AudioRuntime,
2653
1174
  DEFAULT_PLATFORM_SETTINGS,
2654
1175
  DEFAULT_ROOM_PLATFORM_SETTINGS,
2655
1176
  MusicPlaylist,
2656
- PlatformSettingsBoundary,
2657
1177
  PlatformSettingsRuntime,
2658
- acceptAirJamAction,
2659
- agentAction,
2660
- agentActionInput,
2661
- agentStore,
1178
+ captureAgentCanvas,
2662
1179
  createAirJamApp,
2663
- createAirJamStore,
2664
- defineAirJamAgentContract,
2665
- defineAirJamAgentStores,
1180
+ drawAgentCanvas,
2666
1181
  env,
2667
- getEffectiveAudioVolume,
2668
- isActiveMatchPhase,
2669
- isEndedMatchPhase,
2670
- isStandardMatchPhase,
2671
- mergeRoomPlatformSettingsSnapshot,
2672
1182
  onAirJamDiagnostic,
2673
- rejectAirJamAction,
2674
1183
  resolveAirJamBrowserRouterBasename,
2675
1184
  setAirJamDiagnosticsEnabled,
2676
- standardMatchPhases,
2677
1185
  toRoomPlatformSettingsSnapshot,
2678
1186
  toShellMatchPhase,
2679
1187
  useAirJamController,
2680
1188
  useAirJamHost,
1189
+ useAirJamPrivateState,
1190
+ useAirJamSettings,
1191
+ useAirJamStore,
2681
1192
  useAudio,
2682
- useAudioCategoryVolume,
2683
1193
  useAudioRuntimeControls,
2684
1194
  useAudioRuntimeStatus,
2685
- useConnectionStatus,
2686
- useControllerTick,
2687
1195
  useControllerToasts,
2688
- useGetInput,
1196
+ useHostActionListener,
1197
+ useHostAgentCapture,
2689
1198
  useHostAudioMutePreference,
2690
- useHostTick,
2691
1199
  useInheritedPlatformSettings,
2692
- useInputWriter,
2693
1200
  useMusicVolume,
2694
1201
  usePlatformAudioSettings,
2695
1202
  usePlatformSettings,
2696
- usePlayers,
1203
+ usePrefabInspection,
2697
1204
  useRoom,
2698
- useSendSignal
1205
+ useSendSignal,
1206
+ useSimulation,
1207
+ useSimulationEvents,
1208
+ useSimulationFrame,
1209
+ useSimulationSelector
2699
1210
  };
2700
1211
  //# sourceMappingURL=index.js.map