@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,561 +0,0 @@
|
|
|
1
|
-
import {Buffer} from 'node:buffer';
|
|
2
|
-
import {readFile} from 'node:fs/promises';
|
|
3
|
-
import {resolve} from 'node:path';
|
|
4
|
-
import {isDeepStrictEqual} from 'node:util';
|
|
5
|
-
import {fileURLToPath,URL} from 'node:url';
|
|
6
|
-
import {capabilities} from './contracts.mjs';
|
|
7
|
-
import {applyOperations,check,exact,identifier} from './document.mjs';
|
|
8
|
-
import {registerSource} from './assets.mjs';
|
|
9
|
-
import {validateAssetPolicy} from './asset-policy.mjs';
|
|
10
|
-
import {reviewOperations,reviewTargets} from './review-targets.mjs';
|
|
11
|
-
import {createProjectIndex,resolveProjectRoles} from './project-index.mjs';
|
|
12
|
-
import {getModule} from './modules/index.mjs';
|
|
13
|
-
import {requireCreativeQa} from './service.mjs';
|
|
14
|
-
import {hash} from './compiler.mjs';
|
|
15
|
-
import {loadCatalog} from './catalog-cache.mjs';
|
|
16
|
-
import {isAudioMime} from './media-validate.mjs';
|
|
17
|
-
|
|
18
|
-
const root=fileURLToPath(new URL('../../../',import.meta.url));
|
|
19
|
-
function projectModule(project){
|
|
20
|
-
const resolution=resolveProjectRoles(createProjectIndex(project));
|
|
21
|
-
return {resolution,descriptor:resolution.module&&resolution.module!=='tora-native-primitives'?getModule(resolution.module):null};
|
|
22
|
-
}
|
|
23
|
-
const collections=['scenes','components','variables','gameplay','events','eventBindings','assets'];
|
|
24
|
-
const string={type:'string'};
|
|
25
|
-
const strings={type:'array',items:string};
|
|
26
|
-
const object=(properties,required=[])=>({type:'object',properties,required,additionalProperties:false});
|
|
27
|
-
const editSchema=object({
|
|
28
|
-
noteId:string,operations:{type:'array',items:{type:'object'}},scope:strings,
|
|
29
|
-
imports:{type:'array',items:object({catalogId:string,assetId:string},['catalogId','assetId'])},
|
|
30
|
-
changes:{type:'object'},target:string,
|
|
31
|
-
},['noteId']);
|
|
32
|
-
const definition=(name,description,properties,required)=>({type:'function',function:{name,description,parameters:object(properties,required)}});
|
|
33
|
-
const toolDefinitions=[
|
|
34
|
-
definition('inspect','Inspect the working baseline. No arguments returns the project overview. Search record IDs and labels, or read exact records and their referring IDs. Use collection/offset for paging.',{
|
|
35
|
-
ids:strings,search:string,collection:{enum:collections,type:'string'},offset:{type:'integer',minimum:0},previewDigest:string,
|
|
36
|
-
}),
|
|
37
|
-
definition('contracts','List available contracts and supported native operations, or get descriptors by name, including actions, events and operations.',{names:strings}),
|
|
38
|
-
definition('audio','Inspect playable audio routing (bindings, event IDs, conditions, audio assets, bus and volume) and importable licensed WAV cues. Media bytes stay local.',{previewDigest:string}),
|
|
39
|
-
definition('layout','Inspect visible Harvest loss-screen controls and text from a real packaged landscape playthrough. Returns component IDs, text bounds, clipping, and the offset from vertical center between the panel top and install button. Omit previewDigest for the baseline.',{previewDigest:string}),
|
|
40
|
-
definition('preview','Propose all notes in one batch against the original revision. One edit per note. For a pinned note pass changes keyed by authorized field. For unpinned notes optionally use target and changes from the allowed list, or pass native operations and scope listing every changed record ID, including new IDs. Optional imports stage catalog WAVs under assetId. Audio routing supports {kind:"setBindingAudio",bindingId,assetId,replaceBehaviorId?}; omit replaceBehaviorId to add an additional cue. The audio tool describes the required scope. You may append another native action using {kind:"appendAction",bindingId,action}. The preview can be revised. Return its digest with your final noteResults.',{
|
|
41
|
-
edits:{type:'array',items:editSchema},
|
|
42
|
-
},['edits']),
|
|
43
|
-
definition('exercise','Package a validated preview, run Creative QA, and exercise supported audio outcomes. Returns server evidence IDs for final noteResults verification, and actual checks completed. Call after preview.',{previewDigest:string},['previewDigest']),
|
|
44
|
-
definition('qa','Run deterministic static, acoustic, four-viewport layout and primary-interaction QA on the baseline or a packaged preview. Returns exact component defects and labeled screenshot paths. Call this to diagnose an E_CREATIVE_QA rejection.',{previewDigest:string}),
|
|
45
|
-
];
|
|
46
|
-
|
|
47
|
-
function bounded(value,limit=16384){
|
|
48
|
-
check(Buffer.byteLength(JSON.stringify(value))<=limit,'E_AGENT_NARROW_SCOPE');
|
|
49
|
-
return value;
|
|
50
|
-
}
|
|
51
|
-
const byId=(records,id)=>records.find(record=>record.id===id);
|
|
52
|
-
const indexes=new WeakMap();
|
|
53
|
-
function indexProject(project){
|
|
54
|
-
if(!indexes.has(project))indexes.set(project,createProjectIndex(project));
|
|
55
|
-
return indexes.get(project);
|
|
56
|
-
}
|
|
57
|
-
function changedRecords(before,after){
|
|
58
|
-
const first=indexProject(before),next=indexProject(after);
|
|
59
|
-
const ids=new Set([...first.entries(),...next.entries()].map(([id])=>id));
|
|
60
|
-
const changed=[...ids].filter(id=>!isDeepStrictEqual(first.record(id),next.record(id)));
|
|
61
|
-
if(!isDeepStrictEqual(before.base,after.base))changed.push('$project.base');
|
|
62
|
-
return changed;
|
|
63
|
-
}
|
|
64
|
-
function sanitizedRecord(collection,record){
|
|
65
|
-
if(collection==='assets')return {id:record.id,hash:record.hash,mime:record.mime,bytes:record.bytes};
|
|
66
|
-
return record;
|
|
67
|
-
}
|
|
68
|
-
function inspect(project,{ids,search,collection,offset=0}){
|
|
69
|
-
const index=indexProject(project);
|
|
70
|
-
if(ids!==undefined){
|
|
71
|
-
check(Array.isArray(ids)&&ids.length>0&&ids.length<=16&&ids.every(id=>index.record(id)),'E_AGENT_UNKNOWN_RECORD');
|
|
72
|
-
return bounded({records:ids.map(id=>{
|
|
73
|
-
const {collection,record}=index.record(id);
|
|
74
|
-
return {collection,...sanitizedRecord(collection,record),referencedBy:index.referencedBy(id)};
|
|
75
|
-
})});
|
|
76
|
-
}
|
|
77
|
-
if(collection!==undefined||search!==undefined){
|
|
78
|
-
check((collection===undefined||collections.includes(collection))&&(search===undefined||typeof search==='string'&&search.length<=128)&&Number.isSafeInteger(offset)&&offset>=0,'E_AGENT_ARGUMENT');
|
|
79
|
-
const needle=(search??'').toLowerCase();
|
|
80
|
-
const matches=[...index.entries()].map(([,item])=>item).filter(item=>(!collection||item.collection===collection)&&[item.record.id,item.record.label,item.record.kind,item.record.parameters?.text].some(value=>typeof value==='string'&&value.toLowerCase().includes(needle)));
|
|
81
|
-
return {total:matches.length,matches:matches.slice(offset,offset+40).map(({collection,record})=>({collection,id:record.id,label:record.label,kind:record.kind}))};
|
|
82
|
-
}
|
|
83
|
-
return {goal:project.creativeBrief.goal,base:{width:project.base.width,height:project.base.height,startScene:project.base.startScene},scenes:project.scenes,counts:Object.fromEntries(collections.map(c=>[c,project[c].length]))};
|
|
84
|
-
}
|
|
85
|
-
const blockedOperations=new Set(['registerAsset','setStore']);
|
|
86
|
-
function contractInfo(names){
|
|
87
|
-
const cap=capabilities();
|
|
88
|
-
const operations=cap.operations.filter(name=>!blockedOperations.has(name)).concat('appendAction','setBindingAudio','adjustTarget');
|
|
89
|
-
if(!names?.length)return {components:Object.keys(cap.contracts),behaviors:Object.keys(cap.behaviors),operations,lookups:['events','actions','conditions','limits']};
|
|
90
|
-
check(Array.isArray(names)&&names.length<=12,'E_AGENT_CONTRACT_SCOPE');
|
|
91
|
-
const registry={...cap.contracts,...cap.behaviors,operations,events:cap.events,actions:cap.actions,conditions:cap.conditions,limits:cap.limits};
|
|
92
|
-
for(const name of names)check(typeof name==='string'&&Object.hasOwn(registry,name),'E_AGENT_UNKNOWN_CONTRACT');
|
|
93
|
-
return bounded(Object.fromEntries(names.map(name=>[name,registry[name]])));
|
|
94
|
-
}
|
|
95
|
-
export async function catalogAudio(){
|
|
96
|
-
return (await loadCatalog()).audioFiles;
|
|
97
|
-
}
|
|
98
|
-
function audioRoutes(project){
|
|
99
|
-
const assets=new Map(project.assets.map(a=>[a.id,a]));
|
|
100
|
-
return project.gameplay.filter(b=>b.kind==='audio').map(behavior=>{
|
|
101
|
-
const component=byId(project.components,behavior.componentId);
|
|
102
|
-
const asset=assets.get(component?.assetSlots[0]?.assetId);
|
|
103
|
-
const bindings=project.eventBindings.filter(binding=>binding.actions.some(a=>a.kind==='playAudio'&&a.behaviorId===behavior.id))
|
|
104
|
-
.map(({id,eventId,condition})=>({id,eventId,...(condition?{condition}:{})}));
|
|
105
|
-
return {behaviorId:behavior.id,componentId:behavior.componentId,assetId:asset?.id,assetHash:asset?.hash,...behavior.parameters,bindings};
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
async function stageAudio(service,id,imports){
|
|
109
|
-
check(Array.isArray(imports)&&imports.length<=8,'E_REVIEW_IMPORT');
|
|
110
|
-
if(!imports.length)return [];
|
|
111
|
-
const catalog=await catalogAudio();
|
|
112
|
-
const operations=[];
|
|
113
|
-
for(const item of imports){
|
|
114
|
-
check(exact(item,['catalogId','assetId'])&&identifier(item.assetId),'E_REVIEW_IMPORT');
|
|
115
|
-
const choice=catalog.find(cue=>cue.catalogId===item.catalogId);
|
|
116
|
-
check(choice,'E_REVIEW_IMPORT');
|
|
117
|
-
const {source,file}=choice;
|
|
118
|
-
const provenance={origin:'third-party-free',sourceId:source.id,sourceFile:file.path,sourceHash:file.sha256,author:source.author,license:source.license,sourceUrl:source.sourceUrl,styleFamily:source.styleFamily};
|
|
119
|
-
const data=(await readFile(resolve(root,file.file))).toString('base64');
|
|
120
|
-
const receipt=validateAssetPolicy({mime:file.mime,data,provenance},{role:'audio'});
|
|
121
|
-
const rights=[source.author+', '+source.license+'. '+source.sourceUrl,receipt.attribution].filter(Boolean).join('\n');
|
|
122
|
-
const asset=await registerSource(resolve(service.store.root,id),{id:item.assetId,mime:file.mime,data,rights}),record={...asset};delete record.optimization;
|
|
123
|
-
operations.push({kind:'registerAsset',asset:{...record,provenance:JSON.stringify(receipt)}});
|
|
124
|
-
}
|
|
125
|
-
return operations;
|
|
126
|
-
}
|
|
127
|
-
/** Attach a cue to an existing authored event without copying unrelated actions or
|
|
128
|
-
* changing the signal used by any other event. Reuse a bound one-shot where possible. */
|
|
129
|
-
function routeAudio(project,bindings,routes,op,assetIds){
|
|
130
|
-
check(exact(op,['kind','bindingId','assetId','replaceBehaviorId'])&&assetIds.has(op.assetId),'E_REVIEW_AUDIO_ROUTE');
|
|
131
|
-
const binding=bindings.get(op.bindingId);
|
|
132
|
-
check(binding,'E_NATIVE_BINDING');
|
|
133
|
-
const oldIndex=op.replaceBehaviorId===undefined?-1:binding.actions.findIndex(action=>action.kind==='playAudio'&&action.behaviorId===op.replaceBehaviorId);
|
|
134
|
-
check(op.replaceBehaviorId===undefined||oldIndex!==-1,'E_REVIEW_AUDIO_ROUTE');
|
|
135
|
-
const oldRoute=routes.find(route=>route.behaviorId===op.replaceBehaviorId);
|
|
136
|
-
const parameters=oldRoute?.parameters??{bus:'sfx',loop:false,volume:.4,frequency:660,seconds:.15};
|
|
137
|
-
let route=routes.find(item=>item.assetId===op.assetId&&!item.parameters.loop&&item.parameters.volume>0);
|
|
138
|
-
const ops=[];
|
|
139
|
-
if(!route){
|
|
140
|
-
const componentId=binding.id+'.cue',behaviorId=componentId+'.play';
|
|
141
|
-
check(identifier(behaviorId)&&!project.components.some(c=>c.id===componentId)&&!routes.some(r=>r.behaviorId===behaviorId),'E_REVIEW_AUDIO_ROUTE');
|
|
142
|
-
const sceneId=project.components.find(c=>c.id===oldRoute?.componentId)?.sceneId??project.base.startScene;
|
|
143
|
-
route={componentId,behaviorId,parameters,assetId:op.assetId};
|
|
144
|
-
routes.push(route);
|
|
145
|
-
ops.push({kind:'createComponent',component:{id:componentId,contract:'native.group.v1',sceneId,parameters:{visible:false},assetSlots:[{slotId:'source',assetId:op.assetId}]}},
|
|
146
|
-
{kind:'putBehavior',behavior:{id:behaviorId,componentId,kind:'audio',parameters}});
|
|
147
|
-
}
|
|
148
|
-
const actions=[...binding.actions];
|
|
149
|
-
const play={kind:'playAudio',behaviorId:route.behaviorId};
|
|
150
|
-
if(oldIndex>=0)actions[oldIndex]=play;
|
|
151
|
-
else {
|
|
152
|
-
check(!actions.some(action=>isDeepStrictEqual(action,play)),'E_REVIEW_NO_CHANGE');
|
|
153
|
-
actions.push(play);
|
|
154
|
-
}
|
|
155
|
-
const next={...binding,actions};
|
|
156
|
-
bindings.set(next.id,next);
|
|
157
|
-
return [...ops,{kind:'putBinding',binding:next}];
|
|
158
|
-
}
|
|
159
|
-
function expandOperations(project,operations,imports){
|
|
160
|
-
check(Array.isArray(operations)&&operations.length<=128,'E_NATIVE_OPERATIONS');
|
|
161
|
-
const bindings=new Map(project.eventBindings.map(b=>[b.id,b]));
|
|
162
|
-
const assetIds=new Set([...project.assets,...imports.map(op=>op.asset)].filter(a=>isAudioMime(a.mime)).map(a=>a.id));
|
|
163
|
-
const routes=project.gameplay.filter(b=>b.kind==='audio').map(b=>({behaviorId:b.id,componentId:b.componentId,parameters:b.parameters,assetId:byId(project.components,b.componentId)?.assetSlots[0]?.assetId}));
|
|
164
|
-
return operations.flatMap(op=>{
|
|
165
|
-
check(op&&typeof op.kind==='string'&&!blockedOperations.has(op.kind),'E_REVIEW_OPERATION');
|
|
166
|
-
if(op.kind==='adjustTarget'){
|
|
167
|
-
const target=reviewTargets(project).targets.find(t=>t.id===op.target);
|
|
168
|
-
check(target&&exact(op,['kind','target','changes']),'E_REVIEW_SCOPE');
|
|
169
|
-
return reviewOperations(project,target.id,target.fields.filter(field=>!field.confirm).map(field=>field.id),op.changes,project).operations;
|
|
170
|
-
}
|
|
171
|
-
if(op.kind==='setBindingAudio')return routeAudio(project,bindings,routes,op,assetIds);
|
|
172
|
-
if(op.kind==='appendAction'){
|
|
173
|
-
check(exact(op,['kind','bindingId','action'])&&bindings.has(op.bindingId),'E_NATIVE_BINDING');
|
|
174
|
-
const original=bindings.get(op.bindingId);
|
|
175
|
-
op={kind:'putBinding',binding:{...original,actions:[...original.actions,op.action]}};
|
|
176
|
-
}
|
|
177
|
-
if(op.kind==='putBinding'&&op.binding)bindings.set(op.binding.id,op.binding);
|
|
178
|
-
if(op.kind==='deleteBinding')bindings.delete(op.id);
|
|
179
|
-
return [op];
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
function preserveSharedArt(before,after){
|
|
183
|
-
const images=new Set(before.assets.filter(a=>a.mime.startsWith('image/')).map(a=>a.id));
|
|
184
|
-
const counts=new Map();
|
|
185
|
-
for(const component of before.components){
|
|
186
|
-
const assetId=component.assetSlots[0]?.assetId;
|
|
187
|
-
if(images.has(assetId))counts.set(assetId,(counts.get(assetId)??0)+1);
|
|
188
|
-
}
|
|
189
|
-
for(const component of before.components){
|
|
190
|
-
const source=component.assetSlots[0]?.assetId;
|
|
191
|
-
if(counts.get(source)>1){
|
|
192
|
-
const retained=byId(after.components,component.id);
|
|
193
|
-
check(!retained||retained.assetSlots[0]?.assetId===source,'E_REVIEW_SHARED_ART_SCOPE');
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// Keep candidate evidence independent of the model's description of its own edits.
|
|
199
|
-
function recordEvidence(before,after,id){
|
|
200
|
-
const a=indexProject(before).record(id),b=indexProject(after).record(id);
|
|
201
|
-
if(!a)return 'Added '+id;
|
|
202
|
-
if(!b)return 'Removed '+id;
|
|
203
|
-
const hints=[];
|
|
204
|
-
function collect(first,next,path){
|
|
205
|
-
if(hints.length>=3||isDeepStrictEqual(first,next))return;
|
|
206
|
-
if(first&&next&&typeof first==='object'&&typeof next==='object'){
|
|
207
|
-
for(const key of new Set([...Object.keys(first),...Object.keys(next)]))collect(first[key],next[key],[...path,key]);
|
|
208
|
-
}else{
|
|
209
|
-
const value=typeof next==='object'?undefined:JSON.stringify(next);
|
|
210
|
-
hints.push(path.join('.')+(value&&value.length<=110?' = '+value:''));
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
collect(sanitizedRecord(a.collection,a.record),sanitizedRecord(b.collection,b.record),[]);
|
|
214
|
-
return 'Changed '+id+(hints.length?' ('+hints.join(', ')+')':'');
|
|
215
|
-
}
|
|
216
|
-
function modelText(answer,key){
|
|
217
|
-
check(exact(answer,[key])&&typeof answer[key]==='string'&&answer[key].trim()&&answer[key].length<=500,'E_REVIEW_MODEL_RESPONSE');
|
|
218
|
-
return answer[key].trim();
|
|
219
|
-
}
|
|
220
|
-
function resumedPreview(progress,digest){
|
|
221
|
-
const calls=new Map();
|
|
222
|
-
for(const message of progress?.messages??[]){
|
|
223
|
-
for(const call of message.tool_calls??[])if(call.function.name==='preview')calls.set(call.id,call.function.arguments);
|
|
224
|
-
if(message.role==='tool'&&calls.has(message.tool_call_id)){
|
|
225
|
-
try{if(JSON.parse(message.content).previewDigest===digest)return JSON.parse(calls.get(message.tool_call_id));}catch{/* Ignore unrelated incomplete calls. */}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// Only this locally authored probe is evaluated in the browser. The model supplies a
|
|
231
|
-
// preview digest, and receives measured bounds and strings from the packaged canvas.
|
|
232
|
-
async function inspectHarvestLayout(page){
|
|
233
|
-
const project=await page.evaluate(()=>JSON.parse(globalThis.document.getElementById('project').textContent));
|
|
234
|
-
const {resolution}=projectModule(project),panelId=resolution.roles?.outcomePanel?.componentId,ctaId=resolution.roles?.primaryCta?.componentId;
|
|
235
|
-
const replay=project.components.find(component=>component.id==='harvest.replay'||component.id==='salvage.replay')?.id;
|
|
236
|
-
return page.evaluate(({panelId,ctaId,replay})=>{
|
|
237
|
-
const project=JSON.parse(globalThis.document.getElementById('project').textContent);
|
|
238
|
-
const runtime=globalThis.toraRuntime,state=runtime.state();
|
|
239
|
-
const components=new Map(project.components.map(c=>[c.id,c]));
|
|
240
|
-
const responsive=new Map(project.gameplay.filter(b=>b.kind==='responsive-layout').map(b=>[b.componentId,b.parameters]));
|
|
241
|
-
function bounds(id){
|
|
242
|
-
const chain=[];
|
|
243
|
-
let c=components.get(id);
|
|
244
|
-
while(c){chain.unshift(c);c=components.get(c.parentId);}
|
|
245
|
-
let matrix=new globalThis.DOMMatrix();
|
|
246
|
-
for(const node of chain){
|
|
247
|
-
const t=[...(state.components[node.id]?.transform??node.transform)];
|
|
248
|
-
const layout=responsive.get(node.id);
|
|
249
|
-
if(state.viewport.landscape&&layout){
|
|
250
|
-
t[4]+=layout.x-node.transform[4];t[5]+=layout.y-node.transform[5];
|
|
251
|
-
t[0]*=layout.scaleX;t[1]*=layout.scaleX;t[2]*=layout.scaleY;t[3]*=layout.scaleY;
|
|
252
|
-
}
|
|
253
|
-
matrix=matrix.multiply(new globalThis.DOMMatrix(t));
|
|
254
|
-
}
|
|
255
|
-
const props={...chain.at(-1).parameters,...state.components[id]?.parameters};
|
|
256
|
-
const points=[[0,0],[props.width,0],[0,props.height],[props.width,props.height]].map(([x,y])=>matrix.transformPoint({x,y}));
|
|
257
|
-
return {top:Math.min(...points.map(p=>p.y)),bottom:Math.max(...points.map(p=>p.y)),left:Math.min(...points.map(p=>p.x)),right:Math.max(...points.map(p=>p.x))};
|
|
258
|
-
}
|
|
259
|
-
const ids=project.components.filter(c=>c.id===panelId||c.contract==='native.text.v1'||c.id===ctaId||c.id===replay).map(c=>c.id);
|
|
260
|
-
const audit=runtime.auditViewport(ids),missing=new Set(audit.missing);
|
|
261
|
-
const visible=ids.filter(id=>!missing.has(id)).map(id=>{
|
|
262
|
-
const raw=state.components[id]?.parameters.text??components.get(id).parameters.text;
|
|
263
|
-
const text=raw?.replace(/\{\{([a-z0-9_.-]+)\}\}/g,(_,key)=>String(state.variables[key]));
|
|
264
|
-
return {id,bounds:bounds(id),...(text?{text}:{})};
|
|
265
|
-
});
|
|
266
|
-
const panel=visible.find(c=>c.id===panelId),cta=visible.find(c=>c.id===ctaId);
|
|
267
|
-
const contentCenter=panel&&cta?(panel.bounds.top+cta.bounds.top)/2:null;
|
|
268
|
-
for(const label of visible.filter(c=>c.text&&contentCenter!==null))label.verticalOffset=(label.bounds.top+label.bounds.bottom)/2-contentCenter;
|
|
269
|
-
return {viewport:audit.viewport,clipped:audit.issues.map(issue=>issue.id),contentCenter,visible};
|
|
270
|
-
},{panelId,ctaId,replay});
|
|
271
|
-
}
|
|
272
|
-
const mentionsLayout=text=>/\b(landscape|horizontal|sideways)\b/i.test(text)&&/clip|cut off|center|centre|inset|overflow|margin/i.test(text);
|
|
273
|
-
async function outcomeEvidence(project,candidate,artifact,notes,exercise,intent,{browser,verifyCache,onReceipt,scenario}={}){
|
|
274
|
-
const routes=audioRoutes(project),{resolution,descriptor}=projectModule(project);
|
|
275
|
-
if(resolution.status!=='resolved'||!descriptor?.outcomeAudio)return [];
|
|
276
|
-
const finalBinding=resolution.roles.winEvent.bindingId,deadlineBinding=resolution.roles.timeoutEvent.bindingId;
|
|
277
|
-
const tiedTo=(routes,binding)=>routes.filter(route=>route.bindings.some(b=>b.id===binding));
|
|
278
|
-
const oldWin=tiedTo(routes,finalBinding)[0];
|
|
279
|
-
const feedback=notes.map(note=>note.note.toLowerCase()+(note.moment==='end-card'?' win':'')+(note.moment==='timeout'?' loss':''));
|
|
280
|
-
const hasAudio=text=>/\b(sound|music|audio|cue|jingle|sfx)s?\b/.test(text);
|
|
281
|
-
const win=text=>/\b(win|wins|won|winning|victory|complet\w*|success|payoff)\b/.test(text);
|
|
282
|
-
const loss=text=>/\b(loss|lose|lost|losing|fail\w*|timeout)\b/.test(text);
|
|
283
|
-
const typed=intent?.action==='transferOutcomeCue';
|
|
284
|
-
const both=typed||feedback.some(text=>hasAudio(text)&&win(text)&&loss(text));
|
|
285
|
-
const needWin=typed||feedback.some(text=>hasAudio(text)&&win(text));
|
|
286
|
-
const needLoss=typed||feedback.some(text=>hasAudio(text)&&loss(text));
|
|
287
|
-
if(!needWin&&!needLoss)return [];
|
|
288
|
-
const nextRoutes=audioRoutes(candidate);
|
|
289
|
-
const audioChanged=!isDeepStrictEqual(routes,nextRoutes);
|
|
290
|
-
check(audioChanged,'E_REVIEW_AUDIO_UNCHANGED');
|
|
291
|
-
if(typed){
|
|
292
|
-
for(const route of routes.filter(route=>route.behaviorId!==oldWin?.behaviorId)){
|
|
293
|
-
check(isDeepStrictEqual(route,nextRoutes.find(next=>next.behaviorId===route.behaviorId)),'E_REVIEW_ORDINARY_AUDIO_CHANGED');
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
const outcomes=[...(needWin?['win']:[]),...(needLoss?['loss']:[])];
|
|
297
|
-
let result;
|
|
298
|
-
if(exercise)result=await exercise(artifact,{outcomes,accelerateIdle:true});
|
|
299
|
-
else{
|
|
300
|
-
const {exercise:exerciseOutcome,checkerVersion}=await descriptor.outcomeAudio();
|
|
301
|
-
const key=verifyCache.receiptKey({artifactHash:artifact.manifest.artifactHash,checkerVersion,kind:'outcome-audio',host:'unity-ads-ua-playable',scenario:scenario+':'+outcomes.join(',')});
|
|
302
|
-
result=await verifyCache.read(key);await onReceipt({type:'cache',stage:'outcome-audio',hit:Boolean(result)});
|
|
303
|
-
if(!result){result=await exerciseOutcome(artifact,{outcomes,accelerateIdle:true,browser:await browser()});await verifyCache.write(key,result);}
|
|
304
|
-
}
|
|
305
|
-
const evidence=[];
|
|
306
|
-
for(const outcome of outcomes){
|
|
307
|
-
const played=result[outcome]?.started?.filter(cue=>cue.assetHash&&cue.level>0&&!cue.loop)??[];
|
|
308
|
-
const afterOutcome=played.filter(cue=>cue.at>=result[outcome].outcomeAt);
|
|
309
|
-
const opposite=outcome==='win'?'loss':'win';
|
|
310
|
-
const otherStarts=result[opposite]?.started??[];
|
|
311
|
-
const isMove=typed||both&&oldWin&&feedback.some(text=>/\b(mov\w*|swap|transfer|instead)\b/.test(text)&&win(text)&&loss(text));
|
|
312
|
-
const needsNew=typed?intent.constraints.replacementMustBeNew:feedback.some(text=>/\bnew\b/.test(text)&&win(text));
|
|
313
|
-
const oldHashes=new Set(project.assets.map(a=>a.hash));
|
|
314
|
-
let cue;
|
|
315
|
-
if(isMove){
|
|
316
|
-
const fits=outcome==='win'?(item=>item.assetHash!==oldWin.assetHash&&(!needsNew||!oldHashes.has(item.assetHash))):(item=>item.assetHash===oldWin.assetHash);
|
|
317
|
-
const matches=afterOutcome.filter(fits);
|
|
318
|
-
check(matches.length===1,'E_REVIEW_OUTCOME_AUDIO_MISMATCH');
|
|
319
|
-
[cue]=matches;
|
|
320
|
-
check(played.filter(item=>item.assetHash===cue.assetHash).length===1,'E_REVIEW_OUTCOME_AUDIO_COUNT');
|
|
321
|
-
check(!otherStarts.some(item=>item.assetHash===cue.assetHash&&item.level>0),'E_REVIEW_OUTCOME_AUDIO_MISMATCH');
|
|
322
|
-
}else{
|
|
323
|
-
const expected=tiedTo(nextRoutes,outcome==='win'?finalBinding:deadlineBinding);
|
|
324
|
-
const matches=afterOutcome.filter(item=>expected.some(route=>route.assetHash===item.assetHash));
|
|
325
|
-
// An authored outcome can have its own conditional binding rather than use
|
|
326
|
-
// the module's default. The actual ending is still exercised in that case.
|
|
327
|
-
cue=matches.at(-1)??afterOutcome.at(-1);
|
|
328
|
-
check(cue,'E_REVIEW_OUTCOME_AUDIO_MISSING');
|
|
329
|
-
}
|
|
330
|
-
evidence.push((outcome==='win'?'Win':'Loss')+' playback started '+cue.assetId+' in the packaged playable.');
|
|
331
|
-
}
|
|
332
|
-
return evidence;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/** Local, baseline-bound tools for the feedback model. No tool can publish a working revision. */
|
|
336
|
-
export function createReviewTools({service,id,request,project,proposalId,progress,exercise,intent,typed=Boolean(intent),onReceipt,qaRunner}){
|
|
337
|
-
const emit=async event=>{if(onReceipt)await onReceipt(event);};
|
|
338
|
-
const baseline=request.expected;
|
|
339
|
-
const rawNotes=request.notes??[request];
|
|
340
|
-
const normalized=rawNotes.map((note,index)=>({...note,id:String(index+1)}));
|
|
341
|
-
const previews=new Map();
|
|
342
|
-
const layouts=new Map();
|
|
343
|
-
const artifacts=new Map();
|
|
344
|
-
const qaReports=new Map();
|
|
345
|
-
let browserPromise;
|
|
346
|
-
const sharedBrowser=()=>browserPromise??=import('playwright').then(({chromium})=>chromium.launch({headless:true}));
|
|
347
|
-
const dispose=async()=>{if(browserPromise)(await browserPromise.catch(()=>null))?.close();};
|
|
348
|
-
|
|
349
|
-
async function preview({edits}){
|
|
350
|
-
check(Array.isArray(edits)&&edits.length===normalized.length&&new Set(edits.map(e=>e?.noteId)).size===edits.length,'E_REVIEW_NOTE_COVERAGE');
|
|
351
|
-
let current=project;
|
|
352
|
-
const operations=[],perNote=new Map();
|
|
353
|
-
const targets=reviewTargets(project).targets;
|
|
354
|
-
for(const note of normalized){
|
|
355
|
-
const edit=edits.find(e=>e.noteId===note.id);
|
|
356
|
-
check(edit&&exact(edit,['noteId','changes','target','operations','scope','imports']),'E_REVIEW_SCOPE');
|
|
357
|
-
let nextOps;
|
|
358
|
-
if(edit.changes!==undefined){
|
|
359
|
-
check(exact(edit,['noteId','target','changes']),'E_REVIEW_SCOPE');
|
|
360
|
-
const targetId=note.target??edit.target;
|
|
361
|
-
check(edit.target===undefined||edit.target===targetId,'E_REVIEW_SCOPE');
|
|
362
|
-
const target=targets.find(item=>item.id===targetId);
|
|
363
|
-
check(target&&(note.moment==='live'||note.moment===target.moment),'E_REVIEW_SCOPE');
|
|
364
|
-
const fields=note.target!==null?note.fields:target.fields.filter(field=>!field.confirm).map(field=>field.id);
|
|
365
|
-
nextOps=reviewOperations(current,targetId,fields,edit.changes,project).operations;
|
|
366
|
-
}else{
|
|
367
|
-
check((note.target===null||intent?.action==='transferOutcomeCue')&&exact(edit,['noteId','operations','scope','imports']),'E_REVIEW_SCOPE');
|
|
368
|
-
check(Array.isArray(edit.scope)&&edit.scope.length>0&&edit.scope.every(key=>identifier(key)||key==='$project.base'),'E_REVIEW_SCOPE');
|
|
369
|
-
const assets=await stageAudio(service,id,edit.imports??[]);
|
|
370
|
-
nextOps=[...assets,...expandOperations(current,edit.operations,assets)];
|
|
371
|
-
}
|
|
372
|
-
const next=applyOperations(current,nextOps).project;
|
|
373
|
-
const changed=changedRecords(current,next);
|
|
374
|
-
check(changed.length>0,'E_REVIEW_NO_CHANGE');
|
|
375
|
-
if(edit.operations!==undefined){
|
|
376
|
-
check(changed.every(key=>edit.scope.includes(key)),'E_REVIEW_OUTSIDE_SCOPE');
|
|
377
|
-
preserveSharedArt(current,next);
|
|
378
|
-
}
|
|
379
|
-
// A second note cannot overwrite the result authorized by an earlier pinned note.
|
|
380
|
-
for(const [otherId,otherChanged] of perNote){
|
|
381
|
-
if(note.target!==null||normalized.find(n=>n.id===otherId).target!==null){
|
|
382
|
-
check(!otherChanged.some(key=>changed.includes(key)),'E_REVIEW_CONFLICT');
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
perNote.set(note.id,changed);
|
|
386
|
-
operations.push(...nextOps);
|
|
387
|
-
current=next;
|
|
388
|
-
}
|
|
389
|
-
const native=await service.preview(id,{format:'tora-transaction-1',expected:baseline,operations});
|
|
390
|
-
check(isDeepStrictEqual(native.project,current),'E_REVIEW_SCOPE');
|
|
391
|
-
const changedIds=changedRecords(project,current);
|
|
392
|
-
check(changedIds.length&&[...perNote.values()].every(keys=>keys.every(key=>changedIds.includes(key))),'E_REVIEW_CONFLICT');
|
|
393
|
-
const receipts=Object.fromEntries([...perNote].map(([noteId,keys])=>[noteId,keys.map(key=>recordEvidence(project,current,key))]));
|
|
394
|
-
const previous=previews.get(native.previewDigest);
|
|
395
|
-
if(!isDeepStrictEqual(previous?.perNote,perNote)){
|
|
396
|
-
previews.set(native.previewDigest,{project:current,operations,changedIds,receipts,perNote});
|
|
397
|
-
}
|
|
398
|
-
return bounded({previewDigest:native.previewDigest,notes:Object.fromEntries(perNote),evidence:receipts,warnings:native.effects.warnings});
|
|
399
|
-
}
|
|
400
|
-
async function getPreview(digest){
|
|
401
|
-
check(typeof digest==='string'&&/^sha256:[0-9a-f]{64}$/.test(digest),'E_NATIVE_PREVIEW_STALE');
|
|
402
|
-
if(!previews.has(digest)){
|
|
403
|
-
const previous=resumedPreview(progress,digest);
|
|
404
|
-
check(previous,'E_NATIVE_PREVIEW_STALE');
|
|
405
|
-
check((await preview(previous)).previewDigest===digest,'E_NATIVE_PREVIEW_STALE');
|
|
406
|
-
}
|
|
407
|
-
return previews.get(digest);
|
|
408
|
-
}
|
|
409
|
-
async function packageArtifact(digest){
|
|
410
|
-
if(!artifacts.has(digest)){
|
|
411
|
-
const build=async()=>{
|
|
412
|
-
const selected=digest?{...(await getPreview(digest)).project,revisionId:'rev-'+proposalId}:project;
|
|
413
|
-
const started=Date.now();
|
|
414
|
-
try{const artifact=await service.build(id,selected,'unity-ads-ua-playable');await emit({type:'cache',stage:'build',hit:artifact.cacheHit});return artifact;}
|
|
415
|
-
finally{await emit({type:'compilation',durationMs:Date.now()-started});}
|
|
416
|
-
};
|
|
417
|
-
artifacts.set(digest,build().catch(error=>{artifacts.delete(digest);throw error;}));
|
|
418
|
-
}
|
|
419
|
-
return artifacts.get(digest);
|
|
420
|
-
}
|
|
421
|
-
async function creativeQa(digest){
|
|
422
|
-
if(!qaReports.has(digest)){
|
|
423
|
-
const run=async()=>{
|
|
424
|
-
const artifact=await packageArtifact(digest),outputDir=resolve(service.store.root,id,'qa','reviews',proposalId,digest??'baseline');
|
|
425
|
-
if(qaRunner)return qaRunner({html:artifact.html,outputDir,network:'unity-ads-ua-playable'});
|
|
426
|
-
const {runCreativeQa,CREATIVE_QA_CHECKER_VERSION,CREATIVE_QA_FORMAT}=await import('./creative-qa.mjs');
|
|
427
|
-
const key=service.verifyCache.receiptKey({artifactHash:artifact.manifest.artifactHash,checkerVersion:CREATIVE_QA_CHECKER_VERSION,kind:'creative-qa',host:'unity-ads-ua-playable',scenario:digest??'baseline'});
|
|
428
|
-
let report=await service.verifyCache.read(key),valid=report?.format===CREATIVE_QA_FORMAT&&Array.isArray(report.screenshots);
|
|
429
|
-
if(valid)for(const screenshot of report.screenshots){
|
|
430
|
-
try{const bytes=await readFile(resolve(outputDir,screenshot.path));if(hash(bytes)!==screenshot.sha256){valid=false;break;}}catch{valid=false;break;}
|
|
431
|
-
}
|
|
432
|
-
await emit({type:'cache',stage:'creative-qa',hit:valid});
|
|
433
|
-
if(!valid){report=await runCreativeQa({html:artifact.html,outputDir,network:'unity-ads-ua-playable',browser:await sharedBrowser()});await service.verifyCache.write(key,report);}
|
|
434
|
-
return report;
|
|
435
|
-
};
|
|
436
|
-
qaReports.set(digest,run().catch(error=>{qaReports.delete(digest);throw error;}));
|
|
437
|
-
}
|
|
438
|
-
return qaReports.get(digest);
|
|
439
|
-
}
|
|
440
|
-
async function layout(digest){
|
|
441
|
-
const {descriptor}=projectModule(project);
|
|
442
|
-
check(descriptor?.supportsLandscapeReview,'E_REVIEW_SCENARIO_UNAVAILABLE');
|
|
443
|
-
if(layouts.has(digest))return layouts.get(digest);
|
|
444
|
-
const artifact=await packageArtifact(digest);
|
|
445
|
-
const started=Date.now();
|
|
446
|
-
let result;
|
|
447
|
-
try{
|
|
448
|
-
if(exercise){const report=await exercise(artifact,{outcomes:['loss'],landscape:true,inspectOutcome:inspectHarvestLayout,accelerateIdle:true});result=report.loss?.layout;}
|
|
449
|
-
else{
|
|
450
|
-
const {exercise:exerciseOutcome,checkerVersion}=await descriptor.outcomeAudio();
|
|
451
|
-
const key=service.verifyCache.receiptKey({artifactHash:artifact.manifest.artifactHash,checkerVersion,kind:'landscape-layout',viewport:{width:844,height:390},host:'unity-ads-ua-playable',scenario:digest??'baseline'});
|
|
452
|
-
result=await service.verifyCache.read(key);await emit({type:'cache',stage:'landscape-layout',hit:Boolean(result)});
|
|
453
|
-
if(!result){const report=await exerciseOutcome(artifact,{outcomes:['loss'],landscape:true,inspectOutcome:inspectHarvestLayout,accelerateIdle:true,browser:await sharedBrowser()});result=report.loss?.layout;if(result)await service.verifyCache.write(key,result);}
|
|
454
|
-
}
|
|
455
|
-
}finally{await emit({type:'playback',kind:'harvest-layout',outcomes:['loss'],status:result?'completed':'failed',durationMs:Date.now()-started});}
|
|
456
|
-
check(result,'E_REVIEW_LAYOUT');
|
|
457
|
-
layouts.set(digest,result);
|
|
458
|
-
return result;
|
|
459
|
-
}
|
|
460
|
-
async function exercisePreview(digest){
|
|
461
|
-
const staged=await getPreview(digest),{resolution,descriptor}=projectModule(project);
|
|
462
|
-
if(!staged.verified){
|
|
463
|
-
const candidateProject={...staged.project,revisionId:'rev-'+proposalId};
|
|
464
|
-
const artifact=await packageArtifact(digest);
|
|
465
|
-
const qa=requireCreativeQa(await creativeQa(digest));
|
|
466
|
-
const started=Date.now();
|
|
467
|
-
let outcome;
|
|
468
|
-
try{outcome=typed&&intent?.action!=='transferOutcomeCue'?[]:
|
|
469
|
-
await outcomeEvidence(project,candidateProject,artifact,normalized,exercise,intent,{browser:exercise?undefined:sharedBrowser,verifyCache:service.verifyCache,onReceipt:emit,scenario:digest??'baseline'});}
|
|
470
|
-
finally{if(intent?.action==='transferOutcomeCue'||outcome?.length)await emit({type:'playback',kind:descriptor?.outcomeKind??'outcome-audio',outcomes:intent?.action==='transferOutcomeCue'?['win','loss']:[],status:outcome?'completed':'failed',durationMs:Date.now()-started});}
|
|
471
|
-
const checks=[{id:'package',detail:'Packaged candidate ('+artifact.manifest.bytes+' bytes).'},
|
|
472
|
-
{id:'creative-qa',detail:`Creative QA passed with ${qa.warnings.length} warning(s) across four viewports.`},
|
|
473
|
-
...outcome.map(detail=>({id:detail.startsWith('Win ')?'win-audio':'loss-audio',detail})),
|
|
474
|
-
...[...staged.perNote.keys()].map(noteId=>({id:'diff-'+noteId,detail:staged.receipts[noteId].join('. ')}))];
|
|
475
|
-
if((intent?.action==='alignCaption'||!typed&&normalized.some(note=>mentionsLayout(note.note)))&&descriptor?.supportsLandscapeReview){
|
|
476
|
-
const actual=await layout(digest);
|
|
477
|
-
check(actual.clipped.length===0,'E_REVIEW_LANDSCAPE_CLIPPED');
|
|
478
|
-
if(intent?.action==='alignCaption'){
|
|
479
|
-
const captionId=resolution.roles.timeoutCaption?.componentId,panelId=resolution.roles.outcomePanel?.componentId;
|
|
480
|
-
const caption=actual.visible.find(item=>item.id===captionId);
|
|
481
|
-
const panel=actual.visible.find(item=>item.id===panelId);
|
|
482
|
-
const original=byId(project.components,captionId);
|
|
483
|
-
const center=item=>(item.bounds.left+item.bounds.right)/2;
|
|
484
|
-
check(caption&&panel&&caption.text===original.parameters.text&&
|
|
485
|
-
actual.visible.filter(item=>item.text===caption.text).length===1&&Math.abs(center(caption)-center(panel))<1&&
|
|
486
|
-
actual.contentCenter!==null&&Math.abs(caption.verticalOffset)<1,
|
|
487
|
-
'E_REVIEW_LAYOUT');
|
|
488
|
-
}
|
|
489
|
-
checks.push({id:'landscape-loss',detail:'Visible text, buttons and panel fit inside the packaged landscape loss screen.'});
|
|
490
|
-
if(normalized.some(note=>/cent(?:er|re)/i.test(note.note)&&/vertic/i.test(note.note)&&/lo(?:s|st)|timeout/i.test(note.note))){
|
|
491
|
-
const baseline=await layout(undefined);
|
|
492
|
-
const original=baseline.visible.find(c=>c.id===resolution.roles.timeoutCaption?.componentId)??baseline.visible.find(c=>c.id==='harvest.instruction')??baseline.visible.find(c=>c.id==='harvest.reward.detail');
|
|
493
|
-
const texts=actual.visible.filter(c=>c.text===original?.text);
|
|
494
|
-
check(texts.length===1&&Math.abs(texts[0].verticalOffset)<=4,'E_REVIEW_LOSS_TEXT_ALIGNMENT');
|
|
495
|
-
checks.push({id:'loss-text',detail:'The original timeout message appears once, centered within four stage pixels between the panel top and install button.'});
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
staged.verified={bytes:artifact.manifest.bytes,outcome,checks};
|
|
499
|
-
}
|
|
500
|
-
return staged.verified;
|
|
501
|
-
}
|
|
502
|
-
async function callToolUnchecked(name,args){
|
|
503
|
-
check(args&&typeof args==='object'&&!Array.isArray(args),'E_AGENT_ARGUMENT');
|
|
504
|
-
const definition=toolDefinitions.find(tool=>tool.function.name===name);
|
|
505
|
-
check(definition&&exact(args,Object.keys(definition.function.parameters.properties)),'E_AGENT_ARGUMENT');
|
|
506
|
-
const selected=args.previewDigest?(await getPreview(args.previewDigest)).project:project;
|
|
507
|
-
switch(name){
|
|
508
|
-
case 'inspect':return inspect(selected,args);
|
|
509
|
-
case 'contracts':return contractInfo(args.names);
|
|
510
|
-
case 'layout':return {loss:await layout(args.previewDigest),speaksTo:'The banner and any centered loss caption may carry the same wording. Inspect the visibility of both, preserving the original words unless asked for copy changes.',targets:reviewTargets(selected).targets.filter(t=>['ending','timeout-card'].includes(t.id)).map(({id,fields})=>({id,fields})),fieldAdapter:'Unpinned typed operations may include {kind:"adjustTarget",target,changes} plus additional native operations. For an existing caption, text-only changes do not reposition it.'};
|
|
511
|
-
case 'audio':{
|
|
512
|
-
const catalog=(await catalogAudio()).map(({catalogId,source,file})=>({catalogId,author:source.author,license:source.license,availableInProjectAs:selected.assets.filter(a=>a.hash===file.sha256).map(a=>a.id)}));
|
|
513
|
-
const routes=audioRoutes(selected);
|
|
514
|
-
const {resolution,descriptor}=projectModule(selected);
|
|
515
|
-
const outcomes=resolution.status==='resolved'&&descriptor?.outcomeAudio?{
|
|
516
|
-
win:{bindingId:resolution.roles.winEvent.bindingId,when:'the authored win outcome completes'},
|
|
517
|
-
loss:{bindingId:resolution.roles.timeoutEvent.bindingId,when:'the authored deadline reaches the loss end card'},
|
|
518
|
-
}:undefined;
|
|
519
|
-
return bounded({routes,catalog,outcomes,routing:{operation:{kind:'setBindingAudio',bindingId:'existing binding ID',assetId:'project or imported WAV ID',replaceBehaviorId:'omit to add cue, use original behavior ID to replace'},scope:'Include the binding ID. If the WAV has no one-shot audio behavior add BINDING_ID.cue and BINDING_ID.cue.play. For an imported WAV also include the new asset ID.',import:'Use edits[].imports:[{catalogId,assetId}] in preview; choose an entry whose availableInProjectAs is empty when a genuinely new sound is requested.'},events:selected.eventBindings.filter(binding=>/deadline|timeout|payoff|restore\.3/.test(binding.id)).map(({id,eventId,condition,actions})=>({id,eventId,condition,actions:actions.filter(a=>a.kind==='playAudio'||a.kind==='set')}))});
|
|
520
|
-
}
|
|
521
|
-
case 'preview':return preview(args);
|
|
522
|
-
case 'qa':return bounded(await creativeQa(args.previewDigest),24000);
|
|
523
|
-
case 'exercise':return {previewDigest:args.previewDigest,checks:(await exercisePreview(args.previewDigest)).checks};
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
async function callTool(name,args){
|
|
527
|
-
const started=Date.now();
|
|
528
|
-
try{
|
|
529
|
-
const result=await callToolUnchecked(name,args);
|
|
530
|
-
await emit({type:'tool',name,status:'completed',responseBytes:Buffer.byteLength(JSON.stringify(result??null)),durationMs:Date.now()-started});
|
|
531
|
-
return result;
|
|
532
|
-
}catch(error){
|
|
533
|
-
await emit({type:'tool',name,status:'failed',durationMs:Date.now()-started});
|
|
534
|
-
throw error;
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
async function finalize(answer){
|
|
538
|
-
if(answer?.question!==undefined)return {status:'needs-clarification',question:modelText(answer,'question')};
|
|
539
|
-
if(answer?.reason!==undefined)return {status:'needs-scope',reason:modelText(answer,'reason')};
|
|
540
|
-
check(exact(answer,['previewDigest','noteResults'])&&Array.isArray(answer.noteResults)&&answer.noteResults.length===normalized.length,'E_REVIEW_NOTE_COVERAGE');
|
|
541
|
-
const staged=await getPreview(answer.previewDigest);
|
|
542
|
-
for(const note of normalized){
|
|
543
|
-
const result=answer.noteResults.find(item=>item?.noteId===note.id);
|
|
544
|
-
const changed=staged.perNote.get(note.id);
|
|
545
|
-
check(result&&exact(result,['noteId','records','verification'])&&Array.isArray(result.records)&&result.records.length>0&&result.records.every(key=>changed.includes(key)),'E_REVIEW_NOTE_COVERAGE');
|
|
546
|
-
}
|
|
547
|
-
const {bytes,outcome,checks}=await exercisePreview(answer.previewDigest);
|
|
548
|
-
for(const result of answer.noteResults){
|
|
549
|
-
check(Array.isArray(result.verification)&&result.verification.length&&result.verification.every(key=>checks.some(c=>c.id===key)),'E_REVIEW_EVIDENCE');
|
|
550
|
-
}
|
|
551
|
-
const moments=normalized.map(note=>note.moment).filter(moment=>moment!=='live');
|
|
552
|
-
const audioMoments=outcome.map(line=>line.startsWith('Win ')?'end-card':'timeout');
|
|
553
|
-
moments.push(...audioMoments);
|
|
554
|
-
const notesEvidence=Object.values(staged.receipts).flat();
|
|
555
|
-
const summary=outcome.length?outcome.join(' '):notesEvidence.slice(0,3).join('. ').slice(0,500);
|
|
556
|
-
return {status:'candidate',operations:staged.operations,previewDigest:answer.previewDigest,candidate:{
|
|
557
|
-
bytes,summary,audioMoments,moments:[...new Set(moments)],evidence:[...outcome,...checks.filter(c=>c.id==='landscape-loss'||c.id==='loss-text').map(c=>c.detail),...notesEvidence],
|
|
558
|
-
}};
|
|
559
|
-
}
|
|
560
|
-
return {tools:toolDefinitions,callTool,finalize,dispose};
|
|
561
|
-
}
|