@air-jam/devtools 0.0.0-stage → 1.0.0-beta.1
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/LICENSE +21 -0
- package/README.md +112 -2
- package/dist/chunk-2O67AXCU.js +470 -0
- 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-M6CJ7GQC.js +133 -0
- package/dist/chunk-M6CJ7GQC.js.map +1 -0
- package/dist/chunk-MEIMOSZC.js +749 -0
- package/dist/chunk-MEIMOSZC.js.map +1 -0
- package/dist/chunk-O3XG3FNL.js +1014 -0
- package/dist/chunk-O3XG3FNL.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 +19 -0
- package/dist/context.js +10 -0
- package/dist/context.js.map +1 -0
- package/dist/controller.d.ts +67 -0
- package/dist/controller.js +40 -0
- package/dist/controller.js.map +1 -0
- package/dist/dependencies.d.ts +44 -0
- package/dist/dependencies.js +10 -0
- package/dist/dependencies.js.map +1 -0
- package/dist/dev.d.ts +21 -0
- package/dist/dev.js +19 -0
- package/dist/dev.js.map +1 -0
- 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 -0
- package/dist/game-session-broker.js +40 -0
- package/dist/game-session-broker.js.map +1 -0
- package/dist/game-session.d.ts +3934 -0
- package/dist/game-session.js +195 -0
- package/dist/game-session.js.map +1 -0
- 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 +28 -0
- package/dist/games.js +16 -0
- package/dist/games.js.map +1 -0
- package/dist/harness/visual.d.ts +204 -0
- package/dist/harness/visual.js +46 -0
- package/dist/harness/visual.js.map +1 -0
- package/dist/logs.d.ts +15 -0
- package/dist/logs.js +57 -0
- package/dist/logs.js.map +1 -0
- package/dist/managed-process-scope-BicYi_t9.d.ts +3 -0
- package/dist/mcp-config.d.ts +63 -0
- package/dist/mcp-config.js +191 -0
- package/dist/mcp-config.js.map +1 -0
- package/dist/platform-auth.d.ts +9 -0
- package/dist/platform-auth.js +45 -0
- package/dist/platform-auth.js.map +1 -0
- 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 +347 -0
- package/dist/platform-game-media.js +168 -0
- package/dist/platform-game-media.js.map +1 -0
- package/dist/platform-games.d.ts +87 -0
- package/dist/platform-games.js +183 -0
- package/dist/platform-games.js.map +1 -0
- package/dist/quality.d.ts +16 -0
- package/dist/quality.js +62 -0
- package/dist/quality.js.map +1 -0
- package/dist/release.d.ts +1304 -0
- package/dist/release.js +34 -0
- package/dist/release.js.map +1 -0
- 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.d.ts +2 -0
- package/dist/tooling/describe-game.js +54 -0
- package/dist/tooling/describe-game.js.map +1 -0
- package/dist/tooling/game-session-broker.d.ts +2 -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.d.ts +2 -0
- package/dist/tooling/hold-runtime-host.js +931 -0
- package/dist/tooling/hold-runtime-host.js.map +1 -0
- package/dist/tooling/list-visual-scenarios.d.ts +2 -0
- package/dist/tooling/list-visual-scenarios.js +25 -0
- package/dist/tooling/list-visual-scenarios.js.map +1 -0
- package/dist/tooling/managed-dev-supervisor.d.ts +2 -0
- package/dist/tooling/managed-dev-supervisor.js +51 -0
- package/dist/tooling/managed-dev-supervisor.js.map +1 -0
- 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 +287 -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.d.ts +2 -0
- package/dist/tooling/run-visual-capture.js +203 -0
- package/dist/tooling/run-visual-capture.js.map +1 -0
- 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-CdYrgrG_.d.ts +1036 -0
- package/dist/types-DyRD-ym1.d.ts +141 -0
- package/dist/visual.d.ts +21 -0
- package/dist/visual.js +219 -0
- package/dist/visual.js.map +1 -0
- package/package.json +150 -3
- package/src/bounded-response.ts +28 -0
- package/src/built-game-runtime.ts +152 -0
- package/src/commands.ts +40 -0
- package/src/context.ts +218 -0
- package/src/controller-protocol.ts +22 -0
- package/src/controller.ts +1526 -0
- 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 +995 -0
- package/src/fs-utils.ts +93 -0
- package/src/game-action-observation.ts +106 -0
- 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 +793 -0
- 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 +206 -0
- package/src/game-settings.ts +295 -0
- package/src/games.ts +262 -0
- package/src/harness/visual/browser.ts +100 -0
- package/src/harness/visual/controller-observation.ts +181 -0
- package/src/harness/visual/prefab-contract.ts +29 -0
- package/src/harness/visual/prefab-runner.ts +178 -0
- package/src/harness/visual/runner.ts +549 -0
- package/src/harness/visual/runtime-controller-observations.ts +151 -0
- package/src/harness/visual/scenario-contract.ts +8 -0
- package/src/harness/visual/scenario-helpers.ts +67 -0
- package/src/harness/visual/screencast.ts +155 -0
- package/src/harness/visual/session.ts +400 -0
- package/src/harness/visual/types.ts +184 -0
- package/src/harness/visual.ts +7 -0
- 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 +69 -0
- package/src/installed-dependencies.ts +74 -0
- package/src/logs.ts +67 -0
- package/src/managed-process-scope.ts +481 -0
- package/src/mcp-config.ts +262 -0
- package/src/node-process-environment.ts +10 -0
- package/src/platform-auth.ts +594 -0
- package/src/platform-game-analytics.ts +50 -0
- package/src/platform-game-app-id.ts +99 -0
- package/src/platform-game-media.ts +209 -0
- package/src/platform-games.ts +217 -0
- 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/quality.ts +82 -0
- package/src/release.ts +1683 -0
- 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 +218 -0
- 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 +441 -0
- package/src/tooling/list-visual-scenarios.ts +21 -0
- package/src/tooling/load-game.ts +79 -0
- package/src/tooling/managed-dev-supervisor.ts +71 -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 +326 -0
- package/src/tooling/run-test-profile.ts +190 -0
- package/src/tooling/run-visual-capture.ts +231 -0
- package/src/tooling/runtime-owner-actions.ts +65 -0
- package/src/tooling/seal-game-build.ts +118 -0
- package/src/tooling/visual-pack.ts +11 -0
- package/src/types.ts +928 -0
- package/src/visual.ts +296 -0
- package/src/windows-process-scopes.ts +189 -0
- package/src/workspace-contract.ts +32 -0
|
@@ -0,0 +1,931 @@
|
|
|
1
|
+
import {
|
|
2
|
+
evaluateOwnedGameContract,
|
|
3
|
+
invokeOwnedHostAction
|
|
4
|
+
} from "../chunk-E3UZZGAV.js";
|
|
5
|
+
import {
|
|
6
|
+
DEFAULT_CONTROLLER_VIEWPORT,
|
|
7
|
+
DEFAULT_HOST_VIEWPORT,
|
|
8
|
+
bindHarnessControllerUrl,
|
|
9
|
+
installHarnessRuntimeTopology,
|
|
10
|
+
launchScopedHarnessBrowser,
|
|
11
|
+
openVisualHarnessHostSession
|
|
12
|
+
} from "../chunk-O3XG3FNL.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";
|
|
23
|
+
import {
|
|
24
|
+
AIR_JAM_RUNTIME_OWNER_ACTION_RESULT,
|
|
25
|
+
AIR_JAM_RUNTIME_OWNER_CAPTURE_FRAME,
|
|
26
|
+
AIR_JAM_RUNTIME_OWNER_CAPTURE_RESULT,
|
|
27
|
+
isRuntimeOwnerActionRequest,
|
|
28
|
+
isRuntimeOwnerCaptureRequest,
|
|
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";
|
|
43
|
+
|
|
44
|
+
// src/tooling/hold-runtime-host.ts
|
|
45
|
+
import { airJamSettingsValuesSchema } from "@air-jam/sdk/core";
|
|
46
|
+
import {
|
|
47
|
+
AIR_JAM_RUNTIME_INSPECTION_KEY as AIR_JAM_RUNTIME_INSPECTION_KEY2,
|
|
48
|
+
readRuntimeInspectionContract
|
|
49
|
+
} from "@air-jam/sdk/runtime-inspection";
|
|
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";
|
|
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
|
+
}
|
|
189
|
+
|
|
190
|
+
// src/harness/visual/controller-observation.ts
|
|
191
|
+
import { AIR_JAM_RUNTIME_INSPECTION_KEY } from "@air-jam/sdk/runtime-inspection";
|
|
192
|
+
import {
|
|
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 });
|
|
217
|
+
try {
|
|
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);
|
|
288
|
+
},
|
|
289
|
+
{ controllerUrl: controllerUrl.href, harnessSessionId }
|
|
290
|
+
);
|
|
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
|
+
})();
|
|
312
|
+
return {
|
|
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
|
|
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.joinUrl,
|
|
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
|
+
);
|
|
438
|
+
}
|
|
439
|
+
};
|
|
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
|
+
|
|
583
|
+
// src/tooling/hold-runtime-host.ts
|
|
584
|
+
var getFlagValue = (flag) => {
|
|
585
|
+
const inline = process.argv.find((value) => value.startsWith(`${flag}=`));
|
|
586
|
+
if (inline) {
|
|
587
|
+
return inline.slice(flag.length + 1);
|
|
588
|
+
}
|
|
589
|
+
const index = process.argv.indexOf(flag);
|
|
590
|
+
return index === -1 ? null : process.argv[index + 1] ?? null;
|
|
591
|
+
};
|
|
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");
|
|
598
|
+
var localBuildUrl = getFlagValue("--local-build-url");
|
|
599
|
+
var browserBuildUrl = getFlagValue("--browser-build-url");
|
|
600
|
+
var requestedMode = getFlagValue("--mode") ?? "standalone-dev";
|
|
601
|
+
var timeoutMs = Number(getFlagValue("--timeout-ms") ?? "15000");
|
|
602
|
+
if (!appOrigin || !hostUrl || !controllerBaseUrl || !publicHost) {
|
|
603
|
+
throw new Error(
|
|
604
|
+
"Missing required isolated runtime host inputs. Expected resolved topology URLs."
|
|
605
|
+
);
|
|
606
|
+
}
|
|
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;
|
|
619
|
+
var session = await openVisualHarnessHostSession({
|
|
620
|
+
browser,
|
|
621
|
+
runtimeTopology: built?.topology,
|
|
622
|
+
onDiagnostic: (message) => {
|
|
623
|
+
if (startupDiagnostics) console.error(message.slice(0, 4e3));
|
|
624
|
+
},
|
|
625
|
+
mode: requestedMode,
|
|
626
|
+
urls: {
|
|
627
|
+
appOrigin,
|
|
628
|
+
hostUrl: initialHostUrl.toString(),
|
|
629
|
+
controllerBaseUrl,
|
|
630
|
+
publicHost,
|
|
631
|
+
localBuildUrl,
|
|
632
|
+
browserBuildUrl
|
|
633
|
+
}
|
|
634
|
+
});
|
|
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
|
+
};
|
|
670
|
+
var shutdown = async (exitCode = 0) => {
|
|
671
|
+
await Promise.allSettled([
|
|
672
|
+
...[...watches.keys()].map(stopWatch),
|
|
673
|
+
observations.closeAll(),
|
|
674
|
+
session.close(),
|
|
675
|
+
runtimeBrowser.close(),
|
|
676
|
+
built?.close()
|
|
677
|
+
]);
|
|
678
|
+
process.exit(exitCode);
|
|
679
|
+
};
|
|
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
|
+
}
|
|
766
|
+
if (isRuntimeOwnerActionRequest(message)) {
|
|
767
|
+
void (async () => {
|
|
768
|
+
const acknowledgement = await invokeOwnedHostAction(
|
|
769
|
+
session.host,
|
|
770
|
+
message.action
|
|
771
|
+
);
|
|
772
|
+
process.send?.({
|
|
773
|
+
type: AIR_JAM_RUNTIME_OWNER_ACTION_RESULT,
|
|
774
|
+
requestId: message.requestId,
|
|
775
|
+
acknowledgement
|
|
776
|
+
});
|
|
777
|
+
})();
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
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;
|
|
793
|
+
void (async () => {
|
|
794
|
+
const capturedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
795
|
+
const response = {
|
|
796
|
+
type: AIR_JAM_RUNTIME_OWNER_CAPTURE_RESULT,
|
|
797
|
+
requestId: message.requestId,
|
|
798
|
+
ok: false,
|
|
799
|
+
capturedAt,
|
|
800
|
+
screenshots: [],
|
|
801
|
+
error: null
|
|
802
|
+
};
|
|
803
|
+
let observationError;
|
|
804
|
+
try {
|
|
805
|
+
const captureDir = resolveProjectRelativeRuntimeCaptureDir({
|
|
806
|
+
projectDir: process.cwd(),
|
|
807
|
+
relativeDir: message.relativeDir
|
|
808
|
+
});
|
|
809
|
+
const controllerSession = await observations.open(
|
|
810
|
+
message.requestId,
|
|
811
|
+
message,
|
|
812
|
+
(error) => {
|
|
813
|
+
observationError = error;
|
|
814
|
+
}
|
|
815
|
+
);
|
|
816
|
+
if (observationError) throw observationError;
|
|
817
|
+
await mkdir(captureDir, { recursive: true });
|
|
818
|
+
const captures = [
|
|
819
|
+
{
|
|
820
|
+
surface: "host",
|
|
821
|
+
fileName: "host-desktop.png",
|
|
822
|
+
viewport: DEFAULT_HOST_VIEWPORT,
|
|
823
|
+
page: session.host.page
|
|
824
|
+
},
|
|
825
|
+
{
|
|
826
|
+
surface: "controller",
|
|
827
|
+
fileName: "controller-phone.png",
|
|
828
|
+
viewport: DEFAULT_CONTROLLER_VIEWPORT,
|
|
829
|
+
page: controllerSession.page
|
|
830
|
+
}
|
|
831
|
+
];
|
|
832
|
+
for (const capture of captures) {
|
|
833
|
+
await capture.page.waitForTimeout(300);
|
|
834
|
+
const filePath = path2.join(captureDir, capture.fileName);
|
|
835
|
+
await capture.page.screenshot({ path: filePath });
|
|
836
|
+
response.screenshots.push({
|
|
837
|
+
surface: capture.surface,
|
|
838
|
+
width: capture.viewport.width,
|
|
839
|
+
height: capture.viewport.height,
|
|
840
|
+
relativePath: path2.relative(process.cwd(), filePath)
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
response.ok = true;
|
|
844
|
+
} catch (error) {
|
|
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
|
+
}
|
|
861
|
+
}
|
|
862
|
+
process.send?.(response);
|
|
863
|
+
})();
|
|
864
|
+
});
|
|
865
|
+
process.on("SIGTERM", () => {
|
|
866
|
+
void shutdown(0);
|
|
867
|
+
});
|
|
868
|
+
process.on("SIGINT", () => {
|
|
869
|
+
void shutdown(0);
|
|
870
|
+
});
|
|
871
|
+
process.once("disconnect", () => {
|
|
872
|
+
void shutdown(0);
|
|
873
|
+
});
|
|
874
|
+
var readInspection = async () => {
|
|
875
|
+
const rawValue = session.host.embedded ? await session.host.game.locator("body").evaluate(
|
|
876
|
+
(_, key) => window[key] ?? null,
|
|
877
|
+
AIR_JAM_RUNTIME_INSPECTION_KEY2
|
|
878
|
+
) : await session.host.page.evaluate(
|
|
879
|
+
(key) => window[key] ?? null,
|
|
880
|
+
AIR_JAM_RUNTIME_INSPECTION_KEY2
|
|
881
|
+
);
|
|
882
|
+
const inspection = readRuntimeInspectionContract({
|
|
883
|
+
[AIR_JAM_RUNTIME_INSPECTION_KEY2]: rawValue
|
|
884
|
+
});
|
|
885
|
+
return built && inspection?.role === "host" && inspection.joinUrlStatus === "ready" ? {
|
|
886
|
+
...inspection,
|
|
887
|
+
joinUrl: bindHarnessControllerUrl(
|
|
888
|
+
inspection.joinUrl,
|
|
889
|
+
built.urls.controllerBaseUrl
|
|
890
|
+
)
|
|
891
|
+
} : inspection;
|
|
892
|
+
};
|
|
893
|
+
try {
|
|
894
|
+
const startedAt = Date.now();
|
|
895
|
+
let inspection = null;
|
|
896
|
+
while (Date.now() - startedAt < timeoutMs) {
|
|
897
|
+
const nextInspection = await readInspection();
|
|
898
|
+
if (nextInspection?.role === "host" && nextInspection.joinUrlStatus === "ready") {
|
|
899
|
+
inspection = nextInspection;
|
|
900
|
+
break;
|
|
901
|
+
}
|
|
902
|
+
await session.host.page.waitForTimeout(250);
|
|
903
|
+
}
|
|
904
|
+
if (!inspection || inspection.role !== "host") {
|
|
905
|
+
throw new Error(
|
|
906
|
+
"Timed out waiting for a published host runtime inspection contract."
|
|
907
|
+
);
|
|
908
|
+
}
|
|
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.joinUrl,
|
|
923
|
+
inspection
|
|
924
|
+
});
|
|
925
|
+
await new Promise(() => {
|
|
926
|
+
});
|
|
927
|
+
} catch (error) {
|
|
928
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
929
|
+
await shutdown(1);
|
|
930
|
+
}
|
|
931
|
+
//# sourceMappingURL=hold-runtime-host.js.map
|