@air-jam/devtools 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.
Files changed (263) hide show
  1. package/README.md +60 -0
  2. package/dist/{chunk-VKMJO6VN.js → chunk-2O67AXCU.js} +150 -40
  3. package/dist/chunk-2O67AXCU.js.map +1 -0
  4. package/dist/chunk-AO3ZDXF6.js +142 -0
  5. package/dist/chunk-AO3ZDXF6.js.map +1 -0
  6. package/dist/chunk-ART5TEYT.js +472 -0
  7. package/dist/chunk-ART5TEYT.js.map +1 -0
  8. package/dist/chunk-ASC2CK2R.js +77 -0
  9. package/dist/chunk-ASC2CK2R.js.map +1 -0
  10. package/dist/chunk-E3UZZGAV.js +50 -0
  11. package/dist/chunk-E3UZZGAV.js.map +1 -0
  12. package/dist/chunk-EJTE7UKX.js +64 -0
  13. package/dist/chunk-EJTE7UKX.js.map +1 -0
  14. package/dist/chunk-ESFKNN75.js +110 -0
  15. package/dist/chunk-ESFKNN75.js.map +1 -0
  16. package/dist/chunk-EU7A6PXW.js +1339 -0
  17. package/dist/chunk-EU7A6PXW.js.map +1 -0
  18. package/dist/chunk-FN7E6EA7.js +549 -0
  19. package/dist/chunk-FN7E6EA7.js.map +1 -0
  20. package/dist/chunk-GDFAWHGA.js +190 -0
  21. package/dist/chunk-GDFAWHGA.js.map +1 -0
  22. package/dist/chunk-HZUGBH4Y.js +347 -0
  23. package/dist/chunk-HZUGBH4Y.js.map +1 -0
  24. package/dist/chunk-ITKAOEGX.js +93 -0
  25. package/dist/chunk-ITKAOEGX.js.map +1 -0
  26. package/dist/chunk-JBCUTWRI.js +897 -0
  27. package/dist/chunk-JBCUTWRI.js.map +1 -0
  28. package/dist/chunk-JSI5S4WP.js +1174 -0
  29. package/dist/chunk-JSI5S4WP.js.map +1 -0
  30. package/dist/chunk-L4D675BG.js +97 -0
  31. package/dist/chunk-L4D675BG.js.map +1 -0
  32. package/dist/chunk-M6CJ7GQC.js +133 -0
  33. package/dist/chunk-M6CJ7GQC.js.map +1 -0
  34. package/dist/{chunk-CKFT2ZJE.js → chunk-MEIMOSZC.js} +53 -105
  35. package/dist/chunk-MEIMOSZC.js.map +1 -0
  36. package/dist/{chunk-GUEZP773.js → chunk-O3XG3FNL.js} +204 -41
  37. package/dist/chunk-O3XG3FNL.js.map +1 -0
  38. package/dist/chunk-OM6SCJ7H.js +18 -0
  39. package/dist/chunk-OM6SCJ7H.js.map +1 -0
  40. package/dist/chunk-PKD4WVX5.js +63 -0
  41. package/dist/chunk-PKD4WVX5.js.map +1 -0
  42. package/dist/chunk-PMBLXGFM.js +3384 -0
  43. package/dist/chunk-PMBLXGFM.js.map +1 -0
  44. package/dist/chunk-PMNE5GIN.js +279 -0
  45. package/dist/chunk-PMNE5GIN.js.map +1 -0
  46. package/dist/chunk-QAWI64VR.js +148 -0
  47. package/dist/chunk-QAWI64VR.js.map +1 -0
  48. package/dist/chunk-QGADSPHZ.js +449 -0
  49. package/dist/chunk-QGADSPHZ.js.map +1 -0
  50. package/dist/chunk-SPYN66UV.js +338 -0
  51. package/dist/chunk-SPYN66UV.js.map +1 -0
  52. package/dist/context.d.ts +9 -3
  53. package/dist/context.js +2 -1
  54. package/dist/controller.d.ts +33 -7
  55. package/dist/controller.js +18 -8
  56. package/dist/dependencies.d.ts +44 -0
  57. package/dist/dependencies.js +10 -0
  58. package/dist/dev.d.ts +9 -3
  59. package/dist/dev.js +3 -4
  60. package/dist/game-builds.d.ts +200 -0
  61. package/dist/game-builds.js +16 -0
  62. package/dist/game-builds.js.map +1 -0
  63. package/dist/game-run-watch-CEd_SpAT.d.ts +84 -0
  64. package/dist/game-runs.d.ts +1452 -0
  65. package/dist/game-runs.js +76 -0
  66. package/dist/game-runs.js.map +1 -0
  67. package/dist/game-session-broker-CUvORfMd.d.ts +439 -0
  68. package/dist/game-session-broker.d.ts +4 -57
  69. package/dist/game-session-broker.js +33 -228
  70. package/dist/game-session-broker.js.map +1 -1
  71. package/dist/game-session.d.ts +3931 -10
  72. package/dist/game-session.js +186 -15
  73. package/dist/game-session.js.map +1 -1
  74. package/dist/game-settings.d.ts +16 -0
  75. package/dist/game-settings.js +237 -0
  76. package/dist/game-settings.js.map +1 -0
  77. package/dist/games.d.ts +11 -4
  78. package/dist/games.js +4 -2
  79. package/dist/harness/visual.d.ts +34 -151
  80. package/dist/harness/visual.js +6 -1
  81. package/dist/logs.d.ts +8 -2
  82. package/dist/logs.js +3 -4
  83. package/dist/logs.js.map +1 -1
  84. package/dist/managed-process-scope-BicYi_t9.d.ts +3 -0
  85. package/dist/mcp-config.js +2 -1
  86. package/dist/mcp-config.js.map +1 -1
  87. package/dist/platform-auth.d.ts +8 -111
  88. package/dist/platform-auth.js +9 -1
  89. package/dist/platform-game-analytics.d.ts +51 -0
  90. package/dist/platform-game-analytics.js +49 -0
  91. package/dist/platform-game-analytics.js.map +1 -0
  92. package/dist/platform-game-app-id.d.ts +46 -0
  93. package/dist/platform-game-app-id.js +93 -0
  94. package/dist/platform-game-app-id.js.map +1 -0
  95. package/dist/platform-game-media.d.ts +40 -2
  96. package/dist/platform-game-media.js +1 -1
  97. package/dist/platform-games.d.ts +24 -2
  98. package/dist/platform-games.js +16 -84
  99. package/dist/platform-games.js.map +1 -1
  100. package/dist/quality.d.ts +9 -3
  101. package/dist/quality.js +3 -4
  102. package/dist/quality.js.map +1 -1
  103. package/dist/release.d.ts +226 -16
  104. package/dist/release.js +18 -1331
  105. package/dist/release.js.map +1 -1
  106. package/dist/rooms-check.d.ts +90 -0
  107. package/dist/rooms-check.js +717 -0
  108. package/dist/rooms-check.js.map +1 -0
  109. package/dist/source-tree-contract.d.ts +16 -0
  110. package/dist/source-tree-contract.js +13 -0
  111. package/dist/source-tree-contract.js.map +1 -0
  112. package/dist/testing.d.ts +464 -0
  113. package/dist/testing.js +27 -0
  114. package/dist/testing.js.map +1 -0
  115. package/dist/tooling/describe-game.js +54 -0
  116. package/dist/tooling/describe-game.js.map +1 -0
  117. package/dist/tooling/game-session-broker.js +28 -0
  118. package/dist/tooling/game-session-broker.js.map +1 -0
  119. package/dist/tooling/hold-runtime-host.js +769 -67
  120. package/dist/tooling/hold-runtime-host.js.map +1 -1
  121. package/dist/tooling/list-visual-scenarios.js +18 -55
  122. package/dist/tooling/list-visual-scenarios.js.map +1 -1
  123. package/dist/tooling/process-scope-bootstrap.mjs +24 -0
  124. package/dist/tooling/process-scope-guard.d.ts +2 -0
  125. package/dist/tooling/process-scope-guard.js +388 -0
  126. package/dist/tooling/process-scope-guard.js.map +1 -0
  127. package/dist/tooling/process-scope-windows.ps1 +148 -0
  128. package/dist/tooling/rooms-check-device.d.ts +2 -0
  129. package/dist/tooling/rooms-check-device.js +498 -0
  130. package/dist/tooling/rooms-check-device.js.map +1 -0
  131. package/dist/tooling/run-headless-room.d.ts +2 -0
  132. package/dist/tooling/run-headless-room.js +287 -0
  133. package/dist/tooling/run-headless-room.js.map +1 -0
  134. package/dist/tooling/run-test-profile.d.ts +2 -0
  135. package/dist/tooling/run-test-profile.js +181 -0
  136. package/dist/tooling/run-test-profile.js.map +1 -0
  137. package/dist/tooling/run-visual-capture.js +70 -34
  138. package/dist/tooling/run-visual-capture.js.map +1 -1
  139. package/dist/tooling/seal-game-build.d.ts +2 -0
  140. package/dist/tooling/seal-game-build.js +120 -0
  141. package/dist/tooling/seal-game-build.js.map +1 -0
  142. package/dist/{types-C6NrHt88.d.ts → types-CdYrgrG_.d.ts} +337 -76
  143. package/dist/types-DyRD-ym1.d.ts +141 -0
  144. package/dist/visual.d.ts +9 -3
  145. package/dist/visual.js +24 -68
  146. package/dist/visual.js.map +1 -1
  147. package/package.json +51 -14
  148. package/src/bounded-response.ts +28 -0
  149. package/src/built-game-runtime.ts +152 -0
  150. package/src/context.ts +2 -13
  151. package/src/controller-protocol.ts +22 -0
  152. package/src/controller.ts +747 -597
  153. package/src/current-room-host.ts +166 -0
  154. package/src/decision-provider.ts +102 -0
  155. package/src/dependencies.ts +176 -0
  156. package/src/dependency-install-contract.ts +12 -0
  157. package/src/dev.ts +46 -50
  158. package/src/game-action-observation.ts +11 -1
  159. package/src/game-build-protocol.ts +72 -0
  160. package/src/game-build.ts +483 -0
  161. package/src/game-run-owner.ts +2358 -0
  162. package/src/game-run-protocol.ts +448 -0
  163. package/src/game-run-record.ts +92 -0
  164. package/src/game-run-replay.ts +95 -0
  165. package/src/game-run-watch.ts +155 -0
  166. package/src/game-session-broker.ts +689 -197
  167. package/src/game-session-operations.ts +61 -0
  168. package/src/game-session-protocol.ts +180 -0
  169. package/src/game-session-runtime.ts +861 -0
  170. package/src/game-session.ts +164 -417
  171. package/src/game-settings.ts +295 -0
  172. package/src/games.ts +88 -92
  173. package/src/harness/visual/browser.ts +100 -0
  174. package/src/harness/visual/controller-observation.ts +181 -0
  175. package/src/harness/visual/runner.ts +24 -21
  176. package/src/harness/visual/runtime-controller-observations.ts +151 -0
  177. package/src/harness/visual/scenario-contract.ts +1 -2
  178. package/src/harness/visual/scenario-helpers.ts +5 -1
  179. package/src/harness/visual/screencast.ts +155 -0
  180. package/src/harness/visual/session.ts +72 -41
  181. package/src/harness/visual/types.ts +8 -5
  182. package/src/headless-room-protocol.ts +112 -0
  183. package/src/headless-room.ts +222 -0
  184. package/src/helper-channel.ts +229 -0
  185. package/src/helper-scripts.ts +25 -5
  186. package/src/installed-dependencies.ts +74 -0
  187. package/src/managed-process-scope.ts +481 -0
  188. package/src/node-process-environment.ts +10 -0
  189. package/src/platform-auth.ts +194 -55
  190. package/src/platform-game-analytics.ts +50 -0
  191. package/src/platform-game-app-id.ts +99 -0
  192. package/src/platform-games.ts +13 -111
  193. package/src/policy-artifact-contract.ts +52 -0
  194. package/src/policy-artifacts.ts +134 -0
  195. package/src/process-scope-admission.ts +50 -0
  196. package/src/process-scope-protocol.ts +66 -0
  197. package/src/process-scope.ts +327 -0
  198. package/src/release.ts +28 -42
  199. package/src/rooms-check-fleet.ts +194 -0
  200. package/src/rooms-check-link.ts +138 -0
  201. package/src/rooms-check-protocol.ts +244 -0
  202. package/src/rooms-check.ts +797 -0
  203. package/src/runtime-owner-protocol.ts +106 -18
  204. package/src/source-tree-contract.ts +70 -0
  205. package/src/source-tree.ts +84 -0
  206. package/src/test-profile-process.ts +153 -0
  207. package/src/test-profile-protocol.ts +116 -0
  208. package/src/testing.ts +430 -0
  209. package/src/tooling/declaration-hook.ts +52 -0
  210. package/src/tooling/describe-game.ts +49 -0
  211. package/src/tooling/game-session-broker.ts +7 -0
  212. package/src/tooling/hold-runtime-host.ts +255 -38
  213. package/src/tooling/list-visual-scenarios.ts +19 -62
  214. package/src/tooling/load-game.ts +79 -0
  215. package/src/tooling/process-scope-bootstrap.mjs +24 -0
  216. package/src/tooling/process-scope-guard.ts +213 -0
  217. package/src/tooling/process-scope-windows.ps1 +148 -0
  218. package/src/tooling/rooms-check-device.ts +493 -0
  219. package/src/tooling/run-headless-room.ts +326 -0
  220. package/src/tooling/run-test-profile.ts +190 -0
  221. package/src/tooling/run-visual-capture.ts +37 -23
  222. package/src/tooling/runtime-owner-actions.ts +23 -0
  223. package/src/tooling/seal-game-build.ts +118 -0
  224. package/src/tooling/visual-pack.ts +10 -45
  225. package/src/types.ts +54 -77
  226. package/src/visual.ts +14 -22
  227. package/src/windows-process-scopes.ts +189 -0
  228. package/dist/agent.d.ts +0 -15
  229. package/dist/agent.js +0 -19
  230. package/dist/chunk-5YAARMW5.js +0 -36
  231. package/dist/chunk-5YAARMW5.js.map +0 -1
  232. package/dist/chunk-6WQODT37.js +0 -1019
  233. package/dist/chunk-6WQODT37.js.map +0 -1
  234. package/dist/chunk-CKFT2ZJE.js.map +0 -1
  235. package/dist/chunk-ER3Q2C4G.js +0 -358
  236. package/dist/chunk-ER3Q2C4G.js.map +0 -1
  237. package/dist/chunk-GUEZP773.js.map +0 -1
  238. package/dist/chunk-HIDNI56E.js +0 -33
  239. package/dist/chunk-HIDNI56E.js.map +0 -1
  240. package/dist/chunk-QKXS5D35.js +0 -43
  241. package/dist/chunk-QKXS5D35.js.map +0 -1
  242. package/dist/chunk-S4LSCEVE.js +0 -261
  243. package/dist/chunk-S4LSCEVE.js.map +0 -1
  244. package/dist/chunk-VKMJO6VN.js.map +0 -1
  245. package/dist/chunk-WFUR3MXY.js +0 -67
  246. package/dist/chunk-WFUR3MXY.js.map +0 -1
  247. package/dist/chunk-XEMR7KUE.js +0 -361
  248. package/dist/chunk-XEMR7KUE.js.map +0 -1
  249. package/dist/chunk-ZLPD7FY5.js +0 -191
  250. package/dist/chunk-ZLPD7FY5.js.map +0 -1
  251. package/dist/tooling/agent-contract.js +0 -193
  252. package/dist/tooling/agent-contract.js.map +0 -1
  253. package/dist/tooling/inspect-airjam-agent.js +0 -37
  254. package/dist/tooling/inspect-airjam-agent.js.map +0 -1
  255. package/src/agent.ts +0 -380
  256. package/src/tooling/agent-contract.ts +0 -232
  257. package/src/tooling/agent-declaration.ts +0 -36
  258. package/src/tooling/airjam-agent-inspection.ts +0 -45
  259. package/src/tooling/airjam-agent.ts +0 -118
  260. package/src/tooling/inspect-airjam-agent.ts +0 -20
  261. /package/dist/{agent.js.map → dependencies.js.map} +0 -0
  262. /package/dist/tooling/{agent-contract.d.ts → describe-game.d.ts} +0 -0
  263. /package/dist/tooling/{inspect-airjam-agent.d.ts → game-session-broker.d.ts} +0 -0
@@ -1,15 +1,24 @@
1
+ import {
2
+ fixedControllerOrientation,
3
+ type AirJamGameInputModality,
4
+ } from "@air-jam/sdk/metadata";
1
5
  import {
2
6
  AIR_JAM_RUNTIME_INSPECTION_KEY,
3
7
  readRuntimeInspectionContract,
4
8
  } from "@air-jam/sdk/runtime-inspection";
5
9
  import {
6
- chromium,
10
+ AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX,
11
+ resolveRuntimeTopology,
12
+ type ResolvedAirJamRuntimeTopology,
13
+ } from "@air-jam/sdk/runtime-topology";
14
+ import {
7
15
  type Browser,
8
16
  type BrowserContext,
9
17
  type Frame,
10
18
  type FrameLocator,
11
19
  type Page,
12
20
  } from "playwright-core";
21
+ import { installHarnessRuntimeTopology } from "./browser.js";
13
22
  import type {
14
23
  VisualHarnessMode,
15
24
  VisualHarnessPageSurface,
@@ -132,6 +141,20 @@ const readHostRuntimeInspection = async ({
132
141
  return inspection?.role === "host" ? inspection : null;
133
142
  };
134
143
 
144
+ export function bindHarnessControllerUrl(
145
+ resolvedJoinUrl: string,
146
+ controllerBaseUrl: string,
147
+ ) {
148
+ const joinUrl = new URL(resolvedJoinUrl);
149
+ const controllerUrl = new URL(controllerBaseUrl);
150
+ joinUrl.protocol = controllerUrl.protocol;
151
+ joinUrl.host = controllerUrl.host;
152
+ for (const [key, value] of controllerUrl.searchParams)
153
+ if (key.startsWith(AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX))
154
+ joinUrl.searchParams.set(key, value);
155
+ return joinUrl.toString();
156
+ }
157
+
135
158
  const resolveControllerJoinUrl = async ({
136
159
  hostPage,
137
160
  hostGame,
@@ -178,15 +201,14 @@ const resolveControllerJoinUrl = async ({
178
201
  );
179
202
  }
180
203
 
181
- const joinUrl = new URL(resolvedJoinUrl);
182
- const controllerUrl = new URL(controllerBaseUrl);
183
- joinUrl.protocol = controllerUrl.protocol;
184
- joinUrl.host = controllerUrl.host;
185
- return joinUrl.toString();
204
+ return bindHarnessControllerUrl(resolvedJoinUrl, controllerBaseUrl);
186
205
  };
187
206
 
188
207
  export type OpenVisualHarnessSessionOptions = {
189
208
  browser: Browser;
209
+ inputModalities?: readonly AirJamGameInputModality[];
210
+ runtimeTopology?: ResolvedAirJamRuntimeTopology;
211
+ onDiagnostic?: (message: string) => void;
190
212
  urls: Omit<VisualHarnessUrls, "controllerJoinUrl">;
191
213
  mode: VisualHarnessMode;
192
214
  };
@@ -218,6 +240,8 @@ export type OpenVisualHarnessSessionResult = {
218
240
 
219
241
  export const openVisualHarnessHostSession = async ({
220
242
  browser,
243
+ runtimeTopology,
244
+ onDiagnostic,
221
245
  urls,
222
246
  mode,
223
247
  }: OpenVisualHarnessSessionOptions): Promise<OpenVisualHarnessHostSessionResult> => {
@@ -227,7 +251,24 @@ export const openVisualHarnessHostSession = async ({
227
251
  });
228
252
 
229
253
  try {
254
+ if (runtimeTopology)
255
+ await installHarnessRuntimeTopology(hostContext, runtimeTopology);
230
256
  const hostPage = await hostContext.newPage();
257
+ if (onDiagnostic) {
258
+ hostPage.on("pageerror", (error) =>
259
+ onDiagnostic(`Page error: ${error.message}`),
260
+ );
261
+ hostPage.on("console", (message) => {
262
+ if (message.type() === "error")
263
+ onDiagnostic(`Browser error: ${message.text()}`);
264
+ });
265
+ hostPage.on("requestfailed", (request) => {
266
+ const url = new URL(request.url());
267
+ onDiagnostic(
268
+ `Request failed: ${url.origin}${url.pathname}: ${request.failure()?.errorText}`,
269
+ );
270
+ });
271
+ }
231
272
  await hostPage.goto(urls.hostUrl, { waitUntil: "domcontentloaded" });
232
273
  const hostGame: VisualQuerySurface = embedded
233
274
  ? await waitForFrameToLoad({
@@ -253,16 +294,32 @@ export const openVisualHarnessHostSession = async ({
253
294
 
254
295
  export const openVisualHarnessControllerSession = async ({
255
296
  browser,
297
+ inputModalities,
298
+ runtimeTopology,
256
299
  urls,
257
300
  host,
258
301
  }: Omit<OpenVisualHarnessSessionOptions, "mode"> & {
259
302
  host: VisualHarnessPageSurface;
260
303
  }): Promise<OpenVisualHarnessControllerSessionResult> => {
261
304
  const controllerContext = await browser.newContext({
262
- viewport: DEFAULT_CONTROLLER_VIEWPORT,
305
+ viewport:
306
+ fixedControllerOrientation(inputModalities ?? []) === "landscape"
307
+ ? {
308
+ width: DEFAULT_CONTROLLER_VIEWPORT.height,
309
+ height: DEFAULT_CONTROLLER_VIEWPORT.width,
310
+ }
311
+ : DEFAULT_CONTROLLER_VIEWPORT,
263
312
  });
264
313
 
265
314
  try {
315
+ if (runtimeTopology)
316
+ await installHarnessRuntimeTopology(
317
+ controllerContext,
318
+ resolveRuntimeTopology({
319
+ ...runtimeTopology,
320
+ surfaceRole: "controller",
321
+ }),
322
+ );
266
323
  const controllerJoinUrl = await resolveControllerJoinUrl({
267
324
  hostPage: host.page,
268
325
  hostGame: host.game,
@@ -300,11 +357,16 @@ export const openVisualHarnessControllerSession = async ({
300
357
 
301
358
  export const openVisualHarnessSession = async ({
302
359
  browser,
360
+ inputModalities,
361
+ runtimeTopology,
362
+ onDiagnostic,
303
363
  urls,
304
364
  mode,
305
365
  }: OpenVisualHarnessSessionOptions): Promise<OpenVisualHarnessSessionResult> => {
306
366
  const hostSession = await openVisualHarnessHostSession({
307
367
  browser,
368
+ runtimeTopology,
369
+ onDiagnostic,
308
370
  urls,
309
371
  mode,
310
372
  });
@@ -312,6 +374,8 @@ export const openVisualHarnessSession = async ({
312
374
  try {
313
375
  const controllerSession = await openVisualHarnessControllerSession({
314
376
  browser,
377
+ inputModalities,
378
+ runtimeTopology,
315
379
  urls,
316
380
  host: hostSession.host,
317
381
  });
@@ -333,37 +397,4 @@ export const openVisualHarnessSession = async ({
333
397
  }
334
398
  };
335
399
 
336
- export const launchHarnessBrowser = async (): Promise<Browser> => {
337
- const options = {
338
- headless: true,
339
- args: [
340
- "--enable-webgl",
341
- "--ignore-gpu-blocklist",
342
- "--use-angle=swiftshader",
343
- ],
344
- };
345
-
346
- if (process.env.AIRJAM_BROWSER_EXECUTABLE_PATH) {
347
- return chromium.launch({
348
- ...options,
349
- executablePath: process.env.AIRJAM_BROWSER_EXECUTABLE_PATH,
350
- });
351
- }
352
-
353
- try {
354
- return await chromium.launch(options);
355
- } catch (bundledBrowserError) {
356
- try {
357
- return await chromium.launch({ ...options, channel: "chrome" });
358
- } catch (systemBrowserError) {
359
- throw new Error(
360
- [
361
- "Air Jam could not launch a browser runtime for semantic sessions.",
362
- "Install Playwright Chromium or set AIRJAM_BROWSER_EXECUTABLE_PATH to a Chromium-compatible browser.",
363
- `Bundled browser: ${bundledBrowserError instanceof Error ? bundledBrowserError.message : String(bundledBrowserError)}`,
364
- `System Chrome: ${systemBrowserError instanceof Error ? systemBrowserError.message : String(systemBrowserError)}`,
365
- ].join("\n\n"),
366
- );
367
- }
368
- }
369
- };
400
+ export { launchHarnessBrowser } from "./browser.js";
@@ -1,7 +1,11 @@
1
- import type { AirJamAgentContract, AnyAirJamAgentContract } from "@air-jam/sdk";
1
+ import type {
2
+ AirJamAgentContract,
3
+ AnyAirJamAgentContract,
4
+ } from "@air-jam/sdk/core";
5
+ import type { AirJamGameInputModality } from "@air-jam/sdk/metadata";
2
6
  import type { Page } from "playwright-core";
3
7
 
4
- export type { AnyAirJamAgentContract } from "@air-jam/sdk";
8
+ export type { AnyAirJamAgentContract } from "@air-jam/sdk/core";
5
9
 
6
10
  export type VisualHarnessMode = "standalone-dev" | "arcade-built";
7
11
 
@@ -71,8 +75,7 @@ export type VisualScenarioAgentInvocation<TSnapshot = Record<string, unknown>> =
71
75
  snapshotBefore: TSnapshot | null;
72
76
  snapshotAfter: TSnapshot | null;
73
77
  snapshotAfterStatus:
74
- | "committed-update-observed"
75
- | "no-new-commit-before-timeout"
78
+ | import("../../types.js").InvokeGameActionResult["snapshotAfterStatus"]
76
79
  | null;
77
80
  };
78
81
 
@@ -100,6 +103,7 @@ export type VisualScenarioContext<
100
103
  gameId: string;
101
104
  scenario: VisualScenario<TAgent>;
102
105
  scenarioDir: string;
106
+ inputModalities?: readonly AirJamGameInputModality[];
103
107
  urls: VisualHarnessUrls;
104
108
  host: VisualHarnessPageSurface;
105
109
  controller: VisualHarnessPageSurface & {
@@ -133,7 +137,6 @@ export type VisualScenario<
133
137
  export type VisualScenarioPack<
134
138
  TAgent extends AnyAirJamAgentContract = AnyAirJamAgentContract,
135
139
  > = {
136
- agent: TAgent;
137
140
  scenarios: ReadonlyArray<VisualScenario<TAgent>>;
138
141
  };
139
142
 
@@ -0,0 +1,112 @@
1
+ import { airJamSettingsValuesSchema } from "@air-jam/sdk/core";
2
+ import {
3
+ hostAgentRequestSchema,
4
+ hostAgentResponseSchema,
5
+ } from "@air-jam/sdk/runtime-control";
6
+ import { z } from "zod";
7
+
8
+ export const HEADLESS_ROOM_IPC_MAX_BYTES = 1_000_000;
9
+ /** The longest stretch of game time one request may advance. */
10
+ export const HEADLESS_ROOM_MAX_ADVANCE_MS = 60_000;
11
+
12
+ export const headlessRoomRequestSchema = z.discriminatedUnion("kind", [
13
+ z
14
+ .object({
15
+ kind: z.literal("initialize"),
16
+ id: z.uuid(),
17
+ configPath: z.string().min(1),
18
+ settings: airJamSettingsValuesSchema.optional(),
19
+ seed: z.number().int().min(0).max(0xffff_ffff),
20
+ })
21
+ .strict(),
22
+ z
23
+ .object({
24
+ kind: z.literal("agent"),
25
+ id: z.uuid(),
26
+ request: hostAgentRequestSchema,
27
+ })
28
+ .strict(),
29
+ z
30
+ .object({
31
+ kind: z.literal("advance"),
32
+ id: z.uuid(),
33
+ ms: z.number().positive().max(HEADLESS_ROOM_MAX_ADVANCE_MS),
34
+ })
35
+ .strict(),
36
+ z
37
+ .object({
38
+ kind: z.literal("saveInputLog"),
39
+ id: z.uuid(),
40
+ /** Where the room writes its input log. */
41
+ path: z.string().min(1),
42
+ })
43
+ .strict(),
44
+ z
45
+ .object({
46
+ kind: z.literal("replay"),
47
+ id: z.uuid(),
48
+ configPath: z.string().min(1),
49
+ /** An input log this game recorded; the room plays it with no server. */
50
+ logPath: z.string().min(1),
51
+ })
52
+ .strict(),
53
+ ]);
54
+ export type HeadlessRoomRequest = z.infer<typeof headlessRoomRequestSchema>;
55
+
56
+ export const headlessRoomResponseSchema = z.discriminatedUnion("kind", [
57
+ z.object({ kind: z.literal("ready") }).strict(),
58
+ z
59
+ .object({
60
+ kind: z.literal("initialized"),
61
+ id: z.uuid(),
62
+ gameId: z.string().nullable(),
63
+ roomId: z.string().min(1),
64
+ controllerJoinUrl: z.url(),
65
+ nowMs: z.number().nonnegative(),
66
+ /** Whether the room keeps an input log: its game declares a simulation. */
67
+ recordsInputLog: z.boolean(),
68
+ })
69
+ .strict(),
70
+ z
71
+ .object({
72
+ kind: z.literal("agent"),
73
+ id: z.uuid(),
74
+ response: hostAgentResponseSchema,
75
+ })
76
+ .strict(),
77
+ z
78
+ .object({
79
+ kind: z.literal("advanced"),
80
+ id: z.uuid(),
81
+ nowMs: z.number().nonnegative(),
82
+ })
83
+ .strict(),
84
+ z
85
+ .object({
86
+ kind: z.literal("savedInputLog"),
87
+ id: z.uuid(),
88
+ sha256: z.string().regex(/^[a-f0-9]{64}$/),
89
+ ticks: z.number().int().nonnegative(),
90
+ stepMs: z.number().positive(),
91
+ entries: z.number().int().nonnegative(),
92
+ full: z.boolean(),
93
+ })
94
+ .strict(),
95
+ z
96
+ .object({
97
+ kind: z.literal("replayed"),
98
+ id: z.uuid(),
99
+ gameId: z.string().nullable(),
100
+ roomId: z.string().min(1),
101
+ ticks: z.number().int().nonnegative(),
102
+ })
103
+ .strict(),
104
+ z
105
+ .object({
106
+ kind: z.literal("error"),
107
+ id: z.uuid(),
108
+ message: z.string().max(2000),
109
+ })
110
+ .strict(),
111
+ ]);
112
+ export type HeadlessRoomResponse = z.infer<typeof headlessRoomResponseSchema>;
@@ -0,0 +1,222 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import type { GameRunClock } from "./game-run-owner.js";
3
+ import type { HostRequester } from "./game-session-runtime.js";
4
+ import {
5
+ HEADLESS_ROOM_IPC_MAX_BYTES,
6
+ HEADLESS_ROOM_MAX_ADVANCE_MS,
7
+ headlessRoomRequestSchema,
8
+ headlessRoomResponseSchema,
9
+ type HeadlessRoomRequest,
10
+ type HeadlessRoomResponse,
11
+ } from "./headless-room-protocol.js";
12
+ import { startHelperChannel } from "./helper-channel.js";
13
+ import {
14
+ closeAfterProcessFailure,
15
+ type ProcessScopeObserver,
16
+ } from "./managed-process-scope.js";
17
+
18
+ const REQUEST_TIMEOUT_MS = 5_000;
19
+ /** A replay plays the whole recorded match before it answers. */
20
+ const REPLAY_TIMEOUT_MS = 120_000;
21
+
22
+ export type HeadlessRoom = {
23
+ gameId: string | null;
24
+ roomId: string;
25
+ controllerJoinUrl: string;
26
+ /** Reaches the room's host directly, as an owned host. */
27
+ requestHost: HostRequester;
28
+ /** Game time: waiting advances the game rather than the wall clock. */
29
+ clock: GameRunClock;
30
+ /**
31
+ * Writes everything that reached the game so far, by step, for replays;
32
+ * null when the game declares no simulation to replay.
33
+ */
34
+ saveInputLog:
35
+ | ((path: string) => Promise<{
36
+ sha256: string;
37
+ ticks: number;
38
+ stepMs: number;
39
+ entries: number;
40
+ full: boolean;
41
+ }>)
42
+ | null;
43
+ stop: () => Promise<void>;
44
+ };
45
+
46
+ /**
47
+ * Opens a game's room headless in its own process: no page, no drawing, and
48
+ * a clock that moves only when the run waits on it.
49
+ */
50
+ export async function startHeadlessRoom({
51
+ rootDir,
52
+ toolingRootDir,
53
+ configPath,
54
+ seed,
55
+ settings,
56
+ logPath,
57
+ onScope,
58
+ startupSignal,
59
+ }: {
60
+ rootDir: string;
61
+ toolingRootDir?: string;
62
+ configPath: string;
63
+ seed: number;
64
+ settings?: Record<string, string | number | boolean>;
65
+ logPath: string;
66
+ onScope?: ProcessScopeObserver;
67
+ startupSignal?: AbortSignal;
68
+ }): Promise<HeadlessRoom> {
69
+ const channel = await startHelperChannel({
70
+ name: "room",
71
+ helper: "run-headless-room.ts",
72
+ rootDir,
73
+ toolingRootDir,
74
+ onScope,
75
+ startupSignal,
76
+ logPath,
77
+ maxBytes: HEADLESS_ROOM_IPC_MAX_BYTES,
78
+ requestSchema: headlessRoomRequestSchema,
79
+ responseSchema: headlessRoomResponseSchema,
80
+ });
81
+ // One request at a time reaches the room, in the order the run sent them.
82
+ let queue: Promise<unknown> = Promise.resolve();
83
+ const request = <TKind extends HeadlessRoomResponse["kind"]>(
84
+ input: HeadlessRoomRequest,
85
+ expected: TKind,
86
+ timeoutMs = REQUEST_TIMEOUT_MS,
87
+ ) => {
88
+ const result = queue.then(async () => {
89
+ const response = await channel.request(input, timeoutMs);
90
+ if (response.kind === "error") throw new Error(response.message);
91
+ if (response.kind !== expected)
92
+ throw new Error(`room_protocol: Expected ${expected}.`);
93
+ return response as Extract<HeadlessRoomResponse, { kind: TKind }>;
94
+ });
95
+ queue = result.catch(() => undefined);
96
+ return result;
97
+ };
98
+ try {
99
+ const opened = await request(
100
+ { kind: "initialize", id: randomUUID(), configPath, seed, settings },
101
+ "initialized",
102
+ 10_000,
103
+ );
104
+ let nowMs = opened.nowMs;
105
+ return {
106
+ gameId: opened.gameId,
107
+ roomId: opened.roomId,
108
+ controllerJoinUrl: opened.controllerJoinUrl,
109
+ requestHost: async (hostRequest, timeoutMs, signal) => {
110
+ signal?.throwIfAborted();
111
+ const answered = await request(
112
+ { kind: "agent", id: randomUUID(), request: hostRequest },
113
+ "agent",
114
+ timeoutMs,
115
+ );
116
+ return answered.response;
117
+ },
118
+ clock: {
119
+ now: () => nowMs,
120
+ wait: async (ms, signal) => {
121
+ let remaining = ms;
122
+ while (remaining > 0) {
123
+ signal?.throwIfAborted();
124
+ const step = Math.min(remaining, HEADLESS_ROOM_MAX_ADVANCE_MS);
125
+ nowMs = (
126
+ await request(
127
+ { kind: "advance", id: randomUUID(), ms: step },
128
+ "advanced",
129
+ )
130
+ ).nowMs;
131
+ remaining -= step;
132
+ }
133
+ },
134
+ },
135
+ saveInputLog: opened.recordsInputLog
136
+ ? async (logPath) => {
137
+ const { sha256, ticks, stepMs, entries, full } = await request(
138
+ { kind: "saveInputLog", id: randomUUID(), path: logPath },
139
+ "savedInputLog",
140
+ );
141
+ return { sha256, ticks, stepMs, entries, full };
142
+ }
143
+ : null,
144
+ stop: channel.stop,
145
+ };
146
+ } catch (error) {
147
+ return closeAfterProcessFailure(channel.stop, error);
148
+ } finally {
149
+ channel.started();
150
+ }
151
+ }
152
+
153
+ /**
154
+ * Plays a recorded input log on a fresh copy of the game in its own process,
155
+ * with no server or page, and keeps the replayed host for questions such as
156
+ * a final observation.
157
+ */
158
+ export async function replayInputLog({
159
+ rootDir,
160
+ toolingRootDir,
161
+ configPath,
162
+ inputLogPath,
163
+ logPath,
164
+ }: {
165
+ rootDir: string;
166
+ toolingRootDir?: string;
167
+ configPath: string;
168
+ inputLogPath: string;
169
+ logPath: string;
170
+ }): Promise<{
171
+ gameId: string | null;
172
+ roomId: string;
173
+ ticks: number;
174
+ requestHost: HostRequester;
175
+ stop: () => Promise<void>;
176
+ }> {
177
+ const channel = await startHelperChannel({
178
+ name: "replay",
179
+ helper: "run-headless-room.ts",
180
+ rootDir,
181
+ toolingRootDir,
182
+ logPath,
183
+ maxBytes: HEADLESS_ROOM_IPC_MAX_BYTES,
184
+ requestSchema: headlessRoomRequestSchema,
185
+ responseSchema: headlessRoomResponseSchema,
186
+ });
187
+ try {
188
+ const replayed = await channel.request(
189
+ {
190
+ kind: "replay",
191
+ id: randomUUID(),
192
+ configPath,
193
+ logPath: inputLogPath,
194
+ },
195
+ REPLAY_TIMEOUT_MS,
196
+ );
197
+ if (replayed.kind === "error") throw new Error(replayed.message);
198
+ if (replayed.kind !== "replayed")
199
+ throw new Error("room_protocol: Expected replayed.");
200
+ return {
201
+ gameId: replayed.gameId,
202
+ roomId: replayed.roomId,
203
+ ticks: replayed.ticks,
204
+ requestHost: async (hostRequest, timeoutMs, signal) => {
205
+ signal?.throwIfAborted();
206
+ const answered = await channel.request(
207
+ { kind: "agent", id: randomUUID(), request: hostRequest },
208
+ timeoutMs,
209
+ );
210
+ if (answered.kind === "error") throw new Error(answered.message);
211
+ if (answered.kind !== "agent")
212
+ throw new Error("room_protocol: Expected agent.");
213
+ return answered.response;
214
+ },
215
+ stop: channel.stop,
216
+ };
217
+ } catch (error) {
218
+ return closeAfterProcessFailure(channel.stop, error);
219
+ } finally {
220
+ channel.started();
221
+ }
222
+ }