@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,385 +0,0 @@
|
|
|
1
|
-
import {Buffer} from 'node:buffer';
|
|
2
|
-
import {randomUUID} from 'node:crypto';
|
|
3
|
-
import {link, mkdir, readdir, rename, unlink, writeFile} from 'node:fs/promises';
|
|
4
|
-
import {resolve} from 'node:path';
|
|
5
|
-
import {URL} from 'node:url';
|
|
6
|
-
import {isStoreDestination} from '../../../packages/adapters/src/index.mjs';
|
|
7
|
-
import {registerSource, safeFile} from './assets.mjs';
|
|
8
|
-
import {compileNative, hash} from './compiler.mjs';
|
|
9
|
-
import {composeNativeConcept} from './concept.mjs';
|
|
10
|
-
import {applyOperations, check, emptyProject, exact} from './document.mjs';
|
|
11
|
-
import {importProjectFile} from './local-bundle.mjs';
|
|
12
|
-
import {getModule} from './modules/index.mjs';
|
|
13
|
-
import {projectBundle} from './project-bundle.mjs';
|
|
14
|
-
import {contentHash} from './service.mjs';
|
|
15
|
-
import {assertStorePath} from './store-path.mjs';
|
|
16
|
-
import {reviewProviderConfig} from './review-provider.mjs';
|
|
17
|
-
import {IntakeCreatorAgent} from './intake-creator-agent.mjs';
|
|
18
|
-
|
|
19
|
-
const projectIdPattern = /^[a-z][a-z0-9-]{1,47}$/;
|
|
20
|
-
const intakeIdPattern = /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/;
|
|
21
|
-
const assetIdPattern = /^studio-[a-f0-9]{32}$/;
|
|
22
|
-
const referenceIdPattern = /^ref-[a-f0-9]{32}$/;
|
|
23
|
-
const maxAssetCount = 64;
|
|
24
|
-
const maxReferenceCount = 16;
|
|
25
|
-
const maxPackBytes = 12_000_000;
|
|
26
|
-
const mediaTypes = ['image/png', 'image/jpeg', 'audio/wav', 'audio/mpeg'];
|
|
27
|
-
const referenceTypes = ['image/png', 'image/jpeg'];
|
|
28
|
-
const audioPacks = ['auto', 'casual-warm', 'arcade-pop'];
|
|
29
|
-
const assetSources = ['studio-assets', 'hybrid-free', 'free-licensed'];
|
|
30
|
-
|
|
31
|
-
function validText(value, limit, multiline = false) {
|
|
32
|
-
return typeof value === 'string' && value.trim().length > 0 &&
|
|
33
|
-
value.length <= limit && [...value].every(char =>
|
|
34
|
-
(char >= ' ' && char !== '\u007f') || (multiline && ['\n','\r','\t'].includes(char)));
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function referenceUrl(value) {
|
|
38
|
-
if (value === undefined) return undefined;
|
|
39
|
-
try {
|
|
40
|
-
if (typeof value !== 'string' || value.length > 2048) return null;
|
|
41
|
-
const url = new URL(value);
|
|
42
|
-
if (url.protocol === 'https:' && !url.username && !url.password) return url.href;
|
|
43
|
-
} catch {
|
|
44
|
-
// Report the same validation failure for malformed URLs and unsupported schemes.
|
|
45
|
-
}
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async function readJson(path) {
|
|
50
|
-
try {
|
|
51
|
-
return JSON.parse(await safeFile(path));
|
|
52
|
-
} catch (error) {
|
|
53
|
-
if (error.code === 'ENOENT') return undefined;
|
|
54
|
-
throw error;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Make one complete record visible, even when the editor and MCP run in
|
|
59
|
-
// separate processes. Existing claims and publication intents survive retries.
|
|
60
|
-
async function writeRecord(path, value) {
|
|
61
|
-
const temp = path + '.' + randomUUID() + '.tmp';
|
|
62
|
-
await writeFile(temp, JSON.stringify(value), {flag: 'wx'});
|
|
63
|
-
try {
|
|
64
|
-
await link(temp, path);
|
|
65
|
-
return true;
|
|
66
|
-
} catch (error) {
|
|
67
|
-
if (error.code !== 'EEXIST') throw error;
|
|
68
|
-
return false;
|
|
69
|
-
} finally {
|
|
70
|
-
await unlink(temp);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export class ReviewIntake {
|
|
75
|
-
constructor(service,{connection,agentFactory}={}) {
|
|
76
|
-
this.service = service;
|
|
77
|
-
this.connection = connection;
|
|
78
|
-
this.agentFactory = agentFactory ?? (options => new IntakeCreatorAgent(service,this,options.intake,options));
|
|
79
|
-
this.active = new Map();
|
|
80
|
-
this.recovering = new Set();
|
|
81
|
-
this.root = resolve(service.store.root, '.review-intakes');
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
folder(id) {
|
|
85
|
-
check(typeof id === 'string' && intakeIdPattern.test(id), 'E_INTAKE_ARGUMENT');
|
|
86
|
-
return resolve(this.root, id);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async create(input) {
|
|
90
|
-
check(exact(input, ['projectId','name','brief','storeUrl','studio','rights','referenceUrl','mechanic','audioPack','assetSource']), 'E_INTAKE_ARGUMENT');
|
|
91
|
-
const {projectId,name,brief,studio,rights,audioPack,assetSource} = input;
|
|
92
|
-
const mechanic = input.mechanic ?? 'harvest-restore';
|
|
93
|
-
const isCustom = mechanic === 'custom';
|
|
94
|
-
const descriptor = isCustom ? null : getModule(mechanic);
|
|
95
|
-
if (audioPack !== undefined) check(audioPacks.includes(audioPack), 'E_INTAKE_ARGUMENT');
|
|
96
|
-
if (assetSource !== undefined) check(assetSources.includes(assetSource), 'E_INTAKE_ARGUMENT');
|
|
97
|
-
check((isCustom || (descriptor.supportsIntake && descriptor.intake)) &&
|
|
98
|
-
typeof projectId === 'string' && projectIdPattern.test(projectId) && projectId !== 'compose' &&
|
|
99
|
-
validText(name, 80) && validText(brief, 2048, true) && validText(studio, 120) && validText(rights, 1024), 'E_INTAKE_ARGUMENT');
|
|
100
|
-
const reference = referenceUrl(input.referenceUrl);
|
|
101
|
-
const storeUrl = input.storeUrl;
|
|
102
|
-
if (storeUrl !== undefined) {
|
|
103
|
-
check(typeof storeUrl === 'string' && storeUrl.length <= 512 && isStoreDestination(storeUrl), 'E_INTAKE_ARGUMENT');
|
|
104
|
-
} else {
|
|
105
|
-
check(isCustom, 'E_INTAKE_ARGUMENT');
|
|
106
|
-
}
|
|
107
|
-
check(reference !== null, 'E_INTAKE_ARGUMENT');
|
|
108
|
-
check(!(await this.service.store.list()).some(project => project.id === projectId), 'E_PROJECT_EXISTS');
|
|
109
|
-
await assertStorePath(this.root);
|
|
110
|
-
await mkdir(this.root, {recursive:true});
|
|
111
|
-
const id = randomUUID();
|
|
112
|
-
const folder = this.folder(id);
|
|
113
|
-
await mkdir(folder);
|
|
114
|
-
await mkdir(resolve(folder, 'assets'));
|
|
115
|
-
await mkdir(resolve(folder, 'references'));
|
|
116
|
-
const source = {
|
|
117
|
-
id,projectId,name,brief,studio,rights,mechanic,
|
|
118
|
-
...(storeUrl ? {storeUrl} : {}),
|
|
119
|
-
...(audioPack ? {audioPack} : {}),
|
|
120
|
-
...(assetSource ? {assetSource} : {}),
|
|
121
|
-
...(reference ? {referenceUrl:reference} : {}),
|
|
122
|
-
};
|
|
123
|
-
await writeRecord(resolve(folder, 'intake.json'), source);
|
|
124
|
-
return this.read(id);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async read(id) {
|
|
128
|
-
const folder = this.folder(id);
|
|
129
|
-
const source = await readJson(resolve(folder, 'intake.json'));
|
|
130
|
-
check(source, 'E_INTAKE_NOT_FOUND');
|
|
131
|
-
const assetFolder = resolve(folder, 'assets');
|
|
132
|
-
await assertStorePath(assetFolder);
|
|
133
|
-
const names = (await readdir(assetFolder)).filter(name => name.endsWith('.json') && assetIdPattern.test(name.slice(0, -5))).sort();
|
|
134
|
-
const assets = await Promise.all(names.map(name => readJson(resolve(assetFolder, name))));
|
|
135
|
-
let references = [];
|
|
136
|
-
try {
|
|
137
|
-
const refFolder = resolve(folder, 'references');
|
|
138
|
-
await assertStorePath(refFolder);
|
|
139
|
-
const refNames = (await readdir(refFolder)).filter(name => name.endsWith('.json') && referenceIdPattern.test(name.slice(0, -5))).sort();
|
|
140
|
-
references = await Promise.all(refNames.map(name => readJson(resolve(refFolder, name))));
|
|
141
|
-
} catch (error) {
|
|
142
|
-
if (error.code !== 'ENOENT') throw error;
|
|
143
|
-
}
|
|
144
|
-
const [submitted, claimed, intent, buildState] = await Promise.all(['submitted','claimed','publication','build'].map(name => readJson(resolve(folder, name + '.json'))));
|
|
145
|
-
let artifact;
|
|
146
|
-
if (intent) {
|
|
147
|
-
try {
|
|
148
|
-
const {project} = await this.service.store.open(source.projectId);
|
|
149
|
-
if (project.base.kind === 'native-scene' && contentHash(project) === intent.contentHash) artifact = intent.artifact;
|
|
150
|
-
} catch (error) {
|
|
151
|
-
if (error.code !== 'ENOENT') throw error;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
const status = artifact ? 'ready' : buildState?.status ?? (claimed ? 'claimed' : submitted ? 'queued' : 'draft');
|
|
155
|
-
if (status === 'building' && !this.active.has(id) && !this.recovering.has(id) && this.connection) globalThis.queueMicrotask(() => this.recover(id).catch(() => {}));
|
|
156
|
-
return {
|
|
157
|
-
...source, assets, ...(references.length ? {references} : {}), contactSheetPath:'/?intake=' + id,
|
|
158
|
-
status,
|
|
159
|
-
...(buildState?.build ? {build:buildState.build} : {}),
|
|
160
|
-
...(buildState?.build?.title ? {title:buildState.build.title,summary:buildState.build.summary} : {}),
|
|
161
|
-
...(artifact ? {artifact} : intent ? {publicationPending:true} : {})
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
async upload(id, input) {
|
|
166
|
-
return this.service.history.lock('intake-' + id, async () => {
|
|
167
|
-
const current = await this.read(id);
|
|
168
|
-
check(exact(input, ['name','mime','data','kind','note','optimize','preserveResolution']) && validText(input.name, 180) && !/[\\/]/u.test(input.name), 'E_INTAKE_ARGUMENT');
|
|
169
|
-
const kind = input.kind ?? 'asset';
|
|
170
|
-
check(['asset', 'reference'].includes(kind), 'E_INTAKE_ARGUMENT');
|
|
171
|
-
const allowedMimes = kind === 'reference' ? referenceTypes : mediaTypes;
|
|
172
|
-
check(allowedMimes.includes(input.mime) && typeof input.data === 'string' && input.data.length <= 11184812, 'E_INTAKE_ARGUMENT');
|
|
173
|
-
if (input.note !== undefined) check(validText(input.note, 240), 'E_INTAKE_ARGUMENT');
|
|
174
|
-
const bytes = Buffer.from(input.data, 'base64');
|
|
175
|
-
check(bytes.length > 0 && bytes.length <= (kind === 'asset' ? 8000000 : 700000) && bytes.toString('base64') === input.data, 'E_INTAKE_ASSET_SIZE');
|
|
176
|
-
const digest = hash(bytes);
|
|
177
|
-
const folder = this.folder(id);
|
|
178
|
-
if (kind === 'reference') {
|
|
179
|
-
const refId = 'ref-' + hash(JSON.stringify([input.name, input.mime, digest])).slice(7, 39);
|
|
180
|
-
const existingRefs = current.references ?? [];
|
|
181
|
-
if (existingRefs.some(item => item.id === refId)) return current;
|
|
182
|
-
check(current.status === 'draft', 'E_INTAKE_STALE');
|
|
183
|
-
check(existingRefs.length < maxReferenceCount, 'E_INTAKE_ASSET_LIMIT');
|
|
184
|
-
await mkdir(resolve(folder, 'references'), {recursive: true});
|
|
185
|
-
const asset = await registerSource(folder, {id: refId, mime: input.mime, data: input.data, rights: current.rights, optimize: input.optimize, preserveResolution: input.preserveResolution});
|
|
186
|
-
await writeRecord(resolve(folder, 'references', refId + '.json'), {
|
|
187
|
-
id: refId, name: input.name, mime: asset.mime, hash: asset.hash, bytes: asset.bytes,
|
|
188
|
-
...(asset.optimization ? {optimization: asset.optimization} : {}),
|
|
189
|
-
...(input.note ? {note: input.note} : {}),
|
|
190
|
-
});
|
|
191
|
-
return this.read(id);
|
|
192
|
-
}
|
|
193
|
-
const assetId = 'studio-' + hash(JSON.stringify([input.name, input.mime, digest])).slice(7, 39);
|
|
194
|
-
if (current.assets.some(asset => asset.id === assetId)) return current;
|
|
195
|
-
check(current.status === 'draft', 'E_INTAKE_STALE');
|
|
196
|
-
check(current.assets.length < maxAssetCount, 'E_INTAKE_ASSET_LIMIT');
|
|
197
|
-
const asset = await registerSource(folder, {id:assetId, mime:input.mime, data:input.data, rights:current.rights, optimize:input.optimize, preserveResolution:input.preserveResolution});
|
|
198
|
-
check(current.assets.reduce((total, asset) => total + asset.bytes, 0) + asset.bytes <= maxPackBytes, 'E_INTAKE_ASSET_LIMIT');
|
|
199
|
-
await writeRecord(resolve(folder,'assets',assetId + '.json'), {id:assetId,name:input.name,mime:asset.mime,hash:asset.hash,bytes:asset.bytes,...(asset.optimization?{optimization:asset.optimization}:{})});
|
|
200
|
-
return this.read(id);
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
async submit(id, input = {}) {
|
|
205
|
-
check(exact(input,['mode']) && ['auto','byok','mcp'].includes(input.mode ?? 'auto'),'E_INTAKE_ARGUMENT');
|
|
206
|
-
const mode = input.mode ?? 'auto';
|
|
207
|
-
const provider = mode === 'mcp' ? null : await this.verifiedProvider();
|
|
208
|
-
return this.service.history.lock('intake-' + id, async () => {
|
|
209
|
-
const current = await this.read(id);
|
|
210
|
-
if (current.status !== 'draft') {
|
|
211
|
-
if (['failed','cancelled'].includes(current.status) && mode === 'mcp') {
|
|
212
|
-
await writeRecord(resolve(this.folder(id), 'submitted.json'), {submitted:true});
|
|
213
|
-
await this.updateBuild(id,{status:'queued',phase:'handoff',stepLabel:'Ready for $0 MCP handoff',error:undefined,finishedAt:undefined});
|
|
214
|
-
}
|
|
215
|
-
return this.read(id);
|
|
216
|
-
}
|
|
217
|
-
if (current.mechanic === 'custom') {
|
|
218
|
-
if (current.assetSource !== 'free-licensed') {
|
|
219
|
-
check(current.assets.length > 0 || (current.references?.length ?? 0) > 0, 'E_INTAKE_MEDIA_REQUIRED');
|
|
220
|
-
}
|
|
221
|
-
} else {
|
|
222
|
-
const assetsForCheck = current.audioPack
|
|
223
|
-
? [...current.assets, {id: 'catalog-audio-pack', mime: 'audio/wav', hash: 'sha256:' + '0'.repeat(64)}]
|
|
224
|
-
: current.assets;
|
|
225
|
-
getModule(current.mechanic ?? 'harvest-restore').intake.validateMedia(assetsForCheck);
|
|
226
|
-
}
|
|
227
|
-
if (provider) return this.startByok(current,provider);
|
|
228
|
-
await writeRecord(resolve(this.folder(id), 'submitted.json'), {submitted:true});
|
|
229
|
-
return this.read(id);
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
async verifiedProvider() {
|
|
234
|
-
const active = await this.connection?.read();
|
|
235
|
-
if (!active?.verified || !['gemini','openai','anthropic','openai-compatible'].includes(active.provider)) return null;
|
|
236
|
-
return {
|
|
237
|
-
config:reviewProviderConfig({provider:active.provider,model:active.model,endpoint:active.endpoint,apiKey:active.apiKey,vision:active.vision!==false}),
|
|
238
|
-
info:{provider:active.provider,providerLabel:active.providerLabel,model:active.model,modelLabel:active.modelLabel},
|
|
239
|
-
apiKey:active.apiKey,
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
async updateBuild(id,{status,...patch}) {
|
|
244
|
-
const path=resolve(this.folder(id),'build.json'),previous=await readJson(path)??{status:'draft',build:{events:[]}},now=new Date().toISOString();
|
|
245
|
-
const build={...previous.build,...patch,updatedAt:now},events=[...(previous.build?.events??[])];
|
|
246
|
-
if (patch.stepLabel && (events.at(-1)?.label!==patch.stepLabel||events.at(-1)?.phase!==patch.phase)) events.push({at:now,phase:patch.phase??previous.build?.phase??'building',label:patch.stepLabel});
|
|
247
|
-
build.events=events.slice(-80);
|
|
248
|
-
const value={status:status??previous.status,build},temporary=path+'.'+randomUUID()+'.tmp';
|
|
249
|
-
await writeFile(temporary,JSON.stringify(value),{flag:'wx'});await rename(temporary,path);return value;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
async startByok(current,provider) {
|
|
253
|
-
if (this.active.has(current.id)) return current;
|
|
254
|
-
const controller=new globalThis.AbortController();this.active.set(current.id,controller);
|
|
255
|
-
const startedAt=new Date().toISOString();
|
|
256
|
-
await this.updateBuild(current.id,{status:'building',phase:'brief',stepLabel:'Reading brief & uploads',turn:0,maxTurns:12,provider:provider.info.providerLabel,model:provider.info.modelLabel,startedAt,finishedAt:undefined,error:undefined,usage:undefined,draftProjectId:current.build?.draftProjectId});
|
|
257
|
-
const agent=this.agentFactory({intake:current,config:provider.config,connectionInfo:provider.info,fetchImpl:this.connection.fetch,signal:controller.signal,onProgress:async patch=>{
|
|
258
|
-
if(this.active.get(current.id)===controller)await this.updateBuild(current.id,patch);
|
|
259
|
-
}});
|
|
260
|
-
void agent.run().then(async finished=>{
|
|
261
|
-
if(this.active.get(current.id)!==controller)return;
|
|
262
|
-
await this.updateBuild(current.id,{status:'ready',phase:'ready',stepLabel:'Playable ready to review',finishedAt:new Date().toISOString(),title:finished.title,summary:finished.summary,qa:finished.qa,assetsSummary:finished.assetsSummary,...(finished.usage?{usage:finished.usage}:{}),draftProjectId:finished.projectId,error:undefined});
|
|
263
|
-
}).catch(async error=>{
|
|
264
|
-
if(this.active.get(current.id)!==controller)return;
|
|
265
|
-
const cancelled=controller.signal.aborted||error.message==='E_BUILD_CANCELLED',code=/^E_[A-Z0-9_]+$/.test(error.message)?error.message:'E_CREATOR_BUILD_FAILED';
|
|
266
|
-
await this.updateBuild(current.id,{status:cancelled?'cancelled':'failed',phase:cancelled?'cancelled':'failed',stepLabel:cancelled?'Build cancelled':'Build needs attention',finishedAt:new Date().toISOString(),error:cancelled?'E_BUILD_CANCELLED':code});
|
|
267
|
-
}).catch(()=>{}).finally(()=>{if(this.active.get(current.id)===controller)this.active.delete(current.id);});
|
|
268
|
-
return this.read(current.id);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
async recover(id) {
|
|
272
|
-
if (this.active.has(id)||this.recovering.has(id)) return;
|
|
273
|
-
this.recovering.add(id);
|
|
274
|
-
try{
|
|
275
|
-
const current=await this.read(id);if(current.status!=='building')return;
|
|
276
|
-
await this.updateBuild(id,{status:'failed',phase:'failed',error:'E_BUILD_INTERRUPTED',stepLabel:'Build interrupted by server restart — click Retry to continue',finishedAt:new Date().toISOString()});
|
|
277
|
-
}finally{this.recovering.delete(id);}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
async cancel(id) {
|
|
281
|
-
const current=await this.read(id);if(current.status!=='building')return current;
|
|
282
|
-
this.active.get(id)?.abort();this.active.delete(id);await this.updateBuild(id,{status:'cancelled',phase:'cancelled',stepLabel:'Build cancelled',finishedAt:new Date().toISOString(),error:'E_BUILD_CANCELLED'});return this.read(id);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
async retry(id) {
|
|
286
|
-
const current=await this.read(id);if(current.status==='ready'||current.status==='building')return current;
|
|
287
|
-
check(['failed','cancelled'].includes(current.status),'E_INTAKE_STALE');const provider=await this.verifiedProvider();check(provider,'E_BYOK_NOT_CONFIGURED');return this.startByok(current,provider);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
async claim(id) {
|
|
291
|
-
const current = await this.read(id);
|
|
292
|
-
check(current.status !== 'draft', 'E_INTAKE_STALE');
|
|
293
|
-
if (current.status !== 'queued') return current;
|
|
294
|
-
await writeRecord(resolve(this.folder(id), 'claimed.json'), {claimed:true});
|
|
295
|
-
return this.read(id);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
async sourceAsset(id, asset) {
|
|
299
|
-
const bytes = await safeFile(resolve(this.folder(id), 'sources/assets', asset.hash.slice(7)));
|
|
300
|
-
check(hash(bytes) === asset.hash && bytes.length === asset.bytes, 'E_INTAKE_ASSET_HASH');
|
|
301
|
-
return {bytes,mime:asset.mime};
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
async asset(id, assetId) {
|
|
305
|
-
const current = await this.read(id);
|
|
306
|
-
const asset = current.assets.find(entry => entry.id === assetId);
|
|
307
|
-
check(asset, 'E_INTAKE_NOT_FOUND');
|
|
308
|
-
return this.sourceAsset(id, asset);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
async referenceAsset(id, assetId) {
|
|
312
|
-
const current = await this.read(id);
|
|
313
|
-
const asset = (current.references ?? []).find(entry => entry.id === assetId);
|
|
314
|
-
check(asset, 'E_INTAKE_NOT_FOUND');
|
|
315
|
-
return this.sourceAsset(id, asset);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
async build(id, input) {
|
|
319
|
-
const current = await this.read(id);
|
|
320
|
-
if (current.status === 'ready') return current;
|
|
321
|
-
check(current.status === 'claimed', 'E_INTAKE_STALE');
|
|
322
|
-
const publication = resolve(this.folder(id), 'publication.json');
|
|
323
|
-
const savedIntent = await readJson(publication);
|
|
324
|
-
if (savedIntent) return this.publish(current, savedIntent);
|
|
325
|
-
const concept = input?.concept;
|
|
326
|
-
const mechanic = current.mechanic ?? 'harvest-restore';
|
|
327
|
-
const descriptor = getModule(mechanic);
|
|
328
|
-
check(exact(input, ['concept']) && concept && concept.experience?.mechanic === mechanic, 'E_INTAKE_ARGUMENT');
|
|
329
|
-
check(concept.product?.storeUrl === current.storeUrl && concept.product.name === current.name, 'E_INTAKE_PRODUCT');
|
|
330
|
-
const selected = new Set(descriptor.intake.validateConcept(concept, current));
|
|
331
|
-
const originals = new Map(current.assets.map(asset => [asset.id, asset]));
|
|
332
|
-
check([...selected].every(assetId => originals.has(assetId)), 'E_INTAKE_ASSET_REFERENCE');
|
|
333
|
-
const selectedAssets = [...selected].map(assetId => originals.get(assetId));
|
|
334
|
-
descriptor.intake.validateMedia(selectedAssets, concept);
|
|
335
|
-
const assets = await Promise.all([...selected].sort().map(async assetId => {
|
|
336
|
-
const asset = originals.get(assetId);
|
|
337
|
-
const {bytes} = await this.sourceAsset(id, asset);
|
|
338
|
-
return {
|
|
339
|
-
id:assetId, mime:asset.mime, data:bytes.toString('base64'), rights:current.rights,
|
|
340
|
-
provenance:{origin:'studio-original',studio:current.studio,sourceFile:asset.name,
|
|
341
|
-
sourceHash:asset.hash,intakeId:id,styleFamily:current.projectId}
|
|
342
|
-
};
|
|
343
|
-
}));
|
|
344
|
-
const hydrated = descriptor.intake.hydrateConcept(concept, assets);
|
|
345
|
-
const composition = composeNativeConcept(hydrated, {studioAssets:new Map(assets.map(asset => [asset.id, asset]))});
|
|
346
|
-
const base = emptyProject({id:current.projectId,name:current.name,androidUrl:current.storeUrl});
|
|
347
|
-
const {project} = applyOperations(base, composition.operations);
|
|
348
|
-
const bytesById = new Map(assets.map(asset => [asset.id, asset.data]));
|
|
349
|
-
const lowered = project.assets.map(asset => ({...asset,data:bytesById.get(asset.id)}));
|
|
350
|
-
// The compiler enforces the upload limit on the actual Unity HTML.
|
|
351
|
-
const {manifest} = await compileNative(project, {assets:lowered,target:'unity-ads-ua-playable'});
|
|
352
|
-
const intent = {project,contentHash:contentHash(project),artifact:manifest};
|
|
353
|
-
if (!(await writeRecord(publication, intent))) return this.publish(current, await readJson(publication));
|
|
354
|
-
return this.publish(current, intent);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
async publish(current, intent) {
|
|
358
|
-
const {project} = intent;
|
|
359
|
-
check(project.projectId === current.projectId && contentHash(project) === intent.contentHash, 'E_INTAKE_PUBLICATION');
|
|
360
|
-
const byId = new Map(current.assets.map(asset => [asset.id, asset]));
|
|
361
|
-
const data = await Promise.all(project.assets.map(async asset => {
|
|
362
|
-
const original = byId.get(asset.id);
|
|
363
|
-
check(original && original.hash === asset.hash && original.mime === asset.mime, 'E_INTAKE_ASSET_REFERENCE');
|
|
364
|
-
const {bytes} = await this.sourceAsset(current.id, original);
|
|
365
|
-
return [asset.hash, bytes.toString('base64')];
|
|
366
|
-
}));
|
|
367
|
-
const bundle = projectBundle(project, Object.fromEntries(data));
|
|
368
|
-
try {
|
|
369
|
-
await importProjectFile(this.service, bundle);
|
|
370
|
-
} catch (error) {
|
|
371
|
-
if (error.message !== 'E_PROJECT_EXISTS') throw error;
|
|
372
|
-
// A completed import can win the race or outlive its originating agent.
|
|
373
|
-
// Only that exact intake's prepared project may be reused.
|
|
374
|
-
let saved;
|
|
375
|
-
try {
|
|
376
|
-
({project:saved} = await this.service.store.open(current.projectId));
|
|
377
|
-
} catch (openError) {
|
|
378
|
-
if (openError.code === 'ENOENT') throw Error('E_INTAKE_PUBLICATION_PENDING', {cause:openError});
|
|
379
|
-
throw openError;
|
|
380
|
-
}
|
|
381
|
-
check(saved.base.kind === 'native-scene' && contentHash(saved) === intent.contentHash, 'E_PROJECT_EXISTS');
|
|
382
|
-
}
|
|
383
|
-
return this.read(current.id);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import {check,exact} from './document.mjs';
|
|
2
|
-
import {reviewOperations,reviewTargets} from './review-targets.mjs';
|
|
3
|
-
import {catalogAudio} from './review-agent-tools.mjs';
|
|
4
|
-
import {resolveProjectRoles} from './project-index.mjs';
|
|
5
|
-
import {loadCatalogSync} from './catalog-cache.mjs';
|
|
6
|
-
import {getModule,matchTimingField,timingFieldEntries} from './modules/index.mjs';
|
|
7
|
-
import {isAudioMime} from './media-validate.mjs';
|
|
8
|
-
|
|
9
|
-
export const authoringIntentFormat='tora-authoring-intent-1';
|
|
10
|
-
export const harvestOutcomeCueChoices=Object.freeze([{
|
|
11
|
-
catalogId:'kenney-music-jingles/audio/victory.wav',label:'Kenney NES victory',outcome:'win',tone:'celebratory',
|
|
12
|
-
}]);
|
|
13
|
-
export function eligibleOutcomeCueChoices(project,catalog){
|
|
14
|
-
const present=new Set(project.assets.map(asset=>asset.hash)),primary=harvestOutcomeCueChoices[0].catalogId;
|
|
15
|
-
return catalog.audioFiles.filter(({catalogId,file})=>(file.audioMeta?.role==='win'||catalogId===primary)&&file.audioMeta?.valence==='positive'&&!present.has(file.sha256))
|
|
16
|
-
.map(({catalogId,file,source})=>({catalogId,label:source.id+' · '+file.path,outcome:'win',tone:file.audioMeta.valence}))
|
|
17
|
-
.sort((a,b)=>Number(b.catalogId===primary)-Number(a.catalogId===primary)||a.catalogId.localeCompare(b.catalogId));
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const baseIntent=(noteId,action,targetRole,args,constraints,requiredChecks)=>({
|
|
21
|
-
format:authoringIntentFormat,noteId,action,targetRole,arguments:args,constraints,requiredChecks,
|
|
22
|
-
});
|
|
23
|
-
const textIntent=text=>baseIntent('1','replaceText','primaryCta',{text},{literal:true},['package','diff-1']);
|
|
24
|
-
const timingIntent=(field,seconds)=>baseIntent('1','setTiming','reviewTiming',{field,seconds},{absolute:true},['package','diff-1']);
|
|
25
|
-
const captionIntent=()=>baseIntent('1','alignCaption','timeoutCaption',{alignment:'center'},{preserveText:true},['package','diff-1','landscape-loss']);
|
|
26
|
-
const artworkIntent=(target,assetId)=>baseIntent('1','replaceSharedArtwork','sharedArtwork',{target,assetId},{allUses:true},['package','diff-1']);
|
|
27
|
-
|
|
28
|
-
export function transferOutcomeCueIntent(noteId='1',replacementCatalogId=harvestOutcomeCueChoices[0].catalogId){
|
|
29
|
-
return baseIntent(noteId,'transferOutcomeCue','outcomeCues',
|
|
30
|
-
{sourceOutcome:'win',destinationOutcome:'loss',replacementCatalogId},
|
|
31
|
-
{replacementMustBeNew:true,preserveOrdinaryCues:true},['win-audio','loss-audio']);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function literalTextIntent(note){
|
|
35
|
-
if(note.target!=='cta'||note.moment!=='end-card'||note.fields.length!==1||note.fields[0]!=='text')return null;
|
|
36
|
-
const match=/^(?:change|set|update) the (?:selected )?(?:cta|install button)(?: wording| text| label)? to (["“'])(.*)(["”'])[.!?]?$/i.exec(note.note);
|
|
37
|
-
if(!match)return null;
|
|
38
|
-
const closing={'"':'"',"'":"'",'“':'”'}[match[1]];
|
|
39
|
-
if(match[3]!==closing||match[2].includes(closing))return null;
|
|
40
|
-
return textIntent(match[2]);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function permits(note,target,moment,field){
|
|
44
|
-
return (note.moment===moment||note.moment==='live')&&
|
|
45
|
-
(note.target===null||note.target===target&¬e.fields.includes(field));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function literalTimingIntent(note){
|
|
49
|
-
if(note.fields.length!==1)return null;
|
|
50
|
-
const descriptor=matchTimingField({field:note.fields[0],target:note.target,moment:note.moment});
|
|
51
|
-
if(!descriptor||!permits(note,note.target,descriptor.moment,descriptor.field))return null;
|
|
52
|
-
const match=new RegExp('^set (?:the )?'+descriptor.label+' to ([0-9]+(?:\\.[0-9]+)?) (?:seconds?|s)[.!]?$','i').exec(note.note);
|
|
53
|
-
return match?timingIntent(descriptor.field,Number(match[1])):null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function interpretationOptions(request,index,project){
|
|
57
|
-
const notes=request.notes??[request],resolution=resolveProjectRoles(index);
|
|
58
|
-
if(notes.length!==1||resolution.status!=='resolved')return [];
|
|
59
|
-
const note=notes[0],options=[],targets=reviewTargets(project).targets;
|
|
60
|
-
const supported=(target,field)=>targets.some(item=>item.id===target&&item.fields.some(value=>value.id===field));
|
|
61
|
-
if(permits(note,'cta','end-card','text'))options.push(textIntent(''));
|
|
62
|
-
for(const {field,targets:allowedTargets,moment} of timingFieldEntries(resolution.module)){
|
|
63
|
-
const matchedTarget=allowedTargets.find(target=>supported(target,field)&&permits(note,target,moment,field));
|
|
64
|
-
if(matchedTarget){
|
|
65
|
-
const bounds=targets.find(item=>item.id===matchedTarget).fields.find(value=>value.id===field);
|
|
66
|
-
options.push(timingIntent(field,bounds.value));
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if(supported('timeout-card','caption-alignment')&&permits(note,'timeout-card','timeout','caption-alignment'))options.push(captionIntent());
|
|
70
|
-
for(const target of targets.filter(target=>target.imageChoices?.length&&supported(target.id,'shared-art')&&permits(note,target.id,target.moment,'shared-art'))){
|
|
71
|
-
const option=artworkIntent(target.id,target.imageChoices[0]);option.constraints={...option.constraints,allowedAssetIds:[...target.imageChoices]};options.push(option);
|
|
72
|
-
}
|
|
73
|
-
if(canTransferOutcomeCue(index)&&supported('ending','win-cue')&&
|
|
74
|
-
(permits(note,'ending','end-card','win-cue')||note.target===null&¬e.moment==='timeout')){
|
|
75
|
-
const choices=eligibleOutcomeCueChoices(project,loadCatalogSync());
|
|
76
|
-
options.push(...choices.map(choice=>transferOutcomeCueIntent('1',choice.catalogId)));
|
|
77
|
-
}
|
|
78
|
-
return options;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function canTransferOutcomeCue(index){
|
|
82
|
-
const resolution=resolveProjectRoles(index);
|
|
83
|
-
return resolution.module&&resolution.module!=='tora-native-primitives'?getModule(resolution.module).canTransferOutcomeCue(index,resolution):false;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function deterministicIntent(request){
|
|
87
|
-
const notes=request.notes??[request];
|
|
88
|
-
if(notes.length!==1)return null;
|
|
89
|
-
const note=notes[0];
|
|
90
|
-
if(note.intent!==undefined){
|
|
91
|
-
const intent=note.intent;
|
|
92
|
-
check(exact(intent,['format','noteId','action','targetRole','arguments','constraints','requiredChecks'])&&
|
|
93
|
-
intent.format===authoringIntentFormat&&intent.noteId==='1','E_REVIEW_INTENT');
|
|
94
|
-
if(intent.action==='transferOutcomeCue'){
|
|
95
|
-
check(note.target==='ending'&¬e.moment==='end-card'&¬e.fields.length===1&¬e.fields[0]==='win-cue','E_REVIEW_SCOPE');
|
|
96
|
-
validateTransferIntent(intent);return transferOutcomeCueIntent('1',intent.arguments.replacementCatalogId);
|
|
97
|
-
}
|
|
98
|
-
if(intent.action==='replaceText'){
|
|
99
|
-
check(note.target==='cta'&¬e.moment==='end-card'&¬e.fields.length===1&¬e.fields[0]==='text','E_REVIEW_SCOPE');
|
|
100
|
-
check(intent.targetRole==='primaryCta'&&exact(intent.arguments,['text'])&&typeof intent.arguments.text==='string'&&
|
|
101
|
-
exact(intent.constraints,['literal'])&&intent.constraints.literal===true&&intent.requiredChecks?.join(',')==='package,diff-1','E_REVIEW_INTENT');
|
|
102
|
-
return textIntent(intent.arguments.text);
|
|
103
|
-
}
|
|
104
|
-
if(intent.action==='setTiming'){
|
|
105
|
-
const field=intent.arguments?.field,descriptor=matchTimingField({field,target:note.target,moment:note.moment});
|
|
106
|
-
check(descriptor&¬e.fields.length===1&¬e.fields[0]===field,'E_REVIEW_SCOPE');
|
|
107
|
-
check(intent.targetRole==='reviewTiming'&&exact(intent.arguments,['field','seconds'])&&Number.isFinite(intent.arguments.seconds)&&
|
|
108
|
-
exact(intent.constraints,['absolute'])&&intent.constraints.absolute===true&&intent.requiredChecks?.join(',')==='package,diff-1','E_REVIEW_INTENT');
|
|
109
|
-
return timingIntent(field,intent.arguments.seconds);
|
|
110
|
-
}
|
|
111
|
-
if(intent.action==='alignCaption'){
|
|
112
|
-
check(note.target==='timeout-card'&¬e.moment==='timeout'&¬e.fields.length===1&¬e.fields[0]==='caption-alignment','E_REVIEW_SCOPE');
|
|
113
|
-
check(intent.targetRole==='timeoutCaption'&&exact(intent.arguments,['alignment'])&&intent.arguments.alignment==='center'&&
|
|
114
|
-
exact(intent.constraints,['preserveText'])&&intent.constraints.preserveText===true&&intent.requiredChecks?.join(',')==='package,diff-1,landscape-loss','E_REVIEW_INTENT');
|
|
115
|
-
return captionIntent();
|
|
116
|
-
}
|
|
117
|
-
check(intent.action==='replaceSharedArtwork'&¬e.target===intent.arguments?.target&¬e.moment==='opening'&¬e.fields.length===1&¬e.fields[0]==='shared-art','E_REVIEW_SCOPE');
|
|
118
|
-
check(intent.targetRole==='sharedArtwork'&&exact(intent.arguments,['target','assetId'])&&typeof intent.arguments.assetId==='string'&&
|
|
119
|
-
exact(intent.constraints,['allUses'])&&intent.constraints.allUses===true&&intent.requiredChecks?.join(',')==='package,diff-1','E_REVIEW_INTENT');
|
|
120
|
-
return artworkIntent(note.target,intent.arguments.assetId);
|
|
121
|
-
}
|
|
122
|
-
if(note.target==='timeout-card'&¬e.fields.length===1&&permits(note,'timeout-card','timeout','caption-alignment')&&
|
|
123
|
-
/^center the (?:existing )?(?:loss|timeout) (?:caption|message)(?: vertically)? (?:in|within) the (?:end-card )?panel[.!]?$/i.test(note.note))return captionIntent();
|
|
124
|
-
if(/^(?:crop-|core-art$|hazard-art$)/.test(note.target??'')&¬e.fields.length===1&&permits(note,note.target,'opening','shared-art')){
|
|
125
|
-
const asset=/^replace all uses with "([a-z][a-z0-9_.-]{0,95})"[.!]?$/i.exec(note.note);
|
|
126
|
-
if(asset)return artworkIntent(note.target,asset[1]);
|
|
127
|
-
}
|
|
128
|
-
return literalTextIntent(note)??literalTimingIntent(note);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export function deterministicIntents(request){
|
|
132
|
-
const notes=request.notes??[request];
|
|
133
|
-
if(notes.length===1){
|
|
134
|
-
const intent=deterministicIntent(request);
|
|
135
|
-
return intent?[intent]:null;
|
|
136
|
-
}
|
|
137
|
-
const intents=notes.map((note,index)=>{
|
|
138
|
-
const intent=literalTextIntent(note)??literalTimingIntent(note);
|
|
139
|
-
const noteId=String(index+1);
|
|
140
|
-
return intent&&{...intent,noteId,requiredChecks:['package','diff-'+noteId]};
|
|
141
|
-
});
|
|
142
|
-
return intents.every(Boolean)?intents:null;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function validateTransferIntent(intent){
|
|
146
|
-
check(intent.targetRole==='outcomeCues'&&exact(intent.arguments,['sourceOutcome','destinationOutcome','replacementCatalogId'])&&
|
|
147
|
-
intent.arguments.sourceOutcome==='win'&&intent.arguments.destinationOutcome==='loss'&&
|
|
148
|
-
exact(intent.constraints,['replacementMustBeNew','preserveOrdinaryCues'])&&intent.constraints.replacementMustBeNew===true&&
|
|
149
|
-
intent.constraints.preserveOrdinaryCues===true&&Array.isArray(intent.requiredChecks)&&
|
|
150
|
-
intent.requiredChecks.length===2&&intent.requiredChecks[0]==='win-audio'&&intent.requiredChecks[1]==='loss-audio','E_REVIEW_INTENT');
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
async function transferOutcomeCue(project,intent,index){
|
|
154
|
-
validateTransferIntent(intent);
|
|
155
|
-
const resolution=resolveProjectRoles(index);
|
|
156
|
-
check(resolution.status==='resolved','E_REVIEW_ROLE_UNRESOLVED');
|
|
157
|
-
const {winEvent,timeoutEvent,rewardCue}=resolution.roles;
|
|
158
|
-
check(!winEvent.cue.unresolved&&timeoutEvent.cue?.unresolved==='missing-cue','E_REVIEW_OUTCOME_AUDIO_AMBIGUOUS');
|
|
159
|
-
const catalog=await catalogAudio(),replacement=eligibleOutcomeCueChoices(project,{audioFiles:catalog}).find(choice=>choice.catalogId===intent.arguments.replacementCatalogId);
|
|
160
|
-
check(replacement,'E_REVIEW_ASSET_CHOICE');
|
|
161
|
-
const cue=catalog.find(item=>item.catalogId===replacement.catalogId);
|
|
162
|
-
check(isAudioMime(cue?.file.mime),'E_REVIEW_ASSET_CHOICE');
|
|
163
|
-
check(!project.assets.some(asset=>asset.hash===cue.file.sha256),'E_REVIEW_WIN_AUDIO_MUST_BE_NEW');
|
|
164
|
-
check(cue.file.sha256!==rewardCue.assetHash,'E_REVIEW_WIN_AUDIO_MUST_BE_NEW');
|
|
165
|
-
const assetId=getModule(resolution.module).outcomeAssetId;
|
|
166
|
-
check(!project.assets.some(asset=>asset.id===assetId),'E_REVIEW_ASSET_CHOICE');
|
|
167
|
-
const componentId=winEvent.bindingId+'.cue',behaviorId=componentId+'.play';
|
|
168
|
-
return {noteId:intent.noteId,imports:[{catalogId:cue.catalogId,assetId}],operations:[
|
|
169
|
-
{kind:'setBindingAudio',bindingId:timeoutEvent.bindingId,assetId:rewardCue.assetId},
|
|
170
|
-
{kind:'setBindingAudio',bindingId:winEvent.bindingId,assetId,replaceBehaviorId:rewardCue.behaviorId},
|
|
171
|
-
],scope:[assetId,timeoutEvent.bindingId,winEvent.bindingId,componentId,behaviorId]};
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export async function compileDeterministicIntent(project,intent,index,noteTarget){
|
|
175
|
-
check(intent.format===authoringIntentFormat&&/^[1-9][0-9]*$/.test(intent.noteId),'E_REVIEW_INTENT');
|
|
176
|
-
if(intent.action==='alignCaption'){
|
|
177
|
-
check(intent.targetRole==='timeoutCaption'&&exact(intent.arguments,['alignment'])&&intent.arguments.alignment==='center'&&
|
|
178
|
-
exact(intent.constraints,['preserveText'])&&intent.constraints.preserveText===true,'E_REVIEW_INTENT');
|
|
179
|
-
const changes={'caption-alignment':'center'};
|
|
180
|
-
reviewOperations(project,'timeout-card',['caption-alignment'],changes);
|
|
181
|
-
return {edit:{noteId:intent.noteId,target:'timeout-card',changes}};
|
|
182
|
-
}
|
|
183
|
-
if(intent.action==='replaceSharedArtwork'){
|
|
184
|
-
check(intent.targetRole==='sharedArtwork'&&exact(intent.arguments,['target','assetId'])&&
|
|
185
|
-
exact(intent.constraints,['allUses','allowedAssetIds'])&&intent.constraints.allUses===true&&
|
|
186
|
-
(intent.constraints.allowedAssetIds===undefined||Array.isArray(intent.constraints.allowedAssetIds)&&intent.constraints.allowedAssetIds.includes(intent.arguments.assetId)),'E_REVIEW_INTENT');
|
|
187
|
-
const {target,assetId}=intent.arguments;
|
|
188
|
-
const changes={'shared-art':assetId};
|
|
189
|
-
reviewOperations(project,target,['shared-art'],changes);
|
|
190
|
-
return {edit:{noteId:intent.noteId,target,changes}};
|
|
191
|
-
}
|
|
192
|
-
if(intent.action==='setTiming'){
|
|
193
|
-
check(intent.targetRole==='reviewTiming'&&exact(intent.arguments,['field','seconds'])&&
|
|
194
|
-
exact(intent.constraints,['absolute'])&&intent.constraints.absolute===true&&
|
|
195
|
-
Array.isArray(intent.requiredChecks)&&intent.requiredChecks.join(',')==='package,diff-'+intent.noteId,'E_REVIEW_INTENT');
|
|
196
|
-
const {field,seconds}=intent.arguments,resolution=resolveProjectRoles(index);
|
|
197
|
-
check(resolution.status==='resolved','E_REVIEW_ROLE_UNRESOLVED');
|
|
198
|
-
const descriptor=matchTimingField({field,target:noteTarget??undefined,moduleId:resolution.module});
|
|
199
|
-
check(descriptor,'E_REVIEW_SCOPE');
|
|
200
|
-
const target=noteTarget&&descriptor.targets.includes(noteTarget)?noteTarget:descriptor.target;
|
|
201
|
-
check(reviewTargets(project).targets.some(item=>item.id===target&&item.fields.some(value=>value.id===field)),'E_REVIEW_SCOPE');
|
|
202
|
-
reviewOperations(project,target,[field],{[field]:seconds});
|
|
203
|
-
return {edit:{noteId:intent.noteId,target,changes:{[field]:seconds}}};
|
|
204
|
-
}
|
|
205
|
-
if(intent.action==='replaceText'){
|
|
206
|
-
check(intent.targetRole==='primaryCta'&&exact(intent.arguments,['text'])&&exact(intent.constraints,['literal'])&&
|
|
207
|
-
intent.constraints.literal===true&&Array.isArray(intent.requiredChecks)&&intent.requiredChecks.join(',')==='package,diff-'+intent.noteId,'E_REVIEW_INTENT');
|
|
208
|
-
const resolution=resolveProjectRoles(index);
|
|
209
|
-
check(resolution.status==='resolved','E_REVIEW_ROLE_UNRESOLVED');
|
|
210
|
-
const target=resolution.roles.primaryCta;
|
|
211
|
-
const result=reviewOperations(project,'cta',['text'],{text:intent.arguments.text});
|
|
212
|
-
return {edit:{noteId:intent.noteId,target:'cta',changes:{text:intent.arguments.text}},expected:result.expected,
|
|
213
|
-
authorizedRecords:[target.labelId]};
|
|
214
|
-
}
|
|
215
|
-
check(intent.action==='transferOutcomeCue','E_REVIEW_INTENT');
|
|
216
|
-
return {edit:await transferOutcomeCue(project,intent,index)};
|
|
217
|
-
}
|