@air-jam/cli 0.9.3 → 1.0.0-beta.10
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 +128 -0
- package/dist/auth-profile.d.ts +5 -0
- package/dist/auth-profile.js +7 -0
- package/dist/auth-profile.js.map +1 -0
- package/dist/auth-sessions.d.ts +5 -0
- package/dist/auth-sessions.js +7 -0
- package/dist/auth-sessions.js.map +1 -0
- package/dist/chunk-7D4AYBAV.js +64 -0
- package/dist/chunk-7D4AYBAV.js.map +1 -0
- package/dist/chunk-LH7UO57C.js +23 -0
- package/dist/chunk-LH7UO57C.js.map +1 -0
- package/dist/chunk-PKTLVQXZ.js +82 -0
- package/dist/chunk-PKTLVQXZ.js.map +1 -0
- package/dist/chunk-SQE4NPZP.js +31 -0
- package/dist/chunk-SQE4NPZP.js.map +1 -0
- package/dist/{chunk-A4V2N4LX.js → chunk-U6V3HEBB.js} +6 -5
- package/dist/chunk-U6V3HEBB.js.map +1 -0
- package/dist/chunk-VEHNFPEO.js +224 -0
- package/dist/chunk-VEHNFPEO.js.map +1 -0
- package/dist/development.d.ts +4 -0
- package/dist/development.js +1 -1
- package/dist/game-analytics.d.ts +5 -0
- package/dist/game-analytics.js +7 -0
- package/dist/game-analytics.js.map +1 -0
- package/dist/game-app-id.d.ts +5 -0
- package/dist/game-app-id.js +7 -0
- package/dist/game-app-id.js.map +1 -0
- package/dist/game-media.d.ts +5 -0
- package/dist/game-media.js +7 -0
- package/dist/game-media.js.map +1 -0
- package/dist/index.js +688 -404
- package/dist/index.js.map +1 -1
- package/dist/scaffold.d.ts +8 -1
- package/dist/scaffold.js +6 -1
- package/dist/scaffold.js.map +1 -1
- package/package.json +8 -4
- package/runtime/local-network.d.mts +4 -6
- package/runtime/public-assets.mjs +62 -0
- package/runtime/source-fence.mjs +182 -0
- package/runtime/vite-config.d.mts +2 -1
- package/runtime/vite-config.mjs +6 -2
- package/runtime/vite-dev.mjs +18 -0
- package/runtime/vite-https.mjs +2 -3
- package/template-assets/bootstrap/AGENTS.md +56 -14
- package/template-assets/bootstrap/CLAUDE.md +0 -8
- package/template-assets/bootstrap/skills/airjam-mcp/SKILL.md +44 -0
- package/template-assets/bootstrap/skills/controller-ui/SKILL.md +2 -0
- package/template-assets/bootstrap/skills/game-architecture/SKILL.md +47 -3
- package/template-assets/bootstrap/skills/index.md +1 -1
- package/template-assets/bootstrap/skills/prefab-authoring/SKILL.md +10 -0
- package/template-assets/bootstrap/skills/r3f-3d-scene/SKILL.md +10 -0
- package/template-assets/documentation/for-agents/controller-ui/page.mdx +41 -2
- package/template-assets/documentation/for-agents/page.mdx +24 -2
- package/template-assets/documentation/for-agents/project-structure/page.mdx +0 -2
- package/template-assets/documentation/for-agents/state-and-rendering/page.mdx +19 -2
- package/template-assets/documentation/for-agents/supported-agents/page.mdx +18 -0
- package/template-assets/documentation/getting-started/debugging/page.mdx +7 -8
- package/template-assets/documentation/getting-started/dev-logs/page.mdx +0 -2
- package/template-assets/documentation/getting-started/game-ideas/page.mdx +1 -3
- package/template-assets/documentation/getting-started/introduction/page.mdx +71 -54
- package/template-assets/documentation/getting-started/migrating-legacy-games/page.mdx +308 -62
- package/template-assets/documentation/getting-started/quick-start/page.mdx +56 -79
- package/template-assets/documentation/how-it-works/architecture/page.mdx +91 -50
- package/template-assets/documentation/how-it-works/host-system/page.mdx +112 -109
- package/template-assets/documentation/manifest.json +112 -42
- package/template-assets/documentation/sdk/assets-and-theme/page.mdx +185 -0
- package/template-assets/documentation/sdk/hooks/page.mdx +108 -172
- package/template-assets/documentation/sdk/input-system/page.mdx +201 -231
- package/template-assets/documentation/sdk/networked-state/page.mdx +134 -52
- package/template-assets/documentation/sdk/settings/page.mdx +166 -0
- package/template-assets/documentation/sdk/ui-components/page.mdx +38 -27
- package/template-assets/managed/.airjam/ai-pack.json +65 -47
- package/template-assets/managed/docs/airjam/agent-gold-path.md +55 -7
- package/template-assets/managed/docs/airjam/agent-mcp.md +44 -0
- package/template-assets/managed/docs/airjam/composition-shell-contract.md +4 -0
- package/template-assets/managed/docs/airjam/debug-and-testing.md +18 -0
- package/template-assets/managed/docs/airjam/docs-index.md +18 -12
- package/template-assets/managed/docs/airjam/generated/architecture.md +91 -46
- package/template-assets/managed/docs/airjam/generated/assets-and-theme.md +188 -0
- package/template-assets/managed/docs/airjam/generated/controller-ui.md +41 -0
- package/template-assets/managed/docs/airjam/generated/debugging-and-logs.md +7 -6
- package/template-assets/managed/docs/airjam/generated/for-agents.md +24 -0
- package/template-assets/managed/docs/airjam/generated/game-ideas.md +1 -1
- package/template-assets/managed/docs/airjam/generated/host-system.md +112 -102
- package/template-assets/managed/docs/airjam/generated/input-system.md +199 -218
- package/template-assets/managed/docs/airjam/generated/introduction.md +71 -51
- package/template-assets/managed/docs/airjam/generated/migrating-legacy-games.md +308 -60
- package/template-assets/managed/docs/airjam/generated/networked-state.md +134 -50
- package/template-assets/managed/docs/airjam/generated/quick-start.md +56 -79
- package/template-assets/managed/docs/airjam/generated/sdk-hooks.md +108 -167
- package/template-assets/managed/docs/airjam/generated/settings.md +169 -0
- package/template-assets/managed/docs/airjam/generated/state-and-rendering.md +19 -0
- package/template-assets/managed/docs/airjam/generated/supported-agents.md +21 -0
- package/template-assets/managed/docs/airjam/generated/ui-components.md +38 -25
- package/template-assets/managed/docs/airjam/prefab-authoring.md +100 -0
- package/template-assets/managed/docs/airjam/preview-controllers.md +5 -2
- package/template-assets/managed/docs/airjam/r3f-3d-scene.md +66 -0
- package/template-assets/managed/docs/airjam/state-lanes-cookbook.md +15 -20
- package/dist/chunk-A4V2N4LX.js.map +0 -1
|
@@ -7,21 +7,17 @@ The Air Jam SDK provides React hooks for building multiplayer games. This page d
|
|
|
7
7
|
|
|
8
8
|
### `createAirJamApp`
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Declare the game once with `defineAirJamGame` from `@air-jam/sdk/core` in
|
|
11
|
+
`src/airjam.config.ts`. In `app.tsx`, `createAirJamApp(game, options)` binds that
|
|
12
|
+
declaration to the browser environment and returns `Host`, `Controller`,
|
|
13
|
+
`paths` and `session`. Its capacity comes from `game.metadata.maxPlayers`.
|
|
11
14
|
|
|
12
15
|
```tsx
|
|
13
16
|
import { createAirJamApp, env } from "@air-jam/sdk";
|
|
14
|
-
import {
|
|
17
|
+
import { airjam as game } from "./airjam.config";
|
|
15
18
|
|
|
16
|
-
const
|
|
17
|
-
vector: z.object({ x: z.number(), y: z.number() }),
|
|
18
|
-
timestamp: z.number(),
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
const airjam = createAirJamApp({
|
|
19
|
+
export const airjam = createAirJamApp(game, {
|
|
22
20
|
runtime: env.vite(import.meta.env),
|
|
23
|
-
controllerPath: "/controller",
|
|
24
|
-
input: { schema: inputSchema },
|
|
25
21
|
});
|
|
26
22
|
|
|
27
23
|
<Routes>
|
|
@@ -51,6 +47,11 @@ The provider automatically reads from these environment variables if props aren'
|
|
|
51
47
|
- `VITE_AIR_JAM_SERVER_URL` / `NEXT_PUBLIC_AIR_JAM_SERVER_URL` - WebSocket server URL
|
|
52
48
|
- `VITE_AIR_JAM_APP_ID` / `NEXT_PUBLIC_AIR_JAM_APP_ID` - Public app ID
|
|
53
49
|
|
|
50
|
+
Session runtimes mount only in the browser: `airjam.Host`, `airjam.Controller`
|
|
51
|
+
and `AirJamHostRuntime` / `AirJamControllerRuntime` from
|
|
52
|
+
`@air-jam/sdk/arcade/runtime` render nothing on the server, so a server-rendered
|
|
53
|
+
page emits nothing inside them until it hydrates.
|
|
54
|
+
|
|
54
55
|
---
|
|
55
56
|
|
|
56
57
|
### `useAirJamHost`
|
|
@@ -61,11 +62,11 @@ Call `useAirJamHost(selector)` when a component only needs a narrow slice of
|
|
|
61
62
|
host session state and you want to avoid rerendering on unrelated runtime
|
|
62
63
|
fields.
|
|
63
64
|
Selectors receive state fields only; call `useAirJamHost()` when a component
|
|
64
|
-
also needs runtime controls such as `joinUrl
|
|
65
|
+
also needs runtime controls such as `joinUrl` or `sendSignal`.
|
|
65
66
|
|
|
66
67
|
```tsx
|
|
67
68
|
import { useAirJamHost } from "@air-jam/sdk";
|
|
68
|
-
import { airjam } from "../
|
|
69
|
+
import { airjam } from "../app";
|
|
69
70
|
|
|
70
71
|
const HostShell = () => (
|
|
71
72
|
<airjam.Host
|
|
@@ -87,23 +88,21 @@ const HostView = () => {
|
|
|
87
88
|
// Return values
|
|
88
89
|
const {
|
|
89
90
|
roomId, // "ABCD" - The room code
|
|
90
|
-
joinUrl, //
|
|
91
|
+
joinUrl, // Phone join URL; empty when topology has no phone reach
|
|
92
|
+
localControllerUrl, // On-screen controllers on this computer only
|
|
91
93
|
joinUrlStatus, // "loading" | "ready" | "unavailable"
|
|
92
|
-
connectionStatus, // "connected" | "connecting" | "disconnected" | "idle"
|
|
93
|
-
players, // Array of
|
|
94
|
-
|
|
94
|
+
connectionStatus, // "connected" | "connecting" | "reconnecting" | "disconnected" | "idle"
|
|
95
|
+
players, // Array of AirJamPlayer, including phones that are away
|
|
96
|
+
queuePosition, // Place in a busy hosted service's queue, or null
|
|
95
97
|
runtimeState, // "playing" | "paused"
|
|
96
98
|
lastError, // Error message if any
|
|
97
99
|
mode, // "standalone" | "platform"
|
|
98
100
|
|
|
99
101
|
// Functions
|
|
100
|
-
getInput, // (controllerId: string) => Input | undefined
|
|
101
102
|
sendSignal, // Send haptics/toasts to controllers
|
|
102
|
-
sendState, // Publish lightweight controller presentation state
|
|
103
103
|
pauseRuntime, // Set runtimeState to "paused"
|
|
104
104
|
resumeRuntime, // Set runtimeState to "playing"
|
|
105
105
|
setRuntimeState, // Explicitly set "playing" | "paused"
|
|
106
|
-
reconnect, // Force reconnection
|
|
107
106
|
} = host;
|
|
108
107
|
|
|
109
108
|
return (
|
|
@@ -122,33 +121,18 @@ const HostView = () => {
|
|
|
122
121
|
};
|
|
123
122
|
```
|
|
124
123
|
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
Each player is a seat the room assigned (`p1`, `p2`, …). A phone that drops
|
|
125
|
+
keeps its seat for two minutes and shows `connected: false` meanwhile;
|
|
126
|
+
reconnecting is automatic.
|
|
127
127
|
|
|
128
|
-
|
|
128
|
+
Players' controls reach the game only in its simulation steps, through
|
|
129
|
+
`input(playerId)`; see [Input System](./input-system.md).
|
|
129
130
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
host.players.forEach((player) => {
|
|
134
|
-
const input = host.getInput(player.id);
|
|
135
|
-
if (!input) return;
|
|
136
|
-
|
|
137
|
-
// Move player based on joystick
|
|
138
|
-
movePlayer(player.id, input.vector);
|
|
139
|
-
|
|
140
|
-
// Handle button press (tap-safe pulse by default)
|
|
141
|
-
if (input.action) {
|
|
142
|
-
playerShoot(player.id);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
```
|
|
131
|
+
Pause and orientation are the only presentation the host sends phones
|
|
132
|
+
directly. Authoritative multiplayer state lives in the networked stores; a
|
|
133
|
+
short message for the players is a toast signal or a store field.
|
|
147
134
|
|
|
148
|
-
`
|
|
149
|
-
orientation, pause/play status, or short UI messages. It is not the primary
|
|
150
|
-
gameplay sync channel. Authoritative multiplayer state should live in the
|
|
151
|
-
networked stores and flow automatically through those boundaries.
|
|
135
|
+
A game whose `inputModalities` include `'joystick'` always gets a landscape controller; the SDK applies it, so do not set orientation; lay it out with `GamepadLayout` from `@air-jam/sdk/ui`: the stick under the left thumb, the actions under the right in a square the same size, and only short status between them.
|
|
152
136
|
|
|
153
137
|
**Sending Haptic Feedback:**
|
|
154
138
|
|
|
@@ -189,34 +173,6 @@ host.sendSignal("TOAST", {
|
|
|
189
173
|
|
|
190
174
|
---
|
|
191
175
|
|
|
192
|
-
### `useGetInput`
|
|
193
|
-
|
|
194
|
-
Lightweight hook for accessing input without triggering re-renders. Use in performance-critical components.
|
|
195
|
-
|
|
196
|
-
```tsx
|
|
197
|
-
import { useGetInput } from "@air-jam/sdk";
|
|
198
|
-
|
|
199
|
-
const Ship = ({ playerId }: { playerId: string }) => {
|
|
200
|
-
const getInput = useGetInput();
|
|
201
|
-
|
|
202
|
-
// This component won't re-render when connection state changes
|
|
203
|
-
useFrame(() => {
|
|
204
|
-
const input = getInput(playerId);
|
|
205
|
-
if (!input) return;
|
|
206
|
-
|
|
207
|
-
// Update ship position
|
|
208
|
-
shipRef.current.position.x += input.vector.x * SPEED;
|
|
209
|
-
shipRef.current.position.y += input.vector.y * SPEED;
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
return <mesh ref={shipRef}>...</mesh>;
|
|
213
|
-
};
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
**When to use `useGetInput` vs `useAirJamHost().getInput`:**
|
|
217
|
-
|
|
218
|
-
---
|
|
219
|
-
|
|
220
176
|
### `useSendSignal`
|
|
221
177
|
|
|
222
178
|
Lightweight hook for sending signals without triggering re-renders. Use in collision handlers.
|
|
@@ -251,81 +207,47 @@ updates.
|
|
|
251
207
|
Selectors receive state fields only; call `useAirJamController()` when a
|
|
252
208
|
component also needs controls such as `sendSystemCommand`.
|
|
253
209
|
|
|
254
|
-
|
|
255
|
-
|
|
210
|
+
A controller page keeps its seat's key for each room it joins, so a reload or a
|
|
211
|
+
dropped network returns the phone to the same seat.
|
|
256
212
|
|
|
257
213
|
```tsx
|
|
258
|
-
import {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
} from "@air-jam/sdk";
|
|
263
|
-
import { useRef } from "react";
|
|
264
|
-
import { airjam } from "../airjam.config";
|
|
214
|
+
import { useAirJamController } from "@air-jam/sdk";
|
|
215
|
+
import { ControlButton, Stick } from "@air-jam/sdk/ui";
|
|
216
|
+
import { airjam } from "../app";
|
|
217
|
+
import { shipInput } from "../game/contracts/input";
|
|
265
218
|
|
|
266
219
|
const ControllerShell = () => (
|
|
267
|
-
<airjam.Controller
|
|
268
|
-
roomId="ABCD"
|
|
269
|
-
nickname="Player1"
|
|
270
|
-
onState={(state) => {
|
|
271
|
-
if (state.message) {
|
|
272
|
-
showNotification(state.message);
|
|
273
|
-
}
|
|
274
|
-
}}
|
|
275
|
-
>
|
|
220
|
+
<airjam.Controller roomId="ABCD" nickname="Player1">
|
|
276
221
|
<ControllerView />
|
|
277
222
|
</airjam.Controller>
|
|
278
223
|
);
|
|
279
224
|
|
|
280
225
|
const ControllerView = () => {
|
|
281
226
|
const controller = useAirJamController();
|
|
282
|
-
const writeInput = useInputWriter();
|
|
283
|
-
const vectorRef = useRef({ x: 0, y: 0 });
|
|
284
|
-
const actionRef = useRef(false);
|
|
285
227
|
|
|
286
228
|
const {
|
|
287
229
|
roomId, // Room code (from URL or props)
|
|
288
|
-
controllerId, // This
|
|
230
|
+
controllerId, // This phone's seat ("p1", "p2", …)
|
|
289
231
|
connectionStatus, // Connection state
|
|
290
232
|
runtimeState, // "playing" | "paused"
|
|
291
|
-
controllerOrientation, //
|
|
292
|
-
stateMessage, // Optional message from host
|
|
233
|
+
controllerOrientation, // Declared session orientation; always landscape for joystick games
|
|
293
234
|
|
|
294
235
|
// Functions
|
|
295
|
-
sendSystemCommand, // "
|
|
236
|
+
sendSystemCommand, // "pause" | "resume"
|
|
296
237
|
setNickname, // Update nickname
|
|
297
238
|
setAvatarId, // Update avatar selection draft
|
|
298
239
|
updatePlayerProfile, // Patch live label/avatar when connected
|
|
299
240
|
selfPlayer, // This controller's player profile when known
|
|
300
|
-
|
|
241
|
+
leave, // Give up the seat
|
|
242
|
+
input, // This player's declared controls, which phone controls fill
|
|
301
243
|
} = controller;
|
|
302
244
|
|
|
303
|
-
// Canonical cadence for continuous controls:
|
|
304
|
-
// publish at a fixed tick with useControllerTick + useInputWriter.
|
|
305
|
-
useControllerTick(
|
|
306
|
-
() => {
|
|
307
|
-
writeInput({
|
|
308
|
-
vector: vectorRef.current,
|
|
309
|
-
action: actionRef.current,
|
|
310
|
-
timestamp: Date.now(),
|
|
311
|
-
});
|
|
312
|
-
},
|
|
313
|
-
{
|
|
314
|
-
enabled: connectionStatus === "connected" && runtimeState === "playing",
|
|
315
|
-
intervalMs: 16,
|
|
316
|
-
},
|
|
317
|
-
);
|
|
318
|
-
|
|
319
245
|
if (connectionStatus === "connecting") {
|
|
320
246
|
return <div>Connecting to room {roomId}...</div>;
|
|
321
247
|
}
|
|
322
248
|
|
|
323
|
-
if (connectionStatus === "
|
|
324
|
-
return
|
|
325
|
-
<div>
|
|
326
|
-
Disconnected. <button onClick={reconnect}>Retry</button>
|
|
327
|
-
</div>
|
|
328
|
-
);
|
|
249
|
+
if (connectionStatus === "reconnecting") {
|
|
250
|
+
return <div>Reconnecting…</div>;
|
|
329
251
|
}
|
|
330
252
|
|
|
331
253
|
return (
|
|
@@ -334,51 +256,66 @@ const ControllerView = () => {
|
|
|
334
256
|
<div className="mb-2 text-xs uppercase">
|
|
335
257
|
Layout {controllerOrientation}
|
|
336
258
|
</div>
|
|
337
|
-
<
|
|
338
|
-
|
|
339
|
-
vectorRef.current = { x, y };
|
|
340
|
-
}}
|
|
341
|
-
/>
|
|
342
|
-
<FireButton
|
|
343
|
-
onPress={() => (actionRef.current = true)}
|
|
344
|
-
onRelease={() => (actionRef.current = false)}
|
|
345
|
-
/>
|
|
259
|
+
<Stick control={shipInput.move} className="size-48 rounded-full" />
|
|
260
|
+
<ControlButton control={shipInput.fire}>Fire</ControlButton>
|
|
346
261
|
</div>
|
|
347
262
|
);
|
|
348
263
|
};
|
|
349
264
|
```
|
|
350
265
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
Fixed-cadence helper for controller loops. Use it with `useInputWriter` instead of hand-rolled `setInterval` loops.
|
|
266
|
+
Phone controls send the declared controls themselves; a controller runs no
|
|
267
|
+
send loop.
|
|
354
268
|
|
|
355
|
-
###
|
|
269
|
+
### Game simulation
|
|
356
270
|
|
|
357
|
-
|
|
358
|
-
|
|
271
|
+
A game's authoritative state that changes every step, such as positions,
|
|
272
|
+
timers and physics, lives in a declared simulation. The SDK steps it on the
|
|
273
|
+
host at a fixed rate with seeded randomness, so the same seed and inputs replay
|
|
274
|
+
the same game, in a browser or headless and faster than real time. It only
|
|
275
|
+
steps while the room is playing: pausing freezes the game and its game time.
|
|
359
276
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
- `mode: "fixed"` for deterministic fixed-step simulation loops.
|
|
277
|
+
```ts filename="src/game/engine/simulation.ts"
|
|
278
|
+
import { defineAirJamSimulation } from "@air-jam/sdk/core";
|
|
363
279
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
```tsx
|
|
370
|
-
useHostTick({
|
|
371
|
-
mode: "fixed",
|
|
372
|
-
intervalMs: 16,
|
|
373
|
-
onTick: ({ deltaSeconds }) => {
|
|
374
|
-
stepSimulation(deltaSeconds);
|
|
375
|
-
},
|
|
376
|
-
onFrame: ({ fixedStepAlpha }) => {
|
|
377
|
-
renderInterpolatedFrame(fixedStepAlpha);
|
|
280
|
+
export const simulation = defineAirJamSimulation<Sim, GameInput, SimEvent>({
|
|
281
|
+
stepMs: 1000 / 60,
|
|
282
|
+
create: ({ random }) => createSim(random),
|
|
283
|
+
step: (sim, { input, players, random, emit }) => {
|
|
284
|
+
advance(sim, players, input);
|
|
378
285
|
},
|
|
286
|
+
// What agents and tests see of the game, as plain JSON.
|
|
287
|
+
observe: (sim) => ({ fighters: sim.fighters }),
|
|
379
288
|
});
|
|
380
289
|
```
|
|
381
290
|
|
|
291
|
+
Declare it with `defineAirJamGame({ simulation })`. When its code is heavy, such
|
|
292
|
+
as a physics engine, declare a loader instead,
|
|
293
|
+
`simulation: () => import("./game/engine/simulation").then((m) => m.simulation)`,
|
|
294
|
+
so only the host downloads it and controllers stay small. The host draws and
|
|
295
|
+
plays feedback from it, never advances it:
|
|
296
|
+
|
|
297
|
+
- `useSimulationFrame(({ sim, alpha }) => draw(sim, alpha))` runs after every
|
|
298
|
+
display frame; `alpha` interpolates between steps.
|
|
299
|
+
- `useSimulationEvents((event) => playSound(event))` receives what `step`
|
|
300
|
+
emitted, such as a hit.
|
|
301
|
+
- `useSimulationSelector((sim) => value, isEqual?)` reads a value for UI, such
|
|
302
|
+
as a health bar or an entity list, re-rendering only when it changes.
|
|
303
|
+
- `useSimulation()` returns the clock itself.
|
|
304
|
+
- `const captureFrame = useHostAgentCapture((target, options) => drawAgentCanvas(canvas, target, options))`
|
|
305
|
+
optionally gives agents a sharper host render surface. Supporting browsers
|
|
306
|
+
already capture the visible host stage, including HTML lobbies and nested canvases;
|
|
307
|
+
this callback takes priority when it returns true. Returning false (for example,
|
|
308
|
+
before a game canvas mounts) uses the native stage instead.
|
|
309
|
+
Call `captureFrame()` immediately after
|
|
310
|
+
drawing the game and its HUD. The SDK owns the persistent capture canvas and
|
|
311
|
+
records native video at 30 fps; still observations use the same drawing callback.
|
|
312
|
+
Still observations and frame-based test clips encode JPEGs asynchronously. The
|
|
313
|
+
clip sampler skips ticks while encoding is pending rather than queueing frames.
|
|
314
|
+
If you call `captureAgentCanvas()` directly, await its image result.
|
|
315
|
+
|
|
316
|
+
Step code reads stores with `gameStore.getState()` and dispatches with
|
|
317
|
+
`gameStore.actions`; it never reads `Date.now()` or `Math.random()`.
|
|
318
|
+
|
|
382
319
|
**Auto Room Join from URL:**
|
|
383
320
|
|
|
384
321
|
Controllers automatically join rooms from URL query parameters:
|
|
@@ -395,16 +332,15 @@ This is how QR code scanning works—the host generates a URL with the room code
|
|
|
395
332
|
|
|
396
333
|
Use these only when integrating platform-specific runtime behavior.
|
|
397
334
|
|
|
398
|
-
###
|
|
335
|
+
### Room session access (escape hatch)
|
|
399
336
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
```
|
|
337
|
+
`host.room` and `controller.session` are the page's sessions in the room
|
|
338
|
+
(`@air-jam/sdk/room-session`). Networked stores and signals cover what games
|
|
339
|
+
need; reach for the session only for a channel of your own.
|
|
404
340
|
|
|
405
341
|
### Internal context hooks
|
|
406
342
|
|
|
407
|
-
`useAirJamContext`, `useAirJamConfig
|
|
343
|
+
`useAirJamContext`, `useAirJamConfig` and `useAirJamState` are intentionally internal and are not part of the root public SDK surface.
|
|
408
344
|
|
|
409
345
|
---
|
|
410
346
|
|
|
@@ -431,25 +367,23 @@ const unsubscribe = onAirJamDiagnostic((diagnostic) => {
|
|
|
431
367
|
| `AJ_CONFIG_MISSING_RUNTIME_TOPOLOGY` | Runtime config cannot resolve the complete topology contract. | Provide `topology` directly or enable environment resolution for a supported runtime mode. |
|
|
432
368
|
| `AJ_CONFIG_MISSING_APP_ID` | Production runtime started without canonical app ID config. | Set `VITE_AIR_JAM_APP_ID` / `NEXT_PUBLIC_AIR_JAM_APP_ID` or pass `appId` explicitly. |
|
|
433
369
|
| `AJ_STORE_ACTION_SESSION_NOT_READY` | Controller action dispatch attempted before role/room was ready. | Wait until room/session is established before dispatching store actions. |
|
|
434
|
-
| `AJ_STORE_ACTION_SOCKET_DISCONNECTED` | Controller state action dispatch attempted while socket disconnected. | Reconnect before dispatching action. |
|
|
435
370
|
| `AJ_STORE_ACTION_PAYLOAD_INVALID_SHAPE` | State action payload root was not omitted or a plain object. | Dispatch no payload or one plain object payload only. |
|
|
436
371
|
| `AJ_STORE_ACTION_PAYLOAD_NOT_SERIALIZABLE` | State action payload contained non-serializable values. | Use JSON-safe payload objects only (no functions/symbols/cycles). |
|
|
437
|
-
| `
|
|
438
|
-
| `
|
|
439
|
-
| `AJ_INPUT_WRITER_SESSION_NOT_READY` | Input writer called before room/controller identity was ready. | Start publish loop after controller connection/session is ready. |
|
|
440
|
-
| `AJ_INPUT_WRITER_SOCKET_DISCONNECTED` | Input writer called while controller socket was disconnected. | Reconnect before sending input. |
|
|
441
|
-
| `AJ_INPUT_WRITER_SCHEMA_INVALID` | Input payload failed runtime schema validation. | Match payload shape to configured input schema. |
|
|
372
|
+
| `AJ_INPUT_INVALID` | Input from a controller or agent did not match the declared controls. | Send each declared control in its kind's shape; leave out controls not in use. |
|
|
373
|
+
| `AJ_INPUT_NOT_DECLARED` | A phone control rendered where the game declares no controls. | Declare them with `defineAirJamGame({ input })` and render controls inside `<airjam.Controller>`. |
|
|
442
374
|
|
|
443
375
|
---
|
|
444
376
|
|
|
445
|
-
### `
|
|
377
|
+
### `AirJamPlayer`
|
|
446
378
|
|
|
447
379
|
```typescript
|
|
448
|
-
interface
|
|
449
|
-
id: string; //
|
|
380
|
+
interface AirJamPlayer {
|
|
381
|
+
id: string; // The seat the room assigned ("p1", "p2", …)
|
|
450
382
|
label: string; // Display name (e.g., "Player 1")
|
|
451
|
-
color
|
|
383
|
+
color: string; // Assigned color (e.g., "#FF5733")
|
|
452
384
|
avatarId?: string; // Preset avatar id chosen by the player
|
|
385
|
+
kind: "phone" | "preview" | "agent";
|
|
386
|
+
connected: boolean; // false while the phone is away
|
|
453
387
|
}
|
|
454
388
|
```
|
|
455
389
|
|
|
@@ -488,3 +422,10 @@ interface ToastSignalPayload {
|
|
|
488
422
|
duration?: number; // Optional duration in ms
|
|
489
423
|
}
|
|
490
424
|
```
|
|
425
|
+
|
|
426
|
+
## useAirJamSettings
|
|
427
|
+
|
|
428
|
+
Host rendering reads declared settings with `useAirJamSettings(gameSettings)`.
|
|
429
|
+
The hook returns typed current values and subscribes to accepted host updates.
|
|
430
|
+
Controllers read display values copied to replicated store state. See
|
|
431
|
+
[Game Settings](./settings.md) for the full contract.
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
<!-- Generated from content/docs/sdk/settings/page.mdx. Do not edit directly. -->
|
|
2
|
+
<!-- Canonical public doc: https://airjam.io/docs/sdk/settings -->
|
|
3
|
+
|
|
4
|
+
# Game Settings
|
|
5
|
+
|
|
6
|
+
Declare the numbers, switches and choices a creator tunes while playtesting in
|
|
7
|
+
`airjam.config.ts`. The host owns their values and revision. A live update takes
|
|
8
|
+
effect between simulation steps and is recorded for exact replay. While a
|
|
9
|
+
simulation declared as a loader is still loading, updates are refused, so a
|
|
10
|
+
replay starts from the settings the simulation was created with.
|
|
11
|
+
|
|
12
|
+
## Declare settings in core
|
|
13
|
+
|
|
14
|
+
Keep the declaration in a leaf module so the simulation can import its type
|
|
15
|
+
without importing the game config back again.
|
|
16
|
+
|
|
17
|
+
```ts filename="src/game/contracts/settings.ts"
|
|
18
|
+
import {
|
|
19
|
+
defineAirJamSettings,
|
|
20
|
+
setting,
|
|
21
|
+
type AirJamSettingsValues,
|
|
22
|
+
} from "@air-jam/sdk/core";
|
|
23
|
+
|
|
24
|
+
export const pongSettings = defineAirJamSettings({
|
|
25
|
+
ballSpeed: setting.number({
|
|
26
|
+
default: 360,
|
|
27
|
+
min: 180,
|
|
28
|
+
max: 720,
|
|
29
|
+
step: 10,
|
|
30
|
+
live: true,
|
|
31
|
+
label: "Ball speed",
|
|
32
|
+
unit: "px/s",
|
|
33
|
+
description: "How fast the ball crosses the court.",
|
|
34
|
+
}),
|
|
35
|
+
});
|
|
36
|
+
export type PongSettings = AirJamSettingsValues<typeof pongSettings>;
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Pass it as `defineAirJamGame({ settings: pongSettings, ... })`. Remove the
|
|
40
|
+
module constants it replaces. A lobby choice players make, such as
|
|
41
|
+
`pointsToWin`, remains replicated store state.
|
|
42
|
+
|
|
43
|
+
Keys are lower camel case. `setting.number` requires `default`, `min` and
|
|
44
|
+
`max`, with an optional positive `step`; use `step: 1` for whole numbers.
|
|
45
|
+
Steps are multiples of zero. `setting.boolean` requires a boolean `default`.
|
|
46
|
+
`setting.choice` takes a nonempty string tuple in `options` and a `default`
|
|
47
|
+
from that tuple; its value type is the union of those strings.
|
|
48
|
+
Every kind accepts `label`, `description` and `live`, which defaults to false;
|
|
49
|
+
numbers also accept a `unit` shown after the value.
|
|
50
|
+
|
|
51
|
+
The Air Jam platform draws every declared setting in its settings dialog under
|
|
52
|
+
the game's name, on the big screen and on phones, with no settings code in the
|
|
53
|
+
game: a switch for a boolean, segments for a few choices or steps, and a slider
|
|
54
|
+
with its value for a range. A setting that is not `live` waits for the game to
|
|
55
|
+
restart. The screen remembers the values per game and launches the game with
|
|
56
|
+
them next time; a remembered value the game no longer accepts reads as its
|
|
57
|
+
default.
|
|
58
|
+
`defineAirJamSettings` validates defaults immediately. The description returned
|
|
59
|
+
by `airjam.inspect_game` includes these descriptors in `declaration.settings`.
|
|
60
|
+
|
|
61
|
+
## Read the current values
|
|
62
|
+
|
|
63
|
+
Use the settings type as the fourth simulation type parameter:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
defineAirJamSimulation<State, Input, Event, PongSettings>({
|
|
67
|
+
stepMs: 1000 / 60,
|
|
68
|
+
create: ({ settings }) => createState(settings.ballSpeed),
|
|
69
|
+
step: (state, { settings, stepMs }) => {
|
|
70
|
+
state.x += (settings.ballSpeed * stepMs) / 1000;
|
|
71
|
+
},
|
|
72
|
+
observe: (state, { settings }) => ({
|
|
73
|
+
x: state.x,
|
|
74
|
+
ballSpeed: settings.ballSpeed,
|
|
75
|
+
}),
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Store actions read the same values through
|
|
80
|
+
`AirJamActionContext<PongSettings>.settings`. Host rendering calls
|
|
81
|
+
`useAirJamSettings(pongSettings)` from `@air-jam/sdk`; the hook subscribes to
|
|
82
|
+
the host runtime and returns the typed values. Controllers have no settings
|
|
83
|
+
hook. Copy any value a phone must display into replicated store state.
|
|
84
|
+
|
|
85
|
+
## Set initial values and tune a live room
|
|
86
|
+
|
|
87
|
+
`HostRuntimeOptions.settings` accepts a partial set of initial values and fills
|
|
88
|
+
the rest from defaults. `airjam.start_game_run` accepts the same `settings`
|
|
89
|
+
object when creating a new room, for browser and headless runs. Initial values
|
|
90
|
+
may include non-live settings. They are fixed for the host's lifetime.
|
|
91
|
+
|
|
92
|
+
Open a game session with host authority, then call:
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"tool": "airjam.read_game_settings",
|
|
97
|
+
"arguments": { "gameSessionId": "<session id>" }
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The result contains `values` and `revision`, initially zero. Update using that
|
|
102
|
+
revision:
|
|
103
|
+
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"tool": "airjam.update_game_settings",
|
|
107
|
+
"arguments": {
|
|
108
|
+
"gameSessionId": "<session id>",
|
|
109
|
+
"patch": { "ballSpeed": 700 },
|
|
110
|
+
"expectedRevision": 0
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
A successful update returns the complete values and the next revision. The
|
|
116
|
+
whole patch is validated before any value changes. Both tools have the same
|
|
117
|
+
host authority requirements as semantic host actions. The runtime contract is
|
|
118
|
+
`settings-read` with `{ roomId, runtimeId }`, and `settings-update` with those
|
|
119
|
+
fields plus `patch` and `expectedRevision`.
|
|
120
|
+
|
|
121
|
+
The CLI uses the same operations:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
pnpm exec airjam session settings-read <session-id>
|
|
125
|
+
pnpm exec airjam session settings-update <session-id> --patch '{"ballSpeed":700}' --expected-revision 0
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Both commands print JSON. Use `airjam run start --settings '{"ballSpeed":600}'` with the other required
|
|
129
|
+
run options to start a fresh room at a chosen speed. Attaching a run to an
|
|
130
|
+
existing room does not replace its initial settings.
|
|
131
|
+
|
|
132
|
+
## Errors and replay
|
|
133
|
+
|
|
134
|
+
`AJ_SETTING_UNKNOWN` names an undeclared key. `AJ_SETTING_INVALID` means a
|
|
135
|
+
value violates its type, range, step or choices. `AJ_SETTING_STALE` means
|
|
136
|
+
another update changed the revision; read again before applying a new patch.
|
|
137
|
+
`AJ_SETTING_NOT_LIVE` means the setting requires a new room with that initial
|
|
138
|
+
value. Rejected updates leave all values and the revision unchanged.
|
|
139
|
+
|
|
140
|
+
Input logs use `version: 3`, with resolved initial `settings` and ordered
|
|
141
|
+
`settings` events containing each accepted `patch` and `revision`.
|
|
142
|
+
They share the stream with inputs and actions. `replayAirJamInputLog` creates
|
|
143
|
+
the host with the initial values and applies each update in order before its
|
|
144
|
+
recorded step. Use the same seed and game code to reproduce the final state.
|
|
145
|
+
|
|
146
|
+
## Keeping a value
|
|
147
|
+
|
|
148
|
+
A live change lasts for the current room. To make a chosen value the default for
|
|
149
|
+
future rooms and test runs, keep it in the game's declaration:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
pnpm exec airjam game settings keep --set ballSpeed=400 --json
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Use `--dir <game>` from another directory, and repeat `--set` for several values.
|
|
156
|
+
The command requires the game's own `typescript` dependency and rewrites only
|
|
157
|
+
literal `default:` values in the selected `defineAirJamSettings({...})`, even
|
|
158
|
+
when it is imported from another game module. Imported settings must resolve to
|
|
159
|
+
one `const` directly initialized by `defineAirJamSettings`; named and default
|
|
160
|
+
exports and explicit re-export aliases are resolved to that binding. Mutable or
|
|
161
|
+
ambiguous bindings are refused. The config must export the `defineAirJamGame`
|
|
162
|
+
binding as `airjam`, so an unused game declaration is never selected. Comments
|
|
163
|
+
and formatting stay in
|
|
164
|
+
place; the declaration remains the only source of defaults. Commit the change
|
|
165
|
+
as ordinary game source. Shared or computed defaults, ambiguous declarations,
|
|
166
|
+
unknown keys and values outside their declared type, range, step or options are
|
|
167
|
+
refused before writing. The JSON result names the file and each `{ key, from,
|
|
168
|
+
to }`; equal values write nothing. Studio's Keep operation uses this same
|
|
169
|
+
transform and captures the source change in history.
|
|
@@ -61,6 +61,25 @@ The default order is:
|
|
|
61
61
|
3. keep rendering integration separate from pure game rules
|
|
62
62
|
4. use instancing when repeated objects justify it
|
|
63
63
|
|
|
64
|
+
## Loading and the Reveal
|
|
65
|
+
|
|
66
|
+
In the Arcade and the Studio, the page around a game keeps its own cover up
|
|
67
|
+
until the game's host says it is ready, so players never watch a game assemble
|
|
68
|
+
itself. The host is ready once it has mounted, its fonts have loaded and its
|
|
69
|
+
room is connected. Anything still loading after that holds the reveal with
|
|
70
|
+
`<HoldReveal />` from `@air-jam/sdk`:
|
|
71
|
+
|
|
72
|
+
1. render it in every Suspense fallback on the host, including the route-level
|
|
73
|
+
fallback around a lazy host view: `<Suspense fallback={<HoldReveal />}>`
|
|
74
|
+
2. put a Suspense boundary with that fallback around R3F content that loads
|
|
75
|
+
models or textures (`useGLTF`, `useTexture`), so the scene appears whole
|
|
76
|
+
3. render it conditionally for any other loading the host waits on:
|
|
77
|
+
`{!ready && <HoldReveal />}`
|
|
78
|
+
|
|
79
|
+
A fallback can draw its own placeholder and include `<HoldReveal />` inside it.
|
|
80
|
+
The reveal happens once; holding again later changes nothing, and outside a
|
|
81
|
+
host it does nothing.
|
|
82
|
+
|
|
64
83
|
## Air Jam Lane Rules
|
|
65
84
|
|
|
66
85
|
Keep the framework lanes separate:
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<!-- Generated from content/docs/for-agents/supported-agents/page.mdx. Do not edit directly. -->
|
|
2
|
+
<!-- Canonical public doc: https://airjam.io/docs/for-agents/supported-agents -->
|
|
3
|
+
|
|
4
|
+
# Supported Agents
|
|
5
|
+
|
|
6
|
+
Any coding agent that can run terminal commands or start a local stdio MCP
|
|
7
|
+
server can build with Air Jam. Tested means the agent made a game through Air
|
|
8
|
+
Jam's CLI and MCP, played it with two phones and released it.
|
|
9
|
+
|
|
10
|
+
| Agent | Status | Notes |
|
|
11
|
+
| ---------------------------------- | ---------------------- | --------------------------------------- |
|
|
12
|
+
| Codex CLI | Tested | |
|
|
13
|
+
| Claude Code | Tested | |
|
|
14
|
+
| T3 Code | Tested | |
|
|
15
|
+
| Codex app, over SSH | Covered by Codex CLI | Runs the same `codex` program |
|
|
16
|
+
| Claude Desktop Code tab, over SSH | Covered by Claude Code | Runs the same `claude` program |
|
|
17
|
+
| Claude Desktop chat | Not for building | Cannot edit project files |
|
|
18
|
+
| Other terminal or stdio MCP agents | Not tested | Expected to work through the CLI or MCP |
|
|
19
|
+
|
|
20
|
+
Air Jam supports its own CLI and MCP, not the agent's interface. To connect an
|
|
21
|
+
agent, see [For Agents](./for-agents.md).
|