@air-jam/sdk 0.1.4 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +627 -57
- package/dist/agent-tooling-BSMGBix9.d.cts +123 -0
- package/dist/agent-tooling-BSMGBix9.d.ts +123 -0
- package/dist/agent-tooling.cjs +83 -0
- package/dist/agent-tooling.cjs.map +1 -0
- package/dist/agent-tooling.d.cts +2 -0
- package/dist/agent-tooling.d.ts +2 -0
- package/dist/agent-tooling.js +17 -0
- package/dist/agent-tooling.js.map +1 -0
- package/dist/arcade/bridge/controller.cjs +749 -0
- package/dist/arcade/bridge/controller.cjs.map +1 -0
- package/dist/arcade/bridge/controller.d.cts +85 -0
- package/dist/arcade/bridge/controller.d.ts +85 -0
- package/dist/arcade/bridge/controller.js +33 -0
- package/dist/arcade/bridge/controller.js.map +1 -0
- package/dist/arcade/bridge/host.cjs +421 -0
- package/dist/arcade/bridge/host.cjs.map +1 -0
- package/dist/arcade/bridge/host.d.cts +73 -0
- package/dist/arcade/bridge/host.d.ts +73 -0
- package/dist/arcade/bridge/host.js +25 -0
- package/dist/arcade/bridge/host.js.map +1 -0
- package/dist/arcade/bridge/iframe.cjs +453 -0
- package/dist/arcade/bridge/iframe.cjs.map +1 -0
- package/dist/arcade/bridge/iframe.d.cts +80 -0
- package/dist/arcade/bridge/iframe.d.ts +80 -0
- package/dist/arcade/bridge/iframe.js +28 -0
- package/dist/arcade/bridge/iframe.js.map +1 -0
- package/dist/arcade/bridge.cjs +1067 -0
- package/dist/arcade/bridge.cjs.map +1 -0
- package/dist/arcade/bridge.d.cts +11 -0
- package/dist/arcade/bridge.d.ts +11 -0
- package/dist/arcade/bridge.js +76 -0
- package/dist/arcade/bridge.js.map +1 -0
- package/dist/arcade/host.cjs +481 -0
- package/dist/arcade/host.cjs.map +1 -0
- package/dist/arcade/host.d.cts +19 -0
- package/dist/arcade/host.d.ts +19 -0
- package/dist/arcade/host.js +14 -0
- package/dist/arcade/host.js.map +1 -0
- package/dist/arcade/surface.cjs +113 -0
- package/dist/arcade/surface.cjs.map +1 -0
- package/dist/arcade/surface.d.cts +14 -0
- package/dist/arcade/surface.d.ts +14 -0
- package/dist/arcade/surface.js +27 -0
- package/dist/arcade/surface.js.map +1 -0
- package/dist/arcade/url.cjs +544 -0
- package/dist/arcade/url.cjs.map +1 -0
- package/dist/arcade/url.d.cts +68 -0
- package/dist/arcade/url.d.ts +68 -0
- package/dist/arcade/url.js +29 -0
- package/dist/arcade/url.js.map +1 -0
- package/dist/arcade-runtime-url-BW-MUAOY.d.cts +28 -0
- package/dist/arcade-runtime-url-l8qj01Pg.d.ts +28 -0
- package/dist/arcade-surface-identity-CQxDpn_w.d.cts +16 -0
- package/dist/arcade-surface-identity-CQxDpn_w.d.ts +16 -0
- package/dist/arcade.cjs +1737 -0
- package/dist/arcade.cjs.map +1 -0
- package/dist/arcade.d.cts +18 -0
- package/dist/arcade.d.ts +18 -0
- package/dist/arcade.js +123 -0
- package/dist/arcade.js.map +1 -0
- package/dist/capabilities.cjs +39 -0
- package/dist/capabilities.cjs.map +1 -0
- package/dist/capabilities.d.cts +31 -0
- package/dist/capabilities.d.ts +31 -0
- package/dist/capabilities.js +12 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/chunk-32NYL7XI.js +539 -0
- package/dist/chunk-32NYL7XI.js.map +1 -0
- package/dist/chunk-3USU7GY2.js +54 -0
- package/dist/chunk-3USU7GY2.js.map +1 -0
- package/dist/chunk-7UXSWCZZ.js +32 -0
- package/dist/chunk-7UXSWCZZ.js.map +1 -0
- package/dist/chunk-BE6Z4SIT.js +65 -0
- package/dist/chunk-BE6Z4SIT.js.map +1 -0
- package/dist/chunk-CABEUV65.js +184 -0
- package/dist/chunk-CABEUV65.js.map +1 -0
- package/dist/chunk-CEJ5RFSG.js +288 -0
- package/dist/chunk-CEJ5RFSG.js.map +1 -0
- package/dist/chunk-EDRQIOCV.js +25 -0
- package/dist/chunk-EDRQIOCV.js.map +1 -0
- package/dist/chunk-EVZJA6RN.js +140 -0
- package/dist/chunk-EVZJA6RN.js.map +1 -0
- package/dist/chunk-FAT2KJ3K.js +238 -0
- package/dist/chunk-FAT2KJ3K.js.map +1 -0
- package/dist/chunk-IKKDONQL.js +1 -0
- package/dist/chunk-IKKDONQL.js.map +1 -0
- package/dist/chunk-JEHV5C2X.js +249 -0
- package/dist/chunk-JEHV5C2X.js.map +1 -0
- package/dist/chunk-JO2HR5PV.js +43 -0
- package/dist/chunk-JO2HR5PV.js.map +1 -0
- package/dist/chunk-JTF47B56.js +1 -0
- package/dist/chunk-JTF47B56.js.map +1 -0
- package/dist/chunk-KXAFI5OP.js +193 -0
- package/dist/chunk-KXAFI5OP.js.map +1 -0
- package/dist/chunk-LIXPF4P6.js +22 -0
- package/dist/chunk-LIXPF4P6.js.map +1 -0
- package/dist/chunk-MPDMJIX5.js +1 -0
- package/dist/chunk-MPDMJIX5.js.map +1 -0
- package/dist/chunk-NCL6WJCL.js +91 -0
- package/dist/chunk-NCL6WJCL.js.map +1 -0
- package/dist/chunk-NUJBMV3O.js +1435 -0
- package/dist/chunk-NUJBMV3O.js.map +1 -0
- package/dist/chunk-TGRTEWYV.js +195 -0
- package/dist/chunk-TGRTEWYV.js.map +1 -0
- package/dist/chunk-UWJOIVON.js +369 -0
- package/dist/chunk-UWJOIVON.js.map +1 -0
- package/dist/chunk-VKBMZHMQ.js +216 -0
- package/dist/chunk-VKBMZHMQ.js.map +1 -0
- package/dist/chunk-W2VK36RO.js +11 -0
- package/dist/chunk-W2VK36RO.js.map +1 -0
- package/dist/chunk-W3YA5BWR.js +126 -0
- package/dist/chunk-W3YA5BWR.js.map +1 -0
- package/dist/chunk-X24K52DG.js +12 -0
- package/dist/chunk-X24K52DG.js.map +1 -0
- package/dist/chunk-YXHH3MQT.js +230 -0
- package/dist/chunk-YXHH3MQT.js.map +1 -0
- package/dist/chunk-ZLPL2R3R.js +183 -0
- package/dist/chunk-ZLPL2R3R.js.map +1 -0
- package/dist/chunk-ZTQ5SP4H.js +9 -0
- package/dist/chunk-ZTQ5SP4H.js.map +1 -0
- package/dist/controller-Bod8YYr1.d.cts +172 -0
- package/dist/controller-DxVchfiA.d.ts +172 -0
- package/dist/dev-log-events-CVAM29hx.d.cts +123 -0
- package/dist/dev-log-events-CVAM29hx.d.ts +123 -0
- package/dist/handshake-CC_LrK5g.d.cts +31 -0
- package/dist/handshake-CC_LrK5g.d.ts +31 -0
- package/dist/host-8hmq_Sgc.d.cts +109 -0
- package/dist/host-Cw-N6e-5.d.ts +109 -0
- package/dist/index.cjs +8730 -3426
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +676 -1070
- package/dist/index.d.ts +676 -1070
- package/dist/index.js +4892 -3196
- package/dist/index.js.map +1 -1
- package/dist/metadata.cjs +114 -0
- package/dist/metadata.cjs.map +1 -0
- package/dist/metadata.d.cts +95 -0
- package/dist/metadata.d.ts +95 -0
- package/dist/metadata.js +83 -0
- package/dist/metadata.js.map +1 -0
- package/dist/notices-CnGaaS8B.d.ts +38 -0
- package/dist/notices-NyDM5Mtz.d.cts +38 -0
- package/dist/platform-machine.cjs +425 -0
- package/dist/platform-machine.cjs.map +1 -0
- package/dist/platform-machine.d.cts +1183 -0
- package/dist/platform-machine.d.ts +1183 -0
- package/dist/platform-machine.js +309 -0
- package/dist/platform-machine.js.map +1 -0
- package/dist/platform-settings-cuor3i11.d.cts +48 -0
- package/dist/platform-settings-cuor3i11.d.ts +48 -0
- package/dist/prefabs.cjs +36 -0
- package/dist/prefabs.cjs.map +1 -0
- package/dist/prefabs.d.cts +49 -0
- package/dist/prefabs.d.ts +49 -0
- package/dist/prefabs.js +8 -0
- package/dist/prefabs.js.map +1 -0
- package/dist/preview.cjs +2620 -0
- package/dist/preview.cjs.map +1 -0
- package/dist/preview.d.cts +155 -0
- package/dist/preview.d.ts +155 -0
- package/dist/preview.js +1671 -0
- package/dist/preview.js.map +1 -0
- package/dist/protocol.cjs +621 -54
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +76 -240
- package/dist/protocol.d.ts +76 -240
- package/dist/protocol.js +100 -2
- package/dist/protocol.js.map +1 -1
- package/dist/realtime-client-Cu8yVJFw.d.cts +15 -0
- package/dist/realtime-client-Cu8yVJFw.d.ts +15 -0
- package/dist/release.cjs +143 -0
- package/dist/release.cjs.map +1 -0
- package/dist/release.d.cts +64 -0
- package/dist/release.d.ts +64 -0
- package/dist/release.js +43 -0
- package/dist/release.js.map +1 -0
- package/dist/runtime-topology.cjs +405 -0
- package/dist/runtime-topology.cjs.map +1 -0
- package/dist/runtime-topology.d.cts +59 -0
- package/dist/runtime-topology.d.ts +59 -0
- package/dist/runtime-topology.js +31 -0
- package/dist/runtime-topology.js.map +1 -0
- package/dist/standard-match-phase-BucA5dYo.d.ts +44 -0
- package/dist/standard-match-phase-U2ra8J-0.d.cts +44 -0
- package/dist/sync-B6QsNrXz.d.cts +125 -0
- package/dist/sync-B6QsNrXz.d.ts +125 -0
- package/dist/ui.cjs +3061 -0
- package/dist/ui.cjs.map +1 -0
- package/dist/ui.d.cts +320 -0
- package/dist/ui.d.ts +320 -0
- package/dist/ui.js +1719 -0
- package/dist/ui.js.map +1 -0
- package/dist/url-policy-C89zxgw9.d.cts +9 -0
- package/dist/url-policy-C89zxgw9.d.ts +9 -0
- package/package.json +155 -10
- package/src/agent/agent-action.ts +304 -0
- package/src/agent/agent-contract.ts +180 -0
- package/src/agent-tooling.ts +20 -0
- package/src/arcade/bridge/controller.ts +15 -0
- package/src/arcade/bridge/host.ts +12 -0
- package/src/arcade/bridge/iframe.ts +61 -0
- package/src/arcade/bridge.ts +3 -0
- package/src/arcade/host.ts +1 -0
- package/src/arcade/surface.ts +4 -0
- package/src/arcade/url.ts +60 -0
- package/src/arcade.ts +4 -0
- package/src/audio/audio-manager.ts +162 -171
- package/src/audio/hooks.tsx +218 -97
- package/src/audio/index.ts +1 -1
- package/src/audio/music.tsx +139 -0
- package/src/capabilities/manifest.ts +71 -0
- package/src/capabilities.ts +12 -0
- package/src/components/connection-status-pill.tsx +55 -0
- package/src/components/controller-player-name-field.tsx +119 -0
- package/src/components/controller-primary-action.tsx +58 -0
- package/src/components/host-mute-button.tsx +49 -0
- package/src/components/join-qr-overlay.tsx +133 -0
- package/src/components/join-url-action-buttons.tsx +95 -0
- package/src/components/join-url-controls.tsx +58 -0
- package/src/components/join-url-field.tsx +52 -0
- package/src/components/lifecycle-action-group.tsx +129 -0
- package/src/components/player-avatar-strip.tsx +65 -0
- package/src/components/player-avatar.tsx +42 -13
- package/src/components/room-qr-code.tsx +125 -0
- package/src/components/runtime-shell-header.tsx +37 -0
- package/src/components/shell-classes.ts +19 -0
- package/src/components/surface-orientation-layout.ts +60 -0
- package/src/components/surface-viewport-layout.ts +268 -0
- package/src/components/surface-viewport.tsx +314 -0
- package/src/components/ui/button.tsx +4 -6
- package/src/components/ui/slider.tsx +1 -1
- package/src/components/volume-controls.tsx +65 -6
- package/src/context/air-jam-context.tsx +209 -161
- package/src/context/index.ts +2 -2
- package/src/context/session-providers.tsx +77 -0
- package/src/context/session-scope.ts +64 -0
- package/src/context/socket-manager.ts +6 -24
- package/src/contracts/v2/bridge.ts +261 -0
- package/src/contracts/v2/handshake.ts +40 -0
- package/src/contracts/v2/index.ts +2 -0
- package/src/dev/browser-log-sink.ts +912 -0
- package/src/diagnostics.ts +128 -0
- package/src/events.ts +7 -34
- package/src/hooks/internal/use-controller-runtime-api.ts +875 -0
- package/src/hooks/internal/use-host-runtime-api.ts +1051 -0
- package/src/hooks/internal/use-runtime-control-contract.ts +15 -0
- package/src/hooks/internal/use-runtime-inspection-contract.ts +16 -0
- package/src/hooks/internal/use-runtime-observability-contract.ts +24 -0
- package/src/hooks/use-air-jam-controller.ts +155 -475
- package/src/hooks/use-air-jam-host.ts +156 -485
- package/src/hooks/use-connection-status.ts +8 -0
- package/src/hooks/use-controller-lifecycle-intents.ts +27 -0
- package/src/hooks/use-controller-lifecycle-permissions.ts +36 -0
- package/src/hooks/use-controller-shell-status.ts +40 -0
- package/src/hooks/use-controller-tick.ts +65 -0
- package/src/hooks/use-controller-toasts.ts +116 -0
- package/src/hooks/use-get-input.ts +8 -5
- package/src/hooks/use-host-arcade-restore.ts +30 -0
- package/src/hooks/use-host-join-controls.ts +152 -0
- package/src/hooks/use-host-tick.ts +171 -0
- package/src/hooks/use-input-writer.ts +83 -0
- package/src/hooks/use-lifecycle-action-group-model.ts +98 -0
- package/src/hooks/use-players.ts +12 -0
- package/src/hooks/use-room.ts +22 -0
- package/src/hooks/use-send-signal.ts +6 -2
- package/src/index.ts +205 -31
- package/src/internal/input-manager.ts +195 -215
- package/src/lifecycle/index.ts +9 -0
- package/src/lifecycle/standard-match-phase.ts +32 -0
- package/src/metadata/manifest.ts +152 -0
- package/src/metadata.ts +12 -0
- package/src/platform-machine.ts +475 -0
- package/src/prefabs/types.ts +82 -0
- package/src/prefabs.ts +12 -0
- package/src/preview/host-workspace.tsx +59 -0
- package/src/preview/identity.ts +66 -0
- package/src/preview/layout.ts +223 -0
- package/src/preview/manager.ts +577 -0
- package/src/preview/messages.ts +26 -0
- package/src/preview/ownership.ts +81 -0
- package/src/preview/url.ts +117 -0
- package/src/preview/window.tsx +490 -0
- package/src/preview/workspace.tsx +678 -0
- package/src/preview.ts +42 -0
- package/src/protocol/arcade-platform-actions.ts +29 -0
- package/src/protocol/controller.ts +187 -0
- package/src/protocol/core.ts +23 -0
- package/src/protocol/dev-log-events.ts +222 -0
- package/src/protocol/errors.ts +21 -0
- package/src/protocol/host-grant.ts +185 -0
- package/src/protocol/host.ts +138 -0
- package/src/protocol/notices.ts +43 -0
- package/src/protocol/signals.ts +38 -0
- package/src/protocol/socket-events.ts +154 -0
- package/src/protocol/sync.ts +121 -0
- package/src/protocol/url-policy.ts +63 -0
- package/src/protocol.ts +12 -386
- package/src/qrcode.d.ts +16 -0
- package/src/release.ts +99 -0
- package/src/runtime/air-jam-config.ts +287 -0
- package/src/runtime/air-jam-error-boundary.tsx +672 -0
- package/src/runtime/arcade-bridge-request-surface.ts +15 -0
- package/src/runtime/arcade-runtime-url.ts +95 -0
- package/src/runtime/arcade-surface-identity.ts +16 -0
- package/src/runtime/contracts/control.ts +68 -0
- package/src/runtime/contracts/inspection.ts +165 -0
- package/src/runtime/contracts/observability.ts +94 -0
- package/src/runtime/controller-bridge.ts +451 -0
- package/src/runtime/controller-identity.ts +132 -0
- package/src/runtime/controller-presentation.ts +24 -0
- package/src/runtime/controller-realtime-client.ts +591 -0
- package/src/runtime/create-air-jam-app.tsx +260 -0
- package/src/runtime/dev-runtime-events.ts +36 -0
- package/src/runtime/embedded-runtime-adapters.ts +68 -0
- package/src/runtime/host-bridge.ts +388 -0
- package/src/runtime/host-realtime-client.ts +550 -0
- package/src/runtime/iframe-bridge.ts +135 -0
- package/src/runtime/realtime-client.ts +20 -0
- package/src/runtime/router-basename.ts +25 -0
- package/src/runtime/runtime-owner-contexts.tsx +4 -0
- package/src/runtime/runtime-session-params.ts +169 -0
- package/src/runtime/sdk-version.ts +6 -0
- package/src/runtime/session-runtimes.tsx +188 -0
- package/src/runtime/validate-arcade-bridge-attach.ts +14 -0
- package/src/runtime-control.ts +10 -0
- package/src/runtime-inspection.ts +14 -0
- package/src/runtime-observability.ts +9 -0
- package/src/runtime-topology.ts +569 -0
- package/src/settings/platform-settings-bridge.ts +336 -0
- package/src/settings/platform-settings-runtime.tsx +387 -0
- package/src/settings/platform-settings.ts +288 -0
- package/src/state/connection-store.ts +80 -12
- package/src/store/air-jam-store-domain-constants.ts +4 -0
- package/src/store/create-air-jam-store.ts +1094 -227
- package/src/styles.css +4 -38
- package/src/ui.ts +29 -0
- package/src/utils/is-rpc-serializable.ts +56 -0
- package/src/utils/player-avatar-url.ts +48 -0
- package/src/utils/url-builder.ts +7 -0
- package/dist/.tsbuildinfo +0 -1
- package/dist/chunk-B5DURUWT.js +0 -80
- package/dist/chunk-B5DURUWT.js.map +0 -1
- package/src/AirJamClient.ts +0 -224
- package/src/audio/volume-store.ts +0 -124
- package/src/components/controller-shell.tsx +0 -346
- package/src/components/host-shell.tsx +0 -520
- package/src/components/qr-scanner-dialog.tsx +0 -373
- package/src/components/ui/alert.tsx +0 -66
- package/src/components/ui/avatar.tsx +0 -46
- package/src/components/ui/badge.tsx +0 -47
- package/src/components/ui/card.tsx +0 -92
- package/src/components/ui/dialog.tsx +0 -122
- package/src/components/ui/tabs.tsx +0 -64
- package/src/hooks/use-air-jam-shell.ts +0 -379
- package/src/hooks/use-fullscreen.ts +0 -108
package/README.md
CHANGED
|
@@ -1,87 +1,657 @@
|
|
|
1
1
|
# @air-jam/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Core SDK for building Air Jam hosts and mobile controllers.
|
|
4
|
+
|
|
5
|
+
## Stability And Compatibility Policy
|
|
6
|
+
|
|
7
|
+
Air Jam SDK follows semver. What that means concretely for creators building
|
|
8
|
+
against v1:
|
|
9
|
+
|
|
10
|
+
1. **Durable v1 surface.** `@air-jam/sdk`, `@air-jam/sdk/ui`, and
|
|
11
|
+
`@air-jam/sdk/styles.css` are the stable authoring and UI lanes. Breaking
|
|
12
|
+
changes on these require a major version bump, and v1 will be kept working
|
|
13
|
+
for games for **at least 12 months** after v1.0.0 ships.
|
|
14
|
+
2. **Non-breaking v1.x.** Within the `1.x` line we commit to: no removals,
|
|
15
|
+
no incompatible type changes, and no silent behavior changes on the stable
|
|
16
|
+
lanes above. New functionality lands as additive APIs.
|
|
17
|
+
3. **Experimental leaves.** `@air-jam/sdk/preview`, `@air-jam/sdk/arcade*`,
|
|
18
|
+
`@air-jam/sdk/protocol`, `@air-jam/sdk/capabilities`,
|
|
19
|
+
`@air-jam/sdk/metadata`, and `@air-jam/sdk/prefabs` are intentionally
|
|
20
|
+
unstable future-facing seams. They may change within `1.x` — each carries
|
|
21
|
+
a documented purpose in its leaf, and changes are noted in release notes.
|
|
22
|
+
The agent-facing `runtime-control`, `runtime-inspection`,
|
|
23
|
+
`runtime-observability`, and `contracts/v2` seams exist in-source but are
|
|
24
|
+
**not exported publicly** until a first-party consumer lands; they will be
|
|
25
|
+
re-exported as explicit experimental leaves when that happens.
|
|
26
|
+
4. **v2 migration.** When v2 ships, we commit to publishing a codemod (or
|
|
27
|
+
migration notes if the surface is too narrow to automate) alongside the
|
|
28
|
+
release. v1 games will not be silently broken — the v1 SDK will remain
|
|
29
|
+
installable.
|
|
30
|
+
5. **Metadata and capability contracts.** The `defineAirJamGameMetadata` and
|
|
31
|
+
`defineAirJamGameCapabilities` helpers produce versioned, frozen objects.
|
|
32
|
+
Contract versions are bumped explicitly so the platform can accept mixed
|
|
33
|
+
versions during a transition window.
|
|
34
|
+
|
|
35
|
+
Games built against v1 should declare `supportedSdkRange: "^1.0.0"` in their
|
|
36
|
+
metadata unless they intentionally pin tighter.
|
|
37
|
+
|
|
38
|
+
## Three Lanes (Canonical)
|
|
39
|
+
|
|
40
|
+
1. `Input lane` (high frequency, transient):
|
|
41
|
+
`useControllerTick` + `useInputWriter` on controller, `host.getInput` / `useGetInput` on host.
|
|
42
|
+
2. `State lane` (replicated, host-authoritative):
|
|
43
|
+
`createAirJamStore` + `useActions` with `(ctx, payload)` action handlers.
|
|
44
|
+
3. `Signal lane` (out-of-band UX/system):
|
|
45
|
+
`sendSignal` / `sendSystemCommand` for haptics, toasts, room-level commands, and remote audio cues.
|
|
46
|
+
|
|
47
|
+
Do not mix lanes:
|
|
48
|
+
|
|
49
|
+
1. Do not send per-frame stick/button input through store actions.
|
|
50
|
+
2. Do not mutate authoritative game state via signals.
|
|
51
|
+
3. Do not dispatch state actions via `state.actions.*`; use `useStore.useActions()`.
|
|
4
52
|
|
|
5
53
|
## Installation
|
|
6
54
|
|
|
7
55
|
```bash
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
56
|
+
pnpm add @air-jam/sdk zod
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Minimal Setup
|
|
60
|
+
|
|
61
|
+
Use `defineAirJamGameMetadata` for catalog-facing identity and
|
|
62
|
+
`createAirJamApp` for runtime/session wiring. Platform submissions can still
|
|
63
|
+
edit metadata in the dashboard; the code export gives tooling a typed default
|
|
64
|
+
to prefill, validate, and compare against release artifacts.
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
import { createAirJamApp, env } from "@air-jam/sdk";
|
|
68
|
+
import { defineAirJamGameMetadata } from "@air-jam/sdk/metadata";
|
|
69
|
+
import { z } from "zod";
|
|
70
|
+
|
|
71
|
+
const inputSchema = z.object({
|
|
72
|
+
vector: z.object({ x: z.number(), y: z.number() }),
|
|
73
|
+
action: z.boolean(),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
export const gameMetadata = defineAirJamGameMetadata({
|
|
77
|
+
slug: "my-game",
|
|
78
|
+
name: "My Game",
|
|
79
|
+
tagline: "A short catalog pitch for players.",
|
|
80
|
+
category: "party",
|
|
81
|
+
minPlayers: 1,
|
|
82
|
+
maxPlayers: 4,
|
|
83
|
+
inputModalities: ["buttons", "touch"],
|
|
84
|
+
supportedSdkRange: "^1.0.0",
|
|
85
|
+
maintainer: { name: "Your Name" },
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
export const airjam = createAirJamApp({
|
|
89
|
+
runtime: env.vite(import.meta.env),
|
|
90
|
+
controllerPath: "/controller",
|
|
91
|
+
input: { schema: inputSchema },
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Production Auth Modes
|
|
96
|
+
|
|
97
|
+
There are two canonical production modes:
|
|
98
|
+
|
|
99
|
+
1. Static `appId` mode
|
|
100
|
+
2. Optional signed host-grant mode
|
|
101
|
+
|
|
102
|
+
Static `appId` mode is the default. Set:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
VITE_AIR_JAM_SERVER_URL=https://api.airjam.io
|
|
106
|
+
VITE_AIR_JAM_APP_ID=aj_app_your_app_id
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
If you want stricter ownership guarantees while keeping the game static, add:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
VITE_AIR_JAM_HOST_GRANT_ENDPOINT=/api/airjam/host-grant
|
|
11
113
|
```
|
|
12
114
|
|
|
13
|
-
|
|
115
|
+
and have that endpoint return:
|
|
14
116
|
|
|
15
|
-
|
|
117
|
+
```json
|
|
118
|
+
{ "hostGrant": "..." }
|
|
119
|
+
```
|
|
16
120
|
|
|
17
|
-
|
|
121
|
+
The SDK fetches the host grant automatically before `host:bootstrap`. Game code stays unchanged.
|
|
122
|
+
|
|
123
|
+
## Host Usage
|
|
124
|
+
|
|
125
|
+
Mount runtime ownership explicitly at the host boundary, then read it from child code with `useAirJamHost()`.
|
|
126
|
+
|
|
127
|
+
If a component only needs host session state, call `useAirJamHost(selector)` to
|
|
128
|
+
avoid rerendering on unrelated runtime fields.
|
|
129
|
+
Selectors receive state fields only; call `useAirJamHost()` when a component
|
|
130
|
+
also needs runtime controls such as `joinUrl`, `sendSignal`, or `getInput`.
|
|
18
131
|
|
|
19
132
|
```tsx
|
|
20
|
-
import { useAirJamHost } from "@air-jam/sdk";
|
|
21
|
-
|
|
22
|
-
function MyGame() {
|
|
23
|
-
const { roomId, joinUrl, connectionStatus, players } = useAirJamHost({
|
|
24
|
-
roomId: "MYROOM", // Optional: Custom room ID
|
|
25
|
-
maxPlayers: 4,
|
|
26
|
-
apiKey: process.env.AIR_JAM_API_KEY, // Required for production
|
|
27
|
-
onPlayerJoin: (player) => console.log("Player joined:", player),
|
|
28
|
-
onInput: (event) => {
|
|
29
|
-
console.log("Input from", event.controllerId, event.input);
|
|
30
|
-
},
|
|
31
|
-
});
|
|
133
|
+
import { AirJamHostRuntime, env, useAirJamHost } from "@air-jam/sdk";
|
|
32
134
|
|
|
33
|
-
|
|
135
|
+
const HostShell = () => (
|
|
136
|
+
<AirJamHostRuntime
|
|
137
|
+
topology={env.vite(import.meta.env).topology}
|
|
138
|
+
appId={import.meta.env.VITE_AIR_JAM_APP_ID}
|
|
139
|
+
input={{ schema: inputSchema }}
|
|
140
|
+
onPlayerJoin={(player) => console.log("joined", player.id)}
|
|
141
|
+
onPlayerLeave={(controllerId) => console.log("left", controllerId)}
|
|
142
|
+
>
|
|
143
|
+
<HostView />
|
|
144
|
+
</AirJamHostRuntime>
|
|
145
|
+
);
|
|
34
146
|
|
|
147
|
+
export const HostView = () => {
|
|
148
|
+
const host = useAirJamHost();
|
|
35
149
|
return (
|
|
36
|
-
<
|
|
37
|
-
<h1>Room: {roomId}</h1>
|
|
38
|
-
<p>
|
|
39
|
-
|
|
40
|
-
</
|
|
150
|
+
<section>
|
|
151
|
+
<h1>Room: {host.roomId}</h1>
|
|
152
|
+
<p>Status: {host.connectionStatus}</p>
|
|
153
|
+
<p>Join URL: {host.joinUrl}</p>
|
|
154
|
+
</section>
|
|
41
155
|
);
|
|
156
|
+
};
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Use `host.players` for gameplay-facing player iteration. Use `host.controllers`
|
|
160
|
+
when you need the richer controller-session roster with source
|
|
161
|
+
(`phone | preview | virtual`), connected state, and resume-lease metadata.
|
|
162
|
+
Use `host.resetRoom()` when you need a fresh empty room without restarting the
|
|
163
|
+
local backend.
|
|
164
|
+
|
|
165
|
+
Use `host.getInput(controllerId)` in your game loop.
|
|
166
|
+
|
|
167
|
+
Default input behavior:
|
|
168
|
+
|
|
169
|
+
- booleans: `pulse` (tap-safe consume-on-read)
|
|
170
|
+
- vectors: `latest` (continuous latest value)
|
|
171
|
+
|
|
172
|
+
Optional overrides are available via `input.behavior` (`pulse | hold | latest`).
|
|
173
|
+
|
|
174
|
+
### Migration From `input.latch`
|
|
175
|
+
|
|
176
|
+
If you previously used:
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
input: {
|
|
180
|
+
schema,
|
|
181
|
+
latch: {
|
|
182
|
+
booleanFields: ["action"],
|
|
183
|
+
vectorFields: ["vector"],
|
|
184
|
+
},
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Use:
|
|
189
|
+
|
|
190
|
+
```ts
|
|
191
|
+
input: {
|
|
192
|
+
schema,
|
|
193
|
+
behavior: {
|
|
194
|
+
pulse: ["action", "vector"],
|
|
195
|
+
},
|
|
42
196
|
}
|
|
43
197
|
```
|
|
44
198
|
|
|
45
|
-
|
|
199
|
+
Notes:
|
|
200
|
+
|
|
201
|
+
- most games can now remove input behavior config entirely (`input: { schema }`)
|
|
202
|
+
- booleans default to tap-safe `pulse`
|
|
203
|
+
- vectors default to `latest` (continuous)
|
|
204
|
+
|
|
205
|
+
## Controller Usage
|
|
46
206
|
|
|
47
|
-
|
|
207
|
+
Mount runtime ownership explicitly at the controller boundary, then read it from child code with `useAirJamController()`.
|
|
208
|
+
|
|
209
|
+
If a component only needs controller session state, call
|
|
210
|
+
`useAirJamController(selector)` to avoid rerendering on unrelated runtime
|
|
211
|
+
updates.
|
|
212
|
+
Selectors receive state fields only; call `useAirJamController()` when a
|
|
213
|
+
component also needs controls such as `sendSystemCommand`.
|
|
48
214
|
|
|
49
215
|
```tsx
|
|
50
|
-
import {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
216
|
+
import {
|
|
217
|
+
AirJamControllerRuntime,
|
|
218
|
+
env,
|
|
219
|
+
useAirJamController,
|
|
220
|
+
useControllerTick,
|
|
221
|
+
useInputWriter,
|
|
222
|
+
} from "@air-jam/sdk";
|
|
223
|
+
import { SurfaceViewport } from "@air-jam/sdk/ui";
|
|
224
|
+
|
|
225
|
+
const ControllerShell = () => (
|
|
226
|
+
<AirJamControllerRuntime
|
|
227
|
+
topology={env.vite(import.meta.env).topology}
|
|
228
|
+
appId={import.meta.env.VITE_AIR_JAM_APP_ID}
|
|
229
|
+
nickname="Player 1"
|
|
230
|
+
>
|
|
231
|
+
<ControllerView />
|
|
232
|
+
</AirJamControllerRuntime>
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
export const ControllerView = () => {
|
|
236
|
+
const controller = useAirJamController();
|
|
237
|
+
const writeInput = useInputWriter();
|
|
238
|
+
|
|
239
|
+
useControllerTick(
|
|
240
|
+
() => {
|
|
241
|
+
writeInput({
|
|
242
|
+
vector: { x: 0, y: 0 },
|
|
243
|
+
action: false,
|
|
244
|
+
});
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
enabled:
|
|
248
|
+
controller.connectionStatus === "connected" &&
|
|
249
|
+
controller.runtimeState === "playing",
|
|
250
|
+
intervalMs: 16,
|
|
251
|
+
},
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
return (
|
|
255
|
+
<SurfaceViewport orientation="portrait">
|
|
256
|
+
<section>
|
|
257
|
+
<button
|
|
258
|
+
onPointerDown={() =>
|
|
259
|
+
writeInput({
|
|
260
|
+
vector: { x: 0, y: 0 },
|
|
261
|
+
action: true, // one-shot pulses still valid
|
|
262
|
+
})
|
|
263
|
+
}
|
|
264
|
+
>
|
|
265
|
+
Action
|
|
266
|
+
</button>
|
|
267
|
+
</section>
|
|
268
|
+
</SurfaceViewport>
|
|
269
|
+
);
|
|
270
|
+
};
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
Controllers usually join via URL query param: `/controller?room=ABCD`.
|
|
274
|
+
|
|
275
|
+
Standalone controllers also keep one stable local device identity and the last
|
|
276
|
+
room-scoped controller binding. If the same phone refreshes or briefly
|
|
277
|
+
disconnects, the SDK automatically attempts to resume that controller binding
|
|
278
|
+
instead of creating a duplicate player.
|
|
279
|
+
|
|
280
|
+
The important rule is:
|
|
281
|
+
|
|
282
|
+
1. mount `AirJamHostRuntime` / `AirJamControllerRuntime` once per runtime surface
|
|
283
|
+
2. use `useAirJamHost()` / `useAirJamController()` only as read hooks below that boundary
|
|
284
|
+
3. wrap controller UI in `SurfaceViewport` and set its `orientation` there
|
|
285
|
+
|
|
286
|
+
When the controller runs inside Arcade, `SurfaceViewport` automatically publishes
|
|
287
|
+
its orientation to the parent Arcade chrome. The same component still handles
|
|
288
|
+
standalone controller layout, so games do not need a separate host-side
|
|
289
|
+
orientation bridge. Multiplayer game state should live in the networked stores
|
|
290
|
+
and replicate automatically.
|
|
291
|
+
|
|
292
|
+
## Preview Controllers (Experimental)
|
|
293
|
+
|
|
294
|
+
The preview-controller feature lives under the explicit experimental leaf:
|
|
295
|
+
|
|
296
|
+
```ts
|
|
297
|
+
import { HostPreviewControllerWorkspace } from "@air-jam/sdk/preview";
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
Use it when you want a fast local desktop tryout path without replacing the
|
|
301
|
+
normal phone-controller product model.
|
|
302
|
+
|
|
303
|
+
Important rules:
|
|
304
|
+
|
|
305
|
+
1. phone controllers remain the canonical product experience
|
|
306
|
+
2. preview controllers are not a second topology or fake simulator path
|
|
307
|
+
3. preview controllers use the real controller route and join the same room as normal controllers
|
|
308
|
+
4. production should stay explicit opt-in
|
|
309
|
+
|
|
310
|
+
The preview workspace also exposes local recovery controls:
|
|
311
|
+
|
|
312
|
+
1. source-aware `Kick` controls for room controllers
|
|
313
|
+
2. `Reset room`, which creates a fresh empty room and reloads the local host page
|
|
314
|
+
|
|
315
|
+
Recommended host usage:
|
|
316
|
+
|
|
317
|
+
```tsx
|
|
318
|
+
import { HostPreviewControllerWorkspace } from "@air-jam/sdk/preview";
|
|
319
|
+
|
|
320
|
+
export const HostView = () => {
|
|
321
|
+
const previewControllersEnabled = import.meta.env.DEV;
|
|
322
|
+
|
|
323
|
+
return (
|
|
324
|
+
<>
|
|
325
|
+
<GameCanvas />
|
|
326
|
+
<HostPreviewControllerWorkspace enabled={previewControllersEnabled} />
|
|
327
|
+
</>
|
|
328
|
+
);
|
|
329
|
+
};
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
The shared preview leaf currently provides:
|
|
333
|
+
|
|
334
|
+
1. `HostPreviewControllerWorkspace` for normal host-surface mounting
|
|
335
|
+
2. `PreviewControllerWorkspace` and `PreviewControllerWindow` for lower-level composition
|
|
336
|
+
3. `usePreviewControllerManager` for host-local preview session state
|
|
337
|
+
4. `buildPreviewControllerUrl` and related launch helpers for explicit launch control
|
|
338
|
+
|
|
339
|
+
The floating window chrome also supports per-window portrait/landscape rotation,
|
|
340
|
+
and active preview-window opacity is driven by the shared platform settings
|
|
341
|
+
runtime so hosts can persist their preferred transparency level.
|
|
342
|
+
|
|
343
|
+
Keep preview usage inside explicit host-side UI and do not treat it as a stable
|
|
344
|
+
root-SDK contract yet.
|
|
345
|
+
|
|
346
|
+
## Runtime Contract Seams (In-Source, Not Public Exports)
|
|
347
|
+
|
|
348
|
+
Air Jam also carries agent-facing runtime seams for control, inspection, and
|
|
349
|
+
observability. Those modules still exist in-source, but they are **not public
|
|
350
|
+
package exports in v1**, so consumers should not import:
|
|
351
|
+
|
|
352
|
+
1. `@air-jam/sdk/runtime-control`
|
|
353
|
+
2. `@air-jam/sdk/runtime-inspection`
|
|
354
|
+
3. `@air-jam/sdk/runtime-observability`
|
|
355
|
+
4. `@air-jam/sdk/contracts/v2`
|
|
67
356
|
|
|
68
|
-
|
|
357
|
+
Current policy:
|
|
358
|
+
|
|
359
|
+
1. keep these seams private until a real first-party consumer lands
|
|
360
|
+
2. treat them as future agent-facing homes for bots, tests, previews, and agent tooling
|
|
361
|
+
3. re-export them later as explicit experimental leaves instead of implying they are stable root-SDK contracts
|
|
362
|
+
|
|
363
|
+
## Prefab Contract Leaf (Experimental)
|
|
364
|
+
|
|
365
|
+
Prefab definitions should live under a stable, scanable contract instead of
|
|
366
|
+
drifting between scene glue, render layers, and runtime population code.
|
|
367
|
+
|
|
368
|
+
The first prefab contract helpers now live under the explicit experimental leaf:
|
|
369
|
+
|
|
370
|
+
```ts
|
|
371
|
+
import {
|
|
372
|
+
createPrefabCatalog,
|
|
373
|
+
definePrefab,
|
|
374
|
+
type PrefabDefinition,
|
|
375
|
+
} from "@air-jam/sdk/prefabs";
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
Use this leaf when you need a canonical prefab definition that future tooling
|
|
379
|
+
can scan, preview, configure, and catalog.
|
|
380
|
+
|
|
381
|
+
Important rules:
|
|
382
|
+
|
|
383
|
+
1. this leaf defines prefab contracts, not a prefab runtime or editor
|
|
384
|
+
2. keep prefab definitions separate from scene population, pooling, or runtime spawn systems
|
|
385
|
+
3. keep larger gameplay behavior in domain, engine, or adapter modules instead of burying it inside prefab metadata
|
|
386
|
+
4. treat this as the future-facing namespace for Studio and agent-oriented prefab tooling
|
|
387
|
+
|
|
388
|
+
Current scope:
|
|
389
|
+
|
|
390
|
+
1. `definePrefab(...)` for a stable prefab definition shape
|
|
391
|
+
2. `createPrefabCatalog(...)` for a game-owned prefab registry export
|
|
392
|
+
3. shared preview and placement descriptor types for future Studio/catalog work
|
|
393
|
+
|
|
394
|
+
## Controller Feedback Helpers
|
|
395
|
+
|
|
396
|
+
Use explicit audio ownership at each host/controller surface boundary, then consume that runtime-owned manager below it. `AudioRuntime` is role-aware: controller surfaces automatically receive host-triggered remote sounds.
|
|
397
|
+
|
|
398
|
+
```tsx
|
|
399
|
+
import { AudioRuntime, useAudio, useControllerToasts } from "@air-jam/sdk";
|
|
400
|
+
|
|
401
|
+
const manifest = {
|
|
402
|
+
hit: { src: ["/sounds/hit.wav"] },
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
const ControllerHud = () => {
|
|
406
|
+
const audio = useAudio();
|
|
407
|
+
const { latestToast } = useControllerToasts();
|
|
408
|
+
|
|
409
|
+
return latestToast ? <p>{latestToast.message}</p> : null;
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
const ControllerShell = () => (
|
|
413
|
+
<AudioRuntime manifest={manifest}>
|
|
414
|
+
<ControllerHud />
|
|
415
|
+
</AudioRuntime>
|
|
416
|
+
);
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
Host-side `sendSignal("TOAST", ...)` now pairs directly with `useControllerToasts()`.
|
|
420
|
+
Mount `AudioRuntime` once per runtime surface, then call `useAudio()` only below that boundary.
|
|
421
|
+
|
|
422
|
+
## Shared Platform Settings
|
|
423
|
+
|
|
424
|
+
Shared user settings are platform-owned and inherited by embedded games.
|
|
425
|
+
|
|
426
|
+
Mount `PlatformSettingsRuntime` once in the platform shell when you want a persisted owner runtime.
|
|
427
|
+
`AirJamHostRuntime` / `AirJamControllerRuntime` already provide a settings boundary for games, so repo games should not wrap each host/controller surface in another redundant `PlatformSettingsRuntime`.
|
|
428
|
+
|
|
429
|
+
```tsx
|
|
430
|
+
import {
|
|
431
|
+
PlatformSettingsRuntime,
|
|
432
|
+
useInheritedPlatformSettings,
|
|
433
|
+
usePlatformAudioSettings,
|
|
434
|
+
} from "@air-jam/sdk";
|
|
435
|
+
|
|
436
|
+
const ArcadeShell = () => (
|
|
437
|
+
<PlatformSettingsRuntime persistence="local">
|
|
438
|
+
<SettingsPanel />
|
|
439
|
+
<EmbeddedGame />
|
|
440
|
+
</PlatformSettingsRuntime>
|
|
441
|
+
);
|
|
442
|
+
|
|
443
|
+
const SettingsPanel = () => {
|
|
444
|
+
const { masterVolume, setMasterVolume } = usePlatformAudioSettings();
|
|
445
|
+
return (
|
|
446
|
+
<button onClick={() => setMasterVolume(masterVolume === 0 ? 1 : 0)}>
|
|
447
|
+
Toggle Master
|
|
448
|
+
</button>
|
|
449
|
+
);
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
const EmbeddedGame = () => {
|
|
453
|
+
const settings = useInheritedPlatformSettings();
|
|
454
|
+
return <pre>{JSON.stringify(settings.audio, null, 2)}</pre>;
|
|
455
|
+
};
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
Rules:
|
|
459
|
+
|
|
460
|
+
1. mount `PlatformSettingsRuntime persistence="local"` once in the platform shell
|
|
461
|
+
2. let `airjam.Host`, `airjam.Controller`, `AirJamHostRuntime`, and `AirJamControllerRuntime` supply the in-game settings boundary automatically
|
|
462
|
+
3. embedded games inherit platform settings read-only
|
|
463
|
+
4. keep platform settings limited to shared cross-game concerns like audio, accessibility, and feedback
|
|
464
|
+
5. do not recreate feature-specific global settings stores alongside this runtime
|
|
465
|
+
|
|
466
|
+
## Optional UI Primitives
|
|
467
|
+
|
|
468
|
+
`@air-jam/sdk/ui` exports optional presentational primitives (`Button`, `Slider`, `PlayerAvatar`, `VolumeControls`).
|
|
469
|
+
These components are lifecycle-free: they do not create sockets or own host/controller session state.
|
|
470
|
+
`VolumeControls` reads and writes the shared audio slice through the platform settings runtime.
|
|
471
|
+
|
|
472
|
+
## Networked State (Host Source of Truth)
|
|
473
|
+
|
|
474
|
+
Use `createAirJamStore` for shared game state synced from host to controllers.
|
|
475
|
+
|
|
476
|
+
```tsx
|
|
477
|
+
import { createAirJamStore } from "@air-jam/sdk";
|
|
478
|
+
|
|
479
|
+
interface RuntimeState {
|
|
480
|
+
phase: "lobby" | "playing";
|
|
481
|
+
actions: {
|
|
482
|
+
setPhase: (
|
|
483
|
+
ctx: {
|
|
484
|
+
actorId: string;
|
|
485
|
+
role: "controller" | "host";
|
|
486
|
+
connectedPlayerIds: string[];
|
|
487
|
+
},
|
|
488
|
+
payload: { phase: "lobby" | "playing" },
|
|
489
|
+
) => void;
|
|
490
|
+
};
|
|
69
491
|
}
|
|
492
|
+
|
|
493
|
+
export const useGameStore = createAirJamStore<RuntimeState>((set) => ({
|
|
494
|
+
phase: "lobby",
|
|
495
|
+
actions: {
|
|
496
|
+
setPhase: (_ctx, { phase }) => set({ phase }),
|
|
497
|
+
},
|
|
498
|
+
}));
|
|
499
|
+
|
|
500
|
+
const actions = useGameStore.useActions();
|
|
501
|
+
actions.setPhase({ phase: "playing" });
|
|
70
502
|
```
|
|
71
503
|
|
|
72
|
-
|
|
504
|
+
Use `useGameStore.useActions()` for action dispatch. On controllers, action calls are proxied to the host automatically and actor identity is attached by the server.
|
|
505
|
+
|
|
506
|
+
Important identity rule:
|
|
507
|
+
|
|
508
|
+
1. `ctx.actorId` is always the identity of the dispatcher
|
|
509
|
+
2. if host code calls `useActions()`, then `ctx.actorId === "host"`
|
|
510
|
+
3. if host code intentionally wants to run the same semantic action as controller `X`, use `useGameStore.asPlayer("X")` instead of smuggling `controllerId` through an unrelated payload
|
|
511
|
+
|
|
512
|
+
Every action dispatch now resolves to an acknowledgement:
|
|
513
|
+
|
|
514
|
+
1. `{ ok: true, status: "accepted", source, result? }`
|
|
515
|
+
2. `{ ok: false, status: "rejected", source, reason, message, details? }`
|
|
516
|
+
|
|
517
|
+
Networked action contract:
|
|
518
|
+
|
|
519
|
+
1. `() => Promise<ack>` for no-payload actions
|
|
520
|
+
2. `(payloadObject) => Promise<ack>` for payload actions
|
|
521
|
+
3. payload roots must be plain objects, not primitives, arrays, DOM events, or `T | undefined` unions
|
|
522
|
+
4. if an action has no payload, omit it entirely instead of using `undefined` as part of an object-union payload type
|
|
523
|
+
|
|
524
|
+
Action context includes `connectedPlayerIds`, so host actions can prune stale assignments without custom presence-sync actions.
|
|
525
|
+
|
|
526
|
+
For host-only local side effects such as sounds, local sim refs, or one-shot animations, use the store's host action listener seam instead of queueing ephemeral commands through replicated state:
|
|
527
|
+
|
|
528
|
+
```tsx
|
|
529
|
+
useGameStore.useHostActionListener((event) => {
|
|
530
|
+
if (event.actionName !== "fireProjectile") {
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
projectileRuntimeRef.current.spawn(event.payload);
|
|
535
|
+
});
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
For explicit host-side player impersonation, use the host-only player-action lane:
|
|
539
|
+
|
|
540
|
+
```tsx
|
|
541
|
+
const playerActions = useGameStore.asPlayer("ctrl_2");
|
|
542
|
+
|
|
543
|
+
await playerActions.joinTeam({ team: "red" });
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
When a store action should return an explicit semantic result or rejection, use
|
|
547
|
+
`acceptAirJamAction(...)` and `rejectAirJamAction(...)`:
|
|
548
|
+
|
|
549
|
+
```tsx
|
|
550
|
+
import {
|
|
551
|
+
acceptAirJamAction,
|
|
552
|
+
createAirJamStore,
|
|
553
|
+
rejectAirJamAction,
|
|
554
|
+
} from "@air-jam/sdk";
|
|
555
|
+
|
|
556
|
+
export const useGameStore = createAirJamStore((set) => ({
|
|
557
|
+
aliveByPlayerId: {} as Record<string, boolean>,
|
|
558
|
+
actions: {
|
|
559
|
+
fire: ({ actorId }) =>
|
|
560
|
+
set((state) => {
|
|
561
|
+
if (!actorId || state.aliveByPlayerId[actorId] === false) {
|
|
562
|
+
return rejectAirJamAction("player_dead", "Dead players cannot fire.");
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
return acceptAirJamAction({ cooldownMs: 4500 });
|
|
566
|
+
}),
|
|
567
|
+
},
|
|
568
|
+
}));
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
If an action returns `void`, Air Jam treats it as accepted automatically.
|
|
572
|
+
|
|
573
|
+
## Runtime Pause Controls
|
|
574
|
+
|
|
575
|
+
Runtime pause/play is independent from your game-owned match phase. Keep lobby,
|
|
576
|
+
playing, and ended state in your game store, and use explicit runtime commands
|
|
577
|
+
only for pause UI.
|
|
578
|
+
|
|
579
|
+
```tsx
|
|
580
|
+
const host = useAirJamHost();
|
|
581
|
+
|
|
582
|
+
<button
|
|
583
|
+
onClick={
|
|
584
|
+
host.runtimeState === "playing" ? host.pauseRuntime : host.resumeRuntime
|
|
585
|
+
}
|
|
586
|
+
>
|
|
587
|
+
{host.runtimeState === "playing" ? "Pause" : "Resume"}
|
|
588
|
+
</button>;
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
## One Correct Way (Default Path)
|
|
592
|
+
|
|
593
|
+
1. Define one `airjam` app config with `createAirJamApp`.
|
|
594
|
+
2. On controllers, publish input with `useControllerTick` + `useInputWriter`.
|
|
595
|
+
3. On hosts, read input with `getInput` / `useGetInput`.
|
|
596
|
+
4. For host gameplay loops, prefer `useHostTick(...)` over hand-rolled `requestAnimationFrame` or `setInterval` loops.
|
|
597
|
+
5. Keep replicated gameplay state in `createAirJamStore`.
|
|
598
|
+
6. Dispatch all store actions through `useActions()` zero-arg or payload-object calls and check the returned acknowledgement when outcome matters.
|
|
599
|
+
|
|
600
|
+
## Canonical `airjam.config.ts`
|
|
601
|
+
|
|
602
|
+
Keep one runtime/session declaration and use role wrappers directly in routes.
|
|
603
|
+
|
|
604
|
+
```tsx
|
|
605
|
+
import { createAirJamApp, env } from "@air-jam/sdk";
|
|
606
|
+
import { gameInputSchema } from "./types";
|
|
607
|
+
|
|
608
|
+
export const airjam = createAirJamApp({
|
|
609
|
+
runtime: env.vite(import.meta.env),
|
|
610
|
+
controllerPath: "/controller",
|
|
611
|
+
// Optional agent-facing contracts belong here too.
|
|
612
|
+
// agent: agentContract,
|
|
613
|
+
input: {
|
|
614
|
+
schema: gameInputSchema,
|
|
615
|
+
},
|
|
616
|
+
});
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
```tsx
|
|
620
|
+
import { Route, Routes } from "react-router-dom";
|
|
621
|
+
import { airjam } from "./airjam.config";
|
|
622
|
+
|
|
623
|
+
export const App = () => (
|
|
624
|
+
<Routes>
|
|
625
|
+
<Route
|
|
626
|
+
path="/"
|
|
627
|
+
element={
|
|
628
|
+
<airjam.Host>
|
|
629
|
+
<HostView />
|
|
630
|
+
</airjam.Host>
|
|
631
|
+
}
|
|
632
|
+
/>
|
|
633
|
+
<Route
|
|
634
|
+
path={airjam.paths.controller}
|
|
635
|
+
element={
|
|
636
|
+
<airjam.Controller>
|
|
637
|
+
<ControllerView />
|
|
638
|
+
</airjam.Controller>
|
|
639
|
+
}
|
|
640
|
+
/>
|
|
641
|
+
</Routes>
|
|
642
|
+
);
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
This keeps runtime config, host input schema, route path ownership, and optional agent-facing contracts in one place.
|
|
646
|
+
|
|
647
|
+
Optional future-facing game capability metadata should also live here, but the schema is intentionally experimental and lives in `@air-jam/sdk/capabilities`.
|
|
73
648
|
|
|
74
|
-
|
|
649
|
+
## Environment Variables
|
|
75
650
|
|
|
76
|
-
- `
|
|
77
|
-
- `
|
|
78
|
-
- `options.apiKey`: (Optional) Your Air Jam API Key (required for production).
|
|
79
|
-
- `options.onInput`: Callback for controller input.
|
|
80
|
-
- `options.onPlayerJoin`: Callback when a player joins.
|
|
81
|
-
- `options.onPlayerLeave`: Callback when a player leaves.
|
|
651
|
+
- `VITE_AIR_JAM_SERVER_URL` / `NEXT_PUBLIC_AIR_JAM_SERVER_URL`
|
|
652
|
+
- `VITE_AIR_JAM_APP_ID` / `NEXT_PUBLIC_AIR_JAM_APP_ID`
|
|
82
653
|
|
|
83
|
-
|
|
654
|
+
## Full Docs
|
|
84
655
|
|
|
85
|
-
-
|
|
86
|
-
-
|
|
87
|
-
- `connectionStatus`: Current connection state.
|
|
656
|
+
- Platform docs: https://airjam.io/docs
|
|
657
|
+
- Monorepo docs index: `docs/docs-index.md`
|