@nodetool-ai/game-runtime 0.8.3 → 0.8.4-a13.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.
Files changed (108) hide show
  1. package/README.md +65 -0
  2. package/dist/.nodetool-build-stamp +1 -1
  3. package/dist/authoring-reconcile.d.ts.map +1 -1
  4. package/dist/authoring-reconcile.js +5 -3
  5. package/dist/authoring-reconcile.js.map +1 -1
  6. package/dist/document-ops.d.ts +1102 -0
  7. package/dist/document-ops.d.ts.map +1 -1
  8. package/dist/document-ops3d.d.ts +10005 -1631
  9. package/dist/document-ops3d.d.ts.map +1 -1
  10. package/dist/document-ops3d.js +60 -6
  11. package/dist/document-ops3d.js.map +1 -1
  12. package/dist/index.d.ts +5 -0
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +4 -0
  15. package/dist/index.js.map +1 -1
  16. package/dist/material-references3d.d.ts +3 -0
  17. package/dist/material-references3d.d.ts.map +1 -0
  18. package/dist/material-references3d.js +61 -0
  19. package/dist/material-references3d.js.map +1 -0
  20. package/dist/ownership-ops.d.ts +5 -0
  21. package/dist/ownership-ops.d.ts.map +1 -1
  22. package/dist/ownership-ops.js +30 -5
  23. package/dist/ownership-ops.js.map +1 -1
  24. package/dist/player-saves.d.ts +99 -0
  25. package/dist/player-saves.d.ts.map +1 -0
  26. package/dist/player-saves.js +246 -0
  27. package/dist/player-saves.js.map +1 -0
  28. package/dist/script-declarations.js +1 -1
  29. package/dist/script-lifecycle.js +1 -1
  30. package/dist/script-lifecycle.js.map +1 -1
  31. package/dist/script-log.d.ts +47 -0
  32. package/dist/script-log.d.ts.map +1 -0
  33. package/dist/script-log.js +86 -0
  34. package/dist/script-log.js.map +1 -0
  35. package/dist/script-reload.d.ts +21 -0
  36. package/dist/script-reload.d.ts.map +1 -0
  37. package/dist/script-reload.js +72 -0
  38. package/dist/script-reload.js.map +1 -0
  39. package/dist/script-saves.d.ts +33 -0
  40. package/dist/script-saves.d.ts.map +1 -0
  41. package/dist/script-saves.js +60 -0
  42. package/dist/script-saves.js.map +1 -0
  43. package/dist/script-types.d.ts.map +1 -1
  44. package/dist/script-types.js +6 -1
  45. package/dist/script-types.js.map +1 -1
  46. package/dist/script-types3d.d.ts.map +1 -1
  47. package/dist/script-types3d.js +6 -2
  48. package/dist/script-types3d.js.map +1 -1
  49. package/dist/scripts.d.ts +24 -2
  50. package/dist/scripts.d.ts.map +1 -1
  51. package/dist/scripts.js +79 -4
  52. package/dist/scripts.js.map +1 -1
  53. package/dist/scripts3d.d.ts.map +1 -1
  54. package/dist/scripts3d.js +1 -0
  55. package/dist/scripts3d.js.map +1 -1
  56. package/dist/session.d.ts +22 -1
  57. package/dist/session.d.ts.map +1 -1
  58. package/dist/session.js +60 -8
  59. package/dist/session.js.map +1 -1
  60. package/dist/session3d.d.ts +21 -4
  61. package/dist/session3d.d.ts.map +1 -1
  62. package/dist/session3d.js +74 -11
  63. package/dist/session3d.js.map +1 -1
  64. package/dist/spatial3d/materials.d.ts +17 -0
  65. package/dist/spatial3d/materials.d.ts.map +1 -0
  66. package/dist/spatial3d/materials.js +70 -0
  67. package/dist/spatial3d/materials.js.map +1 -0
  68. package/dist/spatial3d/script-commands.d.ts +7 -0
  69. package/dist/spatial3d/script-commands.d.ts.map +1 -0
  70. package/dist/spatial3d/script-commands.js +19 -0
  71. package/dist/spatial3d/script-commands.js.map +1 -0
  72. package/dist/spatial3d/world.d.ts +5 -0
  73. package/dist/spatial3d/world.d.ts.map +1 -1
  74. package/dist/spatial3d/world.js +80 -4
  75. package/dist/spatial3d/world.js.map +1 -1
  76. package/dist/systems/animation-graph3d.d.ts.map +1 -1
  77. package/dist/systems/animation-graph3d.js +6 -1
  78. package/dist/systems/animation-graph3d.js.map +1 -1
  79. package/dist/systems/context2d.d.ts +4 -0
  80. package/dist/systems/context2d.d.ts.map +1 -1
  81. package/dist/systems/context3d.d.ts +8 -1
  82. package/dist/systems/context3d.d.ts.map +1 -1
  83. package/dist/systems/gameplay3d.d.ts.map +1 -1
  84. package/dist/systems/gameplay3d.js +2 -1
  85. package/dist/systems/gameplay3d.js.map +1 -1
  86. package/dist/systems/presentation2d.d.ts +1 -1
  87. package/dist/systems/presentation2d.d.ts.map +1 -1
  88. package/dist/systems/presentation2d.js +6 -0
  89. package/dist/systems/presentation2d.js.map +1 -1
  90. package/dist/systems/presentation3d.d.ts +3 -3
  91. package/dist/systems/presentation3d.d.ts.map +1 -1
  92. package/dist/systems/presentation3d.js +27 -2
  93. package/dist/systems/presentation3d.js.map +1 -1
  94. package/dist/systems/scripts2d.d.ts.map +1 -1
  95. package/dist/systems/scripts2d.js +17 -8
  96. package/dist/systems/scripts2d.js.map +1 -1
  97. package/dist/systems/scripts3d.d.ts.map +1 -1
  98. package/dist/systems/scripts3d.js +26 -6
  99. package/dist/systems/scripts3d.js.map +1 -1
  100. package/dist/validate.d.ts +2 -0
  101. package/dist/validate.d.ts.map +1 -1
  102. package/dist/validate.js +6 -2
  103. package/dist/validate.js.map +1 -1
  104. package/dist/validate3d.d.ts +3 -0
  105. package/dist/validate3d.d.ts.map +1 -1
  106. package/dist/validate3d.js +20 -4
  107. package/dist/validate3d.js.map +1 -1
  108. package/package.json +14 -5
@@ -0,0 +1,99 @@
1
+ import { type GameSaveData, type GameSaveLoaded, type GameSaveScope } from "@nodetool-ai/protocol";
2
+ import type { GameSaveRequest } from "./script-saves.js";
3
+ /** One stored save. `snapshot` is a full session snapshot and only appears on progress saves. */
4
+ export interface GameSaveRecord {
5
+ readonly version: 1;
6
+ readonly data: GameSaveData;
7
+ readonly snapshot?: unknown;
8
+ }
9
+ /**
10
+ * Per-game save storage. Progress and settings saves live in separate scopes, so a slot name can exist in both
11
+ * and removing one never touches the other. Implementations return records as stored. `GamePlayerSaves` validates them.
12
+ */
13
+ export interface GameSaveStorage {
14
+ read(scope: GameSaveScope, slot: string): Promise<unknown>;
15
+ write(scope: GameSaveScope, slot: string, record: GameSaveRecord, options?: {
16
+ readonly onlyIfEmpty?: boolean;
17
+ readonly maxSlots?: number;
18
+ }): Promise<void | boolean>;
19
+ remove(scope: GameSaveScope, slot: string): Promise<void>;
20
+ slots(scope: GameSaveScope): Promise<readonly string[]>;
21
+ }
22
+ /** Storage that lives as long as the object. Headless sessions, the CLI and agent playtests use it so runs stay repeatable. */
23
+ export declare function createMemoryGameSaveStorage(): GameSaveStorage & {
24
+ entries(): Record<GameSaveScope, Record<string, GameSaveRecord>>;
25
+ };
26
+ /**
27
+ * Storage operations that may wait in one `GamePlayerSaves` queue, counting the one running. A script can request 4
28
+ * saves or loads per tick at 60 ticks per second, so a slow store fills the queue in a few ticks. Further operations
29
+ * are rejected instead of piling up behind it.
30
+ */
31
+ export declare const MAX_GAME_SAVE_QUEUE = 8;
32
+ export interface GamePlayerSavesOptions {
33
+ /** Called when a script-requested save or load fails. The game keeps running. */
34
+ readonly onError?: (error: Error, request: GameSaveRequest) => void;
35
+ /**
36
+ * When false, script saves store their data without the requested snapshot, and the snapshot is never taken. Hosts
37
+ * that never read snapshots back use it to keep large snapshots out of small storage. Defaults to true.
38
+ */
39
+ readonly storeSnapshots?: boolean;
40
+ }
41
+ /**
42
+ * The player save API. Hosts call `handle` with a step's save requests after the step and `withLoaded` before the
43
+ * next one. Every storage operation, from scripts or from the host, runs outside the tick through one bounded queue in
44
+ * request order. A finished load waits until the host builds the next input frame, so the loaded data enters the
45
+ * simulation as frame input. Recording that frame is enough to replay it.
46
+ */
47
+ export declare class GamePlayerSaves {
48
+ private readonly storage;
49
+ private readonly options;
50
+ private queue;
51
+ private pending;
52
+ private snapshotPending;
53
+ private ready;
54
+ private generation;
55
+ private outstandingLoads;
56
+ constructor(storage: GameSaveStorage, options?: GamePlayerSavesOptions);
57
+ /**
58
+ * Writes a save. A snapshot is only accepted on a progress save, and only one snapshot save may be pending at a
59
+ * time. Pass the snapshot as a function to skip taking it when the save is rejected.
60
+ */
61
+ save(scope: GameSaveScope, slot: string, data: unknown, snapshot?: unknown): Promise<void>;
62
+ /** Initializes an empty progress slot atomically without replacing an existing save. */
63
+ initialize(slot: string, snapshot: unknown): Promise<boolean>;
64
+ /** Reads a save, or null when the slot is empty. Stored data that fails validation is reported as an error. */
65
+ load(scope: GameSaveScope, slot: string): Promise<GameSaveRecord | null>;
66
+ remove(scope: GameSaveScope, slot: string): Promise<void>;
67
+ slots(scope: GameSaveScope): Promise<readonly string[]>;
68
+ /**
69
+ * Queues a step's save and load requests. `snapshot` is called now, before the next step, for saves that store
70
+ * one, so the stored snapshot is the state at the end of the requesting tick. A request the queue rejects is
71
+ * reported through `onError`. Accepted loads reserve response capacity until delivery. Loads rejected after
72
+ * response capacity is full are reported without adding another response.
73
+ */
74
+ handle(requests: readonly GameSaveRequest[] | undefined, snapshot: () => unknown): void;
75
+ /** Resolves when every queued operation has finished. Headless hosts await it between ticks. */
76
+ idle(): Promise<void>;
77
+ /**
78
+ * Returns the frame with finished loads attached as `loaded`, at most `MAX_GAME_SAVE_LOADS_PER_FRAME` per frame.
79
+ * A frame without finished loads is returned unchanged, so recorded frames of games without saves keep their shape.
80
+ * A frame that already carries `loaded`, such as a recorded frame being replayed, is returned unchanged and
81
+ * receives no pending loads.
82
+ */
83
+ withLoaded<Frame extends {
84
+ readonly loaded?: readonly GameSaveLoaded[];
85
+ }>(frame: Frame): Frame;
86
+ /** Drops queued requests and undelivered loads, for a session reset or a restored snapshot. Writes already started still finish. */
87
+ clear(): void;
88
+ /** Runs `work` after every earlier operation, or rejects at once when `MAX_GAME_SAVE_QUEUE` operations are pending. */
89
+ private enqueue;
90
+ /**
91
+ * Validates and queues a save. The queue and snapshot checks run before `snapshot` is called, so a rejected save
92
+ * costs no snapshot. Storage enforces the slot limit atomically at the write boundary.
93
+ */
94
+ private queueSave;
95
+ private read;
96
+ /** Serializes the snapshot once. UTF-8 needs between 1 and 3 bytes per UTF-16 code unit, so most sizes are decided without encoding. */
97
+ private record;
98
+ }
99
+ //# sourceMappingURL=player-saves.d.ts.map
@@ -0,0 +1 @@
1
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AAO,GAAG,IAAI,CA8BtF;IAED,gGAAgG;IAChG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAEpB;IAED;;;;;OAKG;IACH,UAAU,CAAC,KAAK,SAAS;QAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,cAAc,EAAE,CAAA;KAAE,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,CAK7F;IAED,oIAAoI;IACpI,KAAK,IAAI,IAAI,CAIZ;IAED,uHAAuH;IACvH,OAAO,CAAC,OAAO;IAUf;;;OAGG;IACH,OAAO,CAAC,SAAS;YAgCH,IAAI;IAclB,wIAAwI;IACxI,OAAO,CAAC,MAAM;CAYf"}
@@ -0,0 +1,246 @@
1
+ import { gameSaveData, gameSaveScope, gameSaveSlot, MAX_GAME_SAVE_LOADS_PER_FRAME, MAX_GAME_SAVE_SLOTS, MAX_GAME_SAVE_SNAPSHOT_BYTES } from "@nodetool-ai/protocol";
2
+ /** Storage that lives as long as the object. Headless sessions, the CLI and agent playtests use it so runs stay repeatable. */
3
+ export function createMemoryGameSaveStorage() {
4
+ const scopes = { progress: new Map(), settings: new Map() };
5
+ return {
6
+ read: async (scope, slot) => {
7
+ const stored = scopes[scope].get(slot);
8
+ return stored === undefined ? undefined : JSON.parse(stored);
9
+ },
10
+ write: async (scope, slot, record, options) => {
11
+ if (options?.onlyIfEmpty && scopes[scope].has(slot)) {
12
+ return false;
13
+ }
14
+ if (!scopes[scope].has(slot) && scopes[scope].size >= (options?.maxSlots ?? MAX_GAME_SAVE_SLOTS)) {
15
+ throw new Error("Game save slot limit reached");
16
+ }
17
+ scopes[scope].set(slot, JSON.stringify(record));
18
+ return true;
19
+ },
20
+ remove: async (scope, slot) => { scopes[scope].delete(slot); },
21
+ slots: async (scope) => [...scopes[scope].keys()].sort(),
22
+ entries: () => ({
23
+ progress: Object.fromEntries([...scopes.progress].map(([slot, stored]) => [slot, JSON.parse(stored)])),
24
+ settings: Object.fromEntries([...scopes.settings].map(([slot, stored]) => [slot, JSON.parse(stored)]))
25
+ })
26
+ };
27
+ }
28
+ const encoder = new TextEncoder();
29
+ /**
30
+ * Storage operations that may wait in one `GamePlayerSaves` queue, counting the one running. A script can request 4
31
+ * saves or loads per tick at 60 ticks per second, so a slow store fills the queue in a few ticks. Further operations
32
+ * are rejected instead of piling up behind it.
33
+ */
34
+ export const MAX_GAME_SAVE_QUEUE = 8;
35
+ /**
36
+ * The player save API. Hosts call `handle` with a step's save requests after the step and `withLoaded` before the
37
+ * next one. Every storage operation, from scripts or from the host, runs outside the tick through one bounded queue in
38
+ * request order. A finished load waits until the host builds the next input frame, so the loaded data enters the
39
+ * simulation as frame input. Recording that frame is enough to replay it.
40
+ */
41
+ export class GamePlayerSaves {
42
+ storage;
43
+ options;
44
+ queue = Promise.resolve();
45
+ pending = 0;
46
+ snapshotPending = false;
47
+ ready = [];
48
+ generation = 0;
49
+ outstandingLoads = 0;
50
+ constructor(storage, options = {}) {
51
+ this.storage = storage;
52
+ this.options = options;
53
+ }
54
+ /**
55
+ * Writes a save. A snapshot is only accepted on a progress save, and only one snapshot save may be pending at a
56
+ * time. Pass the snapshot as a function to skip taking it when the save is rejected.
57
+ */
58
+ save(scope, slot, data, snapshot) {
59
+ return this.queueSave(scope, slot, data, snapshot === undefined ? undefined : () => snapshot, () => true);
60
+ }
61
+ /** Initializes an empty progress slot atomically without replacing an existing save. */
62
+ initialize(slot, snapshot) {
63
+ gameSaveSlot.parse(slot);
64
+ const record = this.record(slot, {}, snapshot);
65
+ return this.enqueue(async () => {
66
+ return await this.storage.write("progress", slot, record, { onlyIfEmpty: true, maxSlots: MAX_GAME_SAVE_SLOTS }) !== false;
67
+ });
68
+ }
69
+ /** Reads a save, or null when the slot is empty. Stored data that fails validation is reported as an error. */
70
+ load(scope, slot) {
71
+ return this.enqueue(() => this.read(scope, slot));
72
+ }
73
+ remove(scope, slot) {
74
+ return this.enqueue(async () => {
75
+ gameSaveScope.parse(scope);
76
+ gameSaveSlot.parse(slot);
77
+ await this.storage.remove(scope, slot);
78
+ });
79
+ }
80
+ slots(scope) {
81
+ return this.enqueue(async () => {
82
+ gameSaveScope.parse(scope);
83
+ return this.storage.slots(scope);
84
+ });
85
+ }
86
+ /**
87
+ * Queues a step's save and load requests. `snapshot` is called now, before the next step, for saves that store
88
+ * one, so the stored snapshot is the state at the end of the requesting tick. A request the queue rejects is
89
+ * reported through `onError`. Accepted loads reserve response capacity until delivery. Loads rejected after
90
+ * response capacity is full are reported without adding another response.
91
+ */
92
+ handle(requests, snapshot) {
93
+ if (requests === undefined || requests.length === 0) {
94
+ return;
95
+ }
96
+ const generation = this.generation;
97
+ const current = () => generation === this.generation;
98
+ const report = (request) => (error) => {
99
+ this.options.onError?.(error instanceof Error ? error : new Error(String(error)), request);
100
+ };
101
+ for (const request of requests) {
102
+ if (request.kind === "save") {
103
+ const stored = request.snapshot && this.options.storeSnapshots !== false ? snapshot : undefined;
104
+ this.queueSave(request.scope, request.slot, request.data, stored, current)
105
+ .catch(report(request));
106
+ continue;
107
+ }
108
+ if (this.outstandingLoads >= MAX_GAME_SAVE_QUEUE) {
109
+ report(request)(new Error("Game load response queue is full"));
110
+ continue;
111
+ }
112
+ this.outstandingLoads += 1;
113
+ // A failed or rejected load still answers the script, with null data.
114
+ const answer = (data) => {
115
+ if (current()) {
116
+ this.ready.push({ scope: request.scope, slot: request.slot, data });
117
+ }
118
+ };
119
+ this.enqueue(async () => {
120
+ if (!current()) {
121
+ return;
122
+ }
123
+ let data = null;
124
+ try {
125
+ data = (await this.read(request.scope, request.slot))?.data ?? null;
126
+ }
127
+ catch (error) {
128
+ report(request)(error);
129
+ }
130
+ answer(data);
131
+ }).catch((error) => { report(request)(error); answer(null); });
132
+ }
133
+ }
134
+ /** Resolves when every queued operation has finished. Headless hosts await it between ticks. */
135
+ idle() {
136
+ return this.queue;
137
+ }
138
+ /**
139
+ * Returns the frame with finished loads attached as `loaded`, at most `MAX_GAME_SAVE_LOADS_PER_FRAME` per frame.
140
+ * A frame without finished loads is returned unchanged, so recorded frames of games without saves keep their shape.
141
+ * A frame that already carries `loaded`, such as a recorded frame being replayed, is returned unchanged and
142
+ * receives no pending loads.
143
+ */
144
+ withLoaded(frame) {
145
+ if (this.ready.length === 0 || frame.loaded !== undefined) {
146
+ return frame;
147
+ }
148
+ const delivered = this.ready.splice(0, MAX_GAME_SAVE_LOADS_PER_FRAME);
149
+ this.outstandingLoads -= delivered.length;
150
+ return { ...frame, loaded: delivered };
151
+ }
152
+ /** Drops queued requests and undelivered loads, for a session reset or a restored snapshot. Writes already started still finish. */
153
+ clear() {
154
+ this.generation += 1;
155
+ this.ready = [];
156
+ this.outstandingLoads = 0;
157
+ }
158
+ /** Runs `work` after every earlier operation, or rejects at once when `MAX_GAME_SAVE_QUEUE` operations are pending. */
159
+ enqueue(work) {
160
+ if (this.pending >= MAX_GAME_SAVE_QUEUE) {
161
+ return Promise.reject(new Error(`Game save queue is full (${MAX_GAME_SAVE_QUEUE} pending)`));
162
+ }
163
+ this.pending += 1;
164
+ const result = this.queue.then(work).finally(() => { this.pending -= 1; });
165
+ this.queue = result.then(() => undefined, () => undefined);
166
+ return result;
167
+ }
168
+ /**
169
+ * Validates and queues a save. The queue and snapshot checks run before `snapshot` is called, so a rejected save
170
+ * costs no snapshot. Storage enforces the slot limit atomically at the write boundary.
171
+ */
172
+ queueSave(scope, slot, data, snapshot, current) {
173
+ try {
174
+ gameSaveScope.parse(scope);
175
+ gameSaveSlot.parse(slot);
176
+ if (this.pending >= MAX_GAME_SAVE_QUEUE) {
177
+ throw new Error(`Game save queue is full (${MAX_GAME_SAVE_QUEUE} pending)`);
178
+ }
179
+ if (snapshot !== undefined && scope === "settings") {
180
+ throw new Error("Settings saves cannot store a snapshot");
181
+ }
182
+ if (snapshot !== undefined && this.snapshotPending) {
183
+ throw new Error("A snapshot save is already pending");
184
+ }
185
+ const record = this.record(slot, data, snapshot?.());
186
+ if (record.snapshot !== undefined) {
187
+ this.snapshotPending = true;
188
+ }
189
+ return this.enqueue(async () => {
190
+ try {
191
+ if (!current()) {
192
+ return;
193
+ }
194
+ const existing = await this.storage.slots(scope);
195
+ if (!existing.includes(slot) && existing.length >= MAX_GAME_SAVE_SLOTS) {
196
+ throw new Error(`Game ${scope} saves are limited to ${MAX_GAME_SAVE_SLOTS} slots`);
197
+ }
198
+ await this.storage.write(scope, slot, record, { maxSlots: MAX_GAME_SAVE_SLOTS });
199
+ }
200
+ finally {
201
+ if (record.snapshot !== undefined) {
202
+ this.snapshotPending = false;
203
+ }
204
+ }
205
+ });
206
+ }
207
+ catch (error) {
208
+ return Promise.reject(error);
209
+ }
210
+ }
211
+ async read(scope, slot) {
212
+ gameSaveScope.parse(scope);
213
+ gameSaveSlot.parse(slot);
214
+ const stored = await this.storage.read(scope, slot);
215
+ if (stored === undefined || stored === null) {
216
+ return null;
217
+ }
218
+ if (typeof stored !== "object" || stored.version !== 1) {
219
+ throw new Error(`Stored ${scope} save ${slot} has an unsupported format`);
220
+ }
221
+ const data = gameSaveData.safeParse(stored.data);
222
+ if (!data.success) {
223
+ throw new Error(`Stored ${scope} save ${slot} has invalid data`);
224
+ }
225
+ const snapshot = stored.snapshot;
226
+ return scope === "progress" && snapshot !== undefined ? { version: 1, data: data.data, snapshot } : { version: 1, data: data.data };
227
+ }
228
+ /** Serializes the snapshot once. UTF-8 needs between 1 and 3 bytes per UTF-16 code unit, so most sizes are decided without encoding. */
229
+ record(slot, data, snapshot) {
230
+ const parsed = gameSaveData.parse(data);
231
+ if (snapshot === undefined) {
232
+ return { version: 1, data: parsed };
233
+ }
234
+ const json = JSON.stringify(snapshot);
235
+ if (json === undefined) {
236
+ throw new Error(`Save ${slot} snapshot is not JSON`);
237
+ }
238
+ const bytes = json.length * 3 <= MAX_GAME_SAVE_SNAPSHOT_BYTES ? json.length
239
+ : json.length > MAX_GAME_SAVE_SNAPSHOT_BYTES ? json.length : encoder.encode(json).byteLength;
240
+ if (bytes > MAX_GAME_SAVE_SNAPSHOT_BYTES) {
241
+ throw new Error(`Save snapshot exceeds ${MAX_GAME_SAVE_SNAPSHOT_BYTES} bytes (at least ${bytes})`);
242
+ }
243
+ return { version: 1, data: parsed, snapshot: JSON.parse(json) };
244
+ }
245
+ }
246
+ //# sourceMappingURL=player-saves.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"player-saves.js","sourceRoot":"","sources":["../src/player-saves.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,6BAA6B,EAC7B,mBAAmB,EACnB,4BAA4B,EAI7B,MAAM,uBAAuB,CAAC;AAsB/B,+HAA+H;AAC/H,MAAM,UAAU,2BAA2B;IACzC,MAAM,MAAM,GAA+C,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;IACxG,OAAO;QACL,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YAC1B,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACvC,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAY,CAAC;QAC1E,CAAC;QACD,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE;YAC5C,IAAI,OAAO,EAAE,WAAW,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBAAC,OAAO,KAAK,CAAC;YAAC,CAAC;YACtE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,QAAQ,IAAI,mBAAmB,CAAC,EAAE,CAAC;gBAAC,MAAM,IAAI,KAAK,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,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAY,EAAE,CAAC;IAC7E,CAAC;CACF"}
@@ -70,7 +70,7 @@ type ${name}Contact = { otherId: string; phase: "enter" | "stay" | "exit"; senso
70
70
  /** A trigger event from the previous tick. \`entityId\` is the sender. \`target\` is absent for a broadcast. */
71
71
  type ${name}Event = { kind: "trigger"; event: string; entityId: string; payload?: JSONValue; target?: { entityId: string } | { tag: string } };
72
72
  type ${name}Result = { state?: unknown; commands?: ${command}[] } | undefined | void;
73
- type ${name}DestroyCommandKind = "hud" | "emit" | "spawn" | "despawn" | "sceneTransition";
73
+ type ${name}DestroyCommandKind = "hud" | "ui" | "emit" | "spawn" | "despawn" | "sceneTransition" | "log" | "save" | "load";
74
74
  /**
75
75
  * A script may be an object of hooks instead of a function. Within a tick they run in this order:
76
76
  * onStart (first call), onSceneEnter, onTriggerEnter, onTriggerExit and onContact (previous tick's contacts
@@ -69,7 +69,7 @@ export function removedDestroyCall(stateKey, record, context) {
69
69
  maxCommands: limits.maxCommands, maxTickMs: limits.maxTickMs, state: rest, lifecycle: { destroy: true } };
70
70
  }
71
71
  /** Commands an `onDestroy` call may return. The entity is gone, so commands that act on it are rejected. */
72
- const DESTROY_COMMANDS = new Set(["hud", "emit", "spawn", "despawn", "sceneTransition"]);
72
+ const DESTROY_COMMANDS = new Set(["hud", "ui", "emit", "spawn", "despawn", "sceneTransition"]);
73
73
  export function assertDestroyCommands(commands, entityId, tick) {
74
74
  for (const command of commands) {
75
75
  if (!DESTROY_COMMANDS.has(command.kind)) {
@@ -1 +1 @@
1
- {"version":3,"file":"script-lifecycle.js","sourceRoot":"","sources":["../src/script-lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAwB,MAAM,uBAAuB,CAAC;AAE/E;;;;;GAKG;AAEH,wEAAwE;AACxE,MAAM,CAA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C,KAAK,CAAC,CAAC;QAAC,CAAC;IACzE,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,GAAG,sBAAsB,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CAAC,6BAA6B,sBAAsB,SAAS,CAAC,CAAC;IAChF,CAAC;IACD,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC1C,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG;;;;;oDAKW,2BAA2B,iEAAiE,2BAA2B;;;;;;;;;;;;;;;;;;;;iIAoB1C,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,GAAG,CAAC"}
@@ -0,0 +1,47 @@
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 declare 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 declare 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 declare const gameScriptLogCommand: z.ZodObject<{
14
+ kind: z.ZodLiteral<"log">;
15
+ message: z.ZodString;
16
+ level: z.ZodOptional<z.ZodEnum<{
17
+ error: "error";
18
+ log: "log";
19
+ warning: "warning";
20
+ }>>;
21
+ }, z.core.$strict>;
22
+ export type GameScriptLogCommand = z.infer<typeof gameScriptLogCommand>;
23
+ /** A log line from one script call. Log lines are presentation data. The overflow line names no entity. */
24
+ export interface GameScriptLogEntry {
25
+ readonly tick: number;
26
+ readonly entityId?: string;
27
+ readonly level: NonNullable<GameScriptLogCommand["level"]>;
28
+ readonly message: string;
29
+ }
30
+ /** Collects one tick's log lines with the per-tick and per-message limits applied. */
31
+ export declare class GameScriptLogCollector {
32
+ private readonly tick;
33
+ private readonly lines;
34
+ private dropped;
35
+ constructor(tick: number);
36
+ /**
37
+ * Removes log commands from a call's raw output commands and records them. Other commands keep their order.
38
+ * Returns the input array unchanged when it holds no log command.
39
+ */
40
+ collect(entityId: string, commands: unknown): unknown;
41
+ entries(): readonly GameScriptLogEntry[];
42
+ }
43
+ /** Attaches the lines logged before a failure to the thrown error, unless it already carries some. */
44
+ export declare function withGameScriptLogs(error: unknown, logs: readonly GameScriptLogEntry[] | undefined): unknown;
45
+ /** The script log lines of a failed tick, logged before the failure. */
46
+ export declare function gameScriptLogsOf(error: unknown): readonly GameScriptLogEntry[] | undefined;
47
+ //# sourceMappingURL=script-log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script-log.d.ts","sourceRoot":"","sources":["../src/script-log.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,oGAAoG;AACpG,eAAO,MAAM,qBAAqB,KAAK,CAAC;AACxC;;;GAGG;AACH,eAAO,MAAM,6BAA6B,OAAO,CAAC;AAElD;;;GAGG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;kBAI/B,CAAC;AAEH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAExE,2GAA2G;AAC3G,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,sFAAsF;AACtF,qBAAa,sBAAsB;IAIrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHjC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA4B;IAClD,OAAO,CAAC,OAAO,CAAK;IAEpB,YAA6B,IAAI,EAAE,MAAM,EAAI;IAE7C;;;OAGG;IACH,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAYpD;IAED,OAAO,IAAI,SAAS,kBAAkB,EAAE,CAIvC;CACF;AAYD,sGAAsG;AACtG,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,kBAAkB,EAAE,GAAG,SAAS,GAAG,OAAO,CAI3G;AAED,wEAAwE;AACxE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,kBAAkB,EAAE,GAAG,SAAS,CAE1F"}
@@ -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,MAAM,oBAAoB,GAAG,CAAC,CAAC,YAAY,CAAC;IACjD,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;IACtB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,EAAE;CACtD,CAAC,CAAC;AAYH,sFAAsF;AACtF,MAAM,OAAO,sBAAsB;IAIJ,IAAI;IAHhB,KAAK,GAAyB,EAAE,CAAC;IAC1C,OAAO,GAAG,CAAC,CAAC;IAEpB,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,YAAY,CAAC,EAAE,CAAC;YAAC,OAAO,QAAQ,CAAC;QAAC,CAAC;QAClF,MAAM,IAAI,GAAc,EAAE,CAAC;QAC3B,KAAK,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;YAClD,IAAI,CAA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 +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,QA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