@tora-editor/tora 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +107 -58
- package/assets/free-audio/arcade-pop/audio/loss.wav +0 -0
- package/assets/free-audio/arcade-pop/audio/reward.wav +0 -0
- package/assets/free-audio/arcade-pop/audio/win.wav +0 -0
- package/assets/free-audio/arcade-pop/source/INFO.txt +11 -11
- package/assets/kenney-food-starter/License.txt +28 -0
- package/assets/kenney-food-starter/burger.glb +0 -0
- package/assets/kenney-food-starter/frying-pan.glb +0 -0
- package/assets/kenney-food-starter/plan.json +61 -0
- package/assets/kenney-food-starter/plate.glb +0 -0
- package/assets/kenney-food-starter/pot.glb +0 -0
- package/assets/kenney-harvest/audio/victory.wav +0 -0
- package/assets/kenney-harvest/source/music-jingles/OGG/jingles_NES/jingles_NES03.ogg +0 -0
- package/assets/kenney-harvest/source/music-jingles/OGG/jingles_PIZZA/jingles_PIZZA03.ogg +0 -0
- package/assets/kenney-harvest/source/music-jingles/license.txt +14 -0
- package/bin/tora.mjs +322 -28
- package/crates/packer/trusted/native-3d-meta.json +4 -3
- package/crates/packer/trusted/native-3d.js +181 -181
- package/crates/packer/trusted/native-meta.json +3 -3
- package/crates/packer/trusted/native.js +5 -5
- package/crates/packer/trusted/release-manifest.json +17 -17
- package/crates/packer/trusted/review-runtime-meta.json +4 -3
- package/crates/packer/trusted/review-runtime.js +182 -182
- package/docs/MIGRATION_0_3.md +39 -0
- package/docs/NATIVE_AGENT_TOOLS.md +12 -363
- package/docs/TORA_AGENT_SETUP.md +24 -95
- package/docs/TORA_CREATION_API.md +63 -348
- package/docs/reference/CORE_AUTHORING.md +10 -3
- package/docs/reference/PLAYABLE_STARTERS.md +20 -0
- package/docs/reference/packs/3d.md +11 -3
- package/network-rules/mintegral-appgrowth-single-html.json +10 -10
- package/package.json +6 -6
- package/packages/creative-project/project-v21.schema.json +372 -9
- package/scripts/lean/editor/entry.js +11 -6
- package/scripts/lean/editor/project-launcher.js +116 -0
- package/scripts/lean/editor/quick-edit-panel.js +479 -0
- package/scripts/lean/editor/review-editor.css +256 -68
- package/scripts/lean/editor/review-editor.js +1834 -1086
- package/scripts/lean/editor-state.mjs +6 -0
- package/scripts/lean/editor.mjs +6 -3
- package/scripts/lean/matrix.mjs +5 -0
- package/scripts/lean/native/agent-tools.mjs +39 -62
- package/scripts/lean/native/api.mjs +161 -136
- package/scripts/lean/native/asset-catalog.mjs +7 -6
- package/scripts/lean/native/asset-lineage.mjs +54 -0
- package/scripts/lean/native/asset-prep.mjs +173 -40
- package/scripts/lean/native/assets.mjs +107 -11
- package/scripts/lean/native/audio-assets.mjs +30 -0
- package/scripts/lean/native/browser-pool.mjs +34 -0
- package/scripts/lean/native/build-cache.mjs +38 -7
- package/scripts/lean/native/cc0-inputs.mjs +24 -0
- package/scripts/lean/native/cc0-staging.mjs +28 -8
- package/scripts/lean/native/compiler.mjs +9 -3
- package/scripts/lean/native/contracts.mjs +16 -11
- package/scripts/lean/native/creative-qa.mjs +365 -128
- package/scripts/lean/native/demos.mjs +53 -18
- package/scripts/lean/native/document.mjs +50 -12
- package/scripts/lean/native/export-budget.mjs +75 -0
- package/scripts/lean/native/local-bundle.mjs +7 -3
- package/scripts/lean/native/mcp-server.mjs +42 -74
- package/scripts/lean/native/media-validate.mjs +124 -0
- package/scripts/lean/native/modules/harvest-restore.mjs +3 -284
- package/scripts/lean/native/modules/sort-puzzle.mjs +51 -0
- package/scripts/lean/native/modules/star-salvage.mjs +3 -368
- package/scripts/lean/native/native-bin.mjs +3 -3
- package/scripts/lean/native/outcome-playthrough.mjs +97 -0
- package/scripts/lean/native/project-bundle.mjs +6 -5
- package/scripts/lean/native/project-index.mjs +0 -2
- package/scripts/lean/native/qa-adapters.mjs +10 -0
- package/scripts/lean/native/quick-edit.mjs +328 -0
- package/scripts/lean/native/remote-cc0-fetcher.mjs +403 -197
- package/scripts/lean/native/review.mjs +205 -571
- package/scripts/lean/native/schema-vocabulary.mjs +10 -0
- package/scripts/lean/native/schema.mjs +7 -5
- package/scripts/lean/native/scope.mjs +45 -0
- package/scripts/lean/native/service.mjs +378 -79
- package/scripts/lean/native/starters.mjs +563 -0
- package/scripts/lean/native/variant-adapters.mjs +8 -0
- package/scripts/lean/native/variants-core.mjs +186 -0
- package/scripts/lean/native/variants.mjs +63 -0
- package/scripts/lean/native/win-cues.mjs +96 -0
- package/skills/tora-playables/SKILL.md +1 -1
- package/scripts/lean/editor/review-intake.js +0 -837
- package/scripts/lean/model-client.mjs +0 -119
- package/scripts/lean/native/author-expansion-proofs.mjs +0 -240
- package/scripts/lean/native/author-games.mjs +0 -160
- package/scripts/lean/native/author-harvest.mjs +0 -74
- package/scripts/lean/native/author-primitive-proofs.mjs +0 -874
- package/scripts/lean/native/author-salvage.mjs +0 -71
- package/scripts/lean/native/chat-compose.mjs +0 -287
- package/scripts/lean/native/check-harvest-outcome-audio.mjs +0 -191
- package/scripts/lean/native/check-salvage.mjs +0 -197
- package/scripts/lean/native/compatibility.mjs +0 -34
- package/scripts/lean/native/concept.mjs +0 -633
- package/scripts/lean/native/draw-stroke.mjs +0 -26
- package/scripts/lean/native/erase-mask.mjs +0 -18
- package/scripts/lean/native/harvest-recipe.mjs +0 -21
- package/scripts/lean/native/instance-steering.mjs +0 -24
- package/scripts/lean/native/intake-creator-agent.mjs +0 -98
- package/scripts/lean/native/intake-creator-tools.mjs +0 -165
- package/scripts/lean/native/interaction-gestures.mjs +0 -45
- package/scripts/lean/native/match-board.mjs +0 -138
- package/scripts/lean/native/modules/index.mjs +0 -54
- package/scripts/lean/native/modules/tap-collect.mjs +0 -54
- package/scripts/lean/native/path-network.mjs +0 -132
- package/scripts/lean/native/physics-2d.mjs +0 -154
- package/scripts/lean/native/physics-3d.mjs +0 -259
- package/scripts/lean/native/prepare-audio-collections.mjs +0 -112
- package/scripts/lean/native/prepare-game-audio.mjs +0 -372
- package/scripts/lean/native/prepare-golf-3d-assets.py +0 -177
- package/scripts/lean/native/prepare-golf-assets.py +0 -211
- package/scripts/lean/native/prepare-harvest-audio.mjs +0 -83
- package/scripts/lean/native/prepare-harvest-images.mjs +0 -31
- package/scripts/lean/native/prepare-primitive-images.py +0 -25
- package/scripts/lean/native/prepare-space-salvage-images.mjs +0 -89
- package/scripts/lean/native/prepare-traffic-assets.py +0 -329
- package/scripts/lean/native/presentation.mjs +0 -335
- package/scripts/lean/native/review-agent-tools.mjs +0 -561
- package/scripts/lean/native/review-connection.mjs +0 -303
- package/scripts/lean/native/review-fields.mjs +0 -24
- package/scripts/lean/native/review-intake.mjs +0 -385
- package/scripts/lean/native/review-intents.mjs +0 -217
- package/scripts/lean/native/review-provider.mjs +0 -580
- package/scripts/lean/native/review-receipts.mjs +0 -76
- package/scripts/lean/native/review-resolver.mjs +0 -429
- package/scripts/lean/native/review-targets.mjs +0 -35
- package/scripts/lean/native/runtime.mjs +0 -1623
- package/scripts/lean/native/salvage-recipe.mjs +0 -20
- package/scripts/lean/native/stage-3d.mjs +0 -818
- package/scripts/lean/native/verify.mjs +0 -4
- package/scripts/lean/scene-document.mjs +0 -48
|
@@ -1,105 +1,108 @@
|
|
|
1
|
-
import process from 'node:process';
|
|
2
1
|
import {Buffer} from 'node:buffer';
|
|
2
|
+
import {readFile,stat} from 'node:fs/promises';
|
|
3
3
|
import {parseAuthoringJson} from '../../../packages/creative-project/src/strict-json.mjs';
|
|
4
4
|
import {capabilities,capabilitiesForPacks,capabilitySummary,compactCapabilities,limits} from './contracts.mjs';
|
|
5
5
|
import {buildInspectTree,NativeAgentTools} from './agent-tools.mjs';
|
|
6
6
|
import {check,exact} from './document.mjs';
|
|
7
7
|
import {NativeReview} from './review.mjs';
|
|
8
|
-
import {ReviewConnection} from './review-connection.mjs';
|
|
9
|
-
import {configuredReviewAgent,configuredReviewInterpreter,reviewRoutingFlags} from './review-resolver.mjs';
|
|
10
|
-
import {reviewProviderConfig} from './review-provider.mjs';
|
|
11
|
-
import {ReviewIntake} from './review-intake.mjs';
|
|
12
8
|
import {reviewRuntimeBundle} from './compiler.mjs';
|
|
13
|
-
import {composeFromFreePack,freePackPreview,listFreePacks} from './chat-compose.mjs';
|
|
14
9
|
import {listDemosWithStatus,materializeDemo} from './demos.mjs';
|
|
15
10
|
import {AssetCatalog} from './asset-catalog.mjs';
|
|
16
11
|
import {RemoteCc0Fetcher} from './remote-cc0-fetcher.mjs';
|
|
17
12
|
import {stageVerifiedCc0Assets} from './cc0-staging.mjs';
|
|
13
|
+
import {fetchCc0Properties} from './cc0-inputs.mjs';
|
|
18
14
|
import {prepAssets} from './asset-prep.mjs';
|
|
19
15
|
import {PACKAGE_ROOT} from '../runtime-paths.mjs';
|
|
16
|
+
import {projectWinCueTrack,replaceProjectWinCue,winCuePreview} from './win-cues.mjs';
|
|
17
|
+
import {composeStarter,listStarters} from './starters.mjs';
|
|
18
|
+
import {importProjectFile} from './local-bundle.mjs';
|
|
19
|
+
import {BUNDLE_LIMIT} from './project-bundle.mjs';
|
|
20
|
+
import {buildQuickEditOperations,summarizeQuickEdit} from './quick-edit.mjs';
|
|
21
|
+
import {lowerAssets} from './assets.mjs';
|
|
22
|
+
import {assertStorePath} from './store-path.mjs';
|
|
23
|
+
import {randomUUID} from 'node:crypto';
|
|
24
|
+
import {relative,resolve,sep} from 'node:path';
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
E_MODEL_QUOTA:402,E_MODEL_UNAVAILABLE:422,E_MODEL_UNSUPPORTED_CAPABILITY:422,
|
|
24
|
-
E_MODEL_RATE_LIMIT:429,E_MODEL_TIMEOUT:504,E_MODEL_TRANSPORT:502,
|
|
25
|
-
E_MODEL_UPSTREAM:502,E_MODEL_REQUEST:502,
|
|
26
|
-
};
|
|
27
|
-
export function nativeApi(service,connection=new ReviewConnection(service.store.root),{agentFactory,catalog,remoteFetcher}={}){
|
|
28
|
-
const intakes=new ReviewIntake(service,{connection,agentFactory});
|
|
26
|
+
export function nativeApi(service,{catalog,remoteFetcher}={}){
|
|
27
|
+
const review=new NativeReview(service);
|
|
29
28
|
const assetCatalog=catalog??new AssetCatalog({root:PACKAGE_ROOT});
|
|
30
29
|
const cc0Fetcher=remoteFetcher??new RemoteCc0Fetcher({workspaceRoot:service.store.workspaceRoot,catalog:assetCatalog});
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
providerLabel:config.provider,
|
|
39
|
-
model:config.model,
|
|
40
|
-
modelLabel:config.model,
|
|
41
|
-
vision:Boolean(config.vision),
|
|
42
|
-
verified:config.provider!=='orca'&&config.provider!=='openai-compatible',
|
|
43
|
-
}:undefined,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
const active=await connection.read();
|
|
47
|
-
if(!active)return {config:undefined,info:undefined};
|
|
48
|
-
const config=reviewProviderConfig({
|
|
49
|
-
provider:active.provider,
|
|
50
|
-
model:active.model,
|
|
51
|
-
endpoint:active.endpoint,
|
|
52
|
-
apiKey:active.apiKey,
|
|
53
|
-
vision:active.vision,
|
|
54
|
-
});
|
|
55
|
-
return {
|
|
56
|
-
config,
|
|
57
|
-
info:{
|
|
58
|
-
provider:active.provider,
|
|
59
|
-
providerLabel:active.providerLabel,
|
|
60
|
-
model:active.model,
|
|
61
|
-
modelLabel:active.modelLabel,
|
|
62
|
-
capabilities:active.capabilities,
|
|
63
|
-
audioSummary:active.audioSummary,
|
|
64
|
-
videoSummary:active.videoSummary,
|
|
65
|
-
verified:Boolean(active.verified),
|
|
66
|
-
legacy:Boolean(active.legacy),
|
|
67
|
-
},
|
|
68
|
-
};
|
|
30
|
+
const matrixJobs=new Map();
|
|
31
|
+
const availableTemplates=async()=>{
|
|
32
|
+
const starterInfo=listStarters();
|
|
33
|
+
return {starters:starterInfo.starters,defaults:starterInfo.defaults,templates:starterInfo.starters.map(item=>({
|
|
34
|
+
id:item.id,kind:'starter',name:item.name,genre:item.genre,description:item.tagline,
|
|
35
|
+
mechanic:item.mechanic,previews:[],defaults:starterInfo.defaults,
|
|
36
|
+
}))};
|
|
69
37
|
};
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
38
|
+
const uniqueSlug=async(raw,fallback)=>{
|
|
39
|
+
const base=String(raw??'').toLowerCase().replace(/[^a-z0-9]+/g,'-').replace(/^[^a-z]+/,'').replace(/-+$/,'').slice(0,38);
|
|
40
|
+
const slug=base.length>=2&&base!=='compose'?base:fallback;
|
|
41
|
+
const existing=new Set((await service.store.list()).map(p=>p.id));
|
|
42
|
+
if(!existing.has(slug))return slug;
|
|
43
|
+
for(let n=2;n<999;n++){
|
|
44
|
+
const suffix='-'+n;
|
|
45
|
+
const candidate=slug.slice(0,48-suffix.length)+suffix;
|
|
46
|
+
if(!existing.has(candidate))return candidate;
|
|
47
|
+
}
|
|
48
|
+
throw Error('E_PROJECT_EXISTS');
|
|
79
49
|
};
|
|
80
50
|
return async(req,res,url,port)=>{
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
const
|
|
51
|
+
if(['/api/projects/from-chat','/api/projects/compose'].includes(url.pathname))return false;
|
|
52
|
+
const match=/^\/api\/projects\/([a-z][a-z0-9-]{1,47})(?:\/(transactions\/preview|transactions|history|accept|export|render|review|win-cue|stage-cc0|budget|variants|export-matrix|quick-edit|qa-asset|qa|assets(?:\/[a-z][a-z0-9_.-]{0,95}(?:\/raw)?)?))?$/.exec(url.pathname);
|
|
53
|
+
const matrixJob=/^\/api\/projects\/([a-z][a-z0-9-]{1,47})\/export-matrix\/([a-f0-9-]{36})$/.exec(url.pathname);
|
|
54
|
+
const winCueMatch=/^\/api\/catalog\/win-cues\/([a-z0-9-]+)$/.exec(url.pathname);
|
|
55
|
+
const startersRoute=url.pathname==='/api/starters';
|
|
56
|
+
const startersComposeRoute=url.pathname==='/api/starters/compose';
|
|
57
|
+
const importProjectRoute=url.pathname==='/api/projects/import';
|
|
86
58
|
const assetsCatalogRoute=url.pathname==='/api/assets/catalog';
|
|
87
59
|
const assetsFetchRoute=url.pathname==='/api/assets/fetch-cc0';
|
|
88
60
|
const assetsPrepRoute=url.pathname==='/api/assets/prep';
|
|
89
|
-
const fromChatRoute=url.pathname==='/api/projects/from-chat';
|
|
90
61
|
const demosRoute=url.pathname==='/api/demos';
|
|
91
62
|
const demosOpenRoute=url.pathname==='/api/demos/open';
|
|
92
|
-
const top=
|
|
93
|
-
if(!match&&!
|
|
63
|
+
const top=startersRoute||startersComposeRoute||importProjectRoute||assetsCatalogRoute||assetsFetchRoute||assetsPrepRoute||demosRoute||demosOpenRoute||['/api/open','/api/creation/capabilities','/api/projects'].includes(url.pathname);
|
|
64
|
+
if(!match&&!matrixJob&&!winCueMatch&&!top&&url.pathname!=='/review-runtime.js')return false;
|
|
94
65
|
const json=(status,value)=>{res.writeHead(status,{'Content-Type':'application/json'});res.end(JSON.stringify(value));};
|
|
95
66
|
try{check(req.headers.host==='127.0.0.1:'+port,'E_NATIVE_ORIGIN');
|
|
96
67
|
if(url.pathname==='/review-runtime.js'){
|
|
97
68
|
check(req.method==='GET','E_NATIVE_METHOD');
|
|
98
69
|
res.setHeader('Content-Type','text/javascript');res.end(await reviewRuntimeBundle());return true;
|
|
99
70
|
}
|
|
100
|
-
if(
|
|
71
|
+
if(winCueMatch||(match?.[2]==='win-cue'&&req.method==='GET')){
|
|
72
|
+
check(req.method==='GET','E_NATIVE_METHOD');
|
|
73
|
+
const asset=winCueMatch?await winCuePreview(winCueMatch[1]):await projectWinCueTrack(service,match[1],url.searchParams.get('track'));
|
|
74
|
+
res.writeHead(200,{'Content-Type':asset.mime,'X-Content-Type-Options':'nosniff'});res.end(asset.bytes);
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
if(startersRoute){
|
|
101
78
|
check(req.method==='GET','E_NATIVE_METHOD');
|
|
102
|
-
json(200,await
|
|
79
|
+
json(200,await availableTemplates());return true;
|
|
80
|
+
}
|
|
81
|
+
if(match?.[2]==='qa-asset'&&req.method==='GET'){
|
|
82
|
+
const rel=url.searchParams.get('file');
|
|
83
|
+
check(typeof rel==='string'&&rel.length>0&&rel.length<=260&&!rel.includes('\0')&&!rel.startsWith('/')&&!rel.includes('..')&&!rel.includes('\\')&&!rel.split('/').some(seg=>!seg||seg.startsWith('.'))&&/\.(?:png|jpg|jpeg|webp)$/i.test(rel),'E_NATIVE_ARGUMENT');
|
|
84
|
+
const qaRoot=resolve(service.store.root,match[1],'qa');
|
|
85
|
+
const target=resolve(qaRoot,rel);
|
|
86
|
+
check(target.startsWith(qaRoot+sep),'E_NATIVE_NOT_FOUND');
|
|
87
|
+
await assertStorePath(target);
|
|
88
|
+
const info=await stat(target);
|
|
89
|
+
check(info.isFile(),'E_NATIVE_NOT_FOUND');
|
|
90
|
+
const bytes=await readFile(target);
|
|
91
|
+
const ext=rel.toLowerCase().split('.').pop();
|
|
92
|
+
const mime=ext==='png'?'image/png':ext==='webp'?'image/webp':'image/jpeg';
|
|
93
|
+
res.writeHead(200,{'Content-Type':mime,'X-Content-Type-Options':'nosniff'});res.end(bytes);
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
const rawAssetMatch=match?.[2]&&req.method==='GET'?/^assets\/([a-z][a-z0-9_.-]{0,95})\/raw$/.exec(match[2]):null;
|
|
97
|
+
if(rawAssetMatch){
|
|
98
|
+
const assetId=rawAssetMatch[1];
|
|
99
|
+
const current=await service.read(match[1]);
|
|
100
|
+
const asset=current.project.assets.find(item=>item.id===assetId);
|
|
101
|
+
check(asset,'E_NATIVE_NOT_FOUND');
|
|
102
|
+
const [lowered]=await lowerAssets(resolve(service.store.root,match[1]),[asset]);
|
|
103
|
+
res.writeHead(200,{'Content-Type':asset.mime,'X-Content-Type-Options':'nosniff'});
|
|
104
|
+
res.end(Buffer.from(lowered.data,'base64'));
|
|
105
|
+
return true;
|
|
103
106
|
}
|
|
104
107
|
if(assetsCatalogRoute){
|
|
105
108
|
check(req.method==='GET','E_NATIVE_METHOD');
|
|
@@ -120,61 +123,38 @@ export function nativeApi(service,connection=new ReviewConnection(service.store.
|
|
|
120
123
|
check(req.method==='GET','E_NATIVE_METHOD');
|
|
121
124
|
json(200,{demos:await listDemosWithStatus(service)});return true;
|
|
122
125
|
}
|
|
123
|
-
if(previewMatch){
|
|
124
|
-
check(req.method==='GET','E_NATIVE_METHOD');
|
|
125
|
-
const file=await freePackPreview(previewMatch[1]);
|
|
126
|
-
res.writeHead(200,{'Content-Type':file.mime,'X-Content-Type-Options':'nosniff','Cache-Control':'public, max-age=3600'});
|
|
127
|
-
res.end(file.bytes);return true;
|
|
128
|
-
}
|
|
129
|
-
if(connectionRoute&&req.method==='GET'){
|
|
130
|
-
json(200,await connection.status());return true;
|
|
131
|
-
}
|
|
132
|
-
if(intake&&req.method==='GET'){
|
|
133
|
-
const [,id,route,assetId]=intake;
|
|
134
|
-
if((route==='assets'||route==='references')&&assetId){
|
|
135
|
-
const asset=route==='references'?await intakes.referenceAsset(id,assetId):await intakes.asset(id,assetId);
|
|
136
|
-
res.writeHead(200,{'Content-Type':asset.mime,'X-Content-Type-Options':'nosniff'});res.end(asset.bytes);
|
|
137
|
-
}else{
|
|
138
|
-
check(id&&!route,'E_NATIVE_METHOD');json(200,await intakes.read(id));
|
|
139
|
-
}
|
|
140
|
-
return true;
|
|
141
|
-
}
|
|
142
126
|
if(match?.[2]==='review'&&req.method==='GET'){
|
|
143
|
-
const review=await reviewForConnection();
|
|
144
127
|
const candidate=url.searchParams.get('candidate');
|
|
145
128
|
json(200,candidate?await review.candidate(match[1],candidate):url.searchParams.get('bundle')==='1'?await review.bundle(match[1]):await review.read(match[1]));
|
|
146
129
|
return true;
|
|
147
130
|
}
|
|
148
|
-
if(req.method==='GET'){if(url.pathname==='/api/open'){const id=url.searchParams.get('project'),opened=await service.store.open(id);if(opened.project.base.kind!=='native-scene')return false;const result=await service.read(id);json(200,{...result,projectId:id,inputKind:'native-scene-document'});return true;}if(url.pathname==='/api/creation/capabilities'){const summary=url.searchParams.get('summary'),format=url.searchParams.get('format'),packsParam=url.searchParams.get('packs'),namesParam=url.searchParams.get('names');if(summary==='1'||summary==='true'){json(200,capabilitySummary());return true;}check(format===null||format==='full'||format==='compact','E_NATIVE_ARGUMENT');const packs=packsParam?packsParam.split(',').filter(Boolean):undefined,names=namesParam?namesParam.split(',').filter(Boolean):undefined;if(format==='compact'){json(200,compactCapabilities({packs,names}));return true;}if(names){const tools=new NativeAgentTools(service);json(200,await tools.run({command:'contracts',packs,names}));return true;}json(200,packs?capabilitiesForPacks(packs):capabilities());return true;}else if(url.pathname==='/api/projects'){const projects=await service.store.list();for(const p of projects)if(p.kind==='native-scene'){const r=await service.read(p.id);p.workingRevision=r.revisionId;}json(200,{projects});}else if(match?.[2]==='render')json(200,await service.render(match[1],url.searchParams.get('revision')));else if(match?.[2]?.startsWith('assets/')){const r=await service.read(match[1]),asset=r.project.assets.find(a=>a.id===match[2].slice(7));check(asset,'E_NATIVE_NOT_FOUND');json(200,asset);}else if(match&&!match[2]){const current=await service.read(match[1],url.searchParams.get('revision')??undefined);const tree=url.searchParams.get('tree');json(200,tree==='1'||tree==='true'?buildInspectTree(match[1],current,url.searchParams.get('sceneId')??undefined):current);}else check(false,'E_NATIVE_METHOD');return true;}
|
|
149
|
-
check(req.method==='POST','E_NATIVE_METHOD');check(req.headers.origin==='http://127.0.0.1:'+port,'E_NATIVE_ORIGIN');check(req.headers['content-type']==='application/json','E_NATIVE_CONTENT_TYPE');req.setTimeout(
|
|
150
|
-
if(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
if(body.action==='models'){
|
|
157
|
-
check(exact(body,['action','provider','apiKey','endpoint','preset']),'E_NATIVE_ARGUMENT');
|
|
158
|
-
json(200,await connection.listModels({provider:body.provider,apiKey:body.apiKey,endpoint:body.endpoint,preset:body.preset}));
|
|
159
|
-
return true;
|
|
160
|
-
}
|
|
161
|
-
if(Object.hasOwn(body,'provider')||Object.hasOwn(body,'model')){
|
|
162
|
-
check(exact(body,['provider','model','apiKey','endpoint','preset','vision']),'E_NATIVE_ARGUMENT');
|
|
163
|
-
json(200,await connection.save({provider:body.provider,model:body.model,apiKey:body.apiKey,endpoint:body.endpoint,preset:body.preset,vision:body.vision}));
|
|
164
|
-
return true;
|
|
165
|
-
}
|
|
166
|
-
check(exact(body,['apiKey']),'E_NATIVE_ARGUMENT');
|
|
167
|
-
json(200,await connection.save(body.apiKey));
|
|
131
|
+
if(req.method==='GET'){if(url.pathname==='/api/open'){const id=url.searchParams.get('project'),opened=await service.store.open(id);if(opened.project.base.kind!=='native-scene')return false;const result=await service.read(id);json(200,{...result,projectId:id,inputKind:'native-scene-document'});return true;}if(url.pathname==='/api/creation/capabilities'){const summary=url.searchParams.get('summary'),format=url.searchParams.get('format'),packsParam=url.searchParams.get('packs'),namesParam=url.searchParams.get('names');if(summary==='1'||summary==='true'){json(200,capabilitySummary());return true;}check(format===null||format==='full'||format==='compact','E_NATIVE_ARGUMENT');const packs=packsParam?packsParam.split(',').filter(Boolean):undefined,names=namesParam?namesParam.split(',').filter(Boolean):undefined;if(format==='compact'){json(200,compactCapabilities({packs,names}));return true;}if(names){const tools=new NativeAgentTools(service);json(200,await tools.run({command:'contracts',packs,names}));return true;}json(200,packs?capabilitiesForPacks(packs):capabilities());return true;}else if(url.pathname==='/api/projects'){const projects=await service.store.list();for(const p of projects)if(p.kind==='native-scene'){const r=await service.read(p.id);p.workingRevision=r.revisionId;}json(200,{projects});}else if(matrixJob){const job=matrixJobs.get(matrixJob[2]);check(job&&job.projectId===matrixJob[1],'E_NATIVE_NOT_FOUND');json(200,job);return true;}else if(match?.[2]==='budget'){const target=url.searchParams.get('target')??'standalone-browser-draft',variantId=url.searchParams.get('variant')??undefined,fitTargetBudget=url.searchParams.get('fit')==='1'||url.searchParams.get('fit')==='true';json(200,await service.estimateBudget(match[1],{target,variantId,revisionId:url.searchParams.get('revision')??undefined,fitTargetBudget}));}else if(match?.[2]==='variants'){const variantId=url.searchParams.get('variant');json(200,variantId?await service.diffVariant(match[1],variantId,{revisionId:url.searchParams.get('revision')??undefined}):await service.listVariants(match[1]));}else if(match?.[2]==='render')json(200,await service.render(match[1],url.searchParams.get('revision')));else if(match?.[2]?.startsWith('assets/')){const r=await service.read(match[1]),asset=r.project.assets.find(a=>a.id===match[2].slice(7));check(asset,'E_NATIVE_NOT_FOUND');json(200,asset);}else if(match&&!match[2]){const current=await service.read(match[1],url.searchParams.get('revision')??undefined);const tree=url.searchParams.get('tree');json(200,tree==='1'||tree==='true'?buildInspectTree(match[1],current,url.searchParams.get('sceneId')??undefined):current);}else check(false,'E_NATIVE_METHOD');return true;}
|
|
132
|
+
check(req.method==='POST','E_NATIVE_METHOD');check(req.headers.origin==='http://127.0.0.1:'+port,'E_NATIVE_ORIGIN');check(req.headers['content-type']==='application/json','E_NATIVE_CONTENT_TYPE');req.setTimeout(15000,()=>req.destroy());let bytes=0;const chunks=[];const assetUpload=match?.[2]==='assets',maxBytes=importProjectRoute?BUNDLE_LIMIT+1024*1024:assetUpload?12*1024*1024:limits.transactionBytes;for await(const chunk of req){bytes+=chunk.length;check(bytes<=maxBytes,'E_NATIVE_SIZE');chunks.push(chunk);}req.setTimeout(0);const body=parseAuthoringJson(Buffer.concat(chunks).toString(),{bytes:maxBytes,nodes:limits.nodes,depth:limits.depth,allowNull:match?.[2]==='review'});
|
|
133
|
+
if(startersComposeRoute){
|
|
134
|
+
check(exact(body,['starter','id','name','ctaLabel','winTitle','timeoutTitle','durationSeconds','winHoldSeconds','palette','androidUrl'])&&typeof body.starter==='string','E_NATIVE_ARGUMENT');
|
|
135
|
+
const resolvedId=body.id?String(body.id):await uniqueSlug(body.name||body.starter,body.starter);
|
|
136
|
+
const composed=await composeStarter({...body,id:resolvedId,deliver:false},{service,catalog:assetCatalog,remoteFetcher:cc0Fetcher,workspaceRoot:service.store.workspaceRoot});
|
|
137
|
+
const read=await service.read(composed.projectId);
|
|
138
|
+
json(201,{...composed,name:read.project.creativeBrief?.goal??body.name??composed.projectId,revisionId:read.revisionId,contentHash:read.contentHash});
|
|
168
139
|
return true;
|
|
169
140
|
}
|
|
170
|
-
if(
|
|
171
|
-
|
|
172
|
-
|
|
141
|
+
if(importProjectRoute){
|
|
142
|
+
check(exact(body,['bundleText','copy'])&&typeof body.bundleText==='string'&&body.bundleText.length>0&&(body.copy===undefined||typeof body.copy==='boolean'),'E_NATIVE_ARGUMENT');
|
|
143
|
+
let imported;
|
|
144
|
+
try{
|
|
145
|
+
imported=await importProjectFile(service,body.bundleText,{copy:body.copy!==false});
|
|
146
|
+
}catch(error){
|
|
147
|
+
if(/^E_[A-Z0-9_]+$/.test(error.message))throw error;
|
|
148
|
+
if(/exceeds 64 MiB/i.test(error.message??''))throw Error('E_BUNDLE_SIZE',{cause:error});
|
|
149
|
+
throw Error('E_BUNDLE_INVALID',{cause:error});
|
|
150
|
+
}
|
|
151
|
+
const read=await service.read(imported.projectId);
|
|
152
|
+
json(201,{...imported,name:read.project.creativeBrief?.goal??imported.projectId,revisionId:read.revisionId,contentHash:read.contentHash,editorUrl:'/?project='+encodeURIComponent(imported.projectId)});
|
|
173
153
|
return true;
|
|
174
154
|
}
|
|
175
155
|
if(assetsFetchRoute){
|
|
176
|
-
check(exact(body,
|
|
177
|
-
json(200,await cc0Fetcher.fetchPackWithFallback(
|
|
156
|
+
check(exact(body,Object.keys(fetchCc0Properties))&&typeof body.sourceUrl==='string','E_NATIVE_ARGUMENT');
|
|
157
|
+
json(200,await cc0Fetcher.fetchPackWithFallback(body));
|
|
178
158
|
return true;
|
|
179
159
|
}
|
|
180
160
|
if(assetsPrepRoute){
|
|
@@ -187,35 +167,80 @@ export function nativeApi(service,connection=new ReviewConnection(service.store.
|
|
|
187
167
|
json(200,await materializeDemo(service,body.id));
|
|
188
168
|
return true;
|
|
189
169
|
}
|
|
190
|
-
if(intake){
|
|
191
|
-
const [,id,route,assetId]=intake;
|
|
192
|
-
check(!assetId,'E_NATIVE_METHOD');
|
|
193
|
-
if(!id)json(201,await intakes.create(body));
|
|
194
|
-
else if(route==='assets')json(201,await intakes.upload(id,body));
|
|
195
|
-
else if(route==='submit')json(200,await intakes.submit(id,body));
|
|
196
|
-
else if(route==='cancel'&&exact(body,[]))json(200,await intakes.cancel(id));
|
|
197
|
-
else if(route==='retry'&&exact(body,[]))json(200,await intakes.retry(id));
|
|
198
|
-
else check(false,'E_NATIVE_METHOD');
|
|
199
|
-
return true;
|
|
200
|
-
}
|
|
201
170
|
if(url.pathname==='/api/projects'){check(body.kind===undefined||body.kind==='native-scene','E_NATIVE_KIND');json(201,await service.create(body));return true;}
|
|
202
|
-
check(match,'E_NATIVE_NOT_FOUND');const [,id,route]=match;const fields={history:['expected','action'],accept:['revisionId','contentHash']
|
|
171
|
+
check(match,'E_NATIVE_NOT_FOUND');const [,id,route]=match;const fields={history:['expected','action'],accept:['revisionId','contentHash']}[route];if(fields)check(exact(body,fields)&&fields.every(key=>Object.hasOwn(body,key)),'E_NATIVE_ARGUMENT');
|
|
172
|
+
if(route==='export')check(exact(body,['revisionId','target','fitTargetBudget','variantId','confirmReviewed'])&&Object.hasOwn(body,'revisionId')&&Object.hasOwn(body,'target')&&(body.fitTargetBudget===undefined||typeof body.fitTargetBudget==='boolean'),'E_NATIVE_ARGUMENT');
|
|
173
|
+
if(route==='export-matrix')check(exact(body,['revisionId','variants','targets','fitTargetBudget','confirmReviewed','outputDir'])&&typeof body.revisionId==='string'&&Array.isArray(body.variants)&&Array.isArray(body.targets),'E_NATIVE_ARGUMENT');
|
|
174
|
+
if(route==='variants')check(exact(body,['action','variant','variantId','expectedVariantRevision','preset','id','label','language','texts','actionTexts','variables','storeUrl','direction','text'])&&['upsert','delete','preset'].includes(body.action),'E_NATIVE_ARGUMENT');
|
|
203
175
|
if(route==='assets')check((exact(body,['expected','asset'])&&Object.hasOwn(body,'expected')&&Object.hasOwn(body,'asset'))||(exact(body,['expected','assets'])&&Object.hasOwn(body,'expected')&&Object.hasOwn(body,'assets')),'E_NATIVE_ARGUMENT');
|
|
204
176
|
if(route==='stage-cc0')check(exact(body,['expected','items'])&&Object.hasOwn(body,'expected')&&Array.isArray(body.items),'E_NATIVE_ARGUMENT');
|
|
205
|
-
if(route==='review')
|
|
206
|
-
const review=await reviewForConnection();
|
|
207
|
-
const saved=await review.post(id,body);
|
|
208
|
-
// Once a batch is received, processing belongs to the server, even if the tab closes.
|
|
209
|
-
const start=body.action==='request'&&saved.status==='waiting'&&(review.configured||review.hasDeterministicIntent(saved));
|
|
210
|
-
json(200,start?await review.resolve(id,saved.id):saved);
|
|
211
|
-
}
|
|
177
|
+
if(route==='review')json(200,await review.post(id,body));
|
|
212
178
|
else if(route==='transactions/preview'){const {project,...preview}=await service.preview(id,body);void project;json(200,preview);}
|
|
213
179
|
else if(route==='transactions')json(201,await service.transact(id,body));
|
|
214
180
|
else if(route==='assets')json(201,Array.isArray(body.assets)?await service.uploadBatch(id,body):await service.upload(id,body));
|
|
215
181
|
else if(route==='stage-cc0')json(201,await stageVerifiedCc0Assets({service,projectId:id,expected:body.expected,items:body.items,catalog:assetCatalog,remoteFetcher:cc0Fetcher}));
|
|
182
|
+
else if(route==='win-cue')json(201,await replaceProjectWinCue(service,id,body));
|
|
216
183
|
else if(route==='history')json(200,await service.navigate(id,body));
|
|
217
184
|
else if(route==='accept')json(200,await service.accept(id,body));
|
|
185
|
+
else if(route==='variants'){
|
|
186
|
+
if(body.action==='upsert')json(200,await service.upsertVariant(id,body.variant,{expectedVariantRevision:body.expectedVariantRevision}));
|
|
187
|
+
else if(body.action==='delete')json(200,await service.deleteVariant(id,body.variantId,{expectedVariantRevision:body.expectedVariantRevision}));
|
|
188
|
+
else json(201,await service.createPresetVariant(id,body));
|
|
189
|
+
}
|
|
190
|
+
else if(route==='export-matrix'){
|
|
191
|
+
const jobId=randomUUID(),requested=body.outputDir?resolve(service.store.workspaceRoot,body.outputDir):resolve(service.store.root,id,'exports',jobId),workspace=resolve(service.store.workspaceRoot);check(requested===workspace||requested.startsWith(workspace+sep),'E_AGENT_OUTPUT');
|
|
192
|
+
const job={projectId:id,jobId,status:'RUNNING',progress:[]};matrixJobs.set(jobId,job);json(202,{jobId,status:'RUNNING'});
|
|
193
|
+
void service.exportVariantMatrix(id,{...body,outputDir:requested,onProgress:progress=>{job.progress.push({...progress,at:Date.now()});}}).then(result=>{Object.assign(job,result);}).catch(error=>{job.status='FAILED';job.error=/^E_[A-Z0-9_]+$/.test(error.message)?error.message:'E_NATIVE_FAILED';}).finally(()=>{for(const [key,value]of matrixJobs)if(key!==jobId&&value.completedAt&&Date.now()-value.completedAt>3600000)matrixJobs.delete(key);job.completedAt=Date.now();});
|
|
194
|
+
}
|
|
195
|
+
else if(route==='quick-edit'){
|
|
196
|
+
check(exact(body,['expected','edits'])&&Object.hasOwn(body,'expected')&&Array.isArray(body.edits),'E_QUICK_EDIT_ARGUMENT');
|
|
197
|
+
const current=await service.read(id);
|
|
198
|
+
check(body.expected?.revisionId===current.revisionId&&body.expected?.contentHash===current.contentHash,'E_NATIVE_STALE');
|
|
199
|
+
const operations=buildQuickEditOperations(current.project,body.edits);
|
|
200
|
+
const envelope={format:'tora-transaction-1',expected:body.expected,operations};
|
|
201
|
+
const preview=await service.preview(id,envelope);
|
|
202
|
+
const committed=await service.transact(id,{...envelope,previewDigest:preview.previewDigest});
|
|
203
|
+
const updated=await service.read(id,committed.revisionId);
|
|
204
|
+
json(200,{revisionId:committed.revisionId,contentHash:committed.contentHash,quickEdit:summarizeQuickEdit(updated.project)});
|
|
205
|
+
}
|
|
206
|
+
else if(route==='qa'){
|
|
207
|
+
check(exact(body,['revisionId','target','variantId','fitTargetBudget']),'E_NATIVE_ARGUMENT');
|
|
208
|
+
const target=body.target??'standalone-browser-draft';
|
|
209
|
+
const variantId=body.variantId&&body.variantId!=='base'?body.variantId:undefined;
|
|
210
|
+
const fitTargetBudget=Boolean(body.fitTargetBudget);
|
|
211
|
+
const report=await service.runQa(id,{
|
|
212
|
+
revisionId:body.revisionId,
|
|
213
|
+
target,
|
|
214
|
+
variantId,
|
|
215
|
+
fitTargetBudget,
|
|
216
|
+
motionFilmstrip:true,
|
|
217
|
+
recordVideo:false,
|
|
218
|
+
});
|
|
219
|
+
const budget=await service.estimateBudget(id,{target,variantId,revisionId:body.revisionId,fitTargetBudget});
|
|
220
|
+
const qaRoot=resolve(service.store.root,id,'qa');
|
|
221
|
+
const assetUrl=relPath=>{
|
|
222
|
+
if(!relPath||!report.outputDir)return null;
|
|
223
|
+
const full=resolve(report.outputDir,relPath);
|
|
224
|
+
if(!full.startsWith(qaRoot+sep))return null;
|
|
225
|
+
const rel=relative(qaRoot,full).split(sep).join('/');
|
|
226
|
+
return `/api/projects/${encodeURIComponent(id)}/qa-asset?file=${encodeURIComponent(rel)}`;
|
|
227
|
+
};
|
|
228
|
+
const sheet=report.contactSheets?.find(item=>item.state==='all')??report.contactSheets?.[0];
|
|
229
|
+
const filmstrip=report.motionFilmstrips?.[0];
|
|
230
|
+
json(200,{
|
|
231
|
+
ok:Boolean(report.ok),
|
|
232
|
+
target,
|
|
233
|
+
bytes:budget.totalBytes,
|
|
234
|
+
cacheHit:Boolean(report.cacheHit),
|
|
235
|
+
blockers:report.blockers??[],
|
|
236
|
+
warnings:report.warnings??[],
|
|
237
|
+
checkedStates:report.summary?.checkedStates??[],
|
|
238
|
+
storeCta:report.checks?.browser?.storeCta??null,
|
|
239
|
+
contactSheetUrl:assetUrl(sheet?.path),
|
|
240
|
+
filmstripUrl:assetUrl(filmstrip?.path),
|
|
241
|
+
});
|
|
242
|
+
}
|
|
218
243
|
else if(route==='export')json(200,await service.export(id,body));
|
|
219
244
|
else check(false,'E_NATIVE_METHOD');return true;
|
|
220
|
-
}catch(e){const code=/^E_[A-Z0-9_]+$/.test(
|
|
245
|
+
}catch(e){const msg=String(e?.message??'');const code=/^E_[A-Z0-9_]+$/.test(msg)?msg:/Executable doesn't exist|playwright install|browserType\.launch/i.test(msg)?'E_CHROMIUM_MISSING':e.code==='EEXIST'?'E_NATIVE_EXISTS':e.code==='ENOENT'?'E_NATIVE_NOT_FOUND':'E_NATIVE_FAILED';const status=code.includes('STALE')||code.endsWith('EXISTS')?409:code.includes('ORIGIN')?403:code.includes('SIZE')||code.includes('LIMIT')?413:code.includes('NOT_FOUND')?404:code.startsWith('E_V2_')||code.includes('ENVELOPE')||code.includes('ARGUMENT')||code.includes('JSON')||code.includes('METHOD')||code.includes('CONTENT_TYPE')?400:422;json(status,{error:code,...(e.detail?{detail:e.detail}:{})});return true;}
|
|
221
246
|
};}
|
|
@@ -4,11 +4,11 @@ import {readFile,stat} from 'node:fs/promises';
|
|
|
4
4
|
import {resolve,sep,extname} from 'node:path';
|
|
5
5
|
import {fileURLToPath,URL} from 'node:url';
|
|
6
6
|
import {safeFile} from './assets.mjs';
|
|
7
|
-
import {validateMp3,validateToraMesh} from './media-validate.mjs';
|
|
7
|
+
import {validateGlbHeader,validateMp3,validateToraMesh} from './media-validate.mjs';
|
|
8
8
|
|
|
9
9
|
const workspaceRoot=fileURLToPath(new URL('../../../',import.meta.url));
|
|
10
|
-
const planPacks=['kenney-harvest','kenney-space-salvage','kenney-sports','kenney-racing','tora-golf','tora-traffic'];
|
|
11
|
-
const mediaMimes=new Set(['image/png','image/jpeg','audio/wav','audio/mpeg','model/tora-mesh']);
|
|
10
|
+
const planPacks=['kenney-harvest','kenney-space-salvage','kenney-sports','kenney-racing','kenney-food-starter','tora-golf','tora-traffic'];
|
|
11
|
+
const mediaMimes=new Set(['image/png','image/jpeg','audio/wav','audio/mpeg','model/tora-mesh','model/gltf-binary']);
|
|
12
12
|
const assetSources=new Set(['studio-assets','hybrid-free','free-licensed']);
|
|
13
13
|
const digest=bytes=>'sha256:'+createHash('sha256').update(bytes).digest('hex');
|
|
14
14
|
|
|
@@ -53,6 +53,7 @@ export function inspectMedia(bytes,mime){
|
|
|
53
53
|
else if(mime==='audio/wav')Object.assign(result,wavMetadata(bytes));
|
|
54
54
|
else if(mime==='audio/mpeg')Object.assign(result,validateMp3(bytes));
|
|
55
55
|
else if(mime==='model/tora-mesh')Object.assign(result,validateToraMesh(bytes));
|
|
56
|
+
else if(mime==='model/gltf-binary')Object.assign(result,validateGlbHeader(bytes));
|
|
56
57
|
return result;
|
|
57
58
|
}
|
|
58
59
|
function mediaKind(mime){
|
|
@@ -87,7 +88,7 @@ export class AssetCatalog{
|
|
|
87
88
|
this.root=resolve(root);this.catalogPath=catalogPath;this.packNames=packNames;this.entries=new Map();this.loaded=false;
|
|
88
89
|
}
|
|
89
90
|
async addFile({source,file,packRoot}){
|
|
90
|
-
const inferred={'.png':'image/png','.jpg':'image/jpeg','.jpeg':'image/jpeg','.wav':'audio/wav','.mp3':'audio/mpeg','.t3d':'model/tora-mesh'}[extname(file.file??'').toLowerCase()];file={...file,mime:file.mime??inferred};
|
|
91
|
+
const inferred={'.png':'image/png','.jpg':'image/jpeg','.jpeg':'image/jpeg','.wav':'audio/wav','.mp3':'audio/mpeg','.t3d':'model/tora-mesh','.glb':'model/gltf-binary'}[extname(file.file??'').toLowerCase()];file={...file,mime:file.mime??inferred};
|
|
91
92
|
if(!mediaMimes.has(file.mime)||!file.file||!file.sha256&&!file.sourceHash)return;
|
|
92
93
|
let absolutePath;
|
|
93
94
|
try{absolutePath=contained(this.root,packRoot?resolve(packRoot,file.file):file.file);}catch{return;}
|
|
@@ -148,14 +149,14 @@ export class AssetCatalog{
|
|
|
148
149
|
const words=String(query).toLowerCase().split(/\s+/).filter(Boolean);
|
|
149
150
|
return [...this.entries.values()].filter(entry=>
|
|
150
151
|
(!kind||entry.kind===kind)&&(!styleFamily||entry.styleFamily===styleFamily)&&
|
|
151
|
-
words.every(word=>(entry.name+' '+entry.tags.join(' ')+' '+entry.packTitle).toLowerCase().includes(word))
|
|
152
|
+
words.every(word=>(entry.name+' '+entry.tags.join(' ')+' '+entry.packTitle+' '+(entry.subNodes??[]).join(' ')+' '+(entry.animations??[]).join(' ')).toLowerCase().includes(word))
|
|
152
153
|
).sort((a,b)=>a.styleFamily.localeCompare(b.styleFamily)||a.name.localeCompare(b.name)).slice(0,Math.min(100,Math.max(1,limit))).map(compact);
|
|
153
154
|
}
|
|
154
155
|
get(ids){
|
|
155
156
|
return ids.map(id=>{const entry=this.entries.get(id);if(!entry)throw Error('E_ASSET_NOT_FOUND');return entry;});
|
|
156
157
|
}
|
|
157
158
|
summary(){
|
|
158
|
-
const entries=[...this.entries.values()],families=new Set(entries.filter(entry=>entry.kind==='sprite').map(entry=>entry.styleFamily));
|
|
159
|
+
const entries=[...this.entries.values()],families=new Set(entries.filter(entry=>entry.kind==='sprite'||entry.kind==='mesh').map(entry=>entry.styleFamily));
|
|
159
160
|
return {assets:entries.length,sprites:entries.filter(entry=>entry.kind==='sprite').length,audio:entries.filter(entry=>entry.kind==='audio').length,meshes:entries.filter(entry=>entry.kind==='mesh').length,styleFamilies:[...families].sort()};
|
|
160
161
|
}
|
|
161
162
|
async bytes(id){const [entry]=this.get([id]);return safeFile(entry.absolutePath);}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {randomUUID} from 'node:crypto';
|
|
2
|
+
import {mkdir,rename,rm,writeFile} from 'node:fs/promises';
|
|
3
|
+
import {resolve,dirname} from 'node:path';
|
|
4
|
+
import {check} from './document.mjs';
|
|
5
|
+
import {safeFile} from './assets.mjs';
|
|
6
|
+
import {assertStorePath} from './store-path.mjs';
|
|
7
|
+
|
|
8
|
+
async function load(root){
|
|
9
|
+
const path=resolve(root,'sources/assets/lineage.json');
|
|
10
|
+
try{
|
|
11
|
+
const ledger=JSON.parse((await safeFile(path)).toString());
|
|
12
|
+
check(ledger.format==='tora-asset-lineage-1'&&ledger.revisions&&typeof ledger.revisions==='object','E_ASSET_LINEAGE');
|
|
13
|
+
return ledger;
|
|
14
|
+
}catch(error){
|
|
15
|
+
if(error.code!=='ENOENT')throw error;
|
|
16
|
+
return {format:'tora-asset-lineage-1',revisions:{}};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function readRevisionLineage(root,revisionId){
|
|
21
|
+
const ledger=await load(root);
|
|
22
|
+
return ledger.revisions[revisionId]??{};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// The caller holds the project journal lock, or owns an unpublished import directory.
|
|
26
|
+
export async function saveRevisionLineage(root,project,parentRevisionId,registered=[]){
|
|
27
|
+
const ledger=await load(root);
|
|
28
|
+
const parent=ledger.revisions[parentRevisionId]??{};
|
|
29
|
+
const uploads=new Map(registered.map(asset=>[asset.id,asset]));
|
|
30
|
+
const entries=Object.create(null);
|
|
31
|
+
for(const asset of project.assets){
|
|
32
|
+
const upload=uploads.get(asset.id);
|
|
33
|
+
const receipt=upload?.optimization;
|
|
34
|
+
if(upload&&receipt?.originalHash){
|
|
35
|
+
check(upload.hash===asset.hash,'E_ASSET_LINEAGE');
|
|
36
|
+
const {originalHash,originalMime,originalBytes,dependencyManifestHash,options,...facts}=receipt;
|
|
37
|
+
entries[asset.id]={deliveryHash:asset.hash,originalHash,originalMime,originalBytes,
|
|
38
|
+
...(dependencyManifestHash?{dependencyManifestHash}:{}),options:options??{mode:receipt.mode},
|
|
39
|
+
receipt:facts,masterAvailable:true};
|
|
40
|
+
}else if(!upload&&parent[asset.id]?.deliveryHash===asset.hash){
|
|
41
|
+
entries[asset.id]=parent[asset.id];
|
|
42
|
+
}else{
|
|
43
|
+
entries[asset.id]={deliveryHash:asset.hash,masterAvailable:false};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
ledger.revisions[project.revisionId]=entries;
|
|
47
|
+
const path=resolve(root,'sources/assets/lineage.json');
|
|
48
|
+
await assertStorePath(path);await mkdir(dirname(path),{recursive:true});
|
|
49
|
+
const temp=path+'.'+randomUUID();
|
|
50
|
+
try{
|
|
51
|
+
await writeFile(temp,JSON.stringify(ledger),{flag:'wx'});
|
|
52
|
+
await rename(temp,path);
|
|
53
|
+
}finally{await rm(temp,{force:true});}
|
|
54
|
+
}
|