@air-jam/sdk 0.9.3 → 1.0.0-beta.2
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.
- package/README.md +168 -205
- package/dist/actions-D4eh6Xaa.d.cts +72 -0
- package/dist/actions-D4eh6Xaa.d.ts +72 -0
- package/dist/{agent-contract-CD2QnbBJ.d.cts → agent-contract-BMvCMvhE.d.ts} +3 -19
- package/dist/{agent-contract-CD2QnbBJ.d.ts → agent-contract-DtYf3ici.d.cts} +3 -19
- package/dist/agent-tooling.cjs +135 -46
- package/dist/agent-tooling.cjs.map +1 -1
- package/dist/agent-tooling.d.cts +96 -5
- package/dist/agent-tooling.d.ts +96 -5
- package/dist/agent-tooling.js +15 -14
- package/dist/agent-tooling.js.map +1 -1
- package/dist/{use-air-jam-host-COLy8t4s.d.ts → air-jam-context-B1fQvyYY.d.ts} +121 -114
- package/dist/{use-air-jam-host-DM-ybB3C.d.cts → air-jam-context-BKg_ujpd.d.cts} +121 -114
- package/dist/arcade/bridge/controller.cjs +873 -603
- package/dist/arcade/bridge/controller.cjs.map +1 -1
- package/dist/arcade/bridge/controller.d.cts +28 -76
- package/dist/arcade/bridge/controller.d.ts +28 -76
- package/dist/arcade/bridge/controller.js +27 -28
- package/dist/arcade/bridge/controller.js.map +1 -1
- package/dist/arcade/bridge/host.cjs +1017 -252
- package/dist/arcade/bridge/host.cjs.map +1 -1
- package/dist/arcade/bridge/host.d.cts +6 -72
- package/dist/arcade/bridge/host.d.ts +6 -72
- package/dist/arcade/bridge/host.js +19 -22
- package/dist/arcade/bridge/host.js.map +1 -1
- package/dist/arcade/bridge/iframe.cjs +3 -31
- package/dist/arcade/bridge/iframe.cjs.map +1 -1
- package/dist/arcade/bridge/iframe.d.cts +4 -46
- package/dist/arcade/bridge/iframe.d.ts +4 -46
- package/dist/arcade/bridge/iframe.js +6 -18
- package/dist/arcade/bridge/iframe.js.map +1 -1
- package/dist/arcade/host.cjs +0 -502
- package/dist/arcade/host.cjs.map +1 -1
- package/dist/arcade/host.d.cts +1 -19
- package/dist/arcade/host.d.ts +1 -19
- package/dist/arcade/host.js +0 -14
- package/dist/arcade/host.js.map +1 -1
- package/dist/arcade/runtime.cjs +10373 -4688
- package/dist/arcade/runtime.cjs.map +1 -1
- package/dist/arcade/runtime.d.cts +45 -13
- package/dist/arcade/runtime.d.ts +45 -13
- package/dist/arcade/runtime.js +37 -24
- package/dist/arcade/runtime.js.map +1 -1
- package/dist/arcade/surface.cjs +3 -35
- package/dist/arcade/surface.cjs.map +1 -1
- package/dist/arcade/surface.d.cts +14 -2
- package/dist/arcade/surface.d.ts +14 -2
- package/dist/arcade/surface.js +7 -13
- package/dist/arcade/surface.js.map +1 -1
- package/dist/arcade/url.cjs +45 -283
- package/dist/arcade/url.cjs.map +1 -1
- package/dist/arcade/url.d.cts +3 -56
- package/dist/arcade/url.d.ts +3 -56
- package/dist/arcade/url.js +33 -16
- package/dist/arcade/url.js.map +1 -1
- package/dist/chunk-24NZZOIO.js +700 -0
- package/dist/chunk-24NZZOIO.js.map +1 -0
- package/dist/chunk-27QLKLZL.js +469 -0
- package/dist/chunk-27QLKLZL.js.map +1 -0
- package/dist/{chunk-UWJOIVON.js → chunk-2H2FGF3H.js} +3 -6
- package/dist/chunk-2H2FGF3H.js.map +1 -0
- package/dist/chunk-3LDQCQL2.js +307 -0
- package/dist/chunk-3LDQCQL2.js.map +1 -0
- package/dist/chunk-3M7656SU.js +389 -0
- package/dist/chunk-3M7656SU.js.map +1 -0
- package/dist/{chunk-K4OZ54UD.js → chunk-5CRZFIN6.js} +2 -55
- package/dist/chunk-5CRZFIN6.js.map +1 -0
- package/dist/chunk-5L3O3G5K.js +802 -0
- package/dist/chunk-5L3O3G5K.js.map +1 -0
- package/dist/{chunk-O6X7FJ6N.js → chunk-6PLOJMJD.js} +619 -643
- package/dist/chunk-6PLOJMJD.js.map +1 -0
- package/dist/{chunk-EVZJA6RN.js → chunk-6ZJUA63D.js} +183 -2
- package/dist/chunk-6ZJUA63D.js.map +1 -0
- package/dist/chunk-A6EOGRRG.js +49 -0
- package/dist/chunk-A6EOGRRG.js.map +1 -0
- package/dist/chunk-AXG6FA2H.js +366 -0
- package/dist/chunk-AXG6FA2H.js.map +1 -0
- package/dist/chunk-BEM77SVQ.js +57 -0
- package/dist/chunk-BEM77SVQ.js.map +1 -0
- package/dist/chunk-BQHGPXXN.js +1995 -0
- package/dist/chunk-BQHGPXXN.js.map +1 -0
- package/dist/chunk-C5722GTG.js +176 -0
- package/dist/chunk-C5722GTG.js.map +1 -0
- package/dist/{chunk-CV3PBXPT.js → chunk-C5GS2GMK.js} +99 -105
- package/dist/chunk-C5GS2GMK.js.map +1 -0
- package/dist/chunk-CDL7LYZH.js +19 -0
- package/dist/chunk-CDL7LYZH.js.map +1 -0
- package/dist/{chunk-PSUYTD2L.js → chunk-DA3TE4OP.js} +1 -1
- package/dist/chunk-DA3TE4OP.js.map +1 -0
- package/dist/chunk-DBF7NJ3S.js +72 -0
- package/dist/chunk-DBF7NJ3S.js.map +1 -0
- package/dist/chunk-DRBPVG47.js +89 -0
- package/dist/chunk-DRBPVG47.js.map +1 -0
- package/dist/chunk-FCG42U7D.js +131 -0
- package/dist/chunk-FCG42U7D.js.map +1 -0
- package/dist/chunk-FJ4J2BEC.js +26 -0
- package/dist/chunk-FJ4J2BEC.js.map +1 -0
- package/dist/chunk-H4DEVMTO.js +221 -0
- package/dist/chunk-H4DEVMTO.js.map +1 -0
- package/dist/chunk-ISQZ7F3N.js +83 -0
- package/dist/chunk-ISQZ7F3N.js.map +1 -0
- package/dist/{chunk-IG6GZZSS.js → chunk-JCGTL77W.js} +1 -1
- package/dist/chunk-JCGTL77W.js.map +1 -0
- package/dist/chunk-JJVCBUYM.js +98 -0
- package/dist/chunk-JJVCBUYM.js.map +1 -0
- package/dist/chunk-K6BJJJJM.js +138 -0
- package/dist/chunk-K6BJJJJM.js.map +1 -0
- package/dist/{chunk-MIMPMB7O.js → chunk-KGY4PV2A.js} +24 -3
- package/dist/chunk-KGY4PV2A.js.map +1 -0
- package/dist/chunk-KKRLHT2M.js +2477 -0
- package/dist/chunk-KKRLHT2M.js.map +1 -0
- package/dist/chunk-KSYN4I5Y.js +50 -0
- package/dist/chunk-KSYN4I5Y.js.map +1 -0
- package/dist/chunk-KUGROY5S.js +265 -0
- package/dist/chunk-KUGROY5S.js.map +1 -0
- package/dist/chunk-LX6CTPDW.js +16 -0
- package/dist/chunk-LX6CTPDW.js.map +1 -0
- package/dist/{chunk-BE6Z4SIT.js → chunk-M5553I2G.js} +2 -11
- package/dist/chunk-M5553I2G.js.map +1 -0
- package/dist/{chunk-X24K52DG.js → chunk-MD25536W.js} +1 -1
- package/dist/chunk-MD25536W.js.map +1 -0
- package/dist/{chunk-3USU7GY2.js → chunk-MJAWAHLT.js} +1 -1
- package/dist/chunk-MJAWAHLT.js.map +1 -0
- package/dist/chunk-NBA7UIWG.js +921 -0
- package/dist/chunk-NBA7UIWG.js.map +1 -0
- package/dist/chunk-OAXCFPZ7.js +14 -0
- package/dist/chunk-OAXCFPZ7.js.map +1 -0
- package/dist/{chunk-D4VDEVTZ.js → chunk-QHBRHYMV.js} +18 -17
- package/dist/chunk-QHBRHYMV.js.map +1 -0
- package/dist/chunk-QTNYGAZ7.js +45 -0
- package/dist/chunk-QTNYGAZ7.js.map +1 -0
- package/dist/chunk-UC24OG4X.js +129 -0
- package/dist/chunk-UC24OG4X.js.map +1 -0
- package/dist/chunk-VN2PX2I3.js +188 -0
- package/dist/chunk-VN2PX2I3.js.map +1 -0
- package/dist/chunk-WAFGYJZN.js +1513 -0
- package/dist/chunk-WAFGYJZN.js.map +1 -0
- package/dist/chunk-WGHNGQUS.js +78 -0
- package/dist/chunk-WGHNGQUS.js.map +1 -0
- package/dist/{chunk-X35LLCWV.js → chunk-X5HZBQ6K.js} +6 -8
- package/dist/chunk-X5HZBQ6K.js.map +1 -0
- package/dist/chunk-XLY44PXZ.js +46 -0
- package/dist/chunk-XLY44PXZ.js.map +1 -0
- package/dist/chunk-YXHAWWVU.js +7 -0
- package/dist/chunk-YXHAWWVU.js.map +1 -0
- package/dist/connection-store-CqW-E7ma.d.cts +41 -0
- package/dist/connection-store-ffHWMrMe.d.ts +41 -0
- package/dist/control-Bv8dWjyp.d.ts +1400 -0
- package/dist/control-CNzybWMd.d.cts +1400 -0
- package/dist/controller-ClW0R8mZ.d.cts +26 -0
- package/dist/controller-DRKCa7uQ.d.ts +26 -0
- package/dist/controller-agent-vOiuK7T6.d.cts +130 -0
- package/dist/controller-agent-vOiuK7T6.d.ts +130 -0
- package/dist/controller-bridge.cjs +992 -0
- package/dist/controller-bridge.cjs.map +1 -0
- package/dist/controller-bridge.d.cts +52 -0
- package/dist/controller-bridge.d.ts +52 -0
- package/dist/controller-bridge.js +23 -0
- package/dist/controller-bridge.js.map +1 -0
- package/dist/controller-capture-2GKKGHJ2.js +8 -0
- package/dist/controller-capture-2GKKGHJ2.js.map +1 -0
- package/dist/controller-press-EWWIMVXP.js +231 -0
- package/dist/controller-press-EWWIMVXP.js.map +1 -0
- package/dist/core-BAO0pHrJ.d.cts +15 -0
- package/dist/core-BAO0pHrJ.d.ts +15 -0
- package/dist/core.cjs +5956 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +250 -0
- package/dist/core.d.ts +250 -0
- package/dist/core.js +910 -0
- package/dist/core.js.map +1 -0
- package/dist/dev-events-BffobOfb.d.ts +31 -0
- package/dist/dev-events-Ct7QEgKb.d.cts +31 -0
- package/dist/dev-log-events-B1_B3guZ.d.cts +47 -0
- package/dist/dev-log-events-B1_B3guZ.d.ts +47 -0
- package/dist/frames-D-xKuODS.d.cts +686 -0
- package/dist/frames-D-xKuODS.d.ts +686 -0
- package/dist/game-5n-dh5np.d.cts +77 -0
- package/dist/game-RYb97BN8.d.ts +77 -0
- package/dist/host-runtime-BRtUidEJ.d.cts +399 -0
- package/dist/host-runtime-RrO4pCXI.d.ts +399 -0
- package/dist/index.cjs +11571 -7554
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +100 -358
- package/dist/index.d.ts +100 -358
- package/dist/index.js +414 -1903
- package/dist/index.js.map +1 -1
- package/dist/input-D7FNeehb.d.cts +92 -0
- package/dist/input-D7FNeehb.d.ts +92 -0
- package/dist/input-bindings-686sTen7.d.ts +129 -0
- package/dist/input-bindings-BRac-P0e.d.cts +129 -0
- package/dist/leased-control-BEg4JuXA.d.cts +158 -0
- package/dist/leased-control-BEg4JuXA.d.ts +158 -0
- package/dist/metadata.cjs +3 -9
- package/dist/metadata.cjs.map +1 -1
- package/dist/metadata.d.cts +6 -16
- package/dist/metadata.d.ts +6 -16
- package/dist/metadata.js +8 -76
- package/dist/metadata.js.map +1 -1
- package/dist/phone-room-session-Byomkt92.d.cts +439 -0
- package/dist/phone-room-session-D9C8cSxS.d.ts +439 -0
- package/dist/platform-machine.cjs +133 -3
- package/dist/platform-machine.cjs.map +1 -1
- package/dist/platform-machine.d.cts +525 -27
- package/dist/platform-machine.d.ts +525 -27
- package/dist/platform-machine.js +119 -4
- package/dist/platform-machine.js.map +1 -1
- package/dist/{platform-settings-DUWs4JTy.d.cts → platform-settings-Yb0fQ1dl.d.cts} +1 -3
- package/dist/{platform-settings-DUWs4JTy.d.ts → platform-settings-Yb0fQ1dl.d.ts} +1 -3
- package/dist/prefabs.cjs +134 -3
- package/dist/prefabs.cjs.map +1 -1
- package/dist/prefabs.d.cts +23 -47
- package/dist/prefabs.d.ts +23 -47
- package/dist/prefabs.js +23 -4
- package/dist/prefabs.js.map +1 -1
- package/dist/preview.cjs +2199 -767
- package/dist/preview.cjs.map +1 -1
- package/dist/preview.d.cts +193 -38
- package/dist/preview.d.ts +193 -38
- package/dist/preview.js +478 -254
- package/dist/preview.js.map +1 -1
- package/dist/protocol.cjs +585 -391
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +13 -117
- package/dist/protocol.d.ts +13 -117
- package/dist/protocol.js +43 -80
- package/dist/protocol.js.map +1 -1
- package/dist/release.cjs.map +1 -1
- package/dist/release.d.cts +2 -2
- package/dist/release.d.ts +2 -2
- package/dist/release.js +1 -1
- package/dist/release.js.map +1 -1
- package/dist/replay-input-log-D0NpnA3P.d.ts +31 -0
- package/dist/replay-input-log-bg0g-PCz.d.cts +31 -0
- package/dist/room-protocol.cjs +794 -0
- package/dist/room-protocol.cjs.map +1 -0
- package/dist/room-protocol.d.cts +63 -0
- package/dist/room-protocol.d.ts +63 -0
- package/dist/room-protocol.js +143 -0
- package/dist/room-protocol.js.map +1 -0
- package/dist/room-session.cjs +2336 -0
- package/dist/room-session.cjs.map +1 -0
- package/dist/room-session.d.cts +77 -0
- package/dist/room-session.d.ts +77 -0
- package/dist/room-session.js +103 -0
- package/dist/room-session.js.map +1 -0
- package/dist/runtime/prefab-inspection-bridge.cjs +207 -0
- package/dist/runtime/prefab-inspection-bridge.cjs.map +1 -0
- package/dist/runtime/prefab-inspection-bridge.d.cts +156 -0
- package/dist/runtime/prefab-inspection-bridge.d.ts +156 -0
- package/dist/runtime/prefab-inspection-bridge.js +22 -0
- package/dist/runtime/prefab-inspection-bridge.js.map +1 -0
- package/dist/runtime-control.cjs +2133 -8
- package/dist/runtime-control.cjs.map +1 -1
- package/dist/runtime-control.d.cts +980 -12
- package/dist/runtime-control.d.ts +980 -12
- package/dist/runtime-control.js +264 -4
- package/dist/runtime-control.js.map +1 -1
- package/dist/runtime-inspection.cjs +1222 -558
- package/dist/runtime-inspection.cjs.map +1 -1
- package/dist/runtime-inspection.d.cts +530 -22
- package/dist/runtime-inspection.d.ts +530 -22
- package/dist/runtime-inspection.js +21 -22
- package/dist/runtime-inspection.js.map +1 -1
- package/dist/runtime-reporting-K_ZXpubu.d.cts +43 -0
- package/dist/runtime-reporting-K_ZXpubu.d.ts +43 -0
- package/dist/runtime-topology.cjs +2 -5
- package/dist/runtime-topology.cjs.map +1 -1
- package/dist/runtime-topology.d.cts +1 -1
- package/dist/runtime-topology.d.ts +1 -1
- package/dist/runtime-topology.js +1 -1
- package/dist/runtime-topology.js.map +1 -1
- package/dist/scoped-connector-DEOZvCCG.d.cts +66 -0
- package/dist/scoped-connector-nTHACYTl.d.ts +66 -0
- package/dist/sdk-channels-S6j6AH8v.d.cts +103 -0
- package/dist/sdk-channels-S6j6AH8v.d.ts +103 -0
- package/dist/simulation-DL9j-ghn.d.ts +782 -0
- package/dist/simulation-HmgsvF5H.d.cts +782 -0
- package/dist/{standard-match-phase-BzSgBYFg.d.ts → standard-match-phase-D4N-AU0d.d.cts} +3 -13
- package/dist/{standard-match-phase-CvJUW8Oe.d.cts → standard-match-phase-abt8ZjCh.d.ts} +3 -13
- package/dist/transport-CWF29jU6.d.cts +173 -0
- package/dist/transport-CWF29jU6.d.ts +173 -0
- package/dist/types-p28maMEo.d.cts +102 -0
- package/dist/types-p28maMEo.d.ts +102 -0
- package/dist/ui.cjs +2167 -892
- package/dist/ui.cjs.map +1 -1
- package/dist/ui.d.cts +75 -17
- package/dist/ui.d.ts +75 -17
- package/dist/ui.js +554 -393
- package/dist/ui.js.map +1 -1
- package/package.json +38 -21
- package/src/agent/agent-action.ts +0 -39
- package/src/agent/agent-contract-conformance.ts +8 -1
- package/src/agent/agent-contract.ts +2 -4
- package/src/agent/agent-evaluator.ts +95 -0
- package/src/agent/capture-canvas.ts +79 -0
- package/src/agent/host-canvas-capture.ts +189 -0
- package/src/agent-tooling.ts +5 -20
- package/src/arcade/bridge/controller.ts +8 -11
- package/src/arcade/bridge/host.ts +6 -11
- package/src/arcade/bridge/iframe.ts +1 -50
- package/src/arcade/host.ts +0 -1
- package/src/arcade/surface.ts +5 -1
- package/src/arcade/url.ts +2 -9
- package/src/audio/audio-manager.ts +23 -47
- package/src/audio/hooks.tsx +59 -72
- package/src/components/controller-player-name-field.tsx +2 -2
- package/src/components/controller-primary-action.tsx +1 -1
- package/src/components/controls.tsx +398 -0
- package/src/components/gamepad-layout.tsx +69 -0
- package/src/components/join-url-controls.tsx +5 -1
- package/src/components/lifecycle-action-group.tsx +1 -1
- package/src/components/player-avatar.tsx +50 -3
- package/src/components/room-qr-code.tsx +36 -77
- package/src/components/stage-capture-surface.tsx +91 -0
- package/src/components/surface-viewport.tsx +16 -3
- package/src/components/ui/button.tsx +1 -1
- package/src/constants.ts +0 -15
- package/src/context/air-jam-context.tsx +56 -187
- package/src/context/session-providers.tsx +13 -10
- package/src/controller-bridge.ts +7 -0
- package/src/core/assets.ts +48 -0
- package/src/core/config.ts +70 -0
- package/src/core/connection-store.ts +77 -0
- package/src/core/controller-input.ts +147 -0
- package/src/core/controller-runtime.ts +427 -0
- package/src/core/dev-events.ts +18 -0
- package/src/core/environment.ts +132 -0
- package/src/core/game-description.ts +44 -0
- package/src/core/game.ts +130 -0
- package/src/core/host-input.ts +207 -0
- package/src/core/host-runtime.ts +988 -0
- package/src/core/hosted-rooms.ts +65 -0
- package/src/core/input-bindings.ts +180 -0
- package/src/core/input-log.ts +144 -0
- package/src/core/input.ts +228 -0
- package/src/core/local-input.ts +319 -0
- package/src/core/replay-input-log.ts +298 -0
- package/src/core/replicated-store.ts +1178 -0
- package/src/core/room-action-ack.ts +43 -0
- package/src/core/settings.ts +202 -0
- package/src/core/simulation.ts +307 -0
- package/src/core/theme.ts +33 -0
- package/src/core.ts +167 -0
- package/src/dev/browser-log-sink.ts +35 -12
- package/src/diagnostics.ts +5 -6
- package/src/hooks/internal/use-controller-runtime-api.ts +58 -925
- package/src/hooks/internal/use-host-runtime-api.ts +98 -1270
- package/src/hooks/internal/use-runtime-inspection-contract.ts +14 -2
- package/src/hooks/use-air-jam-controller.ts +32 -53
- package/src/hooks/use-air-jam-host.ts +59 -100
- package/src/hooks/use-air-jam-settings.ts +27 -0
- package/src/hooks/use-controller-toasts.ts +16 -19
- package/src/hooks/use-host-agent-capture.ts +31 -0
- package/src/hooks/use-lifecycle-action-group-model.ts +1 -1
- package/src/hooks/use-send-signal.ts +23 -156
- package/src/hooks/use-simulation.ts +83 -0
- package/src/index.ts +24 -85
- package/src/lifecycle/index.ts +0 -4
- package/src/lifecycle/standard-match-phase.ts +1 -22
- package/src/metadata/manifest.ts +8 -19
- package/src/metadata.ts +1 -1
- package/src/platform-machine.ts +127 -3
- package/src/prefabs/types.ts +91 -20
- package/src/prefabs/view.ts +82 -0
- package/src/prefabs.ts +19 -0
- package/src/preview/host-workspace.tsx +4 -9
- package/src/preview/identity.ts +31 -23
- package/src/preview/layout.ts +5 -1
- package/src/preview/manager.ts +205 -78
- package/src/preview/messages.ts +47 -0
- package/src/preview/ownership.ts +6 -1
- package/src/preview/url.ts +46 -23
- package/src/preview/window.tsx +26 -69
- package/src/preview/workspace-local-seats.ts +166 -0
- package/src/preview/workspace.tsx +89 -37
- package/src/preview.ts +27 -15
- package/src/protocol/actions.ts +58 -0
- package/src/protocol/arcade-platform-actions.ts +2 -16
- package/src/protocol/controller.ts +14 -174
- package/src/protocol/core.ts +8 -15
- package/src/protocol/dev-log-events.ts +5 -81
- package/src/protocol/leased-control.ts +177 -0
- package/src/protocol/room/addressing.ts +35 -0
- package/src/protocol/room/close-codes.ts +33 -0
- package/src/protocol/room/frames.ts +343 -0
- package/src/protocol/room/input-codec.ts +182 -0
- package/src/protocol/room/limits.ts +58 -0
- package/src/protocol/room/patch.ts +135 -0
- package/src/protocol/room/sdk-channels.ts +81 -0
- package/src/protocol/room/seat-id.ts +31 -0
- package/src/protocol/room/transport.ts +63 -0
- package/src/protocol/room/weight.ts +58 -0
- package/src/protocol/runtime-reporting.ts +56 -10
- package/src/protocol.ts +2 -7
- package/src/qrcode.d.ts +3 -13
- package/src/room-protocol.ts +10 -0
- package/src/room-session/browser-wake-events.ts +14 -0
- package/src/room-session/channel-state.ts +293 -0
- package/src/room-session/clock.ts +24 -0
- package/src/room-session/host-room-session.ts +379 -0
- package/src/room-session/input-lane.ts +125 -0
- package/src/room-session/listeners.ts +22 -0
- package/src/room-session/loopback-link.ts +58 -0
- package/src/room-session/phone-room-session.ts +368 -0
- package/src/room-session/port-link.ts +116 -0
- package/src/room-session/room-key.ts +9 -0
- package/src/room-session/roster.ts +23 -0
- package/src/room-session/scoped-connector.ts +577 -0
- package/src/room-session/session-link.ts +306 -0
- package/src/room-session/web-socket-link.ts +57 -0
- package/src/room-session.ts +12 -0
- package/src/runtime/air-jam-config.ts +49 -37
- package/src/runtime/air-jam-error-boundary.tsx +9 -3
- package/src/runtime/arcade-runtime-url.ts +8 -9
- package/src/runtime/browser-controller-environment.ts +116 -0
- package/src/runtime/browser-host-environment.ts +137 -0
- package/src/runtime/browser-replay.ts +211 -0
- package/src/runtime/browser-room.ts +41 -0
- package/src/runtime/connected-runtime-error-boundary.tsx +35 -8
- package/src/runtime/contracts/agent-control.ts +195 -0
- package/src/runtime/contracts/clip.ts +169 -0
- package/src/runtime/contracts/control.ts +653 -16
- package/src/runtime/contracts/controller-agent.ts +130 -0
- package/src/runtime/contracts/input-log.ts +38 -0
- package/src/runtime/contracts/inspection.ts +25 -22
- package/src/runtime/contracts/observation.ts +186 -0
- package/src/runtime/contracts/runtime-identity.ts +43 -0
- package/src/runtime/contracts/timeline.ts +59 -0
- package/src/runtime/controller-agent-bridge.ts +152 -0
- package/src/runtime/controller-bridge-context.ts +29 -0
- package/src/runtime/controller-capture.ts +50 -0
- package/src/runtime/controller-identity.ts +53 -142
- package/src/runtime/controller-presentation.ts +47 -17
- package/src/runtime/controller-press.ts +271 -0
- package/src/runtime/create-air-jam-app.tsx +103 -74
- package/src/runtime/dev-runtime-events.ts +6 -18
- package/src/runtime/embedded-parent.ts +22 -0
- package/src/runtime/embedded-runtime-adapters.ts +10 -9
- package/src/runtime/host-agent-bridge.ts +127 -0
- package/src/runtime/host-capture-boundary.tsx +92 -0
- package/src/runtime/host-capture-context.ts +7 -0
- package/src/runtime/host-clip-reader.ts +93 -0
- package/src/runtime/host-clip-recorder.ts +342 -0
- package/src/runtime/host-input-log-reader.ts +120 -0
- package/src/runtime/host-observation.ts +207 -0
- package/src/runtime/host-pace.ts +36 -0
- package/src/runtime/host-runtime-fault.ts +51 -0
- package/src/runtime/host-timeline.ts +152 -0
- package/src/runtime/local-players.tsx +96 -0
- package/src/runtime/local-seats.ts +612 -0
- package/src/runtime/participant-control.ts +162 -0
- package/src/runtime/prefab-inspection-bridge.ts +174 -0
- package/src/runtime/prefab-inspection-clock.ts +12 -0
- package/src/runtime/prefab-inspection-context.ts +20 -0
- package/src/runtime/prefab-inspection-runtime.tsx +328 -0
- package/src/runtime/preview-inspection-bridge.ts +130 -0
- package/src/runtime/replay-runtime.tsx +101 -0
- package/src/runtime/room-bridge.ts +110 -0
- package/src/runtime/runtime-owner-contexts.tsx +9 -0
- package/src/runtime/runtime-session-params.ts +20 -23
- package/src/runtime/session-runtimes.tsx +231 -64
- package/src/runtime/stage-capture.ts +25 -0
- package/src/runtime-control.ts +41 -0
- package/src/runtime-inspection.ts +14 -7
- package/src/runtime-topology.ts +7 -8
- package/src/settings/platform-settings-runtime.tsx +47 -2
- package/src/settings/platform-settings.ts +0 -65
- package/src/store/use-air-jam-store.ts +73 -0
- package/src/ui.ts +3 -3
- package/src/utils/is-rpc-serializable.ts +11 -19
- package/src/utils/url-builder.ts +0 -7
- package/dist/air-jam-context-BlLPvCup.d.cts +0 -175
- package/dist/air-jam-context-DTsxF-tP.d.ts +0 -175
- package/dist/arcade/bridge.cjs +0 -1087
- package/dist/arcade/bridge.cjs.map +0 -1
- package/dist/arcade/bridge.d.cts +0 -11
- package/dist/arcade/bridge.d.ts +0 -11
- package/dist/arcade/bridge.js +0 -78
- package/dist/arcade/bridge.js.map +0 -1
- package/dist/arcade-runtime-url-BW-MUAOY.d.cts +0 -28
- package/dist/arcade-runtime-url-l8qj01Pg.d.ts +0 -28
- package/dist/arcade.cjs +0 -1767
- package/dist/arcade.cjs.map +0 -1
- package/dist/arcade.d.cts +0 -18
- package/dist/arcade.d.ts +0 -18
- package/dist/arcade.js +0 -129
- package/dist/arcade.js.map +0 -1
- package/dist/chunk-2SZ2YYGJ.js +0 -280
- package/dist/chunk-2SZ2YYGJ.js.map +0 -1
- package/dist/chunk-32RSSFSF.js +0 -214
- package/dist/chunk-32RSSFSF.js.map +0 -1
- package/dist/chunk-3USU7GY2.js.map +0 -1
- package/dist/chunk-3YMUAKPU.js +0 -10
- package/dist/chunk-3YMUAKPU.js.map +0 -1
- package/dist/chunk-56DM2KEW.js +0 -14
- package/dist/chunk-56DM2KEW.js.map +0 -1
- package/dist/chunk-BE6Z4SIT.js.map +0 -1
- package/dist/chunk-CM53YLT5.js +0 -59
- package/dist/chunk-CM53YLT5.js.map +0 -1
- package/dist/chunk-CV3PBXPT.js.map +0 -1
- package/dist/chunk-D4VDEVTZ.js.map +0 -1
- package/dist/chunk-EVZJA6RN.js.map +0 -1
- package/dist/chunk-FUA6EMSJ.js +0 -90
- package/dist/chunk-FUA6EMSJ.js.map +0 -1
- package/dist/chunk-GMLU7RI5.js +0 -70
- package/dist/chunk-GMLU7RI5.js.map +0 -1
- package/dist/chunk-IG6GZZSS.js.map +0 -1
- package/dist/chunk-IKKDONQL.js +0 -1
- package/dist/chunk-IKKDONQL.js.map +0 -1
- package/dist/chunk-ITMQSBTH.js +0 -26
- package/dist/chunk-ITMQSBTH.js.map +0 -1
- package/dist/chunk-J5MCII33.js +0 -620
- package/dist/chunk-J5MCII33.js.map +0 -1
- package/dist/chunk-JTF47B56.js +0 -1
- package/dist/chunk-JTF47B56.js.map +0 -1
- package/dist/chunk-K4OZ54UD.js.map +0 -1
- package/dist/chunk-LIHEEAVE.js +0 -191
- package/dist/chunk-LIHEEAVE.js.map +0 -1
- package/dist/chunk-LIXPF4P6.js +0 -22
- package/dist/chunk-LIXPF4P6.js.map +0 -1
- package/dist/chunk-MIMPMB7O.js.map +0 -1
- package/dist/chunk-MPDMJIX5.js +0 -1
- package/dist/chunk-MPDMJIX5.js.map +0 -1
- package/dist/chunk-O6X7FJ6N.js.map +0 -1
- package/dist/chunk-PSUYTD2L.js.map +0 -1
- package/dist/chunk-QO4KFUEI.js +0 -32
- package/dist/chunk-QO4KFUEI.js.map +0 -1
- package/dist/chunk-QTLYZADF.js +0 -125
- package/dist/chunk-QTLYZADF.js.map +0 -1
- package/dist/chunk-TGRTEWYV.js +0 -195
- package/dist/chunk-TGRTEWYV.js.map +0 -1
- package/dist/chunk-TTQDHKXL.js +0 -3017
- package/dist/chunk-TTQDHKXL.js.map +0 -1
- package/dist/chunk-UCPY7UJC.js +0 -8
- package/dist/chunk-UCPY7UJC.js.map +0 -1
- package/dist/chunk-UPV6YWT5.js +0 -43
- package/dist/chunk-UPV6YWT5.js.map +0 -1
- package/dist/chunk-UWJOIVON.js.map +0 -1
- package/dist/chunk-W2VK36RO.js +0 -11
- package/dist/chunk-W2VK36RO.js.map +0 -1
- package/dist/chunk-X24K52DG.js.map +0 -1
- package/dist/chunk-X35LLCWV.js.map +0 -1
- package/dist/chunk-YXHH3MQT.js +0 -230
- package/dist/chunk-YXHH3MQT.js.map +0 -1
- package/dist/controller-PZEM_1cH.d.ts +0 -176
- package/dist/controller-vj82tKm4.d.cts +0 -176
- package/dist/dev-log-events-BCJKmygo.d.cts +0 -120
- package/dist/dev-log-events-BCJKmygo.d.ts +0 -120
- package/dist/handshake-CC_LrK5g.d.cts +0 -31
- package/dist/handshake-CC_LrK5g.d.ts +0 -31
- package/dist/host-B9pRy0Aa.d.cts +0 -122
- package/dist/host-DylGsX7p.d.ts +0 -122
- package/dist/notices-C4bao3oi.d.ts +0 -38
- package/dist/notices-DNdOjwtj.d.cts +0 -38
- package/dist/realtime-client-Cu8yVJFw.d.cts +0 -15
- package/dist/realtime-client-Cu8yVJFw.d.ts +0 -15
- package/dist/runtime-reporting-pe-eryVz.d.cts +0 -27
- package/dist/runtime-reporting-pe-eryVz.d.ts +0 -27
- package/dist/signals-ZHftIKuc.d.cts +0 -33
- package/dist/signals-ZHftIKuc.d.ts +0 -33
- package/dist/sync-xtPfWhif.d.cts +0 -81
- package/dist/sync-xtPfWhif.d.ts +0 -81
- package/src/arcade/bridge.ts +0 -3
- package/src/arcade.ts +0 -4
- package/src/context/socket-manager.ts +0 -72
- package/src/events.ts +0 -119
- package/src/hooks/use-connection-status.ts +0 -8
- package/src/hooks/use-controller-tick.ts +0 -65
- package/src/hooks/use-get-input.ts +0 -100
- package/src/hooks/use-host-arcade-restore.ts +0 -35
- package/src/hooks/use-host-tick.ts +0 -171
- package/src/hooks/use-input-writer.ts +0 -83
- package/src/hooks/use-players.ts +0 -12
- package/src/internal/input-manager.ts +0 -356
- package/src/protocol/errors.ts +0 -21
- package/src/protocol/host-grant.ts +0 -103
- package/src/protocol/host.ts +0 -150
- package/src/protocol/notices.ts +0 -43
- package/src/protocol/signals.ts +0 -38
- package/src/protocol/socket-events.ts +0 -152
- package/src/protocol/sync.ts +0 -105
- package/src/runtime/admission-retry.ts +0 -62
- package/src/runtime/bridge-envelope-args.ts +0 -21
- package/src/runtime/controller-bridge.ts +0 -439
- package/src/runtime/controller-realtime-client.ts +0 -552
- package/src/runtime/host-bridge.ts +0 -380
- package/src/runtime/host-realtime-client.ts +0 -550
- package/src/runtime/realtime-client.ts +0 -20
- package/src/runtime/validate-arcade-bridge-attach.ts +0 -14
- package/src/state/connection-store.ts +0 -159
- package/src/store/create-air-jam-store.ts +0 -1193
- package/src/store/index.ts +0 -1
- package/src/utils/ids.ts +0 -58
package/dist/core.js
ADDED
|
@@ -0,0 +1,910 @@
|
|
|
1
|
+
import {
|
|
2
|
+
airJamAssetsSchema,
|
|
3
|
+
airJamThemeSchema,
|
|
4
|
+
defineAirJamAssets,
|
|
5
|
+
defineAirJamGame,
|
|
6
|
+
defineAirJamTheme,
|
|
7
|
+
isAirJamGame,
|
|
8
|
+
soundConfigSchema
|
|
9
|
+
} from "./chunk-UC24OG4X.js";
|
|
10
|
+
import {
|
|
11
|
+
ControllerInput,
|
|
12
|
+
ControllerRuntime,
|
|
13
|
+
HostRuntime,
|
|
14
|
+
SimulationClock,
|
|
15
|
+
agentValuesToInputState,
|
|
16
|
+
airJamInputDescriptionSchema,
|
|
17
|
+
axis,
|
|
18
|
+
button,
|
|
19
|
+
createSeededRandom,
|
|
20
|
+
defineAirJamInput,
|
|
21
|
+
defineAirJamSimulation,
|
|
22
|
+
stick
|
|
23
|
+
} from "./chunk-BQHGPXXN.js";
|
|
24
|
+
import "./chunk-XLY44PXZ.js";
|
|
25
|
+
import {
|
|
26
|
+
airJamGameMetadataSchema
|
|
27
|
+
} from "./chunk-WGHNGQUS.js";
|
|
28
|
+
import {
|
|
29
|
+
arrows,
|
|
30
|
+
defineAirJamInputBindings,
|
|
31
|
+
keyAxis,
|
|
32
|
+
keyStick,
|
|
33
|
+
wasd
|
|
34
|
+
} from "./chunk-DRBPVG47.js";
|
|
35
|
+
import {
|
|
36
|
+
emitAirJamDiagnostic
|
|
37
|
+
} from "./chunk-DBF7NJ3S.js";
|
|
38
|
+
import {
|
|
39
|
+
AIRJAM_DEV_LOG_EVENTS
|
|
40
|
+
} from "./chunk-KUGROY5S.js";
|
|
41
|
+
import "./chunk-MJAWAHLT.js";
|
|
42
|
+
import {
|
|
43
|
+
AIR_JAM_HOSTED_ENVIRONMENTS,
|
|
44
|
+
createAirJamConfig,
|
|
45
|
+
createConnectionStore,
|
|
46
|
+
findHostedEnvironment,
|
|
47
|
+
getReconnectingPlayerIds,
|
|
48
|
+
openAirJamReplay,
|
|
49
|
+
replayAirJamInputLog
|
|
50
|
+
} from "./chunk-AXG6FA2H.js";
|
|
51
|
+
import "./chunk-KSYN4I5Y.js";
|
|
52
|
+
import "./chunk-CDL7LYZH.js";
|
|
53
|
+
import {
|
|
54
|
+
AIR_JAM_INPUT_LOG_MAX_ENTRY_BYTES,
|
|
55
|
+
AIR_JAM_INPUT_LOG_MAX_GAME_MS,
|
|
56
|
+
airJamInputLogSchema,
|
|
57
|
+
airJamSettingSchema,
|
|
58
|
+
airJamSettingsValuesSchema,
|
|
59
|
+
defineAirJamSettings,
|
|
60
|
+
isHostRuntimeParticipantLeased,
|
|
61
|
+
registerHostRuntimeActionStore,
|
|
62
|
+
setting
|
|
63
|
+
} from "./chunk-WAFGYJZN.js";
|
|
64
|
+
import {
|
|
65
|
+
airJamActionInvocationResultSchema
|
|
66
|
+
} from "./chunk-H4DEVMTO.js";
|
|
67
|
+
import "./chunk-2H2FGF3H.js";
|
|
68
|
+
import {
|
|
69
|
+
agentAction,
|
|
70
|
+
agentContractDescriptionSchema,
|
|
71
|
+
agentStore,
|
|
72
|
+
createAirJamAgentEvaluator,
|
|
73
|
+
defineAirJamAgentContract,
|
|
74
|
+
defineAirJamAgentStores,
|
|
75
|
+
isRpcSerializable
|
|
76
|
+
} from "./chunk-C5722GTG.js";
|
|
77
|
+
import "./chunk-5CRZFIN6.js";
|
|
78
|
+
import "./chunk-24NZZOIO.js";
|
|
79
|
+
|
|
80
|
+
// src/core/replicated-store.ts
|
|
81
|
+
import { nanoid } from "nanoid";
|
|
82
|
+
import { createStore } from "zustand/vanilla";
|
|
83
|
+
var INTERNAL_ACTION_PREFIX = "_";
|
|
84
|
+
var isEventLikePayload = (payload) => {
|
|
85
|
+
if (payload === null || typeof payload !== "object") {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
const candidate = payload;
|
|
89
|
+
return typeof candidate.preventDefault === "function" || typeof candidate.stopPropagation === "function" || typeof candidate.persist === "function" || "nativeEvent" in candidate && ("target" in candidate || "currentTarget" in candidate);
|
|
90
|
+
};
|
|
91
|
+
var isPlainActionPayload = (payload) => {
|
|
92
|
+
if (payload === null || typeof payload !== "object" || Array.isArray(payload)) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
const prototype = Object.getPrototypeOf(payload);
|
|
96
|
+
return prototype === Object.prototype || prototype === null;
|
|
97
|
+
};
|
|
98
|
+
var isInternalActionName = (actionName) => actionName.startsWith(INTERNAL_ACTION_PREFIX);
|
|
99
|
+
var acceptAirJamAction = (result) => ({
|
|
100
|
+
__airJamActionAcceptance: true,
|
|
101
|
+
...result !== void 0 ? { result } : {}
|
|
102
|
+
});
|
|
103
|
+
var rejectAirJamAction = (reason, message, details) => ({
|
|
104
|
+
__airJamActionRejection: true,
|
|
105
|
+
reason,
|
|
106
|
+
message,
|
|
107
|
+
...details ? { details } : {}
|
|
108
|
+
});
|
|
109
|
+
var isAirJamActionAcceptance = (value) => typeof value === "object" && value !== null && value.__airJamActionAcceptance === true;
|
|
110
|
+
var isAirJamActionRejection = (value) => typeof value === "object" && value !== null && value.__airJamActionRejection === true;
|
|
111
|
+
var createClientRejectedActionResult = (reason, message, details) => ({
|
|
112
|
+
ok: false,
|
|
113
|
+
status: "rejected",
|
|
114
|
+
source: "client",
|
|
115
|
+
reason,
|
|
116
|
+
message,
|
|
117
|
+
...details ? { details } : {}
|
|
118
|
+
});
|
|
119
|
+
var createServerRejectedActionResult = (reason, message, details) => ({
|
|
120
|
+
ok: false,
|
|
121
|
+
status: "rejected",
|
|
122
|
+
source: "server",
|
|
123
|
+
reason,
|
|
124
|
+
message,
|
|
125
|
+
...details ? { details } : {}
|
|
126
|
+
});
|
|
127
|
+
var normalizeAirJamActionInvocationResult = (value, source) => {
|
|
128
|
+
if (isAirJamActionRejection(value)) {
|
|
129
|
+
return {
|
|
130
|
+
ok: false,
|
|
131
|
+
status: "rejected",
|
|
132
|
+
source,
|
|
133
|
+
reason: value.reason,
|
|
134
|
+
message: value.message,
|
|
135
|
+
...value.details ? { details: value.details } : {}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
if (isAirJamActionAcceptance(value)) {
|
|
139
|
+
return {
|
|
140
|
+
ok: true,
|
|
141
|
+
status: "accepted",
|
|
142
|
+
source,
|
|
143
|
+
...value.result !== void 0 ? { result: value.result } : {}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
ok: true,
|
|
148
|
+
status: "accepted",
|
|
149
|
+
source,
|
|
150
|
+
...value !== void 0 ? { result: value } : {}
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
var airJamActionResultOf = (outcome) => {
|
|
154
|
+
switch (outcome.status) {
|
|
155
|
+
case "answered": {
|
|
156
|
+
const parsed = airJamActionInvocationResultSchema.safeParse(
|
|
157
|
+
outcome.result
|
|
158
|
+
);
|
|
159
|
+
return parsed.success ? parsed.data : createServerRejectedActionResult(
|
|
160
|
+
"invalid_answer",
|
|
161
|
+
"The host's answer was not an action result."
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
case "refused":
|
|
165
|
+
return createServerRejectedActionResult(
|
|
166
|
+
"host_away",
|
|
167
|
+
"The host is away, so the action did not run."
|
|
168
|
+
);
|
|
169
|
+
case "unconfirmed":
|
|
170
|
+
case "busy":
|
|
171
|
+
return { ok: false, status: "unconfirmed", source: "client" };
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
var stripActionsFromState = (data) => {
|
|
175
|
+
const { actions: _ignored, ...stateData } = data;
|
|
176
|
+
return stateData;
|
|
177
|
+
};
|
|
178
|
+
var shapeFingerprintOf = (shape) => {
|
|
179
|
+
let first = 2166136261;
|
|
180
|
+
let second = 16777619;
|
|
181
|
+
for (let index = 0; index < shape.length; index += 1) {
|
|
182
|
+
const code = shape.charCodeAt(index);
|
|
183
|
+
first = Math.imul(first ^ code, 16777619) >>> 0;
|
|
184
|
+
second = Math.imul(second ^ code, 2166136261) >>> 0;
|
|
185
|
+
}
|
|
186
|
+
return `${first.toString(16).padStart(8, "0")}${second.toString(16).padStart(8, "0")}`;
|
|
187
|
+
};
|
|
188
|
+
var stateShape = (value) => {
|
|
189
|
+
if (value === null) return "null";
|
|
190
|
+
if (Array.isArray(value)) {
|
|
191
|
+
return `array[${[...new Set(value.map(stateShape))].sort().join(",")}]`;
|
|
192
|
+
}
|
|
193
|
+
if (typeof value === "object") {
|
|
194
|
+
return `object{${Object.keys(value).sort().map(
|
|
195
|
+
(key) => `${JSON.stringify(key)}:${stateShape(Reflect.get(value, key))}`
|
|
196
|
+
).join(",")}}`;
|
|
197
|
+
}
|
|
198
|
+
return typeof value;
|
|
199
|
+
};
|
|
200
|
+
var toActionContext = (call, runtime) => ({
|
|
201
|
+
actorId: call.actor.id,
|
|
202
|
+
role: call.actor.role,
|
|
203
|
+
connectedPlayerIds: runtime.connectedPlayerIds,
|
|
204
|
+
now: runtime.now(),
|
|
205
|
+
settings: runtime.settings?.() ?? {}
|
|
206
|
+
});
|
|
207
|
+
var detachedClock = () => {
|
|
208
|
+
throw new Error("This Air Jam store is not attached to a running session.");
|
|
209
|
+
};
|
|
210
|
+
var AIR_JAM_ACTION_SESSION_WAIT_MS = 1e4;
|
|
211
|
+
function createAirJamStore(initializer, options) {
|
|
212
|
+
const store = createStore((set, get, api) => initializer(set, get, api));
|
|
213
|
+
const shapeFingerprint = shapeFingerprintOf(
|
|
214
|
+
stateShape(stripActionsFromState(store.getInitialState()))
|
|
215
|
+
);
|
|
216
|
+
const privateField = options?.privateField;
|
|
217
|
+
const privateEntries = (state) => {
|
|
218
|
+
if (!privateField) return {};
|
|
219
|
+
const entries = state[privateField];
|
|
220
|
+
if (!entries || typeof entries !== "object" || Array.isArray(entries))
|
|
221
|
+
throw new Error(
|
|
222
|
+
"A private store field must be a map keyed by controllerId."
|
|
223
|
+
);
|
|
224
|
+
return entries;
|
|
225
|
+
};
|
|
226
|
+
const projectState = (state, controllerId) => {
|
|
227
|
+
const data = { ...state };
|
|
228
|
+
if (privateField) {
|
|
229
|
+
const entry = controllerId ? privateEntries(state)[controllerId] : void 0;
|
|
230
|
+
Object.assign(data, {
|
|
231
|
+
[privateField]: controllerId && entry !== void 0 ? { [controllerId]: entry } : {}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
return data;
|
|
235
|
+
};
|
|
236
|
+
if (privateField) privateEntries(store.getState());
|
|
237
|
+
const stateEpoch = nanoid();
|
|
238
|
+
const runtimeSnapshotRef = {
|
|
239
|
+
current: {
|
|
240
|
+
room: null,
|
|
241
|
+
roomId: null,
|
|
242
|
+
resolvedStoreDomain: "",
|
|
243
|
+
controllerId: null,
|
|
244
|
+
connectedPlayerIds: [],
|
|
245
|
+
now: detachedClock
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
const sessionWaiters = /* @__PURE__ */ new Set();
|
|
249
|
+
const sessionReady = (runtime) => runtime.room !== null;
|
|
250
|
+
const waitForSession = () => new Promise((resolve) => {
|
|
251
|
+
const finish = () => {
|
|
252
|
+
clearTimeout(timeout);
|
|
253
|
+
sessionWaiters.delete(finish);
|
|
254
|
+
resolve(runtimeSnapshotRef.current);
|
|
255
|
+
};
|
|
256
|
+
const timeout = setTimeout(finish, AIR_JAM_ACTION_SESSION_WAIT_MS);
|
|
257
|
+
sessionWaiters.add(finish);
|
|
258
|
+
});
|
|
259
|
+
const hostActionListeners = /* @__PURE__ */ new Set();
|
|
260
|
+
const createDispatchedActions = (ownerStore, mode) => {
|
|
261
|
+
const sourceActions = ownerStore.getState().actions;
|
|
262
|
+
const actionDispatch = {};
|
|
263
|
+
for (const actionName of Object.keys(sourceActions)) {
|
|
264
|
+
if (isInternalActionName(actionName)) {
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
const sourceAction = sourceActions[actionName];
|
|
268
|
+
actionDispatch[actionName] = async (payload) => {
|
|
269
|
+
const normalizedPayload = isEventLikePayload(payload) ? void 0 : payload;
|
|
270
|
+
if (normalizedPayload !== payload) {
|
|
271
|
+
emitAirJamDiagnostic({
|
|
272
|
+
code: "AJ_STORE_ACTION_EVENT_PAYLOAD_DROPPED",
|
|
273
|
+
severity: "warn",
|
|
274
|
+
message: `[AirJamConnectionState] Action "${actionName}" received an event-like payload. Dropping payload and continuing.`,
|
|
275
|
+
details: { actionName }
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
const runtime = sessionReady(runtimeSnapshotRef.current) ? runtimeSnapshotRef.current : await waitForSession();
|
|
279
|
+
const role = runtime.room?.role ?? null;
|
|
280
|
+
if (mode.kind === "player" && role !== "host") {
|
|
281
|
+
emitAirJamDiagnostic({
|
|
282
|
+
code: "AJ_STORE_PLAYER_ACTIONS_HOST_ONLY",
|
|
283
|
+
severity: "warn",
|
|
284
|
+
message: `[AirJamConnectionState] Player impersonation for action "${actionName}" is host-only.`,
|
|
285
|
+
details: {
|
|
286
|
+
actionName,
|
|
287
|
+
role,
|
|
288
|
+
controllerId: mode.controllerId
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
return createClientRejectedActionResult(
|
|
292
|
+
"player_actions_host_only",
|
|
293
|
+
`Store action "${actionName}" cannot impersonate a player outside the host runtime.`,
|
|
294
|
+
{
|
|
295
|
+
actionName,
|
|
296
|
+
...role ? { role } : {},
|
|
297
|
+
controllerId: mode.controllerId
|
|
298
|
+
}
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
if (mode.kind === "player") {
|
|
302
|
+
const normalizedControllerId = mode.controllerId.trim();
|
|
303
|
+
if (normalizedControllerId.length === 0) {
|
|
304
|
+
emitAirJamDiagnostic({
|
|
305
|
+
code: "AJ_STORE_PLAYER_ACTIONS_INVALID_ACTOR_ID",
|
|
306
|
+
severity: "warn",
|
|
307
|
+
message: `[AirJamConnectionState] Player impersonation for action "${actionName}" requires a non-empty controller id.`,
|
|
308
|
+
details: {
|
|
309
|
+
actionName
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
return createClientRejectedActionResult(
|
|
313
|
+
"player_actor_id_invalid",
|
|
314
|
+
`Store action "${actionName}" requires a non-empty controller id for player impersonation.`,
|
|
315
|
+
{
|
|
316
|
+
actionName
|
|
317
|
+
}
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
if (!runtime.connectedPlayerIds.includes(normalizedControllerId)) {
|
|
321
|
+
emitAirJamDiagnostic({
|
|
322
|
+
code: "AJ_STORE_PLAYER_ACTIONS_PLAYER_NOT_CONNECTED",
|
|
323
|
+
severity: "warn",
|
|
324
|
+
message: `[AirJamConnectionState] Player impersonation for action "${actionName}" requires a currently connected controller.`,
|
|
325
|
+
details: {
|
|
326
|
+
actionName,
|
|
327
|
+
controllerId: normalizedControllerId,
|
|
328
|
+
connectedPlayerIds: runtime.connectedPlayerIds
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
return createClientRejectedActionResult(
|
|
332
|
+
"player_not_connected",
|
|
333
|
+
`Store action "${actionName}" cannot impersonate controller "${normalizedControllerId}" because it is not currently connected.`,
|
|
334
|
+
{
|
|
335
|
+
actionName,
|
|
336
|
+
controllerId: normalizedControllerId
|
|
337
|
+
}
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
if (role === "host") {
|
|
342
|
+
try {
|
|
343
|
+
const context = mode.kind === "player" ? {
|
|
344
|
+
actorId: mode.controllerId.trim(),
|
|
345
|
+
role: "controller",
|
|
346
|
+
connectedPlayerIds: runtime.connectedPlayerIds,
|
|
347
|
+
now: runtime.now(),
|
|
348
|
+
settings: runtime.settings?.() ?? {}
|
|
349
|
+
} : {
|
|
350
|
+
actorId: "host",
|
|
351
|
+
role: "host",
|
|
352
|
+
connectedPlayerIds: runtime.connectedPlayerIds,
|
|
353
|
+
now: runtime.now(),
|
|
354
|
+
settings: runtime.settings?.() ?? {}
|
|
355
|
+
};
|
|
356
|
+
const result = sourceAction(context, normalizedPayload);
|
|
357
|
+
const acknowledgement = normalizeAirJamActionInvocationResult(
|
|
358
|
+
result,
|
|
359
|
+
"host"
|
|
360
|
+
);
|
|
361
|
+
const typedActionName = actionName;
|
|
362
|
+
notifyHostActionListeners({
|
|
363
|
+
actionName: typedActionName,
|
|
364
|
+
payload: normalizedPayload,
|
|
365
|
+
context,
|
|
366
|
+
acknowledgement,
|
|
367
|
+
invocationKind: "local",
|
|
368
|
+
roomId: runtime.roomId,
|
|
369
|
+
storeDomain: runtime.resolvedStoreDomain
|
|
370
|
+
});
|
|
371
|
+
return acknowledgement;
|
|
372
|
+
} catch (error) {
|
|
373
|
+
const acknowledgement = {
|
|
374
|
+
ok: false,
|
|
375
|
+
status: "rejected",
|
|
376
|
+
source: "host",
|
|
377
|
+
reason: "handler_error",
|
|
378
|
+
message: error instanceof Error ? error.message : String(error)
|
|
379
|
+
};
|
|
380
|
+
const typedActionName = actionName;
|
|
381
|
+
notifyHostActionListeners({
|
|
382
|
+
actionName: typedActionName,
|
|
383
|
+
payload: normalizedPayload,
|
|
384
|
+
context: {
|
|
385
|
+
actorId: mode.kind === "player" ? mode.controllerId.trim() : "host",
|
|
386
|
+
role: mode.kind === "player" ? "controller" : "host",
|
|
387
|
+
connectedPlayerIds: runtime.connectedPlayerIds,
|
|
388
|
+
now: runtime.now(),
|
|
389
|
+
settings: runtime.settings?.() ?? {}
|
|
390
|
+
},
|
|
391
|
+
acknowledgement,
|
|
392
|
+
invocationKind: "local",
|
|
393
|
+
roomId: runtime.roomId,
|
|
394
|
+
storeDomain: runtime.resolvedStoreDomain
|
|
395
|
+
});
|
|
396
|
+
return acknowledgement;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
const room = runtime.room;
|
|
400
|
+
if (!room || room.role !== "controller") {
|
|
401
|
+
emitAirJamDiagnostic({
|
|
402
|
+
code: "AJ_STORE_ACTION_SESSION_NOT_READY",
|
|
403
|
+
severity: "error",
|
|
404
|
+
message: `[AirJamConnectionState] Action "${actionName}" dropped: the session was not ready within ${AIR_JAM_ACTION_SESSION_WAIT_MS / 1e3} s.`,
|
|
405
|
+
details: { actionName }
|
|
406
|
+
});
|
|
407
|
+
return createClientRejectedActionResult(
|
|
408
|
+
"session_not_ready",
|
|
409
|
+
`Store action "${actionName}" cannot run because the controller session is not ready.`,
|
|
410
|
+
{ actionName }
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
if (!isRpcSerializable(normalizedPayload)) {
|
|
414
|
+
emitAirJamDiagnostic({
|
|
415
|
+
code: "AJ_STORE_ACTION_PAYLOAD_NOT_SERIALIZABLE",
|
|
416
|
+
severity: "warn",
|
|
417
|
+
message: `[AirJamConnectionState] Action "${actionName}" blocked: payload must be RPC-serializable.`,
|
|
418
|
+
details: { actionName }
|
|
419
|
+
});
|
|
420
|
+
return createClientRejectedActionResult(
|
|
421
|
+
"payload_not_serializable",
|
|
422
|
+
`Store action "${actionName}" requires an RPC-serializable payload.`,
|
|
423
|
+
{ actionName }
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
if (normalizedPayload !== void 0 && !isPlainActionPayload(normalizedPayload)) {
|
|
427
|
+
emitAirJamDiagnostic({
|
|
428
|
+
code: "AJ_STORE_ACTION_PAYLOAD_INVALID_SHAPE",
|
|
429
|
+
severity: "warn",
|
|
430
|
+
message: `[AirJamConnectionState] Action "${actionName}" blocked: payload must be omitted or a plain object.`,
|
|
431
|
+
details: { actionName }
|
|
432
|
+
});
|
|
433
|
+
return createClientRejectedActionResult(
|
|
434
|
+
"payload_invalid_shape",
|
|
435
|
+
`Store action "${actionName}" requires an omitted payload or a plain object payload.`,
|
|
436
|
+
{ actionName }
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
return airJamActionResultOf(
|
|
440
|
+
await room.request(
|
|
441
|
+
runtime.resolvedStoreDomain,
|
|
442
|
+
actionName,
|
|
443
|
+
normalizedPayload
|
|
444
|
+
)
|
|
445
|
+
);
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
return actionDispatch;
|
|
449
|
+
};
|
|
450
|
+
const notifyHostActionListeners = (event) => {
|
|
451
|
+
for (const registration of hostActionListeners) {
|
|
452
|
+
if (registration.actionNames && !registration.actionNames.has(event.actionName)) {
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
if (!registration.includeRejected && event.acknowledgement.status === "rejected") {
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
try {
|
|
459
|
+
registration.listener(event);
|
|
460
|
+
} catch (error) {
|
|
461
|
+
console.error(
|
|
462
|
+
`[AirJamConnectionState] Host action listener for "${event.actionName}" threw.`,
|
|
463
|
+
error
|
|
464
|
+
);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
const dispatchActionCall = (call) => {
|
|
469
|
+
const { actionName } = call;
|
|
470
|
+
if (isInternalActionName(actionName)) {
|
|
471
|
+
return createServerRejectedActionResult(
|
|
472
|
+
"internal_action",
|
|
473
|
+
"Internal store actions cannot be invoked by controllers."
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
const runtime = runtimeSnapshotRef.current;
|
|
477
|
+
const actionFn = store.getState().actions[actionName];
|
|
478
|
+
if (typeof actionFn !== "function") {
|
|
479
|
+
return createServerRejectedActionResult(
|
|
480
|
+
"action_not_found",
|
|
481
|
+
`Store action "${actionName}" is not registered on the host.`,
|
|
482
|
+
{
|
|
483
|
+
actionName,
|
|
484
|
+
storeDomain: call.storeDomain
|
|
485
|
+
}
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
const context = toActionContext(call, runtime);
|
|
489
|
+
let acknowledgement;
|
|
490
|
+
try {
|
|
491
|
+
acknowledgement = normalizeAirJamActionInvocationResult(
|
|
492
|
+
actionFn(context, call.payload),
|
|
493
|
+
"host"
|
|
494
|
+
);
|
|
495
|
+
} catch (error) {
|
|
496
|
+
acknowledgement = {
|
|
497
|
+
ok: false,
|
|
498
|
+
status: "rejected",
|
|
499
|
+
source: "host",
|
|
500
|
+
reason: "handler_error",
|
|
501
|
+
message: error instanceof Error ? error.message : String(error)
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
const typedActionName = actionName;
|
|
505
|
+
notifyHostActionListeners({
|
|
506
|
+
actionName: typedActionName,
|
|
507
|
+
payload: call.payload,
|
|
508
|
+
context,
|
|
509
|
+
acknowledgement,
|
|
510
|
+
invocationKind: "rpc",
|
|
511
|
+
roomId: runtime.roomId,
|
|
512
|
+
storeDomain: call.storeDomain
|
|
513
|
+
});
|
|
514
|
+
return acknowledgement;
|
|
515
|
+
};
|
|
516
|
+
const documentOf = (state) => stripActionsFromState(state);
|
|
517
|
+
const publishOptions = {
|
|
518
|
+
fingerprint: shapeFingerprint,
|
|
519
|
+
...privateField ? { private: privateField } : {}
|
|
520
|
+
};
|
|
521
|
+
let hostRevision = 0;
|
|
522
|
+
const bindHost = (room, channel, session) => {
|
|
523
|
+
room.publish(channel, documentOf(store.getState()), publishOptions);
|
|
524
|
+
const unsubscribe = store.subscribe((state) => {
|
|
525
|
+
hostRevision += 1;
|
|
526
|
+
room.publish(channel, documentOf(state), publishOptions);
|
|
527
|
+
});
|
|
528
|
+
const stopRestore = room.onRestore(channel, (copy) => {
|
|
529
|
+
if (copy.fingerprint !== shapeFingerprint) {
|
|
530
|
+
session.emitDevEvent?.({
|
|
531
|
+
event: AIRJAM_DEV_LOG_EVENTS.host.stateRestoreDiscarded,
|
|
532
|
+
level: "info",
|
|
533
|
+
role: "host",
|
|
534
|
+
roomId: runtimeSnapshotRef.current.roomId ?? void 0,
|
|
535
|
+
message: "Host kept fresh state because the restored store shape changed",
|
|
536
|
+
data: { storeDomain: channel, reason: "shape_changed" }
|
|
537
|
+
});
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
store.setState(
|
|
541
|
+
stripActionsFromState({
|
|
542
|
+
...store.getState(),
|
|
543
|
+
...copy.document
|
|
544
|
+
})
|
|
545
|
+
);
|
|
546
|
+
});
|
|
547
|
+
const stopAnswering = room.answer(channel, (request) => {
|
|
548
|
+
const controlTarget = session.controlTarget;
|
|
549
|
+
const roomId = runtimeSnapshotRef.current.roomId;
|
|
550
|
+
if (controlTarget && roomId && isHostRuntimeParticipantLeased(controlTarget, roomId, request.seat))
|
|
551
|
+
return createServerRejectedActionResult(
|
|
552
|
+
"participant_control_leased",
|
|
553
|
+
"This controller is owned by a participant-control lease."
|
|
554
|
+
);
|
|
555
|
+
return dispatchActionCall({
|
|
556
|
+
actionName: request.name,
|
|
557
|
+
payload: request.payload,
|
|
558
|
+
storeDomain: channel,
|
|
559
|
+
actor: { id: request.seat, role: "controller" }
|
|
560
|
+
});
|
|
561
|
+
});
|
|
562
|
+
return () => {
|
|
563
|
+
unsubscribe();
|
|
564
|
+
stopRestore();
|
|
565
|
+
stopAnswering();
|
|
566
|
+
};
|
|
567
|
+
};
|
|
568
|
+
const registerControl = (controlTarget, roomId, channel) => {
|
|
569
|
+
const canUseHostControl = () => {
|
|
570
|
+
const runtime = runtimeSnapshotRef.current;
|
|
571
|
+
return runtime.room?.role === "host" && runtime.roomId === roomId;
|
|
572
|
+
};
|
|
573
|
+
return registerHostRuntimeActionStore(controlTarget, {
|
|
574
|
+
roomId,
|
|
575
|
+
storeDomain: channel,
|
|
576
|
+
stateEpoch,
|
|
577
|
+
contractStoreDomain: options?.storeDomain?.trim() || "default",
|
|
578
|
+
read: (controllerId) => {
|
|
579
|
+
if (!canUseHostControl()) throw new Error("host_runtime_not_ready");
|
|
580
|
+
return {
|
|
581
|
+
data: controllerId === void 0 ? stripActionsFromState(store.getState()) : projectState(
|
|
582
|
+
stripActionsFromState(store.getState()),
|
|
583
|
+
controllerId
|
|
584
|
+
),
|
|
585
|
+
revision: hostRevision
|
|
586
|
+
};
|
|
587
|
+
},
|
|
588
|
+
dispatchParticipant: ({ controllerId, actionName, payload }) => {
|
|
589
|
+
if (!canUseHostControl())
|
|
590
|
+
return createClientRejectedActionResult(
|
|
591
|
+
"host_runtime_not_ready",
|
|
592
|
+
"The owning host runtime is not ready for actions."
|
|
593
|
+
);
|
|
594
|
+
return dispatchActionCall({
|
|
595
|
+
actionName,
|
|
596
|
+
payload,
|
|
597
|
+
storeDomain: channel,
|
|
598
|
+
actor: { id: controllerId, role: "controller" }
|
|
599
|
+
});
|
|
600
|
+
},
|
|
601
|
+
invoke: async ({ actionName, payload }) => {
|
|
602
|
+
if (!canUseHostControl())
|
|
603
|
+
return createClientRejectedActionResult(
|
|
604
|
+
"host_runtime_not_ready",
|
|
605
|
+
"The owning host runtime is not ready for actions."
|
|
606
|
+
);
|
|
607
|
+
const actions = createDispatchedActions(store, { kind: "default" });
|
|
608
|
+
if (!Object.hasOwn(actions, actionName))
|
|
609
|
+
return createClientRejectedActionResult(
|
|
610
|
+
"action_not_found",
|
|
611
|
+
"The requested public action is not registered on this host store."
|
|
612
|
+
);
|
|
613
|
+
const invoke = actions[actionName];
|
|
614
|
+
return invoke(payload);
|
|
615
|
+
}
|
|
616
|
+
});
|
|
617
|
+
};
|
|
618
|
+
const bindController = (room, channel) => {
|
|
619
|
+
const mirror = (document) => store.setState(stripActionsFromState(document));
|
|
620
|
+
const current = room.document(channel);
|
|
621
|
+
if (current) mirror(current);
|
|
622
|
+
return room.onDocument(channel, mirror);
|
|
623
|
+
};
|
|
624
|
+
const resolveStoreDomain = (defaultStoreDomain) => {
|
|
625
|
+
const explicit = options?.storeDomain?.trim();
|
|
626
|
+
if (!explicit) return defaultStoreDomain;
|
|
627
|
+
return explicit.length > 128 ? explicit.slice(0, 128) : explicit;
|
|
628
|
+
};
|
|
629
|
+
let attachedSession = null;
|
|
630
|
+
const attach = (session) => {
|
|
631
|
+
if (attachedSession)
|
|
632
|
+
throw new Error(
|
|
633
|
+
"This Air Jam store is already attached to a running session."
|
|
634
|
+
);
|
|
635
|
+
attachedSession = session;
|
|
636
|
+
const channel = resolveStoreDomain(session.defaultStoreDomain);
|
|
637
|
+
let control = null;
|
|
638
|
+
const update = () => {
|
|
639
|
+
const connection = session.connection.getState();
|
|
640
|
+
runtimeSnapshotRef.current = {
|
|
641
|
+
room: session.room,
|
|
642
|
+
roomId: connection.roomId,
|
|
643
|
+
resolvedStoreDomain: channel,
|
|
644
|
+
controllerId: connection.controllerId,
|
|
645
|
+
connectedPlayerIds: connection.players.filter((player) => player.connected).map((player) => player.id).sort(),
|
|
646
|
+
now: session.now,
|
|
647
|
+
settings: session.settings
|
|
648
|
+
};
|
|
649
|
+
for (const release of [...sessionWaiters]) release();
|
|
650
|
+
const controlTarget = session.controlTarget;
|
|
651
|
+
const roomId = connection.roomId;
|
|
652
|
+
if (control?.roomId === roomId) return;
|
|
653
|
+
control?.release();
|
|
654
|
+
control = controlTarget && roomId && session.room.role === "host" ? { roomId, release: registerControl(controlTarget, roomId, channel) } : null;
|
|
655
|
+
};
|
|
656
|
+
const unsubscribe = session.connection.subscribe(update);
|
|
657
|
+
update();
|
|
658
|
+
const unbind = session.room.role === "host" ? bindHost(session.room, channel, session) : bindController(session.room, channel);
|
|
659
|
+
return () => {
|
|
660
|
+
unsubscribe();
|
|
661
|
+
unbind();
|
|
662
|
+
control?.release();
|
|
663
|
+
control = null;
|
|
664
|
+
attachedSession = null;
|
|
665
|
+
runtimeSnapshotRef.current = {
|
|
666
|
+
...runtimeSnapshotRef.current,
|
|
667
|
+
room: null,
|
|
668
|
+
roomId: null,
|
|
669
|
+
now: detachedClock
|
|
670
|
+
};
|
|
671
|
+
};
|
|
672
|
+
};
|
|
673
|
+
const subscribeHostActions = (listener, options2) => {
|
|
674
|
+
const actionNames = options2?.actionNames && options2.actionNames.length > 0 ? new Set(options2.actionNames) : null;
|
|
675
|
+
const registration = {
|
|
676
|
+
actionNames,
|
|
677
|
+
includeRejected: options2?.includeRejected ?? false,
|
|
678
|
+
listener
|
|
679
|
+
};
|
|
680
|
+
hostActionListeners.add(registration);
|
|
681
|
+
return () => {
|
|
682
|
+
hostActionListeners.delete(registration);
|
|
683
|
+
};
|
|
684
|
+
};
|
|
685
|
+
return {
|
|
686
|
+
api: store,
|
|
687
|
+
getState: store.getState,
|
|
688
|
+
getPrivateState: () => {
|
|
689
|
+
const controllerId = runtimeSnapshotRef.current.controllerId;
|
|
690
|
+
return controllerId && privateField ? privateEntries(store.getState())[controllerId] : void 0;
|
|
691
|
+
},
|
|
692
|
+
subscribe: store.subscribe,
|
|
693
|
+
actions: createDispatchedActions(store, { kind: "default" }),
|
|
694
|
+
asPlayer: (controllerId) => createDispatchedActions(store, { kind: "player", controllerId }),
|
|
695
|
+
subscribeHostActions,
|
|
696
|
+
attach,
|
|
697
|
+
replayAction: (call) => {
|
|
698
|
+
const runtime = runtimeSnapshotRef.current;
|
|
699
|
+
if (runtime.room?.role === "host" && call.storeDomain === runtime.resolvedStoreDomain)
|
|
700
|
+
dispatchActionCall(call);
|
|
701
|
+
},
|
|
702
|
+
get attached() {
|
|
703
|
+
return attachedSession !== null;
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// src/agent/agent-action.ts
|
|
709
|
+
var createActionError = (meta, message) => new Error(
|
|
710
|
+
`[${meta.contractKind ?? "action"}:${meta.gameId}.${meta.actionName}] ${message}`
|
|
711
|
+
);
|
|
712
|
+
var createAgentActionMetadata = (payload, options) => ({
|
|
713
|
+
description: options?.description,
|
|
714
|
+
payload: {
|
|
715
|
+
...payload,
|
|
716
|
+
description: options?.payloadDescription ?? payload.description
|
|
717
|
+
},
|
|
718
|
+
resultDescription: options?.resultDescription
|
|
719
|
+
});
|
|
720
|
+
var defineAgentActionInput = (parse, metadata) => ({
|
|
721
|
+
parse,
|
|
722
|
+
metadata
|
|
723
|
+
});
|
|
724
|
+
var parseFiniteNumber = (payload, meta) => {
|
|
725
|
+
const nextValue = typeof payload === "number" && Number.isFinite(payload) ? payload : typeof payload === "string" ? Number(payload) : Number.NaN;
|
|
726
|
+
if (!Number.isFinite(nextValue)) {
|
|
727
|
+
throw createActionError(meta, "expected a finite number payload");
|
|
728
|
+
}
|
|
729
|
+
return nextValue;
|
|
730
|
+
};
|
|
731
|
+
var parseStringValue = (payload, meta) => {
|
|
732
|
+
if (typeof payload !== "string") {
|
|
733
|
+
throw createActionError(meta, "expected a string payload");
|
|
734
|
+
}
|
|
735
|
+
return payload;
|
|
736
|
+
};
|
|
737
|
+
var parseBooleanValue = (payload, meta) => {
|
|
738
|
+
if (typeof payload === "boolean") {
|
|
739
|
+
return payload;
|
|
740
|
+
}
|
|
741
|
+
if (payload === "true" || payload === "1") {
|
|
742
|
+
return true;
|
|
743
|
+
}
|
|
744
|
+
if (payload === "false" || payload === "0") {
|
|
745
|
+
return false;
|
|
746
|
+
}
|
|
747
|
+
throw createActionError(meta, "expected a boolean payload");
|
|
748
|
+
};
|
|
749
|
+
var parseEnumValue = (values, payload, meta) => {
|
|
750
|
+
if (typeof payload !== "string" || !values.includes(payload)) {
|
|
751
|
+
throw createActionError(meta, `expected one of: ${values.join(", ")}`);
|
|
752
|
+
}
|
|
753
|
+
return payload;
|
|
754
|
+
};
|
|
755
|
+
var noneInput = (options) => defineAgentActionInput(
|
|
756
|
+
() => void 0,
|
|
757
|
+
createAgentActionMetadata({ kind: "none" }, options)
|
|
758
|
+
);
|
|
759
|
+
var numberInput = (options) => defineAgentActionInput(
|
|
760
|
+
parseFiniteNumber,
|
|
761
|
+
createAgentActionMetadata({ kind: "number" }, options)
|
|
762
|
+
);
|
|
763
|
+
var stringInput = (options) => defineAgentActionInput(
|
|
764
|
+
parseStringValue,
|
|
765
|
+
createAgentActionMetadata({ kind: "string" }, options)
|
|
766
|
+
);
|
|
767
|
+
var booleanInput = (options) => defineAgentActionInput(
|
|
768
|
+
parseBooleanValue,
|
|
769
|
+
createAgentActionMetadata({ kind: "boolean" }, options)
|
|
770
|
+
);
|
|
771
|
+
var enumInput = (values, options) => defineAgentActionInput(
|
|
772
|
+
(payload, meta) => parseEnumValue(values, payload, meta),
|
|
773
|
+
createAgentActionMetadata(
|
|
774
|
+
{
|
|
775
|
+
kind: "enum",
|
|
776
|
+
allowedValues: [...values]
|
|
777
|
+
},
|
|
778
|
+
options
|
|
779
|
+
)
|
|
780
|
+
);
|
|
781
|
+
var jsonInput = (options) => defineAgentActionInput(
|
|
782
|
+
(payload) => payload,
|
|
783
|
+
createAgentActionMetadata({ kind: "json" }, options)
|
|
784
|
+
);
|
|
785
|
+
function customInput(optionsOrParse, maybeParse) {
|
|
786
|
+
if (typeof optionsOrParse === "function") {
|
|
787
|
+
return defineAgentActionInput(
|
|
788
|
+
optionsOrParse,
|
|
789
|
+
createAgentActionMetadata({ kind: "json" })
|
|
790
|
+
);
|
|
791
|
+
}
|
|
792
|
+
if (typeof maybeParse === "function") {
|
|
793
|
+
return defineAgentActionInput(
|
|
794
|
+
maybeParse,
|
|
795
|
+
createAgentActionMetadata(
|
|
796
|
+
{
|
|
797
|
+
kind: optionsOrParse.payloadKind ?? "json",
|
|
798
|
+
allowedValues: optionsOrParse.allowedValues
|
|
799
|
+
},
|
|
800
|
+
optionsOrParse
|
|
801
|
+
)
|
|
802
|
+
);
|
|
803
|
+
}
|
|
804
|
+
throw new Error("Invalid agent action input definition.");
|
|
805
|
+
}
|
|
806
|
+
var zodInput = (schema, options) => defineAgentActionInput(
|
|
807
|
+
(payload, meta) => {
|
|
808
|
+
const result = schema.safeParse(payload);
|
|
809
|
+
if (result.success) {
|
|
810
|
+
return result.data;
|
|
811
|
+
}
|
|
812
|
+
const firstIssue = result.error.issues[0];
|
|
813
|
+
throw createActionError(
|
|
814
|
+
meta,
|
|
815
|
+
firstIssue?.message ?? "payload failed schema validation"
|
|
816
|
+
);
|
|
817
|
+
},
|
|
818
|
+
createAgentActionMetadata({ kind: "json" }, options)
|
|
819
|
+
);
|
|
820
|
+
var agentActionInput = {
|
|
821
|
+
none: noneInput,
|
|
822
|
+
number: numberInput,
|
|
823
|
+
string: stringInput,
|
|
824
|
+
boolean: booleanInput,
|
|
825
|
+
enum: enumInput,
|
|
826
|
+
json: jsonInput,
|
|
827
|
+
custom: customInput,
|
|
828
|
+
zod: zodInput
|
|
829
|
+
};
|
|
830
|
+
|
|
831
|
+
// src/core/game-description.ts
|
|
832
|
+
import { z } from "zod";
|
|
833
|
+
var airJamGameDescriptionSchema = z.object({
|
|
834
|
+
version: z.literal(1),
|
|
835
|
+
metadata: airJamGameMetadataSchema,
|
|
836
|
+
controllerPath: z.string(),
|
|
837
|
+
simulation: z.boolean(),
|
|
838
|
+
input: airJamInputDescriptionSchema.nullable(),
|
|
839
|
+
agent: agentContractDescriptionSchema.nullable(),
|
|
840
|
+
testing: z.boolean(),
|
|
841
|
+
settings: z.record(z.string(), airJamSettingSchema),
|
|
842
|
+
assets: airJamAssetsSchema,
|
|
843
|
+
theme: airJamThemeSchema
|
|
844
|
+
}).strict();
|
|
845
|
+
function describeAirJamGame(game) {
|
|
846
|
+
return airJamGameDescriptionSchema.parse({
|
|
847
|
+
version: 1,
|
|
848
|
+
metadata: game.metadata,
|
|
849
|
+
controllerPath: game.controllerPath,
|
|
850
|
+
simulation: Boolean(game.simulation),
|
|
851
|
+
input: game.input ?? null,
|
|
852
|
+
agent: game.agent ? createAirJamAgentEvaluator(game.agent).describe() : null,
|
|
853
|
+
testing: Boolean(game.testing),
|
|
854
|
+
settings: game.settings ?? {},
|
|
855
|
+
assets: game.assets ?? { sounds: {}, images: {}, files: {} },
|
|
856
|
+
theme: game.theme ?? { colors: {}, fonts: {} }
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
export {
|
|
860
|
+
AIR_JAM_HOSTED_ENVIRONMENTS,
|
|
861
|
+
AIR_JAM_INPUT_LOG_MAX_ENTRY_BYTES,
|
|
862
|
+
AIR_JAM_INPUT_LOG_MAX_GAME_MS,
|
|
863
|
+
ControllerInput,
|
|
864
|
+
ControllerRuntime,
|
|
865
|
+
HostRuntime,
|
|
866
|
+
SimulationClock,
|
|
867
|
+
acceptAirJamAction,
|
|
868
|
+
agentAction,
|
|
869
|
+
agentActionInput,
|
|
870
|
+
agentStore,
|
|
871
|
+
agentValuesToInputState,
|
|
872
|
+
airJamActionResultOf,
|
|
873
|
+
airJamAssetsSchema,
|
|
874
|
+
airJamGameDescriptionSchema,
|
|
875
|
+
airJamInputDescriptionSchema,
|
|
876
|
+
airJamInputLogSchema,
|
|
877
|
+
airJamSettingSchema,
|
|
878
|
+
airJamSettingsValuesSchema,
|
|
879
|
+
airJamThemeSchema,
|
|
880
|
+
arrows,
|
|
881
|
+
axis,
|
|
882
|
+
button,
|
|
883
|
+
createAirJamConfig,
|
|
884
|
+
createAirJamStore,
|
|
885
|
+
createConnectionStore,
|
|
886
|
+
createSeededRandom,
|
|
887
|
+
defineAirJamAgentContract,
|
|
888
|
+
defineAirJamAgentStores,
|
|
889
|
+
defineAirJamAssets,
|
|
890
|
+
defineAirJamGame,
|
|
891
|
+
defineAirJamInput,
|
|
892
|
+
defineAirJamInputBindings,
|
|
893
|
+
defineAirJamSettings,
|
|
894
|
+
defineAirJamSimulation,
|
|
895
|
+
defineAirJamTheme,
|
|
896
|
+
describeAirJamGame,
|
|
897
|
+
findHostedEnvironment,
|
|
898
|
+
getReconnectingPlayerIds,
|
|
899
|
+
isAirJamGame,
|
|
900
|
+
keyAxis,
|
|
901
|
+
keyStick,
|
|
902
|
+
openAirJamReplay,
|
|
903
|
+
rejectAirJamAction,
|
|
904
|
+
replayAirJamInputLog,
|
|
905
|
+
setting,
|
|
906
|
+
soundConfigSchema,
|
|
907
|
+
stick,
|
|
908
|
+
wasd
|
|
909
|
+
};
|
|
910
|
+
//# sourceMappingURL=core.js.map
|