@air-jam/sdk 0.1.4 → 0.9.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 (357) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +627 -57
  3. package/dist/agent-tooling-BSMGBix9.d.cts +123 -0
  4. package/dist/agent-tooling-BSMGBix9.d.ts +123 -0
  5. package/dist/agent-tooling.cjs +83 -0
  6. package/dist/agent-tooling.cjs.map +1 -0
  7. package/dist/agent-tooling.d.cts +2 -0
  8. package/dist/agent-tooling.d.ts +2 -0
  9. package/dist/agent-tooling.js +17 -0
  10. package/dist/agent-tooling.js.map +1 -0
  11. package/dist/arcade/bridge/controller.cjs +749 -0
  12. package/dist/arcade/bridge/controller.cjs.map +1 -0
  13. package/dist/arcade/bridge/controller.d.cts +85 -0
  14. package/dist/arcade/bridge/controller.d.ts +85 -0
  15. package/dist/arcade/bridge/controller.js +33 -0
  16. package/dist/arcade/bridge/controller.js.map +1 -0
  17. package/dist/arcade/bridge/host.cjs +421 -0
  18. package/dist/arcade/bridge/host.cjs.map +1 -0
  19. package/dist/arcade/bridge/host.d.cts +73 -0
  20. package/dist/arcade/bridge/host.d.ts +73 -0
  21. package/dist/arcade/bridge/host.js +25 -0
  22. package/dist/arcade/bridge/host.js.map +1 -0
  23. package/dist/arcade/bridge/iframe.cjs +453 -0
  24. package/dist/arcade/bridge/iframe.cjs.map +1 -0
  25. package/dist/arcade/bridge/iframe.d.cts +80 -0
  26. package/dist/arcade/bridge/iframe.d.ts +80 -0
  27. package/dist/arcade/bridge/iframe.js +28 -0
  28. package/dist/arcade/bridge/iframe.js.map +1 -0
  29. package/dist/arcade/bridge.cjs +1067 -0
  30. package/dist/arcade/bridge.cjs.map +1 -0
  31. package/dist/arcade/bridge.d.cts +11 -0
  32. package/dist/arcade/bridge.d.ts +11 -0
  33. package/dist/arcade/bridge.js +76 -0
  34. package/dist/arcade/bridge.js.map +1 -0
  35. package/dist/arcade/host.cjs +481 -0
  36. package/dist/arcade/host.cjs.map +1 -0
  37. package/dist/arcade/host.d.cts +19 -0
  38. package/dist/arcade/host.d.ts +19 -0
  39. package/dist/arcade/host.js +14 -0
  40. package/dist/arcade/host.js.map +1 -0
  41. package/dist/arcade/surface.cjs +113 -0
  42. package/dist/arcade/surface.cjs.map +1 -0
  43. package/dist/arcade/surface.d.cts +14 -0
  44. package/dist/arcade/surface.d.ts +14 -0
  45. package/dist/arcade/surface.js +27 -0
  46. package/dist/arcade/surface.js.map +1 -0
  47. package/dist/arcade/url.cjs +544 -0
  48. package/dist/arcade/url.cjs.map +1 -0
  49. package/dist/arcade/url.d.cts +68 -0
  50. package/dist/arcade/url.d.ts +68 -0
  51. package/dist/arcade/url.js +29 -0
  52. package/dist/arcade/url.js.map +1 -0
  53. package/dist/arcade-runtime-url-BW-MUAOY.d.cts +28 -0
  54. package/dist/arcade-runtime-url-l8qj01Pg.d.ts +28 -0
  55. package/dist/arcade-surface-identity-CQxDpn_w.d.cts +16 -0
  56. package/dist/arcade-surface-identity-CQxDpn_w.d.ts +16 -0
  57. package/dist/arcade.cjs +1737 -0
  58. package/dist/arcade.cjs.map +1 -0
  59. package/dist/arcade.d.cts +18 -0
  60. package/dist/arcade.d.ts +18 -0
  61. package/dist/arcade.js +123 -0
  62. package/dist/arcade.js.map +1 -0
  63. package/dist/capabilities.cjs +39 -0
  64. package/dist/capabilities.cjs.map +1 -0
  65. package/dist/capabilities.d.cts +31 -0
  66. package/dist/capabilities.d.ts +31 -0
  67. package/dist/capabilities.js +12 -0
  68. package/dist/capabilities.js.map +1 -0
  69. package/dist/chunk-32NYL7XI.js +539 -0
  70. package/dist/chunk-32NYL7XI.js.map +1 -0
  71. package/dist/chunk-3USU7GY2.js +54 -0
  72. package/dist/chunk-3USU7GY2.js.map +1 -0
  73. package/dist/chunk-7UXSWCZZ.js +32 -0
  74. package/dist/chunk-7UXSWCZZ.js.map +1 -0
  75. package/dist/chunk-BE6Z4SIT.js +65 -0
  76. package/dist/chunk-BE6Z4SIT.js.map +1 -0
  77. package/dist/chunk-CABEUV65.js +184 -0
  78. package/dist/chunk-CABEUV65.js.map +1 -0
  79. package/dist/chunk-CEJ5RFSG.js +288 -0
  80. package/dist/chunk-CEJ5RFSG.js.map +1 -0
  81. package/dist/chunk-EDRQIOCV.js +25 -0
  82. package/dist/chunk-EDRQIOCV.js.map +1 -0
  83. package/dist/chunk-EVZJA6RN.js +140 -0
  84. package/dist/chunk-EVZJA6RN.js.map +1 -0
  85. package/dist/chunk-FAT2KJ3K.js +238 -0
  86. package/dist/chunk-FAT2KJ3K.js.map +1 -0
  87. package/dist/chunk-IKKDONQL.js +1 -0
  88. package/dist/chunk-IKKDONQL.js.map +1 -0
  89. package/dist/chunk-JEHV5C2X.js +249 -0
  90. package/dist/chunk-JEHV5C2X.js.map +1 -0
  91. package/dist/chunk-JO2HR5PV.js +43 -0
  92. package/dist/chunk-JO2HR5PV.js.map +1 -0
  93. package/dist/chunk-JTF47B56.js +1 -0
  94. package/dist/chunk-JTF47B56.js.map +1 -0
  95. package/dist/chunk-KXAFI5OP.js +193 -0
  96. package/dist/chunk-KXAFI5OP.js.map +1 -0
  97. package/dist/chunk-LIXPF4P6.js +22 -0
  98. package/dist/chunk-LIXPF4P6.js.map +1 -0
  99. package/dist/chunk-MPDMJIX5.js +1 -0
  100. package/dist/chunk-MPDMJIX5.js.map +1 -0
  101. package/dist/chunk-NCL6WJCL.js +91 -0
  102. package/dist/chunk-NCL6WJCL.js.map +1 -0
  103. package/dist/chunk-NUJBMV3O.js +1435 -0
  104. package/dist/chunk-NUJBMV3O.js.map +1 -0
  105. package/dist/chunk-TGRTEWYV.js +195 -0
  106. package/dist/chunk-TGRTEWYV.js.map +1 -0
  107. package/dist/chunk-UWJOIVON.js +369 -0
  108. package/dist/chunk-UWJOIVON.js.map +1 -0
  109. package/dist/chunk-VKBMZHMQ.js +216 -0
  110. package/dist/chunk-VKBMZHMQ.js.map +1 -0
  111. package/dist/chunk-W2VK36RO.js +11 -0
  112. package/dist/chunk-W2VK36RO.js.map +1 -0
  113. package/dist/chunk-W3YA5BWR.js +126 -0
  114. package/dist/chunk-W3YA5BWR.js.map +1 -0
  115. package/dist/chunk-X24K52DG.js +12 -0
  116. package/dist/chunk-X24K52DG.js.map +1 -0
  117. package/dist/chunk-YXHH3MQT.js +230 -0
  118. package/dist/chunk-YXHH3MQT.js.map +1 -0
  119. package/dist/chunk-ZLPL2R3R.js +183 -0
  120. package/dist/chunk-ZLPL2R3R.js.map +1 -0
  121. package/dist/chunk-ZTQ5SP4H.js +9 -0
  122. package/dist/chunk-ZTQ5SP4H.js.map +1 -0
  123. package/dist/controller-Bod8YYr1.d.cts +172 -0
  124. package/dist/controller-DxVchfiA.d.ts +172 -0
  125. package/dist/dev-log-events-CVAM29hx.d.cts +123 -0
  126. package/dist/dev-log-events-CVAM29hx.d.ts +123 -0
  127. package/dist/handshake-CC_LrK5g.d.cts +31 -0
  128. package/dist/handshake-CC_LrK5g.d.ts +31 -0
  129. package/dist/host-8hmq_Sgc.d.cts +109 -0
  130. package/dist/host-Cw-N6e-5.d.ts +109 -0
  131. package/dist/index.cjs +8730 -3426
  132. package/dist/index.cjs.map +1 -1
  133. package/dist/index.d.cts +676 -1070
  134. package/dist/index.d.ts +676 -1070
  135. package/dist/index.js +4892 -3196
  136. package/dist/index.js.map +1 -1
  137. package/dist/metadata.cjs +114 -0
  138. package/dist/metadata.cjs.map +1 -0
  139. package/dist/metadata.d.cts +95 -0
  140. package/dist/metadata.d.ts +95 -0
  141. package/dist/metadata.js +83 -0
  142. package/dist/metadata.js.map +1 -0
  143. package/dist/notices-CnGaaS8B.d.ts +38 -0
  144. package/dist/notices-NyDM5Mtz.d.cts +38 -0
  145. package/dist/platform-machine.cjs +425 -0
  146. package/dist/platform-machine.cjs.map +1 -0
  147. package/dist/platform-machine.d.cts +1183 -0
  148. package/dist/platform-machine.d.ts +1183 -0
  149. package/dist/platform-machine.js +309 -0
  150. package/dist/platform-machine.js.map +1 -0
  151. package/dist/platform-settings-cuor3i11.d.cts +48 -0
  152. package/dist/platform-settings-cuor3i11.d.ts +48 -0
  153. package/dist/prefabs.cjs +36 -0
  154. package/dist/prefabs.cjs.map +1 -0
  155. package/dist/prefabs.d.cts +49 -0
  156. package/dist/prefabs.d.ts +49 -0
  157. package/dist/prefabs.js +8 -0
  158. package/dist/prefabs.js.map +1 -0
  159. package/dist/preview.cjs +2620 -0
  160. package/dist/preview.cjs.map +1 -0
  161. package/dist/preview.d.cts +155 -0
  162. package/dist/preview.d.ts +155 -0
  163. package/dist/preview.js +1671 -0
  164. package/dist/preview.js.map +1 -0
  165. package/dist/protocol.cjs +621 -54
  166. package/dist/protocol.cjs.map +1 -1
  167. package/dist/protocol.d.cts +76 -240
  168. package/dist/protocol.d.ts +76 -240
  169. package/dist/protocol.js +100 -2
  170. package/dist/protocol.js.map +1 -1
  171. package/dist/realtime-client-Cu8yVJFw.d.cts +15 -0
  172. package/dist/realtime-client-Cu8yVJFw.d.ts +15 -0
  173. package/dist/release.cjs +143 -0
  174. package/dist/release.cjs.map +1 -0
  175. package/dist/release.d.cts +64 -0
  176. package/dist/release.d.ts +64 -0
  177. package/dist/release.js +43 -0
  178. package/dist/release.js.map +1 -0
  179. package/dist/runtime-topology.cjs +405 -0
  180. package/dist/runtime-topology.cjs.map +1 -0
  181. package/dist/runtime-topology.d.cts +59 -0
  182. package/dist/runtime-topology.d.ts +59 -0
  183. package/dist/runtime-topology.js +31 -0
  184. package/dist/runtime-topology.js.map +1 -0
  185. package/dist/standard-match-phase-BucA5dYo.d.ts +44 -0
  186. package/dist/standard-match-phase-U2ra8J-0.d.cts +44 -0
  187. package/dist/sync-B6QsNrXz.d.cts +125 -0
  188. package/dist/sync-B6QsNrXz.d.ts +125 -0
  189. package/dist/ui.cjs +3061 -0
  190. package/dist/ui.cjs.map +1 -0
  191. package/dist/ui.d.cts +320 -0
  192. package/dist/ui.d.ts +320 -0
  193. package/dist/ui.js +1719 -0
  194. package/dist/ui.js.map +1 -0
  195. package/dist/url-policy-C89zxgw9.d.cts +9 -0
  196. package/dist/url-policy-C89zxgw9.d.ts +9 -0
  197. package/package.json +155 -10
  198. package/src/agent/agent-action.ts +304 -0
  199. package/src/agent/agent-contract.ts +180 -0
  200. package/src/agent-tooling.ts +20 -0
  201. package/src/arcade/bridge/controller.ts +15 -0
  202. package/src/arcade/bridge/host.ts +12 -0
  203. package/src/arcade/bridge/iframe.ts +61 -0
  204. package/src/arcade/bridge.ts +3 -0
  205. package/src/arcade/host.ts +1 -0
  206. package/src/arcade/surface.ts +4 -0
  207. package/src/arcade/url.ts +60 -0
  208. package/src/arcade.ts +4 -0
  209. package/src/audio/audio-manager.ts +162 -171
  210. package/src/audio/hooks.tsx +218 -97
  211. package/src/audio/index.ts +1 -1
  212. package/src/audio/music.tsx +139 -0
  213. package/src/capabilities/manifest.ts +71 -0
  214. package/src/capabilities.ts +12 -0
  215. package/src/components/connection-status-pill.tsx +55 -0
  216. package/src/components/controller-player-name-field.tsx +119 -0
  217. package/src/components/controller-primary-action.tsx +58 -0
  218. package/src/components/host-mute-button.tsx +49 -0
  219. package/src/components/join-qr-overlay.tsx +133 -0
  220. package/src/components/join-url-action-buttons.tsx +95 -0
  221. package/src/components/join-url-controls.tsx +58 -0
  222. package/src/components/join-url-field.tsx +52 -0
  223. package/src/components/lifecycle-action-group.tsx +129 -0
  224. package/src/components/player-avatar-strip.tsx +65 -0
  225. package/src/components/player-avatar.tsx +42 -13
  226. package/src/components/room-qr-code.tsx +125 -0
  227. package/src/components/runtime-shell-header.tsx +37 -0
  228. package/src/components/shell-classes.ts +19 -0
  229. package/src/components/surface-orientation-layout.ts +60 -0
  230. package/src/components/surface-viewport-layout.ts +268 -0
  231. package/src/components/surface-viewport.tsx +314 -0
  232. package/src/components/ui/button.tsx +4 -6
  233. package/src/components/ui/slider.tsx +1 -1
  234. package/src/components/volume-controls.tsx +65 -6
  235. package/src/context/air-jam-context.tsx +209 -161
  236. package/src/context/index.ts +2 -2
  237. package/src/context/session-providers.tsx +77 -0
  238. package/src/context/session-scope.ts +64 -0
  239. package/src/context/socket-manager.ts +6 -24
  240. package/src/contracts/v2/bridge.ts +261 -0
  241. package/src/contracts/v2/handshake.ts +40 -0
  242. package/src/contracts/v2/index.ts +2 -0
  243. package/src/dev/browser-log-sink.ts +912 -0
  244. package/src/diagnostics.ts +128 -0
  245. package/src/events.ts +7 -34
  246. package/src/hooks/internal/use-controller-runtime-api.ts +875 -0
  247. package/src/hooks/internal/use-host-runtime-api.ts +1051 -0
  248. package/src/hooks/internal/use-runtime-control-contract.ts +15 -0
  249. package/src/hooks/internal/use-runtime-inspection-contract.ts +16 -0
  250. package/src/hooks/internal/use-runtime-observability-contract.ts +24 -0
  251. package/src/hooks/use-air-jam-controller.ts +155 -475
  252. package/src/hooks/use-air-jam-host.ts +156 -485
  253. package/src/hooks/use-connection-status.ts +8 -0
  254. package/src/hooks/use-controller-lifecycle-intents.ts +27 -0
  255. package/src/hooks/use-controller-lifecycle-permissions.ts +36 -0
  256. package/src/hooks/use-controller-shell-status.ts +40 -0
  257. package/src/hooks/use-controller-tick.ts +65 -0
  258. package/src/hooks/use-controller-toasts.ts +116 -0
  259. package/src/hooks/use-get-input.ts +8 -5
  260. package/src/hooks/use-host-arcade-restore.ts +30 -0
  261. package/src/hooks/use-host-join-controls.ts +152 -0
  262. package/src/hooks/use-host-tick.ts +171 -0
  263. package/src/hooks/use-input-writer.ts +83 -0
  264. package/src/hooks/use-lifecycle-action-group-model.ts +98 -0
  265. package/src/hooks/use-players.ts +12 -0
  266. package/src/hooks/use-room.ts +22 -0
  267. package/src/hooks/use-send-signal.ts +6 -2
  268. package/src/index.ts +205 -31
  269. package/src/internal/input-manager.ts +195 -215
  270. package/src/lifecycle/index.ts +9 -0
  271. package/src/lifecycle/standard-match-phase.ts +32 -0
  272. package/src/metadata/manifest.ts +152 -0
  273. package/src/metadata.ts +12 -0
  274. package/src/platform-machine.ts +475 -0
  275. package/src/prefabs/types.ts +82 -0
  276. package/src/prefabs.ts +12 -0
  277. package/src/preview/host-workspace.tsx +59 -0
  278. package/src/preview/identity.ts +66 -0
  279. package/src/preview/layout.ts +223 -0
  280. package/src/preview/manager.ts +577 -0
  281. package/src/preview/messages.ts +26 -0
  282. package/src/preview/ownership.ts +81 -0
  283. package/src/preview/url.ts +117 -0
  284. package/src/preview/window.tsx +490 -0
  285. package/src/preview/workspace.tsx +678 -0
  286. package/src/preview.ts +42 -0
  287. package/src/protocol/arcade-platform-actions.ts +29 -0
  288. package/src/protocol/controller.ts +187 -0
  289. package/src/protocol/core.ts +23 -0
  290. package/src/protocol/dev-log-events.ts +222 -0
  291. package/src/protocol/errors.ts +21 -0
  292. package/src/protocol/host-grant.ts +185 -0
  293. package/src/protocol/host.ts +138 -0
  294. package/src/protocol/notices.ts +43 -0
  295. package/src/protocol/signals.ts +38 -0
  296. package/src/protocol/socket-events.ts +154 -0
  297. package/src/protocol/sync.ts +121 -0
  298. package/src/protocol/url-policy.ts +63 -0
  299. package/src/protocol.ts +12 -386
  300. package/src/qrcode.d.ts +16 -0
  301. package/src/release.ts +99 -0
  302. package/src/runtime/air-jam-config.ts +287 -0
  303. package/src/runtime/air-jam-error-boundary.tsx +672 -0
  304. package/src/runtime/arcade-bridge-request-surface.ts +15 -0
  305. package/src/runtime/arcade-runtime-url.ts +95 -0
  306. package/src/runtime/arcade-surface-identity.ts +16 -0
  307. package/src/runtime/contracts/control.ts +68 -0
  308. package/src/runtime/contracts/inspection.ts +165 -0
  309. package/src/runtime/contracts/observability.ts +94 -0
  310. package/src/runtime/controller-bridge.ts +451 -0
  311. package/src/runtime/controller-identity.ts +132 -0
  312. package/src/runtime/controller-presentation.ts +24 -0
  313. package/src/runtime/controller-realtime-client.ts +591 -0
  314. package/src/runtime/create-air-jam-app.tsx +260 -0
  315. package/src/runtime/dev-runtime-events.ts +36 -0
  316. package/src/runtime/embedded-runtime-adapters.ts +68 -0
  317. package/src/runtime/host-bridge.ts +388 -0
  318. package/src/runtime/host-realtime-client.ts +550 -0
  319. package/src/runtime/iframe-bridge.ts +135 -0
  320. package/src/runtime/realtime-client.ts +20 -0
  321. package/src/runtime/router-basename.ts +25 -0
  322. package/src/runtime/runtime-owner-contexts.tsx +4 -0
  323. package/src/runtime/runtime-session-params.ts +169 -0
  324. package/src/runtime/sdk-version.ts +6 -0
  325. package/src/runtime/session-runtimes.tsx +188 -0
  326. package/src/runtime/validate-arcade-bridge-attach.ts +14 -0
  327. package/src/runtime-control.ts +10 -0
  328. package/src/runtime-inspection.ts +14 -0
  329. package/src/runtime-observability.ts +9 -0
  330. package/src/runtime-topology.ts +569 -0
  331. package/src/settings/platform-settings-bridge.ts +336 -0
  332. package/src/settings/platform-settings-runtime.tsx +387 -0
  333. package/src/settings/platform-settings.ts +288 -0
  334. package/src/state/connection-store.ts +80 -12
  335. package/src/store/air-jam-store-domain-constants.ts +4 -0
  336. package/src/store/create-air-jam-store.ts +1094 -227
  337. package/src/styles.css +4 -38
  338. package/src/ui.ts +29 -0
  339. package/src/utils/is-rpc-serializable.ts +56 -0
  340. package/src/utils/player-avatar-url.ts +48 -0
  341. package/src/utils/url-builder.ts +7 -0
  342. package/dist/.tsbuildinfo +0 -1
  343. package/dist/chunk-B5DURUWT.js +0 -80
  344. package/dist/chunk-B5DURUWT.js.map +0 -1
  345. package/src/AirJamClient.ts +0 -224
  346. package/src/audio/volume-store.ts +0 -124
  347. package/src/components/controller-shell.tsx +0 -346
  348. package/src/components/host-shell.tsx +0 -520
  349. package/src/components/qr-scanner-dialog.tsx +0 -373
  350. package/src/components/ui/alert.tsx +0 -66
  351. package/src/components/ui/avatar.tsx +0 -46
  352. package/src/components/ui/badge.tsx +0 -47
  353. package/src/components/ui/card.tsx +0 -92
  354. package/src/components/ui/dialog.tsx +0 -122
  355. package/src/components/ui/tabs.tsx +0 -64
  356. package/src/hooks/use-air-jam-shell.ts +0 -379
  357. package/src/hooks/use-fullscreen.ts +0 -108
@@ -0,0 +1,95 @@
1
+ import { AIR_JAM_DEFAULT_STORE_DOMAIN } from "../store/air-jam-store-domain-constants";
2
+ import type { ArcadeSurfaceRuntimeIdentity } from "./arcade-surface-identity";
3
+
4
+ /**
5
+ * Query param for the canonical replicated store domain in embedded runtimes.
6
+ * When set, {@link resolveImplicitReplicatedStoreDomainFromSearchParams} prefers it over derivation from `aj_arcade_*`.
7
+ */
8
+ export const AIRJAM_STORE_DOMAIN_URL_PARAM = "aj_store_domain";
9
+
10
+ const clampStoreDomain = (value: string): string =>
11
+ value.length > 128 ? value.slice(0, 128) : value;
12
+
13
+ /**
14
+ * Stable replicated store domain for an embedded Arcade surface identity (epoch-bound).
15
+ * Used for host/controller `createAirJamStore` in iframes so shell `default` and prior runs do not collide.
16
+ */
17
+ export const embeddedReplicatedStoreDomainFromArcadeIdentity = (
18
+ identity: ArcadeSurfaceRuntimeIdentity,
19
+ ): string => {
20
+ if (identity.kind === "game") {
21
+ const gameKey = identity.gameId ?? "_";
22
+ return clampStoreDomain(`aj.embedded.game:${identity.epoch}:${gameKey}`);
23
+ }
24
+ return clampStoreDomain(`aj.embedded.browser:${identity.epoch}`);
25
+ };
26
+
27
+ /**
28
+ * Query params used to pass {@link ArcadeSurfaceRuntimeIdentity} and replicated store domain into embedded iframes.
29
+ */
30
+ export const arcadeSurfaceRuntimeUrlParams = (
31
+ identity: ArcadeSurfaceRuntimeIdentity,
32
+ ): Record<string, string> => ({
33
+ aj_arcade_epoch: String(identity.epoch),
34
+ aj_arcade_kind: identity.kind,
35
+ ...(identity.gameId != null ? { aj_arcade_game_id: identity.gameId } : {}),
36
+ [AIRJAM_STORE_DOMAIN_URL_PARAM]:
37
+ embeddedReplicatedStoreDomainFromArcadeIdentity(identity),
38
+ });
39
+
40
+ export const parseOptionalArcadeSurfaceFromSearchParams = (
41
+ params: URLSearchParams,
42
+ ): ArcadeSurfaceRuntimeIdentity | undefined => {
43
+ const epochStr = params.get("aj_arcade_epoch");
44
+ const kind = params.get("aj_arcade_kind");
45
+ if (epochStr === null || (kind !== "browser" && kind !== "game")) {
46
+ return undefined;
47
+ }
48
+
49
+ const epoch = Number(epochStr);
50
+ if (!Number.isFinite(epoch) || epoch < 0 || !Number.isInteger(epoch)) {
51
+ return undefined;
52
+ }
53
+
54
+ const gameIdRaw = params.get("aj_arcade_game_id");
55
+ const gameId =
56
+ kind === "browser"
57
+ ? null
58
+ : gameIdRaw && gameIdRaw.length > 0
59
+ ? gameIdRaw
60
+ : null;
61
+
62
+ return { epoch, kind, gameId };
63
+ };
64
+
65
+ /**
66
+ * Resolves the implicit networked store domain from the current URL (embedded) or {@link AIR_JAM_DEFAULT_STORE_DOMAIN}.
67
+ * Prefer {@link AIRJAM_STORE_DOMAIN_URL_PARAM} when present; otherwise derive from `aj_arcade_*` when valid.
68
+ */
69
+ export const resolveImplicitReplicatedStoreDomainFromSearchParams = (
70
+ params: URLSearchParams,
71
+ ): string => {
72
+ const explicit = params.get(AIRJAM_STORE_DOMAIN_URL_PARAM)?.trim();
73
+ if (explicit && explicit.length > 0) {
74
+ return clampStoreDomain(explicit);
75
+ }
76
+
77
+ const surface = parseOptionalArcadeSurfaceFromSearchParams(params);
78
+ if (surface) {
79
+ return embeddedReplicatedStoreDomainFromArcadeIdentity(surface);
80
+ }
81
+
82
+ return AIR_JAM_DEFAULT_STORE_DOMAIN;
83
+ };
84
+
85
+ /**
86
+ * Browser-only resolver for implicit store domain (SSR-safe: returns default without `window`).
87
+ */
88
+ export const resolveImplicitReplicatedStoreDomainFromWindow = (): string => {
89
+ if (typeof window === "undefined") {
90
+ return AIR_JAM_DEFAULT_STORE_DOMAIN;
91
+ }
92
+ return resolveImplicitReplicatedStoreDomainFromSearchParams(
93
+ new URLSearchParams(window.location.search),
94
+ );
95
+ };
@@ -0,0 +1,16 @@
1
+ import { z } from "zod";
2
+
3
+ /**
4
+ * Minimum Arcade surface identity for embedded runtime bridge attach (see docs/systems/arcade-surface-contract.md).
5
+ */
6
+ export const arcadeSurfaceRuntimeIdentitySchema = z
7
+ .object({
8
+ epoch: z.number().int().nonnegative(),
9
+ kind: z.enum(["browser", "game"]),
10
+ gameId: z.string().nullable(),
11
+ })
12
+ .strict();
13
+
14
+ export type ArcadeSurfaceRuntimeIdentity = z.infer<
15
+ typeof arcadeSurfaceRuntimeIdentitySchema
16
+ >;
@@ -0,0 +1,68 @@
1
+ import type { AirJamControllerApi } from "../../hooks/use-air-jam-controller";
2
+ import type { AirJamHostApi } from "../../hooks/use-air-jam-host";
3
+ import type { PlayerProfilePatch, RuntimeState } from "../../protocol";
4
+
5
+ type HostControlApi = Pick<
6
+ AirJamHostApi,
7
+ | "runtimeState"
8
+ | "pauseRuntime"
9
+ | "resumeRuntime"
10
+ | "setRuntimeState"
11
+ | "sendSignal"
12
+ | "sendState"
13
+ | "reconnect"
14
+ >;
15
+
16
+ type ControllerControlApi = Pick<
17
+ AirJamControllerApi,
18
+ | "runtimeState"
19
+ | "sendSystemCommand"
20
+ | "setNickname"
21
+ | "setAvatarId"
22
+ | "updatePlayerProfile"
23
+ | "reconnect"
24
+ >;
25
+
26
+ export interface HostRuntimeControlContract {
27
+ role: "host";
28
+ reconnect: () => void;
29
+ setRuntimeState: (state: RuntimeState) => void;
30
+ pauseRuntime: () => void;
31
+ resumeRuntime: () => void;
32
+ sendState: HostControlApi["sendState"];
33
+ sendSignal: HostControlApi["sendSignal"];
34
+ }
35
+
36
+ export interface ControllerRuntimeControlContract {
37
+ role: "controller";
38
+ reconnect: () => void;
39
+ sendSystemCommand: ControllerControlApi["sendSystemCommand"];
40
+ setNicknameDraft: (value: string) => void;
41
+ setAvatarIdDraft: (value: string) => void;
42
+ updatePlayerProfile: (
43
+ patch: PlayerProfilePatch,
44
+ ) => ReturnType<ControllerControlApi["updatePlayerProfile"]>;
45
+ }
46
+
47
+ export const createHostRuntimeControlContract = (
48
+ api: HostControlApi,
49
+ ): HostRuntimeControlContract => ({
50
+ role: "host",
51
+ reconnect: api.reconnect,
52
+ setRuntimeState: api.setRuntimeState,
53
+ pauseRuntime: api.pauseRuntime,
54
+ resumeRuntime: api.resumeRuntime,
55
+ sendState: api.sendState,
56
+ sendSignal: api.sendSignal,
57
+ });
58
+
59
+ export const createControllerRuntimeControlContract = (
60
+ api: ControllerControlApi,
61
+ ): ControllerRuntimeControlContract => ({
62
+ role: "controller",
63
+ reconnect: api.reconnect,
64
+ sendSystemCommand: api.sendSystemCommand,
65
+ setNicknameDraft: api.setNickname,
66
+ setAvatarIdDraft: api.setAvatarId,
67
+ updatePlayerProfile: api.updatePlayerProfile,
68
+ });
@@ -0,0 +1,165 @@
1
+ import type { AirJamControllerApi } from "../../hooks/use-air-jam-controller";
2
+ import type {
3
+ AirJamHostApi,
4
+ JoinUrlStatus,
5
+ } from "../../hooks/use-air-jam-host";
6
+ import type {
7
+ ConnectionStatus,
8
+ ControllerOrientation,
9
+ ControllerPresenceNotice,
10
+ PlayerProfile,
11
+ RoomCode,
12
+ RunMode,
13
+ RuntimeState,
14
+ } from "../../protocol";
15
+
16
+ type HostInspectionApi = Pick<
17
+ AirJamHostApi,
18
+ | "roomId"
19
+ | "joinUrl"
20
+ | "joinUrlStatus"
21
+ | "connectionStatus"
22
+ | "players"
23
+ | "controllers"
24
+ | "lastError"
25
+ | "mode"
26
+ | "runtimeState"
27
+ >;
28
+
29
+ type ControllerInspectionApi = Pick<
30
+ AirJamControllerApi,
31
+ | "roomId"
32
+ | "controllerId"
33
+ | "connectionStatus"
34
+ | "lastError"
35
+ | "runtimeState"
36
+ | "controllerOrientation"
37
+ | "roomSettings"
38
+ | "stateMessage"
39
+ | "players"
40
+ | "selfPlayer"
41
+ >;
42
+
43
+ export interface HostRuntimeInspectionContract {
44
+ role: "host";
45
+ roomId: RoomCode;
46
+ joinUrl: string;
47
+ joinUrlStatus: JoinUrlStatus;
48
+ connectionStatus: ConnectionStatus;
49
+ players: readonly PlayerProfile[];
50
+ controllers: readonly ControllerPresenceNotice[];
51
+ lastError?: string;
52
+ mode: RunMode;
53
+ runtimeState: RuntimeState;
54
+ }
55
+
56
+ export interface ControllerRuntimeInspectionContract {
57
+ role: "controller";
58
+ roomId: RoomCode | null;
59
+ controllerId: string | null;
60
+ connectionStatus: ConnectionStatus;
61
+ players: readonly PlayerProfile[];
62
+ selfPlayer: PlayerProfile | null;
63
+ lastError?: string;
64
+ runtimeState: RuntimeState;
65
+ controllerOrientation: ControllerOrientation;
66
+ stateMessage?: string;
67
+ roomSettings: ControllerInspectionApi["roomSettings"];
68
+ }
69
+
70
+ export type RuntimeInspectionContract =
71
+ | HostRuntimeInspectionContract
72
+ | ControllerRuntimeInspectionContract;
73
+
74
+ export const AIR_JAM_RUNTIME_INSPECTION_KEY = "__airJamRuntimeInspection";
75
+
76
+ export const createHostRuntimeInspectionContract = (
77
+ api: HostInspectionApi,
78
+ ): HostRuntimeInspectionContract => ({
79
+ role: "host",
80
+ roomId: api.roomId,
81
+ joinUrl: api.joinUrl,
82
+ joinUrlStatus: api.joinUrlStatus,
83
+ connectionStatus: api.connectionStatus,
84
+ players: api.players,
85
+ controllers: api.controllers,
86
+ lastError: api.lastError,
87
+ mode: api.mode,
88
+ runtimeState: api.runtimeState,
89
+ });
90
+
91
+ export const createControllerRuntimeInspectionContract = (
92
+ api: ControllerInspectionApi,
93
+ ): ControllerRuntimeInspectionContract => ({
94
+ role: "controller",
95
+ roomId: api.roomId,
96
+ controllerId: api.controllerId,
97
+ connectionStatus: api.connectionStatus,
98
+ players: api.players,
99
+ selfPlayer: api.selfPlayer,
100
+ lastError: api.lastError,
101
+ runtimeState: api.runtimeState,
102
+ controllerOrientation: api.controllerOrientation,
103
+ stateMessage: api.stateMessage,
104
+ roomSettings: api.roomSettings,
105
+ });
106
+
107
+ const isRecord = (value: unknown): value is Record<string, unknown> =>
108
+ typeof value === "object" && value !== null;
109
+
110
+ const isHostRuntimeInspectionContract = (
111
+ value: unknown,
112
+ ): value is HostRuntimeInspectionContract =>
113
+ isRecord(value) &&
114
+ value.role === "host" &&
115
+ typeof value.roomId === "string" &&
116
+ typeof value.joinUrl === "string" &&
117
+ typeof value.joinUrlStatus === "string" &&
118
+ typeof value.connectionStatus === "string" &&
119
+ Array.isArray(value.players) &&
120
+ Array.isArray(value.controllers) &&
121
+ typeof value.mode === "string" &&
122
+ typeof value.runtimeState === "string";
123
+
124
+ const isControllerRuntimeInspectionContract = (
125
+ value: unknown,
126
+ ): value is ControllerRuntimeInspectionContract =>
127
+ isRecord(value) &&
128
+ value.role === "controller" &&
129
+ (typeof value.roomId === "string" || value.roomId === null) &&
130
+ (typeof value.controllerId === "string" || value.controllerId === null) &&
131
+ typeof value.connectionStatus === "string" &&
132
+ Array.isArray(value.players) &&
133
+ typeof value.runtimeState === "string" &&
134
+ typeof value.controllerOrientation === "string" &&
135
+ isRecord(value.roomSettings) &&
136
+ isRecord(value.roomSettings.audio) &&
137
+ isRecord(value.roomSettings.previewControllers);
138
+
139
+ export const readRuntimeInspectionContract = (
140
+ target: object,
141
+ ): RuntimeInspectionContract | null => {
142
+ const candidate = (target as Record<string, unknown>)[
143
+ AIR_JAM_RUNTIME_INSPECTION_KEY
144
+ ];
145
+ if (isHostRuntimeInspectionContract(candidate)) {
146
+ return candidate;
147
+ }
148
+ if (isControllerRuntimeInspectionContract(candidate)) {
149
+ return candidate;
150
+ }
151
+ return null;
152
+ };
153
+
154
+ export const publishRuntimeInspectionContract = (
155
+ target: object,
156
+ contract: RuntimeInspectionContract | null,
157
+ ): void => {
158
+ const hostTarget = target as Record<string, unknown>;
159
+ if (contract) {
160
+ hostTarget[AIR_JAM_RUNTIME_INSPECTION_KEY] = contract;
161
+ return;
162
+ }
163
+
164
+ delete hostTarget[AIR_JAM_RUNTIME_INSPECTION_KEY];
165
+ };
@@ -0,0 +1,94 @@
1
+ import type { AirJamDevLogEventName } from "../../protocol";
2
+ import {
3
+ AIRJAM_DEV_RUNTIME_EVENT,
4
+ type AirJamDevRuntimeEventDetail,
5
+ type AirJamDevRuntimeLogLevel,
6
+ } from "../dev-runtime-events";
7
+
8
+ export interface RuntimeObservabilityFilter {
9
+ events?: readonly AirJamDevLogEventName[];
10
+ levels?: readonly AirJamDevRuntimeLogLevel[];
11
+ role?: "host" | "controller";
12
+ roomId?: string;
13
+ controllerId?: string;
14
+ }
15
+
16
+ export interface RuntimeObservabilityEvent extends AirJamDevRuntimeEventDetail {
17
+ source: "runtime";
18
+ observedAt: string;
19
+ }
20
+
21
+ export type RuntimeObservabilityEventHandler = (
22
+ event: RuntimeObservabilityEvent,
23
+ ) => void;
24
+
25
+ const includes = <T>(values: readonly T[] | undefined, candidate: T): boolean =>
26
+ !values || values.includes(candidate);
27
+
28
+ export const createRuntimeObservabilityEvent = (
29
+ detail: AirJamDevRuntimeEventDetail,
30
+ observedAt = new Date().toISOString(),
31
+ ): RuntimeObservabilityEvent => ({
32
+ source: "runtime",
33
+ observedAt,
34
+ ...detail,
35
+ });
36
+
37
+ export const matchesRuntimeObservabilityFilter = (
38
+ event: RuntimeObservabilityEvent,
39
+ filter?: RuntimeObservabilityFilter,
40
+ ): boolean => {
41
+ if (!filter) {
42
+ return true;
43
+ }
44
+
45
+ if (!includes(filter.events, event.event)) {
46
+ return false;
47
+ }
48
+
49
+ if (event.level && !includes(filter.levels, event.level)) {
50
+ return false;
51
+ }
52
+
53
+ if (filter.role && event.role !== filter.role) {
54
+ return false;
55
+ }
56
+
57
+ if (filter.roomId && event.roomId !== filter.roomId) {
58
+ return false;
59
+ }
60
+
61
+ if (filter.controllerId && event.controllerId !== filter.controllerId) {
62
+ return false;
63
+ }
64
+
65
+ return true;
66
+ };
67
+
68
+ export const subscribeToRuntimeObservability = (
69
+ handler: RuntimeObservabilityEventHandler,
70
+ filter?: RuntimeObservabilityFilter,
71
+ ): (() => void) => {
72
+ if (typeof window === "undefined") {
73
+ return () => {};
74
+ }
75
+
76
+ const listener = (event: Event) => {
77
+ const detail = (event as CustomEvent<AirJamDevRuntimeEventDetail>).detail;
78
+ if (!detail) {
79
+ return;
80
+ }
81
+
82
+ const normalized = createRuntimeObservabilityEvent(detail);
83
+ if (!matchesRuntimeObservabilityFilter(normalized, filter)) {
84
+ return;
85
+ }
86
+
87
+ handler(normalized);
88
+ };
89
+
90
+ window.addEventListener(AIRJAM_DEV_RUNTIME_EVENT, listener);
91
+ return () => {
92
+ window.removeEventListener(AIRJAM_DEV_RUNTIME_EVENT, listener);
93
+ };
94
+ };