PageSourceSearch

https://otimizz.ai/assets/CommandAvatarStudio-B35ucQcG.js

js otimizz.ai collected 2026-10-05 12:23:00 UTC 29,417 bytes, 1 lines download raw bytes

1import{j as e,a as Ze,u as ea,b as Le}from"./query-vendor-DRhPQC1X.js";import{r as t}from"./react-vendor-CI9uWh-p.js";import{B as V,s as y,C as F,a as I,K as R,I as K,o as ye,p as fe,q as je,r as ee,t as ae,v as se,w as te,x as D,ae as Fe}from"./index-BIQjbFeg.js";import{T as qe,a as Oe,b as q,c as O}from"./tabs-CLB5JdvL.js";import{R as Ie,a as ie}from"./radio-group-B3xb8jQq.js";import{b9 as Ge,as as aa,aN as sa,h as ta,u as p,aY as ra,X as be,b as de,aq as na,ag as oa,p as Pe,cK as ia,cJ as ge,O as ca,aP as la}from"./ui-vendor-DBRJ-Hal.js";import{showError as Ne}from"./index-Q-MgaALk.js";import"./charts-vendor-Duh-UgyC.js";import"./supabase-vendor-Dn1PXHTx.js";import"./motor-campanha-vendor-DYmQX9O7.js";const Te=r=>{const i=Math.floor(r/60).toString().padStart(2,"0"),v=Math.floor(r%60).toString().padStart(2,"0");return`${i}:${v}`};function da(r,i=16e3){const v=r.numberOfChannels,h=r.length,d=new Float32Array(h);for(let o=0;o<v;o++){const m=r.getChannelData(o);for(let l=0;l<h;l++)d[l]+=m[l]/v}const n=r.sampleRate/i,u=Math.floor(h/n),w=new Float32Array(u);for(let o=0;o<u;o++){const m=o*n,l=Math.floor(m),s=Math.min(h-1,l+1),N=m-l;w[o]=d[l]*(1-N)+d[s]*N}const f=new Int16Array(u);for(let o=0;o<u;o++){const m=Math.max(-1,Math.min(1,w[o]));f[o]=m<0?m*32768:m*32767}const g=f.length*2,j=new ArrayBuffer(44+g),c=new DataView(j),b=(o,m)=>{for(let l=0;l<m.length;l++)c.setUint8(o+l,m.charCodeAt(l))};return b(0,"RIFF"),c.setUint32(4,36+g,!0),b(8,"WAVE"),b(12,"fmt "),c.setUint32(16,16,!0),c.setUint16(20,1,!0),c.setUint16(22,1,!0),c.setUint32(24,i,!0),c.setUint32(28,i*2,!0),c.setUint16(32,2,!0),c.setUint16(34,16,!0),b(36,"data"),c.setUint32(40,g,!0),new Int16Array(j,44).set(f),new Blob([j],{type:"audio/wav"})}function ua({onReady:r,maxSeconds:i=60}){const[v,h]=t.useState("idle"),[d,n]=t.useState(0),[u,w]=t.useState(0),[f,g]=t.useState(null),j=t.useRef(null),c=t.useRef([]),b=t.useRef(null),o=t.useRef(null),m=t.useRef(null),l=t.useRef(null);t.useEffect(()=>()=>s(),[]);const s=()=>{var A,P;o.current&&window.clearInterval(o.current),m.current&&cancelAnimationFrame(m.current),(A=b.current)==null||A.getTracks().forEach(k=>k.stop()),(P=l.current)==null||P.close().catch(()=>{}),b.current=null,l.current=null},N=async()=>{try{const A=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}});b.current=A;const P=MediaRecorder.isTypeSupported("audio/webm;codecs=opus")?"audio/webm;codecs=opus":"audio/webm",k=new MediaRecorder(A,{mimeType:P});j.current=k,c.current=[],k.ondataavailable=_=>{_.data.size>0&&c.current.push(_.data)},k.onstop=async()=>{const _=new Blob(c.current,{type:P});try{const U=new AudioContext,L=await _.arrayBuffer(),ue=await U.decodeAudioData(L.slice(0));await U.close();const Q=da(ue,16e3),me=URL.createObjectURL(Q);g(me);const W=new File([Q],`recording-${Date.now()}.wav`,{type:"audio/wav"});r(W)}catch(U){Ne(U,"gen/audio_failed",{context:"VoiceRecorder.process"}),r(null)}h("recorded"),s()},k.start(100),n(0),h("recording"),o.current=window.setInterval(()=>{n(_=>{const U=_+1;return U>=i&&S(),U})},1e3);const J=new AudioContext;l.current=J;const Y=J.createMediaStreamSource(A),G=J.createAnalyser();G.fftSize=256,Y.connect(G);const B=new Uint8Array(G.frequencyBinCount),oe=()=>{G.getByteTimeDomainData(B);let _=0;for(let U=0;U<B.length;U++){const L=(B[U]-128)/128;_+=L*L}w(Math.min(1,Math.sqrt(_/B.length)*2.5)),m.current=requestAnimationFrame(oe)};oe()}catch{p.error("Microfone indisponível",{description:"Permita o acesso ao microfone nas configurações do navegador."})}},S=()=>{var A;o.current&&window.clearInterval(o.current),m.current&&cancelAnimationFrame(m.current),(A=j.current)==null||A.stop()},X=()=>{h("idle"),n(0),w(0),f&&URL.revokeObjectURL(f),g(null),r(null)};return e.jsxs("div",{className:"rounded-md border p-3 space-y-3 bg-muted/30",children:[v==="idle"&&e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["Grave sua voz direto pelo microfone (até ",i,"s)."]}),e.jsxs(V,{type:"button",size:"sm",onClick:N,children:[e.jsx(Ge,{className:"h-4 w-4 mr-2"})," Gravar"]})]}),v==="recording"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-destructive animate-pulse"}),e.jsxs("span",{className:"text-sm font-medium",children:["Gravando, ",Te(d)]})]}),e.jsxs(V,{type:"button",size:"sm",variant:"destructive",onClick:S,children:[e.jsx(aa,{className:"h-4 w-4 mr-2"})," Parar"]})]}),e.jsx("div",{className:"h-2 w-full rounded bg-background overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary transition-[width] duration-75",style:{width:`${Math.round(u*100)}%`}})})]}),v==="recorded"&&f&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(sa,{className:"h-4 w-4 text-primary"}),e.jsxs("span",{children:["Gravação pronta (",Te(d),")"]})]}),e.jsx("audio",{src:f,controls:!0,className:"w-full"}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(V,{type:"button",size:"sm",variant:"outline",onClick:X,children:[e.jsx(ta,{className:"h-4 w-4 mr-2"})," Regravar"]})})]})]})}const we=["voice-bank-samples"];async function $e(r){const{data:i}=await y.storage.from("avatars").createSignedUrl(r,21600);return(i==null?void 0:i.signedUrl)??null}function Qe(){const r=Ze(),i=ea({queryKey:we,queryFn:async()=>{const{data:{user:n}}=await y.auth.getUser();if(!n)return[];const{data:u,error:w}=await y.from("user_voice_samples").select("*").eq("profile_id",n.id).order("created_at",{ascending:!1});if(w)throw w;
1const f=u??[],g=await Promise.all(f.map(j=>$e(j.audio_path)));return f.map((j,c)=>({...j,signed_url:g[c]}))}}),v=Le({mutationFn:async n=>{const{data:{user:u}}=await y.auth.getUser();if(!u)throw new Error("não autenticado");const w=n.ext.replace(/[^a-z0-9]/gi,"").toLowerCase()||"wav",f=`${u.id}/voice-bank/${Date.now()}-${crypto.randomUUID().slice(0,8)}.${w}`,{error:g}=await y.storage.from("avatars").upload(f,n.blob,{contentType:n.blob.type||"audio/wav",upsert:!1});if(g)throw g;const{data:j,error:c}=await y.from("user_voice_samples").insert({profile_id:u.id,name:n.name.trim().slice(0,80)||"Minha voz",audio_path:f,duration_s:Math.round(n.duration_s*10)/10,mime_type:n.blob.type||"audio/wav",source:n.source}).select().single();if(c)throw await y.storage.from("avatars").remove([f]).catch(()=>{}),c;return j},onSuccess:()=>{r.invalidateQueries({queryKey:we}),p.success("Amostra adicionada ao Banco de Voz")},onError:n=>Ne(n,"crud/save_failed",{context:"useVoiceBank.add"})}),h=Le({mutationFn:async n=>{const{error:u}=await y.from("user_voice_samples").delete().eq("id",n.id);if(u)throw u;await y.storage.from("avatars").remove([n.audio_path]).catch(()=>{})},onSuccess:()=>{r.invalidateQueries({queryKey:we}),p.success("Amostra removida")},onError:n=>Ne(n,"crud/delete_failed",{context:"useVoiceBank.remove"})});return{list:i,create:v,remove:h,sign:async n=>{const u=(i.data??[]).find(w=>w.id===n);return u?$e(u.audio_path):null}}}function ma(r,i=16e3){const v=r.numberOfChannels,h=r.length,d=new Float32Array(h);for(let o=0;o<v;o++){const m=r.getChannelData(o);for(let l=0;l<h;l++)d[l]+=m[l]/v}const n=r.sampleRate/i,u=Math.floor(h/n),w=new Float32Array(u);for(let o=0;o<u;o++){const m=o*n,l=Math.floor(m),s=Math.min(h-1,l+1),N=m-l;w[o]=d[l]*(1-N)+d[s]*N}const f=new Int16Array(u);for(let o=0;o<u;o++){const m=Math.max(-1,Math.min(1,w[o]));f[o]=m<0?m*32768:m*32767}const g=f.length*2,j=new ArrayBuffer(44+g),c=new DataView(j),b=(o,m)=>{for(let l=0;l<m.length;l++)c.setUint8(o+l,m.charCodeAt(l))};return b(0,"RIFF"),c.setUint32(4,36+g,!0),b(8,"WAVE"),b(12,"fmt "),c.setUint32(16,16,!0),c.setUint16(20,1,!0),c.setUint16(22,1,!0),c.setUint32(24,i,!0),c.setUint32(28,i*2,!0),c.setUint16(32,2,!0),c.setUint16(34,16,!0),b(36,"data"),c.setUint32(40,g,!0),new Int16Array(j,44).set(f),new Blob([j],{type:"audio/wav"})}async function ha(r){const i=await r.arrayBuffer(),v=window.AudioContext||window.webkitAudioContext;if(!v)throw new Error("AudioContext indisponível neste navegador");const h=new v;try{let d;try{d=await h.decodeAudioData(i.slice(0))}catch{throw new Error("Não foi possível extrair o áudio deste vídeo neste navegador. Tente exportar como MP4 (codec AAC) ou enviar o áudio em separado (MP3/WAV/M4A).")}return{wav:ma(d,16e3),duration_s:d.duration}}finally{try{await h.close()}catch{}}}function De(r){return new Promise((i,v)=>{const h=URL.createObjectURL(r),d=document.createElement("audio");d.preload="metadata",d.src=h,d.onloadedmetadata=()=>{const n=d.duration;URL.revokeObjectURL(h),i(isFinite(n)?n:0)},d.onerror=()=>{URL.revokeObjectURL(h),v(new Error("não foi possível ler o áudio"))}})}const ce=["mp3","wav","m4a","aac","ogg","flac"],le=["mp4","mov","webm","mkv","avi","m4v"],re=5,ne=90;function xa(r){if(!r)return"?";const i=Math.floor(r/60),v=Math.round(r-i*60);return i>0?`${i}m${v.toString().padStart(2,"0")}s`:`${v}s`}function va(){const{list:r,create:i,remove:v}=Qe(),[h,d]=t.useState(""),[n,u]=t.useState(null),[w,f]=t.useState(!1),g=t.useRef(null),j=t.useRef(null),c=s=>h.trim()?h.trim():s,b=async()=>{if(!n){p.error("Grave uma amostra antes de salvar");return}f(!0);try{const s=await De(n).catch(()=>0);if(s&&s<re){p.error(`Muito curta. Grave entre ${re}s e ${ne}s.`);return}await i.mutateAsync({name:c(`Gravação ${new Date().toLocaleString("pt-BR")}`),blob:n,ext:"wav",source:"recorded",duration_s:s}),u(null),d("")}finally{f(!1)}},o=async s=>{if(!s)return;const N=(s.name.split(".").pop()||"").toLowerCase();if(!ce.includes(N)){p.error(`Formato não aceito. Use: ${ce.join(", ")}`);return}f(!0);try{const S=await De(s).catch(()=>0);S&&(S<re||S>ne*4)&&p.error(`Áudio fora do recomendado (${re}s a ${ne}s). Você pode encurtar antes.`),await i.mutateAsync({name:c(s.name.replace(/\.[^.]+$/,"")),blob:s,ext:N,source:"uploaded_audio",duration_s:S}),d(""),g.current&&(g.current.value="")}finally{f(!1)}},m=async s=>{if(!s)return;const N=(s.name.split(".").pop()||"").toLowerCase();if(!le.includes(N)){p.error(`Formato de vídeo não aceito. Use: ${le.join(", ")}`);return}f(!0),p.info("Extraindo áudio do vídeo, isso pode levar alguns segundos...");try{const{wav:S,duration_s:X}=await ha(s);await i.mutateAsync({name:c(`${s.name.replace(/\.[^.]+$/,"")} (extraído)`),blob:S,ext:"wav",source:"extracted_video",duration_s:X}),d(""),j.current&&(j.current.value="")}catch(S){p.error(S.message??"Falha ao extrair áudio")}finally{f(!1)}},l=r.data??[];return e.jsxs("div",{className:"space-y-4",children:[e.jsx(F,{children:e.jsxs(I,{className:"p-4 space-y-3",children:[e.jsxs("div",{children:[e.jsx(R,{children:"Nome da amostra (opcional)"}),e.jsx(K,{value:h,onChange:s=>d(s.target.value),placeholder:'Ex: "Minha voz oficial", "Voz cansada"',maxLength:80})]}),e.jsxs(qe,{defaultValue:"record",children:[e.jsxs(Oe,{children:[e.jsxs(q,{value:"record",children:[e.jsx(Ge,{className:"h-4 w-4 mr-1"}),"Gravar agora"]}),e.jsxs(q,{value:"audio",children:[e.jsx(ra,{className:"h-4 w-4 mr-1"}),"Enviar áudio"]}),e.jsxs(q,{value:"video",children:[e.jsx(be,{className:"h-4 w-4 mr-1"}),"Extrair de vídeo"]})]}),e.jsxs(O,{value:"record",className:"space-y-3 pt-3",children:[e.jsx(ua,{onReady:s=>
1u(s),maxSeconds:ne}),e.jsxs(V,{onClick:b,disabled:!n||w,children:[w?e.jsx(de,{className:"h-4 w-4 animate-spin mr-1"}):null,"Salvar no Banco de Voz"]})]}),e.jsxs(O,{value:"audio",className:"space-y-2 pt-3",children:[e.jsxs(R,{children:["Arquivo de áudio (",ce.join(", "),")"]}),e.jsx(K,{ref:g,type:"file",accept:ce.map(s=>"."+s).join(",")+",audio/*",disabled:w,onChange:s=>{var N;return o(((N=s.target.files)==null?void 0:N[0])??null)}}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Recomendado: ",re," a ",ne," segundos, voz limpa, sem música ao fundo."]})]}),e.jsxs(O,{value:"video",className:"space-y-2 pt-3",children:[e.jsxs(R,{children:["Arquivo de vídeo (",le.join(", "),")"]}),e.jsx(K,{ref:j,type:"file",accept:le.map(s=>"."+s).join(",")+",video/*",disabled:w,onChange:s=>{var N;return m(((N=s.target.files)==null?void 0:N[0])??null)}}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"O áudio é extraído no seu navegador. O vídeo não é enviado: salvamos só o áudio limpo (WAV mono 16kHz). Se o vídeo for muito grande ou com codec exótico (.mov com HEVC), exporte como MP4 antes."})]})]})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Suas amostras"}),r.isLoading&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Carregando..."}),!r.isLoading&&l.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Nenhuma amostra ainda. Adicione a primeira acima."}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-2",children:l.map(s=>e.jsx(pa,{sample:s,onDelete:()=>v.mutate(s)},s.id))})]})]})}function pa({sample:r,onDelete:i}){const[v,h]=t.useState(!1),d=t.useRef(null),n=()=>{r.signed_url&&(d.current||(d.current=new Audio(r.signed_url),d.current.onended=()=>h(!1)),v?(d.current.pause(),h(!1)):(d.current.play(),h(!0)))},u={recorded:"Gravado",uploaded_audio:"Áudio enviado",extracted_video:"Extraído de vídeo"};return e.jsx(F,{children:e.jsxs(I,{className:"p-3 flex items-center gap-3",children:[e.jsx(V,{size:"icon",variant:"outline",onClick:n,className:"h-9 w-9 shrink-0",children:e.jsx(na,{className:`h-4 w-4 ${v?"text-primary":""}`})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm truncate",children:r.name}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(ye,{variant:"outline",className:"text-[10px]",children:u[r.source]}),e.jsx("span",{children:xa(r.duration_s)}),e.jsxs("span",{children:["· ",new Date(r.created_at).toLocaleDateString("pt-BR")]})]})]}),e.jsx(V,{size:"icon",variant:"ghost",onClick:i,className:"h-8 w-8 shrink-0 text-destructive",children:e.jsx(oa,{className:"h-4 w-4"})})]})})}const fa=[{id:"marina-firme",label:"Marina (firme)"},{id:"alice-leve",label:"Alice (leve)"},{id:"lua-narradora",label:"Lua (narradora)"},{id:"bruno-caloroso",label:"Bruno (caloroso)"},{id:"rafa-energetico",label:"Rafa (energético)"},{id:"leo-cinema",label:"Léo (cinema)"}],ja=[{label:"Apresentação executiva",text:"Oi, sou a Marina. Ajudo empresas a usar IA de um jeito prático, do planejamento à execução. Bora conversar?"},{label:"Convite para evento",text:"Tenho um convite especial pra você: nesta quinta, às 20h, vamos abrir os bastidores do nosso método. Garante sua vaga, são limitadas."},{label:"Anúncio de lançamento",text:"Hoje é o dia. Estamos lançando uma nova forma de criar vídeos com seu próprio avatar, em minutos. Já está disponível, vem ver."},{label:"Boas-vindas curto",text:"Que bom te ver por aqui. Em poucos minutos você vai ver como dá pra escalar conteúdo com qualidade de estúdio."}];function Ua(){var Re,Ue,Me,Ve,ke,Ee,ze,Be;const[r,i]=t.useState("avatares"),[v,h]=t.useState([]),[d,n]=t.useState([]),[u,w]=t.useState([]),[f,g]=t.useState(!1),[j,c]=t.useState(""),[b,o]=t.useState(null),[m,l]=t.useState(!1),[s,N]=t.useState(""),[S,X]=t.useState("preset"),[A,P]=t.useState(""),[k,J]=t.useState(""),[Y,G]=t.useState("9:16"),[B,oe]=t.useState(10),[_,U]=t.useState("tts"),[L,ue]=t.useState("marina-firme"),[Q,me]=t.useState(""),W=Qe(),[T,he]=t.useState(""),[xe,We]=t.useState(""),[Se,_e]=t.useState(!1),[E,ve]=t.useState(null),[Ce,Ae]=t.useState(!1),H=async()=>{g(!0);const{data:{user:a}}=await y.auth.getUser();if(!a){g(!1);return}const[x,C,z]=await Promise.all([y.from("user_avatars").select("*").eq("user_id",a.id).order("created_at",{ascending:!1}),y.from("avatar_scene_presets").select("*").eq("active",!0).order("sort_order"),y.from("avatar_scenes").select("*").eq("user_id",a.id).order("created_at",{ascending:!1}).limit(20)]);h(x.data??[]),n(C.data??[]),w(z.data??[]),g(!1)};t.useEffect(()=>{(async()=>await H())()},[]),t.useEffect(()=>{u.filter(x=>x.status==="running").forEach(x=>pe(x.id))},[u.length]);const He=async()=>
1{if(!j.trim()||!b){p.error("Nome e arquivo são obrigatórios");return}l(!0);try{const{data:{user:a}}=await y.auth.getUser();if(!a)throw new Error("not_authenticated");const x=b.name.split(".").pop()??"bin",C=`${a.id}/sources/${Date.now()}.${x}`,{error:z}=await y.storage.from("avatars").upload(C,b,{upsert:!1});if(z)throw z;const M=b.type.startsWith("video/")?"clip":"photo",{data:$,error:Z}=await y.functions.invoke("avatar-create",{body:{name:j.trim(),source_type:M,source_path:C}});if(Z)throw Z;p.success(`Avatar "${$.avatar.name}" criado`),c(""),o(null),await H()}catch(a){p.error("Falha ao criar avatar: "+(a.message??"erro"))}finally{l(!1)}},Ke=async()=>{if(!s||!T.trim()){p.error("Escolha avatar e escreva o roteiro");return}if(S==="preset"&&!A){p.error("Escolha um cenário");return}if(S==="custom"&&!k.trim()){p.error("Descreva o cenário");return}ve(null);const a={avatar_id:s,preset_id:S==="preset"?A:null,custom_scene_prompt:S==="custom"?k:null,ratio:Y,duration_s:B,voice_mode:_,voice_id:_==="tts"?L:null,script_text:T},{data:x,error:C}=await y.functions.invoke("avatar-scene-plan",{body:a});if(C){p.error("Pré-análise falhou");return}ve(x),p.success("Pré-análise concluída (gratuita)")},Xe=async()=>{if(!E){p.error("Faça a pré-análise primeiro");return}Ae(!0);try{const{data:{user:a}}=await y.auth.getUser();if(!a)throw new Error("not_authenticated");let x=null;if(_==="user_audio"){if(!Q)throw new Error("Selecione uma amostra do Banco de Voz");const $=await W.sign(Q);if(!$)throw new Error("Não foi possível assinar a amostra");x=$}const{data:C,error:z}=await y.functions.invoke("avatar-scene-run",{body:{avatar_id:s,preset_id:S==="preset"?A:null,custom_scene_prompt:S==="custom"?k:null,ratio:Y,duration_s:B,voice_mode:_,voice_id:_==="tts"?L:null,audio_url:x,script_text:T}});if(z)throw z;const M=C==null?void 0:C.scene_id;if(!M)throw new Error("Resposta inválida do servidor");p.success("Cena enviada para renderização. Acompanhando..."),ve(null),i("historico"),await H(),pe(M)}catch(a){p.error("Falha ao gerar cena: "+(a.message??"erro"))}finally{Ae(!1)}},pe=a=>{const x=Date.now(),C=12*60*1e3,z=async()=>{if(Date.now()-x>C){p.error("Tempo esgotado acompanhando a cena. Verifique no histórico."),await H();return}try{const{data:M,error:$}=await y.functions.invoke("avatar-scene-status",{body:{scene_id:a}});if($)throw $;const Z=M==null?void 0:M.status;if(Z==="completed"){p.success("Cena pronta!"),await H();return}if(Z==="failed"){p.error("Cena falhou: "+((M==null?void 0:M.error)??"erro")),await H();return}}catch(M){console.warn("poll error",M)}setTimeout(z,5e3)};setTimeout(z,4e3)},Je=a=>{p.info("Retomando acompanhamento..."),pe(a)},Ye=t.useMemo(()=>{const a={};for(const x of d)a[x.family]=a[x.family]??[],a[x.family].push(x);return a},[d]);return e.jsxs("div",{className:"container mx-auto p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-bold flex items-center gap-2",children:[e.jsx(Pe,{className:"h-7 w-7 text-primary"})," Avatar Studio"]}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Crie seu avatar pessoal e gere cenas cinematográficas em PT-BR. Staff: geração sem cobrança."})]}),e.jsxs(qe,{value:r,onValueChange:i,children:[e.jsxs(Oe,{children:[e.jsxs(q,{value:"avatares",children:[e.jsx(ia,{className:"h-4 w-4 mr-1"}),"Meus Avatares"]}),e.jsxs(q,{value:"banco-voz",children:[e.jsx(ge,{className:"h-4 w-4 mr-1"}),"Banco de Voz"]}),e.jsxs(q,{value:"cenas",children:[e.jsx(be,{className:"h-4 w-4 mr-1"}),"Nova Cena"]}),e.jsx(q,{value:"historico",children:"Histórico"})]}),e.jsxs(O,{value:"avatares",className:"space-y-4",children:[e.jsxs(F,{children:[e.jsx(fe,{children:e.jsx(je,{children:"Criar avatar"})}),e.jsxs(I,{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(R,{children:"Nome do avatar"}),e.jsx(K,{value:j,onChange:a=>c(a.target.value),placeholder:"Ex: Maria executiva",maxLength:60})]}),e.jsxs("div",{children:[e.jsx(R,{children:"Foto frontal (jpg/png) ou clipe curto (mp4, ate 8s)"}),e.jsx(K,{type:"file",accept:"image/jpeg,image/png,video/mp4",onChange:a=>{var x;return o(((x=a.target.files)==null?void 0:x[0])??null)}})]}),e.jsxs(V,{onClick:He,disabled:m,children:[m?e.jsx(de,{className:"h-4 w-4 animate-spin mr-1"}):e.jsx(ca,{className:"h-4 w-4 mr-1"}),"Criar avatar"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[v.map(a=>e.jsxs(F,{className:"overflow-hidden",children:[a.preview_url&&e.jsx("div",{className:"aspect-square bg-muted",children:e.jsx("img",{src:a.preview_url,alt:a.name,className:"w-full h-full object-cover"})}),e.jsxs(I,{className:"p-3",children:[e.jsx("div",{className:"font-medium truncate",children:a.name}),e.jsx(ye,{variant:"outline",className:"mt-1 text-xs",children:a.status})]})]},a.id)),!v.length&&!f&&e.jsx("p",{className:"col-span-full text-sm text-muted-foreground",children:"Nenhum avatar ainda."})]})]}),e.jsx(O,{value:"banco-voz",className:"space-y-4",children:e.jsxs(F,{children:[e.jsx(fe,{children:e.jsx(je,{children:"Banco de Voz"})}),e.jsxs(I,{children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Salve amostras da sua voz para reutilizar nas cenas. Você pode gravar agora, enviar um arquivo de áudio (mp3, wav, m4a...) ou subir um vídeo (.mov, .mp4, .webm) e o áudio é extraído automaticamente no seu navegador."}),e.jsx(va,{})]})]})}),e.jsx(O,{value:"cenas",className:"space-y-4",children:e.jsxs(F,{children:[e.jsx(fe,{children:e.jsx(je,{children:"Nova cena"})}),e.jsxs(I,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:[e.jsxs("div",{children:[e.jsx(R,{children:"Avatar"}),e.jsxs(ee,{value:s,onValueChange:N,children:[e.jsx(ae,{children:e.jsx(se,{placeholder:"Escolha o avatar"})}),e.jsx(te,{children:v.map(a=>e.jsx(D,{value:a.id,children:a.name},a.id))})]})]}),e.jsxs("div",{children:[e.jsx(R,{children:"Formato"}),e.jsxs(ee,{value:Y,onValueChange:a=>G(a),children:[e.jsx(ae,{children:e.jsx(se,{})}),e.jsxs(te,{children:[e.jsx(D,{value:"9:16",children:"Vertical 9:16"}),e.jsx(D,{value:"16:9",children:"Horizontal 16:9"}),e.jsx(D,{value:"1:1",children:"Quadrado 1:1"})]})]})]}),e.jsxs("div",{children:[e.jsx(R,{children:"Duração"}),e.jsxs(ee,{value:String(B),onValueChange:a=>oe(parseInt(a)),children:[e.jsx(ae,{children:e.jsx(se,{})}),e.jsx(te,{children:[5,10,15,20].map(a=>e.jsxs(D,{value:String(a),children:[a,"s"]},a))})]})]})]}),e.jsxs("div",{children:[e.jsx(R,{children:"Cenário"}),e.jsxs(Ie,{value:S,onValueChange:a=>X(a),className:"flex gap-4 my-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ie,{value:"preset",id:"r-preset"}),e.jsx(R,{htmlFor:"r-preset",children:"Cenário pronto"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ie,{value:"custom",id:"r-custom"}),e.jsx(R,{htmlFor:"r-custom",children:"Descrever"})]})]}),S==="preset"?e.jsx("div",{className:"space-y-3",children:Object.entries(Ye).map(([a,x])=>e.jsxs("div",{children:[e.jsx("div",{className:"text-xs uppercase text-muted-foreground mb-1",children:a}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2",children:x.map(C=>e.jsx("button",{type:"button",onClick:()=>P(C.id),className:`text-left p-2 rounded border text-sm ${A===C.id?"border-primary bg-primary/10":"border-border"}`,children:C.name},C.id))})]},a))}):e.jsx(Fe,{value:k,onChange:a=>J(a.target.value),placeholder:"Ex: terraço de hotel ao pôr do sol, vista para Manhattan, luz dourada cinematográfica",maxLength:800,rows:3})]}),e.jsxs("div",{children:[e.jsx(R,{children:"Voz"}),e.jsxs(Ie,{value:_,onValueChange:a=>U(a),className:"flex gap-4 my-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ie,{value:"tts",id:"v-tts"}),e.jsx(R,{htmlFor:"v-tts",children:"Voz IA"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ie,{value:"user_audio",id:"v-user"}),e.jsx(R,{htmlFor:"v-user",children:"Minha voz"})]})]}),_==="tts"?e.jsxs(ee,{value:L,onValueChange:ue,children:[e.jsx(ae,{children:e.jsx(se,{})}),e.jsx(te,{children:fa.map(a=>e.jsx(D,{value:a.id,children:a.label},a.id))})]}):e.jsx("div",{className:"space-y-2",children:W.list.isLoading?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Carregando suas amostras..."}):(W.list.data??[]).length===0?e.jsxs("div",{className:"text-sm text-muted-foreground border border-dashed border-border rounded p-3",children:["Você ainda não tem amostras no Banco de Voz. Abra a aba ",e.jsx("strong",{children:"Banco de Voz"})," para gravar, enviar um áudio ou extrair de um vídeo (.mov, .mp4...).",e.jsxs(V,{variant:"outline",size:"sm",className:"ml-2",onClick:()=>i("banco-voz"),children:[e.jsx(ge,{className:"h-3 w-3 mr-1"}),"Abrir Banco de Voz"]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(ee,{value:Q,onValueChange:me,children:[e.jsx(ae,{children:e.jsx(se,{placeholder:"Escolha uma amostra do seu Banco de Voz"})}),e.jsx(te,{children:(W.list.data??[]).map(a=>e.jsxs(D,{value:a.id,children:[a.name," ",a.duration_s?`· ${Math.round(a.duration_s)}s`:""]},a.id))})]}),e.jsxs(V,{variant:"ghost",size:"sm",onClick:()=>i("banco-voz"),children:[e.jsx(ge,{className:"h-3 w-3 mr-1"}),"Gerenciar Banco de Voz"]})]})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(R,{children:"Roteiro (PT-B
1R)"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"text-xs text-muted-foreground mr-1",children:"Usar exemplo:"}),ja.map(a=>e.jsx("button",{type:"button",onClick:()=>{T.trim()&&!confirm("Substituir o roteiro atual?")||(he(a.text),p.success("Exemplo aplicado, edite à vontade"))},className:"text-xs px-2 py-1 rounded-full border border-border hover:bg-accent transition-colors",children:a.label},a.label))]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(K,{value:xe,onChange:a=>We(a.target.value),placeholder:"Ou descreva uma ideia (ex: convidar pra masterclass de IA quinta às 20h)",maxLength:200}),e.jsxs(V,{type:"button",variant:"outline",disabled:Se||xe.trim().length<3,onClick:async()=>{if(!(T.trim()&&!confirm("Substituir o roteiro atual?"))){_e(!0);try{const{data:a,error:x}=await y.functions.invoke("studio-generate-narration-script",{body:{idea:xe.trim(),duration_s:B,language:"pt-BR"}});if(x||a!=null&&a.error){p.error((a==null?void 0:a.message)||(x==null?void 0:x.message)||"Falha ao gerar roteiro");return}he(a.script||""),p.success("Roteiro pronto, edite à vontade")}catch(a){p.error("Falha ao gerar roteiro: "+(a.message??"erro"))}finally{_e(!1)}}},children:[Se?e.jsx(de,{className:"h-4 w-4 animate-spin mr-1"}):e.jsx(Pe,{className:"h-4 w-4 mr-1"}),"Gerar com IA"]})]}),e.jsx(Fe,{value:T,onChange:a=>he(a.target.value),rows:4,maxLength:2e3,placeholder:"O que o avatar vai dizer?"}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:[T.length," / 2000 caracteres"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(V,{variant:"outline",onClick:Ke,children:"Pré-analisar (grátis)"}),e.jsxs(V,{onClick:Xe,disabled:Ce||!E,children:[Ce?e.jsx(de,{className:"h-4 w-4 animate-spin mr-1"}):e.jsx(be,{className:"h-4 w-4 mr-1"}),"Gerar cena"]})]}),E&&e.jsx(F,{className:"bg-muted/40",children:e.jsxs(I,{className:"p-4 space-y-1 text-sm",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"Avatar:"})," ",(Re=E.summary)==null?void 0:Re.avatar_name]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Cenário:"})," ",(Ue=E.summary)==null?void 0:Ue.scene_label]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Voz:"})," ",(Ve=(Me=E.summary)==null?void 0:Me.voice)==null?void 0:Ve.label]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Duração:"})," ",(ke=E.estimate)==null?void 0:ke.duration_s,"s"]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Custo estimado:"})," ",(Ee=E.estimate)!=null&&Ee.is_staff?"Sem cobrança (staff)":`${(ze=E.estimate)==null?void 0:ze.otc_cost} OTC`]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Motor:"})," ",(Be=E.summary)==null?void 0:Be.engine_label]})]})})]})]})}),e.jsxs(O,{value:"historico",className:"space-y-3",children:[u.map(a=>{var x;return e.jsx(F,{children:e.jsxs(I,{className:"p-4 flex gap-4 items-start",children:[a.video_url&&e.jsx("video",{src:a.video_url,controls:!0,className:"w-48 rounded"}),e.jsxs("div",{className:"flex-1 space-y-1 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(ye,{variant:a.status==="failed"?"destructive":a.status==="completed"?"default":"secondary",children:a.status}),e.jsxs("span",{children:["· ",a.duration_s,"s · ",new Date(a.created_at).toLocaleString("pt-BR")]}),a.status==="running"&&e.jsxs(V,{size:"sm",variant:"outline",onClick:()=>Je(a.id),className:"ml-2 h-7",children:[e.jsx(la,{className:"h-3 w-3 mr-1"})," Retomar acompanhamento"]})]}),((x=a.tech_stack)==null?void 0:x.engine_label)&&e.jsx("div",{className:"text-muted-foreground",children:a.tech_stack.engine_label}),a.status==="failed"&&a.error&&e.jsxs("div",{className:"text-destructive text-xs break-words",children:["Erro: ",a.error]})]})]})},a.id)}),!u.length&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Nenhuma cena ainda."})]})]})]})}export{Ua as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.