1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/aurora-voice-S2ydCitH.js","assets/index-DP61GySm.js","assets/vendor-shared-C5tCw9rW.js","assets/index-BJf8nW0N.css","assets/index-MuG4xkEZ.js","assets/loader-circle-eo-mph3g.js","assets/utils-hQAQiId-.js","assets/x-D235ZOFZ.js","assets/shield-check-BQHCFnRX.js","assets/App-0t6TVAR4.js","assets/use-toast-C6aFH3Eg.js","assets/toaster-BDyw2x6L.js","assets/triangle-alert-CaKCF_Nq.js","assets/section-chips-C68mRSIN.js","assets/chevron-right-qcpptIv2.js","assets/chevron-down-C8mjF8sg.js","assets/trademark-screen-DYufZ-CB.js","assets/sparkles-B4yqwNG6.js","assets/waypoints-C6gFN1cM.js","assets/dialog-B9xd4dRw.js","assets/privacy-I8Fotoxq.js","assets/image-off-CpRV4JaY.js","assets/trial-copy-BQN_0jwW.js","assets/unicorniq-logo-B9mOeuD0.js","assets/App-Bri3Sjey.css","assets/use-live-voice-CicYznrM.js","assets/use-reduced-motion-Dfod_7YK.js","assets/proxy-vcxmOnCc.js","assets/radio-BCn28_eD.js","assets/layout-dashboard-Bx_VpmEh.js"])))=>i.map(i=>d[i]); 2import{_ as Hi}from"./vendor-shared-C5tCw9rW.js";import{r as y,j as e,B as O,R as b,b as en}from"./index-DP61GySm.js";import{L as gs,u as Ha,c as Yi}from"./index-MuG4xkEZ.js";import{au as Ya,aa as Xi,av as Wt,aw as tn,ax as Xa,ay as Wn,az as Hn,aA as Ja,aB as Ji,aq as Za,aC as er,aD as tr,aE as sr,aF as nr,aG as ar,aH as rr,aI as ir,aJ as or,aK as ln,aL as Yn,aM as cn,aN as dn,aO as un,aP as mn,R as lr,p as cr,aQ as bs,aR as Zi,n as js,ag as hn,aS as It,aT as dr,o as eo,B as ur,D as to,aU as so,aV as no,L as Pt,aW as ao,aX as ro,aY as io,aZ as oo,a_ as lo,a$ as _e,b0 as Fe,b1 as co,b2 as qe,b3 as uo,b4 as mo,b5 as ho,b6 as po,b7 as xo,b8 as Xn,v as Dt,b9 as fo,ba as go,bb as vo,bc as yo,bd as Jn,a1 as bo,a2 as jo,be as wo,bf as No,bg as ko,bh as Co,bi as So,bj as Po,a5 as Do,bk as Zn,bl as Io,bm as mr,bn as To,A as Ss,bo as $o,bp as pn,bq as Le,br as hr,bs as pr,bt as xr,bu as Eo,bv as zs,a8 as Ro,bw as Ao,bx as ea,by as Vs,bz as Lo,bA as Mo,bB as Oo,ae as ta,bC as fr,bD as gr,bE as Ko,bF as _o,ad as sa,bG as Fo,bH as qo,bI as Uo,bJ as na,bK as sn,bL as zo,bM as Vo,bN as Qo,bO as Go,ar as aa,ah as Bo,ai as Wo,G as Ho,bP as Yo,bQ as Xo,bR as Jo,bS as Zo,bT as el,bU as tl,bV as sl,bW as nl,bX as al,bY as rl,bZ as il,b_ as ol,b$ as ll,c0 as cl,c1 as dl,c2 as ul,t as ml,c3 as ra,c4 as ia,c5 as hl,c6 as pl,c7 as xl,c8 as fl,c9 as gl,ca as vl,cb as yl,cc as bl,cd as jl,ce as wl,cf as oa,cg as la,ch as Nl,ci as kl,cj as Cl}from"./App-0t6TVAR4.js";import{E as D,hU as Sl,hV as Pl,a2 as re,u as Ae,hW as vr,hX as xn,ex as yr,hY as Dl,hZ as Il,h_ as Tl,h$ as $l,i0 as El,i1 as ca,cY as Rl,i2 as da,i3 as Al,i4 as Ll,i5 as Ml,i6 as ua,z as Ps,ad as Ol,af as Kl,ag as _l,ae as ma,i7 as Fl,i8 as ql,i9 as ha,ia as Ul,ib as zl,ic as pa,id as br,ie as jr,C as wr,ig as Nr,ih as kr,ii as Cr,ij as Sr,ik as Te,ak as Vl,am as Ql,co as Gl,hC as Bl,a1 as Ke,a3 as Bt,il as Wl,im as Hl,io as Yl,ip as Pr,iq as Xl,ir as Jl,is as Zl,it as ec,iu as tc,iv as sc,iw as nc,cC as ac,cD as rc,ix as ic,f_ as oc,iy as lc,eW as cc,eY as dc,iz as uc,$ as mc,iA as hc,iB as pc,iC as xc,iD as fc,iE as gc,iF as vc,iG as yc,iH as bc,iI as jc,iJ as Qs,iK as Gs,iL as wc,iM as Nc,iN as kc,iO as Cc,iP as Sc,a0 as Pc,iQ as Dc,iR as Ic,iS as Tc,iT as $c,a4 as Ec,gG as Rc,iU as xa,iV as Ac}from"./loader-circle-eo-mph3g.js";import{S as fa,a as ga,b as va,c as ya,d as ba}from"./sheet-D99CNdnz.js";import{f as Ze,g as et,h as tt,i as st,j as dt,n as kt}from"./dialog-B9xd4dRw.js";import{u as Be,E as Vt}from"./use-toast-C6aFH3Eg.js";import{K as Dr,M as fn,u as Ir,i as ws,a as Xe,b as Lc,k as Tr,c as vs,d as ys,n as Mc,e as Oc,f as Kc,g as xs,h as _c,j as Bs,l as Ws}from"./kb-upload-api-B1JOirbx.js";import{d as Fc,U as qc,a as ja}from"./toaster-BDyw2x6L.js";import{s as Uc,D as zc}from"./document-detail-dialog-BLfinBwu.js";import{p as Vc,s as $r,A as Qc}from"./chat-uploads-5XGD425p.js";import{I as $e,T as Ue}from"./triangle-alert-CaKCF_Nq.js";import{K as Gc,t as gn,w as vn,x as yn,J as Ge,a0 as Bc,a1 as Wc,a2 as Hc,a3 as Yc,y as Er,b as Ct,z as Ns,e as Rr,l as Ar,G as Xc,H as Jc,d as wa}from"./section-chips-C68mRSIN.js";import{C as ct}from"./chevron-down-C8mjF8sg.js";import{C as Zc}from"./chevron-right-qcpptIv2.js";import{c as Tt,S as ed}from"./shield-check-BQHCFnRX.js";import{F as td}from"./folder-input-IIBl3awU.js";import{S as sd}from"./share-2-DlC9FCa-.js";import{A as nd}from"./answer-claims-dialog-cLRblHg9.js";import{S as ad}from"./share-to-google-chat-C1nFdIqo.js";import{A as rd}from"./ask-expert-button-CFrGDSSp.js";import{X as ut}from"./x-D235ZOFZ.js";import{u as nn,T as an}from"./trademark-screen-DYufZ-CB.js";import{i as id,C as od}from"./cross-source-answer-card-kSSbjfwy.js";import{R as ld}from"./report-dialog-DAjRkQLP.js";import{m as cd,W as dd}from"./world-resource-link-DED65ywg.js";import{S as Je}from"./sparkles-B4yqwNG6.js";import{a as ud}from"./privacy-I8Fotoxq.js";import{T as md}from"./trial-copy-BQN_0jwW.js";import{L as hd}from"./lock-keyhole-DRXxCDV9.js";import{C as pd}from"./calendar-days-DsnPAiiR.js";import{D as xd,a as fd}from"./data-flow-callout-DRYgBXYy.js";import{M as gd}from"./message-square-heart-BXjW7pI6.js";import{u as Lr}from"./use-media-rights-consent-EL3INCxg.js";import{u as vd}from"./duplicate-upload-dialog-9XXVB_WB.js";import{R as yd}from"./rotate-cw-CRf4CPTQ.js";import{L as bd}from"./waypoints-C6gFN1cM.js";import{F as Mr}from"./file-up-DKyCZgN7.js";import{C as Or}from"./cloud-upload-OPb8kvTp.js";
2import{F as jd}from"./folder-closed-D8hGNs0d.js";import{c as wd}from"./utils-hQAQiId-.js";import{M as Nd}from"./menu-Z2GmzAob.js";import"./image-off-CpRV4JaY.js";import"./unicorniq-logo-B9mOeuD0.js";import"./recycle-BgsBJ7Hu.js";import"./publish-dialog-DLwc6n0D.js";import"./sop-tab-DquWwQTO.js";import"./user-round-search-BfSQZyn0.js";const kd=[["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]],Kr=Tt("folder-minus",kd);const Cd=[["path",{d:"M10.7 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v4.1",key:"1bw5m7"}],["path",{d:"m21 21-1.9-1.9",key:"1g2n9r"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}]],Sd=Tt("folder-search",Cd);const Pd=[["path",{d:"M12 19h.01",key:"1wutuc"}],["path",{d:"M12 3h.01",key:"n36tog"}],["path",{d:"M16 19h.01",key:"1vcnzz"}],["path",{d:"M16 3h.01",key:"ll0zb8"}],["path",{d:"M2 13h.01",key:"1aptou"}],["path",{d:"M2 17v4.286a.71.71 0 0 0 1.212.502l2.202-2.202A2 2 0 0 1 6.828 19H8",key:"4cp7zq"}],["path",{d:"M2 5a2 2 0 0 1 2-2",key:"1iztiu"}],["path",{d:"M2 9h.01",key:"1nzd1v"}],["path",{d:"M20 3a2 2 0 0 1 2 2",key:"m48m3a"}],["path",{d:"M22 13h.01",key:"ke7esy"}],["path",{d:"M22 17a2 2 0 0 1-2 2",key:"17q5fo"}],["path",{d:"M22 9h.01",key:"npkp49"}],["path",{d:"M8 3h.01",key:"133hau"}]],_r=Tt("message-square-dashed",Pd);const Dd=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}],["path",{d:"m8 9 3 3-3 3",key:"12hl5m"}]],Id=Tt("panel-right-close",Dd);const Td=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}],["path",{d:"m10 15-3-3 3-3",key:"1pgupc"}]],$d=Tt("panel-right-open",Td);const Ed=[["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551",key:"1miecu"}]],Rd=Tt("paperclip",Ed),Ad="vera:story-asked:";function Ld(t,s){const n=`${Ad}${Ya(t)}`;try{if(s?.getItem(n)==="1")return!1;s?.setItem(n,"1")}catch{}return!0}function Md(t){const[s,n]=y.useState(!1),a=t.toLowerCase();y.useEffect(()=>Fc(a,()=>n(o=>!o)),[a]);const r=y.useCallback(o=>n(l=>o===void 0?!l:o),[]);return[s,r]}const Od=["tenant_admin","platform_admin","platform_engineer"];function Kd(t){return t?t.modelDisclosure===!0?!0:(t.roles??[]).some(s=>Od.includes(s)):!1}function _d(t){const s=Math.max(1,Math.round(t/1e3));if(s<60)return`${s}s`;const n=Math.round(s/60);return n===1?"1 min":`${n} min`}const Na={fast:"a fast model, so this should be quick",moderate:"this usually takes a moment",slow:"a deeper model, so slower but a stronger answer"};function Fd(t,s){if(!s||!t||!t.available||!t.model)return null;const n=Na[t.speedBand]??Na.moderate,a=t.typicalWaitMs!=null&&t.typicalWaitMs>0?` (typically ~${_d(t.typicalWaitMs)})`:"";return`${t.model} is on this â ${n}${a}.`}function qd({open:t,onOpenChange:s,isAdmin:n}){return e.jsx(Ze,{open:t,onOpenChange:s,children:e.jsxs(et,{className:"sm:max-w-md",children:[e.jsxs(tt,{children:[e.jsx("div",{className:"mb-2 flex h-10 w-10 items-center justify-center rounded-full bg-primary/10",children:e.jsx(Xi,{className:"h-5 w-5 text-primary"})}),e.jsx(st,{children:"Voice isnât set up yet"}),e.jsx(dt,{children:n?"Voice input needs a speech-capable provider key. Open Settings and add or update a transcription-capable provider (for example an OpenAI or Gemini key) to enable dictation and Voice Mode.":"Voice input isnât available yet because your workspace hasnât finished setting up a speech provider. Ask your workspace admin to add a transcription-capable provider in Settings."})]}),e.jsx(kt,{children:e.jsx(D,{onClick:()=>s(!1),children:"Got it"})})]})})}const fs=["Thinking","Pondering","Mulling it over","Reasoning it through","Connecting the dots","Consulting your sources","Checking sources for the answer","Cross-referencing your workspace","Weighing the evidence","Tracing the sources","Synthesizing","Piecing it together","Distilling the essentials","Following the thread","Gathering the details",`Composing a ${O.backed} reply`,"Sifting signal from noise","Ruminating","Deliberating","Untangling the question","Consulting the knowledge base","Verifying before answering"];function Ud(t){if(fs.length<=1)return fs[0];let s=t;for(;s===t;)s=fs[Math.floor(Math.random()*fs.length)];return s}const Fr=b.createContext(null),zd=240,Vd=10;function Qd({children:t}){const[s,n]=y.useState(null),[a,r]=y.useState(!1),o=y.useRef(new Map),l=y.useRef(!1),h=y.useCallback((w,d)=>(o.current.set(w,d),()=>{o.current.delete(w)}),[]),p=y.useCallback((w,d)=>{let c=document.elementFromPoint(w,d);for(;c;){const g=o.current.get(c);if(g)return{el:c,spec:g.current};c=c.parentElement}return null},[]),v=y.useCallback((w,d)=>{let c=null,g=null,R=0,$=0,C=!1,A=null,j=null;const L=()=>{c!=null&&(clearTimeout(c),c=null)},T=N=>{C&&N.preventDefault()},k=N=>{j?.el!==N?.el&&(j?.spec.onOver(!1,A),j=N,j?.spec.onOver(!0,A))},B=()=>{document.removeEventListener("pointermove",U),document.removeEventListener("pointerup",W),document.removeEventListener("pointercancel",G),document.removeEventListener("touchmove",T)},Z=N=>{L(),C&&N&&A&&j&&j.spec.canDrop(A)&&j.spec.onDrop(A),k(null),B(),C&&(C=!1,l.current=!1,A=null,n(null),r(!1)),g=null};function U(N){if(g==null||N.pointerId!==g)return;if(!C){Math.hypot(N.clientX-R,N.clientY-$)>Vd&&(L(),B(),g=null);return}if(!A)return;const I=p(N.clientX,N.clientY);k(I&&I.spec.canDrop(A)?I:null)}function W(N){g==null||N.pointerId!==g||Z(!0)}function G(N){g==null||N.pointerId!==g||Z(!1)}const K=()=>
2{if(c=null,l.current){B(),g=null;return}const N=d();if(!N){B(),g=null;return}C=!0,l.current=!0,A=N,n(N),r(!0),document.addEventListener("touchmove",T,{passive:!1})},ee=N=>{N.pointerType!=="mouse"&&(C||l.current||g!=null||(g=N.pointerId,R=N.clientX,$=N.clientY,document.addEventListener("pointermove",U),document.addEventListener("pointerup",W),document.addEventListener("pointercancel",G),c=window.setTimeout(K,zd)))};return w.addEventListener("pointerdown",ee),()=>{w.removeEventListener("pointerdown",ee),Z(!1)}},[p,n]),x=b.useMemo(()=>({item:s,begin:n,end:()=>n(null),touchDragging:a,registerDrop:h,attachTouchDrag:v}),[s,a,h,v]);return e.jsx(Fr.Provider,{value:x,children:t})}function Yt(){return b.useContext(Fr)}function qr(t,s){const n=Yt(),a=y.useRef(s);a.current=s;const r=y.useRef(null);return y.useCallback(o=>{r.current&&(r.current(),r.current=null),o&&n&&t&&(r.current=n.attachTouchDrag(o,()=>a.current()))},[n,t])}function bn(t,s){const n=Yt(),a=y.useRef(s);a.current=s;const r=y.useRef(null);return y.useCallback(o=>{r.current&&(r.current(),r.current=null),o&&n&&t&&(r.current=n.registerDrop(o,a))},[n,t])}function ks(t,s,n){if(s===n)return t;const a=t.filter(o=>o!==s),r=a.indexOf(n);return r===-1?t:(a.splice(r,0,s),a)}const jn=120;function Gd(t){return t.replace(/[^a-zA-Z0-9]/g,"").slice(0,2).toUpperCase()||"â¢"}function Ur(t){return t?"absolute top-0 right-0 z-10 w-[18px] h-[18px] rounded-full bg-background/90 border border-border/70 shadow-sm text-muted-foreground hover:text-foreground flex items-center justify-center data-[state=open]:text-foreground data-[state=open]:bg-secondary":"shrink-0 mr-1 p-1.5 rounded text-muted-foreground hover:text-foreground hover:bg-secondary/80 data-[state=open]:bg-secondary data-[state=open]:text-foreground"}function ka({conv:t,collapsed:s,h:n}){const[a,r]=y.useState(!1),[o,l]=y.useState(!1),[h,p]=y.useState(""),v=t.title||"New Conversation",x=!!t.pinned,w=!!t.projectId,d=()=>{const c=h.trim();c&&(n.onCreateProjectAndAssign(t.id,c),l(!1))};return e.jsxs(e.Fragment,{children:[e.jsxs(gn,{children:[e.jsx(vn,{asChild:!0,children:e.jsx("button",{type:"button","aria-label":`Chat actions: ${v}`,onClick:c=>c.stopPropagation(),className:Ur(s),children:e.jsx(Ja,{className:s?"w-3 h-3":"w-4 h-4"})})}),e.jsxs(yn,{align:"end",side:s?"right":"bottom",className:"w-52",onClick:c=>c.stopPropagation(),children:[e.jsx(Ge,{onSelect:()=>n.onSetPinned(t.id,!x),children:x?e.jsxs(e.Fragment,{children:[e.jsx(Ji,{className:"w-3.5 h-3.5"})," Unpin"]}):e.jsxs(e.Fragment,{children:[e.jsx(Wt,{className:"w-3.5 h-3.5"})," Pin"]})}),e.jsxs(Bc,{children:[e.jsxs(Wc,{children:[e.jsx(td,{className:"w-3.5 h-3.5"})," Add to project"]}),e.jsx(Hc,{children:e.jsxs(Yc,{className:"w-56 max-h-72 overflow-y-auto",children:[n.projects.length===0&&e.jsx(Er,{className:"text-xs font-normal text-muted-foreground",children:"No projects yet"}),n.projects.map(c=>e.jsxs(Ge,{onSelect:()=>n.onSetProject(t.id,c.id),children:[e.jsx("span",{className:"flex-1 truncate",children:c.name}),t.projectId===c.id&&e.jsx(Ct,{className:"w-3.5 h-3.5 ml-2 shrink-0"})]},c.id)),n.projects.length>0&&e.jsx(Ns,{}),e.jsxs(Ge,{onSelect:()=>{p(""),setTimeout(()=>l(!0),0)},children:[e.jsx(tn,{className:"w-3.5 h-3.5"})," New projectâ¦"]})]})})]}),w&&e.jsxs(Ge,{onSelect:()=>n.onSetProject(t.id,null),children:[e.jsx(Kr,{className:"w-3.5 h-3.5"})," Remove from project"]}),n.onShare&&e.jsxs(Ge,{onSelect:()=>n.onShare(t.id,v),"data-testid":`menu-share-${t.id}`,children:[e.jsx(sd,{className:"w-3.5 h-3.5"})," Shareâ¦"]}),e.jsx(Ns,{}),e.jsxs(Ge,{className:"text-destructive focus:text-destructive",onSelect:()=>setTimeout(()=>r(!0),0),children:[e.jsx(Za,{className:"w-3.5 h-3.5"})," Delete"]})]})]}),e.jsx(er,{open:a,onOpenChange:r,children:e.jsxs(tr,{onClick:c=>c.stopPropagation(),children:[e.jsxs(sr,{children:[e.jsx(nr,{children:"Delete this chat?"}),e.jsxs(ar,{children:["â",v,"â and all of its messages will be permanently deleted. This canât be undone."]})]}),e.jsxs(rr,{children:[e.jsx(ir,{children:"Cancel"}),e.jsx(or,{onClick:()=>n.onDelete(t.id),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})}),e.jsx(Ze,{open:o,onOpenChange:l,children:e.jsxs(et,{className:"max-w-sm",onClick:c=>c.stopPropagation(),children:[e.jsxs(tt,{children:[e.jsx(st,{children:"New project"}),e.jsx(dt,{children:"Create a project and add this chat to it."})]}),e.jsx($e,{autoFocus:!0,value:h,onChange:c=>p(c.target.value),placeholder:"Project name",maxLength:jn,onKeyDown:c=>{c.key==="Enter"&&d()}}),e.jsxs(kt,{children:[e.jsx(D,{variant:"ghost",onClick:()=>l(!1),children:"Cancel"}),e.jsx(D,{disabled:!h.trim(),onClick:d,children:"Create & add"})]})]})})]})}function Cs({conv:t,collapsed:s,h:n,showPinBadge:a,reorderPinned:r}){const o=n.activeConvId===t.id,l=t.title||"New Conversation",h=Yt(),p=!!h&&!s,[v,x]=y.useState(!1),w=!!r&&!!h&&h.item?.kind==="chat"&&h.item.pinned,d=qr(p,()=>({kind:"chat",id:t.id,fromProjectId:t.projectId??null,pinned:!!t.pinned})),c=bn(p&&!!r,{canDrop:C=>C.kind==="chat"&&C.pinned&&!!r,onOver:C=>x(C),onDrop:C=>{r&&n.onReorderPinned(ks(r.orderedIds,C.id,t.id))}}),g=y.useCallback(C=>{d(C),c(C)},[d,c]),R=!!h?.touchDragging&&h.item?.kind==="chat"&&h.item.id===t.id,$=C=>{if(h){C.dataTransfer.effectAllowed="move";try{C.dataTransfer.setData("text/plain",t.id)}catch{}h.begin({kind:"chat",id:t.id,fromProjectId:t.projectId??null,pinned:!!t.pinned})}};return s?e.jsxs("div",{role:"listitem",className:"relative w-10 h-10 shrink-0",children:[e.jsx("button",{onClick:()=>n.onSelect(t.id),title:l,"aria-label":l,className:`w-10 h-10 rounded-md text-xs font-semibold uppercase flex items-center justify-center transition-colors ${o?"bg-secondary text-foreground":"text-muted-foreground hover:bg-secondary/50 hover:text-foreground"}`,children:Gd(l)}),a&&e.jsx("span",{className:"absolute top-0 left-0 z-10 w-[15px] h-[15px] rounded-full bg-background/90 border border-border/70 flex items-center justify-center text-muted-foreground",children:e.jsx(Wt,{className:"w-2 h-2"})}),e.jsx(ka,{conv:t,collapsed:!0,h:n})]}):e.jsxs("div",{role:"listitem",ref:g,draggable:p,onDragStart:p?$:void 0,onDragEnd:p?()=>h?.end():void 0,onDragOver:w?C=>{C.preventDefault(),x(!0)}:void 0,onDragLeave:w?()=>x(!1):void 0,onDrop:w?C=>{C.preventDefault();const A=h?.item;A?.kind==="chat"&&r&&n.onReorderPinned(ks(r.orderedIds,A.id,t.id)),h?.end(),x(!1)}:void 0,className:`group relative flex items-center rounded-md transition-colors ${o?"bg-secondary":"hover:bg-secondary/50"} ${p?"cursor-grab active:cursor-grabbing":""} ${R?"opacity-50":""}`,children:[v&&e.jsx("span",{className:"pointer-events-none absolute -top-0.5 left-1 right-1 h-0.5 rounded bg-primary"}),e.jsxs("button",{onClick:()=>n.onSelect(t.id),className:`flex-1 min-w-0 flex items-center gap-1.5 text-left pl-3 pr-1 py-2.5 rounded-md text-sm ${o?"font-medium text-foreground":"text-muted-foreground group-hover:text-foreground"}`,children:[a&&e.jsx(Wt,{className:"w-3 h-3 shrink-0 opacity-70"}),e.jsx("span",{className:"truncate",children:l})]}),e.jsx(ka,{conv:t,collapsed:!1,h:n})]})}function Bd({collapsed:t,conversations:s,h:n}){if(!s||s.length===0)return null;const a=s.map(r=>r.id);return e.jsxs("div",{className:t?"flex flex-col items-center gap-1 w-full":"",children:[t?e.jsx("div",{className:"mx-auto mb-1 h-3 w-3 flex items-center justify-center text-muted-foreground",title:"Pinned",children:e.jsx(Wt,{className:"w-3 h-3"})}):e.jsxs("div",{className:"flex items-center gap-1.5 px-3.5 pt-1 pb-1 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:[e.jsx(Wt,{className:"w-3 h-3"})," Pinned"]}),e.jsx("div",{role:"list",className:t?"flex flex-col items-center gap-1":"space-y-1",children:s.map(r=>e.jsx(Cs,{conv:r,collapsed:t,h:n,showPinBadge:!0,reorderPinned:t?void 0:{orderedIds:a}},r.id))})]})}function Ca({project:t,collapsed:s,h:n}){const[a,r]=y.useState(!1),[o,l]=y.useState(!1),[h,p]=y.useState(t.name),v=()=>{const x=h.trim();x&&(n.onRenameProject(t.id,x),r(!1))};return e.jsxs(e.Fragment,{children:[e.jsxs(gn,{children:[e.jsx(vn,{asChild:!0,children:e.jsx("button",{type:"button","aria-label":`Project actions: ${t.name}`,onClick:x=>x.stopPropagation(),className:Ur(s),children:e.jsx(Ja,{className:s?"w-3 h-3":"w-4 h-4"})})}),e.jsxs(yn,{align:"end",side:s?"right":"bottom",className:"w-44",onClick:x=>x.stopPropagation(),children:[e.jsxs(Ge,{onSelect:()=>{p(t.name),setTimeout(()=>r(!0),0)},children:[e.jsx(ln,{className:"w-3.5 h-3.5"})," Rename"]}),e.jsx(Ns,{}),e.jsxs(Ge,{className:"text-destructive focus:text-destructive",onSelect:()=>setTimeout(()=>l(!0),0),children:[e.jsx(Za,{className:"w-3.5 h-3.5"})," Delete project"]})]})]}),e.jsx(Ze,{open:a,onOpenChange:r,children:e.jsxs(et,{className:"max-w-sm",onClick:x=>x.stopPropagation(),children:[e.jsx(tt,{children:e.jsx(st,{children:"Rename project"})}),e.jsx($e,{autoFocus:!0,value:h,onChange:x=>p(x.target.value),placeholder:"Project name",maxLength:jn,onKeyDown:x=>{x.key==="Enter"&&v()}}),e.jsxs(kt,{children:[e.jsx(D,{variant:"ghost",onClick:()=>r(!1),children:"Cancel"}),e.jsx(D,{disabled:!h.trim(),onClick:v,children:"Save"})]})]})}),e.jsx(er,{open:o,onOpenChange:l,children:e.jsxs(tr,{onClick:x=>x.stopPropagation(),children:[e.jsxs(sr,{children:[e.jsx(nr,{children:"Delete this project?"}),e.jsxs(ar,{children:["â",t.name,"â will be deleted. Its chats wonât be deleted â theyâll return to the ungrouped list."]})]}),e.jsxs(rr,{children:[e.jsx(ir,{children:"Cancel"}),e.jsx(or,{onClick:()=>n.onDeleteProject(t.id),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete project"})]})]})})]})}
2function Sa({project:t,collapsed:s,expanded:n,onToggle:a,h:r,reorderProjects:o}){const l=Xa({queryKey:[...Pl(t.id),"infinite"],queryFn:({pageParam:j})=>Sl(t.id,j?{cursor:j}:void 0),initialPageParam:void 0,getNextPageParam:j=>j.nextCursor??void 0,enabled:n}),h=l.data?l.data.pages.flatMap(j=>j.items):void 0,p=Yt(),v=!!p&&!s,x=p?.item??null,w=v&&x?.kind==="chat",d=v&&!!o&&x?.kind==="project",c=w||d,[g,R]=y.useState(null),$=j=>{j.preventDefault(),x?.kind==="chat"?x.fromProjectId!==t.id&&r.onSetProject(x.id,t.id):x?.kind==="project"&&o&&r.onReorderProjects(ks(o.orderedIds,x.id,t.id)),p?.end(),R(null)},C=bn(v,{canDrop:j=>j.kind==="chat"||j.kind==="project"&&!!o,onOver:(j,L)=>R(j&&L?L.kind==="chat"?"chat":"project":null),onDrop:j=>{j.kind==="chat"?j.fromProjectId!==t.id&&r.onSetProject(j.id,t.id):j.kind==="project"&&o&&r.onReorderProjects(ks(o.orderedIds,j.id,t.id))}}),A=qr(v&&!!o,()=>({kind:"project",id:t.id}));return s?e.jsxs("div",{className:"flex flex-col items-center gap-1 w-full",children:[e.jsxs("div",{className:"relative w-10 h-10 shrink-0",children:[e.jsx("button",{onClick:a,title:t.name,"aria-label":`Project: ${t.name}`,"aria-expanded":n,className:`w-10 h-10 rounded-md flex items-center justify-center transition-colors ${n?"bg-secondary text-foreground":"text-muted-foreground hover:bg-secondary/50 hover:text-foreground"}`,children:n?e.jsx(Wn,{className:"w-4 h-4"}):e.jsx(Hn,{className:"w-4 h-4"})}),e.jsx(Ca,{project:t,collapsed:!0,h:r})]}),n&&e.jsxs("div",{className:"flex flex-col items-center gap-1 w-full",children:[l.isLoading?e.jsx(re,{className:"w-4 h-4 animate-spin text-muted-foreground my-1"}):h&&h.length>0?e.jsx("div",{role:"list",className:"contents",children:h.map(j=>e.jsx(Cs,{conv:j,collapsed:!0,h:r},j.id))}):null,l.hasNextPage&&e.jsx("button",{type:"button",onClick:()=>l.fetchNextPage(),disabled:l.isFetchingNextPage,"aria-label":"Load more chats in this project",className:"w-10 h-8 rounded-md flex items-center justify-center text-muted-foreground hover:bg-secondary/50 disabled:opacity-60",children:l.isFetchingNextPage?e.jsx(re,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(ct,{className:"w-4 h-4"})})]})]}):e.jsxs("div",{children:[e.jsxs("div",{ref:C,onDragOver:c?j=>{j.preventDefault(),R(x?.kind==="chat"?"chat":"project")}:void 0,onDragLeave:c?()=>R(null):void 0,onDrop:c?$:void 0,className:`group relative flex items-center rounded-md transition-colors ${g==="chat"?"ring-2 ring-primary/50 ring-inset bg-primary/5":"hover:bg-secondary/50"} ${p?.touchDragging&&x?.kind==="project"&&x.id===t.id?"opacity-50":""}`,children:[g==="project"&&e.jsx("span",{className:"pointer-events-none absolute -top-0.5 left-1 right-1 h-0.5 rounded bg-primary"}),v&&o&&e.jsx("span",{ref:A,draggable:!0,onDragStart:j=>{j.dataTransfer.effectAllowed="move";try{j.dataTransfer.setData("text/plain",t.id)}catch{}p?.begin({kind:"project",id:t.id})},onDragEnd:()=>p?.end(),"aria-hidden":!0,title:"Drag to reorder",className:"shrink-0 pl-1 flex items-center cursor-grab active:cursor-grabbing text-muted-foreground/40 hover:text-muted-foreground touch-none",children:e.jsx(Gc,{className:"w-3.5 h-3.5"})}),e.jsxs("button",{onClick:a,"aria-expanded":n,className:`flex-1 min-w-0 flex items-center gap-1.5 pr-1 py-2 text-sm text-muted-foreground group-hover:text-foreground ${v&&o?"pl-1":"pl-2"}`,children:[n?e.jsx(ct,{className:"w-3.5 h-3.5 shrink-0"}):e.jsx(Zc,{className:"w-3.5 h-3.5 shrink-0"}),n?e.jsx(Wn,{className:"w-3.5 h-3.5 shrink-0"}):e.jsx(Hn,{className:"w-3.5 h-3.5 shrink-0"}),e.jsx("span",{className:"flex-1 truncate text-left",children:t.name})]}),e.jsx(Ca,{project:t,collapsed:!1,h:r})]}),n&&e.jsxs("div",{className:"pl-3 ml-2 border-l border-border/60 space-y-1 mt-1",children:[l.isLoading?e.jsx("div",{className:"pl-2 py-1 text-xs text-muted-foreground",children:"Loadingâ¦"}):h&&h.length>0?e.jsx("div",{role:"list",className:"contents",children:h.map(j=>e.jsx(Cs,{conv:j,collapsed:!1,h:r},j.id))}):e.jsx("div",{className:"pl-2 py-1 text-xs text-muted-foreground",children:"No chats in this project"}),l.hasNextPage&&e.jsx("button",{type:"button",onClick:()=>l.fetchNextPage(),disabled:l.isFetchingNextPage,className:"w-full py-1.5 rounded-md text-xs font-medium flex items-center justify-center gap-1.5 text-muted-foreground hover:text-foreground hover:bg-secondary/50 disabled:opacity-60",children:l.isFetchingNextPage?e.jsx(re,{className:"w-3.5 h-3.5 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(ct,{className:"w-3.5 h-3.5"})," Load more"]})})]})]})}function Pa({open:t,onOpenChange:s,onCreate:n}){const[a,r]=y.useState("");b.useEffect(()=>{t&&r("")},[t]);const o=()=>{const l=a.trim();l&&(n(l),s(!1))};return e.jsx(Ze,{open:t,onOpenChange:s,children:e.jsxs(et,{className:"max-w-sm",children:[e.jsxs(tt,{children:[e.jsx(st,{children:"New project"}),e.jsx(dt,{children:"Group related chats together."})]}),e.jsx($e,{autoFocus:!0,value:a,onChange:l=>r(l.target.value),placeholder:"Project name",maxLength:jn,onKeyDown:l=>{l.key==="Enter"&&o()}}),e.jsxs(kt,{children:[e.jsx(D,{variant:"ghost",onClick:()=>s(!1),children:"Cancel"}),e.jsx(D,{disabled:!a.trim(),onClick:o,children:"Create"})]})]})})}function Wd({collapsed:t,h:s}){const[n,a]=y.useState(new Set),[r,o]=y.useState(!1),l=s.projects.map(p=>p.id),h=p=>a(v=>{const x=new Set(v);return x.has(p)?x.delete(p):x.add(p),x});return t?e.jsxs("div",{className:"flex flex-col items-center gap-1 w-full",children:[s.projects.map(p=>e.jsx(Sa,{project:p,collapsed:!0,expanded:n.has(p.id),onToggle:()=>h(p.id),h:s},p.id)),e.jsx("button",{type:"button",onClick:()=>o(!0),"aria-label":"New project",title:"New project",className:"w-10 h-10 rounded-md flex items-center justify-center text-muted-foreground hover:bg-secondary/50 hover:text-foreground",children:e.jsx(tn,{className:"w-4 h-4"})}),e.jsx(Pa,{open:r,onOpenChange:o,onCreate:s.onCreateProject})]}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between px-3.5 pt-1 pb-1",children:[e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Projects"}),e.jsx("button",{type:"button",onClick:()=>o(!0),"aria-label":"New project",title:"New project",className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-secondary/80",children:e.jsx(tn,{className:"w-3.5 h-3.5"})})]}),s.projects.length===0?e.jsx("div",{className:"px-3.5 pb-1 text-xs text-muted-foreground",children:"No projects yet"}):e.jsx("div",{className:"space-y-1",children:s.projects.map(p=>e.jsx(Sa,{project:p,collapsed:!1,expanded:n.has(p.id),onToggle:()=>h(p.id),h:s,reorderProjects:{orderedIds:l}},p.id))}),e.jsx(Hd,{h:s}),e.jsx(Pa,{open:r,onOpenChange:o,onCreate:s.onCreateProject})]})}function Hd({h:t}){const s=Yt(),[n,a]=y.useState(!1),r=bn(!0,{canDrop:l=>l.kind==="chat",onOver:l=>a(l),onDrop:l=>{l.kind==="chat"&&t.onSetProject(l.id,null)}});return s?.item?.kind==="chat"&&s.item.fromProjectId!=null?e.jsxs("div",{ref:r,onDragOver:l=>{l.preventDefault(),a(!0)},onDragLeave:()=>a(!1),onDrop:l=>{l.preventDefault();const h=s?.item;h?.kind==="chat"&&t.onSetProject(h.id,null),s?.end(),a(!1)},className:`mt-1 flex items-center gap-1.5 rounded-md border border-dashed px-3 py-2 text-xs transition-colors ${n?"border-primary bg-primary/5 text-foreground":"border-border/70 text-muted-foreground"}`,children:[e.jsx(Kr,{className:"w-3.5 h-3.5 shrink-0"})," Drop here to remove from project"]}):null}function Yd({containerRef:t}){const[s,n]=b.useState({top:!1,bottom:!1});return b.useEffect(()=>{const a=t.current;if(!a)return;const r=a.querySelector("[data-radix-scroll-area-viewport], [data-scroll-hints-viewport]")??a;let o=0;const l=()=>{o=0;const x=r.scrollTop>4,w=r.scrollTop+r.clientHeight<r.scrollHeight-4;n(d=>d.top===x&&d.bottom===w?d:{top:x,bottom:w})},h=()=>{o||(o=window.requestAnimationFrame(l))};l(),r.addEventListener("scroll",h,{passive:!0});const p=new ResizeObserver(h);p.observe(r);const v=new MutationObserver(h);return v.observe(r,{childList:!0,subtree:!0}),()=>{r.removeEventListener("scroll",h),p.disconnect(),v.disconnect(),o&&window.cancelAnimationFrame(o)}},[t]),e.jsxs(e.Fragment,{children:[e.jsx("div",{"aria-hidden":"true",className:`pointer-events-none absolute inset-x-0 top-0 z-10 h-6 bg-gradient-to-b from-background/95 to-transparent transition-opacity duration-200 ${s.top?"opacity-100":"opacity-0"}`}),e.jsx("div",{"aria-hidden":"true",className:`pointer-events-none absolute inset-x-0 bottom-0 z-10 flex h-7 items-end justify-center bg-gradient-to-t from-background/95 to-transparent transition-opacity duration-200 ${s.bottom?"opacity-100":"opacity-0"}`,children:e.jsx(ct,{className:"mb-0.5 h-3 w-3 text-muted-foreground
2/80"})})]})}function zr({compact:t=!1}){return t?e.jsx("div",{className:"p-4 text-center text-xs text-muted-foreground",role:"status","data-testid":"preview-chats-notice",children:Yn}):e.jsx("div",{className:"flex flex-1 items-center justify-center p-6",role:"status","data-testid":"preview-chats-notice",children:e.jsxs("div",{className:"max-w-sm rounded-lg border bg-card p-6 text-center shadow-sm",children:[e.jsx(Rr,{className:"mx-auto mb-3 h-6 w-6 text-muted-foreground","aria-hidden":"true"}),e.jsx("p",{className:"text-sm font-medium",children:Yn}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Nothing is read from, or written into, this member's chat history while you preview their workspace. Everything else shows as they see it."})]})})}function Da({collapsed:t,conversations:s,pinnedConversations:n,railHandlers:a,loadingConvs:r,hasMore:o,loadingMore:l,onLoadMore:h,previewing:p=!1}){const v=(!s||s.length===0)&&(!n||n.length===0)&&a.projects.length===0,x=b.useRef(null);return e.jsxs("div",{ref:x,className:"relative flex-1 min-h-0 flex flex-col",children:[e.jsx(cn,{className:"flex-1 min-h-0",children:e.jsxs("div",{className:`p-2 space-y-1 ${t?"flex flex-col items-center":""}`,children:[p?!t&&e.jsx(zr,{compact:!0}):r?!t&&e.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground animate-pulse",children:"Loading..."}):v?!t&&e.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground",children:"No conversations yet"}):e.jsxs(Qd,{children:[e.jsx(Bd,{collapsed:t,conversations:n,h:a}),t&&n&&n.length>0&&e.jsx("div",{className:"my-1 h-px w-6 bg-border/60"}),e.jsx(Wd,{collapsed:t,h:a}),s&&s.length>0&&e.jsxs(e.Fragment,{children:[t?e.jsx("div",{className:"my-1 h-px w-6 bg-border/60"}):e.jsx("div",{className:"px-3.5 pt-1 pb-1 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Chats"}),e.jsx("div",{role:"list",className:"contents",children:s.map(w=>e.jsx(Cs,{conv:w,collapsed:t,h:a},w.id))})]})]}),o&&!r&&e.jsx("button",{type:"button",onClick:h,disabled:l,"aria-label":"Load older chats",title:"Load older chats",className:`text-muted-foreground hover:text-foreground disabled:opacity-60 transition-colors ${t?"w-10 h-10 rounded-md flex items-center justify-center hover:bg-secondary/50":"w-full mt-1 py-2 rounded-md text-xs font-medium flex items-center justify-center gap-1.5 hover:bg-secondary/50"}`,children:l?e.jsx(re,{className:"w-3.5 h-3.5 animate-spin"}):t?e.jsx(ct,{className:"w-4 h-4"}):e.jsxs(e.Fragment,{children:[e.jsx(ct,{className:"w-3.5 h-3.5"}),"Load more"]})})]})}),!t&&e.jsx(Yd,{containerRef:x})]})}function Xd({onClose:t}){return e.jsx("div",{className:"shrink-0 border-b border-border/60 bg-secondary/40 px-4 lg:px-6 py-2.5",role:"status",children:e.jsxs("div",{className:"max-w-3xl mx-auto flex items-start gap-2.5 text-xs text-muted-foreground",children:[e.jsx(_r,{className:"w-4 h-4 mt-0.5 shrink-0 text-foreground"}),e.jsxs("div",{className:"flex-1 leading-relaxed",children:[e.jsx("span",{className:"font-medium text-foreground",children:"Temporary chat."})," ","Not saved to your history and not used to improve Vera â but itâs still personalized to you for this session."," ",e.jsxs(dn,{children:[e.jsx(un,{asChild:!0,children:e.jsx("button",{type:"button",className:"underline underline-offset-2 hover:text-foreground",children:"data-retention policy"})}),e.jsxs(mn,{align:"start",className:"w-80 text-xs leading-relaxed p-3",children:[e.jsx("p",{className:"font-medium text-foreground mb-1",children:"Data retention"}),e.jsx("p",{className:"text-muted-foreground",children:"Your workspace hasnât set a custom retention policy, so Veraâs platform-default policy applies: temporary chats arenât stored in your history and arenât used to train or improve the platform."})]})]}),e.jsxs("span",{className:"mt-1 flex items-start gap-1.5 text-foreground/80",children:[e.jsx(Ue,{className:"w-3.5 h-3.5 mt-0.5 shrink-0 text-chat-accent"}),"Even for temporary chats, your company may still retain this data â donât enter anything you wouldnât want it to see."]})]}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 px-2 text-[11px] shrink-0",onClick:t,children:"Turn off"})]})})}function Jd({reasoning:t}){const[s,n]=y.useState(!1),{approach:a,confidence:r}=t,o=r.low;return e.jsxs("div",{className:"mt-1.5 w-full max-w-full text-xs",children:[e.jsxs("button",{type:"button",onClick:()=>n(l=>!l),"aria-expanded":s,className:`inline-flex items-center gap-1.5 rounded-md px-1.5 py-0.5 -ml-1.5 transition hover:bg-muted/60 ${o?"text-chat-accent":"text-muted-foreground"}`,children:[o?e.jsx(Ue,{className:"w-3.5 h-3.5 shrink-0"}):e.jsx(Ar,{className:"w-3.5 h-3.5 shrink-0"}),e.jsx("span",{className:"font-medium",children:r.label}),e.jsx("span",{className:"opacity-70",children:"· How Vera answered"}),e.jsx(ct,{className:`w-3 h-3 opacity-70 transition-transform ${s?"rotate-180":""}`})]}),s&&e.jsxs("div",{className:"mt-1.5 rounded-lg border bg-muted/30 px-3 py-2.5 leading-relaxed text-muted-foreground",children:[o&&r.note&&e.jsxs("p",{className:"mb-2 flex items-start gap-1.5 font-medium text-chat-accent",children:[e.jsx(Ue,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsx("span",{children:r.note})]}),e.jsx("p",{className:"mb-1 font-semibold uppercase tracking-wider text-[10px] text-muted-foreground
2/80",children:"How Vera approached this"}),e.jsx(lr,{text:cr([r.label,o&&r.note?r.note:"","How Vera approached this.",...a].filter(Boolean).join(` 3 4`)),active:s,compact:!0,subject:"reasoning",testId:"answer-reasoning",analyticsEvent:"answer_reasoning_listen_started"}),e.jsx("ul",{className:"space-y-1",children:a.map((l,h)=>e.jsxs("li",{className:"flex items-start gap-1.5",children:[e.jsx(bs,{className:"mt-0.5 h-3 w-3 shrink-0 opacity-60"}),e.jsx("span",{children:l})]},h))})]})]})}function Zd({freshness:t}){if(t.state==="fresh")return null;const s=t.state==="sources_withdrawn";return e.jsxs("p",{className:`mt-1.5 inline-flex items-start gap-1.5 text-[11px] ${s?"text-red-700 dark:text-red-400":"text-chat-accent"}`,"data-testid":"answer-freshness-notice",children:[e.jsx(Zi,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"leading-snug",children:t.note??"Knowledge this answer cited has changed since it was written."})]})}function eu({info:t}){return e.jsxs("div",{className:"mt-1.5 w-full max-w-full rounded-lg border border-dashed bg-muted/40 px-3 py-2 font-mono text-[11px] text-muted-foreground","data-testid":"model-debug-panel",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-1.5 font-semibold uppercase tracking-wider text-[10px] text-muted-foreground/80",children:[e.jsx(js,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:"Model debug"})]}),e.jsxs("div",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-0.5",children:[e.jsx("span",{className:"text-muted-foreground/70",children:"Model"}),e.jsx("span",{className:"truncate text-foreground","data-testid":"model-debug-model",children:t.model}),e.jsx("span",{className:"text-muted-foreground/70",children:"Provider"}),e.jsx("span",{className:"truncate text-foreground","data-testid":"model-debug-provider",children:t.provider}),e.jsx("span",{className:"text-muted-foreground/70",children:"Tier"}),e.jsxs("span",{className:"text-foreground","data-testid":"model-debug-tier",children:[t.tierLabel," ",e.jsxs("span",{className:"opacity-60",children:["(",t.tier,")"]})]})]})]})}const tu=96;function Ia(t,s,n,a=tu){return s-t-n<=a}const su=600,nu=new Set(["ArrowUp","PageUp","Home"]);function au(t){return t<0}function ru(t){return t.atBottom?t.now>=t.holdUntil:t.now<t.glideUntil?null:!1}function iu({offer:t,onDecided:s,onOpenSkills:n}){const a=Ae(),{toast:r}=Be(),o=vr(),[l,h]=y.useState(!1),[p,v]=y.useState(t.draft.name),[x,w]=y.useState(t.draft.description),[d,c]=y.useState(t.draft.instructions);if(y.useEffect(()=>{v(t.draft.name),w(t.draft.description),c(t.draft.instructions),h(!1)},[t.id,t.draft.name,t.draft.description,t.draft.instructions]),t.status!=="offered")return null;const g=t.append??null;if(g)return e.jsx(ou,{offer:t,append:g,onDecided:s,onOpenSkills:n});const R=p.trim()!==t.draft.name||x.trim()!==t.draft.description||d.trim()!==t.draft.instructions,$=p.trim()&&x.trim()&&d.trim()&&!o.isPending,C=j=>{a.setQueryData(xn(t.conversationId),{offer:j}),a.invalidateQueries({queryKey:yr()}),s(j)},A=j=>{o.mutate({id:t.conversationId,data:{decision:j,...j==="accept"&&R?{overrides:{name:p.trim(),description:x.trim(),instructions:d.trim(),allowedTools:null}}:{}}},{onSuccess:L=>{C(L.offer),j==="accept"&&r({title:"Skill saved",description:`Vera will use â${L.skill?.name??p.trim()}â when a request matches. Manage it under Settings ⺠Skills.`})},onError:L=>r({title:j==="accept"?"Could not save the skill":"Could not record that",description:dr(L),variant:"destructive"})})};return e.jsx("div",{className:"mt-3 rounded-lg border border-primary/30 bg-primary/5 p-3 text-sm","data-testid":"chat-skill-offer","data-feature-anchor":"skills-save-offer",role:"group","aria-label":"Save this as a skill?",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(hn,{className:"mt-0.5 h-4 w-4 shrink-0 text-primary","aria-hidden":!0}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"font-medium",children:"Save this as a skill?"}),e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:"This looks like a routine you might ask for again. Saved as a personal skill, Vera applies these steps automatically next time a request matches â no re-explaining."}),l?e.jsxs("div",{className:"mt-2 space-y-2",children:[e.jsx($e,{value:p,onChange:j=>v(j.target.value),maxLength:60,"aria-label":"Skill name",className:"h-8 text-sm","data-testid":"skill-offer-name"}),e.jsx($e,{value:x,onChange:j=>w(j.target.value),maxLength:300,"aria-label":"When to use",placeholder:"When to use",className:"h-8 text-sm","data-testid":"skill-offer-when"}),e.jsx(It,{value:d,onChange:j=>c(j.target.value),maxLength:2e3,rows:5,"aria-label":"Instructions",className:"text-sm","data-testid":"skill-offer-instructions"})]}):e.jsxs("div",{className:"mt-2 rounded-md border bg-background/70 px-2.5 py-2",children:[e.jsx("div",{className:"text-sm font-medium","data-testid":"skill-offer-draft-name",children:p}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.jsx("span",{className:"font-medium text-foreground
4/80",children:"When:"})," ",x]}),e.jsx("pre",{className:"mt-1 max-h-40 overflow-y-auto whitespace-pre-wrap text-xs font-sans text-foreground/90",children:d})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5",children:[e.jsxs(D,{size:"sm",onClick:()=>A("accept"),disabled:!$,"data-testid":"skill-offer-accept",children:[o.isPending?e.jsx(re,{className:"mr-1 h-3.5 w-3.5 animate-spin"}):e.jsx(Ct,{className:"mr-1 h-3.5 w-3.5"}),"Save skill"]}),e.jsxs(D,{size:"sm",variant:"outline",onClick:()=>h(j=>!j),disabled:o.isPending,"data-testid":"skill-offer-edit",children:[e.jsx(ln,{className:"mr-1 h-3.5 w-3.5"})," ",l?"Preview":"Edit first"]}),e.jsxs(D,{size:"sm",variant:"ghost",onClick:()=>A("decline"),disabled:o.isPending,"data-testid":"skill-offer-decline",children:[e.jsx(ut,{className:"mr-1 h-3.5 w-3.5"})," Not for this chat"]}),n&&e.jsx("button",{type:"button",className:"ml-auto text-xs text-primary hover:underline",onClick:n,children:"Your skills"})]})]})]})})}function ou({offer:t,append:s,onDecided:n,onOpenSkills:a}){const r=Ae(),{toast:o}=Be(),l=vr(),[h,p]=y.useState(!1),[v,x]=y.useState(s.lines.join(` 5`));y.useEffect(()=>{x(s.lines.join(` 6`)),p(!1)},[t.id]);const w=v.split(` 7`).map($=>$.trim()).filter(Boolean),d=w.join(` 8`)!==s.lines.join(` 9`),c=$=>{r.setQueryData(xn(t.conversationId),{offer:$}),r.invalidateQueries({queryKey:yr()}),n($)},g=$=>l.mutate({id:t.conversationId,data:{decision:$,...$==="accept"&&d?{overrides:{name:t.draft.name,description:t.draft.description||s.targetName,instructions:w.join(` 10`),allowedTools:null}}:{}}},{onSuccess:C=>{c(C.offer),$==="accept"&&o({title:s.recommends?"Sent to your workspace admins":"Skill updated",description:s.recommends?`Your proposed lines for â${s.targetName}â are in the workspace inbox; nothing changes until an admin accepts.`:`Added ${w.length} line${w.length===1?"":"s"} to â${s.targetName}â.`})},onError:C=>o({title:$==="accept"?"Could not add to the skill":"Could not record that",description:dr(C),variant:"destructive"})}),R=s.recommends?`Suggest this for â${s.targetName}â?`:`Add this to â${s.targetName}â?`;return e.jsx("div",{className:"mt-3 rounded-lg border border-primary/30 bg-primary/5 p-3 text-sm","data-testid":"chat-skill-offer","data-offer-kind":"append","data-feature-anchor":"skills-append-offer",role:"group","aria-label":R,children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(hn,{className:"mt-0.5 h-4 w-4 shrink-0 text-primary","aria-hidden":!0}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"font-medium","data-testid":"skill-offer-append-title",children:R}),e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:s.recommends?`â${s.targetName}â is a workspace skill, so this goes to your workspace admins as a recommendation â nothing changes until they accept.`:s.target==="master"?"This reads like a standing rule. Added to the core instructions, Vera follows it whenever any skill applies.":"This looks like it belongs in an existing skill. Nothing is written until you save."}),h?e.jsx(It,{value:v,onChange:$=>x($.target.value),maxLength:2e3,rows:4,"aria-label":"Lines to add",className:"mt-2 text-sm","data-testid":"skill-offer-append-lines"}):e.jsx("ul",{className:"mt-2 list-disc space-y-0.5 rounded-md border bg-background/70 py-2 pl-6 pr-2 text-xs","data-testid":"skill-offer-append-preview",children:w.map(($,C)=>e.jsx("li",{children:$},C))}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5",children:[e.jsxs(D,{size:"sm",onClick:()=>g("accept"),disabled:!w.length||l.isPending,"data-testid":"skill-offer-accept",children:[l.isPending?e.jsx(re,{className:"mr-1 h-3.5 w-3.5 animate-spin"}):e.jsx(Ct,{className:"mr-1 h-3.5 w-3.5"}),s.recommends?"Send recommendation":"Save"]}),e.jsxs(D,{size:"sm",variant:"outline",onClick:()=>p($=>!$),disabled:l.isPending,"data-testid":"skill-offer-edit",children:[e.jsx(ln,{className:"mr-1 h-3.5 w-3.5"})," ",h?"Preview":"Edit first"]}),e.jsxs(D,{size:"sm",variant:"ghost",onClick:()=>g("decline"),disabled:l.isPending,"data-testid":"skill-offer-decline",children:[e.jsx(ut,{className:"mr-1 h-3.5 w-3.5"})," Not for this chat"]}),a&&e.jsx("button",{type:"button",className:"ml-auto text-xs text-primary hover:underline",onClick:a,children:"Your skills"})]})]})]})})}function lu({name:t,scope:s,systemSkills:n}){const a=s==="user"?"your skill":s==="tenant"?"workspace skill":"platform skill",r=n??[];if(!t&&r.length===0)return null;const o=[];t&&o.push(t);for(const h of r)o.push(h.name);const l=[t?`Vera applied ${a} â${t}â to this reply.`:"",r.length?`System context: ${r.map(h=>`â${h.name}â`).join(", ")}
10.`:""].filter(Boolean).join(" ");return e.jsxs("span",{className:"mt-2 inline-flex items-center gap-1 rounded-full border border-primary/30 bg-primary/5 px-2 py-0.5 text-[11px] text-foreground/80","data-testid":"chat-used-skill","data-feature-anchor":"skills-used-chip",title:l,children:[e.jsx(hn,{className:"h-3 w-3 text-primary","aria-hidden":!0}),o.length>1?"Using skills: ":"Using skill: ",e.jsx("span",{className:"font-medium",children:o.join(" · ")})]})}const cu=`Vera answers from your ${O.verified} sources. Ask a question to get started.`,du="Temporary chat â personalized for this session, never saved. Ask a question to get started.",uu="Ask Vera anything...",mu="Temporary chat â ask anythingâ¦",hu="Ask about your learning",pu=`Ask about your assignments, due dates, lessons and certifications â Vera answers from your learning and your workspaceâs ${O.verified} sources.`,xu="Ask about your learningâ¦",fu="Try asking",gu=["What are my assignments?","Whatâs due soon?","Help me with the lesson Iâm on","What certifications do I hold, and which are expiring?"];function vu(t){return t?.lmsFirstWorkspace===!0}function yu(t){return`Let's jump in, ${t}`}function wn(t,s){return s.tempMode?{heading:null,description:du,placeholder:mu,starterPrompts:[],starterLabel:null}:vu(t)?{heading:hu,description:pu,placeholder:xu,starterPrompts:gu,starterLabel:fu}:{heading:null,description:cu,placeholder:uu,starterPrompts:[],starterLabel:null}}function bu(t){return!!t&&t.kind==="db_answer"&&typeof t.sql=="string"}const Ta=t=>t==null?"â":typeof t=="object"?JSON.stringify(t):String(t),Hs=(t,s)=>t?.error??s;function ju(t){const s=`Question over ${t.relations[0]??t.account}`;return(t.question?.trim()||s).slice(0,120)}function $a(t,s,n){return{title:s.trim().slice(0,120),vizKind:"table",sourceKind:"postgres",config:{accountId:t.accountId,plan:t.plan,relationName:t.relations[0]},layout:{w:12,h:6},...n==null?{}:{position:n}}}function wu({card:t}){const{toast:s}=Be(),n=Ae(),a=Dl(),r=Il(),o=Tl(),l=$l(),h=(l.data??[]).filter(N=>N.kind!=="app"),p=ju(t),[v,x]=b.useState(!1),[w,d]=b.useState(!1),[c,g]=b.useState(!1),[R,$]=b.useState(p),[C,A]=b.useState(!1),[j,L]=b.useState(p),[T,k]=b.useState(""),B=El(T,{query:{queryKey:da(T),enabled:C&&!!T}}),Z=b.useMemo(()=>t.columns.map(N=>({id:N,header:N,cell:I=>e.jsx("span",{className:"block max-w-64 truncate",children:Ta(I[N])}),sortValue:I=>{const H=I[N];return typeof H=="number"||typeof H=="string"?H:Ta(H)}})),[t.columns]),U=b.useMemo(()=>new Map(t.rows.map((N,I)=>[N,String(I)])),[t.rows]),W=async()=>{try{await navigator.clipboard.writeText(t.sql),d(!0),window.setTimeout(()=>d(!1),1500)}catch{s({title:"SQL could not be copied",variant:"destructive"})}},G=()=>{const N=R.trim();N&&a.mutate({data:{name:N,connectorSlug:"postgres",input:JSON.stringify({accountId:t.accountId,plan:t.plan})}},{onSuccess:()=>{n.invalidateQueries({queryKey:Rl()}),g(!1),s({title:"Dataset saved",description:e.jsx(gs,{href:"/dashboards",className:"underline underline-offset-2",children:"View datasets"})})},onError:I=>s({title:"Dataset not saved",description:Hs(I,"Try again."),variant:"destructive"})})},K=()=>{const N=p;r.mutate({data:{name:N,description:t.question??null,tiles:[$a(t,N)]}},{onSuccess:I=>{n.invalidateQueries({queryKey:ca()}),s({title:"Report saved",description:e.jsx(gs,{href:`/dashboards/${I.id}`,className:"underline underline-offset-2",children:"Open report"})})},onError:I=>s({title:"Report not saved",description:Hs(I,"Try again."),variant:"destructive"})})},ee=()=>{const N=B.data,I=j.trim();if(!N||!T||!I)return;const H=N.tiles.map((ne,be)=>({title:ne.title,vizKind:ne.vizKind,sourceKind:ne.sourceKind,config:ne.config??{},layout:ne.layout,position:be}));o.mutate({id:T,data:{tiles:[...H,$a(t,I,H.length)]}},{onSuccess:()=>{n.invalidateQueries({queryKey:da(T)}),n.invalidateQueries({queryKey:ca()}),A(!1),s({title:"Tile saved",description:e.jsx(gs,{href:`/dashboards/${T}`,className:"underline underline-offset-2",children:"Open dashboard"})})},onError:ne=>s({title:"Tile not saved",description:Hs(ne,"Try again."),variant:"destructive"})})};return e.jsxs("article",{"data-testid":"db-answer-card",className:"mt-2 w-full max-w-full overflow-hidden rounded-xl border bg-card shadow-sm",children:[e.jsxs("header",{className:"flex flex-wrap items-start justify-between gap-2 border-b bg-muted/20 px-4 py-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"flex items-center gap-2 text-sm font-semibold",children:[e.jsx(eo,{className:"h-4 w-4 text-muted-foreground","aria-hidden":"true"}),"Live data from ",t.account]}),e.jsxs("p",{className:"mt-0.5 text-xs text-muted-foreground",children:[t.rowCount.toLocaleStr
10ing()," ",t.rowCount===1?"row":"rows"," · ",t.bounds.durationMs.toLocaleString()," ms"]})]}),t.bounds.capped&&e.jsx(ur,{variant:"secondary",children:"Capped result"})]}),e.jsxs("div",{className:"space-y-3 p-4",children:[e.jsx(lr,{text:cr([`Live data from ${t.account}. ${t.rowCount.toLocaleString()} ${t.rowCount===1?"row":"rows"}.`,t.question?`Question: ${t.question}`:"",`Sources: ${t.relations.join(", ")||"No relations"}.`,t.sensitivity.note?`Sensitive data handling. ${t.sensitivity.note}`:""].filter(Boolean).join(` 11 12`)),active:!0,compact:!0,subject:"answer",testId:"db-answer",analyticsEvent:"db_answer_listen_started"}),e.jsx(to,{tableId:"chat-db-answer",title:`Results from ${t.account}`,columns:Z,rows:t.rows,rowKey:N=>U.get(N)??"",emptyMessage:"No rows returned",caption:e.jsxs("span",{className:"sr-only",children:["Database query results from ",t.account]})}),e.jsxs("section",{"aria-label":"Sources",className:"space-y-1 text-xs text-muted-foreground",children:[e.jsxs("p",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Sources:"})," ",t.relations.join(", ")||"No relations"]}),t.joins.length>0&&e.jsxs("p",{children:["Joins: ",t.joins.map(N=>`${N.from} â ${N.to} (${N.type})`).join("; ")]}),t.metrics.length>0&&e.jsxs("p",{children:["Metrics: ",t.metrics.map(N=>`${N.alias} = ${N.formula}`).join("; ")]}),t.bounds.timeWindow&&e.jsxs("p",{children:["Time window: ",t.bounds.timeWindow.column,", ",t.bounds.timeWindow.start," to ",t.bounds.timeWindow.end,t.bounds.timeWindow.granularity?` by ${t.bounds.timeWindow.granularity}`:""]})]}),t.sensitivity.note&&e.jsxs("div",{className:"rounded-md border bg-muted/30 px-3 py-2 text-xs",children:[e.jsx("p",{className:"font-medium",children:"Sensitive data handling"}),e.jsx("p",{className:"mt-0.5 text-muted-foreground",children:t.sensitivity.note}),t.sensitivity.masked.length>0&&e.jsxs("p",{className:"mt-1",children:["Masked columns: ",t.sensitivity.masked.join(", ")]}),t.sensitivity.withheld.length>0&&e.jsxs("p",{children:["Withheld columns: ",t.sensitivity.withheld.join(", ")]})]}),e.jsxs("section",{className:"rounded-md border",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsx("span",{className:"text-xs font-medium",children:"SQL"}),e.jsx(D,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2 text-xs","aria-expanded":v,onClick:()=>x(N=>!N),"data-testid":"db-answer-sql-toggle",children:v?"Hide SQL":"Show SQL"})]}),v&&e.jsxs("div",{className:"border-t bg-muted/20 p-3",children:[e.jsx("div",{className:"mb-2 flex justify-end",children:e.jsxs(D,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",onClick:W,"aria-label":"Copy SQL",children:[w?e.jsx(Ct,{className:"mr-1 h-3.5 w-3.5"}):e.jsx(so,{className:"mr-1 h-3.5 w-3.5"}),w?"Copied":"Copy"]})}),e.jsx("pre",{className:"max-h-56 overflow-auto whitespace-pre-wrap text-xs",children:t.sql}),t.values.length>0&&e.jsxs("div",{className:"mt-2 border-t pt-2 text-xs text-muted-foreground",children:["Parameters: ",t.values.map((N,I)=>`$${I+1} = ${JSON.stringify(N)}`).join(", ")]})]})]}),t.saveable&&e.jsxs("div",{className:"flex flex-wrap gap-2 border-t pt-3",children:[e.jsx(D,{type:"button",variant:"outline",size:"sm",onClick:()=>A(!0),"data-testid":"db-answer-save-tile",children:"Save as tile"}),e.jsx(D,{type:"button",variant:"outline",size:"sm",onClick:()=>{$(p),g(!0)},"data-testid":"db-answer-save-dataset",children:"Save as dataset"}),e.jsxs(D,{type:"button",variant:"outline",size:"sm",disabled:r.isPending,onClick:K,"data-testid":"db-answer-save-report",children:[r.isPending&&e.jsx(re,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),"Save as report"]})]}),e.jsx(no,{accountId:t.accountId,subjectKind:"answer",subjectRef:t.relations.join(","),patternKey:t.patternKey,relations:t.relations,joins:t.joins})]}),e.jsx(Ze,{open:c,onOpenChange:g,children:e.jsxs(et,{className:"max-w-md",children:[e.jsxs(tt,{children:[e.jsx(st,{children:"Save as dataset"}),e.jsx(dt,{children:"Save this validated database plan so it can be reused in dashboards."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Pt,{htmlFor:"db-answer-dataset-name",children:"Name"}),e.jsx($e,{id:"db-answer-dataset-name",maxLength:120,value:R,onChange:N=>$(N.target.value)})]}),e.jsxs(kt,{children:[e.jsx(D,{type:"button",variant:"outline",onClick:()=>g(!1),children:"Cancel"}),e.jsxs(D,{type:"button",onClick:G,disabled:!R.trim()||a.isPending,children:[a.isPending&&e.jsx(re,{className:"mr-1.5 h-4 w-4 animate-spin"}),"Save dataset"]})]})]})}),e.jsx(Ze,{open:C,onOpenChange:A,children:e.jsxs(et,{className:"max-w-md",children:[e.jsxs(tt,{children:[e.jsx(st,{children:"Save as tile"}),e.jsx(dt,{children:"Add this live table to one of your existing dashboards."})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Pt,{children:"Dashboard"}),e.jsxs(ao,{value:T,onValueChange:k,children:[e.jsx(ro,{"aria-label":"Dashboard",children:e.jsx(io,{placeholder:l.isLoading?"Loading dashboardsâ¦":"Choose a dashboard"})}),e.jsx(oo,{children:h.map(N=>e.jsx(lo,{value:N.id,children:N.name},N.id))})]}),!l.isLoading&&h.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No tile dashboards are available."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Pt,{htmlFor:"db-answer-tile-title",children:"Tile title"}),e.jsx($e,{id:"db-answer-tile-title",maxLength:120,value:j,onChange:N=>L(N.target.value)})]})]}),e.jsxs(kt,{children:[e.jsx(D,{type:"button",variant:"outline",onClick:()=>A(!1),children:"Cancel"}),e.jsxs(D,{type:"button",onClick:ee,disabled:!T||!j.trim()||B.isLoading||!B.data||o.isPending,children:[(B.isLoading||o.isPending)&&e.jsx(re,{className:"mr-1.5 h-4 w-4 animate-spin"}),"Save tile"]})]})]})})]})}function Nu({question:t,answerText:s,conversationId:n,messageId:a}){const[r,o]=y.useState(!1);if(s.trim().length===0)return null;const l=(t.trim()||s.trim()).slice(0,80);return e.jsxs(e.Fragment,{children:[e.jsxs(_e,{children:[e.jsx(Fe,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-full",onClick:()=>o(!0),"aria-label":"Save as report","data-testid":`button-save-answer-report-${a??"temp"}`,children:e.jsx(co,{className:"w-3 h-3 text-muted-foreground"})})}),e.jsx(qe,{side:"bottom",children:e.jsx("p",{className:"text-xs",children:"Save as report"})})]}),e.jsx(ld,{open:r,onOpenChange:o,source:{kind:"answer",source:{question:t.slice(0,2e3),answerMarkdown:s.slice(0,2e4),conversationId:n,messageId:a},defaultName:l}})]})}function ku({loadingMessages:t,tempMode:s,renderedMessages:n,firstName:a,me:r,userLabel:o,userInitials:l,activeSource:h,setA
12ctiveSource:p,onOpenDocument:v,onOpenClaims:x,reasoningById:w,clarifyById:d,onPickClarifyOption:c,usedSkillById:g,usedSystemSkillsById:R,skillOffer:$,onSkillOfferDecided:C,onOpenSkills:A,showModelDebug:j,ttsLoadingId:L,ttsPlayback:T,onPlay:k,onNavigate:B,thinking:Z,waitExpectation:U,streamingText:W,streamStage:G,canSeeModel:K,transcriptKey:ee,sendSignal:N,feedbackConversationId:I,worldResources:H}){const ne=nn(an.hook,!s&&!t&&n.length===0),be=b.useMemo(()=>{for(let m=n.length-1;m>=0;m--){const ge=n[m];if(ge.role==="assistant")return ge.id}return null},[n]),{primaryColor:pe}=uo(),xe=b.useRef(null),De=b.useRef(null),fe=b.useRef(!0),M=b.useRef(0),_=b.useRef(0),F=b.useRef(!1),[oe,me]=b.useState(!1),ie=b.useCallback(m=>{fe.current=!0,_.current=0,me(!1),m==="smooth"&&(M.current=Date.now()+1200),De.current?.scrollIntoView({behavior:m})},[]),he=b.useCallback(()=>{const m=xe.current;return!!m&&Ia(m.scrollTop,m.scrollHeight,m.clientHeight)},[]);b.useEffect(()=>{const m=xe.current;if(!m)return;const ge=m.parentElement,E=()=>{M.current=0,_.current=Date.now()+su,fe.current=!1},Y=()=>{M.current=0,_.current=0},le=we=>au(we.deltaY)?E():Y(),ce=()=>E(),je=we=>{(nu.has(we.key)||we.key===" "&&we.shiftKey)&&E()},z=we=>{we.target?.closest("[data-radix-scroll-area-scrollbar]")&&E()},nt=()=>{const we=ru({atBottom:Ia(m.scrollTop,m.scrollHeight,m.clientHeight),now:Date.now(),holdUntil:_.current,glideUntil:M.current});we!==null&&(fe.current=we,we&&(M.current=0,me(!1)))};return m.addEventListener("scroll",nt,{passive:!0}),m.addEventListener("wheel",le,{passive:!0}),m.addEventListener("touchstart",ce,{passive:!0}),m.addEventListener("touchmove",ce,{passive:!0}),m.addEventListener("keydown",je),ge?.addEventListener("pointerdown",z),()=>{m.removeEventListener("scroll",nt),m.removeEventListener("wheel",le),m.removeEventListener("touchstart",ce),m.removeEventListener("touchmove",ce),m.removeEventListener("keydown",je),ge?.removeEventListener("pointerdown",z)}},[]),b.useLayoutEffect(()=>{fe.current&&Date.now()<M.current||(ie("auto"),F.current=!0)},[ee,ie]),b.useEffect(()=>{N>0&&(ie("smooth"),F.current=!0)},[N,ie]),b.useEffect(()=>{if(F.current){F.current=!1;return}!fe.current&&Date.now()>=_.current&&he()&&(fe.current=!0,me(!1)),fe.current?Date.now()<M.current?(M.current=Date.now()+1200,De.current?.scrollIntoView({behavior:"smooth"})):De.current?.scrollIntoView({behavior:"auto"}):(n.length>0||W||Z)&&me(!0)},[n,Z,W,G,U,he]);const[We,Ce]=b.useState(""),Ee=b.useRef(null);return b.useEffect(()=>{const m=Ee.current;if(Ee.current={conv:I,msg:be},!(!m||m.conv!==I)&&be&&be!==m.msg){Ce("Vera has replied.");const ge=setTimeout(()=>Ce(""),4e3);return()=>clearTimeout(ge)}},[be,I]),e.jsxs("div",{className:"relative flex-1 min-h-0 flex flex-col","data-testid":"chat-transcript",children:[e.jsx(cn,{className:"flex-1 min-h-0",viewportClassName:"p-4 lg:p-6",viewportRef:xe,children:e.jsxs("div",{className:"max-w-3xl mx-auto space-y-6 pb-4",children:[e.jsx("span",{className:"sr-only",role:"status","data-testid":"reply-announcer",children:We}),!s&&t?e.jsx("div",{className:"flex items-center justify-center py-10 opacity-50",children:e.jsx(re,{className:"w-6 h-6 animate-spin"})}):n.length===0?e.jsxs("div",{className:"h-full flex flex-col items-center justify-center mt-20 text-center",children:[e.jsx("div",{className:"text-4xl font-display font-extrabold tracking-tight mb-3",style:{color:"var(--chat-accent-solid)"},"data-testid":"chat-wordmark","data-wordmark":pe?"brand":"default",children:"Vera"}),(()=>{const m=wn(r,{tempMode:s});return e.jsxs(e.Fragment,{children:[!s&&en("welcomeCity")&&e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.2em] text-muted-foreground mb-2","data-testid":"chat-empty-welcome",children:ne(en("welcomeCity"))}),e.jsx("h3",{className:"text-2xl font-display font-semibold mb-2 text-foreground","data-testid":"chat-empty-heading",children:m.heading??yu(a)}),e.jsx("p",{className:"text-muted-foreground max-w-md",children:m.description})]})})()]}):n.map((m,ge)=>e.jsxs("div",{className:`flex gap-4 ${m.role==="user"?"flex-row-reverse":"flex-row"}`,"data-testid":"chat-turn","data-role":m.role,"data-cited":m.role==="assistant"&&m.spans?.some(E=>Jn(E.kind)==="verified")?"true":void 0,"data-answers":m.role==="assistant"&&n[ge-1]?.role==="user"?Ya(n[ge-1].content):void 0,children:[m.role==="user"?e.jsxs(mo,{className:"w-8 h-8 rounded-lg shrink-0",children:[e.jsx(ho,{src:r?.photoUrl??void 0,alt:o}),e.jsx(po,{className:"rounded-lg bg-secondary text-secondary-foreground text-xs font-bold uppercase",children:l})]}):e.jsx("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center shrink-0 shadow-sm",style:{backgroundColor:"var(--chat-accent-bg)",color:"var(--chat-accent-fg)"},children:e.jsx(Je,{className:"w-4 h-4"})}),e.jsxs("div",{className:`max-w-[85%] min-w-0 group ${m.role==="user"?"items-end flex flex-col":"items-start flex flex-col"}`,children:[e.jsx("div",{className:`px-4 py-3 rounded-2xl max-w-full ${m.role==="user"?"rounded-tr-sm shadow-sm":"bg-card border shadow-sm rounded-tl-sm"}`,style:m.role==="user"?{backgroundColor:"var(--chat-accent-bg)",color:"var(--chat-accent-fg)"}:void 0,children:m.role==="assistant"&&m.spans&&m.spans.length>
120?e.jsx(xo,{spans:m.spans,activeSource:h,setActiveSource:p,onOpenDocument:v,onOpenClaims:x?E=>x(m.id,E):void 0}):m.role==="assistant"?e.jsx("div",{className:"answer-body leading-relaxed text-[15px]",children:e.jsx(Xn,{text:m.content,trimStart:!0,trimEnd:!0})}):e.jsx("div",{className:"whitespace-pre-wrap leading-relaxed text-[15px]",children:m.content})}),m.role==="assistant"&&m.links&&m.links.length>0&&e.jsx("div",{className:"mt-2 flex flex-col items-start gap-1.5",children:m.links.map((E,Y)=>E.external?e.jsxs("a",{href:E.href,target:"_blank",rel:"noopener noreferrer",className:"prov-platform inline-flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-sm font-medium shadow-sm transition hover:brightness-95",children:[e.jsx(bs,{className:"w-3.5 h-3.5 opacity-80"}),e.jsx("span",{children:E.label}),e.jsx(Dt,{className:"w-3.5 h-3.5 opacity-70"})]},`${m.id}-link-${Y}`):E.highlight?e.jsxs("button",{type:"button",onClick:()=>B(E.href),"data-testid":`chat-take-me-there-${Y}`,"data-feature-anchor":"guided-answers-take-me-there","data-highlight-target":E.highlight,className:"prov-platform inline-flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-sm font-medium shadow-sm ring-1 ring-current/20 transition hover:brightness-95",children:[e.jsx(fo,{className:"w-3.5 h-3.5 opacity-80"}),e.jsx("span",{children:E.label}),e.jsx(Dt,{className:"w-3.5 h-3.5 opacity-70"})]},`${m.id}-link-${Y}`):e.jsxs("button",{type:"button",onClick:()=>B(E.href),className:"prov-platform inline-flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-sm font-medium shadow-sm transition hover:brightness-95",children:[e.jsx(bs,{className:"w-3.5 h-3.5 opacity-80"}),e.jsx("span",{children:E.label}),e.jsx(Dt,{className:"w-3.5 h-3.5 opacity-70"})]},`${m.id}-link-${Y}`))}),m.role==="assistant"&&m.cards?.filter(bu).map((E,Y)=>e.jsx(wu,{card:E},`${m.id}-db-answer-${Y}`)),m.role==="assistant"&&m.cards?.filter(id).map((E,Y)=>e.jsx(od,{card:E},`${m.id}-cross-source-${Y}`)),m.role==="assistant"&&c&&(()=>{const E=m.clarifyOptions??d?.[m.id];if(!E||E.length===0)return null;const Y=[...n].reverse().find(le=>le.role==="assistant");return Y&&Y.id!==m.id?null:e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5","data-testid":"chat-clarify-options","data-feature-anchor":"guided-answers-clarify-options",children:[e.jsx(go,{className:"w-3.5 h-3.5 text-muted-foreground","aria-hidden":"true"}),E.map((le,ce)=>e.jsx("button",{type:"button",onClick:()=>c(le),"data-testid":`chat-clarify-option-${ce}`,className:"inline-flex items-center rounded-full border border-border bg-background px-3 py-1 text-sm transition hover:bg-accent hover:text-accent-foreground",children:le},`${m.id}-clarify-${ce}`))]})})(),m.role==="assistant"&&H&&H.length>0&&(()=>{const E=n.findIndex(je=>je.id===m.id),Y=E>0?[...n.slice(0,E)].reverse().find(je=>je.role==="user"):void 0,le=m.spans&&m.spans.length>0?m.spans.map(je=>je.text).join(""):m.content,ce=cd(H,`${Y?.content??""} 13${le}`);return ce.length===0?null:e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5","data-testid":`world-resource-chips-${m.id}`,"aria-label":"Related external resources",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground",children:"Outside Vera:"}),ce.map((je,z)=>e.jsx(dd,{resource:je,compact:!0,testId:`world-resource-chip-${m.id}-${z}`},je.url))]})})(),m.role==="assistant"&&(()=>{const E=m.usedSkill??g?.[m.id],Y=m.usedSystemSkills??R?.[m.id]??[];return E||Y.length?e.jsx("div",{children:e.jsx(lu,{name:E?.name??null,scope:E?.scope??null,systemSkills:Y})}):null})(),m.role==="assistant"&&$&&$.status==="offered"&&C&&(()=>{const E=[...n].reverse().find(Y=>Y.role==="assistant");return E&&E.id!==m.id?null:e.jsx(iu,{offer:$,onDecided:C,onOpenSkills:A})})(),m.role==="assistant"&&(m.reasoning??w[m.id])&&e.jsx(Jd,{reasoning:m.reasoning??w[m.id]}),m.role==="assistant"&&m.freshness&&e.jsx(Zd,{freshness:m.freshness}),m.role==="assistant"&&K&&m.modelInfo&&!j&&e.jsxs("p",{className:"mt-1 flex items-center gap-1.5 text-[11px] text-muted-foreground/80","data-testid":"answered-by",children:[e.jsx(js,{className:"h-3 w-3 shrink-0 opacity-70"}),e.jsxs("span",{children:["Answered by ",m.modelInfo.model]})]}),m.role==="assistant"&&j&&m.modelInfo&&e.jsx(eu,{info:m.modelInfo}),m.role==="assistant"&&e.jsxs("div",{className:"flex items-center gap-1 mt-1 opacity-0 group-hover:opacity-100 focus-within:opacity-100 max-sm:opacity-100 [&:has([data-voted=true])]:opacity-100 transition-opacity",children:[e.jsxs(_e,{children:[e.jsx(Fe,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-full",onClick:()=>k(m),"aria-label":"Play in Vera's voice",children:L===m.id?e.jsx(re,{className:"w-3 h-3 animate-spin text-muted-foreground"}):T.playingKey===m.id?e.jsx(vo,{className:"w-3 h-3",style:{color:"var(--chat-accent-solid)"},fill:"currentColor"}):e.jsx(ud,{className:"w-3 h-3 text-muted-foreground"})})}),e.jsx(qe,{side:"bottom",children:e.jsx("p",{className:"text-xs",children:T.playingKey===m.id?"Stop":"Play in Veraâs voice"})})]}),I&&e.jsx(yo,{conversationId:I,messageId:m.id}),I&&!m.spans?.some(E=>Jn(E.kind)==="verified")&&(()=>{const E=n.findIndex(ce=>ce.id===m.id),Y=E>0?[...n.slice(0,E)].reverse().find(ce=>ce.role==="user"):void 0,le=m.spans&&m.spans.length>0?m.spans.map(ce=>ce.text).join(""):m.content;return e.jsx(rd,{compact:!0,defaultQuestion:Y?.content??"",context:{source:"chat",conversationId:I,messageId:m.id,answerExcerpt:le.slice(0,280)},testId:`ask-expert-${m.id}`})})(),I&&(()=>{const E=n.findIndex(le=>le.id===m.id),Y=E>0?[...n.slice(0,E)].reverse().find(le=>le.role==="user"):void 0;return e.jsx(Nu,{question:Y?.content??"",answerText:m.spans&&m.spans.length>0?m.spans.map(le=>le.text).join(""):m.content,conversationId:I,messageId:m.id})}
13)(),I&&e.jsx(ad,{compact:!0,text:m.spans&&m.spans.length>0?m.spans.map(E=>E.text).join(""):m.content,linkPath:`/?c=${I}`})]})]})]},m.id)),W&&e.jsxs("div",{className:"flex gap-4 flex-row",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center shrink-0 shadow-sm",style:{backgroundColor:"var(--chat-accent-bg)",color:"var(--chat-accent-fg)"},children:e.jsx(Je,{className:"w-4 h-4"})}),e.jsxs("div",{className:"max-w-[85%] min-w-0 flex flex-col items-start",children:[e.jsx("div",{className:"px-4 py-3 rounded-2xl max-w-full bg-card border shadow-sm rounded-tl-sm",children:e.jsx("div",{className:"answer-body leading-relaxed text-[15px]",children:e.jsx(Xn,{text:W,trimStart:!0})})}),e.jsxs("p",{className:"mt-1 flex items-center gap-1.5 text-[11px] text-muted-foreground/80","data-testid":"streaming-hint",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-current animate-pulse","aria-hidden":"true"}),e.jsxs("span",{children:["Writing â checking against your ",O.verified," sourcesâ¦"]})]})]})]}),Z&&!W&&e.jsxs("div",{className:"flex gap-4 flex-row","data-testid":"chat-thinking",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center shrink-0 shadow-sm",style:{backgroundColor:"var(--chat-accent-bg)",color:"var(--chat-accent-fg)"},children:e.jsx(Je,{className:"w-4 h-4"})}),e.jsx("div",{className:"max-w-[85%] flex flex-col items-start",children:e.jsxs("div",{className:"px-4 py-3 rounded-2xl bg-card border shadow-sm rounded-tl-sm",children:[e.jsx("span",{className:"sr-only",role:"status",children:"Vera is working on your answer."}),e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground","aria-hidden":"true",children:[e.jsx("span",{className:"text-[15px] italic",children:Z}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-current animate-bounce",style:{animationDelay:"-0.3s"}}),e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-current animate-bounce",style:{animationDelay:"-0.15s"}}),e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-current animate-bounce"})]})]}),U&&e.jsxs("p",{className:"mt-1.5 flex items-start gap-1.5 text-xs text-muted-foreground/90","data-testid":"wait-expectation",children:[e.jsx(js,{className:"mt-0.5 h-3 w-3 shrink-0 opacity-70"}),e.jsx("span",{children:U})]}),G&&e.jsx("p",{className:"mt-1.5 text-xs text-muted-foreground/80","data-testid":"stream-stage",children:G==="retrieval"?"Searching your knowledgeâ¦":G==="planning"?"Choosing the approachâ¦":"Writing the answerâ¦"})]})})]}),e.jsx("div",{ref:De})]})}),oe&&e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-3 flex justify-center",children:e.jsxs(D,{type:"button",size:"sm",variant:"secondary",className:"pointer-events-auto h-8 rounded-full border shadow-md gap-1.5 text-xs",onClick:()=>ie("smooth"),"data-testid":"jump-to-latest",children:[e.jsx(Xc,{className:"w-3.5 h-3.5","aria-hidden":"true"}),"Jump to latest"]})})]})}const Qt={member:{label:"A teammate",hint:"Someone in this workspace, by their sign-in email."},admin:{label:"My workspace admins",hint:"Any admin of this workspace can open it."},support:{label:"Vera support",hint:"Vera platform support staff can open it to troubleshoot."}},Cu=[{hours:24,label:"1 day"},{hours:168,label:"7 days"},{hours:720,label:"30 days"}];function Ea(t){const s=t?.data;return s?.code==="sharing_disabled"?"Chat sharing is turned off for that destination.":s?.error??s?.message??"Could not share the conversation."}function Su({conversationId:t,conversationTitle:s,open:n,onOpenChange:a}){const{toast:r}=Be(),o=Ae(),[l,h]=b.useState("member"),[p,v]=b.useState(""),[x,w]=b.useState(""),[d,c]=b.useState(168),g=t??"",{data:R}=Al(g,{query:{queryKey:ua(g),enabled:n&&!!t}}),$=()=>o.invalidateQueries({queryKey:ua(g)}),C=Ll({mutation:{onSuccess:()=>{r({title:"Conversation shared",description:`Shared with ${Qt[l].label.toLowerCase()}.`}),v(""),w(""),$()},onError:k=>r({title:"Not shared",description:Ea(k),variant:"destructive"})}}),A=Ml({mutation:{onSuccess:()=>{r({title:"Share revoked"}),$()},onError:k=>r({title:"Could not revoke",description:Ea(k),variant:"destructive"})}}),j=()=>{t&&C.mutate({id:t,data:{recipientKind:l,recipientEmail:l==="member"?p.trim():null,expires
13InHours:d,note:x.trim()||null}})},L=(R??[]).filter(k=>k.status==="active"),T=(R??[]).filter(k=>k.status!=="active");return e.jsx(Ze,{open:n,onOpenChange:a,children:e.jsxs(et,{className:"max-w-lg","data-testid":"share-conversation-dialog",children:[e.jsxs(tt,{children:[e.jsx(st,{children:"Share this chat"}),e.jsxs(dt,{children:[s?`â${s}â â `:"","read-only, expires automatically, and you can revoke it any time. The reader sees the transcript, the tools that ran and the run diagnostics â nothing you could not see yourself."]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(bo,{value:l,onValueChange:k=>h(k),className:"gap-2",children:Object.keys(Qt).map(k=>e.jsxs("label",{className:"flex items-start gap-2 rounded-md border p-2 cursor-pointer has-[:checked]:border-primary",children:[e.jsx(jo,{value:k,id:`share-kind-${k}`,"data-testid":`share-kind-${k}`,className:"mt-0.5"}),e.jsxs("span",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:Qt[k].label}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:Qt[k].hint})]})]},k))}),l==="member"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(Pt,{htmlFor:"share-email",children:"Teammateâs email"}),e.jsx($e,{id:"share-email",type:"email",value:p,onChange:k=>v(k.target.value),placeholder:"[email protected]","data-testid":"share-email"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Pt,{children:"Expires after"}),e.jsx("div",{className:"flex gap-2",children:Cu.map(k=>e.jsx(D,{type:"button",size:"sm",variant:d===k.hours?"default":"outline",onClick:()=>c(k.hours),"data-testid":`share-ttl-${k.hours}`,children:k.label},k.hours))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Pt,{htmlFor:"share-note",children:"Note for the reader (optional)"}),e.jsx(It,{id:"share-note",value:x,onChange:k=>w(k.target.value.slice(0,500)),rows:2,placeholder:"What went wrong, what you expectedâ¦","data-testid":"share-note"})]}),R&&R.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Existing shares"}),e.jsx("ul",{className:"space-y-1 text-sm",children:[...L,...T].map(k=>e.jsxs("li",{className:"flex items-center justify-between gap-2 rounded border px-2 py-1","data-testid":`share-row-${k.id}`,children:[e.jsxs("span",{className:"truncate",children:[k.recipientKind==="member"?k.recipientName??"Teammate":Qt[k.recipientKind].label,e.jsxs("span",{className:"text-xs text-muted-foreground",children:[" · ",k.viewCount," view",k.viewCount===1?"":"s"," · ",k.status==="active"?`until ${wo(new Date(k.expiresAt),"PP")}`:k.status]})]}),k.status==="active"?e.jsx(D,{type:"button",size:"sm",variant:"ghost",onClick:()=>A.mutate({shareId:k.id}),disabled:A.isPending,"data-testid":`share-revoke-${k.id}`,children:"Revoke"}):e.jsx(ur,{variant:"outline",children:k.status})]},k.id))})]})]}),e.jsxs(kt,{children:[e.jsx(D,{type:"button",variant:"outline",onClick:()=>a(!1),children:"Close"}),e.jsxs(D,{type:"button",onClick:j,disabled:C.isPending||l==="member"&&!p.trim(),"data-testid":"share-submit",children:[C.isPending&&e.jsx(re,{className:"w-4 h-4 mr-1 animate-spin"})," Share"]})]})]})})}function Pu({kbUploadInputRef:t,onQueueUpload:s,uploadingItems:n,tempMode:a,me:r,activeConvId:o,coachDismissed:l,setCoachDismissed:h,queryRefinements:p,onApplyRefinement:v,composerRef:x,composerText:w,setComposerText:d,onKeyDown:c,sendPending:g,creating:R,onOpenKbFilePicker:$,onNeedsVoiceConfig:C,maxQuality:A,setMaxQuality:j,modelChoices:L,modelChoice:T,onModelChoiceChange:k,onOpenVoiceMode:B,onSend:Z}){const U=!a&&!!L?.enabled&&L.choices.length>0,W=T?L?.choices.find(K=>K.providerSlug===T.providerSlug&&K.modelId===T.modelId):void 0,G=T?W?.displayName??`${T.modelId} (unavailable)`:null;return e.jsxs("div",{className:"px-4 pt-4 pb-[max(1rem,env(safe-area-inset-bottom))] bg-transparent border-t border-border/60 shrink-0","data-feature-anchor":"connector-chat-tools-composer",children:[e.jsx("input",{ref:t,type:"file",accept:Dr,multiple:!0,className:"hidden",onChange:K=>{const ee=Array.from(K.target.files??[]);K.currentTarget.value="",ee.length&&s(ee)}}),n.length>0&&(()=>{const K=n.reduce((I,H)=>I+H.fraction,0)/n.length,ee=Math.round(K*100),N=K>=1?"Processing⦠hang tight":`Uploading ${n.length===1?n[0].name:`${n.length} files`}⦠${ee}%`;return e.jsxs("div",{className:"max-w-3xl mx-auto mb-2 rounded-lg border bg-secondary/40 px-3 py-2 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(re,{className:"w-3.5 h-3.5 animate-spin shrink-0",style:{color:"var(--chat-accent-solid)"}}),e.jsx("span",{className:"truncate",children:N})]}),e.jsx("div",{className:"mt-1.5 h-1 w-full overflow-hidden rounded-full bg-border",children:e.jsx("div",{className:"h-full rounded-full transition-[width] duration-200",style:{width:`${Math.max(4,ee)}%`,backgroundColor:"var(--chat-accent-solid)"}})})]})})(),(a||o)&&!l&&p.length>0&&e.jsxs("div",{className:"max-w-3xl mx-auto mb-2 flex items-start gap-2",children:[e.jsxs("div",{className:"flex flex-1 flex-wrap items-center gap-1.5",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] font-medium text-muted-foreground pr-0.5",children:[e.jsx(Je,{className:"w-3 h-3",style:{color:"var(--chat-accent-solid)"}}),"Sharpen your ask"]}),p.map(K=>e.jsx("button",{type:"button",onClick:()=>v(K),className:"inline-flex items-center gap-1 rounded-full border bg-secondary/50 hover:bg-secondary px-2.5 py-1 text-xs transition-colors",children:K.label},K.id))]}),e.jsx("button",{type:"button",onClick:()=>h(!0),className:"shrink-0 rounded-full p-1 text-muted-foreground
13/70 hover:text-foreground hover:bg-secondary/60 transition-colors","aria-label":"Dismiss suggestions",children:e.jsx(ut,{className:"w-3.5 h-3.5"})})]}),e.jsxs("div",{"data-tour":"composer",className:"max-w-3xl mx-auto relative rounded-xl border glass-inset shadow-sm focus-within:ring-2 focus-within:ring-[var(--chat-accent-solid)] transition-shadow",children:[e.jsx(It,{ref:x,value:w,onChange:K=>d(K.target.value),onKeyDown:c,onPaste:K=>{const ee=Vc(K.clipboardData);ee.length>0&&s(ee)},"aria-label":"Message Vera",placeholder:wn(r,{tempMode:a}).placeholder,disabled:g||R,className:"min-h-[60px] max-h-[200px] border-0 focus-visible:ring-0 resize-none py-4 px-4 bg-transparent",rows:1}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs(_e,{children:[e.jsx(Fe,{asChild:!0,children:e.jsx(D,{"data-tour":"attach",variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-foreground transition-colors rounded-full",onClick:$,"aria-label":"Attach a document",children:e.jsx(Rd,{className:"w-4 h-4"})})}),e.jsx(qe,{children:e.jsxs("p",{className:"text-xs",children:["Attach a document · ",fn," max"]})})]}),e.jsx(No,{conversationId:o,whenUnavailable:"notify",onNeedsConfig:C,onText:K=>{d(ee=>ee?ee.replace(/\s*$/,"")+" "+K:K),window.setTimeout(()=>x.current?.focus({preventScroll:!0}),50)}}),e.jsxs(_e,{children:[e.jsx(Fe,{asChild:!0,children:e.jsxs(D,{variant:"ghost",size:"sm",className:`h-8 rounded-full transition-colors gap-1.5 ${A?"px-2.5":"w-8 px-0 text-muted-foreground hover:text-foreground"}`,style:A?{backgroundColor:"var(--chat-accent-bg)",color:"var(--chat-accent-fg)"}:void 0,onClick:()=>j(K=>!K),"aria-label":"Max quality","aria-pressed":A,children:[e.jsx(ko,{className:"w-4 h-4"}),A&&e.jsx("span",{className:"text-xs font-medium",children:"Max quality"})]})}),e.jsx(qe,{children:e.jsx("p",{className:"text-xs",children:A?"Max quality on â best model for this question":"Max quality â use the best model for this question"})})]}),U&&e.jsxs(gn,{children:[e.jsxs(_e,{children:[e.jsx(Fe,{asChild:!0,children:e.jsx(vn,{asChild:!0,children:e.jsxs(D,{variant:"ghost",size:"sm",className:`h-8 rounded-full transition-colors gap-1.5 ${G?"px-2.5":"w-8 px-0 text-muted-foreground hover:text-foreground"}`,style:G?{backgroundColor:"var(--chat-accent-bg)",color:"var(--chat-accent-fg)"}:void 0,"aria-label":"Choose a model",children:[e.jsx(js,{className:"w-4 h-4"}),G&&e.jsx("span",{className:"text-xs font-medium max-w-[140px] truncate",children:G})]})})}),e.jsx(qe,{children:e.jsx("p",{className:"text-xs",children:G?`This chat answers with ${G}`:"Choose which model answers this chat"})})]}),e.jsxs(yn,{align:"start",className:"w-64",children:[e.jsx(Er,{className:"text-xs",children:"Model for this chat"}),e.jsxs(Ge,{onClick:()=>k(null),className:"gap-2",children:[e.jsx(Ct,{className:`w-3.5 h-3.5 shrink-0 ${T?"invisible":""}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm",children:"Automatic"}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Vera picks the best fit per question"})]})]}),e.jsx(Ns,{}),L.choices.map(K=>{const ee=T?.providerSlug===K.providerSlug&&T?.modelId===K.modelId;return e.jsxs(Ge,{onClick:()=>k({providerSlug:K.providerSlug,modelId:K.modelId}),className:"gap-2",children:[e.jsx(Ct,{className:`w-3.5 h-3.5 shrink-0 ${ee?"":"invisible"}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm truncate",children:K.displayName}),K.isReasoningModel&&e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Reasoning model"})]})]},`${K.providerSlug}:${K.modelId}`)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs(_e,{children:[e.jsx(Fe,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full text-muted-foreground hover:text-foreground transition-colors",onClick:B,"aria-label":"Advanced voice mode",children:e.jsx(Co,{className:"w-4 h-4"})})}),e.jsx(qe,{children:e.jsx("p",{className:"text-xs",children:"Advanced voice mode"})})]}),e.jsxs(D,{onClick:Z,disabled:!w.trim()||g||R,size:"sm",className:"h-8 px-3 rounded-full transition-transform active:scale-95 hover:brightness-95",style:{backgroundColor:"var(--chat-accent-bg)",color:"var(--chat-accent-fg)"},children:[g?e.jsx(re,{className:"w-4 h-4 animate-spin"}):e.jsx(So,{className:"w-4 h-4 mr-1.5"}),e.jsx("span",{className:"font-medium text-xs",children:"Send"})]})]})]})]}),e.jsxs("div",{className:"max-w-3xl mx-auto text-center mt-2 text-[10px] text-muted-foreground space-y-0.5",children:[e.jsx("div",{children:"Vera can make mistakes. Verify important information."}),e.jsx(Po,{})]})]})}const Du="mailto:[email protected]?subject=Working%20session";function Iu(t,s=md){return t!=="budget_exhausted"?s.lock.titleTime:s.lock.titleCredit}function Ra(t){return t?.trial?.phase==="locked"}function Tu({me:t}){const s=t.trial,n=Do(Zn(t.tenantSlug));if(!s||s.phase!=="locked")return null;const a=Iu(s.lockReason,n);return e.jsx("section",{className:"mx-auto mb-6 w-full max-w-3xl px-4","aria-labelledby":"trial-lock-title","data-testid":"card-trial-lock","data-cause":s.lockReason??"time",children:e.jsxs("div",{className:"rounded-2xl border bg-card p-5 shadow-lg",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-secondary text-primary","aria-hidden":"true",children:e.jsx(hd,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h2",{id:"trial-lock-title",className:"text-lg font-semibold","data-testid":"text-trial-lock-title",children:a}),e.jsx("p",{className:"mt-1 max-w-2xl text-xs leading-5 text-muted-foreground","data-testid":"text-trial-lock-body",children:n.lock.body}
13)]})]}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-xl border bg-background p-4",children:[e.jsx("h3",{className:"text-sm font-semibold",children:n.lock.path1.title}),e.jsx("p",{className:"mt-1 min-h-[34px] text-[11px] leading-4 text-muted-foreground",children:n.lock.path1.body}),e.jsx(D,{asChild:!0,size:"sm",className:"mt-3","data-testid":"button-trial-lock-workspace",children:e.jsxs(gs,{href:"/signup",children:[n.lock.path1.button,e.jsx(Dt,{className:"ml-1 h-3.5 w-3.5","aria-hidden":"true"})]})})]}),e.jsxs("div",{className:"rounded-xl border bg-background p-4",children:[e.jsx("h3",{className:"text-sm font-semibold",children:n.lock.path2.title}),e.jsx("p",{className:"mt-1 min-h-[34px] text-[11px] leading-4 text-muted-foreground",children:n.lock.path2.body}),e.jsx(D,{asChild:!0,size:"sm",variant:"outline",className:"mt-3","data-testid":"button-trial-lock-session",children:e.jsxs("a",{href:Du,children:[n.lock.path2.button,e.jsx(pd,{className:"ml-1 h-3.5 w-3.5","aria-hidden":"true"})]})})]})]}),e.jsxs("div",{className:"mt-4 flex gap-4 text-[11px] font-medium text-muted-foreground",children:[e.jsx("a",{className:"underline",href:"https://unicorniq.ai",target:"_blank",rel:"noreferrer","data-testid":"link-trial-lock-unicorniq",children:n.lock.links[0]}),!["cairn","mara","larkspur","harbor","tamarack","ridgeline"].includes(Zn(t.tenantSlug))&&e.jsx(Io,{className:"underline",destination:"home",testId:"link-trial-lock-summit-site",children:n.lock.links[1]})]})]})})}function Aa(t){const s=t;return s?.data?.error||s?.message||"Something went wrong."}function $u(){const{data:t}=Ps(),{toast:s}=Be(),n=Ae(),[a,r]=y.useState(null),o=!!t?.tenantId&&!mr(t),{data:l}=Ol(void 0,{query:{enabled:o,refetchInterval:8e3,queryKey:ma()}}),h=Kl(),p=_l();if(!o)return null;const v=Date.now(),x=(l??[]).filter(d=>d.status==="pending"&&new Date(d.expiresAt).getTime()>v);if(x.length===0)return null;const w=(d,c)=>{n.invalidateQueries({queryKey:ma()}),s({title:d,...c?{description:c}:{}})};return e.jsx("div",{className:"px-4 pb-2 space-y-2","data-testid":"pending-setup-actions","data-feature-anchor":"connector-chat-tools-approval",children:x.map(d=>e.jsxs("div",{className:"rounded-lg border border-primary/30 bg-primary/5 p-3 flex items-start gap-3","data-testid":`pending-action-${d.id}`,children:[e.jsx(To,{className:"w-4 h-4 mt-0.5 shrink-0 text-primary"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-0.5",children:"Confirm this change"}),e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:d.readback}),d.implications&&d.implications.length>0&&e.jsx("ul",{className:"mt-1.5 space-y-0.5 text-xs text-muted-foreground list-disc pl-4","data-testid":`pending-action-implications-${d.id}`,children:d.implications.map((c,g)=>e.jsx("li",{children:c},g))})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs(D,{size:"sm",disabled:a===d.id,"data-testid":`button-confirm-action-${d.id}`,onClick:()=>{r(d.id),h.mutate({id:d.id},{onSuccess:c=>{r(null),c.status==="executed"?w("Done",c.outcomeSummary??void 0):w("That change failed",c.outcomeError??void 0)},onError:c=>{r(null),w("Could not confirm",Aa(c))}})},children:[a===d.id?e.jsx(re,{className:"w-4 h-4 animate-spin"}):e.jsx(Ct,{className:"w-4 h-4"}),"Confirm"]}),e.jsxs(D,{size:"sm",variant:"outline",disabled:a===d.id,"data-testid":`button-cancel-action-${d.id}`,onClick:()=>{r(d.id),p.mutate({id:d.id},{onSuccess:()=>{r(null),w("Cancelled â nothing was changed")},onError:c=>{r(null),w("Could not cancel",Aa(c))}})},children:[e.jsx(ut,{className:"w-4 h-4"}),"Cancel"]})]})]},d.id))})}const La="starter-prompt:",Eu="starter-script",Ys={surface:"chat"};function Ru({onPrefill:t,onNavigate:s,className:n}){const a=Ae(),{data:r}=Fl(Ys,{query:{queryKey:ha(Ys),staleTime:5*6e4,refetchOnWindowFocus:!1}}),o=ql(),l=x=>a.setQueryData(ha(Ys),x),h=x=>o.mutate({data:{key:x}},{onSuccess:l});if(!r||r.recommendationsEnabled===!1)return null;const p=r.recommendation,v=r.starterScript;
13return!p&&!v?null:e.jsxs("div",{className:n,"data-testid":"next-step-card",children:[v&&e.jsx(Lu,{script:v,busy:o.isPending,onUse:(x,w)=>{t(x),h(La+w)},onSkip:x=>h(La+x),onHide:()=>h(Eu)}),p&&e.jsx(Au,{rec:p,busy:o.isPending,onAct:()=>{p.action.kind==="prefill"?t(p.action.value):s(p.action.value)},onDismiss:()=>h(p.ruleId)})]})}function Au({rec:t,busy:s,onAct:n,onDismiss:a}){return e.jsxs("article",{"aria-label":"Suggestion from Vera","data-testid":"recommendation-card","data-rule-id":t.ruleId,className:"flex items-start gap-2.5 rounded-lg border border-primary/25 bg-primary/[0.07] px-3 py-2.5 text-xs",children:[e.jsx("span",{"aria-hidden":!0,className:"flex h-[22px] w-[22px] flex-none items-center justify-center rounded-md bg-primary text-primary-foreground",children:e.jsx($o,{className:"h-3 w-3"})}),e.jsxs("div",{className:"min-w-0 flex-1 leading-relaxed",children:[e.jsxs("div",{className:"text-[13px] font-medium text-foreground",children:[e.jsx("span",{className:"text-muted-foreground",children:"Try this next:"})," ",t.title]}),e.jsx("p",{className:"mt-0.5 text-muted-foreground","data-testid":"recommendation-why",children:t.why}),e.jsxs(D,{type:"button",size:"sm",variant:"secondary",className:"mt-2 h-7 px-2.5 text-xs",onClick:n,"data-testid":"recommendation-action",children:[t.action.kind==="prefill"?"Ask Vera":"Open",e.jsx(Ss,{className:"ml-1 h-3 w-3"})]})]}),e.jsx("button",{type:"button","aria-label":"Dismiss this suggestion",onClick:a,disabled:s,className:"flex-none rounded p-0.5 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","data-testid":"recommendation-dismiss",children:e.jsx(ut,{className:"h-3.5 w-3.5"})})]})}function Lu({script:t,busy:s,onUse:n,onSkip:a,onHide:r}){const{current:o,step:l,total:h}=t;return e.jsxs("article",{"aria-label":"Starter prompts","data-testid":"starter-prompt-strip","data-step":l,className:"mb-1.5 flex items-start gap-2.5 rounded-lg border bg-muted/40 px-3 py-2.5 text-xs",children:[e.jsx("span",{"aria-hidden":!0,className:"flex h-[22px] w-[22px] flex-none items-center justify-center rounded-md bg-primary/15 text-primary",children:e.jsx(Je,{className:"h-3 w-3"})}),e.jsxs("div",{className:"min-w-0 flex-1 leading-relaxed",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2",children:[e.jsx("span",{className:"text-[13px] font-medium text-foreground",children:o.title}),e.jsxs("span",{className:"text-[11px] text-muted-foreground","data-testid":"starter-prompt-step",children:["Step ",l," of ",h]})]}),e.jsxs("p",{className:"mt-0.5 text-muted-foreground","data-testid":"starter-prompt-text",children:["â",o.prompt,"â"]}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-1.5",children:[e.jsxs(D,{type:"button",size:"sm",variant:"secondary",className:"h-7 px-2.5 text-xs",disabled:s,onClick:()=>n(o.prompt,o.id),"data-testid":"starter-prompt-use",children:["Use this prompt",e.jsx(Ss,{className:"ml-1 h-3 w-3"})]}),e.jsx(D,{type:"button",size:"sm",variant:"ghost",className:"h-7 px-2 text-xs text-muted-foreground",disabled:s,onClick:()=>a(o.id),"data-testid":"starter-prompt-skip",children:"Skip"})]})]}),e.jsx("button",{type:"button","aria-label":"Hide starter prompts",onClick:r,disabled:s,className:"flex-none rounded p-0.5 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","data-testid":"starter-prompt-hide",children:e.jsx(ut,{className:"h-3.5 w-3.5"})})]})}function Mu(t){if(!t)return null;const s=new Date(t);return Number.isNaN(s.getTime())?null:s.toLocaleDateString(void 0,{month:"short",day:"numeric"})}function Ou({onNavigate:t,className:s}){const n=Ae(),{data:a}=Ul({query:{queryKey:pa(),staleTime:6e4,refetchOnWindowFocus:!1}}),r=zl(),o=a?.items??[];if(o.length===0)return null;const l=h=>n.setQueryData(pa(),h);return e.jsx("div",{className:s,"data-testid":"survey-prompt-card",children:e.jsx("ul",{className:"space-y-1.5",children:o.map(h=>{const p=Mu(h.dueAt);return e.jsx("li",{children:e.jsxs("article",{"aria-label":"Survey request","data-testid":"survey-prompt","data-content-item-id":h.contentItemId,className:"flex items-center gap-2.5 rounded-lg border border-primary/25 bg-primary/[0.07] px-3 py-2 text-xs",children:[e.jsx("span",{"aria-hidden":!0,
13className:"flex h-[22px] w-[22px] flex-none items-center justify-center rounded-md bg-primary text-primary-foreground",children:e.jsx(gd,{className:"h-3 w-3"})}),e.jsxs("div",{className:"min-w-0 flex-1 truncate text-[13px] text-foreground",children:[e.jsx("span",{className:"text-muted-foreground",children:"You have a survey:"})," ",e.jsx("span",{className:"font-medium",children:h.title}),p&&e.jsxs("span",{className:"text-muted-foreground",children:[" · due ",p]})]}),e.jsxs(D,{type:"button",size:"sm",variant:"secondary",className:"h-7 flex-none px-2.5 text-xs",onClick:()=>t(h.linkPath),"data-testid":"survey-prompt-take",children:["Take survey",e.jsx(Ss,{className:"ml-1 h-3 w-3"})]}),e.jsx("button",{type:"button","aria-label":`Dismiss the survey prompt for ${h.title}`,disabled:r.isPending,onClick:()=>r.mutate({id:h.contentItemId},{onSuccess:l}),className:"flex-none rounded p-0.5 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","data-testid":"survey-prompt-dismiss",children:e.jsx(ut,{className:"h-3.5 w-3.5"})})]})},h.contentItemId)})})})}const Ku=["text/uri-list","text/html","text/plain"];function rn(t){if(!t)return!1;const s=Array.from(t);return Ku.some(n=>s.includes(n))}function on(t){return t?Array.from(t).includes("Files"):!1}const _u={"&":"&","<":"<",">":">",""":'"',"'":"'","'":"'"," ":" "};function Fu(t){return t.replace(/&(?:amp|lt|gt|quot|nbsp|#39|#x27);/gi,s=>_u[s.toLowerCase()]??s)}function qu(t){return t.split(/\r?\n/).map(s=>s.trim()).filter(s=>s.length>0&&!s.startsWith("#"))}function Uu(t){const s=[],n=/<a\b[^>]*?\bhref\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/gi;let a;for(;(a=n.exec(t))!==null;){const r=(a[1]??a[2]??a[3]??"").trim();r&&s.push(Fu(r))}return s}function zu(t){return t.split(/\s+/).map(s=>s.trim().replace(/[),.;]+$/,"")).filter(s=>/^[a-z][a-z0-9+.-]*:\/\//i.test(s))}function Nn(t){try{return new URL(t)}catch{return null}}const Vu=/^\/(?:document|spreadsheets|presentation|drawings|forms|file)\/(?:u\/\d+\/)?d\/([A-Za-z0-9_-]+)/,Vr=/^\/drive\/(?:u\/\d+\/)?folders\/([A-Za-z0-9_-]+)/;function Qr(t){const s=Vu.exec(t.pathname);if(s)return s[1];if(/^\/(?:open|uc)\/?$/.test(t.pathname)){const n=t.searchParams.get("id");if(n)return n}return null}function Gr(t){return t==="drive.google.com"||t==="docs.google.com"}function Qu(t){return t.endsWith(".sharepoint.com")||t==="sharepoint.com"||t==="onedrive.live.com"||t==="1drv.ms"}function Gu(t){const s=Nn(t.trim());if(!s||s.protocol!=="https:")return"unsupported";const n=s.hostname.toLowerCase();return Gr(n)?Vr.test(s.pathname)?"drive_folder":Qr(s)?"drive":"unsupported":Qu(n)?"sharepoint":"web"}function Bu(t){const s=Nn(t.trim());if(!s)return t.trim();const n=s.hostname.toLowerCase();if(Gr(n)){const r=Qr(s);if(r)return`drive:${r}`;const o=Vr.exec(s.pathname);if(o)return`drive-folder:${o[1]}`}const a=s.pathname.replace(/\/+$/,"");return`${s.protocol}//${n}${a}${s.search}`}function Wu(t){const s=[...t.uriList?qu(t.uriList):[],...t.html?Uu(t.html):[],...t.text?zu(t.text):[]],n=new Set,a=[];for(const r of s){const o=r.trim();if(!o)continue;const l=Bu(o);n.has(l)||(n.add(l),a.push(o))}return a}function Hu(t){return Wu(t).map(s=>({url:s,kind:Gu(s)}))}const Yu="Folder links aren't imported by dropping â paste the folder link into the Knowledge Base panel's folder box.",Xu="Not a link Vera can import â drop an https link to a Drive file, a SharePoint or OneDrive file, or a web page.";function Ju(t,s){const n=[],a=[];for(const r of t)switch(r.kind){case"drive":s.isTenantAuthor&&s.googleConnected?n.push({url:r.url,via:"drive"}):s.personalDriveConnected?n.push({url:r.url,via:"drive_personal"}):s.isTenantAuthor?a.push({url:r.url,reason:"Google Workspace isn't connected â ask an admin to connect it in Settings, or connect Google Drive personally in Connections."}):a.push({url:r.url,reason:"Workspace-wide Drive imports are admin-only â connect Google Drive personally in Connections to import files you can see."});break;case"sharepoint":s.isTenantAuthor?s.sharePointConnected?n.push({url:r.url,via:"sharepoint"}):a.push({url:r.url,reason:"Microsoft 365 isn't connected â connect it in Connections to import SharePoint and OneDrive links."}):a.push({url:r.url,reason:"Only workspace admins can import from SharePoint."});break;case"web":s.isTenantAuthor?n.push({url:r.url,via:"web"}):a.push({url:r.url,reason:"Only workspace admins can add web pages to the Knowledge Base."});break;case"drive_folder":a.push({url:r.url,reason:Yu});break;default:a.push({url:r.url,reason:Xu});break}return{planned:n,blocked:a}}function Zu(t){const s=Nn(t.trim());if(!s)return t.length>48?`${t.slice(0,45)}â¦`:t;
13const n=s.pathname.split("/").filter(Boolean),a=n[n.length-1]??"";return a&&a.length<=32?`${s.hostname}/${a}`:s.hostname}function Ma(t){const{imported:s,failed:n,blocked:a}=t,o=s.length+n.length+a.length,l=[];for(const v of n)l.push(`${Zu(v.url)}: ${v.message}`);const h=new Map;for(const v of a)h.set(v.reason,(h.get(v.reason)??0)+1);for(const[v,x]of h)l.push(x===1?v:`${x} links â ${v}`);const p=l.length?l.join(" "):void 0;return s.length===0?{title:o===0?"Nothing to import from that drop":"Couldn't import that drop",description:p,variant:"destructive"}:n.length===0&&a.length===0?{title:s.length===1?`Imported "${s[0]}"`:`Imported ${s.length} links`}:{title:`Imported ${s.length} of ${o} links`,description:p}}function Br(t){const s=n=>{try{return t.getData(n)}catch{return""}};return{uriList:s("text/uri-list"),html:s("text/html"),text:s("text/plain")}}function Wr(t={}){const{toast:s}=Be(),n=Ae(),{data:a}=Ps(),{data:r}=br(),{data:o}=jr(),{data:l}=wr(),h=Nr(),p=kr(),v=Cr(),x=Sr(),w=pn(),d={isTenantAuthor:(a?.roles??[]).some(j=>["tenant_admin","tenant_group_manager"].includes(j)),googleConnected:!!r?.driveConfigured,sharePointConnected:!!o?.available,personalDriveConnected:(l??[]).some(j=>j.slug==="google-drive"&&j.connected&&j.tenantEnabled&&j.authType==="oauth")},[c,g]=y.useState(null),R=b.useRef(!1),$=async(j,L,T)=>{if(j.via==="drive")return(await h.mutateAsync({data:{url:j.url,...L?{estimateId:L}:{},...T?{visibility:T}:{}}})).filename;if(j.via==="drive_personal")return(await v.mutateAsync({data:{slug:"google-drive",url:j.url,...L?{estimateId:L}:{},...T?{visibility:T}:{}}})).filename;if(j.via==="sharepoint")return(await p.mutateAsync({data:{url:j.url,...L?{estimateId:L}:{},...T?{visibility:T}:{}}})).filename;const k=await x.mutateAsync({data:{url:j.url,...L?{estimateId:L}:{},...T?{visibility:T}:{}}});return k.document.displayName??k.document.filename},C=async(j,L,T)=>{const k=hr(L),B=Le(L,"That link couldn't be imported."),Z=pr(k,B,d.personalDriveConnected);if(!Z.offerPersonalRetry)return{failed:Z.message};try{return{imported:(await v.mutateAsync({data:{slug:"google-drive",url:j.url,...T?{estimateId:T}:{}}})).filename}}catch(U){return{failed:"Your workspace's Google account couldn't read it, and importing through your own Google Drive failed too: "+Le(U,"the retry failed.")}}},A=async j=>{if(!a?.tenantId||R.current)return;const{planned:L,blocked:T}=Ju(Hu(j),d);if(L.length===0){s(Ma({imported:[],failed:[],blocked:T}));return}let k=null;if(t.reviewImport){const U=await t.reviewImport({kind:L.every(W=>W.via==="web")?"url":"connector_document",label:L.length===1?L[0].url:`${L.length} dropped links`,itemCount:L.length,refs:L.map(W=>W.url)});if(!U.proceed)return;k=U.estimateId}R.current=!0,g({done:0,total:L.length});const B=[],Z=[];try{for(const U of L){try{try{B.push(await $(U,k))}catch(W){if(W?.data?.code!=="visibility_required")throw W;const G=await w.ask();if(!G)throw new Error("Import cancelled.");B.push(await $(U,k,G))}}catch(W){if(U.via==="drive"){const G=await C(U,W,k);"imported"in G?B.push(G.imported):Z.push({url:U.url,message:G.failed})}else Z.push({url:U.url,message:Le(W,"That link couldn't be imported.")})}g(W=>W&&{...W,done:W.done+1})}}finally{g(null),R.current=!1}B.length&&n.invalidateQueries({queryKey:Te()}),s(Ma({imported:B,failed:Z,blocked:T}))};return{canImportLinks:d.isTenantAuthor||d.personalDriveConnected,gates:d,linkImportProgress:c,importDroppedLinks:A,visibilityDialog:w.dialog}}function em(t,s){const{toast:n}=Be(),a=Ae(),r=Ir(),o=pn(),[l,h]=y.useState(null),[p,v]=y.useState(!1),[x,w]=y.useState("files"),d=b.useRef(0),{reviewImport:c,dialog:g}=xr(),{importDroppedLinks:R,linkImportProgress:$,visibilityDialog:C}=Wr({reviewImport:c}),A=b.useRef(!1),j=b.useRef(null),[L,T]=y.useState([]),k=()=>{t&&j.current?.click()},{ensureMediaRightsConsent:B,mediaRightsDialog:Z}=Lr(),U=async I=>{!t||I.length===0||await B(I)&&h(I)};return{pendingUpload:l,setPendingUpload:h,isDragging:p,dragKind:x,linkImportProgress:$,kbUploadInputRef:j,uploadingItems:L,openKbFilePicker:k,queueUpload:U,ingestKbFiles:async(I,H=null)=>{if(!t||I.length===0||A.current)return;A.current=!0;const ne=I.filter(ws),be=I.filter(_=>!ws(_));
13if(be.length&&n({title:"Some files were skipped",description:`${be.map(_=>_.name).join(", ")} â supported types: PDF, Word (.docx), PowerPoint (.pptx), .txt, .md, .zip archives of them, plus video/audio recordings.`}),ne.length===0){A.current=!1;return}let pe=ne;const xe=ne.filter(Xe);let De=null;if(xe.length>0){const _=await c({kind:"zip",label:xe.length===1?xe[0].name:`${xe.length} archives`,declaredBytes:xe.reduce((F,oe)=>F+oe.size,0),itemCount:xe.length,refs:xe.map(F=>F.name)});_.proceed?De=_.estimateId:(pe=ne.filter(F=>!Xe(F)),pe.length>0&&n({title:xe.length===1?"1 archive was not uploaded":`${xe.length} archives were not uploaded`,description:"Its cost estimate was not accepted. The remaining files are uploading as usual."}))}if(pe.length===0){A.current=!1;return}T(pe.map(_=>({name:_.name,phase:"uploading",fraction:0})));const fe=[];try{for(let _=0;_<pe.length;_++){const F=pe[_];try{const oe=s?.visibilityChoice?.()??null;let me=oe,ie=null,he;for(;;)try{he=await r.mutateAsync({file:F,estimateId:Xe(F)?De:H,initiativeId:s?.uploadScope?.()?.initiativeId??null,visibility:me??void 0,door:s?.door??"upload",resumeObjectPath:ie,onProgress:(Ce,Ee)=>T(m=>m.map((ge,E)=>E===_?{...ge,phase:Ce,fraction:Ee}:ge))});break}catch(Ce){if(!(Ce instanceof Lc))throw Ce;const Ee=await o.ask(oe);if(!Ee)throw new Error("Upload cancelled.");me=Ee,ie=Ce.objectPath}const We=Tr(he);fe.push(We),he.archive?n({title:`Importing ${he.archive.membersToImport} ${he.archive.membersToImport===1?"file":"files"} from ${F.name}`,description:(he.ingestNotices??[]).join(" ")||"Each supported file inside the archive becomes its own document. Watch the Knowledge Base panel for the per-file report."}):he.ingestJobId&&n({title:`${F.name} is being indexed in the background`,description:["It is too large to read inside one request, so it runs as a resumable job â progress, cost so far and a cancel are in the Knowledge Base panel.",...he.ingestNotices??[]].join(" ")}),We==="failed"&&n({title:`Couldn't process ${F.name}`,description:"The file was uploaded but could not be processed. Re-upload it to retry.",variant:"destructive"})}catch(oe){n({title:`Couldn't upload ${F.name}`,description:vs(oe),variant:"destructive"})}}}finally{T([]),A.current=!1}const M=$r(fe);M&&(a.invalidateQueries({queryKey:Te()}),n(M))},onDragEnter:I=>{if(!t)return;const H=I.dataTransfer.types,ne=on(H);!ne&&!rn(H)||(I.preventDefault(),w(ne?"files":"links"),d.current+=1,v(!0))},onDragOver:I=>{if(!t)return;const H=I.dataTransfer.types;!on(H)&&!rn(H)||I.preventDefault()},onDragLeave:I=>{t&&(d.current=Math.max(0,d.current-1),d.current===0&&v(!1))},onDrop:I=>{if(!t)return;I.preventDefault(),d.current=0,v(!1);const H=Array.from(I.dataTransfer.files);if(H.length>0){U(H);return}const ne=Br(I.dataTransfer);R(ne)},mediaRightsDialog:Z,importPreviewDialog:g,visibilityDialog:b.createElement(b.Fragment,null,o.dialog,C)}}function tm(t){const s=t.trim();return s?/\bshare\s+(?:this|that|it|these|them)?\s*(?:with|to)\s+my\s+(?:group|team)s?\b|\b(?:for|with)\s+my\s+(?:group|team)\s+only\b/i.test(s)?"my_group":/\b(?:whole|entire)\s+workspace\b|\bshare\s+(?:this|that|it)?\s*(?:with|to)\s+(?:the\s+)?(?:workspace|everyone|everybody)\b/i.test(s)?"workspace":/\bkeep\s+(?:this|that|it)\s+private\b|\b(?:only|just)\s+(?:for\s+)?me\b|\bdon'?t\s+share\s+(?:this|that|it)\b/i.test(s)?"private":null:null}const Hr=t=>`vera:voice-config-notice:${t}`;function sm(t){try{return localStorage.getItem(Hr(t))==="1"}catch{return!1}}function nm(t){try{localStorage.setItem(Hr(t),"1")}catch{}}const Oa="00000000-0000-0000-0000-000000000000";function am({me:t,activeConvId:s,setActiveConvId:n,tempMode:a,setTempMessages:r,setLiveMessages:o,createConv:l,sendMessage:h,bumpSavings:p,rememberReasoning:v}){const{toast:x}=Be(),w=Ae(),{data:d}=Vl({query:{enabled:!!t?.tenantId,queryKey:Ql()}}),c=Gl(),g=Eo(),R=b.useRef(()=>{});R.current=()=>g.stop();const $=b.useRef(()=>R.current()).current;b.useEffect(()=>()=>zs($),[$]);const[C,A]=y.useState(Ro),[j,L]=y.useState(!1),[T,k]=y.useState(!1),[B,Z]=y.useState(!1),U=b.useCallback(()=>{const M=t?.id;M&&(sm(M)||(nm(M),Z(!0)))},[t?.id]),[W,G]=y.useState(null),K=Bl(),ee=M=>{const _={...C,voice:M};A(_),ta(_)},N=M=>{const _={...C,lastEngine:M};A(_),ta(_)},I=async M=>{if(!d?.playback){x({title:"Voice playback",description:"Playback needs a provider API key or the ElevenLabs connector â ask an admin to configure one in Settings."});return}if(g.playingKey===M.id){g.stop(),zs($);return}const _=Lo(Mo(M));if(_){G(M.id);try{const F=await c.mutateAsync({data:{text:_,voice:C.voice,conversationId:s}});G(null),Oo($),await g.play(M.id,F),zs($)}catch(F){if(G(null),ea(F)){U();return}x({title:"Playback failed",description:Vs(F,"Couldn't play the audio. Try again."),variant:"destructive"})}}},H=M=>{fr(M,x),gr(M,x)},ne=async M=>{const _=M.trim();if(!_)return null;try{if(a){const me=await h.mutateAsync({id:Oa,data:{content:_}});return r(ie=>[...ie,me.userMessage,me.assistantMessage]),p(),H(me.assistantMessage),me.assistantMessage}let F=s;if(!F){const me=await l.mutateAsync({data:{title:"Voice conversation"}});F=me.id,n(me.id)}const oe=await h.mutateAsync({id:F,data:{content:_}});return v(oe.assistantMessage),w.invalidateQueries({queryKey:Bt(F)}),w.invalidateQueries({queryKey:Ke()}),p(),H(oe.assistantMessage),oe.assistantMessage}catch(F){return x({title:"Voice turn failed",description:Vs(F,"Voice turn failed. Try again."),variant:"destructive"}),null}},be=()=>{if(!d?.voiceMode){U();return}k(!0),L(!0)},pe=b.useRef(!1),xe=()=>{if(!d?.realtime){be();return}pe.current=!0,k(!0),L(!0)},De=b.useCallback(async()=>{try{let M=a?null:s;if(!a&&!M){const oe=await l.mutateAsync({data:{title:"Voice conversation"}});M=oe.id,n(oe.id),w.invalidateQueries({queryKey:Ke()})}const _=pe.current;pe.current=!1;const F=await K.mutateAsync({data:{temporary:a,interview:_}});return Ao("voice_session_started"),{session:F,conversationId:M}}catch(M){return ea(M)?(U(),null):(x({title:"Live voice",description:Vs(M,"Couldnât start a live session."),variant:"destructive"}),null)}},[K,x,a,s,l,w,n]),fe=b.useCallback(M=>{const _=M.conversationId??s;if(M.persisted&&_){w.invalidateQueries({queryKey:Bt(_)}),w.invalidateQueries({queryKey:Ke()});return}const F=new Date().toISOString(),oe=_??Oa,me=()=>typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():`live-${Date.now()}-${Math.random().toString(36).slice(2)}`,ie=[{id:me(),conversationId:oe,role:"user",content:M.userText||"ð¤",createdAt:F}];M.veraText&&ie.push({id:me(),conversationId:oe,role:"assistant",content:M.veraText,spans:M.spans.length>0?M.spans:[{text:M.veraText,kind:"unverified_llm"}],createdAt:F}),o(he=>[...he,...ie])},[s,w,o]);return{voiceCaps:d,ttsPlayback:g,ttsLoadingId:W,voicePrefs:C,setVoice:ee,setEngine:N,voiceModeOpen:j,setVoiceModeOpen:L,voiceEverOpened:T,voiceConfigOpen:B,setVoiceConfigOpen:Z,notifyVoiceConfig:U,handlePlay:I,sendTurnForVoice:ne,openVoiceMode:be,openVoiceInterview:xe,mintSession:De,handleLiveTurn:fe}}const rm=new Set(["take","me","to","the","a","an","my","page","screen","tab","open","go","show","navigate","please","up","bring","view","section","and"]);function im(t){return t.length>3&&t.endsWith("s")?t.slice(0,-1):t}function Xs(t){return t.toLowerCase().replace(/[^a-z0-9]+/g," ").split(" ").filter(
13Boolean).map(im)}function om(t,s){const n=Xs(s);if(n.length===0)return null;const a=n.filter(p=>!rm.has(p));if(a.length===0)return null;const r=a.join(" "),o=new Set(a);let l=null,h=null;for(const p of t){const v=Xs(p.label);if(v.join(" ")===r)return p;if(!l&&v.length>0&&v.every(x=>o.has(x))&&(l=p),!h){const x=Xs(p.href.split("/").filter(Boolean).pop()??"");x.length>0&&x.every(w=>o.has(w))&&(h=p)}}return l??h}function lm(t){if(t==null||!Number.isFinite(t)||t<0)return"â";if(t<60)return`${Math.round(t)}s`;if(t<3600)return`${Math.round(t/60)} min`;const s=Math.floor(t/3600),n=Math.round(t%3600/60);return n?`${s}h ${n}m`:`${s}h`}function Ka(t){return t==null||!Number.isFinite(t)?"â":t>0&&t<.01?"<$0.01":`$${t.toFixed(2)}`}function cm({job:t}){const s=Ae(),n=Hl(),a=Yl(),r=()=>{s.invalidateQueries({queryKey:Pr()}),s.invalidateQueries({queryKey:Te()})},o=Math.max(0,Math.min(100,t.percent)),l=t.status==="failed",h=t.format==="archive",p=t.memberOutcomes??[],v=p.filter(c=>c.outcome==="ingested").length,x=p.filter(c=>c.outcome!=="ingested"),w=new Map;for(const c of p){if(!c.bundle)continue;const g=w.get(c.bundle)??{concepts:0,reserved:0,refused:0};c.outcome==="ingested"?g.concepts+=1:c.conceptId==null?g.reserved+=1:g.refused+=1,w.set(c.bundle,g)}const d=t.status==="completed"||t.status==="failed"||t.status==="cancelled";return e.jsxs("div",{className:"rounded-md border bg-secondary/30 p-2 space-y-1.5","data-testid":`ingest-job-${t.jobId}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[t.status==="running"&&!t.cancelRequested&&e.jsx(re,{className:"w-3 h-3 animate-spin shrink-0 text-muted-foreground"}),l&&e.jsx(Ue,{className:"w-3 h-3 shrink-0 text-destructive"}),e.jsx("span",{className:"truncate font-medium",children:t.filename}),e.jsxs("span",{className:"ml-auto shrink-0 tabular-nums text-muted-foreground",children:[o,"%"]})]}),e.jsx("div",{className:"h-1 w-full overflow-hidden rounded-full bg-border",children:e.jsx("div",{className:"h-full rounded-full transition-[width] duration-300",style:{width:`${Math.max(2,o)}%`,backgroundColor:"var(--chat-accent-solid)"}})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-0.5 text-[10px] text-muted-foreground tabular-nums",children:[e.jsx("span",{children:h?`${v} of ${p.length||t.chunksWritten} file${(p.length||t.chunksWritten)===1?"":"s"} imported`:`${t.chunksWritten.toLocaleString()} chunks`}),e.jsx("span",{children:t.cancelRequested?"cancellingâ¦":t.status==="queued"?"queued":t.status==="completed"?"done":d?t.status:`~${lm(t.etaSeconds)} left`}),e.jsxs("span",{children:[Ka(t.costSoFarUsd),t.estimatedCostUsd!=null?` of ~${Ka(t.estimatedCostUsd)} estimated`:" so far"]})]}),h&&w.size>0&&e.jsx("div",{className:"space-y-0.5","data-testid":`archive-bundles-${t.jobId}`,children:[...w.entries()].map(([c,g])=>e.jsxs("p",{className:"text-[10px] leading-tight text-muted-foreground",children:["Open Knowledge Format bundle â",c,"â: ",g.concepts," concept",g.concepts===1?"":"s"," imported",g.reserved>0?`, ${g.reserved} index/log file${g.reserved===1?"":"s"} set aside`:"",g.refused>0?`, ${g.refused} refused`:"",". Declared review status is recorded as the bundle's claim, not Vera's."]},c))}),l&&t.error&&e.jsx("p",{className:"text-[10px] text-destructive leading-tight",children:t.error}),h&&x.length>0&&e.jsx("div",{className:"space-y-0.5","data-testid":`archive-report-${t.jobId}`,children:x.map(c=>e.jsxs("p",{className:"text-[10px] leading-tight text-muted-foreground truncate",title:`${c.entryName}${c.reason?` â ${c.reason}`:""}`,children:[e.jsx("span",{className:c.outcome==="failed"?"text-destructive":"",children:c.outcome==="failed"?"Failed":"Skipped"})," ",c.filename,c.reason?` â ${c.reason}`:""]},c.entryName))}),e.jsxs("div",{className:"flex justify-end gap-1",children:[l&&e.jsxs(D,{size:"sm",variant:"ghost",className:"h-6 text-[10px] px-1.5",disabled:a.isPending,onClick:()=>a.mutateAsync({jobId:t.jobId}).then(r,r),children:[e.jsx(yd,{className:"w-3 h-3 mr-1"})," Resume"]}),!t.cancelRequested&&!d&&e.jsxs(D,{size:"sm",variant:"ghost",className:"h-6 text-[10px] px-1.5 text-muted-foreground",disabled:n.isPending,onClick:()=>n.mutateAsync({jobId:t.jobId}).then(r,r),children:[e.jsx(Jc,{className:"w-3 h-3 mr-1"})," Cancel"]})]})]})}function dm(){const{data:t}=Wl({query:{queryKey:Pr(),refetchInterval:n=>(n.state.data?.length??0)>0?5e3:!1}}),s=t??[];return s.length===0?null:e.jsxs("div",{className:"space-y-1.5 pt-2","data-testid":"ingest-jobs",children:[e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Large files being indexed"}),s.map(n=>e.jsx(cm,{job:n},n.jobId))]})}function um(t){const[s,n]=y.useState(!1);return y.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const a=window.matchMedia(t),r=()=>n(a.matches);return r(),a.addEventListener("change",r),()=>a.removeEventListener("change",r)},[t]),s}
13const mm="(min-width: 1280px)",Yr={"google-drive":{placeholder:"Paste a Google Drive link or file ID",hint:`Docs, Sheets, Slides, PDF, Word, Excel, PowerPoint & text files import as ${O.verified} sources.`},"google-docs":{placeholder:"Paste a Google Docs link or ID",hint:`The document text imports as a ${O.verified} source.`},"google-sheet":{placeholder:"Paste a Google Sheets link or ID",hint:`Sheet rows import as CSV ${O.verified} sources.`},onedrive:{placeholder:"Paste a OneDrive file link",hint:`PDF, Word, Excel, PowerPoint & plain-text files import as ${O.verified} sources.`},dropbox:{placeholder:"Paste a Dropbox share link or /path",hint:`PDF, Word, Excel, PowerPoint & plain-text files import as ${O.verified} sources.`},box:{placeholder:"Paste a Box file link, ID, or /s/ shared link",hint:`PDF, Word, Excel, PowerPoint & plain-text files import as ${O.verified} sources.`}},hm=Object.keys(Yr),Xr={notion:{placeholder:"Paste a Notion page link or ID",hint:`The page and its sub-pages import as ${O.verified} sources.`},confluence:{placeholder:"Paste a Confluence page or space link",hint:`The page â or a whole space â imports as ${O.verified} sources.`},onenote:{placeholder:"Paste a OneNote page or section id",hint:`The page â or every page in a section â imports as ${O.verified} sources. Ask Vera to list your OneNote notebooks to find the ids.`}},Jr=Object.keys(Xr),Zr={servicenow:{placeholder:"Paste your ServiceNow instance URL (acme.service-now.com)",hint:`Change requests & incidents import as structured ${O.verified} sources.`},cmdb:{placeholder:"Paste your ServiceNow instance URL (acme.service-now.com)",hint:`Asset / configuration-item (CI) records import as structured ${O.verified} sources.`},jira:{placeholder:"Paste a Jira project key (e.g. OPS) or an issue link",hint:`Issues import as structured ${O.verified} sources.`},github:{placeholder:"Paste a GitHub repository (owner/repo) or its link",hint:`Repository issues import as structured ${O.verified} sources.`},salesforce:{placeholder:"Paste your Salesforce instance URL (acme.my.salesforce.com)",hint:`Cases, accounts, contacts & opportunities import as structured ${O.verified} sources.`},pipedrive:{placeholder:"Type a table: deals, persons, organizations or activities â or type all for every table",hint:`Pipedrive records import as structured ${O.verified} sources.`},redtail:{placeholder:"Type a table: contacts, households or activities â or type all for every table",hint:`Redtail CRM records import as structured ${O.verified} sources.`},wealthbox:{placeholder:"Type a table: contacts, households, tasks or notes â or type all for every table",hint:`Wealthbox records import as structured ${O.verified} sources.`},quickbooks:{placeholder:"Type <company (realm) ID>/<table> â customers, invoices or payments (or <realm ID>/all for every table)",hint:`QuickBooks Online records import read-only as structured ${O.verified} sources.`},xero:{placeholder:"Type a table: contacts, invoices or payments â or type all for every table",hint:`Xero records import read-only as structured ${O.verified} sources.`},workwave:{placeholder:"Type <territory ID>/<table> â orders, routes or vehicles (or <territory ID>/all for every table)",hint:`WorkWave Route Manager records import as structured ${O.verified} sources.`},"aws-marketplace":{placeholder:"Type <catalog>/<table> â AWS/opportunities, AWS/offers or Sandbox/opportunities (or AWS/all for every table)",hint:`ACE co-sell deals and private offers import as structured ${O.verified} sources; ACE deals also mirror to your opportunities.`},stripe:{placeholder:"Type a table: customers, invoices or charges â or type all for every table",hint:`Stripe records import read-only as structured ${O.verified} sources; invoices and charges reconcile against your opportunities.`},chargebee:{placeholder:"Type <site>/<table> â customers, invoices or transactions (or <site>/all for every table)",hint:`Chargebee records import read-only as structured ${O.verified} sources; invoices and payments reconcile against your opportunities.`},maxio:{placeholder:"Type <subdomain>/<table> â customers, invoices or payments (or <subdomain>
13/all for every table)",hint:`Maxio records import read-only as structured ${O.verified} sources; invoices and payments reconcile against your opportunities.`},recurly:{placeholder:"Type a table: accounts, invoices or transactions â or type all for every table",hint:`Recurly records import read-only as structured ${O.verified} sources; invoices and transactions reconcile against your opportunities.`},netsuite:{placeholder:"Type <account ID>/<table> â customers, salesorders or invoices (or <account ID>/all for every table)",hint:`NetSuite records import read-only as structured ${O.verified} sources.`},"dynamics-365":{placeholder:"Paste your Dynamics 365 organization URL (contoso.crm.dynamics.com)",hint:`Accounts, contacts, opportunities & cases import as structured ${O.verified} sources from the environment saved on your connection.`}},ei=Object.keys(Zr),_a={"google-drive":{placeholder:"Paste one or more Google Drive folder links (one per line)",hint:`Every supported file in each folder and its sub-folders imports as ${O.verified} sources.`},onedrive:{placeholder:"Paste one or more OneDrive folder links (one per line)",hint:`Every supported file in each folder and its sub-folders imports as ${O.verified} sources.`},sharepoint:{placeholder:"Paste one or more SharePoint folder links (one per line)",hint:`Every supported file in each folder and its sub-folders imports as ${O.verified} sources.`},dropbox:{placeholder:"Paste one or more Dropbox folder links or /paths (one per line)",hint:`Every supported file in each folder and its sub-folders imports as ${O.verified} sources.`},box:{placeholder:"Paste one or more Box folder links or IDs (one per line)",hint:`Every supported file in each folder and its sub-folders imports as ${O.verified} sources.`}},pm=["google-drive","onedrive","dropbox","box"],Fa={...Yr,...Xr,...Zr},xm=[...hm,...Jr,...ei],qa=t=>Jr.includes(t),Ua=t=>ei.includes(t),za="vera:kb-width",Va="vera:kb-collapsed",ti=280,si=520,Ht=320;function Qa(t){return Number.isFinite(t)?Math.max(ti,Math.min(si,Math.round(t))):Ht}function fm(){const[t,s]=y.useState(()=>{if(typeof window>"u")return Ht;const a=window.localStorage.getItem(za);return a?Qa(parseInt(a,10)):Ht}),n=b.useCallback(a=>{const r=Qa(a);s(r);try{window.localStorage.setItem(za,String(r))}catch{}},[]);return[t,n]}function gm(){const[t,s]=y.useState(()=>typeof window>"u"?!0:window.localStorage.getItem(Va)!=="0"),n=b.useCallback(a=>{s(a);try{window.localStorage.setItem(Va,a?"1":"0")}catch{}},[]);return[t,n]}function vm({sources:t,activeSource:s,setActiveSource:n,uploadOpen:a,onUploadOpenChange:r,collapsed:o,onCollapsedChange:l,onOpenDocument:h}){const[p,v]=fm(),[x,w]=y.useState(!1),d=b.useRef(null),c=t.length,g=b.useCallback(R=>{if(R.button!==0)return;R.preventDefault();const $=d.current?.getBoundingClientRect().right??0;w(!0);const C=j=>v($-j.clientX),A=()=>{w(!1),window.removeEventListener("pointermove",C),window.removeEventListener("pointerup",A),window.removeEventListener("pointercancel",A),document.body.style.userSelect="",document.body.style.cursor=""};window.addEventListener("pointermove",C),window.addEventListener("pointerup",A),window.addEventListener("pointercancel",A),document.body.style.userSelect="none",document.body.style.cursor="col-resize"},[v]);return b.useEffect(()=>{if(x)return()=>{document.body.style.userSelect="",document.body.style.cursor=""}},[x]),o?e.jsxs("aside",{className:"w-11 border-l hidden xl:flex flex-col items-center shrink-0 min-h-0 overflow-clip bg-card",children:[e.jsx("div",{className:"h-14 flex items-center justify-center shrink-0",children:e.jsxs(_e,{children:[e.jsx(Fe,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground",onClick:()=>l(!1),"aria-label":"Expand Knowledge Base",children:e.jsx($d,{className:"w-4 h-4"})})}),e.jsx(qe,{side:"left",children:e.jsx("p",{className:"text-xs",children:"Expand Knowledge Base"})})]})}),e.jsxs(_e,{children:[e.jsx(Fe,{asChild:!0,children:e.jsxs("button",{type:"button",onClick:()=>l(!1),"aria-label":c>0?`Knowledge Base â ${c} active source${c===1?"":"s"}`:"Knowledge Base",className:"relative flex h-9 w-9 items-center justify-center rounded-lg text-primary transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[e.jsx(Je,{className:"w-4 h-4"}),c>0&&e.jsx("span",{className:"absolute -right-0.5 -top-0.5 flex h-4 min-w-4 items-center justify-center rounded-full bg-primary px-1 text-[10px] font-bold leading-none text-primary-foreground",children:c>9?"9+":c})]})}),e.jsx(qe,{side:"left",children:e.jsx("p",{className:"text-xs",children:c>0?`${c} active source${c===1?"":"s"}`:"Knowledge Base"})})]}),e.jsx("span",{className:"mt-3 text-[10px] font-semibold uppercase tracking-widest text-muted-foreground [writing-mode:vertical-rl]","aria-hidden":"true",children:"Knowledge Base"})]}):e.jsxs("aside",{ref:d,className:`border-l hidden xl:flex flex-col shrink-0 relative min-h-0 overflow-clip ${x?"":"transition-[width] duration-200"}`,style:{width:p},children:[e.jsx(ni,{sources:t,activeSource:s,setActiveSource:n,uploadOpen:a,onUploadOpe
13nChange:r,onCollapse:()=>l(!0),onOpenDocument:h}),e.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":"Resize Knowledge Base","aria-valuenow":p,"aria-valuemin":ti,"aria-valuemax":si,tabIndex:0,onPointerDown:g,onDoubleClick:()=>v(Ht),onKeyDown:R=>{R.key==="ArrowLeft"?(R.preventDefault(),v(p+16)):R.key==="ArrowRight"?(R.preventDefault(),v(p-16)):R.key==="Home"&&(R.preventDefault(),v(Ht))},className:"group absolute inset-y-0 left-0 z-20 w-2 -translate-x-1/2 cursor-col-resize focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",title:"Drag to resize · double-click to reset",children:e.jsx("div",{className:`absolute inset-y-0 left-1/2 w-px -translate-x-1/2 transition-colors ${x?"bg-primary":"bg-transparent group-hover:bg-primary/40 group-focus-visible:bg-primary/60"}`})})]})}function ni({sources:t,activeSource:s,setActiveSource:n,sheet:a=!1,uploadOpen:r,onUploadOpenChange:o,onCollapse:l,onOpenDocument:h}){const p=um(mm),v=!!a||p,x=nn(an.legend,v),w=nn(an.panel,v),d=Ae(),{toast:c}=Be(),[,g]=Ha(),R=Xl(),$=Ir(),{ask:C,dialog:A}=vd(),{ensureMediaRightsConsent:j,mediaRightsDialog:L}=Lr(),{reviewImport:T,dialog:k}=xr(),{ask:B,dialog:Z}=pn(),{data:U}=Ps(),{data:W}=br(),G=Nr(),{data:K}=jr(),ee=kr(),N=Cr(),I=Jl(),H=Zl(),ne=ec(),be=Sr(),{data:pe}=wr(),xe=(U?.roles??[]).some(u=>["tenant_admin","tenant_group_manager"].includes(u)),De=(pe??[]).some(u=>u.slug==="google-drive"&&u.connected&&u.tenantEnabled&&u.authType==="oauth"),fe=Ko({isTenantAuthor:xe,workspaceGoogleConnected:!!W?.driveConfigured,personalDriveConnected:De}),M=fe!==null,_=xe&&!!K?.available,F=xm.map(u=>(pe??[]).find(P=>P.slug===u&&P.connected&&P.tenantEnabled)).filter(u=>!!u).filter(u=>xe||u.authType==="oauth"),oe=[...pm.map(u=>(pe??[]).find(P=>P.slug===u&&P.connected&&P.tenantEnabled)).filter(u=>!!u).map(u=>({slug:u.slug,name:u.name})),..._?[{slug:"sharepoint",name:"SharePoint"}]:[]],me=r,ie=o,[he,We]=y.useState(""),[Ce,Ee]=y.useState(""),[m,ge]=y.useState([]),E=b.useRef(null),Y=b.useRef(!1),{importDroppedLinks:le,linkImportProgress:ce}=Wr({reviewImport:T}),[je,z]=y.useState(null),nt=u=>on(u.dataTransfer.types)||rn(u.dataTransfer.types),we=u=>P=>{nt(P)&&(P.preventDefault(),P.stopPropagation(),z(u))},at=u=>{u.currentTarget.contains(u.relatedTarget)||z(null)},rt=u=>{if(!nt(u))return;u.preventDefault(),u.stopPropagation(),z(null);const P=Array.from(u.dataTransfer.files);if(P.length>0){vt(P);return}le(Br(u.dataTransfer))},[Ne,$t]=y.useState(""),[St,Et]=y.useState(""),[Me,Rt]=y.useState(null),[At,mt]=y.useState(""),[Lt,ze]=y.useState(null),[ht,it]=y.useState(""),[pt,Mt]=y.useState(""),[Xt,Jt]=y.useState(""),[Ot,Kt]=y.useState(null),[Ds,Zt]=y.useState(!1),xt=Lt&&oe.some(u=>u.slug===Lt)?Lt:oe[0]?.slug??null,ft=Me&&F.some(u=>u.slug===Me)?Me:F[0]?.slug??null,gt=t.find(u=>u.id===s)?.tier??null,es=tc(),ts=u=>{es.mutate({id:u.id},{onSuccess:()=>{d.invalidateQueries({queryKey:Te()}),d.invalidateQueries({queryKey:["/api/documents/search"]}),c({title:`Removed "${u.name}"`,description:"The upload was undone."})},onError:P=>{const q=P?.data?.code;if(q==="delete_undo_expired"||q==="delete_not_permitted"){c({title:"The undo window has passed",description:P?.data?.error??"Ask a workspace admin to remove it."});return}c({title:"Couldn't undo the upload",description:P?.data?.error??"Try again, or ask a workspace admin.",variant:"destructive"})}})},vt=async u=>{if(Y.current)return;if(Y.current=!0,!await j(u)){Y.current=!1;return}const P=u.filter(ws),q=u.filter(X=>!ws(X));q.length&&c({title:"Some files were skipped",description:`${q.map(X=>X.name).join(", ")} â supported types: PDF, Word (.docx), PowerPoint (.pptx), .txt, .md, .zip archives of them (including Open Knowledge Format bundles), plus video/audio recordings.`});const se=P.filter(X=>!Xe(X)&&!ys(X));let de=null,ue=P;if(se.length>0){const X=await T({kind:"upload",label:se.length===1?se[0].name:`${se.length} files`,declaredBytes:se.reduce((ae,He)=>ae+He.size,0),itemCount:se.length,refs:se.map(ae=>ae.name)},{forceAcceptance:se.some(Mc)});X.proceed?de=X.estimateId:(ue=P.filter(ae=>Xe(ae)||ys(ae)),ue.length>0&&c({title:se.length===1?"1 file was not uploaded":`${se.length} files were not uploaded`,description:"Their cost estimate was not accepted. The archives and recordings are uploading as usual."}))}const ve=ue.filter(Xe);let te=null;if(ve.length>0){const X=await T({kind:"zip",label:ve.length===1?ve[0].name:`${ve.length} archives`,declaredBytes:ve.reduce((ae,He)=>ae+He.size,0),itemCount:ve.length,refs:ve.map(ae=>ae.name)}
13);X.proceed?te=X.estimateId:(ue=ue.filter(ae=>!Xe(ae)),ue.length>0&&c({title:ve.length===1?"1 archive was not uploaded":`${ve.length} archives were not uploaded`,description:"Its cost estimate was not accepted. The remaining files are uploading as usual."}))}if(ue.length===0){Y.current=!1;return}ge(ue.map(X=>({name:X.name,phase:"uploading",fraction:0})));const ye=[],Ie=[];try{for(let X=0;X<ue.length;X++){const ae=ue[X],He=Xe(ae)?te:ys(ae)?null:de,as=(Se,Oe)=>ge(yt=>yt.map((bt,Es)=>Es===X?{...bt,phase:Se,fraction:Oe}:bt)),qt=Se=>{const Oe=Tr(Se);ye.push(Oe),Oe==="failed"?c({title:`Couldn't process ${ae.name}`,description:"The file was uploaded but could not be processed. Re-upload it to retry.",variant:"destructive"}):Se.archive?c({title:`Importing ${Se.archive.membersToImport} ${Se.archive.membersToImport===1?"file":"files"} from ${ae.name}`,description:(Se.ingestNotices??[]).join(" ")||"Each supported file inside the archive becomes its own document."}):Ie.push({id:Se.id,name:Se.filename||ae.name})};try{qt(await $.mutateAsync({file:ae,estimateId:He,onProgress:as}))}catch(Se){const Oe=Oc(Se);if(Oe){const yt=await C({filename:ae.name,existingFilename:Oe.duplicate?.existingFilename??null});if(yt)try{qt(await $.mutateAsync({file:ae,estimateId:He,onProgress:as,resumeObjectPath:Oe.objectPath,duplicateResolution:yt}))}catch(bt){c({title:`Couldn't upload ${ae.name}`,description:vs(bt),variant:"destructive"})}continue}if(Kc(Se)){c({title:`${ae.name} is already in your knowledge base`,description:vs(Se)});continue}c({title:`Couldn't upload ${ae.name}`,description:vs(Se),variant:"destructive"})}}}finally{ge([]),Y.current=!1}const ke=$r(ye);if(ke){if(d.invalidateQueries({queryKey:Te()}),Ie.length===1){const X=Ie[0];c({...ke,duration:3e4,action:e.jsx(ja,{altText:"Undo this upload",onClick:()=>ts(X),children:"Undo"})})}else c(ke);ie(!1)}},Is=async()=>{if(!he||!Ce)return;const u=await T({kind:"upload",label:he,charCount:Ce.length,itemCount:1,refs:[he]});u.proceed&&R.mutate({data:{filename:he,mimeType:"text/plain",text:Ce,estimateId:u.estimateId}},{onSuccess:()=>{c({title:"Document ingested successfully"}),d.invalidateQueries({queryKey:Te()}),ie(!1),We(""),Ee("")},onError:P=>c({title:"Failed to upload",description:Le(P,"The document could not be ingested. Try again."),variant:"destructive"})})},ss=async u=>{const P=await T({kind:"connector_document",slug:"google-drive",label:u,refs:[u]});P.proceed&&N.mutate({data:{slug:"google-drive",url:u,estimateId:P.estimateId}},{onSuccess:q=>{c({title:`Imported "${q.filename}" from your Google Drive`}),d.invalidateQueries({queryKey:Te()}),$t(""),ie(!1)},onError:q=>c({title:"Couldn't import from your Google Drive",description:Le(q,"The import through your connected Google Drive failed."),variant:"destructive"})})},_t=async()=>{const u=Ne.trim();if(!u)return;if(fe==="personal"){ss(u);return}const P=await T({kind:"connector_document",slug:"google-drive",label:u,refs:[u]});P.proceed&&G.mutate({data:{url:u,estimateId:P.estimateId}},{onSuccess:q=>{c({title:`Imported "${q.filename}" from Google Drive`}),d.invalidateQueries({queryKey:Te()}),$t(""),ie(!1)},onError:q=>{const se=hr(q),de=Le(q,"Couldn't import from Google Drive."),ue=pr(se,de,De);c({title:"Couldn't import from Google Drive",description:ue.message,variant:"destructive",...ue.offerPersonalRetry?{action:e.jsx(ja,{altText:"Retry through your own Google Drive",onClick:()=>ss(u),children:"Use my Drive"})}:{}})}})},Ts=async()=>{const u=St.trim();if(!u)return;const P=await T({kind:"connector_document",slug:"sharepoint",label:u,refs:[u]});P.proceed&&ee.mutate({data:{url:u,estimateId:P.estimateId}},{onSuccess:q=>{c({title:`Imported "${q.filename}" from SharePoint`}),d.invalidateQueries({queryKey:Te()}),Et(""),ie(!1)},onError:q=>c({title:"Couldn't import from SharePoint",description:Le(q,"Check the link and that Microsoft 365 is still connected."),variant:"destructive"})})},ns=async()=>{const u=At.trim(),P=ft;if(!u||!P)return;const q=F.find(te=>te.slug===P)?.name??"the app",se=Ua(P)?"connector_records":qa(P)?"connector_pages":"connector_document",de=await T({kind:se,slug:P,label:u,refs:[u]});if(!de.proceed)return;const ue=de.estimateId,ve=te=>{const{created:ye,updated:Ie,unchanged:ke}=te,X=[];ye&&X.push(`${ye} new`),Ie&&X.push(`${Ie} updated`),ke&&X.push(`${ke} already up to date`);const ae=X.length?X.join(", "):"nothing to import";c({title:`Synced from ${q}: ${ae}`}),d.invalidateQueries({queryKey:Te()}),mt(""),ie(!1)};if(Ua(P)){try{let te;try{te=await H.mutateAsync({data:{slug:P,url:u,estimateId:ue}})}catch(ye){if(ye?.data?.code!=="visibility_required")throw ye;const Ie=await B();if(!Ie)return;te=await H.mutateAsync({data:{slug:P,url:u,estimateId:ue,visibility:Ie}})}ve(te)}catch(te){c({title:`Couldn't import from ${q}`,description:Le(te,`Check the link and that ${q} is still connected.`),variant:"destructive"})}return}if(qa(P)){I.mutate({data:{slug:P,url:u,estimateId:ue}},{onSuccess:ve,onError:te=>c({title:`Couldn't import from ${q}`,description:Le(te,`Check the link and that ${q} is still connected.`),variant:"destructive"})});return}N.mutate({data:{slug:P,url:u,estimateId:ue}},{onSuccess:te=>{c({title:`Imported "${te.filename}" from ${q}`}),d.invalidateQueries({queryKey:Te()}),mt(""),ie(!1)},onError:te=>c({title:`Couldn't import from ${q}`,description:Le(te,`Check the link and that ${q} is still connected.`),variant:"destructive"})})},$s=async()=>{const u=xt;if(!u)return;const P=ht.split(/[\n,]+/).map(de=>de.trim()).filter(de=>de.length>0);if(P.length===0)return;const q=oe.find(de=>de.slug===u)?.name??"the app",se=await T({kind:"connector_folders",slug:u,urls:P,label:P.length===1?P[0]:`${P.length} folders from ${q}`,refs:P});if(se.proceed)try{let de;try{de=await ne.mutateAsync({data:{slug:u,urls:P,estimateId:se.estimateId}})}catch(ke){if(ke?.data?.code!=="visibility_required")throw ke;const X=await B();if(!X)return;de=await ne.mutateAsync({data:{slug:u,urls:P,estimateId:se.estimateId,visibility:X}})}const{created:ue,updated:ve,unchanged:te}=de,ye=[];ue&&ye.push(`${ue} new`),ve&&ye.push(`${ve} updated`),te&&ye.push(`${te} already up to date`);const Ie=ye.length?ye.join(", "):"nothing to import";c({title:`Imported from ${q}: ${Ie}`}),d.invalidateQueries({queryKey:Te()}),it(""),ie(!1)}catch(de){c({title:`Couldn't import folders from ${q}`,description:Le(de,`Check the links and that ${q} is still connected.`),variant:"destructive"})}},Ft=async()=>{const u=pt.trim();if(!u)return;Kt(null);const P=Xt.trim(),q=await T({kind:"url",label:u,refs:[u]});q.proceed&&be.mutate({data:{url:u,estimateId:q.estimateId,...P?{name:P}:{}}},{onSuccess:se=>{c({title:se.outcome==="created"?`Added "${se.document.displayName}" from the web`:`"${se.document.displayName}" was already in the knowledge base â ${se.outcome==="updated"?"refreshed it in place":"it is already up to date"}`}),d.invalidateQueries({queryKey:Te()}),Mt(""),Jt(""),ie(!1)},onError:se=>Kt(se?.data?.error??"Couldn't add that web page. Check the address and try again.")})};return e.jsxs("div",{className:"flex flex-col h-full min-h-0 bg-card",children:[e.jsxs("div",{className:`h-14 border-b flex items-center justify-between px-4 shrink-0 ${a?"pr-12":""}`,children:[e.jsxs("h3",{className:"font-semibold text-sm flex items-center gap-2",children:[e.jsx(Je,{className:"w-4 h-4 text-primary"})," Knowledge Base"]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(_e,{children:[e.jsx(Fe,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>o(!r),"aria-label":"Add a document",children:e.jsx(_o,{className:"w-4 h-4"})})}),e.jsx(qe,{side:"bottom",children:e.jsx("p",{className:"text-xs",children:"Add a document"})})]}),l&&e.jsxs(_e,{children:[e.jsx(Fe,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:l,"aria-label":"Collapse Knowledge Base",children:e.jsx(Id,{className:"w-4 h-4"})})}),e.jsx(qe,{side:"bottom",children:e.jsx("p",{className:"text-xs",children:"Collapse"})})]})]})]}),e.jsxs(cn,{className:"flex-1",children:[e.jsxs("div",{className:"p-4 border-b",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"Provenance Legend"}),e.jsxs("div",{className:"mt-3 space-y-1.5",children:[e.jsx(Js,{tier:"verified",label:x(O.verifiedSource),desc:"Your cited Verified Sources and documents.",icon:e.jsx(ed,{className:"w-3.5 h-3.5"}),active:gt==="verified"}),e.jsx(Js,{tier:"platform",label:"Platform Knowledge",desc:"Answered from your platform workspace.",icon:e.jsx(bd,{className:"w-3.5 h-3.5"}),active:gt==="platform"}),e.jsx(Js,{tier:"ai",label:"AI-Reasoning",desc:"Model reasoning â verify before relying. Includes external web pages, listed below with their links.",icon:e.jsx(Ue,{className:"w-3.5 h-3.5"}),active:gt==="web"})]})]}),e.jsxs("div",{className:"p-4 border-b",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:w(en("receipts"))}),t.length>0&&e.jsx("span",{className:"text-[10px] font-medium text-primary bg-primary/10 px-1.5 py-0.5 rounded-full",children:t.length})]}),t.length===0?e.jsx("p",{className:"text-xs text-muted-foreground leading-relaxed","data-testid":"cited-sources-empty",children:"Nothing has been cited yet. Ask a question and the sources behind Vera's answer appear here â every one of them open
13able."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-2",children:t.map(u=>{const P=u.tier==="web"?u.url?()=>window.open(u.url,"_blank","noopener,noreferrer"):void 0:u.tier==="platform"?sa(U,"/learning")?void 0:()=>g("/learning"):u.documentId?()=>h?.(u.documentId,u.chunkIndex??null):void 0,q=u.tier==="web"?u.url?"Check this page yourself":"Consulted on the public web":u.tier==="platform"?sa(U,"/learning")?"On file in this workspace":"Open in Vera":u.documentId?"Open the source":"On file in this workspace";return e.jsx(bm,{src:u,active:s===u.id,onEnter:()=>n(u.id),onLeave:()=>n(null),onOpen:P,openLabel:q},u.id)})}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-3 text-[10px] text-muted-foreground",children:[e.jsx(bs,{className:"w-3 h-3 shrink-0"}),"Hover a citation or source to link them."]})]}),e.jsxs("button",{type:"button",onClick:()=>g("/knowledge"),className:"mt-3 inline-flex items-center gap-1 text-[11px] text-primary hover:underline w-fit","data-testid":"link-knowledge-base",children:[e.jsx(Fo,{className:"w-3 h-3"})," Browse the whole knowledge base"]})]}),e.jsxs("div",{className:"p-4",children:[e.jsx("div",{className:"flex items-center justify-between mb-3",children:e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"Add to the knowledge base"})}),e.jsx("input",{ref:E,type:"file",accept:Dr,multiple:!0,className:"hidden",onChange:u=>{const P=Array.from(u.target.files??[]);u.currentTarget.value="",P.length&&vt(P)}}),k,Z,L,me&&e.jsxs("div",{className:"mb-3 p-3 rounded-lg border bg-secondary/30 space-y-3 transition-shadow",style:je?{borderColor:"var(--chat-accent-solid)",boxShadow:"0 0 0 2px var(--chat-accent-solid)"}:void 0,onDragEnter:we("panel"),onDragOver:we("panel"),onDragLeave:at,onDrop:rt,children:[e.jsxs("p",{className:"text-[10px] text-muted-foreground leading-tight flex items-start gap-1",children:[e.jsx(qc,{className:"w-3 h-3 mt-px shrink-0"}),"Anything you add here becomes searchable by everyone in ",U?.tenantName??"your workspace","."]}),A,e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 w-full text-xs justify-start",onClick:()=>E.current?.click(),disabled:$.isPending,children:[$.isPending?e.jsx(re,{className:"w-3.5 h-3.5 animate-spin mr-1.5"}):e.jsx(Mr,{className:"w-3.5 h-3.5 mr-1.5"}),"Upload a file"]}),m.length>0&&(()=>{const u=m.reduce((se,de)=>se+de.fraction,0)/m.length,P=Math.round(u*100),q=u>=1?"Processingâ¦":`Uploading ${m.length===1?m[0].name:`${m.length} files`}⦠${P}%`;return e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[e.jsx("span",{className:"truncate block",children:q}),e.jsx("div",{className:"mt-1 h-1 w-full overflow-hidden rounded-full bg-border",children:e.jsx("div",{className:"h-full rounded-full transition-[width] duration-200",style:{width:`${Math.max(4,P)}%`,backgroundColor:"var(--chat-accent-solid)"}})})]})})(),e.jsx(dm,{}),ce&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-muted-foreground",children:[e.jsx(re,{className:"w-3 h-3 animate-spin shrink-0"}),e.jsx("span",{className:"truncate",children:ce.total===1?"Importing dropped linkâ¦":`Importing dropped links⦠${ce.done} of ${ce.total}`})]}),e.jsxs("p",{className:"text-[10px] text-muted-foreground leading-tight",children:["PDF, Word (.docx), PowerPoint (.pptx), .txt & .md · ",fn," max · added to your knowledge base for ",O.verified," extraction."]}),e.jsxs("p",{className:"text-[10px] text-muted-foreground leading-tight",children:["Or drop files here",M&&_?" â or drag a file straight out of Google Drive, SharePoint or OneDrive.":M?" â or drag a file straight out of Google Drive.":_?" â or drag a file straight out of SharePoint or OneDrive.":"."]}),e.jsxs("div",{className:"pt-3 border-t space-y-2",children:[e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Or pick files from a connected source"}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[10px] text-muted-foreground leading-tight",children:"Browse Google Drive, SharePoint, OneDrive, Dropbox or Box and tick the files to import. Imports only what you pick â the folder isn't kept in sync."}),e.jsxs(D,{size:"sm",variant:"outline",className:"h-7 text-xs shrink-0",onClick:()=>Zt(!0),children:[e.jsx(Sd,{className:"w-3 h-3 mr-1"})," Browse"]})]})]}),e.jsxs("div",{className:"pt-3 border-t space-y-3",children:[e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Or paste text"}),e.jsx($e,{placeholder:"Filename (e.g. policy.txt)",value:he,onCh
13ange:u=>We(u.target.value),className:"h-8 text-xs bg-background"}),e.jsx(It,{placeholder:"Paste content here...",value:Ce,onChange:u=>Ee(u.target.value),className:"min-h-[100px] text-xs resize-none bg-background"}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(D,{variant:"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>ie(!1),children:"Cancel"}),e.jsxs(D,{size:"sm",className:"h-7 text-xs",onClick:Is,disabled:!he||!Ce||R.isPending,children:[R.isPending?e.jsx(re,{className:"w-3 h-3 animate-spin mr-1"}):e.jsx(Or,{className:"w-3 h-3 mr-1"})," Ingest"]})]})]}),e.jsxs("div",{className:"pt-3 border-t space-y-2",children:[e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Or add a web page URL"}),e.jsx($e,{placeholder:"Paste a public https:// web page link",value:pt,onChange:u=>{Mt(u.target.value),Ot&&Kt(null)},onKeyDown:u=>{u.key==="Enter"&&pt.trim()&&!be.isPending&&Ft()},className:"h-8 text-xs bg-background"}),e.jsx($e,{placeholder:"Name (optional â shown instead of the page title)",value:Xt,onChange:u=>Jt(u.target.value),onKeyDown:u=>{u.key==="Enter"&&pt.trim()&&!be.isPending&&Ft()},maxLength:300,className:"h-8 text-xs bg-background"}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"text-[10px] text-muted-foreground leading-tight",children:["Vera fetches the page and imports its readable text as a ",O.verified," source. Re-adding the same URL updates it."]}),e.jsxs(D,{size:"sm",className:"h-7 text-xs shrink-0",onClick:Ft,disabled:!pt.trim()||be.isPending,children:[be.isPending?e.jsx(re,{className:"w-3 h-3 animate-spin mr-1"}):e.jsx(Vt,{className:"w-3 h-3 mr-1"})," Add"]})]}),Ot&&e.jsxs("p",{className:"text-[10px] text-destructive leading-tight flex items-start gap-1",children:[e.jsx(Ue,{className:"w-3 h-3 mt-px shrink-0"})," ",Ot]})]}),M&&e.jsxs("div",{className:`pt-3 border-t space-y-2 transition-colors ${je==="drive"?"rounded-md border border-dashed p-2 -mx-1":""}`,style:je==="drive"?{borderColor:"var(--chat-accent-solid)",backgroundColor:"var(--chat-accent-bg)"}:void 0,onDragEnter:we("drive"),onDragOver:we("drive"),onDragLeave:at,onDrop:rt,children:[e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Or import from Google Drive"}),e.jsx($e,{placeholder:"Paste a Google Doc, Sheet, or Slides link",value:Ne,onChange:u=>$t(u.target.value),className:"h-8 text-xs bg-background"}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[10px] text-muted-foreground leading-tight",children:je==="drive"?"Drop to import from Google Drive.":fe==="personal"?`Imports through your connected Google Drive â Docs, Sheets, Slides, PDF, Word, Excel & PowerPoint import as ${O.verified} sources.`:`Docs, Sheets, Slides, PDF, Word, Excel & PowerPoint import as ${O.verified} sources â paste a link or drag one in.`}),e.jsxs(D,{size:"sm",className:"h-7 text-xs shrink-0",onClick:_t,disabled:!Ne.trim()||(fe==="personal"?N.isPending:G.isPending),children:[(fe==="personal"?N.isPending:G.isPending)?e.jsx(re,{className:"w-3 h-3 animate-spin mr-1"}):e.jsx(Vt,{className:"w-3 h-3 mr-1"})," Import"]})]})]}),_&&e.jsxs("div",{className:"pt-3 border-t space-y-2",children:[e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Or import from SharePoint"}),e.jsx($e,{placeholder:"Paste a SharePoint or OneDrive file link",value:St,onChange:u=>Et(u.target.value),className:"h-8 text-xs bg-background"}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"text-[10px] text-muted-foreground leading-tight",children:["PDF, Word, Excel, PowerPoint & plain-text files import as ",O.verified," sources."]}),e.jsxs(D,{size:"sm",className:"h-7 text-xs shrink-0",onClick:Ts,disabled:!St.trim()||ee.isPending,children:[ee.isPending?e.jsx(re,{className:"w-3 h-3 animate-spin mr-1"}):e.jsx(Vt,{className:"w-3 h-3 mr-1"})," Import"]})]})]}),F.length>0&&ft&&e.jsxs("div",{className:"pt-3 border-t space-y-2",children:[e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Or import from a connected app"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:F.map(u=>e.jsx(D,{type:"button",size:"sm",variant:ft===u.slug?"default":"outline",className:"h-6 text-[10px] px-2",onClick:()=>Rt(u.slug),children:u.name},u.slug))}),e.jsx($e,{placeholder:Fa[ft]?.placeholder??"Paste a link or ID",value:At,onChange:u=>mt(u.target.value),className:"h-8 text-xs bg-background"}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[10px] text-muted-foreground leading-tight",children:Fa[ft]?.hint??`Plain-text files import as ${O.verified} sources.`}),e.jsxs(D,{size:"sm",className:"h-7 text-xs shrink-0",onClick:ns,disabled:!At.trim()||N.isPending||I.isPending,children:[N.isPending||I.isPending?e.jsx(re,{className:"w-3 h-3 animate-spin mr-1"}):e.jsx(Vt,{className:"w-3 h-3 mr-1"})," Import"]})]})]}),oe.length>0&&xt&&e.jsxs("div",{className:"pt-3 border-t space-y-2",children:[e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Or import a whole folder"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:oe.map(u=>e.jsx(D,{type:"button",size:"sm",variant:xt===u.slug?"default":"outline",className:"h-6 text-[10px] px-2",onClick:()=>ze(u.slug),children:u.name},u.slug))}),e.jsx(It,{placeholder:_a[xt]?.placeholder??"Paste one or more folder links (one per line)",value:ht,onChange:u=>
13it(u.target.value),className:"min-h-[60px] text-xs resize-none bg-background"}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[10px] text-muted-foreground leading-tight",children:_a[xt]?.hint??`Every supported file in each folder imports as ${O.verified} sources.`}),e.jsxs(D,{size:"sm",className:"h-7 text-xs shrink-0",onClick:$s,disabled:!ht.trim()||ne.isPending,children:[ne.isPending?e.jsx(re,{className:"w-3 h-3 animate-spin mr-1"}):e.jsx(Vt,{className:"w-3 h-3 mr-1"})," Import"]})]})]})]})]})]}),e.jsx(qo,{open:Ds,onOpenChange:Zt,onImported:u=>{d.invalidateQueries({queryKey:Te()}),c({title:u.title,description:u.detail??void 0,variant:u.hasFailures?"destructive":void 0}),u.imported>0&&ie(!1)}})]})}function Js({tier:t,label:s,desc:n,icon:a,active:r}){const o=Go(t);return e.jsxs("div",{className:`rounded-lg p-2 transition-colors ${r?"bg-secondary":""}`,children:[e.jsxs("span",{className:`prov ${o} inline-flex items-center gap-1 text-[11px] font-medium leading-none`,children:[a,s]}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-snug mt-1.5",children:n})]})}function Zs(t){const s=Math.floor(t/1e3),n=Math.floor(s/3600),a=Math.floor(s%3600/60),r=s%60,o=String(a).padStart(n>0?2:1,"0"),l=String(r).padStart(2,"0");return n>0?`${n}:${o}:${l}`:`${o}:${l}`}function ym(t,s){try{const n=new URL(t);if(!n.hostname.includes("youtube.com")&&!n.hostname.includes("youtu.be"))return null;const a=Math.floor(s/1e3);return n.hostname.includes("youtu.be"),n.searchParams.set("t",String(a)),n.toString()}catch{return null}}function bm({src:t,active:s,onEnter:n,onLeave:a,onOpen:r,openLabel:o}){const l=t.tier==="verified",h=t.tier==="web",p=h?"kb-web":l?"kb-verified":"kb-platform",v=h?"bg-[#b91c1c]":l?"bg-[#4f46e5]":"bg-[#0f766e]",x=!!r,w=t.startOffsetMs!=null&&t.startOffsetMs>=0,d=t.sourceProvider==="youtube",c=w&&d&&t.url?ym(t.url,t.startOffsetMs):null;return e.jsx("div",{className:`kb-card ${p} rounded-lg border bg-background p-3${s?" is-active":""}${x?" cursor-pointer":""}`,role:x?"button":void 0,tabIndex:x?0:void 0,onMouseEnter:n,onMouseLeave:a,onFocus:n,onBlur:a,onClick:r,onKeyDown:x?g=>{(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),r?.())}:void 0,children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:`${v} text-white text-[10px] font-bold rounded w-[18px] h-[18px] flex items-center justify-center shrink-0 mt-0.5`,children:t.num}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-medium leading-snug line-clamp-2",title:t.title,children:t.title}),t.visibilityLabel&&e.jsx("p",{className:"text-[10px] mt-1 text-muted-foreground","data-testid":"source-visibility-label",children:t.visibilityLabel}),t.golden&&e.jsxs("span",{className:"inline-flex items-center gap-1 mt-1.5 text-[10px] font-medium text-chat-accent","data-testid":"source-golden",children:[e.jsx(Uo,{className:"w-3 h-3 shrink-0"})," Golden source"]}),t.confidenceNote&&e.jsx("p",{className:"text-[10px] mt-1 block text-muted-foreground","data-testid":"source-confidence-note",children:t.confidenceNote}),w&&(c?e.jsxs("a",{href:c,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 mt-1.5 text-[10px] font-medium text-primary hover:underline",onClick:g=>g.stopPropagation(),"aria-label":`Jump to ${Zs(t.startOffsetMs)} in video`,children:[e.jsx(wa,{className:"w-3 h-3 shrink-0"}),Zs(t.startOffsetMs)]}):e.jsxs("span",{className:"inline-flex items-center gap-1 mt-1.5 text-[10px] font-medium text-muted-foreground",children:[e.jsx(wa,{className:"w-3 h-3 shrink-0"}),Zs(t.startOffsetMs)]})),na(t)&&e.jsxs("span",{className:"inline-flex items-center gap-1 mt-1.5 text-[10px] font-medium text-muted-foreground","data-testid":"source-page",children:[e.jsx(sn,{className:"w-3 h-3 shrink-0"}),na(t)]}),t.statusLabel&&e.jsxs("p",{className:"text-[10px] mt-1.5 inline-flex items-start gap-1 text-chat-accent","data-testid":`source-status-${t.status}`,children:[e.jsx(Ue,{className:"w-3 h-3 shrink-0 mt-px"}),e.jsx("span",{className:"leading-snug",children:t.statusLabel})]}),(()=>{const g=zo(t);return g?e.jsx("p",{className:"text-[10px] mt-1 block text-muted-foreground","data-testid":"source-age-cue",children:g}):null})(),(()=>{const g=Uc(t.staleness);return g?e.jsxs("p",{className:"text-[10px] mt-1 inline-flex items-start gap-1 text-chat-accent",title:g.detail,"data-testid":"source-stale-cue",children:[e.jsx(Ue,{className:"w-3 h-3 shrink-0 mt-px"}),e.jsxs("span",{className:"leading-snug",children:[g.label,g.lastSeen?` â source copy last seen ${g.lastSeen}`:""]})]}):null})(),t.snippet&&e.jsxs("p",{className:"text-[11px] text-muted-foreground italic mt-1.5 line-clamp-3 border-l-2 border-border pl-2",children:['"',t.snippet,'"']}),t.sop&&e.jsxs("div",{onClick:g=>g.stopPropagation(),children:[e.jsx(Vo,{sop:t.sop,compact:!0}),e.jsx(Qo,{src:t})]}),e.jsx("div",{className:"mt-2 text-[10px] font-medium",children:h?x?e.jsxs("span",{className:"text-red-700 dark:text-red-400 inline-flex items-center gap-1",children:[e.jsx(Dt,{className:"w-3 h-3"})," ",o]}):e.jsx("span",{className:"text-muted-foreground",children:o}):l?x?e.jsxs("span",{className:"text-primary inline-flex items-center gap-1",children:[e.jsx(sn,{className:"w-3 h-3"})," ",o]}):e.jsx("span",{className:"text-muted-foreground",children:o}):e.jsxs("span",{className:"text-teal-700 dark:text-teal-300 inline-flex items-center gap-1",children:[e.jsx(Dt,{className:"w-3 h-3"})," ",o]})})]})]})})}function jm({scopeIds:t,onChange:s,saving:n,disabled:a}){const[r,o]=y.useState(!1),l=sc({query:{queryKey:nc()}}),h=l.data??[],p=t&&t.length>0?t:null,v=p?h.filter(g=>p.includes(g.id)):[],x=p&&!l.isLoading?p.length-v.length:0,w=!!p&&!l.isLoading&&v.length===0,d=p?w?"No sources":v.length===1?v[0].name:`${v[0]?.name??"Collections"} +${v.length-1+x}`:"All knowledge",c=(g,R)=>{const $=p??[],C=R?[...new Set([...$,g])]:$.filter(A=>A!==g);s(C.length>0?C:null)};return e.jsxs(dn,{open:r,onOpenChange:o,children:[e.jsx(un,{asChild:!0,children:e.jsxs(D,{variant:"ghost",size:"sm",disabled:a,className:`h-8 text-xs gap-1.5 max-w-56 ${p?"text-primary":"text-muted-foreground"}`,title:"What this chat's answers can draw on","aria-label":`Knowledge scope: ${d}`,"data-testid":"button-knowledge-scope",children:[n?e.jsx(re,{className:"w-3.5 h-3.5 animate-spin shrink-0"}):w?e.jsx(Ue,{className:"w-3.5 h-3.5 shrink-0 text-chat-accent"}):p?e.jsx(jd,{className:"w-3.5 h-3.5 shrink-0"}):e.jsx(aa,{className:"w-3.5 h-3.5 shrink-0"}),e.jsx("span",{className:"truncate","data-testid":"text-knowledge-scope-label",children:d})]})}),e.jsxs(mn,{align:"end",className:"w-72 p-3 space-y-2","data-testid":"popover-knowledge-scope",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:"Knowledge scope"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"What answers in this chat can draw on. Separated collections join only when picked here."})]}),e.jsxs("button",{type:"button",onClick:()=>{p&&s(null)},"aria-pressed":!p,className:`flex w-full items-start gap-2 rounded-md border px-2.5 py-2 text-left text-xs transition-colors ${p?"hover:bg-muted/60":"border-primary bg-primary/10"}`,"data-testid":"button-scope-default",children:[e.jsx(aa,{className:"w-3.5 h-3.5 shrink-0 mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium",children:"All knowledge"}),e.jsx("span",{className:"block text-muted-foreground",children:"The whole knowledge base, except separated collections."})]})]}),l.isLoading?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground py-1",children:[e.jsx(re,{className:"w-3.5 h-3.5 animate-spin"})," Loading collectionsâ¦"]}):h.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No collections exist yet â create them on the Knowledge Base page."}):e.jsx("div",{className:"space-y-1 max-h-56 overflow-y-auto",children:h.map(g=>{const R=!!p?.includes(g.id);return e.jsxs("label",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 text-xs hover:bg-muted/60 cursor-pointer","data-testid":`label-scope-collection-${g.id}`,children:[e.jsx(Bo,{checked:R,onCheckedChange:$=>c(g.id,$===!0),"aria-label":`Scope to ${g.name}`,"data-testid":`checkbox-scope-collection-${g.id}`}),e.jsx("span",{className:"truncate font-medium",children:g.name}),g.separated&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] text-muted-foreground shrink-0",children:[e.jsx(Rr,{className:"w-3 h-3"})," separated"]}),e.jsx("span",{className:"ml-auto text-[10px] text-muted-foreground tabular-nums shrink-0",children:g.documentCount})]},g.id)})}),x>0&&e.jsxs("p",{className:"flex items-start gap-1.5 text-[11px] text-chat-accent","data-testid":"text-scope-dead-warning",children:[e.jsx(Ue,{className:"w-3.5 h-3.5 shrink-0 mt-0.5"}),e.jsx("span",{children:w?"Every collection this chat was scoped to has been deleted, so answers draw on nothing. Pick a scope above.":`${x} collection${x===1?"":"s"} in this chat's scope no longer exist and are ignored.`})]}),p&&!w&&e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Answers draw ONLY on the checked collection",v.length+x===1?"":"s","."]})]})]})}const Ga={scope:"user"},wm=6;function Nm(t,s=wm){const n=[],a=t.map(()=>0);let r=!0;for(;n.length<s&&r;)r=!1,t.forEach((o,l)=>{if(n.length>=s)return;const h=o.examplePrompts[a[l]];h!=null&&(a[l]+=1,r=!0,n.push({app:o.name,text:h}))});return n}function km({onPrefill:t,className:s}){const{data:n}=ac(Ga,{query:{queryKey:rc(Ga),staleTime:3e5,refetchOnWindowFocus:!1}}),a=b.useMemo(()=>Nm(n?.apps??[]),[n]);return a.length===0?null:e.jsxs("article",{"aria-label":"Ask about your connected apps",className:s,"data-testid":"connector-prompt-chips",children:[e.jsxs("p",{className:"text-[11px] uppercase tracking-wider text-muted-foreground mb-1 inline-flex items-center gap-1",children:[e.jsx(Wo,{className:"w-3 h-3"})," Ask about your connected apps"]}),e.jsx("ul",{className:"flex flex-wrap gap-1.5",children:a.map(r=>e.jsx("li",{children:e.jsx("button",{type:"button",onClick:()=>t(r.text),title:r.app,className:"rounded-full border px-2.5 py-0.5 text-xs hover:bg-muted",children:r.text})},r.text))})]})}function Cm({me:t,onPrefill:s,className:n}){const a=wn(t,{tempMode:!1});return a.starterPrompts.length===0?null:e.jsxs("article",{"aria-label":a.starterLabel??"Try asking",className:n,"data-testid":"learning-starter-prompts",children:[e.jsxs("p",{className:"text-[11px] uppercase tracking-wider text-muted-foreground mb-1 inline-flex items-center gap-1",children:[e.jsx(Ho,{className:"w-3 h-3"})," ",a.starterLabel]}),e.jsx("ul",{className:"flex flex-wrap gap-1.5",children:a.starterPrompts.map(r=>e.jsx("li",{children:e.jsx("button",{type:"button",onClick:()=>s(r),className:"rounded-full border px-2.5 py-0.5 text-xs hover:bg-muted","data-testid":"learning-starter-prompt",children:r})},r))})]})}const Ba=t=>`vera:meeting-actions-dismissed:${t}`;function Sm({className:t,onNavigate:s}){const{data:n}=ic({status:"ready",limit:10,offset:0}),[a,r]=y.useState(0),o=n?.items.find(v=>{try{return sessionStorage.getItem(Ba(v.id))!=="1"}catch{return!0}});if(!o)return null;const h=o.items.find(v=>v.kind==="note")?.title||"Your recent meeting",p=()=>{try{sessionStorage.setItem(Ba(o.id),"1")}catch{}r(v=>v+1)};return e.jsxs("article",{className:wd("relative rounded-xl border border-primary/20 bg-primary/[0.04] p-4 pr-11",t),"aria-labelledby":`meeting-actions-${o.id}`,children:[e.jsx("button",{type:"button",onClick:p,"aria-label":`Dismiss actions for ${h}`,className:"absolute right-2 top-2 rounded-md p-1.5 text-muted-foreground hover:bg-accent hover:text-foreground",children:e.jsx(ut,{className:"h-4 w-4","aria-hidden":!0})}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"rounded-lg bg-primary/10 p-2 text-primary",children:e.jsx(Yo,{className:"h-5 w-5","aria-hidden":!0})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h2",{id:`meeting-actions-${o.id}`,className:"font-medium",children:"Meeting actions are ready"}),e.jsxs("p",{className:"mt-1 text-sm leading-5 text-muted-foreground",children:[h," has ",o.items.length," item",o.items.length===1?"":"s"," ready for your review. Nothing is applied until you accept it.",(o.insights?.length??0)>0&&e.jsxs(e.Fragment,{children:[" ",o.insights.filter(v=>v.status==="answered").length," question",o.insights.filter(v=>v.status==="answered").length===1?"":"s"," raised in the meeting answered from verified knowledge; ",o.insights.filter(v=>v.status!=="answered").length," unresolved."]})]}),e.jsxs(D,{size:"sm",variant:"outline",className:"mt-3",onClick:()=>s(`/meetings/actions/${o.id}`),children:["Review actions ",e.jsx(Ss,{className:"h-4 w-4","aria-hidden":!0})]})]})]})]})}const Pm=y.lazy(()=>Hi(()=>import("./aurora-voice-S2ydCitH.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29])).then(t=>({default:t.AuroraVoice})));function Wa(t,s){const n=new Map(s.map((r,o)=>[r,o])),a=r=>n.has(r)?n.get(r):Number.MAX_SAFE_INTEGER;return[...t].sort((r,o)=>a(r.id)-a(o.id))}const Gt="00000000-0000-0000-0000-000000000000";function kh(){const t=Ae(),{toast:s}=Be(),n=Xo(),{data:a}=Ps(),{data:r}=oc({query:{enabled:!!a?.tenantName,queryKey:$c()}}),o=mr(a),l=Jo(a),[,h]=Ha(),{openSettings:p}=Zo(),v=(a?.displayName||a?.username||"there").split(" ")[0],x=el(a),w=a?.displayName??a?.username??"You",[d,c]=y.useState(null),[g,R]=y.useState(!1),[$,C]=y.useState(null),[A,j]=y.useState(!1),[L,T]=y.useState(!1),{active:k}=tl();b.useEffect(()=>{k&&j(!1)},[k]);const[B,Z]=y.useState(!1),[U,W]=y.useState(!1),G=b.useRef(null),K=b.useRef(null),ee=b.useRef(null),N=b.useRef(null),{pendingUpload:I,setPendingUpload:H,isDragging:ne,dragKind:be,linkImportProgress:pe,kbUploadInputRef:xe,uploadingItems:De,openKbFilePicker:fe,queueUpload:M,ingestKbFiles:_,onDragEnter:F,onDragOver:oe,onDragLeave:me,onDrop:ie,mediaRightsDialog:he,importPreviewDialog:We,visibilityDialog:Ce}=em(a?.tenantId,{uploadScope:()=>N.current,door:"chat_drop",visibilityChoice:()=>tm(rt)}),[Ee,m]=y.useState(!1),ge=b.useMemo(()=>(I??[]).filter(xs),[I]),E=b.useMemo(()=>ge.filter(i=>!Xe(i)&&!ys(i)),[ge]),Y=b.useMemo(()=>E.length>0?{kind:"upload",label:E.length===1?E[0].name:`${E.length} files`,declaredBytes:E.reduce((i,f)=>i+f.size,0),itemCount:E.length,refs:E.map(i=>i.name)}:null,[E]),le=sl(Y,{forceAcceptance:ge.some(_c)}),[ce,je]=gm(),[z,nt]=y.useState(!1),[we,at]=y.useState([]),[rt,Ne]=nl({surface:"chat-composer",contextId:d??"new",userId:a?.id,enabled:!z}),[$t,St]=y.useState(null),Et=b.useRef(void 0),[Me,Rt]=y.useState(null),[At,mt]=y.useState(null),Lt=lc(),ze=b.useRef(0),[ht,it]=y.useState(null),[pt,Mt]=y.useState(null),[Xt,Jt]=y.useState({}),[Ot,Kt]=y.useState({}),[Ds,Zt]=y.useState({}),[xt,ft]=y.useState({}),[gt,es]=y.useState(null),ts=b.useCallback(i=>{if(i?.reasoning&&Jt(f=>({...f,[i.id]:i.reasoning})),i?.clarifyOptions&&i.clarifyOptions.length){const f=i.clarifyOptions;Kt(S=>({...S,[i.id]:f}))}if(i?.usedSkill){const f=i.usedSkill;Zt(S=>({...S,[i.id]:f}))}if(i?.usedSystemSkills&&i.usedSystemSkills.length){const f=i.usedSystemSkills;ft(S=>({...S,[i.id]:f}))}i?.skillOffer&&es(i.skillOffer)},[]),vt=Kd(a),[Is]=Md("m"),ss=Is&&vt,_t=b.useCallback(()=>{t.invalidateQueries({queryKey:cc()}),t.invalidateQueries({queryKey:dc()})},[t]),{actions:Ts,availabilityOf:ns,visibleActions:$s}=al(a),Ft=rl(),[u,P]=y.useState(!1),q=b.useMemo(()=>il(rt,{hasTenant:!!a?.tenantId}),[rt,a?.tenantId]);b.useEffect(()=>{P(!1)},[d,z]);const se=uc(d??"",{query:{enabled:!!d&&!z&&!!a?.tenantId&&!o,queryKey:xn(d??""),retry:!1,staleTime:6e4}}),de=z||!d?null:gt&>.conversationId===d?gt:se.data?.offer??null,ue=b.useCallback(i=>{es(i)},[]),ve=Xa({queryKey:[...Ke(),"infinite"],queryFn:({pageParam:i})=>Ec(i?{cursor:i}:void 0),initialPageParam:void 0,getNextPageParam:i=>i.nextCursor??void 0,enabled:!o}),te=b.useMemo(()=>ve.data?ve.data.pages.flatMap(i=>i.items):void 0,[ve.data]),ye=ve,Ie=ve.isLoading,ke=mc(),X=hc(),[ae,He]=y.useState(null),{data:as}=pc({query:{queryKey:Qs(),enabled:!o}}),{data:qt}=xc({query:{queryKey:Gs(),enabled:!o}}),Se=fc(),Oe=gc(),yt=vc(),bt=yc(),Es=bc(),ai=jc(),jt=b.useCallback(()=>{t.invalidateQueries({queryKey:Ke()}),t.invalidateQueries({queryKey:Qs()}),t.invalidateQueries({queryKey:Gs()}),t.inv
13alidateQueries({predicate:i=>{const f=i.queryKey?.[0];return typeof f=="string"&&f.startsWith("/api/chat-projects/")&&f.endsWith("/conversations")}})},[t]),ot=i=>f=>s({title:i,description:Le(f,kl),variant:"destructive"}),ri=(i,f)=>Se.mutate({id:i,data:{pinned:f}},{onSuccess:jt,onError:ot(f?"Failed to pin chat":"Failed to unpin chat")}),ii=(i,f)=>Oe.mutate({id:i,data:{projectId:f}},{onSuccess:jt,onError:ot(f?"Failed to add chat to project":"Failed to remove chat from project")}),oi=async(i,f)=>{try{const S=await bt.mutateAsync({data:{name:f}});await Oe.mutateAsync({id:i,data:{projectId:S.id}}),jt()}catch(S){ot("Failed to create project")(S)}},li=i=>bt.mutate({data:{name:i}},{onSuccess:jt,onError:ot("Failed to create project")}),ci=(i,f)=>Es.mutate({id:i,data:{name:f}},{onSuccess:jt,onError:ot("Failed to rename project")}),di=i=>ai.mutate({id:i},{onSuccess:jt,onError:ot("Failed to delete project")}),ui=wc(),mi=Nc(),hi=i=>{const f=Qs(),S=t.getQueryData(f);S&&t.setQueryData(f,{...S,items:Wa(S.items,i)}),ui.mutate({data:{ids:i}},{onSuccess:V=>t.setQueryData(f,V),onError:V=>{S&&t.setQueryData(f,S),ot("Failed to reorder pinned chats")(V)}})},pi=i=>{const f=Gs(),S=t.getQueryData(f);S&&t.setQueryData(f,Wa(S,i)),mi.mutate({data:{ids:i}},{onSuccess:V=>t.setQueryData(f,V),onError:V=>{S&&t.setQueryData(f,S),ot("Failed to reorder projects")(V)}})},kn=b.useMemo(()=>te?.filter(i=>!i.pinned&&!i.projectId),[te]),xi=b.useMemo(()=>(qt??[]).map(i=>({id:i.id,name:i.name})),[qt]),Cn=as?.items,Sn=b.useMemo(()=>te?.find(i=>i.id===d),[te,d]),{data:fi}=kc({query:{enabled:!!a?.tenantId,retry:!1,queryKey:Ac()}}),Pn=Cc(),gi=Sc(),[Rs,As]=y.useState(null),[Ve,rs]=y.useState(null),Dn=()=>Ve?{laneBusinessId:Ve.laneBusinessId,initiativeId:Ve.initiativeId}:{};{const i=d?Sn?.initiativeId??null:Ve?.initiativeId??null;N.current=i?{initiativeId:i}:null}const vi=b.useMemo(()=>{if(d){const i=te?.find(f=>f.id===d);return i?.modelChoiceProvider&&i?.modelChoiceModel?{providerSlug:i.modelChoiceProvider,modelId:i.modelChoiceModel}:null}return Rs},[d,te,Rs]),yi=i=>{if(!d){As(i);return}const f=V=>s({title:"Couldn't change the model",description:V?.data?.error??"Try again.",variant:"destructive"}),S=()=>t.invalidateQueries({queryKey:Ke()});i?Pn.mutate({id:d,data:i},{onSuccess:S,onError:f}):gi.mutate({id:d},{onSuccess:S,onError:f})},bi=i=>{const f=S=>yt.mutate({id:S,data:{collectionIds:i}},{onSuccess:()=>{t.invalidateQueries({queryKey:Ke()})},onError:V=>s({title:"Couldn't change the knowledge scope",description:V?.data?.error??"Try again.",variant:"destructive"})});if(d){f(d);return}ke.mutate({data:Dn()},{onSuccess:S=>{c(S.id),rs(null),t.invalidateQueries({queryKey:Ke()}),f(S.id)},onError:S=>s({title:"Couldn't change the knowledge scope",description:S?.data?.error??"Try again.",variant:"destructive"})})},{data:ji,isLoading:wi,isError:Ni}=Pc(d||"",{query:{enabled:!!d,queryKey:Bt(d||"")}}),is=Dc(),[In,Ls]=y.useState([]),[ki,Ci]=y.useState(0),os=z?we:ji,ls=z?Gt:d,cs=b.useMemo(()=>Me&&Me.convKey===ls?{id:Me.id,conversationId:Me.convKey??"",role:"user",content:Me.content,spans:null,links:null,createdAt:Me.createdAt}:null,[Me,ls]),Ye=b.useMemo(()=>[...os??[],...In,...cs?[cs]:[]],[os,In,cs]),{data:Tn}=Ic(d||"",{query:{enabled:!!d&&!z,queryKey:xa(d||"")}}),ds=b.useMemo(()=>{const i=(Tn?.sources??[]).map(ol),f=new Set(i.map(V=>V.id)),S=ll(Ye).filter(V=>!f.has(V.id));return[...i,...S].map((V,lt)=>({...V,num:lt+1}))},[Tn,Ye]),[wt,Ut]=y.useState(null),Ms=b.useMemo(()=>{const i=new Set(ds.map(f=>f.documentId).filter(f=>!!f));return wt&&i.add(wt.documentId),[...i]},[ds,wt]),$n=b.useMemo(()=>({ids:Ms.join(","),limit:100,facets:"none"}),[Ms]),Os=Tc($n,{query:{enabled:Ms.length>0,queryKey:Rc($n)}}),Si=Os.data,En=wt&&Si?.items.find(i=>i.id===wt.documentId)||null,us=cl({requested:!!wt,resolved:!!En,loading:Os.isLoading,errored:Os.isError}),Ks=b.useCallback((i,f)=>Ut({documentId:i,chunkIndex:f}),[]),[_s,Rn]=y.useState(null),Pi=b.useCallback((i,f)=>{!!d&&!z&&(os??[]).some(V=>V.id===i)?Rn({conversationId:d,messageId:i}):f.documentId&&Ut({documentId:f.documentId,chunkIndex:f.chunkIndex})},[d,z,os]);b.useEffect(()=>{C(null),Ls([])},[d]),b.useEffect(()=>{const i=window.matchMedia("(min-width: 768px)"),f=()=>i.matches&&T(!1);return i.addEventListener("change",f),()=>i.removeEventListener("change",f)},[]),b.useEffect(()=>{const i=window.matchMedia("(min-width: 1280px)"),f=()=>i.matches&&Z(!1);return i.addEventListener("change",f),()=>i.removeEventListener("change",f)},[]);const ms=()=>{nt(!1),at([]),C(null),Ls([])},An=()=>{ms(),c(null),As(null),Qe()},Ln=i=>{ms(),c(i)},Re=Yi();b.useEffect(()=>{const i=new URLSearchParams(Re).get("c");i&&(ms(),c(i),h("/",{replace:!0}))},[Re]),b.useEffect(()=>{const i=new URLSearchParams(Re),f=i.get("initiative"),S=i.get("lane");!f||!S||(ms(),c(null),rs({laneBusinessId:S,laneName:i.get("laneName")??"Lane",initiativeId:f,initiativeName:i.get("name")??"Initiative"}),h("/",{replace:!0}))},[Re]),b.useEffect(()=>{new URLSearchParams(Re).has(dl)&&h("/",{replace:!0})},[Re]),b.useEffect(()=>{new URLSearchParams(Re).get("interview")&&(Ne(f=>f.trim()?f:"Interview me so you can get to know me and personalize your answers."),Qe(),h("/",{replace:!0}))},[Re]);const hs=b.useRef(null);b.useEffect(()=>{const i=new URLSearchParams(Re),f=i.get("prompt");if(f==null)return;const S=f.trim().slice(0,2e3);S&&(Ne(V=>V.trim()?V:S),Qe(),i.get("ask")==="1"&&(hs.current=S)),h("/",{replace:!0})},[Re]),b.useEffect(()=>{if(!a||!hs.current)return;const i=hs.current;if(hs.current=null,a.demoWorkspace!==!0)return;let f=null;try{f=window.sessionStorage}catch{}Ld(i,f)&&(Ne(""),Us(i))},[a,Re]);const Di=i=>{He(i);const f=()=>{jt(),Cl(a?.id,"chat-composer",i),d===i&&c(null)};X.mutate({id:i},{onSuccess:f,onError:S=>{const V=Nl(S);if(V.kind==="already_gone"){f();return}s({title:"Failed to delete chat",description:V.message,variant:"destructive"})},onSettled:()=>He(null)})},[Fs,Mn]=y.useState(null),On=i=>({activeConvId:d,onSelect:i,onDelete:Di,deletingConvId:ae,onShare:a?.impersonation?.active?void 0:(f,S)=>Mn({id:f,title:S}),onSetPinned:ri,onSetProject:ii,onCreateProjectAndAssign:oi,onCreateProject:li,onRenameProject:ci,onDeleteProject:di,projects:xi,onReorderPinned:hi,onReorderProjects:pi}),Kn=()=>{C(null),at([]),nt(i=>!i)},Qe=()=>window.setTimeout(()=>ee.current?.focus({preventScroll:!0}),50),{voiceCaps:ps,ttsPlayback:Ii,ttsLoadingId:Ti,voicePrefs:_n,setVoice:$i,setEngine:Ei,voiceModeOpen:Ri,setVoiceModeOpen:Ai,voiceEverOpened:Li,voiceConfigOpen:Mi,setVoiceConfigOpen:Oi,notifyVoiceConfig:Fn,handlePlay:Ki,sendTurnForVoice:_i,openVoiceMode:qs,openVoiceInterview:Fi,mintSession:qi,handleLiveTurn:Ui}
13=am({me:a,activeConvId:d,setActiveConvId:c,tempMode:z,setTempMessages:at,setLiveMessages:Ls,createConv:ke,sendMessage:is,bumpSavings:_t,rememberReasoning:ts});b.useEffect(()=>{new URLSearchParams(Re).get("voiceInterview")&&a&&(a.tenantId&&ps===void 0||(h("/",{replace:!0}),ps?.realtime?Fi():(Ne(i=>i.trim()?i:"Interview me so you can get to know me and personalize your answers."),Qe())))},[Re,a,ps]);const qn=()=>{Qe()};ul({askKb:qn,uploadFiles:fe,voiceMode:qs});const zi=i=>{if(wl(i)){a&&Ft(i.replace(/^guide-/,""),a);return}const f=Ts.find(V=>V.id===i),S=f?ns(f):void 0;if(S?.kind==="activate"||S?.kind==="needs-admin"){p("account",{connectorSlug:S.slug});return}if(S?.kind==="connect-capability"){h("/capabilities");return}switch(i){case"ask-kb":qn();return;case"voice-mode":qs();return;default:{if(f?.navTo){h(f.navTo);return}s({title:f?.label??"Coming soon",description:f?.seamNote??"This isnât wired yet."})}}},Vi=i=>{Ne(i.text),Qe()},Un=()=>Us(rt),Us=i=>{const f=i.trim();if(!f)return;const S=g;R(!1),ml("chat_message_sent",{max_quality:S});const V=++ze.current,lt=Q=>{Rt({id:`__pending_${Date.now()}`,convKey:Q,content:f,createdAt:new Date().toISOString()});const J=Ud(Et.current);Et.current=J,St(J),mt(null),Ci(Pe=>Pe+1),vt&&Lt.mutateAsync({data:{content:f,maxQuality:S}}).then(Pe=>{ze.current===V&&mt(Pe)}).catch(()=>{})},Nt=()=>{ze.current===V&&(Rt(null),St(null),mt(null),it(null),Mt(null))},zt=(Q,J)=>{n.handleError(Q)||s({title:J,description:Q?.data?.error,variant:"destructive"}),Ne(f),R(S)},zn=Q=>{fr(Q,s),gr(Q,s)},Vn=Q=>{at(J=>[...J,Q.userMessage,Q.assistantMessage]),Nt(),_t(),zn(Q.assistantMessage)},Qn=(Q,J)=>{ts(J.assistantMessage),t.setQueryData(Bt(Q),Pe=>[...Pe??[],J.userMessage,J.assistantMessage]),Nt(),t.invalidateQueries({queryKey:Bt(Q)}),t.invalidateQueries({queryKey:xa(Q)}),t.invalidateQueries({queryKey:Ke()}),_t(),zn(J.assistantMessage)},Gn=Q=>({onStage:J=>{ze.current===V&&Mt(J)},onDelta:J=>{ze.current===V&&it(Pe=>Pe&&Pe.convKey===Q?{convKey:Q,text:Pe.text+J}:{convKey:Q,text:J})},onReset:()=>{ze.current===V&&it(null)},onTitle:()=>{t.invalidateQueries({queryKey:Ke()})}}),Gi=()=>{is.mutate({id:Gt,data:{content:f,maxQuality:S}},{onSuccess:Q=>Vn(Q),onError:Q=>{zt(Q,"Failed to send message"),Nt()}})},Bi=Q=>{is.mutate({id:Q,data:{content:f,maxQuality:S}},{onSuccess:J=>Qn(Q,J),onError:J=>{zt(J,"Failed to send message"),Nt()}})},Wi=()=>{oa({conversationId:Gt,content:f,maxQuality:S,events:Gn(Gt)}).then(Vn).catch(Q=>{if(Q instanceof la){zt(Q,"Failed to send message"),Nt();return}ze.current===V&&it(null),Gi()})},Bn=Q=>{oa({conversationId:Q,content:f,maxQuality:S,events:Gn(Q)}).then(J=>Qn(Q,J)).catch(J=>{if(J instanceof la){zt(J,"Failed to send message"),Nt();return}ze.current===V&&it(null),Bi(Q)})};if(z){Ne(""),lt(Gt),Wi();return}if(!d){Ne(""),lt(null);const Q=Rs;ke.mutate({data:Dn()},{onSuccess:async J=>{if(c(J.id),As(null),rs(null),Rt(Pe=>Pe&&Pe.convKey===null?{...Pe,convKey:J.id}:Pe),Q)try{await Pn.mutateAsync({id:J.id,data:Q})}catch(Pe){s({title:"Couldn't apply your model pick",description:Pe?.data?.error??"This chat will use automatic routing.",variant:"destructive"})}t.invalidateQueries({queryKey:Ke()}),Bn(J.id)},onError:J=>{zt(J,"Failed to start chat"),Nt()}});return}Ne(""),lt(d),Bn(d)},Qi=i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),Un())};return e.jsxs("div",{className:"flex h-full min-h-0 w-full overflow-clip foundation-bg",children:[a&&e.jsx(ra,{me:a,collapsed:A,onToggleCollapse:()=>j(i=>!i),onNewChat:An,creating:ke.isPending,rootClassName:"hidden md:flex",children:e.jsx(Da,{collapsed:A,conversations:kn,pinnedConversations:Cn,railHandlers:On(Ln),loadingConvs:Ie,previewing:o,hasMore:!!ye.hasNextPage,loadingMore:ye.isFetchingNextPage,onLoadMore:()=>ye.fetchNextPage()})}),e.jsxs("div",{role:"main",id:"main-content",tabIndex:-1,className:"flex-1 flex flex-col min-w-0 min-h-0 relative overflow-clip glass-panel outline-none",onDragEnter:F,onDragOver:oe,onDragLeave:me,onDrop:ie,children:[ne&&a?.tenantId&&e.jsxs("div",{className:"absolute inset-2 z-40 flex flex-col items-center justify-center rounded-xl border-2 border-dashed bg-background/85 backdrop-blur-sm pointer-events-none",style:{borderColor:"var(--chat-accent-solid)"},children:[e.jsx(Or,{className:"w-10 h-10 mb-3",style:{color:"var(--chat-accent-solid)"}}),e.jsx("p",{className:"font-medium text-foreground text-center px-6",children:"Drop files or Google Drive links to add them to your Knowledge Base"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 text-center px-6",children:be==="links"?"Google Docs, Sheets, Slides & Drive files · SharePoint and OneDrive links · web pages":"PDF, Word, PowerPoint, .txt & .md · added to your knowledge base"})]}),pe&&e.jsx("div",{className:"absolute inset-x-0 top-16 z-40 flex justify-center pointer-events-none",children:e.jsxs("div",{className:"flex items-center gap-2 rounded-full border bg-background/95 px-3 py-1.5 shadow-sm backdrop-blur-sm",children:[e.jsx(re,{className:"w-3.5 h-3.5 animate-spin",style:{color:"var(--chat-accent-solid)"}}),e.jsx("span",{className:"text-xs text-muted-foreground",children:pe.total===1?"Importing dropped linkâ¦":`Importing dropped links⦠${pe.done} of ${pe.total}`})]})}),e.jsxs("header",{className:"h-14 border-b border-border/60 flex items-center justify-between gap-2 px-4 lg:px-6 bg-transparent shrink-0 z-10",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(D,{ref:G,variant:"ghost",size:"icon",className:"h-9 w-9 shrink-0 -ml-1 text-muted-foreground md:hidden",onClick:()=>T(!0),"aria-label":"Open conversations",children:e.jsx(Nd,{className:"w-5 h-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"font-semibold text-lg truncate",children:z?"Temporary chat":te?.find(i=>i.id===d)?.title||"New chat"}),!z&&(()=>{const i=te?.find(f=>f.id===d);return d?i?.laneName?e.jsx(ia,{laneName:i.laneName,initiativeName:i.initiativeName,testId:"chat-scope-chip"}):null:e.jsxs("div",{className:"flex items-center gap-1.5","data-testid":"chat-scope-picker-row",children:[Ve&&e.jsx(ia,{laneName:Ve.laneName,initiativeName:Ve.initiativeName,testId:"chat-scope-chip"}),e.jsx(hl,{currentLaneId:Ve?.laneBusinessId??null,currentInitiativeId:Ve?.initiativeId??null,onPick:rs,triggerTestId:"chat-scope-picker",ariaLabel:"Scope this new chat to a business lane or initiative",align:"start",trigger:e.jsx("button",{type:"button",className:"text-[11px] text-muted-foreground hover:text-foreground underline-offset-2 hover:underline","data-testid":"chat-scope-picker",children:Ve?"Change scope":"Scope to a lane or initiative"})})]})})()]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[a?.tenantId&&e.jsxs(D,{ref:K,variant:"ghost",size:"sm",className:"text-xs h-8 text-muted-foreground xl:hidden",onClick:()=>Z(!0),"aria-label":"Show sources and provenance",children:[e.jsx(Je,{className:"w-4 h-4 sm:mr-1.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Sources"})]}),a?.tenantId&&!z&&e.jsx(jm,{scopeIds:Sn?.knowledgeScopeCollectionIds??null,onChange:bi,saving:yt.isPending||!d&&ke.isPending}),e.jsxs(_e,{children:[e.jsx(Fe,{asChild:!0,children:e.jsxs(D,{variant:z?"secondary":"ghost",size:"sm",className:`text-xs h-8 ${z?"text-foreground":"text-muted-foreground"}`,onClick:Kn,"aria-pressed":z,"aria-label":z?"Turn off temporary chat":"Start a temporary chat",children:[e.jsx(_r,{className:"w-4 h-4 sm:mr-1.5"}),e.jsx("span",{className:"hidden sm:inline",children:z?"Temporary: on":"Temporary"})]})}),e.jsx(qe,{side:"bottom",children:e.jsx("p",{className:"text-xs",children:"Temporary chat â not saved to history or training"})})]}),e.jsxs(dn,{children:[e.jsx(un,{asChild:!0,children:e.jsxs(D,{variant:"ghost",size:"sm",className:"text-xs h-8 text-muted-foreground hidden sm:flex",children:[e.jsx(Ar,{className:"w-4 h-4 mr-1.5"}),"How Vera answers"]})}),e.jsxs(mn,{className:"w-72 text-sm p-4",align:"end",children:[e.jsxs("h4",{className:"font-semibold mb-3 flex items-center gap-2",children:[e.jsx(Je,{className:"w-4 h-4 text-primary"})," Provenance Legend"]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"prov prov-verified w-max text-xs",children:O.verifiedSource}),e.jsx("span",{className:"text-muted-foreground text-xs",children:"Your cited Verified Sources and documents."})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"prov prov-platform w-max text-xs",children:"Platform Knowledge"}),e.jsx("span",{className:"text-muted-foreground text-xs",children:"Answered from your platform workspace."})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"prov prov-ai w-max text-xs",children:"AI-Reasoning"}),e.jsx("span",{className:"text-muted-foreground text-xs",children:"Model reasoning â not tied to a source. Verify before relying."})]})]})]})]})]})]}),z&&e.jsx(Xd,{onClose:Kn}),o?e.jsx(zr,{}):!z&&d&&Ni?e.jsx("div",{className:"flex flex-1 items-center justify-center p-6",children:e.jsxs("div",{className:"max-w-sm rounded-lg border bg-card p-6 text-center shadow-sm",children:[e.jsx("p",{className:"text-sm font-medium",children:"This conversation is no longer available"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"It may have been deleted, or the link you followed is out of date."}),e.jsx(D,{size:"sm",className:"mt-4",onClick:()=>{c(null),Qe()},children:"Start a new chat"})]})}):e.jsx(ku,{loadingMessages:wi&&!cs,tempMode:z,renderedMessages:Ye,firstName:v,me:a,userLabel:w,userInitials:x,activeSource:$,setActiveSource:C,onOpenDocument:Ks,onOpenClaims:Pi,reasoningById:Xt,clarifyById:Ot,onPickClarifyOption:Us,usedSkillById:Ds,usedSystemSkillsById:xt,skillOffer:de,onSkillOfferDecided:ue,onOpenSkills:()=>p("skills"),showModelDebug:ss,ttsLoadingId:Ti,ttsPlayback:Ii,onPlay:Ki,onNavigate:h,thinking:$t,waitExpectation:Fd(At,vt),streamingText:ht&&ht.convKey===ls?ht.text:null,streamStage:pt,canSeeModel:vt,transcriptKey:ls??"__new",sendSignal:ki,feedbackConversationId:z?null:d,worldResources:r?.externalResources??null}),Ye.some(i=>i.role==="assistant"&&(i.spans?.length??0)>0)&&e.jsx("div",{className:"shrink-0 px-4 lg:px-6 pb-1",children:e.jsx("div",{className:"max-w-3xl mx-auto",children:e.jsx(pl,{swatches:!0,trademark:!0})})}),!o&&e.jsx($u,{}),e.jsx("div",{className:"shrink-0 px-4 lg:px-6",children:e.jsxs("div",{className:"max-w-3xl mx-auto
13space-y-1.5",children:[!d&&!z&&Ye.length===0&&e.jsx(Ru,{className:"pb-1",onPrefill:i=>{Ne(f=>f.trim()?f:i),Qe()},onNavigate:i=>h(i)}),!d&&!z&&Ye.length===0&&e.jsx(Ou,{className:"pb-1",onNavigate:i=>h(i)}),!d&&!z&&Ye.length===0&&e.jsx(Sm,{className:"mb-1",onNavigate:i=>h(i)}),!d&&!z&&Ye.length===0&&e.jsx(Cm,{me:a,className:"pb-1",onPrefill:i=>{Ne(f=>f.trim()?f:i),Qe()}}),!d&&!z&&Ye.length===0&&e.jsx(km,{className:"pb-1",onPrefill:i=>{Ne(f=>f.trim()?f:i),Qe()}}),e.jsx(xd,{className:"pb-1"}),e.jsx(fd,{surface:"chat",className:"pb-1"})]})}),a&&Ra(a)&&e.jsx(Tu,{me:a}),!o&&!Ra(a)&&e.jsx(Pu,{kbUploadInputRef:xe,onQueueUpload:M,uploadingItems:De,tempMode:z,me:a,activeConvId:d,coachDismissed:u,setCoachDismissed:P,queryRefinements:q,onApplyRefinement:Vi,composerRef:ee,composerText:rt,setComposerText:Ne,onKeyDown:Qi,sendPending:is.isPending,creating:ke.isPending,onOpenKbFilePicker:fe,onNeedsVoiceConfig:Fn,maxQuality:g,setMaxQuality:R,modelChoices:fi,modelChoice:vi,onModelChoiceChange:yi,onOpenVoiceMode:qs,onSend:Un})]}),a?.tenantId&&e.jsx(vm,{sources:ds,activeSource:$,setActiveSource:C,uploadOpen:Ee,onUploadOpenChange:m,collapsed:ce,onCollapsedChange:je,onOpenDocument:Ks}),e.jsx(nd,{open:!!_s,onOpenChange:i=>{i||Rn(null)},source:_s?{kind:"fetch",..._s}:null,onOpenInKnowledge:i=>Ut({documentId:i.documentId,chunkIndex:null})}),e.jsx(zc,{doc:En,passageIndex:wt?.chunkIndex??null,onOpenChange:i=>{i||Ut(null)},onRetryUpload:()=>m(!0)}),(us.kind==="loading"||us.kind==="dead")&&e.jsx(Ze,{open:!0,onOpenChange:i=>{i||Ut(null)},children:e.jsx(et,{className:"max-w-md","data-testid":"dialog-citation-unresolved",children:e.jsxs(tt,{children:[e.jsx(st,{className:"flex items-center gap-2",children:us.kind==="loading"?e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"w-4 h-4 animate-spin"})," Opening the cited source"]}):"This source can't be opened"}),e.jsx(dt,{"data-testid":"text-citation-unresolved-reason",children:us.message})]})})}),e.jsx(fa,{open:L,onOpenChange:T,children:e.jsxs(ga,{side:"left",className:"w-[300px] p-0 gap-0 flex flex-col md:hidden",onCloseAutoFocus:i=>{i.preventDefault(),G.current?.focus()},children:[e.jsxs(va,{className:"sr-only",children:[e.jsx(ya,{children:"Conversations"}),e.jsx(ba,{children:"Switch between conversations or start a new chat."})]}),a&&e.jsx(ra,{me:a,collapsed:!1,onNewChat:()=>{An(),T(!1)},creating:ke.isPending,fill:!0,children:e.jsx(Da,{collapsed:!1,conversations:kn,pinnedConversations:Cn,railHandlers:On(i=>{Ln(i),T(!1)}),loadingConvs:Ie,previewing:o,hasMore:!!ye.hasNextPage,loadingMore:ye.isFetchingNextPage,onLoadMore:()=>ye.fetchNextPage()})})]})}),a?.tenantId&&e.jsx(fa,{open:B,onOpenChange:Z,children:e.jsxs(ga,{side:"bottom",className:"h-[85dvh] max-h-[100dvh] p-0 gap-0 flex flex-col xl:hidden pb-[env(safe-area-inset-bottom)]",onCloseAutoFocus:i=>{i.preventDefault(),K.current?.focus()},children:[e.jsxs(va,{className:"sr-only",children:[e.jsx(ya,{children:"Sources & Provenance"}),e.jsx(ba,{children:"The provenance legend, the sources behind the current answer, and your workspace documents."})]}),e.jsxs("div",{className:"border-b shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>W(i=>!i),"aria-expanded":U,className:"flex w-full items-center gap-2 px-4 py-3 text-sm font-semibold",children:[e.jsx(xl,{className:"w-4 h-4 text-primary"})," Actions",e.jsx(ct,{className:`ml-auto w-4 h-4 text-muted-foreground transition-transform ${U?"rotate-180":""}`})]}),U&&e.jsx(fl,{groups:gl($s),onSelect:i=>{Z(!1),zi(i)},availabilityOf:ns})]}),e.jsx(ni,{sheet:!0,sources:ds,activeSource:$,setActiveSource:C,uploadOpen:Ee,onUploadOpenChange:m,onOpenDocument:Ks})]})}),Li&&e.jsx(y.Suspense,{fallback:null,children:e.jsx(Pm,{open:Ri,onClose:()=>Ai(!1),accent:"var(--chat-accent-solid)",voice:_n.voice,onChangeVoice:$i,conversationId:z?null:d,sendTurn:_i,realtimeAvailable:!!ps?.realtime,mintSession:qi,onLiveTurn:Ui,onNeedsConfig:Fn,defaultEngine:_n.lastEngine,onEngineChosen:Ei,resolveNavTarget:i=>a?om([...vl(a,l),...yl(a,l),...bl(a,l),...jl(a,l)],i):null})}),e.jsx(qd,{open:Mi,onOpenChange:Oi,isAdmin:a?.roles?.includes("tenant_admin")??!1}),he,We,Ce,e.jsx(Ze,{open:!!I,onOpenChange:i=>{i||H(null)},children:e.jsxs(et,{className:"sm:max-w-md",children:[e.jsxs(tt,{children:[e.jsx(st,{children:"Add to Knowledge Base"}),e.jsxs(dt,{children:["Documents are added to your workspace knowledge base, where their claims are extracted and indexed for ",O.backed," answers."]})]}),I&&(()=>{const i=I.filter(xs),f=I.filter(S=>!xs(S));return e.jsxs("div",{className:"space-y-4",children:[e.jsx("ul",{className:"max-h-40 overflow-y-auto space-y-1 rounded-md border bg-secondary/30 p-2",children:I.map((S,V)=>{const lt=!xs(S);return e.jsxs("li",{className:"flex items-center justify-between gap-3 text-xs",children:[e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx(sn,{className:"w-3.5 h-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"truncate",children:S.name})]}),e.jsxs("span",{className:`shrink-0 tabular-nums ${lt?"text-destructive font-medium":"text-muted-foreground"}`,children:[Bs(S.size),lt?` · over ${Ws(S)}`:""]})]},V)})}),f.length>0&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 p-2.5 text-xs text-destructive",children:[e.jsx(Ue,{className:"w-4 h-4 shrink-0 mt-0.5"}),e.jsx("span",{children:f.length===1?`That file is ${Bs(f[0].size)} â over the ${Ws(f[0])} limit for that type, so it wonât be uploaded.`:`${f.length} files are over the limit for their type and wonât be uploaded: ${f.map(S=>`${S.name} (${Bs(S.size)}, max ${Ws(S)})`).join(", ")}.`})]}),i.length>0&&le.panel,e.jsx(Qc,{}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["PDF, Word, PowerPoint, .txt, .md · ",fn," max"]}),e.jsxs("div",{className:"flex gap-2 ml-auto",children:[e.jsx(D,{variant:"ghost",size:"sm",className:"h-8 text-xs",onClick:()=>H(null),children:"Cancel"}),e.jsxs(D,{size:"sm",className:"h-8 text-xs",style:{backgroundColor:"var(--chat-accent-bg)",color:"var(--chat-accent-fg)"},disabled:i.length===0||!le.canProceed,onClick:()=>{const S=i,V=le.estimateId;(async()=>await le.confirm()&&(H(null),await _(S,V)))()},children:[e.jsx(Mr,{className:"w-3.5 h-3.5 mr-1.5"}),"Add ",i.length>0?`${i.length} `:"","document",i.length===1?"":"s"]})]})]})]})})()]})}),e.jsx(Su,{conversationId:Fs?.id??null,conversationTitle:Fs?.title,open:!!Fs,onOpenChange:i=>!i&&Mn(null)})]})}export{kh 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.