1import{r as n,j as e}from"./framer-motion-CQxuJa5n.js";import{u as re,b as ae,M as ee,G as q,C as z,f as G,g as H,h as J,i as Z,j as se,I as pe,p as k,B as x,s as p,ae as ne,K as $,Z as Ae,D as Be,z as Le,ac as Fe,R as De,n as Pe,x as Re,A as Ke}from"./index-CSx7K-7R.js";import{C as We,a as Ue,b as $e}from"./collapsible-VrVLN1fc.js";import{B as te}from"./badge-Yar_qzGV.js";import{A as L,a as F}from"./alert-DDlZdiu2.js";import{P as ve}from"./progress-xZI-P8gz.js";import{P as X}from"./phone-DfeYL_-y.js";import{L as Oe}from"./lock-CwA9FnEu.js";import{C}from"./circle-check-big-BvOaTfBT.js";import{C as O}from"./circle-x-Bjw_qpIQ.js";import{S as Me}from"./save-DeKktgg2.js";import{G as fe}from"./globe-B3q7zUSQ.js";import{C as I}from"./circle-play-DRSMpigj.js";import{S as qe}from"./settings-ClDRCqQC.js";import{A as M}from"./arrow-right-Q4CCUTFT.js";import{V as je}from"./volume-2-CRS5fxmT.js";import{R as ze}from"./radio-CEdjniLT.js";import{C as Ge}from"./chevron-up-fhR0nOsN.js";import{C as be}from"./chevron-down-DvU9LH4D.js";import{C as xe}from"./copy-B5YKNs8h.js";import"./recharts-CFjfazL9.js";import"./index-oMQApiRp.js";function He({agentId:a,agentName:_,disabled:u,onSuccess:l}){const v=re(),{toast:W}=ae(),[o,w]=n.useState("idle"),[D,j]=n.useState(null),[m,T]=n.useState(null),[y,b]=n.useState(_||""),P=[{id:"twilio",label:"Twilio Webhook",icon:e.jsx(X,{className:"h-4 w-4"}),status:o==="verifying-twilio"?"active":m?.twilio?.status==="pass"?"pass":m?.twilio?.status==="fail"?"fail":"pending"},{id:"elevenlabs",label:"ElevenLabs",icon:e.jsx(ee,{className:"h-4 w-4"}),status:o==="verifying-elevenlabs"?"active":m?.elevenlabs?.status==="pass"?"pass":m?.elevenlabs?.status==="fail"?"fail":"pending"},{id:"brain",label:"Brain",icon:e.jsx(q,{className:"h-4 w-4"}),status:o==="verifying-brain"?"active":m?.brain?.status==="pass"?"pass":m?.brain?.status==="fail"?"fail":"pending"}],E=async()=>{if(!y.trim()){j("Agent navn er pÃ¥krævet");return}w("saving"),j(null),T(null);const c=crypto.randomUUID();try{y.trim()&&await p.from("voice_agents").update({name:y.trim()}).eq("id",a),w("verifying-twilio"),await new Promise(f=>setTimeout(f,500)),w("verifying-elevenlabs"),await new Promise(f=>setTimeout(f,500)),w("verifying-brain");const{data:h,error:g}=await p.functions.invoke("finalize-agent-setup",{body:{agent_id:a,operation_id:c,build_version:ne}});if(g)throw g;h?.success?(w("success"),T(h.verification_result),W({title:"â Agent gemt og aktiveret!",description:`Snapshot v${h.version} oprettet`}),setTimeout(()=>{l?.(h.snapshot_id),v(`/voice-agent/${a}`)},1500)):(w("error"),j(h?.error||"Ukendt fejl"),T(h?.verification_result))}catch(h){console.error("Save error:",h),w("error"),j(h.message||"Kunne ikke gemme agent")}},R=()=>{switch(o){case"saving":return 10;case"verifying-twilio":return 30;case"verifying-elevenlabs":return 60;case"verifying-brain":return 85;case"success":return 100;default:return 0}},N=y.trim().length>0,S=()=>{switch(o){case"saving":return e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"h-4 w-4 mr-2 animate-spin"}),"Gemmer konfiguration..."]});case"verifying-twilio":return e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"h-4 w-4 mr-2 animate-spin"}),"Verificerer Twilio..."]});case"verifying-elevenlabs":return e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"h-4 w-4 mr-2 animate-spin"}),"Verificerer ElevenLabs..."]});case"verifying-brain":return e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"h-4 w-4 mr-2 animate-spin"}),"Verificerer Brain..."]});case"success":return e.jsxs(e.Fragment,{children:[e.jsx(C,{className:"h-4 w-4 mr-2"}),"Gemt!"]});case"error":return e.jsxs(e.Fragment,{children:[e.jsx(O,{className:"h-4 w-4 mr-2"}),"Prøv igen"]});default:return e.jsxs(e.Fragment,{children:[e.jsx(Me,{className:"h-4 w-4 mr-2"}),"Gem & Aktivér Agent"]})}},i=["saving","verifying-twilio","verifying-elevenlabs","verifying-brain"].includes(o);return e.jsxs(z,{className:"border-primary/50",children:[e.jsxs(G,{children:[e.jsxs(H,{
1className:"flex items-center gap-2",children:[e.jsx(Oe,{className:"h-5 w-5"}),"Gem & Aktivér Agent"]}),e.jsx(J,{children:"Dette vil lÃ¥se konfigurationen, verificere alle integrationer og aktivere agenten for opkald."})]}),e.jsxs(Z,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(se,{htmlFor:"agent-name",children:"Agent Navn *"}),e.jsx(pe,{id:"agent-name",value:y,onChange:c=>b(c.target.value),placeholder:"Giv din agent et navn...",disabled:i}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Dette navn vil vises i dashboardet og bruges til at identificere agenten."})]}),e.jsxs("div",{className:"text-sm text-muted-foreground space-y-1",children:[e.jsx("p",{children:"â LÃ¥ser den nuværende konfiguration"}),e.jsx("p",{children:"â Verificerer Twilio webhook"}),e.jsx("p",{children:"â Verificerer ElevenLabs integration"}),e.jsx("p",{children:"â Verificerer Brain endpoint"}),e.jsx("p",{children:"â Aktiverer agenten for opkald"})]}),i&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(ve,{value:R()}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:P.map(c=>e.jsxs("div",{className:`flex items-center gap-2 text-sm ${c.status==="active"?"text-primary font-medium":c.status==="pass"?"text-accent-foreground":c.status==="fail"?"text-destructive":"text-muted-foreground"}`,children:[c.status==="active"&&e.jsx(k,{className:"h-4 w-4 animate-spin"}),c.status==="pass"&&e.jsx(C,{className:"h-4 w-4"}),c.status==="fail"&&e.jsx(O,{className:"h-4 w-4"}),c.status==="pending"&&c.icon,e.jsx("span",{children:c.label})]},c.id))})]}),o==="success"&&e.jsxs(L,{className:"border-accent-foreground bg-accent/10",children:[e.jsx(C,{className:"h-4 w-4 text-accent-foreground"}),e.jsx(F,{children:"Agent er nu gemt og aktiveret! Du bliver omdirigeret til agent-oversigten..."})]}),o==="error"&&D&&e.jsxs(L,{variant:"destructive",children:[e.jsx(O,{className:"h-4 w-4"}),e.jsxs(F,{children:[D,m&&e.jsxs("div",{className:"mt-2 text-xs",children:[e.jsxs("p",{children:["Twilio: ",m.twilio?.status]}),e.jsxs("p",{children:["ElevenLabs: ",m.elevenlabs?.status]}),e.jsxs("p",{children:["Brain: ",m.brain?.status]})]})]})]}),e.jsx(x,{onClick:E,disabled:u||i||!N,size:"lg",className:"w-full",variant:o==="error"?"destructive":"default",children:S()}),!N&&o==="idle"&&e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:"Indtast et agent navn for at fortsætte"})]})]})}function Je({agentId:a,onComplete:_}){re();const{toast:u}=ae(),[l,v]=n.useState(0),[W,o]=n.useState(!1),[w,D]=n.useState(null);n.useEffect(()=>{console.log("ManualSetupFlow v2 loaded",ne)},[]);const[j,m]=n.useState(""),[T,y]=n.useState(!1),[b,P]=n.useState(null),[E,R]=n.useState([]),[N,S]=n.useState(""),[i,c]=n.useState(!1),[h,g]=n.useState(!1),[f,r]=n.useState(!1),[V,A]=n.useState(!1),[ie,le]=n.useState(!1),[Q,ce]=n.useState(!1),[oe,de]=n.useState(!1),[Y,we]=n.useState(!1),B=[{id:"website",title:"1. Website/Viden",description:"Scan virksomhedens hjemmeside",icon:e.jsx(fe,{className:"h-5 w-5"}),status:b?"complete":l===0?"active":"pending",details:b?`${b.pages} sider, ${b.words} ord`:void 0},{id:"twilio",title:"2. Telefon",description:"Tilslut og konfigurer nummer",icon:e.jsx(X,{className:"h-5 w-5"}),status:h?"complete":l===1?"active":"pending",details:h?"Webhook verificeret â":void 0},{id:"elevenlabs",title:"3. Stemme",description:"Vælg og test stemme",icon:e.jsx(ee,{className:"h-5 w-5"}),status:V?"complete":l===2?"active":"pending",details:V?"TTS test bestÃ¥et â":void 0},{id:"brain",title:"4. Hjerne",description:"Konfigurer AI-model",icon:e.jsx(q,{className:"h-5 w-5"}),status:Q?"complete":l===3?"active":"pending",details:Q?"Brain konfigureret â":void 0},{id:"verify",title:"5. Verificer",description:"Test hele pipelinen",icon:e.jsx(I,{className:"h-5 w-5"}),status:Y?"complete":l===4?"active":"pending",details:Y?"Alle tests bestÃ¥et â":void 0}];n.useEffect(()=>{async function s(){const{data:t}=await p.from("voice_agents").select("*").eq("id",a).single();if(t){if(D(t),m(t.url||""),t.scraped_content){const d=typeof t.scraped_content=="object"?t.scraped_content.content:t.scraped_content;if(d&&d.length>100){const K=d.split(/\s+/).length;P({pages:1,words:K}),v(1)}}if(t.phone_number&&S(t.phone_number),t.custom_llm_enabled){const{data:d}=await p.rpc("check_agent_brain_token",{p_agent_id:a});d&&ce(!0)}}}s()},[a]),n.useEffect(()=>{async function s(){const{data:t}=await p.rpc("get_user_phone_numbers");t&&(R(t),t.find(K=>K.voice_agent_id===a)?.webhook_configured&&(g(!0),l<2&&v(2)))}s()},[a]);const Ne=async()=>
1{if(!j.trim()){u({title:"Indtast en URL",variant:"destructive"});return}y(!0);try{await p.from("voice_agents").update({url:j}).eq("id",a);const{data:s,error:t}=await p.functions.invoke("deep-url-scan",{body:{url:j,agentId:a,maxPages:20}});if(t)throw t;if(s?.success)P({pages:s.pages_crawled||1,words:s.word_count||s.total_words||0}),v(1),u({title:`â Scannet ${s.pages_crawled||1} sider`});else throw new Error(s?.error||"Scanning fejlede")}catch(s){console.error("Scan error:",s),u({title:"Scanning fejlede",description:s.message,variant:"destructive"})}finally{y(!1)}},ke=async()=>{if(!N){u({title:"Vælg et telefonnummer",variant:"destructive"});return}const s=E.find(t=>t.phone_number===N);if(!s?.twilio_phone_sid){u({title:"Telefonnummer mangler Twilio SID",variant:"destructive"});return}c(!0);try{const{data:t,error:d}=await p.functions.invoke("bind-phone-to-agent",{body:{agent_id:a,phone_sid:s.twilio_phone_sid,e164:N}});if(d)throw d;if(t?.verified)g(!0),v(2),u({title:"â Webhook konfigureret og verificeret"});else throw new Error(t?.error||"Webhook verifikation fejlede")}catch(t){console.error("Webhook error:",t),u({title:"Webhook konfiguration fejlede",description:t.message,variant:"destructive"})}finally{c(!1)}},ye=async()=>{r(!0);try{const{data:s,error:t}=await p.functions.invoke("sync-elevenlabs-agent",{body:{agentId:a,forceRecreate:!1}});if(t)throw t;if(s?.success)A(!0),v(3),u({title:"â ElevenLabs synkroniseret"});else throw new Error(s?.error||"ElevenLabs sync fejlede")}catch(s){console.error("TTS test error:",s),u({title:"TTS test fejlede",description:s.message,variant:"destructive"})}finally{r(!1)}},_e=async()=>{le(!0);try{const{data:s,error:t}=await p.from("voice_agents").select("brain_token, custom_llm_enabled, system_prompt, first_message, name").eq("id",a).single();if(t||!s)throw new Error("Kunne ikke hente agent");const d={};if(s.brain_token||(d.brain_token=crypto.randomUUID().replace(/-/g,"")+crypto.randomUUID().replace(/-/g,"")),s.custom_llm_enabled||(d.custom_llm_enabled=!0),(!s.system_prompt||s.system_prompt.length<50)&&(d.system_prompt=`Du er en venlig og professionel AI-assistent for ${s.name}. 2Du hjælper kunder med spørgsmÃ¥l om virksomheden, produkter og services. 3Vær altid høflig, præcis og hjælpsom. 4Hvis du ikke kender svaret, sÃ¥ sig det ærligt og tilbyd at sende kunden videre til en medarbejder.`),s.first_message||(d.first_message=`Hej, du har ringet til ${s.name}. Hvad kan jeg hjælpe dig med?`),Object.keys(d).length>0){d.updated_at=new Date().toISOString();const{error:ge}=await p.from("voice_agents").update(d).eq("id",a);if(ge)throw new Error(`Kunne ikke opdatere agent: ${ge.message}`)}const{data:K,error:he}=await p.functions.invoke("sync-elevenlabs-agent",{body:{agentId:a,forceRecreate:!1}});if(he||!K?.success)throw new Error(he?.message||K?.error||"Kunne ikke synkronisere brain til stemmeagenten");const{data:U,error:Ee}=await p.functions.invoke("test-voice-agent-setup",{body:{agentId:a}}),Ve=U?.success===!0&&U?.checks?.has_brain_token===!0&&U?.checks?.elevenlabs_uses_custom_llm===!0&&U?.checks?.voice_brain_responds===!0;if(Ee||!Ve)throw new Error(U?.message||"Brain/stemme binding er ikke komplet endnu. Prøv igen.");ce(!0),v(4),u({title:"â Brain konfigureret og synkroniseret"})}catch(s){console.error("Brain config error:",s),u({title:"Brain konfiguration fejlede",description:s.message,variant:"destructive"})}finally{le(!1)}},Se=async()=>{de(!0);try{const{data:s,error:t}=await p.functions.invoke("test-voice-agent-setup",{body:{agentId:a}});if(t)throw t;if(s?.success)we(!0),u({title:"â Alle kritiske checks bestÃ¥et!"}),_?.();else{const d=Array.isArray(s?.recommendations)?s.recommendations.slice(0,2).join(" · "):null;throw new Error(d||s?.message||s?.error||"Verifikation fejlede")}}catch(s){console.error("Verification error:",s),u({title:"Verifikation fejlede",description:s.message,variant:"destructive"})}finally{de(!1)}},Ce=s=>{switch(s){case"complete":return"text-accent-foreground";case"active":return"text-primary";case"error":return"text-destructive";case"warning":return"text-warning";default:return"text-muted-foreground"}},Te=s=>{switch(s){case"complete":return e.jsx(C,{className:"h-5 w-5 text-accent-foreground"});case"error":return e.jsx(O,{className:"h-5 w-5 text-destructive"});case"warning":return e.jsx(Fe,{className:"h-5 w-5 text-warning"});default:return null}},me=B.filter(s=>s.status==="complete").length,ue=me/B.length*100;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs(z,{children:[e.jsxs(G,{children:[e.jsxs(H,{
4className:"flex items-center gap-2",children:[e.jsx(qe,{className:"h-5 w-5"}),"Manuel Opsætning"]}),e.jsx(J,{children:"Følg disse trin i rækkefølge for at konfigurere din agent"})]}),e.jsxs(Z,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{children:[me," af ",B.length," trin fuldført"]}),e.jsxs("span",{children:[Math.round(ue),"%"]})]}),e.jsx(ve,{value:ue})]}),e.jsx("div",{className:"flex justify-between mt-4",children:B.map((s,t)=>e.jsxs("div",{className:$("flex flex-col items-center gap-1 text-center flex-1",Ce(s.status)),children:[e.jsx("div",{className:$("w-10 h-10 rounded-full border-2 flex items-center justify-center",s.status==="complete"&&"bg-accent border-accent",s.status==="active"&&"bg-primary/10 border-primary",s.status==="pending"&&"border-muted"),children:Te(s.status)||s.icon}),e.jsx("span",{className:"text-xs font-medium",children:s.title.split(".")[0]})]},s.id))})]})]}),e.jsxs(z,{className:"border-primary",children:[e.jsxs(G,{children:[e.jsxs(H,{
4className:"flex items-center gap-2",children:[B[l]?.icon,B[l]?.title]}),e.jsx(J,{children:B[l]?.description})]}),e.jsxs(Z,{children:[l===0&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(se,{htmlFor:"url",children:"Virksomhedens hjemmeside"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(pe,{id:"url",type:"url",placeholder:"https://www.dinvirksomhed.dk",value:j,onChange:s=>m(s.target.value)}),e.jsx(x,{onClick:Ne,disabled:T||!j.trim(),children:T?e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"h-4 w-4 mr-2 animate-spin"}),"Scanner..."]}):e.jsxs(e.Fragment,{children:[e.jsx(fe,{className:"h-4 w-4 mr-2"}),"Scan"]})})]})]}),b&&e.jsxs(L,{className:"border-accent",children:[e.jsx(C,{className:"h-4 w-4"}),e.jsxs(F,{children:["â Bekræftet URL: ",j,e.jsx("br",{}),b.pages," sider scannet, ",b.words.toLocaleString()," ord indlæst"]})]}),b&&e.jsxs(x,{onClick:()=>v(1),children:["Fortsæt til Telefon",e.jsx(M,{className:"h-4 w-4 ml-2"})]})]}),l===1&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(se,{children:"Vælg telefonnummer"}),e.jsx("div",{className:"grid gap-2",children:E.filter(s=>!s.voice_agent_id||s.voice_agent_id===a).map(s=>e.jsx("div",{className:$("p-3 border rounded-lg cursor-pointer transition-colors",N===s.phone_number?"border-primary bg-primary/5":"hover:border-muted-foreground"),onClick:()=>S(s.phone_number),children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(X,{className:"h-4 w-4"}),e.jsx("span",{className:"font-mono",children:s.phone_number})]}),s.webhook_configured&&e.jsxs(te,{variant:"outline",className:"text-green-500",children:[e.jsx(C,{className:"h-3 w-3 mr-1"}),"Webhook OK"]})]})},s.id))})]}),e.jsx(x,{onClick:ke,disabled:i||!N,className:"w-full",children:i?e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"h-4 w-4 mr-2 animate-spin"}),"Konfigurerer webhook..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ae,{className:"h-4 w-4 mr-2"}),"Anvend Webhook + Verificer"]})}),h&&e.jsxs(x,{onClick:()=>v(2),children:["Fortsæt til Stemme",e.jsx(M,{className:"h-4 w-4 ml-2"})]})]}),l===2&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(L,{children:[e.jsx(ee,{className:"h-4 w-4"}),e.jsx(F,{children:"Dette trin synkroniserer din agent med ElevenLabs og tester at TTS virker."})]}),e.jsx(x,{onClick:ye,disabled:f,className:"w-full",children:f?e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"h-4 w-4 mr-2 animate-spin"}),"Synkroniserer..."]}):e.jsxs(e.Fragment,{children:[e.jsx(je,{className:"h-4 w-4 mr-2"}),"Synkroniser & Test TTS"]})}),V&&e.jsxs(x,{onClick:()=>v(3),children:["Fortsæt til Hjerne",e.jsx(M,{className:"h-4 w-4 ml-2"})]})]}),l===3&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(L,{children:[e.jsx(q,{className:"h-4 w-4"}),e.jsx(F,{children:"Dette trin sikrer at brain token er genereret og Custom LLM er aktiveret."})]}),e.jsx(x,{onClick:_e,disabled:ie,className:"w-full",children:ie?e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"h-4 w-4 mr-2 animate-spin"}),"Konfigurerer..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Be,{className:"h-4 w-4 mr-2"}),"Konfigurer Brain + KB Toggles"]})}),Q&&e.jsxs(x,{onClick:()=>v(4),children:["Fortsæt til Verifikation",e.jsx(M,{className:"h-4 w-4 ml-2"})]})]}),l===4&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(L,{children:[e.jsx(I,{className:"h-4 w-4"}),e.jsx(F,{children:"Kør en fuld test af hele pipelinen: Twilio â ElevenLabs â Brain â Viden"})]}),e.jsx(x,{onClick:Se,disabled:oe,size:"lg",className:"w-full",children:oe?e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"h-4 w-4 mr-2 animate-spin"}),"Verificerer (15 sek)..."]}):e.jsxs(e.Fragment,{children:[e.jsx(I,{className:"h-4 w-4 mr-2"}),"Start Verifikation"]})}),Y&&e.jsxs(e.Fragment,{children:[e.jsxs(L,{className:"border-green-500 bg-green-500/10",children:[e.jsx(C,{className:"h-4 w-4 text-green-500"}),e.jsx(F,{className:"text-green-700",children:"â Alle tests bestÃ¥et! Din agent er klar til brug."})]}),e.jsx(Le,{className:"my-4"}),e.jsx(He,{agentId:a,onSuccess:s=>{console.log("Agent saved with snapshot:",s),_?.()}})]})]})]})]})]})}function Ze({agentId:a,phoneNumber:_,voiceId:u}){const{toast:l}=ae(),[v,W]=n.useState({}
4),[o,w]=n.useState({twilio:null,stream:null,brain:null,tts:null}),[D,j]=n.useState(null),m=async(i,c,h)=>{W(g=>({...g,[i]:!0}));try{const g=Date.now(),{data:f,error:r}=await p.functions.invoke(c,{body:h}),V=Date.now()-g;if(r)throw r;w(A=>({...A,[i]:{...f,latency_ms:V}})),f.success?l({title:`â ${i.toUpperCase()} OK`,description:f.value?`Værdi: ${f.value}`:"Test bestÃ¥et"}):l({title:`â ${i.toUpperCase()} FEJL`,description:f.error||"Test fejlede",variant:"destructive"})}catch(g){w(f=>({...f,[i]:{success:!1,error:g.message||"Uventet fejl"}})),l({title:`Fejl i ${i}`,description:g.message,variant:"destructive"})}finally{W(g=>({...g,[i]:!1}))}},T=()=>m("twilio","diagnostic-test-twilio",{agent_id:a}),y=()=>m("stream","diagnostic-test-stream",{agent_id:a}),b=()=>m("brain","diagnostic-test-brain",{agent_id:a}),P=()=>m("tts","diagnostic-test-tts",{agent_id:a,voice_id:u}),E=o.twilio?.success&&o.stream?.success&&o.brain?.success&&o.tts?.success,R=Object.values(o).some(i=>i&&!i.success),N=async i=>{await navigator.clipboard.writeText(JSON.stringify(i,null,2)),l({title:"Kopieret!",description:"Raw data kopieret til udklipsholder"})},S=({testKey:i,icon:c,title:h,description:g,onTest:f})=>{const r=o[i],V=v[i],A=D===i;return e.jsxs("div",{className:"border rounded-lg overflow-hidden",children:[e.jsx("div",{className:$("p-4 transition-colors",r?.success===!0&&"bg-green-500/10 border-green-500/30",r?.success===!1&&"bg-destructive/10 border-destructive/30",!r&&"bg-card"),children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:$("p-2 rounded-lg",r?.success===!0&&"bg-green-500/20 text-green-600",r?.success===!1&&"bg-destructive/20 text-destructive",!r&&"bg-muted text-muted-foreground"),children:e.jsx(c,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsxs("h4",{className:"font-medium flex items-center gap-2",children:[h,r?.success===!0&&e.jsx(C,{className:"h-4 w-4 text-green-500"}),r?.success===!1&&e.jsx(O,{className:"h-4 w-4 text-destructive"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:g}),r&&e.jsx("div",{className:"mt-2 text-sm",children:r.success?e.jsxs("span",{className:"text-green-600 font-mono",children:["â ",r.value!==void 0?`Værdi: ${r.value}`:"OK",r.latency_ms&&` (${r.latency_ms}ms)`]}):e.jsxs("span",{className:"text-destructive font-mono",children:["â ",r.error]})})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(x,{size:"sm",onClick:f,disabled:V,variant:r?.success?"outline":"default",children:V?e.jsx(k,{className:"h-4 w-4 animate-spin"}):r?e.jsx(De,{className:"h-4 w-4"}):"Test"}),r&&(r.raw_request||r.raw_response)&&e.jsx(x,{size:"sm",variant:"ghost",onClick:()=>j(A?null:i),children:A?e.jsx(Ge,{className:"h-4 w-4"}):e.jsx(be,{className:"h-4 w-4"})})]})]})}),A&&r&&e.jsxs("div",{className:"p-4 bg-muted/50 border-t space-y-3",children:[r.raw_request&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase",children:"Request"}),e.jsx(x,{size:"sm",variant:"ghost",className:"h-6",onClick:()=>N(r.raw_request),children:e.jsx(xe,{className:"h-3 w-3"})})]}),e.jsx("pre",{className:"text-xs font-mono bg-background p-2 rounded border overflow-x-auto max-h-40",children:JSON.stringify(r.raw_request,null,2)})]}),r.raw_response&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase",children:"Response"}),e.jsx(x,{size:"sm",variant:"ghost",className:"h-6",onClick:()=>N(r.raw_response),children:e.jsx(xe,{className:"h-3 w-3"})})]}),e.jsx("pre",{className:"text-xs font-mono bg-background p-2 rounded border overflow-x-auto max-h-40",children:JSON.stringify(r.raw_response,null,2)})]})]})]})};return e.jsxs(z,{children:[e.jsx(G,{children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsxs(H,{
4className:"flex items-center gap-2",children:["ð§ Diagnostik Kontrolpult",E&&e.jsx(te,{className:"bg-green-600",children:"4/4 OK"}),R&&!E&&e.jsxs(te,{variant:"destructive",children:[Object.values(o).filter(i=>i?.success).length,"/4 OK"]})]}),e.jsx(J,{children:"Test hver del af voice pipeline separat. Alle 4 skal være grønne."})]})})}),e.jsxs(Z,{className:"space-y-3",children:[e.jsx(S,{testKey:"twilio",icon:X,title:"1. Twilio â Webhook",description:"Rammer Twilio vores webhook? Vis sidste CallSid",onTest:T}),e.jsx(S,{testKey:"stream",icon:ze,title:"2. Stream â Audio Frames",description:"Modtager vi audio frames? frames_received > 0",onTest:y}),e.jsx(S,{testKey:"brain",icon:q,title:"3. Brain â LLM",description:"Kan vi kalde LLM med tekst? llm_calls_count > 0",onTest:b}),e.jsx(S,{testKey:"tts",icon:je,title:"4. TTS â ElevenLabs",description:"FÃ¥r vi bytes fra ElevenLabs? tts_bytes > 0",onTest:P}),E&&e.jsx("div",{className:"mt-4 p-4 rounded-lg bg-green-500/10 border border-green-500/30",children:e.jsxs("p",{className:"text-sm font-medium text-green-600 flex items-center gap-2",children:[e.jsx(C,{className:"h-5 w-5"}),"Alle 4 tests bestÃ¥et! Voice pipeline er fuldt funktionel."]})}),R&&e.jsx("div",{className:"mt-4 p-4 rounded-lg bg-destructive/10 border border-destructive/30",children:e.jsx("p",{className:"text-sm font-medium text-destructive",children:"â En eller flere tests fejlede. Se raw request/response for debugging."})})]})]})}function vs(){const{id:a}=Pe(),_=re();return n.useEffect(()=>{console.log("[Route] /voice-agent/:id/setup â v2",ne)},[]),n.useEffect(()=>{a||_("/voice-dashboard",{replace:!0})},[a,_]),a?e.jsx(Re,{children:e.jsxs("div",{className:"container max-w-4xl py-6 space-y-6",children:[e.jsxs("header",{className:"flex items-center gap-4",children:[e.jsx(x,{variant:"ghost",size:"icon",onClick:()=>_("/voice-agent/"+a),children:e.jsx(Ke,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Manuel Opsætning (v2)"}),e.jsx("p",{className:"text-muted-foreground",children:"Website â Telefon â ElevenLabs â Brain â Verify"})]})]}),e.jsx(Je,{agentId:a}),e.jsxs(We,{children:[e.jsx(Ue,{asChild:!0,children:e.jsxs(x,{variant:"outline",className:"w-full justify-between",children:["Diagnostik (avanceret)",e.jsx(be,{className:"h-4 w-4"})]})}),e.jsx($e,{className:"pt-4",children:e.jsx(Ze,{agentId:a})})]})]})}):null}export{vs 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.