@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
|
@@ -94,3 +94,9 @@ export class EditorState{
|
|
|
94
94
|
async write(id,state){const path=await this.file(id),temp=path+'.'+randomUUID()+'.tmp';await writeFile(temp,JSON.stringify(state));await rename(temp,path);}
|
|
95
95
|
async lock(id,fn){id=this.store.root+'\0'+id;const prior=this.queues.get(id)??Promise.resolve();let release;const done=new Promise(r=>release=r);this.queues.set(id,done);await prior;try{return await fn();}finally{release();if(this.queues.get(id)===done)this.queues.delete(id);}}
|
|
96
96
|
}
|
|
97
|
+
|
|
98
|
+
export async function withProjectFileLock(lockPath,fn,{lockTimeoutMs=15000,staleLockMs=30000}={}){
|
|
99
|
+
const state=Object.create(EditorState.prototype);state.lockTimeoutMs=lockTimeoutMs;state.staleLockMs=staleLockMs;
|
|
100
|
+
const token=await state.acquireFileLock(lockPath);
|
|
101
|
+
try{return await fn();}finally{await state.releaseFileLock(lockPath,token);}
|
|
102
|
+
}
|
package/scripts/lean/editor.mjs
CHANGED
|
@@ -7,20 +7,22 @@ import {ProjectStore} from './project-store.mjs';
|
|
|
7
7
|
import {EditorState} from './editor-state.mjs';
|
|
8
8
|
import {NativeService} from './native/service.mjs';
|
|
9
9
|
import {nativeApi} from './native/api.mjs';
|
|
10
|
+
import {closeSharedBrowser,getSharedBrowser} from './native/browser-pool.mjs';
|
|
10
11
|
|
|
11
12
|
const assets = new Map([
|
|
12
13
|
['/', ['index.html', 'text/html; charset=utf-8']],
|
|
13
14
|
['/entry.js', ['entry.js', 'text/javascript']],
|
|
14
15
|
['/review-editor.js', ['review-editor.js', 'text/javascript']],
|
|
15
|
-
['/
|
|
16
|
+
['/quick-edit-panel.js', ['quick-edit-panel.js', 'text/javascript']],
|
|
17
|
+
['/project-launcher.js', ['project-launcher.js', 'text/javascript']],
|
|
16
18
|
['/review-editor.css', ['review-editor.css', 'text/css']],
|
|
17
19
|
['/brand/manrope.ttf', ['brand/manrope.ttf', 'font/ttf']],
|
|
18
20
|
['/brand/mark.svg', ['brand/mark.svg', 'image/svg+xml']],
|
|
19
21
|
['/brand/tora-wordmark.svg', ['brand/tora-wordmark.svg', 'image/svg+xml']],
|
|
20
22
|
]);
|
|
21
23
|
|
|
22
|
-
export async function createEditorServer({store = new ProjectStore(), port = 0
|
|
23
|
-
const native = nativeApi(new NativeService(store, new EditorState(store)
|
|
24
|
+
export async function createEditorServer({store = new ProjectStore(), port = 0} = {}) {
|
|
25
|
+
const native = nativeApi(new NativeService(store, new EditorState(store), {browserProvider: getSharedBrowser}));
|
|
24
26
|
const server = createServer(async (req, res) => {
|
|
25
27
|
res.setHeader('Cache-Control', 'no-store');
|
|
26
28
|
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
@@ -40,6 +42,7 @@ export async function createEditorServer({store = new ProjectStore(), port = 0,
|
|
|
40
42
|
res.end(JSON.stringify({error: error.message || 'E_EDITOR_SERVER'}));
|
|
41
43
|
}
|
|
42
44
|
});
|
|
45
|
+
server.once('close', () => {void closeSharedBrowser();});
|
|
43
46
|
await new Promise((done, reject) => {
|
|
44
47
|
server.once('error', reject);
|
|
45
48
|
server.listen(port, '127.0.0.1', done);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
const check=(value,code)=>{if(!value)throw Error(code);};
|
|
2
|
+
export const identityMatrix=()=>[1,0,0,1,0,0];
|
|
3
|
+
export function validateMatrix(matrix){check(Array.isArray(matrix)&&matrix.length===6&&matrix.every(Number.isFinite),'E_SCENE_MATRIX');return matrix;}
|
|
4
|
+
export function multiplyMatrix(left,right){validateMatrix(left);validateMatrix(right);return [left[0]*right[0]+left[2]*right[1],left[1]*right[0]+left[3]*right[1],left[0]*right[2]+left[2]*right[3],left[1]*right[2]+left[3]*right[3],left[0]*right[4]+left[2]*right[5]+left[4],left[1]*right[4]+left[3]*right[5]+left[5]];}
|
|
5
|
+
export function inverseMatrix(matrix){validateMatrix(matrix);const determinant=matrix[0]*matrix[3]-matrix[1]*matrix[2];check(Math.abs(determinant)>1e-12,'E_SCENE_SINGULAR_TRANSFORM');return [matrix[3]/determinant,-matrix[1]/determinant,-matrix[2]/determinant,matrix[0]/determinant,(matrix[2]*matrix[5]-matrix[3]*matrix[4])/determinant,(matrix[1]*matrix[4]-matrix[0]*matrix[5])/determinant];}
|
|
@@ -5,15 +5,14 @@ import {resolve,dirname,basename} from 'node:path';
|
|
|
5
5
|
import {ProjectStore} from '../project-store.mjs';
|
|
6
6
|
import {EditorState} from '../editor-state.mjs';
|
|
7
7
|
import {NativeService} from './service.mjs';
|
|
8
|
-
import {runtimeBundle} from './compiler.mjs';
|
|
8
|
+
import {runtimeBundle,runtime3dBundle,projectUses3d} from './compiler.mjs';
|
|
9
9
|
import {exportProjectFile,importProjectPath} from './local-bundle.mjs';
|
|
10
10
|
import {playableHTML} from './html.mjs';
|
|
11
|
-
import {registerSource} from './assets.mjs';
|
|
12
11
|
import {capabilities,capabilitiesForPacks,compactCapabilities} from './contracts.mjs';
|
|
13
|
-
import {composeNativeConcept,CREATIVE_CONCEPT_SCHEMA} from './concept.mjs';
|
|
14
12
|
import {references,check} from './document.mjs';
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
import {nativeCollections,outsideNativeScope} from './scope.mjs';
|
|
14
|
+
import {NativeReview} from './review.mjs';
|
|
15
|
+
const collections=nativeCollections;
|
|
17
16
|
const identity=r=>({revisionId:r.revisionId,contentHash:r.contentHash});
|
|
18
17
|
const round1=n=>Math.round(Number(n)*10)/10;
|
|
19
18
|
const shortContract=id=>({rectangle:'rect',button:'btn',image:'img',group:'grp',ellipse:'ell',sprite:'spr','walk-sprite':'walk'})[id.replace(/^native\./,'').replace(/\.v1$/,'')]??id.replace(/^native\./,'').replace(/\.v1$/,'');
|
|
@@ -21,14 +20,6 @@ function bounded(value,limit){check(Buffer.byteLength(JSON.stringify(value))<=li
|
|
|
21
20
|
function pick(record,fields){if(!fields)return record;const result={id:record.id};for(const key of fields){if(Object.hasOwn(record,key))result[key]=record[key];else if(key.startsWith('parameters.')&&Object.hasOwn(record.parameters??{},key.slice(11))){result.parameters??={};result.parameters[key.slice(11)]=record.parameters[key.slice(11)];}}return result;}
|
|
22
21
|
function descriptors(project,ids,fields){const result={},registry=capabilities().contracts;for(const c of project.components.filter(c=>ids.includes(c.id))){if(!c.contract||!registry[c.contract])continue;const keys=!fields||fields.includes('parameters')?Object.keys(c.parameters):fields.filter(k=>k.startsWith('parameters.')).map(k=>k.slice(11));if(keys.length)result[c.contract]={properties:Object.fromEntries(keys.filter(key=>Object.hasOwn(registry[c.contract].properties,key)).map(key=>[key,registry[c.contract].properties[key]]))};}return result;}
|
|
23
22
|
function records(project){return collections.flatMap(collection=>project[collection].map(record=>({collection,record})));}
|
|
24
|
-
function recordRefs(record){
|
|
25
|
-
const refs=[...references(record)];
|
|
26
|
-
if(record?.parentId)refs.push(record.parentId);
|
|
27
|
-
if(record?.contract==='native.text.v1'&&typeof record.parameters?.text==='string'){
|
|
28
|
-
for(const m of record.parameters.text.matchAll(/\{\{([a-z0-9_.-]+)\}\}/g))refs.push(m[1]);
|
|
29
|
-
}
|
|
30
|
-
return refs;
|
|
31
|
-
}
|
|
32
23
|
function summarizeEvent(event){
|
|
33
24
|
if(!event)return '?';
|
|
34
25
|
const target=event.componentId??event.sceneId??event.variableId??event.behaviorId??'';
|
|
@@ -66,14 +57,14 @@ export function buildInspectTree(projectId,current,sceneId){
|
|
|
66
57
|
for(const c of childrenOf(parentKey)){
|
|
67
58
|
const p=c.parameters??{},parts=[`${' '.repeat(depth)}${c.id} [${shortContract(c.contract)}]`];
|
|
68
59
|
if(c.contract==='native.mesh3d.v1'){
|
|
60
|
+
if(p.subNode)parts.push(`subNode:${p.subNode}`);
|
|
69
61
|
parts.push(`${p.primitive??'box'}@(${round1(p.x??0)},${round1(p.y??0)},${round1(p.z??0)})`);
|
|
70
62
|
}else{
|
|
71
63
|
const t=c.transform??[1,0,0,1,0,0],tx=round1(t[4]),ty=round1(t[5]),w=round1(p.width??0),h=round1(p.height??0);
|
|
72
64
|
if(tx!==0||ty!==0)parts.push(`@(${tx},${ty})`);
|
|
73
65
|
if(w!==0||h!==0)parts.push(`${w}x${h}`);
|
|
74
66
|
}
|
|
75
|
-
const
|
|
76
|
-
if(assetId)parts.push(`a:${assetId}`);
|
|
67
|
+
for(const slot of c.assetSlots??[])parts.push(`${slot.slotId==='source'?'a':slot.slotId}:${slot.assetId}`);
|
|
77
68
|
if(typeof p.text==='string'){const clean=p.text.replace(/\s+/g,' ');parts.push(`"${clean.length>24?clean.slice(0,23)+'…':clean}"`);}
|
|
78
69
|
if(p.visible===false)parts.push('hidden');
|
|
79
70
|
if(c.prototype)parts.push('proto');
|
|
@@ -102,6 +93,16 @@ export function buildInspectTree(projectId,current,sceneId){
|
|
|
102
93
|
scenes,bindings,
|
|
103
94
|
},16384);
|
|
104
95
|
}
|
|
96
|
+
function compactMatrixSummary(summary){
|
|
97
|
+
if((summary.entries?.length??0)<=40&&Buffer.byteLength(JSON.stringify(summary))<=200000)return summary;
|
|
98
|
+
const {exports,entries,...pinned}=summary;void exports;void entries;
|
|
99
|
+
return {...pinned,summaryPath:resolve(summary.outputDir,'matrix-summary.json'),exportCount:summary.exports.length,failureCount:summary.failures.length,failures:summary.failures.slice(0,20).map(({blockers,...failure})=>({...failure,blockerCount:blockers?.length??0})),truncated:true};
|
|
100
|
+
}
|
|
101
|
+
async function withInspectBudget(service,input,current,result){
|
|
102
|
+
if(input.includeBudget)result={...result,budget:await service.estimateBudget(current.project.projectId,{target:input.target??'standalone-browser-draft',variantId:input.variantId,revisionId:current.revisionId})};
|
|
103
|
+
if(input.includeReview)result={...result,review:await new NativeReview(service).summaries(current.project.projectId)};
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
105
106
|
export class NativeAgentTools{
|
|
106
107
|
constructor(service=new NativeService(new ProjectStore(resolve('.tora/native-projects')),undefined)){this.service=service;this.previewCache=new Map();if(!service.history)service.history=new EditorState(service.store);}
|
|
107
108
|
async run(input){check(input&&typeof input==='object'&&!Array.isArray(input),'E_AGENT_ARGUMENT');const {command,id}=input;
|
|
@@ -111,9 +112,7 @@ export class NativeAgentTools{
|
|
|
111
112
|
if(input.names!==undefined)check(Array.isArray(input.names)&&input.names.length>0&&input.names.length<=16,'E_AGENT_CONTRACT_SCOPE');
|
|
112
113
|
else check(Boolean(input.packs),'E_AGENT_CONTRACT_SCOPE');
|
|
113
114
|
if(input.format==='compact'){
|
|
114
|
-
const
|
|
115
|
-
const result=input.packs||otherNames.length?compactCapabilities({packs:input.packs,names:otherNames.length?otherNames:undefined}):{format:'tora-creation-capabilities-compact-1'};
|
|
116
|
-
if(wantsConcept)result['creative-concept']=CREATIVE_CONCEPT_SCHEMA;
|
|
115
|
+
const result=input.packs||input.names?.length?compactCapabilities({packs:input.packs,names:input.names}):{format:'tora-creation-capabilities-compact-1'};
|
|
117
116
|
return bounded(result,input.packs?65536:24576);
|
|
118
117
|
}
|
|
119
118
|
const cap=capabilities();
|
|
@@ -121,7 +120,6 @@ export class NativeAgentTools{
|
|
|
121
120
|
for(const name of input.names??[]){
|
|
122
121
|
if(cap.contracts[name]){if(input.packs){result.contracts??={};result.contracts[name]=cap.contracts[name];}else result[name]=cap.contracts[name];}
|
|
123
122
|
else if(cap.behaviors[name]){if(input.packs){result.behaviors??={};result.behaviors[name]=cap.behaviors[name];}else result[name]=cap.behaviors[name];}
|
|
124
|
-
else if(name==='creative-concept')result['creative-concept']=CREATIVE_CONCEPT_SCHEMA;
|
|
125
123
|
else if(name==='operations')result.operations=cap.operations;
|
|
126
124
|
else if(name==='actions')result.actions=cap.actions;
|
|
127
125
|
else if(name==='events')result.events=cap.events;
|
|
@@ -130,37 +128,21 @@ export class NativeAgentTools{
|
|
|
130
128
|
}
|
|
131
129
|
return bounded(result,input.packs?65536:24576);
|
|
132
130
|
}
|
|
133
|
-
if(command==='compose'){
|
|
134
|
-
const composition=composeNativeConcept(input.concept);
|
|
135
|
-
const summary={status:'COMPOSED',projectId:id,conceptHash:composition.conceptHash,conceptAccepted:false,accepted:false,creativeStatus:composition.creativeStatus,unmetRequirements:composition.unmetRequirements,requirements:composition.requirements,...(composition.recipe?{recipe:composition.recipe}:{})};
|
|
136
|
-
// Check response capacity before creating a project or committing a revision.
|
|
137
|
-
bounded({...summary,expected:{revisionId:'rev-'+'0'.repeat(36),contentHash:'sha256:'+'0'.repeat(64)}},24576);
|
|
138
|
-
const created=await this.service.create({id,name:input.name??input.concept?.product?.name});
|
|
139
|
-
const registered=new Map();for(const asset of composition.assets)registered.set(asset.id,await registerSource(resolve(this.service.store.root,id),asset));
|
|
140
|
-
const operations=composition.operations.map(operation=>{if(operation.kind!=='registerAsset'||!registered.has(operation.asset.id))return operation;const metadata=registered.get(operation.asset.id);return {...operation,asset:{...operation.asset,hash:metadata.hash,mime:metadata.mime,bytes:metadata.bytes}};});
|
|
141
|
-
const envelope={format:'tora-transaction-1',expected:identity(created),operations};
|
|
142
|
-
const preview=await this.service.preview(id,envelope);
|
|
143
|
-
const record=composition.recipe?(state,revision)=>{
|
|
144
|
-
state.authoring={recipe:composition.recipe,conceptHash:composition.conceptHash,createdRevisionId:revision.revisionId};
|
|
145
|
-
}:undefined;
|
|
146
|
-
const result=await this.service.transact(id,{...envelope,previewDigest:preview.previewDigest},{record});
|
|
147
|
-
return {...summary,expected:identity(result)};
|
|
148
|
-
}
|
|
149
131
|
if(command==='create'){const r=await this.service.create({id,name:input.name,...(input.androidUrl?{androidUrl:input.androidUrl}:{})});return bounded({status:'CREATED',projectId:id,expected:identity(r)},4096);}
|
|
150
132
|
if(command==='import'){check(typeof input.file==='string','E_AGENT_ARGUMENT');return bounded(await importProjectPath(this.service,input.file,{copy:input.copy===true}),4096);}
|
|
151
|
-
if(command==='export'&&input.format==='project'){check(typeof input.output==='string'&&input.output.length>0,'E_AGENT_OUTPUT');const text=await exportProjectFile(this.service,id),output=resolve(input.output);await mkdir(dirname(output),{recursive:true});await writeFile(output,text);return {status:'EXPORTED',projectId:id,output,format:'tora-project-bundle',version:
|
|
133
|
+
if(command==='export'&&input.format==='project'){check(typeof input.output==='string'&&input.output.length>0,'E_AGENT_OUTPUT');const text=await exportProjectFile(this.service,id),output=resolve(input.output);await mkdir(dirname(output),{recursive:true});await writeFile(output,text);return {status:'EXPORTED',projectId:id,output,format:'tora-project-bundle',version:JSON.parse(text).version};}
|
|
152
134
|
const current=await this.service.read(id,input.revisionId);
|
|
153
135
|
if(command==='inspect'){
|
|
154
|
-
if(input.full)return {projectId:id,expected:identity(current),accepted:current.accepted,project:current.project};
|
|
155
|
-
if(input.tree)return buildInspectTree(id,current,input.sceneId);
|
|
136
|
+
if(input.full)return withInspectBudget(this.service,input,current,{projectId:id,expected:identity(current),accepted:current.accepted,project:current.project});
|
|
137
|
+
if(input.tree)return withInspectBudget(this.service,input,current,buildInspectTree(id,current,input.sceneId));
|
|
156
138
|
const all=records(current.project);
|
|
157
139
|
if(input.ids){check(Array.isArray(input.ids)&&input.ids.length>0&&input.ids.length<=64&&new Set(input.ids).size===input.ids.length,'E_AGENT_SCOPE');check(input.ids.every(id=>all.some(x=>x.record.id===id)),'E_AGENT_UNKNOWN_RECORD');if(input.fields)check(Array.isArray(input.fields)&&input.fields.every(k=>typeof k==='string'),'E_AGENT_FIELDS');const selected=new Set(input.ids),needed=new Set(input.ids);for(const id of input.ids){let component=current.project.components.find(c=>c.id===id);while(component){needed.add(component.sceneId);if(component.parentId)needed.add(component.parentId);component=current.project.components.find(c=>c.id===component.parentId);}}
|
|
158
140
|
for(const {record}of all)if(selected.has(record.id))for(const ref of references(record))needed.add(ref);
|
|
159
141
|
const related=all.filter(({record})=>needed.has(record.id)||references(record).some(ref=>selected.has(ref)));
|
|
160
|
-
return bounded({projectId:id,expected:identity(current),records:related.map(({collection,record})=>({collection,...pick(record,selected.has(record.id)?input.fields:undefined)})),contracts:descriptors(current.project,input.ids,input.fields)},24576);
|
|
142
|
+
return bounded(await withInspectBudget(this.service,input,current,{projectId:id,expected:identity(current),records:related.map(({collection,record})=>({collection,...pick(record,selected.has(record.id)?input.fields:undefined)})),contracts:descriptors(current.project,input.ids,input.fields)}),24576);
|
|
161
143
|
}
|
|
162
|
-
if(input.search!==undefined){check(typeof input.search==='string'&&input.search.length<=128,'E_AGENT_ARGUMENT');const query=input.search.toLowerCase();return bounded({projectId:id,expected:identity(current),matches:all.filter(({record})=>(record.id+' '+(record.label??'')).toLowerCase().includes(query)).map(({collection,record})=>({collection,id:record.id,label:record.label}))},8192);}
|
|
163
|
-
return bounded({projectId:id,expected:identity(current),goal:current.project.creativeBrief.goal,scenes:current.project.scenes,counts:Object.fromEntries(collections.map(k=>[k,current.project[k].length])),targets:capabilities().targets},8192);
|
|
144
|
+
if(input.search!==undefined){check(typeof input.search==='string'&&input.search.length<=128,'E_AGENT_ARGUMENT');const query=input.search.toLowerCase();return bounded(await withInspectBudget(this.service,input,current,{projectId:id,expected:identity(current),matches:all.filter(({record})=>(record.id+' '+(record.label??'')).toLowerCase().includes(query)).map(({collection,record})=>({collection,id:record.id,label:record.label}))}),8192);}
|
|
145
|
+
return bounded(await withInspectBudget(this.service,input,current,{projectId:id,expected:identity(current),goal:current.project.creativeBrief.goal,scenes:current.project.scenes,counts:Object.fromEntries(collections.map(k=>[k,current.project[k].length])),targets:capabilities().targets}),8192);
|
|
164
146
|
}
|
|
165
147
|
if(command==='edit'){
|
|
166
148
|
check(input.expected&&Array.isArray(input.scope)&&input.scope.every(s=>typeof s==='string'),'E_AGENT_ARGUMENT');
|
|
@@ -186,23 +168,7 @@ export class NativeAgentTools{
|
|
|
186
168
|
this.previewCache.set(previewDigest,{id,expected:input.expected,operations,previewDigest,changed,warnings,previewProject});
|
|
187
169
|
while(this.previewCache.size>16)this.previewCache.delete(this.previewCache.keys().next().value);
|
|
188
170
|
}
|
|
189
|
-
const
|
|
190
|
-
let outside;
|
|
191
|
-
if(input.scopeCreates){
|
|
192
|
-
const existingAll=new Set(collections.flatMap(col=>current.project[col].map(r=>r.id)));
|
|
193
|
-
const existingMutable=new Set(mutableCollections.flatMap(col=>current.project[col].map(r=>r.id)));
|
|
194
|
-
const previewById=new Map(collections.flatMap(col=>previewProject[col].map(r=>[r.id,r])));
|
|
195
|
-
outside=changed.filter(cid=>{
|
|
196
|
-
if(scope.has(cid))return false;
|
|
197
|
-
if(cid==='$project.base'||existingAll.has(cid))return true;
|
|
198
|
-
const rec=previewById.get(cid);
|
|
199
|
-
if(!rec)return true;
|
|
200
|
-
const refs=recordRefs(rec);
|
|
201
|
-
return refs.some(ref=>existingMutable.has(ref)&&!scope.has(ref));
|
|
202
|
-
});
|
|
203
|
-
}else{
|
|
204
|
-
outside=changed.filter(cid=>!scope.has(cid));
|
|
205
|
-
}
|
|
171
|
+
const outside=outsideNativeScope(current.project,previewProject,changed,input.scope,input.scopeCreates===true);
|
|
206
172
|
// Explicit scope includes all intended writes (or reference-safe creates when scopeCreates:true).
|
|
207
173
|
if(input.previewOnly||outside.length){return bounded({status:'PREVIEW',expected:input.expected,previewDigest,changedIds:changed,outsideScope:outside,warnings},24576);}
|
|
208
174
|
if(input.previewDigest)check(input.previewDigest===previewDigest,'E_NATIVE_PREVIEW_STALE');
|
|
@@ -211,17 +177,28 @@ export class NativeAgentTools{
|
|
|
211
177
|
this.previewCache.delete(previewDigest);
|
|
212
178
|
return {...summary,expected:identity(result)};
|
|
213
179
|
}
|
|
180
|
+
if(command==='variants'){
|
|
181
|
+
check(['list','diff','upsert','delete','preset'].includes(input.action),'E_AGENT_ARGUMENT');
|
|
182
|
+
if(input.action==='list')return this.service.listVariants(id);
|
|
183
|
+
if(input.action==='diff'){check(typeof input.variantId==='string'&&input.variantId.length>0,'E_AGENT_ARGUMENT');return this.service.diffVariant(id,input.variantId,{revisionId:input.revisionId});}
|
|
184
|
+
if(input.action==='upsert'){check(input.variant&&typeof input.variant==='object','E_AGENT_ARGUMENT');return this.service.upsertVariant(id,input.variant,{expectedVariantRevision:input.expectedVariantRevision});}
|
|
185
|
+
if(input.action==='delete'){check(typeof input.variantId==='string'&&input.variantId.length>0,'E_AGENT_ARGUMENT');return this.service.deleteVariant(id,input.variantId,{expectedVariantRevision:input.expectedVariantRevision});}
|
|
186
|
+
check(typeof input.variantId==='string'&&input.variantId.length>0&&typeof input.preset==='string'&&input.preset.length>0,'E_AGENT_ARGUMENT');
|
|
187
|
+
const {command:cmd,variantId,...preset}=input;void cmd;
|
|
188
|
+
return this.service.createPresetVariant(id,{...preset,id:variantId});
|
|
189
|
+
}
|
|
214
190
|
if(command==='history'){check(input.expected,'E_AGENT_EXPECTED');const r=await this.service.navigate(id,{expected:input.expected,action:input.action});return {status:'SAVED',expected:identity(r)};}
|
|
215
191
|
if(command==='export'||command==='render'||command==='qa'){
|
|
216
|
-
if(command==='qa'){const output=input.output!==undefined?resolve(input.output):undefined;return bounded(await this.service.runQa(id,{revisionId:current.revisionId,target:input.target??'standalone-browser-draft',...(output?{outputDir:output}:{}),...(input.motionFilmstrip!==undefined?{motionFilmstrip:input.motionFilmstrip}:{}),...(input.recordVideo!==undefined?{recordVideo:input.recordVideo}:{})}),65536);}
|
|
192
|
+
if(command==='qa'){const output=input.output!==undefined?resolve(input.output):undefined;return bounded(await this.service.runQa(id,{revisionId:current.revisionId,target:input.target??'standalone-browser-draft',...(output?{outputDir:output}:{}),...(input.motionFilmstrip!==undefined?{motionFilmstrip:input.motionFilmstrip}:{}),...(input.recordVideo!==undefined?{recordVideo:input.recordVideo}:{}),...(input.fitTargetBudget!==undefined?{fitTargetBudget:Boolean(input.fitTargetBudget)}:{}),...(input.variantId?{variantId:input.variantId}:{}),...(input.confirmReviewed?{confirmReviewed:input.confirmReviewed}:{})}),65536);}
|
|
217
193
|
if(command==='export'&&input.targets!==undefined){
|
|
218
194
|
check(input.format===undefined&&input.output===undefined&&input.target===undefined,'E_AGENT_ARGUMENT');
|
|
219
195
|
check(typeof input.outputDir==='string'&&input.outputDir.length>0,'E_AGENT_OUTPUT');
|
|
220
|
-
return bounded(await this.service.
|
|
196
|
+
if(input.variants!==undefined)return bounded(compactMatrixSummary(await this.service.exportVariantMatrix(id,{revisionId:current.revisionId,targets:input.targets,variants:input.variants,outputDir:input.outputDir,...(input.fitTargetBudget!==undefined?{fitTargetBudget:Boolean(input.fitTargetBudget)}:{}),...(input.confirmReviewed?{confirmReviewed:input.confirmReviewed}:{})})),262144);
|
|
197
|
+
return bounded(await this.service.exportBatch(id,{revisionId:current.revisionId,targets:input.targets,outputDir:input.outputDir,...(input.fitTargetBudget!==undefined?{fitTargetBudget:Boolean(input.fitTargetBudget)}:{}),...(input.variantId?{variantId:input.variantId}:{}),...(input.confirmReviewed?{confirmReviewed:input.confirmReviewed}:{})}),16384);
|
|
221
198
|
}
|
|
222
199
|
check(typeof input.output==='string'&&input.output.length>0,'E_AGENT_OUTPUT');const output=resolve(input.output);let html,archiveBytes,artifactHash,sceneId,manifest;
|
|
223
|
-
if(command==='render'){sceneId=input.sceneId??current.project.base.startScene;check(current.project.scenes.some(scene=>scene.id===sceneId),'E_AGENT_UNKNOWN_SCENE');const render=await this.service.render(id,current.revisionId);html=playableHTML({...current.project,assets:render.assets},await runtimeBundle(),{edit:true,sceneId});const {hash}=await import('./compiler.mjs');artifactHash=hash(html);}else{const artifact=await this.service.export(id,{revisionId:current.revisionId,target:input.target??'standalone-browser-draft'});html=artifact.html;archiveBytes=artifact.archiveBytes;artifactHash=artifact.manifest.artifactHash;manifest=artifact.manifest;if(artifact.archiveBytes){check(output.toLowerCase().endsWith('.zip'),'E_AGENT_OUTPUT');if((input.target??'') === 'mintegral-appgrowth-zip')check(basename(output)===`${id}.zip`,'E_AGENT_OUTPUT');}}
|
|
224
|
-
await mkdir(dirname(output),{recursive:true});await writeFile(output,archiveBytes??html);return bounded({status:command==='render'?'RENDER_READY':'EXPORTED',projectId:id,expected:identity(current),output,artifactHash,target:command==='render'?'editor-preview':input.target??'standalone-browser-draft',...(manifest?{bytes:manifest.bytes,packaging:manifest.packaging}:{}),...(sceneId?{sceneId,edit:true}:{})},4096);
|
|
200
|
+
if(command==='render'){sceneId=input.sceneId??current.project.base.startScene;check(current.project.scenes.some(scene=>scene.id===sceneId),'E_AGENT_UNKNOWN_SCENE');const render=await this.service.render(id,current.revisionId);html=playableHTML({...current.project,assets:render.assets},projectUses3d(current.project)?await runtime3dBundle():await runtimeBundle(),{edit:true,sceneId});const {hash}=await import('./compiler.mjs');artifactHash=hash(html);}else{const artifact=await this.service.export(id,{revisionId:current.revisionId,target:input.target??'standalone-browser-draft',...(input.fitTargetBudget!==undefined?{fitTargetBudget:Boolean(input.fitTargetBudget)}:{}),...(input.variantId?{variantId:input.variantId}:{}),...(input.confirmReviewed?{confirmReviewed:input.confirmReviewed}:{})});html=artifact.html;archiveBytes=artifact.archiveBytes;artifactHash=artifact.manifest.artifactHash;manifest=artifact.manifest;if(artifact.archiveBytes){check(output.toLowerCase().endsWith('.zip'),'E_AGENT_OUTPUT');if((input.target??'') === 'mintegral-appgrowth-zip')check(basename(output)===`${id}.zip`,'E_AGENT_OUTPUT');}else if(input.target&&input.target!=='standalone-browser-draft')check(basename(output)==='index.html','E_AGENT_OUTPUT');}
|
|
201
|
+
await mkdir(dirname(output),{recursive:true});await writeFile(output,archiveBytes??html);return bounded({status:command==='render'?'RENDER_READY':'EXPORTED',projectId:id,expected:identity(current),output,artifactHash,target:command==='render'?'editor-preview':input.target??'standalone-browser-draft',...(manifest?{bytes:manifest.bytes,packaging:manifest.packaging,...(manifest.budgetOptimization?{fitTargetBudget:true}:{})}:{}),...(sceneId?{sceneId,edit:true}:{})},4096);
|
|
225
202
|
}
|
|
226
203
|
throw Error('E_AGENT_COMMAND');
|
|
227
204
|
}
|