@air-jam/sdk 0.1.3 → 0.9.0

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 (348) 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 +488 -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 +13 -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 +363 -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 +28 -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 +1565 -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 +122 -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-2432OL7L.js +193 -0
  70. package/dist/chunk-2432OL7L.js.map +1 -0
  71. package/dist/chunk-2J65FXEP.js +41 -0
  72. package/dist/chunk-2J65FXEP.js.map +1 -0
  73. package/dist/chunk-32NYL7XI.js +539 -0
  74. package/dist/chunk-32NYL7XI.js.map +1 -0
  75. package/dist/chunk-3USU7GY2.js +54 -0
  76. package/dist/chunk-3USU7GY2.js.map +1 -0
  77. package/dist/chunk-BE6Z4SIT.js +65 -0
  78. package/dist/chunk-BE6Z4SIT.js.map +1 -0
  79. package/dist/chunk-CQUG24WX.js +249 -0
  80. package/dist/chunk-CQUG24WX.js.map +1 -0
  81. package/dist/chunk-D3X4MN4U.js +288 -0
  82. package/dist/chunk-D3X4MN4U.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-HFWRZVZ3.js +1438 -0
  86. package/dist/chunk-HFWRZVZ3.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-JTF47B56.js +1 -0
  90. package/dist/chunk-JTF47B56.js.map +1 -0
  91. package/dist/chunk-LIXPF4P6.js +22 -0
  92. package/dist/chunk-LIXPF4P6.js.map +1 -0
  93. package/dist/chunk-MKBASO6X.js +216 -0
  94. package/dist/chunk-MKBASO6X.js.map +1 -0
  95. package/dist/chunk-MPDMJIX5.js +1 -0
  96. package/dist/chunk-MPDMJIX5.js.map +1 -0
  97. package/dist/chunk-NCL6WJCL.js +91 -0
  98. package/dist/chunk-NCL6WJCL.js.map +1 -0
  99. package/dist/chunk-NU5W6VAV.js +126 -0
  100. package/dist/chunk-NU5W6VAV.js.map +1 -0
  101. package/dist/chunk-TGRTEWYV.js +195 -0
  102. package/dist/chunk-TGRTEWYV.js.map +1 -0
  103. package/dist/chunk-VDRNNGHX.js +184 -0
  104. package/dist/chunk-VDRNNGHX.js.map +1 -0
  105. package/dist/chunk-VN5LDWVN.js +32 -0
  106. package/dist/chunk-VN5LDWVN.js.map +1 -0
  107. package/dist/chunk-W2VK36RO.js +11 -0
  108. package/dist/chunk-W2VK36RO.js.map +1 -0
  109. package/dist/chunk-X24K52DG.js +12 -0
  110. package/dist/chunk-X24K52DG.js.map +1 -0
  111. package/dist/chunk-XLUWV45V.js +25 -0
  112. package/dist/chunk-XLUWV45V.js.map +1 -0
  113. package/dist/chunk-Y4RAPKKB.js +238 -0
  114. package/dist/chunk-Y4RAPKKB.js.map +1 -0
  115. package/dist/chunk-YXHH3MQT.js +230 -0
  116. package/dist/chunk-YXHH3MQT.js.map +1 -0
  117. package/dist/chunk-ZLPL2R3R.js +183 -0
  118. package/dist/chunk-ZLPL2R3R.js.map +1 -0
  119. package/dist/chunk-ZTQ5SP4H.js +9 -0
  120. package/dist/chunk-ZTQ5SP4H.js.map +1 -0
  121. package/dist/controller-Bod8YYr1.d.cts +172 -0
  122. package/dist/controller-DxVchfiA.d.ts +172 -0
  123. package/dist/dev-log-events-CVAM29hx.d.cts +123 -0
  124. package/dist/dev-log-events-CVAM29hx.d.ts +123 -0
  125. package/dist/handshake-CC_LrK5g.d.cts +31 -0
  126. package/dist/handshake-CC_LrK5g.d.ts +31 -0
  127. package/dist/host-8hmq_Sgc.d.cts +109 -0
  128. package/dist/host-Cw-N6e-5.d.ts +109 -0
  129. package/dist/index.cjs +8512 -3518
  130. package/dist/index.cjs.map +1 -1
  131. package/dist/index.d.cts +676 -1070
  132. package/dist/index.d.ts +676 -1070
  133. package/dist/index.js +4892 -3188
  134. package/dist/index.js.map +1 -1
  135. package/dist/metadata.cjs +114 -0
  136. package/dist/metadata.cjs.map +1 -0
  137. package/dist/metadata.d.cts +95 -0
  138. package/dist/metadata.d.ts +95 -0
  139. package/dist/metadata.js +83 -0
  140. package/dist/metadata.js.map +1 -0
  141. package/dist/notices-CnGaaS8B.d.ts +38 -0
  142. package/dist/notices-NyDM5Mtz.d.cts +38 -0
  143. package/dist/platform-machine.cjs +425 -0
  144. package/dist/platform-machine.cjs.map +1 -0
  145. package/dist/platform-machine.d.cts +1183 -0
  146. package/dist/platform-machine.d.ts +1183 -0
  147. package/dist/platform-machine.js +309 -0
  148. package/dist/platform-machine.js.map +1 -0
  149. package/dist/platform-settings-cuor3i11.d.cts +48 -0
  150. package/dist/platform-settings-cuor3i11.d.ts +48 -0
  151. package/dist/prefabs.cjs +36 -0
  152. package/dist/prefabs.cjs.map +1 -0
  153. package/dist/prefabs.d.cts +49 -0
  154. package/dist/prefabs.d.ts +49 -0
  155. package/dist/prefabs.js +8 -0
  156. package/dist/prefabs.js.map +1 -0
  157. package/dist/preview.cjs +2609 -0
  158. package/dist/preview.cjs.map +1 -0
  159. package/dist/preview.d.cts +155 -0
  160. package/dist/preview.d.ts +155 -0
  161. package/dist/preview.js +1671 -0
  162. package/dist/preview.js.map +1 -0
  163. package/dist/protocol.cjs +621 -54
  164. package/dist/protocol.cjs.map +1 -1
  165. package/dist/protocol.d.cts +76 -240
  166. package/dist/protocol.d.ts +76 -240
  167. package/dist/protocol.js +100 -2
  168. package/dist/protocol.js.map +1 -1
  169. package/dist/realtime-client-Cu8yVJFw.d.cts +15 -0
  170. package/dist/realtime-client-Cu8yVJFw.d.ts +15 -0
  171. package/dist/release.cjs +143 -0
  172. package/dist/release.cjs.map +1 -0
  173. package/dist/release.d.cts +64 -0
  174. package/dist/release.d.ts +64 -0
  175. package/dist/release.js +43 -0
  176. package/dist/release.js.map +1 -0
  177. package/dist/standard-match-phase-BucA5dYo.d.ts +44 -0
  178. package/dist/standard-match-phase-U2ra8J-0.d.cts +44 -0
  179. package/dist/sync-B6QsNrXz.d.cts +125 -0
  180. package/dist/sync-B6QsNrXz.d.ts +125 -0
  181. package/dist/ui.cjs +2827 -0
  182. package/dist/ui.cjs.map +1 -0
  183. package/dist/ui.d.cts +320 -0
  184. package/dist/ui.d.ts +320 -0
  185. package/dist/ui.js +1718 -0
  186. package/dist/ui.js.map +1 -0
  187. package/dist/url-policy-C89zxgw9.d.cts +9 -0
  188. package/dist/url-policy-C89zxgw9.d.ts +9 -0
  189. package/package.json +154 -13
  190. package/src/agent/agent-action.ts +304 -0
  191. package/src/agent/agent-contract.ts +180 -0
  192. package/src/agent-tooling.ts +20 -0
  193. package/src/arcade/bridge/controller.ts +15 -0
  194. package/src/arcade/bridge/host.ts +12 -0
  195. package/src/arcade/bridge/iframe.ts +61 -0
  196. package/src/arcade/bridge.ts +3 -0
  197. package/src/arcade/host.ts +1 -0
  198. package/src/arcade/surface.ts +4 -0
  199. package/src/arcade/url.ts +60 -0
  200. package/src/arcade.ts +4 -0
  201. package/src/audio/audio-manager.ts +162 -171
  202. package/src/audio/hooks.tsx +218 -97
  203. package/src/audio/index.ts +1 -1
  204. package/src/audio/music.tsx +139 -0
  205. package/src/capabilities/manifest.ts +71 -0
  206. package/src/capabilities.ts +12 -0
  207. package/src/components/connection-status-pill.tsx +55 -0
  208. package/src/components/controller-player-name-field.tsx +119 -0
  209. package/src/components/controller-primary-action.tsx +58 -0
  210. package/src/components/host-mute-button.tsx +49 -0
  211. package/src/components/join-qr-overlay.tsx +133 -0
  212. package/src/components/join-url-action-buttons.tsx +95 -0
  213. package/src/components/join-url-controls.tsx +58 -0
  214. package/src/components/join-url-field.tsx +52 -0
  215. package/src/components/lifecycle-action-group.tsx +129 -0
  216. package/src/components/player-avatar-strip.tsx +65 -0
  217. package/src/components/player-avatar.tsx +42 -14
  218. package/src/components/room-qr-code.tsx +125 -0
  219. package/src/components/runtime-shell-header.tsx +37 -0
  220. package/src/components/shell-classes.ts +19 -0
  221. package/src/components/surface-orientation-layout.ts +60 -0
  222. package/src/components/surface-viewport-layout.ts +268 -0
  223. package/src/components/surface-viewport.tsx +314 -0
  224. package/src/components/ui/button.tsx +4 -6
  225. package/src/components/ui/slider.tsx +1 -1
  226. package/src/components/volume-controls.tsx +65 -6
  227. package/src/context/air-jam-context.tsx +209 -141
  228. package/src/context/index.ts +2 -2
  229. package/src/context/session-providers.tsx +77 -0
  230. package/src/context/session-scope.ts +64 -0
  231. package/src/context/socket-manager.ts +6 -25
  232. package/src/contracts/v2/bridge.ts +261 -0
  233. package/src/contracts/v2/handshake.ts +40 -0
  234. package/src/contracts/v2/index.ts +2 -0
  235. package/src/dev/browser-log-sink.ts +912 -0
  236. package/src/diagnostics.ts +128 -0
  237. package/src/events.ts +7 -34
  238. package/src/hooks/internal/use-controller-runtime-api.ts +875 -0
  239. package/src/hooks/internal/use-host-runtime-api.ts +1051 -0
  240. package/src/hooks/internal/use-runtime-control-contract.ts +15 -0
  241. package/src/hooks/internal/use-runtime-inspection-contract.ts +16 -0
  242. package/src/hooks/internal/use-runtime-observability-contract.ts +24 -0
  243. package/src/hooks/use-air-jam-controller.ts +155 -475
  244. package/src/hooks/use-air-jam-host.ts +156 -485
  245. package/src/hooks/use-connection-status.ts +8 -0
  246. package/src/hooks/use-controller-lifecycle-intents.ts +27 -0
  247. package/src/hooks/use-controller-lifecycle-permissions.ts +36 -0
  248. package/src/hooks/use-controller-shell-status.ts +40 -0
  249. package/src/hooks/use-controller-tick.ts +65 -0
  250. package/src/hooks/use-controller-toasts.ts +116 -0
  251. package/src/hooks/use-get-input.ts +8 -5
  252. package/src/hooks/use-host-arcade-restore.ts +30 -0
  253. package/src/hooks/use-host-join-controls.ts +152 -0
  254. package/src/hooks/use-host-tick.ts +171 -0
  255. package/src/hooks/use-input-writer.ts +83 -0
  256. package/src/hooks/use-lifecycle-action-group-model.ts +98 -0
  257. package/src/hooks/use-players.ts +12 -0
  258. package/src/hooks/use-room.ts +22 -0
  259. package/src/hooks/use-send-signal.ts +6 -2
  260. package/src/index.ts +205 -31
  261. package/src/internal/input-manager.ts +195 -215
  262. package/src/lifecycle/index.ts +9 -0
  263. package/src/lifecycle/standard-match-phase.ts +32 -0
  264. package/src/metadata/manifest.ts +152 -0
  265. package/src/metadata.ts +12 -0
  266. package/src/platform-machine.ts +475 -0
  267. package/src/prefabs/types.ts +82 -0
  268. package/src/prefabs.ts +12 -0
  269. package/src/preview/host-workspace.tsx +59 -0
  270. package/src/preview/identity.ts +66 -0
  271. package/src/preview/layout.ts +223 -0
  272. package/src/preview/manager.ts +577 -0
  273. package/src/preview/messages.ts +26 -0
  274. package/src/preview/ownership.ts +81 -0
  275. package/src/preview/url.ts +117 -0
  276. package/src/preview/window.tsx +490 -0
  277. package/src/preview/workspace.tsx +678 -0
  278. package/src/preview.ts +42 -0
  279. package/src/protocol/arcade-platform-actions.ts +29 -0
  280. package/src/protocol/controller.ts +187 -0
  281. package/src/protocol/core.ts +23 -0
  282. package/src/protocol/dev-log-events.ts +222 -0
  283. package/src/protocol/errors.ts +21 -0
  284. package/src/protocol/host-grant.ts +185 -0
  285. package/src/protocol/host.ts +138 -0
  286. package/src/protocol/notices.ts +43 -0
  287. package/src/protocol/signals.ts +38 -0
  288. package/src/protocol/socket-events.ts +154 -0
  289. package/src/protocol/sync.ts +121 -0
  290. package/src/protocol/url-policy.ts +63 -0
  291. package/src/protocol.ts +12 -386
  292. package/src/qrcode.d.ts +16 -0
  293. package/src/release.ts +99 -0
  294. package/src/runtime/air-jam-config.ts +287 -0
  295. package/src/runtime/air-jam-error-boundary.tsx +672 -0
  296. package/src/runtime/arcade-bridge-request-surface.ts +15 -0
  297. package/src/runtime/arcade-runtime-url.ts +95 -0
  298. package/src/runtime/arcade-surface-identity.ts +16 -0
  299. package/src/runtime/contracts/control.ts +68 -0
  300. package/src/runtime/contracts/inspection.ts +165 -0
  301. package/src/runtime/contracts/observability.ts +94 -0
  302. package/src/runtime/controller-bridge.ts +451 -0
  303. package/src/runtime/controller-identity.ts +132 -0
  304. package/src/runtime/controller-presentation.ts +24 -0
  305. package/src/runtime/controller-realtime-client.ts +591 -0
  306. package/src/runtime/create-air-jam-app.tsx +260 -0
  307. package/src/runtime/dev-runtime-events.ts +36 -0
  308. package/src/runtime/embedded-runtime-adapters.ts +68 -0
  309. package/src/runtime/host-bridge.ts +388 -0
  310. package/src/runtime/host-realtime-client.ts +550 -0
  311. package/src/runtime/iframe-bridge.ts +135 -0
  312. package/src/runtime/realtime-client.ts +20 -0
  313. package/src/runtime/router-basename.ts +25 -0
  314. package/src/runtime/runtime-owner-contexts.tsx +4 -0
  315. package/src/runtime/runtime-session-params.ts +169 -0
  316. package/src/runtime/sdk-version.ts +6 -0
  317. package/src/runtime/session-runtimes.tsx +188 -0
  318. package/src/runtime/validate-arcade-bridge-attach.ts +14 -0
  319. package/src/runtime-control.ts +10 -0
  320. package/src/runtime-inspection.ts +14 -0
  321. package/src/runtime-observability.ts +9 -0
  322. package/src/settings/platform-settings-bridge.ts +336 -0
  323. package/src/settings/platform-settings-runtime.tsx +387 -0
  324. package/src/settings/platform-settings.ts +288 -0
  325. package/src/state/connection-store.ts +80 -12
  326. package/src/store/air-jam-store-domain-constants.ts +4 -0
  327. package/src/store/create-air-jam-store.ts +1094 -227
  328. package/src/styles.css +4 -38
  329. package/src/ui.ts +29 -0
  330. package/src/utils/is-rpc-serializable.ts +56 -0
  331. package/src/utils/player-avatar-url.ts +48 -0
  332. package/src/utils/url-builder.ts +7 -0
  333. package/dist/.tsbuildinfo +0 -1
  334. package/dist/chunk-B5DURUWT.js +0 -80
  335. package/dist/chunk-B5DURUWT.js.map +0 -1
  336. package/src/AirJamClient.ts +0 -224
  337. package/src/audio/volume-store.ts +0 -124
  338. package/src/components/controller-shell.tsx +0 -346
  339. package/src/components/host-shell.tsx +0 -521
  340. package/src/components/qr-scanner-dialog.tsx +0 -373
  341. package/src/components/ui/alert.tsx +0 -66
  342. package/src/components/ui/avatar.tsx +0 -46
  343. package/src/components/ui/badge.tsx +0 -47
  344. package/src/components/ui/card.tsx +0 -92
  345. package/src/components/ui/dialog.tsx +0 -122
  346. package/src/components/ui/tabs.tsx +0 -64
  347. package/src/hooks/use-air-jam-shell.ts +0 -379
  348. package/src/hooks/use-fullscreen.ts +0 -108
@@ -0,0 +1,672 @@
1
+ import {
2
+ Check,
3
+ Copy,
4
+ Maximize2,
5
+ Minimize2,
6
+ RefreshCw,
7
+ RotateCcw,
8
+ } from "lucide-react";
9
+ import type { CSSProperties, ErrorInfo, JSX, ReactNode } from "react";
10
+ import { Component, useCallback, useEffect, useRef, useState } from "react";
11
+ import { emitAirJamDiagnostic } from "../diagnostics";
12
+ import { AIRJAM_DEV_LOG_EVENTS } from "../protocol";
13
+ import { emitAirJamDevRuntimeEvent } from "./dev-runtime-events";
14
+
15
+ export type AirJamRuntimeRole = "host" | "controller";
16
+
17
+ interface AirJamRuntimeErrorContext {
18
+ role: AirJamRuntimeRole;
19
+ roomId?: string;
20
+ appId?: string;
21
+ }
22
+
23
+ export interface AirJamErrorFallbackRenderProps extends AirJamRuntimeErrorContext {
24
+ error: Error;
25
+ reset: () => void;
26
+ reload: () => void;
27
+ isEmbedded: boolean;
28
+ }
29
+
30
+ export type AirJamErrorFallbackRenderer = (
31
+ props: AirJamErrorFallbackRenderProps,
32
+ ) => JSX.Element;
33
+
34
+ export interface AirJamErrorBoundaryProps extends AirJamRuntimeErrorContext {
35
+ children: ReactNode;
36
+ renderFallback?: AirJamErrorFallbackRenderer;
37
+ onError?: (
38
+ error: Error,
39
+ errorInfo: ErrorInfo,
40
+ context: AirJamRuntimeErrorContext,
41
+ ) => void;
42
+ }
43
+
44
+ interface AirJamErrorBoundaryState {
45
+ error: Error | null;
46
+ }
47
+
48
+ const toError = (value: unknown): Error => {
49
+ if (value instanceof Error) {
50
+ return value;
51
+ }
52
+ if (typeof value === "string") {
53
+ return new Error(value);
54
+ }
55
+ return new Error("Unknown runtime error");
56
+ };
57
+
58
+ const isEmbeddedRuntime = (): boolean =>
59
+ typeof window !== "undefined" &&
60
+ typeof window.parent !== "undefined" &&
61
+ window.parent !== window;
62
+
63
+ const roleLabel = (role: AirJamRuntimeRole): string =>
64
+ role === "host" ? "Host runtime" : "Controller runtime";
65
+
66
+ const mono =
67
+ "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, monospace";
68
+
69
+ const errorSurface = {
70
+ bg: "#0a0a0a",
71
+ panel: "#141414",
72
+ panelBorder: "rgba(255, 255, 255, 0.08)",
73
+ inset: "#0c0c0c",
74
+ insetBorder: "rgba(255, 255, 255, 0.06)",
75
+ text: "#fafafa",
76
+ muted: "#a3a3a3",
77
+ dim: "#737373",
78
+ zOverlay: 2147483000,
79
+ } as const;
80
+
81
+ const iconSize = 16;
82
+
83
+ const createErrorDigest = (error: Error): string => {
84
+ const input = `${error.name}:${error.message}:${error.stack ?? ""}`;
85
+ let hash = 0;
86
+ for (let index = 0; index < input.length; index += 1) {
87
+ hash = (hash * 31 + input.charCodeAt(index)) >>> 0;
88
+ }
89
+ return hash.toString(16).padStart(8, "0");
90
+ };
91
+
92
+ const copyTextToClipboard = async (text: string): Promise<void> => {
93
+ if (
94
+ typeof navigator !== "undefined" &&
95
+ navigator.clipboard &&
96
+ typeof navigator.clipboard.writeText === "function"
97
+ ) {
98
+ await navigator.clipboard.writeText(text);
99
+ return;
100
+ }
101
+
102
+ if (typeof document === "undefined") {
103
+ throw new Error("Clipboard is unavailable");
104
+ }
105
+
106
+ const textarea = document.createElement("textarea");
107
+ textarea.value = text;
108
+ textarea.style.position = "fixed";
109
+ textarea.style.opacity = "0";
110
+ textarea.style.pointerEvents = "none";
111
+ document.body.appendChild(textarea);
112
+ textarea.focus();
113
+ textarea.select();
114
+
115
+ const succeeded =
116
+ typeof document.execCommand === "function"
117
+ ? document.execCommand("copy")
118
+ : false;
119
+
120
+ document.body.removeChild(textarea);
121
+
122
+ if (!succeeded) {
123
+ throw new Error("Copy command failed");
124
+ }
125
+ };
126
+
127
+ const createCopyPayload = ({
128
+ role,
129
+ roomId,
130
+ appId,
131
+ error,
132
+ digest,
133
+ isEmbedded,
134
+ }: {
135
+ role: AirJamRuntimeRole;
136
+ roomId?: string;
137
+ appId?: string;
138
+ error: Error;
139
+ digest: string;
140
+ isEmbedded: boolean;
141
+ }): string => {
142
+ const lines = [
143
+ "AirJam Runtime Error",
144
+ `Role: ${role}`,
145
+ `Digest: ${digest}`,
146
+ `Embedded: ${isEmbedded ? "yes" : "no"}`,
147
+ roomId ? `Room: ${roomId}` : null,
148
+ appId ? `App ID: ${appId}` : null,
149
+ `Error: ${error.message || "Unknown error"}`,
150
+ "",
151
+ "Stack:",
152
+ error.stack ?? "(no stack)",
153
+ ].filter((line): line is string => line !== null);
154
+
155
+ return lines.join("\n");
156
+ };
157
+
158
+ const btnRow: CSSProperties = {
159
+ display: "inline-flex",
160
+ alignItems: "center",
161
+ justifyContent: "center",
162
+ gap: "0.35rem",
163
+ borderRadius: "0.5rem",
164
+ padding: "0.5rem 0.75rem",
165
+ fontSize: "0.8125rem",
166
+ fontWeight: 600,
167
+ cursor: "pointer",
168
+ fontFamily:
169
+ "ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif",
170
+ };
171
+
172
+ const DefaultFallback = ({
173
+ role,
174
+ roomId,
175
+ appId,
176
+ error,
177
+ reset,
178
+ reload,
179
+ isEmbedded,
180
+ }: AirJamErrorFallbackRenderProps): JSX.Element => {
181
+ const digest = createErrorDigest(error);
182
+ const [isMinimized, setIsMinimized] = useState(false);
183
+ const [copyState, setCopyState] = useState<"idle" | "copied" | "failed">(
184
+ "idle",
185
+ );
186
+ const copyResetTimeoutRef = useRef<number | null>(null);
187
+
188
+ useEffect(() => {
189
+ return () => {
190
+ if (
191
+ copyResetTimeoutRef.current !== null &&
192
+ typeof window !== "undefined"
193
+ ) {
194
+ window.clearTimeout(copyResetTimeoutRef.current);
195
+ }
196
+ };
197
+ }, []);
198
+
199
+ const scheduleCopyStatusReset = useCallback(() => {
200
+ if (typeof window === "undefined") {
201
+ return;
202
+ }
203
+ if (copyResetTimeoutRef.current !== null) {
204
+ window.clearTimeout(copyResetTimeoutRef.current);
205
+ }
206
+ copyResetTimeoutRef.current = window.setTimeout(() => {
207
+ setCopyState("idle");
208
+ copyResetTimeoutRef.current = null;
209
+ }, 1800);
210
+ }, []);
211
+
212
+ const handleCopy = useCallback(async () => {
213
+ try {
214
+ await copyTextToClipboard(
215
+ createCopyPayload({
216
+ role,
217
+ roomId,
218
+ appId,
219
+ error,
220
+ isEmbedded,
221
+ digest,
222
+ }),
223
+ );
224
+ setCopyState("copied");
225
+ scheduleCopyStatusReset();
226
+ } catch {
227
+ setCopyState("failed");
228
+ scheduleCopyStatusReset();
229
+ }
230
+ }, [appId, digest, error, isEmbedded, role, roomId, scheduleCopyStatusReset]);
231
+
232
+ const copyButtonLabel =
233
+ copyState === "copied"
234
+ ? "Copied"
235
+ : copyState === "failed"
236
+ ? "Copy failed"
237
+ : "Copy details";
238
+
239
+ const CopyGlyph =
240
+ copyState === "copied" ? (
241
+ <Check size={iconSize} strokeWidth={2} aria-hidden />
242
+ ) : (
243
+ <Copy size={iconSize} strokeWidth={2} aria-hidden />
244
+ );
245
+
246
+ if (isMinimized) {
247
+ return (
248
+ <>
249
+ <div
250
+ aria-hidden
251
+ style={{
252
+ position: "fixed",
253
+ inset: 0,
254
+ zIndex: errorSurface.zOverlay,
255
+ background: "rgba(10, 10, 10, 0.72)",
256
+ }}
257
+ />
258
+ <div
259
+ style={{
260
+ position: "fixed",
261
+ bottom: "1rem",
262
+ right: "1rem",
263
+ zIndex: errorSurface.zOverlay + 1,
264
+ maxWidth: "min(22rem, calc(100vw - 2rem))",
265
+ borderRadius: "0.625rem",
266
+ border: `1px solid ${errorSurface.panelBorder}`,
267
+ background: errorSurface.panel,
268
+ boxShadow: "0 16px 48px rgba(0, 0, 0, 0.55)",
269
+ padding: "0.75rem 0.85rem",
270
+ }}
271
+ >
272
+ <div
273
+ style={{
274
+ display: "flex",
275
+ alignItems: "flex-start",
276
+ justifyContent: "space-between",
277
+ gap: "0.5rem",
278
+ }}
279
+ >
280
+ <div style={{ minWidth: 0 }}>
281
+ <div
282
+ style={{
283
+ fontSize: "0.6875rem",
284
+ fontWeight: 600,
285
+ letterSpacing: "0.02em",
286
+ color: errorSurface.dim,
287
+ textTransform: "uppercase",
288
+ }}
289
+ >
290
+ AirJam · runtime error
291
+ </div>
292
+ <div
293
+ style={{
294
+ marginTop: "0.25rem",
295
+ fontSize: "0.75rem",
296
+ color: errorSurface.muted,
297
+ fontFamily: mono,
298
+ lineHeight: 1.4,
299
+ wordBreak: "break-word",
300
+ }}
301
+ >
302
+ {role} · {digest}
303
+ </div>
304
+ </div>
305
+ <button
306
+ type="button"
307
+ onClick={() => setIsMinimized(false)}
308
+ aria-label="Expand error panel"
309
+ title="Expand error panel"
310
+ style={{
311
+ ...btnRow,
312
+ flexShrink: 0,
313
+ border: `1px solid ${errorSurface.panelBorder}`,
314
+ background: errorSurface.inset,
315
+ color: errorSurface.text,
316
+ padding: "0.4rem",
317
+ }}
318
+ >
319
+ <Maximize2 size={iconSize} strokeWidth={2} aria-hidden />
320
+ </button>
321
+ </div>
322
+ <div
323
+ style={{
324
+ marginTop: "0.65rem",
325
+ display: "flex",
326
+ flexWrap: "wrap",
327
+ gap: "0.4rem",
328
+ }}
329
+ >
330
+ <button
331
+ type="button"
332
+ onClick={() => {
333
+ void handleCopy();
334
+ }}
335
+ style={{
336
+ ...btnRow,
337
+ border: `1px solid ${errorSurface.panelBorder}`,
338
+ background: "transparent",
339
+ color: errorSurface.muted,
340
+ }}
341
+ >
342
+ {CopyGlyph}
343
+ {copyButtonLabel}
344
+ </button>
345
+ <button
346
+ type="button"
347
+ onClick={reload}
348
+ style={{
349
+ ...btnRow,
350
+ border: "none",
351
+ background: errorSurface.text,
352
+ color: errorSurface.bg,
353
+ }}
354
+ >
355
+ <RefreshCw size={iconSize} strokeWidth={2} aria-hidden />
356
+ Reload
357
+ </button>
358
+ </div>
359
+ </div>
360
+ </>
361
+ );
362
+ }
363
+
364
+ return (
365
+ <div
366
+ style={{
367
+ minHeight: "100vh",
368
+ width: "100%",
369
+ display: "flex",
370
+ alignItems: "center",
371
+ justifyContent: "center",
372
+ background: errorSurface.bg,
373
+ padding: "1.5rem 1rem",
374
+ boxSizing: "border-box",
375
+ }}
376
+ >
377
+ <div
378
+ style={{
379
+ position: "relative",
380
+ width: "100%",
381
+ maxWidth: "42rem",
382
+ borderRadius: "0.625rem",
383
+ border: `1px solid ${errorSurface.panelBorder}`,
384
+ background: errorSurface.panel,
385
+ boxShadow: "0 24px 64px rgba(0, 0, 0, 0.45)",
386
+ padding: "1.25rem 1.35rem",
387
+ boxSizing: "border-box",
388
+ }}
389
+ >
390
+ <button
391
+ type="button"
392
+ onClick={() => setIsMinimized(true)}
393
+ aria-label="Minimize error panel"
394
+ title="Minimize error panel"
395
+ style={{
396
+ ...btnRow,
397
+ position: "absolute",
398
+ top: "0.85rem",
399
+ right: "0.85rem",
400
+ padding: "0.4rem",
401
+ border: `1px solid ${errorSurface.panelBorder}`,
402
+ background: errorSurface.inset,
403
+ color: errorSurface.muted,
404
+ }}
405
+ >
406
+ <Minimize2 size={iconSize} strokeWidth={2} aria-hidden />
407
+ </button>
408
+
409
+ <div
410
+ style={{
411
+ fontSize: "0.6875rem",
412
+ fontWeight: 500,
413
+ letterSpacing: "0.04em",
414
+ color: errorSurface.dim,
415
+ textTransform: "uppercase",
416
+ paddingRight: "2.5rem",
417
+ }}
418
+ >
419
+ AirJam · runtime error · {role}
420
+ </div>
421
+
422
+ <h1
423
+ style={{
424
+ marginTop: "0.65rem",
425
+ marginBottom: 0,
426
+ fontSize: "1.25rem",
427
+ lineHeight: 1.25,
428
+ fontWeight: 600,
429
+ color: errorSurface.text,
430
+ fontFamily:
431
+ "ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif",
432
+ }}
433
+ >
434
+ Something went wrong
435
+ </h1>
436
+
437
+ <p
438
+ style={{
439
+ marginTop: "0.45rem",
440
+ marginBottom: 0,
441
+ fontSize: "0.8125rem",
442
+ color: errorSurface.muted,
443
+ lineHeight: 1.45,
444
+ }}
445
+ >
446
+ {roleLabel(role)} hit an error. Details below.
447
+ </p>
448
+
449
+ <div
450
+ style={{
451
+ marginTop: "1rem",
452
+ border: `1px solid ${errorSurface.insetBorder}`,
453
+ borderRadius: "0.5rem",
454
+ background: errorSurface.inset,
455
+ padding: "0.75rem 0.85rem",
456
+ fontSize: "0.75rem",
457
+ color: errorSurface.muted,
458
+ fontFamily: mono,
459
+ lineHeight: 1.5,
460
+ wordBreak: "break-word",
461
+ }}
462
+ >
463
+ <div>
464
+ <span style={{ color: errorSurface.dim }}>Digest </span>
465
+ {digest}
466
+ </div>
467
+ {roomId ? (
468
+ <div style={{ marginTop: "0.35rem" }}>
469
+ <span style={{ color: errorSurface.dim }}>Room </span>
470
+ {roomId}
471
+ </div>
472
+ ) : null}
473
+ <div style={{ marginTop: "0.35rem" }}>
474
+ <span style={{ color: errorSurface.dim }}>Error </span>
475
+ {error.message || "Unknown error"}
476
+ </div>
477
+ </div>
478
+
479
+ <details
480
+ style={{
481
+ marginTop: "0.75rem",
482
+ fontSize: "0.75rem",
483
+ color: errorSurface.muted,
484
+ }}
485
+ >
486
+ <summary
487
+ style={{
488
+ cursor: "pointer",
489
+ fontWeight: 500,
490
+ color: errorSurface.muted,
491
+ listStyle: "none",
492
+ }}
493
+ >
494
+ Stack trace
495
+ </summary>
496
+ <pre
497
+ style={{
498
+ marginTop: "0.5rem",
499
+ marginBottom: 0,
500
+ overflowX: "auto",
501
+ whiteSpace: "pre-wrap",
502
+ wordBreak: "break-word",
503
+ border: `1px solid ${errorSurface.insetBorder}`,
504
+ borderRadius: "0.45rem",
505
+ background: errorSurface.inset,
506
+ padding: "0.65rem 0.75rem",
507
+ color: errorSurface.muted,
508
+ fontFamily: mono,
509
+ fontSize: "0.6875rem",
510
+ lineHeight: 1.45,
511
+ }}
512
+ >
513
+ {error.stack ?? error.message}
514
+ </pre>
515
+ </details>
516
+
517
+ <div
518
+ style={{
519
+ marginTop: "1.1rem",
520
+ display: "flex",
521
+ flexWrap: "wrap",
522
+ alignItems: "center",
523
+ gap: "0.45rem",
524
+ }}
525
+ >
526
+ <button
527
+ type="button"
528
+ onClick={reload}
529
+ style={{
530
+ ...btnRow,
531
+ border: "none",
532
+ background: errorSurface.text,
533
+ color: errorSurface.bg,
534
+ }}
535
+ >
536
+ <RefreshCw size={iconSize} strokeWidth={2} aria-hidden />
537
+ Reload
538
+ </button>
539
+ <button
540
+ type="button"
541
+ onClick={reset}
542
+ style={{
543
+ ...btnRow,
544
+ border: `1px solid ${errorSurface.panelBorder}`,
545
+ background: "transparent",
546
+ color: errorSurface.text,
547
+ }}
548
+ >
549
+ <RotateCcw size={iconSize} strokeWidth={2} aria-hidden />
550
+ Try again
551
+ </button>
552
+ <button
553
+ type="button"
554
+ onClick={() => {
555
+ void handleCopy();
556
+ }}
557
+ style={{
558
+ ...btnRow,
559
+ border: `1px solid ${errorSurface.panelBorder}`,
560
+ background: "transparent",
561
+ color: errorSurface.muted,
562
+ }}
563
+ >
564
+ {CopyGlyph}
565
+ {copyButtonLabel}
566
+ </button>
567
+ </div>
568
+
569
+ {isEmbedded ? (
570
+ <p
571
+ style={{
572
+ marginTop: "0.85rem",
573
+ marginBottom: 0,
574
+ fontSize: "0.6875rem",
575
+ color: errorSurface.dim,
576
+ lineHeight: 1.4,
577
+ fontFamily: mono,
578
+ }}
579
+ >
580
+ Embedded: if reload loops, exit and relaunch from the Arcade shell.
581
+ </p>
582
+ ) : null}
583
+ </div>
584
+ </div>
585
+ );
586
+ };
587
+
588
+ export class AirJamErrorBoundary extends Component<
589
+ AirJamErrorBoundaryProps,
590
+ AirJamErrorBoundaryState
591
+ > {
592
+ public state: AirJamErrorBoundaryState = {
593
+ error: null,
594
+ };
595
+
596
+ static getDerivedStateFromError(error: unknown): AirJamErrorBoundaryState {
597
+ return {
598
+ error: toError(error),
599
+ };
600
+ }
601
+
602
+ componentDidCatch(error: Error, errorInfo: ErrorInfo): void {
603
+ const { role, roomId, appId, onError } = this.props;
604
+ const details = {
605
+ role,
606
+ roomId,
607
+ appId,
608
+ name: error.name,
609
+ message: error.message,
610
+ stack: error.stack,
611
+ componentStack: errorInfo.componentStack,
612
+ };
613
+
614
+ emitAirJamDiagnostic({
615
+ code: "AJ_RUNTIME_RENDER_CRASH",
616
+ severity: "error",
617
+ message: `[AirJam] ${role} runtime crashed during render.`,
618
+ details,
619
+ });
620
+
621
+ emitAirJamDevRuntimeEvent({
622
+ event: AIRJAM_DEV_LOG_EVENTS.browser.runtime,
623
+ level: "error",
624
+ message: `AirJam ${role} runtime crashed during render`,
625
+ role,
626
+ roomId,
627
+ code: "AJ_RUNTIME_RENDER_CRASH",
628
+ data: details,
629
+ });
630
+
631
+ onError?.(error, errorInfo, {
632
+ role,
633
+ roomId,
634
+ appId,
635
+ });
636
+ }
637
+
638
+ private handleReset = (): void => {
639
+ this.setState({ error: null });
640
+ };
641
+
642
+ private handleReload = (): void => {
643
+ if (typeof window !== "undefined") {
644
+ window.location.reload();
645
+ }
646
+ };
647
+
648
+ render(): JSX.Element {
649
+ const { error } = this.state;
650
+ const { children, role, roomId, appId, renderFallback } = this.props;
651
+
652
+ if (!error) {
653
+ return <>{children}</>;
654
+ }
655
+
656
+ const fallbackProps: AirJamErrorFallbackRenderProps = {
657
+ role,
658
+ roomId,
659
+ appId,
660
+ error,
661
+ reset: this.handleReset,
662
+ reload: this.handleReload,
663
+ isEmbedded: isEmbeddedRuntime(),
664
+ };
665
+
666
+ if (renderFallback) {
667
+ return renderFallback(fallbackProps);
668
+ }
669
+
670
+ return <DefaultFallback {...fallbackProps} />;
671
+ }
672
+ }
@@ -0,0 +1,15 @@
1
+ import type { ArcadeSurfaceRuntimeIdentity } from "./arcade-surface-identity";
2
+
3
+ /**
4
+ * Returns true when the iframe surface identity does not match the parent's active surface.
5
+ */
6
+ export const isArcadeSurfaceMismatch = (
7
+ active: ArcadeSurfaceRuntimeIdentity,
8
+ request: ArcadeSurfaceRuntimeIdentity,
9
+ ): boolean => {
10
+ return (
11
+ request.epoch !== active.epoch ||
12
+ request.kind !== active.kind ||
13
+ request.gameId !== active.gameId
14
+ );
15
+ };