1import{k as Y,o as U,r as t,c_ as H,B,j as e,bk as D,bl as P,az as L,bm as W,aG as $,X as K,D as Q,c$ as Z}from"./index-BQExbPNd.js";import{u as X,a as q,M as G,b as V}from"./index-BHnDJFYl.js";const ee="https://ywktqjrmhryjhtgqojxn.supabase.co/functions/v1/arrow-ai-chat";function se(){const{user:r}=Y(),{subscription:n}=U(),{messages:u,addMessage:x,updateLastAssistant:j,clearHistory:_,minutesRemaining:b}=X((r==null?void 0:r.id)??null),[M,f]=t.useState(!1),g=t.useRef(null),m=H(),d=t.useCallback(async p=>{var w,I,A,i,k,y;x("user",p),f(!0);let v="";const N=new AbortController;g.current=N;const S=[...u.map(l=>({role:l.role,content:l.content})),{role:"user",content:p}];try{const l=await fetch(ee,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inl3a3RxanJtaHJ5amh0Z3FvanhuIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzQ3MjMwMzYsImV4cCI6MjA5MDI5OTAzNn0.uxrFT_kwpv-Q2kWYNEkB7uEuBvZByhYOdvIpg-AhsYM"},body:JSON.stringify({messages:S,currentRoute:m.pathname,userContext:n?{plan:n.plan,planStatus:n.plan_status,trialEndsAt:n.trial_ends_at,trialResumesUsed:n.trial_resumes_used,trialCoverLettersUsed:n.trial_cover_letters_used,resumesUsed:n.resumes_used,resumesLimit:n.resumes_limit}:void 0}),signal:N.signal});if(!l.ok){const o=await l.json().catch(()=>({error:"Request failed"}));B.error(o.error||"Something went wrong"),f(!1);return}if(!l.body)throw new Error("No response body");const C=l.body.getReader(),s=new TextDecoder;let a="";const T=o=>{v+=o,j(v)};let O=!1;for(;!O;){const{done:o,value:E}=await C.read();if(o)break;a+=s.decode(E,{stream:!0});let R;for(;(R=a.indexOf(` 2`))!==-1;){let c=a.slice(0,R);if(a=a.slice(R+1),c.endsWith("\r")&&(c=c.slice(0,-1)),c.startsWith(":")||c.trim()===""||!c.startsWith("data: "))continue;const z=c.slice(6).trim();if(z==="[DONE]"){O=!0;break}try{const J=(A=(I=(w=JSON.parse(z).choices)==null?void 0:w[0])==null?void 0:I.delta)==null?void 0:A.content;J&&T(J)}catch{a=c+` 3`+a;break}}}if(a.trim())for(let o of a.split(` 4`)){if(!o||(o.endsWith("\r")&&(o=o.slice(0,-1)),o.startsWith(":")||o.trim()==="")||!o.startsWith("data: "))continue;const E=o.slice(6).trim();if(E!=="[DONE]")try{const c=(y=(k=(i=JSON.parse(E).choices)==null?void 0:i[0])==null?void 0:k.delta)==null?void 0:y.content;c&&T(c)}catch{}}}catch(l){l.name!=="AbortError"&&(console.error("ArrowAI stream error:",l),B.error("Failed to get a response. Please try again."))}finally{f(!1),g.current=null}},[u,m.pathname,x,j]),h=t.useCallback(()=>{var p;(p=g.current)==null||p.abort()},[]);return{messages:u,isStreaming:M,sendMessage:d,clearMessages:_,stopStreaming:h,minutesRemaining:b}}const F={"/forge":"Need help generating your first resume? Tell me the role you're targeting and I'll walk you through it.","/tracker":"Ready to start tracking? Add your first application and I'll show you how to set up your pipeline.","/interview-prep":"Got an interview coming up? Tell me the role and company and I'll show you how to prep in under 5 minutes."};function te(){return e.jsxs("div",{className:"flex items-center gap-1 px-3 py-2",children:[e.jsx("span",{className:"h-2 w-2 rounded-full bg-muted-foreground/40 animate-bounce [animation-delay:0ms]"}),e.jsx("span",{className:"h-2 w-2 rounded-full bg-muted-foreground/40 animate-bounce [animation-delay:150ms]"}),e.jsx("span",{className:"h-2 w-2 rounded-full bg-muted-foreground/40 animate-bounce [animation-delay:300ms]"})]})}function ie(){var C;const[r,n]=t.useState(()=>sessionStorage.getItem("arrowai_open")==="true");t.useEffect(()=>{sessionStorage.setItem("arrowai_open",String(r))},[r]);const[u,x]=t.useState(""),[j,_]=t.useState(!1),[b,M]=t.useState(new Set),f=t.useRef(null),g=t.useRef(null),m=H(),{messages:d,isStreaming:h,sendMessage:p,clearMessages:v,stopStreaming:N,minutesRemaining:S}=se(),w=t.useRef(u);w.current=u;const I=t.useCallback(()=>{const s=w.current.trim();s&&(x(""),p(s))},[p]),A=t.useCallback(s=>x(s),[]),i=q(A,I);t.useEffect(()=>{const s=setTimeout(()=>_(!0),3e3);return()=>clearTimeout(s)},[]),t.useEffect(()=>{const s=a=>
4{(a.metaKey||a.ctrlKey)&&a.key==="/"&&(a.preventDefault(),n(T=>!T)),a.key==="Escape"&&r&&n(!1)};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[r]),t.useEffect(()=>{r&&setTimeout(()=>{var s;return(s=g.current)==null?void 0:s.focus()},350)},[r]),t.useEffect(()=>{var s;(s=f.current)==null||s.scrollTo({top:f.current.scrollHeight,behavior:"smooth"})},[d,h]),t.useEffect(()=>{r&&!b.has(m.pathname)&&F[m.pathname]&&d.length===0&&M(s=>new Set(s).add(m.pathname))},[r,m.pathname,b,d.length]);const k=b.has(m.pathname)?void 0:F[m.pathname],y=()=>{const s=u.trim();!s||h||(x(""),p(s))},l=s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),y())};return e.jsxs(e.Fragment,{children:[!r&&e.jsxs(D,{children:[e.jsx(P,{asChild:!0,children:e.jsx("button",{onClick:()=>n(!0),style:{bottom:"calc(var(--ai-bar-height, 0px) + 0.75rem)"},className:`fixed right-6 z-[60] h-14 w-14 rounded-full bg-primary text-primary-foreground shadow-lg flex items-center justify-center transition-all hover:scale-105 focus:outline-none focus-visible:ring-2 focus-visible:ring-ring ${j?"":"animate-pulse"}`,"aria-label":"Open ArrowAI assistant",children:e.jsx(L,{className:"h-6 w-6"})})}),e.jsx(W,{side:"left",children:e.jsxs("p",{children:["ArrowAI ",e.jsx("span",{className:"text-muted-foreground text-xs ml-1",children:"Ctrl+/"})]})})]}),r&&e.jsxs("div",{role:"dialog","aria-label":"ArrowAI chat",className:`fixed bottom-6 right-6 z-[60] flex flex-col bg-background border border-border rounded-2xl shadow-2xl overflow-hidden animate-scale-in 5 w-[420px] h-[600px] max-sm:inset-0 max-sm:bottom-0 max-sm:right-0 max-sm:w-full max-sm:h-full max-sm:rounded-none max-sm:border-0`,children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border bg-card",children:[e.jsx("div",{className:"h-8 w-8 rounded-full bg-primary flex items-center justify-center flex-shrink-0",children:e.jsx(L,{className:"h-4 w-4 text-primary-foreground"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground leading-tight",children:"ArrowAI"}),d.length>0&&S>0&&e.jsxs("span",{className:"text-[11px] text-muted-foreground/50",children:["clears in ",S,"m"]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-tight",children:"Your Quivr'd guide"})]}),e.jsxs(D,{children:[e.jsx(P,{asChild:!0,children:e.jsx("button",{onClick:v,className:"p-1.5 rounded-lg hover:bg-muted text-muted-foreground transition-colors","aria-label":"Clear conversation",children:e.jsx($,{className:"h-4 w-4"})})}),e.jsx(W,{children:"Clear conversation"})]}),e.jsx("button",{onClick:()=>n(!1),className:"p-1.5 rounded-lg hover:bg-muted text-muted-foreground transition-colors","aria-label":"Close ArrowAI",children:e.jsx(K,{className:"h-4 w-4"})})]}),e.jsxs("div",{ref:f,className:"flex-1 overflow-y-auto px-4 py-3 space-y-3",children:[d.length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center gap-3 py-8",children:[e.jsx("div",{className:"h-12 w-12 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx(L,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Hey! I'm ArrowAI."}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 max-w-[280px]",children:k||"Ask me anything about Quivr'd or your career. I'm here to help you hit your target."})]})]}),d.map((s,a)=>e.jsx(re,{message:s},a)),h&&((C=d[d.length-1])==null?void 0:C.role)!=="assistant"&&e.jsx("div",{className:"flex justify-start",children:e.jsx("div",{className:"bg-card border border-border rounded-xl px-3 py-2",children:e.jsx(te,{})})})]}),e.jsxs("div",{className:"border-t border-border bg-card px-3 py-2.5 flex items-end gap-2",children:[i.supported&&e.jsx(G,{isListening:i.isListening,autoSendProgress:i.autoSendProgress,onStart:i.startListening,onStop:i.stopListening}),e.jsx("textarea",{ref:g,value:u,onChange:s=>x(s.target.value),onKeyDown:l,placeholder:i.isListening&&i.autoSendProgress===0?"ðï¸ Listening...":i.isListening&&i.autoSendProgress>0?"Sending in a moment, tap mic to cancel":"Ask ArrowAI anything...",rows:1,className:"flex-1 resize-none bg-transparent text-sm text-foreground placeholder:text-muted-foreground focus:outline-none max-h-24 min-h-[36px] py-2",style:{scrollbarWidth:"thin"}}),e.jsx(Q,{size:"icon",variant:"ghost",onClick:h?N:y,disabled:!h&&!u.trim(),className:"flex-shrink-0 h-9 w-9","aria-label":h?"Stop generating":"Send message",children:h?e.jsx("div",{className:"h-3.5 w-3.5 rounded-sm bg-foreground"}):e.jsx(Z,{className:"h-4 w-4"})})]})]})]})}function re({message:r}){const n=r.role==="user";return e.jsx("div",{className:`flex ${n?"justify-end":"justify-start"}`,children:e.jsx("div",{className:`max-w-[85%] rounded-xl px-3 py-2 text-sm leading-relaxed ${n?"bg-primary text-primary-foreground rounded-br-sm":"bg-card border border-border text-foreground rounded-bl-sm"}`,children:n?e.jsx("p",{className:"whitespace-pre-wrap",children:r.content}):e.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none [&>*:first-child]:mt-0 [&>*:last-child]:mb-0 [&_p]:my-1 [&_ul]:my-1 [&_ol]:my-1 [&_li]:my-0",children:e.jsx(V,{children:r.content})})})})}export{ie as ArrowAIPanel};
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.