PageSourceSearch

https://app.prepin.ai/assets/InterviewV2-k5Ut-U2r.js

js prepin.ai collected 2026-10-02 00:05:05 UTC 34,888 bytes, 19 lines download raw bytes

1import{r as n,gf as gr,b as fr,u as pr,j as t,B as $,cZ as De,X as le,bk as K,bx as Ce,t as oe,y as Y,cX as Ue,c_ as Be,c$ as We,T as D,V as se,bc as hr,bd as mr,be as br,d0 as xr,cl as yr,bg as vr,d1 as wr,ao as Ee,cN as Sr,d2 as Ir,g as jr,aB as Ar,aO as re,d3 as kr,d4 as Cr,d5 as Er,d6 as Rr,aP as $r,aQ as zr,d7 as Tr,aR as Mr,aT as Ge,d8 as Lr,ht as me,hu as Vr,hv as _r}from"./vendor-BCRspNgZ.js";import{u as Fr,q as Pr,v as Hr,z as Nr,y as Dr,K as Ye,b as ae,w as qe,a as te,B as Ur,O as Br,I as Wr,C as Xe,D as Gr}from"./components-Bl_54C1A.js";import{g as Yr}from"./pages-DE9jEnKg.js";const z={INACTIVE:"inactive",ACTIVE:"active",LOADING:"loading"};function qr(){const[e,o]=n.useState(!1),[r,c]=n.useState(z.INACTIVE),[d,u]=n.useState([]),[g,b]=n.useState(null),[T,E]=n.useState(0),[I,x]=n.useState(0),[M,p]=n.useState(!1),[L,U]=n.useState("vad"),[N,R]=n.useState(null),v=n.useRef(null),V=n.useRef(null),s=n.useRef(null),_=n.useRef(null);n.useEffect(()=>{v.current||(console.log("Vapi instance in useVapi:",v.current),v.current=new gr("3908c8cd-a25a-478b-b670-e908944b0fec"));const a=v.current,k=()=>o(!0),F=()=>o(!1),y=()=>{if(console.log("Call has started successfully"),c(z.ACTIVE),L==="manual")try{a.setMuted(!0),console.log("Initial mic state set to muted in manual mode")}catch(w){console.error("Error setting initial mic state:",w)}else try{a.setMuted(!1),console.log("Initial mic state set to unmuted in VAD mode")}catch(w){console.error("Error setting initial mic state:",w)}},Q=()=>{console.log("Call has ended"),c(z.INACTIVE)},J=w=>E(w),ue=w=>{if(w.type==="transcript"&&w.transcriptType==="partial"?b(w):w.type==="transcript"&&w.transcriptType==="final"&&(u(S=>[...S,w]),b(null)),w.type==="audio"){if(!_.current){_.current=new Audio,_.current.crossOrigin="anonymous",V.current=new(window.AudioContext||window.webkitAudioContext);const S=V.current.createMediaElementSource(_.current);s.current=V.current.createAnalyser(),s.current.fftSize=2048,S.connect(s.current),S.connect(V.current.destination)}_.current.src=w.audio,_.current.play().catch(console.error),_.current.onended=()=>{p(!1)},p(!0)}w.type==="assistant-volume"&&x(w.volumeLevel)},de=w=>{c(z.INACTIVE),console.error("Vapi Error:",w)};return a.on("speech-start",k),a.on("speech-end",F),a.on("call-start",y),a.on("call-end",Q),a.on("volume-level",J),a.on("message",ue),a.on("error",de),()=>{a.off("speech-start",k),a.off("speech-end",F),a.off("call-start",y),a.off("call-end",Q),a.off("volume-level",J),a.off("message",ue),a.off("error",de),V.current&&V.current.close()}},[L]);const B=n.useCallback(async(a,k)=>{c(z.LOADING);try{console.log("Attempting to start Vapi session with options:",JSON.stringify(a,null,2));const F=typeof a=="object"&&a!==null?Object.keys(a):[];let y;const Q=typeof a=="object"&&a!==null&&typeof a.assistantId=="string"&&F.every(J=>["assistantId","assistantOverrides"].includes(J));if(typeof a=="string"?y=await v.current.start(a,k):Q?y=await v.current.start(a.assistantId,a.assistantOverrides):y=await v.current.start(a,k),y!=null&&y.error)throw console.error("❌ Vapi Start Error:",y.error),console.error("Full response:",y),c(z.INACTIVE),new Error(`VAPI Error: ${y.error.message||y.error}`);return y!=null&&y.id&&(R(y.id),console.log("✅ VAPI call started with ID:",y.id)),c(z.ACTIVE),y}catch(F){throw console.error("❌ Error starting Vapi session:",F),console.error("Error details:",{message:F.message,stack:F.stack,response:F.response}),c(z.INACTIVE),F}},[]),W=n.useCallback(()=>{c(z.LOADING),v.current&&v.current.stop()},[]),xe=n.useCallback(()=>{r===z.ACTIVE?W():B()},[r,B,W]),ce=n.useCallback(a=>
1{if(U(a),v.current&&r===z.ACTIVE)try{a==="vad"?(v.current.setMuted(!1),console.log("Mic unmuted in VAD mode")):(v.current.setMuted(!0),console.log("Mic muted in manual mode"))}catch(k){console.error("Error toggling mic on mode change:",k)}},[r]);return{isSpeechActive:e,callStatus:r,audioLevel:T,assistantVolumeLevel:I,activeTranscript:g,messages:d,start:B,stop:W,toggleCall:xe,mode:L,setMode:ce,vapi:v.current,isAISpeaking:M,assistantAnalyser:s.current,currentCallId:N}}const Xr=async(e,o={})=>{const r={maxAttempts:3,initialDelay:1e3,maxDelay:1e4,backoffMultiplier:2,onRetry:null,...o};let c;for(let d=1;d<=r.maxAttempts;d++)try{console.log(`🔄 Attempt ${d}/${r.maxAttempts}...`);const u=await e();return d>1&&console.log(`✅ Succeeded on attempt ${d}`),u}catch(u){if(c=u,d===r.maxAttempts)throw console.error(`❌ All ${r.maxAttempts} attempts failed`),u;const g=Math.min(r.initialDelay*Math.pow(r.backoffMultiplier,d-1),r.maxDelay);console.warn(`⚠️ Attempt ${d} failed: ${u.message}`),console.log(`⏳ Retrying in ${g}ms...`),r.onRetry&&r.onRetry(d,r.maxAttempts,g,u),await new Promise(b=>setTimeout(b,g))}throw c},Kr=e=>{var d,u;const o=["timeout","network","connection","ECONNREFUSED","ETIMEDOUT","ENOTFOUND","Failed to fetch","NetworkError","fetch failed"],r=((d=e.message)==null?void 0:d.toLowerCase())||"",c=((u=e.name)==null?void 0:u.toLowerCase())||"";return o.some(g=>r.includes(g.toLowerCase())||c.includes(g.toLowerCase()))},Jr=e=>{const o=e.message||"";return o.includes("camera")||o.includes("video")?"Camera access denied or unavailable. Please check your camera permissions and try again.":o.includes("microphone")||o.includes("audio")?"Microphone access denied or unavailable. Please check your microphone permissions and try again.":o.includes("timeout")?"Connection timeout. Please check your internet connection and try again.":o.includes("VAPI")?"Interview service temporarily unavailable. Please try again in a moment.":Kr(e)?"Connection issue detected. Please check your internet connection and try again.":`Failed to start interview: ${o}`},Zr=()=>t.jsx(oe,{spacing:1,p:3,bg:"rgba(255, 255, 255, 0.95)",borderRadius:"2xl",borderTopLeftRadius:"2px",border:"1px solid",borderColor:"gray.200",alignSelf:"flex-start",boxShadow:"sm",children:[0,1,2].map(e=>t.jsx(le.div,{animate:{y:[0,-5,0]},transition:{duration:.6,repeat:1/0,delay:e*.2},style:{width:"6px",height:"6px",backgroundColor:"#A0AEC0",borderRadius:"50%"}},e))}),Qr=e=>{let o="";return e.experience&&Array.isArray(e.experience)&&(o+=`### EXPERIENCE
2
3`,e.experience.forEach(r=>{o+=`**${r.position}** | ${r.company}
4`,o+=`${r.date}
5`,r.responsibilities&&Array.isArray(r.responsibilities)&&r.responsibilities.forEach(c=>{o+=`- ${c}
6`}),o+=`
7`})),e.skills&&Array.isArray(e.skills)&&(o+=`### SKILLS
8
9`,e.skills.forEach(r=>{o+=`**${r.category}:** ${r.skills.join(", ")}
10`}),o+=`
11`),e.education&&Array.isArray(e.education)&&(o+=`### EDUCATION
12
13`,e.education.forEach(r=>{o+=`**${r.degree}**
14${r.university} | ${r.year}
15
16`})),o.trim()||JSON.stringify(e,null,2)},Qe=e=>{if(!e)return null;let o="";return typeof e!="string"?e.unstructuredResume?o=e.unstructuredResume:e.experience||e.education||e.skills?o=Qr(e):e.content?o=e.content:o=JSON.stringify(e,null,2):o=e,o=o.replace(/^Suggested Answer:\s*/i,""),o.split(`
17`).map((c,d)=>{let u=c,g=!1;(c.trim().startsWith("- ")||c.trim().startsWith("* "))&&(u=c.trim().substring(2),g=!0);const T=u.split(/(\*\*.*?\*\*)/g).map((E,I)=>E.startsWith("**")&&E.endsWith("**")?t.jsx(D,{as:"span",fontWeight:"bold",color:"white",children:E.slice(2,-2)},I):t.jsx("span",{children:E},I));return t.jsxs($,{display:"flex",ml:g?4:0,mb:1,children:[g&&t.jsx(D,{mr:2,color:"gray.400",children:"•"}),t.jsx(D,{as:"span",color:"gray.200",children:T})]},d)})},Or=({text:e})=>{const[o,r]=n.useState(0);return n.useEffect(()=>{r(0);const c=setInterval(()=>{r(d=>d>=e.length?(clearInterval(c),d):d+1)},15);return()=>clearInterval(c)},[e]),t.jsx($,{children:Qe(e.slice(0,o))})},et=e=>{const o=Math.floor(e/60),r=e%60;return`${o.toString().padStart(2,"0")}:${r.toString().padStart(2,"0")}`},Ke={en:"English",cs:"Czech",da:"Danish",nl:"Dutch",fi:"Finnish",fr:"French",de:"German",el:"Greek",it:"Italian",no:"Norwegian",pl:"Polish",pt:"Portuguese",ro:"Romanian",es:"Spanish",sv:"Swedish",uk:"Ukrainian"},Je={en:"en-US",cs:"cs",da:"da",nl:"nl",fi:"fi",fr:"fr",de:"de",el:"el",it:"it",no:"no",pl:"pl",pt:"pt",ro:"ro",es:"es",sv:"sv",uk:"uk"},be=(e="en")=>{const o=String(e||"").toLowerCase().trim();return o&&o.split(/[-_]/)[0]||"en"},Oe=(e="en")=>{const o=be(e);return Ke[o]||Ke.en},Ze={en:({roundName:e,position:o,companyName:r})=>`Hi, welcome to ${e||"this interview"} for the ${o||"role"}${r?` at ${r}`:""}. Please start with a short introduction about your background.`,cs:({roundName:e,position:o,companyName:r})=>`Ahoj, vitejte u ${e||"tohoto pohovoru"} na pozici ${o||"role"}${r?` ve spolecnosti ${r}`:""}. Zacnete prosim kratkym predstavenim sveho zazemi.`,da:({roundName:e,position:o,companyName:r})=>`Hej, velkommen til ${e||"dette interview"} for rollen ${o||"rollen"}${r?` hos ${r}`:""}. Start venligst med en kort intro om din baggrund.`,nl:({roundName:e,position:o,companyName:r})=>`Hoi, welkom bij ${e||"dit interview"} voor de functie ${o||"de rol"}${r?` bij ${r}`:""}. Begin met een korte introductie van je achtergrond.`,fi:({roundName:e,position:o,companyName:r})=>`Hei, tervetuloa ${e||"tahan haastatteluun"} rooliin ${o||"rooli"}
17${r?` yrityksessa ${r}`:""}. Aloita lyhyella taustasi esittelylla.`,fr:({roundName:e,position:o,companyName:r})=>`Bonjour, bienvenue a ${e||"cet entretien"} pour le poste ${o||"ce role"}${r?` chez ${r}`:""}. Commencez par une breve presentation de votre parcours.`,de:({roundName:e,position:o,companyName:r})=>`Hallo, willkommen bei ${e||"diesem Interview"} fur die Position ${o||"diese Rolle"}${r?` bei ${r}`:""}. Starten Sie bitte mit einer kurzen Vorstellung Ihres Hintergrunds.`,el:({roundName:e,position:o,companyName:r})=>`Geia sas, kalos irthate sto ${e||"sygkekrimeno interview"} gia ton rolo ${o||"tou rolou"}${r?` stin ${r}`:""}. Xekiniste me mia syntomi parousiasi tou ypovathrou sas.`,it:({roundName:e,position:o,companyName:r})=>`Ciao, benvenuto a ${e||"questo colloquio"} per il ruolo ${o||"questo ruolo"}${r?` in ${r}`:""}. Inizia con una breve presentazione del tuo background.`,no:({roundName:e,position:o,companyName:r})=>`Hei, velkommen til ${e||"dette intervjuet"} for rollen ${o||"rollen"}${r?` hos ${r}`:""}. Start gjerne med en kort introduksjon av bakgrunnen din.`,pl:({roundName:e,position:o,companyName:r})=>`Czesc, witaj w ${e||"tej rozmowie"} na stanowisko ${o||"tej roli"}${r?` w ${r}`:""}. Zacznij prosze od krotkiego przedstawienia swojego doswiadczenia.`,pt:({roundName:e,position:o,companyName:r})=>`Ola, bem-vindo a ${e||"esta entrevista"} para o cargo ${o||"esta funcao"}${r?` na ${r}`:""}. Comece com uma breve apresentacao da sua experiencia.`,ro:({roundName:e,position:o,companyName:r})=>`Salut, bine ai venit la ${e||"acest interviu"} pentru rolul ${o||"acest rol"}${r?` la ${r}`:""}. Te rog sa incepi cu o scurta prezentare a experientei tale.`,es:({roundName:e,position:o,companyName:r})=>`Hola, bienvenido a ${e||"esta entrevista"} para el puesto ${o||"este rol"}${r?` en ${r}`:""}. Empieza con una breve introduccion sobre tu experiencia.`,sv:({roundName:e,position:o,companyName:r})=>`Hej, valkommen till ${e||"den har intervjun"} for rollen ${o||"rollen"}${r?` pa ${r}`:""}. Borja med en kort introduktion av din bakgrund.`,uk:({roundName:e,position:o,companyName:r})=>`Pryvit, vitayu na ${e||"tsomu intervyu"} na posadu ${o||"tsyu rol"}${r?` v ${r}`:""}. Bud laska, pochni z korotkogo predstavlennya svoho dosvidu.`},rt=(e,o="en")=>{var d,u,g,b,T,E,I,x,M,p,L,U,N,R,v,V,s,_;const r=be(o),c=[(u=(d=e==null?void 0:e.assistantOverrides)==null?void 0:d.variableValues)==null?void 0:u.first_message_localized,(b=(g=e==null?void 0:e.assistantOverrides)==null?void 0:g.variableValues)==null?void 0:b.first_message_translations,(E=(T=e==null?void 0:e.assistantOverrides)==null?void 0:T.variableValues)==null?void 0:E.localized_first_messages,(M=(x=(I=e==null?void 0:e.assistantOverrides)==null?void 0:I.variableValues)==null?void 0:x.translations)==null?void 0:M.first_message,(p=e==null?void 0:e.assistant)==null?void 0:p.first_message_localized,(L=e==null?void 0:e.assistant)==null?void 0:L.first_message_translations,(U=e==null?void 0:e.assistant)==null?void 0:U.localized_first_messages,(R=(N=e==null?void 0:e.assistant)==null?void 0:N.translations)==null?void 0:R.first_message,e==null?void 0:e.first_message_localized,e==null?void 0:e.first_message_translations,e==null?void 0:e.localized_first_messages,(v=e==null?void 0:e.translations)==null?void 0:v.first_message];for(const B of c){const W=Yr(B,r);if(W)return W}if(r==="en"){const B=String(((s=(V=e==null?void 0:e.assistantOverrides)==null?void 0:V.variableValues)==null?void 0:s.first_message)||((_=e==null?void 0:e.assistant)==null?void 0:_.first_message)||(e==null?void 0:e.first_message)||"").trim();if(B)return B}return""},tt=({assistantOptions:e,languageCode:o="en",languageLabel:r="English",roundName:c="",position:d="",companyName:u=""})=>{var v,V;const g=be(o),b=r||Oe(g),T=Je[g]||Je.en,E=Ze[g]||Ze.en,I=rt(e,g)||E({roundName:c,position:d,companyName:u}),x=`IMPORTANT: Conduct the full interview in ${b} (${g}) unless the candidate explicitly asks to switch language.`,M=(s={})=>{const _=s.variableValues||{};return{...s,variableValues:{..._,interview_language:b,interview_language_code:g,first_message:I},firstMessage:I}};if(typeof e=="string"&&e.trim())return{assistantId:e.trim(),assistantOverrides:M({})};const p={...e||{}},L=typeof p.assistantId=="string"&&p.assistantId.trim()||typeof((v
17=p.assistant)==null?void 0:v.id)=="string"&&p.assistant.id.trim()||"";if(L)return{assistantId:L,assistantOverrides:M(p.assistantOverrides||{})};const U=Array.isArray((V=p==null?void 0:p.model)==null?void 0:V.messages)?p.model.messages:[],N=U.findIndex(s=>(s==null?void 0:s.role)==="system"&&typeof(s==null?void 0:s.content)=="string"),R=[...U];if(N>=0){const s=String(R[N].content||"");s.includes(x)||(R[N]={...R[N],content:`${s}
18
19${x}`.trim()})}else R.unshift({role:"system",content:x});return{...p,firstMessage:I,transcriber:{...p.transcriber||{},language:T},model:{...p.model||{},messages:R}}};function ot(e){if(!e)return .5;const o=["neutral","happy","surprised"],r=["sad","angry","fearful","disgusted"];let c=0;const d=typeof e.asSortedArray=="function"?Object.fromEntries(e.asSortedArray().map(u=>[u.expression,u.probability])):e;return o.forEach(u=>c+=d[u]||0),r.forEach(u=>c-=d[u]||0),Math.max(0,Math.min(1,(c+1)/2))}function nt(e){return e>.7?"High":e>.4?"Medium":"Low"}function it(e){if(!e)return .5;const o=e.getLeftEye(),r=e.getRightEye(),c=e.getNose(),d=M=>M.reduce((p,L)=>({x:p.x+L.x,y:p.y+L.y}),{x:0,y:0}),u=d(o);u.x/=o.length,u.y/=o.length;const g=d(r);g.x/=r.length,g.y/=r.length;const b=c[0],T=(M,p)=>Math.sqrt(Math.pow(M.x-p.x,2)+Math.pow(M.y-p.y,2)),E=T(u,g),I=T(u,b),x=T(g,b);return 1-Math.abs(I-x)/(E||1)}function st(e){return e>.8?"Looking at camera":"Not looking at camera"}function at(e){var r;return e&&((r=(typeof e.asSortedArray=="function"?e.asSortedArray():Object.entries(e).sort((c,d)=>d[1]-c[1]).map(([c,d])=>({expression:c,probability:d})))[0])==null?void 0:r.expression)||"neutral"}const lt=n.memo(({initialTime:e,isActive:o,onTimeUp:r})=>{const[c,d]=n.useState(e),u=n.useRef(null),g=n.useRef(r);return n.useEffect(()=>{g.current=r},[r]),n.useEffect(()=>(o?u.current=setInterval(()=>{d(b=>b<=1?(clearInterval(u.current),g.current(),0):b-1)},1e3):u.current&&clearInterval(u.current),()=>clearInterval(u.current)),[o]),t.jsx(D,{color:"gray.300",fontWeight:"bold",ml:1,children:et(c)})}),ft=()=>{const e=fr(),o=pr(),{user:r}=Fr(),{isDemoMode:c}=Pr(),d=e.state||{},u=Hr(d),{assistantOptions:g,currentRound:b,position:T,companyName:E,selectedDevices:I,interviewId:x,subscriptionLevel:M="Free",interviewTime:p,hasMediaStream:L,interviewLanguageCode:U,interviewLanguageLabel:N}=u,R=be(U||(typeof window<"u"?localStorage.getItem("codingInterviewSelectedVoiceLanguage"):"")||"en"),v=N||Oe(R),V=c?300:typeof p=="number"?p:M==="Free"?300:1200;n.useEffect(()=>{typeof window>"u"||localStorage.setItem("codingInterviewSelectedVoiceLanguage",R)},[R]),n.useEffect(()=>{u&&Object.keys(u).length>0&&Nr(u)},[u]);const[s,_]=n.useState(null),[B,W]=n.useState(!0),{start:xe,stop:ce,callStatus:a,vapi:k,isAISpeaking:F,currentCallId:y,isSpeechActive:Q,activeTranscript:J}=qr(),{startRecording:ue,stopRecording:de,stopAndUpload:w}=Dr(x,b),S=n.useRef(null),A=n.useRef(null);n.useRef(!0),n.useRef(null),n.useRef(null);const ye=n.useRef(!1),O=n.useRef(null),Z=n.useRef(null),er=n.useRef(0),ve=n.useRef(!1),ge=n.useRef(null),we=n.useRef("General Discussion"),rr=n.useRef(!1);n.useRef(!1),n.useEffect(()=>{rr.current=F},[F]);const[Re,tr]=n.useState(!1),[$e,ze]=n.useState(!1),Te=n.useRef([]);n.useRef(0);const Se=n.useRef(null),[q,or]=n.useState("pip"),[G,ne]=n.useState(null),[m,Me]=n.useState(!1),[Ie,nr]=n.useState(!0),[ir,sr]=n.useState(!1),[Le,Ve]=n.useState([]),[_e,Fe]=n.useState(!1),[ee,ar]=n.useState([]),[ct,lr]=n.useState([]),[fe,Pe]=n.useState(!1),je=a===z.ACTIVE&&!Q&&!F&&(!J||!J.transcript)&&ee.length===0,cr=i=>{lr(f=>[...f,i]),ar(f=>{const l=[...f],h=l[l.length-1],C=h&&h.role===i.role;return i.transcriptType==="partial"?(i.role==="assistant"&&(we.current=i.transcript),C?l[l.length-1]={...h,temp:i.transcript}:l.push({id:Date.now()+Math.random(),role:i.role,committed:"",temp:i.transcript})):i.transcriptType==="final"&&(i.role==="assistant"&&(we.current=i.transcript),C?l[l.length-1]={...h,committed:h.committed+i.transcript+" ",temp:""}:l.push({id:Date.now()+Math.random(),role:i.role,committed:i.transcript+" ",temp:""})),l})};n.useEffect(()=>{m&&ge.current&&(ge.current.scrollTop=ge.current.scrollHeight)},[ee,m,je]),n.useEffect(()=>{(async()=>
19{if(x)try{W(!0);const f="https://api.prepin.ai";let l=null;try{const h=await ae.get(`${f}/api/templates/${x}`,{withCredentials:!0});l={...h.data,isTemplate:!0,customPosition:h.data.title,companyName:h.data.companyName,interviewType:h.data.interviewType||"General Interview"}}catch{l=(await ae.get(`${f}/api/interviews/${x}`,{withCredentials:!0})).data}_(l)}catch(f){console.error("Failed to fetch interview data:",f)}finally{W(!1)}})()},[x]),n.useEffect(()=>{a!==z.INACTIVE&&S.current&&O.current&&(S.current.srcObject=O.current)},[a]);const ur=async()=>{if(!ye.current&&a!==z.ACTIVE)try{ye.current=!0,Ye.pauseTracking();let i;if(L&&window.__interviewMediaStream){const l=window.__interviewMediaStream;l.getAudioTracks().forEach(C=>C.stop());const h=l.getVideoTracks();i=new MediaStream(h),delete window.__interviewMediaStream}else i=await navigator.mediaDevices.getUserMedia({audio:!1,video:{deviceId:I!=null&&I.videoInput?{exact:I.videoInput}:void 0,width:{ideal:1280},height:{ideal:720}}});O.current=i,S.current&&(S.current.srcObject=i);const f=tt({assistantOptions:g,languageCode:R,languageLabel:v,roundName:b,position:T,companyName:E});await Xr(async()=>{const l=await xe(f);if(!(l!=null&&l.id))throw new Error("No session ID");return l},{maxAttempts:5});try{await ue(),ve.current=!0,console.log("✅ Video recording started successfully")}catch(l){console.error("❌ Video recording failed:",l),ve.current=!1,te("Video Recording Warning","warning","Video recording could not start. The interview will continue with audio only. Please check camera permissions.")}ze(!0),setTimeout(()=>ze(!1),3e4)}catch(i){console.error("Setup failed:",i),te("Failed to start interview","error",Jr(i)),ye.current=!1}},He=n.useCallback(async()=>{var l,h;if(fe)return;Pe(!0),Ye.resumeTracking();let i=!1,f=null;try{if(await ce(),ve.current)try{c?(console.log("🎬 [Demo] Stopping recording without upload..."),await de(),i=!0):(console.log("🎬 Attempting to stop and upload video..."),await w(),i=!0),console.log("✅ Video process complete")}catch(P){f=P,console.error("❌ Video upload failed:",P),console.error("Video upload error details:",{message:P.message,response:(l=P.response)==null?void 0:l.data,status:(h=P.response)==null?void 0:h.status})}else console.log("⚠️ Video recording was never started, skipping upload");O.current&&O.current.getTracks().forEach(P=>P.stop());const C=y;C&&!c&&await ae.post("https://api.prepin.ai/api/v2/videocall/end-interview",{interviewId:x,roundName:b,callId:C,emotions:Te.current},{withCredentials:!0}),qe(),i?te("Interview Completed","success","Your interview has been submitted successfully with video recording."):te("Interview Completed (Video Upload Failed)","warning","Your interview was submitted but the video recording could not be uploaded. Your audio and transcript were saved.")}catch(C){console.error("End interview error:",C),c?(console.log("Demo End: Proceeding despite error (likely session mismatch in demo mode)"),qe()):(te("Interview Ended","error","There was an issue processing your interview. Please contact support if you don't see your results.",null,8e3),o("/interview-board"))}},[fe,ce,w,y,x,b,o]);n.useEffect(()=>{if(!k)return;const i=l=>{er.current=l};k.on("volume-level",i);const f=l=>{l.type==="transcript"&&(cr(l),Z.current&&Z.current.markDirty())};return k.on("message",f),()=>{k.off("volume-level",i),k.off("message",f)}},[k]),n.useEffect(()=>{(async()=>{const f="/models";
19try{await Promise.all([me.tinyFaceDetector.loadFromUri(f),me.faceLandmark68Net.loadFromUri(f),me.faceExpressionNet.loadFromUri(f),me.ageGenderNet.loadFromUri(f)]),tr(!0),console.log("✅ Face detection models loaded")}catch(l){console.error("Failed to load face models:",l)}})()},[]),n.useEffect(()=>{if(a!=="active"||!Re||!S.current)return;const i=async()=>{if(!(!S.current||S.current.paused||S.current.ended))try{const l=await Vr(S.current,new _r).withFaceLandmarks().withFaceExpressions().withAgeAndGender();if(l){const{x:h,y:C,width:P,height:Ae}=l.detection.box;if($e&&A.current){const j=A.current.getContext("2d");j&&((A.current.width!==S.current.videoWidth||A.current.height!==S.current.videoHeight)&&(A.current.width=S.current.videoWidth,A.current.height=S.current.videoHeight),j.clearRect(0,0,A.current.width,A.current.height),j.strokeStyle="#00bfff",j.lineWidth=2,j.strokeRect(h,C,P,Ae))}else if(A.current){const j=A.current.getContext("2d");j==null||j.clearRect(0,0,A.current.width,A.current.height)}const pe=l.expressions,he=l.landmarks,X=pe.asSortedArray?Object.fromEntries(pe.asSortedArray().map(j=>[j.expression,j.probability])):pe,H=ot(X),ke=it(he),ie={timestamp:new Date().toISOString(),engagementLevel:nt(H),gazeStatus:st(ke),dominantEmotion:at(X),aiQuestion:we.current||"General Discussion",age:l.age,gender:l.gender,probability:Object.values(X).sort((j,dr)=>dr-j)[0]||0,box:{x:h,y:C,width:P,height:Ae}};Te.current.push(ie)}else if(A.current){const h=A.current.getContext("2d");h==null||h.clearRect(0,0,A.current.width,A.current.height)}}catch(l){console.warn("Detection error:",l)}},f=setTimeout(()=>{i(),Se.current=setInterval(i,1e3)},1e4);return()=>{clearTimeout(f),Se.current&&clearInterval(Se.current)}},[a,Re,$e]);const Ne=async()=>{var i,f,l,h;if(!_e){Fe(!0),Ve([]);try{const P=ee.filter(H=>H.role==="assistant"&&(H.committed||H.temp)).slice(-2).map(H=>(H.committed+(H.temp||"")).trim()).filter(H=>H.length>0);P.length===0&&P.push(`Interview for ${(s==null?void 0:s.customPosition)||"this role"} at ${(s==null?void 0:s.companyName)||"this company"}`);const he=(await ae.post("https://api.prepin.ai/api/videocall/generate-suggested-answer",{questions:P,interviewId:x,positionDescription:(s==null?void 0:s.positionDescription)||((i=s==null?void 0:s.goal)==null?void 0:i.jobDescription)||"",candidateInfo:{interviewId:x,skills:((f=s==null?void 0:s.resume)==null?void 0:f.skills)||[],experience:((l=s==null?void 0:s.resume)==null?void 0:l.experience)||[],education:((h=s==null?void 0:s.resume)==null?void 0:h.education)||[]}},{withCredentials:!0})).data.suggestedHints||[],X=[];he.forEach((H,ke)=>{const ie=H.match(/### STRATEGIC_ADVICE:?([\s\S]*?)(?=### KEY_POINTS|$)/i),j=H.match(/### KEY_POINTS:?([\s\S]*)/i);ie||j?(ie&&X.push({title:"Strategic Advice",content:ie[1].trim()}),j&&X.push({title:"Key Highlights",content:j[1].trim()})):X.push({title:`Strategic Advice ${he.length>1?ke+1:""}`,content:H})}),Ve(X),sr(!0)}catch(C){console.error("AI Copilot Error:",C),te("Copilot Error","error","Failed to generate suggestions. Please try again.",null,3e3)}finally{Fe(!1)}}};return n.useEffect(()=>(a===z.ACTIVE&&!Z.current&&(Z.current=new Ur(x,b),Z.current.start(()=>({conversation:ee,duration:0}),async i=>{await ae.post("https://api.prepin.ai/api/v2/videocall/auto-save",i,{withCredentials:!0})})),()=>{Z.current&&Z.current.stop()}),[a]),t.jsxs($,{w:"100vw",h:"100vh",bg:"white",overflow:"hidden",position:"relative",color:"gray.800",children:[t.jsx(Br,{agent:"screening",status:a,voiceState:je?"thinking":"listening",processing:fe}),t.jsx(Wr,{interviewData:s,callStatus:a,onCopilotClick:()=>{ne("copilot"),Ne()},isGeneratingHints:_e,top:8,left:10}),t.jsx(De,{children:G&&t.jsx(le.div,{initial:{opacity:0,x:-20,scale:.95},animate:{opacity:1,x:0,scale:1},exit:{opacity:0,x:-20,scale:.95},transition:{duration:.3},style:{position:"absolute",top:"25%",left:"20px",zIndex:10,maxWidth:"500px",width:"100%",transform:"translateY(-50%)"},children:t.jsxs($,{p:5,bg:"rgba(10, 10, 10, 0.90)",color:"white",backdropFilter:"blur(16px)",borderRadius:"2xl",boxShadow:"xl",border:"1px solid",borderColor:"gray.700",position:"relative",maxH:"60vh",overflowY:"auto",children:[t.jsx(K,{icon:t.jsx(Ce,{}),size:"xs",position:"absolute",top:3,right:3,variant:"ghost",color:"whiteAlpha.700",onClick:()=>ne(null)}),t.jsxs(oe,{mb:4,spacing:3,borderBottom:"1px solid",borderColor:"gray.700",pb:3,align:"center",children:[G==="copilot"&&t.jsx(Y,{as:Ue,boxSize:5,color:"gray.400"}),G==="resume"&&t.jsx(Y,{as:Be,boxSize:5,color:"gray.400"}),G==="job"&&t.jsx(Y,{as:We,boxSize:5,color:"gray.400"}),t.jsx(D,{fontSize:"md",fontWeight:"bold",color:"gray.200",letterSpacing:"wide",children:G==="copilot"?"Copilot Suggestions":G==="resume"?"User Resume":"Position Description"})]}),t.jsx(se,{align:"stretch",spacing:2,divider:G==="copilot"?null:t.jsx($,{w:"full",h:"1px",bg:"whiteAlpha.100"}),children:G==="copilot"?Le.length>0?t.jsx(hr,{allowToggle:!0,allowMultiple:!0,defaultIndex:[0],border:"transparent",children:Le.map((i,f)=>t.jsx(mr,{border:"none",mb:2,children:({isExpanded:l})=>t.jsxs(t.Fragment,{children:[t.jsxs(br,{_expanded:{bg:"whiteAlpha.100",borderRadius:"md"},px:2,py:3,_hover:{bg:"whiteAlpha.100",borderRadius:"md"},children:[l?t.jsx(Y,{as:xr,color:"gray.400",mr:3}):t.jsx(Y,{as:yr,color:"gray.400",mr:3}),t.jsx($,{flex:"1",textAlign:"left",children:t.jsx(D,{fontSize:"sm",fontWeight:"bold",color:"gray.200",children:i.title})})]}),t.jsx(vr,{pb:4,px:4,bg:"blackAlpha.200",borderRadius:"md",mt:1,children:t.jsx($,{fontSize:"sm",color:"gray.300",lineHeight:"tall",children:t.jsx(Or,{text:i.content})})})]})},f))}):t.jsx(D,{fontSize:"xs",color:"gray.400",fontStyle:"italic",px:2,children:"Analyzing conversation context..."}):t.jsx($,{fontSize:"sm",color:"gray.300",whiteSpace:"pre-wrap",lineHeight:"relaxed",children:Qe(G==="resume"?(s==null?void 0:s.resume)||"No resume found.":(s==null?void 0:s.positionDescription)||"No job description found.")})})]})})}),t.jsxs(se,{position:"absolute",top:m?"15%":"45%",right:"20px",transform:m?"none":"translateY(-50%)",zIndex:30,al
19ign:m?"stretch":"end",spacing:4,width:m?"400px":"350px",maxH:m?"70vh":"auto",bg:m?"rgba(255, 255, 255, 0.95)":"transparent",backdropFilter:m?"blur(16px)":"none",borderRadius:"2xl",p:m?5:0,boxShadow:m?"2xl":"none",border:m?"1px solid":"none",borderColor:"gray.200",transition:"all 0.3s ease",pointerEvents:m?"auto":"none",children:[m&&t.jsxs(oe,{mb:2,justify:"space-between",borderBottom:"1px solid",borderColor:"gray.00",pb:3,pointerEvents:"auto",children:[t.jsxs(oe,{spacing:2,children:[t.jsx(Y,{as:wr,color:"gray.500"}),t.jsx(D,{fontSize:"sm",fontWeight:"bold",color:"gray.800",letterSpacing:"wide",children:"FULL TRANSCRIPT"})]}),t.jsx(K,{icon:t.jsx(Ce,{}),size:"xs",variant:"ghost",color:"gray.400",onClick:()=>Me(!1)})]}),t.jsx($,{ref:ge,overflowY:m?"auto":"visible",w:"full",pr:m?2:0,sx:{"&::-webkit-scrollbar":{width:"4px"},"&::-webkit-scrollbar-track":{background:"transparent"},"&::-webkit-scrollbar-thumb":{background:"gray.200",borderRadius:"10px"}},children:t.jsxs(se,{align:m?"stretch":"end",spacing:4,children:[t.jsx(De,{mode:"popLayout",children:(m?ee:ee.slice(-2)).map(i=>t.jsxs(le.div,{layout:!0,initial:{opacity:0,y:30,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.9,transition:{duration:.2}},transition:{duration:.3},style:{width:"100%",display:"flex",justifyContent:i.role==="user"?"flex-end":"flex-start"},children:[i.role!=="user"&&t.jsx(Ee,{size:"sm",src:Xe,name:"Recruiter",mr:2,alignSelf:"flex-start",mt:1}),t.jsxs($,{bg:i.role==="user"?m?"blue.500":"rgba(10, 10, 10, 0.85)":"rgba(255, 255, 255, 0.95)",color:i.role==="user"?"white":"gray.800",px:4,py:3,borderRadius:"2xl",borderTopRightRadius:i.role==="user"?"none":"2xl",borderTopLeftRadius:i.role==="user"?"2xl":"none",maxW:m?"90%":"85%",boxShadow:"sm",border:"1px solid",borderColor:i.role==="user"?m?"blue.600":"gray.700":"gray.200",children:[!m&&t.jsx(D,{fontSize:"xs",fontWeight:"bold",color:i.role==="user"?"gray.400":"gray.500",mb:1,children:i.role==="user"?"YOU":"RECRUITER"}),t.jsxs(D,{fontSize:"sm",lineHeight:"tall",children:[i.committed,t.jsx("span",{style:{opacity:.6},children:i.temp})]})]}),i.role==="user"&&!m&&t.jsx(Ee,{size:"sm",src:r==null?void 0:r.avatar,name:(r==null?void 0:r.username)||"You",ml:2,alignSelf:"flex-start",mt:1})]},i.id))}),je&&t.jsxs(le.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0},transition:{duration:.3},style:{width:"100%",display:"flex",justifyContent:"flex-start",alignItems:"flex-start"},children:[t.jsx(Ee,{size:"sm",src:Xe,name:"Recruiter",mr:2,mt:1}),t.jsx(Zr,{})]})]})})]}),t.jsx($,{position:"absolute",top:8,right:10,zIndex:10,children:t.jsxs(oe,{bg:"rgba(10, 10, 10, 0.85)",backdropFilter:"blur(12px)",px:4,py:2,borderRadius:"full",spacing:2,boxShadow:"0 4px 12px rgba(0,0,0,0.1)",children:[t.jsx(Y,{as:Sr,color:"gray.300"}),t.jsx(lt,{initialTime:V,isActive:a==="active",onTimeUp:He})]})}),t.jsx(le.div,{drag:q==="pip",dragConstraints:q==="pip"?{left:0,right:window.innerWidth-300,top:0,bottom:window.innerHeight-300}:void 0,whileHover:q==="pip"?{scale:1.02}:{},animate:q==="center"?{top:"50%",left:"50%",x:"-50%",y:"-50%",width:"500px",height:"500px",borderRadius:"24px",zIndex:15}:{top:"calc(100% - 280px)",left:"40px",x:0,y:0,width:"240px",height:"240px",borderRadius:"50%",zIndex:20},transition:{type:"spring",stiffness:260,damping:20},style:{position:"absolute",cursor:q==="pip"?"grab":"default",boxShadow:"0 20px 50px -10px rgba(0,0,0,0.5)"},children:t.jsx($,{w:"100%",h:"100%",overflow:"hidden",border:"4px solid",borderColor:"gray.200",bg:"gray.200",borderRadius:"inherit",children:a==="inactive"&&!O.current?t.jsx(se,{h:"full",justify:"center",bg:"gray.50",position:"relative",overflow:"hidden",_before:{content:'""',position:"absolute",top:0,left:0,right:0,bottom:0,backgroundImage:'url("https://cdn.prod.website-files.com/6286650c317fddfbb431b9c1/62f218c3111e07bb0aae6f71_Dots-faded-graphic.svg")',backgroundSize:"cover",backgroundPosition:"center",opacity:.5,zIndex:0},children:t.jsx(se,{zIndex:1,children:t.jsx(Y,{as:Ir,boxSize:12,color:"gray.300"})})}):t.jsxs(t.Fragment,{children:[t.jsx("video",{ref:S,autoPlay:!0,playsInl
19ine:!0,muted:!0,style:{width:"100%",height:"100%",objectFit:"cover",transform:"scaleX(-1)",pointerEvents:"none"}}),t.jsx("canvas",{ref:A,style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",transform:"scaleX(-1)"}})]})})}),t.jsx(Gr,{isOpen:fe,onClose:()=>Pe(!1),interviewId:x,roundName:b,position:s==null?void 0:s.customPosition,companyName:s==null?void 0:s.companyName}),(a==="inactive"||a==="loading")&&t.jsx(jr,{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",zIndex:20,bg:"white",color:"gray.900",fontSize:"md",fontWeight:"medium",borderRadius:"full",px:4,py:3,h:"auto",boxShadow:"0 10px 30px rgba(0,0,0,0.15)",_hover:{transform:"translate(-50%, -52%)",boxShadow:"0 15px 35px rgba(0,0,0,0.2)"},_active:{transform:"translate(-50%, -50%)",scale:.98},onClick:ur,isLoading:a==="loading",loadingText:"Connecting...",leftIcon:t.jsx($,{bg:"black",borderRadius:"full",p:1.5,display:"flex",alignItems:"center",justifyContent:"center",children:t.jsx(Y,{as:Ar,color:"white",boxSize:3.5})}),children:"Start Interview"}),a!=="inactive"&&a!=="loading"&&t.jsx($,{position:"absolute",bottom:8,left:"50%",transform:"translateX(-50%)",zIndex:20,children:t.jsx(oe,{bg:"rgba(10, 10, 10, 0.85)",backdropFilter:"blur(12px)",borderRadius:"full",px:6,py:3,spacing:4,boxShadow:"0 8px 32px rgba(0,0,0,0.2)",children:t.jsxs(t.Fragment,{children:[t.jsx(re,{label:"End Interview",bg:"gray.100",color:"black",hasArrow:!0,children:t.jsx(K,{"aria-label":"End Interview",icon:t.jsx(Ce,{size:20}),colorScheme:"red",bg:"red.500",color:"gray.300",_hover:{bg:"red.600"},onClick:He,borderRadius:"full",size:"md"})}),t.jsx($,{w:"1px",h:"16px",bg:"gray.600"}),t.jsx(re,{label:q==="pip"?"Center Video":"Picture-in-Picture",bg:"gray.100",color:"black",hasArrow:!0,children:t.jsx(K,{"aria-label":"Resize Video",icon:q==="pip"?t.jsx(kr,{size:20}):t.jsx(Cr,{size:20}),onClick:()=>{or(q==="pip"?"center":"pip")},variant:"ghost",color:"gray.300",_hover:{bg:"whiteAlpha.200"},borderRadius:"full",size:"sm"})}),t.jsx(re,{label:Ie?"Mute Microphone":"Unmute Microphone",bg:"gray.100",color:"black",hasArrow:!0,children:t.jsx(K,{"aria-label":"Toggle Mic",icon:Ie?t.jsx(Er,{size:20}):t.jsx(Rr,{size:20}),onClick:()=>{nr(i=>{if(k)try{k.setMuted(i)}catch(f){console.error("Failed to toggle mic:",f)}return!i})},variant:"ghost",color:Ie?"gray.300":"red.400",_hover:{bg:"whiteAlpha.200"},borderRadius:"full",size:"sm"})}),t.jsxs($r,{children:[t.jsx(re,{label:"View Documents",bg:"gray.100",color:"black",hasArrow:!0,children:t.jsx(zr,{as:K,"aria-label":"Documents",icon:t.jsx(Tr,{size:20}),variant:"ghost",color:"gray.300",_hover:{bg:"whiteAlpha.200"},borderRadius:"full",size:"sm"})}),t.jsxs(Mr,{bg:"rgba(10, 10, 10, 0.85)",borderColor:"gray.800",backdropFilter:"blur(12px)",boxShadow:"2xl",mb:3,children:[t.jsx(Ge,{icon:t.jsx(We,{}),onClick:()=>ne("job"),_hover:{bg:"whiteAlpha.200"},bg:"transparent",color:"gray.200",fontSize:"sm",children:"Position Description"}),t.jsx(Ge,{icon:t.jsx(Be,{}),onClick:()=>ne("resume"),_hover:{bg:"whiteAlpha.200"},bg:"transparent",color:"gray.200",fontSize:"sm",children:"User Resume"})]})]}),t.jsx(re,{label:"AI Copilot Hints",bg:"gray.100",color:"black",hasArrow:!0,children:t.jsx(K,{"aria-label":"AI Copilot",icon:t.jsx(Ue,{size:20}),variant:"ghost",color:ir?"purple.300":"gray.300",_hover:{bg:"whiteAlpha.200"},borderRadius:"full",size:"sm",onClick:()=>{ne("copilot"),Ne()}})}),t.jsx(re,{label:"View Transcript",bg:"gray.100",color:"black",hasArrow:!0,children:t.jsx(K,{"aria-label":"View Transcript",icon:t.jsx(Lr,{size:20}),variant:"ghost",color:m?"blue.300":"gray.300",_hover:{bg:"whiteAlpha.200"},borderRadius:"full",size:"sm",onClick:()=>Me(!m)})})]})})})]})};export{ft 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.