PageSourceSearch

https://vonvo.ai/assets/ActivationFlow-Cx2EDrzM.js

js vonvo.ai collected 2026-10-05 13:14:03 UTC 24,695 bytes, 1 lines download raw bytes

1import{j as e}from"./vendor-query-DAAv_TEJ.js";import{r as t,u as pe}from"./vendor-react-BahMz3y6.js";import{D as we,C as Q,c as Z,a as $,n as xe,N as Se,T as ke,e as J,s as C,B as P,E as Ce,O as _e,Q as Ie,R as Ae,V as Te,W as fe,Y as Re,S as $e,Z as Ee,u as ze,j as G,$ as De}from"./index-BtJhHOKM.js";import{u as Me}from"./useActivationFlow-ACEuhmxN.js";import{I as Pe}from"./infinity-B7I6Gmpm.js";import{m as Fe}from"./vendor-elevenlabs-Bh_7FvXI.js";import{C as Le,a as Oe,b as Ue}from"./ColdCallIonPanel-CCXQzvcW.js";import{u as qe,L as Ve,T as Be}from"./useAICoach-DoCh2JXt.js";import{A as Ye,T as He}from"./AIAvatar-Cu_Sk7xk.js";import{L as ae}from"./loader-circle-B9gSizFi.js";import{T as We}from"./timer-smeCUoFi.js";import{M as Ge}from"./mic-off-CHuNhFW_.js";import{P as me}from"./phone-off-Do22gxg6.js";import{C as Je}from"./circle-check-big-CDlFowqp.js";import{c as ue}from"./confetti.module-ONDKWxYZ.js";import"./vendor-ui-core-M8iOpbwb.js";import"./vendor-charts-D8mzgm-r.js";import"./vendor-supabase-DsXfWiGW.js";import"./vendor-ui-extra-MYsYsKPI.js";import"./wifi-DbwZXotC.js";import"./copy-CUGS2qMc.js";import"./IonMascot-C13Lpunn.js";import"./bot-Bhs2OUG5.js";import"./send-CB93AqoV.js";import"./circle-check-DmnYgI5W.js";import"./zap-al22T3WF.js";function Qe({onStart:s,totalScenarios:i,currentIndex:o}){return e.jsx("div",{className:"min-h-screen bg-background flex flex-col items-center justify-center p-4",children:e.jsxs("div",{className:"w-full max-w-lg text-center space-y-8",children:[e.jsx("div",{className:"mx-auto w-20 h-20 rounded-2xl bg-gradient-to-br from-primary/20 to-primary/5 flex items-center justify-center",children:e.jsx(we,{className:"w-10 h-10 text-primary"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight",children:"Let's See Where You're At"}),e.jsxs("p",{className:"text-lg text-muted-foreground",children:["Complete ",i," quick scenarios so we can benchmark your skills and personalise your training."]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"This helps us understand your current level and tailor recommendations."})]}),e.jsxs("div",{className:"flex items-center justify-center gap-3",children:[Array.from({length:i}).map((y,f)=>e.jsx("div",{className:`w-3 h-3 rounded-full transition-colors ${f<=o?"bg-primary":"bg-muted-foreground/30"}`},f)),e.jsxs("span",{className:"text-sm text-muted-foreground ml-2",children:["Scenario ",o+1," of ",i]})]}),e.jsx(Q,{className:"bg-muted/30 border-muted",children:e.jsx(Z,{className:"py-4 px-6",children:e.jsx("div",{className:"flex items-center justify-center gap-2 text-sm text-muted-foreground",children:e.jsx("span",{className:"font-medium",children:"⏱️ ~2 minutes per scenario"})})})}),e.jsxs($,{size:"lg",onClick:s,className:"w-full max-w-xs mx-auto text-lg h-14",children:["Start Scenario 1",e.jsx(xe,{className:"w-5 h-5 ml-2"})]})]})})}function Ze({scenario:s,currentIndex:i,totalScenarios:o,onStartCall:y}){return e.jsx("div",{className:"min-h-screen bg-background flex flex-col items-center justify-center p-4",children:e.jsxs("div",{className:"w-full max-w-xl space-y-6",children:[e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx("div",{className:"flex items-center justify-center gap-3 mb-4",children:Array.from({length:o}).map((f,m)=>e.jsx("div",{className:`w-2.5 h-2.5 rounded-full transition-colors ${m<i||m===i?"bg-primary":"bg-muted-foreground/30"}`},m))}),e.jsxs("p",{className:"text-sm font-medium text-muted-foreground",children:["Scenario ",i+1," of ",o]}),e.jsx("h1",{className:"text-2xl font-bold",children:s.name})]}),e.jsx(Q,{className:"bg-muted/30 border-muted",children:e.jsxs(Z,{className:"p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx(Se,{className:"w-4 h-4 text-primary"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Prospect Opens With"}),e.jsxs("p",{className:"text-sm leading-relaxed",children:['"',s.prospect_opening,'"']})]})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx(ke,{className:"w-4 h-4 text-primary"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Your Goal"}),e.jsx("p",{className:"text-sm leading-relaxed",children:s.goal_instruction})]})]})]})}),e.jsxs("div",{className:"space-y-3 text-center",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Sell your product and handle any objections that come up."}),e.jsxs("div",{className:"flex items-center justify-center gap-2 text-xs text-muted-foreground",children:[e.jsx(Pe,{className:"w-4 h-4"}),e.jsx("span",{children:"The call won't end automatically — keep going until you've done your best."})]})]}),e.jsx("div",{className:"pt-2",children:e.jsx($,{size:"lg",onClick:y,className:"w-full h-14 text-lg",children:"Start Practice Call"})})]})})}function Ke({scenario:s,currentIndex:i,totalScenarios:o,onEnd:y}){const[f,m]=t.useState(!1),[g,n]=t.useState(!1),[j,_]=t.useState(0),[N,K]=t.useState([]),[w,E]=t.useState(null),[q,z]=t.useState([]),[F,V]=t.useState(!1),[L,B]=t.useState(!1),[A,re]=t.useState(""),[X,ee]=t.useState(0),[D,se]=t.useState(!1),Y=t.useRef(null),H=t.useRef(""),O=t.useRef(`activation-${Date.now()}`),U=t.useRef(null),u=t.useRef(null),l=t.useRef(null),I=t.useRef(0),S=t.useRef(0),b=t.useRef([]),p=t.useRef([]);t.useEffect(()=>{b.current=N},[N]);const{getRealtimeCoaching:T,isLoading:x}=qe(),c=Fe({micMuted:g,onConnect:()=>{console.log("✅ Connected to AI agent");const a=new Date;E(a),U.current=a.getTime(),l.current=setInterval(()=>{ee(r=>r+1)},1e3)},onDisconnect:()=>{console.log("🔌 Disconnected from AI agent"),l.current&&clearInterval(l.current)},onMessage:({message:a,source:r})=>{const d=U.current?Date.now()-U.current:Date.now();if(r==="ai"&&a){if(a===H.current)return;H.current=a;const v={id:`activation-prospect-${Date.now()}-${Math.random().toString(36).substring(7)}`,session_id:O.current,speaker:"prospect",content:a,timestamp_ms:d,created_at:new Date().toISOString()};K(h=>[...h,v]),ge(a,[...b.current,v])}else if(r==="user"&&a){const v={id:`activation-user-${Date.now()}-${Math.random().toString(36).substring(7)}`,session_id:O.current,speaker:"user",content:a,timestamp_ms:d,created_at:new Date().toISOString()};K(h=>[...h,v])}},onError:a=>{console.error("Conversation error:",a),J.error("Connection error. Please try again.")}});t.useEffect(()=>{if(c.status==="connected"){const a=()=>{const r=c.getOutputVolume();_(r),B(r>10);const d=c.getInputVolume();V(d>.02),u.current=requestAnimationFrame(a)};a()}return()=>{u.current&&cancelAnimationFrame(u.current)}},[c.status]),t.useEffect(()=>(he(),()=>{c.status==="connected"&&c.endSession(),l.current&&clearInterval(l.current),u.current&&cancelAnimationFrame(u.current)}),[]);const ge=t.useCallback(async(a,r)=>{if(!(r.length<2))try{const d=await T(a,null,!0,r.map(v=>({speaker:v.speaker,content:v.content})),p.current,{name:s.name,difficulty:s.difficulty||"Medium",prospectName:s.name},"practice","prospect");
1if(d.structured)z(v=>[d.structured,...v].slice(0,10)),p.current=[...p.current.slice(-4),d.structured.strategy];else if(d.suggestion){const v={strategy:d.suggestion,prospectEmotion:"Analyzing...",examplePhrase:""};z(h=>[v,...h].slice(0,10)),p.current=[...p.current.slice(-4),d.suggestion]}}catch(d){console.error("Coaching error:",d)}},[T,s.name,s.difficulty]),he=t.useCallback(async()=>{var a,r,d,v;m(!0);try{await navigator.mediaDevices.getUserMedia({audio:!0});const{data:{user:h}}=await C.auth.getUser(),{data:M}=await C.from("profiles").select("full_name, organization_id").eq("user_id",h==null?void 0:h.id).single(),oe=((a=M==null?void 0:M.full_name)==null?void 0:a.split(" ")[0])||"there",be=((r=s.first_message)==null?void 0:r.replace(/{user_first_name}/g,oe))||s.prospect_opening,Ne={prospect:{name:"Prospect",personality:s.prospect_personality,situation:s.prospect_background,objections:((d=s.objections)==null?void 0:d.join("; "))||""},scenario:{id:s.id,name:s.name,description:s.description,difficulty:s.difficulty,industry:"General",stage:s.call_context||"cold_call",prospectBackground:s.prospect_background,prospectPersonality:s.prospect_personality,objections:s.objections||[]},user:{name:oe},prospectOpening:s.prospect_opening,activationFirstMessage:be,callContext:s.call_context,objectionTrigger:s.objection_trigger,additionalInstructions:""},{data:te}=await C.from("elevenlabs_agents").select("agent_id").eq("agent_type","cold_call").eq("is_active",!0).limit(1),ce=(v=te==null?void 0:te[0])==null?void 0:v.agent_id;if(!ce)throw new Error("No active agent found");const{data:R,error:le}=await C.functions.invoke("practice-ai-agent",{body:{action:"get-token",agentId:ce,sessionId:O.current,sessionType:"activation",context:Ne,userId:h==null?void 0:h.id,organizationId:M==null?void 0:M.organization_id}});if(le)throw le;if(!(R!=null&&R.signedUrl))throw new Error("No signed URL received");const W={};R.composedPrompt&&(W.prompt_for_elevenlabs=R.composedPrompt),R.callInitiation&&(W.call_initiation=R.callInitiation);const de=await c.startSession({signedUrl:R.signedUrl,...Object.keys(W).length>0?{dynamicVariables:W}:{},connectionType:"websocket"});de&&(Y.current=de)}catch(h){console.error("Failed to start conversation:",h),J.error(`Failed to connect: ${h instanceof Error?h.message:"Unknown error"}`)}finally{m(!1)}},[c,s]),ne=t.useCallback(async()=>{const a=Y.current;l.current&&clearInterval(l.current),await c.endSession();const r=w?Math.round((Date.now()-w.getTime())/1e3):0;y({transcript:N,duration:r,conversationId:a})},[c,N,w,y]),je=t.useCallback(()=>{n(!g)},[g]),ie=t.useCallback((a,r)=>{I.current=a,S.current=r},[]),ve=t.useCallback(()=>{z(a=>a.slice(1))},[]),k=c.status==="connected",ye=a=>{const r=Math.floor(a/60),d=a%60;return`${r}:${d.toString().padStart(2,"0")}`};return f&&!k?e.jsxs("div",{className:"min-h-screen bg-background flex flex-col items-center justify-center gap-6",children:[e.jsxs("div",{className:"relative flex items-center justify-center",children:[e.jsx("div",{className:"absolute w-28 h-28 rounded-full bg-primary/10 animate-ping"}),e.jsx("div",{className:"absolute w-20 h-20 rounded-full bg-primary/15 animate-pulse"}),e.jsx("div",{className:"w-14 h-14 rounded-full bg-primary/20 flex items-center justify-center",children:e.jsx(ae,{className:"w-6 h-6 text-primary animate-spin"})})]}),e.jsxs("div",{className:"text-center space-y-1.5",children:[e.jsx("p",{className:"text-base font-medium",children:"Connecting call..."}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[s.name," · Scenario ",i+1," of ",o]})]})]}):e.jsxs("div",{className:"relative animate-fade-in h-full",children:[e.jsx("div",{className:"sticky top-0 z-10 bg-background border-b border-border px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex items-center gap-2",children:Array.from({length:o}).map((a,r)=>e.jsx("div",{className:`w-2 h-2 rounded-full transition-colors ${r<=i?"bg-primary":"bg-muted-foreground/30"}`},r))}),e.jsxs(P,{variant:"secondary",className:"text-xs",children:["Scenario ",i+1," of ",o]}),k&&e.jsxs(P,{variant:"outline",className:"gap-1.5",children:[e.jsx(We,{className:"h-3 w-3"}),ye(X)]}),k&&e.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-primary font-medium",children:[e.jsx(ae,{className:"h-3 w-3 animate-spin"}),c.isSpeaking?"Prospect Speaking...":"Listening..."]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[k&&e.jsx($,{variant:"outline",size:"icon",onClick:je,className:Ce(g&&"bg-destructive/10 border-destructive"),children:g?e.jsx(Ge,{className:"w-4 h-4"}):e.jsx(_e,{className:"w-4 h-4"})}),e.jsxs($,{variant:"destructive",size:"sm",onClick:ne,disabled:!k&&!f,className:"hidden lg:flex gap-2",children:[e.jsx(me,{className:"w-4 h-4"}),"End Call"]})]})]})}),e.jsxs("div",{className:"hidden lg:grid lg:grid-cols-[340px_1fr_320px] h-[calc(100vh-8rem)]",children:[e.jsx(Le,{transcriptEntries:N,prospectPartialText:A,isConnected:k,isSpeaking:c.isSpeaking,audioLevel:j,callDuration:X,userIsSpeaking:F,prospectIsSpeaking:L,onTalkTimeUpdate:ie,prospectName:s.name}),e.jsx(Oe,{coachingHistory:q,isLoading:x,isActive:k}),e.jsx(Ue,{transcriptEntries:N,prospectName:s.name})]}),e.jsxs("div",{className:"lg:hidden space-y-4 p-4 pb-28",children:[s.objections&&s.objections.length>0&&e.jsx("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/10 p-3",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Ie,{className:"h-4 w-4 text-amber-500 mt-0.5 shrink-0"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-amber-600 dar
1k:text-amber-400",children:"Objections you'll face:"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.objections.slice(0,3).map((a,r)=>e.jsxs(P,{variant:"outline",className:"text-xs bg-background/50 border-amber-500/30",children:['"',typeof a=="string"?a:(a==null?void 0:a.response)||a,'"']},r))})]})]})}),e.jsxs("div",{className:"rounded-xl border border-border bg-card overflow-hidden",children:[e.jsxs("button",{onClick:()=>se(!D),className:"w-full flex items-center justify-between p-3 hover:bg-muted/50 transition-colors",children:[e.jsxs("span",{className:"text-sm font-medium flex items-center gap-2",children:["AI Coach",q.length>0&&!D&&e.jsx(P,{variant:"secondary",className:"text-xs",children:"New tip"})]}),D?e.jsx(Ae,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Te,{className:"h-4 w-4 text-muted-foreground"})]}),D&&e.jsx("div",{className:"border-t border-border",children:e.jsx(Ve,{structuredCoaching:q[0]||null,onDismiss:ve,isLoading:x})})]}),e.jsxs("div",{className:"flex items-center gap-4 p-4 rounded-xl border border-border bg-card",children:[e.jsx(Ye,{isSpeaking:c.isSpeaking,audioLevel:j,personality:s.prospect_personality,className:"w-14 h-14"}),e.jsx("div",{className:"flex-1",children:e.jsx(Be,{micIsSpeaking:F,tabIsSpeaking:L||c.isSpeaking,isActive:k,onTalkTimeUpdate:ie,compact:!0})}),k&&e.jsx(P,{variant:c.isSpeaking?"default":"secondary",children:c.isSpeaking?"Speaking":"Listening"})]}),e.jsx("div",{className:"rounded-xl border border-border bg-card min-h-[300px]",children:e.jsx(He,{entries:N,isLive:k,prospectLiveText:A,micIsSpeaking:F,tabIsSpeaking:L})})]}),e.jsx("div",{className:"lg:hidden fixed bottom-0 left-0 right-0 z-50 bg-background border-t border-border p-4 pb-6",children:e.jsxs($,{variant:"destructive",size:"lg",onClick:ne,disabled:!k&&!f,className:"w-full gap-2",children:[e.jsx(me,{className:"w-5 h-5"}),"End Call"]})})]})}function Xe({currentIndex:s,totalScenarios:i,isLastScenario:o,onContinue:y,isSaving:f=!1}){const m=s+1,g=i-m;return e.jsx("div",{className:"min-h-screen bg-background flex flex-col items-center justify-center p-4",children:e.jsxs("div",{className:"w-full max-w-xl space-y-8",children:[e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx("div",{className:"mx-auto w-16 h-16 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx(Je,{className:"w-8 h-8 text-primary"})}),e.jsxs("h1",{className:"text-2xl font-bold",children:["Scenario ",m," Complete!"]}),e.jsx("p",{className:"text-muted-foreground",children:o?"All scenarios complete! Your call analyses are now ready to view.":"Your performance is being analysed. Return to dashboard to continue."})]}),e.jsx(Q,{className:"border-primary/20 bg-primary/5",children:e.jsx(Z,{className:"p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-primary/10 flex items-center justify-center flex-shrink-0",children:e.jsx(fe,{className:"w-5 h-5 text-primary"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium",children:o?"Your Skills Report is Ready!":"Analysis in Progress..."}),e.jsx("p",{className:"text-sm text-muted-foreground",children:o?"View your scores across all scenarios to see where you excel and where to focus.":`${g} more scenario${g===1?"":"s"} to go. Complete all to unlock your full skills report.`})]})]})})}),e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("div",{className:"flex items-center justify-center gap-3",children:Array.from({length:i}).map((n,j)=>e.jsx("div",{className:`w-3 h-3 rounded-full transition-colors ${j<=s?"bg-primary":"bg-muted-foreground/30"}`},j))}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[m," of ",i," scenarios completed"]})]}),e.jsx($,{size:"lg",onClick:y,className:"w-full h-14 text-lg",disabled:f,children:f?e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"w-5 h-5 mr-2 animate-spin"}),"Saving your session..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Re,{className:"w-5 h-5 mr-2"}),"Back to Dashboard"]})})]})})}function es({onContinue:s,completedScenarios:i}){const[o,y]=t.useState(!1),f=pe(),m=i||[{index:0,name:"The Brush-Off",description:"Handling initial resistance"},{index:1,name:"The Price Objection",description:"Addressing budget concerns"},{index:2,name:"The Info Request",description:"Converting brush-offs to conversations"}];t.useEffect(()=>{const j=Date.now()+2e3,_=()=>{ue({particleCount:3,angle:60,spread:55,origin:{x:0},colors:["#6366f1","#8b5cf6","#a855f7"]}),ue({particleCount:3,angle:120,spread:55,origin:{x:1},colors:["#6366f1","#8b5cf6","#a855f7"]}),Date.now()<j&&requestAnimationFrame(_)};_();const N=setTimeout(()=>y(!0),600);return()=>clearTimeout(N)},[]);const g=(n,j)=>{f(j?`/call-analysis/${j}?type=practice`:"/analysis?type=practice")};return e.jsx("div",{className:"min-h-screen bg-background flex flex-col items-center justify-center p-4",children:e.jsxs("div",{className:"w-full max-w-lg space-y-8",children:[e.jsx("div",{className:"mx-auto w-24 h-24 rounded-full bg-gradient-to-br from-primary/20 to-primary/5 flex items-center justify-center animate-in zoom-in duration-500",children:e.jsx($e,{className:"w-12 h-12 text-primary"})}),e.jsxs("div",{className:"space-y-4 animate-in fade-in slide-in-from-bottom-4 duration-700 text-center",children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Your Baseline is Set!"}),e.jsx("p",{className:"text-lg text-muted-foreground",children:"We've benchmarked your current skills. Review your scores below and start improving."})]}),e.jsxs("div",{className:`space-y-3 transition-all duration-500 ${o?"opacity-100 translate-y-0":"opacity-0 translate-y-4"}`,children:[e.jsx("h2",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide text-center",children:"Your Skills Report"}),e.jsx("div",{className:"space-y-2",children:m.map((n,j)=>e.jsx(Q,{className:"border-border/50 hover:border-primary/30 transition-colors cursor-pointer group",onClick:()=>g(n.index,n.sessionId),children:e.jsx(Z,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx(fe,{className:"w-4 h-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:n.name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n.description})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{variant:"secondary",className:"text-xs",children:"View Score"}),e.jsx(Ee,{className:"w-4 h-4 text-muted-foreground group-hover:text-primary transition-colors"})]})]})})},n.index))})]}),e.jsxs("div",{className:`transition-all duration-500 delay-200 ${o?"opacity-100 translate-y-0":"opacity-0 translate-y-4"}`,children:[e.jsxs($,{size:"lg",onClick:s,className:"w-full h-14 text-lg",children:["Continue to Dashboard",e.jsx(xe,{className:"w-5 h-5 ml-2"})]}),e.jsx("p",{className:"text-xs text-center text-muted-foreground mt-3",children:"You can always review your call analyses from the dashboard"})]})]})})}function _s(){const s=pe(),{user:i,loading:o,isAuthenticated:y,organizationId:f}=ze(),{scenarios:m,currentScenarioIndex:g,currentScenario:n,isComplete:j,isLoading:_,markScenarioComplete:N,refetchProgress:K}=Me(),[w,E]=t.useState("intro"),[q,z]=t.useState(null),[F,V]=t.useState([]),[L,B]=t.useState(!1),[A,re]=t.useState(null),[X,ee]=t.useState(null);t.useEffect(()=>{if(!o&&!y){s("/auth");return}if(!_&&j){s("/dashboard");return}},[o,y,_,j,s]),t.useEffect(()=>{if(!i||_||m.length===0)return;(async()=>{const{data:l}=await C.from("practice_sessions").select("id, session_title, created_at").eq("user_id",i.id).eq("mode","activation").order("created_at",{ascending:!0});if(l&&l.length>0){const I=l.map((S,b)=>{var p,T;return{index:b,name:((p=S.session_title)==null?void 0:p.replace("Activation: ",""))||`Scenario ${b+1}`,description:((T=m[b])==null?void 0:T.description)||"",sessionId:S.id}});V(I)}})()},[i,_,m]);const D=()=>{E("intro")},se=()=>{E("practice")},Y=async u=>
1{if(!n)return;const l=g;re(l),B(!0),console.log(`[Activation] Session ended for scenario ${l+1}: ${n.name}`);try{const{data:{user:I}}=await C.auth.getUser();if(!I){console.error("No authenticated user found"),J.error("Authentication required"),z(u),E("feedback");return}const{data:S}=await C.from("profiles").select("organization_id").eq("user_id",I.id).single(),b=(S==null?void 0:S.organization_id)||f;console.log(`[Activation] Saving session with org_id: ${b} (context: ${f}, fresh: ${S==null?void 0:S.organization_id})`),b||console.warn("[Activation] No organization_id available for session");const{data:p,error:T}=await C.from("practice_sessions").insert({user_id:I.id,organization_id:b,status:"completed",mode:"activation",duration_seconds:u.duration,transcript:u.transcript,session_title:`Activation: ${n.name}`}).select("id").single();if(T)console.error("Error saving activation session:",T),J.error("Failed to save session");else if(p){if(console.log(`[Activation] Saved session ${p.id} for scenario ${l+1}`),ee(p.id),V(x=>[...x,{index:l,name:n.name,description:n.description,sessionId:p.id}]),u.duration>0&&b){const x=Math.round(u.duration/60*10*100)/100;console.log(`[Activation] Logging credit usage: ${x} credits for ${u.duration}s`);const{error:c}=await C.from("credit_usage").insert({organization_id:b,user_id:I.id,action_type:"onboarding",credits_consumed:x,duration_seconds:u.duration,is_free:!1,metadata:{scenario_index:l,scenario_name:n.name,session_id:p.id}});c&&console.error("Error logging credit usage:",c)}try{const x=await N(l);console.log("[Activation] Progress updated:",x)}catch(x){console.error("Error updating progress:",x)}C.functions.invoke("analyze-practice-session",{body:{sessionId:p.id}}).then(({error:x})=>{x?console.error("Error triggering analysis:",x):console.log("Analysis triggered for session:",p.id)}),u.conversationId&&C.functions.invoke("fetch-conversation-audio",{body:{conversationId:u.conversationId,sessionId:p.id,sessionType:"practice"}}).then(({error:x})=>{x&&console.error("Error fetching audio:",x)})}}catch(I){console.error("Unexpected error saving session:",I)}finally{B(!1)}z(u),E("feedback")},H=async()=>{s("/dashboard")},O=()=>{s("/dashboard")};if(o||_)return e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-4",children:e.jsxs("div",{className:"w-full max-w-md 
1space-y-4",children:[e.jsx(G,{className:"h-12 w-3/4 mx-auto"}),e.jsx(G,{className:"h-6 w-full"}),e.jsx(G,{className:"h-48 w-full"}),e.jsx(G,{className:"h-12 w-full"})]})});const U=w==="feedback"&&A!==null?A:g;return w==="feedback"&&A!==null&&m[A],e.jsxs(e.Fragment,{children:[e.jsxs(De,{children:[e.jsx("title",{children:"Get Started | Vonvo"}),e.jsx("meta",{name:"description",content:"Complete your onboarding by practicing 3 real sales scenarios. Build confidence with AI-powered roleplay before accessing the full platform."})]}),e.jsxs("div",{className:"min-h-screen bg-background",children:[w==="welcome"&&e.jsx(Qe,{onStart:D,totalScenarios:3,currentIndex:g}),w==="intro"&&n&&e.jsx(Ze,{scenario:n,currentIndex:g,totalScenarios:3,onStartCall:se}),w==="practice"&&n&&e.jsx(Ke,{scenario:n,currentIndex:g,totalScenarios:3,onEnd:Y}),w==="feedback"&&e.jsx(Xe,{currentIndex:U,totalScenarios:3,isLastScenario:A===2,onContinue:H,isSaving:L}),w==="complete"&&e.jsx(es,{onContinue:O,completedScenarios:F})]})]})}export{_s 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.