pelican-engine 0.0.0-stage → 0.3.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 (192) hide show
  1. package/AGENTS.md +147 -0
  2. package/LICENSE +22 -0
  3. package/README.md +129 -2
  4. package/distribution.json +197 -0
  5. package/docs/AI-WORKFLOW.md +517 -0
  6. package/docs/ARCHITECTURE.md +268 -0
  7. package/docs/CAPABILITIES.md +264 -0
  8. package/docs/DECISIONS.md +107 -0
  9. package/docs/M3-USAGE.md +192 -0
  10. package/docs/PELICAN-MIGRATION.md +38 -0
  11. package/docs/RENDER-BACKENDS.md +50 -0
  12. package/docs/ROADMAP.md +239 -0
  13. package/docs/THIRD-PARTY-NOTICES.md +151 -0
  14. package/docs/api/REFERENCE.md +1435 -0
  15. package/docs/api/index.json +1139 -0
  16. package/docs/npm/DISTRIBUTION.md +130 -0
  17. package/docs/npm/GAME-AUTHOR.md +147 -0
  18. package/engine.manifest.json +15 -0
  19. package/lib/assets/audio.js +67 -0
  20. package/lib/assets/errors.js +36 -0
  21. package/lib/assets/glb.js +277 -0
  22. package/lib/assets/index.js +53 -0
  23. package/lib/assets/jpeg.js +199 -0
  24. package/lib/assets/model.js +558 -0
  25. package/lib/assets/optimize.js +95 -0
  26. package/lib/assets/texture.js +187 -0
  27. package/lib/compiler/distribution.js +17 -0
  28. package/lib/compiler/extract.js +425 -0
  29. package/lib/compiler/graph.js +366 -0
  30. package/lib/compiler/index.js +574 -0
  31. package/lib/compiler/normalize.js +1194 -0
  32. package/lib/compiler/source-map.js +25 -0
  33. package/lib/compiler/types.js +2 -0
  34. package/lib/compiler/version.js +93 -0
  35. package/lib/experiments/simulation/index.js +2 -0
  36. package/lib/experiments/simulation/math.js +41 -0
  37. package/lib/experiments/simulation/probe.js +215 -0
  38. package/lib/experiments/simulation/scenes.js +192 -0
  39. package/lib/experiments/simulation/solver.js +346 -0
  40. package/lib/experiments/simulation/types.js +1 -0
  41. package/lib/experiments/world/adapters.js +30 -0
  42. package/lib/experiments/world/geometry.js +180 -0
  43. package/lib/experiments/world/index.js +2 -0
  44. package/lib/experiments/world/probe.js +288 -0
  45. package/lib/experiments/world/types.js +1 -0
  46. package/lib/experiments/world/world.js +599 -0
  47. package/lib/navigation/index.js +157 -0
  48. package/lib/physics/index.js +909 -0
  49. package/lib/protocol/index.js +92 -0
  50. package/lib/renderer/acceleration.js +609 -0
  51. package/lib/renderer/browser.js +2015 -0
  52. package/lib/renderer/bsdf.js +260 -0
  53. package/lib/renderer/checkpoint.js +88 -0
  54. package/lib/renderer/compute-executor.js +1034 -0
  55. package/lib/renderer/compute-texture-assets.js +49 -0
  56. package/lib/renderer/compute-view-contract.js +1 -0
  57. package/lib/renderer/denoiser.js +361 -0
  58. package/lib/renderer/dielectric.js +360 -0
  59. package/lib/renderer/embedded-image-pixels.js +368 -0
  60. package/lib/renderer/emissive-lights.js +67 -0
  61. package/lib/renderer/environment-importance.js +55 -0
  62. package/lib/renderer/environment.js +346 -0
  63. package/lib/renderer/gameplay.js +464 -0
  64. package/lib/renderer/geometry.js +103 -0
  65. package/lib/renderer/graph-expressions.js +485 -0
  66. package/lib/renderer/graph-tsl.js +141 -0
  67. package/lib/renderer/graph.js +214 -0
  68. package/lib/renderer/managed-texture-sampling.js +29 -0
  69. package/lib/renderer/material-graphs.js +297 -0
  70. package/lib/renderer/medium.js +348 -0
  71. package/lib/renderer/models.js +1053 -0
  72. package/lib/renderer/motion-shader.js +40 -0
  73. package/lib/renderer/path-shader.js +196 -0
  74. package/lib/renderer/pathtrace.js +324 -0
  75. package/lib/renderer/postprocess-contract.js +1 -0
  76. package/lib/renderer/postprocess.js +494 -0
  77. package/lib/renderer/render-buffers.js +132 -0
  78. package/lib/renderer/render-textures.js +155 -0
  79. package/lib/renderer/startup.js +50 -0
  80. package/lib/renderer/surface-capture.js +199 -0
  81. package/lib/renderer/surface-gpu.js +270 -0
  82. package/lib/renderer/surface-motion.js +84 -0
  83. package/lib/renderer/surface-ray-shader.js +91 -0
  84. package/lib/renderer/surface-shader.js +88 -0
  85. package/lib/renderer/surface-tracer.js +1720 -0
  86. package/lib/renderer/surface.js +1425 -0
  87. package/lib/renderer/temporal-filter.js +512 -0
  88. package/lib/renderer/texture-pixels.js +207 -0
  89. package/lib/renderer/traversal-nodes.js +54 -0
  90. package/lib/renderer/ui.js +446 -0
  91. package/lib/renderer/vertex-bounds.js +127 -0
  92. package/lib/renderer/vertex-contract.js +1 -0
  93. package/lib/renderer/vertex-graphs.js +197 -0
  94. package/lib/renderer/volume-shader.js +50 -0
  95. package/lib/runtime/compute-contract.js +1 -0
  96. package/lib/runtime/compute-service.js +674 -0
  97. package/lib/runtime/contracts.js +1 -0
  98. package/lib/runtime/error.js +37 -0
  99. package/lib/runtime/events.js +189 -0
  100. package/lib/runtime/game-services.js +772 -0
  101. package/lib/runtime/host.js +839 -0
  102. package/lib/runtime/material-parameters.js +145 -0
  103. package/lib/runtime/plugins.js +1 -0
  104. package/lib/runtime/postprocess-contract.js +1 -0
  105. package/lib/runtime/postprocess.js +189 -0
  106. package/lib/runtime/prefabs.js +13 -0
  107. package/lib/runtime/random.js +88 -0
  108. package/lib/runtime/render-buffer-contract.js +1 -0
  109. package/lib/runtime/render-buffers.js +243 -0
  110. package/lib/runtime/render-capabilities.js +17 -0
  111. package/lib/runtime/render-settings.js +249 -0
  112. package/lib/runtime/render-texture-contract.js +1 -0
  113. package/lib/runtime/render-textures.js +271 -0
  114. package/lib/runtime/resources.js +648 -0
  115. package/lib/runtime/scheduler.js +765 -0
  116. package/lib/runtime/storage.js +169 -0
  117. package/lib/runtime/world.js +594 -0
  118. package/lib/schema/index.js +24 -0
  119. package/lib/sdk/graph-values.js +16 -0
  120. package/lib/sdk/index.d.ts +800 -0
  121. package/lib/sdk/index.js +82 -0
  122. package/lib/tools/api-index.js +113 -0
  123. package/lib/tools/browser-session.js +89 -0
  124. package/lib/tools/cli.js +513 -0
  125. package/lib/tools/compress-dist.js +59 -0
  126. package/lib/tools/control-client.js +153 -0
  127. package/lib/tools/control-server.js +633 -0
  128. package/lib/tools/diagnostic-code.js +3 -0
  129. package/lib/tools/doctor.js +496 -0
  130. package/lib/tools/npm/browser-cli.js +6 -0
  131. package/lib/tools/npm/entry.js +40 -0
  132. package/lib/tools/npm/layout.js +195 -0
  133. package/lib/tools/setup.js +153 -0
  134. package/licenses/@dimforge/rapier2d-compat/LICENSE +201 -0
  135. package/licenses/@dimforge/rapier3d-compat/LICENSE +201 -0
  136. package/licenses/@gltf-transform/core/LICENSE.md +21 -0
  137. package/licenses/@gltf-transform/extensions/LICENSE.md +21 -0
  138. package/licenses/@gltf-transform/functions/LICENSE.md +21 -0
  139. package/licenses/@img/colour/LICENSE.md +82 -0
  140. package/licenses/@img/sharp-win32-x64/LICENSE +191 -0
  141. package/licenses/@oxc-project/types/LICENSE +22 -0
  142. package/licenses/@rolldown/pluginutils/LICENSE +21 -0
  143. package/licenses/@tweenjs/tween.js/LICENSE +23 -0
  144. package/licenses/@types/ndarray/LICENSE +21 -0
  145. package/licenses/@types/node/LICENSE +21 -0
  146. package/licenses/@types/stats.js/LICENSE +21 -0
  147. package/licenses/@types/three/@dimforge/rapier3d-compat/LICENSE +201 -0
  148. package/licenses/@types/three/LICENSE +21 -0
  149. package/licenses/@types/webxr/LICENSE +21 -0
  150. package/licenses/@webgpu/types/LICENSE +26 -0
  151. package/licenses/THIRD-PARTY-NOTICES.md +139 -0
  152. package/licenses/cwise-compiler/LICENSE +22 -0
  153. package/licenses/detect-libc/LICENSE +201 -0
  154. package/licenses/esbuild/LICENSE.md +21 -0
  155. package/licenses/fast-png/LICENSE +21 -0
  156. package/licenses/fdir/LICENSE +7 -0
  157. package/licenses/fflate/LICENSE +21 -0
  158. package/licenses/iobuffer/LICENSE +22 -0
  159. package/licenses/iota-array/LICENSE +22 -0
  160. package/licenses/is-buffer/LICENSE +21 -0
  161. package/licenses/ktx-parse/LICENSE +21 -0
  162. package/licenses/lightningcss/LICENSE +373 -0
  163. package/licenses/lightningcss-win32-x64-msvc/LICENSE +373 -0
  164. package/licenses/meshoptimizer/LICENSE.md +21 -0
  165. package/licenses/nanoid/LICENSE +20 -0
  166. package/licenses/ndarray/LICENSE +22 -0
  167. package/licenses/ndarray-lanczos/LICENSE +21 -0
  168. package/licenses/ndarray-ops/LICENSE +22 -0
  169. package/licenses/ndarray-pixels/LICENSE +21 -0
  170. package/licenses/ngraph.path/LICENSE +21 -0
  171. package/licenses/picocolors/LICENSE +15 -0
  172. package/licenses/picomatch/LICENSE +21 -0
  173. package/licenses/playwright/LICENSE +202 -0
  174. package/licenses/playwright/NOTICE +5 -0
  175. package/licenses/playwright-core/LICENSE +202 -0
  176. package/licenses/playwright-core/NOTICE +5 -0
  177. package/licenses/postcss/LICENSE +20 -0
  178. package/licenses/prettier/LICENSE +7 -0
  179. package/licenses/property-graph/LICENSE +21 -0
  180. package/licenses/rolldown/LICENSE +25 -0
  181. package/licenses/semver/LICENSE +15 -0
  182. package/licenses/sharp/LICENSE +191 -0
  183. package/licenses/source-map-js/LICENSE +28 -0
  184. package/licenses/three/LICENSE +21 -0
  185. package/licenses/tinyglobby/LICENSE +21 -0
  186. package/licenses/tsx/LICENSE +21 -0
  187. package/licenses/typescript/LICENSE.txt +55 -0
  188. package/licenses/undici-types/LICENSE +21 -0
  189. package/licenses/uniq/LICENSE +22 -0
  190. package/licenses/vite/LICENSE.md +2084 -0
  191. package/package.json +49 -4
  192. package/web/index.html +34 -0
@@ -0,0 +1,153 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { parseCommand, PROTOCOL_VERSION, result, } from "../protocol/index.js";
3
+ const MAX_BODY = 1024 * 1024;
4
+ const MAX_RESPONSE = 8 * MAX_BODY;
5
+ const statuses = [
6
+ "queued",
7
+ "running",
8
+ "succeeded",
9
+ "failed",
10
+ "cancelled",
11
+ "timed_out",
12
+ ];
13
+ function failure(taskId, code, status = "failed") {
14
+ return result(taskId, status, { stateUnknown: true }, [
15
+ {
16
+ code,
17
+ severity: "error",
18
+ message: "Control request did not yield a confirmed result. Runtime state must not be assumed preserved.",
19
+ remediation: "Inspect server task status using the same taskId; explicitly reset the session when its state is discarded or uncertain.",
20
+ },
21
+ ]);
22
+ }
23
+ function loopback(host) {
24
+ return (host === "localhost" ||
25
+ host === "[::1]" ||
26
+ /^127(?:\.\d{1,3}){3}$/.test(host));
27
+ }
28
+ /** Node-side client; imports do not start services, browsers, or command execution. */
29
+ export function createControlClient(options) {
30
+ let base;
31
+ try {
32
+ base = new URL(options.url);
33
+ }
34
+ catch {
35
+ throw new Error("TC_CONTROL_URL_INVALID: Expected a local HTTP development server URL.");
36
+ }
37
+ if (base.protocol !== "http:" ||
38
+ !loopback(base.hostname) ||
39
+ base.username ||
40
+ base.password ||
41
+ base.search ||
42
+ base.hash)
43
+ throw new Error("TC_CONTROL_URL_INVALID: Expected a loopback HTTP development server URL without credentials.");
44
+ const timeoutMs = options.timeoutMs ?? 35_000;
45
+ if (!Number.isInteger(timeoutMs) || timeoutMs < 10 || timeoutMs > 120_000)
46
+ throw new Error("TC_CONTROL_TIMEOUT_RANGE: timeoutMs must be an integer in [10,120000].");
47
+ async function request(route, body, sendOptions = {}) {
48
+ const taskId = sendOptions.taskId ?? `control-${randomUUID()}`;
49
+ if (!/^[a-zA-Z0-9_-]{1,96}$/.test(taskId))
50
+ return failure(`control-${randomUUID()}`, "TC_CONTROL_TASK_ID_INVALID");
51
+ let serialized;
52
+ try {
53
+ if (body !== undefined)
54
+ serialized = JSON.stringify(body);
55
+ if (serialized && Buffer.byteLength(serialized) > MAX_BODY)
56
+ return failure(taskId, "TC_CONTROL_BODY_TOO_LARGE");
57
+ }
58
+ catch {
59
+ return failure(taskId, "TC_CONTROL_JSON_INVALID");
60
+ }
61
+ const abort = new AbortController();
62
+ const externalAbort = () => abort.abort();
63
+ let timedOut = false;
64
+ const timer = setTimeout(() => {
65
+ timedOut = true;
66
+ abort.abort();
67
+ }, timeoutMs);
68
+ sendOptions.signal?.addEventListener("abort", externalAbort, {
69
+ once: true,
70
+ });
71
+ if (sendOptions.signal?.aborted)
72
+ abort.abort();
73
+ try {
74
+ const response = await fetch(new URL(route, base.origin), {
75
+ method: body === undefined ? "GET" : "POST",
76
+ headers: {
77
+ "Content-Type": "application/json",
78
+ "X-Pelican-Task-Id": taskId,
79
+ },
80
+ body: serialized,
81
+ signal: abort.signal,
82
+ redirect: "error",
83
+ credentials: "omit",
84
+ cache: "no-store",
85
+ });
86
+ if (response.headers
87
+ .get("content-type")
88
+ ?.split(";", 1)[0]
89
+ .trim()
90
+ .toLowerCase() !== "application/json") {
91
+ await response.body?.cancel();
92
+ return failure(taskId, "TC_CONTROL_RESPONSE_INVALID");
93
+ }
94
+ const reader = response.body?.getReader();
95
+ if (!reader)
96
+ return failure(taskId, "TC_CONTROL_RESPONSE_INVALID");
97
+ const chunks = [];
98
+ let bytes = 0;
99
+ for (;;) {
100
+ const chunk = await reader.read();
101
+ if (chunk.done)
102
+ break;
103
+ bytes += chunk.value.byteLength;
104
+ if (bytes > MAX_RESPONSE) {
105
+ await reader.cancel();
106
+ return failure(taskId, "TC_CONTROL_RESPONSE_TOO_LARGE");
107
+ }
108
+ chunks.push(chunk.value);
109
+ }
110
+ const payload = JSON.parse(Buffer.concat(chunks).toString("utf8"));
111
+ if (!payload ||
112
+ payload.protocolVersion !== PROTOCOL_VERSION ||
113
+ payload.taskId !== taskId ||
114
+ !statuses.includes(payload.status) ||
115
+ !Array.isArray(payload.diagnostics) ||
116
+ !Array.isArray(payload.artifacts) ||
117
+ !("data" in payload))
118
+ return failure(taskId, "TC_CONTROL_RESPONSE_INVALID");
119
+ if (!response.ok && payload.status === "succeeded")
120
+ return failure(taskId, "TC_CONTROL_RESPONSE_INVALID");
121
+ return payload;
122
+ }
123
+ catch {
124
+ return failure(taskId, timedOut
125
+ ? "TC_CONTROL_CLIENT_TIMEOUT"
126
+ : sendOptions.signal?.aborted
127
+ ? "TC_CONTROL_CLIENT_CANCELLED"
128
+ : "TC_CONTROL_TRANSPORT_FAILURE", timedOut
129
+ ? "timed_out"
130
+ : sendOptions.signal?.aborted
131
+ ? "cancelled"
132
+ : "failed");
133
+ }
134
+ finally {
135
+ clearTimeout(timer);
136
+ sendOptions.signal?.removeEventListener("abort", externalAbort);
137
+ }
138
+ }
139
+ return {
140
+ send: async (command, sendOptions) => {
141
+ try {
142
+ parseCommand(command);
143
+ }
144
+ catch {
145
+ return failure(sendOptions?.taskId ?? `control-${randomUUID()}`, "TC_CONTROL_COMMAND_INVALID");
146
+ }
147
+ return request("/__pelican/control", command, sendOptions);
148
+ },
149
+ status: () => request("/__pelican/status", undefined),
150
+ cancel: (taskId) => request("/__pelican/cancel", { taskId }),
151
+ reset: () => request("/__pelican/session", { action: "reset" }),
152
+ };
153
+ }