vibedgames 0.5.0 → 0.6.0
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/dist/commands/completions.d.ts +1 -1
- package/dist/commands/completions.js +21 -20
- package/dist/commands/credits.d.ts +5 -5
- package/dist/commands/credits.js +43 -33
- package/dist/commands/deploy.d.ts +10 -10
- package/dist/commands/deploy.js +155 -139
- package/dist/commands/factory.d.ts +1 -1
- package/dist/commands/factory.js +18 -15
- package/dist/commands/fork.d.ts +14 -14
- package/dist/commands/fork.js +51 -46
- package/dist/commands/generate.js +318 -264
- package/dist/commands/init.d.ts +8 -8
- package/dist/commands/init.js +31 -24
- package/dist/commands/login.js +12 -12
- package/dist/commands/logout.js +2 -2
- package/dist/commands/new.d.ts +16 -16
- package/dist/commands/new.js +153 -142
- package/dist/commands/playtest-run.d.ts +62 -0
- package/dist/commands/playtest-run.js +258 -0
- package/dist/commands/playtest.d.ts +41 -6
- package/dist/commands/playtest.js +114 -101
- package/dist/commands/update.d.ts +7 -7
- package/dist/commands/update.js +20 -17
- package/dist/commands/whoami.d.ts +5 -5
- package/dist/commands/whoami.js +8 -7
- package/dist/index.js +21 -11
- package/dist/lib/api.d.ts +4 -4
- package/dist/lib/api.js +6 -12
- package/dist/lib/archive.d.ts +4 -4
- package/dist/lib/archive.js +121 -104
- package/dist/lib/codex.d.ts +45 -15
- package/dist/lib/codex.js +175 -106
- package/dist/lib/config-file.d.ts +6 -6
- package/dist/lib/config-file.js +28 -26
- package/dist/lib/config.d.ts +8 -8
- package/dist/lib/config.js +31 -33
- package/dist/lib/manifest.d.ts +3 -3
- package/dist/lib/manifest.js +42 -38
- package/dist/lib/media-args.d.ts +7 -7
- package/dist/lib/media-args.js +113 -95
- package/dist/lib/media-download.d.ts +9 -9
- package/dist/lib/media-download.js +148 -134
- package/dist/lib/media-poll.d.ts +8 -8
- package/dist/lib/media-poll.js +32 -27
- package/dist/lib/media-upload.d.ts +2 -2
- package/dist/lib/media-upload.js +27 -27
- package/dist/lib/output.d.ts +27 -12
- package/dist/lib/output.js +26 -26
- package/dist/lib/package-manager.d.ts +3 -3
- package/dist/lib/package-manager.js +27 -22
- package/dist/lib/playtest/agent.d.ts +188 -0
- package/dist/lib/playtest/agent.js +610 -0
- package/dist/lib/playtest/browser.d.ts +109 -0
- package/dist/lib/playtest/browser.js +219 -0
- package/dist/lib/playtest/controls.d.ts +47 -0
- package/dist/lib/playtest/controls.js +218 -0
- package/dist/lib/playtest/errors.d.ts +9 -0
- package/dist/lib/playtest/errors.js +12 -0
- package/dist/lib/playtest/keys.d.ts +41 -0
- package/dist/lib/playtest/keys.js +157 -0
- package/dist/lib/playtest/run.d.ts +193 -0
- package/dist/lib/playtest/run.js +408 -0
- package/dist/lib/run.d.ts +4 -4
- package/dist/lib/run.js +7 -4
- package/dist/lib/strict-args.d.ts +4 -4
- package/dist/lib/strict-args.js +28 -18
- package/dist/lib/types.d.ts +5 -5
- package/dist/lib/types.js +9 -12
- package/dist/lib/update.d.ts +4 -4
- package/dist/lib/update.js +41 -32
- package/dist/lib/upload.d.ts +4 -4
- package/dist/lib/upload.js +14 -9
- package/package.json +16 -16
package/dist/lib/output.d.ts
CHANGED
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
* skill at all. `--field` removes it: the CLI does the selection itself and
|
|
8
8
|
* prints a bare scalar that a shell can capture directly.
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
10
|
+
export interface OutputArgs {
|
|
11
11
|
json?: boolean;
|
|
12
12
|
field?: string;
|
|
13
|
-
}
|
|
13
|
+
}
|
|
14
14
|
/**
|
|
15
15
|
* What the commands hand to stdout: JSON, plus `undefined` so payload types
|
|
16
16
|
* can carry optional members (JSON.stringify drops them, and `--field`
|
|
@@ -19,35 +19,50 @@ export type OutputArgs = {
|
|
|
19
19
|
export type OutputValue = string | number | boolean | null | undefined | OutputValue[] | {
|
|
20
20
|
[key: string]: OutputValue;
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
/**
|
|
23
|
+
* What a command may hand to `writeStructured`: a JSON value, or a payload
|
|
24
|
+
* type declared member by member.
|
|
25
|
+
*
|
|
26
|
+
* The second arm exists because TypeScript grants an implicit index signature
|
|
27
|
+
* only to a type alias, never to an interface — declaration merging could add
|
|
28
|
+
* members later, so an interface's keys are never assumed and it is not
|
|
29
|
+
* assignable to `OutputValue`'s object arm. Mapping the payload's own keys
|
|
30
|
+
* checks each one against `OutputValue` instead, which still rejects a `Date`
|
|
31
|
+
* or a method where `[key: string]: unknown` on every payload would not.
|
|
32
|
+
*/
|
|
33
|
+
type OutputPayload<T> = OutputValue | {
|
|
34
|
+
[K in keyof T]: OutputValue;
|
|
35
|
+
};
|
|
36
|
+
export declare const isJsonOutput: (args: OutputArgs) => boolean;
|
|
37
|
+
export declare const writeJson: (value: OutputValue) => void;
|
|
24
38
|
/**
|
|
25
39
|
* Resolve a dotted path against a decoded JSON value. Supports array indexing
|
|
26
40
|
* in both `items[0]` and `items.0` spellings, since agents write both.
|
|
27
41
|
* Returns `undefined` for any path that doesn't resolve.
|
|
28
42
|
*/
|
|
29
|
-
export declare
|
|
43
|
+
export declare const selectField: (value: OutputValue, path: string) => OutputValue;
|
|
30
44
|
/**
|
|
31
45
|
* Render one selected value for shell capture. Scalars print bare so
|
|
32
46
|
* `$(vg ... --field url)` needs no unquoting; arrays of scalars print one per
|
|
33
47
|
* line so they can be looped over; anything structural falls back to JSON.
|
|
34
48
|
*/
|
|
35
|
-
export declare
|
|
49
|
+
export declare const formatField: (value: OutputValue) => string;
|
|
36
50
|
/**
|
|
37
51
|
* The standard exit path for a command that produced structured data.
|
|
38
52
|
* `--field` wins over `--json` when both are passed, since asking for one
|
|
39
53
|
* value is the more specific request. Returns false when neither flag was
|
|
40
54
|
* given, so the caller can fall through to its human-readable rendering.
|
|
41
55
|
*/
|
|
42
|
-
export declare
|
|
56
|
+
export declare const writeStructured: <T extends OutputPayload<T>>(value: T, args: OutputArgs) => boolean;
|
|
43
57
|
/** The `--json`/`--field` arg pair, for spreading into a citty `args` block. */
|
|
44
58
|
export declare const outputArgs: {
|
|
45
|
-
readonly json: {
|
|
46
|
-
readonly type: "boolean";
|
|
47
|
-
readonly description: "Print structured JSON to stdout.";
|
|
48
|
-
};
|
|
49
59
|
readonly field: {
|
|
50
|
-
readonly type: "string";
|
|
51
60
|
readonly description: "Print a single value from the JSON result, e.g. --field request_id or --field images[0].url. Prints scalars bare for shell capture.";
|
|
61
|
+
readonly type: "string";
|
|
62
|
+
};
|
|
63
|
+
readonly json: {
|
|
64
|
+
readonly description: "Print structured JSON to stdout.";
|
|
65
|
+
readonly type: "boolean";
|
|
52
66
|
};
|
|
53
67
|
};
|
|
68
|
+
export {};
|
package/dist/lib/output.js
CHANGED
|
@@ -7,74 +7,74 @@
|
|
|
7
7
|
* skill at all. `--field` removes it: the CLI does the selection itself and
|
|
8
8
|
* prints a bare scalar that a shell can capture directly.
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export
|
|
15
|
-
return Boolean(args.json) || process.env.VG_JSON_OUTPUT === "1";
|
|
16
|
-
}
|
|
17
|
-
export function writeJson(value) {
|
|
10
|
+
const isOutputObject = (value) =>
|
|
11
|
+
// Object() is the identity only on objects; arrays are split off explicitly.
|
|
12
|
+
Object(value) === value && !Array.isArray(value);
|
|
13
|
+
export const isJsonOutput = (args) => Boolean(args.json) || process.env.VG_JSON_OUTPUT === "1";
|
|
14
|
+
export const writeJson = (value) => {
|
|
18
15
|
process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
|
|
19
|
-
}
|
|
16
|
+
};
|
|
20
17
|
/**
|
|
21
18
|
* Resolve a dotted path against a decoded JSON value. Supports array indexing
|
|
22
19
|
* in both `items[0]` and `items.0` spellings, since agents write both.
|
|
23
20
|
* Returns `undefined` for any path that doesn't resolve.
|
|
24
21
|
*/
|
|
25
|
-
export
|
|
22
|
+
export const selectField = (value, path) => {
|
|
26
23
|
const segments = path
|
|
27
|
-
.
|
|
24
|
+
.replaceAll(/\[(?<index>-?\d+)\]/gu, ".$<index>")
|
|
28
25
|
.split(".")
|
|
29
26
|
.filter(Boolean);
|
|
30
27
|
let current = value;
|
|
31
28
|
for (const segment of segments) {
|
|
32
|
-
if (current === null || current === undefined)
|
|
29
|
+
if (current === null || current === undefined) {
|
|
33
30
|
return undefined;
|
|
31
|
+
}
|
|
34
32
|
if (Array.isArray(current)) {
|
|
35
33
|
const index = Number(segment);
|
|
36
|
-
if (!Number.isInteger(index))
|
|
34
|
+
if (!Number.isInteger(index)) {
|
|
37
35
|
return undefined;
|
|
36
|
+
}
|
|
38
37
|
// Negative indices count from the end, which is handy for "the last
|
|
39
38
|
// frame" style selections.
|
|
40
39
|
current = current.at(index);
|
|
41
40
|
continue;
|
|
42
41
|
}
|
|
43
|
-
if (!isOutputObject(current))
|
|
42
|
+
if (!isOutputObject(current)) {
|
|
44
43
|
return undefined;
|
|
44
|
+
}
|
|
45
45
|
current = current[segment];
|
|
46
46
|
}
|
|
47
47
|
return current;
|
|
48
|
-
}
|
|
48
|
+
};
|
|
49
49
|
// A value that prints as one bare token: null or a primitive.
|
|
50
|
-
|
|
51
|
-
return value === null || (value !== undefined && Object(value) !== value);
|
|
52
|
-
}
|
|
50
|
+
const isScalarEntry = (value) => value === null || (value !== undefined && Object(value) !== value);
|
|
53
51
|
/**
|
|
54
52
|
* Render one selected value for shell capture. Scalars print bare so
|
|
55
53
|
* `$(vg ... --field url)` needs no unquoting; arrays of scalars print one per
|
|
56
54
|
* line so they can be looped over; anything structural falls back to JSON.
|
|
57
55
|
*/
|
|
58
|
-
export
|
|
59
|
-
if (value === null || value === undefined)
|
|
56
|
+
export const formatField = (value) => {
|
|
57
|
+
if (value === null || value === undefined) {
|
|
60
58
|
return "";
|
|
59
|
+
}
|
|
61
60
|
if (Array.isArray(value)) {
|
|
62
61
|
if (value.every(isScalarEntry)) {
|
|
63
62
|
return value.map((v) => (v === null ? "" : String(v))).join("\n");
|
|
64
63
|
}
|
|
65
64
|
return JSON.stringify(value, null, 2);
|
|
66
65
|
}
|
|
67
|
-
if (isOutputObject(value))
|
|
66
|
+
if (isOutputObject(value)) {
|
|
68
67
|
return JSON.stringify(value, null, 2);
|
|
68
|
+
}
|
|
69
69
|
return String(value);
|
|
70
|
-
}
|
|
70
|
+
};
|
|
71
71
|
/**
|
|
72
72
|
* The standard exit path for a command that produced structured data.
|
|
73
73
|
* `--field` wins over `--json` when both are passed, since asking for one
|
|
74
74
|
* value is the more specific request. Returns false when neither flag was
|
|
75
75
|
* given, so the caller can fall through to its human-readable rendering.
|
|
76
76
|
*/
|
|
77
|
-
export
|
|
77
|
+
export const writeStructured = (value, args) => {
|
|
78
78
|
if (args.field) {
|
|
79
79
|
const selected = selectField(value, args.field);
|
|
80
80
|
if (selected === undefined) {
|
|
@@ -91,12 +91,12 @@ export function writeStructured(value, args) {
|
|
|
91
91
|
return true;
|
|
92
92
|
}
|
|
93
93
|
return false;
|
|
94
|
-
}
|
|
94
|
+
};
|
|
95
95
|
/** The `--json`/`--field` arg pair, for spreading into a citty `args` block. */
|
|
96
96
|
export const outputArgs = {
|
|
97
|
-
json: { type: "boolean", description: "Print structured JSON to stdout." },
|
|
98
97
|
field: {
|
|
99
|
-
type: "string",
|
|
100
98
|
description: "Print a single value from the JSON result, e.g. --field request_id or --field images[0].url. Prints scalars bare for shell capture.",
|
|
99
|
+
type: "string",
|
|
101
100
|
},
|
|
101
|
+
json: { description: "Print structured JSON to stdout.", type: "boolean" },
|
|
102
102
|
};
|
|
@@ -18,8 +18,8 @@ export declare const PKG_NAME = "vibedgames";
|
|
|
18
18
|
* `installPath` is where the CLI is installed — normally the directory this
|
|
19
19
|
* module resolves from. Bun's own runtime is a signal in its own right.
|
|
20
20
|
*/
|
|
21
|
-
export declare
|
|
21
|
+
export declare const detectPackageManager: (installPath: string, env?: NodeJS.ProcessEnv) => PackageManager;
|
|
22
22
|
/** The argv that installs or upgrades a package globally, per manager. */
|
|
23
|
-
export declare
|
|
23
|
+
export declare const globalInstallArgs: (manager: PackageManager, pkg?: string) => string[];
|
|
24
24
|
/** The command a user can copy-paste when the automatic update can't run. */
|
|
25
|
-
export declare
|
|
25
|
+
export declare const globalInstallCommand: (manager: PackageManager, pkg?: string) => string;
|
|
@@ -22,51 +22,56 @@ export const PKG_NAME = "vibedgames";
|
|
|
22
22
|
* directory named after them.
|
|
23
23
|
*/
|
|
24
24
|
const SIGNATURES = [
|
|
25
|
-
["bun", /[/\\]\.bun[/\\]/],
|
|
25
|
+
["bun", /[/\\]\.bun[/\\]/u],
|
|
26
26
|
// pnpm's global store, not a project-local `node_modules/.pnpm`.
|
|
27
|
-
["pnpm", /[/\\](?:pnpm[/\\]global|\.pnpm-global|Library[/\\]pnpm)[/\\]/],
|
|
28
|
-
["yarn", /[/\\](?:\.yarn|yarn[/\\]global|\.config[/\\]yarn)[/\\]/],
|
|
29
|
-
["npm", /[/\\]lib[/\\]node_modules[/\\]/],
|
|
30
|
-
["npm", /[/\\]npm[/\\]node_modules[/\\]/],
|
|
27
|
+
["pnpm", /[/\\](?:pnpm[/\\]global|\.pnpm-global|Library[/\\]pnpm)[/\\]/u],
|
|
28
|
+
["yarn", /[/\\](?:\.yarn|yarn[/\\]global|\.config[/\\]yarn)[/\\]/u],
|
|
29
|
+
["npm", /[/\\]lib[/\\]node_modules[/\\]/u],
|
|
30
|
+
["npm", /[/\\]npm[/\\]node_modules[/\\]/u],
|
|
31
31
|
];
|
|
32
32
|
/**
|
|
33
33
|
* `npm_config_user_agent` is set by whichever manager is running us — reliable
|
|
34
34
|
* when `vg` was invoked through a script (`pnpm vg …`), absent otherwise.
|
|
35
35
|
*/
|
|
36
|
-
|
|
37
|
-
if (!userAgent)
|
|
36
|
+
const fromUserAgent = (userAgent) => {
|
|
37
|
+
if (!userAgent) {
|
|
38
38
|
return null;
|
|
39
|
-
|
|
39
|
+
}
|
|
40
|
+
const [name] = userAgent.split("/");
|
|
40
41
|
return name === "npm" || name === "pnpm" || name === "yarn" || name === "bun" ? name : null;
|
|
41
|
-
}
|
|
42
|
+
};
|
|
42
43
|
/**
|
|
43
44
|
* `installPath` is where the CLI is installed — normally the directory this
|
|
44
45
|
* module resolves from. Bun's own runtime is a signal in its own right.
|
|
45
46
|
*/
|
|
46
|
-
export
|
|
47
|
+
export const detectPackageManager = (installPath, env = process.env) => {
|
|
47
48
|
for (const [manager, signature] of SIGNATURES) {
|
|
48
|
-
if (signature.test(installPath))
|
|
49
|
+
if (signature.test(installPath)) {
|
|
49
50
|
return manager;
|
|
51
|
+
}
|
|
50
52
|
}
|
|
51
53
|
// Bun reports itself in versions; running under it means `bun add` works.
|
|
52
|
-
if ("Bun" in globalThis)
|
|
54
|
+
if ("Bun" in globalThis) {
|
|
53
55
|
return "bun";
|
|
56
|
+
}
|
|
54
57
|
return fromUserAgent(env.npm_config_user_agent) ?? "npm";
|
|
55
|
-
}
|
|
58
|
+
};
|
|
56
59
|
/** The argv that installs or upgrades a package globally, per manager. */
|
|
57
|
-
export
|
|
60
|
+
export const globalInstallArgs = (manager, pkg = PKG_NAME) => {
|
|
58
61
|
switch (manager) {
|
|
59
|
-
case "pnpm":
|
|
62
|
+
case "pnpm": {
|
|
60
63
|
return ["add", "-g", pkg];
|
|
61
|
-
|
|
64
|
+
}
|
|
65
|
+
case "yarn": {
|
|
62
66
|
return ["global", "add", pkg];
|
|
63
|
-
|
|
67
|
+
}
|
|
68
|
+
case "bun": {
|
|
64
69
|
return ["add", "-g", pkg];
|
|
65
|
-
|
|
70
|
+
}
|
|
71
|
+
default: {
|
|
66
72
|
return ["install", "-g", pkg];
|
|
73
|
+
}
|
|
67
74
|
}
|
|
68
|
-
}
|
|
75
|
+
};
|
|
69
76
|
/** The command a user can copy-paste when the automatic update can't run. */
|
|
70
|
-
export
|
|
71
|
-
return `${manager} ${globalInstallArgs(manager, pkg).join(" ")}`;
|
|
72
|
-
}
|
|
77
|
+
export const globalInstallCommand = (manager, pkg = PKG_NAME) => `${manager} ${globalInstallArgs(manager, pkg).join(" ")}`;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The in-page playtester.
|
|
3
|
+
*
|
|
4
|
+
* `vg playtest run` injects this function's SOURCE into the game's page and
|
|
5
|
+
* calls it there, so the whole decide → apply → measure loop runs inside the
|
|
6
|
+
* browser: no CLI round trip per decision, and a per-frame reflex layer that
|
|
7
|
+
* a subprocess could never keep up with. The CLI's only jobs are to mint the
|
|
8
|
+
* token, inject, poll `window.__PLAYTEST_AGENT__.done`, and read the
|
|
9
|
+
* records back.
|
|
10
|
+
*
|
|
11
|
+
* Rules that follow from being stringified: `inPageAgent` and `browserEnv`
|
|
12
|
+
* must be entirely self-contained — no imports, no module-scope references
|
|
13
|
+
* (the `declare`d globals below are erased and resolve to the page's own) —
|
|
14
|
+
* which is why every helper lives inside them. The agent talks to the page
|
|
15
|
+
* only through `env`, the real browser in production and a fake in tests.
|
|
16
|
+
*
|
|
17
|
+
* The decision is the hold: the previous inputs stay down while the model
|
|
18
|
+
* answers, so the game runs continuously and the loop decides at the
|
|
19
|
+
* model's latency, with `tickMs` as a floor. A move option in the game's
|
|
20
|
+
* `__GAME_PLAYTEST__` may carry a `reflex(game)` function; while that option
|
|
21
|
+
* is the current intent, the reflex runs every frame and its returned inputs
|
|
22
|
+
* are what is held — the model sets intent a few times a second, the reflex
|
|
23
|
+
* turns it into input at 60 fps.
|
|
24
|
+
*/
|
|
25
|
+
/** A parsed JSON document — the shape of everything that crosses the page boundary. */
|
|
26
|
+
type Json = string | number | boolean | null | Json[] | {
|
|
27
|
+
[key: string]: Json;
|
|
28
|
+
};
|
|
29
|
+
export interface AgentKeyInit {
|
|
30
|
+
code: string;
|
|
31
|
+
key: string;
|
|
32
|
+
keyCode: number;
|
|
33
|
+
which: number;
|
|
34
|
+
altKey: boolean;
|
|
35
|
+
ctrlKey: boolean;
|
|
36
|
+
shiftKey: boolean;
|
|
37
|
+
bubbles: true;
|
|
38
|
+
}
|
|
39
|
+
export interface AgentPointer {
|
|
40
|
+
x: number;
|
|
41
|
+
y: number;
|
|
42
|
+
down: boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface AgentMove {
|
|
45
|
+
description: string;
|
|
46
|
+
inits: AgentKeyInit[];
|
|
47
|
+
pointer: AgentPointer | null;
|
|
48
|
+
}
|
|
49
|
+
export interface AgentAction {
|
|
50
|
+
description: string;
|
|
51
|
+
inits: AgentKeyInit[];
|
|
52
|
+
}
|
|
53
|
+
export interface AgentConfig {
|
|
54
|
+
decideUrl: string;
|
|
55
|
+
token: string;
|
|
56
|
+
model: string;
|
|
57
|
+
goal: string;
|
|
58
|
+
move: Record<string, AgentMove>;
|
|
59
|
+
actions: Record<string, AgentAction>;
|
|
60
|
+
/** Every supported KeyboardEvent code, for inputs a reflex returns. */
|
|
61
|
+
keyTable: Record<string, AgentKeyInit>;
|
|
62
|
+
ticks: number;
|
|
63
|
+
tickMs: number;
|
|
64
|
+
finalHoldMs: number;
|
|
65
|
+
actionThreshold: number;
|
|
66
|
+
motionEpsilon: number;
|
|
67
|
+
stuckRun: number;
|
|
68
|
+
/** Decisions in a row of holding nothing, going nowhere, before the no-input option is rested. */
|
|
69
|
+
idleRun: number;
|
|
70
|
+
/** How many decisions a rested no-input option stays out of the question. */
|
|
71
|
+
idleRestTicks: number;
|
|
72
|
+
trailLength: number;
|
|
73
|
+
decisionRetries: number;
|
|
74
|
+
decisionTimeoutMs: number;
|
|
75
|
+
}
|
|
76
|
+
export interface AgentSample {
|
|
77
|
+
x: number;
|
|
78
|
+
y: number;
|
|
79
|
+
z: number;
|
|
80
|
+
frame: number;
|
|
81
|
+
score: number;
|
|
82
|
+
complete: boolean;
|
|
83
|
+
}
|
|
84
|
+
export interface AgentWindow {
|
|
85
|
+
path: number;
|
|
86
|
+
peak: number;
|
|
87
|
+
frameBefore: number;
|
|
88
|
+
frame: number;
|
|
89
|
+
scoreBefore: number;
|
|
90
|
+
score: number;
|
|
91
|
+
x: number;
|
|
92
|
+
y: number;
|
|
93
|
+
z: number;
|
|
94
|
+
complete: boolean;
|
|
95
|
+
}
|
|
96
|
+
export interface AgentRecord {
|
|
97
|
+
tick: number;
|
|
98
|
+
move: string;
|
|
99
|
+
actions: string[];
|
|
100
|
+
actionProbabilities: Record<string, number>;
|
|
101
|
+
confidence: number | null;
|
|
102
|
+
decisionMs: number;
|
|
103
|
+
inputTokens: number;
|
|
104
|
+
outputTokens: number;
|
|
105
|
+
/** Frames on which the option's reflex produced the held input. */
|
|
106
|
+
reflexFrames: number;
|
|
107
|
+
/**
|
|
108
|
+
* The model's own read of how close the player is to `goal`, 0–1, from the
|
|
109
|
+
* `progress` score question; null when it gave none.
|
|
110
|
+
*/
|
|
111
|
+
progress: number | null;
|
|
112
|
+
/** Whether the move asked the player to move at all, so a still window can count as stuck. */
|
|
113
|
+
askedToMove: boolean;
|
|
114
|
+
window: AgentWindow;
|
|
115
|
+
}
|
|
116
|
+
export interface AgentUsage {
|
|
117
|
+
calls: number;
|
|
118
|
+
inputTokens: number;
|
|
119
|
+
outputTokens: number;
|
|
120
|
+
totalDecisionMs: number;
|
|
121
|
+
maxDecisionMs: number;
|
|
122
|
+
}
|
|
123
|
+
export interface AgentResult {
|
|
124
|
+
done: boolean;
|
|
125
|
+
error: string | null;
|
|
126
|
+
records: AgentRecord[];
|
|
127
|
+
usage: AgentUsage;
|
|
128
|
+
wallMs: number;
|
|
129
|
+
completedAtTick: number | null;
|
|
130
|
+
stop: () => void;
|
|
131
|
+
}
|
|
132
|
+
/** The game's diagnostics, as far as the agent reads them. */
|
|
133
|
+
export interface Diagnostics {
|
|
134
|
+
frame?: number;
|
|
135
|
+
score?: number;
|
|
136
|
+
complete?: boolean;
|
|
137
|
+
player?: {
|
|
138
|
+
x?: number;
|
|
139
|
+
y?: number;
|
|
140
|
+
z?: number;
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/** What a reflex may hand back: key codes to hold and/or a pointer position. */
|
|
144
|
+
export interface ReflexInputs {
|
|
145
|
+
keys?: string[];
|
|
146
|
+
pointer?: {
|
|
147
|
+
x: number;
|
|
148
|
+
y: number;
|
|
149
|
+
down?: boolean;
|
|
150
|
+
} | null;
|
|
151
|
+
}
|
|
152
|
+
export type Reflex = (game: Diagnostics | null) => ReflexInputs | null | undefined;
|
|
153
|
+
export interface AgentResponse {
|
|
154
|
+
ok: boolean;
|
|
155
|
+
status: number;
|
|
156
|
+
text: () => Promise<string>;
|
|
157
|
+
}
|
|
158
|
+
export interface AgentRequest {
|
|
159
|
+
method: string;
|
|
160
|
+
headers: Record<string, string>;
|
|
161
|
+
body: string;
|
|
162
|
+
}
|
|
163
|
+
/** The page, as the agent sees it. */
|
|
164
|
+
export interface AgentEnv {
|
|
165
|
+
now: () => number;
|
|
166
|
+
fetch: (url: string, init: AgentRequest) => Promise<AgentResponse>;
|
|
167
|
+
raf: (frame: () => void) => number;
|
|
168
|
+
caf: (id: number) => void;
|
|
169
|
+
delay: (ms: number) => Promise<void>;
|
|
170
|
+
read: () => AgentSample;
|
|
171
|
+
/** A JSON-safe copy of the diagnostics, for the model. */
|
|
172
|
+
snapshot: () => Json;
|
|
173
|
+
/** The live diagnostics object, for a reflex. */
|
|
174
|
+
live: () => Diagnostics | null;
|
|
175
|
+
dispatchKey: (type: "keydown" | "keyup", init: AgentKeyInit) => void;
|
|
176
|
+
dispatchPointer: (pointer: AgentPointer, type: "pointermove" | "pointerdown" | "pointerup") => void;
|
|
177
|
+
reflexFor: (label: string) => Reflex | null;
|
|
178
|
+
publish: (result: AgentResult) => void;
|
|
179
|
+
}
|
|
180
|
+
/** The real page as an AgentEnv. Only ever runs in the browser; injected beside the agent. */
|
|
181
|
+
export declare const browserEnv: () => AgentEnv;
|
|
182
|
+
/**
|
|
183
|
+
* Run the playtest inside the page. Returns the live result object, which is
|
|
184
|
+
* also published as `window.__PLAYTEST_AGENT__`; `done` flips when the run
|
|
185
|
+
* ends, `error` says why if it ended early.
|
|
186
|
+
*/
|
|
187
|
+
export declare const inPageAgent: (config: AgentConfig, env: AgentEnv) => AgentResult;
|
|
188
|
+
export {};
|