← Files ClaraARCHIVED FILE

ui/media.html

10.7 KB · Nov 21, 2026 · 00:11 UTC

↓ Download file

See the change to this file →

<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; font-src data:; media-src blob:; connect-src 'none'; base-uri 'none'; form-action 'none'">
<title>Clara · Audio</title><style>
@font-face{font-family:'Instrument Sans';src:url(data:font/ttf;base64,__FONT__) format('truetype');font-display:swap}*{box-sizing:border-box}body{margin:0;font:16px/1.5 'Instrument Sans',sans-serif;color:#1f2421;background:#fff}header{padding:16px 24px;border-bottom:1px solid #e8eae7;font-weight:600;color:#194b70}main{max-width:760px;padding:24px;margin:auto}h1{font-size:24px;line-height:1.3}button,input{font:inherit}button{min-height:44px;padding:10px 16px;border:1px solid #d8dcd7;background:#fff;color:#194b70;border-radius:6px;cursor:pointer}button.primary{background:#194b70;color:white}button:disabled{opacity:.55;cursor:default}button:focus-visible,input:focus-visible{outline:2px solid #194b70;outline-offset:3px}.controls{display:flex;flex-wrap:wrap;gap:12px;margin:20px 0}label{display:grid;gap:8px;margin:20px 0}input{max-width:100%}.detail{color:#596671;font-size:14px}#status{overflow-wrap:anywhere}audio{max-width:100%}[hidden]{display:none!important}@media(max-width:480px){main{padding:16px}}
</style></head><body><header>Clara</header><main><h1 id="title">Audio and narration</h1><p id="intro">Open the selected work from your Clara chat.</p>
<section id="selection" hidden><label><span id="chooseLabel"></span><input id="file" type="file" accept="audio/*,video/mp4,video/webm"></label><div class="controls"><button id="record" hidden></button><button id="stop" hidden></button></div><p id="captureNote" class="detail"></p></section>
<p id="selected"></p><audio id="preview" controls hidden></audio><p id="notice" class="detail"></p><div class="controls"><button class="primary" id="continue" disabled></button><button id="check" disabled></button></div><p id="status" role="status" aria-live="polite"></p></main>
<script>
'use strict';
const words={
 en:{title:'Audio and narration',transcribe:'Transcribe a recording',deck_feedback:'Correct a presentation',narration:'Generate approved narration',intro:'The result will return to this chat and the selected work folder.',choose:'Choose a recording',record:'Record audio',stop:'Stop and save locally',capture:'Live recording is unavailable in this host. Select an existing recording.',notice:'When you continue, Mparanza and OpenAI process the selected audio for transcription, or the approved narration text for speech. Source documents are not sent by this panel.',next:'Continue in this chat',check:'Check status',saving:'Saving locally…',sending:'Returning to chat…',sent:'Request sent. Continue in the chat.',error:'Not confirmed. Check the chat and saved status before retrying.',unsupported:'This host cannot continue in chat from this panel. Ask Clara to resume the saved media session.',select_file:'Choose a recording to begin.',receiving:'Receiving the selected recording…',ready:'Ready to continue.',confirmed:'Processing requested in chat.',authentication_required:'Sign in to Mparanza to continue. Your selection is saved.',processing:'Processing. Check status for the saved result.',needs_review:'The processing outcome needs review in chat. Files are retained; no automatic retry.',complete:'Result saved in the work folder.',selected:'Selected:'},
 it:{title:'Audio e narrazione',transcribe:'Trascrivi una registrazione',deck_feedback:'Correggi una presentazione',narration:'Genera la narrazione approvata',intro:'Il risultato torna in questa chat e nella cartella di lavoro selezionata.',choose:'Scegli una registrazione',record:'Registra audio',stop:'Ferma e salva in locale',capture:'Questo host non permette la registrazione dal pannello. Scegli una registrazione esistente.',notice:'Continuando, Mparanza e OpenAI elaborano l’audio selezionato per trascriverlo, oppure il testo approvato per la narrazione. Il pannello non invia i documenti di origine.',next:'Continua in questa chat',check:'Verifica lo stato',saving:'Salvataggio locale…',sending:'Ritorno alla chat…',sent:'Richiesta inviata. Prosegui nella chat.',error:'Operazione non confermata. Verifica la chat e lo stato salvato prima di riprovare.',unsupported:'Questo host non permette di continuare nella chat dal pannello. Chiedi a Clara di riprendere la sessione salvata.',select_file:'Scegli una registrazione per iniziare.',receiving:'Ricezione della registrazione…',ready:'Pronto per continuare.',confirmed:'Elaborazione richiesta nella chat.',authentication_required:'Accedi a Mparanza per continuare. La selezione è salvata.',processing:'Elaborazione in corso. Verifica lo stato per il risultato salvato.',needs_review:'Verifica l’esito nella chat. I file sono conservati; nessun nuovo tentativo automatico.',complete:'Risultato salvato nella cartella di lavoro.',selected:'Selezionato:'}
};
const ids=['title','intro','chooseLabel','record','stop','captureNote','selected','notice','continue','check','status','selection','file','preview'];const el=Object.fromEntries(ids.map(id=>[id,document.getElementById(id)]));
let data,host,copy=words.en,busy=false,sent=false,nextId=0,recorder,stream,chunks=[],previewURL;
const pending=new Map();
function rpc(method,params){return new Promise((resolve,reject)=>{const id=++nextId,timer=setTimeout(()=>{pending.delete(id);reject(new Error(copy.error));},method==='ui/message'?300000:30000);pending.set(id,{resolve,reject,timer});parent.postMessage({jsonrpc:'2.0',id,method,params},'*');});}
async function tool(name,args){const result=await rpc('tools/call',{name,arguments:args});if(result?.isError||!result?._meta?.media)throw new Error(copy.error);return result._meta.media;}
function canRecord(){return !!(navigator.mediaDevices?.getUserMedia&&window.MediaRecorder&&host?.hostContext?.permissions?.microphone);}
function render(){if(!data)return;copy=words[data.language]||words.en;document.documentElement.lang=words[data.language]?data.language:'en';el.title.textContent=copy[data.operation];document.title='Clara · '+copy[data.operation];el.intro.textContent=copy.intro;el.chooseLabel.textContent=copy.choose;el.record.textContent=copy.record;el.stop.textContent=copy.stop;el.notice.textContent=copy.notice;el.continue.textContent=copy.next;el.check.textContent=copy.check;el.selection.hidden=data.operation==='narration';el.selected.textContent=data.filename?copy.selected+' '+data.filename:'';el.file.disabled=busy||!['select_file','receiving'].includes(data.status);el.record.hidden=!canRecord()||recorder?.state==='recording'||data.status!=='select_file';el.stop.hidden=recorder?.state!=='recording';el.captureNote.textContent=canRecord()?'':copy.capture;el.check.disabled=busy;el.continue.disabled=busy||sent||!['ready','confirmed','authentication_required'].includes(data.status)||!host?.hostCapabilities?.experimental?.['openai/message'];el.status.textContent=host&&!host.hostCapabilities?.experimental?.['openai/message']?copy.unsupported:copy[data.status]||copy.error;}
async function save(file){if(busy||!data)return;busy=true;render();el.status.textContent=copy.saving;try{if(!file.size||file.size>268435456)throw new Error('Select a nonempty recording up to 256 MB, or ask Clara to use its local path.');let index=0;for(let offset=0;offset<file.size;offset+=262144){const bytes=new Uint8Array(await file.slice(offset,offset+262144).arrayBuffer());let raw='';for(const b of bytes)raw+=String.fromCharCode(b);data=await tool('clara_media_save',{session:data.session,filename:file.name,index:index++,data:btoa(raw),final:offset+bytes.length===file.size});}if(previewURL)URL.revokeObjectURL(previewURL);previewURL=URL.createObjectURL(file);el.preview.src=previewURL;el.preview.hidden=false;}catch(error){el.status.textContent=error.message;busy=false;el.check.disabled=false;return;}busy=false;render();}
el.file.addEventListener('change',()=>{if(el.file.files[0])save(el.file.files[0]);});
el.record.addEventListener('click',async()=>{try{stream=await navigator.mediaDevices.getUserMedia({audio:true});chunks=[];recorder=new MediaRecorder(stream);recorder.ondataavailable=e=>{if(e.data.size)chunks.push(e.data);};recorder.onstop=()=>{stream.getTracks().forEach(track=>track.stop());const mime=recorder.mimeType;save(new File(chunks,['audio/mp4','video/mp4'].some(t=>mime.startsWith(t))?'recording.m4a':'recording.webm',{type:mime}));};recorder.start(1000);render();}catch{el.captureNote.textContent=copy.capture;}});
el.stop.addEventListener('click',()=>{if(recorder?.state==='recording')recorder.stop();});
el.check.addEventListener('click',async()=>{if(busy||!data)return;busy=true;try{data=await tool('clara_media_status',{session:data.session});}catch{el.status.textContent=copy.error;}finally{busy=false;render();}});
el.continue.addEventListener('click',async()=>{if(busy||sent||el.continue.disabled)return;busy=true;render();try{data=await tool('clara_media_confirm',{session:data.session});sent=true;el.status.textContent=copy.sending;const text='Continue the saved Clara media session '+data.session+'. Use clara_media_status, then the installed operator-media instructions. The user selected '+data.operation+' and confirmed the processing notice. Use an already-authorized private Mparanza session file for clara_media_run; never ask for credential contents or extract browser cookies. If authentication is unavailable, preserve the session and report authentication_required. After completion, consume the saved output in the original workflow. Do not launch an upload page or ask the user to move JSON/ZIP files. Respond in '+data.language+'.';const result=await rpc('ui/message',{role:'user',content:[{type:'text',text}],_meta:{'openai/message':{target:'active'}}});if(result?.isError)throw new Error(copy.error);busy=false;render();el.status.textContent=copy.sent;}catch(error){busy=false;render();el.status.textContent=error.message;}});
addEventListener('message',event=>{if(event.source!==parent||event.data?.jsonrpc!=='2.0')return;const m=event.data,item=pending.get(m.id);if(item&&!m.method){clearTimeout(item.timer);pending.delete(m.id);m.error?item.reject(new Error(copy.error)):item.resolve(m.result);return;}if(m.method==='ui/notifications/tool-result'&&m.params?._meta?.media){data=m.params._meta.media;render();}if(m.method==='ui/resource-teardown'){stream?.getTracks().forEach(track=>track.stop());if(previewURL)URL.revokeObjectURL(previewURL);parent.postMessage({jsonrpc:'2.0',id:m.id,result:{}},'*');}});
rpc('ui/initialize',{protocolVersion:'2026-01-26',appInfo:{name:'Clara media',version:'1.0.0'},appCapabilities:{availableDisplayModes:['inline','fullscreen']}}).then(result=>{host=result;render();parent.postMessage({jsonrpc:'2.0',method:'ui/notifications/initialized'},'*');}).catch(()=>{el.status.textContent=copy.error;});
</script></body></html>

SHA-256: c9ed3323ad90a751e3ae794e140a972148959d7ab03cfd85939a83ec1eed4c82