@air-jam/devtools 0.0.0-stage → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +52 -2
- package/dist/agent.d.ts +15 -0
- package/dist/agent.js +19 -0
- package/dist/agent.js.map +1 -0
- package/dist/chunk-5YAARMW5.js +36 -0
- package/dist/chunk-5YAARMW5.js.map +1 -0
- package/dist/chunk-6WQODT37.js +1019 -0
- package/dist/chunk-6WQODT37.js.map +1 -0
- package/dist/chunk-CKFT2ZJE.js +801 -0
- package/dist/chunk-CKFT2ZJE.js.map +1 -0
- package/dist/chunk-ER3Q2C4G.js +358 -0
- package/dist/chunk-ER3Q2C4G.js.map +1 -0
- package/dist/chunk-GUEZP773.js +851 -0
- package/dist/chunk-GUEZP773.js.map +1 -0
- package/dist/chunk-HIDNI56E.js +33 -0
- package/dist/chunk-HIDNI56E.js.map +1 -0
- package/dist/chunk-QKXS5D35.js +43 -0
- package/dist/chunk-QKXS5D35.js.map +1 -0
- package/dist/chunk-S4LSCEVE.js +261 -0
- package/dist/chunk-S4LSCEVE.js.map +1 -0
- package/dist/chunk-VKMJO6VN.js +360 -0
- package/dist/chunk-VKMJO6VN.js.map +1 -0
- package/dist/chunk-WFUR3MXY.js +67 -0
- package/dist/chunk-WFUR3MXY.js.map +1 -0
- package/dist/chunk-XEMR7KUE.js +361 -0
- package/dist/chunk-XEMR7KUE.js.map +1 -0
- package/dist/chunk-ZLPD7FY5.js +191 -0
- package/dist/chunk-ZLPD7FY5.js.map +1 -0
- package/dist/context.d.ts +13 -0
- package/dist/context.js +9 -0
- package/dist/context.js.map +1 -0
- package/dist/controller.d.ts +41 -0
- package/dist/controller.js +30 -0
- package/dist/controller.js.map +1 -0
- package/dist/dev.d.ts +15 -0
- package/dist/dev.js +20 -0
- package/dist/dev.js.map +1 -0
- package/dist/game-session-broker.d.ts +57 -0
- package/dist/game-session-broker.js +235 -0
- package/dist/game-session-broker.js.map +1 -0
- package/dist/game-session.d.ts +13 -0
- package/dist/game-session.js +24 -0
- package/dist/game-session.js.map +1 -0
- package/dist/games.d.ts +21 -0
- package/dist/games.js +14 -0
- package/dist/games.js.map +1 -0
- package/dist/harness/visual.d.ts +321 -0
- package/dist/harness/visual.js +41 -0
- package/dist/harness/visual.js.map +1 -0
- package/dist/logs.d.ts +9 -0
- package/dist/logs.js +58 -0
- package/dist/logs.js.map +1 -0
- package/dist/mcp-config.d.ts +63 -0
- package/dist/mcp-config.js +190 -0
- package/dist/mcp-config.js.map +1 -0
- package/dist/platform-auth.d.ts +112 -0
- package/dist/platform-auth.js +37 -0
- package/dist/platform-auth.js.map +1 -0
- package/dist/platform-game-media.d.ts +309 -0
- package/dist/platform-game-media.js +168 -0
- package/dist/platform-game-media.js.map +1 -0
- package/dist/platform-games.d.ts +65 -0
- package/dist/platform-games.js +251 -0
- package/dist/platform-games.js.map +1 -0
- package/dist/quality.d.ts +10 -0
- package/dist/quality.js +63 -0
- package/dist/quality.js.map +1 -0
- package/dist/release.d.ts +1094 -0
- package/dist/release.js +1347 -0
- package/dist/release.js.map +1 -0
- package/dist/tooling/agent-contract.d.ts +2 -0
- package/dist/tooling/agent-contract.js +193 -0
- package/dist/tooling/agent-contract.js.map +1 -0
- package/dist/tooling/hold-runtime-host.d.ts +2 -0
- package/dist/tooling/hold-runtime-host.js +229 -0
- package/dist/tooling/hold-runtime-host.js.map +1 -0
- package/dist/tooling/inspect-airjam-agent.d.ts +2 -0
- package/dist/tooling/inspect-airjam-agent.js +37 -0
- package/dist/tooling/inspect-airjam-agent.js.map +1 -0
- package/dist/tooling/list-visual-scenarios.d.ts +2 -0
- package/dist/tooling/list-visual-scenarios.js +62 -0
- package/dist/tooling/list-visual-scenarios.js.map +1 -0
- package/dist/tooling/managed-dev-supervisor.d.ts +2 -0
- package/dist/tooling/managed-dev-supervisor.js +51 -0
- package/dist/tooling/managed-dev-supervisor.js.map +1 -0
- package/dist/tooling/run-visual-capture.d.ts +2 -0
- package/dist/tooling/run-visual-capture.js +167 -0
- package/dist/tooling/run-visual-capture.js.map +1 -0
- package/dist/types-C6NrHt88.d.ts +775 -0
- package/dist/visual.d.ts +15 -0
- package/dist/visual.js +263 -0
- package/dist/visual.js.map +1 -0
- package/package.json +113 -3
- package/src/agent.ts +380 -0
- package/src/commands.ts +40 -0
- package/src/context.ts +229 -0
- package/src/controller.ts +1376 -0
- package/src/dev.ts +999 -0
- package/src/fs-utils.ts +93 -0
- package/src/game-action-observation.ts +96 -0
- package/src/game-session-broker.ts +301 -0
- package/src/game-session.ts +459 -0
- package/src/games.ts +266 -0
- package/src/harness/visual/prefab-contract.ts +29 -0
- package/src/harness/visual/prefab-runner.ts +178 -0
- package/src/harness/visual/runner.ts +546 -0
- package/src/harness/visual/scenario-contract.ts +9 -0
- package/src/harness/visual/scenario-helpers.ts +63 -0
- package/src/harness/visual/session.ts +369 -0
- package/src/harness/visual/types.ts +181 -0
- package/src/harness/visual.ts +7 -0
- package/src/helper-scripts.ts +49 -0
- package/src/logs.ts +67 -0
- package/src/mcp-config.ts +262 -0
- package/src/platform-auth.ts +455 -0
- package/src/platform-game-media.ts +209 -0
- package/src/platform-games.ts +315 -0
- package/src/quality.ts +82 -0
- package/src/release.ts +1697 -0
- package/src/runtime-owner-protocol.ts +130 -0
- package/src/tooling/agent-contract.ts +232 -0
- package/src/tooling/agent-declaration.ts +36 -0
- package/src/tooling/airjam-agent-inspection.ts +45 -0
- package/src/tooling/airjam-agent.ts +118 -0
- package/src/tooling/hold-runtime-host.ts +224 -0
- package/src/tooling/inspect-airjam-agent.ts +20 -0
- package/src/tooling/list-visual-scenarios.ts +64 -0
- package/src/tooling/managed-dev-supervisor.ts +71 -0
- package/src/tooling/run-visual-capture.ts +217 -0
- package/src/tooling/runtime-owner-actions.ts +42 -0
- package/src/tooling/visual-pack.ts +46 -0
- package/src/types.ts +951 -0
- package/src/visual.ts +304 -0
- package/src/workspace-contract.ts +32 -0
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AIR_JAM_RUNTIME_INSPECTION_KEY,
|
|
3
|
+
readRuntimeInspectionContract,
|
|
4
|
+
} from "@air-jam/sdk/runtime-inspection";
|
|
5
|
+
import {
|
|
6
|
+
chromium,
|
|
7
|
+
type Browser,
|
|
8
|
+
type BrowserContext,
|
|
9
|
+
type Frame,
|
|
10
|
+
type FrameLocator,
|
|
11
|
+
type Page,
|
|
12
|
+
} from "playwright-core";
|
|
13
|
+
import type {
|
|
14
|
+
VisualHarnessMode,
|
|
15
|
+
VisualHarnessPageSurface,
|
|
16
|
+
VisualHarnessUrls,
|
|
17
|
+
VisualQuerySurface,
|
|
18
|
+
VisualViewport,
|
|
19
|
+
} from "./types.js";
|
|
20
|
+
|
|
21
|
+
export const DEFAULT_HOST_VIEWPORT: VisualViewport = {
|
|
22
|
+
width: 1440,
|
|
23
|
+
height: 1024,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const DEFAULT_CONTROLLER_VIEWPORT: VisualViewport = {
|
|
27
|
+
width: 390,
|
|
28
|
+
height: 844,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const isEmbeddedMode = (mode: VisualHarnessMode): boolean =>
|
|
32
|
+
mode !== "standalone-dev";
|
|
33
|
+
|
|
34
|
+
export const dismissHarnessControllerFullscreenPrompt = async (
|
|
35
|
+
page: Page,
|
|
36
|
+
): Promise<boolean> => {
|
|
37
|
+
const openPrompt = page.locator(
|
|
38
|
+
'[data-testid="controller-fullscreen-prompt"][data-state="open"]',
|
|
39
|
+
);
|
|
40
|
+
await openPrompt
|
|
41
|
+
.waitFor({ state: "visible", timeout: 5_000 })
|
|
42
|
+
.catch(() => null);
|
|
43
|
+
|
|
44
|
+
if (!(await openPrompt.isVisible().catch(() => false))) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
await page
|
|
49
|
+
.getByTestId("controller-fullscreen-prompt-dismiss")
|
|
50
|
+
.click({ force: true });
|
|
51
|
+
await openPrompt.waitFor({ state: "hidden", timeout: 10_000 });
|
|
52
|
+
return true;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const waitForFrameToLoad = async ({
|
|
56
|
+
page,
|
|
57
|
+
testId,
|
|
58
|
+
timeoutMs = 30_000,
|
|
59
|
+
}: {
|
|
60
|
+
page: Page;
|
|
61
|
+
testId: string;
|
|
62
|
+
timeoutMs?: number;
|
|
63
|
+
}): Promise<FrameLocator> => {
|
|
64
|
+
const iframe = page.getByTestId(testId);
|
|
65
|
+
await iframe.waitFor({ state: "visible", timeout: timeoutMs });
|
|
66
|
+
const iframeHandle = await iframe.elementHandle({ timeout: timeoutMs });
|
|
67
|
+
if (!iframeHandle) {
|
|
68
|
+
throw new Error(`Could not resolve iframe handle for "${testId}".`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const startedAt = Date.now();
|
|
72
|
+
let resolvedFrame: Frame | null = null;
|
|
73
|
+
|
|
74
|
+
while (Date.now() - startedAt < timeoutMs) {
|
|
75
|
+
const nextFrame = await iframeHandle.contentFrame();
|
|
76
|
+
const frameUrl = nextFrame?.url() ?? "";
|
|
77
|
+
if (nextFrame && frameUrl.length > 0 && frameUrl !== "about:blank") {
|
|
78
|
+
resolvedFrame = nextFrame;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
await page.waitForTimeout(100);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (!resolvedFrame) {
|
|
85
|
+
throw new Error(`Timed out waiting for iframe "${testId}" to resolve.`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
await resolvedFrame.waitForLoadState("domcontentloaded", {
|
|
89
|
+
timeout: Math.max(1, timeoutMs - (Date.now() - startedAt)),
|
|
90
|
+
});
|
|
91
|
+
return page.frameLocator(`iframe[data-testid="${testId}"]`);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const readRuntimeHref = async ({
|
|
95
|
+
page,
|
|
96
|
+
game,
|
|
97
|
+
embedded,
|
|
98
|
+
}: {
|
|
99
|
+
page: Page;
|
|
100
|
+
game: VisualQuerySurface;
|
|
101
|
+
embedded: boolean;
|
|
102
|
+
}): Promise<string> =>
|
|
103
|
+
embedded
|
|
104
|
+
? game.locator("body").evaluate(() => window.location.href)
|
|
105
|
+
: page.evaluate(() => window.location.href);
|
|
106
|
+
|
|
107
|
+
const readHostRuntimeInspection = async ({
|
|
108
|
+
page,
|
|
109
|
+
game,
|
|
110
|
+
embedded,
|
|
111
|
+
}: {
|
|
112
|
+
page: Page;
|
|
113
|
+
game: VisualQuerySurface;
|
|
114
|
+
embedded: boolean;
|
|
115
|
+
}) => {
|
|
116
|
+
const rawInspection = embedded
|
|
117
|
+
? await game
|
|
118
|
+
.locator("body")
|
|
119
|
+
.evaluate(
|
|
120
|
+
(_, key) =>
|
|
121
|
+
(window as unknown as Record<string, unknown>)[key] ?? null,
|
|
122
|
+
AIR_JAM_RUNTIME_INSPECTION_KEY,
|
|
123
|
+
)
|
|
124
|
+
: await page.evaluate(
|
|
125
|
+
(key) => (window as unknown as Record<string, unknown>)[key] ?? null,
|
|
126
|
+
AIR_JAM_RUNTIME_INSPECTION_KEY,
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const inspection = readRuntimeInspectionContract({
|
|
130
|
+
[AIR_JAM_RUNTIME_INSPECTION_KEY]: rawInspection,
|
|
131
|
+
});
|
|
132
|
+
return inspection?.role === "host" ? inspection : null;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const resolveControllerJoinUrl = async ({
|
|
136
|
+
hostPage,
|
|
137
|
+
hostGame,
|
|
138
|
+
hostEmbedded,
|
|
139
|
+
controllerBaseUrl,
|
|
140
|
+
}: {
|
|
141
|
+
hostPage: Page;
|
|
142
|
+
hostGame: VisualQuerySurface;
|
|
143
|
+
hostEmbedded: boolean;
|
|
144
|
+
controllerBaseUrl: string;
|
|
145
|
+
}): Promise<string> => {
|
|
146
|
+
let resolvedJoinUrl: string | null = null;
|
|
147
|
+
|
|
148
|
+
for (let attempt = 0; attempt < 80; attempt += 1) {
|
|
149
|
+
const inspection = await readHostRuntimeInspection({
|
|
150
|
+
page: hostPage,
|
|
151
|
+
game: hostGame,
|
|
152
|
+
embedded: hostEmbedded,
|
|
153
|
+
});
|
|
154
|
+
if (inspection?.joinUrlStatus === "ready" && inspection.joinUrl) {
|
|
155
|
+
resolvedJoinUrl = inspection.joinUrl;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (!resolvedJoinUrl) {
|
|
159
|
+
const runtimeUrl = new URL(
|
|
160
|
+
await readRuntimeHref({
|
|
161
|
+
page: hostPage,
|
|
162
|
+
game: hostGame,
|
|
163
|
+
embedded: hostEmbedded,
|
|
164
|
+
}),
|
|
165
|
+
);
|
|
166
|
+
resolvedJoinUrl = runtimeUrl.searchParams.get("aj_join_url");
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (resolvedJoinUrl) {
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
await hostPage.waitForTimeout(250);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (!resolvedJoinUrl) {
|
|
176
|
+
throw new Error(
|
|
177
|
+
"Could not resolve a controller join URL from the host runtime inspection contract or runtime URL.",
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const joinUrl = new URL(resolvedJoinUrl);
|
|
182
|
+
const controllerUrl = new URL(controllerBaseUrl);
|
|
183
|
+
joinUrl.protocol = controllerUrl.protocol;
|
|
184
|
+
joinUrl.host = controllerUrl.host;
|
|
185
|
+
return joinUrl.toString();
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
export type OpenVisualHarnessSessionOptions = {
|
|
189
|
+
browser: Browser;
|
|
190
|
+
urls: Omit<VisualHarnessUrls, "controllerJoinUrl">;
|
|
191
|
+
mode: VisualHarnessMode;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
export type OpenVisualHarnessHostSessionResult = {
|
|
195
|
+
urls: Omit<VisualHarnessUrls, "controllerJoinUrl"> & {
|
|
196
|
+
controllerJoinUrl: null;
|
|
197
|
+
};
|
|
198
|
+
host: VisualHarnessPageSurface;
|
|
199
|
+
close: () => Promise<void>;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
export type OpenVisualHarnessControllerSessionResult = {
|
|
203
|
+
urls: VisualHarnessUrls;
|
|
204
|
+
controller: VisualHarnessPageSurface & {
|
|
205
|
+
fullscreenPromptDismissed: boolean;
|
|
206
|
+
};
|
|
207
|
+
close: () => Promise<void>;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
export type OpenVisualHarnessSessionResult = {
|
|
211
|
+
urls: VisualHarnessUrls;
|
|
212
|
+
host: VisualHarnessPageSurface;
|
|
213
|
+
controller: VisualHarnessPageSurface & {
|
|
214
|
+
fullscreenPromptDismissed: boolean;
|
|
215
|
+
};
|
|
216
|
+
close: () => Promise<void>;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
export const openVisualHarnessHostSession = async ({
|
|
220
|
+
browser,
|
|
221
|
+
urls,
|
|
222
|
+
mode,
|
|
223
|
+
}: OpenVisualHarnessSessionOptions): Promise<OpenVisualHarnessHostSessionResult> => {
|
|
224
|
+
const embedded = isEmbeddedMode(mode);
|
|
225
|
+
const hostContext: BrowserContext = await browser.newContext({
|
|
226
|
+
viewport: DEFAULT_HOST_VIEWPORT,
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
try {
|
|
230
|
+
const hostPage = await hostContext.newPage();
|
|
231
|
+
await hostPage.goto(urls.hostUrl, { waitUntil: "domcontentloaded" });
|
|
232
|
+
const hostGame: VisualQuerySurface = embedded
|
|
233
|
+
? await waitForFrameToLoad({
|
|
234
|
+
page: hostPage,
|
|
235
|
+
testId: "arcade-host-game-frame",
|
|
236
|
+
})
|
|
237
|
+
: hostPage;
|
|
238
|
+
|
|
239
|
+
return {
|
|
240
|
+
urls: { ...urls, controllerJoinUrl: null },
|
|
241
|
+
host: {
|
|
242
|
+
page: hostPage,
|
|
243
|
+
game: hostGame,
|
|
244
|
+
embedded,
|
|
245
|
+
},
|
|
246
|
+
close: () => hostContext.close(),
|
|
247
|
+
};
|
|
248
|
+
} catch (error) {
|
|
249
|
+
await hostContext.close().catch(() => null);
|
|
250
|
+
throw error;
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
export const openVisualHarnessControllerSession = async ({
|
|
255
|
+
browser,
|
|
256
|
+
urls,
|
|
257
|
+
host,
|
|
258
|
+
}: Omit<OpenVisualHarnessSessionOptions, "mode"> & {
|
|
259
|
+
host: VisualHarnessPageSurface;
|
|
260
|
+
}): Promise<OpenVisualHarnessControllerSessionResult> => {
|
|
261
|
+
const controllerContext = await browser.newContext({
|
|
262
|
+
viewport: DEFAULT_CONTROLLER_VIEWPORT,
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
try {
|
|
266
|
+
const controllerJoinUrl = await resolveControllerJoinUrl({
|
|
267
|
+
hostPage: host.page,
|
|
268
|
+
hostGame: host.game,
|
|
269
|
+
hostEmbedded: host.embedded,
|
|
270
|
+
controllerBaseUrl: urls.controllerBaseUrl,
|
|
271
|
+
});
|
|
272
|
+
const controllerPage = await controllerContext.newPage();
|
|
273
|
+
await controllerPage.goto(controllerJoinUrl, {
|
|
274
|
+
waitUntil: "domcontentloaded",
|
|
275
|
+
});
|
|
276
|
+
const fullscreenPromptDismissed =
|
|
277
|
+
await dismissHarnessControllerFullscreenPrompt(controllerPage);
|
|
278
|
+
const controllerGame: VisualQuerySurface = host.embedded
|
|
279
|
+
? await waitForFrameToLoad({
|
|
280
|
+
page: controllerPage,
|
|
281
|
+
testId: "arcade-controller-game-frame",
|
|
282
|
+
})
|
|
283
|
+
: controllerPage;
|
|
284
|
+
|
|
285
|
+
return {
|
|
286
|
+
urls: { ...urls, controllerJoinUrl },
|
|
287
|
+
controller: {
|
|
288
|
+
page: controllerPage,
|
|
289
|
+
game: controllerGame,
|
|
290
|
+
embedded: host.embedded,
|
|
291
|
+
fullscreenPromptDismissed,
|
|
292
|
+
},
|
|
293
|
+
close: () => controllerContext.close(),
|
|
294
|
+
};
|
|
295
|
+
} catch (error) {
|
|
296
|
+
await controllerContext.close().catch(() => null);
|
|
297
|
+
throw error;
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
export const openVisualHarnessSession = async ({
|
|
302
|
+
browser,
|
|
303
|
+
urls,
|
|
304
|
+
mode,
|
|
305
|
+
}: OpenVisualHarnessSessionOptions): Promise<OpenVisualHarnessSessionResult> => {
|
|
306
|
+
const hostSession = await openVisualHarnessHostSession({
|
|
307
|
+
browser,
|
|
308
|
+
urls,
|
|
309
|
+
mode,
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
try {
|
|
313
|
+
const controllerSession = await openVisualHarnessControllerSession({
|
|
314
|
+
browser,
|
|
315
|
+
urls,
|
|
316
|
+
host: hostSession.host,
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
return {
|
|
320
|
+
urls: controllerSession.urls,
|
|
321
|
+
host: hostSession.host,
|
|
322
|
+
controller: controllerSession.controller,
|
|
323
|
+
close: async () => {
|
|
324
|
+
await Promise.allSettled([
|
|
325
|
+
hostSession.close(),
|
|
326
|
+
controllerSession.close(),
|
|
327
|
+
]);
|
|
328
|
+
},
|
|
329
|
+
};
|
|
330
|
+
} catch (error) {
|
|
331
|
+
await hostSession.close().catch(() => null);
|
|
332
|
+
throw error;
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
export const launchHarnessBrowser = async (): Promise<Browser> => {
|
|
337
|
+
const options = {
|
|
338
|
+
headless: true,
|
|
339
|
+
args: [
|
|
340
|
+
"--enable-webgl",
|
|
341
|
+
"--ignore-gpu-blocklist",
|
|
342
|
+
"--use-angle=swiftshader",
|
|
343
|
+
],
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
if (process.env.AIRJAM_BROWSER_EXECUTABLE_PATH) {
|
|
347
|
+
return chromium.launch({
|
|
348
|
+
...options,
|
|
349
|
+
executablePath: process.env.AIRJAM_BROWSER_EXECUTABLE_PATH,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
try {
|
|
354
|
+
return await chromium.launch(options);
|
|
355
|
+
} catch (bundledBrowserError) {
|
|
356
|
+
try {
|
|
357
|
+
return await chromium.launch({ ...options, channel: "chrome" });
|
|
358
|
+
} catch (systemBrowserError) {
|
|
359
|
+
throw new Error(
|
|
360
|
+
[
|
|
361
|
+
"Air Jam could not launch a browser runtime for semantic sessions.",
|
|
362
|
+
"Install Playwright Chromium or set AIRJAM_BROWSER_EXECUTABLE_PATH to a Chromium-compatible browser.",
|
|
363
|
+
`Bundled browser: ${bundledBrowserError instanceof Error ? bundledBrowserError.message : String(bundledBrowserError)}`,
|
|
364
|
+
`System Chrome: ${systemBrowserError instanceof Error ? systemBrowserError.message : String(systemBrowserError)}`,
|
|
365
|
+
].join("\n\n"),
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
};
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import type { AirJamAgentContract, AnyAirJamAgentContract } from "@air-jam/sdk";
|
|
2
|
+
import type { Page } from "playwright-core";
|
|
3
|
+
|
|
4
|
+
export type { AnyAirJamAgentContract } from "@air-jam/sdk";
|
|
5
|
+
|
|
6
|
+
export type VisualHarnessMode = "standalone-dev" | "arcade-built";
|
|
7
|
+
|
|
8
|
+
export type VisualViewport = {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type VisualScreenshotRecord = {
|
|
14
|
+
surface: "host" | "controller";
|
|
15
|
+
viewportName: string;
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
fileName: string;
|
|
19
|
+
filePath: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type VisualHarnessUrls = {
|
|
23
|
+
appOrigin: string;
|
|
24
|
+
hostUrl: string;
|
|
25
|
+
controllerBaseUrl: string;
|
|
26
|
+
publicHost: string;
|
|
27
|
+
localBuildUrl: string | null;
|
|
28
|
+
browserBuildUrl: string | null;
|
|
29
|
+
controllerJoinUrl: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type VisualQuerySurface = {
|
|
33
|
+
getByLabel: Page["getByLabel"];
|
|
34
|
+
getByRole: Page["getByRole"];
|
|
35
|
+
getByTestId: Page["getByTestId"];
|
|
36
|
+
getByText: Page["getByText"];
|
|
37
|
+
locator: Page["locator"];
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type VisualHarnessPageSurface = {
|
|
41
|
+
page: Page;
|
|
42
|
+
game: VisualQuerySurface;
|
|
43
|
+
embedded: boolean;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type InferVisualScenarioSnapshot<TAgent> =
|
|
47
|
+
TAgent extends AirJamAgentContract<infer TSnapshot, infer _TStores>
|
|
48
|
+
? TSnapshot
|
|
49
|
+
: never;
|
|
50
|
+
|
|
51
|
+
export type VisualScenarioAgentActionDescriptor = {
|
|
52
|
+
actionId: string;
|
|
53
|
+
lane: "player" | "host";
|
|
54
|
+
source: "semantic-game";
|
|
55
|
+
description: string | null;
|
|
56
|
+
availability: string | null;
|
|
57
|
+
payload: {
|
|
58
|
+
kind: "none" | "boolean" | "number" | "string" | "enum" | "json";
|
|
59
|
+
description: string | null;
|
|
60
|
+
allowedValues?: string[];
|
|
61
|
+
};
|
|
62
|
+
resultDescription: string | null;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export type VisualScenarioAgentInvocation<TSnapshot = Record<string, unknown>> =
|
|
66
|
+
{
|
|
67
|
+
actionId: string;
|
|
68
|
+
lane: "player" | "host";
|
|
69
|
+
outcome: string | null;
|
|
70
|
+
acknowledgementObservation: string | null;
|
|
71
|
+
snapshotBefore: TSnapshot | null;
|
|
72
|
+
snapshotAfter: TSnapshot | null;
|
|
73
|
+
snapshotAfterStatus:
|
|
74
|
+
| "committed-update-observed"
|
|
75
|
+
| "no-new-commit-before-timeout"
|
|
76
|
+
| null;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export type VisualScenarioAgent<TSnapshot = Record<string, unknown>> = {
|
|
80
|
+
listActions: () => Promise<readonly VisualScenarioAgentActionDescriptor[]>;
|
|
81
|
+
read: () => Promise<TSnapshot>;
|
|
82
|
+
waitFor: (
|
|
83
|
+
predicate: (snapshot: TSnapshot) => boolean | Promise<boolean>,
|
|
84
|
+
description?: string,
|
|
85
|
+
timeout?: number,
|
|
86
|
+
) => Promise<TSnapshot>;
|
|
87
|
+
invoke: (
|
|
88
|
+
actionId: string,
|
|
89
|
+
payload?: unknown,
|
|
90
|
+
options?: {
|
|
91
|
+
timeoutMs?: number;
|
|
92
|
+
},
|
|
93
|
+
) => Promise<VisualScenarioAgentInvocation<TSnapshot>>;
|
|
94
|
+
close: () => Promise<void>;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export type VisualScenarioContext<
|
|
98
|
+
TAgent extends AnyAirJamAgentContract = AnyAirJamAgentContract,
|
|
99
|
+
> = {
|
|
100
|
+
gameId: string;
|
|
101
|
+
scenario: VisualScenario<TAgent>;
|
|
102
|
+
scenarioDir: string;
|
|
103
|
+
urls: VisualHarnessUrls;
|
|
104
|
+
host: VisualHarnessPageSurface;
|
|
105
|
+
controller: VisualHarnessPageSurface & {
|
|
106
|
+
fullscreenPromptDismissed: boolean;
|
|
107
|
+
};
|
|
108
|
+
note: (value: string) => void;
|
|
109
|
+
sleep: (ms: number) => Promise<void>;
|
|
110
|
+
ensureControllerInteractive: () => Promise<void>;
|
|
111
|
+
agent: VisualScenarioAgent<InferVisualScenarioSnapshot<TAgent>>;
|
|
112
|
+
captureHost: (
|
|
113
|
+
viewportName: string,
|
|
114
|
+
viewport: VisualViewport,
|
|
115
|
+
) => Promise<void>;
|
|
116
|
+
captureController: (
|
|
117
|
+
viewportName: string,
|
|
118
|
+
viewport: VisualViewport,
|
|
119
|
+
) => Promise<void>;
|
|
120
|
+
screenshotRecords: VisualScreenshotRecord[];
|
|
121
|
+
notes: string[];
|
|
122
|
+
close: () => Promise<void>;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export type VisualScenario<
|
|
126
|
+
TAgent extends AnyAirJamAgentContract = AnyAirJamAgentContract,
|
|
127
|
+
> = {
|
|
128
|
+
id: string;
|
|
129
|
+
description?: string;
|
|
130
|
+
run: (context: VisualScenarioContext<TAgent>) => Promise<void>;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export type VisualScenarioPack<
|
|
134
|
+
TAgent extends AnyAirJamAgentContract = AnyAirJamAgentContract,
|
|
135
|
+
> = {
|
|
136
|
+
agent: TAgent;
|
|
137
|
+
scenarios: ReadonlyArray<VisualScenario<TAgent>>;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export type VisualCaptureScenarioMetadata = {
|
|
141
|
+
gameId: string;
|
|
142
|
+
scenarioId: string;
|
|
143
|
+
scenarioDescription: string | null;
|
|
144
|
+
runtimeMode: VisualHarnessMode;
|
|
145
|
+
capturedAt: string;
|
|
146
|
+
status: "captured" | "failed";
|
|
147
|
+
urls: Omit<VisualHarnessUrls, "controllerJoinUrl"> | VisualHarnessUrls;
|
|
148
|
+
screenshots: Array<{
|
|
149
|
+
surface: "host" | "controller";
|
|
150
|
+
viewportName: string;
|
|
151
|
+
width: number;
|
|
152
|
+
height: number;
|
|
153
|
+
fileName: string;
|
|
154
|
+
relativePath: string;
|
|
155
|
+
}>;
|
|
156
|
+
notes: string[];
|
|
157
|
+
error: {
|
|
158
|
+
message: string;
|
|
159
|
+
stack: string | null;
|
|
160
|
+
} | null;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export type VisualCaptureSummary = {
|
|
164
|
+
gameId: string;
|
|
165
|
+
mode: VisualHarnessMode;
|
|
166
|
+
secure: boolean;
|
|
167
|
+
capturedAt: string;
|
|
168
|
+
scenarios: Array<{
|
|
169
|
+
scenarioId: string;
|
|
170
|
+
status: "captured" | "failed";
|
|
171
|
+
screenshotCount: number;
|
|
172
|
+
relativeDir: string;
|
|
173
|
+
}>;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export type RunVisualCaptureCommandOptions = {
|
|
177
|
+
gameId: string;
|
|
178
|
+
scenarioId?: string | null;
|
|
179
|
+
mode?: VisualHarnessMode;
|
|
180
|
+
secure?: boolean;
|
|
181
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./visual/prefab-contract.js";
|
|
2
|
+
export * from "./visual/prefab-runner.js";
|
|
3
|
+
export * from "./visual/runner.js";
|
|
4
|
+
export * from "./visual/scenario-contract.js";
|
|
5
|
+
export * from "./visual/scenario-helpers.js";
|
|
6
|
+
export * from "./visual/session.js";
|
|
7
|
+
export * from "./visual/types.js";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
const moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
|
|
9
|
+
export const resolveDevtoolsHelperScript = (fileName: string): string => {
|
|
10
|
+
const builtHelperPath = path.resolve(
|
|
11
|
+
moduleDir,
|
|
12
|
+
"tooling",
|
|
13
|
+
fileName.replace(/\.ts$/, ".js"),
|
|
14
|
+
);
|
|
15
|
+
if (existsSync(builtHelperPath)) {
|
|
16
|
+
return builtHelperPath;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const sourceHelperPath = path.resolve(
|
|
20
|
+
moduleDir,
|
|
21
|
+
"..",
|
|
22
|
+
"src",
|
|
23
|
+
"tooling",
|
|
24
|
+
fileName,
|
|
25
|
+
);
|
|
26
|
+
if (existsSync(sourceHelperPath)) {
|
|
27
|
+
return sourceHelperPath;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Air Jam helper script is missing from this installation: ${fileName}`,
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const typescriptExtensions = new Set([".ts", ".tsx", ".mts", ".cts"]);
|
|
36
|
+
const projectTypescriptLoaderHelpers = new Set([
|
|
37
|
+
"agent-contract",
|
|
38
|
+
"inspect-airjam-agent",
|
|
39
|
+
"list-visual-scenarios",
|
|
40
|
+
"run-visual-capture",
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
export const resolveDevtoolsHelperArgs = (helperPath: string): string[] =>
|
|
44
|
+
typescriptExtensions.has(path.extname(helperPath)) ||
|
|
45
|
+
projectTypescriptLoaderHelpers.has(
|
|
46
|
+
path.basename(helperPath, path.extname(helperPath)),
|
|
47
|
+
)
|
|
48
|
+
? ["--import", require.resolve("tsx"), helperPath]
|
|
49
|
+
: [helperPath];
|
package/src/logs.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { runCommandResult } from "./commands.js";
|
|
2
|
+
import { detectProjectContext } from "./context.js";
|
|
3
|
+
import type { CommandResult, ReadDevLogsOptions } from "./types.js";
|
|
4
|
+
|
|
5
|
+
export type { CommandResult, ReadDevLogsOptions } from "./types.js";
|
|
6
|
+
|
|
7
|
+
const pushOption = (
|
|
8
|
+
args: string[],
|
|
9
|
+
name: string,
|
|
10
|
+
value: string | number | undefined,
|
|
11
|
+
): void => {
|
|
12
|
+
if (value !== undefined && value !== "") {
|
|
13
|
+
args.push(`--${name}=${String(value)}`);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const readDevLogs = async (
|
|
18
|
+
options: ReadDevLogsOptions = {},
|
|
19
|
+
): Promise<CommandResult & { lines: string[] }> => {
|
|
20
|
+
const context = await detectProjectContext({ cwd: options.cwd });
|
|
21
|
+
const args = ["exec", "air-jam-server", "logs"];
|
|
22
|
+
|
|
23
|
+
pushOption(args, "view", options.view ?? "signal");
|
|
24
|
+
pushOption(args, "source", options.source);
|
|
25
|
+
pushOption(args, "trace", options.trace);
|
|
26
|
+
pushOption(args, "room", options.room);
|
|
27
|
+
pushOption(args, "controller", options.controller);
|
|
28
|
+
pushOption(args, "event", options.event);
|
|
29
|
+
pushOption(args, "process", options.process);
|
|
30
|
+
pushOption(args, "level", options.level);
|
|
31
|
+
pushOption(args, "runtime", options.runtime);
|
|
32
|
+
pushOption(args, "epoch", options.epoch);
|
|
33
|
+
pushOption(args, "console-category", options.consoleCategory);
|
|
34
|
+
pushOption(args, "file", options.file);
|
|
35
|
+
|
|
36
|
+
const result = runCommandResult({
|
|
37
|
+
command: "pnpm",
|
|
38
|
+
args,
|
|
39
|
+
cwd: context.rootDir,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const missingLogMessage = `${result.stderr}\n${result.stdout}`;
|
|
43
|
+
if (!result.ok && /Dev log file not found:/i.test(missingLogMessage)) {
|
|
44
|
+
const message =
|
|
45
|
+
"Air Jam dev logs are not ready yet. Start local dev with `pnpm run dev`, then retry logs after the server creates `.airjam/logs/dev-latest.ndjson`.";
|
|
46
|
+
return {
|
|
47
|
+
...result,
|
|
48
|
+
exitCode: 0,
|
|
49
|
+
ok: true,
|
|
50
|
+
stdout: message,
|
|
51
|
+
stderr: "",
|
|
52
|
+
lines: [message],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const allLines = result.stdout.split(/\r?\n/).filter(Boolean);
|
|
57
|
+
const lines =
|
|
58
|
+
typeof options.tail === "number" && options.tail >= 0
|
|
59
|
+
? allLines.slice(-options.tail)
|
|
60
|
+
: allLines;
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
...result,
|
|
64
|
+
stdout: lines.join("\n"),
|
|
65
|
+
lines,
|
|
66
|
+
};
|
|
67
|
+
};
|