@air-jam/cli 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 +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 +0 -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 +106 -171
- 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 +155 -0
- package/template-assets/documentation/sdk/ui-components/page.mdx +45 -4
- package/template-assets/managed/.airjam/ai-pack.json +61 -43
- 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/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 +106 -166
- package/template-assets/managed/docs/airjam/generated/settings.md +158 -0
- package/template-assets/managed/docs/airjam/generated/supported-agents.md +21 -0
- package/template-assets/managed/docs/airjam/generated/ui-components.md +45 -2
- package/template-assets/managed/docs/airjam/prefab-authoring.md +100 -0
- package/template-assets/managed/docs/airjam/preview-controllers.md +4 -1
- 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
|
|
@@ -89,21 +90,18 @@ const HostView = () => {
|
|
|
89
90
|
roomId, // "ABCD" - The room code
|
|
90
91
|
joinUrl, // Full URL for controllers to join
|
|
91
92
|
joinUrlStatus, // "loading" | "ready" | "unavailable"
|
|
92
|
-
connectionStatus, // "connected" | "connecting" | "disconnected" | "idle"
|
|
93
|
-
players, // Array of
|
|
94
|
-
|
|
93
|
+
connectionStatus, // "connected" | "connecting" | "reconnecting" | "disconnected" | "idle"
|
|
94
|
+
players, // Array of AirJamPlayer, including phones that are away
|
|
95
|
+
queuePosition, // Place in a busy hosted service's queue, or null
|
|
95
96
|
runtimeState, // "playing" | "paused"
|
|
96
97
|
lastError, // Error message if any
|
|
97
98
|
mode, // "standalone" | "platform"
|
|
98
99
|
|
|
99
100
|
// Functions
|
|
100
|
-
getInput, // (controllerId: string) => Input | undefined
|
|
101
101
|
sendSignal, // Send haptics/toasts to controllers
|
|
102
|
-
sendState, // Publish lightweight controller presentation state
|
|
103
102
|
pauseRuntime, // Set runtimeState to "paused"
|
|
104
103
|
resumeRuntime, // Set runtimeState to "playing"
|
|
105
104
|
setRuntimeState, // Explicitly set "playing" | "paused"
|
|
106
|
-
reconnect, // Force reconnection
|
|
107
105
|
} = host;
|
|
108
106
|
|
|
109
107
|
return (
|
|
@@ -122,33 +120,18 @@ const HostView = () => {
|
|
|
122
120
|
};
|
|
123
121
|
```
|
|
124
122
|
|
|
125
|
-
|
|
126
|
-
|
|
123
|
+
Each player is a seat the room assigned (`p1`, `p2`, …). A phone that drops
|
|
124
|
+
keeps its seat for two minutes and shows `connected: false` meanwhile;
|
|
125
|
+
reconnecting is automatic.
|
|
127
126
|
|
|
128
|
-
|
|
127
|
+
Players' controls reach the game only in its simulation steps, through
|
|
128
|
+
`input(playerId)`; see [Input System](./input-system.md).
|
|
129
129
|
|
|
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
|
-
```
|
|
130
|
+
Pause and orientation are the only presentation the host sends phones
|
|
131
|
+
directly. Authoritative multiplayer state lives in the networked stores; a
|
|
132
|
+
short message for the players is a toast signal or a store field.
|
|
147
133
|
|
|
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.
|
|
134
|
+
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
135
|
|
|
153
136
|
**Sending Haptic Feedback:**
|
|
154
137
|
|
|
@@ -189,34 +172,6 @@ host.sendSignal("TOAST", {
|
|
|
189
172
|
|
|
190
173
|
---
|
|
191
174
|
|
|
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
175
|
### `useSendSignal`
|
|
221
176
|
|
|
222
177
|
Lightweight hook for sending signals without triggering re-renders. Use in collision handlers.
|
|
@@ -251,81 +206,47 @@ updates.
|
|
|
251
206
|
Selectors receive state fields only; call `useAirJamController()` when a
|
|
252
207
|
component also needs controls such as `sendSystemCommand`.
|
|
253
208
|
|
|
254
|
-
|
|
255
|
-
|
|
209
|
+
A controller page keeps its seat's key for each room it joins, so a reload or a
|
|
210
|
+
dropped network returns the phone to the same seat.
|
|
256
211
|
|
|
257
212
|
```tsx
|
|
258
|
-
import {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
} from "@air-jam/sdk";
|
|
263
|
-
import { useRef } from "react";
|
|
264
|
-
import { airjam } from "../airjam.config";
|
|
213
|
+
import { useAirJamController } from "@air-jam/sdk";
|
|
214
|
+
import { ControlButton, Stick } from "@air-jam/sdk/ui";
|
|
215
|
+
import { airjam } from "../app";
|
|
216
|
+
import { shipInput } from "../game/contracts/input";
|
|
265
217
|
|
|
266
218
|
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
|
-
>
|
|
219
|
+
<airjam.Controller roomId="ABCD" nickname="Player1">
|
|
276
220
|
<ControllerView />
|
|
277
221
|
</airjam.Controller>
|
|
278
222
|
);
|
|
279
223
|
|
|
280
224
|
const ControllerView = () => {
|
|
281
225
|
const controller = useAirJamController();
|
|
282
|
-
const writeInput = useInputWriter();
|
|
283
|
-
const vectorRef = useRef({ x: 0, y: 0 });
|
|
284
|
-
const actionRef = useRef(false);
|
|
285
226
|
|
|
286
227
|
const {
|
|
287
228
|
roomId, // Room code (from URL or props)
|
|
288
|
-
controllerId, // This
|
|
229
|
+
controllerId, // This phone's seat ("p1", "p2", …)
|
|
289
230
|
connectionStatus, // Connection state
|
|
290
231
|
runtimeState, // "playing" | "paused"
|
|
291
|
-
controllerOrientation, //
|
|
292
|
-
stateMessage, // Optional message from host
|
|
232
|
+
controllerOrientation, // Declared session orientation; always landscape for joystick games
|
|
293
233
|
|
|
294
234
|
// Functions
|
|
295
|
-
sendSystemCommand, // "
|
|
235
|
+
sendSystemCommand, // "pause" | "resume"
|
|
296
236
|
setNickname, // Update nickname
|
|
297
237
|
setAvatarId, // Update avatar selection draft
|
|
298
238
|
updatePlayerProfile, // Patch live label/avatar when connected
|
|
299
239
|
selfPlayer, // This controller's player profile when known
|
|
300
|
-
|
|
240
|
+
leave, // Give up the seat
|
|
241
|
+
input, // This player's declared controls, which phone controls fill
|
|
301
242
|
} = controller;
|
|
302
243
|
|
|
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
244
|
if (connectionStatus === "connecting") {
|
|
320
245
|
return <div>Connecting to room {roomId}...</div>;
|
|
321
246
|
}
|
|
322
247
|
|
|
323
|
-
if (connectionStatus === "
|
|
324
|
-
return
|
|
325
|
-
<div>
|
|
326
|
-
Disconnected. <button onClick={reconnect}>Retry</button>
|
|
327
|
-
</div>
|
|
328
|
-
);
|
|
248
|
+
if (connectionStatus === "reconnecting") {
|
|
249
|
+
return <div>Reconnecting…</div>;
|
|
329
250
|
}
|
|
330
251
|
|
|
331
252
|
return (
|
|
@@ -334,51 +255,66 @@ const ControllerView = () => {
|
|
|
334
255
|
<div className="mb-2 text-xs uppercase">
|
|
335
256
|
Layout {controllerOrientation}
|
|
336
257
|
</div>
|
|
337
|
-
<
|
|
338
|
-
|
|
339
|
-
vectorRef.current = { x, y };
|
|
340
|
-
}}
|
|
341
|
-
/>
|
|
342
|
-
<FireButton
|
|
343
|
-
onPress={() => (actionRef.current = true)}
|
|
344
|
-
onRelease={() => (actionRef.current = false)}
|
|
345
|
-
/>
|
|
258
|
+
<Stick control={shipInput.move} className="size-48 rounded-full" />
|
|
259
|
+
<ControlButton control={shipInput.fire}>Fire</ControlButton>
|
|
346
260
|
</div>
|
|
347
261
|
);
|
|
348
262
|
};
|
|
349
263
|
```
|
|
350
264
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
Fixed-cadence helper for controller loops. Use it with `useInputWriter` instead of hand-rolled `setInterval` loops.
|
|
265
|
+
Phone controls send the declared controls themselves; a controller runs no
|
|
266
|
+
send loop.
|
|
354
267
|
|
|
355
|
-
###
|
|
268
|
+
### Game simulation
|
|
356
269
|
|
|
357
|
-
|
|
358
|
-
|
|
270
|
+
A game's authoritative state that changes every step, such as positions,
|
|
271
|
+
timers and physics, lives in a declared simulation. The SDK steps it on the
|
|
272
|
+
host at a fixed rate with seeded randomness, so the same seed and inputs replay
|
|
273
|
+
the same game, in a browser or headless and faster than real time. It only
|
|
274
|
+
steps while the room is playing: pausing freezes the game and its game time.
|
|
359
275
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
- `mode: "fixed"` for deterministic fixed-step simulation loops.
|
|
276
|
+
```ts filename="src/game/engine/simulation.ts"
|
|
277
|
+
import { defineAirJamSimulation } from "@air-jam/sdk/core";
|
|
363
278
|
|
|
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);
|
|
279
|
+
export const simulation = defineAirJamSimulation<Sim, GameInput, SimEvent>({
|
|
280
|
+
stepMs: 1000 / 60,
|
|
281
|
+
create: ({ random }) => createSim(random),
|
|
282
|
+
step: (sim, { input, players, random, emit }) => {
|
|
283
|
+
advance(sim, players, input);
|
|
378
284
|
},
|
|
285
|
+
// What agents and tests see of the game, as plain JSON.
|
|
286
|
+
observe: (sim) => ({ fighters: sim.fighters }),
|
|
379
287
|
});
|
|
380
288
|
```
|
|
381
289
|
|
|
290
|
+
Declare it with `defineAirJamGame({ simulation })`. When its code is heavy, such
|
|
291
|
+
as a physics engine, declare a loader instead,
|
|
292
|
+
`simulation: () => import("./game/engine/simulation").then((m) => m.simulation)`,
|
|
293
|
+
so only the host downloads it and controllers stay small. The host draws and
|
|
294
|
+
plays feedback from it, never advances it:
|
|
295
|
+
|
|
296
|
+
- `useSimulationFrame(({ sim, alpha }) => draw(sim, alpha))` runs after every
|
|
297
|
+
display frame; `alpha` interpolates between steps.
|
|
298
|
+
- `useSimulationEvents((event) => playSound(event))` receives what `step`
|
|
299
|
+
emitted, such as a hit.
|
|
300
|
+
- `useSimulationSelector((sim) => value, isEqual?)` reads a value for UI, such
|
|
301
|
+
as a health bar or an entity list, re-rendering only when it changes.
|
|
302
|
+
- `useSimulation()` returns the clock itself.
|
|
303
|
+
- `const captureFrame = useHostAgentCapture((target, options) => drawAgentCanvas(canvas, target, options))`
|
|
304
|
+
optionally gives agents a sharper host render surface. Supporting browsers
|
|
305
|
+
already capture the visible host stage, including HTML lobbies and nested canvases;
|
|
306
|
+
this callback takes priority when it returns true. Returning false (for example,
|
|
307
|
+
before a game canvas mounts) uses the native stage instead.
|
|
308
|
+
Call `captureFrame()` immediately after
|
|
309
|
+
drawing the game and its HUD. The SDK owns the persistent capture canvas and
|
|
310
|
+
records native video at 30 fps; still observations use the same drawing callback.
|
|
311
|
+
Still observations and frame-based test clips encode JPEGs asynchronously. The
|
|
312
|
+
clip sampler skips ticks while encoding is pending rather than queueing frames.
|
|
313
|
+
If you call `captureAgentCanvas()` directly, await its image result.
|
|
314
|
+
|
|
315
|
+
Step code reads stores with `gameStore.getState()` and dispatches with
|
|
316
|
+
`gameStore.actions`; it never reads `Date.now()` or `Math.random()`.
|
|
317
|
+
|
|
382
318
|
**Auto Room Join from URL:**
|
|
383
319
|
|
|
384
320
|
Controllers automatically join rooms from URL query parameters:
|
|
@@ -395,16 +331,15 @@ This is how QR code scanning works—the host generates a URL with the room code
|
|
|
395
331
|
|
|
396
332
|
Use these only when integrating platform-specific runtime behavior.
|
|
397
333
|
|
|
398
|
-
###
|
|
334
|
+
### Room session access (escape hatch)
|
|
399
335
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
```
|
|
336
|
+
`host.room` and `controller.session` are the page's sessions in the room
|
|
337
|
+
(`@air-jam/sdk/room-session`). Networked stores and signals cover what games
|
|
338
|
+
need; reach for the session only for a channel of your own.
|
|
404
339
|
|
|
405
340
|
### Internal context hooks
|
|
406
341
|
|
|
407
|
-
`useAirJamContext`, `useAirJamConfig
|
|
342
|
+
`useAirJamContext`, `useAirJamConfig` and `useAirJamState` are intentionally internal and are not part of the root public SDK surface.
|
|
408
343
|
|
|
409
344
|
---
|
|
410
345
|
|
|
@@ -431,25 +366,23 @@ const unsubscribe = onAirJamDiagnostic((diagnostic) => {
|
|
|
431
366
|
| `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
367
|
| `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
368
|
| `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
369
|
| `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
370
|
| `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. |
|
|
371
|
+
| `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. |
|
|
372
|
+
| `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
373
|
|
|
443
374
|
---
|
|
444
375
|
|
|
445
|
-
### `
|
|
376
|
+
### `AirJamPlayer`
|
|
446
377
|
|
|
447
378
|
```typescript
|
|
448
|
-
interface
|
|
449
|
-
id: string; //
|
|
379
|
+
interface AirJamPlayer {
|
|
380
|
+
id: string; // The seat the room assigned ("p1", "p2", …)
|
|
450
381
|
label: string; // Display name (e.g., "Player 1")
|
|
451
|
-
color
|
|
382
|
+
color: string; // Assigned color (e.g., "#FF5733")
|
|
452
383
|
avatarId?: string; // Preset avatar id chosen by the player
|
|
384
|
+
kind: "phone" | "preview" | "agent";
|
|
385
|
+
connected: boolean; // false while the phone is away
|
|
453
386
|
}
|
|
454
387
|
```
|
|
455
388
|
|
|
@@ -488,3 +421,10 @@ interface ToastSignalPayload {
|
|
|
488
421
|
duration?: number; // Optional duration in ms
|
|
489
422
|
}
|
|
490
423
|
```
|
|
424
|
+
|
|
425
|
+
## useAirJamSettings
|
|
426
|
+
|
|
427
|
+
Host rendering reads declared settings with `useAirJamSettings(gameSettings)`.
|
|
428
|
+
The hook returns typed current values and subscribes to accepted host updates.
|
|
429
|
+
Controllers read display values copied to replicated store state. See
|
|
430
|
+
[Game Settings](./settings.md) for the full contract.
|
|
@@ -0,0 +1,158 @@
|
|
|
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
|
+
description: "Ball speed in pixels per second.",
|
|
32
|
+
}),
|
|
33
|
+
});
|
|
34
|
+
export type PongSettings = AirJamSettingsValues<typeof pongSettings>;
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Pass it as `defineAirJamGame({ settings: pongSettings, ... })`. Remove the
|
|
38
|
+
module constants it replaces. A lobby choice players make, such as
|
|
39
|
+
`pointsToWin`, remains replicated store state.
|
|
40
|
+
|
|
41
|
+
Keys are lower camel case. `setting.number` requires `default`, `min` and
|
|
42
|
+
`max`, with an optional positive `step`; use `step: 1` for whole numbers.
|
|
43
|
+
Steps are multiples of zero. `setting.boolean` requires a boolean `default`.
|
|
44
|
+
`setting.choice` takes a nonempty string tuple in `options` and a `default`
|
|
45
|
+
from that tuple; its value type is the union of those strings.
|
|
46
|
+
Every kind accepts `description` and `live`, which defaults to false.
|
|
47
|
+
`defineAirJamSettings` validates defaults immediately. The description returned
|
|
48
|
+
by `airjam.inspect_game` includes these descriptors in `declaration.settings`.
|
|
49
|
+
|
|
50
|
+
## Read the current values
|
|
51
|
+
|
|
52
|
+
Use the settings type as the fourth simulation type parameter:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
defineAirJamSimulation<State, Input, Event, PongSettings>({
|
|
56
|
+
stepMs: 1000 / 60,
|
|
57
|
+
create: ({ settings }) => createState(settings.ballSpeed),
|
|
58
|
+
step: (state, { settings, stepMs }) => {
|
|
59
|
+
state.x += (settings.ballSpeed * stepMs) / 1000;
|
|
60
|
+
},
|
|
61
|
+
observe: (state, { settings }) => ({
|
|
62
|
+
x: state.x,
|
|
63
|
+
ballSpeed: settings.ballSpeed,
|
|
64
|
+
}),
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Store actions read the same values through
|
|
69
|
+
`AirJamActionContext<PongSettings>.settings`. Host rendering calls
|
|
70
|
+
`useAirJamSettings(pongSettings)` from `@air-jam/sdk`; the hook subscribes to
|
|
71
|
+
the host runtime and returns the typed values. Controllers have no settings
|
|
72
|
+
hook. Copy any value a phone must display into replicated store state.
|
|
73
|
+
|
|
74
|
+
## Set initial values and tune a live room
|
|
75
|
+
|
|
76
|
+
`HostRuntimeOptions.settings` accepts a partial set of initial values and fills
|
|
77
|
+
the rest from defaults. `airjam.start_game_run` accepts the same `settings`
|
|
78
|
+
object when creating a new room, for browser and headless runs. Initial values
|
|
79
|
+
may include non-live settings. They are fixed for the host's lifetime.
|
|
80
|
+
|
|
81
|
+
Open a game session with host authority, then call:
|
|
82
|
+
|
|
83
|
+
```json
|
|
84
|
+
{
|
|
85
|
+
"tool": "airjam.read_game_settings",
|
|
86
|
+
"arguments": { "gameSessionId": "<session id>" }
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
The result contains `values` and `revision`, initially zero. Update using that
|
|
91
|
+
revision:
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"tool": "airjam.update_game_settings",
|
|
96
|
+
"arguments": {
|
|
97
|
+
"gameSessionId": "<session id>",
|
|
98
|
+
"patch": { "ballSpeed": 700 },
|
|
99
|
+
"expectedRevision": 0
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
A successful update returns the complete values and the next revision. The
|
|
105
|
+
whole patch is validated before any value changes. Both tools have the same
|
|
106
|
+
host authority requirements as semantic host actions. The runtime contract is
|
|
107
|
+
`settings-read` with `{ roomId, runtimeId }`, and `settings-update` with those
|
|
108
|
+
fields plus `patch` and `expectedRevision`.
|
|
109
|
+
|
|
110
|
+
The CLI uses the same operations:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
pnpm exec airjam session settings-read <session-id>
|
|
114
|
+
pnpm exec airjam session settings-update <session-id> --patch '{"ballSpeed":700}' --expected-revision 0
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Both commands print JSON. Use `airjam run start --settings '{"ballSpeed":600}'` with the other required
|
|
118
|
+
run options to start a fresh room at a chosen speed. Attaching a run to an
|
|
119
|
+
existing room does not replace its initial settings.
|
|
120
|
+
|
|
121
|
+
## Errors and replay
|
|
122
|
+
|
|
123
|
+
`AJ_SETTING_UNKNOWN` names an undeclared key. `AJ_SETTING_INVALID` means a
|
|
124
|
+
value violates its type, range, step or choices. `AJ_SETTING_STALE` means
|
|
125
|
+
another update changed the revision; read again before applying a new patch.
|
|
126
|
+
`AJ_SETTING_NOT_LIVE` means the setting requires a new room with that initial
|
|
127
|
+
value. Rejected updates leave all values and the revision unchanged.
|
|
128
|
+
|
|
129
|
+
Input logs use `version: 3`, with resolved initial `settings` and ordered
|
|
130
|
+
`settings` events containing each accepted `patch` and `revision`.
|
|
131
|
+
They share the stream with inputs and actions. `replayAirJamInputLog` creates
|
|
132
|
+
the host with the initial values and applies each update in order before its
|
|
133
|
+
recorded step. Use the same seed and game code to reproduce the final state.
|
|
134
|
+
|
|
135
|
+
## Keeping a value
|
|
136
|
+
|
|
137
|
+
A live change lasts for the current room. To make a chosen value the default for
|
|
138
|
+
future rooms and test runs, keep it in the game's declaration:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
pnpm exec airjam game settings keep --set ballSpeed=400 --json
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Use `--dir <game>` from another directory, and repeat `--set` for several values.
|
|
145
|
+
The command requires the game's own `typescript` dependency and rewrites only
|
|
146
|
+
literal `default:` values in the selected `defineAirJamSettings({...})`, even
|
|
147
|
+
when it is imported from another game module. Imported settings must resolve to
|
|
148
|
+
one `const` directly initialized by `defineAirJamSettings`; named and default
|
|
149
|
+
exports and explicit re-export aliases are resolved to that binding. Mutable or
|
|
150
|
+
ambiguous bindings are refused. The config must export the `defineAirJamGame`
|
|
151
|
+
binding as `airjam`, so an unused game declaration is never selected. Comments
|
|
152
|
+
and formatting stay in
|
|
153
|
+
place; the declaration remains the only source of defaults. Commit the change
|
|
154
|
+
as ordinary game source. Shared or computed defaults, ambiguous declarations,
|
|
155
|
+
unknown keys and values outside their declared type, range, step or options are
|
|
156
|
+
refused before writing. The JSON result names the file and each `{ key, from,
|
|
157
|
+
to }`; equal values write nothing. Studio's Keep operation uses this same
|
|
158
|
+
transform and captures the source change in history.
|
|
@@ -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).
|
|
@@ -96,6 +96,8 @@ Use it for:
|
|
|
96
96
|
|
|
97
97
|
### `SurfaceViewport`
|
|
98
98
|
|
|
99
|
+
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.
|
|
100
|
+
|
|
99
101
|
Own safe-area, orientation, and page-level UI scaling for a game surface.
|
|
100
102
|
It should fill the available screen while scaling the UI system proportionally, rather than letterboxing a fixed contained stage.
|
|
101
103
|
Internally it publishes a local `--airjam-ui-scale` into Tailwind's own spacing, text, radius, and container variables so normal Tailwind utilities keep working.
|
|
@@ -103,7 +105,7 @@ Internally it publishes a local `--airjam-ui-scale` into Tailwind's own spacing,
|
|
|
103
105
|
```tsx
|
|
104
106
|
import { SurfaceViewport } from "@air-jam/sdk/ui";
|
|
105
107
|
|
|
106
|
-
<SurfaceViewport
|
|
108
|
+
<SurfaceViewport className="bg-zinc-950">
|
|
107
109
|
<ControllerView />
|
|
108
110
|
</SurfaceViewport>;
|
|
109
111
|
```
|
|
@@ -161,6 +163,47 @@ Use it for:
|
|
|
161
163
|
|
|
162
164
|
---
|
|
163
165
|
|
|
166
|
+
## Phone Controls
|
|
167
|
+
|
|
168
|
+
`ControlButton`, `AxisButton` and `Stick` bind phone UI to the game's declared
|
|
169
|
+
controls and send them; see [Input System](./input-system.md).
|
|
170
|
+
|
|
171
|
+
```tsx
|
|
172
|
+
import { AxisButton, ControlButton, Stick } from "@air-jam/sdk/ui";
|
|
173
|
+
|
|
174
|
+
<Stick control={shipInput.move} knobClassName="bg-white/30" />
|
|
175
|
+
<AxisButton control={pongInput.direction} value={-1}>Up</AxisButton>
|
|
176
|
+
<ControlButton control={shipInput.fire} className="data-[active=true]:ring-2">
|
|
177
|
+
Fire
|
|
178
|
+
</ControlButton>
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Each sets `data-active` while held. `Stick` takes `directions="4-way"`,
|
|
182
|
+
`deadzone`, `knob`, `knobClassName`, and a function child that draws the whole
|
|
183
|
+
stick from `{ value, active }`.
|
|
184
|
+
|
|
185
|
+
### `GamepadLayout`
|
|
186
|
+
|
|
187
|
+
Lays out a sideways controller like a gamepad: `left` and `right` thumb
|
|
188
|
+
squares of the same size, sized from the phone's short side and mirrored about
|
|
189
|
+
the centre, with a compact `center` column between them. `right` holds one
|
|
190
|
+
action, or several as a cluster around the main one. It fills its parent, so
|
|
191
|
+
put a header above it. See [Controller UI](https://airjam.io/docs/for-agents/controller-ui#sideways-controllers).
|
|
192
|
+
|
|
193
|
+
```tsx
|
|
194
|
+
import { ControlButton, GamepadLayout, Stick } from "@air-jam/sdk/ui";
|
|
195
|
+
|
|
196
|
+
<GamepadLayout
|
|
197
|
+
left={<Stick control={gameInput.move} className="rounded-full bg-white/10" />}
|
|
198
|
+
center={<span className="text-xs uppercase">Round 1</span>}
|
|
199
|
+
right={
|
|
200
|
+
<ControlButton control={gameInput.action} className="rounded-full">
|
|
201
|
+
Go
|
|
202
|
+
</ControlButton>
|
|
203
|
+
}
|
|
204
|
+
/>;
|
|
205
|
+
```
|
|
206
|
+
|
|
164
207
|
### `Button`
|
|
165
208
|
|
|
166
209
|
Styling primitive for consistent buttons.
|
|
@@ -217,6 +260,6 @@ Combine:
|
|
|
217
260
|
|
|
218
261
|
## Anti-Patterns
|
|
219
262
|
|
|
220
|
-
- Do not build gameplay input on
|
|
263
|
+
- Do not build gameplay input on `Button`; bind controls with `ControlButton`, `AxisButton` and `Stick`.
|
|
221
264
|
- Do not rely on UI primitives for room/session lifecycle; lifecycle stays in headless SDK hooks.
|
|
222
265
|
- Do not fork component behavior in each game if composition solves it; prefer small wrappers around canonical primitives.
|