@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/ui.cjs CHANGED
@@ -31,10 +31,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var ui_exports = {};
32
32
  __export(ui_exports, {
33
33
  AIRJAM_DEFAULT_AVATAR_SEEDS: () => AIRJAM_DEFAULT_AVATAR_SEEDS,
34
+ AxisButton: () => AxisButton,
34
35
  Button: () => Button,
35
36
  ConnectionStatusPill: () => ConnectionStatusPill,
37
+ ControlButton: () => ControlButton,
36
38
  ControllerPlayerNameField: () => ControllerPlayerNameField,
37
39
  ControllerPrimaryAction: () => ControllerPrimaryAction,
40
+ GamepadLayout: () => GamepadLayout,
38
41
  HostMuteButton: () => HostMuteButton,
39
42
  JoinQrOverlay: () => JoinQrOverlay,
40
43
  JoinUrlActionButtons: () => JoinUrlActionButtons,
@@ -46,12 +49,10 @@ __export(ui_exports, {
46
49
  RoomQrCode: () => RoomQrCode,
47
50
  RuntimeShellHeader: () => RuntimeShellHeader,
48
51
  Slider: () => Slider,
52
+ Stick: () => Stick,
49
53
  SurfaceViewport: () => SurfaceViewport,
50
54
  VolumeControls: () => VolumeControls,
51
- buttonVariants: () => buttonVariants,
52
55
  getDiceBearAdventurerNeutralUrl: () => getDiceBearAdventurerNeutralUrl,
53
- getPlayerAvatarImageUrl: () => getPlayerAvatarImageUrl,
54
- resolvePlayerAvatarSeed: () => resolvePlayerAvatarSeed,
55
56
  useControllerLifecycleIntents: () => useControllerLifecycleIntents,
56
57
  useControllerLifecyclePermissions: () => useControllerLifecyclePermissions,
57
58
  useControllerShellStatus: () => useControllerShellStatus,
@@ -122,14 +123,17 @@ var import_react5 = require("react");
122
123
 
123
124
  // src/hooks/use-air-jam-controller.ts
124
125
  var import_react4 = require("react");
125
- var import_zustand3 = require("zustand");
126
+ var import_zustand2 = require("zustand");
126
127
  var import_shallow2 = require("zustand/react/shallow");
127
128
 
128
129
  // src/context/air-jam-context.tsx
129
130
  var import_react = require("react");
130
- var import_zustand2 = require("zustand");
131
+ var import_zustand = require("zustand");
131
132
  var import_shallow = require("zustand/react/shallow");
132
133
 
134
+ // src/core/connection-store.ts
135
+ var import_vanilla = require("zustand/vanilla");
136
+
133
137
  // src/diagnostics.ts
134
138
  var listeners = /* @__PURE__ */ new Set();
135
139
  var lastEmissionByKey = /* @__PURE__ */ new Map();
@@ -186,20 +190,47 @@ var createAirJamDiagnosticError = (code, message, details) => {
186
190
  return error;
187
191
  };
188
192
 
189
- // src/protocol/arcade-platform-actions.ts
193
+ // src/protocol/actions.ts
190
194
  var import_zod = require("zod");
191
- var arcadeBrowserConfirmPayloadSchema = import_zod.z.object({ epoch: import_zod.z.number().int().positive().safe() }).strict();
195
+ var airJamActionPayloadSchema = import_zod.z.record(import_zod.z.string(), import_zod.z.unknown());
196
+ var airJamActionAcceptedSchema = import_zod.z.object({
197
+ ok: import_zod.z.literal(true),
198
+ status: import_zod.z.literal("accepted"),
199
+ source: import_zod.z.enum(["client", "host"]),
200
+ result: import_zod.z.unknown().optional()
201
+ });
202
+ var airJamActionRejectedSchema = import_zod.z.object({
203
+ ok: import_zod.z.literal(false),
204
+ status: import_zod.z.literal("rejected"),
205
+ source: import_zod.z.enum(["client", "server", "host"]),
206
+ reason: import_zod.z.string(),
207
+ message: import_zod.z.string(),
208
+ details: airJamActionPayloadSchema.optional()
209
+ });
210
+ var airJamActionUnconfirmedSchema = import_zod.z.object({
211
+ ok: import_zod.z.literal(false),
212
+ status: import_zod.z.literal("unconfirmed"),
213
+ source: import_zod.z.literal("client")
214
+ });
215
+ var airJamActionInvocationResultSchema = import_zod.z.discriminatedUnion(
216
+ "status",
217
+ [
218
+ airJamActionAcceptedSchema,
219
+ airJamActionRejectedSchema,
220
+ airJamActionUnconfirmedSchema
221
+ ]
222
+ );
223
+
224
+ // src/protocol/arcade-platform-actions.ts
225
+ var import_zod2 = require("zod");
226
+ var arcadeBrowserConfirmPayloadSchema = import_zod2.z.object({ epoch: import_zod2.z.number().int().positive().safe() }).strict();
192
227
  var arcadeBrowserNavigatePayloadSchema = arcadeBrowserConfirmPayloadSchema.extend({
193
- direction: import_zod.z.enum(["up", "down", "left", "right"])
228
+ direction: import_zod2.z.enum(["up", "down", "left", "right"])
194
229
  });
195
230
 
196
231
  // src/protocol/controller.ts
197
232
  var import_zod3 = require("zod");
198
233
 
199
- // src/protocol/core.ts
200
- var import_zod2 = require("zod");
201
- var roomCodeSchema = import_zod2.z.string().trim().min(4).max(8).regex(/^[A-Z0-9]+$/, { message: "room code must contain only A-Z or 0-9" });
202
-
203
234
  // src/settings/platform-settings.ts
204
235
  var DEFAULT_PLATFORM_SETTINGS = {
205
236
  audio: {
@@ -229,76 +260,26 @@ var getEffectiveAudioVolume = (settings, category) => {
229
260
  };
230
261
 
231
262
  // src/protocol/controller.ts
232
- var controllerInputSchema = import_zod3.z.object({
233
- roomId: roomCodeSchema,
234
- controllerId: import_zod3.z.string().min(3),
235
- input: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown())
236
- });
237
- var controllerOrientationSchema = import_zod3.z.enum(["portrait", "landscape"]);
238
- var controllerSourceSchema = import_zod3.z.enum(["phone", "preview", "virtual"]);
239
- var controllerStateSchema = import_zod3.z.object({
240
- roomId: roomCodeSchema,
241
- state: import_zod3.z.object({
242
- orientation: controllerOrientationSchema.optional(),
243
- message: import_zod3.z.string().optional(),
244
- roomSettings: import_zod3.z.object({
245
- audio: import_zod3.z.object({
246
- masterVolume: import_zod3.z.number().min(0).max(1),
247
- musicVolume: import_zod3.z.number().min(0).max(1),
248
- sfxVolume: import_zod3.z.number().min(0).max(1)
249
- }),
250
- previewControllers: import_zod3.z.object({
251
- activeOpacity: import_zod3.z.number().min(0).max(1)
252
- })
253
- }).optional(),
254
- runtimeState: import_zod3.z.enum(["paused", "playing"]).optional(),
255
- stateVersion: import_zod3.z.number().int().nonnegative().optional()
256
- })
257
- });
258
- var controllerJoinSchema = import_zod3.z.object({
259
- roomId: roomCodeSchema,
260
- controllerId: import_zod3.z.string().min(3),
261
- /**
262
- * Local device/source hint, never authority to resume a controller slot.
263
- */
264
- deviceId: import_zod3.z.string().min(8).max(128).optional(),
265
- nickname: import_zod3.z.string().trim().min(1).max(24).optional(),
266
- /** Preset avatar key (platform-defined); optional at join. */
267
- avatarId: import_zod3.z.string().trim().min(1).max(48).optional(),
268
- capabilityToken: import_zod3.z.string().min(1).optional(),
269
- /** Private server-issued proof required to resume an existing controller. */
270
- resumeCapabilityToken: import_zod3.z.string().min(1).max(128).optional()
271
- });
272
- var controllerLeaveSchema = import_zod3.z.object({
273
- roomId: roomCodeSchema,
274
- controllerId: import_zod3.z.string().min(3)
275
- });
276
- var controllerSystemSchema = import_zod3.z.object({
277
- roomId: roomCodeSchema,
278
- command: import_zod3.z.enum(["exit", "pause", "resume"])
263
+ var playerProfileSchema = import_zod3.z.object({
264
+ id: import_zod3.z.string(),
265
+ label: import_zod3.z.string(),
266
+ color: import_zod3.z.string().optional(),
267
+ avatarId: import_zod3.z.string().optional()
279
268
  });
280
269
  var playerProfilePatchSchema = import_zod3.z.object({
281
270
  label: import_zod3.z.string().trim().min(1).max(24).optional(),
282
271
  avatarId: import_zod3.z.string().trim().min(1).max(48).optional()
283
272
  }).strict();
284
- var controllerUpdatePlayerProfileSchema = import_zod3.z.object({
285
- roomId: roomCodeSchema,
286
- controllerId: import_zod3.z.string().min(3),
287
- patch: playerProfilePatchSchema
288
- }).refine(
289
- (data) => data.patch.label !== void 0 || data.patch.avatarId !== void 0,
290
- { message: "patch must include at least one field" }
291
- );
292
- var controllerPrivilegedGrantSchema = import_zod3.z.enum([
293
- "system",
294
- "play_sound",
295
- "action_rpc"
273
+
274
+ // src/protocol/core.ts
275
+ var import_zod4 = require("zod");
276
+ var connectionStatusSchema = import_zod4.z.enum([
277
+ "idle",
278
+ "connecting",
279
+ "connected",
280
+ "disconnected",
281
+ "reconnecting"
296
282
  ]);
297
- var controllerPrivilegedCapabilitySchema = import_zod3.z.object({
298
- token: import_zod3.z.string().min(1),
299
- expiresAt: import_zod3.z.number().int().positive(),
300
- grants: import_zod3.z.array(controllerPrivilegedGrantSchema).min(1)
301
- });
302
283
 
303
284
  // src/protocol/dev-log-events.ts
304
285
  var AIRJAM_DEV_LOG_EVENTS = {
@@ -306,18 +287,9 @@ var AIRJAM_DEV_LOG_EVENTS = {
306
287
  started: "server.started",
307
288
  startupFailed: "server.startup.failed"
308
289
  },
309
- socket: {
310
- connected: "socket.connected",
311
- disconnected: "socket.disconnected"
312
- },
313
290
  auth: {
314
291
  modeDisabled: "auth.mode.disabled",
315
- modeMasterKey: "auth.mode.master_key",
316
- modeDatabaseAndHostGrant: "auth.mode.database_and_host_grant",
317
- modeDatabase: "auth.mode.database",
318
- backendMissing: "auth.backend.missing",
319
- appIdLastUsedAtUpdateFailed: "auth.app_id_last_used_at_update.failed",
320
- appIdVerificationDatabaseError: "auth.app_id_verification.database_error"
292
+ modeMasterKey: "auth.mode.master_key"
321
293
  },
322
294
  browser: {
323
295
  logSessionStarted: "browser.log_session.started",
@@ -333,82 +305,18 @@ var AIRJAM_DEV_LOG_EVENTS = {
333
305
  providerUnmounted: "runtime.provider.unmounted",
334
306
  windowBeforeUnload: "runtime.window.beforeunload",
335
307
  windowPageHide: "runtime.window.pagehide",
336
- socketConnected: "runtime.socket.connected",
337
- socketDisconnected: "runtime.socket.disconnected",
338
- socketConnectError: "runtime.socket.connect_error",
339
- hostCreateRoomRequested: "runtime.host.create_room.requested",
340
- hostReconnectRequested: "runtime.host.reconnect.requested",
341
- hostReconnectRetryScheduled: "runtime.host.reconnect.retry_scheduled",
308
+ roomStatus: "runtime.room.status",
342
309
  hostResetRoomRequested: "runtime.host.reset_room.requested",
343
- hostStateReceived: "runtime.host.state.received",
344
- controllerJoinRequested: "runtime.controller.join.requested",
345
- controllerStateReceived: "runtime.controller.state.received",
310
+ clipCaptureFailed: "runtime.host.clip_capture_failed",
311
+ hostFrameFault: "runtime.host.frame_fault",
312
+ errorReport: "runtime.error_report",
346
313
  phaseTransition: "runtime.phase.transition",
347
- stateVersionReceived: "runtime.state_version.received",
348
- invariantViolation: "runtime.invariant.violation",
349
314
  embeddedBridgeRequested: "runtime.embedded_bridge.requested",
350
- embeddedBridgeAttached: "runtime.embedded_bridge.attached",
351
315
  embeddedBridgeRejected: "runtime.embedded_bridge.rejected",
352
- embeddedBridgeClosed: "runtime.embedded_bridge.closed",
353
316
  browserLogSinkFailure: "runtime.browser_log_sink.failure"
354
317
  },
355
318
  host: {
356
- lifecycleRejected: "host.lifecycle.rejected",
357
- bootstrapVerified: "host.bootstrap.verified",
358
- bootstrapRejected: "host.bootstrap.rejected",
359
- disconnectPendingRoomClose: "host.disconnect.pending_room_close",
360
- disconnectRoomClosed: "host.disconnect.room_closed",
361
- createRoomAccepted: "host.create_room.accepted",
362
- createRoomRejected: "host.create_room.rejected",
363
- reconnectAccepted: "host.reconnect.accepted",
364
- reconnectRejected: "host.reconnect.rejected",
365
- resetRoomAccepted: "host.reset_room.accepted",
366
- resetRoomRejected: "host.reset_room.rejected",
367
- systemAccepted: "host.system.accepted",
368
- systemRejected: "host.system.rejected",
369
- stateRejected: "host.state.rejected",
370
- signalRejected: "host.signal.rejected",
371
- playSoundRejected: "host.play_sound.rejected",
372
- stateBroadcastSummary: "host.state_broadcast.summary",
373
- reconnectStateReconcile: "host.reconnect.state_reconcile",
374
- stateSyncSummary: "host.state_sync.summary",
375
- stateSyncRejected: "host.state_sync.rejected"
376
- },
377
- controller: {
378
- joinAccepted: "controller.join.accepted",
379
- joinRejected: "controller.join.rejected",
380
- resumeAccepted: "controller.resume.accepted",
381
- disconnectPendingResume: "controller.disconnect.pending_resume",
382
- disconnectLeaseExpired: "controller.disconnect.lease_expired",
383
- disconnectApplied: "controller.disconnect.applied",
384
- profileUpdateAccepted: "controller.profile_update.accepted",
385
- profileUpdateRejected: "controller.profile_update.rejected",
386
- leaveAccepted: "controller.leave.accepted",
387
- leaveRejected: "controller.leave.rejected",
388
- inputSummary: "controller.input.summary",
389
- inputDroppedSummary: "controller.input_dropped.summary",
390
- inputRejected: "controller.input.rejected",
391
- systemAccepted: "controller.system.accepted",
392
- systemRejected: "controller.system.rejected",
393
- playSoundRejected: "controller.play_sound.rejected",
394
- actionRpcSummary: "controller.action_rpc.summary",
395
- actionRpcRejected: "controller.action_rpc.rejected"
396
- },
397
- system: {
398
- launchGameAccepted: "system.launch_game.accepted",
399
- launchGameRejected: "system.launch_game.rejected",
400
- closeGameAccepted: "system.close_game.accepted",
401
- closeGameRejected: "system.close_game.rejected"
402
- },
403
- childHost: {
404
- joinAccepted: "child_host.join.accepted",
405
- joinRejected: "child_host.join.rejected",
406
- disconnectPendingSystemFocus: "child_host.disconnect.pending_system_focus",
407
- disconnectSystemFocusRestored: "child_host.disconnect.system_focus_restored"
408
- },
409
- embeddedGame: {
410
- activateAccepted: "embedded_game.activate.accepted",
411
- activateRejected: "embedded_game.activate.rejected"
319
+ stateRestoreDiscarded: "host.state_restore.discarded"
412
320
  }
413
321
  };
414
322
  var AIRJAM_BROWSER_LOG_EVENT_BY_SOURCE = {
@@ -419,109 +327,522 @@ var AIRJAM_BROWSER_LOG_EVENT_BY_SOURCE = {
419
327
  runtime: AIRJAM_DEV_LOG_EVENTS.browser.runtime
420
328
  };
421
329
 
422
- // src/protocol/host.ts
423
- var import_zod4 = require("zod");
424
- var hostSessionKindSchema = import_zod4.z.enum(["game", "system"]);
425
- var childHostCapabilitySchema = import_zod4.z.object({
426
- token: import_zod4.z.string().min(1),
427
- expiresAt: import_zod4.z.number().int().positive()
330
+ // src/protocol/leased-control.ts
331
+ var import_zod11 = require("zod");
332
+
333
+ // src/protocol/room/addressing.ts
334
+ var import_zod5 = require("zod");
335
+ var roomCodeSchema = import_zod5.z.string().regex(/^[A-Z0-9]{4,8}$/);
336
+
337
+ // src/protocol/room/frames.ts
338
+ var import_zod8 = require("zod");
339
+
340
+ // src/protocol/room/limits.ts
341
+ var import_zod6 = require("zod");
342
+ var MAXIMUM_ROOM_SEATS = 16;
343
+ var count = import_zod6.z.number().int().positive();
344
+ var duration = import_zod6.z.number().int().nonnegative();
345
+ var roomLimitsShape = {
346
+ seats: count.max(MAXIMUM_ROOM_SEATS),
347
+ channels: count,
348
+ /** How often a phone may send its controls; phones coalesce to it. */
349
+ inputIntervalMs: count,
350
+ /** One phone's whole control state; a host input record states its length in one byte. */
351
+ inputBytes: count.max(255),
352
+ inputsPerSecond: count,
353
+ /** The most a channel's document, or any one state frame, may weigh. */
354
+ stateBytes: count,
355
+ statesPerSecond: count,
356
+ /** The most any other text frame may weigh. */
357
+ frameBytes: count,
358
+ /** Text frames other than state, per connection. */
359
+ framesPerSecond: count,
360
+ /** Frames that do not parse, within one second, before the connection is closed. */
361
+ strikesPerSecond: count,
362
+ seatHoldMs: duration,
363
+ /** How long the room waits for its host, as it opens and after the host's connection ends. */
364
+ hostGraceMs: count,
365
+ maximumAgeMs: count
366
+ };
367
+ var roomLimitsSchema = import_zod6.z.strictObject(roomLimitsShape);
368
+ var roomLimitsWireSchema = import_zod6.z.object(roomLimitsShape);
369
+ var DEFAULT_ROOM_LIMITS = Object.freeze({
370
+ seats: MAXIMUM_ROOM_SEATS,
371
+ channels: 8,
372
+ inputIntervalMs: 16,
373
+ inputBytes: 64,
374
+ inputsPerSecond: 120,
375
+ stateBytes: 65536,
376
+ statesPerSecond: 60,
377
+ frameBytes: 8192,
378
+ framesPerSecond: 60,
379
+ strikesPerSecond: 64,
380
+ seatHoldMs: 12e4,
381
+ hostGraceMs: 6e4,
382
+ maximumAgeMs: 24 * 60 * 60 * 1e3
428
383
  });
429
- var hostResumeCapabilitySchema = import_zod4.z.object({
430
- token: import_zod4.z.string().min(1)
384
+
385
+ // src/protocol/room/patch.ts
386
+ var isPlainObject = (value) => {
387
+ if (typeof value !== "object" || value === null || Array.isArray(value))
388
+ return false;
389
+ const prototype = Object.getPrototypeOf(value);
390
+ return prototype === Object.prototype || prototype === null;
391
+ };
392
+
393
+ // src/protocol/room/seat-id.ts
394
+ var import_zod7 = require("zod");
395
+ var seatIdSchema = import_zod7.z.string().regex(/^p[1-9][0-9]{0,4}$/);
396
+
397
+ // src/protocol/room/frames.ts
398
+ var MAXIMUM_FRAME_DEPTH = 32;
399
+ var keySchema = import_zod8.z.string().min(16).max(128);
400
+ var instanceSchema = import_zod8.z.string().min(1).max(64);
401
+ var channelSchema = import_zod8.z.string().min(1).max(128);
402
+ var revisionSchema = import_zod8.z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
403
+ var requestIdSchema = import_zod8.z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
404
+ var featuresSchema = import_zod8.z.array(import_zod8.z.string().min(1).max(64)).max(32);
405
+ var documentSchema = import_zod8.z.custom(isPlainObject, {
406
+ message: "A state document is a plain JSON object."
431
407
  });
432
- var hostBootstrapSchema = import_zod4.z.object({
433
- appId: import_zod4.z.string().optional(),
434
- hostGrant: import_zod4.z.string().min(1).optional(),
435
- hostSessionKind: hostSessionKindSchema.default("game")
408
+ var pathSchema = import_zod8.z.array(import_zod8.z.string()).min(1).max(32);
409
+ var seatKindSchema = import_zod8.z.enum(["phone", "preview", "agent"]);
410
+ var seatProfileSchema = import_zod8.z.object({
411
+ label: import_zod8.z.string().trim().min(1).max(24).optional(),
412
+ avatarId: import_zod8.z.string().trim().min(1).max(48).optional(),
413
+ /** Shown instead of the label while a local seat plays through this phone. */
414
+ localSeatLabel: import_zod8.z.string().trim().min(1).max(32).optional()
436
415
  });
437
- var systemLaunchGameSchema = import_zod4.z.object({
438
- roomId: roomCodeSchema,
439
- gameId: import_zod4.z.string()
416
+ var helloFields = {
417
+ type: import_zod8.z.literal("hello"),
418
+ key: keySchema,
419
+ instance: instanceSchema.optional(),
420
+ sdk: import_zod8.z.string().min(1).max(64),
421
+ features: featuresSchema.optional()
422
+ };
423
+ var hostHelloSchema = import_zod8.z.object({
424
+ ...helloFields,
425
+ /** Opaque to the room; the gate reads it before the room opens. */
426
+ credential: import_zod8.z.string().min(1).max(8192).optional(),
427
+ /** How many players the game takes; the room admits no more. */
428
+ seats: import_zod8.z.number().int().min(1).max(MAXIMUM_ROOM_SEATS)
440
429
  });
441
- var hostJoinAsChildSchema = import_zod4.z.object({
442
- roomId: roomCodeSchema,
443
- capabilityToken: import_zod4.z.string().min(1)
430
+ var phoneHelloSchema = import_zod8.z.object({
431
+ ...helloFields,
432
+ kind: seatKindSchema,
433
+ profile: seatProfileSchema.optional(),
434
+ /**
435
+ * The page this phone runs in, the same across its reconnects. A seat
436
+ * resumed from another page (a reload, or another tab taking it over)
437
+ * starts its controls afresh, so the host takes a new input baseline.
438
+ */
439
+ page: import_zod8.z.string().min(1).max(64).optional()
444
440
  });
445
- var hostActivateEmbeddedGameSchema = import_zod4.z.object({
446
- roomId: roomCodeSchema,
447
- capabilityToken: import_zod4.z.string().min(1)
441
+ var statePatchFields = {
442
+ type: import_zod8.z.literal("state"),
443
+ channel: channelSchema,
444
+ revision: revisionSchema,
445
+ base: revisionSchema,
446
+ set: import_zod8.z.array(import_zod8.z.tuple([pathSchema, import_zod8.z.unknown()])).default([]),
447
+ unset: import_zod8.z.array(pathSchema).default([])
448
+ };
449
+ var stateDocumentFields = {
450
+ type: import_zod8.z.literal("state"),
451
+ channel: channelSchema,
452
+ revision: revisionSchema,
453
+ document: documentSchema
454
+ };
455
+ var hostStateFrameSchema = import_zod8.z.union([
456
+ import_zod8.z.object({
457
+ ...stateDocumentFields,
458
+ /** The store's shape, so a reloading host knows whether to take its state back. */
459
+ fingerprint: import_zod8.z.string().min(1).max(256).optional(),
460
+ /** A top-level field keyed by seat whose entries only their own seat sees. */
461
+ private: import_zod8.z.string().min(1).max(128).optional()
462
+ }),
463
+ import_zod8.z.object(statePatchFields).refine(
464
+ (frame) => frame.revision > frame.base,
465
+ "A patch produces a later revision than its base."
466
+ )
467
+ ]);
468
+ var hostToRoomFrameSchemas = {
469
+ state: hostStateFrameSchema,
470
+ response: import_zod8.z.object({
471
+ type: import_zod8.z.literal("response"),
472
+ seat: seatIdSchema,
473
+ id: requestIdSchema,
474
+ result: import_zod8.z.unknown().optional()
475
+ }),
476
+ signal: import_zod8.z.object({
477
+ type: import_zod8.z.literal("signal"),
478
+ seat: seatIdSchema.optional(),
479
+ kind: import_zod8.z.string().min(1).max(64),
480
+ payload: import_zod8.z.unknown().optional()
481
+ }),
482
+ room: import_zod8.z.object({
483
+ type: import_zod8.z.literal("room"),
484
+ seats: import_zod8.z.number().int().min(1).max(MAXIMUM_ROOM_SEATS).optional(),
485
+ locked: import_zod8.z.boolean().optional()
486
+ }),
487
+ remove: import_zod8.z.object({ type: import_zod8.z.literal("remove"), seat: seatIdSchema }),
488
+ drop: import_zod8.z.object({ type: import_zod8.z.literal("drop"), channel: channelSchema }),
489
+ activity: import_zod8.z.object({
490
+ type: import_zod8.z.literal("activity"),
491
+ activity: import_zod8.z.string().min(1).max(128).nullable()
492
+ }),
493
+ end: import_zod8.z.object({ type: import_zod8.z.literal("end") })
494
+ };
495
+ var phoneToRoomFrameSchemas = {
496
+ request: import_zod8.z.object({
497
+ type: import_zod8.z.literal("request"),
498
+ id: requestIdSchema,
499
+ channel: channelSchema,
500
+ name: import_zod8.z.string().min(1).max(128),
501
+ payload: import_zod8.z.unknown().optional()
502
+ }),
503
+ profile: import_zod8.z.object({
504
+ type: import_zod8.z.literal("profile"),
505
+ label: seatProfileSchema.shape.label,
506
+ avatarId: seatProfileSchema.shape.avatarId
507
+ }).refine(
508
+ (frame) => frame.label !== void 0 || frame.avatarId !== void 0,
509
+ "A profile change names a label or an avatar."
510
+ ),
511
+ leave: import_zod8.z.object({ type: import_zod8.z.literal("leave") }),
512
+ /** This seat's controls start again from zero, as a newly loaded controller frame's do. */
513
+ baseline: import_zod8.z.object({ type: import_zod8.z.literal("baseline") })
514
+ };
515
+ var seatViewSchema = import_zod8.z.object({
516
+ id: seatIdSchema,
517
+ label: import_zod8.z.string(),
518
+ color: import_zod8.z.string(),
519
+ avatarId: import_zod8.z.string().optional(),
520
+ kind: seatKindSchema,
521
+ connected: import_zod8.z.boolean()
448
522
  });
449
- var hostCreateRoomSchema = import_zod4.z.object({
450
- maxPlayers: import_zod4.z.number().int().min(1).max(16).default(8)
523
+ var channelCopySchema = import_zod8.z.object({
524
+ channel: channelSchema,
525
+ revision: revisionSchema,
526
+ document: documentSchema,
527
+ fingerprint: import_zod8.z.string().optional(),
528
+ private: import_zod8.z.string().optional()
451
529
  });
452
- var hostReconnectSchema = import_zod4.z.object({
453
- roomId: roomCodeSchema,
454
- resumeCapabilityToken: import_zod4.z.string().min(1)
530
+ var welcomeFields = {
531
+ type: import_zod8.z.literal("welcome"),
532
+ code: import_zod8.z.string(),
533
+ instance: instanceSchema,
534
+ seats: import_zod8.z.array(seatViewSchema),
535
+ channels: import_zod8.z.array(channelCopySchema),
536
+ limits: roomLimitsWireSchema,
537
+ features: featuresSchema
538
+ };
539
+ var roomStateFrameSchema = import_zod8.z.union([
540
+ import_zod8.z.object(stateDocumentFields),
541
+ import_zod8.z.object(statePatchFields)
542
+ ]);
543
+ var roomToHostFrameSchemas = {
544
+ welcome: import_zod8.z.object({
545
+ ...welcomeFields,
546
+ /** Seats the room admits, and whether it admits new players at all. */
547
+ seatsWanted: import_zod8.z.number().int().min(1).max(MAXIMUM_ROOM_SEATS),
548
+ locked: import_zod8.z.boolean(),
549
+ activity: import_zod8.z.string().nullable()
550
+ }),
551
+ wait: import_zod8.z.object({
552
+ type: import_zod8.z.literal("wait"),
553
+ position: import_zod8.z.number().int().positive()
554
+ }),
555
+ seat: import_zod8.z.object({
556
+ type: import_zod8.z.literal("seat"),
557
+ seat: seatViewSchema,
558
+ /** The seat's controls restart from a new page: decode them afresh. */
559
+ inputBaseline: import_zod8.z.literal(true).optional()
560
+ }),
561
+ left: import_zod8.z.object({ type: import_zod8.z.literal("left"), seat: seatIdSchema }),
562
+ need: import_zod8.z.object({ type: import_zod8.z.literal("need"), channel: channelSchema }),
563
+ request: import_zod8.z.object({
564
+ type: import_zod8.z.literal("request"),
565
+ seat: seatIdSchema,
566
+ id: requestIdSchema,
567
+ channel: channelSchema,
568
+ name: import_zod8.z.string(),
569
+ payload: import_zod8.z.unknown().optional()
570
+ })
571
+ };
572
+ var roomToPhoneFrameSchemas = {
573
+ welcome: import_zod8.z.object({
574
+ ...welcomeFields,
575
+ seat: seatIdSchema,
576
+ host: import_zod8.z.boolean()
577
+ }),
578
+ seat: roomToHostFrameSchemas.seat,
579
+ left: roomToHostFrameSchemas.left,
580
+ host: import_zod8.z.object({ type: import_zod8.z.literal("host"), present: import_zod8.z.boolean() }),
581
+ state: roomStateFrameSchema,
582
+ drop: hostToRoomFrameSchemas.drop,
583
+ // The refusal comes first: a result may be absent, so the other branch
584
+ // would accept a refusal and strip what it says.
585
+ response: import_zod8.z.union([
586
+ import_zod8.z.object({
587
+ type: import_zod8.z.literal("response"),
588
+ id: requestIdSchema,
589
+ /** The room answered itself because no host could. */
590
+ refused: import_zod8.z.literal("host-away")
591
+ }),
592
+ import_zod8.z.object({
593
+ type: import_zod8.z.literal("response"),
594
+ id: requestIdSchema,
595
+ result: import_zod8.z.unknown().optional()
596
+ })
597
+ ]),
598
+ signal: import_zod8.z.object({
599
+ type: import_zod8.z.literal("signal"),
600
+ kind: import_zod8.z.string(),
601
+ payload: import_zod8.z.unknown().optional()
602
+ })
603
+ };
604
+ var nestsWithin = (value, depth) => {
605
+ if (typeof value !== "object" || value === null) return true;
606
+ if (depth === 0) return false;
607
+ for (const child of Object.values(value))
608
+ if (!nestsWithin(child, depth - 1)) return false;
609
+ return true;
610
+ };
611
+ var TOO_DEEP = /* @__PURE__ */ Symbol("too deep");
612
+ var parseJson = (text) => {
613
+ let value;
614
+ try {
615
+ value = JSON.parse(text);
616
+ } catch {
617
+ return void 0;
618
+ }
619
+ return nestsWithin(value, MAXIMUM_FRAME_DEPTH) ? value : TOO_DEEP;
620
+ };
621
+ var readType = (value) => isPlainObject(value) && typeof value.type === "string" ? value.type : null;
622
+ var createFrameParser = (schemas) => (text) => {
623
+ const value = parseJson(text);
624
+ if (value === TOO_DEEP) return { status: "too-deep" };
625
+ const type = readType(value);
626
+ if (type === null) return { status: "invalid" };
627
+ if (!Object.hasOwn(schemas, type)) return { status: "unknown" };
628
+ const parsed = schemas[type].safeParse(value);
629
+ return parsed.success ? { status: "frame", frame: parsed.data } : { status: "invalid" };
630
+ };
631
+ var parseHostToRoomFrame = createFrameParser(hostToRoomFrameSchemas);
632
+ var parsePhoneToRoomFrame = createFrameParser(phoneToRoomFrameSchemas);
633
+ var parseRoomToHostFrame = createFrameParser(roomToHostFrameSchemas);
634
+ var parseRoomToPhoneFrame = createFrameParser(roomToPhoneFrameSchemas);
635
+ var createHelloParser = (schema) => (text) => {
636
+ const parsed = schema.safeParse(parseJson(text));
637
+ return parsed.success ? parsed.data : null;
638
+ };
639
+ var parseHostHello = createHelloParser(hostHelloSchema);
640
+ var parsePhoneHello = createHelloParser(phoneHelloSchema);
641
+
642
+ // src/protocol/room/sdk-channels.ts
643
+ var import_zod9 = require("zod");
644
+ var runtimeStateSchema = import_zod9.z.enum(["paused", "playing"]);
645
+ var controllerOrientationSchema = import_zod9.z.enum(["portrait", "landscape"]);
646
+ var presentationDocumentSchema = import_zod9.z.object({
647
+ runtimeState: runtimeStateSchema,
648
+ orientation: controllerOrientationSchema
455
649
  });
456
- var hostResetRoomSchema = import_zod4.z.object({
457
- roomId: roomCodeSchema
650
+ var presentationRequestSchema = import_zod9.z.enum(["pause", "resume"]);
651
+ var hapticSignalPayloadSchema = import_zod9.z.object({
652
+ pattern: import_zod9.z.enum(["light", "medium", "heavy", "success", "failure", "custom"]),
653
+ sequence: import_zod9.z.union([import_zod9.z.number().nonnegative(), import_zod9.z.array(import_zod9.z.number().nonnegative())]).optional()
458
654
  });
459
- var hostRemoveControllerSchema = import_zod4.z.object({
460
- roomId: roomCodeSchema,
461
- controllerId: import_zod4.z.string().min(3)
655
+ var toastSignalPayloadSchema = import_zod9.z.object({
656
+ message: import_zod9.z.string(),
657
+ color: import_zod9.z.string().optional(),
658
+ duration: import_zod9.z.number().nonnegative().optional()
659
+ });
660
+ var soundSignalPayloadSchema = import_zod9.z.object({
661
+ soundId: import_zod9.z.string().min(1),
662
+ volume: import_zod9.z.number().min(0).max(1).optional(),
663
+ loop: import_zod9.z.boolean().optional()
462
664
  });
463
665
 
464
- // src/protocol/host-grant.ts
465
- var import_zod5 = require("zod");
466
-
467
- // src/protocol/signed-envelope.ts
468
- var encoder = new TextEncoder();
469
- var decoder = new TextDecoder();
666
+ // src/runtime/contracts/runtime-identity.ts
667
+ var import_zod10 = require("zod");
668
+ var hostRuntimeIdentitySchema = import_zod10.z.object({
669
+ documentId: import_zod10.z.string().min(1).max(128),
670
+ roomId: roomCodeSchema,
671
+ contractId: import_zod10.z.string().min(1),
672
+ runtimeId: import_zod10.z.string().min(1)
673
+ });
674
+ var hostObservationIdentitySchema = hostRuntimeIdentitySchema.extend({
675
+ surfaceId: import_zod10.z.string().min(1).nullable(),
676
+ participantId: import_zod10.z.string().min(1).nullable().default(null)
677
+ });
678
+ var identityKeys = hostObservationIdentitySchema.keyof().options;
470
679
 
471
- // src/protocol/host-grant.ts
472
- var hostGrantAudienceSchema = import_zod5.z.literal("airjam:realtime");
473
- var hostGrantClaimsSchema = import_zod5.z.object({
474
- typ: import_zod5.z.literal("airjam.host_grant.v3"),
475
- jti: import_zod5.z.string().uuid(),
476
- aud: hostGrantAudienceSchema,
477
- appId: import_zod5.z.string().min(1),
478
- gameId: import_zod5.z.string().min(1),
479
- creatorId: import_zod5.z.string().min(1),
480
- iat: import_zod5.z.number().int().positive(),
481
- exp: import_zod5.z.number().int().positive(),
482
- origins: import_zod5.z.array(import_zod5.z.string().url()).min(1),
483
- sessionKind: hostSessionKindSchema
680
+ // src/protocol/leased-control.ts
681
+ var jsonValueSchema = import_zod11.z.unknown().refine(
682
+ (input) => {
683
+ const pending = [
684
+ { value: input, depth: 0 }
685
+ ];
686
+ for (const current of pending) {
687
+ if (current.depth > 32) return false;
688
+ if (current.value && typeof current.value === "object") {
689
+ for (const value of Object.values(current.value)) {
690
+ if (pending.length >= 4096) return false;
691
+ pending.push({ value, depth: current.depth + 1 });
692
+ }
693
+ }
694
+ }
695
+ return true;
696
+ },
697
+ {
698
+ error: "Participant JSON exceeds its depth or node budget.",
699
+ abort: true
700
+ }
701
+ ).pipe(import_zod11.z.json());
702
+ var PARTICIPANT_INPUT_SCHEMA_BYTES = 32e3;
703
+ var participantInputSchemaDescriptionSchema = import_zod11.z.discriminatedUnion(
704
+ "status",
705
+ [
706
+ import_zod11.z.object({
707
+ status: import_zod11.z.literal("available"),
708
+ schema: import_zod11.z.record(import_zod11.z.string(), jsonValueSchema).refine(
709
+ (schema) => new TextEncoder().encode(JSON.stringify(schema)).byteLength <= PARTICIPANT_INPUT_SCHEMA_BYTES,
710
+ "Input JSON Schema exceeds its byte budget."
711
+ )
712
+ }).strict(),
713
+ import_zod11.z.object({
714
+ status: import_zod11.z.literal("unavailable"),
715
+ reason: import_zod11.z.enum(["not-configured", "not-representable"])
716
+ }).strict()
717
+ ]
718
+ );
719
+ var leaseSequenceSchema = import_zod11.z.number().int().positive().max(Number.MAX_SAFE_INTEGER);
720
+ var deadlineMs = import_zod11.z.number().nonnegative().max(Number.MAX_SAFE_INTEGER).describe(
721
+ "Admission deadline in the observed host's monotonic clock. Derive it from observation.clock.startedAtMs; never use the caller's clock."
722
+ );
723
+ var participantInputOperationSchema = import_zod11.z.object({
724
+ kind: import_zod11.z.literal("input"),
725
+ deadlineMs,
726
+ input: import_zod11.z.record(import_zod11.z.string(), jsonValueSchema),
727
+ ttlMs: import_zod11.z.number().int().min(50).max(2e3)
484
728
  }).strict();
485
-
486
- // src/protocol/runtime-reporting.ts
487
- var import_zod6 = require("zod");
488
- var AIRJAM_RUNTIME_ERROR_REPORT_CONTRACT_VERSION = 1;
489
- var runtimeErrorReportSchema = import_zod6.z.object({
490
- contractVersion: import_zod6.z.literal(AIRJAM_RUNTIME_ERROR_REPORT_CONTRACT_VERSION),
491
- reportId: import_zod6.z.string().uuid(),
492
- roomId: roomCodeSchema,
493
- role: import_zod6.z.enum(["host", "controller"]),
494
- code: import_zod6.z.literal("AJ_RUNTIME_RENDER_CRASH"),
495
- errorName: import_zod6.z.string().trim().min(1).max(80).regex(/^[A-Za-z][A-Za-z0-9._-]*$/u),
496
- digest: import_zod6.z.string().regex(/^[a-f0-9]{8}$/u),
497
- occurredAt: import_zod6.z.string().datetime()
729
+ var participantReleaseOperationSchema = import_zod11.z.object({ kind: import_zod11.z.literal("release") }).strict();
730
+ var participantActionOperationSchema = import_zod11.z.object({
731
+ kind: import_zod11.z.literal("action"),
732
+ deadlineMs,
733
+ actionId: import_zod11.z.string().min(1).max(128),
734
+ input: jsonValueSchema.optional()
498
735
  }).strict();
499
-
500
- // src/protocol/sync.ts
501
- var import_zod7 = require("zod");
502
- var stateSyncRequestIdSchema = import_zod7.z.string().trim().min(1).max(128);
503
- var airJamActionPayloadSchema = import_zod7.z.record(import_zod7.z.string(), import_zod7.z.unknown());
504
- var controllerActionRpcSchema = import_zod7.z.object({
505
- roomId: roomCodeSchema,
506
- actionName: import_zod7.z.string().trim().min(1),
507
- payload: import_zod7.z.union([airJamActionPayloadSchema, import_zod7.z.undefined()]).optional(),
508
- storeDomain: import_zod7.z.string().trim().min(1).max(128)
736
+ var operationSchema = import_zod11.z.discriminatedUnion("kind", [
737
+ participantInputOperationSchema,
738
+ participantReleaseOperationSchema,
739
+ participantActionOperationSchema
740
+ ]);
741
+ var leasedControlRequestSchema = import_zod11.z.object({
742
+ lease: import_zod11.z.object({ id: import_zod11.z.uuid(), sequence: leaseSequenceSchema }).strict(),
743
+ expected: hostObservationIdentitySchema.strict(),
744
+ operation: operationSchema
509
745
  }).strict();
510
- var hostStateSyncSchema = import_zod7.z.object({
746
+ var controllerLeasedControlSchema = leasedControlRequestSchema.extend({
511
747
  roomId: roomCodeSchema,
512
- data: import_zod7.z.record(import_zod7.z.string(), import_zod7.z.unknown()),
513
- storeDomain: import_zod7.z.string().trim().min(1).max(128),
514
- revision: import_zod7.z.number().int().nonnegative(),
515
- requestId: stateSyncRequestIdSchema.optional()
516
- }).strict();
517
- var controllerStateSyncRequestSchema = import_zod7.z.object({
748
+ controllerId: import_zod11.z.string().min(1).max(128)
749
+ }).strict().refine(
750
+ (value) => value.roomId === value.expected.roomId,
751
+ "Participant control must target the observed room."
752
+ );
753
+ var controllerLeasedControlAckSchema = import_zod11.z.discriminatedUnion("status", [
754
+ import_zod11.z.object({
755
+ status: import_zod11.z.literal("applied"),
756
+ leaseId: import_zod11.z.uuid(),
757
+ sequence: leaseSequenceSchema,
758
+ replayed: import_zod11.z.boolean(),
759
+ operation: import_zod11.z.discriminatedUnion("kind", [
760
+ import_zod11.z.object({ kind: import_zod11.z.literal("input") }).strict(),
761
+ import_zod11.z.object({ kind: import_zod11.z.literal("release") }).strict(),
762
+ import_zod11.z.object({
763
+ kind: import_zod11.z.literal("action"),
764
+ result: airJamActionInvocationResultSchema
765
+ }).strict()
766
+ ])
767
+ }).strict(),
768
+ import_zod11.z.object({
769
+ status: import_zod11.z.literal("rejected"),
770
+ reason: import_zod11.z.enum([
771
+ "invalid_request",
772
+ "rate_limited",
773
+ "invalid_input",
774
+ "invalid_action",
775
+ "invalid_action_lane",
776
+ "room_not_found",
777
+ "unauthorized",
778
+ "active_host_missing",
779
+ "busy",
780
+ "stale_identity",
781
+ "stale_decision",
782
+ "invalid_deadline",
783
+ "lease_conflict",
784
+ "stale_sequence",
785
+ "sequence_conflict",
786
+ "unsupported"
787
+ ])
788
+ }).strict(),
789
+ import_zod11.z.object({
790
+ status: import_zod11.z.literal("unconfirmed"),
791
+ reason: import_zod11.z.enum([
792
+ "host_ack_unavailable",
793
+ "transport_ack_unavailable",
794
+ "runtime_replaced",
795
+ "invalid_acknowledgement",
796
+ "runtime_unavailable"
797
+ ])
798
+ }).strict()
799
+ ]);
800
+
801
+ // src/protocol/runtime-reporting.ts
802
+ var import_zod12 = require("zod");
803
+ var AIRJAM_RUNTIME_ERROR_REPORT_CONTRACT_VERSION = 2;
804
+ var runtimeErrorReportSchema = import_zod12.z.object({
805
+ contractVersion: import_zod12.z.literal(AIRJAM_RUNTIME_ERROR_REPORT_CONTRACT_VERSION),
806
+ reportId: import_zod12.z.uuid(),
518
807
  roomId: roomCodeSchema,
519
- storeDomain: import_zod7.z.string().trim().min(1).max(128),
520
- requestId: stateSyncRequestIdSchema.optional()
808
+ instance: import_zod12.z.string().min(1).max(64),
809
+ role: import_zod12.z.enum(["host", "controller"]),
810
+ seat: seatIdSchema.optional(),
811
+ code: import_zod12.z.literal("AJ_RUNTIME_RENDER_CRASH"),
812
+ errorName: import_zod12.z.string().trim().min(1).max(80).regex(/^[A-Za-z][A-Za-z0-9._-]*$/u),
813
+ digest: import_zod12.z.string().regex(/^[a-f0-9]{8}$/u),
814
+ occurredAt: import_zod12.z.iso.datetime()
521
815
  }).strict();
816
+ var RUNTIME_ERROR_REPORT_RETRY_DELAYS_MS = [1e3, 2e3, 4e3];
817
+ var createRuntimeErrorReporter = ({
818
+ endpoint,
819
+ credentials
820
+ }) => {
821
+ return (report) => {
822
+ const body = JSON.stringify(report);
823
+ const send = async (retries) => {
824
+ const response = await fetch(endpoint, {
825
+ method: "POST",
826
+ headers: { "content-type": "application/json" },
827
+ body,
828
+ credentials,
829
+ keepalive: true
830
+ }).catch(() => null);
831
+ const [delay, ...later] = retries;
832
+ if (response?.status !== 404 || delay === void 0) return;
833
+ await new Promise((resolve) => setTimeout(resolve, delay));
834
+ await send(later);
835
+ };
836
+ void send(RUNTIME_ERROR_REPORT_RETRY_DELAYS_MS);
837
+ };
838
+ };
839
+
840
+ // src/protocol/signed-envelope.ts
841
+ var encoder = new TextEncoder();
842
+ var decoder = new TextDecoder();
522
843
 
523
844
  // src/protocol/url-policy.ts
524
- var import_zod8 = require("zod");
845
+ var import_zod13 = require("zod");
525
846
  var ALLOWED_RUNTIME_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:"]);
526
847
  var parseRuntimeUrl = (value) => {
527
848
  try {
@@ -537,7 +858,11 @@ var parseRuntimeUrl = (value) => {
537
858
  return null;
538
859
  }
539
860
  };
540
- var runtimeUrlSchema = import_zod8.z.string().trim().min(1).refine((value) => parseRuntimeUrl(value) !== null, {
861
+ var normalizeRuntimeUrl = (value) => {
862
+ const parsed = parseRuntimeUrl(value);
863
+ return parsed ? parsed.toString() : null;
864
+ };
865
+ var runtimeUrlSchema = import_zod13.z.string().trim().min(1).refine((value) => parseRuntimeUrl(value) !== null, {
541
866
  message: "URL must be a valid http(s) URL without embedded credentials."
542
867
  });
543
868
 
@@ -785,11 +1110,673 @@ var parseRuntimeTopologyFromSearchParams = (params) => {
785
1110
  });
786
1111
  };
787
1112
 
788
- // src/state/connection-store.ts
789
- var import_zustand = require("zustand");
1113
+ // src/runtime/embedded-parent.ts
1114
+ function embeddedRuntimeParent(topology) {
1115
+ if (typeof window === "undefined" || window.parent === window || !topology.embedded)
1116
+ return null;
1117
+ if (!topology.embedParentOrigin)
1118
+ throw new Error("An embedded runtime requires its declared parent origin.");
1119
+ return {
1120
+ window: window.parent,
1121
+ origin: new URL(topology.embedParentOrigin).origin
1122
+ };
1123
+ }
1124
+
1125
+ // src/core/hosted-rooms.ts
1126
+ var AIR_JAM_HOSTED_RUNTIME_ERRORS_ENDPOINT = "https://airjam.io/api/airjam/runtime-errors";
1127
+ var hostedRuntimeErrorReporter = createRuntimeErrorReporter({
1128
+ endpoint: AIR_JAM_HOSTED_RUNTIME_ERRORS_ENDPOINT,
1129
+ credentials: "omit"
1130
+ });
1131
+
1132
+ // src/runtime/browser-replay.ts
1133
+ var import_zod24 = require("zod");
1134
+
1135
+ // src/core/input-log.ts
1136
+ var import_zod15 = require("zod");
1137
+
1138
+ // src/core/settings.ts
1139
+ var import_zod14 = require("zod");
1140
+ var common = {
1141
+ live: import_zod14.z.boolean().default(false),
1142
+ description: import_zod14.z.string().min(1).optional()
1143
+ };
1144
+ var numberSettingSchema = import_zod14.z.object({
1145
+ kind: import_zod14.z.literal("number"),
1146
+ default: import_zod14.z.number().finite(),
1147
+ min: import_zod14.z.number().finite(),
1148
+ max: import_zod14.z.number().finite(),
1149
+ step: import_zod14.z.number().finite().positive().optional(),
1150
+ ...common
1151
+ }).strict();
1152
+ var booleanSettingSchema = import_zod14.z.object({
1153
+ kind: import_zod14.z.literal("boolean"),
1154
+ default: import_zod14.z.boolean(),
1155
+ ...common
1156
+ }).strict();
1157
+ var choiceSettingSchema = import_zod14.z.object({
1158
+ kind: import_zod14.z.literal("choice"),
1159
+ options: import_zod14.z.array(import_zod14.z.string().min(1)).nonempty(),
1160
+ default: import_zod14.z.string(),
1161
+ ...common
1162
+ }).strict();
1163
+ var airJamSettingSchema = import_zod14.z.discriminatedUnion("kind", [
1164
+ numberSettingSchema,
1165
+ booleanSettingSchema,
1166
+ choiceSettingSchema
1167
+ ]);
1168
+ var airJamSettingsValuesSchema = import_zod14.z.record(
1169
+ import_zod14.z.string(),
1170
+ import_zod14.z.union([import_zod14.z.number().finite(), import_zod14.z.boolean(), import_zod14.z.string()])
1171
+ );
1172
+
1173
+ // src/core/input-log.ts
1174
+ var AIR_JAM_INPUT_LOG_EVENTS = [
1175
+ "seat",
1176
+ "left",
1177
+ "input",
1178
+ "runtime",
1179
+ "action",
1180
+ "settings"
1181
+ ];
1182
+ var inputLogEntrySchema = import_zod15.z.object({
1183
+ /** The step the event reached the game before. */
1184
+ tick: import_zod15.z.number().int().positive(),
1185
+ event: import_zod15.z.enum(AIR_JAM_INPUT_LOG_EVENTS),
1186
+ payload: import_zod15.z.record(import_zod15.z.string(), import_zod15.z.unknown())
1187
+ }).strict();
1188
+ var airJamInputLogSchema = import_zod15.z.object({
1189
+ version: import_zod15.z.literal(3),
1190
+ settings: airJamSettingsValuesSchema,
1191
+ seed: import_zod15.z.number().int().min(0).max(4294967295),
1192
+ stepMs: import_zod15.z.number().positive(),
1193
+ /** Steps the recorded host took. */
1194
+ ticks: import_zod15.z.number().int().nonnegative(),
1195
+ /** The store domain of stores that declare none, so actions find their store again. */
1196
+ storeDomain: import_zod15.z.string().min(1),
1197
+ entries: import_zod15.z.array(inputLogEntrySchema)
1198
+ }).strict();
1199
+ var AIR_JAM_INPUT_LOG_MAX_GAME_MS = 30 * 60 * 1e3;
1200
+ var AIR_JAM_INPUT_LOG_MAX_ENTRY_BYTES = 16 * 1024 * 1024;
1201
+
1202
+ // src/core/replay-input-log.ts
1203
+ var import_zod23 = require("zod");
1204
+
1205
+ // src/runtime/contracts/control.ts
1206
+ var import_nanoid2 = require("nanoid");
1207
+ var import_zod22 = require("zod");
1208
+
1209
+ // src/agent/agent-evaluator.ts
1210
+ var import_zod16 = require("zod");
1211
+
1212
+ // src/utils/is-rpc-serializable.ts
1213
+ var isRpcSerializable = (value, seen = /* @__PURE__ */ new WeakSet()) => {
1214
+ if (value === null || value === void 0) {
1215
+ return true;
1216
+ }
1217
+ const valueType = typeof value;
1218
+ if (valueType === "string" || valueType === "boolean") {
1219
+ return true;
1220
+ }
1221
+ if (valueType === "number") {
1222
+ return Number.isFinite(value);
1223
+ }
1224
+ if (valueType === "function" || valueType === "symbol" || valueType === "bigint") {
1225
+ return false;
1226
+ }
1227
+ if (valueType !== "object") {
1228
+ return false;
1229
+ }
1230
+ const objectValue = value;
1231
+ if (seen.has(objectValue)) {
1232
+ return false;
1233
+ }
1234
+ seen.add(objectValue);
1235
+ try {
1236
+ if (objectValue instanceof Date) return true;
1237
+ if (Array.isArray(objectValue))
1238
+ return objectValue.every((entry) => isRpcSerializable(entry, seen));
1239
+ const prototype = Object.getPrototypeOf(objectValue);
1240
+ if (prototype !== Object.prototype && prototype !== null) return false;
1241
+ return Object.values(objectValue).every(
1242
+ (entry) => isRpcSerializable(entry, seen)
1243
+ );
1244
+ } finally {
1245
+ seen.delete(objectValue);
1246
+ }
1247
+ };
1248
+
1249
+ // src/agent/agent-evaluator.ts
1250
+ var agentActionDescriptorSchema = import_zod16.z.object({
1251
+ actionId: import_zod16.z.string().min(1),
1252
+ target: import_zod16.z.object({
1253
+ kind: import_zod16.z.enum(["participant", "host"]),
1254
+ actionName: import_zod16.z.string().min(1),
1255
+ storeDomain: import_zod16.z.string().min(1)
1256
+ }),
1257
+ description: import_zod16.z.string().nullable(),
1258
+ availability: import_zod16.z.string().nullable(),
1259
+ payload: import_zod16.z.object({
1260
+ kind: import_zod16.z.enum(["none", "boolean", "number", "string", "enum", "json"]),
1261
+ description: import_zod16.z.string().nullable(),
1262
+ allowedValues: import_zod16.z.array(import_zod16.z.string()).optional()
1263
+ }),
1264
+ resultDescription: import_zod16.z.string().nullable()
1265
+ });
1266
+ var agentContractDescriptionSchema = import_zod16.z.object({
1267
+ snapshotStoreDomains: import_zod16.z.array(import_zod16.z.string().min(1)),
1268
+ snapshotDescription: import_zod16.z.string().nullable(),
1269
+ actions: import_zod16.z.array(agentActionDescriptorSchema)
1270
+ });
1271
+
1272
+ // src/runtime/host-observation.ts
1273
+ var import_nanoid = require("nanoid");
1274
+
1275
+ // src/runtime/contracts/observation.ts
1276
+ var import_zod17 = require("zod");
1277
+ var HOST_OBSERVATION_IMAGE_BYTES = 64e4;
1278
+ var jsonObject = import_zod17.z.record(import_zod17.z.string(), import_zod17.z.unknown()).refine(
1279
+ (value) => isRpcSerializable(value) && new TextEncoder().encode(JSON.stringify(value)).byteLength <= 128e3,
1280
+ {
1281
+ message: "Observations require serializable JSON within the 128 KB state budget."
1282
+ }
1283
+ );
1284
+ var hostObservationRequestSchema = import_zod17.z.object({
1285
+ roomId: roomCodeSchema,
1286
+ controllerId: import_zod17.z.string().min(1).max(128).nullable(),
1287
+ scope: import_zod17.z.enum(["player", "diagnostic"]),
1288
+ includeImage: import_zod17.z.boolean(),
1289
+ expected: hostObservationIdentitySchema.optional()
1290
+ }).strict();
1291
+ var hostObservationImageSchema = import_zod17.z.object({
1292
+ mimeType: import_zod17.z.enum(["image/jpeg", "image/png", "image/webp"]),
1293
+ data: import_zod17.z.string().min(4).max(Math.ceil(HOST_OBSERVATION_IMAGE_BYTES / 3) * 4).regex(/^[A-Za-z0-9+/]*={0,2}$/).refine(
1294
+ (value) => value.length % 4 === 0 && value.length / 4 * 3 - (value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0) <= HOST_OBSERVATION_IMAGE_BYTES,
1295
+ "Observation image exceeds its byte budget or is invalid base64."
1296
+ ),
1297
+ width: import_zod17.z.number().int().positive().max(4096),
1298
+ height: import_zod17.z.number().int().positive().max(4096),
1299
+ coverage: import_zod17.z.enum(["render-surface", "host-document", "controller-view"])
1300
+ }).strict();
1301
+ var storeRevision = import_zod17.z.object({
1302
+ storeDomain: import_zod17.z.string().min(1),
1303
+ revision: import_zod17.z.number().int().nonnegative()
1304
+ });
1305
+ var hostRuntimeFaultSchema = import_zod17.z.object({
1306
+ name: import_zod17.z.string().max(128),
1307
+ message: import_zod17.z.string().max(2048),
1308
+ source: import_zod17.z.object({
1309
+ file: import_zod17.z.string().max(2048),
1310
+ line: import_zod17.z.number().int().positive(),
1311
+ column: import_zod17.z.number().int().positive()
1312
+ }).strict().nullable(),
1313
+ stack: import_zod17.z.string().max(8192)
1314
+ }).strict();
1315
+ var hostObservationPresentationSchema = import_zod17.z.object({
1316
+ runtimeState: runtimeStateSchema,
1317
+ connectionStatus: connectionStatusSchema,
1318
+ fault: hostRuntimeFaultSchema.nullable().optional()
1319
+ }).strict();
1320
+ var hostObservationClockSchema = import_zod17.z.object({
1321
+ startedAtMs: import_zod17.z.number().nonnegative(),
1322
+ finishedAtMs: import_zod17.z.number().nonnegative()
1323
+ }).strict().refine(
1324
+ (value) => value.finishedAtMs >= value.startedAtMs,
1325
+ "The host clock must advance monotonically."
1326
+ );
1327
+ var hostObservationSchema = import_zod17.z.object({
1328
+ version: import_zod17.z.literal(1),
1329
+ id: import_zod17.z.string().min(1),
1330
+ identity: hostObservationIdentitySchema,
1331
+ sequence: import_zod17.z.number().int().positive(),
1332
+ scope: import_zod17.z.enum(["player", "diagnostic"]),
1333
+ controllerId: import_zod17.z.string().nullable(),
1334
+ host: import_zod17.z.object({
1335
+ before: hostObservationPresentationSchema.nullable(),
1336
+ after: hostObservationPresentationSchema.nullable()
1337
+ }).optional(),
1338
+ actions: import_zod17.z.array(agentActionDescriptorSchema).optional(),
1339
+ capabilities: import_zod17.z.object({
1340
+ participantControl: import_zod17.z.object({
1341
+ input: import_zod17.z.literal(1).optional(),
1342
+ inputSchema: participantInputSchemaDescriptionSchema.optional(),
1343
+ actions: import_zod17.z.literal(1).optional()
1344
+ }).optional()
1345
+ }).optional(),
1346
+ capturedAt: import_zod17.z.iso.datetime(),
1347
+ clock: hostObservationClockSchema.optional(),
1348
+ /** The page's slowest fixed-step simulation against real time, since it started. */
1349
+ pace: import_zod17.z.object({
1350
+ frames: import_zod17.z.number().int().nonnegative(),
1351
+ wallMs: import_zod17.z.number().nonnegative(),
1352
+ simulatedMs: import_zod17.z.number().nonnegative()
1353
+ }).strict().optional(),
1354
+ durationMs: import_zod17.z.number().nonnegative(),
1355
+ snapshot: jsonObject,
1356
+ runtime: jsonObject.nullable(),
1357
+ ticks: import_zod17.z.object({
1358
+ before: import_zod17.z.number().int().nonnegative().nullable(),
1359
+ after: import_zod17.z.number().int().nonnegative().nullable()
1360
+ }),
1361
+ stores: import_zod17.z.object({
1362
+ before: import_zod17.z.array(storeRevision),
1363
+ after: import_zod17.z.array(storeRevision)
1364
+ }),
1365
+ visual: import_zod17.z.discriminatedUnion("status", [
1366
+ import_zod17.z.object({
1367
+ status: import_zod17.z.literal("captured"),
1368
+ image: hostObservationImageSchema
1369
+ }),
1370
+ import_zod17.z.object({
1371
+ status: import_zod17.z.literal("unavailable"),
1372
+ reason: import_zod17.z.enum([
1373
+ "not-requested",
1374
+ "unsupported",
1375
+ "surface-unavailable",
1376
+ "timeout"
1377
+ ]),
1378
+ detail: import_zod17.z.string().max(1024).optional()
1379
+ })
1380
+ ])
1381
+ });
1382
+
1383
+ // src/runtime/contracts/agent-control.ts
1384
+ var import_zod21 = require("zod");
1385
+
1386
+ // src/runtime/contracts/clip.ts
1387
+ var import_zod18 = require("zod");
1388
+ var CLIP_MIN_FRAME_INTERVAL_MS = 33;
1389
+ var clipFrameIntervalSchema = import_zod18.z.number().int().min(CLIP_MIN_FRAME_INTERVAL_MS);
1390
+ var CLIP_MAX_DURATION_MS = 15e3;
1391
+ var CLIP_MAX_FRAMES = Math.ceil(
1392
+ CLIP_MAX_DURATION_MS / CLIP_MIN_FRAME_INTERVAL_MS
1393
+ );
1394
+ var CLIP_MAX_BYTES = 4 * 1024 * 1024;
1395
+ var CLIP_FRAME_MAX_BYTES = 160 * 1024;
1396
+ var CLIP_PAGE_BASE64_CHARS = 768 * 1024;
1397
+ var CLIP_RECORDING_LIFETIME_MS = 6e5;
1398
+ var CLIP_VIDEO_MAX_BYTES = 32 * 1024 * 1024;
1399
+ var clipNotCapturedReasonSchema = import_zod18.z.enum([
1400
+ "busy",
1401
+ "unsupported",
1402
+ "surface-unavailable",
1403
+ "capture-failed",
1404
+ "runtime-replaced",
1405
+ "host-unavailable",
1406
+ "headless"
1407
+ ]);
1408
+ var clipImageBytes = (data) => data.length / 4 * 3 - (data.endsWith("==") ? 2 : data.endsWith("=") ? 1 : 0);
1409
+ var clipFrameSchema = import_zod18.z.object({
1410
+ index: import_zod18.z.number().int().nonnegative(),
1411
+ atMs: import_zod18.z.number().nonnegative().max(CLIP_RECORDING_LIFETIME_MS),
1412
+ width: import_zod18.z.number().int().positive().max(1280),
1413
+ height: import_zod18.z.number().int().positive().max(1280),
1414
+ mimeType: import_zod18.z.literal("image/jpeg"),
1415
+ data: import_zod18.z.string().min(4).max(Math.ceil(CLIP_FRAME_MAX_BYTES / 3) * 4).regex(/^[A-Za-z0-9+/]*={0,2}$/).refine(
1416
+ (data) => data.length % 4 === 0 && clipImageBytes(data) <= CLIP_FRAME_MAX_BYTES,
1417
+ "Clip frame exceeds its byte budget or is invalid base64."
1418
+ )
1419
+ }).strict();
1420
+ var clipMetadata = {
1421
+ clipId: import_zod18.z.string().min(1).max(128),
1422
+ identity: hostObservationIdentitySchema,
1423
+ startedAt: import_zod18.z.iso.datetime(),
1424
+ frameIntervalMs: clipFrameIntervalSchema,
1425
+ // Offsets and duration refer to the original recording, even after old frames drop.
1426
+ durationMs: import_zod18.z.number().nonnegative().max(CLIP_RECORDING_LIFETIME_MS),
1427
+ droppedFrames: import_zod18.z.number().int().nonnegative(),
1428
+ skippedFrames: import_zod18.z.number().int().nonnegative()
1429
+ };
1430
+ var clipArtifactSchema = import_zod18.z.object({
1431
+ version: import_zod18.z.literal(1),
1432
+ ...clipMetadata,
1433
+ frames: import_zod18.z.array(clipFrameSchema).min(1).max(CLIP_MAX_FRAMES)
1434
+ }).strict().superRefine((clip, ctx) => {
1435
+ const frames = clip.frames;
1436
+ if (frames.length > Math.ceil(CLIP_MAX_DURATION_MS / clip.frameIntervalMs))
1437
+ ctx.addIssue({
1438
+ code: "custom",
1439
+ message: "Clip exceeds its cadence frame budget."
1440
+ });
1441
+ if (frames.reduce((sum, frame) => sum + clipImageBytes(frame.data), 0) > CLIP_MAX_BYTES)
1442
+ ctx.addIssue({
1443
+ code: "custom",
1444
+ message: "Clip exceeds its image byte budget."
1445
+ });
1446
+ if (frames.some(
1447
+ (frame, i) => frame.atMs > clip.durationMs || frame.atMs < clip.durationMs - CLIP_MAX_DURATION_MS || i > 0 && (frame.atMs <= frames[i - 1].atMs || frame.index !== frames[i - 1].index + 1)
1448
+ ))
1449
+ ctx.addIssue({
1450
+ code: "custom",
1451
+ message: "Clip frames must be ordered within the kept time window."
1452
+ });
1453
+ });
1454
+ var clipNativeCaptureSchema = import_zod18.z.object({
1455
+ drawsAttempted: import_zod18.z.number().int().nonnegative(),
1456
+ drawsMade: import_zod18.z.number().int().nonnegative()
1457
+ }).strict();
1458
+ var clipVideoPageSchema = import_zod18.z.object({
1459
+ mimeType: import_zod18.z.string().min(1).max(128),
1460
+ width: import_zod18.z.number().int().positive().max(1280),
1461
+ height: import_zod18.z.number().int().positive().max(1280),
1462
+ chunks: import_zod18.z.array(
1463
+ import_zod18.z.string().min(4).max(CLIP_PAGE_BASE64_CHARS).regex(
1464
+ /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/
1465
+ )
1466
+ ).max(1),
1467
+ nextChunk: import_zod18.z.number().int().nonnegative().nullable()
1468
+ }).strict();
1469
+ var clipReadSchema = import_zod18.z.object({
1470
+ ...clipMetadata,
1471
+ state: import_zod18.z.enum(["recording", "stopped"]),
1472
+ // Native encoded frames are counted after stop by the video consumer.
1473
+ nativeCapture: clipNativeCaptureSchema.optional(),
1474
+ droppedFrames: clipMetadata.droppedFrames.nullable(),
1475
+ skippedFrames: clipMetadata.skippedFrames.nullable(),
1476
+ frameCount: import_zod18.z.number().int().nonnegative().max(Math.ceil(CLIP_RECORDING_LIFETIME_MS / CLIP_MIN_FRAME_INTERVAL_MS)).nullable(),
1477
+ notCaptured: clipNotCapturedReasonSchema.nullable(),
1478
+ frames: import_zod18.z.array(clipFrameSchema).max(CLIP_MAX_FRAMES).refine(
1479
+ (frames) => frames.reduce((sum, frame) => sum + frame.data.length, 0) <= CLIP_PAGE_BASE64_CHARS,
1480
+ "Clip page exceeds its transfer budget."
1481
+ ),
1482
+ nextFrame: import_zod18.z.number().int().nonnegative().nullable(),
1483
+ video: clipVideoPageSchema.optional()
1484
+ }).strict();
1485
+
1486
+ // src/runtime/contracts/input-log.ts
1487
+ var import_zod19 = require("zod");
1488
+ var INPUT_LOG_PAGE_BYTES = 512 * 1024;
1489
+ var inputLogCutSchema = import_zod19.z.object({
1490
+ ticks: import_zod19.z.number().int().nonnegative(),
1491
+ entryCount: import_zod19.z.number().int().nonnegative()
1492
+ }).strict();
1493
+ var hostInputLogPageSchema = import_zod19.z.object({
1494
+ identity: hostObservationIdentitySchema,
1495
+ observation: hostObservationSchema.optional(),
1496
+ header: airJamInputLogSchema.omit({ entries: true }),
1497
+ entryCount: import_zod19.z.number().int().nonnegative(),
1498
+ full: import_zod19.z.boolean(),
1499
+ entries: airJamInputLogSchema.shape.entries,
1500
+ nextEntry: import_zod19.z.number().int().nonnegative().nullable()
1501
+ }).strict();
1502
+ var inputLogNotReplayableReasonSchema = import_zod19.z.enum([
1503
+ "no-simulation",
1504
+ "loading",
1505
+ "runtime-replaced",
1506
+ "host-unavailable"
1507
+ ]);
1508
+
1509
+ // src/runtime/contracts/timeline.ts
1510
+ var import_zod20 = require("zod");
1511
+ var facts = {
1512
+ id: import_zod20.z.string().min(1),
1513
+ tick: import_zod20.z.number().int().nonnegative(),
1514
+ /** Epoch milliseconds, unlike the simulation's game clock. */
1515
+ at: import_zod20.z.number().nonnegative()
1516
+ };
1517
+ var hostTimelineEntrySchema = import_zod20.z.discriminatedUnion("kind", [
1518
+ import_zod20.z.object({
1519
+ ...facts,
1520
+ kind: import_zod20.z.enum(["join", "drop", "leave", "name"]),
1521
+ controllerId: import_zod20.z.string(),
1522
+ name: import_zod20.z.string().optional(),
1523
+ previousName: import_zod20.z.string().optional()
1524
+ }),
1525
+ import_zod20.z.object({
1526
+ ...facts,
1527
+ kind: import_zod20.z.literal("state"),
1528
+ state: import_zod20.z.enum(["paused", "playing"])
1529
+ }),
1530
+ import_zod20.z.object({
1531
+ ...facts,
1532
+ kind: import_zod20.z.literal("settings"),
1533
+ values: airJamSettingsValuesSchema,
1534
+ previousValues: airJamSettingsValuesSchema
1535
+ }),
1536
+ import_zod20.z.object({
1537
+ ...facts,
1538
+ kind: import_zod20.z.literal("moment"),
1539
+ text: import_zod20.z.string().min(1).max(240)
1540
+ })
1541
+ ]);
1542
+ var hostTimelinePaceSchema = import_zod20.z.object({
1543
+ /** End of the five-second sampling window, in epoch milliseconds. */
1544
+ at: import_zod20.z.number().nonnegative(),
1545
+ fps: import_zod20.z.number().nonnegative(),
1546
+ speed: import_zod20.z.number().nonnegative()
1547
+ });
1548
+ var hostTimelineSchema = import_zod20.z.discriminatedUnion("status", [
1549
+ import_zod20.z.object({
1550
+ status: import_zod20.z.literal("available"),
1551
+ identity: hostObservationIdentitySchema,
1552
+ startedAt: import_zod20.z.number().nonnegative(),
1553
+ stepMs: import_zod20.z.number().positive(),
1554
+ entries: import_zod20.z.array(hostTimelineEntrySchema),
1555
+ pace: import_zod20.z.array(hostTimelinePaceSchema).max(360)
1556
+ }),
1557
+ import_zod20.z.object({
1558
+ status: import_zod20.z.literal("unavailable"),
1559
+ identity: hostObservationIdentitySchema,
1560
+ reason: import_zod20.z.enum(["no-simulation", "simulation-loading"])
1561
+ })
1562
+ ]);
1563
+
1564
+ // src/runtime/contracts/agent-control.ts
1565
+ var identity = import_zod21.z.object({
1566
+ roomId: roomCodeSchema,
1567
+ controllerId: import_zod21.z.string().min(1)
1568
+ });
1569
+ var actionRequest = identity.extend({
1570
+ contractId: import_zod21.z.string().min(1),
1571
+ runtimeId: import_zod21.z.string().min(1),
1572
+ actionId: import_zod21.z.string().min(1),
1573
+ payload: import_zod21.z.unknown().refine(
1574
+ (value) => isRpcSerializable(value),
1575
+ "Agent input must be serializable JSON data."
1576
+ ).optional()
1577
+ });
1578
+ var hostAgentRequestSchema = import_zod21.z.discriminatedUnion("operation", [
1579
+ /** The room's instance and every seat in it, with what kind of device holds each. */
1580
+ import_zod21.z.object({ operation: import_zod21.z.literal("seats"), roomId: roomCodeSchema }).strict(),
1581
+ import_zod21.z.object({ operation: import_zod21.z.literal("timeline-read"), roomId: roomCodeSchema }).strict(),
1582
+ import_zod21.z.object({
1583
+ operation: import_zod21.z.literal("input-log-read"),
1584
+ roomId: roomCodeSchema,
1585
+ runtimeId: import_zod21.z.string().min(1),
1586
+ cut: inputLogCutSchema.nullable(),
1587
+ observe: hostObservationRequestSchema.pick({ controllerId: true, scope: true }).optional(),
1588
+ fromEntry: import_zod21.z.number().int().nonnegative()
1589
+ }).strict(),
1590
+ hostObservationRequestSchema.extend({ operation: import_zod21.z.literal("observe") }).strict(),
1591
+ identity.extend({
1592
+ operation: import_zod21.z.literal("read"),
1593
+ controllerId: import_zod21.z.string().min(1).nullable()
1594
+ }).strict(),
1595
+ import_zod21.z.object({
1596
+ operation: import_zod21.z.literal("settings-read"),
1597
+ roomId: roomCodeSchema,
1598
+ runtimeId: import_zod21.z.string().min(1)
1599
+ }).strict(),
1600
+ import_zod21.z.object({
1601
+ operation: import_zod21.z.literal("settings-update"),
1602
+ roomId: roomCodeSchema,
1603
+ runtimeId: import_zod21.z.string().min(1),
1604
+ patch: airJamSettingsValuesSchema,
1605
+ expectedRevision: import_zod21.z.number().int().nonnegative()
1606
+ }).strict(),
1607
+ actionRequest.extend({ operation: import_zod21.z.literal("resolve") }).strict(),
1608
+ actionRequest.extend({ operation: import_zod21.z.literal("invoke-host") }).strict(),
1609
+ import_zod21.z.object({
1610
+ operation: import_zod21.z.literal("clip-start"),
1611
+ delivery: import_zod21.z.enum(["pages", "video"]).optional(),
1612
+ frameIntervalMs: clipFrameIntervalSchema.optional(),
1613
+ roomId: roomCodeSchema,
1614
+ runtimeId: import_zod21.z.string().min(1),
1615
+ clipId: import_zod21.z.string().min(1).max(128)
1616
+ }).strict(),
1617
+ import_zod21.z.object({
1618
+ operation: import_zod21.z.literal("clip-read"),
1619
+ roomId: roomCodeSchema,
1620
+ clipId: import_zod21.z.string().min(1).max(128),
1621
+ stop: import_zod21.z.boolean(),
1622
+ fromChunk: import_zod21.z.number().int().nonnegative().optional(),
1623
+ fromFrame: import_zod21.z.number().int().nonnegative()
1624
+ }).strict()
1625
+ ]);
1626
+ var hostAgentSnapshotSchema = agentContractDescriptionSchema.extend({
1627
+ contractId: import_zod21.z.string().min(1),
1628
+ runtimeId: import_zod21.z.string().min(1),
1629
+ snapshot: import_zod21.z.record(import_zod21.z.string(), import_zod21.z.unknown()),
1630
+ rawStores: import_zod21.z.array(
1631
+ import_zod21.z.object({
1632
+ storeDomain: import_zod21.z.string().min(1),
1633
+ data: import_zod21.z.record(import_zod21.z.string(), import_zod21.z.unknown()),
1634
+ revision: import_zod21.z.number().int().nonnegative(),
1635
+ updatedAt: import_zod21.z.string()
1636
+ })
1637
+ ),
1638
+ storeDomainBindings: import_zod21.z.array(
1639
+ import_zod21.z.object({
1640
+ contractStoreDomain: import_zod21.z.string(),
1641
+ runtimeStoreDomain: import_zod21.z.string()
1642
+ })
1643
+ )
1644
+ });
1645
+ var hostAgentResponseSchema = import_zod21.z.discriminatedUnion("operation", [
1646
+ import_zod21.z.object({
1647
+ operation: import_zod21.z.literal("seats"),
1648
+ instance: import_zod21.z.string().min(1),
1649
+ seats: import_zod21.z.array(seatViewSchema)
1650
+ }).strict(),
1651
+ import_zod21.z.object({
1652
+ operation: import_zod21.z.literal("timeline-read"),
1653
+ timeline: hostTimelineSchema
1654
+ }).strict(),
1655
+ import_zod21.z.object({
1656
+ operation: import_zod21.z.literal("input-log-read"),
1657
+ page: hostInputLogPageSchema
1658
+ }).strict(),
1659
+ import_zod21.z.object({
1660
+ operation: import_zod21.z.literal("clip-start"),
1661
+ clipId: import_zod21.z.string().min(1).max(128),
1662
+ startedAt: import_zod21.z.iso.datetime()
1663
+ }).strict(),
1664
+ import_zod21.z.object({ operation: import_zod21.z.literal("clip-read"), clip: clipReadSchema }).strict(),
1665
+ import_zod21.z.object({
1666
+ operation: import_zod21.z.enum(["settings-read", "settings-update"]),
1667
+ values: airJamSettingsValuesSchema,
1668
+ revision: import_zod21.z.number().int().nonnegative()
1669
+ }),
1670
+ import_zod21.z.object({
1671
+ operation: import_zod21.z.literal("observe"),
1672
+ observation: hostObservationSchema
1673
+ }),
1674
+ import_zod21.z.object({
1675
+ operation: import_zod21.z.literal("read"),
1676
+ snapshot: hostAgentSnapshotSchema.nullable()
1677
+ }),
1678
+ import_zod21.z.object({
1679
+ operation: import_zod21.z.enum(["resolve", "invoke-host"]),
1680
+ target: import_zod21.z.object({
1681
+ kind: import_zod21.z.enum(["participant", "host"]),
1682
+ actionName: import_zod21.z.string(),
1683
+ storeDomain: import_zod21.z.string()
1684
+ }),
1685
+ payload: import_zod21.z.record(import_zod21.z.string(), import_zod21.z.unknown()).optional(),
1686
+ acknowledgement: airJamActionInvocationResultSchema.optional()
1687
+ })
1688
+ ]);
1689
+ var hostAgentRequestMessageSchema = import_zod21.z.object({
1690
+ type: import_zod21.z.literal("AIRJAM_HOST_AGENT"),
1691
+ requestId: import_zod21.z.string().min(1).max(128),
1692
+ request: hostAgentRequestSchema
1693
+ }).strict();
1694
+ var hostAgentResultMessageSchema = import_zod21.z.object({
1695
+ type: import_zod21.z.literal("AIRJAM_HOST_AGENT_RESULT"),
1696
+ requestId: hostAgentRequestMessageSchema.shape.requestId,
1697
+ result: import_zod21.z.discriminatedUnion("ok", [
1698
+ import_zod21.z.object({ ok: import_zod21.z.literal(true), response: hostAgentResponseSchema }),
1699
+ import_zod21.z.object({ ok: import_zod21.z.literal(false), error: import_zod21.z.string().min(1).max(1024) })
1700
+ ])
1701
+ }).strict();
1702
+
1703
+ // src/runtime/contracts/control.ts
1704
+ var hostRuntimeActionRequestSchema = import_zod22.z.object({
1705
+ roomId: roomCodeSchema,
1706
+ storeDomain: import_zod22.z.string().trim().min(1).max(128),
1707
+ actionName: import_zod22.z.string().trim().min(1).max(128),
1708
+ payload: import_zod22.z.record(import_zod22.z.string(), import_zod22.z.unknown()).optional()
1709
+ }).strict();
1710
+ var hostStateEpochSchema = import_zod22.z.object({
1711
+ storeDomain: import_zod22.z.string().min(1).max(128),
1712
+ epoch: import_zod22.z.string().min(1).max(128)
1713
+ });
1714
+
1715
+ // src/core/replay-input-log.ts
1716
+ var settingsLogEventSchema = import_zod23.z.object({
1717
+ patch: airJamSettingsValuesSchema,
1718
+ revision: import_zod23.z.number().int().positive()
1719
+ }).strict();
1720
+ var seatLogEventSchema = import_zod23.z.object({ seat: seatViewSchema });
1721
+ var leftLogEventSchema = import_zod23.z.object({ seat: import_zod23.z.string() });
1722
+ var inputLogEventSchema = import_zod23.z.object({
1723
+ seat: import_zod23.z.string(),
1724
+ input: import_zod23.z.record(import_zod23.z.string(), import_zod23.z.unknown())
1725
+ });
1726
+ var runtimeLogEventSchema = import_zod23.z.object({ runtimeState: runtimeStateSchema });
1727
+ var actionLogEventSchema = import_zod23.z.object({
1728
+ actionName: import_zod23.z.string(),
1729
+ payload: import_zod23.z.unknown().optional(),
1730
+ storeDomain: import_zod23.z.string(),
1731
+ actor: import_zod23.z.object({
1732
+ id: import_zod23.z.string(),
1733
+ role: import_zod23.z.enum(["host", "controller"])
1734
+ })
1735
+ });
790
1736
 
791
- // src/context/socket-manager.ts
792
- var import_socket = require("socket.io-client");
1737
+ // src/runtime/browser-replay.ts
1738
+ var whole = import_zod24.z.number().int().nonnegative();
1739
+ var replayAdvanceSchema = import_zod24.z.union([
1740
+ import_zod24.z.object({ steps: whole }).strict(),
1741
+ import_zod24.z.object({ ms: import_zod24.z.number().finite().nonnegative() }).strict(),
1742
+ import_zod24.z.object({ toTick: whole }).strict()
1743
+ ]);
1744
+ var replayRequestSchema = import_zod24.z.discriminatedUnion("operation", [
1745
+ import_zod24.z.object({
1746
+ operation: import_zod24.z.literal("open"),
1747
+ log: airJamInputLogSchema,
1748
+ observe: hostObservationRequestSchema.pick({ scope: true, controllerId: true }).optional()
1749
+ }).strict(),
1750
+ import_zod24.z.object({ operation: import_zod24.z.literal("advance"), by: replayAdvanceSchema }).strict(),
1751
+ import_zod24.z.object({
1752
+ operation: import_zod24.z.literal("read"),
1753
+ /** Capture the paused frame on this explicit read; open and advance omit images. */
1754
+ includeImage: import_zod24.z.boolean().optional()
1755
+ }).strict()
1756
+ ]);
1757
+ var replayReadSchema = import_zod24.z.object({
1758
+ tick: whole,
1759
+ ticks: whole,
1760
+ done: import_zod24.z.boolean(),
1761
+ stepMs: import_zod24.z.number().positive(),
1762
+ observation: hostObservationSchema
1763
+ }).strict();
1764
+ var replayRequestMessageSchema = import_zod24.z.object({
1765
+ type: import_zod24.z.literal("AIRJAM_REPLAY"),
1766
+ requestId: import_zod24.z.string().min(1),
1767
+ request: replayRequestSchema
1768
+ }).strict();
1769
+ var replayMessageSchema = import_zod24.z.discriminatedUnion("type", [
1770
+ import_zod24.z.object({ type: import_zod24.z.literal("AIRJAM_REPLAY_READY") }).strict(),
1771
+ import_zod24.z.object({
1772
+ type: import_zod24.z.literal("AIRJAM_REPLAY_RESULT"),
1773
+ requestId: import_zod24.z.string().min(1),
1774
+ result: import_zod24.z.discriminatedUnion("ok", [
1775
+ import_zod24.z.object({ ok: import_zod24.z.literal(true), response: replayReadSchema }).strict(),
1776
+ import_zod24.z.object({ ok: import_zod24.z.literal(false), error: import_zod24.z.string() }).strict()
1777
+ ])
1778
+ }).strict()
1779
+ ]);
793
1780
 
794
1781
  // src/context/air-jam-context.tsx
795
1782
  var import_jsx_runtime2 = require("react/jsx-runtime");
@@ -831,8 +1818,10 @@ var useAssertSessionScope = (expectedScope, hookName) => {
831
1818
 
832
1819
  // src/runtime/runtime-owner-contexts.tsx
833
1820
  var import_react3 = require("react");
1821
+ var fixedControllerOrientationContext = (0, import_react3.createContext)(void 0);
834
1822
  var hostRuntimeContext = (0, import_react3.createContext)(null);
835
1823
  var controllerRuntimeContext = (0, import_react3.createContext)(null);
1824
+ var declaredStoresContext = (0, import_react3.createContext)(null);
836
1825
 
837
1826
  // src/hooks/use-air-jam-controller.ts
838
1827
  var toControllerState = (state) => {
@@ -844,8 +1833,6 @@ var toControllerState = (state) => {
844
1833
  lastError: state.lastError,
845
1834
  runtimeState: state.runtimeState,
846
1835
  controllerOrientation: state.controllerOrientation,
847
- stateMessage: state.stateMessage,
848
- roomSettings: state.roomSettings,
849
1836
  players: state.players,
850
1837
  selfPlayer
851
1838
  };
@@ -853,7 +1840,7 @@ var toControllerState = (state) => {
853
1840
  function useAirJamController(selector) {
854
1841
  useAssertSessionScope("controller", "useAirJamController");
855
1842
  const { store } = useAirJamContext();
856
- const selectedState = (0, import_zustand3.useStore)(
1843
+ const selectedState = (0, import_zustand2.useStore)(
857
1844
  store,
858
1845
  (0, import_shallow2.useShallow)((state) => {
859
1846
  const controllerState = toControllerState(state);
@@ -1059,7 +2046,7 @@ var ControllerPrimaryAction = ({
1059
2046
  children: [
1060
2047
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "min-w-0", children: [
1061
2048
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "truncate text-base font-black tracking-[0.12em] uppercase sm:text-lg", children: label }),
1062
- helper ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "mt-1 text-sm/5 font-medium tracking-normal normal-case opacity-80", children: helper }) : null
2049
+ helper ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "mt-1 text-sm/5 font-medium tracking-normal whitespace-normal normal-case opacity-80", children: helper }) : null
1063
2050
  ] }),
1064
2051
  icon ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "ml-4 flex shrink-0 items-center justify-center", children: icon }) : null
1065
2052
  ]
@@ -1067,19 +2054,335 @@ var ControllerPrimaryAction = ({
1067
2054
  ) });
1068
2055
  };
1069
2056
 
1070
- // src/components/host-mute-button.tsx
1071
- var import_lucide_react = require("lucide-react");
2057
+ // src/components/controls.tsx
2058
+ var import_react6 = require("react");
1072
2059
  var import_jsx_runtime6 = require("react/jsx-runtime");
1073
- function HostMuteButton({
1074
- muted,
1075
- onToggle,
1076
- className,
2060
+ var useControllerInput = () => {
2061
+ const runtime = (0, import_react6.useContext)(
2062
+ controllerRuntimeContext
2063
+ );
2064
+ if (!runtime?.input)
2065
+ throw createAirJamDiagnosticError(
2066
+ "AJ_INPUT_NOT_DECLARED",
2067
+ "Phone controls send declared controls. Declare them with defineAirJamGame({ input }) and render controls inside <airjam.Controller>."
2068
+ );
2069
+ return runtime.input;
2070
+ };
2071
+ var capturePointer = (event) => {
2072
+ try {
2073
+ event.currentTarget.setPointerCapture(event.pointerId);
2074
+ } catch {
2075
+ }
2076
+ };
2077
+ var isPressKey = (event) => event.key === " " || event.key === "Enter";
2078
+ var usePress = (start, disabled, onActiveChange) => {
2079
+ const release = (0, import_react6.useRef)(null);
2080
+ const pointer = (0, import_react6.useRef)(null);
2081
+ const [active, setActive] = (0, import_react6.useState)(false);
2082
+ const onActiveChangeRef = (0, import_react6.useRef)(onActiveChange);
2083
+ (0, import_react6.useEffect)(() => {
2084
+ onActiveChangeRef.current = onActiveChange;
2085
+ });
2086
+ const begin = (0, import_react6.useCallback)(() => {
2087
+ if (release.current) return false;
2088
+ release.current = start();
2089
+ setActive(true);
2090
+ onActiveChangeRef.current?.(true);
2091
+ return true;
2092
+ }, [start]);
2093
+ const end = (0, import_react6.useCallback)(() => {
2094
+ pointer.current = null;
2095
+ if (!release.current) return;
2096
+ release.current();
2097
+ release.current = null;
2098
+ setActive(false);
2099
+ onActiveChangeRef.current?.(false);
2100
+ }, []);
2101
+ (0, import_react6.useEffect)(() => {
2102
+ if (disabled) end();
2103
+ }, [disabled, end]);
2104
+ (0, import_react6.useEffect)(() => end, [end]);
2105
+ const endPointer = (event) => {
2106
+ if (event.pointerId === pointer.current) end();
2107
+ };
2108
+ return {
2109
+ active,
2110
+ handlers: {
2111
+ onPointerDown: (event) => {
2112
+ if (disabled || event.button !== 0 || !begin()) return;
2113
+ event.preventDefault();
2114
+ pointer.current = event.pointerId;
2115
+ capturePointer(event);
2116
+ },
2117
+ onPointerUp: endPointer,
2118
+ onPointerCancel: endPointer,
2119
+ onLostPointerCapture: endPointer,
2120
+ onKeyDown: (event) => {
2121
+ if (disabled || !isPressKey(event)) return;
2122
+ event.preventDefault();
2123
+ if (!event.repeat) begin();
2124
+ },
2125
+ onKeyUp: (event) => {
2126
+ if (!isPressKey(event)) return;
2127
+ event.preventDefault();
2128
+ end();
2129
+ },
2130
+ // Focus leaving ends a key hold; a finger still down keeps its press.
2131
+ onBlur: () => {
2132
+ if (pointer.current === null) end();
2133
+ },
2134
+ onContextMenu: (event) => event.preventDefault()
2135
+ }
2136
+ };
2137
+ };
2138
+ var ControlButton = ({
2139
+ control,
2140
+ disabled = false,
2141
+ onActiveChange,
2142
+ className,
2143
+ ...props
2144
+ }) => {
2145
+ const input = useControllerInput();
2146
+ const press = (0, import_react6.useCallback)(
2147
+ () => input.press(control.name),
2148
+ [input, control.name]
2149
+ );
2150
+ const { active, handlers } = usePress(press, disabled, onActiveChange);
2151
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2152
+ "button",
2153
+ {
2154
+ type: "button",
2155
+ ...props,
2156
+ ...handlers,
2157
+ disabled,
2158
+ "data-active": active,
2159
+ className: cn("touch-none select-none", className)
2160
+ }
2161
+ );
2162
+ };
2163
+ var AxisButton = ({
2164
+ control,
2165
+ value,
2166
+ disabled = false,
2167
+ onActiveChange,
2168
+ className,
2169
+ ...props
2170
+ }) => {
2171
+ const input = useControllerInput();
2172
+ const hold = (0, import_react6.useCallback)(
2173
+ () => input.hold(control.name, value),
2174
+ [input, control.name, value]
2175
+ );
2176
+ const { active, handlers } = usePress(hold, disabled, onActiveChange);
2177
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2178
+ "button",
2179
+ {
2180
+ type: "button",
2181
+ ...props,
2182
+ ...handlers,
2183
+ disabled,
2184
+ "data-active": active,
2185
+ className: cn("touch-none select-none", className)
2186
+ }
2187
+ );
2188
+ };
2189
+ var centre = (element) => {
2190
+ const rect = element?.getBoundingClientRect();
2191
+ return rect ? { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 } : null;
2192
+ };
2193
+ var resolveStickPoint = (point, origin, right, bottom) => {
2194
+ const xAxis = { x: right.x - origin.x, y: right.y - origin.y };
2195
+ const yAxis = { x: bottom.x - origin.x, y: bottom.y - origin.y };
2196
+ const determinant = xAxis.x * yAxis.y - xAxis.y * yAxis.x;
2197
+ if (!Number.isFinite(determinant) || Math.abs(determinant) < 1e-3)
2198
+ return { x: 0, y: 0 };
2199
+ const offset = { x: point.x - origin.x, y: point.y - origin.y };
2200
+ const across = (offset.x * yAxis.y - offset.y * yAxis.x) / determinant;
2201
+ const down = (xAxis.x * offset.y - xAxis.y * offset.x) / determinant;
2202
+ return { x: 2 * across - 1, y: 2 * down - 1 };
2203
+ };
2204
+ var shapeStick = (vector, directions, deadzone) => {
2205
+ const length = Math.hypot(vector.x, vector.y);
2206
+ if (length <= deadzone) return { x: 0, y: 0 };
2207
+ if (directions === "4-way")
2208
+ return Math.abs(vector.x) > Math.abs(vector.y) ? { x: Math.sign(vector.x), y: 0 } : { x: 0, y: Math.sign(vector.y) };
2209
+ return length > 1 ? { x: vector.x / length, y: vector.y / length } : vector;
2210
+ };
2211
+ var CENTRE = { x: 0, y: 0 };
2212
+ var Stick = ({
2213
+ control,
2214
+ directions = "any",
2215
+ deadzone = 0,
2216
+ disabled = false,
2217
+ knobClassName,
2218
+ knob,
2219
+ children,
2220
+ onActiveChange,
2221
+ className,
2222
+ ...props
2223
+ }) => {
2224
+ const fixedOrientation = (0, import_react6.useContext)(fixedControllerOrientationContext);
2225
+ if (fixedOrientation === null)
2226
+ throw new Error(
2227
+ "Stick requires joystick input: declare 'joystick' in inputModalities in airjam.config."
2228
+ );
2229
+ const input = useControllerInput();
2230
+ const origin = (0, import_react6.useRef)(null);
2231
+ const right = (0, import_react6.useRef)(null);
2232
+ const bottom = (0, import_react6.useRef)(null);
2233
+ const pointer = (0, import_react6.useRef)(null);
2234
+ const [active, setActive] = (0, import_react6.useState)(false);
2235
+ const subscribe = (0, import_react6.useCallback)(
2236
+ (listener) => input.subscribe(listener),
2237
+ [input]
2238
+ );
2239
+ const value = (0, import_react6.useSyncExternalStore)(
2240
+ subscribe,
2241
+ () => input.value(control.name),
2242
+ () => CENTRE
2243
+ );
2244
+ const setActiveState = (next) => {
2245
+ setActive(next);
2246
+ onActiveChange?.(next);
2247
+ };
2248
+ const follow = (event) => {
2249
+ const corners = [origin, right, bottom].map(
2250
+ ({ current }) => centre(current)
2251
+ );
2252
+ const [topLeft, topRight, bottomLeft] = corners;
2253
+ if (!topLeft || !topRight || !bottomLeft) return;
2254
+ input.set(
2255
+ control.name,
2256
+ shapeStick(
2257
+ resolveStickPoint(
2258
+ { x: event.clientX, y: event.clientY },
2259
+ topLeft,
2260
+ topRight,
2261
+ bottomLeft
2262
+ ),
2263
+ directions,
2264
+ deadzone
2265
+ )
2266
+ );
2267
+ };
2268
+ const end = (event) => {
2269
+ if (event.pointerId !== pointer.current) return;
2270
+ pointer.current = null;
2271
+ input.set(control.name, CENTRE);
2272
+ setActiveState(false);
2273
+ };
2274
+ (0, import_react6.useEffect)(() => {
2275
+ if (!disabled || pointer.current === null) return;
2276
+ pointer.current = null;
2277
+ input.set(control.name, CENTRE);
2278
+ setActive(false);
2279
+ }, [disabled, input, control.name]);
2280
+ const marker = "pointer-events-none absolute size-0";
2281
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
2282
+ "div",
2283
+ {
2284
+ role: "application",
2285
+ "aria-label": "Joystick",
2286
+ ...props,
2287
+ "data-active": active,
2288
+ className: cn("relative touch-none select-none", className),
2289
+ onPointerDown: (event) => {
2290
+ if (disabled || pointer.current !== null || event.button !== 0) return;
2291
+ event.preventDefault();
2292
+ pointer.current = event.pointerId;
2293
+ capturePointer(event);
2294
+ setActiveState(true);
2295
+ follow(event);
2296
+ },
2297
+ onPointerMove: (event) => {
2298
+ if (event.pointerId === pointer.current) follow(event);
2299
+ },
2300
+ onPointerUp: end,
2301
+ onPointerCancel: end,
2302
+ onLostPointerCapture: end,
2303
+ onContextMenu: (event) => event.preventDefault(),
2304
+ children: [
2305
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { ref: origin, className: cn(marker, "top-0 left-0") }),
2306
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { ref: right, className: cn(marker, "top-0 left-full") }),
2307
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { ref: bottom, className: cn(marker, "top-full left-0") }),
2308
+ typeof children === "function" ? children({ value, active }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
2309
+ children,
2310
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2311
+ "span",
2312
+ {
2313
+ className: cn(
2314
+ "pointer-events-none absolute top-1/2 left-1/2 flex size-1/3 items-center justify-center rounded-full bg-current/30",
2315
+ !active && "transition-transform duration-150 ease-out",
2316
+ knobClassName
2317
+ ),
2318
+ style: {
2319
+ transform: `translate(calc(-50% + ${value.x * 100}%), calc(-50% + ${value.y * 100}%))`
2320
+ },
2321
+ children: knob
2322
+ }
2323
+ )
2324
+ ] })
2325
+ ]
2326
+ }
2327
+ );
2328
+ };
2329
+
2330
+ // src/components/gamepad-layout.tsx
2331
+ var import_jsx_runtime7 = require("react/jsx-runtime");
2332
+ var layoutStyle = {
2333
+ containerType: "size",
2334
+ "--airjam-thumb-size": "min(62cqh, 27cqw)",
2335
+ "--airjam-thumb-margin": "min(10cqh, 5cqw)"
2336
+ };
2337
+ var zoneStyle = {
2338
+ width: "calc(var(--airjam-thumb-size) + 2 * var(--airjam-thumb-margin))"
2339
+ };
2340
+ var slotStyle = {
2341
+ width: "var(--airjam-thumb-size)",
2342
+ height: "var(--airjam-thumb-size)"
2343
+ };
2344
+ var ThumbZone = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2345
+ "div",
2346
+ {
2347
+ className: "flex h-full flex-none items-center justify-center",
2348
+ style: zoneStyle,
2349
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "grid *:size-full", style: slotStyle, children })
2350
+ }
2351
+ );
2352
+ var GamepadLayout = ({
2353
+ left,
2354
+ right,
2355
+ center,
2356
+ className,
2357
+ style,
2358
+ ...props
2359
+ }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
2360
+ "div",
2361
+ {
2362
+ ...props,
2363
+ className: cn("flex h-full w-full items-center", className),
2364
+ style: { ...layoutStyle, ...style },
2365
+ children: [
2366
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ThumbZone, { children: left }),
2367
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "flex h-full min-w-0 flex-1 flex-col items-center justify-center gap-2 text-center", children: center }),
2368
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ThumbZone, { children: right })
2369
+ ]
2370
+ }
2371
+ );
2372
+
2373
+ // src/components/host-mute-button.tsx
2374
+ var import_lucide_react = require("lucide-react");
2375
+ var import_jsx_runtime8 = require("react/jsx-runtime");
2376
+ function HostMuteButton({
2377
+ muted,
2378
+ onToggle,
2379
+ className,
1077
2380
  labelClassName,
1078
2381
  mutedLabel = "Unmute",
1079
2382
  unmutedLabel = "Mute"
1080
2383
  }) {
1081
2384
  const label = muted ? mutedLabel : unmutedLabel;
1082
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
2385
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
1083
2386
  Button,
1084
2387
  {
1085
2388
  type: "button",
@@ -1094,8 +2397,8 @@ function HostMuteButton({
1094
2397
  className
1095
2398
  ),
1096
2399
  children: [
1097
- muted ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react.VolumeX, { className: "size-4" }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react.Volume2, { className: "size-4" }),
1098
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2400
+ muted ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react.VolumeX, { className: "size-4" }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react.Volume2, { className: "size-4" }),
2401
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1099
2402
  "span",
1100
2403
  {
1101
2404
  className: cn(
@@ -1111,13 +2414,13 @@ function HostMuteButton({
1111
2414
  }
1112
2415
 
1113
2416
  // src/components/join-qr-overlay.tsx
1114
- var import_react7 = require("react");
2417
+ var import_react8 = require("react");
1115
2418
  var import_react_dom = require("react-dom");
1116
2419
 
1117
2420
  // src/components/room-qr-code.tsx
1118
2421
  var import_qrcode = require("qrcode");
1119
- var import_react6 = require("react");
1120
- var import_jsx_runtime7 = require("react/jsx-runtime");
2422
+ var import_react7 = require("react");
2423
+ var import_jsx_runtime9 = require("react/jsx-runtime");
1121
2424
  var RoomQrCode = ({
1122
2425
  value,
1123
2426
  size = 180,
@@ -1130,58 +2433,24 @@ var RoomQrCode = ({
1130
2433
  alt = "Room join QR code"
1131
2434
  }) => {
1132
2435
  const trimmed = value.trim();
1133
- const qrKey = `${trimmed}\0${size}\0${padding}\0${foregroundColor}\0${backgroundColor}\0${errorCorrectionLevel}`;
1134
- const [qrState, setQrState] = (0, import_react6.useState)({
1135
- key: null,
1136
- dataUrl: null,
1137
- error: false
1138
- });
1139
- (0, import_react6.useEffect)(() => {
1140
- if (!trimmed) {
1141
- return;
1142
- }
1143
- let cancelled = false;
1144
- void (0, import_qrcode.toDataURL)(trimmed, {
1145
- width: size,
1146
- margin: padding,
1147
- errorCorrectionLevel,
1148
- color: {
1149
- dark: foregroundColor,
1150
- light: backgroundColor
1151
- }
1152
- }).then((nextUrl) => {
1153
- if (!cancelled) {
1154
- setQrState({
1155
- key: qrKey,
1156
- dataUrl: nextUrl,
1157
- error: false
1158
- });
1159
- }
1160
- }).catch(() => {
1161
- if (!cancelled) {
1162
- setQrState({
1163
- key: qrKey,
1164
- dataUrl: null,
1165
- error: true
1166
- });
2436
+ const qr = (0, import_react7.useMemo)(() => {
2437
+ if (!trimmed) return null;
2438
+ try {
2439
+ const { modules } = (0, import_qrcode.create)(trimmed, { errorCorrectionLevel });
2440
+ let path = "";
2441
+ for (let row = 0; row < modules.size; row += 1) {
2442
+ for (let column = 0; column < modules.size; column += 1) {
2443
+ if (modules.data[row * modules.size + column]) {
2444
+ path += `M${column},${row}h1v1h-1z`;
2445
+ }
2446
+ }
1167
2447
  }
1168
- });
1169
- return () => {
1170
- cancelled = true;
1171
- };
1172
- }, [
1173
- backgroundColor,
1174
- errorCorrectionLevel,
1175
- foregroundColor,
1176
- padding,
1177
- size,
1178
- qrKey,
1179
- trimmed
1180
- ]);
1181
- const imageSrc = trimmed && qrState.key === qrKey && qrState.dataUrl ? qrState.dataUrl : null;
1182
- const isLoading = !!trimmed && qrState.key !== qrKey;
1183
- const isUnavailable = !trimmed || qrState.key === qrKey && qrState.error;
1184
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2448
+ return { path, size: modules.size };
2449
+ } catch {
2450
+ return null;
2451
+ }
2452
+ }, [trimmed, errorCorrectionLevel]);
2453
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1185
2454
  "div",
1186
2455
  {
1187
2456
  className,
@@ -1192,19 +2461,31 @@ var RoomQrCode = ({
1192
2461
  },
1193
2462
  "aria-live": "polite",
1194
2463
  "aria-label": alt,
1195
- children: imageSrc ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1196
- "img",
2464
+ children: qr ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
2465
+ "svg",
1197
2466
  {
1198
- src: imageSrc,
1199
- alt,
2467
+ role: "img",
2468
+ "aria-label": alt,
1200
2469
  width: size,
1201
2470
  height: size,
1202
- className: "h-full w-full rounded-md object-cover"
2471
+ viewBox: `${-padding} ${-padding} ${qr.size + padding * 2} ${qr.size + padding * 2}`,
2472
+ shapeRendering: "crispEdges",
2473
+ className: "h-full w-full rounded-md",
2474
+ children: [
2475
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
2476
+ "rect",
2477
+ {
2478
+ x: -padding,
2479
+ y: -padding,
2480
+ width: qr.size + padding * 2,
2481
+ height: qr.size + padding * 2,
2482
+ fill: backgroundColor
2483
+ }
2484
+ ),
2485
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("path", { d: qr.path, fill: foregroundColor })
2486
+ ]
1203
2487
  }
1204
- ) : isLoading ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex h-full w-full flex-col items-center justify-center gap-2 rounded-md bg-black/15 text-xs text-white/70", children: [
1205
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "h-5 w-5 animate-spin rounded-full border-2 border-white/20 border-t-white/80" }),
1206
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: "Generating QR\u2026" })
1207
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "flex h-full w-full items-center justify-center rounded-md bg-black/15 text-xs text-white/70", children: isUnavailable ? "QR unavailable" : "Generating QR\u2026" })
2488
+ ) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "flex h-full w-full items-center justify-center rounded-md bg-black/15 text-xs text-white/70", children: "QR unavailable" })
1208
2489
  }
1209
2490
  );
1210
2491
  };
@@ -1217,7 +2498,7 @@ var shellFieldClassName = "h-11 min-w-0 w-full rounded-2xl border border-white/1
1217
2498
  var shellUtilityButtonClassName = "rounded-2xl border-white/12 bg-white/[0.045] text-white/88 shadow-[inset_0_1px_0_rgba(255,255,255,0.03)] hover:bg-white/[0.085] hover:text-white disabled:border-white/8 disabled:bg-white/[0.03] disabled:text-white/35";
1218
2499
 
1219
2500
  // src/components/join-qr-overlay.tsx
1220
- var import_jsx_runtime8 = require("react/jsx-runtime");
2501
+ var import_jsx_runtime10 = require("react/jsx-runtime");
1221
2502
  var JoinQrOverlay = ({
1222
2503
  open,
1223
2504
  value,
@@ -1243,8 +2524,8 @@ var JoinQrOverlay = ({
1243
2524
  const joinUrlValue = value?.trim() ?? "";
1244
2525
  const effectiveStatus = status === "ready" && joinUrlValue.length === 0 ? "unavailable" : status;
1245
2526
  const overlaySize = `min(72vw, ${size}px)`;
1246
- const [entered, setEntered] = (0, import_react7.useState)(false);
1247
- (0, import_react7.useEffect)(() => {
2527
+ const [entered, setEntered] = (0, import_react8.useState)(false);
2528
+ (0, import_react8.useEffect)(() => {
1248
2529
  if (!open || typeof window === "undefined") {
1249
2530
  return;
1250
2531
  }
@@ -1258,7 +2539,7 @@ var JoinQrOverlay = ({
1258
2539
  window.removeEventListener("keydown", handleKeyDown);
1259
2540
  };
1260
2541
  }, [onClose, open]);
1261
- (0, import_react7.useEffect)(() => {
2542
+ (0, import_react8.useEffect)(() => {
1262
2543
  if (!open || typeof window === "undefined") {
1263
2544
  setEntered(false);
1264
2545
  return;
@@ -1277,7 +2558,7 @@ var JoinQrOverlay = ({
1277
2558
  const handlePanelClick = (event) => {
1278
2559
  event.stopPropagation();
1279
2560
  };
1280
- const dialog = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2561
+ const dialog = /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1281
2562
  "div",
1282
2563
  {
1283
2564
  role: "dialog",
@@ -1289,7 +2570,7 @@ var JoinQrOverlay = ({
1289
2570
  className
1290
2571
  ),
1291
2572
  onClick: onClose,
1292
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
2573
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
1293
2574
  "div",
1294
2575
  {
1295
2576
  className: cn(
@@ -1299,11 +2580,11 @@ var JoinQrOverlay = ({
1299
2580
  ),
1300
2581
  onClick: handlePanelClick,
1301
2582
  children: [
1302
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "space-y-1", children: [
1303
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "text-[11px] tracking-[0.18em] text-slate-400 uppercase", children: roomLabel }),
1304
- roomId ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "text-2xl font-semibold tracking-tight text-white tabular-nums", children: roomId }) : null
2583
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "space-y-1", children: [
2584
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "text-[11px] tracking-[0.18em] text-slate-400 uppercase", children: roomLabel }),
2585
+ roomId ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "text-2xl font-semibold tracking-tight text-white tabular-nums", children: roomId }) : null
1305
2586
  ] }),
1306
- effectiveStatus === "loading" ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
2587
+ effectiveStatus === "loading" ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
1307
2588
  "div",
1308
2589
  {
1309
2590
  className: cn(
@@ -1316,11 +2597,11 @@ var JoinQrOverlay = ({
1316
2597
  aspectRatio: "1 / 1"
1317
2598
  },
1318
2599
  children: [
1319
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "h-8 w-8 animate-spin rounded-full border-2 border-white/15 border-t-white/85" }),
1320
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: loadingLabel })
2600
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "h-8 w-8 animate-spin rounded-full border-2 border-white/15 border-t-white/85" }),
2601
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: loadingLabel })
1321
2602
  ]
1322
2603
  }
1323
- ) : effectiveStatus === "ready" ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2604
+ ) : effectiveStatus === "ready" ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1324
2605
  RoomQrCode,
1325
2606
  {
1326
2607
  value: joinUrlValue,
@@ -1339,7 +2620,7 @@ var JoinQrOverlay = ({
1339
2620
  },
1340
2621
  alt: qrAlt ?? (roomId ? `QR code to join room ${roomId}` : "QR code to join as a controller")
1341
2622
  }
1342
- ) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2623
+ ) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1343
2624
  "div",
1344
2625
  {
1345
2626
  className: cn(
@@ -1354,7 +2635,7 @@ var JoinQrOverlay = ({
1354
2635
  children: unavailableLabel
1355
2636
  }
1356
2637
  ),
1357
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2638
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1358
2639
  "p",
1359
2640
  {
1360
2641
  className: cn(
@@ -1364,7 +2645,7 @@ var JoinQrOverlay = ({
1364
2645
  children: description
1365
2646
  }
1366
2647
  ),
1367
- showCloseButton ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2648
+ showCloseButton ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1368
2649
  Button,
1369
2650
  {
1370
2651
  type: "button",
@@ -1391,7 +2672,7 @@ var JoinQrOverlay = ({
1391
2672
 
1392
2673
  // src/components/join-url-action-buttons.tsx
1393
2674
  var import_lucide_react2 = require("lucide-react");
1394
- var import_jsx_runtime9 = require("react/jsx-runtime");
2675
+ var import_jsx_runtime11 = require("react/jsx-runtime");
1395
2676
  var JoinUrlActionButtons = ({
1396
2677
  hasValue,
1397
2678
  copied = false,
@@ -1403,7 +2684,7 @@ var JoinUrlActionButtons = ({
1403
2684
  buttonClassName
1404
2685
  }) => {
1405
2686
  const showsQrButton = typeof onToggleQr === "function";
1406
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
2687
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
1407
2688
  "div",
1408
2689
  {
1409
2690
  className: cn(
@@ -1412,7 +2693,7 @@ var JoinUrlActionButtons = ({
1412
2693
  className
1413
2694
  ),
1414
2695
  children: [
1415
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
2696
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
1416
2697
  Button,
1417
2698
  {
1418
2699
  type: "button",
@@ -1427,12 +2708,12 @@ var JoinUrlActionButtons = ({
1427
2708
  buttonClassName
1428
2709
  ),
1429
2710
  children: [
1430
- copied ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react2.Check, { className: "h-4 w-4", "aria-hidden": true }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react2.Copy, { className: "h-4 w-4", "aria-hidden": true }),
1431
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "truncate", children: copied ? "Copied" : "Copy" })
2711
+ copied ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.Check, { className: "h-4 w-4", "aria-hidden": true }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.Copy, { className: "h-4 w-4", "aria-hidden": true }),
2712
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "truncate", children: copied ? "Copied" : "Copy" })
1432
2713
  ]
1433
2714
  }
1434
2715
  ),
1435
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
2716
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
1436
2717
  Button,
1437
2718
  {
1438
2719
  type: "button",
@@ -1447,12 +2728,12 @@ var JoinUrlActionButtons = ({
1447
2728
  buttonClassName
1448
2729
  ),
1449
2730
  children: [
1450
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react2.ExternalLink, { className: "h-4 w-4", "aria-hidden": true }),
1451
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "truncate", children: "New tab" })
2731
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.ExternalLink, { className: "h-4 w-4", "aria-hidden": true }),
2732
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "truncate", children: "New tab" })
1452
2733
  ]
1453
2734
  }
1454
2735
  ),
1455
- showsQrButton ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
2736
+ showsQrButton ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
1456
2737
  Button,
1457
2738
  {
1458
2739
  type: "button",
@@ -1468,8 +2749,8 @@ var JoinUrlActionButtons = ({
1468
2749
  buttonClassName
1469
2750
  ),
1470
2751
  children: [
1471
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react2.QrCode, { className: "h-4 w-4", "aria-hidden": true }),
1472
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "truncate", children: qrVisible ? "Hide QR" : "QR code" })
2752
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.QrCode, { className: "h-4 w-4", "aria-hidden": true }),
2753
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "truncate", children: qrVisible ? "Hide QR" : "QR code" })
1473
2754
  ]
1474
2755
  }
1475
2756
  ) : null
@@ -1478,9 +2759,128 @@ var JoinUrlActionButtons = ({
1478
2759
  );
1479
2760
  };
1480
2761
 
2762
+ // src/runtime/controller-bridge-context.ts
2763
+ var import_zod26 = require("zod");
2764
+
2765
+ // src/runtime/arcade-surface-identity.ts
2766
+ var import_zod25 = require("zod");
2767
+ var arcadeSurfaceRuntimeIdentitySchema = import_zod25.z.object({
2768
+ epoch: import_zod25.z.number().int().nonnegative(),
2769
+ kind: import_zod25.z.enum(["browser", "game"]),
2770
+ gameId: import_zod25.z.string().nullable()
2771
+ }).strict();
2772
+
2773
+ // src/runtime/controller-bridge-context.ts
2774
+ var controllerBridgeContextSchema = import_zod26.z.union([
2775
+ import_zod26.z.object({ arcadeSurface: arcadeSurfaceRuntimeIdentitySchema }).strict(),
2776
+ import_zod26.z.object({ harnessSessionId: import_zod26.z.uuid() }).strict()
2777
+ ]);
2778
+ function controllerBridgeContext(context) {
2779
+ return "arcadeSurface" in context ? { arcadeSurface: context.arcadeSurface } : { harnessSessionId: context.harnessSessionId };
2780
+ }
2781
+ function withControllerBridgeContext(shape) {
2782
+ return import_zod26.z.union([
2783
+ import_zod26.z.object({ ...shape, arcadeSurface: arcadeSurfaceRuntimeIdentitySchema }).strict(),
2784
+ import_zod26.z.object({ ...shape, harnessSessionId: import_zod26.z.uuid() }).strict()
2785
+ ]);
2786
+ }
2787
+
2788
+ // src/runtime/arcade-runtime-url.ts
2789
+ var parseOptionalArcadeSurfaceFromSearchParams = (params) => {
2790
+ const epochStr = params.get("aj_arcade_epoch");
2791
+ const kind = params.get("aj_arcade_kind");
2792
+ if (epochStr === null || kind !== "browser" && kind !== "game") {
2793
+ return void 0;
2794
+ }
2795
+ const epoch = Number(epochStr);
2796
+ if (!Number.isFinite(epoch) || epoch < 0 || !Number.isInteger(epoch)) {
2797
+ return void 0;
2798
+ }
2799
+ const gameIdRaw = params.get("aj_arcade_game_id");
2800
+ const gameId = kind === "browser" ? null : gameIdRaw && gameIdRaw.length > 0 ? gameIdRaw : null;
2801
+ return { epoch, kind, gameId };
2802
+ };
2803
+
2804
+ // src/runtime/runtime-session-params.ts
2805
+ var readChildHostRuntimeParams = () => {
2806
+ if (typeof window === "undefined") {
2807
+ return null;
2808
+ }
2809
+ const params = new URLSearchParams(window.location.search);
2810
+ const room = params.get("aj_room");
2811
+ if (!room) {
2812
+ return null;
2813
+ }
2814
+ const joinUrl = params.get("aj_join_url");
2815
+ const normalizedJoinUrl = joinUrl ? normalizeRuntimeUrl(joinUrl) : null;
2816
+ const topology = parseRuntimeTopologyFromSearchParams(params);
2817
+ if (!topology) {
2818
+ return null;
2819
+ }
2820
+ const arcadeSurface = parseOptionalArcadeSurfaceFromSearchParams(params);
2821
+ if (!arcadeSurface) {
2822
+ return null;
2823
+ }
2824
+ return {
2825
+ room,
2826
+ joinUrl: normalizedJoinUrl ?? void 0,
2827
+ topology,
2828
+ arcadeSurface
2829
+ };
2830
+ };
2831
+ var readEmbeddedControllerRuntimeParams = () => {
2832
+ if (typeof window === "undefined") {
2833
+ return null;
2834
+ }
2835
+ const params = new URLSearchParams(window.location.search);
2836
+ const room = params.get("aj_room");
2837
+ if (!room) {
2838
+ return null;
2839
+ }
2840
+ const topology = parseRuntimeTopologyFromSearchParams(params);
2841
+ if (!topology) {
2842
+ return null;
2843
+ }
2844
+ const harnessContext = params.has("aj_harness_session") ? controllerBridgeContextSchema.parse({
2845
+ harnessSessionId: params.get("aj_harness_session")
2846
+ }) : null;
2847
+ const context = controllerBridgeContextSchema.safeParse(
2848
+ harnessContext ? harnessContext : { arcadeSurface: parseOptionalArcadeSurfaceFromSearchParams(params) }
2849
+ );
2850
+ if (!context.success) {
2851
+ return null;
2852
+ }
2853
+ const rawLabel = params.get("aj_player_label")?.trim();
2854
+ const rawAvatarId = params.get("aj_player_avatar")?.trim();
2855
+ const playerProfile = rawLabel || rawAvatarId ? {
2856
+ ...rawLabel ? { label: rawLabel } : {},
2857
+ ...rawAvatarId ? { avatarId: rawAvatarId } : {}
2858
+ } : void 0;
2859
+ return {
2860
+ room,
2861
+ topology,
2862
+ ...context.data,
2863
+ ...playerProfile ? { playerProfile } : {}
2864
+ };
2865
+ };
2866
+
2867
+ // src/runtime/embedded-runtime-adapters.ts
2868
+ var readEmbeddedHostChildSession = () => {
2869
+ const raw = readChildHostRuntimeParams();
2870
+ if (!raw) {
2871
+ return null;
2872
+ }
2873
+ return {
2874
+ roomId: roomCodeSchema.parse(raw.room.toUpperCase()),
2875
+ joinUrl: raw.joinUrl,
2876
+ topology: raw.topology,
2877
+ arcadeSurface: raw.arcadeSurface
2878
+ };
2879
+ };
2880
+
1481
2881
  // src/components/join-url-field.tsx
1482
- var import_react8 = require("react");
1483
- var import_jsx_runtime10 = require("react/jsx-runtime");
2882
+ var import_react9 = require("react");
2883
+ var import_jsx_runtime12 = require("react/jsx-runtime");
1484
2884
  var JoinUrlField = ({
1485
2885
  value,
1486
2886
  label = "Controller link",
@@ -1491,11 +2891,11 @@ var JoinUrlField = ({
1491
2891
  inputName = "airjam-controller-link"
1492
2892
  }) => {
1493
2893
  const hasValue = Boolean(value && value.trim().length > 0);
1494
- const generatedInputId = (0, import_react8.useId)();
2894
+ const generatedInputId = (0, import_react9.useId)();
1495
2895
  const resolvedInputId = inputId ?? generatedInputId;
1496
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: cn("space-y-2.5", className), children: [
1497
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("label", { className: shellLabelClassName, htmlFor: resolvedInputId, children: label }),
1498
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
2896
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: cn("space-y-2.5", className), children: [
2897
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("label", { className: shellLabelClassName, htmlFor: resolvedInputId, children: label }),
2898
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1499
2899
  "input",
1500
2900
  {
1501
2901
  id: resolvedInputId,
@@ -1508,12 +2908,12 @@ var JoinUrlField = ({
1508
2908
  className: cn(shellFieldClassName, inputClassName)
1509
2909
  }
1510
2910
  ),
1511
- helperText ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: shellHelperTextClassName, children: helperText }) : null
2911
+ helperText ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: shellHelperTextClassName, children: helperText }) : null
1512
2912
  ] });
1513
2913
  };
1514
2914
 
1515
2915
  // src/components/join-url-controls.tsx
1516
- var import_jsx_runtime11 = require("react/jsx-runtime");
2916
+ var import_jsx_runtime13 = require("react/jsx-runtime");
1517
2917
  var JoinUrlControls = ({
1518
2918
  value,
1519
2919
  label = "Controller link",
@@ -1527,9 +2927,10 @@ var JoinUrlControls = ({
1527
2927
  inputClassName,
1528
2928
  buttonClassName
1529
2929
  }) => {
2930
+ if (readEmbeddedHostChildSession()) return null;
1530
2931
  const hasValue = Boolean(value && value.trim().length > 0);
1531
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: cn("w-full space-y-3", className), children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "flex flex-col gap-3", children: [
1532
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2932
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: cn("w-full space-y-3", className), children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "flex flex-col gap-3", children: [
2933
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1533
2934
  JoinUrlField,
1534
2935
  {
1535
2936
  value,
@@ -1539,7 +2940,7 @@ var JoinUrlControls = ({
1539
2940
  inputClassName
1540
2941
  }
1541
2942
  ),
1542
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2943
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1543
2944
  JoinUrlActionButtons,
1544
2945
  {
1545
2946
  hasValue,
@@ -1615,7 +3016,7 @@ var useLifecycleActionGroupModel = ({
1615
3016
  };
1616
3017
 
1617
3018
  // src/components/lifecycle-action-group.tsx
1618
- var import_jsx_runtime12 = require("react/jsx-runtime");
3019
+ var import_jsx_runtime14 = require("react/jsx-runtime");
1619
3020
  var LifecycleActionGroup = ({
1620
3021
  phase,
1621
3022
  runtimeState,
@@ -1651,23 +3052,23 @@ var LifecycleActionGroup = ({
1651
3052
  const renderIcon = (kind, label) => {
1652
3053
  switch (kind) {
1653
3054
  case "start":
1654
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_lucide_react3.Play, { "aria-hidden": true, className: "size-4.5" });
3055
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_lucide_react3.Play, { "aria-hidden": true, className: "size-4.5" });
1655
3056
  case "pause-toggle":
1656
- return label.toLowerCase() === "resume" ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_lucide_react3.Play, { "aria-hidden": true, className: "size-4.5" }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_lucide_react3.Pause, { "aria-hidden": true, className: "size-4.5" });
3057
+ return label.toLowerCase() === "resume" ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_lucide_react3.Play, { "aria-hidden": true, className: "size-4.5" }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_lucide_react3.Pause, { "aria-hidden": true, className: "size-4.5" });
1657
3058
  case "restart":
1658
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_lucide_react3.RotateCcw, { "aria-hidden": true, className: "size-4.5" });
3059
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_lucide_react3.RotateCcw, { "aria-hidden": true, className: "size-4.5" });
1659
3060
  case "back-to-lobby":
1660
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_lucide_react3.House, { "aria-hidden": true, className: "size-4.5" });
3061
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_lucide_react3.House, { "aria-hidden": true, className: "size-4.5" });
1661
3062
  }
1662
3063
  };
1663
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3064
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1664
3065
  "div",
1665
3066
  {
1666
3067
  className: cn(
1667
3068
  "flex min-w-0 flex-nowrap items-center justify-end gap-1.5 overflow-x-auto",
1668
3069
  className
1669
3070
  ),
1670
- children: actions.map((action) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3071
+ children: actions.map((action) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1671
3072
  Button,
1672
3073
  {
1673
3074
  type: "button",
@@ -1691,6 +3092,7 @@ var LifecycleActionGroup = ({
1691
3092
 
1692
3093
  // src/components/player-avatar.tsx
1693
3094
  var import_lucide_react4 = require("lucide-react");
3095
+ var import_react10 = require("react");
1694
3096
 
1695
3097
  // src/utils/player-avatar-url.ts
1696
3098
  var DIEBEAR_ADVENTURER_NEUTRAL_SVG_BASE = "https://api.dicebear.com/9.x/adventurer-neutral/svg";
@@ -1722,7 +3124,7 @@ var getDiceBearAdventurerNeutralUrl = (seed) => `${DIEBEAR_ADVENTURER_NEUTRAL_SV
1722
3124
  var getPlayerAvatarImageUrl = (player) => getDiceBearAdventurerNeutralUrl(resolvePlayerAvatarSeed(player));
1723
3125
 
1724
3126
  // src/components/player-avatar.tsx
1725
- var import_jsx_runtime13 = require("react/jsx-runtime");
3127
+ var import_jsx_runtime15 = require("react/jsx-runtime");
1726
3128
  var hexToRgba = (hex, opacity) => {
1727
3129
  const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
1728
3130
  if (!result) return `rgba(0, 0, 0, ${opacity})`;
@@ -1737,6 +3139,7 @@ var PlayerAvatar = ({
1737
3139
  size = "md",
1738
3140
  className = ""
1739
3141
  }) => {
3142
+ const [failedSrc, setFailedSrc] = (0, import_react10.useState)(null);
1740
3143
  const accentColor = player.color || "hsl(var(--border))";
1741
3144
  const sizeClasses = {
1742
3145
  sm: "h-9 w-9 border-2",
@@ -1759,7 +3162,7 @@ var PlayerAvatar = ({
1759
3162
  className
1760
3163
  );
1761
3164
  if (isBot) {
1762
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
3165
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1763
3166
  "div",
1764
3167
  {
1765
3168
  role: "img",
@@ -1773,479 +3176,147 @@ var PlayerAvatar = ({
1773
3176
  color: accentColor,
1774
3177
  boxShadow: shadowStyles[size]
1775
3178
  },
1776
- children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_lucide_react4.Bot, { "aria-hidden": "true", className: iconSizeClasses[size] })
3179
+ children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_lucide_react4.Bot, { "aria-hidden": "true", className: iconSizeClasses[size] })
1777
3180
  }
1778
3181
  );
1779
3182
  }
1780
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1781
- "img",
1782
- {
1783
- src: getPlayerAvatarImageUrl(player),
1784
- alt: player.label,
1785
- className: cn("bg-secondary/30", shellClassName),
1786
- style: {
1787
- borderColor: accentColor,
1788
- boxShadow: shadowStyles[size]
1789
- }
1790
- }
1791
- );
1792
- };
1793
-
1794
- // src/components/player-avatar-strip.tsx
1795
- var import_jsx_runtime14 = require("react/jsx-runtime");
1796
- var overflowSizeClasses = {
1797
- sm: "h-9 w-9 min-h-9 min-w-9 text-[0.625rem]",
1798
- md: "h-12 w-12 min-h-12 min-w-12 text-[11px]",
1799
- lg: "h-16 w-16 min-h-16 min-w-16 text-xs"
1800
- };
1801
- var PlayerAvatarStrip = ({
1802
- players,
1803
- maxVisible = 4,
1804
- size = "sm",
1805
- className,
1806
- avatarClassName = "",
1807
- overflowBadgeClassName = ""
1808
- }) => {
1809
- const visible = players.slice(0, maxVisible);
1810
- const overflow = Math.max(0, players.length - maxVisible);
1811
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: cn("flex items-center -space-x-2", className), children: [
1812
- visible.map((player) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1813
- PlayerAvatar,
1814
- {
1815
- player,
1816
- size,
1817
- className: avatarClassName
1818
- },
1819
- player.id
1820
- )),
1821
- overflow > 0 && /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
3183
+ const src = getPlayerAvatarImageUrl(player);
3184
+ if (failedSrc === src) {
3185
+ const initials = playerInitials(player.label);
3186
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1822
3187
  "div",
1823
3188
  {
1824
- className: cn(
1825
- "bg-secondary/50 text-foreground flex shrink-0 items-center justify-center rounded-full border-2 border-[hsl(var(--border))] font-semibold tabular-nums shadow-sm",
1826
- overflowSizeClasses[size],
1827
- overflowBadgeClassName
1828
- ),
1829
- "aria-label": `${overflow} more players`,
1830
- children: [
1831
- "+",
1832
- overflow
1833
- ]
1834
- }
1835
- )
1836
- ] });
1837
- };
1838
-
1839
- // src/components/runtime-shell-header.tsx
1840
- var import_jsx_runtime15 = require("react/jsx-runtime");
1841
- var RuntimeShellHeader = ({
1842
- connectionStatus,
1843
- leftSlot,
1844
- rightSlot,
1845
- className
1846
- }) => {
1847
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
1848
- "header",
1849
- {
1850
- className: cn(
1851
- "flex min-h-16 items-center gap-2.5 px-3 py-2.5 sm:px-4",
1852
- shellHeaderClassName,
1853
- className
1854
- ),
1855
- children: [
1856
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "min-w-0 flex-1", children: leftSlot }),
1857
- /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "flex shrink-0 items-center gap-2.5", children: [
1858
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ConnectionStatusPill, { status: connectionStatus }),
1859
- rightSlot ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "flex items-center justify-end", children: rightSlot }) : null
1860
- ] })
1861
- ]
1862
- }
1863
- );
1864
- };
1865
-
1866
- // src/components/surface-viewport.tsx
1867
- var import_react9 = require("react");
1868
-
1869
- // src/runtime/controller-bridge.ts
1870
- var import_zod13 = require("zod");
1871
-
1872
- // src/contracts/v2/bridge.ts
1873
- var import_zod9 = require("zod");
1874
- var roomCodeSchema2 = import_zod9.z.string().trim().min(4).max(8).regex(/^[A-Z0-9]+$/, {
1875
- message: "room code must contain only A-Z or 0-9"
1876
- });
1877
- var runtimeStateSchema = import_zod9.z.enum(["paused", "playing"]);
1878
- var playerProfileSchema = import_zod9.z.object({
1879
- id: import_zod9.z.string().min(1),
1880
- label: import_zod9.z.string().min(1),
1881
- color: import_zod9.z.string().optional(),
1882
- avatarId: import_zod9.z.string().optional()
1883
- }).strict();
1884
- var inputFrameEntrySchema = import_zod9.z.object({
1885
- controllerId: import_zod9.z.string().min(1),
1886
- input: import_zod9.z.record(import_zod9.z.string(), import_zod9.z.unknown())
1887
- }).strict();
1888
- var V2_BRIDGE_PARENT_TO_GAME_TYPES = [
1889
- "BOOTSTRAP",
1890
- "PLAYERS_UPDATE",
1891
- "RUNTIME_STATE_UPDATE",
1892
- "INPUT_FRAME",
1893
- "PAUSE",
1894
- "RESUME",
1895
- "SHUTDOWN"
1896
- ];
1897
- var V2_BRIDGE_GAME_TO_PARENT_TYPES = [
1898
- "READY",
1899
- "STATE_PATCH",
1900
- "SIGNAL",
1901
- "ERROR",
1902
- "METRICS"
1903
- ];
1904
- var allMessageTypes = [
1905
- ...V2_BRIDGE_PARENT_TO_GAME_TYPES,
1906
- ...V2_BRIDGE_GAME_TO_PARENT_TYPES
1907
- ];
1908
- var knownBridgeMessageTypeSet = new Set(allMessageTypes);
1909
- var bootstrapMessageSchema = import_zod9.z.object({
1910
- type: import_zod9.z.literal("BOOTSTRAP"),
1911
- payload: import_zod9.z.object({
1912
- roomId: roomCodeSchema2,
1913
- players: import_zod9.z.array(playerProfileSchema),
1914
- state: import_zod9.z.object({
1915
- runtimeState: runtimeStateSchema,
1916
- message: import_zod9.z.string().optional()
1917
- }).strict(),
1918
- capabilities: import_zod9.z.record(import_zod9.z.string(), import_zod9.z.boolean()).default({})
1919
- }).strict()
1920
- }).strict();
1921
- var playersUpdateMessageSchema = import_zod9.z.object({
1922
- type: import_zod9.z.literal("PLAYERS_UPDATE"),
1923
- payload: import_zod9.z.object({
1924
- players: import_zod9.z.array(playerProfileSchema)
1925
- }).strict()
1926
- }).strict();
1927
- var runtimeStateUpdateMessageSchema = import_zod9.z.object({
1928
- type: import_zod9.z.literal("RUNTIME_STATE_UPDATE"),
1929
- payload: import_zod9.z.object({
1930
- runtimeState: runtimeStateSchema,
1931
- message: import_zod9.z.string().optional()
1932
- }).strict()
1933
- }).strict();
1934
- var inputFrameMessageSchema = import_zod9.z.object({
1935
- type: import_zod9.z.literal("INPUT_FRAME"),
1936
- payload: import_zod9.z.object({
1937
- frameId: import_zod9.z.number().int().nonnegative(),
1938
- inputs: import_zod9.z.array(inputFrameEntrySchema)
1939
- }).strict()
1940
- }).strict();
1941
- var pauseMessageSchema = import_zod9.z.object({
1942
- type: import_zod9.z.literal("PAUSE"),
1943
- payload: import_zod9.z.object({
1944
- reason: import_zod9.z.string().optional()
1945
- }).strict()
1946
- }).strict();
1947
- var resumeMessageSchema = import_zod9.z.object({
1948
- type: import_zod9.z.literal("RESUME"),
1949
- payload: import_zod9.z.object({}).strict()
1950
- }).strict();
1951
- var shutdownMessageSchema = import_zod9.z.object({
1952
- type: import_zod9.z.literal("SHUTDOWN"),
1953
- payload: import_zod9.z.object({
1954
- reason: import_zod9.z.string().min(1)
1955
- }).strict()
1956
- }).strict();
1957
- var readyMessageSchema = import_zod9.z.object({
1958
- type: import_zod9.z.literal("READY"),
1959
- payload: import_zod9.z.object({
1960
- readyAtMs: import_zod9.z.number().int().nonnegative()
1961
- }).strict()
1962
- }).strict();
1963
- var statePatchMessageSchema = import_zod9.z.object({
1964
- type: import_zod9.z.literal("STATE_PATCH"),
1965
- payload: import_zod9.z.object({
1966
- patch: import_zod9.z.record(import_zod9.z.string(), import_zod9.z.unknown())
1967
- }).strict()
1968
- }).strict();
1969
- var signalMessageSchema = import_zod9.z.object({
1970
- type: import_zod9.z.literal("SIGNAL"),
1971
- payload: import_zod9.z.object({
1972
- signalType: import_zod9.z.string().min(1),
1973
- targetId: import_zod9.z.string().min(1).optional(),
1974
- data: import_zod9.z.record(import_zod9.z.string(), import_zod9.z.unknown())
1975
- }).strict()
1976
- }).strict();
1977
- var errorMessageSchema = import_zod9.z.object({
1978
- type: import_zod9.z.literal("ERROR"),
1979
- payload: import_zod9.z.object({
1980
- code: import_zod9.z.string().min(1),
1981
- message: import_zod9.z.string().min(1),
1982
- details: import_zod9.z.record(import_zod9.z.string(), import_zod9.z.unknown()).optional()
1983
- }).strict()
1984
- }).strict();
1985
- var metricsMessageSchema = import_zod9.z.object({
1986
- type: import_zod9.z.literal("METRICS"),
1987
- payload: import_zod9.z.object({
1988
- values: import_zod9.z.record(import_zod9.z.string(), import_zod9.z.number())
1989
- }).strict()
1990
- }).strict();
1991
- var v2BridgeParentToGameMessageSchema = import_zod9.z.union([
1992
- bootstrapMessageSchema,
1993
- playersUpdateMessageSchema,
1994
- runtimeStateUpdateMessageSchema,
1995
- inputFrameMessageSchema,
1996
- pauseMessageSchema,
1997
- resumeMessageSchema,
1998
- shutdownMessageSchema
1999
- ]);
2000
- var v2BridgeGameToParentMessageSchema = import_zod9.z.union([
2001
- readyMessageSchema,
2002
- statePatchMessageSchema,
2003
- signalMessageSchema,
2004
- errorMessageSchema,
2005
- metricsMessageSchema
2006
- ]);
2007
- var v2BridgeMessageSchema = import_zod9.z.union([
2008
- v2BridgeParentToGameMessageSchema,
2009
- v2BridgeGameToParentMessageSchema
2010
- ]);
2011
-
2012
- // src/contracts/v2/handshake.ts
2013
- var import_zod10 = require("zod");
2014
- var AIR_JAM_PROTOCOL_V2 = "2";
2015
- var semanticVersionPattern = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
2016
- var v2ProtocolVersionSchema = import_zod10.z.literal(AIR_JAM_PROTOCOL_V2);
2017
- var runtimeKindSchema = import_zod10.z.enum([
2018
- "standalone-host",
2019
- "standalone-controller",
2020
- "arcade-runtime",
2021
- "arcade-game-iframe",
2022
- "arcade-host-runtime",
2023
- "arcade-host-iframe",
2024
- "arcade-controller-runtime",
2025
- "arcade-controller-iframe"
2026
- ]);
2027
- var capabilityFlagsSchema = import_zod10.z.record(import_zod10.z.string(), import_zod10.z.boolean());
2028
- var sdkVersionSchema = import_zod10.z.string().regex(
2029
- semanticVersionPattern,
2030
- "sdkVersion must use semantic version format (for example 1.2.3)"
2031
- );
2032
- var v2HandshakeSchema = import_zod10.z.object({
2033
- protocolVersion: v2ProtocolVersionSchema,
2034
- sdkVersion: sdkVersionSchema,
2035
- runtimeKind: runtimeKindSchema,
2036
- capabilityFlags: capabilityFlagsSchema.default({})
2037
- }).strict();
2038
-
2039
- // src/runtime/arcade-surface-identity.ts
2040
- var import_zod11 = require("zod");
2041
- var arcadeSurfaceRuntimeIdentitySchema = import_zod11.z.object({
2042
- epoch: import_zod11.z.number().int().nonnegative(),
2043
- kind: import_zod11.z.enum(["browser", "game"]),
2044
- gameId: import_zod11.z.string().nullable()
2045
- }).strict();
2046
-
2047
- // src/runtime/iframe-bridge.ts
2048
- var import_zod12 = require("zod");
2049
- var AIRJAM_BRIDGE_INIT = "AIRJAM_BRIDGE_INIT";
2050
- var AIRJAM_SETTINGS_SYNC = "AIRJAM_SETTINGS_SYNC";
2051
- var AIRJAM_SETTINGS_READY = "AIRJAM_SETTINGS_READY";
2052
- var airJamSettingsSyncSchema = import_zod12.z.object({
2053
- type: import_zod12.z.literal(AIRJAM_SETTINGS_SYNC),
2054
- payload: import_zod12.z.object({
2055
- settings: import_zod12.z.object({
2056
- audio: import_zod12.z.object({
2057
- masterVolume: import_zod12.z.number(),
2058
- musicVolume: import_zod12.z.number(),
2059
- sfxVolume: import_zod12.z.number()
2060
- }).strict(),
2061
- accessibility: import_zod12.z.object({
2062
- reducedMotion: import_zod12.z.boolean(),
2063
- highContrast: import_zod12.z.boolean()
2064
- }).strict(),
2065
- feedback: import_zod12.z.object({
2066
- hapticsEnabled: import_zod12.z.boolean()
2067
- }).strict(),
2068
- previewControllers: import_zod12.z.object({
2069
- activeOpacity: import_zod12.z.number()
2070
- }).strict()
2071
- }).strict()
2072
- }).strict()
2073
- }).strict();
2074
- var airJamBridgeInitSchema = import_zod12.z.object({
2075
- type: import_zod12.z.literal(AIRJAM_BRIDGE_INIT),
2076
- payload: import_zod12.z.object({
2077
- handshake: v2HandshakeSchema
2078
- }).strict()
2079
- }).strict();
2080
- var airJamSettingsReadySchema = import_zod12.z.object({
2081
- type: import_zod12.z.literal(AIRJAM_SETTINGS_READY),
2082
- payload: import_zod12.z.object({
2083
- ready: import_zod12.z.literal(true)
2084
- }).strict()
2085
- }).strict();
2086
-
2087
- // src/runtime/controller-bridge.ts
2088
- var AIRJAM_CONTROLLER_BRIDGE_REQUEST = "AIRJAM_CONTROLLER_BRIDGE_REQUEST";
2089
- var AIRJAM_CONTROLLER_BRIDGE_ATTACH = "AIRJAM_CONTROLLER_BRIDGE_ATTACH";
2090
- var AIRJAM_CONTROLLER_BRIDGE_EVENT = "AIRJAM_CONTROLLER_BRIDGE_EVENT";
2091
- var AIRJAM_CONTROLLER_BRIDGE_EMIT = "AIRJAM_CONTROLLER_BRIDGE_EMIT";
2092
- var AIRJAM_CONTROLLER_BRIDGE_CLOSE = "AIRJAM_CONTROLLER_BRIDGE_CLOSE";
2093
- var AIRJAM_CONTROLLER_PRESENTATION_SYNC = "AIRJAM_CONTROLLER_PRESENTATION_SYNC";
2094
- var AIRJAM_CONTROLLER_BRIDGE_RESPONSE = "AIRJAM_CONTROLLER_BRIDGE_RESPONSE";
2095
- var controllerBridgeClientEvents = [
2096
- "controller:input",
2097
- "controller:action_rpc",
2098
- "controller:state_sync_request",
2099
- "controller:system",
2100
- "controller:play_sound",
2101
- "controller:updatePlayerProfile"
2102
- ];
2103
- var controllerBridgeServerEvents = [
2104
- "connect",
2105
- "disconnect",
2106
- "server:welcome",
2107
- "server:controllerJoined",
2108
- "server:controllerLeft",
2109
- "server:state",
2110
- "server:hostLeft",
2111
- "server:error",
2112
- "server:signal",
2113
- "server:playSound",
2114
- "server:playerUpdated",
2115
- "airjam:state_sync"
2116
- ];
2117
- var bridgeRequestSchema = import_zod13.z.object({
2118
- type: import_zod13.z.literal(AIRJAM_CONTROLLER_BRIDGE_REQUEST),
2119
- payload: import_zod13.z.object({
2120
- handshake: v2HandshakeSchema,
2121
- roomId: import_zod13.z.string().min(1),
2122
- controllerId: import_zod13.z.string().min(1),
2123
- arcadeSurface: arcadeSurfaceRuntimeIdentitySchema
2124
- }).strict()
2125
- }).strict();
2126
- var bridgeAttachSchema = import_zod13.z.object({
2127
- type: import_zod13.z.literal(AIRJAM_CONTROLLER_BRIDGE_ATTACH),
2128
- payload: import_zod13.z.object({
2129
- handshake: v2HandshakeSchema,
2130
- snapshot: import_zod13.z.object({
2131
- roomId: import_zod13.z.string().min(1),
2132
- controllerId: import_zod13.z.string().min(1),
2133
- connected: import_zod13.z.boolean(),
2134
- socketId: import_zod13.z.string().optional(),
2135
- player: import_zod13.z.unknown().optional(),
2136
- players: import_zod13.z.array(import_zod13.z.unknown()).optional(),
2137
- state: import_zod13.z.unknown().optional(),
2138
- arcadeSurface: arcadeSurfaceRuntimeIdentitySchema
2139
- }).strict()
2140
- }).strict()
2141
- }).strict();
2142
- var bridgeEventSchema = import_zod13.z.object({
2143
- type: import_zod13.z.literal(AIRJAM_CONTROLLER_BRIDGE_EVENT),
2144
- payload: import_zod13.z.object({
2145
- event: import_zod13.z.enum(controllerBridgeServerEvents),
2146
- args: import_zod13.z.array(import_zod13.z.unknown()),
2147
- requestId: import_zod13.z.string().min(1).optional()
2148
- }).strict()
2149
- }).strict();
2150
- var bridgeEmitSchema = import_zod13.z.object({
2151
- type: import_zod13.z.literal(AIRJAM_CONTROLLER_BRIDGE_EMIT),
2152
- payload: import_zod13.z.object({
2153
- event: import_zod13.z.enum(controllerBridgeClientEvents),
2154
- args: import_zod13.z.array(import_zod13.z.unknown()),
2155
- requestId: import_zod13.z.string().min(1).optional()
2156
- }).strict()
2157
- }).strict();
2158
- var bridgeResponseSchema = import_zod13.z.object({
2159
- type: import_zod13.z.literal(AIRJAM_CONTROLLER_BRIDGE_RESPONSE),
2160
- payload: import_zod13.z.object({
2161
- requestId: import_zod13.z.string().min(1),
2162
- ack: import_zod13.z.unknown()
2163
- }).strict()
2164
- }).strict();
2165
- var bridgeCloseSchema = import_zod13.z.object({
2166
- type: import_zod13.z.literal(AIRJAM_CONTROLLER_BRIDGE_CLOSE),
2167
- payload: import_zod13.z.object({
2168
- reason: import_zod13.z.string().optional()
2169
- }).strict()
2170
- }).strict();
2171
- var presentationSyncSchema = import_zod13.z.object({
2172
- type: import_zod13.z.literal(AIRJAM_CONTROLLER_PRESENTATION_SYNC),
2173
- payload: import_zod13.z.object({
2174
- orientation: controllerOrientationSchema,
2175
- arcadeSurface: arcadeSurfaceRuntimeIdentitySchema
2176
- }).strict()
2177
- }).strict();
2178
- var createControllerPresentationSyncMessage = (payload) => ({
2179
- type: AIRJAM_CONTROLLER_PRESENTATION_SYNC,
2180
- payload
2181
- });
2182
-
2183
- // src/runtime/arcade-runtime-url.ts
2184
- var parseOptionalArcadeSurfaceFromSearchParams = (params) => {
2185
- const epochStr = params.get("aj_arcade_epoch");
2186
- const kind = params.get("aj_arcade_kind");
2187
- if (epochStr === null || kind !== "browser" && kind !== "game") {
2188
- return void 0;
2189
- }
2190
- const epoch = Number(epochStr);
2191
- if (!Number.isFinite(epoch) || epoch < 0 || !Number.isInteger(epoch)) {
2192
- return void 0;
3189
+ role: "img",
3190
+ "aria-label": player.label,
3191
+ className: cn(
3192
+ "bg-secondary/40 flex items-center justify-center font-semibold uppercase",
3193
+ initialsSizeClasses[size],
3194
+ shellClassName
3195
+ ),
3196
+ style: {
3197
+ borderColor: accentColor,
3198
+ color: accentColor,
3199
+ boxShadow: shadowStyles[size]
3200
+ },
3201
+ children: initials ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { "aria-hidden": "true", children: initials }) : /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_lucide_react4.UserRound, { "aria-hidden": "true", className: iconSizeClasses[size] })
3202
+ }
3203
+ );
2193
3204
  }
2194
- const gameIdRaw = params.get("aj_arcade_game_id");
2195
- const gameId = kind === "browser" ? null : gameIdRaw && gameIdRaw.length > 0 ? gameIdRaw : null;
2196
- return { epoch, kind, gameId };
3205
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
3206
+ "img",
3207
+ {
3208
+ src,
3209
+ alt: player.label,
3210
+ onError: () => setFailedSrc(src),
3211
+ className: cn("bg-secondary/30", shellClassName),
3212
+ style: {
3213
+ borderColor: accentColor,
3214
+ boxShadow: shadowStyles[size]
3215
+ }
3216
+ }
3217
+ );
3218
+ };
3219
+ var initialsSizeClasses = {
3220
+ sm: "text-xs",
3221
+ md: "text-sm",
3222
+ lg: "text-base"
2197
3223
  };
3224
+ var playerInitials = (label) => label.trim().split(/\s+/).filter(Boolean).slice(0, 2).map((word) => Array.from(word)[0] ?? "").join("");
2198
3225
 
2199
- // src/runtime/runtime-session-params.ts
2200
- var readEmbeddedControllerRuntimeParams = () => {
2201
- if (typeof window === "undefined") {
2202
- return null;
2203
- }
2204
- const params = new URLSearchParams(window.location.search);
2205
- const room = params.get("aj_room");
2206
- const controllerId = params.get("aj_controller_id");
2207
- if (!room || !controllerId) {
2208
- return null;
2209
- }
2210
- const topology = parseRuntimeTopologyFromSearchParams(params);
2211
- if (!topology) {
2212
- return null;
2213
- }
2214
- const arcadeSurface = parseOptionalArcadeSurfaceFromSearchParams(params);
2215
- if (!arcadeSurface) {
2216
- return null;
2217
- }
2218
- const rawLabel = params.get("aj_player_label")?.trim();
2219
- const rawAvatarId = params.get("aj_player_avatar")?.trim();
2220
- const playerProfile = rawLabel || rawAvatarId ? {
2221
- ...rawLabel ? { label: rawLabel } : {},
2222
- ...rawAvatarId ? { avatarId: rawAvatarId } : {}
2223
- } : void 0;
2224
- return {
2225
- room,
2226
- controllerId,
2227
- topology,
2228
- arcadeSurface,
2229
- ...playerProfile ? { playerProfile } : {}
2230
- };
3226
+ // src/components/player-avatar-strip.tsx
3227
+ var import_jsx_runtime16 = require("react/jsx-runtime");
3228
+ var overflowSizeClasses = {
3229
+ sm: "h-9 w-9 min-h-9 min-w-9 text-[0.625rem]",
3230
+ md: "h-12 w-12 min-h-12 min-w-12 text-[11px]",
3231
+ lg: "h-16 w-16 min-h-16 min-w-16 text-xs"
3232
+ };
3233
+ var PlayerAvatarStrip = ({
3234
+ players,
3235
+ maxVisible = 4,
3236
+ size = "sm",
3237
+ className,
3238
+ avatarClassName = "",
3239
+ overflowBadgeClassName = ""
3240
+ }) => {
3241
+ const visible = players.slice(0, maxVisible);
3242
+ const overflow = Math.max(0, players.length - maxVisible);
3243
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: cn("flex items-center -space-x-2", className), children: [
3244
+ visible.map((player) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
3245
+ PlayerAvatar,
3246
+ {
3247
+ player,
3248
+ size,
3249
+ className: avatarClassName
3250
+ },
3251
+ player.id
3252
+ )),
3253
+ overflow > 0 && /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
3254
+ "div",
3255
+ {
3256
+ className: cn(
3257
+ "bg-secondary/50 text-foreground flex shrink-0 items-center justify-center rounded-full border-2 border-[hsl(var(--border))] font-semibold tabular-nums shadow-sm",
3258
+ overflowSizeClasses[size],
3259
+ overflowBadgeClassName
3260
+ ),
3261
+ "aria-label": `${overflow} more players`,
3262
+ children: [
3263
+ "+",
3264
+ overflow
3265
+ ]
3266
+ }
3267
+ )
3268
+ ] });
3269
+ };
3270
+
3271
+ // src/components/runtime-shell-header.tsx
3272
+ var import_jsx_runtime17 = require("react/jsx-runtime");
3273
+ var RuntimeShellHeader = ({
3274
+ connectionStatus,
3275
+ leftSlot,
3276
+ rightSlot,
3277
+ className
3278
+ }) => {
3279
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
3280
+ "header",
3281
+ {
3282
+ className: cn(
3283
+ "flex min-h-16 items-center gap-2.5 px-3 py-2.5 sm:px-4",
3284
+ shellHeaderClassName,
3285
+ className
3286
+ ),
3287
+ children: [
3288
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "min-w-0 flex-1", children: leftSlot }),
3289
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "flex shrink-0 items-center gap-2.5", children: [
3290
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ConnectionStatusPill, { status: connectionStatus }),
3291
+ rightSlot ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "flex items-center justify-end", children: rightSlot }) : null
3292
+ ] })
3293
+ ]
3294
+ }
3295
+ );
2231
3296
  };
2232
3297
 
3298
+ // src/components/surface-viewport.tsx
3299
+ var import_react11 = require("react");
3300
+
2233
3301
  // src/runtime/controller-presentation.ts
3302
+ var import_zod27 = require("zod");
3303
+ var AIRJAM_CONTROLLER_PRESENTATION_SYNC = "AIRJAM_CONTROLLER_PRESENTATION_SYNC";
3304
+ var presentationSyncSchema = import_zod27.z.object({
3305
+ type: import_zod27.z.literal(AIRJAM_CONTROLLER_PRESENTATION_SYNC),
3306
+ payload: withControllerBridgeContext({
3307
+ orientation: controllerOrientationSchema
3308
+ })
3309
+ }).strict();
2234
3310
  var publishEmbeddedControllerPresentation = (orientation) => {
2235
- if (typeof window === "undefined" || window.parent === window) {
2236
- return;
2237
- }
2238
3311
  const runtimeParams = readEmbeddedControllerRuntimeParams();
2239
- if (!runtimeParams) {
2240
- return;
2241
- }
2242
- window.parent.postMessage(
2243
- createControllerPresentationSyncMessage({
2244
- orientation,
2245
- arcadeSurface: runtimeParams.arcadeSurface
2246
- }),
2247
- runtimeParams.topology.embedParentOrigin ?? "*"
2248
- );
3312
+ if (!runtimeParams) return;
3313
+ const parent = embeddedRuntimeParent(runtimeParams.topology);
3314
+ if (!parent) return;
3315
+ const message = {
3316
+ type: AIRJAM_CONTROLLER_PRESENTATION_SYNC,
3317
+ payload: { orientation, ...controllerBridgeContext(runtimeParams) }
3318
+ };
3319
+ parent.window.postMessage(message, parent.origin);
2249
3320
  };
2250
3321
 
2251
3322
  // src/components/surface-orientation-layout.ts
@@ -2472,7 +3543,7 @@ var createSurfaceViewportScaleStyle = ({
2472
3543
  };
2473
3544
 
2474
3545
  // src/components/surface-viewport.tsx
2475
- var import_jsx_runtime16 = require("react/jsx-runtime");
3546
+ var import_jsx_runtime18 = require("react/jsx-runtime");
2476
3547
  var readLayoutViewportSize = () => {
2477
3548
  if (typeof window === "undefined") {
2478
3549
  return { width: 0, height: 0 };
@@ -2545,7 +3616,7 @@ var getOrientation = ({
2545
3616
  };
2546
3617
  var SurfaceViewport = ({
2547
3618
  children,
2548
- orientation,
3619
+ orientation: requestedOrientation,
2549
3620
  lockOnGesture = true,
2550
3621
  className,
2551
3622
  contentClassName,
@@ -2556,10 +3627,17 @@ var SurfaceViewport = ({
2556
3627
  minScale,
2557
3628
  maxScale
2558
3629
  }) => {
2559
- const [viewport, setViewport] = (0, import_react9.useState)(null);
2560
- const viewportRef = (0, import_react9.useRef)(null);
2561
3630
  const sessionScope = useSessionScope();
2562
- (0, import_react9.useEffect)(() => {
3631
+ const declaredOrientation = (0, import_react11.useContext)(fixedControllerOrientationContext);
3632
+ const fixedOrientation = sessionScope === "controller" ? declaredOrientation : null;
3633
+ if (fixedOrientation && requestedOrientation && requestedOrientation !== fixedOrientation)
3634
+ throw new Error(
3635
+ "SurfaceViewport orientation conflicts with inputModalities: ['joystick'] in airjam.config: joystick games always use landscape; omit orientation."
3636
+ );
3637
+ const orientation = fixedOrientation ?? requestedOrientation;
3638
+ const [viewport, setViewport] = (0, import_react11.useState)(null);
3639
+ const viewportRef = (0, import_react11.useRef)(null);
3640
+ (0, import_react11.useEffect)(() => {
2563
3641
  if (typeof window === "undefined") {
2564
3642
  return;
2565
3643
  }
@@ -2581,7 +3659,7 @@ var SurfaceViewport = ({
2581
3659
  window.removeEventListener("orientationchange", updateViewport);
2582
3660
  };
2583
3661
  }, []);
2584
- (0, import_react9.useEffect)(() => {
3662
+ (0, import_react11.useEffect)(() => {
2585
3663
  if (typeof window === "undefined" || !orientation || !lockOnGesture) {
2586
3664
  return;
2587
3665
  }
@@ -2605,7 +3683,7 @@ var SurfaceViewport = ({
2605
3683
  window.removeEventListener("pointerdown", onFirstGesture, true);
2606
3684
  };
2607
3685
  }, [orientation, lockOnGesture]);
2608
- (0, import_react9.useEffect)(() => {
3686
+ (0, import_react11.useEffect)(() => {
2609
3687
  if (!orientation || sessionScope !== "controller") {
2610
3688
  return;
2611
3689
  }
@@ -2614,11 +3692,11 @@ var SurfaceViewport = ({
2614
3692
  const currentOrientation = viewport ? getOrientation(viewport) : "portrait";
2615
3693
  const effectiveOrientation = orientation ?? currentOrientation;
2616
3694
  const needsRotation = orientation ? currentOrientation !== orientation : false;
2617
- const shellStyle = (0, import_react9.useMemo)(
3695
+ const shellStyle = (0, import_react11.useMemo)(
2618
3696
  () => orientation ? resolveForcedOrientationFrameStyle(orientation, needsRotation) : resolveForcedOrientationFrameStyle(effectiveOrientation, false),
2619
3697
  [effectiveOrientation, needsRotation, orientation]
2620
3698
  );
2621
- const availableSize = (0, import_react9.useMemo)(
3699
+ const availableSize = (0, import_react11.useMemo)(
2622
3700
  () => resolveSurfaceViewportAvailableSize({
2623
3701
  safeViewportWidth: viewport?.width ?? 0,
2624
3702
  safeViewportHeight: viewport?.height ?? 0,
@@ -2627,7 +3705,7 @@ var SurfaceViewport = ({
2627
3705
  }),
2628
3706
  [needsRotation, orientation, viewport]
2629
3707
  );
2630
- const referenceSize = (0, import_react9.useMemo)(
3708
+ const referenceSize = (0, import_react11.useMemo)(
2631
3709
  () => resolveSurfaceViewportReferenceSize({
2632
3710
  sessionScope,
2633
3711
  designWidth,
@@ -2645,7 +3723,7 @@ var SurfaceViewport = ({
2645
3723
  sessionScope
2646
3724
  ]
2647
3725
  );
2648
- const scale = (0, import_react9.useMemo)(() => {
3726
+ const scale = (0, import_react11.useMemo)(() => {
2649
3727
  const scaleMode = sessionScope === "controller" ? effectiveOrientation === "portrait" ? "width" : "height" : "fit";
2650
3728
  return resolveSurfaceViewportScale({
2651
3729
  availableWidth: availableSize.width,
@@ -2668,7 +3746,7 @@ var SurfaceViewport = ({
2668
3746
  sessionScope,
2669
3747
  uiScaleMultiplier
2670
3748
  ]);
2671
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
3749
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2672
3750
  "div",
2673
3751
  {
2674
3752
  className: cn("fixed inset-0 overflow-hidden", className),
@@ -2676,7 +3754,7 @@ var SurfaceViewport = ({
2676
3754
  ...createSurfaceViewportOuterStyle(),
2677
3755
  ...style
2678
3756
  },
2679
- children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { style: shellStyle, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
3757
+ children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { style: shellStyle, children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2680
3758
  "div",
2681
3759
  {
2682
3760
  className: cn("h-full w-full overflow-hidden", contentClassName),
@@ -2686,7 +3764,7 @@ var SurfaceViewport = ({
2686
3764
  referenceWidth: referenceSize.width,
2687
3765
  referenceHeight: referenceSize.height
2688
3766
  }),
2689
- children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "h-full w-full", "data-airjam-surface-root": "true", children })
3767
+ children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "h-full w-full", "data-airjam-surface-root": "true", children })
2690
3768
  }
2691
3769
  ) })
2692
3770
  }
@@ -2696,7 +3774,7 @@ var SurfaceViewport = ({
2696
3774
  // src/components/ui/slider.tsx
2697
3775
  var SliderPrimitive = __toESM(require("@radix-ui/react-slider"), 1);
2698
3776
  var React = __toESM(require("react"), 1);
2699
- var import_jsx_runtime17 = require("react/jsx-runtime");
3777
+ var import_jsx_runtime19 = require("react/jsx-runtime");
2700
3778
  function Slider({
2701
3779
  className,
2702
3780
  defaultValue,
@@ -2709,7 +3787,7 @@ function Slider({
2709
3787
  () => Array.isArray(value) ? value : Array.isArray(defaultValue) ? defaultValue : [min, max],
2710
3788
  [value, defaultValue, min, max]
2711
3789
  );
2712
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
3790
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
2713
3791
  SliderPrimitive.Root,
2714
3792
  {
2715
3793
  "data-slot": "slider",
@@ -2723,14 +3801,14 @@ function Slider({
2723
3801
  ),
2724
3802
  ...props,
2725
3803
  children: [
2726
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
3804
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2727
3805
  SliderPrimitive.Track,
2728
3806
  {
2729
3807
  "data-slot": "slider-track",
2730
3808
  className: cn(
2731
3809
  "bg-muted relative grow overflow-hidden rounded-full data-[orientation=horizontal]:h-1.5 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5"
2732
3810
  ),
2733
- children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
3811
+ children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2734
3812
  SliderPrimitive.Range,
2735
3813
  {
2736
3814
  "data-slot": "slider-range",
@@ -2741,7 +3819,7 @@ function Slider({
2741
3819
  )
2742
3820
  }
2743
3821
  ),
2744
- Array.from({ length: _values.length }, (_, index) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
3822
+ Array.from({ length: _values.length }, (_, index) => /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2745
3823
  SliderPrimitive.Thumb,
2746
3824
  {
2747
3825
  "data-slot": "slider-thumb",
@@ -2758,9 +3836,220 @@ function Slider({
2758
3836
  var import_lucide_react5 = require("lucide-react");
2759
3837
 
2760
3838
  // src/settings/platform-settings-runtime.tsx
2761
- var import_react10 = require("react");
2762
- var import_jsx_runtime18 = require("react/jsx-runtime");
2763
- var platformSettingsContext = (0, import_react10.createContext)(null);
3839
+ var import_react12 = require("react");
3840
+
3841
+ // src/runtime/iframe-bridge.ts
3842
+ var import_zod30 = require("zod");
3843
+
3844
+ // src/contracts/v2/bridge.ts
3845
+ var import_zod28 = require("zod");
3846
+ var roomCodeSchema2 = import_zod28.z.string().trim().min(4).max(8).regex(/^[A-Z0-9]+$/, {
3847
+ message: "room code must contain only A-Z or 0-9"
3848
+ });
3849
+ var runtimeStateSchema2 = import_zod28.z.enum(["paused", "playing"]);
3850
+ var playerProfileSchema2 = import_zod28.z.object({
3851
+ id: import_zod28.z.string().min(1),
3852
+ label: import_zod28.z.string().min(1),
3853
+ color: import_zod28.z.string().optional(),
3854
+ avatarId: import_zod28.z.string().optional()
3855
+ }).strict();
3856
+ var inputFrameEntrySchema = import_zod28.z.object({
3857
+ controllerId: import_zod28.z.string().min(1),
3858
+ input: import_zod28.z.record(import_zod28.z.string(), import_zod28.z.unknown())
3859
+ }).strict();
3860
+ var V2_BRIDGE_PARENT_TO_GAME_TYPES = [
3861
+ "BOOTSTRAP",
3862
+ "PLAYERS_UPDATE",
3863
+ "RUNTIME_STATE_UPDATE",
3864
+ "INPUT_FRAME",
3865
+ "PAUSE",
3866
+ "RESUME",
3867
+ "SHUTDOWN"
3868
+ ];
3869
+ var V2_BRIDGE_GAME_TO_PARENT_TYPES = [
3870
+ "READY",
3871
+ "STATE_PATCH",
3872
+ "SIGNAL",
3873
+ "ERROR",
3874
+ "METRICS"
3875
+ ];
3876
+ var allMessageTypes = [
3877
+ ...V2_BRIDGE_PARENT_TO_GAME_TYPES,
3878
+ ...V2_BRIDGE_GAME_TO_PARENT_TYPES
3879
+ ];
3880
+ var knownBridgeMessageTypeSet = new Set(allMessageTypes);
3881
+ var bootstrapMessageSchema = import_zod28.z.object({
3882
+ type: import_zod28.z.literal("BOOTSTRAP"),
3883
+ payload: import_zod28.z.object({
3884
+ roomId: roomCodeSchema2,
3885
+ players: import_zod28.z.array(playerProfileSchema2),
3886
+ state: import_zod28.z.object({
3887
+ runtimeState: runtimeStateSchema2,
3888
+ message: import_zod28.z.string().optional()
3889
+ }).strict(),
3890
+ capabilities: import_zod28.z.record(import_zod28.z.string(), import_zod28.z.boolean()).default({})
3891
+ }).strict()
3892
+ }).strict();
3893
+ var playersUpdateMessageSchema = import_zod28.z.object({
3894
+ type: import_zod28.z.literal("PLAYERS_UPDATE"),
3895
+ payload: import_zod28.z.object({
3896
+ players: import_zod28.z.array(playerProfileSchema2)
3897
+ }).strict()
3898
+ }).strict();
3899
+ var runtimeStateUpdateMessageSchema = import_zod28.z.object({
3900
+ type: import_zod28.z.literal("RUNTIME_STATE_UPDATE"),
3901
+ payload: import_zod28.z.object({
3902
+ runtimeState: runtimeStateSchema2,
3903
+ message: import_zod28.z.string().optional()
3904
+ }).strict()
3905
+ }).strict();
3906
+ var inputFrameMessageSchema = import_zod28.z.object({
3907
+ type: import_zod28.z.literal("INPUT_FRAME"),
3908
+ payload: import_zod28.z.object({
3909
+ frameId: import_zod28.z.number().int().nonnegative(),
3910
+ inputs: import_zod28.z.array(inputFrameEntrySchema)
3911
+ }).strict()
3912
+ }).strict();
3913
+ var pauseMessageSchema = import_zod28.z.object({
3914
+ type: import_zod28.z.literal("PAUSE"),
3915
+ payload: import_zod28.z.object({
3916
+ reason: import_zod28.z.string().optional()
3917
+ }).strict()
3918
+ }).strict();
3919
+ var resumeMessageSchema = import_zod28.z.object({
3920
+ type: import_zod28.z.literal("RESUME"),
3921
+ payload: import_zod28.z.object({}).strict()
3922
+ }).strict();
3923
+ var shutdownMessageSchema = import_zod28.z.object({
3924
+ type: import_zod28.z.literal("SHUTDOWN"),
3925
+ payload: import_zod28.z.object({
3926
+ reason: import_zod28.z.string().min(1)
3927
+ }).strict()
3928
+ }).strict();
3929
+ var readyMessageSchema = import_zod28.z.object({
3930
+ type: import_zod28.z.literal("READY"),
3931
+ payload: import_zod28.z.object({
3932
+ readyAtMs: import_zod28.z.number().int().nonnegative()
3933
+ }).strict()
3934
+ }).strict();
3935
+ var statePatchMessageSchema = import_zod28.z.object({
3936
+ type: import_zod28.z.literal("STATE_PATCH"),
3937
+ payload: import_zod28.z.object({
3938
+ patch: import_zod28.z.record(import_zod28.z.string(), import_zod28.z.unknown())
3939
+ }).strict()
3940
+ }).strict();
3941
+ var signalMessageSchema = import_zod28.z.object({
3942
+ type: import_zod28.z.literal("SIGNAL"),
3943
+ payload: import_zod28.z.object({
3944
+ signalType: import_zod28.z.string().min(1),
3945
+ targetId: import_zod28.z.string().min(1).optional(),
3946
+ data: import_zod28.z.record(import_zod28.z.string(), import_zod28.z.unknown())
3947
+ }).strict()
3948
+ }).strict();
3949
+ var errorMessageSchema = import_zod28.z.object({
3950
+ type: import_zod28.z.literal("ERROR"),
3951
+ payload: import_zod28.z.object({
3952
+ code: import_zod28.z.string().min(1),
3953
+ message: import_zod28.z.string().min(1),
3954
+ details: import_zod28.z.record(import_zod28.z.string(), import_zod28.z.unknown()).optional()
3955
+ }).strict()
3956
+ }).strict();
3957
+ var metricsMessageSchema = import_zod28.z.object({
3958
+ type: import_zod28.z.literal("METRICS"),
3959
+ payload: import_zod28.z.object({
3960
+ values: import_zod28.z.record(import_zod28.z.string(), import_zod28.z.number())
3961
+ }).strict()
3962
+ }).strict();
3963
+ var v2BridgeParentToGameMessageSchema = import_zod28.z.union([
3964
+ bootstrapMessageSchema,
3965
+ playersUpdateMessageSchema,
3966
+ runtimeStateUpdateMessageSchema,
3967
+ inputFrameMessageSchema,
3968
+ pauseMessageSchema,
3969
+ resumeMessageSchema,
3970
+ shutdownMessageSchema
3971
+ ]);
3972
+ var v2BridgeGameToParentMessageSchema = import_zod28.z.union([
3973
+ readyMessageSchema,
3974
+ statePatchMessageSchema,
3975
+ signalMessageSchema,
3976
+ errorMessageSchema,
3977
+ metricsMessageSchema
3978
+ ]);
3979
+ var v2BridgeMessageSchema = import_zod28.z.union([
3980
+ v2BridgeParentToGameMessageSchema,
3981
+ v2BridgeGameToParentMessageSchema
3982
+ ]);
3983
+
3984
+ // src/contracts/v2/handshake.ts
3985
+ var import_zod29 = require("zod");
3986
+ var AIR_JAM_PROTOCOL_V2 = "2";
3987
+ var semanticVersionPattern = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
3988
+ var v2ProtocolVersionSchema = import_zod29.z.literal(AIR_JAM_PROTOCOL_V2);
3989
+ var runtimeKindSchema = import_zod29.z.enum([
3990
+ "standalone-host",
3991
+ "standalone-controller",
3992
+ "arcade-runtime",
3993
+ "arcade-game-iframe",
3994
+ "arcade-host-runtime",
3995
+ "arcade-host-iframe",
3996
+ "arcade-controller-runtime",
3997
+ "arcade-controller-iframe"
3998
+ ]);
3999
+ var capabilityFlagsSchema = import_zod29.z.record(import_zod29.z.string(), import_zod29.z.boolean());
4000
+ var sdkVersionSchema = import_zod29.z.string().regex(
4001
+ semanticVersionPattern,
4002
+ "sdkVersion must use semantic version format (for example 1.2.3)"
4003
+ );
4004
+ var v2HandshakeSchema = import_zod29.z.object({
4005
+ protocolVersion: v2ProtocolVersionSchema,
4006
+ sdkVersion: sdkVersionSchema,
4007
+ runtimeKind: runtimeKindSchema,
4008
+ capabilityFlags: capabilityFlagsSchema.default({})
4009
+ }).strict();
4010
+
4011
+ // src/runtime/iframe-bridge.ts
4012
+ var AIRJAM_BRIDGE_INIT = "AIRJAM_BRIDGE_INIT";
4013
+ var AIRJAM_SETTINGS_SYNC = "AIRJAM_SETTINGS_SYNC";
4014
+ var AIRJAM_SETTINGS_READY = "AIRJAM_SETTINGS_READY";
4015
+ var airJamSettingsSyncSchema = import_zod30.z.object({
4016
+ type: import_zod30.z.literal(AIRJAM_SETTINGS_SYNC),
4017
+ payload: import_zod30.z.object({
4018
+ settings: import_zod30.z.object({
4019
+ audio: import_zod30.z.object({
4020
+ masterVolume: import_zod30.z.number(),
4021
+ musicVolume: import_zod30.z.number(),
4022
+ sfxVolume: import_zod30.z.number()
4023
+ }).strict(),
4024
+ accessibility: import_zod30.z.object({
4025
+ reducedMotion: import_zod30.z.boolean(),
4026
+ highContrast: import_zod30.z.boolean()
4027
+ }).strict(),
4028
+ feedback: import_zod30.z.object({
4029
+ hapticsEnabled: import_zod30.z.boolean()
4030
+ }).strict(),
4031
+ previewControllers: import_zod30.z.object({
4032
+ activeOpacity: import_zod30.z.number()
4033
+ }).strict()
4034
+ }).strict()
4035
+ }).strict()
4036
+ }).strict();
4037
+ var airJamBridgeInitSchema = import_zod30.z.object({
4038
+ type: import_zod30.z.literal(AIRJAM_BRIDGE_INIT),
4039
+ payload: import_zod30.z.object({
4040
+ handshake: v2HandshakeSchema
4041
+ }).strict()
4042
+ }).strict();
4043
+ var airJamSettingsReadySchema = import_zod30.z.object({
4044
+ type: import_zod30.z.literal(AIRJAM_SETTINGS_READY),
4045
+ payload: import_zod30.z.object({
4046
+ ready: import_zod30.z.literal(true)
4047
+ }).strict()
4048
+ }).strict();
4049
+
4050
+ // src/settings/platform-settings-runtime.tsx
4051
+ var import_jsx_runtime20 = require("react/jsx-runtime");
4052
+ var platformSettingsContext = (0, import_react12.createContext)(null);
2764
4053
  var createDefaultContextValue = () => ({
2765
4054
  mode: "default",
2766
4055
  status: "ready",
@@ -2777,10 +4066,10 @@ var createDefaultContextValue = () => ({
2777
4066
  }
2778
4067
  });
2779
4068
  function usePlatformAudioSettings() {
2780
- const context = (0, import_react10.useContext)(platformSettingsContext) ?? createDefaultContextValue();
4069
+ const context = (0, import_react12.useContext)(platformSettingsContext) ?? createDefaultContextValue();
2781
4070
  const { audio } = context.settings;
2782
4071
  const isReadOnly = context.mode !== "owner";
2783
- const setAudioSetting = (0, import_react10.useCallback)(
4072
+ const setAudioSetting = (0, import_react12.useCallback)(
2784
4073
  (patch) => {
2785
4074
  if (context.mode !== "owner") {
2786
4075
  throw new Error(
@@ -2802,12 +4091,12 @@ function usePlatformAudioSettings() {
2802
4091
  }
2803
4092
 
2804
4093
  // src/components/volume-controls.tsx
2805
- var import_jsx_runtime19 = require("react/jsx-runtime");
4094
+ var import_jsx_runtime21 = require("react/jsx-runtime");
2806
4095
  function VolumeControls(props) {
2807
4096
  if (props.values) {
2808
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(ControlledVolumeControls, { ...props });
4097
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(ControlledVolumeControls, { ...props });
2809
4098
  }
2810
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(OwnedVolumeControls, { ...props });
4099
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(OwnedVolumeControls, { ...props });
2811
4100
  }
2812
4101
  function OwnedVolumeControls({ className, compact }) {
2813
4102
  const {
@@ -2818,7 +4107,7 @@ function OwnedVolumeControls({ className, compact }) {
2818
4107
  setMusicVolume,
2819
4108
  setSfxVolume
2820
4109
  } = usePlatformAudioSettings();
2821
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
4110
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2822
4111
  ControlledVolumeControls,
2823
4112
  {
2824
4113
  className,
@@ -2844,20 +4133,20 @@ function ControlledVolumeControls({
2844
4133
  throw new Error("ControlledVolumeControls requires values");
2845
4134
  }
2846
4135
  const { masterVolume, musicVolume, sfxVolume } = values;
2847
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: cn("flex flex-col gap-3", compact && "gap-1", className), children: [
2848
- /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-center gap-2", children: [
2849
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_lucide_react5.Volume2, { className: "text-muted-foreground h-4 w-4" }),
2850
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "text-sm font-medium", children: "Volume" })
4136
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: cn("flex flex-col gap-3", compact && "gap-1", className), children: [
4137
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex items-center gap-2", children: [
4138
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_lucide_react5.Volume2, { className: "text-muted-foreground h-4 w-4" }),
4139
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { className: "text-sm font-medium", children: "Volume" })
2851
4140
  ] }),
2852
- /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "space-y-1.5", children: [
2853
- /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-center justify-between", children: [
2854
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("label", { className: "text-muted-foreground text-xs", children: "Master" }),
2855
- /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("span", { className: "text-muted-foreground font-mono text-xs", children: [
4141
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "space-y-1.5", children: [
4142
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex items-center justify-between", children: [
4143
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("label", { className: "text-muted-foreground text-xs", children: "Master" }),
4144
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("span", { className: "text-muted-foreground font-mono text-xs", children: [
2856
4145
  Math.round(masterVolume * 100),
2857
4146
  "%"
2858
4147
  ] })
2859
4148
  ] }),
2860
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
4149
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2861
4150
  Slider,
2862
4151
  {
2863
4152
  "data-testid": "platform-settings-master-volume",
@@ -2872,18 +4161,18 @@ function ControlledVolumeControls({
2872
4161
  }
2873
4162
  )
2874
4163
  ] }),
2875
- /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "space-y-1.5", children: [
2876
- /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-center justify-between", children: [
2877
- /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-center gap-1.5", children: [
2878
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_lucide_react5.Music, { className: "text-muted-foreground h-3 w-3" }),
2879
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("label", { className: "text-muted-foreground text-xs", children: "Music" })
4164
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "space-y-1.5", children: [
4165
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex items-center justify-between", children: [
4166
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex items-center gap-1.5", children: [
4167
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_lucide_react5.Music, { className: "text-muted-foreground h-3 w-3" }),
4168
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("label", { className: "text-muted-foreground text-xs", children: "Music" })
2880
4169
  ] }),
2881
- /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("span", { className: "text-muted-foreground font-mono text-xs", children: [
4170
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("span", { className: "text-muted-foreground font-mono text-xs", children: [
2882
4171
  Math.round(musicVolume * 100),
2883
4172
  "%"
2884
4173
  ] })
2885
4174
  ] }),
2886
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
4175
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2887
4176
  Slider,
2888
4177
  {
2889
4178
  "data-testid": "platform-settings-music-volume",
@@ -2898,18 +4187,18 @@ function ControlledVolumeControls({
2898
4187
  }
2899
4188
  )
2900
4189
  ] }),
2901
- /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "space-y-1.5", children: [
2902
- /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-center justify-between", children: [
2903
- /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-center gap-1.5", children: [
2904
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_lucide_react5.Headphones, { className: "text-muted-foreground h-3 w-3" }),
2905
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("label", { className: "text-muted-foreground text-xs", children: "SFX" })
4190
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "space-y-1.5", children: [
4191
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex items-center justify-between", children: [
4192
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex items-center gap-1.5", children: [
4193
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_lucide_react5.Headphones, { className: "text-muted-foreground h-3 w-3" }),
4194
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("label", { className: "text-muted-foreground text-xs", children: "SFX" })
2906
4195
  ] }),
2907
- /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("span", { className: "text-muted-foreground font-mono text-xs", children: [
4196
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("span", { className: "text-muted-foreground font-mono text-xs", children: [
2908
4197
  Math.round(sfxVolume * 100),
2909
4198
  "%"
2910
4199
  ] })
2911
4200
  ] }),
2912
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
4201
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2913
4202
  Slider,
2914
4203
  {
2915
4204
  "data-testid": "platform-settings-sfx-volume",
@@ -2985,7 +4274,7 @@ var useControllerShellStatus = ({
2985
4274
  };
2986
4275
 
2987
4276
  // src/hooks/use-host-join-controls.ts
2988
- var import_react11 = require("react");
4277
+ var import_react13 = require("react");
2989
4278
  var copyTextToClipboard = async (text) => {
2990
4279
  if (!text) {
2991
4280
  return false;
@@ -3020,17 +4309,17 @@ var useHostJoinControls = ({
3020
4309
  onStartMatch,
3021
4310
  copiedDurationMs = 1800
3022
4311
  }) => {
3023
- const [copied, setCopied] = (0, import_react11.useState)(false);
3024
- const [joinQrVisible, setJoinQrVisible] = (0, import_react11.useState)(false);
3025
- const resetTimerRef = (0, import_react11.useRef)(null);
3026
- const joinUrlValue = (0, import_react11.useMemo)(() => joinUrl ?? "", [joinUrl]);
4312
+ const [copied, setCopied] = (0, import_react13.useState)(false);
4313
+ const [joinQrVisible, setJoinQrVisible] = (0, import_react13.useState)(false);
4314
+ const resetTimerRef = (0, import_react13.useRef)(null);
4315
+ const joinUrlValue = (0, import_react13.useMemo)(() => joinUrl ?? "", [joinUrl]);
3027
4316
  const hasJoinUrl = joinUrlValue.length > 0;
3028
- (0, import_react11.useEffect)(() => {
4317
+ (0, import_react13.useEffect)(() => {
3029
4318
  if (!hasJoinUrl) {
3030
4319
  setJoinQrVisible(false);
3031
4320
  }
3032
4321
  }, [hasJoinUrl]);
3033
- const handleCopy = (0, import_react11.useCallback)(async () => {
4322
+ const handleCopy = (0, import_react13.useCallback)(async () => {
3034
4323
  if (!joinUrlValue) {
3035
4324
  return;
3036
4325
  }
@@ -3047,28 +4336,28 @@ var useHostJoinControls = ({
3047
4336
  resetTimerRef.current = null;
3048
4337
  }, copiedDurationMs);
3049
4338
  }, [copiedDurationMs, joinUrlValue]);
3050
- const handleOpen = (0, import_react11.useCallback)(() => {
4339
+ const handleOpen = (0, import_react13.useCallback)(() => {
3051
4340
  if (!joinUrlValue || typeof window === "undefined") {
3052
4341
  return;
3053
4342
  }
3054
4343
  window.open(joinUrlValue, "_blank", "noopener,noreferrer");
3055
4344
  }, [joinUrlValue]);
3056
- const showJoinQr = (0, import_react11.useCallback)(() => {
4345
+ const showJoinQr = (0, import_react13.useCallback)(() => {
3057
4346
  if (!hasJoinUrl) {
3058
4347
  return;
3059
4348
  }
3060
4349
  setJoinQrVisible(true);
3061
4350
  }, [hasJoinUrl]);
3062
- const hideJoinQr = (0, import_react11.useCallback)(() => {
4351
+ const hideJoinQr = (0, import_react13.useCallback)(() => {
3063
4352
  setJoinQrVisible(false);
3064
4353
  }, []);
3065
- const toggleJoinQr = (0, import_react11.useCallback)(() => {
4354
+ const toggleJoinQr = (0, import_react13.useCallback)(() => {
3066
4355
  if (!hasJoinUrl) {
3067
4356
  return;
3068
4357
  }
3069
4358
  setJoinQrVisible((current) => !current);
3070
4359
  }, [hasJoinUrl]);
3071
- const handleStart = (0, import_react11.useCallback)(() => {
4360
+ const handleStart = (0, import_react13.useCallback)(() => {
3072
4361
  if (!canStartMatch) {
3073
4362
  return;
3074
4363
  }
@@ -3091,10 +4380,13 @@ var useHostJoinControls = ({
3091
4380
  // Annotate the CommonJS export names for ESM import in node:
3092
4381
  0 && (module.exports = {
3093
4382
  AIRJAM_DEFAULT_AVATAR_SEEDS,
4383
+ AxisButton,
3094
4384
  Button,
3095
4385
  ConnectionStatusPill,
4386
+ ControlButton,
3096
4387
  ControllerPlayerNameField,
3097
4388
  ControllerPrimaryAction,
4389
+ GamepadLayout,
3098
4390
  HostMuteButton,
3099
4391
  JoinQrOverlay,
3100
4392
  JoinUrlActionButtons,
@@ -3106,12 +4398,10 @@ var useHostJoinControls = ({
3106
4398
  RoomQrCode,
3107
4399
  RuntimeShellHeader,
3108
4400
  Slider,
4401
+ Stick,
3109
4402
  SurfaceViewport,
3110
4403
  VolumeControls,
3111
- buttonVariants,
3112
4404
  getDiceBearAdventurerNeutralUrl,
3113
- getPlayerAvatarImageUrl,
3114
- resolvePlayerAvatarSeed,
3115
4405
  useControllerLifecycleIntents,
3116
4406
  useControllerLifecyclePermissions,
3117
4407
  useControllerShellStatus,