{"manifest":{"schemaVersion":1,"sdkVersion":"0.1.0","id":"sm.blueprint","version":"2.1.7","name":"Blueprint","description":"Edit, structure, lock, and review assisted changes to the complete production Blueprint before exact save and downstream handoff with bounded saved revision and collaborator context with exact project media-library browsing and trusted previews.","kind":"workspace","runtime":"javascript","entry":"src/run.js","license":"MIT","provenance":{"notice":"MIT License\n\nCopyright (c) 2026 StillMade contributors\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"},"inputs":{"blueprint":{"type":"bible","context":"blueprint","primary":true,"required":false,"default":{"schemaVersion":1},"description":"The complete current project blueprint. Unknown and future fields are retained unchanged."},"updatedBlueprint":{"type":"bible","required":false,"default":{"schemaVersion":1},"description":"The complete edited blueprint prepared by this Block's workspace."},"commit":{"type":"boolean","default":false,"description":"Prepare the edited document for StillMade review and Apply."},"assistantEdit":{"type":"workspace-edit","required":false,"description":"An exact Blueprint proposal from a connected workspace.propose assistant Block. It remains reviewable before local adoption and final Apply."},"versions":{"type":"metadata[]","context":"versions","required":false,"description":"Host-backed saved revision records for this exact project workspace."},"presence":{"type":"metadata[]","required":false,"description":"Bounded collaborator presence supplied through a declared connection or host project context."},"assets":{"type":"asset[]","context":"assets","required":false,"description":"Exact stored project media versions available for bounded browsing and local attachment."}},"outputs":{"blueprint":{"type":"bible","primary":true,"role":"production_blueprint","description":"The complete edited blueprint for the next Step."},"edit":{"type":"workspace-edit","description":"An exact before/after Blueprint change reviewed before it updates the project."},"shotPlan":{"type":"shot-plan","role":"shot_plan_handoff","description":"A deterministic Shots document derived from the edited Blueprint scenes and shot lists for a downstream Shots or Animated Scene Step."},"revision":{"type":"metadata","description":"A deterministic revision event for durable host storage and collaboration propagation.","required":false}},"permissions":{"project":["context.blueprint.read","workspace.blueprint.propose","context.versions.read","context.assets.read"],"network":[],"filesystem":[],"secrets":[]},"ui":[],"platforms":{"phone":{"supported":true},"browser":{"supported":true},"desktop":{"supported":true}}},"code":"const copy = value => JSON.parse(JSON.stringify(value));\nconst source = copy(input.blueprint || {schemaVersion: 1});\nconst candidate = input.commit ? copy(input.updatedBlueprint) : copy(source);\nif (!candidate || Array.isArray(candidate) || candidate.schemaVersion !== 1) {\n  throw new Error('Keep the complete version 1 Blueprint document.');\n}\nconst title = typeof candidate.title === 'string' && candidate.title.trim()\n  ? `Update Blueprint: ${candidate.title.trim().slice(0, 160)}`\n  : 'Update production Blueprint';\nconst seconds = value => {\n  const number = Number(value);\n  if (Number.isFinite(number) && number > 0) return number;\n  const match = String(value || '').match(/\\d+(?:\\.\\d+)?/);\n  return match ? Math.max(.001, Number(match[0])) : 4;\n};\nlet cursor = 0;\nconst shots = [];\nfor (const [sceneIndex, scene] of (Array.isArray(candidate.scenes) ? candidate.scenes : []).entries()) {\n  const narration = (Array.isArray(candidate.voiceover) ? candidate.voiceover : []).find(line => line?.sceneId && line.sceneId === scene?.id)?.text || '';\n  for (const [shotIndex, sourceShot] of (Array.isArray(scene?.shotList) ? scene.shotList : []).entries()) {\n    const shot = copy(sourceShot || {});\n    const start = Number.isFinite(Number(shot.startTime)) ? Number(shot.startTime) : cursor;\n    const duration = Number.isFinite(Number(shot.endTime)) && Number(shot.endTime) > start\n      ? Number(shot.endTime) - start\n      : seconds(shot.intendedDuration || shot.generationLength);\n    const end = start + duration;\n    shots.push({...shot,id:String(shot.id || `scene-${sceneIndex + 1}-shot-${shotIndex + 1}`),sceneId:String(scene?.id || scene?.sceneId || `scene-${sceneIndex + 1}`),sceneTitle:String(scene?.title || ''),startTime:start,endTime:end,voiceoverText:String(shot.voiceoverText || narration)});\n    cursor = Math.max(cursor, end);\n  }\n}\nconst outputs = {\n  blueprint: candidate,\n  shotPlan: {schemaVersion: 1, shots},\n  edit: {schemaVersion: 1, title, field: 'blueprint', before: source, after: candidate}\n};\nif(Array.isArray(input.versions)||Array.isArray(input.presence))outputs.revision={schemaVersion:1,scope:'blueprint',baseRevision:(Array.isArray(input.versions)?input.versions:[]).slice(0,200).reduce((highest,item)=>Math.max(highest,Number(item&&item.revision)||0),0),committed:!!input.commit,changed:JSON.stringify(source)!==JSON.stringify(candidate),paths:JSON.stringify(source)===JSON.stringify(candidate)?[]:['blueprint']};\nreturn outputs;\n","view":{"html":"<main class=\"blueprint-workspace\">\n  <header>\n    <div><small>Production workspace</small><h1>Blueprint</h1></div>\n    <div class=\"actions\"><button id=\"undo\" type=\"button\" class=\"secondary\">Undo</button><button id=\"redo\" type=\"button\" class=\"secondary\">Redo</button><button id=\"tidy\" type=\"button\" class=\"secondary\">Tidy structure</button><button id=\"lock\" type=\"button\" class=\"secondary\">Lock editing</button><button id=\"reset\" type=\"button\" class=\"secondary\">Reset changes</button><button id=\"save\" type=\"button\" data-stillmade-action=\"run\">Review changes</button></div>\n  </header>\n  <output id=\"status\" role=\"status\" aria-live=\"polite\">Loading the project Blueprint…</output>\n  <section><h2>Saved revisions and collaborators</h2><div id=\"workspaceSync\"></div></section>\n  <section><h2>Project media library</h2><p>Browse exact stored image versions supplied by the host.</p><div id=\"mediaLibrary\"></div><img id=\"libraryPreview\" alt=\"Trusted project media preview\" hidden></section>\n  <section><div class=\"section-title\"><h2>Assistant proposal</h2><button id=\"applyAssistant\" type=\"button\" class=\"secondary\">Apply proposal locally</button></div><div id=\"assistantProposal\"></div></section>\n  <section class=\"handoff\"><h2>Shots handoff</h2><p id=\"handoffSummary\">Scene shot lists become a typed Shots document for the next Step.</p><button id=\"prepareShots\" type=\"button\" class=\"secondary\">Prepare Shots handoff</button></section>\n\n  <section>\n    <h2>Project overview</h2>\n    <div class=\"grid two\">\n      <label>Title<input id=\"title\" type=\"text\"></label>\n      <label>Video type<input id=\"videoType\" type=\"text\"></label>\n      <label>Target length<input id=\"targetLength\" type=\"text\"></label>\n      <label>Tone<input id=\"tone\" type=\"text\"></label>\n      <label>Aspect ratio<input id=\"aspectRatio\" type=\"text\"></label>\n    </div>\n    <label>Description<textarea id=\"description\"></textarea></label>\n    <label>Extra information<textarea id=\"extraInfo\"></textarea></label>\n  </section>\n\n  <section>\n    <h2>Emotional arc</h2>\n    <div class=\"grid two\">\n      <label>Beginning<textarea id=\"arcBeginning\"></textarea></label>\n      <label>Escalation<textarea id=\"arcEscalation\"></textarea></label>\n      <label>Climax<textarea id=\"arcClimax\"></textarea></label>\n      <label>Resolution<textarea id=\"arcResolution\"></textarea></label>\n    </div>\n  </section>\n\n  <section>\n    <h2>Visual style guide</h2>\n    <div class=\"grid two\">\n      <label>Color palette<textarea id=\"styleColor\"></textarea></label>\n      <label>Lighting tone<textarea id=\"styleLighting\"></textarea></label>\n      <label>Camera language<textarea id=\"styleCamera\"></textarea></label>\n      <label>Overall aesthetic<textarea id=\"styleAesthetic\"></textarea></label>\n    </div>\n  </section>\n\n  <section><div class=\"section-title\"><h2>Voiceover</h2><button id=\"addVoiceover\" type=\"button\" class=\"secondary\">Add narration</button></div><div id=\"voiceover\" class=\"cards\"></div></section>\n  <section><div class=\"section-title\"><h2>Characters</h2><button id=\"addCharacter\" type=\"button\" class=\"secondary\">Add character</button></div><div id=\"characters\" class=\"cards\"></div></section>\n  <section><div class=\"section-title\"><h2>Locations</h2><button id=\"addLocation\" type=\"button\" class=\"secondary\">Add location</button></div><div id=\"locations\" class=\"cards\"></div></section>\n  <section><div class=\"section-title\"><h2>Scenes and shots</h2><button id=\"addScene\" type=\"button\" class=\"secondary\">Add scene</button></div><div id=\"scenes\" class=\"cards\"></div></section>\n\n  <details id=\"advanced\"><summary>Complete Blueprint data</summary><p>All fields are retained. Edit this JSON for fields a custom Blueprint adds beyond the standard workspace.</p><label for=\"raw\">Complete Blueprint JSON</label><textarea id=\"raw\" class=\"raw\" spellcheck=\"false\"></textarea><button id=\"applyRaw\" type=\"button\" class=\"secondary\">Apply JSON to workspace</button></details>\n</main>\n","css":".blueprint-workspace{max-width:1100px;margin:0 auto;padding:8px;color:var(--fg)}\nheader,.section-title,.actions{display:flex;align-items:center;gap:10px;flex-wrap:wrap}header{justify-content:space-between;margin-bottom:14px}header h1{margin:2px 0}header small,output,p{color:var(--fg-muted)}\nsection,details{margin:14px 0;padding:16px;border:1px solid var(--border-tok);border-radius:var(--r-3);background:var(--bg-elev-1)}\nh2{margin:0 0 12px;font-size:22px}.section-title{justify-content:space-between}.section-title h2{margin:0}\n.grid{display:grid;gap:12px}.grid.two{grid-template-columns:repeat(2,minmax(0,1fr))}label{display:grid;gap:6px;margin:10px 0;font-size:13px;font-weight:600}textarea{min-height:88px;resize:vertical}input,textarea{width:100%;background:var(--bg)}\n.cards{display:grid;gap:12px}.card{padding:14px;border:1px solid var(--border-tok);border-radius:var(--r-3);background:var(--bg)}.card-head{display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap}.card h3{margin:0;font-size:16px}.secondary{background:transparent;color:var(--fg)}.danger{background:transparent;color:var(--signal)}\n.shot-list{display:grid;gap:10px;margin-top:12px}.shot{padding:12px;border-left:3px solid var(--border-strong);background:var(--bg-elev-1)}.shot .grid{margin-top:4px}button,input,textarea,summary{min-height:44px}button{cursor:pointer}button:disabled{cursor:not-allowed;opacity:.55}\n.raw{min-height:320px;font-family:var(--font-mono);font-size:12px}summary{font-weight:700}output{display:block;min-height:24px;margin:8px 2px}\n@media(max-width:680px){.blueprint-workspace{padding:0}.grid.two{grid-template-columns:1fr}section,details{padding:12px}.actions{width:100%}.actions button{flex:1}}\n","javascript":"const fields = {\n  title: document.getElementById('title'), description: document.getElementById('description'), videoType: document.getElementById('videoType'),\n  targetLength: document.getElementById('targetLength'), tone: document.getElementById('tone'), aspectRatio: document.getElementById('aspectRatio'), extraInfo: document.getElementById('extraInfo')\n};\nconst arc = {beginning:document.getElementById('arcBeginning'),escalation:document.getElementById('arcEscalation'),climax:document.getElementById('arcClimax'),resolution:document.getElementById('arcResolution')};\nconst visual = {colorPalette:document.getElementById('styleColor'),lightingTone:document.getElementById('styleLighting'),cameraLanguage:document.getElementById('styleCamera'),overallAesthetic:document.getElementById('styleAesthetic')};\nconst status = document.getElementById('status'), raw = document.getElementById('raw'), save = document.getElementById('save');\nlet source = {schemaVersion:1}, draft = {schemaVersion:1}, busy = false, dirty = false, locked=false, revision = 0, revisions=[], revisionIndex=-1, assistantEdit=null,mediaAssets=[];\nconst clone = value => JSON.parse(JSON.stringify(value));\nconst text = value => Array.isArray(value) ? value.join(', ') : value === undefined || value === null ? '' : String(value);\nconst control = (label,action,value,multiline=true) => ({tag:'label',text:undefined,children:[{tag:'span',text:label},multiline?{tag:'textarea',action,value:text(value),disabled:busy||locked,label}:{tag:'input',type:'text',action,value:text(value),disabled:busy||locked,label}]});\nconst remove = (action,label) => ({tag:'button',action,text:label,className:'danger',disabled:busy||locked});\nconst card = (title,children,action) => ({tag:'article',className:'card',children:[{tag:'div',className:'card-head',children:[{tag:'h3',text:title},remove(action,'Remove')]},...children]});\nconst actionButton = (action,label) => ({tag:'button',action,text:label,className:'secondary',disabled:busy||locked});\nconst nextId = (prefix,items) => prefix+'-'+String(items.reduce((number,item)=>Math.max(number,Number(String(item && item.id || '').replace(prefix+'-',''))||0),0)+1);\nconst shotCard = (shot,sceneIndex,shotIndex) => ({tag:'article',className:'shot',children:[\n  {tag:'div',className:'card-head',children:[{tag:'h3',text:text(shot.id)||'Shot '+String(shotIndex+1)},remove('remove-shot:'+String(sceneIndex)+':'+String(shotIndex),'Remove shot')]},\n  {tag:'div',className:'grid two',children:[control('Shot ID','shot-id:'+sceneIndex+':'+shotIndex,shot.id,false),control('Type','shot-type:'+sceneIndex+':'+shotIndex,shot.type,false),control('Camera size','shot-size:'+sceneIndex+':'+shotIndex,shot.cameraSize,false),control('Camera angle','shot-angle:'+sceneIndex+':'+shotIndex,shot.cameraAngle,false),control('Camera movement','shot-movement:'+sceneIndex+':'+shotIndex,shot.cameraMovement || shot.movement,false),control('Duration','shot-duration:'+sceneIndex+':'+shotIndex,shot.intendedDuration,false),control('Generation length','shot-generation:'+sceneIndex+':'+shotIndex,shot.generationLength,false),control('Fulfillment','shot-fulfillment:'+sceneIndex+':'+shotIndex,shot.fulfillmentType,false)]},\n  control('Description','shot-description:'+sceneIndex+':'+shotIndex,shot.description),control('Image prompt','shot-image:'+sceneIndex+':'+shotIndex,shot.imagePromptReadable),control('Video prompt','shot-video:'+sceneIndex+':'+shotIndex,shot.videoPromptReadable)\n]});\nconst ensure = () => {\n  if(!draft.emotionalArc || Array.isArray(draft.emotionalArc)) draft.emotionalArc={};\n  if(!draft.visualStyleGuide || Array.isArray(draft.visualStyleGuide)) draft.visualStyleGuide=clone(draft.visualStyle && !Array.isArray(draft.visualStyle) ? draft.visualStyle : {});\n  if(!Array.isArray(draft.voiceover)) draft.voiceover=[];\n  if(!Array.isArray(draft.characters)) draft.characters=[];\n  if(!Array.isArray(draft.locations)) draft.locations=[];\n  if(!Array.isArray(draft.scenes)) draft.scenes=[];\n};\nconst draw = () => {\n  ensure();\n  fields.title.value=text(draft.title);fields.description.value=text(draft.description);fields.videoType.value=text(draft.videoType);fields.targetLength.value=text(draft.targetLength);fields.tone.value=text(draft.tone);fields.aspectRatio.value=text(draft.aspectRatio);fields.extraInfo.value=text(draft.extraInfo);\n  arc.beginning.value=text(draft.emotionalArc.beginning);arc.escalation.value=text(draft.emotionalArc.escalation);arc.climax.value=text(draft.emotionalArc.climax);arc.resolution.value=text(draft.emotionalArc.resolution);\n  visual.colorPalette.value=text(draft.visualStyleGuide.colorPalette);visual.lightingTone.value=text(draft.visualStyleGuide.lightingTone);visual.cameraLanguage.value=text(draft.visualStyleGuide.cameraLanguage);visual.overallAesthetic.value=text(draft.visualStyleGuide.overallAesthetic || draft.visualStyleGuide.aesthetic);\n  StillMade.render('voiceover',draft.voiceover.map((line,index)=>card(text(line.sceneId)||'Voiceover '+String(index+1),[control('Scene ID','voiceover-scene:'+String(index),line.sceneId,false),control('Speaker','voiceover-speaker:'+String(index),line.characterSpeaking,false),control('Narration','voiceover:'+String(index),line.text)],'remove-voiceover:'+String(index))));\n  StillMade.render('characters',draft.characters.map((item,index)=>card(text(item.name)||'Character '+String(index+1),[control('Name','character-name:'+String(index),item.name,false),control('Role','character-role:'+String(index),item.role,false),control('Physical description','character-physical:'+String(index),item.physicalDescription),control('Personality','character-personality:'+String(index),item.personality),control('Notes','character-notes:'+String(index),item.notes)],'remove-character:'+String(index))));\n  StillMade.render('locations',draft.locations.map((item,index)=>card(text(item.name)||'Location '+String(index+1),[control('Name','location-name:'+String(index),item.name,false),control('Time of day','location-time:'+String(index),item.timeOfDay,false),control('Visual description','location-visual:'+String(index),item.visualDescription),control('Atmosphere','location-atmosphere:'+String(index),item.atmosphere || item.emotionalAtmosphere)],'remove-location:'+String(index))));\n  StillMade.render('scenes',draft.scenes.map((item,index)=>card(text(item.title)||'Scene '+text(item.sceneNumber || index+1),[control('Scene number','scene-number:'+String(index),item.sceneNumber,false),control('Title','scene-title:'+String(index),item.title,false),control('Time of day','scene-time:'+String(index),item.timeOfDay,false),control('Emotional tone','scene-tone:'+String(index),item.emotionalTone,false),control('What happens','scene-action:'+String(index),item.whatHappens || item.action),control('Key visual moment','scene-visual:'+String(index),item.keyVisualMoment),control('Characters','scene-characters:'+String(index),item.charactersPresent),{tag:'div',className:'card-head',children:[{tag:'h3',text:String(item.shotList.length)+' shots'},actionButton('add-shot:'+String(index),'Add shot')]},{tag:'div',className:'shot-list',children:item.shotList.map((shot,shotIndex)=>shotCard(shot,index,shotIndex))}], 'remove-scene:'+String(index))));\n  StillMade.render('assistantProposal',assistantEdit?[{tag:'p',text:text(assistantEdit.title||'Blueprint proposal')},{tag:'p',text:assistantEdit.field==='blueprint'?'Ready for local review. Nothing changes until you apply it here, then use Review changes.':'This proposal targets another workspace and cannot be applied here.'}]:[{tag:'p',text:'Connect a Blueprint Assistant workspace proposal to review assisted changes here.'}]);raw.value=JSON.stringify(draft,null,2);const lock=document.getElementById('lock');lock.textContent=locked?'Unlock editing':'Lock editing';document.querySelectorAll('input,textarea,select,button').forEach(node=>{if(node!==lock)node.disabled=busy||locked});document.getElementById('undo').disabled=busy||locked||revisionIndex<=0;document.getElementById('redo').disabled=busy||locked||revisionIndex>=revisions.length-1;\n};\nconst changed = () => {dirty=true;revision+=1;const encoded=JSON.stringify(draft);if(JSON.stringify(revisions.find((item,position)=>position===revisionIndex))!==encoded){revisions=revisions.slice(0,revisionIndex+1);revisions.push(clone(draft));if(revisions.length>50)revisions.shift();revisionIndex=revisions.length-1}status.textContent='Changes are local until you choose Review changes.';raw.value=JSON.stringify(draft,null,2)};\nfields.title.addEventListener('input',()=>{draft.title=fields.title.value;changed()});fields.description.addEventListener('input',()=>{draft.description=fields.description.value;changed()});fields.videoType.addEventListener('input',()=>{draft.videoType=fields.videoType.value;changed()});fields.targetLength.addEventListener('input',()=>{draft.targetLength=fields.targetLength.value;changed()});fields.tone.addEventListener('input',()=>{draft.tone=fields.tone.value;changed()});fields.aspectRatio.addEventListener('input',()=>{draft.aspectRatio=fields.aspectRatio.value;changed()});fields.extraInfo.addEventListener('input',()=>{draft.extraInfo=fields.extraInfo.value;changed()});\narc.beginning.addEventListener('input',()=>{ensure();draft.emotionalArc.beginning=arc.beginning.value;changed()});arc.escalation.addEventListener('input',()=>{ensure();draft.emotionalArc.escalation=arc.escalation.value;changed()});arc.climax.addEventListener('input',()=>{ensure();draft.emotionalArc.climax=arc.climax.value;changed()});arc.resolution.addEventListener('input',()=>{ensure();draft.emotionalArc.resolution=arc.resolution.value;changed()});\nvisual.colorPalette.addEventListener('input',()=>{ensure();draft.visualStyleGuide.colorPalette=visual.colorPalette.value;changed()});visual.lightingTone.addEventListener('input',()=>{ensure();draft.visualStyleGuide.lightingTone=visual.lightingTone.value;changed()});visual.cameraLanguage.addEventListener('input',()=>{ensure();draft.visualStyleGuide.cameraLanguage=visual.cameraLanguage.value;changed()});visual.overallAesthetic.addEventListener('input',()=>{ensure();draft.visualStyleGuide.overallAesthetic=visual.overallAesthetic.value;changed()});\nStillMade.onAction(event=>{\n  if(busy||locked)return;const parts=event.action.split(':'),index=Number(parts[1]),kind=parts[0];ensure();\n  const character=draft.characters.find((item,position)=>position===index),place=draft.locations.find((item,position)=>position===index),scene=draft.scenes.find((item,position)=>position===index),voice=draft.voiceover.find((item,position)=>position===index);\n  if(kind==='voiceover'&&voice)voice.text=event.value;if(kind==='voiceover-scene'&&voice)voice.sceneId=event.value;if(kind==='voiceover-speaker'&&voice)voice.characterSpeaking=event.value;\n  if(kind==='character-name'&&character)character.name=event.value;if(kind==='character-role'&&character)character.role=event.value;if(kind==='character-physical'&&character)character.physicalDescription=event.value;if(kind==='character-personality'&&character)character.personality=event.value;if(kind==='character-notes'&&character)character.notes=event.value;\n  if(kind==='location-name'&&place)place.name=event.value;if(kind==='location-time'&&place)place.timeOfDay=event.value;if(kind==='location-visual'&&place)place.visualDescription=event.value;if(kind==='location-atmosphere'&&place)place.atmosphere=event.value;\n  if(kind==='scene-number'&&scene)scene.sceneNumber=event.value;if(kind==='scene-title'&&scene)scene.title=event.value;if(kind==='scene-time'&&scene)scene.timeOfDay=event.value;if(kind==='scene-tone'&&scene)scene.emotionalTone=event.value;if(kind==='scene-action'&&scene)scene.whatHappens=event.value;if(kind==='scene-visual'&&scene)scene.keyVisualMoment=event.value;if(kind==='scene-characters'&&scene)scene.charactersPresent=event.value.split(',').map(value=>value.trim()).filter(Boolean);\n  const shotIndex=Number(parts[2]),shot=scene && scene.shotList.find((item,position)=>position===shotIndex);\n  if(kind==='shot-id'&&shot)shot.id=event.value;if(kind==='shot-type'&&shot)shot.type=event.value;if(kind==='shot-size'&&shot)shot.cameraSize=event.value;if(kind==='shot-angle'&&shot)shot.cameraAngle=event.value;if(kind==='shot-movement'&&shot)shot.cameraMovement=event.value;if(kind==='shot-duration'&&shot)shot.intendedDuration=event.value;if(kind==='shot-generation'&&shot)shot.generationLength=event.value;if(kind==='shot-fulfillment'&&shot)shot.fulfillmentType=event.value;if(kind==='shot-description'&&shot)shot.description=event.value;if(kind==='shot-image'&&shot)shot.imagePromptReadable=event.value;if(kind==='shot-video'&&shot)shot.videoPromptReadable=event.value;\n  if(kind==='add-shot'&&scene)scene.shotList=[...scene.shotList,{id:nextId('shot',scene.shotList),type:'',description:'',cameraSize:'',cameraAngle:'',cameraMovement:'',intendedDuration:'',generationLength:'',fulfillmentType:'',imagePromptReadable:'',videoPromptReadable:''}];\n  if(kind==='remove-shot'&&scene)scene.shotList=scene.shotList.filter((item,position)=>position!==shotIndex);if(kind==='remove-voiceover')draft.voiceover=draft.voiceover.filter((item,position)=>position!==index);if(kind==='remove-character')draft.characters=draft.characters.filter((item,position)=>position!==index);if(kind==='remove-location')draft.locations=draft.locations.filter((item,position)=>position!==index);if(kind==='remove-scene')draft.scenes=draft.scenes.filter((item,position)=>position!==index);\n  changed();if(kind.startsWith('remove-')||kind==='add-shot')draw();\n});\ndocument.getElementById('addVoiceover').addEventListener('click',()=>{if(!busy&&!locked){ensure();draft.voiceover=[...draft.voiceover,{sceneId:'scene-'+String(draft.voiceover.length+1),characterSpeaking:'',text:''}];changed();draw()}});\ndocument.getElementById('addCharacter').addEventListener('click',()=>{if(!busy&&!locked){ensure();draft.characters=[...draft.characters,{id:nextId('character',draft.characters),name:'New character',role:'',physicalDescription:'',personality:'',notes:''}];changed();draw()}});\ndocument.getElementById('addLocation').addEventListener('click',()=>{if(!busy&&!locked){ensure();draft.locations=[...draft.locations,{id:nextId('location',draft.locations),name:'New location',timeOfDay:'',visualDescription:'',atmosphere:''}];changed();draw()}});\ndocument.getElementById('addScene').addEventListener('click',()=>{if(!busy&&!locked){ensure();draft.scenes=[...draft.scenes,{id:nextId('scene',draft.scenes),sceneNumber:draft.scenes.length+1,title:'New scene',timeOfDay:'',emotionalTone:'',whatHappens:'',keyVisualMoment:'',charactersPresent:[],shotList:[]}];changed();draw()}});\ndocument.getElementById('applyRaw').addEventListener('click',()=>{if(busy||locked)return;try{const value=JSON.parse(raw.value);if(!value||Array.isArray(value)||value.schemaVersion!==1)throw Error('Blueprint JSON must be a version 1 object.');draft=clone(value);changed();draw();status.textContent='Complete Blueprint data applied to this workspace.'}catch(error){status.textContent=error.message}});\ndocument.getElementById('reset').addEventListener('click',()=>{if(!busy&&!locked){draft=clone(source);dirty=false;revision+=1;draw();status.textContent='Changes reset to the current project Blueprint.'}});\nsave.addEventListener('click',async()=>{if(busy||locked)return;const started=revision;busy=true;draw();status.textContent='Checking the complete Blueprint…';try{const result=await StillMade.run({blueprint:source,updatedBlueprint:dirty?draft:source,commit:true});if(started===revision)status.textContent='Blueprint is ready below. Review the before and after, then choose Apply.';draft=clone(result.blueprint)}catch(error){status.textContent=error.message||'The Blueprint could not be prepared.'}finally{busy=false;draw()}});\nconst renderMediaLibrary=()=>StillMade.render('mediaLibrary',mediaAssets.length?mediaAssets.slice(0,50).map((asset,index)=>({tag:'article',className:'card',children:[{tag:'strong',text:text(asset.title||asset.name||asset.assetId)+' · '+text(asset.versionId)},{tag:'div',className:'row',children:[{tag:'button',action:'library-preview:'+String(index),text:'Preview',className:'secondary'},{tag:'button',action:'library-attach:'+String(index),text:'Add reference',className:'secondary'}]}]})):[{tag:'p',text:'No stored project images are available.'}]);\nconst renderWorkspaceSync=(versions,presence)=>{const saved=Array.isArray(versions)?versions.slice(0,20):[],people=Array.isArray(presence)?presence.slice(0,20):[];StillMade.render('workspaceSync',[{tag:'p',text:saved.length?String(saved.length)+' saved revision'+(saved.length===1?'':'s')+' available.':'No saved revisions yet.'},{tag:'ul',children:saved.map((item,index)=>({tag:'li',text:text(item.title||item.label||item.id||'Revision '+String(index+1))+' · '+text(item.createdAt||item.updatedAt||item.date||'Saved')}))},{tag:'p',text:people.length?String(people.length)+' collaborator'+(people.length===1?'':'s')+' active or recently active.':'No collaborator presence available.'},{tag:'ul',children:people.map((item,index)=>({tag:'li',text:text(item.name||item.displayName||item.id||'Collaborator '+String(index+1))+(item.editing?' · editing '+text(item.editing):'' )}))}])};\nStillMade.onInput(values=>{mediaAssets=(Array.isArray(values.assets)?values.assets:[]).filter(asset=>asset&&asset.kind==='image'&&asset.url).slice(0,50);renderMediaLibrary();source=clone(values.blueprint||{schemaVersion:1});draft=clone(source);assistantEdit=values.assistantEdit?clone(values.assistantEdit):null;dirty=false;locked=false;revisions=[clone(draft)];revisionIndex=0;revision+=1;draw();renderWorkspaceSync(values.versions,values.presence);status.textContent='Edit any section. Every unshown project field is retained.'});\n\ndocument.getElementById('prepareShots').addEventListener('click',async()=>{if(busy||locked)return;busy=true;draw();status.textContent='Preparing the exact shot sequence…';try{const result=await StillMade.run({blueprint:source,updatedBlueprint:draft,commit:true});document.getElementById('handoffSummary').textContent=String(result.shotPlan.shots.length)+' shots are ready for a connected Shots or Animated Scene Step.';status.textContent='Shots handoff is ready below. Review Blueprint changes before Apply.'}catch(error){status.textContent=error.message||'The Shots handoff could not be prepared.'}finally{busy=false;draw()}});\n\nconst restoreHistory=index=>{if(busy||locked||index<0||index>=revisions.length)return;revisionIndex=index;draft=clone(revisions.find((item,position)=>position===index));dirty=JSON.stringify(draft)!==JSON.stringify(source);revision+=1;draw();status.textContent='Restored local Blueprint revision '+String(index+1)+' of '+String(revisions.length)+'.'};document.getElementById('undo').addEventListener('click',()=>restoreHistory(revisionIndex-1));document.getElementById('redo').addEventListener('click',()=>restoreHistory(revisionIndex+1));document.getElementById('lock').addEventListener('click',()=>{if(busy)return;locked=!locked;draw();status.textContent=locked?'Blueprint editing locked. Unlock to make changes.':'Blueprint editing unlocked.'});document.getElementById('tidy').addEventListener('click',()=>{if(busy||locked)return;const tidy=value=>typeof value==='string'?value.trim().replace(/\\s+/g,' '):value;draft={...draft,title:tidy(draft.title),description:tidy(draft.description),videoType:tidy(draft.videoType),targetLength:tidy(draft.targetLength),tone:tidy(draft.tone),aspectRatio:tidy(draft.aspectRatio),extraInfo:tidy(draft.extraInfo)};ensure();draft.voiceover=draft.voiceover.map((item,index)=>({...item,sceneId:tidy(item.sceneId)||'scene-'+String(index+1),characterSpeaking:tidy(item.characterSpeaking),text:tidy(item.text)}));draft.characters=draft.characters.map((item,index)=>({...item,id:item.id||'character-'+String(index+1),name:tidy(item.name),role:tidy(item.role),physicalDescription:tidy(item.physicalDescription),personality:tidy(item.personality),notes:tidy(item.notes)}));draft.locations=draft.locations.map((item,index)=>({...item,id:item.id||'location-'+String(index+1),name:tidy(item.name),timeOfDay:tidy(item.timeOfDay),visualDescription:tidy(item.visualDescription),atmosphere:tidy(item.atmosphere)}));draft.scenes=draft.scenes.map((scene,index)=>({...scene,id:scene.id||'scene-'+String(index+1),title:tidy(scene.title),whatHappens:tidy(scene.whatHappens),keyVisualMoment:tidy(scene.keyVisualMoment),shotList:scene.shotList.map((shot,shotIndex)=>({...shot,id:shot.id||'scene-'+String(index+1)+'-shot-'+String(shotIndex+1),description:tidy(shot.description),imagePromptReadable:tidy(shot.imagePromptReadable),videoPromptReadable:tidy(shot.videoPromptReadable)}))}));changed();draw();status.textContent='Structure assistant trimmed standard text and filled missing stable IDs. Undo is available.'});\n\ndocument.getElementById('applyAssistant').addEventListener('click',()=>{if(busy||locked||!assistantEdit)return;if(assistantEdit.field!=='blueprint'||JSON.stringify(assistantEdit.before)!==JSON.stringify(source)){status.textContent='Assistant proposal is stale or targets another workspace. Request a new proposal from the current Blueprint.';return}draft=clone(assistantEdit.after);changed();draw();status.textContent='Assistant proposal applied locally. Review the fields, undo if needed, then choose Review changes.'});\n\nStillMade.onAction(async event=>{if(!event.action.startsWith('library-')||busy||locked)return;const parts=event.action.split(':'),asset=mediaAssets.find((item,index)=>index===Number(parts[1]));if(!asset)return;if(parts[0]==='library-preview'){try{const preview=await StillMade.previewImage(asset),image=document.getElementById('libraryPreview');image.src=preview.url;image.hidden=false;status.textContent='Showing a trusted preview of the exact stored version.'}catch(error){status.textContent=error.message||'Preview unavailable.'}return}if(!Array.isArray(draft.mediaReferences))draft.mediaReferences=[];if(!draft.mediaReferences.some(item=>item.assetId===asset.assetId&&item.versionId===asset.versionId))draft.mediaReferences=[...draft.mediaReferences,clone(asset)];changed();status.textContent='Exact stored media reference added to the Blueprint.'});\n"},"tests":[{"name":"Retain the complete existing Blueprint without edits","input":{"blueprint":{"schemaVersion":1,"title":"Keep me","characters":[{"id":"hero","name":"Ari","portrait":{"assetId":"portrait-1","versionId":"v3"}}],"customWorkflow":{"keep":true}},"updatedBlueprint":{"schemaVersion":1},"commit":false},"expected":{"blueprint":{"schemaVersion":1,"title":"Keep me","characters":[{"id":"hero","name":"Ari","portrait":{"assetId":"portrait-1","versionId":"v3"}}],"customWorkflow":{"keep":true}},"shotPlan":{"schemaVersion":1,"shots":[]},"edit":{"schemaVersion":1,"title":"Update Blueprint: Keep me","field":"blueprint","before":{"schemaVersion":1,"title":"Keep me","characters":[{"id":"hero","name":"Ari","portrait":{"assetId":"portrait-1","versionId":"v3"}}],"customWorkflow":{"keep":true}},"after":{"schemaVersion":1,"title":"Keep me","characters":[{"id":"hero","name":"Ari","portrait":{"assetId":"portrait-1","versionId":"v3"}}],"customWorkflow":{"keep":true}}}}},{"name":"Prepare one complete exact Blueprint update","input":{"blueprint":{"schemaVersion":1,"title":"Original","characters":[{"id":"hero","name":"Ari","portrait":{"assetId":"portrait-1","versionId":"v3"}}],"scenes":[{"id":"scene-1","title":"Opening","shotList":[{"id":"shot-1","prompt":"Keep this"}]}]},"updatedBlueprint":{"schemaVersion":1,"title":"Revised","characters":[{"id":"hero","name":"Ari","portrait":{"assetId":"portrait-1","versionId":"v3"}}],"scenes":[{"id":"scene-1","title":"New opening","shotList":[{"id":"shot-1","prompt":"Keep this"}]}]},"commit":true},"expected":{"blueprint":{"schemaVersion":1,"title":"Revised","characters":[{"id":"hero","name":"Ari","portrait":{"assetId":"portrait-1","versionId":"v3"}}],"scenes":[{"id":"scene-1","title":"New opening","shotList":[{"id":"shot-1","prompt":"Keep this"}]}]},"shotPlan":{"schemaVersion":1,"shots":[{"id":"shot-1","prompt":"Keep this","sceneId":"scene-1","sceneTitle":"New opening","startTime":0,"endTime":4,"voiceoverText":""}]},"edit":{"schemaVersion":1,"title":"Update Blueprint: Revised","field":"blueprint","before":{"schemaVersion":1,"title":"Original","characters":[{"id":"hero","name":"Ari","portrait":{"assetId":"portrait-1","versionId":"v3"}}],"scenes":[{"id":"scene-1","title":"Opening","shotList":[{"id":"shot-1","prompt":"Keep this"}]}]},"after":{"schemaVersion":1,"title":"Revised","characters":[{"id":"hero","name":"Ari","portrait":{"assetId":"portrait-1","versionId":"v3"}}],"scenes":[{"id":"scene-1","title":"New opening","shotList":[{"id":"shot-1","prompt":"Keep this"}]}]}}}}]}