@nodetool-ai/game-runtime 0.8.3 → 0.8.4-a24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -0
- package/dist/.nodetool-build-stamp +1 -1
- package/dist/authoring-reconcile.d.ts.map +1 -1
- package/dist/authoring-reconcile.js +5 -3
- package/dist/authoring-reconcile.js.map +1 -1
- package/dist/document-ops.d.ts +1102 -0
- package/dist/document-ops.d.ts.map +1 -1
- package/dist/document-ops3d.d.ts +10020 -1628
- package/dist/document-ops3d.d.ts.map +1 -1
- package/dist/document-ops3d.js +67 -6
- package/dist/document-ops3d.js.map +1 -1
- package/dist/environment-preset-ops3d.d.ts +4 -0
- package/dist/environment-preset-ops3d.d.ts.map +1 -0
- package/dist/environment-preset-ops3d.js +43 -0
- package/dist/environment-preset-ops3d.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/material-references3d.d.ts +3 -0
- package/dist/material-references3d.d.ts.map +1 -0
- package/dist/material-references3d.js +61 -0
- package/dist/material-references3d.js.map +1 -0
- package/dist/ownership-ops.d.ts +5 -0
- package/dist/ownership-ops.d.ts.map +1 -1
- package/dist/ownership-ops.js +30 -5
- package/dist/ownership-ops.js.map +1 -1
- package/dist/player-saves.d.ts +99 -0
- package/dist/player-saves.d.ts.map +1 -0
- package/dist/player-saves.js +246 -0
- package/dist/player-saves.js.map +1 -0
- package/dist/script-declarations.js +1 -1
- package/dist/script-lifecycle.js +1 -1
- package/dist/script-lifecycle.js.map +1 -1
- package/dist/script-log.d.ts +47 -0
- package/dist/script-log.d.ts.map +1 -0
- package/dist/script-log.js +86 -0
- package/dist/script-log.js.map +1 -0
- package/dist/script-reload.d.ts +21 -0
- package/dist/script-reload.d.ts.map +1 -0
- package/dist/script-reload.js +72 -0
- package/dist/script-reload.js.map +1 -0
- package/dist/script-saves.d.ts +33 -0
- package/dist/script-saves.d.ts.map +1 -0
- package/dist/script-saves.js +60 -0
- package/dist/script-saves.js.map +1 -0
- package/dist/script-types.d.ts.map +1 -1
- package/dist/script-types.js +6 -1
- package/dist/script-types.js.map +1 -1
- package/dist/script-types3d.d.ts.map +1 -1
- package/dist/script-types3d.js +6 -2
- package/dist/script-types3d.js.map +1 -1
- package/dist/scripts.d.ts +24 -2
- package/dist/scripts.d.ts.map +1 -1
- package/dist/scripts.js +79 -4
- package/dist/scripts.js.map +1 -1
- package/dist/scripts3d.d.ts.map +1 -1
- package/dist/scripts3d.js +1 -0
- package/dist/scripts3d.js.map +1 -1
- package/dist/session.d.ts +22 -1
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +60 -8
- package/dist/session.js.map +1 -1
- package/dist/session3d.d.ts +21 -4
- package/dist/session3d.d.ts.map +1 -1
- package/dist/session3d.js +74 -11
- package/dist/session3d.js.map +1 -1
- package/dist/spatial3d/materials.d.ts +17 -0
- package/dist/spatial3d/materials.d.ts.map +1 -0
- package/dist/spatial3d/materials.js +70 -0
- package/dist/spatial3d/materials.js.map +1 -0
- package/dist/spatial3d/script-commands.d.ts +7 -0
- package/dist/spatial3d/script-commands.d.ts.map +1 -0
- package/dist/spatial3d/script-commands.js +19 -0
- package/dist/spatial3d/script-commands.js.map +1 -0
- package/dist/spatial3d/world.d.ts +5 -0
- package/dist/spatial3d/world.d.ts.map +1 -1
- package/dist/spatial3d/world.js +80 -4
- package/dist/spatial3d/world.js.map +1 -1
- package/dist/systems/animation-graph3d.d.ts.map +1 -1
- package/dist/systems/animation-graph3d.js +6 -1
- package/dist/systems/animation-graph3d.js.map +1 -1
- package/dist/systems/context2d.d.ts +4 -0
- package/dist/systems/context2d.d.ts.map +1 -1
- package/dist/systems/context3d.d.ts +8 -1
- package/dist/systems/context3d.d.ts.map +1 -1
- package/dist/systems/gameplay3d.d.ts.map +1 -1
- package/dist/systems/gameplay3d.js +2 -1
- package/dist/systems/gameplay3d.js.map +1 -1
- package/dist/systems/presentation2d.d.ts +1 -1
- package/dist/systems/presentation2d.d.ts.map +1 -1
- package/dist/systems/presentation2d.js +6 -0
- package/dist/systems/presentation2d.js.map +1 -1
- package/dist/systems/presentation3d.d.ts +3 -3
- package/dist/systems/presentation3d.d.ts.map +1 -1
- package/dist/systems/presentation3d.js +27 -2
- package/dist/systems/presentation3d.js.map +1 -1
- package/dist/systems/scripts2d.d.ts.map +1 -1
- package/dist/systems/scripts2d.js +17 -8
- package/dist/systems/scripts2d.js.map +1 -1
- package/dist/systems/scripts3d.d.ts.map +1 -1
- package/dist/systems/scripts3d.js +26 -6
- package/dist/systems/scripts3d.js.map +1 -1
- package/dist/validate.d.ts +2 -0
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +6 -2
- package/dist/validate.js.map +1 -1
- package/dist/validate3d.d.ts +3 -0
- package/dist/validate3d.d.ts.map +1 -1
- package/dist/validate3d.js +20 -4
- package/dist/validate3d.js.map +1 -1
- package/package.json +14 -5
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Script log lines kept per tick. Later lines in the same tick collapse into one overflow line. */
|
|
3
|
+
export const GAME_SCRIPT_LOG_LIMIT = 32;
|
|
4
|
+
/**
|
|
5
|
+
* UTF-16 code units kept from one log message, cut back to a code-point boundary. Longer messages are truncated.
|
|
6
|
+
* Log text still counts toward the 64 KiB output limit of a script call, which fails the call when exceeded.
|
|
7
|
+
*/
|
|
8
|
+
export const GAME_SCRIPT_LOG_MESSAGE_LIMIT = 1000;
|
|
9
|
+
/**
|
|
10
|
+
* A script command that writes a line to the editor console. It never reaches the simulation: the runner
|
|
11
|
+
* removes it from the call's commands, so it does not count against `maxCommands` or enter snapshots or replay state.
|
|
12
|
+
*/
|
|
13
|
+
export const gameScriptLogCommand = z.strictObject({
|
|
14
|
+
kind: z.literal("log"),
|
|
15
|
+
message: z.string(),
|
|
16
|
+
level: z.enum(["log", "warning", "error"]).optional()
|
|
17
|
+
});
|
|
18
|
+
/** Collects one tick's log lines with the per-tick and per-message limits applied. */
|
|
19
|
+
export class GameScriptLogCollector {
|
|
20
|
+
tick;
|
|
21
|
+
lines = [];
|
|
22
|
+
dropped = 0;
|
|
23
|
+
constructor(tick) {
|
|
24
|
+
this.tick = tick;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Removes log commands from a call's raw output commands and records them. Other commands keep their order.
|
|
28
|
+
* Returns the input array unchanged when it holds no log command.
|
|
29
|
+
*/
|
|
30
|
+
collect(entityId, commands) {
|
|
31
|
+
if (!Array.isArray(commands) || !commands.some(isLogCommand)) {
|
|
32
|
+
return commands;
|
|
33
|
+
}
|
|
34
|
+
const rest = [];
|
|
35
|
+
for (const [index, command] of commands.entries()) {
|
|
36
|
+
if (!isLogCommand(command)) {
|
|
37
|
+
rest.push(command);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const parsed = gameScriptLogCommand.safeParse(command);
|
|
41
|
+
if (!parsed.success) {
|
|
42
|
+
throw new Error(`Invalid log command at index ${index}: ${z.prettifyError(parsed.error)}`);
|
|
43
|
+
}
|
|
44
|
+
if (this.lines.length >= GAME_SCRIPT_LOG_LIMIT) {
|
|
45
|
+
this.dropped += 1;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const { message, level = "log" } = parsed.data;
|
|
49
|
+
this.lines.push({ tick: this.tick, entityId, level, message: truncateLogMessage(message) });
|
|
50
|
+
}
|
|
51
|
+
return rest;
|
|
52
|
+
}
|
|
53
|
+
entries() {
|
|
54
|
+
if (this.dropped === 0) {
|
|
55
|
+
return this.lines;
|
|
56
|
+
}
|
|
57
|
+
return [...this.lines, { tick: this.tick, level: "warning",
|
|
58
|
+
message: `${this.dropped} more script log ${this.dropped === 1 ? "line" : "lines"} dropped at tick ${this.tick} (limit ${GAME_SCRIPT_LOG_LIMIT} per tick)` }];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function truncateLogMessage(message) {
|
|
62
|
+
if (message.length <= GAME_SCRIPT_LOG_MESSAGE_LIMIT) {
|
|
63
|
+
return message;
|
|
64
|
+
}
|
|
65
|
+
const last = message.charCodeAt(GAME_SCRIPT_LOG_MESSAGE_LIMIT - 1);
|
|
66
|
+
// Never keep the high half of a surrogate pair without its low half.
|
|
67
|
+
const end = last >= 0xd800 && last <= 0xdbff ? GAME_SCRIPT_LOG_MESSAGE_LIMIT - 1 : GAME_SCRIPT_LOG_MESSAGE_LIMIT;
|
|
68
|
+
return `${message.slice(0, end)}…`;
|
|
69
|
+
}
|
|
70
|
+
const SCRIPT_LOGS = Symbol("gameScriptLogs");
|
|
71
|
+
/** Attaches the lines logged before a failure to the thrown error, unless it already carries some. */
|
|
72
|
+
export function withGameScriptLogs(error, logs) {
|
|
73
|
+
if (logs === undefined || logs.length === 0 || !(error instanceof Error) || SCRIPT_LOGS in error) {
|
|
74
|
+
return error;
|
|
75
|
+
}
|
|
76
|
+
Object.defineProperty(error, SCRIPT_LOGS, { value: logs });
|
|
77
|
+
return error;
|
|
78
|
+
}
|
|
79
|
+
/** The script log lines of a failed tick, logged before the failure. */
|
|
80
|
+
export function gameScriptLogsOf(error) {
|
|
81
|
+
return error instanceof Error && SCRIPT_LOGS in error ? error[SCRIPT_LOGS] : undefined;
|
|
82
|
+
}
|
|
83
|
+
function isLogCommand(command) {
|
|
84
|
+
return typeof command === "object" && command !== null && command.kind === "log";
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=script-log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script-log.js","sourceRoot":"","sources":["../src/script-log.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,oGAAoG;AACpG,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACxC;;;GAGG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,IAAI,CAAC;AAElD;;;GAGG;AACH,MAAM,CAAC,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,MAAM,WAAW,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAE7C,sGAAsG;AACtG,MAAM,UAAU,kBAAkB,CAAC,KAAc,EAAE,IAA+C;IAChG,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,IAAI,WAAW,IAAI,KAAK,EAAE,CAAC;QAAC,OAAO,KAAK,CAAC;IAAC,CAAC;IACnH,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3D,OAAO,KAAK,CAAC;AACf,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,OAAO,KAAK,YAAY,KAAK,IAAI,WAAW,IAAI,KAAK,CAAC,CAAC,CAAE,KAAkE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACvJ,CAAC;AAED,SAAS,YAAY,CAAC,OAAgB;IACpC,OAAO,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,IAAK,OAA8B,CAAC,IAAI,KAAK,KAAK,CAAC;AAC3G,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AnyGameDocument } from "@nodetool-ai/protocol";
|
|
2
|
+
import { type GameScriptSourceUpdate } from "./scripts.js";
|
|
3
|
+
export type GameScriptReloadResult<Document> = {
|
|
4
|
+
readonly ok: true;
|
|
5
|
+
readonly changed: boolean;
|
|
6
|
+
readonly document: Document;
|
|
7
|
+
} | {
|
|
8
|
+
readonly ok: false;
|
|
9
|
+
readonly error: string;
|
|
10
|
+
};
|
|
11
|
+
/** Serializes source-only reloads and commits their document identity with the compiled sources. */
|
|
12
|
+
export declare function createGameScriptReloader<Document extends AnyGameDocument>(options: {
|
|
13
|
+
readonly initialRevision: string;
|
|
14
|
+
readonly current: () => Document;
|
|
15
|
+
readonly parse: (candidate: Document) => Document;
|
|
16
|
+
readonly assertAvailable: () => void;
|
|
17
|
+
/** Snapshot identity may include resolved runtime fields that authored documents cannot store. */
|
|
18
|
+
readonly snapshotDigest?: (document: Document) => Promise<string>;
|
|
19
|
+
readonly commit: (document: Document, updates: readonly GameScriptSourceUpdate[], digest: string) => void;
|
|
20
|
+
}): (candidate: Document, signal?: AbortSignal) => Promise<GameScriptReloadResult<Document>>;
|
|
21
|
+
//# sourceMappingURL=script-reload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script-reload.d.ts","sourceRoot":"","sources":["../src/script-reload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAmB,KAAK,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAG5E,MAAM,MAAM,sBAAsB,CAAC,QAAQ,IACvC;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,GAC7E;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnD,oGAAoG;AACpG,wBAAgB,wBAAwB,CAAC,QAAQ,SAAS,eAAe,EAAE,OAAO,EAAE;IAClF,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,QAAQ,CAAC;IACjC,QAAQ,CAAC,KAAK,EAAE,CAAC,SAAS,EAAE,QAAQ,KAAK,QAAQ,CAAC;IAClD,QAAQ,CAAC,eAAe,EAAE,MAAM,IAAI,CAAC;IACrC,kGAAkG;IAClG,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAClE,QAAQ,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,sBAAsB,EAAE,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3G,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,sBAAsB,CAAC,QAAQ,CAAC,CAAC,CA0D3F"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { scriptSourceKey } from "./scripts.js";
|
|
2
|
+
import { digestGame3D } from "./spatial3d/digest.js";
|
|
3
|
+
/** Serializes source-only reloads and commits their document identity with the compiled sources. */
|
|
4
|
+
export function createGameScriptReloader(options) {
|
|
5
|
+
let pending = Promise.resolve();
|
|
6
|
+
return (candidate, signal) => {
|
|
7
|
+
const captured = structuredClone(candidate);
|
|
8
|
+
const task = pending.then(async () => {
|
|
9
|
+
try {
|
|
10
|
+
options.assertAvailable();
|
|
11
|
+
signal?.throwIfAborted();
|
|
12
|
+
const current = options.current();
|
|
13
|
+
const parsed = options.parse(captured);
|
|
14
|
+
const normalized = structuredClone(parsed);
|
|
15
|
+
normalized.revision = current.revision;
|
|
16
|
+
const updates = [];
|
|
17
|
+
const compare = (before, after, sceneId) => {
|
|
18
|
+
before.forEach((entity, entityIndex) => {
|
|
19
|
+
const next = after[entityIndex];
|
|
20
|
+
if (next?.id !== entity.id) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
entity.behaviors.forEach((behavior, index) => {
|
|
24
|
+
const replacement = next.behaviors[index];
|
|
25
|
+
if (behavior.kind === "script" && replacement?.kind === "script") {
|
|
26
|
+
if (behavior.source !== replacement.source) {
|
|
27
|
+
updates.push({ sourceKey: scriptSourceKey(sceneId, entity.id, index), source: replacement.source });
|
|
28
|
+
replacement.source = behavior.source;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
current.scenes.forEach((scene, index) => {
|
|
35
|
+
const next = normalized.scenes[index];
|
|
36
|
+
if (next?.id === scene.id) {
|
|
37
|
+
compare(scene.entities, next.entities, scene.id);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
if (current.schemaVersion === 3 && normalized.schemaVersion === 3) {
|
|
41
|
+
for (const [id, prefab] of Object.entries(current.prefabs)) {
|
|
42
|
+
const next = normalized.prefabs[id];
|
|
43
|
+
if (next) {
|
|
44
|
+
compare(prefab.entities, next.entities, `prefab:${id}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (await digestGame3D(normalized) !== await digestGame3D(current)) {
|
|
49
|
+
throw new Error("Live reload accepts only existing script source edits. Restart from tick 0 for other changes");
|
|
50
|
+
}
|
|
51
|
+
options.assertAvailable();
|
|
52
|
+
signal?.throwIfAborted();
|
|
53
|
+
if (updates.length === 0) {
|
|
54
|
+
return { ok: true, changed: false, document: structuredClone(current) };
|
|
55
|
+
}
|
|
56
|
+
parsed.revision = options.initialRevision;
|
|
57
|
+
parsed.revision = `script:${await digestGame3D(parsed)}`;
|
|
58
|
+
const digest = await (options.snapshotDigest?.(parsed) ?? digestGame3D(parsed));
|
|
59
|
+
options.assertAvailable();
|
|
60
|
+
signal?.throwIfAborted();
|
|
61
|
+
options.commit(parsed, updates, digest);
|
|
62
|
+
return { ok: true, changed: true, document: structuredClone(parsed) };
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
pending = task;
|
|
69
|
+
return task;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=script-reload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script-reload.js","sourceRoot":"","sources":["../src/script-reload.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAA+B,M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,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type GameSaveData, type GameSaveScope } from "@nodetool-ai/protocol";
|
|
2
|
+
/**
|
|
3
|
+
* A save or load a script asked for during a tick. The host performs it after the tick, outside the simulation.
|
|
4
|
+
* Requests never enter snapshots, events or replay state. A load's result reaches scripts on a later input frame.
|
|
5
|
+
*/
|
|
6
|
+
export type GameSaveRequest = {
|
|
7
|
+
readonly kind: "save";
|
|
8
|
+
readonly tick: number;
|
|
9
|
+
readonly entityId: string;
|
|
10
|
+
readonly scope: GameSaveScope;
|
|
11
|
+
readonly slot: string;
|
|
12
|
+
readonly data: GameSaveData;
|
|
13
|
+
readonly snapshot: boolean;
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: "load";
|
|
16
|
+
readonly tick: number;
|
|
17
|
+
readonly entityId: string;
|
|
18
|
+
readonly scope: GameSaveScope;
|
|
19
|
+
readonly slot: string;
|
|
20
|
+
};
|
|
21
|
+
/** Collects one tick's save and load commands, at most `MAX_GAME_SAVE_REQUESTS_PER_TICK` across all calls. */
|
|
22
|
+
export declare class GameScriptSaveCollector {
|
|
23
|
+
private readonly tick;
|
|
24
|
+
private readonly requests;
|
|
25
|
+
constructor(tick: number);
|
|
26
|
+
/**
|
|
27
|
+
* Removes save and load commands from a call's raw output commands and records them in order.
|
|
28
|
+
* Returns the input array unchanged when it holds neither.
|
|
29
|
+
*/
|
|
30
|
+
collect(entityId: string, commands: unknown): unknown;
|
|
31
|
+
entries(): readonly GameSaveRequest[];
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=script-saves.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script-saves.d.ts","sourceRoot":"","sources":["../src/script-saves.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqE,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAGjJ;;;GAGG;AACH,MAAM,MAAM,eAAe,GACvB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAChI,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GACzD;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtI,8GAA8G;AAC9G,qBAAa,uBAAuB;IAGtB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAyB;IAElD,YAA6B,IAAI,EAAE,MAAM,EAAI;IAE7C;;;OAGG;IACH,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAsBpD;IAED,OAAO,IAAI,SAAS,eAAe,EAAE,CAEpC;CACF"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { gameLoadCommand, gameSaveCommand, MAX_GAME_SAVE_REQUESTS_PER_TICK } from "@nodetool-ai/protocol";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/** Collects one tick's save and load commands, at most `MAX_GAME_SAVE_REQUESTS_PER_TICK` across all calls. */
|
|
4
|
+
export class GameScriptSaveCollector {
|
|
5
|
+
tick;
|
|
6
|
+
requests = [];
|
|
7
|
+
constructor(tick) {
|
|
8
|
+
this.tick = tick;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Removes save and load commands from a call's raw output commands and records them in order.
|
|
12
|
+
* Returns the input array unchanged when it holds neither.
|
|
13
|
+
*/
|
|
14
|
+
collect(entityId, commands) {
|
|
15
|
+
if (!Array.isArray(commands) || !commands.some(isSaveCommand)) {
|
|
16
|
+
return commands;
|
|
17
|
+
}
|
|
18
|
+
const rest = [];
|
|
19
|
+
for (const [index, command] of commands.entries()) {
|
|
20
|
+
if (!isSaveCommand(command)) {
|
|
21
|
+
rest.push(command);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (this.requests.length >= MAX_GAME_SAVE_REQUESTS_PER_TICK) {
|
|
25
|
+
throw new Error(`Save and load commands exceed ${MAX_GAME_SAVE_REQUESTS_PER_TICK} per tick`);
|
|
26
|
+
}
|
|
27
|
+
const kind = command.kind;
|
|
28
|
+
if (kind === "save") {
|
|
29
|
+
const parsed = gameSaveCommand.safeParse(command);
|
|
30
|
+
if (!parsed.success) {
|
|
31
|
+
throw new Error(`Invalid save command at index ${index}: ${z.prettifyError(parsed.error)}`);
|
|
32
|
+
}
|
|
33
|
+
const { slot, data, scope = "progress", snapshot = false } = parsed.data;
|
|
34
|
+
if (scope === "settings" && snapshot) {
|
|
35
|
+
throw new Error(`Invalid save command at index ${index}: settings saves cannot store a snapshot`);
|
|
36
|
+
}
|
|
37
|
+
this.requests.push({ kind, tick: this.tick, entityId, scope, slot, data, snapshot });
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const parsed = gameLoadCommand.safeParse(command);
|
|
41
|
+
if (!parsed.success) {
|
|
42
|
+
throw new Error(`Invalid load command at index ${index}: ${z.prettifyError(parsed.error)}`);
|
|
43
|
+
}
|
|
44
|
+
this.requests.push({ kind, tick: this.tick, entityId, scope: parsed.data.scope ?? "progress", slot: parsed.data.slot });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return rest;
|
|
48
|
+
}
|
|
49
|
+
entries() {
|
|
50
|
+
return this.requests;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function isSaveCommand(command) {
|
|
54
|
+
if (typeof command !== "object" || command === null) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
const kind = command.kind;
|
|
58
|
+
return kind === "save" || kind === "load";
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=script-saves.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script-saves.js","sourceRoot":"","sources":["../src/script-saves.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,+BAA+B,EAAyC,MAAM,uBAAuB,CAAC;AACjJ,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAWxB,8GAA8G;AAC9G,MAAM,OAAO,uBAAuB;IAGL,IAAI;IAFhB,QAAQ,GAAsB,EAAE,CAAC;IAElD,YAA6B,IAAY;oBAAZ,IAAI;IAAW,CAAC;IAE7C;;;OAGG;IACH,OAAO,CAAC,QAAgB,EAAE,QAAiB;QACzC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;YAAC,OAAO,QAAQ,CAAC;QAAC,CAAC;QACnF,MAAM,IAAI,GAAc,EAAE,CAAC;QAC3B,KAAK,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;YAClD,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;gBAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBAAC,SAAS;YAAC,CAAC;YAC9D,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,IAAI,+BAA+B,EAAE,CAAC;gBAC5D,MAAM,IAAI,KAAK,CAAC,iCAAiC,+BAA+B,WAAW,CAAC,CAAC;YAC/F,CAAC;YACD,MAAM,IAAI,GAAI,OAAqC,CAAC,IAAI,CAAC;YACzD,IAAI,IAAI,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;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF;AAED,SAAS,aAAa,CAAC,OAAgB;IACrC,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QAAC,OAAO,KAAK,CAAC;IAAC,CAAC;IACtE,MAAM,IAAI,GAAI,OAA8B,CAAC,IAAI,CAAC;IAClD,OAAO,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,MAAM,CAAC;AAC5C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"script-types.d.ts","sourceRoot":"","sources":["../src/script-types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"script-types.d.ts","sourceRoot":"","sources":["../src/script-types.ts"],"names":[],"mappings":"AAOA,4EAA4E;AAC5E,eAAO,MAAM,iBAAiB,QAwB7B,CAAC;AAEF,2DAA2D;AAC3D,eAAO,MAAM,uBAAuB,QAEnC,CAAC;AAEF,gGAAgG;AAChG,eAAO,MAAM,2BAA2B,QAA4F,CAAC"}
|
package/dist/script-types.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { gameLoadCommand, gameSaveCommand } from "@nodetool-ai/protocol";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { gameScriptLogCommand } from "./script-log.js";
|
|
1
4
|
import { gameScriptCommand } from "./scripts.js";
|
|
2
5
|
import { gameScriptLifecycleDeclaration, gameScriptSchemaDeclaration, gameScriptWorldDeclaration } from "./script-declarations.js";
|
|
3
6
|
/** Monaco declarations for the native game function-expression contract. */
|
|
4
7
|
export const GAME_SCRIPT_TYPES = `
|
|
5
|
-
${gameScriptSchemaDeclaration("GameScriptCommand", gameScriptCommand)}
|
|
8
|
+
${gameScriptSchemaDeclaration("GameScriptCommand", z.union([gameScriptCommand, gameScriptLogCommand, gameSaveCommand, gameLoadCommand]))}
|
|
6
9
|
|
|
7
10
|
type JSONValue = string | number | boolean | null | JSONValue[] | { [key: string]: JSONValue };
|
|
8
11
|
type GameScriptParamValue = number | boolean | string | { x: number; y: number; z?: number } | null;
|
|
@@ -19,6 +22,8 @@ type GameScriptInput = {
|
|
|
19
22
|
random: () => number;
|
|
20
23
|
/** Present when the behavior declares params. Entity and asset params are IDs or null. */
|
|
21
24
|
params?: Readonly<Record<string, GameScriptParamValue>>;
|
|
25
|
+
/** Finished \`load\` commands from earlier ticks. data is null for an empty slot. */
|
|
26
|
+
loaded?: readonly { scope: "progress" | "settings"; slot: string; data: Record<string, JSONValue> | null }[];
|
|
22
27
|
};
|
|
23
28
|
|
|
24
29
|
type GameScriptResult = { state: unknown; commands: GameScriptCommand[] };
|
package/dist/script-types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"script-types.js","sourceRoot":"","sources":["../src/script-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,8BAA8B,EAAE,2BAA2B,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAEnI,4EAA4E;AAC5E,MAAM,CAAC,MAAM,iBAAiB,GAAG;EAC/B,2BAA2B,CAAC,mBAAmB,EAAE,iBAAiB,CAAC
|
|
1
|
+
{"version":3,"file":"script-types.js","sourceRoot":"","sources":["../src/script-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,8BAA8B,EAAE,2BAA2B,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAEnI,4EAA4E;AAC5E,MAAM,CAAC,MAAM,iBAAiB,GAAG;EAC/B,2BAA2B,CAAC,mBAAmB,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,iBAAiB,EAAE,oBAAoB,EAAE,eAAe,EAAE,eAAe,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;CAuBvI,CAAC;AAEF,2DAA2D;AAC3D,MAAM,CAAC,MAAM,uBAAuB,GAAG,0BAA0B,CAC/D,+GAA+G,CAChH,CAAC;AAEF,gGAAgG;AAChG,MAAM,CAAC,MAAM,2BAA2B,GAAG,8BAA8B,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,mBAAmB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"script-types3d.d.ts","sourceRoot":"","sources":["../src/script-types3d.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"script-types3d.d.ts","sourceRoot":"","sources":["../src/script-types3d.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,oBAAoB,QAsBhC,CAAC;AAEF,2DAA2D;AAC3D,eAAO,MAAM,0BAA0B,QAEtC,CAAC;AAEF,gGAAgG;AAChG,eAAO,MAAM,8BAA8B,QAAkG,CAAC"}
|
package/dist/script-types3d.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { gameQueryResult3D, gameScriptCommand3D } from "@nodetool-ai/protocol";
|
|
1
|
+
import { gameLoadCommand, gameQueryResult3D, gameSaveCommand, gameScriptCommand3D } from "@nodetool-ai/protocol";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { gameScriptLogCommand } from "./script-log.js";
|
|
2
4
|
import { gameScriptLifecycleDeclaration, gameScriptSchemaDeclaration, gameScriptWorldDeclaration } from "./script-declarations.js";
|
|
3
5
|
export const GAME_SCRIPT_TYPES_3D = `
|
|
4
6
|
type JSONValue = string | number | boolean | null | JSONValue[] | { [key: string]: JSONValue };
|
|
5
7
|
type Vector3 = { x: number; y: number; z: number };
|
|
6
8
|
type Quaternion3D = [number, number, number, number];
|
|
7
9
|
type GameScriptParamValue = number | boolean | string | { x: number; y: number; z?: number } | null;
|
|
8
|
-
${gameScriptSchemaDeclaration("GameScriptCommand3D", gameScriptCommand3D)}
|
|
10
|
+
${gameScriptSchemaDeclaration("GameScriptCommand3D", z.union([gameScriptCommand3D, gameScriptLogCommand, gameSaveCommand, gameLoadCommand]))}
|
|
9
11
|
${gameScriptSchemaDeclaration("GameQueryResult3D", gameQueryResult3D)}
|
|
10
12
|
|
|
11
13
|
type GameScriptWorldEntity3D = { id: string; source: string; position: Vector3; velocity: Vector3; grounded: boolean; tags: readonly string[]; props: Readonly<Record<string, JSONValue>>; rotation: Quaternion3D; active: boolean };
|
|
@@ -17,6 +19,8 @@ type GameScriptInput3D = {
|
|
|
17
19
|
entity: GameScriptWorldEntity3D; world: readonly GameScriptWorldEntity3D[]; state: unknown; random: () => number;
|
|
18
20
|
/** Present when the behavior declares params. Entity and asset params are IDs or null. */
|
|
19
21
|
params?: Readonly<Record<string, GameScriptParamValue>>;
|
|
22
|
+
/** Finished \`load\` commands from earlier ticks. data is null for an empty slot. */
|
|
23
|
+
loaded?: readonly { scope: "progress" | "settings"; slot: string; data: Record<string, JSONValue> | null }[];
|
|
20
24
|
};
|
|
21
25
|
type GameScriptResult3D = { state: unknown; commands: GameScriptCommand3D[] };
|
|
22
26
|
type GameScript3D = (input: GameScriptInput3D) => GameScriptResult3D;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"script-types3d.js","sourceRoot":"","sources":["../src/script-types3d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"script-types3d.js","sourceRoot":"","sources":["../src/script-types3d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,8BAA8B,EAAE,2BAA2B,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAEnI,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;EAKlC,2BAA2B,CAAC,qBAAqB,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,mBAAmB,EAAE,oBAAoB,EAAE,eAAe,EAAE,eAAe,CAAC,CAAC,CAAC;EAC1I,2BAA2B,CAAC,mBAAmB,EAAE,iBAAiB,CAAC;;;;;;;;;;;;;;;;CAgBpE,CAAC;AAEF,2DAA2D;AAC3D,MAAM,CAAC,MAAM,0BAA0B,GAAG,0BAA0B,CAClE,yFAAyF,CAC1F,CAAC;AAEF,gGAAgG;AAChG,MAAM,CAAC,MAAM,8BAA8B,GAAG,8BAA8B,CAAC,mBAAmB,EAAE,mBAAmB,EAAE,qBAAqB,CAAC,CAAC"}
|
package/dist/scripts.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { type GameDocument, type GameEntityProps, type GameScriptParam, type GameScriptParamValue, type GameSnapshot } from "@nodetool-ai/protocol";
|
|
2
|
+
import { type GameDocument, type GameEntityProps, type GameInputFrame, type GameScriptParam, type GameScriptParamValue, type GameSnapshot } from "@nodetool-ai/protocol";
|
|
3
|
+
import { type GameScriptLogEntry } from "./script-log.js";
|
|
4
|
+
import { type GameSaveRequest } from "./script-saves.js";
|
|
3
5
|
import { type ScriptCallClock } from "./script-clock.js";
|
|
4
6
|
import { type GameScriptLifecycle } from "./script-lifecycle.js";
|
|
5
7
|
import { type ScriptWorldEntity } from "./script-world.js";
|
|
@@ -89,7 +91,9 @@ export interface GameScriptCall {
|
|
|
89
91
|
readonly velocityX: number;
|
|
90
92
|
readonly velocityY: number;
|
|
91
93
|
readonly touching: GameScriptTouching;
|
|
92
|
-
/**
|
|
94
|
+
/** Final properties retained for a destruction call after removal. */
|
|
95
|
+
readonly props?: GameEntityProps;
|
|
96
|
+
/** Schema 4 metadata. Active props travel once per entity in `GameScriptInput.props`. */
|
|
93
97
|
readonly tags?: readonly string[];
|
|
94
98
|
readonly rotation?: number;
|
|
95
99
|
readonly active?: boolean;
|
|
@@ -123,6 +127,10 @@ export interface GameScriptBatch {
|
|
|
123
127
|
readonly results: readonly GameScriptResult[];
|
|
124
128
|
readonly rngState: number;
|
|
125
129
|
readonly stats: GameScriptStats;
|
|
130
|
+
/** The tick's `log` command lines, present when a script logged. Never part of simulation state. */
|
|
131
|
+
readonly logs?: readonly GameScriptLogEntry[];
|
|
132
|
+
/** The tick's `save` and `load` commands, present when a script issued one. Never part of simulation state. */
|
|
133
|
+
readonly saves?: readonly GameSaveRequest[];
|
|
126
134
|
}
|
|
127
135
|
/** An active entity with a collider or camera, as every script sees it this tick. */
|
|
128
136
|
export interface GameScriptWorldEntity {
|
|
@@ -140,6 +148,8 @@ export interface GameScriptInput {
|
|
|
140
148
|
readonly justPressed: readonly string[];
|
|
141
149
|
readonly events: readonly unknown[];
|
|
142
150
|
readonly world: readonly GameScriptWorldEntity[];
|
|
151
|
+
/** Finished save loads from the input frame. Absent on ticks without one. */
|
|
152
|
+
readonly loaded?: GameInputFrame["loaded"];
|
|
143
153
|
/** Schema 4: non-empty props of the tick's entities, keyed by entity id and sent once. */
|
|
144
154
|
readonly props?: Readonly<Record<string, GameEntityProps>>;
|
|
145
155
|
}
|
|
@@ -150,8 +160,14 @@ export interface GameScriptRunner {
|
|
|
150
160
|
/** Lifecycle source keys whose object defines `onEvent`. */
|
|
151
161
|
readonly eventSources?: ReadonlySet<string>;
|
|
152
162
|
retain?(stateKeys: ReadonlySet<string>): void;
|
|
163
|
+
/** Compiles every replacement before changing sources or retained realms. */
|
|
164
|
+
reloadSources(updates: readonly GameScriptSourceUpdate[]): void;
|
|
153
165
|
dispose(): void;
|
|
154
166
|
}
|
|
167
|
+
export interface GameScriptSourceUpdate {
|
|
168
|
+
readonly sourceKey: string;
|
|
169
|
+
readonly source: string;
|
|
170
|
+
}
|
|
155
171
|
export declare function scriptSourceKey(sceneId: string, entityId: string, behaviorIndex: number): string;
|
|
156
172
|
export declare function hasGameScripts(document: GameDocument): boolean;
|
|
157
173
|
export interface GameScriptOptions {
|
|
@@ -163,6 +179,8 @@ export interface GameScriptOptions {
|
|
|
163
179
|
}
|
|
164
180
|
/** Only proven input-only functions may retain their context between calls. */
|
|
165
181
|
export interface IsolatedScriptCall {
|
|
182
|
+
/** Final properties retained for a destruction call after removal. */
|
|
183
|
+
readonly props?: GameEntityProps;
|
|
166
184
|
readonly sourceKey: string;
|
|
167
185
|
readonly stateKey: string;
|
|
168
186
|
readonly entityId: string;
|
|
@@ -190,12 +208,16 @@ export interface IsolatedScriptRunner<Call extends IsolatedScriptCall, Input ext
|
|
|
190
208
|
}[];
|
|
191
209
|
readonly rngState: number;
|
|
192
210
|
readonly stats: GameScriptStats;
|
|
211
|
+
readonly logs?: readonly GameScriptLogEntry[];
|
|
212
|
+
readonly saves?: readonly GameSaveRequest[];
|
|
193
213
|
};
|
|
194
214
|
/** Source keys whose script is a lifecycle object rather than a function. */
|
|
195
215
|
readonly hookSources?: ReadonlySet<string>;
|
|
196
216
|
/** Lifecycle source keys whose object defines `onEvent`. */
|
|
197
217
|
readonly eventSources?: ReadonlySet<string>;
|
|
198
218
|
retain?(stateKeys: ReadonlySet<string>): void;
|
|
219
|
+
/** Compiles every replacement before changing sources or retained realms. */
|
|
220
|
+
reloadSources(updates: readonly GameScriptSourceUpdate[]): void;
|
|
199
221
|
dispose(): void;
|
|
200
222
|
}
|
|
201
223
|
interface ScriptDefinitions {
|
package/dist/scripts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scripts.d.ts","sourceRoot":"","sources":["../src/scripts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC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AAE,OAAO,CAAC,CAAC,CA2arD;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAYjH"}
|
package/dist/scripts.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { gameNonSpatialScriptCommand, gameUiScriptCommand, resolveGameScriptParams } from "@nodetool-ai/protocol";
|
|
2
|
+
import { gameBehavior, gameNonSpatialScriptCommand, gameUiScriptCommand, resolveGameScriptParams } from "@nodetool-ai/protocol";
|
|
3
|
+
import { GameScriptLogCollector, withGameScriptLogs } from "./script-log.js";
|
|
4
|
+
import { GameScriptSaveCollector } from "./script-saves.js";
|
|
3
5
|
import { defaultScriptCallClock, startScriptCallTimer } from "./script-clock.js";
|
|
4
6
|
import { commitScriptHooks, planScriptHooks, scriptHookIssue, SCRIPT_LIFECYCLE_DISPATCH } from "./script-lifecycle.js";
|
|
5
7
|
import { canPersistGameScript } from "./script-persistence.js";
|
|
@@ -305,7 +307,7 @@ export async function prepareIsolatedGameScripts(document, commandSchema, payloa
|
|
|
305
307
|
});
|
|
306
308
|
}
|
|
307
309
|
}
|
|
308
|
-
const
|
|
310
|
+
const executeBatch = (calls, input, rngState, world, batchMs, logs, saves) => {
|
|
309
311
|
const started = performance.now();
|
|
310
312
|
const batchDeadline = started + batchMs;
|
|
311
313
|
// This limits the logical tick payload, which carries each entity's props once.
|
|
@@ -354,7 +356,7 @@ export async function prepareIsolatedGameScripts(document, commandSchema, payloa
|
|
|
354
356
|
const callJson = (call, plan) => {
|
|
355
357
|
// A lifecycle call shows its hooks the record's inner state and receives its hook steps instead of host facts.
|
|
356
358
|
const guest = plan === undefined ? call : { ...call, state: plan.state, lifecycle: undefined, steps: plan.steps };
|
|
357
|
-
return JSON.stringify(propsTable === undefined ? guest : { ...guest, props: propsOf(propsTable, call.entityId) });
|
|
359
|
+
return JSON.stringify(propsTable === undefined ? guest : { ...guest, props: call.lifecycle?.destroy ? call.props ?? propsOf(propsTable, call.entityId) : propsOf(propsTable, call.entityId) });
|
|
358
360
|
};
|
|
359
361
|
let hostWorld;
|
|
360
362
|
const getHostWorld = () => hostWorld ??= new ScriptWorldSnapshot(world ?? input.world, propsTable);
|
|
@@ -470,6 +472,15 @@ export async function prepareIsolatedGameScripts(document, commandSchema, payloa
|
|
|
470
472
|
throw new Error(`Output exceeds 64 KiB (${rawOutputBytes} bytes in call ${results.length + 1})`);
|
|
471
473
|
}
|
|
472
474
|
const parsed = JSON.parse(output);
|
|
475
|
+
// Log, save and load commands leave the output here, so they never reach the command limit, the systems or the snapshot.
|
|
476
|
+
const guestValue = typeof parsed === "object" && parsed !== null ? parsed.value : undefined;
|
|
477
|
+
if (typeof guestValue === "object" && guestValue !== null) {
|
|
478
|
+
const commands = guestValue.commands;
|
|
479
|
+
const simulated = saves.collect(call.entityId, logs.collect(call.entityId, commands));
|
|
480
|
+
if (simulated !== commands) {
|
|
481
|
+
guestValue.commands = simulated;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
473
484
|
const envelope = envelopeSchema.parse(parsed);
|
|
474
485
|
const value = plan === undefined ? envelope.value
|
|
475
486
|
: { state: commitScriptHooks(envelope.value.state, plan, input.tick), commands: envelope.value.commands };
|
|
@@ -514,7 +525,21 @@ export async function prepareIsolatedGameScripts(document, commandSchema, payloa
|
|
|
514
525
|
byEntity[call.entityId] = { durationMs: previous.durationMs + performance.now() - callStarted, calls: previous.calls + 1 };
|
|
515
526
|
}
|
|
516
527
|
assertBeforeDeadline(batchDeadline, batchBudget);
|
|
517
|
-
|
|
528
|
+
const stats = { durationMs: performance.now() - started, commands: commandCount, calls: calls.length, byEntity };
|
|
529
|
+
const lines = logs.entries();
|
|
530
|
+
const requests = saves.entries();
|
|
531
|
+
return { results, rngState: nextRngState, stats, ...(lines.length === 0 ? undefined : { logs: lines }),
|
|
532
|
+
...(requests.length === 0 ? undefined : { saves: requests }) };
|
|
533
|
+
};
|
|
534
|
+
// A failed batch carries the lines its calls logged before the failure.
|
|
535
|
+
const execute = (calls, input, rngState, world, batchMs) => {
|
|
536
|
+
const logs = new GameScriptLogCollector(input.tick);
|
|
537
|
+
try {
|
|
538
|
+
return executeBatch(calls, input, rngState, world, batchMs, logs, new GameScriptSaveCollector(input.tick));
|
|
539
|
+
}
|
|
540
|
+
catch (error) {
|
|
541
|
+
throw withGameScriptLogs(error, logs.entries());
|
|
542
|
+
}
|
|
518
543
|
};
|
|
519
544
|
const warmCalls = !warmedCommandSchemas.has(commandSchema);
|
|
520
545
|
const warmHooks = hookSources.size > 0 && !warmedHookSchemas.has(commandSchema);
|
|
@@ -556,6 +581,55 @@ export async function prepareIsolatedGameScripts(document, commandSchema, payloa
|
|
|
556
581
|
}
|
|
557
582
|
}
|
|
558
583
|
return {
|
|
584
|
+
reloadSources(updates) {
|
|
585
|
+
const candidates = [];
|
|
586
|
+
for (const update of updates) {
|
|
587
|
+
gameBehavior.options[9].shape.source.parse(update.source);
|
|
588
|
+
if (!sources.has(update.sourceKey)) {
|
|
589
|
+
throw new Error(`Unknown game script ${update.sourceKey}`);
|
|
590
|
+
}
|
|
591
|
+
const deadline = performance.now() + 100;
|
|
592
|
+
runtime.setInterruptHandler(() => performance.now() >= deadline);
|
|
593
|
+
const persistent = canPersistGameScript(update.source);
|
|
594
|
+
const inspected = inspectSource(update.sourceKey, update.source, persistent);
|
|
595
|
+
try {
|
|
596
|
+
if (inspected.hooks !== hookSources.has(update.sourceKey)) {
|
|
597
|
+
throw new Error("Changing between a function and lifecycle hooks requires restart from tick 0");
|
|
598
|
+
}
|
|
599
|
+
candidates.push({ update, persistent, onEvent: inspected.onEvent });
|
|
600
|
+
}
|
|
601
|
+
finally {
|
|
602
|
+
disposeRealm(inspected.realm);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
const changedKeys = new Set(candidates.map(({ update }) => update.sourceKey));
|
|
606
|
+
for (const { update, persistent, onEvent } of candidates) {
|
|
607
|
+
sources.set(update.sourceKey, update.source);
|
|
608
|
+
if (persistent) {
|
|
609
|
+
persistentSources.add(update.sourceKey);
|
|
610
|
+
}
|
|
611
|
+
else {
|
|
612
|
+
persistentSources.delete(update.sourceKey);
|
|
613
|
+
}
|
|
614
|
+
if (onEvent) {
|
|
615
|
+
eventSources.add(update.sourceKey);
|
|
616
|
+
}
|
|
617
|
+
else {
|
|
618
|
+
eventSources.delete(update.sourceKey);
|
|
619
|
+
}
|
|
620
|
+
const realm = prepared.get(update.sourceKey);
|
|
621
|
+
if (realm) {
|
|
622
|
+
disposeRealm(realm);
|
|
623
|
+
prepared.delete(update.sourceKey);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
for (const [stateKey, realm] of realms) {
|
|
627
|
+
if (changedKeys.has(realm.sourceKey)) {
|
|
628
|
+
disposeRealm(realm);
|
|
629
|
+
realms.delete(stateKey);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
},
|
|
559
633
|
hookSources,
|
|
560
634
|
eventSources,
|
|
561
635
|
retain,
|
|
@@ -597,6 +671,7 @@ export function prepareGameScripts(document, options) {
|
|
|
597
671
|
...(data.call.props === undefined ? undefined
|
|
598
672
|
: { tags: data.call.tags, props: data.call.props, rotation: data.call.rotation, active: data.call.active })
|
|
599
673
|
}, world: data.input.world, state: data.call.state, random: __gameRandom,
|
|
674
|
+
...(data.input.loaded === undefined ? undefined : { loaded: data.input.loaded }),
|
|
600
675
|
...(data.params === undefined ? undefined : { params: data.params })
|
|
601
676
|
}`, options);
|
|
602
677
|
}
|