@air-jam/sdk 0.9.2 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/README.md +25 -45
  2. package/dist/{agent-tooling-BSMGBix9.d.cts → agent-contract-CD2QnbBJ.d.cts} +1 -1
  3. package/dist/{agent-tooling-BSMGBix9.d.ts → agent-contract-CD2QnbBJ.d.ts} +1 -1
  4. package/dist/agent-tooling.cjs +139 -0
  5. package/dist/agent-tooling.cjs.map +1 -1
  6. package/dist/agent-tooling.d.cts +25 -1
  7. package/dist/agent-tooling.d.ts +25 -1
  8. package/dist/agent-tooling.js +138 -0
  9. package/dist/agent-tooling.js.map +1 -1
  10. package/dist/air-jam-context-BlLPvCup.d.cts +175 -0
  11. package/dist/air-jam-context-DTsxF-tP.d.ts +175 -0
  12. package/dist/arcade/bridge/controller.cjs +214 -194
  13. package/dist/arcade/bridge/controller.cjs.map +1 -1
  14. package/dist/arcade/bridge/controller.d.cts +2 -2
  15. package/dist/arcade/bridge/controller.d.ts +2 -2
  16. package/dist/arcade/bridge/controller.js +6 -4
  17. package/dist/arcade/bridge/host.cjs +1 -1
  18. package/dist/arcade/bridge/host.cjs.map +1 -1
  19. package/dist/arcade/bridge/host.d.cts +3 -3
  20. package/dist/arcade/bridge/host.d.ts +3 -3
  21. package/dist/arcade/bridge/host.js +4 -3
  22. package/dist/arcade/bridge/iframe.cjs +1 -1
  23. package/dist/arcade/bridge/iframe.cjs.map +1 -1
  24. package/dist/arcade/bridge/iframe.d.cts +2 -2
  25. package/dist/arcade/bridge/iframe.d.ts +2 -2
  26. package/dist/arcade/bridge/iframe.js +4 -4
  27. package/dist/arcade/bridge.cjs +251 -231
  28. package/dist/arcade/bridge.cjs.map +1 -1
  29. package/dist/arcade/bridge.d.cts +4 -4
  30. package/dist/arcade/bridge.d.ts +4 -4
  31. package/dist/arcade/bridge.js +9 -7
  32. package/dist/arcade/host.cjs +145 -122
  33. package/dist/arcade/host.cjs.map +1 -1
  34. package/dist/arcade/host.d.cts +5 -4
  35. package/dist/arcade/host.d.ts +5 -4
  36. package/dist/arcade/host.js +6 -5
  37. package/dist/arcade/runtime.cjs +6499 -0
  38. package/dist/arcade/runtime.cjs.map +1 -0
  39. package/dist/arcade/runtime.d.cts +22 -0
  40. package/dist/arcade/runtime.d.ts +22 -0
  41. package/dist/arcade/runtime.js +32 -0
  42. package/dist/arcade/runtime.js.map +1 -0
  43. package/dist/arcade/surface.cjs +9 -0
  44. package/dist/arcade/surface.cjs.map +1 -1
  45. package/dist/arcade/surface.d.cts +6 -1
  46. package/dist/arcade/surface.d.ts +6 -1
  47. package/dist/arcade/surface.js +6 -2
  48. package/dist/arcade/url.d.cts +4 -4
  49. package/dist/arcade/url.d.ts +4 -4
  50. package/dist/arcade/url.js +5 -5
  51. package/dist/arcade.cjs +322 -292
  52. package/dist/arcade.cjs.map +1 -1
  53. package/dist/arcade.d.cts +6 -6
  54. package/dist/arcade.d.ts +6 -6
  55. package/dist/arcade.js +35 -29
  56. package/dist/{chunk-Q4UALQO4.js → chunk-2SZ2YYGJ.js} +8 -16
  57. package/dist/chunk-2SZ2YYGJ.js.map +1 -0
  58. package/dist/{chunk-KOB73SPD.js → chunk-32RSSFSF.js} +10 -12
  59. package/dist/chunk-32RSSFSF.js.map +1 -0
  60. package/dist/chunk-3YMUAKPU.js +10 -0
  61. package/dist/chunk-3YMUAKPU.js.map +1 -0
  62. package/dist/chunk-56DM2KEW.js +14 -0
  63. package/dist/chunk-56DM2KEW.js.map +1 -0
  64. package/dist/chunk-CM53YLT5.js +59 -0
  65. package/dist/chunk-CM53YLT5.js.map +1 -0
  66. package/dist/{chunk-DY67S3LR.js → chunk-CV3PBXPT.js} +3 -3
  67. package/dist/chunk-D4VDEVTZ.js +80 -0
  68. package/dist/chunk-D4VDEVTZ.js.map +1 -0
  69. package/dist/{chunk-E5PVHEAX.js → chunk-FUA6EMSJ.js} +24 -60
  70. package/dist/chunk-FUA6EMSJ.js.map +1 -0
  71. package/dist/chunk-GMLU7RI5.js +70 -0
  72. package/dist/chunk-GMLU7RI5.js.map +1 -0
  73. package/dist/{chunk-NCL6WJCL.js → chunk-IG6GZZSS.js} +32 -1
  74. package/dist/chunk-IG6GZZSS.js.map +1 -0
  75. package/dist/{chunk-EDRQIOCV.js → chunk-ITMQSBTH.js} +3 -2
  76. package/dist/chunk-ITMQSBTH.js.map +1 -0
  77. package/dist/{chunk-32NYL7XI.js → chunk-J5MCII33.js} +189 -108
  78. package/dist/chunk-J5MCII33.js.map +1 -0
  79. package/dist/{chunk-ZLPL2R3R.js → chunk-K4OZ54UD.js} +7 -34
  80. package/dist/chunk-K4OZ54UD.js.map +1 -0
  81. package/dist/{chunk-6CMB356F.js → chunk-LIHEEAVE.js} +9 -11
  82. package/dist/chunk-LIHEEAVE.js.map +1 -0
  83. package/dist/{chunk-7OTQTT6H.js → chunk-MIMPMB7O.js} +2 -2
  84. package/dist/{chunk-NUJBMV3O.js → chunk-O6X7FJ6N.js} +29 -32
  85. package/dist/chunk-O6X7FJ6N.js.map +1 -0
  86. package/dist/chunk-PSUYTD2L.js +16 -0
  87. package/dist/chunk-PSUYTD2L.js.map +1 -0
  88. package/dist/{chunk-M4DKOI42.js → chunk-QO4KFUEI.js} +2 -2
  89. package/dist/chunk-QTLYZADF.js +125 -0
  90. package/dist/chunk-QTLYZADF.js.map +1 -0
  91. package/dist/chunk-TTQDHKXL.js +3017 -0
  92. package/dist/chunk-TTQDHKXL.js.map +1 -0
  93. package/dist/chunk-UCPY7UJC.js +8 -0
  94. package/dist/chunk-UCPY7UJC.js.map +1 -0
  95. package/dist/{chunk-JO2HR5PV.js → chunk-UPV6YWT5.js} +4 -4
  96. package/dist/chunk-X35LLCWV.js +65 -0
  97. package/dist/chunk-X35LLCWV.js.map +1 -0
  98. package/dist/{controller-DxVchfiA.d.ts → controller-PZEM_1cH.d.ts} +6 -2
  99. package/dist/{controller-Bod8YYr1.d.cts → controller-vj82tKm4.d.cts} +6 -2
  100. package/dist/{dev-log-events-CVAM29hx.d.cts → dev-log-events-BCJKmygo.d.cts} +0 -3
  101. package/dist/{dev-log-events-CVAM29hx.d.ts → dev-log-events-BCJKmygo.d.ts} +0 -3
  102. package/dist/{host-8hmq_Sgc.d.cts → host-B9pRy0Aa.d.cts} +20 -7
  103. package/dist/{host-Cw-N6e-5.d.ts → host-DylGsX7p.d.ts} +20 -7
  104. package/dist/index.cjs +4260 -3870
  105. package/dist/index.cjs.map +1 -1
  106. package/dist/index.d.cts +40 -649
  107. package/dist/index.d.ts +40 -649
  108. package/dist/index.js +1030 -3727
  109. package/dist/index.js.map +1 -1
  110. package/dist/metadata.cjs.map +1 -1
  111. package/dist/metadata.d.cts +2 -3
  112. package/dist/metadata.d.ts +2 -3
  113. package/dist/metadata.js.map +1 -1
  114. package/dist/{notices-CnGaaS8B.d.ts → notices-C4bao3oi.d.ts} +1 -1
  115. package/dist/{notices-NyDM5Mtz.d.cts → notices-DNdOjwtj.d.cts} +1 -1
  116. package/dist/platform-machine.cjs +115 -15
  117. package/dist/platform-machine.cjs.map +1 -1
  118. package/dist/platform-machine.d.cts +1338 -65
  119. package/dist/platform-machine.d.ts +1338 -65
  120. package/dist/platform-machine.js +88 -15
  121. package/dist/platform-machine.js.map +1 -1
  122. package/dist/{platform-settings-cuor3i11.d.cts → platform-settings-DUWs4JTy.d.cts} +1 -1
  123. package/dist/{platform-settings-cuor3i11.d.ts → platform-settings-DUWs4JTy.d.ts} +1 -1
  124. package/dist/preview.cjs +301 -253
  125. package/dist/preview.cjs.map +1 -1
  126. package/dist/preview.d.cts +6 -4
  127. package/dist/preview.d.ts +6 -4
  128. package/dist/preview.js +31 -21
  129. package/dist/preview.js.map +1 -1
  130. package/dist/protocol.cjs +282 -167
  131. package/dist/protocol.cjs.map +1 -1
  132. package/dist/protocol.d.cts +74 -21
  133. package/dist/protocol.d.ts +74 -21
  134. package/dist/protocol.js +28 -10
  135. package/dist/release.cjs +37 -0
  136. package/dist/release.cjs.map +1 -1
  137. package/dist/release.d.cts +27 -1
  138. package/dist/release.d.ts +27 -1
  139. package/dist/release.js +13 -1
  140. package/dist/runtime-control.cjs +46 -0
  141. package/dist/runtime-control.cjs.map +1 -0
  142. package/dist/runtime-control.d.cts +17 -0
  143. package/dist/runtime-control.d.ts +17 -0
  144. package/dist/runtime-control.js +8 -0
  145. package/dist/runtime-control.js.map +1 -0
  146. package/dist/runtime-inspection.cjs +655 -0
  147. package/dist/runtime-inspection.cjs.map +1 -0
  148. package/dist/runtime-inspection.d.cts +47 -0
  149. package/dist/runtime-inspection.d.ts +47 -0
  150. package/dist/runtime-inspection.js +30 -0
  151. package/dist/runtime-inspection.js.map +1 -0
  152. package/dist/runtime-reporting-pe-eryVz.d.cts +27 -0
  153. package/dist/runtime-reporting-pe-eryVz.d.ts +27 -0
  154. package/dist/signals-ZHftIKuc.d.cts +33 -0
  155. package/dist/signals-ZHftIKuc.d.ts +33 -0
  156. package/dist/{standard-match-phase-BucA5dYo.d.ts → standard-match-phase-BzSgBYFg.d.ts} +2 -2
  157. package/dist/{standard-match-phase-U2ra8J-0.d.cts → standard-match-phase-CvJUW8Oe.d.cts} +2 -2
  158. package/dist/{sync-B6QsNrXz.d.cts → sync-xtPfWhif.d.cts} +1 -45
  159. package/dist/{sync-B6QsNrXz.d.ts → sync-xtPfWhif.d.ts} +1 -45
  160. package/dist/ui.cjs +593 -610
  161. package/dist/ui.cjs.map +1 -1
  162. package/dist/ui.d.cts +3 -3
  163. package/dist/ui.d.ts +3 -3
  164. package/dist/ui.js +16 -11
  165. package/dist/ui.js.map +1 -1
  166. package/dist/use-air-jam-host-COLy8t4s.d.ts +403 -0
  167. package/dist/use-air-jam-host-DM-ybB3C.d.cts +403 -0
  168. package/package.json +55 -21
  169. package/src/agent/agent-contract-conformance.ts +201 -0
  170. package/src/agent-tooling.ts +5 -0
  171. package/src/arcade/runtime.ts +6 -0
  172. package/src/arcade/surface.ts +1 -0
  173. package/src/context/air-jam-context.tsx +8 -8
  174. package/src/context/socket-manager.ts +0 -7
  175. package/src/dev/browser-log-sink.ts +12 -15
  176. package/src/events.ts +0 -5
  177. package/src/hooks/internal/use-controller-runtime-api.ts +110 -21
  178. package/src/hooks/internal/use-host-runtime-api.ts +306 -49
  179. package/src/hooks/use-air-jam-controller.ts +9 -9
  180. package/src/hooks/use-air-jam-host.ts +7 -7
  181. package/src/hooks/use-get-input.ts +1 -1
  182. package/src/hooks/use-host-arcade-restore.ts +6 -1
  183. package/src/index.ts +6 -25
  184. package/src/metadata/manifest.ts +2 -3
  185. package/src/platform-machine.ts +109 -12
  186. package/src/preview/workspace.tsx +48 -29
  187. package/src/protocol/arcade-platform-actions.ts +19 -1
  188. package/src/protocol/controller.ts +8 -2
  189. package/src/protocol/dev-log-events.ts +0 -3
  190. package/src/protocol/host-grant.ts +58 -140
  191. package/src/protocol/host.ts +21 -9
  192. package/src/protocol/runtime-reporting.ts +32 -0
  193. package/src/protocol/signed-envelope.ts +176 -0
  194. package/src/protocol/socket-events.ts +8 -10
  195. package/src/protocol/sync.ts +0 -16
  196. package/src/protocol.ts +2 -0
  197. package/src/release.ts +32 -0
  198. package/src/runtime/admission-retry.ts +62 -0
  199. package/src/runtime/air-jam-config.ts +6 -16
  200. package/src/runtime/air-jam-error-boundary.tsx +46 -2
  201. package/src/runtime/bridge-envelope-args.ts +21 -0
  202. package/src/runtime/connected-runtime-error-boundary.tsx +31 -0
  203. package/src/runtime/contracts/control.ts +107 -59
  204. package/src/runtime/controller-bridge.ts +12 -24
  205. package/src/runtime/controller-identity.ts +55 -27
  206. package/src/runtime/controller-realtime-client.ts +8 -47
  207. package/src/runtime/create-air-jam-app.tsx +21 -13
  208. package/src/runtime/host-bridge.ts +16 -24
  209. package/src/runtime/local-reference-game-identity.ts +13 -0
  210. package/src/runtime/runtime-session-params.ts +4 -64
  211. package/src/runtime-control.ts +3 -8
  212. package/src/settings/platform-settings-runtime.tsx +1 -6
  213. package/src/settings/platform-settings.ts +7 -38
  214. package/src/state/connection-store.ts +13 -6
  215. package/src/store/create-air-jam-store.ts +59 -7
  216. package/src/utils/ids.ts +32 -5
  217. package/dist/capabilities.cjs +0 -39
  218. package/dist/capabilities.cjs.map +0 -1
  219. package/dist/capabilities.d.cts +0 -31
  220. package/dist/capabilities.d.ts +0 -31
  221. package/dist/capabilities.js +0 -12
  222. package/dist/capabilities.js.map +0 -1
  223. package/dist/chunk-32NYL7XI.js.map +0 -1
  224. package/dist/chunk-6CMB356F.js.map +0 -1
  225. package/dist/chunk-CVYR5RJT.js +0 -184
  226. package/dist/chunk-CVYR5RJT.js.map +0 -1
  227. package/dist/chunk-E5PVHEAX.js.map +0 -1
  228. package/dist/chunk-EDRQIOCV.js.map +0 -1
  229. package/dist/chunk-KOB73SPD.js.map +0 -1
  230. package/dist/chunk-NCL6WJCL.js.map +0 -1
  231. package/dist/chunk-NUJBMV3O.js.map +0 -1
  232. package/dist/chunk-Q4UALQO4.js.map +0 -1
  233. package/dist/chunk-ZLPL2R3R.js.map +0 -1
  234. package/dist/chunk-ZTQ5SP4H.js +0 -9
  235. package/dist/chunk-ZTQ5SP4H.js.map +0 -1
  236. package/src/capabilities/manifest.ts +0 -71
  237. package/src/capabilities.ts +0 -12
  238. package/src/hooks/internal/use-runtime-control-contract.ts +0 -15
  239. package/src/hooks/internal/use-runtime-observability-contract.ts +0 -24
  240. package/src/runtime/contracts/observability.ts +0 -94
  241. package/src/runtime-observability.ts +0 -9
  242. /package/dist/{chunk-DY67S3LR.js.map → chunk-CV3PBXPT.js.map} +0 -0
  243. /package/dist/{chunk-7OTQTT6H.js.map → chunk-MIMPMB7O.js.map} +0 -0
  244. /package/dist/{chunk-M4DKOI42.js.map → chunk-QO4KFUEI.js.map} +0 -0
  245. /package/dist/{chunk-JO2HR5PV.js.map → chunk-UPV6YWT5.js.map} +0 -0
@@ -0,0 +1,201 @@
1
+ import {
2
+ describeAirJamAgentAction,
3
+ resolveAirJamAgentActionPayload,
4
+ type AnyAirJamAgentContract,
5
+ } from "./agent-contract.js";
6
+
7
+ export type AirJamAgentContractConformanceIssue = {
8
+ code:
9
+ | "store-domain-mismatch"
10
+ | "missing-store-actions"
11
+ | "missing-target-action"
12
+ | "invalid-action-metadata"
13
+ | "payload-parse-failed"
14
+ | "snapshot-failed"
15
+ | "snapshot-not-json";
16
+ path: string;
17
+ message: string;
18
+ };
19
+
20
+ export type AirJamAgentContractConformanceReport = {
21
+ schemaVersion: 1;
22
+ gameId: string;
23
+ ok: boolean;
24
+ storeDomains: string[];
25
+ actionNames: string[];
26
+ issues: AirJamAgentContractConformanceIssue[];
27
+ };
28
+
29
+ type InspectAirJamAgentContractConformanceOptions = {
30
+ gameId: string;
31
+ contract: AnyAirJamAgentContract;
32
+ stores: Record<string, object>;
33
+ controllerId?: string | null;
34
+ };
35
+
36
+ const representativePayload = (
37
+ kind: ReturnType<typeof describeAirJamAgentAction>["payload"]["kind"],
38
+ allowedValues?: string[],
39
+ ): unknown => {
40
+ switch (kind) {
41
+ case "none":
42
+ return undefined;
43
+ case "boolean":
44
+ return true;
45
+ case "number":
46
+ return 1;
47
+ case "string":
48
+ return "conformance";
49
+ case "enum":
50
+ return allowedValues?.[0];
51
+ case "json":
52
+ return {};
53
+ }
54
+ };
55
+
56
+ const inspectJsonValue = (
57
+ value: unknown,
58
+ path: string,
59
+ seen: Set<object>,
60
+ issues: AirJamAgentContractConformanceIssue[],
61
+ ): void => {
62
+ if (
63
+ value === null ||
64
+ typeof value === "string" ||
65
+ typeof value === "boolean"
66
+ ) {
67
+ return;
68
+ }
69
+ if (typeof value === "number") {
70
+ if (!Number.isFinite(value)) {
71
+ issues.push({
72
+ code: "snapshot-not-json",
73
+ path,
74
+ message: "Snapshot numbers must be finite.",
75
+ });
76
+ }
77
+ return;
78
+ }
79
+ if (typeof value !== "object") {
80
+ issues.push({
81
+ code: "snapshot-not-json",
82
+ path,
83
+ message: `Snapshot value has unsupported type ${typeof value}.`,
84
+ });
85
+ return;
86
+ }
87
+ if (seen.has(value)) {
88
+ issues.push({
89
+ code: "snapshot-not-json",
90
+ path,
91
+ message: "Snapshot contains a circular reference.",
92
+ });
93
+ return;
94
+ }
95
+
96
+ seen.add(value);
97
+ if (Array.isArray(value)) {
98
+ value.forEach((entry, index) =>
99
+ inspectJsonValue(entry, `${path}[${index}]`, seen, issues),
100
+ );
101
+ } else {
102
+ for (const [key, entry] of Object.entries(value)) {
103
+ inspectJsonValue(entry, `${path}.${key}`, seen, issues);
104
+ }
105
+ }
106
+ seen.delete(value);
107
+ };
108
+
109
+ export const inspectAirJamAgentContractConformance = async ({
110
+ gameId,
111
+ contract,
112
+ stores,
113
+ controllerId = "conformance-controller",
114
+ }: InspectAirJamAgentContractConformanceOptions): Promise<AirJamAgentContractConformanceReport> => {
115
+ const issues: AirJamAgentContractConformanceIssue[] = [];
116
+ const storeDomains = Object.keys(contract.stores).sort();
117
+ const runtimeStoreDomains = Object.keys(stores).sort();
118
+ const actionNames = Object.keys(contract.actions).sort();
119
+
120
+ if (JSON.stringify(storeDomains) !== JSON.stringify(runtimeStoreDomains)) {
121
+ issues.push({
122
+ code: "store-domain-mismatch",
123
+ path: "stores",
124
+ message: `Declared domains [${storeDomains.join(", ")}] do not match runtime domains [${runtimeStoreDomains.join(", ")}].`,
125
+ });
126
+ }
127
+
128
+ for (const [actionName, action] of Object.entries(contract.actions)) {
129
+ const targetDomain = action.target.storeDomain ?? "default";
130
+ const runtimeStore = stores[targetDomain] as
131
+ | { actions?: Record<string, unknown> }
132
+ | undefined;
133
+ if (!runtimeStore?.actions || typeof runtimeStore.actions !== "object") {
134
+ issues.push({
135
+ code: "missing-store-actions",
136
+ path: `actions.${actionName}.target`,
137
+ message: `Runtime store "${targetDomain}" does not expose an actions object.`,
138
+ });
139
+ } else if (
140
+ typeof runtimeStore.actions[action.target.actionName] !== "function"
141
+ ) {
142
+ issues.push({
143
+ code: "missing-target-action",
144
+ path: `actions.${actionName}.target`,
145
+ message: `Runtime store "${targetDomain}" does not expose action "${action.target.actionName}".`,
146
+ });
147
+ }
148
+
149
+ const metadata = describeAirJamAgentAction(action);
150
+ if (
151
+ !metadata.description?.trim() ||
152
+ !metadata.resultDescription?.trim() ||
153
+ (metadata.payload.kind === "enum" &&
154
+ !metadata.payload.allowedValues?.length)
155
+ ) {
156
+ issues.push({
157
+ code: "invalid-action-metadata",
158
+ path: `actions.${actionName}`,
159
+ message:
160
+ "Every semantic action must describe its intent, expected result, and enum values when applicable.",
161
+ });
162
+ }
163
+
164
+ try {
165
+ resolveAirJamAgentActionPayload(
166
+ action,
167
+ representativePayload(
168
+ metadata.payload.kind,
169
+ metadata.payload.allowedValues,
170
+ ),
171
+ { gameId, actionName, contractKind: "conformance" },
172
+ );
173
+ } catch (error) {
174
+ issues.push({
175
+ code: "payload-parse-failed",
176
+ path: `actions.${actionName}.input`,
177
+ message: error instanceof Error ? error.message : String(error),
178
+ });
179
+ }
180
+ }
181
+
182
+ try {
183
+ const snapshot = await contract.projectSnapshot({ controllerId, stores });
184
+ inspectJsonValue(snapshot, "snapshot", new Set(), issues);
185
+ } catch (error) {
186
+ issues.push({
187
+ code: "snapshot-failed",
188
+ path: "snapshot",
189
+ message: error instanceof Error ? error.message : String(error),
190
+ });
191
+ }
192
+
193
+ return {
194
+ schemaVersion: 1,
195
+ gameId,
196
+ ok: issues.length === 0,
197
+ storeDomains,
198
+ actionNames,
199
+ issues,
200
+ };
201
+ };
@@ -18,3 +18,8 @@ export {
18
18
  type AirJamAgentActionContract,
19
19
  type AirJamAgentContract,
20
20
  } from "./agent/agent-contract";
21
+ export {
22
+ inspectAirJamAgentContractConformance,
23
+ type AirJamAgentContractConformanceIssue,
24
+ type AirJamAgentContractConformanceReport,
25
+ } from "./agent/agent-contract-conformance";
@@ -0,0 +1,6 @@
1
+ export {
2
+ AirJamControllerRuntime,
3
+ AirJamHostRuntime,
4
+ type AirJamControllerRuntimeProps,
5
+ type AirJamHostRuntimeProps,
6
+ } from "../runtime/session-runtimes";
@@ -1,4 +1,5 @@
1
1
  export * from "../runtime/arcade-bridge-request-surface";
2
2
  export * from "../runtime/arcade-runtime-url";
3
3
  export * from "../runtime/arcade-surface-identity";
4
+ export * from "../runtime/local-reference-game-identity";
4
5
  export { AIR_JAM_ARCADE_SURFACE_STORE_DOMAIN } from "../store/air-jam-store-domain-constants";
@@ -42,12 +42,6 @@
42
42
  * );
43
43
  * ```
44
44
  */
45
- import type {
46
- ResolvedAirJamRuntimeTopology,
47
- RuntimeTopologyInput,
48
- SurfaceRole,
49
- } from "../runtime-topology";
50
- import { isLocalDevControlSurfaceTopology } from "../runtime-topology";
51
45
  import {
52
46
  createContext,
53
47
  useCallback,
@@ -65,6 +59,12 @@ import { InputManager, type InputConfig } from "../internal/input-manager";
65
59
  import type { ConnectionRole } from "../protocol";
66
60
  import { AIRJAM_DEV_LOG_EVENTS } from "../protocol";
67
61
  import type { HostSessionKind } from "../protocol/host";
62
+ import type {
63
+ ResolvedAirJamRuntimeTopology,
64
+ RuntimeTopologyInput,
65
+ SurfaceRole,
66
+ } from "../runtime-topology";
67
+ import { isLocalDevControlSurfaceTopology } from "../runtime-topology";
68
68
  import type { AirJamConfig } from "../runtime/air-jam-config";
69
69
  import { resolveAirJamConfig } from "../runtime/air-jam-config";
70
70
  import {
@@ -113,7 +113,7 @@ export interface AirJamProviderProps<
113
113
  children: ReactNode;
114
114
  /** Explicit runtime topology for this surface. Prefer this over loose endpoint props. */
115
115
  topology?: RuntimeTopologyInput | ResolvedAirJamRuntimeTopology;
116
- /** Internal surface-role hint when normalizing legacy endpoint props into topology. */
116
+ /** Internal surface-role hint used while resolving topology. */
117
117
  surfaceRole?: SurfaceRole;
118
118
  /**
119
119
  * App ID for production bootstrap identity.
@@ -478,7 +478,7 @@ export const useAirJamContext = (): AirJamContextValue => {
478
478
  * @example
479
479
  * ```tsx
480
480
  * const config = useAirJamConfig();
481
- * console.log(config.serverUrl, config.maxPlayers);
481
+ * console.log(config.topology.backendOrigin, config.maxPlayers);
482
482
  * ```
483
483
  */
484
484
  export const useAirJamConfig = (): AirJamConfig => {
@@ -63,13 +63,6 @@ export class SocketManager {
63
63
  }
64
64
  }
65
65
 
66
- /**
67
- * Deprecated compatibility alias. Returns the resolved socket origin.
68
- */
69
- getServerUrl(): string {
70
- return this.socketOrigin;
71
- }
72
-
73
66
  private normalizeOrigin(origin: string): string {
74
67
  if (!origin.includes("://")) {
75
68
  return `http://${origin}`;
@@ -1,8 +1,3 @@
1
- import {
2
- isLocalDevControlSurfaceTopology,
3
- type ProxyStrategy,
4
- type ResolvedAirJamRuntimeTopology,
5
- } from "../runtime-topology";
6
1
  import {
7
2
  onAirJamDiagnostic,
8
3
  type AirJamDiagnostic,
@@ -17,6 +12,11 @@ import {
17
12
  AIRJAM_DEV_LOG_EVENTS,
18
13
  resolveAirJamBrowserConsoleCategory,
19
14
  } from "../protocol";
15
+ import {
16
+ isLocalDevControlSurfaceTopology,
17
+ type ProxyStrategy,
18
+ type ResolvedAirJamRuntimeTopology,
19
+ } from "../runtime-topology";
20
20
  import {
21
21
  AIRJAM_DEV_LOG_SINK_FAILURE,
22
22
  AIRJAM_DEV_RUNTIME_EVENT,
@@ -74,7 +74,6 @@ type ConsoleMethodName = "debug" | "info" | "log" | "warn" | "error";
74
74
 
75
75
  interface BrowserLogSinkOptions {
76
76
  backendOrigin?: string;
77
- serverUrl?: string;
78
77
  appOrigin?: string;
79
78
  proxyStrategy?: ProxyStrategy;
80
79
  appId?: string;
@@ -134,30 +133,28 @@ const isDevelopmentRuntime = (): boolean => {
134
133
 
135
134
  const resolveEndpointBase = ({
136
135
  backendOrigin,
137
- serverUrl,
138
136
  appOrigin,
139
137
  proxyStrategy,
140
138
  }: Pick<
141
139
  BrowserLogSinkOptions,
142
- "backendOrigin" | "serverUrl" | "appOrigin" | "proxyStrategy"
140
+ "backendOrigin" | "appOrigin" | "proxyStrategy"
143
141
  >): string | null => {
144
142
  if (proxyStrategy && proxyStrategy !== "none") {
145
143
  return (appOrigin ?? resolveDevProxyBaseUrl())?.replace(/\/$/, "") ?? null;
146
144
  }
147
145
 
148
- const explicitOrigin = backendOrigin ?? serverUrl;
149
- if (!explicitOrigin) {
146
+ if (!backendOrigin) {
150
147
  return resolveDevProxyBaseUrl();
151
148
  }
152
149
 
153
- if (explicitOrigin.startsWith("ws://")) {
154
- return `http://${explicitOrigin.slice(5)}`.replace(/\/$/, "");
150
+ if (backendOrigin.startsWith("ws://")) {
151
+ return `http://${backendOrigin.slice(5)}`.replace(/\/$/, "");
155
152
  }
156
- if (explicitOrigin.startsWith("wss://")) {
157
- return `https://${explicitOrigin.slice(6)}`.replace(/\/$/, "");
153
+ if (backendOrigin.startsWith("wss://")) {
154
+ return `https://${backendOrigin.slice(6)}`.replace(/\/$/, "");
158
155
  }
159
156
 
160
- return explicitOrigin.replace(/\/$/, "");
157
+ return backendOrigin.replace(/\/$/, "");
161
158
  };
162
159
 
163
160
  const resolveDevProxyBaseUrl = (): string | null => {
package/src/events.ts CHANGED
@@ -12,11 +12,6 @@ export const HostEvents = {
12
12
  */
13
13
  BOOTSTRAP: "host:bootstrap",
14
14
 
15
- /**
16
- * Register as the system/arcade master host
17
- */
18
- REGISTER_SYSTEM: "host:registerSystem",
19
-
20
15
  /**
21
16
  * Join as a child host (game launched from arcade)
22
17
  */
@@ -26,6 +26,7 @@ import {
26
26
  controllerJoinSchema,
27
27
  controllerLeaveSchema,
28
28
  controllerSystemSchema,
29
+ ErrorCode,
29
30
  playerProfilePatchSchema,
30
31
  roomCodeSchema,
31
32
  } from "../../protocol";
@@ -35,11 +36,16 @@ import type {
35
36
  ControllerWelcomePayload,
36
37
  PlayerUpdatedNotice,
37
38
  } from "../../protocol/notices";
39
+ import {
40
+ resolveAdmissionRetry,
41
+ type AdmissionRetryDecision,
42
+ } from "../../runtime/admission-retry";
38
43
  import {
39
44
  clearControllerRoomBinding,
40
45
  getOrCreateControllerDeviceId,
41
46
  readControllerRoomBinding,
42
47
  writeControllerRoomBinding,
48
+ type ControllerRoomBinding,
43
49
  } from "../../runtime/controller-identity";
44
50
  import { getControllerRealtimeClient } from "../../runtime/controller-realtime-client";
45
51
  import { emitAirJamDevRuntimeEvent } from "../../runtime/dev-runtime-events";
@@ -169,14 +175,21 @@ export const useControllerRuntimeApi = (
169
175
  if (urlControllerId) return urlControllerId;
170
176
  }
171
177
  if (parsedRoomId) {
172
- const persistedControllerId = readControllerRoomBinding(parsedRoomId);
173
- if (persistedControllerId) {
174
- return persistedControllerId;
178
+ const persistedBinding = readControllerRoomBinding(parsedRoomId);
179
+ if (persistedBinding) {
180
+ return persistedBinding.controllerId;
175
181
  }
176
182
  }
177
183
  return generateControllerId();
178
184
  }, [options.controllerId, embeddedController, parsedRoomId]);
179
185
 
186
+ // Keep recovery authority even when browser storage is unavailable. Never pass
187
+ // it through the embedded game bridge, public player state, or runtime logs.
188
+ const resumeBindingRef = useRef<{
189
+ roomId: string;
190
+ binding: ControllerRoomBinding;
191
+ } | null>(null);
192
+
180
193
  const onStateRef = useRef<AirJamControllerOptions["onState"]>(
181
194
  options.onState,
182
195
  );
@@ -463,6 +476,17 @@ export const useControllerRuntimeApi = (
463
476
  return;
464
477
  }
465
478
 
479
+ let disposed = false;
480
+ let joinEpoch = 0;
481
+ let joinRetryTimeout: ReturnType<typeof setTimeout> | null = null;
482
+ const clearJoinRetryTimeout = (): void => {
483
+ if (!joinRetryTimeout) {
484
+ return;
485
+ }
486
+ clearTimeout(joinRetryTimeout);
487
+ joinRetryTimeout = null;
488
+ };
489
+
466
490
  storeState.setControllerId(controllerId);
467
491
  if (
468
492
  embeddedController?.playerProfile?.label ||
@@ -483,22 +507,24 @@ export const useControllerRuntimeApi = (
483
507
  storeState.upsertPlayer(fallbackPlayer);
484
508
  }
485
509
 
486
- const handleConnect = (): void => {
487
- emitControllerRuntimeEvent({
488
- event: AIRJAM_DEV_LOG_EVENTS.runtime.socketConnected,
489
- message: "Controller socket connected",
490
- roomId: parsedRoomId ?? undefined,
491
- data: {
492
- socketId: socket.id,
493
- connected: socket.connected,
494
- },
495
- });
496
- store.getState().setStatus("connected");
497
-
498
- if (embeddedController) {
510
+ const attemptJoin = (
511
+ completedRetries: number,
512
+ operationEpoch: number,
513
+ retry?: AdmissionRetryDecision,
514
+ ): void => {
515
+ if (
516
+ disposed ||
517
+ operationEpoch !== joinEpoch ||
518
+ !socket.connected ||
519
+ embeddedController
520
+ ) {
499
521
  return;
500
522
  }
501
523
 
524
+ const resumeBinding =
525
+ resumeBindingRef.current?.roomId === parsedRoomId
526
+ ? resumeBindingRef.current.binding
527
+ : readControllerRoomBinding(parsedRoomId);
502
528
  const payload = controllerJoinSchema.parse({
503
529
  roomId: parsedRoomId,
504
530
  controllerId,
@@ -506,10 +532,17 @@ export const useControllerRuntimeApi = (
506
532
  nickname: nicknameRef.current || undefined,
507
533
  avatarId: avatarIdRef.current || undefined,
508
534
  capabilityToken: capabilityToken ?? undefined,
535
+ resumeCapabilityToken:
536
+ resumeBinding?.controllerId === controllerId
537
+ ? resumeBinding.resumeCapabilityToken
538
+ : undefined,
509
539
  });
510
540
  emitControllerRuntimeEvent({
511
541
  event: AIRJAM_DEV_LOG_EVENTS.runtime.controllerJoinRequested,
512
- message: "Controller requested room join",
542
+ message:
543
+ completedRetries === 0
544
+ ? "Controller requested room join"
545
+ : "Controller retried room join after admission denial",
513
546
  roomId: payload.roomId,
514
547
  data: {
515
548
  joinSource,
@@ -517,28 +550,82 @@ export const useControllerRuntimeApi = (
517
550
  hasNickname: Boolean(payload.nickname),
518
551
  hasAvatarId: Boolean(payload.avatarId),
519
552
  hasCapabilityToken: Boolean(payload.capabilityToken),
553
+ admissionAttempt: completedRetries + 1,
554
+ ...(retry
555
+ ? {
556
+ retryReasonCode: retry.code,
557
+ retryAfterSeconds: retry.retryAfterSeconds,
558
+ }
559
+ : {}),
520
560
  },
521
561
  });
522
562
  socket.emit("controller:join", payload, (ack: ControllerJoinAck) => {
563
+ if (disposed || operationEpoch !== joinEpoch) {
564
+ return;
565
+ }
566
+
523
567
  const latestState = store.getState();
524
568
  if (!ack.ok) {
525
- if (ack.code === "ROOM_NOT_FOUND") {
569
+ if (ack.code === ErrorCode.ROOM_NOT_FOUND) {
526
570
  clearControllerRoomBinding(parsedRoomId);
527
571
  }
528
572
  latestState.setError(ack.message ?? "Unable to join room");
529
- latestState.setStatus("disconnected");
530
573
  latestState.resetRuntimeState();
574
+
575
+ const retryDecision = resolveAdmissionRetry(ack, completedRetries);
576
+ if (retryDecision) {
577
+ latestState.setStatus("connecting");
578
+ clearJoinRetryTimeout();
579
+ joinRetryTimeout = setTimeout(() => {
580
+ joinRetryTimeout = null;
581
+ attemptJoin(completedRetries + 1, operationEpoch, retryDecision);
582
+ }, retryDecision.delayMs);
583
+ return;
584
+ }
585
+
586
+ latestState.setStatus("disconnected");
531
587
  return;
532
588
  }
533
589
  if (ack.controllerId) {
534
590
  latestState.setControllerId(ack.controllerId);
535
- writeControllerRoomBinding(parsedRoomId, ack.controllerId);
591
+ if (ack.resumeCapabilityToken) {
592
+ const binding = {
593
+ controllerId: ack.controllerId,
594
+ resumeCapabilityToken: ack.resumeCapabilityToken,
595
+ };
596
+ resumeBindingRef.current = { roomId: parsedRoomId, binding };
597
+ writeControllerRoomBinding(parsedRoomId, binding);
598
+ }
536
599
  }
600
+ latestState.setError(undefined);
537
601
  latestState.setStatus("connected");
538
602
  });
539
603
  };
540
604
 
605
+ const handleConnect = (): void => {
606
+ clearJoinRetryTimeout();
607
+ joinEpoch += 1;
608
+ const operationEpoch = joinEpoch;
609
+ emitControllerRuntimeEvent({
610
+ event: AIRJAM_DEV_LOG_EVENTS.runtime.socketConnected,
611
+ message: "Controller socket connected",
612
+ roomId: parsedRoomId ?? undefined,
613
+ data: {
614
+ socketId: socket.id,
615
+ connected: socket.connected,
616
+ },
617
+ });
618
+ store.getState().setStatus("connected");
619
+
620
+ if (embeddedController) {
621
+ return;
622
+ }
623
+ attemptJoin(0, operationEpoch);
624
+ };
625
+
541
626
  const handleDisconnect = (reason?: string): void => {
627
+ joinEpoch += 1;
628
+ clearJoinRetryTimeout();
542
629
  emitControllerRuntimeEvent({
543
630
  event: AIRJAM_DEV_LOG_EVENTS.runtime.socketDisconnected,
544
631
  message: "Controller socket disconnected",
@@ -582,7 +669,6 @@ export const useControllerRuntimeApi = (
582
669
  if (!storeRoomId && payload.roomId) {
583
670
  latestState.setRoomId(payload.roomId);
584
671
  }
585
- writeControllerRoomBinding(payload.roomId, payload.controllerId);
586
672
  if (Array.isArray(payload.players)) {
587
673
  latestState.resetPlayers();
588
674
  payload.players.forEach((player) => {
@@ -756,6 +842,9 @@ export const useControllerRuntimeApi = (
756
842
  }
757
843
 
758
844
  return () => {
845
+ disposed = true;
846
+ joinEpoch += 1;
847
+ clearJoinRetryTimeout();
759
848
  socket.off("connect", handleConnect);
760
849
  socket.off("disconnect", handleDisconnect);
761
850
  socket.off("connect_error", handleConnectError);