teodor-new-chat-ui 2.0.31 → 2.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -7102,13 +7102,13 @@ function Pn({
7102
7102
  }
7103
7103
  )
7104
7104
  ] }),
7105
- d && q.length > 0 && /* @__PURE__ */ R("div", { className: "flex items-center gap-2 px-4 py-2 border-b bg-background/50 text-xs", children: [
7105
+ d && q.length > 0 && /* @__PURE__ */ R("div", { className: "flex items-center gap-2 px-4 py-2 border-b border-border bg-muted/60 text-xs dark:bg-muted/50", children: [
7106
7106
  /* @__PURE__ */ c(ua, { className: "h-4 w-4 opacity-70" }),
7107
7107
  /* @__PURE__ */ c("span", { className: "opacity-70", children: "Checkpoint:" }),
7108
7108
  /* @__PURE__ */ R(
7109
7109
  "select",
7110
7110
  {
7111
- className: "border rounded px-2 py-1 text-xs",
7111
+ className: "border border-border rounded px-2 py-1 text-xs bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring dark:bg-secondary",
7112
7112
  value: G ?? "",
7113
7113
  onChange: (k) => {
7114
7114
  const X = k.target.value || null;
package/dist/index.umd.js CHANGED
@@ -55,7 +55,7 @@
55
55
  `)},ii=function(){var e=parseInt(document.body.getAttribute(Pt)||"0",10);return isFinite(e)?e:0},sg=function(){l.useEffect(function(){return document.body.setAttribute(Pt,(ii()+1).toString()),function(){var e=ii()-1;e<=0?document.body.removeAttribute(Pt):document.body.setAttribute(Pt,e.toString())}},[])},ag=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;sg();var s=l.useMemo(function(){return ng(o)},[o]);return l.createElement(rg,{styles:og(s,!t,o,n?"":"!important")})},vo=!1;if(typeof window<"u")try{var Hn=Object.defineProperty({},"passive",{get:function(){return vo=!0,!0}});window.addEventListener("test",Hn,Hn),window.removeEventListener("test",Hn,Hn)}catch{vo=!1}var _t=vo?{passive:!1}:!1,ig=function(e){return e.tagName==="TEXTAREA"},ci=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!ig(e)&&n[t]==="visible")},cg=function(e){return ci(e,"overflowY")},lg=function(e){return ci(e,"overflowX")},li=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=di(e,r);if(o){var s=ui(e,r),a=s[1],c=s[2];if(a>c)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},dg=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},ug=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},di=function(e,t){return e==="v"?cg(t):lg(t)},ui=function(e,t){return e==="v"?dg(t):ug(t)},fg=function(e,t){return e==="h"&&t==="rtl"?-1:1},pg=function(e,t,n,r,o){var s=fg(e,window.getComputedStyle(t).direction),a=s*r,c=n.target,d=t.contains(c),f=!1,u=a>0,p=0,m=0;do{if(!c)break;var v=ui(e,c),g=v[0],h=v[1],b=v[2],w=h-b-s*g;(g||w)&&di(e,c)&&(p+=w,m+=g);var y=c.parentNode;c=y&&y.nodeType===Node.DOCUMENT_FRAGMENT_NODE?y.host:y}while(!d&&c!==document.body||d&&(t.contains(c)||t===c));return(u&&Math.abs(p)<1||!u&&Math.abs(m)<1)&&(f=!0),f},Wn=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},fi=function(e){return[e.deltaX,e.deltaY]},pi=function(e){return e&&"current"in e?e.current:e},hg=function(e,t){return e[0]===t[0]&&e[1]===t[1]},gg=function(e){return`
56
56
  .block-interactivity-`.concat(e,` {pointer-events: none;}
57
57
  .allow-interactivity-`).concat(e,` {pointer-events: all;}
58
- `)},mg=0,It=[];function bg(e){var t=l.useRef([]),n=l.useRef([0,0]),r=l.useRef(),o=l.useState(mg++)[0],s=l.useState(ai)[0],a=l.useRef(e);l.useEffect(function(){a.current=e},[e]),l.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var h=Bh([e.lockRef.current],(e.shards||[]).map(pi),!0).filter(Boolean);return h.forEach(function(b){return b.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),h.forEach(function(b){return b.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var c=l.useCallback(function(h,b){if("touches"in h&&h.touches.length===2||h.type==="wheel"&&h.ctrlKey)return!a.current.allowPinchZoom;var w=Wn(h),y=n.current,x="deltaX"in h?h.deltaX:y[0]-w[0],E="deltaY"in h?h.deltaY:y[1]-w[1],C,O=h.target,N=Math.abs(x)>Math.abs(E)?"h":"v";if("touches"in h&&N==="h"&&O.type==="range")return!1;var $=li(N,O);if(!$)return!0;if($?C=N:(C=N==="v"?"h":"v",$=li(N,O)),!$)return!1;if(!r.current&&"changedTouches"in h&&(x||E)&&(r.current=C),!C)return!0;var L=r.current||C;return pg(L,b,h,L==="h"?x:E)},[]),d=l.useCallback(function(h){var b=h;if(!(!It.length||It[It.length-1]!==s)){var w="deltaY"in b?fi(b):Wn(b),y=t.current.filter(function(C){return C.name===b.type&&(C.target===b.target||b.target===C.shadowParent)&&hg(C.delta,w)})[0];if(y&&y.should){b.cancelable&&b.preventDefault();return}if(!y){var x=(a.current.shards||[]).map(pi).filter(Boolean).filter(function(C){return C.contains(b.target)}),E=x.length>0?c(b,x[0]):!a.current.noIsolation;E&&b.cancelable&&b.preventDefault()}}},[]),f=l.useCallback(function(h,b,w,y){var x={name:h,delta:b,target:w,should:y,shadowParent:vg(w)};t.current.push(x),setTimeout(function(){t.current=t.current.filter(function(E){return E!==x})},1)},[]),u=l.useCallback(function(h){n.current=Wn(h),r.current=void 0},[]),p=l.useCallback(function(h){f(h.type,fi(h),h.target,c(h,e.lockRef.current))},[]),m=l.useCallback(function(h){f(h.type,Wn(h),h.target,c(h,e.lockRef.current))},[]);l.useEffect(function(){return It.push(s),e.setCallbacks({onScrollCapture:p,onWheelCapture:p,onTouchMoveCapture:m}),document.addEventListener("wheel",d,_t),document.addEventListener("touchmove",d,_t),document.addEventListener("touchstart",u,_t),function(){It=It.filter(function(h){return h!==s}),document.removeEventListener("wheel",d,_t),document.removeEventListener("touchmove",d,_t),document.removeEventListener("touchstart",u,_t)}},[]);var v=e.removeScrollBar,g=e.inert;return l.createElement(l.Fragment,null,g?l.createElement(s,{styles:gg(o)}):null,v?l.createElement(ag,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function vg(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const wg=Gh(si,bg);var Vn=l.forwardRef(function(e,t){return l.createElement(zn,qe({},e,{ref:t,sideCar:wg}))});Vn.classNames=zn.classNames;var wo=["Enter"," "],yg=["ArrowDown","PageUp","Home"],hi=["ArrowUp","PageDown","End"],xg=[...yg,...hi],Sg={ltr:[...wo,"ArrowRight"],rtl:[...wo,"ArrowLeft"]},Cg={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Yt="Menu",[Jt,Eg,Ng]=Hr(Yt),[ut,gi]=Le(Yt,[Ng,Tt,Ya]),jn=Tt(),mi=Ya(),[Tg,ft]=ut(Yt),[Ag,Zt]=ut(Yt),bi=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:a=!0}=e,c=jn(t),[d,f]=l.useState(null),u=l.useRef(!1),p=we(s),m=Cn(o);return l.useEffect(()=>{const v=()=>{u.current=!0,document.addEventListener("pointerdown",g,{capture:!0,once:!0}),document.addEventListener("pointermove",g,{capture:!0,once:!0})},g=()=>u.current=!1;return document.addEventListener("keydown",v,{capture:!0}),()=>{document.removeEventListener("keydown",v,{capture:!0}),document.removeEventListener("pointerdown",g,{capture:!0}),document.removeEventListener("pointermove",g,{capture:!0})}},[]),i.jsx(ao,{...c,children:i.jsx(Tg,{scope:t,open:n,onOpenChange:p,content:d,onContentChange:f,children:i.jsx(Ag,{scope:t,onClose:l.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:u,dir:m,modal:a,children:r})})})};bi.displayName=Yt;var Pg="MenuAnchor",yo=l.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=jn(n);return i.jsx(io,{...o,...r,ref:t})});yo.displayName=Pg;var xo="MenuPortal",[_g,vi]=ut(xo,{forceMount:void 0}),wi=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=ft(xo,t);return i.jsx(_g,{scope:t,forceMount:n,children:i.jsx(Te,{present:n||s.open,children:i.jsx(Ln,{asChild:!0,container:o,children:r})})})};wi.displayName=xo;var Oe="MenuContent",[Ig,So]=ut(Oe),yi=l.forwardRef((e,t)=>{const n=vi(Oe,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=ft(Oe,e.__scopeMenu),a=Zt(Oe,e.__scopeMenu);return i.jsx(Jt.Provider,{scope:e.__scopeMenu,children:i.jsx(Te,{present:r||s.open,children:i.jsx(Jt.Slot,{scope:e.__scopeMenu,children:a.modal?i.jsx(Og,{...o,ref:t}):i.jsx(kg,{...o,ref:t})})})})}),Og=l.forwardRef((e,t)=>{const n=ft(Oe,e.__scopeMenu),r=l.useRef(null),o=re(t,r);return l.useEffect(()=>{const s=r.current;if(s)return ho(s)},[]),i.jsx(Co,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:U(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),kg=l.forwardRef((e,t)=>{const n=ft(Oe,e.__scopeMenu);return i.jsx(Co,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),Mg=Pe.createSlot("MenuContent.ScrollLock"),Co=l.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:a,disableOutsidePointerEvents:c,onEntryFocus:d,onEscapeKeyDown:f,onPointerDownOutside:u,onFocusOutside:p,onInteractOutside:m,onDismiss:v,disableOutsideScroll:g,...h}=e,b=ft(Oe,n),w=Zt(Oe,n),y=jn(n),x=mi(n),E=Eg(n),[C,O]=l.useState(null),N=l.useRef(null),$=re(t,N,b.onContentChange),L=l.useRef(0),F=l.useRef(""),R=l.useRef(0),G=l.useRef(null),V=l.useRef("right"),z=l.useRef(0),X=g?Vn:l.Fragment,B=g?{as:Mg,allowPinchZoom:!0}:void 0,q=_=>{var j,se;const I=F.current+_,k=E().filter(le=>!le.disabled),J=document.activeElement,M=(j=k.find(le=>le.ref.current===J))==null?void 0:j.textValue,H=k.map(le=>le.textValue),de=Rg(H,I,M),ie=(se=k.find(le=>le.textValue===de))==null?void 0:se.ref.current;(function le(ae){F.current=ae,window.clearTimeout(L.current),ae!==""&&(L.current=window.setTimeout(()=>le(""),1e3))})(I),ie&&setTimeout(()=>ie.focus())};l.useEffect(()=>()=>window.clearTimeout(L.current),[]),jr();const T=l.useCallback(_=>{var k,J;return V.current===((k=G.current)==null?void 0:k.side)&&Gg(_,(J=G.current)==null?void 0:J.area)},[]);return i.jsx(Ig,{scope:n,searchRef:F,onItemEnter:l.useCallback(_=>{T(_)&&_.preventDefault()},[T]),onItemLeave:l.useCallback(_=>{var I;T(_)||((I=N.current)==null||I.focus(),O(null))},[T]),onTriggerLeave:l.useCallback(_=>{T(_)&&_.preventDefault()},[T]),pointerGraceTimerRef:R,onPointerGraceIntentChange:l.useCallback(_=>{G.current=_},[]),children:i.jsx(X,{...B,children:i.jsx(En,{asChild:!0,trapped:o,onMountAutoFocus:U(s,_=>{var I;_.preventDefault(),(I=N.current)==null||I.focus({preventScroll:!0})}),onUnmountAutoFocus:a,children:i.jsx(Rt,{asChild:!0,disableOutsidePointerEvents:c,onEscapeKeyDown:f,onPointerDownOutside:u,onFocusOutside:p,onInteractOutside:m,onDismiss:v,children:i.jsx(Mh,{asChild:!0,...x,dir:w.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:O,onEntryFocus:U(d,_=>{w.isUsingKeyboardRef.current||_.preventDefault()}),preventScrollOnEntryFocus:!0,children:i.jsx(co,{role:"menu","aria-orientation":"vertical","data-state":$i(b.open),"data-radix-menu-content":"",dir:w.dir,...y,...h,ref:$,style:{outline:"none",...h.style},onKeyDown:U(h.onKeyDown,_=>{const k=_.target.closest("[data-radix-menu-content]")===_.currentTarget,J=_.ctrlKey||_.altKey||_.metaKey,M=_.key.length===1;k&&(_.key==="Tab"&&_.preventDefault(),!J&&M&&q(_.key));const H=N.current;if(_.target!==H||!xg.includes(_.key))return;_.preventDefault();const ie=E().filter(j=>!j.disabled).map(j=>j.ref.current);hi.includes(_.key)&&ie.reverse(),Vg(ie)}),onBlur:U(e.onBlur,_=>{_.currentTarget.contains(_.target)||(window.clearTimeout(L.current),F.current="")}),onPointerMove:U(e.onPointerMove,en(_=>{const I=_.target,k=z.current!==_.clientX;if(_.currentTarget.contains(I)&&k){const J=_.clientX>z.current?"right":"left";V.current=J,z.current=_.clientX}}))})})})})})})});yi.displayName=Oe;var Dg="MenuGroup",Eo=l.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return i.jsx(Z.div,{role:"group",...r,ref:t})});Eo.displayName=Dg;var Lg="MenuLabel",xi=l.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return i.jsx(Z.div,{...r,ref:t})});xi.displayName=Lg;var Rn="MenuItem",Si="menu.itemSelect",Kn=l.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=l.useRef(null),a=Zt(Rn,e.__scopeMenu),c=So(Rn,e.__scopeMenu),d=re(t,s),f=l.useRef(!1),u=()=>{const p=s.current;if(!n&&p){const m=new CustomEvent(Si,{bubbles:!0,cancelable:!0});p.addEventListener(Si,v=>r==null?void 0:r(v),{once:!0}),Js(p,m),m.defaultPrevented?f.current=!1:a.onClose()}};return i.jsx(Ci,{...o,ref:d,disabled:n,onClick:U(e.onClick,u),onPointerDown:p=>{var m;(m=e.onPointerDown)==null||m.call(e,p),f.current=!0},onPointerUp:U(e.onPointerUp,p=>{var m;f.current||(m=p.currentTarget)==null||m.click()}),onKeyDown:U(e.onKeyDown,p=>{const m=c.searchRef.current!=="";n||m&&p.key===" "||wo.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});Kn.displayName=Rn;var Ci=l.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,a=So(Rn,n),c=mi(n),d=l.useRef(null),f=re(t,d),[u,p]=l.useState(!1),[m,v]=l.useState("");return l.useEffect(()=>{const g=d.current;g&&v((g.textContent??"").trim())},[s.children]),i.jsx(Jt.ItemSlot,{scope:n,disabled:r,textValue:o??m,children:i.jsx(Dh,{asChild:!0,...c,focusable:!r,children:i.jsx(Z.div,{role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:f,onPointerMove:U(e.onPointerMove,en(g=>{r?a.onItemLeave(g):(a.onItemEnter(g),g.defaultPrevented||g.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:U(e.onPointerLeave,en(g=>a.onItemLeave(g))),onFocus:U(e.onFocus,()=>p(!0)),onBlur:U(e.onBlur,()=>p(!1))})})})}),Fg="MenuCheckboxItem",Ei=l.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return i.jsx(_i,{scope:e.__scopeMenu,checked:n,children:i.jsx(Kn,{role:"menuitemcheckbox","aria-checked":Gn(n)?"mixed":n,...o,ref:t,"data-state":To(n),onSelect:U(o.onSelect,()=>r==null?void 0:r(Gn(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Ei.displayName=Fg;var Ni="MenuRadioGroup",[$g,Bg]=ut(Ni,{value:void 0,onValueChange:()=>{}}),Ti=l.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=we(r);return i.jsx($g,{scope:e.__scopeMenu,value:n,onValueChange:s,children:i.jsx(Eo,{...o,ref:t})})});Ti.displayName=Ni;var Ai="MenuRadioItem",Pi=l.forwardRef((e,t)=>{const{value:n,...r}=e,o=Bg(Ai,e.__scopeMenu),s=n===o.value;return i.jsx(_i,{scope:e.__scopeMenu,checked:s,children:i.jsx(Kn,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":To(s),onSelect:U(r.onSelect,()=>{var a;return(a=o.onValueChange)==null?void 0:a.call(o,n)},{checkForDefaultPrevented:!1})})})});Pi.displayName=Ai;var No="MenuItemIndicator",[_i,Ug]=ut(No,{checked:!1}),Ii=l.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=Ug(No,n);return i.jsx(Te,{present:r||Gn(s.checked)||s.checked===!0,children:i.jsx(Z.span,{...o,ref:t,"data-state":To(s.checked)})})});Ii.displayName=No;var zg="MenuSeparator",Oi=l.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return i.jsx(Z.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Oi.displayName=zg;var Hg="MenuArrow",ki=l.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=jn(n);return i.jsx(lo,{...o,...r,ref:t})});ki.displayName=Hg;var Wg="MenuSub",[Ow,Mi]=ut(Wg),Qt="MenuSubTrigger",Di=l.forwardRef((e,t)=>{const n=ft(Qt,e.__scopeMenu),r=Zt(Qt,e.__scopeMenu),o=Mi(Qt,e.__scopeMenu),s=So(Qt,e.__scopeMenu),a=l.useRef(null),{pointerGraceTimerRef:c,onPointerGraceIntentChange:d}=s,f={__scopeMenu:e.__scopeMenu},u=l.useCallback(()=>{a.current&&window.clearTimeout(a.current),a.current=null},[]);return l.useEffect(()=>u,[u]),l.useEffect(()=>{const p=c.current;return()=>{window.clearTimeout(p),d(null)}},[c,d]),i.jsx(yo,{asChild:!0,...f,children:i.jsx(Ci,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":$i(n.open),...e,ref:Fr(t,o.onTriggerChange),onClick:p=>{var m;(m=e.onClick)==null||m.call(e,p),!(e.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:U(e.onPointerMove,en(p=>{s.onItemEnter(p),!p.defaultPrevented&&!e.disabled&&!n.open&&!a.current&&(s.onPointerGraceIntentChange(null),a.current=window.setTimeout(()=>{n.onOpenChange(!0),u()},100))})),onPointerLeave:U(e.onPointerLeave,en(p=>{var v,g;u();const m=(v=n.content)==null?void 0:v.getBoundingClientRect();if(m){const h=(g=n.content)==null?void 0:g.dataset.side,b=h==="right",w=b?-5:5,y=m[b?"left":"right"],x=m[b?"right":"left"];s.onPointerGraceIntentChange({area:[{x:p.clientX+w,y:p.clientY},{x:y,y:m.top},{x,y:m.top},{x,y:m.bottom},{x:y,y:m.bottom}],side:h}),window.clearTimeout(c.current),c.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(p),p.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:U(e.onKeyDown,p=>{var v;const m=s.searchRef.current!=="";e.disabled||m&&p.key===" "||Sg[r.dir].includes(p.key)&&(n.onOpenChange(!0),(v=n.content)==null||v.focus(),p.preventDefault())})})})});Di.displayName=Qt;var Li="MenuSubContent",Fi=l.forwardRef((e,t)=>{const n=vi(Oe,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=ft(Oe,e.__scopeMenu),a=Zt(Oe,e.__scopeMenu),c=Mi(Li,e.__scopeMenu),d=l.useRef(null),f=re(t,d);return i.jsx(Jt.Provider,{scope:e.__scopeMenu,children:i.jsx(Te,{present:r||s.open,children:i.jsx(Jt.Slot,{scope:e.__scopeMenu,children:i.jsx(Co,{id:c.contentId,"aria-labelledby":c.triggerId,...o,ref:f,align:"start",side:a.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:u=>{var p;a.isUsingKeyboardRef.current&&((p=d.current)==null||p.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:U(e.onFocusOutside,u=>{u.target!==c.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:U(e.onEscapeKeyDown,u=>{a.onClose(),u.preventDefault()}),onKeyDown:U(e.onKeyDown,u=>{var v;const p=u.currentTarget.contains(u.target),m=Cg[a.dir].includes(u.key);p&&m&&(s.onOpenChange(!1),(v=c.trigger)==null||v.focus(),u.preventDefault())})})})})})});Fi.displayName=Li;function $i(e){return e?"open":"closed"}function Gn(e){return e==="indeterminate"}function To(e){return Gn(e)?"indeterminate":e?"checked":"unchecked"}function Vg(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function jg(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Rg(e,t,n){const o=t.length>1&&Array.from(t).every(f=>f===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let a=jg(e,Math.max(s,0));o.length===1&&(a=a.filter(f=>f!==n));const d=a.find(f=>f.toLowerCase().startsWith(o.toLowerCase()));return d!==n?d:void 0}function Kg(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,a=t.length-1;s<t.length;a=s++){const c=t[s],d=t[a],f=c.x,u=c.y,p=d.x,m=d.y;u>r!=m>r&&n<(p-f)*(r-u)/(m-u)+f&&(o=!o)}return o}function Gg(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Kg(n,t)}function en(e){return t=>t.pointerType==="mouse"?e(t):void 0}var qg=bi,Xg=yo,Yg=wi,Jg=yi,Zg=Eo,Qg=xi,em=Kn,tm=Ei,nm=Ti,rm=Pi,om=Ii,sm=Oi,am=ki,im=Di,cm=Fi,qn="DropdownMenu",[lm,kw]=Le(qn,[gi]),Se=gi(),[dm,Bi]=lm(qn),Ui=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:a,modal:c=!0}=e,d=Se(t),f=l.useRef(null),[u,p]=Qe({prop:o,defaultProp:s??!1,onChange:a,caller:qn});return i.jsx(dm,{scope:t,triggerId:Fe(),triggerRef:f,contentId:Fe(),open:u,onOpenChange:p,onOpenToggle:l.useCallback(()=>p(m=>!m),[p]),modal:c,children:i.jsx(qg,{...d,open:u,onOpenChange:p,dir:r,modal:c,children:n})})};Ui.displayName=qn;var zi="DropdownMenuTrigger",Hi=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Bi(zi,n),a=Se(n);return i.jsx(Xg,{asChild:!0,...a,children:i.jsx(Z.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...o,ref:Fr(t,s.triggerRef),onPointerDown:U(e.onPointerDown,c=>{!r&&c.button===0&&c.ctrlKey===!1&&(s.onOpenToggle(),s.open||c.preventDefault())}),onKeyDown:U(e.onKeyDown,c=>{r||(["Enter"," "].includes(c.key)&&s.onOpenToggle(),c.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(c.key)&&c.preventDefault())})})})});Hi.displayName=zi;var um="DropdownMenuPortal",Wi=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Se(t);return i.jsx(Yg,{...r,...n})};Wi.displayName=um;var Vi="DropdownMenuContent",ji=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bi(Vi,n),s=Se(n),a=l.useRef(!1);return i.jsx(Jg,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:U(e.onCloseAutoFocus,c=>{var d;a.current||(d=o.triggerRef.current)==null||d.focus(),a.current=!1,c.preventDefault()}),onInteractOutside:U(e.onInteractOutside,c=>{const d=c.detail.originalEvent,f=d.button===0&&d.ctrlKey===!0,u=d.button===2||f;(!o.modal||u)&&(a.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});ji.displayName=Vi;var fm="DropdownMenuGroup",pm=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Se(n);return i.jsx(Zg,{...o,...r,ref:t})});pm.displayName=fm;var hm="DropdownMenuLabel",Ri=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Se(n);return i.jsx(Qg,{...o,...r,ref:t})});Ri.displayName=hm;var gm="DropdownMenuItem",Ki=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Se(n);return i.jsx(em,{...o,...r,ref:t})});Ki.displayName=gm;var mm="DropdownMenuCheckboxItem",Gi=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Se(n);return i.jsx(tm,{...o,...r,ref:t})});Gi.displayName=mm;var bm="DropdownMenuRadioGroup",vm=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Se(n);return i.jsx(nm,{...o,...r,ref:t})});vm.displayName=bm;var wm="DropdownMenuRadioItem",qi=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Se(n);return i.jsx(rm,{...o,...r,ref:t})});qi.displayName=wm;var ym="DropdownMenuItemIndicator",Xi=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Se(n);return i.jsx(om,{...o,...r,ref:t})});Xi.displayName=ym;var xm="DropdownMenuSeparator",Yi=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Se(n);return i.jsx(sm,{...o,...r,ref:t})});Yi.displayName=xm;var Sm="DropdownMenuArrow",Cm=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Se(n);return i.jsx(am,{...o,...r,ref:t})});Cm.displayName=Sm;var Em="DropdownMenuSubTrigger",Ji=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Se(n);return i.jsx(im,{...o,...r,ref:t})});Ji.displayName=Em;var Nm="DropdownMenuSubContent",Zi=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Se(n);return i.jsx(cm,{...o,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Zi.displayName=Nm;var Tm=Ui,Am=Hi,Pm=Wi,Qi=ji,ec=Ri,tc=Ki,nc=Gi,rc=qi,oc=Xi,sc=Yi,ac=Ji,ic=Zi;const _m=Tm,Im=Am,Om=l.forwardRef(({className:e,inset:t,children:n,...r},o)=>i.jsxs(ac,{ref:o,className:A("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...r,children:[n,i.jsx(K.ChevronRight,{className:"ml-auto h-4 w-4"})]}));Om.displayName=ac.displayName;const km=l.forwardRef(({className:e,...t},n)=>i.jsx(ic,{ref:n,className:A("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg 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",e),...t}));km.displayName=ic.displayName;const cc=l.forwardRef(({className:e,sideOffset:t=4,...n},r)=>i.jsx(Pm,{children:i.jsx(Qi,{ref:r,sideOffset:t,className:A("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]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})}));cc.displayName=Qi.displayName;const lc=l.forwardRef(({className:e,inset:t,...n},r)=>i.jsx(tc,{ref:r,className:A("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));lc.displayName=tc.displayName;const Mm=l.forwardRef(({className:e,children:t,checked:n,...r},o)=>i.jsxs(nc,{ref:o,className:A("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[i.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:i.jsx(oc,{children:i.jsx(K.Check,{className:"h-4 w-4"})})}),t]}));Mm.displayName=nc.displayName;const Dm=l.forwardRef(({className:e,children:t,...n},r)=>i.jsxs(rc,{ref:r,className:A("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[i.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:i.jsx(oc,{children:i.jsx(K.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));Dm.displayName=rc.displayName;const Lm=l.forwardRef(({className:e,inset:t,...n},r)=>i.jsx(ec,{ref:r,className:A("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));Lm.displayName=ec.displayName;const Fm=l.forwardRef(({className:e,...t},n)=>i.jsx(sc,{ref:n,className:A("-mx-1 my-1 h-px bg-muted",e),...t}));Fm.displayName=sc.displayName;function tn({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=40,enableFileUpload:s=!0,enableMessageEditing:a=!0,customStyles:c={},onMessageSent:d,onError:f}){const{currentThreadId:u,messages:p,isStreaming:m,streamingAssistantId:v,error:g,send:h,stop:b,lastCheckpointId:w,listCheckpoints:y,navigateToCheckpoint:x,returnToLatest:E}=Lr(),[C,O]=P.useState(""),[N,$]=P.useState(null),[L,F]=P.useState(null),[R,G]=P.useState([]),[V,z]=P.useState(!1),[X,B]=P.useState([]),[q,T]=P.useState(null),_=P.useRef(null),I=P.useRef(null),k=P.useRef(null),[J,M]=P.useState("desktop");P.useEffect(()=>{const D=()=>{const Y=window.innerWidth;M(Y<640?"phone":Y<1024?"tablet":"desktop")};return D(),window.addEventListener("resize",D),()=>window.removeEventListener("resize",D)},[]),P.useEffect(()=>{var D;(D=_.current)==null||D.scrollIntoView({behavior:"smooth"})},[p]),P.useEffect(()=>{var D;n&&((D=I.current)==null||D.focus())},[n]),P.useEffect(()=>{g&&!V&&(f==null||f(g))},[g,V,f]),P.useEffect(()=>{let D=!0;if(!u){B([]),T(null);return}return y(u).then(Y=>{var Ae;if(!D)return;const oe=Y.checkpoints||[];B(oe);const ue=((Ae=oe.slice().sort((Dt,Ce)=>new Date(Ce.createdAt).getTime()-new Date(Dt.createdAt).getTime())[0])==null?void 0:Ae.checkpointId)||null;T(Dt=>Dt??ue)}).catch(()=>{}),()=>{D=!1}},[u,y]),P.useEffect(()=>{w&&T(w)},[w]);const H=D=>{if(D.length>xt)return`Message too long (${D.length}/${xt} characters)`;try{return Hf(D),null}catch(Y){return(Y==null?void 0:Y.message)||"Invalid message"}},de=D=>{const Y=D.content||[],oe=Y.filter(ue=>ue.type==="text").map(ue=>ue.text).join("");if(oe)return oe;try{return JSON.stringify(Y,null,2)}catch{return String(Y)}},ie=D=>{var Dt;if(!X.length)return[];const oe=(((Dt=p[D])==null?void 0:Dt.role)??"user")==="user",ue=oe?D+2:D+1;return X.filter(Ce=>(Ce.messagesLen??-1)>=(oe?ue:0)).filter(Ce=>oe?(Ce.messagesLen??0)>=ue:(Ce.messagesLen??0)===ue).map(Ce=>({checkpoint_id:Ce.checkpointId,checkpoint_ns:Ce.checkpointNs,message_count:Ce.messagesLen??0,last_message_preview:Ce.preview??void 0,ts:new Date(Ce.createdAt).getTime(),isCurrent:Ce.checkpointId===q})).sort((Ce,iw)=>(Ce.ts||0)-(iw.ts||0))},j=D=>{if(D===void 0)return{canGoBack:!1,canGoForward:!1,currentIndex:0,totalBranches:0};const Y=ie(D);if(Y.length<=1)return{canGoBack:!1,canGoForward:!1,currentIndex:0,totalBranches:Y.length};const oe=Math.max(0,Y.findIndex(ue=>ue.isCurrent));return{canGoBack:oe>0,canGoForward:oe<Y.length-1,currentIndex:oe,totalBranches:Y.length}},se=async()=>{const D=C.trim();if(!D&&R.length===0)return;const Y=H(D);if(Y){F(Y);return}try{const oe=window.__editingCheckpointId||q||void 0;await h(D,{checkpointId:oe,payloadExtras:N?{edit:!0,originalMessageId:N}:void 0,attachments:R}),d==null||d(D),O(""),F(null),G([]),delete window.__editingCheckpointId,$(null),I.current&&(I.current.style.height="auto")}catch(oe){const ue=(oe==null?void 0:oe.message)||"Failed to send message";F(ue),f==null||f(ue)}},le=(D,Y)=>{a&&($(D),O(Y),F(null),setTimeout(()=>{I.current&&(I.current.focus(),I.current.style.height="auto",I.current.style.height=I.current.scrollHeight+"px")},0))},ae=async(D,Y)=>{const oe=p.find(Ae=>Ae.id===D);if(!oe){F("Message not found");return}const ue=de(oe);$(D),O(ue),window.__editingCheckpointId=Y,setTimeout(()=>{var Ae;return(Ae=I.current)==null?void 0:Ae.focus()},0)},W=()=>{$(null),O(""),F(null),delete window.__editingCheckpointId,I.current&&(I.current.style.height="auto")},ee=D=>{D.key==="Enter"&&!D.shiftKey?(D.preventDefault(),se()):D.key==="Escape"&&N&&(D.preventDefault(),W())},pe=D=>{const Y=Array.from(D.target.files||[]);G(oe=>[...oe,...Y])},ge=D=>G(Y=>Y.filter((oe,ue)=>D!==ue)),be=async D=>{u&&(await x(D),T(D))},ne=async()=>{await E(),T(null)},ye=`flex flex-col h-full min-w-0 bg-transparent ${e} ${c.container||""}`,ce=`flex-1 min-h-0 min-w-0 overflow-y-auto p-4 space-y-4 bg-transparent ${c.messagesArea||""}`,he=`flex-shrink-0 border-t p-4 bg-transparent ${c.inputArea||""}`;return i.jsxs("div",{className:ye,children:[!!g&&!V&&i.jsxs("div",{className:"bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[i.jsx("span",{children:g}),i.jsx(fe,{variant:"ghost",size:"sm",onClick:()=>z(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:i.jsx(K.X,{size:16})})]}),u&&X.length>0&&i.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 border-b bg-background/50 text-xs",children:[i.jsx(K.GitBranch,{className:"h-4 w-4 opacity-70"}),i.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),i.jsxs("select",{className:"border rounded px-2 py-1 text-xs",value:q??"",onChange:D=>{const Y=D.target.value||null;Y?be(Y):ne()},children:[i.jsx("option",{value:"",children:"Latest"}),X.slice().sort((D,Y)=>new Date(Y.createdAt).getTime()-new Date(D.createdAt).getTime()).map(D=>i.jsxs("option",{value:D.checkpointId,children:[new Date(D.createdAt).toLocaleString(),D.preview?` — ${D.preview.slice(0,30)}`:""]},D.checkpointId))]})]}),i.jsxs("div",{className:ce,style:r?{maxHeight:r}:void 0,children:[p.length===0?i.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground",children:"No messages yet. Start a conversation!"}):p.map((D,Y)=>i.jsx(ra,{message:D,messageIndex:Y,isStreamingMessage:m&&v===D.id,streamingDebounceMs:o,isEditing:N===D.id,showActions:a,showTimestamp:!1,showAgentName:!0,layoutSize:J,truncateToolMessages:!1,toolMessagePreviewLength:200,checkpointBranches:ie(Y),currentCheckpointId:q??void 0,temporalNavigation:j(Y),onSwitchToCheckpoint:be,onReturnToMainThread:ne,onNavigateToPreviousBranch:()=>{const oe=ie(Y),ue=Math.max(0,oe.findIndex(Ae=>Ae.isCurrent));ue>0&&be(oe[ue-1].checkpoint_id)},onNavigateToNextBranch:()=>{const oe=ie(Y),ue=Math.max(0,oe.findIndex(Ae=>Ae.isCurrent));ue>=0&&ue<oe.length-1&&be(oe[ue+1].checkpoint_id)},onEdit:(oe,ue)=>le(oe,ue),onEditFromCheckpoint:ae,onRegenerate:()=>{const oe=[...p].reverse().find(Ae=>Ae.role==="user"),ue=oe?de(oe):"";ue&&h(ue,{checkpointId:q??void 0})},onCancelEdit:W},D.id||Y)),i.jsx("div",{ref:_})]}),i.jsxs("div",{className:he,children:[N&&i.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(K.Edit3,{size:16,className:"text-blue-600"}),i.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),i.jsx(fe,{variant:"ghost",size:"sm",onClick:W,className:"text-blue-600 hover:bg-blue-100",children:i.jsx(K.X,{size:16})})]})}),s&&i.jsxs("div",{className:"mb-3",children:[i.jsx("input",{ref:k,type:"file",multiple:!0,onChange:D=>pe(D),className:"hidden"}),R.length>0&&i.jsx("div",{className:"mb-3 flex flex-wrap gap-2",children:R.map((D,Y)=>i.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 rounded-lg px-3 py-2 text-sm",children:[i.jsx(K.Paperclip,{size:14}),i.jsx("span",{className:"truncate max-w-[150px]",children:D.name}),i.jsx(fe,{variant:"ghost",size:"sm",onClick:()=>ge(Y),className:"h-4 w-4 p-0 text-gray-500 hover:text-red-500","aria-label":`Remove ${D.name}`,children:i.jsx(K.X,{size:12})})]},Y))})]}),L&&i.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:L}),i.jsxs("div",{className:"flex items-end gap-2",children:[s&&i.jsxs(_m,{children:[i.jsx(Im,{asChild:!0,children:i.jsx(fe,{type:"button",size:"icon",variant:"outline",disabled:m,title:"More input actions",className:c.moreButton||"",children:i.jsx(K.Plus,{size:16})})}),i.jsx(cc,{align:"start",sideOffset:6,className:"w-52",children:i.jsxs(lc,{onClick:()=>{var D;return(D=k.current)==null?void 0:D.click()},className:"cursor-pointer",children:[i.jsx(K.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]})})]}),i.jsx("div",{className:"flex-1",children:i.jsx(qs,{ref:I,value:C,onChange:D=>{O(D.target.value),F(null),I.current&&(I.current.style.height="auto",I.current.style.height=`${I.current.scrollHeight}px`)},onKeyDown:ee,placeholder:N?"Edit your message...":t,className:`resize-none min-h-[44px] max-h-[20rem] w-full ${N?"border-blue-400 bg-blue-50":""} ${L?"border-red-400":""} ${c.textarea||""}`,disabled:!1,maxLength:xt,rows:1})}),i.jsx("div",{children:m?i.jsx(fe,{type:"button",onClick:b,size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",children:i.jsx(K.Square,{size:16})}):i.jsx(fe,{type:"button",onClick:se,size:"icon",disabled:!C.trim()&&R.length===0,className:`shrink-0 ${c.sendButton||""}`,title:N?"Save changes":"Send message",children:i.jsx(K.Send,{size:16})})})]}),C.length>xt*.8&&i.jsxs("div",{className:"mt-2 text-xs text-gray-500 text-right",children:[C.length,"/",xt]})]})]})}const nn=l.forwardRef(({className:e,type:t,...n},r)=>i.jsx("input",{type:t,className:A("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:r,...n}));nn.displayName="Input";function Ao(e,[t,n]){return Math.min(n,Math.max(t,e))}function $m(e,t){return l.useReducer((n,r)=>t[n][r]??n,e)}var Po="ScrollArea",[dc,Mw]=Le(Po),[Bm,ke]=dc(Po),uc=l.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...a}=e,[c,d]=l.useState(null),[f,u]=l.useState(null),[p,m]=l.useState(null),[v,g]=l.useState(null),[h,b]=l.useState(null),[w,y]=l.useState(0),[x,E]=l.useState(0),[C,O]=l.useState(!1),[N,$]=l.useState(!1),L=re(t,R=>d(R)),F=Cn(o);return i.jsx(Bm,{scope:n,type:r,dir:F,scrollHideDelay:s,scrollArea:c,viewport:f,onViewportChange:u,content:p,onContentChange:m,scrollbarX:v,onScrollbarXChange:g,scrollbarXEnabled:C,onScrollbarXEnabledChange:O,scrollbarY:h,onScrollbarYChange:b,scrollbarYEnabled:N,onScrollbarYEnabledChange:$,onCornerWidthChange:y,onCornerHeightChange:E,children:i.jsx(Z.div,{dir:F,...a,ref:L,style:{position:"relative","--radix-scroll-area-corner-width":w+"px","--radix-scroll-area-corner-height":x+"px",...e.style}})})});uc.displayName=Po;var fc="ScrollAreaViewport",pc=l.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,a=ke(fc,n),c=l.useRef(null),d=re(t,c,a.onViewportChange);return i.jsxs(i.Fragment,{children:[i.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),i.jsx(Z.div,{"data-radix-scroll-area-viewport":"",...s,ref:d,style:{overflowX:a.scrollbarXEnabled?"scroll":"hidden",overflowY:a.scrollbarYEnabled?"scroll":"hidden",...e.style},children:i.jsx("div",{ref:a.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});pc.displayName=fc;var Xe="ScrollAreaScrollbar",_o=l.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=ke(Xe,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:a}=o,c=e.orientation==="horizontal";return l.useEffect(()=>(c?s(!0):a(!0),()=>{c?s(!1):a(!1)}),[c,s,a]),o.type==="hover"?i.jsx(Um,{...r,ref:t,forceMount:n}):o.type==="scroll"?i.jsx(zm,{...r,ref:t,forceMount:n}):o.type==="auto"?i.jsx(hc,{...r,ref:t,forceMount:n}):o.type==="always"?i.jsx(Io,{...r,ref:t}):null});_o.displayName=Xe;var Um=l.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=ke(Xe,e.__scopeScrollArea),[s,a]=l.useState(!1);return l.useEffect(()=>{const c=o.scrollArea;let d=0;if(c){const f=()=>{window.clearTimeout(d),a(!0)},u=()=>{d=window.setTimeout(()=>a(!1),o.scrollHideDelay)};return c.addEventListener("pointerenter",f),c.addEventListener("pointerleave",u),()=>{window.clearTimeout(d),c.removeEventListener("pointerenter",f),c.removeEventListener("pointerleave",u)}}},[o.scrollArea,o.scrollHideDelay]),i.jsx(Te,{present:n||s,children:i.jsx(hc,{"data-state":s?"visible":"hidden",...r,ref:t})})}),zm=l.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=ke(Xe,e.__scopeScrollArea),s=e.orientation==="horizontal",a=Zn(()=>d("SCROLL_END"),100),[c,d]=$m("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return l.useEffect(()=>{if(c==="idle"){const f=window.setTimeout(()=>d("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(f)}},[c,o.scrollHideDelay,d]),l.useEffect(()=>{const f=o.viewport,u=s?"scrollLeft":"scrollTop";if(f){let p=f[u];const m=()=>{const v=f[u];p!==v&&(d("SCROLL"),a()),p=v};return f.addEventListener("scroll",m),()=>f.removeEventListener("scroll",m)}},[o.viewport,s,d,a]),i.jsx(Te,{present:n||c!=="hidden",children:i.jsx(Io,{"data-state":c==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:U(e.onPointerEnter,()=>d("POINTER_ENTER")),onPointerLeave:U(e.onPointerLeave,()=>d("POINTER_LEAVE"))})})}),hc=l.forwardRef((e,t)=>{const n=ke(Xe,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,a]=l.useState(!1),c=e.orientation==="horizontal",d=Zn(()=>{if(n.viewport){const f=n.viewport.offsetWidth<n.viewport.scrollWidth,u=n.viewport.offsetHeight<n.viewport.scrollHeight;a(c?f:u)}},10);return Ot(n.viewport,d),Ot(n.content,d),i.jsx(Te,{present:r||s,children:i.jsx(Io,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Io=l.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=ke(Xe,e.__scopeScrollArea),s=l.useRef(null),a=l.useRef(0),[c,d]=l.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),f=wc(c.viewport,c.content),u={...r,sizes:c,onSizesChange:d,hasThumb:f>0&&f<1,onThumbChange:m=>s.current=m,onThumbPointerUp:()=>a.current=0,onThumbPointerDown:m=>a.current=m};function p(m,v){return Km(m,a.current,c,v)}return n==="horizontal"?i.jsx(Hm,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const m=o.viewport.scrollLeft,v=yc(m,c,o.dir);s.current.style.transform=`translate3d(${v}px, 0, 0)`}},onWheelScroll:m=>{o.viewport&&(o.viewport.scrollLeft=m)},onDragScroll:m=>{o.viewport&&(o.viewport.scrollLeft=p(m,o.dir))}}):n==="vertical"?i.jsx(Wm,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const m=o.viewport.scrollTop,v=yc(m,c);s.current.style.transform=`translate3d(0, ${v}px, 0)`}},onWheelScroll:m=>{o.viewport&&(o.viewport.scrollTop=m)},onDragScroll:m=>{o.viewport&&(o.viewport.scrollTop=p(m))}}):null}),Hm=l.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=ke(Xe,e.__scopeScrollArea),[a,c]=l.useState(),d=l.useRef(null),f=re(t,d,s.onScrollbarXChange);return l.useEffect(()=>{d.current&&c(getComputedStyle(d.current))},[d]),i.jsx(mc,{"data-orientation":"horizontal",...o,ref:f,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Jn(n)+"px",...e.style},onThumbPointerDown:u=>e.onThumbPointerDown(u.x),onDragScroll:u=>e.onDragScroll(u.x),onWheelScroll:(u,p)=>{if(s.viewport){const m=s.viewport.scrollLeft+u.deltaX;e.onWheelScroll(m),Sc(m,p)&&u.preventDefault()}},onResize:()=>{d.current&&s.viewport&&a&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:d.current.clientWidth,paddingStart:Yn(a.paddingLeft),paddingEnd:Yn(a.paddingRight)}})}})}),Wm=l.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=ke(Xe,e.__scopeScrollArea),[a,c]=l.useState(),d=l.useRef(null),f=re(t,d,s.onScrollbarYChange);return l.useEffect(()=>{d.current&&c(getComputedStyle(d.current))},[d]),i.jsx(mc,{"data-orientation":"vertical",...o,ref:f,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Jn(n)+"px",...e.style},onThumbPointerDown:u=>e.onThumbPointerDown(u.y),onDragScroll:u=>e.onDragScroll(u.y),onWheelScroll:(u,p)=>{if(s.viewport){const m=s.viewport.scrollTop+u.deltaY;e.onWheelScroll(m),Sc(m,p)&&u.preventDefault()}},onResize:()=>{d.current&&s.viewport&&a&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:d.current.clientHeight,paddingStart:Yn(a.paddingTop),paddingEnd:Yn(a.paddingBottom)}})}})}),[Vm,gc]=dc(Xe),mc=l.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:a,onThumbPointerDown:c,onThumbPositionChange:d,onDragScroll:f,onWheelScroll:u,onResize:p,...m}=e,v=ke(Xe,n),[g,h]=l.useState(null),b=re(t,L=>h(L)),w=l.useRef(null),y=l.useRef(""),x=v.viewport,E=r.content-r.viewport,C=we(u),O=we(d),N=Zn(p,10);function $(L){if(w.current){const F=L.clientX-w.current.left,R=L.clientY-w.current.top;f({x:F,y:R})}}return l.useEffect(()=>{const L=F=>{const R=F.target;(g==null?void 0:g.contains(R))&&C(F,E)};return document.addEventListener("wheel",L,{passive:!1}),()=>document.removeEventListener("wheel",L,{passive:!1})},[x,g,E,C]),l.useEffect(O,[r,O]),Ot(g,N),Ot(v.content,N),i.jsx(Vm,{scope:n,scrollbar:g,hasThumb:o,onThumbChange:we(s),onThumbPointerUp:we(a),onThumbPositionChange:O,onThumbPointerDown:we(c),children:i.jsx(Z.div,{...m,ref:b,style:{position:"absolute",...m.style},onPointerDown:U(e.onPointerDown,L=>{L.button===0&&(L.target.setPointerCapture(L.pointerId),w.current=g.getBoundingClientRect(),y.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",v.viewport&&(v.viewport.style.scrollBehavior="auto"),$(L))}),onPointerMove:U(e.onPointerMove,$),onPointerUp:U(e.onPointerUp,L=>{const F=L.target;F.hasPointerCapture(L.pointerId)&&F.releasePointerCapture(L.pointerId),document.body.style.webkitUserSelect=y.current,v.viewport&&(v.viewport.style.scrollBehavior=""),w.current=null})})})}),Xn="ScrollAreaThumb",bc=l.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=gc(Xn,e.__scopeScrollArea);return i.jsx(Te,{present:n||o.hasThumb,children:i.jsx(jm,{ref:t,...r})})}),jm=l.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=ke(Xn,n),a=gc(Xn,n),{onThumbPositionChange:c}=a,d=re(t,p=>a.onThumbChange(p)),f=l.useRef(void 0),u=Zn(()=>{f.current&&(f.current(),f.current=void 0)},100);return l.useEffect(()=>{const p=s.viewport;if(p){const m=()=>{if(u(),!f.current){const v=Gm(p,c);f.current=v,c()}};return c(),p.addEventListener("scroll",m),()=>p.removeEventListener("scroll",m)}},[s.viewport,u,c]),i.jsx(Z.div,{"data-state":a.hasThumb?"visible":"hidden",...o,ref:d,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:U(e.onPointerDownCapture,p=>{const v=p.target.getBoundingClientRect(),g=p.clientX-v.left,h=p.clientY-v.top;a.onThumbPointerDown({x:g,y:h})}),onPointerUp:U(e.onPointerUp,a.onThumbPointerUp)})});bc.displayName=Xn;var Oo="ScrollAreaCorner",vc=l.forwardRef((e,t)=>{const n=ke(Oo,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?i.jsx(Rm,{...e,ref:t}):null});vc.displayName=Oo;var Rm=l.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=ke(Oo,n),[s,a]=l.useState(0),[c,d]=l.useState(0),f=!!(s&&c);return Ot(o.scrollbarX,()=>{var p;const u=((p=o.scrollbarX)==null?void 0:p.offsetHeight)||0;o.onCornerHeightChange(u),d(u)}),Ot(o.scrollbarY,()=>{var p;const u=((p=o.scrollbarY)==null?void 0:p.offsetWidth)||0;o.onCornerWidthChange(u),a(u)}),f?i.jsx(Z.div,{...r,ref:t,style:{width:s,height:c,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Yn(e){return e?parseInt(e,10):0}function wc(e,t){const n=e/t;return isNaN(n)?0:n}function Jn(e){const t=wc(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function Km(e,t,n,r="ltr"){const o=Jn(n),s=o/2,a=t||s,c=o-a,d=n.scrollbar.paddingStart+a,f=n.scrollbar.size-n.scrollbar.paddingEnd-c,u=n.content-n.viewport,p=r==="ltr"?[0,u]:[u*-1,0];return xc([d,f],p)(e)}function yc(e,t,n="ltr"){const r=Jn(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,a=t.content-t.viewport,c=s-r,d=n==="ltr"?[0,a]:[a*-1,0],f=Ao(e,d);return xc([0,a],[0,c])(f)}function xc(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}function Sc(e,t){return e>0&&e<t}var Gm=(e,t=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},r=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},a=n.left!==s.left,c=n.top!==s.top;(a||c)&&t(),n=s,r=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(r)};function Zn(e,t){const n=we(e),r=l.useRef(0);return l.useEffect(()=>()=>window.clearTimeout(r.current),[]),l.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Ot(e,t){const n=we(t);ve(()=>{let r=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return o.observe(e),()=>{window.cancelAnimationFrame(r),o.unobserve(e)}}},[e,n])}var Cc=uc,qm=pc,Xm=vc;const Ec=l.forwardRef(({className:e,children:t,...n},r)=>i.jsxs(Cc,{ref:r,className:A("relative overflow-hidden",e),...n,children:[i.jsx(qm,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),i.jsx(Nc,{}),i.jsx(Xm,{})]}));Ec.displayName=Cc.displayName;const Nc=l.forwardRef(({className:e,orientation:t="vertical",...n},r)=>i.jsx(_o,{ref:r,orientation:t,className:A("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:i.jsx(bc,{className:"relative flex-1 rounded-full bg-border"})}));Nc.displayName=_o.displayName;function Qn({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:a=null,navigateToThread:c,onThreadSelect:d,onThreadCreate:f,onThreadDelete:u}){const{loadThread:p,threads:m,refreshThreads:v,currentThreadId:g,createThread:h,deleteThread:b,renameThread:w}=Lr(),[y,x]=P.useState(m??[]),[E,C]=P.useState(!1),[O,N]=P.useState(null),[$,L]=P.useState(null),[F,R]=P.useState(""),[G,V]=P.useState(!1);P.useEffect(()=>{x(m??[])},[m]);const z=async M=>{try{await p(M),c==null||c(M),d==null||d(M)}catch(H){console.error("Failed to select thread:",H)}},X=async()=>{try{V(!0);const M=await h();f==null||f(M),c==null||c(M)}catch(M){console.error("Failed to create thread:",M)}finally{V(!1)}},B=async(M,H)=>{if(H.stopPropagation(),!!confirm("Delete this thread?"))try{await b(M),u==null||u(M)}catch(de){console.error("Failed to delete thread:",de)}},q=(M,H)=>{H.stopPropagation(),L(M.threadId),R(M.title||`Thread ${M.threadId.slice(0,8)}`)},T=async M=>{if(F.trim())try{await w(M,F.trim()),L(null),R("")}catch(H){console.error("Failed to update title:",H)}},_=()=>{L(null),R("")},I=(M,H)=>{M.key==="Enter"?T(H):M.key==="Escape"&&_()},k=M=>{if(!M)return"";try{const H=new Date(M),ie=new Date().getTime()-H.getTime(),j=Math.floor(ie/(1e3*60*60*24));return j===0?H.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):j===1?"Yesterday":j<7?`${j} days ago`:H.toLocaleDateString()}catch{return""}},J=M=>M.title||`Thread ${M.threadId.slice(0,8)}`;return i.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&i.jsx("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:i.jsx(fe,{onClick:X,disabled:G||E,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:G?"Creating...":"New Chat",children:i.jsx(K.MessageSquarePlus,{size:20})})}),i.jsx(Ec,{className:`flex-1 ${s.threadList||""}`,style:{maxHeight:o},children:i.jsx("div",{className:"p-2 space-y-1 pb-4",children:E?i.jsx("div",{className:"text-center py-8 text-slate-400",children:"Loading…"}):y.length===0?i.jsxs("div",{className:"text-center py-8 text-slate-400",children:[i.jsx(K.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),i.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):y.slice().sort((M,H)=>new Date(H.updatedAt||H.createdAt||"").getTime()-new Date(M.updatedAt||M.createdAt||"").getTime()).map(M=>i.jsxs("div",{onClick:()=>z(M.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(a??g)===M.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("div",{className:"flex-1 min-w-0",children:$===M.threadId?i.jsxs("div",{className:"flex items-center gap-2",onClick:H=>H.stopPropagation(),children:[i.jsx(nn,{value:F,onChange:H=>R(H.target.value),onKeyDown:H=>I(H,M.threadId),className:"h-6 text-sm",autoFocus:!0}),i.jsx(fe,{variant:"ghost",size:"sm",onClick:()=>T(M.threadId),className:"h-6 w-6 p-0",children:i.jsx(K.Check,{size:12})}),i.jsx(fe,{variant:"ghost",size:"sm",onClick:_,className:"h-6 w-6 p-0",children:i.jsx(K.X,{size:12})})]}):i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:J(M)}),i.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[i.jsx(K.Calendar,{size:10}),i.jsx("span",{children:k(M.updatedAt||M.createdAt)})]})]})}),i.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&$!==M.threadId&&i.jsx(fe,{variant:"ghost",size:"sm",onClick:H=>q(M,H),className:"h-6 w-6 p-0",title:"Edit title",children:i.jsx(K.Edit3,{size:12})}),n&&i.jsx(fe,{variant:"ghost",size:"sm",onClick:H=>B(M.threadId,H),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:i.jsx(K.Trash2,{size:12})})]})]}),a===M.threadId&&i.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},M.threadId))})})]})}const Tc=P.createContext(null);function Ym({children:e,basePath:t="/chat"}){const n=P.useMemo(()=>t?t==="/"?"":t.endsWith("/")?t.slice(0,-1):t:"/chat",[t]),r={basePath:n,buildThreadPath:o=>`${n}/${o}`,buildBasePath:()=>n};return i.jsx(Tc.Provider,{value:r,children:e})}function Jm(){const e=P.useContext(Tc);return e||{basePath:"/chat",buildThreadPath:t=>`/chat/${t}`,buildBasePath:()=>"/chat"}}const Ac={BASE_URL:"/",DEV:!1,MODE:"library",PROD:!0,SSR:!1};function rn(e){var o;const t=typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:br&&br.tagName.toUpperCase()==="SCRIPT"&&br.src||new URL("index.umd.js",document.baseURI).href}<"u"&&Ac?Ac[e]:void 0,n=(o=globalThis==null?void 0:globalThis.process)==null?void 0:o.env,r=n?n[e]:void 0;return(t??r)||void 0}function Zm(){return rn("VITE_API_BASE_URL")||rn("NEXT_PUBLIC_API_BASE_URL")||void 0}function Qm(){return rn("VITE_API_KEY")||rn("NEXT_PUBLIC_API_KEY")||rn("VITE_AUTH_TOKEN")||void 0}function Pc(){const e=Zm(),t=Qm(),n={};return e&&(n.baseUrl=e),t&&(n.apiKey=t),n}function _c(){const e=Pc(),t=Ye.getAuthToken();return{apiBaseUrl:e.baseUrl||Ye.baseUrl||"http://localhost:8000",apiKey:t||e.apiKey||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,truncateToolMessages:!0,toolMessagePreviewLength:200,darkMode:!1,enableSound:!1,messageHistory:100}}const Ic="chat-settings";function eb(){try{const e=localStorage.getItem(Ic);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function tb(e){try{localStorage.setItem(Ic,JSON.stringify(e)),e.apiKey&&Ye.setAuthToken(e.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function nb(){const e=_c(),t=eb(),n=Ye.getAuthToken();return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Ye.baseUrl||t.apiBaseUrl||e.apiBaseUrl}}function rb(e){e.apiKey&&Ye.setAuthToken(e.apiKey),tb(e)}const ko=768;function ob(){const[e,t]=l.useState(void 0);return l.useEffect(()=>{const n=window.matchMedia(`(max-width: ${ko-1}px)`),r=()=>{t(window.innerWidth<ko)};return n.addEventListener("change",r),t(window.innerWidth<ko),()=>n.removeEventListener("change",r)},[]),!!e}var sb="Separator",Oc="horizontal",ab=["horizontal","vertical"],kc=l.forwardRef((e,t)=>{const{decorative:n,orientation:r=Oc,...o}=e,s=ib(r)?r:Oc,c=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return i.jsx(Z.div,{"data-orientation":s,...c,...o,ref:t})});kc.displayName=sb;function ib(e){return ab.includes(e)}var Mc=kc;const Mo=l.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>i.jsx(Mc,{ref:o,decorative:n,orientation:t,className:A("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Mo.displayName=Mc.displayName;var er="Dialog",[Dc,Dw]=Le(er),[cb,Ue]=Dc(er),Lc=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:a=!0}=e,c=l.useRef(null),d=l.useRef(null),[f,u]=Qe({prop:r,defaultProp:o??!1,onChange:s,caller:er});return i.jsx(cb,{scope:t,triggerRef:c,contentRef:d,contentId:Fe(),titleId:Fe(),descriptionId:Fe(),open:f,onOpenChange:u,onOpenToggle:l.useCallback(()=>u(p=>!p),[u]),modal:a,children:n})};Lc.displayName=er;var Fc="DialogTrigger",$c=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Ue(Fc,n),s=re(t,o.triggerRef);return i.jsx(Z.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Fo(o.open),...r,ref:s,onClick:U(e.onClick,o.onOpenToggle)})});$c.displayName=Fc;var Do="DialogPortal",[lb,Bc]=Dc(Do,{forceMount:void 0}),Uc=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=Ue(Do,t);return i.jsx(lb,{scope:t,forceMount:n,children:l.Children.map(r,a=>i.jsx(Te,{present:n||s.open,children:i.jsx(Ln,{asChild:!0,container:o,children:a})}))})};Uc.displayName=Do;var tr="DialogOverlay",zc=l.forwardRef((e,t)=>{const n=Bc(tr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=Ue(tr,e.__scopeDialog);return s.modal?i.jsx(Te,{present:r||s.open,children:i.jsx(ub,{...o,ref:t})}):null});zc.displayName=tr;var db=Pe.createSlot("DialogOverlay.RemoveScroll"),ub=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Ue(tr,n);return i.jsx(Vn,{as:db,allowPinchZoom:!0,shards:[o.contentRef],children:i.jsx(Z.div,{"data-state":Fo(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),pt="DialogContent",Hc=l.forwardRef((e,t)=>{const n=Bc(pt,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=Ue(pt,e.__scopeDialog);return i.jsx(Te,{present:r||s.open,children:s.modal?i.jsx(fb,{...o,ref:t}):i.jsx(pb,{...o,ref:t})})});Hc.displayName=pt;var fb=l.forwardRef((e,t)=>{const n=Ue(pt,e.__scopeDialog),r=l.useRef(null),o=re(t,n.contentRef,r);return l.useEffect(()=>{const s=r.current;if(s)return ho(s)},[]),i.jsx(Wc,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:U(e.onCloseAutoFocus,s=>{var a;s.preventDefault(),(a=n.triggerRef.current)==null||a.focus()}),onPointerDownOutside:U(e.onPointerDownOutside,s=>{const a=s.detail.originalEvent,c=a.button===0&&a.ctrlKey===!0;(a.button===2||c)&&s.preventDefault()}),onFocusOutside:U(e.onFocusOutside,s=>s.preventDefault())})}),pb=l.forwardRef((e,t)=>{const n=Ue(pt,e.__scopeDialog),r=l.useRef(!1),o=l.useRef(!1);return i.jsx(Wc,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var a,c;(a=e.onCloseAutoFocus)==null||a.call(e,s),s.defaultPrevented||(r.current||(c=n.triggerRef.current)==null||c.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var d,f;(d=e.onInteractOutside)==null||d.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const a=s.target;((f=n.triggerRef.current)==null?void 0:f.contains(a))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),Wc=l.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...a}=e,c=Ue(pt,n),d=l.useRef(null),f=re(t,d);return jr(),i.jsxs(i.Fragment,{children:[i.jsx(En,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:i.jsx(Rt,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionId,"aria-labelledby":c.titleId,"data-state":Fo(c.open),...a,ref:f,onDismiss:()=>c.onOpenChange(!1)})}),i.jsxs(i.Fragment,{children:[i.jsx(hb,{titleId:c.titleId}),i.jsx(mb,{contentRef:d,descriptionId:c.descriptionId})]})]})}),Lo="DialogTitle",Vc=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Ue(Lo,n);return i.jsx(Z.h2,{id:o.titleId,...r,ref:t})});Vc.displayName=Lo;var jc="DialogDescription",Rc=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Ue(jc,n);return i.jsx(Z.p,{id:o.descriptionId,...r,ref:t})});Rc.displayName=jc;var Kc="DialogClose",Gc=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Ue(Kc,n);return i.jsx(Z.button,{type:"button",...r,ref:t,onClick:U(e.onClick,()=>o.onOpenChange(!1))})});Gc.displayName=Kc;function Fo(e){return e?"open":"closed"}var qc="DialogTitleWarning",[Lw,Xc]=df(qc,{contentName:pt,titleName:Lo,docsSlug:"dialog"}),hb=({titleId:e})=>{const t=Xc(qc),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
58
+ `)},mg=0,It=[];function bg(e){var t=l.useRef([]),n=l.useRef([0,0]),r=l.useRef(),o=l.useState(mg++)[0],s=l.useState(ai)[0],a=l.useRef(e);l.useEffect(function(){a.current=e},[e]),l.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var h=Bh([e.lockRef.current],(e.shards||[]).map(pi),!0).filter(Boolean);return h.forEach(function(b){return b.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),h.forEach(function(b){return b.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var c=l.useCallback(function(h,b){if("touches"in h&&h.touches.length===2||h.type==="wheel"&&h.ctrlKey)return!a.current.allowPinchZoom;var w=Wn(h),y=n.current,x="deltaX"in h?h.deltaX:y[0]-w[0],E="deltaY"in h?h.deltaY:y[1]-w[1],C,O=h.target,N=Math.abs(x)>Math.abs(E)?"h":"v";if("touches"in h&&N==="h"&&O.type==="range")return!1;var $=li(N,O);if(!$)return!0;if($?C=N:(C=N==="v"?"h":"v",$=li(N,O)),!$)return!1;if(!r.current&&"changedTouches"in h&&(x||E)&&(r.current=C),!C)return!0;var L=r.current||C;return pg(L,b,h,L==="h"?x:E)},[]),d=l.useCallback(function(h){var b=h;if(!(!It.length||It[It.length-1]!==s)){var w="deltaY"in b?fi(b):Wn(b),y=t.current.filter(function(C){return C.name===b.type&&(C.target===b.target||b.target===C.shadowParent)&&hg(C.delta,w)})[0];if(y&&y.should){b.cancelable&&b.preventDefault();return}if(!y){var x=(a.current.shards||[]).map(pi).filter(Boolean).filter(function(C){return C.contains(b.target)}),E=x.length>0?c(b,x[0]):!a.current.noIsolation;E&&b.cancelable&&b.preventDefault()}}},[]),f=l.useCallback(function(h,b,w,y){var x={name:h,delta:b,target:w,should:y,shadowParent:vg(w)};t.current.push(x),setTimeout(function(){t.current=t.current.filter(function(E){return E!==x})},1)},[]),u=l.useCallback(function(h){n.current=Wn(h),r.current=void 0},[]),p=l.useCallback(function(h){f(h.type,fi(h),h.target,c(h,e.lockRef.current))},[]),m=l.useCallback(function(h){f(h.type,Wn(h),h.target,c(h,e.lockRef.current))},[]);l.useEffect(function(){return It.push(s),e.setCallbacks({onScrollCapture:p,onWheelCapture:p,onTouchMoveCapture:m}),document.addEventListener("wheel",d,_t),document.addEventListener("touchmove",d,_t),document.addEventListener("touchstart",u,_t),function(){It=It.filter(function(h){return h!==s}),document.removeEventListener("wheel",d,_t),document.removeEventListener("touchmove",d,_t),document.removeEventListener("touchstart",u,_t)}},[]);var v=e.removeScrollBar,g=e.inert;return l.createElement(l.Fragment,null,g?l.createElement(s,{styles:gg(o)}):null,v?l.createElement(ag,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function vg(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const wg=Gh(si,bg);var Vn=l.forwardRef(function(e,t){return l.createElement(zn,qe({},e,{ref:t,sideCar:wg}))});Vn.classNames=zn.classNames;var wo=["Enter"," "],yg=["ArrowDown","PageUp","Home"],hi=["ArrowUp","PageDown","End"],xg=[...yg,...hi],Sg={ltr:[...wo,"ArrowRight"],rtl:[...wo,"ArrowLeft"]},Cg={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Yt="Menu",[Jt,Eg,Ng]=Hr(Yt),[ut,gi]=Le(Yt,[Ng,Tt,Ya]),jn=Tt(),mi=Ya(),[Tg,ft]=ut(Yt),[Ag,Zt]=ut(Yt),bi=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:a=!0}=e,c=jn(t),[d,f]=l.useState(null),u=l.useRef(!1),p=we(s),m=Cn(o);return l.useEffect(()=>{const v=()=>{u.current=!0,document.addEventListener("pointerdown",g,{capture:!0,once:!0}),document.addEventListener("pointermove",g,{capture:!0,once:!0})},g=()=>u.current=!1;return document.addEventListener("keydown",v,{capture:!0}),()=>{document.removeEventListener("keydown",v,{capture:!0}),document.removeEventListener("pointerdown",g,{capture:!0}),document.removeEventListener("pointermove",g,{capture:!0})}},[]),i.jsx(ao,{...c,children:i.jsx(Tg,{scope:t,open:n,onOpenChange:p,content:d,onContentChange:f,children:i.jsx(Ag,{scope:t,onClose:l.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:u,dir:m,modal:a,children:r})})})};bi.displayName=Yt;var Pg="MenuAnchor",yo=l.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=jn(n);return i.jsx(io,{...o,...r,ref:t})});yo.displayName=Pg;var xo="MenuPortal",[_g,vi]=ut(xo,{forceMount:void 0}),wi=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=ft(xo,t);return i.jsx(_g,{scope:t,forceMount:n,children:i.jsx(Te,{present:n||s.open,children:i.jsx(Ln,{asChild:!0,container:o,children:r})})})};wi.displayName=xo;var Oe="MenuContent",[Ig,So]=ut(Oe),yi=l.forwardRef((e,t)=>{const n=vi(Oe,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=ft(Oe,e.__scopeMenu),a=Zt(Oe,e.__scopeMenu);return i.jsx(Jt.Provider,{scope:e.__scopeMenu,children:i.jsx(Te,{present:r||s.open,children:i.jsx(Jt.Slot,{scope:e.__scopeMenu,children:a.modal?i.jsx(Og,{...o,ref:t}):i.jsx(kg,{...o,ref:t})})})})}),Og=l.forwardRef((e,t)=>{const n=ft(Oe,e.__scopeMenu),r=l.useRef(null),o=re(t,r);return l.useEffect(()=>{const s=r.current;if(s)return ho(s)},[]),i.jsx(Co,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:U(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),kg=l.forwardRef((e,t)=>{const n=ft(Oe,e.__scopeMenu);return i.jsx(Co,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),Mg=Pe.createSlot("MenuContent.ScrollLock"),Co=l.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:a,disableOutsidePointerEvents:c,onEntryFocus:d,onEscapeKeyDown:f,onPointerDownOutside:u,onFocusOutside:p,onInteractOutside:m,onDismiss:v,disableOutsideScroll:g,...h}=e,b=ft(Oe,n),w=Zt(Oe,n),y=jn(n),x=mi(n),E=Eg(n),[C,O]=l.useState(null),N=l.useRef(null),$=re(t,N,b.onContentChange),L=l.useRef(0),F=l.useRef(""),R=l.useRef(0),G=l.useRef(null),V=l.useRef("right"),z=l.useRef(0),X=g?Vn:l.Fragment,B=g?{as:Mg,allowPinchZoom:!0}:void 0,q=_=>{var j,se;const I=F.current+_,k=E().filter(le=>!le.disabled),J=document.activeElement,M=(j=k.find(le=>le.ref.current===J))==null?void 0:j.textValue,H=k.map(le=>le.textValue),de=Rg(H,I,M),ie=(se=k.find(le=>le.textValue===de))==null?void 0:se.ref.current;(function le(ae){F.current=ae,window.clearTimeout(L.current),ae!==""&&(L.current=window.setTimeout(()=>le(""),1e3))})(I),ie&&setTimeout(()=>ie.focus())};l.useEffect(()=>()=>window.clearTimeout(L.current),[]),jr();const T=l.useCallback(_=>{var k,J;return V.current===((k=G.current)==null?void 0:k.side)&&Gg(_,(J=G.current)==null?void 0:J.area)},[]);return i.jsx(Ig,{scope:n,searchRef:F,onItemEnter:l.useCallback(_=>{T(_)&&_.preventDefault()},[T]),onItemLeave:l.useCallback(_=>{var I;T(_)||((I=N.current)==null||I.focus(),O(null))},[T]),onTriggerLeave:l.useCallback(_=>{T(_)&&_.preventDefault()},[T]),pointerGraceTimerRef:R,onPointerGraceIntentChange:l.useCallback(_=>{G.current=_},[]),children:i.jsx(X,{...B,children:i.jsx(En,{asChild:!0,trapped:o,onMountAutoFocus:U(s,_=>{var I;_.preventDefault(),(I=N.current)==null||I.focus({preventScroll:!0})}),onUnmountAutoFocus:a,children:i.jsx(Rt,{asChild:!0,disableOutsidePointerEvents:c,onEscapeKeyDown:f,onPointerDownOutside:u,onFocusOutside:p,onInteractOutside:m,onDismiss:v,children:i.jsx(Mh,{asChild:!0,...x,dir:w.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:O,onEntryFocus:U(d,_=>{w.isUsingKeyboardRef.current||_.preventDefault()}),preventScrollOnEntryFocus:!0,children:i.jsx(co,{role:"menu","aria-orientation":"vertical","data-state":$i(b.open),"data-radix-menu-content":"",dir:w.dir,...y,...h,ref:$,style:{outline:"none",...h.style},onKeyDown:U(h.onKeyDown,_=>{const k=_.target.closest("[data-radix-menu-content]")===_.currentTarget,J=_.ctrlKey||_.altKey||_.metaKey,M=_.key.length===1;k&&(_.key==="Tab"&&_.preventDefault(),!J&&M&&q(_.key));const H=N.current;if(_.target!==H||!xg.includes(_.key))return;_.preventDefault();const ie=E().filter(j=>!j.disabled).map(j=>j.ref.current);hi.includes(_.key)&&ie.reverse(),Vg(ie)}),onBlur:U(e.onBlur,_=>{_.currentTarget.contains(_.target)||(window.clearTimeout(L.current),F.current="")}),onPointerMove:U(e.onPointerMove,en(_=>{const I=_.target,k=z.current!==_.clientX;if(_.currentTarget.contains(I)&&k){const J=_.clientX>z.current?"right":"left";V.current=J,z.current=_.clientX}}))})})})})})})});yi.displayName=Oe;var Dg="MenuGroup",Eo=l.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return i.jsx(Z.div,{role:"group",...r,ref:t})});Eo.displayName=Dg;var Lg="MenuLabel",xi=l.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return i.jsx(Z.div,{...r,ref:t})});xi.displayName=Lg;var Rn="MenuItem",Si="menu.itemSelect",Kn=l.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=l.useRef(null),a=Zt(Rn,e.__scopeMenu),c=So(Rn,e.__scopeMenu),d=re(t,s),f=l.useRef(!1),u=()=>{const p=s.current;if(!n&&p){const m=new CustomEvent(Si,{bubbles:!0,cancelable:!0});p.addEventListener(Si,v=>r==null?void 0:r(v),{once:!0}),Js(p,m),m.defaultPrevented?f.current=!1:a.onClose()}};return i.jsx(Ci,{...o,ref:d,disabled:n,onClick:U(e.onClick,u),onPointerDown:p=>{var m;(m=e.onPointerDown)==null||m.call(e,p),f.current=!0},onPointerUp:U(e.onPointerUp,p=>{var m;f.current||(m=p.currentTarget)==null||m.click()}),onKeyDown:U(e.onKeyDown,p=>{const m=c.searchRef.current!=="";n||m&&p.key===" "||wo.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});Kn.displayName=Rn;var Ci=l.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,a=So(Rn,n),c=mi(n),d=l.useRef(null),f=re(t,d),[u,p]=l.useState(!1),[m,v]=l.useState("");return l.useEffect(()=>{const g=d.current;g&&v((g.textContent??"").trim())},[s.children]),i.jsx(Jt.ItemSlot,{scope:n,disabled:r,textValue:o??m,children:i.jsx(Dh,{asChild:!0,...c,focusable:!r,children:i.jsx(Z.div,{role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:f,onPointerMove:U(e.onPointerMove,en(g=>{r?a.onItemLeave(g):(a.onItemEnter(g),g.defaultPrevented||g.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:U(e.onPointerLeave,en(g=>a.onItemLeave(g))),onFocus:U(e.onFocus,()=>p(!0)),onBlur:U(e.onBlur,()=>p(!1))})})})}),Fg="MenuCheckboxItem",Ei=l.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return i.jsx(_i,{scope:e.__scopeMenu,checked:n,children:i.jsx(Kn,{role:"menuitemcheckbox","aria-checked":Gn(n)?"mixed":n,...o,ref:t,"data-state":To(n),onSelect:U(o.onSelect,()=>r==null?void 0:r(Gn(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Ei.displayName=Fg;var Ni="MenuRadioGroup",[$g,Bg]=ut(Ni,{value:void 0,onValueChange:()=>{}}),Ti=l.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=we(r);return i.jsx($g,{scope:e.__scopeMenu,value:n,onValueChange:s,children:i.jsx(Eo,{...o,ref:t})})});Ti.displayName=Ni;var Ai="MenuRadioItem",Pi=l.forwardRef((e,t)=>{const{value:n,...r}=e,o=Bg(Ai,e.__scopeMenu),s=n===o.value;return i.jsx(_i,{scope:e.__scopeMenu,checked:s,children:i.jsx(Kn,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":To(s),onSelect:U(r.onSelect,()=>{var a;return(a=o.onValueChange)==null?void 0:a.call(o,n)},{checkForDefaultPrevented:!1})})})});Pi.displayName=Ai;var No="MenuItemIndicator",[_i,Ug]=ut(No,{checked:!1}),Ii=l.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=Ug(No,n);return i.jsx(Te,{present:r||Gn(s.checked)||s.checked===!0,children:i.jsx(Z.span,{...o,ref:t,"data-state":To(s.checked)})})});Ii.displayName=No;var zg="MenuSeparator",Oi=l.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return i.jsx(Z.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Oi.displayName=zg;var Hg="MenuArrow",ki=l.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=jn(n);return i.jsx(lo,{...o,...r,ref:t})});ki.displayName=Hg;var Wg="MenuSub",[Ow,Mi]=ut(Wg),Qt="MenuSubTrigger",Di=l.forwardRef((e,t)=>{const n=ft(Qt,e.__scopeMenu),r=Zt(Qt,e.__scopeMenu),o=Mi(Qt,e.__scopeMenu),s=So(Qt,e.__scopeMenu),a=l.useRef(null),{pointerGraceTimerRef:c,onPointerGraceIntentChange:d}=s,f={__scopeMenu:e.__scopeMenu},u=l.useCallback(()=>{a.current&&window.clearTimeout(a.current),a.current=null},[]);return l.useEffect(()=>u,[u]),l.useEffect(()=>{const p=c.current;return()=>{window.clearTimeout(p),d(null)}},[c,d]),i.jsx(yo,{asChild:!0,...f,children:i.jsx(Ci,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":$i(n.open),...e,ref:Fr(t,o.onTriggerChange),onClick:p=>{var m;(m=e.onClick)==null||m.call(e,p),!(e.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:U(e.onPointerMove,en(p=>{s.onItemEnter(p),!p.defaultPrevented&&!e.disabled&&!n.open&&!a.current&&(s.onPointerGraceIntentChange(null),a.current=window.setTimeout(()=>{n.onOpenChange(!0),u()},100))})),onPointerLeave:U(e.onPointerLeave,en(p=>{var v,g;u();const m=(v=n.content)==null?void 0:v.getBoundingClientRect();if(m){const h=(g=n.content)==null?void 0:g.dataset.side,b=h==="right",w=b?-5:5,y=m[b?"left":"right"],x=m[b?"right":"left"];s.onPointerGraceIntentChange({area:[{x:p.clientX+w,y:p.clientY},{x:y,y:m.top},{x,y:m.top},{x,y:m.bottom},{x:y,y:m.bottom}],side:h}),window.clearTimeout(c.current),c.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(p),p.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:U(e.onKeyDown,p=>{var v;const m=s.searchRef.current!=="";e.disabled||m&&p.key===" "||Sg[r.dir].includes(p.key)&&(n.onOpenChange(!0),(v=n.content)==null||v.focus(),p.preventDefault())})})})});Di.displayName=Qt;var Li="MenuSubContent",Fi=l.forwardRef((e,t)=>{const n=vi(Oe,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=ft(Oe,e.__scopeMenu),a=Zt(Oe,e.__scopeMenu),c=Mi(Li,e.__scopeMenu),d=l.useRef(null),f=re(t,d);return i.jsx(Jt.Provider,{scope:e.__scopeMenu,children:i.jsx(Te,{present:r||s.open,children:i.jsx(Jt.Slot,{scope:e.__scopeMenu,children:i.jsx(Co,{id:c.contentId,"aria-labelledby":c.triggerId,...o,ref:f,align:"start",side:a.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:u=>{var p;a.isUsingKeyboardRef.current&&((p=d.current)==null||p.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:U(e.onFocusOutside,u=>{u.target!==c.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:U(e.onEscapeKeyDown,u=>{a.onClose(),u.preventDefault()}),onKeyDown:U(e.onKeyDown,u=>{var v;const p=u.currentTarget.contains(u.target),m=Cg[a.dir].includes(u.key);p&&m&&(s.onOpenChange(!1),(v=c.trigger)==null||v.focus(),u.preventDefault())})})})})})});Fi.displayName=Li;function $i(e){return e?"open":"closed"}function Gn(e){return e==="indeterminate"}function To(e){return Gn(e)?"indeterminate":e?"checked":"unchecked"}function Vg(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function jg(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Rg(e,t,n){const o=t.length>1&&Array.from(t).every(f=>f===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let a=jg(e,Math.max(s,0));o.length===1&&(a=a.filter(f=>f!==n));const d=a.find(f=>f.toLowerCase().startsWith(o.toLowerCase()));return d!==n?d:void 0}function Kg(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,a=t.length-1;s<t.length;a=s++){const c=t[s],d=t[a],f=c.x,u=c.y,p=d.x,m=d.y;u>r!=m>r&&n<(p-f)*(r-u)/(m-u)+f&&(o=!o)}return o}function Gg(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Kg(n,t)}function en(e){return t=>t.pointerType==="mouse"?e(t):void 0}var qg=bi,Xg=yo,Yg=wi,Jg=yi,Zg=Eo,Qg=xi,em=Kn,tm=Ei,nm=Ti,rm=Pi,om=Ii,sm=Oi,am=ki,im=Di,cm=Fi,qn="DropdownMenu",[lm,kw]=Le(qn,[gi]),Se=gi(),[dm,Bi]=lm(qn),Ui=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:a,modal:c=!0}=e,d=Se(t),f=l.useRef(null),[u,p]=Qe({prop:o,defaultProp:s??!1,onChange:a,caller:qn});return i.jsx(dm,{scope:t,triggerId:Fe(),triggerRef:f,contentId:Fe(),open:u,onOpenChange:p,onOpenToggle:l.useCallback(()=>p(m=>!m),[p]),modal:c,children:i.jsx(qg,{...d,open:u,onOpenChange:p,dir:r,modal:c,children:n})})};Ui.displayName=qn;var zi="DropdownMenuTrigger",Hi=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Bi(zi,n),a=Se(n);return i.jsx(Xg,{asChild:!0,...a,children:i.jsx(Z.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...o,ref:Fr(t,s.triggerRef),onPointerDown:U(e.onPointerDown,c=>{!r&&c.button===0&&c.ctrlKey===!1&&(s.onOpenToggle(),s.open||c.preventDefault())}),onKeyDown:U(e.onKeyDown,c=>{r||(["Enter"," "].includes(c.key)&&s.onOpenToggle(),c.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(c.key)&&c.preventDefault())})})})});Hi.displayName=zi;var um="DropdownMenuPortal",Wi=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Se(t);return i.jsx(Yg,{...r,...n})};Wi.displayName=um;var Vi="DropdownMenuContent",ji=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bi(Vi,n),s=Se(n),a=l.useRef(!1);return i.jsx(Jg,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:U(e.onCloseAutoFocus,c=>{var d;a.current||(d=o.triggerRef.current)==null||d.focus(),a.current=!1,c.preventDefault()}),onInteractOutside:U(e.onInteractOutside,c=>{const d=c.detail.originalEvent,f=d.button===0&&d.ctrlKey===!0,u=d.button===2||f;(!o.modal||u)&&(a.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});ji.displayName=Vi;var fm="DropdownMenuGroup",pm=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Se(n);return i.jsx(Zg,{...o,...r,ref:t})});pm.displayName=fm;var hm="DropdownMenuLabel",Ri=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Se(n);return i.jsx(Qg,{...o,...r,ref:t})});Ri.displayName=hm;var gm="DropdownMenuItem",Ki=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Se(n);return i.jsx(em,{...o,...r,ref:t})});Ki.displayName=gm;var mm="DropdownMenuCheckboxItem",Gi=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Se(n);return i.jsx(tm,{...o,...r,ref:t})});Gi.displayName=mm;var bm="DropdownMenuRadioGroup",vm=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Se(n);return i.jsx(nm,{...o,...r,ref:t})});vm.displayName=bm;var wm="DropdownMenuRadioItem",qi=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Se(n);return i.jsx(rm,{...o,...r,ref:t})});qi.displayName=wm;var ym="DropdownMenuItemIndicator",Xi=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Se(n);return i.jsx(om,{...o,...r,ref:t})});Xi.displayName=ym;var xm="DropdownMenuSeparator",Yi=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Se(n);return i.jsx(sm,{...o,...r,ref:t})});Yi.displayName=xm;var Sm="DropdownMenuArrow",Cm=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Se(n);return i.jsx(am,{...o,...r,ref:t})});Cm.displayName=Sm;var Em="DropdownMenuSubTrigger",Ji=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Se(n);return i.jsx(im,{...o,...r,ref:t})});Ji.displayName=Em;var Nm="DropdownMenuSubContent",Zi=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Se(n);return i.jsx(cm,{...o,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Zi.displayName=Nm;var Tm=Ui,Am=Hi,Pm=Wi,Qi=ji,ec=Ri,tc=Ki,nc=Gi,rc=qi,oc=Xi,sc=Yi,ac=Ji,ic=Zi;const _m=Tm,Im=Am,Om=l.forwardRef(({className:e,inset:t,children:n,...r},o)=>i.jsxs(ac,{ref:o,className:A("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...r,children:[n,i.jsx(K.ChevronRight,{className:"ml-auto h-4 w-4"})]}));Om.displayName=ac.displayName;const km=l.forwardRef(({className:e,...t},n)=>i.jsx(ic,{ref:n,className:A("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg 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",e),...t}));km.displayName=ic.displayName;const cc=l.forwardRef(({className:e,sideOffset:t=4,...n},r)=>i.jsx(Pm,{children:i.jsx(Qi,{ref:r,sideOffset:t,className:A("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]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})}));cc.displayName=Qi.displayName;const lc=l.forwardRef(({className:e,inset:t,...n},r)=>i.jsx(tc,{ref:r,className:A("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));lc.displayName=tc.displayName;const Mm=l.forwardRef(({className:e,children:t,checked:n,...r},o)=>i.jsxs(nc,{ref:o,className:A("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[i.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:i.jsx(oc,{children:i.jsx(K.Check,{className:"h-4 w-4"})})}),t]}));Mm.displayName=nc.displayName;const Dm=l.forwardRef(({className:e,children:t,...n},r)=>i.jsxs(rc,{ref:r,className:A("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[i.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:i.jsx(oc,{children:i.jsx(K.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));Dm.displayName=rc.displayName;const Lm=l.forwardRef(({className:e,inset:t,...n},r)=>i.jsx(ec,{ref:r,className:A("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));Lm.displayName=ec.displayName;const Fm=l.forwardRef(({className:e,...t},n)=>i.jsx(sc,{ref:n,className:A("-mx-1 my-1 h-px bg-muted",e),...t}));Fm.displayName=sc.displayName;function tn({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=40,enableFileUpload:s=!0,enableMessageEditing:a=!0,customStyles:c={},onMessageSent:d,onError:f}){const{currentThreadId:u,messages:p,isStreaming:m,streamingAssistantId:v,error:g,send:h,stop:b,lastCheckpointId:w,listCheckpoints:y,navigateToCheckpoint:x,returnToLatest:E}=Lr(),[C,O]=P.useState(""),[N,$]=P.useState(null),[L,F]=P.useState(null),[R,G]=P.useState([]),[V,z]=P.useState(!1),[X,B]=P.useState([]),[q,T]=P.useState(null),_=P.useRef(null),I=P.useRef(null),k=P.useRef(null),[J,M]=P.useState("desktop");P.useEffect(()=>{const D=()=>{const Y=window.innerWidth;M(Y<640?"phone":Y<1024?"tablet":"desktop")};return D(),window.addEventListener("resize",D),()=>window.removeEventListener("resize",D)},[]),P.useEffect(()=>{var D;(D=_.current)==null||D.scrollIntoView({behavior:"smooth"})},[p]),P.useEffect(()=>{var D;n&&((D=I.current)==null||D.focus())},[n]),P.useEffect(()=>{g&&!V&&(f==null||f(g))},[g,V,f]),P.useEffect(()=>{let D=!0;if(!u){B([]),T(null);return}return y(u).then(Y=>{var Ae;if(!D)return;const oe=Y.checkpoints||[];B(oe);const ue=((Ae=oe.slice().sort((Dt,Ce)=>new Date(Ce.createdAt).getTime()-new Date(Dt.createdAt).getTime())[0])==null?void 0:Ae.checkpointId)||null;T(Dt=>Dt??ue)}).catch(()=>{}),()=>{D=!1}},[u,y]),P.useEffect(()=>{w&&T(w)},[w]);const H=D=>{if(D.length>xt)return`Message too long (${D.length}/${xt} characters)`;try{return Hf(D),null}catch(Y){return(Y==null?void 0:Y.message)||"Invalid message"}},de=D=>{const Y=D.content||[],oe=Y.filter(ue=>ue.type==="text").map(ue=>ue.text).join("");if(oe)return oe;try{return JSON.stringify(Y,null,2)}catch{return String(Y)}},ie=D=>{var Dt;if(!X.length)return[];const oe=(((Dt=p[D])==null?void 0:Dt.role)??"user")==="user",ue=oe?D+2:D+1;return X.filter(Ce=>(Ce.messagesLen??-1)>=(oe?ue:0)).filter(Ce=>oe?(Ce.messagesLen??0)>=ue:(Ce.messagesLen??0)===ue).map(Ce=>({checkpoint_id:Ce.checkpointId,checkpoint_ns:Ce.checkpointNs,message_count:Ce.messagesLen??0,last_message_preview:Ce.preview??void 0,ts:new Date(Ce.createdAt).getTime(),isCurrent:Ce.checkpointId===q})).sort((Ce,iw)=>(Ce.ts||0)-(iw.ts||0))},j=D=>{if(D===void 0)return{canGoBack:!1,canGoForward:!1,currentIndex:0,totalBranches:0};const Y=ie(D);if(Y.length<=1)return{canGoBack:!1,canGoForward:!1,currentIndex:0,totalBranches:Y.length};const oe=Math.max(0,Y.findIndex(ue=>ue.isCurrent));return{canGoBack:oe>0,canGoForward:oe<Y.length-1,currentIndex:oe,totalBranches:Y.length}},se=async()=>{const D=C.trim();if(!D&&R.length===0)return;const Y=H(D);if(Y){F(Y);return}try{const oe=window.__editingCheckpointId||q||void 0;await h(D,{checkpointId:oe,payloadExtras:N?{edit:!0,originalMessageId:N}:void 0,attachments:R}),d==null||d(D),O(""),F(null),G([]),delete window.__editingCheckpointId,$(null),I.current&&(I.current.style.height="auto")}catch(oe){const ue=(oe==null?void 0:oe.message)||"Failed to send message";F(ue),f==null||f(ue)}},le=(D,Y)=>{a&&($(D),O(Y),F(null),setTimeout(()=>{I.current&&(I.current.focus(),I.current.style.height="auto",I.current.style.height=I.current.scrollHeight+"px")},0))},ae=async(D,Y)=>{const oe=p.find(Ae=>Ae.id===D);if(!oe){F("Message not found");return}const ue=de(oe);$(D),O(ue),window.__editingCheckpointId=Y,setTimeout(()=>{var Ae;return(Ae=I.current)==null?void 0:Ae.focus()},0)},W=()=>{$(null),O(""),F(null),delete window.__editingCheckpointId,I.current&&(I.current.style.height="auto")},ee=D=>{D.key==="Enter"&&!D.shiftKey?(D.preventDefault(),se()):D.key==="Escape"&&N&&(D.preventDefault(),W())},pe=D=>{const Y=Array.from(D.target.files||[]);G(oe=>[...oe,...Y])},ge=D=>G(Y=>Y.filter((oe,ue)=>D!==ue)),be=async D=>{u&&(await x(D),T(D))},ne=async()=>{await E(),T(null)},ye=`flex flex-col h-full min-w-0 bg-transparent ${e} ${c.container||""}`,ce=`flex-1 min-h-0 min-w-0 overflow-y-auto p-4 space-y-4 bg-transparent ${c.messagesArea||""}`,he=`flex-shrink-0 border-t p-4 bg-transparent ${c.inputArea||""}`;return i.jsxs("div",{className:ye,children:[!!g&&!V&&i.jsxs("div",{className:"bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[i.jsx("span",{children:g}),i.jsx(fe,{variant:"ghost",size:"sm",onClick:()=>z(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:i.jsx(K.X,{size:16})})]}),u&&X.length>0&&i.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 border-b border-border bg-muted/60 text-xs dark:bg-muted/50",children:[i.jsx(K.GitBranch,{className:"h-4 w-4 opacity-70"}),i.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),i.jsxs("select",{className:"border border-border rounded px-2 py-1 text-xs bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring dark:bg-secondary",value:q??"",onChange:D=>{const Y=D.target.value||null;Y?be(Y):ne()},children:[i.jsx("option",{value:"",children:"Latest"}),X.slice().sort((D,Y)=>new Date(Y.createdAt).getTime()-new Date(D.createdAt).getTime()).map(D=>i.jsxs("option",{value:D.checkpointId,children:[new Date(D.createdAt).toLocaleString(),D.preview?` — ${D.preview.slice(0,30)}`:""]},D.checkpointId))]})]}),i.jsxs("div",{className:ce,style:r?{maxHeight:r}:void 0,children:[p.length===0?i.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground",children:"No messages yet. Start a conversation!"}):p.map((D,Y)=>i.jsx(ra,{message:D,messageIndex:Y,isStreamingMessage:m&&v===D.id,streamingDebounceMs:o,isEditing:N===D.id,showActions:a,showTimestamp:!1,showAgentName:!0,layoutSize:J,truncateToolMessages:!1,toolMessagePreviewLength:200,checkpointBranches:ie(Y),currentCheckpointId:q??void 0,temporalNavigation:j(Y),onSwitchToCheckpoint:be,onReturnToMainThread:ne,onNavigateToPreviousBranch:()=>{const oe=ie(Y),ue=Math.max(0,oe.findIndex(Ae=>Ae.isCurrent));ue>0&&be(oe[ue-1].checkpoint_id)},onNavigateToNextBranch:()=>{const oe=ie(Y),ue=Math.max(0,oe.findIndex(Ae=>Ae.isCurrent));ue>=0&&ue<oe.length-1&&be(oe[ue+1].checkpoint_id)},onEdit:(oe,ue)=>le(oe,ue),onEditFromCheckpoint:ae,onRegenerate:()=>{const oe=[...p].reverse().find(Ae=>Ae.role==="user"),ue=oe?de(oe):"";ue&&h(ue,{checkpointId:q??void 0})},onCancelEdit:W},D.id||Y)),i.jsx("div",{ref:_})]}),i.jsxs("div",{className:he,children:[N&&i.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(K.Edit3,{size:16,className:"text-blue-600"}),i.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),i.jsx(fe,{variant:"ghost",size:"sm",onClick:W,className:"text-blue-600 hover:bg-blue-100",children:i.jsx(K.X,{size:16})})]})}),s&&i.jsxs("div",{className:"mb-3",children:[i.jsx("input",{ref:k,type:"file",multiple:!0,onChange:D=>pe(D),className:"hidden"}),R.length>0&&i.jsx("div",{className:"mb-3 flex flex-wrap gap-2",children:R.map((D,Y)=>i.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 rounded-lg px-3 py-2 text-sm",children:[i.jsx(K.Paperclip,{size:14}),i.jsx("span",{className:"truncate max-w-[150px]",children:D.name}),i.jsx(fe,{variant:"ghost",size:"sm",onClick:()=>ge(Y),className:"h-4 w-4 p-0 text-gray-500 hover:text-red-500","aria-label":`Remove ${D.name}`,children:i.jsx(K.X,{size:12})})]},Y))})]}),L&&i.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:L}),i.jsxs("div",{className:"flex items-end gap-2",children:[s&&i.jsxs(_m,{children:[i.jsx(Im,{asChild:!0,children:i.jsx(fe,{type:"button",size:"icon",variant:"outline",disabled:m,title:"More input actions",className:c.moreButton||"",children:i.jsx(K.Plus,{size:16})})}),i.jsx(cc,{align:"start",sideOffset:6,className:"w-52",children:i.jsxs(lc,{onClick:()=>{var D;return(D=k.current)==null?void 0:D.click()},className:"cursor-pointer",children:[i.jsx(K.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]})})]}),i.jsx("div",{className:"flex-1",children:i.jsx(qs,{ref:I,value:C,onChange:D=>{O(D.target.value),F(null),I.current&&(I.current.style.height="auto",I.current.style.height=`${I.current.scrollHeight}px`)},onKeyDown:ee,placeholder:N?"Edit your message...":t,className:`resize-none min-h-[44px] max-h-[20rem] w-full ${N?"border-blue-400 bg-blue-50":""} ${L?"border-red-400":""} ${c.textarea||""}`,disabled:!1,maxLength:xt,rows:1})}),i.jsx("div",{children:m?i.jsx(fe,{type:"button",onClick:b,size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",children:i.jsx(K.Square,{size:16})}):i.jsx(fe,{type:"button",onClick:se,size:"icon",disabled:!C.trim()&&R.length===0,className:`shrink-0 ${c.sendButton||""}`,title:N?"Save changes":"Send message",children:i.jsx(K.Send,{size:16})})})]}),C.length>xt*.8&&i.jsxs("div",{className:"mt-2 text-xs text-gray-500 text-right",children:[C.length,"/",xt]})]})]})}const nn=l.forwardRef(({className:e,type:t,...n},r)=>i.jsx("input",{type:t,className:A("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:r,...n}));nn.displayName="Input";function Ao(e,[t,n]){return Math.min(n,Math.max(t,e))}function $m(e,t){return l.useReducer((n,r)=>t[n][r]??n,e)}var Po="ScrollArea",[dc,Mw]=Le(Po),[Bm,ke]=dc(Po),uc=l.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...a}=e,[c,d]=l.useState(null),[f,u]=l.useState(null),[p,m]=l.useState(null),[v,g]=l.useState(null),[h,b]=l.useState(null),[w,y]=l.useState(0),[x,E]=l.useState(0),[C,O]=l.useState(!1),[N,$]=l.useState(!1),L=re(t,R=>d(R)),F=Cn(o);return i.jsx(Bm,{scope:n,type:r,dir:F,scrollHideDelay:s,scrollArea:c,viewport:f,onViewportChange:u,content:p,onContentChange:m,scrollbarX:v,onScrollbarXChange:g,scrollbarXEnabled:C,onScrollbarXEnabledChange:O,scrollbarY:h,onScrollbarYChange:b,scrollbarYEnabled:N,onScrollbarYEnabledChange:$,onCornerWidthChange:y,onCornerHeightChange:E,children:i.jsx(Z.div,{dir:F,...a,ref:L,style:{position:"relative","--radix-scroll-area-corner-width":w+"px","--radix-scroll-area-corner-height":x+"px",...e.style}})})});uc.displayName=Po;var fc="ScrollAreaViewport",pc=l.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,a=ke(fc,n),c=l.useRef(null),d=re(t,c,a.onViewportChange);return i.jsxs(i.Fragment,{children:[i.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),i.jsx(Z.div,{"data-radix-scroll-area-viewport":"",...s,ref:d,style:{overflowX:a.scrollbarXEnabled?"scroll":"hidden",overflowY:a.scrollbarYEnabled?"scroll":"hidden",...e.style},children:i.jsx("div",{ref:a.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});pc.displayName=fc;var Xe="ScrollAreaScrollbar",_o=l.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=ke(Xe,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:a}=o,c=e.orientation==="horizontal";return l.useEffect(()=>(c?s(!0):a(!0),()=>{c?s(!1):a(!1)}),[c,s,a]),o.type==="hover"?i.jsx(Um,{...r,ref:t,forceMount:n}):o.type==="scroll"?i.jsx(zm,{...r,ref:t,forceMount:n}):o.type==="auto"?i.jsx(hc,{...r,ref:t,forceMount:n}):o.type==="always"?i.jsx(Io,{...r,ref:t}):null});_o.displayName=Xe;var Um=l.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=ke(Xe,e.__scopeScrollArea),[s,a]=l.useState(!1);return l.useEffect(()=>{const c=o.scrollArea;let d=0;if(c){const f=()=>{window.clearTimeout(d),a(!0)},u=()=>{d=window.setTimeout(()=>a(!1),o.scrollHideDelay)};return c.addEventListener("pointerenter",f),c.addEventListener("pointerleave",u),()=>{window.clearTimeout(d),c.removeEventListener("pointerenter",f),c.removeEventListener("pointerleave",u)}}},[o.scrollArea,o.scrollHideDelay]),i.jsx(Te,{present:n||s,children:i.jsx(hc,{"data-state":s?"visible":"hidden",...r,ref:t})})}),zm=l.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=ke(Xe,e.__scopeScrollArea),s=e.orientation==="horizontal",a=Zn(()=>d("SCROLL_END"),100),[c,d]=$m("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return l.useEffect(()=>{if(c==="idle"){const f=window.setTimeout(()=>d("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(f)}},[c,o.scrollHideDelay,d]),l.useEffect(()=>{const f=o.viewport,u=s?"scrollLeft":"scrollTop";if(f){let p=f[u];const m=()=>{const v=f[u];p!==v&&(d("SCROLL"),a()),p=v};return f.addEventListener("scroll",m),()=>f.removeEventListener("scroll",m)}},[o.viewport,s,d,a]),i.jsx(Te,{present:n||c!=="hidden",children:i.jsx(Io,{"data-state":c==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:U(e.onPointerEnter,()=>d("POINTER_ENTER")),onPointerLeave:U(e.onPointerLeave,()=>d("POINTER_LEAVE"))})})}),hc=l.forwardRef((e,t)=>{const n=ke(Xe,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,a]=l.useState(!1),c=e.orientation==="horizontal",d=Zn(()=>{if(n.viewport){const f=n.viewport.offsetWidth<n.viewport.scrollWidth,u=n.viewport.offsetHeight<n.viewport.scrollHeight;a(c?f:u)}},10);return Ot(n.viewport,d),Ot(n.content,d),i.jsx(Te,{present:r||s,children:i.jsx(Io,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Io=l.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=ke(Xe,e.__scopeScrollArea),s=l.useRef(null),a=l.useRef(0),[c,d]=l.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),f=wc(c.viewport,c.content),u={...r,sizes:c,onSizesChange:d,hasThumb:f>0&&f<1,onThumbChange:m=>s.current=m,onThumbPointerUp:()=>a.current=0,onThumbPointerDown:m=>a.current=m};function p(m,v){return Km(m,a.current,c,v)}return n==="horizontal"?i.jsx(Hm,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const m=o.viewport.scrollLeft,v=yc(m,c,o.dir);s.current.style.transform=`translate3d(${v}px, 0, 0)`}},onWheelScroll:m=>{o.viewport&&(o.viewport.scrollLeft=m)},onDragScroll:m=>{o.viewport&&(o.viewport.scrollLeft=p(m,o.dir))}}):n==="vertical"?i.jsx(Wm,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const m=o.viewport.scrollTop,v=yc(m,c);s.current.style.transform=`translate3d(0, ${v}px, 0)`}},onWheelScroll:m=>{o.viewport&&(o.viewport.scrollTop=m)},onDragScroll:m=>{o.viewport&&(o.viewport.scrollTop=p(m))}}):null}),Hm=l.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=ke(Xe,e.__scopeScrollArea),[a,c]=l.useState(),d=l.useRef(null),f=re(t,d,s.onScrollbarXChange);return l.useEffect(()=>{d.current&&c(getComputedStyle(d.current))},[d]),i.jsx(mc,{"data-orientation":"horizontal",...o,ref:f,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Jn(n)+"px",...e.style},onThumbPointerDown:u=>e.onThumbPointerDown(u.x),onDragScroll:u=>e.onDragScroll(u.x),onWheelScroll:(u,p)=>{if(s.viewport){const m=s.viewport.scrollLeft+u.deltaX;e.onWheelScroll(m),Sc(m,p)&&u.preventDefault()}},onResize:()=>{d.current&&s.viewport&&a&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:d.current.clientWidth,paddingStart:Yn(a.paddingLeft),paddingEnd:Yn(a.paddingRight)}})}})}),Wm=l.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=ke(Xe,e.__scopeScrollArea),[a,c]=l.useState(),d=l.useRef(null),f=re(t,d,s.onScrollbarYChange);return l.useEffect(()=>{d.current&&c(getComputedStyle(d.current))},[d]),i.jsx(mc,{"data-orientation":"vertical",...o,ref:f,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Jn(n)+"px",...e.style},onThumbPointerDown:u=>e.onThumbPointerDown(u.y),onDragScroll:u=>e.onDragScroll(u.y),onWheelScroll:(u,p)=>{if(s.viewport){const m=s.viewport.scrollTop+u.deltaY;e.onWheelScroll(m),Sc(m,p)&&u.preventDefault()}},onResize:()=>{d.current&&s.viewport&&a&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:d.current.clientHeight,paddingStart:Yn(a.paddingTop),paddingEnd:Yn(a.paddingBottom)}})}})}),[Vm,gc]=dc(Xe),mc=l.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:a,onThumbPointerDown:c,onThumbPositionChange:d,onDragScroll:f,onWheelScroll:u,onResize:p,...m}=e,v=ke(Xe,n),[g,h]=l.useState(null),b=re(t,L=>h(L)),w=l.useRef(null),y=l.useRef(""),x=v.viewport,E=r.content-r.viewport,C=we(u),O=we(d),N=Zn(p,10);function $(L){if(w.current){const F=L.clientX-w.current.left,R=L.clientY-w.current.top;f({x:F,y:R})}}return l.useEffect(()=>{const L=F=>{const R=F.target;(g==null?void 0:g.contains(R))&&C(F,E)};return document.addEventListener("wheel",L,{passive:!1}),()=>document.removeEventListener("wheel",L,{passive:!1})},[x,g,E,C]),l.useEffect(O,[r,O]),Ot(g,N),Ot(v.content,N),i.jsx(Vm,{scope:n,scrollbar:g,hasThumb:o,onThumbChange:we(s),onThumbPointerUp:we(a),onThumbPositionChange:O,onThumbPointerDown:we(c),children:i.jsx(Z.div,{...m,ref:b,style:{position:"absolute",...m.style},onPointerDown:U(e.onPointerDown,L=>{L.button===0&&(L.target.setPointerCapture(L.pointerId),w.current=g.getBoundingClientRect(),y.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",v.viewport&&(v.viewport.style.scrollBehavior="auto"),$(L))}),onPointerMove:U(e.onPointerMove,$),onPointerUp:U(e.onPointerUp,L=>{const F=L.target;F.hasPointerCapture(L.pointerId)&&F.releasePointerCapture(L.pointerId),document.body.style.webkitUserSelect=y.current,v.viewport&&(v.viewport.style.scrollBehavior=""),w.current=null})})})}),Xn="ScrollAreaThumb",bc=l.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=gc(Xn,e.__scopeScrollArea);return i.jsx(Te,{present:n||o.hasThumb,children:i.jsx(jm,{ref:t,...r})})}),jm=l.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=ke(Xn,n),a=gc(Xn,n),{onThumbPositionChange:c}=a,d=re(t,p=>a.onThumbChange(p)),f=l.useRef(void 0),u=Zn(()=>{f.current&&(f.current(),f.current=void 0)},100);return l.useEffect(()=>{const p=s.viewport;if(p){const m=()=>{if(u(),!f.current){const v=Gm(p,c);f.current=v,c()}};return c(),p.addEventListener("scroll",m),()=>p.removeEventListener("scroll",m)}},[s.viewport,u,c]),i.jsx(Z.div,{"data-state":a.hasThumb?"visible":"hidden",...o,ref:d,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:U(e.onPointerDownCapture,p=>{const v=p.target.getBoundingClientRect(),g=p.clientX-v.left,h=p.clientY-v.top;a.onThumbPointerDown({x:g,y:h})}),onPointerUp:U(e.onPointerUp,a.onThumbPointerUp)})});bc.displayName=Xn;var Oo="ScrollAreaCorner",vc=l.forwardRef((e,t)=>{const n=ke(Oo,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?i.jsx(Rm,{...e,ref:t}):null});vc.displayName=Oo;var Rm=l.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=ke(Oo,n),[s,a]=l.useState(0),[c,d]=l.useState(0),f=!!(s&&c);return Ot(o.scrollbarX,()=>{var p;const u=((p=o.scrollbarX)==null?void 0:p.offsetHeight)||0;o.onCornerHeightChange(u),d(u)}),Ot(o.scrollbarY,()=>{var p;const u=((p=o.scrollbarY)==null?void 0:p.offsetWidth)||0;o.onCornerWidthChange(u),a(u)}),f?i.jsx(Z.div,{...r,ref:t,style:{width:s,height:c,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Yn(e){return e?parseInt(e,10):0}function wc(e,t){const n=e/t;return isNaN(n)?0:n}function Jn(e){const t=wc(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function Km(e,t,n,r="ltr"){const o=Jn(n),s=o/2,a=t||s,c=o-a,d=n.scrollbar.paddingStart+a,f=n.scrollbar.size-n.scrollbar.paddingEnd-c,u=n.content-n.viewport,p=r==="ltr"?[0,u]:[u*-1,0];return xc([d,f],p)(e)}function yc(e,t,n="ltr"){const r=Jn(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,a=t.content-t.viewport,c=s-r,d=n==="ltr"?[0,a]:[a*-1,0],f=Ao(e,d);return xc([0,a],[0,c])(f)}function xc(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}function Sc(e,t){return e>0&&e<t}var Gm=(e,t=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},r=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},a=n.left!==s.left,c=n.top!==s.top;(a||c)&&t(),n=s,r=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(r)};function Zn(e,t){const n=we(e),r=l.useRef(0);return l.useEffect(()=>()=>window.clearTimeout(r.current),[]),l.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Ot(e,t){const n=we(t);ve(()=>{let r=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return o.observe(e),()=>{window.cancelAnimationFrame(r),o.unobserve(e)}}},[e,n])}var Cc=uc,qm=pc,Xm=vc;const Ec=l.forwardRef(({className:e,children:t,...n},r)=>i.jsxs(Cc,{ref:r,className:A("relative overflow-hidden",e),...n,children:[i.jsx(qm,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),i.jsx(Nc,{}),i.jsx(Xm,{})]}));Ec.displayName=Cc.displayName;const Nc=l.forwardRef(({className:e,orientation:t="vertical",...n},r)=>i.jsx(_o,{ref:r,orientation:t,className:A("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:i.jsx(bc,{className:"relative flex-1 rounded-full bg-border"})}));Nc.displayName=_o.displayName;function Qn({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:a=null,navigateToThread:c,onThreadSelect:d,onThreadCreate:f,onThreadDelete:u}){const{loadThread:p,threads:m,refreshThreads:v,currentThreadId:g,createThread:h,deleteThread:b,renameThread:w}=Lr(),[y,x]=P.useState(m??[]),[E,C]=P.useState(!1),[O,N]=P.useState(null),[$,L]=P.useState(null),[F,R]=P.useState(""),[G,V]=P.useState(!1);P.useEffect(()=>{x(m??[])},[m]);const z=async M=>{try{await p(M),c==null||c(M),d==null||d(M)}catch(H){console.error("Failed to select thread:",H)}},X=async()=>{try{V(!0);const M=await h();f==null||f(M),c==null||c(M)}catch(M){console.error("Failed to create thread:",M)}finally{V(!1)}},B=async(M,H)=>{if(H.stopPropagation(),!!confirm("Delete this thread?"))try{await b(M),u==null||u(M)}catch(de){console.error("Failed to delete thread:",de)}},q=(M,H)=>{H.stopPropagation(),L(M.threadId),R(M.title||`Thread ${M.threadId.slice(0,8)}`)},T=async M=>{if(F.trim())try{await w(M,F.trim()),L(null),R("")}catch(H){console.error("Failed to update title:",H)}},_=()=>{L(null),R("")},I=(M,H)=>{M.key==="Enter"?T(H):M.key==="Escape"&&_()},k=M=>{if(!M)return"";try{const H=new Date(M),ie=new Date().getTime()-H.getTime(),j=Math.floor(ie/(1e3*60*60*24));return j===0?H.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):j===1?"Yesterday":j<7?`${j} days ago`:H.toLocaleDateString()}catch{return""}},J=M=>M.title||`Thread ${M.threadId.slice(0,8)}`;return i.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&i.jsx("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:i.jsx(fe,{onClick:X,disabled:G||E,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:G?"Creating...":"New Chat",children:i.jsx(K.MessageSquarePlus,{size:20})})}),i.jsx(Ec,{className:`flex-1 ${s.threadList||""}`,style:{maxHeight:o},children:i.jsx("div",{className:"p-2 space-y-1 pb-4",children:E?i.jsx("div",{className:"text-center py-8 text-slate-400",children:"Loading…"}):y.length===0?i.jsxs("div",{className:"text-center py-8 text-slate-400",children:[i.jsx(K.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),i.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):y.slice().sort((M,H)=>new Date(H.updatedAt||H.createdAt||"").getTime()-new Date(M.updatedAt||M.createdAt||"").getTime()).map(M=>i.jsxs("div",{onClick:()=>z(M.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(a??g)===M.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("div",{className:"flex-1 min-w-0",children:$===M.threadId?i.jsxs("div",{className:"flex items-center gap-2",onClick:H=>H.stopPropagation(),children:[i.jsx(nn,{value:F,onChange:H=>R(H.target.value),onKeyDown:H=>I(H,M.threadId),className:"h-6 text-sm",autoFocus:!0}),i.jsx(fe,{variant:"ghost",size:"sm",onClick:()=>T(M.threadId),className:"h-6 w-6 p-0",children:i.jsx(K.Check,{size:12})}),i.jsx(fe,{variant:"ghost",size:"sm",onClick:_,className:"h-6 w-6 p-0",children:i.jsx(K.X,{size:12})})]}):i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:J(M)}),i.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[i.jsx(K.Calendar,{size:10}),i.jsx("span",{children:k(M.updatedAt||M.createdAt)})]})]})}),i.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&$!==M.threadId&&i.jsx(fe,{variant:"ghost",size:"sm",onClick:H=>q(M,H),className:"h-6 w-6 p-0",title:"Edit title",children:i.jsx(K.Edit3,{size:12})}),n&&i.jsx(fe,{variant:"ghost",size:"sm",onClick:H=>B(M.threadId,H),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:i.jsx(K.Trash2,{size:12})})]})]}),a===M.threadId&&i.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},M.threadId))})})]})}const Tc=P.createContext(null);function Ym({children:e,basePath:t="/chat"}){const n=P.useMemo(()=>t?t==="/"?"":t.endsWith("/")?t.slice(0,-1):t:"/chat",[t]),r={basePath:n,buildThreadPath:o=>`${n}/${o}`,buildBasePath:()=>n};return i.jsx(Tc.Provider,{value:r,children:e})}function Jm(){const e=P.useContext(Tc);return e||{basePath:"/chat",buildThreadPath:t=>`/chat/${t}`,buildBasePath:()=>"/chat"}}const Ac={BASE_URL:"/",DEV:!1,MODE:"library",PROD:!0,SSR:!1};function rn(e){var o;const t=typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:br&&br.tagName.toUpperCase()==="SCRIPT"&&br.src||new URL("index.umd.js",document.baseURI).href}<"u"&&Ac?Ac[e]:void 0,n=(o=globalThis==null?void 0:globalThis.process)==null?void 0:o.env,r=n?n[e]:void 0;return(t??r)||void 0}function Zm(){return rn("VITE_API_BASE_URL")||rn("NEXT_PUBLIC_API_BASE_URL")||void 0}function Qm(){return rn("VITE_API_KEY")||rn("NEXT_PUBLIC_API_KEY")||rn("VITE_AUTH_TOKEN")||void 0}function Pc(){const e=Zm(),t=Qm(),n={};return e&&(n.baseUrl=e),t&&(n.apiKey=t),n}function _c(){const e=Pc(),t=Ye.getAuthToken();return{apiBaseUrl:e.baseUrl||Ye.baseUrl||"http://localhost:8000",apiKey:t||e.apiKey||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,truncateToolMessages:!0,toolMessagePreviewLength:200,darkMode:!1,enableSound:!1,messageHistory:100}}const Ic="chat-settings";function eb(){try{const e=localStorage.getItem(Ic);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function tb(e){try{localStorage.setItem(Ic,JSON.stringify(e)),e.apiKey&&Ye.setAuthToken(e.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function nb(){const e=_c(),t=eb(),n=Ye.getAuthToken();return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Ye.baseUrl||t.apiBaseUrl||e.apiBaseUrl}}function rb(e){e.apiKey&&Ye.setAuthToken(e.apiKey),tb(e)}const ko=768;function ob(){const[e,t]=l.useState(void 0);return l.useEffect(()=>{const n=window.matchMedia(`(max-width: ${ko-1}px)`),r=()=>{t(window.innerWidth<ko)};return n.addEventListener("change",r),t(window.innerWidth<ko),()=>n.removeEventListener("change",r)},[]),!!e}var sb="Separator",Oc="horizontal",ab=["horizontal","vertical"],kc=l.forwardRef((e,t)=>{const{decorative:n,orientation:r=Oc,...o}=e,s=ib(r)?r:Oc,c=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return i.jsx(Z.div,{"data-orientation":s,...c,...o,ref:t})});kc.displayName=sb;function ib(e){return ab.includes(e)}var Mc=kc;const Mo=l.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>i.jsx(Mc,{ref:o,decorative:n,orientation:t,className:A("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Mo.displayName=Mc.displayName;var er="Dialog",[Dc,Dw]=Le(er),[cb,Ue]=Dc(er),Lc=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:a=!0}=e,c=l.useRef(null),d=l.useRef(null),[f,u]=Qe({prop:r,defaultProp:o??!1,onChange:s,caller:er});return i.jsx(cb,{scope:t,triggerRef:c,contentRef:d,contentId:Fe(),titleId:Fe(),descriptionId:Fe(),open:f,onOpenChange:u,onOpenToggle:l.useCallback(()=>u(p=>!p),[u]),modal:a,children:n})};Lc.displayName=er;var Fc="DialogTrigger",$c=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Ue(Fc,n),s=re(t,o.triggerRef);return i.jsx(Z.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Fo(o.open),...r,ref:s,onClick:U(e.onClick,o.onOpenToggle)})});$c.displayName=Fc;var Do="DialogPortal",[lb,Bc]=Dc(Do,{forceMount:void 0}),Uc=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=Ue(Do,t);return i.jsx(lb,{scope:t,forceMount:n,children:l.Children.map(r,a=>i.jsx(Te,{present:n||s.open,children:i.jsx(Ln,{asChild:!0,container:o,children:a})}))})};Uc.displayName=Do;var tr="DialogOverlay",zc=l.forwardRef((e,t)=>{const n=Bc(tr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=Ue(tr,e.__scopeDialog);return s.modal?i.jsx(Te,{present:r||s.open,children:i.jsx(ub,{...o,ref:t})}):null});zc.displayName=tr;var db=Pe.createSlot("DialogOverlay.RemoveScroll"),ub=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Ue(tr,n);return i.jsx(Vn,{as:db,allowPinchZoom:!0,shards:[o.contentRef],children:i.jsx(Z.div,{"data-state":Fo(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),pt="DialogContent",Hc=l.forwardRef((e,t)=>{const n=Bc(pt,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=Ue(pt,e.__scopeDialog);return i.jsx(Te,{present:r||s.open,children:s.modal?i.jsx(fb,{...o,ref:t}):i.jsx(pb,{...o,ref:t})})});Hc.displayName=pt;var fb=l.forwardRef((e,t)=>{const n=Ue(pt,e.__scopeDialog),r=l.useRef(null),o=re(t,n.contentRef,r);return l.useEffect(()=>{const s=r.current;if(s)return ho(s)},[]),i.jsx(Wc,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:U(e.onCloseAutoFocus,s=>{var a;s.preventDefault(),(a=n.triggerRef.current)==null||a.focus()}),onPointerDownOutside:U(e.onPointerDownOutside,s=>{const a=s.detail.originalEvent,c=a.button===0&&a.ctrlKey===!0;(a.button===2||c)&&s.preventDefault()}),onFocusOutside:U(e.onFocusOutside,s=>s.preventDefault())})}),pb=l.forwardRef((e,t)=>{const n=Ue(pt,e.__scopeDialog),r=l.useRef(!1),o=l.useRef(!1);return i.jsx(Wc,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var a,c;(a=e.onCloseAutoFocus)==null||a.call(e,s),s.defaultPrevented||(r.current||(c=n.triggerRef.current)==null||c.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var d,f;(d=e.onInteractOutside)==null||d.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const a=s.target;((f=n.triggerRef.current)==null?void 0:f.contains(a))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),Wc=l.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...a}=e,c=Ue(pt,n),d=l.useRef(null),f=re(t,d);return jr(),i.jsxs(i.Fragment,{children:[i.jsx(En,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:i.jsx(Rt,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionId,"aria-labelledby":c.titleId,"data-state":Fo(c.open),...a,ref:f,onDismiss:()=>c.onOpenChange(!1)})}),i.jsxs(i.Fragment,{children:[i.jsx(hb,{titleId:c.titleId}),i.jsx(mb,{contentRef:d,descriptionId:c.descriptionId})]})]})}),Lo="DialogTitle",Vc=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Ue(Lo,n);return i.jsx(Z.h2,{id:o.titleId,...r,ref:t})});Vc.displayName=Lo;var jc="DialogDescription",Rc=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Ue(jc,n);return i.jsx(Z.p,{id:o.descriptionId,...r,ref:t})});Rc.displayName=jc;var Kc="DialogClose",Gc=l.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Ue(Kc,n);return i.jsx(Z.button,{type:"button",...r,ref:t,onClick:U(e.onClick,()=>o.onOpenChange(!1))})});Gc.displayName=Kc;function Fo(e){return e?"open":"closed"}var qc="DialogTitleWarning",[Lw,Xc]=df(qc,{contentName:pt,titleName:Lo,docsSlug:"dialog"}),hb=({titleId:e})=>{const t=Xc(qc),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
59
59
 
60
60
  If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
61
61
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teodor-new-chat-ui",
3
- "version": "2.0.31",
3
+ "version": "2.0.32",
4
4
  "description": "React chat UI components with streaming support, tool calls, and modern design",
5
5
  "main": "dist/index.umd.js",
6
6
  "module": "dist/index.esm.js",