teodor-new-chat-ui 2.0.40 → 2.0.41
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 +1 -1
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -7240,7 +7240,7 @@ function Fn({
|
|
|
7240
7240
|
d && (await x(I), V(I));
|
|
7241
7241
|
}, se = async () => {
|
|
7242
7242
|
await C(), V(null);
|
|
7243
|
-
}, Ae = `flex flex-col h-full min-h-0 min-w-0 overflow-hidden bg-transparent ${e} ${i.container || ""}`, Pe = `flex-1 min-h-0 min-w-0 overflow-y-auto overflow-x-
|
|
7243
|
+
}, Ae = `flex w-full flex-col h-full min-h-0 min-w-0 overflow-x-hidden bg-transparent ${e} ${i.container || ""}`, Pe = `flex-1 min-h-0 min-w-0 w-full overflow-y-auto overflow-x-auto overscroll-x-contain break-words break-anywhere p-4 space-y-4 bg-transparent ${i.messagesArea || ""}`, Ue = `flex-shrink-0 w-full border-t p-4 bg-transparent ${i.inputArea || ""}`;
|
|
7244
7244
|
return /* @__PURE__ */ E("div", { className: Ae, children: [
|
|
7245
7245
|
!!m && !L && /* @__PURE__ */ E("div", { className: "bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between", children: [
|
|
7246
7246
|
/* @__PURE__ */ c("span", { children: m }),
|
package/dist/index.umd.js
CHANGED
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
`)},mi=function(){var e=parseInt(document.body.getAttribute(Ft)||"0",10);return isFinite(e)?e:0},hg=function(){l.useEffect(function(){return document.body.setAttribute(Ft,(mi()+1).toString()),function(){var e=mi()-1;e<=0?document.body.removeAttribute(Ft):document.body.setAttribute(Ft,e.toString())}},[])},gg=function(e){var t=e.noRelative,r=e.noImportant,n=e.gapMode,o=n===void 0?"margin":n;hg();var s=l.useMemo(function(){return ug(o)},[o]);return l.createElement(fg,{styles:pg(s,!t,o,r?"":"!important")})},Ao=!1;if(typeof window<"u")try{var qr=Object.defineProperty({},"passive",{get:function(){return Ao=!0,!0}});window.addEventListener("test",qr,qr),window.removeEventListener("test",qr,qr)}catch{Ao=!1}var $t=Ao?{passive:!1}:!1,mg=function(e){return e.tagName==="TEXTAREA"},bi=function(e,t){if(!(e instanceof Element))return!1;var r=window.getComputedStyle(e);return r[t]!=="hidden"&&!(r.overflowY===r.overflowX&&!mg(e)&&r[t]==="visible")},bg=function(e){return bi(e,"overflowY")},vg=function(e){return bi(e,"overflowX")},vi=function(e,t){var r=t.ownerDocument,n=t;do{typeof ShadowRoot<"u"&&n instanceof ShadowRoot&&(n=n.host);var o=wi(e,n);if(o){var s=yi(e,n),a=s[1],c=s[2];if(a>c)return!0}n=n.parentNode}while(n&&n!==r.body);return!1},wg=function(e){var t=e.scrollTop,r=e.scrollHeight,n=e.clientHeight;return[t,r,n]},yg=function(e){var t=e.scrollLeft,r=e.scrollWidth,n=e.clientWidth;return[t,r,n]},wi=function(e,t){return e==="v"?bg(t):vg(t)},yi=function(e,t){return e==="v"?wg(t):yg(t)},xg=function(e,t){return e==="h"&&t==="rtl"?-1:1},Sg=function(e,t,r,n,o){var s=xg(e,window.getComputedStyle(t).direction),a=s*n,c=r.target,d=t.contains(c),f=!1,u=a>0,p=0,m=0;do{if(!c)break;var v=yi(e,c),g=v[0],h=v[1],b=v[2],w=h-b-s*g;(g||w)&&wi(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},Xr=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},xi=function(e){return[e.deltaX,e.deltaY]},Si=function(e){return e&&"current"in e?e.current:e},Cg=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Eg=function(e){return`
|
|
56
56
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
57
57
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
58
|
-
`)},Ng=0,Bt=[];function Tg(e){var t=l.useRef([]),r=l.useRef([0,0]),n=l.useRef(),o=l.useState(Ng++)[0],s=l.useState(gi)[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=Gh([e.lockRef.current],(e.shards||[]).map(Si),!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=Xr(h),y=r.current,x="deltaX"in h?h.deltaX:y[0]-w[0],C="deltaY"in h?h.deltaY:y[1]-w[1],E,O=h.target,N=Math.abs(x)>Math.abs(C)?"h":"v";if("touches"in h&&N==="h"&&O.type==="range")return!1;var L=vi(N,O);if(!L)return!0;if(L?E=N:(E=N==="v"?"h":"v",L=vi(N,O)),!L)return!1;if(!n.current&&"changedTouches"in h&&(x||C)&&(n.current=E),!E)return!0;var D=n.current||E;return Sg(D,b,h,D==="h"?x:C)},[]),d=l.useCallback(function(h){var b=h;if(!(!Bt.length||Bt[Bt.length-1]!==s)){var w="deltaY"in b?xi(b):Xr(b),y=t.current.filter(function(E){return E.name===b.type&&(E.target===b.target||b.target===E.shadowParent)&&Cg(E.delta,w)})[0];if(y&&y.should){b.cancelable&&b.preventDefault();return}if(!y){var x=(a.current.shards||[]).map(Si).filter(Boolean).filter(function(E){return E.contains(b.target)}),C=x.length>0?c(b,x[0]):!a.current.noIsolation;C&&b.cancelable&&b.preventDefault()}}},[]),f=l.useCallback(function(h,b,w,y){var x={name:h,delta:b,target:w,should:y,shadowParent:Ag(w)};t.current.push(x),setTimeout(function(){t.current=t.current.filter(function(C){return C!==x})},1)},[]),u=l.useCallback(function(h){r.current=Xr(h),n.current=void 0},[]),p=l.useCallback(function(h){f(h.type,xi(h),h.target,c(h,e.lockRef.current))},[]),m=l.useCallback(function(h){f(h.type,Xr(h),h.target,c(h,e.lockRef.current))},[]);l.useEffect(function(){return Bt.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(){Bt=Bt.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:Eg(o)}):null,v?l.createElement(gg,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Ag(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Pg=rg(hi,Tg);var Yr=l.forwardRef(function(e,t){return l.createElement(Gr,Qe({},e,{ref:t,sideCar:Pg}))});Yr.classNames=Gr.classNames;var Po=["Enter"," "],_g=["ArrowDown","PageUp","Home"],Ci=["ArrowUp","PageDown","End"],Ig=[..._g,...Ci],kg={ltr:[...Po,"ArrowRight"],rtl:[...Po,"ArrowLeft"]},Og={ltr:["ArrowLeft"],rtl:["ArrowRight"]},nr="Menu",[or,Mg,Dg]=Yn(nr),[vt,Ei]=Ue(nr,[Dg,Dt,si]),Jr=Dt(),Ni=si(),[Lg,wt]=vt(nr),[Fg,sr]=vt(nr),Ti=e=>{const{__scopeMenu:t,open:r=!1,children:n,dir:o,onOpenChange:s,modal:a=!0}=e,c=Jr(t),[d,f]=l.useState(null),u=l.useRef(!1),p=Se(s),m=Ir(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(mo,{...c,children:i.jsx(Lg,{scope:t,open:r,onOpenChange:p,content:d,onContentChange:f,children:i.jsx(Fg,{scope:t,onClose:l.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:u,dir:m,modal:a,children:n})})})};Ti.displayName=nr;var $g="MenuAnchor",_o=l.forwardRef((e,t)=>{const{__scopeMenu:r,...n}=e,o=Jr(r);return i.jsx(bo,{...o,...n,ref:t})});_o.displayName=$g;var Io="MenuPortal",[Bg,Ai]=vt(Io,{forceMount:void 0}),Pi=e=>{const{__scopeMenu:t,forceMount:r,children:n,container:o}=e,s=wt(Io,t);return i.jsx(Bg,{scope:t,forceMount:r,children:i.jsx(_e,{present:r||s.open,children:i.jsx(Wr,{asChild:!0,container:o,children:n})})})};Pi.displayName=Io;var Le="MenuContent",[Ug,ko]=vt(Le),_i=l.forwardRef((e,t)=>{const r=Ai(Le,e.__scopeMenu),{forceMount:n=r.forceMount,...o}=e,s=wt(Le,e.__scopeMenu),a=sr(Le,e.__scopeMenu);return i.jsx(or.Provider,{scope:e.__scopeMenu,children:i.jsx(_e,{present:n||s.open,children:i.jsx(or.Slot,{scope:e.__scopeMenu,children:a.modal?i.jsx(Hg,{...o,ref:t}):i.jsx(zg,{...o,ref:t})})})})}),Hg=l.forwardRef((e,t)=>{const r=wt(Le,e.__scopeMenu),n=l.useRef(null),o=se(t,n);return l.useEffect(()=>{const s=n.current;if(s)return Co(s)},[]),i.jsx(Oo,{...e,ref:o,trapFocus:r.open,disableOutsidePointerEvents:r.open,disableOutsideScroll:!0,onFocusOutside:U(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>r.onOpenChange(!1)})}),zg=l.forwardRef((e,t)=>{const r=wt(Le,e.__scopeMenu);return i.jsx(Oo,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>r.onOpenChange(!1)})}),Wg=Oe.createSlot("MenuContent.ScrollLock"),Oo=l.forwardRef((e,t)=>{const{__scopeMenu:r,loop:n=!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=wt(Le,r),w=sr(Le,r),y=Jr(r),x=Ni(r),C=Mg(r),[E,O]=l.useState(null),N=l.useRef(null),L=se(t,N,b.onContentChange),D=l.useRef(0),$=l.useRef(""),R=l.useRef(0),X=l.useRef(null),B=l.useRef("right"),M=l.useRef(0),J=g?Yr:l.Fragment,F=g?{as:Wg,allowPinchZoom:!0}:void 0,H=_=>{var z,ce;const G=$.current+_,j=C().filter(pe=>!pe.disabled),Z=document.activeElement,I=(z=j.find(pe=>pe.ref.current===Z))==null?void 0:z.textValue,W=j.map(pe=>pe.textValue),ge=em(W,G,I),he=(ce=j.find(pe=>pe.textValue===ge))==null?void 0:ce.ref.current;(function pe(le){$.current=le,window.clearTimeout(D.current),le!==""&&(D.current=window.setTimeout(()=>pe(""),1e3))})(G),he&&setTimeout(()=>he.focus())};l.useEffect(()=>()=>window.clearTimeout(D.current),[]),Qn();const P=l.useCallback(_=>{var j,Z;return B.current===((j=X.current)==null?void 0:j.side)&&rm(_,(Z=X.current)==null?void 0:Z.area)},[]);return i.jsx(Ug,{scope:r,searchRef:$,onItemEnter:l.useCallback(_=>{P(_)&&_.preventDefault()},[P]),onItemLeave:l.useCallback(_=>{var G;P(_)||((G=N.current)==null||G.focus(),O(null))},[P]),onTriggerLeave:l.useCallback(_=>{P(_)&&_.preventDefault()},[P]),pointerGraceTimerRef:R,onPointerGraceIntentChange:l.useCallback(_=>{X.current=_},[]),children:i.jsx(J,{...F,children:i.jsx(kr,{asChild:!0,trapped:o,onMountAutoFocus:U(s,_=>{var G;_.preventDefault(),(G=N.current)==null||G.focus({preventScroll:!0})}),onUnmountAutoFocus:a,children:i.jsx(Zt,{asChild:!0,disableOutsidePointerEvents:c,onEscapeKeyDown:f,onPointerDownOutside:u,onFocusOutside:p,onInteractOutside:m,onDismiss:v,children:i.jsx(Wh,{asChild:!0,...x,dir:w.dir,orientation:"vertical",loop:n,currentTabStopId:E,onCurrentTabStopIdChange:O,onEntryFocus:U(d,_=>{w.isUsingKeyboardRef.current||_.preventDefault()}),preventScrollOnEntryFocus:!0,children:i.jsx(vo,{role:"menu","aria-orientation":"vertical","data-state":Ki(b.open),"data-radix-menu-content":"",dir:w.dir,...y,...h,ref:L,style:{outline:"none",...h.style},onKeyDown:U(h.onKeyDown,_=>{const j=_.target.closest("[data-radix-menu-content]")===_.currentTarget,Z=_.ctrlKey||_.altKey||_.metaKey,I=_.key.length===1;j&&(_.key==="Tab"&&_.preventDefault(),!Z&&I&&H(_.key));const W=N.current;if(_.target!==W||!Ig.includes(_.key))return;_.preventDefault();const he=C().filter(z=>!z.disabled).map(z=>z.ref.current);Ci.includes(_.key)&&he.reverse(),Zg(he)}),onBlur:U(e.onBlur,_=>{_.currentTarget.contains(_.target)||(window.clearTimeout(D.current),$.current="")}),onPointerMove:U(e.onPointerMove,ir(_=>{const G=_.target,j=M.current!==_.clientX;if(_.currentTarget.contains(G)&&j){const Z=_.clientX>M.current?"right":"left";B.current=Z,M.current=_.clientX}}))})})})})})})});_i.displayName=Le;var Vg="MenuGroup",Mo=l.forwardRef((e,t)=>{const{__scopeMenu:r,...n}=e;return i.jsx(Q.div,{role:"group",...n,ref:t})});Mo.displayName=Vg;var jg="MenuLabel",Ii=l.forwardRef((e,t)=>{const{__scopeMenu:r,...n}=e;return i.jsx(Q.div,{...n,ref:t})});Ii.displayName=jg;var Zr="MenuItem",ki="menu.itemSelect",Qr=l.forwardRef((e,t)=>{const{disabled:r=!1,onSelect:n,...o}=e,s=l.useRef(null),a=sr(Zr,e.__scopeMenu),c=ko(Zr,e.__scopeMenu),d=se(t,s),f=l.useRef(!1),u=()=>{const p=s.current;if(!r&&p){const m=new CustomEvent(ki,{bubbles:!0,cancelable:!0});p.addEventListener(ki,v=>n==null?void 0:n(v),{once:!0}),aa(p,m),m.defaultPrevented?f.current=!1:a.onClose()}};return i.jsx(Oi,{...o,ref:d,disabled:r,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!=="";r||m&&p.key===" "||Po.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});Qr.displayName=Zr;var Oi=l.forwardRef((e,t)=>{const{__scopeMenu:r,disabled:n=!1,textValue:o,...s}=e,a=ko(Zr,r),c=Ni(r),d=l.useRef(null),f=se(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(or.ItemSlot,{scope:r,disabled:n,textValue:o??m,children:i.jsx(Vh,{asChild:!0,...c,focusable:!n,children:i.jsx(Q.div,{role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":n||void 0,"data-disabled":n?"":void 0,...s,ref:f,onPointerMove:U(e.onPointerMove,ir(g=>{n?a.onItemLeave(g):(a.onItemEnter(g),g.defaultPrevented||g.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:U(e.onPointerLeave,ir(g=>a.onItemLeave(g))),onFocus:U(e.onFocus,()=>p(!0)),onBlur:U(e.onBlur,()=>p(!1))})})})}),Rg="MenuCheckboxItem",Mi=l.forwardRef((e,t)=>{const{checked:r=!1,onCheckedChange:n,...o}=e;return i.jsx(Bi,{scope:e.__scopeMenu,checked:r,children:i.jsx(Qr,{role:"menuitemcheckbox","aria-checked":en(r)?"mixed":r,...o,ref:t,"data-state":Lo(r),onSelect:U(o.onSelect,()=>n==null?void 0:n(en(r)?!0:!r),{checkForDefaultPrevented:!1})})})});Mi.displayName=Rg;var Di="MenuRadioGroup",[Kg,Gg]=vt(Di,{value:void 0,onValueChange:()=>{}}),Li=l.forwardRef((e,t)=>{const{value:r,onValueChange:n,...o}=e,s=Se(n);return i.jsx(Kg,{scope:e.__scopeMenu,value:r,onValueChange:s,children:i.jsx(Mo,{...o,ref:t})})});Li.displayName=Di;var Fi="MenuRadioItem",$i=l.forwardRef((e,t)=>{const{value:r,...n}=e,o=Gg(Fi,e.__scopeMenu),s=r===o.value;return i.jsx(Bi,{scope:e.__scopeMenu,checked:s,children:i.jsx(Qr,{role:"menuitemradio","aria-checked":s,...n,ref:t,"data-state":Lo(s),onSelect:U(n.onSelect,()=>{var a;return(a=o.onValueChange)==null?void 0:a.call(o,r)},{checkForDefaultPrevented:!1})})})});$i.displayName=Fi;var Do="MenuItemIndicator",[Bi,qg]=vt(Do,{checked:!1}),Ui=l.forwardRef((e,t)=>{const{__scopeMenu:r,forceMount:n,...o}=e,s=qg(Do,r);return i.jsx(_e,{present:n||en(s.checked)||s.checked===!0,children:i.jsx(Q.span,{...o,ref:t,"data-state":Lo(s.checked)})})});Ui.displayName=Do;var Xg="MenuSeparator",Hi=l.forwardRef((e,t)=>{const{__scopeMenu:r,...n}=e;return i.jsx(Q.div,{role:"separator","aria-orientation":"horizontal",...n,ref:t})});Hi.displayName=Xg;var Yg="MenuArrow",zi=l.forwardRef((e,t)=>{const{__scopeMenu:r,...n}=e,o=Jr(r);return i.jsx(wo,{...o,...n,ref:t})});zi.displayName=Yg;var Jg="MenuSub",[Hw,Wi]=vt(Jg),ar="MenuSubTrigger",Vi=l.forwardRef((e,t)=>{const r=wt(ar,e.__scopeMenu),n=sr(ar,e.__scopeMenu),o=Wi(ar,e.__scopeMenu),s=ko(ar,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(_o,{asChild:!0,...f,children:i.jsx(Oi,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":r.open,"aria-controls":o.contentId,"data-state":Ki(r.open),...e,ref:Rn(t,o.onTriggerChange),onClick:p=>{var m;(m=e.onClick)==null||m.call(e,p),!(e.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),r.open||r.onOpenChange(!0))},onPointerMove:U(e.onPointerMove,ir(p=>{s.onItemEnter(p),!p.defaultPrevented&&!e.disabled&&!r.open&&!a.current&&(s.onPointerGraceIntentChange(null),a.current=window.setTimeout(()=>{r.onOpenChange(!0),u()},100))})),onPointerLeave:U(e.onPointerLeave,ir(p=>{var v,g;u();const m=(v=r.content)==null?void 0:v.getBoundingClientRect();if(m){const h=(g=r.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===" "||kg[n.dir].includes(p.key)&&(r.onOpenChange(!0),(v=r.content)==null||v.focus(),p.preventDefault())})})})});Vi.displayName=ar;var ji="MenuSubContent",Ri=l.forwardRef((e,t)=>{const r=Ai(Le,e.__scopeMenu),{forceMount:n=r.forceMount,...o}=e,s=wt(Le,e.__scopeMenu),a=sr(Le,e.__scopeMenu),c=Wi(ji,e.__scopeMenu),d=l.useRef(null),f=se(t,d);return i.jsx(or.Provider,{scope:e.__scopeMenu,children:i.jsx(_e,{present:n||s.open,children:i.jsx(or.Slot,{scope:e.__scopeMenu,children:i.jsx(Oo,{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=Og[a.dir].includes(u.key);p&&m&&(s.onOpenChange(!1),(v=c.trigger)==null||v.focus(),u.preventDefault())})})})})})});Ri.displayName=ji;function Ki(e){return e?"open":"closed"}function en(e){return e==="indeterminate"}function Lo(e){return en(e)?"indeterminate":e?"checked":"unchecked"}function Zg(e){const t=document.activeElement;for(const r of e)if(r===t||(r.focus(),document.activeElement!==t))return}function Qg(e,t){return e.map((r,n)=>e[(t+n)%e.length])}function em(e,t,r){const o=t.length>1&&Array.from(t).every(f=>f===t[0])?t[0]:t,s=r?e.indexOf(r):-1;let a=Qg(e,Math.max(s,0));o.length===1&&(a=a.filter(f=>f!==r));const d=a.find(f=>f.toLowerCase().startsWith(o.toLowerCase()));return d!==r?d:void 0}function tm(e,t){const{x:r,y:n}=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>n!=m>n&&r<(p-f)*(n-u)/(m-u)+f&&(o=!o)}return o}function rm(e,t){if(!t)return!1;const r={x:e.clientX,y:e.clientY};return tm(r,t)}function ir(e){return t=>t.pointerType==="mouse"?e(t):void 0}var nm=Ti,om=_o,sm=Pi,am=_i,im=Mo,cm=Ii,lm=Qr,dm=Mi,um=Li,fm=$i,pm=Ui,hm=Hi,gm=zi,mm=Vi,bm=Ri,tn="DropdownMenu",[vm,zw]=Ue(tn,[Ei]),Ee=Ei(),[wm,Gi]=vm(tn),qi=e=>{const{__scopeDropdownMenu:t,children:r,dir:n,open:o,defaultOpen:s,onOpenChange:a,modal:c=!0}=e,d=Ee(t),f=l.useRef(null),[u,p]=st({prop:o,defaultProp:s??!1,onChange:a,caller:tn});return i.jsx(wm,{scope:t,triggerId:He(),triggerRef:f,contentId:He(),open:u,onOpenChange:p,onOpenToggle:l.useCallback(()=>p(m=>!m),[p]),modal:c,children:i.jsx(nm,{...d,open:u,onOpenChange:p,dir:n,modal:c,children:r})})};qi.displayName=tn;var Xi="DropdownMenuTrigger",Yi=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,disabled:n=!1,...o}=e,s=Gi(Xi,r),a=Ee(r);return i.jsx(om,{asChild:!0,...a,children:i.jsx(Q.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":n?"":void 0,disabled:n,...o,ref:Rn(t,s.triggerRef),onPointerDown:U(e.onPointerDown,c=>{!n&&c.button===0&&c.ctrlKey===!1&&(s.onOpenToggle(),s.open||c.preventDefault())}),onKeyDown:U(e.onKeyDown,c=>{n||(["Enter"," "].includes(c.key)&&s.onOpenToggle(),c.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(c.key)&&c.preventDefault())})})})});Yi.displayName=Xi;var ym="DropdownMenuPortal",Ji=e=>{const{__scopeDropdownMenu:t,...r}=e,n=Ee(t);return i.jsx(sm,{...n,...r})};Ji.displayName=ym;var Zi="DropdownMenuContent",Qi=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Gi(Zi,r),s=Ee(r),a=l.useRef(!1);return i.jsx(am,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...n,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)"}})});Qi.displayName=Zi;var xm="DropdownMenuGroup",Sm=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(im,{...o,...n,ref:t})});Sm.displayName=xm;var Cm="DropdownMenuLabel",ec=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(cm,{...o,...n,ref:t})});ec.displayName=Cm;var Em="DropdownMenuItem",tc=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(lm,{...o,...n,ref:t})});tc.displayName=Em;var Nm="DropdownMenuCheckboxItem",rc=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(dm,{...o,...n,ref:t})});rc.displayName=Nm;var Tm="DropdownMenuRadioGroup",Am=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(um,{...o,...n,ref:t})});Am.displayName=Tm;var Pm="DropdownMenuRadioItem",nc=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(fm,{...o,...n,ref:t})});nc.displayName=Pm;var _m="DropdownMenuItemIndicator",oc=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(pm,{...o,...n,ref:t})});oc.displayName=_m;var Im="DropdownMenuSeparator",sc=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(hm,{...o,...n,ref:t})});sc.displayName=Im;var km="DropdownMenuArrow",Om=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(gm,{...o,...n,ref:t})});Om.displayName=km;var Mm="DropdownMenuSubTrigger",ac=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(mm,{...o,...n,ref:t})});ac.displayName=Mm;var Dm="DropdownMenuSubContent",ic=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(bm,{...o,...n,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)"}})});ic.displayName=Dm;var Lm=qi,Fm=Yi,$m=Ji,cc=Qi,lc=ec,dc=tc,uc=rc,fc=nc,pc=oc,hc=sc,gc=ac,mc=ic;const Bm=Lm,Um=Fm,Hm=l.forwardRef(({className:e,inset:t,children:r,...n},o)=>i.jsxs(gc,{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),...n,children:[r,i.jsx(q.ChevronRight,{className:"ml-auto h-4 w-4"})]}));Hm.displayName=gc.displayName;const zm=l.forwardRef(({className:e,...t},r)=>i.jsx(mc,{ref:r,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}));zm.displayName=mc.displayName;const bc=l.forwardRef(({className:e,sideOffset:t=4,...r},n)=>i.jsx($m,{children:i.jsx(cc,{ref:n,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),...r})}));bc.displayName=cc.displayName;const vc=l.forwardRef(({className:e,inset:t,...r},n)=>i.jsx(dc,{ref:n,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),...r}));vc.displayName=dc.displayName;const Wm=l.forwardRef(({className:e,children:t,checked:r,...n},o)=>i.jsxs(uc,{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:r,...n,children:[i.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:i.jsx(pc,{children:i.jsx(q.Check,{className:"h-4 w-4"})})}),t]}));Wm.displayName=uc.displayName;const Vm=l.forwardRef(({className:e,children:t,...r},n)=>i.jsxs(fc,{ref:n,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),...r,children:[i.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:i.jsx(pc,{children:i.jsx(q.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));Vm.displayName=fc.displayName;const jm=l.forwardRef(({className:e,inset:t,...r},n)=>i.jsx(lc,{ref:n,className:A("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...r}));jm.displayName=lc.displayName;const Rm=l.forwardRef(({className:e,...t},r)=>i.jsx(hc,{ref:r,className:A("-mx-1 my-1 h-px bg-muted",e),...t}));Rm.displayName=hc.displayName;function cr({className:e="",placeholder:t="Type your message...",autoFocus:r=!0,maxHeight:n=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:C,hasMoreHistory:E,isLoadingHistory:O,loadOlderMessages:N}=jn(),[L,D]=T.useState(""),[$,R]=T.useState(null),[X,B]=T.useState(null),[M,J]=T.useState([]),[F,H]=T.useState(!1),[P,_]=T.useState([]),[G,j]=T.useState(null),Z=T.useRef(null),I=T.useRef(null),W=T.useRef(null),ge=T.useRef(null),he=T.useRef(!1),z=T.useRef(!0),ce=T.useRef(0),[pe,le]=T.useState("desktop");T.useEffect(()=>{const k=()=>{const Y=window.innerWidth;le(Y<640?"phone":Y<1024?"tablet":"desktop")};return k(),window.addEventListener("resize",k),()=>window.removeEventListener("resize",k)},[]);const de=T.useCallback(async()=>{if(!E||O)return;const k=ge.current;if(!k)return;const Y=k.scrollHeight,re=k.scrollTop;he.current=!0;try{await N()}catch(oe){console.warn("loadOlderMessages failed",oe)}finally{requestAnimationFrame(()=>{const oe=ge.current;if(!oe){he.current=!1;return}const ve=oe.scrollHeight;oe.scrollTop=re+(ve-Y);const ft=ve-oe.scrollTop-oe.clientHeight;z.current=ft<=32,he.current=!1})}},[E,O,N]);T.useEffect(()=>{const k=ge.current;if(!k)return;const Y=()=>{k.scrollTop<=80&&de();const ve=k.scrollHeight-k.scrollTop-k.clientHeight;z.current=ve<=80};return k.addEventListener("scroll",Y),()=>k.removeEventListener("scroll",Y)},[de]),T.useEffect(()=>{p.length<ce.current&&(z.current=!0),ce.current=p.length},[p.length]),T.useEffect(()=>{const k=ge.current;k&&(he.current||z.current&&(k.scrollTop=k.scrollHeight,z.current=!0))},[p]),T.useEffect(()=>{var k;r&&((k=I.current)==null||k.focus())},[r]),T.useEffect(()=>{g&&!F&&(f==null||f(g))},[g,F,f]),T.useEffect(()=>{let k=!0;if(!u){_([]),j(null);return}return y(u).then(Y=>{var ve;if(!k)return;const re=Y.checkpoints||[];_(re);const oe=((ve=re.slice().sort((ft,Te)=>new Date(Te.createdAt).getTime()-new Date(ft.createdAt).getTime())[0])==null?void 0:ve.checkpointId)||null;j(ft=>ft??oe)}).catch(()=>{}),()=>{k=!1}},[u,y]),T.useEffect(()=>{w&&j(w)},[w]);const ue=k=>{if(k.length>_t)return`Message too long (${k.length}/${_t} characters)`;try{return Yf(k),null}catch(Y){return(Y==null?void 0:Y.message)||"Invalid message"}},V=k=>{const Y=k.content||[],re=Y.filter(oe=>oe.type==="text").map(oe=>oe.text).join("");if(re)return re;try{return JSON.stringify(Y,null,2)}catch{return String(Y)}},K=k=>{var ft;if(!P.length)return[];const re=(((ft=p[k])==null?void 0:ft.role)??"user")==="user",oe=re?k+2:k+1;return P.filter(Te=>(Te.messagesLen??-1)>=(re?oe:0)).filter(Te=>re?(Te.messagesLen??0)>=oe:(Te.messagesLen??0)===oe).map(Te=>({checkpoint_id:Te.checkpointId,checkpoint_ns:Te.checkpointNs,message_count:Te.messagesLen??0,last_message_preview:Te.preview??void 0,ts:new Date(Te.createdAt).getTime(),isCurrent:Te.checkpointId===G})).sort((Te,mw)=>(Te.ts||0)-(mw.ts||0))},be=k=>{if(k===void 0)return{canGoBack:!1,canGoForward:!1,currentIndex:0,totalBranches:0};const Y=K(k);if(Y.length<=1)return{canGoBack:!1,canGoForward:!1,currentIndex:0,totalBranches:Y.length};const re=Math.max(0,Y.findIndex(oe=>oe.isCurrent));return{canGoBack:re>0,canGoForward:re<Y.length-1,currentIndex:re,totalBranches:Y.length}},ee=async()=>{const k=L.trim();if(!k&&M.length===0)return;const Y=ue(k);if(Y){B(Y);return}try{const re=window.__editingCheckpointId||G||void 0;await h(k,{checkpointId:re,payloadExtras:$?{edit:!0,originalMessageId:$}:void 0,attachments:M}),d==null||d(k),D(""),B(null),J([]),delete window.__editingCheckpointId,R(null),I.current&&(I.current.style.height="auto")}catch(re){const oe=(re==null?void 0:re.message)||"Failed to send message";B(oe),f==null||f(oe)}},ye=(k,Y)=>{a&&(R(k),D(Y),B(null),setTimeout(()=>{I.current&&(I.current.focus(),I.current.style.height="auto",I.current.style.height=I.current.scrollHeight+"px")},0))},ae=async(k,Y)=>{const re=p.find(ve=>ve.id===k);if(!re){B("Message not found");return}const oe=V(re);R(k),D(oe),window.__editingCheckpointId=Y,setTimeout(()=>{var ve;return(ve=I.current)==null?void 0:ve.focus()},0)},fe=()=>{R(null),D(""),B(null),delete window.__editingCheckpointId,I.current&&(I.current.style.height="auto")},Ne=k=>{k.key==="Enter"&&!k.shiftKey?(k.preventDefault(),ee()):k.key==="Escape"&&$&&(k.preventDefault(),fe())},ot=k=>{const Y=Array.from(k.target.files||[]);J(re=>[...re,...Y])},as=k=>J(Y=>Y.filter((re,oe)=>k!==oe)),Et=async k=>{u&&(await x(k),j(k))},ie=async()=>{await C(),j(null)},Ie=`flex flex-col h-full min-h-0 min-w-0 overflow-hidden bg-transparent ${e} ${c.container||""}`,ke=`flex-1 min-h-0 min-w-0 overflow-y-auto overflow-x-hidden break-words break-anywhere p-4 space-y-4 bg-transparent ${c.messagesArea||""}`,Re=`flex-shrink-0 border-t p-4 bg-transparent ${c.inputArea||""}`;return i.jsxs("div",{className:Ie,children:[!!g&&!F&&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(me,{variant:"ghost",size:"sm",onClick:()=>H(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:i.jsx(q.X,{size:16})})]}),u&&P.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(q.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:G??"",onChange:k=>{const Y=k.target.value||null;Y?Et(Y):ie()},children:[i.jsx("option",{value:"",children:"Latest"}),P.slice().sort((k,Y)=>new Date(Y.createdAt).getTime()-new Date(k.createdAt).getTime()).map(k=>i.jsxs("option",{value:k.checkpointId,children:[new Date(k.createdAt).toLocaleString(),k.preview?` — ${k.preview.slice(0,30)}`:""]},k.checkpointId))]})]}),i.jsxs("div",{ref:ge,className:ke,style:n?{maxHeight:n}: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!"}):i.jsxs(i.Fragment,{children:[(O||!E)&&i.jsx("div",{className:"flex justify-center py-2 text-xs text-muted-foreground",children:O?i.jsx(q.Loader2,{className:"h-4 w-4 animate-spin"}):"You've reached the beginning"}),p.map((k,Y)=>i.jsx(fa,{message:k,messageIndex:Y,isStreamingMessage:m&&v===k.id,streamingDebounceMs:o,isEditing:$===k.id,showActions:a,showTimestamp:!1,showAgentName:!0,layoutSize:pe,truncateToolMessages:!1,toolMessagePreviewLength:200,checkpointBranches:K(Y),currentCheckpointId:G??void 0,temporalNavigation:be(Y),onSwitchToCheckpoint:Et,onReturnToMainThread:ie,onNavigateToPreviousBranch:()=>{const re=K(Y),oe=Math.max(0,re.findIndex(ve=>ve.isCurrent));oe>0&&Et(re[oe-1].checkpoint_id)},onNavigateToNextBranch:()=>{const re=K(Y),oe=Math.max(0,re.findIndex(ve=>ve.isCurrent));oe>=0&&oe<re.length-1&&Et(re[oe+1].checkpoint_id)},onEdit:(re,oe)=>ye(re,oe),onEditFromCheckpoint:ae,onRegenerate:()=>{const re=[...p].reverse().find(ve=>ve.role==="user"),oe=re?V(re):"";oe&&h(oe,{checkpointId:G??void 0})},onCancelEdit:fe},k.id||Y))]}),i.jsx("div",{ref:Z})]}),i.jsxs("div",{className:Re,children:[$&&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(q.Edit3,{size:16,className:"text-blue-600"}),i.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),i.jsx(me,{variant:"ghost",size:"sm",onClick:fe,className:"text-blue-600 hover:bg-blue-100",children:i.jsx(q.X,{size:16})})]})}),s&&i.jsxs("div",{className:"mb-3",children:[i.jsx("input",{ref:W,type:"file",multiple:!0,onChange:k=>ot(k),className:"hidden"}),M.length>0&&i.jsx("div",{className:"mb-3 flex flex-wrap gap-2",children:M.map((k,Y)=>i.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 rounded-lg px-3 py-2 text-sm",children:[i.jsx(q.Paperclip,{size:14}),i.jsx("span",{className:"truncate max-w-[150px]",children:k.name}),i.jsx(me,{variant:"ghost",size:"sm",onClick:()=>as(Y),className:"h-4 w-4 p-0 text-gray-500 hover:text-red-500","aria-label":`Remove ${k.name}`,children:i.jsx(q.X,{size:12})})]},Y))})]}),X&&i.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:X}),i.jsxs("div",{className:"flex items-end gap-2",children:[s&&i.jsxs(Bm,{children:[i.jsx(Um,{asChild:!0,children:i.jsx(me,{type:"button",size:"icon",variant:"outline",disabled:m,title:"More input actions",className:c.moreButton||"",children:i.jsx(q.Plus,{size:16})})}),i.jsx(bc,{align:"start",sideOffset:6,className:"w-52",children:i.jsxs(vc,{onClick:()=>{var k;return(k=W.current)==null?void 0:k.click()},className:"cursor-pointer",children:[i.jsx(q.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]})})]}),i.jsx("div",{className:"flex-1",children:i.jsx(na,{ref:I,value:L,onChange:k=>{D(k.target.value),B(null),I.current&&(I.current.style.height="auto",I.current.style.height=`${I.current.scrollHeight}px`)},onKeyDown:Ne,placeholder:$?"Edit your message...":t,className:`resize-none min-h-[44px] max-h-[20rem] w-full ${$?"border-blue-400 bg-blue-50":""} ${X?"border-red-400":""} ${c.textarea||""}`,disabled:!1,maxLength:_t,rows:1})}),i.jsx("div",{children:m?i.jsx(me,{type:"button",onClick:b,size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",children:i.jsx(q.Square,{size:16})}):i.jsx(me,{type:"button",onClick:ee,size:"icon",disabled:!L.trim()&&M.length===0,className:`shrink-0 ${c.sendButton||""}`,title:$?"Save changes":"Send message",children:i.jsx(q.Send,{size:16})})})]}),L.length>_t*.8&&i.jsxs("div",{className:"mt-2 text-xs text-gray-500 text-right",children:[L.length,"/",_t]})]})]})}const lr=l.forwardRef(({className:e,type:t,...r},n)=>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:n,...r}));lr.displayName="Input";function Fo(e,[t,r]){return Math.min(r,Math.max(t,e))}function Km(e,t){return l.useReducer((r,n)=>t[r][n]??r,e)}var $o="ScrollArea",[wc,Ww]=Ue($o),[Gm,Fe]=wc($o),yc=l.forwardRef((e,t)=>{const{__scopeScrollArea:r,type:n="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,C]=l.useState(0),[E,O]=l.useState(!1),[N,L]=l.useState(!1),D=se(t,R=>d(R)),$=Ir(o);return i.jsx(Gm,{scope:r,type:n,dir:$,scrollHideDelay:s,scrollArea:c,viewport:f,onViewportChange:u,content:p,onContentChange:m,scrollbarX:v,onScrollbarXChange:g,scrollbarXEnabled:E,onScrollbarXEnabledChange:O,scrollbarY:h,onScrollbarYChange:b,scrollbarYEnabled:N,onScrollbarYEnabledChange:L,onCornerWidthChange:y,onCornerHeightChange:C,children:i.jsx(Q.div,{dir:$,...a,ref:D,style:{position:"relative","--radix-scroll-area-corner-width":w+"px","--radix-scroll-area-corner-height":x+"px",...e.style}})})});yc.displayName=$o;var xc="ScrollAreaViewport",Sc=l.forwardRef((e,t)=>{const{__scopeScrollArea:r,children:n,nonce:o,...s}=e,a=Fe(xc,r),c=l.useRef(null),d=se(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(Q.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:n})})]})});Sc.displayName=xc;var et="ScrollAreaScrollbar",Bo=l.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=Fe(et,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(qm,{...n,ref:t,forceMount:r}):o.type==="scroll"?i.jsx(Xm,{...n,ref:t,forceMount:r}):o.type==="auto"?i.jsx(Cc,{...n,ref:t,forceMount:r}):o.type==="always"?i.jsx(Uo,{...n,ref:t}):null});Bo.displayName=et;var qm=l.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=Fe(et,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(_e,{present:r||s,children:i.jsx(Cc,{"data-state":s?"visible":"hidden",...n,ref:t})})}),Xm=l.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=Fe(et,e.__scopeScrollArea),s=e.orientation==="horizontal",a=sn(()=>d("SCROLL_END"),100),[c,d]=Km("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(_e,{present:r||c!=="hidden",children:i.jsx(Uo,{"data-state":c==="hidden"?"hidden":"visible",...n,ref:t,onPointerEnter:U(e.onPointerEnter,()=>d("POINTER_ENTER")),onPointerLeave:U(e.onPointerLeave,()=>d("POINTER_LEAVE"))})})}),Cc=l.forwardRef((e,t)=>{const r=Fe(et,e.__scopeScrollArea),{forceMount:n,...o}=e,[s,a]=l.useState(!1),c=e.orientation==="horizontal",d=sn(()=>{if(r.viewport){const f=r.viewport.offsetWidth<r.viewport.scrollWidth,u=r.viewport.offsetHeight<r.viewport.scrollHeight;a(c?f:u)}},10);return Ut(r.viewport,d),Ut(r.content,d),i.jsx(_e,{present:n||s,children:i.jsx(Uo,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Uo=l.forwardRef((e,t)=>{const{orientation:r="vertical",...n}=e,o=Fe(et,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=Pc(c.viewport,c.content),u={...n,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 tb(m,a.current,c,v)}return r==="horizontal"?i.jsx(Ym,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const m=o.viewport.scrollLeft,v=_c(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))}}):r==="vertical"?i.jsx(Jm,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const m=o.viewport.scrollTop,v=_c(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}),Ym=l.forwardRef((e,t)=>{const{sizes:r,onSizesChange:n,...o}=e,s=Fe(et,e.__scopeScrollArea),[a,c]=l.useState(),d=l.useRef(null),f=se(t,d,s.onScrollbarXChange);return l.useEffect(()=>{d.current&&c(getComputedStyle(d.current))},[d]),i.jsx(Nc,{"data-orientation":"horizontal",...o,ref:f,sizes:r,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":on(r)+"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),kc(m,p)&&u.preventDefault()}},onResize:()=>{d.current&&s.viewport&&a&&n({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:d.current.clientWidth,paddingStart:nn(a.paddingLeft),paddingEnd:nn(a.paddingRight)}})}})}),Jm=l.forwardRef((e,t)=>{const{sizes:r,onSizesChange:n,...o}=e,s=Fe(et,e.__scopeScrollArea),[a,c]=l.useState(),d=l.useRef(null),f=se(t,d,s.onScrollbarYChange);return l.useEffect(()=>{d.current&&c(getComputedStyle(d.current))},[d]),i.jsx(Nc,{"data-orientation":"vertical",...o,ref:f,sizes:r,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":on(r)+"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),kc(m,p)&&u.preventDefault()}},onResize:()=>{d.current&&s.viewport&&a&&n({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:d.current.clientHeight,paddingStart:nn(a.paddingTop),paddingEnd:nn(a.paddingBottom)}})}})}),[Zm,Ec]=wc(et),Nc=l.forwardRef((e,t)=>{const{__scopeScrollArea:r,sizes:n,hasThumb:o,onThumbChange:s,onThumbPointerUp:a,onThumbPointerDown:c,onThumbPositionChange:d,onDragScroll:f,onWheelScroll:u,onResize:p,...m}=e,v=Fe(et,r),[g,h]=l.useState(null),b=se(t,D=>h(D)),w=l.useRef(null),y=l.useRef(""),x=v.viewport,C=n.content-n.viewport,E=Se(u),O=Se(d),N=sn(p,10);function L(D){if(w.current){const $=D.clientX-w.current.left,R=D.clientY-w.current.top;f({x:$,y:R})}}return l.useEffect(()=>{const D=$=>{const R=$.target;(g==null?void 0:g.contains(R))&&E($,C)};return document.addEventListener("wheel",D,{passive:!1}),()=>document.removeEventListener("wheel",D,{passive:!1})},[x,g,C,E]),l.useEffect(O,[n,O]),Ut(g,N),Ut(v.content,N),i.jsx(Zm,{scope:r,scrollbar:g,hasThumb:o,onThumbChange:Se(s),onThumbPointerUp:Se(a),onThumbPositionChange:O,onThumbPointerDown:Se(c),children:i.jsx(Q.div,{...m,ref:b,style:{position:"absolute",...m.style},onPointerDown:U(e.onPointerDown,D=>{D.button===0&&(D.target.setPointerCapture(D.pointerId),w.current=g.getBoundingClientRect(),y.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",v.viewport&&(v.viewport.style.scrollBehavior="auto"),L(D))}),onPointerMove:U(e.onPointerMove,L),onPointerUp:U(e.onPointerUp,D=>{const $=D.target;$.hasPointerCapture(D.pointerId)&&$.releasePointerCapture(D.pointerId),document.body.style.webkitUserSelect=y.current,v.viewport&&(v.viewport.style.scrollBehavior=""),w.current=null})})})}),rn="ScrollAreaThumb",Tc=l.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=Ec(rn,e.__scopeScrollArea);return i.jsx(_e,{present:r||o.hasThumb,children:i.jsx(Qm,{ref:t,...n})})}),Qm=l.forwardRef((e,t)=>{const{__scopeScrollArea:r,style:n,...o}=e,s=Fe(rn,r),a=Ec(rn,r),{onThumbPositionChange:c}=a,d=se(t,p=>a.onThumbChange(p)),f=l.useRef(void 0),u=sn(()=>{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=rb(p,c);f.current=v,c()}};return c(),p.addEventListener("scroll",m),()=>p.removeEventListener("scroll",m)}},[s.viewport,u,c]),i.jsx(Q.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)",...n},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)})});Tc.displayName=rn;var Ho="ScrollAreaCorner",Ac=l.forwardRef((e,t)=>{const r=Fe(Ho,e.__scopeScrollArea),n=!!(r.scrollbarX&&r.scrollbarY);return r.type!=="scroll"&&n?i.jsx(eb,{...e,ref:t}):null});Ac.displayName=Ho;var eb=l.forwardRef((e,t)=>{const{__scopeScrollArea:r,...n}=e,o=Fe(Ho,r),[s,a]=l.useState(0),[c,d]=l.useState(0),f=!!(s&&c);return Ut(o.scrollbarX,()=>{var p;const u=((p=o.scrollbarX)==null?void 0:p.offsetHeight)||0;o.onCornerHeightChange(u),d(u)}),Ut(o.scrollbarY,()=>{var p;const u=((p=o.scrollbarY)==null?void 0:p.offsetWidth)||0;o.onCornerWidthChange(u),a(u)}),f?i.jsx(Q.div,{...n,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 nn(e){return e?parseInt(e,10):0}function Pc(e,t){const r=e/t;return isNaN(r)?0:r}function on(e){const t=Pc(e.viewport,e.content),r=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,n=(e.scrollbar.size-r)*t;return Math.max(n,18)}function tb(e,t,r,n="ltr"){const o=on(r),s=o/2,a=t||s,c=o-a,d=r.scrollbar.paddingStart+a,f=r.scrollbar.size-r.scrollbar.paddingEnd-c,u=r.content-r.viewport,p=n==="ltr"?[0,u]:[u*-1,0];return Ic([d,f],p)(e)}function _c(e,t,r="ltr"){const n=on(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,a=t.content-t.viewport,c=s-n,d=r==="ltr"?[0,a]:[a*-1,0],f=Fo(e,d);return Ic([0,a],[0,c])(f)}function Ic(e,t){return r=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const n=(t[1]-t[0])/(e[1]-e[0]);return t[0]+n*(r-e[0])}}function kc(e,t){return e>0&&e<t}var rb=(e,t=()=>{})=>{let r={left:e.scrollLeft,top:e.scrollTop},n=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},a=r.left!==s.left,c=r.top!==s.top;(a||c)&&t(),r=s,n=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(n)};function sn(e,t){const r=Se(e),n=l.useRef(0);return l.useEffect(()=>()=>window.clearTimeout(n.current),[]),l.useCallback(()=>{window.clearTimeout(n.current),n.current=window.setTimeout(r,t)},[r,t])}function Ut(e,t){const r=Se(t);xe(()=>{let n=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(n),n=window.requestAnimationFrame(r)});return o.observe(e),()=>{window.cancelAnimationFrame(n),o.unobserve(e)}}},[e,r])}var Oc=yc,nb=Sc,ob=Ac;const Mc=l.forwardRef(({className:e,children:t,...r},n)=>i.jsxs(Oc,{ref:n,className:A("relative overflow-hidden",e),...r,children:[i.jsx(nb,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),i.jsx(Dc,{}),i.jsx(ob,{})]}));Mc.displayName=Oc.displayName;const Dc=l.forwardRef(({className:e,orientation:t="vertical",...r},n)=>i.jsx(Bo,{ref:n,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),...r,children:i.jsx(Tc,{className:"relative flex-1 rounded-full bg-border"})}));Dc.displayName=Bo.displayName;function an({className:e="",showCreateButton:t=!0,showDeleteButton:r=!0,showEditTitle:n=!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}=jn(),[y,x]=T.useState(m??[]),[C,E]=T.useState(!1),[O,N]=T.useState(null),[L,D]=T.useState(null),[$,R]=T.useState(""),[X,B]=T.useState(!1);T.useEffect(()=>{x(m??[])},[m]);const M=async I=>{try{await p(I),c==null||c(I),d==null||d(I)}catch(W){console.error("Failed to select thread:",W)}},J=async()=>{try{B(!0);const I=await h();f==null||f(I),c==null||c(I)}catch(I){console.error("Failed to create thread:",I)}finally{B(!1)}},F=async(I,W)=>{if(W.stopPropagation(),!!confirm("Delete this thread?"))try{await b(I),u==null||u(I)}catch(ge){console.error("Failed to delete thread:",ge)}},H=(I,W)=>{W.stopPropagation(),D(I.threadId),R(I.title||`Thread ${I.threadId.slice(0,8)}`)},P=async I=>{if($.trim())try{await w(I,$.trim()),D(null),R("")}catch(W){console.error("Failed to update title:",W)}},_=()=>{D(null),R("")},G=(I,W)=>{I.key==="Enter"?P(W):I.key==="Escape"&&_()},j=I=>{if(!I)return"";try{const W=new Date(I),he=new Date().getTime()-W.getTime(),z=Math.floor(he/(1e3*60*60*24));return z===0?W.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):z===1?"Yesterday":z<7?`${z} days ago`:W.toLocaleDateString()}catch{return""}},Z=I=>I.title||`Thread ${I.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(me,{onClick:J,disabled:X||C,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:X?"Creating...":"New Chat",children:i.jsx(q.MessageSquarePlus,{size:20})})}),i.jsx(Mc,{className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:i.jsx("div",{className:"p-2 space-y-1 pb-4",children:C?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(q.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((I,W)=>new Date(W.updatedAt||W.createdAt||"").getTime()-new Date(I.updatedAt||I.createdAt||"").getTime()).map(I=>i.jsxs("div",{onClick:()=>M(I.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(a??g)===I.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:L===I.threadId?i.jsxs("div",{className:"flex items-center gap-2",onClick:W=>W.stopPropagation(),children:[i.jsx(lr,{value:$,onChange:W=>R(W.target.value),onKeyDown:W=>G(W,I.threadId),className:"h-6 text-sm",autoFocus:!0}),i.jsx(me,{variant:"ghost",size:"sm",onClick:()=>P(I.threadId),className:"h-6 w-6 p-0",children:i.jsx(q.Check,{size:12})}),i.jsx(me,{variant:"ghost",size:"sm",onClick:_,className:"h-6 w-6 p-0",children:i.jsx(q.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:Z(I)}),i.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[i.jsx(q.Calendar,{size:10}),i.jsx("span",{children:j(I.updatedAt||I.createdAt)})]})]})}),i.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[n&&L!==I.threadId&&i.jsx(me,{variant:"ghost",size:"sm",onClick:W=>H(I,W),className:"h-6 w-6 p-0",title:"Edit title",children:i.jsx(q.Edit3,{size:12})}),r&&i.jsx(me,{variant:"ghost",size:"sm",onClick:W=>F(I.threadId,W),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(q.Trash2,{size:12})})]})]}),a===I.threadId&&i.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},I.threadId))})})]})}const Lc=T.createContext(null);function sb({children:e,basePath:t="/chat"}){const r=T.useMemo(()=>t?t==="/"?"":t.endsWith("/")?t.slice(0,-1):t:"/chat",[t]),n={basePath:r,buildThreadPath:o=>`${r}/${o}`,buildBasePath:()=>r};return i.jsx(Lc.Provider,{value:n,children:e})}function ab(){const e=T.useContext(Lc);return e||{basePath:"/chat",buildThreadPath:t=>`/chat/${t}`,buildBasePath:()=>"/chat"}}const Fc={BASE_URL:"/",DEV:!1,MODE:"library",PROD:!0,SSR:!1};function dr(e){var o;const t=typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Nn&&Nn.tagName.toUpperCase()==="SCRIPT"&&Nn.src||new URL("index.umd.js",document.baseURI).href}<"u"&&Fc?Fc[e]:void 0,r=(o=globalThis==null?void 0:globalThis.process)==null?void 0:o.env,n=r?r[e]:void 0;return(t??n)||void 0}function ib(){return dr("VITE_API_BASE_URL")||dr("NEXT_PUBLIC_API_BASE_URL")||void 0}function cb(){return dr("VITE_API_KEY")||dr("NEXT_PUBLIC_API_KEY")||dr("VITE_AUTH_TOKEN")||void 0}function $c(){const e=ib(),t=cb(),r={};return e&&(r.baseUrl=e),t&&(r.apiKey=t),r}function Bc(){const e=$c(),t=tt.getAuthToken();return{apiBaseUrl:e.baseUrl||tt.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 Uc="chat-settings";function lb(){try{const e=localStorage.getItem(Uc);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function db(e){try{localStorage.setItem(Uc,JSON.stringify(e)),e.apiKey&&tt.setAuthToken(e.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function ub(){const e=Bc(),t=lb(),r=tt.getAuthToken();return{...e,...t,apiKey:r||t.apiKey||e.apiKey,apiBaseUrl:tt.baseUrl||t.apiBaseUrl||e.apiBaseUrl}}function fb(e){e.apiKey&&tt.setAuthToken(e.apiKey),db(e)}const zo=768;function pb(){const[e,t]=l.useState(void 0);return l.useEffect(()=>{const r=window.matchMedia(`(max-width: ${zo-1}px)`),n=()=>{t(window.innerWidth<zo)};return r.addEventListener("change",n),t(window.innerWidth<zo),()=>r.removeEventListener("change",n)},[]),!!e}var hb="Separator",Hc="horizontal",gb=["horizontal","vertical"],zc=l.forwardRef((e,t)=>{const{decorative:r,orientation:n=Hc,...o}=e,s=mb(n)?n:Hc,c=r?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return i.jsx(Q.div,{"data-orientation":s,...c,...o,ref:t})});zc.displayName=hb;function mb(e){return gb.includes(e)}var Wc=zc;const Wo=l.forwardRef(({className:e,orientation:t="horizontal",decorative:r=!0,...n},o)=>i.jsx(Wc,{ref:o,decorative:r,orientation:t,className:A("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...n}));Wo.displayName=Wc.displayName;var cn="Dialog",[Vc,Vw]=Ue(cn),[bb,Ve]=Vc(cn),jc=e=>{const{__scopeDialog:t,children:r,open:n,defaultOpen:o,onOpenChange:s,modal:a=!0}=e,c=l.useRef(null),d=l.useRef(null),[f,u]=st({prop:n,defaultProp:o??!1,onChange:s,caller:cn});return i.jsx(bb,{scope:t,triggerRef:c,contentRef:d,contentId:He(),titleId:He(),descriptionId:He(),open:f,onOpenChange:u,onOpenToggle:l.useCallback(()=>u(p=>!p),[u]),modal:a,children:r})};jc.displayName=cn;var Rc="DialogTrigger",Kc=l.forwardRef((e,t)=>{const{__scopeDialog:r,...n}=e,o=Ve(Rc,r),s=se(t,o.triggerRef);return i.jsx(Q.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Ro(o.open),...n,ref:s,onClick:U(e.onClick,o.onOpenToggle)})});Kc.displayName=Rc;var Vo="DialogPortal",[vb,Gc]=Vc(Vo,{forceMount:void 0}),qc=e=>{const{__scopeDialog:t,forceMount:r,children:n,container:o}=e,s=Ve(Vo,t);return i.jsx(vb,{scope:t,forceMount:r,children:l.Children.map(n,a=>i.jsx(_e,{present:r||s.open,children:i.jsx(Wr,{asChild:!0,container:o,children:a})}))})};qc.displayName=Vo;var ln="DialogOverlay",Xc=l.forwardRef((e,t)=>{const r=Gc(ln,e.__scopeDialog),{forceMount:n=r.forceMount,...o}=e,s=Ve(ln,e.__scopeDialog);return s.modal?i.jsx(_e,{present:n||s.open,children:i.jsx(yb,{...o,ref:t})}):null});Xc.displayName=ln;var wb=Oe.createSlot("DialogOverlay.RemoveScroll"),yb=l.forwardRef((e,t)=>{const{__scopeDialog:r,...n}=e,o=Ve(ln,r);return i.jsx(Yr,{as:wb,allowPinchZoom:!0,shards:[o.contentRef],children:i.jsx(Q.div,{"data-state":Ro(o.open),...n,ref:t,style:{pointerEvents:"auto",...n.style}})})}),yt="DialogContent",Yc=l.forwardRef((e,t)=>{const r=Gc(yt,e.__scopeDialog),{forceMount:n=r.forceMount,...o}=e,s=Ve(yt,e.__scopeDialog);return i.jsx(_e,{present:n||s.open,children:s.modal?i.jsx(xb,{...o,ref:t}):i.jsx(Sb,{...o,ref:t})})});Yc.displayName=yt;var xb=l.forwardRef((e,t)=>{const r=Ve(yt,e.__scopeDialog),n=l.useRef(null),o=se(t,r.contentRef,n);return l.useEffect(()=>{const s=n.current;if(s)return Co(s)},[]),i.jsx(Jc,{...e,ref:o,trapFocus:r.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:U(e.onCloseAutoFocus,s=>{var a;s.preventDefault(),(a=r.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())})}),Sb=l.forwardRef((e,t)=>{const r=Ve(yt,e.__scopeDialog),n=l.useRef(!1),o=l.useRef(!1);return i.jsx(Jc,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var a,c;(a=e.onCloseAutoFocus)==null||a.call(e,s),s.defaultPrevented||(n.current||(c=r.triggerRef.current)==null||c.focus(),s.preventDefault()),n.current=!1,o.current=!1},onInteractOutside:s=>{var d,f;(d=e.onInteractOutside)==null||d.call(e,s),s.defaultPrevented||(n.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const a=s.target;((f=r.triggerRef.current)==null?void 0:f.contains(a))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),Jc=l.forwardRef((e,t)=>{const{__scopeDialog:r,trapFocus:n,onOpenAutoFocus:o,onCloseAutoFocus:s,...a}=e,c=Ve(yt,r),d=l.useRef(null),f=se(t,d);return Qn(),i.jsxs(i.Fragment,{children:[i.jsx(kr,{asChild:!0,loop:!0,trapped:n,onMountAutoFocus:o,onUnmountAutoFocus:s,children:i.jsx(Zt,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionId,"aria-labelledby":c.titleId,"data-state":Ro(c.open),...a,ref:f,onDismiss:()=>c.onOpenChange(!1)})}),i.jsxs(i.Fragment,{children:[i.jsx(Cb,{titleId:c.titleId}),i.jsx(Nb,{contentRef:d,descriptionId:c.descriptionId})]})]})}),jo="DialogTitle",Zc=l.forwardRef((e,t)=>{const{__scopeDialog:r,...n}=e,o=Ve(jo,r);return i.jsx(Q.h2,{id:o.titleId,...n,ref:t})});Zc.displayName=jo;var Qc="DialogDescription",el=l.forwardRef((e,t)=>{const{__scopeDialog:r,...n}=e,o=Ve(Qc,r);return i.jsx(Q.p,{id:o.descriptionId,...n,ref:t})});el.displayName=Qc;var tl="DialogClose",rl=l.forwardRef((e,t)=>{const{__scopeDialog:r,...n}=e,o=Ve(tl,r);return i.jsx(Q.button,{type:"button",...n,ref:t,onClick:U(e.onClick,()=>o.onOpenChange(!1))})});rl.displayName=tl;function Ro(e){return e?"open":"closed"}var nl="DialogTitleWarning",[jw,ol]=wf(nl,{contentName:yt,titleName:jo,docsSlug:"dialog"}),Cb=({titleId:e})=>{const t=ol(nl),r=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
|
|
58
|
+
`)},Ng=0,Bt=[];function Tg(e){var t=l.useRef([]),r=l.useRef([0,0]),n=l.useRef(),o=l.useState(Ng++)[0],s=l.useState(gi)[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=Gh([e.lockRef.current],(e.shards||[]).map(Si),!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=Xr(h),y=r.current,x="deltaX"in h?h.deltaX:y[0]-w[0],C="deltaY"in h?h.deltaY:y[1]-w[1],E,O=h.target,N=Math.abs(x)>Math.abs(C)?"h":"v";if("touches"in h&&N==="h"&&O.type==="range")return!1;var L=vi(N,O);if(!L)return!0;if(L?E=N:(E=N==="v"?"h":"v",L=vi(N,O)),!L)return!1;if(!n.current&&"changedTouches"in h&&(x||C)&&(n.current=E),!E)return!0;var D=n.current||E;return Sg(D,b,h,D==="h"?x:C)},[]),d=l.useCallback(function(h){var b=h;if(!(!Bt.length||Bt[Bt.length-1]!==s)){var w="deltaY"in b?xi(b):Xr(b),y=t.current.filter(function(E){return E.name===b.type&&(E.target===b.target||b.target===E.shadowParent)&&Cg(E.delta,w)})[0];if(y&&y.should){b.cancelable&&b.preventDefault();return}if(!y){var x=(a.current.shards||[]).map(Si).filter(Boolean).filter(function(E){return E.contains(b.target)}),C=x.length>0?c(b,x[0]):!a.current.noIsolation;C&&b.cancelable&&b.preventDefault()}}},[]),f=l.useCallback(function(h,b,w,y){var x={name:h,delta:b,target:w,should:y,shadowParent:Ag(w)};t.current.push(x),setTimeout(function(){t.current=t.current.filter(function(C){return C!==x})},1)},[]),u=l.useCallback(function(h){r.current=Xr(h),n.current=void 0},[]),p=l.useCallback(function(h){f(h.type,xi(h),h.target,c(h,e.lockRef.current))},[]),m=l.useCallback(function(h){f(h.type,Xr(h),h.target,c(h,e.lockRef.current))},[]);l.useEffect(function(){return Bt.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(){Bt=Bt.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:Eg(o)}):null,v?l.createElement(gg,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Ag(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Pg=rg(hi,Tg);var Yr=l.forwardRef(function(e,t){return l.createElement(Gr,Qe({},e,{ref:t,sideCar:Pg}))});Yr.classNames=Gr.classNames;var Po=["Enter"," "],_g=["ArrowDown","PageUp","Home"],Ci=["ArrowUp","PageDown","End"],Ig=[..._g,...Ci],kg={ltr:[...Po,"ArrowRight"],rtl:[...Po,"ArrowLeft"]},Og={ltr:["ArrowLeft"],rtl:["ArrowRight"]},nr="Menu",[or,Mg,Dg]=Yn(nr),[vt,Ei]=Ue(nr,[Dg,Dt,si]),Jr=Dt(),Ni=si(),[Lg,wt]=vt(nr),[Fg,sr]=vt(nr),Ti=e=>{const{__scopeMenu:t,open:r=!1,children:n,dir:o,onOpenChange:s,modal:a=!0}=e,c=Jr(t),[d,f]=l.useState(null),u=l.useRef(!1),p=Se(s),m=Ir(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(mo,{...c,children:i.jsx(Lg,{scope:t,open:r,onOpenChange:p,content:d,onContentChange:f,children:i.jsx(Fg,{scope:t,onClose:l.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:u,dir:m,modal:a,children:n})})})};Ti.displayName=nr;var $g="MenuAnchor",_o=l.forwardRef((e,t)=>{const{__scopeMenu:r,...n}=e,o=Jr(r);return i.jsx(bo,{...o,...n,ref:t})});_o.displayName=$g;var Io="MenuPortal",[Bg,Ai]=vt(Io,{forceMount:void 0}),Pi=e=>{const{__scopeMenu:t,forceMount:r,children:n,container:o}=e,s=wt(Io,t);return i.jsx(Bg,{scope:t,forceMount:r,children:i.jsx(_e,{present:r||s.open,children:i.jsx(Wr,{asChild:!0,container:o,children:n})})})};Pi.displayName=Io;var Le="MenuContent",[Ug,ko]=vt(Le),_i=l.forwardRef((e,t)=>{const r=Ai(Le,e.__scopeMenu),{forceMount:n=r.forceMount,...o}=e,s=wt(Le,e.__scopeMenu),a=sr(Le,e.__scopeMenu);return i.jsx(or.Provider,{scope:e.__scopeMenu,children:i.jsx(_e,{present:n||s.open,children:i.jsx(or.Slot,{scope:e.__scopeMenu,children:a.modal?i.jsx(Hg,{...o,ref:t}):i.jsx(zg,{...o,ref:t})})})})}),Hg=l.forwardRef((e,t)=>{const r=wt(Le,e.__scopeMenu),n=l.useRef(null),o=se(t,n);return l.useEffect(()=>{const s=n.current;if(s)return Co(s)},[]),i.jsx(Oo,{...e,ref:o,trapFocus:r.open,disableOutsidePointerEvents:r.open,disableOutsideScroll:!0,onFocusOutside:U(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>r.onOpenChange(!1)})}),zg=l.forwardRef((e,t)=>{const r=wt(Le,e.__scopeMenu);return i.jsx(Oo,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>r.onOpenChange(!1)})}),Wg=Oe.createSlot("MenuContent.ScrollLock"),Oo=l.forwardRef((e,t)=>{const{__scopeMenu:r,loop:n=!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=wt(Le,r),w=sr(Le,r),y=Jr(r),x=Ni(r),C=Mg(r),[E,O]=l.useState(null),N=l.useRef(null),L=se(t,N,b.onContentChange),D=l.useRef(0),$=l.useRef(""),R=l.useRef(0),X=l.useRef(null),B=l.useRef("right"),M=l.useRef(0),J=g?Yr:l.Fragment,F=g?{as:Wg,allowPinchZoom:!0}:void 0,H=_=>{var z,ce;const G=$.current+_,j=C().filter(pe=>!pe.disabled),Z=document.activeElement,I=(z=j.find(pe=>pe.ref.current===Z))==null?void 0:z.textValue,W=j.map(pe=>pe.textValue),ge=em(W,G,I),he=(ce=j.find(pe=>pe.textValue===ge))==null?void 0:ce.ref.current;(function pe(le){$.current=le,window.clearTimeout(D.current),le!==""&&(D.current=window.setTimeout(()=>pe(""),1e3))})(G),he&&setTimeout(()=>he.focus())};l.useEffect(()=>()=>window.clearTimeout(D.current),[]),Qn();const P=l.useCallback(_=>{var j,Z;return B.current===((j=X.current)==null?void 0:j.side)&&rm(_,(Z=X.current)==null?void 0:Z.area)},[]);return i.jsx(Ug,{scope:r,searchRef:$,onItemEnter:l.useCallback(_=>{P(_)&&_.preventDefault()},[P]),onItemLeave:l.useCallback(_=>{var G;P(_)||((G=N.current)==null||G.focus(),O(null))},[P]),onTriggerLeave:l.useCallback(_=>{P(_)&&_.preventDefault()},[P]),pointerGraceTimerRef:R,onPointerGraceIntentChange:l.useCallback(_=>{X.current=_},[]),children:i.jsx(J,{...F,children:i.jsx(kr,{asChild:!0,trapped:o,onMountAutoFocus:U(s,_=>{var G;_.preventDefault(),(G=N.current)==null||G.focus({preventScroll:!0})}),onUnmountAutoFocus:a,children:i.jsx(Zt,{asChild:!0,disableOutsidePointerEvents:c,onEscapeKeyDown:f,onPointerDownOutside:u,onFocusOutside:p,onInteractOutside:m,onDismiss:v,children:i.jsx(Wh,{asChild:!0,...x,dir:w.dir,orientation:"vertical",loop:n,currentTabStopId:E,onCurrentTabStopIdChange:O,onEntryFocus:U(d,_=>{w.isUsingKeyboardRef.current||_.preventDefault()}),preventScrollOnEntryFocus:!0,children:i.jsx(vo,{role:"menu","aria-orientation":"vertical","data-state":Ki(b.open),"data-radix-menu-content":"",dir:w.dir,...y,...h,ref:L,style:{outline:"none",...h.style},onKeyDown:U(h.onKeyDown,_=>{const j=_.target.closest("[data-radix-menu-content]")===_.currentTarget,Z=_.ctrlKey||_.altKey||_.metaKey,I=_.key.length===1;j&&(_.key==="Tab"&&_.preventDefault(),!Z&&I&&H(_.key));const W=N.current;if(_.target!==W||!Ig.includes(_.key))return;_.preventDefault();const he=C().filter(z=>!z.disabled).map(z=>z.ref.current);Ci.includes(_.key)&&he.reverse(),Zg(he)}),onBlur:U(e.onBlur,_=>{_.currentTarget.contains(_.target)||(window.clearTimeout(D.current),$.current="")}),onPointerMove:U(e.onPointerMove,ir(_=>{const G=_.target,j=M.current!==_.clientX;if(_.currentTarget.contains(G)&&j){const Z=_.clientX>M.current?"right":"left";B.current=Z,M.current=_.clientX}}))})})})})})})});_i.displayName=Le;var Vg="MenuGroup",Mo=l.forwardRef((e,t)=>{const{__scopeMenu:r,...n}=e;return i.jsx(Q.div,{role:"group",...n,ref:t})});Mo.displayName=Vg;var jg="MenuLabel",Ii=l.forwardRef((e,t)=>{const{__scopeMenu:r,...n}=e;return i.jsx(Q.div,{...n,ref:t})});Ii.displayName=jg;var Zr="MenuItem",ki="menu.itemSelect",Qr=l.forwardRef((e,t)=>{const{disabled:r=!1,onSelect:n,...o}=e,s=l.useRef(null),a=sr(Zr,e.__scopeMenu),c=ko(Zr,e.__scopeMenu),d=se(t,s),f=l.useRef(!1),u=()=>{const p=s.current;if(!r&&p){const m=new CustomEvent(ki,{bubbles:!0,cancelable:!0});p.addEventListener(ki,v=>n==null?void 0:n(v),{once:!0}),aa(p,m),m.defaultPrevented?f.current=!1:a.onClose()}};return i.jsx(Oi,{...o,ref:d,disabled:r,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!=="";r||m&&p.key===" "||Po.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});Qr.displayName=Zr;var Oi=l.forwardRef((e,t)=>{const{__scopeMenu:r,disabled:n=!1,textValue:o,...s}=e,a=ko(Zr,r),c=Ni(r),d=l.useRef(null),f=se(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(or.ItemSlot,{scope:r,disabled:n,textValue:o??m,children:i.jsx(Vh,{asChild:!0,...c,focusable:!n,children:i.jsx(Q.div,{role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":n||void 0,"data-disabled":n?"":void 0,...s,ref:f,onPointerMove:U(e.onPointerMove,ir(g=>{n?a.onItemLeave(g):(a.onItemEnter(g),g.defaultPrevented||g.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:U(e.onPointerLeave,ir(g=>a.onItemLeave(g))),onFocus:U(e.onFocus,()=>p(!0)),onBlur:U(e.onBlur,()=>p(!1))})})})}),Rg="MenuCheckboxItem",Mi=l.forwardRef((e,t)=>{const{checked:r=!1,onCheckedChange:n,...o}=e;return i.jsx(Bi,{scope:e.__scopeMenu,checked:r,children:i.jsx(Qr,{role:"menuitemcheckbox","aria-checked":en(r)?"mixed":r,...o,ref:t,"data-state":Lo(r),onSelect:U(o.onSelect,()=>n==null?void 0:n(en(r)?!0:!r),{checkForDefaultPrevented:!1})})})});Mi.displayName=Rg;var Di="MenuRadioGroup",[Kg,Gg]=vt(Di,{value:void 0,onValueChange:()=>{}}),Li=l.forwardRef((e,t)=>{const{value:r,onValueChange:n,...o}=e,s=Se(n);return i.jsx(Kg,{scope:e.__scopeMenu,value:r,onValueChange:s,children:i.jsx(Mo,{...o,ref:t})})});Li.displayName=Di;var Fi="MenuRadioItem",$i=l.forwardRef((e,t)=>{const{value:r,...n}=e,o=Gg(Fi,e.__scopeMenu),s=r===o.value;return i.jsx(Bi,{scope:e.__scopeMenu,checked:s,children:i.jsx(Qr,{role:"menuitemradio","aria-checked":s,...n,ref:t,"data-state":Lo(s),onSelect:U(n.onSelect,()=>{var a;return(a=o.onValueChange)==null?void 0:a.call(o,r)},{checkForDefaultPrevented:!1})})})});$i.displayName=Fi;var Do="MenuItemIndicator",[Bi,qg]=vt(Do,{checked:!1}),Ui=l.forwardRef((e,t)=>{const{__scopeMenu:r,forceMount:n,...o}=e,s=qg(Do,r);return i.jsx(_e,{present:n||en(s.checked)||s.checked===!0,children:i.jsx(Q.span,{...o,ref:t,"data-state":Lo(s.checked)})})});Ui.displayName=Do;var Xg="MenuSeparator",Hi=l.forwardRef((e,t)=>{const{__scopeMenu:r,...n}=e;return i.jsx(Q.div,{role:"separator","aria-orientation":"horizontal",...n,ref:t})});Hi.displayName=Xg;var Yg="MenuArrow",zi=l.forwardRef((e,t)=>{const{__scopeMenu:r,...n}=e,o=Jr(r);return i.jsx(wo,{...o,...n,ref:t})});zi.displayName=Yg;var Jg="MenuSub",[Hw,Wi]=vt(Jg),ar="MenuSubTrigger",Vi=l.forwardRef((e,t)=>{const r=wt(ar,e.__scopeMenu),n=sr(ar,e.__scopeMenu),o=Wi(ar,e.__scopeMenu),s=ko(ar,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(_o,{asChild:!0,...f,children:i.jsx(Oi,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":r.open,"aria-controls":o.contentId,"data-state":Ki(r.open),...e,ref:Rn(t,o.onTriggerChange),onClick:p=>{var m;(m=e.onClick)==null||m.call(e,p),!(e.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),r.open||r.onOpenChange(!0))},onPointerMove:U(e.onPointerMove,ir(p=>{s.onItemEnter(p),!p.defaultPrevented&&!e.disabled&&!r.open&&!a.current&&(s.onPointerGraceIntentChange(null),a.current=window.setTimeout(()=>{r.onOpenChange(!0),u()},100))})),onPointerLeave:U(e.onPointerLeave,ir(p=>{var v,g;u();const m=(v=r.content)==null?void 0:v.getBoundingClientRect();if(m){const h=(g=r.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===" "||kg[n.dir].includes(p.key)&&(r.onOpenChange(!0),(v=r.content)==null||v.focus(),p.preventDefault())})})})});Vi.displayName=ar;var ji="MenuSubContent",Ri=l.forwardRef((e,t)=>{const r=Ai(Le,e.__scopeMenu),{forceMount:n=r.forceMount,...o}=e,s=wt(Le,e.__scopeMenu),a=sr(Le,e.__scopeMenu),c=Wi(ji,e.__scopeMenu),d=l.useRef(null),f=se(t,d);return i.jsx(or.Provider,{scope:e.__scopeMenu,children:i.jsx(_e,{present:n||s.open,children:i.jsx(or.Slot,{scope:e.__scopeMenu,children:i.jsx(Oo,{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=Og[a.dir].includes(u.key);p&&m&&(s.onOpenChange(!1),(v=c.trigger)==null||v.focus(),u.preventDefault())})})})})})});Ri.displayName=ji;function Ki(e){return e?"open":"closed"}function en(e){return e==="indeterminate"}function Lo(e){return en(e)?"indeterminate":e?"checked":"unchecked"}function Zg(e){const t=document.activeElement;for(const r of e)if(r===t||(r.focus(),document.activeElement!==t))return}function Qg(e,t){return e.map((r,n)=>e[(t+n)%e.length])}function em(e,t,r){const o=t.length>1&&Array.from(t).every(f=>f===t[0])?t[0]:t,s=r?e.indexOf(r):-1;let a=Qg(e,Math.max(s,0));o.length===1&&(a=a.filter(f=>f!==r));const d=a.find(f=>f.toLowerCase().startsWith(o.toLowerCase()));return d!==r?d:void 0}function tm(e,t){const{x:r,y:n}=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>n!=m>n&&r<(p-f)*(n-u)/(m-u)+f&&(o=!o)}return o}function rm(e,t){if(!t)return!1;const r={x:e.clientX,y:e.clientY};return tm(r,t)}function ir(e){return t=>t.pointerType==="mouse"?e(t):void 0}var nm=Ti,om=_o,sm=Pi,am=_i,im=Mo,cm=Ii,lm=Qr,dm=Mi,um=Li,fm=$i,pm=Ui,hm=Hi,gm=zi,mm=Vi,bm=Ri,tn="DropdownMenu",[vm,zw]=Ue(tn,[Ei]),Ee=Ei(),[wm,Gi]=vm(tn),qi=e=>{const{__scopeDropdownMenu:t,children:r,dir:n,open:o,defaultOpen:s,onOpenChange:a,modal:c=!0}=e,d=Ee(t),f=l.useRef(null),[u,p]=st({prop:o,defaultProp:s??!1,onChange:a,caller:tn});return i.jsx(wm,{scope:t,triggerId:He(),triggerRef:f,contentId:He(),open:u,onOpenChange:p,onOpenToggle:l.useCallback(()=>p(m=>!m),[p]),modal:c,children:i.jsx(nm,{...d,open:u,onOpenChange:p,dir:n,modal:c,children:r})})};qi.displayName=tn;var Xi="DropdownMenuTrigger",Yi=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,disabled:n=!1,...o}=e,s=Gi(Xi,r),a=Ee(r);return i.jsx(om,{asChild:!0,...a,children:i.jsx(Q.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":n?"":void 0,disabled:n,...o,ref:Rn(t,s.triggerRef),onPointerDown:U(e.onPointerDown,c=>{!n&&c.button===0&&c.ctrlKey===!1&&(s.onOpenToggle(),s.open||c.preventDefault())}),onKeyDown:U(e.onKeyDown,c=>{n||(["Enter"," "].includes(c.key)&&s.onOpenToggle(),c.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(c.key)&&c.preventDefault())})})})});Yi.displayName=Xi;var ym="DropdownMenuPortal",Ji=e=>{const{__scopeDropdownMenu:t,...r}=e,n=Ee(t);return i.jsx(sm,{...n,...r})};Ji.displayName=ym;var Zi="DropdownMenuContent",Qi=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Gi(Zi,r),s=Ee(r),a=l.useRef(!1);return i.jsx(am,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...n,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)"}})});Qi.displayName=Zi;var xm="DropdownMenuGroup",Sm=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(im,{...o,...n,ref:t})});Sm.displayName=xm;var Cm="DropdownMenuLabel",ec=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(cm,{...o,...n,ref:t})});ec.displayName=Cm;var Em="DropdownMenuItem",tc=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(lm,{...o,...n,ref:t})});tc.displayName=Em;var Nm="DropdownMenuCheckboxItem",rc=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(dm,{...o,...n,ref:t})});rc.displayName=Nm;var Tm="DropdownMenuRadioGroup",Am=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(um,{...o,...n,ref:t})});Am.displayName=Tm;var Pm="DropdownMenuRadioItem",nc=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(fm,{...o,...n,ref:t})});nc.displayName=Pm;var _m="DropdownMenuItemIndicator",oc=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(pm,{...o,...n,ref:t})});oc.displayName=_m;var Im="DropdownMenuSeparator",sc=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(hm,{...o,...n,ref:t})});sc.displayName=Im;var km="DropdownMenuArrow",Om=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(gm,{...o,...n,ref:t})});Om.displayName=km;var Mm="DropdownMenuSubTrigger",ac=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(mm,{...o,...n,ref:t})});ac.displayName=Mm;var Dm="DropdownMenuSubContent",ic=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(bm,{...o,...n,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)"}})});ic.displayName=Dm;var Lm=qi,Fm=Yi,$m=Ji,cc=Qi,lc=ec,dc=tc,uc=rc,fc=nc,pc=oc,hc=sc,gc=ac,mc=ic;const Bm=Lm,Um=Fm,Hm=l.forwardRef(({className:e,inset:t,children:r,...n},o)=>i.jsxs(gc,{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),...n,children:[r,i.jsx(q.ChevronRight,{className:"ml-auto h-4 w-4"})]}));Hm.displayName=gc.displayName;const zm=l.forwardRef(({className:e,...t},r)=>i.jsx(mc,{ref:r,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}));zm.displayName=mc.displayName;const bc=l.forwardRef(({className:e,sideOffset:t=4,...r},n)=>i.jsx($m,{children:i.jsx(cc,{ref:n,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),...r})}));bc.displayName=cc.displayName;const vc=l.forwardRef(({className:e,inset:t,...r},n)=>i.jsx(dc,{ref:n,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),...r}));vc.displayName=dc.displayName;const Wm=l.forwardRef(({className:e,children:t,checked:r,...n},o)=>i.jsxs(uc,{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:r,...n,children:[i.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:i.jsx(pc,{children:i.jsx(q.Check,{className:"h-4 w-4"})})}),t]}));Wm.displayName=uc.displayName;const Vm=l.forwardRef(({className:e,children:t,...r},n)=>i.jsxs(fc,{ref:n,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),...r,children:[i.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:i.jsx(pc,{children:i.jsx(q.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));Vm.displayName=fc.displayName;const jm=l.forwardRef(({className:e,inset:t,...r},n)=>i.jsx(lc,{ref:n,className:A("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...r}));jm.displayName=lc.displayName;const Rm=l.forwardRef(({className:e,...t},r)=>i.jsx(hc,{ref:r,className:A("-mx-1 my-1 h-px bg-muted",e),...t}));Rm.displayName=hc.displayName;function cr({className:e="",placeholder:t="Type your message...",autoFocus:r=!0,maxHeight:n=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:C,hasMoreHistory:E,isLoadingHistory:O,loadOlderMessages:N}=jn(),[L,D]=T.useState(""),[$,R]=T.useState(null),[X,B]=T.useState(null),[M,J]=T.useState([]),[F,H]=T.useState(!1),[P,_]=T.useState([]),[G,j]=T.useState(null),Z=T.useRef(null),I=T.useRef(null),W=T.useRef(null),ge=T.useRef(null),he=T.useRef(!1),z=T.useRef(!0),ce=T.useRef(0),[pe,le]=T.useState("desktop");T.useEffect(()=>{const k=()=>{const Y=window.innerWidth;le(Y<640?"phone":Y<1024?"tablet":"desktop")};return k(),window.addEventListener("resize",k),()=>window.removeEventListener("resize",k)},[]);const de=T.useCallback(async()=>{if(!E||O)return;const k=ge.current;if(!k)return;const Y=k.scrollHeight,re=k.scrollTop;he.current=!0;try{await N()}catch(oe){console.warn("loadOlderMessages failed",oe)}finally{requestAnimationFrame(()=>{const oe=ge.current;if(!oe){he.current=!1;return}const ve=oe.scrollHeight;oe.scrollTop=re+(ve-Y);const ft=ve-oe.scrollTop-oe.clientHeight;z.current=ft<=32,he.current=!1})}},[E,O,N]);T.useEffect(()=>{const k=ge.current;if(!k)return;const Y=()=>{k.scrollTop<=80&&de();const ve=k.scrollHeight-k.scrollTop-k.clientHeight;z.current=ve<=80};return k.addEventListener("scroll",Y),()=>k.removeEventListener("scroll",Y)},[de]),T.useEffect(()=>{p.length<ce.current&&(z.current=!0),ce.current=p.length},[p.length]),T.useEffect(()=>{const k=ge.current;k&&(he.current||z.current&&(k.scrollTop=k.scrollHeight,z.current=!0))},[p]),T.useEffect(()=>{var k;r&&((k=I.current)==null||k.focus())},[r]),T.useEffect(()=>{g&&!F&&(f==null||f(g))},[g,F,f]),T.useEffect(()=>{let k=!0;if(!u){_([]),j(null);return}return y(u).then(Y=>{var ve;if(!k)return;const re=Y.checkpoints||[];_(re);const oe=((ve=re.slice().sort((ft,Te)=>new Date(Te.createdAt).getTime()-new Date(ft.createdAt).getTime())[0])==null?void 0:ve.checkpointId)||null;j(ft=>ft??oe)}).catch(()=>{}),()=>{k=!1}},[u,y]),T.useEffect(()=>{w&&j(w)},[w]);const ue=k=>{if(k.length>_t)return`Message too long (${k.length}/${_t} characters)`;try{return Yf(k),null}catch(Y){return(Y==null?void 0:Y.message)||"Invalid message"}},V=k=>{const Y=k.content||[],re=Y.filter(oe=>oe.type==="text").map(oe=>oe.text).join("");if(re)return re;try{return JSON.stringify(Y,null,2)}catch{return String(Y)}},K=k=>{var ft;if(!P.length)return[];const re=(((ft=p[k])==null?void 0:ft.role)??"user")==="user",oe=re?k+2:k+1;return P.filter(Te=>(Te.messagesLen??-1)>=(re?oe:0)).filter(Te=>re?(Te.messagesLen??0)>=oe:(Te.messagesLen??0)===oe).map(Te=>({checkpoint_id:Te.checkpointId,checkpoint_ns:Te.checkpointNs,message_count:Te.messagesLen??0,last_message_preview:Te.preview??void 0,ts:new Date(Te.createdAt).getTime(),isCurrent:Te.checkpointId===G})).sort((Te,mw)=>(Te.ts||0)-(mw.ts||0))},be=k=>{if(k===void 0)return{canGoBack:!1,canGoForward:!1,currentIndex:0,totalBranches:0};const Y=K(k);if(Y.length<=1)return{canGoBack:!1,canGoForward:!1,currentIndex:0,totalBranches:Y.length};const re=Math.max(0,Y.findIndex(oe=>oe.isCurrent));return{canGoBack:re>0,canGoForward:re<Y.length-1,currentIndex:re,totalBranches:Y.length}},ee=async()=>{const k=L.trim();if(!k&&M.length===0)return;const Y=ue(k);if(Y){B(Y);return}try{const re=window.__editingCheckpointId||G||void 0;await h(k,{checkpointId:re,payloadExtras:$?{edit:!0,originalMessageId:$}:void 0,attachments:M}),d==null||d(k),D(""),B(null),J([]),delete window.__editingCheckpointId,R(null),I.current&&(I.current.style.height="auto")}catch(re){const oe=(re==null?void 0:re.message)||"Failed to send message";B(oe),f==null||f(oe)}},ye=(k,Y)=>{a&&(R(k),D(Y),B(null),setTimeout(()=>{I.current&&(I.current.focus(),I.current.style.height="auto",I.current.style.height=I.current.scrollHeight+"px")},0))},ae=async(k,Y)=>{const re=p.find(ve=>ve.id===k);if(!re){B("Message not found");return}const oe=V(re);R(k),D(oe),window.__editingCheckpointId=Y,setTimeout(()=>{var ve;return(ve=I.current)==null?void 0:ve.focus()},0)},fe=()=>{R(null),D(""),B(null),delete window.__editingCheckpointId,I.current&&(I.current.style.height="auto")},Ne=k=>{k.key==="Enter"&&!k.shiftKey?(k.preventDefault(),ee()):k.key==="Escape"&&$&&(k.preventDefault(),fe())},ot=k=>{const Y=Array.from(k.target.files||[]);J(re=>[...re,...Y])},as=k=>J(Y=>Y.filter((re,oe)=>k!==oe)),Et=async k=>{u&&(await x(k),j(k))},ie=async()=>{await C(),j(null)},Ie=`flex w-full flex-col h-full min-h-0 min-w-0 overflow-x-hidden bg-transparent ${e} ${c.container||""}`,ke=`flex-1 min-h-0 min-w-0 w-full overflow-y-auto overflow-x-auto overscroll-x-contain break-words break-anywhere p-4 space-y-4 bg-transparent ${c.messagesArea||""}`,Re=`flex-shrink-0 w-full border-t p-4 bg-transparent ${c.inputArea||""}`;return i.jsxs("div",{className:Ie,children:[!!g&&!F&&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(me,{variant:"ghost",size:"sm",onClick:()=>H(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:i.jsx(q.X,{size:16})})]}),u&&P.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(q.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:G??"",onChange:k=>{const Y=k.target.value||null;Y?Et(Y):ie()},children:[i.jsx("option",{value:"",children:"Latest"}),P.slice().sort((k,Y)=>new Date(Y.createdAt).getTime()-new Date(k.createdAt).getTime()).map(k=>i.jsxs("option",{value:k.checkpointId,children:[new Date(k.createdAt).toLocaleString(),k.preview?` — ${k.preview.slice(0,30)}`:""]},k.checkpointId))]})]}),i.jsxs("div",{ref:ge,className:ke,style:n?{maxHeight:n}: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!"}):i.jsxs(i.Fragment,{children:[(O||!E)&&i.jsx("div",{className:"flex justify-center py-2 text-xs text-muted-foreground",children:O?i.jsx(q.Loader2,{className:"h-4 w-4 animate-spin"}):"You've reached the beginning"}),p.map((k,Y)=>i.jsx(fa,{message:k,messageIndex:Y,isStreamingMessage:m&&v===k.id,streamingDebounceMs:o,isEditing:$===k.id,showActions:a,showTimestamp:!1,showAgentName:!0,layoutSize:pe,truncateToolMessages:!1,toolMessagePreviewLength:200,checkpointBranches:K(Y),currentCheckpointId:G??void 0,temporalNavigation:be(Y),onSwitchToCheckpoint:Et,onReturnToMainThread:ie,onNavigateToPreviousBranch:()=>{const re=K(Y),oe=Math.max(0,re.findIndex(ve=>ve.isCurrent));oe>0&&Et(re[oe-1].checkpoint_id)},onNavigateToNextBranch:()=>{const re=K(Y),oe=Math.max(0,re.findIndex(ve=>ve.isCurrent));oe>=0&&oe<re.length-1&&Et(re[oe+1].checkpoint_id)},onEdit:(re,oe)=>ye(re,oe),onEditFromCheckpoint:ae,onRegenerate:()=>{const re=[...p].reverse().find(ve=>ve.role==="user"),oe=re?V(re):"";oe&&h(oe,{checkpointId:G??void 0})},onCancelEdit:fe},k.id||Y))]}),i.jsx("div",{ref:Z})]}),i.jsxs("div",{className:Re,children:[$&&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(q.Edit3,{size:16,className:"text-blue-600"}),i.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),i.jsx(me,{variant:"ghost",size:"sm",onClick:fe,className:"text-blue-600 hover:bg-blue-100",children:i.jsx(q.X,{size:16})})]})}),s&&i.jsxs("div",{className:"mb-3",children:[i.jsx("input",{ref:W,type:"file",multiple:!0,onChange:k=>ot(k),className:"hidden"}),M.length>0&&i.jsx("div",{className:"mb-3 flex flex-wrap gap-2",children:M.map((k,Y)=>i.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 rounded-lg px-3 py-2 text-sm",children:[i.jsx(q.Paperclip,{size:14}),i.jsx("span",{className:"truncate max-w-[150px]",children:k.name}),i.jsx(me,{variant:"ghost",size:"sm",onClick:()=>as(Y),className:"h-4 w-4 p-0 text-gray-500 hover:text-red-500","aria-label":`Remove ${k.name}`,children:i.jsx(q.X,{size:12})})]},Y))})]}),X&&i.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:X}),i.jsxs("div",{className:"flex items-end gap-2",children:[s&&i.jsxs(Bm,{children:[i.jsx(Um,{asChild:!0,children:i.jsx(me,{type:"button",size:"icon",variant:"outline",disabled:m,title:"More input actions",className:c.moreButton||"",children:i.jsx(q.Plus,{size:16})})}),i.jsx(bc,{align:"start",sideOffset:6,className:"w-52",children:i.jsxs(vc,{onClick:()=>{var k;return(k=W.current)==null?void 0:k.click()},className:"cursor-pointer",children:[i.jsx(q.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]})})]}),i.jsx("div",{className:"flex-1",children:i.jsx(na,{ref:I,value:L,onChange:k=>{D(k.target.value),B(null),I.current&&(I.current.style.height="auto",I.current.style.height=`${I.current.scrollHeight}px`)},onKeyDown:Ne,placeholder:$?"Edit your message...":t,className:`resize-none min-h-[44px] max-h-[20rem] w-full ${$?"border-blue-400 bg-blue-50":""} ${X?"border-red-400":""} ${c.textarea||""}`,disabled:!1,maxLength:_t,rows:1})}),i.jsx("div",{children:m?i.jsx(me,{type:"button",onClick:b,size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",children:i.jsx(q.Square,{size:16})}):i.jsx(me,{type:"button",onClick:ee,size:"icon",disabled:!L.trim()&&M.length===0,className:`shrink-0 ${c.sendButton||""}`,title:$?"Save changes":"Send message",children:i.jsx(q.Send,{size:16})})})]}),L.length>_t*.8&&i.jsxs("div",{className:"mt-2 text-xs text-gray-500 text-right",children:[L.length,"/",_t]})]})]})}const lr=l.forwardRef(({className:e,type:t,...r},n)=>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:n,...r}));lr.displayName="Input";function Fo(e,[t,r]){return Math.min(r,Math.max(t,e))}function Km(e,t){return l.useReducer((r,n)=>t[r][n]??r,e)}var $o="ScrollArea",[wc,Ww]=Ue($o),[Gm,Fe]=wc($o),yc=l.forwardRef((e,t)=>{const{__scopeScrollArea:r,type:n="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,C]=l.useState(0),[E,O]=l.useState(!1),[N,L]=l.useState(!1),D=se(t,R=>d(R)),$=Ir(o);return i.jsx(Gm,{scope:r,type:n,dir:$,scrollHideDelay:s,scrollArea:c,viewport:f,onViewportChange:u,content:p,onContentChange:m,scrollbarX:v,onScrollbarXChange:g,scrollbarXEnabled:E,onScrollbarXEnabledChange:O,scrollbarY:h,onScrollbarYChange:b,scrollbarYEnabled:N,onScrollbarYEnabledChange:L,onCornerWidthChange:y,onCornerHeightChange:C,children:i.jsx(Q.div,{dir:$,...a,ref:D,style:{position:"relative","--radix-scroll-area-corner-width":w+"px","--radix-scroll-area-corner-height":x+"px",...e.style}})})});yc.displayName=$o;var xc="ScrollAreaViewport",Sc=l.forwardRef((e,t)=>{const{__scopeScrollArea:r,children:n,nonce:o,...s}=e,a=Fe(xc,r),c=l.useRef(null),d=se(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(Q.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:n})})]})});Sc.displayName=xc;var et="ScrollAreaScrollbar",Bo=l.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=Fe(et,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(qm,{...n,ref:t,forceMount:r}):o.type==="scroll"?i.jsx(Xm,{...n,ref:t,forceMount:r}):o.type==="auto"?i.jsx(Cc,{...n,ref:t,forceMount:r}):o.type==="always"?i.jsx(Uo,{...n,ref:t}):null});Bo.displayName=et;var qm=l.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=Fe(et,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(_e,{present:r||s,children:i.jsx(Cc,{"data-state":s?"visible":"hidden",...n,ref:t})})}),Xm=l.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=Fe(et,e.__scopeScrollArea),s=e.orientation==="horizontal",a=sn(()=>d("SCROLL_END"),100),[c,d]=Km("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(_e,{present:r||c!=="hidden",children:i.jsx(Uo,{"data-state":c==="hidden"?"hidden":"visible",...n,ref:t,onPointerEnter:U(e.onPointerEnter,()=>d("POINTER_ENTER")),onPointerLeave:U(e.onPointerLeave,()=>d("POINTER_LEAVE"))})})}),Cc=l.forwardRef((e,t)=>{const r=Fe(et,e.__scopeScrollArea),{forceMount:n,...o}=e,[s,a]=l.useState(!1),c=e.orientation==="horizontal",d=sn(()=>{if(r.viewport){const f=r.viewport.offsetWidth<r.viewport.scrollWidth,u=r.viewport.offsetHeight<r.viewport.scrollHeight;a(c?f:u)}},10);return Ut(r.viewport,d),Ut(r.content,d),i.jsx(_e,{present:n||s,children:i.jsx(Uo,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Uo=l.forwardRef((e,t)=>{const{orientation:r="vertical",...n}=e,o=Fe(et,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=Pc(c.viewport,c.content),u={...n,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 tb(m,a.current,c,v)}return r==="horizontal"?i.jsx(Ym,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const m=o.viewport.scrollLeft,v=_c(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))}}):r==="vertical"?i.jsx(Jm,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const m=o.viewport.scrollTop,v=_c(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}),Ym=l.forwardRef((e,t)=>{const{sizes:r,onSizesChange:n,...o}=e,s=Fe(et,e.__scopeScrollArea),[a,c]=l.useState(),d=l.useRef(null),f=se(t,d,s.onScrollbarXChange);return l.useEffect(()=>{d.current&&c(getComputedStyle(d.current))},[d]),i.jsx(Nc,{"data-orientation":"horizontal",...o,ref:f,sizes:r,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":on(r)+"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),kc(m,p)&&u.preventDefault()}},onResize:()=>{d.current&&s.viewport&&a&&n({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:d.current.clientWidth,paddingStart:nn(a.paddingLeft),paddingEnd:nn(a.paddingRight)}})}})}),Jm=l.forwardRef((e,t)=>{const{sizes:r,onSizesChange:n,...o}=e,s=Fe(et,e.__scopeScrollArea),[a,c]=l.useState(),d=l.useRef(null),f=se(t,d,s.onScrollbarYChange);return l.useEffect(()=>{d.current&&c(getComputedStyle(d.current))},[d]),i.jsx(Nc,{"data-orientation":"vertical",...o,ref:f,sizes:r,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":on(r)+"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),kc(m,p)&&u.preventDefault()}},onResize:()=>{d.current&&s.viewport&&a&&n({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:d.current.clientHeight,paddingStart:nn(a.paddingTop),paddingEnd:nn(a.paddingBottom)}})}})}),[Zm,Ec]=wc(et),Nc=l.forwardRef((e,t)=>{const{__scopeScrollArea:r,sizes:n,hasThumb:o,onThumbChange:s,onThumbPointerUp:a,onThumbPointerDown:c,onThumbPositionChange:d,onDragScroll:f,onWheelScroll:u,onResize:p,...m}=e,v=Fe(et,r),[g,h]=l.useState(null),b=se(t,D=>h(D)),w=l.useRef(null),y=l.useRef(""),x=v.viewport,C=n.content-n.viewport,E=Se(u),O=Se(d),N=sn(p,10);function L(D){if(w.current){const $=D.clientX-w.current.left,R=D.clientY-w.current.top;f({x:$,y:R})}}return l.useEffect(()=>{const D=$=>{const R=$.target;(g==null?void 0:g.contains(R))&&E($,C)};return document.addEventListener("wheel",D,{passive:!1}),()=>document.removeEventListener("wheel",D,{passive:!1})},[x,g,C,E]),l.useEffect(O,[n,O]),Ut(g,N),Ut(v.content,N),i.jsx(Zm,{scope:r,scrollbar:g,hasThumb:o,onThumbChange:Se(s),onThumbPointerUp:Se(a),onThumbPositionChange:O,onThumbPointerDown:Se(c),children:i.jsx(Q.div,{...m,ref:b,style:{position:"absolute",...m.style},onPointerDown:U(e.onPointerDown,D=>{D.button===0&&(D.target.setPointerCapture(D.pointerId),w.current=g.getBoundingClientRect(),y.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",v.viewport&&(v.viewport.style.scrollBehavior="auto"),L(D))}),onPointerMove:U(e.onPointerMove,L),onPointerUp:U(e.onPointerUp,D=>{const $=D.target;$.hasPointerCapture(D.pointerId)&&$.releasePointerCapture(D.pointerId),document.body.style.webkitUserSelect=y.current,v.viewport&&(v.viewport.style.scrollBehavior=""),w.current=null})})})}),rn="ScrollAreaThumb",Tc=l.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=Ec(rn,e.__scopeScrollArea);return i.jsx(_e,{present:r||o.hasThumb,children:i.jsx(Qm,{ref:t,...n})})}),Qm=l.forwardRef((e,t)=>{const{__scopeScrollArea:r,style:n,...o}=e,s=Fe(rn,r),a=Ec(rn,r),{onThumbPositionChange:c}=a,d=se(t,p=>a.onThumbChange(p)),f=l.useRef(void 0),u=sn(()=>{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=rb(p,c);f.current=v,c()}};return c(),p.addEventListener("scroll",m),()=>p.removeEventListener("scroll",m)}},[s.viewport,u,c]),i.jsx(Q.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)",...n},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)})});Tc.displayName=rn;var Ho="ScrollAreaCorner",Ac=l.forwardRef((e,t)=>{const r=Fe(Ho,e.__scopeScrollArea),n=!!(r.scrollbarX&&r.scrollbarY);return r.type!=="scroll"&&n?i.jsx(eb,{...e,ref:t}):null});Ac.displayName=Ho;var eb=l.forwardRef((e,t)=>{const{__scopeScrollArea:r,...n}=e,o=Fe(Ho,r),[s,a]=l.useState(0),[c,d]=l.useState(0),f=!!(s&&c);return Ut(o.scrollbarX,()=>{var p;const u=((p=o.scrollbarX)==null?void 0:p.offsetHeight)||0;o.onCornerHeightChange(u),d(u)}),Ut(o.scrollbarY,()=>{var p;const u=((p=o.scrollbarY)==null?void 0:p.offsetWidth)||0;o.onCornerWidthChange(u),a(u)}),f?i.jsx(Q.div,{...n,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 nn(e){return e?parseInt(e,10):0}function Pc(e,t){const r=e/t;return isNaN(r)?0:r}function on(e){const t=Pc(e.viewport,e.content),r=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,n=(e.scrollbar.size-r)*t;return Math.max(n,18)}function tb(e,t,r,n="ltr"){const o=on(r),s=o/2,a=t||s,c=o-a,d=r.scrollbar.paddingStart+a,f=r.scrollbar.size-r.scrollbar.paddingEnd-c,u=r.content-r.viewport,p=n==="ltr"?[0,u]:[u*-1,0];return Ic([d,f],p)(e)}function _c(e,t,r="ltr"){const n=on(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,a=t.content-t.viewport,c=s-n,d=r==="ltr"?[0,a]:[a*-1,0],f=Fo(e,d);return Ic([0,a],[0,c])(f)}function Ic(e,t){return r=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const n=(t[1]-t[0])/(e[1]-e[0]);return t[0]+n*(r-e[0])}}function kc(e,t){return e>0&&e<t}var rb=(e,t=()=>{})=>{let r={left:e.scrollLeft,top:e.scrollTop},n=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},a=r.left!==s.left,c=r.top!==s.top;(a||c)&&t(),r=s,n=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(n)};function sn(e,t){const r=Se(e),n=l.useRef(0);return l.useEffect(()=>()=>window.clearTimeout(n.current),[]),l.useCallback(()=>{window.clearTimeout(n.current),n.current=window.setTimeout(r,t)},[r,t])}function Ut(e,t){const r=Se(t);xe(()=>{let n=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(n),n=window.requestAnimationFrame(r)});return o.observe(e),()=>{window.cancelAnimationFrame(n),o.unobserve(e)}}},[e,r])}var Oc=yc,nb=Sc,ob=Ac;const Mc=l.forwardRef(({className:e,children:t,...r},n)=>i.jsxs(Oc,{ref:n,className:A("relative overflow-hidden",e),...r,children:[i.jsx(nb,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),i.jsx(Dc,{}),i.jsx(ob,{})]}));Mc.displayName=Oc.displayName;const Dc=l.forwardRef(({className:e,orientation:t="vertical",...r},n)=>i.jsx(Bo,{ref:n,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),...r,children:i.jsx(Tc,{className:"relative flex-1 rounded-full bg-border"})}));Dc.displayName=Bo.displayName;function an({className:e="",showCreateButton:t=!0,showDeleteButton:r=!0,showEditTitle:n=!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}=jn(),[y,x]=T.useState(m??[]),[C,E]=T.useState(!1),[O,N]=T.useState(null),[L,D]=T.useState(null),[$,R]=T.useState(""),[X,B]=T.useState(!1);T.useEffect(()=>{x(m??[])},[m]);const M=async I=>{try{await p(I),c==null||c(I),d==null||d(I)}catch(W){console.error("Failed to select thread:",W)}},J=async()=>{try{B(!0);const I=await h();f==null||f(I),c==null||c(I)}catch(I){console.error("Failed to create thread:",I)}finally{B(!1)}},F=async(I,W)=>{if(W.stopPropagation(),!!confirm("Delete this thread?"))try{await b(I),u==null||u(I)}catch(ge){console.error("Failed to delete thread:",ge)}},H=(I,W)=>{W.stopPropagation(),D(I.threadId),R(I.title||`Thread ${I.threadId.slice(0,8)}`)},P=async I=>{if($.trim())try{await w(I,$.trim()),D(null),R("")}catch(W){console.error("Failed to update title:",W)}},_=()=>{D(null),R("")},G=(I,W)=>{I.key==="Enter"?P(W):I.key==="Escape"&&_()},j=I=>{if(!I)return"";try{const W=new Date(I),he=new Date().getTime()-W.getTime(),z=Math.floor(he/(1e3*60*60*24));return z===0?W.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):z===1?"Yesterday":z<7?`${z} days ago`:W.toLocaleDateString()}catch{return""}},Z=I=>I.title||`Thread ${I.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(me,{onClick:J,disabled:X||C,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:X?"Creating...":"New Chat",children:i.jsx(q.MessageSquarePlus,{size:20})})}),i.jsx(Mc,{className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:i.jsx("div",{className:"p-2 space-y-1 pb-4",children:C?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(q.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((I,W)=>new Date(W.updatedAt||W.createdAt||"").getTime()-new Date(I.updatedAt||I.createdAt||"").getTime()).map(I=>i.jsxs("div",{onClick:()=>M(I.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(a??g)===I.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:L===I.threadId?i.jsxs("div",{className:"flex items-center gap-2",onClick:W=>W.stopPropagation(),children:[i.jsx(lr,{value:$,onChange:W=>R(W.target.value),onKeyDown:W=>G(W,I.threadId),className:"h-6 text-sm",autoFocus:!0}),i.jsx(me,{variant:"ghost",size:"sm",onClick:()=>P(I.threadId),className:"h-6 w-6 p-0",children:i.jsx(q.Check,{size:12})}),i.jsx(me,{variant:"ghost",size:"sm",onClick:_,className:"h-6 w-6 p-0",children:i.jsx(q.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:Z(I)}),i.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[i.jsx(q.Calendar,{size:10}),i.jsx("span",{children:j(I.updatedAt||I.createdAt)})]})]})}),i.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[n&&L!==I.threadId&&i.jsx(me,{variant:"ghost",size:"sm",onClick:W=>H(I,W),className:"h-6 w-6 p-0",title:"Edit title",children:i.jsx(q.Edit3,{size:12})}),r&&i.jsx(me,{variant:"ghost",size:"sm",onClick:W=>F(I.threadId,W),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(q.Trash2,{size:12})})]})]}),a===I.threadId&&i.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},I.threadId))})})]})}const Lc=T.createContext(null);function sb({children:e,basePath:t="/chat"}){const r=T.useMemo(()=>t?t==="/"?"":t.endsWith("/")?t.slice(0,-1):t:"/chat",[t]),n={basePath:r,buildThreadPath:o=>`${r}/${o}`,buildBasePath:()=>r};return i.jsx(Lc.Provider,{value:n,children:e})}function ab(){const e=T.useContext(Lc);return e||{basePath:"/chat",buildThreadPath:t=>`/chat/${t}`,buildBasePath:()=>"/chat"}}const Fc={BASE_URL:"/",DEV:!1,MODE:"library",PROD:!0,SSR:!1};function dr(e){var o;const t=typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Nn&&Nn.tagName.toUpperCase()==="SCRIPT"&&Nn.src||new URL("index.umd.js",document.baseURI).href}<"u"&&Fc?Fc[e]:void 0,r=(o=globalThis==null?void 0:globalThis.process)==null?void 0:o.env,n=r?r[e]:void 0;return(t??n)||void 0}function ib(){return dr("VITE_API_BASE_URL")||dr("NEXT_PUBLIC_API_BASE_URL")||void 0}function cb(){return dr("VITE_API_KEY")||dr("NEXT_PUBLIC_API_KEY")||dr("VITE_AUTH_TOKEN")||void 0}function $c(){const e=ib(),t=cb(),r={};return e&&(r.baseUrl=e),t&&(r.apiKey=t),r}function Bc(){const e=$c(),t=tt.getAuthToken();return{apiBaseUrl:e.baseUrl||tt.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 Uc="chat-settings";function lb(){try{const e=localStorage.getItem(Uc);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function db(e){try{localStorage.setItem(Uc,JSON.stringify(e)),e.apiKey&&tt.setAuthToken(e.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function ub(){const e=Bc(),t=lb(),r=tt.getAuthToken();return{...e,...t,apiKey:r||t.apiKey||e.apiKey,apiBaseUrl:tt.baseUrl||t.apiBaseUrl||e.apiBaseUrl}}function fb(e){e.apiKey&&tt.setAuthToken(e.apiKey),db(e)}const zo=768;function pb(){const[e,t]=l.useState(void 0);return l.useEffect(()=>{const r=window.matchMedia(`(max-width: ${zo-1}px)`),n=()=>{t(window.innerWidth<zo)};return r.addEventListener("change",n),t(window.innerWidth<zo),()=>r.removeEventListener("change",n)},[]),!!e}var hb="Separator",Hc="horizontal",gb=["horizontal","vertical"],zc=l.forwardRef((e,t)=>{const{decorative:r,orientation:n=Hc,...o}=e,s=mb(n)?n:Hc,c=r?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return i.jsx(Q.div,{"data-orientation":s,...c,...o,ref:t})});zc.displayName=hb;function mb(e){return gb.includes(e)}var Wc=zc;const Wo=l.forwardRef(({className:e,orientation:t="horizontal",decorative:r=!0,...n},o)=>i.jsx(Wc,{ref:o,decorative:r,orientation:t,className:A("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...n}));Wo.displayName=Wc.displayName;var cn="Dialog",[Vc,Vw]=Ue(cn),[bb,Ve]=Vc(cn),jc=e=>{const{__scopeDialog:t,children:r,open:n,defaultOpen:o,onOpenChange:s,modal:a=!0}=e,c=l.useRef(null),d=l.useRef(null),[f,u]=st({prop:n,defaultProp:o??!1,onChange:s,caller:cn});return i.jsx(bb,{scope:t,triggerRef:c,contentRef:d,contentId:He(),titleId:He(),descriptionId:He(),open:f,onOpenChange:u,onOpenToggle:l.useCallback(()=>u(p=>!p),[u]),modal:a,children:r})};jc.displayName=cn;var Rc="DialogTrigger",Kc=l.forwardRef((e,t)=>{const{__scopeDialog:r,...n}=e,o=Ve(Rc,r),s=se(t,o.triggerRef);return i.jsx(Q.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Ro(o.open),...n,ref:s,onClick:U(e.onClick,o.onOpenToggle)})});Kc.displayName=Rc;var Vo="DialogPortal",[vb,Gc]=Vc(Vo,{forceMount:void 0}),qc=e=>{const{__scopeDialog:t,forceMount:r,children:n,container:o}=e,s=Ve(Vo,t);return i.jsx(vb,{scope:t,forceMount:r,children:l.Children.map(n,a=>i.jsx(_e,{present:r||s.open,children:i.jsx(Wr,{asChild:!0,container:o,children:a})}))})};qc.displayName=Vo;var ln="DialogOverlay",Xc=l.forwardRef((e,t)=>{const r=Gc(ln,e.__scopeDialog),{forceMount:n=r.forceMount,...o}=e,s=Ve(ln,e.__scopeDialog);return s.modal?i.jsx(_e,{present:n||s.open,children:i.jsx(yb,{...o,ref:t})}):null});Xc.displayName=ln;var wb=Oe.createSlot("DialogOverlay.RemoveScroll"),yb=l.forwardRef((e,t)=>{const{__scopeDialog:r,...n}=e,o=Ve(ln,r);return i.jsx(Yr,{as:wb,allowPinchZoom:!0,shards:[o.contentRef],children:i.jsx(Q.div,{"data-state":Ro(o.open),...n,ref:t,style:{pointerEvents:"auto",...n.style}})})}),yt="DialogContent",Yc=l.forwardRef((e,t)=>{const r=Gc(yt,e.__scopeDialog),{forceMount:n=r.forceMount,...o}=e,s=Ve(yt,e.__scopeDialog);return i.jsx(_e,{present:n||s.open,children:s.modal?i.jsx(xb,{...o,ref:t}):i.jsx(Sb,{...o,ref:t})})});Yc.displayName=yt;var xb=l.forwardRef((e,t)=>{const r=Ve(yt,e.__scopeDialog),n=l.useRef(null),o=se(t,r.contentRef,n);return l.useEffect(()=>{const s=n.current;if(s)return Co(s)},[]),i.jsx(Jc,{...e,ref:o,trapFocus:r.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:U(e.onCloseAutoFocus,s=>{var a;s.preventDefault(),(a=r.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())})}),Sb=l.forwardRef((e,t)=>{const r=Ve(yt,e.__scopeDialog),n=l.useRef(!1),o=l.useRef(!1);return i.jsx(Jc,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var a,c;(a=e.onCloseAutoFocus)==null||a.call(e,s),s.defaultPrevented||(n.current||(c=r.triggerRef.current)==null||c.focus(),s.preventDefault()),n.current=!1,o.current=!1},onInteractOutside:s=>{var d,f;(d=e.onInteractOutside)==null||d.call(e,s),s.defaultPrevented||(n.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const a=s.target;((f=r.triggerRef.current)==null?void 0:f.contains(a))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),Jc=l.forwardRef((e,t)=>{const{__scopeDialog:r,trapFocus:n,onOpenAutoFocus:o,onCloseAutoFocus:s,...a}=e,c=Ve(yt,r),d=l.useRef(null),f=se(t,d);return Qn(),i.jsxs(i.Fragment,{children:[i.jsx(kr,{asChild:!0,loop:!0,trapped:n,onMountAutoFocus:o,onUnmountAutoFocus:s,children:i.jsx(Zt,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionId,"aria-labelledby":c.titleId,"data-state":Ro(c.open),...a,ref:f,onDismiss:()=>c.onOpenChange(!1)})}),i.jsxs(i.Fragment,{children:[i.jsx(Cb,{titleId:c.titleId}),i.jsx(Nb,{contentRef:d,descriptionId:c.descriptionId})]})]})}),jo="DialogTitle",Zc=l.forwardRef((e,t)=>{const{__scopeDialog:r,...n}=e,o=Ve(jo,r);return i.jsx(Q.h2,{id:o.titleId,...n,ref:t})});Zc.displayName=jo;var Qc="DialogDescription",el=l.forwardRef((e,t)=>{const{__scopeDialog:r,...n}=e,o=Ve(Qc,r);return i.jsx(Q.p,{id:o.descriptionId,...n,ref:t})});el.displayName=Qc;var tl="DialogClose",rl=l.forwardRef((e,t)=>{const{__scopeDialog:r,...n}=e,o=Ve(tl,r);return i.jsx(Q.button,{type:"button",...n,ref:t,onClick:U(e.onClick,()=>o.onOpenChange(!1))})});rl.displayName=tl;function Ro(e){return e?"open":"closed"}var nl="DialogTitleWarning",[jw,ol]=wf(nl,{contentName:yt,titleName:jo,docsSlug:"dialog"}),Cb=({titleId:e})=>{const t=ol(nl),r=`\`${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