oda-engine 0.0.0-stage → 0.1.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 (204) hide show
  1. package/README.md +151 -2
  2. package/bin/nowhere.mjs +352 -0
  3. package/lib/account.mjs +57 -0
  4. package/lib/agentModules.mjs +57 -0
  5. package/lib/devServer.mjs +351 -0
  6. package/lib/headless.mjs +231 -0
  7. package/lib/headlessPreview.mjs +212 -0
  8. package/lib/keys.mjs +517 -0
  9. package/lib/make.mjs +855 -0
  10. package/lib/mcp.mjs +537 -0
  11. package/lib/open.mjs +22 -0
  12. package/lib/preview.mjs +87 -0
  13. package/lib/previewRpc.mjs +134 -0
  14. package/lib/project.mjs +359 -0
  15. package/lib/publishFlow.mjs +131 -0
  16. package/lib/resources.mjs +50 -0
  17. package/lib/rules.mjs +60 -0
  18. package/lib/scaffold.mjs +42 -0
  19. package/lib/setup.mjs +59 -0
  20. package/lib/tools.mjs +668 -0
  21. package/package.json +51 -4
  22. package/template/game.config.json +9 -0
  23. package/template/scene.json +4 -0
  24. package/template/src/main.ts +11 -0
  25. package/vendor/DOCS.md +447 -0
  26. package/vendor/agent/appRun.mjs +520 -0
  27. package/vendor/agent/assets/brief.mjs +242 -0
  28. package/vendor/agent/assets/collider.mjs +531 -0
  29. package/vendor/agent/assets/environments/index.mjs +12 -0
  30. package/vendor/agent/assets/environments/worldlabs.mjs +161 -0
  31. package/vendor/agent/assets/fetch.mjs +168 -0
  32. package/vendor/agent/assets/footprint.mjs +13 -0
  33. package/vendor/agent/assets/gltf.mjs +547 -0
  34. package/vendor/agent/assets/hdr.mjs +269 -0
  35. package/vendor/agent/assets/imageOps.mjs +171 -0
  36. package/vendor/agent/assets/images/codex.mjs +307 -0
  37. package/vendor/agent/assets/images/fal.mjs +75 -0
  38. package/vendor/agent/assets/images/gemini.mjs +84 -0
  39. package/vendor/agent/assets/images/index.mjs +25 -0
  40. package/vendor/agent/assets/images/openai.mjs +75 -0
  41. package/vendor/agent/assets/images/stability.mjs +71 -0
  42. package/vendor/agent/assets/images/views.mjs +31 -0
  43. package/vendor/agent/assets/import.mjs +1352 -0
  44. package/vendor/agent/assets/inspect.mjs +465 -0
  45. package/vendor/agent/assets/jobs.mjs +196 -0
  46. package/vendor/agent/assets/ktx2.mjs +290 -0
  47. package/vendor/agent/assets/ledger.mjs +466 -0
  48. package/vendor/agent/assets/net.mjs +254 -0
  49. package/vendor/agent/assets/prices.json +39 -0
  50. package/vendor/agent/assets/providers/fal.mjs +115 -0
  51. package/vendor/agent/assets/providers/index.mjs +22 -0
  52. package/vendor/agent/assets/providers/meshy.mjs +119 -0
  53. package/vendor/agent/assets/providers/tripo.mjs +188 -0
  54. package/vendor/agent/assets/sources/ambientcg.mjs +129 -0
  55. package/vendor/agent/assets/sources/index.mjs +23 -0
  56. package/vendor/agent/assets/sources/polyhaven.mjs +237 -0
  57. package/vendor/agent/assets/sources/polypizza.mjs +121 -0
  58. package/vendor/agent/assets/splat.mjs +631 -0
  59. package/vendor/agent/assets/targets.mjs +122 -0
  60. package/vendor/agent/assets/tile.mjs +261 -0
  61. package/vendor/agent/assets/unzip.mjs +180 -0
  62. package/vendor/agent/blender/cleanup.py +360 -0
  63. package/vendor/agent/blender/convert.py +167 -0
  64. package/vendor/agent/blender/find.mjs +192 -0
  65. package/vendor/agent/blender/nw_export.py +104 -0
  66. package/vendor/agent/blender/nw_rubric.py +426 -0
  67. package/vendor/agent/blender/run.mjs +193 -0
  68. package/vendor/agent/blender/runner.py +252 -0
  69. package/vendor/agent/blender/sheet.py +743 -0
  70. package/vendor/agent/depth.mjs +134 -0
  71. package/vendor/agent/director/board.mjs +451 -0
  72. package/vendor/agent/director/contracts.mjs +663 -0
  73. package/vendor/agent/director/director.mjs +2365 -0
  74. package/vendor/agent/director/estimate.mjs +200 -0
  75. package/vendor/agent/director/gate.mjs +802 -0
  76. package/vendor/agent/director/limits.json +16 -0
  77. package/vendor/agent/director/methods.mjs +457 -0
  78. package/vendor/agent/director/policy.json +33 -0
  79. package/vendor/agent/director/prompts.mjs +244 -0
  80. package/vendor/agent/director/reading.mjs +341 -0
  81. package/vendor/agent/director/router.mjs +184 -0
  82. package/vendor/agent/director/seams.mjs +243 -0
  83. package/vendor/agent/director/session.mjs +643 -0
  84. package/vendor/agent/director/store.mjs +119 -0
  85. package/vendor/agent/director/taskGate.mjs +110 -0
  86. package/vendor/agent/director/teamLedger.mjs +118 -0
  87. package/vendor/agent/director/triage.mjs +63 -0
  88. package/vendor/agent/downloads.cjs +363 -0
  89. package/vendor/agent/flow.mjs +78 -0
  90. package/vendor/agent/guard.mjs +613 -0
  91. package/vendor/agent/host.mjs +1736 -0
  92. package/vendor/agent/language.mjs +58 -0
  93. package/vendor/agent/ledger.mjs +360 -0
  94. package/vendor/agent/locale.cjs +186 -0
  95. package/vendor/agent/loop/capacity.mjs +74 -0
  96. package/vendor/agent/loop/compose.mjs +127 -0
  97. package/vendor/agent/loop/gate.mjs +205 -0
  98. package/vendor/agent/loop/judge.mjs +189 -0
  99. package/vendor/agent/loop/levels.mjs +273 -0
  100. package/vendor/agent/loop/state.mjs +358 -0
  101. package/vendor/agent/notes.cjs +278 -0
  102. package/vendor/agent/pace.mjs +258 -0
  103. package/vendor/agent/panels.mjs +431 -0
  104. package/vendor/agent/prompt.mjs +342 -0
  105. package/vendor/agent/reference/board.mjs +410 -0
  106. package/vendor/agent/reference/compose.mjs +364 -0
  107. package/vendor/agent/reference/decode.mjs +56 -0
  108. package/vendor/agent/reference/facts.mjs +1874 -0
  109. package/vendor/agent/reference/png.mjs +107 -0
  110. package/vendor/agent/reference/records.mjs +63 -0
  111. package/vendor/agent/reference/web.mjs +252 -0
  112. package/vendor/agent/roles/artist.mjs +69 -0
  113. package/vendor/agent/roles/builder.mjs +79 -0
  114. package/vendor/agent/roles/checks.mjs +223 -0
  115. package/vendor/agent/roles/common.mjs +188 -0
  116. package/vendor/agent/roles/critic.mjs +171 -0
  117. package/vendor/agent/roles/index.mjs +39 -0
  118. package/vendor/agent/roles/modeller.mjs +142 -0
  119. package/vendor/agent/roles/qa.mjs +58 -0
  120. package/vendor/agent/roles/rubrics.mjs +79 -0
  121. package/vendor/agent/roles/sound.mjs +69 -0
  122. package/vendor/agent/rounds.cjs +333 -0
  123. package/vendor/agent/shared.mjs +284 -0
  124. package/vendor/agent/stopGate.mjs +574 -0
  125. package/vendor/agent/subagents.mjs +129 -0
  126. package/vendor/agent/tools/assets.mjs +499 -0
  127. package/vendor/agent/tools/blender.mjs +754 -0
  128. package/vendor/agent/tools/cards.mjs +479 -0
  129. package/vendor/agent/tools/choices.mjs +479 -0
  130. package/vendor/agent/tools/compose.mjs +74 -0
  131. package/vendor/agent/tools/environment.mjs +488 -0
  132. package/vendor/agent/tools/eyes.mjs +733 -0
  133. package/vendor/agent/tools/generate.mjs +338 -0
  134. package/vendor/agent/tools/guide.mjs +46 -0
  135. package/vendor/agent/tools/harness.mjs +193 -0
  136. package/vendor/agent/tools/image.mjs +643 -0
  137. package/vendor/agent/tools/index.mjs +162 -0
  138. package/vendor/agent/tools/look.mjs +578 -0
  139. package/vendor/agent/tools/loop.mjs +858 -0
  140. package/vendor/agent/tools/others.mjs +123 -0
  141. package/vendor/agent/tools/pictures.mjs +535 -0
  142. package/vendor/agent/tools/reference.mjs +366 -0
  143. package/vendor/agent/transcripts.mjs +118 -0
  144. package/vendor/agent-loop.mjs +602 -0
  145. package/vendor/agent-plugin/.claude-plugin/plugin.json +5 -0
  146. package/vendor/agent-plugin/skills/art-direction/SKILL.md +82 -0
  147. package/vendor/agent-plugin/skills/asset-legality/SKILL.md +101 -0
  148. package/vendor/agent-plugin/skills/asset-sources/SKILL.md +111 -0
  149. package/vendor/agent-plugin/skills/blender-modeling/SKILL.md +97 -0
  150. package/vendor/agent-plugin/skills/look-dev/SKILL.md +104 -0
  151. package/vendor/agent-plugin/skills/playtesting/SKILL.md +74 -0
  152. package/vendor/agent-plugin/skills/reference-loop/SKILL.md +102 -0
  153. package/vendor/agent-plugin/skills/sound-design/SKILL.md +60 -0
  154. package/vendor/agent-plugin/skills/style/SKILL.md +35 -0
  155. package/vendor/agent-plugin/skills/tsl-r185/SKILL.md +107 -0
  156. package/vendor/auth.cjs +570 -0
  157. package/vendor/build.cjs +953 -0
  158. package/vendor/catalog.json +455 -0
  159. package/vendor/connectors.cjs +688 -0
  160. package/vendor/eyes.mjs +733 -0
  161. package/vendor/gameExports.json +1390 -0
  162. package/vendor/git.cjs +222 -0
  163. package/vendor/models.json +57 -0
  164. package/vendor/publish.cjs +1018 -0
  165. package/vendor/refBoard.cjs +301 -0
  166. package/vendor/schema/dist/assets.d.ts +335 -0
  167. package/vendor/schema/dist/assets.js +439 -0
  168. package/vendor/schema/dist/brief.d.ts +357 -0
  169. package/vendor/schema/dist/brief.js +302 -0
  170. package/vendor/schema/dist/common.d.ts +9 -0
  171. package/vendor/schema/dist/common.js +13 -0
  172. package/vendor/schema/dist/config.d.ts +406 -0
  173. package/vendor/schema/dist/config.js +355 -0
  174. package/vendor/schema/dist/contract.d.ts +599 -0
  175. package/vendor/schema/dist/contract.js +1146 -0
  176. package/vendor/schema/dist/index.d.ts +14 -0
  177. package/vendor/schema/dist/index.js +21 -0
  178. package/vendor/schema/dist/look.d.ts +463 -0
  179. package/vendor/schema/dist/look.js +681 -0
  180. package/vendor/schema/dist/lookStats.d.ts +230 -0
  181. package/vendor/schema/dist/lookStats.js +768 -0
  182. package/vendor/schema/dist/pilot.d.ts +32 -0
  183. package/vendor/schema/dist/pilot.js +44 -0
  184. package/vendor/schema/dist/publish.d.ts +214 -0
  185. package/vendor/schema/dist/publish.js +291 -0
  186. package/vendor/schema/dist/scene.d.ts +75 -0
  187. package/vendor/schema/dist/scene.js +120 -0
  188. package/vendor/schema/dist/skyLight.d.ts +141 -0
  189. package/vendor/schema/dist/skyLight.js +436 -0
  190. package/vendor/schema/dist/style.d.ts +131 -0
  191. package/vendor/schema/dist/style.js +155 -0
  192. package/vendor/schema/package.json +1 -0
  193. package/vendor/selectionPrompt.mjs +51 -0
  194. package/vendor/useTools.mjs +195 -0
  195. package/vendor/userMessage.mjs +26 -0
  196. package/web-dist/assets/GaussianSplatUtils-CptQkDVX.js +1 -0
  197. package/web-dist/assets/KTX2Loader-C53LJqss.js +2 -0
  198. package/web-dist/assets/SPZLoader-BQ3tjaTv.js +1 -0
  199. package/web-dist/assets/gaussianSplat-_9tcWegB.js +1 -0
  200. package/web-dist/assets/index-Baka-ZO7.js +693 -0
  201. package/web-dist/assets/index-CcjyyQco.css +1 -0
  202. package/web-dist/assets/meshopt_decoder.module-BvwdjiD3.js +1 -0
  203. package/web-dist/assets/zstddec.module-CfFeQW7d.js +1 -0
  204. package/web-dist/index.html +34 -0
@@ -0,0 +1,439 @@
1
+ import { z } from 'zod';
2
+ // What a planet may carry beside its code, and the record of where each file
3
+ // came from. One implementation, run in the same three places as the rest of
4
+ // publish.ts: the studio's asset tools and its Publish button, and the
5
+ // `publish` Edge Function (bundled into _verifier.js). The ledger itself
6
+ // (assets.lock.json) is written by the studio alone, through asset_import,
7
+ // nw_blender, nw_take_download and a creator's drop; this file only says what
8
+ // a valid one looks like and what publishing makes of it.
9
+ //
10
+ // ASSET_EXTENSIONS and isAssetPath in publish.ts are unchanged: they describe
11
+ // what a scene may place (models). The kinds below are what a version
12
+ // directory may hold, which is more.
13
+ /** Every kind of file a planet may carry, its extensions and the most one
14
+ * file of it may weigh. Models keep the 50 MB storage ceiling
15
+ * (LIMITS.assetFileMb); the others are sized for what a browser decodes
16
+ * without stalling the first frame. A splat environment (a Gaussian splat,
17
+ * three's GaussianSplat) travels as .spz only: asset_import turns a .ply or
18
+ * a .splat into one, so the player reads a single compact format. It keeps
19
+ * the storage ceiling too, which is about 2.3 million splats with their
20
+ * full colour detail. It is not the planet's own splat.bin (publish.ts),
21
+ * the point cloud the universe shows inside a planet's glass. */
22
+ export const ASSET_KINDS = {
23
+ model: { extensions: ['.glb', '.gltf', '.obj', '.fbx', '.stl', '.ply', '.dae', '.3mf'], fileMb: 50 },
24
+ texture: { extensions: ['.ktx2', '.webp', '.png', '.jpg'], fileMb: 8 },
25
+ hdri: { extensions: ['.hdr', '.exr'], fileMb: 24 },
26
+ audio: { extensions: ['.ogg', '.mp3', '.wav'], fileMb: 10 },
27
+ lut: { extensions: ['.cube'], fileMb: 2 },
28
+ splat: { extensions: ['.spz'], fileMb: 50 },
29
+ };
30
+ /** Everything one planet carries, every kind together (LIMITS.assetsMb). */
31
+ export const ASSETS_TOTAL_MB = 100;
32
+ /** The sounds a planet carries, in total, inside ASSETS_TOTAL_MB. */
33
+ export const AUDIO_TOTAL_MB = 20;
34
+ /** How many splats one splat file may hold, and the whole planet, the count
35
+ * past which asset_import says a splat is for desktops, and the size a
36
+ * planet with splats aims to stay under (SPACE_FIRST W7: 60 MB, so it
37
+ * loads in a few seconds).
38
+ *
39
+ * Phase 1 timed the GPU alone (1.78 million splats in 15 ms a frame) and
40
+ * allowed 3 million. The real preview is far slower: the CLI's page with
41
+ * the look's defaults, headless Chrome on an Apple M5 Pro at 1280 x 720,
42
+ * walking inside the splat (2026-10-24), steady fps on WebGPU and WebGL 2:
43
+ *
44
+ * 195k about 55 and 40 (three's lion)
45
+ * 500k 33 and 19 (World Labs' example kitchen)
46
+ * 1M 19 and 10 (the kitchen twice over)
47
+ * 2M 9.5 and 5 (four times)
48
+ *
49
+ * so a frame costs about 30 ms per 500,000 splats on WebGPU. A planet may
50
+ * ask for 1 million at most, the most a fast desktop still walks; World
51
+ * Labs' full_res (about 2 million) is past it. Phones were not measured:
52
+ * 500,000 is the size World Labs exports for lighter devices, a vendor's
53
+ * choice, not a measurement. */
54
+ export const SPLAT_LIMITS = { count: 1_000_000, planetCount: 1_000_000, phoneCount: 500_000, planetMb: 60 };
55
+ /** The splats a ledger records (its splat entries' meta.count), leaving out
56
+ * the paths in `except` (files about to be replaced). */
57
+ export function planetSplats(files, except = []) {
58
+ let total = 0;
59
+ for (const [path, entry] of Object.entries(files ?? {})) {
60
+ if (entry?.kind !== 'splat' || except.includes(path))
61
+ continue;
62
+ const n = Number(entry.meta?.count);
63
+ if (Number.isFinite(n) && n > 0)
64
+ total += n;
65
+ }
66
+ return total;
67
+ }
68
+ /** What a check says about a planet's splat environments: more splats in all
69
+ * than a planet may draw, and a planet with splats past the size it aims
70
+ * for. Empty for a planet with none. */
71
+ export function splatAdvice(files, planetBytes) {
72
+ const entries = Object.values(files ?? {}).filter((e) => e?.kind === 'splat');
73
+ if (entries.length === 0)
74
+ return [];
75
+ const out = [];
76
+ const total = planetSplats(files);
77
+ const fmt = (n) => n.toLocaleString('en-US');
78
+ if (total > SPLAT_LIMITS.planetCount) {
79
+ out.push(`The planet's splat files hold ${fmt(total)} splats in all, past the ${fmt(SPLAT_LIMITS.planetCount)} a planet may draw: take one out, or import a smaller export.`);
80
+ }
81
+ const mb = planetBytes / (1024 * 1024);
82
+ if (mb > SPLAT_LIMITS.planetMb) {
83
+ out.push(`With splats the planet aims to stay under ${SPLAT_LIMITS.planetMb} MB so it loads in a few seconds; it now weighs ${Math.round(mb * 10) / 10} MB. A smaller export (World Labs' 500k), or fewer other files, brings it down.`);
84
+ }
85
+ return out;
86
+ }
87
+ const extOf = (path) => {
88
+ const name = path.slice(path.lastIndexOf('/') + 1);
89
+ const dot = name.lastIndexOf('.');
90
+ return dot < 1 ? '' : name.slice(dot).toLowerCase();
91
+ };
92
+ /** The kind a file is by its extension, or null for one a planet cannot carry. */
93
+ export function assetKindOf(path) {
94
+ const ext = extOf(String(path ?? ''));
95
+ if (!ext)
96
+ return null;
97
+ for (const kind of Object.keys(ASSET_KINDS)) {
98
+ if (ASSET_KINDS[kind].extensions.includes(ext))
99
+ return kind;
100
+ }
101
+ return null;
102
+ }
103
+ /** A file a planet may carry: directly inside assets/, one of the kinds above,
104
+ * nothing that climbs out. The same structural rules as isAssetPath, so every
105
+ * model a scene could place before is still a path a planet may carry; the
106
+ * Storage key is built from this string. */
107
+ export function isPublishablePath(path) {
108
+ if (typeof path !== 'string' || !path.startsWith('assets/'))
109
+ return false;
110
+ if (path.includes('..') || path.includes('\\'))
111
+ return false;
112
+ if (path.split('/').length !== 2)
113
+ return false;
114
+ const name = path.slice('assets/'.length);
115
+ if (name.lastIndexOf('.') < 1)
116
+ return false;
117
+ return assetKindOf(path) !== null;
118
+ }
119
+ /** How big a thing is, which sets how many triangles and texture pixels it may
120
+ * spend. The agent names one when it imports or builds a model. */
121
+ export const ASSET_CLASSES = ['small', 'prop', 'large', 'hero', 'character', 'building', 'terrain'];
122
+ export const TRIANGLE_BUDGETS = {
123
+ small: 2000,
124
+ prop: 5000,
125
+ large: 20000,
126
+ hero: 50000,
127
+ character: 30000,
128
+ building: 40000,
129
+ terrain: 100000,
130
+ };
131
+ /** The longest side of any one texture, in pixels. */
132
+ export const TEXTURE_BUDGETS = {
133
+ small: 512,
134
+ prop: 1024,
135
+ large: 2048,
136
+ hero: 2048,
137
+ character: 2048,
138
+ building: 2048,
139
+ terrain: 2048,
140
+ };
141
+ /** What a planet player built from this package decodes: meshopt-compressed
142
+ * geometry and KTX2 textures, both by WebAssembly, which the player page's
143
+ * CSP allows from publish contract 4 on (decision D1). The server and the
144
+ * player that are live may still be older, so whether one planet may carry
145
+ * them is the handshake's business ('meshopt' and 'ktx2' in what each side
146
+ * offers), and asset_import writes them only where the last pre-flight did
147
+ * not find a side without them. */
148
+ export const DECODERS_LIVE = { meshopt: true, ktx2: true };
149
+ /** Whether a planet built from this package shows its credits to visitors:
150
+ * the planet page lists the manifest's credit lines from publish contract 4
151
+ * on (decision D2). CC BY needs a visible credit, so a planet that carries a
152
+ * CC BY file needs 'credits' of the player that shows it, and a server or a
153
+ * player from before contract 4 does not offer it. */
154
+ export const CREDITS_SHOWN = true;
155
+ // ---------------------------------------------------------------------------
156
+ // the ledger
157
+ // ---------------------------------------------------------------------------
158
+ export const LEDGER_FILE = 'assets.lock.json';
159
+ const DAY = /^\d{4}-\d{2}-\d{2}$/;
160
+ const SHA = /^[0-9a-f]{64}$/;
161
+ export const AssetEntry = z.object({
162
+ /** blend and image: inputs under blender/ only. */
163
+ kind: z.enum(['model', 'texture', 'hdri', 'audio', 'lut', 'splat', 'blend', 'image']),
164
+ bytes: z.number().int().nonnegative(),
165
+ sha256: z.string().regex(SHA),
166
+ origin: z.enum(['download', 'generated', 'made', 'creator', 'legacy']),
167
+ license: z.object({
168
+ /** 'CC0-1.0', 'CC-BY-4.0', 'LicenseRef-Own', ... */
169
+ spdx: z.string().min(1).max(64),
170
+ url: z.string().url().optional(),
171
+ /** Required for CC BY and CC BY-SA. */
172
+ credit: z.string().max(300).optional(),
173
+ /** The licence text as read that day: a licence page can change later. */
174
+ textSha256: z.string().regex(SHA).optional(),
175
+ checkedAt: z.string().regex(DAY),
176
+ /** CC BY-SA: the creator agreed in a choice card. */
177
+ confirmedByCreator: z.boolean().optional(),
178
+ }),
179
+ source: z
180
+ .object({
181
+ provider: z.string().max(40),
182
+ id: z.string().max(200).optional(),
183
+ url: z.string().url().optional(),
184
+ author: z.string().max(120).optional(),
185
+ title: z.string().max(200).optional(),
186
+ host: z.string().max(200).optional(),
187
+ fetchedAt: z.string().optional(),
188
+ })
189
+ .optional(),
190
+ generation: z
191
+ .object({ vendor: z.string(), model: z.string(), prompt: z.string().max(2000), job: z.string(), usd: z.number().min(0) })
192
+ .optional(),
193
+ /** Other ledger paths: the blender/ inputs a GLB was baked from. */
194
+ derivedFrom: z.array(z.string()).max(64).optional(),
195
+ steps: z.array(z.object({ op: z.string().max(40), at: z.string(), detail: z.string().max(400) })).max(50).default([]),
196
+ publish: z.boolean().default(true),
197
+ /** model: { triangles, size_m, class }; hdri: { top, bottom }; splat:
198
+ * { count, shDegree, bounds_m, collider, frame }. */
199
+ meta: z.record(z.string(), z.unknown()).optional(),
200
+ });
201
+ export const AssetLock = z.object({ schema: z.literal('nowhere/assets@1'), files: z.record(z.string(), AssetEntry) });
202
+ export const LICENSE_POLICY = {
203
+ allowed: ['CC0-1.0', 'LicenseRef-PD', 'LicenseRef-Own', 'LicenseRef-Creator-Declared', 'LicenseRef-Generated-Owned', 'LicenseRef-QAL-1.0'],
204
+ /** Need license.credit; publishing them needs CREDITS_SHOWN. */
205
+ credit: ['CC-BY-4.0', 'CC-BY-3.0'],
206
+ /** Need confirmedByCreator and a credit. */
207
+ ask: ['CC-BY-SA-4.0', 'CC-BY-SA-3.0'],
208
+ refused: /(^|-)(NC|ND)(-|$)|Editorial|Unknown|NoAI/i,
209
+ };
210
+ const listed = (list, spdx) => list.includes(spdx);
211
+ /** Whether a file under this licence may be used in a planet, and whether it
212
+ * needs a visible credit. The codes are the LedgerFinding codes publishing
213
+ * reports. */
214
+ export function licenseVerdict(license) {
215
+ const spdx = String(license?.spdx ?? '').trim();
216
+ if (!spdx)
217
+ return { ok: false, code: 'ledger:license', reason: 'it has no licence recorded' };
218
+ if (LICENSE_POLICY.refused.test(spdx)) {
219
+ const why = /(^|-)NC(-|$)/i.test(spdx)
220
+ ? 'non-commercial licences are refused, since a planet is published to everyone'
221
+ : /(^|-)ND(-|$)/i.test(spdx)
222
+ ? 'no-derivatives licences are refused: reducing, retexturing or kitbashing a model is a derivative'
223
+ : /Editorial/i.test(spdx)
224
+ ? 'editorial-only licences are refused'
225
+ : /NoAI/i.test(spdx)
226
+ ? 'its author forbids its use with AI tools'
227
+ : 'its licence is unknown';
228
+ return { ok: false, code: 'ledger:license', reason: `${spdx}: ${why}` };
229
+ }
230
+ if (listed(LICENSE_POLICY.allowed, spdx))
231
+ return { ok: true, credit: false };
232
+ const credit = typeof license.credit === 'string' && license.credit.trim().length > 0;
233
+ if (listed(LICENSE_POLICY.credit, spdx)) {
234
+ if (!credit)
235
+ return { ok: false, code: 'ledger:credit', reason: `${spdx} needs a credit line (title, author, source), and none is recorded` };
236
+ return { ok: true, credit: true };
237
+ }
238
+ if (listed(LICENSE_POLICY.ask, spdx)) {
239
+ if (!credit)
240
+ return { ok: false, code: 'ledger:credit', reason: `${spdx} needs a credit line (title, author, source), and none is recorded` };
241
+ if (license.confirmedByCreator !== true) {
242
+ return { ok: false, code: 'ledger:sa-unconfirmed', reason: `${spdx} puts the same licence on what is built from it, so the creator has to agree first` };
243
+ }
244
+ return { ok: true, credit: true };
245
+ }
246
+ return { ok: false, code: 'ledger:license', reason: `${spdx} is not a licence the studio knows how to publish` };
247
+ }
248
+ /** The files the config needs beside the bundle: an HDRI sky's asset and a
249
+ * LUT. Read by plain property access (config.sky.asset when sky.kind is
250
+ * 'hdri'; config.look?.grade?.lut?.asset), so it works on any version of the
251
+ * config schema, and on an unvalidated document. */
252
+ export function collectConfigAssets(config) {
253
+ const out = [];
254
+ const c = config;
255
+ const sky = c?.sky;
256
+ if (sky && sky.kind === 'hdri' && typeof sky.asset === 'string')
257
+ out.push(sky.asset);
258
+ const lut = c?.look?.grade?.lut;
259
+ if (lut && typeof lut === 'object' && typeof lut.asset === 'string' && !out.includes(lut.asset))
260
+ out.push(lut.asset);
261
+ const items = config?.items;
262
+ if (Array.isArray(items)) {
263
+ for (const item of items) {
264
+ const icon = item?.icon;
265
+ if (typeof icon === 'string' && !out.includes(icon))
266
+ out.push(icon);
267
+ }
268
+ }
269
+ return out;
270
+ }
271
+ /** One sentence per file that may not travel. uploads: every file under
272
+ * assets/ about to go up. sha256 is checked when given (the studio gives it;
273
+ * the Edge Function checks bytes only). */
274
+ export function checkLedger(lock, uploads, opts = {}) {
275
+ const creditsShown = opts.creditsShown ?? CREDITS_SHOWN;
276
+ const findings = [];
277
+ const files = lock?.files ?? {};
278
+ for (const upload of uploads) {
279
+ const path = upload.path;
280
+ const entry = Object.prototype.hasOwnProperty.call(files, path) ? files[path] : undefined;
281
+ const say = (code, message) => findings.push({ code, path, message });
282
+ if (!entry) {
283
+ say('ledger:missing', `${path} is not in ${LEDGER_FILE}, so nothing records where it came from or its licence. Bring files in with asset_import (or build them with nw_blender), which records both.`);
284
+ continue;
285
+ }
286
+ const kind = assetKindOf(path);
287
+ if (!kind || entry.kind !== kind) {
288
+ say('ledger:kind', `${path} is recorded as a ${entry.kind} file, but its name says ${kind ? `a ${kind}` : 'nothing a planet carries'}.`);
289
+ continue;
290
+ }
291
+ if (entry.publish === false) {
292
+ say('ledger:not-published', `${path} is marked in ${LEDGER_FILE} as staying on this machine, so it cannot be published.`);
293
+ continue;
294
+ }
295
+ if (entry.bytes !== upload.bytes) {
296
+ say('ledger:bytes', `${path} has changed since it was recorded (${upload.bytes} bytes now, ${entry.bytes} recorded). Import it again with asset_import (replace: true) so the ledger matches.`);
297
+ continue;
298
+ }
299
+ if (upload.sha256 !== undefined && upload.sha256 !== entry.sha256) {
300
+ say('ledger:sha', `${path} has changed since it was recorded (its contents differ). Import it again with asset_import (replace: true) so the ledger matches.`);
301
+ continue;
302
+ }
303
+ const verdict = licenseVerdict(entry.license);
304
+ if (!verdict.ok) {
305
+ say(verdict.code, `${path} cannot be published: ${verdict.reason}.`);
306
+ continue;
307
+ }
308
+ if (verdict.credit && !creditsShown) {
309
+ say('ledger:credits-hidden', `${path} is ${entry.license.spdx}, which needs a credit visitors can see, and planets cannot show credits yet. Use a CC0 file instead, or keep it in the studio for now.`);
310
+ }
311
+ }
312
+ return findings;
313
+ }
314
+ /** The view of the ledger that goes to the server. */
315
+ export const PublishLock = z.object({
316
+ schema: z.literal('nowhere/assets-publish@1'),
317
+ files: z
318
+ .record(z.string().max(400), z.object({
319
+ kind: z.string().max(16),
320
+ bytes: z.number().int().nonnegative(),
321
+ sha256: z.string().regex(SHA),
322
+ origin: z.string().max(16),
323
+ license: z.object({
324
+ spdx: z.string().min(1).max(64),
325
+ credit: z.string().max(300).optional(),
326
+ confirmedByCreator: z.boolean().optional(),
327
+ }),
328
+ }))
329
+ .refine((files) => Object.keys(files).length <= 400, 'at most 400 files'),
330
+ });
331
+ /** What goes to the server: per published file its kind, size, hash, origin
332
+ * and licence. Prompts, costs, steps and sources stay on the creator's
333
+ * machine. */
334
+ export function publishLock(lock) {
335
+ const files = {};
336
+ for (const [path, entry] of Object.entries(lock?.files ?? {})) {
337
+ if (!isPublishablePath(path) || entry.publish === false)
338
+ continue;
339
+ files[path] = {
340
+ kind: entry.kind,
341
+ bytes: entry.bytes,
342
+ sha256: entry.sha256,
343
+ origin: entry.origin,
344
+ license: {
345
+ spdx: entry.license.spdx,
346
+ ...(entry.license.credit ? { credit: entry.license.credit } : {}),
347
+ ...(entry.license.confirmedByCreator ? { confirmedByCreator: true } : {}),
348
+ },
349
+ };
350
+ }
351
+ return { schema: 'nowhere/assets-publish@1', files };
352
+ }
353
+ /** The publish view as the server receives it, or why it is refused. */
354
+ export function parsePublishLock(raw) {
355
+ const parsed = PublishLock.safeParse(raw);
356
+ if (parsed.success)
357
+ return { ok: true, lock: parsed.data };
358
+ const first = parsed.error.issues[0];
359
+ return { ok: false, error: `${first?.path.join('.') || 'assets.lock.json'}: ${first?.message ?? 'not valid'}` };
360
+ }
361
+ const SOURCE_NAMES = { polyhaven: 'Poly Haven', ambientcg: 'ambientCG', polypizza: 'Poly Pizza' };
362
+ /** The credit line a file shows: its recorded credit, or one made from its
363
+ * title, author and source (a courtesy for CC0, which asks for none). */
364
+ function creditLine(entry) {
365
+ if (entry.license.credit?.trim())
366
+ return entry.license.credit.trim();
367
+ const s = entry.source;
368
+ const title = s?.title ? `"${s.title}"` : null;
369
+ const by = s?.author ? `by ${s.author}` : null;
370
+ const where = s?.provider ? (SOURCE_NAMES[s.provider] ?? s.provider) : null;
371
+ const parts = [title, by, where ? `(${where})` : null].filter(Boolean);
372
+ return parts.length ? `${parts.join(' ')}, ${entry.license.spdx}` : entry.license.spdx;
373
+ }
374
+ /** The credits of a ledger: the section CREDITS.md carries, and the lines a
375
+ * planet's manifest lists for visitors (every published file under assets/,
376
+ * with a courtesy line where its licence asks for none). */
377
+ export function creditsFor(lock) {
378
+ const all = Object.entries(lock?.files ?? {}).sort(([a], [b]) => a.localeCompare(b));
379
+ const entries = all
380
+ .filter(([path, entry]) => isPublishablePath(path) && entry.publish !== false)
381
+ .map(([path, entry]) => ({
382
+ path,
383
+ ...(entry.source?.title ? { title: entry.source.title } : {}),
384
+ ...(entry.source?.author ? { author: entry.source.author } : {}),
385
+ license: entry.license.spdx,
386
+ ...(entry.source?.url ? { url: entry.source.url } : {}),
387
+ credit: creditLine(entry),
388
+ }));
389
+ const line = ([path, entry]) => {
390
+ const s = entry.source;
391
+ const bits = [creditLine(entry)];
392
+ if (s?.url && !bits[0].includes(s.url))
393
+ bits.push(s.url);
394
+ if (entry.generation)
395
+ bits.push(`generated with ${entry.generation.vendor} ${entry.generation.model}`);
396
+ if (entry.derivedFrom?.length)
397
+ bits.push(`made from ${entry.derivedFrom.join(', ')}`);
398
+ const day = (s?.fetchedAt ?? entry.license.checkedAt).slice(0, 10);
399
+ bits.push(`${entry.origin === 'download' ? 'downloaded' : 'recorded'} ${day}`);
400
+ return `- \`${path}\`: ${bits.join(', ')}`;
401
+ };
402
+ const game = all.filter(([path]) => path.startsWith('assets/'));
403
+ const inputs = all.filter(([path]) => !path.startsWith('assets/'));
404
+ const parts = ['## Assets', '', ...(game.length ? game.map(line) : ['- none yet'])];
405
+ if (inputs.length)
406
+ parts.push('', '## Blender inputs (not published)', '', ...inputs.map(line));
407
+ return { markdown: parts.join('\n'), entries };
408
+ }
409
+ const MB = 1024 * 1024;
410
+ const mb = (bytes) => (bytes / MB).toFixed(1);
411
+ /** Every size rule on the files a version carries beside its code: each file
412
+ * against its kind's ceiling, the sounds together against AUDIO_TOTAL_MB and
413
+ * everything against ASSETS_TOTAL_MB. Empty when they all fit. */
414
+ export function assetSizeProblems(files) {
415
+ const out = [];
416
+ let total = 0;
417
+ let audio = 0;
418
+ for (const f of files) {
419
+ total += f.bytes;
420
+ const kind = assetKindOf(f.path);
421
+ if (!kind) {
422
+ out.push({ code: 'budget:kind', path: f.path, message: `${f.path} is not a kind of file a planet carries.` });
423
+ continue;
424
+ }
425
+ if (kind === 'audio')
426
+ audio += f.bytes;
427
+ const ceiling = ASSET_KINDS[kind].fileMb;
428
+ if (f.bytes > ceiling * MB) {
429
+ out.push({ code: 'budget:file', path: f.path, message: `${f.path} is ${mb(f.bytes)} MB; one ${kind} file can be at most ${ceiling} MB.` });
430
+ }
431
+ }
432
+ if (audio > AUDIO_TOTAL_MB * MB) {
433
+ out.push({ code: 'budget:audio', message: `The sounds come to ${mb(audio)} MB; a planet carries at most ${AUDIO_TOTAL_MB} MB of sound.` });
434
+ }
435
+ if (total > ASSETS_TOTAL_MB * MB) {
436
+ out.push({ code: 'budget:total', message: `The files come to ${mb(total)} MB; a planet carries ${ASSETS_TOTAL_MB} MB.` });
437
+ }
438
+ return out;
439
+ }