vendor: 8,884 bytes, lines 1-31
1import{c as he,r as a,bA as Vt,j as e,cL as Wt,cM as Xt,bk as Jt,bp as ye,cN as dt,cO as Zt,cP as es,cQ as ts,cR as ss,br as ns,cS as as,cT as rs,cU as os,cV as is,cW as cs,cX as ls,cY as ds,cZ as ms,c_ as us,$ as L,aq as hs,n as xs,bQ as ps,u as ke,b as mt,aQ as ut,an as Xe,ao as me,B as _,q as Je,i as fs,I as Oe,aA as gs,c1 as ht,D as be,z as Ne,F as Ce,G as _e,a4 as Me,x as Fe,y as ue,R as De,ab as ys,ae as vs,af as ws,ag as js,ah as bs,aE as Ns,J as Ve,ai as Cs,aj as _s,ak as Ms,c9 as xt,cp as Ss,cq as ks,cr as Is,cs as ze,c$ as Rs,s as R,V as p,Q as Ts,bY as at,S as Es,b4 as Ae,d as Ps,av as Os,aw as As,a$ as He,b0 as Qe,b1 as Ge,h as Ds,cI as qs,a8 as Ls,ba as Ks,c4 as Fs}from"./index-6Cb8ZntX.js";import{B as Se,u as zs,a as Hs,b as Qs,c as Gs,C as rt,d as $s,e as Bs}from"./ChatMessageList-CUqn27ek.js";import{u as ve}from"./useMutation-BYbzxuG8.js";import{f as Us}from"./formatDistanceToNow-BVWz0Vo_.js";import{C as Ys}from"./code-xml-Im62CeeZ.js";import"./file-text-ZKhXXF0Q.js";import"./square-CJsD6J3g.js";import"./endOfDay-3fqMHIi-.js";import"./en-US-_pJbXdef.js";import"./endOfMonth-CvoUCuXv.js";/** 2 * @license lucide-react v0.468.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const Vs=he("Ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]]);/** 7 * @license lucide-react v0.468.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const Ws=he("PanelLeftOpen",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"m14 9 3 3-3 3",key:"8010ee"}]]);/** 12 * @license lucide-react v0.468.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const $e=he("PanelLeft",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]]);/** 17 * @license lucide-react v0.468.0 - ISC 18 * 19 * This source code is licensed under the ISC license. 20 * See the LICENSE file in the root directory of this source tree. 21 */const Xs=he("PenLine",[["path",{d:"M12 20h9",key:"t2du7b"}],["path",{d:"M16.376 3.622a1 1 0 0 1 3.002 3.002L7.368 18.635a2 2 0 0 1-.855.506l-2.872.838a.5.5 0 0 1-.62-.62l.838-2.872a2 2 0 0 1 .506-.854z",key:"1ykcvy"}]]);/** 22 * @license lucide-react v0.468.0 - ISC 23 * 24 * This source code is licensed under the ISC license. 25 * See the LICENSE file in the root directory of this source tree. 26 */const Be=he("PinOff",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89",key:"znwnzq"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11",key:"c9qhm2"}]]);/** 27 * @license lucide-react v0.468.0 - ISC 28 * 29 * This source code is licensed under the ISC license. 30 * See the LICENSE file in the root directory of this source tree. 31 */const we=he("Pin",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]);var Ze="ContextMenu",[Js]=ns(Ze,[dt]),D=dt(),[Zs,pt]=Js(Ze),ft=t=>{const{__scopeContextMenu:s,children:n,onOpenChange:o,dir:l,modal:h=!0}=t,[g,x]=a.useState(!1),d=D(s),w=Vt(o),c=a.useCallback(y=>{x(y),w(y)},[w]);return e.jsx(Zs,{scope:s,open:g,onOpenChange:c,modal:h,children:e.jsx(Wt,{...d,dir:l,open:g,onOpenChange:c,modal:h,children:n})})};ft.displayName=Ze;var gt="ContextMenuTrigger",yt=a.forwardRef((t,s)=>{const{__scopeContextMenu:n,disabled:o=!1,...l}=t,h=pt(gt,n),g=D(n),x=a.useRef({x:0,y:0}),d=a.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...x.current})}),w=a.useRef(0),c=a.useCallback(()=>window.clearTimeout(w.current),[]),y=P=>{x.current={x:P.clientX,y:P.clientY},h.onOpenChange(!0)};return a.useEffect(()=>c,[c]),a.useEffect(()=>void(o&&c()),[o,c]),e.jsxs(e.Fragment,{children:[e.jsx(Xt,{...g,virtualRef:d}),e.jsx(Jt.span,{"data-state":h.open?"open":"closed","data-disabled":o?"":void 0,...l,ref:s,style:{WebkitTouchCallout:"none",...t.style},onContextMenu:o?t.onContextMenu:ye(t.onContextMenu,P=>{c(),y(P),P.preventDefault()}),onPointerDown:o?t.onPointerDown:ye(t.onPointerDown,Te(P=>{c(),w.current=window.setTimeout(()=>y(P),700)})),onPointerMove:o?t.onPointerMove:ye(t.onPointerMove,Te(c)),onPointerCancel:o?t.onPointerCancel:ye(t.onPointerCancel,Te(c)),onPointerUp:o?t.onPointerUp:ye(t.onPointerUp,Te(c))})]})});yt.displayName=gt;var en="ContextMenuPortal",vt=t=>{const{__scopeContextMenu:s,...n}=t,o=D(s);return e.jsx(Zt,{...o,...n})};vt.displayName=en;var wt="ContextMenuContent",jt=a.forwardRef((t,s)=>{const{__scopeContextMenu:n,...o}=t,l=pt(wt,n),h=D(n),g=a.useRef(!1);return e.jsx(es,{...h,...o,ref:s,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:x=>{var d;(d=t.onCloseAutoFocus)==null||d.call(t,x),!x.defaultPrevented&&g.current&&x.preventDefault(),g.current=!1},onInteractOutside:x=>{var d;(d=t.onInteractOutside)==null||d.call(t,x),!x.defaultPrevented&&!l.modal&&(g.current=!0)},style:{...t.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});jt.displayName=wt;var tn="ContextMenuGroup",sn=a.forwardRef((t,s)=>{const{__scopeContextMenu:n,...o}=t,l=D(n);return e.jsx(as,{...l,...o,ref:s})});sn.displayName=tn;var nn="ContextMenuLabel",bt=a.forwardRef((t,s)=>{const{__scopeContextMenu:n,...o}=t,l=D(n);return e.jsx(rs,{...l,...o,ref:s})});bt.displayName=nn;var an="ContextMenuItem",Nt=a.forwardRef((t,s)=>{const{__scopeContextMenu:n,...o}=t,l=D(n);return e.jsx(ts,{...l,...o,ref:s})});Nt.displayName=an;var rn="ContextMenuCheckboxItem",Ct=a.forwardRef((t,s)=>{const{__scopeContextMenu:n,...o}=t,l=D(n);return e.jsx(os,{...l,...o,ref:s})});Ct.displayName=rn;var on="ContextMenuRadioGroup",cn=a.forwardRef((t,s)=>{const{__scopeContextMenu:n,...o}=t,l=D(n);return e.jsx(is,{...l,...o,ref:s})});cn.displayName=on;var ln="ContextMenuRadioItem",_t=a.forwardRef((t,s)=>{const{__scopeContextMenu:n,...o}=t,l=D(n);return e.jsx(cs,{...l,...o,ref:s})});_t.displayName=ln;var dn="ContextMenuItemIndicator",Mt=a.forwardRef((t,s)=>{const{__scopeContextMenu:n,...o}=t,l=D(n);return e.jsx(ls,{...l,...o,ref:s})});Mt.displayName=dn;var mn="ContextMenuSeparator",St=a.forwardRef((t,s)=>{const{__scopeContextMenu:n,...o}=t,l=D(n);return e.jsx(ss,{...l,...o,ref:s})});St.displayName=mn;var un="ContextMenuArrow",hn=a.forwardRef((t,s)=>{const{__scopeContextMenu:n,...o}=t,l=D(n);return e.jsx(ds,{...l,...o,ref:s})});hn.displayName=un;var xn="ContextMenuSubTrigger",kt=a.forwardRef((t,s)=>{const{__scopeContextMenu:n,...o}=t,l=D(n);return e.jsx(ms,{...l,...o,ref:s})});kt.displayName=xn;var pn="ContextMenuSubContent",It=a.forwardRef((t,s)=>{const{__scopeContextMenu:n,...o}=t,l=D(n);return e.jsx(us,{...l,...o,ref:s,style:{...t.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});It.displayName=pn;function Te(t){return s=>s.pointerType!=="mouse"?t(s):void 0}var fn=ft,gn=yt,yn=vt,Rt=jt,Tt=bt,Et=Nt,Pt=Ct,Ot=_t,At=Mt,Dt=St,qt=kt,Lt=It;const vn=fn,wn=gn,jn=a.forwardRef(({className:t,inset:s,children:n,...o},l)=>e.jsxs(qt,{ref:l,className:L("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[state=open]:bg-accent data-[state=open]:text-accent-foreground focus:bg-accent focus:text-accent-foreground",s&&"pl-8",t),...o,children:[n,e.jsx(hs,{className:"ml-auto h-4 w-4"})]}));jn.displayName=qt.displayName;const bn=a.forwardRef(({className:t,...s},n)=>e.jsx(Lt,{ref:n,className:L("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:sli
31de-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t),...s}));bn.displayName=Lt.displayName;const Kt=a.forwardRef(({className:t,...s},n)=>e.jsx(yn,{children:e.jsx(Rt,{ref:n,className:L("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md animate-in fade-in-80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t),...s})}));Kt.displayName=Rt.displayName;const Pe=a.forwardRef(({className:t,inset:s,...n},o)=>e.jsx(Et,{ref:o,className:L("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 focus:bg-accent focus:text-accent-foreground",s&&"pl-8",t),...n}));Pe.displayName=Et.displayName;const Nn=a.forwardRef(({className:t,children:s,checked:n,...o},l)=>e.jsxs(Pt,{ref:l,className:L("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 focus:bg-accent focus:text-accent-foreground",t),checked:n,...o,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(At,{children:e.jsx(xs,{className:"h-4 w-4"})})}),s]}));Nn.displayName=Pt.displayName;const Cn=a.forwardRef(({className:t,children:s,...n},o)=>e.jsxs(Ot,{ref:o,className:L("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 focus:bg-accent focus:text-accent-foreground",t),...n,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(At,{children:e.jsx(ps,{className:"h-2 w-2 fill-current"})})}),s]}));Cn.displayName=Ot.displayName;const _n=a.forwardRef(({className:t,inset:s,...n},o)=>e.jsx(Tt,{ref:o,className:L("px-2 py-1.5 text-sm font-semibold text-foreground",s&&"pl-8",t),...n}));_n.displayName=Tt.displayName;const Ft=a.forwardRef(({className:t,...s},n)=>e.jsx(Dt,{ref:n,className:L("-mx-1 my-1 h-px bg-border",t),...s}));Ft.displayName=Dt.displayName;const Mn=450;function ot({onNavigate:t}){const{user:s}=ke(),n=mt(),{conversationId:o}=ut(),l=Xe(),[h,g]=a.useState(null),[x,d]=a.useState(!0),[w,c]=a.useState(null),[y,P]=a.useState(""),[M,z]=a.useState(null),[Y,ae]=a.useState(""),[G,b]=a.useState("");a.useEffect(()=>{const r=setTimeout(()=>b(Y.trim()),200);return()=>clearTimeout(r)},[Y]);const k=G.length>=2,{data:xe=[]}=me({queryKey:["chat-conversations",s==null?void 0:s.id],queryFn:async()=>{if(!s)return[];const{data:r,error:S}=await R.from("chat_conversations").select("id, title, is_locked, is_pinned, updated_at").eq("user_id",s.id).order("is_pinned",{ascending:!1}).order("updated_at",{ascending:!1}).limit(50);if(S)throw S;return r??[]},enabled:!!s}),{data:re=[],isFetching:pe}=me({queryKey:["chat-conversations-search",s==null?void 0:s.id,G],enabled:!!s&&k,queryFn:async()=>{const{data:r,error:S}=await R.rpc("search_chat_conversations",{q:G,lim:50});if(S)throw S;return r??[]}}),V=k?re:xe.map(r=>({...r,snippet:null})),J=V.filter(r=>r.is_pinned),fe=V.filter(r=>!r.is_pinned),{data:N=0}=me({queryKey:["chat-memory-items-by-convo",h==null?void 0:h.id],enabled:!!(h!=null&&h.id)&&!!s,queryFn:async()=>{const{count:r}=await R.from("chat_memory_items").select("id",{count:"exact",head:!0}).eq("user_id",s.id).eq("source_conversation_id",h.id);return r??0}}),oe=()=>{n("/chat"),t==null||t()},$=async r=>{const S=!r.is_pinned;l.setQueryData(["chat-conversations",s==null?void 0:s.id],X=>(X??[]).map(B=>B.id===r.id?{...B,is_pinned:S}:B));const{error:H}=await R.from("chat_conversations").update({is_pinned:S}).eq("id",r.id);H?(p.error("Couldn't update pin"),l.invalidateQueries({queryKey:["chat-conversations"]}
31)):(p.success(S?"Pinned":"Unpinned"),l.invalidateQueries({queryKey:["chat-conversations"]}))},ie=r=>{P(r.title||""),c({id:r.id,title:r.title||""})},A=async()=>{if(!w)return;const r=y.trim().slice(0,120);if(!r){c(null);return}const S=w.id;c(null);const{error:H}=await R.from("chat_conversations").update({title:r}).eq("id",S);if(H){p.error("Couldn't rename");return}l.invalidateQueries({queryKey:["chat-conversations"]}),l.invalidateQueries({queryKey:["chat-conversations-search"]}),p.success("Renamed")},ce=r=>{d(!0),g({id:r.id,title:r.title||"New chat"})},Q=async()=>{if(!h)return;const r=h.id;x&&N>0&&s&&(await R.from("chat_memory_items").delete().eq("user_id",s.id).eq("source_conversation_id",r),l.invalidateQueries({queryKey:["chat-memory-items"]}));const{error:S}=await R.from("chat_conversations").delete().eq("id",r);if(S){p.error("Failed to delete");return}l.invalidateQueries({queryKey:["chat-conversations"]}),o===r&&n("/chat"),g(null),p.success(x&&N>0?`Conversation deleted · ${N} memor${N===1?"y":"ies"} forgotten`:"Conversation deleted")},W=({c:r})=>{const S=r.id===o,H=G.toLowerCase(),X=C=>{if(!k)return C;const T=C.toLowerCase().indexOf(H);return T<0?C:e.jsxs(e.Fragment,{children:[C.slice(0,T),e.jsx("mark",{className:"rounded-sm bg-primary/20 px-0.5 text-foreground",children:C.slice(T,T+H.length)}),C.slice(T+H.length)]})},B=()=>{n(`/chat/${r.id}`),t==null||t()},Z=a.useRef(null),te=a.useRef(!1),se=a.useRef(null),Ie=C=>{te.current=!1;const T=C.touches[0];se.current={x:T.clientX,y:T.clientY},Z.current=window.setTimeout(()=>{var ne;te.current=!0;try{(ne=navigator.vibrate)==null||ne.call(navigator,15)}catch{}z(r)},Mn)},Re=()=>{Z.current&&(window.clearTimeout(Z.current),Z.current=null)},K=C=>{if(!se.current)return;const T=C.touches[0];(Math.abs(T.clientX-se.current.x)>8||Math.abs(T.clientY-se.current.y)>8)&&Re()},le=()=>Re(),ge=()=>{if(te.current){te.current=!1;return}B()};return e.jsxs(vn,{children:[e.jsx(wn,{asChild:!0,children:e.jsxs("div",{role:"button",tabIndex:0,onClick:ge,onKeyDown:C=>{(C.key==="Enter"||C.key===" ")&&(C.preventDefault(),B())},onTouchStart:Ie,onTouchMove:K,onTouchEnd:le,onTouchCancel:le,style:{touchAction:"manipulation"},className:L("group flex w-full cursor-pointer select-none items-start gap-2 rounded-lg px-3 py-2 text-left text-sm transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-ring active:scale-[0.99]",S?"bg-accent":"hover:bg-accent/50"),children:[r.is_locked?e.jsx(xt,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-destructive"}):r.is_pinned?e.jsx(we,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 fill-current text-primary"}):null,e.jsxs("span",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"block truncate",children:X(r.title||"New chat")}),r.snippet&&e.jsx("span",{className:"mt-0.5 block truncate text-[11px] text-muted-foreground",children:X(r.snippet)})]}),e.jsxs(Ss,{children:[e.jsx(ks,{asChild:!0,children:e.jsx("button",{type:"button",onClick:C=>C.stopPropagation(),className:"-m-1 hidden shrink-0 rounded p-1 text-muted-foreground transition hover:bg-accent hover:text-foreground md:inline-flex data-[state=open]:bg-accent data-[state=open]:text-foreground","aria-label":"Conversation actions",children:e.jsx(Vs,{className:"h-4 w-4"})})}),e.jsxs(Is,{align:"end",className:"w-44",onClick:C=>C.stopPropagation(),children:[e.jsxs(ze,{onSelect:()=>$(r),children:[r.is_pinned?e.jsx(Be,{className:"mr-2 h-4 w-4"}):e.jsx(we,{className:"mr-2 h-4 w-4"}),r.is_pinned?"Unpin":"Pin chat"]}),e.jsxs(ze,{onSelect:()=>ie(r),children:[e.jsx(Fe,{className:"mr-2 h-4 w-4"})," Rename"]}),e.jsx(Rs,{}),e.jsxs(ze,{onSelect:()=>ce(r),className:"text-destructive focus:text-destructive",children:[e.jsx(ue,{className:"mr-2 h-4 w-4"})," Delete"]})]})]})]})}),e.jsxs(Kt,{className:"w-44",children:[e.jsxs(Pe,{onSelect:()=>$(r),children:[r.is_pinned?e.jsx(Be,{className:"mr-2 h-4 w-4"}):e.jsx(we,{className:"mr-2 h-4 w-4"}),r.is_pinned?"Unpin":"Pin chat"]}),e.jsxs(Pe,{onSelect:()=>ie(r),children:[e.jsx(Fe,{className:"mr-2 h-4 w-4"})," Rename"]}),e.jsx(Ft,{}),e.jsxs(Pe,{onSelect:()=>ce(r),className:"text-destructive focus:text-destructive",children:[e.jsx(ue,{className:"mr-2 h-4 w-4"})," Delete"]})]})]})};return e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsxs("div",{className:"space-y-2 p-3",children:[e.jsxs(_,{onClick:oe,className:"w-full justify-start gap-2 rounded-xl",variant:"outline",children:[e.jsx(Je,{className:"h-4 w-4"}),"New chat"]}),e.jsxs("div",{className:"relative",children:[e.jsx(fs,{className:"pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx(Oe,{value:Y,onChange:r=>ae(r.target.value),placeholder:"Search chatsâ¦",className:"h-9 rounded-lg pl-8 pr-8 text-sm"}),Y&&e.jsx("button",{onClick:()=>ae(""),className:"absolute right-2 top-1/2 -translate-y-1/2 roun
31ded p-0.5 text-muted-foreground hover:text-foreground","aria-label":"Clear search",children:e.jsx(gs,{className:"h-3.5 w-3.5"})})]})]}),e.jsx(ht,{className:"flex-1 px-2",children:e.jsxs("div",{className:"space-y-0.5 pb-4",children:[!k&&V.length===0&&e.jsx("p",{className:"px-3 py-8 text-center text-xs text-muted-foreground",children:"No conversations yet"}),k&&!pe&&V.length===0&&e.jsxs("p",{className:"px-3 py-8 text-center text-xs text-muted-foreground",children:['No matches for "',G,'"']}),!k&&J.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-3 pb-1 pt-2 text-[10px] font-medium uppercase tracking-wider text-muted-foreground",children:[e.jsx(we,{className:"h-3 w-3"})," Pinned"]}),J.map(r=>e.jsx(W,{c:r},r.id)),fe.length>0&&e.jsx("div",{className:"px-3 pb-1 pt-3 text-[10px] font-medium uppercase tracking-wider text-muted-foreground",children:"Recent"})]}),(k?V:fe).map(r=>e.jsx(W,{c:r},r.id))]})}),e.jsx(be,{open:!!M,onOpenChange:r=>!r&&z(null),children:e.jsxs(Ne,{className:"sm:max-w-sm gap-2 p-4",children:[e.jsxs(Ce,{className:"space-y-1",children:[e.jsx(_e,{className:"truncate text-sm",children:(M==null?void 0:M.title)||"New chat"}),e.jsx(Me,{className:"text-[11px]",children:"Choose an action"})]}),e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("button",{className:"flex items-center gap-3 rounded-lg px-3 py-3 text-left text-sm hover:bg-accent",onClick:()=>{const r=M;z(null),$(r)},children:[M!=null&&M.is_pinned?e.jsx(Be,{className:"h-4 w-4"}):e.jsx(we,{className:"h-4 w-4"}),M!=null&&M.is_pinned?"Unpin chat":"Pin chat"]}),e.jsxs("button",{className:"flex items-center gap-3 rounded-lg px-3 py-3 text-left text-sm hover:bg-accent",onClick:()=>{const r=M;z(null),ie(r)},children:[e.jsx(Fe,{className:"h-4 w-4"})," Rename"]}),e.jsxs("button",{className:"flex items-center gap-3 rounded-lg px-3 py-3 text-left text-sm text-destructive hover:bg-destructive/10",onClick:()=>{const r=M;z(null),ce(r)},children:[e.jsx(ue,{className:"h-4 w-4"})," Delete"]})]})]})}),e.jsx(be,{open:!!w,onOpenChange:r=>!r&&c(null),children:e.jsxs(Ne,{className:"sm:max-w-md",children:[e.jsxs(Ce,{children:[e.jsx(_e,{children:"Rename chat"}),e.jsx(Me,{children:"Give this conversation a memorable title."})]}),e.jsx(Oe,{autoFocus:!0,value:y,onChange:r=>P(r.target.value),onKeyDown:r=>{r.key==="Enter"&&(r.preventDefault(),A())},maxLength:120,placeholder:"New title"}),e.jsxs(De,{className:"gap-2",children:[e.jsx(_,{variant:"ghost",onClick:()=>c(null),children:"Cancel"}),e.jsx(_,{onClick:A,children:"Save"})]})]})}),e.jsx(ys,{open:!!h,onOpenChange:r=>!r&&g(null),children:e.jsxs(vs,{children:[e.jsxs(ws,{children:[e.jsx(js,{children:"Delete conversation?"}),e.jsxs(bs,{children:['"',h==null?void 0:h.title,`" will be permanently removed. This can't be undone.`]})]}),N>0&&e.jsxs("div",{className:"flex items-start gap-3 rounded-md border border-border/60 bg-muted/30 px-3 py-2.5",children:[e.jsx(Ns,{id:"forget-memories",checked:x,onCheckedChange:r=>d(!!r),className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs(Ve,{htmlFor:"forget-memories",className:"text-sm font-medium leading-tight",children:["Also forget ",N," memor",N===1?"y":"ies"," saved from this chat"]}),e.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:"Recommended â keeps your memory clean of context you no longer want."})]})]}),e.jsxs(Cs,{children:[e.jsx(_s,{children:"Cancel"}),e.jsx(Ms,{onClick:Q,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})})]})}const zt=["chat-memory-settings"],je=["chat-memory-items"];function Ht(){const{user:t}=ke();return me({queryKey:zt,enabled:!!t,queryFn:async()=>{const{data:s,error:n}=await R.from("chat_memory_settings").select("enabled, prompted_at").eq("user_id",t.id).maybeSingle();if(n)throw n;return{enabled:!!(s!=null&&s.enabled),prompted_at:(s==null?void 0:s.prompted_at)??null}},staleTime:5*60*1e3})}function Qt(){const{user:t}=ke();return me({queryKey:je,enabled:!!t,queryFn:async()=>{const{data:s,error:n}=await R.from("chat_memory_items").select("id, content, source_conversation_id, created_at").eq("user_id",t.id).order("created_at",{ascending:!1});if(n)throw n;return s??[]},staleTime:60*1e3})}function et(){const{user:t}=ke(),s=Xe(),n=ve({mutationFn:async x=>{if(!t)throw new Error("Not signed in");const{error:d}=await R.from("chat_memory_settings").upsert({user_id:t.id,...x},{onConflict:"user_id"});if(d)throw d},onSuccess:()=>s.invalidateQueries({queryKey:zt})}),o=ve({mutationFn:async({id:x,content:d})=>{const{error:w}=await R.from("chat_memory_items").update({content:d}).eq("id",x);if(w)throw w},onSuccess:()=>s.invalidateQueries({queryKey:je})}),l=ve({mutationFn:async x=>{const{error:d}=await R.from("chat_memory_items").delete().eq("id",x);if(d)throw d},onSuccess:()=>s.invalidateQueries({queryKey:je})}),h=ve({mutationFn:async()=>
31{if(!t)return;const{error:x}=await R.from("chat_memory_items").delete().eq("user_id",t.id);if(x)throw x},onSuccess:()=>s.invalidateQueries({queryKey:je})}),g=ve({mutationFn:async x=>{if(!t)throw new Error("Not signed in");const d=x.trim();if(!d)throw new Error("Memory cannot be empty");if(d.length>200)throw new Error("Memory must be 200 characters or fewer");const{error:w}=await R.from("chat_memory_items").insert({user_id:t.id,content:d});if(w)throw/cap reached/i.test(w.message)?new Error("You've reached the 20-item memory cap. Delete something first."):w},onSuccess:()=>s.invalidateQueries({queryKey:je})});return{upsertSettings:n,updateItem:o,deleteItem:l,clearAll:h,addItem:g}}const We=200,Ue=20;function Sn({open:t,onOpenChange:s}){const{data:n,isLoading:o}=Ht(),{data:l=[],isLoading:h}=Qt(),{upsertSettings:g,updateItem:x,deleteItem:d,clearAll:w,addItem:c}=et(),[y,P]=a.useState(""),[M,z]=a.useState(!1);a.useEffect(()=>{t||(P(""),z(!1))},[t]);const Y=async b=>{try{const k={enabled:b};n!=null&&n.prompted_at||(k.prompted_at=new Date().toISOString()),await g.mutateAsync(k),p.success(b?"Memory enabled":"Memory disabled")}catch(k){p.error((k==null?void 0:k.message)||"Couldn't update memory settings")}},ae=async()=>{try{await c.mutateAsync(y),P(""),p.success("Saved to memory")}catch(b){p.error((b==null?void 0:b.message)||"Couldn't save memory")}},G=async()=>{try{await w.mutateAsync(),p.success("Memory cleared"),z(!1)}catch(b){p.error((b==null?void 0:b.message)||"Couldn't clear memory")}};return e.jsx(be,{open:t,onOpenChange:s,children:e.jsxs(Ne,{className:"sm:max-w-lg",children:[e.jsxs(Ce,{children:[e.jsxs(_e,{className:"flex items-center gap-2",children:[e.jsx(Se,{className:"h-4 w-4"})," Memory"]}),e.jsxs(Me,{children:["Pixel Bunny can remember small facts about you across chats so replies feel more personal. Memory is ",e.jsx("strong",{children:"off in Incognito"})," and is cleared when you delete the chat it came from."]})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-border/60 bg-muted/30 px-4 py-3",children:[e.jsxs("div",{children:[e.jsx(Ve,{htmlFor:"memory-toggle",className:"text-sm font-medium",children:"Enable memory"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:n!=null&&n.enabled?"On â I'll save things you mention worth remembering.":"Off â nothing is saved across chats."})]}),e.jsx(Ts,{id:"memory-toggle",checked:!!(n!=null&&n.enabled),disabled:o||g.isPending,onCheckedChange:Y})]}),(n==null?void 0:n.enabled)&&e.jsxs(e.Fragment,{children:[e.jsx(at,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ve,{htmlFor:"new-memory",className:"text-xs font-medium text-muted-foreground",children:"Add a memory yourself"}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Oe,{id:"new-memory",value:y,onChange:b=>P(b.target.value.slice(0,We)),placeholder:"e.g. Prefers concise answers",className:"text-sm",disabled:l.length>=Ue}),e.jsx(_,{size:"sm",onClick:ae,disabled:!y.trim()||c.isPending||l.length>=Ue,children:e.jsx(Je,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex justify-between text-[10px] text-muted-foreground",children:[e.jsxs("span",{children:[l.length," / ",Ue," saved"]}),e.jsxs("span",{children:[y.length," / ",We]})]})]}),e.jsx(at,{}),e.jsx(ht,{className:"max-h-[280px] pr-2",children:h?e.jsx("div",{className:"py-8 text-center text-xs text-muted-foreground",children:"Loadingâ¦"}):l.length===0?e.jsxs("div",{className:"flex flex-col items-center gap-2 py-8 text-center",children:[e.jsx(Es,{className:"h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Nothing saved yet. As you chat, things worth remembering will appear here."})]}):e.jsx("ul",{className:"space-y-1.5",children:l.map(b=>e.jsx(kn,{id:b.id,content:b.content,createdAt:b.created_at,onSave:k=>x.mutateAsync({id:b.id,content:k}),onDelete:()=>d.mutateAsync(b.id)},b.id))})})]}),e.jsxs(De,{className:"gap-2 sm:justify-between",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-muted-foreground",children:[e.jsx(Ae,{className:"h-3 w-3"})," Off in Incognito"]}),l.length>0&&(n==null?void 0:n.enabled)&&(M?e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(_,{size:"sm",variant:"ghost",onClick:()=>z(!1),children:"Cancel"}),e.jsx(_,{size:"sm",variant:"destructive",onClick:G,children:"Clear everything"})]}):e.jsxs(_,{size:"sm",variant:"ghost",onClick:()=>z(!0),children:[e.jsx(ue,{className:"mr-1.5 h-3.5 w-3.5"})," Clear all"]}))]})]})})}function kn({id:t,content:s,createdAt:n,onSave:o,onDelete:l}
31){const[h,g]=a.useState(!1),[x,d]=a.useState(s),w=async()=>{const c=x.trim();if(!c||c===s){g(!1),d(s);return}try{await o(c),g(!1),p.success("Memory updated")}catch(y){p.error((y==null?void 0:y.message)||"Couldn't update")}};return e.jsxs("li",{className:"group flex items-start gap-2 rounded-md border border-border/40 bg-background/60 px-3 py-2 transition hover:border-border",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[h?e.jsx(Oe,{autoFocus:!0,value:x,onChange:c=>d(c.target.value.slice(0,We)),onBlur:w,onKeyDown:c=>{c.key==="Enter"&&w(),c.key==="Escape"&&(g(!1),d(s))},className:"h-7 text-xs"}):e.jsx("button",{onClick:()=>g(!0),className:"block w-full text-left text-xs leading-relaxed text-foreground/90",children:s}),e.jsxs("p",{className:"mt-0.5 text-[10px] text-muted-foreground",children:["saved ",Us(new Date(n),{addSuffix:!0})]})]}),e.jsx(_,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-0 transition group-hover:opacity-100",onClick:async()=>{try{await l(),p.success("Removed from memory")}catch(c){p.error((c==null?void 0:c.message)||"Couldn't delete")}},children:e.jsx(ue,{className:"h-3 w-3"})})]})}function In({open:t,onOpenChange:s}){const{upsertSettings:n}=et(),o=async l=>{try{await n.mutateAsync({enabled:l,prompted_at:new Date().toISOString()}),p.success(l?"Memory turned on":"Memory stays off"),s(!1)}catch(h){p.error((h==null?void 0:h.message)||"Couldn't save preference")}};return e.jsx(be,{open:t,onOpenChange:s,children:e.jsxs(Ne,{className:"sm:max-w-md",children:[e.jsxs(Ce,{children:[e.jsx("div",{className:"mb-2 flex h-10 w-10 items-center justify-center rounded-xl bg-primary/10",children:e.jsx(Se,{className:"h-5 w-5 text-primary"})}),e.jsx(_e,{children:"Want me to remember things?"}),e.jsxs(Me,{className:"space-y-2 pt-1",children:[e.jsx("span",{className:"block",children:"I can save short facts you mention â like your name, role, or how you like answers formatted â so future chats feel more personal."}),e.jsxs("span",{className:"flex items-start gap-2 rounded-md bg-muted/50 px-3 py-2 text-xs",children:[e.jsx(Ae,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsxs("span",{children:["Memory is ",e.jsx("strong",{children:"off in Incognito"})," chats."]})]}),e.jsxs("span",{className:"flex items-start gap-2 rounded-md bg-muted/50 px-3 py-2 text-xs",children:[e.jsx(ue,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsx("span",{children:"Deleting a chat can also forget memories saved from it."})]}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:"You can turn it off, edit, or clear everything anytime in Memory settings."})]})]}),e.jsxs(De,{className:"gap-2 sm:justify-end",children:[e.jsx(_,{variant:"ghost",onClick:()=>o(!1),disabled:n.isPending,children:"No thanks"}),e.jsxs(_,{onClick:()=>o(!0),disabled:n.isPending,children:[e.jsx(Se,{className:"mr-1.5 h-4 w-4"}),"Turn memory on"]})]})]})})}const Rn=[{icon:qs,label:"Brainstorm ideas",prompt:"Brainstorm 5 unexpected product names for a sleep-tracking ring",hint:"Spark fresh angles"},{icon:Xs,label:"Draft a post",prompt:"Write a punchy LinkedIn post announcing our new feature",hint:"Tone, hook, CTA"},{icon:Ls,label:"Help me reply",prompt:"Help me write a polite email declining a meeting",hint:"Short and warm"},{icon:Ys,label:"Explain code",prompt:"Explain how React's useEffect cleanup works with a small example",hint:"Quick walkthrough"}],it="chat-sidebar-collapsed",ct="chat:lastModelId",Ee="chat:incognito-hint-seen",Ye="chat:memory-hint-seen",lt="chat:history-hint-seen";function zn(){var nt;const{conversationId:t}=ut(),s=mt(),[n]=Ps(),{user:o,profile:l}=ke(),h=Xe(),{data:g=[]}=zs(),x=Hs(),[d,w]=a.useState(""),[c,y]=a.useState([]),[P,M]=a.useState(!1),[z,Y]=a.useState(!1),[ae,G]=a.useState(!1),[b,k]=a.useState(!1),[xe,re]=a.useState(!1),[pe,V]=a.useState(!1),[J,fe]=a.useState(!1),{data:N}=Ht(),{data:oe=[]}=Qt(),[$,ie]=a.useState(()=>typeof window>"u"?!0:window.localStorage.getItem(it)!=="0"),[A,ce]=a.useState(null),[Q,W]=a.useState(null),{send:r,stop:S,isStreaming:H}=Qs(),X=a.useRef();a.useEffect(()=>{window.localStorage.setItem(it,$?"1":"0")},[$]),a.useEffect(()=>{var j;if(d||!g.length)return;const i=typeof window<"u"?window.localStorage.getItem(ct):null,m=i&&g.find(v=>v.id===i),f=((j=g.find(v=>v.id==="grok-4.3"))==null?void 0:j.id)??g[0].id;w(m?i:f)},[g,d]),a.useEffect(()=>{if(d)try{window.localStorage.setItem(ct,d)}catch{}},[d]),a.useEffect(()=>{if(!N||N.enabled||N.prompted_at)return;c.filter(m=>m.role==="assistant"&&!m.streaming&&m.content.trim().length>0).length>=3&&k(!0)},[c,N]),a.useEffect(()=>{if(typeof window>"u")return;const i=n.get("onboarding")==="1",m=O=>window.localStorage.getItem(O)==="1",f=i||!m(lt),j=i||!m(Ye),v=i||!m(Ee);if(f){const O=setTimeout(()=>fe(!0),700);return()=>clearTimeout(O)}if(j){const O=setTimeout(()=>V(!0),700);return()=>clearTimeout(O)}if(v){const O=setTimeout(()=>re(!0),700);return()=>clearTimeout(O)}},[n]);const B=i=>{try{window.localStorage.setItem(i,"1")}catch{}},Z=a.useCallback(()=>{fe(!1),B(lt),window.localStorage.getItem(Ye)!=="1"?setTimeout(()=>V(!0),250):window.localStorage.getItem(Ee)!=="1"&&setTimeout(()=>re(!0),250)},[]),te=a.useCallback(()=>{V(!1),B(Ye),window.localStorage.getItem(Ee)!=="1"&&setTimeout(()=>re(!0),250)},[]),se=a.useCallback(()=>{re(!1),B(Ee)},[]),{deleteItem:Ie}=et(),Re=a.useCallback(async(i,m)=>{y(f=>f.map(j=>j.id===i?{...j,memorySaved:(j.memorySaved??[]).filter(v=>v.id!==m)}:j));try{await Ie.mutateAsync(m),p.success("Forgotten")}catch(f){p.error((f==null?void 0:f.message)||"Couldn't forget that one")}},[Ie]),{data:K}=me({queryKey:["chat-messages",t],queryFn:async()=>
31{if(!t)return null;const{data:i}=await R.from("chat_conversations").select("id, default_model_id, is_locked").eq("id",t).maybeSingle(),{data:m}=await R.from("chat_messages").select("id, role, content, attachments, status, model_id").eq("conversation_id",t).order("created_at",{ascending:!0});return{convo:i,msgs:m??[]}},enabled:!!t,staleTime:3e4,gcTime:5*6e4,placeholderData:Fs}),le=a.useRef(null),ge=a.useRef(null);a.useEffect(()=>{y([]),le.current=null,H&&S()},[t]),a.useEffect(()=>{var i,m;t&&K!=null&&K.msgs&&((i=K.convo)==null?void 0:i.id)===t&&(y(f=>{const v=ge.current===t?f.filter(F=>F.id.startsWith("tmp-")):[];return[...K.msgs.map(F=>({id:F.id,role:F.role,content:F.content,attachments:F.attachments,status:F.status,modelId:F.model_id??void 0})),...v]}),(m=K.convo)!=null&&m.default_model_id&&le.current!==t&&(w(K.convo.default_model_id),le.current=t))},[t,K]);const C=a.useCallback(i=>{w(i),t&&R.from("chat_conversations").update({default_model_id:i}).eq("id",t)},[t]),T=a.useCallback(async(i,m,f)=>{const j=f??d;if(!o||!j)return;const v={id:`tmp-u-${Date.now()}`,role:"user",content:i,attachments:m},O={id:`tmp-a-${Date.now()}`,role:"assistant",content:"",streaming:!0,modelId:j};y(u=>[...u,v,O]);const F=!t;let U=t;if(!U){const{data:u,error:E}=await R.from("chat_conversations").insert({user_id:o.id,default_model_id:j}).select("id").single();if(E||!u){y(I=>I.filter(ee=>ee.id!==v.id&&ee.id!==O.id)),p.error("Failed to start conversation");return}U=u.id,s(`/chat/${U}`,{replace:!0})}ge.current=U;let q="";await r({conversation_id:U,model_id:j,message:i,attachments:m.map(u=>({url:u.url,type:u.type})),onMemorySaved:({id:u,fact:E})=>{y(I=>I.map(ee=>ee.id===O.id?{...ee,memorySaved:[...ee.memorySaved??[],{id:u,fact:E}]}:ee)),h.invalidateQueries({queryKey:["chat-memory-items"]})},onDelta:u=>{q+=u,y(E=>E.map(I=>I.id===O.id?{...I,content:q}:I))},onDone:u=>{y(E=>E.map(I=>I.id===O.id?{...I,streaming:!1,status:(u==null?void 0:u.status)??"complete"}:I)),ge.current=null,h.setQueryData(["chat-conversations",o==null?void 0:o.id],E=>{if(!E)return E;const I=E.findIndex(Ke=>Ke.id===U);return I<0?E:[{...E[I],updated_at:new Date().toISOString()},...E.slice(0,I),...E.slice(I+1)].sort((Ke,Yt)=>Number(Yt.is_pinned)-Number(Ke.is_pinned))}),h.invalidateQueries({queryKey:["chat-messages",U]}),h.invalidateQueries({queryKey:["profile"]}),F&&h.invalidateQueries({queryKey:["chat-conversations"]}),(u==null?void 0:u.status)==="unpaid"?p.error("Reply delivered but couldn't be billed. Top up to continue."):u&&u.credits_charged>0&&p.success(`${u.credits_charged} credit${u.credits_charged===1?"":"s"} used`)},onError:u=>{y(E=>E.filter(I=>I.id!==v.id&&I.id!==O.id)),u.code==="RATE_LIMITED"?p.warning("Model is busy",{description:"Try again in a moment or switch to another model."}):u.code==="MODEL_UNAVAILABLE"?p.warning("Model unavailable",{description:u.message||"Pick another model and try again."}):u.code==="PROVIDER_DOWN"?p.warning("AI provider unavailable",{description:"Please retry in a moment."}):u.code==="DAILY_CAP_REACHED"?p.warning("Daily chat limit reached",{description:u.message}):u.code==="CONTENT_BLOCKED"?p.error("Message blocked",{description:u.message}):u.code==="CONCURRENT_REQUEST"?p.warning(u.message):u.status===402?Y(!0):u.status===429?p.warning("Rate limited. Please retry shortly."):u.status===423?p.error(u.message):p.error(u.message||"Something went wrong")}})},[t,d,o,r,s,h,l,x]);a.useEffect(()=>{X.current=T},[T]);const ne=a.useCallback(i=>{const m=c.findIndex(f=>f.id===i);for(let f=m-1;f>=0;f--)if(c[f].role==="user")return{text:c[f].content,attachments:c[f].attachments??[]};return null},[c]),de=a.useCallback(async(i,m,f,j)=>{var U;if(!t||!c.find(q=>q.id===i))return;const F=c.slice(c.findIndex(q=>q.id===i)).filter(q=>!q.id.startsWith("tmp-")).map(q=>q.id);F.length&&await R.from("chat_messages").delete().in("id",F),y(q=>q.slice(0,q.findIndex(u=>u.id===i)));try{await((U=X.current)==null?void 0:U.call(X,m,f,j))}catch{p.error("Couldn't resend",{description:"Your previous reply was removed. Try sending again."})}},[t,c]),Gt=a.useCallback(i=>{const m=c.find(f=>f.id===i);m&&(ce({text:m.content,key:Date.now()}),qe.current=i)},[c]),qe=a.useRef(null),tt=a.useCallback((i,m)=>{const f=qe.current;if(f){qe.current=null,ce(null),de(f,i,m);return}T(i,m)},[T,de]),$t=a.useCallback(async i=>{const m=ne(i);if(!m)return;const f=c.findIndex(v=>v.id===i);let j=null;for(let v=f-1;v>=0;v--)if(c[v].role==="user"){j=c[v].id;break}j&&await de(j,m.text,m.attachments)},[ne,c,de]),Bt=a.useCallback(i=>{W({assistantId:i,modelId:d})},[d]),Ut=a.useCallback(async()=>
31{if(!Q)return;const i=ne(Q.assistantId);if(!i){W(null);return}let m=null;const f=c.findIndex(v=>v.id===Q.assistantId);for(let v=f-1;v>=0;v--)if(c[v].role==="user"){m=c[v].id;break}const j=Q.modelId;W(null),w(j),m&&await de(m,i.text,i.attachments,j)},[Q,ne,c,de]);Gs({onNewChat:()=>s("/chat"),onToggleSidebar:()=>{window.matchMedia("(min-width: 768px)").matches?ie(i=>!i):M(i=>!i)},onStop:()=>{H&&S()}});const Le=c.length===0,st=!!((nt=K==null?void 0:K.convo)!=null&&nt.is_locked);return e.jsxs("div",{className:"flex h-[100svh] md:h-[calc(100dvh-3rem)] w-full",children:[e.jsx("aside",{className:L("hidden shrink-0 overflow-hidden border-r border-border/50 bg-muted/20 transition-[width] duration-200 ease-out md:block",$?"w-0 border-r-0":"w-64"),children:e.jsx("div",{className:"w-64",children:e.jsx(ot,{})})}),e.jsx(Os,{open:P,onOpenChange:M,children:e.jsx(As,{side:"left",className:"w-72 p-0",children:e.jsx(ot,{onNavigate:()=>M(!1)})})}),e.jsxs("main",{className:"flex min-w-0 flex-1 flex-col bg-muted/30",children:[e.jsxs("header",{className:"flex h-12 items-center justify-between border-b border-border/40 px-3",children:[e.jsx("div",{className:"flex items-center gap-1",children:e.jsxs("div",{className:"relative",children:[e.jsx(_,{variant:"ghost",size:"icon",className:L("md:hidden",J&&"ring-2 ring-primary animate-pulse"),onClick:()=>{J&&Z(),M(!0)},"aria-label":"Open conversations",children:e.jsx($e,{className:"h-4 w-4"})}),e.jsx(_,{variant:"ghost",size:"icon",className:L("hidden md:inline-flex",J&&"ring-2 ring-primary animate-pulse"),onClick:()=>{J&&Z(),ie(i=>!i)},"aria-label":$?"Show conversations (âK)":"Hide conversations (âK)",title:$?"Show conversations (âK)":"Hide conversations (âK)",children:$?e.jsx(Ws,{className:"h-4 w-4"}):e.jsx($e,{className:"h-4 w-4"})}),J&&e.jsxs("div",{className:"absolute left-0 top-[calc(100%+8px)] z-50 w-60 rounded-lg border border-border bg-popover p-3 text-xs shadow-lg",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-1.5 font-medium",children:[e.jsx($e,{className:"h-3 w-3 text-primary"})," Your chats live here"]}),e.jsx("p",{className:"text-muted-foreground",children:"Browse, search, pin, rename or delete past conversations. Long-press any chat on mobile."}),e.jsx(_,{size:"sm",variant:"ghost",className:"mt-2 h-6 w-full text-[11px]",onClick:Z,children:"Got it"})]})]})}),e.jsx("div",{className:"flex-1 text-center text-sm font-medium text-muted-foreground",children:!Le&&"Pixel Bunny Chat"}),e.jsxs("div",{className:"flex items-center gap-0.5",children:[!Le&&e.jsxs(He,{children:[e.jsx(Qe,{asChild:!0,children:e.jsx(_,{variant:"ghost",size:"icon",onClick:()=>s("/chat"),"aria-label":"New chat",children:e.jsx(Je,{className:"h-4 w-4"})})}),e.jsx(Ge,{side:"bottom",children:"New chat (ââ§O)"})]}),e.jsxs("div",{className:"relative",children:[e.jsxs(He,{children:[e.jsx(Qe,{asChild:!0,children:e.jsxs(_,{variant:"ghost",size:"icon",onClick:()=>{pe&&te(),G(!0)},"aria-label":"Memory settings",className:L("relative",pe&&"ring-2 ring-primary animate-pulse"),children:[e.jsx(Se,{className:"h-4 w-4"}),(N==null?void 0:N.enabled)&&oe.length>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-[9px] font-medium text-primary-foreground",children:oe.length}),(N==null?void 0:N.enabled)&&oe.length===0&&e.jsx("span",{className:"absolute right-1.5 top-1.5 h-1.5 w-1.5 rounded-full bg-primary"})]})}),e.jsx(Ge,{side:"bottom",children:N!=null&&N.enabled?`Memory · ${oe.length} saved`:"Memory · off"})]}),pe&&e.jsxs("div",{className:"absolute right-0 top-[calc(100%+8px)] z-50 w-60 rounded-lg border border-border bg-popover p-3 text-xs shadow-lg",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-1.5 font-medium",children:[e.jsx(Se,{className:"h-3 w-3 text-primary"})," Memory"]}),e.jsx("p",{className:"text-muted-foreground",children:"Turn on memory and I'll remember preferences across chats. Tap the brain anytime to manage."}),e.jsx(_,{size:"sm",variant:"ghost",className:"mt-2 h-6 w-full text-[11px]",onClick:te,children:"Got it"})]})]}),e.jsxs("div",{className:"relative",children:[e.jsxs(He,{children:[e.jsx(Qe,{asChild:!0,children:e.jsx(_,{asChild:!0,variant:"ghost",size:"icon","aria-label":"Incognito chat",className:L("relative",xe&&"ring-2 ring-primary animate-pulse"),onClick:()=>{xe&&se()},children:e.jsx(Ds,{to:"/incognito",children:e.jsx(Ae,{className:"h-4 w-4"})})})}),e.jsx(Ge,{side:"bottom",children:"Incognito chat"})]}),xe&&e.jsxs("div",{className:"absolute right-0 top-[calc(100%+8px)] z-50 w-60 rounded-lg border border-border bg-popover p-3 text-xs shadow-lg",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-1.5 font-medium",children:[e.jsx(Ae,{className:"h-3 w-3 text-primary"})," Private chat"]}),e.jsx("p",{className:"text-muted-foreground",children:"Tap here to chat off the record â nothing is saved and memory is paused."}),e.jsx(_,{size:"sm",variant:"ghost",className:"mt-2 h-6 w-full text-[11px]",onClick:se,children:"Got it"})]})]})]})]}),e.jsx("div",{className:"flex flex-1 flex-col overflow-hidden",children:Le?e.jsxs("div",{className:"relative flex flex-1 flex-col items-center justify-center overflow-hidden px-4 py-6",children:[e.jsx("div",{"aria-hidden":!0,
31className:"pointer-events-none absolute inset-0 -z-10 opacity-60",style:{background:"radial-gradient(ellipse 60% 50% at 50% 35%, hsl(var(--primary) / 0.10), transparent 70%)"}}),e.jsxs("div",{className:"mx-auto flex w-full max-w-3xl flex-col items-center",children:[e.jsxs("div",{className:"mb-5 flex items-center gap-2 text-[11px] font-medium uppercase tracking-[0.18em] text-muted-foreground",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary/70 animate-pulse"}),"Pixel Bunny Chat"]}),e.jsxs("h1",{className:"text-center font-semibold tracking-tight",style:{fontSize:"clamp(28px, 5vw, 44px)",lineHeight:1.05},children:["What should we"," ",e.jsx("span",{className:"bg-gradient-to-r from-primary to-foreground bg-clip-text text-transparent",children:"make today"}),"?"]}),e.jsx("p",{className:"mt-3 max-w-md text-center text-sm text-muted-foreground",children:"Multi-model chat with vision, voice and memory â pick a model and start typing."}),e.jsx("div",{className:"mt-8 w-full",children:e.jsx(rt,{modelId:d,onModelChange:C,onSend:tt,isStreaming:H,onStop:S,initialText:A==null?void 0:A.text,initialKey:A==null?void 0:A.key})}),e.jsx("div",{className:"mx-auto mt-5 grid w-full max-w-2xl grid-cols-1 gap-2 px-3 sm:grid-cols-2",children:Rn.map(i=>{const m=i.icon;return e.jsxs("button",{onClick:()=>T(i.prompt,[]),className:"group flex items-start gap-3 rounded-xl border border-border/60 bg-background/40 px-3.5 py-3 text-left transition hover:-translate-y-px hover:border-border hover:bg-accent/50 hover:shadow-sm",children:[e.jsx("span",{className:"mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary transition group-hover:bg-primary/15",children:e.jsx(m,{className:"h-3.5 w-3.5"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-[13px] font-medium leading-tight",children:i.label}),e.jsx("span",{className:"mt-0.5 block truncate text-[11px] text-muted-foreground",children:i.hint})]})]},i.label)})})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex-1 overflow-y-auto overscroll-contain",children:e.jsx($s,{messages:c,models:g,onEdit:Gt,onRegenerate:$t,onSwitchModel:Bt,onDeleteMemory:Re})}),st&&e.jsx("div",{className:"mx-auto w-full max-w-3xl px-4",children:e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-destructive/40 bg-destructive/5 px-4 py-3 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 text-destructive",children:[e.jsx(xt,{className:"h-4 w-4"}),e.jsx("span",{children:"This chat is locked due to a billing issue. Top up and start a new chat."})]}),e.jsx(_,{size:"sm",variant:"outline",onClick:()=>s("/chat"),children:"New chat"})]})}),e.jsx("div",{className:"bg-gradient-to-t from-muted/30 via-muted/30 to-transparent px-3 pt-3 md:px-4 md:pt-6",style:{paddingBottom:"max(env(safe-area-inset-bottom), 0.5rem)"},children:e.jsx("div",{className:"mx-auto max-w-3xl",children:e.jsx(rt,{modelId:d,onModelChange:C,onSend:tt,isStreaming:H,onStop:S,initialText:A==null?void 0:A.text,initialKey:A==null?void 0:A.key,disabled:st})})})]})})]}),e.jsx(be,{open:!!Q,onOpenChange:i=>!i&&W(null),children:e.jsxs(Ne,{className:"sm:max-w-md",children:[e.jsxs(Ce,{children:[e.jsx(_e,{children:"Try with another model"}),e.jsx(Me,{children:"We'll re-run the previous question on the selected model. The current reply will be replaced."})]}),Q&&e.jsx("div",{className:"py-2",children:e.jsx(Bs,{value:Q.modelId,onChange:i=>W({...Q,modelId:i})})}),e.jsxs(De,{className:"gap-2",children:[e.jsx(_,{variant:"ghost",onClick:()=>W(null),children:"Cancel"}),e.jsx(_,{onClick:Ut,children:"Re-run"})]})]})}),e.jsx(Ks,{open:z,onOpenChange:Y,reason:"insufficient_credits"}),e.jsx(Sn,{open:ae,onOpenChange:G}),e.jsx(In,{open:b,onOpenChange:k})]})}export{zn 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.