@nodetool-ai/game-runtime 0.8.19 → 0.8.21

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 (64) hide show
  1. package/dist/.nodetool-build-stamp +1 -1
  2. package/dist/adventure.d.ts +42 -0
  3. package/dist/adventure.d.ts.map +1 -0
  4. package/dist/adventure.js +733 -0
  5. package/dist/adventure.js.map +1 -0
  6. package/dist/index.d.ts +1 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +1 -0
  9. package/dist/index.js.map +1 -1
  10. package/dist/native-browser/assets.d.ts +19 -0
  11. package/dist/native-browser/assets.d.ts.map +1 -0
  12. package/dist/native-browser/assets.js +70 -0
  13. package/dist/native-browser/assets.js.map +1 -0
  14. package/dist/native-browser/index.d.ts +6 -0
  15. package/dist/native-browser/index.d.ts.map +1 -0
  16. package/dist/native-browser/index.js +5 -0
  17. package/dist/native-browser/index.js.map +1 -0
  18. package/dist/native-browser/input.d.ts +70 -0
  19. package/dist/native-browser/input.d.ts.map +1 -0
  20. package/dist/native-browser/input.js +298 -0
  21. package/dist/native-browser/input.js.map +1 -0
  22. package/dist/native-browser/saves.d.ts +37 -0
  23. package/dist/native-browser/saves.d.ts.map +1 -0
  24. package/dist/native-browser/saves.js +187 -0
  25. package/dist/native-browser/saves.js.map +1 -0
  26. package/dist/native-browser/session.d.ts +46 -0
  27. package/dist/native-browser/session.d.ts.map +1 -0
  28. package/dist/native-browser/session.js +206 -0
  29. package/dist/native-browser/session.js.map +1 -0
  30. package/dist/native-browser/wasm.d.ts +28 -0
  31. package/dist/native-browser/wasm.d.ts.map +1 -0
  32. package/dist/native-browser/wasm.js +68 -0
  33. package/dist/native-browser/wasm.js.map +1 -0
  34. package/dist/native-browser/worker.d.ts +8 -0
  35. package/dist/native-browser/worker.d.ts.map +1 -0
  36. package/dist/native-browser/worker.js +109 -0
  37. package/dist/native-browser/worker.js.map +1 -0
  38. package/dist/native-editor-client.d.ts +1283 -0
  39. package/dist/native-editor-client.d.ts.map +1 -0
  40. package/dist/native-editor-client.js +106 -0
  41. package/dist/native-editor-client.js.map +1 -0
  42. package/dist/native-game-export.mjs +112 -0
  43. package/dist/native-game-notices.txt +934 -0
  44. package/dist/native-game-web-export.mjs +125 -0
  45. package/dist/native-json-save-files.d.ts +8 -0
  46. package/dist/native-json-save-files.d.ts.map +1 -0
  47. package/dist/native-json-save-files.js +95 -0
  48. package/dist/native-json-save-files.js.map +1 -0
  49. package/dist/native-template.d.ts +14 -0
  50. package/dist/native-template.d.ts.map +1 -0
  51. package/dist/native-template.js +99 -0
  52. package/dist/native-template.js.map +1 -0
  53. package/dist/native-worker.d.ts +36 -0
  54. package/dist/native-worker.d.ts.map +1 -0
  55. package/dist/native-worker.js +158 -0
  56. package/dist/native-worker.js.map +1 -0
  57. package/dist/native.d.ts +49 -0
  58. package/dist/native.d.ts.map +1 -0
  59. package/dist/native.js +305 -0
  60. package/dist/native.js.map +1 -0
  61. package/dist/systems/presentation2d.d.ts.map +1 -1
  62. package/dist/systems/presentation2d.js +3 -1
  63. package/dist/systems/presentation2d.js.map +1 -1
  64. package/package.json +32 -7
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env node
2
+ import { createHash } from 'node:crypto';
3
+ import { lstat, mkdir, mkdtemp, readFile, realpath, rename, rm, writeFile } from 'node:fs/promises';
4
+ import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
5
+ import { tmpdir } from 'node:os';
6
+ import { fileURLToPath, pathToFileURL } from 'node:url';
7
+
8
+ const hash = bytes => createHash('sha256').update(bytes).digest('hex');
9
+ export const NATIVE_BROWSER_FILES = ['native-game.mjs', 'native-game.wasm', 'native-game-worker.js', 'native-game-player.js', 'native-game-browser.json', 'native-game-notices.txt'];
10
+ function safePath(path) {
11
+ return typeof path === 'string' && path.length > 0 && path.length <= 4096 && !isAbsolute(path) && !/[\\:%?#\u0000-\u001f]/u.test(path) && path.split('/').every(part => part && part !== '.' && part !== '..');
12
+ }
13
+ function inside(root, path) {
14
+ const value = relative(root, path);
15
+ return value !== '..' && !value.startsWith(`..${sep}`) && !isAbsolute(value);
16
+ }
17
+ async function validateNativeDocument(document, staged, validationRoot, signal) {
18
+ signal?.throwIfAborted();
19
+ const directory = await mkdtemp(join(validationRoot ?? tmpdir(), '.native-game-web-validate-'));
20
+ try {
21
+ const modulePath = join(directory, 'native-game.mjs');
22
+ for (const name of ['native-game.mjs', 'native-game.wasm']) {
23
+ const path = join(directory, name);
24
+ await writeFile(path, staged.get(name));
25
+ if (hash(await readFile(path)) !== hash(staged.get(name))) { throw new Error('Native validation runtime staging verification failed'); }
26
+ }
27
+ signal?.throwIfAborted();
28
+ const factory = (await import(pathToFileURL(modulePath).href)).default;
29
+ if (typeof factory !== 'function') { throw new Error('Native browser module has no factory'); }
30
+ const module = await factory({ locateFile(name) { if (name !== 'native-game.wasm') { throw new Error('Undeclared native validation runtime file'); } return join(directory, name); }, print() {}, printErr() {} });
31
+ signal?.throwIfAborted();
32
+ const context = module._ng_create();
33
+ if (!context) { throw new Error('Native browser validation context creation failed'); }
34
+ let pointer = 0;
35
+ try {
36
+ const requestId = 'export-validate';
37
+ const bytes = new TextEncoder().encode(JSON.stringify({ protocolVersion: 1, requestId, operation: 'validate', document }));
38
+ pointer = module._malloc(bytes.length);
39
+ if (!Number.isSafeInteger(pointer) || pointer <= 0 || pointer + bytes.length > module.HEAPU8.byteLength) { throw new Error('Native browser validation allocation failed'); }
40
+ module.HEAPU8.set(bytes, pointer);
41
+ const status = module._ng_dispatch(context, pointer, bytes.length);
42
+ const resultPointer = module._ng_response_pointer(context), length = module._ng_response_length(context), heap = module.HEAPU8;
43
+ if ((status !== 0 && status !== 1) || !Number.isSafeInteger(resultPointer) || resultPointer < 0 || !Number.isSafeInteger(length) || length < 1 || length > 16 * 1024 * 1024 || resultPointer + length > heap.byteLength) { throw new Error('Invalid native browser validation response'); }
44
+ const response = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(heap.slice(resultPointer, resultPointer + length)));
45
+ if (status !== 0 || response.status !== 'ok' || response.protocolVersion !== 1 || response.requestId !== requestId) {
46
+ throw new Error(`Native browser document validation failed: ${response.error?.message ?? 'invalid response'}`);
47
+ }
48
+ signal?.throwIfAborted();
49
+ } finally { if (pointer) { module._free(pointer); } module._ng_destroy(context); }
50
+ } finally { await rm(directory, { recursive: true, force: true }); }
51
+ }
52
+ export async function exportNativeBrowserPlayer(options) {
53
+ options.signal?.throwIfAborted();
54
+ if (typeof options.output !== 'string' || options.output.split(/[\\/]/).includes('..')) { throw new Error('Unsafe export destination'); }
55
+ const output = resolve(options.output);
56
+ try { await lstat(output); throw new Error('Export destination already exists'); } catch (error) { if (error.code !== 'ENOENT') { throw error; } }
57
+ const documentBytes = await readFile(options.document);
58
+ if (documentBytes.length > 4 * 1024 * 1024) { throw new Error('Document exceeds 4 MiB'); }
59
+ const document = JSON.parse(documentBytes.toString('utf8'));
60
+ if (document.engine !== 'native-cpp-1' || !((document.schemaVersion === 4 && document.dimension === '3d') || (document.schemaVersion === 5 && document.dimension === '2d')) || !Array.isArray(document.assets)) { throw new Error('Expected native C++ dimensional document'); }
61
+ if (document.assets.length > 4096) { throw new Error('Native browser asset count exceeds 4096 entry budget'); }
62
+ const runtime = options.runtime;
63
+ if (!runtime || NATIVE_BROWSER_FILES.some(name => typeof runtime[name] !== 'string')) { throw new Error('Native browser capability unavailable: install the browser runtime profile'); }
64
+ const identity = JSON.parse(await readFile(runtime['native-game-browser.json'], 'utf8'));
65
+ if (identity.engine !== 'native-cpp-1' || !Array.isArray(identity.files) || identity.files.length < 4) { throw new Error('Invalid native browser artifact identity'); }
66
+ const staged = new Map();
67
+ for (const name of NATIVE_BROWSER_FILES) {
68
+ options.signal?.throwIfAborted();
69
+ const bytes = await readFile(runtime[name]);
70
+ if (!bytes.length) { throw new Error(`Empty browser artifact: ${name}`); }
71
+ if (name !== 'native-game-browser.json') {
72
+ const item = identity.files.find(entry => entry.path === name);
73
+ if (!item || item.size !== bytes.length || item.digest !== hash(bytes)) { throw new Error(`Browser runtime digest mismatch: ${name}`); }
74
+ }
75
+ staged.set(name, bytes);
76
+ }
77
+ const assetsRoot = await realpath(resolve(options.assetsRoot ?? dirname(options.document)));
78
+ const ids = new Set(), paths = new Set(); let assetBytes = 0;
79
+ for (const asset of document.assets) {
80
+ options.signal?.throwIfAborted();
81
+ if (typeof asset.id !== 'string' || ids.has(asset.id) || paths.has(asset.path) || !safePath(asset.path) || !/^[a-f0-9]{64}$/.test(asset.digest) || !Number.isSafeInteger(asset.size) || asset.size < 0 || asset.size > 64 * 1024 * 1024) { throw new Error('Invalid prepared asset entry'); }
82
+ ids.add(asset.id); paths.add(asset.path);
83
+ const source = await realpath(resolve(assetsRoot, asset.path));
84
+ if (!inside(assetsRoot, source) || !(await lstat(source)).isFile()) { throw new Error(`Asset leaves prepared root: ${asset.id}`); }
85
+ const bytes = await readFile(source); assetBytes += bytes.length;
86
+ if (assetBytes > 256 * 1024 * 1024 || bytes.length !== asset.size || hash(bytes) !== asset.digest) { throw new Error(`Asset digest, size or total budget mismatch: ${asset.id}`); }
87
+ staged.set(`assets/${asset.path}`, bytes);
88
+ }
89
+ for (const asset of document.assets) { for (const id of asset.dependencies ?? []) { if (!ids.has(id)) { throw new Error(`Missing asset dependency: ${id}`); } } }
90
+ await validateNativeDocument(document, staged, options.validationRoot, options.signal);
91
+ staged.set('game.json', Buffer.from(JSON.stringify(document)));
92
+ staged.set('assets.manifest.json', Buffer.from(JSON.stringify(document.assets)));
93
+ staged.set('index.html', Buffer.from('<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta http-equiv="Content-Security-Policy" content="default-src \'self\'; script-src \'self\' \'wasm-unsafe-eval\'; worker-src \'self\'; connect-src \'self\'; img-src \'self\' blob:; media-src \'self\' blob:; style-src \'self\'; object-src \'none\'; base-uri \'none\'"><title>Native game</title><link rel="stylesheet" href="styles.css"></head><body><canvas id="game"></canvas><div id="hud"></div><p id="status" role="status">Starting native game…</p><script type="module" src="native-game-player.js"></script></body></html>'));
94
+ staged.set('styles.css', Buffer.from('html,body{margin:0;width:100%;height:100%;overflow:hidden;background:#000}canvas{display:block;width:100%;height:100%}#hud{position:absolute;inset:0;pointer-events:none}#status{position:absolute;top:0;color:white;background:black;font:16px sans-serif}'));
95
+ const inventory = [...staged].map(([path, bytes]) => ({ path, size: bytes.length, digest: hash(bytes) }));
96
+ const report = { engine: document.engine, schemaVersion: document.schemaVersion, dimension: document.dimension, target: 'web', entry: 'index.html', assetBytes, files: inventory };
97
+ staged.set('bundle.json', Buffer.from(JSON.stringify(report, null, 2)));
98
+ options.signal?.throwIfAborted();
99
+ await mkdir(dirname(output), { recursive: true });
100
+ const parent = await realpath(dirname(output));
101
+ const stage = await mkdtemp(join(parent, '.native-game-web-export-'));
102
+ try {
103
+ for (const [path, bytes] of staged) {
104
+ options.signal?.throwIfAborted();
105
+ const target = join(stage, path); await mkdir(dirname(target), { recursive: true }); await writeFile(target, bytes);
106
+ if (hash(await readFile(target)) !== hash(bytes)) { throw new Error(`Staging verification failed: ${path}`); }
107
+ }
108
+ options.signal?.throwIfAborted();
109
+ try { await lstat(output); throw new Error('Export destination appeared during staging'); } catch (error) { if (error.code !== 'ENOENT') { throw error; } }
110
+ await rename(stage, output);
111
+ return { ...report, output };
112
+ } finally { await rm(stage, { recursive: true, force: true }); }
113
+ }
114
+ if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
115
+ const controller = new AbortController();
116
+ const abort = () => controller.abort(new Error('Native browser export cancelled'));
117
+ process.on('SIGTERM', abort); process.on('SIGINT', abort);
118
+ try {
119
+ const options = JSON.parse(process.argv[2]);
120
+ const { files, ...summary } = await exportNativeBrowserPlayer({ ...options, signal: controller.signal });
121
+ console.log(JSON.stringify({ ...summary, fileCount: files.length + 1 }));
122
+ }
123
+ catch (error) { console.error(error.message); process.exitCode = 1; }
124
+ finally { process.off('SIGTERM', abort); process.off('SIGINT', abort); }
125
+ }
@@ -0,0 +1,8 @@
1
+ import { type NativeJsonSaveStorage } from "@nodetool-ai/protocol/native-game";
2
+ /** Per-game storage with atomic replacement and a cross-process scope lock. */
3
+ export declare function createNativeAtomicFileSaveStorage(options: {
4
+ readonly root: string;
5
+ readonly gameId: string;
6
+ readonly engineContract: string;
7
+ }): NativeJsonSaveStorage;
8
+ //# sourceMappingURL=native-json-save-files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-json-save-files.d.ts","sourceRoot":"","sources":["../src/native-json-save-files.ts"],"names":[],"mappings":"AAMA,OAAO,EAAwB,KAAK,qBAAqB,EAAwB,MAAM,mCAAmC,CAAC;AAE3H,+EAA+E;AAC/E,wBAAgB,iCAAiC,CAAC,OAAO,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;CAAE,GAAG,qBAAqB,CA6CrK"}
@@ -0,0 +1,95 @@
1
+ import { DatabaseSync } from "node:sqlite";
2
+ import { constants } from "node:fs";
3
+ import { mkdir, open, readdir, rename, rm } from "node:fs/promises";
4
+ import { createHash, randomUUID } from "node:crypto";
5
+ import { join } from "node:path";
6
+ import { gameSaveScope, gameSaveSlot, MAX_GAME_SAVE_SLOTS } from "@nodetool-ai/protocol";
7
+ import { nativeJsonSaveRecord } from "@nodetool-ai/protocol/native-game";
8
+ /** Per-game storage with atomic replacement and a cross-process scope lock. */
9
+ export function createNativeAtomicFileSaveStorage(options) {
10
+ if (!options.gameId || !options.engineContract) {
11
+ throw new Error("Native saves require a full game ID and engine contract");
12
+ }
13
+ const namespace = createHash("sha256").update(JSON.stringify([options.gameId, options.engineContract])).digest("hex");
14
+ const directory = (scope) => join(options.root, namespace, gameSaveScope.parse(scope));
15
+ const path = (scope, slot) => join(directory(scope), `${gameSaveSlot.parse(slot)}.json`);
16
+ return {
17
+ persistence: "durable",
18
+ async read(scope, slot) {
19
+ let file;
20
+ try {
21
+ file = await open(path(scope, slot), constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
22
+ }
23
+ catch (error) {
24
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
25
+ return null;
26
+ }
27
+ throw error;
28
+ }
29
+ try {
30
+ const stat = await file.stat();
31
+ if (!stat.isFile() || stat.size > 17 * 1024) {
32
+ throw new Error("Native JSON save record exceeds file limit");
33
+ }
34
+ const buffer = Buffer.alloc(17 * 1024 + 1);
35
+ const { bytesRead } = await file.read(buffer, 0, buffer.length, 0);
36
+ if (bytesRead > 17 * 1024) {
37
+ throw new Error("Native JSON save grew beyond file limit");
38
+ }
39
+ return nativeJsonSaveRecord.parse(JSON.parse(buffer.subarray(0, bytesRead).toString("utf8")));
40
+ }
41
+ finally {
42
+ await file.close();
43
+ }
44
+ },
45
+ async write(scope, slot, record) {
46
+ const parsed = nativeJsonSaveRecord.parse(record), target = path(scope, slot), folder = directory(scope);
47
+ await mkdir(folder, { recursive: true, mode: 0o700 });
48
+ // SQLite holds an OS-released lock, so a killed writer cannot strand ownership.
49
+ // Keep the database file: unlinking a lock inode would split concurrent writers.
50
+ const lock = new DatabaseSync(join(folder, ".write-lock.sqlite"));
51
+ let locked = false;
52
+ const temporary = join(folder, `.${randomUUID()}.tmp`);
53
+ try {
54
+ lock.exec("BEGIN IMMEDIATE");
55
+ locked = true;
56
+ const slots = (await readdir(folder)).filter((name) => /^[A-Za-z0-9_-]{1,32}\.json$/.test(name));
57
+ if (!slots.includes(`${slot}.json`) && slots.length >= MAX_GAME_SAVE_SLOTS) {
58
+ throw new Error("Native save slot limit reached");
59
+ }
60
+ const file = await open(temporary, "wx", 0o600);
61
+ try {
62
+ await file.writeFile(JSON.stringify(parsed));
63
+ await file.sync();
64
+ }
65
+ finally {
66
+ await file.close();
67
+ }
68
+ await rename(temporary, target);
69
+ const parent = await open(folder, constants.O_RDONLY);
70
+ try {
71
+ await parent.sync();
72
+ }
73
+ finally {
74
+ await parent.close();
75
+ }
76
+ }
77
+ finally {
78
+ try {
79
+ await rm(temporary, { force: true });
80
+ }
81
+ finally {
82
+ try {
83
+ if (locked) {
84
+ lock.exec("ROLLBACK");
85
+ }
86
+ }
87
+ finally {
88
+ lock.close();
89
+ }
90
+ }
91
+ }
92
+ }
93
+ };
94
+ }
95
+ //# sourceMappingURL=native-json-save-files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-json-save-files.js","sourceRoot":"","sources":["../src/native-json-save-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACzF,OAAO,EAAE,oBAAoB,EAAoD,MAAM,mCAAmC,CAAC;AAE3H,+EAA+E;AAC/E,MAAM,UAAU,iCAAiC,CAAC,OAA4F;IAC5I,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;QAAC,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAAC,CAAC;IAC/H,MAAM,SAAS,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACtH,MAAM,SAAS,GAAG,CAAC,KAAsB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NativeGame3dDocument, type NativeGame2dDocument } from "@nodetool-ai/protocol/native-game";
2
+ /** Asset-free geometry plus an owned WAV gives agents a reproducible first course. */
3
+ export declare function createNativeCppCourse(id: string, title?: string): {
4
+ readonly document: NativeGame3dDocument;
5
+ readonly audio: Uint8Array;
6
+ readonly files: Readonly<Record<string, Uint8Array>>;
7
+ };
8
+ /** Native 2D authoring course uses the shared Luau lifecycle and TS component vocabulary. */
9
+ export declare function createNativeCpp2dCourse(id: string, title?: string): {
10
+ readonly document: NativeGame2dDocument;
11
+ readonly audio: Uint8Array;
12
+ readonly files: Readonly<Record<string, Uint8Array>>;
13
+ };
14
+ //# sourceMappingURL=native-template.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-template.d.ts","sourceRoot":"","sources":["../src/native-template.ts"],"names":[],"mappings":"AAEA,OAAO,EAA8C,KAAK,oBAAoB,EAAE,KAAK,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACrJ,sFAAsF;AACtF,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,SAAiB,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,oBAAoB,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAA;CAAE,CAsBvM;AAoBD,6FAA6F;AAC7F,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,SAAiB,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,oBAAoB,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAA;CAAE,CAuBzM"}
@@ -0,0 +1,99 @@
1
+ import { deflateSync } from "node:zlib";
2
+ import { createHash } from "node:crypto";
3
+ import { nativeGame3dDocument, nativeGame2dDocument } from "@nodetool-ai/protocol/native-game";
4
+ /** Asset-free geometry plus an owned WAV gives agents a reproducible first course. */
5
+ export function createNativeCppCourse(id, title = "Relay Course") {
6
+ const frames = 1600, wav = Buffer.alloc(44 + frames * 2);
7
+ wav.write("RIFF");
8
+ wav.writeUInt32LE(wav.length - 8, 4);
9
+ wav.write("WAVEfmt ", 8);
10
+ wav.writeUInt32LE(16, 16);
11
+ wav.writeUInt16LE(1, 20);
12
+ wav.writeUInt16LE(1, 22);
13
+ wav.writeUInt32LE(16000, 24);
14
+ wav.writeUInt32LE(32000, 28);
15
+ wav.writeUInt16LE(2, 32);
16
+ wav.writeUInt16LE(16, 34);
17
+ wav.write("data", 36);
18
+ wav.writeUInt32LE(frames * 2, 40);
19
+ for (let frame = 0; frame < frames; frame++) {
20
+ wav.writeInt16LE(Math.round(Math.sin(frame * Math.PI * 880 / 16000) * 5000 * (1 - frame / frames)), 44 + frame * 2);
21
+ }
22
+ const document = nativeGame3dDocument.parse({ schemaVersion: 4, engine: "native-cpp-1", dimension: "3d", id, title, initialSceneId: "course",
23
+ camera: { position: [7, 6, 10], target: [0, 1, 0] },
24
+ assets: [{ id: "collect-tone", kind: "audio", path: "collect.wav", size: wav.length, digest: createHash("sha256").update(wav).digest("hex") }],
25
+ hud: [{ id: "score", kind: "text", bounds: [.02, .02, .4, .1], text: "Score {score}" }, { id: "restart", kind: "button", bounds: [.8, .02, .18, .1], text: "Restart", action: "restart" }],
26
+ inputActions: [{ id: "finish", bindings: ["KeyF"] }, { id: "restart", bindings: ["KeyR"] }],
27
+ scripts: [
28
+ { id: "platform-motion", language: "luau", source: "return {\n onFixedUpdate = function(ctx)\n ctx.command({ kind = \"setPosition\", position = { -2, 0.25, math.sin(ctx.tick / 60) * 2 } })\n end,\n}\n" },
29
+ { id: "gate-control", language: "luau", source: "return {\n onFixedUpdate = function(ctx)\n if ctx.tick >= 2 then\n ctx.command({ kind = \"setPosition\", position = { 3, 3, 0 } })\n end\n end,\n}\n" },
30
+ { id: "collect-audio", language: "luau", source: "return {\n onDestroy = function(ctx)\n ctx.command({ kind = \"audio\", assetId = \"collect-tone\" })\n end,\n}\n" },
31
+ { id: "course-control", language: "luau", source: "return {\n onFixedUpdate = function(ctx)\n local actions = ctx.input.actions\n local wasFinished = ctx.state.finished == true\n local finishPressed = actions ~= nil and actions.finish == true\n local restartPressed = actions ~= nil and actions.restart == true\n ctx.state.finished = wasFinished or finishPressed\n if restartPressed then\n ctx.command({ kind = \"score\", amount = wasFinished and -11 or -1 })\n ctx.command({ kind = \"transition\", sceneId = \"course\" })\n elseif finishPressed and not wasFinished then\n ctx.command({ kind = \"score\", amount = 10 })\n ctx.command({ kind = \"emit\", name = \"finish\" })\n end\n end,\n}\n" }
32
+ ], scenes: [{ id: "course", entities: [
33
+ { id: "floor", transform: { position: [0, -.5, 0] }, collider: { shape: "box", halfExtents: [6, .5, 6] }, visual: { kind: "primitive", shape: "box", size: [12, 1, 12], color: [.2, .3, .35, 1] } },
34
+ { id: "player", transform: { position: [0, 1, 0] }, collider: { shape: "capsule", radius: .35, halfHeight: .4 }, character: {}, visual: { kind: "primitive", shape: "capsule", size: [.7, 1.5, .7], color: [.1, .6, 1, 1] }, behaviors: [{ id: "course", scriptId: "course-control" }] },
35
+ { id: "collectible", transform: { position: [0, 1, 0] }, collider: { shape: "sphere", radius: .3, sensor: true }, gameplay: { collectible: true, scoreValue: 1 }, visual: { kind: "primitive", shape: "sphere", size: [.6, .6, .6], color: [1, .8, .1, 1] }, behaviors: [{ id: "tone", scriptId: "collect-audio" }] },
36
+ { id: "platform", transform: { position: [-2, .25, 0] }, body: { type: "kinematic" }, collider: { shape: "box", halfExtents: [1, .25, 1] }, visual: { kind: "primitive", shape: "box", size: [2, .5, 2], color: [.2, .7, .2, 1] }, behaviors: [{ id: "motion", scriptId: "platform-motion" }] },
37
+ { id: "gate", transform: { position: [3, 1, 0] }, body: { type: "kinematic" }, collider: { shape: "box", halfExtents: [.2, 1, 2] }, visual: { kind: "primitive", shape: "box", size: [.4, 2, 4], color: [.8, .2, .2, 1] }, behaviors: [{ id: "open", scriptId: "gate-control" }] }
38
+ ] }] });
39
+ return { document, audio: wav, files: { "collect.wav": wav } };
40
+ }
41
+ /** Small owned atlas, encoded without an external image service or runtime dependency. */
42
+ function courseAtlas() {
43
+ const chunk = (name, data) => {
44
+ const type = Buffer.from(name), body = Buffer.concat([type, data]);
45
+ let crc = 0xffffffff;
46
+ for (const byte of body) {
47
+ crc ^= byte;
48
+ for (let bit = 0; bit < 8; bit++) {
49
+ crc = (crc >>> 1) ^ ((crc & 1) ? 0xedb88320 : 0);
50
+ }
51
+ }
52
+ const header = Buffer.alloc(4), checksum = Buffer.alloc(4);
53
+ header.writeUInt32BE(data.length);
54
+ checksum.writeUInt32BE((crc ^ 0xffffffff) >>> 0);
55
+ return Buffer.concat([header, body, checksum]);
56
+ };
57
+ const header = Buffer.alloc(13);
58
+ header.writeUInt32BE(32);
59
+ header.writeUInt32BE(16, 4);
60
+ header[8] = 8;
61
+ header[9] = 6;
62
+ const pixels = Buffer.alloc(16 * (1 + 32 * 4));
63
+ for (let y = 0; y < 16; y++) {
64
+ for (let x = 0; x < 32; x++) {
65
+ const offset = y * 129 + 1 + x * 4;
66
+ pixels[offset] = x < 16 ? 50 : 255;
67
+ pixels[offset + 1] = x < 16 ? 170 : 200;
68
+ pixels[offset + 2] = x < 16 ? 230 : 60;
69
+ pixels[offset + 3] = 255;
70
+ }
71
+ }
72
+ return Buffer.concat([Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]), chunk("IHDR", header), chunk("IDAT", deflateSync(pixels)), chunk("IEND", Buffer.alloc(0))]);
73
+ }
74
+ /** Native 2D authoring course uses the shared Luau lifecycle and TS component vocabulary. */
75
+ export function createNativeCpp2dCourse(id, title = "Relay Course") {
76
+ const base = createNativeCppCourse(id, title), image = courseAtlas();
77
+ const first = { x: 0, y: 0, width: 16, height: 16 }, second = { x: 16, y: 0, width: 16, height: 16 };
78
+ const { camera: _camera, ...common } = base.document;
79
+ const document = nativeGame2dDocument.parse({ ...common, schemaVersion: 5, dimension: "2d",
80
+ gravity: { x: 0, y: -9.81 }, camera2d: { width: 16, height: 9, zoom: 1 },
81
+ assets: [...base.document.assets, { id: "course-atlas", kind: "image", path: "course.png", size: image.length, digest: createHash("sha256").update(image).digest("hex") }],
82
+ lighting: { ambient: { color: "#ffffff", intensity: 0.65 }, points: [{ x: 3, y: 2, color: "#ffdd88", intensity: 1, radius: 5, falloff: 1 }] },
83
+ backgrounds: [{ id: "sky", assetId: "course-atlas", width: 16, height: 9, frame: first, layer: -100, parallax: { x: 0.2, y: 0.2 }, mode: "repeat" }],
84
+ scripts: [
85
+ { id: "platform-motion", language: "luau", source: "return {\n onFixedUpdate = function(ctx)\n ctx.command({ kind = \"setVelocity\", velocity = { x = math.cos(ctx.tick / 60), y = 0 } })\n end,\n}\n" },
86
+ { id: "gate-control", language: "luau", source: "return {\n onFixedUpdate = function(ctx)\n if ctx.tick >= 2 then\n ctx.command({ kind = \"setPosition\", position = { x = 4, y = 5 } })\n end\n end,\n}\n" },
87
+ base.document.scripts.find(script => script.id === "collect-audio"),
88
+ base.document.scripts.find(script => script.id === "course-control")
89
+ ], scenes: [{ id: "course", entities: [
90
+ { id: "floor", tilemap: { assetId: "course-atlas", solid: true, tiles: Array.from({ length: 16 }, (_, index) => ({ x: index - 8, y: -2, width: 1, height: 1, frame: first })) } },
91
+ { id: "player", transform: { x: 0, y: 0 }, body2d: { type: "kinematic", gravityScale: 1 }, collider2d: { width: 0.7, height: 1 }, sprite: { assetId: "course-atlas", width: 0.7, height: 1, frame: first, layer: 2 }, animator: { frames: [first, second], ticksPerFrame: 15 }, behaviors: [{ id: "course", scriptId: "course-control" }] },
92
+ { id: "collectible", transform: { x: 0, y: 0 }, collider2d: { width: 0.4, height: 0.4, sensor: true }, gameplay: { collectible: true, scoreValue: 1 }, sprite: { assetId: "course-atlas", width: 0.4, height: 0.4, frame: second, layer: 3, unlit: true }, behaviors: [{ id: "tone", scriptId: "collect-audio" }] },
93
+ { id: "platform", transform: { x: -3, y: 0 }, body2d: { type: "static" }, collider2d: { width: 2, height: 0.3 }, sprite: { assetId: "course-atlas", width: 2, height: 0.3, frame: first }, behaviors: [{ id: "motion", scriptId: "platform-motion" }] },
94
+ { id: "one-way", transform: { x: 2, y: 1 }, collider2d: { width: 2, height: 0.2, oneWay: true }, sprite: { assetId: "course-atlas", width: 2, height: 0.2, frame: second } },
95
+ { id: "gate", transform: { x: 4, y: 0 }, collider2d: { width: 0.3, height: 3 }, sprite: { assetId: "course-atlas", width: 0.3, height: 3, frame: second }, behaviors: [{ id: "open", scriptId: "gate-control" }] }
96
+ ] }] });
97
+ return { document, audio: base.audio, files: { ...base.files, "course.png": image } };
98
+ }
99
+ //# sourceMappingURL=native-template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-template.js","sourceRoot":"","sources":["../src/native-template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAwD,MAAM,mCAAmC,CAAC;AACrJ,sFAAsF;AACtF,MAAM,UAAU,qBAAqB,CAAC,EAAU,EAAE,KAAK,GAAG,cAAc;IACtE,MAAM,MAAM,GAAG,IAAI,EAAE,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC;IACzD,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAAC,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IAAC,GAAG,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IAAC,GAAG,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAAC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,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAC,EAAE;iBACnN,EAAE,CAAC,EAAE,CAAC,CAAC;IACV,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,EAAE,CAAC;AACxF,CAAC"}
@@ -0,0 +1,36 @@
1
+ export declare class NativeGameWorkerError extends Error {
2
+ readonly code: string;
3
+ readonly currentRevision?: string | number | undefined;
4
+ readonly path?: string | undefined;
5
+ readonly details?: Readonly<Record<string, unknown>> | undefined;
6
+ constructor(code: string, message: string, currentRevision?: string | number | undefined, path?: string | undefined, details?: Readonly<Record<string, unknown>> | undefined);
7
+ }
8
+ export interface NativeGameWorkerOptions {
9
+ readonly executable: string;
10
+ readonly args?: readonly string[];
11
+ readonly maxFrameBytes?: number;
12
+ readonly requestTimeoutMs?: number;
13
+ readonly killGraceMs?: number;
14
+ }
15
+ /** A dedicated child receives no inherited provider credentials or application environment. */
16
+ export declare class NativeGameWorker {
17
+ private readonly child;
18
+ private readonly pending;
19
+ private readonly maxFrameBytes;
20
+ private readonly timeoutMs;
21
+ private readonly killGraceMs;
22
+ private buffer;
23
+ private closed;
24
+ private stopping;
25
+ private diagnostics;
26
+ constructor(options: NativeGameWorkerOptions);
27
+ request(operation: string, input?: Readonly<Record<string, unknown>>, options?: {
28
+ readonly signal?: AbortSignal;
29
+ readonly requestId?: string;
30
+ }): Promise<unknown>;
31
+ close(): void;
32
+ private cancelAndStop;
33
+ private receive;
34
+ private fail;
35
+ }
36
+ //#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,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,WAAW,CAAM;IAEzB,YAAY,OAAO,EAAE,uBAAuB,EAe3C;IAEK,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM,EAAE,OAAO,GAAE;QACvF,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;QAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;KACvD,GAAG,OAAO,CAAC,OAAO,CAAC,CAwBxB;IAED,KAAK,IAAI,IAAI,CAGZ;IAED,OAAO,CAAC,aAAa;IAcrB,OAAO,CAAC,OAAO;IAyBf,OAAO,CAAC,IAAI;CAOb"}
@@ -0,0 +1,158 @@
1
+ import { spawn } from "node:child_process";
2
+ import { randomUUID } from "node:crypto";
3
+ import { pack, unpack } from "msgpackr";
4
+ import { z } from "zod";
5
+ const responseSchema = z.discriminatedUnion("status", [
6
+ z.object({ protocolVersion: z.literal(1), requestId: z.string(), status: z.literal("ok"), result: z.unknown() }),
7
+ z.object({ protocolVersion: z.literal(1), requestId: z.string(), status: z.literal("error"),
8
+ error: z.object({ code: z.string(), message: z.string(), path: z.string().optional(), currentRevision: z.union([z.string(), z.number()]).optional(),
9
+ details: z.record(z.string(), z.unknown()).optional() }) })
10
+ ]);
11
+ export class NativeGameWorkerError extends Error {
12
+ code;
13
+ currentRevision;
14
+ path;
15
+ details;
16
+ constructor(code, message, currentRevision, path, details) {
17
+ super(message);
18
+ this.code = code;
19
+ this.currentRevision = currentRevision;
20
+ this.path = path;
21
+ this.details = details;
22
+ this.name = "NativeGameWorkerError";
23
+ }
24
+ }
25
+ /** A dedicated child receives no inherited provider credentials or application environment. */
26
+ export class NativeGameWorker {
27
+ child;
28
+ pending = new Map();
29
+ maxFrameBytes;
30
+ timeoutMs;
31
+ killGraceMs;
32
+ buffer = Buffer.alloc(0);
33
+ closed = false;
34
+ stopping = false;
35
+ diagnostics = "";
36
+ constructor(options) {
37
+ this.maxFrameBytes = options.maxFrameBytes ?? 16 * 1024 * 1024;
38
+ this.timeoutMs = options.requestTimeoutMs ?? 30_000;
39
+ this.killGraceMs = options.killGraceMs ?? 250;
40
+ this.child = spawn(options.executable, [...(options.args ?? [])], {
41
+ stdio: "pipe", env: { PATH: process.env.PATH, SystemRoot: process.env.SystemRoot }
42
+ });
43
+ this.child.stdout.on("data", (chunk) => this.receive(chunk));
44
+ this.child.stderr.on("data", (chunk) => {
45
+ this.diagnostics = (this.diagnostics + chunk.toString("utf8")).slice(-8192);
46
+ });
47
+ this.child.on("error", (error) => this.fail(error));
48
+ this.child.stdin.on("error", (error) => this.fail(error));
49
+ this.child.on("exit", (code, signal) => this.fail(new NativeGameWorkerError("worker_exit", `Native game worker exited (${signal ?? code}): ${this.diagnostics}`)));
50
+ }
51
+ async request(operation, input = {}, options = {}) {
52
+ options.signal?.throwIfAborted();
53
+ if (this.closed || this.stopping) {
54
+ throw new NativeGameWorkerError("worker_closed", "Native game worker is closed");
55
+ }
56
+ if (this.pending.size >= 64 || this.child.stdin.writableLength > this.maxFrameBytes) {
57
+ throw new NativeGameWorkerError("backpressure", "Native game worker request queue is full");
58
+ }
59
+ const requestId = options.requestId ?? randomUUID();
60
+ if (this.pending.has(requestId)) {
61
+ throw new NativeGameWorkerError("duplicate_request", "Request is already pending");
62
+ }
63
+ const payload = pack({ ...input, protocolVersion: 1, requestId, operation });
64
+ if (payload.length > this.maxFrameBytes) {
65
+ throw new NativeGameWorkerError("frame_limit", "Request exceeds frame limit");
66
+ }
67
+ const frame = Buffer.allocUnsafe(payload.length + 4);
68
+ frame.writeUInt32BE(payload.length);
69
+ payload.copy(frame, 4);
70
+ return new Promise((resolve, reject) => {
71
+ const abort = () => {
72
+ const error = new NativeGameWorkerError("cancelled", "Native game request cancelled");
73
+ this.cancelAndStop(requestId, error);
74
+ };
75
+ const timer = setTimeout(() => this.cancelAndStop(requestId, new NativeGameWorkerError("timeout", "Native game request timed out")), this.timeoutMs);
76
+ const dispose = () => { clearTimeout(timer); options.signal?.removeEventListener("abort", abort); };
77
+ this.pending.set(requestId, { resolve, reject, dispose });
78
+ options.signal?.addEventListener("abort", abort, { once: true });
79
+ this.child.stdin.write(frame, (error) => { if (error) {
80
+ this.fail(error);
81
+ } });
82
+ });
83
+ }
84
+ close() {
85
+ if (this.closed) {
86
+ return;
87
+ }
88
+ this.fail(new NativeGameWorkerError("worker_closed", "Native game worker closed"));
89
+ }
90
+ cancelAndStop(targetRequestId, error) {
91
+ const pending = this.pending.get(targetRequestId);
92
+ if (!pending) {
93
+ return;
94
+ }
95
+ this.stopping = true;
96
+ pending.dispose();
97
+ pending.reject(error);
98
+ this.pending.delete(targetRequestId);
99
+ // An unacknowledged mutation has an unknown outcome. Terminate this worker rather than reuse uncertain state.
100
+ const payload = pack({ protocolVersion: 1, requestId: randomUUID(), operation: "cancel", targetRequestId });
101
+ const frame = Buffer.allocUnsafe(payload.length + 4);
102
+ frame.writeUInt32BE(payload.length);
103
+ payload.copy(frame, 4);
104
+ this.child.stdin.write(frame);
105
+ const timer = setTimeout(() => this.fail(error), this.killGraceMs);
106
+ timer.unref();
107
+ }
108
+ receive(chunk) {
109
+ if (this.closed) {
110
+ return;
111
+ }
112
+ this.buffer = Buffer.concat([this.buffer, chunk]);
113
+ while (this.buffer.length >= 4) {
114
+ const length = this.buffer.readUInt32BE(0);
115
+ if (length === 0 || length > this.maxFrameBytes) {
116
+ this.fail(new NativeGameWorkerError("frame_limit", "Worker response exceeds frame limit"));
117
+ return;
118
+ }
119
+ if (this.buffer.length < length + 4) {
120
+ return;
121
+ }
122
+ const bytes = this.buffer.subarray(4, length + 4);
123
+ this.buffer = this.buffer.subarray(length + 4);
124
+ try {
125
+ const response = responseSchema.parse(unpack(bytes));
126
+ const pending = this.pending.get(response.requestId);
127
+ if (!pending) {
128
+ continue;
129
+ }
130
+ pending.dispose();
131
+ this.pending.delete(response.requestId);
132
+ if (response.status === "error") {
133
+ pending.reject(new NativeGameWorkerError(response.error.code, response.error.message, response.error.currentRevision, response.error.path, response.error.details));
134
+ }
135
+ else {
136
+ pending.resolve(response.result);
137
+ }
138
+ }
139
+ catch (error) {
140
+ this.fail(error instanceof Error ? error : new Error(String(error)));
141
+ return;
142
+ }
143
+ }
144
+ }
145
+ fail(error) {
146
+ if (this.closed) {
147
+ return;
148
+ }
149
+ this.closed = true;
150
+ for (const pending of this.pending.values()) {
151
+ pending.dispose();
152
+ pending.reject(error);
153
+ }
154
+ this.pending.clear();
155
+ this.child.kill("SIGKILL");
156
+ }
157
+ }
158
+ //# sourceMappingURL=native-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-worker.js","sourceRoot":"","sources":["../src/native-worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAuC,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,cAAc,GAAG,CAAC,CAAC,kBAAkB,CAAC,QAAQ,EAAE;IACpD,CAAC,CAAC,MAAM,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;IAChH,CAAC,CAAC,MAAM,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;QACzF,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,I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