@air-jam/devtools 0.9.3 → 1.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -0
- package/dist/{chunk-VKMJO6VN.js → chunk-2O67AXCU.js} +150 -40
- package/dist/chunk-2O67AXCU.js.map +1 -0
- package/dist/chunk-AO3ZDXF6.js +142 -0
- package/dist/chunk-AO3ZDXF6.js.map +1 -0
- package/dist/chunk-ART5TEYT.js +472 -0
- package/dist/chunk-ART5TEYT.js.map +1 -0
- package/dist/chunk-ASC2CK2R.js +77 -0
- package/dist/chunk-ASC2CK2R.js.map +1 -0
- package/dist/chunk-E3UZZGAV.js +50 -0
- package/dist/chunk-E3UZZGAV.js.map +1 -0
- package/dist/chunk-EJTE7UKX.js +64 -0
- package/dist/chunk-EJTE7UKX.js.map +1 -0
- package/dist/chunk-ESFKNN75.js +110 -0
- package/dist/chunk-ESFKNN75.js.map +1 -0
- package/dist/chunk-EU7A6PXW.js +1339 -0
- package/dist/chunk-EU7A6PXW.js.map +1 -0
- package/dist/chunk-FN7E6EA7.js +549 -0
- package/dist/chunk-FN7E6EA7.js.map +1 -0
- package/dist/chunk-GDFAWHGA.js +190 -0
- package/dist/chunk-GDFAWHGA.js.map +1 -0
- package/dist/chunk-HZUGBH4Y.js +347 -0
- package/dist/chunk-HZUGBH4Y.js.map +1 -0
- package/dist/chunk-ITKAOEGX.js +93 -0
- package/dist/chunk-ITKAOEGX.js.map +1 -0
- package/dist/chunk-JBCUTWRI.js +897 -0
- package/dist/chunk-JBCUTWRI.js.map +1 -0
- package/dist/chunk-JSI5S4WP.js +1174 -0
- package/dist/chunk-JSI5S4WP.js.map +1 -0
- package/dist/chunk-L4D675BG.js +97 -0
- package/dist/chunk-L4D675BG.js.map +1 -0
- package/dist/{chunk-GUEZP773.js → chunk-LB3Y64P5.js} +206 -60
- package/dist/chunk-LB3Y64P5.js.map +1 -0
- package/dist/chunk-M6CJ7GQC.js +133 -0
- package/dist/chunk-M6CJ7GQC.js.map +1 -0
- package/dist/{chunk-CKFT2ZJE.js → chunk-MEIMOSZC.js} +53 -105
- package/dist/chunk-MEIMOSZC.js.map +1 -0
- package/dist/chunk-OM6SCJ7H.js +18 -0
- package/dist/chunk-OM6SCJ7H.js.map +1 -0
- package/dist/chunk-PKD4WVX5.js +63 -0
- package/dist/chunk-PKD4WVX5.js.map +1 -0
- package/dist/chunk-PMBLXGFM.js +3384 -0
- package/dist/chunk-PMBLXGFM.js.map +1 -0
- package/dist/chunk-PMNE5GIN.js +279 -0
- package/dist/chunk-PMNE5GIN.js.map +1 -0
- package/dist/chunk-QAWI64VR.js +148 -0
- package/dist/chunk-QAWI64VR.js.map +1 -0
- package/dist/chunk-QGADSPHZ.js +449 -0
- package/dist/chunk-QGADSPHZ.js.map +1 -0
- package/dist/chunk-SPYN66UV.js +338 -0
- package/dist/chunk-SPYN66UV.js.map +1 -0
- package/dist/context.d.ts +9 -3
- package/dist/context.js +2 -1
- package/dist/controller.d.ts +33 -7
- package/dist/controller.js +18 -8
- package/dist/dependencies.d.ts +44 -0
- package/dist/dependencies.js +10 -0
- package/dist/dev.d.ts +9 -3
- package/dist/dev.js +3 -4
- package/dist/game-builds.d.ts +200 -0
- package/dist/game-builds.js +16 -0
- package/dist/game-builds.js.map +1 -0
- package/dist/game-run-watch-CEd_SpAT.d.ts +84 -0
- package/dist/game-runs.d.ts +1452 -0
- package/dist/game-runs.js +76 -0
- package/dist/game-runs.js.map +1 -0
- package/dist/game-session-broker-CUvORfMd.d.ts +439 -0
- package/dist/game-session-broker.d.ts +4 -57
- package/dist/game-session-broker.js +33 -228
- package/dist/game-session-broker.js.map +1 -1
- package/dist/game-session.d.ts +3931 -10
- package/dist/game-session.js +186 -15
- package/dist/game-session.js.map +1 -1
- package/dist/game-settings.d.ts +16 -0
- package/dist/game-settings.js +237 -0
- package/dist/game-settings.js.map +1 -0
- package/dist/games.d.ts +11 -4
- package/dist/games.js +4 -2
- package/dist/harness/visual.d.ts +34 -151
- package/dist/harness/visual.js +6 -1
- package/dist/logs.d.ts +8 -2
- package/dist/logs.js +3 -4
- package/dist/logs.js.map +1 -1
- package/dist/managed-process-scope-BicYi_t9.d.ts +3 -0
- package/dist/mcp-config.js +2 -1
- package/dist/mcp-config.js.map +1 -1
- package/dist/platform-auth.d.ts +8 -111
- package/dist/platform-auth.js +9 -1
- package/dist/platform-game-analytics.d.ts +51 -0
- package/dist/platform-game-analytics.js +49 -0
- package/dist/platform-game-analytics.js.map +1 -0
- package/dist/platform-game-app-id.d.ts +46 -0
- package/dist/platform-game-app-id.js +93 -0
- package/dist/platform-game-app-id.js.map +1 -0
- package/dist/platform-game-media.d.ts +40 -2
- package/dist/platform-game-media.js +1 -1
- package/dist/platform-games.d.ts +24 -2
- package/dist/platform-games.js +16 -84
- package/dist/platform-games.js.map +1 -1
- package/dist/quality.d.ts +9 -3
- package/dist/quality.js +3 -4
- package/dist/quality.js.map +1 -1
- package/dist/release.d.ts +226 -16
- package/dist/release.js +18 -1331
- package/dist/release.js.map +1 -1
- package/dist/rooms-check.d.ts +90 -0
- package/dist/rooms-check.js +717 -0
- package/dist/rooms-check.js.map +1 -0
- package/dist/source-tree-contract.d.ts +16 -0
- package/dist/source-tree-contract.js +13 -0
- package/dist/source-tree-contract.js.map +1 -0
- package/dist/testing.d.ts +464 -0
- package/dist/testing.js +27 -0
- package/dist/testing.js.map +1 -0
- package/dist/tooling/describe-game.js +54 -0
- package/dist/tooling/describe-game.js.map +1 -0
- package/dist/tooling/game-session-broker.js +28 -0
- package/dist/tooling/game-session-broker.js.map +1 -0
- package/dist/tooling/hold-runtime-host.js +770 -68
- package/dist/tooling/hold-runtime-host.js.map +1 -1
- package/dist/tooling/list-visual-scenarios.js +18 -55
- package/dist/tooling/list-visual-scenarios.js.map +1 -1
- package/dist/tooling/process-scope-bootstrap.mjs +24 -0
- package/dist/tooling/process-scope-guard.d.ts +2 -0
- package/dist/tooling/process-scope-guard.js +388 -0
- package/dist/tooling/process-scope-guard.js.map +1 -0
- package/dist/tooling/process-scope-windows.ps1 +148 -0
- package/dist/tooling/rooms-check-device.d.ts +2 -0
- package/dist/tooling/rooms-check-device.js +498 -0
- package/dist/tooling/rooms-check-device.js.map +1 -0
- package/dist/tooling/run-headless-room.d.ts +2 -0
- package/dist/tooling/run-headless-room.js +288 -0
- package/dist/tooling/run-headless-room.js.map +1 -0
- package/dist/tooling/run-test-profile.d.ts +2 -0
- package/dist/tooling/run-test-profile.js +181 -0
- package/dist/tooling/run-test-profile.js.map +1 -0
- package/dist/tooling/run-visual-capture.js +70 -34
- package/dist/tooling/run-visual-capture.js.map +1 -1
- package/dist/tooling/seal-game-build.d.ts +2 -0
- package/dist/tooling/seal-game-build.js +120 -0
- package/dist/tooling/seal-game-build.js.map +1 -0
- package/dist/{types-C6NrHt88.d.ts → types-CdYrgrG_.d.ts} +337 -76
- package/dist/types-DyRD-ym1.d.ts +141 -0
- package/dist/visual.d.ts +9 -3
- package/dist/visual.js +24 -68
- package/dist/visual.js.map +1 -1
- package/package.json +51 -14
- package/src/bounded-response.ts +28 -0
- package/src/built-game-runtime.ts +152 -0
- package/src/context.ts +2 -13
- package/src/controller-protocol.ts +22 -0
- package/src/controller.ts +747 -597
- package/src/current-room-host.ts +166 -0
- package/src/decision-provider.ts +102 -0
- package/src/dependencies.ts +176 -0
- package/src/dependency-install-contract.ts +12 -0
- package/src/dev.ts +46 -50
- package/src/game-action-observation.ts +11 -1
- package/src/game-build-protocol.ts +72 -0
- package/src/game-build.ts +483 -0
- package/src/game-run-owner.ts +2358 -0
- package/src/game-run-protocol.ts +448 -0
- package/src/game-run-record.ts +92 -0
- package/src/game-run-replay.ts +95 -0
- package/src/game-run-watch.ts +155 -0
- package/src/game-session-broker.ts +689 -197
- package/src/game-session-operations.ts +61 -0
- package/src/game-session-protocol.ts +180 -0
- package/src/game-session-runtime.ts +861 -0
- package/src/game-session.ts +164 -417
- package/src/game-settings.ts +295 -0
- package/src/games.ts +88 -92
- package/src/harness/visual/browser.ts +100 -0
- package/src/harness/visual/controller-observation.ts +181 -0
- package/src/harness/visual/runner.ts +24 -21
- package/src/harness/visual/runtime-controller-observations.ts +151 -0
- package/src/harness/visual/scenario-contract.ts +1 -2
- package/src/harness/visual/scenario-helpers.ts +5 -1
- package/src/harness/visual/screencast.ts +155 -0
- package/src/harness/visual/session.ts +74 -69
- package/src/harness/visual/types.ts +8 -5
- package/src/headless-room-protocol.ts +112 -0
- package/src/headless-room.ts +222 -0
- package/src/helper-channel.ts +229 -0
- package/src/helper-scripts.ts +25 -5
- package/src/installed-dependencies.ts +74 -0
- package/src/managed-process-scope.ts +481 -0
- package/src/node-process-environment.ts +10 -0
- package/src/platform-auth.ts +194 -55
- package/src/platform-game-analytics.ts +50 -0
- package/src/platform-game-app-id.ts +99 -0
- package/src/platform-games.ts +13 -111
- package/src/policy-artifact-contract.ts +52 -0
- package/src/policy-artifacts.ts +134 -0
- package/src/process-scope-admission.ts +50 -0
- package/src/process-scope-protocol.ts +66 -0
- package/src/process-scope.ts +327 -0
- package/src/release.ts +28 -42
- package/src/rooms-check-fleet.ts +194 -0
- package/src/rooms-check-link.ts +138 -0
- package/src/rooms-check-protocol.ts +244 -0
- package/src/rooms-check.ts +797 -0
- package/src/runtime-owner-protocol.ts +106 -18
- package/src/source-tree-contract.ts +70 -0
- package/src/source-tree.ts +84 -0
- package/src/test-profile-process.ts +153 -0
- package/src/test-profile-protocol.ts +116 -0
- package/src/testing.ts +430 -0
- package/src/tooling/declaration-hook.ts +52 -0
- package/src/tooling/describe-game.ts +49 -0
- package/src/tooling/game-session-broker.ts +7 -0
- package/src/tooling/hold-runtime-host.ts +254 -42
- package/src/tooling/list-visual-scenarios.ts +19 -62
- package/src/tooling/load-game.ts +79 -0
- package/src/tooling/process-scope-bootstrap.mjs +24 -0
- package/src/tooling/process-scope-guard.ts +213 -0
- package/src/tooling/process-scope-windows.ps1 +148 -0
- package/src/tooling/rooms-check-device.ts +493 -0
- package/src/tooling/run-headless-room.ts +329 -0
- package/src/tooling/run-test-profile.ts +190 -0
- package/src/tooling/run-visual-capture.ts +37 -23
- package/src/tooling/runtime-owner-actions.ts +23 -0
- package/src/tooling/seal-game-build.ts +118 -0
- package/src/tooling/visual-pack.ts +10 -45
- package/src/types.ts +54 -77
- package/src/visual.ts +14 -22
- package/src/windows-process-scopes.ts +189 -0
- package/dist/agent.d.ts +0 -15
- package/dist/agent.js +0 -19
- package/dist/chunk-5YAARMW5.js +0 -36
- package/dist/chunk-5YAARMW5.js.map +0 -1
- package/dist/chunk-6WQODT37.js +0 -1019
- package/dist/chunk-6WQODT37.js.map +0 -1
- package/dist/chunk-CKFT2ZJE.js.map +0 -1
- package/dist/chunk-ER3Q2C4G.js +0 -358
- package/dist/chunk-ER3Q2C4G.js.map +0 -1
- package/dist/chunk-GUEZP773.js.map +0 -1
- package/dist/chunk-HIDNI56E.js +0 -33
- package/dist/chunk-HIDNI56E.js.map +0 -1
- package/dist/chunk-QKXS5D35.js +0 -43
- package/dist/chunk-QKXS5D35.js.map +0 -1
- package/dist/chunk-S4LSCEVE.js +0 -261
- package/dist/chunk-S4LSCEVE.js.map +0 -1
- package/dist/chunk-VKMJO6VN.js.map +0 -1
- package/dist/chunk-WFUR3MXY.js +0 -67
- package/dist/chunk-WFUR3MXY.js.map +0 -1
- package/dist/chunk-XEMR7KUE.js +0 -361
- package/dist/chunk-XEMR7KUE.js.map +0 -1
- package/dist/chunk-ZLPD7FY5.js +0 -191
- package/dist/chunk-ZLPD7FY5.js.map +0 -1
- package/dist/tooling/agent-contract.js +0 -193
- package/dist/tooling/agent-contract.js.map +0 -1
- package/dist/tooling/inspect-airjam-agent.js +0 -37
- package/dist/tooling/inspect-airjam-agent.js.map +0 -1
- package/src/agent.ts +0 -380
- package/src/tooling/agent-contract.ts +0 -232
- package/src/tooling/agent-declaration.ts +0 -36
- package/src/tooling/airjam-agent-inspection.ts +0 -45
- package/src/tooling/airjam-agent.ts +0 -118
- package/src/tooling/inspect-airjam-agent.ts +0 -20
- /package/dist/{agent.js.map → dependencies.js.map} +0 -0
- /package/dist/tooling/{agent-contract.d.ts → describe-game.d.ts} +0 -0
- /package/dist/tooling/{inspect-airjam-agent.d.ts → game-session-broker.d.ts} +0 -0
|
@@ -1,56 +1,585 @@
|
|
|
1
|
+
import {
|
|
2
|
+
evaluateOwnedGameContract,
|
|
3
|
+
invokeOwnedHostAction
|
|
4
|
+
} from "../chunk-E3UZZGAV.js";
|
|
1
5
|
import {
|
|
2
6
|
DEFAULT_CONTROLLER_VIEWPORT,
|
|
3
7
|
DEFAULT_HOST_VIEWPORT,
|
|
4
|
-
|
|
5
|
-
|
|
8
|
+
bindHarnessControllerUrl,
|
|
9
|
+
installHarnessRuntimeTopology,
|
|
10
|
+
launchScopedHarnessBrowser,
|
|
6
11
|
openVisualHarnessHostSession
|
|
7
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-LB3Y64P5.js";
|
|
13
|
+
import {
|
|
14
|
+
distributionFiles
|
|
15
|
+
} from "../chunk-FN7E6EA7.js";
|
|
16
|
+
import "../chunk-HZUGBH4Y.js";
|
|
17
|
+
import "../chunk-PMNE5GIN.js";
|
|
18
|
+
import {
|
|
19
|
+
gameBuildManifestSchema
|
|
20
|
+
} from "../chunk-ASC2CK2R.js";
|
|
21
|
+
import "../chunk-OM6SCJ7H.js";
|
|
22
|
+
import "../chunk-EJTE7UKX.js";
|
|
8
23
|
import {
|
|
9
24
|
AIR_JAM_RUNTIME_OWNER_ACTION_RESULT,
|
|
25
|
+
AIR_JAM_RUNTIME_OWNER_CAPTURE_FRAME,
|
|
10
26
|
AIR_JAM_RUNTIME_OWNER_CAPTURE_RESULT,
|
|
11
27
|
isRuntimeOwnerActionRequest,
|
|
12
28
|
isRuntimeOwnerCaptureRequest,
|
|
13
|
-
resolveProjectRelativeRuntimeCaptureDir
|
|
14
|
-
|
|
29
|
+
resolveProjectRelativeRuntimeCaptureDir,
|
|
30
|
+
runtimeOwnerAgentRequestSchema,
|
|
31
|
+
runtimeOwnerCapturePortSchema,
|
|
32
|
+
runtimeOwnerWatchRequestSchema,
|
|
33
|
+
runtimeOwnerWatchStopSchema
|
|
34
|
+
} from "../chunk-M6CJ7GQC.js";
|
|
35
|
+
import "../chunk-QGADSPHZ.js";
|
|
36
|
+
import {
|
|
37
|
+
GAME_WATCH_HEARTBEAT_MS,
|
|
38
|
+
MAXIMUM_GAME_WATCH_FRAME_BASE64
|
|
39
|
+
} from "../chunk-AO3ZDXF6.js";
|
|
40
|
+
import "../chunk-SPYN66UV.js";
|
|
41
|
+
import "../chunk-ART5TEYT.js";
|
|
42
|
+
import "../chunk-PKD4WVX5.js";
|
|
15
43
|
|
|
16
44
|
// src/tooling/hold-runtime-host.ts
|
|
45
|
+
import { airJamSettingsValuesSchema } from "@air-jam/sdk/core";
|
|
17
46
|
import {
|
|
18
|
-
AIR_JAM_RUNTIME_INSPECTION_KEY,
|
|
47
|
+
AIR_JAM_RUNTIME_INSPECTION_KEY as AIR_JAM_RUNTIME_INSPECTION_KEY2,
|
|
19
48
|
readRuntimeInspectionContract
|
|
20
49
|
} from "@air-jam/sdk/runtime-inspection";
|
|
21
50
|
import { mkdir } from "fs/promises";
|
|
51
|
+
import path2 from "path";
|
|
52
|
+
|
|
53
|
+
// src/built-game-runtime.ts
|
|
54
|
+
import {
|
|
55
|
+
resolveRuntimeTopology,
|
|
56
|
+
runtimeTopologyToQueryParams
|
|
57
|
+
} from "@air-jam/sdk/runtime-topology";
|
|
58
|
+
import { loadServerEnv } from "@air-jam/server";
|
|
59
|
+
import { createRoomServer } from "@air-jam/server/room-server";
|
|
60
|
+
import { createHash } from "crypto";
|
|
61
|
+
import { readFile, realpath } from "fs/promises";
|
|
22
62
|
import path from "path";
|
|
63
|
+
var CONTENT_TYPES = {
|
|
64
|
+
".html": "text/html; charset=utf-8",
|
|
65
|
+
".js": "text/javascript; charset=utf-8",
|
|
66
|
+
".mjs": "text/javascript; charset=utf-8",
|
|
67
|
+
".css": "text/css; charset=utf-8",
|
|
68
|
+
".json": "application/json; charset=utf-8",
|
|
69
|
+
".map": "application/json; charset=utf-8",
|
|
70
|
+
".txt": "text/plain; charset=utf-8",
|
|
71
|
+
".svg": "image/svg+xml",
|
|
72
|
+
".png": "image/png",
|
|
73
|
+
".jpg": "image/jpeg",
|
|
74
|
+
".jpeg": "image/jpeg",
|
|
75
|
+
".gif": "image/gif",
|
|
76
|
+
".webp": "image/webp",
|
|
77
|
+
".avif": "image/avif",
|
|
78
|
+
".ico": "image/x-icon",
|
|
79
|
+
".woff": "font/woff",
|
|
80
|
+
".woff2": "font/woff2",
|
|
81
|
+
".ttf": "font/ttf",
|
|
82
|
+
".otf": "font/otf",
|
|
83
|
+
".mp3": "audio/mpeg",
|
|
84
|
+
".ogg": "audio/ogg",
|
|
85
|
+
".wav": "audio/wav",
|
|
86
|
+
".m4a": "audio/mp4",
|
|
87
|
+
".mp4": "video/mp4",
|
|
88
|
+
".webm": "video/webm",
|
|
89
|
+
".glb": "model/gltf-binary",
|
|
90
|
+
".gltf": "model/gltf+json",
|
|
91
|
+
".wasm": "application/wasm"
|
|
92
|
+
};
|
|
93
|
+
var contentTypeOf = (name) => CONTENT_TYPES[path.extname(name).toLowerCase()] ?? "application/octet-stream";
|
|
94
|
+
async function startBuiltGameRuntime(manifestPath) {
|
|
95
|
+
const manifest = gameBuildManifestSchema.parse(
|
|
96
|
+
JSON.parse(await readFile(manifestPath, "utf8"))
|
|
97
|
+
);
|
|
98
|
+
const root = await realpath(
|
|
99
|
+
path.join(path.dirname(manifestPath), "source/dist")
|
|
100
|
+
);
|
|
101
|
+
const files = await distributionFiles(root);
|
|
102
|
+
if (createHash("sha256").update(JSON.stringify(files)).digest("hex") !== manifest.distHash)
|
|
103
|
+
throw new Error(
|
|
104
|
+
"build_integrity_changed: The distribution changed before host startup."
|
|
105
|
+
);
|
|
106
|
+
const allowed = new Set(files.map((file) => file.path));
|
|
107
|
+
const serveFile = (request, response) => {
|
|
108
|
+
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
109
|
+
response.writeHead(405).end();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
let name;
|
|
113
|
+
try {
|
|
114
|
+
name = decodeURIComponent(
|
|
115
|
+
new URL(request.url ?? "/", "http://localhost").pathname
|
|
116
|
+
).slice(1);
|
|
117
|
+
} catch {
|
|
118
|
+
response.writeHead(400).end();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (name === "" || !allowed.has(name) && request.headers.accept?.includes("text/html") && !name.split("/").some((segment) => segment.includes(".")))
|
|
122
|
+
name = "index.html";
|
|
123
|
+
if (!allowed.has(name)) {
|
|
124
|
+
response.writeHead(404).end();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
readFile(path.join(root, name)).then(
|
|
128
|
+
(body) => {
|
|
129
|
+
response.writeHead(200, {
|
|
130
|
+
"content-type": contentTypeOf(name),
|
|
131
|
+
"content-length": body.byteLength,
|
|
132
|
+
"x-content-type-options": "nosniff",
|
|
133
|
+
"cache-control": "no-store"
|
|
134
|
+
});
|
|
135
|
+
response.end(request.method === "HEAD" ? void 0 : body);
|
|
136
|
+
},
|
|
137
|
+
() => {
|
|
138
|
+
if (!response.headersSent) response.writeHead(404).end();
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
};
|
|
142
|
+
const runtime = createRoomServer({
|
|
143
|
+
host: "127.0.0.1",
|
|
144
|
+
port: 0,
|
|
145
|
+
envConfig: loadServerEnv({
|
|
146
|
+
NODE_ENV: "test",
|
|
147
|
+
AIR_JAM_AUTH_MODE: "disabled"
|
|
148
|
+
}),
|
|
149
|
+
otherRequests: serveFile
|
|
150
|
+
});
|
|
151
|
+
try {
|
|
152
|
+
const origin = `http://127.0.0.1:${await runtime.start()}`;
|
|
153
|
+
const topology = (surfaceRole) => resolveRuntimeTopology({
|
|
154
|
+
runtimeMode: "self-hosted-production",
|
|
155
|
+
surfaceRole,
|
|
156
|
+
appOrigin: origin,
|
|
157
|
+
backendOrigin: origin,
|
|
158
|
+
socketOrigin: origin,
|
|
159
|
+
publicHost: origin,
|
|
160
|
+
embedded: false,
|
|
161
|
+
proxyStrategy: "none",
|
|
162
|
+
secureTransport: false
|
|
163
|
+
});
|
|
164
|
+
const surfaceUrl = (role) => {
|
|
165
|
+
const url = new URL(role === "host" ? "/" : "/controller", origin);
|
|
166
|
+
for (const [key, value] of Object.entries(
|
|
167
|
+
runtimeTopologyToQueryParams(topology(role))
|
|
168
|
+
))
|
|
169
|
+
url.searchParams.set(key, value);
|
|
170
|
+
return url.toString();
|
|
171
|
+
};
|
|
172
|
+
return {
|
|
173
|
+
topology: topology("host"),
|
|
174
|
+
urls: {
|
|
175
|
+
appOrigin: origin,
|
|
176
|
+
hostUrl: surfaceUrl("host"),
|
|
177
|
+
controllerBaseUrl: surfaceUrl("controller"),
|
|
178
|
+
publicHost: origin,
|
|
179
|
+
localBuildUrl: null,
|
|
180
|
+
browserBuildUrl: null
|
|
181
|
+
},
|
|
182
|
+
close: () => runtime.stop()
|
|
183
|
+
};
|
|
184
|
+
} catch (error) {
|
|
185
|
+
await runtime.stop();
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
23
189
|
|
|
24
|
-
// src/
|
|
190
|
+
// src/harness/visual/controller-observation.ts
|
|
191
|
+
import { AIR_JAM_RUNTIME_INSPECTION_KEY } from "@air-jam/sdk/runtime-inspection";
|
|
25
192
|
import {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
193
|
+
parseRuntimeTopologyFromSearchParams,
|
|
194
|
+
resolveRuntimeTopology as resolveRuntimeTopology2,
|
|
195
|
+
runtimeTopologyToQueryParams as runtimeTopologyToQueryParams2
|
|
196
|
+
} from "@air-jam/sdk/runtime-topology";
|
|
197
|
+
async function openControllerObservation({
|
|
198
|
+
browser: browser2,
|
|
199
|
+
controllerJoinUrl,
|
|
200
|
+
harnessSessionId,
|
|
201
|
+
roomId,
|
|
202
|
+
onPortMessage,
|
|
203
|
+
signal
|
|
204
|
+
}) {
|
|
205
|
+
const context = await browser2.newContext({
|
|
206
|
+
viewport: DEFAULT_CONTROLLER_VIEWPORT
|
|
207
|
+
});
|
|
208
|
+
let closing;
|
|
209
|
+
const close = () => {
|
|
210
|
+
signal?.removeEventListener("abort", aborted);
|
|
211
|
+
return closing ??= context.close();
|
|
212
|
+
};
|
|
213
|
+
const aborted = () => {
|
|
214
|
+
void close().catch(() => void 0);
|
|
215
|
+
};
|
|
216
|
+
signal?.addEventListener("abort", aborted, { once: true });
|
|
29
217
|
try {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
218
|
+
signal?.throwIfAborted();
|
|
219
|
+
const controllerUrl = new URL(controllerJoinUrl);
|
|
220
|
+
const parentUrl = new URL(
|
|
221
|
+
`/__airjam/controller-observation/${harnessSessionId}`,
|
|
222
|
+
"http://airjam-controller-observation.localhost"
|
|
223
|
+
);
|
|
224
|
+
await context.grantPermissions(["local-network-access"], {
|
|
225
|
+
origin: parentUrl.origin
|
|
226
|
+
});
|
|
227
|
+
const topology = parseRuntimeTopologyFromSearchParams(
|
|
228
|
+
controllerUrl.searchParams
|
|
229
|
+
);
|
|
230
|
+
if (!topology)
|
|
231
|
+
throw new Error(
|
|
232
|
+
"Controller observation requires complete runtime topology."
|
|
233
|
+
);
|
|
234
|
+
const observationTopology = resolveRuntimeTopology2({
|
|
235
|
+
...topology,
|
|
236
|
+
embedded: true,
|
|
237
|
+
embedParentOrigin: parentUrl.origin
|
|
238
|
+
});
|
|
239
|
+
await installHarnessRuntimeTopology(context, observationTopology);
|
|
240
|
+
for (const [name, value] of Object.entries(
|
|
241
|
+
runtimeTopologyToQueryParams2(observationTopology)
|
|
242
|
+
))
|
|
243
|
+
controllerUrl.searchParams.set(name, value);
|
|
244
|
+
controllerUrl.searchParams.set("aj_room", roomId);
|
|
245
|
+
controllerUrl.searchParams.set("aj_harness_session", harnessSessionId);
|
|
246
|
+
const page = await context.newPage();
|
|
247
|
+
await page.route(
|
|
248
|
+
parentUrl.href,
|
|
249
|
+
(route) => route.fulfill({
|
|
250
|
+
contentType: "text/html",
|
|
251
|
+
body: "<!doctype html><html><head><style>html,body,iframe{width:100%;height:100%;margin:0;border:0;display:block;overflow:hidden}</style></head><body></body></html>"
|
|
252
|
+
})
|
|
253
|
+
);
|
|
254
|
+
await page.exposeBinding(
|
|
255
|
+
"airJamObservationMessage",
|
|
256
|
+
(_, message) => onPortMessage(message)
|
|
257
|
+
);
|
|
258
|
+
await page.goto(parentUrl.href, { waitUntil: "domcontentloaded" });
|
|
259
|
+
await page.evaluate(
|
|
260
|
+
({ controllerUrl: controllerUrl2, harnessSessionId: harnessSessionId2 }) => {
|
|
261
|
+
const frame = document.createElement("iframe");
|
|
262
|
+
let port = null;
|
|
263
|
+
const pending = [];
|
|
264
|
+
Object.assign(window, {
|
|
265
|
+
airJamObservationDeliver: (message) => {
|
|
266
|
+
if (port) port.postMessage(message);
|
|
267
|
+
else pending.push(message);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
window.addEventListener("message", (event) => {
|
|
271
|
+
if (event.source !== frame.contentWindow || event.origin !== new URL(controllerUrl2).origin)
|
|
272
|
+
return;
|
|
273
|
+
const request = event.data;
|
|
274
|
+
if (request.type !== "AIRJAM_ROOM_BRIDGE_REQUEST" || !event.ports[0] || request.payload?.role !== "controller" || request.payload.harnessSessionId !== harnessSessionId2)
|
|
275
|
+
return;
|
|
276
|
+
port?.close();
|
|
277
|
+
port = event.ports[0];
|
|
278
|
+
port.onmessage = (message) => {
|
|
279
|
+
const binding = Reflect.get(window, "airJamObservationMessage");
|
|
280
|
+
void binding(message.data);
|
|
281
|
+
};
|
|
282
|
+
port.start();
|
|
283
|
+
for (const message of pending.splice(0)) port.postMessage(message);
|
|
284
|
+
});
|
|
285
|
+
frame.src = controllerUrl2;
|
|
286
|
+
frame.title = "Acting controller observation";
|
|
287
|
+
document.body.append(frame);
|
|
40
288
|
},
|
|
41
|
-
{
|
|
289
|
+
{ controllerUrl: controllerUrl.href, harnessSessionId }
|
|
42
290
|
);
|
|
43
|
-
|
|
291
|
+
const frameElement = await page.locator("iframe").elementHandle();
|
|
292
|
+
if (!frameElement)
|
|
293
|
+
throw new Error("Controller observation frame is missing.");
|
|
294
|
+
const controllerFrame = await frameElement.contentFrame();
|
|
295
|
+
if (!controllerFrame)
|
|
296
|
+
throw new Error("Controller observation document is unavailable.");
|
|
297
|
+
const ready = (async () => {
|
|
298
|
+
await controllerFrame.waitForFunction(
|
|
299
|
+
({ key, roomId: roomId2 }) => {
|
|
300
|
+
const inspection = Reflect.get(window, key);
|
|
301
|
+
return inspection?.roomId === roomId2 && inspection.connectionStatus === "connected";
|
|
302
|
+
},
|
|
303
|
+
{ key: AIR_JAM_RUNTIME_INSPECTION_KEY, roomId }
|
|
304
|
+
);
|
|
305
|
+
await controllerFrame.evaluate(
|
|
306
|
+
() => new Promise(
|
|
307
|
+
(resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve()))
|
|
308
|
+
)
|
|
309
|
+
);
|
|
310
|
+
signal?.throwIfAborted();
|
|
311
|
+
})();
|
|
44
312
|
return {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
313
|
+
page,
|
|
314
|
+
ready,
|
|
315
|
+
async deliver(message) {
|
|
316
|
+
await page.evaluate((message2) => {
|
|
317
|
+
const deliver = Reflect.get(window, "airJamObservationDeliver");
|
|
318
|
+
deliver(message2);
|
|
319
|
+
}, message);
|
|
320
|
+
},
|
|
321
|
+
close
|
|
50
322
|
};
|
|
323
|
+
} catch (error) {
|
|
324
|
+
await close();
|
|
325
|
+
throw error;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// src/harness/visual/runtime-controller-observations.ts
|
|
330
|
+
var PENDING_DELIVERIES = 256;
|
|
331
|
+
var RuntimeControllerObservations = class {
|
|
332
|
+
constructor(options) {
|
|
333
|
+
this.options = options;
|
|
334
|
+
}
|
|
335
|
+
entries = /* @__PURE__ */ new Map();
|
|
336
|
+
async open(requestId, context, onError) {
|
|
337
|
+
if (this.entries.has(requestId))
|
|
338
|
+
throw new Error("Controller observation already exists.");
|
|
339
|
+
const entry = {
|
|
340
|
+
queued: 0,
|
|
341
|
+
abort: new AbortController(),
|
|
342
|
+
pending: [],
|
|
343
|
+
delivery: Promise.resolve(),
|
|
344
|
+
onError
|
|
345
|
+
};
|
|
346
|
+
this.entries.set(requestId, entry);
|
|
347
|
+
entry.opening = (async () => {
|
|
348
|
+
const inspection = await this.options.readInspection();
|
|
349
|
+
if (inspection?.role !== "host" || inspection.roomId !== context.roomId)
|
|
350
|
+
throw new Error("Observation belongs to another host room.");
|
|
351
|
+
const observation = await openControllerObservation({
|
|
352
|
+
browser: this.options.browser,
|
|
353
|
+
signal: entry.abort.signal,
|
|
354
|
+
controllerJoinUrl: inspection.localControllerUrl,
|
|
355
|
+
harnessSessionId: context.harnessSessionId,
|
|
356
|
+
roomId: context.roomId,
|
|
357
|
+
onPortMessage: (message) => this.options.send({
|
|
358
|
+
type: AIR_JAM_RUNTIME_OWNER_CAPTURE_FRAME,
|
|
359
|
+
requestId,
|
|
360
|
+
message
|
|
361
|
+
})
|
|
362
|
+
});
|
|
363
|
+
entry.observation = observation;
|
|
364
|
+
for (const event of entry.pending.splice(0)) this.deliver(event);
|
|
365
|
+
await observation.ready;
|
|
366
|
+
await entry.delivery;
|
|
367
|
+
if (entry.error) throw entry.error;
|
|
368
|
+
return observation;
|
|
369
|
+
})();
|
|
370
|
+
try {
|
|
371
|
+
return await entry.opening;
|
|
372
|
+
} catch (error) {
|
|
373
|
+
try {
|
|
374
|
+
await this.close(requestId);
|
|
375
|
+
} catch (cleanupError) {
|
|
376
|
+
throw new AggregateError(
|
|
377
|
+
[error, cleanupError],
|
|
378
|
+
"Controller observation failed and cleanup was not confirmed."
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
throw error;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
fail(entry, error) {
|
|
385
|
+
if (entry.error) return;
|
|
386
|
+
entry.error = error;
|
|
387
|
+
entry.onError(error instanceof Error ? error : new Error(String(error)));
|
|
388
|
+
}
|
|
389
|
+
deliver(event) {
|
|
390
|
+
const entry = this.entries.get(event.requestId);
|
|
391
|
+
if (!entry || entry.error || entry.closing) return;
|
|
392
|
+
if (entry.pending.length + entry.queued >= PENDING_DELIVERIES) {
|
|
393
|
+
this.fail(
|
|
394
|
+
entry,
|
|
395
|
+
new Error("Controller observation event allowance exceeded.")
|
|
396
|
+
);
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
if (!entry.observation) {
|
|
400
|
+
entry.pending.push(event);
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
const observation = entry.observation;
|
|
404
|
+
entry.queued++;
|
|
405
|
+
entry.delivery = entry.delivery.then(() => {
|
|
406
|
+
if (!entry.closing && !entry.error)
|
|
407
|
+
return observation.deliver(event.message);
|
|
408
|
+
}).catch((error) => {
|
|
409
|
+
if (!entry.closing) this.fail(entry, error);
|
|
410
|
+
}).finally(() => {
|
|
411
|
+
entry.queued--;
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
async close(requestId) {
|
|
415
|
+
const entry = this.entries.get(requestId);
|
|
416
|
+
if (!entry) return;
|
|
417
|
+
entry.abort.abort();
|
|
418
|
+
return entry.closing ??= (async () => {
|
|
419
|
+
try {
|
|
420
|
+
await entry.opening?.catch(() => void 0);
|
|
421
|
+
await entry.observation?.close();
|
|
422
|
+
await entry.delivery;
|
|
423
|
+
} finally {
|
|
424
|
+
this.entries.delete(requestId);
|
|
425
|
+
}
|
|
426
|
+
})();
|
|
427
|
+
}
|
|
428
|
+
async closeAll() {
|
|
429
|
+
const results = await Promise.allSettled(
|
|
430
|
+
[...this.entries.keys()].map((id) => this.close(id))
|
|
431
|
+
);
|
|
432
|
+
const failed = results.filter((result) => result.status === "rejected");
|
|
433
|
+
if (failed.length)
|
|
434
|
+
throw new AggregateError(
|
|
435
|
+
failed.map((result) => result.reason),
|
|
436
|
+
"Controller observation cleanup failed."
|
|
437
|
+
);
|
|
51
438
|
}
|
|
52
439
|
};
|
|
53
440
|
|
|
441
|
+
// src/harness/visual/screencast.ts
|
|
442
|
+
function jpegDimensions(data) {
|
|
443
|
+
const bytes = Buffer.from(data, "base64");
|
|
444
|
+
if (bytes[0] !== 255 || bytes[1] !== 216)
|
|
445
|
+
throw new Error("Run watch received a non-JPEG frame.");
|
|
446
|
+
let offset = 2;
|
|
447
|
+
while (offset + 4 <= bytes.length) {
|
|
448
|
+
if (bytes[offset] !== 255) throw new Error("Invalid JPEG marker.");
|
|
449
|
+
const marker = bytes[offset + 1];
|
|
450
|
+
const length = bytes.readUInt16BE(offset + 2);
|
|
451
|
+
if (length < 2 || offset + 2 + length > bytes.length) break;
|
|
452
|
+
if ([192, 193, 194].includes(marker)) {
|
|
453
|
+
if (length < 8) break;
|
|
454
|
+
return {
|
|
455
|
+
width: bytes.readUInt16BE(offset + 7),
|
|
456
|
+
height: bytes.readUInt16BE(offset + 5)
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
offset += length + 2;
|
|
460
|
+
}
|
|
461
|
+
throw new Error("Run watch JPEG dimensions are unavailable.");
|
|
462
|
+
}
|
|
463
|
+
async function startGameScreencast({
|
|
464
|
+
page,
|
|
465
|
+
send,
|
|
466
|
+
onError,
|
|
467
|
+
onReady
|
|
468
|
+
}) {
|
|
469
|
+
const viewport = page.viewportSize();
|
|
470
|
+
if (!viewport)
|
|
471
|
+
throw new Error("Run watch requires an explicit capture viewport.");
|
|
472
|
+
const scale = Math.min(1, 1280 / Math.max(viewport.width, viewport.height));
|
|
473
|
+
const connection = await page.context().newCDPSession(page);
|
|
474
|
+
let closed = false;
|
|
475
|
+
let sending = false;
|
|
476
|
+
let pending;
|
|
477
|
+
let heartbeat;
|
|
478
|
+
let sequence = 0;
|
|
479
|
+
let lastFrameSeq = null;
|
|
480
|
+
const acknowledgements = [];
|
|
481
|
+
let acknowledgementTimer;
|
|
482
|
+
let heartbeatTimer;
|
|
483
|
+
let nextAcknowledgementAt = 0;
|
|
484
|
+
const acknowledge = () => {
|
|
485
|
+
if (closed || acknowledgementTimer || !acknowledgements.length) return;
|
|
486
|
+
acknowledgementTimer = setTimeout(
|
|
487
|
+
() => {
|
|
488
|
+
acknowledgementTimer = void 0;
|
|
489
|
+
if (closed) return;
|
|
490
|
+
const sessionId = acknowledgements.shift();
|
|
491
|
+
if (sessionId === void 0) return;
|
|
492
|
+
nextAcknowledgementAt = performance.now() + 1e3 / 15;
|
|
493
|
+
void connection.send("Page.screencastFrameAck", { sessionId }).then(acknowledge, (error) => {
|
|
494
|
+
if (!closed) onError(error);
|
|
495
|
+
});
|
|
496
|
+
},
|
|
497
|
+
Math.max(0, nextAcknowledgementAt - performance.now())
|
|
498
|
+
);
|
|
499
|
+
};
|
|
500
|
+
const flush = () => {
|
|
501
|
+
if (closed || sending) return;
|
|
502
|
+
const event = heartbeat ?? pending;
|
|
503
|
+
if (!event) return;
|
|
504
|
+
if (event.type === "frame") pending = void 0;
|
|
505
|
+
else heartbeat = void 0;
|
|
506
|
+
sending = true;
|
|
507
|
+
send(event, (error) => {
|
|
508
|
+
sending = false;
|
|
509
|
+
if (closed) return;
|
|
510
|
+
if (error) {
|
|
511
|
+
onError(error);
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
flush();
|
|
515
|
+
});
|
|
516
|
+
};
|
|
517
|
+
const pageClosed = () => {
|
|
518
|
+
if (!closed) onError(new Error("Watched game surface closed."));
|
|
519
|
+
};
|
|
520
|
+
page.once("close", pageClosed);
|
|
521
|
+
connection.on("Page.screencastFrame", (frame) => {
|
|
522
|
+
if (closed) return;
|
|
523
|
+
if (acknowledgements.length >= 4) {
|
|
524
|
+
onError(new Error("Run watch capture flow control exceeded."));
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
acknowledgements.push(frame.sessionId);
|
|
528
|
+
acknowledge();
|
|
529
|
+
try {
|
|
530
|
+
if (frame.data.length > MAXIMUM_GAME_WATCH_FRAME_BASE64)
|
|
531
|
+
throw new Error("Run watch frame exceeds its transfer allowance.");
|
|
532
|
+
if (frame.metadata.timestamp === void 0)
|
|
533
|
+
throw new Error("Run watch frame is missing its capture timestamp.");
|
|
534
|
+
if (sequence === 0) {
|
|
535
|
+
onReady(jpegDimensions(frame.data));
|
|
536
|
+
heartbeatTimer = setInterval(() => {
|
|
537
|
+
heartbeat = { type: "heartbeat", at: Date.now(), lastFrameSeq };
|
|
538
|
+
flush();
|
|
539
|
+
}, GAME_WATCH_HEARTBEAT_MS);
|
|
540
|
+
}
|
|
541
|
+
lastFrameSeq = sequence++;
|
|
542
|
+
pending = {
|
|
543
|
+
type: "frame",
|
|
544
|
+
seq: lastFrameSeq,
|
|
545
|
+
capturedAt: frame.metadata.timestamp * 1e3,
|
|
546
|
+
data: frame.data
|
|
547
|
+
};
|
|
548
|
+
flush();
|
|
549
|
+
} catch (error) {
|
|
550
|
+
onError(error instanceof Error ? error : new Error(String(error)));
|
|
551
|
+
}
|
|
552
|
+
});
|
|
553
|
+
const close = async () => {
|
|
554
|
+
if (closed) return;
|
|
555
|
+
closed = true;
|
|
556
|
+
clearInterval(heartbeatTimer);
|
|
557
|
+
clearTimeout(acknowledgementTimer);
|
|
558
|
+
acknowledgements.length = 0;
|
|
559
|
+
pending = void 0;
|
|
560
|
+
heartbeat = void 0;
|
|
561
|
+
page.off("close", pageClosed);
|
|
562
|
+
try {
|
|
563
|
+
await connection.detach();
|
|
564
|
+
} catch (error) {
|
|
565
|
+
if (!page.isClosed()) throw error;
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
try {
|
|
569
|
+
await connection.send("Page.startScreencast", {
|
|
570
|
+
format: "jpeg",
|
|
571
|
+
quality: 75,
|
|
572
|
+
maxWidth: Math.floor(viewport.width * scale),
|
|
573
|
+
maxHeight: Math.floor(viewport.height * scale),
|
|
574
|
+
everyNthFrame: 1
|
|
575
|
+
});
|
|
576
|
+
return { close };
|
|
577
|
+
} catch (error) {
|
|
578
|
+
await close();
|
|
579
|
+
throw error;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
|
|
54
583
|
// src/tooling/hold-runtime-host.ts
|
|
55
584
|
var getFlagValue = (flag) => {
|
|
56
585
|
const inline = process.argv.find((value) => value.startsWith(`${flag}=`));
|
|
@@ -60,10 +589,12 @@ var getFlagValue = (flag) => {
|
|
|
60
589
|
const index = process.argv.indexOf(flag);
|
|
61
590
|
return index === -1 ? null : process.argv[index + 1] ?? null;
|
|
62
591
|
};
|
|
63
|
-
var
|
|
64
|
-
var
|
|
65
|
-
var
|
|
66
|
-
var
|
|
592
|
+
var pinnedManifest = getFlagValue("--pinned-build");
|
|
593
|
+
var built = pinnedManifest ? await startBuiltGameRuntime(pinnedManifest) : null;
|
|
594
|
+
var appOrigin = built?.urls.appOrigin ?? getFlagValue("--app-origin");
|
|
595
|
+
var hostUrl = built?.urls.hostUrl ?? getFlagValue("--host-url");
|
|
596
|
+
var controllerBaseUrl = built?.urls.controllerBaseUrl ?? getFlagValue("--controller-base-url");
|
|
597
|
+
var publicHost = built?.urls.publicHost ?? getFlagValue("--public-host");
|
|
67
598
|
var localBuildUrl = getFlagValue("--local-build-url");
|
|
68
599
|
var browserBuildUrl = getFlagValue("--browser-build-url");
|
|
69
600
|
var requestedMode = getFlagValue("--mode") ?? "standalone-dev";
|
|
@@ -73,29 +604,165 @@ if (!appOrigin || !hostUrl || !controllerBaseUrl || !publicHost) {
|
|
|
73
604
|
"Missing required isolated runtime host inputs. Expected resolved topology URLs."
|
|
74
605
|
);
|
|
75
606
|
}
|
|
76
|
-
var
|
|
607
|
+
var initialSettings = getFlagValue("--settings");
|
|
608
|
+
var initialHostUrl = new URL(hostUrl);
|
|
609
|
+
if (initialSettings)
|
|
610
|
+
initialHostUrl.searchParams.set(
|
|
611
|
+
"airjamSettings",
|
|
612
|
+
JSON.stringify(
|
|
613
|
+
airJamSettingsValuesSchema.parse(JSON.parse(initialSettings))
|
|
614
|
+
)
|
|
615
|
+
);
|
|
616
|
+
var runtimeBrowser = await launchScopedHarnessBrowser();
|
|
617
|
+
var { browser } = runtimeBrowser;
|
|
618
|
+
var startupDiagnostics = true;
|
|
77
619
|
var session = await openVisualHarnessHostSession({
|
|
78
620
|
browser,
|
|
621
|
+
runtimeTopology: built?.topology,
|
|
622
|
+
onDiagnostic: (message) => {
|
|
623
|
+
if (startupDiagnostics) console.error(message.slice(0, 4e3));
|
|
624
|
+
},
|
|
79
625
|
mode: requestedMode,
|
|
80
626
|
urls: {
|
|
81
627
|
appOrigin,
|
|
82
|
-
hostUrl,
|
|
628
|
+
hostUrl: initialHostUrl.toString(),
|
|
83
629
|
controllerBaseUrl,
|
|
84
630
|
publicHost,
|
|
85
631
|
localBuildUrl,
|
|
86
632
|
browserBuildUrl
|
|
87
633
|
}
|
|
88
634
|
});
|
|
89
|
-
var
|
|
635
|
+
var captureRequestId = null;
|
|
636
|
+
var observations = new RuntimeControllerObservations({
|
|
637
|
+
browser,
|
|
638
|
+
readInspection: () => readInspection(),
|
|
639
|
+
send: (message) => {
|
|
640
|
+
process.send?.(message);
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
var watches = /* @__PURE__ */ new Map();
|
|
644
|
+
var stopWatch = (watchId) => {
|
|
645
|
+
const watch = watches.get(watchId);
|
|
646
|
+
if (!watch) return Promise.resolve();
|
|
647
|
+
watch.stopping = true;
|
|
648
|
+
return watch.closing ??= (async () => {
|
|
649
|
+
const results = await Promise.allSettled([
|
|
650
|
+
observations.close(watchId),
|
|
651
|
+
(async () => {
|
|
652
|
+
await watch.opening.catch(() => void 0);
|
|
653
|
+
await watch.cast?.close();
|
|
654
|
+
})()
|
|
655
|
+
]);
|
|
656
|
+
const failures = results.filter((result) => result.status === "rejected");
|
|
657
|
+
watches.delete(watchId);
|
|
658
|
+
if (failures.length)
|
|
659
|
+
throw new AggregateError(
|
|
660
|
+
failures.map((result) => result.reason),
|
|
661
|
+
[
|
|
662
|
+
"Run watch cleanup failed.",
|
|
663
|
+
...failures.map(
|
|
664
|
+
({ reason }) => reason instanceof Error ? reason.message : String(reason)
|
|
665
|
+
)
|
|
666
|
+
].join(" ").slice(0, 4e3)
|
|
667
|
+
);
|
|
668
|
+
})();
|
|
669
|
+
};
|
|
90
670
|
var shutdown = async (exitCode = 0) => {
|
|
91
671
|
await Promise.allSettled([
|
|
92
|
-
|
|
672
|
+
...[...watches.keys()].map(stopWatch),
|
|
673
|
+
observations.closeAll(),
|
|
93
674
|
session.close(),
|
|
94
|
-
|
|
675
|
+
runtimeBrowser.close(),
|
|
676
|
+
built?.close()
|
|
95
677
|
]);
|
|
96
678
|
process.exit(exitCode);
|
|
97
679
|
};
|
|
98
680
|
process.on("message", (message) => {
|
|
681
|
+
const agentRequest = runtimeOwnerAgentRequestSchema.safeParse(message);
|
|
682
|
+
if (agentRequest.success) {
|
|
683
|
+
const { requestId, request } = agentRequest.data;
|
|
684
|
+
void (async () => {
|
|
685
|
+
try {
|
|
686
|
+
const result = await evaluateOwnedGameContract(session.host, request);
|
|
687
|
+
process.send?.({
|
|
688
|
+
type: "air-jam-runtime-owner.agent-result/v1",
|
|
689
|
+
requestId,
|
|
690
|
+
ok: true,
|
|
691
|
+
result
|
|
692
|
+
});
|
|
693
|
+
} catch (error) {
|
|
694
|
+
process.send?.({
|
|
695
|
+
type: "air-jam-runtime-owner.agent-result/v1",
|
|
696
|
+
requestId,
|
|
697
|
+
ok: false,
|
|
698
|
+
error: error instanceof Error ? error.message : String(error)
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
})();
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
const captureEvent = runtimeOwnerCapturePortSchema.safeParse(message);
|
|
705
|
+
if (captureEvent.success) {
|
|
706
|
+
observations.deliver(captureEvent.data);
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
const watchStop = runtimeOwnerWatchStopSchema.safeParse(message);
|
|
710
|
+
if (watchStop.success) {
|
|
711
|
+
void stopWatch(watchStop.data.watchId).then(() => {
|
|
712
|
+
process.send?.({
|
|
713
|
+
type: "air-jam-runtime-owner.watch-event/v1",
|
|
714
|
+
watchId: watchStop.data.watchId,
|
|
715
|
+
event: { type: "closed" }
|
|
716
|
+
});
|
|
717
|
+
}).catch((error) => {
|
|
718
|
+
process.send?.({
|
|
719
|
+
type: "air-jam-runtime-owner.watch-event/v1",
|
|
720
|
+
watchId: watchStop.data.watchId,
|
|
721
|
+
event: { type: "error", message: String(error).slice(0, 4e3) }
|
|
722
|
+
});
|
|
723
|
+
});
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
const watchRequest = runtimeOwnerWatchRequestSchema.safeParse(message);
|
|
727
|
+
if (watchRequest.success) {
|
|
728
|
+
const request = watchRequest.data;
|
|
729
|
+
if (watches.has(request.watchId)) return;
|
|
730
|
+
const send = (event, sent) => {
|
|
731
|
+
const message2 = {
|
|
732
|
+
type: "air-jam-runtime-owner.watch-event/v1",
|
|
733
|
+
watchId: request.watchId,
|
|
734
|
+
event
|
|
735
|
+
};
|
|
736
|
+
if (sent) process.send?.(message2, void 0, void 0, sent);
|
|
737
|
+
else process.send?.(message2);
|
|
738
|
+
};
|
|
739
|
+
const fail = (error) => {
|
|
740
|
+
if (watches.get(request.watchId)?.stopping) return;
|
|
741
|
+
send({ type: "error", message: error.message.slice(0, 4e3) });
|
|
742
|
+
void stopWatch(request.watchId).catch(
|
|
743
|
+
(cleanupError) => console.error("Run watch cleanup failed:", cleanupError)
|
|
744
|
+
);
|
|
745
|
+
};
|
|
746
|
+
if (watches.size >= 2) {
|
|
747
|
+
send({ type: "error", message: "Run watch producer limit reached." });
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
const watch = { opening: Promise.resolve(), stopping: false };
|
|
751
|
+
watches.set(request.watchId, watch);
|
|
752
|
+
watch.opening = (async () => {
|
|
753
|
+
const page = request.surface === "host" ? session.host.page : (await observations.open(request.watchId, request, fail)).page;
|
|
754
|
+
watch.cast = await startGameScreencast({
|
|
755
|
+
page,
|
|
756
|
+
send,
|
|
757
|
+
onError: fail,
|
|
758
|
+
onReady: (dimensions) => send({ type: "ready", ...dimensions })
|
|
759
|
+
});
|
|
760
|
+
})();
|
|
761
|
+
void watch.opening.catch(
|
|
762
|
+
(error) => fail(error instanceof Error ? error : new Error(String(error)))
|
|
763
|
+
);
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
99
766
|
if (isRuntimeOwnerActionRequest(message)) {
|
|
100
767
|
void (async () => {
|
|
101
768
|
const acknowledgement = await invokeOwnedHostAction(
|
|
@@ -111,6 +778,18 @@ process.on("message", (message) => {
|
|
|
111
778
|
return;
|
|
112
779
|
}
|
|
113
780
|
if (!isRuntimeOwnerCaptureRequest(message)) return;
|
|
781
|
+
if (captureRequestId) {
|
|
782
|
+
process.send?.({
|
|
783
|
+
type: AIR_JAM_RUNTIME_OWNER_CAPTURE_RESULT,
|
|
784
|
+
requestId: message.requestId,
|
|
785
|
+
ok: false,
|
|
786
|
+
capturedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
787
|
+
screenshots: [],
|
|
788
|
+
error: "A runtime visual capture is already active."
|
|
789
|
+
});
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
captureRequestId = message.requestId;
|
|
114
793
|
void (async () => {
|
|
115
794
|
const capturedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
116
795
|
const response = {
|
|
@@ -121,23 +800,20 @@ process.on("message", (message) => {
|
|
|
121
800
|
screenshots: [],
|
|
122
801
|
error: null
|
|
123
802
|
};
|
|
803
|
+
let observationError;
|
|
124
804
|
try {
|
|
125
805
|
const captureDir = resolveProjectRelativeRuntimeCaptureDir({
|
|
126
806
|
projectDir: process.cwd(),
|
|
127
807
|
relativeDir: message.relativeDir
|
|
128
808
|
});
|
|
129
|
-
controllerSession
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
browserBuildUrl
|
|
138
|
-
},
|
|
139
|
-
host: session.host
|
|
140
|
-
});
|
|
809
|
+
const controllerSession = await observations.open(
|
|
810
|
+
message.requestId,
|
|
811
|
+
message,
|
|
812
|
+
(error) => {
|
|
813
|
+
observationError = error;
|
|
814
|
+
}
|
|
815
|
+
);
|
|
816
|
+
if (observationError) throw observationError;
|
|
141
817
|
await mkdir(captureDir, { recursive: true });
|
|
142
818
|
const captures = [
|
|
143
819
|
{
|
|
@@ -150,23 +826,38 @@ process.on("message", (message) => {
|
|
|
150
826
|
surface: "controller",
|
|
151
827
|
fileName: "controller-phone.png",
|
|
152
828
|
viewport: DEFAULT_CONTROLLER_VIEWPORT,
|
|
153
|
-
page: controllerSession.
|
|
829
|
+
page: controllerSession.page
|
|
154
830
|
}
|
|
155
831
|
];
|
|
156
832
|
for (const capture of captures) {
|
|
157
833
|
await capture.page.waitForTimeout(300);
|
|
158
|
-
const filePath =
|
|
834
|
+
const filePath = path2.join(captureDir, capture.fileName);
|
|
159
835
|
await capture.page.screenshot({ path: filePath });
|
|
160
836
|
response.screenshots.push({
|
|
161
837
|
surface: capture.surface,
|
|
162
838
|
width: capture.viewport.width,
|
|
163
839
|
height: capture.viewport.height,
|
|
164
|
-
relativePath:
|
|
840
|
+
relativePath: path2.relative(process.cwd(), filePath)
|
|
165
841
|
});
|
|
166
842
|
}
|
|
167
843
|
response.ok = true;
|
|
168
844
|
} catch (error) {
|
|
169
845
|
response.error = error instanceof Error ? error.message : String(error);
|
|
846
|
+
} finally {
|
|
847
|
+
captureRequestId = null;
|
|
848
|
+
if (observationError) {
|
|
849
|
+
response.ok = false;
|
|
850
|
+
response.error = observationError.message;
|
|
851
|
+
}
|
|
852
|
+
try {
|
|
853
|
+
await observations.close(message.requestId);
|
|
854
|
+
} catch (error) {
|
|
855
|
+
response.ok = false;
|
|
856
|
+
response.error = [
|
|
857
|
+
response.error,
|
|
858
|
+
error instanceof Error ? error.message : String(error)
|
|
859
|
+
].filter(Boolean).join("; ");
|
|
860
|
+
}
|
|
170
861
|
}
|
|
171
862
|
process.send?.(response);
|
|
172
863
|
})();
|
|
@@ -183,21 +874,28 @@ process.once("disconnect", () => {
|
|
|
183
874
|
var readInspection = async () => {
|
|
184
875
|
const rawValue = session.host.embedded ? await session.host.game.locator("body").evaluate(
|
|
185
876
|
(_, key) => window[key] ?? null,
|
|
186
|
-
|
|
877
|
+
AIR_JAM_RUNTIME_INSPECTION_KEY2
|
|
187
878
|
) : await session.host.page.evaluate(
|
|
188
879
|
(key) => window[key] ?? null,
|
|
189
|
-
|
|
880
|
+
AIR_JAM_RUNTIME_INSPECTION_KEY2
|
|
190
881
|
);
|
|
191
|
-
|
|
192
|
-
[
|
|
882
|
+
const inspection = readRuntimeInspectionContract({
|
|
883
|
+
[AIR_JAM_RUNTIME_INSPECTION_KEY2]: rawValue
|
|
193
884
|
});
|
|
885
|
+
return built && inspection?.role === "host" && inspection.localControllerUrl ? {
|
|
886
|
+
...inspection,
|
|
887
|
+
localControllerUrl: bindHarnessControllerUrl(
|
|
888
|
+
inspection.localControllerUrl,
|
|
889
|
+
built.urls.controllerBaseUrl
|
|
890
|
+
)
|
|
891
|
+
} : inspection;
|
|
194
892
|
};
|
|
195
893
|
try {
|
|
196
894
|
const startedAt = Date.now();
|
|
197
895
|
let inspection = null;
|
|
198
896
|
while (Date.now() - startedAt < timeoutMs) {
|
|
199
897
|
const nextInspection = await readInspection();
|
|
200
|
-
if (nextInspection?.role === "host" && nextInspection.
|
|
898
|
+
if (nextInspection?.role === "host" && nextInspection.localControllerUrl) {
|
|
201
899
|
inspection = nextInspection;
|
|
202
900
|
break;
|
|
203
901
|
}
|
|
@@ -208,18 +906,22 @@ try {
|
|
|
208
906
|
"Timed out waiting for a published host runtime inspection contract."
|
|
209
907
|
);
|
|
210
908
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
909
|
+
if (built) {
|
|
910
|
+
const origin = new URL(session.host.page.url()).origin;
|
|
911
|
+
if (origin !== appOrigin || await session.host.page.evaluate(
|
|
912
|
+
() => performance.getEntriesByType("resource").some((entry) => new URL(entry.name).pathname === "/@vite/client")
|
|
913
|
+
))
|
|
914
|
+
throw new Error(
|
|
915
|
+
"build_runtime_invalid: The owned browser is not running the pinned production origin."
|
|
916
|
+
);
|
|
917
|
+
}
|
|
918
|
+
startupDiagnostics = false;
|
|
919
|
+
process.send?.({
|
|
920
|
+
type: "air-jam-runtime-owner.ready/v1",
|
|
921
|
+
roomId: inspection.roomId,
|
|
922
|
+
controllerJoinUrl: inspection.localControllerUrl,
|
|
923
|
+
inspection
|
|
924
|
+
});
|
|
223
925
|
await new Promise(() => {
|
|
224
926
|
});
|
|
225
927
|
} catch (error) {
|