@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
|
@@ -0,0 +1,1174 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AIR_JAM_RUNTIME_OWNER_ACTION_REQUEST,
|
|
3
|
+
AIR_JAM_RUNTIME_OWNER_CAPTURE_PORT,
|
|
4
|
+
AIR_JAM_RUNTIME_OWNER_CAPTURE_REQUEST,
|
|
5
|
+
isRuntimeOwnerActionResult,
|
|
6
|
+
isRuntimeOwnerCaptureResult,
|
|
7
|
+
runtimeOwnerAgentResultSchema,
|
|
8
|
+
runtimeOwnerCaptureFrameSchema,
|
|
9
|
+
runtimeOwnerWatchEventSchema
|
|
10
|
+
} from "./chunk-M6CJ7GQC.js";
|
|
11
|
+
import {
|
|
12
|
+
closeScopedProcess,
|
|
13
|
+
spawnScopedProcess
|
|
14
|
+
} from "./chunk-QGADSPHZ.js";
|
|
15
|
+
import {
|
|
16
|
+
getTopology
|
|
17
|
+
} from "./chunk-MEIMOSZC.js";
|
|
18
|
+
import {
|
|
19
|
+
detectProjectContext,
|
|
20
|
+
inspectGame
|
|
21
|
+
} from "./chunk-ART5TEYT.js";
|
|
22
|
+
import {
|
|
23
|
+
resolveDevtoolsHelperArgs,
|
|
24
|
+
resolveDevtoolsHelperScript,
|
|
25
|
+
resolveProjectDevtoolsHelperScript
|
|
26
|
+
} from "./chunk-PKD4WVX5.js";
|
|
27
|
+
|
|
28
|
+
// src/controller.ts
|
|
29
|
+
import {
|
|
30
|
+
AIR_JAM_ARCADE_SURFACE_STORE_DOMAIN,
|
|
31
|
+
arcadeSurfaceRuntimeIdentitySchema,
|
|
32
|
+
embeddedReplicatedStoreDomainFromArcadeIdentity,
|
|
33
|
+
localReferenceSourceGameId
|
|
34
|
+
} from "@air-jam/sdk/arcade/surface";
|
|
35
|
+
import {
|
|
36
|
+
agentValuesToInputState,
|
|
37
|
+
airJamActionResultOf
|
|
38
|
+
} from "@air-jam/sdk/core";
|
|
39
|
+
import {
|
|
40
|
+
controllerLeasedControlAckSchema,
|
|
41
|
+
leasedControlRequestSchema
|
|
42
|
+
} from "@air-jam/sdk/protocol";
|
|
43
|
+
import {
|
|
44
|
+
AIRJAM_CONTROL_CHANNEL,
|
|
45
|
+
AIRJAM_LEASED_CONTROL_REQUEST,
|
|
46
|
+
AIRJAM_PRESENTATION_CHANNEL,
|
|
47
|
+
encodeInputPayload,
|
|
48
|
+
encodePhoneInputFrame
|
|
49
|
+
} from "@air-jam/sdk/room-protocol";
|
|
50
|
+
import {
|
|
51
|
+
createRoomKey,
|
|
52
|
+
createScopedPhoneConnector,
|
|
53
|
+
createWebSocketConnector,
|
|
54
|
+
PhoneRoomSession,
|
|
55
|
+
serveRoomPort
|
|
56
|
+
} from "@air-jam/sdk/room-session";
|
|
57
|
+
import {
|
|
58
|
+
AIR_JAM_RUNTIME_INSPECTION_KEY,
|
|
59
|
+
readRuntimeInspectionContract
|
|
60
|
+
} from "@air-jam/sdk/runtime-inspection";
|
|
61
|
+
import { parseRuntimeTopologyFromSearchParams } from "@air-jam/sdk/runtime-topology";
|
|
62
|
+
import { randomUUID } from "crypto";
|
|
63
|
+
import { z } from "zod";
|
|
64
|
+
var DEFAULT_TIMEOUT_MS = 5e3;
|
|
65
|
+
var DEFAULT_VISUAL_CAPTURE_TIMEOUT_MS = 15e3;
|
|
66
|
+
var WAIT_INTERVAL_MS = 25;
|
|
67
|
+
var virtualControllerSessions = /* @__PURE__ */ new Map();
|
|
68
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
69
|
+
var toJsonObject = (value) => {
|
|
70
|
+
if (!isRecord(value)) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
return { ...value };
|
|
74
|
+
};
|
|
75
|
+
var nowIso = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
76
|
+
var waitForCondition = async ({
|
|
77
|
+
timeoutMs,
|
|
78
|
+
predicate
|
|
79
|
+
}) => {
|
|
80
|
+
const startedAt = Date.now();
|
|
81
|
+
while (!predicate()) {
|
|
82
|
+
if (Date.now() - startedAt >= timeoutMs) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
await new Promise((resolve) => setTimeout(resolve, WAIT_INTERVAL_MS));
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
var waitForWelcome = (room, timeoutMs) => new Promise((resolve, reject) => {
|
|
89
|
+
const settle = (status) => {
|
|
90
|
+
if (status.phase === "open") finish();
|
|
91
|
+
else if (status.phase === "closed")
|
|
92
|
+
finish(new Error(`Controller join was refused (${status.reason}).`));
|
|
93
|
+
};
|
|
94
|
+
const finish = (error) => {
|
|
95
|
+
clearTimeout(timer);
|
|
96
|
+
stop();
|
|
97
|
+
if (error) reject(error);
|
|
98
|
+
else resolve();
|
|
99
|
+
};
|
|
100
|
+
const timer = setTimeout(
|
|
101
|
+
() => finish(
|
|
102
|
+
new Error(
|
|
103
|
+
"Timed out waiting for the room to welcome the controller."
|
|
104
|
+
)
|
|
105
|
+
),
|
|
106
|
+
timeoutMs
|
|
107
|
+
);
|
|
108
|
+
const stop = room.on("status", settle);
|
|
109
|
+
settle(room.status);
|
|
110
|
+
});
|
|
111
|
+
var waitForChannel = async (room, channel, timeoutMs) => {
|
|
112
|
+
await waitForCondition({
|
|
113
|
+
timeoutMs,
|
|
114
|
+
predicate: () => room.channel(channel) !== void 0
|
|
115
|
+
});
|
|
116
|
+
return room.channel(channel) ?? null;
|
|
117
|
+
};
|
|
118
|
+
var requestOwnedHostAction = async ({
|
|
119
|
+
owner,
|
|
120
|
+
payload,
|
|
121
|
+
timeoutMs
|
|
122
|
+
}) => await new Promise((resolve) => {
|
|
123
|
+
const requestId = randomUUID();
|
|
124
|
+
const finish = (ack) => {
|
|
125
|
+
clearTimeout(timeout);
|
|
126
|
+
owner.off("message", onMessage);
|
|
127
|
+
owner.off("exit", onExit);
|
|
128
|
+
owner.off("disconnect", onExit);
|
|
129
|
+
owner.off("error", onError);
|
|
130
|
+
resolve(ack);
|
|
131
|
+
};
|
|
132
|
+
const onError = () => finish({
|
|
133
|
+
ok: false,
|
|
134
|
+
status: "rejected",
|
|
135
|
+
source: "client",
|
|
136
|
+
reason: "host_ack_missing",
|
|
137
|
+
message: "The owned host runtime disconnected before its acknowledgement was observed."
|
|
138
|
+
});
|
|
139
|
+
const onExit = () => onError();
|
|
140
|
+
const onMessage = (message) => {
|
|
141
|
+
if (isRuntimeOwnerActionResult(message) && message.requestId === requestId)
|
|
142
|
+
finish(message.acknowledgement);
|
|
143
|
+
};
|
|
144
|
+
const timeout = setTimeout(() => {
|
|
145
|
+
finish({
|
|
146
|
+
ok: false,
|
|
147
|
+
status: "rejected",
|
|
148
|
+
source: "client",
|
|
149
|
+
reason: "host_ack_timeout",
|
|
150
|
+
message: "Timed out waiting for the owned host action acknowledgement."
|
|
151
|
+
});
|
|
152
|
+
}, timeoutMs);
|
|
153
|
+
owner.on("message", onMessage);
|
|
154
|
+
owner.once("exit", onExit);
|
|
155
|
+
owner.once("disconnect", onExit);
|
|
156
|
+
owner.once("error", onError);
|
|
157
|
+
try {
|
|
158
|
+
owner.send(
|
|
159
|
+
{
|
|
160
|
+
type: AIR_JAM_RUNTIME_OWNER_ACTION_REQUEST,
|
|
161
|
+
requestId,
|
|
162
|
+
action: payload
|
|
163
|
+
},
|
|
164
|
+
(error) => {
|
|
165
|
+
if (error) onError();
|
|
166
|
+
}
|
|
167
|
+
);
|
|
168
|
+
} catch {
|
|
169
|
+
onError();
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
var parseJoinRoomId = (joinUrl) => {
|
|
173
|
+
const roomId = joinUrl.searchParams.get("room") ?? joinUrl.searchParams.get("aj_room");
|
|
174
|
+
return roomId?.trim().toUpperCase() || null;
|
|
175
|
+
};
|
|
176
|
+
var terminateIsolatedRuntimeOwner = closeScopedProcess;
|
|
177
|
+
var resolveSocketOriginFromTopology = async (options) => {
|
|
178
|
+
try {
|
|
179
|
+
const topology = await getTopology(options);
|
|
180
|
+
const preferredSurfaces = [
|
|
181
|
+
topology.surfaces.controller,
|
|
182
|
+
topology.surfaces.embeddedController,
|
|
183
|
+
topology.surfaces.platformController
|
|
184
|
+
];
|
|
185
|
+
for (const surface of preferredSurfaces) {
|
|
186
|
+
const objectSurface = toJsonObject(surface);
|
|
187
|
+
const socketOrigin = (typeof objectSurface?.socketOrigin === "string" ? objectSurface.socketOrigin : null) ?? (typeof objectSurface?.backendOrigin === "string" ? objectSurface.backendOrigin : null) ?? (typeof objectSurface?.appOrigin === "string" ? objectSurface.appOrigin : null);
|
|
188
|
+
if (socketOrigin) {
|
|
189
|
+
return socketOrigin;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
} catch {
|
|
193
|
+
}
|
|
194
|
+
return null;
|
|
195
|
+
};
|
|
196
|
+
var resolveControllerJoinUrlFromTopology = async ({
|
|
197
|
+
cwd,
|
|
198
|
+
gameId,
|
|
199
|
+
mode,
|
|
200
|
+
secure,
|
|
201
|
+
roomId
|
|
202
|
+
}) => {
|
|
203
|
+
if (!roomId) {
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
const topology = await getTopology({
|
|
207
|
+
cwd,
|
|
208
|
+
gameId,
|
|
209
|
+
mode,
|
|
210
|
+
secure
|
|
211
|
+
});
|
|
212
|
+
if (!topology.urls.controllerBaseUrl) {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
const joinUrl = new URL(topology.urls.controllerBaseUrl);
|
|
216
|
+
joinUrl.searchParams.set("room", roomId);
|
|
217
|
+
return joinUrl.toString();
|
|
218
|
+
};
|
|
219
|
+
var startIsolatedRuntimeOwner = async ({
|
|
220
|
+
cwd,
|
|
221
|
+
gameId,
|
|
222
|
+
mode,
|
|
223
|
+
secure,
|
|
224
|
+
timeoutMs,
|
|
225
|
+
build,
|
|
226
|
+
settings,
|
|
227
|
+
onScope
|
|
228
|
+
}) => {
|
|
229
|
+
const topology = build ? null : await getTopology({
|
|
230
|
+
cwd,
|
|
231
|
+
gameId,
|
|
232
|
+
mode,
|
|
233
|
+
secure
|
|
234
|
+
});
|
|
235
|
+
const appOrigin = topology?.urls.appOrigin;
|
|
236
|
+
const hostUrl = topology?.urls.hostUrl;
|
|
237
|
+
const controllerBaseUrl = topology?.urls.controllerBaseUrl;
|
|
238
|
+
const publicHost = topology?.urls.publicHost;
|
|
239
|
+
if (!build && (!appOrigin || !hostUrl || !controllerBaseUrl || !publicHost)) {
|
|
240
|
+
throw new Error(
|
|
241
|
+
"Unable to start an isolated runtime owner because the resolved topology is incomplete."
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
const helperFile = build ? resolveProjectDevtoolsHelperScript(build.rootDir, "hold-runtime-host.ts") : resolveDevtoolsHelperScript("hold-runtime-host.ts");
|
|
245
|
+
const args = [
|
|
246
|
+
...resolveDevtoolsHelperArgs(helperFile),
|
|
247
|
+
"--mode",
|
|
248
|
+
mode,
|
|
249
|
+
"--timeout-ms",
|
|
250
|
+
String(timeoutMs)
|
|
251
|
+
];
|
|
252
|
+
if (settings) args.push("--settings", JSON.stringify(settings));
|
|
253
|
+
if (build) args.push("--pinned-build", build.manifestPath);
|
|
254
|
+
else {
|
|
255
|
+
for (const [flag, value] of [
|
|
256
|
+
["--app-origin", appOrigin],
|
|
257
|
+
["--host-url", hostUrl],
|
|
258
|
+
["--controller-base-url", controllerBaseUrl],
|
|
259
|
+
["--public-host", publicHost],
|
|
260
|
+
["--local-build-url", topology?.urls.localBuildUrl],
|
|
261
|
+
["--browser-build-url", topology?.urls.browserBuildUrl]
|
|
262
|
+
])
|
|
263
|
+
if (value) args.push(flag, value);
|
|
264
|
+
}
|
|
265
|
+
const helperProcess = await spawnScopedProcess(args, {
|
|
266
|
+
cwd,
|
|
267
|
+
onScope
|
|
268
|
+
});
|
|
269
|
+
return await new Promise((resolve, reject) => {
|
|
270
|
+
let stderrBuffer = "";
|
|
271
|
+
let settled = false;
|
|
272
|
+
const timeout = setTimeout(() => {
|
|
273
|
+
cleanup();
|
|
274
|
+
void terminateIsolatedRuntimeOwner(helperProcess).finally(() => {
|
|
275
|
+
const stderrSummary = stderrBuffer.trim();
|
|
276
|
+
const stderrSuffix = stderrSummary ? ` Helper stderr: ${stderrSummary}` : "";
|
|
277
|
+
reject(
|
|
278
|
+
new Error(
|
|
279
|
+
"Timed out waiting for isolated runtime ownership. Another local game session may still own the isolated runtime lease, or no host page may be available to create a room. Run `pnpm exec airjam status` to inspect local dev processes; if the state looks stale, run `pnpm exec airjam reset local` and then reopen the host page." + stderrSuffix
|
|
280
|
+
)
|
|
281
|
+
);
|
|
282
|
+
});
|
|
283
|
+
}, timeoutMs);
|
|
284
|
+
const cleanup = () => {
|
|
285
|
+
clearTimeout(timeout);
|
|
286
|
+
helperProcess.off("message", onReady);
|
|
287
|
+
helperProcess.stderr?.off("data", onStderr);
|
|
288
|
+
helperProcess.off("exit", onExit);
|
|
289
|
+
helperProcess.off("error", onError);
|
|
290
|
+
};
|
|
291
|
+
const onReady = (message) => {
|
|
292
|
+
const result = z.object({
|
|
293
|
+
type: z.literal("air-jam-runtime-owner.ready/v1"),
|
|
294
|
+
roomId: z.string().nullable(),
|
|
295
|
+
controllerJoinUrl: z.string().nullable(),
|
|
296
|
+
inspection: z.unknown()
|
|
297
|
+
}).safeParse(message);
|
|
298
|
+
if (!result.success) return;
|
|
299
|
+
const inspection = readRuntimeInspectionContract({
|
|
300
|
+
[AIR_JAM_RUNTIME_INSPECTION_KEY]: result.data.inspection
|
|
301
|
+
});
|
|
302
|
+
if (inspection?.role !== "host") {
|
|
303
|
+
cleanup();
|
|
304
|
+
void terminateIsolatedRuntimeOwner(helperProcess).then(
|
|
305
|
+
() => reject(
|
|
306
|
+
new Error(
|
|
307
|
+
"Isolated runtime owner returned an invalid host inspection."
|
|
308
|
+
)
|
|
309
|
+
),
|
|
310
|
+
reject
|
|
311
|
+
);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
settled = true;
|
|
315
|
+
cleanup();
|
|
316
|
+
resolve({
|
|
317
|
+
process: helperProcess,
|
|
318
|
+
roomId: result.data.roomId,
|
|
319
|
+
controllerJoinUrl: result.data.controllerJoinUrl,
|
|
320
|
+
inspection
|
|
321
|
+
});
|
|
322
|
+
};
|
|
323
|
+
const onStderr = (chunk) => {
|
|
324
|
+
stderrBuffer = (stderrBuffer + chunk.toString()).slice(-262144);
|
|
325
|
+
};
|
|
326
|
+
const onError = (error) => {
|
|
327
|
+
if (settled) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
cleanup();
|
|
331
|
+
reject(error);
|
|
332
|
+
};
|
|
333
|
+
const onExit = (code, signal) => {
|
|
334
|
+
if (settled) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
cleanup();
|
|
338
|
+
reject(
|
|
339
|
+
new Error(
|
|
340
|
+
[
|
|
341
|
+
"Isolated runtime owner exited before producing a join URL.",
|
|
342
|
+
stderrBuffer.trim(),
|
|
343
|
+
`exit=${code ?? "null"} signal=${signal ?? "null"}`
|
|
344
|
+
].filter(Boolean).join("\n")
|
|
345
|
+
)
|
|
346
|
+
);
|
|
347
|
+
};
|
|
348
|
+
helperProcess.stdout?.resume();
|
|
349
|
+
helperProcess.on("message", onReady);
|
|
350
|
+
helperProcess.stderr?.on("data", onStderr);
|
|
351
|
+
helperProcess.once("error", onError);
|
|
352
|
+
helperProcess.once("exit", onExit);
|
|
353
|
+
});
|
|
354
|
+
};
|
|
355
|
+
function relayControllerObservation(session, owner, requestId, onError) {
|
|
356
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
357
|
+
const fromOwner = (message) => {
|
|
358
|
+
const frame = runtimeOwnerCaptureFrameSchema.safeParse(message);
|
|
359
|
+
if (!frame.success || frame.data.requestId !== requestId) return;
|
|
360
|
+
for (const listener of listeners)
|
|
361
|
+
listener({ data: frame.data.message });
|
|
362
|
+
};
|
|
363
|
+
const port = {
|
|
364
|
+
addEventListener: (_, listener) => listeners.add(listener),
|
|
365
|
+
removeEventListener: (_, listener) => listeners.delete(listener),
|
|
366
|
+
start: () => {
|
|
367
|
+
},
|
|
368
|
+
postMessage: (message) => owner.send(
|
|
369
|
+
{ type: AIR_JAM_RUNTIME_OWNER_CAPTURE_PORT, requestId, message },
|
|
370
|
+
(error) => {
|
|
371
|
+
if (error) onError(error);
|
|
372
|
+
}
|
|
373
|
+
)
|
|
374
|
+
};
|
|
375
|
+
const scoped = createScopedPhoneConnector(session.room, () => true);
|
|
376
|
+
const stopServing = serveRoomPort(port, (address, handlers) => {
|
|
377
|
+
const link = scoped.connector(address, handlers);
|
|
378
|
+
let greeted = false;
|
|
379
|
+
const readOnly = {
|
|
380
|
+
...link,
|
|
381
|
+
send: (data) => {
|
|
382
|
+
if (!greeted || data === "ping") link.send(data);
|
|
383
|
+
greeted = true;
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
return readOnly;
|
|
387
|
+
});
|
|
388
|
+
owner.on("message", fromOwner);
|
|
389
|
+
return {
|
|
390
|
+
close() {
|
|
391
|
+
stopServing();
|
|
392
|
+
scoped.close();
|
|
393
|
+
owner.off("message", fromOwner);
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
var captureControllerSessionVisuals = async ({
|
|
398
|
+
controllerSessionId,
|
|
399
|
+
relativeDir,
|
|
400
|
+
timeoutMs = DEFAULT_VISUAL_CAPTURE_TIMEOUT_MS
|
|
401
|
+
}) => {
|
|
402
|
+
const session = getRequiredSession(controllerSessionId);
|
|
403
|
+
const owner = session.isolatedRuntimeOwner;
|
|
404
|
+
if (!session.summary.connected)
|
|
405
|
+
throw new Error(
|
|
406
|
+
"The acting controller must be connected for visual capture."
|
|
407
|
+
);
|
|
408
|
+
if (!owner?.connected) {
|
|
409
|
+
throw new Error(
|
|
410
|
+
`Air Jam controller session "${controllerSessionId}" does not own a capturable host runtime. Capture from the first game session opened for the room.`
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
const requestId = randomUUID();
|
|
414
|
+
const result = await new Promise(
|
|
415
|
+
(resolve, reject) => {
|
|
416
|
+
const timeout = setTimeout(() => {
|
|
417
|
+
cleanup();
|
|
418
|
+
reject(new Error("Timed out waiting for runtime visual capture."));
|
|
419
|
+
}, timeoutMs);
|
|
420
|
+
const cleanup = () => {
|
|
421
|
+
clearTimeout(timeout);
|
|
422
|
+
relay.close();
|
|
423
|
+
stopFollowing();
|
|
424
|
+
owner.off("message", onMessage);
|
|
425
|
+
owner.off("error", onError);
|
|
426
|
+
owner.off("exit", onExit);
|
|
427
|
+
};
|
|
428
|
+
const onMessage = (message) => {
|
|
429
|
+
if (!isRuntimeOwnerCaptureResult(message) || message.requestId !== requestId) {
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
cleanup();
|
|
433
|
+
if (!message.ok) {
|
|
434
|
+
reject(new Error(message.error ?? "Runtime visual capture failed."));
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
resolve(message);
|
|
438
|
+
};
|
|
439
|
+
const onError = (error) => {
|
|
440
|
+
cleanup();
|
|
441
|
+
reject(error);
|
|
442
|
+
};
|
|
443
|
+
const stopFollowing = session.room.on("status", (status) => {
|
|
444
|
+
if (status.phase === "open") return;
|
|
445
|
+
cleanup();
|
|
446
|
+
reject(
|
|
447
|
+
new Error(
|
|
448
|
+
"Acting controller disconnected before visual capture completed."
|
|
449
|
+
)
|
|
450
|
+
);
|
|
451
|
+
});
|
|
452
|
+
const onExit = (code) => {
|
|
453
|
+
cleanup();
|
|
454
|
+
reject(
|
|
455
|
+
new Error(
|
|
456
|
+
`Runtime owner exited before visual capture completed (code ${code ?? "unknown"}).`
|
|
457
|
+
)
|
|
458
|
+
);
|
|
459
|
+
};
|
|
460
|
+
const relay = relayControllerObservation(
|
|
461
|
+
session,
|
|
462
|
+
owner,
|
|
463
|
+
requestId,
|
|
464
|
+
onError
|
|
465
|
+
);
|
|
466
|
+
owner.on("message", onMessage);
|
|
467
|
+
owner.once("error", onError);
|
|
468
|
+
owner.once("exit", onExit);
|
|
469
|
+
owner.send(
|
|
470
|
+
{
|
|
471
|
+
type: AIR_JAM_RUNTIME_OWNER_CAPTURE_REQUEST,
|
|
472
|
+
requestId,
|
|
473
|
+
relativeDir,
|
|
474
|
+
harnessSessionId: session.summary.controllerSessionId,
|
|
475
|
+
roomId: session.summary.roomId
|
|
476
|
+
},
|
|
477
|
+
(error) => {
|
|
478
|
+
if (error) onError(error);
|
|
479
|
+
}
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
);
|
|
483
|
+
return {
|
|
484
|
+
capturedAt: result.capturedAt,
|
|
485
|
+
screenshots: result.screenshots
|
|
486
|
+
};
|
|
487
|
+
};
|
|
488
|
+
var buildRuntimeSnapshot = ({
|
|
489
|
+
session,
|
|
490
|
+
requestedStoreDomains = [],
|
|
491
|
+
missingStoreDomains = []
|
|
492
|
+
}) => {
|
|
493
|
+
const room = session.room;
|
|
494
|
+
return {
|
|
495
|
+
...session.summary,
|
|
496
|
+
welcome: room.instance ? {
|
|
497
|
+
roomId: room.code,
|
|
498
|
+
instance: room.instance,
|
|
499
|
+
controllerId: room.seat
|
|
500
|
+
} : null,
|
|
501
|
+
controllerState: room.channel(AIRJAM_PRESENTATION_CHANNEL) ?? null,
|
|
502
|
+
players: room.seats.map((seat) => ({ ...seat })),
|
|
503
|
+
storeSnapshots: [...room.documents()].map(([storeDomain, data]) => ({
|
|
504
|
+
storeDomain,
|
|
505
|
+
data,
|
|
506
|
+
revision: session.storeUpdates.get(storeDomain)?.revision ?? 0,
|
|
507
|
+
updatedAt: session.storeUpdates.get(storeDomain)?.updatedAt ?? session.summary.connectedAt
|
|
508
|
+
})).sort((left, right) => left.storeDomain.localeCompare(right.storeDomain)),
|
|
509
|
+
lastSignal: session.lastSignal,
|
|
510
|
+
lastError: session.lastError,
|
|
511
|
+
requestedStoreDomains: [...requestedStoreDomains],
|
|
512
|
+
missingStoreDomains: [...missingStoreDomains]
|
|
513
|
+
};
|
|
514
|
+
};
|
|
515
|
+
var buildSessionSummary = (session) => ({
|
|
516
|
+
...session.summary
|
|
517
|
+
});
|
|
518
|
+
var ownsControllerSessionHost = (controllerSessionId) => {
|
|
519
|
+
const owner = getRequiredSession(controllerSessionId).isolatedRuntimeOwner;
|
|
520
|
+
return Boolean(owner?.connected && !owner.killed && owner.exitCode === null);
|
|
521
|
+
};
|
|
522
|
+
var getRequiredSession = (controllerSessionId) => {
|
|
523
|
+
const session = virtualControllerSessions.get(controllerSessionId);
|
|
524
|
+
if (!session) {
|
|
525
|
+
throw new Error(
|
|
526
|
+
`Unknown Air Jam controller session "${controllerSessionId}". Connect a controller first.`
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
return session;
|
|
530
|
+
};
|
|
531
|
+
var inspectControllerSessionContext = (controllerSessionId) => {
|
|
532
|
+
const session = getRequiredSession(controllerSessionId);
|
|
533
|
+
return {
|
|
534
|
+
cwd: session.cwd,
|
|
535
|
+
gameId: session.summary.gameId,
|
|
536
|
+
controllerId: session.summary.controllerId,
|
|
537
|
+
session: buildSessionSummary(session)
|
|
538
|
+
};
|
|
539
|
+
};
|
|
540
|
+
var resolveControllerSessionGameRuntime = async ({
|
|
541
|
+
controllerSessionId,
|
|
542
|
+
game,
|
|
543
|
+
timeoutMs = DEFAULT_TIMEOUT_MS
|
|
544
|
+
}) => {
|
|
545
|
+
const session = getRequiredSession(controllerSessionId);
|
|
546
|
+
const usesArcadeRuntime = session.summary.mode === "arcade-dev" || session.summary.mode === "arcade-test" || session.summary.topologyMode === "arcade-live" || session.summary.topologyMode === "arcade-built";
|
|
547
|
+
if (!usesArcadeRuntime) {
|
|
548
|
+
return {
|
|
549
|
+
gameId: session.summary.gameId,
|
|
550
|
+
defaultStoreDomain: "default"
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
const surfaceData = await waitForChannel(
|
|
554
|
+
session.room,
|
|
555
|
+
AIR_JAM_ARCADE_SURFACE_STORE_DOMAIN,
|
|
556
|
+
timeoutMs
|
|
557
|
+
);
|
|
558
|
+
const parsedSurface = arcadeSurfaceRuntimeIdentitySchema.safeParse({
|
|
559
|
+
epoch: surfaceData?.epoch,
|
|
560
|
+
kind: surfaceData?.kind,
|
|
561
|
+
gameId: surfaceData?.gameId
|
|
562
|
+
});
|
|
563
|
+
if (!parsedSurface.success) {
|
|
564
|
+
throw new Error(
|
|
565
|
+
`Arcade controller session "${controllerSessionId}" did not expose a valid "${AIR_JAM_ARCADE_SURFACE_STORE_DOMAIN}" snapshot.`
|
|
566
|
+
);
|
|
567
|
+
}
|
|
568
|
+
if (parsedSurface.data.kind !== "game" || !parsedSurface.data.gameId) {
|
|
569
|
+
session.summary.gameId = null;
|
|
570
|
+
throw new Error(
|
|
571
|
+
`Arcade controller session "${controllerSessionId}" does not currently have an active embedded game.`
|
|
572
|
+
);
|
|
573
|
+
}
|
|
574
|
+
const sourceGameId = session.projectMode === "standalone-game" ? (game ?? await inspectGame({ cwd: session.cwd })).id : localReferenceSourceGameId(parsedSurface.data.gameId) ?? parsedSurface.data.gameId;
|
|
575
|
+
session.summary.gameId = sourceGameId;
|
|
576
|
+
return {
|
|
577
|
+
gameId: sourceGameId,
|
|
578
|
+
defaultStoreDomain: embeddedReplicatedStoreDomainFromArcadeIdentity(
|
|
579
|
+
parsedSurface.data
|
|
580
|
+
)
|
|
581
|
+
};
|
|
582
|
+
};
|
|
583
|
+
var followRoom = (session) => {
|
|
584
|
+
const room = session.room;
|
|
585
|
+
room.on("status", (status) => {
|
|
586
|
+
session.summary.connected = status.phase === "open";
|
|
587
|
+
if (status.phase === "open") {
|
|
588
|
+
session.summary.controllerId = room.seat ?? session.summary.controllerId;
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
if (status.phase !== "closed") return;
|
|
592
|
+
session.summary.disconnectedAt = nowIso();
|
|
593
|
+
session.summary.disconnectReason = status.reason;
|
|
594
|
+
if (status.reason !== "owner" && status.reason !== "left")
|
|
595
|
+
session.lastError = { reason: status.reason };
|
|
596
|
+
void terminateIsolatedRuntimeOwner(session.isolatedRuntimeOwner).then(
|
|
597
|
+
() => {
|
|
598
|
+
session.isolatedRuntimeOwner = null;
|
|
599
|
+
},
|
|
600
|
+
(error) => console.error(error)
|
|
601
|
+
);
|
|
602
|
+
});
|
|
603
|
+
room.on("state", ({ channel }) => {
|
|
604
|
+
const previous = session.storeUpdates.get(channel)?.revision ?? 0;
|
|
605
|
+
session.storeUpdates.set(channel, {
|
|
606
|
+
revision: previous + 1,
|
|
607
|
+
updatedAt: nowIso()
|
|
608
|
+
});
|
|
609
|
+
});
|
|
610
|
+
room.on("signal", (signal) => {
|
|
611
|
+
session.lastSignal = {
|
|
612
|
+
kind: signal.kind,
|
|
613
|
+
payload: signal.payload
|
|
614
|
+
};
|
|
615
|
+
});
|
|
616
|
+
};
|
|
617
|
+
var connectController = async ({
|
|
618
|
+
cwd = process.cwd(),
|
|
619
|
+
gameId,
|
|
620
|
+
mode = "standalone-dev",
|
|
621
|
+
secure = false,
|
|
622
|
+
roomId,
|
|
623
|
+
controllerJoinUrl,
|
|
624
|
+
nickname,
|
|
625
|
+
avatarId,
|
|
626
|
+
timeoutMs = DEFAULT_TIMEOUT_MS
|
|
627
|
+
} = {}, {
|
|
628
|
+
build,
|
|
629
|
+
onScope,
|
|
630
|
+
settings
|
|
631
|
+
} = {}) => {
|
|
632
|
+
const context = await detectProjectContext({ cwd });
|
|
633
|
+
const normalizedRequestedRoomId = roomId?.trim().toUpperCase() || void 0;
|
|
634
|
+
const canUseIsolatedOwner = !normalizedRequestedRoomId && !controllerJoinUrl && (Boolean(gameId) || context.mode === "standalone-game");
|
|
635
|
+
const connectWithJoinUrl = async ({
|
|
636
|
+
joinUrlString,
|
|
637
|
+
ownedRuntimeProcess
|
|
638
|
+
}) => {
|
|
639
|
+
const joinUrl = new URL(joinUrlString);
|
|
640
|
+
const resolvedRoomId = normalizedRequestedRoomId ?? parseJoinRoomId(joinUrl);
|
|
641
|
+
if (!resolvedRoomId) {
|
|
642
|
+
throw new Error(
|
|
643
|
+
`Controller join URL "${joinUrlString}" does not include a room code.`
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
const topology = controllerJoinUrl ? null : await getTopology({ cwd, gameId, mode, secure }).catch(() => null);
|
|
647
|
+
const resolvedGameId = gameId ?? topology?.gameId ?? null;
|
|
648
|
+
const resolvedSocketOrigin = parseRuntimeTopologyFromSearchParams(joinUrl.searchParams)?.socketOrigin ?? (controllerJoinUrl ? joinUrl.origin : await resolveSocketOriginFromTopology({
|
|
649
|
+
cwd,
|
|
650
|
+
gameId: resolvedGameId ?? void 0,
|
|
651
|
+
mode,
|
|
652
|
+
secure
|
|
653
|
+
}) ?? joinUrl.origin);
|
|
654
|
+
const controllerSessionId = randomUUID();
|
|
655
|
+
const label = nickname?.trim().slice(0, 24);
|
|
656
|
+
const avatar = avatarId?.trim();
|
|
657
|
+
const room = new PhoneRoomSession({
|
|
658
|
+
connector: createWebSocketConnector(resolvedSocketOrigin),
|
|
659
|
+
key: createRoomKey(),
|
|
660
|
+
code: resolvedRoomId,
|
|
661
|
+
kind: "agent",
|
|
662
|
+
deviceWakeEvents: null,
|
|
663
|
+
...label || avatar ? {
|
|
664
|
+
profile: {
|
|
665
|
+
...label ? { label } : {},
|
|
666
|
+
...avatar ? { avatarId: avatar } : {}
|
|
667
|
+
}
|
|
668
|
+
} : {}
|
|
669
|
+
});
|
|
670
|
+
const internalSession = {
|
|
671
|
+
cwd,
|
|
672
|
+
summary: {
|
|
673
|
+
controllerSessionId,
|
|
674
|
+
gameId: resolvedGameId,
|
|
675
|
+
projectMode: context.mode,
|
|
676
|
+
mode,
|
|
677
|
+
topologyMode: build ? "self-hosted-production" : topology?.topologyMode ?? null,
|
|
678
|
+
secure,
|
|
679
|
+
process: topology?.process ?? null,
|
|
680
|
+
roomId: resolvedRoomId,
|
|
681
|
+
controllerId: "",
|
|
682
|
+
controllerJoinUrl: joinUrlString,
|
|
683
|
+
socketOrigin: resolvedSocketOrigin,
|
|
684
|
+
connected: false,
|
|
685
|
+
connectedAt: nowIso(),
|
|
686
|
+
disconnectedAt: null,
|
|
687
|
+
disconnectReason: null
|
|
688
|
+
},
|
|
689
|
+
room,
|
|
690
|
+
projectMode: context.mode,
|
|
691
|
+
storeUpdates: /* @__PURE__ */ new Map(),
|
|
692
|
+
lastSignal: null,
|
|
693
|
+
lastError: null,
|
|
694
|
+
isolatedRuntimeOwner: ownedRuntimeProcess,
|
|
695
|
+
participantLeaseId: null,
|
|
696
|
+
participantLastCommand: null,
|
|
697
|
+
inputState: null,
|
|
698
|
+
inputLayout: void 0
|
|
699
|
+
};
|
|
700
|
+
followRoom(internalSession);
|
|
701
|
+
try {
|
|
702
|
+
await waitForWelcome(room, timeoutMs);
|
|
703
|
+
await waitForChannel(
|
|
704
|
+
room,
|
|
705
|
+
AIRJAM_PRESENTATION_CHANNEL,
|
|
706
|
+
Math.min(timeoutMs, 500)
|
|
707
|
+
);
|
|
708
|
+
virtualControllerSessions.set(controllerSessionId, internalSession);
|
|
709
|
+
return buildRuntimeSnapshot({ session: internalSession });
|
|
710
|
+
} catch (error) {
|
|
711
|
+
room.close();
|
|
712
|
+
await terminateIsolatedRuntimeOwner(ownedRuntimeProcess);
|
|
713
|
+
throw error;
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
const resolvedJoinUrl = build ? null : controllerJoinUrl ?? await resolveControllerJoinUrlFromTopology({
|
|
717
|
+
cwd,
|
|
718
|
+
gameId,
|
|
719
|
+
mode,
|
|
720
|
+
secure,
|
|
721
|
+
roomId: normalizedRequestedRoomId
|
|
722
|
+
});
|
|
723
|
+
if (!resolvedJoinUrl) {
|
|
724
|
+
if (!canUseIsolatedOwner) {
|
|
725
|
+
throw new Error(
|
|
726
|
+
"Unable to resolve a controller join URL. Open the host page first so a room exists, or provide roomId/controllerJoinUrl explicitly. If a stale dev process may be holding the local runtime, run `pnpm exec airjam status` and then `pnpm exec airjam reset local`."
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
const owner = await startIsolatedRuntimeOwner({
|
|
730
|
+
cwd,
|
|
731
|
+
gameId,
|
|
732
|
+
mode,
|
|
733
|
+
secure,
|
|
734
|
+
timeoutMs,
|
|
735
|
+
build,
|
|
736
|
+
settings,
|
|
737
|
+
onScope
|
|
738
|
+
});
|
|
739
|
+
if (!owner.controllerJoinUrl) {
|
|
740
|
+
await terminateIsolatedRuntimeOwner(owner.process);
|
|
741
|
+
throw new Error(
|
|
742
|
+
"Isolated runtime owner did not produce a controller join URL."
|
|
743
|
+
);
|
|
744
|
+
}
|
|
745
|
+
return connectWithJoinUrl({
|
|
746
|
+
joinUrlString: owner.controllerJoinUrl,
|
|
747
|
+
ownedRuntimeProcess: owner.process
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
return connectWithJoinUrl({
|
|
751
|
+
joinUrlString: resolvedJoinUrl,
|
|
752
|
+
ownedRuntimeProcess: null
|
|
753
|
+
});
|
|
754
|
+
};
|
|
755
|
+
var sendControllerInput = async ({
|
|
756
|
+
controllerSessionId,
|
|
757
|
+
input
|
|
758
|
+
}) => {
|
|
759
|
+
const session = getRequiredSession(controllerSessionId);
|
|
760
|
+
if (!session.summary.connected) {
|
|
761
|
+
throw new Error(
|
|
762
|
+
`Air Jam controller session "${controllerSessionId}" is not connected.`
|
|
763
|
+
);
|
|
764
|
+
}
|
|
765
|
+
if (session.participantLeaseId)
|
|
766
|
+
throw new Error(
|
|
767
|
+
"participant_control_leased: Use the leased control path for this player."
|
|
768
|
+
);
|
|
769
|
+
session.inputLayout ??= await inspectGame({
|
|
770
|
+
cwd: session.cwd,
|
|
771
|
+
...session.summary.gameId ? { gameId: session.summary.gameId } : {}
|
|
772
|
+
}).then(
|
|
773
|
+
(game) => game.declaration.input,
|
|
774
|
+
() => null
|
|
775
|
+
) ?? null;
|
|
776
|
+
const layout = session.inputLayout;
|
|
777
|
+
if (!layout)
|
|
778
|
+
throw new Error(
|
|
779
|
+
"input_unavailable: This controller's game declares no controls it can read."
|
|
780
|
+
);
|
|
781
|
+
const payload = {
|
|
782
|
+
...session.inputState,
|
|
783
|
+
...agentValuesToInputState(session.inputState, input)
|
|
784
|
+
};
|
|
785
|
+
session.inputState = payload;
|
|
786
|
+
session.room.sendInputFrame(
|
|
787
|
+
encodePhoneInputFrame(encodeInputPayload(layout, payload))
|
|
788
|
+
);
|
|
789
|
+
return {
|
|
790
|
+
...buildSessionSummary(session),
|
|
791
|
+
input: payload,
|
|
792
|
+
sentAt: nowIso()
|
|
793
|
+
};
|
|
794
|
+
};
|
|
795
|
+
async function controlControllerParticipant({
|
|
796
|
+
controllerSessionId,
|
|
797
|
+
...input
|
|
798
|
+
}) {
|
|
799
|
+
const session = getRequiredSession(controllerSessionId);
|
|
800
|
+
const request = leasedControlRequestSchema.parse(input);
|
|
801
|
+
if (!session.summary.connected)
|
|
802
|
+
return { status: "rejected", reason: "unauthorized" };
|
|
803
|
+
if (session.participantLeaseId && session.participantLeaseId !== request.lease.id)
|
|
804
|
+
return { status: "rejected", reason: "lease_conflict" };
|
|
805
|
+
session.participantLeaseId = request.lease.id;
|
|
806
|
+
if (!session.participantLastCommand || request.lease.sequence > session.participantLastCommand.lease.sequence)
|
|
807
|
+
session.participantLastCommand = request;
|
|
808
|
+
const outcome = await session.room.request(
|
|
809
|
+
AIRJAM_CONTROL_CHANNEL,
|
|
810
|
+
AIRJAM_LEASED_CONTROL_REQUEST,
|
|
811
|
+
request,
|
|
812
|
+
{ exclusive: true, timeoutMs: 2e3 }
|
|
813
|
+
);
|
|
814
|
+
if (outcome.status === "busy") return { status: "rejected", reason: "busy" };
|
|
815
|
+
if (outcome.status === "refused")
|
|
816
|
+
return { status: "rejected", reason: "active_host_missing" };
|
|
817
|
+
if (outcome.status === "unconfirmed")
|
|
818
|
+
return { status: "unconfirmed", reason: "transport_ack_unavailable" };
|
|
819
|
+
const parsed = controllerLeasedControlAckSchema.safeParse(outcome.result);
|
|
820
|
+
if (!parsed.success || parsed.data.status === "applied" && (parsed.data.leaseId !== request.lease.id || parsed.data.sequence !== request.lease.sequence || parsed.data.operation.kind !== request.operation.kind))
|
|
821
|
+
return { status: "unconfirmed", reason: "invalid_acknowledgement" };
|
|
822
|
+
return parsed.data;
|
|
823
|
+
}
|
|
824
|
+
var invokeControllerAction = async ({
|
|
825
|
+
controllerSessionId,
|
|
826
|
+
actionName,
|
|
827
|
+
storeDomain,
|
|
828
|
+
payload,
|
|
829
|
+
timeoutMs = DEFAULT_TIMEOUT_MS
|
|
830
|
+
}) => {
|
|
831
|
+
const session = getRequiredSession(controllerSessionId);
|
|
832
|
+
if (!session.summary.connected) {
|
|
833
|
+
throw new Error(
|
|
834
|
+
`Air Jam controller session "${controllerSessionId}" is not connected.`
|
|
835
|
+
);
|
|
836
|
+
}
|
|
837
|
+
if (session.participantLeaseId)
|
|
838
|
+
throw new Error(
|
|
839
|
+
"participant_control_leased: Use the leased control path for this player."
|
|
840
|
+
);
|
|
841
|
+
const normalizedPayload = payload ? { ...payload } : void 0;
|
|
842
|
+
const acknowledgement = airJamActionResultOf(
|
|
843
|
+
await session.room.request(storeDomain, actionName, normalizedPayload, {
|
|
844
|
+
timeoutMs
|
|
845
|
+
})
|
|
846
|
+
);
|
|
847
|
+
return {
|
|
848
|
+
...buildSessionSummary(session),
|
|
849
|
+
actionName,
|
|
850
|
+
storeDomain,
|
|
851
|
+
...normalizedPayload ? { payload: normalizedPayload } : {},
|
|
852
|
+
sentAt: nowIso(),
|
|
853
|
+
acknowledgement
|
|
854
|
+
};
|
|
855
|
+
};
|
|
856
|
+
var invokeHostAction = async ({
|
|
857
|
+
controllerSessionId,
|
|
858
|
+
actionName,
|
|
859
|
+
storeDomain,
|
|
860
|
+
payload,
|
|
861
|
+
timeoutMs = DEFAULT_TIMEOUT_MS
|
|
862
|
+
}) => {
|
|
863
|
+
const session = getRequiredSession(controllerSessionId);
|
|
864
|
+
if (!session.summary.connected) {
|
|
865
|
+
throw new Error(
|
|
866
|
+
`Air Jam controller session "${controllerSessionId}" is not connected.`
|
|
867
|
+
);
|
|
868
|
+
}
|
|
869
|
+
const normalizedPayload = payload ? { ...payload } : void 0;
|
|
870
|
+
const owner = session.isolatedRuntimeOwner;
|
|
871
|
+
const acknowledgement = owner && ownsControllerSessionHost(controllerSessionId) ? await requestOwnedHostAction({
|
|
872
|
+
owner,
|
|
873
|
+
payload: {
|
|
874
|
+
roomId: session.summary.roomId,
|
|
875
|
+
actionName,
|
|
876
|
+
payload: normalizedPayload,
|
|
877
|
+
storeDomain
|
|
878
|
+
},
|
|
879
|
+
timeoutMs
|
|
880
|
+
}) : {
|
|
881
|
+
ok: false,
|
|
882
|
+
status: "rejected",
|
|
883
|
+
source: "client",
|
|
884
|
+
reason: "host_runtime_not_owned",
|
|
885
|
+
message: "Host actions require an owned host runtime; room attachments provide player participation only."
|
|
886
|
+
};
|
|
887
|
+
return {
|
|
888
|
+
...buildSessionSummary(session),
|
|
889
|
+
actionName,
|
|
890
|
+
storeDomain,
|
|
891
|
+
...normalizedPayload ? { payload: normalizedPayload } : {},
|
|
892
|
+
sentAt: nowIso(),
|
|
893
|
+
acknowledgement
|
|
894
|
+
};
|
|
895
|
+
};
|
|
896
|
+
var readRuntimeSnapshot = async ({
|
|
897
|
+
controllerSessionId,
|
|
898
|
+
storeDomains = [],
|
|
899
|
+
requestSync = storeDomains.length > 0,
|
|
900
|
+
timeoutMs = DEFAULT_TIMEOUT_MS
|
|
901
|
+
}) => {
|
|
902
|
+
const session = getRequiredSession(controllerSessionId);
|
|
903
|
+
const normalizedStoreDomains = Array.from(
|
|
904
|
+
new Set(
|
|
905
|
+
storeDomains.map((entry) => entry.trim()).filter((entry) => entry.length > 0)
|
|
906
|
+
)
|
|
907
|
+
);
|
|
908
|
+
const missingStoreDomains = [];
|
|
909
|
+
if (requestSync && normalizedStoreDomains.length > 0) {
|
|
910
|
+
const syncResults = await Promise.all(
|
|
911
|
+
normalizedStoreDomains.map(async (storeDomain) => ({
|
|
912
|
+
storeDomain,
|
|
913
|
+
ok: await waitForChannel(session.room, storeDomain, timeoutMs) !== null
|
|
914
|
+
}))
|
|
915
|
+
);
|
|
916
|
+
for (const result of syncResults) {
|
|
917
|
+
if (!result.ok) {
|
|
918
|
+
missingStoreDomains.push(result.storeDomain);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
return buildRuntimeSnapshot({
|
|
923
|
+
session,
|
|
924
|
+
requestedStoreDomains: normalizedStoreDomains,
|
|
925
|
+
missingStoreDomains
|
|
926
|
+
});
|
|
927
|
+
};
|
|
928
|
+
async function disposeControllerSession(session) {
|
|
929
|
+
const owner = session.isolatedRuntimeOwner;
|
|
930
|
+
session.room.close();
|
|
931
|
+
session.summary.connected = false;
|
|
932
|
+
session.summary.disconnectedAt ??= nowIso();
|
|
933
|
+
session.summary.disconnectReason ??= "manual_disconnect";
|
|
934
|
+
await terminateIsolatedRuntimeOwner(owner);
|
|
935
|
+
session.isolatedRuntimeOwner = null;
|
|
936
|
+
virtualControllerSessions.delete(session.summary.controllerSessionId);
|
|
937
|
+
}
|
|
938
|
+
async function forceDisconnectController({
|
|
939
|
+
controllerSessionId
|
|
940
|
+
}) {
|
|
941
|
+
const session = getRequiredSession(controllerSessionId);
|
|
942
|
+
await disposeControllerSession(session);
|
|
943
|
+
return {
|
|
944
|
+
disconnected: true,
|
|
945
|
+
release: { status: "unconfirmed", reason: "runtime_unavailable" },
|
|
946
|
+
leave: {
|
|
947
|
+
status: "unconfirmed",
|
|
948
|
+
message: "Forced local transport/runtime teardown; server leave was not confirmed."
|
|
949
|
+
},
|
|
950
|
+
session: buildSessionSummary(session)
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
var disconnectController = async ({
|
|
954
|
+
controllerSessionId
|
|
955
|
+
}) => {
|
|
956
|
+
const session = getRequiredSession(controllerSessionId);
|
|
957
|
+
const last = session.participantLastCommand;
|
|
958
|
+
const release = last ? last.lease.sequence === Number.MAX_SAFE_INTEGER ? { status: "rejected", reason: "invalid_request" } : await controlControllerParticipant({
|
|
959
|
+
controllerSessionId,
|
|
960
|
+
expected: last.expected,
|
|
961
|
+
lease: { id: last.lease.id, sequence: last.lease.sequence + 1 },
|
|
962
|
+
operation: { kind: "release" }
|
|
963
|
+
}) : { status: "not-leased" };
|
|
964
|
+
let leave = { status: "not-connected" };
|
|
965
|
+
if (session.summary.connected) {
|
|
966
|
+
session.room.leave();
|
|
967
|
+
await waitForCondition({
|
|
968
|
+
timeoutMs: DEFAULT_TIMEOUT_MS,
|
|
969
|
+
predicate: () => session.room.status.phase === "closed"
|
|
970
|
+
});
|
|
971
|
+
const status = session.room.status;
|
|
972
|
+
leave = status.phase === "closed" && status.reason === "left" ? { status: "acknowledged" } : {
|
|
973
|
+
status: "unconfirmed",
|
|
974
|
+
message: "The room did not confirm the seat was given up."
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
await disposeControllerSession(session);
|
|
978
|
+
return {
|
|
979
|
+
disconnected: true,
|
|
980
|
+
leave,
|
|
981
|
+
release,
|
|
982
|
+
session: buildSessionSummary(session)
|
|
983
|
+
};
|
|
984
|
+
};
|
|
985
|
+
async function requestControllerHostAgent(controllerSessionId, request, timeoutMs, signal) {
|
|
986
|
+
const owner = getRequiredSession(controllerSessionId).isolatedRuntimeOwner;
|
|
987
|
+
if (!owner || !ownsControllerSessionHost(controllerSessionId))
|
|
988
|
+
throw new Error(
|
|
989
|
+
"contract_runtime_not_owned: Semantic testing requires an owned host. Open a game session without an explicit room or join URL."
|
|
990
|
+
);
|
|
991
|
+
return new Promise((resolve, reject) => {
|
|
992
|
+
const requestId = randomUUID();
|
|
993
|
+
let settled = false;
|
|
994
|
+
const finish = (error, result) => {
|
|
995
|
+
if (settled) return;
|
|
996
|
+
settled = true;
|
|
997
|
+
clearTimeout(timer);
|
|
998
|
+
owner.off("message", onMessage);
|
|
999
|
+
owner.off("error", onError);
|
|
1000
|
+
owner.off("exit", onExit);
|
|
1001
|
+
owner.off("disconnect", onExit);
|
|
1002
|
+
signal?.removeEventListener("abort", onAbort);
|
|
1003
|
+
if (error) reject(error);
|
|
1004
|
+
else if (result) resolve(result);
|
|
1005
|
+
};
|
|
1006
|
+
const onMessage = (message) => {
|
|
1007
|
+
if (!message || typeof message !== "object" || !("type" in message) || message.type !== "air-jam-runtime-owner.agent-result/v1" || !("requestId" in message) || message.requestId !== requestId)
|
|
1008
|
+
return;
|
|
1009
|
+
const parsed = runtimeOwnerAgentResultSchema.safeParse(message);
|
|
1010
|
+
if (!parsed.success) {
|
|
1011
|
+
finish(
|
|
1012
|
+
new Error(
|
|
1013
|
+
"invalid_runtime_response: Owned host returned an invalid agent response."
|
|
1014
|
+
)
|
|
1015
|
+
);
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
1018
|
+
if (parsed.data.ok) finish(void 0, parsed.data.result);
|
|
1019
|
+
else finish(new Error(parsed.data.error));
|
|
1020
|
+
};
|
|
1021
|
+
const onError = (error) => finish(error);
|
|
1022
|
+
const onExit = () => finish(
|
|
1023
|
+
new Error("runtime_disconnected: Owned host exited during evaluation.")
|
|
1024
|
+
);
|
|
1025
|
+
const onAbort = () => finish(new Error("session_closed: Evaluation was cancelled."));
|
|
1026
|
+
const timer = setTimeout(
|
|
1027
|
+
() => finish(
|
|
1028
|
+
new Error("evaluation_timeout: Owned game evaluation timed out.")
|
|
1029
|
+
),
|
|
1030
|
+
timeoutMs
|
|
1031
|
+
);
|
|
1032
|
+
owner.on("message", onMessage);
|
|
1033
|
+
owner.once("error", onError);
|
|
1034
|
+
owner.once("exit", onExit);
|
|
1035
|
+
owner.once("disconnect", onExit);
|
|
1036
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1037
|
+
if (signal?.aborted) {
|
|
1038
|
+
onAbort();
|
|
1039
|
+
return;
|
|
1040
|
+
}
|
|
1041
|
+
try {
|
|
1042
|
+
owner.send(
|
|
1043
|
+
{ type: "air-jam-runtime-owner.agent/v1", requestId, request },
|
|
1044
|
+
(error) => {
|
|
1045
|
+
if (error) onError(error);
|
|
1046
|
+
}
|
|
1047
|
+
);
|
|
1048
|
+
} catch (error) {
|
|
1049
|
+
onError(error instanceof Error ? error : new Error(String(error)));
|
|
1050
|
+
}
|
|
1051
|
+
});
|
|
1052
|
+
}
|
|
1053
|
+
async function watchControllerSessionVisuals({
|
|
1054
|
+
ownerControllerSessionId,
|
|
1055
|
+
controllerSessionId,
|
|
1056
|
+
onEvent,
|
|
1057
|
+
signal
|
|
1058
|
+
}) {
|
|
1059
|
+
signal.throwIfAborted();
|
|
1060
|
+
const session = getRequiredSession(ownerControllerSessionId);
|
|
1061
|
+
const owner = session.isolatedRuntimeOwner;
|
|
1062
|
+
if (!owner?.connected)
|
|
1063
|
+
throw new Error("Run watch requires its owned host runtime.");
|
|
1064
|
+
const target = controllerSessionId ? getRequiredSession(controllerSessionId) : void 0;
|
|
1065
|
+
if (target && (!target.summary.connected || target.summary.roomId !== session.summary.roomId))
|
|
1066
|
+
throw new Error("Run watch controller is not connected to the owned room.");
|
|
1067
|
+
const watchId = randomUUID();
|
|
1068
|
+
await new Promise((resolve, reject) => {
|
|
1069
|
+
let stopping = false;
|
|
1070
|
+
let failed;
|
|
1071
|
+
const cleanup = () => {
|
|
1072
|
+
clearTimeout(timeout);
|
|
1073
|
+
owner.off("message", message);
|
|
1074
|
+
owner.off("error", error);
|
|
1075
|
+
owner.off("exit", exit);
|
|
1076
|
+
signal.removeEventListener("abort", stop);
|
|
1077
|
+
relay?.close();
|
|
1078
|
+
};
|
|
1079
|
+
const settle = (failure) => {
|
|
1080
|
+
cleanup();
|
|
1081
|
+
if (failure) reject(failure);
|
|
1082
|
+
else resolve();
|
|
1083
|
+
};
|
|
1084
|
+
let timeout = setTimeout(
|
|
1085
|
+
() => error(new Error("Timed out starting the game watch.")),
|
|
1086
|
+
DEFAULT_VISUAL_CAPTURE_TIMEOUT_MS
|
|
1087
|
+
);
|
|
1088
|
+
const stop = () => {
|
|
1089
|
+
if (stopping) return;
|
|
1090
|
+
stopping = true;
|
|
1091
|
+
clearTimeout(timeout);
|
|
1092
|
+
timeout = setTimeout(
|
|
1093
|
+
() => settle(new Error("Timed out closing the game watch.")),
|
|
1094
|
+
DEFAULT_VISUAL_CAPTURE_TIMEOUT_MS
|
|
1095
|
+
);
|
|
1096
|
+
owner.send(
|
|
1097
|
+
{ type: "air-jam-runtime-owner.watch-stop/v1", watchId },
|
|
1098
|
+
(failure) => {
|
|
1099
|
+
if (failure) settle(failure);
|
|
1100
|
+
}
|
|
1101
|
+
);
|
|
1102
|
+
};
|
|
1103
|
+
const error = (failure) => {
|
|
1104
|
+
failed ??= failure;
|
|
1105
|
+
stop();
|
|
1106
|
+
};
|
|
1107
|
+
const exit = () => settle(new Error("Game watch owner exited before its stream closed."));
|
|
1108
|
+
const message = (value) => {
|
|
1109
|
+
const parsed = runtimeOwnerWatchEventSchema.safeParse(value);
|
|
1110
|
+
if (!parsed.success || parsed.data.watchId !== watchId) return;
|
|
1111
|
+
const event = parsed.data.event;
|
|
1112
|
+
if (event.type === "closed") {
|
|
1113
|
+
settle(failed);
|
|
1114
|
+
return;
|
|
1115
|
+
}
|
|
1116
|
+
if (event.type === "error") {
|
|
1117
|
+
if (stopping) {
|
|
1118
|
+
settle(new Error(event.message));
|
|
1119
|
+
return;
|
|
1120
|
+
}
|
|
1121
|
+
error(new Error(event.message));
|
|
1122
|
+
return;
|
|
1123
|
+
}
|
|
1124
|
+
if (stopping) return;
|
|
1125
|
+
if (event.type === "ready") clearTimeout(timeout);
|
|
1126
|
+
try {
|
|
1127
|
+
onEvent(event);
|
|
1128
|
+
} catch (failure) {
|
|
1129
|
+
error(failure instanceof Error ? failure : new Error(String(failure)));
|
|
1130
|
+
}
|
|
1131
|
+
};
|
|
1132
|
+
const relay = target ? relayControllerObservation(target, owner, watchId, error) : void 0;
|
|
1133
|
+
owner.on("message", message);
|
|
1134
|
+
owner.once("error", error);
|
|
1135
|
+
owner.once("exit", exit);
|
|
1136
|
+
signal.addEventListener("abort", stop, { once: true });
|
|
1137
|
+
if (signal.aborted) {
|
|
1138
|
+
stop();
|
|
1139
|
+
return;
|
|
1140
|
+
}
|
|
1141
|
+
owner.send(
|
|
1142
|
+
{
|
|
1143
|
+
type: "air-jam-runtime-owner.watch/v1",
|
|
1144
|
+
watchId,
|
|
1145
|
+
surface: target ? "controller" : "host",
|
|
1146
|
+
...target ? {
|
|
1147
|
+
harnessSessionId: target.summary.controllerSessionId,
|
|
1148
|
+
roomId: target.summary.roomId
|
|
1149
|
+
} : {}
|
|
1150
|
+
},
|
|
1151
|
+
(failure) => {
|
|
1152
|
+
if (failure) error(failure);
|
|
1153
|
+
}
|
|
1154
|
+
);
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
export {
|
|
1159
|
+
captureControllerSessionVisuals,
|
|
1160
|
+
ownsControllerSessionHost,
|
|
1161
|
+
inspectControllerSessionContext,
|
|
1162
|
+
resolveControllerSessionGameRuntime,
|
|
1163
|
+
connectController,
|
|
1164
|
+
sendControllerInput,
|
|
1165
|
+
controlControllerParticipant,
|
|
1166
|
+
invokeControllerAction,
|
|
1167
|
+
invokeHostAction,
|
|
1168
|
+
readRuntimeSnapshot,
|
|
1169
|
+
forceDisconnectController,
|
|
1170
|
+
disconnectController,
|
|
1171
|
+
requestControllerHostAgent,
|
|
1172
|
+
watchControllerSessionVisuals
|
|
1173
|
+
};
|
|
1174
|
+
//# sourceMappingURL=chunk-JSI5S4WP.js.map
|