@tora-editor/tora 0.2.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 +5 -6
- package/bin/tora.mjs +255 -29
- package/crates/packer/trusted/native-3d-meta.json +3 -3
- package/crates/packer/trusted/native-3d.js +180 -180
- 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 +3 -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 -106
- package/docs/TORA_CREATION_API.md +63 -365
- package/docs/reference/CORE_AUTHORING.md +8 -2
- package/docs/reference/PLAYABLE_STARTERS.md +1 -1
- package/docs/reference/packs/3d.md +2 -0
- package/package.json +6 -6
- package/packages/creative-project/project-v21.schema.json +108 -1
- 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 +246 -68
- package/scripts/lean/editor/review-editor.js +1731 -1099
- 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 +35 -58
- package/scripts/lean/native/api.mjs +148 -134
- 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 +36 -5
- package/scripts/lean/native/contracts.mjs +8 -6
- package/scripts/lean/native/creative-qa.mjs +66 -12
- package/scripts/lean/native/demos.mjs +11 -20
- package/scripts/lean/native/document.mjs +14 -2
- package/scripts/lean/native/local-bundle.mjs +4 -2
- package/scripts/lean/native/mcp-server.mjs +16 -35
- 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/project-bundle.mjs +3 -2
- 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/review.mjs +203 -572
- package/scripts/lean/native/schema-vocabulary.mjs +10 -0
- package/scripts/lean/native/schema.mjs +1 -1
- package/scripts/lean/native/scope.mjs +45 -0
- package/scripts/lean/native/service.mjs +242 -70
- package/scripts/lean/native/starters.mjs +135 -8
- 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 +1 -1
- 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 -143
- package/scripts/lean/native/author-fps.mjs +0 -545
- 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 -875
- 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 -190
- package/scripts/lean/native/check-salvage.mjs +0 -200
- 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/glb-loader.mjs +0 -468
- 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 -218
- 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-fps-assets.mjs +0 -330
- 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 -1809
- package/scripts/lean/native/salvage-recipe.mjs +0 -20
- package/scripts/lean/native/stage-3d.mjs +0 -1121
- package/scripts/lean/native/verify.mjs +0 -4
- package/scripts/lean/scene-document.mjs +0 -48
|
@@ -1,60 +1,44 @@
|
|
|
1
|
-
/* global document,window,fetch,navigator,btoa,atob,crypto,ResizeObserver,Blob,URL,Image,OfflineAudioContext,setTimeout,clearTimeout,setInterval */
|
|
1
|
+
/* global document,window,fetch,navigator,btoa,atob,crypto,ResizeObserver,Blob,URL,URLSearchParams,Image,OfflineAudioContext,setTimeout,clearTimeout,setInterval */
|
|
2
|
+
import {createQuickEditPanel} from './quick-edit-panel.js';
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
export const errorLabels = {
|
|
5
|
-
E_NATIVE_STALE: '
|
|
6
|
-
E_REVIEW_STALE: '
|
|
7
|
-
E_REVIEW_LIMIT: 'This request reached its
|
|
8
|
-
E_REVIEW_CONFLICT: 'Two notes
|
|
9
|
-
E_REVIEW_SCOPE: '
|
|
10
|
-
|
|
6
|
+
E_NATIVE_STALE: 'This playable changed in another tab. Refresh before saving.',
|
|
7
|
+
E_REVIEW_STALE: 'This playable changed after your review note was written. Start a new review on the latest version.',
|
|
8
|
+
E_REVIEW_LIMIT: 'This request reached its note or storage limit. Start a fresh request.',
|
|
9
|
+
E_REVIEW_CONFLICT: 'Two notes ask for conflicting changes. Adjust one and retry.',
|
|
10
|
+
E_REVIEW_SCOPE: 'That change is outside the allowed scope.',
|
|
11
|
+
E_REVIEW_OUTSIDE_SCOPE: 'The proposed operations touch records outside the authorized review scope.',
|
|
12
|
+
E_REVIEW_ASSET_INGEST: 'Review proposals cannot ingest new asset bytes. Upload the asset separately and start a fresh review request.',
|
|
13
|
+
E_REVIEW_ARGUMENT: 'Invalid review request or proposal payload.',
|
|
14
|
+
E_REVIEW_EXISTS: 'A different review request or proposal already used that ID.',
|
|
15
|
+
E_REVIEW_STATUS: 'This review request is no longer in a state that accepts that action.',
|
|
16
|
+
E_REVIEW_NOT_FOUND: 'That review request could not be found.',
|
|
17
|
+
E_REVIEW_JOURNAL: 'Review journal format error.',
|
|
18
|
+
E_REVIEW_NO_CHANGE: 'No changes were detected compared to the current values.',
|
|
11
19
|
E_REVIEW_TEXT_FIT: 'That wording is too wide for the space or uses unsupported characters.',
|
|
12
|
-
E_REVIEW_VALUE: 'That value is outside the
|
|
13
|
-
E_REVIEW_BUILD: 'Tora could not package this
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
E_REVIEW_WIN_AUDIO_MUST_BE_NEW: 'The proposed win sound already exists in the playable.',
|
|
23
|
-
E_REVIEW_KEY_FORMAT: 'Enter a valid API key (8+ visible characters, no spaces or line breaks).',
|
|
24
|
-
E_REVIEW_KEY_SAVE: 'Tora could not save the API connection on this machine.',
|
|
25
|
-
E_MODEL_UNSUPPORTED_CAPABILITY: 'This API or model is not verified for full playable-ad creation (requires tool calling, vision, and full audio/QA support). Choose Gemini, OpenAI, or Claude.',
|
|
26
|
-
E_MODEL_UNAVAILABLE: 'Your API key does not have access to that model. Pick another verified model or check your account tier.',
|
|
27
|
-
E_MODEL_AUTH: 'The provider rejected that API key. Check the key and try again.',
|
|
28
|
-
E_MODEL_FORBIDDEN: 'This API key does not have permission for that model.',
|
|
29
|
-
E_MODEL_QUOTA: 'That API account has reached its billing quota. Check your provider balance and retry.',
|
|
30
|
-
E_MODEL_FREE_ACCESS: 'This legacy free route requires an eligible GitHub account.',
|
|
31
|
-
E_MODEL_FREE_PROMPT_LIMIT: 'These notes exceed the legacy free prompt limit.',
|
|
32
|
-
E_MODEL_FREE_CAPACITY: 'The model is temporarily at capacity. Try again shortly.',
|
|
33
|
-
E_MODEL_RATE_LIMIT: 'The provider rate-limited this request. Try again shortly.',
|
|
34
|
-
E_MODEL_UPSTREAM: 'The provider is temporarily unavailable. Try again shortly.',
|
|
35
|
-
E_MODEL_REQUEST: 'The provider rejected the request. Check your model access and key.',
|
|
36
|
-
E_MODEL_HTTP: 'The provider rejected the request. Check your API key and account limits.',
|
|
37
|
-
E_MODEL_TIMEOUT: 'The provider took too long to respond.',
|
|
38
|
-
E_MODEL_TRANSPORT: 'Tora could not reach the provider API. Check your internet connection.',
|
|
39
|
-
E_MODEL_INCOMPLETE: 'The model returned an incomplete answer.',
|
|
40
|
-
E_CREATIVE_QA: 'Creative QA found a layout, audio, or interaction blocker that prevented staging.',
|
|
41
|
-
E_INTAKE_HARVEST_MEDIA: 'Attach at least 5 distinct PNG/JPEG game sprites plus a WAV sound (or switch audio to a Free CC0 pack).',
|
|
42
|
-
E_INTAKE_SALVAGE_MEDIA: 'Attach at least 4 distinct PNG/JPEG game sprites plus a WAV sound (or switch audio to a Free CC0 pack).',
|
|
43
|
-
E_NATIVE_ASSET_DECODE: 'One of those files could not be decoded as a valid PNG, JPEG, or PCM WAV.',
|
|
44
|
-
E_NATIVE_ASSET_SIZE: 'Upload raw media up to 8 MB; the optimized delivery asset must fit 700 KB. Try auto mode or a shorter/smaller source.',
|
|
45
|
-
E_INTAKE_ASSET_SIZE: 'Upload raw media up to 8 MB; Tora will optimize it for delivery.',
|
|
46
|
-
E_INTAKE_MEDIA_REQUIRED: 'Attach your game art or audio files first, or slide to Free assets only.',
|
|
47
|
-
E_BYOK_NOT_CONFIGURED: 'Connect a verified API key (Gemini, OpenAI, or Claude) to build directly from Send.',
|
|
48
|
-
E_BUILD_CANCELLED: 'Build cancelled.',
|
|
49
|
-
E_BUILD_INTERRUPTED: 'The build was interrupted by a server restart. Click Retry build to continue.',
|
|
50
|
-
E_CREATOR_TURN_CAP: 'The build reached its 12-turn safety limit. Retry to continue from the saved draft.',
|
|
51
|
-
E_ASSET_SOURCE_DISALLOWED: 'That asset source is blocked by your current Asset & sound source slider setting.',
|
|
20
|
+
E_REVIEW_VALUE: 'That value is outside the allowed range.',
|
|
21
|
+
E_REVIEW_BUILD: 'Tora could not package this update.',
|
|
22
|
+
E_REVIEW_NOTE_COVERAGE: 'The proposal did not cover every note in this review request.',
|
|
23
|
+
E_REVIEW_OUTCOME_AUDIO_MISSING: 'The packaged preview did not play the requested win/loss sound.',
|
|
24
|
+
E_REVIEW_OUTCOME_AUDIO_MISMATCH: 'The packaged preview played a different sound than requested.',
|
|
25
|
+
E_REVIEW_WIN_AUDIO_MUST_BE_NEW: 'The chosen win sound is already used in this playable.',
|
|
26
|
+
E_CREATIVE_QA: 'Creative QA found a layout, audio, or interaction issue to fix before exporting.',
|
|
27
|
+
E_NATIVE_ASSET_DECODE: 'One of those files could not be read as a valid PNG, JPEG, or WAV.',
|
|
28
|
+
E_NATIVE_ASSET_SIZE: 'Upload raw files up to 8 MB; optimized delivery assets must fit 700 KB.',
|
|
29
|
+
E_ASSET_SOURCE_DISALLOWED: 'That asset source is blocked by your current Asset & sound source setting.',
|
|
52
30
|
E_ASSET_STYLE_FAMILY: 'Keep visual artwork within one consistent art style family.',
|
|
53
|
-
E_NATIVE_UNSUPPORTED_TARGET: 'That export target is not supported yet.',
|
|
54
|
-
|
|
55
|
-
|
|
31
|
+
E_NATIVE_UNSUPPORTED_TARGET: 'That ad-network export target is not supported yet.',
|
|
32
|
+
E_NATIVE_SIZE: 'This playable exceeds the selected size limit. Turn on Auto-shrink in Budget or compress large assets.',
|
|
33
|
+
E_UPLOAD_SIZE: 'This playable is larger than the selected ad network allows. Turn on Auto-shrink in Budget to shrink it automatically.',
|
|
34
|
+
E_NATIVE_STORE: 'Enter a valid Google Play or App Store link before exporting for this ad network.',
|
|
56
35
|
E_ARTIFACT_PLACEHOLDER: 'Replace the placeholder store link with your real Google Play or App Store URL before exporting.',
|
|
57
|
-
E_PROJECT_EXISTS: 'A project with that ID already exists. Try a different
|
|
36
|
+
E_PROJECT_EXISTS: 'A project with that ID already exists. Try a different name.',
|
|
37
|
+
E_BUNDLE_INVALID: 'That file is not a valid .tora.json playable project.',
|
|
38
|
+
E_BUNDLE_SIZE: 'This .tora.json file exceeds the 64 MB import limit.',
|
|
39
|
+
E_QUICK_EDIT_ARGUMENT: 'Invalid Quick Edit value. Check your input and try again.',
|
|
40
|
+
E_QUICK_EDIT_TARGET: 'That element could not be found in the current version. Refresh and retry.',
|
|
41
|
+
E_CHROMIUM_MISSING: 'Playwright Chromium is not installed on this computer. Run `npx playwright install chromium` to enable 4-screen QA.',
|
|
58
42
|
};
|
|
59
43
|
|
|
60
44
|
export async function reviewRequest(path, body) {
|
|
@@ -104,6 +88,37 @@ export function formatBytes(bytes) {
|
|
|
104
88
|
return Math.round(bytes / 104857.6) / 10 + ' MB';
|
|
105
89
|
}
|
|
106
90
|
|
|
91
|
+
export function budgetPresentation(budget) {
|
|
92
|
+
if (!budget) return {label: 'Budget · checking', description: 'Checking the export budget.'};
|
|
93
|
+
const measurement = budget.measurement === 'measured' ? 'Measured' : 'Estimated';
|
|
94
|
+
const total = formatBytes(budget.totalBytes ?? 0);
|
|
95
|
+
const limit = Number.isFinite(budget.targetLimitBytes) ? formatBytes(budget.targetLimitBytes) : '';
|
|
96
|
+
const label = `${measurement} · ${total}${limit ? ' / ' + limit : ''}`;
|
|
97
|
+
const status = budget.status === 'over' ? 'over the target limit' : budget.status === 'tight' ? 'near the target limit' : 'within the target limit';
|
|
98
|
+
return {label, description: `${measurement} export size: ${total}${limit ? ' of ' + limit : ''}, ${status}.`};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function variantTextDeltas(variant) {
|
|
102
|
+
const rows = [];
|
|
103
|
+
for (const [id, override] of Object.entries(variant?.texts ?? {})) {
|
|
104
|
+
const text = typeof override?.text === 'string' ? override.text : '';
|
|
105
|
+
const extras = Object.fromEntries(Object.entries(override ?? {}).filter(([key]) => key !== 'text'));
|
|
106
|
+
rows.push({kind: 'Text', id, text, detail: Object.keys(extras).length ? JSON.stringify(extras) : ''});
|
|
107
|
+
}
|
|
108
|
+
for (const [id, text] of Object.entries(variant?.actionTexts ?? {})) rows.push({kind: 'Action text', id, text, detail: ''});
|
|
109
|
+
for (const [id, override] of Object.entries(variant?.colors ?? {})) {
|
|
110
|
+
rows.push({kind: 'Color', id, text: Object.entries(override ?? {}).map(([k, v]) => `${k}: ${v}`).join(', '), detail: ''});
|
|
111
|
+
}
|
|
112
|
+
for (const [id, override] of Object.entries(variant?.behaviors ?? {})) {
|
|
113
|
+
rows.push({kind: 'Timing', id, text: Object.entries(override ?? {}).map(([k, v]) => `${k}: ${v}`).join(', '), detail: ''});
|
|
114
|
+
}
|
|
115
|
+
for (const [id, override] of Object.entries(variant?.assets ?? {})) {
|
|
116
|
+
rows.push({kind: 'Asset', id, text: override?.assetId ?? '', detail: override?.slotId ? `slot: ${override.slotId}` : ''});
|
|
117
|
+
}
|
|
118
|
+
if (variant?.storeUrl) rows.push({kind: 'Store URL', id: '$project.base', text: variant.storeUrl, detail: ''});
|
|
119
|
+
return rows;
|
|
120
|
+
}
|
|
121
|
+
|
|
107
122
|
export function wireAutoGrowTextarea(textarea, {onSubmit, maxHeight = 160} = {}) {
|
|
108
123
|
const resize = () => {
|
|
109
124
|
textarea.style.height = '40px';
|
|
@@ -348,494 +363,6 @@ export async function extractVideoKeyframes(file, {frameCount = 3} = {}) {
|
|
|
348
363
|
}
|
|
349
364
|
}
|
|
350
365
|
|
|
351
|
-
const FALLBACK_VERIFIED_PROVIDERS = [
|
|
352
|
-
{
|
|
353
|
-
id: 'gemini',
|
|
354
|
-
label: 'Google Gemini',
|
|
355
|
-
keyUrl: 'https://aistudio.google.com/apikey',
|
|
356
|
-
keyPlaceholder: 'AIza...',
|
|
357
|
-
defaultModel: 'gemini-4-hydrogen',
|
|
358
|
-
audioSummary: 'Native audio + Tora acoustic QA',
|
|
359
|
-
videoSummary: 'Native video + keyframes',
|
|
360
|
-
summary: 'Handles everything natively: vision, audio, video frames, and multi-turn playable tools.',
|
|
361
|
-
models: [
|
|
362
|
-
{id: 'gemini-4-hydrogen', label: 'Gemini 4 Hydrogen', badge: 'Recommended', contextTokens: 1_000_000},
|
|
363
|
-
{id: 'gemini-4-carbon', label: 'Gemini 4 Carbon', badge: 'Flagship', contextTokens: 1_000_000},
|
|
364
|
-
{id: 'gemini-4-neon', label: 'Gemini 4 Neon', badge: 'Frontier', contextTokens: 1_000_000},
|
|
365
|
-
{id: 'gemini-3.8-flash', label: 'Gemini 3.8 Flash', badge: 'Fast', contextTokens: 1_000_000},
|
|
366
|
-
],
|
|
367
|
-
},
|
|
368
|
-
{
|
|
369
|
-
id: 'openai',
|
|
370
|
-
label: 'OpenAI',
|
|
371
|
-
keyUrl: 'https://platform.openai.com/api-keys',
|
|
372
|
-
keyPlaceholder: 'sk-...',
|
|
373
|
-
defaultModel: 'gpt-6.2-sol',
|
|
374
|
-
audioSummary: 'Tora acoustic QA + WAV catalog',
|
|
375
|
-
videoSummary: 'Extracted video keyframes',
|
|
376
|
-
summary: 'Strong tool calling and vision for scenes and video frames; sounds verified via Tora acoustic analysis.',
|
|
377
|
-
models: [
|
|
378
|
-
{id: 'gpt-6.2-sol', label: 'GPT-6.2 Sol', badge: 'Recommended', contextTokens: 1_000_000},
|
|
379
|
-
{id: 'gpt-6.2-astra', label: 'GPT-6.2 Astra', badge: 'Flagship', contextTokens: 1_050_000},
|
|
380
|
-
{id: 'gpt-6.1-terra', label: 'GPT-6.1 Terra', badge: 'Fast', contextTokens: 1_000_000},
|
|
381
|
-
],
|
|
382
|
-
},
|
|
383
|
-
{
|
|
384
|
-
id: 'anthropic',
|
|
385
|
-
label: 'Anthropic Claude',
|
|
386
|
-
keyUrl: 'https://console.anthropic.com/settings/keys',
|
|
387
|
-
keyPlaceholder: 'sk-ant-...',
|
|
388
|
-
defaultModel: 'claude-opus-5-5',
|
|
389
|
-
audioSummary: 'Tora acoustic QA + WAV catalog',
|
|
390
|
-
videoSummary: 'Extracted video keyframes',
|
|
391
|
-
summary: 'Precise multi-turn scene editing and vision for visuals and video frames; sounds verified via Tora acoustic analysis.',
|
|
392
|
-
models: [
|
|
393
|
-
{id: 'claude-opus-5-5', label: 'Claude Opus 5.5', badge: 'Recommended', contextTokens: 1_000_000},
|
|
394
|
-
{id: 'claude-sonnet-5-5', label: 'Claude Sonnet 5.5', badge: 'Fast', contextTokens: 1_000_000},
|
|
395
|
-
{id: 'claude-fable-5-2', label: 'Claude Fable 5.2', badge: 'Deep reasoning', contextTokens: 1_000_000},
|
|
396
|
-
],
|
|
397
|
-
},
|
|
398
|
-
{
|
|
399
|
-
id: 'openai-compatible',
|
|
400
|
-
label: 'Custom / OpenRouter',
|
|
401
|
-
keyUrl: 'https://openrouter.ai/keys',
|
|
402
|
-
keyPlaceholder: 'sk-or-v1-...',
|
|
403
|
-
defaultModel: 'qwen/qwen3.8-max',
|
|
404
|
-
audioSummary: 'Tora acoustic QA + WAV catalog',
|
|
405
|
-
videoSummary: 'Extracted video keyframes (when vision enabled)',
|
|
406
|
-
summary: 'Connect OpenRouter, DeepSeek, Kimi, Qwen, GLM, or any custom/local OpenAI-compatible API.',
|
|
407
|
-
customEndpoint: true,
|
|
408
|
-
presets: [
|
|
409
|
-
{id: 'openrouter', label: 'OpenRouter', endpoint: 'https://openrouter.ai/api/v1', keyUrl: 'https://openrouter.ai/keys', keyPlaceholder: 'sk-or-v1-...', defaultModel: 'qwen/qwen3.8-max', vision: true, models: [{id: 'qwen/qwen3.8-max', label: 'Qwen 3.8 Max (OpenRouter)', badge: 'Recommended', contextTokens: 1_000_000, vision: true}, {id: 'moonshotai/kimi-k3.1-pro', label: 'Kimi K3.1 Pro (OpenRouter)', badge: 'Flagship', contextTokens: 1_000_000, vision: true}, {id: 'z-ai/glm-5.3-flash', label: 'GLM-5.3 Flash (OpenRouter)', badge: 'Fast', contextTokens: 1_000_000, vision: true}, {id: 'deepseek/deepseek-v4-pro', label: 'DeepSeek V4 Pro (OpenRouter)', badge: 'Coding', contextTokens: 128_000, vision: false}]},
|
|
410
|
-
{id: 'deepseek', label: 'DeepSeek', endpoint: 'https://api.deepseek.com/v1', keyUrl: 'https://platform.deepseek.com/api_keys', keyPlaceholder: 'sk-...', defaultModel: 'deepseek-chat', vision: false, models: [{id: 'deepseek-chat', label: 'DeepSeek Chat', badge: 'Recommended', contextTokens: 128_000, vision: false}, {id: 'deepseek-reasoner', label: 'DeepSeek Reasoner', badge: 'Reasoning', contextTokens: 128_000, vision: false}]},
|
|
411
|
-
{id: 'kimi', label: 'Kimi (Moonshot)', endpoint: 'https://api.moonshot.ai/v1', keyUrl: 'https://platform.moonshot.ai/console/api-keys', keyPlaceholder: 'sk-...', defaultModel: 'kimi-k3.1-pro', vision: true, models: [{id: 'kimi-k3.1-pro', label: 'Kimi K3.1 Pro', badge: 'Recommended', contextTokens: 1_000_000, vision: true}, {id: 'kimi-k3', label: 'Kimi K3', badge: 'Balanced', contextTokens: 1_000_000, vision: true}, {id: 'kimi-k2.7-code', label: 'Kimi K2.7 Code', badge: 'Coding', contextTokens: 256_000, vision: true}]},
|
|
412
|
-
{id: 'qwen', label: 'Qwen (Alibaba)', endpoint: 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1', keyUrl: 'https://modelstudio.console.alibabacloud.com/', keyPlaceholder: 'sk-...', defaultModel: 'qwen3.8-max', vision: true, models: [{id: 'qwen3.8-max', label: 'Qwen 3.8 Max', badge: 'Recommended', contextTokens: 1_000_000, vision: true}, {id: 'qwen3.7-plus', label: 'Qwen 3.7 Plus', badge: 'Balanced', contextTokens: 1_000_000, vision: true}, {id: 'qwen3.8-flash', label: 'Qwen 3.8 Flash', badge: 'Fast', contextTokens: 1_000_000, vision: true}]},
|
|
413
|
-
{id: 'glm', label: 'GLM (Z.ai)', endpoint: 'https://api.z.ai/api/paas/v4', keyUrl: 'https://z.ai/manage-apikey/apikey-list', keyPlaceholder: 'Paste Z.ai / BigModel key', defaultModel: 'glm-5.3-flash', vision: true, models: [{id: 'glm-5.3-flash', label: 'GLM-5.3 Flash', badge: 'Recommended', contextTokens: 1_000_000, vision: true}, {id: 'glm-5.3', label: 'GLM-5.3', badge: 'Flagship', contextTokens: 1_000_000, vision: false}, {id: 'glm-5v-turbo', label: 'GLM-5V Turbo', badge: 'Vision', contextTokens: 256_000, vision: true}]},
|
|
414
|
-
{id: 'custom', label: 'Custom / Local', endpoint: '', keyUrl: '', keyPlaceholder: 'API key (or "local" for Ollama/vLLM)', defaultModel: '', vision: true, models: []},
|
|
415
|
-
],
|
|
416
|
-
models: [{id: 'qwen/qwen3.8-max', label: 'Qwen 3.8 Max (OpenRouter)', badge: 'Recommended', contextTokens: 1_000_000, vision: true}],
|
|
417
|
-
},
|
|
418
|
-
];
|
|
419
|
-
|
|
420
|
-
export function createApiConnectionController({pillButton, onStatusChange} = {}) {
|
|
421
|
-
let status = {configured: false, supportedProviders: FALLBACK_VERIFIED_PROVIDERS};
|
|
422
|
-
let selectedProviderId = 'gemini';
|
|
423
|
-
let selectedModelId = 'gemini-4-hydrogen';
|
|
424
|
-
let selectedPresetId = 'openrouter';
|
|
425
|
-
let customEndpoint = 'https://openrouter.ai/api/v1';
|
|
426
|
-
let customVision = true;
|
|
427
|
-
let discoveredModels = {};
|
|
428
|
-
let busy = false;
|
|
429
|
-
|
|
430
|
-
const dialog = document.createElement('dialog');
|
|
431
|
-
dialog.className = 'tora-modal';
|
|
432
|
-
dialog.setAttribute('aria-labelledby', 'tora-api-modal-title');
|
|
433
|
-
dialog.innerHTML = `
|
|
434
|
-
<div class="tora-modal-card">
|
|
435
|
-
<div class="tora-modal-head">
|
|
436
|
-
<div>
|
|
437
|
-
<h2 id="tora-api-modal-title">Connect a playable-ready AI API</h2>
|
|
438
|
-
<p class="tora-modal-sub">Connect Gemini, OpenAI, Claude, or any OpenAI-compatible API (OpenRouter, DeepSeek, Kimi, Qwen, GLM, or local).</p>
|
|
439
|
-
</div>
|
|
440
|
-
<button type="button" class="tora-modal-close" id="tora-api-close" aria-label="Close">×</button>
|
|
441
|
-
</div>
|
|
442
|
-
<div class="tora-api-current" id="tora-api-current" hidden></div>
|
|
443
|
-
<div class="tora-provider-grid" id="tora-provider-grid" role="radiogroup" aria-label="Verified AI providers"></div>
|
|
444
|
-
<form class="tora-api-form" id="tora-api-form">
|
|
445
|
-
<div class="tora-compat-fields" id="tora-compat-fields" hidden>
|
|
446
|
-
<div class="tora-preset-row" id="tora-preset-row" role="group" aria-label="OpenAI-compatible presets"></div>
|
|
447
|
-
<label>API Base URL
|
|
448
|
-
<input id="tora-api-endpoint" type="text" inputmode="url" maxlength="512" autocomplete="off" spellcheck="false" placeholder="https://openrouter.ai/api/v1 or http://127.0.0.1:11434/v1">
|
|
449
|
-
</label>
|
|
450
|
-
</div>
|
|
451
|
-
<div class="tora-api-row">
|
|
452
|
-
<label id="tora-api-model-wrap">Model
|
|
453
|
-
<select id="tora-api-model"></select>
|
|
454
|
-
</label>
|
|
455
|
-
<a id="tora-api-get-key" class="tora-key-link" target="_blank" rel="noopener noreferrer">Get API key ↗</a>
|
|
456
|
-
</div>
|
|
457
|
-
<label id="tora-api-custom-model-wrap" hidden>Model ID (or pick above)
|
|
458
|
-
<input id="tora-api-custom-model" type="text" maxlength="128" autocomplete="off" spellcheck="false" placeholder="e.g. qwen/qwen3.8-max, deepseek-chat, kimi-k3.1-pro">
|
|
459
|
-
</label>
|
|
460
|
-
<label class="tora-vision-check" id="tora-api-vision-wrap" hidden>
|
|
461
|
-
<input id="tora-api-vision" type="checkbox" checked>
|
|
462
|
-
<span>Model supports vision (inspects Creative QA screenshots)</span>
|
|
463
|
-
</label>
|
|
464
|
-
<div class="tora-cap-row" id="tora-cap-row" aria-label="Verified capabilities"></div>
|
|
465
|
-
<p class="tora-api-note" id="tora-api-media-note"></p>
|
|
466
|
-
<label>Your API key
|
|
467
|
-
<input id="tora-api-key" type="password" required maxlength="4096" autocomplete="off" spellcheck="false" placeholder="Paste your API key">
|
|
468
|
-
</label>
|
|
469
|
-
<div class="tora-modal-actions">
|
|
470
|
-
<button type="submit" class="review-primary" id="tora-api-save">Verify & connect</button>
|
|
471
|
-
<button type="button" id="tora-api-fetch-models">Load models from key</button>
|
|
472
|
-
<button type="button" id="tora-api-disconnect" hidden>Disconnect</button>
|
|
473
|
-
</div>
|
|
474
|
-
<p class="review-error" id="tora-api-error" role="alert"></p>
|
|
475
|
-
<p class="tora-api-footnote">Keys are verified directly with the provider before saving, stored locally (<code>0600</code>), and never exported in playables. Prefer $0 API keys? Connect Claude Code, Cursor, Codex, or Gemini CLI via Tora MCP instead.</p>
|
|
476
|
-
</form>
|
|
477
|
-
</div>
|
|
478
|
-
`;
|
|
479
|
-
document.body.append(dialog);
|
|
480
|
-
|
|
481
|
-
const $ = id => dialog.querySelector('#' + id);
|
|
482
|
-
const providersList = () => status.supportedProviders?.length ? status.supportedProviders : FALLBACK_VERIFIED_PROVIDERS;
|
|
483
|
-
const activePresetFor = provider => {
|
|
484
|
-
const presets = provider?.presets ?? [];
|
|
485
|
-
return presets.find(item => item.id === selectedPresetId) ?? presets[0] ?? null;
|
|
486
|
-
};
|
|
487
|
-
const cacheKeyFor = provider => provider.id === 'openai-compatible'
|
|
488
|
-
? `openai-compatible:${selectedPresetId}:${customEndpoint}`
|
|
489
|
-
: provider.id;
|
|
490
|
-
const modelsForProvider = provider => {
|
|
491
|
-
const preset = provider.id === 'openai-compatible' ? activePresetFor(provider) : null;
|
|
492
|
-
const baseModels = preset ? [...(preset.models ?? [])] : [...(provider.models ?? [])];
|
|
493
|
-
const cached = discoveredModels[cacheKeyFor(provider)];
|
|
494
|
-
const list = cached?.length ? [...cached] : baseModels;
|
|
495
|
-
if (status.verified && status.provider === provider.id && status.model && !list.some(item => item.id === status.model)) {
|
|
496
|
-
if (provider.id !== 'openai-compatible' || status.endpoint === customEndpoint) {
|
|
497
|
-
list.unshift({
|
|
498
|
-
id: status.model,
|
|
499
|
-
label: status.modelLabel || status.model,
|
|
500
|
-
badge: 'Connected',
|
|
501
|
-
contextTokens: null,
|
|
502
|
-
vision: status.capabilities?.vision,
|
|
503
|
-
});
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
return list;
|
|
507
|
-
};
|
|
508
|
-
|
|
509
|
-
function formatContext(tokens) {
|
|
510
|
-
if (!tokens) return '';
|
|
511
|
-
return tokens >= 1_000_000 ? (tokens / 1_000_000) + 'M context' : Math.round(tokens / 1000) + 'K context';
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
function updatePill() {
|
|
515
|
-
if (!pillButton) return;
|
|
516
|
-
if (status.configured) {
|
|
517
|
-
pillButton.dataset.connected = 'true';
|
|
518
|
-
pillButton.textContent = status.verified ? (status.modelLabel || status.model || 'API connected') + ' ✓' : (status.modelLabel || 'Legacy API');
|
|
519
|
-
pillButton.title = status.verified
|
|
520
|
-
? `Connected to ${status.providerLabel} (${status.modelLabel})`
|
|
521
|
-
: 'Legacy text-only connection. Click to switch to a verified playable-ready API.';
|
|
522
|
-
} else {
|
|
523
|
-
pillButton.dataset.connected = 'false';
|
|
524
|
-
pillButton.textContent = 'Connect API';
|
|
525
|
-
pillButton.title = 'Connect Gemini, OpenAI, Claude, OpenRouter, DeepSeek, Kimi, Qwen, GLM, or a custom API key';
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
function renderCapabilities() {
|
|
530
|
-
const provider = providersList().find(item => item.id === selectedProviderId) ?? providersList()[0];
|
|
531
|
-
if (!provider) return;
|
|
532
|
-
const isCompat = provider.id === 'openai-compatible';
|
|
533
|
-
const preset = isCompat ? activePresetFor(provider) : null;
|
|
534
|
-
const list = modelsForProvider(provider);
|
|
535
|
-
const model = list.find(item => item.id === selectedModelId) ?? list[0] ?? null;
|
|
536
|
-
selectedProviderId = provider.id;
|
|
537
|
-
|
|
538
|
-
const keyUrl = isCompat ? (preset?.keyUrl || '') : provider.keyUrl;
|
|
539
|
-
const keyLink = $('tora-api-get-key');
|
|
540
|
-
keyLink.hidden = !keyUrl;
|
|
541
|
-
if (keyUrl) keyLink.href = keyUrl;
|
|
542
|
-
$('tora-api-key').placeholder = (isCompat && preset?.keyPlaceholder) || provider.keyPlaceholder || 'Paste your API key';
|
|
543
|
-
$('tora-api-media-note').textContent = provider.summary;
|
|
544
|
-
|
|
545
|
-
const visionEnabled = isCompat ? customVision : true;
|
|
546
|
-
const caps = [
|
|
547
|
-
{text: '✓ Scene tools & JSON'},
|
|
548
|
-
visionEnabled ? {text: '✓ Vision'} : {text: '⚠ Text-only (no screenshot review)', warn: true},
|
|
549
|
-
{text: '✓ Audio: ' + provider.audioSummary},
|
|
550
|
-
{text: '✓ Video: ' + (visionEnabled ? 'Extracted video keyframes' : 'Disabled (text-only)')},
|
|
551
|
-
...(model?.contextTokens ? [{text: '✓ ' + formatContext(model.contextTokens)}] : []),
|
|
552
|
-
];
|
|
553
|
-
$('tora-cap-row').replaceChildren(...caps.map(item => reviewElement('span', item.text, item.warn ? 'tora-cap-pill tora-cap-pill-warn' : 'tora-cap-pill')));
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
function renderPresets(provider) {
|
|
557
|
-
const isCompat = provider.id === 'openai-compatible';
|
|
558
|
-
$('tora-compat-fields').hidden = !isCompat;
|
|
559
|
-
$('tora-api-custom-model-wrap').hidden = !isCompat;
|
|
560
|
-
$('tora-api-vision-wrap').hidden = !isCompat;
|
|
561
|
-
$('tora-api-endpoint').required = isCompat;
|
|
562
|
-
$('tora-api-custom-model').required = isCompat;
|
|
563
|
-
if (!isCompat) return;
|
|
564
|
-
|
|
565
|
-
const presets = provider.presets ?? [];
|
|
566
|
-
if (!presets.some(item => item.id === selectedPresetId)) selectedPresetId = presets[0]?.id ?? 'openrouter';
|
|
567
|
-
$('tora-preset-row').replaceChildren(...presets.map(preset => {
|
|
568
|
-
const btn = reviewElement('button', preset.label, 'tora-preset-btn');
|
|
569
|
-
btn.type = 'button';
|
|
570
|
-
const active = preset.id === selectedPresetId;
|
|
571
|
-
btn.dataset.active = String(active);
|
|
572
|
-
btn.setAttribute('aria-pressed', String(active));
|
|
573
|
-
btn.onclick = () => {
|
|
574
|
-
selectedPresetId = preset.id;
|
|
575
|
-
customEndpoint = preset.endpoint;
|
|
576
|
-
selectedModelId = preset.defaultModel;
|
|
577
|
-
customVision = preset.vision !== false;
|
|
578
|
-
$('tora-api-endpoint').value = customEndpoint;
|
|
579
|
-
$('tora-api-custom-model').value = selectedModelId;
|
|
580
|
-
$('tora-api-vision').checked = customVision;
|
|
581
|
-
renderPresets(provider);
|
|
582
|
-
renderModels();
|
|
583
|
-
};
|
|
584
|
-
return btn;
|
|
585
|
-
}));
|
|
586
|
-
$('tora-api-endpoint').value = customEndpoint;
|
|
587
|
-
$('tora-api-vision').checked = customVision;
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
function renderModels() {
|
|
591
|
-
const provider = providersList().find(item => item.id === selectedProviderId) ?? providersList()[0];
|
|
592
|
-
if (!provider) return;
|
|
593
|
-
const isCompat = provider.id === 'openai-compatible';
|
|
594
|
-
const list = modelsForProvider(provider);
|
|
595
|
-
const select = $('tora-api-model');
|
|
596
|
-
const selectWrap = $('tora-api-model-wrap');
|
|
597
|
-
if (list.length) {
|
|
598
|
-
selectWrap.hidden = false;
|
|
599
|
-
select.required = !isCompat;
|
|
600
|
-
if (!isCompat && !list.some(item => item.id === selectedModelId)) {
|
|
601
|
-
selectedModelId = list.some(item => item.id === provider.defaultModel) ? provider.defaultModel : (list[0]?.id || '');
|
|
602
|
-
}
|
|
603
|
-
select.replaceChildren(...list.map(model => {
|
|
604
|
-
const option = reviewElement('option', model.label + (model.badge ? ' · ' + model.badge : ''));
|
|
605
|
-
option.value = model.id;
|
|
606
|
-
return option;
|
|
607
|
-
}));
|
|
608
|
-
if (list.some(item => item.id === selectedModelId)) select.value = selectedModelId;
|
|
609
|
-
} else {
|
|
610
|
-
selectWrap.hidden = true;
|
|
611
|
-
select.required = false;
|
|
612
|
-
select.replaceChildren();
|
|
613
|
-
}
|
|
614
|
-
if (isCompat) {
|
|
615
|
-
$('tora-api-custom-model').value = selectedModelId || '';
|
|
616
|
-
}
|
|
617
|
-
renderCapabilities();
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
function renderModal() {
|
|
621
|
-
const providers = providersList();
|
|
622
|
-
if (!providers.some(item => item.id === selectedProviderId)) {
|
|
623
|
-
selectedProviderId = status.verified && status.provider ? status.provider : (providers[0]?.id ?? 'gemini');
|
|
624
|
-
selectedModelId = status.verified && status.model ? status.model : '';
|
|
625
|
-
}
|
|
626
|
-
const currentBox = $('tora-api-current');
|
|
627
|
-
if (status.configured) {
|
|
628
|
-
currentBox.hidden = false;
|
|
629
|
-
currentBox.replaceChildren(
|
|
630
|
-
reviewElement('strong', status.verified ? 'Connected: ' + status.providerLabel + ' · ' + status.modelLabel : 'Legacy connection active'),
|
|
631
|
-
reviewElement('span', status.keyHint ? 'Key ' + status.keyHint : ''),
|
|
632
|
-
);
|
|
633
|
-
$('tora-api-disconnect').hidden = false;
|
|
634
|
-
} else {
|
|
635
|
-
currentBox.hidden = true;
|
|
636
|
-
$('tora-api-disconnect').hidden = true;
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
$('tora-provider-grid').replaceChildren(...providers.map(provider => {
|
|
640
|
-
const card = reviewElement('button', '', 'tora-provider-card');
|
|
641
|
-
card.type = 'button';
|
|
642
|
-
card.setAttribute('role', 'radio');
|
|
643
|
-
const active = provider.id === selectedProviderId;
|
|
644
|
-
card.setAttribute('aria-checked', String(active));
|
|
645
|
-
card.dataset.active = String(active);
|
|
646
|
-
const tag = provider.id === 'gemini'
|
|
647
|
-
? 'Native audio & video'
|
|
648
|
-
: provider.id === 'openai-compatible'
|
|
649
|
-
? 'OpenRouter, DeepSeek, Kimi, Qwen, GLM'
|
|
650
|
-
: 'Vision + Tora audio QA';
|
|
651
|
-
card.append(
|
|
652
|
-
reviewElement('strong', provider.label),
|
|
653
|
-
reviewElement('span', tag, 'tora-provider-tag'),
|
|
654
|
-
);
|
|
655
|
-
card.onclick = () => {
|
|
656
|
-
selectedProviderId = provider.id;
|
|
657
|
-
if (provider.id === 'openai-compatible') {
|
|
658
|
-
const preset = activePresetFor(provider);
|
|
659
|
-
if (preset && !customEndpoint) customEndpoint = preset.endpoint;
|
|
660
|
-
selectedModelId = preset?.defaultModel ?? provider.defaultModel;
|
|
661
|
-
customVision = preset?.vision !== false;
|
|
662
|
-
} else {
|
|
663
|
-
selectedModelId = provider.defaultModel;
|
|
664
|
-
}
|
|
665
|
-
renderModal();
|
|
666
|
-
};
|
|
667
|
-
return card;
|
|
668
|
-
}));
|
|
669
|
-
const activeProvider = providers.find(item => item.id === selectedProviderId) ?? providers[0];
|
|
670
|
-
renderPresets(activeProvider);
|
|
671
|
-
renderModels();
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
async function refresh() {
|
|
675
|
-
try {
|
|
676
|
-
status = await reviewRequest('/api/review/connection');
|
|
677
|
-
if (status.verified && status.provider) {
|
|
678
|
-
selectedProviderId = status.provider;
|
|
679
|
-
selectedModelId = status.model;
|
|
680
|
-
if (status.provider === 'openai-compatible') {
|
|
681
|
-
if (status.preset) selectedPresetId = status.preset;
|
|
682
|
-
if (status.endpoint) customEndpoint = status.endpoint;
|
|
683
|
-
customVision = status.capabilities?.vision !== false;
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
updatePill();
|
|
687
|
-
onStatusChange?.(status);
|
|
688
|
-
} catch {
|
|
689
|
-
updatePill();
|
|
690
|
-
}
|
|
691
|
-
return status;
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
function open(prefillMessage = '') {
|
|
695
|
-
$('tora-api-error').textContent = prefillMessage;
|
|
696
|
-
renderModal();
|
|
697
|
-
if (!dialog.open) dialog.showModal();
|
|
698
|
-
$('tora-api-key').focus();
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
function close() {
|
|
702
|
-
if (dialog.open) dialog.close();
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
$('tora-api-close').onclick = close;
|
|
706
|
-
dialog.addEventListener('click', event => {
|
|
707
|
-
if (event.target === dialog) close();
|
|
708
|
-
});
|
|
709
|
-
$('tora-api-model').onchange = event => {
|
|
710
|
-
selectedModelId = event.target.value;
|
|
711
|
-
if (selectedProviderId === 'openai-compatible') {
|
|
712
|
-
$('tora-api-custom-model').value = selectedModelId;
|
|
713
|
-
const provider = providersList().find(item => item.id === 'openai-compatible');
|
|
714
|
-
const match = modelsForProvider(provider).find(item => item.id === selectedModelId);
|
|
715
|
-
if (typeof match?.vision === 'boolean') {
|
|
716
|
-
customVision = match.vision;
|
|
717
|
-
$('tora-api-vision').checked = customVision;
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
renderCapabilities();
|
|
721
|
-
};
|
|
722
|
-
$('tora-api-endpoint').oninput = event => {
|
|
723
|
-
customEndpoint = event.target.value.trim();
|
|
724
|
-
};
|
|
725
|
-
$('tora-api-custom-model').oninput = event => {
|
|
726
|
-
selectedModelId = event.target.value.trim();
|
|
727
|
-
};
|
|
728
|
-
$('tora-api-vision').onchange = event => {
|
|
729
|
-
customVision = event.target.checked;
|
|
730
|
-
renderCapabilities();
|
|
731
|
-
};
|
|
732
|
-
|
|
733
|
-
$('tora-api-form').onsubmit = async event => {
|
|
734
|
-
event.preventDefault();
|
|
735
|
-
if (busy) return;
|
|
736
|
-
const key = $('tora-api-key').value.trim();
|
|
737
|
-
if (!key) return;
|
|
738
|
-
const isCompat = selectedProviderId === 'openai-compatible';
|
|
739
|
-
const modelToSave = isCompat ? ($('tora-api-custom-model').value.trim() || selectedModelId) : selectedModelId;
|
|
740
|
-
const endpointToSave = isCompat ? $('tora-api-endpoint').value.trim() : undefined;
|
|
741
|
-
if (isCompat && (!endpointToSave || !modelToSave)) {
|
|
742
|
-
$('tora-api-error').textContent = 'Enter both an API Base URL and Model ID.';
|
|
743
|
-
return;
|
|
744
|
-
}
|
|
745
|
-
busy = true;
|
|
746
|
-
$('tora-api-error').textContent = '';
|
|
747
|
-
const saveBtn = $('tora-api-save');
|
|
748
|
-
saveBtn.disabled = true;
|
|
749
|
-
saveBtn.textContent = 'Verifying model access…';
|
|
750
|
-
try {
|
|
751
|
-
await reviewRequest('/api/review/connection', {
|
|
752
|
-
provider: selectedProviderId,
|
|
753
|
-
model: modelToSave,
|
|
754
|
-
apiKey: key,
|
|
755
|
-
...(isCompat ? {endpoint: endpointToSave, preset: selectedPresetId, vision: customVision} : {}),
|
|
756
|
-
});
|
|
757
|
-
$('tora-api-key').value = '';
|
|
758
|
-
await refresh();
|
|
759
|
-
close();
|
|
760
|
-
} catch (error) {
|
|
761
|
-
$('tora-api-error').textContent = errorLabels[error.message] ?? error.message;
|
|
762
|
-
} finally {
|
|
763
|
-
busy = false;
|
|
764
|
-
saveBtn.disabled = false;
|
|
765
|
-
saveBtn.textContent = 'Verify & connect';
|
|
766
|
-
}
|
|
767
|
-
};
|
|
768
|
-
|
|
769
|
-
$('tora-api-fetch-models').onclick = async () => {
|
|
770
|
-
if (busy) return;
|
|
771
|
-
const key = $('tora-api-key').value.trim();
|
|
772
|
-
if (!key) {
|
|
773
|
-
$('tora-api-error').textContent = 'Paste your API key first to load your live account models.';
|
|
774
|
-
$('tora-api-key').focus();
|
|
775
|
-
return;
|
|
776
|
-
}
|
|
777
|
-
const isCompat = selectedProviderId === 'openai-compatible';
|
|
778
|
-
const endpointToQuery = isCompat ? $('tora-api-endpoint').value.trim() : undefined;
|
|
779
|
-
if (isCompat && !endpointToQuery) {
|
|
780
|
-
$('tora-api-error').textContent = 'Enter an API Base URL first.';
|
|
781
|
-
$('tora-api-endpoint').focus();
|
|
782
|
-
return;
|
|
783
|
-
}
|
|
784
|
-
busy = true;
|
|
785
|
-
$('tora-api-error').textContent = '';
|
|
786
|
-
const fetchBtn = $('tora-api-fetch-models');
|
|
787
|
-
fetchBtn.disabled = true;
|
|
788
|
-
fetchBtn.textContent = 'Loading models…';
|
|
789
|
-
try {
|
|
790
|
-
const result = await reviewRequest('/api/review/connection', {
|
|
791
|
-
action: 'models',
|
|
792
|
-
provider: selectedProviderId,
|
|
793
|
-
apiKey: key,
|
|
794
|
-
...(isCompat ? {endpoint: endpointToQuery, preset: selectedPresetId} : {}),
|
|
795
|
-
});
|
|
796
|
-
if (!result.models?.length) {
|
|
797
|
-
$('tora-api-error').textContent = 'No playable-ready models were returned for this API key.';
|
|
798
|
-
} else {
|
|
799
|
-
const provider = providersList().find(item => item.id === selectedProviderId);
|
|
800
|
-
discoveredModels[cacheKeyFor(provider)] = result.models;
|
|
801
|
-
selectedModelId = result.models[0].id;
|
|
802
|
-
renderModels();
|
|
803
|
-
}
|
|
804
|
-
} catch (error) {
|
|
805
|
-
$('tora-api-error').textContent = errorLabels[error.message] ?? error.message;
|
|
806
|
-
} finally {
|
|
807
|
-
busy = false;
|
|
808
|
-
fetchBtn.disabled = false;
|
|
809
|
-
fetchBtn.textContent = 'Load models from key';
|
|
810
|
-
}
|
|
811
|
-
};
|
|
812
|
-
|
|
813
|
-
$('tora-api-disconnect').onclick = async () => {
|
|
814
|
-
if (busy) return;
|
|
815
|
-
busy = true;
|
|
816
|
-
$('tora-api-error').textContent = '';
|
|
817
|
-
try {
|
|
818
|
-
await reviewRequest('/api/review/connection', {action: 'disconnect'});
|
|
819
|
-
await refresh();
|
|
820
|
-
renderModal();
|
|
821
|
-
} catch (error) {
|
|
822
|
-
$('tora-api-error').textContent = errorLabels[error.message] ?? error.message;
|
|
823
|
-
} finally {
|
|
824
|
-
busy = false;
|
|
825
|
-
}
|
|
826
|
-
};
|
|
827
|
-
|
|
828
|
-
if (pillButton) pillButton.onclick = () => open();
|
|
829
|
-
|
|
830
|
-
return {
|
|
831
|
-
refresh,
|
|
832
|
-
open,
|
|
833
|
-
close,
|
|
834
|
-
getStatus: () => status,
|
|
835
|
-
};
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
|
|
839
366
|
function loadRuntime() {
|
|
840
367
|
return new Promise((resolve, reject) => {
|
|
841
368
|
const script = reviewElement('script');
|
|
@@ -855,24 +382,21 @@ function download(name, contents, mime) {
|
|
|
855
382
|
}
|
|
856
383
|
|
|
857
384
|
const statusLabels = {
|
|
858
|
-
waiting: '
|
|
859
|
-
claimed: '
|
|
860
|
-
building: 'Building
|
|
861
|
-
|
|
862
|
-
'model-error': 'Could not complete automatically',
|
|
863
|
-
candidate: 'Revision ready to compare',
|
|
385
|
+
waiting: 'Waiting for external client',
|
|
386
|
+
claimed: 'Claimed by external client',
|
|
387
|
+
building: 'Building candidate',
|
|
388
|
+
candidate: 'Candidate ready to compare',
|
|
864
389
|
promoted: 'Applied ✓',
|
|
865
390
|
discarded: 'Discarded',
|
|
866
|
-
rejected: '
|
|
867
|
-
'needs-scope': 'Needs
|
|
868
|
-
'needs-clarification': 'Quick question for you',
|
|
391
|
+
rejected: 'Proposal blocked',
|
|
392
|
+
'needs-scope': 'Needs broader scope',
|
|
869
393
|
};
|
|
870
394
|
|
|
871
395
|
const playIcon = '<svg viewBox="0 0 20 20" width="16" height="16" aria-hidden="true"><path d="M5.5 3.6 16.2 10 5.5 16.4Z" fill="currentColor" stroke="currentColor" stroke-width="1.4" stroke-linejoin="round"/></svg>';
|
|
872
396
|
const pauseIcon = '<svg viewBox="0 0 20 20" width="16" height="16" aria-hidden="true"><rect x="4.5" y="3.5" width="3.8" height="13" rx="1" fill="currentColor"/><rect x="11.7" y="3.5" width="3.8" height="13" rx="1" fill="currentColor"/></svg>';
|
|
873
397
|
const restartIcon = '<svg viewBox="0 0 20 20" width="15" height="15" aria-hidden="true"><path d="M15.8 10a5.8 5.8 0 1 1-1.6-4" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"/><path d="M14.4 2.8v3.6h-3.6" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/></svg>';
|
|
874
398
|
|
|
875
|
-
function makePreview(figure, orientation, labelText) {
|
|
399
|
+
function makePreview(figure, orientation, labelText, sharedImageCache) {
|
|
876
400
|
const screen = figure.querySelector('.review-screen');
|
|
877
401
|
const toggleBtn = figure.querySelector('[data-role="toggle-play"]');
|
|
878
402
|
const restartBtn = figure.querySelector('[data-role="restart-play"]');
|
|
@@ -881,7 +405,15 @@ function makePreview(figure, orientation, labelText) {
|
|
|
881
405
|
const picker = reviewElement('div', '', 'review-picker');
|
|
882
406
|
picker.dataset.active = 'false';
|
|
883
407
|
picker.setAttribute('aria-hidden', 'true');
|
|
884
|
-
|
|
408
|
+
const safeOverlay = reviewElement('div', '', 'tora-safe-overlay');
|
|
409
|
+
safeOverlay.hidden = true;
|
|
410
|
+
safeOverlay.setAttribute('aria-hidden', 'true');
|
|
411
|
+
safeOverlay.innerHTML = `
|
|
412
|
+
<span class="tora-safe-zone tora-safe-tl" title="Top-left ad overlay (mute / countdown)">Mute</span>
|
|
413
|
+
<span class="tora-safe-zone tora-safe-tr" title="Top-right ad overlay (Close X)">✕ Close</span>
|
|
414
|
+
<span class="tora-safe-zone tora-safe-bl" title="Bottom-left ad info / privacy badge">Ad Info</span>
|
|
415
|
+
`;
|
|
416
|
+
screen.append(canvas, safeOverlay, picker);
|
|
885
417
|
let runtime;
|
|
886
418
|
let playing = false;
|
|
887
419
|
let freshStart = true;
|
|
@@ -899,18 +431,38 @@ function makePreview(figure, orientation, labelText) {
|
|
|
899
431
|
syncButton();
|
|
900
432
|
if (restartBtn) restartBtn.innerHTML = restartIcon;
|
|
901
433
|
|
|
434
|
+
const mount = ({project, assets}) => {
|
|
435
|
+
runtime?.destroy();
|
|
436
|
+
runtime = globalThis.ToraNative.mountNative({...project, assets}, canvas, {review: true, sharedImageCache});
|
|
437
|
+
playing = false;
|
|
438
|
+
freshStart = true;
|
|
439
|
+
syncButton();
|
|
440
|
+
};
|
|
441
|
+
|
|
902
442
|
return {
|
|
903
443
|
picker,
|
|
444
|
+
safeOverlay,
|
|
904
445
|
toggleBtn,
|
|
905
446
|
restartBtn,
|
|
906
447
|
isPlaying: () => playing,
|
|
907
448
|
orient: () => { figure.dataset.orientation = orientation.value; },
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
449
|
+
setDevice: device => { figure.dataset.device = device; },
|
|
450
|
+
setSafeAreas: visible => { safeOverlay.hidden = !visible; },
|
|
451
|
+
mount,
|
|
452
|
+
applyVariant: data => {
|
|
453
|
+
const next = {...data.project, assets: data.assets};
|
|
454
|
+
if (runtime?.canApplyVariantInPlace?.(next)) {
|
|
455
|
+
try {
|
|
456
|
+
runtime.applyVariantPreview(next);
|
|
457
|
+
playing = false;
|
|
458
|
+
freshStart = true;
|
|
459
|
+
syncButton();
|
|
460
|
+
return;
|
|
461
|
+
} catch (error) {
|
|
462
|
+
if (error.message !== 'E_NATIVE_VARIANT_REMOUNT') throw error;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
mount(data);
|
|
914
466
|
},
|
|
915
467
|
playback: () => {
|
|
916
468
|
runtime.restart();
|
|
@@ -939,7 +491,7 @@ function makePreview(figure, orientation, labelText) {
|
|
|
939
491
|
playing = false;
|
|
940
492
|
syncButton();
|
|
941
493
|
},
|
|
942
|
-
state: () => runtime
|
|
494
|
+
state: () => runtime?.state?.(),
|
|
943
495
|
capture: () => canvas.toDataURL('image/jpeg', .7).split(',')[1],
|
|
944
496
|
pick: event => runtime.pickReview(event.clientX, event.clientY),
|
|
945
497
|
outlines: (ids = []) => {
|
|
@@ -1001,31 +553,69 @@ export function populateDemosMenu(menuEl, listEl, currentProjectId = '') {
|
|
|
1001
553
|
|
|
1002
554
|
export async function openReview(projectId, initialMetadata) {
|
|
1003
555
|
const $ = reviewShell(`
|
|
556
|
+
<div class="tora-sandbox-banner" id="tora-sandbox-banner" hidden role="region" aria-label="Online Sandbox Notice">
|
|
557
|
+
<span><strong>Online Sandbox:</strong> Edit text, colors, and variants live in your browser, or import/download <code>.tora.json</code>.</span>
|
|
558
|
+
<span class="tora-sandbox-sub">Run <code>npx @tora-editor/tora editor</code> locally for asset compression, Creative QA, and verified ad-network packaging.</span>
|
|
559
|
+
</div>
|
|
1004
560
|
<header class="review-header">
|
|
1005
561
|
<img class="review-wordmark" src="./brand/tora-wordmark.svg" alt="Tora">
|
|
1006
562
|
<h1 id="review-title"></h1>
|
|
1007
563
|
<nav aria-label="Project actions" class="review-actions">
|
|
1008
564
|
<a class="review-button" id="review-new-link" href="?view=new&from=${encodeURIComponent(projectId)}">+ New</a>
|
|
565
|
+
<button type="button" id="review-import-btn" title="Open an editable .tora.json playable file">Import .tora.json</button>
|
|
566
|
+
<input type="file" id="review-import-picker" accept=".json,.tora.json,application/json" hidden>
|
|
1009
567
|
<details class="review-menu tora-demo-menu" id="review-demos" hidden>
|
|
1010
568
|
<summary>Demos</summary>
|
|
1011
569
|
<div class="tora-demo-list" id="review-demo-list"></div>
|
|
1012
570
|
</details>
|
|
1013
|
-
<button type="button"
|
|
1014
|
-
<button type="button" id="review-
|
|
571
|
+
<button type="button" id="review-undo" hidden title="Undo last edit (Ctrl/Cmd+Z)">Undo</button>
|
|
572
|
+
<button type="button" id="review-redo" hidden title="Redo edit (Ctrl/Cmd+Shift+Z)">Redo</button>
|
|
573
|
+
<details class="review-menu review-qa-menu" id="review-qa-menu">
|
|
574
|
+
<summary id="review-qa-summary">Check QA</summary>
|
|
575
|
+
<div class="tora-qa-panel">
|
|
576
|
+
<p class="tora-budget-intro" id="review-qa-intro">Test this playable across 4 mobile/tablet screen sizes, audio unlock, and ad-network limits.</p>
|
|
577
|
+
<button type="button" id="review-qa-run" class="review-primary">Run 4-Screen QA Check</button>
|
|
578
|
+
<div id="review-qa-results" class="tora-qa-results" hidden></div>
|
|
579
|
+
<p class="review-error" id="review-qa-error" role="alert"></p>
|
|
580
|
+
<p class="tora-export-hint">Automated checks verify layout, audio, and rules only — always inspect visuals and test on real phones before launch.</p>
|
|
581
|
+
</div>
|
|
582
|
+
</details>
|
|
583
|
+
<details class="review-menu review-budget" id="review-budget">
|
|
584
|
+
<summary id="review-budget-summary">Budget · checking</summary>
|
|
585
|
+
<div class="tora-budget-panel">
|
|
586
|
+
<p class="tora-budget-intro" id="review-budget-intro">Estimated until this exact export has been packaged.</p>
|
|
587
|
+
<dl class="tora-budget-breakdown" aria-label="Asset budget breakdown">
|
|
588
|
+
<div><dt>Images</dt><dd id="review-budget-images">—</dd></div>
|
|
589
|
+
<div><dt>3D</dt><dd id="review-budget-models">—</dd></div>
|
|
590
|
+
<div><dt>Audio</dt><dd id="review-budget-audio">—</dd></div>
|
|
591
|
+
</dl>
|
|
592
|
+
<div class="tora-budget-assets">
|
|
593
|
+
<strong>Largest assets</strong>
|
|
594
|
+
<ol id="review-budget-top"></ol>
|
|
595
|
+
</div>
|
|
596
|
+
<p class="tora-export-hint" id="review-budget-unused"></p>
|
|
597
|
+
<label class="tora-fit-toggle"><input type="checkbox" id="review-auto-fit">Auto-shrink to fit this ad network's limit</label>
|
|
598
|
+
<p class="tora-export-hint">Auto-shrink optimizes delivery images and audio for export while keeping your original editable project unchanged.</p>
|
|
599
|
+
<p class="review-error" id="review-budget-error" role="alert"></p>
|
|
600
|
+
<button type="button" id="review-budget-refresh">Refresh budget</button>
|
|
601
|
+
</div>
|
|
602
|
+
</details>
|
|
1015
603
|
<details class="review-menu" id="review-export-menu">
|
|
1016
604
|
<summary>Export</summary>
|
|
1017
605
|
<div class="tora-export-panel">
|
|
1018
|
-
<label class="tora-export-target-label">
|
|
606
|
+
<label class="tora-export-target-label">Ad network
|
|
1019
607
|
<select id="review-export-target" aria-label="Network target"></select>
|
|
1020
608
|
</label>
|
|
1021
609
|
<form class="review-store" id="review-store">
|
|
1022
|
-
<label><span>Store
|
|
610
|
+
<label><span>App Store / Google Play link <span class="tora-optional-tag">(optional)</span></span>
|
|
1023
611
|
<input id="review-store-url" type="url" placeholder="https://play.google.com/store/... or App Store">
|
|
1024
612
|
</label>
|
|
1025
|
-
<span class="tora-export-hint">Optional for browser
|
|
613
|
+
<span class="tora-export-hint">Optional for browser previews; required when exporting for Unity Ads or AppLovin.</span>
|
|
1026
614
|
</form>
|
|
1027
615
|
<button type="button" id="review-export" class="review-primary" disabled>Approve & export (Unity Ads)</button>
|
|
1028
616
|
<button type="button" id="review-export-draft" disabled>Download browser draft (no store URL)</button>
|
|
617
|
+
<button type="button" id="review-export-matrix" disabled>Export variant matrix</button>
|
|
618
|
+
<section class="tora-matrix-job" id="review-matrix-job" aria-label="Variant matrix export" role="status" aria-live="polite" hidden></section>
|
|
1029
619
|
<button type="button" id="review-bundle" disabled>Download editable project (.tora.json)</button>
|
|
1030
620
|
<p class="tora-export-hint" id="review-export-verification">Export checks cover static structure and mock-host lifecycle only. Verify the exact file in the selected network's official preview tool and on physical iOS/Android devices before launch. This is not official network acceptance.</p>
|
|
1031
621
|
</div>
|
|
@@ -1037,12 +627,35 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
1037
627
|
<div class="review-toolbar">
|
|
1038
628
|
<div id="review-moments" class="review-actions" role="group" aria-label="Review moments"></div>
|
|
1039
629
|
<button type="button" id="review-replay-change" hidden>Replay change</button>
|
|
630
|
+
<select id="review-device" aria-label="Preview device size" disabled>
|
|
631
|
+
<option value="modern-phone">Modern Phone (390×700)</option>
|
|
632
|
+
<option value="small-phone">Small Phone (320×568)</option>
|
|
633
|
+
<option value="tablet">Tablet (768×1024)</option>
|
|
634
|
+
</select>
|
|
1040
635
|
<select id="review-orientation" aria-label="Screen orientation" disabled>
|
|
1041
636
|
<option value="portrait">Portrait</option><option value="landscape">Landscape</option>
|
|
1042
637
|
</select>
|
|
638
|
+
<button type="button" id="review-safe-areas" aria-pressed="false" title="Show where ad networks place Close X, Mute, and Privacy icons">Safe areas</button>
|
|
1043
639
|
</div>
|
|
640
|
+
<section class="review-variants" aria-label="Creative variants">
|
|
641
|
+
<div class="review-variant-strip" id="review-variant-strip" role="group" aria-label="Preview variant"></div>
|
|
642
|
+
<details class="review-variant-delta" id="review-variant-delta" hidden>
|
|
643
|
+
<summary id="review-variant-delta-summary">Variant changes</summary>
|
|
644
|
+
<div class="review-variant-delta-body">
|
|
645
|
+
<div class="review-variant-delta-list" id="review-variant-delta-list"></div>
|
|
646
|
+
<p class="review-variant-diagnostics" id="review-variant-diagnostics"></p>
|
|
647
|
+
<div class="review-actions">
|
|
648
|
+
<button type="button" id="review-variant-edit">Edit variant</button>
|
|
649
|
+
<button type="button" id="review-variant-compare">Compare vs Base</button>
|
|
650
|
+
<button type="button" id="review-variant-reset">Reset to Base</button>
|
|
651
|
+
<button type="button" id="review-variant-delete" class="tora-danger-btn">Delete</button>
|
|
652
|
+
</div>
|
|
653
|
+
</div>
|
|
654
|
+
</details>
|
|
655
|
+
<p class="review-variant-status" id="review-variant-status" role="status"></p>
|
|
656
|
+
</section>
|
|
1044
657
|
<div id="review-previews" class="review-previews" data-compare="false" data-orientation="portrait">
|
|
1045
|
-
<figure id="review-before" class="review-preview" data-orientation="portrait">
|
|
658
|
+
<figure id="review-before" class="review-preview" data-orientation="portrait" data-device="modern-phone">
|
|
1046
659
|
<div class="review-preview-bar">
|
|
1047
660
|
<figcaption hidden>Before</figcaption>
|
|
1048
661
|
<div class="review-preview-controls">
|
|
@@ -1052,7 +665,7 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
1052
665
|
</div>
|
|
1053
666
|
<div class="review-screen"></div>
|
|
1054
667
|
</figure>
|
|
1055
|
-
<figure id="review-after" class="review-preview" data-orientation="portrait" hidden>
|
|
668
|
+
<figure id="review-after" class="review-preview" data-orientation="portrait" data-device="modern-phone" hidden>
|
|
1056
669
|
<div class="review-preview-bar">
|
|
1057
670
|
<figcaption>After</figcaption>
|
|
1058
671
|
<div class="review-preview-controls">
|
|
@@ -1064,96 +677,212 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
1064
677
|
</figure>
|
|
1065
678
|
</div>
|
|
1066
679
|
</section>
|
|
1067
|
-
<aside class="review-side tora-chat-side" aria-label="Studio
|
|
680
|
+
<aside class="review-side tora-chat-side" aria-label="Studio controls">
|
|
1068
681
|
<div class="tora-chat-head">
|
|
1069
|
-
<div>
|
|
1070
|
-
<
|
|
1071
|
-
<
|
|
682
|
+
<div class="tora-side-tabs" role="tablist" aria-label="Editor mode">
|
|
683
|
+
<button type="button" role="tab" id="review-tab-chat" aria-selected="true" aria-controls="review-chat-pane" class="tora-side-tab">Review notes</button>
|
|
684
|
+
<button type="button" role="tab" id="review-tab-quick" aria-selected="false" aria-controls="review-quick-edit-pane" class="tora-side-tab">Quick Edit</button>
|
|
1072
685
|
</div>
|
|
1073
686
|
<button type="button" class="tora-target-btn" id="review-note-toggle" aria-expanded="false" aria-controls="review-attachment" disabled>🎯 Target</button>
|
|
1074
687
|
</div>
|
|
1075
688
|
|
|
1076
|
-
<div class="tora-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
<div class="tora-
|
|
1081
|
-
|
|
1082
|
-
<
|
|
1083
|
-
<div class="review-
|
|
1084
|
-
|
|
1085
|
-
<
|
|
1086
|
-
<
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
689
|
+
<div id="review-quick-edit-pane" class="tora-qe-scroll" role="tabpanel" aria-labelledby="review-tab-quick" hidden></div>
|
|
690
|
+
|
|
691
|
+
<div id="review-chat-pane" class="tora-chat-pane" role="tabpanel" aria-labelledby="review-tab-chat">
|
|
692
|
+
<div class="tora-chat-scroll" id="review-thread" aria-live="polite">
|
|
693
|
+
<div class="tora-bubble tora-bubble-assistant" id="review-welcome">
|
|
694
|
+
<div class="tora-bubble-meta"><strong>Tora</strong><span>Ready</span></div>
|
|
695
|
+
<p>Write visual review notes and choose the native records your connected AI client may change. Submitting creates a handoff only; it never runs a model.</p>
|
|
696
|
+
<div class="tora-starter-row" id="review-quick-chips"></div>
|
|
697
|
+
<details id="review-win-sound" hidden>
|
|
698
|
+
<summary>Win sound</summary>
|
|
699
|
+
<div class="review-win-sound-controls">
|
|
700
|
+
<select id="review-win-sound-option" aria-label="Win sound"></select>
|
|
701
|
+
<button type="button" id="review-win-sound-preview">Listen</button>
|
|
702
|
+
<button type="button" id="review-win-sound-apply">Use sound</button>
|
|
703
|
+
</div>
|
|
704
|
+
<p id="review-win-sound-status" aria-live="polite"></p>
|
|
705
|
+
</details>
|
|
706
|
+
</div>
|
|
707
|
+
<div id="review-requests" class="tora-chat-turns"></div>
|
|
708
|
+
<div id="review-active" class="tora-chat-turns"></div>
|
|
709
|
+
<div id="review-local-log" class="tora-chat-turns"></div>
|
|
1090
710
|
</div>
|
|
1091
|
-
<div id="review-requests" class="tora-chat-turns"></div>
|
|
1092
|
-
<div id="review-active" class="tora-chat-turns"></div>
|
|
1093
|
-
<div id="review-local-log" class="tora-chat-turns"></div>
|
|
1094
|
-
</div>
|
|
1095
711
|
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
712
|
+
<div class="tora-chat-dock">
|
|
713
|
+
<div class="tora-candidate-banner" id="review-candidate-banner" hidden>
|
|
714
|
+
Compare Before & After on the left, then choose <strong>Use this version</strong> or <strong>Discard</strong> above to continue reviewing.
|
|
715
|
+
</div>
|
|
716
|
+
<form class="tora-composer" id="review-note">
|
|
717
|
+
<div class="review-attachment" id="review-attachment" hidden>
|
|
718
|
+
<div class="tora-attachment-head">
|
|
719
|
+
<strong id="review-pick-help">Click the preview or pick what to change</strong>
|
|
720
|
+
<button type="button" class="tora-attach-remove" id="review-clear-target" aria-label="Clear target">×</button>
|
|
721
|
+
</div>
|
|
722
|
+
<div class="tora-scope-presets" id="review-scope-presets" role="group" aria-label="Quick scope presets"></div>
|
|
723
|
+
<select id="review-target" aria-label="Feedback target"></select>
|
|
724
|
+
<div class="tora-scope-selected" id="review-scope-selected" hidden></div>
|
|
725
|
+
<label class="tora-scope-creates-row">
|
|
726
|
+
<input type="checkbox" id="review-allow-creates">
|
|
727
|
+
<span>Allow agent to add new elements</span>
|
|
728
|
+
</label>
|
|
729
|
+
<details id="review-fields" hidden>
|
|
730
|
+
<summary id="review-fields-summary">Customize exact records</summary>
|
|
731
|
+
<input type="search" id="review-scope-filter" class="tora-scope-filter" placeholder="Filter records…" aria-label="Filter records">
|
|
732
|
+
<div id="review-field-options"></div>
|
|
733
|
+
</details>
|
|
1105
734
|
</div>
|
|
1106
|
-
|
|
1107
|
-
<
|
|
1108
|
-
|
|
1109
|
-
|
|
735
|
+
|
|
736
|
+
<div class="tora-attach-strip" id="review-ref-strip" hidden></div>
|
|
737
|
+
|
|
738
|
+
<details class="review-note-list" id="review-queued" hidden>
|
|
739
|
+
<summary id="review-queued-label">Notes in this message</summary>
|
|
740
|
+
<ul id="review-queued-notes"></ul>
|
|
1110
741
|
</details>
|
|
1111
|
-
</div>
|
|
1112
742
|
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
<button type="button" class="tora-plus-btn" id="review-plus-btn" aria-label="Add target, asset, or photo" aria-expanded="false" aria-controls="review-plus-menu">+</button>
|
|
1123
|
-
<div class="tora-plus-menu" id="review-plus-menu" hidden role="menu">
|
|
1124
|
-
<button type="button" role="menuitem" id="rev-menu-target"><strong>Target a part on screen</strong><span>Highlight an element & unlock instant $0 controls</span></button>
|
|
1125
|
-
<button type="button" role="menuitem" id="rev-menu-asset"><strong>Upload game asset</strong><span>Add PNG, JPEG, or WAV/MP3 directly to this playable</span></button>
|
|
1126
|
-
<button type="button" role="menuitem" id="rev-menu-ref"><strong>Attach reference photo or video</strong><span>Share visual context with your verified AI model</span></button>
|
|
1127
|
-
<button type="button" role="menuitem" id="rev-menu-queue"><strong>Queue multiple notes</strong><span>Bundle current message and write another</span></button>
|
|
743
|
+
<div class="tora-composer-bar">
|
|
744
|
+
<div class="tora-plus-wrap">
|
|
745
|
+
<button type="button" class="tora-plus-btn" id="review-plus-btn" aria-label="Add target, asset, or photo" aria-expanded="false" aria-controls="review-plus-menu">+</button>
|
|
746
|
+
<div class="tora-plus-menu" id="review-plus-menu" hidden role="menu">
|
|
747
|
+
<button type="button" role="menuitem" id="rev-menu-target"><strong>Choose review scope</strong><span>Select records the external agent may change</span></button>
|
|
748
|
+
<button type="button" role="menuitem" id="rev-menu-asset"><strong>Upload game asset</strong><span>Add PNG, JPEG, or WAV/MP3 directly to this playable</span></button>
|
|
749
|
+
<button type="button" role="menuitem" id="rev-menu-ref"><strong>Attach a review frame</strong><span>Capture visual context for the external agent</span></button>
|
|
750
|
+
<button type="button" role="menuitem" id="rev-menu-queue"><strong>Queue multiple notes</strong><span>Bundle current message and write another</span></button>
|
|
751
|
+
</div>
|
|
1128
752
|
</div>
|
|
753
|
+
<textarea id="review-note-text" aria-label="Revision note" rows="1" maxlength="2000" placeholder="Describe your changes" disabled></textarea>
|
|
754
|
+
<button type="submit" class="review-primary tora-send-btn" id="review-submit" disabled aria-label="Send">Send ↑</button>
|
|
1129
755
|
</div>
|
|
1130
|
-
<textarea id="review-note-text" aria-label="Revision note" rows="1" maxlength="2000" placeholder="Tell Tora what to change…" disabled></textarea>
|
|
1131
|
-
<button type="submit" class="review-primary tora-send-btn" id="review-submit" disabled aria-label="Send">Send ↑</button>
|
|
1132
|
-
</div>
|
|
1133
756
|
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
</
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
757
|
+
<div class="tora-composer-foot">
|
|
758
|
+
<span id="review-route-hint">External client required to propose changes</span>
|
|
759
|
+
</div>
|
|
760
|
+
<input type="file" id="review-asset-picker" accept=".png,.jpg,.jpeg,.wav,.mp3,.ogg,.m4a" hidden>
|
|
761
|
+
<input type="file" id="review-ref-picker" accept=".png,.jpg,.jpeg,.webp,video/mp4,video/webm,video/quicktime,.mp4,.webm,.mov" hidden>
|
|
762
|
+
</form>
|
|
763
|
+
</div>
|
|
764
|
+
</div>
|
|
765
|
+
<div class="tora-side-foot">
|
|
766
|
+
<p id="review-status" role="status"></p>
|
|
767
|
+
<p class="review-error" id="review-error" role="alert"></p>
|
|
1145
768
|
</div>
|
|
1146
769
|
</aside>
|
|
1147
770
|
</main>
|
|
771
|
+
<dialog class="tora-modal" id="review-variant-dialog" aria-labelledby="review-variant-dialog-title">
|
|
772
|
+
<form class="tora-modal-card tora-variant-form" id="review-variant-form">
|
|
773
|
+
<div class="tora-modal-head">
|
|
774
|
+
<div><h2 id="review-variant-dialog-title">Create a variant</h2><p class="tora-modal-sub">Test a new hook, easier timer, standout CTA, or translation without changing your Base playable.</p></div>
|
|
775
|
+
<button type="button" class="tora-modal-close" id="review-variant-close" aria-label="Close">×</button>
|
|
776
|
+
</div>
|
|
777
|
+
<div class="tora-variant-id-row">
|
|
778
|
+
<label><span>Variant name</span>
|
|
779
|
+
<input id="review-variant-label" type="text" required maxlength="60" autocomplete="off" placeholder="Spanish (LATAM) or Short Hook">
|
|
780
|
+
</label>
|
|
781
|
+
<label><span>Short ID <span class="tora-optional-tag">(auto)</span></span>
|
|
782
|
+
<input id="review-variant-id" type="text" required pattern="[a-z][a-z0-9\\-]{1,47}" maxlength="48" autocomplete="off" placeholder="short-hook">
|
|
783
|
+
</label>
|
|
784
|
+
</div>
|
|
785
|
+
<label>What do you want to test?
|
|
786
|
+
<select id="review-variant-preset">
|
|
787
|
+
<option value="shorter-hook">Shorter opening hook</option>
|
|
788
|
+
<option value="easier-win">Easier win (longer timer)</option>
|
|
789
|
+
<option value="high-contrast-cta">High-contrast Install button</option>
|
|
790
|
+
<option value="locale">Language / Localization</option>
|
|
791
|
+
<option value="custom">Custom (blank override)</option>
|
|
792
|
+
</select>
|
|
793
|
+
</label>
|
|
794
|
+
<label id="review-variant-hook-wrap">Opening hook text <span class="tora-optional-tag">(optional)</span>
|
|
795
|
+
<input id="review-variant-hook-text" type="text" maxlength="40" autocomplete="off" placeholder="PLAY NOW">
|
|
796
|
+
</label>
|
|
797
|
+
<div id="review-variant-language-wrap" class="tora-variant-lang-row" hidden>
|
|
798
|
+
<label><span>Language</span>
|
|
799
|
+
<select id="review-variant-language-select" aria-label="Pick language">
|
|
800
|
+
<option value="es-419">Spanish (LATAM) · es-419</option>
|
|
801
|
+
<option value="es-ES">Spanish (Spain) · es-ES</option>
|
|
802
|
+
<option value="fr-FR">French · fr-FR</option>
|
|
803
|
+
<option value="de-DE">German · de-DE</option>
|
|
804
|
+
<option value="pt-BR">Portuguese (Brazil) · pt-BR</option>
|
|
805
|
+
<option value="ja-JP">Japanese · ja-JP</option>
|
|
806
|
+
<option value="ko-KR">Korean · ko-KR</option>
|
|
807
|
+
<option value="zh-Hans">Chinese (Simplified) · zh-Hans</option>
|
|
808
|
+
<option value="zh-Hant">Chinese (Traditional) · zh-Hant</option>
|
|
809
|
+
<option value="ar">Arabic (RTL) · ar</option>
|
|
810
|
+
<option value="he">Hebrew (RTL) · he</option>
|
|
811
|
+
<option value="tr-TR">Turkish · tr-TR</option>
|
|
812
|
+
<option value="it-IT">Italian · it-IT</option>
|
|
813
|
+
<option value="hi-IN">Hindi · hi-IN</option>
|
|
814
|
+
<option value="en-US">English (US) · en-US</option>
|
|
815
|
+
<option value="custom">Other language code…</option>
|
|
816
|
+
</select>
|
|
817
|
+
</label>
|
|
818
|
+
<label><span class="tora-lang-code-head">Language code <span id="review-variant-rtl-badge" class="tora-pill tora-pill-mint" hidden>RTL auto-layout</span></span>
|
|
819
|
+
<input id="review-variant-language" type="text" maxlength="16" autocomplete="off" placeholder="es-419">
|
|
820
|
+
</label>
|
|
821
|
+
</div>
|
|
822
|
+
<div id="review-variant-localization-fields" class="tora-variant-localization" hidden>
|
|
823
|
+
<div class="tora-loc-toolbar">
|
|
824
|
+
<span id="review-variant-loc-progress" class="tora-export-hint">Translations supplied by you or your connected AI client:</span>
|
|
825
|
+
</div>
|
|
826
|
+
<div id="review-variant-translation-rows" class="tora-loc-table"></div>
|
|
827
|
+
<details class="tora-optional-details" id="review-variant-raw-json">
|
|
828
|
+
<summary>Advanced: Edit raw JSON maps</summary>
|
|
829
|
+
<div class="tora-loc-json-fields">
|
|
830
|
+
<label>Component text map (JSON)<textarea id="review-variant-texts" rows="3" spellcheck="false">{}</textarea></label>
|
|
831
|
+
<label>Runtime action text map (JSON)<textarea id="review-variant-action-texts" rows="3" spellcheck="false">{}</textarea></label>
|
|
832
|
+
<label>String variable map (JSON)<textarea id="review-variant-variables" rows="3" spellcheck="false">{}</textarea></label>
|
|
833
|
+
</div>
|
|
834
|
+
</details>
|
|
835
|
+
</div>
|
|
836
|
+
<p class="review-error" id="review-variant-error" role="alert"></p>
|
|
837
|
+
<div class="tora-modal-actions"><button type="submit" class="review-primary" id="review-variant-create">Create & preview</button></div>
|
|
838
|
+
</form>
|
|
839
|
+
</dialog>
|
|
840
|
+
<dialog class="tora-modal" id="review-matrix-dialog" aria-labelledby="review-matrix-dialog-title">
|
|
841
|
+
<form class="tora-modal-card tora-matrix-form" id="review-matrix-form">
|
|
842
|
+
<div class="tora-modal-head">
|
|
843
|
+
<div><h2 id="review-matrix-dialog-title">Export variant matrix</h2><p class="tora-modal-sub">Runs in the background against this revision. Failures are shown first; successful exports are still written.</p></div>
|
|
844
|
+
<button type="button" class="tora-modal-close" id="review-matrix-close" aria-label="Close">×</button>
|
|
845
|
+
</div>
|
|
846
|
+
<fieldset><legend>Variants</legend><div class="tora-matrix-choices" id="review-matrix-variants"></div></fieldset>
|
|
847
|
+
<fieldset><legend>Network targets</legend><div class="tora-matrix-choices" id="review-matrix-targets"></div></fieldset>
|
|
848
|
+
<p class="tora-export-hint" id="review-matrix-fit"></p>
|
|
849
|
+
<p class="review-error" id="review-matrix-error" role="alert"></p>
|
|
850
|
+
<div class="tora-modal-actions"><button type="submit" class="review-primary" id="review-matrix-start">Start matrix export</button></div>
|
|
851
|
+
</form>
|
|
852
|
+
</dialog>
|
|
1148
853
|
`);
|
|
1149
854
|
|
|
1150
855
|
const orientation = $('review-orientation');
|
|
1151
|
-
|
|
1152
|
-
const
|
|
856
|
+
$('review-title').textContent = initialMetadata?.name ?? projectId;
|
|
857
|
+
const sharedImageCache = new Map();
|
|
858
|
+
const before = makePreview($('review-before'), orientation, 'Before', sharedImageCache);
|
|
859
|
+
const after = makePreview($('review-after'), orientation, 'After', sharedImageCache);
|
|
1153
860
|
const prefix = '/api/projects/' + encodeURIComponent(projectId);
|
|
1154
861
|
const api = (route, body) => reviewRequest(prefix + route, body);
|
|
1155
862
|
let metadata = initialMetadata;
|
|
863
|
+
metadata.variants ??= {format: 'tora-variants-1', revision: 0, variants: []};
|
|
864
|
+
metadata.moments ??= [{id: 'opening', label: 'Opening'}];
|
|
865
|
+
metadata.targets ??= [];
|
|
866
|
+
metadata.scopes ??= [];
|
|
867
|
+
const isHosted = Boolean(globalThis.toraHostedReview);
|
|
1156
868
|
let displayedRevision;
|
|
869
|
+
let displayedVariantId;
|
|
870
|
+
let displayedVariantHash;
|
|
871
|
+
let activeVariantId = 'base';
|
|
872
|
+
let variantCompare = false;
|
|
873
|
+
let variantDrawSignature;
|
|
874
|
+
let variantSwitchVersion = 0;
|
|
875
|
+
let budgetRequestVersion = 0;
|
|
876
|
+
let budgetKey;
|
|
877
|
+
let budgetData;
|
|
878
|
+
let budgetError;
|
|
879
|
+
let qaResultKey = null;
|
|
880
|
+
let matrixJob;
|
|
881
|
+
let matrixPollVersion = 0;
|
|
882
|
+
let matrixPollTimer;
|
|
883
|
+
let matrixPollError;
|
|
884
|
+
let matrixExpected = 0;
|
|
885
|
+
let matrixRevisionId;
|
|
1157
886
|
let candidateId;
|
|
1158
887
|
let comparisonVersion;
|
|
1159
888
|
let moment;
|
|
@@ -1163,10 +892,10 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
1163
892
|
let queuedExpected;
|
|
1164
893
|
let queuedSignature;
|
|
1165
894
|
let editingRequestId;
|
|
1166
|
-
let resolvingId;
|
|
1167
|
-
let pendingRetryRequestId;
|
|
1168
895
|
let attachedRefFrame = null;
|
|
1169
|
-
let
|
|
896
|
+
let selectedScopeIds = new Set();
|
|
897
|
+
let scopeFilterText = '';
|
|
898
|
+
let showAllScopeRecords = false;
|
|
1170
899
|
let busy = false;
|
|
1171
900
|
let actions = Promise.resolve();
|
|
1172
901
|
let requestSignature;
|
|
@@ -1197,11 +926,29 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
1197
926
|
}));
|
|
1198
927
|
if (exportTargets.some(target => target.id === previous)) exportTargetSelect.value = previous;
|
|
1199
928
|
};
|
|
929
|
+
const currentQaKey = () => JSON.stringify([
|
|
930
|
+
metadata.expected?.revisionId,
|
|
931
|
+
activeVariantId,
|
|
932
|
+
selectedExportTarget()?.id,
|
|
933
|
+
$('review-auto-fit').checked,
|
|
934
|
+
]);
|
|
935
|
+
function invalidateQaIfStale() {
|
|
936
|
+
if (!qaResultKey || qaResultKey === currentQaKey()) return;
|
|
937
|
+
qaResultKey = null;
|
|
938
|
+
$('review-qa-summary').textContent = 'Check QA';
|
|
939
|
+
delete $('review-qa-menu').dataset.status;
|
|
940
|
+
$('review-qa-results').hidden = true;
|
|
941
|
+
$('review-qa-error').textContent = '';
|
|
942
|
+
}
|
|
943
|
+
|
|
1200
944
|
const updateExportButton = () => {
|
|
1201
945
|
const target = selectedExportTarget();
|
|
1202
|
-
|
|
1203
|
-
$
|
|
1204
|
-
|
|
946
|
+
const variant = activeVariant();
|
|
947
|
+
const variantSuffix = variant ? ` · ${variant.label}` : '';
|
|
948
|
+
$('review-export').textContent = (metadata.accepted ? `Export for ${target.label}` : `Approve & export for ${target.label}`) + variantSuffix;
|
|
949
|
+
$('review-export-matrix').disabled = !metadata.variants.variants.length || Boolean(candidateId);
|
|
950
|
+
$('review-store-url').required = Boolean(target.requiresStoreUrl && !variant?.storeUrl);
|
|
951
|
+
const requirement = document.querySelector('#review-store .tora-optional-tag'); if (requirement) requirement.textContent = target.requiresStoreUrl ? (variant?.storeUrl ? '(variant configured)' : '(required)') : '(dashboard configured)';
|
|
1205
952
|
const note = $('review-export-verification');
|
|
1206
953
|
if (note) {
|
|
1207
954
|
note.replaceChildren();
|
|
@@ -1217,6 +964,8 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
1217
964
|
}
|
|
1218
965
|
note.append(document.createTextNode(' and on physical iOS/Android devices before launch.'));
|
|
1219
966
|
}
|
|
967
|
+
invalidateQaIfStale();
|
|
968
|
+
void refreshBudget();
|
|
1220
969
|
};
|
|
1221
970
|
renderExportTargets();
|
|
1222
971
|
exportTargetSelect.onchange = updateExportButton;
|
|
@@ -1228,7 +977,7 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
1228
977
|
updateExportButton();
|
|
1229
978
|
}).catch(() => {});
|
|
1230
979
|
|
|
1231
|
-
document.title = metadata.name + ' | Tora
|
|
980
|
+
document.title = metadata.name + ' | Tora review';
|
|
1232
981
|
|
|
1233
982
|
const scrollThread = () => { threadEl.scrollTop = threadEl.scrollHeight; };
|
|
1234
983
|
const popover = wirePopoverMenu($('review-plus-btn'), $('review-plus-menu'));
|
|
@@ -1237,34 +986,10 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
1237
986
|
maxHeight: 132,
|
|
1238
987
|
});
|
|
1239
988
|
|
|
1240
|
-
const connectionCtrl = createApiConnectionController({
|
|
1241
|
-
pillButton: $('review-api-pill'),
|
|
1242
|
-
onStatusChange: async nextStatus => {
|
|
1243
|
-
updateRouteHint(nextStatus);
|
|
1244
|
-
if (!initialized) return;
|
|
1245
|
-
if (nextStatus?.configured && pendingRetryRequestId) {
|
|
1246
|
-
const retryId = pendingRetryRequestId;
|
|
1247
|
-
pendingRetryRequestId = undefined;
|
|
1248
|
-
await updateMetadata();
|
|
1249
|
-
resolveRequest(retryId);
|
|
1250
|
-
} else if (nextStatus) {
|
|
1251
|
-
await updateMetadata();
|
|
1252
|
-
}
|
|
1253
|
-
},
|
|
1254
|
-
});
|
|
1255
989
|
void populateDemosMenu($('review-demos'), $('review-demo-list'), projectId);
|
|
1256
990
|
|
|
1257
|
-
function updateRouteHint(
|
|
1258
|
-
|
|
1259
|
-
if (connStatus?.configured) {
|
|
1260
|
-
hint.textContent = connStatus.verified
|
|
1261
|
-
? `${connStatus.modelLabel} · Vision + Tora audio QA`
|
|
1262
|
-
: `${connStatus.modelLabel || 'Legacy API'} · Click API pill to upgrade`;
|
|
1263
|
-
} else if (metadata.feedbackModel) {
|
|
1264
|
-
hint.textContent = `${metadata.connection?.modelLabel ?? metadata.feedbackModel} connected`;
|
|
1265
|
-
} else {
|
|
1266
|
-
hint.textContent = 'Instant $0 edits active · Connect a verified API for open-ended chat';
|
|
1267
|
-
}
|
|
991
|
+
function updateRouteHint() {
|
|
992
|
+
$('review-route-hint').textContent = 'Notes are handed to your external AI client; no model runs in Tora.';
|
|
1268
993
|
}
|
|
1269
994
|
|
|
1270
995
|
function showError(error) {
|
|
@@ -1285,6 +1010,60 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
1285
1010
|
};
|
|
1286
1011
|
}
|
|
1287
1012
|
|
|
1013
|
+
function renderBudget() {
|
|
1014
|
+
const summary = $('review-budget-summary');
|
|
1015
|
+
const presentation = budgetPresentation(budgetData);
|
|
1016
|
+
summary.textContent = budgetError ? 'Budget · unavailable' : presentation.label;
|
|
1017
|
+
summary.setAttribute('aria-label', budgetError ? 'Export budget unavailable. Open for details.' : presentation.description);
|
|
1018
|
+
$('review-budget').dataset.status = budgetError ? 'unavailable' : budgetData?.status ?? 'loading';
|
|
1019
|
+
$('review-budget-images').textContent = budgetData ? formatBytes(budgetData.images2dBytes ?? 0) : '—';
|
|
1020
|
+
$('review-budget-models').textContent = budgetData ? formatBytes(budgetData.models3dBytes ?? 0) : '—';
|
|
1021
|
+
$('review-budget-audio').textContent = budgetData ? formatBytes(budgetData.audioBytes ?? 0) : '—';
|
|
1022
|
+
$('review-budget-intro').textContent = budgetData?.measurement === 'measured'
|
|
1023
|
+
? 'Measured from the cached package for this exact revision, variant, target, and fit setting.'
|
|
1024
|
+
: 'Estimated before final packaging; measured after this exact export is packaged.';
|
|
1025
|
+
$('review-budget-top').replaceChildren(...(budgetData?.topAssets ?? []).map(asset => {
|
|
1026
|
+
const item = reviewElement('li');
|
|
1027
|
+
item.append(reviewElement('strong', asset.id), reviewElement('span', formatBytes(asset.rawBytes ?? asset.bytes ?? 0) + (asset.unused ? ' · unused' : '')));
|
|
1028
|
+
return item;
|
|
1029
|
+
}));
|
|
1030
|
+
$('review-budget-unused').textContent = budgetData
|
|
1031
|
+
? budgetData.unusedAssetCount ? `${budgetData.unusedAssetCount} unused asset${budgetData.unusedAssetCount === 1 ? '' : 's'} can be dropped by Auto-shrink.` : 'No unused assets detected.'
|
|
1032
|
+
: '';
|
|
1033
|
+
$('review-budget-error').textContent = budgetError ?? '';
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
async function refreshBudget(force = false) {
|
|
1037
|
+
const target = selectedExportTarget();
|
|
1038
|
+
if (!target || !metadata.expected) return;
|
|
1039
|
+
const revisionId = metadata.expected.revisionId;
|
|
1040
|
+
const fit = $('review-auto-fit').checked;
|
|
1041
|
+
const key = JSON.stringify([revisionId, target.id, activeVariantId, fit]);
|
|
1042
|
+
if (!force && key === budgetKey) return;
|
|
1043
|
+
const version = ++budgetRequestVersion;
|
|
1044
|
+
budgetKey = key;
|
|
1045
|
+
budgetData = undefined;
|
|
1046
|
+
budgetError = undefined;
|
|
1047
|
+
renderBudget();
|
|
1048
|
+
const query = new URLSearchParams({target: target.id, variant: activeVariantId, fit: String(fit), revision: revisionId});
|
|
1049
|
+
try {
|
|
1050
|
+
const result = await api('/budget?' + query);
|
|
1051
|
+
if (version !== budgetRequestVersion) return;
|
|
1052
|
+
budgetData = result;
|
|
1053
|
+
budgetError = undefined;
|
|
1054
|
+
} catch (error) {
|
|
1055
|
+
if (version !== budgetRequestVersion) return;
|
|
1056
|
+
budgetError = errorLabels[error.message] ?? error.message;
|
|
1057
|
+
}
|
|
1058
|
+
renderBudget();
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
$('review-auto-fit').onchange = () => {
|
|
1062
|
+
invalidateQaIfStale();
|
|
1063
|
+
void refreshBudget(true);
|
|
1064
|
+
};
|
|
1065
|
+
$('review-budget-refresh').onclick = () => { void refreshBudget(true); };
|
|
1066
|
+
|
|
1288
1067
|
function stopWinSoundPreview() {
|
|
1289
1068
|
const running = previewAudio;
|
|
1290
1069
|
previewAudio = undefined;
|
|
@@ -1297,7 +1076,7 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
1297
1076
|
}
|
|
1298
1077
|
|
|
1299
1078
|
function drawWinSoundControls() {
|
|
1300
|
-
winSoundPanel.hidden = !metadata.winCue;
|
|
1079
|
+
winSoundPanel.hidden = isHosted || !metadata.winCue;
|
|
1301
1080
|
if (!metadata.winCue) return;
|
|
1302
1081
|
const {choices} = metadata.winCue;
|
|
1303
1082
|
const selected = winSoundSelect.value || choices.find(choice => choice.current)?.key || 'current';
|
|
@@ -1381,64 +1160,105 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
1381
1160
|
});
|
|
1382
1161
|
|
|
1383
1162
|
function syncComparisonChoice() {
|
|
1384
|
-
|
|
1385
|
-
$('review-
|
|
1163
|
+
const comparing = Boolean(candidateId) || variantCompare;
|
|
1164
|
+
$('review-before').dataset.selected = String(comparing && comparisonVersion === 'before');
|
|
1165
|
+
$('review-after').dataset.selected = String(comparing && comparisonVersion === 'after');
|
|
1386
1166
|
$('review-replay-change').disabled = false;
|
|
1387
1167
|
updateWinSoundApply();
|
|
1168
|
+
drawVariants();
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
function friendlyScopeLabel(scope) {
|
|
1172
|
+
if (!scope) return '';
|
|
1173
|
+
if (scope.id === '$project.base') return 'Project settings (store link, stage)';
|
|
1174
|
+
const qe = metadata.quickEdit;
|
|
1175
|
+
const textHit = qe?.texts?.find(item => item.id === scope.id);
|
|
1176
|
+
if (textHit) return textHit.roleLabel;
|
|
1177
|
+
const colorHit = qe?.colors?.find(item => item.componentId === scope.id);
|
|
1178
|
+
if (colorHit) return colorHit.roleLabel.replace(/\s+color$/i, '');
|
|
1179
|
+
const timingHit = qe?.timings?.find(item => item.behaviorId === scope.id);
|
|
1180
|
+
if (timingHit) return timingHit.roleLabel;
|
|
1181
|
+
if (scope.label && scope.label !== scope.id && !/^[a-z0-9_.-]+\.[a-z0-9_.-]+$/i.test(scope.label)) return scope.label;
|
|
1182
|
+
const tail = scope.id.split('.').filter(part => part && !['starter', 'scene', 'harvest', 'salvage', 'sort', 'ui', 'hud', 'group', 'layout'].includes(part.toLowerCase()));
|
|
1183
|
+
const source = (tail.length ? tail.slice(-2) : scope.id.split('.').slice(-2)).join(' ');
|
|
1184
|
+
const spaced = source.replace(/[-_]+/g, ' ').replace(/([a-z])([A-Z])/g, '$1 $2').replace(/\s+/g, ' ').trim();
|
|
1185
|
+
return spaced ? spaced[0].toUpperCase() + spaced.slice(1) : scope.id;
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
function relatedScopesFor(scope) {
|
|
1189
|
+
if (!scope) return [];
|
|
1190
|
+
return metadata.scopes.filter(item =>
|
|
1191
|
+
item.id !== scope.id && (
|
|
1192
|
+
item.componentId === scope.id ||
|
|
1193
|
+
item.parentId === scope.id ||
|
|
1194
|
+
(scope.parentId && item.id === scope.parentId) ||
|
|
1195
|
+
item.references?.includes(scope.id) ||
|
|
1196
|
+
scope.references?.includes(item.id)
|
|
1197
|
+
),
|
|
1198
|
+
);
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
function scopePresets() {
|
|
1202
|
+
const presets = [];
|
|
1203
|
+
const qe = metadata.quickEdit;
|
|
1204
|
+
const ctaIds = new Set();
|
|
1205
|
+
for (const item of qe?.texts ?? []) if (item.isCta) { ctaIds.add(item.id); if (item.parentId) ctaIds.add(item.parentId); }
|
|
1206
|
+
for (const item of qe?.colors ?? []) if (item.isCta) ctaIds.add(item.componentId);
|
|
1207
|
+
const validCta = [...ctaIds].filter(id => metadata.scopes.some(s => s.id === id));
|
|
1208
|
+
if (validCta.length) presets.push({id: 'cta', label: 'Install button', ids: validCta});
|
|
1209
|
+
|
|
1210
|
+
const activeScene = before.state?.()?.scene;
|
|
1211
|
+
const textIds = metadata.scopes
|
|
1212
|
+
.filter(s => s.collection === 'components' && s.contract === 'native.text.v1' && (!activeScene || s.sceneId === activeScene))
|
|
1213
|
+
.map(s => s.id).slice(0, 32);
|
|
1214
|
+
if (textIds.length) presets.push({id: 'texts', label: 'Visible text', ids: textIds});
|
|
1215
|
+
|
|
1216
|
+
const timingIds = (qe?.timings ?? []).map(item => item.behaviorId).filter(id => metadata.scopes.some(s => s.id === id));
|
|
1217
|
+
if (timingIds.length) presets.push({id: 'timing', label: 'Timing', ids: timingIds});
|
|
1218
|
+
|
|
1219
|
+
const audioIds = metadata.scopes.filter(s => s.collection === 'gameplay' && s.kind === 'audio').map(s => s.id).slice(0, 32);
|
|
1220
|
+
if (audioIds.length) presets.push({id: 'audio', label: 'Audio', ids: audioIds});
|
|
1221
|
+
|
|
1222
|
+
if (metadata.scopes.some(s => s.id === '$project.base')) {
|
|
1223
|
+
presets.push({id: 'base', label: 'Project settings', ids: ['$project.base']});
|
|
1224
|
+
}
|
|
1225
|
+
return presets;
|
|
1388
1226
|
}
|
|
1389
1227
|
|
|
1390
1228
|
function paintOutline() {
|
|
1391
|
-
|
|
1392
|
-
|
|
1229
|
+
if (attachment.hidden) {
|
|
1230
|
+
before.outlines([]);
|
|
1231
|
+
return;
|
|
1232
|
+
}
|
|
1233
|
+
const componentIds = [...selectedScopeIds].filter(id => metadata.scopes.some(item => item.id === id && item.collection === 'components'));
|
|
1234
|
+
before.outlines(componentIds);
|
|
1393
1235
|
}
|
|
1394
1236
|
|
|
1395
1237
|
function drawQuickChips() {
|
|
1396
1238
|
const row = $('review-quick-chips');
|
|
1397
1239
|
const chips = [];
|
|
1398
|
-
if (metadata.
|
|
1399
|
-
chips.push({
|
|
1400
|
-
label: 'Edit install button',
|
|
1401
|
-
run: () => {
|
|
1402
|
-
selectMoment('end-card');
|
|
1403
|
-
toggleAttachment(true);
|
|
1404
|
-
targetMenu.value = 'cta';
|
|
1405
|
-
drawFields();
|
|
1406
|
-
$('review-fields').open = true;
|
|
1407
|
-
$('review-direct-text')?.focus();
|
|
1408
|
-
},
|
|
1409
|
-
});
|
|
1410
|
-
}
|
|
1411
|
-
if (metadata.targets.some(t => t.id === 'opening')) {
|
|
1240
|
+
if (!isHosted && metadata.scopes.length) {
|
|
1412
1241
|
chips.push({
|
|
1413
|
-
label: '
|
|
1242
|
+
label: 'Pick what to change',
|
|
1414
1243
|
run: () => {
|
|
1415
|
-
selectMoment('opening');
|
|
1416
1244
|
toggleAttachment(true);
|
|
1417
|
-
targetMenu.
|
|
1418
|
-
drawFields();
|
|
1419
|
-
$('review-fields').open = true;
|
|
1420
|
-
draftText.focus();
|
|
1245
|
+
targetMenu.focus();
|
|
1421
1246
|
},
|
|
1422
1247
|
});
|
|
1423
1248
|
}
|
|
1424
|
-
if (
|
|
1249
|
+
if (!isHosted && metadata.winCue) {
|
|
1425
1250
|
chips.push({
|
|
1426
1251
|
label: 'Change win sound',
|
|
1427
1252
|
run: () => {
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
winSoundSelect.focus();
|
|
1431
|
-
return;
|
|
1432
|
-
}
|
|
1433
|
-
selectMoment('end-card');
|
|
1434
|
-
toggleAttachment(true);
|
|
1435
|
-
targetMenu.value = 'ending';
|
|
1436
|
-
drawFields();
|
|
1437
|
-
$('review-fields').open = true;
|
|
1438
|
-
($('review-win-cue-replacement') || draftText).focus();
|
|
1253
|
+
winSoundPanel.open = true;
|
|
1254
|
+
winSoundSelect.focus();
|
|
1439
1255
|
},
|
|
1440
1256
|
});
|
|
1441
1257
|
}
|
|
1258
|
+
chips.push({
|
|
1259
|
+
label: 'Quick Edit copy & colors',
|
|
1260
|
+
run: () => setSideTab('quick'),
|
|
1261
|
+
});
|
|
1442
1262
|
row.replaceChildren(...chips.map(chip => {
|
|
1443
1263
|
const btn = reviewElement('button', chip.label, 'tora-starter-chip');
|
|
1444
1264
|
btn.type = 'button';
|
|
@@ -1447,92 +1267,203 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
1447
1267
|
}));
|
|
1448
1268
|
}
|
|
1449
1269
|
|
|
1450
|
-
function
|
|
1451
|
-
const
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
const
|
|
1456
|
-
const
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
['hint-delay','reveal-duration','payoff-hold','feedback-duration'].includes(field.id))) {
|
|
1463
|
-
const direct = reviewElement('input');
|
|
1464
|
-
const timing = field.id !== 'text';
|
|
1465
|
-
if (timing) {
|
|
1466
|
-
direct.dataset.directTimingField = field.id;
|
|
1467
|
-
if (!$('review-direct-timing')) direct.id = 'review-direct-timing';
|
|
1270
|
+
function drawScopePresets() {
|
|
1271
|
+
const row = $('review-scope-presets');
|
|
1272
|
+
const presets = scopePresets();
|
|
1273
|
+
row.hidden = !presets.length;
|
|
1274
|
+
row.replaceChildren(...presets.map(preset => {
|
|
1275
|
+
const active = preset.ids.length > 0 && preset.ids.every(id => selectedScopeIds.has(id));
|
|
1276
|
+
const btn = reviewElement('button', preset.label, 'tora-scope-chip');
|
|
1277
|
+
btn.type = 'button';
|
|
1278
|
+
btn.setAttribute('aria-pressed', String(active));
|
|
1279
|
+
btn.onclick = () => {
|
|
1280
|
+
if (active) {
|
|
1281
|
+
for (const id of preset.ids) selectedScopeIds.delete(id);
|
|
1468
1282
|
} else {
|
|
1469
|
-
|
|
1283
|
+
selectedScopeIds = new Set(preset.ids);
|
|
1284
|
+
targetMenu.value = preset.ids[0] ?? '';
|
|
1470
1285
|
}
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1286
|
+
drawFields();
|
|
1287
|
+
};
|
|
1288
|
+
return btn;
|
|
1289
|
+
}));
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
function drawSelectedPills() {
|
|
1293
|
+
const box = $('review-scope-selected');
|
|
1294
|
+
const ids = [...selectedScopeIds];
|
|
1295
|
+
const selectedTarget = metadata.scopes.find(scope => scope.id === targetMenu.value);
|
|
1296
|
+
const missingRelated = selectedTarget ? relatedScopesFor(selectedTarget).filter(item => !selectedScopeIds.has(item.id)) : [];
|
|
1297
|
+
box.hidden = ids.length === 0 && missingRelated.length === 0;
|
|
1298
|
+
const nodes = [];
|
|
1299
|
+
const visible = ids.slice(0, 4);
|
|
1300
|
+
for (const id of visible) {
|
|
1301
|
+
const scope = metadata.scopes.find(item => item.id === id);
|
|
1302
|
+
const pill = reviewElement('span', '', 'tora-scope-pill');
|
|
1303
|
+
pill.append(reviewElement('span', friendlyScopeLabel(scope) || id));
|
|
1304
|
+
const remove = reviewElement('button', '×', 'tora-scope-pill-x');
|
|
1305
|
+
remove.type = 'button';
|
|
1306
|
+
remove.setAttribute('aria-label', 'Remove ' + (friendlyScopeLabel(scope) || id));
|
|
1307
|
+
remove.onclick = () => {
|
|
1308
|
+
selectedScopeIds.delete(id);
|
|
1309
|
+
if (targetMenu.value === id) targetMenu.value = '';
|
|
1310
|
+
drawFields();
|
|
1311
|
+
};
|
|
1312
|
+
pill.append(remove);
|
|
1313
|
+
nodes.push(pill);
|
|
1314
|
+
}
|
|
1315
|
+
if (ids.length > visible.length) {
|
|
1316
|
+
const more = reviewElement('button', `+${ids.length - visible.length} more`, 'tora-scope-link');
|
|
1317
|
+
more.type = 'button';
|
|
1318
|
+
more.onclick = () => { $('review-fields').open = true; };
|
|
1319
|
+
nodes.push(more);
|
|
1320
|
+
}
|
|
1321
|
+
if (missingRelated.length) {
|
|
1322
|
+
const addRel = reviewElement('button', `+ Include related (${missingRelated.length})`, 'tora-scope-link');
|
|
1323
|
+
addRel.type = 'button';
|
|
1324
|
+
addRel.title = missingRelated.map(item => friendlyScopeLabel(item)).slice(0, 6).join(', ');
|
|
1325
|
+
addRel.onclick = () => {
|
|
1326
|
+
for (const item of missingRelated) {
|
|
1327
|
+
if (selectedScopeIds.size < 64) selectedScopeIds.add(item.id);
|
|
1328
|
+
}
|
|
1329
|
+
drawFields();
|
|
1330
|
+
};
|
|
1331
|
+
nodes.push(addRel);
|
|
1332
|
+
}
|
|
1333
|
+
if (ids.length > 1) {
|
|
1334
|
+
const clear = reviewElement('button', 'Clear', 'tora-scope-link');
|
|
1335
|
+
clear.type = 'button';
|
|
1336
|
+
clear.onclick = () => {
|
|
1337
|
+
selectedScopeIds.clear();
|
|
1338
|
+
targetMenu.value = '';
|
|
1339
|
+
drawFields();
|
|
1340
|
+
};
|
|
1341
|
+
nodes.push(clear);
|
|
1342
|
+
}
|
|
1343
|
+
box.replaceChildren(...nodes);
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
function drawFields() {
|
|
1347
|
+
const validIds = new Set(metadata.scopes.map(scope => scope.id));
|
|
1348
|
+
for (const id of [...selectedScopeIds]) if (!validIds.has(id)) selectedScopeIds.delete(id);
|
|
1349
|
+
|
|
1350
|
+
const selected = metadata.scopes.find(scope => scope.id === targetMenu.value);
|
|
1351
|
+
const query = scopeFilterText.trim().toLowerCase();
|
|
1352
|
+
let list;
|
|
1353
|
+
if (query) {
|
|
1354
|
+
list = metadata.scopes.filter(scope =>
|
|
1355
|
+
scope.id.toLowerCase().includes(query) ||
|
|
1356
|
+
friendlyScopeLabel(scope).toLowerCase().includes(query) ||
|
|
1357
|
+
scope.collection.toLowerCase().includes(query),
|
|
1358
|
+
);
|
|
1359
|
+
} else if (selected && !showAllScopeRecords) {
|
|
1360
|
+
list = [selected, ...relatedScopesFor(selected)];
|
|
1361
|
+
for (const id of selectedScopeIds) {
|
|
1362
|
+
if (!list.some(item => item.id === id)) {
|
|
1363
|
+
const extra = metadata.scopes.find(item => item.id === id);
|
|
1364
|
+
if (extra) list.push(extra);
|
|
1481
1365
|
}
|
|
1482
|
-
direct.oninput = () => {
|
|
1483
|
-
if (!direct.value) return;
|
|
1484
|
-
for (const fieldInput of $('review-field-options').querySelectorAll('input[type="checkbox"]'))
|
|
1485
|
-
fieldInput.checked = fieldInput === input;
|
|
1486
|
-
drawQueued();
|
|
1487
|
-
};
|
|
1488
|
-
const apply = reviewElement('button', 'Apply instant ($0)', 'review-direct-apply');
|
|
1489
|
-
apply.type = 'button';
|
|
1490
|
-
apply.onclick = handle(() => notePanel.requestSubmit());
|
|
1491
|
-
label.append(direct, apply);
|
|
1492
1366
|
}
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1367
|
+
} else if (!showAllScopeRecords && metadata.scopes.length > 24) {
|
|
1368
|
+
const keyIds = new Set([
|
|
1369
|
+
'$project.base',
|
|
1370
|
+
...selectedScopeIds,
|
|
1371
|
+
...(metadata.quickEdit?.texts ?? []).map(item => item.id),
|
|
1372
|
+
...(metadata.quickEdit?.colors ?? []).map(item => item.componentId),
|
|
1373
|
+
...(metadata.quickEdit?.timings ?? []).map(item => item.behaviorId),
|
|
1374
|
+
]);
|
|
1375
|
+
list = metadata.scopes.filter(scope => keyIds.has(scope.id) || scope.collection === 'scenes');
|
|
1376
|
+
} else {
|
|
1377
|
+
list = metadata.scopes;
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
$('review-fields').hidden = false;
|
|
1381
|
+
$('review-fields-summary').textContent = selectedScopeIds.size
|
|
1382
|
+
? `Customize exact records (${selectedScopeIds.size} selected)`
|
|
1383
|
+
: 'Customize exact records';
|
|
1384
|
+
|
|
1385
|
+
const items = list.slice(0, 120).map(scope => {
|
|
1386
|
+
const friendly = friendlyScopeLabel(scope);
|
|
1387
|
+
const label = reviewElement('label');
|
|
1388
|
+
const input = reviewElement('input');
|
|
1389
|
+
input.type = 'checkbox'; input.value = scope.id; input.dataset.reviewScope = 'true';
|
|
1390
|
+
input.checked = selectedScopeIds.has(scope.id);
|
|
1391
|
+
input.onchange = () => {
|
|
1392
|
+
if (input.checked) selectedScopeIds.add(scope.id);
|
|
1393
|
+
else selectedScopeIds.delete(scope.id);
|
|
1394
|
+
drawScopePresets();
|
|
1395
|
+
drawSelectedPills();
|
|
1396
|
+
$('review-fields-summary').textContent = selectedScopeIds.size
|
|
1397
|
+
? `Customize exact records (${selectedScopeIds.size} selected)`
|
|
1398
|
+
: 'Customize exact records';
|
|
1399
|
+
paintOutline();
|
|
1400
|
+
};
|
|
1401
|
+
label.append(input, reviewElement('span', friendly));
|
|
1402
|
+
if (friendly.toLowerCase() !== scope.id.toLowerCase()) {
|
|
1403
|
+
label.append(reviewElement('code', scope.id, 'tora-scope-id'));
|
|
1511
1404
|
}
|
|
1512
1405
|
return label;
|
|
1513
|
-
})
|
|
1406
|
+
});
|
|
1407
|
+
if (!query && !showAllScopeRecords && list.length < metadata.scopes.length) {
|
|
1408
|
+
const showAll = reviewElement('button', `Show all ${metadata.scopes.length} records`, 'tora-scope-link');
|
|
1409
|
+
showAll.type = 'button';
|
|
1410
|
+
showAll.onclick = () => {
|
|
1411
|
+
showAllScopeRecords = true;
|
|
1412
|
+
drawFields();
|
|
1413
|
+
};
|
|
1414
|
+
items.push(showAll);
|
|
1415
|
+
} else if (query && list.length === 0) {
|
|
1416
|
+
items.push(reviewElement('span', 'No matching records.', 'tora-export-hint'));
|
|
1417
|
+
}
|
|
1418
|
+
$('review-field-options').replaceChildren(...items);
|
|
1419
|
+
drawScopePresets();
|
|
1420
|
+
drawSelectedPills();
|
|
1514
1421
|
paintOutline();
|
|
1515
1422
|
}
|
|
1516
1423
|
|
|
1517
1424
|
function setTargetOptions() {
|
|
1518
1425
|
const activeId = targetMenu.value;
|
|
1519
|
-
const
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1426
|
+
const prompt = reviewElement('option', 'Pick an element to change…');
|
|
1427
|
+
prompt.value = '';
|
|
1428
|
+
|
|
1429
|
+
const keyIds = new Set([
|
|
1430
|
+
'$project.base',
|
|
1431
|
+
...(metadata.quickEdit?.texts ?? []).map(item => item.id),
|
|
1432
|
+
...(metadata.quickEdit?.colors ?? []).map(item => item.componentId),
|
|
1433
|
+
...(metadata.quickEdit?.timings ?? []).map(item => item.behaviorId),
|
|
1434
|
+
]);
|
|
1435
|
+
const keyGroup = [], visualGroup = [], logicGroup = [];
|
|
1436
|
+
for (const scope of metadata.scopes) {
|
|
1437
|
+
const friendly = friendlyScopeLabel(scope);
|
|
1438
|
+
const text = friendly.toLowerCase() === scope.id.toLowerCase() ? scope.id : `${friendly} (${scope.id})`;
|
|
1439
|
+
const option = reviewElement('option', text);
|
|
1440
|
+
option.value = scope.id;
|
|
1441
|
+
if (keyIds.has(scope.id)) keyGroup.push(option);
|
|
1442
|
+
else if (scope.collection === 'components') visualGroup.push(option);
|
|
1443
|
+
else logicGroup.push(option);
|
|
1444
|
+
}
|
|
1445
|
+
const groups = [prompt];
|
|
1446
|
+
const addGroup = (label, options) => {
|
|
1447
|
+
if (!options.length) return;
|
|
1448
|
+
const group = reviewElement('optgroup');
|
|
1449
|
+
group.label = label;
|
|
1450
|
+
group.append(...options);
|
|
1451
|
+
groups.push(group);
|
|
1452
|
+
};
|
|
1453
|
+
addGroup('Key elements', keyGroup);
|
|
1454
|
+
addGroup('Visual objects', visualGroup);
|
|
1455
|
+
addGroup('Scenes, rules & assets', logicGroup);
|
|
1456
|
+
|
|
1457
|
+
targetMenu.replaceChildren(...groups);
|
|
1458
|
+
targetMenu.value = metadata.scopes.some(scope => scope.id === activeId) ? activeId : '';
|
|
1528
1459
|
drawFields();
|
|
1529
1460
|
}
|
|
1530
1461
|
|
|
1531
1462
|
function selectMoment(next) {
|
|
1532
1463
|
moment = next;
|
|
1533
1464
|
before.seek(moment);
|
|
1534
|
-
if (candidateId) after.seek(moment);
|
|
1535
|
-
before.picker.dataset.active = attachment.hidden ? '
|
|
1465
|
+
if (candidateId || variantCompare) after.seek(moment);
|
|
1466
|
+
before.picker.dataset.active = (!attachment.hidden || activeSideTab === 'quick') ? 'true' : 'false';
|
|
1536
1467
|
for (const button of $('review-moments').children)
|
|
1537
1468
|
button.setAttribute('aria-pressed', String(button.dataset.moment === moment));
|
|
1538
1469
|
setTargetOptions();
|
|
@@ -1560,9 +1491,19 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
1560
1491
|
if (open) {
|
|
1561
1492
|
before.freeze();
|
|
1562
1493
|
moment = visibleMoment();
|
|
1494
|
+
showAllScopeRecords = false;
|
|
1495
|
+
scopeFilterText = '';
|
|
1496
|
+
$('review-scope-filter').value = '';
|
|
1563
1497
|
setTargetOptions();
|
|
1564
1498
|
} else {
|
|
1565
1499
|
targetMenu.value = '';
|
|
1500
|
+
selectedScopeIds.clear();
|
|
1501
|
+
showAllScopeRecords = false;
|
|
1502
|
+
scopeFilterText = '';
|
|
1503
|
+
$('review-scope-filter').value = '';
|
|
1504
|
+
$('review-fields').open = false;
|
|
1505
|
+
const allowCreatesBox = $('review-allow-creates');
|
|
1506
|
+
if (allowCreatesBox) allowCreatesBox.checked = false;
|
|
1566
1507
|
drawFields();
|
|
1567
1508
|
}
|
|
1568
1509
|
}
|
|
@@ -1592,27 +1533,470 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
1592
1533
|
strip.replaceChildren(chip);
|
|
1593
1534
|
}
|
|
1594
1535
|
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
const [document, render] = await Promise.all([api('?revision=' + encoded), api('/render?revision=' + encoded)]);
|
|
1598
|
-
return {project: document.project, assets: render.assets};
|
|
1536
|
+
function activeVariant() {
|
|
1537
|
+
return metadata.variants?.variants.find(variant => variant.id === activeVariantId);
|
|
1599
1538
|
}
|
|
1600
1539
|
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1540
|
+
function clearVariantComparison() {
|
|
1541
|
+
if (!variantCompare) return;
|
|
1542
|
+
variantCompare = false;
|
|
1543
|
+
comparisonVersion = undefined;
|
|
1544
|
+
after.hide();
|
|
1545
|
+
$('review-previews').dataset.compare = 'false';
|
|
1546
|
+
$('review-before').querySelector('figcaption').hidden = true;
|
|
1547
|
+
$('review-after').querySelector('figcaption').textContent = 'After';
|
|
1548
|
+
syncComparisonChoice();
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
const RTL_LANG_RE = /^(ar|fa|he|iw|ps|sd|ug|ur|yi)(?:-|$)/i;
|
|
1552
|
+
let editingVariantId = null;
|
|
1553
|
+
let variantIdManuallyEdited = false;
|
|
1554
|
+
let variantLabelAutoFilled = false;
|
|
1555
|
+
let deleteConfirmVariantId = null;
|
|
1556
|
+
let deleteConfirmTimer = null;
|
|
1557
|
+
|
|
1558
|
+
function resetVariantDeleteConfirm() {
|
|
1559
|
+
clearTimeout(deleteConfirmTimer);
|
|
1560
|
+
deleteConfirmTimer = null;
|
|
1561
|
+
deleteConfirmVariantId = null;
|
|
1562
|
+
const btn = $('review-variant-delete');
|
|
1563
|
+
if (btn) btn.textContent = 'Delete';
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
function slugifyVariantId(label) {
|
|
1567
|
+
const slug = String(label ?? '').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^[^a-z]+/, '').replace(/-+$/, '').slice(0, 44);
|
|
1568
|
+
return slug.length >= 2 ? slug : '';
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
function friendlyLocalizableRole(kind, key) {
|
|
1572
|
+
const qeMatch = metadata.quickEdit?.texts?.find(item => item.id === key);
|
|
1573
|
+
if (qeMatch?.roleLabel) return qeMatch.roleLabel;
|
|
1574
|
+
if (kind === 'actionTexts') return 'In-game popup';
|
|
1575
|
+
if (kind === 'variables') return 'Dynamic text';
|
|
1576
|
+
const tail = String(key).split('.').slice(-2).join(' ').replace(/[-_]+/g, ' ');
|
|
1577
|
+
return tail ? tail[0].toUpperCase() + tail.slice(1) : 'Text';
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
function syncRtlBadge() {
|
|
1581
|
+
const code = $('review-variant-language').value.trim();
|
|
1582
|
+
const isRtl = RTL_LANG_RE.test(code);
|
|
1583
|
+
$('review-variant-rtl-badge').hidden = !isRtl;
|
|
1584
|
+
const select = $('review-variant-language-select');
|
|
1585
|
+
const hasOpt = [...select.options].some(opt => opt.value === code);
|
|
1586
|
+
select.value = hasOpt ? code : 'custom';
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
function renderTranslationTable(values) {
|
|
1590
|
+
const container = $('review-variant-translation-rows');
|
|
1591
|
+
const localizable = metadata.variants.localizable ?? {texts: {}, actionTexts: {}, variables: {}};
|
|
1592
|
+
const buckets = [
|
|
1593
|
+
{key: 'texts', textareaId: 'review-variant-texts', entries: Object.entries(localizable.texts ?? {})},
|
|
1594
|
+
{key: 'actionTexts', textareaId: 'review-variant-action-texts', entries: Object.entries(localizable.actionTexts ?? {})},
|
|
1595
|
+
{key: 'variables', textareaId: 'review-variant-variables', entries: Object.entries(localizable.variables ?? {})},
|
|
1596
|
+
];
|
|
1597
|
+
const currentMaps = {
|
|
1598
|
+
texts: {...(localizable.texts ?? {}), ...(values?.texts ?? {})},
|
|
1599
|
+
actionTexts: {...(localizable.actionTexts ?? {}), ...(values?.actionTexts ?? {})},
|
|
1600
|
+
variables: {...(localizable.variables ?? {}), ...(values?.variables ?? {})},
|
|
1601
|
+
};
|
|
1602
|
+
const syncTextareas = () => {
|
|
1603
|
+
$('review-variant-texts').value = JSON.stringify(currentMaps.texts, null, 2);
|
|
1604
|
+
$('review-variant-action-texts').value = JSON.stringify(currentMaps.actionTexts, null, 2);
|
|
1605
|
+
$('review-variant-variables').value = JSON.stringify(currentMaps.variables, null, 2);
|
|
1606
|
+
const pairs = buckets.flatMap(bucket => bucket.entries.map(([k, orig]) => [String(orig), String(currentMaps[bucket.key][k] ?? '')]));
|
|
1607
|
+
const translated = pairs.filter(([orig, val]) => val.trim().length > 0 && val.trim() !== orig.trim()).length;
|
|
1608
|
+
const filled = pairs.filter(([, val]) => val.trim().length > 0).length;
|
|
1609
|
+
$('review-variant-loc-progress').textContent = pairs.length
|
|
1610
|
+
? `${translated} / ${pairs.length} translated (${filled} filled)`
|
|
1611
|
+
: 'No visible text strings found to translate.';
|
|
1612
|
+
};
|
|
1613
|
+
|
|
1614
|
+
const rows = [];
|
|
1615
|
+
for (const bucket of buckets) {
|
|
1616
|
+
for (const [recordId, original] of bucket.entries) {
|
|
1617
|
+
const row = reviewElement('div', '', 'tora-loc-row');
|
|
1618
|
+
const origWrap = reviewElement('div', '', 'tora-loc-orig');
|
|
1619
|
+
origWrap.append(
|
|
1620
|
+
reviewElement('span', friendlyLocalizableRole(bucket.key, recordId), 'tora-pill'),
|
|
1621
|
+
reviewElement('strong', String(original)),
|
|
1622
|
+
);
|
|
1623
|
+
const input = reviewElement('input');
|
|
1624
|
+
input.type = 'text';
|
|
1625
|
+
input.maxLength = 512;
|
|
1626
|
+
input.value = currentMaps[bucket.key][recordId] ?? original;
|
|
1627
|
+
input.placeholder = String(original);
|
|
1628
|
+
input.dataset.locBucket = bucket.key;
|
|
1629
|
+
input.dataset.locKey = recordId;
|
|
1630
|
+
input.setAttribute('aria-label', `Translation for ${original}`);
|
|
1631
|
+
if (RTL_LANG_RE.test($('review-variant-language').value.trim())) input.dir = 'rtl';
|
|
1632
|
+
input.oninput = () => {
|
|
1633
|
+
currentMaps[bucket.key][recordId] = input.value;
|
|
1634
|
+
syncTextareas();
|
|
1635
|
+
};
|
|
1636
|
+
row.append(origWrap, input);
|
|
1637
|
+
rows.push(row);
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
container.replaceChildren(...(rows.length ? rows : [reviewElement('p', 'No localizable text strings in this project.', 'tora-export-hint')]));
|
|
1641
|
+
syncTextareas();
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1644
|
+
function syncVariantDialogVisibility() {
|
|
1645
|
+
const preset = $('review-variant-preset').value;
|
|
1646
|
+
const locale = preset === 'locale';
|
|
1647
|
+
const hook = preset === 'shorter-hook' && !editingVariantId;
|
|
1648
|
+
$('review-variant-hook-wrap').hidden = !hook;
|
|
1649
|
+
$('review-variant-language-wrap').hidden = !locale;
|
|
1650
|
+
$('review-variant-localization-fields').hidden = !locale;
|
|
1651
|
+
$('review-variant-language').required = locale;
|
|
1652
|
+
if (locale) syncRtlBadge();
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
function openVariantDialog(existingVariant = null) {
|
|
1656
|
+
editingVariantId = existingVariant ? existingVariant.id : null;
|
|
1657
|
+
variantIdManuallyEdited = Boolean(existingVariant);
|
|
1658
|
+
variantLabelAutoFilled = false;
|
|
1659
|
+
$('review-variant-error').textContent = '';
|
|
1660
|
+
$('review-variant-form').reset();
|
|
1661
|
+
$('review-variant-dialog-title').textContent = existingVariant ? `Edit variant · ${existingVariant.label}` : 'Create a variant';
|
|
1662
|
+
$('review-variant-create').textContent = existingVariant ? 'Save changes' : 'Create & preview';
|
|
1663
|
+
$('review-variant-id').readOnly = Boolean(existingVariant);
|
|
1664
|
+
$('review-variant-preset').disabled = Boolean(existingVariant);
|
|
1665
|
+
if (existingVariant) {
|
|
1666
|
+
$('review-variant-id').value = existingVariant.id;
|
|
1667
|
+
$('review-variant-label').value = existingVariant.label;
|
|
1668
|
+
$('review-variant-preset').value = existingVariant.preset ?? 'custom';
|
|
1669
|
+
$('review-variant-language').value = existingVariant.language ?? '';
|
|
1670
|
+
const existingTexts = Object.fromEntries(Object.entries(existingVariant.texts ?? {}).map(([k, v]) => [k, typeof v?.text === 'string' ? v.text : '']));
|
|
1671
|
+
renderTranslationTable({
|
|
1672
|
+
texts: existingTexts,
|
|
1673
|
+
actionTexts: existingVariant.actionTexts ?? {},
|
|
1674
|
+
variables: existingVariant.variables ?? {},
|
|
1675
|
+
});
|
|
1676
|
+
} else {
|
|
1677
|
+
$('review-variant-language').value = '';
|
|
1678
|
+
renderTranslationTable(null);
|
|
1679
|
+
}
|
|
1680
|
+
syncVariantDialogVisibility();
|
|
1681
|
+
$('review-variant-dialog').showModal();
|
|
1682
|
+
($('review-variant-label') || $('review-variant-id')).focus();
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
function drawVariants() {
|
|
1686
|
+
const variants = metadata.variants?.variants ?? [];
|
|
1687
|
+
const signature = JSON.stringify([variants, metadata.variants?.diagnostics, activeVariantId, candidateId, variantCompare]);
|
|
1688
|
+
if (signature === variantDrawSignature) return;
|
|
1689
|
+
variantDrawSignature = signature;
|
|
1690
|
+
const strip = $('review-variant-strip');
|
|
1691
|
+
const choices = [];
|
|
1692
|
+
const choice = (id, label) => {
|
|
1693
|
+
const button = reviewElement('button', label, 'review-variant-pill');
|
|
1694
|
+
button.type = 'button';
|
|
1695
|
+
button.id = 'review-variant-' + id;
|
|
1696
|
+
button.disabled = Boolean(candidateId);
|
|
1697
|
+
button.setAttribute('aria-pressed', String(activeVariantId === id));
|
|
1698
|
+
button.onclick = handle(() => selectVariant(id));
|
|
1699
|
+
return button;
|
|
1700
|
+
};
|
|
1701
|
+
if (variants.length) {
|
|
1702
|
+
choices.push(choice('base', 'Base'));
|
|
1703
|
+
for (const variant of variants) choices.push(choice(variant.id, variant.label));
|
|
1704
|
+
}
|
|
1705
|
+
const add = reviewElement('button', '+ Variant', 'review-variant-add');
|
|
1706
|
+
add.type = 'button';
|
|
1707
|
+
add.id = 'review-variant-add';
|
|
1708
|
+
add.disabled = Boolean(candidateId);
|
|
1709
|
+
add.setAttribute('aria-haspopup', 'dialog');
|
|
1710
|
+
add.onclick = () => openVariantDialog(null);
|
|
1711
|
+
choices.push(add);
|
|
1712
|
+
strip.replaceChildren(...choices);
|
|
1713
|
+
|
|
1714
|
+
const variant = activeVariant();
|
|
1715
|
+
$('review-variant-delta').hidden = !variant;
|
|
1716
|
+
if (variant) {
|
|
1717
|
+
$('review-variant-delta-summary').textContent = `Changes · ${variant.label}${variant.language ? ' (' + variant.language + ')' : ''}`;
|
|
1718
|
+
const rows = variantTextDeltas(variant);
|
|
1719
|
+
const list = $('review-variant-delta-list');
|
|
1720
|
+
if (rows.length) {
|
|
1721
|
+
list.replaceChildren(...rows.map(row => {
|
|
1722
|
+
const item = reviewElement('div', '', 'review-variant-delta-row');
|
|
1723
|
+
item.append(reviewElement('span', row.kind, 'tora-pill'), reviewElement('code', row.id), reviewElement('p', row.text || '(style override)'));
|
|
1724
|
+
if (row.detail) item.append(reviewElement('code', row.detail));
|
|
1725
|
+
return item;
|
|
1726
|
+
}));
|
|
1727
|
+
} else {
|
|
1728
|
+
list.replaceChildren(reviewElement('p', 'No overrides yet. Use Quick Edit or Edit variant to customize this variant without changing Base.'));
|
|
1729
|
+
}
|
|
1730
|
+
const diagnostics = (metadata.variants?.diagnostics ?? []).filter(item => item.variantId === variant.id);
|
|
1731
|
+
$('review-variant-diagnostics').textContent = diagnostics.map(item => `${item.recordId ? item.recordId + ': ' : ''}${item.reason ?? item.code}`).join('\n');
|
|
1732
|
+
$('review-variant-edit').disabled = Boolean(candidateId);
|
|
1733
|
+
$('review-variant-compare').textContent = variantCompare ? 'Close comparison' : 'Compare vs Base';
|
|
1734
|
+
$('review-variant-compare').disabled = Boolean(candidateId);
|
|
1735
|
+
$('review-variant-reset').disabled = Boolean(candidateId);
|
|
1736
|
+
$('review-variant-delete').disabled = Boolean(candidateId);
|
|
1737
|
+
}
|
|
1738
|
+
updateExportButton();
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
const assetsByRevision = new Map();
|
|
1742
|
+
async function revisionAssets(revision) {
|
|
1743
|
+
if (assetsByRevision.has(revision)) return assetsByRevision.get(revision);
|
|
1744
|
+
const render = await api('/render?revision=' + encodeURIComponent(revision));
|
|
1745
|
+
assetsByRevision.set(revision, render.assets);
|
|
1746
|
+
while (assetsByRevision.size > 4) assetsByRevision.delete(assetsByRevision.keys().next().value);
|
|
1747
|
+
return render.assets;
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
async function projectData(revision) {
|
|
1751
|
+
const encoded = encodeURIComponent(revision);
|
|
1752
|
+
const [document, assets] = await Promise.all([api('?revision=' + encoded), revisionAssets(revision)]);
|
|
1753
|
+
return {project: document.project, assets};
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1756
|
+
async function previewData(revision, variantId) {
|
|
1757
|
+
if (variantId === 'base') return projectData(revision);
|
|
1758
|
+
const query = new URLSearchParams({variant: variantId, revision});
|
|
1759
|
+
const [materialized, assets] = await Promise.all([api('/variants?' + query), revisionAssets(revision)]);
|
|
1760
|
+
return {project: {...materialized.project, assets}, assets, variant: materialized.variant};
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1763
|
+
async function mountCurrent() {
|
|
1764
|
+
const revision = metadata.expected.revisionId;
|
|
1765
|
+
const variantId = activeVariantId;
|
|
1766
|
+
const variantHash = metadata.variants?.hash;
|
|
1767
|
+
const data = await previewData(revision, variantId);
|
|
1768
|
+
if (variantId !== activeVariantId || revision !== metadata.expected.revisionId) return;
|
|
1769
|
+
before.mount(data);
|
|
1770
|
+
displayedRevision = revision;
|
|
1771
|
+
displayedVariantId = variantId;
|
|
1772
|
+
displayedVariantHash = variantHash;
|
|
1773
|
+
if (moment && metadata.moments.some(item => item.id === moment)) selectMoment(moment);
|
|
1606
1774
|
else before.playback();
|
|
1607
1775
|
}
|
|
1608
1776
|
|
|
1777
|
+
async function selectVariant(id, {force = false} = {}) {
|
|
1778
|
+
if (candidateId) throw Error('Choose Use this version or Discard before switching variants.');
|
|
1779
|
+
if (!force && id === activeVariantId && !variantCompare) return;
|
|
1780
|
+
if (id !== 'base' && !metadata.variants.variants.some(variant => variant.id === id)) throw Error('That variant is no longer available.');
|
|
1781
|
+
const version = ++variantSwitchVersion;
|
|
1782
|
+
const revision = metadata.expected.revisionId;
|
|
1783
|
+
clearVariantComparison();
|
|
1784
|
+
resetVariantDeleteConfirm();
|
|
1785
|
+
activeVariantId = id;
|
|
1786
|
+
drawVariants();
|
|
1787
|
+
updateExportButton();
|
|
1788
|
+
quickEditCtrl.render();
|
|
1789
|
+
invalidateQaIfStale();
|
|
1790
|
+
const isDraftStore = url => !url || url === 'https://play.google.com/store/apps/details?id=com.playablelab.draft' || /id=com\.(?:example|yourcompany|yourapp|demo|test)\./i.test(url);
|
|
1791
|
+
const activeStoreUrl = activeVariant()?.storeUrl ?? metadata.storeUrl;
|
|
1792
|
+
if (document.activeElement !== $('review-store-url')) $('review-store-url').value = isDraftStore(activeStoreUrl) ? '' : (activeStoreUrl ?? '');
|
|
1793
|
+
$('review-variant-status').textContent = 'Loading ' + (activeVariant()?.label ?? 'Base') + '…';
|
|
1794
|
+
try {
|
|
1795
|
+
const data = await previewData(revision, id);
|
|
1796
|
+
if (version !== variantSwitchVersion || id !== activeVariantId || revision !== metadata.expected.revisionId) return;
|
|
1797
|
+
before.applyVariant(data);
|
|
1798
|
+
displayedRevision = revision;
|
|
1799
|
+
displayedVariantId = id;
|
|
1800
|
+
displayedVariantHash = metadata.variants?.hash;
|
|
1801
|
+
if (moment && metadata.moments.some(item => item.id === moment)) selectMoment(moment);
|
|
1802
|
+
else before.playback();
|
|
1803
|
+
$('review-variant-status').textContent = 'Previewing ' + (activeVariant()?.label ?? 'Base') + '.';
|
|
1804
|
+
} catch (error) {
|
|
1805
|
+
if (version === variantSwitchVersion) $('review-variant-status').textContent = '';
|
|
1806
|
+
throw error;
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
async function compareActiveVariant() {
|
|
1811
|
+
if (candidateId) throw Error('Choose Use this version or Discard before comparing a variant.');
|
|
1812
|
+
if (variantCompare) {
|
|
1813
|
+
clearVariantComparison();
|
|
1814
|
+
await mountCurrent();
|
|
1815
|
+
drawVariants();
|
|
1816
|
+
return;
|
|
1817
|
+
}
|
|
1818
|
+
const variant = activeVariant();
|
|
1819
|
+
if (!variant) return;
|
|
1820
|
+
const version = ++variantSwitchVersion;
|
|
1821
|
+
const revision = metadata.expected.revisionId;
|
|
1822
|
+
$('review-variant-status').textContent = 'Loading Base comparison…';
|
|
1823
|
+
const [baseline, selected] = await Promise.all([projectData(revision), previewData(revision, variant.id)]);
|
|
1824
|
+
if (version !== variantSwitchVersion || variant.id !== activeVariantId || revision !== metadata.expected.revisionId) return;
|
|
1825
|
+
before.mount(baseline);
|
|
1826
|
+
after.show();
|
|
1827
|
+
after.mount(selected);
|
|
1828
|
+
displayedRevision = revision;
|
|
1829
|
+
displayedVariantId = 'base';
|
|
1830
|
+
displayedVariantHash = metadata.variants?.hash;
|
|
1831
|
+
variantCompare = true;
|
|
1832
|
+
comparisonVersion = undefined;
|
|
1833
|
+
toggleAttachment(false);
|
|
1834
|
+
$('review-previews').dataset.compare = 'true';
|
|
1835
|
+
$('review-before').querySelector('figcaption').textContent = 'Base';
|
|
1836
|
+
$('review-before').querySelector('figcaption').hidden = false;
|
|
1837
|
+
$('review-after').querySelector('figcaption').textContent = variant.label;
|
|
1838
|
+
const checkpoint = moment && metadata.moments.some(item => item.id === moment) ? moment : metadata.moments[0]?.id;
|
|
1839
|
+
if (checkpoint) selectMoment(checkpoint);
|
|
1840
|
+
else { before.playback(); after.playback(); }
|
|
1841
|
+
$('review-variant-status').textContent = '';
|
|
1842
|
+
syncComparisonChoice();
|
|
1843
|
+
drawVariants();
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
$('review-variant-edit').onclick = () => {
|
|
1847
|
+
const variant = activeVariant();
|
|
1848
|
+
if (variant) openVariantDialog(variant);
|
|
1849
|
+
};
|
|
1850
|
+
$('review-variant-delete').onclick = handle(async () => {
|
|
1851
|
+
const variant = activeVariant();
|
|
1852
|
+
if (!variant) return;
|
|
1853
|
+
if (deleteConfirmVariantId !== variant.id) {
|
|
1854
|
+
resetVariantDeleteConfirm();
|
|
1855
|
+
deleteConfirmVariantId = variant.id;
|
|
1856
|
+
$('review-variant-delete').textContent = 'Confirm delete?';
|
|
1857
|
+
deleteConfirmTimer = setTimeout(resetVariantDeleteConfirm, 4000);
|
|
1858
|
+
return;
|
|
1859
|
+
}
|
|
1860
|
+
resetVariantDeleteConfirm();
|
|
1861
|
+
const deleted = await api('/variants', {
|
|
1862
|
+
action: 'delete',
|
|
1863
|
+
variantId: variant.id,
|
|
1864
|
+
expectedVariantRevision: metadata.variants.revision,
|
|
1865
|
+
});
|
|
1866
|
+
metadata.variants = {...metadata.variants, ...deleted};
|
|
1867
|
+
variantDrawSignature = undefined;
|
|
1868
|
+
await selectVariant('base', {force: true});
|
|
1869
|
+
$('review-variant-status').textContent = `Deleted variant "${variant.label}".`;
|
|
1870
|
+
});
|
|
1871
|
+
$('review-variant-compare').onclick = handle(compareActiveVariant);
|
|
1872
|
+
$('review-variant-reset').onclick = handle(() => selectVariant('base'));
|
|
1873
|
+
$('review-variant-close').onclick = () => $('review-variant-dialog').close();
|
|
1874
|
+
$('review-variant-dialog').addEventListener('click', event => {
|
|
1875
|
+
if (event.target === $('review-variant-dialog')) $('review-variant-dialog').close();
|
|
1876
|
+
});
|
|
1877
|
+
$('review-variant-id').addEventListener('input', () => {
|
|
1878
|
+
variantIdManuallyEdited = Boolean($('review-variant-id').value.trim());
|
|
1879
|
+
});
|
|
1880
|
+
$('review-variant-label').addEventListener('input', () => {
|
|
1881
|
+
variantLabelAutoFilled = false;
|
|
1882
|
+
if (!variantIdManuallyEdited && !editingVariantId) {
|
|
1883
|
+
$('review-variant-id').value = slugifyVariantId($('review-variant-label').value);
|
|
1884
|
+
}
|
|
1885
|
+
});
|
|
1886
|
+
function applySelectedLanguageDefaults(selectEl) {
|
|
1887
|
+
const optLabel = selectEl.selectedOptions[0]?.textContent?.split(' · ')[0] ?? '';
|
|
1888
|
+
if (!editingVariantId && optLabel && (!$('review-variant-label').value.trim() || variantLabelAutoFilled)) {
|
|
1889
|
+
$('review-variant-label').value = optLabel.replace(/\s*\(RTL\)\s*/i, '').trim();
|
|
1890
|
+
variantLabelAutoFilled = true;
|
|
1891
|
+
if (!variantIdManuallyEdited) $('review-variant-id').value = slugifyVariantId($('review-variant-label').value);
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
$('review-variant-language-select').onchange = event => {
|
|
1895
|
+
const code = event.target.value;
|
|
1896
|
+
if (code !== 'custom') {
|
|
1897
|
+
$('review-variant-language').value = code;
|
|
1898
|
+
applySelectedLanguageDefaults(event.target);
|
|
1899
|
+
} else {
|
|
1900
|
+
$('review-variant-language').focus();
|
|
1901
|
+
}
|
|
1902
|
+
syncRtlBadge();
|
|
1903
|
+
const isRtl = RTL_LANG_RE.test($('review-variant-language').value.trim());
|
|
1904
|
+
for (const input of $('review-variant-translation-rows').querySelectorAll('input[data-loc-key]')) {
|
|
1905
|
+
input.dir = isRtl ? 'rtl' : 'ltr';
|
|
1906
|
+
}
|
|
1907
|
+
};
|
|
1908
|
+
$('review-variant-language').addEventListener('input', () => {
|
|
1909
|
+
syncRtlBadge();
|
|
1910
|
+
const isRtl = RTL_LANG_RE.test($('review-variant-language').value.trim());
|
|
1911
|
+
for (const input of $('review-variant-translation-rows').querySelectorAll('input[data-loc-key]')) {
|
|
1912
|
+
input.dir = isRtl ? 'rtl' : 'ltr';
|
|
1913
|
+
}
|
|
1914
|
+
});
|
|
1915
|
+
$('review-variant-preset').onchange = () => {
|
|
1916
|
+
syncVariantDialogVisibility();
|
|
1917
|
+
if ($('review-variant-preset').value === 'locale') {
|
|
1918
|
+
const select = $('review-variant-language-select');
|
|
1919
|
+
if (!$('review-variant-language').value.trim()) {
|
|
1920
|
+
const picked = select.value;
|
|
1921
|
+
if (picked && picked !== 'custom') {
|
|
1922
|
+
$('review-variant-language').value = picked;
|
|
1923
|
+
applySelectedLanguageDefaults(select);
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
syncRtlBadge();
|
|
1927
|
+
renderTranslationTable(null);
|
|
1928
|
+
}
|
|
1929
|
+
};
|
|
1930
|
+
$('review-variant-form').onsubmit = handle(async () => {
|
|
1931
|
+
const submit = $('review-variant-create');
|
|
1932
|
+
submit.disabled = true;
|
|
1933
|
+
$('review-variant-error').textContent = '';
|
|
1934
|
+
try {
|
|
1935
|
+
const preset = $('review-variant-preset').value, locale = preset === 'locale', readMap = id => {
|
|
1936
|
+
const value = JSON.parse($(id).value || '{}');
|
|
1937
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || Object.values(value).some(entry => typeof entry !== 'string')) throw Error('Translation maps must contain string values.');
|
|
1938
|
+
return value;
|
|
1939
|
+
};
|
|
1940
|
+
const label = $('review-variant-label').value.trim();
|
|
1941
|
+
const id = $('review-variant-id').value.trim() || slugifyVariantId(label);
|
|
1942
|
+
if (!id) throw Error('Enter a valid short ID (lowercase letters, numbers, and hyphens).');
|
|
1943
|
+
const localization = locale ? {texts: readMap('review-variant-texts'), actionTexts: readMap('review-variant-action-texts'), variables: readMap('review-variant-variables')} : {};
|
|
1944
|
+
let result;
|
|
1945
|
+
if (editingVariantId) {
|
|
1946
|
+
const existing = metadata.variants.variants.find(item => item.id === editingVariantId);
|
|
1947
|
+
const lang = locale ? $('review-variant-language').value.trim() : existing?.language;
|
|
1948
|
+
const rtlDir = lang && RTL_LANG_RE.test(lang) ? 'rtl' : undefined;
|
|
1949
|
+
const updatedVariant = {
|
|
1950
|
+
...(existing ?? {id, preset}),
|
|
1951
|
+
id: editingVariantId,
|
|
1952
|
+
label,
|
|
1953
|
+
...(locale ? {
|
|
1954
|
+
preset: 'locale',
|
|
1955
|
+
language: lang,
|
|
1956
|
+
texts: Object.fromEntries(Object.entries(localization.texts).map(([k, text]) => [k, {...(existing?.texts?.[k] ?? {}), text, ...(rtlDir ? {direction: rtlDir} : {})}])),
|
|
1957
|
+
actionTexts: localization.actionTexts,
|
|
1958
|
+
variables: localization.variables,
|
|
1959
|
+
} : {}),
|
|
1960
|
+
};
|
|
1961
|
+
result = await api('/variants', {
|
|
1962
|
+
action: 'upsert',
|
|
1963
|
+
variant: updatedVariant,
|
|
1964
|
+
expectedVariantRevision: metadata.variants.revision,
|
|
1965
|
+
});
|
|
1966
|
+
} else {
|
|
1967
|
+
const hookText = preset === 'shorter-hook' ? $('review-variant-hook-text').value.trim() : '';
|
|
1968
|
+
result = await api('/variants', {
|
|
1969
|
+
action: 'preset',
|
|
1970
|
+
id,
|
|
1971
|
+
label,
|
|
1972
|
+
preset,
|
|
1973
|
+
...(hookText ? {text: hookText} : {}),
|
|
1974
|
+
...(locale ? {language: $('review-variant-language').value.trim(), ...localization} : {}),
|
|
1975
|
+
expectedVariantRevision: metadata.variants.revision,
|
|
1976
|
+
});
|
|
1977
|
+
}
|
|
1978
|
+
metadata.variants = {...metadata.variants, ...result};
|
|
1979
|
+
variantDrawSignature = undefined;
|
|
1980
|
+
editingVariantId = null;
|
|
1981
|
+
$('review-variant-dialog').close();
|
|
1982
|
+
$('review-variant-form').reset();
|
|
1983
|
+
await selectVariant(result.variant.id, {force: true});
|
|
1984
|
+
} catch (error) {
|
|
1985
|
+
$('review-variant-error').textContent = errorLabels[error.message] ?? error.message;
|
|
1986
|
+
} finally {
|
|
1987
|
+
submit.disabled = false;
|
|
1988
|
+
}
|
|
1989
|
+
});
|
|
1990
|
+
|
|
1609
1991
|
async function closeCandidate() {
|
|
1610
1992
|
candidateId = undefined;
|
|
1611
1993
|
comparisonVersion = undefined;
|
|
1612
1994
|
after.hide();
|
|
1613
1995
|
$('review-previews').dataset.compare = 'false';
|
|
1614
1996
|
$('review-replay-change').hidden = true;
|
|
1997
|
+
$('review-before').querySelector('figcaption').textContent = 'Before';
|
|
1615
1998
|
$('review-before').querySelector('figcaption').hidden = true;
|
|
1999
|
+
$('review-after').querySelector('figcaption').textContent = 'After';
|
|
1616
2000
|
syncComparisonChoice();
|
|
1617
2001
|
await mountCurrent();
|
|
1618
2002
|
requestSignature = undefined;
|
|
@@ -1632,18 +2016,23 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
1632
2016
|
}
|
|
1633
2017
|
|
|
1634
2018
|
async function mountComparison(request) {
|
|
2019
|
+
clearVariantComparison();
|
|
1635
2020
|
const [baseline, candidate] = await Promise.all([
|
|
1636
|
-
displayedRevision === request.expected.revisionId ? undefined : projectData(request.expected.revisionId),
|
|
2021
|
+
displayedRevision === (request.baseline ?? request.expected).revisionId && displayedVariantId === 'base' ? undefined : projectData((request.baseline ?? request.expected).revisionId),
|
|
1637
2022
|
api('/review?candidate=' + encodeURIComponent(request.id)),
|
|
1638
2023
|
]);
|
|
1639
2024
|
if (baseline) {
|
|
1640
2025
|
before.mount(baseline);
|
|
1641
|
-
displayedRevision = request.expected.revisionId;
|
|
2026
|
+
displayedRevision = (request.baseline ?? request.expected).revisionId;
|
|
2027
|
+
displayedVariantId = 'base';
|
|
2028
|
+
displayedVariantHash = metadata.variants?.hash;
|
|
1642
2029
|
}
|
|
1643
2030
|
comparisonVersion = undefined;
|
|
1644
2031
|
toggleAttachment(false);
|
|
1645
2032
|
$('review-previews').dataset.compare = 'true';
|
|
2033
|
+
$('review-before').querySelector('figcaption').textContent = 'Before';
|
|
1646
2034
|
$('review-before').querySelector('figcaption').hidden = false;
|
|
2035
|
+
$('review-after').querySelector('figcaption').textContent = 'After';
|
|
1647
2036
|
after.show();
|
|
1648
2037
|
after.mount(candidate);
|
|
1649
2038
|
candidateId = request.id;
|
|
@@ -1655,230 +2044,103 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
1655
2044
|
drawRequests();
|
|
1656
2045
|
}
|
|
1657
2046
|
|
|
1658
|
-
const unresolved = ['waiting', 'claimed', 'needs-scope', '
|
|
1659
|
-
const onCurrentVersion = request => request.expected.revisionId === metadata.expected.revisionId;
|
|
2047
|
+
const unresolved = ['waiting', 'claimed', 'needs-scope', 'rejected', 'building'];
|
|
2048
|
+
const onCurrentVersion = request => (request.baseline ?? request.expected).revisionId === metadata.expected.revisionId;
|
|
1660
2049
|
const notesOf = request => request.notes ?? [request];
|
|
1661
2050
|
|
|
1662
2051
|
function editSavedNotes(request) {
|
|
1663
2052
|
if (draftText.value.trim() || queuedNotes.length) throw Error('Send or clear your current message before reusing a past one.');
|
|
1664
2053
|
editingRequestId = request.id;
|
|
1665
|
-
|
|
1666
|
-
const draft = notes.at(-1);
|
|
1667
|
-
const supported = note => metadata.targets.some(target => target.id === note.target && target.moment === note.moment &&
|
|
1668
|
-
note.fields.every(id => target.fields.some(field => field.id === id)));
|
|
1669
|
-
const normalized = ({target, fields, moment, note, intent}) => ({
|
|
1670
|
-
target: target && supported({target, fields, moment}) ? target : null,
|
|
1671
|
-
fields: target && supported({target, fields, moment}) ? fields : [],
|
|
1672
|
-
moment: metadata.moments.some(item => item.id === moment) ? moment : 'live',
|
|
1673
|
-
note,
|
|
1674
|
-
...(intent && metadata.deterministicAuthoring ? {intent} : {}),
|
|
1675
|
-
});
|
|
1676
|
-
queuedNotes = notes.slice(0, -1).map(normalized);
|
|
2054
|
+
queuedNotes = []; queuedExpected = undefined;
|
|
1677
2055
|
draftExpected = metadata.expected;
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
if (
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
drawRequests();
|
|
1691
|
-
drawQueued();
|
|
1692
|
-
$('review-queued').open = true;
|
|
1693
|
-
draftText.focus();
|
|
1694
|
-
}
|
|
1695
|
-
|
|
1696
|
-
function needsConnection(request) {
|
|
1697
|
-
if (request?.receipt?.route === 'deterministic' || request?.intent || request?.notes?.some(note => note.intent)) return false;
|
|
1698
|
-
return !metadata.feedbackModel || ['E_MODEL_AUTH', 'E_MODEL_FORBIDDEN'].includes(request?.reason);
|
|
2056
|
+
draftText.value = notesOf(request).map(note => note.text ?? note.note).filter(Boolean).join('\n');
|
|
2057
|
+
resizeDraft(); toggleAttachment(true); targetMenu.value = '';
|
|
2058
|
+
selectedScopeIds = new Set(notesOf(request).flatMap(note => note.scope ?? []));
|
|
2059
|
+
drawFields();
|
|
2060
|
+
if (request.readOnly || !selectedScopeIds.size) $('review-fields').open = true;
|
|
2061
|
+
const allowCreatesBox = $('review-allow-creates');
|
|
2062
|
+
if (allowCreatesBox) allowCreatesBox.checked = notesOf(request).some(note => note.allowCreates === true);
|
|
2063
|
+
$('review-queued').open = false;
|
|
2064
|
+
feedbackStatus.textContent = request.readOnly
|
|
2065
|
+
? 'Historical request: choose a new scope, then create a review on the current baseline.'
|
|
2066
|
+
: 'Review the scope, then create a fresh request on the current baseline.';
|
|
2067
|
+
draftText.focus(); drawRequests(); drawQueued();
|
|
1699
2068
|
}
|
|
1700
2069
|
|
|
1701
2070
|
function composeChatTurn(request) {
|
|
1702
2071
|
const turn = reviewElement('div', '', 'tora-chat-turn');
|
|
1703
|
-
const current = onCurrentVersion(request);
|
|
1704
|
-
const
|
|
1705
|
-
|
|
1706
|
-
// 1. User message bubble
|
|
2072
|
+
const current = onCurrentVersion(request), status = request.status;
|
|
2073
|
+
const notes = notesOf(request);
|
|
1707
2074
|
const userBubble = reviewElement('div', '', 'tora-bubble tora-bubble-user');
|
|
1708
2075
|
const userMeta = reviewElement('div', '', 'tora-bubble-meta');
|
|
1709
|
-
userMeta.append(reviewElement('strong', '
|
|
1710
|
-
const notes = notesOf(request);
|
|
1711
|
-
if (notes.length === 1 && notes[0].target) {
|
|
1712
|
-
userMeta.append(reviewElement('span', '🎯 ' + noteLabel(notes[0]), 'tora-pill'));
|
|
1713
|
-
}
|
|
2076
|
+
userMeta.append(reviewElement('strong', request.readOnly ? 'Historical review' : 'Review notes'));
|
|
1714
2077
|
userBubble.append(userMeta);
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
for (const note of notes) {
|
|
1720
|
-
const row = reviewElement('li');
|
|
1721
|
-
row.append(reviewElement('strong', noteLabel(note)), reviewElement('p', note.note));
|
|
1722
|
-
list.append(row);
|
|
1723
|
-
}
|
|
1724
|
-
userBubble.append(list);
|
|
1725
|
-
}
|
|
1726
|
-
turn.append(userBubble);
|
|
1727
|
-
|
|
1728
|
-
// 2. Assistant response bubble
|
|
1729
|
-
const botBubble = reviewElement('div', '', 'tora-bubble tora-bubble-assistant');
|
|
1730
|
-
botBubble.dataset.status = status;
|
|
1731
|
-
const botMeta = reviewElement('div', '', 'tora-bubble-meta');
|
|
1732
|
-
botMeta.append(reviewElement('strong', 'Tora'));
|
|
1733
|
-
botMeta.append(reviewElement('span', !current && unresolved.includes(status) ? 'Earlier version' : (statusLabels[status] ?? status), 'tora-status-badge'));
|
|
1734
|
-
if (request.receipt?.route === 'deterministic') {
|
|
1735
|
-
botMeta.append(reviewElement('span', 'Instant · $0', 'review-route'));
|
|
1736
|
-
} else if (request.receipt?.route === 'interpretation') {
|
|
1737
|
-
const calls = request.receipt.providerCalls?.filter(call => call.phase === 'interpretation').length ?? 0;
|
|
1738
|
-
botMeta.append(reviewElement('span', `Interpreted · ${calls} call${calls === 1 ? '' : 's'}`, 'review-route'));
|
|
1739
|
-
} else if (['general-agent', 'agent'].includes(request.receipt?.route)) {
|
|
1740
|
-
const modelLabel = metadata.connection?.modelLabel || 'Agent';
|
|
1741
|
-
botMeta.append(reviewElement('span', modelLabel, 'review-route'));
|
|
2078
|
+
const list = reviewElement('ul', '', 'review-note-items');
|
|
2079
|
+
for (const note of notes) {
|
|
2080
|
+
const row = reviewElement('li');
|
|
2081
|
+
row.append(reviewElement('strong', noteLabel(note)), reviewElement('p', note.text ?? note.note)); list.append(row);
|
|
1742
2082
|
}
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
if (evidence.length) {
|
|
2083
|
+
userBubble.append(list); turn.append(userBubble);
|
|
2084
|
+
const response = reviewElement('div', '', 'tora-bubble tora-bubble-assistant');
|
|
2085
|
+
response.dataset.status = status;
|
|
2086
|
+
const meta = reviewElement('div', '', 'tora-bubble-meta');
|
|
2087
|
+
meta.append(reviewElement('strong', 'External agent'), reviewElement('span', !current ? 'Earlier version' : (statusLabels[status] ?? status), 'tora-status-badge'));
|
|
2088
|
+
response.append(meta);
|
|
2089
|
+
if (request.readOnly) response.append(reviewElement('p', 'Read-only history. Create a new scoped review to reuse these notes.'));
|
|
2090
|
+
if (status === 'building') response.append(reviewElement('p', 'The external client is building and checking a candidate.'));
|
|
2091
|
+
if (request.candidate) response.append(reviewElement('p', request.candidate.summary));
|
|
2092
|
+
if (request.candidate?.changedIds?.length) {
|
|
1754
2093
|
const details = reviewElement('details', '', 'tora-diff-details');
|
|
1755
|
-
details.append(reviewElement('summary',
|
|
1756
|
-
const
|
|
1757
|
-
for (const
|
|
1758
|
-
details.append(
|
|
1759
|
-
botBubble.append(details);
|
|
2094
|
+
details.append(reviewElement('summary', 'Changed records (' + request.candidate.changedIds.length + ')'));
|
|
2095
|
+
const changed = reviewElement('ul');
|
|
2096
|
+
for (const id of request.candidate.changedIds) changed.append(reviewElement('li', id));
|
|
2097
|
+
details.append(changed); response.append(details);
|
|
1760
2098
|
}
|
|
1761
|
-
|
|
1762
|
-
if (
|
|
1763
|
-
const
|
|
1764
|
-
form.append(reviewElement('p', request.question));
|
|
1765
|
-
const row = reviewElement('div', '', 'tora-clarify-row');
|
|
1766
|
-
const input = reviewElement('input');
|
|
1767
|
-
input.type = 'text';
|
|
1768
|
-
input.required = true;
|
|
1769
|
-
input.maxLength = 2000;
|
|
1770
|
-
input.placeholder = 'Reply to Tora…';
|
|
1771
|
-
const submit = reviewElement('button', 'Reply ↑', 'review-primary');
|
|
1772
|
-
row.append(input, submit);
|
|
1773
|
-
form.append(row);
|
|
1774
|
-
form.onsubmit = event => {
|
|
1775
|
-
event.preventDefault();
|
|
1776
|
-
if (input.value.trim()) resolveRequest(request.id, input.value.trim());
|
|
1777
|
-
};
|
|
1778
|
-
botBubble.append(form);
|
|
2099
|
+
if (request.reason) response.append(reviewElement('p', errorLabels[request.reason] ?? request.reason));
|
|
2100
|
+
if (request.creativeQa?.blockers?.length) {
|
|
2101
|
+
const diagnostics = reviewElement('pre', JSON.stringify(request.creativeQa.blockers, null, 2)); response.append(diagnostics);
|
|
1779
2102
|
}
|
|
1780
|
-
|
|
1781
|
-
if (current && request.reason && status !== 'resolving') {
|
|
1782
|
-
const message = errorLabels[request.reason] ?? request.reason;
|
|
1783
|
-
const retry = request.retryAt > Date.now() ? ' Available after ' + new Date(request.retryAt).toLocaleTimeString() + '.' : '';
|
|
1784
|
-
botBubble.append(reviewElement('p', message + retry));
|
|
1785
|
-
}
|
|
1786
|
-
|
|
1787
2103
|
const controls = reviewElement('div', '', 'review-actions');
|
|
1788
2104
|
const action = (label, callback, primary = false, parent = controls) => {
|
|
1789
|
-
const button = reviewElement('button', label, primary ? 'review-primary' : '');
|
|
1790
|
-
button.
|
|
1791
|
-
button.onclick = handle(callback);
|
|
1792
|
-
parent.append(button);
|
|
1793
|
-
return button;
|
|
2105
|
+
const button = reviewElement('button', label, primary ? 'review-primary' : ''); button.type = 'button';
|
|
2106
|
+
button.onclick = handle(callback); parent.append(button); return button;
|
|
1794
2107
|
};
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
const seenLabels = new Set();
|
|
1798
|
-
for (const note of notes) {
|
|
1799
|
-
if (!metadata.moments.some(item => item.id === note.moment)) continue;
|
|
1800
|
-
const label = noteLabel(note);
|
|
1801
|
-
if (seenLabels.has(label)) continue;
|
|
1802
|
-
seenLabels.add(label);
|
|
1803
|
-
if (notes.length > 1 || candidateId !== request.id) {
|
|
1804
|
-
action('Compare ' + label, async () => { await compare(request); selectMoment(note.moment); });
|
|
1805
|
-
}
|
|
1806
|
-
}
|
|
1807
|
-
if (!seenLabels.size && candidateId !== request.id) {
|
|
1808
|
-
action('Compare preview', async () => { await compare(request); });
|
|
1809
|
-
}
|
|
1810
|
-
for (const [checkpoint, label] of [['end-card', 'Replay win'], ['timeout', 'Replay loss']]) {
|
|
1811
|
-
if (!request.candidate.audioMoments?.includes(checkpoint) || !metadata.moments.some(item => item.id === checkpoint)) continue;
|
|
1812
|
-
const replay = reviewElement('button', label);
|
|
1813
|
-
replay.type = 'button';
|
|
1814
|
-
replay.onclick = event => {
|
|
1815
|
-
if (candidateId !== request.id || !event.isTrusted) return;
|
|
1816
|
-
try {
|
|
1817
|
-
comparisonVersion = 'after';
|
|
1818
|
-
selectMoment(checkpoint);
|
|
1819
|
-
syncComparisonChoice();
|
|
1820
|
-
after.seek(checkpoint, {motion: true, trustedEvent: event});
|
|
1821
|
-
} catch (error) { showError(error); }
|
|
1822
|
-
};
|
|
1823
|
-
controls.append(replay);
|
|
1824
|
-
}
|
|
2108
|
+
if (status === 'candidate' && current && !request.readOnly) {
|
|
2109
|
+
if (candidateId !== request.id) action('Compare preview', () => compare(request));
|
|
1825
2110
|
action('Use this version', async () => {
|
|
1826
2111
|
await api('/review', {action: 'promote', requestId: request.id});
|
|
1827
|
-
metadata = await api('/review');
|
|
1828
|
-
await closeCandidate();
|
|
1829
|
-
await updateMetadata(false);
|
|
2112
|
+
metadata = await api('/review'); await closeCandidate(); await updateMetadata(false);
|
|
1830
2113
|
feedbackStatus.textContent = 'Version applied.';
|
|
1831
2114
|
}, true);
|
|
1832
2115
|
action('Discard', async () => {
|
|
1833
2116
|
await api('/review', {action: 'discard', requestId: request.id});
|
|
1834
|
-
metadata = await api('/review');
|
|
1835
|
-
if (candidateId === request.id) await closeCandidate();
|
|
1836
|
-
await updateMetadata(false);
|
|
2117
|
+
metadata = await api('/review'); if (candidateId === request.id) await closeCandidate(); await updateMetadata(false);
|
|
1837
2118
|
});
|
|
1838
|
-
} else if (status === '
|
|
1839
|
-
action('
|
|
1840
|
-
} else if (unresolved.includes(status) && !['
|
|
1841
|
-
|
|
1842
|
-
const connectBtn = reviewElement('button', 'Connect verified API', 'review-primary');
|
|
1843
|
-
connectBtn.type = 'button';
|
|
1844
|
-
connectBtn.onclick = () => {
|
|
1845
|
-
pendingRetryRequestId = request.id;
|
|
1846
|
-
connectionCtrl.open();
|
|
1847
|
-
};
|
|
1848
|
-
controls.append(connectBtn);
|
|
1849
|
-
} else if (current && status !== 'needs-clarification' && metadata.feedbackModel
|
|
1850
|
-
&& (!request.retryAt || request.retryAt <= Date.now()) && request.reason !== 'E_REVIEW_AGENT_LIMIT') {
|
|
1851
|
-
action(status === 'waiting' || status === 'claimed' ? 'Run with AI' : 'Try again', () => resolveRequest(request.id), true);
|
|
1852
|
-
}
|
|
1853
|
-
action(current ? 'Edit in chat' : 'Reuse', () => editSavedNotes(request));
|
|
1854
|
-
if (current && ['waiting', 'claimed', 'rejected'].includes(status)) {
|
|
1855
|
-
const manual = reviewElement('details', '', 'review-manual');
|
|
1856
|
-
manual.append(reviewElement('summary', 'Use MCP agent ($0)'));
|
|
1857
|
-
const instruction = reviewElement('input');
|
|
1858
|
-
instruction.setAttribute('aria-label', 'Agent instruction');
|
|
1859
|
-
instruction.readOnly = true;
|
|
1860
|
-
instruction.value = 'Open Tora review request ' + request.id + ' for project ' + projectId + ' and prepare the requested revision.';
|
|
1861
|
-
action('Copy MCP instruction', () => copyInstruction(instruction, feedbackStatus), false, manual);
|
|
1862
|
-
manual.append(instruction);
|
|
1863
|
-
controls.append(manual);
|
|
1864
|
-
}
|
|
1865
|
-
} else if (status === 'discarded') {
|
|
1866
|
-
action('Reuse', () => editSavedNotes(request));
|
|
2119
|
+
} else if (request.readOnly || status === 'discarded') {
|
|
2120
|
+
action(request.readOnly ? 'Create new review from these notes' : 'Reuse notes', () => editSavedNotes(request));
|
|
2121
|
+
} else if (unresolved.includes(status) && !['building'].includes(status)) {
|
|
2122
|
+
action('Edit notes and scope', () => editSavedNotes(request));
|
|
1867
2123
|
}
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
2124
|
+
if (current && !request.readOnly && ['waiting', 'claimed', 'needs-scope', 'rejected'].includes(status)) {
|
|
2125
|
+
const manual = reviewElement('details', '', 'review-manual');
|
|
2126
|
+
manual.append(reviewElement('summary', 'Copy external-agent handoff'));
|
|
2127
|
+
const instruction = reviewElement('textarea');
|
|
2128
|
+
instruction.setAttribute('aria-label', 'Agent handoff'); instruction.readOnly = true; instruction.rows = 4;
|
|
2129
|
+
instruction.value = 'Project: ' + projectId + '\nReview request: ' + request.id + '\nBaseline: ' + JSON.stringify(request.baseline ?? request.expected) + '\nUse tora_review_claim, then tora_review_propose with native operations covering every note.';
|
|
2130
|
+
action('Copy handoff', () => copyInstruction(instruction, feedbackStatus), false, manual);
|
|
2131
|
+
manual.append(instruction); controls.append(manual);
|
|
2132
|
+
}
|
|
2133
|
+
if (controls.childElementCount) response.append(controls);
|
|
2134
|
+
turn.append(response); return turn;
|
|
1872
2135
|
}
|
|
1873
2136
|
|
|
1874
2137
|
function drawRequests() {
|
|
1875
2138
|
const chronological = metadata.requests.filter(request => request.status !== 'superseded');
|
|
1876
2139
|
const activeCandidate = [...chronological].reverse().find(request => onCurrentVersion(request) && request.status === 'candidate');
|
|
1877
|
-
const activeResolving = [...chronological].reverse().find(request => onCurrentVersion(request) &&
|
|
2140
|
+
const activeResolving = [...chronological].reverse().find(request => onCurrentVersion(request) && request.status === 'building');
|
|
1878
2141
|
$('review-candidate-banner').hidden = !activeCandidate;
|
|
1879
2142
|
|
|
1880
|
-
const signature = JSON.stringify([chronological, metadata.expected.revisionId,
|
|
1881
|
-
chronological.map(request => !request.retryAt || request.retryAt <= Date.now())]);
|
|
2143
|
+
const signature = JSON.stringify([chronological, metadata.expected.revisionId, candidateId]);
|
|
1882
2144
|
if (signature === requestSignature) return;
|
|
1883
2145
|
requestSignature = signature;
|
|
1884
2146
|
|
|
@@ -1889,10 +2151,79 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
1889
2151
|
scrollThread();
|
|
1890
2152
|
}
|
|
1891
2153
|
|
|
2154
|
+
let activeSideTab = 'chat';
|
|
2155
|
+
let safeAreasVisible = false;
|
|
2156
|
+
|
|
2157
|
+
const quickEditCtrl = createQuickEditPanel({
|
|
2158
|
+
container: $('review-quick-edit-pane'),
|
|
2159
|
+
projectId,
|
|
2160
|
+
api,
|
|
2161
|
+
getMetadata: () => metadata,
|
|
2162
|
+
getAssetDataUrl: assetId => {
|
|
2163
|
+
const list = assetsByRevision.get(displayedRevision);
|
|
2164
|
+
const match = Array.isArray(list) ? list.find(item => item.id === assetId) : null;
|
|
2165
|
+
return match?.data ? `data:${match.mime};base64,${match.data}` : '';
|
|
2166
|
+
},
|
|
2167
|
+
isCandidateActive: () => Boolean(candidateId),
|
|
2168
|
+
getActiveVariant: () => activeVariant() ?? null,
|
|
2169
|
+
getActiveVariantLabel: () => activeVariant()?.label ?? '',
|
|
2170
|
+
onUpdated: async () => {
|
|
2171
|
+
await updateMetadata(true, false);
|
|
2172
|
+
await refreshBudget(true);
|
|
2173
|
+
},
|
|
2174
|
+
onSelectMoment: nextMoment => {
|
|
2175
|
+
if (metadata.moments.some(item => item.id === nextMoment)) selectMoment(nextMoment);
|
|
2176
|
+
},
|
|
2177
|
+
onHighlight: ids => {
|
|
2178
|
+
before.outlines(ids ?? []);
|
|
2179
|
+
},
|
|
2180
|
+
onStatus: msg => { feedbackStatus.textContent = msg; },
|
|
2181
|
+
onError: err => {
|
|
2182
|
+
if (!err) $('review-error').textContent = '';
|
|
2183
|
+
else showError(typeof err === 'string' ? Error(err) : err);
|
|
2184
|
+
},
|
|
2185
|
+
prepareImageFile,
|
|
2186
|
+
prepareAudioFile,
|
|
2187
|
+
formatBytes,
|
|
2188
|
+
reviewElement,
|
|
2189
|
+
isHosted,
|
|
2190
|
+
});
|
|
2191
|
+
|
|
2192
|
+
function setSideTab(tab) {
|
|
2193
|
+
activeSideTab = isHosted || tab === 'quick' ? 'quick' : 'chat';
|
|
2194
|
+
const isQuick = activeSideTab === 'quick';
|
|
2195
|
+
$('review-tab-chat').setAttribute('aria-selected', String(!isQuick));
|
|
2196
|
+
$('review-tab-quick').setAttribute('aria-selected', String(isQuick));
|
|
2197
|
+
$('review-chat-pane').hidden = isHosted || isQuick;
|
|
2198
|
+
$('review-quick-edit-pane').hidden = !isQuick;
|
|
2199
|
+
$('review-note-toggle').hidden = isHosted || isQuick || !metadata.scopes.length;
|
|
2200
|
+
if (isQuick) {
|
|
2201
|
+
toggleAttachment(false);
|
|
2202
|
+
quickEditCtrl.render();
|
|
2203
|
+
before.picker.dataset.active = before.isPlaying() ? 'false' : 'true';
|
|
2204
|
+
} else {
|
|
2205
|
+
before.outlines([]);
|
|
2206
|
+
before.picker.dataset.active = attachment.hidden ? 'false' : 'true';
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
|
|
2210
|
+
$('review-tab-chat').onclick = () => setSideTab('chat');
|
|
2211
|
+
$('review-tab-quick').onclick = () => setSideTab('quick');
|
|
2212
|
+
|
|
1892
2213
|
async function updateMetadata(fetchLatest = true, automaticCompare = false) {
|
|
1893
2214
|
if (fetchLatest) metadata = await api('/review');
|
|
2215
|
+
metadata.variants ??= {format: 'tora-variants-1', revision: 0, variants: []};
|
|
2216
|
+
metadata.moments ??= [{id: 'opening', label: 'Opening'}];
|
|
2217
|
+
metadata.targets ??= [];
|
|
2218
|
+
metadata.scopes ??= [];
|
|
2219
|
+
if (activeVariantId !== 'base' && !metadata.variants.variants.some(variant => variant.id === activeVariantId)) {
|
|
2220
|
+
activeVariantId = 'base';
|
|
2221
|
+
variantSwitchVersion++;
|
|
2222
|
+
clearVariantComparison();
|
|
2223
|
+
}
|
|
2224
|
+
const variantContextChanged = displayedVariantHash !== metadata.variants.hash;
|
|
2225
|
+
if (variantCompare && (displayedRevision !== metadata.expected.revisionId || variantContextChanged)) clearVariantComparison();
|
|
1894
2226
|
$('review-title').textContent = metadata.name;
|
|
1895
|
-
$('review-model-choice').hidden = !metadata.paidFeedbackModel;
|
|
1896
2227
|
updateRouteHint();
|
|
1897
2228
|
const staleNote = draftExpected && draftExpected.revisionId !== metadata.expected.revisionId;
|
|
1898
2229
|
if (staleNote) feedbackStatus.textContent = 'The playable changed. Press play to sync the preview.';
|
|
@@ -1906,10 +2237,15 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
1906
2237
|
drawQuickChips();
|
|
1907
2238
|
drawWinSoundControls();
|
|
1908
2239
|
$('review-undo').hidden = !metadata.canUndo;
|
|
2240
|
+
$('review-redo').hidden = !metadata.canRedo;
|
|
2241
|
+
drawVariants();
|
|
1909
2242
|
updateExportButton();
|
|
2243
|
+
quickEditCtrl.render();
|
|
2244
|
+
invalidateQaIfStale();
|
|
1910
2245
|
const isDraftStore = url => !url || url === 'https://play.google.com/store/apps/details?id=com.playablelab.draft' || /id=com\.(?:example|yourcompany|yourapp|demo|test)\./i.test(url);
|
|
1911
|
-
|
|
1912
|
-
if (
|
|
2246
|
+
const activeStoreUrl = activeVariant()?.storeUrl ?? metadata.storeUrl;
|
|
2247
|
+
if (document.activeElement !== $('review-store-url')) $('review-store-url').value = isDraftStore(activeStoreUrl) ? '' : (activeStoreUrl ?? '');
|
|
2248
|
+
if (!candidateId && !variantCompare && !staleNote && (displayedRevision !== metadata.expected.revisionId || displayedVariantId !== activeVariantId || variantContextChanged)) await mountCurrent();
|
|
1913
2249
|
drawRequests();
|
|
1914
2250
|
const candidate = metadata.requests.findLast(request => request.status === 'candidate' && onCurrentVersion(request));
|
|
1915
2251
|
if (automaticCompare && candidate && !candidateId && !draftText.value.trim() && !queuedNotes.length) await compare(candidate);
|
|
@@ -1938,9 +2274,10 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
1938
2274
|
const other = version === 'after' ? before : after;
|
|
1939
2275
|
if (!restart && target.isPlaying()) {
|
|
1940
2276
|
target.freeze();
|
|
2277
|
+
if (version === 'before' && activeSideTab === 'quick') before.picker.dataset.active = 'true';
|
|
1941
2278
|
return;
|
|
1942
2279
|
}
|
|
1943
|
-
if (candidateId) {
|
|
2280
|
+
if (candidateId || variantCompare) {
|
|
1944
2281
|
comparisonVersion = version;
|
|
1945
2282
|
other.freeze();
|
|
1946
2283
|
syncComparisonChoice();
|
|
@@ -1957,6 +2294,7 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
1957
2294
|
} else {
|
|
1958
2295
|
target.resume();
|
|
1959
2296
|
}
|
|
2297
|
+
if (version === 'before') before.picker.dataset.active = 'false';
|
|
1960
2298
|
feedbackStatus.textContent = '';
|
|
1961
2299
|
}
|
|
1962
2300
|
|
|
@@ -1964,18 +2302,39 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
1964
2302
|
$('review-before-restart').onclick = handle(() => toggleVersionPlay('before', true));
|
|
1965
2303
|
$('review-after-toggle').onclick = handle(() => toggleVersionPlay('after', false));
|
|
1966
2304
|
$('review-after-restart').onclick = handle(() => toggleVersionPlay('after', true));
|
|
1967
|
-
|
|
2305
|
+
const deviceSelect = $('review-device');
|
|
2306
|
+
function applyViewport() {
|
|
2307
|
+
const deviceId = deviceSelect.value;
|
|
1968
2308
|
$('review-previews').dataset.orientation = orientation.value;
|
|
1969
2309
|
before.orient();
|
|
1970
2310
|
after.orient();
|
|
2311
|
+
before.setDevice(deviceId);
|
|
2312
|
+
after.setDevice(deviceId);
|
|
1971
2313
|
before.freeze();
|
|
1972
|
-
if (candidateId) after.freeze();
|
|
2314
|
+
if (candidateId || variantCompare) after.freeze();
|
|
1973
2315
|
if (moment && metadata.moments.some(item => item.id === moment)) selectMoment(moment);
|
|
1974
|
-
}
|
|
2316
|
+
}
|
|
2317
|
+
|
|
2318
|
+
deviceSelect.onchange = handle(applyViewport);
|
|
2319
|
+
orientation.onchange = handle(applyViewport);
|
|
2320
|
+
$('review-safe-areas').onclick = () => {
|
|
2321
|
+
safeAreasVisible = !safeAreasVisible;
|
|
2322
|
+
$('review-safe-areas').setAttribute('aria-pressed', String(safeAreasVisible));
|
|
2323
|
+
before.setSafeAreas(safeAreasVisible);
|
|
2324
|
+
after.setSafeAreas(safeAreasVisible);
|
|
2325
|
+
};
|
|
1975
2326
|
|
|
1976
2327
|
$('review-note-toggle').onclick = handle(() => toggleAttachment(attachment.hidden));
|
|
1977
2328
|
$('review-clear-target').onclick = handle(() => toggleAttachment(false));
|
|
1978
|
-
targetMenu.onchange =
|
|
2329
|
+
targetMenu.onchange = () => {
|
|
2330
|
+
showAllScopeRecords = false;
|
|
2331
|
+
selectedScopeIds = targetMenu.value ? new Set([targetMenu.value]) : new Set();
|
|
2332
|
+
drawFields();
|
|
2333
|
+
};
|
|
2334
|
+
$('review-scope-filter').oninput = event => {
|
|
2335
|
+
scopeFilterText = event.target.value;
|
|
2336
|
+
drawFields();
|
|
2337
|
+
};
|
|
1979
2338
|
|
|
1980
2339
|
$('rev-menu-target').onclick = () => {
|
|
1981
2340
|
popover.close();
|
|
@@ -2023,7 +2382,7 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
2023
2382
|
id: assetId,
|
|
2024
2383
|
mime: prepared.mime,
|
|
2025
2384
|
data: prepared.data,
|
|
2026
|
-
rights: 'Creator uploaded directly in Tora Studio
|
|
2385
|
+
rights: 'Creator uploaded directly in Tora Studio and confirmed commercial rights.',
|
|
2027
2386
|
},
|
|
2028
2387
|
});
|
|
2029
2388
|
feedbackStatus.textContent = '';
|
|
@@ -2031,7 +2390,7 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
2031
2390
|
const meta = reviewElement('div', '', 'tora-bubble-meta'), receipt = uploaded.asset.optimization;
|
|
2032
2391
|
meta.append(reviewElement('strong', 'Tora'), reviewElement('span', 'Asset added', 'tora-status-badge'));
|
|
2033
2392
|
const savings = receipt ? ` · ${receipt.mode}-optimized from ${formatBytes(receipt.originalBytes)} (${receipt.savedPercent >= 0 ? '-' : '+'}${Math.abs(receipt.savedPercent)}%)` : '';
|
|
2034
|
-
log.append(meta, reviewElement('p', `Added "${prepared.name}" (${formatBytes(uploaded.asset.bytes)}${savings}) as asset "${assetId}".
|
|
2393
|
+
log.append(meta, reviewElement('p', `Added "${prepared.name}" (${formatBytes(uploaded.asset.bytes)}${savings}) as asset "${assetId}". Use Quick Edit or your connected AI client to assign it.`));
|
|
2035
2394
|
if (receipt && receipt.originalBytes <= 700000 && receipt.originalHash !== uploaded.asset.hash) {
|
|
2036
2395
|
const lossless = reviewElement('button', 'Use lossless', 'review-button'); lossless.type = 'button';
|
|
2037
2396
|
lossless.onclick = handle(async () => {
|
|
@@ -2072,42 +2431,45 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
2072
2431
|
|
|
2073
2432
|
before.picker.onclick = event => {
|
|
2074
2433
|
const hit = before.pick(event);
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2434
|
+
if (activeSideTab === 'quick') {
|
|
2435
|
+
if (quickEditCtrl.focusFromHit(hit)) {
|
|
2436
|
+
before.outlines(hit.slice(0, 1));
|
|
2437
|
+
}
|
|
2438
|
+
return;
|
|
2439
|
+
}
|
|
2440
|
+
const targetId = hit.find(id => metadata.scopes.some(scope => scope.collection === 'components' && scope.id === id));
|
|
2441
|
+
if (targetId) {
|
|
2442
|
+
targetMenu.value = targetId;
|
|
2443
|
+
selectedScopeIds = new Set([targetId]);
|
|
2444
|
+
showAllScopeRecords = false;
|
|
2445
|
+
drawFields();
|
|
2446
|
+
}
|
|
2082
2447
|
};
|
|
2083
2448
|
new ResizeObserver(paintOutline).observe(before.picker);
|
|
2084
2449
|
|
|
2085
2450
|
function noteLabel(note) {
|
|
2451
|
+
if (note.scope?.length) return note.scope.map(id => friendlyScopeLabel(metadata.scopes.find(scope => scope.id === id)) || id).join(', ');
|
|
2086
2452
|
return metadata.targets.find(item => item.id === note.target)?.label
|
|
2087
2453
|
?? metadata.moments.find(item => item.id === note.moment)?.label
|
|
2088
|
-
?? '
|
|
2454
|
+
?? 'Scoped review';
|
|
2089
2455
|
}
|
|
2090
2456
|
|
|
2091
2457
|
function drawQueued() {
|
|
2092
2458
|
const stale = [queuedExpected, draftExpected].some(expected => expected && expected.revisionId !== metadata.expected.revisionId);
|
|
2093
2459
|
const hasText = Boolean(draftText.value.trim());
|
|
2094
|
-
const hasDirect = !attachment.hidden && Boolean(
|
|
2095
|
-
$('review-direct-text')?.value ||
|
|
2096
|
-
[...$('review-field-options').querySelectorAll('input[data-direct-timing-field]')].some(input => input.value) ||
|
|
2097
|
-
$('review-win-cue-replacement')?.value);
|
|
2098
2460
|
const unavailable = Boolean(candidateId);
|
|
2099
|
-
$('review-note-toggle').hidden = !metadata.
|
|
2461
|
+
$('review-note-toggle').hidden = isHosted || activeSideTab === 'quick' || !metadata.scopes.length;
|
|
2100
2462
|
$('review-note-toggle').disabled = unavailable;
|
|
2101
2463
|
draftText.disabled = unavailable;
|
|
2102
2464
|
$('review-queued').hidden = queuedNotes.length === 0;
|
|
2103
2465
|
$('review-queued-label').textContent = queuedNotes.length + (queuedNotes.length === 1 ? ' note queued' : ' notes queued');
|
|
2104
|
-
$('review-submit').disabled = stale || unavailable || (!hasText && !
|
|
2105
|
-
const signature = JSON.stringify([stale, queuedNotes.map(note => [note.
|
|
2466
|
+
$('review-submit').disabled = stale || unavailable || (!hasText && !queuedNotes.length);
|
|
2467
|
+
const signature = JSON.stringify([stale, queuedNotes.map(note => [note.scope, note.moment, note.text])]);
|
|
2106
2468
|
if (signature === queuedSignature) return;
|
|
2107
2469
|
queuedSignature = signature;
|
|
2108
2470
|
const items = queuedNotes.map((note, index) => {
|
|
2109
2471
|
const item = reviewElement('li');
|
|
2110
|
-
item.append(reviewElement('strong', noteLabel(note)), reviewElement('p', note.note));
|
|
2472
|
+
item.append(reviewElement('strong', noteLabel(note)), reviewElement('p', note.text ?? note.note));
|
|
2111
2473
|
const remove = reviewElement('button', 'Remove');
|
|
2112
2474
|
remove.type = 'button';
|
|
2113
2475
|
remove.setAttribute('aria-label', 'Remove note ' + (index + 1));
|
|
@@ -2125,44 +2487,21 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
2125
2487
|
|
|
2126
2488
|
function readDraft() {
|
|
2127
2489
|
const text = draftText.value.trim();
|
|
2128
|
-
|
|
2129
|
-
const
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
const
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
let note = text;
|
|
2144
|
-
if (replacementCatalogId) {
|
|
2145
|
-
intent = {
|
|
2146
|
-
format: 'tora-authoring-intent-1', noteId: '1', action: 'transferOutcomeCue', targetRole: 'outcomeCues',
|
|
2147
|
-
arguments: {sourceOutcome: 'win', destinationOutcome: 'loss', replacementCatalogId},
|
|
2148
|
-
constraints: {replacementMustBeNew: true, preserveOrdinaryCues: true}, requiredChecks: ['win-audio', 'loss-audio'],
|
|
2149
|
-
};
|
|
2150
|
-
note ||= 'Move the current win cue to loss and use the selected new win cue.';
|
|
2151
|
-
} else if (directText) {
|
|
2152
|
-
if (directText.trim() !== directText) throw Error('Remove leading or trailing spaces in the button wording.');
|
|
2153
|
-
intent = {
|
|
2154
|
-
format: 'tora-authoring-intent-1', noteId: '1', action: 'replaceText', targetRole: 'primaryCta',
|
|
2155
|
-
arguments: {text: directText}, constraints: {literal: true}, requiredChecks: ['package', 'diff-1'],
|
|
2156
|
-
};
|
|
2157
|
-
note ||= `Change the selected CTA to "${directText}"`;
|
|
2158
|
-
} else if (Number.isFinite(directSeconds)) {
|
|
2159
|
-
intent = {
|
|
2160
|
-
format: 'tora-authoring-intent-1', noteId: '1', action: 'setTiming', targetRole: 'reviewTiming',
|
|
2161
|
-
arguments: {field: timingField, seconds: directSeconds}, constraints: {absolute: true}, requiredChecks: ['package', 'diff-1'],
|
|
2162
|
-
};
|
|
2163
|
-
note ||= `Set the selected timing to ${directSeconds} seconds.`;
|
|
2164
|
-
}
|
|
2165
|
-
return {target, fields, moment: moment ?? visibleMoment(), note, ...(frame && frame.length < 250000 ? {frame} : {}), ...(intent ? {intent} : {})};
|
|
2490
|
+
if (!text) throw Error('Write a visual review note first.');
|
|
2491
|
+
const scope = selectedScopeIds.size
|
|
2492
|
+
? [...selectedScopeIds]
|
|
2493
|
+
: [...$('review-field-options').querySelectorAll('input[data-review-scope]:checked')].map(input => input.value);
|
|
2494
|
+
if (!scope.length) throw Error('Pick a target (click the preview, use a quick preset, or choose from the menu) before sending.');
|
|
2495
|
+
const frame = attachedRefFrame?.data && attachedRefFrame.data.length < 250000 ? attachedRefFrame.data : before.capture();
|
|
2496
|
+
const activeScene = before.state()?.scene;
|
|
2497
|
+
const sceneId = metadata.scopes.some(item => item.collection === 'scenes' && item.id === activeScene) ? activeScene : undefined;
|
|
2498
|
+
return {
|
|
2499
|
+
noteId: crypto.randomUUID(), text, scope,
|
|
2500
|
+
allowCreates: $('review-allow-creates')?.checked === true,
|
|
2501
|
+
moment: moment ?? visibleMoment(),
|
|
2502
|
+
...(sceneId ? {sceneId} : {}),
|
|
2503
|
+
...(frame && frame.length < 250000 ? {frame} : {}),
|
|
2504
|
+
};
|
|
2166
2505
|
}
|
|
2167
2506
|
|
|
2168
2507
|
draftText.oninput = () => {
|
|
@@ -2171,69 +2510,219 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
2171
2510
|
drawQueued();
|
|
2172
2511
|
};
|
|
2173
2512
|
|
|
2174
|
-
function resolveRequest(requestId, answer) {
|
|
2175
|
-
if (resolvingId) return;
|
|
2176
|
-
resolvingId = requestId;
|
|
2177
|
-
drawRequests();
|
|
2178
|
-
void api('/review', answer ? {action: 'answer', requestId, answer} : {action: 'resolve', requestId}).then(() =>
|
|
2179
|
-
handle(async () => {
|
|
2180
|
-
resolvingId = undefined;
|
|
2181
|
-
await updateMetadata(true, true);
|
|
2182
|
-
}, false)(),
|
|
2183
|
-
error => handle(async () => {
|
|
2184
|
-
resolvingId = undefined;
|
|
2185
|
-
await updateMetadata();
|
|
2186
|
-
throw error;
|
|
2187
|
-
}, false)());
|
|
2188
|
-
}
|
|
2189
|
-
|
|
2190
2513
|
notePanel.onsubmit = handle(async () => {
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
$('review-win-cue-replacement')?.value);
|
|
2195
|
-
if (!queuedNotes.length && !draftText.value.trim() && !hasDirect) return;
|
|
2196
|
-
const expected = queuedExpected ?? draftExpected ?? metadata.expected;
|
|
2197
|
-
if (expected.revisionId !== metadata.expected.revisionId ||
|
|
2514
|
+
if (!queuedNotes.length && !draftText.value.trim()) return;
|
|
2515
|
+
const baseline = queuedExpected ?? draftExpected ?? metadata.expected;
|
|
2516
|
+
if (baseline.revisionId !== metadata.expected.revisionId ||
|
|
2198
2517
|
(draftExpected && draftExpected.revisionId !== metadata.expected.revisionId)) throw Error(errorLabels.E_REVIEW_STALE);
|
|
2199
|
-
const notes = draftText.value.trim()
|
|
2200
|
-
|
|
2201
|
-
const
|
|
2202
|
-
const
|
|
2203
|
-
|
|
2204
|
-
|
|
2518
|
+
const notes = draftText.value.trim() ? [...queuedNotes, readDraft()] : queuedNotes;
|
|
2519
|
+
const replaced = metadata.requests.find(request => request.id === editingRequestId && !request.readOnly && onCurrentVersion(request) && unresolved.includes(request.status));
|
|
2520
|
+
const input = {action: 'request', baseline, notes, ...(replaced ? {replacesRequestId: replaced.id} : {})};
|
|
2521
|
+
const fingerprint = JSON.stringify({
|
|
2522
|
+
...input,
|
|
2523
|
+
notes: notes.map(({noteId, ...rest}) => { void noteId; return rest; }),
|
|
2524
|
+
});
|
|
2205
2525
|
if (new Blob([JSON.stringify(input)]).size > 1048400) throw Error('These notes are too large together. Remove one and retry.');
|
|
2206
2526
|
if (pendingRequest?.fingerprint !== fingerprint) pendingRequest = {fingerprint, input, id: crypto.randomUUID()};
|
|
2207
|
-
$('review-submit').disabled = true;
|
|
2208
|
-
|
|
2209
|
-
|
|
2527
|
+
$('review-submit').disabled = true; $('review-submit').textContent = 'Saving…';
|
|
2528
|
+
try { await api('/review', {...pendingRequest.input, requestId: pendingRequest.id}); }
|
|
2529
|
+
finally { $('review-submit').textContent = 'Send ↑'; drawQueued(); }
|
|
2530
|
+
pendingRequest = undefined; draftText.value = ''; resizeDraft(); draftExpected = undefined;
|
|
2531
|
+
queuedNotes = []; queuedExpected = undefined; editingRequestId = undefined; attachedRefFrame = null;
|
|
2532
|
+
renderRefStrip(); toggleAttachment(false);
|
|
2533
|
+
await updateMetadata(true);
|
|
2534
|
+
feedbackStatus.textContent = 'Review request saved. Copy its handoff for your connected AI client.';
|
|
2535
|
+
});
|
|
2536
|
+
|
|
2537
|
+
function updateMatrixStart() {
|
|
2538
|
+
const variants = [...$('review-matrix-variants').querySelectorAll('input:checked')].length;
|
|
2539
|
+
const targets = [...$('review-matrix-targets').querySelectorAll('input:checked')].length;
|
|
2540
|
+
$('review-matrix-start').disabled = !variants || !targets;
|
|
2541
|
+
}
|
|
2542
|
+
|
|
2543
|
+
function renderMatrixChoices() {
|
|
2544
|
+
$('review-matrix-variants').replaceChildren(...metadata.variants.variants.map(variant => {
|
|
2545
|
+
const label = reviewElement('label');
|
|
2546
|
+
const input = reviewElement('input');
|
|
2547
|
+
input.type = 'checkbox';
|
|
2548
|
+
input.value = variant.id;
|
|
2549
|
+
input.checked = true;
|
|
2550
|
+
input.onchange = updateMatrixStart;
|
|
2551
|
+
label.append(input, reviewElement('span', variant.label));
|
|
2552
|
+
return label;
|
|
2553
|
+
}));
|
|
2554
|
+
$('review-matrix-targets').replaceChildren(...exportTargets.map(target => {
|
|
2555
|
+
const label = reviewElement('label');
|
|
2556
|
+
const input = reviewElement('input');
|
|
2557
|
+
input.type = 'checkbox';
|
|
2558
|
+
input.value = target.id;
|
|
2559
|
+
input.checked = target.id === selectedExportTarget().id;
|
|
2560
|
+
input.onchange = updateMatrixStart;
|
|
2561
|
+
label.append(input, reviewElement('span', target.label));
|
|
2562
|
+
return label;
|
|
2563
|
+
}));
|
|
2564
|
+
$('review-matrix-fit').textContent = $('review-auto-fit').checked ? 'Auto-shrink is on for every export in this matrix.' : 'Auto-shrink is off. Over-budget entries may fail independently.';
|
|
2565
|
+
$('review-matrix-error').textContent = '';
|
|
2566
|
+
updateMatrixStart();
|
|
2567
|
+
}
|
|
2568
|
+
|
|
2569
|
+
function drawMatrixJob() {
|
|
2570
|
+
const panel = $('review-matrix-job');
|
|
2571
|
+
if (!matrixJob) {
|
|
2572
|
+
panel.hidden = true;
|
|
2573
|
+
panel.replaceChildren();
|
|
2574
|
+
return;
|
|
2575
|
+
}
|
|
2576
|
+
panel.hidden = false;
|
|
2577
|
+
const failures = matrixJob.failures ?? [];
|
|
2578
|
+
const exports = matrixJob.exports ?? [];
|
|
2579
|
+
const terminal = new Set((matrixJob.progress ?? []).filter(item => ['passed', 'failed'].includes(item.status)).map(item => `${item.variantId}:${item.target}`));
|
|
2580
|
+
const heading = reviewElement('div', '', 'tora-matrix-heading');
|
|
2581
|
+
const status = matrixPollError ? 'Polling paused' : matrixJob.status === 'RUNNING' ? 'Running' : failures.length || matrixJob.status === 'FAILED' ? 'Needs attention' : 'Exported';
|
|
2582
|
+
heading.append(reviewElement('strong', 'Matrix export'), reviewElement('span', status, 'tora-status-badge'));
|
|
2583
|
+
const nodes = [heading];
|
|
2584
|
+
if (matrixRevisionId) nodes.push(reviewElement('p', `Snapshot saved (${matrixRevisionId.slice(0, 8)}…) · you can keep editing while exports finish.`, 'tora-export-hint'));
|
|
2585
|
+
if (matrixJob.status === 'RUNNING') {
|
|
2586
|
+
const progress = reviewElement('progress');
|
|
2587
|
+
progress.max = Math.max(1, matrixExpected);
|
|
2588
|
+
progress.value = Math.min(terminal.size, matrixExpected);
|
|
2589
|
+
progress.setAttribute('aria-label', `Matrix export progress: ${terminal.size} of ${matrixExpected} complete`);
|
|
2590
|
+
nodes.push(progress, reviewElement('p', `${terminal.size} of ${matrixExpected} combinations finished. You can keep working.`, 'tora-export-hint'));
|
|
2591
|
+
}
|
|
2592
|
+
if (failures.length) {
|
|
2593
|
+
const box = reviewElement('div', '', 'tora-matrix-failures');
|
|
2594
|
+
box.append(reviewElement('h3', `Failed combinations (${failures.length})`));
|
|
2595
|
+
const list = reviewElement('ul');
|
|
2596
|
+
for (const failure of failures) {
|
|
2597
|
+
const item = reviewElement('li');
|
|
2598
|
+
const variant = metadata.variants.variants.find(item => item.id === failure.variantId);
|
|
2599
|
+
const target = exportTargets.find(item => item.id === failure.target);
|
|
2600
|
+
const link = reviewElement('a', `${variant?.label ?? failure.variantId} · ${target?.label ?? failure.target}`);
|
|
2601
|
+
link.href = '#review-variant-' + failure.variantId;
|
|
2602
|
+
link.onclick = handle(async () => {
|
|
2603
|
+
$('review-export-menu').open = false;
|
|
2604
|
+
await selectVariant(failure.variantId);
|
|
2605
|
+
});
|
|
2606
|
+
item.append(link, reviewElement('p', errorLabels[failure.error] ?? failure.error ?? 'Export failed.'));
|
|
2607
|
+
const blockers = Array.isArray(failure.blockers) ? failure.blockers : [];
|
|
2608
|
+
if (blockers.length) {
|
|
2609
|
+
const reasons = reviewElement('ul');
|
|
2610
|
+
for (const blocker of blockers) reasons.append(reviewElement('li', blocker.message ?? blocker.detail ?? blocker.defectKind ?? blocker.code ?? 'Export check failed.'));
|
|
2611
|
+
item.append(reasons);
|
|
2612
|
+
}
|
|
2613
|
+
list.append(item);
|
|
2614
|
+
}
|
|
2615
|
+
box.append(list);
|
|
2616
|
+
nodes.push(box);
|
|
2617
|
+
}
|
|
2618
|
+
if (matrixJob.error) nodes.push(reviewElement('p', errorLabels[matrixJob.error] ?? matrixJob.error, 'review-error'));
|
|
2619
|
+
if (matrixPollError) {
|
|
2620
|
+
nodes.push(reviewElement('p', matrixPollError, 'review-error'));
|
|
2621
|
+
const retry = reviewElement('button', 'Retry status');
|
|
2622
|
+
retry.type = 'button';
|
|
2623
|
+
retry.onclick = () => {
|
|
2624
|
+
matrixPollError = undefined;
|
|
2625
|
+
drawMatrixJob();
|
|
2626
|
+
void pollMatrixJob(matrixJob.jobId, matrixPollVersion);
|
|
2627
|
+
};
|
|
2628
|
+
nodes.push(retry);
|
|
2629
|
+
}
|
|
2630
|
+
if (exports.length) {
|
|
2631
|
+
const details = reviewElement('details', '', 'tora-matrix-successes');
|
|
2632
|
+
details.append(reviewElement('summary', `${exports.length} successful export${exports.length === 1 ? '' : 's'}`));
|
|
2633
|
+
const list = reviewElement('ul');
|
|
2634
|
+
for (const item of exports) {
|
|
2635
|
+
const variant = metadata.variants.variants.find(variant => variant.id === item.variantId);
|
|
2636
|
+
const target = exportTargets.find(target => target.id === item.target);
|
|
2637
|
+
const row = reviewElement('li', `${variant?.label ?? item.variantId} · ${target?.label ?? item.target}`);
|
|
2638
|
+
if (item.output) row.append(reviewElement('code', item.output));
|
|
2639
|
+
list.append(row);
|
|
2640
|
+
}
|
|
2641
|
+
details.append(list);
|
|
2642
|
+
nodes.push(details);
|
|
2643
|
+
}
|
|
2644
|
+
if (matrixJob.outputDir) nodes.push(reviewElement('p', 'Output: ' + matrixJob.outputDir + ' · matrix-summary.json', 'tora-export-hint'));
|
|
2645
|
+
if (matrixJob.status !== 'RUNNING') nodes.push(reviewElement('p', 'Static and mock-host checks are not official network acceptance. Verify successful artifacts in official preview tools and on physical devices.', 'tora-export-hint'));
|
|
2646
|
+
panel.replaceChildren(...nodes);
|
|
2647
|
+
}
|
|
2648
|
+
|
|
2649
|
+
async function pollMatrixJob(jobId, version) {
|
|
2210
2650
|
try {
|
|
2211
|
-
result = await api('/
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2651
|
+
const result = await api('/export-matrix/' + encodeURIComponent(jobId));
|
|
2652
|
+
if (version !== matrixPollVersion || matrixJob?.jobId !== jobId) return;
|
|
2653
|
+
matrixJob = result;
|
|
2654
|
+
matrixPollError = undefined;
|
|
2655
|
+
drawMatrixJob();
|
|
2656
|
+
if (result.status === 'RUNNING') matrixPollTimer = setTimeout(() => { void pollMatrixJob(jobId, version); }, 900);
|
|
2657
|
+
} catch (error) {
|
|
2658
|
+
if (version !== matrixPollVersion || matrixJob?.jobId !== jobId) return;
|
|
2659
|
+
matrixPollError = errorLabels[error.message] ?? error.message;
|
|
2660
|
+
drawMatrixJob();
|
|
2215
2661
|
}
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
$('review-export-matrix').onclick = handle(() => {
|
|
2665
|
+
if (candidateId) throw Error('Choose Use this version or Discard before exporting a variant matrix.');
|
|
2666
|
+
if (!metadata.variants.variants.length) throw Error('Create a variant before exporting a matrix.');
|
|
2667
|
+
renderMatrixChoices();
|
|
2668
|
+
$('review-matrix-dialog').showModal();
|
|
2669
|
+
});
|
|
2670
|
+
$('review-matrix-close').onclick = () => $('review-matrix-dialog').close();
|
|
2671
|
+
$('review-matrix-dialog').addEventListener('click', event => {
|
|
2672
|
+
if (event.target === $('review-matrix-dialog')) $('review-matrix-dialog').close();
|
|
2673
|
+
});
|
|
2674
|
+
$('review-matrix-form').onsubmit = handle(async () => {
|
|
2675
|
+
const variants = [...$('review-matrix-variants').querySelectorAll('input:checked')].map(input => input.value);
|
|
2676
|
+
const targets = [...$('review-matrix-targets').querySelectorAll('input:checked')].map(input => input.value);
|
|
2677
|
+
if (!variants.length || !targets.length) return;
|
|
2678
|
+
const submit = $('review-matrix-start');
|
|
2679
|
+
submit.disabled = true;
|
|
2680
|
+
$('review-matrix-error').textContent = '';
|
|
2681
|
+
try {
|
|
2682
|
+
const revisionId = metadata.expected.revisionId;
|
|
2683
|
+
const started = await api('/export-matrix', {
|
|
2684
|
+
revisionId,
|
|
2685
|
+
variants,
|
|
2686
|
+
targets,
|
|
2687
|
+
fitTargetBudget: $('review-auto-fit').checked,
|
|
2688
|
+
});
|
|
2689
|
+
clearTimeout(matrixPollTimer);
|
|
2690
|
+
const version = ++matrixPollVersion;
|
|
2691
|
+
matrixJob = {jobId: started.jobId, status: 'RUNNING', progress: []};
|
|
2692
|
+
matrixExpected = variants.length * targets.length;
|
|
2693
|
+
matrixRevisionId = revisionId;
|
|
2694
|
+
matrixPollError = undefined;
|
|
2695
|
+
$('review-matrix-dialog').close();
|
|
2696
|
+
drawMatrixJob();
|
|
2697
|
+
void pollMatrixJob(started.jobId, version);
|
|
2698
|
+
} catch (error) {
|
|
2699
|
+
$('review-matrix-error').textContent = errorLabels[error.message] ?? error.message;
|
|
2700
|
+
} finally {
|
|
2701
|
+
submit.disabled = false;
|
|
2230
2702
|
}
|
|
2231
2703
|
});
|
|
2232
2704
|
|
|
2233
2705
|
async function syncOptionalStoreUrl() {
|
|
2234
2706
|
const entered = $('review-store-url').value.trim();
|
|
2235
|
-
|
|
2236
|
-
|
|
2707
|
+
const variant = activeVariant();
|
|
2708
|
+
const currentUrl = variant?.storeUrl ?? metadata.storeUrl ?? '';
|
|
2709
|
+
if (entered === currentUrl || (!entered && selectedExportTarget().requiresStoreUrl)) return;
|
|
2710
|
+
if (variant) {
|
|
2711
|
+
const nextVariant = globalThis.structuredClone(variant);
|
|
2712
|
+
if (entered) nextVariant.storeUrl = entered;
|
|
2713
|
+
else delete nextVariant.storeUrl;
|
|
2714
|
+
await api('/variants', {
|
|
2715
|
+
action: 'upsert',
|
|
2716
|
+
variant: nextVariant,
|
|
2717
|
+
expectedVariantRevision: metadata.variants?.revision,
|
|
2718
|
+
});
|
|
2719
|
+
} else if (isHosted) {
|
|
2720
|
+
await api('/quick-edit', {expected: metadata.expected, edits: [{kind: 'storeUrl', url: entered}]});
|
|
2721
|
+
} else {
|
|
2722
|
+
const envelope = {format: 'tora-transaction-1', expected: metadata.expected, operations: [{kind: 'setStore', url: entered}]};
|
|
2723
|
+
const preview = await api('/transactions/preview', envelope);
|
|
2724
|
+
await api('/transactions', {...envelope, previewDigest: preview.previewDigest});
|
|
2725
|
+
}
|
|
2237
2726
|
metadata = await api('/review');
|
|
2238
2727
|
if (candidateId) await closeCandidate();
|
|
2239
2728
|
}
|
|
@@ -2245,38 +2734,170 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
2245
2734
|
feedbackStatus.textContent = 'Store destination saved.';
|
|
2246
2735
|
await updateMetadata(false);
|
|
2247
2736
|
});
|
|
2737
|
+
$('review-import-btn').onclick = () => $('review-import-picker').click();
|
|
2738
|
+
$('review-import-picker').onchange = handle(async event => {
|
|
2739
|
+
const file = event.target.files?.[0];
|
|
2740
|
+
event.target.value = '';
|
|
2741
|
+
if (!file) return;
|
|
2742
|
+
if (file.size > 64 * 1024 * 1024) throw Error('E_BUNDLE_SIZE');
|
|
2743
|
+
feedbackStatus.textContent = `Importing ${file.name}…`;
|
|
2744
|
+
const bundleText = await file.text();
|
|
2745
|
+
const imported = await reviewRequest('/api/projects/import', {bundleText, copy: true});
|
|
2746
|
+
window.location.href = imported.editorUrl ?? ('?project=' + encodeURIComponent(imported.projectId));
|
|
2747
|
+
});
|
|
2748
|
+
|
|
2749
|
+
$('review-qa-run').onclick = handle(async () => {
|
|
2750
|
+
if (isHosted) {
|
|
2751
|
+
$('review-qa-error').textContent = 'Full 4-screen Playwright QA runs inside local Tora Studio. Run `npx @tora-editor/tora editor` locally to run QA and package ad-network builds.';
|
|
2752
|
+
return;
|
|
2753
|
+
}
|
|
2754
|
+
const btn = $('review-qa-run');
|
|
2755
|
+
const results = $('review-qa-results');
|
|
2756
|
+
$('review-qa-error').textContent = '';
|
|
2757
|
+
btn.disabled = true;
|
|
2758
|
+
btn.textContent = 'Checking 4 screens & audio…';
|
|
2759
|
+
try {
|
|
2760
|
+
const target = selectedExportTarget();
|
|
2761
|
+
const variant = activeVariant();
|
|
2762
|
+
const activeStoreUrl = variant?.storeUrl ?? metadata.storeUrl ?? '';
|
|
2763
|
+
const hasRealStoreUrl = Boolean(activeStoreUrl) && activeStoreUrl !== 'https://play.google.com/store/apps/details?id=com.playablelab.draft' && !/id=com\.(?:example|yourcompany|yourapp|demo|test)\./i.test(activeStoreUrl);
|
|
2764
|
+
const needsStoreFirst = Boolean(target?.requiresStoreUrl && !hasRealStoreUrl);
|
|
2765
|
+
const qaTarget = needsStoreFirst ? 'standalone-browser-draft' : (target?.id ?? 'standalone-browser-draft');
|
|
2766
|
+
const report = await api('/qa', {
|
|
2767
|
+
revisionId: metadata.expected.revisionId,
|
|
2768
|
+
target: qaTarget,
|
|
2769
|
+
fitTargetBudget: $('review-auto-fit').checked,
|
|
2770
|
+
...(variant ? {variantId: variant.id} : {}),
|
|
2771
|
+
});
|
|
2772
|
+
qaResultKey = currentQaKey();
|
|
2773
|
+
$('review-qa-summary').textContent = report.ok ? 'QA · Passed ✓' : `QA · ${report.blockers.length} to fix`;
|
|
2774
|
+
$('review-qa-menu').dataset.status = report.ok ? 'ok' : 'fail';
|
|
2775
|
+
results.hidden = false;
|
|
2776
|
+
const nodes = [];
|
|
2777
|
+
const badge = reviewElement('div', '', 'tora-qa-summary-row');
|
|
2778
|
+
badge.append(
|
|
2779
|
+
reviewElement('span', report.ok ? (needsStoreFirst ? '✓ Draft ready for review' : '✓ Ready for review') : `⚠ ${report.blockers.length} blocker${report.blockers.length === 1 ? '' : 's'} found`, report.ok ? 'tora-pill tora-pill-mint' : 'tora-status-badge'),
|
|
2780
|
+
reviewElement('span', `${formatBytes(report.bytes)} · ${report.warnings.length} warning${report.warnings.length === 1 ? '' : 's'}`, 'tora-export-hint'),
|
|
2781
|
+
);
|
|
2782
|
+
nodes.push(badge);
|
|
2783
|
+
const list = reviewElement('ul', '', 'tora-qa-checklist');
|
|
2784
|
+
const addCheck = (ok, text) => {
|
|
2785
|
+
const li = reviewElement('li', (ok ? '✓ ' : '✗ ') + text);
|
|
2786
|
+
li.dataset.ok = String(ok);
|
|
2787
|
+
list.append(li);
|
|
2788
|
+
};
|
|
2789
|
+
addCheck(report.blockers.length === 0, report.blockers.length === 0 ? '4-viewport layout & audio checks passed' : `${report.blockers.length} blocker(s) need attention`);
|
|
2790
|
+
const ctaEntries = Object.values(report.storeCta ?? {});
|
|
2791
|
+
if (ctaEntries.length) {
|
|
2792
|
+
const ctaOk = ctaEntries.every(entry => entry?.ok === true);
|
|
2793
|
+
addCheck(ctaOk, ctaOk ? 'Store install button responds on click' : 'Store install button did not respond on click');
|
|
2794
|
+
}
|
|
2795
|
+
if (needsStoreFirst && target) {
|
|
2796
|
+
const reminder = reviewElement('li', `⚠ Checked as Browser Draft — add your App Store / Google Play link in Export before shipping to ${target.label}.`);
|
|
2797
|
+
reminder.dataset.ok = 'warn';
|
|
2798
|
+
list.append(reminder);
|
|
2799
|
+
}
|
|
2800
|
+
const fitsAll = report.bytes <= 2_000_000;
|
|
2801
|
+
const fitsFiveMb = report.bytes < 5_000_000;
|
|
2802
|
+
const sizePrefix = needsStoreFirst ? 'Browser draft size' : 'Packaged size';
|
|
2803
|
+
addCheck(fitsFiveMb, fitsAll ? `${sizePrefix} fits all 7 ad-network limits (≤ 2 MB)` : fitsFiveMb ? `${sizePrefix} fits 5 MB networks (turn on Auto-shrink in Budget for Meta ≤ 2 MB)` : `${sizePrefix} exceeds 5 MB limit — turn on Auto-shrink in Budget`);
|
|
2804
|
+
nodes.push(list);
|
|
2805
|
+
if (report.blockers.length) {
|
|
2806
|
+
const box = reviewElement('div', '', 'tora-matrix-failures');
|
|
2807
|
+
box.append(reviewElement('h3', 'Items to fix'));
|
|
2808
|
+
const ul = reviewElement('ul');
|
|
2809
|
+
for (const blocker of report.blockers.slice(0, 6)) {
|
|
2810
|
+
ul.append(reviewElement('li', blocker.message ?? blocker.detail ?? blocker.defectKind ?? 'Check failed'));
|
|
2811
|
+
}
|
|
2812
|
+
box.append(ul);
|
|
2813
|
+
nodes.push(box);
|
|
2814
|
+
}
|
|
2815
|
+
if (report.contactSheetUrl) {
|
|
2816
|
+
const link = reviewElement('a', '', 'tora-qa-sheet-link');
|
|
2817
|
+
link.href = report.contactSheetUrl;
|
|
2818
|
+
link.target = '_blank';
|
|
2819
|
+
link.rel = 'noopener noreferrer';
|
|
2820
|
+
const img = reviewElement('img', '', 'tora-qa-sheet-img');
|
|
2821
|
+
img.src = report.contactSheetUrl;
|
|
2822
|
+
img.alt = '4-viewport Creative QA contact sheet';
|
|
2823
|
+
link.append(img, reviewElement('span', 'Open full 4-screen contact sheet ↗'));
|
|
2824
|
+
nodes.push(link);
|
|
2825
|
+
}
|
|
2826
|
+
results.replaceChildren(...nodes);
|
|
2827
|
+
} catch (error) {
|
|
2828
|
+
$('review-qa-error').textContent = errorLabels[error.message] ?? error.message;
|
|
2829
|
+
} finally {
|
|
2830
|
+
btn.disabled = false;
|
|
2831
|
+
btn.textContent = 'Run 4-Screen QA Check';
|
|
2832
|
+
}
|
|
2833
|
+
});
|
|
2834
|
+
|
|
2248
2835
|
$('review-undo').onclick = handle(async () => {
|
|
2249
2836
|
await api('/history', {expected: metadata.expected, action: 'undo'});
|
|
2250
2837
|
metadata = await api('/review');
|
|
2251
2838
|
if (candidateId) await closeCandidate();
|
|
2252
2839
|
await updateMetadata(false);
|
|
2253
2840
|
});
|
|
2841
|
+
$('review-redo').onclick = handle(async () => {
|
|
2842
|
+
await api('/history', {expected: metadata.expected, action: 'redo'});
|
|
2843
|
+
metadata = await api('/review');
|
|
2844
|
+
if (candidateId) await closeCandidate();
|
|
2845
|
+
await updateMetadata(false);
|
|
2846
|
+
});
|
|
2847
|
+
document.addEventListener('keydown', event => {
|
|
2848
|
+
if (!(event.metaKey || event.ctrlKey) || event.altKey) return;
|
|
2849
|
+
const tag = document.activeElement?.tagName;
|
|
2850
|
+
if (['INPUT', 'TEXTAREA', 'SELECT'].includes(tag)) return;
|
|
2851
|
+
if (event.key.toLowerCase() === 'z' && !event.shiftKey && metadata.canUndo && !busy) {
|
|
2852
|
+
event.preventDefault();
|
|
2853
|
+
$('review-undo').click();
|
|
2854
|
+
} else if (((event.key.toLowerCase() === 'z' && event.shiftKey) || event.key.toLowerCase() === 'y') && metadata.canRedo && !busy) {
|
|
2855
|
+
event.preventDefault();
|
|
2856
|
+
$('review-redo').click();
|
|
2857
|
+
}
|
|
2858
|
+
});
|
|
2254
2859
|
$('review-export').onclick = handle(async () => {
|
|
2255
2860
|
if (candidateId) throw Error('Choose Use this version or Discard before exporting.');
|
|
2256
2861
|
const target = selectedExportTarget();
|
|
2862
|
+
const variant = activeVariant();
|
|
2257
2863
|
await syncOptionalStoreUrl();
|
|
2258
|
-
|
|
2864
|
+
const storeUrl = variant?.storeUrl ?? metadata.storeUrl;
|
|
2865
|
+
if (target.requiresStoreUrl && (!storeUrl || /id=com\.(?:example|yourcompany|yourapp|demo|test)\./i.test(storeUrl))) {
|
|
2259
2866
|
$('review-store-url').focus();
|
|
2260
|
-
throw Error(
|
|
2867
|
+
throw Error(storeUrl ? 'E_ARTIFACT_PLACEHOLDER' : 'E_NATIVE_STORE');
|
|
2261
2868
|
}
|
|
2262
2869
|
const {revisionId, contentHash} = metadata.expected;
|
|
2263
|
-
const artifact = await api('/export', {
|
|
2870
|
+
const artifact = await api('/export', {
|
|
2871
|
+
revisionId,
|
|
2872
|
+
target: target.id,
|
|
2873
|
+
fitTargetBudget: $('review-auto-fit').checked,
|
|
2874
|
+
...(variant ? {variantId: variant.id} : {}),
|
|
2875
|
+
});
|
|
2264
2876
|
if (!metadata.accepted) await api('/accept', {revisionId, contentHash});
|
|
2877
|
+
const variantSuffix = variant ? '-' + variant.id : '';
|
|
2265
2878
|
if (artifact.archiveBase64) {
|
|
2266
2879
|
const bytes = Uint8Array.from(atob(artifact.archiveBase64), character => character.charCodeAt(0));
|
|
2267
|
-
download(artifact.archiveFilename ?? projectId + '-' + target.filenameSuffix + '.zip', bytes, 'application/zip');
|
|
2268
|
-
} else download(
|
|
2269
|
-
const draftHint =
|
|
2270
|
-
feedbackStatus.textContent = `Approved revision downloaded for ${target.label}. Static and mock-host checks passed; official preview and device verification are still required.${draftHint}`;
|
|
2880
|
+
download(artifact.archiveFilename ?? projectId + variantSuffix + '-' + target.filenameSuffix + '.zip', bytes, 'application/zip');
|
|
2881
|
+
} else download(target.id === 'standalone-browser-draft' ? projectId + variantSuffix + '-draft.html' : 'index.html', artifact.html, 'text/html');
|
|
2882
|
+
const draftHint = storeUrl === 'https://play.google.com/store/apps/details?id=com.playablelab.draft' ? ' Replace the draft Store URL before uploading to a live campaign.' : '';
|
|
2883
|
+
feedbackStatus.textContent = `Approved ${variant?.label ?? 'Base'} revision downloaded for ${target.label}. Static and mock-host checks passed; official preview and device verification are still required.${draftHint}`;
|
|
2271
2884
|
await updateMetadata();
|
|
2885
|
+
await refreshBudget(true);
|
|
2272
2886
|
});
|
|
2273
2887
|
$('review-export-draft').onclick = handle(async () => {
|
|
2274
2888
|
if (candidateId) throw Error('Choose Use this version or Discard before exporting.');
|
|
2275
2889
|
await syncOptionalStoreUrl();
|
|
2276
2890
|
const {revisionId} = metadata.expected;
|
|
2277
|
-
const
|
|
2278
|
-
|
|
2279
|
-
|
|
2891
|
+
const variant = activeVariant();
|
|
2892
|
+
const {html} = await api('/export', {
|
|
2893
|
+
revisionId,
|
|
2894
|
+
target: 'standalone-browser-draft',
|
|
2895
|
+
fitTargetBudget: $('review-auto-fit').checked,
|
|
2896
|
+
...(variant ? {variantId: variant.id} : {}),
|
|
2897
|
+
});
|
|
2898
|
+
download(projectId + (variant ? '-' + variant.id : '') + '-draft.html', html, 'text/html');
|
|
2899
|
+
feedbackStatus.textContent = `Standalone ${variant?.label ?? 'Base'} browser draft downloaded.`;
|
|
2900
|
+
await refreshBudget(true);
|
|
2280
2901
|
});
|
|
2281
2902
|
$('review-bundle').onclick = handle(async () => {
|
|
2282
2903
|
const bundle = await api('/review?bundle=1');
|
|
@@ -2287,12 +2908,23 @@ export async function openReview(projectId, initialMetadata) {
|
|
|
2287
2908
|
const refresh = handle(() => updateMetadata(true, true), false);
|
|
2288
2909
|
try {
|
|
2289
2910
|
await loadRuntime();
|
|
2290
|
-
await connectionCtrl.refresh();
|
|
2291
2911
|
await mountCurrent();
|
|
2292
|
-
initialized = true;
|
|
2293
2912
|
await updateMetadata(false, true);
|
|
2294
|
-
for (const name of ['review-before-toggle', 'review-before-restart', 'review-after-toggle', 'review-after-restart', 'review-orientation', 'review-export', 'review-export-draft', 'review-bundle']) $(name).disabled = false;
|
|
2913
|
+
for (const name of ['review-before-toggle', 'review-before-restart', 'review-after-toggle', 'review-after-restart', 'review-orientation', 'review-device', 'review-export', 'review-export-draft', 'review-bundle']) $(name).disabled = false;
|
|
2295
2914
|
for (const button of $('review-moments').children) button.disabled = false;
|
|
2915
|
+
if (isHosted) {
|
|
2916
|
+
$('tora-sandbox-banner').hidden = false;
|
|
2917
|
+
$('review-qa-menu').hidden = true;
|
|
2918
|
+
$('review-tab-chat').hidden = true;
|
|
2919
|
+
$('review-chat-pane').hidden = true;
|
|
2920
|
+
$('review-note-toggle').hidden = true;
|
|
2921
|
+
$('review-note').hidden = true;
|
|
2922
|
+
$('review-export-matrix').hidden = true;
|
|
2923
|
+
winSoundPanel.hidden = true;
|
|
2924
|
+
setSideTab('quick');
|
|
2925
|
+
} else if (new URLSearchParams(window.location.search).get('tab') === 'quick-edit') {
|
|
2926
|
+
setSideTab('quick');
|
|
2927
|
+
}
|
|
2296
2928
|
setInterval(() => { if (!document.hidden && !busy) void refresh(); }, 1800);
|
|
2297
2929
|
} catch (error) {
|
|
2298
2930
|
showError(error);
|