@air-jam/devtools 0.9.3 → 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/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-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-GUEZP773.js → chunk-O3XG3FNL.js} +204 -41
- 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 +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 +769 -67
- 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 +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.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 +72 -41
- 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 +255 -38
- 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 +326 -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
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One headless room: the Air Jam room server on a loopback port, which
|
|
3
|
+
* phones and agents join over the network, and the game's host core joined
|
|
4
|
+
* straight into its rooms over the loopback link, with no page and no
|
|
5
|
+
* drawing. The game's clock moves only when the owner advances it, so a test
|
|
6
|
+
* plays on game time, as fast as the host runs.
|
|
7
|
+
*/
|
|
8
|
+
import {
|
|
9
|
+
airJamInputLogSchema,
|
|
10
|
+
createAirJamConfig,
|
|
11
|
+
createConnectionStore,
|
|
12
|
+
replayAirJamInputLog,
|
|
13
|
+
type AirJamHostEnvironment,
|
|
14
|
+
} from "@air-jam/sdk/core";
|
|
15
|
+
import { AIRJAM_PRESENTATION_CHANNEL } from "@air-jam/sdk/room-protocol";
|
|
16
|
+
import {
|
|
17
|
+
createLoopbackConnector,
|
|
18
|
+
createRoomKey,
|
|
19
|
+
HostRoomSession,
|
|
20
|
+
} from "@air-jam/sdk/room-session";
|
|
21
|
+
import {
|
|
22
|
+
AIR_JAM_RUNTIME_CONTROL_KEY,
|
|
23
|
+
type HostRuntimeControl,
|
|
24
|
+
} from "@air-jam/sdk/runtime-control";
|
|
25
|
+
import {
|
|
26
|
+
resolveRuntimeTopology,
|
|
27
|
+
runtimeTopologyToQueryParams,
|
|
28
|
+
} from "@air-jam/sdk/runtime-topology";
|
|
29
|
+
import { loadServerEnv } from "@air-jam/server";
|
|
30
|
+
import { createRoomServer } from "@air-jam/server/room-server";
|
|
31
|
+
import { createHash } from "node:crypto";
|
|
32
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
33
|
+
import {
|
|
34
|
+
HEADLESS_ROOM_IPC_MAX_BYTES,
|
|
35
|
+
headlessRoomRequestSchema,
|
|
36
|
+
type HeadlessRoomResponse,
|
|
37
|
+
} from "../headless-room-protocol.js";
|
|
38
|
+
import { loadAirJamGame } from "./load-game.js";
|
|
39
|
+
|
|
40
|
+
const STARTUP_MS = 10_000;
|
|
41
|
+
|
|
42
|
+
type Room = {
|
|
43
|
+
agent: HostRuntimeControl["agent"];
|
|
44
|
+
/** Null for a replay, which has already played. */
|
|
45
|
+
advance: ((ms: number) => number) | null;
|
|
46
|
+
saveInputLog: ((path: string) => Promise<SavedInputLog>) | null;
|
|
47
|
+
close: () => Promise<void>;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
type SavedInputLog = {
|
|
51
|
+
sha256: string;
|
|
52
|
+
ticks: number;
|
|
53
|
+
stepMs: number;
|
|
54
|
+
entries: number;
|
|
55
|
+
full: boolean;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
let room: Room | undefined;
|
|
59
|
+
let initializing = false;
|
|
60
|
+
let busy = false;
|
|
61
|
+
|
|
62
|
+
function send(message: HeadlessRoomResponse) {
|
|
63
|
+
if (process.connected) process.send?.(message);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function openRoom(
|
|
67
|
+
configPath: string,
|
|
68
|
+
seed: number,
|
|
69
|
+
settings?: Record<string, string | number | boolean>,
|
|
70
|
+
) {
|
|
71
|
+
const app = await loadAirJamGame(configPath);
|
|
72
|
+
const server = createRoomServer({
|
|
73
|
+
host: "127.0.0.1",
|
|
74
|
+
port: 0,
|
|
75
|
+
envConfig: loadServerEnv({
|
|
76
|
+
NODE_ENV: "test",
|
|
77
|
+
AIR_JAM_AUTH_MODE: "disabled",
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
80
|
+
const origin = `http://127.0.0.1:${await server.start()}`;
|
|
81
|
+
const topology = (surfaceRole: "host" | "controller") =>
|
|
82
|
+
resolveRuntimeTopology({
|
|
83
|
+
runtimeMode: "self-hosted-production",
|
|
84
|
+
surfaceRole,
|
|
85
|
+
appOrigin: origin,
|
|
86
|
+
backendOrigin: origin,
|
|
87
|
+
socketOrigin: origin,
|
|
88
|
+
publicHost: origin,
|
|
89
|
+
embedded: false,
|
|
90
|
+
proxyStrategy: "none",
|
|
91
|
+
secureTransport: false,
|
|
92
|
+
});
|
|
93
|
+
const connector = createLoopbackConnector(server.rooms);
|
|
94
|
+
let nowMs = 0;
|
|
95
|
+
const controlTarget = {};
|
|
96
|
+
const environment: AirJamHostEnvironment = {
|
|
97
|
+
embedded: null,
|
|
98
|
+
requestedRoomId: null,
|
|
99
|
+
runMode: "standalone",
|
|
100
|
+
defaultStoreDomain: "default",
|
|
101
|
+
presentationChannel: AIRJAM_PRESENTATION_CHANNEL,
|
|
102
|
+
controlTarget,
|
|
103
|
+
openRoom: (options) =>
|
|
104
|
+
new HostRoomSession({
|
|
105
|
+
...options,
|
|
106
|
+
connector,
|
|
107
|
+
deviceWakeEvents: null,
|
|
108
|
+
heartbeat: null,
|
|
109
|
+
}),
|
|
110
|
+
createKey: createRoomKey,
|
|
111
|
+
readResume: () => null,
|
|
112
|
+
writeResume: () => {},
|
|
113
|
+
requestHostGrant: () =>
|
|
114
|
+
Promise.reject(new Error("A headless room runs without host grants.")),
|
|
115
|
+
controllerUrl: async (roomId) => {
|
|
116
|
+
const url = new URL(app.controllerPath, origin);
|
|
117
|
+
url.searchParams.set("room", roomId);
|
|
118
|
+
for (const [key, value] of Object.entries(
|
|
119
|
+
runtimeTopologyToQueryParams(topology("controller")),
|
|
120
|
+
))
|
|
121
|
+
url.searchParams.set(key, value);
|
|
122
|
+
return url.toString();
|
|
123
|
+
},
|
|
124
|
+
reportError: () => {},
|
|
125
|
+
emitDevEvent: () => {},
|
|
126
|
+
setDevLogContext: () => {},
|
|
127
|
+
seed: () => seed,
|
|
128
|
+
now: () => nowMs,
|
|
129
|
+
};
|
|
130
|
+
const store = createConnectionStore();
|
|
131
|
+
// The game's own SDK builds its host, so its stores and host share one runtime.
|
|
132
|
+
const runtime = app.createHostRuntime(
|
|
133
|
+
{
|
|
134
|
+
config: createAirJamConfig({
|
|
135
|
+
topology: topology("host"),
|
|
136
|
+
maxPlayers: app.metadata.maxPlayers,
|
|
137
|
+
}),
|
|
138
|
+
store,
|
|
139
|
+
environment,
|
|
140
|
+
},
|
|
141
|
+
// A game with a simulation keeps the input log that replays the run.
|
|
142
|
+
{ seed, settings },
|
|
143
|
+
);
|
|
144
|
+
const stop = runtime.start();
|
|
145
|
+
const close = async () => {
|
|
146
|
+
stop();
|
|
147
|
+
await server.stop();
|
|
148
|
+
};
|
|
149
|
+
try {
|
|
150
|
+
await runtime.ready;
|
|
151
|
+
const joined = await new Promise<{ roomId: string; joinUrl: string }>(
|
|
152
|
+
(resolve, reject) => {
|
|
153
|
+
const timer = setTimeout(
|
|
154
|
+
() =>
|
|
155
|
+
reject(new Error("room_startup_timeout: The host never joined.")),
|
|
156
|
+
STARTUP_MS,
|
|
157
|
+
);
|
|
158
|
+
const check = () => {
|
|
159
|
+
const state = store.getState();
|
|
160
|
+
if (
|
|
161
|
+
state.connectionStatus === "connected" &&
|
|
162
|
+
state.roomId &&
|
|
163
|
+
state.joinUrl
|
|
164
|
+
) {
|
|
165
|
+
clearTimeout(timer);
|
|
166
|
+
unsubscribe();
|
|
167
|
+
resolve({ roomId: state.roomId, joinUrl: state.joinUrl });
|
|
168
|
+
} else if (state.lastError) {
|
|
169
|
+
clearTimeout(timer);
|
|
170
|
+
unsubscribe();
|
|
171
|
+
reject(new Error(`room_unavailable: ${state.lastError}`));
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const unsubscribe = store.subscribe(check);
|
|
175
|
+
check();
|
|
176
|
+
},
|
|
177
|
+
);
|
|
178
|
+
room = {
|
|
179
|
+
agent: (request) => {
|
|
180
|
+
const control = Reflect.get(
|
|
181
|
+
controlTarget,
|
|
182
|
+
AIR_JAM_RUNTIME_CONTROL_KEY,
|
|
183
|
+
) as HostRuntimeControl | undefined;
|
|
184
|
+
if (!control)
|
|
185
|
+
throw new Error(
|
|
186
|
+
"room_unavailable: The game publishes nothing agents can read.",
|
|
187
|
+
);
|
|
188
|
+
return control.agent(request);
|
|
189
|
+
},
|
|
190
|
+
advance: (ms) => {
|
|
191
|
+
nowMs += ms;
|
|
192
|
+
runtime.simulation?.advance(ms);
|
|
193
|
+
return nowMs;
|
|
194
|
+
},
|
|
195
|
+
saveInputLog: app.simulation
|
|
196
|
+
? async (path) => {
|
|
197
|
+
const log = runtime.inputLog();
|
|
198
|
+
const source = `${JSON.stringify(log)}\n`;
|
|
199
|
+
await writeFile(path, source, { mode: 0o600 });
|
|
200
|
+
return {
|
|
201
|
+
sha256: createHash("sha256").update(source).digest("hex"),
|
|
202
|
+
ticks: log.ticks,
|
|
203
|
+
stepMs: log.stepMs,
|
|
204
|
+
entries: log.entries.length,
|
|
205
|
+
full: runtime.inputLogFull,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
: null,
|
|
209
|
+
close,
|
|
210
|
+
};
|
|
211
|
+
return {
|
|
212
|
+
gameId: app.metadata.slug,
|
|
213
|
+
roomId: joined.roomId,
|
|
214
|
+
controllerJoinUrl: joined.joinUrl,
|
|
215
|
+
nowMs,
|
|
216
|
+
recordsInputLog: Boolean(app.simulation),
|
|
217
|
+
};
|
|
218
|
+
} catch (error) {
|
|
219
|
+
await close();
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
async function replayRoom(configPath: string, logPath: string) {
|
|
225
|
+
const app = await loadAirJamGame(configPath);
|
|
226
|
+
const log = airJamInputLogSchema.parse(
|
|
227
|
+
JSON.parse(await readFile(logPath, "utf8")),
|
|
228
|
+
);
|
|
229
|
+
const replayed = await replayAirJamInputLog(app.createHostRuntime, log);
|
|
230
|
+
room = {
|
|
231
|
+
agent: replayed.agent,
|
|
232
|
+
advance: null,
|
|
233
|
+
saveInputLog: null,
|
|
234
|
+
close: async () => replayed.stop(),
|
|
235
|
+
};
|
|
236
|
+
return {
|
|
237
|
+
gameId: app.metadata.slug,
|
|
238
|
+
roomId: replayed.roomId,
|
|
239
|
+
ticks: log.ticks,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
process.on("disconnect", () => {
|
|
244
|
+
void (room?.close() ?? Promise.resolve()).finally(() => process.exit(0));
|
|
245
|
+
});
|
|
246
|
+
process.on("message", (message: unknown) => {
|
|
247
|
+
void (async () => {
|
|
248
|
+
if (
|
|
249
|
+
Buffer.byteLength(JSON.stringify(message)) > HEADLESS_ROOM_IPC_MAX_BYTES
|
|
250
|
+
)
|
|
251
|
+
throw new Error("Oversized headless room request.");
|
|
252
|
+
const request = headlessRoomRequestSchema.parse(message);
|
|
253
|
+
if (busy)
|
|
254
|
+
return send({ kind: "error", id: request.id, message: "room_busy" });
|
|
255
|
+
busy = true;
|
|
256
|
+
try {
|
|
257
|
+
if (request.kind === "initialize") {
|
|
258
|
+
if (room || initializing)
|
|
259
|
+
throw new Error("The headless room is already open.");
|
|
260
|
+
initializing = true;
|
|
261
|
+
send({
|
|
262
|
+
kind: "initialized",
|
|
263
|
+
id: request.id,
|
|
264
|
+
...(await openRoom(
|
|
265
|
+
request.configPath,
|
|
266
|
+
request.seed,
|
|
267
|
+
request.settings,
|
|
268
|
+
)),
|
|
269
|
+
});
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (request.kind === "replay") {
|
|
273
|
+
if (room || initializing)
|
|
274
|
+
throw new Error("The headless room is already open.");
|
|
275
|
+
initializing = true;
|
|
276
|
+
send({
|
|
277
|
+
kind: "replayed",
|
|
278
|
+
id: request.id,
|
|
279
|
+
...(await replayRoom(request.configPath, request.logPath)),
|
|
280
|
+
});
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
if (!room) throw new Error("The headless room is not open.");
|
|
284
|
+
if (request.kind === "agent")
|
|
285
|
+
send({
|
|
286
|
+
kind: "agent",
|
|
287
|
+
id: request.id,
|
|
288
|
+
response: await room.agent(request.request),
|
|
289
|
+
});
|
|
290
|
+
else if (request.kind === "saveInputLog") {
|
|
291
|
+
if (!room.saveInputLog)
|
|
292
|
+
throw new Error(
|
|
293
|
+
"no_input_log: This room keeps no input log; its game declares no simulation.",
|
|
294
|
+
);
|
|
295
|
+
send({
|
|
296
|
+
kind: "savedInputLog",
|
|
297
|
+
id: request.id,
|
|
298
|
+
...(await room.saveInputLog(request.path)),
|
|
299
|
+
});
|
|
300
|
+
} else {
|
|
301
|
+
if (!room.advance)
|
|
302
|
+
throw new Error("replay_finished: A replay has already played.");
|
|
303
|
+
send({
|
|
304
|
+
kind: "advanced",
|
|
305
|
+
id: request.id,
|
|
306
|
+
nowMs: room.advance(request.ms),
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
} catch (error) {
|
|
310
|
+
send({
|
|
311
|
+
kind: "error",
|
|
312
|
+
id: request.id,
|
|
313
|
+
message: (error instanceof Error ? error.message : String(error)).slice(
|
|
314
|
+
0,
|
|
315
|
+
2000,
|
|
316
|
+
),
|
|
317
|
+
});
|
|
318
|
+
} finally {
|
|
319
|
+
busy = false;
|
|
320
|
+
}
|
|
321
|
+
})().catch((error) => {
|
|
322
|
+
console.error(error);
|
|
323
|
+
process.exit(1);
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
send({ kind: "ready" });
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TEST_PROFILE_IPC_MAX_BYTES,
|
|
3
|
+
createPolicyRandom,
|
|
4
|
+
testProfileRequestSchema,
|
|
5
|
+
type TestProfileResponse,
|
|
6
|
+
} from "../test-profile-protocol.js";
|
|
7
|
+
import {
|
|
8
|
+
PLAY_RUN_PLAYER,
|
|
9
|
+
airJamPolicyDecisionSchema,
|
|
10
|
+
airJamScenarioVerdictSchema,
|
|
11
|
+
createAirJamPlayerPolicy,
|
|
12
|
+
describeAirJamTestProfiles,
|
|
13
|
+
policyPreparationSchema,
|
|
14
|
+
type AirJamRunReceipt,
|
|
15
|
+
type AirJamTestPolicy,
|
|
16
|
+
type AirJamTestProfile,
|
|
17
|
+
} from "../testing.js";
|
|
18
|
+
import { loadAirJamGame, loadAirJamTesting } from "./load-game.js";
|
|
19
|
+
|
|
20
|
+
let role: "discover" | "policy" | "evaluator" | undefined;
|
|
21
|
+
let busy = false;
|
|
22
|
+
let profile: AirJamTestProfile | undefined;
|
|
23
|
+
let evaluator: ReturnType<AirJamTestProfile["evaluator"]["create"]> | undefined;
|
|
24
|
+
let evaluationIndex = 0;
|
|
25
|
+
const policySequences = new Map<string, number>();
|
|
26
|
+
const policies = new Map<
|
|
27
|
+
string,
|
|
28
|
+
Awaited<ReturnType<AirJamTestPolicy["create"]>>
|
|
29
|
+
>();
|
|
30
|
+
function send(message: TestProfileResponse) {
|
|
31
|
+
if (process.connected) process.send?.(message);
|
|
32
|
+
}
|
|
33
|
+
function acceptReceipts(receipts: AirJamRunReceipt[], seatId?: string) {
|
|
34
|
+
let previous =
|
|
35
|
+
seatId === undefined ? evaluationIndex : (policySequences.get(seatId) ?? 0);
|
|
36
|
+
for (const receipt of receipts) {
|
|
37
|
+
const next = seatId === undefined ? receipt.index : receipt.sequence;
|
|
38
|
+
if (
|
|
39
|
+
next !== previous + 1 ||
|
|
40
|
+
(seatId !== undefined && receipt.seatId !== seatId)
|
|
41
|
+
)
|
|
42
|
+
throw new Error(
|
|
43
|
+
"receipt_protocol: Missing, repeated or misdirected effect receipt.",
|
|
44
|
+
);
|
|
45
|
+
previous = next;
|
|
46
|
+
}
|
|
47
|
+
if (seatId === undefined) evaluationIndex = previous;
|
|
48
|
+
else policySequences.set(seatId, previous);
|
|
49
|
+
}
|
|
50
|
+
process.on("disconnect", () => process.exit(0));
|
|
51
|
+
process.on("message", (message: unknown) => {
|
|
52
|
+
void (async () => {
|
|
53
|
+
if (Buffer.byteLength(JSON.stringify(message)) > TEST_PROFILE_IPC_MAX_BYTES)
|
|
54
|
+
throw new Error("Oversized test profile request.");
|
|
55
|
+
const request = testProfileRequestSchema.parse(message);
|
|
56
|
+
if (busy)
|
|
57
|
+
return send({ kind: "error", id: request.id, message: "policy_busy" });
|
|
58
|
+
busy = true;
|
|
59
|
+
try {
|
|
60
|
+
if (request.kind === "initialize") {
|
|
61
|
+
if (role !== undefined)
|
|
62
|
+
throw new Error("Test profile already initialized.");
|
|
63
|
+
const game = await loadAirJamGame(request.configPath);
|
|
64
|
+
const testing = await loadAirJamTesting(request.configPath, game);
|
|
65
|
+
if (!testing)
|
|
66
|
+
throw new Error(
|
|
67
|
+
request.runKind === "play"
|
|
68
|
+
? "This game has no player contract; it cannot seat a model player."
|
|
69
|
+
: "Game does not declare testing.",
|
|
70
|
+
);
|
|
71
|
+
const profiles = describeAirJamTestProfiles(testing.profiles);
|
|
72
|
+
const preparation = policyPreparationSchema.parse([]);
|
|
73
|
+
const artifacts = request.artifacts;
|
|
74
|
+
role = request.role;
|
|
75
|
+
if (role !== "policy" && artifacts !== undefined)
|
|
76
|
+
throw new Error(
|
|
77
|
+
"Only the policy process can receive model artifacts.",
|
|
78
|
+
);
|
|
79
|
+
if (request.runKind === "play") {
|
|
80
|
+
if (role !== "policy" || artifacts)
|
|
81
|
+
throw new Error("Play initializes only its player policy.");
|
|
82
|
+
if (!testing.player)
|
|
83
|
+
throw new Error(
|
|
84
|
+
"This game has no player contract; it cannot seat a model player.",
|
|
85
|
+
);
|
|
86
|
+
const started = performance.now();
|
|
87
|
+
const instance = await createAirJamPlayerPolicy(
|
|
88
|
+
testing.player,
|
|
89
|
+
).create({
|
|
90
|
+
seatId: PLAY_RUN_PLAYER.seats[0].id,
|
|
91
|
+
random: createPolicyRandom(request.seed),
|
|
92
|
+
});
|
|
93
|
+
policies.set(PLAY_RUN_PLAYER.seats[0].id, instance);
|
|
94
|
+
preparation.push({
|
|
95
|
+
seatId: PLAY_RUN_PLAYER.seats[0].id,
|
|
96
|
+
prepareMs: performance.now() - started,
|
|
97
|
+
});
|
|
98
|
+
} else if (role !== "discover") {
|
|
99
|
+
profile = testing.profiles[request.profileId ?? ""];
|
|
100
|
+
if (!profile) throw new Error("Unknown test profile.");
|
|
101
|
+
if (role === "policy") {
|
|
102
|
+
const policy = profile.policies[request.policyId ?? ""];
|
|
103
|
+
if (!policy) throw new Error("Unknown test policy.");
|
|
104
|
+
if (Boolean(policy.artifacts) !== Boolean(artifacts))
|
|
105
|
+
throw new Error(
|
|
106
|
+
"Policy artifacts must be verified by the run owner before initialization.",
|
|
107
|
+
);
|
|
108
|
+
for (const [index, seat] of profile.seats.entries()) {
|
|
109
|
+
const started = performance.now();
|
|
110
|
+
const instance = await policy.create({
|
|
111
|
+
seatId: seat.id,
|
|
112
|
+
random: createPolicyRandom(
|
|
113
|
+
(request.seed + Math.imul(index, 0x9e3779b9)) >>> 0,
|
|
114
|
+
),
|
|
115
|
+
...(artifacts ? { artifacts } : {}),
|
|
116
|
+
});
|
|
117
|
+
if (typeof instance.decide !== "function")
|
|
118
|
+
throw new Error("Policy must provide decide().");
|
|
119
|
+
preparation.push({
|
|
120
|
+
seatId: seat.id,
|
|
121
|
+
prepareMs: performance.now() - started,
|
|
122
|
+
});
|
|
123
|
+
policies.set(seat.id, instance);
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
evaluator = profile.evaluator.create({
|
|
127
|
+
seats: profile.seats.map((seat) => seat.id),
|
|
128
|
+
});
|
|
129
|
+
if (typeof evaluator.evaluate !== "function")
|
|
130
|
+
throw new Error("Scenario must provide evaluate().");
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
send({
|
|
134
|
+
kind: "initialized",
|
|
135
|
+
id: request.id,
|
|
136
|
+
profiles,
|
|
137
|
+
preparation,
|
|
138
|
+
});
|
|
139
|
+
} else if (request.kind === "decide") {
|
|
140
|
+
const policy = policies.get(request.step.seatId);
|
|
141
|
+
if (role !== "policy" || !policy)
|
|
142
|
+
throw new Error("Policy seat is not initialized.");
|
|
143
|
+
acceptReceipts(request.step.receipts, request.step.seatId);
|
|
144
|
+
const decision = airJamPolicyDecisionSchema.parse(
|
|
145
|
+
await policy.decide(request.step),
|
|
146
|
+
);
|
|
147
|
+
send({ kind: "decision", id: request.id, decision });
|
|
148
|
+
} else {
|
|
149
|
+
if (role !== "evaluator" || !evaluator || !profile)
|
|
150
|
+
throw new Error("Scenario evaluator is not initialized.");
|
|
151
|
+
const activeProfile = profile;
|
|
152
|
+
if (
|
|
153
|
+
request.sample.seats.length !== activeProfile.seats.length ||
|
|
154
|
+
request.sample.seats.some(
|
|
155
|
+
(seat, index) => seat.seatId !== activeProfile.seats[index].id,
|
|
156
|
+
)
|
|
157
|
+
)
|
|
158
|
+
throw new Error(
|
|
159
|
+
"Evaluation seat mapping does not match the scenario.",
|
|
160
|
+
);
|
|
161
|
+
acceptReceipts(request.sample.receipts);
|
|
162
|
+
const verdict = airJamScenarioVerdictSchema.parse(
|
|
163
|
+
evaluator.evaluate(request.sample),
|
|
164
|
+
);
|
|
165
|
+
if (
|
|
166
|
+
Object.keys(verdict.metrics ?? {}).some(
|
|
167
|
+
(id) => !activeProfile.metrics.some((metric) => metric.id === id),
|
|
168
|
+
)
|
|
169
|
+
)
|
|
170
|
+
throw new Error("Evaluator returned an undeclared metric.");
|
|
171
|
+
send({ kind: "evaluation", id: request.id, verdict });
|
|
172
|
+
}
|
|
173
|
+
} catch (error) {
|
|
174
|
+
send({
|
|
175
|
+
kind: "error",
|
|
176
|
+
id: request.id,
|
|
177
|
+
message: (error instanceof Error ? error.message : String(error)).slice(
|
|
178
|
+
0,
|
|
179
|
+
2000,
|
|
180
|
+
),
|
|
181
|
+
});
|
|
182
|
+
} finally {
|
|
183
|
+
busy = false;
|
|
184
|
+
}
|
|
185
|
+
})().catch((error) => {
|
|
186
|
+
console.error(error);
|
|
187
|
+
process.exit(1);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
send({ kind: "ready" });
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
closeGameSession,
|
|
3
|
-
invokeGameSessionAction,
|
|
4
|
-
openGameSession,
|
|
5
|
-
readGameSession,
|
|
6
|
-
} from "../game-session.js";
|
|
1
|
+
import { createGameSessionRuntime } from "../game-session-runtime.js";
|
|
7
2
|
import type {
|
|
8
3
|
AnyAirJamAgentContract,
|
|
9
4
|
VisualHarnessMode,
|
|
5
|
+
VisualHarnessPageSurface,
|
|
10
6
|
VisualScenarioAgent,
|
|
11
7
|
VisualScenarioAgentInvocation,
|
|
12
8
|
VisualScenarioPack,
|
|
13
9
|
} from "../harness/visual.js";
|
|
14
10
|
import { runVisualHarness } from "../harness/visual.js";
|
|
15
|
-
import {
|
|
11
|
+
import { evaluateOwnedGameContract } from "./runtime-owner-actions.js";
|
|
12
|
+
import { loadVisualScenarioPackFromConfig } from "./visual-pack.js";
|
|
16
13
|
|
|
17
14
|
const getFlagValue = (flag: string): string | null => {
|
|
18
15
|
const inline = process.argv.find((value) => value.startsWith(`${flag}=`));
|
|
@@ -24,7 +21,6 @@ const getFlagValue = (flag: string): string | null => {
|
|
|
24
21
|
return index === -1 ? null : (process.argv[index + 1] ?? null);
|
|
25
22
|
};
|
|
26
23
|
|
|
27
|
-
const modulePath = getFlagValue("--module-path");
|
|
28
24
|
const configPath = getFlagValue("--config");
|
|
29
25
|
const artifactRoot = getFlagValue("--artifact-root");
|
|
30
26
|
const hostUrl = getFlagValue("--host-url");
|
|
@@ -39,7 +35,7 @@ const gameId = getFlagValue("--game-id");
|
|
|
39
35
|
const secure = process.argv.includes("--secure");
|
|
40
36
|
|
|
41
37
|
if (
|
|
42
|
-
|
|
38
|
+
!configPath ||
|
|
43
39
|
!artifactRoot ||
|
|
44
40
|
!hostUrl ||
|
|
45
41
|
!appOrigin ||
|
|
@@ -48,14 +44,19 @@ if (
|
|
|
48
44
|
!gameId
|
|
49
45
|
) {
|
|
50
46
|
throw new Error(
|
|
51
|
-
"Missing required visual capture inputs. Expected game id,
|
|
47
|
+
"Missing required visual capture inputs. Expected game id, config path, artifact root, and resolved topology URLs.",
|
|
52
48
|
);
|
|
53
49
|
}
|
|
54
50
|
|
|
55
|
-
const scenarioPack = (await
|
|
56
|
-
modulePath,
|
|
51
|
+
const scenarioPack = (await loadVisualScenarioPackFromConfig(
|
|
57
52
|
configPath,
|
|
58
|
-
|
|
53
|
+
)) as VisualScenarioPack<AnyAirJamAgentContract>;
|
|
54
|
+
const {
|
|
55
|
+
closeGameSession,
|
|
56
|
+
invokeGameSessionAction,
|
|
57
|
+
openGameSession,
|
|
58
|
+
readGameSession,
|
|
59
|
+
} = createGameSessionRuntime();
|
|
59
60
|
const mode =
|
|
60
61
|
requestedMode === "arcade-test" ? "arcade-built" : "standalone-dev";
|
|
61
62
|
|
|
@@ -67,28 +68,35 @@ const asSnapshotRecord = (snapshot: unknown): Record<string, unknown> | null =>
|
|
|
67
68
|
const createScenarioAgentSession = async ({
|
|
68
69
|
gameId,
|
|
69
70
|
urls,
|
|
71
|
+
host,
|
|
70
72
|
mode,
|
|
71
73
|
secure,
|
|
72
74
|
}: {
|
|
73
75
|
gameId: string;
|
|
76
|
+
host: VisualHarnessPageSurface;
|
|
74
77
|
mode: VisualHarnessMode;
|
|
75
78
|
secure: boolean;
|
|
76
79
|
urls: {
|
|
77
80
|
controllerJoinUrl: string;
|
|
78
81
|
};
|
|
79
82
|
}): Promise<VisualScenarioAgent> => {
|
|
80
|
-
const opened = await openGameSession(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
const opened = await openGameSession(
|
|
84
|
+
{
|
|
85
|
+
cwd: process.cwd(),
|
|
86
|
+
gameId,
|
|
87
|
+
mode: mode === "arcade-built" ? "arcade-test" : "standalone-dev",
|
|
88
|
+
secure,
|
|
89
|
+
controllerJoinUrl: urls.controllerJoinUrl,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
access: "owned-host",
|
|
93
|
+
request: (request) => evaluateOwnedGameContract(host, request),
|
|
94
|
+
},
|
|
95
|
+
);
|
|
87
96
|
|
|
88
97
|
const read = async (): Promise<Record<string, unknown>> => {
|
|
89
98
|
const inspection = await readGameSession({
|
|
90
99
|
gameSessionId: opened.gameSessionId,
|
|
91
|
-
requestSync: true,
|
|
92
100
|
});
|
|
93
101
|
if (!inspection.gameSnapshot?.snapshot) {
|
|
94
102
|
throw new Error(
|
|
@@ -104,7 +112,6 @@ const createScenarioAgentSession = async ({
|
|
|
104
112
|
listActions: async () => {
|
|
105
113
|
const inspection = await readGameSession({
|
|
106
114
|
gameSessionId: opened.gameSessionId,
|
|
107
|
-
requestSync: true,
|
|
108
115
|
});
|
|
109
116
|
return inspection.actions;
|
|
110
117
|
},
|
|
@@ -187,9 +194,16 @@ try {
|
|
|
187
194
|
secure,
|
|
188
195
|
artifactRoot,
|
|
189
196
|
loadScenarioPack: async () => scenarioPack,
|
|
190
|
-
createAgentSession: async ({
|
|
197
|
+
createAgentSession: async ({
|
|
198
|
+
gameId: activeGameId,
|
|
199
|
+
urls,
|
|
200
|
+
host,
|
|
201
|
+
mode,
|
|
202
|
+
secure,
|
|
203
|
+
}) =>
|
|
191
204
|
createScenarioAgentSession({
|
|
192
205
|
gameId: activeGameId,
|
|
206
|
+
host,
|
|
193
207
|
urls,
|
|
194
208
|
mode,
|
|
195
209
|
secure,
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { AirJamActionInvocationResult } from "@air-jam/sdk";
|
|
2
2
|
import {
|
|
3
3
|
AIR_JAM_RUNTIME_CONTROL_KEY,
|
|
4
|
+
hostAgentResponseSchema,
|
|
5
|
+
type HostAgentRequest,
|
|
6
|
+
type HostAgentResponse,
|
|
4
7
|
type HostRuntimeActionRequest,
|
|
5
8
|
type HostRuntimeControl,
|
|
6
9
|
} from "@air-jam/sdk/runtime-control";
|
|
@@ -40,3 +43,23 @@ export const invokeOwnedHostAction = async (
|
|
|
40
43
|
};
|
|
41
44
|
}
|
|
42
45
|
};
|
|
46
|
+
|
|
47
|
+
export async function evaluateOwnedGameContract(
|
|
48
|
+
host: VisualHarnessPageSurface,
|
|
49
|
+
request: HostAgentRequest,
|
|
50
|
+
): Promise<HostAgentResponse> {
|
|
51
|
+
const result = await host.game.locator("body").evaluate(
|
|
52
|
+
async (_, { key, request }) => {
|
|
53
|
+
const control = (
|
|
54
|
+
window as unknown as Record<string, HostRuntimeControl | undefined>
|
|
55
|
+
)[key];
|
|
56
|
+
if (!control)
|
|
57
|
+
throw new Error(
|
|
58
|
+
"contract_runtime_unavailable: Owned game control is not mounted.",
|
|
59
|
+
);
|
|
60
|
+
return control.agent(request);
|
|
61
|
+
},
|
|
62
|
+
{ key: AIR_JAM_RUNTIME_CONTROL_KEY, request },
|
|
63
|
+
);
|
|
64
|
+
return hostAgentResponseSchema.parse(result);
|
|
65
|
+
}
|