@cuongtran001/kanna 0.56.3 → 0.56.4

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.
@@ -693,7 +693,7 @@ Please change the parent <Route path="${C}"> to <Route path="${C==="/"?"*":`${C}
693
693
  `)},sM=function(){var e=parseInt(document.body.getAttribute(pd)||"0",10);return isFinite(e)?e:0},eY=function(){v.useEffect(function(){return document.body.setAttribute(pd,(sM()+1).toString()),function(){var e=sM()-1;e<=0?document.body.removeAttribute(pd):document.body.setAttribute(pd,e.toString())}},[])},tY=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,i=r===void 0?"margin":r;eY();var s=v.useMemo(function(){return QK(i)},[i]);return v.createElement(ZK,{styles:JK(s,!t,i,n?"":"!important")})},RS=!1;if(typeof window<"u")try{var Mg=Object.defineProperty({},"passive",{get:function(){return RS=!0,!0}});window.addEventListener("test",Mg,Mg),window.removeEventListener("test",Mg,Mg)}catch{RS=!1}var Fu=RS?{passive:!1}:!1,nY=function(e){return e.tagName==="TEXTAREA"},J5=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!nY(e)&&n[t]==="visible")},rY=function(e){return J5(e,"overflowY")},iY=function(e){return J5(e,"overflowX")},oM=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var i=eO(e,r);if(i){var s=tO(e,r),o=s[1],l=s[2];if(o>l)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},sY=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},oY=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},eO=function(e,t){return e==="v"?rY(t):iY(t)},tO=function(e,t){return e==="v"?sY(t):oY(t)},aY=function(e,t){return e==="h"&&t==="rtl"?-1:1},lY=function(e,t,n,r,i){var s=aY(e,window.getComputedStyle(t).direction),o=s*r,l=n.target,c=t.contains(l),u=!1,p=o>0,h=0,g=0;do{if(!l)break;var b=tO(e,l),x=b[0],_=b[1],w=b[2],C=_-w-s*x;(x||C)&&eO(e,l)&&(h+=C,g+=x);var E=l.parentNode;l=E&&E.nodeType===Node.DOCUMENT_FRAGMENT_NODE?E.host:E}while(!c&&l!==document.body||c&&(t.contains(l)||t===l));return(p&&Math.abs(h)<1||!p&&Math.abs(g)<1)&&(u=!0),u},Lg=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},aM=function(e){return[e.deltaX,e.deltaY]},lM=function(e){return e&&"current"in e?e.current:e},cY=function(e,t){return e[0]===t[0]&&e[1]===t[1]},uY=function(e){return`
694
694
  .block-interactivity-`.concat(e,` {pointer-events: none;}
695
695
  .allow-interactivity-`).concat(e,` {pointer-events: all;}
696
- `)},dY=0,$u=[];function fY(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),i=v.useState(dY++)[0],s=v.useState(Z5)[0],o=v.useRef(e);v.useEffect(function(){o.current=e},[e]),v.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(i));var _=jK([e.lockRef.current],(e.shards||[]).map(lM),!0).filter(Boolean);return _.forEach(function(w){return w.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),_.forEach(function(w){return w.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var l=v.useCallback(function(_,w){if("touches"in _&&_.touches.length===2||_.type==="wheel"&&_.ctrlKey)return!o.current.allowPinchZoom;var C=Lg(_),E=n.current,k="deltaX"in _?_.deltaX:E[0]-C[0],R="deltaY"in _?_.deltaY:E[1]-C[1],N,A=_.target,M=Math.abs(k)>Math.abs(R)?"h":"v";if("touches"in _&&M==="h"&&A.type==="range")return!1;var D=window.getSelection(),U=D&&D.anchorNode,j=U?U===A||U.contains(A):!1;if(j)return!1;var P=oM(M,A);if(!P)return!0;if(P?N=M:(N=M==="v"?"h":"v",P=oM(M,A)),!P)return!1;if(!r.current&&"changedTouches"in _&&(k||R)&&(r.current=N),!N)return!0;var z=r.current||N;return lY(z,w,_,z==="h"?k:R)},[]),c=v.useCallback(function(_){var w=_;if(!(!$u.length||$u[$u.length-1]!==s)){var C="deltaY"in w?aM(w):Lg(w),E=t.current.filter(function(N){return N.name===w.type&&(N.target===w.target||w.target===N.shadowParent)&&cY(N.delta,C)})[0];if(E&&E.should){w.cancelable&&w.preventDefault();return}if(!E){var k=(o.current.shards||[]).map(lM).filter(Boolean).filter(function(N){return N.contains(w.target)}),R=k.length>0?l(w,k[0]):!o.current.noIsolation;R&&w.cancelable&&w.preventDefault()}}},[]),u=v.useCallback(function(_,w,C,E){var k={name:_,delta:w,target:C,should:E,shadowParent:hY(C)};t.current.push(k),setTimeout(function(){t.current=t.current.filter(function(R){return R!==k})},1)},[]),p=v.useCallback(function(_){n.current=Lg(_),r.current=void 0},[]),h=v.useCallback(function(_){u(_.type,aM(_),_.target,l(_,e.lockRef.current))},[]),g=v.useCallback(function(_){u(_.type,Lg(_),_.target,l(_,e.lockRef.current))},[]);v.useEffect(function(){return $u.push(s),e.setCallbacks({onScrollCapture:h,onWheelCapture:h,onTouchMoveCapture:g}),document.addEventListener("wheel",c,Fu),document.addEventListener("touchmove",c,Fu),document.addEventListener("touchstart",p,Fu),function(){$u=$u.filter(function(_){return _!==s}),document.removeEventListener("wheel",c,Fu),document.removeEventListener("touchmove",c,Fu),document.removeEventListener("touchstart",p,Fu)}},[]);var b=e.removeScrollBar,x=e.inert;return v.createElement(v.Fragment,null,x?v.createElement(s,{styles:uY(i)}):null,b?v.createElement(tY,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function hY(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const pY=HK(Q5,fY);var Vp=v.forwardRef(function(e,t){return v.createElement(yy,ko({},e,{ref:t,sideCar:pY}))});Vp.classNames=yy.classNames;var mY=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Hu=new WeakMap,jg=new WeakMap,Dg={},z_=0,nO=function(e){return e&&(e.host||nO(e.parentNode))},gY=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=nO(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},vY=function(e,t,n,r){var i=gY(t,Array.isArray(e)?e:[e]);Dg[n]||(Dg[n]=new WeakMap);var s=Dg[n],o=[],l=new Set,c=new Set(i),u=function(h){!h||l.has(h)||(l.add(h),u(h.parentNode))};i.forEach(u);var p=function(h){!h||c.has(h)||Array.prototype.forEach.call(h.children,function(g){if(l.has(g))p(g);else try{var b=g.getAttribute(r),x=b!==null&&b!=="false",_=(Hu.get(g)||0)+1,w=(s.get(g)||0)+1;Hu.set(g,_),s.set(g,w),o.push(g),_===1&&x&&jg.set(g,!0),w===1&&g.setAttribute(n,"true"),x||g.setAttribute(r,"true")}catch(C){console.error("aria-hidden: cannot operate on ",g,C)}})};return p(t),l.clear(),z_++,function(){o.forEach(function(h){var g=Hu.get(h)-1,b=s.get(h)-1;Hu.set(h,g),s.set(h,b),g||(jg.has(h)||h.removeAttribute(r),jg.delete(h)),b||h.removeAttribute(n)}),z_--,z_||(Hu=new WeakMap,Hu=new WeakMap,jg=new WeakMap,Dg={})}},xy=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),i=mY(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll("[aria-live], script"))),vY(r,i,n,"aria-hidden")):function(){return null}},_y="Dialog",[rO]=Ta(_y),[bY,so]=rO(_y),iO=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!0}=e,l=v.useRef(null),c=v.useRef(null),[u,p]=Td({prop:r,defaultProp:i??!1,onChange:s,caller:_y});return f.jsx(bY,{scope:t,triggerRef:l,contentRef:c,contentId:ba(),titleId:ba(),descriptionId:ba(),open:u,onOpenChange:p,onOpenToggle:v.useCallback(()=>p(h=>!h),[p]),modal:o,children:n})};iO.displayName=_y;var sO="DialogTrigger",yY=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=so(sO,n),s=yn(t,i.triggerRef);return f.jsx(nn.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":ak(i.open),...r,ref:s,onClick:rt(e.onClick,i.onOpenToggle)})});yY.displayName=sO;var sk="DialogPortal",[xY,oO]=rO(sk,{forceMount:void 0}),aO=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:i}=e,s=so(sk,t);return f.jsx(xY,{scope:t,forceMount:n,children:v.Children.map(r,o=>f.jsx(js,{present:n||s.open,children:f.jsx(Yd,{asChild:!0,container:i,children:o})}))})};aO.displayName=sk;var pb="DialogOverlay",lO=v.forwardRef((e,t)=>{const n=oO(pb,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,s=so(pb,e.__scopeDialog);return s.modal?f.jsx(js,{present:r||s.open,children:f.jsx(wY,{...i,ref:t})}):null});lO.displayName=pb;var _Y=Ic("DialogOverlay.RemoveScroll"),wY=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=so(pb,n);return f.jsx(Vp,{as:_Y,allowPinchZoom:!0,shards:[i.contentRef],children:f.jsx(nn.div,{"data-state":ak(i.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),Pc="DialogContent",cO=v.forwardRef((e,t)=>{const n=oO(Pc,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,s=so(Pc,e.__scopeDialog);return f.jsx(js,{present:r||s.open,children:s.modal?f.jsx(SY,{...i,ref:t}):f.jsx(CY,{...i,ref:t})})});cO.displayName=Pc;var SY=v.forwardRef((e,t)=>{const n=so(Pc,e.__scopeDialog),r=v.useRef(null),i=yn(t,n.contentRef,r);return v.useEffect(()=>{const s=r.current;if(s)return xy(s)},[]),f.jsx(uO,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:rt(e.onCloseAutoFocus,s=>{var o;s.preventDefault(),(o=n.triggerRef.current)==null||o.focus()}),onPointerDownOutside:rt(e.onPointerDownOutside,s=>{const o=s.detail.originalEvent,l=o.button===0&&o.ctrlKey===!0;(o.button===2||l)&&s.preventDefault()}),onFocusOutside:rt(e.onFocusOutside,s=>s.preventDefault())})}),CY=v.forwardRef((e,t)=>{const n=so(Pc,e.__scopeDialog),r=v.useRef(!1),i=v.useRef(!1);return f.jsx(uO,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var o,l;(o=e.onCloseAutoFocus)==null||o.call(e,s),s.defaultPrevented||(r.current||(l=n.triggerRef.current)==null||l.focus(),s.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:s=>{var c,u;(c=e.onInteractOutside)==null||c.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const o=s.target;((u=n.triggerRef.current)==null?void 0:u.contains(o))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&i.current&&s.preventDefault()}})}),uO=v.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,...o}=e,l=so(Pc,n),c=v.useRef(null),u=yn(t,c);return by(),f.jsxs(f.Fragment,{children:[f.jsx(Up,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:f.jsx(Kd,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":ak(l.open),...o,ref:u,onDismiss:()=>l.onOpenChange(!1)})}),f.jsxs(f.Fragment,{children:[f.jsx(kY,{titleId:l.titleId}),f.jsx(TY,{contentRef:c,descriptionId:l.descriptionId})]})]})}),ok="DialogTitle",dO=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=so(ok,n);return f.jsx(nn.h2,{id:i.titleId,...r,ref:t})});dO.displayName=ok;var fO="DialogDescription",hO=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=so(fO,n);return f.jsx(nn.p,{id:i.descriptionId,...r,ref:t})});hO.displayName=fO;var pO="DialogClose",mO=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=so(pO,n);return f.jsx(nn.button,{type:"button",...r,ref:t,onClick:rt(e.onClick,()=>i.onOpenChange(!1))})});mO.displayName=pO;function ak(e){return e?"open":"closed"}var gO="DialogTitleWarning",[Q2e,vO]=tK(gO,{contentName:Pc,titleName:ok,docsSlug:"dialog"}),kY=({titleId:e})=>{const t=vO(gO),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
696
+ `)},dY=0,$u=[];function fY(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),i=v.useState(dY++)[0],s=v.useState(Z5)[0],o=v.useRef(e);v.useEffect(function(){o.current=e},[e]),v.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(i));var _=jK([e.lockRef.current],(e.shards||[]).map(lM),!0).filter(Boolean);return _.forEach(function(w){return w.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),_.forEach(function(w){return w.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var l=v.useCallback(function(_,w){if("touches"in _&&_.touches.length===2||_.type==="wheel"&&_.ctrlKey)return!o.current.allowPinchZoom;var C=Lg(_),E=n.current,k="deltaX"in _?_.deltaX:E[0]-C[0],R="deltaY"in _?_.deltaY:E[1]-C[1],N,A=_.target,M=Math.abs(k)>Math.abs(R)?"h":"v";if("touches"in _&&M==="h"&&A.type==="range")return!1;var D=window.getSelection(),U=D&&D.anchorNode,j=U?U===A||U.contains(A):!1;if(j)return!1;var P=oM(M,A);if(!P)return!0;if(P?N=M:(N=M==="v"?"h":"v",P=oM(M,A)),!P)return!1;if(!r.current&&"changedTouches"in _&&(k||R)&&(r.current=N),!N)return!0;var z=r.current||N;return lY(z,w,_,z==="h"?k:R)},[]),c=v.useCallback(function(_){var w=_;if(!(!$u.length||$u[$u.length-1]!==s)){var C="deltaY"in w?aM(w):Lg(w),E=t.current.filter(function(N){return N.name===w.type&&(N.target===w.target||w.target===N.shadowParent)&&cY(N.delta,C)})[0];if(E&&E.should){w.cancelable&&w.preventDefault();return}if(!E){var k=(o.current.shards||[]).map(lM).filter(Boolean).filter(function(N){return N.contains(w.target)}),R=k.length>0?l(w,k[0]):!o.current.noIsolation;R&&w.cancelable&&w.preventDefault()}}},[]),u=v.useCallback(function(_,w,C,E){var k={name:_,delta:w,target:C,should:E,shadowParent:hY(C)};t.current.push(k),setTimeout(function(){t.current=t.current.filter(function(R){return R!==k})},1)},[]),p=v.useCallback(function(_){n.current=Lg(_),r.current=void 0},[]),h=v.useCallback(function(_){u(_.type,aM(_),_.target,l(_,e.lockRef.current))},[]),g=v.useCallback(function(_){u(_.type,Lg(_),_.target,l(_,e.lockRef.current))},[]);v.useEffect(function(){return $u.push(s),e.setCallbacks({onScrollCapture:h,onWheelCapture:h,onTouchMoveCapture:g}),document.addEventListener("wheel",c,Fu),document.addEventListener("touchmove",c,Fu),document.addEventListener("touchstart",p,Fu),function(){$u=$u.filter(function(_){return _!==s}),document.removeEventListener("wheel",c,Fu),document.removeEventListener("touchmove",c,Fu),document.removeEventListener("touchstart",p,Fu)}},[]);var b=e.removeScrollBar,x=e.inert;return v.createElement(v.Fragment,null,x?v.createElement(s,{styles:uY(i)}):null,b?v.createElement(tY,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function hY(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const pY=HK(Q5,fY);var Vp=v.forwardRef(function(e,t){return v.createElement(yy,ko({},e,{ref:t,sideCar:pY}))});Vp.classNames=yy.classNames;var mY=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Hu=new WeakMap,jg=new WeakMap,Dg={},z_=0,nO=function(e){return e&&(e.host||nO(e.parentNode))},gY=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=nO(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},vY=function(e,t,n,r){var i=gY(t,Array.isArray(e)?e:[e]);Dg[n]||(Dg[n]=new WeakMap);var s=Dg[n],o=[],l=new Set,c=new Set(i),u=function(h){!h||l.has(h)||(l.add(h),u(h.parentNode))};i.forEach(u);var p=function(h){!h||c.has(h)||Array.prototype.forEach.call(h.children,function(g){if(l.has(g))p(g);else try{var b=g.getAttribute(r),x=b!==null&&b!=="false",_=(Hu.get(g)||0)+1,w=(s.get(g)||0)+1;Hu.set(g,_),s.set(g,w),o.push(g),_===1&&x&&jg.set(g,!0),w===1&&g.setAttribute(n,"true"),x||g.setAttribute(r,"true")}catch(C){console.error("aria-hidden: cannot operate on ",g,C)}})};return p(t),l.clear(),z_++,function(){o.forEach(function(h){var g=Hu.get(h)-1,b=s.get(h)-1;Hu.set(h,g),s.set(h,b),g||(jg.has(h)||h.removeAttribute(r),jg.delete(h)),b||h.removeAttribute(n)}),z_--,z_||(Hu=new WeakMap,Hu=new WeakMap,jg=new WeakMap,Dg={})}},xy=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),i=mY(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll("[aria-live], script"))),vY(r,i,n,"aria-hidden")):function(){return null}},_y="Dialog",[rO]=Ta(_y),[bY,so]=rO(_y),iO=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!0}=e,l=v.useRef(null),c=v.useRef(null),[u,p]=Td({prop:r,defaultProp:i??!1,onChange:s,caller:_y});return f.jsx(bY,{scope:t,triggerRef:l,contentRef:c,contentId:ba(),titleId:ba(),descriptionId:ba(),open:u,onOpenChange:p,onOpenToggle:v.useCallback(()=>p(h=>!h),[p]),modal:o,children:n})};iO.displayName=_y;var sO="DialogTrigger",yY=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=so(sO,n),s=yn(t,i.triggerRef);return f.jsx(nn.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":ak(i.open),...r,ref:s,onClick:rt(e.onClick,i.onOpenToggle)})});yY.displayName=sO;var sk="DialogPortal",[xY,oO]=rO(sk,{forceMount:void 0}),aO=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:i}=e,s=so(sk,t);return f.jsx(xY,{scope:t,forceMount:n,children:v.Children.map(r,o=>f.jsx(js,{present:n||s.open,children:f.jsx(Yd,{asChild:!0,container:i,children:o})}))})};aO.displayName=sk;var pb="DialogOverlay",lO=v.forwardRef((e,t)=>{const n=oO(pb,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,s=so(pb,e.__scopeDialog);return s.modal?f.jsx(js,{present:r||s.open,children:f.jsx(wY,{...i,ref:t})}):null});lO.displayName=pb;var _Y=Ic("DialogOverlay.RemoveScroll"),wY=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=so(pb,n);return f.jsx(Vp,{as:_Y,allowPinchZoom:!0,shards:[i.contentRef],children:f.jsx(nn.div,{"data-state":ak(i.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),Pc="DialogContent",cO=v.forwardRef((e,t)=>{const n=oO(Pc,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,s=so(Pc,e.__scopeDialog);return f.jsx(js,{present:r||s.open,children:s.modal?f.jsx(SY,{...i,ref:t}):f.jsx(CY,{...i,ref:t})})});cO.displayName=Pc;var SY=v.forwardRef((e,t)=>{const n=so(Pc,e.__scopeDialog),r=v.useRef(null),i=yn(t,n.contentRef,r);return v.useEffect(()=>{const s=r.current;if(s)return xy(s)},[]),f.jsx(uO,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:rt(e.onCloseAutoFocus,s=>{var o;s.preventDefault(),(o=n.triggerRef.current)==null||o.focus()}),onPointerDownOutside:rt(e.onPointerDownOutside,s=>{const o=s.detail.originalEvent,l=o.button===0&&o.ctrlKey===!0;(o.button===2||l)&&s.preventDefault()}),onFocusOutside:rt(e.onFocusOutside,s=>s.preventDefault())})}),CY=v.forwardRef((e,t)=>{const n=so(Pc,e.__scopeDialog),r=v.useRef(!1),i=v.useRef(!1);return f.jsx(uO,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var o,l;(o=e.onCloseAutoFocus)==null||o.call(e,s),s.defaultPrevented||(r.current||(l=n.triggerRef.current)==null||l.focus(),s.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:s=>{var c,u;(c=e.onInteractOutside)==null||c.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const o=s.target;((u=n.triggerRef.current)==null?void 0:u.contains(o))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&i.current&&s.preventDefault()}})}),uO=v.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,...o}=e,l=so(Pc,n),c=v.useRef(null),u=yn(t,c);return by(),f.jsxs(f.Fragment,{children:[f.jsx(Up,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:f.jsx(Kd,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":ak(l.open),...o,ref:u,onDismiss:()=>l.onOpenChange(!1)})}),f.jsxs(f.Fragment,{children:[f.jsx(kY,{titleId:l.titleId}),f.jsx(TY,{contentRef:c,descriptionId:l.descriptionId})]})]})}),ok="DialogTitle",dO=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=so(ok,n);return f.jsx(nn.h2,{id:i.titleId,...r,ref:t})});dO.displayName=ok;var fO="DialogDescription",hO=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=so(fO,n);return f.jsx(nn.p,{id:i.descriptionId,...r,ref:t})});hO.displayName=fO;var pO="DialogClose",mO=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=so(pO,n);return f.jsx(nn.button,{type:"button",...r,ref:t,onClick:rt(e.onClick,()=>i.onOpenChange(!1))})});mO.displayName=pO;function ak(e){return e?"open":"closed"}var gO="DialogTitleWarning",[Z2e,vO]=tK(gO,{contentName:Pc,titleName:ok,docsSlug:"dialog"}),kY=({titleId:e})=>{const t=vO(gO),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
697
697
 
698
698
  If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
699
699
 
@@ -703,7 +703,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
703
703
  `)!==n.readPathDeny.join(`
704
704
  `)&&(A.readPathDeny=R),N.join(`
705
705
  `)!==n.writePathDeny.join(`
706
- `)&&(A.writePathDeny=N),Object.keys(A).length===0?null:A}function E(){i(C())}function k(){i(null)}return f.jsxs(f.Fragment,{children:[f.jsx(Rs,{open:e,onOpenChange:R=>{R||s()},children:f.jsxs(Zi,{className:"max-w-2xl",children:[f.jsxs(Ns,{children:["Permissions — ",t]}),f.jsxs(Io,{className:"space-y-5",children:[f.jsxs("div",{className:"space-y-2",children:[f.jsx("div",{className:"text-sm font-medium",children:"Default action"}),f.jsxs("div",{className:"text-xs text-muted-foreground",children:["Behaviour when a tool call has no explicit allow/deny rule. ",f.jsx("strong",{children:"auto-allow"})," bypasses prompts and runs untrusted shell commands without supervision — use a worktree."]}),f.jsx(da,{value:o,onValueChange:w,options:[{value:"ask",label:"Ask"},{value:"auto-allow",label:"Auto-allow (unsafe)"},{value:"auto-deny",label:"Auto-deny"}]})]}),f.jsxs("div",{className:"space-y-2",children:[f.jsx("div",{className:"text-sm font-medium",children:"Read-path deny list"}),f.jsx("div",{className:"text-xs text-muted-foreground",children:"One glob per line. The model cannot read paths matching any entry. Defaults shown below — edit to add or remove."}),f.jsx("textarea",{value:c,onChange:R=>u(R.target.value),rows:8,className:"w-full rounded-md border border-border bg-background px-3 py-2 font-mono text-xs",spellCheck:!1})]}),f.jsxs("div",{className:"space-y-2",children:[f.jsx("div",{className:"text-sm font-medium",children:"Write-path deny list"}),f.jsx("div",{className:"text-xs text-muted-foreground",children:"One glob per line. The model cannot edit or write paths matching any entry."}),f.jsx("textarea",{value:p,onChange:R=>h(R.target.value),rows:8,className:"w-full rounded-md border border-border bg-background px-3 py-2 font-mono text-xs",spellCheck:!1})]})]}),f.jsxs(_a,{className:"justify-between",children:[f.jsx(Ge,{variant:"ghost",onClick:k,children:"Reset to defaults"}),f.jsxs("div",{className:"flex gap-2",children:[f.jsx(Ge,{variant:"ghost",onClick:s,children:"Cancel"}),f.jsx(Ge,{onClick:E,children:"Apply"})]})]})]})}),f.jsx(Rs,{open:g,onOpenChange:R=>{R||(b(!1),_(null))},children:f.jsxs(Zi,{className:"max-w-md",children:[f.jsx(Ns,{children:"Enable auto-allow for this chat?"}),f.jsxs(Io,{className:"space-y-3 text-sm",children:[f.jsx("p",{children:"Auto-allow disables tool-call prompts. The model can run shell commands, write files, and edit code without asking. Read/write deny lists still apply."}),f.jsx("p",{className:"text-warning",children:"Use a worktree for risky tasks."})]}),f.jsxs(_a,{className:"justify-end gap-2",children:[f.jsx(Ge,{variant:"ghost",onClick:()=>{b(!1),_(null)},children:"Cancel"}),f.jsx(Ge,{variant:"destructive",onClick:()=>{x&&l(x),b(!1),_(null)},children:"Enable auto-allow"})]})]})})]})}function xQ({open:e,shareUrl:t,onOpenChange:n,onOpenLink:r,onCopyLink:i}){const[s,o]=v.useState(!1);v.useEffect(()=>{e||o(!1)},[e,t]);const l=async()=>{await i()&&(o(!0),window.setTimeout(()=>{o(!1)},2e3))};return f.jsx(Rs,{open:e,onOpenChange:n,children:f.jsxs(Zi,{size:"md",children:[f.jsxs(CO,{children:[f.jsx(Ns,{children:"Shared Link"}),f.jsx(Xd,{children:"Shared links are snapshots in time and contain all attachments, tool calls and history. Be mindful of sensitive info."})]}),f.jsx(Io,{className:"space-y-3",children:f.jsxs("div",{className:"flex w-full items-center gap-2 rounded-2xl border border-border bg-muted/40 pl-4 px-3 py-2.5",children:[f.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-sm text-foreground",children:t}),f.jsx("button",{type:"button",onClick:()=>void l(),title:s?"Copied":"Copy link","aria-label":s?"Copied":"Copy link",className:"flex flex-shrink-0 items-center justify-center rounded-lg text-logo hover:text-logo/60 transition-colors hover:bg-background hover:text-foreground",children:s?f.jsx(yi,{className:"h-4 w-4 text-emerald-400"}):f.jsx(jl,{className:"h-4 w-4"})})]})}),f.jsx(_a,{children:f.jsxs(IY,{type:"button",onClick:r,children:[f.jsx(XC,{className:"mr-2 h-4 w-4"}),"Open"]})})]})})}const _Q={defaultAction:"ask",bash:{autoAllowVerbs:["ls","pwd","git status","git diff","git log"]},readPathDeny:["~/.ssh","~/.aws","~/.gcp","~/.config/gh","~/.claude","~/.kanna","~/Library/Keychains","/etc/shadow","/etc/sudoers","~/.gnupg","~/.gitconfig","**/.git/config","~/.npmrc","~/.netrc","~/.docker/config.json","**/.env","**/.env.*","**/credentials*","**/*.pem","**/*.key","**/id_rsa*","**/id_ed25519*"],writePathDeny:["/etc/**","/usr/**","/System/**","~/.ssh/**","~/.aws/**","~/.config/gh/**","~/.claude/**","~/.kanna/**","~/.gnupg/**","~/.gitconfig","**/.git/config"],toolDenyList:[{tool:"mcp__kanna__bash",pattern:"rm\\s+-rf\\s+(/|~|\\$HOME)(?:\\b|$|\\s)"},{tool:"mcp__kanna__bash",pattern:"git\\s+push\\b.*--force"}],toolAllowList:[]},Kn=v.forwardRef(({className:e,type:t,...n},r)=>f.jsx("input",{ref:r,type:t,className:me("flex w-full rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50",e),...n}));Kn.displayName="Input";const a3=v.createContext(null);function wQ({children:e}){const[t,n]=v.useState(null),[r,i]=v.useState(""),s=v.useRef(null);v.useEffect(()=>{(t==null?void 0:t.kind)==="prompt"&&(i(t.options.initialValue??""),setTimeout(()=>{var b,x;(b=s.current)==null||b.focus(),(x=s.current)==null||x.select()},0))},[t]);const o=v.useCallback(()=>{n(null),i("")},[]),l=v.useCallback(()=>{t&&(t.kind==="confirm"?t.resolve(!1):t.kind==="prompt"?t.resolve(null):t.resolve(),o())},[o,t]),c=v.useCallback(()=>{t&&(t.kind==="confirm"?t.resolve(!0):t.kind==="prompt"?t.resolve(r.trim()||null):t.resolve(),o())},[o,t,r]),u=v.useCallback(b=>new Promise(x=>{n({kind:"confirm",options:b,resolve:x})}),[]),p=v.useCallback(b=>new Promise(x=>{n({kind:"prompt",options:b,resolve:x})}),[]),h=v.useCallback(b=>new Promise(x=>{n({kind:"alert",options:b,resolve:x})}),[]),g=v.useMemo(()=>({confirm:u,prompt:p,alert:h}),[h,u,p]);return f.jsxs(a3.Provider,{value:g,children:[e,f.jsx(Rs,{open:t!==null,onOpenChange:b=>{b||!t||l()},children:f.jsx(Zi,{size:"sm",onKeyDown:b=>{b.key!=="Enter"||b.shiftKey||!t||t.kind!=="confirm"||(b.preventDefault(),c())},children:t?f.jsxs(f.Fragment,{children:[f.jsxs(Io,{className:"space-y-4",children:[f.jsx(Ns,{children:t.options.title}),t.options.description?f.jsx(Xd,{children:t.options.description}):null,t.kind==="prompt"?f.jsx(Kn,{ref:s,type:"text",value:r,onChange:b=>i(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),c())},placeholder:t.options.placeholder}):null]}),f.jsxs(_a,{children:[f.jsx(Ge,{variant:"ghost",size:"sm",onClick:l,className:t.kind==="alert"?"hidden":void 0,children:"cancelLabel"in t.options?t.options.cancelLabel??"Cancel":"Cancel"}),f.jsx(Ge,{variant:t.kind==="confirm"?t.options.confirmVariant??"default":"secondary",size:"sm",onClick:c,disabled:t.kind==="prompt"&&!r.trim(),children:t.kind==="alert"?t.options.closeLabel??"OK":"confirmLabel"in t.options?t.options.confirmLabel??"Confirm":"Confirm"})]})]}):null})})]})}function Kp(){const e=v.useContext(a3);if(!e)throw new Error("useAppDialog must be used within AppDialogProvider");return e}const wk=v.forwardRef(({className:e,...t},n)=>f.jsx("div",{ref:n,className:me("bg-card text-card-foreground",e),...t}));wk.displayName="Card";const Sk=v.forwardRef(({className:e,...t},n)=>f.jsx("div",{ref:n,className:me("flex flex-col space-y-1.5 p-2",e),...t}));Sk.displayName="CardHeader";const l3=v.forwardRef(({className:e,...t},n)=>f.jsx("h3",{ref:n,className:me("text-2xl font-semibold leading-none tracking-tight",e),...t}));l3.displayName="CardTitle";const c3=v.forwardRef(({className:e,...t},n)=>f.jsx("p",{ref:n,className:me("text-sm text-muted-foreground",e),...t}));c3.displayName="CardDescription";const Ck=v.forwardRef(({className:e,...t},n)=>f.jsx("div",{ref:n,className:me("p-6 pt-0",e),...t}));Ck.displayName="CardContent";const SQ=v.forwardRef(({className:e,...t},n)=>f.jsx("div",{ref:n,className:me("flex items-center p-6 pt-0",e),...t}));SQ.displayName="CardFooter";const CQ="modulepreload",kQ=function(e){return"/"+e},CM={},K=function(t,n,r){let i=Promise.resolve();if(n&&n.length>0){let o=function(u){return Promise.all(u.map(p=>Promise.resolve(p).then(h=>({status:"fulfilled",value:h}),h=>({status:"rejected",reason:h}))))};document.getElementsByTagName("link");const l=document.querySelector("meta[property=csp-nonce]"),c=(l==null?void 0:l.nonce)||(l==null?void 0:l.getAttribute("nonce"));i=o(n.map(u=>{if(u=kQ(u),u in CM)return;CM[u]=!0;const p=u.endsWith(".css"),h=p?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${u}"]${h}`))return;const g=document.createElement("link");if(g.rel=p?"stylesheet":CQ,p||(g.as="script"),g.crossOrigin="",g.href=u,c&&g.setAttribute("nonce",c),document.head.appendChild(g),p)return new Promise((b,x)=>{g.addEventListener("load",b),g.addEventListener("error",()=>x(new Error(`Unable to preload CSS for ${u}`)))})}))}function s(o){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=o,window.dispatchEvent(l),!l.defaultPrevented)throw o}return i.then(o=>{for(const l of o||[])l.status==="rejected"&&s(l.reason);return t().catch(s)})},EQ=v.lazy(()=>K(()=>import("./index-DZs2QDFW.js"),[]).then(e=>({default:e.Toaster})));function TQ(){return f.jsx(v.Suspense,{fallback:null,children:f.jsx(EQ,{position:"bottom-right",theme:"system",closeButton:!0,duration:6e3})})}const RQ="0.56.3",NQ={version:RQ},or="Kanna",kM="kanna",AQ=".kanna",MQ=".kanna-dev",LQ="KANNA_RUNTIME_PROFILE",kk=`kanna/${NQ.version}`,jQ="[kanna]",DQ=`~/${or}`;function Ly(){var t;return(t=globalThis.process)==null?void 0:t.env}function IQ(e=Ly()){var t;return((t=e==null?void 0:e[LQ])==null?void 0:t.trim().toLowerCase())==="dev"?"dev":"prod"}function PQ(e=Ly()){return IQ(e)==="dev"?MQ:AQ}function OQ(e=Ly()){return`~/${PQ(e)}`}function zQ(e=Ly()){return`${OQ(e)}/keybindings.json`}function Pg(e){return e?`${kM} ${e}`:kM}const EM=e=>{let t;const n=new Set,r=(u,p)=>{const h=typeof u=="function"?u(t):u;if(!Object.is(h,t)){const g=t;t=p??(typeof h!="object"||h===null)?h:Object.assign({},t,h),n.forEach(b=>b(t,g))}},i=()=>t,l={setState:r,getState:i,getInitialState:()=>c,subscribe:u=>(n.add(u),()=>n.delete(u))},c=t=e(r,i,l);return l},BQ=(e=>e?EM(e):EM),FQ=e=>e;function $Q(e,t=FQ){const n=_n.useSyncExternalStore(e.subscribe,_n.useCallback(()=>t(e.getState()),[e,t]),_n.useCallback(()=>t(e.getInitialState()),[e,t]));return _n.useDebugValue(n),n}const HQ=e=>{const t=BQ(e),n=r=>$Q(t,r);return Object.assign(n,t),n},oo=(e=>HQ),u3="always",d3="funk",UQ=[{value:"blow",label:"Blow"},{value:"bottle",label:"Bottle"},{value:"frog",label:"Frog"},{value:"funk",label:"Funk"},{value:"glass",label:"Glass"},{value:"ping",label:"Ping"},{value:"pop",label:"Pop"},{value:"purr",label:"Purr"},{value:"tink",label:"Tink"}];function VQ(e){switch(e){case"never":case"unfocused":case"always":return e;default:return u3}}function WQ(e){switch(e){case"blow":case"bottle":case"frog":case"funk":case"glass":case"ping":case"pop":case"purr":case"tink":return e;default:return d3}}const Ec=oo()(e=>({chatSoundPreference:u3,chatSoundId:d3,setChatSoundPreference:t=>e({chatSoundPreference:VQ(t)}),setChatSoundId:t=>e({chatSoundId:WQ(t)})})),GQ={blow:"/chat-sounds/Blow.mp3",bottle:"/chat-sounds/Bottle.mp3",frog:"/chat-sounds/Frog.mp3",funk:"/chat-sounds/Funk.mp3",glass:"/chat-sounds/Glass.mp3",ping:"/chat-sounds/Ping.mp3",pop:"/chat-sounds/Pop.mp3",purr:"/chat-sounds/Purr.mp3",tink:"/chat-sounds/Tink.mp3"};function qQ(e=document){return e.visibilityState!=="visible"||!e.hasFocus()}function KQ(e){const t=new Audio(GQ[e]);return t.preload="auto",t.play()}async function DS(e,t){if(t<=0)return;const n=Array.from({length:t},(r,i)=>new Promise(s=>{window.setTimeout(()=>{KQ(e).catch(()=>{}).finally(()=>s())},i*90)}));await Promise.all(n)}function YQ(e,t=document){return e==="never"?!1:e==="always"?!0:qQ(t)}function XQ(e){return e.projectGroups.reduce((t,n)=>t+n.chats.reduce((r,i)=>r+(i.unread?1:0)+(i.status==="waiting_for_user"?1:0),0),0)}function TM(e){let t=0;const n=new Set;for(const r of e.projectGroups)for(const i of r.chats)i.unread&&(t+=1),i.status==="waiting_for_user"&&n.add(i.chatId);return{unreadCount:t,waitingChatIds:n}}function QQ(e,t){if(!e)return 0;const n=TM(e),r=TM(t),i=Math.max(0,r.unreadCount-n.unreadCount);let s=0;for(const o of r.waitingChatIds)n.waitingChatIds.has(o)||(s+=1);return i+s}function IS(e){return e.split(/[\s_-]+/).filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" ")}const ZQ=[/^(?:\/usr\/bin\/env\s+)?(?:\/bin\/)?(?:bash|zsh|sh)\s+(?:-[a-zA-Z]*c|-c)\s+(['"])([\s\S]*)\1$/,/^(?:\/usr\/bin\/env\s+)?(?:\/bin\/)?(?:bash|zsh|sh)\s+(?:-[a-zA-Z]*c|-c)\s+(.+)$/,/^(?:\/usr\/bin\/env\s+)?(?:cmd(?:\.exe)?)\s+\/c\s+(['"])([\s\S]*)\1$/i,/^(?:\/usr\/bin\/env\s+)?(?:cmd(?:\.exe)?)\s+\/c\s+(.+)$/i,/^(?:\/usr\/bin\/env\s+)?(?:powershell(?:\.exe)?|pwsh)\s+(?:-NoProfile\s+)?-Command\s+(['"])([\s\S]*)\1$/i,/^(?:\/usr\/bin\/env\s+)?(?:powershell(?:\.exe)?|pwsh)\s+(?:-NoProfile\s+)?-Command\s+(.+)$/i];function JQ(e){const t=e.trim();for(const n of ZQ){const r=t.match(n);if(!r)continue;const i=(r[2]??r[1]??"").trim();if(i)return i}return t}function Ek(e){return e.split("/").pop()||e}const eZ=1440*6e4;function tZ(e,t){const n=Math.max(0,t-e),r=Math.floor(n/1e3),i=Math.floor(r/3600),s=Math.floor(r%3600/60),o=r%60;return i>0?`${i}h ${s}m`:s>0?`${s}m ${o}s`:`${o}s`}function nZ(e){const t=new Date(e),n=t.getHours().toString().padStart(2,"0"),r=t.getMinutes().toString().padStart(2,"0");return`${n}:${r}`}function rZ(e,t){if(e===void 0)return null;const n=Math.max(0,t-e),r=6e4,i=60*r,s=eZ,o=7*s;return n<r?"now":n<i?`${Math.floor(n/r)}m`:n<s?`${Math.floor(n/i)}h`:n<o?`${Math.floor(n/s)}d`:`${Math.floor(n/o)}w`}function iZ(e){return e.lastMessageAt??e._creationTime}const Tk=1e3,Fv=60*Tk,ld=60*Fv,H_=24*ld;function xl(e){const t=Math.max(0,e);if(t<Fv)return`${Math.floor(t/Tk)}s`;if(t<ld)return`${Math.floor(t/Fv)}m`;if(t<H_){const i=Math.floor(t/ld),s=Math.floor(t%ld/Fv);return s===0?`${i}h`:`${i}h ${s}m`}const n=Math.floor(t/H_),r=Math.floor(t%H_/ld);return r===0?`${n}d`:`${n}d ${r}h`}function PS(e){const t=Math.max(0,e);if(t>=ld)return xl(t);const n=Math.floor(t/Tk),r=Math.floor(n/60),i=n%60;return`${r}:${i.toString().padStart(2,"0")}`}function OS(e){switch(e){case"idle":return"Idle";case"starting":return"Starting";case"running":return"Running";case"waiting_for_user":return"Waiting";case"failed":return"Failed"}}function RM(e){switch(e){case"running":return"active";case"waiting_for_user":return"attention";case"failed":return"destructive";case"idle":case"starting":default:return"muted"}}function NM(e){switch(e){case"active":return"text-emerald-500 dark:text-emerald-400";case"attention":return"text-amber-500 dark:text-amber-400";case"destructive":return"text-destructive";case"muted":default:return"text-muted-foreground"}}function Rk(e){const t=e+"CollectionProvider",[n,r]=Ta(t),[i,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),o=_=>{const{scope:w,children:C}=_,E=_n.useRef(null),k=_n.useRef(new Map).current;return f.jsx(i,{scope:w,itemMap:k,collectionRef:E,children:C})};o.displayName=t;const l=e+"CollectionSlot",c=Ic(l),u=_n.forwardRef((_,w)=>{const{scope:C,children:E}=_,k=s(l,C),R=yn(w,k.collectionRef);return f.jsx(c,{ref:R,children:E})});u.displayName=l;const p=e+"CollectionItemSlot",h="data-radix-collection-item",g=Ic(p),b=_n.forwardRef((_,w)=>{const{scope:C,children:E,...k}=_,R=_n.useRef(null),N=yn(w,R),A=s(p,C);return _n.useEffect(()=>(A.itemMap.set(R,{ref:R,...k}),()=>void A.itemMap.delete(R))),f.jsx(g,{[h]:"",ref:N,children:E})});b.displayName=p;function x(_){const w=s(e+"CollectionConsumer",_);return _n.useCallback(()=>{const E=w.collectionRef.current;if(!E)return[];const k=Array.from(E.querySelectorAll(`[${h}]`));return Array.from(w.itemMap.values()).sort((A,M)=>k.indexOf(A.ref.current)-k.indexOf(M.ref.current))},[w.collectionRef,w.itemMap])}return[{Provider:o,Slot:u,ItemSlot:b},x,r]}var sZ=v.createContext(void 0);function Nk(e){const t=v.useContext(sZ);return e||t||"ltr"}var U_="rovingFocusGroup.onEntryFocus",oZ={bubbles:!1,cancelable:!0},Yp="RovingFocusGroup",[zS,f3,aZ]=Rk(Yp),[lZ,h3]=Ta(Yp,[aZ]),[cZ,uZ]=lZ(Yp),p3=v.forwardRef((e,t)=>f.jsx(zS.Provider,{scope:e.__scopeRovingFocusGroup,children:f.jsx(zS.Slot,{scope:e.__scopeRovingFocusGroup,children:f.jsx(dZ,{...e,ref:t})})}));p3.displayName=Yp;var dZ=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:s,currentTabStopId:o,defaultCurrentTabStopId:l,onCurrentTabStopIdChange:c,onEntryFocus:u,preventScrollOnEntryFocus:p=!1,...h}=e,g=v.useRef(null),b=yn(t,g),x=Nk(s),[_,w]=Td({prop:o,defaultProp:l??null,onChange:c,caller:Yp}),[C,E]=v.useState(!1),k=Js(u),R=f3(n),N=v.useRef(!1),[A,M]=v.useState(0);return v.useEffect(()=>{const D=g.current;if(D)return D.addEventListener(U_,k),()=>D.removeEventListener(U_,k)},[k]),f.jsx(cZ,{scope:n,orientation:r,dir:x,loop:i,currentTabStopId:_,onItemFocus:v.useCallback(D=>w(D),[w]),onItemShiftTab:v.useCallback(()=>E(!0),[]),onFocusableItemAdd:v.useCallback(()=>M(D=>D+1),[]),onFocusableItemRemove:v.useCallback(()=>M(D=>D-1),[]),children:f.jsx(nn.div,{tabIndex:C||A===0?-1:0,"data-orientation":r,...h,ref:b,style:{outline:"none",...e.style},onMouseDown:rt(e.onMouseDown,()=>{N.current=!0}),onFocus:rt(e.onFocus,D=>{const U=!N.current;if(D.target===D.currentTarget&&U&&!C){const j=new CustomEvent(U_,oZ);if(D.currentTarget.dispatchEvent(j),!j.defaultPrevented){const P=R().filter(B=>B.focusable),z=P.find(B=>B.active),O=P.find(B=>B.id===_),V=[z,O,...P].filter(Boolean).map(B=>B.ref.current);v3(V,p)}}N.current=!1}),onBlur:rt(e.onBlur,()=>E(!1))})})}),m3="RovingFocusGroupItem",g3=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,c=ba(),u=s||c,p=uZ(m3,n),h=p.currentTabStopId===u,g=f3(n),{onFocusableItemAdd:b,onFocusableItemRemove:x,currentTabStopId:_}=p;return v.useEffect(()=>{if(r)return b(),()=>x()},[r,b,x]),f.jsx(zS.ItemSlot,{scope:n,id:u,focusable:r,active:i,children:f.jsx(nn.span,{tabIndex:h?0:-1,"data-orientation":p.orientation,...l,ref:t,onMouseDown:rt(e.onMouseDown,w=>{r?p.onItemFocus(u):w.preventDefault()}),onFocus:rt(e.onFocus,()=>p.onItemFocus(u)),onKeyDown:rt(e.onKeyDown,w=>{if(w.key==="Tab"&&w.shiftKey){p.onItemShiftTab();return}if(w.target!==w.currentTarget)return;const C=pZ(w,p.orientation,p.dir);if(C!==void 0){if(w.metaKey||w.ctrlKey||w.altKey||w.shiftKey)return;w.preventDefault();let k=g().filter(R=>R.focusable).map(R=>R.ref.current);if(C==="last")k.reverse();else if(C==="prev"||C==="next"){C==="prev"&&k.reverse();const R=k.indexOf(w.currentTarget);k=p.loop?mZ(k,R+1):k.slice(R+1)}setTimeout(()=>v3(k))}}),children:typeof o=="function"?o({isCurrentTabStop:h,hasTabStop:_!=null}):o})})});g3.displayName=m3;var fZ={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function hZ(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function pZ(e,t,n){const r=hZ(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return fZ[r]}function v3(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function mZ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var gZ=p3,vZ=g3,BS=["Enter"," "],bZ=["ArrowDown","PageUp","Home"],b3=["ArrowUp","PageDown","End"],yZ=[...bZ,...b3],xZ={ltr:[...BS,"ArrowRight"],rtl:[...BS,"ArrowLeft"]},_Z={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Xp="Menu",[cp,wZ,SZ]=Rk(Xp),[Xc,y3]=Ta(Xp,[SZ,Bl,h3]),jy=Bl(),x3=h3(),[CZ,Qc]=Xc(Xp),[kZ,Qp]=Xc(Xp),_3=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=jy(t),[c,u]=v.useState(null),p=v.useRef(!1),h=Js(s),g=Nk(i);return v.useEffect(()=>{const b=()=>{p.current=!0,document.addEventListener("pointerdown",x,{capture:!0,once:!0}),document.addEventListener("pointermove",x,{capture:!0,once:!0})},x=()=>p.current=!1;return document.addEventListener("keydown",b,{capture:!0}),()=>{document.removeEventListener("keydown",b,{capture:!0}),document.removeEventListener("pointerdown",x,{capture:!0}),document.removeEventListener("pointermove",x,{capture:!0})}},[]),f.jsx(Ey,{...l,children:f.jsx(CZ,{scope:t,open:n,onOpenChange:h,content:c,onContentChange:u,children:f.jsx(kZ,{scope:t,onClose:v.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:p,dir:g,modal:o,children:r})})})};_3.displayName=Xp;var EZ="MenuAnchor",Ak=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=jy(n);return f.jsx(Gp,{...i,...r,ref:t})});Ak.displayName=EZ;var Mk="MenuPortal",[TZ,w3]=Xc(Mk,{forceMount:void 0}),S3=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=Qc(Mk,t);return f.jsx(TZ,{scope:t,forceMount:n,children:f.jsx(js,{present:n||s.open,children:f.jsx(Yd,{asChild:!0,container:i,children:r})})})};S3.displayName=Mk;var Es="MenuContent",[RZ,Lk]=Xc(Es),C3=v.forwardRef((e,t)=>{const n=w3(Es,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=Qc(Es,e.__scopeMenu),o=Qp(Es,e.__scopeMenu);return f.jsx(cp.Provider,{scope:e.__scopeMenu,children:f.jsx(js,{present:r||s.open,children:f.jsx(cp.Slot,{scope:e.__scopeMenu,children:o.modal?f.jsx(NZ,{...i,ref:t}):f.jsx(AZ,{...i,ref:t})})})})}),NZ=v.forwardRef((e,t)=>{const n=Qc(Es,e.__scopeMenu),r=v.useRef(null),i=yn(t,r);return v.useEffect(()=>{const s=r.current;if(s)return xy(s)},[]),f.jsx(jk,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:rt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),AZ=v.forwardRef((e,t)=>{const n=Qc(Es,e.__scopeMenu);return f.jsx(jk,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),MZ=Ic("MenuContent.ScrollLock"),jk=v.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:l,onEntryFocus:c,onEscapeKeyDown:u,onPointerDownOutside:p,onFocusOutside:h,onInteractOutside:g,onDismiss:b,disableOutsideScroll:x,..._}=e,w=Qc(Es,n),C=Qp(Es,n),E=jy(n),k=x3(n),R=wZ(n),[N,A]=v.useState(null),M=v.useRef(null),D=yn(t,M,w.onContentChange),U=v.useRef(0),j=v.useRef(""),P=v.useRef(0),z=v.useRef(null),O=v.useRef("right"),$=v.useRef(0),V=x?Vp:v.Fragment,B=x?{as:MZ,allowPinchZoom:!0}:void 0,F=X=>{var te,ie;const I=j.current+X,G=R().filter(de=>!de.disabled),ee=document.activeElement,H=(te=G.find(de=>de.ref.current===ee))==null?void 0:te.textValue,ue=G.map(de=>de.textValue),ae=UZ(ue,I,H),J=(ie=G.find(de=>de.textValue===ae))==null?void 0:ie.ref.current;(function de(he){j.current=he,window.clearTimeout(U.current),he!==""&&(U.current=window.setTimeout(()=>de(""),1e3))})(I),J&&setTimeout(()=>J.focus())};v.useEffect(()=>()=>window.clearTimeout(U.current),[]),by();const W=v.useCallback(X=>{var G,ee;return O.current===((G=z.current)==null?void 0:G.side)&&WZ(X,(ee=z.current)==null?void 0:ee.area)},[]);return f.jsx(RZ,{scope:n,searchRef:j,onItemEnter:v.useCallback(X=>{W(X)&&X.preventDefault()},[W]),onItemLeave:v.useCallback(X=>{var I;W(X)||((I=M.current)==null||I.focus(),A(null))},[W]),onTriggerLeave:v.useCallback(X=>{W(X)&&X.preventDefault()},[W]),pointerGraceTimerRef:P,onPointerGraceIntentChange:v.useCallback(X=>{z.current=X},[]),children:f.jsx(V,{...B,children:f.jsx(Up,{asChild:!0,trapped:i,onMountAutoFocus:rt(s,X=>{var I;X.preventDefault(),(I=M.current)==null||I.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:f.jsx(Kd,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:u,onPointerDownOutside:p,onFocusOutside:h,onInteractOutside:g,onDismiss:b,children:f.jsx(gZ,{asChild:!0,...k,dir:C.dir,orientation:"vertical",loop:r,currentTabStopId:N,onCurrentTabStopIdChange:A,onEntryFocus:rt(c,X=>{C.isUsingKeyboardRef.current||X.preventDefault()}),preventScrollOnEntryFocus:!0,children:f.jsx(Ty,{role:"menu","aria-orientation":"vertical","data-state":F3(w.open),"data-radix-menu-content":"",dir:C.dir,...E,..._,ref:D,style:{outline:"none",..._.style},onKeyDown:rt(_.onKeyDown,X=>{const G=X.target.closest("[data-radix-menu-content]")===X.currentTarget,ee=X.ctrlKey||X.altKey||X.metaKey,H=X.key.length===1;G&&(X.key==="Tab"&&X.preventDefault(),!ee&&H&&F(X.key));const ue=M.current;if(X.target!==ue||!yZ.includes(X.key))return;X.preventDefault();const J=R().filter(te=>!te.disabled).map(te=>te.ref.current);b3.includes(X.key)&&J.reverse(),$Z(J)}),onBlur:rt(e.onBlur,X=>{X.currentTarget.contains(X.target)||(window.clearTimeout(U.current),j.current="")}),onPointerMove:rt(e.onPointerMove,up(X=>{const I=X.target,G=$.current!==X.clientX;if(X.currentTarget.contains(I)&&G){const ee=X.clientX>$.current?"right":"left";O.current=ee,$.current=X.clientX}}))})})})})})})});C3.displayName=Es;var LZ="MenuGroup",Dk=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return f.jsx(nn.div,{role:"group",...r,ref:t})});Dk.displayName=LZ;var jZ="MenuLabel",k3=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return f.jsx(nn.div,{...r,ref:t})});k3.displayName=jZ;var Sb="MenuItem",AM="menu.itemSelect",Dy=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=v.useRef(null),o=Qp(Sb,e.__scopeMenu),l=Lk(Sb,e.__scopeMenu),c=yn(t,s),u=v.useRef(!1),p=()=>{const h=s.current;if(!n&&h){const g=new CustomEvent(AM,{bubbles:!0,cancelable:!0});h.addEventListener(AM,b=>r==null?void 0:r(b),{once:!0}),W5(h,g),g.defaultPrevented?u.current=!1:o.onClose()}};return f.jsx(E3,{...i,ref:c,disabled:n,onClick:rt(e.onClick,p),onPointerDown:h=>{var g;(g=e.onPointerDown)==null||g.call(e,h),u.current=!0},onPointerUp:rt(e.onPointerUp,h=>{var g;u.current||(g=h.currentTarget)==null||g.click()}),onKeyDown:rt(e.onKeyDown,h=>{const g=l.searchRef.current!=="";n||g&&h.key===" "||BS.includes(h.key)&&(h.currentTarget.click(),h.preventDefault())})})});Dy.displayName=Sb;var E3=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=Lk(Sb,n),l=x3(n),c=v.useRef(null),u=yn(t,c),[p,h]=v.useState(!1),[g,b]=v.useState("");return v.useEffect(()=>{const x=c.current;x&&b((x.textContent??"").trim())},[s.children]),f.jsx(cp.ItemSlot,{scope:n,disabled:r,textValue:i??g,children:f.jsx(vZ,{asChild:!0,...l,focusable:!r,children:f.jsx(nn.div,{role:"menuitem","data-highlighted":p?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:u,onPointerMove:rt(e.onPointerMove,up(x=>{r?o.onItemLeave(x):(o.onItemEnter(x),x.defaultPrevented||x.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:rt(e.onPointerLeave,up(x=>o.onItemLeave(x))),onFocus:rt(e.onFocus,()=>h(!0)),onBlur:rt(e.onBlur,()=>h(!1))})})})}),DZ="MenuCheckboxItem",T3=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return f.jsx(L3,{scope:e.__scopeMenu,checked:n,children:f.jsx(Dy,{role:"menuitemcheckbox","aria-checked":Cb(n)?"mixed":n,...i,ref:t,"data-state":Pk(n),onSelect:rt(i.onSelect,()=>r==null?void 0:r(Cb(n)?!0:!n),{checkForDefaultPrevented:!1})})})});T3.displayName=DZ;var R3="MenuRadioGroup",[IZ,PZ]=Xc(R3,{value:void 0,onValueChange:()=>{}}),N3=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=Js(r);return f.jsx(IZ,{scope:e.__scopeMenu,value:n,onValueChange:s,children:f.jsx(Dk,{...i,ref:t})})});N3.displayName=R3;var A3="MenuRadioItem",M3=v.forwardRef((e,t)=>{const{value:n,...r}=e,i=PZ(A3,e.__scopeMenu),s=n===i.value;return f.jsx(L3,{scope:e.__scopeMenu,checked:s,children:f.jsx(Dy,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Pk(s),onSelect:rt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});M3.displayName=A3;var Ik="MenuItemIndicator",[L3,OZ]=Xc(Ik,{checked:!1}),j3=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=OZ(Ik,n);return f.jsx(js,{present:r||Cb(s.checked)||s.checked===!0,children:f.jsx(nn.span,{...i,ref:t,"data-state":Pk(s.checked)})})});j3.displayName=Ik;var zZ="MenuSeparator",D3=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return f.jsx(nn.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});D3.displayName=zZ;var BZ="MenuArrow",I3=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=jy(n);return f.jsx(Ry,{...i,...r,ref:t})});I3.displayName=BZ;var FZ="MenuSub",[Z2e,P3]=Xc(FZ),Nh="MenuSubTrigger",O3=v.forwardRef((e,t)=>{const n=Qc(Nh,e.__scopeMenu),r=Qp(Nh,e.__scopeMenu),i=P3(Nh,e.__scopeMenu),s=Lk(Nh,e.__scopeMenu),o=v.useRef(null),{pointerGraceTimerRef:l,onPointerGraceIntentChange:c}=s,u={__scopeMenu:e.__scopeMenu},p=v.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return v.useEffect(()=>p,[p]),v.useEffect(()=>{const h=l.current;return()=>{window.clearTimeout(h),c(null)}},[l,c]),f.jsx(Ak,{asChild:!0,...u,children:f.jsx(E3,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":F3(n.open),...e,ref:ik(t,i.onTriggerChange),onClick:h=>{var g;(g=e.onClick)==null||g.call(e,h),!(e.disabled||h.defaultPrevented)&&(h.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:rt(e.onPointerMove,up(h=>{s.onItemEnter(h),!h.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),p()},100))})),onPointerLeave:rt(e.onPointerLeave,up(h=>{var b,x;p();const g=(b=n.content)==null?void 0:b.getBoundingClientRect();if(g){const _=(x=n.content)==null?void 0:x.dataset.side,w=_==="right",C=w?-5:5,E=g[w?"left":"right"],k=g[w?"right":"left"];s.onPointerGraceIntentChange({area:[{x:h.clientX+C,y:h.clientY},{x:E,y:g.top},{x:k,y:g.top},{x:k,y:g.bottom},{x:E,y:g.bottom}],side:_}),window.clearTimeout(l.current),l.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(h),h.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:rt(e.onKeyDown,h=>{var b;const g=s.searchRef.current!=="";e.disabled||g&&h.key===" "||xZ[r.dir].includes(h.key)&&(n.onOpenChange(!0),(b=n.content)==null||b.focus(),h.preventDefault())})})})});O3.displayName=Nh;var z3="MenuSubContent",B3=v.forwardRef((e,t)=>{const n=w3(Es,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=Qc(Es,e.__scopeMenu),o=Qp(Es,e.__scopeMenu),l=P3(z3,e.__scopeMenu),c=v.useRef(null),u=yn(t,c);return f.jsx(cp.Provider,{scope:e.__scopeMenu,children:f.jsx(js,{present:r||s.open,children:f.jsx(cp.Slot,{scope:e.__scopeMenu,children:f.jsx(jk,{id:l.contentId,"aria-labelledby":l.triggerId,...i,ref:u,align:"start",side:o.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:p=>{var h;o.isUsingKeyboardRef.current&&((h=c.current)==null||h.focus()),p.preventDefault()},onCloseAutoFocus:p=>p.preventDefault(),onFocusOutside:rt(e.onFocusOutside,p=>{p.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:rt(e.onEscapeKeyDown,p=>{o.onClose(),p.preventDefault()}),onKeyDown:rt(e.onKeyDown,p=>{var b;const h=p.currentTarget.contains(p.target),g=_Z[o.dir].includes(p.key);h&&g&&(s.onOpenChange(!1),(b=l.trigger)==null||b.focus(),p.preventDefault())})})})})})});B3.displayName=z3;function F3(e){return e?"open":"closed"}function Cb(e){return e==="indeterminate"}function Pk(e){return Cb(e)?"indeterminate":e?"checked":"unchecked"}function $Z(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function HZ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function UZ(e,t,n){const i=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let o=HZ(e,Math.max(s,0));i.length===1&&(o=o.filter(u=>u!==n));const c=o.find(u=>u.toLowerCase().startsWith(i.toLowerCase()));return c!==n?c:void 0}function VZ(e,t){const{x:n,y:r}=e;let i=!1;for(let s=0,o=t.length-1;s<t.length;o=s++){const l=t[s],c=t[o],u=l.x,p=l.y,h=c.x,g=c.y;p>r!=g>r&&n<(h-u)*(r-p)/(g-p)+u&&(i=!i)}return i}function WZ(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return VZ(n,t)}function up(e){return t=>t.pointerType==="mouse"?e(t):void 0}var GZ=_3,qZ=Ak,KZ=S3,YZ=C3,XZ=Dk,QZ=k3,ZZ=Dy,JZ=T3,eJ=N3,tJ=M3,nJ=j3,rJ=D3,iJ=I3,sJ=O3,oJ=B3,Ok="ContextMenu",[aJ]=Ta(Ok,[y3]),xi=y3(),[lJ,$3]=aJ(Ok),H3=e=>{const{__scopeContextMenu:t,children:n,onOpenChange:r,dir:i,modal:s=!0}=e,[o,l]=v.useState(!1),c=xi(t),u=Js(r),p=v.useCallback(h=>{l(h),u(h)},[u]);return f.jsx(lJ,{scope:t,open:o,onOpenChange:p,modal:s,children:f.jsx(GZ,{...c,dir:i,open:o,onOpenChange:p,modal:s,children:n})})};H3.displayName=Ok;var U3="ContextMenuTrigger",V3=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,disabled:r=!1,...i}=e,s=$3(U3,n),o=xi(n),l=v.useRef({x:0,y:0}),c=v.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...l.current})}),u=v.useRef(0),p=v.useCallback(()=>window.clearTimeout(u.current),[]),h=g=>{l.current={x:g.clientX,y:g.clientY},s.onOpenChange(!0)};return v.useEffect(()=>p,[p]),v.useEffect(()=>void(r&&p()),[r,p]),f.jsxs(f.Fragment,{children:[f.jsx(qZ,{...o,virtualRef:c}),f.jsx(nn.span,{"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,...i,ref:t,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:r?e.onContextMenu:rt(e.onContextMenu,g=>{p(),h(g),g.preventDefault()}),onPointerDown:r?e.onPointerDown:rt(e.onPointerDown,Og(g=>{p(),u.current=window.setTimeout(()=>h(g),700)})),onPointerMove:r?e.onPointerMove:rt(e.onPointerMove,Og(p)),onPointerCancel:r?e.onPointerCancel:rt(e.onPointerCancel,Og(p)),onPointerUp:r?e.onPointerUp:rt(e.onPointerUp,Og(p))})]})});V3.displayName=U3;var cJ="ContextMenuPortal",W3=e=>{const{__scopeContextMenu:t,...n}=e,r=xi(t);return f.jsx(KZ,{...r,...n})};W3.displayName=cJ;var G3="ContextMenuContent",q3=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=$3(G3,n),s=xi(n),o=v.useRef(!1);return f.jsx(YZ,{...s,...r,ref:t,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:l=>{var c;(c=e.onCloseAutoFocus)==null||c.call(e,l),!l.defaultPrevented&&o.current&&l.preventDefault(),o.current=!1},onInteractOutside:l=>{var c;(c=e.onInteractOutside)==null||c.call(e,l),!l.defaultPrevented&&!i.modal&&(o.current=!0)},style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});q3.displayName=G3;var uJ="ContextMenuGroup",dJ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=xi(n);return f.jsx(XZ,{...i,...r,ref:t})});dJ.displayName=uJ;var fJ="ContextMenuLabel",hJ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=xi(n);return f.jsx(QZ,{...i,...r,ref:t})});hJ.displayName=fJ;var pJ="ContextMenuItem",K3=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=xi(n);return f.jsx(ZZ,{...i,...r,ref:t})});K3.displayName=pJ;var mJ="ContextMenuCheckboxItem",gJ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=xi(n);return f.jsx(JZ,{...i,...r,ref:t})});gJ.displayName=mJ;var vJ="ContextMenuRadioGroup",bJ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=xi(n);return f.jsx(eJ,{...i,...r,ref:t})});bJ.displayName=vJ;var yJ="ContextMenuRadioItem",xJ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=xi(n);return f.jsx(tJ,{...i,...r,ref:t})});xJ.displayName=yJ;var _J="ContextMenuItemIndicator",wJ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=xi(n);return f.jsx(nJ,{...i,...r,ref:t})});wJ.displayName=_J;var SJ="ContextMenuSeparator",Y3=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=xi(n);return f.jsx(rJ,{...i,...r,ref:t})});Y3.displayName=SJ;var CJ="ContextMenuArrow",kJ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=xi(n);return f.jsx(iJ,{...i,...r,ref:t})});kJ.displayName=CJ;var EJ="ContextMenuSubTrigger",TJ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=xi(n);return f.jsx(sJ,{...i,...r,ref:t})});TJ.displayName=EJ;var RJ="ContextMenuSubContent",NJ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=xi(n);return f.jsx(oJ,{...i,...r,ref:t,style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});NJ.displayName=RJ;function Og(e){return t=>t.pointerType!=="mouse"?e(t):void 0}var AJ=H3,MJ=V3,LJ=W3,X3=q3,Q3=K3,Z3=Y3;const J3=v.createContext(null);function Zc({onOpenChange:e,...t}){const[n,r]=v.useState(0),i=v.useCallback(()=>{r(s=>s+1),e==null||e(!1)},[e]);return f.jsx(J3.Provider,{value:i,children:f.jsx(AJ,{onOpenChange:e,...t},n)})}const Jc=MJ,Fl=v.forwardRef(({className:e,...t},n)=>f.jsx(LJ,{children:f.jsx(X3,{ref:n,className:me("z-50 min-w-[170px] overflow-hidden rounded-xl border border-border bg-background p-1 shadow-lg outline-hidden animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",e),...t})}));Fl.displayName=X3.displayName;const Mn=v.forwardRef(({className:e,onSelect:t,...n},r)=>{const i=v.useContext(J3);return f.jsx(Q3,{ref:r,className:me("relative flex cursor-default select-none items-center gap-2.5 rounded-lg px-3 py-2 text-xs font-medium text-foreground outline-hidden transition-colors hover:bg-muted focus:bg-muted data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),onSelect:s=>{t==null||t(s),i==null||i()},...n})});Mn.displayName=Q3.displayName;const e4=v.forwardRef(({className:e,...t},n)=>f.jsx(Z3,{ref:n,className:me("-mx-1 my-1 h-px bg-border",e),...t}));e4.displayName=Z3.displayName;var Iy="Popover",[t4]=Ta(Iy,[Bl]),Zp=Bl(),[jJ,$l]=t4(Iy),n4=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=Zp(t),c=v.useRef(null),[u,p]=v.useState(!1),[h,g]=Td({prop:r,defaultProp:i??!1,onChange:s,caller:Iy});return f.jsx(Ey,{...l,children:f.jsx(jJ,{scope:t,contentId:ba(),triggerRef:c,open:h,onOpenChange:g,onOpenToggle:v.useCallback(()=>g(b=>!b),[g]),hasCustomAnchor:u,onCustomAnchorAdd:v.useCallback(()=>p(!0),[]),onCustomAnchorRemove:v.useCallback(()=>p(!1),[]),modal:o,children:n})})};n4.displayName=Iy;var r4="PopoverAnchor",DJ=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=$l(r4,n),s=Zp(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return v.useEffect(()=>(o(),()=>l()),[o,l]),f.jsx(Gp,{...s,...r,ref:t})});DJ.displayName=r4;var i4="PopoverTrigger",s4=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=$l(i4,n),s=Zp(n),o=yn(t,i.triggerRef),l=f.jsx(nn.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":u4(i.open),...r,ref:o,onClick:rt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:f.jsx(Gp,{asChild:!0,...s,children:l})});s4.displayName=i4;var zk="PopoverPortal",[IJ,PJ]=t4(zk,{forceMount:void 0}),o4=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=$l(zk,t);return f.jsx(IJ,{scope:t,forceMount:n,children:f.jsx(js,{present:n||s.open,children:f.jsx(Yd,{asChild:!0,container:i,children:r})})})};o4.displayName=zk;var Ad="PopoverContent",a4=v.forwardRef((e,t)=>{const n=PJ(Ad,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=$l(Ad,e.__scopePopover);return f.jsx(js,{present:r||s.open,children:s.modal?f.jsx(zJ,{...i,ref:t}):f.jsx(BJ,{...i,ref:t})})});a4.displayName=Ad;var OJ=Ic("PopoverContent.RemoveScroll"),zJ=v.forwardRef((e,t)=>{const n=$l(Ad,e.__scopePopover),r=v.useRef(null),i=yn(t,r),s=v.useRef(!1);return v.useEffect(()=>{const o=r.current;if(o)return xy(o)},[]),f.jsx(Vp,{as:OJ,allowPinchZoom:!0,children:f.jsx(l4,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:rt(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:rt(e.onPointerDownOutside,o=>{const l=o.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,u=l.button===2||c;s.current=u},{checkForDefaultPrevented:!1}),onFocusOutside:rt(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),BJ=v.forwardRef((e,t)=>{const n=$l(Ad,e.__scopePopover),r=v.useRef(!1),i=v.useRef(!1);return f.jsx(l4,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var o,l;(o=e.onCloseAutoFocus)==null||o.call(e,s),s.defaultPrevented||(r.current||(l=n.triggerRef.current)==null||l.focus(),s.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:s=>{var c,u;(c=e.onInteractOutside)==null||c.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const o=s.target;((u=n.triggerRef.current)==null?void 0:u.contains(o))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&i.current&&s.preventDefault()}})}),l4=v.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:l,onPointerDownOutside:c,onFocusOutside:u,onInteractOutside:p,...h}=e,g=$l(Ad,n),b=Zp(n);return by(),f.jsx(Up,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:f.jsx(Kd,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:p,onEscapeKeyDown:l,onPointerDownOutside:c,onFocusOutside:u,onDismiss:()=>g.onOpenChange(!1),children:f.jsx(Ty,{"data-state":u4(g.open),role:"dialog",id:g.contentId,...b,...h,ref:t,style:{...h.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),c4="PopoverClose",FJ=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=$l(c4,n);return f.jsx(nn.button,{type:"button",...r,ref:t,onClick:rt(e.onClick,()=>i.onOpenChange(!1))})});FJ.displayName=c4;var $J="PopoverArrow",HJ=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Zp(n);return f.jsx(Ry,{...i,...r,ref:t})});HJ.displayName=$J;function u4(e){return e?"open":"closed"}var UJ=n4,VJ=s4,WJ=o4,d4=a4;const Bk=UJ,Fk=VJ,Py=v.forwardRef(({className:e,align:t="center",sideOffset:n=4,...r},i)=>f.jsx(WJ,{children:f.jsx(d4,{ref:i,align:t,sideOffset:n,[sp]:"",onCloseAutoFocus:s=>{var o;s.preventDefault(),window.dispatchEvent(new Event(mb)),(o=r.onCloseAutoFocus)==null||o.call(r,s)},className:me("z-50 w-72 rounded-xl border border-border bg-background p-4 shadow-lg outline-hidden animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-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})}));Py.displayName=d4.displayName;function GJ({editorLabel:e,starred:t,onCopyPath:n,onShowArchived:r,onOpenInFinder:i,onOpenInEditor:s,onToggleStar:o,onHide:l,children:c}){return f.jsxs(Zc,{children:[f.jsx(Jc,{asChild:!0,children:c}),f.jsxs(Fl,{children:[f.jsxs(Mn,{onSelect:u=>{u.stopPropagation(),o()},children:[t?f.jsx(GG,{className:"h-3.5 w-3.5"}):f.jsx(E5,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:t?"Unstar project":"Star project"})]}),f.jsxs(Mn,{onSelect:u=>{u.stopPropagation(),n()},children:[f.jsx(jl,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Copy Path"})]}),f.jsxs(Mn,{onSelect:u=>{u.stopPropagation(),r()},children:[f.jsx(GC,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Show Archived"})]}),f.jsxs(Mn,{onSelect:u=>{u.stopPropagation(),i()},children:[f.jsx(py,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Show in Finder"})]}),f.jsxs(Mn,{onSelect:u=>{u.stopPropagation(),s()},children:[f.jsx(KC,{className:"h-3.5 w-3.5"}),f.jsxs("span",{className:"text-xs font-medium",children:["Open in ",e]})]}),f.jsxs(Mn,{onSelect:u=>{u.stopPropagation(),l()},className:"text-destructive hover:bg-destructive/10 focus:bg-destructive/10",children:[f.jsx(WV,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Hide"})]})]})]})}function qJ({canFork:e,onRename:t,onShare:n,onOpenInFinder:r,onFork:i,onArchive:s,onDelete:o,onEditPermissions:l,children:c}){return f.jsxs(Zc,{children:[f.jsx(Jc,{asChild:!0,children:c}),f.jsxs(Fl,{children:[f.jsxs(Mn,{onSelect:u=>{u.preventDefault(),t()},children:[f.jsx(Hp,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Rename"})]}),f.jsxs(Mn,{onSelect:u=>{u.preventDefault(),n()},children:[f.jsx(tk,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Share"})]}),f.jsxs(Mn,{onSelect:u=>{u.preventDefault(),r()},children:[f.jsx(py,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Open in Finder"})]}),f.jsxs(Mn,{disabled:!e,onSelect:u=>{u.preventDefault(),e&&i()},children:[f.jsx(k5,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Fork"})]}),l?f.jsxs(Mn,{onSelect:u=>{u.preventDefault(),l()},children:[f.jsx(C5,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Permissions…"})]}):null,f.jsxs(Mn,{onSelect:u=>{u.preventDefault(),s()},children:[f.jsx(GC,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Archive"})]}),f.jsxs(Mn,{onSelect:u=>{u.preventDefault(),o()},className:"text-destructive dark:text-red-400 hover:bg-destructive/10 focus:bg-destructive/10 dark:hover:bg-red-500/20 dark:focus:bg-red-500/20",children:[f.jsx(qd,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Delete"})]})]})]})}function KJ({stackTitle:e,onRename:t,onEditMembers:n,onDelete:r,children:i}){const[s,o]=v.useState(!1);function l(c){return()=>{o(!1),c()}}return f.jsxs(Bk,{open:s,onOpenChange:o,children:[f.jsx(Fk,{asChild:!0,children:i}),f.jsxs(Py,{align:"end",sideOffset:4,className:"w-44 p-1",role:"menu","aria-label":`Actions for ${e}`,children:[f.jsxs("button",{type:"button",role:"menuitem",onClick:l(t),className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-xs font-medium hover:bg-muted focus-visible:bg-muted outline-hidden",children:[f.jsx(Hp,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Rename"})]}),f.jsxs("button",{type:"button",role:"menuitem",onClick:l(n),className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-xs font-medium hover:bg-muted focus-visible:bg-muted outline-hidden",children:[f.jsx(T5,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Edit members"})]}),f.jsxs("button",{type:"button",role:"menuitem",onClick:l(r),className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-xs font-medium text-destructive dark:text-red-400 hover:bg-destructive/10 focus-visible:bg-destructive/10 dark:hover:bg-red-500/20 dark:focus-visible:bg-red-500/20 outline-hidden",children:[f.jsx(qd,{className:"h-3.5 w-3.5"}),f.jsxs("span",{children:["Delete ",e]})]})]})]})}function YJ({stackTitle:e,onRename:t,onEditMembers:n,onDelete:r,children:i}){return f.jsxs(Zc,{children:[f.jsx(Jc,{asChild:!0,children:i}),f.jsxs(Fl,{children:[f.jsxs(Mn,{onSelect:s=>{s.preventDefault(),t()},children:[f.jsx(Hp,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Rename"})]}),f.jsxs(Mn,{onSelect:s=>{s.preventDefault(),n()},children:[f.jsx(T5,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Edit members"})]}),f.jsxs(Mn,{onSelect:s=>{s.preventDefault(),r()},className:"text-destructive dark:text-red-400 hover:bg-destructive/10 focus:bg-destructive/10 dark:hover:bg-red-500/20 dark:focus:bg-red-500/20",children:[f.jsx(qd,{className:"h-3.5 w-3.5"}),f.jsxs("span",{className:"text-xs font-medium",children:["Delete ",e]})]})]})]})}function XJ(e){return e.status==="running"||e.status==="starting"?"warning":e.status==="waiting_for_user"?"info":e.status==="failed"?"destructive":e.unread?"success":null}function QJ(e){switch(e){case"warning":return"bg-warning";case"info":return"bg-info";case"success":return"bg-success";case"destructive":return"bg-destructive";default:return""}}function ZJ(e){switch(e){case"warning":return"text-warning";case"info":return"text-info";case"success":return"text-success";case"destructive":return"text-destructive";default:return"text-muted-foreground"}}function JJ(e){switch(e){case"active":return{glyph:"●",tone:"text-success",title:"Claude PTY session active"};case"warming":return{glyph:"◐",tone:"text-warning",title:"Claude PTY session warming"};case"idle":return{glyph:"○",tone:"text-muted-foreground",title:"Claude PTY session idle"};case"cooling":return{glyph:"◌",tone:"text-muted-foreground",title:"Claude PTY session cooling down"};case"cold":default:return null}}function eee({chat:e,activeChatId:t,nowMs:n,shortcutHint:r=null,showShortcutHint:i=!1,onSelectChat:s,onRenameChat:o,onShareChat:l,onOpenInFinder:c,onForkChat:u,onArchiveChat:p,onDeleteChat:h,onEditPermissions:g}){const b=(e.status==="running"||e.status==="waiting_for_user")&&e.stateEnteredAt!=null,x=b&&e.stateEnteredAt!=null?`${OS(e.status)} ${PS(n-e.stateEnteredAt)}`:xl(n-(e.lastMessageAt??e._creationTime)),_=i&&r?r:x,w=i&&!!r,C=eK(e.chatId),E=t===C,k=XJ(e),R=e.canFork?"w-12":b?"w-12 md:w-20":"w-6 md:w-14",N=f.jsxs("div",{"data-chat-id":C,className:me("group flex items-center gap-2 pl-2 pr-1 py-1.5 rounded-md cursor-pointer transition-colors duration-150",E?"bg-muted":"hover:bg-muted/40"),onClick:()=>s(e.chatId),children:[f.jsx("span",{className:"relative flex h-3.5 w-3.5 shrink-0 items-center justify-center","aria-hidden":!0,children:k?f.jsx("span",{className:me("h-2 w-2 rounded-full",QJ(k))}):null}),(()=>{const A=JJ(e.sessionState);return A?f.jsx("span",{className:me("shrink-0 text-[10px] leading-none",A.tone),title:A.title,"aria-label":A.title,children:A.glyph}):null})(),e.hasPolicyOverride?f.jsx(C5,{className:"size-3 shrink-0 text-warning","aria-label":"Per-chat permission override active"}):null,f.jsx("span",{className:me("truncate flex-1 text-sm",E?"text-foreground font-medium":"text-foreground/90",e.status==="idle"&&!e.unread&&!E?"text-muted-foreground":""),children:e.title}),f.jsxs("div",{className:me("relative h-6 shrink-0",R),children:[_?w?f.jsx("span",{className:"hidden md:flex absolute inset-0 items-center justify-end pr-0.5 text-[11px] text-foreground transition-opacity duration-150 group-hover:opacity-0",children:f.jsx(s3,{className:"h-4 min-w-4 rounded-sm border-border/50 bg-transparent px-1 text-[10px]",children:r})}):f.jsx("span",{className:me("hidden md:flex absolute inset-0 items-center justify-end pr-1 text-[11px] tabular-nums transition-opacity duration-150 group-hover:opacity-0 whitespace-nowrap",b?ZJ(k):"text-muted-foreground"),children:_}):null,f.jsxs("div",{className:me("absolute inset-0 flex items-center justify-end gap-0 transition-opacity duration-150",_?"opacity-100 md:opacity-0 md:group-hover:opacity-100":"opacity-100"),children:[e.canFork?f.jsx(Ge,{variant:"ghost",size:"icon",className:"h-6 w-6 cursor-pointer rounded-sm hover:!bg-transparent !border-0",onClick:A=>{A.stopPropagation(),u(e.chatId)},title:"Fork chat",children:f.jsx(k5,{className:"size-3.5"})}):null,f.jsx(Ge,{variant:"ghost",size:"icon",className:"h-6 w-6 cursor-pointer rounded-sm hover:!bg-transparent !border-0",onClick:A=>{A.stopPropagation(),p(e.chatId)},title:"Archive chat",children:f.jsx(GC,{className:"size-3.5"})})]})]})]},e._id);return f.jsx(qJ,{canFork:e.canFork,onRename:()=>o(e.chatId),onShare:()=>l(e.chatId),onOpenInFinder:()=>c(e.localPath),onFork:()=>u(e.chatId),onArchive:()=>p(e.chatId),onDelete:()=>h(e.chatId),onEditPermissions:g?()=>g(e.chatId):void 0,children:N})}const tee=v.memo(eee);function nee(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return v.useMemo(()=>r=>{t.forEach(i=>i(r))},t)}const Oy=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Jd(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function $k(e){return"nodeType"in e}function Ii(e){var t,n;return e?Jd(e)?e:$k(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function Hk(e){const{Document:t}=Ii(e);return e instanceof t}function Jp(e){return Jd(e)?!1:e instanceof Ii(e).HTMLElement}function f4(e){return e instanceof Ii(e).SVGElement}function ef(e){return e?Jd(e)?e.document:$k(e)?Hk(e)?e:Jp(e)||f4(e)?e.ownerDocument:document:document:document}const Po=Oy?v.useLayoutEffect:v.useEffect;function Uk(e){const t=v.useRef(e);return Po(()=>{t.current=e}),v.useCallback(function(){for(var n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];return t.current==null?void 0:t.current(...r)},[])}function ree(){const e=v.useRef(null),t=v.useCallback((r,i)=>{e.current=setInterval(r,i)},[]),n=v.useCallback(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[]);return[t,n]}function dp(e,t){t===void 0&&(t=[e]);const n=v.useRef(e);return Po(()=>{n.current!==e&&(n.current=e)},t),n}function em(e,t){const n=v.useRef();return v.useMemo(()=>{const r=e(n.current);return n.current=r,r},[...t])}function kb(e){const t=Uk(e),n=v.useRef(null),r=v.useCallback(i=>{i!==n.current&&(t==null||t(i,n.current)),n.current=i},[]);return[n,r]}function FS(e){const t=v.useRef();return v.useEffect(()=>{t.current=e},[e]),t.current}let V_={};function tm(e,t){return v.useMemo(()=>{if(t)return t;const n=V_[e]==null?0:V_[e]+1;return V_[e]=n,e+"-"+n},[e,t])}function h4(e){return function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return r.reduce((s,o)=>{const l=Object.entries(o);for(const[c,u]of l){const p=s[c];p!=null&&(s[c]=p+e*u)}return s},{...t})}}const gd=h4(1),Eb=h4(-1);function iee(e){return"clientX"in e&&"clientY"in e}function Vk(e){if(!e)return!1;const{KeyboardEvent:t}=Ii(e.target);return t&&e instanceof t}function see(e){if(!e)return!1;const{TouchEvent:t}=Ii(e.target);return t&&e instanceof t}function $S(e){if(see(e)){if(e.touches&&e.touches.length){const{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}else if(e.changedTouches&&e.changedTouches.length){const{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return iee(e)?{x:e.clientX,y:e.clientY}:null}const fp=Object.freeze({Translate:{toString(e){if(!e)return;const{x:t,y:n}=e;return"translate3d("+(t?Math.round(t):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(e){if(!e)return;const{scaleX:t,scaleY:n}=e;return"scaleX("+t+") scaleY("+n+")"}},Transform:{toString(e){if(e)return[fp.Translate.toString(e),fp.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}}),MM="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function oee(e){return e.matches(MM)?e:e.querySelector(MM)}const aee={display:"none"};function lee(e){let{id:t,value:n}=e;return _n.createElement("div",{id:t,style:aee},n)}function cee(e){let{id:t,announcement:n,ariaLiveType:r="assertive"}=e;const i={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return _n.createElement("div",{id:t,style:i,role:"status","aria-live":r,"aria-atomic":!0},n)}function uee(){const[e,t]=v.useState("");return{announce:v.useCallback(r=>{r!=null&&t(r)},[]),announcement:e}}const p4=v.createContext(null);function dee(e){const t=v.useContext(p4);v.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function fee(){const[e]=v.useState(()=>new Set),t=v.useCallback(r=>(e.add(r),()=>e.delete(r)),[e]);return[v.useCallback(r=>{let{type:i,event:s}=r;e.forEach(o=>{var l;return(l=o[i])==null?void 0:l.call(o,s)})},[e]),t]}const hee={draggable:`
706
+ `)&&(A.writePathDeny=N),Object.keys(A).length===0?null:A}function E(){i(C())}function k(){i(null)}return f.jsxs(f.Fragment,{children:[f.jsx(Rs,{open:e,onOpenChange:R=>{R||s()},children:f.jsxs(Zi,{className:"max-w-2xl",children:[f.jsxs(Ns,{children:["Permissions — ",t]}),f.jsxs(Io,{className:"space-y-5",children:[f.jsxs("div",{className:"space-y-2",children:[f.jsx("div",{className:"text-sm font-medium",children:"Default action"}),f.jsxs("div",{className:"text-xs text-muted-foreground",children:["Behaviour when a tool call has no explicit allow/deny rule. ",f.jsx("strong",{children:"auto-allow"})," bypasses prompts and runs untrusted shell commands without supervision — use a worktree."]}),f.jsx(da,{value:o,onValueChange:w,options:[{value:"ask",label:"Ask"},{value:"auto-allow",label:"Auto-allow (unsafe)"},{value:"auto-deny",label:"Auto-deny"}]})]}),f.jsxs("div",{className:"space-y-2",children:[f.jsx("div",{className:"text-sm font-medium",children:"Read-path deny list"}),f.jsx("div",{className:"text-xs text-muted-foreground",children:"One glob per line. The model cannot read paths matching any entry. Defaults shown below — edit to add or remove."}),f.jsx("textarea",{value:c,onChange:R=>u(R.target.value),rows:8,className:"w-full rounded-md border border-border bg-background px-3 py-2 font-mono text-xs",spellCheck:!1})]}),f.jsxs("div",{className:"space-y-2",children:[f.jsx("div",{className:"text-sm font-medium",children:"Write-path deny list"}),f.jsx("div",{className:"text-xs text-muted-foreground",children:"One glob per line. The model cannot edit or write paths matching any entry."}),f.jsx("textarea",{value:p,onChange:R=>h(R.target.value),rows:8,className:"w-full rounded-md border border-border bg-background px-3 py-2 font-mono text-xs",spellCheck:!1})]})]}),f.jsxs(_a,{className:"justify-between",children:[f.jsx(Ge,{variant:"ghost",onClick:k,children:"Reset to defaults"}),f.jsxs("div",{className:"flex gap-2",children:[f.jsx(Ge,{variant:"ghost",onClick:s,children:"Cancel"}),f.jsx(Ge,{onClick:E,children:"Apply"})]})]})]})}),f.jsx(Rs,{open:g,onOpenChange:R=>{R||(b(!1),_(null))},children:f.jsxs(Zi,{className:"max-w-md",children:[f.jsx(Ns,{children:"Enable auto-allow for this chat?"}),f.jsxs(Io,{className:"space-y-3 text-sm",children:[f.jsx("p",{children:"Auto-allow disables tool-call prompts. The model can run shell commands, write files, and edit code without asking. Read/write deny lists still apply."}),f.jsx("p",{className:"text-warning",children:"Use a worktree for risky tasks."})]}),f.jsxs(_a,{className:"justify-end gap-2",children:[f.jsx(Ge,{variant:"ghost",onClick:()=>{b(!1),_(null)},children:"Cancel"}),f.jsx(Ge,{variant:"destructive",onClick:()=>{x&&l(x),b(!1),_(null)},children:"Enable auto-allow"})]})]})})]})}function xQ({open:e,shareUrl:t,onOpenChange:n,onOpenLink:r,onCopyLink:i}){const[s,o]=v.useState(!1);v.useEffect(()=>{e||o(!1)},[e,t]);const l=async()=>{await i()&&(o(!0),window.setTimeout(()=>{o(!1)},2e3))};return f.jsx(Rs,{open:e,onOpenChange:n,children:f.jsxs(Zi,{size:"md",children:[f.jsxs(CO,{children:[f.jsx(Ns,{children:"Shared Link"}),f.jsx(Xd,{children:"Shared links are snapshots in time and contain all attachments, tool calls and history. Be mindful of sensitive info."})]}),f.jsx(Io,{className:"space-y-3",children:f.jsxs("div",{className:"flex w-full items-center gap-2 rounded-2xl border border-border bg-muted/40 pl-4 px-3 py-2.5",children:[f.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-sm text-foreground",children:t}),f.jsx("button",{type:"button",onClick:()=>void l(),title:s?"Copied":"Copy link","aria-label":s?"Copied":"Copy link",className:"flex flex-shrink-0 items-center justify-center rounded-lg text-logo hover:text-logo/60 transition-colors hover:bg-background hover:text-foreground",children:s?f.jsx(yi,{className:"h-4 w-4 text-emerald-400"}):f.jsx(jl,{className:"h-4 w-4"})})]})}),f.jsx(_a,{children:f.jsxs(IY,{type:"button",onClick:r,children:[f.jsx(XC,{className:"mr-2 h-4 w-4"}),"Open"]})})]})})}const _Q={defaultAction:"ask",bash:{autoAllowVerbs:["ls","pwd","git status","git diff","git log"]},readPathDeny:["~/.ssh","~/.aws","~/.gcp","~/.config/gh","~/.claude","~/.kanna","~/Library/Keychains","/etc/shadow","/etc/sudoers","~/.gnupg","~/.gitconfig","**/.git/config","~/.npmrc","~/.netrc","~/.docker/config.json","**/.env","**/.env.*","**/credentials*","**/*.pem","**/*.key","**/id_rsa*","**/id_ed25519*"],writePathDeny:["/etc/**","/usr/**","/System/**","~/.ssh/**","~/.aws/**","~/.config/gh/**","~/.claude/**","~/.kanna/**","~/.gnupg/**","~/.gitconfig","**/.git/config"],toolDenyList:[{tool:"mcp__kanna__bash",pattern:"rm\\s+-rf\\s+(/|~|\\$HOME)(?:\\b|$|\\s)"},{tool:"mcp__kanna__bash",pattern:"git\\s+push\\b.*--force"}],toolAllowList:[]},Kn=v.forwardRef(({className:e,type:t,...n},r)=>f.jsx("input",{ref:r,type:t,className:me("flex w-full rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50",e),...n}));Kn.displayName="Input";const a3=v.createContext(null);function wQ({children:e}){const[t,n]=v.useState(null),[r,i]=v.useState(""),s=v.useRef(null);v.useEffect(()=>{(t==null?void 0:t.kind)==="prompt"&&(i(t.options.initialValue??""),setTimeout(()=>{var b,x;(b=s.current)==null||b.focus(),(x=s.current)==null||x.select()},0))},[t]);const o=v.useCallback(()=>{n(null),i("")},[]),l=v.useCallback(()=>{t&&(t.kind==="confirm"?t.resolve(!1):t.kind==="prompt"?t.resolve(null):t.resolve(),o())},[o,t]),c=v.useCallback(()=>{t&&(t.kind==="confirm"?t.resolve(!0):t.kind==="prompt"?t.resolve(r.trim()||null):t.resolve(),o())},[o,t,r]),u=v.useCallback(b=>new Promise(x=>{n({kind:"confirm",options:b,resolve:x})}),[]),p=v.useCallback(b=>new Promise(x=>{n({kind:"prompt",options:b,resolve:x})}),[]),h=v.useCallback(b=>new Promise(x=>{n({kind:"alert",options:b,resolve:x})}),[]),g=v.useMemo(()=>({confirm:u,prompt:p,alert:h}),[h,u,p]);return f.jsxs(a3.Provider,{value:g,children:[e,f.jsx(Rs,{open:t!==null,onOpenChange:b=>{b||!t||l()},children:f.jsx(Zi,{size:"sm",onKeyDown:b=>{b.key!=="Enter"||b.shiftKey||!t||t.kind!=="confirm"||(b.preventDefault(),c())},children:t?f.jsxs(f.Fragment,{children:[f.jsxs(Io,{className:"space-y-4",children:[f.jsx(Ns,{children:t.options.title}),t.options.description?f.jsx(Xd,{children:t.options.description}):null,t.kind==="prompt"?f.jsx(Kn,{ref:s,type:"text",value:r,onChange:b=>i(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),c())},placeholder:t.options.placeholder}):null]}),f.jsxs(_a,{children:[f.jsx(Ge,{variant:"ghost",size:"sm",onClick:l,className:t.kind==="alert"?"hidden":void 0,children:"cancelLabel"in t.options?t.options.cancelLabel??"Cancel":"Cancel"}),f.jsx(Ge,{variant:t.kind==="confirm"?t.options.confirmVariant??"default":"secondary",size:"sm",onClick:c,disabled:t.kind==="prompt"&&!r.trim(),children:t.kind==="alert"?t.options.closeLabel??"OK":"confirmLabel"in t.options?t.options.confirmLabel??"Confirm":"Confirm"})]})]}):null})})]})}function Kp(){const e=v.useContext(a3);if(!e)throw new Error("useAppDialog must be used within AppDialogProvider");return e}const wk=v.forwardRef(({className:e,...t},n)=>f.jsx("div",{ref:n,className:me("bg-card text-card-foreground",e),...t}));wk.displayName="Card";const Sk=v.forwardRef(({className:e,...t},n)=>f.jsx("div",{ref:n,className:me("flex flex-col space-y-1.5 p-2",e),...t}));Sk.displayName="CardHeader";const l3=v.forwardRef(({className:e,...t},n)=>f.jsx("h3",{ref:n,className:me("text-2xl font-semibold leading-none tracking-tight",e),...t}));l3.displayName="CardTitle";const c3=v.forwardRef(({className:e,...t},n)=>f.jsx("p",{ref:n,className:me("text-sm text-muted-foreground",e),...t}));c3.displayName="CardDescription";const Ck=v.forwardRef(({className:e,...t},n)=>f.jsx("div",{ref:n,className:me("p-6 pt-0",e),...t}));Ck.displayName="CardContent";const SQ=v.forwardRef(({className:e,...t},n)=>f.jsx("div",{ref:n,className:me("flex items-center p-6 pt-0",e),...t}));SQ.displayName="CardFooter";const CQ="modulepreload",kQ=function(e){return"/"+e},CM={},K=function(t,n,r){let i=Promise.resolve();if(n&&n.length>0){let o=function(u){return Promise.all(u.map(p=>Promise.resolve(p).then(h=>({status:"fulfilled",value:h}),h=>({status:"rejected",reason:h}))))};document.getElementsByTagName("link");const l=document.querySelector("meta[property=csp-nonce]"),c=(l==null?void 0:l.nonce)||(l==null?void 0:l.getAttribute("nonce"));i=o(n.map(u=>{if(u=kQ(u),u in CM)return;CM[u]=!0;const p=u.endsWith(".css"),h=p?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${u}"]${h}`))return;const g=document.createElement("link");if(g.rel=p?"stylesheet":CQ,p||(g.as="script"),g.crossOrigin="",g.href=u,c&&g.setAttribute("nonce",c),document.head.appendChild(g),p)return new Promise((b,x)=>{g.addEventListener("load",b),g.addEventListener("error",()=>x(new Error(`Unable to preload CSS for ${u}`)))})}))}function s(o){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=o,window.dispatchEvent(l),!l.defaultPrevented)throw o}return i.then(o=>{for(const l of o||[])l.status==="rejected"&&s(l.reason);return t().catch(s)})},EQ=v.lazy(()=>K(()=>import("./index-zcdDKOCt.js"),[]).then(e=>({default:e.Toaster})));function TQ(){return f.jsx(v.Suspense,{fallback:null,children:f.jsx(EQ,{position:"bottom-right",theme:"system",closeButton:!0,duration:6e3})})}const RQ="0.56.4",NQ={version:RQ},or="Kanna",kM="kanna",AQ=".kanna",MQ=".kanna-dev",LQ="KANNA_RUNTIME_PROFILE",kk=`kanna/${NQ.version}`,jQ="[kanna]",DQ=`~/${or}`;function Ly(){var t;return(t=globalThis.process)==null?void 0:t.env}function IQ(e=Ly()){var t;return((t=e==null?void 0:e[LQ])==null?void 0:t.trim().toLowerCase())==="dev"?"dev":"prod"}function PQ(e=Ly()){return IQ(e)==="dev"?MQ:AQ}function OQ(e=Ly()){return`~/${PQ(e)}`}function zQ(e=Ly()){return`${OQ(e)}/keybindings.json`}function Pg(e){return e?`${kM} ${e}`:kM}const EM=e=>{let t;const n=new Set,r=(u,p)=>{const h=typeof u=="function"?u(t):u;if(!Object.is(h,t)){const g=t;t=p??(typeof h!="object"||h===null)?h:Object.assign({},t,h),n.forEach(b=>b(t,g))}},i=()=>t,l={setState:r,getState:i,getInitialState:()=>c,subscribe:u=>(n.add(u),()=>n.delete(u))},c=t=e(r,i,l);return l},BQ=(e=>e?EM(e):EM),FQ=e=>e;function $Q(e,t=FQ){const n=_n.useSyncExternalStore(e.subscribe,_n.useCallback(()=>t(e.getState()),[e,t]),_n.useCallback(()=>t(e.getInitialState()),[e,t]));return _n.useDebugValue(n),n}const HQ=e=>{const t=BQ(e),n=r=>$Q(t,r);return Object.assign(n,t),n},oo=(e=>HQ),u3="always",d3="funk",UQ=[{value:"blow",label:"Blow"},{value:"bottle",label:"Bottle"},{value:"frog",label:"Frog"},{value:"funk",label:"Funk"},{value:"glass",label:"Glass"},{value:"ping",label:"Ping"},{value:"pop",label:"Pop"},{value:"purr",label:"Purr"},{value:"tink",label:"Tink"}];function VQ(e){switch(e){case"never":case"unfocused":case"always":return e;default:return u3}}function WQ(e){switch(e){case"blow":case"bottle":case"frog":case"funk":case"glass":case"ping":case"pop":case"purr":case"tink":return e;default:return d3}}const Ec=oo()(e=>({chatSoundPreference:u3,chatSoundId:d3,setChatSoundPreference:t=>e({chatSoundPreference:VQ(t)}),setChatSoundId:t=>e({chatSoundId:WQ(t)})})),GQ={blow:"/chat-sounds/Blow.mp3",bottle:"/chat-sounds/Bottle.mp3",frog:"/chat-sounds/Frog.mp3",funk:"/chat-sounds/Funk.mp3",glass:"/chat-sounds/Glass.mp3",ping:"/chat-sounds/Ping.mp3",pop:"/chat-sounds/Pop.mp3",purr:"/chat-sounds/Purr.mp3",tink:"/chat-sounds/Tink.mp3"};function qQ(e=document){return e.visibilityState!=="visible"||!e.hasFocus()}function KQ(e){const t=new Audio(GQ[e]);return t.preload="auto",t.play()}async function DS(e,t){if(t<=0)return;const n=Array.from({length:t},(r,i)=>new Promise(s=>{window.setTimeout(()=>{KQ(e).catch(()=>{}).finally(()=>s())},i*90)}));await Promise.all(n)}function YQ(e,t=document){return e==="never"?!1:e==="always"?!0:qQ(t)}function XQ(e){return e.projectGroups.reduce((t,n)=>t+n.chats.reduce((r,i)=>r+(i.unread?1:0)+(i.status==="waiting_for_user"?1:0),0),0)}function TM(e){let t=0;const n=new Set;for(const r of e.projectGroups)for(const i of r.chats)i.unread&&(t+=1),i.status==="waiting_for_user"&&n.add(i.chatId);return{unreadCount:t,waitingChatIds:n}}function QQ(e,t){if(!e)return 0;const n=TM(e),r=TM(t),i=Math.max(0,r.unreadCount-n.unreadCount);let s=0;for(const o of r.waitingChatIds)n.waitingChatIds.has(o)||(s+=1);return i+s}function IS(e){return e.split(/[\s_-]+/).filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" ")}const ZQ=[/^(?:\/usr\/bin\/env\s+)?(?:\/bin\/)?(?:bash|zsh|sh)\s+(?:-[a-zA-Z]*c|-c)\s+(['"])([\s\S]*)\1$/,/^(?:\/usr\/bin\/env\s+)?(?:\/bin\/)?(?:bash|zsh|sh)\s+(?:-[a-zA-Z]*c|-c)\s+(.+)$/,/^(?:\/usr\/bin\/env\s+)?(?:cmd(?:\.exe)?)\s+\/c\s+(['"])([\s\S]*)\1$/i,/^(?:\/usr\/bin\/env\s+)?(?:cmd(?:\.exe)?)\s+\/c\s+(.+)$/i,/^(?:\/usr\/bin\/env\s+)?(?:powershell(?:\.exe)?|pwsh)\s+(?:-NoProfile\s+)?-Command\s+(['"])([\s\S]*)\1$/i,/^(?:\/usr\/bin\/env\s+)?(?:powershell(?:\.exe)?|pwsh)\s+(?:-NoProfile\s+)?-Command\s+(.+)$/i];function JQ(e){const t=e.trim();for(const n of ZQ){const r=t.match(n);if(!r)continue;const i=(r[2]??r[1]??"").trim();if(i)return i}return t}function Ek(e){return e.split("/").pop()||e}const eZ=1440*6e4;function tZ(e,t){const n=Math.max(0,t-e),r=Math.floor(n/1e3),i=Math.floor(r/3600),s=Math.floor(r%3600/60),o=r%60;return i>0?`${i}h ${s}m`:s>0?`${s}m ${o}s`:`${o}s`}function nZ(e){const t=new Date(e),n=t.getHours().toString().padStart(2,"0"),r=t.getMinutes().toString().padStart(2,"0");return`${n}:${r}`}function rZ(e,t){if(e===void 0)return null;const n=Math.max(0,t-e),r=6e4,i=60*r,s=eZ,o=7*s;return n<r?"now":n<i?`${Math.floor(n/r)}m`:n<s?`${Math.floor(n/i)}h`:n<o?`${Math.floor(n/s)}d`:`${Math.floor(n/o)}w`}function iZ(e){return e.lastMessageAt??e._creationTime}const Tk=1e3,Fv=60*Tk,ld=60*Fv,H_=24*ld;function xl(e){const t=Math.max(0,e);if(t<Fv)return`${Math.floor(t/Tk)}s`;if(t<ld)return`${Math.floor(t/Fv)}m`;if(t<H_){const i=Math.floor(t/ld),s=Math.floor(t%ld/Fv);return s===0?`${i}h`:`${i}h ${s}m`}const n=Math.floor(t/H_),r=Math.floor(t%H_/ld);return r===0?`${n}d`:`${n}d ${r}h`}function PS(e){const t=Math.max(0,e);if(t>=ld)return xl(t);const n=Math.floor(t/Tk),r=Math.floor(n/60),i=n%60;return`${r}:${i.toString().padStart(2,"0")}`}function OS(e){switch(e){case"idle":return"Idle";case"starting":return"Starting";case"running":return"Running";case"waiting_for_user":return"Waiting";case"failed":return"Failed"}}function RM(e){switch(e){case"running":return"active";case"waiting_for_user":return"attention";case"failed":return"destructive";case"idle":case"starting":default:return"muted"}}function NM(e){switch(e){case"active":return"text-emerald-500 dark:text-emerald-400";case"attention":return"text-amber-500 dark:text-amber-400";case"destructive":return"text-destructive";case"muted":default:return"text-muted-foreground"}}function Rk(e){const t=e+"CollectionProvider",[n,r]=Ta(t),[i,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),o=_=>{const{scope:w,children:C}=_,E=_n.useRef(null),k=_n.useRef(new Map).current;return f.jsx(i,{scope:w,itemMap:k,collectionRef:E,children:C})};o.displayName=t;const l=e+"CollectionSlot",c=Ic(l),u=_n.forwardRef((_,w)=>{const{scope:C,children:E}=_,k=s(l,C),R=yn(w,k.collectionRef);return f.jsx(c,{ref:R,children:E})});u.displayName=l;const p=e+"CollectionItemSlot",h="data-radix-collection-item",g=Ic(p),b=_n.forwardRef((_,w)=>{const{scope:C,children:E,...k}=_,R=_n.useRef(null),N=yn(w,R),A=s(p,C);return _n.useEffect(()=>(A.itemMap.set(R,{ref:R,...k}),()=>void A.itemMap.delete(R))),f.jsx(g,{[h]:"",ref:N,children:E})});b.displayName=p;function x(_){const w=s(e+"CollectionConsumer",_);return _n.useCallback(()=>{const E=w.collectionRef.current;if(!E)return[];const k=Array.from(E.querySelectorAll(`[${h}]`));return Array.from(w.itemMap.values()).sort((A,M)=>k.indexOf(A.ref.current)-k.indexOf(M.ref.current))},[w.collectionRef,w.itemMap])}return[{Provider:o,Slot:u,ItemSlot:b},x,r]}var sZ=v.createContext(void 0);function Nk(e){const t=v.useContext(sZ);return e||t||"ltr"}var U_="rovingFocusGroup.onEntryFocus",oZ={bubbles:!1,cancelable:!0},Yp="RovingFocusGroup",[zS,f3,aZ]=Rk(Yp),[lZ,h3]=Ta(Yp,[aZ]),[cZ,uZ]=lZ(Yp),p3=v.forwardRef((e,t)=>f.jsx(zS.Provider,{scope:e.__scopeRovingFocusGroup,children:f.jsx(zS.Slot,{scope:e.__scopeRovingFocusGroup,children:f.jsx(dZ,{...e,ref:t})})}));p3.displayName=Yp;var dZ=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:s,currentTabStopId:o,defaultCurrentTabStopId:l,onCurrentTabStopIdChange:c,onEntryFocus:u,preventScrollOnEntryFocus:p=!1,...h}=e,g=v.useRef(null),b=yn(t,g),x=Nk(s),[_,w]=Td({prop:o,defaultProp:l??null,onChange:c,caller:Yp}),[C,E]=v.useState(!1),k=Js(u),R=f3(n),N=v.useRef(!1),[A,M]=v.useState(0);return v.useEffect(()=>{const D=g.current;if(D)return D.addEventListener(U_,k),()=>D.removeEventListener(U_,k)},[k]),f.jsx(cZ,{scope:n,orientation:r,dir:x,loop:i,currentTabStopId:_,onItemFocus:v.useCallback(D=>w(D),[w]),onItemShiftTab:v.useCallback(()=>E(!0),[]),onFocusableItemAdd:v.useCallback(()=>M(D=>D+1),[]),onFocusableItemRemove:v.useCallback(()=>M(D=>D-1),[]),children:f.jsx(nn.div,{tabIndex:C||A===0?-1:0,"data-orientation":r,...h,ref:b,style:{outline:"none",...e.style},onMouseDown:rt(e.onMouseDown,()=>{N.current=!0}),onFocus:rt(e.onFocus,D=>{const U=!N.current;if(D.target===D.currentTarget&&U&&!C){const j=new CustomEvent(U_,oZ);if(D.currentTarget.dispatchEvent(j),!j.defaultPrevented){const P=R().filter(B=>B.focusable),z=P.find(B=>B.active),O=P.find(B=>B.id===_),V=[z,O,...P].filter(Boolean).map(B=>B.ref.current);v3(V,p)}}N.current=!1}),onBlur:rt(e.onBlur,()=>E(!1))})})}),m3="RovingFocusGroupItem",g3=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,c=ba(),u=s||c,p=uZ(m3,n),h=p.currentTabStopId===u,g=f3(n),{onFocusableItemAdd:b,onFocusableItemRemove:x,currentTabStopId:_}=p;return v.useEffect(()=>{if(r)return b(),()=>x()},[r,b,x]),f.jsx(zS.ItemSlot,{scope:n,id:u,focusable:r,active:i,children:f.jsx(nn.span,{tabIndex:h?0:-1,"data-orientation":p.orientation,...l,ref:t,onMouseDown:rt(e.onMouseDown,w=>{r?p.onItemFocus(u):w.preventDefault()}),onFocus:rt(e.onFocus,()=>p.onItemFocus(u)),onKeyDown:rt(e.onKeyDown,w=>{if(w.key==="Tab"&&w.shiftKey){p.onItemShiftTab();return}if(w.target!==w.currentTarget)return;const C=pZ(w,p.orientation,p.dir);if(C!==void 0){if(w.metaKey||w.ctrlKey||w.altKey||w.shiftKey)return;w.preventDefault();let k=g().filter(R=>R.focusable).map(R=>R.ref.current);if(C==="last")k.reverse();else if(C==="prev"||C==="next"){C==="prev"&&k.reverse();const R=k.indexOf(w.currentTarget);k=p.loop?mZ(k,R+1):k.slice(R+1)}setTimeout(()=>v3(k))}}),children:typeof o=="function"?o({isCurrentTabStop:h,hasTabStop:_!=null}):o})})});g3.displayName=m3;var fZ={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function hZ(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function pZ(e,t,n){const r=hZ(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return fZ[r]}function v3(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function mZ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var gZ=p3,vZ=g3,BS=["Enter"," "],bZ=["ArrowDown","PageUp","Home"],b3=["ArrowUp","PageDown","End"],yZ=[...bZ,...b3],xZ={ltr:[...BS,"ArrowRight"],rtl:[...BS,"ArrowLeft"]},_Z={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Xp="Menu",[cp,wZ,SZ]=Rk(Xp),[Xc,y3]=Ta(Xp,[SZ,Bl,h3]),jy=Bl(),x3=h3(),[CZ,Qc]=Xc(Xp),[kZ,Qp]=Xc(Xp),_3=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=jy(t),[c,u]=v.useState(null),p=v.useRef(!1),h=Js(s),g=Nk(i);return v.useEffect(()=>{const b=()=>{p.current=!0,document.addEventListener("pointerdown",x,{capture:!0,once:!0}),document.addEventListener("pointermove",x,{capture:!0,once:!0})},x=()=>p.current=!1;return document.addEventListener("keydown",b,{capture:!0}),()=>{document.removeEventListener("keydown",b,{capture:!0}),document.removeEventListener("pointerdown",x,{capture:!0}),document.removeEventListener("pointermove",x,{capture:!0})}},[]),f.jsx(Ey,{...l,children:f.jsx(CZ,{scope:t,open:n,onOpenChange:h,content:c,onContentChange:u,children:f.jsx(kZ,{scope:t,onClose:v.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:p,dir:g,modal:o,children:r})})})};_3.displayName=Xp;var EZ="MenuAnchor",Ak=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=jy(n);return f.jsx(Gp,{...i,...r,ref:t})});Ak.displayName=EZ;var Mk="MenuPortal",[TZ,w3]=Xc(Mk,{forceMount:void 0}),S3=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=Qc(Mk,t);return f.jsx(TZ,{scope:t,forceMount:n,children:f.jsx(js,{present:n||s.open,children:f.jsx(Yd,{asChild:!0,container:i,children:r})})})};S3.displayName=Mk;var Es="MenuContent",[RZ,Lk]=Xc(Es),C3=v.forwardRef((e,t)=>{const n=w3(Es,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=Qc(Es,e.__scopeMenu),o=Qp(Es,e.__scopeMenu);return f.jsx(cp.Provider,{scope:e.__scopeMenu,children:f.jsx(js,{present:r||s.open,children:f.jsx(cp.Slot,{scope:e.__scopeMenu,children:o.modal?f.jsx(NZ,{...i,ref:t}):f.jsx(AZ,{...i,ref:t})})})})}),NZ=v.forwardRef((e,t)=>{const n=Qc(Es,e.__scopeMenu),r=v.useRef(null),i=yn(t,r);return v.useEffect(()=>{const s=r.current;if(s)return xy(s)},[]),f.jsx(jk,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:rt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),AZ=v.forwardRef((e,t)=>{const n=Qc(Es,e.__scopeMenu);return f.jsx(jk,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),MZ=Ic("MenuContent.ScrollLock"),jk=v.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:l,onEntryFocus:c,onEscapeKeyDown:u,onPointerDownOutside:p,onFocusOutside:h,onInteractOutside:g,onDismiss:b,disableOutsideScroll:x,..._}=e,w=Qc(Es,n),C=Qp(Es,n),E=jy(n),k=x3(n),R=wZ(n),[N,A]=v.useState(null),M=v.useRef(null),D=yn(t,M,w.onContentChange),U=v.useRef(0),j=v.useRef(""),P=v.useRef(0),z=v.useRef(null),O=v.useRef("right"),$=v.useRef(0),V=x?Vp:v.Fragment,B=x?{as:MZ,allowPinchZoom:!0}:void 0,F=X=>{var te,ie;const I=j.current+X,G=R().filter(de=>!de.disabled),ee=document.activeElement,H=(te=G.find(de=>de.ref.current===ee))==null?void 0:te.textValue,ue=G.map(de=>de.textValue),ae=UZ(ue,I,H),J=(ie=G.find(de=>de.textValue===ae))==null?void 0:ie.ref.current;(function de(he){j.current=he,window.clearTimeout(U.current),he!==""&&(U.current=window.setTimeout(()=>de(""),1e3))})(I),J&&setTimeout(()=>J.focus())};v.useEffect(()=>()=>window.clearTimeout(U.current),[]),by();const W=v.useCallback(X=>{var G,ee;return O.current===((G=z.current)==null?void 0:G.side)&&WZ(X,(ee=z.current)==null?void 0:ee.area)},[]);return f.jsx(RZ,{scope:n,searchRef:j,onItemEnter:v.useCallback(X=>{W(X)&&X.preventDefault()},[W]),onItemLeave:v.useCallback(X=>{var I;W(X)||((I=M.current)==null||I.focus(),A(null))},[W]),onTriggerLeave:v.useCallback(X=>{W(X)&&X.preventDefault()},[W]),pointerGraceTimerRef:P,onPointerGraceIntentChange:v.useCallback(X=>{z.current=X},[]),children:f.jsx(V,{...B,children:f.jsx(Up,{asChild:!0,trapped:i,onMountAutoFocus:rt(s,X=>{var I;X.preventDefault(),(I=M.current)==null||I.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:f.jsx(Kd,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:u,onPointerDownOutside:p,onFocusOutside:h,onInteractOutside:g,onDismiss:b,children:f.jsx(gZ,{asChild:!0,...k,dir:C.dir,orientation:"vertical",loop:r,currentTabStopId:N,onCurrentTabStopIdChange:A,onEntryFocus:rt(c,X=>{C.isUsingKeyboardRef.current||X.preventDefault()}),preventScrollOnEntryFocus:!0,children:f.jsx(Ty,{role:"menu","aria-orientation":"vertical","data-state":F3(w.open),"data-radix-menu-content":"",dir:C.dir,...E,..._,ref:D,style:{outline:"none",..._.style},onKeyDown:rt(_.onKeyDown,X=>{const G=X.target.closest("[data-radix-menu-content]")===X.currentTarget,ee=X.ctrlKey||X.altKey||X.metaKey,H=X.key.length===1;G&&(X.key==="Tab"&&X.preventDefault(),!ee&&H&&F(X.key));const ue=M.current;if(X.target!==ue||!yZ.includes(X.key))return;X.preventDefault();const J=R().filter(te=>!te.disabled).map(te=>te.ref.current);b3.includes(X.key)&&J.reverse(),$Z(J)}),onBlur:rt(e.onBlur,X=>{X.currentTarget.contains(X.target)||(window.clearTimeout(U.current),j.current="")}),onPointerMove:rt(e.onPointerMove,up(X=>{const I=X.target,G=$.current!==X.clientX;if(X.currentTarget.contains(I)&&G){const ee=X.clientX>$.current?"right":"left";O.current=ee,$.current=X.clientX}}))})})})})})})});C3.displayName=Es;var LZ="MenuGroup",Dk=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return f.jsx(nn.div,{role:"group",...r,ref:t})});Dk.displayName=LZ;var jZ="MenuLabel",k3=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return f.jsx(nn.div,{...r,ref:t})});k3.displayName=jZ;var Sb="MenuItem",AM="menu.itemSelect",Dy=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=v.useRef(null),o=Qp(Sb,e.__scopeMenu),l=Lk(Sb,e.__scopeMenu),c=yn(t,s),u=v.useRef(!1),p=()=>{const h=s.current;if(!n&&h){const g=new CustomEvent(AM,{bubbles:!0,cancelable:!0});h.addEventListener(AM,b=>r==null?void 0:r(b),{once:!0}),W5(h,g),g.defaultPrevented?u.current=!1:o.onClose()}};return f.jsx(E3,{...i,ref:c,disabled:n,onClick:rt(e.onClick,p),onPointerDown:h=>{var g;(g=e.onPointerDown)==null||g.call(e,h),u.current=!0},onPointerUp:rt(e.onPointerUp,h=>{var g;u.current||(g=h.currentTarget)==null||g.click()}),onKeyDown:rt(e.onKeyDown,h=>{const g=l.searchRef.current!=="";n||g&&h.key===" "||BS.includes(h.key)&&(h.currentTarget.click(),h.preventDefault())})})});Dy.displayName=Sb;var E3=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=Lk(Sb,n),l=x3(n),c=v.useRef(null),u=yn(t,c),[p,h]=v.useState(!1),[g,b]=v.useState("");return v.useEffect(()=>{const x=c.current;x&&b((x.textContent??"").trim())},[s.children]),f.jsx(cp.ItemSlot,{scope:n,disabled:r,textValue:i??g,children:f.jsx(vZ,{asChild:!0,...l,focusable:!r,children:f.jsx(nn.div,{role:"menuitem","data-highlighted":p?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:u,onPointerMove:rt(e.onPointerMove,up(x=>{r?o.onItemLeave(x):(o.onItemEnter(x),x.defaultPrevented||x.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:rt(e.onPointerLeave,up(x=>o.onItemLeave(x))),onFocus:rt(e.onFocus,()=>h(!0)),onBlur:rt(e.onBlur,()=>h(!1))})})})}),DZ="MenuCheckboxItem",T3=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return f.jsx(L3,{scope:e.__scopeMenu,checked:n,children:f.jsx(Dy,{role:"menuitemcheckbox","aria-checked":Cb(n)?"mixed":n,...i,ref:t,"data-state":Pk(n),onSelect:rt(i.onSelect,()=>r==null?void 0:r(Cb(n)?!0:!n),{checkForDefaultPrevented:!1})})})});T3.displayName=DZ;var R3="MenuRadioGroup",[IZ,PZ]=Xc(R3,{value:void 0,onValueChange:()=>{}}),N3=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=Js(r);return f.jsx(IZ,{scope:e.__scopeMenu,value:n,onValueChange:s,children:f.jsx(Dk,{...i,ref:t})})});N3.displayName=R3;var A3="MenuRadioItem",M3=v.forwardRef((e,t)=>{const{value:n,...r}=e,i=PZ(A3,e.__scopeMenu),s=n===i.value;return f.jsx(L3,{scope:e.__scopeMenu,checked:s,children:f.jsx(Dy,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Pk(s),onSelect:rt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});M3.displayName=A3;var Ik="MenuItemIndicator",[L3,OZ]=Xc(Ik,{checked:!1}),j3=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=OZ(Ik,n);return f.jsx(js,{present:r||Cb(s.checked)||s.checked===!0,children:f.jsx(nn.span,{...i,ref:t,"data-state":Pk(s.checked)})})});j3.displayName=Ik;var zZ="MenuSeparator",D3=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return f.jsx(nn.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});D3.displayName=zZ;var BZ="MenuArrow",I3=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=jy(n);return f.jsx(Ry,{...i,...r,ref:t})});I3.displayName=BZ;var FZ="MenuSub",[J2e,P3]=Xc(FZ),Nh="MenuSubTrigger",O3=v.forwardRef((e,t)=>{const n=Qc(Nh,e.__scopeMenu),r=Qp(Nh,e.__scopeMenu),i=P3(Nh,e.__scopeMenu),s=Lk(Nh,e.__scopeMenu),o=v.useRef(null),{pointerGraceTimerRef:l,onPointerGraceIntentChange:c}=s,u={__scopeMenu:e.__scopeMenu},p=v.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return v.useEffect(()=>p,[p]),v.useEffect(()=>{const h=l.current;return()=>{window.clearTimeout(h),c(null)}},[l,c]),f.jsx(Ak,{asChild:!0,...u,children:f.jsx(E3,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":F3(n.open),...e,ref:ik(t,i.onTriggerChange),onClick:h=>{var g;(g=e.onClick)==null||g.call(e,h),!(e.disabled||h.defaultPrevented)&&(h.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:rt(e.onPointerMove,up(h=>{s.onItemEnter(h),!h.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),p()},100))})),onPointerLeave:rt(e.onPointerLeave,up(h=>{var b,x;p();const g=(b=n.content)==null?void 0:b.getBoundingClientRect();if(g){const _=(x=n.content)==null?void 0:x.dataset.side,w=_==="right",C=w?-5:5,E=g[w?"left":"right"],k=g[w?"right":"left"];s.onPointerGraceIntentChange({area:[{x:h.clientX+C,y:h.clientY},{x:E,y:g.top},{x:k,y:g.top},{x:k,y:g.bottom},{x:E,y:g.bottom}],side:_}),window.clearTimeout(l.current),l.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(h),h.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:rt(e.onKeyDown,h=>{var b;const g=s.searchRef.current!=="";e.disabled||g&&h.key===" "||xZ[r.dir].includes(h.key)&&(n.onOpenChange(!0),(b=n.content)==null||b.focus(),h.preventDefault())})})})});O3.displayName=Nh;var z3="MenuSubContent",B3=v.forwardRef((e,t)=>{const n=w3(Es,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=Qc(Es,e.__scopeMenu),o=Qp(Es,e.__scopeMenu),l=P3(z3,e.__scopeMenu),c=v.useRef(null),u=yn(t,c);return f.jsx(cp.Provider,{scope:e.__scopeMenu,children:f.jsx(js,{present:r||s.open,children:f.jsx(cp.Slot,{scope:e.__scopeMenu,children:f.jsx(jk,{id:l.contentId,"aria-labelledby":l.triggerId,...i,ref:u,align:"start",side:o.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:p=>{var h;o.isUsingKeyboardRef.current&&((h=c.current)==null||h.focus()),p.preventDefault()},onCloseAutoFocus:p=>p.preventDefault(),onFocusOutside:rt(e.onFocusOutside,p=>{p.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:rt(e.onEscapeKeyDown,p=>{o.onClose(),p.preventDefault()}),onKeyDown:rt(e.onKeyDown,p=>{var b;const h=p.currentTarget.contains(p.target),g=_Z[o.dir].includes(p.key);h&&g&&(s.onOpenChange(!1),(b=l.trigger)==null||b.focus(),p.preventDefault())})})})})})});B3.displayName=z3;function F3(e){return e?"open":"closed"}function Cb(e){return e==="indeterminate"}function Pk(e){return Cb(e)?"indeterminate":e?"checked":"unchecked"}function $Z(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function HZ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function UZ(e,t,n){const i=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let o=HZ(e,Math.max(s,0));i.length===1&&(o=o.filter(u=>u!==n));const c=o.find(u=>u.toLowerCase().startsWith(i.toLowerCase()));return c!==n?c:void 0}function VZ(e,t){const{x:n,y:r}=e;let i=!1;for(let s=0,o=t.length-1;s<t.length;o=s++){const l=t[s],c=t[o],u=l.x,p=l.y,h=c.x,g=c.y;p>r!=g>r&&n<(h-u)*(r-p)/(g-p)+u&&(i=!i)}return i}function WZ(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return VZ(n,t)}function up(e){return t=>t.pointerType==="mouse"?e(t):void 0}var GZ=_3,qZ=Ak,KZ=S3,YZ=C3,XZ=Dk,QZ=k3,ZZ=Dy,JZ=T3,eJ=N3,tJ=M3,nJ=j3,rJ=D3,iJ=I3,sJ=O3,oJ=B3,Ok="ContextMenu",[aJ]=Ta(Ok,[y3]),xi=y3(),[lJ,$3]=aJ(Ok),H3=e=>{const{__scopeContextMenu:t,children:n,onOpenChange:r,dir:i,modal:s=!0}=e,[o,l]=v.useState(!1),c=xi(t),u=Js(r),p=v.useCallback(h=>{l(h),u(h)},[u]);return f.jsx(lJ,{scope:t,open:o,onOpenChange:p,modal:s,children:f.jsx(GZ,{...c,dir:i,open:o,onOpenChange:p,modal:s,children:n})})};H3.displayName=Ok;var U3="ContextMenuTrigger",V3=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,disabled:r=!1,...i}=e,s=$3(U3,n),o=xi(n),l=v.useRef({x:0,y:0}),c=v.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...l.current})}),u=v.useRef(0),p=v.useCallback(()=>window.clearTimeout(u.current),[]),h=g=>{l.current={x:g.clientX,y:g.clientY},s.onOpenChange(!0)};return v.useEffect(()=>p,[p]),v.useEffect(()=>void(r&&p()),[r,p]),f.jsxs(f.Fragment,{children:[f.jsx(qZ,{...o,virtualRef:c}),f.jsx(nn.span,{"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,...i,ref:t,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:r?e.onContextMenu:rt(e.onContextMenu,g=>{p(),h(g),g.preventDefault()}),onPointerDown:r?e.onPointerDown:rt(e.onPointerDown,Og(g=>{p(),u.current=window.setTimeout(()=>h(g),700)})),onPointerMove:r?e.onPointerMove:rt(e.onPointerMove,Og(p)),onPointerCancel:r?e.onPointerCancel:rt(e.onPointerCancel,Og(p)),onPointerUp:r?e.onPointerUp:rt(e.onPointerUp,Og(p))})]})});V3.displayName=U3;var cJ="ContextMenuPortal",W3=e=>{const{__scopeContextMenu:t,...n}=e,r=xi(t);return f.jsx(KZ,{...r,...n})};W3.displayName=cJ;var G3="ContextMenuContent",q3=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=$3(G3,n),s=xi(n),o=v.useRef(!1);return f.jsx(YZ,{...s,...r,ref:t,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:l=>{var c;(c=e.onCloseAutoFocus)==null||c.call(e,l),!l.defaultPrevented&&o.current&&l.preventDefault(),o.current=!1},onInteractOutside:l=>{var c;(c=e.onInteractOutside)==null||c.call(e,l),!l.defaultPrevented&&!i.modal&&(o.current=!0)},style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});q3.displayName=G3;var uJ="ContextMenuGroup",dJ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=xi(n);return f.jsx(XZ,{...i,...r,ref:t})});dJ.displayName=uJ;var fJ="ContextMenuLabel",hJ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=xi(n);return f.jsx(QZ,{...i,...r,ref:t})});hJ.displayName=fJ;var pJ="ContextMenuItem",K3=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=xi(n);return f.jsx(ZZ,{...i,...r,ref:t})});K3.displayName=pJ;var mJ="ContextMenuCheckboxItem",gJ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=xi(n);return f.jsx(JZ,{...i,...r,ref:t})});gJ.displayName=mJ;var vJ="ContextMenuRadioGroup",bJ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=xi(n);return f.jsx(eJ,{...i,...r,ref:t})});bJ.displayName=vJ;var yJ="ContextMenuRadioItem",xJ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=xi(n);return f.jsx(tJ,{...i,...r,ref:t})});xJ.displayName=yJ;var _J="ContextMenuItemIndicator",wJ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=xi(n);return f.jsx(nJ,{...i,...r,ref:t})});wJ.displayName=_J;var SJ="ContextMenuSeparator",Y3=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=xi(n);return f.jsx(rJ,{...i,...r,ref:t})});Y3.displayName=SJ;var CJ="ContextMenuArrow",kJ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=xi(n);return f.jsx(iJ,{...i,...r,ref:t})});kJ.displayName=CJ;var EJ="ContextMenuSubTrigger",TJ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=xi(n);return f.jsx(sJ,{...i,...r,ref:t})});TJ.displayName=EJ;var RJ="ContextMenuSubContent",NJ=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=xi(n);return f.jsx(oJ,{...i,...r,ref:t,style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});NJ.displayName=RJ;function Og(e){return t=>t.pointerType!=="mouse"?e(t):void 0}var AJ=H3,MJ=V3,LJ=W3,X3=q3,Q3=K3,Z3=Y3;const J3=v.createContext(null);function Zc({onOpenChange:e,...t}){const[n,r]=v.useState(0),i=v.useCallback(()=>{r(s=>s+1),e==null||e(!1)},[e]);return f.jsx(J3.Provider,{value:i,children:f.jsx(AJ,{onOpenChange:e,...t},n)})}const Jc=MJ,Fl=v.forwardRef(({className:e,...t},n)=>f.jsx(LJ,{children:f.jsx(X3,{ref:n,className:me("z-50 min-w-[170px] overflow-hidden rounded-xl border border-border bg-background p-1 shadow-lg outline-hidden animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",e),...t})}));Fl.displayName=X3.displayName;const Mn=v.forwardRef(({className:e,onSelect:t,...n},r)=>{const i=v.useContext(J3);return f.jsx(Q3,{ref:r,className:me("relative flex cursor-default select-none items-center gap-2.5 rounded-lg px-3 py-2 text-xs font-medium text-foreground outline-hidden transition-colors hover:bg-muted focus:bg-muted data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),onSelect:s=>{t==null||t(s),i==null||i()},...n})});Mn.displayName=Q3.displayName;const e4=v.forwardRef(({className:e,...t},n)=>f.jsx(Z3,{ref:n,className:me("-mx-1 my-1 h-px bg-border",e),...t}));e4.displayName=Z3.displayName;var Iy="Popover",[t4]=Ta(Iy,[Bl]),Zp=Bl(),[jJ,$l]=t4(Iy),n4=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=Zp(t),c=v.useRef(null),[u,p]=v.useState(!1),[h,g]=Td({prop:r,defaultProp:i??!1,onChange:s,caller:Iy});return f.jsx(Ey,{...l,children:f.jsx(jJ,{scope:t,contentId:ba(),triggerRef:c,open:h,onOpenChange:g,onOpenToggle:v.useCallback(()=>g(b=>!b),[g]),hasCustomAnchor:u,onCustomAnchorAdd:v.useCallback(()=>p(!0),[]),onCustomAnchorRemove:v.useCallback(()=>p(!1),[]),modal:o,children:n})})};n4.displayName=Iy;var r4="PopoverAnchor",DJ=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=$l(r4,n),s=Zp(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return v.useEffect(()=>(o(),()=>l()),[o,l]),f.jsx(Gp,{...s,...r,ref:t})});DJ.displayName=r4;var i4="PopoverTrigger",s4=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=$l(i4,n),s=Zp(n),o=yn(t,i.triggerRef),l=f.jsx(nn.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":u4(i.open),...r,ref:o,onClick:rt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:f.jsx(Gp,{asChild:!0,...s,children:l})});s4.displayName=i4;var zk="PopoverPortal",[IJ,PJ]=t4(zk,{forceMount:void 0}),o4=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=$l(zk,t);return f.jsx(IJ,{scope:t,forceMount:n,children:f.jsx(js,{present:n||s.open,children:f.jsx(Yd,{asChild:!0,container:i,children:r})})})};o4.displayName=zk;var Ad="PopoverContent",a4=v.forwardRef((e,t)=>{const n=PJ(Ad,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=$l(Ad,e.__scopePopover);return f.jsx(js,{present:r||s.open,children:s.modal?f.jsx(zJ,{...i,ref:t}):f.jsx(BJ,{...i,ref:t})})});a4.displayName=Ad;var OJ=Ic("PopoverContent.RemoveScroll"),zJ=v.forwardRef((e,t)=>{const n=$l(Ad,e.__scopePopover),r=v.useRef(null),i=yn(t,r),s=v.useRef(!1);return v.useEffect(()=>{const o=r.current;if(o)return xy(o)},[]),f.jsx(Vp,{as:OJ,allowPinchZoom:!0,children:f.jsx(l4,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:rt(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:rt(e.onPointerDownOutside,o=>{const l=o.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,u=l.button===2||c;s.current=u},{checkForDefaultPrevented:!1}),onFocusOutside:rt(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),BJ=v.forwardRef((e,t)=>{const n=$l(Ad,e.__scopePopover),r=v.useRef(!1),i=v.useRef(!1);return f.jsx(l4,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var o,l;(o=e.onCloseAutoFocus)==null||o.call(e,s),s.defaultPrevented||(r.current||(l=n.triggerRef.current)==null||l.focus(),s.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:s=>{var c,u;(c=e.onInteractOutside)==null||c.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const o=s.target;((u=n.triggerRef.current)==null?void 0:u.contains(o))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&i.current&&s.preventDefault()}})}),l4=v.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:l,onPointerDownOutside:c,onFocusOutside:u,onInteractOutside:p,...h}=e,g=$l(Ad,n),b=Zp(n);return by(),f.jsx(Up,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:f.jsx(Kd,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:p,onEscapeKeyDown:l,onPointerDownOutside:c,onFocusOutside:u,onDismiss:()=>g.onOpenChange(!1),children:f.jsx(Ty,{"data-state":u4(g.open),role:"dialog",id:g.contentId,...b,...h,ref:t,style:{...h.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),c4="PopoverClose",FJ=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=$l(c4,n);return f.jsx(nn.button,{type:"button",...r,ref:t,onClick:rt(e.onClick,()=>i.onOpenChange(!1))})});FJ.displayName=c4;var $J="PopoverArrow",HJ=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Zp(n);return f.jsx(Ry,{...i,...r,ref:t})});HJ.displayName=$J;function u4(e){return e?"open":"closed"}var UJ=n4,VJ=s4,WJ=o4,d4=a4;const Bk=UJ,Fk=VJ,Py=v.forwardRef(({className:e,align:t="center",sideOffset:n=4,...r},i)=>f.jsx(WJ,{children:f.jsx(d4,{ref:i,align:t,sideOffset:n,[sp]:"",onCloseAutoFocus:s=>{var o;s.preventDefault(),window.dispatchEvent(new Event(mb)),(o=r.onCloseAutoFocus)==null||o.call(r,s)},className:me("z-50 w-72 rounded-xl border border-border bg-background p-4 shadow-lg outline-hidden animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-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})}));Py.displayName=d4.displayName;function GJ({editorLabel:e,starred:t,onCopyPath:n,onShowArchived:r,onOpenInFinder:i,onOpenInEditor:s,onToggleStar:o,onHide:l,children:c}){return f.jsxs(Zc,{children:[f.jsx(Jc,{asChild:!0,children:c}),f.jsxs(Fl,{children:[f.jsxs(Mn,{onSelect:u=>{u.stopPropagation(),o()},children:[t?f.jsx(GG,{className:"h-3.5 w-3.5"}):f.jsx(E5,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:t?"Unstar project":"Star project"})]}),f.jsxs(Mn,{onSelect:u=>{u.stopPropagation(),n()},children:[f.jsx(jl,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Copy Path"})]}),f.jsxs(Mn,{onSelect:u=>{u.stopPropagation(),r()},children:[f.jsx(GC,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Show Archived"})]}),f.jsxs(Mn,{onSelect:u=>{u.stopPropagation(),i()},children:[f.jsx(py,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Show in Finder"})]}),f.jsxs(Mn,{onSelect:u=>{u.stopPropagation(),s()},children:[f.jsx(KC,{className:"h-3.5 w-3.5"}),f.jsxs("span",{className:"text-xs font-medium",children:["Open in ",e]})]}),f.jsxs(Mn,{onSelect:u=>{u.stopPropagation(),l()},className:"text-destructive hover:bg-destructive/10 focus:bg-destructive/10",children:[f.jsx(WV,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Hide"})]})]})]})}function qJ({canFork:e,onRename:t,onShare:n,onOpenInFinder:r,onFork:i,onArchive:s,onDelete:o,onEditPermissions:l,children:c}){return f.jsxs(Zc,{children:[f.jsx(Jc,{asChild:!0,children:c}),f.jsxs(Fl,{children:[f.jsxs(Mn,{onSelect:u=>{u.preventDefault(),t()},children:[f.jsx(Hp,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Rename"})]}),f.jsxs(Mn,{onSelect:u=>{u.preventDefault(),n()},children:[f.jsx(tk,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Share"})]}),f.jsxs(Mn,{onSelect:u=>{u.preventDefault(),r()},children:[f.jsx(py,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Open in Finder"})]}),f.jsxs(Mn,{disabled:!e,onSelect:u=>{u.preventDefault(),e&&i()},children:[f.jsx(k5,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Fork"})]}),l?f.jsxs(Mn,{onSelect:u=>{u.preventDefault(),l()},children:[f.jsx(C5,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Permissions…"})]}):null,f.jsxs(Mn,{onSelect:u=>{u.preventDefault(),s()},children:[f.jsx(GC,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Archive"})]}),f.jsxs(Mn,{onSelect:u=>{u.preventDefault(),o()},className:"text-destructive dark:text-red-400 hover:bg-destructive/10 focus:bg-destructive/10 dark:hover:bg-red-500/20 dark:focus:bg-red-500/20",children:[f.jsx(qd,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Delete"})]})]})]})}function KJ({stackTitle:e,onRename:t,onEditMembers:n,onDelete:r,children:i}){const[s,o]=v.useState(!1);function l(c){return()=>{o(!1),c()}}return f.jsxs(Bk,{open:s,onOpenChange:o,children:[f.jsx(Fk,{asChild:!0,children:i}),f.jsxs(Py,{align:"end",sideOffset:4,className:"w-44 p-1",role:"menu","aria-label":`Actions for ${e}`,children:[f.jsxs("button",{type:"button",role:"menuitem",onClick:l(t),className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-xs font-medium hover:bg-muted focus-visible:bg-muted outline-hidden",children:[f.jsx(Hp,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Rename"})]}),f.jsxs("button",{type:"button",role:"menuitem",onClick:l(n),className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-xs font-medium hover:bg-muted focus-visible:bg-muted outline-hidden",children:[f.jsx(T5,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Edit members"})]}),f.jsxs("button",{type:"button",role:"menuitem",onClick:l(r),className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-xs font-medium text-destructive dark:text-red-400 hover:bg-destructive/10 focus-visible:bg-destructive/10 dark:hover:bg-red-500/20 dark:focus-visible:bg-red-500/20 outline-hidden",children:[f.jsx(qd,{className:"h-3.5 w-3.5"}),f.jsxs("span",{children:["Delete ",e]})]})]})]})}function YJ({stackTitle:e,onRename:t,onEditMembers:n,onDelete:r,children:i}){return f.jsxs(Zc,{children:[f.jsx(Jc,{asChild:!0,children:i}),f.jsxs(Fl,{children:[f.jsxs(Mn,{onSelect:s=>{s.preventDefault(),t()},children:[f.jsx(Hp,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Rename"})]}),f.jsxs(Mn,{onSelect:s=>{s.preventDefault(),n()},children:[f.jsx(T5,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Edit members"})]}),f.jsxs(Mn,{onSelect:s=>{s.preventDefault(),r()},className:"text-destructive dark:text-red-400 hover:bg-destructive/10 focus:bg-destructive/10 dark:hover:bg-red-500/20 dark:focus:bg-red-500/20",children:[f.jsx(qd,{className:"h-3.5 w-3.5"}),f.jsxs("span",{className:"text-xs font-medium",children:["Delete ",e]})]})]})]})}function XJ(e){return e.status==="running"||e.status==="starting"?"warning":e.status==="waiting_for_user"?"info":e.status==="failed"?"destructive":e.unread?"success":null}function QJ(e){switch(e){case"warning":return"bg-warning";case"info":return"bg-info";case"success":return"bg-success";case"destructive":return"bg-destructive";default:return""}}function ZJ(e){switch(e){case"warning":return"text-warning";case"info":return"text-info";case"success":return"text-success";case"destructive":return"text-destructive";default:return"text-muted-foreground"}}function JJ(e){switch(e){case"active":return{glyph:"●",tone:"text-success",title:"Claude PTY session active"};case"warming":return{glyph:"◐",tone:"text-warning",title:"Claude PTY session warming"};case"idle":return{glyph:"○",tone:"text-muted-foreground",title:"Claude PTY session idle"};case"cooling":return{glyph:"◌",tone:"text-muted-foreground",title:"Claude PTY session cooling down"};case"cold":default:return null}}function eee({chat:e,activeChatId:t,nowMs:n,shortcutHint:r=null,showShortcutHint:i=!1,onSelectChat:s,onRenameChat:o,onShareChat:l,onOpenInFinder:c,onForkChat:u,onArchiveChat:p,onDeleteChat:h,onEditPermissions:g}){const b=(e.status==="running"||e.status==="waiting_for_user")&&e.stateEnteredAt!=null,x=b&&e.stateEnteredAt!=null?`${OS(e.status)} ${PS(n-e.stateEnteredAt)}`:xl(n-(e.lastMessageAt??e._creationTime)),_=i&&r?r:x,w=i&&!!r,C=eK(e.chatId),E=t===C,k=XJ(e),R=e.canFork?"w-12":b?"w-12 md:w-20":"w-6 md:w-14",N=f.jsxs("div",{"data-chat-id":C,className:me("group flex items-center gap-2 pl-2 pr-1 py-1.5 rounded-md cursor-pointer transition-colors duration-150",E?"bg-muted":"hover:bg-muted/40"),onClick:()=>s(e.chatId),children:[f.jsx("span",{className:"relative flex h-3.5 w-3.5 shrink-0 items-center justify-center","aria-hidden":!0,children:k?f.jsx("span",{className:me("h-2 w-2 rounded-full",QJ(k))}):null}),(()=>{const A=JJ(e.sessionState);return A?f.jsx("span",{className:me("shrink-0 text-[10px] leading-none",A.tone),title:A.title,"aria-label":A.title,children:A.glyph}):null})(),e.hasPolicyOverride?f.jsx(C5,{className:"size-3 shrink-0 text-warning","aria-label":"Per-chat permission override active"}):null,f.jsx("span",{className:me("truncate flex-1 text-sm",E?"text-foreground font-medium":"text-foreground/90",e.status==="idle"&&!e.unread&&!E?"text-muted-foreground":""),children:e.title}),f.jsxs("div",{className:me("relative h-6 shrink-0",R),children:[_?w?f.jsx("span",{className:"hidden md:flex absolute inset-0 items-center justify-end pr-0.5 text-[11px] text-foreground transition-opacity duration-150 group-hover:opacity-0",children:f.jsx(s3,{className:"h-4 min-w-4 rounded-sm border-border/50 bg-transparent px-1 text-[10px]",children:r})}):f.jsx("span",{className:me("hidden md:flex absolute inset-0 items-center justify-end pr-1 text-[11px] tabular-nums transition-opacity duration-150 group-hover:opacity-0 whitespace-nowrap",b?ZJ(k):"text-muted-foreground"),children:_}):null,f.jsxs("div",{className:me("absolute inset-0 flex items-center justify-end gap-0 transition-opacity duration-150",_?"opacity-100 md:opacity-0 md:group-hover:opacity-100":"opacity-100"),children:[e.canFork?f.jsx(Ge,{variant:"ghost",size:"icon",className:"h-6 w-6 cursor-pointer rounded-sm hover:!bg-transparent !border-0",onClick:A=>{A.stopPropagation(),u(e.chatId)},title:"Fork chat",children:f.jsx(k5,{className:"size-3.5"})}):null,f.jsx(Ge,{variant:"ghost",size:"icon",className:"h-6 w-6 cursor-pointer rounded-sm hover:!bg-transparent !border-0",onClick:A=>{A.stopPropagation(),p(e.chatId)},title:"Archive chat",children:f.jsx(GC,{className:"size-3.5"})})]})]})]},e._id);return f.jsx(qJ,{canFork:e.canFork,onRename:()=>o(e.chatId),onShare:()=>l(e.chatId),onOpenInFinder:()=>c(e.localPath),onFork:()=>u(e.chatId),onArchive:()=>p(e.chatId),onDelete:()=>h(e.chatId),onEditPermissions:g?()=>g(e.chatId):void 0,children:N})}const tee=v.memo(eee);function nee(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return v.useMemo(()=>r=>{t.forEach(i=>i(r))},t)}const Oy=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Jd(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function $k(e){return"nodeType"in e}function Ii(e){var t,n;return e?Jd(e)?e:$k(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function Hk(e){const{Document:t}=Ii(e);return e instanceof t}function Jp(e){return Jd(e)?!1:e instanceof Ii(e).HTMLElement}function f4(e){return e instanceof Ii(e).SVGElement}function ef(e){return e?Jd(e)?e.document:$k(e)?Hk(e)?e:Jp(e)||f4(e)?e.ownerDocument:document:document:document}const Po=Oy?v.useLayoutEffect:v.useEffect;function Uk(e){const t=v.useRef(e);return Po(()=>{t.current=e}),v.useCallback(function(){for(var n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];return t.current==null?void 0:t.current(...r)},[])}function ree(){const e=v.useRef(null),t=v.useCallback((r,i)=>{e.current=setInterval(r,i)},[]),n=v.useCallback(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[]);return[t,n]}function dp(e,t){t===void 0&&(t=[e]);const n=v.useRef(e);return Po(()=>{n.current!==e&&(n.current=e)},t),n}function em(e,t){const n=v.useRef();return v.useMemo(()=>{const r=e(n.current);return n.current=r,r},[...t])}function kb(e){const t=Uk(e),n=v.useRef(null),r=v.useCallback(i=>{i!==n.current&&(t==null||t(i,n.current)),n.current=i},[]);return[n,r]}function FS(e){const t=v.useRef();return v.useEffect(()=>{t.current=e},[e]),t.current}let V_={};function tm(e,t){return v.useMemo(()=>{if(t)return t;const n=V_[e]==null?0:V_[e]+1;return V_[e]=n,e+"-"+n},[e,t])}function h4(e){return function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return r.reduce((s,o)=>{const l=Object.entries(o);for(const[c,u]of l){const p=s[c];p!=null&&(s[c]=p+e*u)}return s},{...t})}}const gd=h4(1),Eb=h4(-1);function iee(e){return"clientX"in e&&"clientY"in e}function Vk(e){if(!e)return!1;const{KeyboardEvent:t}=Ii(e.target);return t&&e instanceof t}function see(e){if(!e)return!1;const{TouchEvent:t}=Ii(e.target);return t&&e instanceof t}function $S(e){if(see(e)){if(e.touches&&e.touches.length){const{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}else if(e.changedTouches&&e.changedTouches.length){const{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return iee(e)?{x:e.clientX,y:e.clientY}:null}const fp=Object.freeze({Translate:{toString(e){if(!e)return;const{x:t,y:n}=e;return"translate3d("+(t?Math.round(t):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(e){if(!e)return;const{scaleX:t,scaleY:n}=e;return"scaleX("+t+") scaleY("+n+")"}},Transform:{toString(e){if(e)return[fp.Translate.toString(e),fp.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}}),MM="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function oee(e){return e.matches(MM)?e:e.querySelector(MM)}const aee={display:"none"};function lee(e){let{id:t,value:n}=e;return _n.createElement("div",{id:t,style:aee},n)}function cee(e){let{id:t,announcement:n,ariaLiveType:r="assertive"}=e;const i={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return _n.createElement("div",{id:t,style:i,role:"status","aria-live":r,"aria-atomic":!0},n)}function uee(){const[e,t]=v.useState("");return{announce:v.useCallback(r=>{r!=null&&t(r)},[]),announcement:e}}const p4=v.createContext(null);function dee(e){const t=v.useContext(p4);v.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function fee(){const[e]=v.useState(()=>new Set),t=v.useCallback(r=>(e.add(r),()=>e.delete(r)),[e]);return[v.useCallback(r=>{let{type:i,event:s}=r;e.forEach(o=>{var l;return(l=o[i])==null?void 0:l.call(o,s)})},[e]),t]}const hee={draggable:`
707
707
  To pick up a draggable item, press the space bar.
708
708
  While dragging, use the arrow keys to move the item.
709
709
  Press space again to drop the item in its new position, or press escape to cancel.
@@ -858,7 +858,7 @@ XID_Continue XIDC
858
858
  XID_Start XIDS`.split(/\s/).map(e=>[Zy(e),e])),Iae=new Map([["s",Sr(383)],[Sr(383),"s"]]),Pae=new Map([[Sr(223),Sr(7838)],[Sr(107),Sr(8490)],[Sr(229),Sr(8491)],[Sr(969),Sr(8486)]]),Oae=new Map([vl(453),vl(456),vl(459),vl(498),...hw(8072,8079),...hw(8088,8095),...hw(8104,8111),vl(8124),vl(8140),vl(8188)]),zae=new Map([["alnum",Ot`[\p{Alpha}\p{Nd}]`],["alpha",Ot`\p{Alpha}`],["ascii",Ot`\p{ASCII}`],["blank",Ot`[\p{Zs}\t]`],["cntrl",Ot`\p{Cc}`],["digit",Ot`\p{Nd}`],["graph",Ot`[\P{space}&&\P{Cc}&&\P{Cn}&&\P{Cs}]`],["lower",Ot`\p{Lower}`],["print",Ot`[[\P{space}&&\P{Cc}&&\P{Cn}&&\P{Cs}]\p{Zs}]`],["punct",Ot`[\p{P}\p{S}]`],["space",Ot`\p{space}`],["upper",Ot`\p{Upper}`],["word",Ot`[\p{Alpha}\p{M}\p{Nd}\p{Pc}]`],["xdigit",Ot`\p{AHex}`]]);function Bae(e,t){const n=[];for(let r=e;r<=t;r++)n.push(r);return n}function vl(e){const t=Sr(e);return[t.toLowerCase(),t]}function hw(e,t){return Bae(e,t).map(n=>vl(n))}var s8=new Set(["Lower","Lowercase","Upper","Uppercase","Ll","Lowercase_Letter","Lt","Titlecase_Letter","Lu","Uppercase_Letter"]);function Fae(e,t){const n={accuracy:"default",asciiWordBoundaries:!1,avoidSubclass:!1,bestEffortTarget:"ES2025",...t};o8(e);const r={accuracy:n.accuracy,asciiWordBoundaries:n.asciiWordBoundaries,avoidSubclass:n.avoidSubclass,flagDirectivesByAlt:new Map,jsGroupNameMap:new Map,minTargetEs2024:w1(n.bestEffortTarget,"ES2024"),passedLookbehind:!1,strategy:null,subroutineRefMap:new Map,supportedGNodes:new Set,digitIsAscii:e.flags.digitIsAscii,spaceIsAscii:e.flags.spaceIsAscii,wordIsAscii:e.flags.wordIsAscii};Gh(e,$ae,r);const i={dotAll:e.flags.dotAll,ignoreCase:e.flags.ignoreCase},s={currentFlags:i,prevFlags:null,globalFlags:i,groupOriginByCopy:new Map,groupsByName:new Map,multiplexCapturesToLeftByRef:new Map,openRefs:new Map,reffedNodesByReferencer:new Map,subroutineRefMap:r.subroutineRefMap};Gh(e,Hae,s);const o={groupsByName:s.groupsByName,highestOrphanBackref:0,numCapturesToLeft:0,reffedNodesByReferencer:s.reffedNodesByReferencer};return Gh(e,Uae,o),e._originMap=s.groupOriginByCopy,e._strategy=r.strategy,e}var $ae={AbsenceFunction({node:e,parent:t,replaceWith:n}){const{body:r,kind:i}=e;if(i==="repeater"){const s=qs();s.body[0].body.push(Cc({negate:!0,body:r}),od("Any"));const o=qs();o.body[0].body.push(Q6("greedy",0,1/0,s)),n(sr(o,t),{traverse:!0})}else throw new Error('Unsupported absence function "(?~|"')},Alternative:{enter({node:e,parent:t,key:n},{flagDirectivesByAlt:r}){const i=e.body.filter(s=>s.kind==="flags");for(let s=n+1;s<t.body.length;s++){const o=t.body[s];Ep(r,o,[]).push(...i)}},exit({node:e},{flagDirectivesByAlt:t}){var n;if((n=t.get(e))!=null&&n.length){const r=l8(t.get(e));if(r){const i=qs({flags:r});i.body[0].body=e.body,e.body=[sr(i,e)]}}}},Assertion({node:e,parent:t,key:n,container:r,root:i,remove:s,replaceWith:o},l){const{kind:c,negate:u}=e,{asciiWordBoundaries:p,avoidSubclass:h,supportedGNodes:g,wordIsAscii:b}=l;if(c==="text_segment_boundary")throw new Error(`Unsupported text segment boundary "\\${u?"Y":"y"}"`);if(c==="line_end")o(sr(Cc({body:[Fc({body:[b1("string_end")]}),Fc({body:[Qy(10)]})]}),t));else if(c==="line_start")o(sr(ia(Ot`(?<=\A|\n(?!\z))`,{skipLookbehindValidation:!0}),t));else if(c==="search_start")if(g.has(e))i.flags.sticky=!0,s();else{const x=r[n-1];if(x&&Yae(x))o(sr(Cc({negate:!0}),t));else{if(h)throw new Error(Ot`Uses "\G" in a way that requires a subclass`);o(bl(b1("string_start"),t)),l.strategy="clip_search"}}else if(!(c==="string_end"||c==="string_start"))if(c==="string_end_newline")o(sr(ia(Ot`(?=\n?\z)`),t));else if(c==="word_boundary"){if(!b&&!p){const x=`(?:(?<=${ra})(?!${ra})|(?<!${ra})(?=${ra}))`,_=`(?:(?<=${ra})(?=${ra})|(?<!${ra})(?!${ra}))`;o(sr(ia(u?_:x),t))}}else throw new Error(`Unexpected assertion kind "${c}"`)},Backreference({node:e},{jsGroupNameMap:t}){let{ref:n}=e;typeof n=="string"&&!mw(n)&&(n=pw(n,t),e.ref=n)},CapturingGroup({node:e},{jsGroupNameMap:t,subroutineRefMap:n}){let{name:r}=e;r&&!mw(r)&&(r=pw(r,t),e.name=r),n.set(e.number,e),r&&n.set(r,e)},CharacterClassRange({node:e,parent:t,replaceWith:n}){if(t.kind==="intersection"){const r=qv({body:[e]});n(sr(r,t),{traverse:!0})}},CharacterSet({node:e,parent:t,replaceWith:n},{accuracy:r,minTargetEs2024:i,digitIsAscii:s,spaceIsAscii:o,wordIsAscii:l}){const{kind:c,negate:u,value:p}=e;if(s&&(c==="digit"||p==="digit")){n(bl(x1("digit",{negate:u}),t));return}if(o&&(c==="space"||p==="space")){n(sr(gw(ia(jae),u),t));return}if(l&&(c==="word"||p==="word")){n(bl(x1("word",{negate:u}),t));return}if(c==="any")n(bl(od("Any"),t));else if(c==="digit")n(bl(od("Nd",{negate:u}),t));else if(c!=="dot")if(c==="text_segment"){if(r==="strict")throw new Error(Ot`Use of "\X" requires non-strict accuracy`);const h="\\p{Emoji}(?:\\p{EMod}|\\uFE0F\\u20E3?|[\\x{E0020}-\\x{E007E}]+\\x{E007F})?",g=Ot`\p{RI}{2}|${h}(?:\u200D${h})*`;n(sr(ia(Ot`(?>\r\n|${i?Ot`\p{RGI_Emoji}`:g}|\P{M}\p{M}*)`,{skipPropertyNameValidation:!0}),t))}else if(c==="hex")n(bl(od("AHex",{negate:u}),t));else if(c==="newline")n(sr(ia(u?`[^
859
859
  ]`:`(?>\r
860
860
  ?|[
861
- \v\f…\u2028\u2029])`),t));else if(c==="posix")if(!i&&(p==="graph"||p==="print")){if(r==="strict")throw new Error(`POSIX class "${p}" requires min target ES2024 or non-strict accuracy`);let h={graph:"!-~",print:" -~"}[p];u&&(h=`\0-${Sr(h.codePointAt(0)-1)}${Sr(h.codePointAt(2)+1)}-􏿿`),n(sr(ia(`[${h}]`),t))}else n(sr(gw(ia(zae.get(p)),u),t));else if(c==="property")RE.has(Zy(p))||(e.key="sc");else if(c==="space")n(bl(od("space",{negate:u}),t));else if(c==="word")n(sr(gw(ia(ra),u),t));else throw new Error(`Unexpected character set kind "${c}"`)},Directive({node:e,parent:t,root:n,remove:r,replaceWith:i,removeAllPrevSiblings:s,removeAllNextSiblings:o}){const{kind:l,flags:c}=e;if(l==="flags")if(!c.enable&&!c.disable)r();else{const u=qs({flags:c});u.body[0].body=o(),i(sr(u,t),{traverse:!0})}else if(l==="keep"){const u=n.body[0],h=n.body.length===1&&K6(u,{type:"Group"})&&u.body[0].body.length===1?u.body[0]:n;if(t.parent!==h||h.body.length>1)throw new Error(Ot`Uses "\K" in a way that's unsupported`);const g=Cc({behind:!0});g.body[0].body=s(),i(sr(g,t))}else throw new Error(`Unexpected directive kind "${l}"`)},Flags({node:e,parent:t}){if(e.posixIsAscii)throw new Error('Unsupported flag "P"');if(e.textSegmentMode==="word")throw new Error('Unsupported flag "y{w}"');["digitIsAscii","extended","posixIsAscii","spaceIsAscii","wordIsAscii","textSegmentMode"].forEach(n=>delete e[n]),Object.assign(e,{global:!1,hasIndices:!1,multiline:!1,sticky:e.sticky??!1}),t.options={disable:{x:!0,n:!0},force:{v:!0}}},Group({node:e}){if(!e.flags)return;const{enable:t,disable:n}=e.flags;t!=null&&t.extended&&delete t.extended,n!=null&&n.extended&&delete n.extended,t!=null&&t.dotAll&&(n!=null&&n.dotAll)&&delete t.dotAll,t!=null&&t.ignoreCase&&(n!=null&&n.ignoreCase)&&delete t.ignoreCase,t&&!Object.keys(t).length&&delete e.flags.enable,n&&!Object.keys(n).length&&delete e.flags.disable,!e.flags.enable&&!e.flags.disable&&delete e.flags},LookaroundAssertion({node:e},t){const{kind:n}=e;n==="lookbehind"&&(t.passedLookbehind=!0)},NamedCallout({node:e,parent:t,replaceWith:n}){const{kind:r}=e;if(r==="fail")n(sr(Cc({negate:!0}),t));else throw new Error(`Unsupported named callout "(*${r.toUpperCase()}"`)},Quantifier({node:e}){if(e.body.type==="Quantifier"){const t=qs();t.body[0].body.push(e.body),e.body=sr(t,e)}},Regex:{enter({node:e},{supportedGNodes:t}){const n=[];let r=!1,i=!1;for(const s of e.body)if(s.body.length===1&&s.body[0].kind==="search_start")s.body.pop();else{const o=u8(s.body);o?(r=!0,Array.isArray(o)?n.push(...o):n.push(o)):i=!0}r&&!i&&n.forEach(s=>t.add(s))},exit(e,{accuracy:t,passedLookbehind:n,strategy:r}){if(t==="strict"&&n&&r)throw new Error(Ot`Uses "\G" in a way that requires non-strict accuracy`)}},Subroutine({node:e},{jsGroupNameMap:t}){let{ref:n}=e;typeof n=="string"&&!mw(n)&&(n=pw(n,t),e.ref=n)}},Hae={Backreference({node:e},{multiplexCapturesToLeftByRef:t,reffedNodesByReferencer:n}){const{orphan:r,ref:i}=e;r||n.set(e,[...t.get(i).map(({node:s})=>s)])},CapturingGroup:{enter({node:e,parent:t,replaceWith:n,skip:r},{groupOriginByCopy:i,groupsByName:s,multiplexCapturesToLeftByRef:o,openRefs:l,reffedNodesByReferencer:c}){const u=i.get(e);if(u&&l.has(e.number)){const h=bl($L(e.number),t);c.set(h,l.get(e.number)),n(h);return}l.set(e.number,e),o.set(e.number,[]),e.name&&Ep(o,e.name,[]);const p=o.get(e.name??e.number);for(let h=0;h<p.length;h++){const g=p[h];if(u===g.node||u&&u===g.origin||e===g.origin){p.splice(h,1);break}}if(o.get(e.number).push({node:e,origin:u}),e.name&&o.get(e.name).push({node:e,origin:u}),e.name){const h=Ep(s,e.name,new Map);let g=!1;if(u)g=!0;else for(const b of h.values())if(!b.hasDuplicateNameToRemove){g=!0;break}s.get(e.name).set(e,{node:e,hasDuplicateNameToRemove:g})}},exit({node:e},{openRefs:t}){t.delete(e.number)}},Group:{enter({node:e},t){t.prevFlags=t.currentFlags,e.flags&&(t.currentFlags=$b(t.currentFlags,e.flags))},exit(e,t){t.currentFlags=t.prevFlags}},Subroutine({node:e,parent:t,replaceWith:n},r){const{isRecursive:i,ref:s}=e;if(i){let p=t;for(;(p=p.parent)&&!(p.type==="CapturingGroup"&&(p.name===s||p.number===s)););r.reffedNodesByReferencer.set(e,p);return}const o=r.subroutineRefMap.get(s),l=s===0,c=l?$L(0):a8(o,r.groupOriginByCopy,null);let u=c;if(!l){const p=l8(Gae(o,g=>g.type==="Group"&&!!g.flags)),h=p?$b(r.globalFlags,p):r.globalFlags;Vae(h,r.currentFlags)||(u=qs({flags:qae(h)}),u.body[0].body.push(c))}n(sr(u,t),{traverse:!l})}},Uae={Backreference({node:e,parent:t,replaceWith:n},r){if(e.orphan){r.highestOrphanBackref=Math.max(r.highestOrphanBackref,e.ref);return}const s=r.reffedNodesByReferencer.get(e).filter(o=>Wae(o,e));if(!s.length)n(sr(Cc({negate:!0}),t));else if(s.length>1){const o=qs({atomic:!0,body:s.reverse().map(l=>Fc({body:[y1(l.number)]}))});n(sr(o,t))}else e.ref=s[0].number},CapturingGroup({node:e},t){e.number=++t.numCapturesToLeft,e.name&&t.groupsByName.get(e.name).get(e).hasDuplicateNameToRemove&&delete e.name},Regex:{exit({node:e},t){const n=Math.max(t.highestOrphanBackref-t.numCapturesToLeft,0);for(let r=0;r<n;r++){const i=X6();e.body.at(-1).body.push(i)}}},Subroutine({node:e},t){!e.isRecursive||e.ref===0||(e.ref=t.reffedNodesByReferencer.get(e).number)}};function o8(e){Gh(e,{"*"({node:t,parent:n}){t.parent=n}})}function Vae(e,t){return e.dotAll===t.dotAll&&e.ignoreCase===t.ignoreCase}function Wae(e,t){let n=t;do{if(n.type==="Regex")return!1;if(n.type==="Alternative")continue;if(n===e)return!1;const r=c8(n.parent);for(const i of r){if(i===n)break;if(i===e||d8(i,e))return!0}}while(n=n.parent);throw new Error("Unexpected path")}function a8(e,t,n,r){const i=Array.isArray(e)?[]:{};for(const[s,o]of Object.entries(e))s==="parent"?i.parent=Array.isArray(n)?r:n:o&&typeof o=="object"?i[s]=a8(o,t,i,n):(s==="type"&&o==="CapturingGroup"&&t.set(i,t.get(e)??e),i[s]=o);return i}function $L(e){const t=Z6(e);return t.isRecursive=!0,t}function Gae(e,t){const n=[];for(;e=e.parent;)(!t||t(e))&&n.push(e);return n}function pw(e,t){if(t.has(e))return t.get(e);const n=`$${t.size}_${e.replace(/^[^$_\p{IDS}]|[^$\u200C\u200D\p{IDC}]/ug,"_")}`;return t.set(e,n),n}function l8(e){const t=["dotAll","ignoreCase"],n={enable:{},disable:{}};return e.forEach(({flags:r})=>{t.forEach(i=>{var s,o;(s=r.enable)!=null&&s[i]&&(delete n.disable[i],n.enable[i]=!0),(o=r.disable)!=null&&o[i]&&(n.disable[i]=!0)})}),Object.keys(n.enable).length||delete n.enable,Object.keys(n.disable).length||delete n.disable,n.enable||n.disable?n:null}function qae({dotAll:e,ignoreCase:t}){const n={};return(e||t)&&(n.enable={},e&&(n.enable.dotAll=!0),t&&(n.enable.ignoreCase=!0)),(!e||!t)&&(n.disable={},!e&&(n.disable.dotAll=!0),!t&&(n.disable.ignoreCase=!0)),n}function c8(e){if(!e)throw new Error("Node expected");const{body:t}=e;return Array.isArray(t)?t:t?[t]:null}function u8(e){const t=e.find(n=>n.kind==="search_start"||Xae(n,{negate:!1})||!Kae(n));if(!t)return null;if(t.kind==="search_start")return t;if(t.type==="LookaroundAssertion")return t.body[0].body[0];if(t.type==="CapturingGroup"||t.type==="Group"){const n=[];for(const r of t.body){const i=u8(r.body);if(!i)return null;Array.isArray(i)?n.push(...i):n.push(i)}return n}return null}function d8(e,t){const n=c8(e)??[];for(const r of n)if(r===t||d8(r,t))return!0;return!1}function Kae({type:e}){return e==="Assertion"||e==="Directive"||e==="LookaroundAssertion"}function Yae(e){const t=["Character","CharacterClass","CharacterSet"];return t.includes(e.type)||e.type==="Quantifier"&&e.min&&t.includes(e.body.type)}function Xae(e,t){const n={negate:null,...t};return e.type==="LookaroundAssertion"&&(n.negate===null||e.negate===n.negate)&&e.body.length===1&&K6(e.body[0],{type:"Assertion",kind:"search_start"})}function mw(e){return/^[$_\p{IDS}][$\u200C\u200D\p{IDC}]*$/u.test(e)}function ia(e,t){const r=Y6(e,{...t,unicodePropertyMap:RE}).body;return r.length>1||r[0].body.length>1?qs({body:r}):r[0].body[0]}function gw(e,t){return e.negate=t,e}function bl(e,t){return e.parent=t,e}function sr(e,t){return o8(e),e.parent=t,e}function Qae(e,t){const n=r8(t),r=w1(n.target,"ES2024"),i=w1(n.target,"ES2025"),s=n.rules.recursionLimit;if(!Number.isInteger(s)||s<2||s>20)throw new Error("Invalid recursionLimit; use 2-20");let o=null,l=null;if(!i){const b=[e.flags.ignoreCase];Gh(e,Zae,{getCurrentModI:()=>b.at(-1),popModI(){b.pop()},pushModI(x){b.push(x)},setHasCasedChar(){b.at(-1)?o=!0:l=!0}})}const c={dotAll:e.flags.dotAll,ignoreCase:!!((e.flags.ignoreCase||o)&&!l)};let u=e;const p={accuracy:n.accuracy,appliedGlobalFlags:c,captureMap:new Map,currentFlags:{dotAll:e.flags.dotAll,ignoreCase:e.flags.ignoreCase},inCharClass:!1,lastNode:u,originMap:e._originMap,recursionLimit:s,useAppliedIgnoreCase:!!(!i&&o&&l),useFlagMods:i,useFlagV:r,verbose:n.verbose};function h(b){return p.lastNode=u,u=b,Mae(Jae[b.type],`Unexpected node type "${b.type}"`)(b,p,h)}const g={pattern:e.body.map(h).join("|"),flags:h(e.flags),options:{...e.options}};return r||(delete g.options.force.v,g.options.disable.v=!0,g.options.unicodeSetsPlugin=null),g._captureTransfers=new Map,g._hiddenCaptures=[],p.captureMap.forEach((b,x)=>{b.hidden&&g._hiddenCaptures.push(x),b.transferTo&&Ep(g._captureTransfers,b.transferTo,[]).push(x)}),g}var Zae={"*":{enter({node:e},t){if(UL(e)){const n=t.getCurrentModI();t.pushModI(e.flags?$b({ignoreCase:n},e.flags).ignoreCase:n)}},exit({node:e},t){UL(e)&&t.popModI()}},Backreference(e,t){t.setHasCasedChar()},Character({node:e},t){NE(Sr(e.value))&&t.setHasCasedChar()},CharacterClassRange({node:e,skip:t},n){t(),f8(e,{firstOnly:!0}).length&&n.setHasCasedChar()},CharacterSet({node:e},t){e.kind==="property"&&s8.has(e.value)&&t.setHasCasedChar()}},Jae={Alternative({body:e},t,n){return e.map(n).join("")},Assertion({kind:e,negate:t}){if(e==="string_end")return"$";if(e==="string_start")return"^";if(e==="word_boundary")return t?Ot`\B`:Ot`\b`;throw new Error(`Unexpected assertion kind "${e}"`)},Backreference({ref:e},t){if(typeof e!="number")throw new Error("Unexpected named backref in transformed AST");if(!t.useFlagMods&&t.accuracy==="strict"&&t.currentFlags.ignoreCase&&!t.captureMap.get(e).ignoreCase)throw new Error("Use of case-insensitive backref to case-sensitive group requires target ES2025 or non-strict accuracy");return"\\"+e},CapturingGroup(e,t,n){const{body:r,name:i,number:s}=e,o={ignoreCase:t.currentFlags.ignoreCase},l=t.originMap.get(e);return l&&(o.hidden=!0,s>l.number&&(o.transferTo=l.number)),t.captureMap.set(s,o),`(${i?`?<${i}>`:""}${r.map(n).join("|")})`},Character({value:e},t){const n=Sr(e),r=Vu(e,{escDigit:t.lastNode.type==="Backreference",inCharClass:t.inCharClass,useFlagV:t.useFlagV});if(r!==n)return r;if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase&&NE(n)){const i=i8(n);return t.inCharClass?i.join(""):i.length>1?`[${i.join("")}]`:i[0]}return n},CharacterClass(e,t,n){const{kind:r,negate:i,parent:s}=e;let{body:o}=e;if(r==="intersection"&&!t.useFlagV)throw new Error("Use of character class intersection requires min target ES2024");Xs.bugFlagVLiteralHyphenIsRange&&t.useFlagV&&o.some(VL)&&(o=[Qy(45),...o.filter(u=>!VL(u))]);const l=()=>`[${i?"^":""}${o.map(n).join(r==="intersection"?"&&":"")}]`;if(!t.inCharClass){if((!t.useFlagV||Xs.bugNestedClassIgnoresNegation)&&!i){const p=o.filter(h=>h.type==="CharacterClass"&&h.kind==="union"&&h.negate);if(p.length){const h=qs(),g=h.body[0];return h.parent=s,g.parent=h,o=o.filter(b=>!p.includes(b)),e.body=o,o.length?(e.parent=g,g.body.push(e)):h.body.pop(),p.forEach(b=>{const x=Fc({body:[b]});b.parent=x,x.parent=h,h.body.push(x)}),n(h)}}t.inCharClass=!0;const u=l();return t.inCharClass=!1,u}const c=o[0];if(r==="union"&&!i&&c&&((!t.useFlagV||!t.verbose)&&s.kind==="union"&&!(Xs.bugFlagVLiteralHyphenIsRange&&t.useFlagV)||!t.verbose&&s.kind==="intersection"&&o.length===1&&c.type!=="CharacterClassRange"))return o.map(n).join("");if(!t.useFlagV&&s.type==="CharacterClass")throw new Error("Uses nested character class in a way that requires min target ES2024");return l()},CharacterClassRange(e,t){const n=e.min.value,r=e.max.value,i={escDigit:!1,inCharClass:!0,useFlagV:t.useFlagV},s=Vu(n,i),o=Vu(r,i),l=new Set;if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase){const c=f8(e);ile(c).forEach(p=>{l.add(Array.isArray(p)?`${Vu(p[0],i)}-${Vu(p[1],i)}`:Vu(p,i))})}return`${s}-${o}${[...l].join("")}`},CharacterSet({kind:e,negate:t,value:n,key:r},i){if(e==="dot")return i.currentFlags.dotAll?i.appliedGlobalFlags.dotAll||i.useFlagMods?".":"[^]":Ot`[^\n]`;if(e==="digit")return t?Ot`\D`:Ot`\d`;if(e==="property"){if(i.useAppliedIgnoreCase&&i.currentFlags.ignoreCase&&s8.has(n))throw new Error(`Unicode property "${n}" can't be case-insensitive when other chars have specific case`);return`${t?Ot`\P`:Ot`\p`}{${r?`${r}=`:""}${n}}`}if(e==="word")return t?Ot`\W`:Ot`\w`;throw new Error(`Unexpected character set kind "${e}"`)},Flags(e,t){return(t.appliedGlobalFlags.ignoreCase?"i":"")+(e.dotAll?"s":"")+(e.sticky?"y":"")},Group({atomic:e,body:t,flags:n,parent:r},i,s){const o=i.currentFlags;n&&(i.currentFlags=$b(o,n));const l=t.map(s).join("|"),c=!i.verbose&&t.length===1&&r.type!=="Quantifier"&&!e&&(!i.useFlagMods||!n)?l:`(?${sle(e,n,i.useFlagMods)}${l})`;return i.currentFlags=o,c},LookaroundAssertion({body:e,kind:t,negate:n},r,i){return`(?${`${t==="lookahead"?"":"<"}${n?"!":"="}`}${e.map(i).join("|")})`},Quantifier(e,t,n){return n(e.body)+ole(e)},Subroutine({isRecursive:e,ref:t},n){if(!e)throw new Error("Unexpected non-recursive subroutine in transformed AST");const r=n.recursionLimit;return t===0?`(?R=${r})`:Ot`\g<${t}&R=${r}>`}},ele=new Set(["$","(",")","*","+",".","?","[","\\","]","^","{","|","}"]),tle=new Set(["-","\\","]","^","["]),nle=new Set(["(",")","-","/","[","\\","]","^","{","|","}","!","#","$","%","&","*","+",",",".",":",";","<","=",">","?","@","`","~"]),HL=new Map([[9,Ot`\t`],[10,Ot`\n`],[11,Ot`\v`],[12,Ot`\f`],[13,Ot`\r`],[8232,Ot`\u2028`],[8233,Ot`\u2029`],[65279,Ot`\uFEFF`]]),rle=new RegExp("^\\p{Cased}$","u");function NE(e){return rle.test(e)}function f8(e,t){const n=!!(t!=null&&t.firstOnly),r=e.min.value,i=e.max.value,s=[];if(r<65&&(i===65535||i>=131071)||r===65536&&i>=131071)return s;for(let o=r;o<=i;o++){const l=Sr(o);if(!NE(l))continue;const c=i8(l).filter(u=>{const p=u.codePointAt(0);return p<r||p>i});if(c.length&&(s.push(...c),n))break}return s}function Vu(e,{escDigit:t,inCharClass:n,useFlagV:r}){if(HL.has(e))return HL.get(e);if(e<32||e>126&&e<160||e>262143||t&&ale(e))return e>255?`\\u{${e.toString(16).toUpperCase()}}`:`\\x${e.toString(16).toUpperCase().padStart(2,"0")}`;const i=n?r?nle:tle:ele,s=Sr(e);return(i.has(s)?"\\":"")+s}function ile(e){const t=e.map(i=>i.codePointAt(0)).sort((i,s)=>i-s),n=[];let r=null;for(let i=0;i<t.length;i++)t[i+1]===t[i]+1?r??(r=t[i]):r===null?n.push(t[i]):(n.push([r,t[i]]),r=null);return n}function sle(e,t,n){if(e)return">";let r="";if(t&&n){const{enable:i,disable:s}=t;r=(i!=null&&i.ignoreCase?"i":"")+(i!=null&&i.dotAll?"s":"")+(s?"-":"")+(s!=null&&s.ignoreCase?"i":"")+(s!=null&&s.dotAll?"s":"")}return`${r}:`}function ole({kind:e,max:t,min:n}){let r;return!n&&t===1?r="?":!n&&t===1/0?r="*":n===1&&t===1/0?r="+":n===t?r=`{${n}}`:r=`{${n},${t===1/0?"":t}}`,r+{greedy:"",lazy:"?",possessive:"+"}[e]}function UL({type:e}){return e==="CapturingGroup"||e==="Group"||e==="LookaroundAssertion"}function ale(e){return e>47&&e<58}function VL({type:e,value:t}){return e==="Character"&&t===45}var Cl,ua,Mc,kl,Lc,Bp,S1,Ll,lle=(Ll=class extends RegExp{constructor(n,r,i){var t=(...WTe)=>(super(...WTe),ll(this,Bp),ll(this,Cl,new Map),ll(this,ua,null),ll(this,Mc),ll(this,kl,null),ll(this,Lc,null),ne(this,"rawOptions",{}),this);const s=!!(i!=null&&i.lazyCompile);if(n instanceof RegExp){if(i)throw new Error("Cannot provide options when copying a regexp");const o=n;t(o,r),hs(this,Mc,o.source),o instanceof Ll&&(hs(this,Cl,br(o,Cl)),hs(this,kl,br(o,kl)),hs(this,Lc,br(o,Lc)),this.rawOptions=o.rawOptions)}else{const o={hiddenCaptures:[],strategy:null,transfers:[],...i};t(s?"":n,r),hs(this,Mc,n),hs(this,Cl,ule(o.hiddenCaptures,o.transfers)),hs(this,Lc,o.strategy),this.rawOptions=i??{}}s||hs(this,ua,this)}get source(){return br(this,Mc)||"(?:)"}exec(n){if(!br(this,ua)){const{lazyCompile:s,...o}=this.rawOptions;hs(this,ua,new Ll(br(this,Mc),this.flags,o))}const r=this.global||this.sticky,i=this.lastIndex;if(br(this,Lc)==="clip_search"&&r&&i){this.lastIndex=0;const s=x_(this,Bp,S1).call(this,n.slice(i));return s&&(cle(s,i,n,this.hasIndices),this.lastIndex+=i),s}return x_(this,Bp,S1).call(this,n)}},Cl=new WeakMap,ua=new WeakMap,Mc=new WeakMap,kl=new WeakMap,Lc=new WeakMap,Bp=new WeakSet,S1=function(n){br(this,ua).lastIndex=this.lastIndex;const r=hA(Ll.prototype,this,"exec").call(br(this,ua),n);if(this.lastIndex=br(this,ua).lastIndex,!r||!br(this,Cl).size)return r;const i=[...r];r.length=1;let s;this.hasIndices&&(s=[...r.indices],r.indices.length=1);const o=[0];for(let l=1;l<i.length;l++){const{hidden:c,transferTo:u}=br(this,Cl).get(l)??{};if(c?o.push(null):(o.push(r.length),r.push(i[l]),this.hasIndices&&r.indices.push(s[l])),u&&i[l]!==void 0){const p=o[u];if(!p)throw new Error(`Invalid capture transfer to "${p}"`);if(r[p]=i[l],this.hasIndices&&(r.indices[p]=s[l]),r.groups){br(this,kl)||hs(this,kl,dle(this.source));const h=br(this,kl).get(u);h&&(r.groups[h]=i[l],this.hasIndices&&(r.indices.groups[h]=s[l]))}}}return r},Ll);function cle(e,t,n,r){if(e.index+=t,e.input=n,r){const i=e.indices;for(let o=0;o<i.length;o++){const l=i[o];l&&(i[o]=[l[0]+t,l[1]+t])}const s=i.groups;s&&Object.keys(s).forEach(o=>{const l=s[o];l&&(s[o]=[l[0]+t,l[1]+t])})}}function ule(e,t){const n=new Map;for(const r of e)n.set(r,{hidden:!0});for(const[r,i]of t)for(const s of i)Ep(n,s,{}).transferTo=r;return n}function dle(e){const t=/(?<capture>\((?:\?<(?![=!])(?<name>[^>]+)>|(?!\?)))|\\?./gsu,n=new Map;let r=0,i=0,s;for(;s=t.exec(e);){const{0:o,groups:{capture:l,name:c}}=s;o==="["?r++:r?o==="]"&&r--:l&&(i++,c&&n.set(i,c))}return n}function fle(e,t){const n=hle(e,t);return n.options?new lle(n.pattern,n.flags,n.options):new RegExp(n.pattern,n.flags)}function hle(e,t){const n=r8(t),r=Y6(e,{flags:n.flags,normalizeUnknownPropertyNames:!0,rules:{captureGroup:n.rules.captureGroup,singleline:n.rules.singleline},skipBackrefValidation:n.rules.allowOrphanBackrefs,unicodePropertyMap:RE}),i=Fae(r,{accuracy:n.accuracy,asciiWordBoundaries:n.rules.asciiWordBoundaries,avoidSubclass:n.avoidSubclass,bestEffortTarget:n.target}),s=Qae(i,n),o=Nae(s.pattern,{captureTransfers:s._captureTransfers,hiddenCaptures:s._hiddenCaptures,mode:"external"}),l=Tae(o.pattern),c=Eae(l.pattern,{captureTransfers:o.captureTransfers,hiddenCaptures:o.hiddenCaptures}),u={pattern:c.pattern,flags:`${n.hasIndices?"d":""}${n.global?"g":""}${s.flags}${s.options.disable.v?"u":"v"}`};if(n.avoidSubclass){if(n.lazyCompileLength!==1/0)throw new Error("Lazy compilation requires subclass")}else{const p=c.hiddenCaptures.sort((x,_)=>x-_),h=Array.from(c.captureTransfers),g=i._strategy,b=u.pattern.length>=n.lazyCompileLength;(p.length||h.length||g||b)&&(u.options={...p.length&&{hiddenCaptures:p},...h.length&&{transfers:h},...g&&{strategy:g},...b&&{lazyCompile:b}})}return u}const WL=4294967295;class ple{constructor(t,n={}){ne(this,"regexps");this.patterns=t,this.options=n;const{forgiving:r=!1,cache:i,regexConstructor:s}=n;if(!s)throw new Error("Option `regexConstructor` is not provided");this.regexps=t.map(o=>{if(typeof o!="string")return o;const l=i==null?void 0:i.get(o);if(l){if(l instanceof RegExp)return l;if(r)return null;throw l}try{const c=s(o);return i==null||i.set(o,c),c}catch(c){if(i==null||i.set(o,c),r)return null;throw c}})}findNextMatchSync(t,n,r){const i=typeof t=="string"?t:t.content,s=[];function o(l,c,u=0){return{index:l,captureIndices:c.indices.map(p=>p==null?{start:WL,end:WL,length:0}:{start:p[0]+u,end:p[1]+u,length:p[1]-p[0]})}}for(let l=0;l<this.regexps.length;l++){const c=this.regexps[l];if(c)try{c.lastIndex=n;const u=c.exec(i);if(!u)continue;if(u.index===n)return o(l,u,0);s.push([l,u,0])}catch(u){if(this.options.forgiving)continue;throw u}}if(s.length){const l=Math.min(...s.map(c=>c[1].index));for(const[c,u,p]of s)if(u.index===l)return o(c,u,p)}return null}}function h8(e,t){return fle(e,{global:!0,hasIndices:!0,lazyCompileLength:3e3,rules:{allowOrphanBackrefs:!0,asciiWordBoundaries:!0,captureGroup:!0,recursionLimit:5,singleline:!0},...t})}function p8(e={}){const t=Object.assign({target:"auto",cache:new Map},e);return t.regexConstructor||(t.regexConstructor=n=>h8(n,{target:t.target})),{createScanner(n){return new ple(n,t)},createString(n){return{content:n}}}}const mle=Object.freeze(Object.defineProperty({__proto__:null,ShikiError:ar,addClassToHast:hE,applyColorReplacements:ya,bundledLanguages:Fb,bundledLanguagesAlias:B6,bundledLanguagesBase:z6,bundledLanguagesInfo:xE,bundledThemes:_E,bundledThemesInfo:F6,codeToHast:koe,codeToHtml:Coe,codeToTokens:Eoe,codeToTokensBase:Toe,codeToTokensWithThemes:Roe,createBundledHighlighter:yE,createCssVariablesTheme:loe,createHighlighter:CE,createHighlighterCore:bE,createHighlighterCoreSync:soe,createJavaScriptRegexEngine:p8,createOnigurumaEngine:SE,createPositionConverter:m6,createShikiInternal:D6,createShikiInternalSync:vE,createSingletonShorthands:O6,createdBundledHighlighter:aoe,defaultJavaScriptRegexConstructor:h8,enableDeprecationWarnings:noe,flatTokenVariants:y6,getLastGrammarState:Aoe,getSingletonHighlighter:Noe,getSingletonHighlighterCore:ooe,getTokenStyleObject:wp,guessEmbeddedLanguages:g6,hastToHtml:T6,isNoneTheme:Gy,isPlainLang:Wy,isSpecialLang:dE,isSpecialTheme:fE,loadWasm:H6,makeSingletonHighlighter:P6,makeSingletonHighlighterCore:I6,normalizeGetter:uE,normalizeTheme:om,resolveColorReplacements:_p,splitLines:sm,splitToken:v6,splitTokens:b6,stringifyTokenStyle:zb,toArray:p6,tokenizeAnsiWithTheme:S6,tokenizeWithTheme:k6,tokensToHast:E6,transformerDecorations:_6,warnDeprecated:L6},Symbol.toStringTag,{value:"Module"}));async function gle(e){if(Pz())throw new Error(`resolveLanguage("${e}") cannot be called from a worker context. Languages must be pre-resolved on the main thread and passed to the worker via the resolvedLanguages parameter.`);const t=tw.get(e);if(t!=null)return t;try{let n=Pre.get(e);if(n==null&&Object.prototype.hasOwnProperty.call(Fb,e)&&(n=Fb[e]),n==null)throw new Error(`resolveLanguage: "${e}" not found in bundled or custom languages`);const r=n().then(({default:i})=>{const s={name:e,data:i};return vp.has(e)||vp.set(e,s),s});return tw.set(e,r),await r}finally{tw.delete(e)}}function vle(e){return vp.get(e)??gle(e)}async function ble(e){if(Pz())throw new Error(`resolveTheme("${e}") cannot be called from a worker context. Themes must be pre-resolved on the main thread and passed to the worker via the resolvedLanguages parameter.`);const t=ew.get(e);if(t!=null)return t;try{const n=s1.get(e)??_E[e];if(n==null)throw new Error(`resolveTheme: No valid loader for ${e}`);const r=n().then(s=>yle(e,"default"in s?s.default:s));ew.set(e,r);const i=await r;if(i.name!==e)throw new Error(`resolvedTheme: themeName: ${e} does not match theme.name: ${i.name}`);return jc.set(i.name,i),i}finally{ew.delete(e)}}function yle(e,t){const n=jc.get(e);return n??(t=om(t),jc.set(e,t),t)}function xle(e){return jc.get(e)??ble(e)}function m8(e,t){if(s1.has(e)){console.error("SharedHighlight.registerCustomTheme: theme name already registered",e);return}s1.set(e,t)}let Co;async function _le({themes:e,langs:t,preferredHighlighter:n="shiki-js"}){Co??(Co=CE({themes:[],langs:["text"],engine:n==="shiki-wasm"?SE(K(()=>import("./wasm-CG6Dc4jp.js"),[])):p8()}));const r=Sle(Co)?await Co:Co;Co=r;const i=[];for(const o of t){if(o==="text"||o==="ansi")continue;const l=vle(o);"then"in l?i.push(l):iL(l,r)}const s=[];for(const o of e){const l=xle(o);"then"in l?s.push(l):rL(l,Co)}return(i.length>0||s.length>0)&&await Promise.all([Promise.all(i).then(o=>{iL(o,r)}),Promise.all(s).then(o=>{rL(o,r)})]),r}function wle(){if(Co!=null&&!("then"in Co))return Co}function Sle(e=Co){return e!=null&&"then"in e}m8("pierre-dark",async()=>{const{default:e}=await K(async()=>{const{default:t}=await import("./pierre-dark-DF2SEV7i.js");return{default:t}},[]);return{...e,name:"pierre-dark"}});m8("pierre-light",async()=>{const{default:e}=await K(async()=>{const{default:t}=await import("./pierre-light-DOlZxES8.js");return{default:t}},[]);return{...e,name:"pierre-light"}});function g8(e=To){const t=[];return typeof e=="string"?t.push(e):(t.push(e.dark),t.push(e.light)),t}function v8(e,t){return e==null||t==null||typeof e=="string"||typeof t=="string"?e===t:e.dark===t.dark&&e.light===t.light}const Wu=new Map,ph={"1c":"1c",abap:"abap",as:"actionscript-3",ada:"ada",adb:"ada",ads:"ada",adoc:"asciidoc",asciidoc:"asciidoc","component.html":"angular-html","component.ts":"angular-ts",conf:"nginx",htaccess:"apache",cls:"tex",trigger:"apex",apl:"apl",applescript:"applescript",scpt:"applescript",ara:"ara",asm:"asm",s:"riscv",astro:"astro",awk:"awk",bal:"ballerina",sh:"zsh",bash:"zsh",bat:"cmd",cmd:"cmd",be:"berry",beancount:"beancount",bib:"bibtex",bicep:"bicep","blade.php":"blade",bsl:"bsl",c:"c",h:"objective-cpp",cs:"csharp",cpp:"cpp",hpp:"cpp",cc:"cpp",cxx:"cpp",hh:"cpp",cdc:"cdc",cairo:"cairo",clar:"clarity",clj:"clojure",cljs:"clojure",cljc:"clojure",soy:"soy",cmake:"cmake","CMakeLists.txt":"cmake",cob:"cobol",cbl:"cobol",cobol:"cobol",CODEOWNERS:"codeowners",ql:"ql",coffee:"coffeescript",lisp:"lisp",cl:"lisp",lsp:"lisp",log:"log",v:"verilog",cql:"cql",cr:"crystal",css:"css",csv:"csv",cue:"cue",cypher:"cypher",cyp:"cypher",d:"d",dart:"dart",dax:"dax",desktop:"desktop",diff:"diff",patch:"diff",Dockerfile:"dockerfile",dockerfile:"dockerfile",env:"dotenv",dm:"dream-maker",edge:"edge",el:"emacs-lisp",ex:"elixir",exs:"elixir",elm:"elm",erb:"erb",erl:"erlang",hrl:"erlang",f:"fortran-fixed-form",for:"fortran-fixed-form",fs:"fsharp",fsi:"fsharp",fsx:"fsharp",f03:"f03",f08:"f08",f18:"f18",f77:"f77",f90:"fortran-free-form",f95:"fortran-free-form",fnl:"fennel",fish:"fish",ftl:"ftl",tres:"gdresource",res:"gdresource",gd:"gdscript",gdshader:"gdshader",gs:"genie",feature:"gherkin",COMMIT_EDITMSG:"git-commit","git-rebase-todo":"git-rebase",gjs:"glimmer-js",gleam:"gleam",gts:"glimmer-ts",glsl:"glsl",vert:"glsl",frag:"glsl",shader:"shaderlab",gp:"gnuplot",plt:"gnuplot",gnuplot:"gnuplot",go:"go",graphql:"graphql",gql:"graphql",groovy:"groovy",gvy:"groovy",hack:"hack",haml:"haml",hbs:"handlebars",handlebars:"handlebars",hs:"haskell",lhs:"haskell",hx:"haxe",hcl:"hcl",hjson:"hjson",hlsl:"hlsl",fx:"hlsl",html:"html",htm:"html",http:"http",rest:"http",hxml:"hxml",hy:"hy",imba:"imba",ini:"ini",cfg:"ini",jade:"pug",pug:"pug",java:"java",js:"javascript",mjs:"javascript",cjs:"javascript",jinja:"jinja",jinja2:"jinja",j2:"jinja",jison:"jison",jl:"julia",json:"json",json5:"json5",jsonc:"jsonc",jsonl:"jsonl",jsonnet:"jsonnet",libsonnet:"jsonnet",jssm:"jssm",jsx:"jsx",kt:"kotlin",kts:"kts",kql:"kusto",tex:"tex",ltx:"tex",lean:"lean4",less:"less",liquid:"liquid",lit:"lit",ll:"llvm",logo:"logo",lua:"lua",luau:"luau",Makefile:"makefile",mk:"makefile",makefile:"makefile",md:"markdown",markdown:"markdown",marko:"marko",m:"wolfram",mat:"matlab",mdc:"mdc",mdx:"mdx",wiki:"wikitext",mediawiki:"wikitext",mmd:"mermaid",mermaid:"mermaid",mips:"mipsasm",mojo:"mojo","🔥":"mojo",move:"move",nar:"narrat",nf:"nextflow",nim:"nim",nims:"nim",nimble:"nim",nix:"nix",nu:"nushell",mm:"objective-cpp",ml:"ocaml",mli:"ocaml",mll:"ocaml",mly:"ocaml",pas:"pascal",p:"pascal",pl:"prolog",pm:"perl",t:"perl",raku:"raku",p6:"raku",pl6:"raku",php:"php",phtml:"php",pls:"plsql",sql:"sql",po:"po",polar:"polar",pcss:"postcss",pot:"pot",potx:"potx",pq:"powerquery",pqm:"powerquery",ps1:"powershell",psm1:"powershell",psd1:"powershell",prisma:"prisma",pro:"prolog",P:"prolog",properties:"properties",proto:"protobuf",pp:"puppet",purs:"purescript",py:"python",pyw:"python",pyi:"python",qml:"qml",qmldir:"qmldir",qss:"qss",r:"r",R:"r",rkt:"racket",rktl:"racket",razor:"razor",cshtml:"razor",rb:"ruby",rbw:"ruby",reg:"reg",regex:"regexp",rel:"rel",rs:"rust",rst:"rst",rake:"ruby",gemspec:"ruby",sas:"sas",sass:"sass",scala:"scala",sc:"scala",scm:"scheme",ss:"scheme",sld:"scheme",scss:"scss",sdbl:"sdbl",shadergraph:"shader",st:"smalltalk",sol:"solidity",sparql:"sparql",rq:"sparql",spl:"splunk",config:"ssh-config",do:"stata",ado:"stata",dta:"stata",styl:"stylus",stylus:"stylus",svelte:"svelte",swift:"swift",sv:"system-verilog",svh:"system-verilog",service:"systemd",socket:"systemd",device:"systemd",timer:"systemd",talon:"talonscript",tasl:"tasl",tcl:"tcl",templ:"templ",tf:"tf",tfvars:"tfvars",toml:"toml",ts:"typescript",tsp:"typespec",tsv:"tsv",tsx:"tsx",ttl:"turtle",twig:"twig",typ:"typst",vv:"v",vala:"vala",vapi:"vala",vb:"vb",vbs:"vb",bas:"vb",vh:"verilog",vhd:"vhdl",vhdl:"vhdl",vim:"vimscript",vue:"vue","vine.ts":"vue-vine",vy:"vyper",wasm:"wasm",wat:"wasm",wy:"文言",wgsl:"wgsl",wit:"wit",wl:"wolfram",nb:"wolfram",xml:"xml",xsl:"xsl",xslt:"xsl",yaml:"yaml",yml:"yml",zs:"zenscript",zig:"zig",zsh:"zsh",sty:"tex"};function jd(e){var r;if(Wu.has(e))return Wu.get(e)??"text";if(ph[e]!=null)return ph[e];const t=e.match(/\.([^/\\]+\.[^/\\]+)$/);if(t!=null){if(Wu.has(t[1]))return Wu.get(t[1])??"text";if(ph[t[1]]!=null)return ph[t[1]]??"text"}const n=((r=e.match(/\.([^.]+)$/))==null?void 0:r[1])??"";return Wu.has(n)?Wu.get(n)??"text":ph[n]??"text"}function Dd(e){return e.replace(/\n$|\r\n$/,"")}function Ca(e){return{type:"text",value:e}}function Yt({tagName:e,children:t=[],properties:n={}}){return{type:"element",tagName:e,properties:n,children:t}}function Hb({name:e,width:t=16,height:n=16,properties:r}){return Yt({tagName:"svg",properties:{width:t,height:n,viewBox:"0 0 16 16",...r},children:[Yt({tagName:"use",properties:{href:`#${e.replace(/^#/,"")}`}})]})}function Cle(e){let t=e.children[0];for(;t!=null;){if(t.type==="element"&&t.tagName==="code")return t;"children"in t?t=t.children[0]:t=null}}function Zg(e){return Yt({tagName:"div",properties:{"data-gutter":""},children:e})}function kle(e,t,n,r={}){return Yt({tagName:"div",properties:{"data-line-type":e,"data-column-number":t,"data-line-index":n,...r},children:t!=null?[Yt({tagName:"span",properties:{"data-line-number-content":""},children:[Ca(`${t}`)]})]:void 0})}function Vs(e,t,n){return Yt({tagName:"div",properties:{"data-gutter-buffer":t,"data-buffer-size":n,"data-line-type":t==="annotation"?void 0:e,style:t==="annotation"?`grid-row: span ${n};`:`grid-row: span ${n};min-height:calc(${n} * 1lh);`}})}function Ele(e,t,n){const r=typeof n.lineInfo=="function"?n.lineInfo(t):n.lineInfo[t-1];if(r==null){const i=`processLine: line ${t}, contains no state.lineInfo`;throw console.error(i,{node:e,line:t,state:n}),new Error(i)}return e.tagName="div",e.properties["data-line"]=r.lineNumber,e.properties["data-alt-line"]=r.altLineNumber,e.properties["data-line-type"]=r.type,e.properties["data-line-index"]=r.lineIndex,e.children.length===0&&e.children.push(Ca(`
861
+ \v\f…\u2028\u2029])`),t));else if(c==="posix")if(!i&&(p==="graph"||p==="print")){if(r==="strict")throw new Error(`POSIX class "${p}" requires min target ES2024 or non-strict accuracy`);let h={graph:"!-~",print:" -~"}[p];u&&(h=`\0-${Sr(h.codePointAt(0)-1)}${Sr(h.codePointAt(2)+1)}-􏿿`),n(sr(ia(`[${h}]`),t))}else n(sr(gw(ia(zae.get(p)),u),t));else if(c==="property")RE.has(Zy(p))||(e.key="sc");else if(c==="space")n(bl(od("space",{negate:u}),t));else if(c==="word")n(sr(gw(ia(ra),u),t));else throw new Error(`Unexpected character set kind "${c}"`)},Directive({node:e,parent:t,root:n,remove:r,replaceWith:i,removeAllPrevSiblings:s,removeAllNextSiblings:o}){const{kind:l,flags:c}=e;if(l==="flags")if(!c.enable&&!c.disable)r();else{const u=qs({flags:c});u.body[0].body=o(),i(sr(u,t),{traverse:!0})}else if(l==="keep"){const u=n.body[0],h=n.body.length===1&&K6(u,{type:"Group"})&&u.body[0].body.length===1?u.body[0]:n;if(t.parent!==h||h.body.length>1)throw new Error(Ot`Uses "\K" in a way that's unsupported`);const g=Cc({behind:!0});g.body[0].body=s(),i(sr(g,t))}else throw new Error(`Unexpected directive kind "${l}"`)},Flags({node:e,parent:t}){if(e.posixIsAscii)throw new Error('Unsupported flag "P"');if(e.textSegmentMode==="word")throw new Error('Unsupported flag "y{w}"');["digitIsAscii","extended","posixIsAscii","spaceIsAscii","wordIsAscii","textSegmentMode"].forEach(n=>delete e[n]),Object.assign(e,{global:!1,hasIndices:!1,multiline:!1,sticky:e.sticky??!1}),t.options={disable:{x:!0,n:!0},force:{v:!0}}},Group({node:e}){if(!e.flags)return;const{enable:t,disable:n}=e.flags;t!=null&&t.extended&&delete t.extended,n!=null&&n.extended&&delete n.extended,t!=null&&t.dotAll&&(n!=null&&n.dotAll)&&delete t.dotAll,t!=null&&t.ignoreCase&&(n!=null&&n.ignoreCase)&&delete t.ignoreCase,t&&!Object.keys(t).length&&delete e.flags.enable,n&&!Object.keys(n).length&&delete e.flags.disable,!e.flags.enable&&!e.flags.disable&&delete e.flags},LookaroundAssertion({node:e},t){const{kind:n}=e;n==="lookbehind"&&(t.passedLookbehind=!0)},NamedCallout({node:e,parent:t,replaceWith:n}){const{kind:r}=e;if(r==="fail")n(sr(Cc({negate:!0}),t));else throw new Error(`Unsupported named callout "(*${r.toUpperCase()}"`)},Quantifier({node:e}){if(e.body.type==="Quantifier"){const t=qs();t.body[0].body.push(e.body),e.body=sr(t,e)}},Regex:{enter({node:e},{supportedGNodes:t}){const n=[];let r=!1,i=!1;for(const s of e.body)if(s.body.length===1&&s.body[0].kind==="search_start")s.body.pop();else{const o=u8(s.body);o?(r=!0,Array.isArray(o)?n.push(...o):n.push(o)):i=!0}r&&!i&&n.forEach(s=>t.add(s))},exit(e,{accuracy:t,passedLookbehind:n,strategy:r}){if(t==="strict"&&n&&r)throw new Error(Ot`Uses "\G" in a way that requires non-strict accuracy`)}},Subroutine({node:e},{jsGroupNameMap:t}){let{ref:n}=e;typeof n=="string"&&!mw(n)&&(n=pw(n,t),e.ref=n)}},Hae={Backreference({node:e},{multiplexCapturesToLeftByRef:t,reffedNodesByReferencer:n}){const{orphan:r,ref:i}=e;r||n.set(e,[...t.get(i).map(({node:s})=>s)])},CapturingGroup:{enter({node:e,parent:t,replaceWith:n,skip:r},{groupOriginByCopy:i,groupsByName:s,multiplexCapturesToLeftByRef:o,openRefs:l,reffedNodesByReferencer:c}){const u=i.get(e);if(u&&l.has(e.number)){const h=bl($L(e.number),t);c.set(h,l.get(e.number)),n(h);return}l.set(e.number,e),o.set(e.number,[]),e.name&&Ep(o,e.name,[]);const p=o.get(e.name??e.number);for(let h=0;h<p.length;h++){const g=p[h];if(u===g.node||u&&u===g.origin||e===g.origin){p.splice(h,1);break}}if(o.get(e.number).push({node:e,origin:u}),e.name&&o.get(e.name).push({node:e,origin:u}),e.name){const h=Ep(s,e.name,new Map);let g=!1;if(u)g=!0;else for(const b of h.values())if(!b.hasDuplicateNameToRemove){g=!0;break}s.get(e.name).set(e,{node:e,hasDuplicateNameToRemove:g})}},exit({node:e},{openRefs:t}){t.delete(e.number)}},Group:{enter({node:e},t){t.prevFlags=t.currentFlags,e.flags&&(t.currentFlags=$b(t.currentFlags,e.flags))},exit(e,t){t.currentFlags=t.prevFlags}},Subroutine({node:e,parent:t,replaceWith:n},r){const{isRecursive:i,ref:s}=e;if(i){let p=t;for(;(p=p.parent)&&!(p.type==="CapturingGroup"&&(p.name===s||p.number===s)););r.reffedNodesByReferencer.set(e,p);return}const o=r.subroutineRefMap.get(s),l=s===0,c=l?$L(0):a8(o,r.groupOriginByCopy,null);let u=c;if(!l){const p=l8(Gae(o,g=>g.type==="Group"&&!!g.flags)),h=p?$b(r.globalFlags,p):r.globalFlags;Vae(h,r.currentFlags)||(u=qs({flags:qae(h)}),u.body[0].body.push(c))}n(sr(u,t),{traverse:!l})}},Uae={Backreference({node:e,parent:t,replaceWith:n},r){if(e.orphan){r.highestOrphanBackref=Math.max(r.highestOrphanBackref,e.ref);return}const s=r.reffedNodesByReferencer.get(e).filter(o=>Wae(o,e));if(!s.length)n(sr(Cc({negate:!0}),t));else if(s.length>1){const o=qs({atomic:!0,body:s.reverse().map(l=>Fc({body:[y1(l.number)]}))});n(sr(o,t))}else e.ref=s[0].number},CapturingGroup({node:e},t){e.number=++t.numCapturesToLeft,e.name&&t.groupsByName.get(e.name).get(e).hasDuplicateNameToRemove&&delete e.name},Regex:{exit({node:e},t){const n=Math.max(t.highestOrphanBackref-t.numCapturesToLeft,0);for(let r=0;r<n;r++){const i=X6();e.body.at(-1).body.push(i)}}},Subroutine({node:e},t){!e.isRecursive||e.ref===0||(e.ref=t.reffedNodesByReferencer.get(e).number)}};function o8(e){Gh(e,{"*"({node:t,parent:n}){t.parent=n}})}function Vae(e,t){return e.dotAll===t.dotAll&&e.ignoreCase===t.ignoreCase}function Wae(e,t){let n=t;do{if(n.type==="Regex")return!1;if(n.type==="Alternative")continue;if(n===e)return!1;const r=c8(n.parent);for(const i of r){if(i===n)break;if(i===e||d8(i,e))return!0}}while(n=n.parent);throw new Error("Unexpected path")}function a8(e,t,n,r){const i=Array.isArray(e)?[]:{};for(const[s,o]of Object.entries(e))s==="parent"?i.parent=Array.isArray(n)?r:n:o&&typeof o=="object"?i[s]=a8(o,t,i,n):(s==="type"&&o==="CapturingGroup"&&t.set(i,t.get(e)??e),i[s]=o);return i}function $L(e){const t=Z6(e);return t.isRecursive=!0,t}function Gae(e,t){const n=[];for(;e=e.parent;)(!t||t(e))&&n.push(e);return n}function pw(e,t){if(t.has(e))return t.get(e);const n=`$${t.size}_${e.replace(/^[^$_\p{IDS}]|[^$\u200C\u200D\p{IDC}]/ug,"_")}`;return t.set(e,n),n}function l8(e){const t=["dotAll","ignoreCase"],n={enable:{},disable:{}};return e.forEach(({flags:r})=>{t.forEach(i=>{var s,o;(s=r.enable)!=null&&s[i]&&(delete n.disable[i],n.enable[i]=!0),(o=r.disable)!=null&&o[i]&&(n.disable[i]=!0)})}),Object.keys(n.enable).length||delete n.enable,Object.keys(n.disable).length||delete n.disable,n.enable||n.disable?n:null}function qae({dotAll:e,ignoreCase:t}){const n={};return(e||t)&&(n.enable={},e&&(n.enable.dotAll=!0),t&&(n.enable.ignoreCase=!0)),(!e||!t)&&(n.disable={},!e&&(n.disable.dotAll=!0),!t&&(n.disable.ignoreCase=!0)),n}function c8(e){if(!e)throw new Error("Node expected");const{body:t}=e;return Array.isArray(t)?t:t?[t]:null}function u8(e){const t=e.find(n=>n.kind==="search_start"||Xae(n,{negate:!1})||!Kae(n));if(!t)return null;if(t.kind==="search_start")return t;if(t.type==="LookaroundAssertion")return t.body[0].body[0];if(t.type==="CapturingGroup"||t.type==="Group"){const n=[];for(const r of t.body){const i=u8(r.body);if(!i)return null;Array.isArray(i)?n.push(...i):n.push(i)}return n}return null}function d8(e,t){const n=c8(e)??[];for(const r of n)if(r===t||d8(r,t))return!0;return!1}function Kae({type:e}){return e==="Assertion"||e==="Directive"||e==="LookaroundAssertion"}function Yae(e){const t=["Character","CharacterClass","CharacterSet"];return t.includes(e.type)||e.type==="Quantifier"&&e.min&&t.includes(e.body.type)}function Xae(e,t){const n={negate:null,...t};return e.type==="LookaroundAssertion"&&(n.negate===null||e.negate===n.negate)&&e.body.length===1&&K6(e.body[0],{type:"Assertion",kind:"search_start"})}function mw(e){return/^[$_\p{IDS}][$\u200C\u200D\p{IDC}]*$/u.test(e)}function ia(e,t){const r=Y6(e,{...t,unicodePropertyMap:RE}).body;return r.length>1||r[0].body.length>1?qs({body:r}):r[0].body[0]}function gw(e,t){return e.negate=t,e}function bl(e,t){return e.parent=t,e}function sr(e,t){return o8(e),e.parent=t,e}function Qae(e,t){const n=r8(t),r=w1(n.target,"ES2024"),i=w1(n.target,"ES2025"),s=n.rules.recursionLimit;if(!Number.isInteger(s)||s<2||s>20)throw new Error("Invalid recursionLimit; use 2-20");let o=null,l=null;if(!i){const b=[e.flags.ignoreCase];Gh(e,Zae,{getCurrentModI:()=>b.at(-1),popModI(){b.pop()},pushModI(x){b.push(x)},setHasCasedChar(){b.at(-1)?o=!0:l=!0}})}const c={dotAll:e.flags.dotAll,ignoreCase:!!((e.flags.ignoreCase||o)&&!l)};let u=e;const p={accuracy:n.accuracy,appliedGlobalFlags:c,captureMap:new Map,currentFlags:{dotAll:e.flags.dotAll,ignoreCase:e.flags.ignoreCase},inCharClass:!1,lastNode:u,originMap:e._originMap,recursionLimit:s,useAppliedIgnoreCase:!!(!i&&o&&l),useFlagMods:i,useFlagV:r,verbose:n.verbose};function h(b){return p.lastNode=u,u=b,Mae(Jae[b.type],`Unexpected node type "${b.type}"`)(b,p,h)}const g={pattern:e.body.map(h).join("|"),flags:h(e.flags),options:{...e.options}};return r||(delete g.options.force.v,g.options.disable.v=!0,g.options.unicodeSetsPlugin=null),g._captureTransfers=new Map,g._hiddenCaptures=[],p.captureMap.forEach((b,x)=>{b.hidden&&g._hiddenCaptures.push(x),b.transferTo&&Ep(g._captureTransfers,b.transferTo,[]).push(x)}),g}var Zae={"*":{enter({node:e},t){if(UL(e)){const n=t.getCurrentModI();t.pushModI(e.flags?$b({ignoreCase:n},e.flags).ignoreCase:n)}},exit({node:e},t){UL(e)&&t.popModI()}},Backreference(e,t){t.setHasCasedChar()},Character({node:e},t){NE(Sr(e.value))&&t.setHasCasedChar()},CharacterClassRange({node:e,skip:t},n){t(),f8(e,{firstOnly:!0}).length&&n.setHasCasedChar()},CharacterSet({node:e},t){e.kind==="property"&&s8.has(e.value)&&t.setHasCasedChar()}},Jae={Alternative({body:e},t,n){return e.map(n).join("")},Assertion({kind:e,negate:t}){if(e==="string_end")return"$";if(e==="string_start")return"^";if(e==="word_boundary")return t?Ot`\B`:Ot`\b`;throw new Error(`Unexpected assertion kind "${e}"`)},Backreference({ref:e},t){if(typeof e!="number")throw new Error("Unexpected named backref in transformed AST");if(!t.useFlagMods&&t.accuracy==="strict"&&t.currentFlags.ignoreCase&&!t.captureMap.get(e).ignoreCase)throw new Error("Use of case-insensitive backref to case-sensitive group requires target ES2025 or non-strict accuracy");return"\\"+e},CapturingGroup(e,t,n){const{body:r,name:i,number:s}=e,o={ignoreCase:t.currentFlags.ignoreCase},l=t.originMap.get(e);return l&&(o.hidden=!0,s>l.number&&(o.transferTo=l.number)),t.captureMap.set(s,o),`(${i?`?<${i}>`:""}${r.map(n).join("|")})`},Character({value:e},t){const n=Sr(e),r=Vu(e,{escDigit:t.lastNode.type==="Backreference",inCharClass:t.inCharClass,useFlagV:t.useFlagV});if(r!==n)return r;if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase&&NE(n)){const i=i8(n);return t.inCharClass?i.join(""):i.length>1?`[${i.join("")}]`:i[0]}return n},CharacterClass(e,t,n){const{kind:r,negate:i,parent:s}=e;let{body:o}=e;if(r==="intersection"&&!t.useFlagV)throw new Error("Use of character class intersection requires min target ES2024");Xs.bugFlagVLiteralHyphenIsRange&&t.useFlagV&&o.some(VL)&&(o=[Qy(45),...o.filter(u=>!VL(u))]);const l=()=>`[${i?"^":""}${o.map(n).join(r==="intersection"?"&&":"")}]`;if(!t.inCharClass){if((!t.useFlagV||Xs.bugNestedClassIgnoresNegation)&&!i){const p=o.filter(h=>h.type==="CharacterClass"&&h.kind==="union"&&h.negate);if(p.length){const h=qs(),g=h.body[0];return h.parent=s,g.parent=h,o=o.filter(b=>!p.includes(b)),e.body=o,o.length?(e.parent=g,g.body.push(e)):h.body.pop(),p.forEach(b=>{const x=Fc({body:[b]});b.parent=x,x.parent=h,h.body.push(x)}),n(h)}}t.inCharClass=!0;const u=l();return t.inCharClass=!1,u}const c=o[0];if(r==="union"&&!i&&c&&((!t.useFlagV||!t.verbose)&&s.kind==="union"&&!(Xs.bugFlagVLiteralHyphenIsRange&&t.useFlagV)||!t.verbose&&s.kind==="intersection"&&o.length===1&&c.type!=="CharacterClassRange"))return o.map(n).join("");if(!t.useFlagV&&s.type==="CharacterClass")throw new Error("Uses nested character class in a way that requires min target ES2024");return l()},CharacterClassRange(e,t){const n=e.min.value,r=e.max.value,i={escDigit:!1,inCharClass:!0,useFlagV:t.useFlagV},s=Vu(n,i),o=Vu(r,i),l=new Set;if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase){const c=f8(e);ile(c).forEach(p=>{l.add(Array.isArray(p)?`${Vu(p[0],i)}-${Vu(p[1],i)}`:Vu(p,i))})}return`${s}-${o}${[...l].join("")}`},CharacterSet({kind:e,negate:t,value:n,key:r},i){if(e==="dot")return i.currentFlags.dotAll?i.appliedGlobalFlags.dotAll||i.useFlagMods?".":"[^]":Ot`[^\n]`;if(e==="digit")return t?Ot`\D`:Ot`\d`;if(e==="property"){if(i.useAppliedIgnoreCase&&i.currentFlags.ignoreCase&&s8.has(n))throw new Error(`Unicode property "${n}" can't be case-insensitive when other chars have specific case`);return`${t?Ot`\P`:Ot`\p`}{${r?`${r}=`:""}${n}}`}if(e==="word")return t?Ot`\W`:Ot`\w`;throw new Error(`Unexpected character set kind "${e}"`)},Flags(e,t){return(t.appliedGlobalFlags.ignoreCase?"i":"")+(e.dotAll?"s":"")+(e.sticky?"y":"")},Group({atomic:e,body:t,flags:n,parent:r},i,s){const o=i.currentFlags;n&&(i.currentFlags=$b(o,n));const l=t.map(s).join("|"),c=!i.verbose&&t.length===1&&r.type!=="Quantifier"&&!e&&(!i.useFlagMods||!n)?l:`(?${sle(e,n,i.useFlagMods)}${l})`;return i.currentFlags=o,c},LookaroundAssertion({body:e,kind:t,negate:n},r,i){return`(?${`${t==="lookahead"?"":"<"}${n?"!":"="}`}${e.map(i).join("|")})`},Quantifier(e,t,n){return n(e.body)+ole(e)},Subroutine({isRecursive:e,ref:t},n){if(!e)throw new Error("Unexpected non-recursive subroutine in transformed AST");const r=n.recursionLimit;return t===0?`(?R=${r})`:Ot`\g<${t}&R=${r}>`}},ele=new Set(["$","(",")","*","+",".","?","[","\\","]","^","{","|","}"]),tle=new Set(["-","\\","]","^","["]),nle=new Set(["(",")","-","/","[","\\","]","^","{","|","}","!","#","$","%","&","*","+",",",".",":",";","<","=",">","?","@","`","~"]),HL=new Map([[9,Ot`\t`],[10,Ot`\n`],[11,Ot`\v`],[12,Ot`\f`],[13,Ot`\r`],[8232,Ot`\u2028`],[8233,Ot`\u2029`],[65279,Ot`\uFEFF`]]),rle=new RegExp("^\\p{Cased}$","u");function NE(e){return rle.test(e)}function f8(e,t){const n=!!(t!=null&&t.firstOnly),r=e.min.value,i=e.max.value,s=[];if(r<65&&(i===65535||i>=131071)||r===65536&&i>=131071)return s;for(let o=r;o<=i;o++){const l=Sr(o);if(!NE(l))continue;const c=i8(l).filter(u=>{const p=u.codePointAt(0);return p<r||p>i});if(c.length&&(s.push(...c),n))break}return s}function Vu(e,{escDigit:t,inCharClass:n,useFlagV:r}){if(HL.has(e))return HL.get(e);if(e<32||e>126&&e<160||e>262143||t&&ale(e))return e>255?`\\u{${e.toString(16).toUpperCase()}}`:`\\x${e.toString(16).toUpperCase().padStart(2,"0")}`;const i=n?r?nle:tle:ele,s=Sr(e);return(i.has(s)?"\\":"")+s}function ile(e){const t=e.map(i=>i.codePointAt(0)).sort((i,s)=>i-s),n=[];let r=null;for(let i=0;i<t.length;i++)t[i+1]===t[i]+1?r??(r=t[i]):r===null?n.push(t[i]):(n.push([r,t[i]]),r=null);return n}function sle(e,t,n){if(e)return">";let r="";if(t&&n){const{enable:i,disable:s}=t;r=(i!=null&&i.ignoreCase?"i":"")+(i!=null&&i.dotAll?"s":"")+(s?"-":"")+(s!=null&&s.ignoreCase?"i":"")+(s!=null&&s.dotAll?"s":"")}return`${r}:`}function ole({kind:e,max:t,min:n}){let r;return!n&&t===1?r="?":!n&&t===1/0?r="*":n===1&&t===1/0?r="+":n===t?r=`{${n}}`:r=`{${n},${t===1/0?"":t}}`,r+{greedy:"",lazy:"?",possessive:"+"}[e]}function UL({type:e}){return e==="CapturingGroup"||e==="Group"||e==="LookaroundAssertion"}function ale(e){return e>47&&e<58}function VL({type:e,value:t}){return e==="Character"&&t===45}var Cl,ua,Mc,kl,Lc,Bp,S1,Ll,lle=(Ll=class extends RegExp{constructor(n,r,i){var t=(...GTe)=>(super(...GTe),ll(this,Bp),ll(this,Cl,new Map),ll(this,ua,null),ll(this,Mc),ll(this,kl,null),ll(this,Lc,null),ne(this,"rawOptions",{}),this);const s=!!(i!=null&&i.lazyCompile);if(n instanceof RegExp){if(i)throw new Error("Cannot provide options when copying a regexp");const o=n;t(o,r),hs(this,Mc,o.source),o instanceof Ll&&(hs(this,Cl,br(o,Cl)),hs(this,kl,br(o,kl)),hs(this,Lc,br(o,Lc)),this.rawOptions=o.rawOptions)}else{const o={hiddenCaptures:[],strategy:null,transfers:[],...i};t(s?"":n,r),hs(this,Mc,n),hs(this,Cl,ule(o.hiddenCaptures,o.transfers)),hs(this,Lc,o.strategy),this.rawOptions=i??{}}s||hs(this,ua,this)}get source(){return br(this,Mc)||"(?:)"}exec(n){if(!br(this,ua)){const{lazyCompile:s,...o}=this.rawOptions;hs(this,ua,new Ll(br(this,Mc),this.flags,o))}const r=this.global||this.sticky,i=this.lastIndex;if(br(this,Lc)==="clip_search"&&r&&i){this.lastIndex=0;const s=x_(this,Bp,S1).call(this,n.slice(i));return s&&(cle(s,i,n,this.hasIndices),this.lastIndex+=i),s}return x_(this,Bp,S1).call(this,n)}},Cl=new WeakMap,ua=new WeakMap,Mc=new WeakMap,kl=new WeakMap,Lc=new WeakMap,Bp=new WeakSet,S1=function(n){br(this,ua).lastIndex=this.lastIndex;const r=hA(Ll.prototype,this,"exec").call(br(this,ua),n);if(this.lastIndex=br(this,ua).lastIndex,!r||!br(this,Cl).size)return r;const i=[...r];r.length=1;let s;this.hasIndices&&(s=[...r.indices],r.indices.length=1);const o=[0];for(let l=1;l<i.length;l++){const{hidden:c,transferTo:u}=br(this,Cl).get(l)??{};if(c?o.push(null):(o.push(r.length),r.push(i[l]),this.hasIndices&&r.indices.push(s[l])),u&&i[l]!==void 0){const p=o[u];if(!p)throw new Error(`Invalid capture transfer to "${p}"`);if(r[p]=i[l],this.hasIndices&&(r.indices[p]=s[l]),r.groups){br(this,kl)||hs(this,kl,dle(this.source));const h=br(this,kl).get(u);h&&(r.groups[h]=i[l],this.hasIndices&&(r.indices.groups[h]=s[l]))}}}return r},Ll);function cle(e,t,n,r){if(e.index+=t,e.input=n,r){const i=e.indices;for(let o=0;o<i.length;o++){const l=i[o];l&&(i[o]=[l[0]+t,l[1]+t])}const s=i.groups;s&&Object.keys(s).forEach(o=>{const l=s[o];l&&(s[o]=[l[0]+t,l[1]+t])})}}function ule(e,t){const n=new Map;for(const r of e)n.set(r,{hidden:!0});for(const[r,i]of t)for(const s of i)Ep(n,s,{}).transferTo=r;return n}function dle(e){const t=/(?<capture>\((?:\?<(?![=!])(?<name>[^>]+)>|(?!\?)))|\\?./gsu,n=new Map;let r=0,i=0,s;for(;s=t.exec(e);){const{0:o,groups:{capture:l,name:c}}=s;o==="["?r++:r?o==="]"&&r--:l&&(i++,c&&n.set(i,c))}return n}function fle(e,t){const n=hle(e,t);return n.options?new lle(n.pattern,n.flags,n.options):new RegExp(n.pattern,n.flags)}function hle(e,t){const n=r8(t),r=Y6(e,{flags:n.flags,normalizeUnknownPropertyNames:!0,rules:{captureGroup:n.rules.captureGroup,singleline:n.rules.singleline},skipBackrefValidation:n.rules.allowOrphanBackrefs,unicodePropertyMap:RE}),i=Fae(r,{accuracy:n.accuracy,asciiWordBoundaries:n.rules.asciiWordBoundaries,avoidSubclass:n.avoidSubclass,bestEffortTarget:n.target}),s=Qae(i,n),o=Nae(s.pattern,{captureTransfers:s._captureTransfers,hiddenCaptures:s._hiddenCaptures,mode:"external"}),l=Tae(o.pattern),c=Eae(l.pattern,{captureTransfers:o.captureTransfers,hiddenCaptures:o.hiddenCaptures}),u={pattern:c.pattern,flags:`${n.hasIndices?"d":""}${n.global?"g":""}${s.flags}${s.options.disable.v?"u":"v"}`};if(n.avoidSubclass){if(n.lazyCompileLength!==1/0)throw new Error("Lazy compilation requires subclass")}else{const p=c.hiddenCaptures.sort((x,_)=>x-_),h=Array.from(c.captureTransfers),g=i._strategy,b=u.pattern.length>=n.lazyCompileLength;(p.length||h.length||g||b)&&(u.options={...p.length&&{hiddenCaptures:p},...h.length&&{transfers:h},...g&&{strategy:g},...b&&{lazyCompile:b}})}return u}const WL=4294967295;class ple{constructor(t,n={}){ne(this,"regexps");this.patterns=t,this.options=n;const{forgiving:r=!1,cache:i,regexConstructor:s}=n;if(!s)throw new Error("Option `regexConstructor` is not provided");this.regexps=t.map(o=>{if(typeof o!="string")return o;const l=i==null?void 0:i.get(o);if(l){if(l instanceof RegExp)return l;if(r)return null;throw l}try{const c=s(o);return i==null||i.set(o,c),c}catch(c){if(i==null||i.set(o,c),r)return null;throw c}})}findNextMatchSync(t,n,r){const i=typeof t=="string"?t:t.content,s=[];function o(l,c,u=0){return{index:l,captureIndices:c.indices.map(p=>p==null?{start:WL,end:WL,length:0}:{start:p[0]+u,end:p[1]+u,length:p[1]-p[0]})}}for(let l=0;l<this.regexps.length;l++){const c=this.regexps[l];if(c)try{c.lastIndex=n;const u=c.exec(i);if(!u)continue;if(u.index===n)return o(l,u,0);s.push([l,u,0])}catch(u){if(this.options.forgiving)continue;throw u}}if(s.length){const l=Math.min(...s.map(c=>c[1].index));for(const[c,u,p]of s)if(u.index===l)return o(c,u,p)}return null}}function h8(e,t){return fle(e,{global:!0,hasIndices:!0,lazyCompileLength:3e3,rules:{allowOrphanBackrefs:!0,asciiWordBoundaries:!0,captureGroup:!0,recursionLimit:5,singleline:!0},...t})}function p8(e={}){const t=Object.assign({target:"auto",cache:new Map},e);return t.regexConstructor||(t.regexConstructor=n=>h8(n,{target:t.target})),{createScanner(n){return new ple(n,t)},createString(n){return{content:n}}}}const mle=Object.freeze(Object.defineProperty({__proto__:null,ShikiError:ar,addClassToHast:hE,applyColorReplacements:ya,bundledLanguages:Fb,bundledLanguagesAlias:B6,bundledLanguagesBase:z6,bundledLanguagesInfo:xE,bundledThemes:_E,bundledThemesInfo:F6,codeToHast:koe,codeToHtml:Coe,codeToTokens:Eoe,codeToTokensBase:Toe,codeToTokensWithThemes:Roe,createBundledHighlighter:yE,createCssVariablesTheme:loe,createHighlighter:CE,createHighlighterCore:bE,createHighlighterCoreSync:soe,createJavaScriptRegexEngine:p8,createOnigurumaEngine:SE,createPositionConverter:m6,createShikiInternal:D6,createShikiInternalSync:vE,createSingletonShorthands:O6,createdBundledHighlighter:aoe,defaultJavaScriptRegexConstructor:h8,enableDeprecationWarnings:noe,flatTokenVariants:y6,getLastGrammarState:Aoe,getSingletonHighlighter:Noe,getSingletonHighlighterCore:ooe,getTokenStyleObject:wp,guessEmbeddedLanguages:g6,hastToHtml:T6,isNoneTheme:Gy,isPlainLang:Wy,isSpecialLang:dE,isSpecialTheme:fE,loadWasm:H6,makeSingletonHighlighter:P6,makeSingletonHighlighterCore:I6,normalizeGetter:uE,normalizeTheme:om,resolveColorReplacements:_p,splitLines:sm,splitToken:v6,splitTokens:b6,stringifyTokenStyle:zb,toArray:p6,tokenizeAnsiWithTheme:S6,tokenizeWithTheme:k6,tokensToHast:E6,transformerDecorations:_6,warnDeprecated:L6},Symbol.toStringTag,{value:"Module"}));async function gle(e){if(Pz())throw new Error(`resolveLanguage("${e}") cannot be called from a worker context. Languages must be pre-resolved on the main thread and passed to the worker via the resolvedLanguages parameter.`);const t=tw.get(e);if(t!=null)return t;try{let n=Pre.get(e);if(n==null&&Object.prototype.hasOwnProperty.call(Fb,e)&&(n=Fb[e]),n==null)throw new Error(`resolveLanguage: "${e}" not found in bundled or custom languages`);const r=n().then(({default:i})=>{const s={name:e,data:i};return vp.has(e)||vp.set(e,s),s});return tw.set(e,r),await r}finally{tw.delete(e)}}function vle(e){return vp.get(e)??gle(e)}async function ble(e){if(Pz())throw new Error(`resolveTheme("${e}") cannot be called from a worker context. Themes must be pre-resolved on the main thread and passed to the worker via the resolvedLanguages parameter.`);const t=ew.get(e);if(t!=null)return t;try{const n=s1.get(e)??_E[e];if(n==null)throw new Error(`resolveTheme: No valid loader for ${e}`);const r=n().then(s=>yle(e,"default"in s?s.default:s));ew.set(e,r);const i=await r;if(i.name!==e)throw new Error(`resolvedTheme: themeName: ${e} does not match theme.name: ${i.name}`);return jc.set(i.name,i),i}finally{ew.delete(e)}}function yle(e,t){const n=jc.get(e);return n??(t=om(t),jc.set(e,t),t)}function xle(e){return jc.get(e)??ble(e)}function m8(e,t){if(s1.has(e)){console.error("SharedHighlight.registerCustomTheme: theme name already registered",e);return}s1.set(e,t)}let Co;async function _le({themes:e,langs:t,preferredHighlighter:n="shiki-js"}){Co??(Co=CE({themes:[],langs:["text"],engine:n==="shiki-wasm"?SE(K(()=>import("./wasm-CG6Dc4jp.js"),[])):p8()}));const r=Sle(Co)?await Co:Co;Co=r;const i=[];for(const o of t){if(o==="text"||o==="ansi")continue;const l=vle(o);"then"in l?i.push(l):iL(l,r)}const s=[];for(const o of e){const l=xle(o);"then"in l?s.push(l):rL(l,Co)}return(i.length>0||s.length>0)&&await Promise.all([Promise.all(i).then(o=>{iL(o,r)}),Promise.all(s).then(o=>{rL(o,r)})]),r}function wle(){if(Co!=null&&!("then"in Co))return Co}function Sle(e=Co){return e!=null&&"then"in e}m8("pierre-dark",async()=>{const{default:e}=await K(async()=>{const{default:t}=await import("./pierre-dark-DF2SEV7i.js");return{default:t}},[]);return{...e,name:"pierre-dark"}});m8("pierre-light",async()=>{const{default:e}=await K(async()=>{const{default:t}=await import("./pierre-light-DOlZxES8.js");return{default:t}},[]);return{...e,name:"pierre-light"}});function g8(e=To){const t=[];return typeof e=="string"?t.push(e):(t.push(e.dark),t.push(e.light)),t}function v8(e,t){return e==null||t==null||typeof e=="string"||typeof t=="string"?e===t:e.dark===t.dark&&e.light===t.light}const Wu=new Map,ph={"1c":"1c",abap:"abap",as:"actionscript-3",ada:"ada",adb:"ada",ads:"ada",adoc:"asciidoc",asciidoc:"asciidoc","component.html":"angular-html","component.ts":"angular-ts",conf:"nginx",htaccess:"apache",cls:"tex",trigger:"apex",apl:"apl",applescript:"applescript",scpt:"applescript",ara:"ara",asm:"asm",s:"riscv",astro:"astro",awk:"awk",bal:"ballerina",sh:"zsh",bash:"zsh",bat:"cmd",cmd:"cmd",be:"berry",beancount:"beancount",bib:"bibtex",bicep:"bicep","blade.php":"blade",bsl:"bsl",c:"c",h:"objective-cpp",cs:"csharp",cpp:"cpp",hpp:"cpp",cc:"cpp",cxx:"cpp",hh:"cpp",cdc:"cdc",cairo:"cairo",clar:"clarity",clj:"clojure",cljs:"clojure",cljc:"clojure",soy:"soy",cmake:"cmake","CMakeLists.txt":"cmake",cob:"cobol",cbl:"cobol",cobol:"cobol",CODEOWNERS:"codeowners",ql:"ql",coffee:"coffeescript",lisp:"lisp",cl:"lisp",lsp:"lisp",log:"log",v:"verilog",cql:"cql",cr:"crystal",css:"css",csv:"csv",cue:"cue",cypher:"cypher",cyp:"cypher",d:"d",dart:"dart",dax:"dax",desktop:"desktop",diff:"diff",patch:"diff",Dockerfile:"dockerfile",dockerfile:"dockerfile",env:"dotenv",dm:"dream-maker",edge:"edge",el:"emacs-lisp",ex:"elixir",exs:"elixir",elm:"elm",erb:"erb",erl:"erlang",hrl:"erlang",f:"fortran-fixed-form",for:"fortran-fixed-form",fs:"fsharp",fsi:"fsharp",fsx:"fsharp",f03:"f03",f08:"f08",f18:"f18",f77:"f77",f90:"fortran-free-form",f95:"fortran-free-form",fnl:"fennel",fish:"fish",ftl:"ftl",tres:"gdresource",res:"gdresource",gd:"gdscript",gdshader:"gdshader",gs:"genie",feature:"gherkin",COMMIT_EDITMSG:"git-commit","git-rebase-todo":"git-rebase",gjs:"glimmer-js",gleam:"gleam",gts:"glimmer-ts",glsl:"glsl",vert:"glsl",frag:"glsl",shader:"shaderlab",gp:"gnuplot",plt:"gnuplot",gnuplot:"gnuplot",go:"go",graphql:"graphql",gql:"graphql",groovy:"groovy",gvy:"groovy",hack:"hack",haml:"haml",hbs:"handlebars",handlebars:"handlebars",hs:"haskell",lhs:"haskell",hx:"haxe",hcl:"hcl",hjson:"hjson",hlsl:"hlsl",fx:"hlsl",html:"html",htm:"html",http:"http",rest:"http",hxml:"hxml",hy:"hy",imba:"imba",ini:"ini",cfg:"ini",jade:"pug",pug:"pug",java:"java",js:"javascript",mjs:"javascript",cjs:"javascript",jinja:"jinja",jinja2:"jinja",j2:"jinja",jison:"jison",jl:"julia",json:"json",json5:"json5",jsonc:"jsonc",jsonl:"jsonl",jsonnet:"jsonnet",libsonnet:"jsonnet",jssm:"jssm",jsx:"jsx",kt:"kotlin",kts:"kts",kql:"kusto",tex:"tex",ltx:"tex",lean:"lean4",less:"less",liquid:"liquid",lit:"lit",ll:"llvm",logo:"logo",lua:"lua",luau:"luau",Makefile:"makefile",mk:"makefile",makefile:"makefile",md:"markdown",markdown:"markdown",marko:"marko",m:"wolfram",mat:"matlab",mdc:"mdc",mdx:"mdx",wiki:"wikitext",mediawiki:"wikitext",mmd:"mermaid",mermaid:"mermaid",mips:"mipsasm",mojo:"mojo","🔥":"mojo",move:"move",nar:"narrat",nf:"nextflow",nim:"nim",nims:"nim",nimble:"nim",nix:"nix",nu:"nushell",mm:"objective-cpp",ml:"ocaml",mli:"ocaml",mll:"ocaml",mly:"ocaml",pas:"pascal",p:"pascal",pl:"prolog",pm:"perl",t:"perl",raku:"raku",p6:"raku",pl6:"raku",php:"php",phtml:"php",pls:"plsql",sql:"sql",po:"po",polar:"polar",pcss:"postcss",pot:"pot",potx:"potx",pq:"powerquery",pqm:"powerquery",ps1:"powershell",psm1:"powershell",psd1:"powershell",prisma:"prisma",pro:"prolog",P:"prolog",properties:"properties",proto:"protobuf",pp:"puppet",purs:"purescript",py:"python",pyw:"python",pyi:"python",qml:"qml",qmldir:"qmldir",qss:"qss",r:"r",R:"r",rkt:"racket",rktl:"racket",razor:"razor",cshtml:"razor",rb:"ruby",rbw:"ruby",reg:"reg",regex:"regexp",rel:"rel",rs:"rust",rst:"rst",rake:"ruby",gemspec:"ruby",sas:"sas",sass:"sass",scala:"scala",sc:"scala",scm:"scheme",ss:"scheme",sld:"scheme",scss:"scss",sdbl:"sdbl",shadergraph:"shader",st:"smalltalk",sol:"solidity",sparql:"sparql",rq:"sparql",spl:"splunk",config:"ssh-config",do:"stata",ado:"stata",dta:"stata",styl:"stylus",stylus:"stylus",svelte:"svelte",swift:"swift",sv:"system-verilog",svh:"system-verilog",service:"systemd",socket:"systemd",device:"systemd",timer:"systemd",talon:"talonscript",tasl:"tasl",tcl:"tcl",templ:"templ",tf:"tf",tfvars:"tfvars",toml:"toml",ts:"typescript",tsp:"typespec",tsv:"tsv",tsx:"tsx",ttl:"turtle",twig:"twig",typ:"typst",vv:"v",vala:"vala",vapi:"vala",vb:"vb",vbs:"vb",bas:"vb",vh:"verilog",vhd:"vhdl",vhdl:"vhdl",vim:"vimscript",vue:"vue","vine.ts":"vue-vine",vy:"vyper",wasm:"wasm",wat:"wasm",wy:"文言",wgsl:"wgsl",wit:"wit",wl:"wolfram",nb:"wolfram",xml:"xml",xsl:"xsl",xslt:"xsl",yaml:"yaml",yml:"yml",zs:"zenscript",zig:"zig",zsh:"zsh",sty:"tex"};function jd(e){var r;if(Wu.has(e))return Wu.get(e)??"text";if(ph[e]!=null)return ph[e];const t=e.match(/\.([^/\\]+\.[^/\\]+)$/);if(t!=null){if(Wu.has(t[1]))return Wu.get(t[1])??"text";if(ph[t[1]]!=null)return ph[t[1]]??"text"}const n=((r=e.match(/\.([^.]+)$/))==null?void 0:r[1])??"";return Wu.has(n)?Wu.get(n)??"text":ph[n]??"text"}function Dd(e){return e.replace(/\n$|\r\n$/,"")}function Ca(e){return{type:"text",value:e}}function Yt({tagName:e,children:t=[],properties:n={}}){return{type:"element",tagName:e,properties:n,children:t}}function Hb({name:e,width:t=16,height:n=16,properties:r}){return Yt({tagName:"svg",properties:{width:t,height:n,viewBox:"0 0 16 16",...r},children:[Yt({tagName:"use",properties:{href:`#${e.replace(/^#/,"")}`}})]})}function Cle(e){let t=e.children[0];for(;t!=null;){if(t.type==="element"&&t.tagName==="code")return t;"children"in t?t=t.children[0]:t=null}}function Zg(e){return Yt({tagName:"div",properties:{"data-gutter":""},children:e})}function kle(e,t,n,r={}){return Yt({tagName:"div",properties:{"data-line-type":e,"data-column-number":t,"data-line-index":n,...r},children:t!=null?[Yt({tagName:"span",properties:{"data-line-number-content":""},children:[Ca(`${t}`)]})]:void 0})}function Vs(e,t,n){return Yt({tagName:"div",properties:{"data-gutter-buffer":t,"data-buffer-size":n,"data-line-type":t==="annotation"?void 0:e,style:t==="annotation"?`grid-row: span ${n};`:`grid-row: span ${n};min-height:calc(${n} * 1lh);`}})}function Ele(e,t,n){const r=typeof n.lineInfo=="function"?n.lineInfo(t):n.lineInfo[t-1];if(r==null){const i=`processLine: line ${t}, contains no state.lineInfo`;throw console.error(i,{node:e,line:t,state:n}),new Error(i)}return e.tagName="div",e.properties["data-line"]=r.lineNumber,e.properties["data-alt-line"]=r.altLineNumber,e.properties["data-line-type"]=r.type,e.properties["data-line-index"]=r.lineIndex,e.children.length===0&&e.children.push(Ca(`
862
862
  `)),e}const Jg=Symbol("no-token"),vw=Symbol("multiple-tokens");function b8(e){const t=Tle(e);if(t!=null)return t;let n=Jg;const r=[];let i=[],s;const o=()=>{if(i.length===0||s==null){i=[],s=void 0;return}if(i.length===1){const c=i[0];if((c==null?void 0:c.type)==="element"){Rle(c,s);for(const u of c.children)Kv(u)}else Kv(c);r.push(c),i=[],s=void 0;return}for(const c of i)Kv(c);r.push(Yt({tagName:"span",properties:{"data-char":s},children:i})),i=[],s=void 0},l=c=>{if(c!==Jg){if(c===vw){n=vw;return}if(n===Jg){n=c;return}n!==c&&(n=vw)}};for(const c of e.children){const u=c.type==="element"?b8(c):Jg;if(l(u),typeof u!="number"){o(),r.push(c);continue}s!=null&&s!==u&&o(),s??(s=u),i.push(c)}return o(),e.children=r,n}function Tle(e){const t=e.properties["data-char"];if(typeof t=="number")return t}function Kv(e){if(e.type==="element"){e.properties["data-char"]=void 0;for(const t of e.children)Kv(t)}}function Rle(e,t){e.properties["data-char"]=t}function Nle(e={}){const{classPrefix:t="__shiki_",classSuffix:n="",classReplacer:r=l=>l}=e,i=new Map;function s(l){return Object.entries(l).map(([c,u])=>`${c}:${u}`).join(";")}function o(l){const c=typeof l=="string"?l:s(l);let u=t+Ale(c)+n;return u=r(u),i.has(u)||i.set(u,typeof l=="string"?l:{...l}),u}return{name:"@shikijs/transformers:style-to-class",pre(l){if(!l.properties.style)return;const c=o(l.properties.style);delete l.properties.style,this.addClassToHast(l,c)},tokens(l){for(const c of l)for(const u of c){if(!u.htmlStyle)continue;const p=o(u.htmlStyle);u.htmlStyle={},u.htmlAttrs||(u.htmlAttrs={}),u.htmlAttrs.class?u.htmlAttrs.class+=` ${p}`:u.htmlAttrs.class=p}},getClassRegistry(){return i},getCSS(){let l="";for(const[c,u]of i.entries())l+=`.${c}{${typeof u=="string"?u:s(u)}}`;return l},clearRegistry(){i.clear()}}}function Ale(e,t=0){let n=3735928559^t,r=1103547991^t;for(let i=0,s;i<e.length;i++)s=e.charCodeAt(i),n=Math.imul(n^s,2654435761),r=Math.imul(r^s,1597334677);return n=Math.imul(n^n>>>16,2246822507),n^=Math.imul(r^r>>>13,3266489909),r=Math.imul(r^r>>>16,2246822507),r^=Math.imul(n^n>>>13,3266489909),(4294967296*(2097151&r)+(n>>>0)).toString(36).slice(0,6)}function Mle(e=!1,t=!1){const n={lineInfo:[]},r=[{line(i){return delete i.properties.class,i},pre(i){const s=Cle(i),o=[];if(s!=null){let l=1;for(const c of s.children)c.type==="element"&&(e&&b8(c),o.push(Ele(c,l,n)),l++);s.children=o}return i},...e?{tokens(i){for(const s of i){let o=0;for(const l of s){const c=l;c.__lineChar??(c.__lineChar=o),o+=l.content.length}}},preprocess(i,s){s.mergeWhitespaces="never"},span(i,s,o,l,c){if((c==null?void 0:c.offset)!=null&&c.content!=null){const u=c.__lineChar;return u!=null&&(i.properties["data-char"]=u),i}return i}}:null}];return t&&r.push(Lle,GL),{state:n,transformers:r,toClass:GL}}const GL=Nle({classPrefix:"hl-"}),Lle={name:"token-style-normalizer",tokens(e){for(const t of e)for(const n of t){if(n.htmlStyle!=null)continue;const r={};n.color!=null&&(r.color=n.color),n.bgColor!=null&&(r["background-color"]=n.bgColor),n.fontStyle!=null&&n.fontStyle!==0&&((n.fontStyle&1)!==0&&(r["font-style"]="italic"),(n.fontStyle&2)!==0&&(r["font-weight"]="bold"),(n.fontStyle&4)!==0&&(r["text-decoration"]="underline")),Object.keys(r).length>0&&(n.htmlStyle=r)}}};function Gs(e){return`--${e==="token"?"diffs-token":"diffs"}-`}function jle({theme:e=To,highlighter:t,prefix:n}){let r="";if(typeof e=="string"){const i=t.getTheme(e);r+=`color:${i.fg};`,r+=`background-color:${i.bg};`,r+=`${Gs("global")}fg:${i.fg};`,r+=`${Gs("global")}bg:${i.bg};`,r+=bw(i,n)}else{let i=t.getTheme(e.dark);r+=`${Gs("global")}dark:${i.fg};`,r+=`${Gs("global")}dark-bg:${i.bg};`,r+=bw(i,"dark"),i=t.getTheme(e.light),r+=`${Gs("global")}light:${i.fg};`,r+=`${Gs("global")}light-bg:${i.bg};`,r+=bw(i,"light")}return r}function bw(e,t){var o,l,c,u,p,h;t=t!=null?`${t}-`:"";let n="";const r=((o=e.colors)==null?void 0:o["gitDecoration.addedResourceForeground"])??((l=e.colors)==null?void 0:l["terminal.ansiGreen"]);r!=null&&(n+=`${Gs("global")}${t}addition-color:${r};`);const i=((c=e.colors)==null?void 0:c["gitDecoration.deletedResourceForeground"])??((u=e.colors)==null?void 0:u["terminal.ansiRed"]);i!=null&&(n+=`${Gs("global")}${t}deletion-color:${i};`);const s=((p=e.colors)==null?void 0:p["gitDecoration.modifiedResourceForeground"])??((h=e.colors)==null?void 0:h["terminal.ansiBlue"]);return s!=null&&(n+=`${Gs("global")}${t}modified-color:${s};`),n}function qL(e){let t=e.children[0];for(;t!=null;){if(t.type==="element"&&t.tagName==="code")return t.children;"children"in t?t=t.children[0]:t=null}throw console.error(e),new Error("getLineNodes: Unable to find children")}function KL(e,t){return(e==null?void 0:e.cacheKey)===(t==null?void 0:t.cacheKey)&&(e==null?void 0:e.contents)===(t==null?void 0:t.contents)&&(e==null?void 0:e.name)===(t==null?void 0:t.name)&&(e==null?void 0:e.lang)===(t==null?void 0:t.lang)}function yw(e,t){return v8(e.theme,t.theme)&&e.useTokenTransformer===t.useTokenTransformer&&e.tokenizeMaxLineLength===t.tokenizeMaxLineLength&&e.lineDiffType===t.lineDiffType&&e.maxLineDiffLength===t.maxLineDiffLength}function Dle(e){const t=e.lang??jd(e.name),n=e.lang??(e.prevName!=null?jd(e.prevName):"text");return t==="text"&&n==="text"}function Ub({diff:e,diffStyle:t,startingLine:n=0,totalLines:r=1/0,expandedHunks:i,collapsedContextThreshold:s=bd,callback:o}){const l={finalHunk:e.hunks.at(-1),viewportStart:n,viewportEnd:n+r,isWindowedHighlight:n>0||r<1/0,splitCount:0,unifiedCount:0,shouldBreak(){if(!l.isWindowedHighlight)return!1;const c=l.unifiedCount>=n+r,u=l.splitCount>=n+r;return t==="unified"?c:(t==="split"||c)&&u},shouldSkip(c,u){if(!l.isWindowedHighlight)return!1;const p=l.unifiedCount+c<n,h=l.splitCount+u<n;return t==="unified"?p:(t==="split"||p)&&h},incrementCounts(c,u){(t==="unified"||t==="both")&&(l.unifiedCount+=c),(t==="split"||t==="both")&&(l.splitCount+=u)},isInWindow(c,u){if(!l.isWindowedHighlight)return!0;const p=l.isInUnifiedWindow(c),h=l.isInSplitWindow(u);return t==="unified"?p:t==="split"?h:p||h},isInUnifiedWindow(c){return!l.isWindowedHighlight||l.unifiedCount>=n-c&&l.unifiedCount<n+r},isInSplitWindow(c){return!l.isWindowedHighlight||l.splitCount>=n-c&&l.splitCount<n+r},emit(c,u=!1){return u||(t==="unified"?l.incrementCounts(1,0):t==="split"?l.incrementCounts(0,1):l.incrementCounts(1,1)),o(c)??!1}};e:for(const[c,u]of e.hunks.entries()){let b=function(A,M){return h==null||h.collapsedLines<=0||h.fromStart+h.fromEnd>0?0:t==="unified"?A===u.unifiedLineStart+u.unifiedLineCount-1?h.collapsedLines:0:M===u.splitLineStart+u.splitLineCount-1?h.collapsedLines:0},x=function(){if(p.collapsedLines===0)return 0;const A=p.collapsedLines;return p.collapsedLines=0,A};if(l.shouldBreak())break;const p=YL(e.isPartial,u.collapsedBefore,i,c,s),h=(()=>{if(u!==l.finalHunk||!Ile(e))return;const A=e.additionLines.length-(u.additionLineIndex+u.additionCount),M=e.deletionLines.length-(u.deletionLineIndex+u.deletionCount);if(A!==M)throw new Error(`iterateOverDiff: trailing context mismatch (additions=${A}, deletions=${M}) for ${e.name}`);const D=Math.min(A,M);return YL(e.isPartial,D,i,e.hunks.length,s)})(),g=p.fromStart+p.fromEnd;if(l.shouldSkip(g,g))l.incrementCounts(g,g),x();else{let A=u.unifiedLineStart-p.rangeSize,M=u.splitLineStart-p.rangeSize,D=u.deletionLineIndex-p.rangeSize,U=u.additionLineIndex-p.rangeSize,j=u.deletionStart-p.rangeSize,P=u.additionStart-p.rangeSize,z=0;for(;z<p.fromStart;){if(l.isInWindow(0,0)){if(l.emit({hunkIndex:c,hunk:u,collapsedBefore:0,collapsedAfter:0,type:"context-expanded",deletionLine:{lineNumber:j+z,lineIndex:D+z,noEOFCR:!1,unifiedLineIndex:A+z,splitLineIndex:M+z},additionLine:{unifiedLineIndex:A+z,splitLineIndex:M+z,lineIndex:U+z,lineNumber:P+z,noEOFCR:!1}}))break e}else l.incrementCounts(1,1);z++}for(A=u.unifiedLineStart-p.fromEnd,M=u.splitLineStart-p.fromEnd,D=u.deletionLineIndex-p.fromEnd,U=u.additionLineIndex-p.fromEnd,j=u.deletionStart-p.fromEnd,P=u.additionStart-p.fromEnd,z=0;z<p.fromEnd;){if(l.isInWindow(0,0)){if(l.emit({hunkIndex:c,hunk:u,collapsedBefore:x(),collapsedAfter:0,type:"context-expanded",deletionLine:{lineNumber:j+z,lineIndex:D+z,noEOFCR:!1,unifiedLineIndex:A+z,splitLineIndex:M+z},additionLine:{unifiedLineIndex:A+z,splitLineIndex:M+z,lineIndex:U+z,lineNumber:P+z,noEOFCR:!1}}))break e}else l.incrementCounts(1,1);z++}}let _=u.unifiedLineStart,w=u.splitLineStart,C=u.deletionLineIndex,E=u.additionLineIndex,k=u.deletionStart,R=u.additionStart;const N=u.hunkContent.at(-1);for(const A of u.hunkContent){if(l.shouldBreak())break e;const M=A===N;if(A.type==="context"){if(l.shouldSkip(A.lines,A.lines))l.incrementCounts(A.lines,A.lines),x();else{let D=0;for(;D<A.lines;){if(l.isInWindow(0,0)){const U=M&&D===A.lines-1,j=_+D,P=w+D;if(l.emit({hunkIndex:c,hunk:u,collapsedBefore:x(),collapsedAfter:b(j,P),type:"context",deletionLine:{lineNumber:k+D,lineIndex:C+D,noEOFCR:U&&u.noEOFCRDeletions,unifiedLineIndex:j,splitLineIndex:P},additionLine:{unifiedLineIndex:j,splitLineIndex:P,lineIndex:E+D,lineNumber:R+D,noEOFCR:U&&u.noEOFCRAdditions}}))break e}else l.incrementCounts(1,1);D++}}_+=A.lines,w+=A.lines,C+=A.lines,E+=A.lines,k+=A.lines,R+=A.lines}else{const D=Math.max(A.deletions,A.additions),U=A.deletions+A.additions;if(!l.shouldSkip(U,D)){const j=Ple(l,A,t);for(const[P,z]of j)for(let O=P;O<z;O++){const $=b(_+O,t==="unified"?w+(O<A.deletions?O:O-A.deletions):w+O);if(l.emit(Ole({hunkIndex:c,hunk:u,collapsedBefore:x(),collapsedAfter:$,diffStyle:t,index:O,unifiedLineIndex:_,splitLineIndex:w,additionLineIndex:E,deletionLineIndex:C,additionLineNumber:R,deletionLineNumber:k,content:A,isLastContent:M,unifiedCount:U,splitCount:D}),!0))break e}}x(),l.incrementCounts(U,D),_+=U,w+=D,C+=A.deletions,E+=A.additions,k+=A.deletions,R+=A.additions}}if(h!=null){const{collapsedLines:A,fromStart:M,fromEnd:D}=h,U=M+D;let j=0;for(;j<U;){if(l.shouldBreak())break e;if(l.isInWindow(0,0)){const P=j===U-1;if(l.emit({hunkIndex:e.hunks.length,hunk:void 0,collapsedBefore:0,collapsedAfter:P?A:0,type:"context-expanded",deletionLine:{lineNumber:k+j,lineIndex:C+j,noEOFCR:!1,unifiedLineIndex:_+j,splitLineIndex:w+j},additionLine:{unifiedLineIndex:_+j,splitLineIndex:w+j,lineIndex:E+j,lineNumber:R+j,noEOFCR:!1}}))break e}else l.incrementCounts(1,1);j++}}}}function YL(e,t,n,r,i){if(t=Math.max(t,0),t===0||e)return{fromStart:0,fromEnd:0,rangeSize:t,collapsedLines:Math.max(t,0)};if(n===!0||t<=i)return{fromStart:t,fromEnd:0,rangeSize:t,collapsedLines:0};const s=n==null?void 0:n.get(r),o=Math.min(Math.max((s==null?void 0:s.fromStart)??0,0),t),l=Math.min(Math.max((s==null?void 0:s.fromEnd)??0,0),t),c=o+l,u=c>=t;return{fromStart:u?t:o,fromEnd:u?0:l,rangeSize:t,collapsedLines:Math.max(t-c,0)}}function Ile(e){const t=e.hunks.at(-1);return t==null||e.isPartial||e.additionLines.length===0||e.deletionLines.length===0?!1:t.additionLineIndex+t.additionCount<e.additionLines.length||t.deletionLineIndex+t.deletionCount<e.deletionLines.length}function Ple(e,t,n){if(!e.isWindowedHighlight)return[[0,n==="unified"?t.deletions+t.additions:Math.max(t.deletions,t.additions)]];const r=n!=="split",i=n!=="unified",s=n==="unified"?"unified":"split",o=[];function l(h,g){if(h+g<=e.viewportStart||h>=e.viewportEnd)return;const b=Math.max(0,e.viewportStart-h),x=Math.min(g,e.viewportEnd-h);return x>b?[b,x]:void 0}function c(h,g){return s==="split"?h:g==="additions"?[h[0]+t.deletions,h[1]+t.deletions]:h}function u(h,g){if(h==null)return;const[b,x]=c(h,g);x>b&&o.push([b,x])}if(r&&(u(l(e.unifiedCount,t.deletions),"deletions"),u(l(e.unifiedCount+t.deletions,t.additions),"additions")),i&&(u(l(e.splitCount,t.deletions),"deletions"),u(l(e.splitCount,t.additions),"additions")),o.length===0)return o;o.sort((h,g)=>h[0]-g[0]);const p=[o[0]];for(const[h,g]of o.slice(1)){const b=p[p.length-1];h<=b[1]?b[1]=Math.max(b[1],g):p.push([h,g])}return p}function Ole({hunkIndex:e,hunk:t,collapsedAfter:n,collapsedBefore:r,diffStyle:i,index:s,unifiedLineIndex:o,splitLineIndex:l,additionLineIndex:c,deletionLineIndex:u,additionLineNumber:p,deletionLineNumber:h,content:g,isLastContent:b,unifiedCount:x,splitCount:_}){const w=s<g.deletions?o+s:void 0,C=i==="unified"?s>=g.deletions?o+s:void 0:s<g.additions?o+g.deletions+s:void 0,E=i==="unified"?l+(s<g.deletions?s:s-g.deletions):l+s,k=s<g.deletions?u+s:void 0,R=s<g.deletions?h+s:void 0,N=i==="unified"?s>=g.deletions?c+(s-g.deletions):void 0:s<g.additions?c+s:void 0,A=i==="unified"?s>=g.deletions?p+(s-g.deletions):void 0:s<g.additions?p+s:void 0,M=i==="unified"?b&&s===g.deletions-1&&t.noEOFCRDeletions:b&&s===_-1&&t.noEOFCRDeletions,D=i==="unified"?b&&s===x-1&&t.noEOFCRAdditions:b&&s===_-1&&t.noEOFCRAdditions,U=k!=null&&R!=null&&w!=null?{lineNumber:R,lineIndex:k,noEOFCR:M,unifiedLineIndex:w,splitLineIndex:E}:void 0,j=N!=null&&A!=null&&C!=null?{unifiedLineIndex:C,splitLineIndex:E,lineIndex:N,lineNumber:A,noEOFCR:D}:void 0;if(U==null&&j!=null)return{type:"change",hunkIndex:e,hunk:t,collapsedAfter:n,collapsedBefore:r,deletionLine:void 0,additionLine:j};if(U!=null&&j==null)return{type:"change",hunkIndex:e,hunk:t,collapsedAfter:n,collapsedBefore:r,deletionLine:U,additionLine:void 0};if(U==null||j==null)throw new Error("iterateOverDiff: missing change line data");return{type:"change",hunkIndex:e,hunk:t,collapsedAfter:n,collapsedBefore:r,deletionLine:U,additionLine:j}}class AE{diff(t,n,r={}){let i;typeof r=="function"?(i=r,r={}):"callback"in r&&(i=r.callback);const s=this.castInput(t,r),o=this.castInput(n,r),l=this.removeEmpty(this.tokenize(s,r)),c=this.removeEmpty(this.tokenize(o,r));return this.diffWithOptionsObj(l,c,r,i)}diffWithOptionsObj(t,n,r,i){var s;const o=E=>{if(E=this.postProcess(E,r),i){setTimeout(function(){i(E)},0);return}else return E},l=n.length,c=t.length;let u=1,p=l+c;r.maxEditLength!=null&&(p=Math.min(p,r.maxEditLength));const h=(s=r.timeout)!==null&&s!==void 0?s:1/0,g=Date.now()+h,b=[{oldPos:-1,lastComponent:void 0}];let x=this.extractCommon(b[0],n,t,0,r);if(b[0].oldPos+1>=c&&x+1>=l)return o(this.buildValues(b[0].lastComponent,n,t));let _=-1/0,w=1/0;const C=()=>{for(let E=Math.max(_,-u);E<=Math.min(w,u);E+=2){let k;const R=b[E-1],N=b[E+1];R&&(b[E-1]=void 0);let A=!1;if(N){const D=N.oldPos-E;A=N&&0<=D&&D<l}const M=R&&R.oldPos+1<c;if(!A&&!M){b[E]=void 0;continue}if(!M||A&&R.oldPos<N.oldPos?k=this.addToPath(N,!0,!1,0,r):k=this.addToPath(R,!1,!0,1,r),x=this.extractCommon(k,n,t,E,r),k.oldPos+1>=c&&x+1>=l)return o(this.buildValues(k.lastComponent,n,t))||!0;b[E]=k,k.oldPos+1>=c&&(w=Math.min(w,E-1)),x+1>=l&&(_=Math.max(_,E+1))}u++};if(i)(function E(){setTimeout(function(){if(u>p||Date.now()>g)return i(void 0);C()||E()},0)})();else for(;u<=p&&Date.now()<=g;){const E=C();if(E)return E}}addToPath(t,n,r,i,s){const o=t.lastComponent;return o&&!s.oneChangePerToken&&o.added===n&&o.removed===r?{oldPos:t.oldPos+i,lastComponent:{count:o.count+1,added:n,removed:r,previousComponent:o.previousComponent}}:{oldPos:t.oldPos+i,lastComponent:{count:1,added:n,removed:r,previousComponent:o}}}extractCommon(t,n,r,i,s){const o=n.length,l=r.length;let c=t.oldPos,u=c-i,p=0;for(;u+1<o&&c+1<l&&this.equals(r[c+1],n[u+1],s);)u++,c++,p++,s.oneChangePerToken&&(t.lastComponent={count:1,previousComponent:t.lastComponent,added:!1,removed:!1});return p&&!s.oneChangePerToken&&(t.lastComponent={count:p,previousComponent:t.lastComponent,added:!1,removed:!1}),t.oldPos=c,u}equals(t,n,r){return r.comparator?r.comparator(t,n):t===n||!!r.ignoreCase&&t.toLowerCase()===n.toLowerCase()}removeEmpty(t){const n=[];for(let r=0;r<t.length;r++)t[r]&&n.push(t[r]);return n}castInput(t,n){return t}tokenize(t,n){return Array.from(t)}join(t){return t.join("")}postProcess(t,n){return t}get useLongestToken(){return!1}buildValues(t,n,r){const i=[];let s;for(;t;)i.push(t),s=t.previousComponent,delete t.previousComponent,t=s;i.reverse();const o=i.length;let l=0,c=0,u=0;for(;l<o;l++){const p=i[l];if(p.removed)p.value=this.join(r.slice(u,u+p.count)),u+=p.count;else{if(!p.added&&this.useLongestToken){let h=n.slice(c,c+p.count);h=h.map(function(g,b){const x=r[u+b];return x.length>g.length?x:g}),p.value=this.join(h)}else p.value=this.join(n.slice(c,c+p.count));c+=p.count,p.added||(u+=p.count)}}return i}}class zle extends AE{}const Ble=new zle;function Fle(e,t,n){return Ble.diff(e,t,n)}const XL="a-zA-Z0-9_\\u{AD}\\u{C0}-\\u{D6}\\u{D8}-\\u{F6}\\u{F8}-\\u{2C6}\\u{2C8}-\\u{2D7}\\u{2DE}-\\u{2FF}\\u{1E00}-\\u{1EFF}";class $le extends AE{tokenize(t){const n=new RegExp(`(\\r?\\n)|[${XL}]+|[^\\S\\n\\r]+|[^${XL}]`,"ug");return t.match(n)||[]}}const Hle=new $le;function Ule(e,t,n){return Hle.diff(e,t,n)}class Vle extends AE{constructor(){super(...arguments),this.tokenize=Gle}equals(t,n,r){return r.ignoreWhitespace?((!r.newlineIsToken||!t.includes(`
863
863
  `))&&(t=t.trim()),(!r.newlineIsToken||!n.includes(`
864
864
  `))&&(n=n.trim())):r.ignoreNewlineAtEof&&!r.newlineIsToken&&(t.endsWith(`
@@ -2602,7 +2602,7 @@ XID_Start XIDS`.split(/\s/).map(e=>[Zy(e),e])),Iae=new Map([["s",Sr(383)],[Sr(38
2602
2602
  `});++r<e.length;)r&&n.push({type:"text",value:`
2603
2603
  `}),n.push(e[r]);return t&&e.length>0&&n.push({type:"text",value:`
2604
2604
  `}),n}function Yj(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function Xj(e,t){const n=age(e,t),r=n.one(e,void 0),i=sge(n),s=Array.isArray(r)?{type:"root",children:r}:r||{type:"root",children:[]};return i&&s.children.push({type:"text",value:`
2605
- `},i),s}function fge(e,t){return e&&"run"in e?async function(n,r){const i=Xj(n,{file:r,...t});await e.run(i,r)}:function(n,r){return Xj(n,{file:r,...e||t})}}function Qj(e){if(e)throw e}var Pw,Zj;function hge(){if(Zj)return Pw;Zj=1;var e=Object.prototype.hasOwnProperty,t=Object.prototype.toString,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=function(u){return typeof Array.isArray=="function"?Array.isArray(u):t.call(u)==="[object Array]"},s=function(u){if(!u||t.call(u)!=="[object Object]")return!1;var p=e.call(u,"constructor"),h=u.constructor&&u.constructor.prototype&&e.call(u.constructor.prototype,"isPrototypeOf");if(u.constructor&&!p&&!h)return!1;var g;for(g in u);return typeof g>"u"||e.call(u,g)},o=function(u,p){n&&p.name==="__proto__"?n(u,p.name,{enumerable:!0,configurable:!0,value:p.newValue,writable:!0}):u[p.name]=p.newValue},l=function(u,p){if(p==="__proto__")if(e.call(u,p)){if(r)return r(u,p).value}else return;return u[p]};return Pw=function c(){var u,p,h,g,b,x,_=arguments[0],w=1,C=arguments.length,E=!1;for(typeof _=="boolean"&&(E=_,_=arguments[1]||{},w=2),(_==null||typeof _!="object"&&typeof _!="function")&&(_={});w<C;++w)if(u=arguments[w],u!=null)for(p in u)h=l(_,p),g=l(u,p),_!==g&&(E&&g&&(s(g)||(b=i(g)))?(b?(b=!1,x=h&&i(h)?h:[]):x=h&&s(h)?h:{},o(_,{name:p,newValue:c(E,x,g)})):typeof g<"u"&&o(_,{name:p,newValue:g}));return _},Pw}var pge=hge();const Ow=cy(pge);function z1(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function mge(){const e=[],t={run:n,use:r};return t;function n(...i){let s=-1;const o=i.pop();if(typeof o!="function")throw new TypeError("Expected function as last argument, not "+o);l(null,...i);function l(c,...u){const p=e[++s];let h=-1;if(c){o(c);return}for(;++h<i.length;)(u[h]===null||u[h]===void 0)&&(u[h]=i[h]);i=u,p?gge(p,l)(...u):o(null,...u)}}function r(i){if(typeof i!="function")throw new TypeError("Expected `middelware` to be a function, not "+i);return e.push(i),t}}function gge(e,t){let n;return r;function r(...o){const l=e.length>o.length;let c;l&&o.push(i);try{c=e.apply(this,o)}catch(u){const p=u;if(l&&n)throw p;return i(p)}l||(c&&c.then&&typeof c.then=="function"?c.then(s,i):c instanceof Error?i(c):s(c))}function i(o,...l){n||(n=!0,t(o,...l))}function s(o){i(null,o)}}const wo={basename:vge,dirname:bge,extname:yge,join:xge,sep:"/"};function vge(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');cm(e);let n=0,r=-1,i=e.length,s;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(s){n=i+1;break}}else r<0&&(s=!0,r=i+1);return r<0?"":e.slice(n,r)}if(t===e)return"";let o=-1,l=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(s){n=i+1;break}}else o<0&&(s=!0,o=i+1),l>-1&&(e.codePointAt(i)===t.codePointAt(l--)?l<0&&(r=i):(l=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function bge(e){if(cm(e),e.length===0)return".";let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||(r=!0);return t<0?e.codePointAt(0)===47?"/":".":t===1&&e.codePointAt(0)===47?"//":e.slice(0,t)}function yge(e){cm(e);let t=e.length,n=-1,r=0,i=-1,s=0,o;for(;t--;){const l=e.codePointAt(t);if(l===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),l===46?i<0?i=t:s!==1&&(s=1):i>-1&&(s=-1)}return i<0||n<0||s===0||s===1&&i===n-1&&i===r+1?"":e.slice(i,n)}function xge(...e){let t=-1,n;for(;++t<e.length;)cm(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":_ge(n)}function _ge(e){cm(e);const t=e.codePointAt(0)===47;let n=wge(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function wge(e,t){let n="",r=0,i=-1,s=0,o=-1,l,c;for(;++o<=e.length;){if(o<e.length)l=e.codePointAt(o);else{if(l===47)break;l=47}if(l===47){if(!(i===o-1||s===1))if(i!==o-1&&s===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(c=n.lastIndexOf("/"),c!==n.length-1){c<0?(n="",r=0):(n=n.slice(0,c),r=n.length-1-n.lastIndexOf("/")),i=o,s=0;continue}}else if(n.length>0){n="",r=0,i=o,s=0;continue}}t&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,s=0}else l===46&&s>-1?s++:s=-1}return n}function cm(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const Sge={cwd:Cge};function Cge(){return"/"}function B1(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function kge(e){if(typeof e=="string")e=new URL(e);else if(!B1(e)){const t=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code="ERR_INVALID_ARG_TYPE",t}if(e.protocol!=="file:"){const t=new TypeError("The URL must be of scheme file");throw t.code="ERR_INVALID_URL_SCHEME",t}return Ege(e)}function Ege(e){if(e.hostname!==""){const r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}const t=e.pathname;let n=-1;for(;++n<t.length;)if(t.codePointAt(n)===37&&t.codePointAt(n+1)===50){const r=t.codePointAt(n+2);if(r===70||r===102){const i=new TypeError("File URL path must not include encoded / characters");throw i.code="ERR_INVALID_FILE_URL_PATH",i}}return decodeURIComponent(t)}const zw=["history","path","basename","stem","extname","dirname"];class TB{constructor(t){let n;t?B1(t)?n={path:t}:typeof t=="string"||Tge(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":Sge.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<zw.length;){const s=zw[r];s in n&&n[s]!==void 0&&n[s]!==null&&(this[s]=s==="history"?[...n[s]]:n[s])}let i;for(i in n)zw.includes(i)||(this[i]=n[i])}get basename(){return typeof this.path=="string"?wo.basename(this.path):void 0}set basename(t){Fw(t,"basename"),Bw(t,"basename"),this.path=wo.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?wo.dirname(this.path):void 0}set dirname(t){Jj(this.basename,"dirname"),this.path=wo.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?wo.extname(this.path):void 0}set extname(t){if(Bw(t,"extname"),Jj(this.dirname,"extname"),t){if(t.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(t.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=wo.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){B1(t)&&(t=kge(t)),Fw(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?wo.basename(this.path,this.extname):void 0}set stem(t){Fw(t,"stem"),Bw(t,"stem"),this.path=wo.join(this.dirname||"",t+(this.extname||""))}fail(t,n,r){const i=this.message(t,n,r);throw i.fatal=!0,i}info(t,n,r){const i=this.message(t,n,r);return i.fatal=void 0,i}message(t,n,r){const i=new oi(t,n,r);return this.path&&(i.name=this.path+":"+i.name,i.file=this.path),i.fatal=!1,this.messages.push(i),i}toString(t){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(t||void 0).decode(this.value)}}function Bw(e,t){if(e&&e.includes(wo.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+wo.sep+"`")}function Fw(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function Jj(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function Tge(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Rge=(function(e){const r=this.constructor.prototype,i=r[e],s=function(){return i.apply(s,arguments)};return Object.setPrototypeOf(s,r),s}),Nge={}.hasOwnProperty;class KE extends Rge{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=mge()}copy(){const t=new KE;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];t.use(...r)}return t.data(Ow(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(Uw("data",this.frozen),this.namespace[t]=n,this):Nge.call(this.namespace,t)&&this.namespace[t]||void 0:t?(Uw("data",this.frozen),this.namespace=t,this):this.namespace}freeze(){if(this.frozen)return this;const t=this;for(;++this.freezeIndex<this.attachers.length;){const[n,...r]=this.attachers[this.freezeIndex];if(r[0]===!1)continue;r[0]===!0&&(r[0]=void 0);const i=n.call(t,...r);typeof i=="function"&&this.transformers.use(i)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(t){this.freeze();const n=uv(t),r=this.parser||this.Parser;return $w("parse",r),r(String(n),n)}process(t,n){const r=this;return this.freeze(),$w("process",this.parser||this.Parser),Hw("process",this.compiler||this.Compiler),n?i(void 0,n):new Promise(i);function i(s,o){const l=uv(t),c=r.parse(l);r.run(c,l,function(p,h,g){if(p||!h||!g)return u(p);const b=h,x=r.stringify(b,g);Lge(x)?g.value=x:g.result=x,u(p,g)});function u(p,h){p||!h?o(p):s?s(h):n(void 0,h)}}}processSync(t){let n=!1,r;return this.freeze(),$w("processSync",this.parser||this.Parser),Hw("processSync",this.compiler||this.Compiler),this.process(t,i),tD("processSync","process",n),r;function i(s,o){n=!0,Qj(s),r=o}}run(t,n,r){eD(t),this.freeze();const i=this.transformers;return!r&&typeof n=="function"&&(r=n,n=void 0),r?s(void 0,r):new Promise(s);function s(o,l){const c=uv(n);i.run(t,c,u);function u(p,h,g){const b=h||t;p?l(p):o?o(b):r(void 0,b,g)}}}runSync(t,n){let r=!1,i;return this.run(t,n,s),tD("runSync","run",r),i;function s(o,l){Qj(o),i=l,r=!0}}stringify(t,n){this.freeze();const r=uv(n),i=this.compiler||this.Compiler;return Hw("stringify",i),eD(t),i(t,r)}use(t,...n){const r=this.attachers,i=this.namespace;if(Uw("use",this.frozen),t!=null)if(typeof t=="function")c(t,n);else if(typeof t=="object")Array.isArray(t)?l(t):o(t);else throw new TypeError("Expected usable value, not `"+t+"`");return this;function s(u){if(typeof u=="function")c(u,[]);else if(typeof u=="object")if(Array.isArray(u)){const[p,...h]=u;c(p,h)}else o(u);else throw new TypeError("Expected usable value, not `"+u+"`")}function o(u){if(!("plugins"in u)&&!("settings"in u))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");l(u.plugins),u.settings&&(i.settings=Ow(!0,i.settings,u.settings))}function l(u){let p=-1;if(u!=null)if(Array.isArray(u))for(;++p<u.length;){const h=u[p];s(h)}else throw new TypeError("Expected a list of plugins, not `"+u+"`")}function c(u,p){let h=-1,g=-1;for(;++h<r.length;)if(r[h][0]===u){g=h;break}if(g===-1)r.push([u,...p]);else if(p.length>0){let[b,...x]=p;const _=r[g][1];z1(_)&&z1(b)&&(b=Ow(!0,_,b)),r[g]=[u,b,...x]}}}}const Age=new KE().freeze();function $w(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function Hw(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function Uw(e,t){if(t)throw new Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function eD(e){if(!z1(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function tD(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function uv(e){return Mge(e)?e:new TB(e)}function Mge(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function Lge(e){return typeof e=="string"||jge(e)}function jge(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Dge="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",nD=[],rD={allowDangerousHtml:!0},Ige=/^(https?|ircs?|mailto|xmpp)$/i,Pge=[{from:"astPlugins",id:"remove-buggy-html-in-markdown-parser"},{from:"allowDangerousHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"allowNode",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowElement"},{from:"allowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowedElements"},{from:"className",id:"remove-classname"},{from:"disallowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"disallowedElements"},{from:"escapeHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"includeElementIndex",id:"#remove-includeelementindex"},{from:"includeNodeIndex",id:"change-includenodeindex-to-includeelementindex"},{from:"linkTarget",id:"remove-linktarget"},{from:"plugins",id:"change-plugins-to-remarkplugins",to:"remarkPlugins"},{from:"rawSourcePos",id:"#remove-rawsourcepos"},{from:"renderers",id:"change-renderers-to-components",to:"components"},{from:"source",id:"change-source-to-children",to:"children"},{from:"sourcePos",id:"#remove-sourcepos"},{from:"transformImageUri",id:"#add-urltransform",to:"urlTransform"},{from:"transformLinkUri",id:"#add-urltransform",to:"urlTransform"}];function tu(e){const t=Oge(e),n=zge(e);return Bge(t.runSync(t.parse(n),n),e)}function Oge(e){const t=e.rehypePlugins||nD,n=e.remarkPlugins||nD,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...rD}:rD;return Age().use(Eme).use(n).use(fge,r).use(t)}function zge(e){const t=e.children||"",n=new TB;return typeof t=="string"&&(n.value=t),n}function Bge(e,t){const n=t.allowedElements,r=t.allowElement,i=t.components,s=t.disallowedElements,o=t.skipHtml,l=t.unwrapDisallowed,c=t.urlTransform||Fge;for(const p of Pge)Object.hasOwn(t,p.from)&&(""+p.from+(p.to?"use `"+p.to+"` instead":"remove it")+Dge+p.id,void 0);return jE(e,u),Dpe(e,{Fragment:f.Fragment,components:i,ignoreInvalidStyle:!0,jsx:f.jsx,jsxs:f.jsxs,passKeys:!0,passNode:!0});function u(p,h,g){if(p.type==="raw"&&g&&typeof h=="number")return o?g.children.splice(h,1):g.children[h]={type:"text",value:p.value},h;if(p.type==="element"){let b;for(b in Iw)if(Object.hasOwn(Iw,b)&&Object.hasOwn(p.properties,b)){const x=p.properties[b],_=Iw[b];(_===null||_.includes(p.tagName))&&(p.properties[b]=c(String(x||""),b,p))}}if(p.type==="element"){let b=n?!n.includes(p.tagName):s?s.includes(p.tagName):!1;if(!b&&r&&typeof h=="number"&&(b=!r(p,h,g)),b&&g&&typeof h=="number")return l&&p.children?g.children.splice(h,1,...p.children):g.children.splice(h,1),h}}}function Fge(e){const t=e.indexOf(":"),n=e.indexOf("?"),r=e.indexOf("#"),i=e.indexOf("/");return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||Ige.test(e.slice(0,t))?e:""}const dv=new Map;function $ge(e){return`${e.id}|${e.contentUrl}|${e.size??0}`}function a0(e){const t=$ge(e),n=dv.get(t),[r,i]=v.useState(n??{status:"loading"}),[s,o]=v.useState(t),l=v.useRef(t);return l.current=t,s!==t&&(o(t),i(dv.get(t)??{status:"loading"})),v.useEffect(()=>{if(n&&n.status!=="loading")return;let c=!1;const u=t;return ME(e.contentUrl,S8).then(p=>{if(c||l.current!==u)return;const h={status:"ready",content:p.content,truncated:p.truncated};dv.set(u,h),i(h)}).catch(p=>{if(c||l.current!==u)return;const g={status:"error",message:p instanceof Error?p.message:"Unable to load preview."};dv.set(u,g),i(g)}),()=>{c=!0}},[n,t,e.contentUrl]),r}function Hge({source:e}){const t=a0(e);return t.status==="loading"?f.jsxs("div",{className:"p-4 text-sm text-muted-foreground",children:[f.jsx("div",{className:"prose hidden"})," Loading…"]}):t.status==="error"?f.jsx("div",{className:"p-4 text-sm text-destructive",children:t.message}):f.jsxs("div",{className:"space-y-2 overflow-auto p-3",children:[t.truncated?f.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-xs text-muted-foreground",children:"Preview truncated to 1024 KB."}):null,f.jsx("div",{className:"prose prose-sm prose-invert max-w-none rounded-xl border border-border bg-background p-4",children:f.jsx(tu,{remarkPlugins:hf,components:pf,children:t.content})})]})}const fv=new Map;function Uge(e){return`${e.id}|${e.contentUrl}|${e.size??0}|${e.mimeType}`}function Vge({source:e}){const t=Uge(e),n=fv.get(t),[r,i]=v.useState(n??{status:"loading"}),[s,o]=v.useState(t),l=v.useRef(t);if(l.current=t,s!==t&&(o(t),i(fv.get(t)??{status:"loading"})),v.useEffect(()=>{if(n&&n.status!=="loading")return;const g=e.mimeType==="text/tab-separated-values"?" ":",";let b=!1;const x=t;return ME(e.contentUrl,S8).then(_=>{if(b||l.current!==x)return;const w={status:"ready",table:wue(_.content,g),truncated:_.truncated};fv.set(x,w),i(w)}).catch(_=>{if(b||l.current!==x)return;const w={status:"error",message:_ instanceof Error?_.message:"Unable to load preview."};fv.set(x,w),i(w)}),()=>{b=!0}},[n,t,e.contentUrl,e.mimeType]),r.status==="loading")return f.jsxs("div",{className:"p-4 text-sm text-muted-foreground",children:[f.jsx("table",{className:"sr-only"})," Loading…"]});if(r.status==="error")return f.jsxs("div",{className:"p-4 text-sm text-destructive",children:[f.jsx("table",{className:"sr-only"})," ",r.message]});const{table:c}=r,[u,...p]=c.rows,h=[r.truncated?"Preview truncated to 1024 KB.":null,c.truncatedRows?`Showing first ${c.rows.length} of ${c.rowCount} rows.`:null,c.truncatedColumns?`Showing first ${A1} of ${c.columnCount} columns.`:null].filter(Boolean);return f.jsxs("div",{className:"space-y-2 overflow-auto p-3",children:[h.length?f.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-xs text-muted-foreground",children:h.join(" ")}):null,f.jsx("div",{className:"max-h-[70dvh] overflow-auto rounded-xl border border-border bg-background",children:f.jsxs("table",{className:"min-w-full border-collapse text-xs",children:[u?f.jsx("thead",{className:"sticky top-0 bg-muted",children:f.jsx("tr",{children:u.map((g,b)=>f.jsx("th",{className:"border-b border-border px-3 py-2 text-left font-medium",children:g||" "},b))})}):null,f.jsx("tbody",{children:p.map((g,b)=>f.jsx("tr",{className:"odd:bg-background even:bg-muted/20",children:g.map((x,_)=>f.jsx("td",{className:"max-w-[320px] border-b border-border px-3 py-2 align-top",children:f.jsx("div",{className:"whitespace-pre-wrap break-words",children:x||" "})},_))},b))})]})})]})}function Wge({source:e}){const t=a0(e);return t.status==="loading"?f.jsxs("div",{className:"p-4 text-sm text-muted-foreground",children:[f.jsx("pre",{className:"sr-only"})," Loading…"]}):t.status==="error"?f.jsxs("div",{className:"p-4 text-sm text-destructive",children:[f.jsx("pre",{className:"sr-only"})," ",t.message]}):f.jsxs("div",{className:"space-y-2 overflow-auto p-3",children:[t.truncated?f.jsx(Gge,{children:"Preview truncated to 1024 KB."}):null,f.jsx("pre",{className:"whitespace-pre-wrap break-words rounded-xl border border-border bg-background p-3 text-xs",children:t.content})]})}function Gge({children:e}){return f.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-xs text-muted-foreground",children:e})}function qge({source:e}){const t=a0(e),n=v.useMemo(()=>t.status==="ready"?_ue(t.content):"",[t]);return t.status==="loading"?f.jsxs("div",{className:"p-4 text-sm text-muted-foreground",children:[f.jsx("pre",{className:"sr-only"})," Loading…"]}):t.status==="error"?f.jsxs("div",{className:"p-4 text-sm text-destructive",children:[f.jsx("pre",{className:"sr-only"})," ",t.message]}):f.jsxs("div",{className:"space-y-2 overflow-auto p-3",children:[t.truncated?f.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-xs text-muted-foreground",children:"Preview truncated to 1024 KB."}):null,f.jsx("pre",{className:"whitespace-pre-wrap break-words rounded-xl border border-border bg-background p-3 text-xs",children:n})]})}function Kge({source:e}){return f.jsxs("div",{className:"flex h-full flex-col items-stretch justify-center gap-3 p-4",children:[f.jsx("div",{className:"text-sm font-medium text-foreground",children:e.displayName}),f.jsx("audio",{src:e.contentUrl,controls:!0,preload:"metadata",className:"w-full"})]})}function Yge({source:e}){return f.jsx("div",{className:"flex h-full items-center justify-center bg-black/40 p-2",children:f.jsx("video",{src:e.contentUrl,controls:!0,playsInline:!0,preload:"metadata",className:"max-h-[60dvh] w-full rounded-xl"})})}const Xge=200*1024;function Qge(e){const t=e.lastIndexOf(".");if(t<0)return"text";const n=e.slice(t+1).toLowerCase();return{ts:"typescript",tsx:"tsx",js:"javascript",jsx:"jsx",py:"python",go:"go",rs:"rust",java:"java",rb:"ruby",sh:"bash",zsh:"bash",yml:"yaml",yaml:"yaml",css:"css",scss:"scss",html:"html",json:"json",md:"markdown",sql:"sql",cpp:"cpp",c:"c",h:"c",swift:"swift",kt:"kotlin",php:"php",toml:"toml"}[n]??"text"}function Zge({source:e}){const t=a0(e),n=t.status==="ready"&&t.content.length<=Xge,r=n?`${e.id}|${e.contentUrl}|${e.size??0}|${t.content.length}`:null,[i,s]=v.useState(null);return v.useEffect(()=>{if(!n||t.status!=="ready"||r===null)return;let o=!1;const l=r;return K(()=>Promise.resolve().then(()=>mle),void 0).then(async c=>{if(o)return;const u=await c.codeToHtml(t.content,{lang:Qge(e.fileName),theme:"github-dark"});o||s({key:l,html:u})}).catch(()=>{typeof console<"u"&&console.warn("[file-preview] Shiki unavailable; falling back to plain text")}),()=>{o=!0}},[n,r,t,e.fileName]),t.status==="loading"?f.jsxs("div",{className:"p-4 text-sm text-muted-foreground",children:[f.jsx("pre",{className:"sr-only"})," Loading…"]}):t.status==="error"?f.jsxs("div",{className:"p-4 text-sm text-destructive",children:[f.jsx("pre",{className:"sr-only"})," ",t.message]}):i&&i.key===r?f.jsx("div",{className:"overflow-auto p-3 text-xs",dangerouslySetInnerHTML:{__html:i.html}}):f.jsxs("div",{className:"space-y-2 overflow-auto p-3",children:[t.truncated?f.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-xs text-muted-foreground",children:"Preview truncated to 1024 KB."}):null,f.jsx("pre",{className:"whitespace-pre-wrap break-words rounded-xl border border-border bg-background p-3 text-xs",children:t.content})]})}async function Jge(e){var r;const t=tve(e.contentUrl),n=navigator.share;if(typeof n=="function")try{return await n.call(navigator,{title:e.displayName,url:t}),"shared"}catch(i){if(i instanceof DOMException&&i.name==="AbortError")return"shared"}if((r=navigator.clipboard)!=null&&r.writeText)try{return await navigator.clipboard.writeText(t),"copied"}catch{return"failed"}return"failed"}function eve(e){const t=document.createElement("a");t.href=e.contentUrl,t.download=e.fileName,t.rel="noopener",document.body.appendChild(t),t.click(),t.remove()}function tve(e){return typeof window>"u"?e:new URL(e,document.baseURI||window.location.href).toString()}function ff({source:e,open:t,onOpenChange:n}){const r=v.useCallback(()=>n(!1),[n]);return f.jsx(Rs,{open:t&&e!==null,onOpenChange:n,children:f.jsx(Zi,{size:"lg",className:"inset-0 h-[100dvh] max-h-none w-full max-w-none translate-x-0 translate-y-0 rounded-none p-0 md:inset-auto md:left-1/2 md:top-1/2 md:h-auto md:max-h-[90dvh] md:w-auto md:max-w-3xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-2xl",children:e?f.jsx(nve,{source:e,onClose:r}):null})})}function nve({source:e,onClose:t}){const n=ive(e),[r,i]=v.useState(0),s=v.useRef(null),o=v.useCallback(h=>{s.current={y:h.clientY,lastY:h.clientY,lastT:Date.now()};try{h.currentTarget.setPointerCapture(h.pointerId)}catch{}},[]),l=v.useCallback(h=>{if(!s.current)return;const g=h.clientY-s.current.y;g<0||(s.current.lastY=h.clientY,s.current.lastT=Date.now(),i(g))},[]),c=v.useCallback(h=>{const g=s.current;s.current=null;try{h.currentTarget.releasePointerCapture(h.pointerId)}catch{}if(!g)return;const b=h.clientY-g.y,x=Math.max(1,Date.now()-g.lastT),_=(h.clientY-g.lastY)/x;b>120||_>.5?t():i(0)},[t]),u=v.useCallback(()=>{Jge(e)},[e]),p=v.useCallback(()=>eve(e),[e]);return f.jsxs("div",{className:"flex h-full max-h-full flex-col",style:r>0?{transform:`translateY(${r}px)`,transition:"none"}:void 0,children:[f.jsxs("div",{onPointerDown:o,onPointerMove:l,onPointerUp:c,onPointerCancel:c,className:"border-b border-border px-4 py-3 touch-none",children:[f.jsx("div",{className:"mx-auto mb-2 h-1 w-12 rounded-full bg-muted md:hidden",role:"button","aria-label":"Drag down to close"}),f.jsx(Ns,{className:"truncate text-base",children:e.displayName}),f.jsx(Xd,{className:"truncate text-xs",children:n})]}),f.jsx("div",{className:"min-h-0 flex-1 overflow-auto",role:"region","aria-label":"File preview",children:v.createElement(rve(e),{source:e})},e.id),f.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-border px-4 py-3",children:[f.jsxs(Ge,{type:"button",variant:"outline",onClick:u,children:[f.jsx(LG,{className:"mr-2 h-4 w-4"}),"Share"]}),e.origin==="offer_download"?f.jsxs(Ge,{type:"button",onClick:p,children:[f.jsx(YC,{className:"mr-2 h-4 w-4"}),"Download"]}):null]})]})}function rve(e){const t={id:e.id,displayName:e.displayName,mimeType:e.mimeType,size:e.size??0,contentUrl:e.contentUrl,relativePath:e.relativePath??""},n=uf(t);return n==="image"?ype:n==="pdf"?Lj:n==="audio"?Kge:n==="video"?Yge:n==="table"?Vge:n==="markdown"?Hge:n==="json"?qge:n==="code"?Zge:cf(t).kind==="external"?Lj:Wge}function ive(e){const t={id:e.id,displayName:e.displayName,mimeType:e.mimeType,size:e.size??0,contentUrl:e.contentUrl,relativePath:e.relativePath??""},n=uf(t),r=t0(n,e.mimeType),i=e.size?` · ${mf(e.size)}`:"";return`${r}${i}`}function um(e,t){return{id:e.id,contentUrl:e.contentUrl,displayName:e.displayName,fileName:e.displayName,relativePath:e.relativePath,mimeType:e.mimeType,size:e.size,origin:t}}function sve(e){const t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function ove({path:e,linkText:t}){const n=v.useMemo(()=>BE(e),[e]),[r,i]=v.useState({kind:"loading"}),[s,o]=v.useState(!1);v.useEffect(()=>{const A=new AbortController;return fetch(n,{method:"HEAD",signal:A.signal}).then(M=>{var j,P;if(A.signal.aborted)return;if(!M.ok){i({kind:M.status===404?"missing":"error"});return}const D=((P=(j=M.headers.get("Content-Type"))==null?void 0:j.split(";")[0])==null?void 0:P.trim())||"application/octet-stream",U=Number.parseInt(M.headers.get("Content-Length")??"0",10)||0;i({kind:"ready",mimeType:D,size:U})}).catch(()=>{A.signal.aborted||i({kind:"error"})}),()=>A.abort()},[n]);const l=sve(e),c=t||l,u=bpe(c,28),p=r.kind==="ready"?r.mimeType:"application/octet-stream",h=r.kind==="ready"?r.size:0,g={id:`local-file-${n}`,kind:"file",displayName:u,absolutePath:e,relativePath:e,contentUrl:n,mimeType:p,size:h};if(r.kind==="missing")return f.jsx("span",{className:"inline-flex align-bottom","data-testid":"local-file-link",children:f.jsx(Lo,{attachment:g,disabledReason:"File no longer available"})});const b=uf(g),x=t0(b,p),_=h>0?mf(h):null,w=r.kind==="loading",C=r.kind==="error",E=w?f.jsx("span",{className:"text-muted-foreground",children:"Fetching…"}):C?f.jsx("span",{className:"text-muted-foreground",children:"Unable to load"}):f.jsxs(f.Fragment,{children:[x,_?f.jsxs(f.Fragment,{children:[" · ",f.jsx("span",{className:"tabular-nums",children:_})]}):null]}),k=r.kind==="ready"?cf(g):null,R=k!==null&&!k.openInNewTab,N=[R?"Preview":"Download",c,x,_].filter(Boolean);return R?f.jsxs(f.Fragment,{children:[f.jsx("span",{className:"inline-flex align-bottom","data-testid":"local-file-link",children:f.jsx(Lo,{attachment:g,onClick:()=>o(!0),meta:E,ariaLabel:N.join(", ")})}),f.jsx(ff,{source:s?um(g,"local_file_link"):null,open:s,onOpenChange:o})]}):f.jsx("span",{className:"inline-flex align-bottom","data-testid":"local-file-link",children:f.jsx(Lo,{attachment:g,href:n,download:l,meta:E,ariaLabel:N.join(", ")})})}const ave={readonly:!1,localLinkMode:"open",attachmentMode:"live"},lve=v.createContext(ave);function l0(){return v.useContext(lve)}const Yb=()=>{},RB=v.createContext(Yb);function NB({children:e,onOpenLocalLink:t}){return f.jsx(RB.Provider,{value:t??Yb,children:e})}const F1={Task:db,TaskOutput:db,Bash:my,Glob:Bh,Grep:Bh,ExitPlanMode:zA,Read:b5,Edit:nW,Write:iW,Delete:dW,NotebookEdit:Hp,WebFetch:J9,TodoWrite:vV,WebSearch:Bh,KillShell:UG,AskUserQuestion:w5,Skill:OG,EnterPlanMode:zA},AB=eq;function MB(e){return F1[e]?F1[e]:AB}function LB({icon:e,className:t}){return f.jsx(e,{className:t})}function Aa({children:e,className:t}){return f.jsx("div",{className:me("flex gap-3 justify-start items-center",t),children:e})}function jB({children:e,className:t}){return f.jsx("div",{className:me("flex items-center gap-1.5 text-xs",t),children:e})}function Pl({children:e,className:t}){return f.jsx("span",{className:me("font-medium text-foreground/80",t),children:e})}function cve({children:e}){return f.jsx("span",{className:"text-muted-foreground",children:e})}function uve({children:e,className:t}){return f.jsxs(Aa,{className:me("px-0.5 text-xs tracking-wide",t),children:[f.jsx("div",{className:"w-full h-[1px] bg-border"}),f.jsx(Pl,{className:"whitespace-nowrap text-[11px] tracking-widest text-muted-foreground/60 uppercase flex-shrink-0",children:e}),f.jsx("div",{className:"w-full h-[1px] bg-border"})]})}function c0({children:e,expandedContent:t,defaultExpanded:n=!1}){const[r,i]=v.useState(n);return f.jsxs("div",{className:"flex flex-col w-full",children:[f.jsxs("button",{onClick:()=>i(!r),className:`group/expandable-row cursor-pointer grid grid-cols-[auto_1fr] items-center gap-1 text-sm ${r?"":"hover:opacity-60 transition-opacity"}`,children:[f.jsx("div",{className:"grid grid-cols-[auto_1fr] items-center gap-1.5",children:e}),f.jsx(Do,{className:`h-4.5 w-4.5 text-muted-icon translate-y-[0.5px] transition-all duration-200 opacity-0 group-hover/expandable-row:opacity-100 ${r?"rotate-90 opacity-100":""}`})]}),r&&t]})}function iD({label:e,children:t,copyText:n}){const[r,i]=v.useState(!1),s=n??Xb(t),o=v.useCallback(async()=>{await navigator.clipboard.writeText(s),i(!0),setTimeout(()=>i(!1),2e3)},[s]);return f.jsxs("div",{children:[f.jsx("span",{className:"font-medium text-muted-foreground",children:e}),f.jsxs("div",{className:"relative group/codeblock",children:[f.jsx("pre",{className:"my-1 text-xs font-mono whitespace-no-wrap break-all bg-muted border border-border rounded-lg p-2 max-h-64 overflow-auto w-full",children:t}),f.jsx(Ge,{variant:"ghost",size:"icon","aria-label":r?"Copied":"Copy code",className:me("absolute top-[4px] right-[4px] z-10 h-11 w-11 md:h-6.5 md:w-6.5 rounded-sm text-muted-foreground opacity-100 md:opacity-0 md:group-hover/codeblock:opacity-100 transition-opacity [@media(hover:none)]:!opacity-100",!r&&"hover:text-foreground",r&&"hover:!bg-transparent hover:!border-transparent"),onClick:o,children:r?f.jsx(yi,{className:"h-3.5 w-3.5 text-success"}):f.jsx(jl,{className:"h-4 w-4"})})]})]})}function DB({children:e,icon:t,className:n}){return f.jsxs("span",{className:me("inline-flex items-center gap-1 px-2 py-1 bg-muted border border-border rounded-full",n),children:[t&&f.jsx(t,{className:"h-3 w-3 text-muted-foreground"}),e]})}function u0({children:e,className:t}){return f.jsxs("div",{className:me("grid grid-cols-[auto_1fr] gap-2 min-w-0",t),children:[f.jsx("div",{className:" min-w-5 flex flex-col relative items-center justify-center",children:f.jsx("div",{className:"min-h-full w-[1px] bg-muted-foreground/20"})}),f.jsx("div",{className:"-ml-[1px] min-w-0 overflow-hidden",children:e})]})}function Xb(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e);if(Array.isArray(e))return e.map(Xb).join("");if(e&&typeof e=="object"&&"props"in e){const t=e.props;return Xb(t.children)}return""}function sD(e,t){return v.isValidElement(e)?v.cloneElement(e,{className:me(e.props.className,t)}):e}function dve({children:e,...t}){const[n,r]=v.useState(!1),i=Xb(e),s=async()=>{await navigator.clipboard.writeText(i),r(!0),setTimeout(()=>r(!1),2e3)};return f.jsxs("div",{className:"relative overflow-x-auto max-w-full min-w-0 no-code-highlight group/pre",children:[f.jsx("pre",{className:"min-w-0 rounded-xl py-2.5 px-3.5 [.no-pre-highlight_&]:bg-background",...t,children:e}),f.jsx(Ge,{variant:"ghost",size:"icon","aria-label":n?"Copied":"Copy code",className:me("absolute top-[35px] -translate-y-[50%] -translate-x-[1px] rounded-md right-1.5 h-11 w-11 md:h-8 md:w-8 text-muted-foreground opacity-100 md:opacity-0 md:group-hover/pre:opacity-100 transition-opacity [@media(hover:none)]:!opacity-100",!n&&"hover:text-foreground",n&&"hover:!bg-transparent hover:!border-transparent"),onClick:s,children:n?f.jsx(yi,{className:"h-4 w-4 text-success"}):f.jsx(jl,{className:"h-4 w-4"})})]})}const YE={h1:({children:e})=>f.jsx("h1",{className:"text-[20px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h2:({children:e})=>f.jsx("h2",{className:"text-[18px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h3:({children:e})=>f.jsx("h3",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h4:({children:e})=>f.jsx("h4",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h5:({children:e})=>f.jsx("h5",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h6:({children:e})=>f.jsx("h6",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),pre:dve,code:({children:e,className:t,...n})=>t?f.jsx("code",{className:"block text-xs whitespace-pre",...n,children:e}):f.jsx("code",{className:"break-all px-1 bg-border/60 dark:[.no-pre-highlight_&]:bg-background dark:[.text-pretty_&]:bg-neutral [.no-code-highlight_&]:!bg-transparent py-0.5 rounded text-sm whitespace-wrap",...n,children:e}),table:({children:e,...t})=>f.jsx("div",{className:"border border-border rounded-xl overflow-x-auto",children:f.jsx("table",{className:"table-auto min-w-full divide-y divide-border bg-background",...t,children:e})}),tbody:({children:e,...t})=>f.jsx("tbody",{className:"divide-y divide-border",...t,children:e}),th:({children:e,...t})=>f.jsx("th",{className:"text-left text-xs uppercase text-muted-foreground tracking-wider p-2 pl-0 first:pl-3 bg-muted dark:bg-card [&_*]:font-semibold",...t,children:e}),td:({children:e,...t})=>f.jsx("td",{className:"text-left p-2 pl-0 first:pl-3 [&_*]:font-normal ",...t,children:e}),p:({children:e,...t})=>f.jsx("p",{className:"break-words mt-5 mb-3 first:mt-0 last:mb-0",...t,children:e}),blockquote:({children:e,...t})=>(()=>{const n=v.Children.toArray(e),r=n[0];r!==void 0&&(n[0]=sD(r,"mt-0"));const i=n.length-1,s=n[i];return s!==void 0&&(n[i]=sD(s,"mb-0")),f.jsx("blockquote",{className:"my-2 mt-5 mb-3 first:mt-0 last:mb-0 border-l-2 border-border/80 pl-2 text-muted-foreground",...t,children:n})})(),a:({children:e,...t})=>f.jsx("a",{className:"transition-all underline decoration-2 text-logo decoration-logo/50 hover:text-logo/70 dark:text-logo dark:decoration-logo/70 dark:hover:text-logo/60 dark:hover:decoration-logo/40 ",target:"_blank",rel:"noopener noreferrer",...t,children:e}),img:({src:e,...t})=>{const n=typeof e=="string"&&vpe(e)?BE(e):e;return f.jsx("img",{src:n,...t})}};function fve({children:e,href:t,onClick:n,overrideOpenLocalLink:r,...i}){const s=v.useContext(RB),o=r??s,l=l0(),c=mpe(t);if(c&&l.localLinkMode==="text")return f.jsx("span",{className:"transition-all underline decoration-2 text-logo decoration-logo/50",children:e});if(c&&!dB(c.path)){const u=$1(e).trim();return f.jsx(ove,{path:c.path,linkText:u||void 0})}return f.jsx("a",{className:"transition-all underline decoration-2 text-logo decoration-logo/50 hover:text-logo/70 dark:text-logo dark:decoration-logo/70 dark:hover:text-logo/60 dark:hover:decoration-logo/40 ",href:t,target:c?void 0:"_blank",rel:c?void 0:"noopener noreferrer",onClick:u=>{n==null||n(u),!(u.defaultPrevented||!c||o===Yb)&&(u.preventDefault(),o({...c,clientX:u.clientX,clientY:u.clientY,trigger:"click"}))},onContextMenu:u=>{!c||o===Yb||(u.preventDefault(),o({...c,clientX:u.clientX,clientY:u.clientY,trigger:"contextmenu"}))},...i,children:e})}function hve(e){return{...YE,a:t=>f.jsx(fve,{...t,overrideOpenLocalLink:e==null?void 0:e.onOpenLocalLink})}}const hf=[uB],pf=hve();function $1(e){return e==null||typeof e=="boolean"?"":typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map($1).join(""):v.isValidElement(e)?$1(e.props.children):""}({...YE});function XE({attachment:e,previewUrl:t,onClick:n,onRemove:r,className:i,size:s="transcript",uploadProgress:o,onCancelUpload:l}){const c=e.contentUrl||t,u=s==="composer",p=o!==void 0;return f.jsxs("div",{className:me("group relative flex flex-row items-end",i),children:[f.jsxs("button",{type:"button",onClick:n,className:me("group/image relative overflow-hidden rounded-xl border border-border/80 bg-background shadow-sm",u?"min-w-[80px]":"min-w-[200px]"),children:[c?f.jsx("img",{src:c,alt:e.displayName,className:me("rounded-xl object-contain bg-muted",u?"min-h-[50px] min-w-[80px] max-h-[120px] max-w-[200px]":"min-h-[100px] min-w-[200px] max-h-[300px] max-w-[300px]")}):f.jsx("div",{className:me("flex items-center justify-center rounded-xl bg-muted text-muted-foreground",u?"min-h-[64px] min-w-[80px]":"min-h-[160px] min-w-[200px]"),children:f.jsx(v5,{className:me(u?"size-6":"size-8")})}),f.jsxs("div",{className:me("pointer-events-none absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/75 via-black/30 to-transparent text-left opacity-0 transition-opacity duration-200 group-hover/image:opacity-100",u?"px-2.5 pb-2 pt-6":"px-4 pb-3 pt-10"),children:[f.jsx("div",{className:me("truncate font-medium text-white",u?"text-xs":"text-sm"),children:e.displayName}),f.jsxs("div",{className:"truncate text-xs text-white/80",children:[e.mimeType," · ",mf(e.size)]})]})]}),p?f.jsx(R8,{progress:o??null,onCancel:l,size:u?"sm":"md",cancelLabel:`Cancel upload of ${e.displayName}`}):null,r&&!p?f.jsx(IB,{displayName:e.displayName,onRemove:r}):null]})}function Lo({attachment:e,onClick:t,onRemove:n,className:r,uploadProgress:i,onCancelUpload:s,href:o,download:l,meta:c,ariaLabel:u,disabledReason:p}){const h=e.kind==="mention"?"text":uf(e),g=gve(h),b=e.kind==="mention",x=b?pve(e.displayName):e.displayName,_=b?mve(e.displayName):"",w=i!==void 0,C=!!p,E=me("flex w-[200px] items-center gap-2 rounded-xl border border-border bg-background p-1 pr-3 text-left transition-colors",C?"cursor-not-allowed opacity-60":"hover:bg-accent/50"),k=b?f.jsx("div",{className:"max-w-[150px] truncate text-[11px] text-muted-foreground",children:_?`@${_}`:"@mention"}):p?f.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:p}):c!==void 0?f.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:c}):f.jsxs("div",{className:"truncate text-[11px] text-muted-foreground",children:[e.mimeType," · ",mf(e.size)]}),R=f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"flex min-h-10 min-w-10 items-center justify-center rounded-lg border border-border bg-muted text-muted-foreground",children:f.jsx(LB,{icon:g,className:"size-5"})}),f.jsxs("div",{className:"min-w-0",children:[f.jsx("div",{className:me("max-w-[150px] truncate text-[13px] font-medium",C?"text-muted-foreground line-through":"text-foreground"),children:x}),k]})]});return f.jsxs("div",{className:me("group relative",r),children:[o&&!C?f.jsx("a",{href:o,download:l,rel:"noopener","aria-label":u,className:E,children:R}):f.jsx("button",{type:"button",onClick:C?void 0:t,title:b?e.displayName:void 0,"aria-label":u,"aria-disabled":C||void 0,disabled:C,className:E,children:R}),w?f.jsx(R8,{progress:i??null,onCancel:s,size:"sm",cancelLabel:`Cancel upload of ${e.displayName}`}):null,n&&!w?f.jsx(IB,{displayName:e.displayName,onRemove:n}):null]})}function pve(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function mve(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(0,n):""}function IB({displayName:e,onRemove:t}){return f.jsx("button",{type:"button",className:"absolute right-2 top-2 rounded-full bg-background/90 p-1 text-muted-foreground shadow-sm transition hover:bg-muted hover:text-foreground",onClick:n=>{n.preventDefault(),n.stopPropagation(),t()},"aria-label":`Remove ${e}`,children:f.jsx(io,{className:"h-3.5 w-3.5"})})}function gve(e){switch(e){case"image":return v5;case"pdf":return mG;case"markdown":return SG;case"json":return YV;case"table":return oW;case"code":return QV;case"text":return QC;case"archive":return qV;case"audio":return JV;case"video":return cW;default:return b5}}function mf(e){return e<1024?`${e} B`:e<1024*1024?`${Math.max(1,Math.round(e/1024))} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}const d0=v.forwardRef(({className:e,...t},n)=>f.jsx("textarea",{"data-gramm":"false","data-gramm_editor":"false","data-enable-grammarly":"false","data-1p-ignore":!0,autoComplete:"off",className:me("flex w-full rounded-lg border border-border bg-background px-2.5 py-2 text-sm placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));d0.displayName="Textarea";const hv={};function oD(e){return!e.isCollapsed&&!e.hasPreviewAttachment&&e.patch===void 0&&e.patchError===void 0&&!e.isPatchLoading}function vve(e,t){return!e||!t.mimeType||typeof t.size!="number"||t.changeType==="deleted"||!t.mimeType.startsWith("image/")&&t.mimeType!=="application/pdf"?null:{id:`diff:${t.path}`,kind:t.mimeType.startsWith("image/")?"image":"file",displayName:t.path.split("/").pop()??t.path,absolutePath:t.path,relativePath:t.path,contentUrl:`/api/projects/${e}/files/${encodeURIComponent(t.path)}/content`,mimeType:t.mimeType,size:t.size}}function PB(e){return e.isUntracked}function bve(e){return PB(e)?e.path.includes("/"):!1}function Vw(e){return f.jsxs(Yr,{delayDuration:0,children:[f.jsx(Xr,{asChild:!0,children:f.jsx("button",{type:"button","aria-label":e.label,title:e.label,onClick:e.onClick,className:me("flex h-11 w-11 md:h-7 md:w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",e.active&&"bg-accent text-foreground"),children:e.children})}),f.jsx(Br,{children:e.label})]})}function OB({checked:e,mixed:t=!1,label:n,className:r,onClick:i}){return f.jsx("button",{type:"button","aria-label":n??(e?"Exclude file from commit":"Include file in commit"),"aria-checked":t?"mixed":e,"aria-pressed":t?"mixed":e,onClick:s=>{s.stopPropagation(),i()},className:me("flex size-4.5 shrink-0 items-center justify-center rounded border transition-colors",e||t?"border-foreground bg-foreground text-background":"border-border bg-background text-transparent",r),children:t?f.jsx(YW,{className:"h-3 w-3",strokeWidth:3}):e?f.jsx(yi,{className:"h-3 w-3",strokeWidth:3}):null})}function QE(e){const t=Date.parse(e);if(!Number.isFinite(t))return"";const n=Date.now()-t,r=6e4,i=60*r,s=24*i,o=7*s,l=30*s,c=365*s;return n<r?"just now":n<i?`${Math.round(n/r)}m ago`:n<s?`${Math.round(n/i)}hr ago`:n<o?`${Math.round(n/s)}d ago`:n<l?`${Math.round(n/o)}wk ago`:n<c?`${Math.round(n/l)}mo ago`:`${Math.round(n/c)}yr ago`}function yve(e){return e?`Last fetched ${QE(e)}`:"No local fetch recorded"}function xve({entry:e,isPendingPush:t=!1}){const n=QE(e.authoredAt),r=!!e.githubUrl;return f.jsxs("button",{type:"button",disabled:!r,onClick:()=>{!e.githubUrl||typeof window>"u"||window.open(e.githubUrl,"_blank","noopener,noreferrer")},className:me("flex w-full items-start gap-3 rounded-lg border border-border bg-background pl-3 pr-2 py-2 text-left transition-colors",r?"hover:bg-accent":"cursor-default opacity-60"),children:[f.jsxs("div",{className:"min-w-0 flex-1",children:[f.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:e.summary}),e.description?f.jsx("div",{className:"mt-1 line-clamp-2 whitespace-pre-wrap text-xs text-muted-foreground",children:e.description}):null,f.jsxs("div",{className:"mt-1 flex min-w-0 items-center gap-1 text-xs text-muted-foreground",children:[e.authorName?f.jsx("span",{className:"truncate",children:e.authorName}):null,e.authorName&&n?f.jsx("span",{"aria-hidden":"true",children:"•"}):null,n?f.jsx("span",{children:n}):null]})]}),e.tags.length>0?f.jsxs("div",{className:"flex shrink-0 flex-wrap justify-end gap-1",children:[e.tags.map(i=>f.jsx("span",{className:"inline-flex items-center rounded-full bg-muted border border-border px-2 py-0.5 text-[11px]",children:i},i)),t?f.jsx("span",{className:"inline-flex items-center rounded-full bg-muted border border-border px-2 py-0.5 text-[11px]",children:f.jsx(rp,{className:"size-3"})}):null]}):t?f.jsx("div",{className:"flex shrink-0 flex-wrap justify-end gap-1",children:f.jsx("span",{className:"inline-flex items-center rounded-full bg-muted border border-border px-2 py-0.5 text-[11px]",children:f.jsx(rp,{className:"size-3"})})}):null]})}function aD(e){switch(e.kind){case"local":return 0;case"pull_request":return 1;case"remote":default:return 2}}function _ve(e){const t=new Map;for(const n of e){const r=t.get(n.name);(!r||aD(n)<aD(r))&&t.set(n.name,n)}return t}function wve(e,t){const n=_ve([...e.local,...e.pullRequests,...e.remote]);t&&n.delete(t);const r=new Set,i=e.defaultBranchName?n.get(e.defaultBranchName):void 0;i&&r.add(i.name);const s=e.recent.map(l=>n.get(l.name)??l).filter(l=>!!l&&!r.has(l.name));for(const l of s)r.add(l.name);const o=[...n.values()].filter(l=>!r.has(l.name)).sort((l,c)=>l.displayName.localeCompare(c.displayName));return{defaultBranch:i,recent:s,other:o}}function Sve({open:e,onOpenChange:t,onGetGitHubPublishInfo:n,onCheckGitHubRepoAvailability:r,onPublish:i}){const[s,o]=v.useState(null),[l,c]=v.useState(!1),[u,p]=v.useState(""),[h,g]=v.useState(""),[b,x]=v.useState("private"),[_,w]=v.useState(""),[C,E]=v.useState(null),[k,R]=v.useState(!1),[N,A]=v.useState(!1);v.useEffect(()=>{if(!e)return;let U=!1;return c(!0),E(null),n().then(j=>{U||(o(j),p(j.owners[0]??j.activeAccountLogin??""),g(j.suggestedRepoName),x("private"),w(""))}).finally(()=>{U||c(!1)}),()=>{U=!0}},[n,e]),v.useEffect(()=>{if(!e||!(s!=null&&s.ghInstalled)||!s.authenticated)return;const U=u.trim(),j=h.trim();if(!U||!j){E(null);return}let P=!1;R(!0);const z=window.setTimeout(()=>{r({owner:U,name:j}).then(O=>{P||E(O)}).finally(()=>{P||R(!1)})},250);return()=>{P=!0,window.clearTimeout(z)}},[s==null?void 0:s.authenticated,s==null?void 0:s.ghInstalled,h,r,e,u]);async function M(){if(!(!u.trim()||!h.trim())){A(!0);try{const U=await i({owner:u.trim(),name:h.trim(),visibility:b,description:_});U!=null&&U.ok&&t(!1)}finally{A(!1)}}}const D=!!(s!=null&&s.ghInstalled&&s.authenticated&&u.trim()&&h.trim()&&(C!=null&&C.available)&&!k&&!N);return f.jsx(Rs,{open:e,onOpenChange:t,children:f.jsxs(Zi,{size:"sm",className:"max-w-[min(92vw,475px)]",children:[f.jsxs(Io,{className:"space-y-2 px-4 pb-4 pt-4",children:[f.jsxs("div",{className:"space-y-1",children:[f.jsx(Ns,{children:"Push to GitHub"}),f.jsx(Xd,{children:"Create a GitHub repository from this local project using GitHub CLI."})]}),l?f.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[f.jsx(Cn,{className:"size-4 animate-spin"}),f.jsx("span",{children:"Checking GitHub CLI…"})]}):s&&!s.ghInstalled?f.jsxs("div",{className:"space-y-2 text-sm text-muted-foreground",children:[f.jsx("p",{children:"GitHub CLI is not installed."}),f.jsx("div",{className:"rounded-lg border border-border px-3 py-2 font-mono text-xs text-foreground",children:"brew install gh"}),f.jsx("p",{children:"Then run:"}),f.jsx("div",{className:"rounded-lg border border-border px-3 py-2 font-mono text-xs text-foreground",children:"gh auth login"})]}):s&&!s.authenticated?f.jsxs("div",{className:"space-y-2 text-sm text-muted-foreground",children:[f.jsx("p",{children:"GitHub CLI is installed but not signed in."}),f.jsx("div",{className:"rounded-lg border border-border px-3 py-2 font-mono text-xs text-foreground",children:"gh auth login"})]}):f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"space-y-2",children:f.jsxs(Sl,{value:u,onValueChange:p,children:[f.jsx(fa,{className:"pl-[11px] [&>span]:flex [&>span]:items-center [&>span]:gap-2",children:f.jsx(Sc,{placeholder:"Select owner"})}),f.jsx(ha,{children:((s==null?void 0:s.owners)??[]).map(U=>f.jsx(Ws,{value:U,children:f.jsxs("span",{className:"flex items-center gap-2",children:[U===(s==null?void 0:s.activeAccountLogin)?f.jsx(gy,{className:"size-4 text-muted-foreground"}):f.jsx(hV,{className:"size-4 text-muted-foreground"}),f.jsx("span",{className:"pl-[1px]",children:U})]})},U))})]})}),f.jsx("div",{className:"space-y-2",children:f.jsxs("div",{className:"relative",children:[f.jsx(Kn,{value:h,onChange:U=>g(U.target.value),placeholder:"my-repo",className:"pl-9 pr-10"}),f.jsx(aG,{className:"pointer-events-none absolute inset-y-0 left-3 my-auto size-4 text-muted-foreground"}),k?f.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-3 flex items-center text-muted-foreground",children:f.jsx(Cn,{className:"size-4 animate-spin"})}):C?f.jsx("div",{className:"absolute inset-y-0 right-2 flex items-center",children:f.jsxs(Yr,{delayDuration:0,children:[f.jsx(Xr,{asChild:!0,children:f.jsx("button",{type:"button",tabIndex:-1,"aria-label":C.message,className:me("flex size-6 items-center justify-center rounded-md",C.available?"text-success":"text-destructive"),children:C.available?f.jsx(yi,{className:"size-4"}):f.jsx(fb,{className:"size-4"})})}),f.jsx(Br,{children:C.message})]})}):null]})}),f.jsx("div",{className:"space-y-2",children:f.jsxs("div",{className:"relative",children:[f.jsx(QC,{className:"pointer-events-none absolute left-3 top-3 size-4 text-muted-foreground"}),f.jsx(d0,{value:_,onChange:U=>w(U.target.value),rows:3,placeholder:"Optional description",className:"pl-9 outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"})]})}),f.jsx("div",{className:"space-y-2",children:f.jsxs(Sl,{value:b,onValueChange:U=>x(U),children:[f.jsx(fa,{className:"pl-[11px] [&>span]:flex [&>span]:items-center [&>span]:gap-2",children:f.jsx(Sc,{placeholder:"Select visibility"})}),f.jsxs(ha,{children:[f.jsx(Ws,{value:"private",children:f.jsxs("span",{className:"flex items-center gap-2",children:[f.jsx(FW,{className:"size-4 text-muted-foreground"}),f.jsx("span",{className:"pl-[1px]",children:"Private"})]})}),f.jsx(Ws,{value:"public",children:f.jsxs("span",{className:"flex items-center gap-2",children:[f.jsx(TW,{className:"size-4 text-muted-foreground"}),f.jsx("span",{className:"pl-[1px]",children:"Public"})]})})]})]})})]})]}),f.jsxs(_a,{children:[f.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>t(!1),children:"Cancel"}),f.jsx(Ge,{size:"sm",disabled:!D,onClick:()=>void M(),children:N?f.jsxs(f.Fragment,{children:[f.jsx(Cn,{className:"mr-1.5 size-3.5 animate-spin"}),"Publishing…"]}):"Push to GitHub"})]})]})})}function zB({value:e,onChange:t,placeholder:n,disabled:r,trailingAction:i}){return f.jsxs("div",{className:"relative",children:[f.jsx(Bh,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),f.jsx(Kn,{value:e,onChange:s=>t(s.target.value),placeholder:n,className:me("h-9 pl-7 text-sm",i?"pr-14":void 0),disabled:r}),i?f.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2",children:i}):null]})}function Nc({title:e,entries:t,emptyLabel:n,selectedName:r,disabled:i,stickyTitle:s=!1,onSelect:o}){return t.length===0&&!n?null:f.jsxs("div",{className:"space-y-1",children:[f.jsx("div",{className:me("px-1 py-1 text-[11px] font-medium uppercase tracking-[0.08em] text-muted-foreground",s&&"sticky top-0 z-10 bg-background"),children:e}),t.length===0?f.jsx("div",{className:"px-1 py-1 text-xs text-muted-foreground",children:n}):t.map(l=>{const c=r===l.name;return f.jsxs("button",{type:"button",disabled:i,onClick:()=>o(l),className:me("flex w-full items-start gap-2 rounded-lg px-2 py-2 text-left transition-colors disabled:opacity-60",c?"bg-accent text-foreground":"hover:bg-accent"),children:[l.kind==="pull_request"?f.jsx(_5,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}):f.jsx(kc,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),f.jsxs("div",{className:"min-w-0 flex-1",children:[f.jsxs("div",{className:"flex w-full items-center gap-3",children:[f.jsx("div",{className:"min-w-0 flex-1 overflow-hidden whitespace-nowrap text-sm text-foreground",children:l.displayName}),l.updatedAt?f.jsx("div",{className:"ml-auto shrink-0 text-right text-[11px] text-muted-foreground",children:QE(l.updatedAt)}):null]}),l.kind==="pull_request"&&l.description||l.headLabel?f.jsx("div",{className:"truncate text-xs text-muted-foreground",children:l.kind==="pull_request"?l.description??l.headLabel??l.name:l.headLabel??void 0}):null]})]},l.id)})]})}function Cve({open:e,onOpenChange:t,branchList:n,currentBranchName:r,onPreviewMergeBranch:i,onMergeBranch:s}){const[o,l]=v.useState(""),[c,u]=v.useState(null),[p,h]=v.useState(null),[g,b]=v.useState(null),[x,_]=v.useState(!1),[w,C]=v.useState(!1),E=v.useMemo(()=>n?wve(n,r):{defaultBranch:void 0,recent:[],other:[]},[n,r]),k=o.trim().toLowerCase(),R=v.useCallback(P=>k?[P.displayName,P.name,P.description,P.prTitle,P.headLabel].some(z=>z==null?void 0:z.toLowerCase().includes(k)):!0,[k]),N=E.defaultBranch&&R(E.defaultBranch)?E.defaultBranch:void 0,A=E.recent.filter(R),M=E.other.filter(R),D=v.useMemo(()=>c?[E.defaultBranch,...E.recent,...E.other].find(P=>P!==void 0&&P.name===c)??null:null,[E.defaultBranch,E.other,E.recent,c]);v.useEffect(()=>{e||(l(""),u(null),h(null),b(null),_(!1),C(!1))},[e]),v.useEffect(()=>{if(!e||!D){h(null),b(null),_(!1);return}let P=!1;return h(null),b(null),_(!0),i(D).then(z=>{P||h(z)}).catch(z=>{P||b(z instanceof Error?z.message:String(z))}).finally(()=>{P||_(!1)}),()=>{P=!0}},[i,e,D]);const U=!D||!p||x||w||p.status!=="mergeable";async function j(){if(!(!D||U)){C(!0);try{const P=await s(D);P!=null&&P.ok&&t(!1)}finally{C(!1)}}}return f.jsx(Rs,{open:e,onOpenChange:t,children:f.jsxs(Zi,{size:"sm",className:"max-w-[min(92vw,475px)]",children:[f.jsxs(Io,{className:"flex min-h-0 flex-col gap-3 px-4 pb-4 pt-4",children:[f.jsxs("div",{className:"space-y-1",children:[f.jsxs(Ns,{children:["Merge into ",r??"current branch"]}),f.jsx(Xd,{children:"Choose a branch to continue."})]}),f.jsx(zB,{value:o,onChange:l,placeholder:"Search branches"}),f.jsxs("div",{className:"max-h-[375px] space-y-3 overflow-y-auto pr-1",children:[f.jsx(Nc,{title:"Default Branch",entries:N?[N]:[],emptyLabel:"No default branch available.",selectedName:c,onSelect:P=>u(P.name)}),f.jsx(Nc,{title:"Recent Branches",entries:A,emptyLabel:"No recent branches.",selectedName:c,onSelect:P=>u(P.name)}),f.jsx(Nc,{title:"Other Branches",entries:M,emptyLabel:"No other branches match this search.",selectedName:c,onSelect:P=>u(P.name)})]}),f.jsx("div",{className:"px-2",children:D?x?f.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[f.jsx(Cn,{className:"size-3.5 animate-spin"}),f.jsx("span",{children:"Checking merge preview…"})]}):g?f.jsx("div",{className:"text-sm text-destructive",children:g}):p?f.jsxs("div",{className:"flex items-start gap-2",children:[p.status==="up_to_date"?f.jsx(yi,{className:"mt-1 size-3.5 shrink-0 text-success"}):p.status==="conflicts"?f.jsx(fb,{className:"mt-1 size-3.5 shrink-0 text-warning"}):p.status==="mergeable"?f.jsx(x5,{className:"mt-1 size-3.5 shrink-0 text-muted-foreground"}):f.jsx(fb,{className:"mt-1 size-3.5 shrink-0 text-destructive"}),f.jsxs("div",{className:"min-w-0 space-y-1",children:[f.jsx("div",{className:"text-sm font-medium text-foreground",children:p.message}),p.detail?f.jsx("div",{className:"line-clamp-2 whitespace-pre-wrap text-xs text-muted-foreground",children:p.detail}):null]})]}):f.jsx("div",{className:"text-sm text-muted-foreground",children:"Preview unavailable."}):f.jsx("div",{className:"text-sm text-muted-foreground",children:"Select a branch to preview the merge."})})]}),f.jsx(_a,{children:f.jsxs("div",{className:"flex min-w-0 w-full items-center justify-end gap-2",children:[f.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>t(!1),children:"Cancel"}),f.jsx(Ge,{className:"max-w-full min-w-0",size:"sm",disabled:U,onClick:()=>void j(),children:w?f.jsxs(f.Fragment,{children:[f.jsx(Cn,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),"Merging…"]}):f.jsx("span",{className:"block max-w-full truncate",children:"Merge"})})]})})]})})}function kve({currentBranchName:e,onListBranches:t,onPreviewMergeBranch:n,onMergeBranch:r,onCheckoutBranch:i,onCreateBranch:s}){const[o,l]=v.useState(!1),[c,u]=v.useState(!1),[p,h]=v.useState(!1),[g,b]=v.useState(!1),[x,_]=v.useState(""),[w,C]=v.useState("branches"),[E,k]=v.useState(null),[R,N]=v.useState(null);v.useEffect(()=>{o&&(h(!0),N(null),t().then(W=>k(W)).catch(W=>{N(W instanceof Error?W.message:String(W))}).finally(()=>{h(!1)}))},[t,o]);const A=x.trim().toLowerCase(),M=W=>W.filter(X=>A?[X.displayName,X.name,X.description,X.prTitle,X.headLabel].some(I=>I==null?void 0:I.toLowerCase().includes(A)):!0),D=(E==null?void 0:E.currentBranchName)??e,U=new Set(((E==null?void 0:E.pullRequests)??[]).map(W=>W.headRefName??W.name)),j=M((E==null?void 0:E.recent)??[]).filter(W=>W.name!==D),P=M((E==null?void 0:E.local)??[]).filter(W=>W.name!==D),z=M((E==null?void 0:E.remote)??[]).filter(W=>W.name!==D&&!U.has(W.name)),O=M((E==null?void 0:E.pullRequests)??[]).filter(W=>W.name!==D),$=(E==null?void 0:E.pullRequests.length)??0;async function V(W){b(!0);try{await i(W),l(!1),_(""),C("branches")}finally{b(!1)}}async function B(){b(!0);try{await s(),l(!1),_(""),C("branches")}finally{b(!1)}}function F(){l(!1),u(!0)}return f.jsxs(Bk,{open:o,onOpenChange:l,children:[f.jsx(Fk,{asChild:!0,children:f.jsxs("button",{type:"button",className:"flex min-w-0 max-w-full items-center gap-1 rounded-md px-1.5 py-1 text-sm transition-colors hover:bg-accent hover:text-foreground","aria-label":"Open branch switcher",children:[f.jsx(kc,{className:"h-3.5 w-3.5 shrink-0"}),f.jsx("span",{className:"truncate",children:e??"Detached HEAD"}),f.jsx(Gd,{className:"h-3.5 w-3.5 shrink-0"})]})}),f.jsx(Py,{align:"start",className:"w-[320px] p-2",children:f.jsxs("div",{className:"space-y-2",children:[f.jsx(zB,{value:x,onChange:_,placeholder:w==="pull_requests"?"Search pull requests":"Search branches",disabled:p||g,trailingAction:f.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>void B(),disabled:p||g,className:"h-7 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:"+ New"})}),f.jsx(da,{value:w,onValueChange:W=>C(W),size:"sm",className:"w-full",optionClassName:"flex-1 justify-center",options:[{value:"branches",label:"Branches"},{value:"pull_requests",label:`Open PRs ${$}`}]}),f.jsx("div",{className:"max-h-[420px] overflow-y-auto pr-1.5 -mr-[8px]",children:p?f.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 text-sm text-muted-foreground",children:[f.jsx(Cn,{className:"h-4 w-4 animate-spin"}),f.jsx("span",{children:"Loading branches…"})]}):R?f.jsx("div",{className:"rounded-lg border border-border px-3 py-2 text-sm text-muted-foreground",children:R}):w==="pull_requests"?f.jsx(Nc,{title:"Open PRs",entries:O,emptyLabel:(E==null?void 0:E.pullRequestsStatus)==="error"?E.pullRequestsError??"Could not load pull requests.":(E==null?void 0:E.pullRequestsStatus)==="unavailable"?"Pull requests unavailable for this repository.":"No open pull requests.",disabled:g,stickyTitle:!0,onSelect:W=>{V(W)}}):f.jsxs("div",{className:"space-y-3",children:[f.jsx(Nc,{title:"Recent",entries:j,emptyLabel:"No recent branches.",disabled:g,stickyTitle:!0,onSelect:W=>{V(W)}}),f.jsx(Nc,{title:"Local",entries:P,emptyLabel:"No local branches.",disabled:g,stickyTitle:!0,onSelect:W=>{V(W)}}),f.jsx(Nc,{title:"Remote",entries:z,emptyLabel:"No remote branches.",disabled:g,stickyTitle:!0,onSelect:W=>{V(W)}})]})}),D?f.jsx(Ge,{variant:"default",size:"sm",disabled:p||g||!!R,onClick:F,className:"h-9 w-full justify-center rounded-lg px-3 text-sm",children:f.jsxs("span",{className:"block max-w-full truncate",children:[f.jsx(wW,{className:"mr-1.5 inline h-3.5 w-3.5 shrink-0"}),"Merge branch into ",D,"..."]})}):null]})}),f.jsx(Cve,{open:c,onOpenChange:u,branchList:E,currentBranchName:D,onPreviewMergeBranch:n,onMergeBranch:r})]})}function Eve({file:e,rootRef:t,projectId:n,isCollapsed:r,isChecked:i,editorLabel:s,diffRenderMode:o,wrapLines:l,onToggleCollapsed:c,onToggleChecked:u,fileActions:p,patch:h,patchError:g,isPatchLoading:b,onLoadPatch:x}){const _=PB(e),w=bve(e),[C,E]=v.useState(null),k=v.useRef(null),R=v.useRef(null),{sentinelRef:N,isStuck:A}=due({rootRef:t,disabled:r}),M=v.useMemo(()=>vve(n,e),[e,n]),D=M!==null,U=oD({isCollapsed:r,hasPreviewAttachment:D,patch:h,patchError:g,isPatchLoading:b});v.useEffect(()=>{if(!U)return;const O=`${e.path}\0${e.patchDigest}`;R.current!==O&&(R.current=O,x(e.path).catch(()=>{}))},[e.patchDigest,e.path,x,U]);function j(O){if(cf(O).openInNewTab){typeof window<"u"&&window.open(new URL(O.contentUrl,window.location.origin).toString(),"_blank","noopener,noreferrer");return}E(O.id)}function P(O){var V;O.preventDefault(),O.stopPropagation();const $=O.currentTarget.getBoundingClientRect();(V=k.current)==null||V.dispatchEvent(new MouseEvent("contextmenu",{bubbles:!0,cancelable:!0,clientX:$.left+$.width/2,clientY:$.bottom,view:window}))}function z(){if(!r){c();return}if(D||h!==void 0){c();return}if(b)return;if(!(g!==void 0||oD({isCollapsed:!1,hasPreviewAttachment:D,patch:h,patchError:g,isPatchLoading:b}))){c();return}x(e.path).then(()=>{c()}).catch(()=>{})}return f.jsxs(Zc,{children:[f.jsx(Jc,{asChild:!0,children:f.jsxs("div",{ref:k,className:"relative rounded-lg border border-border bg-background",children:[r?null:f.jsx("div",{ref:N,className:"pointer-events-none absolute inset-x-0 top-0 h-px","aria-hidden":"true"}),f.jsxs("div",{role:"button",tabIndex:0,onClick:z,onKeyDown:O=>{O.key!=="Enter"&&O.key!==" "||(O.preventDefault(),z())},className:me("group/header sticky top-0 z-20 flex cursor-pointer items-center justify-between gap-3 bg-background pl-[7px] pr-2.5 py-1.5 text-[13px] text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",!r&&!A&&"rounded-t-[calc(theme(borderRadius.lg)-1px)]",r&&"rounded-[calc(theme(borderRadius.lg)-1px)]",!r&&"border-b border-border/50"),children:[f.jsxs("div",{className:"flex min-w-0 items-center",children:[f.jsx(OB,{checked:i,onClick:u}),f.jsx("div",{className:"min-w-0 truncate select-none ml-2 mr-1",children:e.path})]}),f.jsxs("div",{className:"flex shrink-0 items-center gap-2 select-none",children:[f.jsxs("span",{className:"whitespace-nowrap text-xs font-mono",children:[e.additions>0?f.jsxs("span",{className:"text-success",children:["+",e.additions]}):null,e.deletions>0?f.jsxs("span",{className:e.additions>0?"ml-2 text-destructive":"text-destructive",children:["-",e.deletions]}):null]}),f.jsx("button",{type:"button","aria-label":`Open actions for ${e.path}`,onClick:P,className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:f.jsx(ip,{className:"h-3.5 w-3.5 shrink-0"})}),b&&r&&!M?f.jsx(Cn,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):r?f.jsx(Gd,{className:"h-3.5 w-3.5 shrink-0"}):f.jsx(g5,{className:"h-3.5 w-3.5 shrink-0"})]})]}),r?null:f.jsx("div",{className:"kanna-diff-patch overflow-hidden rounded-b-[calc(theme(borderRadius.lg)-1px)] pb-[1px]",children:M?f.jsx("div",{className:"flex justify-center p-3",children:M.kind==="image"?f.jsx(XE,{attachment:M,onClick:()=>j(M)}):f.jsx(Lo,{attachment:M,onClick:()=>j(M)})}):b?f.jsxs("div",{className:"flex items-center justify-center px-3 py-8 text-sm text-muted-foreground",children:[f.jsx(Cn,{className:"mr-2 h-4 w-4 animate-spin"}),"Loading diff..."]}):g?f.jsx("div",{className:"px-3 py-4 text-sm text-destructive",children:g}):h!==void 0?f.jsx(cue,{patch:h,options:{diffStyle:o,disableFileHeader:!0,disableBackground:!1,overflow:l?"wrap":"scroll",lineDiffType:"word",diffIndicators:"classic"}}):f.jsx("div",{className:"px-3 py-4 text-sm text-muted-foreground",children:"Diff unavailable."})}),f.jsx(ff,{source:M&&C===M.id?um(M,"user_attachment"):null,open:M!==null&&C===M.id,onOpenChange:O=>!O&&E(null)})]},e.path)}),f.jsxs(Fl,{children:[f.jsxs(Mn,{onSelect:O=>{O.stopPropagation(),p.onOpenFile(e.path)},children:[f.jsx(KC,{className:"h-3.5 w-3.5"}),f.jsxs("span",{className:"text-xs font-medium",children:["Open in ",s]})]}),f.jsxs(Mn,{onSelect:O=>{O.stopPropagation(),p.onOpenInFinder(e.path)},children:[f.jsx(py,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Open in Finder"})]}),f.jsxs(Mn,{onSelect:O=>{O.stopPropagation(),p.onDiscardFile(e.path)},className:"text-destructive hover:bg-destructive/10 focus:bg-destructive/10",children:[f.jsx(qd,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Discard Changes"})]}),f.jsxs(Mn,{disabled:!_,onSelect:O=>{O.stopPropagation(),_&&p.onIgnoreFile(e.path)},children:[f.jsx(LA,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Ignore File"})]}),f.jsxs(Mn,{disabled:!w,onSelect:O=>{O.stopPropagation(),w&&p.onIgnoreFolder(e.path)},children:[f.jsx(LA,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Ignore folder..."})]}),f.jsx(e4,{}),f.jsxs(Mn,{onSelect:O=>{O.stopPropagation(),p.onCopyFilePath(e.path)},children:[f.jsx(jl,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Copy File Path"})]}),f.jsxs(Mn,{onSelect:O=>{O.stopPropagation(),p.onCopyRelativePath(e.path)},children:[f.jsx(jl,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Copy Relative Path"})]})]})]})}function Tve({projectId:e,diffs:t,editorLabel:n,diffRenderMode:r,wrapLines:i,onOpenFile:s,onOpenInFinder:o,onDiscardFile:l,onIgnoreFile:c,onIgnoreFolder:u,onCopyFilePath:p,onCopyRelativePath:h,onListBranches:g,onPreviewMergeBranch:b,onMergeBranch:x,onCheckoutBranch:_,onCreateBranch:w,onGenerateCommitMessage:C,onInitializeGit:E,onGetGitHubPublishInfo:k,onCheckGitHubRepoAvailability:R,onSetupGitHub:N,onCommit:A,onSyncWithRemote:M,onLoadPatch:D,onDiffRenderModeChange:U,onWrapLinesChange:j}){var Ye;const P=v.useMemo(()=>({onOpenFile:s,onOpenInFinder:o,onDiscardFile:l,onIgnoreFile:c,onIgnoreFolder:u,onCopyFilePath:p,onCopyRelativePath:h}),[s,o,l,c,u,p,h]),z=t.files.length>0,[O,$]=v.useState(!1),[V,B]=v.useState(null),[F,W]=v.useState(!1),[X,I]=v.useState(!1),[G,ee]=v.useState({}),[H,ue]=v.useState({}),[ae,J]=v.useState({}),te=v.useRef(null),ie=v.useRef({}),de=v.useMemo(()=>t.files.map(_e=>_e.path),[t.files]),he=v.useMemo(()=>de.join("\0"),[de]),Le=Li(_e=>{var Je;return e?((Je=_e.projectUi[e])==null?void 0:Je.viewMode)??(z?"changes":"history"):z?"changes":"history"}),ce=Li(_e=>{var Je;return e?((Je=_e.projectUi[e])==null?void 0:Je.collapsedPaths)??hv:hv}),De=Li(_e=>{var Je;return e?((Je=_e.projectUi[e])==null?void 0:Je.summary)??"":""}),pe=Li(_e=>{var Je;return e?((Je=_e.projectUi[e])==null?void 0:Je.description)??"":""}),st=Li(_e=>_e.reconcileCollapsedPaths),zt=Li(_e=>_e.toggleCollapsedPath),Et=Li(_e=>_e.setViewMode),Qt=Li(_e=>_e.setCommitDraft),Dt=Li(_e=>_e.clearCommitDraft),Tt=iv(_e=>e?_e.checkedPathsByProjectId[e]??hv:hv),mt=iv(_e=>_e.reconcileProject),At=iv(_e=>_e.setChecked),It=iv(_e=>_e.setAllChecked),ht=v.useRef(z);v.useEffect(()=>{e&&st(e,de)},[de,he,e,st]),v.useEffect(()=>{const _e=Object.fromEntries(t.files.map(et=>[et.path,et.patchDigest])),Je=et=>ie.current[et]===_e[et];ee(et=>Object.fromEntries(Object.entries(et).filter(([$e])=>de.includes($e)&&Je($e)))),ue(et=>Object.fromEntries(Object.entries(et).filter(([$e])=>de.includes($e)&&Je($e)))),J(et=>Object.fromEntries(Object.entries(et).filter(([$e])=>de.includes($e)&&Je($e)))),ie.current=_e},[t.files,de,he]),v.useEffect(()=>{e&&mt(e,de)},[de,he,e,mt]),v.useEffect(()=>{if(!e)return;if(ht.current!==z){Et(e,z?"changes":"history"),ht.current=z;return}ht.current=z},[z,e,Et]);const Ht=v.useMemo(()=>t.files.filter(_e=>Tt[_e.path]??!0).map(_e=>_e.path),[Tt,t.files]),ge=Ht.length,we=t.files.length>0&&ge===t.files.length,Be=ge>0&&ge<t.files.length,tt=De.trim(),Pe=tt.length>0,Ve=V!==null,qe=O||Ve,Xe=((Ye=t.branchHistory)==null?void 0:Ye.entries)??[],We=t.behindCount??0,gt=t.aheadCount??0,ot=t.hasUpstream===!0,Bt=t.hasUpstream===!1&&!!t.branchName,ut=t.hasOriginRemote===!0,on=t.branchName?t.branchName.split("/").map(_e=>encodeURIComponent(_e)).join("/"):null,cn=Bt?"publish":We>0?"pull":"fetch",vt=t.originRepoSlug&&on?`https://github.com/${t.originRepoSlug}/compare/${on}?expand=1`:null,Rt=!!(ot&&vt&&t.branchName&&t.branchName!==t.defaultBranchName),St=t.status==="ready"&&ge>0&&!qe,Ut=t.status==="ready"&&ge>0&&Pe&&!qe,xt=ut?"commit_and_push":"commit_only",ft=t.branchName??"current branch";async function Lt(_e){if(Ut){B(_e);try{const Je=await A({paths:Ht,summary:tt,description:pe.trim(),mode:_e});(Je!=null&&Je.ok||Je!=null&&Je.localCommitCreated)&&e&&Dt(e)}finally{B(null)}}}async function Pt(){if(St){$(!0);try{const _e=await C({paths:Ht});e&&Qt(e,{summary:_e.subject,description:_e.body})}finally{$(!1)}}}function Ie(_e){if(!(!(_e.metaKey||_e.ctrlKey)||_e.key!=="Enter")){if(_e.preventDefault(),Pe){Lt(xt);return}Pt()}}async function ze(_e=cn){if(!(t.status!=="ready"||F)){W(!0);try{await M(_e)}finally{W(!1)}}}const Te=v.useCallback(async _e=>{var Je;if(G[_e]!==void 0||ae[_e])return G[_e]??"";J(et=>({...et,[_e]:!0})),ue(et=>{if(!(_e in et))return et;const{[_e]:$e,...Mt}=et;return Mt});try{const et=await D(_e);ee(Mt=>({...Mt,[_e]:et}));const $e=(Je=t.files.find(Mt=>Mt.path===_e))==null?void 0:Je.patchDigest;return $e&&(ie.current={...ie.current,[_e]:$e}),et}catch(et){const $e=et instanceof Error?et.message:String(et);throw ue(Mt=>({...Mt,[_e]:$e})),et}finally{J(et=>{const{[_e]:$e,...Mt}=et;return Mt})}},[t.files,ae,D,G]);return f.jsx("div",{className:"h-full min-h-0 border-l border-border bg-background md:min-w-[370px]",children:f.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[f.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pl-2.5 pr-2 py-2",children:[f.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:f.jsx(kve,{currentBranchName:t.branchName,onListBranches:g,onPreviewMergeBranch:b,onMergeBranch:x,onCheckoutBranch:_,onCreateBranch:w})}),t.status==="ready"?ut?cn==="publish"?f.jsxs(Ge,{variant:"ghost",size:"sm",onClick:()=>void ze(),disabled:F,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[F?f.jsx(Cn,{className:"h-3.5 w-3.5 animate-spin"}):f.jsx(Pv,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Publish Branch"})]}):f.jsxs("div",{className:"flex items-center gap-1",children:[cn==="fetch"?f.jsxs(Yr,{delayDuration:0,children:[f.jsx(Xr,{asChild:!0,children:f.jsxs(Ge,{variant:"ghost",size:"sm",onClick:()=>void ze(),disabled:F,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[F?f.jsx(Cn,{className:"h-3.5 w-3.5 animate-spin"}):f.jsx(vG,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Fetch"})]})}),f.jsx(Br,{children:yve(t.lastFetchedAt)})]}):f.jsxs(Ge,{variant:"ghost",size:"sm",onClick:()=>void ze(),disabled:F,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[F?f.jsx(Cn,{className:"h-3.5 w-3.5 animate-spin"}):f.jsx(YC,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Pull"}),f.jsx("span",{className:"inline-flex min-w-4 items-center justify-center rounded-full bg-muted px-1 text-[10px] text-muted-foreground",children:We})]}),ot&&gt>0?f.jsxs(Ge,{variant:"default",size:"sm",onClick:()=>void ze("push"),disabled:F,className:"h-7 gap-1.5 px-2 text-xs",children:[F?f.jsx(Cn,{className:"h-3.5 w-3.5 animate-spin"}):f.jsx(Pv,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Push"}),f.jsx("span",{className:"inline-flex min-w-4 items-center justify-center rounded-full bg-primary-foreground/15 px-1 text-[10px] text-primary-foreground",children:gt})]}):null,Rt&&vt?f.jsxs(Ge,{variant:"ghost",size:"sm",onClick:()=>{typeof window>"u"||window.open(vt,"_blank","noopener,noreferrer")},className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[f.jsx(_5,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"PR"})]}):null]}):f.jsxs(Ge,{variant:"default",size:"sm",onClick:()=>I(!0),className:"h-7 gap-1.5 px-3 text-xs",children:[f.jsx(kW,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Push to GitHub"})]}):null]}),f.jsxs("div",{className:"relative min-h-0 flex-1",children:[f.jsx("div",{className:"sticky top-0 z-30 pl-[14px] pr-[12px] pt-[6px] bg-gradient-to-b from-background to-transparent",children:f.jsx("div",{className:"relative h-[40px] flex min-w-0 items-center justify-center gap-[13px]",children:f.jsxs("div",{className:"flex min-w-0 flex-1 items-center justify-between gap-[13px] relative",children:[Le==="changes"?f.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-muted-foreground/70",children:[f.jsx(OB,{checked:we,mixed:Be,label:Be?"Select all files for commit":we?"Unselect all files from commit":"Select all files for commit",onClick:()=>{!e||t.files.length===0||It(e,de,Be?!0:!we)}}),f.jsxs("span",{children:[ge," files"]})]}):f.jsx("div",{}),f.jsx("div",{className:"pointer-events-none absolute left-1/2 -translate-x-1/2 top-1/2 -translate-y-1/2",children:f.jsx("div",{className:"pointer-events-auto",children:f.jsx(da,{value:Le,onValueChange:_e=>{e&&Et(e,_e)},size:"sm",optionClassName:"flex-1 justify-center",options:[{value:"changes",label:"Changes"},{value:"history",label:"History"}]})})}),Le==="changes"?f.jsxs("div",{className:"flex items-center gap-1",children:[f.jsx(Vw,{label:"Unified diff",active:r==="unified",onClick:()=>U("unified"),children:f.jsx(_G,{className:"h-4 w-4"})}),f.jsx(Vw,{label:"Side-by-side diff",active:r==="split",onClick:()=>U("split"),children:f.jsx(jV,{className:"h-4 w-4"})}),f.jsx(Vw,{label:i?"Disable word wrap":"Enable word wrap",active:i,onClick:()=>j(!i),children:f.jsx(ZG,{className:"h-4 w-4"})})]}):f.jsx("div",{})]})})}),f.jsx("div",{ref:te,className:"h-full overflow-y-auto [scrollbar-gutter:stable]",children:t.status==="no_repo"?f.jsx("div",{className:"flex h-full items-center justify-center px-6 py-3 text-center",children:f.jsxs("div",{className:"flex max-w-[280px] flex-col items-center gap-3",children:[f.jsx("p",{className:"text-sm text-muted-foreground",children:"Initialize git here to start tracking branches, diffs, and history."}),f.jsx(Ge,{size:"sm",onClick:()=>void E(),children:"Init Git"})]})}):Le==="history"?Xe.length===0?f.jsx("div",{className:"flex h-full items-center justify-center px-6 py-3 text-center",children:f.jsxs("p",{className:"text-sm text-muted-foreground",children:["No recent commits on ",t.branchName??"this branch","."]})}):f.jsx("div",{className:"space-y-1.5 p-1.5",children:Xe.map((_e,Je)=>f.jsx(xve,{entry:_e,isPendingPush:Je<gt},_e.sha))}):t.files.length===0?f.jsx("div",{className:"flex h-full items-center justify-center px-6 py-3 text-center",children:f.jsx("p",{className:"text-sm text-muted-foreground",children:"No file changes."})}):f.jsxs("div",{className:"space-y-1.5 p-1.5 pb-10",children:[t.files.map(_e=>{const Je=ce[_e.path]??!0,et=Tt[_e.path]??!0;return f.jsx(Eve,{file:_e,rootRef:te,projectId:e,isCollapsed:Je,isChecked:et,editorLabel:n,diffRenderMode:r,wrapLines:i,onToggleCollapsed:()=>{e&&zt(e,_e.path)},onToggleChecked:()=>{e&&At(e,_e.path,!et)},fileActions:P,patch:G[_e.path],patchError:H[_e.path],isPatchLoading:!!ae[_e.path],onLoadPatch:Te},_e.path)}),Le==="changes"?f.jsxs("div",{className:"pointer-events-none sticky inset-x-0 bottom-11 py-1 pb-6 z-30 overflow-y-auto",children:[f.jsx("div",{className:"absolute inset-x-0 bottom-0 top-0 bg-gradient-to-t from-background to-transparent"}),f.jsx("div",{className:"pointer-events-auto relative",children:f.jsxs("div",{className:"space-y-0 rounded-xl mx-auto max-w-[700px]",children:[f.jsx(Kn,{value:De,onChange:_e=>{e&&Qt(e,{summary:_e.target.value,description:pe})},onKeyDown:Ie,placeholder:"Commit message (override)",className:"rounded-t-xl rounded-b-none px-3",disabled:qe||t.status!=="ready"}),f.jsx(d0,{value:pe,onChange:_e=>{e&&Qt(e,{summary:De,description:_e.target.value})},onKeyDown:Ie,placeholder:"Description",rows:5,className:"-mt-px rounded-t-none rounded-b-xl px-3 outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background mb-2",disabled:qe||t.status!=="ready"}),f.jsx("div",{className:"w-full flex flex-row",children:f.jsxs(Zc,{children:[f.jsx(Jc,{asChild:!0,children:f.jsx(Ge,{type:"button",className:"-mt-px w-full rounded-xl",disabled:Pe?!Ut:!St,onClick:()=>{if(Pe){Lt(xt);return}Pt()},children:f.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[Pe?Ve?f.jsx(Cn,{strokeWidth:2.5,className:"size-3 shrink-0 animate-spin"}):xt==="commit_and_push"?t.hasUpstream?f.jsx(Pv,{strokeWidth:2.5,className:"size-3 shrink-0"}):f.jsx(x5,{strokeWidth:2.5,className:"size-3 shrink-0"}):f.jsx(yi,{strokeWidth:2.5,className:"size-3 shrink-0"}):O?f.jsx(Cn,{strokeWidth:2.5,className:"size-3 shrink-0 animate-spin"}):f.jsx(sG,{strokeWidth:2.5,className:"size-3 shrink-0"}),f.jsx("span",{className:"min-w-0 truncate text-left",children:Pe?Ve?V==="commit_only"?"Committing...":"Committing & Pushing...":xt==="commit_only"?f.jsxs(f.Fragment,{children:["Commit to ",f.jsx(kc,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),ft]}):t.hasUpstream?f.jsxs(f.Fragment,{children:["Commit & push to ",f.jsx(kc,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),ft]}):f.jsxs(f.Fragment,{children:["Commit & publish ",f.jsx(kc,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),ft]}):O?"Generating...":f.jsxs(f.Fragment,{children:["Generate message for ",f.jsx(kc,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),ft]})})]})})}),t.hasUpstream?f.jsx(Fl,{children:f.jsx(Mn,{disabled:!Pe||!Ut,onSelect:_e=>{_e.stopPropagation(),Lt("commit_only")},children:"Commit Only"})}):null]})})]})})]}):null]})})]}),f.jsx(Sve,{open:X,onOpenChange:I,onGetGitHubPublishInfo:k,onCheckGitHubRepoAvailability:R,onPublish:N})]})})}const Rve=v.memo(Tve);function Nve(e,t){const n=getComputedStyle(e),r=parseFloat(n.fontSize);return t*r}function Ave(e,t){const n=getComputedStyle(e.ownerDocument.body),r=parseFloat(n.fontSize);return t*r}function Mve(e){return e/100*window.innerHeight}function Lve(e){return e/100*window.innerWidth}function jve(e){switch(typeof e){case"number":return[e,"px"];case"string":{const t=parseFloat(e);return e.endsWith("%")?[t,"%"]:e.endsWith("px")?[t,"px"]:e.endsWith("rem")?[t,"rem"]:e.endsWith("em")?[t,"em"]:e.endsWith("vh")?[t,"vh"]:e.endsWith("vw")?[t,"vw"]:[t,"%"]}}}function Lh({groupSize:e,panelElement:t,styleProp:n}){let r;const[i,s]=jve(n);switch(s){case"%":{r=i/100*e;break}case"px":{r=i;break}case"rem":{r=Ave(t,i);break}case"em":{r=Nve(t,i);break}case"vh":{r=Mve(i);break}case"vw":{r=Lve(i);break}}return r}function ji(e){return parseFloat(e.toFixed(3))}function Pd({group:e}){const{orientation:t,panels:n}=e;return n.reduce((r,i)=>(r+=t==="horizontal"?i.element.offsetWidth:i.element.offsetHeight,r),0)}function H1(e){const{panels:t}=e,n=Pd({group:e});return n===0?t.map(r=>({groupResizeBehavior:r.panelConstraints.groupResizeBehavior,collapsedSize:0,collapsible:r.panelConstraints.collapsible===!0,defaultSize:void 0,disabled:r.panelConstraints.disabled,minSize:0,maxSize:100,panelId:r.id})):t.map(r=>{const{element:i,panelConstraints:s}=r;let o=0;if(s.collapsedSize!==void 0){const p=Lh({groupSize:n,panelElement:i,styleProp:s.collapsedSize});o=ji(p/n*100)}let l;if(s.defaultSize!==void 0){const p=Lh({groupSize:n,panelElement:i,styleProp:s.defaultSize});l=ji(p/n*100)}let c=0;if(s.minSize!==void 0){const p=Lh({groupSize:n,panelElement:i,styleProp:s.minSize});c=ji(p/n*100)}let u=100;if(s.maxSize!==void 0){const p=Lh({groupSize:n,panelElement:i,styleProp:s.maxSize});u=ji(p/n*100)}return{groupResizeBehavior:s.groupResizeBehavior,collapsedSize:o,collapsible:s.collapsible===!0,defaultSize:l,disabled:s.disabled,minSize:c,maxSize:u,panelId:r.id}})}function An(e,t="Assertion error"){if(!e)throw Error(t)}function U1(e,t){return Array.from(t).sort(e==="horizontal"?Dve:Ive)}function Dve(e,t){const n=e.element.offsetLeft-t.element.offsetLeft;return n!==0?n:e.element.offsetWidth-t.element.offsetWidth}function Ive(e,t){const n=e.element.offsetTop-t.element.offsetTop;return n!==0?n:e.element.offsetHeight-t.element.offsetHeight}function BB(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.ELEMENT_NODE}function FB(e,t){return{x:e.x>=t.left&&e.x<=t.right?0:Math.min(Math.abs(e.x-t.left),Math.abs(e.x-t.right)),y:e.y>=t.top&&e.y<=t.bottom?0:Math.min(Math.abs(e.y-t.top),Math.abs(e.y-t.bottom))}}function Pve({orientation:e,rects:t,targetRect:n}){const r={x:n.x+n.width/2,y:n.y+n.height/2};let i,s=Number.MAX_VALUE;for(const o of t){const{x:l,y:c}=FB(r,o),u=e==="horizontal"?l:c;u<s&&(s=u,i=o)}return An(i,"No rect found"),i}let pv;function Ove(){return pv===void 0&&(typeof matchMedia=="function"?pv=!!matchMedia("(pointer:coarse)").matches:pv=!1),pv}function $B(e){const{element:t,orientation:n,panels:r,separators:i}=e,s=U1(n,Array.from(t.children).filter(BB).map(x=>({element:x}))).map(({element:x})=>x),o=[];let l=!1,c=!1,u=-1,p=-1,h=0,g,b=[];{let x=-1;for(const _ of s)_.hasAttribute("data-panel")&&(x++,_.ariaDisabled===null&&(h++,u===-1&&(u=x),p=x))}if(h>1){let x=-1;for(const _ of s)if(_.hasAttribute("data-panel")){x++;const w=r.find(C=>C.element===_);if(w){if(g){const C=g.element.getBoundingClientRect(),E=_.getBoundingClientRect();let k;if(c){const R=n==="horizontal"?new DOMRect(C.right,C.top,0,C.height):new DOMRect(C.left,C.bottom,C.width,0),N=n==="horizontal"?new DOMRect(E.left,E.top,0,E.height):new DOMRect(E.left,E.top,E.width,0);switch(b.length){case 0:{k=[R,N];break}case 1:{const A=b[0],M=Pve({orientation:n,rects:[C,E],targetRect:A.element.getBoundingClientRect()});k=[A,M===C?N:R];break}default:{k=b;break}}}else b.length?k=b:k=[n==="horizontal"?new DOMRect(C.right,E.top,E.left-C.right,E.height):new DOMRect(E.left,C.bottom,E.width,E.top-C.bottom)];for(const R of k){let N="width"in R?R:R.element.getBoundingClientRect();const A=Ove()?e.resizeTargetMinimumSize.coarse:e.resizeTargetMinimumSize.fine;if(N.width<A){const D=A-N.width;N=new DOMRect(N.x-D/2,N.y,N.width+D,N.height)}if(N.height<A){const D=A-N.height;N=new DOMRect(N.x,N.y-D/2,N.width,N.height+D)}const M=x<=u||x>p;!l&&!M&&o.push({group:e,groupSize:Pd({group:e}),panels:[g,w],separator:"width"in R?void 0:R,rect:N}),l=!1}}c=!1,g=w,b=[]}}else if(_.hasAttribute("data-separator")){_.ariaDisabled!==null&&(l=!0);const w=i.find(C=>C.element===_);w?b.push(w):(g=void 0,b=[])}else c=!0}return o}var El,UP;let HB=(UP=class{constructor(){ll(this,El,{})}addListener(t,n){const r=br(this,El)[t];return r===void 0?br(this,El)[t]=[n]:r.includes(n)||r.push(n),()=>{this.removeListener(t,n)}}emit(t,n){const r=br(this,El)[t];if(r!==void 0)if(r.length===1)r[0].call(null,n);else{let i=!1,s=null;const o=Array.from(r);for(let l=0;l<o.length;l++){const c=o[l];try{c.call(null,n)}catch(u){s===null&&(i=!0,s=u)}}if(i)throw s}}removeAllListeners(){hs(this,El,{})}removeListener(t,n){const r=br(this,El)[t];if(r!==void 0){const i=r.indexOf(n);i>=0&&r.splice(i,1)}}},El=new WeakMap,UP),Ro=new Map;const UB=new HB;function zve(e){Ro=new Map(Ro),Ro.delete(e)}function lD(e,t){for(const[n]of Ro)if(n.id===e)return n}function Al(e,t){for(const[n,r]of Ro)if(n.id===e)return r;if(t)throw Error(`Could not find data for Group with id ${e}`)}function nu(){return Ro}function ZE(e,t){return UB.addListener("groupChange",n=>{n.group.id===e&&t(n)})}function ka(e,t){const n=Ro.get(e);Ro=new Map(Ro),Ro.set(e,t),UB.emit("groupChange",{group:e,prev:n,next:t})}function Bve(e,t,n){let r,i={x:1/0,y:1/0};for(const s of t){const o=FB(n,s.rect);switch(e){case"horizontal":{o.x<=i.x&&(r=s,i=o);break}case"vertical":{o.y<=i.y&&(r=s,i=o);break}}}return r?{distance:i,hitRegion:r}:void 0}function Fve(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function $ve(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:dD(e),b:dD(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();An(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:uD(cD(n.a)),b:uD(cD(n.b))};if(i.a===i.b){const s=r.childNodes,o={a:n.a.at(-1),b:n.b.at(-1)};let l=s.length;for(;l--;){const c=s[l];if(c===o.a)return 1;if(c===o.b)return-1}}return Math.sign(i.a-i.b)}const Hve=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function Uve(e){const t=getComputedStyle(VB(e)??e).display;return t==="flex"||t==="inline-flex"}function Vve(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||Uve(e))||+t.opacity<1||"transform"in t&&t.transform!=="none"||"webkitTransform"in t&&t.webkitTransform!=="none"||"mixBlendMode"in t&&t.mixBlendMode!=="normal"||"filter"in t&&t.filter!=="none"||"webkitFilter"in t&&t.webkitFilter!=="none"||"isolation"in t&&t.isolation==="isolate"||Hve.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function cD(e){let t=e.length;for(;t--;){const n=e[t];if(An(n,"Missing node"),Vve(n))return n}return null}function uD(e){return e&&Number(getComputedStyle(e).zIndex)||0}function dD(e){const t=[];for(;e;)t.push(e),e=VB(e);return t}function VB(e){const{parentNode:t}=e;return Fve(t)?t.host:t}function Wve(e,t){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function Gve({groupElement:e,hitRegion:t,pointerEventTarget:n}){if(!BB(n)||n.contains(e)||e.contains(n))return!0;if($ve(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if(Wve(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function JE(e,t){const n=[];return t.forEach((r,i)=>{if(i.disabled)return;const s=$B(i),o=Bve(i.orientation,s,{x:e.clientX,y:e.clientY});o&&o.distance.x<=0&&o.distance.y<=0&&Gve({groupElement:i.element,hitRegion:o.hitRegion.rect,pointerEventTarget:e.target})&&n.push(o.hitRegion)}),n}function qve(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function pi(e,t,n=0){return Math.abs(ji(e)-ji(t))<=n}function So(e,t){return pi(e,t)?0:e>t?1:-1}function ud({overrideDisabledPanels:e,panelConstraints:t,prevSize:n,size:r}){const{collapsedSize:i=0,collapsible:s,disabled:o,maxSize:l=100,minSize:c=0}=t;if(o&&!e)return n;if(So(r,c)<0)if(s){const u=(i+c)/2;So(r,u)<0?r=i:r=c}else r=c;return r=Math.min(l,r),r=ji(r),r}function Np({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(pi(e,0))return t;const o=s==="imperative-api",l=Object.values(t),c=Object.values(i),u=[...l],[p,h]=r;An(p!=null,"Invalid first pivot index"),An(h!=null,"Invalid second pivot index");let g=0;switch(s){case"keyboard":{{const _=e<0?h:p,w=n[_];An(w,`Panel constraints not found for index ${_}`);const{collapsedSize:C=0,collapsible:E,minSize:k=0}=w;if(E){const R=l[_];if(An(R!=null,`Previous layout not found for panel index ${_}`),pi(R,C)){const N=k-R;So(N,Math.abs(e))>0&&(e=e<0?0-N:N)}}}{const _=e<0?p:h,w=n[_];An(w,`No panel constraints found for index ${_}`);const{collapsedSize:C=0,collapsible:E,minSize:k=0}=w;if(E){const R=l[_];if(An(R!=null,`Previous layout not found for panel index ${_}`),pi(R,k)){const N=R-C;So(N,Math.abs(e))>0&&(e=e<0?0-N:N)}}}break}default:{const _=e<0?h:p,w=n[_];An(w,`Panel constraints not found for index ${_}`);const C=l[_],{collapsible:E,collapsedSize:k,minSize:R}=w;if(E&&So(C,R)<0)if(e>0){const N=R-k,A=N/2,M=C+e;So(M,R)<0&&(e=So(e,A)<=0?0:N)}else{const N=R-k,A=100-N/2,M=C-e;So(M,R)<0&&(e=So(100+e,A)>0?0:-N)}break}}{const _=e<0?1:-1;let w=e<0?h:p,C=0;for(;;){const k=l[w];An(k!=null,`Previous layout not found for panel index ${w}`);const R=ud({overrideDisabledPanels:o,panelConstraints:n[w],prevSize:k,size:100})-k;if(C+=R,w+=_,w<0||w>=n.length)break}const E=Math.min(Math.abs(e),Math.abs(C));e=e<0?0-E:E}{let _=e<0?p:h;for(;_>=0&&_<n.length;){const w=Math.abs(e)-Math.abs(g),C=l[_];An(C!=null,`Previous layout not found for panel index ${_}`);const E=C-w,k=ud({overrideDisabledPanels:o,panelConstraints:n[_],prevSize:C,size:E});if(!pi(C,k)&&(g+=C-k,u[_]=k,g.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?_--:_++}}if(qve(c,u))return i;{const _=e<0?h:p,w=l[_];An(w!=null,`Previous layout not found for panel index ${_}`);const C=w+g,E=ud({overrideDisabledPanels:o,panelConstraints:n[_],prevSize:w,size:C});if(u[_]=E,!pi(E,C)){let k=C-E,R=e<0?h:p;for(;R>=0&&R<n.length;){const N=u[R];An(N!=null,`Previous layout not found for panel index ${R}`);const A=N+k,M=ud({overrideDisabledPanels:o,panelConstraints:n[R],prevSize:N,size:A});if(pi(N,M)||(k-=M-N,u[R]=M),pi(k,0))break;e>0?R--:R++}}}const b=Object.values(u).reduce((_,w)=>w+_,0);if(!pi(b,100,.1))return i;const x=Object.keys(i);return u.reduce((_,w,C)=>(_[x[C]]=w,_),{})}function Hc(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(t[n]===void 0||So(e[n],t[n])!==0)return!1;return!0}function Uc({layout:e,panelConstraints:t}){const n=Object.values(e),r=[...n],i=r.reduce((l,c)=>l+c,0);if(r.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${r.map(l=>`${l}%`).join(", ")}`);if(!pi(i,100)&&r.length>0)for(let l=0;l<t.length;l++){const c=r[l];An(c!=null,`No layout data found for index ${l}`);const u=100/i*c;r[l]=u}let s=0;for(let l=0;l<t.length;l++){const c=n[l];An(c!=null,`No layout data found for index ${l}`);const u=r[l];An(u!=null,`No layout data found for index ${l}`);const p=ud({overrideDisabledPanels:!0,panelConstraints:t[l],prevSize:c,size:u});u!=p&&(s+=u-p,r[l]=p)}if(!pi(s,0))for(let l=0;l<t.length;l++){const c=r[l];An(c!=null,`No layout data found for index ${l}`);const u=c+s,p=ud({overrideDisabledPanels:!0,panelConstraints:t[l],prevSize:c,size:u});if(c!==p&&(s-=p-c,r[l]=p,pi(s,0)))break}const o=Object.keys(e);return r.reduce((l,c,u)=>(l[o[u]]=c,l),{})}function WB({groupId:e,panelId:t}){const n=()=>{const l=nu();for(const[c,{defaultLayoutDeferred:u,derivedPanelConstraints:p,layout:h,groupSize:g,separatorToPanels:b}]of l)if(c.id===e)return{defaultLayoutDeferred:u,derivedPanelConstraints:p,group:c,groupSize:g,layout:h,separatorToPanels:b};throw Error(`Group ${e} not found`)},r=()=>{const l=n().derivedPanelConstraints.find(c=>c.panelId===t);if(l!==void 0)return l;throw Error(`Panel constraints not found for Panel ${t}`)},i=()=>{const l=n().group.panels.find(c=>c.id===t);if(l!==void 0)return l;throw Error(`Layout not found for Panel ${t}`)},s=()=>{const l=n().layout[t];if(l!==void 0)return l;throw Error(`Layout not found for Panel ${t}`)},o=l=>{const c=s();if(l===c)return;const{defaultLayoutDeferred:u,derivedPanelConstraints:p,group:h,groupSize:g,layout:b,separatorToPanels:x}=n(),_=h.panels.findIndex(k=>k.id===t),w=_===h.panels.length-1,C=Np({delta:w?c-l:l-c,initialLayout:b,panelConstraints:p,pivotIndices:w?[_-1,_]:[_,_+1],prevLayout:b,trigger:"imperative-api"}),E=Uc({layout:C,panelConstraints:p});Hc(b,E)||ka(h,{defaultLayoutDeferred:u,derivedPanelConstraints:p,groupSize:g,layout:E,separatorToPanels:x})};return{collapse:()=>{const{collapsible:l,collapsedSize:c}=r(),{mutableValues:u}=i(),p=s();l&&p!==c&&(u.expandToSize=p,o(c))},expand:()=>{const{collapsible:l,collapsedSize:c,minSize:u}=r(),{mutableValues:p}=i(),h=s();if(l&&h===c){let g=p.expandToSize??u;g===0&&(g=1),o(g)}},getSize:()=>{const{group:l}=n(),c=s(),{element:u}=i(),p=l.orientation==="horizontal"?u.offsetWidth:u.offsetHeight;return{asPercentage:c,inPixels:p}},isCollapsed:()=>{const{collapsible:l,collapsedSize:c}=r(),u=s();return l&&pi(c,u)},resize:l=>{const{group:c}=n(),{element:u}=i(),p=Pd({group:c}),h=Lh({groupSize:p,panelElement:u,styleProp:l}),g=ji(h/p*100);o(g)}}}function fD(e){if(e.defaultPrevented)return;const t=nu();JE(e,t).forEach(n=>{if(n.separator){const r=n.panels.find(i=>i.panelConstraints.defaultSize!==void 0);if(r){const i=r.panelConstraints.defaultSize,s=WB({groupId:n.group.id,panelId:r.id});s&&i!==void 0&&(s.resize(i),e.preventDefault())}}})}function Qv(e){const t=nu();for(const[n]of t)if(n.separators.some(r=>r.element===e))return n;throw Error("Could not find parent Group for separator element")}function GB({groupId:e}){const t=()=>{const n=nu();for(const[r,i]of n)if(r.id===e)return{group:r,...i};throw Error(`Could not find Group with id "${e}"`)};return{getLayout(){const{defaultLayoutDeferred:n,layout:r}=t();return n?{}:r},setLayout(n){const{defaultLayoutDeferred:r,derivedPanelConstraints:i,group:s,groupSize:o,layout:l,separatorToPanels:c}=t(),u=Uc({layout:n,panelConstraints:i});return r?l:(Hc(l,u)||ka(s,{defaultLayoutDeferred:r,derivedPanelConstraints:i,groupSize:o,layout:u,separatorToPanels:c}),u)}}}function mc(e,t){const n=Qv(e),r=Al(n.id,!0),i=n.separators.find(p=>p.element===e);An(i,"Matching separator not found");const s=r.separatorToPanels.get(i);An(s,"Matching panels not found");const o=s.map(p=>n.panels.indexOf(p)),l=GB({groupId:n.id}).getLayout(),c=Np({delta:t,initialLayout:l,panelConstraints:r.derivedPanelConstraints,pivotIndices:o,prevLayout:l,trigger:"keyboard"}),u=Uc({layout:c,panelConstraints:r.derivedPanelConstraints});Hc(l,u)||ka(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedPanelConstraints:r.derivedPanelConstraints,groupSize:r.groupSize,layout:u,separatorToPanels:r.separatorToPanels})}function hD(e){if(e.defaultPrevented)return;const t=e.currentTarget,n=Qv(t);if(!n.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),n.orientation==="vertical"&&mc(t,5);break}case"ArrowLeft":{e.preventDefault(),n.orientation==="horizontal"&&mc(t,-5);break}case"ArrowRight":{e.preventDefault(),n.orientation==="horizontal"&&mc(t,5);break}case"ArrowUp":{e.preventDefault(),n.orientation==="vertical"&&mc(t,-5);break}case"End":{e.preventDefault(),mc(t,100);break}case"Enter":{e.preventDefault();const r=Qv(t),i=Al(r.id,!0),{derivedPanelConstraints:s,layout:o,separatorToPanels:l}=i,c=r.separators.find(g=>g.element===t);An(c,"Matching separator not found");const u=l.get(c);An(u,"Matching panels not found");const p=u[0],h=s.find(g=>g.panelId===p.id);if(An(h,"Panel metadata not found"),h.collapsible){const g=o[p.id],b=h.collapsedSize===g?r.mutableState.expandedPanelSizes[p.id]??h.minSize:h.collapsedSize;mc(t,b-g)}break}case"F6":{e.preventDefault();const r=Qv(t).separators.map(o=>o.element),i=Array.from(r).findIndex(o=>o===e.currentTarget);An(i!==null,"Index not found");const s=e.shiftKey?i>0?i-1:r.length-1:i+1<r.length?i+1:0;r[s].focus({preventScroll:!0});break}case"Home":{e.preventDefault(),mc(t,-100);break}}}let Sd={cursorFlags:0,state:"inactive"};const e2=new HB;function Vc(){return Sd}function Kve(e){return e2.addListener("change",e)}function Yve(e){const t=Sd,n={...Sd};n.cursorFlags=e,Sd=n,e2.emit("change",{prev:t,next:n})}function Cd(e){const t=Sd;Sd=e,e2.emit("change",{prev:t,next:e})}function pD(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=nu(),n=JE(e,t),r=new Map;let i=!1;n.forEach(s=>{s.separator&&(i||(i=!0,s.separator.element.focus({preventScroll:!0})));const o=t.get(s.group);o&&r.set(s.group,o.layout)}),Cd({cursorFlags:0,hitRegions:n,initialLayoutMap:r,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}),n.length&&e.preventDefault()}const Xve=e=>e,Ww=()=>{},qB=1,KB=2,YB=4,XB=8,mD=3,gD=12;let mv;function vD(){return mv===void 0&&(mv=!1,typeof window<"u"&&(window.navigator.userAgent.includes("Chrome")||window.navigator.userAgent.includes("Firefox"))&&(mv=!0)),mv}function Qve({cursorFlags:e,groups:t,state:n}){let r=0,i=0;switch(n){case"active":case"hover":t.forEach(s=>{if(!s.mutableState.disableCursor)switch(s.orientation){case"horizontal":{r++;break}case"vertical":{i++;break}}})}if(!(r===0&&i===0)){switch(n){case"active":{if(e&&vD()){const s=(e&qB)!==0,o=(e&KB)!==0,l=(e&YB)!==0,c=(e&XB)!==0;if(s)return l?"se-resize":c?"ne-resize":"e-resize";if(o)return l?"sw-resize":c?"nw-resize":"w-resize";if(l)return"s-resize";if(c)return"n-resize"}break}}return vD()?r>0&&i>0?"move":r>0?"ew-resize":"ns-resize":r>0&&i>0?"grab":r>0?"col-resize":"row-resize"}}const bD=new WeakMap;function t2(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:n}=bD.get(e)??{};n===void 0&&(n=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets&&e.adoptedStyleSheets.push(n));const r=Vc();switch(r.state){case"active":case"hover":{const i=Qve({cursorFlags:r.cursorFlags,groups:r.hitRegions.map(o=>o.group),state:r.state}),s=`*, *:hover {cursor: ${i} !important; }`;if(t===s)return;t=s,i?n.cssRules.length===0?n.insertRule(s):n.replaceSync(s):n.cssRules.length===1&&n.deleteRule(0);break}case"inactive":{t=void 0,n.cssRules.length===1&&n.deleteRule(0);break}}bD.set(e,{prevStyle:t,styleSheet:n})}function QB({document:e,event:t,hitRegions:n,initialLayoutMap:r,mountedGroups:i,pointerDownAtPoint:s,prevCursorFlags:o}){let l=0;n.forEach(u=>{const{group:p,groupSize:h}=u,{orientation:g,panels:b}=p,{disableCursor:x}=p.mutableState;let _=0;s?g==="horizontal"?_=(t.clientX-s.x)/h*100:_=(t.clientY-s.y)/h*100:g==="horizontal"?_=t.clientX<0?-100:100:_=t.clientY<0?-100:100;const w=r.get(p),C=i.get(p);if(!w||!C)return;const{defaultLayoutDeferred:E,derivedPanelConstraints:k,groupSize:R,layout:N,separatorToPanels:A}=C;if(k&&N&&A){const M=Np({delta:_,initialLayout:w,panelConstraints:k,pivotIndices:u.panels.map(D=>b.indexOf(D)),prevLayout:N,trigger:"mouse-or-touch"});if(Hc(M,N)){if(_!==0&&!x)switch(g){case"horizontal":{l|=_<0?qB:KB;break}case"vertical":{l|=_<0?YB:XB;break}}}else ka(u.group,{defaultLayoutDeferred:E,derivedPanelConstraints:k,groupSize:R,layout:M,separatorToPanels:A})}});let c=0;t.movementX===0?c|=o&mD:c|=l&mD,t.movementY===0?c|=o&gD:c|=l&gD,Yve(c),t2(e)}function yD(e){const t=nu(),n=Vc();switch(n.state){case"active":QB({document:e.currentTarget,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedGroups:t,prevCursorFlags:n.cursorFlags})}}function xD(e){if(e.defaultPrevented)return;const t=Vc(),n=nu();switch(t.state){case"active":{if(e.buttons===0){Cd({cursorFlags:0,state:"inactive"}),t.hitRegions.forEach(r=>{const i=Al(r.group.id,!0);ka(r.group,i)});return}QB({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break}default:{const r=JE(e,n);r.length===0?t.state!=="inactive"&&Cd({cursorFlags:0,state:"inactive"}):Cd({cursorFlags:0,hitRegions:r,state:"hover"}),t2(e.currentTarget);break}}}function _D(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(Vc().state){case"hover":Cd({cursorFlags:0,state:"inactive"})}}function wD(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=Vc();switch(t.state){case"active":Cd({cursorFlags:0,state:"inactive"}),t.hitRegions.length>0&&(t2(e.currentTarget),t.hitRegions.forEach(n=>{const r=Al(n.group.id,!0);ka(n.group,r)}),e.preventDefault())}}function SD(e){let t=0,n=0;const r={};for(const s of e)if(s.defaultSize!==void 0){t++;const o=ji(s.defaultSize);n+=o,r[s.panelId]=o}else r[s.panelId]=void 0;const i=e.length-t;if(i!==0){const s=ji((100-n)/i);for(const o of e)o.defaultSize===void 0&&(r[o.panelId]=s)}return r}function Zve(e,t,n){if(!n[0])return;const r=e.panels.find(c=>c.element===t);if(!r||!r.onResize)return;const i=Pd({group:e}),s=e.orientation==="horizontal"?r.element.offsetWidth:r.element.offsetHeight,o=r.mutableValues.prevSize,l={asPercentage:ji(s/i*100),inPixels:s};r.mutableValues.prevSize=l,r.onResize(l,r.id,o)}function Jve(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(e[n]!==t[n])return!1;return!0}function ebe({group:e,nextGroupSize:t,prevGroupSize:n,prevLayout:r}){if(n<=0||t<=0||n===t)return r;let i=0,s=0,o=!1;const l=new Map,c=[];for(const h of e.panels){const g=r[h.id]??0;switch(h.panelConstraints.groupResizeBehavior){case"preserve-pixel-size":{o=!0;const b=g/100*n,x=ji(b/t*100);l.set(h.id,x),i+=x;break}case"preserve-relative-size":default:{c.push(h.id),s+=g;break}}}if(!o||c.length===0)return r;const u=100-i,p={...r};if(l.forEach((h,g)=>{p[g]=h}),s>0)for(const h of c){const g=r[h]??0;p[h]=ji(g/s*u)}else{const h=ji(u/c.length);for(const g of c)p[g]=h}return p}function tbe(e,t){const n=e.map(i=>i.id),r=Object.keys(t);if(n.length!==r.length)return!1;for(const i of n)if(!r.includes(i))return!1;return!0}const Xu=new Map;function nbe(e){let t=!0;An(e.element.ownerDocument.defaultView,"Cannot register an unmounted Group");const n=e.element.ownerDocument.defaultView.ResizeObserver,r=new Set,i=new Set,s=new n(x=>{for(const _ of x){const{borderBoxSize:w,target:C}=_;if(C===e.element){if(t){const E=Pd({group:e});if(E===0)return;const k=Al(e.id);if(!k)return;const R=H1(e),N=k.defaultLayoutDeferred?SD(R):k.layout,A=ebe({group:e,nextGroupSize:E,prevGroupSize:k.groupSize,prevLayout:N}),M=Uc({layout:A,panelConstraints:R});if(!k.defaultLayoutDeferred&&Hc(k.layout,M)&&Jve(k.derivedPanelConstraints,R)&&k.groupSize===E)return;ka(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:R,groupSize:E,layout:M,separatorToPanels:k.separatorToPanels})}}else Zve(e,C,w)}});s.observe(e.element),e.panels.forEach(x=>{An(!r.has(x.id),`Panel ids must be unique; id "${x.id}" was used more than once`),r.add(x.id),x.onResize&&s.observe(x.element)});const o=Pd({group:e}),l=H1(e),c=e.panels.map(({id:x})=>x).join(",");let u=e.mutableState.defaultLayout;u&&(tbe(e.panels,u)||(u=void 0));const p=e.mutableState.layouts[c]??u??SD(l),h=Uc({layout:p,panelConstraints:l}),g=e.element.ownerDocument;Xu.set(g,(Xu.get(g)??0)+1);const b=new Map;return $B(e).forEach(x=>{x.separator&&b.set(x.separator,x.panels)}),ka(e,{defaultLayoutDeferred:o===0,derivedPanelConstraints:l,groupSize:o,layout:h,separatorToPanels:b}),e.separators.forEach(x=>{An(!i.has(x.id),`Separator ids must be unique; id "${x.id}" was used more than once`),i.add(x.id),x.element.addEventListener("keydown",hD)}),Xu.get(g)===1&&(g.addEventListener("dblclick",fD,!0),g.addEventListener("pointerdown",pD,!0),g.addEventListener("pointerleave",yD),g.addEventListener("pointermove",xD),g.addEventListener("pointerout",_D),g.addEventListener("pointerup",wD,!0)),function(){t=!1,Xu.set(g,Math.max(0,(Xu.get(g)??0)-1)),zve(e),e.separators.forEach(x=>{x.element.removeEventListener("keydown",hD)}),Xu.get(g)||(g.removeEventListener("dblclick",fD,!0),g.removeEventListener("pointerdown",pD,!0),g.removeEventListener("pointerleave",yD),g.removeEventListener("pointermove",xD),g.removeEventListener("pointerout",_D),g.removeEventListener("pointerup",wD,!0)),s.disconnect()}}function rbe(){const[e,t]=v.useState({}),n=v.useCallback(()=>t({}),[]);return[e,n]}function n2(e){const t=v.useId();return`${e??t}`}const ru=typeof window<"u"?v.useLayoutEffect:v.useEffect;function Xh(e){const t=v.useRef(e);return ru(()=>{t.current=e},[e]),v.useCallback((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[t])}function r2(...e){return Xh(t=>{e.forEach(n=>{if(n)switch(typeof n){case"function":{n(t);break}case"object":{n.current=t;break}}})})}function i2(e){const t=v.useRef({...e});return ru(()=>{for(const n in e)t.current[n]=e[n]},[e]),t.current}const ZB=v.createContext(null);function ibe(e,t){const n=v.useRef({getLayout:()=>({}),setLayout:Xve});v.useImperativeHandle(t,()=>n.current,[]),ru(()=>{Object.assign(n.current,GB({groupId:e}))})}function JB({children:e,className:t,defaultLayout:n,disableCursor:r,disabled:i,elementRef:s,groupRef:o,id:l,onLayoutChange:c,onLayoutChanged:u,orientation:p="horizontal",resizeTargetMinimumSize:h={coarse:20,fine:10},style:g,...b}){const x=v.useRef({onLayoutChange:{},onLayoutChanged:{}}),_=Xh(P=>{Hc(x.current.onLayoutChange,P)||(x.current.onLayoutChange=P,c==null||c(P))}),w=Xh(P=>{Hc(x.current.onLayoutChanged,P)||(x.current.onLayoutChanged=P,u==null||u(P))}),C=n2(l),E=v.useRef(null),[k,R]=rbe(),N=v.useRef({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:h,separators:[]}),A=r2(E,s);ibe(C,o);const M=Xh((P,z)=>{const O=Vc(),$=lD(P),V=Al(P);if(V){let B=!1;switch(O.state){case"active":{B=O.hitRegions.some(F=>F.group===$);break}}return{flexGrow:V.layout[z]??1,pointerEvents:B?"none":void 0}}return{flexGrow:(n==null?void 0:n[z])??1}}),D=i2({defaultLayout:n,disableCursor:r}),U=v.useMemo(()=>({get disableCursor(){return!!D.disableCursor},getPanelStyles:M,id:C,orientation:p,registerPanel:P=>{const z=N.current;return z.panels=U1(p,[...z.panels,P]),R(),()=>{z.panels=z.panels.filter(O=>O!==P),R()}},registerSeparator:P=>{const z=N.current;return z.separators=U1(p,[...z.separators,P]),R(),()=>{z.separators=z.separators.filter(O=>O!==P),R()}},togglePanelDisabled:(P,z)=>{const O=N.current.panels.find(B=>B.id===P);O&&(O.panelConstraints.disabled=z);const $=lD(C),V=Al(C);$&&V&&ka($,{...V,derivedPanelConstraints:H1($)})},toggleSeparatorDisabled:(P,z)=>{const O=N.current.separators.find($=>$.id===P);O&&(O.disabled=z)}}),[M,C,R,p,D]),j=v.useRef(null);return ru(()=>{const P=E.current;if(P===null)return;const z=N.current;let O;if(D.defaultLayout!==void 0&&Object.keys(D.defaultLayout).length===z.panels.length){O={};for(const I of z.panels){const G=D.defaultLayout[I.id];G!==void 0&&(O[I.id]=G)}}const $={disabled:!!i,element:P,id:C,mutableState:{defaultLayout:O,disableCursor:!!D.disableCursor,expandedPanelSizes:N.current.lastExpandedPanelSizes,layouts:N.current.layouts},orientation:p,panels:z.panels,resizeTargetMinimumSize:z.resizeTargetMinimumSize,separators:z.separators};j.current=$;const V=nbe($),{defaultLayoutDeferred:B,derivedPanelConstraints:F,layout:W}=Al($.id,!0);!B&&F.length>0&&(_(W),w(W));const X=ZE(C,I=>{const{defaultLayoutDeferred:G,derivedPanelConstraints:ee,layout:H}=I.next;if(G||ee.length===0)return;const ue=$.panels.map(({id:J})=>J).join(",");$.mutableState.layouts[ue]=H,ee.forEach(J=>{if(J.collapsible){const{layout:te}=I.prev??{};if(te){const ie=pi(J.collapsedSize,H[J.panelId]),de=pi(J.collapsedSize,te[J.panelId]);ie&&!de&&($.mutableState.expandedPanelSizes[J.panelId]=te[J.panelId])}}});const ae=Vc().state!=="active";_(H),ae&&w(H)});return()=>{j.current=null,V(),X()}},[i,C,w,_,p,k,D]),v.useEffect(()=>{const P=j.current;P&&(P.mutableState.defaultLayout=n,P.mutableState.disableCursor=!!r)}),f.jsx(ZB.Provider,{value:U,children:f.jsx("div",{...b,className:t,"data-group":!0,"data-testid":C,id:C,ref:A,style:{height:"100%",width:"100%",overflow:"hidden",...g,display:"flex",flexDirection:p==="horizontal"?"row":"column",flexWrap:"nowrap",touchAction:p==="horizontal"?"pan-y":"pan-x"},children:e})})}JB.displayName="Group";function s2(){const e=v.useContext(ZB);return An(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function sbe(e,t){const{id:n}=s2(),r=v.useRef({collapse:Ww,expand:Ww,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:Ww});v.useImperativeHandle(t,()=>r.current,[]),ru(()=>{Object.assign(r.current,WB({groupId:n,panelId:e}))})}function eF({children:e,className:t,collapsedSize:n="0%",collapsible:r=!1,defaultSize:i,disabled:s,elementRef:o,groupResizeBehavior:l="preserve-relative-size",id:c,maxSize:u="100%",minSize:p="0%",onResize:h,panelRef:g,style:b,...x}){const _=!!c,w=n2(c),C=i2({disabled:s}),E=v.useRef(null),k=r2(E,o),{getPanelStyles:R,id:N,orientation:A,registerPanel:M,togglePanelDisabled:D}=s2(),U=h!==null,j=Xh((z,O,$)=>{h==null||h(z,c,$)});ru(()=>{const z=E.current;if(z!==null){const O={element:z,id:w,idIsStable:_,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:U?j:void 0,panelConstraints:{groupResizeBehavior:l,collapsedSize:n,collapsible:r,defaultSize:i,disabled:C.disabled,maxSize:u,minSize:p}};return M(O)}},[l,n,r,i,U,w,_,u,p,j,M,C]),v.useEffect(()=>{D(w,!!s)},[s,w,D]),sbe(w,g);const P=v.useSyncExternalStore(z=>ZE(N,z),()=>JSON.stringify(R(N,w)),()=>JSON.stringify(R(N,w)));return f.jsx("div",{...x,"aria-disabled":s||void 0,"data-panel":!0,"data-testid":w,id:w,ref:k,style:{...obe,display:"flex",flexBasis:0,flexShrink:1,overflow:"visible",...JSON.parse(P)},children:f.jsx("div",{className:t,style:{maxHeight:"100%",maxWidth:"100%",flexGrow:1,overflow:"auto",...b,touchAction:A==="horizontal"?"pan-y":"pan-x"},children:e})})}eF.displayName="Panel";const obe={minHeight:0,maxHeight:"100%",height:"auto",minWidth:0,maxWidth:"100%",width:"auto",border:"none",borderWidth:0,padding:0,margin:0};function abe({layout:e,panelConstraints:t,panelId:n,panelIndex:r}){let i,s;const o=e[n],l=t.find(c=>c.panelId===n);if(l){const c=l.maxSize,u=l.collapsible?l.collapsedSize:l.minSize,p=[r,r+1];s=Uc({layout:Np({delta:u-o,initialLayout:e,panelConstraints:t,pivotIndices:p,prevLayout:e}),panelConstraints:t})[n],i=Uc({layout:Np({delta:c-o,initialLayout:e,panelConstraints:t,pivotIndices:p,prevLayout:e}),panelConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:s,valueNow:o}}function tF({children:e,className:t,disabled:n,elementRef:r,id:i,style:s,...o}){const l=n2(i),c=i2({disabled:n}),[u,p]=v.useState({}),[h,g]=v.useState("inactive"),b=v.useRef(null),x=r2(b,r),{disableCursor:_,id:w,orientation:C,registerSeparator:E,toggleSeparatorDisabled:k}=s2(),R=C==="horizontal"?"vertical":"horizontal";ru(()=>{const A=b.current;if(A!==null){const M={disabled:c.disabled,element:A,id:l},D=E(M),U=Kve(P=>{g(P.next.state!=="inactive"&&P.next.hitRegions.some(z=>z.separator===M)?P.next.state:"inactive")}),j=ZE(w,P=>{const{derivedPanelConstraints:z,layout:O,separatorToPanels:$}=P.next,V=$.get(M);if(V){const B=V[0],F=V.indexOf(B);p(abe({layout:O,panelConstraints:z,panelId:B.id,panelIndex:F}))}});return()=>{U(),j(),D()}}},[w,l,E,c]),v.useEffect(()=>{k(l,!!n)},[n,l,k]);let N;return n&&!_&&(N="not-allowed"),f.jsx("div",{...o,"aria-controls":u.valueControls,"aria-disabled":n||void 0,"aria-orientation":R,"aria-valuemax":u.valueMax,"aria-valuemin":u.valueMin,"aria-valuenow":u.valueNow,children:e,className:t,"data-separator":n?"disabled":h,"data-testid":l,id:l,ref:x,role:"separator",style:{flexBasis:"auto",cursor:N,...s,flexGrow:0,flexShrink:0,touchAction:"none"},tabIndex:n?void 0:0})}tF.displayName="Separator";const o2=({className:e,...t})=>f.jsx(JB,{className:me("flex h-full w-full",e),...t}),Ap=e=>f.jsx(eF,{...e}),a2=({withHandle:e,orientation:t,disabled:n,className:r,...i})=>f.jsx(tF,{disabled:n,className:me("relative flex items-center justify-center bg-transparent focus-visible:outline-none",t==="vertical"?"h-2 w-full -my-1 cursor-row-resize":"h-full w-2 -mx-1 cursor-col-resize",e&&(t==="vertical"?"before:absolute before:inset-x-0 before:top-1/2 before:h-0.5 before:-translate-y-1/2 before:bg-border":"before:absolute before:inset-y-0 before:left-1/2 before:w-px before:-translate-x-1/2 before:bg-border"),r),...i,children:f.jsx("span",{className:"sr-only",children:t==="vertical"?"Resize rows":"Resize columns"})});function nF(e,t,n){const r=typeof e.maxTokens=="number"&&Number.isFinite(e.maxTokens)?e.maxTokens:null,i=r&&r>0?Math.min(100,e.usedTokens/r*100):null,s=r!==null?Math.max(0,Math.round(r-e.usedTokens)):null,o=i!==null?Math.max(0,100-i):null;return{...e,compactsAutomatically:e.compactsAutomatically||n,maxTokens:r??void 0,remainingTokens:s,usedPercentage:i,remainingPercentage:o,updatedAt:t}}function lbe(e){const t=e.some(n=>n.kind==="compact_boundary"||n.kind==="compact_summary"||n.kind==="context_cleared");for(let n=e.length-1;n>=0;n-=1){const r=e[n];if(r&&!(r.kind!=="context_window_updated"||r.usage.usedTokens<=0))return nF(r.usage,new Date(r.createdAt).toISOString(),t)}return null}function cbe(e,t){return!e||t===null||!Number.isFinite(t)||t<=0?e:nF({...e,maxTokens:t},e.updatedAt,e.compactsAutomatically)}function xh(e){return e==null||!Number.isFinite(e)?"0":e<1e3?`${Math.round(e)}`:e<1e4?`${(e/1e3).toFixed(1).replace(/\.0$/,"")}k`:e<1e6?`${Math.round(e/1e3)}k`:`${(e/1e6).toFixed(1).replace(/\.0$/,"")}m`}const l2=[68,32];function ube(){return{isVisible:!1,mainSizes:[...l2],terminals:[],nextTerminalIndex:0}}function dbe(e,t){return e[t]??ube()}function Gw(e){if(e.length===0)return[];const t=e.reduce((n,r)=>n+Math.max(r,0),0);return!Number.isFinite(t)||t<=0?Array.from({length:e.length},()=>100/e.length):e.map(n=>Math.max(n,0)/t*100)}function fbe(e){let t=e,n="";do n=String.fromCharCode(65+t%26)+n,t=Math.floor(t/26)-1;while(t>=0);return`Terminal ${n}`}function hbe(e){if(e.length===0)return e;const t=e.length+1;return e.map(n=>({...n,size:n.size*e.length/t}))}function Qu(e,t,n){return{...e,[t]:n(dbe(e,t))}}const yl=oo()(lf(e=>({projects:{},addTerminal:(t,n)=>e(r=>({projects:Qu(r.projects,t,i=>{var c,u;const s=hbe(i.terminals),o={id:((u=(c=globalThis.crypto)==null?void 0:c.randomUUID)==null?void 0:u.call(c))??`terminal-${Date.now()}-${i.nextTerminalIndex}`,title:fbe(i.nextTerminalIndex),size:100/(s.length+1)},l=n?Math.max(s.findIndex(p=>p.id===n)+1,0):s.length;return{...i,isVisible:!0,nextTerminalIndex:i.nextTerminalIndex+1,terminals:[...s.slice(0,l),o,...s.slice(l)]}})})),removeTerminal:(t,n)=>e(r=>({projects:Qu(r.projects,t,i=>{const s=i.terminals.filter(l=>l.id!==n);if(s.length===0)return{...i,isVisible:!1,terminals:[]};const o=Gw(s.map(l=>l.size));return{...i,terminals:s.map((l,c)=>({...l,size:o[c]??100/s.length}))}})})),toggleVisibility:t=>e(n=>({projects:Qu(n.projects,t,r=>({...r,isVisible:r.terminals.length>0?!r.isVisible:!1}))})),resetMainSizes:t=>e(n=>({projects:Qu(n.projects,t,r=>({...r,mainSizes:[...l2]}))})),setMainSizes:(t,n)=>e(r=>{if(n.length!==2)return r;const i=Gw(n);return{projects:Qu(r.projects,t,s=>({...s,mainSizes:i}))}}),setTerminalSizes:(t,n)=>e(r=>({projects:Qu(r.projects,t,i=>{if(n.length!==i.terminals.length)return i;const s=Gw(n);return{...i,terminals:i.terminals.map((o,l)=>({...o,size:s[l]??o.size}))}})})),clearProject:t=>e(n=>{const{[t]:r,...i}=n.projects;return{projects:i}})}),{name:"terminal-layouts",version:1})),pbe={isVisible:!1,mainSizes:[...l2],terminals:[],nextTerminalIndex:0},mbe=35;function gbe(e,t){return!Number.isFinite(e)||e<=0||!Number.isFinite(t)||t<=0?0:e*(t/100)}function vbe(e,t){const n=gbe(e,t);return n>=0&&n<mbe}const f0=350,bbe=[.4,0,.2,1],ybe=8,CD=1e-6;function xbe(e,t,n){const r=1-e;return 3*r*r*e*t+3*r*e*e*n+e*e*e}function _be(e,t,n){const r=1-e;return 3*r*r*e*t+3*r*e*e*n+e*e*e}function wbe(e,t,n){const r=1-e;return 3*r*r*t+6*r*e*(n-t)+3*e*e*(1-n)}function Sbe(e,t,n){let r=e;for(let i=0;i<ybe;i+=1){const s=xbe(r,t,n)-e;if(Math.abs(s)<CD)return r;const o=wbe(r,t,n);if(Math.abs(o)<CD)break;r-=s/o}return r}function Cbe(e){if(e<=0)return 0;if(e>=1)return 1;const[t,n,r,i]=bbe,s=Sbe(e,t,r);return _be(s,n,i)}function rF(e,t,n){const r=Cbe(n);return[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r]}function kbe({projectId:e,shouldRenderRightSidebarLayout:t,showRightSidebar:n,rightSidebarSize:r}){const i=v.useRef(null),s=v.useRef(null),o=v.useRef(null),l=v.useRef(null),c=v.useRef(null),u=v.useRef(!1),p=v.useRef(null),h=v.useRef(!1),g=v.useRef(!1);return v.useEffect(()=>()=>{l.current!==null&&window.cancelAnimationFrame(l.current),c.current!==null&&window.clearTimeout(c.current)},[]),v.useLayoutEffect(()=>{var M,D,U,j,P,z;if(!t){l.current!==null&&(window.cancelAnimationFrame(l.current),l.current=null),c.current!==null&&(window.clearTimeout(c.current),c.current=null),u.current=!1;return}const b=i.current;if(!b)return;l.current!==null&&(window.cancelAnimationFrame(l.current),l.current=null),c.current!==null&&(window.clearTimeout(c.current),c.current=null);const x=p.current,_=x!==null&&x!==e,w=n&&!g.current,C=!h.current,E=n?[100-r,r]:[100,0],k=_||C&&n,R=w||C?[100,0]:[b.getLayout().workspace??E[0],b.getLayout().rightSidebar??E[1]];if(p.current=e,h.current=t,g.current=n,k||Math.abs(R[0]-E[0])<.1&&Math.abs(R[1]-E[1])<.1){b.setLayout({workspace:E[0],rightSidebar:E[1]}),(M=s.current)==null||M.setAttribute("data-right-sidebar-open",n?"true":"false"),(D=o.current)==null||D.setAttribute("data-right-sidebar-open",n?"true":"false"),(U=o.current)==null||U.setAttribute("data-right-sidebar-animated","false");return}u.current=!0,(j=s.current)==null||j.setAttribute("data-right-sidebar-open",n?"true":"false"),(P=o.current)==null||P.setAttribute("data-right-sidebar-open",n?"true":"false"),(z=o.current)==null||z.setAttribute("data-right-sidebar-animated","true"),b.setLayout({workspace:R[0],rightSidebar:R[1]});const N=performance.now(),A=O=>{const $=Math.min(1,(O-N)/f0),V=rF(R,E,$);if(b.setLayout({workspace:V[0],rightSidebar:V[1]}),$<1){l.current=window.requestAnimationFrame(A);return}b.setLayout({workspace:E[0],rightSidebar:E[1]}),l.current=null,c.current=window.setTimeout(()=>{u.current=!1,c.current=null},0)};l.current=window.requestAnimationFrame(A)},[e,r,t,n]),v.useEffect(()=>{t||(h.current=!1,g.current=!1)},[t]),{isAnimating:u,panelGroupRef:i,sidebarPanelRef:s,sidebarVisualRef:o}}function Ebe(e){return e.visibilityState==="visible"?e.activeChatId:null}function Tbe(e){e.socket.setFocusedChat(Ebe({activeChatId:e.activeChatId,visibilityState:e.visibilityState}))}function Rbe({socket:e,activeChatId:t}){v.useEffect(()=>{if(typeof document>"u")return;const n=()=>{Tbe({socket:e,activeChatId:t,visibilityState:document.visibilityState})};return n(),document.addEventListener("visibilitychange",n),window.addEventListener("pagehide",n),window.addEventListener("pageshow",n),()=>{document.removeEventListener("visibilitychange",n),window.removeEventListener("pagehide",n),window.removeEventListener("pageshow",n),e.setFocusedChat(null)}},[e,t])}function Nbe({rootRef:e,fallbackRef:t,enabled:n,canCancel:r}){v.useEffect(()=>{if(!n)return;let i=0,s=null;const o=h=>{const g=h instanceof Element?h:null,b=e.current,x=t.current;if(uM({trigger:"pointer",activeElement:document.activeElement,pointerStartTarget:s,pointerEndTarget:g,root:b,fallback:x,hasActiveOverlay:cM(document),hasActiveSelection:MY(window.getSelection())})!=="restore"){s=null;return}x==null||x.focus({preventScroll:!0}),s=null},l=h=>{cancelAnimationFrame(i),s=h.target instanceof Element?h.target:null},c=h=>{cancelAnimationFrame(i),i=window.requestAnimationFrame(()=>{o(h.target)})},u=()=>{s=null;const h=t.current;!h||h.disabled||h.focus({preventScroll:!0})},p=h=>{if(h.key!=="Escape")return;const g=t.current;uM({trigger:"escape",activeElement:document.activeElement,fallback:g,hasActiveOverlay:cM(document),canCancel:r,defaultPrevented:h.defaultPrevented})==="escape-focus"&&(h.preventDefault(),g==null||g.focus({preventScroll:!0}))};return window.addEventListener("pointerdown",l,!0),window.addEventListener("pointerup",c,!0),window.addEventListener("keydown",p,!0),window.addEventListener(mb,u),()=>{cancelAnimationFrame(i),window.removeEventListener("pointerdown",l,!0),window.removeEventListener("pointerup",c,!0),window.removeEventListener("keydown",p,!0),window.removeEventListener(mb,u)}},[r,n,t,e])}function Abe(e){const t=e.previousProjectId!==null&&e.previousProjectId!==e.projectId,n=e.previousProjectId===null&&e.projectId!==null;return!t&&!n&&e.showTerminalPane&&!e.wasTerminalVisible}function Mbe({previousProjectId:e,projectId:t,previousShouldRenderTerminalLayout:n,previousShowTerminalPane:r,showTerminalPane:i,terminalLayout:s,liveLayout:o}){const l=e!==null&&e!==t,c=i&&!r,u=!n,p=e===null&&t!==null,h=i?s.mainSizes:[100,0];return{currentLayout:c||u?[100,0]:o,shouldSkipAnimation:l||p&&u,targetLayout:h}}function Lbe({chatInputRef:e,projectId:t,shouldRenderTerminalLayout:n,showTerminalPane:r,terminalLayout:i}){const s=v.useRef(null),o=v.useRef(null),l=v.useRef(null),c=v.useRef(null),u=v.useRef(null),p=v.useRef(!1),h=v.useRef(null),g=v.useRef(!1),b=v.useRef(!1),x=v.useRef(!1),[_,w]=v.useState(0);return v.useEffect(()=>{var k;const C=h.current,E=x.current;Abe({previousProjectId:C,projectId:t,showTerminalPane:r,wasTerminalVisible:E})&&w(R=>R+1),C!==null&&C===t&&!r&&E&&((k=e.current)==null||k.focus({preventScroll:!0})),x.current=r,h.current=t},[e,t,r]),v.useEffect(()=>()=>{c.current!==null&&window.cancelAnimationFrame(c.current),u.current!==null&&window.clearTimeout(u.current)},[]),v.useLayoutEffect(()=>{var D,U,j,P,z,O;if(!n){c.current!==null&&(window.cancelAnimationFrame(c.current),c.current=null),u.current!==null&&(window.clearTimeout(u.current),u.current=null),p.current=!1;return}const C=s.current;if(!C)return;c.current!==null&&(window.cancelAnimationFrame(c.current),c.current=null),u.current!==null&&(window.clearTimeout(u.current),u.current=null);const E=h.current,{currentLayout:k,shouldSkipAnimation:R,targetLayout:N}=Mbe({previousProjectId:E,projectId:t,previousShouldRenderTerminalLayout:g.current,previousShowTerminalPane:b.current,showTerminalPane:r,terminalLayout:i,liveLayout:[C.getLayout().chat??i.mainSizes[0],C.getLayout().terminal??i.mainSizes[1]]});if(g.current=n,b.current=r,R||Math.abs(k[0]-N[0])<.1&&Math.abs(k[1]-N[1])<.1){C.setLayout({chat:N[0],terminal:N[1]}),(D=o.current)==null||D.setAttribute("data-terminal-open",r?"true":"false"),(U=l.current)==null||U.setAttribute("data-terminal-open",r?"true":"false"),(j=l.current)==null||j.setAttribute("data-terminal-animated","false");return}p.current=!0,(P=o.current)==null||P.setAttribute("data-terminal-open",r?"true":"false"),(z=l.current)==null||z.setAttribute("data-terminal-open",r?"true":"false"),(O=l.current)==null||O.setAttribute("data-terminal-animated","true"),C.setLayout({chat:k[0],terminal:k[1]});const A=performance.now(),M=$=>{const V=Math.min(1,($-A)/f0),B=rF(k,N,V);if(C.setLayout({chat:B[0],terminal:B[1]}),V<1){c.current=window.requestAnimationFrame(M);return}C.setLayout({chat:N[0],terminal:N[1]}),c.current=null,u.current=window.setTimeout(()=>{p.current=!1,u.current=null},0)};c.current=window.requestAnimationFrame(M)},[t,n,r,i]),v.useEffect(()=>{n||(g.current=!1,b.current=!1)},[n]),{isAnimating:p,mainPanelGroupRef:s,terminalFocusRequestVersion:_,terminalPanelRef:o,terminalVisualRef:l}}const kD=e=>Symbol.iterator in e,ED=e=>"entries"in e,TD=(e,t)=>{const n=e instanceof Map?e:new Map(e.entries()),r=t instanceof Map?t:new Map(t.entries());if(n.size!==r.size)return!1;for(const[i,s]of n)if(!r.has(i)||!Object.is(s,r.get(i)))return!1;return!0},jbe=(e,t)=>{const n=e[Symbol.iterator](),r=t[Symbol.iterator]();let i=n.next(),s=r.next();for(;!i.done&&!s.done;){if(!Object.is(i.value,s.value))return!1;i=n.next(),s=r.next()}return!!i.done&&!!s.done};function Dbe(e,t){return Object.is(e,t)?!0:typeof e!="object"||e===null||typeof t!="object"||t===null||Object.getPrototypeOf(e)!==Object.getPrototypeOf(t)?!1:kD(e)&&kD(t)?ED(e)&&ED(t)?TD(e,t):jbe(e,t):TD({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function RD(e){const t=_n.useRef(void 0);return n=>{const r=e(n);return Dbe(t.current,r)?t.current:t.current=r}}const Qh="__new__";function gc(e){var s,o;const t=(s=e==null?void 0:e.modelOptions)==null?void 0:s.reasoningEffort,n=GM(t)?t:GM(e==null?void 0:e.effort)?e.effort:pp.reasoningEffort,r=Qte(e==null?void 0:e.model),i=Zk(r,(o=e==null?void 0:e.modelOptions)==null?void 0:o.contextWindow);return{model:r,modelOptions:{reasoningEffort:!P4(r)&&n==="max"?"high":n,contextWindow:i},planMode:!!(e!=null&&e.planMode)}}function gv(e){var n,r;const t=(n=e==null?void 0:e.modelOptions)==null?void 0:n.reasoningEffort;return{model:Zte(e==null?void 0:e.model),modelOptions:{reasoningEffort:qM(t)?t:qM(e==null?void 0:e.effort)?e.effort:GS.reasoningEffort,fastMode:typeof((r=e==null?void 0:e.modelOptions)==null?void 0:r.fastMode)=="boolean"?e.modelOptions.fastMode:GS.fastMode},planMode:!!(e!=null&&e.planMode)}}function Ibe(){return{claude:{model:"claude-opus-4-7",modelOptions:{...pp},planMode:!1},codex:{model:"gpt-5.5",modelOptions:{...GS},planMode:!1}}}function Pbe(e,t){return e.reasoningEffort===t.reasoningEffort&&e.contextWindow===t.contextWindow}function Obe(e,t){return e.reasoningEffort===t.reasoningEffort&&e.fastMode===t.fastMode}function zbe(e,t){return e.claude.model===t.claude.model&&e.claude.planMode===t.claude.planMode&&Pbe(e.claude.modelOptions,t.claude.modelOptions)&&e.codex.model===t.codex.model&&e.codex.planMode===t.codex.planMode&&Obe(e.codex.modelOptions,t.codex.modelOptions)}function Bbe(e,t){if(t===void 0){console.info(`[chat-preferences] ${e}`);return}console.info(`[chat-preferences] ${e}`,t)}function Zh(e,t){if(e==="claude"){const r=t.claude;return{provider:"claude",model:r.model,modelOptions:{...r.modelOptions},planMode:r.planMode}}const n=t.codex;return{provider:"codex",model:n.model,modelOptions:{...n.modelOptions},planMode:n.planMode}}function V1(e){return e.provider==="claude"?{provider:"claude",model:e.model,modelOptions:{...e.modelOptions},planMode:e.planMode}:{provider:"codex",model:e.model,modelOptions:{...e.modelOptions},planMode:e.planMode}}function iF(e){return e.providerHint?Zh(e.providerHint,e.providerDefaults):e.defaultProvider==="last_used"?e.sourceState?V1(e.sourceState):Zh("claude",e.providerDefaults):Zh(e.defaultProvider,e.providerDefaults)}function sF(e,t){const n=e.chatStates[t];return n||iF({defaultProvider:e.defaultProvider,providerDefaults:e.providerDefaults,legacyComposerState:e.legacyComposerState})}function vv(e,t,n){const r=sF(e,t);return{chatStates:{...e.chatStates,[t]:n(r)}}}const gi=oo()(lf((e,t)=>({defaultProvider:"last_used",providerDefaults:Ibe(),chatStates:{},legacyComposerState:{provider:"claude",model:"claude-opus-4-7",modelOptions:{...pp},planMode:!1},setDefaultProvider:n=>e({defaultProvider:n}),applyServerDefaults:(n,r)=>e(i=>{if(i.defaultProvider===n&&zbe(i.providerDefaults,r))return{defaultProvider:n,providerDefaults:r};const{[Qh]:o,...l}=i.chatStates;return{defaultProvider:n,providerDefaults:r,chatStates:l}}),setProviderDefaultModel:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:n==="claude"?gc({...i.providerDefaults.claude,model:r}):gv({...i.providerDefaults.codex,model:r})}})),setProviderDefaultModelOptions:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:n==="claude"?gc({...i.providerDefaults.claude,modelOptions:{...i.providerDefaults.claude.modelOptions,...r}}):gv({...i.providerDefaults.codex,modelOptions:{...i.providerDefaults.codex.modelOptions,...r}})}})),setProviderDefaultPlanMode:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:{...i.providerDefaults[n],planMode:r}}})),getComposerState:n=>V1(sF(t(),n)),initializeComposerForChat:(n,r)=>e(i=>{if(i.chatStates[n])return i;const s=iF({defaultProvider:i.defaultProvider,providerDefaults:i.providerDefaults,sourceState:r==null?void 0:r.sourceState,legacyComposerState:i.legacyComposerState,providerHint:r==null?void 0:r.providerHint});return Bbe("initializeComposerForChat",{chatId:n,composerState:s}),{chatStates:{...i.chatStates,[n]:s}}}),setComposerState:(n,r)=>e(i=>({chatStates:{...i.chatStates,[n]:r.provider==="claude"?{provider:"claude",model:gc(r).model,modelOptions:gc(r).modelOptions,planMode:r.planMode}:V1(r)}})),setChatComposerProvider:(n,r)=>e(i=>vv(i,n,()=>Zh(r,i.providerDefaults))),setChatComposerModel:(n,r)=>e(i=>vv(i,n,s=>s.provider==="claude"?{provider:"claude",model:gc({...s,model:r}).model,modelOptions:gc({...s,model:r}).modelOptions,planMode:s.planMode}:{provider:"codex",model:r,modelOptions:gv({...s,model:r}).modelOptions,planMode:s.planMode})),setChatComposerModelOptions:(n,r)=>e(i=>vv(i,n,s=>s.provider==="claude"?{provider:"claude",model:s.model,modelOptions:gc({...s,modelOptions:{...s.modelOptions,...r}}).modelOptions,planMode:s.planMode}:{provider:"codex",model:s.model,modelOptions:gv({...s,modelOptions:{...s.modelOptions,...r}}).modelOptions,planMode:s.planMode})),setChatComposerPlanMode:(n,r)=>e(i=>vv(i,n,s=>({...s,planMode:r}))),resetChatComposerFromProvider:(n,r)=>e(i=>({chatStates:{...i.chatStates,[n]:Zh(r,i.providerDefaults)}}))}),{name:"chat-preferences-state",version:1,partialize:e=>({chatStates:e.chatStates,legacyComposerState:e.legacyComposerState})})),W1=oo()(lf((e,t)=>({drafts:{},attachmentDrafts:{},setDraft:(n,r)=>e(i=>{if(!r){const{[n]:s,...o}=i.drafts;return{drafts:o}}return{drafts:{...i.drafts,[n]:r}}}),clearDraft:n=>e(r=>{const{[n]:i,...s}=r.drafts;return{drafts:s}}),getDraft:n=>t().drafts[n]??"",setAttachmentDrafts:(n,r)=>e(i=>{if(r.length===0){const{[n]:s,...o}=i.attachmentDrafts;return{attachmentDrafts:o}}return{attachmentDrafts:{...i.attachmentDrafts,[n]:r}}}),clearAttachmentDrafts:n=>e(r=>{const{[n]:i,...s}=r.attachmentDrafts;return{attachmentDrafts:s}}),getAttachmentDrafts:n=>t().attachmentDrafts[n]??[]}),{name:"chat-input-drafts"})),c2=oo()(e=>({byChatId:{},loadingByChatId:{},setForChat:(t,n)=>e(r=>({byChatId:{...r.byChatId,[t]:n}})),setLoadingForChat:(t,n)=>e(r=>(r.loadingByChatId[t]??!1)===n?r:{loadingByChatId:{...r.loadingByChatId,[t]:n}}),clear:t=>e(n=>{const r=t in n.byChatId,i=t in n.loadingByChatId;if(!r&&!i)return n;const{[t]:s,...o}=n.byChatId,{[t]:l,...c}=n.loadingByChatId;return{byChatId:o,loadingByChatId:c}})}));function Fbe(e){return{autoResumeOnRateLimit:!!(e!=null&&e.autoResumeOnRateLimit)}}const G1=oo()(lf(e=>({autoResumeOnRateLimit:!1,setAutoResumeOnRateLimit:t=>e({autoResumeOnRateLimit:t})}),{name:"kanna-preferences",version:1,migrate:e=>Fbe(e)}));function $be(e,t){var n,r,i,s,o,l,c,u,p;return{...e,...t,terminal:{...e.terminal,...t.terminal},editor:{...e.editor,...t.editor},providerDefaults:{claude:{...e.providerDefaults.claude,...(n=t.providerDefaults)==null?void 0:n.claude,modelOptions:{...e.providerDefaults.claude.modelOptions,...(i=(r=t.providerDefaults)==null?void 0:r.claude)==null?void 0:i.modelOptions}},codex:{...e.providerDefaults.codex,...(s=t.providerDefaults)==null?void 0:s.codex,modelOptions:{...e.providerDefaults.codex.modelOptions,...(l=(o=t.providerDefaults)==null?void 0:o.codex)==null?void 0:l.modelOptions}}},cloudflareTunnel:{...e.cloudflareTunnel,...t.cloudflareTunnel},claudeAuth:{tokens:((c=t.claudeAuth)==null?void 0:c.tokens)??e.claudeAuth.tokens},auth:{...e.auth,...t.auth},uploads:{...e.uploads,...t.uploads},subagents:e.subagents,claudeDriver:{preference:((u=t.claudeDriver)==null?void 0:u.preference)??e.claudeDriver.preference,lifecycle:{...e.claudeDriver.lifecycle,...(p=t.claudeDriver)==null?void 0:p.lifecycle}}}}const Ks=oo()(e=>({settings:null,hydrationStatus:"idle",setHydrationStatus:t=>e({hydrationStatus:t}),setFromServer:t=>e({settings:t,hydrationStatus:"ready"}),applyOptimisticPatch:t=>e(n=>({settings:n.settings?$be(n.settings,t):n.settings}))})),oF=v.createContext(void 0),Hbe=e=>e==="light"||e==="dark"||e==="system";function Ube(e){return e==="dark"?"black-translucent":"default"}function ND(e,t){if(typeof document>"u")return;let n=document.head.querySelector(`meta[name="${e}"]`);n||(n=document.createElement("meta"),n.setAttribute("name",e),document.head.appendChild(n)),n.setAttribute("content",t)}function AD(e){if(typeof document>"u"||typeof window>"u")return;const t=getComputedStyle(document.body).backgroundColor||getComputedStyle(document.documentElement).backgroundColor;t&&ND("theme-color",t),ND("apple-mobile-web-app-status-bar-style",Ube(e)),document.documentElement.style.colorScheme=e}const Zv=()=>typeof window>"u"?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",MD=e=>{if(typeof document>"u")return;const t=e==="system"?Zv():e;document.documentElement.classList.toggle("dark",t==="dark")},Vbe=()=>{var t;const e=(t=Ks.getState().settings)==null?void 0:t.theme;return e&&Hbe(e)?e:"system"};function Wbe({children:e}){const t=Ks(o=>{var l;return(l=o.settings)==null?void 0:l.theme}),n=Ks(o=>o.applyOptimisticPatch),[r,i]=v.useState(Vbe);v.useEffect(()=>{!t||t===r||i(t)},[t,r]),v.useEffect(()=>{MD(r)},[r]),v.useEffect(()=>{const o=r==="system"?Zv():r;AD(o)},[r]),v.useEffect(()=>{if(r!=="system")return;const o=window.matchMedia("(prefers-color-scheme: dark)"),l=()=>{MD("system"),AD(Zv())};return o.addEventListener?(o.addEventListener("change",l),()=>o.removeEventListener("change",l)):(o.addListener(l),()=>o.removeListener(l))},[r]);const s=v.useMemo(()=>{const o=r==="system"?Zv():r;return{theme:r,resolvedTheme:o,setTheme:l=>{i(l),n({theme:l})}}},[n,r]);return f.jsx(oF.Provider,{value:s,children:e})}function u2(){const e=v.useContext(oF);if(!e)throw new Error("useTheme must be used within ThemeProvider");return e}function Zu(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function LD(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}function Gbe(e){const t=e&&typeof e=="object"&&"content"in e&&Array.isArray(e.content)?e.content:Array.isArray(e)?e:[],n=[];for(const r of t)if(!(!r||typeof r!="object"||!("type"in r))){if(r.type==="text"&&typeof r.text=="string"){n.push({type:"text",text:r.text});continue}if(r.type==="image"){if("data"in r&&typeof r.data=="string"){n.push({type:"image",data:r.data,mimeType:typeof r.mimeType=="string"?r.mimeType:void 0});continue}"source"in r&&r.source&&typeof r.source=="object"&&"type"in r.source&&r.source.type==="base64"&&"data"in r.source&&typeof r.source.data=="string"&&n.push({type:"image",data:r.source.data,mimeType:typeof r.source.media_type=="string"?r.source.media_type:void 0})}}return n}function qbe(e){const t=e&&typeof e=="object"&&"content"in e&&Array.isArray(e.content)?e.content:Array.isArray(e)?e:null;if(!t)return null;const n=[];for(const r of t)r&&typeof r=="object"&&"type"in r&&r.type==="text"&&typeof r.text=="string"&&n.push(r.text);return n.length>0?n.join(""):null}function Kbe(e,t){const n=LD(t);switch(e.toolKind){case"ask_user_question":{const s=Zu(n),o=Zu(s==null?void 0:s.answers)??(s||{});return{answers:Object.fromEntries(Object.entries(o).map(([l,c])=>Array.isArray(c)?[l,c.map(u=>String(u))]:c&&typeof c=="object"&&Array.isArray(c.answers)?[l,c.answers.map(u=>String(u))]:c==null||c===""?[l,[]]:[l,[String(c)]])),...(s==null?void 0:s.discarded)===!0?{discarded:!0}:{}}}case"exit_plan_mode":{const s=Zu(n);return{confirmed:typeof(s==null?void 0:s.confirmed)=="boolean"?s.confirmed:void 0,clearContext:typeof(s==null?void 0:s.clearContext)=="boolean"?s.clearContext:void 0,message:typeof(s==null?void 0:s.message)=="string"?s.message:void 0,...(s==null?void 0:s.discarded)===!0?{discarded:!0}:{}}}case"offer_download":{const s=qbe(n),o=s?LD(s):n,l=Zu(o);return{contentUrl:typeof(l==null?void 0:l.contentUrl)=="string"?l.contentUrl:"",relativePath:typeof(l==null?void 0:l.relativePath)=="string"?l.relativePath:"",fileName:typeof(l==null?void 0:l.fileName)=="string"?l.fileName:"",displayName:typeof(l==null?void 0:l.displayName)=="string"?l.displayName:typeof(l==null?void 0:l.fileName)=="string"?l.fileName:"",size:typeof(l==null?void 0:l.size)=="number"?l.size:0,...typeof(l==null?void 0:l.mimeType)=="string"?{mimeType:l.mimeType}:{}}}case"image_generation":{const s=Zu(n);return{contentUrl:typeof(s==null?void 0:s.contentUrl)=="string"?s.contentUrl:"",relativePath:typeof(s==null?void 0:s.relativePath)=="string"?s.relativePath:"",fileName:typeof(s==null?void 0:s.fileName)=="string"?s.fileName:""}}case"read_file":if(typeof n=="string")return n;const r=Gbe(n);if(r.length>0)return{content:r.flatMap(s=>s.type==="text"?[s.text]:[]).join(""),blocks:r};const i=Zu(n);return{content:typeof(i==null?void 0:i.content)=="string"?i.content:JSON.stringify(n,null,2)};default:return n}}function aF(e){return new Date(e).toISOString()}function Ni(e){return{id:e._id,messageId:e.messageId,timestamp:aF(e.createdAt),hidden:e.hidden}}function Ybe(e){return{id:e._id,messageId:e.messageId,hidden:e.hidden,kind:"tool",toolKind:e.tool.toolKind,toolName:e.tool.toolName,toolId:e.tool.toolId,input:e.tool.input,timestamp:aF(e.createdAt)}}function Xbe(e){if(e.debugRaw)try{return JSON.parse(e.debugRaw).tool_use_result}catch{return}}function lF(e){const t=new Map,n=[];for(const r of e)switch(r.kind){case"user_prompt":n.push({...Ni(r),kind:"user_prompt",content:r.content,attachments:r.attachments??[],steered:r.steered,autoContinue:r.autoContinue});break;case"system_init":n.push({...Ni(r),kind:"system_init",provider:r.provider,model:r.model,tools:r.tools,agents:r.agents,slashCommands:r.slashCommands,mcpServers:r.mcpServers,debugRaw:r.debugRaw});break;case"account_info":n.push({...Ni(r),kind:"account_info",accountInfo:r.accountInfo});break;case"assistant_text":n.push({...Ni(r),kind:"assistant_text",text:r.text});break;case"tool_call":{const i=Ybe(r);t.set(r.tool.toolId,{hydrated:i,normalized:r.tool}),n.push(i);break}case"tool_result":{const i=t.get(r.toolId);if(i){const s=i.normalized.toolKind==="ask_user_question"||i.normalized.toolKind==="exit_plan_mode"?Xbe(r)??r.content:r.content;i.hydrated.result=Kbe(i.normalized,s),i.hydrated.rawResult=s,i.hydrated.isError=r.isError,r.persisted&&(i.hydrated.persisted=r.persisted)}break}case"result":n.push({...Ni(r),kind:"result",success:!r.isError,cancelled:r.subtype==="cancelled",result:r.result,durationMs:r.durationMs,costUsd:r.costUsd});break;case"status":n.push({...Ni(r),kind:"status",status:r.status});break;case"context_window_updated":n.push({...Ni(r),kind:"context_window_updated",usage:r.usage});break;case"compact_boundary":n.push({...Ni(r),kind:"compact_boundary"});break;case"compact_summary":n.push({...Ni(r),kind:"compact_summary",summary:r.summary});break;case"context_cleared":n.push({...Ni(r),kind:"context_cleared"});break;case"interrupted":n.push({...Ni(r),kind:"interrupted"});break;case"auto_continue_prompt":n.push({...Ni(r),kind:"auto_continue_prompt",scheduleId:r.scheduleId});break;case"pending_tool_request":n.push({...Ni(r),kind:"pending_tool_request",toolRequestId:r.toolRequestId,toolName:r.toolName,arguments:r.arguments});break;case"tool_request_resolved":break;default:n.push({...Ni(r),kind:"unknown",json:JSON.stringify(r,null,2)});break}return n}const Qbe=["AskUserQuestion","ExitPlanMode","TodoWrite"],Zbe=new Set(["TodoWrite"]);function Jbe(e,t){for(let n=e.length-1;n>=0;n-=1){const r=e[n];if(r.kind!=="tool")continue;const i=r;if(i.toolName===t&&!i.result)return i.id}return null}function eye(e,t){for(let n=e.length-1;n>=0;n-=1){const r=e[n];if(r.kind!=="tool")continue;const i=r;if(i.toolName===t)return i.id}return null}function tye(e){const t={};for(const n of Qbe)t[n]=Zbe.has(n)?eye(e,n):Jbe(e,n);return t}function nye(e){return e==="starting"||e==="running"||e==="waiting_for_user"}function rye(e){return e==="starting"||e==="running"||e==="waiting_for_user"}const d2="pushDeviceId";function cF(){return typeof localStorage>"u"?null:localStorage.getItem(d2)}function iye(e){typeof localStorage>"u"||localStorage.setItem(d2,e)}function sye(){typeof localStorage>"u"||localStorage.removeItem(d2)}function oye(){return!(typeof window>"u"||typeof Notification>"u"||!("serviceWorker"in navigator)||typeof globalThis.PushManager>"u")}function aye(){var t;if(typeof window>"u")return!1;if(window.isSecureContext)return!0;const e=((t=window.location)==null?void 0:t.hostname)??"";return e==="localhost"||e==="127.0.0.1"||e==="::1"}function q1(){if(!oye())return{state:"unsupported"};if(!aye())return{state:"insecure-context"};switch(Notification.permission){case"granted":return{state:"granted"};case"denied":return{state:"denied"};default:return{state:"default"}}}function lye(e){if(typeof Buffer<"u")return new Uint8Array(Buffer.from(e,"base64url"));const t="=".repeat((4-e.length%4)%4),n=(e+t).replace(/-/g,"+").replace(/_/g,"/"),r=atob(n),i=new Uint8Array(r.length);for(let s=0;s<r.length;s+=1)i[s]=r.charCodeAt(s);return i}function cye(e){const t=e||"";return/iPhone|iPad/i.test(t)?"iPhone / iPad":/Android/i.test(t)?"Android":/Macintosh/i.test(t)?"Mac":/Windows/i.test(t)?"Windows PC":t||"Browser"}async function uye(e){const t=q1();if(t.state==="unsupported")throw new Error("Push not supported in this browser");if(t.state==="insecure-context")throw new Error("Push requires a secure context (HTTPS)");if(t.state==="denied")throw new Error("Notification permission previously denied");if(await Notification.requestPermission()!=="granted")throw new Error("Notification permission was not granted");const r=await navigator.serviceWorker.register("/sw.js");await navigator.serviceWorker.ready;const i=await r.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:lye(e.vapidPublicKey)}),s=i.toJSON(),o=s.endpoint??i.endpoint,l=s.keys??{};if(!o||!l.p256dh||!l.auth)throw new Error("Subscription returned without endpoint or keys");const c=navigator.userAgent??"",{id:u}=await e.sendToServer({subscription:{endpoint:o,keys:{p256dh:l.p256dh,auth:l.auth}},label:cye(c),userAgent:c});return u}async function dye(e){const n=await(await navigator.serviceWorker.ready).pushManager.getSubscription();n&&await n.unsubscribe(),await e.sendToServer(e.pushDeviceId)}typeof navigator<"u"&&"serviceWorker"in navigator&&navigator.serviceWorker.addEventListener("message",e=>{const t=e.data;(t==null?void 0:t.type)==="kanna.navigate"&&typeof t.url=="string"&&(window.location.href=t.url)});const fye=25e3,hye=15e3,pye=4e3,jD="kanna:profile-send-to-starting";function DD(){try{return window.sessionStorage.getItem(jD)==="1"||window.localStorage.getItem(jD)==="1"}catch{return!1}}class mye{constructor(t){ne(this,"url");ne(this,"ws",null);ne(this,"started",!1);ne(this,"reconnectTimer",null);ne(this,"reconnectDelayMs",750);ne(this,"subscriptions",new Map);ne(this,"pending",new Map);ne(this,"outboundQueue",[]);ne(this,"statusListeners",new Set);ne(this,"heartbeatTimer",null);ne(this,"pingTimeoutTimer",null);ne(this,"pingPromise",null);ne(this,"lastOpenAt",0);ne(this,"lastMessageAt",0);ne(this,"reconnectImmediatelyOnClose",!1);ne(this,"handleWindowFocus",()=>{this.ensureHealthyConnection()});ne(this,"handleVisibilityChange",()=>{if(document.visibilityState==="visible"){this.startHeartbeat(),this.ensureHealthyConnection();return}this.stopHeartbeat()});ne(this,"handleOnline",()=>{this.ensureHealthyConnection()});this.url=t}start(){this.started||(this.started=!0,window.addEventListener("focus",this.handleWindowFocus),window.addEventListener("online",this.handleOnline),document.addEventListener("visibilitychange",this.handleVisibilityChange),this.connect())}dispose(){var t;this.started=!1,this.reconnectTimer&&(window.clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.stopHeartbeat(),this.clearPingState(),window.removeEventListener("focus",this.handleWindowFocus),window.removeEventListener("online",this.handleOnline),document.removeEventListener("visibilitychange",this.handleVisibilityChange),(t=this.ws)==null||t.close(),this.ws=null;for(const n of this.pending.values())n.reject(new Error("Socket disposed"));this.pending.clear()}onStatus(t){return this.statusListeners.add(t),t(this.getStatus()),()=>{this.statusListeners.delete(t)}}subscribe(t,n,r){const i=_c();return this.subscriptions.set(i,{topic:t,listener:n,eventListener:r}),this.enqueue({v:1,type:"subscribe",id:i,topic:t}),()=>{this.subscriptions.delete(i),this.enqueue({v:1,type:"unsubscribe",id:i})}}subscribeTerminal(t,n){const r=_c(),i={type:"terminal",terminalId:t};return this.subscriptions.set(r,{topic:i,listener:n.onSnapshot,eventListener:n.onEvent}),this.enqueue({v:1,type:"subscribe",id:r,topic:i}),()=>{this.subscriptions.delete(r),this.enqueue({v:1,type:"unsubscribe",id:r})}}command(t){const n=_c(),r={v:1,type:"command",id:n,command:t};return new Promise((i,s)=>{this.pending.set(n,{resolve:i,reject:s}),this.enqueue(r)})}setFocusedChat(t){const n=_c();this.enqueue({v:1,type:"command",id:n,command:{type:"push.setFocusedChat",chatId:t}})}ensureHealthyConnection(){return!this.ws||this.ws.readyState===WebSocket.CLOSED||this.ws.readyState===WebSocket.CLOSING?(this.reconnectNow(),Promise.resolve()):this.ws.readyState===WebSocket.CONNECTING||!this.isConnectionStale()?Promise.resolve():this.sendPing()}connect(){this.started&&(this.emitStatus("connecting"),this.ws=new WebSocket(this.url),this.ws.addEventListener("open",()=>{this.reconnectDelayMs=750,this.reconnectImmediatelyOnClose=!1,this.lastOpenAt=Date.now(),this.lastMessageAt=this.lastOpenAt,this.emitStatus("connected"),this.startHeartbeat();for(const[n,r]of this.subscriptions.entries())this.sendNow({v:1,type:"subscribe",id:n,topic:r.topic});for(;this.outboundQueue.length>0;){const n=this.outboundQueue.shift();n&&this.sendNow(n)}const t=cF();t&&this.sendNow({v:1,type:"command",id:_c(),command:{type:"push.identifyDevice",pushDeviceId:t}})}),this.ws.addEventListener("message",t=>{var s,o;this.lastMessageAt=Date.now();const n=performance.now(),r=String(t.data);let i;try{i=JSON.parse(r)}catch{return}if(DD()&&i.type==="snapshot"&&i.snapshot.type==="chat"&&((s=i.snapshot.data)==null?void 0:s.runtime.status)==="starting"&&console.debug("[kanna/send->starting][client-ws]",{stage:"socket_message_received",receivedAt:n,payloadBytes:r.length,chatId:i.snapshot.data.runtime.chatId,status:i.snapshot.data.runtime.status,messageCount:i.snapshot.data.messages.length}),DD()&&i.type==="ack"&&console.debug("[kanna/send->starting][client-ws]",{stage:"socket_ack_received",receivedAt:n,payloadBytes:r.length,commandId:i.id}),i.type==="snapshot"){const l=this.subscriptions.get(i.id);l==null||l.listener(i.snapshot.data);return}if(i.type==="event"){const l=this.subscriptions.get(i.id);(o=l==null?void 0:l.eventListener)==null||o.call(l,i.event);return}if(i.type==="ack"){const l=this.pending.get(i.id);if(!l)return;this.pending.delete(i.id),l.resolve(i.result);return}if(i.type==="error"){if(!i.id){console.error(jQ,i.message);return}const l=this.pending.get(i.id);if(!l)return;this.pending.delete(i.id),l.reject(new Error(i.message))}}),this.ws.addEventListener("close",()=>{if(!this.started)return;const t=this.reconnectImmediatelyOnClose;this.reconnectImmediatelyOnClose=!1,this.stopHeartbeat(),this.clearPingState(),this.emitStatus("disconnected");for(const n of this.pending.values())n.reject(new Error("Disconnected"));if(this.pending.clear(),t){this.connect();return}this.scheduleReconnect()}))}scheduleReconnect(){this.reconnectTimer===null&&(this.reconnectTimer=window.setTimeout(()=>{this.reconnectTimer=null,this.connect(),this.reconnectDelayMs=Math.min(this.reconnectDelayMs*2,5e3)},this.reconnectDelayMs))}getStatus(){var t,n;return((t=this.ws)==null?void 0:t.readyState)===WebSocket.OPEN?"connected":((n=this.ws)==null?void 0:n.readyState)===WebSocket.CONNECTING?"connecting":"disconnected"}emitStatus(t){for(const n of this.statusListeners)n(t)}isConnectionStale(){const t=Math.max(this.lastMessageAt,this.lastOpenAt);return t>0&&Date.now()-t>=fye}sendPing(){if(this.pingPromise)return this.pingPromise;const t=this.command({type:"system.ping"}).then(()=>{this.clearPingState()}).catch(n=>{throw this.clearPingState(),this.reconnectNow(),n});return this.pingTimeoutTimer=window.setTimeout(()=>{this.clearPingState(),this.reconnectNow()},pye),this.pingPromise=t,t}reconnectNow(){if(this.reconnectTimer!==null&&(window.clearTimeout(this.reconnectTimer),this.reconnectTimer=null),!this.ws||this.ws.readyState===WebSocket.CLOSED){this.connect();return}this.ws.readyState!==WebSocket.CONNECTING&&(this.reconnectImmediatelyOnClose=!0,this.ws.close())}startHeartbeat(){document.visibilityState==="visible"&&this.heartbeatTimer===null&&(this.heartbeatTimer=window.setInterval(()=>{var t;if(document.visibilityState!=="visible"){this.stopHeartbeat();return}((t=this.ws)==null?void 0:t.readyState)===WebSocket.OPEN&&this.ensureHealthyConnection()},hye))}stopHeartbeat(){this.heartbeatTimer!==null&&(window.clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}clearPingState(){this.pingTimeoutTimer!==null&&(window.clearTimeout(this.pingTimeoutTimer),this.pingTimeoutTimer=null),this.pingPromise=null}enqueue(t){var n;if(((n=this.ws)==null?void 0:n.readyState)===WebSocket.OPEN){this.sendNow(t);return}this.outboundQueue.push(t)}sendNow(t){var n;(n=this.ws)==null||n.send(JSON.stringify(t))}}async function gye(e){const{toast:t}=await K(async()=>{const{toast:r}=await import("./index-DZs2QDFW.js");return{toast:r}},[]);t(`${e} ${e===1?"process":"processes"} survived restart`,{description:"Review and stop them in Background tasks (⌘⇧B).",action:{label:"Review",onClick:()=>Ys.getState().openDialog()}})}function vye(e,t){const n=new Set([...Object.keys(e),...Object.keys(t)]);for(const r of n)if(e[r]!==t[r])return!1;return!0}function bye(e,t){return e===t?!0:!e||!t?!1:e.chatId===t.chatId&&e.projectId===t.projectId&&e.localPath===t.localPath&&e.title===t.title&&e.status===t.status&&e.isDraining===t.isDraining&&e.provider===t.provider&&e.planMode===t.planMode&&vye(e.sessionTokensByProvider,t.sessionTokensByProvider)}function yye(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>{var i;return n._id===((i=t[r])==null?void 0:i._id)})}function xye(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>{var i;return n.id===((i=t[r])==null?void 0:i.id)})}function _ye(e,t){return e===t?!0:!e||!t?!1:e.hasOlder===t.hasOlder&&e.olderCursor===t.olderCursor&&e.recentLimit===t.recentLimit}function wye(e,t){return e.id===t.id&&e.content===t.content&&e.createdAt===t.createdAt&&e.provider===t.provider&&e.model===t.model&&e.planMode===t.planMode&&JSON.stringify(e.modelOptions)===JSON.stringify(t.modelOptions)&&Sye(e.attachments,t.attachments)}function Sye(e,t){return e===t?!0:e.length!==t.length?!1:e.every((n,r)=>{const i=t[r];return!!i&&n.id===i.id&&n.kind===i.kind&&n.displayName===i.displayName&&n.absolutePath===i.absolutePath&&n.relativePath===i.relativePath&&n.contentUrl===i.contentUrl&&n.mimeType===i.mimeType&&n.size===i.size})}function Cye(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>wye(n,t[r]))}function kye(e,t){var s,o;if(e===t)return!0;if(!e||!t||e.status!==t.status||e.branchName!==t.branchName||e.defaultBranchName!==t.defaultBranchName||e.hasOriginRemote!==t.hasOriginRemote||e.originRepoSlug!==t.originRepoSlug||e.hasUpstream!==t.hasUpstream||e.aheadCount!==t.aheadCount||e.behindCount!==t.behindCount||e.lastFetchedAt!==t.lastFetchedAt)return!1;const n=((s=e.branchHistory)==null?void 0:s.entries)??[],r=((o=t.branchHistory)==null?void 0:o.entries)??[];return n.length!==r.length||!n.every((l,c)=>{const u=r[c];return!!u&&l.sha===u.sha&&l.summary===u.summary&&l.description===u.description&&l.authorName===u.authorName&&l.authoredAt===u.authoredAt&&l.githubUrl===u.githubUrl&&l.tags.length===u.tags.length&&l.tags.every((p,h)=>p===u.tags[h])})||e.files.length!==t.files.length?!1:e.files.every((l,c)=>{const u=t.files[c];return!!u&&l.path===u.path&&l.changeType===u.changeType&&l.isUntracked===u.isUntracked&&l.additions===u.additions&&l.deletions===u.deletions&&l.patchDigest===u.patchDigest&&l.mimeType===u.mimeType&&l.size===u.size})}function Eye(e,t){return!!(e&&e.status!=="unknown"&&t&&t.status==="unknown"&&t.files.length===0)}function Tye(e,t){if(e===t)return!0;if(!e||!t)return!1;const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:n.every(i=>{const s=e[i],o=t[i];return!s||!o?!1:s.state===o.state&&s.scheduledAt===o.scheduledAt&&s.resetAt===o.resetAt&&s.detectedAt===o.detectedAt&&s.tz===o.tz})}function Rye(e,t){if(e===t)return!0;if(!e||!t)return!1;const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:n.every(i=>{const s=e[i],o=t[i];return!s||!o?!1:s.state===o.state&&s.url===o.url&&s.error===o.error&&s.port===o.port&&s.activatedAt===o.activatedAt&&s.stoppedAt===o.stoppedAt})}function Nye(e,t){return e===t?!0:!e||!t?!1:bye(e.runtime,t.runtime)&&Cye(e.queuedMessages,t.queuedMessages)&&yye(e.messages,t.messages)&&_ye(e.history,t.history)&&xye(e.availableProviders,t.availableProviders)&&Tye(e.schedules,t.schedules)&&e.liveScheduleId===t.liveScheduleId&&Rye(e.tunnels,t.tunnels)&&e.liveTunnelId===t.liveTunnelId}function ID(e,t){const n=new Map;for(const r of e)n.set(r._id,r);for(const r of t)n.set(r._id,r);return[...n.values()]}function Aye(e){for(let t=e.length-1;t>=0;t-=1){const n=e[t];if((n==null?void 0:n.kind)==="user_prompt"&&n.content.trim().length>0)return n.content}return null}const PD="__new_chat__",uF="lever-theme",dF="chat-sound-preferences",fF="terminal-preferences",hF="chat-preferences";function qw(e){if(typeof window>"u")return null;const t=window.localStorage.getItem(e);if(!t)return null;try{const n=JSON.parse(t);return n.state&&typeof n.state=="object"&&!Array.isArray(n.state)?n.state:null}catch{return null}}function Mye(){if(typeof window>"u")return null;const e={},t=window.localStorage.getItem(uF);(t==="light"||t==="dark"||t==="system")&&(e.theme=t);const n=qw(dF);((n==null?void 0:n.chatSoundPreference)==="never"||(n==null?void 0:n.chatSoundPreference)==="unfocused"||(n==null?void 0:n.chatSoundPreference)==="always")&&(e.chatSoundPreference=n.chatSoundPreference),((n==null?void 0:n.chatSoundId)==="blow"||(n==null?void 0:n.chatSoundId)==="bottle"||(n==null?void 0:n.chatSoundId)==="frog"||(n==null?void 0:n.chatSoundId)==="funk"||(n==null?void 0:n.chatSoundId)==="glass"||(n==null?void 0:n.chatSoundId)==="ping"||(n==null?void 0:n.chatSoundId)==="pop"||(n==null?void 0:n.chatSoundId)==="purr"||(n==null?void 0:n.chatSoundId)==="tink")&&(e.chatSoundId=n.chatSoundId);const r=qw(fF);if(r){e.terminal={},typeof r.scrollbackLines=="number"&&(e.terminal.scrollbackLines=r.scrollbackLines),typeof r.minColumnWidth=="number"&&(e.terminal.minColumnWidth=r.minColumnWidth);const s={};(r.editorPreset==="cursor"||r.editorPreset==="vscode"||r.editorPreset==="xcode"||r.editorPreset==="windsurf"||r.editorPreset==="custom")&&(s.preset=r.editorPreset),typeof r.editorCommandTemplate=="string"&&(s.commandTemplate=r.editorCommandTemplate),Object.keys(s).length>0&&(e.editor=s)}const i=qw(hF);return((i==null?void 0:i.defaultProvider)==="last_used"||(i==null?void 0:i.defaultProvider)==="claude"||(i==null?void 0:i.defaultProvider)==="codex")&&(e.defaultProvider=i.defaultProvider),i!=null&&i.providerDefaults&&typeof i.providerDefaults=="object"&&(e.providerDefaults=i.providerDefaults),e.browserSettingsMigrated=!0,Object.keys(e).length>1?e:null}function Lye(){typeof window>"u"||(window.localStorage.removeItem(uF),window.localStorage.removeItem(dF),window.localStorage.removeItem(fF),window.localStorage.removeItem(hF))}function _h(e){Ks.getState().setFromServer(e);const t=hi.getState();t.setScrollbackLines(e.terminal.scrollbackLines),t.setMinColumnWidth(e.terminal.minColumnWidth),t.setEditorPreset(e.editor.preset),t.setEditorCommandTemplate(e.editor.commandTemplate);const n=Ec.getState();n.setChatSoundPreference(e.chatSoundPreference),n.setChatSoundId(e.chatSoundId),gi.getState().applyServerDefaults(e.defaultProvider,e.providerDefaults)}function jye(e){return JSON.stringify({id:e.id,kind:e.kind,displayName:e.displayName,relativePath:e.relativePath,mimeType:e.mimeType,size:e.size,contentUrl:e.contentUrl})}function f2(e,t=[]){return JSON.stringify({content:e,attachments:t.map(jye)})}function Dye(e,t){return e.reduce((n,r)=>r.kind!=="user_prompt"?n:n+(f2(r.content,r.attachments??[])===t?1:0),0)}function Iye(e,t,n){const r=new Map;for(const i of n){if(i.kind!=="user_prompt")continue;const s=f2(i.content,i.attachments??[]);r.set(s,(r.get(s)??0)+1)}return e.filter(i=>i.scopeId!==t?!0:(r.get(i.signature)??0)<i.requiredMatchCount)}function Pye(e,t,n){return e.some(r=>r.id===t)?e.filter(r=>r.id!==t):e}const Oye=200,zye=500;function OD(e,t){var r;const n=e.find(i=>i.chats.some(s=>s.chatId===t));return n?((r=n.chats.find(i=>i.chatId!==t))==null?void 0:r.chatId)??null:null}function zD(e,t){if(!(t!=null&&t.length)||e.length<=1)return e;const n=new Map(e.map((o,l)=>[o.groupKey,l])),r=new Set,i=t.map(o=>{if(r.has(o))return null;r.add(o);const l=n.get(o);return l===void 0?null:e[l]}).filter(o=>!!o);if(i.length===0)return e;const s=[...i,...e.filter(o=>!r.has(o.groupKey))];return s.every((o,l)=>o===e[l])?e:s}function Bye(e=document){return e.visibilityState==="visible"&&e.hasFocus()}function Fye(){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws`}function $ye(){const[e]=v.useState(()=>new mye(Fye()));return v.useEffect(()=>(e.start(),()=>{e.dispose()}),[e]),e}const BD="kanna:profile-send-to-starting";function Hye(){try{return window.sessionStorage.getItem(BD)==="1"||window.localStorage.getItem(BD)==="1"}catch{return!1}}function pF(e){return Number((performance.now()-e).toFixed(1))}function fl(e,t,n){!e||!Hye()||console.debug("[kanna/send->starting][client]",{traceId:e.traceId,stage:t,elapsedMs:pF(e.startedAt),serverChatId:e.serverChatId,routeChatIdAtSend:e.routeChatIdAtSend,...n})}function Uye(e){var t,n;return(e==null?void 0:e.provider)==="claude"&&e.model&&((t=e.modelOptions)!=null&&t.claude)?{provider:"claude",model:e.model,modelOptions:{reasoningEffort:e.modelOptions.claude.reasoningEffort??"high",contextWindow:e.modelOptions.claude.contextWindow??"200k"},planMode:!!e.planMode}:(e==null?void 0:e.provider)==="codex"&&e.model&&((n=e.modelOptions)!=null&&n.codex)?{provider:"codex",model:e.model,modelOptions:{reasoningEffort:e.modelOptions.codex.reasoningEffort??"high",fastMode:e.modelOptions.codex.fastMode??!1},planMode:!!e.planMode}:null}function Vye(e,t){var n;return t?((n=e.find(r=>r.chats.some(i=>i.chatId===t)))==null?void 0:n.groupKey)??null:null}function Wye(e,t){return e==="awaiting_disconnect"&&t==="disconnected"?"awaiting_server_ready":"none"}const Gye=30,h2="kanna:ui-update-restart",mF="kanna:last-update-reload-request";function qye(e){return e+Gye}function Kye(e,t){return t>0?t:e}function FD(){return window.sessionStorage.getItem(h2)}function bv(e){window.sessionStorage.setItem(h2,e)}function wh(){window.sessionStorage.removeItem(h2)}function Yye(e,t){return e?String(e)!==t:!1}function Xye(){return window.sessionStorage.getItem(mF)}function Qye(e){window.sessionStorage.setItem(mF,String(e))}function Zye(){return"/auth/status"}function Jye(e,t,n="application/json"){const r=new Blob([t],{type:`${n}; charset=utf-8`}),i=URL.createObjectURL(r),s=document.createElement("a");s.href=i,s.download=e,s.style.display="none",document.body.append(s),s.click(),s.remove(),URL.revokeObjectURL(i)}async function e0e(e=fetch){return(await e(Zye(),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}})).ok}function t0e(e){const t=e.selectedProjectId??e.sidebarProjectId??null;return t?{kind:"project_id",projectId:t}:e.fallbackLocalProjectPath?{kind:"local_path",localPath:e.fallbackLocalProjectPath}:null}function n0e(e,t){return!e||!t?null:e.runtime.chatId!==t?(e.runtime.chatId,e.runtime.provider,null):e}function r0e(e){var $r,fo,Yl;const t=Wd(),n=$ye(),r=Kp(),{resolvedTheme:i}=u2(),[s,o]=v.useState({starredProjectGroups:[],projectGroups:[],stacks:[]}),[l,c]=v.useState(null),[u,p]=v.useState(null),[h,g]=v.useState(null),[b,x]=v.useState(null),[_,w]=v.useState([]),[C,E]=v.useState(!1),[k,R]=v.useState(null),[N,A]=v.useState(!1),[M,D]=v.useState({}),[U,j]=v.useState(null),[P,z]=v.useState(null),[O,$]=v.useState(null),[V,B]=v.useState(null),[F,W]=v.useState("connecting"),[X,I]=v.useState(!1),[G,ee]=v.useState(!1),[H,ue]=v.useState(!1),[ae,J]=v.useState(null),[te,ie]=v.useState(!1),[de,he]=v.useState(!1),[Le,ce]=v.useState(!1),[De,pe]=v.useState(null),[st,zt]=v.useState(!1),[Et,Qt]=v.useState(null),[Dt,Tt]=v.useState(!1),[mt,At]=v.useState(null),[It,ht]=v.useState(null),[Ht,ge]=v.useState([]),[we,Be]=v.useState(null),[tt,Pe]=v.useState(0),Ve=v.useRef(new Map),qe=W1(RD(Y=>Object.keys(Y.drafts).sort())),Xe=W1(RD(Y=>Object.keys(Y.attachmentDrafts).sort())),We=v.useRef(0),gt=v.useRef(null),ot=v.useRef({projectId:null,diffs:null}),Bt=vne(hi(Y=>Y.editorPreset)),ut=v.useMemo(()=>zD(s.projectGroups,l),[l,s.projectGroups]),on=v.useRef(ut);v.useLayoutEffect(()=>{on.current=ut});const cn=v.useMemo(()=>ut===s.projectGroups?s:{...s,projectGroups:ut},[s,ut]);v.useEffect(()=>n.onStatus(W),[n]),v.useEffect(()=>n.subscribe({type:"sidebar"},Y=>{o(Y),c(Z=>Z&&zD(Y.projectGroups,Z)===Y.projectGroups?null:Z),I(!0),pe(null)}),[n]),v.useEffect(()=>{if(F!=="connected")return;const Y=[...new Set([...qe,...Xe])].sort();n.command({type:"chat.setDraftProtection",chatIds:Y}).catch(Z=>{pe(Z instanceof Error?Z.message:String(Z))})},[Xe,F,qe,n]),v.useEffect(()=>n.subscribe({type:"local-projects"},Y=>{p(Y),ee(!0),pe(null)}),[n]),v.useEffect(()=>n.subscribe({type:"update"},Y=>{g(Y),pe(null)}),[n]),v.useEffect(()=>{F==="connected"&&n.command({type:"update.check",force:!0}).catch(Y=>{pe(Y instanceof Error?Y.message:String(Y))})},[F,n]),v.useEffect(()=>{const Y=h==null?void 0:h.reloadRequestedAt;Yye(Y,Xye())&&Y&&(Qye(Y),bv("awaiting_disconnect"))},[h==null?void 0:h.reloadRequestedAt]),v.useEffect(()=>{const Y=FD();if(Wye(Y,F)==="awaiting_server_ready"){bv("awaiting_server_ready");return}},[F]),v.useEffect(()=>{if(FD()!=="awaiting_server_ready")return;let Y=!1,Z=null;const Ae=async()=>{try{if(await e0e()){if(Y)return;wh(),window.location.reload();return}}catch{}Y||(Z=window.setTimeout(()=>{Ae()},500))};return Ae(),()=>{Y=!0,Z!==null&&window.clearTimeout(Z)}},[F]),v.useEffect(()=>{function Y(){h!=null&&h.lastCheckedAt&&(Date.now()-h.lastCheckedAt<=3600*1e3||n.command({type:"update.check"}).catch(Z=>{pe(Z instanceof Error?Z.message:String(Z))}))}return window.addEventListener("focus",Y),()=>{window.removeEventListener("focus",Y)}},[n,h==null?void 0:h.lastCheckedAt]),v.useEffect(()=>n.subscribe({type:"keybindings"},Y=>{j(Y),pe(null)}),[n]),v.useEffect(()=>n.subscribe({type:"app-settings"},Y=>{z(Y),_h(Y),pe(null)}),[n]),v.useEffect(()=>n.subscribe({type:"push-config"},Y=>{$(Y)}),[n]),v.useEffect(()=>{let Y=!1;return n.subscribe({type:"bg-tasks"},Z=>{Ys.getState().applySnapshot(Z.tasks),!Y&&Z.orphanRecoveryCount!=null&&Z.orphanRecoveryCount>0&&(Y=!0,gye(Z.orphanRecoveryCount))},Z=>{Z.type==="bg-tasks.added"?Ys.getState().applyDiff({op:"added",task:Z.task}):Z.type==="bg-tasks.updated"?Ys.getState().applyDiff({op:"updated",task:Z.task}):Z.type==="bg-tasks.removed"&&Ys.getState().applyDiff({op:"removed",task:Z.task})})},[n]);const vt=v.useCallback(async()=>{try{Ks.getState().setHydrationStatus("loading");const Y=await n.command({type:"settings.readAppSettings"});z(Y),_h(Y),pe(null)}catch(Y){Ks.getState().setHydrationStatus("error"),pe(Y instanceof Error?Y.message:String(Y))}},[n]),Rt=v.useCallback(async(Y,Z)=>{try{await n.command({type:"chat.setPolicyOverride",chatId:Y,policyOverride:Z}),pe(null)}catch(Ae){throw pe(Ae instanceof Error?Ae.message:String(Ae)),Ae}},[n]),St=v.useCallback(async Y=>{try{Ks.getState().applyOptimisticPatch(Y);const Z=await n.command({type:"settings.writeAppSettingsPatch",patch:Y});z(Z),_h(Z),pe(null)}catch(Z){throw pe(Z instanceof Error?Z.message:String(Z)),await vt(),Z}},[vt,n]),Ut=v.useCallback(async Y=>{try{Ks.getState().applyOptimisticPatch({cloudflareTunnel:Y});const Z=await n.command({type:"appSettings.setCloudflareTunnel",patch:Y});z(Z),_h(Z),pe(null)}catch(Z){throw pe(Z instanceof Error?Z.message:String(Z)),await vt(),Z}},[vt,n]),xt=v.useCallback(async Y=>{try{Ks.getState().applyOptimisticPatch({claudeAuth:Y});const Z=await n.command({type:"appSettings.setClaudeAuth",patch:Y});z(Z),_h(Z),pe(null)}catch(Z){throw pe(Z instanceof Error?Z.message:String(Z)),await vt(),Z}},[vt,n]),ft=v.useCallback(async Y=>await n.command({type:"appSettings.testOAuthToken",token:Y}),[n]),Lt=v.useCallback(async()=>{try{const Y=await n.command({type:"settings.readLlmProvider"});B(Y),pe(null)}catch(Y){pe(Y instanceof Error?Y.message:String(Y))}},[n]),Pt=v.useCallback(async Y=>{try{const Z=await n.command({type:"settings.writeLlmProvider",provider:Y.provider,apiKey:Y.apiKey,model:Y.model,baseUrl:Y.baseUrl});B(Z),pe(null)}catch(Z){throw pe(Z instanceof Error?Z.message:String(Z)),Z}},[n]),Ie=v.useCallback(async Y=>await n.command({type:"settings.validateLlmProvider",provider:Y.provider,apiKey:Y.apiKey,model:Y.model,baseUrl:Y.baseUrl}),[n]);v.useEffect(()=>{F==="connected"&&vt()},[F,vt]),v.useEffect(()=>{if(F!=="connected"||(P==null?void 0:P.browserSettingsMigrated)!==!1)return;const Y=Mye();Y&&St(Y).then(Lye).catch(()=>{})},[P==null?void 0:P.browserSettingsMigrated,F,St]),v.useEffect(()=>{F==="connected"&&Lt()},[F,Lt]),v.useEffect(()=>{function Y(){Pe(Z=>Z+1)}return window.addEventListener("focus",Y),document.addEventListener("visibilitychange",Y),()=>{window.removeEventListener("focus",Y),document.removeEventListener("visibilitychange",Y)}},[]),v.useEffect(()=>{if(!e){x(null),ue(!0);return}++We.current,on.current.length,on.current.reduce((Z,Ae)=>Z+Ae.chats.length,0),x(null),ue(!1);const Y=n.subscribe({type:"chat",chatId:e,recentLimit:Oye},Z=>{if(Z!=null&&Z.runtime.chatId){const Ae=[...Ve.current.values()].filter(bt=>bt.serverChatId===Z.runtime.chatId).sort((bt,Pn)=>Pn.startedAt-bt.startedAt)[0];Ae&&Ae.snapshotAt===void 0&&(Ae.snapshotAt=performance.now(),fl(Ae,"chat_snapshot_received",{status:Z.runtime.status,messageCount:Z.messages.length}))}if(x(Ae=>{const bt=Nye(Ae,Z);return Z==null||Z.runtime.chatId,Z==null||Z.runtime.provider,Z==null||Z.runtime.status,Z==null||Z.messages.length,bt?Ae:Z}),R((Z==null?void 0:Z.history.olderCursor)??null),A((Z==null?void 0:Z.history.hasOlder)??!1),ue(!0),pe(null),Z){const Ae=c2.getState();Ae.setForChat(Z.runtime.chatId,Z.slashCommands??[]),Ae.setLoadingForChat(Z.runtime.chatId,Z.slashCommandsLoading??!1)}});return()=>{on.current.length,on.current.reduce((Z,Ae)=>Z+Ae.chats.length,0),Y()}},[e,n]),v.useEffect(()=>{if(ae)return;const Y=ut[0];Y&&J(Y.groupKey)},[ae,ut]),v.useEffect(()=>{if(!e||!X||!H)return;if(ut.some(Z=>Z.chats.some(Ae=>Ae.chatId===e))){It===e&&ht(null);return}It!==e&&t("/")},[e,H,t,It,ut,X]),v.useEffect(()=>{b&&(J(b.runtime.projectId),It===b.runtime.chatId&&ht(null))},[b,It]),v.useEffect(()=>{if(!e||!X||!Bye())return;const Y=ut.flatMap(Z=>Z.chats).find(Z=>Z.chatId===e);Y!=null&&Y.unread&&n.command({type:"chat.markRead",chatId:e}).catch(Z=>{pe(Z instanceof Error?Z.message:String(Z))})},[e,tt,ut,X,n]),v.useEffect(()=>{w([]),E(!1),R(null),A(!1)},[e]);const ze=v.useMemo(()=>n0e(b,e),[e,b]),Te=v.useMemo(()=>(ze==null?void 0:ze.runtime.projectId)??Vye(ut,e)??ae,[e,ze==null?void 0:ze.runtime.projectId,ae,ut]),Ye=v.useMemo(()=>{const Y=Te?M[Te]??null:null;return Te&&Y?(ot.current={projectId:Te,diffs:Y},Y):Te&&ot.current.projectId===Te?ot.current.diffs:Y},[Te,M]);v.useEffect(()=>Te?n.subscribe({type:"project-git",projectId:Te},Z=>{D(Ae=>{const bt=Z??null;return Eye(Ae[Te]??null,bt)||kye(Ae[Te]??null,bt)?Ae:{...Ae,[Te]:bt}}),pe(null)}):void 0,[Te,n]),v.useEffect(()=>{b==null||b.runtime.chatId,b==null||b.runtime.provider,ze==null||ze.runtime.chatId,ze==null||ze.runtime.provider},[e,ze,b,It]);const _e=v.useMemo(()=>ID(_,(ze==null?void 0:ze.messages)??[]),[ze==null?void 0:ze.messages,_]),Je=e??PD,et=v.useMemo(()=>Ht.filter(Y=>Y.scopeId===Je).map(Y=>Y.entry),[Je,Ht]),$e=v.useMemo(()=>[..._e,...et],[et,_e]),Mt=v.useMemo(()=>lF($e),[$e]),un=v.useMemo(()=>Aye(Mt),[Mt]),Zt=v.useMemo(()=>tye(Mt),[Mt]),Fe=(ze==null?void 0:ze.runtime)??null,hn=(ze==null?void 0:ze.queuedMessages)??[],se=((we==null?void 0:we.scopeId)===Je&&(!Fe||Fe.status==="idle")?"starting":null)??(Fe==null?void 0:Fe.status)??null,le=(ze==null?void 0:ze.availableProviders)??Uh,Ce=rye(se??void 0),Ee=nye(se??void 0),Qe=(Fe==null?void 0:Fe.isDraining)??!1,ct=(($r=u==null?void 0:u.projects[0])==null?void 0:$r.localPath)??null,Ze=(Fe==null?void 0:Fe.localPath)??ct??((fo=ut[0])==null?void 0:fo.localPath),Vt=!!(ae??(Fe==null?void 0:Fe.projectId)??((Yl=ut[0])==null?void 0:Yl.groupKey)??ct);v.useEffect(()=>{(we==null?void 0:we.scopeId)===Je&&Fe!=null&&Fe.status&&Fe.status!=="idle"&&Be(null)},[we,Je,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!(we!=null&&we.ackedAt)||we.scopeId!==Je||Fe!=null&&Fe.status&&Fe.status!=="idle")return;const Y=window.setTimeout(()=>{Be(Z=>(Z==null?void 0:Z.scopeId)===Je&&Z.ackedAt===we.ackedAt?null:Z)},300);return()=>window.clearTimeout(Y)},[we,Je,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!e||(Fe==null?void 0:Fe.status)!=="starting")return;const Y=[...Ve.current.values()].filter(Z=>Z.serverChatId===e).sort((Z,Ae)=>Ae.startedAt-Z.startedAt)[0];!Y||Y.startingStatusAt!==void 0||(Y.startingStatusAt=performance.now(),fl(Y,"runtime_status_starting",{status:Fe.status}))},[e,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!e||!Fe||Fe.status==="starting")return;const Y=[...Ve.current.values()].filter(Z=>Z.serverChatId===e).sort((Z,Ae)=>Ae.startedAt-Z.startedAt)[0];!Y||Y.startingRenderedAt!==void 0||(fl(Y,"starting_not_observed",{status:Fe.status}),Ve.current.delete(Y.traceId))},[e,Fe]),v.useLayoutEffect(()=>{if(!e||(Fe==null?void 0:Fe.status)!=="starting"){gt.current=null;return}const Y=[...Ve.current.values()].filter(Z=>Z.serverChatId===e).sort((Z,Ae)=>Ae.startedAt-Z.startedAt)[0];Y&&gt.current!==Y.traceId&&(gt.current=Y.traceId,Y.startingRenderedAt=performance.now(),fl(Y,"starting_render_committed",{totalMs:pF(Y.startedAt)}),Ve.current.delete(Y.traceId))},[e,Fe==null?void 0:Fe.status]),v.useEffect(()=>{ge(Y=>{const Z=Iye(Y,Je,_e);return Z.length===Y.length&&Z.every((Ae,bt)=>Ae===Y[bt])?Y:Z})},[Je,_e]);const Dn=v.useCallback(async()=>{if(!(!e||!k||C||!N)){E(!0);try{const Y=await n.command({type:"chat.loadHistory",chatId:e,beforeCursor:k,limit:zye});w(Z=>ID(Y.messages,Z)),R(Y.olderCursor),A(Y.hasOlder),pe(null)}catch(Y){const Z=Y instanceof Error?Y.message:String(Y);pe(Z)}finally{E(!1)}}},[e,N,k,C,n]),fn=v.useCallback(async Y=>{const Z=gi.getState(),Ae=e?Z.getComposerState(e):Z.getComposerState(Qh),bt=await n.command({type:"chat.create",projectId:Y});Z.initializeComposerForChat(bt.chatId,{sourceState:Ae}),J(Y),ht(bt.chatId),t(`/chat/${bt.chatId}`),ie(!1),pe(null)},[e,t,n]),Si=v.useCallback(async Y=>Y.kind==="project_id"?{projectId:Y.projectId}:Y.kind==="local_path"?{projectId:(await n.command({type:"project.open",localPath:Y.localPath})).projectId,localPath:Y.localPath}:{projectId:(await n.command(Y.project.mode==="new"?{type:"project.create",localPath:Y.project.localPath,title:Y.project.title}:{type:"project.open",localPath:Y.project.localPath})).projectId,localPath:Y.project.localPath},[n]),Vn=v.useCallback(async Y=>{try{const Z=Y.kind==="project_id"?null:Y.kind==="local_path"?Y.localPath:Y.project.localPath;Z&&At(Z);const{projectId:Ae}=await Si(Y);await fn(Ae)}catch(Z){pe(Z instanceof Error?Z.message:String(Z))}finally{At(null)}},[fn,Si]),Tr=v.useCallback(async Y=>{await Vn({kind:"project_id",projectId:Y})},[Vn]),Qr=v.useCallback(async Y=>{try{const Z=await n.command({type:"chat.fork",chatId:Y.chatId}),Ae=gi.getState();Ae.initializeComposerForChat(Z.chatId,{sourceState:Ae.getComposerState(Y.chatId)}),ht(Z.chatId),t(`/chat/${Z.chatId}`),ie(!1),pe(null)}catch(Z){pe(Z instanceof Error?Z.message:String(Z))}},[t,n]),Oi=v.useCallback(async Y=>{await Vn({kind:"local_path",localPath:Y})},[Vn]),ai=v.useCallback(async Y=>{await Vn({kind:"project_request",project:Y})},[Vn]),ts=v.useCallback(async Y=>{try{await n.command({type:"update.check",force:Y==null?void 0:Y.force}),pe(null)}catch(Z){pe(Z instanceof Error?Z.message:String(Z))}},[n]),zi=v.useCallback(async()=>{try{const Y=await n.command({type:"update.install"});if(!Y.ok){wh(),pe(null),await r.alert({title:Y.userTitle??"Update failed",description:Y.userMessage??"Kanna could not install the update. Try again later.",closeLabel:"OK"});return}if(Y.ok&&Y.action==="reload"){window.location.reload();return}Y.ok&&Y.action==="restart"&&bv("awaiting_disconnect"),pe(null)}catch(Y){wh(),pe(Y instanceof Error?Y.message:String(Y))}},[r,n]),_t=v.useCallback(async()=>{try{const Y=await n.command({type:"update.reload"});if(!Y.ok){wh(),pe(null),await r.alert({title:Y.userTitle??"Re-deploy failed",description:Y.userMessage??"Kanna could not re-deploy. Try again later.",closeLabel:"OK"});return}if(Y.action==="reload"){window.location.reload();return}bv("awaiting_disconnect"),pe(null)}catch(Y){wh(),pe(Y instanceof Error?Y.message:String(Y))}},[r,n]),an=v.useCallback(async()=>{try{const Y=await fetch("/auth/logout",{method:"POST",headers:{Accept:"application/json"}});if(!Y.ok)throw new Error(`Sign out failed with status ${Y.status}`);pe(null),window.location.reload()}catch(Y){pe(Y instanceof Error?Y.message:String(Y))}},[]),kn=v.useCallback(async(Y,Z)=>{var _m;const Ae=(Z==null?void 0:Z.attachments)??[],bt=_c(),Pn=_c(),Zr=f2(Y,Ae),Ba=e??PD;Be({scopeId:Ba,ackedAt:null});const Ps={traceId:Pn,optimisticId:bt,startedAt:performance.now(),serverChatId:e,routeChatIdAtSend:e,contentPreview:Y.slice(0,80)};Ve.current.set(Pn,Ps),fl(Ps,"handle_send_called",{optimisticScopeId:Ba,attachments:Ae.length,contentLength:Y.length,contentPreview:Ps.contentPreview});const S0=Dye(_e,Zr)+Ht.filter(Yn=>Yn.scopeId===Ba&&Yn.signature===Zr).length+1;ge(Yn=>[...Yn,{id:bt,scopeId:Ba,signature:Zr,requiredMatchCount:S0,entry:{_id:`optimistic:${bt}`,kind:"user_prompt",content:Y,attachments:Ae,createdAt:Date.now()}}]),fl(Ps,"optimistic_prompt_added",{optimisticId:bt,optimisticScopeId:Ba});try{let Yn=ae??((_m=ut[0])==null?void 0:_m.groupKey)??null;if(!e&&!Yn&&ct&&(Yn=(await n.command({type:"project.open",localPath:ct})).projectId,J(Yn)),!e&&!Yn)throw new Error("Open a project first");const Sf=G1.getState().autoResumeOnRateLimit,ci=await n.command({type:"chat.send",chatId:e??void 0,projectId:e?void 0:Yn??void 0,clientTraceId:Pn,provider:Z==null?void 0:Z.provider,content:Y,attachments:Ae,model:Z==null?void 0:Z.model,modelOptions:Z==null?void 0:Z.modelOptions,planMode:Z==null?void 0:Z.planMode,autoResumeOnRateLimit:Sf});if(Ps.ackAt=performance.now(),Ps.serverChatId=ci.chatId??Ps.serverChatId,ci.queued?(ge(Os=>Pye(Os,bt,{queued:!0})),Be(null)):Be(Os=>Os&&{scopeId:!e&&ci.chatId?ci.chatId:Os.scopeId,ackedAt:performance.now()}),fl(Ps,"chat_send_ack_received",{resultChatId:ci.chatId??null,queued:ci.queued??!1}),!e&&ci.chatId){ge(wm=>wm.map(Cf=>Cf.id===bt?{...Cf,scopeId:ci.chatId}:Cf));const Os=gi.getState();Os.setComposerState(ci.chatId,Uye(Z)??Os.getComposerState(Qh)),ht(ci.chatId),t(`/chat/${ci.chatId}`)}pe(null)}catch(Yn){throw ge(Sf=>Sf.filter(ci=>ci.id!==bt)),Be(null),fl(Ps,"handle_send_failed",{error:Yn instanceof Error?Yn.message:String(Yn)}),Ve.current.delete(Pn),pe(Yn instanceof Error?Yn.message:String(Yn)),Yn}},[e,ct,t,Ht,ae,_e,ut,n]),gn=v.useCallback(async Y=>{if(e)try{await n.command({type:"message.steer",chatId:e,queuedMessageId:Y}),pe(null)}catch(Z){pe(Z instanceof Error?Z.message:String(Z))}},[e,n]),ao=v.useCallback(async Y=>{if(e)try{await n.command({type:"message.dequeue",chatId:e,queuedMessageId:Y}),pe(null)}catch(Z){pe(Z instanceof Error?Z.message:String(Z))}},[e,n]),Da=v.useCallback(async()=>{if(e)try{await n.command({type:"chat.cancel",chatId:e})}catch(Y){pe(Y instanceof Error?Y.message:String(Y))}},[e,n]),ns=v.useCallback(async()=>{if(e)try{await n.command({type:"chat.stopDraining",chatId:e})}catch(Y){pe(Y instanceof Error?Y.message:String(Y))}},[e,n]),Fo=v.useCallback(async Y=>{const Z=await r.prompt({title:"Rename Chat",initialValue:Y.title,confirmLabel:"Rename"});if(!(!Z||Z===Y.title))try{await n.command({type:"chat.rename",chatId:Y.chatId,title:Z}),pe(null)}catch(Ae){pe(Ae instanceof Error?Ae.message:String(Ae))}},[r,n]),rs=v.useCallback(async Y=>{if(await r.confirm({title:"Delete Chat",description:`Delete "${Y.title}"? This cannot be undone.`,confirmLabel:"Delete",confirmVariant:"destructive"}))try{if(await n.command({type:"chat.delete",chatId:Y.chatId}),Y.chatId===e){const Ae=OD(ut,Y.chatId);t(Ae?`/chat/${Ae}`:"/")}}catch(Ae){pe(Ae instanceof Error?Ae.message:String(Ae))}},[e,r,t,ut,n]),Ia=v.useCallback(async Y=>{try{if(await n.command({type:"chat.archive",chatId:Y.chatId}),Y.chatId===e){const Z=OD(ut,Y.chatId);t(Z?`/chat/${Z}`:"/")}pe(null)}catch(Z){pe(Z instanceof Error?Z.message:String(Z))}},[e,t,ut,n]),cr=v.useCallback(async Y=>{try{ht(Y),await n.command({type:"chat.unarchive",chatId:Y}),t(`/chat/${Y}`),pe(null)}catch(Z){ht(null),pe(Z instanceof Error?Z.message:String(Z))}},[t,n]),je=v.useCallback(async Y=>{try{await n.command({type:"project.remove",projectId:Y}),yl.getState().clearProject(Y),Li.getState().clearProject(Y),(Fe==null?void 0:Fe.projectId)===Y&&t("/"),pe(null)}catch(Z){pe(Z instanceof Error?Z.message:String(Z))}},[t,Fe,n]),Ke=v.useCallback(async(Y,Z)=>{try{await n.command({type:"project.setStar",projectId:Y,starred:Z}),pe(null)}catch(Ae){pe(Ae instanceof Error?Ae.message:String(Ae))}},[n]),Ft=v.useCallback(async Y=>{c(Y);try{await n.command({type:"sidebar.reorderProjectGroups",projectIds:Y}),pe(null)}catch(Z){c(null),pe(Z instanceof Error?Z.message:String(Z))}},[n]),tr=v.useCallback(async(Y,Z)=>{try{await n.command({type:"stack.create",title:Y,projectIds:Z}),pe(null)}catch(Ae){pe(Ae instanceof Error?Ae.message:String(Ae))}},[n]),li=v.useCallback(async(Y,Z)=>{try{await n.command({type:"stack.rename",stackId:Y,title:Z}),pe(null)}catch(Ae){pe(Ae instanceof Error?Ae.message:String(Ae))}},[n]),lo=v.useCallback(async Y=>{try{await n.command({type:"stack.remove",stackId:Y}),pe(null)}catch(Z){pe(Z instanceof Error?Z.message:String(Z))}},[n]),Q=v.useCallback(async(Y,Z)=>{try{await n.command({type:"stack.addProject",stackId:Y,projectId:Z}),pe(null)}catch(Ae){pe(Ae instanceof Error?Ae.message:String(Ae))}},[n]),Oe=v.useCallback(async(Y,Z)=>{try{await n.command({type:"stack.removeProject",stackId:Y,projectId:Z}),pe(null)}catch(Ae){pe(Ae instanceof Error?Ae.message:String(Ae))}},[n]),xn=v.useCallback(async(Y,Z,Ae)=>{try{const bt=gi.getState(),Pn=e?bt.getComposerState(e):bt.getComposerState(Qh),Zr=await n.command({type:"chat.create",projectId:Y,stackId:Z,stackBindings:Ae});bt.initializeComposerForChat(Zr.chatId,{sourceState:Pn}),J(Y),ht(Zr.chatId),t(`/chat/${Zr.chatId}`),ie(!1),pe(null)}catch(bt){pe(bt instanceof Error?bt.message:String(bt))}},[e,t,n]),co=v.useCallback(async Y=>{try{const Z=await n.command({type:"stack.listWorktrees",projectId:Y});return pe(null),Z.worktrees}catch(Z){return pe(Z instanceof Error?Z.message:String(Z)),[]}},[n]),Wl=v.useCallback(async()=>await n.command({type:"sessions.importClaude"}),[n]),is=v.useCallback(async Y=>{const Z=hi.getState();pe(null),await n.command({type:"system.openExternal",...Y,editor:Y.action==="open_editor"?Y.editor??{preset:Z.editorPreset,commandTemplate:Z.editorCommandTemplate}:void 0})},[n]),bf=v.useCallback(async(Y,Z)=>{var bt,Pn;const Ae=(Fe==null?void 0:Fe.localPath)??((bt=u==null?void 0:u.projects[0])==null?void 0:bt.localPath)??((Pn=ut[0])==null?void 0:Pn.localPath);if(Ae)try{await is({action:Y,localPath:Ae,editor:Z})}catch(Zr){pe(Zr instanceof Error?Zr.message:String(Zr))}},[u==null?void 0:u.projects,is,Fe==null?void 0:Fe.localPath,ut]),Pa=v.useCallback(async Y=>{var Z;try{if(typeof navigator>"u"||!((Z=navigator.clipboard)!=null&&Z.writeText))throw new Error("Clipboard is not available");await navigator.clipboard.writeText(Y),pe(null)}catch(Ae){pe(Ae instanceof Error?Ae.message:String(Ae))}},[]),Ds=v.useCallback(async(Y,Z="open_editor",Ae)=>{try{await is({action:Z,localPath:Y.path,line:Y.line,column:Y.column,editor:Ae})}catch(bt){pe(bt instanceof Error?bt.message:String(bt))}},[is]),yf=v.useCallback(async(Y,Z)=>{try{await is({action:Y,localPath:Z})}catch(Ae){pe(Ae instanceof Error?Ae.message:String(Ae))}},[is]),Gl=v.useCallback(async(Y=e)=>{if(!Y||st)return null;zt(!0);try{const Z=await n.command({type:"chat.exportStandalone",chatId:Y,theme:i,attachmentMode:"bundle"});return pe(null),Z}catch(Z){return pe(Z instanceof Error?Z.message:String(Z)),null}finally{zt(!1)}},[e,st,i,n]),Oa=v.useCallback(async(Y=e)=>{if(!Y||st)return;Tt(!1);const Z=await Gl(Y);if(Z!=null&&Z.ok&&Z.shareUrl){Qt(Z.shareUrl),Tt(!0);return}Z&&!Z.ok&&await r.confirm({title:"Share failed",description:Z.error,confirmLabel:"Download transcript JSON",cancelLabel:"Close",confirmVariant:"secondary"})&&Jye(Z.transcriptFileName,Z.transcriptJson)},[e,r,Gl,st]),za=v.useCallback(()=>{Qt(null),Tt(!1)},[]),vm=v.useCallback(async()=>{var Y;if(!Et)return!1;try{if(typeof navigator>"u"||!((Y=navigator.clipboard)!=null&&Y.writeText))throw new Error("Clipboard is not available");return await navigator.clipboard.writeText(Et),!0}catch(Z){return await r.alert({title:"Copy failed",description:Z instanceof Error?Z.message:String(Z),closeLabel:"Close"}),!1}},[r,Et]),xf=v.useCallback(()=>{Et&&(window.open(Et,"_blank","noopener,noreferrer"),Qt(null))},[Et]),bm=v.useCallback(()=>{var Z;const Y=t0e({selectedProjectId:ae,sidebarProjectId:(Z=ut[0])==null?void 0:Z.groupKey,fallbackLocalProjectPath:ct});if(Y){Vn(Y);return}t("/")},[ct,t,ae,ut,Vn]),ql=v.useCallback(()=>ie(!0),[]),Is=v.useCallback(()=>ie(!1),[]),_f=v.useCallback(()=>he(!0),[]),Kl=v.useCallback(()=>he(!1),[]),uo=v.useCallback(()=>ce(!0),[]),wf=v.useCallback(()=>ce(!1),[]),lu=v.useCallback(async(Y,Z,Ae)=>{if(e)try{await n.command({type:"chat.respondTool",chatId:e,toolUseId:Y,result:{questions:Z,answers:Ae}})}catch(bt){pe(bt instanceof Error?bt.message:String(bt))}},[e,n]),ym=v.useCallback(async(Y,Z,Ae,bt)=>{if(e){Z&&gi.getState().setChatComposerPlanMode(e,!1);try{await n.command({type:"chat.respondTool",chatId:e,toolUseId:Y,result:{confirmed:Z,...Ae?{clearContext:!0}:{},...bt?{message:bt}:{}}})}catch(Pn){pe(Pn instanceof Error?Pn.message:String(Pn))}}},[e,n]),cu=v.useCallback(async(Y,Z,Ae,bt)=>{if(e)try{await n.command({type:"chat.respondSubagentTool",chatId:e,runId:Y,toolUseId:Z,result:{questions:Ae,answers:bt}})}catch(Pn){pe(Pn instanceof Error?Pn.message:String(Pn))}},[e,n]),uu=v.useCallback(async(Y,Z,Ae)=>{if(e)try{await n.command({type:"chat.respondSubagentTool",chatId:e,runId:Y,toolUseId:Z,result:Ae})}catch(bt){pe(bt instanceof Error?bt.message:String(bt))}},[e,n]),xm=v.useCallback(async(Y,Z)=>{if(e)try{await n.command({type:"chat.toolRequestAnswer",chatId:e,toolRequestId:Y,decision:Z})}catch(Ae){pe(Ae instanceof Error?Ae.message:String(Ae))}},[e,n]);return{socket:n,activeChatId:e,activeProjectId:Te,sidebarData:cn,localProjects:u,updateSnapshot:h,chatSnapshot:b,chatDiffSnapshot:Ye,keybindings:U,appSettings:P,pushConfig:O,llmProvider:V,connectionStatus:F,sidebarReady:X,localProjectsReady:G,commandError:De,startingLocalPath:mt,sidebarOpen:te,sidebarCollapsed:de,messages:Mt,queuedMessages:hn,previousPrompt:un,latestToolIds:Zt,runtime:Fe,runtimeStatus:se,isHistoryLoading:C,hasOlderHistory:N,availableProviders:le,isProcessing:Ce,canCancel:Ee,isDraining:Qe,isExportingStandalone:st,standaloneShareUrl:Et,standaloneShareComplete:Dt,navbarLocalPath:Ze,editorLabel:Bt,hasSelectedProject:Vt,addProjectModalOpen:Le,openSidebar:ql,closeSidebar:Is,collapseSidebar:_f,expandSidebar:Kl,openAddProjectModal:uo,closeAddProjectModal:wf,loadOlderHistory:Dn,handleCreateChat:Tr,handleForkChat:Qr,handleOpenLocalProject:Oi,handleCreateProject:ai,handleCheckForUpdates:ts,handleInstallUpdate:zi,handleForceReload:_t,handleReadAppSettings:vt,handleWriteAppSettings:St,handleSetChatPolicyOverride:Rt,handleWriteCloudflareTunnel:Ut,handleWriteClaudeAuth:xt,handleTestOAuthToken:ft,handleReadLlmProvider:Lt,handleWriteLlmProvider:Pt,handleValidateLlmProvider:Ie,handleSignOut:an,handleSend:kn,handleSteerQueuedMessage:gn,handleRemoveQueuedMessage:ao,handleCancel:Da,handleStopDraining:ns,handleRenameChat:Fo,handleShareChat:Oa,handleArchiveChat:Ia,handleOpenArchivedChat:cr,handleDeleteChat:rs,handleHideProject:je,handleToggleProjectStar:Ke,handleReorderProjectGroups:Ft,stacks:cn.stacks,handleCreateStack:tr,handleRenameStack:li,handleRemoveStack:lo,handleAddProjectToStack:Q,handleRemoveProjectFromStack:Oe,handleCreateStackChat:xn,handleListStackWorktrees:co,importClaudeSessions:Wl,handleCopyPath:Pa,handleOpenExternal:bf,handleOpenExternalPath:yf,handleOpenLocalLink:Ds,handleCompose:bm,handleAskUserQuestion:lu,handleExitPlanMode:ym,handleSubagentAskUserQuestion:cu,handleSubagentExitPlanMode:uu,handleExportStandalone:Gl,handleCloseStandaloneShareDialog:za,handleOpenStandaloneShareLink:xf,handleCopyStandaloneShareLink:vm,handleToolRequestAnswer:xm}}const gF=v.memo(function({message:t}){return f.jsx("div",{className:"text-pretty prose prose-sm dark:prose-invert px-0.5 w-full max-w-[70ch] space-y-4",children:f.jsx(tu,{remarkPlugins:hf,components:pf,children:t.text})})}),dm=({children:e,className:t,animate:n=!0,shimmerWidth:r,...i})=>f.jsx("span",{className:me("mx-auto max-w-md text-foreground/60",n&&"animate-shiny-pulse",t),...i,children:e});function i0e(e){const t=e.split(`
2605
+ `},i),s}function fge(e,t){return e&&"run"in e?async function(n,r){const i=Xj(n,{file:r,...t});await e.run(i,r)}:function(n,r){return Xj(n,{file:r,...e||t})}}function Qj(e){if(e)throw e}var Pw,Zj;function hge(){if(Zj)return Pw;Zj=1;var e=Object.prototype.hasOwnProperty,t=Object.prototype.toString,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=function(u){return typeof Array.isArray=="function"?Array.isArray(u):t.call(u)==="[object Array]"},s=function(u){if(!u||t.call(u)!=="[object Object]")return!1;var p=e.call(u,"constructor"),h=u.constructor&&u.constructor.prototype&&e.call(u.constructor.prototype,"isPrototypeOf");if(u.constructor&&!p&&!h)return!1;var g;for(g in u);return typeof g>"u"||e.call(u,g)},o=function(u,p){n&&p.name==="__proto__"?n(u,p.name,{enumerable:!0,configurable:!0,value:p.newValue,writable:!0}):u[p.name]=p.newValue},l=function(u,p){if(p==="__proto__")if(e.call(u,p)){if(r)return r(u,p).value}else return;return u[p]};return Pw=function c(){var u,p,h,g,b,x,_=arguments[0],w=1,C=arguments.length,E=!1;for(typeof _=="boolean"&&(E=_,_=arguments[1]||{},w=2),(_==null||typeof _!="object"&&typeof _!="function")&&(_={});w<C;++w)if(u=arguments[w],u!=null)for(p in u)h=l(_,p),g=l(u,p),_!==g&&(E&&g&&(s(g)||(b=i(g)))?(b?(b=!1,x=h&&i(h)?h:[]):x=h&&s(h)?h:{},o(_,{name:p,newValue:c(E,x,g)})):typeof g<"u"&&o(_,{name:p,newValue:g}));return _},Pw}var pge=hge();const Ow=cy(pge);function z1(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function mge(){const e=[],t={run:n,use:r};return t;function n(...i){let s=-1;const o=i.pop();if(typeof o!="function")throw new TypeError("Expected function as last argument, not "+o);l(null,...i);function l(c,...u){const p=e[++s];let h=-1;if(c){o(c);return}for(;++h<i.length;)(u[h]===null||u[h]===void 0)&&(u[h]=i[h]);i=u,p?gge(p,l)(...u):o(null,...u)}}function r(i){if(typeof i!="function")throw new TypeError("Expected `middelware` to be a function, not "+i);return e.push(i),t}}function gge(e,t){let n;return r;function r(...o){const l=e.length>o.length;let c;l&&o.push(i);try{c=e.apply(this,o)}catch(u){const p=u;if(l&&n)throw p;return i(p)}l||(c&&c.then&&typeof c.then=="function"?c.then(s,i):c instanceof Error?i(c):s(c))}function i(o,...l){n||(n=!0,t(o,...l))}function s(o){i(null,o)}}const wo={basename:vge,dirname:bge,extname:yge,join:xge,sep:"/"};function vge(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');cm(e);let n=0,r=-1,i=e.length,s;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(s){n=i+1;break}}else r<0&&(s=!0,r=i+1);return r<0?"":e.slice(n,r)}if(t===e)return"";let o=-1,l=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(s){n=i+1;break}}else o<0&&(s=!0,o=i+1),l>-1&&(e.codePointAt(i)===t.codePointAt(l--)?l<0&&(r=i):(l=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function bge(e){if(cm(e),e.length===0)return".";let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||(r=!0);return t<0?e.codePointAt(0)===47?"/":".":t===1&&e.codePointAt(0)===47?"//":e.slice(0,t)}function yge(e){cm(e);let t=e.length,n=-1,r=0,i=-1,s=0,o;for(;t--;){const l=e.codePointAt(t);if(l===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),l===46?i<0?i=t:s!==1&&(s=1):i>-1&&(s=-1)}return i<0||n<0||s===0||s===1&&i===n-1&&i===r+1?"":e.slice(i,n)}function xge(...e){let t=-1,n;for(;++t<e.length;)cm(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":_ge(n)}function _ge(e){cm(e);const t=e.codePointAt(0)===47;let n=wge(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function wge(e,t){let n="",r=0,i=-1,s=0,o=-1,l,c;for(;++o<=e.length;){if(o<e.length)l=e.codePointAt(o);else{if(l===47)break;l=47}if(l===47){if(!(i===o-1||s===1))if(i!==o-1&&s===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(c=n.lastIndexOf("/"),c!==n.length-1){c<0?(n="",r=0):(n=n.slice(0,c),r=n.length-1-n.lastIndexOf("/")),i=o,s=0;continue}}else if(n.length>0){n="",r=0,i=o,s=0;continue}}t&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,s=0}else l===46&&s>-1?s++:s=-1}return n}function cm(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const Sge={cwd:Cge};function Cge(){return"/"}function B1(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function kge(e){if(typeof e=="string")e=new URL(e);else if(!B1(e)){const t=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code="ERR_INVALID_ARG_TYPE",t}if(e.protocol!=="file:"){const t=new TypeError("The URL must be of scheme file");throw t.code="ERR_INVALID_URL_SCHEME",t}return Ege(e)}function Ege(e){if(e.hostname!==""){const r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}const t=e.pathname;let n=-1;for(;++n<t.length;)if(t.codePointAt(n)===37&&t.codePointAt(n+1)===50){const r=t.codePointAt(n+2);if(r===70||r===102){const i=new TypeError("File URL path must not include encoded / characters");throw i.code="ERR_INVALID_FILE_URL_PATH",i}}return decodeURIComponent(t)}const zw=["history","path","basename","stem","extname","dirname"];class TB{constructor(t){let n;t?B1(t)?n={path:t}:typeof t=="string"||Tge(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":Sge.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<zw.length;){const s=zw[r];s in n&&n[s]!==void 0&&n[s]!==null&&(this[s]=s==="history"?[...n[s]]:n[s])}let i;for(i in n)zw.includes(i)||(this[i]=n[i])}get basename(){return typeof this.path=="string"?wo.basename(this.path):void 0}set basename(t){Fw(t,"basename"),Bw(t,"basename"),this.path=wo.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?wo.dirname(this.path):void 0}set dirname(t){Jj(this.basename,"dirname"),this.path=wo.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?wo.extname(this.path):void 0}set extname(t){if(Bw(t,"extname"),Jj(this.dirname,"extname"),t){if(t.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(t.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=wo.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){B1(t)&&(t=kge(t)),Fw(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?wo.basename(this.path,this.extname):void 0}set stem(t){Fw(t,"stem"),Bw(t,"stem"),this.path=wo.join(this.dirname||"",t+(this.extname||""))}fail(t,n,r){const i=this.message(t,n,r);throw i.fatal=!0,i}info(t,n,r){const i=this.message(t,n,r);return i.fatal=void 0,i}message(t,n,r){const i=new oi(t,n,r);return this.path&&(i.name=this.path+":"+i.name,i.file=this.path),i.fatal=!1,this.messages.push(i),i}toString(t){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(t||void 0).decode(this.value)}}function Bw(e,t){if(e&&e.includes(wo.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+wo.sep+"`")}function Fw(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function Jj(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function Tge(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Rge=(function(e){const r=this.constructor.prototype,i=r[e],s=function(){return i.apply(s,arguments)};return Object.setPrototypeOf(s,r),s}),Nge={}.hasOwnProperty;class KE extends Rge{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=mge()}copy(){const t=new KE;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];t.use(...r)}return t.data(Ow(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(Uw("data",this.frozen),this.namespace[t]=n,this):Nge.call(this.namespace,t)&&this.namespace[t]||void 0:t?(Uw("data",this.frozen),this.namespace=t,this):this.namespace}freeze(){if(this.frozen)return this;const t=this;for(;++this.freezeIndex<this.attachers.length;){const[n,...r]=this.attachers[this.freezeIndex];if(r[0]===!1)continue;r[0]===!0&&(r[0]=void 0);const i=n.call(t,...r);typeof i=="function"&&this.transformers.use(i)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(t){this.freeze();const n=uv(t),r=this.parser||this.Parser;return $w("parse",r),r(String(n),n)}process(t,n){const r=this;return this.freeze(),$w("process",this.parser||this.Parser),Hw("process",this.compiler||this.Compiler),n?i(void 0,n):new Promise(i);function i(s,o){const l=uv(t),c=r.parse(l);r.run(c,l,function(p,h,g){if(p||!h||!g)return u(p);const b=h,x=r.stringify(b,g);Lge(x)?g.value=x:g.result=x,u(p,g)});function u(p,h){p||!h?o(p):s?s(h):n(void 0,h)}}}processSync(t){let n=!1,r;return this.freeze(),$w("processSync",this.parser||this.Parser),Hw("processSync",this.compiler||this.Compiler),this.process(t,i),tD("processSync","process",n),r;function i(s,o){n=!0,Qj(s),r=o}}run(t,n,r){eD(t),this.freeze();const i=this.transformers;return!r&&typeof n=="function"&&(r=n,n=void 0),r?s(void 0,r):new Promise(s);function s(o,l){const c=uv(n);i.run(t,c,u);function u(p,h,g){const b=h||t;p?l(p):o?o(b):r(void 0,b,g)}}}runSync(t,n){let r=!1,i;return this.run(t,n,s),tD("runSync","run",r),i;function s(o,l){Qj(o),i=l,r=!0}}stringify(t,n){this.freeze();const r=uv(n),i=this.compiler||this.Compiler;return Hw("stringify",i),eD(t),i(t,r)}use(t,...n){const r=this.attachers,i=this.namespace;if(Uw("use",this.frozen),t!=null)if(typeof t=="function")c(t,n);else if(typeof t=="object")Array.isArray(t)?l(t):o(t);else throw new TypeError("Expected usable value, not `"+t+"`");return this;function s(u){if(typeof u=="function")c(u,[]);else if(typeof u=="object")if(Array.isArray(u)){const[p,...h]=u;c(p,h)}else o(u);else throw new TypeError("Expected usable value, not `"+u+"`")}function o(u){if(!("plugins"in u)&&!("settings"in u))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");l(u.plugins),u.settings&&(i.settings=Ow(!0,i.settings,u.settings))}function l(u){let p=-1;if(u!=null)if(Array.isArray(u))for(;++p<u.length;){const h=u[p];s(h)}else throw new TypeError("Expected a list of plugins, not `"+u+"`")}function c(u,p){let h=-1,g=-1;for(;++h<r.length;)if(r[h][0]===u){g=h;break}if(g===-1)r.push([u,...p]);else if(p.length>0){let[b,...x]=p;const _=r[g][1];z1(_)&&z1(b)&&(b=Ow(!0,_,b)),r[g]=[u,b,...x]}}}}const Age=new KE().freeze();function $w(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function Hw(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function Uw(e,t){if(t)throw new Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function eD(e){if(!z1(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function tD(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function uv(e){return Mge(e)?e:new TB(e)}function Mge(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function Lge(e){return typeof e=="string"||jge(e)}function jge(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Dge="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",nD=[],rD={allowDangerousHtml:!0},Ige=/^(https?|ircs?|mailto|xmpp)$/i,Pge=[{from:"astPlugins",id:"remove-buggy-html-in-markdown-parser"},{from:"allowDangerousHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"allowNode",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowElement"},{from:"allowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowedElements"},{from:"className",id:"remove-classname"},{from:"disallowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"disallowedElements"},{from:"escapeHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"includeElementIndex",id:"#remove-includeelementindex"},{from:"includeNodeIndex",id:"change-includenodeindex-to-includeelementindex"},{from:"linkTarget",id:"remove-linktarget"},{from:"plugins",id:"change-plugins-to-remarkplugins",to:"remarkPlugins"},{from:"rawSourcePos",id:"#remove-rawsourcepos"},{from:"renderers",id:"change-renderers-to-components",to:"components"},{from:"source",id:"change-source-to-children",to:"children"},{from:"sourcePos",id:"#remove-sourcepos"},{from:"transformImageUri",id:"#add-urltransform",to:"urlTransform"},{from:"transformLinkUri",id:"#add-urltransform",to:"urlTransform"}];function tu(e){const t=Oge(e),n=zge(e);return Bge(t.runSync(t.parse(n),n),e)}function Oge(e){const t=e.rehypePlugins||nD,n=e.remarkPlugins||nD,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...rD}:rD;return Age().use(Eme).use(n).use(fge,r).use(t)}function zge(e){const t=e.children||"",n=new TB;return typeof t=="string"&&(n.value=t),n}function Bge(e,t){const n=t.allowedElements,r=t.allowElement,i=t.components,s=t.disallowedElements,o=t.skipHtml,l=t.unwrapDisallowed,c=t.urlTransform||Fge;for(const p of Pge)Object.hasOwn(t,p.from)&&(""+p.from+(p.to?"use `"+p.to+"` instead":"remove it")+Dge+p.id,void 0);return jE(e,u),Dpe(e,{Fragment:f.Fragment,components:i,ignoreInvalidStyle:!0,jsx:f.jsx,jsxs:f.jsxs,passKeys:!0,passNode:!0});function u(p,h,g){if(p.type==="raw"&&g&&typeof h=="number")return o?g.children.splice(h,1):g.children[h]={type:"text",value:p.value},h;if(p.type==="element"){let b;for(b in Iw)if(Object.hasOwn(Iw,b)&&Object.hasOwn(p.properties,b)){const x=p.properties[b],_=Iw[b];(_===null||_.includes(p.tagName))&&(p.properties[b]=c(String(x||""),b,p))}}if(p.type==="element"){let b=n?!n.includes(p.tagName):s?s.includes(p.tagName):!1;if(!b&&r&&typeof h=="number"&&(b=!r(p,h,g)),b&&g&&typeof h=="number")return l&&p.children?g.children.splice(h,1,...p.children):g.children.splice(h,1),h}}}function Fge(e){const t=e.indexOf(":"),n=e.indexOf("?"),r=e.indexOf("#"),i=e.indexOf("/");return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||Ige.test(e.slice(0,t))?e:""}const dv=new Map;function $ge(e){return`${e.id}|${e.contentUrl}|${e.size??0}`}function a0(e){const t=$ge(e),n=dv.get(t),[r,i]=v.useState(n??{status:"loading"}),[s,o]=v.useState(t),l=v.useRef(t);return l.current=t,s!==t&&(o(t),i(dv.get(t)??{status:"loading"})),v.useEffect(()=>{if(n&&n.status!=="loading")return;let c=!1;const u=t;return ME(e.contentUrl,S8).then(p=>{if(c||l.current!==u)return;const h={status:"ready",content:p.content,truncated:p.truncated};dv.set(u,h),i(h)}).catch(p=>{if(c||l.current!==u)return;const g={status:"error",message:p instanceof Error?p.message:"Unable to load preview."};dv.set(u,g),i(g)}),()=>{c=!0}},[n,t,e.contentUrl]),r}function Hge({source:e}){const t=a0(e);return t.status==="loading"?f.jsxs("div",{className:"p-4 text-sm text-muted-foreground",children:[f.jsx("div",{className:"prose hidden"})," Loading…"]}):t.status==="error"?f.jsx("div",{className:"p-4 text-sm text-destructive",children:t.message}):f.jsxs("div",{className:"space-y-2 overflow-auto p-3",children:[t.truncated?f.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-xs text-muted-foreground",children:"Preview truncated to 1024 KB."}):null,f.jsx("div",{className:"prose prose-sm prose-invert max-w-none rounded-xl border border-border bg-background p-4",children:f.jsx(tu,{remarkPlugins:hf,components:pf,children:t.content})})]})}const fv=new Map;function Uge(e){return`${e.id}|${e.contentUrl}|${e.size??0}|${e.mimeType}`}function Vge({source:e}){const t=Uge(e),n=fv.get(t),[r,i]=v.useState(n??{status:"loading"}),[s,o]=v.useState(t),l=v.useRef(t);if(l.current=t,s!==t&&(o(t),i(fv.get(t)??{status:"loading"})),v.useEffect(()=>{if(n&&n.status!=="loading")return;const g=e.mimeType==="text/tab-separated-values"?" ":",";let b=!1;const x=t;return ME(e.contentUrl,S8).then(_=>{if(b||l.current!==x)return;const w={status:"ready",table:wue(_.content,g),truncated:_.truncated};fv.set(x,w),i(w)}).catch(_=>{if(b||l.current!==x)return;const w={status:"error",message:_ instanceof Error?_.message:"Unable to load preview."};fv.set(x,w),i(w)}),()=>{b=!0}},[n,t,e.contentUrl,e.mimeType]),r.status==="loading")return f.jsxs("div",{className:"p-4 text-sm text-muted-foreground",children:[f.jsx("table",{className:"sr-only"})," Loading…"]});if(r.status==="error")return f.jsxs("div",{className:"p-4 text-sm text-destructive",children:[f.jsx("table",{className:"sr-only"})," ",r.message]});const{table:c}=r,[u,...p]=c.rows,h=[r.truncated?"Preview truncated to 1024 KB.":null,c.truncatedRows?`Showing first ${c.rows.length} of ${c.rowCount} rows.`:null,c.truncatedColumns?`Showing first ${A1} of ${c.columnCount} columns.`:null].filter(Boolean);return f.jsxs("div",{className:"space-y-2 overflow-auto p-3",children:[h.length?f.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-xs text-muted-foreground",children:h.join(" ")}):null,f.jsx("div",{className:"max-h-[70dvh] overflow-auto rounded-xl border border-border bg-background",children:f.jsxs("table",{className:"min-w-full border-collapse text-xs",children:[u?f.jsx("thead",{className:"sticky top-0 bg-muted",children:f.jsx("tr",{children:u.map((g,b)=>f.jsx("th",{className:"border-b border-border px-3 py-2 text-left font-medium",children:g||" "},b))})}):null,f.jsx("tbody",{children:p.map((g,b)=>f.jsx("tr",{className:"odd:bg-background even:bg-muted/20",children:g.map((x,_)=>f.jsx("td",{className:"max-w-[320px] border-b border-border px-3 py-2 align-top",children:f.jsx("div",{className:"whitespace-pre-wrap break-words",children:x||" "})},_))},b))})]})})]})}function Wge({source:e}){const t=a0(e);return t.status==="loading"?f.jsxs("div",{className:"p-4 text-sm text-muted-foreground",children:[f.jsx("pre",{className:"sr-only"})," Loading…"]}):t.status==="error"?f.jsxs("div",{className:"p-4 text-sm text-destructive",children:[f.jsx("pre",{className:"sr-only"})," ",t.message]}):f.jsxs("div",{className:"space-y-2 overflow-auto p-3",children:[t.truncated?f.jsx(Gge,{children:"Preview truncated to 1024 KB."}):null,f.jsx("pre",{className:"whitespace-pre-wrap break-words rounded-xl border border-border bg-background p-3 text-xs",children:t.content})]})}function Gge({children:e}){return f.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-xs text-muted-foreground",children:e})}function qge({source:e}){const t=a0(e),n=v.useMemo(()=>t.status==="ready"?_ue(t.content):"",[t]);return t.status==="loading"?f.jsxs("div",{className:"p-4 text-sm text-muted-foreground",children:[f.jsx("pre",{className:"sr-only"})," Loading…"]}):t.status==="error"?f.jsxs("div",{className:"p-4 text-sm text-destructive",children:[f.jsx("pre",{className:"sr-only"})," ",t.message]}):f.jsxs("div",{className:"space-y-2 overflow-auto p-3",children:[t.truncated?f.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-xs text-muted-foreground",children:"Preview truncated to 1024 KB."}):null,f.jsx("pre",{className:"whitespace-pre-wrap break-words rounded-xl border border-border bg-background p-3 text-xs",children:n})]})}function Kge({source:e}){return f.jsxs("div",{className:"flex h-full flex-col items-stretch justify-center gap-3 p-4",children:[f.jsx("div",{className:"text-sm font-medium text-foreground",children:e.displayName}),f.jsx("audio",{src:e.contentUrl,controls:!0,preload:"metadata",className:"w-full"})]})}function Yge({source:e}){return f.jsx("div",{className:"flex h-full items-center justify-center bg-black/40 p-2",children:f.jsx("video",{src:e.contentUrl,controls:!0,playsInline:!0,preload:"metadata",className:"max-h-[60dvh] w-full rounded-xl"})})}const Xge=200*1024;function Qge(e){const t=e.lastIndexOf(".");if(t<0)return"text";const n=e.slice(t+1).toLowerCase();return{ts:"typescript",tsx:"tsx",js:"javascript",jsx:"jsx",py:"python",go:"go",rs:"rust",java:"java",rb:"ruby",sh:"bash",zsh:"bash",yml:"yaml",yaml:"yaml",css:"css",scss:"scss",html:"html",json:"json",md:"markdown",sql:"sql",cpp:"cpp",c:"c",h:"c",swift:"swift",kt:"kotlin",php:"php",toml:"toml"}[n]??"text"}function Zge({source:e}){const t=a0(e),n=t.status==="ready"&&t.content.length<=Xge,r=n?`${e.id}|${e.contentUrl}|${e.size??0}|${t.content.length}`:null,[i,s]=v.useState(null);return v.useEffect(()=>{if(!n||t.status!=="ready"||r===null)return;let o=!1;const l=r;return K(()=>Promise.resolve().then(()=>mle),void 0).then(async c=>{if(o)return;const u=await c.codeToHtml(t.content,{lang:Qge(e.fileName),theme:"github-dark"});o||s({key:l,html:u})}).catch(()=>{typeof console<"u"&&console.warn("[file-preview] Shiki unavailable; falling back to plain text")}),()=>{o=!0}},[n,r,t,e.fileName]),t.status==="loading"?f.jsxs("div",{className:"p-4 text-sm text-muted-foreground",children:[f.jsx("pre",{className:"sr-only"})," Loading…"]}):t.status==="error"?f.jsxs("div",{className:"p-4 text-sm text-destructive",children:[f.jsx("pre",{className:"sr-only"})," ",t.message]}):i&&i.key===r?f.jsx("div",{className:"overflow-auto p-3 text-xs",dangerouslySetInnerHTML:{__html:i.html}}):f.jsxs("div",{className:"space-y-2 overflow-auto p-3",children:[t.truncated?f.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-xs text-muted-foreground",children:"Preview truncated to 1024 KB."}):null,f.jsx("pre",{className:"whitespace-pre-wrap break-words rounded-xl border border-border bg-background p-3 text-xs",children:t.content})]})}async function Jge(e){var r;const t=tve(e.contentUrl),n=navigator.share;if(typeof n=="function")try{return await n.call(navigator,{title:e.displayName,url:t}),"shared"}catch(i){if(i instanceof DOMException&&i.name==="AbortError")return"shared"}if((r=navigator.clipboard)!=null&&r.writeText)try{return await navigator.clipboard.writeText(t),"copied"}catch{return"failed"}return"failed"}function eve(e){const t=document.createElement("a");t.href=e.contentUrl,t.download=e.fileName,t.rel="noopener",document.body.appendChild(t),t.click(),t.remove()}function tve(e){return typeof window>"u"?e:new URL(e,document.baseURI||window.location.href).toString()}function ff({source:e,open:t,onOpenChange:n}){const r=v.useCallback(()=>n(!1),[n]);return f.jsx(Rs,{open:t&&e!==null,onOpenChange:n,children:f.jsx(Zi,{size:"lg",className:"inset-0 h-[100dvh] max-h-none w-full max-w-none translate-x-0 translate-y-0 rounded-none p-0 md:inset-auto md:left-1/2 md:top-1/2 md:h-auto md:max-h-[90dvh] md:w-auto md:max-w-3xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-2xl",children:e?f.jsx(nve,{source:e,onClose:r}):null})})}function nve({source:e,onClose:t}){const n=ive(e),[r,i]=v.useState(0),s=v.useRef(null),o=v.useCallback(h=>{s.current={y:h.clientY,lastY:h.clientY,lastT:Date.now()};try{h.currentTarget.setPointerCapture(h.pointerId)}catch{}},[]),l=v.useCallback(h=>{if(!s.current)return;const g=h.clientY-s.current.y;g<0||(s.current.lastY=h.clientY,s.current.lastT=Date.now(),i(g))},[]),c=v.useCallback(h=>{const g=s.current;s.current=null;try{h.currentTarget.releasePointerCapture(h.pointerId)}catch{}if(!g)return;const b=h.clientY-g.y,x=Math.max(1,Date.now()-g.lastT),_=(h.clientY-g.lastY)/x;b>120||_>.5?t():i(0)},[t]),u=v.useCallback(()=>{Jge(e)},[e]),p=v.useCallback(()=>eve(e),[e]);return f.jsxs("div",{className:"flex h-full max-h-full flex-col",style:r>0?{transform:`translateY(${r}px)`,transition:"none"}:void 0,children:[f.jsxs("div",{onPointerDown:o,onPointerMove:l,onPointerUp:c,onPointerCancel:c,className:"border-b border-border px-4 py-3 touch-none",children:[f.jsx("div",{className:"mx-auto mb-2 h-1 w-12 rounded-full bg-muted md:hidden",role:"button","aria-label":"Drag down to close"}),f.jsx(Ns,{className:"truncate text-base",children:e.displayName}),f.jsx(Xd,{className:"truncate text-xs",children:n})]}),f.jsx("div",{className:"min-h-0 flex-1 overflow-auto",role:"region","aria-label":"File preview",children:v.createElement(rve(e),{source:e})},e.id),f.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-border px-4 py-3",children:[f.jsxs(Ge,{type:"button",variant:"outline",onClick:u,children:[f.jsx(LG,{className:"mr-2 h-4 w-4"}),"Share"]}),e.origin==="offer_download"?f.jsxs(Ge,{type:"button",onClick:p,children:[f.jsx(YC,{className:"mr-2 h-4 w-4"}),"Download"]}):null]})]})}function rve(e){const t={id:e.id,displayName:e.displayName,mimeType:e.mimeType,size:e.size??0,contentUrl:e.contentUrl,relativePath:e.relativePath??""},n=uf(t);return n==="image"?ype:n==="pdf"?Lj:n==="audio"?Kge:n==="video"?Yge:n==="table"?Vge:n==="markdown"?Hge:n==="json"?qge:n==="code"?Zge:cf(t).kind==="external"?Lj:Wge}function ive(e){const t={id:e.id,displayName:e.displayName,mimeType:e.mimeType,size:e.size??0,contentUrl:e.contentUrl,relativePath:e.relativePath??""},n=uf(t),r=t0(n,e.mimeType),i=e.size?` · ${mf(e.size)}`:"";return`${r}${i}`}function um(e,t){return{id:e.id,contentUrl:e.contentUrl,displayName:e.displayName,fileName:e.displayName,relativePath:e.relativePath,mimeType:e.mimeType,size:e.size,origin:t}}function sve(e){const t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function ove({path:e,linkText:t}){const n=v.useMemo(()=>BE(e),[e]),[r,i]=v.useState({kind:"loading"}),[s,o]=v.useState(!1);v.useEffect(()=>{const A=new AbortController;return fetch(n,{method:"HEAD",signal:A.signal}).then(M=>{var j,P;if(A.signal.aborted)return;if(!M.ok){i({kind:M.status===404?"missing":"error"});return}const D=((P=(j=M.headers.get("Content-Type"))==null?void 0:j.split(";")[0])==null?void 0:P.trim())||"application/octet-stream",U=Number.parseInt(M.headers.get("Content-Length")??"0",10)||0;i({kind:"ready",mimeType:D,size:U})}).catch(()=>{A.signal.aborted||i({kind:"error"})}),()=>A.abort()},[n]);const l=sve(e),c=t||l,u=bpe(c,28),p=r.kind==="ready"?r.mimeType:"application/octet-stream",h=r.kind==="ready"?r.size:0,g={id:`local-file-${n}`,kind:"file",displayName:u,absolutePath:e,relativePath:e,contentUrl:n,mimeType:p,size:h};if(r.kind==="missing")return f.jsx("span",{className:"inline-flex align-bottom","data-testid":"local-file-link",children:f.jsx(Lo,{attachment:g,disabledReason:"File no longer available"})});const b=uf(g),x=t0(b,p),_=h>0?mf(h):null,w=r.kind==="loading",C=r.kind==="error",E=w?f.jsx("span",{className:"text-muted-foreground",children:"Fetching…"}):C?f.jsx("span",{className:"text-muted-foreground",children:"Unable to load"}):f.jsxs(f.Fragment,{children:[x,_?f.jsxs(f.Fragment,{children:[" · ",f.jsx("span",{className:"tabular-nums",children:_})]}):null]}),k=r.kind==="ready"?cf(g):null,R=k!==null&&!k.openInNewTab,N=[R?"Preview":"Download",c,x,_].filter(Boolean);return R?f.jsxs(f.Fragment,{children:[f.jsx("span",{className:"inline-flex align-bottom","data-testid":"local-file-link",children:f.jsx(Lo,{attachment:g,onClick:()=>o(!0),meta:E,ariaLabel:N.join(", ")})}),f.jsx(ff,{source:s?um(g,"local_file_link"):null,open:s,onOpenChange:o})]}):f.jsx("span",{className:"inline-flex align-bottom","data-testid":"local-file-link",children:f.jsx(Lo,{attachment:g,href:n,download:l,meta:E,ariaLabel:N.join(", ")})})}const ave={readonly:!1,localLinkMode:"open",attachmentMode:"live"},lve=v.createContext(ave);function l0(){return v.useContext(lve)}const Yb=()=>{},RB=v.createContext(Yb);function NB({children:e,onOpenLocalLink:t}){return f.jsx(RB.Provider,{value:t??Yb,children:e})}const F1={Task:db,TaskOutput:db,Bash:my,Glob:Bh,Grep:Bh,ExitPlanMode:zA,Read:b5,Edit:nW,Write:iW,Delete:dW,NotebookEdit:Hp,WebFetch:J9,TodoWrite:vV,WebSearch:Bh,KillShell:UG,AskUserQuestion:w5,Skill:OG,EnterPlanMode:zA},AB=eq;function MB(e){return F1[e]?F1[e]:AB}function LB({icon:e,className:t}){return f.jsx(e,{className:t})}function Aa({children:e,className:t}){return f.jsx("div",{className:me("flex gap-3 justify-start items-center",t),children:e})}function jB({children:e,className:t}){return f.jsx("div",{className:me("flex items-center gap-1.5 text-xs",t),children:e})}function Pl({children:e,className:t}){return f.jsx("span",{className:me("font-medium text-foreground/80",t),children:e})}function cve({children:e}){return f.jsx("span",{className:"text-muted-foreground",children:e})}function uve({children:e,className:t}){return f.jsxs(Aa,{className:me("px-0.5 text-xs tracking-wide",t),children:[f.jsx("div",{className:"w-full h-[1px] bg-border"}),f.jsx(Pl,{className:"whitespace-nowrap text-[11px] tracking-widest text-muted-foreground/60 uppercase flex-shrink-0",children:e}),f.jsx("div",{className:"w-full h-[1px] bg-border"})]})}function c0({children:e,expandedContent:t,defaultExpanded:n=!1}){const[r,i]=v.useState(n);return f.jsxs("div",{className:"flex flex-col w-full",children:[f.jsxs("button",{onClick:()=>i(!r),className:`group/expandable-row cursor-pointer grid grid-cols-[auto_1fr] items-center gap-1 text-sm ${r?"":"hover:opacity-60 transition-opacity"}`,children:[f.jsx("div",{className:"grid grid-cols-[auto_1fr] items-center gap-1.5",children:e}),f.jsx(Do,{className:`h-4.5 w-4.5 text-muted-icon translate-y-[0.5px] transition-all duration-200 opacity-0 group-hover/expandable-row:opacity-100 ${r?"rotate-90 opacity-100":""}`})]}),r&&t]})}function iD({label:e,children:t,copyText:n}){const[r,i]=v.useState(!1),s=n??Xb(t),o=v.useCallback(async()=>{await navigator.clipboard.writeText(s),i(!0),setTimeout(()=>i(!1),2e3)},[s]);return f.jsxs("div",{children:[f.jsx("span",{className:"font-medium text-muted-foreground",children:e}),f.jsxs("div",{className:"relative group/codeblock",children:[f.jsx("pre",{className:"my-1 text-xs font-mono whitespace-no-wrap break-all bg-muted border border-border rounded-lg p-2 max-h-64 overflow-auto w-full",children:t}),f.jsx(Ge,{variant:"ghost",size:"icon","aria-label":r?"Copied":"Copy code",className:me("absolute top-[4px] right-[4px] z-10 h-11 w-11 md:h-6.5 md:w-6.5 rounded-sm text-muted-foreground opacity-100 md:opacity-0 md:group-hover/codeblock:opacity-100 transition-opacity [@media(hover:none)]:!opacity-100",!r&&"hover:text-foreground",r&&"hover:!bg-transparent hover:!border-transparent"),onClick:o,children:r?f.jsx(yi,{className:"h-3.5 w-3.5 text-success"}):f.jsx(jl,{className:"h-4 w-4"})})]})]})}function DB({children:e,icon:t,className:n}){return f.jsxs("span",{className:me("inline-flex items-center gap-1 px-2 py-1 bg-muted border border-border rounded-full",n),children:[t&&f.jsx(t,{className:"h-3 w-3 text-muted-foreground"}),e]})}function u0({children:e,className:t}){return f.jsxs("div",{className:me("grid grid-cols-[auto_1fr] gap-2 min-w-0",t),children:[f.jsx("div",{className:" min-w-5 flex flex-col relative items-center justify-center",children:f.jsx("div",{className:"min-h-full w-[1px] bg-muted-foreground/20"})}),f.jsx("div",{className:"-ml-[1px] min-w-0 overflow-hidden",children:e})]})}function Xb(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e);if(Array.isArray(e))return e.map(Xb).join("");if(e&&typeof e=="object"&&"props"in e){const t=e.props;return Xb(t.children)}return""}function sD(e,t){return v.isValidElement(e)?v.cloneElement(e,{className:me(e.props.className,t)}):e}function dve({children:e,...t}){const[n,r]=v.useState(!1),i=Xb(e),s=async()=>{await navigator.clipboard.writeText(i),r(!0),setTimeout(()=>r(!1),2e3)};return f.jsxs("div",{className:"relative overflow-x-auto max-w-full min-w-0 no-code-highlight group/pre",children:[f.jsx("pre",{className:"min-w-0 rounded-xl py-2.5 px-3.5 [.no-pre-highlight_&]:bg-background",...t,children:e}),f.jsx(Ge,{variant:"ghost",size:"icon","aria-label":n?"Copied":"Copy code",className:me("absolute top-[35px] -translate-y-[50%] -translate-x-[1px] rounded-md right-1.5 h-11 w-11 md:h-8 md:w-8 text-muted-foreground opacity-100 md:opacity-0 md:group-hover/pre:opacity-100 transition-opacity [@media(hover:none)]:!opacity-100",!n&&"hover:text-foreground",n&&"hover:!bg-transparent hover:!border-transparent"),onClick:s,children:n?f.jsx(yi,{className:"h-4 w-4 text-success"}):f.jsx(jl,{className:"h-4 w-4"})})]})}const YE={h1:({children:e})=>f.jsx("h1",{className:"text-[20px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h2:({children:e})=>f.jsx("h2",{className:"text-[18px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h3:({children:e})=>f.jsx("h3",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h4:({children:e})=>f.jsx("h4",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h5:({children:e})=>f.jsx("h5",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h6:({children:e})=>f.jsx("h6",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),pre:dve,code:({children:e,className:t,...n})=>t?f.jsx("code",{className:"block text-xs whitespace-pre",...n,children:e}):f.jsx("code",{className:"break-all px-1 bg-border/60 dark:[.no-pre-highlight_&]:bg-background dark:[.text-pretty_&]:bg-neutral [.no-code-highlight_&]:!bg-transparent py-0.5 rounded text-sm whitespace-wrap",...n,children:e}),table:({children:e,...t})=>f.jsx("div",{className:"border border-border rounded-xl overflow-x-auto",children:f.jsx("table",{className:"table-auto min-w-full divide-y divide-border bg-background",...t,children:e})}),tbody:({children:e,...t})=>f.jsx("tbody",{className:"divide-y divide-border",...t,children:e}),th:({children:e,...t})=>f.jsx("th",{className:"text-left text-xs uppercase text-muted-foreground tracking-wider p-2 pl-0 first:pl-3 bg-muted dark:bg-card [&_*]:font-semibold",...t,children:e}),td:({children:e,...t})=>f.jsx("td",{className:"text-left p-2 pl-0 first:pl-3 [&_*]:font-normal ",...t,children:e}),p:({children:e,...t})=>f.jsx("p",{className:"break-words mt-5 mb-3 first:mt-0 last:mb-0",...t,children:e}),blockquote:({children:e,...t})=>(()=>{const n=v.Children.toArray(e),r=n[0];r!==void 0&&(n[0]=sD(r,"mt-0"));const i=n.length-1,s=n[i];return s!==void 0&&(n[i]=sD(s,"mb-0")),f.jsx("blockquote",{className:"my-2 mt-5 mb-3 first:mt-0 last:mb-0 border-l-2 border-border/80 pl-2 text-muted-foreground",...t,children:n})})(),a:({children:e,...t})=>f.jsx("a",{className:"transition-all underline decoration-2 text-logo decoration-logo/50 hover:text-logo/70 dark:text-logo dark:decoration-logo/70 dark:hover:text-logo/60 dark:hover:decoration-logo/40 ",target:"_blank",rel:"noopener noreferrer",...t,children:e}),img:({src:e,...t})=>{const n=typeof e=="string"&&vpe(e)?BE(e):e;return f.jsx("img",{src:n,...t})}};function fve({children:e,href:t,onClick:n,overrideOpenLocalLink:r,...i}){const s=v.useContext(RB),o=r??s,l=l0(),c=mpe(t);if(c&&l.localLinkMode==="text")return f.jsx("span",{className:"transition-all underline decoration-2 text-logo decoration-logo/50",children:e});if(c&&!dB(c.path)){const u=$1(e).trim();return f.jsx(ove,{path:c.path,linkText:u||void 0})}return f.jsx("a",{className:"transition-all underline decoration-2 text-logo decoration-logo/50 hover:text-logo/70 dark:text-logo dark:decoration-logo/70 dark:hover:text-logo/60 dark:hover:decoration-logo/40 ",href:t,target:c?void 0:"_blank",rel:c?void 0:"noopener noreferrer",onClick:u=>{n==null||n(u),!(u.defaultPrevented||!c||o===Yb)&&(u.preventDefault(),o({...c,clientX:u.clientX,clientY:u.clientY,trigger:"click"}))},onContextMenu:u=>{!c||o===Yb||(u.preventDefault(),o({...c,clientX:u.clientX,clientY:u.clientY,trigger:"contextmenu"}))},...i,children:e})}function hve(e){return{...YE,a:t=>f.jsx(fve,{...t,overrideOpenLocalLink:e==null?void 0:e.onOpenLocalLink})}}const hf=[uB],pf=hve();function $1(e){return e==null||typeof e=="boolean"?"":typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map($1).join(""):v.isValidElement(e)?$1(e.props.children):""}({...YE});function XE({attachment:e,previewUrl:t,onClick:n,onRemove:r,className:i,size:s="transcript",uploadProgress:o,onCancelUpload:l}){const c=e.contentUrl||t,u=s==="composer",p=o!==void 0;return f.jsxs("div",{className:me("group relative flex flex-row items-end",i),children:[f.jsxs("button",{type:"button",onClick:n,className:me("group/image relative overflow-hidden rounded-xl border border-border/80 bg-background shadow-sm",u?"min-w-[80px]":"min-w-[200px]"),children:[c?f.jsx("img",{src:c,alt:e.displayName,className:me("rounded-xl object-contain bg-muted",u?"min-h-[50px] min-w-[80px] max-h-[120px] max-w-[200px]":"min-h-[100px] min-w-[200px] max-h-[300px] max-w-[300px]")}):f.jsx("div",{className:me("flex items-center justify-center rounded-xl bg-muted text-muted-foreground",u?"min-h-[64px] min-w-[80px]":"min-h-[160px] min-w-[200px]"),children:f.jsx(v5,{className:me(u?"size-6":"size-8")})}),f.jsxs("div",{className:me("pointer-events-none absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/75 via-black/30 to-transparent text-left opacity-0 transition-opacity duration-200 group-hover/image:opacity-100",u?"px-2.5 pb-2 pt-6":"px-4 pb-3 pt-10"),children:[f.jsx("div",{className:me("truncate font-medium text-white",u?"text-xs":"text-sm"),children:e.displayName}),f.jsxs("div",{className:"truncate text-xs text-white/80",children:[e.mimeType," · ",mf(e.size)]})]})]}),p?f.jsx(R8,{progress:o??null,onCancel:l,size:u?"sm":"md",cancelLabel:`Cancel upload of ${e.displayName}`}):null,r&&!p?f.jsx(IB,{displayName:e.displayName,onRemove:r}):null]})}function Lo({attachment:e,onClick:t,onRemove:n,className:r,uploadProgress:i,onCancelUpload:s,href:o,download:l,meta:c,ariaLabel:u,disabledReason:p}){const h=e.kind==="mention"?"text":uf(e),g=gve(h),b=e.kind==="mention",x=b?pve(e.displayName):e.displayName,_=b?mve(e.displayName):"",w=i!==void 0,C=!!p,E=me("flex w-[200px] items-center gap-2 rounded-xl border border-border bg-background p-1 pr-3 text-left transition-colors",C?"cursor-not-allowed opacity-60":"hover:bg-accent/50"),k=b?f.jsx("div",{className:"max-w-[150px] truncate text-[11px] text-muted-foreground",children:_?`@${_}`:"@mention"}):p?f.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:p}):c!==void 0?f.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:c}):f.jsxs("div",{className:"truncate text-[11px] text-muted-foreground",children:[e.mimeType," · ",mf(e.size)]}),R=f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"flex min-h-10 min-w-10 items-center justify-center rounded-lg border border-border bg-muted text-muted-foreground",children:f.jsx(LB,{icon:g,className:"size-5"})}),f.jsxs("div",{className:"min-w-0",children:[f.jsx("div",{className:me("max-w-[150px] truncate text-[13px] font-medium",C?"text-muted-foreground line-through":"text-foreground"),children:x}),k]})]});return f.jsxs("div",{className:me("group relative",r),children:[o&&!C?f.jsx("a",{href:o,download:l,rel:"noopener","aria-label":u,className:E,children:R}):f.jsx("button",{type:"button",onClick:C?void 0:t,title:b?e.displayName:void 0,"aria-label":u,"aria-disabled":C||void 0,disabled:C,className:E,children:R}),w?f.jsx(R8,{progress:i??null,onCancel:s,size:"sm",cancelLabel:`Cancel upload of ${e.displayName}`}):null,n&&!w?f.jsx(IB,{displayName:e.displayName,onRemove:n}):null]})}function pve(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function mve(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(0,n):""}function IB({displayName:e,onRemove:t}){return f.jsx("button",{type:"button",className:"absolute right-2 top-2 rounded-full bg-background/90 p-1 text-muted-foreground shadow-sm transition hover:bg-muted hover:text-foreground",onClick:n=>{n.preventDefault(),n.stopPropagation(),t()},"aria-label":`Remove ${e}`,children:f.jsx(io,{className:"h-3.5 w-3.5"})})}function gve(e){switch(e){case"image":return v5;case"pdf":return mG;case"markdown":return SG;case"json":return YV;case"table":return oW;case"code":return QV;case"text":return QC;case"archive":return qV;case"audio":return JV;case"video":return cW;default:return b5}}function mf(e){return e<1024?`${e} B`:e<1024*1024?`${Math.max(1,Math.round(e/1024))} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}const d0=v.forwardRef(({className:e,...t},n)=>f.jsx("textarea",{"data-gramm":"false","data-gramm_editor":"false","data-enable-grammarly":"false","data-1p-ignore":!0,autoComplete:"off",className:me("flex w-full rounded-lg border border-border bg-background px-2.5 py-2 text-sm placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));d0.displayName="Textarea";const hv={};function oD(e){return!e.isCollapsed&&!e.hasPreviewAttachment&&e.patch===void 0&&e.patchError===void 0&&!e.isPatchLoading}function vve(e,t){return!e||!t.mimeType||typeof t.size!="number"||t.changeType==="deleted"||!t.mimeType.startsWith("image/")&&t.mimeType!=="application/pdf"?null:{id:`diff:${t.path}`,kind:t.mimeType.startsWith("image/")?"image":"file",displayName:t.path.split("/").pop()??t.path,absolutePath:t.path,relativePath:t.path,contentUrl:`/api/projects/${e}/files/${encodeURIComponent(t.path)}/content`,mimeType:t.mimeType,size:t.size}}function PB(e){return e.isUntracked}function bve(e){return PB(e)?e.path.includes("/"):!1}function Vw(e){return f.jsxs(Yr,{delayDuration:0,children:[f.jsx(Xr,{asChild:!0,children:f.jsx("button",{type:"button","aria-label":e.label,title:e.label,onClick:e.onClick,className:me("flex h-11 w-11 md:h-7 md:w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",e.active&&"bg-accent text-foreground"),children:e.children})}),f.jsx(Br,{children:e.label})]})}function OB({checked:e,mixed:t=!1,label:n,className:r,onClick:i}){return f.jsx("button",{type:"button","aria-label":n??(e?"Exclude file from commit":"Include file in commit"),"aria-checked":t?"mixed":e,"aria-pressed":t?"mixed":e,onClick:s=>{s.stopPropagation(),i()},className:me("flex size-4.5 shrink-0 items-center justify-center rounded border transition-colors",e||t?"border-foreground bg-foreground text-background":"border-border bg-background text-transparent",r),children:t?f.jsx(YW,{className:"h-3 w-3",strokeWidth:3}):e?f.jsx(yi,{className:"h-3 w-3",strokeWidth:3}):null})}function QE(e){const t=Date.parse(e);if(!Number.isFinite(t))return"";const n=Date.now()-t,r=6e4,i=60*r,s=24*i,o=7*s,l=30*s,c=365*s;return n<r?"just now":n<i?`${Math.round(n/r)}m ago`:n<s?`${Math.round(n/i)}hr ago`:n<o?`${Math.round(n/s)}d ago`:n<l?`${Math.round(n/o)}wk ago`:n<c?`${Math.round(n/l)}mo ago`:`${Math.round(n/c)}yr ago`}function yve(e){return e?`Last fetched ${QE(e)}`:"No local fetch recorded"}function xve({entry:e,isPendingPush:t=!1}){const n=QE(e.authoredAt),r=!!e.githubUrl;return f.jsxs("button",{type:"button",disabled:!r,onClick:()=>{!e.githubUrl||typeof window>"u"||window.open(e.githubUrl,"_blank","noopener,noreferrer")},className:me("flex w-full items-start gap-3 rounded-lg border border-border bg-background pl-3 pr-2 py-2 text-left transition-colors",r?"hover:bg-accent":"cursor-default opacity-60"),children:[f.jsxs("div",{className:"min-w-0 flex-1",children:[f.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:e.summary}),e.description?f.jsx("div",{className:"mt-1 line-clamp-2 whitespace-pre-wrap text-xs text-muted-foreground",children:e.description}):null,f.jsxs("div",{className:"mt-1 flex min-w-0 items-center gap-1 text-xs text-muted-foreground",children:[e.authorName?f.jsx("span",{className:"truncate",children:e.authorName}):null,e.authorName&&n?f.jsx("span",{"aria-hidden":"true",children:"•"}):null,n?f.jsx("span",{children:n}):null]})]}),e.tags.length>0?f.jsxs("div",{className:"flex shrink-0 flex-wrap justify-end gap-1",children:[e.tags.map(i=>f.jsx("span",{className:"inline-flex items-center rounded-full bg-muted border border-border px-2 py-0.5 text-[11px]",children:i},i)),t?f.jsx("span",{className:"inline-flex items-center rounded-full bg-muted border border-border px-2 py-0.5 text-[11px]",children:f.jsx(rp,{className:"size-3"})}):null]}):t?f.jsx("div",{className:"flex shrink-0 flex-wrap justify-end gap-1",children:f.jsx("span",{className:"inline-flex items-center rounded-full bg-muted border border-border px-2 py-0.5 text-[11px]",children:f.jsx(rp,{className:"size-3"})})}):null]})}function aD(e){switch(e.kind){case"local":return 0;case"pull_request":return 1;case"remote":default:return 2}}function _ve(e){const t=new Map;for(const n of e){const r=t.get(n.name);(!r||aD(n)<aD(r))&&t.set(n.name,n)}return t}function wve(e,t){const n=_ve([...e.local,...e.pullRequests,...e.remote]);t&&n.delete(t);const r=new Set,i=e.defaultBranchName?n.get(e.defaultBranchName):void 0;i&&r.add(i.name);const s=e.recent.map(l=>n.get(l.name)??l).filter(l=>!!l&&!r.has(l.name));for(const l of s)r.add(l.name);const o=[...n.values()].filter(l=>!r.has(l.name)).sort((l,c)=>l.displayName.localeCompare(c.displayName));return{defaultBranch:i,recent:s,other:o}}function Sve({open:e,onOpenChange:t,onGetGitHubPublishInfo:n,onCheckGitHubRepoAvailability:r,onPublish:i}){const[s,o]=v.useState(null),[l,c]=v.useState(!1),[u,p]=v.useState(""),[h,g]=v.useState(""),[b,x]=v.useState("private"),[_,w]=v.useState(""),[C,E]=v.useState(null),[k,R]=v.useState(!1),[N,A]=v.useState(!1);v.useEffect(()=>{if(!e)return;let U=!1;return c(!0),E(null),n().then(j=>{U||(o(j),p(j.owners[0]??j.activeAccountLogin??""),g(j.suggestedRepoName),x("private"),w(""))}).finally(()=>{U||c(!1)}),()=>{U=!0}},[n,e]),v.useEffect(()=>{if(!e||!(s!=null&&s.ghInstalled)||!s.authenticated)return;const U=u.trim(),j=h.trim();if(!U||!j){E(null);return}let P=!1;R(!0);const z=window.setTimeout(()=>{r({owner:U,name:j}).then(O=>{P||E(O)}).finally(()=>{P||R(!1)})},250);return()=>{P=!0,window.clearTimeout(z)}},[s==null?void 0:s.authenticated,s==null?void 0:s.ghInstalled,h,r,e,u]);async function M(){if(!(!u.trim()||!h.trim())){A(!0);try{const U=await i({owner:u.trim(),name:h.trim(),visibility:b,description:_});U!=null&&U.ok&&t(!1)}finally{A(!1)}}}const D=!!(s!=null&&s.ghInstalled&&s.authenticated&&u.trim()&&h.trim()&&(C!=null&&C.available)&&!k&&!N);return f.jsx(Rs,{open:e,onOpenChange:t,children:f.jsxs(Zi,{size:"sm",className:"max-w-[min(92vw,475px)]",children:[f.jsxs(Io,{className:"space-y-2 px-4 pb-4 pt-4",children:[f.jsxs("div",{className:"space-y-1",children:[f.jsx(Ns,{children:"Push to GitHub"}),f.jsx(Xd,{children:"Create a GitHub repository from this local project using GitHub CLI."})]}),l?f.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[f.jsx(Cn,{className:"size-4 animate-spin"}),f.jsx("span",{children:"Checking GitHub CLI…"})]}):s&&!s.ghInstalled?f.jsxs("div",{className:"space-y-2 text-sm text-muted-foreground",children:[f.jsx("p",{children:"GitHub CLI is not installed."}),f.jsx("div",{className:"rounded-lg border border-border px-3 py-2 font-mono text-xs text-foreground",children:"brew install gh"}),f.jsx("p",{children:"Then run:"}),f.jsx("div",{className:"rounded-lg border border-border px-3 py-2 font-mono text-xs text-foreground",children:"gh auth login"})]}):s&&!s.authenticated?f.jsxs("div",{className:"space-y-2 text-sm text-muted-foreground",children:[f.jsx("p",{children:"GitHub CLI is installed but not signed in."}),f.jsx("div",{className:"rounded-lg border border-border px-3 py-2 font-mono text-xs text-foreground",children:"gh auth login"})]}):f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"space-y-2",children:f.jsxs(Sl,{value:u,onValueChange:p,children:[f.jsx(fa,{className:"pl-[11px] [&>span]:flex [&>span]:items-center [&>span]:gap-2",children:f.jsx(Sc,{placeholder:"Select owner"})}),f.jsx(ha,{children:((s==null?void 0:s.owners)??[]).map(U=>f.jsx(Ws,{value:U,children:f.jsxs("span",{className:"flex items-center gap-2",children:[U===(s==null?void 0:s.activeAccountLogin)?f.jsx(gy,{className:"size-4 text-muted-foreground"}):f.jsx(hV,{className:"size-4 text-muted-foreground"}),f.jsx("span",{className:"pl-[1px]",children:U})]})},U))})]})}),f.jsx("div",{className:"space-y-2",children:f.jsxs("div",{className:"relative",children:[f.jsx(Kn,{value:h,onChange:U=>g(U.target.value),placeholder:"my-repo",className:"pl-9 pr-10"}),f.jsx(aG,{className:"pointer-events-none absolute inset-y-0 left-3 my-auto size-4 text-muted-foreground"}),k?f.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-3 flex items-center text-muted-foreground",children:f.jsx(Cn,{className:"size-4 animate-spin"})}):C?f.jsx("div",{className:"absolute inset-y-0 right-2 flex items-center",children:f.jsxs(Yr,{delayDuration:0,children:[f.jsx(Xr,{asChild:!0,children:f.jsx("button",{type:"button",tabIndex:-1,"aria-label":C.message,className:me("flex size-6 items-center justify-center rounded-md",C.available?"text-success":"text-destructive"),children:C.available?f.jsx(yi,{className:"size-4"}):f.jsx(fb,{className:"size-4"})})}),f.jsx(Br,{children:C.message})]})}):null]})}),f.jsx("div",{className:"space-y-2",children:f.jsxs("div",{className:"relative",children:[f.jsx(QC,{className:"pointer-events-none absolute left-3 top-3 size-4 text-muted-foreground"}),f.jsx(d0,{value:_,onChange:U=>w(U.target.value),rows:3,placeholder:"Optional description",className:"pl-9 outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"})]})}),f.jsx("div",{className:"space-y-2",children:f.jsxs(Sl,{value:b,onValueChange:U=>x(U),children:[f.jsx(fa,{className:"pl-[11px] [&>span]:flex [&>span]:items-center [&>span]:gap-2",children:f.jsx(Sc,{placeholder:"Select visibility"})}),f.jsxs(ha,{children:[f.jsx(Ws,{value:"private",children:f.jsxs("span",{className:"flex items-center gap-2",children:[f.jsx(FW,{className:"size-4 text-muted-foreground"}),f.jsx("span",{className:"pl-[1px]",children:"Private"})]})}),f.jsx(Ws,{value:"public",children:f.jsxs("span",{className:"flex items-center gap-2",children:[f.jsx(TW,{className:"size-4 text-muted-foreground"}),f.jsx("span",{className:"pl-[1px]",children:"Public"})]})})]})]})})]})]}),f.jsxs(_a,{children:[f.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>t(!1),children:"Cancel"}),f.jsx(Ge,{size:"sm",disabled:!D,onClick:()=>void M(),children:N?f.jsxs(f.Fragment,{children:[f.jsx(Cn,{className:"mr-1.5 size-3.5 animate-spin"}),"Publishing…"]}):"Push to GitHub"})]})]})})}function zB({value:e,onChange:t,placeholder:n,disabled:r,trailingAction:i}){return f.jsxs("div",{className:"relative",children:[f.jsx(Bh,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),f.jsx(Kn,{value:e,onChange:s=>t(s.target.value),placeholder:n,className:me("h-9 pl-7 text-sm",i?"pr-14":void 0),disabled:r}),i?f.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2",children:i}):null]})}function Nc({title:e,entries:t,emptyLabel:n,selectedName:r,disabled:i,stickyTitle:s=!1,onSelect:o}){return t.length===0&&!n?null:f.jsxs("div",{className:"space-y-1",children:[f.jsx("div",{className:me("px-1 py-1 text-[11px] font-medium uppercase tracking-[0.08em] text-muted-foreground",s&&"sticky top-0 z-10 bg-background"),children:e}),t.length===0?f.jsx("div",{className:"px-1 py-1 text-xs text-muted-foreground",children:n}):t.map(l=>{const c=r===l.name;return f.jsxs("button",{type:"button",disabled:i,onClick:()=>o(l),className:me("flex w-full items-start gap-2 rounded-lg px-2 py-2 text-left transition-colors disabled:opacity-60",c?"bg-accent text-foreground":"hover:bg-accent"),children:[l.kind==="pull_request"?f.jsx(_5,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}):f.jsx(kc,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),f.jsxs("div",{className:"min-w-0 flex-1",children:[f.jsxs("div",{className:"flex w-full items-center gap-3",children:[f.jsx("div",{className:"min-w-0 flex-1 overflow-hidden whitespace-nowrap text-sm text-foreground",children:l.displayName}),l.updatedAt?f.jsx("div",{className:"ml-auto shrink-0 text-right text-[11px] text-muted-foreground",children:QE(l.updatedAt)}):null]}),l.kind==="pull_request"&&l.description||l.headLabel?f.jsx("div",{className:"truncate text-xs text-muted-foreground",children:l.kind==="pull_request"?l.description??l.headLabel??l.name:l.headLabel??void 0}):null]})]},l.id)})]})}function Cve({open:e,onOpenChange:t,branchList:n,currentBranchName:r,onPreviewMergeBranch:i,onMergeBranch:s}){const[o,l]=v.useState(""),[c,u]=v.useState(null),[p,h]=v.useState(null),[g,b]=v.useState(null),[x,_]=v.useState(!1),[w,C]=v.useState(!1),E=v.useMemo(()=>n?wve(n,r):{defaultBranch:void 0,recent:[],other:[]},[n,r]),k=o.trim().toLowerCase(),R=v.useCallback(P=>k?[P.displayName,P.name,P.description,P.prTitle,P.headLabel].some(z=>z==null?void 0:z.toLowerCase().includes(k)):!0,[k]),N=E.defaultBranch&&R(E.defaultBranch)?E.defaultBranch:void 0,A=E.recent.filter(R),M=E.other.filter(R),D=v.useMemo(()=>c?[E.defaultBranch,...E.recent,...E.other].find(P=>P!==void 0&&P.name===c)??null:null,[E.defaultBranch,E.other,E.recent,c]);v.useEffect(()=>{e||(l(""),u(null),h(null),b(null),_(!1),C(!1))},[e]),v.useEffect(()=>{if(!e||!D){h(null),b(null),_(!1);return}let P=!1;return h(null),b(null),_(!0),i(D).then(z=>{P||h(z)}).catch(z=>{P||b(z instanceof Error?z.message:String(z))}).finally(()=>{P||_(!1)}),()=>{P=!0}},[i,e,D]);const U=!D||!p||x||w||p.status!=="mergeable";async function j(){if(!(!D||U)){C(!0);try{const P=await s(D);P!=null&&P.ok&&t(!1)}finally{C(!1)}}}return f.jsx(Rs,{open:e,onOpenChange:t,children:f.jsxs(Zi,{size:"sm",className:"max-w-[min(92vw,475px)]",children:[f.jsxs(Io,{className:"flex min-h-0 flex-col gap-3 px-4 pb-4 pt-4",children:[f.jsxs("div",{className:"space-y-1",children:[f.jsxs(Ns,{children:["Merge into ",r??"current branch"]}),f.jsx(Xd,{children:"Choose a branch to continue."})]}),f.jsx(zB,{value:o,onChange:l,placeholder:"Search branches"}),f.jsxs("div",{className:"max-h-[375px] space-y-3 overflow-y-auto pr-1",children:[f.jsx(Nc,{title:"Default Branch",entries:N?[N]:[],emptyLabel:"No default branch available.",selectedName:c,onSelect:P=>u(P.name)}),f.jsx(Nc,{title:"Recent Branches",entries:A,emptyLabel:"No recent branches.",selectedName:c,onSelect:P=>u(P.name)}),f.jsx(Nc,{title:"Other Branches",entries:M,emptyLabel:"No other branches match this search.",selectedName:c,onSelect:P=>u(P.name)})]}),f.jsx("div",{className:"px-2",children:D?x?f.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[f.jsx(Cn,{className:"size-3.5 animate-spin"}),f.jsx("span",{children:"Checking merge preview…"})]}):g?f.jsx("div",{className:"text-sm text-destructive",children:g}):p?f.jsxs("div",{className:"flex items-start gap-2",children:[p.status==="up_to_date"?f.jsx(yi,{className:"mt-1 size-3.5 shrink-0 text-success"}):p.status==="conflicts"?f.jsx(fb,{className:"mt-1 size-3.5 shrink-0 text-warning"}):p.status==="mergeable"?f.jsx(x5,{className:"mt-1 size-3.5 shrink-0 text-muted-foreground"}):f.jsx(fb,{className:"mt-1 size-3.5 shrink-0 text-destructive"}),f.jsxs("div",{className:"min-w-0 space-y-1",children:[f.jsx("div",{className:"text-sm font-medium text-foreground",children:p.message}),p.detail?f.jsx("div",{className:"line-clamp-2 whitespace-pre-wrap text-xs text-muted-foreground",children:p.detail}):null]})]}):f.jsx("div",{className:"text-sm text-muted-foreground",children:"Preview unavailable."}):f.jsx("div",{className:"text-sm text-muted-foreground",children:"Select a branch to preview the merge."})})]}),f.jsx(_a,{children:f.jsxs("div",{className:"flex min-w-0 w-full items-center justify-end gap-2",children:[f.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>t(!1),children:"Cancel"}),f.jsx(Ge,{className:"max-w-full min-w-0",size:"sm",disabled:U,onClick:()=>void j(),children:w?f.jsxs(f.Fragment,{children:[f.jsx(Cn,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),"Merging…"]}):f.jsx("span",{className:"block max-w-full truncate",children:"Merge"})})]})})]})})}function kve({currentBranchName:e,onListBranches:t,onPreviewMergeBranch:n,onMergeBranch:r,onCheckoutBranch:i,onCreateBranch:s}){const[o,l]=v.useState(!1),[c,u]=v.useState(!1),[p,h]=v.useState(!1),[g,b]=v.useState(!1),[x,_]=v.useState(""),[w,C]=v.useState("branches"),[E,k]=v.useState(null),[R,N]=v.useState(null);v.useEffect(()=>{o&&(h(!0),N(null),t().then(W=>k(W)).catch(W=>{N(W instanceof Error?W.message:String(W))}).finally(()=>{h(!1)}))},[t,o]);const A=x.trim().toLowerCase(),M=W=>W.filter(X=>A?[X.displayName,X.name,X.description,X.prTitle,X.headLabel].some(I=>I==null?void 0:I.toLowerCase().includes(A)):!0),D=(E==null?void 0:E.currentBranchName)??e,U=new Set(((E==null?void 0:E.pullRequests)??[]).map(W=>W.headRefName??W.name)),j=M((E==null?void 0:E.recent)??[]).filter(W=>W.name!==D),P=M((E==null?void 0:E.local)??[]).filter(W=>W.name!==D),z=M((E==null?void 0:E.remote)??[]).filter(W=>W.name!==D&&!U.has(W.name)),O=M((E==null?void 0:E.pullRequests)??[]).filter(W=>W.name!==D),$=(E==null?void 0:E.pullRequests.length)??0;async function V(W){b(!0);try{await i(W),l(!1),_(""),C("branches")}finally{b(!1)}}async function B(){b(!0);try{await s(),l(!1),_(""),C("branches")}finally{b(!1)}}function F(){l(!1),u(!0)}return f.jsxs(Bk,{open:o,onOpenChange:l,children:[f.jsx(Fk,{asChild:!0,children:f.jsxs("button",{type:"button",className:"flex min-w-0 max-w-full items-center gap-1 rounded-md px-1.5 py-1 text-sm transition-colors hover:bg-accent hover:text-foreground","aria-label":"Open branch switcher",children:[f.jsx(kc,{className:"h-3.5 w-3.5 shrink-0"}),f.jsx("span",{className:"truncate",children:e??"Detached HEAD"}),f.jsx(Gd,{className:"h-3.5 w-3.5 shrink-0"})]})}),f.jsx(Py,{align:"start",className:"w-[320px] p-2",children:f.jsxs("div",{className:"space-y-2",children:[f.jsx(zB,{value:x,onChange:_,placeholder:w==="pull_requests"?"Search pull requests":"Search branches",disabled:p||g,trailingAction:f.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>void B(),disabled:p||g,className:"h-7 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:"+ New"})}),f.jsx(da,{value:w,onValueChange:W=>C(W),size:"sm",className:"w-full",optionClassName:"flex-1 justify-center",options:[{value:"branches",label:"Branches"},{value:"pull_requests",label:`Open PRs ${$}`}]}),f.jsx("div",{className:"max-h-[420px] overflow-y-auto pr-1.5 -mr-[8px]",children:p?f.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 text-sm text-muted-foreground",children:[f.jsx(Cn,{className:"h-4 w-4 animate-spin"}),f.jsx("span",{children:"Loading branches…"})]}):R?f.jsx("div",{className:"rounded-lg border border-border px-3 py-2 text-sm text-muted-foreground",children:R}):w==="pull_requests"?f.jsx(Nc,{title:"Open PRs",entries:O,emptyLabel:(E==null?void 0:E.pullRequestsStatus)==="error"?E.pullRequestsError??"Could not load pull requests.":(E==null?void 0:E.pullRequestsStatus)==="unavailable"?"Pull requests unavailable for this repository.":"No open pull requests.",disabled:g,stickyTitle:!0,onSelect:W=>{V(W)}}):f.jsxs("div",{className:"space-y-3",children:[f.jsx(Nc,{title:"Recent",entries:j,emptyLabel:"No recent branches.",disabled:g,stickyTitle:!0,onSelect:W=>{V(W)}}),f.jsx(Nc,{title:"Local",entries:P,emptyLabel:"No local branches.",disabled:g,stickyTitle:!0,onSelect:W=>{V(W)}}),f.jsx(Nc,{title:"Remote",entries:z,emptyLabel:"No remote branches.",disabled:g,stickyTitle:!0,onSelect:W=>{V(W)}})]})}),D?f.jsx(Ge,{variant:"default",size:"sm",disabled:p||g||!!R,onClick:F,className:"h-9 w-full justify-center rounded-lg px-3 text-sm",children:f.jsxs("span",{className:"block max-w-full truncate",children:[f.jsx(wW,{className:"mr-1.5 inline h-3.5 w-3.5 shrink-0"}),"Merge branch into ",D,"..."]})}):null]})}),f.jsx(Cve,{open:c,onOpenChange:u,branchList:E,currentBranchName:D,onPreviewMergeBranch:n,onMergeBranch:r})]})}function Eve({file:e,rootRef:t,projectId:n,isCollapsed:r,isChecked:i,editorLabel:s,diffRenderMode:o,wrapLines:l,onToggleCollapsed:c,onToggleChecked:u,fileActions:p,patch:h,patchError:g,isPatchLoading:b,onLoadPatch:x}){const _=PB(e),w=bve(e),[C,E]=v.useState(null),k=v.useRef(null),R=v.useRef(null),{sentinelRef:N,isStuck:A}=due({rootRef:t,disabled:r}),M=v.useMemo(()=>vve(n,e),[e,n]),D=M!==null,U=oD({isCollapsed:r,hasPreviewAttachment:D,patch:h,patchError:g,isPatchLoading:b});v.useEffect(()=>{if(!U)return;const O=`${e.path}\0${e.patchDigest}`;R.current!==O&&(R.current=O,x(e.path).catch(()=>{}))},[e.patchDigest,e.path,x,U]);function j(O){if(cf(O).openInNewTab){typeof window<"u"&&window.open(new URL(O.contentUrl,window.location.origin).toString(),"_blank","noopener,noreferrer");return}E(O.id)}function P(O){var V;O.preventDefault(),O.stopPropagation();const $=O.currentTarget.getBoundingClientRect();(V=k.current)==null||V.dispatchEvent(new MouseEvent("contextmenu",{bubbles:!0,cancelable:!0,clientX:$.left+$.width/2,clientY:$.bottom,view:window}))}function z(){if(!r){c();return}if(D||h!==void 0){c();return}if(b)return;if(!(g!==void 0||oD({isCollapsed:!1,hasPreviewAttachment:D,patch:h,patchError:g,isPatchLoading:b}))){c();return}x(e.path).then(()=>{c()}).catch(()=>{})}return f.jsxs(Zc,{children:[f.jsx(Jc,{asChild:!0,children:f.jsxs("div",{ref:k,className:"relative rounded-lg border border-border bg-background",children:[r?null:f.jsx("div",{ref:N,className:"pointer-events-none absolute inset-x-0 top-0 h-px","aria-hidden":"true"}),f.jsxs("div",{role:"button",tabIndex:0,onClick:z,onKeyDown:O=>{O.key!=="Enter"&&O.key!==" "||(O.preventDefault(),z())},className:me("group/header sticky top-0 z-20 flex cursor-pointer items-center justify-between gap-3 bg-background pl-[7px] pr-2.5 py-1.5 text-[13px] text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",!r&&!A&&"rounded-t-[calc(theme(borderRadius.lg)-1px)]",r&&"rounded-[calc(theme(borderRadius.lg)-1px)]",!r&&"border-b border-border/50"),children:[f.jsxs("div",{className:"flex min-w-0 items-center",children:[f.jsx(OB,{checked:i,onClick:u}),f.jsx("div",{className:"min-w-0 truncate select-none ml-2 mr-1",children:e.path})]}),f.jsxs("div",{className:"flex shrink-0 items-center gap-2 select-none",children:[f.jsxs("span",{className:"whitespace-nowrap text-xs font-mono",children:[e.additions>0?f.jsxs("span",{className:"text-success",children:["+",e.additions]}):null,e.deletions>0?f.jsxs("span",{className:e.additions>0?"ml-2 text-destructive":"text-destructive",children:["-",e.deletions]}):null]}),f.jsx("button",{type:"button","aria-label":`Open actions for ${e.path}`,onClick:P,className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:f.jsx(ip,{className:"h-3.5 w-3.5 shrink-0"})}),b&&r&&!M?f.jsx(Cn,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):r?f.jsx(Gd,{className:"h-3.5 w-3.5 shrink-0"}):f.jsx(g5,{className:"h-3.5 w-3.5 shrink-0"})]})]}),r?null:f.jsx("div",{className:"kanna-diff-patch overflow-hidden rounded-b-[calc(theme(borderRadius.lg)-1px)] pb-[1px]",children:M?f.jsx("div",{className:"flex justify-center p-3",children:M.kind==="image"?f.jsx(XE,{attachment:M,onClick:()=>j(M)}):f.jsx(Lo,{attachment:M,onClick:()=>j(M)})}):b?f.jsxs("div",{className:"flex items-center justify-center px-3 py-8 text-sm text-muted-foreground",children:[f.jsx(Cn,{className:"mr-2 h-4 w-4 animate-spin"}),"Loading diff..."]}):g?f.jsx("div",{className:"px-3 py-4 text-sm text-destructive",children:g}):h!==void 0?f.jsx(cue,{patch:h,options:{diffStyle:o,disableFileHeader:!0,disableBackground:!1,overflow:l?"wrap":"scroll",lineDiffType:"word",diffIndicators:"classic"}}):f.jsx("div",{className:"px-3 py-4 text-sm text-muted-foreground",children:"Diff unavailable."})}),f.jsx(ff,{source:M&&C===M.id?um(M,"user_attachment"):null,open:M!==null&&C===M.id,onOpenChange:O=>!O&&E(null)})]},e.path)}),f.jsxs(Fl,{children:[f.jsxs(Mn,{onSelect:O=>{O.stopPropagation(),p.onOpenFile(e.path)},children:[f.jsx(KC,{className:"h-3.5 w-3.5"}),f.jsxs("span",{className:"text-xs font-medium",children:["Open in ",s]})]}),f.jsxs(Mn,{onSelect:O=>{O.stopPropagation(),p.onOpenInFinder(e.path)},children:[f.jsx(py,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Open in Finder"})]}),f.jsxs(Mn,{onSelect:O=>{O.stopPropagation(),p.onDiscardFile(e.path)},className:"text-destructive hover:bg-destructive/10 focus:bg-destructive/10",children:[f.jsx(qd,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Discard Changes"})]}),f.jsxs(Mn,{disabled:!_,onSelect:O=>{O.stopPropagation(),_&&p.onIgnoreFile(e.path)},children:[f.jsx(LA,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Ignore File"})]}),f.jsxs(Mn,{disabled:!w,onSelect:O=>{O.stopPropagation(),w&&p.onIgnoreFolder(e.path)},children:[f.jsx(LA,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Ignore folder..."})]}),f.jsx(e4,{}),f.jsxs(Mn,{onSelect:O=>{O.stopPropagation(),p.onCopyFilePath(e.path)},children:[f.jsx(jl,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Copy File Path"})]}),f.jsxs(Mn,{onSelect:O=>{O.stopPropagation(),p.onCopyRelativePath(e.path)},children:[f.jsx(jl,{className:"h-3.5 w-3.5"}),f.jsx("span",{className:"text-xs font-medium",children:"Copy Relative Path"})]})]})]})}function Tve({projectId:e,diffs:t,editorLabel:n,diffRenderMode:r,wrapLines:i,onOpenFile:s,onOpenInFinder:o,onDiscardFile:l,onIgnoreFile:c,onIgnoreFolder:u,onCopyFilePath:p,onCopyRelativePath:h,onListBranches:g,onPreviewMergeBranch:b,onMergeBranch:x,onCheckoutBranch:_,onCreateBranch:w,onGenerateCommitMessage:C,onInitializeGit:E,onGetGitHubPublishInfo:k,onCheckGitHubRepoAvailability:R,onSetupGitHub:N,onCommit:A,onSyncWithRemote:M,onLoadPatch:D,onDiffRenderModeChange:U,onWrapLinesChange:j}){var Ye;const P=v.useMemo(()=>({onOpenFile:s,onOpenInFinder:o,onDiscardFile:l,onIgnoreFile:c,onIgnoreFolder:u,onCopyFilePath:p,onCopyRelativePath:h}),[s,o,l,c,u,p,h]),z=t.files.length>0,[O,$]=v.useState(!1),[V,B]=v.useState(null),[F,W]=v.useState(!1),[X,I]=v.useState(!1),[G,ee]=v.useState({}),[H,ue]=v.useState({}),[ae,J]=v.useState({}),te=v.useRef(null),ie=v.useRef({}),de=v.useMemo(()=>t.files.map(_e=>_e.path),[t.files]),he=v.useMemo(()=>de.join("\0"),[de]),Le=Li(_e=>{var Je;return e?((Je=_e.projectUi[e])==null?void 0:Je.viewMode)??(z?"changes":"history"):z?"changes":"history"}),ce=Li(_e=>{var Je;return e?((Je=_e.projectUi[e])==null?void 0:Je.collapsedPaths)??hv:hv}),De=Li(_e=>{var Je;return e?((Je=_e.projectUi[e])==null?void 0:Je.summary)??"":""}),pe=Li(_e=>{var Je;return e?((Je=_e.projectUi[e])==null?void 0:Je.description)??"":""}),st=Li(_e=>_e.reconcileCollapsedPaths),zt=Li(_e=>_e.toggleCollapsedPath),Et=Li(_e=>_e.setViewMode),Qt=Li(_e=>_e.setCommitDraft),Dt=Li(_e=>_e.clearCommitDraft),Tt=iv(_e=>e?_e.checkedPathsByProjectId[e]??hv:hv),mt=iv(_e=>_e.reconcileProject),At=iv(_e=>_e.setChecked),It=iv(_e=>_e.setAllChecked),ht=v.useRef(z);v.useEffect(()=>{e&&st(e,de)},[de,he,e,st]),v.useEffect(()=>{const _e=Object.fromEntries(t.files.map(et=>[et.path,et.patchDigest])),Je=et=>ie.current[et]===_e[et];ee(et=>Object.fromEntries(Object.entries(et).filter(([$e])=>de.includes($e)&&Je($e)))),ue(et=>Object.fromEntries(Object.entries(et).filter(([$e])=>de.includes($e)&&Je($e)))),J(et=>Object.fromEntries(Object.entries(et).filter(([$e])=>de.includes($e)&&Je($e)))),ie.current=_e},[t.files,de,he]),v.useEffect(()=>{e&&mt(e,de)},[de,he,e,mt]),v.useEffect(()=>{if(!e)return;if(ht.current!==z){Et(e,z?"changes":"history"),ht.current=z;return}ht.current=z},[z,e,Et]);const Ht=v.useMemo(()=>t.files.filter(_e=>Tt[_e.path]??!0).map(_e=>_e.path),[Tt,t.files]),ge=Ht.length,we=t.files.length>0&&ge===t.files.length,Be=ge>0&&ge<t.files.length,tt=De.trim(),Pe=tt.length>0,Ve=V!==null,qe=O||Ve,Xe=((Ye=t.branchHistory)==null?void 0:Ye.entries)??[],We=t.behindCount??0,gt=t.aheadCount??0,ot=t.hasUpstream===!0,Bt=t.hasUpstream===!1&&!!t.branchName,ut=t.hasOriginRemote===!0,on=t.branchName?t.branchName.split("/").map(_e=>encodeURIComponent(_e)).join("/"):null,cn=Bt?"publish":We>0?"pull":"fetch",vt=t.originRepoSlug&&on?`https://github.com/${t.originRepoSlug}/compare/${on}?expand=1`:null,Rt=!!(ot&&vt&&t.branchName&&t.branchName!==t.defaultBranchName),St=t.status==="ready"&&ge>0&&!qe,Ut=t.status==="ready"&&ge>0&&Pe&&!qe,xt=ut?"commit_and_push":"commit_only",ft=t.branchName??"current branch";async function Lt(_e){if(Ut){B(_e);try{const Je=await A({paths:Ht,summary:tt,description:pe.trim(),mode:_e});(Je!=null&&Je.ok||Je!=null&&Je.localCommitCreated)&&e&&Dt(e)}finally{B(null)}}}async function Pt(){if(St){$(!0);try{const _e=await C({paths:Ht});e&&Qt(e,{summary:_e.subject,description:_e.body})}finally{$(!1)}}}function Ie(_e){if(!(!(_e.metaKey||_e.ctrlKey)||_e.key!=="Enter")){if(_e.preventDefault(),Pe){Lt(xt);return}Pt()}}async function ze(_e=cn){if(!(t.status!=="ready"||F)){W(!0);try{await M(_e)}finally{W(!1)}}}const Te=v.useCallback(async _e=>{var Je;if(G[_e]!==void 0||ae[_e])return G[_e]??"";J(et=>({...et,[_e]:!0})),ue(et=>{if(!(_e in et))return et;const{[_e]:$e,...Mt}=et;return Mt});try{const et=await D(_e);ee(Mt=>({...Mt,[_e]:et}));const $e=(Je=t.files.find(Mt=>Mt.path===_e))==null?void 0:Je.patchDigest;return $e&&(ie.current={...ie.current,[_e]:$e}),et}catch(et){const $e=et instanceof Error?et.message:String(et);throw ue(Mt=>({...Mt,[_e]:$e})),et}finally{J(et=>{const{[_e]:$e,...Mt}=et;return Mt})}},[t.files,ae,D,G]);return f.jsx("div",{className:"h-full min-h-0 border-l border-border bg-background md:min-w-[370px]",children:f.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[f.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pl-2.5 pr-2 py-2",children:[f.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:f.jsx(kve,{currentBranchName:t.branchName,onListBranches:g,onPreviewMergeBranch:b,onMergeBranch:x,onCheckoutBranch:_,onCreateBranch:w})}),t.status==="ready"?ut?cn==="publish"?f.jsxs(Ge,{variant:"ghost",size:"sm",onClick:()=>void ze(),disabled:F,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[F?f.jsx(Cn,{className:"h-3.5 w-3.5 animate-spin"}):f.jsx(Pv,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Publish Branch"})]}):f.jsxs("div",{className:"flex items-center gap-1",children:[cn==="fetch"?f.jsxs(Yr,{delayDuration:0,children:[f.jsx(Xr,{asChild:!0,children:f.jsxs(Ge,{variant:"ghost",size:"sm",onClick:()=>void ze(),disabled:F,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[F?f.jsx(Cn,{className:"h-3.5 w-3.5 animate-spin"}):f.jsx(vG,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Fetch"})]})}),f.jsx(Br,{children:yve(t.lastFetchedAt)})]}):f.jsxs(Ge,{variant:"ghost",size:"sm",onClick:()=>void ze(),disabled:F,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[F?f.jsx(Cn,{className:"h-3.5 w-3.5 animate-spin"}):f.jsx(YC,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Pull"}),f.jsx("span",{className:"inline-flex min-w-4 items-center justify-center rounded-full bg-muted px-1 text-[10px] text-muted-foreground",children:We})]}),ot&&gt>0?f.jsxs(Ge,{variant:"default",size:"sm",onClick:()=>void ze("push"),disabled:F,className:"h-7 gap-1.5 px-2 text-xs",children:[F?f.jsx(Cn,{className:"h-3.5 w-3.5 animate-spin"}):f.jsx(Pv,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Push"}),f.jsx("span",{className:"inline-flex min-w-4 items-center justify-center rounded-full bg-primary-foreground/15 px-1 text-[10px] text-primary-foreground",children:gt})]}):null,Rt&&vt?f.jsxs(Ge,{variant:"ghost",size:"sm",onClick:()=>{typeof window>"u"||window.open(vt,"_blank","noopener,noreferrer")},className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[f.jsx(_5,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"PR"})]}):null]}):f.jsxs(Ge,{variant:"default",size:"sm",onClick:()=>I(!0),className:"h-7 gap-1.5 px-3 text-xs",children:[f.jsx(kW,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:"Push to GitHub"})]}):null]}),f.jsxs("div",{className:"relative min-h-0 flex-1",children:[f.jsx("div",{className:"sticky top-0 z-30 pl-[14px] pr-[12px] pt-[6px] bg-gradient-to-b from-background to-transparent",children:f.jsx("div",{className:"relative h-[40px] flex min-w-0 items-center justify-center gap-[13px]",children:f.jsxs("div",{className:"flex min-w-0 flex-1 items-center justify-between gap-[13px] relative",children:[Le==="changes"?f.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-muted-foreground/70",children:[f.jsx(OB,{checked:we,mixed:Be,label:Be?"Select all files for commit":we?"Unselect all files from commit":"Select all files for commit",onClick:()=>{!e||t.files.length===0||It(e,de,Be?!0:!we)}}),f.jsxs("span",{children:[ge," files"]})]}):f.jsx("div",{}),f.jsx("div",{className:"pointer-events-none absolute left-1/2 -translate-x-1/2 top-1/2 -translate-y-1/2",children:f.jsx("div",{className:"pointer-events-auto",children:f.jsx(da,{value:Le,onValueChange:_e=>{e&&Et(e,_e)},size:"sm",optionClassName:"flex-1 justify-center",options:[{value:"changes",label:"Changes"},{value:"history",label:"History"}]})})}),Le==="changes"?f.jsxs("div",{className:"flex items-center gap-1",children:[f.jsx(Vw,{label:"Unified diff",active:r==="unified",onClick:()=>U("unified"),children:f.jsx(_G,{className:"h-4 w-4"})}),f.jsx(Vw,{label:"Side-by-side diff",active:r==="split",onClick:()=>U("split"),children:f.jsx(jV,{className:"h-4 w-4"})}),f.jsx(Vw,{label:i?"Disable word wrap":"Enable word wrap",active:i,onClick:()=>j(!i),children:f.jsx(ZG,{className:"h-4 w-4"})})]}):f.jsx("div",{})]})})}),f.jsx("div",{ref:te,className:"h-full overflow-y-auto [scrollbar-gutter:stable]",children:t.status==="no_repo"?f.jsx("div",{className:"flex h-full items-center justify-center px-6 py-3 text-center",children:f.jsxs("div",{className:"flex max-w-[280px] flex-col items-center gap-3",children:[f.jsx("p",{className:"text-sm text-muted-foreground",children:"Initialize git here to start tracking branches, diffs, and history."}),f.jsx(Ge,{size:"sm",onClick:()=>void E(),children:"Init Git"})]})}):Le==="history"?Xe.length===0?f.jsx("div",{className:"flex h-full items-center justify-center px-6 py-3 text-center",children:f.jsxs("p",{className:"text-sm text-muted-foreground",children:["No recent commits on ",t.branchName??"this branch","."]})}):f.jsx("div",{className:"space-y-1.5 p-1.5",children:Xe.map((_e,Je)=>f.jsx(xve,{entry:_e,isPendingPush:Je<gt},_e.sha))}):t.files.length===0?f.jsx("div",{className:"flex h-full items-center justify-center px-6 py-3 text-center",children:f.jsx("p",{className:"text-sm text-muted-foreground",children:"No file changes."})}):f.jsxs("div",{className:"space-y-1.5 p-1.5 pb-10",children:[t.files.map(_e=>{const Je=ce[_e.path]??!0,et=Tt[_e.path]??!0;return f.jsx(Eve,{file:_e,rootRef:te,projectId:e,isCollapsed:Je,isChecked:et,editorLabel:n,diffRenderMode:r,wrapLines:i,onToggleCollapsed:()=>{e&&zt(e,_e.path)},onToggleChecked:()=>{e&&At(e,_e.path,!et)},fileActions:P,patch:G[_e.path],patchError:H[_e.path],isPatchLoading:!!ae[_e.path],onLoadPatch:Te},_e.path)}),Le==="changes"?f.jsxs("div",{className:"pointer-events-none sticky inset-x-0 bottom-11 py-1 pb-6 z-30 overflow-y-auto",children:[f.jsx("div",{className:"absolute inset-x-0 bottom-0 top-0 bg-gradient-to-t from-background to-transparent"}),f.jsx("div",{className:"pointer-events-auto relative",children:f.jsxs("div",{className:"space-y-0 rounded-xl mx-auto max-w-[700px]",children:[f.jsx(Kn,{value:De,onChange:_e=>{e&&Qt(e,{summary:_e.target.value,description:pe})},onKeyDown:Ie,placeholder:"Commit message (override)",className:"rounded-t-xl rounded-b-none px-3",disabled:qe||t.status!=="ready"}),f.jsx(d0,{value:pe,onChange:_e=>{e&&Qt(e,{summary:De,description:_e.target.value})},onKeyDown:Ie,placeholder:"Description",rows:5,className:"-mt-px rounded-t-none rounded-b-xl px-3 outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background mb-2",disabled:qe||t.status!=="ready"}),f.jsx("div",{className:"w-full flex flex-row",children:f.jsxs(Zc,{children:[f.jsx(Jc,{asChild:!0,children:f.jsx(Ge,{type:"button",className:"-mt-px w-full rounded-xl",disabled:Pe?!Ut:!St,onClick:()=>{if(Pe){Lt(xt);return}Pt()},children:f.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[Pe?Ve?f.jsx(Cn,{strokeWidth:2.5,className:"size-3 shrink-0 animate-spin"}):xt==="commit_and_push"?t.hasUpstream?f.jsx(Pv,{strokeWidth:2.5,className:"size-3 shrink-0"}):f.jsx(x5,{strokeWidth:2.5,className:"size-3 shrink-0"}):f.jsx(yi,{strokeWidth:2.5,className:"size-3 shrink-0"}):O?f.jsx(Cn,{strokeWidth:2.5,className:"size-3 shrink-0 animate-spin"}):f.jsx(sG,{strokeWidth:2.5,className:"size-3 shrink-0"}),f.jsx("span",{className:"min-w-0 truncate text-left",children:Pe?Ve?V==="commit_only"?"Committing...":"Committing & Pushing...":xt==="commit_only"?f.jsxs(f.Fragment,{children:["Commit to ",f.jsx(kc,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),ft]}):t.hasUpstream?f.jsxs(f.Fragment,{children:["Commit & push to ",f.jsx(kc,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),ft]}):f.jsxs(f.Fragment,{children:["Commit & publish ",f.jsx(kc,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),ft]}):O?"Generating...":f.jsxs(f.Fragment,{children:["Generate message for ",f.jsx(kc,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),ft]})})]})})}),t.hasUpstream?f.jsx(Fl,{children:f.jsx(Mn,{disabled:!Pe||!Ut,onSelect:_e=>{_e.stopPropagation(),Lt("commit_only")},children:"Commit Only"})}):null]})})]})})]}):null]})})]}),f.jsx(Sve,{open:X,onOpenChange:I,onGetGitHubPublishInfo:k,onCheckGitHubRepoAvailability:R,onPublish:N})]})})}const Rve=v.memo(Tve);function Nve(e,t){const n=getComputedStyle(e),r=parseFloat(n.fontSize);return t*r}function Ave(e,t){const n=getComputedStyle(e.ownerDocument.body),r=parseFloat(n.fontSize);return t*r}function Mve(e){return e/100*window.innerHeight}function Lve(e){return e/100*window.innerWidth}function jve(e){switch(typeof e){case"number":return[e,"px"];case"string":{const t=parseFloat(e);return e.endsWith("%")?[t,"%"]:e.endsWith("px")?[t,"px"]:e.endsWith("rem")?[t,"rem"]:e.endsWith("em")?[t,"em"]:e.endsWith("vh")?[t,"vh"]:e.endsWith("vw")?[t,"vw"]:[t,"%"]}}}function Lh({groupSize:e,panelElement:t,styleProp:n}){let r;const[i,s]=jve(n);switch(s){case"%":{r=i/100*e;break}case"px":{r=i;break}case"rem":{r=Ave(t,i);break}case"em":{r=Nve(t,i);break}case"vh":{r=Mve(i);break}case"vw":{r=Lve(i);break}}return r}function ji(e){return parseFloat(e.toFixed(3))}function Pd({group:e}){const{orientation:t,panels:n}=e;return n.reduce((r,i)=>(r+=t==="horizontal"?i.element.offsetWidth:i.element.offsetHeight,r),0)}function H1(e){const{panels:t}=e,n=Pd({group:e});return n===0?t.map(r=>({groupResizeBehavior:r.panelConstraints.groupResizeBehavior,collapsedSize:0,collapsible:r.panelConstraints.collapsible===!0,defaultSize:void 0,disabled:r.panelConstraints.disabled,minSize:0,maxSize:100,panelId:r.id})):t.map(r=>{const{element:i,panelConstraints:s}=r;let o=0;if(s.collapsedSize!==void 0){const p=Lh({groupSize:n,panelElement:i,styleProp:s.collapsedSize});o=ji(p/n*100)}let l;if(s.defaultSize!==void 0){const p=Lh({groupSize:n,panelElement:i,styleProp:s.defaultSize});l=ji(p/n*100)}let c=0;if(s.minSize!==void 0){const p=Lh({groupSize:n,panelElement:i,styleProp:s.minSize});c=ji(p/n*100)}let u=100;if(s.maxSize!==void 0){const p=Lh({groupSize:n,panelElement:i,styleProp:s.maxSize});u=ji(p/n*100)}return{groupResizeBehavior:s.groupResizeBehavior,collapsedSize:o,collapsible:s.collapsible===!0,defaultSize:l,disabled:s.disabled,minSize:c,maxSize:u,panelId:r.id}})}function An(e,t="Assertion error"){if(!e)throw Error(t)}function U1(e,t){return Array.from(t).sort(e==="horizontal"?Dve:Ive)}function Dve(e,t){const n=e.element.offsetLeft-t.element.offsetLeft;return n!==0?n:e.element.offsetWidth-t.element.offsetWidth}function Ive(e,t){const n=e.element.offsetTop-t.element.offsetTop;return n!==0?n:e.element.offsetHeight-t.element.offsetHeight}function BB(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.ELEMENT_NODE}function FB(e,t){return{x:e.x>=t.left&&e.x<=t.right?0:Math.min(Math.abs(e.x-t.left),Math.abs(e.x-t.right)),y:e.y>=t.top&&e.y<=t.bottom?0:Math.min(Math.abs(e.y-t.top),Math.abs(e.y-t.bottom))}}function Pve({orientation:e,rects:t,targetRect:n}){const r={x:n.x+n.width/2,y:n.y+n.height/2};let i,s=Number.MAX_VALUE;for(const o of t){const{x:l,y:c}=FB(r,o),u=e==="horizontal"?l:c;u<s&&(s=u,i=o)}return An(i,"No rect found"),i}let pv;function Ove(){return pv===void 0&&(typeof matchMedia=="function"?pv=!!matchMedia("(pointer:coarse)").matches:pv=!1),pv}function $B(e){const{element:t,orientation:n,panels:r,separators:i}=e,s=U1(n,Array.from(t.children).filter(BB).map(x=>({element:x}))).map(({element:x})=>x),o=[];let l=!1,c=!1,u=-1,p=-1,h=0,g,b=[];{let x=-1;for(const _ of s)_.hasAttribute("data-panel")&&(x++,_.ariaDisabled===null&&(h++,u===-1&&(u=x),p=x))}if(h>1){let x=-1;for(const _ of s)if(_.hasAttribute("data-panel")){x++;const w=r.find(C=>C.element===_);if(w){if(g){const C=g.element.getBoundingClientRect(),E=_.getBoundingClientRect();let k;if(c){const R=n==="horizontal"?new DOMRect(C.right,C.top,0,C.height):new DOMRect(C.left,C.bottom,C.width,0),N=n==="horizontal"?new DOMRect(E.left,E.top,0,E.height):new DOMRect(E.left,E.top,E.width,0);switch(b.length){case 0:{k=[R,N];break}case 1:{const A=b[0],M=Pve({orientation:n,rects:[C,E],targetRect:A.element.getBoundingClientRect()});k=[A,M===C?N:R];break}default:{k=b;break}}}else b.length?k=b:k=[n==="horizontal"?new DOMRect(C.right,E.top,E.left-C.right,E.height):new DOMRect(E.left,C.bottom,E.width,E.top-C.bottom)];for(const R of k){let N="width"in R?R:R.element.getBoundingClientRect();const A=Ove()?e.resizeTargetMinimumSize.coarse:e.resizeTargetMinimumSize.fine;if(N.width<A){const D=A-N.width;N=new DOMRect(N.x-D/2,N.y,N.width+D,N.height)}if(N.height<A){const D=A-N.height;N=new DOMRect(N.x,N.y-D/2,N.width,N.height+D)}const M=x<=u||x>p;!l&&!M&&o.push({group:e,groupSize:Pd({group:e}),panels:[g,w],separator:"width"in R?void 0:R,rect:N}),l=!1}}c=!1,g=w,b=[]}}else if(_.hasAttribute("data-separator")){_.ariaDisabled!==null&&(l=!0);const w=i.find(C=>C.element===_);w?b.push(w):(g=void 0,b=[])}else c=!0}return o}var El,UP;let HB=(UP=class{constructor(){ll(this,El,{})}addListener(t,n){const r=br(this,El)[t];return r===void 0?br(this,El)[t]=[n]:r.includes(n)||r.push(n),()=>{this.removeListener(t,n)}}emit(t,n){const r=br(this,El)[t];if(r!==void 0)if(r.length===1)r[0].call(null,n);else{let i=!1,s=null;const o=Array.from(r);for(let l=0;l<o.length;l++){const c=o[l];try{c.call(null,n)}catch(u){s===null&&(i=!0,s=u)}}if(i)throw s}}removeAllListeners(){hs(this,El,{})}removeListener(t,n){const r=br(this,El)[t];if(r!==void 0){const i=r.indexOf(n);i>=0&&r.splice(i,1)}}},El=new WeakMap,UP),Ro=new Map;const UB=new HB;function zve(e){Ro=new Map(Ro),Ro.delete(e)}function lD(e,t){for(const[n]of Ro)if(n.id===e)return n}function Al(e,t){for(const[n,r]of Ro)if(n.id===e)return r;if(t)throw Error(`Could not find data for Group with id ${e}`)}function nu(){return Ro}function ZE(e,t){return UB.addListener("groupChange",n=>{n.group.id===e&&t(n)})}function ka(e,t){const n=Ro.get(e);Ro=new Map(Ro),Ro.set(e,t),UB.emit("groupChange",{group:e,prev:n,next:t})}function Bve(e,t,n){let r,i={x:1/0,y:1/0};for(const s of t){const o=FB(n,s.rect);switch(e){case"horizontal":{o.x<=i.x&&(r=s,i=o);break}case"vertical":{o.y<=i.y&&(r=s,i=o);break}}}return r?{distance:i,hitRegion:r}:void 0}function Fve(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function $ve(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:dD(e),b:dD(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();An(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:uD(cD(n.a)),b:uD(cD(n.b))};if(i.a===i.b){const s=r.childNodes,o={a:n.a.at(-1),b:n.b.at(-1)};let l=s.length;for(;l--;){const c=s[l];if(c===o.a)return 1;if(c===o.b)return-1}}return Math.sign(i.a-i.b)}const Hve=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function Uve(e){const t=getComputedStyle(VB(e)??e).display;return t==="flex"||t==="inline-flex"}function Vve(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||Uve(e))||+t.opacity<1||"transform"in t&&t.transform!=="none"||"webkitTransform"in t&&t.webkitTransform!=="none"||"mixBlendMode"in t&&t.mixBlendMode!=="normal"||"filter"in t&&t.filter!=="none"||"webkitFilter"in t&&t.webkitFilter!=="none"||"isolation"in t&&t.isolation==="isolate"||Hve.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function cD(e){let t=e.length;for(;t--;){const n=e[t];if(An(n,"Missing node"),Vve(n))return n}return null}function uD(e){return e&&Number(getComputedStyle(e).zIndex)||0}function dD(e){const t=[];for(;e;)t.push(e),e=VB(e);return t}function VB(e){const{parentNode:t}=e;return Fve(t)?t.host:t}function Wve(e,t){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function Gve({groupElement:e,hitRegion:t,pointerEventTarget:n}){if(!BB(n)||n.contains(e)||e.contains(n))return!0;if($ve(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if(Wve(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function JE(e,t){const n=[];return t.forEach((r,i)=>{if(i.disabled)return;const s=$B(i),o=Bve(i.orientation,s,{x:e.clientX,y:e.clientY});o&&o.distance.x<=0&&o.distance.y<=0&&Gve({groupElement:i.element,hitRegion:o.hitRegion.rect,pointerEventTarget:e.target})&&n.push(o.hitRegion)}),n}function qve(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function pi(e,t,n=0){return Math.abs(ji(e)-ji(t))<=n}function So(e,t){return pi(e,t)?0:e>t?1:-1}function ud({overrideDisabledPanels:e,panelConstraints:t,prevSize:n,size:r}){const{collapsedSize:i=0,collapsible:s,disabled:o,maxSize:l=100,minSize:c=0}=t;if(o&&!e)return n;if(So(r,c)<0)if(s){const u=(i+c)/2;So(r,u)<0?r=i:r=c}else r=c;return r=Math.min(l,r),r=ji(r),r}function Np({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(pi(e,0))return t;const o=s==="imperative-api",l=Object.values(t),c=Object.values(i),u=[...l],[p,h]=r;An(p!=null,"Invalid first pivot index"),An(h!=null,"Invalid second pivot index");let g=0;switch(s){case"keyboard":{{const _=e<0?h:p,w=n[_];An(w,`Panel constraints not found for index ${_}`);const{collapsedSize:C=0,collapsible:E,minSize:k=0}=w;if(E){const R=l[_];if(An(R!=null,`Previous layout not found for panel index ${_}`),pi(R,C)){const N=k-R;So(N,Math.abs(e))>0&&(e=e<0?0-N:N)}}}{const _=e<0?p:h,w=n[_];An(w,`No panel constraints found for index ${_}`);const{collapsedSize:C=0,collapsible:E,minSize:k=0}=w;if(E){const R=l[_];if(An(R!=null,`Previous layout not found for panel index ${_}`),pi(R,k)){const N=R-C;So(N,Math.abs(e))>0&&(e=e<0?0-N:N)}}}break}default:{const _=e<0?h:p,w=n[_];An(w,`Panel constraints not found for index ${_}`);const C=l[_],{collapsible:E,collapsedSize:k,minSize:R}=w;if(E&&So(C,R)<0)if(e>0){const N=R-k,A=N/2,M=C+e;So(M,R)<0&&(e=So(e,A)<=0?0:N)}else{const N=R-k,A=100-N/2,M=C-e;So(M,R)<0&&(e=So(100+e,A)>0?0:-N)}break}}{const _=e<0?1:-1;let w=e<0?h:p,C=0;for(;;){const k=l[w];An(k!=null,`Previous layout not found for panel index ${w}`);const R=ud({overrideDisabledPanels:o,panelConstraints:n[w],prevSize:k,size:100})-k;if(C+=R,w+=_,w<0||w>=n.length)break}const E=Math.min(Math.abs(e),Math.abs(C));e=e<0?0-E:E}{let _=e<0?p:h;for(;_>=0&&_<n.length;){const w=Math.abs(e)-Math.abs(g),C=l[_];An(C!=null,`Previous layout not found for panel index ${_}`);const E=C-w,k=ud({overrideDisabledPanels:o,panelConstraints:n[_],prevSize:C,size:E});if(!pi(C,k)&&(g+=C-k,u[_]=k,g.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?_--:_++}}if(qve(c,u))return i;{const _=e<0?h:p,w=l[_];An(w!=null,`Previous layout not found for panel index ${_}`);const C=w+g,E=ud({overrideDisabledPanels:o,panelConstraints:n[_],prevSize:w,size:C});if(u[_]=E,!pi(E,C)){let k=C-E,R=e<0?h:p;for(;R>=0&&R<n.length;){const N=u[R];An(N!=null,`Previous layout not found for panel index ${R}`);const A=N+k,M=ud({overrideDisabledPanels:o,panelConstraints:n[R],prevSize:N,size:A});if(pi(N,M)||(k-=M-N,u[R]=M),pi(k,0))break;e>0?R--:R++}}}const b=Object.values(u).reduce((_,w)=>w+_,0);if(!pi(b,100,.1))return i;const x=Object.keys(i);return u.reduce((_,w,C)=>(_[x[C]]=w,_),{})}function Hc(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(t[n]===void 0||So(e[n],t[n])!==0)return!1;return!0}function Uc({layout:e,panelConstraints:t}){const n=Object.values(e),r=[...n],i=r.reduce((l,c)=>l+c,0);if(r.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${r.map(l=>`${l}%`).join(", ")}`);if(!pi(i,100)&&r.length>0)for(let l=0;l<t.length;l++){const c=r[l];An(c!=null,`No layout data found for index ${l}`);const u=100/i*c;r[l]=u}let s=0;for(let l=0;l<t.length;l++){const c=n[l];An(c!=null,`No layout data found for index ${l}`);const u=r[l];An(u!=null,`No layout data found for index ${l}`);const p=ud({overrideDisabledPanels:!0,panelConstraints:t[l],prevSize:c,size:u});u!=p&&(s+=u-p,r[l]=p)}if(!pi(s,0))for(let l=0;l<t.length;l++){const c=r[l];An(c!=null,`No layout data found for index ${l}`);const u=c+s,p=ud({overrideDisabledPanels:!0,panelConstraints:t[l],prevSize:c,size:u});if(c!==p&&(s-=p-c,r[l]=p,pi(s,0)))break}const o=Object.keys(e);return r.reduce((l,c,u)=>(l[o[u]]=c,l),{})}function WB({groupId:e,panelId:t}){const n=()=>{const l=nu();for(const[c,{defaultLayoutDeferred:u,derivedPanelConstraints:p,layout:h,groupSize:g,separatorToPanels:b}]of l)if(c.id===e)return{defaultLayoutDeferred:u,derivedPanelConstraints:p,group:c,groupSize:g,layout:h,separatorToPanels:b};throw Error(`Group ${e} not found`)},r=()=>{const l=n().derivedPanelConstraints.find(c=>c.panelId===t);if(l!==void 0)return l;throw Error(`Panel constraints not found for Panel ${t}`)},i=()=>{const l=n().group.panels.find(c=>c.id===t);if(l!==void 0)return l;throw Error(`Layout not found for Panel ${t}`)},s=()=>{const l=n().layout[t];if(l!==void 0)return l;throw Error(`Layout not found for Panel ${t}`)},o=l=>{const c=s();if(l===c)return;const{defaultLayoutDeferred:u,derivedPanelConstraints:p,group:h,groupSize:g,layout:b,separatorToPanels:x}=n(),_=h.panels.findIndex(k=>k.id===t),w=_===h.panels.length-1,C=Np({delta:w?c-l:l-c,initialLayout:b,panelConstraints:p,pivotIndices:w?[_-1,_]:[_,_+1],prevLayout:b,trigger:"imperative-api"}),E=Uc({layout:C,panelConstraints:p});Hc(b,E)||ka(h,{defaultLayoutDeferred:u,derivedPanelConstraints:p,groupSize:g,layout:E,separatorToPanels:x})};return{collapse:()=>{const{collapsible:l,collapsedSize:c}=r(),{mutableValues:u}=i(),p=s();l&&p!==c&&(u.expandToSize=p,o(c))},expand:()=>{const{collapsible:l,collapsedSize:c,minSize:u}=r(),{mutableValues:p}=i(),h=s();if(l&&h===c){let g=p.expandToSize??u;g===0&&(g=1),o(g)}},getSize:()=>{const{group:l}=n(),c=s(),{element:u}=i(),p=l.orientation==="horizontal"?u.offsetWidth:u.offsetHeight;return{asPercentage:c,inPixels:p}},isCollapsed:()=>{const{collapsible:l,collapsedSize:c}=r(),u=s();return l&&pi(c,u)},resize:l=>{const{group:c}=n(),{element:u}=i(),p=Pd({group:c}),h=Lh({groupSize:p,panelElement:u,styleProp:l}),g=ji(h/p*100);o(g)}}}function fD(e){if(e.defaultPrevented)return;const t=nu();JE(e,t).forEach(n=>{if(n.separator){const r=n.panels.find(i=>i.panelConstraints.defaultSize!==void 0);if(r){const i=r.panelConstraints.defaultSize,s=WB({groupId:n.group.id,panelId:r.id});s&&i!==void 0&&(s.resize(i),e.preventDefault())}}})}function Qv(e){const t=nu();for(const[n]of t)if(n.separators.some(r=>r.element===e))return n;throw Error("Could not find parent Group for separator element")}function GB({groupId:e}){const t=()=>{const n=nu();for(const[r,i]of n)if(r.id===e)return{group:r,...i};throw Error(`Could not find Group with id "${e}"`)};return{getLayout(){const{defaultLayoutDeferred:n,layout:r}=t();return n?{}:r},setLayout(n){const{defaultLayoutDeferred:r,derivedPanelConstraints:i,group:s,groupSize:o,layout:l,separatorToPanels:c}=t(),u=Uc({layout:n,panelConstraints:i});return r?l:(Hc(l,u)||ka(s,{defaultLayoutDeferred:r,derivedPanelConstraints:i,groupSize:o,layout:u,separatorToPanels:c}),u)}}}function mc(e,t){const n=Qv(e),r=Al(n.id,!0),i=n.separators.find(p=>p.element===e);An(i,"Matching separator not found");const s=r.separatorToPanels.get(i);An(s,"Matching panels not found");const o=s.map(p=>n.panels.indexOf(p)),l=GB({groupId:n.id}).getLayout(),c=Np({delta:t,initialLayout:l,panelConstraints:r.derivedPanelConstraints,pivotIndices:o,prevLayout:l,trigger:"keyboard"}),u=Uc({layout:c,panelConstraints:r.derivedPanelConstraints});Hc(l,u)||ka(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedPanelConstraints:r.derivedPanelConstraints,groupSize:r.groupSize,layout:u,separatorToPanels:r.separatorToPanels})}function hD(e){if(e.defaultPrevented)return;const t=e.currentTarget,n=Qv(t);if(!n.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),n.orientation==="vertical"&&mc(t,5);break}case"ArrowLeft":{e.preventDefault(),n.orientation==="horizontal"&&mc(t,-5);break}case"ArrowRight":{e.preventDefault(),n.orientation==="horizontal"&&mc(t,5);break}case"ArrowUp":{e.preventDefault(),n.orientation==="vertical"&&mc(t,-5);break}case"End":{e.preventDefault(),mc(t,100);break}case"Enter":{e.preventDefault();const r=Qv(t),i=Al(r.id,!0),{derivedPanelConstraints:s,layout:o,separatorToPanels:l}=i,c=r.separators.find(g=>g.element===t);An(c,"Matching separator not found");const u=l.get(c);An(u,"Matching panels not found");const p=u[0],h=s.find(g=>g.panelId===p.id);if(An(h,"Panel metadata not found"),h.collapsible){const g=o[p.id],b=h.collapsedSize===g?r.mutableState.expandedPanelSizes[p.id]??h.minSize:h.collapsedSize;mc(t,b-g)}break}case"F6":{e.preventDefault();const r=Qv(t).separators.map(o=>o.element),i=Array.from(r).findIndex(o=>o===e.currentTarget);An(i!==null,"Index not found");const s=e.shiftKey?i>0?i-1:r.length-1:i+1<r.length?i+1:0;r[s].focus({preventScroll:!0});break}case"Home":{e.preventDefault(),mc(t,-100);break}}}let Sd={cursorFlags:0,state:"inactive"};const e2=new HB;function Vc(){return Sd}function Kve(e){return e2.addListener("change",e)}function Yve(e){const t=Sd,n={...Sd};n.cursorFlags=e,Sd=n,e2.emit("change",{prev:t,next:n})}function Cd(e){const t=Sd;Sd=e,e2.emit("change",{prev:t,next:e})}function pD(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=nu(),n=JE(e,t),r=new Map;let i=!1;n.forEach(s=>{s.separator&&(i||(i=!0,s.separator.element.focus({preventScroll:!0})));const o=t.get(s.group);o&&r.set(s.group,o.layout)}),Cd({cursorFlags:0,hitRegions:n,initialLayoutMap:r,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}),n.length&&e.preventDefault()}const Xve=e=>e,Ww=()=>{},qB=1,KB=2,YB=4,XB=8,mD=3,gD=12;let mv;function vD(){return mv===void 0&&(mv=!1,typeof window<"u"&&(window.navigator.userAgent.includes("Chrome")||window.navigator.userAgent.includes("Firefox"))&&(mv=!0)),mv}function Qve({cursorFlags:e,groups:t,state:n}){let r=0,i=0;switch(n){case"active":case"hover":t.forEach(s=>{if(!s.mutableState.disableCursor)switch(s.orientation){case"horizontal":{r++;break}case"vertical":{i++;break}}})}if(!(r===0&&i===0)){switch(n){case"active":{if(e&&vD()){const s=(e&qB)!==0,o=(e&KB)!==0,l=(e&YB)!==0,c=(e&XB)!==0;if(s)return l?"se-resize":c?"ne-resize":"e-resize";if(o)return l?"sw-resize":c?"nw-resize":"w-resize";if(l)return"s-resize";if(c)return"n-resize"}break}}return vD()?r>0&&i>0?"move":r>0?"ew-resize":"ns-resize":r>0&&i>0?"grab":r>0?"col-resize":"row-resize"}}const bD=new WeakMap;function t2(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:n}=bD.get(e)??{};n===void 0&&(n=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets&&e.adoptedStyleSheets.push(n));const r=Vc();switch(r.state){case"active":case"hover":{const i=Qve({cursorFlags:r.cursorFlags,groups:r.hitRegions.map(o=>o.group),state:r.state}),s=`*, *:hover {cursor: ${i} !important; }`;if(t===s)return;t=s,i?n.cssRules.length===0?n.insertRule(s):n.replaceSync(s):n.cssRules.length===1&&n.deleteRule(0);break}case"inactive":{t=void 0,n.cssRules.length===1&&n.deleteRule(0);break}}bD.set(e,{prevStyle:t,styleSheet:n})}function QB({document:e,event:t,hitRegions:n,initialLayoutMap:r,mountedGroups:i,pointerDownAtPoint:s,prevCursorFlags:o}){let l=0;n.forEach(u=>{const{group:p,groupSize:h}=u,{orientation:g,panels:b}=p,{disableCursor:x}=p.mutableState;let _=0;s?g==="horizontal"?_=(t.clientX-s.x)/h*100:_=(t.clientY-s.y)/h*100:g==="horizontal"?_=t.clientX<0?-100:100:_=t.clientY<0?-100:100;const w=r.get(p),C=i.get(p);if(!w||!C)return;const{defaultLayoutDeferred:E,derivedPanelConstraints:k,groupSize:R,layout:N,separatorToPanels:A}=C;if(k&&N&&A){const M=Np({delta:_,initialLayout:w,panelConstraints:k,pivotIndices:u.panels.map(D=>b.indexOf(D)),prevLayout:N,trigger:"mouse-or-touch"});if(Hc(M,N)){if(_!==0&&!x)switch(g){case"horizontal":{l|=_<0?qB:KB;break}case"vertical":{l|=_<0?YB:XB;break}}}else ka(u.group,{defaultLayoutDeferred:E,derivedPanelConstraints:k,groupSize:R,layout:M,separatorToPanels:A})}});let c=0;t.movementX===0?c|=o&mD:c|=l&mD,t.movementY===0?c|=o&gD:c|=l&gD,Yve(c),t2(e)}function yD(e){const t=nu(),n=Vc();switch(n.state){case"active":QB({document:e.currentTarget,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedGroups:t,prevCursorFlags:n.cursorFlags})}}function xD(e){if(e.defaultPrevented)return;const t=Vc(),n=nu();switch(t.state){case"active":{if(e.buttons===0){Cd({cursorFlags:0,state:"inactive"}),t.hitRegions.forEach(r=>{const i=Al(r.group.id,!0);ka(r.group,i)});return}QB({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break}default:{const r=JE(e,n);r.length===0?t.state!=="inactive"&&Cd({cursorFlags:0,state:"inactive"}):Cd({cursorFlags:0,hitRegions:r,state:"hover"}),t2(e.currentTarget);break}}}function _D(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(Vc().state){case"hover":Cd({cursorFlags:0,state:"inactive"})}}function wD(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=Vc();switch(t.state){case"active":Cd({cursorFlags:0,state:"inactive"}),t.hitRegions.length>0&&(t2(e.currentTarget),t.hitRegions.forEach(n=>{const r=Al(n.group.id,!0);ka(n.group,r)}),e.preventDefault())}}function SD(e){let t=0,n=0;const r={};for(const s of e)if(s.defaultSize!==void 0){t++;const o=ji(s.defaultSize);n+=o,r[s.panelId]=o}else r[s.panelId]=void 0;const i=e.length-t;if(i!==0){const s=ji((100-n)/i);for(const o of e)o.defaultSize===void 0&&(r[o.panelId]=s)}return r}function Zve(e,t,n){if(!n[0])return;const r=e.panels.find(c=>c.element===t);if(!r||!r.onResize)return;const i=Pd({group:e}),s=e.orientation==="horizontal"?r.element.offsetWidth:r.element.offsetHeight,o=r.mutableValues.prevSize,l={asPercentage:ji(s/i*100),inPixels:s};r.mutableValues.prevSize=l,r.onResize(l,r.id,o)}function Jve(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(e[n]!==t[n])return!1;return!0}function ebe({group:e,nextGroupSize:t,prevGroupSize:n,prevLayout:r}){if(n<=0||t<=0||n===t)return r;let i=0,s=0,o=!1;const l=new Map,c=[];for(const h of e.panels){const g=r[h.id]??0;switch(h.panelConstraints.groupResizeBehavior){case"preserve-pixel-size":{o=!0;const b=g/100*n,x=ji(b/t*100);l.set(h.id,x),i+=x;break}case"preserve-relative-size":default:{c.push(h.id),s+=g;break}}}if(!o||c.length===0)return r;const u=100-i,p={...r};if(l.forEach((h,g)=>{p[g]=h}),s>0)for(const h of c){const g=r[h]??0;p[h]=ji(g/s*u)}else{const h=ji(u/c.length);for(const g of c)p[g]=h}return p}function tbe(e,t){const n=e.map(i=>i.id),r=Object.keys(t);if(n.length!==r.length)return!1;for(const i of n)if(!r.includes(i))return!1;return!0}const Xu=new Map;function nbe(e){let t=!0;An(e.element.ownerDocument.defaultView,"Cannot register an unmounted Group");const n=e.element.ownerDocument.defaultView.ResizeObserver,r=new Set,i=new Set,s=new n(x=>{for(const _ of x){const{borderBoxSize:w,target:C}=_;if(C===e.element){if(t){const E=Pd({group:e});if(E===0)return;const k=Al(e.id);if(!k)return;const R=H1(e),N=k.defaultLayoutDeferred?SD(R):k.layout,A=ebe({group:e,nextGroupSize:E,prevGroupSize:k.groupSize,prevLayout:N}),M=Uc({layout:A,panelConstraints:R});if(!k.defaultLayoutDeferred&&Hc(k.layout,M)&&Jve(k.derivedPanelConstraints,R)&&k.groupSize===E)return;ka(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:R,groupSize:E,layout:M,separatorToPanels:k.separatorToPanels})}}else Zve(e,C,w)}});s.observe(e.element),e.panels.forEach(x=>{An(!r.has(x.id),`Panel ids must be unique; id "${x.id}" was used more than once`),r.add(x.id),x.onResize&&s.observe(x.element)});const o=Pd({group:e}),l=H1(e),c=e.panels.map(({id:x})=>x).join(",");let u=e.mutableState.defaultLayout;u&&(tbe(e.panels,u)||(u=void 0));const p=e.mutableState.layouts[c]??u??SD(l),h=Uc({layout:p,panelConstraints:l}),g=e.element.ownerDocument;Xu.set(g,(Xu.get(g)??0)+1);const b=new Map;return $B(e).forEach(x=>{x.separator&&b.set(x.separator,x.panels)}),ka(e,{defaultLayoutDeferred:o===0,derivedPanelConstraints:l,groupSize:o,layout:h,separatorToPanels:b}),e.separators.forEach(x=>{An(!i.has(x.id),`Separator ids must be unique; id "${x.id}" was used more than once`),i.add(x.id),x.element.addEventListener("keydown",hD)}),Xu.get(g)===1&&(g.addEventListener("dblclick",fD,!0),g.addEventListener("pointerdown",pD,!0),g.addEventListener("pointerleave",yD),g.addEventListener("pointermove",xD),g.addEventListener("pointerout",_D),g.addEventListener("pointerup",wD,!0)),function(){t=!1,Xu.set(g,Math.max(0,(Xu.get(g)??0)-1)),zve(e),e.separators.forEach(x=>{x.element.removeEventListener("keydown",hD)}),Xu.get(g)||(g.removeEventListener("dblclick",fD,!0),g.removeEventListener("pointerdown",pD,!0),g.removeEventListener("pointerleave",yD),g.removeEventListener("pointermove",xD),g.removeEventListener("pointerout",_D),g.removeEventListener("pointerup",wD,!0)),s.disconnect()}}function rbe(){const[e,t]=v.useState({}),n=v.useCallback(()=>t({}),[]);return[e,n]}function n2(e){const t=v.useId();return`${e??t}`}const ru=typeof window<"u"?v.useLayoutEffect:v.useEffect;function Xh(e){const t=v.useRef(e);return ru(()=>{t.current=e},[e]),v.useCallback((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[t])}function r2(...e){return Xh(t=>{e.forEach(n=>{if(n)switch(typeof n){case"function":{n(t);break}case"object":{n.current=t;break}}})})}function i2(e){const t=v.useRef({...e});return ru(()=>{for(const n in e)t.current[n]=e[n]},[e]),t.current}const ZB=v.createContext(null);function ibe(e,t){const n=v.useRef({getLayout:()=>({}),setLayout:Xve});v.useImperativeHandle(t,()=>n.current,[]),ru(()=>{Object.assign(n.current,GB({groupId:e}))})}function JB({children:e,className:t,defaultLayout:n,disableCursor:r,disabled:i,elementRef:s,groupRef:o,id:l,onLayoutChange:c,onLayoutChanged:u,orientation:p="horizontal",resizeTargetMinimumSize:h={coarse:20,fine:10},style:g,...b}){const x=v.useRef({onLayoutChange:{},onLayoutChanged:{}}),_=Xh(P=>{Hc(x.current.onLayoutChange,P)||(x.current.onLayoutChange=P,c==null||c(P))}),w=Xh(P=>{Hc(x.current.onLayoutChanged,P)||(x.current.onLayoutChanged=P,u==null||u(P))}),C=n2(l),E=v.useRef(null),[k,R]=rbe(),N=v.useRef({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:h,separators:[]}),A=r2(E,s);ibe(C,o);const M=Xh((P,z)=>{const O=Vc(),$=lD(P),V=Al(P);if(V){let B=!1;switch(O.state){case"active":{B=O.hitRegions.some(F=>F.group===$);break}}return{flexGrow:V.layout[z]??1,pointerEvents:B?"none":void 0}}return{flexGrow:(n==null?void 0:n[z])??1}}),D=i2({defaultLayout:n,disableCursor:r}),U=v.useMemo(()=>({get disableCursor(){return!!D.disableCursor},getPanelStyles:M,id:C,orientation:p,registerPanel:P=>{const z=N.current;return z.panels=U1(p,[...z.panels,P]),R(),()=>{z.panels=z.panels.filter(O=>O!==P),R()}},registerSeparator:P=>{const z=N.current;return z.separators=U1(p,[...z.separators,P]),R(),()=>{z.separators=z.separators.filter(O=>O!==P),R()}},togglePanelDisabled:(P,z)=>{const O=N.current.panels.find(B=>B.id===P);O&&(O.panelConstraints.disabled=z);const $=lD(C),V=Al(C);$&&V&&ka($,{...V,derivedPanelConstraints:H1($)})},toggleSeparatorDisabled:(P,z)=>{const O=N.current.separators.find($=>$.id===P);O&&(O.disabled=z)}}),[M,C,R,p,D]),j=v.useRef(null);return ru(()=>{const P=E.current;if(P===null)return;const z=N.current;let O;if(D.defaultLayout!==void 0&&Object.keys(D.defaultLayout).length===z.panels.length){O={};for(const I of z.panels){const G=D.defaultLayout[I.id];G!==void 0&&(O[I.id]=G)}}const $={disabled:!!i,element:P,id:C,mutableState:{defaultLayout:O,disableCursor:!!D.disableCursor,expandedPanelSizes:N.current.lastExpandedPanelSizes,layouts:N.current.layouts},orientation:p,panels:z.panels,resizeTargetMinimumSize:z.resizeTargetMinimumSize,separators:z.separators};j.current=$;const V=nbe($),{defaultLayoutDeferred:B,derivedPanelConstraints:F,layout:W}=Al($.id,!0);!B&&F.length>0&&(_(W),w(W));const X=ZE(C,I=>{const{defaultLayoutDeferred:G,derivedPanelConstraints:ee,layout:H}=I.next;if(G||ee.length===0)return;const ue=$.panels.map(({id:J})=>J).join(",");$.mutableState.layouts[ue]=H,ee.forEach(J=>{if(J.collapsible){const{layout:te}=I.prev??{};if(te){const ie=pi(J.collapsedSize,H[J.panelId]),de=pi(J.collapsedSize,te[J.panelId]);ie&&!de&&($.mutableState.expandedPanelSizes[J.panelId]=te[J.panelId])}}});const ae=Vc().state!=="active";_(H),ae&&w(H)});return()=>{j.current=null,V(),X()}},[i,C,w,_,p,k,D]),v.useEffect(()=>{const P=j.current;P&&(P.mutableState.defaultLayout=n,P.mutableState.disableCursor=!!r)}),f.jsx(ZB.Provider,{value:U,children:f.jsx("div",{...b,className:t,"data-group":!0,"data-testid":C,id:C,ref:A,style:{height:"100%",width:"100%",overflow:"hidden",...g,display:"flex",flexDirection:p==="horizontal"?"row":"column",flexWrap:"nowrap",touchAction:p==="horizontal"?"pan-y":"pan-x"},children:e})})}JB.displayName="Group";function s2(){const e=v.useContext(ZB);return An(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function sbe(e,t){const{id:n}=s2(),r=v.useRef({collapse:Ww,expand:Ww,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:Ww});v.useImperativeHandle(t,()=>r.current,[]),ru(()=>{Object.assign(r.current,WB({groupId:n,panelId:e}))})}function eF({children:e,className:t,collapsedSize:n="0%",collapsible:r=!1,defaultSize:i,disabled:s,elementRef:o,groupResizeBehavior:l="preserve-relative-size",id:c,maxSize:u="100%",minSize:p="0%",onResize:h,panelRef:g,style:b,...x}){const _=!!c,w=n2(c),C=i2({disabled:s}),E=v.useRef(null),k=r2(E,o),{getPanelStyles:R,id:N,orientation:A,registerPanel:M,togglePanelDisabled:D}=s2(),U=h!==null,j=Xh((z,O,$)=>{h==null||h(z,c,$)});ru(()=>{const z=E.current;if(z!==null){const O={element:z,id:w,idIsStable:_,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:U?j:void 0,panelConstraints:{groupResizeBehavior:l,collapsedSize:n,collapsible:r,defaultSize:i,disabled:C.disabled,maxSize:u,minSize:p}};return M(O)}},[l,n,r,i,U,w,_,u,p,j,M,C]),v.useEffect(()=>{D(w,!!s)},[s,w,D]),sbe(w,g);const P=v.useSyncExternalStore(z=>ZE(N,z),()=>JSON.stringify(R(N,w)),()=>JSON.stringify(R(N,w)));return f.jsx("div",{...x,"aria-disabled":s||void 0,"data-panel":!0,"data-testid":w,id:w,ref:k,style:{...obe,display:"flex",flexBasis:0,flexShrink:1,overflow:"visible",...JSON.parse(P)},children:f.jsx("div",{className:t,style:{maxHeight:"100%",maxWidth:"100%",flexGrow:1,overflow:"auto",...b,touchAction:A==="horizontal"?"pan-y":"pan-x"},children:e})})}eF.displayName="Panel";const obe={minHeight:0,maxHeight:"100%",height:"auto",minWidth:0,maxWidth:"100%",width:"auto",border:"none",borderWidth:0,padding:0,margin:0};function abe({layout:e,panelConstraints:t,panelId:n,panelIndex:r}){let i,s;const o=e[n],l=t.find(c=>c.panelId===n);if(l){const c=l.maxSize,u=l.collapsible?l.collapsedSize:l.minSize,p=[r,r+1];s=Uc({layout:Np({delta:u-o,initialLayout:e,panelConstraints:t,pivotIndices:p,prevLayout:e}),panelConstraints:t})[n],i=Uc({layout:Np({delta:c-o,initialLayout:e,panelConstraints:t,pivotIndices:p,prevLayout:e}),panelConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:s,valueNow:o}}function tF({children:e,className:t,disabled:n,elementRef:r,id:i,style:s,...o}){const l=n2(i),c=i2({disabled:n}),[u,p]=v.useState({}),[h,g]=v.useState("inactive"),b=v.useRef(null),x=r2(b,r),{disableCursor:_,id:w,orientation:C,registerSeparator:E,toggleSeparatorDisabled:k}=s2(),R=C==="horizontal"?"vertical":"horizontal";ru(()=>{const A=b.current;if(A!==null){const M={disabled:c.disabled,element:A,id:l},D=E(M),U=Kve(P=>{g(P.next.state!=="inactive"&&P.next.hitRegions.some(z=>z.separator===M)?P.next.state:"inactive")}),j=ZE(w,P=>{const{derivedPanelConstraints:z,layout:O,separatorToPanels:$}=P.next,V=$.get(M);if(V){const B=V[0],F=V.indexOf(B);p(abe({layout:O,panelConstraints:z,panelId:B.id,panelIndex:F}))}});return()=>{U(),j(),D()}}},[w,l,E,c]),v.useEffect(()=>{k(l,!!n)},[n,l,k]);let N;return n&&!_&&(N="not-allowed"),f.jsx("div",{...o,"aria-controls":u.valueControls,"aria-disabled":n||void 0,"aria-orientation":R,"aria-valuemax":u.valueMax,"aria-valuemin":u.valueMin,"aria-valuenow":u.valueNow,children:e,className:t,"data-separator":n?"disabled":h,"data-testid":l,id:l,ref:x,role:"separator",style:{flexBasis:"auto",cursor:N,...s,flexGrow:0,flexShrink:0,touchAction:"none"},tabIndex:n?void 0:0})}tF.displayName="Separator";const o2=({className:e,...t})=>f.jsx(JB,{className:me("flex h-full w-full",e),...t}),Ap=e=>f.jsx(eF,{...e}),a2=({withHandle:e,orientation:t,disabled:n,className:r,...i})=>f.jsx(tF,{disabled:n,className:me("relative flex items-center justify-center bg-transparent focus-visible:outline-none",t==="vertical"?"h-2 w-full -my-1 cursor-row-resize":"h-full w-2 -mx-1 cursor-col-resize",e&&(t==="vertical"?"before:absolute before:inset-x-0 before:top-1/2 before:h-0.5 before:-translate-y-1/2 before:bg-border":"before:absolute before:inset-y-0 before:left-1/2 before:w-px before:-translate-x-1/2 before:bg-border"),r),...i,children:f.jsx("span",{className:"sr-only",children:t==="vertical"?"Resize rows":"Resize columns"})});function nF(e,t,n){const r=typeof e.maxTokens=="number"&&Number.isFinite(e.maxTokens)?e.maxTokens:null,i=r&&r>0?Math.min(100,e.usedTokens/r*100):null,s=r!==null?Math.max(0,Math.round(r-e.usedTokens)):null,o=i!==null?Math.max(0,100-i):null;return{...e,compactsAutomatically:e.compactsAutomatically||n,maxTokens:r??void 0,remainingTokens:s,usedPercentage:i,remainingPercentage:o,updatedAt:t}}function lbe(e){const t=e.some(n=>n.kind==="compact_boundary"||n.kind==="compact_summary"||n.kind==="context_cleared");for(let n=e.length-1;n>=0;n-=1){const r=e[n];if(r&&!(r.kind!=="context_window_updated"||r.usage.usedTokens<=0))return nF(r.usage,new Date(r.createdAt).toISOString(),t)}return null}function cbe(e,t){return!e||t===null||!Number.isFinite(t)||t<=0?e:nF({...e,maxTokens:t},e.updatedAt,e.compactsAutomatically)}function xh(e){return e==null||!Number.isFinite(e)?"0":e<1e3?`${Math.round(e)}`:e<1e4?`${(e/1e3).toFixed(1).replace(/\.0$/,"")}k`:e<1e6?`${Math.round(e/1e3)}k`:`${(e/1e6).toFixed(1).replace(/\.0$/,"")}m`}const l2=[68,32];function ube(){return{isVisible:!1,mainSizes:[...l2],terminals:[],nextTerminalIndex:0}}function dbe(e,t){return e[t]??ube()}function Gw(e){if(e.length===0)return[];const t=e.reduce((n,r)=>n+Math.max(r,0),0);return!Number.isFinite(t)||t<=0?Array.from({length:e.length},()=>100/e.length):e.map(n=>Math.max(n,0)/t*100)}function fbe(e){let t=e,n="";do n=String.fromCharCode(65+t%26)+n,t=Math.floor(t/26)-1;while(t>=0);return`Terminal ${n}`}function hbe(e){if(e.length===0)return e;const t=e.length+1;return e.map(n=>({...n,size:n.size*e.length/t}))}function Qu(e,t,n){return{...e,[t]:n(dbe(e,t))}}const yl=oo()(lf(e=>({projects:{},addTerminal:(t,n)=>e(r=>({projects:Qu(r.projects,t,i=>{var c,u;const s=hbe(i.terminals),o={id:((u=(c=globalThis.crypto)==null?void 0:c.randomUUID)==null?void 0:u.call(c))??`terminal-${Date.now()}-${i.nextTerminalIndex}`,title:fbe(i.nextTerminalIndex),size:100/(s.length+1)},l=n?Math.max(s.findIndex(p=>p.id===n)+1,0):s.length;return{...i,isVisible:!0,nextTerminalIndex:i.nextTerminalIndex+1,terminals:[...s.slice(0,l),o,...s.slice(l)]}})})),removeTerminal:(t,n)=>e(r=>({projects:Qu(r.projects,t,i=>{const s=i.terminals.filter(l=>l.id!==n);if(s.length===0)return{...i,isVisible:!1,terminals:[]};const o=Gw(s.map(l=>l.size));return{...i,terminals:s.map((l,c)=>({...l,size:o[c]??100/s.length}))}})})),toggleVisibility:t=>e(n=>({projects:Qu(n.projects,t,r=>({...r,isVisible:r.terminals.length>0?!r.isVisible:!1}))})),resetMainSizes:t=>e(n=>({projects:Qu(n.projects,t,r=>({...r,mainSizes:[...l2]}))})),setMainSizes:(t,n)=>e(r=>{if(n.length!==2)return r;const i=Gw(n);return{projects:Qu(r.projects,t,s=>({...s,mainSizes:i}))}}),setTerminalSizes:(t,n)=>e(r=>({projects:Qu(r.projects,t,i=>{if(n.length!==i.terminals.length)return i;const s=Gw(n);return{...i,terminals:i.terminals.map((o,l)=>({...o,size:s[l]??o.size}))}})})),clearProject:t=>e(n=>{const{[t]:r,...i}=n.projects;return{projects:i}})}),{name:"terminal-layouts",version:1})),pbe={isVisible:!1,mainSizes:[...l2],terminals:[],nextTerminalIndex:0},mbe=35;function gbe(e,t){return!Number.isFinite(e)||e<=0||!Number.isFinite(t)||t<=0?0:e*(t/100)}function vbe(e,t){const n=gbe(e,t);return n>=0&&n<mbe}const f0=350,bbe=[.4,0,.2,1],ybe=8,CD=1e-6;function xbe(e,t,n){const r=1-e;return 3*r*r*e*t+3*r*e*e*n+e*e*e}function _be(e,t,n){const r=1-e;return 3*r*r*e*t+3*r*e*e*n+e*e*e}function wbe(e,t,n){const r=1-e;return 3*r*r*t+6*r*e*(n-t)+3*e*e*(1-n)}function Sbe(e,t,n){let r=e;for(let i=0;i<ybe;i+=1){const s=xbe(r,t,n)-e;if(Math.abs(s)<CD)return r;const o=wbe(r,t,n);if(Math.abs(o)<CD)break;r-=s/o}return r}function Cbe(e){if(e<=0)return 0;if(e>=1)return 1;const[t,n,r,i]=bbe,s=Sbe(e,t,r);return _be(s,n,i)}function rF(e,t,n){const r=Cbe(n);return[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r]}function kbe({projectId:e,shouldRenderRightSidebarLayout:t,showRightSidebar:n,rightSidebarSize:r}){const i=v.useRef(null),s=v.useRef(null),o=v.useRef(null),l=v.useRef(null),c=v.useRef(null),u=v.useRef(!1),p=v.useRef(null),h=v.useRef(!1),g=v.useRef(!1);return v.useEffect(()=>()=>{l.current!==null&&window.cancelAnimationFrame(l.current),c.current!==null&&window.clearTimeout(c.current)},[]),v.useLayoutEffect(()=>{var M,D,U,j,P,z;if(!t){l.current!==null&&(window.cancelAnimationFrame(l.current),l.current=null),c.current!==null&&(window.clearTimeout(c.current),c.current=null),u.current=!1;return}const b=i.current;if(!b)return;l.current!==null&&(window.cancelAnimationFrame(l.current),l.current=null),c.current!==null&&(window.clearTimeout(c.current),c.current=null);const x=p.current,_=x!==null&&x!==e,w=n&&!g.current,C=!h.current,E=n?[100-r,r]:[100,0],k=_||C&&n,R=w||C?[100,0]:[b.getLayout().workspace??E[0],b.getLayout().rightSidebar??E[1]];if(p.current=e,h.current=t,g.current=n,k||Math.abs(R[0]-E[0])<.1&&Math.abs(R[1]-E[1])<.1){b.setLayout({workspace:E[0],rightSidebar:E[1]}),(M=s.current)==null||M.setAttribute("data-right-sidebar-open",n?"true":"false"),(D=o.current)==null||D.setAttribute("data-right-sidebar-open",n?"true":"false"),(U=o.current)==null||U.setAttribute("data-right-sidebar-animated","false");return}u.current=!0,(j=s.current)==null||j.setAttribute("data-right-sidebar-open",n?"true":"false"),(P=o.current)==null||P.setAttribute("data-right-sidebar-open",n?"true":"false"),(z=o.current)==null||z.setAttribute("data-right-sidebar-animated","true"),b.setLayout({workspace:R[0],rightSidebar:R[1]});const N=performance.now(),A=O=>{const $=Math.min(1,(O-N)/f0),V=rF(R,E,$);if(b.setLayout({workspace:V[0],rightSidebar:V[1]}),$<1){l.current=window.requestAnimationFrame(A);return}b.setLayout({workspace:E[0],rightSidebar:E[1]}),l.current=null,c.current=window.setTimeout(()=>{u.current=!1,c.current=null},0)};l.current=window.requestAnimationFrame(A)},[e,r,t,n]),v.useEffect(()=>{t||(h.current=!1,g.current=!1)},[t]),{isAnimating:u,panelGroupRef:i,sidebarPanelRef:s,sidebarVisualRef:o}}function Ebe(e){return e.visibilityState==="visible"?e.activeChatId:null}function Tbe(e){e.socket.setFocusedChat(Ebe({activeChatId:e.activeChatId,visibilityState:e.visibilityState}))}function Rbe({socket:e,activeChatId:t}){v.useEffect(()=>{if(typeof document>"u")return;const n=()=>{Tbe({socket:e,activeChatId:t,visibilityState:document.visibilityState})};return n(),document.addEventListener("visibilitychange",n),window.addEventListener("pagehide",n),window.addEventListener("pageshow",n),()=>{document.removeEventListener("visibilitychange",n),window.removeEventListener("pagehide",n),window.removeEventListener("pageshow",n),e.setFocusedChat(null)}},[e,t])}function Nbe({rootRef:e,fallbackRef:t,enabled:n,canCancel:r}){v.useEffect(()=>{if(!n)return;let i=0,s=null;const o=h=>{const g=h instanceof Element?h:null,b=e.current,x=t.current;if(uM({trigger:"pointer",activeElement:document.activeElement,pointerStartTarget:s,pointerEndTarget:g,root:b,fallback:x,hasActiveOverlay:cM(document),hasActiveSelection:MY(window.getSelection())})!=="restore"){s=null;return}x==null||x.focus({preventScroll:!0}),s=null},l=h=>{cancelAnimationFrame(i),s=h.target instanceof Element?h.target:null},c=h=>{cancelAnimationFrame(i),i=window.requestAnimationFrame(()=>{o(h.target)})},u=()=>{s=null;const h=t.current;!h||h.disabled||h.focus({preventScroll:!0})},p=h=>{if(h.key!=="Escape")return;const g=t.current;uM({trigger:"escape",activeElement:document.activeElement,fallback:g,hasActiveOverlay:cM(document),canCancel:r,defaultPrevented:h.defaultPrevented})==="escape-focus"&&(h.preventDefault(),g==null||g.focus({preventScroll:!0}))};return window.addEventListener("pointerdown",l,!0),window.addEventListener("pointerup",c,!0),window.addEventListener("keydown",p,!0),window.addEventListener(mb,u),()=>{cancelAnimationFrame(i),window.removeEventListener("pointerdown",l,!0),window.removeEventListener("pointerup",c,!0),window.removeEventListener("keydown",p,!0),window.removeEventListener(mb,u)}},[r,n,t,e])}function Abe(e){const t=e.previousProjectId!==null&&e.previousProjectId!==e.projectId,n=e.previousProjectId===null&&e.projectId!==null;return!t&&!n&&e.showTerminalPane&&!e.wasTerminalVisible}function Mbe({previousProjectId:e,projectId:t,previousShouldRenderTerminalLayout:n,previousShowTerminalPane:r,showTerminalPane:i,terminalLayout:s,liveLayout:o}){const l=e!==null&&e!==t,c=i&&!r,u=!n,p=e===null&&t!==null,h=i?s.mainSizes:[100,0];return{currentLayout:c||u?[100,0]:o,shouldSkipAnimation:l||p&&u,targetLayout:h}}function Lbe({chatInputRef:e,projectId:t,shouldRenderTerminalLayout:n,showTerminalPane:r,terminalLayout:i}){const s=v.useRef(null),o=v.useRef(null),l=v.useRef(null),c=v.useRef(null),u=v.useRef(null),p=v.useRef(!1),h=v.useRef(null),g=v.useRef(!1),b=v.useRef(!1),x=v.useRef(!1),[_,w]=v.useState(0);return v.useEffect(()=>{var k;const C=h.current,E=x.current;Abe({previousProjectId:C,projectId:t,showTerminalPane:r,wasTerminalVisible:E})&&w(R=>R+1),C!==null&&C===t&&!r&&E&&((k=e.current)==null||k.focus({preventScroll:!0})),x.current=r,h.current=t},[e,t,r]),v.useEffect(()=>()=>{c.current!==null&&window.cancelAnimationFrame(c.current),u.current!==null&&window.clearTimeout(u.current)},[]),v.useLayoutEffect(()=>{var D,U,j,P,z,O;if(!n){c.current!==null&&(window.cancelAnimationFrame(c.current),c.current=null),u.current!==null&&(window.clearTimeout(u.current),u.current=null),p.current=!1;return}const C=s.current;if(!C)return;c.current!==null&&(window.cancelAnimationFrame(c.current),c.current=null),u.current!==null&&(window.clearTimeout(u.current),u.current=null);const E=h.current,{currentLayout:k,shouldSkipAnimation:R,targetLayout:N}=Mbe({previousProjectId:E,projectId:t,previousShouldRenderTerminalLayout:g.current,previousShowTerminalPane:b.current,showTerminalPane:r,terminalLayout:i,liveLayout:[C.getLayout().chat??i.mainSizes[0],C.getLayout().terminal??i.mainSizes[1]]});if(g.current=n,b.current=r,R||Math.abs(k[0]-N[0])<.1&&Math.abs(k[1]-N[1])<.1){C.setLayout({chat:N[0],terminal:N[1]}),(D=o.current)==null||D.setAttribute("data-terminal-open",r?"true":"false"),(U=l.current)==null||U.setAttribute("data-terminal-open",r?"true":"false"),(j=l.current)==null||j.setAttribute("data-terminal-animated","false");return}p.current=!0,(P=o.current)==null||P.setAttribute("data-terminal-open",r?"true":"false"),(z=l.current)==null||z.setAttribute("data-terminal-open",r?"true":"false"),(O=l.current)==null||O.setAttribute("data-terminal-animated","true"),C.setLayout({chat:k[0],terminal:k[1]});const A=performance.now(),M=$=>{const V=Math.min(1,($-A)/f0),B=rF(k,N,V);if(C.setLayout({chat:B[0],terminal:B[1]}),V<1){c.current=window.requestAnimationFrame(M);return}C.setLayout({chat:N[0],terminal:N[1]}),c.current=null,u.current=window.setTimeout(()=>{p.current=!1,u.current=null},0)};c.current=window.requestAnimationFrame(M)},[t,n,r,i]),v.useEffect(()=>{n||(g.current=!1,b.current=!1)},[n]),{isAnimating:p,mainPanelGroupRef:s,terminalFocusRequestVersion:_,terminalPanelRef:o,terminalVisualRef:l}}const kD=e=>Symbol.iterator in e,ED=e=>"entries"in e,TD=(e,t)=>{const n=e instanceof Map?e:new Map(e.entries()),r=t instanceof Map?t:new Map(t.entries());if(n.size!==r.size)return!1;for(const[i,s]of n)if(!r.has(i)||!Object.is(s,r.get(i)))return!1;return!0},jbe=(e,t)=>{const n=e[Symbol.iterator](),r=t[Symbol.iterator]();let i=n.next(),s=r.next();for(;!i.done&&!s.done;){if(!Object.is(i.value,s.value))return!1;i=n.next(),s=r.next()}return!!i.done&&!!s.done};function Dbe(e,t){return Object.is(e,t)?!0:typeof e!="object"||e===null||typeof t!="object"||t===null||Object.getPrototypeOf(e)!==Object.getPrototypeOf(t)?!1:kD(e)&&kD(t)?ED(e)&&ED(t)?TD(e,t):jbe(e,t):TD({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function RD(e){const t=_n.useRef(void 0);return n=>{const r=e(n);return Dbe(t.current,r)?t.current:t.current=r}}const Qh="__new__";function gc(e){var s,o;const t=(s=e==null?void 0:e.modelOptions)==null?void 0:s.reasoningEffort,n=GM(t)?t:GM(e==null?void 0:e.effort)?e.effort:pp.reasoningEffort,r=Qte(e==null?void 0:e.model),i=Zk(r,(o=e==null?void 0:e.modelOptions)==null?void 0:o.contextWindow);return{model:r,modelOptions:{reasoningEffort:!P4(r)&&n==="max"?"high":n,contextWindow:i},planMode:!!(e!=null&&e.planMode)}}function gv(e){var n,r;const t=(n=e==null?void 0:e.modelOptions)==null?void 0:n.reasoningEffort;return{model:Zte(e==null?void 0:e.model),modelOptions:{reasoningEffort:qM(t)?t:qM(e==null?void 0:e.effort)?e.effort:GS.reasoningEffort,fastMode:typeof((r=e==null?void 0:e.modelOptions)==null?void 0:r.fastMode)=="boolean"?e.modelOptions.fastMode:GS.fastMode},planMode:!!(e!=null&&e.planMode)}}function Ibe(){return{claude:{model:"claude-opus-4-7",modelOptions:{...pp},planMode:!1},codex:{model:"gpt-5.5",modelOptions:{...GS},planMode:!1}}}function Pbe(e,t){return e.reasoningEffort===t.reasoningEffort&&e.contextWindow===t.contextWindow}function Obe(e,t){return e.reasoningEffort===t.reasoningEffort&&e.fastMode===t.fastMode}function zbe(e,t){return e.claude.model===t.claude.model&&e.claude.planMode===t.claude.planMode&&Pbe(e.claude.modelOptions,t.claude.modelOptions)&&e.codex.model===t.codex.model&&e.codex.planMode===t.codex.planMode&&Obe(e.codex.modelOptions,t.codex.modelOptions)}function Bbe(e,t){if(t===void 0){console.info(`[chat-preferences] ${e}`);return}console.info(`[chat-preferences] ${e}`,t)}function Zh(e,t){if(e==="claude"){const r=t.claude;return{provider:"claude",model:r.model,modelOptions:{...r.modelOptions},planMode:r.planMode}}const n=t.codex;return{provider:"codex",model:n.model,modelOptions:{...n.modelOptions},planMode:n.planMode}}function V1(e){return e.provider==="claude"?{provider:"claude",model:e.model,modelOptions:{...e.modelOptions},planMode:e.planMode}:{provider:"codex",model:e.model,modelOptions:{...e.modelOptions},planMode:e.planMode}}function iF(e){return e.providerHint?Zh(e.providerHint,e.providerDefaults):e.defaultProvider==="last_used"?e.sourceState?V1(e.sourceState):Zh("claude",e.providerDefaults):Zh(e.defaultProvider,e.providerDefaults)}function sF(e,t){const n=e.chatStates[t];return n||iF({defaultProvider:e.defaultProvider,providerDefaults:e.providerDefaults,legacyComposerState:e.legacyComposerState})}function vv(e,t,n){const r=sF(e,t);return{chatStates:{...e.chatStates,[t]:n(r)}}}const gi=oo()(lf((e,t)=>({defaultProvider:"last_used",providerDefaults:Ibe(),chatStates:{},legacyComposerState:{provider:"claude",model:"claude-opus-4-7",modelOptions:{...pp},planMode:!1},setDefaultProvider:n=>e({defaultProvider:n}),applyServerDefaults:(n,r)=>e(i=>{if(i.defaultProvider===n&&zbe(i.providerDefaults,r))return{defaultProvider:n,providerDefaults:r};const{[Qh]:o,...l}=i.chatStates;return{defaultProvider:n,providerDefaults:r,chatStates:l}}),setProviderDefaultModel:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:n==="claude"?gc({...i.providerDefaults.claude,model:r}):gv({...i.providerDefaults.codex,model:r})}})),setProviderDefaultModelOptions:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:n==="claude"?gc({...i.providerDefaults.claude,modelOptions:{...i.providerDefaults.claude.modelOptions,...r}}):gv({...i.providerDefaults.codex,modelOptions:{...i.providerDefaults.codex.modelOptions,...r}})}})),setProviderDefaultPlanMode:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:{...i.providerDefaults[n],planMode:r}}})),getComposerState:n=>V1(sF(t(),n)),initializeComposerForChat:(n,r)=>e(i=>{if(i.chatStates[n])return i;const s=iF({defaultProvider:i.defaultProvider,providerDefaults:i.providerDefaults,sourceState:r==null?void 0:r.sourceState,legacyComposerState:i.legacyComposerState,providerHint:r==null?void 0:r.providerHint});return Bbe("initializeComposerForChat",{chatId:n,composerState:s}),{chatStates:{...i.chatStates,[n]:s}}}),setComposerState:(n,r)=>e(i=>({chatStates:{...i.chatStates,[n]:r.provider==="claude"?{provider:"claude",model:gc(r).model,modelOptions:gc(r).modelOptions,planMode:r.planMode}:V1(r)}})),setChatComposerProvider:(n,r)=>e(i=>vv(i,n,()=>Zh(r,i.providerDefaults))),setChatComposerModel:(n,r)=>e(i=>vv(i,n,s=>s.provider==="claude"?{provider:"claude",model:gc({...s,model:r}).model,modelOptions:gc({...s,model:r}).modelOptions,planMode:s.planMode}:{provider:"codex",model:r,modelOptions:gv({...s,model:r}).modelOptions,planMode:s.planMode})),setChatComposerModelOptions:(n,r)=>e(i=>vv(i,n,s=>s.provider==="claude"?{provider:"claude",model:s.model,modelOptions:gc({...s,modelOptions:{...s.modelOptions,...r}}).modelOptions,planMode:s.planMode}:{provider:"codex",model:s.model,modelOptions:gv({...s,modelOptions:{...s.modelOptions,...r}}).modelOptions,planMode:s.planMode})),setChatComposerPlanMode:(n,r)=>e(i=>vv(i,n,s=>({...s,planMode:r}))),resetChatComposerFromProvider:(n,r)=>e(i=>({chatStates:{...i.chatStates,[n]:Zh(r,i.providerDefaults)}}))}),{name:"chat-preferences-state",version:1,partialize:e=>({chatStates:e.chatStates,legacyComposerState:e.legacyComposerState})})),W1=oo()(lf((e,t)=>({drafts:{},attachmentDrafts:{},setDraft:(n,r)=>e(i=>{if(!r){const{[n]:s,...o}=i.drafts;return{drafts:o}}return{drafts:{...i.drafts,[n]:r}}}),clearDraft:n=>e(r=>{const{[n]:i,...s}=r.drafts;return{drafts:s}}),getDraft:n=>t().drafts[n]??"",setAttachmentDrafts:(n,r)=>e(i=>{if(r.length===0){const{[n]:s,...o}=i.attachmentDrafts;return{attachmentDrafts:o}}return{attachmentDrafts:{...i.attachmentDrafts,[n]:r}}}),clearAttachmentDrafts:n=>e(r=>{const{[n]:i,...s}=r.attachmentDrafts;return{attachmentDrafts:s}}),getAttachmentDrafts:n=>t().attachmentDrafts[n]??[]}),{name:"chat-input-drafts"})),c2=oo()(e=>({byChatId:{},loadingByChatId:{},setForChat:(t,n)=>e(r=>({byChatId:{...r.byChatId,[t]:n}})),setLoadingForChat:(t,n)=>e(r=>(r.loadingByChatId[t]??!1)===n?r:{loadingByChatId:{...r.loadingByChatId,[t]:n}}),clear:t=>e(n=>{const r=t in n.byChatId,i=t in n.loadingByChatId;if(!r&&!i)return n;const{[t]:s,...o}=n.byChatId,{[t]:l,...c}=n.loadingByChatId;return{byChatId:o,loadingByChatId:c}})}));function Fbe(e){return{autoResumeOnRateLimit:!!(e!=null&&e.autoResumeOnRateLimit)}}const G1=oo()(lf(e=>({autoResumeOnRateLimit:!1,setAutoResumeOnRateLimit:t=>e({autoResumeOnRateLimit:t})}),{name:"kanna-preferences",version:1,migrate:e=>Fbe(e)}));function $be(e,t){var n,r,i,s,o,l,c,u,p;return{...e,...t,terminal:{...e.terminal,...t.terminal},editor:{...e.editor,...t.editor},providerDefaults:{claude:{...e.providerDefaults.claude,...(n=t.providerDefaults)==null?void 0:n.claude,modelOptions:{...e.providerDefaults.claude.modelOptions,...(i=(r=t.providerDefaults)==null?void 0:r.claude)==null?void 0:i.modelOptions}},codex:{...e.providerDefaults.codex,...(s=t.providerDefaults)==null?void 0:s.codex,modelOptions:{...e.providerDefaults.codex.modelOptions,...(l=(o=t.providerDefaults)==null?void 0:o.codex)==null?void 0:l.modelOptions}}},cloudflareTunnel:{...e.cloudflareTunnel,...t.cloudflareTunnel},claudeAuth:{tokens:((c=t.claudeAuth)==null?void 0:c.tokens)??e.claudeAuth.tokens},auth:{...e.auth,...t.auth},uploads:{...e.uploads,...t.uploads},subagents:e.subagents,claudeDriver:{preference:((u=t.claudeDriver)==null?void 0:u.preference)??e.claudeDriver.preference,lifecycle:{...e.claudeDriver.lifecycle,...(p=t.claudeDriver)==null?void 0:p.lifecycle}}}}const Ks=oo()(e=>({settings:null,hydrationStatus:"idle",setHydrationStatus:t=>e({hydrationStatus:t}),setFromServer:t=>e({settings:t,hydrationStatus:"ready"}),applyOptimisticPatch:t=>e(n=>({settings:n.settings?$be(n.settings,t):n.settings}))})),oF=v.createContext(void 0),Hbe=e=>e==="light"||e==="dark"||e==="system";function Ube(e){return e==="dark"?"black-translucent":"default"}function ND(e,t){if(typeof document>"u")return;let n=document.head.querySelector(`meta[name="${e}"]`);n||(n=document.createElement("meta"),n.setAttribute("name",e),document.head.appendChild(n)),n.setAttribute("content",t)}function AD(e){if(typeof document>"u"||typeof window>"u")return;const t=getComputedStyle(document.body).backgroundColor||getComputedStyle(document.documentElement).backgroundColor;t&&ND("theme-color",t),ND("apple-mobile-web-app-status-bar-style",Ube(e)),document.documentElement.style.colorScheme=e}const Zv=()=>typeof window>"u"?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",MD=e=>{if(typeof document>"u")return;const t=e==="system"?Zv():e;document.documentElement.classList.toggle("dark",t==="dark")},Vbe=()=>{var t;const e=(t=Ks.getState().settings)==null?void 0:t.theme;return e&&Hbe(e)?e:"system"};function Wbe({children:e}){const t=Ks(o=>{var l;return(l=o.settings)==null?void 0:l.theme}),n=Ks(o=>o.applyOptimisticPatch),[r,i]=v.useState(Vbe);v.useEffect(()=>{!t||t===r||i(t)},[t,r]),v.useEffect(()=>{MD(r)},[r]),v.useEffect(()=>{const o=r==="system"?Zv():r;AD(o)},[r]),v.useEffect(()=>{if(r!=="system")return;const o=window.matchMedia("(prefers-color-scheme: dark)"),l=()=>{MD("system"),AD(Zv())};return o.addEventListener?(o.addEventListener("change",l),()=>o.removeEventListener("change",l)):(o.addListener(l),()=>o.removeListener(l))},[r]);const s=v.useMemo(()=>{const o=r==="system"?Zv():r;return{theme:r,resolvedTheme:o,setTheme:l=>{i(l),n({theme:l})}}},[n,r]);return f.jsx(oF.Provider,{value:s,children:e})}function u2(){const e=v.useContext(oF);if(!e)throw new Error("useTheme must be used within ThemeProvider");return e}function Zu(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function LD(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}function Gbe(e){const t=e&&typeof e=="object"&&"content"in e&&Array.isArray(e.content)?e.content:Array.isArray(e)?e:[],n=[];for(const r of t)if(!(!r||typeof r!="object"||!("type"in r))){if(r.type==="text"&&typeof r.text=="string"){n.push({type:"text",text:r.text});continue}if(r.type==="image"){if("data"in r&&typeof r.data=="string"){n.push({type:"image",data:r.data,mimeType:typeof r.mimeType=="string"?r.mimeType:void 0});continue}"source"in r&&r.source&&typeof r.source=="object"&&"type"in r.source&&r.source.type==="base64"&&"data"in r.source&&typeof r.source.data=="string"&&n.push({type:"image",data:r.source.data,mimeType:typeof r.source.media_type=="string"?r.source.media_type:void 0})}}return n}function qbe(e){const t=e&&typeof e=="object"&&"content"in e&&Array.isArray(e.content)?e.content:Array.isArray(e)?e:null;if(!t)return null;const n=[];for(const r of t)r&&typeof r=="object"&&"type"in r&&r.type==="text"&&typeof r.text=="string"&&n.push(r.text);return n.length>0?n.join(""):null}function Kbe(e,t){const n=LD(t);switch(e.toolKind){case"ask_user_question":{const s=Zu(n),o=Zu(s==null?void 0:s.answers)??(s||{});return{answers:Object.fromEntries(Object.entries(o).map(([l,c])=>Array.isArray(c)?[l,c.map(u=>String(u))]:c&&typeof c=="object"&&Array.isArray(c.answers)?[l,c.answers.map(u=>String(u))]:c==null||c===""?[l,[]]:[l,[String(c)]])),...(s==null?void 0:s.discarded)===!0?{discarded:!0}:{}}}case"exit_plan_mode":{const s=Zu(n);return{confirmed:typeof(s==null?void 0:s.confirmed)=="boolean"?s.confirmed:void 0,clearContext:typeof(s==null?void 0:s.clearContext)=="boolean"?s.clearContext:void 0,message:typeof(s==null?void 0:s.message)=="string"?s.message:void 0,...(s==null?void 0:s.discarded)===!0?{discarded:!0}:{}}}case"offer_download":{const s=qbe(n),o=s?LD(s):n,l=Zu(o);return{contentUrl:typeof(l==null?void 0:l.contentUrl)=="string"?l.contentUrl:"",relativePath:typeof(l==null?void 0:l.relativePath)=="string"?l.relativePath:"",fileName:typeof(l==null?void 0:l.fileName)=="string"?l.fileName:"",displayName:typeof(l==null?void 0:l.displayName)=="string"?l.displayName:typeof(l==null?void 0:l.fileName)=="string"?l.fileName:"",size:typeof(l==null?void 0:l.size)=="number"?l.size:0,...typeof(l==null?void 0:l.mimeType)=="string"?{mimeType:l.mimeType}:{}}}case"image_generation":{const s=Zu(n);return{contentUrl:typeof(s==null?void 0:s.contentUrl)=="string"?s.contentUrl:"",relativePath:typeof(s==null?void 0:s.relativePath)=="string"?s.relativePath:"",fileName:typeof(s==null?void 0:s.fileName)=="string"?s.fileName:""}}case"read_file":if(typeof n=="string")return n;const r=Gbe(n);if(r.length>0)return{content:r.flatMap(s=>s.type==="text"?[s.text]:[]).join(""),blocks:r};const i=Zu(n);return{content:typeof(i==null?void 0:i.content)=="string"?i.content:JSON.stringify(n,null,2)};default:return n}}function aF(e){return new Date(e).toISOString()}function Ni(e){return{id:e._id,messageId:e.messageId,timestamp:aF(e.createdAt),hidden:e.hidden}}function Ybe(e){return{id:e._id,messageId:e.messageId,hidden:e.hidden,kind:"tool",toolKind:e.tool.toolKind,toolName:e.tool.toolName,toolId:e.tool.toolId,input:e.tool.input,timestamp:aF(e.createdAt)}}function Xbe(e){if(e.debugRaw)try{return JSON.parse(e.debugRaw).tool_use_result}catch{return}}function lF(e){const t=new Map,n=[];for(const r of e)switch(r.kind){case"user_prompt":n.push({...Ni(r),kind:"user_prompt",content:r.content,attachments:r.attachments??[],steered:r.steered,autoContinue:r.autoContinue});break;case"system_init":n.push({...Ni(r),kind:"system_init",provider:r.provider,model:r.model,tools:r.tools,agents:r.agents,slashCommands:r.slashCommands,mcpServers:r.mcpServers,debugRaw:r.debugRaw});break;case"account_info":n.push({...Ni(r),kind:"account_info",accountInfo:r.accountInfo});break;case"assistant_text":n.push({...Ni(r),kind:"assistant_text",text:r.text});break;case"tool_call":{const i=Ybe(r);t.set(r.tool.toolId,{hydrated:i,normalized:r.tool}),n.push(i);break}case"tool_result":{const i=t.get(r.toolId);if(i){const s=i.normalized.toolKind==="ask_user_question"||i.normalized.toolKind==="exit_plan_mode"?Xbe(r)??r.content:r.content;i.hydrated.result=Kbe(i.normalized,s),i.hydrated.rawResult=s,i.hydrated.isError=r.isError,r.persisted&&(i.hydrated.persisted=r.persisted)}break}case"result":n.push({...Ni(r),kind:"result",success:!r.isError,cancelled:r.subtype==="cancelled",result:r.result,durationMs:r.durationMs,costUsd:r.costUsd});break;case"status":n.push({...Ni(r),kind:"status",status:r.status});break;case"context_window_updated":n.push({...Ni(r),kind:"context_window_updated",usage:r.usage});break;case"compact_boundary":n.push({...Ni(r),kind:"compact_boundary"});break;case"compact_summary":n.push({...Ni(r),kind:"compact_summary",summary:r.summary});break;case"context_cleared":n.push({...Ni(r),kind:"context_cleared"});break;case"interrupted":n.push({...Ni(r),kind:"interrupted"});break;case"auto_continue_prompt":n.push({...Ni(r),kind:"auto_continue_prompt",scheduleId:r.scheduleId});break;case"pending_tool_request":n.push({...Ni(r),kind:"pending_tool_request",toolRequestId:r.toolRequestId,toolName:r.toolName,arguments:r.arguments});break;case"tool_request_resolved":break;default:n.push({...Ni(r),kind:"unknown",json:JSON.stringify(r,null,2)});break}return n}const Qbe=["AskUserQuestion","ExitPlanMode","TodoWrite"],Zbe=new Set(["TodoWrite"]);function Jbe(e,t){for(let n=e.length-1;n>=0;n-=1){const r=e[n];if(r.kind!=="tool")continue;const i=r;if(i.toolName===t&&!i.result)return i.id}return null}function eye(e,t){for(let n=e.length-1;n>=0;n-=1){const r=e[n];if(r.kind!=="tool")continue;const i=r;if(i.toolName===t)return i.id}return null}function tye(e){const t={};for(const n of Qbe)t[n]=Zbe.has(n)?eye(e,n):Jbe(e,n);return t}function nye(e){return e==="starting"||e==="running"||e==="waiting_for_user"}function rye(e){return e==="starting"||e==="running"||e==="waiting_for_user"}const d2="pushDeviceId";function cF(){return typeof localStorage>"u"?null:localStorage.getItem(d2)}function iye(e){typeof localStorage>"u"||localStorage.setItem(d2,e)}function sye(){typeof localStorage>"u"||localStorage.removeItem(d2)}function oye(){return!(typeof window>"u"||typeof Notification>"u"||!("serviceWorker"in navigator)||typeof globalThis.PushManager>"u")}function aye(){var t;if(typeof window>"u")return!1;if(window.isSecureContext)return!0;const e=((t=window.location)==null?void 0:t.hostname)??"";return e==="localhost"||e==="127.0.0.1"||e==="::1"}function q1(){if(!oye())return{state:"unsupported"};if(!aye())return{state:"insecure-context"};switch(Notification.permission){case"granted":return{state:"granted"};case"denied":return{state:"denied"};default:return{state:"default"}}}function lye(e){if(typeof Buffer<"u")return new Uint8Array(Buffer.from(e,"base64url"));const t="=".repeat((4-e.length%4)%4),n=(e+t).replace(/-/g,"+").replace(/_/g,"/"),r=atob(n),i=new Uint8Array(r.length);for(let s=0;s<r.length;s+=1)i[s]=r.charCodeAt(s);return i}function cye(e){const t=e||"";return/iPhone|iPad/i.test(t)?"iPhone / iPad":/Android/i.test(t)?"Android":/Macintosh/i.test(t)?"Mac":/Windows/i.test(t)?"Windows PC":t||"Browser"}async function uye(e){const t=q1();if(t.state==="unsupported")throw new Error("Push not supported in this browser");if(t.state==="insecure-context")throw new Error("Push requires a secure context (HTTPS)");if(t.state==="denied")throw new Error("Notification permission previously denied");if(await Notification.requestPermission()!=="granted")throw new Error("Notification permission was not granted");const r=await navigator.serviceWorker.register("/sw.js");await navigator.serviceWorker.ready;const i=await r.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:lye(e.vapidPublicKey)}),s=i.toJSON(),o=s.endpoint??i.endpoint,l=s.keys??{};if(!o||!l.p256dh||!l.auth)throw new Error("Subscription returned without endpoint or keys");const c=navigator.userAgent??"",{id:u}=await e.sendToServer({subscription:{endpoint:o,keys:{p256dh:l.p256dh,auth:l.auth}},label:cye(c),userAgent:c});return u}async function dye(e){const n=await(await navigator.serviceWorker.ready).pushManager.getSubscription();n&&await n.unsubscribe(),await e.sendToServer(e.pushDeviceId)}typeof navigator<"u"&&"serviceWorker"in navigator&&navigator.serviceWorker.addEventListener("message",e=>{const t=e.data;(t==null?void 0:t.type)==="kanna.navigate"&&typeof t.url=="string"&&(window.location.href=t.url)});const fye=25e3,hye=15e3,pye=4e3,jD="kanna:profile-send-to-starting";function DD(){try{return window.sessionStorage.getItem(jD)==="1"||window.localStorage.getItem(jD)==="1"}catch{return!1}}class mye{constructor(t){ne(this,"url");ne(this,"ws",null);ne(this,"started",!1);ne(this,"reconnectTimer",null);ne(this,"reconnectDelayMs",750);ne(this,"subscriptions",new Map);ne(this,"pending",new Map);ne(this,"outboundQueue",[]);ne(this,"statusListeners",new Set);ne(this,"heartbeatTimer",null);ne(this,"pingTimeoutTimer",null);ne(this,"pingPromise",null);ne(this,"lastOpenAt",0);ne(this,"lastMessageAt",0);ne(this,"reconnectImmediatelyOnClose",!1);ne(this,"handleWindowFocus",()=>{this.ensureHealthyConnection()});ne(this,"handleVisibilityChange",()=>{if(document.visibilityState==="visible"){this.startHeartbeat(),this.ensureHealthyConnection();return}this.stopHeartbeat()});ne(this,"handleOnline",()=>{this.ensureHealthyConnection()});this.url=t}start(){this.started||(this.started=!0,window.addEventListener("focus",this.handleWindowFocus),window.addEventListener("online",this.handleOnline),document.addEventListener("visibilitychange",this.handleVisibilityChange),this.connect())}dispose(){var t;this.started=!1,this.reconnectTimer&&(window.clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.stopHeartbeat(),this.clearPingState(),window.removeEventListener("focus",this.handleWindowFocus),window.removeEventListener("online",this.handleOnline),document.removeEventListener("visibilitychange",this.handleVisibilityChange),(t=this.ws)==null||t.close(),this.ws=null;for(const n of this.pending.values())n.reject(new Error("Socket disposed"));this.pending.clear()}onStatus(t){return this.statusListeners.add(t),t(this.getStatus()),()=>{this.statusListeners.delete(t)}}subscribe(t,n,r){const i=_c();return this.subscriptions.set(i,{topic:t,listener:n,eventListener:r}),this.enqueue({v:1,type:"subscribe",id:i,topic:t}),()=>{this.subscriptions.delete(i),this.enqueue({v:1,type:"unsubscribe",id:i})}}subscribeTerminal(t,n){const r=_c(),i={type:"terminal",terminalId:t};return this.subscriptions.set(r,{topic:i,listener:n.onSnapshot,eventListener:n.onEvent}),this.enqueue({v:1,type:"subscribe",id:r,topic:i}),()=>{this.subscriptions.delete(r),this.enqueue({v:1,type:"unsubscribe",id:r})}}command(t){const n=_c(),r={v:1,type:"command",id:n,command:t};return new Promise((i,s)=>{this.pending.set(n,{resolve:i,reject:s}),this.enqueue(r)})}setFocusedChat(t){const n=_c();this.enqueue({v:1,type:"command",id:n,command:{type:"push.setFocusedChat",chatId:t}})}ensureHealthyConnection(){return!this.ws||this.ws.readyState===WebSocket.CLOSED||this.ws.readyState===WebSocket.CLOSING?(this.reconnectNow(),Promise.resolve()):this.ws.readyState===WebSocket.CONNECTING||!this.isConnectionStale()?Promise.resolve():this.sendPing()}connect(){this.started&&(this.emitStatus("connecting"),this.ws=new WebSocket(this.url),this.ws.addEventListener("open",()=>{this.reconnectDelayMs=750,this.reconnectImmediatelyOnClose=!1,this.lastOpenAt=Date.now(),this.lastMessageAt=this.lastOpenAt,this.emitStatus("connected"),this.startHeartbeat();for(const[n,r]of this.subscriptions.entries())this.sendNow({v:1,type:"subscribe",id:n,topic:r.topic});for(;this.outboundQueue.length>0;){const n=this.outboundQueue.shift();n&&this.sendNow(n)}const t=cF();t&&this.sendNow({v:1,type:"command",id:_c(),command:{type:"push.identifyDevice",pushDeviceId:t}})}),this.ws.addEventListener("message",t=>{var s,o;this.lastMessageAt=Date.now();const n=performance.now(),r=String(t.data);let i;try{i=JSON.parse(r)}catch{return}if(DD()&&i.type==="snapshot"&&i.snapshot.type==="chat"&&((s=i.snapshot.data)==null?void 0:s.runtime.status)==="starting"&&console.debug("[kanna/send->starting][client-ws]",{stage:"socket_message_received",receivedAt:n,payloadBytes:r.length,chatId:i.snapshot.data.runtime.chatId,status:i.snapshot.data.runtime.status,messageCount:i.snapshot.data.messages.length}),DD()&&i.type==="ack"&&console.debug("[kanna/send->starting][client-ws]",{stage:"socket_ack_received",receivedAt:n,payloadBytes:r.length,commandId:i.id}),i.type==="snapshot"){const l=this.subscriptions.get(i.id);l==null||l.listener(i.snapshot.data);return}if(i.type==="event"){const l=this.subscriptions.get(i.id);(o=l==null?void 0:l.eventListener)==null||o.call(l,i.event);return}if(i.type==="ack"){const l=this.pending.get(i.id);if(!l)return;this.pending.delete(i.id),l.resolve(i.result);return}if(i.type==="error"){if(!i.id){console.error(jQ,i.message);return}const l=this.pending.get(i.id);if(!l)return;this.pending.delete(i.id),l.reject(new Error(i.message))}}),this.ws.addEventListener("close",()=>{if(!this.started)return;const t=this.reconnectImmediatelyOnClose;this.reconnectImmediatelyOnClose=!1,this.stopHeartbeat(),this.clearPingState(),this.emitStatus("disconnected");for(const n of this.pending.values())n.reject(new Error("Disconnected"));if(this.pending.clear(),t){this.connect();return}this.scheduleReconnect()}))}scheduleReconnect(){this.reconnectTimer===null&&(this.reconnectTimer=window.setTimeout(()=>{this.reconnectTimer=null,this.connect(),this.reconnectDelayMs=Math.min(this.reconnectDelayMs*2,5e3)},this.reconnectDelayMs))}getStatus(){var t,n;return((t=this.ws)==null?void 0:t.readyState)===WebSocket.OPEN?"connected":((n=this.ws)==null?void 0:n.readyState)===WebSocket.CONNECTING?"connecting":"disconnected"}emitStatus(t){for(const n of this.statusListeners)n(t)}isConnectionStale(){const t=Math.max(this.lastMessageAt,this.lastOpenAt);return t>0&&Date.now()-t>=fye}sendPing(){if(this.pingPromise)return this.pingPromise;const t=this.command({type:"system.ping"}).then(()=>{this.clearPingState()}).catch(n=>{throw this.clearPingState(),this.reconnectNow(),n});return this.pingTimeoutTimer=window.setTimeout(()=>{this.clearPingState(),this.reconnectNow()},pye),this.pingPromise=t,t}reconnectNow(){if(this.reconnectTimer!==null&&(window.clearTimeout(this.reconnectTimer),this.reconnectTimer=null),!this.ws||this.ws.readyState===WebSocket.CLOSED){this.connect();return}this.ws.readyState!==WebSocket.CONNECTING&&(this.reconnectImmediatelyOnClose=!0,this.ws.close())}startHeartbeat(){document.visibilityState==="visible"&&this.heartbeatTimer===null&&(this.heartbeatTimer=window.setInterval(()=>{var t;if(document.visibilityState!=="visible"){this.stopHeartbeat();return}((t=this.ws)==null?void 0:t.readyState)===WebSocket.OPEN&&this.ensureHealthyConnection()},hye))}stopHeartbeat(){this.heartbeatTimer!==null&&(window.clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}clearPingState(){this.pingTimeoutTimer!==null&&(window.clearTimeout(this.pingTimeoutTimer),this.pingTimeoutTimer=null),this.pingPromise=null}enqueue(t){var n;if(((n=this.ws)==null?void 0:n.readyState)===WebSocket.OPEN){this.sendNow(t);return}this.outboundQueue.push(t)}sendNow(t){var n;(n=this.ws)==null||n.send(JSON.stringify(t))}}async function gye(e){const{toast:t}=await K(async()=>{const{toast:r}=await import("./index-zcdDKOCt.js");return{toast:r}},[]);t(`${e} ${e===1?"process":"processes"} survived restart`,{description:"Review and stop them in Background tasks (⌘⇧B).",action:{label:"Review",onClick:()=>Ys.getState().openDialog()}})}function vye(e,t){const n=new Set([...Object.keys(e),...Object.keys(t)]);for(const r of n)if(e[r]!==t[r])return!1;return!0}function bye(e,t){return e===t?!0:!e||!t?!1:e.chatId===t.chatId&&e.projectId===t.projectId&&e.localPath===t.localPath&&e.title===t.title&&e.status===t.status&&e.isDraining===t.isDraining&&e.provider===t.provider&&e.planMode===t.planMode&&vye(e.sessionTokensByProvider,t.sessionTokensByProvider)}function yye(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>{var i;return n._id===((i=t[r])==null?void 0:i._id)})}function xye(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>{var i;return n.id===((i=t[r])==null?void 0:i.id)})}function _ye(e,t){return e===t?!0:!e||!t?!1:e.hasOlder===t.hasOlder&&e.olderCursor===t.olderCursor&&e.recentLimit===t.recentLimit}function wye(e,t){return e.id===t.id&&e.content===t.content&&e.createdAt===t.createdAt&&e.provider===t.provider&&e.model===t.model&&e.planMode===t.planMode&&JSON.stringify(e.modelOptions)===JSON.stringify(t.modelOptions)&&Sye(e.attachments,t.attachments)}function Sye(e,t){return e===t?!0:e.length!==t.length?!1:e.every((n,r)=>{const i=t[r];return!!i&&n.id===i.id&&n.kind===i.kind&&n.displayName===i.displayName&&n.absolutePath===i.absolutePath&&n.relativePath===i.relativePath&&n.contentUrl===i.contentUrl&&n.mimeType===i.mimeType&&n.size===i.size})}function Cye(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>wye(n,t[r]))}function kye(e,t){var s,o;if(e===t)return!0;if(!e||!t||e.status!==t.status||e.branchName!==t.branchName||e.defaultBranchName!==t.defaultBranchName||e.hasOriginRemote!==t.hasOriginRemote||e.originRepoSlug!==t.originRepoSlug||e.hasUpstream!==t.hasUpstream||e.aheadCount!==t.aheadCount||e.behindCount!==t.behindCount||e.lastFetchedAt!==t.lastFetchedAt)return!1;const n=((s=e.branchHistory)==null?void 0:s.entries)??[],r=((o=t.branchHistory)==null?void 0:o.entries)??[];return n.length!==r.length||!n.every((l,c)=>{const u=r[c];return!!u&&l.sha===u.sha&&l.summary===u.summary&&l.description===u.description&&l.authorName===u.authorName&&l.authoredAt===u.authoredAt&&l.githubUrl===u.githubUrl&&l.tags.length===u.tags.length&&l.tags.every((p,h)=>p===u.tags[h])})||e.files.length!==t.files.length?!1:e.files.every((l,c)=>{const u=t.files[c];return!!u&&l.path===u.path&&l.changeType===u.changeType&&l.isUntracked===u.isUntracked&&l.additions===u.additions&&l.deletions===u.deletions&&l.patchDigest===u.patchDigest&&l.mimeType===u.mimeType&&l.size===u.size})}function Eye(e,t){return!!(e&&e.status!=="unknown"&&t&&t.status==="unknown"&&t.files.length===0)}function Tye(e,t){if(e===t)return!0;if(!e||!t)return!1;const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:n.every(i=>{const s=e[i],o=t[i];return!s||!o?!1:s.state===o.state&&s.scheduledAt===o.scheduledAt&&s.resetAt===o.resetAt&&s.detectedAt===o.detectedAt&&s.tz===o.tz})}function Rye(e,t){if(e===t)return!0;if(!e||!t)return!1;const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:n.every(i=>{const s=e[i],o=t[i];return!s||!o?!1:s.state===o.state&&s.url===o.url&&s.error===o.error&&s.port===o.port&&s.activatedAt===o.activatedAt&&s.stoppedAt===o.stoppedAt})}function Nye(e,t){return e===t?!0:!e||!t?!1:bye(e.runtime,t.runtime)&&Cye(e.queuedMessages,t.queuedMessages)&&yye(e.messages,t.messages)&&_ye(e.history,t.history)&&xye(e.availableProviders,t.availableProviders)&&Tye(e.schedules,t.schedules)&&e.liveScheduleId===t.liveScheduleId&&Rye(e.tunnels,t.tunnels)&&e.liveTunnelId===t.liveTunnelId}function ID(e,t){const n=new Map;for(const r of e)n.set(r._id,r);for(const r of t)n.set(r._id,r);return[...n.values()]}function Aye(e){for(let t=e.length-1;t>=0;t-=1){const n=e[t];if((n==null?void 0:n.kind)==="user_prompt"&&n.content.trim().length>0)return n.content}return null}const PD="__new_chat__",uF="lever-theme",dF="chat-sound-preferences",fF="terminal-preferences",hF="chat-preferences";function qw(e){if(typeof window>"u")return null;const t=window.localStorage.getItem(e);if(!t)return null;try{const n=JSON.parse(t);return n.state&&typeof n.state=="object"&&!Array.isArray(n.state)?n.state:null}catch{return null}}function Mye(){if(typeof window>"u")return null;const e={},t=window.localStorage.getItem(uF);(t==="light"||t==="dark"||t==="system")&&(e.theme=t);const n=qw(dF);((n==null?void 0:n.chatSoundPreference)==="never"||(n==null?void 0:n.chatSoundPreference)==="unfocused"||(n==null?void 0:n.chatSoundPreference)==="always")&&(e.chatSoundPreference=n.chatSoundPreference),((n==null?void 0:n.chatSoundId)==="blow"||(n==null?void 0:n.chatSoundId)==="bottle"||(n==null?void 0:n.chatSoundId)==="frog"||(n==null?void 0:n.chatSoundId)==="funk"||(n==null?void 0:n.chatSoundId)==="glass"||(n==null?void 0:n.chatSoundId)==="ping"||(n==null?void 0:n.chatSoundId)==="pop"||(n==null?void 0:n.chatSoundId)==="purr"||(n==null?void 0:n.chatSoundId)==="tink")&&(e.chatSoundId=n.chatSoundId);const r=qw(fF);if(r){e.terminal={},typeof r.scrollbackLines=="number"&&(e.terminal.scrollbackLines=r.scrollbackLines),typeof r.minColumnWidth=="number"&&(e.terminal.minColumnWidth=r.minColumnWidth);const s={};(r.editorPreset==="cursor"||r.editorPreset==="vscode"||r.editorPreset==="xcode"||r.editorPreset==="windsurf"||r.editorPreset==="custom")&&(s.preset=r.editorPreset),typeof r.editorCommandTemplate=="string"&&(s.commandTemplate=r.editorCommandTemplate),Object.keys(s).length>0&&(e.editor=s)}const i=qw(hF);return((i==null?void 0:i.defaultProvider)==="last_used"||(i==null?void 0:i.defaultProvider)==="claude"||(i==null?void 0:i.defaultProvider)==="codex")&&(e.defaultProvider=i.defaultProvider),i!=null&&i.providerDefaults&&typeof i.providerDefaults=="object"&&(e.providerDefaults=i.providerDefaults),e.browserSettingsMigrated=!0,Object.keys(e).length>1?e:null}function Lye(){typeof window>"u"||(window.localStorage.removeItem(uF),window.localStorage.removeItem(dF),window.localStorage.removeItem(fF),window.localStorage.removeItem(hF))}function _h(e){Ks.getState().setFromServer(e);const t=hi.getState();t.setScrollbackLines(e.terminal.scrollbackLines),t.setMinColumnWidth(e.terminal.minColumnWidth),t.setEditorPreset(e.editor.preset),t.setEditorCommandTemplate(e.editor.commandTemplate);const n=Ec.getState();n.setChatSoundPreference(e.chatSoundPreference),n.setChatSoundId(e.chatSoundId),gi.getState().applyServerDefaults(e.defaultProvider,e.providerDefaults)}function jye(e){return JSON.stringify({id:e.id,kind:e.kind,displayName:e.displayName,relativePath:e.relativePath,mimeType:e.mimeType,size:e.size,contentUrl:e.contentUrl})}function f2(e,t=[]){return JSON.stringify({content:e,attachments:t.map(jye)})}function Dye(e,t){return e.reduce((n,r)=>r.kind!=="user_prompt"?n:n+(f2(r.content,r.attachments??[])===t?1:0),0)}function Iye(e,t,n){const r=new Map;for(const i of n){if(i.kind!=="user_prompt")continue;const s=f2(i.content,i.attachments??[]);r.set(s,(r.get(s)??0)+1)}return e.filter(i=>i.scopeId!==t?!0:(r.get(i.signature)??0)<i.requiredMatchCount)}function Pye(e,t,n){return e.some(r=>r.id===t)?e.filter(r=>r.id!==t):e}const Oye=200,zye=500;function OD(e,t){var r;const n=e.find(i=>i.chats.some(s=>s.chatId===t));return n?((r=n.chats.find(i=>i.chatId!==t))==null?void 0:r.chatId)??null:null}function zD(e,t){if(!(t!=null&&t.length)||e.length<=1)return e;const n=new Map(e.map((o,l)=>[o.groupKey,l])),r=new Set,i=t.map(o=>{if(r.has(o))return null;r.add(o);const l=n.get(o);return l===void 0?null:e[l]}).filter(o=>!!o);if(i.length===0)return e;const s=[...i,...e.filter(o=>!r.has(o.groupKey))];return s.every((o,l)=>o===e[l])?e:s}function Bye(e=document){return e.visibilityState==="visible"&&e.hasFocus()}function Fye(){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws`}function $ye(){const[e]=v.useState(()=>new mye(Fye()));return v.useEffect(()=>(e.start(),()=>{e.dispose()}),[e]),e}const BD="kanna:profile-send-to-starting";function Hye(){try{return window.sessionStorage.getItem(BD)==="1"||window.localStorage.getItem(BD)==="1"}catch{return!1}}function pF(e){return Number((performance.now()-e).toFixed(1))}function fl(e,t,n){!e||!Hye()||console.debug("[kanna/send->starting][client]",{traceId:e.traceId,stage:t,elapsedMs:pF(e.startedAt),serverChatId:e.serverChatId,routeChatIdAtSend:e.routeChatIdAtSend,...n})}function Uye(e){var t,n;return(e==null?void 0:e.provider)==="claude"&&e.model&&((t=e.modelOptions)!=null&&t.claude)?{provider:"claude",model:e.model,modelOptions:{reasoningEffort:e.modelOptions.claude.reasoningEffort??"high",contextWindow:e.modelOptions.claude.contextWindow??"200k"},planMode:!!e.planMode}:(e==null?void 0:e.provider)==="codex"&&e.model&&((n=e.modelOptions)!=null&&n.codex)?{provider:"codex",model:e.model,modelOptions:{reasoningEffort:e.modelOptions.codex.reasoningEffort??"high",fastMode:e.modelOptions.codex.fastMode??!1},planMode:!!e.planMode}:null}function Vye(e,t){var n;return t?((n=e.find(r=>r.chats.some(i=>i.chatId===t)))==null?void 0:n.groupKey)??null:null}function Wye(e,t){return e==="awaiting_disconnect"&&t==="disconnected"?"awaiting_server_ready":"none"}const Gye=30,h2="kanna:ui-update-restart",mF="kanna:last-update-reload-request";function qye(e){return e+Gye}function Kye(e,t){return t>0?t:e}function FD(){return window.sessionStorage.getItem(h2)}function bv(e){window.sessionStorage.setItem(h2,e)}function wh(){window.sessionStorage.removeItem(h2)}function Yye(e,t){return e?String(e)!==t:!1}function Xye(){return window.sessionStorage.getItem(mF)}function Qye(e){window.sessionStorage.setItem(mF,String(e))}function Zye(){return"/auth/status"}function Jye(e,t,n="application/json"){const r=new Blob([t],{type:`${n}; charset=utf-8`}),i=URL.createObjectURL(r),s=document.createElement("a");s.href=i,s.download=e,s.style.display="none",document.body.append(s),s.click(),s.remove(),URL.revokeObjectURL(i)}async function e0e(e=fetch){return(await e(Zye(),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}})).ok}function t0e(e){const t=e.selectedProjectId??e.sidebarProjectId??null;return t?{kind:"project_id",projectId:t}:e.fallbackLocalProjectPath?{kind:"local_path",localPath:e.fallbackLocalProjectPath}:null}function n0e(e,t){return!e||!t?null:e.runtime.chatId!==t?(e.runtime.chatId,e.runtime.provider,null):e}function r0e(e){var $r,fo,Yl;const t=Wd(),n=$ye(),r=Kp(),{resolvedTheme:i}=u2(),[s,o]=v.useState({starredProjectGroups:[],projectGroups:[],stacks:[]}),[l,c]=v.useState(null),[u,p]=v.useState(null),[h,g]=v.useState(null),[b,x]=v.useState(null),[_,w]=v.useState([]),[C,E]=v.useState(!1),[k,R]=v.useState(null),[N,A]=v.useState(!1),[M,D]=v.useState({}),[U,j]=v.useState(null),[P,z]=v.useState(null),[O,$]=v.useState(null),[V,B]=v.useState(null),[F,W]=v.useState("connecting"),[X,I]=v.useState(!1),[G,ee]=v.useState(!1),[H,ue]=v.useState(!1),[ae,J]=v.useState(null),[te,ie]=v.useState(!1),[de,he]=v.useState(!1),[Le,ce]=v.useState(!1),[De,pe]=v.useState(null),[st,zt]=v.useState(!1),[Et,Qt]=v.useState(null),[Dt,Tt]=v.useState(!1),[mt,At]=v.useState(null),[It,ht]=v.useState(null),[Ht,ge]=v.useState([]),[we,Be]=v.useState(null),[tt,Pe]=v.useState(0),Ve=v.useRef(new Map),qe=W1(RD(Y=>Object.keys(Y.drafts).sort())),Xe=W1(RD(Y=>Object.keys(Y.attachmentDrafts).sort())),We=v.useRef(0),gt=v.useRef(null),ot=v.useRef({projectId:null,diffs:null}),Bt=vne(hi(Y=>Y.editorPreset)),ut=v.useMemo(()=>zD(s.projectGroups,l),[l,s.projectGroups]),on=v.useRef(ut);v.useLayoutEffect(()=>{on.current=ut});const cn=v.useMemo(()=>ut===s.projectGroups?s:{...s,projectGroups:ut},[s,ut]);v.useEffect(()=>n.onStatus(W),[n]),v.useEffect(()=>n.subscribe({type:"sidebar"},Y=>{o(Y),c(Z=>Z&&zD(Y.projectGroups,Z)===Y.projectGroups?null:Z),I(!0),pe(null)}),[n]),v.useEffect(()=>{if(F!=="connected")return;const Y=[...new Set([...qe,...Xe])].sort();n.command({type:"chat.setDraftProtection",chatIds:Y}).catch(Z=>{pe(Z instanceof Error?Z.message:String(Z))})},[Xe,F,qe,n]),v.useEffect(()=>n.subscribe({type:"local-projects"},Y=>{p(Y),ee(!0),pe(null)}),[n]),v.useEffect(()=>n.subscribe({type:"update"},Y=>{g(Y),pe(null)}),[n]),v.useEffect(()=>{F==="connected"&&n.command({type:"update.check",force:!0}).catch(Y=>{pe(Y instanceof Error?Y.message:String(Y))})},[F,n]),v.useEffect(()=>{const Y=h==null?void 0:h.reloadRequestedAt;Yye(Y,Xye())&&Y&&(Qye(Y),bv("awaiting_disconnect"))},[h==null?void 0:h.reloadRequestedAt]),v.useEffect(()=>{const Y=FD();if(Wye(Y,F)==="awaiting_server_ready"){bv("awaiting_server_ready");return}},[F]),v.useEffect(()=>{if(FD()!=="awaiting_server_ready")return;let Y=!1,Z=null;const Ae=async()=>{try{if(await e0e()){if(Y)return;wh(),window.location.reload();return}}catch{}Y||(Z=window.setTimeout(()=>{Ae()},500))};return Ae(),()=>{Y=!0,Z!==null&&window.clearTimeout(Z)}},[F]),v.useEffect(()=>{function Y(){h!=null&&h.lastCheckedAt&&(Date.now()-h.lastCheckedAt<=3600*1e3||n.command({type:"update.check"}).catch(Z=>{pe(Z instanceof Error?Z.message:String(Z))}))}return window.addEventListener("focus",Y),()=>{window.removeEventListener("focus",Y)}},[n,h==null?void 0:h.lastCheckedAt]),v.useEffect(()=>n.subscribe({type:"keybindings"},Y=>{j(Y),pe(null)}),[n]),v.useEffect(()=>n.subscribe({type:"app-settings"},Y=>{z(Y),_h(Y),pe(null)}),[n]),v.useEffect(()=>n.subscribe({type:"push-config"},Y=>{$(Y)}),[n]),v.useEffect(()=>{let Y=!1;return n.subscribe({type:"bg-tasks"},Z=>{Ys.getState().applySnapshot(Z.tasks),!Y&&Z.orphanRecoveryCount!=null&&Z.orphanRecoveryCount>0&&(Y=!0,gye(Z.orphanRecoveryCount))},Z=>{Z.type==="bg-tasks.added"?Ys.getState().applyDiff({op:"added",task:Z.task}):Z.type==="bg-tasks.updated"?Ys.getState().applyDiff({op:"updated",task:Z.task}):Z.type==="bg-tasks.removed"&&Ys.getState().applyDiff({op:"removed",task:Z.task})})},[n]);const vt=v.useCallback(async()=>{try{Ks.getState().setHydrationStatus("loading");const Y=await n.command({type:"settings.readAppSettings"});z(Y),_h(Y),pe(null)}catch(Y){Ks.getState().setHydrationStatus("error"),pe(Y instanceof Error?Y.message:String(Y))}},[n]),Rt=v.useCallback(async(Y,Z)=>{try{await n.command({type:"chat.setPolicyOverride",chatId:Y,policyOverride:Z}),pe(null)}catch(Ae){throw pe(Ae instanceof Error?Ae.message:String(Ae)),Ae}},[n]),St=v.useCallback(async Y=>{try{Ks.getState().applyOptimisticPatch(Y);const Z=await n.command({type:"settings.writeAppSettingsPatch",patch:Y});z(Z),_h(Z),pe(null)}catch(Z){throw pe(Z instanceof Error?Z.message:String(Z)),await vt(),Z}},[vt,n]),Ut=v.useCallback(async Y=>{try{Ks.getState().applyOptimisticPatch({cloudflareTunnel:Y});const Z=await n.command({type:"appSettings.setCloudflareTunnel",patch:Y});z(Z),_h(Z),pe(null)}catch(Z){throw pe(Z instanceof Error?Z.message:String(Z)),await vt(),Z}},[vt,n]),xt=v.useCallback(async Y=>{try{Ks.getState().applyOptimisticPatch({claudeAuth:Y});const Z=await n.command({type:"appSettings.setClaudeAuth",patch:Y});z(Z),_h(Z),pe(null)}catch(Z){throw pe(Z instanceof Error?Z.message:String(Z)),await vt(),Z}},[vt,n]),ft=v.useCallback(async Y=>await n.command({type:"appSettings.testOAuthToken",token:Y}),[n]),Lt=v.useCallback(async()=>{try{const Y=await n.command({type:"settings.readLlmProvider"});B(Y),pe(null)}catch(Y){pe(Y instanceof Error?Y.message:String(Y))}},[n]),Pt=v.useCallback(async Y=>{try{const Z=await n.command({type:"settings.writeLlmProvider",provider:Y.provider,apiKey:Y.apiKey,model:Y.model,baseUrl:Y.baseUrl});B(Z),pe(null)}catch(Z){throw pe(Z instanceof Error?Z.message:String(Z)),Z}},[n]),Ie=v.useCallback(async Y=>await n.command({type:"settings.validateLlmProvider",provider:Y.provider,apiKey:Y.apiKey,model:Y.model,baseUrl:Y.baseUrl}),[n]);v.useEffect(()=>{F==="connected"&&vt()},[F,vt]),v.useEffect(()=>{if(F!=="connected"||(P==null?void 0:P.browserSettingsMigrated)!==!1)return;const Y=Mye();Y&&St(Y).then(Lye).catch(()=>{})},[P==null?void 0:P.browserSettingsMigrated,F,St]),v.useEffect(()=>{F==="connected"&&Lt()},[F,Lt]),v.useEffect(()=>{function Y(){Pe(Z=>Z+1)}return window.addEventListener("focus",Y),document.addEventListener("visibilitychange",Y),()=>{window.removeEventListener("focus",Y),document.removeEventListener("visibilitychange",Y)}},[]),v.useEffect(()=>{if(!e){x(null),ue(!0);return}++We.current,on.current.length,on.current.reduce((Z,Ae)=>Z+Ae.chats.length,0),x(null),ue(!1);const Y=n.subscribe({type:"chat",chatId:e,recentLimit:Oye},Z=>{if(Z!=null&&Z.runtime.chatId){const Ae=[...Ve.current.values()].filter(bt=>bt.serverChatId===Z.runtime.chatId).sort((bt,Pn)=>Pn.startedAt-bt.startedAt)[0];Ae&&Ae.snapshotAt===void 0&&(Ae.snapshotAt=performance.now(),fl(Ae,"chat_snapshot_received",{status:Z.runtime.status,messageCount:Z.messages.length}))}if(x(Ae=>{const bt=Nye(Ae,Z);return Z==null||Z.runtime.chatId,Z==null||Z.runtime.provider,Z==null||Z.runtime.status,Z==null||Z.messages.length,bt?Ae:Z}),R((Z==null?void 0:Z.history.olderCursor)??null),A((Z==null?void 0:Z.history.hasOlder)??!1),ue(!0),pe(null),Z){const Ae=c2.getState();Ae.setForChat(Z.runtime.chatId,Z.slashCommands??[]),Ae.setLoadingForChat(Z.runtime.chatId,Z.slashCommandsLoading??!1)}});return()=>{on.current.length,on.current.reduce((Z,Ae)=>Z+Ae.chats.length,0),Y()}},[e,n]),v.useEffect(()=>{if(ae)return;const Y=ut[0];Y&&J(Y.groupKey)},[ae,ut]),v.useEffect(()=>{if(!e||!X||!H)return;if(ut.some(Z=>Z.chats.some(Ae=>Ae.chatId===e))){It===e&&ht(null);return}It!==e&&t("/")},[e,H,t,It,ut,X]),v.useEffect(()=>{b&&(J(b.runtime.projectId),It===b.runtime.chatId&&ht(null))},[b,It]),v.useEffect(()=>{if(!e||!X||!Bye())return;const Y=ut.flatMap(Z=>Z.chats).find(Z=>Z.chatId===e);Y!=null&&Y.unread&&n.command({type:"chat.markRead",chatId:e}).catch(Z=>{pe(Z instanceof Error?Z.message:String(Z))})},[e,tt,ut,X,n]),v.useEffect(()=>{w([]),E(!1),R(null),A(!1)},[e]);const ze=v.useMemo(()=>n0e(b,e),[e,b]),Te=v.useMemo(()=>(ze==null?void 0:ze.runtime.projectId)??Vye(ut,e)??ae,[e,ze==null?void 0:ze.runtime.projectId,ae,ut]),Ye=v.useMemo(()=>{const Y=Te?M[Te]??null:null;return Te&&Y?(ot.current={projectId:Te,diffs:Y},Y):Te&&ot.current.projectId===Te?ot.current.diffs:Y},[Te,M]);v.useEffect(()=>Te?n.subscribe({type:"project-git",projectId:Te},Z=>{D(Ae=>{const bt=Z??null;return Eye(Ae[Te]??null,bt)||kye(Ae[Te]??null,bt)?Ae:{...Ae,[Te]:bt}}),pe(null)}):void 0,[Te,n]),v.useEffect(()=>{b==null||b.runtime.chatId,b==null||b.runtime.provider,ze==null||ze.runtime.chatId,ze==null||ze.runtime.provider},[e,ze,b,It]);const _e=v.useMemo(()=>ID(_,(ze==null?void 0:ze.messages)??[]),[ze==null?void 0:ze.messages,_]),Je=e??PD,et=v.useMemo(()=>Ht.filter(Y=>Y.scopeId===Je).map(Y=>Y.entry),[Je,Ht]),$e=v.useMemo(()=>[..._e,...et],[et,_e]),Mt=v.useMemo(()=>lF($e),[$e]),un=v.useMemo(()=>Aye(Mt),[Mt]),Zt=v.useMemo(()=>tye(Mt),[Mt]),Fe=(ze==null?void 0:ze.runtime)??null,hn=(ze==null?void 0:ze.queuedMessages)??[],se=((we==null?void 0:we.scopeId)===Je&&(!Fe||Fe.status==="idle")?"starting":null)??(Fe==null?void 0:Fe.status)??null,le=(ze==null?void 0:ze.availableProviders)??Uh,Ce=rye(se??void 0),Ee=nye(se??void 0),Qe=(Fe==null?void 0:Fe.isDraining)??!1,ct=(($r=u==null?void 0:u.projects[0])==null?void 0:$r.localPath)??null,Ze=(Fe==null?void 0:Fe.localPath)??ct??((fo=ut[0])==null?void 0:fo.localPath),Vt=!!(ae??(Fe==null?void 0:Fe.projectId)??((Yl=ut[0])==null?void 0:Yl.groupKey)??ct);v.useEffect(()=>{(we==null?void 0:we.scopeId)===Je&&Fe!=null&&Fe.status&&Fe.status!=="idle"&&Be(null)},[we,Je,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!(we!=null&&we.ackedAt)||we.scopeId!==Je||Fe!=null&&Fe.status&&Fe.status!=="idle")return;const Y=window.setTimeout(()=>{Be(Z=>(Z==null?void 0:Z.scopeId)===Je&&Z.ackedAt===we.ackedAt?null:Z)},300);return()=>window.clearTimeout(Y)},[we,Je,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!e||(Fe==null?void 0:Fe.status)!=="starting")return;const Y=[...Ve.current.values()].filter(Z=>Z.serverChatId===e).sort((Z,Ae)=>Ae.startedAt-Z.startedAt)[0];!Y||Y.startingStatusAt!==void 0||(Y.startingStatusAt=performance.now(),fl(Y,"runtime_status_starting",{status:Fe.status}))},[e,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!e||!Fe||Fe.status==="starting")return;const Y=[...Ve.current.values()].filter(Z=>Z.serverChatId===e).sort((Z,Ae)=>Ae.startedAt-Z.startedAt)[0];!Y||Y.startingRenderedAt!==void 0||(fl(Y,"starting_not_observed",{status:Fe.status}),Ve.current.delete(Y.traceId))},[e,Fe]),v.useLayoutEffect(()=>{if(!e||(Fe==null?void 0:Fe.status)!=="starting"){gt.current=null;return}const Y=[...Ve.current.values()].filter(Z=>Z.serverChatId===e).sort((Z,Ae)=>Ae.startedAt-Z.startedAt)[0];Y&&gt.current!==Y.traceId&&(gt.current=Y.traceId,Y.startingRenderedAt=performance.now(),fl(Y,"starting_render_committed",{totalMs:pF(Y.startedAt)}),Ve.current.delete(Y.traceId))},[e,Fe==null?void 0:Fe.status]),v.useEffect(()=>{ge(Y=>{const Z=Iye(Y,Je,_e);return Z.length===Y.length&&Z.every((Ae,bt)=>Ae===Y[bt])?Y:Z})},[Je,_e]);const Dn=v.useCallback(async()=>{if(!(!e||!k||C||!N)){E(!0);try{const Y=await n.command({type:"chat.loadHistory",chatId:e,beforeCursor:k,limit:zye});w(Z=>ID(Y.messages,Z)),R(Y.olderCursor),A(Y.hasOlder),pe(null)}catch(Y){const Z=Y instanceof Error?Y.message:String(Y);pe(Z)}finally{E(!1)}}},[e,N,k,C,n]),fn=v.useCallback(async Y=>{const Z=gi.getState(),Ae=e?Z.getComposerState(e):Z.getComposerState(Qh),bt=await n.command({type:"chat.create",projectId:Y});Z.initializeComposerForChat(bt.chatId,{sourceState:Ae}),J(Y),ht(bt.chatId),t(`/chat/${bt.chatId}`),ie(!1),pe(null)},[e,t,n]),Si=v.useCallback(async Y=>Y.kind==="project_id"?{projectId:Y.projectId}:Y.kind==="local_path"?{projectId:(await n.command({type:"project.open",localPath:Y.localPath})).projectId,localPath:Y.localPath}:{projectId:(await n.command(Y.project.mode==="new"?{type:"project.create",localPath:Y.project.localPath,title:Y.project.title}:{type:"project.open",localPath:Y.project.localPath})).projectId,localPath:Y.project.localPath},[n]),Vn=v.useCallback(async Y=>{try{const Z=Y.kind==="project_id"?null:Y.kind==="local_path"?Y.localPath:Y.project.localPath;Z&&At(Z);const{projectId:Ae}=await Si(Y);await fn(Ae)}catch(Z){pe(Z instanceof Error?Z.message:String(Z))}finally{At(null)}},[fn,Si]),Tr=v.useCallback(async Y=>{await Vn({kind:"project_id",projectId:Y})},[Vn]),Qr=v.useCallback(async Y=>{try{const Z=await n.command({type:"chat.fork",chatId:Y.chatId}),Ae=gi.getState();Ae.initializeComposerForChat(Z.chatId,{sourceState:Ae.getComposerState(Y.chatId)}),ht(Z.chatId),t(`/chat/${Z.chatId}`),ie(!1),pe(null)}catch(Z){pe(Z instanceof Error?Z.message:String(Z))}},[t,n]),Oi=v.useCallback(async Y=>{await Vn({kind:"local_path",localPath:Y})},[Vn]),ai=v.useCallback(async Y=>{await Vn({kind:"project_request",project:Y})},[Vn]),ts=v.useCallback(async Y=>{try{await n.command({type:"update.check",force:Y==null?void 0:Y.force}),pe(null)}catch(Z){pe(Z instanceof Error?Z.message:String(Z))}},[n]),zi=v.useCallback(async()=>{try{const Y=await n.command({type:"update.install"});if(!Y.ok){wh(),pe(null),await r.alert({title:Y.userTitle??"Update failed",description:Y.userMessage??"Kanna could not install the update. Try again later.",closeLabel:"OK"});return}if(Y.ok&&Y.action==="reload"){window.location.reload();return}Y.ok&&Y.action==="restart"&&bv("awaiting_disconnect"),pe(null)}catch(Y){wh(),pe(Y instanceof Error?Y.message:String(Y))}},[r,n]),_t=v.useCallback(async()=>{try{const Y=await n.command({type:"update.reload"});if(!Y.ok){wh(),pe(null),await r.alert({title:Y.userTitle??"Re-deploy failed",description:Y.userMessage??"Kanna could not re-deploy. Try again later.",closeLabel:"OK"});return}if(Y.action==="reload"){window.location.reload();return}bv("awaiting_disconnect"),pe(null)}catch(Y){wh(),pe(Y instanceof Error?Y.message:String(Y))}},[r,n]),an=v.useCallback(async()=>{try{const Y=await fetch("/auth/logout",{method:"POST",headers:{Accept:"application/json"}});if(!Y.ok)throw new Error(`Sign out failed with status ${Y.status}`);pe(null),window.location.reload()}catch(Y){pe(Y instanceof Error?Y.message:String(Y))}},[]),kn=v.useCallback(async(Y,Z)=>{var _m;const Ae=(Z==null?void 0:Z.attachments)??[],bt=_c(),Pn=_c(),Zr=f2(Y,Ae),Ba=e??PD;Be({scopeId:Ba,ackedAt:null});const Ps={traceId:Pn,optimisticId:bt,startedAt:performance.now(),serverChatId:e,routeChatIdAtSend:e,contentPreview:Y.slice(0,80)};Ve.current.set(Pn,Ps),fl(Ps,"handle_send_called",{optimisticScopeId:Ba,attachments:Ae.length,contentLength:Y.length,contentPreview:Ps.contentPreview});const S0=Dye(_e,Zr)+Ht.filter(Yn=>Yn.scopeId===Ba&&Yn.signature===Zr).length+1;ge(Yn=>[...Yn,{id:bt,scopeId:Ba,signature:Zr,requiredMatchCount:S0,entry:{_id:`optimistic:${bt}`,kind:"user_prompt",content:Y,attachments:Ae,createdAt:Date.now()}}]),fl(Ps,"optimistic_prompt_added",{optimisticId:bt,optimisticScopeId:Ba});try{let Yn=ae??((_m=ut[0])==null?void 0:_m.groupKey)??null;if(!e&&!Yn&&ct&&(Yn=(await n.command({type:"project.open",localPath:ct})).projectId,J(Yn)),!e&&!Yn)throw new Error("Open a project first");const Sf=G1.getState().autoResumeOnRateLimit,ci=await n.command({type:"chat.send",chatId:e??void 0,projectId:e?void 0:Yn??void 0,clientTraceId:Pn,provider:Z==null?void 0:Z.provider,content:Y,attachments:Ae,model:Z==null?void 0:Z.model,modelOptions:Z==null?void 0:Z.modelOptions,planMode:Z==null?void 0:Z.planMode,autoResumeOnRateLimit:Sf});if(Ps.ackAt=performance.now(),Ps.serverChatId=ci.chatId??Ps.serverChatId,ci.queued?(ge(Os=>Pye(Os,bt,{queued:!0})),Be(null)):Be(Os=>Os&&{scopeId:!e&&ci.chatId?ci.chatId:Os.scopeId,ackedAt:performance.now()}),fl(Ps,"chat_send_ack_received",{resultChatId:ci.chatId??null,queued:ci.queued??!1}),!e&&ci.chatId){ge(wm=>wm.map(Cf=>Cf.id===bt?{...Cf,scopeId:ci.chatId}:Cf));const Os=gi.getState();Os.setComposerState(ci.chatId,Uye(Z)??Os.getComposerState(Qh)),ht(ci.chatId),t(`/chat/${ci.chatId}`)}pe(null)}catch(Yn){throw ge(Sf=>Sf.filter(ci=>ci.id!==bt)),Be(null),fl(Ps,"handle_send_failed",{error:Yn instanceof Error?Yn.message:String(Yn)}),Ve.current.delete(Pn),pe(Yn instanceof Error?Yn.message:String(Yn)),Yn}},[e,ct,t,Ht,ae,_e,ut,n]),gn=v.useCallback(async Y=>{if(e)try{await n.command({type:"message.steer",chatId:e,queuedMessageId:Y}),pe(null)}catch(Z){pe(Z instanceof Error?Z.message:String(Z))}},[e,n]),ao=v.useCallback(async Y=>{if(e)try{await n.command({type:"message.dequeue",chatId:e,queuedMessageId:Y}),pe(null)}catch(Z){pe(Z instanceof Error?Z.message:String(Z))}},[e,n]),Da=v.useCallback(async()=>{if(e)try{await n.command({type:"chat.cancel",chatId:e})}catch(Y){pe(Y instanceof Error?Y.message:String(Y))}},[e,n]),ns=v.useCallback(async()=>{if(e)try{await n.command({type:"chat.stopDraining",chatId:e})}catch(Y){pe(Y instanceof Error?Y.message:String(Y))}},[e,n]),Fo=v.useCallback(async Y=>{const Z=await r.prompt({title:"Rename Chat",initialValue:Y.title,confirmLabel:"Rename"});if(!(!Z||Z===Y.title))try{await n.command({type:"chat.rename",chatId:Y.chatId,title:Z}),pe(null)}catch(Ae){pe(Ae instanceof Error?Ae.message:String(Ae))}},[r,n]),rs=v.useCallback(async Y=>{if(await r.confirm({title:"Delete Chat",description:`Delete "${Y.title}"? This cannot be undone.`,confirmLabel:"Delete",confirmVariant:"destructive"}))try{if(await n.command({type:"chat.delete",chatId:Y.chatId}),Y.chatId===e){const Ae=OD(ut,Y.chatId);t(Ae?`/chat/${Ae}`:"/")}}catch(Ae){pe(Ae instanceof Error?Ae.message:String(Ae))}},[e,r,t,ut,n]),Ia=v.useCallback(async Y=>{try{if(await n.command({type:"chat.archive",chatId:Y.chatId}),Y.chatId===e){const Z=OD(ut,Y.chatId);t(Z?`/chat/${Z}`:"/")}pe(null)}catch(Z){pe(Z instanceof Error?Z.message:String(Z))}},[e,t,ut,n]),cr=v.useCallback(async Y=>{try{ht(Y),await n.command({type:"chat.unarchive",chatId:Y}),t(`/chat/${Y}`),pe(null)}catch(Z){ht(null),pe(Z instanceof Error?Z.message:String(Z))}},[t,n]),je=v.useCallback(async Y=>{try{await n.command({type:"project.remove",projectId:Y}),yl.getState().clearProject(Y),Li.getState().clearProject(Y),(Fe==null?void 0:Fe.projectId)===Y&&t("/"),pe(null)}catch(Z){pe(Z instanceof Error?Z.message:String(Z))}},[t,Fe,n]),Ke=v.useCallback(async(Y,Z)=>{try{await n.command({type:"project.setStar",projectId:Y,starred:Z}),pe(null)}catch(Ae){pe(Ae instanceof Error?Ae.message:String(Ae))}},[n]),Ft=v.useCallback(async Y=>{c(Y);try{await n.command({type:"sidebar.reorderProjectGroups",projectIds:Y}),pe(null)}catch(Z){c(null),pe(Z instanceof Error?Z.message:String(Z))}},[n]),tr=v.useCallback(async(Y,Z)=>{try{await n.command({type:"stack.create",title:Y,projectIds:Z}),pe(null)}catch(Ae){pe(Ae instanceof Error?Ae.message:String(Ae))}},[n]),li=v.useCallback(async(Y,Z)=>{try{await n.command({type:"stack.rename",stackId:Y,title:Z}),pe(null)}catch(Ae){pe(Ae instanceof Error?Ae.message:String(Ae))}},[n]),lo=v.useCallback(async Y=>{try{await n.command({type:"stack.remove",stackId:Y}),pe(null)}catch(Z){pe(Z instanceof Error?Z.message:String(Z))}},[n]),Q=v.useCallback(async(Y,Z)=>{try{await n.command({type:"stack.addProject",stackId:Y,projectId:Z}),pe(null)}catch(Ae){pe(Ae instanceof Error?Ae.message:String(Ae))}},[n]),Oe=v.useCallback(async(Y,Z)=>{try{await n.command({type:"stack.removeProject",stackId:Y,projectId:Z}),pe(null)}catch(Ae){pe(Ae instanceof Error?Ae.message:String(Ae))}},[n]),xn=v.useCallback(async(Y,Z,Ae)=>{try{const bt=gi.getState(),Pn=e?bt.getComposerState(e):bt.getComposerState(Qh),Zr=await n.command({type:"chat.create",projectId:Y,stackId:Z,stackBindings:Ae});bt.initializeComposerForChat(Zr.chatId,{sourceState:Pn}),J(Y),ht(Zr.chatId),t(`/chat/${Zr.chatId}`),ie(!1),pe(null)}catch(bt){pe(bt instanceof Error?bt.message:String(bt))}},[e,t,n]),co=v.useCallback(async Y=>{try{const Z=await n.command({type:"stack.listWorktrees",projectId:Y});return pe(null),Z.worktrees}catch(Z){return pe(Z instanceof Error?Z.message:String(Z)),[]}},[n]),Wl=v.useCallback(async()=>await n.command({type:"sessions.importClaude"}),[n]),is=v.useCallback(async Y=>{const Z=hi.getState();pe(null),await n.command({type:"system.openExternal",...Y,editor:Y.action==="open_editor"?Y.editor??{preset:Z.editorPreset,commandTemplate:Z.editorCommandTemplate}:void 0})},[n]),bf=v.useCallback(async(Y,Z)=>{var bt,Pn;const Ae=(Fe==null?void 0:Fe.localPath)??((bt=u==null?void 0:u.projects[0])==null?void 0:bt.localPath)??((Pn=ut[0])==null?void 0:Pn.localPath);if(Ae)try{await is({action:Y,localPath:Ae,editor:Z})}catch(Zr){pe(Zr instanceof Error?Zr.message:String(Zr))}},[u==null?void 0:u.projects,is,Fe==null?void 0:Fe.localPath,ut]),Pa=v.useCallback(async Y=>{var Z;try{if(typeof navigator>"u"||!((Z=navigator.clipboard)!=null&&Z.writeText))throw new Error("Clipboard is not available");await navigator.clipboard.writeText(Y),pe(null)}catch(Ae){pe(Ae instanceof Error?Ae.message:String(Ae))}},[]),Ds=v.useCallback(async(Y,Z="open_editor",Ae)=>{try{await is({action:Z,localPath:Y.path,line:Y.line,column:Y.column,editor:Ae})}catch(bt){pe(bt instanceof Error?bt.message:String(bt))}},[is]),yf=v.useCallback(async(Y,Z)=>{try{await is({action:Y,localPath:Z})}catch(Ae){pe(Ae instanceof Error?Ae.message:String(Ae))}},[is]),Gl=v.useCallback(async(Y=e)=>{if(!Y||st)return null;zt(!0);try{const Z=await n.command({type:"chat.exportStandalone",chatId:Y,theme:i,attachmentMode:"bundle"});return pe(null),Z}catch(Z){return pe(Z instanceof Error?Z.message:String(Z)),null}finally{zt(!1)}},[e,st,i,n]),Oa=v.useCallback(async(Y=e)=>{if(!Y||st)return;Tt(!1);const Z=await Gl(Y);if(Z!=null&&Z.ok&&Z.shareUrl){Qt(Z.shareUrl),Tt(!0);return}Z&&!Z.ok&&await r.confirm({title:"Share failed",description:Z.error,confirmLabel:"Download transcript JSON",cancelLabel:"Close",confirmVariant:"secondary"})&&Jye(Z.transcriptFileName,Z.transcriptJson)},[e,r,Gl,st]),za=v.useCallback(()=>{Qt(null),Tt(!1)},[]),vm=v.useCallback(async()=>{var Y;if(!Et)return!1;try{if(typeof navigator>"u"||!((Y=navigator.clipboard)!=null&&Y.writeText))throw new Error("Clipboard is not available");return await navigator.clipboard.writeText(Et),!0}catch(Z){return await r.alert({title:"Copy failed",description:Z instanceof Error?Z.message:String(Z),closeLabel:"Close"}),!1}},[r,Et]),xf=v.useCallback(()=>{Et&&(window.open(Et,"_blank","noopener,noreferrer"),Qt(null))},[Et]),bm=v.useCallback(()=>{var Z;const Y=t0e({selectedProjectId:ae,sidebarProjectId:(Z=ut[0])==null?void 0:Z.groupKey,fallbackLocalProjectPath:ct});if(Y){Vn(Y);return}t("/")},[ct,t,ae,ut,Vn]),ql=v.useCallback(()=>ie(!0),[]),Is=v.useCallback(()=>ie(!1),[]),_f=v.useCallback(()=>he(!0),[]),Kl=v.useCallback(()=>he(!1),[]),uo=v.useCallback(()=>ce(!0),[]),wf=v.useCallback(()=>ce(!1),[]),lu=v.useCallback(async(Y,Z,Ae)=>{if(e)try{await n.command({type:"chat.respondTool",chatId:e,toolUseId:Y,result:{questions:Z,answers:Ae}})}catch(bt){pe(bt instanceof Error?bt.message:String(bt))}},[e,n]),ym=v.useCallback(async(Y,Z,Ae,bt)=>{if(e){Z&&gi.getState().setChatComposerPlanMode(e,!1);try{await n.command({type:"chat.respondTool",chatId:e,toolUseId:Y,result:{confirmed:Z,...Ae?{clearContext:!0}:{},...bt?{message:bt}:{}}})}catch(Pn){pe(Pn instanceof Error?Pn.message:String(Pn))}}},[e,n]),cu=v.useCallback(async(Y,Z,Ae,bt)=>{if(e)try{await n.command({type:"chat.respondSubagentTool",chatId:e,runId:Y,toolUseId:Z,result:{questions:Ae,answers:bt}})}catch(Pn){pe(Pn instanceof Error?Pn.message:String(Pn))}},[e,n]),uu=v.useCallback(async(Y,Z,Ae)=>{if(e)try{await n.command({type:"chat.respondSubagentTool",chatId:e,runId:Y,toolUseId:Z,result:Ae})}catch(bt){pe(bt instanceof Error?bt.message:String(bt))}},[e,n]),xm=v.useCallback(async(Y,Z)=>{if(e)try{await n.command({type:"chat.toolRequestAnswer",chatId:e,toolRequestId:Y,decision:Z})}catch(Ae){pe(Ae instanceof Error?Ae.message:String(Ae))}},[e,n]);return{socket:n,activeChatId:e,activeProjectId:Te,sidebarData:cn,localProjects:u,updateSnapshot:h,chatSnapshot:b,chatDiffSnapshot:Ye,keybindings:U,appSettings:P,pushConfig:O,llmProvider:V,connectionStatus:F,sidebarReady:X,localProjectsReady:G,commandError:De,startingLocalPath:mt,sidebarOpen:te,sidebarCollapsed:de,messages:Mt,queuedMessages:hn,previousPrompt:un,latestToolIds:Zt,runtime:Fe,runtimeStatus:se,isHistoryLoading:C,hasOlderHistory:N,availableProviders:le,isProcessing:Ce,canCancel:Ee,isDraining:Qe,isExportingStandalone:st,standaloneShareUrl:Et,standaloneShareComplete:Dt,navbarLocalPath:Ze,editorLabel:Bt,hasSelectedProject:Vt,addProjectModalOpen:Le,openSidebar:ql,closeSidebar:Is,collapseSidebar:_f,expandSidebar:Kl,openAddProjectModal:uo,closeAddProjectModal:wf,loadOlderHistory:Dn,handleCreateChat:Tr,handleForkChat:Qr,handleOpenLocalProject:Oi,handleCreateProject:ai,handleCheckForUpdates:ts,handleInstallUpdate:zi,handleForceReload:_t,handleReadAppSettings:vt,handleWriteAppSettings:St,handleSetChatPolicyOverride:Rt,handleWriteCloudflareTunnel:Ut,handleWriteClaudeAuth:xt,handleTestOAuthToken:ft,handleReadLlmProvider:Lt,handleWriteLlmProvider:Pt,handleValidateLlmProvider:Ie,handleSignOut:an,handleSend:kn,handleSteerQueuedMessage:gn,handleRemoveQueuedMessage:ao,handleCancel:Da,handleStopDraining:ns,handleRenameChat:Fo,handleShareChat:Oa,handleArchiveChat:Ia,handleOpenArchivedChat:cr,handleDeleteChat:rs,handleHideProject:je,handleToggleProjectStar:Ke,handleReorderProjectGroups:Ft,stacks:cn.stacks,handleCreateStack:tr,handleRenameStack:li,handleRemoveStack:lo,handleAddProjectToStack:Q,handleRemoveProjectFromStack:Oe,handleCreateStackChat:xn,handleListStackWorktrees:co,importClaudeSessions:Wl,handleCopyPath:Pa,handleOpenExternal:bf,handleOpenExternalPath:yf,handleOpenLocalLink:Ds,handleCompose:bm,handleAskUserQuestion:lu,handleExitPlanMode:ym,handleSubagentAskUserQuestion:cu,handleSubagentExitPlanMode:uu,handleExportStandalone:Gl,handleCloseStandaloneShareDialog:za,handleOpenStandaloneShareLink:xf,handleCopyStandaloneShareLink:vm,handleToolRequestAnswer:xm}}const gF=v.memo(function({message:t}){return f.jsx("div",{className:"text-pretty prose prose-sm dark:prose-invert px-0.5 w-full max-w-[70ch] space-y-4",children:f.jsx(tu,{remarkPlugins:hf,components:pf,children:t.text})})}),dm=({children:e,className:t,animate:n=!0,shimmerWidth:r,...i})=>f.jsx("span",{className:me("mx-auto max-w-md text-foreground/60",n&&"animate-shiny-pulse",t),...i,children:e});function i0e(e){const t=e.split(`
2606
2606
  `),n=/^\s*(\d+)→(.*)$/;return t.map(r=>{const i=r.match(n);return i?{lineNumber:parseInt(i[1],10),content:i[2]}:{lineNumber:null,content:r}})}function s0e(e){return e.replace(/<[^>]+>/g,"")}function o0e(e,t){const n=e.split(`
2607
2607
  `),r=t.split(`
2608
2608
  `),i=a0e(n,r),s=l0e(n,r,i);return c0e(s)}function a0e(e,t){const n=e.length,r=t.length,i=Array.from({length:n+1},()=>Array(r+1).fill(0));for(let s=1;s<=n;s++)for(let o=1;o<=r;o++)i[s][o]=e[s-1]===t[o-1]?i[s-1][o-1]+1:Math.max(i[s-1][o],i[s][o-1]);return i}function l0e(e,t,n){const r=[];let i=e.length,s=t.length;for(;i>0||s>0;)i>0&&s>0&&e[i-1]===t[s-1]?(r.push({type:"context",text:e[i-1],oldIdx:i,newIdx:s}),i--,s--):s>0&&(i===0||n[i][s-1]>=n[i-1][s])?(r.push({type:"added",text:t[s-1],oldIdx:i,newIdx:s}),s--):(r.push({type:"removed",text:e[i-1],oldIdx:i,newIdx:s}),i--);return r.reverse()}function c0e(e){return e.map(t=>{const n=t.type==="removed"?"-":t.type==="added"?"+":" ";return{type:t.type,content:`${n}${t.text}`}})}function yv({content:e,isDiff:t=!1,oldString:n,newString:r}){const i=v.useMemo(()=>t&&n!==void 0&&r!==void 0?o0e(n,r):[],[t,n,r]),s=v.useMemo(()=>t?[]:i0e(e),[e,t]),o=v.useMemo(()=>s.some(l=>l.lineNumber!==null),[s]);return t&&i.length>0?f.jsx("div",{className:"my-1 rounded-lg border border-border overflow-hidden",children:f.jsx("div",{className:"overflow-auto max-h-64 md:max-h-[50vh]",children:f.jsx("table",{className:"w-full border-collapse text-xs font-mono",children:f.jsx("tbody",{children:i.map((l,c)=>{const u=l.type==="removed"?"bg-destructive/10 dark:bg-destructive/15":l.type==="added"?"bg-success/10 dark:bg-success/15":"",p=l.type==="removed"?"text-destructive":l.type==="added"?"text-success":"text-foreground";return f.jsxs("tr",{className:u,children:[f.jsx("td",{className:`px-2 py-0 select-none w-0 whitespace-nowrap ${l.type==="removed"?"text-destructive/50":l.type==="added"?"text-success/50":"text-muted-foreground/50"}`,children:l.type==="removed"?"-":l.type==="added"?"+":" "}),f.jsx("td",{className:`px-2 py-0 whitespace-pre select-all ${p}`,children:l.content.slice(1)})]},c)})})})})}):f.jsx("div",{className:"my-1 rounded-lg border border-border overflow-hidden",children:f.jsx("div",{className:"overflow-auto max-h-64 md:max-h-[50vh]",children:f.jsx("table",{className:"w-full border-collapse text-xs font-mono",children:f.jsx("tbody",{children:s.map((l,c)=>f.jsxs("tr",{children:[o&&f.jsx("td",{className:"px-2 py-0 select-none w-0 whitespace-nowrap text-muted-foreground/50 text-right",children:l.lineNumber!==null?l.lineNumber:""}),f.jsx("td",{className:"px-2 py-0 whitespace-pre select-all text-foreground",children:s0e(l.content)})]},c))})})})})}function $D(e){return(e&&typeof e=="object"&&"content"in e&&Array.isArray(e.content)?e.content:Array.isArray(e)?e:[]).flatMap(n=>!n||typeof n!="object"||!("type"in n)||n.type!=="image"?[]:"data"in n&&typeof n.data=="string"?[{type:"image",data:n.data,mimeType:typeof n.mimeType=="string"?n.mimeType:void 0}]:"source"in n&&n.source&&typeof n.source=="object"&&"type"in n.source&&n.source.type==="base64"&&"data"in n.source&&typeof n.source.data=="string"?[{type:"image",data:n.source.data,mimeType:typeof n.source.media_type=="string"?n.source.media_type:void 0}]:[])}function u0e({images:e}){return f.jsx("div",{className:"flex flex-col gap-3",children:e.map((t,n)=>{const r=t.mimeType||"image/png";return f.jsx("div",{className:"overflow-hidden rounded-lg border border-border bg-muted/20",children:f.jsx("img",{src:`data:${r};base64,${t.data}`,alt:`Read result ${n+1}`,className:"max-h-[50vh] w-full object-contain bg-background"})},`${r}:${n}`)})})}function Qb({message:e,isLoading:t=!1,localPath:n}){var w;const r=e.result!==void 0,i=!r&&t,s=v.useMemo(()=>{if(e.toolKind==="skill")return e.input.skill;if(e.toolKind==="glob")return`Search files ${e.input.pattern==="**/*"?"in all directories":`matching ${e.input.pattern}`}`;if(e.toolKind==="grep"){const C=e.input.pattern,E=e.input.outputMode;return E==="count"?`Count \`${C}\` occurrences`:E==="content"?`Find \`${C}\` in text`:`Find \`${C}\` in files`}return e.toolKind==="bash"?e.input.description||(e.input.command?JQ(e.input.command):"Bash"):e.toolKind==="web_search"?e.input.query||"Web Search":e.toolKind==="read_file"?`Read ${av(e.input.filePath,n)}`:e.toolKind==="write_file"?`Write ${av(e.input.filePath,n)}`:e.toolKind==="edit_file"?`Edit ${av(e.input.filePath,n)}`:e.toolKind==="delete_file"?`Delete ${av(e.input.filePath,n)}`:e.toolKind==="mcp_generic"?`${IS(e.input.tool)} from ${IS(e.input.server)}`:e.toolKind==="subagent_task"&&e.input.subagentType||e.toolName},[e.input,e.toolKind,e.toolName,n]),o=v.useMemo(()=>e.toolKind==="subagent_task",[e.toolKind]),l=v.useMemo(()=>{if(e.toolKind==="skill")return e.input.skill},[e.input,e.toolKind]),c=e.toolKind==="bash",u=e.toolKind==="write_file",p=e.toolKind==="edit_file",h=e.toolKind==="delete_file",g=e.toolKind==="read_file",b=v.useMemo(()=>{if(typeof e.result=="string")return e.result;if(!e.result)return"";if(typeof e.result=="object"&&e.result!==null&&"content"in e.result){const C=e.result.content;if(typeof C=="string")return C}return JSON.stringify(e.result,null,2)},[e.result]),x=v.useMemo(()=>{if(!g)return[];if(e.result&&typeof e.result=="object"&&"blocks"in e.result){const C=e.result.blocks;if(Array.isArray(C)){const E=$D(C);if(E.length>0)return E}}return $D(e.rawResult)},[g,e.rawResult,e.result]),_=v.useMemo(()=>{switch(e.toolKind){case"bash":return e.input.command;case"write_file":case"delete_file":return e.input.content;default:return JSON.stringify(e.input,null,2)}},[e]);return f.jsx(Aa,{className:"w-full",children:f.jsxs(c0,{expandedContent:f.jsx(u0,{className:"my-4 text-sm",children:f.jsxs("div",{className:"flex flex-col gap-2",children:[p?f.jsx(yv,{content:"",isDiff:!0,oldString:e.input.oldString,newString:e.input.newString}):h?f.jsx(yv,{content:e.input.content}):!g&&!u&&f.jsx(iD,{label:c?f.jsxs("span",{className:"flex items-center gap-2 w-full",children:[f.jsx("span",{children:"Command"}),!!e.input.timeoutMs&&f.jsxs("span",{className:"text-muted-foreground",children:["timeout: ",String(e.input.timeoutMs),"ms"]}),!!e.input.runInBackground&&f.jsx("span",{className:"text-muted-foreground",children:"background"})]}):u?"Contents":"Input",copyText:_,children:_}),r&&g&&!e.isError&&(x.length>0?f.jsxs("div",{children:[f.jsx("span",{className:"font-medium text-muted-foreground",children:"Image"}),f.jsx("div",{className:"mt-1",children:f.jsx(u0e,{images:x})})]}):f.jsx(yv,{content:b})),u&&!e.isError&&f.jsx(yv,{content:e.input.content}),r&&!g&&!(u&&!e.isError)&&!(p&&!e.isError)&&!(h&&!e.isError)&&f.jsx(iD,{label:e.isError?"Error":"Result",copyText:b,children:b})]})}),children:[f.jsx("div",{className:"w-5 h-5 relative flex items-center justify-center",children:e.isError?f.jsx(io,{className:"size-4 text-destructive"}):o?f.jsx(gy,{className:"size-4 text-muted-icon"}):f.jsx(LB,{icon:MB(e.toolName),className:"size-4 text-muted-icon"})}),f.jsx(Pl,{className:"text-left transition-opacity duration-200 truncate",children:f.jsx(dm,{animate:i,shimmerWidth:Math.max(20,(((w=l||s)==null?void 0:w.length)??33)*3),children:l||s})})]})})}function d0e(e){if(e<1e3)return`${e}ms`;const t=Math.floor(e/1e3),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?`${n}h${r>0?` ${r}m`:""}`:r>0?`${r}m${i>0?` ${i}s`:""}`:`${i}s`}function HD({durationMs:e,prefix:t="Worked for"}){return e<=0?null:f.jsxs(uve,{children:[t," ",d0e(e)]})}function vF({message:e}){return e.success?f.jsx(HD,{durationMs:e.durationMs}):f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"px-4 py-3 mx-2 my-1 rounded-lg bg-destructive/10 border border-destructive/20 text-destructive text-sm",children:e.result||"An unknown error occurred."}),f.jsx(HD,{durationMs:e.durationMs,prefix:"Failed after"})]})}function f0e(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(2)} MB`}function h0e(e){return typeof e=="string"?e:JSON.stringify(e,null,2)}function p0e(e){return e.replace(/<persisted-output>\n?/g,"").replace(/\n?<\/persisted-output>/g,"")}function m0e({message:e,localPath:t}){if(e.kind==="tool"&&e.persisted){const n=p0e(h0e(e.rawResult??""));return f.jsxs("div",{className:"rounded-md border border-border bg-muted/30 p-2 space-y-1 text-xs",children:[f.jsxs("div",{className:"font-medium",children:[e.toolName,": output too large (",f0e(e.persisted.originalSize),") — saved to disk"]}),f.jsx("pre",{className:"text-[11px] whitespace-pre-wrap overflow-hidden max-h-48",children:n}),f.jsxs("a",{href:BE(e.persisted.filePath),className:"text-blue-500 hover:underline break-all",target:"_blank",rel:"noreferrer",children:["View full output (",e.persisted.filePath,")"]})]})}switch(e.kind){case"assistant_text":return f.jsx(gF,{message:e});case"tool":return f.jsx(Qb,{message:e,isLoading:!1,localPath:t});case"result":return f.jsx(vF,{message:e});default:return null}}function g0e(e){switch(e){case"AUTH_REQUIRED":return"Auth required";case"UNKNOWN_SUBAGENT":return"Unknown subagent";case"LOOP_DETECTED":return"Loop detected";case"DEPTH_EXCEEDED":return"Depth exceeded";case"TIMEOUT":return"Timeout";case"PROVIDER_ERROR":return"Provider error";case"INTERRUPTED":return"Interrupted";case"USER_CANCELLED":return"Cancelled by you";default:return"Error"}}function v0e({error:e,runId:t,onRetry:n,onOpenSettings:r}){const i=e.code==="TIMEOUT"||e.code==="PROVIDER_ERROR",s=e.code==="AUTH_REQUIRED";return f.jsxs("div",{"data-testid":`subagent-error:${t}`,className:"rounded-md border border-destructive/40 bg-destructive/5 p-3 text-sm",children:[f.jsxs("div",{className:"flex items-center gap-2 font-medium text-destructive",children:[f.jsx(fb,{className:"h-4 w-4"}),f.jsx("span",{children:g0e(e.code)})]}),f.jsx("p",{className:"mt-1 text-foreground",children:e.message}),f.jsxs("div",{className:"mt-2 flex gap-2",children:[s&&r&&f.jsxs("button",{type:"button",onClick:r,className:"inline-flex items-center gap-1 text-xs underline",children:[f.jsx(jW,{className:"h-3 w-3"})," Open settings"]}),i&&n&&f.jsxs("button",{type:"button",onClick:n,className:"inline-flex items-center gap-1 text-xs underline",children:[f.jsx(yG,{className:"h-3 w-3"})," Retry"]})]})]})}function b0e({question:e,currentIndex:t,totalQuestions:n,onBack:r,children:i}){const s=r&&t>0;return f.jsxs("div",{className:"rounded-2xl border border-border overflow-hidden",children:[f.jsxs("div",{className:"relative",children:[f.jsxs("h3",{className:"font-medium text-foreground text-sm p-3 px-4 bg-card border-b border-border text-foreground flex flex-row items-center gap-2",children:[s?f.jsx("button",{onClick:r,className:" text-muted-foreground hover:opacity-60 transition-all flex items-center",children:f.jsx(_V,{className:"h-4 w-4 -ml-0.5",strokeWidth:3})}):n>1?f.jsxs("span",{className:"font-bold text-muted-foreground whitespace-nowrap",children:[t+1," of ",n]}):null,e]}),n>1&&f.jsx("div",{className:"absolute bottom-0 left-0 right-0 h-0.5 bg-border",children:f.jsx("div",{className:"h-full bg-muted-foreground/40 transition-all duration-300",style:{width:`${t/n*100}%`}})})]}),i]})}function UD({label:e,description:t}){return f.jsxs(f.Fragment,{children:[f.jsx("span",{className:"text-foreground text-sm",children:e}),t&&f.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:t})]})}function bF({selected:e,multiSelect:t,onClick:n}){return f.jsx("button",{type:"button",onClick:n,className:me("flex-shrink-0 w-5 h-5 border-1 flex items-center justify-center",t?"rounded":"rounded-full",e?"border-transparent bg-foreground":"border-muted-foreground/50 bg-background",n&&e&&"cursor-pointer"),children:e&&f.jsx(yi,{strokeWidth:3,className:"translate-y-[0.5px] h-3 w-3 text-white dark:text-background"})})}function y0e({option:e,selected:t,multiSelect:n,onClick:r,isLast:i}){const s="w-full text-left p-3 pt-2.5 pl-4 pr-5 bg-background",o=i?"":"border-b border-border";return r?f.jsx("button",{onClick:r,className:me(s,o,"transition-all cursor-pointer"),children:f.jsxs("div",{className:"flex items-center justify-between gap-3",children:[f.jsx("div",{className:"flex-1 min-w-0",children:f.jsx(UD,{label:e.label,description:e.description})}),f.jsx(bF,{selected:t,multiSelect:n})]})}):f.jsx("div",{className:me(s,o),children:f.jsx(UD,{label:e.label,description:e.description})})}function x0e(e){return e==null?void 0:e.answers}function ps(e){return e.id||e.question}function yF({message:e,onSubmit:t,isLatest:n}){var F,W;const r=l0(),i=e.input.questions,s=!!e.result,o=x0e(e.result),l=((F=e.result)==null?void 0:F.discarded)===!0,[c,u]=v.useState(0),[p,h]=v.useState({}),[g,b]=v.useState({}),[x,_]=v.useState(o??null),[w,C]=v.useState(s),E=(X,I)=>{var ae;const G=(ae=g[X])==null?void 0:ae.trim(),ee=p[X]||"",H=I||i.find(J=>ps(J)===X);if(H!=null&&H.multiSelect)return[ee,G].filter(Boolean).flatMap(J=>J.split(", ").filter(Boolean));const ue=G||ee;return ue?[ue]:[]},k=X=>{const I=p[ps(X)]||"";return X.multiSelect?I.split(", ").filter(Boolean):[I]},R=(X,I)=>{const G=ps(X);if(X.multiSelect){const ee=p[G]?p[G].split(", ").filter(Boolean):[],H=ee.includes(I)?ee.filter(ue=>ue!==I):[...ee,I];h({...p,[G]:H.join(", ")})}else h({...p,[G]:I}),b({...g,[G]:""}),c<i.length-1&&setTimeout(()=>u(c+1),150)},N=(X,I)=>{const G=ps(X);b({...g,[G]:I}),I&&!X.multiSelect&&h({...p,[G]:""})},A=X=>{const I=ps(X);X.multiSelect&&g[I]&&b({...g,[I]:""})},M=i.every(X=>E(ps(X),X).length>0),D=i[c],U=c===i.length-1,j=D&&E(ps(D),D).length>0,P=()=>{c<i.length-1&&u(c+1)},z=()=>{c>0&&u(c-1)},O=()=>{if(!M)return;const X={};for(const I of i){const G=ps(I);X[G]=E(G,I)}_(X),C(!0),t(e.toolId,i,X)},$=X=>{if(X.key==="Enter"&&!(!D||!j)){if(X.preventDefault(),U){O();return}P()}};if(w||s){const X=o||x||{};return f.jsx("div",{className:"w-full",children:f.jsxs("div",{className:"rounded-2xl border border-border overflow-hidden",children:[f.jsxs("div",{className:"font-medium text-sm p-3 px-4 pr-5 bg-muted border-b border-border flex flex-row items-center justify-between",children:[f.jsxs("p",{children:["Question",i.length!==1?"s":""]}),f.jsx("p",{className:"",children:l?"Discarded":"Answers"})]}),i.map((I,G)=>{const ee=X[ps(I)]||X[I.question]||[],H=G===i.length-1;return f.jsxs("div",{className:me("w-full p-3 pt-2.5 pl-4 pr-5 bg-background flex items-center justify-between gap-3",!H&&"border-b border-border"),children:[f.jsx("div",{className:"text-sm text-pretty",children:I.question}),ee.length>0&&f.jsx("div",{className:"text-sm font-medium text-right max-w-[50%] text-pretty",children:ee.join(", ")}),ee.length===0&&f.jsx("div",{className:"text-sm font-medium text-right italic",children:l?"Discarded":"No Response"})]},ps(I))})]})})}if(r.readonly)return f.jsx("div",{className:"w-full",children:f.jsxs("div",{className:"rounded-2xl border border-border overflow-hidden",children:[f.jsxs("div",{className:"font-medium text-sm p-3 px-4 pr-5 bg-muted border-b border-border flex flex-row items-center justify-between gap-3",children:[f.jsxs("p",{children:["Question",i.length!==1?"s":""]}),f.jsx("p",{className:"text-muted-foreground",children:"Awaiting response"})]}),i.map((X,I)=>{var G;return f.jsxs("div",{className:me("w-full p-3 pt-2.5 pl-4 pr-5 bg-background flex items-center justify-between gap-3",I<i.length-1&&"border-b border-border"),children:[f.jsx("div",{className:"text-sm text-pretty",children:X.question}),f.jsx("div",{className:"max-w-[50%] text-right text-xs text-muted-foreground text-pretty",children:((G=X.options)==null?void 0:G.map(ee=>ee.label).join(", "))||"Freeform response"})]},ps(X))})]})});if(!n)return f.jsx("div",{className:"w-full py-2",children:f.jsxs("div",{className:"flex items-center gap-2",children:[f.jsx(w5,{className:"h-4 w-4 text-muted-foreground"}),f.jsx("span",{className:"text-sm text-muted-foreground",children:"Questions pending (newer question active)"})]})});if(!D)return null;const V=k(D),B=g[ps(D)]||"";return f.jsxs("div",{className:"w-full space-y-3",children:[f.jsxs(b0e,{question:D.question,currentIndex:c,totalQuestions:i.length,onBack:c>0?z:void 0,children:[(W=D.options)==null?void 0:W.map(X=>f.jsx(y0e,{option:X,selected:V.includes(X.label),multiSelect:D.multiSelect,onClick:()=>R(D,X.label)},X.label)),f.jsx("div",{className:"transition-all bg-background",children:f.jsxs("div",{className:"flex pr-5 items-center justify-between gap-3",children:[f.jsx("input",{type:"text",value:B,onChange:X=>N(D,X.target.value),onKeyDown:$,placeholder:"Other...",className:"flex-1 px-3 !py-1 pl-4 min-h-[55px] min-w-0 text-sm bg-transparent outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background rounded-md text-foreground placeholder:text-muted-foreground"}),f.jsx(bF,{selected:!!B,multiSelect:D.multiSelect,onClick:D.multiSelect&&B?()=>A(D):void 0})]})})]}),f.jsxs("div",{className:"flex justify-end gap-2 mx-2",children:[!U&&j&&(D.multiSelect||!!B)&&f.jsx(Ge,{size:"sm",onClick:P,children:"Next"}),U&&f.jsx(Ge,{size:"sm",onClick:O,disabled:!M,className:me(!M&&"opacity-50 cursor-not-allowed","rounded-full"),children:"Submit"})]})]})}function xF({message:e,onConfirm:t,isLatest:n}){const r=l0(),i=!!e.result,[s,o]=v.useState(!1),[l,c]=v.useState(!1),[u,p]=v.useState(!1),[h,g]=v.useState(""),b=v.useRef(null),x=e.input;v.useEffect(()=>{u&&b.current&&b.current.focus()},[u]);const _=async()=>{x!=null&&x.plan&&(await navigator.clipboard.writeText(x.plan),c(!0),setTimeout(()=>c(!1),2e3))},w=i?e.result:null,C=(w==null?void 0:w.discarded)===!0;return f.jsxs("div",{className:"flex flex-col gap-3",children:[f.jsxs("div",{className:"relative rounded-2xl border border-border overflow-hidden group/plan",children:[(x==null?void 0:x.plan)&&f.jsx(Ge,{variant:"ghost",size:"icon","aria-label":l?"Copied":"Copy plan",className:me("absolute top-2 right-2 z-10 h-11 w-11 md:h-8 md:w-8 rounded-md text-muted-foreground opacity-100 md:opacity-0 md:group-hover/plan:opacity-100 transition-opacity [@media(hover:none)]:!opacity-100",!l&&"hover:text-foreground",l&&"hover:!bg-transparent hover:!border-transparent"),onClick:_,children:l?f.jsx(yi,{className:"h-4 w-4 text-success"}):f.jsx(jl,{className:"h-4 w-4"})}),f.jsxs("div",{className:me("!pt-5 !pb-0 px-4 md:py-4.5 md:px-5.5 bg-muted dark:bg-card overflow-scroll no-pre-highlight transition-all",i&&!s?"max-h-[min(400px,40vh)] ":"",i?"hover:!pb-[32px]":""),children:[i&&f.jsxs(Ge,{variant:"ghost",className:"absolute z-10 bottom-2 pr-2.5 !pl-3.5 h-[34px] inline-flex gap-1 text-sm left-[50%] -translate-x-[50%] text-muted-foreground backdrop-blur-sm hover:text-foreground opacity-0 group-hover/plan:opacity-100 transition-all rounded-full border border-border",onClick:()=>o(!s),children:[s?"Show Less":"Show More",f.jsx(Gd,{className:`size-3.5 transition-transform ${s?"rotate-180":""}`})]}),x!=null&&x.plan?f.jsxs("div",{className:"prose prose-sm dark:prose-invert max-w-none",children:[f.jsx(tu,{remarkPlugins:hf,components:pf,children:x.plan}),f.jsx("div",{className:"mt-5"})]}):f.jsx("p",{className:"text-sm text-muted-foreground",children:"No plan provided"})]})]}),i?f.jsx("div",{className:"flex justify-end mx-2",children:f.jsxs("span",{className:"pl-4 inline text-sm font-medium bg-background text-foreground/60 border border-border py-1.5 px-3 rounded-[20px] leading-relaxed max-w-[85%] sm:max-w-[80%]",children:[f.jsx("em",{children:C?"Discarded":w!=null&&w.clearContext?"Approved & Cleared Context":w!=null&&w.confirmed?"Approved":w!=null&&w.message?`Adjusted: "${w.message}"`:"Adjusted Plan"}),f.jsx(zV,{className:"inline h-4 w-4 ml-1.5 -mt-0.5"})]})}):n?r.readonly?f.jsx("div",{className:"flex justify-end mx-2",children:f.jsx("span",{className:"inline text-sm text-muted-foreground italic",children:"Plan pending in original session"})}):f.jsxs("div",{className:"flex flex-col gap-3",children:[!u&&f.jsxs("div",{className:"flex flex-col md:flex-row items-stretch md:items-center justify-end gap-2 mx-2",children:[f.jsxs(Ge,{size:"sm",onClick:()=>t(e.toolId,!0,!0),className:"rounded-full bg-primary text-background pr-4 md:order-last",children:[f.jsx(mV,{className:"h-4 w-4 mr-1.5"}),"Approve & Clear"]}),f.jsxs("div",{className:"flex items-stretch md:items-center gap-2 md:contents",children:[f.jsxs(Ge,{size:"sm",variant:"outline",onClick:()=>p(!0),className:"rounded-full border-border flex-1 md:flex-initial md:order-first",children:[f.jsx(Hp,{className:"h-4 w-4 mr-1.5"}),"Suggest Edits"]}),f.jsxs(Ge,{size:"sm",variant:"outline",onClick:()=>t(e.toolId,!0),className:"rounded-full border-border flex-1 md:flex-initial",children:[f.jsx(yi,{className:"h-4 w-4 mr-1.5"}),"Approve"]})]})]}),u&&f.jsxs("div",{className:"flex flex-col gap-2",children:[f.jsx("textarea",{ref:b,value:h,onChange:E=>g(E.target.value),onKeyDown:E=>{E.key==="Enter"&&!E.shiftKey&&h.trim()&&(E.preventDefault(),t(e.toolId,!1,void 0,h.trim())),E.key==="Escape"&&(p(!1),g(""))},placeholder:"Describe what you'd like to change...",rows:3,className:"w-full rounded-2xl border border-border bg-muted dark:bg-card px-4 py-3 text-sm text-foreground placeholder:text-muted-foreground resize-none outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"}),f.jsxs("div",{className:"flex items-center justify-end gap-2 mx-2",children:[f.jsx(Ge,{size:"sm",variant:"ghost",onClick:()=>{p(!1),g("")},className:"rounded-full text-muted-foreground",children:"Cancel"}),f.jsxs(Ge,{size:"sm",disabled:!h.trim(),onClick:()=>t(e.toolId,!1,void 0,h.trim()),className:"rounded-full bg-primary text-background disabled:opacity-50 disabled:pointer-events-none",children:[f.jsx(EG,{className:"h-4 w-4 mr-1.5"}),"Adjust Plan"]})]})]})]}):f.jsx("div",{className:"flex justify-end mx-2",children:f.jsx("span",{className:"inline text-sm text-muted-foreground italic",children:"Plan pending (newer prompt active)"})})]})}function _0e({pendingTool:e,onAskUserQuestionSubmit:t,onExitPlanModeSubmit:n}){if(e.toolKind==="ask_user_question"){const r=e.input,i={id:e.toolUseId,kind:"tool",toolKind:"ask_user_question",toolName:"AskUserQuestion",toolId:e.toolUseId,input:{questions:r.questions??[]},timestamp:new Date(e.requestedAt).toISOString()};return f.jsxs("div",{"data-testid":`subagent-pending-tool:${e.toolUseId}`,children:[f.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground mb-1",children:"awaiting your response"}),f.jsx(yF,{message:i,onSubmit:t,isLatest:!0})]})}if(e.toolKind==="exit_plan_mode"){const r=e.input,i={id:e.toolUseId,kind:"tool",toolKind:"exit_plan_mode",toolName:"ExitPlanMode",toolId:e.toolUseId,input:{plan:r.plan,summary:r.summary},timestamp:new Date(e.requestedAt).toISOString()};return f.jsxs("div",{"data-testid":`subagent-pending-tool:${e.toolUseId}`,children:[f.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground mb-1",children:"awaiting your response"}),f.jsx(xF,{message:i,onConfirm:(s,o,l,c)=>n(s,{confirmed:o,clearContext:l,message:c}),isLatest:!0})]})}return null}function _F({run:e,indentDepth:t,localPath:n,onOpenSettings:r,onRetry:i,onSubagentAskUserQuestionSubmit:s,onSubagentExitPlanModeSubmit:o,onCancelSubagentRun:l}){var h;const c=lF(e.entries),u=c.some(g=>g.kind==="assistant_text"),p=e.status==="running"&&u;return f.jsxs("div",{"data-testid":`subagent-message:${e.runId}`,className:me("border-l-2 border-accent pl-3 py-2 space-y-2"),style:{marginLeft:`${t*24}px`},children:[f.jsxs("header",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[f.jsx(qC,{className:"h-3.5 w-3.5"}),f.jsx("span",{children:e.subagentName}),f.jsxs("span",{className:"opacity-60",children:[e.provider,e.model?`/${e.model}`:""]}),((h=e.usage)==null?void 0:h.outputTokens)!=null&&f.jsxs("span",{className:"opacity-60",children:["· ",e.usage.inputTokens??0,"↑ ",e.usage.outputTokens,"↓"]}),e.status==="running"&&f.jsx("span",{className:"ml-auto inline-block animate-pulse",children:p?"streaming...":"running..."}),l&&e.status==="running"&&f.jsx("button",{type:"button","data-testid":`subagent-cancel:${e.runId}`,"aria-label":"Cancel subagent",onClick:()=>l(e.chatId,e.runId),className:"text-muted-foreground hover:text-foreground",children:f.jsx(io,{className:"h-3.5 w-3.5"})})]}),c.map(g=>f.jsx(m0e,{message:g,localPath:n},g.id)),e.pendingTool&&f.jsx(_0e,{pendingTool:e.pendingTool,onAskUserQuestionSubmit:(g,b,x)=>s==null?void 0:s(e.runId,g,b,x),onExitPlanModeSubmit:(g,b)=>o==null?void 0:o(e.runId,g,b)}),c.length===0&&e.finalText&&f.jsxs("div",{className:me("whitespace-pre-wrap text-sm",p&&"text-foreground/80"),children:[e.finalText,p&&f.jsx("span",{className:"ml-0.5 inline-block w-2 animate-pulse",children:"▍"})]}),e.status==="failed"&&e.error&&f.jsx("div",{children:f.jsx(v0e,{error:e.error,runId:e.runId,subagentId:e.subagentId,onOpenSettings:r,onRetry:i})})]})}function w0e(e){var n;const t=e.match(/^<system-message>\s*([\s\S]*?)\s*<\/system-message>\s*([\s\S]*)$/);return t?{systemMessage:((n=t[1])==null?void 0:n.trim())||null,body:t[2]??""}:{systemMessage:null,body:e}}const S0e=v.memo(function({content:t,attachments:n=[],steered:r=!1,autoContinue:i}){const[s,o]=v.useState(null),l=l0(),c=v.useMemo(()=>w0e(t),[t]),u=l.attachmentMode==="metadata",p=!l.readonly||l.attachmentMode==="bundle",h=v.useMemo(()=>n.filter(w=>w.kind==="image"&&(w.contentUrl||u)),[n,u]),g=v.useMemo(()=>n.filter(w=>w.kind!=="image"||!w.contentUrl&&!u),[n,u]),b=n.find(w=>w.id===s)??null,x=b?um(b,"user_attachment"):null;function _(w){if(!p||!w.contentUrl)return;if(cf(w).openInNewTab){typeof window<"u"&&window.open(new URL(w.contentUrl,document.baseURI||window.location.href).toString(),"_blank","noopener,noreferrer");return}o(w.id)}return f.jsxs(f.Fragment,{children:[f.jsxs("div",{className:"flex flex-col items-end gap-2",children:[h.length>0?f.jsx("div",{className:"flex max-w-[85%] sm:max-w-[80%] flex-wrap justify-end gap-3",children:h.map(w=>f.jsx(XE,{attachment:w,onClick:p?()=>_(w):void 0},w.id))}):null,g.length>0?f.jsx("div",{className:"flex max-w-[85%] sm:max-w-[80%] flex-wrap justify-end gap-2",children:g.map(w=>f.jsx(Lo,{attachment:w,onClick:p?()=>_(w):void 0},w.id))}):null,c.body||!c.body&&n.length===0&&t&&!c.systemMessage?f.jsxs("div",{className:"flex max-w-[85%] items-center gap-2 sm:max-w-[80%]",children:[r?f.jsx(cq,{"aria-label":"Sent mid-turn",className:"size-3.5 shrink-0 text-muted-foreground"}):null,f.jsx("div",{className:"min-w-0 flex-1 rounded-[20px] border border-border bg-muted px-3.5 py-1.5 text-primary prose prose-sm prose-invert [&_p]:whitespace-pre-line",children:f.jsx(tu,{remarkPlugins:hf,components:pf,children:c.body})})]}):null,i?f.jsx("span",{className:"text-xs text-muted-foreground opacity-70",children:"auto-sent"}):null]}),f.jsx(ff,{source:x,open:x!==null,onOpenChange:w=>!w&&o(null)})]})});function C0e({json:e}){return f.jsx("div",{className:"flex gap-3 justify-start",children:f.jsx("div",{className:"flex-1 max-w-[90%]",children:f.jsx("pre",{className:"text-xs font-mono whitespace-pre-wrap break-words bg-muted rounded-lg p-3 overflow-auto max-h-96",children:e})})})}function wF({title:e,count:t,children:n,badge:r}){const[i,s]=v.useState(!1);return t===0?null:f.jsxs("div",{className:"flex flex-col gap-1.5",children:[f.jsxs("button",{onClick:()=>s(!i),className:"flex items-center gap-1 cursor-pointer group/section hover:opacity-60 transition-opacity",children:[f.jsx(Do,{className:me("h-3.5 w-3.5 text-muted-foreground transition-transform duration-200",i&&"rotate-90")}),f.jsx("span",{className:"text-muted-foreground font-medium",children:e}),f.jsx("span",{className:"text-muted-foreground/60",children:t}),r]}),i&&f.jsx("div",{className:"ml-5",children:n})]})}function Kw({title:e,items:t,icon:n,getIcon:r}){return t.length===0?null:f.jsx(wF,{title:e,count:t.length,children:f.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.map(i=>f.jsx(DB,{icon:r?r(i):n,children:i},i))})})}function k0e(e){const t=e.match(/^mcp__([^_]+)__(.+)$/);return t?{server:t[1],tool:t[2]}:null}function SF({status:e}){const t=e==="connected"?"bg-success":e==="pending"?"bg-warning":"bg-destructive";return f.jsx("span",{className:me("inline-block h-2 w-2 rounded-full shrink-0",t)})}function E0e(e){switch(e){case"connected":return"Connected";case"failed":return"Failed";case"needs-auth":return"Needs auth";case"pending":return"Connecting...";case"disabled":return"Disabled";default:return e}}function VD({server:e}){const[t,n]=v.useState(!1),r=e.status==="connected";return f.jsxs("div",{className:"flex flex-col gap-1.5",children:[f.jsxs("button",{onClick:()=>r&&e.tools.length>0&&n(!t),className:me("flex items-center gap-1.5",r&&e.tools.length>0&&"cursor-pointer hover:opacity-60 transition-opacity"),children:[r&&e.tools.length>0&&f.jsx(Do,{className:me("h-3 w-3 text-muted-foreground transition-transform duration-200",t&&"rotate-90")}),f.jsx(SF,{status:e.status}),f.jsx("span",{className:"text-muted-foreground font-medium",children:IS(e.name)}),r?f.jsxs("span",{className:"text-muted-foreground/50",children:[e.tools.length," tools"]}):f.jsx("span",{className:"text-muted-foreground/50",children:E0e(e.status)})]}),!r&&e.error&&f.jsx("span",{className:"text-destructive ml-5",children:e.error}),t&&e.tools.length>0&&f.jsx("div",{className:"flex flex-wrap gap-1.5 ml-5",children:e.tools.map(i=>f.jsx(DB,{icon:MB(`mcp__${e.name}__${i}`),children:i},i))})]})}function T0e({servers:e}){if(e.length===0)return null;const t=e.filter(i=>i.status==="connected"),n=e.filter(i=>i.status!=="connected"),r=n.length>0?f.jsxs("span",{className:"flex items-center gap-1 ml-1",children:[f.jsx(SF,{status:"failed"}),f.jsxs("span",{className:"text-muted-foreground/60",children:[n.length," disconnected"]})]}):null;return f.jsx(wF,{title:"MCP Servers",count:e.length,badge:r,children:f.jsxs("div",{className:"flex flex-col gap-2",children:[t.map(i=>f.jsx(VD,{server:i},i.name)),n.map(i=>f.jsx(VD,{server:i},i.name))]})})}function R0e({rawJson:e}){const[t,n]=v.useState(!1);return f.jsxs("div",{className:"flex flex-col gap-1.5",children:[f.jsxs("button",{onClick:()=>n(!t),className:"flex items-center gap-1 cursor-pointer group/section hover:opacity-60 transition-opacity",children:[f.jsx(Do,{className:me("h-3.5 w-3.5 text-muted-foreground transition-transform duration-200",t&&"rotate-90")}),f.jsx("span",{className:"text-muted-foreground font-medium",children:"Raw Message"})]}),t&&f.jsx("pre",{className:"ml-5 text-xs whitespace-pre-wrap break-all border border-border rounded-md p-3 overflow-x-auto max-h-96 overflow-y-auto",children:e})]})}function N0e({message:e,rawJson:t}){const{coreTools:n,mcpServersWithTools:r}=v.useMemo(()=>{const i=new Map,s=[];for(const l of e.tools){const c=k0e(l);if(c){const u=i.get(c.server)||[];u.push(c.tool),i.set(c.server,u)}else s.push(l)}const o=e.mcpServers.map(l=>({name:l.name,status:l.status,error:l.error,tools:i.get(l.name)||[]}));return{coreTools:s,mcpServersWithTools:o}},[e.tools,e.mcpServers]);return f.jsx(Aa,{children:f.jsxs(c0,{expandedContent:f.jsx(u0,{className:"my-4 text-xs",children:f.jsxs("div",{className:"flex flex-col gap-3",children:[f.jsx(cve,{children:e.model}),f.jsx(Kw,{title:"Tools",items:n,getIcon:i=>F1[i]??AB}),f.jsx(Kw,{title:"Agents",items:e.agents,icon:gy}),f.jsx(Kw,{title:"Commands",items:e.slashCommands,icon:IG}),f.jsx(T0e,{servers:r}),t&&f.jsx(R0e,{rawJson:t})]})}),children:[f.jsx(iV,{className:"h-5 w-5 text-logo"}),f.jsx(Pl,{children:"Session Started"})]})})}function A0e({message:e}){return f.jsx(Aa,{className:"hidden",children:f.jsxs(c0,{expandedContent:f.jsx(u0,{className:"my-4 text-xs",children:f.jsx("pre",{className:"font-mono whitespace-pre-wrap break-all bg-muted border border-border rounded-lg p-2 max-h-64 overflow-auto",children:JSON.stringify(e.accountInfo,null,2)})}),children:[f.jsx("div",{className:"size-5 flex justify-center items-center ",children:f.jsx(gy,{className:"h-4 w-4 text-muted-foreground"})}),f.jsx(Pl,{children:"Account"})]})})}const M0e={completed:{Icon:yi,iconClass:"text-success",textClass:"text-muted-foreground"},in_progress:{Icon:Cn,iconClass:"text-foreground animate-spin",textClass:"text-foreground font-medium"},pending:{Icon:TV,iconClass:"text-muted-foreground",textClass:"text-muted-foreground"}};function L0e({message:e}){const t=e.input.todos;return t.length?f.jsx("div",{className:"w-full",children:f.jsxs("div",{className:"rounded-2xl border border-border overflow-hidden",children:[f.jsxs("h3",{className:"font-medium text-foreground text-sm p-3 px-4 bg-card border-b border-border flex items-center gap-2",children:[f.jsx(IW,{className:"h-4 w-4 text-muted-foreground"}),"Progress"]}),f.jsx("div",{children:t.map((n,r)=>{const i=r===t.length-1,{Icon:s,iconClass:o,textClass:l}=M0e[n.status];return f.jsxs("div",{className:me("flex items-center gap-3 px-4 py-2.5 bg-background",!i&&"border-b border-border"),children:[f.jsx(s,{className:me("h-4 w-4 flex-shrink-0",o)}),f.jsx("span",{className:me("text-sm",l),children:n.status==="in_progress"?n.activeForm:n.content})]},r)})})]})}):null}function j0e({message:e}){const t=e.result,n=t==null?void 0:t.contentUrl,[r,i]=v.useState("idle"),[s,o]=v.useState(!1);if(v.useEffect(()=>{if(!n)return;const _=new AbortController;return fetch(n,{method:"HEAD",signal:_.signal}).then(w=>{_.signal.aborted||i(w.ok?"ready":"missing")}).catch(()=>{}),()=>_.abort()},[n]),!t||!n)return null;const l={id:`offer-download-${e.toolId}`,kind:"file",displayName:t.displayName||t.fileName,absolutePath:t.relativePath,relativePath:t.relativePath,contentUrl:n,mimeType:t.mimeType??"application/octet-stream",size:t.size},c=uf(l),u=t0(c,t.mimeType),p=t.size>0?mf(t.size):null,h=f.jsxs(f.Fragment,{children:[u,p?f.jsxs(f.Fragment,{children:[" · ",f.jsx("span",{className:"tabular-nums",children:p})]}):null]});if(r==="missing")return f.jsx("div",{className:"flex","data-testid":"offer-download-link",children:f.jsx(Lo,{attachment:l,disabledReason:"File no longer available"})});if(!cf(l).openInNewTab){const _=`Preview ${l.displayName}, ${u}${p?`, ${p}`:""}`;return f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"flex","data-testid":"offer-download-link",children:f.jsx(Lo,{attachment:l,onClick:()=>o(!0),meta:h,ariaLabel:_})}),f.jsx(ff,{source:s?um(l,"offer_download"):null,open:s,onOpenChange:o})]})}const x=["Download",l.displayName,u,p].filter(Boolean);return f.jsx("div",{className:"flex","data-testid":"offer-download-link",children:f.jsx(Lo,{attachment:l,href:n,download:t.fileName||void 0,meta:h,ariaLabel:x.join(", ")})})}const Yw=new Map;function D0e(e){const{cacheKey:t,enabled:n,ref:r,fetcher:i,rootMargin:s}=e,o=Yw.get(t),[l,c]=v.useState(o!==void 0?"ready":"idle"),[u,p]=v.useState(o!==void 0?o:null),[h,g]=v.useState(null),[b,x]=v.useState(t),_=v.useRef(null),w=v.useRef(t);if(w.current=t,b!==t){x(t);const C=Yw.get(t);c(C!==void 0?"ready":"idle"),p(C!==void 0?C:null),g(null)}return v.useEffect(()=>{if(!n||o!==void 0)return;const C=r.current;if(!C||typeof IntersectionObserver>"u")return;let E=!1;const k=t,R=new IntersectionObserver(N=>{for(const A of N){if(!A.isIntersecting)continue;if(R.disconnect(),E)return;const M=new AbortController;_.current=M,c("loading"),i(M.signal).then(D=>{E||w.current!==k||(Yw.set(k,D),p(D),c("ready"))}).catch(D=>{E||M.signal.aborted||w.current!==k||(g(D instanceof Error?D:new Error(String(D))),c("error"))});break}},{rootMargin:s??"200px"});return R.observe(C),()=>{var N;E=!0,R.disconnect(),(N=_.current)==null||N.abort(),_.current=null}},[o,t,n,r,i,s]),v.useMemo(()=>({state:l,data:u,error:h}),[l,u,h])}function I0e({source:e,onOpen:t,variant:n}){const r={id:e.id,kind:"file",displayName:e.displayName,mimeType:e.mimeType,size:e.size??0,contentUrl:e.contentUrl,relativePath:e.relativePath??"",absolutePath:""},i=uf(r),s=t0(i,e.mimeType),o=e.size&&e.size>0?mf(e.size):null;return i==="image"?f.jsx("button",{type:"button",onClick:t,"aria-label":`Preview ${e.displayName}`,className:"overflow-hidden rounded-xl border border-border bg-background",children:f.jsx("img",{src:e.contentUrl,alt:e.altText??e.displayName,loading:"lazy",className:"max-h-64 w-auto max-w-full object-contain"})}):n==="expanded"&&(i==="text"||i==="code"||i==="markdown"||i==="json"||i==="table")?f.jsx(P0e,{source:e,onOpen:t,friendlyType:s,sizeLabel:o}):f.jsx(Lo,{attachment:r,onClick:t,meta:f.jsxs(f.Fragment,{children:[s,o?f.jsxs(f.Fragment,{children:[" · ",f.jsx("span",{className:"tabular-nums",children:o})]}):null]}),ariaLabel:`Preview ${e.displayName}, ${s}${o?`, ${o}`:""}`})}const P0e=function({source:t,onOpen:n,friendlyType:r,sizeLabel:i}){const s=v.useRef(null),o=t.contentUrl,l=v.useCallback(async p=>{const h=await ME(o,4096);if(p.aborted)throw new Error("aborted");return h.content.slice(0,200)},[o]),c=D0e({ref:s,enabled:!0,cacheKey:`snippet:${t.id}|${t.contentUrl}|${t.size??0}`,fetcher:l}),u=c.state==="ready"&&typeof c.data=="string"?c.data:"";return f.jsxs("button",{ref:s,type:"button",onClick:n,"aria-label":`Preview ${t.displayName}`,className:"flex w-full max-w-md flex-col items-start gap-1 rounded-xl border border-border bg-background p-3 text-left hover:bg-accent/40",children:[f.jsx("div",{className:"text-sm font-medium text-foreground",children:t.displayName}),f.jsxs("div",{className:"text-[11px] text-muted-foreground",children:[r,i?` · ${i}`:""]}),u?f.jsx("pre",{className:"line-clamp-3 max-h-16 w-full whitespace-pre-wrap break-words text-[11px] text-muted-foreground",children:u}):null]})};function O0e({message:e}){const{status:t,revisedPrompt:n}=e.input,r=e.result,i=r==null?void 0:r.contentUrl,s=e.isError||t==="failed",[o,l]=v.useState(!1);if(!s&&!r&&t==="in_progress")return f.jsxs("div",{className:"flex flex-col gap-1 rounded-md border border-border/40 bg-muted/30 px-3 py-2 text-sm text-muted-foreground","data-testid":"image-generation-pending",children:[f.jsx("span",{children:"Generating image…"}),n?f.jsx("span",{className:"italic",children:n}):null]});if(s||!r||!i)return f.jsxs("div",{className:"flex flex-col gap-1 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm","data-testid":"image-generation-error",children:[f.jsx("span",{children:"Image generation failed."}),r!=null&&r.relativePath?f.jsx("span",{className:"text-muted-foreground",children:r.relativePath}):null]});const c={id:`image-gen-${e.toolId}`,contentUrl:i,displayName:r.fileName,fileName:r.fileName,relativePath:r.relativePath,mimeType:"image/png",origin:"image_generation",altText:n??void 0};return f.jsxs("figure",{className:"flex flex-col gap-2","data-testid":"image-generation",children:[f.jsx(I0e,{source:c,onOpen:()=>l(!0),variant:"expanded"}),n?f.jsx("figcaption",{className:"text-xs text-muted-foreground italic",children:n}):null,f.jsx(ff,{source:o?c:null,open:o,onOpenChange:l})]})}function z0e({message:e}){return f.jsx("div",{className:"flex items-center justify-end gap-2 text-sm text-muted-foreground",children:f.jsxs("div",{className:"inline-flex gap-1.5 items-center justify-center whitespace-nowrap text-sm font-medium bg-background text-foreground/60 border border-border h-9 pl-1 pr-4 rounded-full",children:[f.jsx(kV,{className:"h-4 w-4 ml-1.5"}),f.jsx("em",{children:"Interrupted"})]})})}function Zb({size:e=4}){return f.jsxs("svg",{className:"flex-1",viewBox:`0 0 100 ${e}`,preserveAspectRatio:"none",style:{height:`${e}px`},children:[f.jsx("pattern",{id:"zigzag",width:e,height:e,patternUnits:"userSpaceOnUse",children:f.jsx("path",{d:`M0 ${e} L${e/2} 0 L${e} ${e}`,fill:"none",stroke:"currentColor",strokeWidth:"0.5",className:"text-muted-foreground/30",style:{stroke:"currentColor"}})}),f.jsx("rect",{width:"100%",height:e,fill:"url(#zigzag)",className:"text-muted-foreground/30"})]})}function B0e(){return f.jsxs("div",{className:"flex items-center gap-3",children:[f.jsx(Zb,{}),f.jsx("span",{className:"text-[11px] tracking-widest text-muted-foreground uppercase flex-shrink-0",children:"Compacted"}),f.jsx(Zb,{})]})}function F0e(){return f.jsxs("div",{className:"flex items-center gap-3",children:[f.jsx(Zb,{}),f.jsx("span",{className:"text-[11px] tracking-widest text-muted-foreground uppercase flex-shrink-0",children:"Context Cleared"}),f.jsx(Zb,{})]})}function $0e({message:e}){return f.jsx(Aa,{children:f.jsxs(c0,{expandedContent:f.jsx(u0,{className:"my-4 text-xs",children:f.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none",children:f.jsx(tu,{remarkPlugins:hf,components:pf,children:e.summary})})}),children:[f.jsx("div",{className:"w-5 h-5 relative flex items-center justify-center",children:f.jsx(S5,{className:"h-4.5 w-4.5 text-muted-foreground"})}),f.jsx(Pl,{children:"Summarized"})]})})}const H0e={compacting:"Compacting..."};function U0e({message:e}){const t=H0e[e.status]||e.status;return f.jsxs(Aa,{className:"grid grid-cols-[auto_1fr] items-center gap-1.5 text-sm animate-pulse",children:[f.jsx("div",{className:"w-5 h-5 relative flex items-center justify-center",children:f.jsx(S5,{className:"h-4.5 w-4.5 text-muted-foreground"})}),f.jsx(Pl,{className:"text-left transition-opacity duration-200 truncate",children:t})]})}const V0e={read_file:{key:"read",singular:"read",plural:"reads"},edit_file:{key:"edit",singular:"edit",plural:"edits"},write_file:{key:"write",singular:"write",plural:"writes"},delete_file:{key:"delete",singular:"delete",plural:"deletes"},bash:{key:"bash",singular:"command",plural:"commands"},grep:{key:"grep",singular:"search",plural:"searches"},glob:{key:"glob",singular:"glob",plural:"globs"},subagent_task:{key:"task",singular:"agent",plural:"agents"},web_search:{key:"websearch",singular:"web search",plural:"web searches"},skill:{key:"skill",singular:"skill",plural:"skills"},todo_write:{key:"todo",singular:"todo update",plural:"todo updates"}},W0e={key:"other",singular:"tool call",plural:"tool calls"};function G0e(e){return V0e[e]??W0e}function q0e(e){const t=new Map,n=[];for(const r of e){const i=r.toolKind,s=G0e(i),o=t.get(s.key);o?o.count++:(t.set(s.key,{category:s,count:1}),n.push(s.key))}return n.map(r=>{const{category:i,count:s}=t.get(r);return`${s} ${s===1?i.singular:i.plural}`}).join(", ")}function K0e({messages:e,isLoading:t,localPath:n,expanded:r,onExpandedChange:i}){const s=v.useMemo(()=>q0e(e),[e]),l=e.some(c=>c.result===void 0)&&t;return f.jsx(Aa,{className:"w-full",children:f.jsxs("div",{className:"flex flex-col w-full",children:[f.jsx("button",{onClick:()=>i(!r),className:`group cursor-pointer grid grid-cols-[auto_1fr] items-center gap-1 text-sm ${!r&&!l?"hover:opacity-60 transition-opacity":""}`,children:f.jsxs("div",{className:"grid grid-cols-[auto_1fr] items-center gap-1.5",children:[f.jsx("div",{className:"w-5 h-5 relative flex items-center justify-center",children:f.jsx(Do,{className:`h-4.5 w-4.5 text-muted-icon transition-all duration-200 ${r?"rotate-90":""}`})}),f.jsx(Pl,{className:"text-left",children:f.jsx(dm,{animate:l,children:s})})]})}),r&&f.jsxs("div",{className:"my-4 flex flex-col gap-3",children:[e.map(c=>f.jsx(Qb,{message:c,isLoading:t,localPath:n},c.id)),e.length>5&&f.jsx("button",{onClick:()=>i(!1),className:"cursor-pointer grid grid-cols-[auto_1fr] items-center gap-1 text-xs hover:opacity-80 transition-opacity",children:f.jsxs("div",{className:"grid grid-cols-[auto_1fr] items-center gap-1.5",children:[f.jsx("div",{className:"w-5 h-5 relative flex items-center justify-center",children:f.jsx(Do,{className:"h-4.5 w-4.5 text-muted-icon -rotate-90"})}),f.jsx(Pl,{className:"text-left",children:"Collapse"})]})})]})]})})}function Y0e(e){if(e!=="system")return e}function Xw(e,t){const n=Y0e(t),r=new Intl.DateTimeFormat("en-GB",{timeZone:n,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hour12:!1}).formatToParts(new Date(e)),i=o=>{var l;return((l=r.find(c=>c.type===o))==null?void 0:l.value)??"00"};let s=i("hour");return s==="24"&&(s="00"),`${i("day")}/${i("month")}/${i("year")} ${s}:${i("minute")}`}const X0e=/^(\d{2})\/(\d{2})\/(\d{4}) (\d{2}):(\d{2})$/;function WD(e,t){if(e==="system")return-new Date(t).getTimezoneOffset();const n=new Intl.DateTimeFormat("en-US",{timeZone:e,hour12:!1,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}).formatToParts(new Date(t)),r=o=>{var l;return Number(((l=n.find(c=>c.type===o))==null?void 0:l.value)??0)};let i=r("hour");i===24&&(i=0);const s=Date.UTC(r("year"),r("month")-1,r("day"),i,r("minute"),r("second"));return Math.round((s-t)/6e4)}function Q0e(e,t){const n=X0e.exec(e.trim());if(!n)return null;const[,r,i,s,o,l]=n,c=Number(r),u=Number(i),p=Number(s),h=Number(o),g=Number(l);if(u<1||u>12||c<1||c>31||h>23||g>59)return null;const b=Date.UTC(p,u-1,c,h,g),x=WD(t,b),_=b-x*6e4,w=WD(t,_);return _-(w-x)*6e4}const Z0e={neutral:"border-border bg-card",muted:"border-border/50 bg-card/50 opacity-75",success:"border-emerald-500/30 bg-emerald-500/5",error:"border-destructive/40 bg-destructive/5"},J0e={primary:"default",secondary:"secondary",ghost:"ghost",destructive:"destructive"};function pa({title:e,description:t,body:n,errorMessage:r,tone:i="neutral",actions:s=[]}){const[o,l]=v.useState(null),[c,u]=v.useState(null),p=v.useCallback(async g=>{if(o)return;u(null);let b;try{b=g.onClick()}catch(x){console.error("[transcript-action-card] sync click threw",x),u(x instanceof Error?x.message:String(x));return}if(b instanceof Promise){l(g.id);try{await b}catch(x){console.error("[transcript-action-card] async click rejected",x),u(x instanceof Error?x.message:String(x))}finally{l(null)}}},[o]),h=o!==null;return f.jsxs("div",{"data-focus-fallback-ignore":!0,className:me("rounded-lg border px-4 py-3 text-sm space-y-2 transition-colors",Z0e[i]),children:[f.jsx("div",{className:"flex items-start justify-between gap-3",children:f.jsxs("div",{className:"space-y-1 min-w-0 flex-1",children:[f.jsx("div",{className:"font-medium leading-tight",children:e}),t?f.jsx("div",{className:"text-muted-foreground text-xs leading-snug",children:t}):null]})}),n?f.jsx("div",{className:"text-xs leading-snug",children:n}):null,r?f.jsx("div",{className:"text-destructive text-xs leading-snug",children:r}):null,c?f.jsx("div",{className:"text-destructive text-xs leading-snug",role:"alert",children:c}):null,s.length>0?f.jsx("div",{className:"flex flex-wrap gap-2 pt-1",children:s.map(g=>{const b=o===g.id;return f.jsxs(Ge,{type:"button",size:"sm",variant:J0e[g.variant??"ghost"],disabled:g.disabled||h&&!b,onClick:()=>{p(g)},className:"gap-1.5",children:[b?f.jsx(Cn,{className:"size-3.5 animate-spin"}):null,g.label]},g.id)})}):null]})}function exe({schedule:e,onAccept:t,onReschedule:n,onCancel:r}){const[i,s]=v.useState(()=>Xw(e.scheduledAt??e.resetAt,e.tz)),[o,l]=v.useState(!1),c=v.useMemo(()=>Q0e(i,e.tz),[i,e.tz]),u=c!==null&&c>Date.now(),p=c===null?"Use format dd/mm/yyyy hh:mm":u?null:"Time must be in the future";if(e.state==="fired"){const x=Xw(e.scheduledAt??e.resetAt,e.tz);return f.jsx(pa,{title:`Auto-continued at ${x}`,tone:"success"})}if(e.state==="cancelled")return f.jsx(pa,{title:"Auto-continue cancelled",tone:"muted"});if(e.state==="proposed"){const x=e.resetAt<=Date.now(),_=[{id:"schedule",label:"Schedule",variant:"primary",disabled:!u,onClick:()=>{c!==null&&t(c)}},{id:"dismiss",label:"Dismiss",variant:"ghost",onClick:()=>r()}];return f.jsx(pa,{title:"Rate limit hit — schedule auto-continue?",description:x?"Reset time has passed — accept to continue now.":void 0,body:f.jsxs("div",{className:"space-y-1",children:[f.jsx(Kn,{value:i,onChange:w=>s(w.target.value),placeholder:"dd/mm/yyyy hh:mm"}),p&&f.jsx("div",{className:"text-destructive text-xs",children:p})]}),actions:_})}const h=Xw(e.scheduledAt??e.resetAt,e.tz),g=e.tz==="system"?"local":e.tz;if(!o){const x=[{id:"change",label:"Change time",variant:"secondary",onClick:()=>l(!0)},{id:"cancel",label:"Cancel",variant:"ghost",onClick:()=>r()}];return f.jsx(pa,{title:`Auto-continue at ${h} (${g})`,actions:x})}const b=[{id:"save",label:"Save",variant:"primary",disabled:!u,onClick:()=>{c!==null&&(n(c),l(!1))}},{id:"back",label:"Back",variant:"ghost",onClick:()=>l(!1)}];return f.jsx(pa,{title:`Auto-continue at ${h} (${g})`,body:f.jsxs("div",{className:"space-y-1",children:[f.jsx(Kn,{value:i,onChange:x=>s(x.target.value),placeholder:"dd/mm/yyyy hh:mm"}),p&&f.jsx("div",{className:"text-destructive text-xs",children:p})]}),actions:b})}function txe({toolRequestId:e,questions:t,onAnswer:n}){const[r,i]=v.useState({});function s(u){return u.id??u.question}function o(u,p){const h=s(u);u.multiSelect?i(g=>{const b=g[h]??[],x=b.includes(p)?b.filter(_=>_!==p):[...b,p];return{...g,[h]:x}}):i(g=>({...g,[h]:[p]}))}function l(){const u={};for(const p of t){const h=s(p);u[h]=r[h]??[]}n(e,{kind:"answer",payload:{questions:t,answers:u}})}const c=t.every(u=>{var h;const p=s(u);return(((h=r[p])==null?void 0:h.length)??0)>0});return f.jsxs("div",{className:"rounded-2xl border border-border overflow-hidden",children:[f.jsxs("div",{className:"font-medium text-sm p-3 px-4 bg-muted border-b border-border flex items-center justify-between",children:[f.jsxs("span",{children:["Question",t.length!==1?"s":""]}),f.jsx("span",{className:"text-xs text-muted-foreground",children:"Reconnected — awaiting your response"})]}),t.map((u,p)=>{var x;const h=s(u),g=r[h]??[],b=p===t.length-1;return f.jsxs("div",{className:`bg-background px-4 py-3 ${b?"":"border-b border-border"}`,children:[f.jsx("p",{className:"text-sm font-medium mb-2",children:u.question}),u.options&&u.options.length>0?f.jsx("div",{className:"flex flex-wrap gap-2",children:u.options.map(_=>f.jsx("button",{onClick:()=>o(u,_.label),className:`rounded-full border px-3 py-1 text-xs transition-colors ${g.includes(_.label)?"border-foreground bg-foreground text-background":"border-border bg-background text-foreground hover:bg-muted"}`,children:_.label},_.label))}):f.jsx("input",{type:"text",className:"w-full rounded-md border border-border bg-muted px-3 py-1.5 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring",placeholder:"Type your answer...",value:((x=r[h])==null?void 0:x[0])??"",onChange:_=>{const w=_.target.value;i(C=>({...C,[h]:w?[w]:[]}))}})]},h)}),f.jsxs("div",{className:"flex justify-end gap-2 px-4 py-3 bg-background border-t border-border",children:[f.jsx(Ge,{size:"sm",variant:"outline",className:"rounded-full",onClick:()=>n(e,{kind:"deny",reason:"user_canceled"}),children:"Cancel"}),f.jsx(Ge,{size:"sm",className:"rounded-full",disabled:!c,onClick:l,children:"Submit"})]})]})}function nxe({toolRequestId:e,plan:t,onAnswer:n}){return f.jsxs("div",{className:"rounded-2xl border border-border overflow-hidden",children:[f.jsxs("div",{className:"font-medium text-sm p-3 px-4 bg-muted border-b border-border flex items-center justify-between",children:[f.jsx("span",{children:"Plan"}),f.jsx("span",{className:"text-xs text-muted-foreground",children:"Reconnected — awaiting your response"})]}),f.jsx("div",{className:"bg-background px-4 py-3",children:f.jsx("p",{className:"text-sm whitespace-pre-wrap",children:t})}),f.jsxs("div",{className:"flex justify-end gap-2 px-4 py-3 bg-background border-t border-border",children:[f.jsx(Ge,{size:"sm",variant:"outline",className:"rounded-full",onClick:()=>n(e,{kind:"deny",reason:"user_canceled"}),children:"Edit"}),f.jsx(Ge,{size:"sm",className:"rounded-full",onClick:()=>n(e,{kind:"answer",payload:{confirmed:!0}}),children:"Confirm"})]})]})}function rxe({toolRequestId:e,toolName:t,onAnswer:n}){return f.jsxs("div",{className:"flex items-center gap-3 rounded-2xl border border-border bg-background px-4 py-3 text-sm",children:[f.jsxs("span",{className:"text-muted-foreground flex-1",children:["Pending tool: ",f.jsx("span",{className:"font-mono text-foreground",children:t})]}),f.jsx("button",{className:"text-xs text-muted-foreground underline hover:text-foreground transition-colors",onClick:()=>n(e,{kind:"deny",reason:"user_canceled"}),children:"Cancel"})]})}function ixe({entry:e,onAnswer:t}){const{toolRequestId:n,toolName:r,arguments:i}=e;if(r==="mcp__kanna__ask_user_question"){const s=i.questions??[];return f.jsx(txe,{toolRequestId:n,questions:s,onAnswer:t})}if(r==="mcp__kanna__exit_plan_mode"){const s=typeof i.plan=="string"?i.plan:"";return f.jsx(nxe,{toolRequestId:n,plan:s,onAnswer:t})}return f.jsx(rxe,{toolRequestId:n,toolName:r,onAnswer:t})}const sxe=new Set(["AskUserQuestion","ExitPlanMode","TodoWrite"]);function GD(e){if(e.kind!=="tool")return!1;const t=e.toolName;return!sxe.has(t)}function oxe(e,{isFirstSystem:t,isFirstAccount:n,isLatestTodoWrite:r,hideResult:i,isFinalStatus:s}){let o=!e.hidden;if(o)switch(e.kind){case"system_init":o=t;break;case"account_info":o=n;break;case"tool":o=e.toolKind!=="todo_write"||r;break;case"result":o=!i&&(!e.success||e.durationMs>6e4);break;case"context_window_updated":o=!1;break;case"status":o=s;break;default:o=!0;break}return{isFirstSystem:t,isFirstAccount:n,isLatestTodoWrite:r,hideResult:i,isFinalStatus:s,shouldRender:o}}function axe(e,t){const n=e.findIndex(i=>i.kind==="system_init"),r=e.findIndex(i=>i.kind==="account_info");return e.map((i,s)=>{const o=e[s-1],l=e[s+1];return oxe(i,{isFirstSystem:n===s,isFirstAccount:r===s,isLatestTodoWrite:i.id===t.TodoWrite,hideResult:(l==null?void 0:l.kind)==="context_cleared"||(o==null?void 0:o.kind)==="context_cleared",isFinalStatus:s===e.length-1})})}function lxe(e,t){const n=[];let r=0;for(;r<e.length;){const i=e[r],s=t[r];if(s!=null&&s.shouldRender&&GD(i)){const o=[i],l=r;for(r+=1;r<e.length;){const c=e[r],u=t[r];if(!(u!=null&&u.shouldRender)){r+=1;continue}if(!GD(c))break;o.push(c),r+=1}o.length>=2?n.push({type:"tool-group",messages:o,startIndex:l}):n.push({type:"single",message:i,index:l});continue}n.push({type:"single",message:i,index:r}),r+=1}return n}function qD(e){var n;return e.type==="single"?e.message.id:`tool-group:${((n=e.messages[0])==null?void 0:n.id)??e.startIndex}`}function Qw(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>n===t[r])}function cxe(e,t){return e.id===t.id&&e.kind===t.kind&&e.displayName===t.displayName&&e.absolutePath===t.absolutePath&&e.relativePath===t.relativePath&&e.contentUrl===t.contentUrl&&e.mimeType===t.mimeType&&e.size===t.size}function uxe(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>cxe(n,t[r]))}function Od(e,t){var n,r;if(e===t)return!0;if(e.kind!==t.kind||e.id!==t.id||e.hidden!==t.hidden)return!1;switch(e.kind){case"user_prompt":return e.content===(t.kind==="user_prompt"?t.content:null)&&t.kind==="user_prompt"&&e.steered===t.steered&&((n=e.autoContinue)==null?void 0:n.scheduleId)===((r=t.autoContinue)==null?void 0:r.scheduleId)&&uxe(e.attachments,t.attachments);case"system_init":return t.kind==="system_init"&&e.provider===t.provider&&e.model===t.model&&Qw(e.tools,t.tools)&&Qw(e.agents,t.agents)&&Qw(e.slashCommands,t.slashCommands)&&e.debugRaw===t.debugRaw;case"account_info":return t.kind==="account_info"&&JSON.stringify(e.accountInfo)===JSON.stringify(t.accountInfo);case"assistant_text":return t.kind==="assistant_text"&&e.text===t.text;case"tool":return t.kind==="tool"&&e.toolKind===t.toolKind&&e.toolName===t.toolName&&e.toolId===t.toolId&&e.isError===t.isError&&JSON.stringify(e.input)===JSON.stringify(t.input)&&JSON.stringify(e.result)===JSON.stringify(t.result)&&JSON.stringify(e.rawResult)===JSON.stringify(t.rawResult);case"result":return t.kind==="result"&&e.success===t.success&&e.cancelled===t.cancelled&&e.result===t.result&&e.durationMs===t.durationMs&&e.costUsd===t.costUsd;case"status":return t.kind==="status"&&e.status===t.status;case"compact_summary":return t.kind==="compact_summary"&&e.summary===t.summary;case"context_window_updated":return t.kind==="context_window_updated"&&JSON.stringify(e.usage)===JSON.stringify(t.usage);case"compact_boundary":case"context_cleared":case"interrupted":return!0;case"unknown":return t.kind==="unknown"&&e.json===t.json;case"auto_continue_prompt":return t.kind==="auto_continue_prompt"&&e.scheduleId===t.scheduleId;case"pending_tool_request":return t.kind==="pending_tool_request"&&e.toolRequestId===t.toolRequestId&&e.toolName===t.toolName}}function dxe(e,t){return e.kind!==t.kind||e.id!==t.id?!1:e.kind==="single"&&t.kind==="single"?e.index===t.index&&e.isLoading===t.isLoading&&e.localPath===t.localPath&&e.isFirstSystem===t.isFirstSystem&&e.isFirstAccount===t.isFirstAccount&&e.isLatestAskUserQuestion===t.isLatestAskUserQuestion&&e.isLatestExitPlanMode===t.isLatestExitPlanMode&&e.isLatestTodoWrite===t.isLatestTodoWrite&&e.hideResult===t.hideResult&&e.isFinalStatus===t.isFinalStatus&&Od(e.message,t.message):e.kind==="tool-group"&&t.kind==="tool-group"?e.startIndex===t.startIndex&&e.isLoading===t.isLoading&&e.localPath===t.localPath&&e.messages.length===t.messages.length&&e.messages.every((n,r)=>Od(n,t.messages[r])):!1}function fxe(e,t){const n=new Map;let r=e.length!==t.byId.size;const i=e.map((s,o)=>{const l=t.byId.get(s.id),c=l&&dxe(l,s)?l:s;return n.set(s.id,c),!r&&t.result[o]!==c&&(r=!0),c});return r?{byId:n,result:i}:t}function hxe(e){const t=v.useRef({byId:new Map,result:[]}),n=v.useMemo(()=>fxe(e,t.current),[e]);return v.useLayoutEffect(()=>{t.current=n}),n.result}const CF=(e,t)=>{},pxe=v.memo(function({message:t,index:n,isLoading:r,localPath:i,isFirstSystem:s,isFirstAccount:o,isLatestAskUserQuestion:l,isLatestExitPlanMode:c,isLatestTodoWrite:u,hideResult:p,isFinalStatus:h,onAskUserQuestionSubmit:g,onExitPlanModeConfirm:b,onToolRequestAnswer:x=CF,schedules:_,onAutoContinueAccept:w,onAutoContinueReschedule:C,onAutoContinueCancel:E}){let k=null;if(t.kind==="user_prompt")k=f.jsx(S0e,{content:t.content,attachments:t.attachments,steered:t.steered,autoContinue:t.autoContinue},t.id);else switch(t.kind){case"auto_continue_prompt":{const R=_[t.scheduleId];if(!R){k=f.jsx("div",{className:"rounded border px-3 py-2 text-sm opacity-70",children:"Auto-continue expired"},t.id);break}k=f.jsx(exe,{schedule:R,onAccept:N=>w(t.scheduleId,N),onReschedule:N=>C(t.scheduleId,N),onCancel:()=>E(t.scheduleId)},t.id);break}case"unknown":k=f.jsx(C0e,{json:t.json},t.id);break;case"system_init":k=s?f.jsx(N0e,{message:t,rawJson:t.debugRaw},t.id):null;break;case"account_info":k=o?f.jsx(A0e,{message:t},t.id):null;break;case"assistant_text":k=f.jsx(gF,{message:t},t.id);break;case"tool":if(t.isError){k=f.jsx(Qb,{message:t,isLoading:r,localPath:i},t.id);break}if(t.toolKind==="ask_user_question"){k=f.jsx(yF,{message:t,onSubmit:g,isLatest:l},t.id);break}if(t.toolKind==="exit_plan_mode"){k=f.jsx(xF,{message:t,onConfirm:b,isLatest:c},t.id);break}if(t.toolKind==="todo_write"){k=u?f.jsx(L0e,{message:t},t.id):null;break}if(t.toolKind==="offer_download"&&t.result){k=f.jsx(j0e,{message:t},t.id);break}if(t.toolKind==="image_generation"){k=f.jsx(O0e,{message:t},t.id);break}k=f.jsx(Qb,{message:t,isLoading:r,localPath:i},t.id);break;case"result":k=p?null:f.jsx(vF,{message:t},t.id);break;case"context_window_updated":k=null;break;case"interrupted":k=f.jsx(z0e,{message:t},t.id);break;case"compact_boundary":k=f.jsx(B0e,{},t.id);break;case"context_cleared":k=f.jsx(F0e,{},t.id);break;case"compact_summary":k=f.jsx($0e,{message:t},t.id);break;case"status":k=h?f.jsx(U0e,{message:t},t.id):null;break;case"pending_tool_request":k=f.jsx(ixe,{entry:t,onAnswer:x},t.id);break}return k?f.jsx("div",{id:`msg-${t.id}`,className:"group relative","data-index":n,[gb]:"",children:k}):null},(e,t)=>e.index===t.index&&e.isLoading===t.isLoading&&e.localPath===t.localPath&&e.isFirstSystem===t.isFirstSystem&&e.isFirstAccount===t.isFirstAccount&&e.isLatestAskUserQuestion===t.isLatestAskUserQuestion&&e.isLatestExitPlanMode===t.isLatestExitPlanMode&&e.isLatestTodoWrite===t.isLatestTodoWrite&&e.hideResult===t.hideResult&&e.isFinalStatus===t.isFinalStatus&&e.onAskUserQuestionSubmit===t.onAskUserQuestionSubmit&&e.onExitPlanModeConfirm===t.onExitPlanModeConfirm&&e.onToolRequestAnswer===t.onToolRequestAnswer&&e.schedules===t.schedules&&e.onAutoContinueAccept===t.onAutoContinueAccept&&e.onAutoContinueReschedule===t.onAutoContinueReschedule&&e.onAutoContinueCancel===t.onAutoContinueCancel&&Od(e.message,t.message)),mxe=v.memo(function({id:t,messages:n,isLoading:r,localPath:i,expanded:s,onExpandedChange:o}){return f.jsx("div",{className:"group relative",[gb]:"",children:f.jsx(K0e,{messages:n,isLoading:r,localPath:i,expanded:s,onExpandedChange:l=>o(t,l)})})},(e,t)=>e.id===t.id&&e.startIndex===t.startIndex&&e.isLoading===t.isLoading&&e.localPath===t.localPath&&e.expanded===t.expanded&&e.onExpandedChange===t.onExpandedChange&&e.messages.length===t.messages.length&&e.messages.every((n,r)=>Od(n,t.messages[r])));function kF(e,{isLoading:t,localPath:n,latestToolIds:r}){const i=axe(e,r),s=lxe(e,i),o=[];for(const l of s){if(l.type==="tool-group"){o.push({kind:"tool-group",id:qD(l),startIndex:l.startIndex,messages:l.messages,isLoading:t&&l.messages.some(p=>p.kind==="tool"&&p.result===void 0),localPath:n});continue}const c=i[l.index];if(!c)continue;const u={kind:"single",id:qD(l),message:l.message,index:l.index,isLoading:l.message.kind==="tool"&&l.message.result===void 0&&t,localPath:n,isFirstSystem:c.isFirstSystem,isFirstAccount:c.isFirstAccount,isLatestAskUserQuestion:l.message.id===r.AskUserQuestion,isLatestExitPlanMode:l.message.id===r.ExitPlanMode,isLatestTodoWrite:c.isLatestTodoWrite,hideResult:c.hideResult,isFinalStatus:c.isFinalStatus};c.shouldRender&&o.push(u)}return o}const gxe={};function EF(e,t,n,r,i,s,o){const l=n.get(e.runId)??[];return f.jsxs(_n.Fragment,{children:[f.jsx(_F,{run:e,indentDepth:t,localPath:r,onSubagentAskUserQuestionSubmit:i,onSubagentExitPlanModeSubmit:s,onCancelSubagentRun:o}),l.map(c=>EF(c,t+1,n,r,i,s,o))]},e.runId)}const TF=v.memo(function({row:t,toolGroupExpanded:n,onToolGroupExpandedChange:r,onAskUserQuestionSubmit:i,onExitPlanModeConfirm:s,onToolRequestAnswer:o,schedules:l,onAutoContinueAccept:c,onAutoContinueReschedule:u,onAutoContinueCancel:p}){return t.kind==="tool-group"?f.jsx(mxe,{id:t.id,startIndex:t.startIndex,messages:t.messages,isLoading:t.isLoading,localPath:t.localPath,expanded:n??!1,onExpandedChange:r}):f.jsx(pxe,{message:t.message,index:t.index,isLoading:t.isLoading,localPath:t.localPath,isFirstSystem:t.isFirstSystem,isFirstAccount:t.isFirstAccount,isLatestAskUserQuestion:t.isLatestAskUserQuestion,isLatestExitPlanMode:t.isLatestExitPlanMode,isLatestTodoWrite:t.isLatestTodoWrite,hideResult:t.hideResult,isFinalStatus:t.isFinalStatus,onAskUserQuestionSubmit:i,onExitPlanModeConfirm:s,onToolRequestAnswer:o,schedules:l,onAutoContinueAccept:c,onAutoContinueReschedule:u,onAutoContinueCancel:p})},(e,t)=>{if(e.toolGroupExpanded!==t.toolGroupExpanded||e.onToolGroupExpandedChange!==t.onToolGroupExpandedChange||e.onAskUserQuestionSubmit!==t.onAskUserQuestionSubmit||e.onExitPlanModeConfirm!==t.onExitPlanModeConfirm||e.onToolRequestAnswer!==t.onToolRequestAnswer||e.schedules!==t.schedules||e.onAutoContinueAccept!==t.onAutoContinueAccept||e.onAutoContinueReschedule!==t.onAutoContinueReschedule||e.onAutoContinueCancel!==t.onAutoContinueCancel||e.row.kind!==t.row.kind||e.row.id!==t.row.id)return!1;if(e.row.kind==="tool-group"&&t.row.kind==="tool-group"){const n=e.row,r=t.row;return n.startIndex===r.startIndex&&n.isLoading===r.isLoading&&n.localPath===r.localPath&&n.messages.length===r.messages.length&&n.messages.every((i,s)=>Od(i,r.messages[s]))}return e.row.kind==="single"&&t.row.kind==="single"?e.row.index===t.row.index&&e.row.isLoading===t.row.isLoading&&e.row.localPath===t.row.localPath&&e.row.isFirstSystem===t.row.isFirstSystem&&e.row.isFirstAccount===t.row.isFirstAccount&&e.row.isLatestAskUserQuestion===t.row.isLatestAskUserQuestion&&e.row.isLatestExitPlanMode===t.row.isLatestExitPlanMode&&e.row.isLatestTodoWrite===t.row.isLatestTodoWrite&&e.row.hideResult===t.row.hideResult&&e.row.isFinalStatus===t.row.isFinalStatus&&Od(e.row.message,t.row.message):!1}),RF={},vxe=(e,t)=>{},bxe=(e,t)=>{},yxe=e=>{};function xxe({messages:e,isLoading:t,localPath:n,latestToolIds:r,onOpenLocalLink:i,onAskUserQuestionSubmit:s,onExitPlanModeConfirm:o,onToolRequestAnswer:l=CF,schedules:c=RF,onAutoContinueAccept:u=vxe,onAutoContinueReschedule:p=bxe,onAutoContinueCancel:h=yxe,onTunnelAccept:g,onTunnelStop:b,onTunnelRetry:x,subagentRuns:_=gxe,onSubagentAskUserQuestionSubmit:w,onSubagentExitPlanModeSubmit:C,onCancelSubagentRun:E}){const[k,R]=v.useState({}),N=v.useMemo(()=>kF(e,{isLoading:t,localPath:n,latestToolIds:r}),[t,r,n,e]),{runsByUserMessageId:A,childrenByParentRunId:M}=v.useMemo(()=>{const U=new Map,j=new Map;for(const z of Object.values(_))if(z.parentRunId===null){const O=U.get(z.parentUserMessageId)??[];O.push(z),U.set(z.parentUserMessageId,O)}else{const O=j.get(z.parentRunId)??[];O.push(z),j.set(z.parentRunId,O)}const P=(z,O)=>z.startedAt-O.startedAt||z.runId.localeCompare(O.runId);for(const z of U.values())z.sort(P);for(const z of j.values())z.sort(P);return{runsByUserMessageId:U,childrenByParentRunId:j}},[_]),D=v.useCallback((U,j)=>{R(P=>P[U]===j?P:{...P,[U]:j})},[]);return f.jsx(NB,{onOpenLocalLink:i,children:N.map(U=>{const j=U.kind==="single"&&U.message.kind==="user_prompt"?U.message.id:null,P=j?A.get(j)??[]:[];return f.jsxs("div",{className:"mx-auto max-w-[800px] pb-5",children:[f.jsx(TF,{row:U,toolGroupExpanded:U.kind==="tool-group"?k[U.id]??!1:void 0,onToolGroupExpandedChange:D,onAskUserQuestionSubmit:s,onExitPlanModeConfirm:o,onToolRequestAnswer:l,schedules:c,onAutoContinueAccept:u,onAutoContinueReschedule:p,onAutoContinueCancel:h}),P.map(z=>EF(z,0,M,n??"",w,C,E))]},U.id)})})}v.memo(xxe);function _xe(e=1e3){const[t,n]=v.useState(()=>Date.now()),r=v.useRef(e);return v.useLayoutEffect(()=>{r.current=e}),v.useEffect(()=>{const i=window.setInterval(()=>{n(Date.now())},r.current);return()=>window.clearInterval(i)},[]),t}function wxe(e){switch(e.kind){case"bash_shell":return e.command;case"terminal_pty":return`PTY: ${e.cwd}`;case"codex_session":return"Codex session";case"draining_stream":return"Draining stream"}}function Sxe(e){switch(e.kind){case"bash_shell":return"bash";case"terminal_pty":return"terminal";case"codex_session":return"codex";case"draining_stream":return"stream"}}function Cxe(e){return"chatId"in e?e.chatId??null:null}function kxe(e){return e.kind==="bash_shell"?e.status==="stopping"?"stopping":"running":"active"}function Exe(e){return(e.lastOutput??"").split(`
@@ -2713,4 +2713,4 @@ ${he.detail}`:""}`,closeLabel:"OK"})}catch(he){await r.alert({title:"Checkout fa
2713
2713
 
2714
2714
  ${ie.detail}`:""}`,closeLabel:"OK"}),ie}catch(ie){return await r.alert({title:"Merge failed",description:ie instanceof Error?ie.message:String(ie),closeLabel:"OK"}),null}},[r,C,e.socket]),ee=v.useCallback(async()=>{const J=h.current;if(!J)return;const te=await r.prompt({title:"New Branch",description:"Enter a branch name.",placeholder:"feature/my-branch",confirmLabel:"Create"});if(!te)return;const ie=await W(),de=ie.currentBranchName,he=ie.defaultBranchName;let Le=he;he&&de&&he!==de&&(Le=await r.confirm({title:"Branch Base",description:`Create "${te}" from ${de} instead of ${he}?`,confirmLabel:`From ${de}`,cancelLabel:`From ${he}`})?de:he);try{const ce=await e.socket.command({type:"chat.createBranch",chatId:J,name:te,baseBranchName:Le});ce.snapshotChanged&&C(),ce.ok||await r.alert({title:ce.title,description:`${ce.message}${ce.detail?`
2715
2715
 
2716
- ${ce.detail}`:""}`,closeLabel:"OK"})}catch(ce){await r.alert({title:"Create branch failed",description:ce instanceof Error?ce.message:String(ce),closeLabel:"OK"})}},[r,W,C,e.socket]);return v.useEffect(()=>{if(!t||!n)return;const J=window.setInterval(()=>{C()},s1e);return()=>window.clearInterval(J)},[t,C,n]),v.useEffect(()=>{!t||!n||C()},[t,C,n]),v.useEffect(()=>{!t||!e.activeChatId||p.current!==t&&(p.current=t,w())},[t,w,e.activeChatId]),v.useEffect(()=>{if(!t||!n)return;function J(){document.visibilityState==="visible"&&C()}return window.addEventListener("focus",J),document.addEventListener("visibilitychange",J),()=>{window.removeEventListener("focus",J),document.removeEventListener("visibilitychange",J)}},[t,C,n]),v.useEffect(()=>{n&&u.current&&!e.isProcessing&&C(),u.current=e.isProcessing},[C,n,e.isProcessing]),v.useEffect(()=>()=>{c.current!==null&&window.clearTimeout(c.current)},[]),v.useEffect(()=>{n||c.current!==null&&(window.clearTimeout(c.current),c.current=null)},[t,n]),{diffRenderMode:i,wrapDiffLines:o,setDiffRenderMode:s,setWrapDiffLines:l,scheduleTerminalDiffRefresh:E,handleOpenDiffFile:k,handleCopyDiffFilePath:R,handleCopyDiffRelativePath:N,handleLoadDiffPatch:A,handleDiscardDiffFile:M,handleIgnoreDiffFile:D,handleIgnoreDiffFolder:U,handleOpenDiffInFinder:j,handleCommitDiffs:P,handleSyncBranch:z,handleGenerateCommitMessage:O,handleInitializeGit:$,handleGetGitHubPublishInfo:V,handleCheckGitHubRepoAvailability:B,handleSetupGitHub:F,handleListBranches:W,handleCheckoutBranch:X,handlePreviewMergeBranch:I,handleMergeBranch:G,handleCreateBranch:ee}}const r7={"--terminal-toggle-duration":`${f0}ms`};function GEe(e,t){const[n,r]=v.useState(""),[i,s]=v.useState(!1);return v.useEffect(()=>{if(!e)return;r(""),s(!1);let o=0;const l=window.setInterval(()=>{o+=1,r(ny.slice(0,o)),o>=ny.length&&(window.clearInterval(l),s(!0))},r1e);return()=>window.clearInterval(l)},[e,t]),{typedEmptyStateText:n,isEmptyStateTypingComplete:i}}function qEe(e){const[t,n]=v.useState(!1),r=v.useRef(0),i=v.useCallback(u=>{var p;return a1e(((p=u.dataTransfer)==null?void 0:p.types)??[])},[]),s=v.useCallback(u=>{!i(u)||!e.hasSelectedProject||(u.preventDefault(),r.current+=1,n(!0))},[e.hasSelectedProject,i]),o=v.useCallback(u=>{!i(u)||!e.hasSelectedProject||(u.preventDefault(),u.dataTransfer.dropEffect="copy",t||n(!0))},[e.hasSelectedProject,i,t]),l=v.useCallback(u=>{!i(u)||!e.hasSelectedProject||(u.preventDefault(),r.current=Math.max(0,r.current-1),r.current===0&&n(!1))},[e.hasSelectedProject,i]),c=v.useCallback(u=>{!i(u)||!e.hasSelectedProject||(u.preventDefault(),r.current=0,n(!1),e.onFilesDropped([...u.dataTransfer.files]))},[e,i]);return{isPageFileDragActive:t,handleTranscriptDragEnter:s,handleTranscriptDragOver:o,handleTranscriptDragLeave:l,handleTranscriptDrop:c}}function KEe(e){const[t,n]=v.useState(0);return v.useLayoutEffect(()=>{const r=e.current;if(!r)return;const i=()=>{const o=r.clientWidth;n(l=>Math.abs(l-o)<1?l:o)},s=new ResizeObserver(i);return s.observe(r),i(),()=>s.disconnect()},[e]),t}function YEe(){const e=v.useRef(null),[t,n]=v.useState(148),r=v.useCallback(()=>{const i=e.current;if(!i)return;const s=i.getBoundingClientRect().height;n(o=>Kye(o,s))},[]);return v.useLayoutEffect(()=>{const i=e.current;if(!i)return;const s=new ResizeObserver(()=>{r()});return s.observe(i),r(),()=>s.disconnect()},[r]),{inputRef:e,syncInputHeight:r,transcriptPaddingBottom:qye(t)}}const XEe=768;function QEe(e){return e>0&&e<XEe}function ZEe(){const[e,t]=v.useState(()=>typeof window>"u"?0:window.innerWidth);return v.useEffect(()=>{if(typeof window>"u")return;const n=()=>t(window.innerWidth);return n(),window.addEventListener("resize",n),()=>window.removeEventListener("resize",n)},[]),QEe(e)}function JEe(e){const[t,n]=v.useState(0);return v.useEffect(()=>{const r=e.layoutRootRef.current;if(!r)return;const i=()=>{const o=r.getBoundingClientRect().height;if(!e.shouldRenderTerminalLayout||o<=0)return;const l=o*(e.terminalMainSizes[1]/100);l<=0||n(c=>Math.abs(c-l)<1?c:l)},s=new ResizeObserver(i);return s.observe(r),i(),()=>s.disconnect()},[e.layoutRootRef,e.shouldRenderTerminalLayout,e.terminalMainSizes]),t}const RP=v.memo(function(t){return f.jsx(Rve,{...t,diffs:t.diffs??s$})}),e2e=v.memo(function({showRightSidebar:t,sizePercent:n,sidebarPanelRef:r,sidebarVisualRef:i,content:s}){return f.jsx(Ap,{id:"rightSidebar",defaultSize:`${n}%`,className:"min-h-0 min-w-0",elementRef:r,children:f.jsx("div",{ref:i,className:"h-full min-h-0 overflow-hidden","data-right-sidebar-open":t?"true":"false","data-right-sidebar-animated":"false","data-right-sidebar-visual":!0,style:r7,children:s})})}),t2e=v.memo(function({projectId:t,showRightSidebar:n,sidebarVisualRef:r,onClose:i,content:s}){return t?f.jsxs("div",{className:me("absolute inset-0 z-40 transition-opacity duration-300 ease-out",n?"pointer-events-auto opacity-100":"pointer-events-none opacity-0"),"aria-hidden":n?void 0:!0,"data-mobile-right-sidebar-overlay":!0,children:[f.jsx("button",{type:"button",className:"absolute inset-0 bg-black/45 backdrop-blur-[1px]","aria-label":"Close changes sidebar",onClick:i}),f.jsx("div",{ref:r,className:me("absolute inset-y-0 right-0 flex w-[min(92vw,30rem)] max-w-full min-h-0 flex-col overflow-hidden border-l border-border bg-background shadow-2xl transition-transform duration-300 ease-out","pt-[max(env(safe-area-inset-top),0px)] pb-[max(env(safe-area-inset-bottom),0px)]",n?"translate-x-0":"translate-x-full"),"data-right-sidebar-open":n?"true":"false","data-right-sidebar-animated":"false","data-right-sidebar-visual":!0,children:s})]}):null});function n2e({chatCard:e,projectId:t,shouldRenderTerminalLayout:n,showTerminalPane:r,terminalLayout:i,mainPanelGroupRef:s,terminalPanelRef:o,terminalVisualRef:l,fixedTerminalHeight:c,terminalFocusRequestVersion:u,addTerminal:p,socket:h,connectionStatus:g,scrollback:b,minColumnWidth:x,splitTerminalShortcut:_,onTerminalCommandSent:w,onRemoveTerminal:C,onTerminalLayout:E,onLayoutChanged:k}){return n?f.jsxs(o2,{groupRef:s,orientation:"vertical",className:"flex-1 min-h-0",onLayoutChanged:k,children:[f.jsx(Ap,{id:"chat",defaultSize:`${i.mainSizes[0]}%`,minSize:"25%",className:"min-h-0",children:e}),f.jsx(a2,{withHandle:!0,orientation:"vertical",disabled:!r,className:me(!r&&"pointer-events-none opacity-0")}),f.jsx(Ap,{id:"terminal",defaultSize:`${i.mainSizes[1]}%`,minSize:"0%",className:"min-h-0",elementRef:o,children:f.jsx("div",{ref:l,className:"h-full min-h-0 overflow-hidden relative","data-terminal-open":r?"true":"false","data-terminal-animated":"false","data-terminal-visual":!0,style:r7,children:f.jsx(VEe,{projectId:t,fixedTerminalHeight:c,terminalLayout:i,addTerminal:p,socket:h,connectionStatus:g,scrollback:b,minColumnWidth:x,splitTerminalShortcut:_,focusRequestVersion:u,onTerminalCommandSent:w,onRemoveTerminal:C,onTerminalLayout:E})})})]},t):f.jsx(f.Fragment,{children:e})}function r2e(){var Qr,Oi,ai,ts,zi,_t,an,kn,gn,ao,Da,ns,Fo,rs,Ia,cr;const e=$C(),{handleCancel:t,handleOpenExternal:n}=e,r=Kp(),i=v.useRef(null),s=v.useRef(null),o=v.useRef(!0),l=v.useRef(null),c=v.useRef(null),u=v.useRef(null),p=v.useRef(null),{inputRef:h,syncInputHeight:g,transcriptPaddingBottom:b}=YEe(),[x,_]=v.useState(!1),w=Ys(je=>je.dialogOpen),C=v.useCallback(()=>{Ys.getState().toggleDialog()},[]),E=e.messages.length===0&&((Qr=e.runtime)==null?void 0:Qr.title)==="New Chat",k=e.activeProjectId,N=yl(je=>k?je.projects[k]:void 0)??pbe,M=Li(je=>k?je.projects[k]:void 0)??vue,D=Li(je=>je.size),U=yl(je=>je.addTerminal),j=yl(je=>je.removeTerminal),P=yl(je=>je.toggleVisibility),z=yl(je=>je.resetMainSizes),O=yl(je=>je.setMainSizes),$=yl(je=>je.setTerminalSizes),V=Li(je=>je.toggleVisibility),B=Li(je=>je.setSize),F=hi(je=>je.scrollbackLines),W=hi(je=>je.minColumnWidth),X=hi(je=>je.editorPreset),I=hi(je=>je.editorCommandTemplate),G=v.useMemo(()=>Jk(e.keybindings),[e.keybindings]),ee=v.useMemo(()=>{var je;return lbe(((je=e.chatSnapshot)==null?void 0:je.messages)??[])},[(Oi=e.chatSnapshot)==null?void 0:Oi.messages]),H=N.terminals.length>0,ue=!!(k&&N.isVisible&&H),ae=!!(k&&H),J=!!(k&&M.isVisible),te=!!k,ie=ZEe(),de=te&&!ie,he=KEe(i),Le=v.useCallback((je,Ke)=>{if(!Number.isFinite(je))return D;const Ft=Ke??he,tr=Ft>0?pue/Ft*100:R1;return Math.max(R1,tr,je)},[D,he]),ce=Le(D??wd),De=JEe({layoutRootRef:i,shouldRenderTerminalLayout:ae,terminalMainSizes:N.mainSizes}),{isAnimating:pe,mainPanelGroupRef:st,terminalFocusRequestVersion:zt,terminalPanelRef:Et,terminalVisualRef:Qt}=Lbe({showTerminalPane:ue,shouldRenderTerminalLayout:ae,projectId:k,terminalLayout:N,chatInputRef:u}),{isAnimating:Dt,panelGroupRef:Tt,sidebarPanelRef:mt,sidebarVisualRef:At}=kbe({projectId:k,shouldRenderRightSidebarLayout:de,showRightSidebar:J,rightSidebarSize:ce}),{diffRenderMode:It,wrapDiffLines:ht,setDiffRenderMode:Ht,setWrapDiffLines:ge,scheduleTerminalDiffRefresh:we,handleOpenDiffFile:Be,handleCopyDiffFilePath:tt,handleCopyDiffRelativePath:Pe,handleLoadDiffPatch:Ve,handleDiscardDiffFile:qe,handleIgnoreDiffFile:Xe,handleIgnoreDiffFolder:We,handleOpenDiffInFinder:gt,handleCommitDiffs:ot,handleSyncBranch:Bt,handleGenerateCommitMessage:ut,handleInitializeGit:on,handleGetGitHubPublishInfo:cn,handleCheckGitHubRepoAvailability:vt,handleSetupGitHub:Rt,handleListBranches:St,handleCheckoutBranch:Ut,handlePreviewMergeBranch:xt,handleMergeBranch:ft,handleCreateBranch:Lt}=WEe({state:e,projectId:k,showRightSidebar:J}),{typedEmptyStateText:Pt,isEmptyStateTypingComplete:Ie}=GEe(E,e.activeChatId);Nbe({rootRef:c,fallbackRef:u,enabled:e.hasSelectedProject,canCancel:e.canCancel}),Rbe({socket:e.socket,activeChatId:e.activeChatId});const ze=v.useCallback(je=>{var Ke;!e.hasSelectedProject||je.length===0||(Ke=p.current)==null||Ke.enqueueFiles(je)},[e.hasSelectedProject]),{isPageFileDragActive:Te,handleTranscriptDragEnter:Ye,handleTranscriptDragOver:_e,handleTranscriptDragLeave:Je,handleTranscriptDrop:et}=qEe({hasSelectedProject:e.hasSelectedProject,onFilesDropped:ze}),$e=v.useCallback(()=>{if(k){if(H){P(k);return}U(k)}},[U,H,k,P]),Mt=v.useCallback(je=>{var li;if(!k||!ue||pe.current)return;const Ke=je.chat,Ft=je.terminal;if(!Number.isFinite(Ke)||!Number.isFinite(Ft))return;const tr=((li=i.current)==null?void 0:li.getBoundingClientRect().height)??0;if(vbe(tr,Ft)){z(k),P(k);return}O(k,[Ke,Ft])},[pe,k,z,O,ue,P]),un=v.useCallback(()=>{k&&V(k)},[k,V]),Zt=v.useCallback(()=>{var je;if(k){if(J){V(k);return}if(((je=e.chatDiffSnapshot)==null?void 0:je.status)==="no_repo"){(async()=>{if(!await r.confirm({title:"Initialize Git?",description:"Initialize a local git repository in this project?",confirmLabel:"Init Git",cancelLabel:"Cancel"}))return;const Ft=await on();Ft!=null&&Ft.ok&&!J&&V(k)})();return}V(k)}},[r,on,k,J,(ai=e.chatDiffSnapshot)==null?void 0:ai.status,V]),Fe=v.useCallback((je,Ke)=>{e.socket.command({type:"terminal.close",terminalId:Ke}).catch(()=>{}),j(je,Ke)},[j,e.socket]),hn=v.useCallback(()=>{l.current!==null&&(window.clearTimeout(l.current),l.current=null)},[]),lr=v.useCallback(je=>{if(o.current!==je){if(o.current=je,je){hn(),_(!1);return}hn(),l.current=window.setTimeout(()=>{_(!0),l.current=null},150)}},[hn]),se=v.useCallback(()=>{var Ke,Ft;const je=(Ft=(Ke=s.current)==null?void 0:Ke.getState)==null?void 0:Ft.call(Ke);je&&lr(je.isAtEnd)},[lr]),le=v.useCallback(async(je=!0)=>{var Ke,Ft;o.current=!0,hn(),_(!1),await((Ft=(Ke=s.current)==null?void 0:Ke.scrollToEnd)==null?void 0:Ft.call(Ke,{animated:je}))},[hn]),Ce=v.useCallback(async(je,Ke)=>{await le(!1),await e.handleSend(je,Ke)},[le,e]),Ee=v.useCallback((je,Ke)=>{const Ft=e.activeChatId;Ft&&e.socket.command({type:"autoContinue.accept",chatId:Ft,scheduleId:je,scheduledAt:Ke}).catch(()=>{})},[e.activeChatId,e.socket]),Qe=v.useCallback((je,Ke)=>{const Ft=e.activeChatId;Ft&&e.socket.command({type:"autoContinue.reschedule",chatId:Ft,scheduleId:je,scheduledAt:Ke}).catch(()=>{})},[e.activeChatId,e.socket]),ct=v.useCallback(je=>{const Ke=e.activeChatId;Ke&&e.socket.command({type:"autoContinue.cancel",chatId:Ke,scheduleId:je}).catch(()=>{})},[e.activeChatId,e.socket]),Ze=v.useCallback(async je=>{const Ke=e.activeChatId;Ke&&await e.socket.command({type:"tunnel.accept",chatId:Ke,tunnelId:je})},[e.activeChatId,e.socket]),Vt=v.useCallback(async je=>{const Ke=e.activeChatId;Ke&&await e.socket.command({type:"tunnel.stop",chatId:Ke,tunnelId:je})},[e.activeChatId,e.socket]),Dn=v.useCallback(async je=>{const Ke=e.activeChatId;Ke&&await e.socket.command({type:"tunnel.retry",chatId:Ke,tunnelId:je})},[e.activeChatId,e.socket]),fn=v.useCallback((je,Ke)=>{e.socket.command({type:"chat.cancelSubagentRun",chatId:je,runId:Ke}).catch(()=>{})},[e.socket]);v.useEffect(()=>()=>hn(),[hn]),v.useEffect(()=>{o.current=!0,hn(),_(!1)},[hn,e.activeChatId]),v.useEffect(()=>{function je(Ke){if(k){if(fh(G,"toggleEmbeddedTerminal",Ke)){Ke.preventDefault(),$e();return}if(fh(G,"toggleRightSidebar",Ke)){Ke.preventDefault(),Zt();return}if(fh(G,"openInFinder",Ke)){Ke.preventDefault(),n("open_finder");return}if(fh(G,"openInEditor",Ke)){Ke.preventDefault(),n("open_editor");return}fh(G,"addSplitTerminal",Ke)&&(Ke.preventDefault(),U(k))}}return window.addEventListener("keydown",je),()=>window.removeEventListener("keydown",je)},[U,n,$e,Zt,k,G]),v.useEffect(()=>{function je(Ke){(Ke.metaKey||Ke.ctrlKey)&&Ke.shiftKey&&Ke.key.toLowerCase()==="b"&&(Ke.preventDefault(),C())}return window.addEventListener("keydown",je),()=>window.removeEventListener("keydown",je)},[C]),v.useEffect(()=>{const je=window.requestAnimationFrame(()=>{se()}),Ke=window.setTimeout(()=>{se()},f0);return()=>{window.cancelAnimationFrame(je),window.clearTimeout(Ke)}},[ae,ue,se]),v.useEffect(()=>{function je(){se()}return window.addEventListener("resize",je),()=>window.removeEventListener("resize",je)},[se]),v.useEffect(()=>{if(!J||!ie)return;const je=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=je}},[ie,J]),v.useEffect(()=>{if(!J||!ie)return;function je(Ke){Ke.key==="Escape"&&(Ke.preventDefault(),un())}return window.addEventListener("keydown",je),()=>window.removeEventListener("keydown",je)},[un,ie,J]),v.useEffect(()=>{if(!o.current)return;let je=null;const Ke=window.requestAnimationFrame(()=>{var Ft,tr;(tr=(Ft=s.current)==null?void 0:Ft.scrollToEnd)==null||tr.call(Ft,{animated:!1}),je=window.requestAnimationFrame(()=>{var li,lo;(lo=(li=s.current)==null?void 0:li.scrollToEnd)==null||lo.call(li,{animated:!1})})});return()=>{window.cancelAnimationFrame(Ke),je!==null&&window.cancelAnimationFrame(je)}},[e.commandError,e.isDraining,e.isProcessing,e.messages.length,e.queuedMessages.length,e.runtimeStatus]),v.useLayoutEffect(()=>{var Ft,tr;if(!J||ie||he<=0||Dt.current)return;const je=Le(D,he),Ke=(Ft=Tt.current)==null?void 0:Ft.getLayout();Ke&&(Math.abs((Ke.rightSidebar??0)-je)<.1||(tr=Tt.current)==null||tr.setLayout({workspace:100-je,rightSidebar:je}))},[Le,D,Dt,he,Tt,J,ie]);const Si=f.jsxs(wk,{ref:c,className:"bg-background h-full flex flex-col overflow-hidden border-0 rounded-none relative",onDragEnter:Ye,onDragOver:_e,onDragLeave:Je,onDrop:et,children:[f.jsxs(Ck,{className:"flex flex-1 min-h-0 flex-col overflow-hidden p-0 relative",children:[f.jsx(xre,{sidebarCollapsed:e.sidebarCollapsed,onOpenSidebar:e.openSidebar,onExpandSidebar:e.expandSidebar,onNewChat:e.handleCompose,localPath:e.navbarLocalPath,embeddedTerminalVisible:ue,onToggleEmbeddedTerminal:k?$e:void 0,rightSidebarVisible:J,onToggleRightSidebar:k?Zt:void 0,onOpenExternal:n,onExportTranscript:e.activeChatId?()=>void e.handleShareChat(e.activeChatId):void 0,canExportTranscript:!!e.activeChatId&&!e.isExportingStandalone,isExportingTranscript:e.isExportingStandalone,exportTranscriptComplete:e.standaloneShareComplete,editorPreset:X,editorCommandTemplate:I,platform:(ts=e.localProjects)==null?void 0:ts.machine.platform,finderShortcut:G.bindings.openInFinder,editorShortcut:G.bindings.openInEditor,terminalShortcut:G.bindings.toggleEmbeddedTerminal,rightSidebarShortcut:G.bindings.toggleRightSidebar,branchName:(zi=e.chatDiffSnapshot)==null?void 0:zi.branchName,hasGitRepo:((_t=e.chatDiffSnapshot)==null?void 0:_t.status)!=="no_repo",gitStatus:(an=e.chatDiffSnapshot)==null?void 0:an.status,timings:(kn=e.runtime)==null?void 0:kn.timings,status:(gn=e.runtime)==null?void 0:gn.status,onOpenBgTasks:C}),f.jsx(u1e,{activeChatId:e.activeChatId,listRef:s,messages:e.messages,queuedMessages:e.queuedMessages,transcriptPaddingBottom:b,localPath:(ao=e.runtime)==null?void 0:ao.localPath,latestToolIds:e.latestToolIds,isHistoryLoading:e.isHistoryLoading,hasOlderHistory:e.hasOlderHistory,isProcessing:e.isProcessing,runtimeStatus:e.runtimeStatus,isDraining:e.isDraining,commandError:e.commandError,loadOlderHistory:e.loadOlderHistory,onStopDraining:e.handleStopDraining,onSteerQueuedMessage:e.handleSteerQueuedMessage,onRemoveQueuedMessage:e.handleRemoveQueuedMessage,onOpenLocalLink:e.handleOpenLocalLink,editorPreset:X,editorCommandTemplate:I,platform:(Da=e.localProjects)==null?void 0:Da.machine.platform,onAskUserQuestionSubmit:e.handleAskUserQuestion,onExitPlanModeConfirm:e.handleExitPlanMode,onToolRequestAnswer:e.handleToolRequestAnswer,onSubagentAskUserQuestionSubmit:e.handleSubagentAskUserQuestion,onSubagentExitPlanModeSubmit:e.handleSubagentExitPlanMode,schedules:((ns=e.chatSnapshot)==null?void 0:ns.schedules)??RF,onAutoContinueAccept:Ee,onAutoContinueReschedule:Qe,onAutoContinueCancel:ct,tunnels:(Fo=e.chatSnapshot)==null?void 0:Fo.tunnels,liveTunnelId:(rs=e.chatSnapshot)==null?void 0:rs.liveTunnelId,onTunnelAccept:Ze,onTunnelStop:Vt,onTunnelRetry:Dn,subagentRuns:(Ia=e.chatSnapshot)==null?void 0:Ia.subagentRuns,onCancelSubagentRun:fn,showScrollButton:x&&e.messages.length>0,onIsAtEndChange:lr,scrollToBottom:()=>le(!0),typedEmptyStateText:Pt,isEmptyStateTypingComplete:Ie,isPageFileDragActive:Te,showEmptyState:E})]}),f.jsx(__e,{inputRef:h,onLayoutChange:g,chatInputRef:p,chatInputElementRef:u,activeChatId:e.activeChatId,previousPrompt:e.previousPrompt,hasSelectedProject:e.hasSelectedProject,canCancel:e.canCancel,projectId:k,activeProvider:((cr=e.runtime)==null?void 0:cr.provider)??null,availableProviders:e.availableProviders,contextWindowSnapshot:ee,onSubmit:Ce,onCancel:t})]}),Vn=k?f.jsx(n2e,{chatCard:Si,projectId:k,shouldRenderTerminalLayout:ae,showTerminalPane:ue,terminalLayout:N,mainPanelGroupRef:st,terminalPanelRef:Et,terminalVisualRef:Qt,fixedTerminalHeight:De,terminalFocusRequestVersion:zt,addTerminal:U,socket:e.socket,connectionStatus:e.connectionStatus,scrollback:F,minColumnWidth:W,splitTerminalShortcut:G.bindings.addSplitTerminal,onTerminalCommandSent:we,onRemoveTerminal:Fe,onTerminalLayout:$,onLayoutChanged:Mt}):Si,Tr=v.useMemo(()=>k?{projectId:k,diffs:e.chatDiffSnapshot??s$,editorLabel:e.editorLabel,diffRenderMode:It,wrapLines:ht,onOpenFile:Be,onOpenInFinder:gt,onDiscardFile:qe,onIgnoreFile:Xe,onIgnoreFolder:We,onCopyFilePath:tt,onCopyRelativePath:Pe,onLoadPatch:Ve,onListBranches:St,onPreviewMergeBranch:xt,onMergeBranch:ft,onCheckoutBranch:Ut,onCreateBranch:Lt,onGenerateCommitMessage:ut,onInitializeGit:on,onGetGitHubPublishInfo:cn,onCheckGitHubRepoAvailability:vt,onSetupGitHub:Rt,onCommit:ot,onSyncWithRemote:Bt,onDiffRenderModeChange:Ht,onWrapLinesChange:ge,onClose:un}:null,[It,vt,Ut,un,ot,tt,Pe,Lt,qe,ut,cn,Xe,We,on,St,Ve,ft,Be,gt,xt,Rt,Bt,k,Ht,ge,e.chatDiffSnapshot,e.editorLabel,ht]);return f.jsxs("div",{ref:i,className:"flex-1 flex flex-col min-w-0 relative",children:[f.jsx(Mxe,{open:w,onOpenChange:je=>{je?Ys.getState().openDialog():Ys.getState().closeDialog()},socket:e.socket}),de&&k?f.jsxs(o2,{groupRef:Tt,orientation:"horizontal",className:"flex-1 min-h-0",onLayoutChange:je=>{var Ft;if(!J||Dt.current)return;const Ke=Le(je.rightSidebar);Math.abs(Ke-je.rightSidebar)<.1||(Ft=Tt.current)==null||Ft.setLayout({workspace:100-Ke,rightSidebar:Ke})},onLayoutChanged:je=>{!J||Dt.current||B(Le(je.rightSidebar))},children:[f.jsx(Ap,{id:"workspace",defaultSize:`${100-ce}%`,minSize:"20%",className:"min-h-0 min-w-0",children:Vn}),f.jsx(a2,{withHandle:!1,orientation:"horizontal",disabled:!J,className:me(!J&&"pointer-events-none opacity-0")}),f.jsx(e2e,{showRightSidebar:J,sizePercent:ce,sidebarPanelRef:mt,sidebarVisualRef:At,content:Tr?f.jsx(RP,{...Tr}):null})]},`${k}-right-sidebar`):Vn,ie?f.jsx(t2e,{projectId:k,showRightSidebar:J,sidebarVisualRef:At,onClose:un,content:Tr?f.jsx(RP,{...Tr}):null}):null]})}function NP({narrow:e=!1,title:t,subtitle:n,icon:r=JC}){return f.jsxs("div",{className:me("w-full",e?"max-w-2xl px-6 pt-16 mx-auto":"px-6 pt-16 mb-10"),children:[f.jsxs("div",{className:me("flex items-center gap-1 mb-2",e&&"justify-center"),children:[f.jsx("div",{className:"p-2 pl-0 rounded-lg",children:f.jsx(r,{className:"h-6 w-6 text-muted-foreground"})}),f.jsx("h1",{className:"text-2xl font-semibold text-foreground",children:t})]}),n&&f.jsx("p",{className:me("text-muted-foreground",e&&"mb-10 text-center"),children:n})]})}function i2e(e){return e.toLowerCase().replace(/[\s_]+/g,"-").replace(/[^a-z0-9-]/g,"").replace(/-+/g,"-").replace(/^-|-$/g,"")}function s2e({open:e,onOpenChange:t,onConfirm:n}){const[r,i]=v.useState("new"),[s,o]=v.useState(""),[l,c]=v.useState(""),u=v.useRef(null),p=v.useRef(null);v.useEffect(()=>{e&&(i("new"),o(""),c(""),setTimeout(()=>{var w;return(w=u.current)==null?void 0:w.focus()},0))},[e]),v.useEffect(()=>{e&&setTimeout(()=>{var w,C;r==="new"?(w=u.current)==null||w.focus():(C=p.current)==null||C.focus()},0)},[r,e]);const h=i2e(s),g=h?`${DQ}/${h}`:"",b=l.trim(),x=r==="new"?!!h:!!b,_=()=>{if(x){if(r==="new")n({mode:"new",localPath:g,title:s.trim()});else{const w=b.split("/").pop()||b;n({mode:"existing",localPath:b,title:w})}t(!1)}};return f.jsx(Rs,{open:e,onOpenChange:t,children:f.jsxs(Zi,{size:"sm",children:[f.jsxs(Io,{className:"space-y-4",children:[f.jsx(Ns,{children:"Add Project"}),f.jsx(da,{value:r,onValueChange:i,options:[{value:"new",label:"New Folder"},{value:"existing",label:"Existing Path"}],className:"w-full mb-2",optionClassName:"flex-1 justify-center"}),r==="new"?f.jsxs("div",{className:"space-y-2",children:[f.jsx(Kn,{ref:u,type:"text",value:s,onChange:w=>o(w.target.value),onKeyDown:w=>{w.key==="Enter"&&_(),w.key==="Escape"&&t(!1)},placeholder:"Project name"}),g&&f.jsx("p",{className:"text-xs text-muted-foreground font-mono",children:g})]}):f.jsxs("div",{className:"space-y-2",children:[f.jsx(Kn,{ref:p,type:"text",value:l,onChange:w=>c(w.target.value),onKeyDown:w=>{w.key==="Enter"&&_(),w.key==="Escape"&&t(!1)},placeholder:"~/Projects/my-app"}),f.jsx("p",{className:"text-xs text-muted-foreground",children:"The folder will be created if it doesn't exist."})]})]}),f.jsxs(_a,{children:[f.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>t(!1),children:"Cancel"}),f.jsx(Ge,{variant:"secondary",size:"sm",onClick:_,disabled:!x,children:"Create"})]})]})})}function o2e({text:e}){const[t,n]=v.useState(!1);async function r(){await navigator.clipboard.writeText(e),n(!0),setTimeout(()=>n(!1),2e3)}return f.jsx(Ge,{variant:"ghost",size:"icon-mobile","aria-label":t?"Copied":"Copy to clipboard",className:"text-muted-foreground hover:text-foreground",onClick:()=>void r(),children:t?f.jsx(yi,{className:"h-4 w-4 text-success"}):f.jsx(jl,{className:"h-4 w-4"})})}function AP({children:e}){return f.jsxs("div",{className:"grid grid-cols-[1fr_auto] items-center group bg-background border border-border text-foreground rounded-xl p-1.5 pl-3 font-mono text-sm",children:[f.jsxs("pre",{className:"inline-flex items-center gap-2 overflow-x-auto",children:[f.jsx(Do,{className:"inline h-4 w-4 opacity-40"}),f.jsx("code",{children:e})]}),f.jsx(o2e,{text:e})]})}function jv({children:e}){return f.jsx("div",{className:"bg-card border border-border rounded-2xl p-4",children:e})}function xS({children:e}){return f.jsx("h2",{className:"text-[13px] font-medium text-muted-foreground uppercase tracking-wider mb-3",children:e})}function _S({icon:e,title:t,subtitle:n,iconClassName:r}){return f.jsxs("div",{className:"flex flex-col items-start gap-1.5 min-w-0",children:[f.jsx(e,{className:r||"h-5 w-5 text-muted-foreground"}),f.jsx("span",{className:"text-sm font-medium text-foreground",children:t}),f.jsx("span",{className:"text-xs text-muted-foreground leading-tight",children:n})]})}function MP(){return f.jsx("div",{"aria-hidden":!0,className:"mt-5 h-px w-6 shrink-0 bg-border"})}function LP({number:e,title:t,children:n}){return f.jsx("div",{className:"flex gap-4",children:f.jsxs("div",{className:"flex-1 min-w-0",children:[f.jsxs("div",{className:"grid grid-cols-[auto_1fr] items-baseline gap-3",children:[f.jsxs("div",{className:"flex-shrink-0 flex items-center justify-center font-medium text-logo",children:[e,"."]}),f.jsx("h3",{className:"font-medium text-foreground mb-2",children:t})]}),f.jsx("div",{className:"text-muted-foreground text-sm space-y-3",children:n})]})})}function a2e({localPath:e,loading:t,onClick:n}){return f.jsxs(Yr,{children:[f.jsx(Xr,{asChild:!0,children:f.jsxs("button",{className:me("border border-border hover:border-primary/30 group rounded-lg bg-card px-4 py-3 flex items-center gap-3 w-full text-left hover:bg-muted/50 transition-colors",t&&"opacity-50 cursor-not-allowed"),disabled:t,onClick:n,children:[f.jsx(y5,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),f.jsx("span",{className:"font-medium text-foreground truncate flex-1",children:Ek(e)}),t?f.jsx(Cn,{className:"h-4 w-4 text-muted-foreground group-hover:text-primary animate-spin flex-shrink-0"}):f.jsx(ek,{className:"h-4 w-4 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0"})]})}),f.jsx(Br,{children:f.jsx("p",{children:e})})]})}function l2e({connectionStatus:e,ready:t,snapshot:n,startingLocalPath:r,commandError:i,newProjectOpen:s,onNewProjectOpenChange:o,onOpenProject:l,onCreateProject:c}){const u=v.useMemo(()=>(n==null?void 0:n.projects)??[],[n==null?void 0:n.projects]),p=e==="connecting"||!t,h=e==="connected"&&t;return f.jsxs("div",{className:"flex-1 flex flex-col min-w-0 bg-background overflow-y-auto",children:[h?f.jsxs(f.Fragment,{children:[f.jsx(NP,{title:(n==null?void 0:n.machine.displayName)??"Local Projects",subtitle:`${or} is connected, choose a project below to get started.`}),f.jsxs("div",{className:"w-full px-6 mb-10",children:[f.jsxs("div",{className:"flex items-baseline justify-between mb-3",children:[f.jsx("h2",{className:"text-[13px] font-medium text-muted-foreground uppercase tracking-wider",children:"Projects"}),f.jsxs(Ge,{variant:"default",size:"sm",onClick:()=>o(!0),children:[f.jsx(Ed,{className:"h-4 w-4 mr-1.5"}),"Add Project"]})]}),u.length>0?f.jsx("div",{className:"grid gap-2 [grid-template-columns:repeat(auto-fill,minmax(min(260px,100%),1fr))]",children:u.map(g=>f.jsx(a2e,{localPath:g.localPath,loading:r===g.localPath,onClick:()=>{l(g.localPath)}},g.localPath))}):f.jsx(jv,{children:f.jsx("p",{className:"text-sm text-muted-foreground",children:"No local projects discovered yet. Open one with Claude or Codex, or create a new project here."})}),i?f.jsx("div",{className:"text-sm text-destructive border border-destructive/20 bg-destructive/5 rounded-xl px-4 py-3 mt-4",children:i}):null]})]}):f.jsxs(f.Fragment,{children:[f.jsx(NP,{narrow:!0,icon:IA,title:p?`Connecting ${or}`:`Connect ${or}`,subtitle:p?`${or} is starting up and loading your local projects.`:`Run ${or} directly on your machine with full access to your local files and agent project history.`}),f.jsxs("div",{className:"max-w-2xl w-full mx-auto pb-12 px-6",children:[f.jsx(xS,{children:"Status"}),f.jsx("div",{className:"mb-8",children:f.jsx(jv,{children:f.jsxs("div",{className:"flex items-center gap-3",children:[f.jsx(Cn,{className:"h-4 w-4 text-muted-foreground animate-spin"}),f.jsx("span",{className:"text-sm text-muted-foreground",children:p?`Connecting to your local ${or} server...`:f.jsxs(f.Fragment,{children:["Not connected. Run ",f.jsx("code",{className:"bg-background border border-border rounded-md mx-0.5 p-1 font-mono text-xs text-foreground",children:Pg()})," from any terminal on this machine."]})})]})})}),p?null:f.jsxs("div",{className:"mb-10",children:[f.jsx(xS,{children:"How it works"}),f.jsx(jv,{children:f.jsxs("div",{className:"flex items-start gap-4 py-2 px-2",children:[f.jsx(_S,{icon:my,title:`${or} CLI`,subtitle:"On Your Machine"}),f.jsx(MP,{}),f.jsx(_S,{icon:JC,title:`${or} Server`,subtitle:"Local WebSocket"}),f.jsx(MP,{}),f.jsx(_S,{icon:IA,title:`${or} UI`,subtitle:"Project Chat"})]})})]}),p?null:f.jsxs("div",{className:"mb-10",children:[f.jsx(xS,{children:"Setup"}),f.jsx(jv,{children:f.jsxs("div",{className:"space-y-4",children:[f.jsxs(LP,{number:1,title:`Start ${or}`,children:[f.jsx("p",{children:"Run this command in your terminal:"}),f.jsx(AP,{children:Pg()})]}),f.jsxs(LP,{number:2,title:"Open the local UI",children:[f.jsxs("p",{children:[or," serves the app locally and opens the Local Projects page in an app-style browser window."]}),f.jsx(AP,{children:"http://localhost:3210/local"})]}),f.jsxs("div",{className:"mt-8",children:[f.jsx("h3",{className:"text-sm font-medium text-muted-foreground uppercase tracking-wider mb-4",children:"Notes"}),f.jsxs("div",{className:"space-y-3 text-sm",children:[f.jsxs("div",{className:"flex gap-4",children:[f.jsx("code",{className:"font-mono text-foreground whitespace-nowrap",children:Pg("").trim()}),f.jsx("span",{className:"text-muted-foreground",children:"Start in the current directory"})]}),f.jsxs("div",{className:"flex gap-4",children:[f.jsx("code",{className:"font-mono text-foreground whitespace-nowrap",children:Pg("--no-open")}),f.jsx("span",{className:"text-muted-foreground",children:"Start the server without opening the browser"})]})]})]})]})})]})]})]}),f.jsx(s2e,{open:s,onOpenChange:o,onConfirm:g=>{c(g)}}),f.jsx("div",{className:"py-4 text-center",children:f.jsxs("span",{className:"text-xs text-muted-foreground/50",children:["v",kk.split("/")[1]]})})]})}function c2e(){const e=$C();return f.jsx("div",{className:"flex-1 flex flex-col min-w-0 relative",children:f.jsx(l2e,{connectionStatus:e.connectionStatus,ready:e.localProjectsReady,snapshot:e.localProjects,startingLocalPath:e.startingLocalPath,commandError:e.commandError,newProjectOpen:e.addProjectModalOpen,onNewProjectOpenChange:t=>{if(t){e.openAddProjectModal();return}e.closeAddProjectModal()},onOpenProject:e.handleOpenLocalProject,onCreateProject:e.handleCreateProject})})}const u2e=["app_launch","project_opened","project_created","project_removed","chat_created","chat_deleted","message_sent","update_checked","update_installed","update_failed","analytics_enabled","analytics_disabled"],d2e=["current_version","environment","latest_version","custom_port_enabled","no_open_enabled","password_enabled","strict_port_enabled","remote_enabled","host_enabled","share_quick_enabled","share_token_enabled"];function f2e(e){if(!e)return"—";const t=e.trim();if(!t)return"—";const n=t.slice(-4);return`${t.startsWith("sk-ant-")?"sk-ant-":""}…${n}`}function h2e(e){if(e<=0)return"reset now";const t=Math.ceil(e/1e3),n=Math.floor(t/60),r=t%60;if(n<60)return`reset in ${n}m ${r.toString().padStart(2,"0")}s`;const i=Math.floor(n/60),s=n%60;return`reset in ${i}h ${s.toString().padStart(2,"0")}m`}function p2e({entry:e,now:t}){if(e.status==="active")return f.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground",children:[f.jsx("span",{className:"size-1.5 rounded-full bg-muted-foreground/50","aria-hidden":"true"}),"Active"]});if(e.status==="limited"){const r=e.limitedUntil!==null?h2e(e.limitedUntil-t):null;return f.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-amber-600 dark:text-amber-400",children:[f.jsx("span",{className:"size-1.5 rounded-full bg-amber-500","aria-hidden":"true"}),"Limited",r!==null&&f.jsxs(f.Fragment,{children:[" ","(",f.jsx("span",{className:"tabular-nums",children:r}),")"]})]})}if(e.status==="disabled")return f.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground/60",children:[f.jsx("span",{className:"size-1.5 rounded-full bg-muted-foreground/30","aria-hidden":"true"}),"Disabled"]});const n=e.lastErrorMessage??"Unknown error";return f.jsx(My,{children:f.jsxs(Yr,{children:[f.jsx(Xr,{asChild:!0,children:f.jsxs("span",{className:"inline-flex cursor-default items-center gap-1.5 text-xs text-destructive",children:[f.jsx("span",{className:"size-1.5 rounded-full bg-destructive","aria-hidden":"true"}),"Error",f.jsx("span",{className:"sr-only",children:n})]})}),f.jsx(Br,{"aria-hidden":"true",children:n})]})})}function m2e({entry:e,now:t,isCurrent:n,onRemove:r,onToggleDisabled:i,onTest:s}){const[o,l]=v.useState(null),[c,u]=v.useState(!1),p=async()=>{u(!0),l(null);try{const g=await s(e.token),b=g.ok?"OK":g.error??"Error";l(b),setTimeout(()=>l(null),3e3)}catch{l("Error"),setTimeout(()=>l(null),3e3)}finally{u(!1)}},h=e.status==="disabled";return f.jsxs("div",{className:"flex items-center justify-between gap-3 border-t border-border py-3",children:[f.jsxs("div",{className:"min-w-0 flex-1",children:[f.jsxs("div",{className:"flex items-center gap-3",children:[f.jsx("span",{className:`text-sm font-medium ${h?"text-muted-foreground/60":"text-foreground"}`,children:e.label}),f.jsx("code",{className:"text-xs font-mono text-muted-foreground",children:f2e(e.token)}),n&&f.jsx("span",{className:"inline-flex items-center rounded-full border border-primary/40 bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-primary",children:"In use"})]}),f.jsx("div",{className:"mt-0.5",children:f.jsx(p2e,{entry:e,now:t})})]}),f.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[o!==null&&f.jsx("span",{className:"text-xs text-muted-foreground",children:o}),f.jsxs("button",{type:"button","aria-label":"Test",onClick:p,disabled:c||h,className:"inline-flex items-center gap-1 rounded px-2 py-1 text-xs text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",children:[f.jsx(pW,{className:"size-3","aria-hidden":"true"}),"Test"]}),f.jsx(My,{children:f.jsxs(Yr,{children:[f.jsx(Xr,{asChild:!0,children:f.jsxs("button",{type:"button","aria-label":h?"Enable":"Disable",onClick:i,className:"rounded p-1 text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[h?f.jsx(hG,{className:"size-3.5","aria-hidden":"true"}):f.jsx(dG,{className:"size-3.5","aria-hidden":"true"}),f.jsx("span",{className:"sr-only",children:h?"Enable":"Disable"})]})}),f.jsx(Br,{children:h?"Enable":"Disable"})]})}),f.jsxs("button",{type:"button","aria-label":"Remove",onClick:r,className:"rounded p-1 text-muted-foreground transition-colors hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[f.jsx(qd,{className:"size-3.5","aria-hidden":"true"}),f.jsx("span",{className:"sr-only",children:"Remove"})]})]})]})}function g2e({tokens:e,onWrite:t}){const[n,r]=v.useState(""),[i,s]=v.useState(""),[o,l]=v.useState(!1),c=n.trim().length>0&&i.trim().length>0&&!o,u=async()=>{if(c){l(!0);try{const p={id:crypto.randomUUID(),label:n.trim(),token:i.trim(),status:"active",limitedUntil:null,lastUsedAt:null,lastErrorAt:null,lastErrorMessage:null,addedAt:Date.now()};await t({tokens:[...e,p]}),r(""),s("")}finally{l(!1)}}};return f.jsx("div",{className:"border-t border-border pt-4",children:f.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-end sm:gap-3",children:[f.jsx("div",{className:"flex-1",children:f.jsx(Kn,{value:n,onChange:p=>r(p.target.value),placeholder:"e.g. personal",maxLength:64,className:"text-sm","aria-label":"Token label"})}),f.jsx("div",{className:"flex-[2]",children:f.jsx(Kn,{value:i,onChange:p=>s(p.target.value),type:"password",placeholder:"sk-ant-...",maxLength:1024,className:"text-sm font-mono","aria-label":"OAuth token"})}),f.jsx("button",{type:"button",onClick:u,disabled:!c,className:"inline-flex shrink-0 items-center rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",children:"Add token"})]})})}function v2e({tokens:e,onWrite:t,onTest:n,now:r}){var c;const i=r??Date.now(),s=((c=e.reduce((u,p)=>p.lastUsedAt!==null&&(u===null||p.lastUsedAt>(u.lastUsedAt??0))?p:u,null))==null?void 0:c.id)??null,o=u=>{t({tokens:e.filter(p=>p.id!==u)})},l=u=>{t({tokens:e.map(p=>p.id===u?{...p,status:p.status==="disabled"?"active":"disabled"}:p)})};return f.jsxs("div",{children:[e.map(u=>f.jsx(m2e,{entry:u,now:i,isCurrent:u.id===s,onRemove:()=>o(u.id),onToggleDisabled:()=>l(u.id),onTest:n},u.id)),f.jsx(g2e,{tokens:e,onWrite:t})]})}function tp({children:e,className:t,icon:n,type:r="button",variant:i="outline",...s}){return f.jsxs("button",{type:r,className:me(vy({variant:i,size:"sm"}),"h-auto gap-1.5 px-3 py-1.5",t),...s,children:[n,f.jsx("span",{children:e})]})}const jP="inline-flex items-center justify-center rounded-lg border border-border bg-background px-3 py-1.5 text-sm font-medium text-foreground transition-colors hover:bg-muted",b2e="inline-flex items-center justify-center rounded-lg bg-foreground px-3 py-1.5 text-sm font-medium text-background transition-colors hover:bg-foreground/90",DP="rounded bg-muted px-1 py-0.5 font-mono text-[12px] text-foreground",IP="text-[11px] font-medium uppercase tracking-wide text-muted-foreground";function y2e(e){const{permissionState:t}=e;if(t==="unsupported")return f.jsx("p",{className:"text-sm text-muted-foreground",children:"Push notifications are not supported in this browser."});if(t==="insecure-context")return f.jsxs("p",{className:"text-sm text-muted-foreground",children:["Push requires HTTPS. Run ",f.jsx("code",{className:DP,children:"kanna --share"})," or open Kanna over a tunnel, then enable on this device."]});if(t==="denied")return f.jsx("p",{className:"text-sm text-muted-foreground",children:"You blocked notifications for this site. Re-enable them in your browser settings, then reload."});if(!(t==="granted"&&e.config.devices.some(i=>i.id===e.currentDeviceId)))return f.jsx("button",{type:"button",onClick:()=>void e.onEnable(),className:b2e,children:"Enable on this device"});const r=new Set(e.config.preferences.mutedProjectPaths);return f.jsxs("div",{className:"flex w-full min-w-0 flex-col gap-5 md:w-[440px]",children:[f.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[f.jsxs("span",{className:"inline-flex items-center gap-2 rounded-full border border-border bg-card/40 px-3 py-1 text-xs font-medium text-foreground",children:[f.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-emerald-500","aria-hidden":!0}),"Enabled on this device"]}),f.jsx("button",{type:"button",onClick:()=>void e.onTest(),className:jP,children:"Send test"}),f.jsx("button",{type:"button",onClick:()=>void e.onDisable(),className:jP,children:"Disable"})]}),f.jsxs("div",{className:"flex flex-col gap-2",children:[f.jsx("div",{className:IP,children:"Devices"}),f.jsx("ul",{className:"flex flex-col gap-1.5",children:e.config.devices.map(i=>f.jsxs("li",{className:"flex items-start justify-between gap-3 rounded-lg border border-border bg-card/40 px-3 py-2",children:[f.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[f.jsx("span",{className:"truncate text-sm font-medium text-foreground",children:i.label}),f.jsx("span",{className:"line-clamp-2 break-all text-[11px] leading-snug text-muted-foreground",children:i.userAgent})]}),!i.isCurrentDevice&&f.jsx("button",{type:"button",onClick:()=>void e.onRemoveDevice(i.id),"aria-label":`Remove ${i.label}`,className:"shrink-0 rounded-md border border-border bg-background px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:"Remove"})]},i.id))})]}),f.jsxs("div",{className:"flex flex-col gap-2",children:[f.jsx("div",{className:IP,children:"Per-project"}),f.jsx("ul",{className:"flex flex-col",children:e.projects.map(i=>f.jsx("li",{children:f.jsxs("label",{className:"flex cursor-pointer items-center gap-3 rounded-md px-2 py-1.5 transition-colors hover:bg-muted/50",children:[f.jsx("input",{type:"checkbox",checked:!r.has(i.localPath),onChange:s=>void e.onMuteToggle(i.localPath,!s.target.checked),className:"h-4 w-4 shrink-0 rounded border-border accent-foreground"}),f.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[12px] text-foreground",title:i.localPath,children:i.localPath})]})},i.localPath))})]}),f.jsxs("p",{className:"text-xs leading-relaxed text-muted-foreground",children:["Phone setup: this page must be reachable over HTTPS. Run"," ",f.jsx("code",{className:DP,children:"kanna --share"})," or open Kanna over your tunnel on the phone, then enable on that device."]})]})}const zh=[{id:"general",label:"General",icon:AG,subtitle:"Manage appearance, editor behavior, and embedded terminal defaults."},{id:"skills",label:"Skills",icon:jA,subtitle:"Manage globally installed agent skills from the active skill lock file."},{id:"providers",label:"Providers",icon:GW,subtitle:"Manage the default chat provider and saved model defaults for Claude Code and Codex."},{id:"keybindings",label:"Keybindings",icon:IV,subtitle:"Edit global app shortcuts stored in the active keybindings file."},{id:"changelog",label:"Changelog",icon:jA,subtitle:"Release notes pulled from the public GitHub releases feed."}];function PP(e){return e&&zh.some(t=>t.id===e)?e:null}const x2e=[{value:"light",label:"Light",icon:YG},{value:"dark",label:"Dark",icon:ZW},{value:"system",label:"System",icon:JC}],_2e=[{value:"never",label:"Never"},{value:"unfocused",label:"When Unfocused"},{value:"always",label:"Always"}],w2e=[{value:"disabled",label:"Off"},{value:"enabled",label:"On"}],S2e=[{value:"disabled",label:"Off"},{value:"enabled",label:"On"}],C2e=[{value:"always-ask",label:"Always ask"},{value:"auto-expose",label:"Auto-expose"}],k2e=[{value:"openai",label:"OpenAI"},{value:"openrouter",label:"OpenRouter"},{value:"custom",label:"Custom"}],E2e="https://api.github.com/repos/cuongtranba/kanna/releases",T2e=300*1e3;let fd=null;const OP=Object.keys(O4);function R2e(e){return`Edit global app shortcuts stored in ${e}.`}function zP(e,t){return e!==t}async function N2e(e=fetch){const t=await e(E2e,{headers:{Accept:"application/vnd.github+json"}});if(!t.ok)throw new Error(`GitHub releases request failed with status ${t.status}`);return(await t.json()).filter(r=>!r.draft)}function A2e(){return fd?Date.now()>=fd.expiresAt?(fd=null,null):fd.releases:null}function M2e(e){fd={releases:e,expiresAt:Date.now()+T2e}}async function BP(e){const t=e!=null&&e.force?null:A2e();if(t)return t;const n=await N2e(e==null?void 0:e.fetchImpl);return M2e(n),n}function L2e(e){if(!e)return"Unpublished";const t=new Date(e);return Number.isNaN(t.getTime())?"Unknown date":new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",year:"numeric"}).format(t)}function j2e({status:e,releases:t,error:n,onRetry:r,updateSnapshot:i,currentVersion:s,onInstallUpdate:o,onCheckForUpdates:l,onForceReload:c}){var w;const u=(i==null?void 0:i.latestVersion)??((w=t[0])==null?void 0:w.tag_name)??"Unknown",p=(i==null?void 0:i.currentVersion)??s,h=(i==null?void 0:i.status)==="checking",g=(i==null?void 0:i.status)==="updating"||(i==null?void 0:i.status)==="restart_pending",b=(i==null?void 0:i.updateAvailable)===!0,x=u.replace(/^v/i,""),_=p.replace(/^v/i,"");return f.jsxs("div",{className:"space-y-4",children:[e==="loading"||e==="idle"?f.jsx("div",{className:"flex min-h-[180px] items-center justify-center rounded-2xl border border-border bg-card/40 px-6 py-8 text-sm text-muted-foreground",children:f.jsxs("div",{className:"flex items-center gap-3",children:[f.jsx(Cn,{className:"h-4 w-4 animate-spin"}),f.jsx("span",{children:"Loading release notes…"})]})}):null,e==="error"?f.jsx("div",{className:"rounded-lg border border-destructive/20 bg-destructive/5 px-6 py-5",children:f.jsxs("div",{className:"flex items-start justify-between gap-4",children:[f.jsxs("div",{children:[f.jsx("div",{className:"text-sm font-medium text-foreground",children:"Could not load changelog"}),f.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:n??"Unable to load changelog."})]}),f.jsx("button",{type:"button",onClick:r,className:"rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground transition-colors hover:bg-muted",children:"Retry"})]})}):null,e==="success"&&t.length===0?f.jsxs("div",{className:"rounded-lg border border-border bg-card/30 px-6 py-8",children:[f.jsx("div",{className:"text-sm font-medium text-foreground",children:"No releases yet"}),f.jsx("div",{className:"mt-2 text-sm text-muted-foreground",children:"GitHub did not return any published releases for this repository."})]}):null,e==="success"?f.jsxs("div",{className:"flex justify-end gap-2",children:[f.jsx(tp,{variant:"outline",onClick:c,disabled:g,children:g?"Re-deploying…":"Re-deploy"}),f.jsx(tp,{variant:"outline",onClick:l,disabled:h||g,children:h?"Checking…":"Check for updates"})]}):null,e==="success"&&t.length>0?t.map(C=>{var N,A;const E=C.tag_name.replace(/^v/i,""),k=E===x,R=E===_;return f.jsxs("article",{className:me("rounded-xl border bg-card/30 pl-6 pr-4 py-4",k?"border-border bg-muted":"border-border"),children:[f.jsxs("div",{className:"flex flex-row items-center min-w-0 flex-1 gap-3 ",children:[f.jsxs("div",{className:"flex flex-row items-center min-w-0 flex-1 gap-2 ",children:[f.jsx("div",{className:"text-lg font-semibold tracking-[-0.2px] text-foreground",children:((N=C.name)==null?void 0:N.trim())||C.tag_name}),f.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2 text-sm text-muted-foreground",children:[f.jsx("span",{children:L2e(C.published_at)}),C.prerelease?f.jsx("span",{className:"rounded-full border border-border px-2.5 py-1 uppercase tracking-wide",children:"Prerelease"}):null]})]}),f.jsxs("div",{className:"flex flex-row items-center justify-end min-w-0 flex-1 gap-2 ",children:[f.jsx("a",{href:C.html_url,target:"_blank",rel:"noopener noreferrer","aria-label":"View release on GitHub",className:me(vy({variant:"ghost",size:"icon-sm"}),"h-11 w-11 md:h-8 md:w-8 shrink-0 rounded-md hover:!bg-transparent hover:border-border/0"),children:f.jsx(D2e,{className:"h-4 w-4"})}),R?f.jsx("span",{className:me("bg-transparent border border-border text-secondary-foreground","h-9 rounded-full px-3 text-sm","h-auto gap-1.5 px-3 py-1.5"),children:"Current"}):null,k&&b?f.jsx(tp,{variant:"default",className:"",onClick:o,disabled:g,children:f.jsxs("div",{className:"flex flex-row items-center justify-center gap-2",children:[f.jsx(NV,{className:"size-4"}),g?"Updating…":"Update"]})}):null]})]}),(A=C.body)!=null&&A.trim()?f.jsx("div",{className:"prose prose-sm mt-5 max-w-none text-foreground dark:prose-invert",children:f.jsx(tu,{remarkPlugins:[uB],components:YE,children:C.body})}):f.jsx("div",{className:"mt-5 text-sm text-muted-foreground",children:"No release notes were provided."})]},C.id)}):null]})}function D2e({className:e}){return f.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",className:e,children:f.jsx("path",{d:"M12 .5C5.649.5.5 5.649.5 12A11.5 11.5 0 0 0 8.36 22.04c.575.106.785-.25.785-.556 0-.274-.01-1-.015-1.962-3.181.691-3.853-1.532-3.853-1.532-.52-1.322-1.27-1.674-1.27-1.674-1.038-.71.08-.695.08-.695 1.148.08 1.752 1.178 1.752 1.178 1.02 1.748 2.676 1.243 3.328.95.103-.738.399-1.243.725-1.53-2.54-.289-5.211-1.27-5.211-5.65 0-1.248.446-2.27 1.177-3.07-.118-.288-.51-1.45.112-3.024 0 0 .96-.307 3.145 1.173A10.91 10.91 0 0 1 12 6.03c.973.004 1.954.132 2.87.387 2.182-1.48 3.14-1.173 3.14-1.173.625 1.573.233 2.736.115 3.024.734.8 1.175 1.822 1.175 3.07 0 4.39-2.676 5.358-5.224 5.642.41.353.776 1.05.776 2.117 0 1.528-.014 2.761-.014 3.136 0 .309.207.668.79.555A11.502 11.502 0 0 0 23.5 12C23.5 5.649 18.351.5 12 .5Z"})})}function I2e(e){return!e||e<=0?"0 installs":e>=1e6?`${(e/1e6).toFixed(1).replace(/\.0$/,"")}M installs`:e>=1e3?`${(e/1e3).toFixed(1).replace(/\.0$/,"")}K installs`:`${e} install${e===1?"":"s"}`}function P2e({message:e}){return f.jsx("pre",{className:"max-w-full overflow-x-auto whitespace-pre-wrap rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-xs text-destructive",children:e})}function O2e({skill:e,uninstalling:t,onUninstall:n}){const r=e.source?`https://skills.sh/${e.source}/${e.name}`:null;return f.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3 rounded-lg border border-border bg-card/30 p-3",children:[f.jsxs("div",{className:"min-w-0",children:[f.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:e.name}),f.jsx("div",{className:"truncate text-xs text-muted-foreground",children:e.source||"Unknown source"})]}),f.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[r?f.jsx("a",{href:r,target:"_blank",rel:"noreferrer","aria-label":`View ${e.name} on skills.sh`,className:"touch-manipulation inline-flex h-8 w-8 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:f.jsx(XC,{className:"h-4 w-4"})}):null,f.jsx("button",{type:"button","aria-label":`Uninstall ${e.name}`,disabled:t,onClick:n,className:"touch-manipulation inline-flex h-8 w-8 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive disabled:pointer-events-none disabled:opacity-50",children:t?f.jsx(Cn,{className:"h-4 w-4 animate-spin"}):f.jsx(qd,{className:"h-4 w-4"})})]})]})}function z2e({skill:e,installing:t,installed:n,message:r,onInstall:i}){return f.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3 rounded-lg border border-border bg-card/30 p-3",children:[f.jsxs("div",{className:"min-w-0",children:[f.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:e.name}),f.jsxs("div",{className:"truncate text-xs text-muted-foreground",children:[e.source," · ",I2e(e.installs)]}),n&&r?f.jsx("div",{className:"mt-1 truncate text-xs text-emerald-500",children:r}):null]}),f.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[f.jsx("a",{href:`https://skills.sh/${e.id}`,target:"_blank",rel:"noreferrer","aria-label":`View ${e.name} on skills.sh`,className:"touch-manipulation inline-flex h-8 w-8 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:f.jsx(XC,{className:"h-4 w-4"})}),f.jsxs(Ge,{type:"button",size:"sm",variant:n?"secondary":"default",disabled:t||n,onClick:i,className:"h-6 rounded-full px-2 text-xs",children:[t?f.jsx(Cn,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):null,n?"Installed":t?"Installing":"Get"]})]})]})}function B2e({state:e}){const t=e.socket,n=e.connectionStatus,[r,i]=v.useState(""),[s,o]=v.useState([]),[l,c]=v.useState(!1),[u,p]=v.useState(null),[h,g]=v.useState([]),[b,x]=v.useState(()=>new Set),[_,w]=v.useState(!1),[C,E]=v.useState(null),[k,R]=v.useState(null),[N,A]=v.useState(null),[M,D]=v.useState(null),[U,j]=v.useState({}),P=v.useCallback(async()=>{if(n!=="connected"){g([]),x(new Set),E(null),w(!1);return}try{w(!0),E(null);const $=await t.command({type:"skills.listInstalled"});g($.skills),x(new Set($.skills.map(V=>V.name)))}catch($){g([]),x(new Set),E($ instanceof Error?$.message:"Unable to read installed skills.")}finally{w(!1)}},[n,t]);v.useEffect(()=>{P()},[n,P,t]),v.useEffect(()=>{const $=r.trim();if($.length<2){o([]),p(null),c(!1);return}if(n!=="connected"){o([]),c(!1),p("Backend connection required.");return}let V=!1;c(!0),p(null);const B=window.setTimeout(()=>{t.command({type:"skills.search",query:$,limit:100}).then(F=>{V||o(F.skills)}).catch(F=>{V||(o([]),p(F instanceof Error?F.message:"Unable to search skills."))}).finally(()=>{V||c(!1)})},250);return()=>{V=!0,window.clearTimeout(B)}},[n,r,t]);async function z($){if(n!=="connected"){R("Backend connection required.");return}try{A($.id),R(null),j(V=>{const B={...V};return delete B[$.id],B}),await t.command({type:"skills.install",source:$.source,skillId:$.skillId}),x(V=>new Set(V).add($.skillId)),j(V=>({...V,[$.id]:"Installed globally"})),P()}catch(V){R(V instanceof Error?V.message:"Install failed.")}finally{A(null)}}async function O($){if(n!=="connected"){R("Backend connection required.");return}try{D($.name),R(null),await t.command({type:"skills.uninstall",skillId:$.name}),g(V=>V.filter(B=>B.name!==$.name)),x(V=>{const B=new Set(V);return B.delete($.name),B}),j(V=>{const B={...V};for(const F of Object.keys(B))(F.endsWith(`/${$.name}`)||F===$.name)&&delete B[F];return B}),P()}catch(V){R(V instanceof Error?V.message:"Uninstall failed.")}finally{D(null)}}return f.jsxs("div",{className:"flex flex-col gap-6",children:[k?f.jsx(P2e,{message:k}):null,f.jsxs("section",{className:"flex flex-col gap-3",children:[f.jsxs("div",{className:"flex items-center justify-between gap-3",children:[f.jsx("div",{className:"text-sm font-medium text-foreground",children:"Installed"}),_?f.jsx(Cn,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}):null]}),C?f.jsx("div",{className:"text-xs text-destructive",children:C}):null,h.length>0?f.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:h.map($=>f.jsx(O2e,{skill:$,uninstalling:M===$.name,onUninstall:()=>{O($)}},`${$.source}/${$.name}`))}):_?null:f.jsx("div",{className:"rounded-lg border border-border bg-card/30 p-3 text-sm text-muted-foreground",children:"No global skills installed."})]}),f.jsxs("section",{className:"flex flex-col gap-3",children:[f.jsx("div",{className:"text-sm font-medium text-foreground",children:"Discover"}),f.jsxs("div",{className:"flex h-10 items-center gap-2 rounded-lg border border-border bg-card/30 px-3",children:[f.jsx(Bh,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),f.jsx("input",{type:"text",role:"searchbox",value:r,onChange:$=>i($.target.value),placeholder:"Search skills",className:"min-w-0 flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground"}),r?f.jsx("button",{type:"button","aria-label":"Clear skills search",onClick:()=>i(""),className:"touch-manipulation inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:f.jsx(io,{className:"h-3.5 w-3.5"})}):null,l?f.jsx(Cn,{className:"h-4 w-4 shrink-0 animate-spin text-muted-foreground"}):null]}),u?f.jsx("div",{className:"text-xs text-destructive",children:u}):null,f.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:s.map($=>f.jsx(z2e,{skill:$,installing:N===$.id,installed:b.has($.skillId),message:U[$.id],onInstall:()=>{z($)}},$.id))}),!l&&!u&&r.trim().length>=2&&s.length===0?f.jsx("div",{className:"rounded-lg border border-border bg-card/30 p-3 text-sm text-muted-foreground",children:"No skills found."}):null]})]})}function Gn({title:e,description:t,children:n,bordered:r=!0,alignStart:i=!1}){return f.jsx("div",{className:r?"border-t border-border":void 0,children:f.jsxs("div",{className:me("flex flex-col gap-4 py-5 md:flex-row md:justify-between md:gap-8",i?"md:items-start":"md:items-center"),children:[f.jsxs("div",{className:"min-w-0 max-w-xl",children:[f.jsx("div",{className:"text-sm font-medium text-foreground",children:e}),f.jsx("div",{className:"mt-1 text-[13px] text-muted-foreground",children:t})]}),f.jsx("div",{className:"flex items-center justify-start md:shrink-0 md:justify-end",children:n})]})})}function F2e({checked:e,onChange:t}){return f.jsxs("label",{className:"inline-flex items-center gap-2",children:[f.jsx("input",{type:"checkbox",checked:e,onChange:n=>t(n.target.checked)}),"Enabled"]})}function $2e(){var tr,li,lo;const e=Wd(),{sectionId:t}=o5(),n=$C(),{theme:r,setTheme:i}=u2(),[s,o]=v.useState("idle"),[l,c]=v.useState(!1),[u,p]=v.useState(!1),[h,g]=v.useState([]),[b,x]=v.useState(null),_=PP(t)??"general",w=n.connectionStatus==="connecting"||!n.localProjectsReady,C=((tr=n.localProjects)==null?void 0:tr.machine.displayName)??"Unavailable",E=((li=n.localProjects)==null?void 0:li.projects.length)??0,k=kk.split("/")[1]??"unknown",R=hi(Q=>Q.scrollbackLines),N=hi(Q=>Q.minColumnWidth),A=hi(Q=>Q.editorPreset),M=hi(Q=>Q.editorCommandTemplate),D=hi(Q=>Q.setScrollbackLines),U=hi(Q=>Q.setMinColumnWidth),j=hi(Q=>Q.setEditorPreset),P=hi(Q=>Q.setEditorCommandTemplate),z=Ec(Q=>Q.chatSoundPreference),O=Ec(Q=>Q.chatSoundId),$=Ec(Q=>Q.setChatSoundPreference),V=Ec(Q=>Q.setChatSoundId),B=n.keybindings,F=n.appSettings,W=n.llmProvider,X=G1(Q=>Q.autoResumeOnRateLimit),I=G1(Q=>Q.setAutoResumeOnRateLimit),G=gi(Q=>Q.defaultProvider),ee=gi(Q=>Q.providerDefaults),H=gi(Q=>Q.setDefaultProvider),ue=gi(Q=>Q.setProviderDefaultModel),ae=gi(Q=>Q.setProviderDefaultModelOptions),J=gi(Q=>Q.setProviderDefaultPlanMode),te=v.useMemo(()=>Jk(B),[B]),ie=te.filePathDisplay||zQ(),[de,he]=v.useState(()=>q1().state),[Le,ce]=v.useState(()=>cF()),[De,pe]=v.useState(String(R)),[st,zt]=v.useState(String(N)),Et=(F==null?void 0:F.uploads.maxFileSizeMb)??KM.maxFileSizeMb,[Qt,Dt]=v.useState(String(Et)),Tt=(F==null?void 0:F.claudeDriver.preference)??YM.preference,mt=Math.round(((F==null?void 0:F.claudeDriver.lifecycle.idleTimeoutMs)??Hv.idleTimeoutMs)/6e4),At=(F==null?void 0:F.claudeDriver.lifecycle.maxConcurrent)??Hv.maxConcurrent,[It,ht]=v.useState(String(mt)),[Ht,ge]=v.useState(String(At)),[we,Be]=v.useState(M),[tt,Pe]=v.useState({}),[Ve,qe]=v.useState(null),[Xe,We]=v.useState(null),[gt,ot]=v.useState(!1),[Bt,ut]=v.useState(null),[on,cn]=v.useState((F==null?void 0:F.cloudflareTunnel.cloudflaredPath)??XM.cloudflaredPath),[vt,Rt]=v.useState({provider:"openai",apiKey:"",model:"",baseUrl:""}),[St,Ut]=v.useState(null),[xt,ft]=v.useState("idle"),[Lt,Pt]=v.useState(null),[Ie,ze]=v.useState(!1),Te=n.updateSnapshot,Ye=n.handleWriteAppSettings,_e=n.handleWriteCloudflareTunnel,Je=n.handleWriteClaudeAuth,et=n.handleTestOAuthToken,$e=n.handleReadLlmProvider,Mt=n.handleWriteLlmProvider,un=n.handleValidateLlmProvider,Zt=(Te==null?void 0:Te.status)==="checking"?"Checking for updates…":(Te==null?void 0:Te.status)==="updating"?"Installing update…":(Te==null?void 0:Te.status)==="restart_pending"?"Restarting Kanna…":(Te==null?void 0:Te.status)==="available"?`Update available${Te.latestVersion?`: ${Te.latestVersion}`:""}`:(Te==null?void 0:Te.status)==="up_to_date"?"Up to date":(Te==null?void 0:Te.status)==="error"?"Update check failed":"Not checked yet";v.useEffect(()=>{pe(String(R))},[R]),v.useEffect(()=>{zt(String(N))},[N]),v.useEffect(()=>{Dt(String(Et))},[Et]),v.useEffect(()=>{ht(String(mt))},[mt]),v.useEffect(()=>{ge(String(At))},[At]),v.useEffect(()=>{const Q=()=>he(q1().state);return window.addEventListener("focus",Q),()=>window.removeEventListener("focus",Q)},[]),v.useEffect(()=>{Be(M)},[M]),v.useEffect(()=>{Pe(Object.fromEntries(OP.map(Q=>[Q,Q_(te.bindings[Q])])))},[te]),v.useEffect(()=>{W&&Rt({provider:W.provider,apiKey:W.apiKey,model:W.model,baseUrl:W.baseUrl})},[W]),v.useEffect(()=>{ft("idle"),Pt(null)},[vt.provider,vt.apiKey,vt.model,vt.baseUrl]),v.useEffect(()=>{t&&(PP(t)||e("/settings/general",{replace:!0}))},[e,t]),v.useEffect(()=>{F&&cn(F.cloudflareTunnel.cloudflaredPath)},[F]),v.useEffect(()=>{let Q=!1;return fetch("/auth/status",{method:"GET",cache:"no-store",headers:{Accept:"application/json"}}).then(async Oe=>Oe.ok?await Oe.json():{enabled:!1}).then(Oe=>{Q||p(Oe.enabled===!0)}).catch(()=>{Q||p(!1)}),()=>{Q=!0}},[]),v.useEffect(()=>{_!=="providers"||w||$e()},[$e,w,_]),v.useEffect(()=>{if(_!=="changelog"||w)return;let Q=!1;return o("loading"),x(null),BP().then(Oe=>{Q||(g(Oe),o("success"))}).catch(Oe=>{Q||(x(Oe instanceof Error?Oe.message:"Unable to load changelog."),o("error"))}),()=>{Q=!0}},[w,_]);function Fe(){const Q=Number(De);if(!Number.isFinite(Q)){pe(String(R));return}D(Q),Ye({terminal:{scrollbackLines:Q}}).catch(Oe=>{We(Oe instanceof Error?Oe.message:"Unable to save terminal settings.")})}function hn(){const Q=Number(st);if(!Number.isFinite(Q)){zt(String(N));return}U(Q),Ye({terminal:{minColumnWidth:Q}}).catch(Oe=>{We(Oe instanceof Error?Oe.message:"Unable to save terminal settings.")})}function lr(){const Q=Number(Qt);if(!Number.isFinite(Q)||Q<Fg||Q>$g){Dt(String(Et)),We(`Max file size must be between ${Fg} and ${$g} MB.`);return}if(Math.round(Q)===Et){Dt(String(Et));return}Ye({uploads:{maxFileSizeMb:Math.round(Q)}}).catch(Oe=>{We(Oe instanceof Error?Oe.message:"Unable to save upload settings.")})}function se(Q){Q!==Tt&&Ye({claudeDriver:{preference:Q}}).catch(Oe=>{We(Oe instanceof Error?Oe.message:"Unable to save Claude driver preference.")})}function le(){const Q=Number(It),Oe=Math.round(Y_/6e4),xn=Math.round(X_/6e4);if(!Number.isFinite(Q)||Q<Oe||Q>xn){ht(String(mt)),We(`Idle timeout must be between ${Oe} and ${xn} minutes.`);return}if(Math.round(Q)===mt){ht(String(mt));return}Ye({claudeDriver:{lifecycle:{idleTimeoutMs:Math.round(Q)*6e4}}}).catch(co=>{We(co instanceof Error?co.message:"Unable to save Claude lifecycle settings.")})}function Ce(){const Q=Number(Ht);if(!Number.isFinite(Q)||Q<Hg||Q>Ug){ge(String(At)),We(`Max concurrent sessions must be between ${Hg} and ${Ug}.`);return}if(Math.round(Q)===At){ge(String(At));return}Ye({claudeDriver:{lifecycle:{maxConcurrent:Math.round(Q)}}}).catch(Oe=>{We(Oe instanceof Error?Oe.message:"Unable to save Claude lifecycle settings.")})}function Ee(Q,Oe){Q.key==="Enter"&&(Oe(),Q.currentTarget.blur())}function Qe(Q,Oe){Q.key==="Enter"&&(Oe(),Q.currentTarget.blur())}function ct(){P(we),Ye({editor:{commandTemplate:we}}).catch(Q=>{We(Q instanceof Error?Q.message:"Unable to save editor settings.")})}function Ze(Q){i(Q),Ye({theme:Q}).catch(Oe=>{We(Oe instanceof Error?Oe.message:"Unable to save theme settings.")})}function Vt(Q){j(Q);const Oe=Q==="custom"?M:Md(Q);Ye({editor:{preset:Q,commandTemplate:Oe}}).catch(xn=>{We(xn instanceof Error?xn.message:"Unable to save editor settings.")})}function Dn(Q){zP(z,Q)&&($(Q),Ye({chatSoundPreference:Q}).catch(Oe=>{We(Oe instanceof Error?Oe.message:"Unable to save chat sound settings.")}),DS(O,1).catch(()=>{}))}function fn(Q){zP(O,Q)&&(V(Q),Ye({chatSoundId:Q}).catch(Oe=>{We(Oe instanceof Error?Oe.message:"Unable to save chat sound settings.")}),DS(Q,1).catch(()=>{}))}async function Si(Q){try{We(null),await Ye({analyticsEnabled:Q==="enabled"})}catch(Oe){We(Oe instanceof Error?Oe.message:"Unable to save analytics settings.")}}async function Vn(Q){try{ut(null),await _e(Q)}catch(Oe){ut(Oe instanceof Error?Oe.message:"Unable to save Cloudflare Tunnel settings.")}}function Tr(Q){H(Q),Ye({defaultProvider:Q}).catch(Oe=>{We(Oe instanceof Error?Oe.message:"Unable to save provider settings.")})}function Qr(Q,Oe){ue(Q,Oe),Ye({providerDefaults:{[Q]:{model:Oe}}}).catch(xn=>{We(xn instanceof Error?xn.message:"Unable to save provider settings.")})}function Oi(Q,Oe){ae(Q,Oe),Ye({providerDefaults:{[Q]:{modelOptions:Oe}}}).catch(xn=>{We(xn instanceof Error?xn.message:"Unable to save provider settings.")})}function ai(Q,Oe){J(Q,Oe),Ye({providerDefaults:{[Q]:{planMode:Oe}}}).catch(xn=>{We(xn instanceof Error?xn.message:"Unable to save provider settings.")})}async function ts(){try{qe(null),await n.socket.command({type:"settings.writeKeybindings",bindings:FP(tt)})}catch(Q){qe(Q instanceof Error?Q.message:"Unable to save keybindings.")}}async function zi(Q){const Oe={...tt,[Q]:Q_(mp[Q])};Pe(Oe);try{qe(null),await n.socket.command({type:"settings.writeKeybindings",bindings:FP(Oe)})}catch(xn){qe(xn instanceof Error?xn.message:"Unable to save keybindings.")}}async function _t(Q=vt){try{Ut(null),await Mt(Q);const Oe=await un(Q);ft(Oe.ok?"valid":"invalid"),Pt(Oe.error)}catch(Oe){const xn=Oe instanceof Error?{name:Oe.name,message:Oe.message}:Oe;ft("invalid"),Pt(xn),Ut(Oe instanceof Error?Oe.message:"Unable to save quick response provider settings.")}}function an(Q){const Oe={...vt,provider:Q,model:Q==="openai"?Kte:Q==="openrouter"?Yte:vt.model,baseUrl:Q==="custom"?vt.baseUrl:""};Rt(Oe),_t(Oe)}function kn(){fd=null,o("loading"),x(null),BP({force:!0}).then(Q=>{g(Q),o("success")}).catch(Q=>{x(Q instanceof Error?Q.message:"Unable to load changelog."),o("error")})}const gn=we.replaceAll("{path}","/Users/jake/Projects/kanna/src/client/app/App.tsx").replaceAll("{line}","12").replaceAll("{column}","1"),ao=u2e,Da=(F==null?void 0:F.analyticsEnabled)===!1?"disabled":"enabled",ns=(F==null?void 0:F.cloudflareTunnel)??XM,Fo=ns.enabled?"enabled":"disabled",rs=zh.find(Q=>Q.id===_)??zh[0],Ia=_==="keybindings"?R2e(ie):rs.subtitle,cr=!w,je=Lt?JSON.stringify(Lt,null,2):"",Ke=f.jsxs(f.Fragment,{children:[f.jsxs("span",{children:["Use an OpenAI-compatible API for title and commit message generation before Claude and Codex. Stored in ",(W==null?void 0:W.filePathDisplay)??"the active llm-provider.json file","."]}),f.jsx("span",{className:me("mt-2 block text-sm font-medium",xt==="valid"?"text-success":xt==="invalid"?"text-destructive":"hidden"),children:xt==="valid"?"Credentials valid & saved":xt==="invalid"?f.jsxs(f.Fragment,{children:[f.jsx("span",{children:"Credentials invalid."}),Lt?f.jsxs(f.Fragment,{children:[" ",f.jsx("button",{type:"button",onClick:()=>ze(!0),className:"underline underline-offset-2",children:"See error"})]}):null]}):null})]});async function Ft(){if(!l){c(!0);try{await n.handleSignOut()}finally{c(!1)}}}return f.jsxs("div",{className:"relative flex h-full flex-1 min-w-0 bg-background",children:[f.jsxs("div",{className:"flex min-w-0 flex-1",children:[f.jsx("aside",{className:`hidden w-[200px] shrink-0 md:block ${cr?"pb-[89px]":""}`,children:f.jsxs("div",{className:"flex flex-col gap-1 px-4 py-6",children:[f.jsx("div",{className:"px-3 pb-5 text-[22px] font-extrabold tracking-[-0.5px] text-foreground",children:"Settings"}),zh.map(Q=>{const Oe=Q.id==="changelog"&&(Te==null?void 0:Te.updateAvailable)===!0;return f.jsx("button",{type:"button",onClick:()=>e(`/settings/${Q.id}`),className:`cursor-pointer rounded-lg px-3 py-2 text-sm ${Q.id===_?"bg-muted font-medium text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"}`,children:f.jsxs("div",{className:"flex items-center gap-2.5",children:[f.jsx(Q.icon,{className:"h-4 w-4 shrink-0"}),f.jsx("span",{children:Q.label}),Oe?f.jsx("span",{className:"ml-auto inline-flex items-center rounded-full bg-logo/20 px-2 py-0.5 text-[10px] font-bold tracking-wider text-logo",children:"UPDATE"}):null]})},Q.label)}),u?f.jsx("button",{type:"button",onClick:()=>{Ft()},disabled:l,className:"cursor-pointer rounded-lg px-3 py-2 text-sm text-muted-foreground hover:bg-muted/50 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",children:f.jsxs("div",{className:"flex items-center gap-2.5",children:[f.jsx(OA,{className:"h-4 w-4 shrink-0"}),f.jsx("span",{children:l?"Signing out...":"Sign out"})]})}):null]})}),f.jsxs("div",{className:"min-w-0 flex-1 overflow-y-auto",children:[f.jsx("div",{className:"border-b border-border py-2 md:hidden",children:f.jsx("div",{className:"overflow-x-auto pr-4 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:f.jsxs("div",{className:"flex min-w-max items-center gap-2",children:[f.jsx("div",{className:" sticky left-0 bg-gradient-to-r from-background via-background/80 to-transparent px-2 py-1",children:f.jsx("button",{type:"button",onClick:n.openSidebar,className:"flex shrink-0 items-center p-2 text-sm text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground","aria-label":"Open sidebar",title:"Open sidebar",children:f.jsx(ZC,{className:"h-4 w-4 shrink-0"})})}),zh.map(Q=>f.jsxs("button",{type:"button",onClick:()=>e(`/settings/${Q.id}`),className:me("flex shrink-0 items-center gap-2 rounded-full border px-3 py-2 text-sm transition-colors",Q.id===_?"border-transparent bg-muted font-medium text-foreground":"border-border bg-background text-muted-foreground hover:bg-muted/50 hover:text-foreground"),children:[f.jsx(Q.icon,{className:"h-4 w-4 shrink-0"}),f.jsx("span",{className:"whitespace-nowrap",children:Q.label})]},Q.label)),u?f.jsxs("button",{type:"button",onClick:()=>{Ft()},disabled:l,className:me("flex shrink-0 items-center gap-2 rounded-full border px-3 py-2 text-sm transition-colors","border-border bg-background text-muted-foreground hover:bg-muted/50 hover:text-foreground","disabled:cursor-not-allowed disabled:opacity-50"),children:[f.jsx(OA,{className:"h-4 w-4 shrink-0"}),f.jsx("span",{className:"whitespace-nowrap",children:l?"Signing out...":"Sign out"})]}):null]})})}),f.jsxs("div",{className:"w-full px-4 pb-32 pt-8 md:px-6 md:pt-16",children:[w?f.jsx("div",{className:"flex min-h-[240px] items-center justify-center rounded-2xl border border-border bg-card/40 px-4 py-6 text-sm text-muted-foreground",children:f.jsxs("div",{className:"flex items-center gap-3",children:[f.jsx(Cn,{className:"h-4 w-4 animate-spin"}),f.jsx("span",{children:"Loading machine settings…"})]})}):f.jsxs("div",{className:"mx-auto max-w-4xl",children:[f.jsxs("div",{className:"pb-6",children:[f.jsxs("div",{className:"flex items-center justify-between gap-4 min-h-[34px]",children:[f.jsx("div",{className:"text-lg font-semibold tracking-[-0.2px] text-foreground",children:rs.label}),_==="general"?f.jsx(tp,{variant:"outline",onClick:()=>e("/settings/changelog"),children:"Check for updates"}):null,_==="keybindings"?f.jsxs(tp,{onClick:()=>{n.handleOpenExternalPath("open_editor",ie)},icon:f.jsx(KC,{className:"h-4 w-4"}),children:["Open in ",n.editorLabel]}):null]}),f.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:Ia})]}),_==="general"?f.jsxs(f.Fragment,{children:[Xe?f.jsx("div",{className:"mb-4 rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-sm text-destructive",children:Xe}):null,f.jsxs("div",{className:"border-b border-border",children:[f.jsx(Gn,{title:"Application Update",description:f.jsxs(f.Fragment,{children:[f.jsxs("span",{children:[Zt,"."]}),Te!=null&&Te.lastCheckedAt?f.jsxs("span",{children:[" Last checked ",new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(Te.lastCheckedAt),"."]}):null,Te!=null&&Te.error?f.jsxs("span",{children:[" ",Te.error]}):null]}),bordered:!1,children:f.jsxs("div",{className:"text-right text-sm text-foreground",children:[f.jsxs("div",{children:["Current: ",(Te==null?void 0:Te.currentVersion)??k]}),f.jsxs("div",{className:"text-xs text-muted-foreground",children:["Latest: ",(Te==null?void 0:Te.latestVersion)??"Unknown"]})]})}),f.jsx(Gn,{title:"Theme",description:"Choose between light, dark, or system appearance",children:f.jsx(da,{value:r,onValueChange:Ze,options:x2e,size:"sm"})}),f.jsx(Gn,{title:"Chat Sounds",description:"Play a pop when a chat starts waiting on you or the unread chat count increases",children:f.jsxs(Sl,{value:z,onValueChange:Q=>Dn(Q),children:[f.jsx(fa,{className:"min-w-[180px]",children:f.jsx(Sc,{})}),f.jsx(ha,{children:f.jsx(id,{children:_2e.map(Q=>f.jsx(Ws,{value:Q.value,children:Q.label},Q.value))})})]})}),f.jsx(Gn,{title:"Chat Sound",description:"The bundled sound used for chat notification playback and previews",children:f.jsxs(Sl,{value:O,onValueChange:Q=>fn(Q),children:[f.jsx(fa,{className:"min-w-[180px]",children:f.jsx(Sc,{})}),f.jsx(ha,{children:f.jsx(id,{children:UQ.map(Q=>f.jsx(Ws,{value:Q.value,children:Q.label},Q.value))})})]})}),f.jsx(Gn,{title:"Default Editor",description:"Used when opening transcript links or files from the git diff menu",alignStart:!0,children:f.jsxs(Sl,{value:A,onValueChange:Q=>Vt(Q),children:[f.jsx(fa,{className:"min-w-[180px]",children:f.jsx(Sc,{})}),f.jsx(ha,{children:f.jsx(id,{children:nE.map(Q=>f.jsx(Ws,{value:Q.value,children:f.jsxs("span",{className:"flex items-center gap-2",children:[f.jsx(U4,{preset:Q.value,className:"h-4 w-4 shrink-0"}),f.jsx("span",{children:Q.label})]})},Q.value))})})]})}),A==="custom"?f.jsx("div",{className:"border-t border-border",children:f.jsxs("div",{className:"flex justify-between gap-8 py-5 pl-6",children:[f.jsxs("div",{className:"min-w-0 max-w-xl",children:[f.jsx("div",{className:"text-sm font-medium text-foreground",children:"Command Template"}),f.jsxs("div",{className:"mt-1 text-[13px] text-muted-foreground",children:["Include ","{path}"," and optionally ","{line}"," and ","{column}"," in your command."]})]}),f.jsxs("div",{className:"flex min-w-0 max-w-[420px] flex-1 flex-col items-stretch gap-2",children:[f.jsx(Kn,{type:"text",value:we,onChange:Q=>Be(Q.target.value),onBlur:ct,onKeyDown:Q=>Qe(Q,ct),className:"font-mono"}),f.jsxs("div",{className:"text-xs text-muted-foreground",children:["Preview: ",f.jsx("span",{className:"font-mono",children:gn})]})]})]})}):null,f.jsx(Gn,{title:"Terminal Scrollback",description:"Lines retained for embedded terminal history",children:f.jsxs("div",{className:"flex w-full min-w-0 flex-col items-stretch gap-2 md:w-auto md:items-end",children:[f.jsx(Kn,{type:"number",min:YS,max:XS,step:100,value:De,onChange:Q=>pe(Q.target.value),onBlur:Fe,onKeyDown:Q=>Ee(Q,Fe),className:"hide-number-steppers w-full text-left font-mono md:w-28 md:text-right"}),f.jsxs("div",{className:"text-left text-xs text-muted-foreground md:text-right",children:[YS,"-",XS," lines",R===eE?" (default)":""]})]})}),f.jsx(Gn,{title:"Terminal Min Column Width",description:"Minimum width for each terminal pane",children:f.jsxs("div",{className:"flex w-full min-w-0 flex-col items-stretch gap-2 md:w-auto md:items-end",children:[f.jsx(Kn,{type:"number",min:QS,max:ZS,step:10,value:st,onChange:Q=>zt(Q.target.value),onBlur:hn,onKeyDown:Q=>Ee(Q,hn),className:"hide-number-steppers w-full text-left font-mono md:w-28 md:text-right"}),f.jsxs("div",{className:"text-left text-xs text-muted-foreground md:text-right",children:[QS,"-",ZS," px",N===tE?" (default)":""]})]})}),f.jsx(Gn,{title:"Max upload file size",description:"Largest single file the chat upload endpoint accepts.",children:f.jsxs("div",{className:"flex w-full min-w-0 flex-col items-stretch gap-1.5 md:w-auto md:items-end",children:[f.jsxs("div",{className:"flex items-center gap-2 md:justify-end",children:[f.jsx(Kn,{type:"number",min:Fg,max:$g,step:1,value:Qt,onChange:Q=>Dt(Q.target.value),onBlur:lr,onKeyDown:Q=>Ee(Q,lr),className:"hide-number-steppers w-full text-left font-mono tabular-nums md:w-24 md:text-right","aria-label":"Max upload file size in megabytes"}),f.jsx("span",{className:"text-sm text-muted-foreground",children:"MB"})]}),f.jsxs("div",{className:"text-left text-xs text-muted-foreground tabular-nums md:text-right",children:[Fg,"–",$g," MB · default ",KM.maxFileSizeMb]})]})}),f.jsx(Gn,{title:"Auto-resume on rate limit",description:'When you hit a rate limit, automatically schedule "continue" at the reset time instead of asking. You can still cancel each one from the chat.',children:f.jsx(F2e,{checked:X,onChange:I})}),n.pushConfig?f.jsx(Gn,{title:"Push notifications",description:"Get notified when a chat is waiting for you, finishes, or fails. Works on iPhone (after Add to Home Screen), Android, and desktop browsers.",bordered:!1,alignStart:!0,children:f.jsx(y2e,{permissionState:de,config:n.pushConfig,projects:((lo=n.localProjects)==null?void 0:lo.projects)??[],currentDeviceId:Le,onEnable:async()=>{if(!n.pushConfig)return;const Q=await uye({vapidPublicKey:n.pushConfig.vapidPublicKey,sendToServer:async Oe=>{const xn=await n.socket.command({type:"push.subscribe",subscription:Oe.subscription,label:Oe.label,userAgent:Oe.userAgent});return iye(xn.id),{id:xn.id}}});ce(Q)},onDisable:async()=>{Le&&(await dye({pushDeviceId:Le,sendToServer:async Q=>{await n.socket.command({type:"push.unsubscribe",pushDeviceId:Q})}}),sye(),ce(null))},onTest:async()=>{await n.socket.command({type:"push.test"})},onMuteToggle:async(Q,Oe)=>{await n.socket.command({type:"push.setProjectMute",localPath:Q,muted:Oe})},onRemoveDevice:async Q=>{await n.socket.command({type:"push.unsubscribe",pushDeviceId:Q})}})}):null,f.jsx(Gn,{title:"Anonymous Analytics",description:f.jsxs(f.Fragment,{children:[f.jsx("span",{children:"Help improve Kanna with anonymous product analytics. Kanna sends tracked event names plus a small set of event properties like current version, environment, update version info, and launch flags. No message content, prompts, file paths, or provider credentials are sent."}),f.jsxs("span",{className:"mt-1 block",children:["Stored in ",(F==null?void 0:F.filePathDisplay)??"~/.kanna/data/settings.json","."," ",f.jsx("button",{type:"button",onClick:()=>ot(!0),className:"underline underline-offset-2 text-foreground hover:text-foreground/80",children:"View tracked events"})]}),F!=null&&F.warning?f.jsx("span",{className:"mt-1 block",children:F.warning}):null]}),children:f.jsx(da,{value:Da,onValueChange:Q=>{Si(Q)},options:w2e,size:"sm"})})]}),f.jsxs("div",{className:"border-b border-border",children:[Bt?f.jsx("div",{className:"mb-4 rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-sm text-destructive",children:Bt}):null,f.jsx(Gn,{title:"Cloudflare Tunnel",description:f.jsxs(f.Fragment,{children:[f.jsxs("span",{children:["When enabled, Claude can call the ",f.jsx("code",{className:"rounded bg-muted px-1 py-0.5 font-mono text-xs",children:"expose_port"})," tool to expose a local port via Cloudflare Tunnel. The mode below controls whether each call requires your approval or is exposed automatically. Requires"," ",f.jsx("code",{className:"rounded bg-muted px-1 py-0.5 font-mono text-xs",children:"cloudflared"})," ","to be installed."]}),f.jsxs("span",{className:"mt-1 block",children:["Stored in ",(F==null?void 0:F.filePathDisplay)??"~/.kanna/data/settings.json","."]})]}),bordered:!1,children:f.jsx(da,{value:Fo,onValueChange:Q=>{Vn({enabled:Q==="enabled"})},options:S2e,size:"sm"})}),ns.enabled&&f.jsxs(f.Fragment,{children:[f.jsx(Gn,{title:"Tool mode",description:"Always ask: each expose_port call shows an accept card. Auto-expose: expose_port calls spawn cloudflared immediately without prompting.",children:f.jsx(da,{value:ns.mode,onValueChange:Q=>{Vn({mode:Q})},options:C2e,size:"sm"})}),f.jsx(Gn,{title:"cloudflared path",description:"Path to the cloudflared binary. Defaults to the one found on $PATH.",children:f.jsx(Kn,{value:on,onChange:Q=>cn(Q.target.value),onBlur:()=>{Vn({cloudflaredPath:on})},placeholder:"cloudflared",className:"w-full font-mono md:w-64"})})]})]})]}):_==="providers"?f.jsxs("div",{className:"border-b border-border",children:[f.jsx(Gn,{title:"Claude OAuth tokens",description:"Manage multiple Claude OAuth tokens. Kanna switches automatically when one hits its rate limit.",bordered:!1,alignStart:!0,children:f.jsx("div",{className:"w-full md:w-[420px]",children:f.jsx(v2e,{tokens:(F==null?void 0:F.claudeAuth.tokens)??[],onWrite:Je,onTest:et})})}),f.jsx(Gn,{title:"Claude driver",description:"SDK uses the @anthropic-ai/claude-agent-sdk programmatic API (billed at API rates). PTY launches the `claude` CLI under a pseudo-terminal — preserves Pro/Max subscription billing. Requires `claude /login` to have been run once and ANTHROPIC_API_KEY to be unset. macOS/Linux only.",children:f.jsx(da,{value:Tt,onValueChange:Q=>se(Q),options:[{value:"sdk",label:"SDK (API)"},{value:"pty",label:"PTY (subscription)"}]})}),f.jsx(Gn,{title:"PTY idle timeout",description:"Stop a Claude PTY session after this many minutes without user activity. Lower values free subscription quota faster; higher values keep cold-start latency low.",children:f.jsxs("div",{className:"flex w-full min-w-0 flex-col items-stretch gap-2 md:w-auto md:items-end",children:[f.jsx(Kn,{type:"number",min:Math.round(Y_/6e4),max:Math.round(X_/6e4),step:1,value:It,onChange:Q=>ht(Q.target.value),onBlur:le,onKeyDown:Q=>Ee(Q,le),className:"hide-number-steppers w-full text-left font-mono md:w-28 md:text-right"}),f.jsxs("div",{className:"text-left text-xs text-muted-foreground md:text-right",children:[Math.round(Y_/6e4),"–",Math.round(X_/6e4)," min · default ",Math.round(Hv.idleTimeoutMs/6e4)]})]})}),f.jsx(Gn,{title:"PTY max concurrent sessions",description:"Hard cap on resident Claude PTY processes. Excess sessions are evicted LRU; their next activation cold-starts.",children:f.jsxs("div",{className:"flex w-full min-w-0 flex-col items-stretch gap-2 md:w-auto md:items-end",children:[f.jsx(Kn,{type:"number",min:Hg,max:Ug,step:1,value:Ht,onChange:Q=>ge(Q.target.value),onBlur:Ce,onKeyDown:Q=>Ee(Q,Ce),className:"hide-number-steppers w-full text-left font-mono md:w-28 md:text-right"}),f.jsxs("div",{className:"text-left text-xs text-muted-foreground md:text-right",children:[Hg,"–",Ug," · default ",YM.lifecycle.maxConcurrent]})]})}),f.jsx(Gn,{title:"Default Provider",description:"The default harness used for new chats before a provider is locked by an existing session.",children:f.jsxs(Sl,{value:G,onValueChange:Q=>Tr(Q),children:[f.jsx(fa,{className:"min-w-[180px]",children:f.jsx(Sc,{})}),f.jsx(ha,{children:f.jsxs(id,{children:[f.jsx(Ws,{value:"last_used",children:"Last Used"}),Uh.map(Q=>f.jsx(Ws,{value:Q.id,children:Q.label},Q.id))]})})]})}),f.jsx(Gn,{title:"Claude Code Defaults",description:"Saved defaults when using Claude Code.",alignStart:!0,children:f.jsx("div",{className:"max-w-[420px]",children:f.jsx(K1,{availableProviders:Uh,selectedProvider:"claude",showProviderPicker:!1,model:ee.claude.model,modelOptions:ee.claude.modelOptions,onModelChange:(Q,Oe)=>{Qr("claude",Oe)},onModelOptionChange:Q=>{Q.type==="claudeReasoningEffort"?Oi("claude",{reasoningEffort:Q.effort}):Q.type==="contextWindow"&&Oi("claude",{contextWindow:Q.contextWindow})},planMode:ee.claude.planMode,onPlanModeChange:Q=>ai("claude",Q),includePlanMode:!0,className:"justify-start flex-wrap"})})}),f.jsx(Gn,{title:"Codex Defaults",description:"Saved defaults when using Codex.",alignStart:!0,children:f.jsx("div",{className:"max-w-[420px]",children:f.jsx(K1,{availableProviders:Uh,selectedProvider:"codex",showProviderPicker:!1,model:ee.codex.model,modelOptions:ee.codex.modelOptions,onModelChange:(Q,Oe)=>{Qr("codex",Oe)},onModelOptionChange:Q=>{Q.type==="codexReasoningEffort"?Oi("codex",{reasoningEffort:Q.effort}):Q.type==="fastMode"&&Oi("codex",{fastMode:Q.fastMode})},planMode:ee.codex.planMode,onPlanModeChange:Q=>ai("codex",Q),includePlanMode:!0,className:"justify-start flex-wrap"})})}),f.jsx(Gn,{title:"Quick Response SDK",description:Ke,alignStart:!0,children:f.jsxs("div",{className:"flex w-full max-w-[420px] flex-col gap-3",children:[St?f.jsx("div",{className:"rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-sm text-destructive",children:St}):null,W!=null&&W.warning?f.jsx("div",{className:"rounded-lg border border-border bg-card/30 px-4 py-3 text-sm text-muted-foreground",children:W.warning}):null,f.jsxs(Sl,{value:vt.provider,onValueChange:Q=>an(Q),children:[f.jsx(fa,{className:"w-full",children:f.jsx(Sc,{})}),f.jsx(ha,{children:f.jsx(id,{children:k2e.map(Q=>f.jsx(Ws,{value:Q.value,children:Q.label},Q.value))})})]}),vt.provider==="custom"?f.jsx(Kn,{value:vt.baseUrl,onChange:Q=>Rt(Oe=>({...Oe,baseUrl:Q.target.value})),onBlur:()=>void _t(),onKeyDown:Q=>Qe(Q,()=>void _t()),placeholder:"https://your-provider.example/v1"}):null,f.jsx(Kn,{type:"password",value:vt.apiKey,onChange:Q=>Rt(Oe=>({...Oe,apiKey:Q.target.value})),onBlur:()=>void _t(),onKeyDown:Q=>Qe(Q,()=>void _t()),placeholder:"API key"}),f.jsx(Kn,{value:vt.model,onChange:Q=>Rt(Oe=>({...Oe,model:Q.target.value})),onBlur:()=>void _t(),onKeyDown:Q=>Qe(Q,()=>void _t()),placeholder:"Model id"})]})})]}):_==="keybindings"?f.jsxs("div",{className:"border-b border-border",children:[Ve?f.jsx("div",{className:"mb-4 rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-sm text-destructive",children:Ve}):null,te.warning?f.jsx("div",{className:"mb-4 rounded-lg border border-border bg-card/30 px-4 py-3 text-sm text-muted-foreground",children:te.warning}):null,OP.map((Q,Oe)=>{const xn=Q_(mp[Q]),co=tt[Q]??"",Wl=co!==xn;return f.jsx(Gn,{title:O4[Q],description:f.jsxs(f.Fragment,{children:[f.jsx("span",{children:"Comma-separated shortcuts."}),Wl?f.jsxs(f.Fragment,{children:[f.jsx("span",{children:" "}),f.jsxs("button",{type:"button",onClick:()=>{zi(Q)},className:"inline rounded text-foreground hover:text-foreground/80",children:["Restore: ",xn]})]}):null]}),bordered:Oe!==0,children:f.jsx("div",{className:"flex min-w-0 max-w-[420px] flex-1 flex-col items-stretch gap-2",children:f.jsx(Kn,{type:"text",value:co,onChange:is=>{const bf=is.target.value;Pe(Pa=>({...Pa,[Q]:bf}))},onBlur:()=>{ts()},onKeyDown:is=>Qe(is,()=>{ts()}),className:"font-mono"})})},Q)})]}):_==="skills"?f.jsx(B2e,{state:n}):f.jsx(j2e,{status:s,releases:h,error:b,onRetry:kn,updateSnapshot:Te,currentVersion:k,onInstallUpdate:()=>{n.handleInstallUpdate()},onCheckForUpdates:()=>{n.handleCheckForUpdates({force:!0})},onForceReload:()=>{n.handleForceReload()}})]}),n.commandError?f.jsxs("div",{className:"mx-auto mt-4 flex max-w-4xl items-start gap-3 rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-sm text-destructive",children:[f.jsx(MW,{className:"mt-0.5 h-4 w-4 flex-shrink-0"}),f.jsx("span",{children:n.commandError})]}):null]})]})]}),cr?f.jsx("div",{className:"absolute bottom-0 left-0 right-0 border-t border-border bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80",children:f.jsx("div",{className:"px-6 py-[14.25px]",children:f.jsxs("div",{className:"grid gap-3 text-xs text-muted-foreground grid-cols-2 lg:grid-cols-4",children:[f.jsxs("div",{children:[f.jsx("div",{className:"mb-1 uppercase tracking-wide text-[11px] text-muted-foreground/80",children:"Machine"}),f.jsx("div",{className:"text-foreground/80",children:C})]}),f.jsxs("div",{className:"hidden md:block",children:[f.jsx("div",{className:"mb-1 uppercase tracking-wide text-[11px] text-muted-foreground/80",children:"Connection"}),f.jsx("div",{className:"text-foreground/80",children:n.connectionStatus})]}),f.jsxs("div",{className:"hidden md:block",children:[f.jsx("div",{className:"mb-1 uppercase tracking-wide text-[11px] text-muted-foreground/80",children:"Projects Indexed"}),f.jsx("div",{className:"text-foreground/80",children:E})]}),f.jsxs("div",{children:[f.jsx("div",{className:"mb-1 uppercase tracking-wide text-[11px] text-muted-foreground/80",children:"App Version"}),f.jsx("div",{className:"text-foreground/80",children:k})]})]})})}):null,f.jsx(Rs,{open:gt,onOpenChange:ot,children:f.jsxs(Zi,{size:"lg",children:[f.jsxs(Io,{className:"space-y-4",children:[f.jsx(Ns,{children:"Tracked Events"}),f.jsx("div",{className:"text-sm text-muted-foreground",children:"Kanna sends these event names plus the limited property keys below, depending on the event type."}),f.jsxs("div",{className:"max-h-[60vh] overflow-auto rounded-lg border border-border bg-muted/40 p-3",children:[f.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Event Names"}),f.jsx("ul",{className:"mt-3 space-y-2 text-sm",children:ao.map(Q=>f.jsx("li",{className:"font-mono text-foreground",children:Q},Q))}),f.jsx("div",{className:"mt-6 text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Property Keys"}),f.jsx("ul",{className:"mt-3 space-y-2 text-sm",children:d2e.map(Q=>f.jsx("li",{className:"font-mono text-foreground",children:Q},Q))})]})]}),f.jsx(_a,{children:f.jsx(Ge,{variant:"secondary",size:"sm",onClick:()=>ot(!1),children:"Close"})})]})}),f.jsx(Rs,{open:Ie,onOpenChange:ze,children:f.jsxs(Zi,{size:"lg",children:[f.jsxs(Io,{className:"space-y-4",children:[f.jsx(Ns,{children:"Validation Error"}),f.jsx("pre",{className:"max-h-[60vh] overflow-auto rounded-lg border border-border bg-muted p-3 text-xs font-mono whitespace-pre-wrap break-words",children:je})]}),f.jsx(_a,{children:f.jsx(Ge,{variant:"secondary",size:"sm",onClick:()=>ze(!1),children:"Close"})})]})})]})}function FP(e){return{toggleEmbeddedTerminal:$s(e.toggleEmbeddedTerminal??""),toggleRightSidebar:$s(e.toggleRightSidebar??""),openInFinder:$s(e.openInFinder??""),openInEditor:$s(e.openInEditor??""),addSplitTerminal:$s(e.addSplitTerminal??""),jumpToSidebarChat:$s(e.jumpToSidebarChat??""),createChatInCurrentProject:$s(e.createChatInCurrentProject??""),openAddProject:$s(e.openAddProject??""),newStack:$s(e.newStack??""),newStackChat:$s(e.newStackChat??""),jumpToStacks:$s(e.jumpToStacks??"")}}const $P="kanna:last-seen-version",HP=500;function H2e(e){return!e.enabled||e.authenticated?{status:"ready"}:{status:"locked",error:null}}function U2e(e){return e!==!0}function V2e({error:e,onSubmit:t}){const[n,r]=v.useState(""),[i,s]=v.useState(!1);async function o(l){if(l.preventDefault(),!(!n||i)){s(!0);try{await t(n),r("")}finally{s(!1)}}}return f.jsx("div",{className:"flex min-h-[100dvh] items-center justify-center bg-background px-6 py-10",children:f.jsxs(wk,{className:"w-full max-w-md rounded-3xl border border-border bg-card shadow-sm",children:[f.jsxs(Sk,{className:"flex flex-col p-2 space-y-3 px-6 pt-6 pb-5 pl-[28px]",children:[f.jsxs("div",{className:"flex items-center gap-3",children:[f.jsx(hd,{className:"h-5 w-5 text-logo"}),f.jsx("div",{children:f.jsx(l3,{className:"font-logo text-xl uppercase text-foreground",children:or})})]}),f.jsx(c3,{className:"leading-6",children:"Enter your password to continue."})]}),f.jsx(Ck,{className:"px-6 pb-6",children:f.jsxs("form",{className:"space-y-4",onSubmit:l=>void o(l),children:[e?f.jsx("div",{className:"rounded-2xl border border-destructive/20 bg-destructive/10 px-4 py-3 text-sm text-foreground",children:e}):null,f.jsx(Kn,{id:"kanna-password",type:"password",autoComplete:"current-password",value:n,onChange:l=>r(l.target.value),placeholder:"Password",disabled:i,className:"h-11 rounded-2xl bg-background"}),f.jsx(Ge,{type:"submit",disabled:i||n.length===0,className:"h-11 w-full",children:i?"Unlocking...":"Unlock"})]})})]})})}function W2e(){const[e,t]=v.useState({status:"checking"}),n=v.useRef(null),r=v.useRef(async()=>{}),i=v.useCallback(async()=>{n.current!==null&&(window.clearTimeout(n.current),n.current=null),t(c=>c.status==="ready"?c:{status:"checking"});let o;try{o=await fetch("/auth/status",{method:"GET",cache:"no-store",headers:{Accept:"application/json"}})}catch{n.current=window.setTimeout(()=>{r.current()},HP);return}if(U2e(o.ok)){n.current=window.setTimeout(()=>{r.current()},HP);return}const l=await o.json();t(H2e(l))},[]);v.useLayoutEffect(()=>{r.current=i}),v.useEffect(()=>(i(),()=>{n.current!==null&&window.clearTimeout(n.current)}),[i]);const s=v.useCallback(async o=>{if(!(await fetch("/auth/login",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({password:o,next:window.location.pathname+window.location.search})})).ok){t({status:"locked",error:"Incorrect password. Try again."});return}await i()},[i]);return{state:e,submitPassword:s}}function G2e(e,t,n){return e==="/"&&!!t&&n!==t}function q2e(e,t,n=document){return!!e&&YQ(t,n)}function K2e(){var de,he,Le;const e=ro(),t=Wd(),n=o5(),r=r0e(n.chatId??null),i=Kp(),s=Ec(ce=>ce.chatSoundPreference),o=Ec(ce=>ce.chatSoundId),l=e.pathname==="/",c=kk.split("/")[1]??"unknown",u=v.useRef(null),{handleCreateChat:p,handleForkChat:h,handleRenameChat:g,handleShareChat:b,handleArchiveChat:x,handleOpenArchivedChat:_,openAddProjectModal:w,handleDeleteChat:C,handleCopyPath:E,handleOpenExternalPath:k,handleHideProject:R,handleToggleProjectStar:N,handleReorderProjectGroups:A,importClaudeSessions:M}=r,D=v.useCallback(ce=>{p(ce)},[p]),U=v.useCallback(ce=>{h(ce)},[h]),j=v.useCallback(ce=>{g(ce)},[g]),P=v.useCallback(ce=>{b(ce)},[b]),z=v.useCallback(ce=>{x(ce)},[x]),O=v.useCallback(ce=>{_(ce)},[_]),$=v.useCallback(()=>{w()},[w]),V=v.useCallback(ce=>{C(ce)},[C]),B=v.useCallback(ce=>{E(ce)},[E]),F=v.useCallback((ce,De)=>{k(ce,De)},[k]),W=v.useCallback(ce=>{R(ce)},[R]),X=v.useCallback((ce,De)=>{N(ce,De)},[N]),I=v.useCallback(ce=>{A(ce)},[A]),G=v.useCallback(async()=>{try{const ce=await M(),De=[`Imported ${ce.imported}`,`updated ${ce.updated}`,`skipped ${ce.skipped}`,`failed ${ce.failed}`],pe=ce.newProjects>0?` (${ce.newProjects} new projects)`:"";await i.alert({title:"Import complete",description:`${De.join(", ")}.${pe}`})}catch(ce){console.error("[kanna/import] failed",ce),await i.alert({title:"Import failed",description:"See console for details."})}},[i,M]),[ee,H]=v.useState(null),ue=v.useCallback(ce=>{H(ce),r.activeChatId!==ce&&t(`/chat/${ce}`)},[t,r.activeChatId]),ae=((de=r.chatSnapshot)==null?void 0:de.runtime.title)??"Chat",J=((he=r.chatSnapshot)==null?void 0:he.runtime.policyOverride)??null,te=v.useMemo(()=>f.jsx(pne,{data:r.sidebarData,activeChatId:r.activeChatId,connectionStatus:r.connectionStatus,ready:r.sidebarReady,open:r.sidebarOpen,collapsed:r.sidebarCollapsed,showMobileOpenButton:l,onOpen:r.openSidebar,onClose:r.closeSidebar,onCollapse:r.collapseSidebar,onExpand:r.expandSidebar,onCreateChat:D,onForkChat:U,currentProjectId:r.activeProjectId,keybindings:r.keybindings,onRenameChat:j,onShareChat:P,onArchiveChat:z,onOpenArchivedChat:O,onDeleteChat:V,onEditChatPermissions:ue,onOpenAddProjectModal:$,onImportClaudeSessions:G,onCopyPath:B,onOpenExternalPath:F,onHideProject:W,onToggleStar:X,onReorderProjectGroups:I,onCreateStack:r.handleCreateStack,onRenameStack:r.handleRenameStack,onRemoveStack:r.handleRemoveStack,onCreateStackChat:r.handleCreateStackChat,onListStackWorktrees:r.handleListStackWorktrees,editorLabel:r.editorLabel,updateSnapshot:r.updateSnapshot}),[$,G,B,D,z,V,O,U,F,j,P,ue,I,W,X,l,r.activeChatId,r.activeProjectId,r.keybindings,r.closeSidebar,r.collapseSidebar,r.connectionStatus,r.editorLabel,r.expandSidebar,r.openSidebar,r.sidebarCollapsed,r.sidebarData,r.sidebarOpen,r.sidebarReady,r.updateSnapshot,r.handleCreateStack,r.handleRenameStack,r.handleRemoveStack,r.handleCreateStackChat,r.handleListStackWorktrees]);v.useEffect(()=>{const ce=window.localStorage.getItem($P),De=G2e(e.pathname,c,ce);window.localStorage.setItem($P,c),De&&t("/settings/changelog",{replace:!0})},[c,e.pathname,t]),v.useLayoutEffect(()=>{document.title=or},[e.key]),v.useEffect(()=>{function ce(){document.title=or}function De(){document.title=or}return window.addEventListener("pageshow",ce),window.addEventListener("pagehide",De),()=>{window.removeEventListener("pageshow",ce),window.removeEventListener("pagehide",De)}},[]),v.useEffect(()=>{const ce=XQ(r.sidebarData);document.title=ce>0?`[${ce}] ${or}`:or},[r.sidebarData]),v.useEffect(()=>{const ce=QQ(u.current,r.sidebarData);u.current=r.sidebarData,!(ce<=0)&&q2e(r.appSettings,s)&&DS(o,ce).catch(()=>{})},[o,s,r.appSettings,r.sidebarData]);const ie=((Le=r.appSettings)==null?void 0:Le.claudeDriver.preference)==="pty";return f.jsxs("div",{className:"flex h-[100dvh] min-h-[100dvh] overflow-hidden",children:[te,f.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[ie?f.jsxs("div",{role:"status",className:"flex items-center justify-center gap-2 border-b border-warning/40 bg-warning/10 px-3 py-1.5 text-xs text-warning-foreground",children:[f.jsx("span",{className:"font-medium",children:"PTY driver active."}),f.jsx("span",{className:"text-warning-foreground/80",children:"Tools run under the `claude` CLI with subscription billing. Use a worktree for risky tasks."})]}):null,f.jsx(c9,{context:r})]}),f.jsx(xQ,{open:!!r.standaloneShareUrl,shareUrl:r.standaloneShareUrl??"",onOpenChange:ce=>{ce||r.handleCloseStandaloneShareDialog()},onOpenLink:r.handleOpenStandaloneShareLink,onCopyLink:r.handleCopyStandaloneShareLink}),f.jsx(bQ,{open:ee!=null&&ee===r.activeChatId,chatTitle:ae,baseline:_Q,current:J,onCancel:()=>H(null),onApply:ce=>{ee&&(r.handleSetChatPolicyOverride(ee,ce).catch(()=>{}),H(null))}})]})}function Y2e(){const e=W2e();return e.state.status==="checking"?f.jsx("div",{className:"flex min-h-[100dvh] items-center justify-center bg-background text-sm text-muted-foreground",children:"Checking session…"}):e.state.status==="locked"?f.jsx(V2e,{error:e.state.error,onSubmit:e.submitPassword}):f.jsx(My,{children:f.jsxs(wQ,{children:[f.jsx(d9,{children:f.jsxs(rd,{element:f.jsx(K2e,{}),children:[f.jsx(rd,{path:"/",element:f.jsx(c2e,{})}),f.jsx(rd,{path:"/settings",element:f.jsx(l9,{to:"/settings/general",replace:!0})}),f.jsx(rd,{path:"/settings/:sectionId",element:f.jsx($2e,{})}),f.jsx(rd,{path:"/chat/:chatId",element:f.jsx(r2e,{})})]})}),f.jsx(TQ,{})]})})}const i7=document.getElementById("root");if(!i7)throw new Error("Missing #root");dU.createRoot(i7).render(f.jsx(v.StrictMode,{children:f.jsx(I9,{children:f.jsx(Wbe,{children:f.jsx(Y2e,{})})})}));export{_n as R,W9 as a};
2716
+ ${ce.detail}`:""}`,closeLabel:"OK"})}catch(ce){await r.alert({title:"Create branch failed",description:ce instanceof Error?ce.message:String(ce),closeLabel:"OK"})}},[r,W,C,e.socket]);return v.useEffect(()=>{if(!t||!n)return;const J=window.setInterval(()=>{C()},s1e);return()=>window.clearInterval(J)},[t,C,n]),v.useEffect(()=>{!t||!n||C()},[t,C,n]),v.useEffect(()=>{!t||!e.activeChatId||p.current!==t&&(p.current=t,w())},[t,w,e.activeChatId]),v.useEffect(()=>{if(!t||!n)return;function J(){document.visibilityState==="visible"&&C()}return window.addEventListener("focus",J),document.addEventListener("visibilitychange",J),()=>{window.removeEventListener("focus",J),document.removeEventListener("visibilitychange",J)}},[t,C,n]),v.useEffect(()=>{n&&u.current&&!e.isProcessing&&C(),u.current=e.isProcessing},[C,n,e.isProcessing]),v.useEffect(()=>()=>{c.current!==null&&window.clearTimeout(c.current)},[]),v.useEffect(()=>{n||c.current!==null&&(window.clearTimeout(c.current),c.current=null)},[t,n]),{diffRenderMode:i,wrapDiffLines:o,setDiffRenderMode:s,setWrapDiffLines:l,scheduleTerminalDiffRefresh:E,handleOpenDiffFile:k,handleCopyDiffFilePath:R,handleCopyDiffRelativePath:N,handleLoadDiffPatch:A,handleDiscardDiffFile:M,handleIgnoreDiffFile:D,handleIgnoreDiffFolder:U,handleOpenDiffInFinder:j,handleCommitDiffs:P,handleSyncBranch:z,handleGenerateCommitMessage:O,handleInitializeGit:$,handleGetGitHubPublishInfo:V,handleCheckGitHubRepoAvailability:B,handleSetupGitHub:F,handleListBranches:W,handleCheckoutBranch:X,handlePreviewMergeBranch:I,handleMergeBranch:G,handleCreateBranch:ee}}const GEe="flex-1 flex flex-col min-h-0 min-w-0 relative",r7={"--terminal-toggle-duration":`${f0}ms`};function qEe(e,t){const[n,r]=v.useState(""),[i,s]=v.useState(!1);return v.useEffect(()=>{if(!e)return;r(""),s(!1);let o=0;const l=window.setInterval(()=>{o+=1,r(ny.slice(0,o)),o>=ny.length&&(window.clearInterval(l),s(!0))},r1e);return()=>window.clearInterval(l)},[e,t]),{typedEmptyStateText:n,isEmptyStateTypingComplete:i}}function KEe(e){const[t,n]=v.useState(!1),r=v.useRef(0),i=v.useCallback(u=>{var p;return a1e(((p=u.dataTransfer)==null?void 0:p.types)??[])},[]),s=v.useCallback(u=>{!i(u)||!e.hasSelectedProject||(u.preventDefault(),r.current+=1,n(!0))},[e.hasSelectedProject,i]),o=v.useCallback(u=>{!i(u)||!e.hasSelectedProject||(u.preventDefault(),u.dataTransfer.dropEffect="copy",t||n(!0))},[e.hasSelectedProject,i,t]),l=v.useCallback(u=>{!i(u)||!e.hasSelectedProject||(u.preventDefault(),r.current=Math.max(0,r.current-1),r.current===0&&n(!1))},[e.hasSelectedProject,i]),c=v.useCallback(u=>{!i(u)||!e.hasSelectedProject||(u.preventDefault(),r.current=0,n(!1),e.onFilesDropped([...u.dataTransfer.files]))},[e,i]);return{isPageFileDragActive:t,handleTranscriptDragEnter:s,handleTranscriptDragOver:o,handleTranscriptDragLeave:l,handleTranscriptDrop:c}}function YEe(e){const[t,n]=v.useState(0);return v.useLayoutEffect(()=>{const r=e.current;if(!r)return;const i=()=>{const o=r.clientWidth;n(l=>Math.abs(l-o)<1?l:o)},s=new ResizeObserver(i);return s.observe(r),i(),()=>s.disconnect()},[e]),t}function XEe(){const e=v.useRef(null),[t,n]=v.useState(148),r=v.useCallback(()=>{const i=e.current;if(!i)return;const s=i.getBoundingClientRect().height;n(o=>Kye(o,s))},[]);return v.useLayoutEffect(()=>{const i=e.current;if(!i)return;const s=new ResizeObserver(()=>{r()});return s.observe(i),r(),()=>s.disconnect()},[r]),{inputRef:e,syncInputHeight:r,transcriptPaddingBottom:qye(t)}}const QEe=768;function ZEe(e){return e>0&&e<QEe}function JEe(){const[e,t]=v.useState(()=>typeof window>"u"?0:window.innerWidth);return v.useEffect(()=>{if(typeof window>"u")return;const n=()=>t(window.innerWidth);return n(),window.addEventListener("resize",n),()=>window.removeEventListener("resize",n)},[]),ZEe(e)}function e2e(e){const[t,n]=v.useState(0);return v.useEffect(()=>{const r=e.layoutRootRef.current;if(!r)return;const i=()=>{const o=r.getBoundingClientRect().height;if(!e.shouldRenderTerminalLayout||o<=0)return;const l=o*(e.terminalMainSizes[1]/100);l<=0||n(c=>Math.abs(c-l)<1?c:l)},s=new ResizeObserver(i);return s.observe(r),i(),()=>s.disconnect()},[e.layoutRootRef,e.shouldRenderTerminalLayout,e.terminalMainSizes]),t}const RP=v.memo(function(t){return f.jsx(Rve,{...t,diffs:t.diffs??s$})}),t2e=v.memo(function({showRightSidebar:t,sizePercent:n,sidebarPanelRef:r,sidebarVisualRef:i,content:s}){return f.jsx(Ap,{id:"rightSidebar",defaultSize:`${n}%`,className:"min-h-0 min-w-0",elementRef:r,children:f.jsx("div",{ref:i,className:"h-full min-h-0 overflow-hidden","data-right-sidebar-open":t?"true":"false","data-right-sidebar-animated":"false","data-right-sidebar-visual":!0,style:r7,children:s})})}),n2e=v.memo(function({projectId:t,showRightSidebar:n,sidebarVisualRef:r,onClose:i,content:s}){return t?f.jsxs("div",{className:me("absolute inset-0 z-40 transition-opacity duration-300 ease-out",n?"pointer-events-auto opacity-100":"pointer-events-none opacity-0"),"aria-hidden":n?void 0:!0,"data-mobile-right-sidebar-overlay":!0,children:[f.jsx("button",{type:"button",className:"absolute inset-0 bg-black/45 backdrop-blur-[1px]","aria-label":"Close changes sidebar",onClick:i}),f.jsx("div",{ref:r,className:me("absolute inset-y-0 right-0 flex w-[min(92vw,30rem)] max-w-full min-h-0 flex-col overflow-hidden border-l border-border bg-background shadow-2xl transition-transform duration-300 ease-out","pt-[max(env(safe-area-inset-top),0px)] pb-[max(env(safe-area-inset-bottom),0px)]",n?"translate-x-0":"translate-x-full"),"data-right-sidebar-open":n?"true":"false","data-right-sidebar-animated":"false","data-right-sidebar-visual":!0,children:s})]}):null});function r2e({chatCard:e,projectId:t,shouldRenderTerminalLayout:n,showTerminalPane:r,terminalLayout:i,mainPanelGroupRef:s,terminalPanelRef:o,terminalVisualRef:l,fixedTerminalHeight:c,terminalFocusRequestVersion:u,addTerminal:p,socket:h,connectionStatus:g,scrollback:b,minColumnWidth:x,splitTerminalShortcut:_,onTerminalCommandSent:w,onRemoveTerminal:C,onTerminalLayout:E,onLayoutChanged:k}){return n?f.jsxs(o2,{groupRef:s,orientation:"vertical",className:"flex-1 min-h-0",onLayoutChanged:k,children:[f.jsx(Ap,{id:"chat",defaultSize:`${i.mainSizes[0]}%`,minSize:"25%",className:"min-h-0",children:e}),f.jsx(a2,{withHandle:!0,orientation:"vertical",disabled:!r,className:me(!r&&"pointer-events-none opacity-0")}),f.jsx(Ap,{id:"terminal",defaultSize:`${i.mainSizes[1]}%`,minSize:"0%",className:"min-h-0",elementRef:o,children:f.jsx("div",{ref:l,className:"h-full min-h-0 overflow-hidden relative","data-terminal-open":r?"true":"false","data-terminal-animated":"false","data-terminal-visual":!0,style:r7,children:f.jsx(VEe,{projectId:t,fixedTerminalHeight:c,terminalLayout:i,addTerminal:p,socket:h,connectionStatus:g,scrollback:b,minColumnWidth:x,splitTerminalShortcut:_,focusRequestVersion:u,onTerminalCommandSent:w,onRemoveTerminal:C,onTerminalLayout:E})})})]},t):f.jsx(f.Fragment,{children:e})}function i2e(){var Qr,Oi,ai,ts,zi,_t,an,kn,gn,ao,Da,ns,Fo,rs,Ia,cr;const e=$C(),{handleCancel:t,handleOpenExternal:n}=e,r=Kp(),i=v.useRef(null),s=v.useRef(null),o=v.useRef(!0),l=v.useRef(null),c=v.useRef(null),u=v.useRef(null),p=v.useRef(null),{inputRef:h,syncInputHeight:g,transcriptPaddingBottom:b}=XEe(),[x,_]=v.useState(!1),w=Ys(je=>je.dialogOpen),C=v.useCallback(()=>{Ys.getState().toggleDialog()},[]),E=e.messages.length===0&&((Qr=e.runtime)==null?void 0:Qr.title)==="New Chat",k=e.activeProjectId,N=yl(je=>k?je.projects[k]:void 0)??pbe,M=Li(je=>k?je.projects[k]:void 0)??vue,D=Li(je=>je.size),U=yl(je=>je.addTerminal),j=yl(je=>je.removeTerminal),P=yl(je=>je.toggleVisibility),z=yl(je=>je.resetMainSizes),O=yl(je=>je.setMainSizes),$=yl(je=>je.setTerminalSizes),V=Li(je=>je.toggleVisibility),B=Li(je=>je.setSize),F=hi(je=>je.scrollbackLines),W=hi(je=>je.minColumnWidth),X=hi(je=>je.editorPreset),I=hi(je=>je.editorCommandTemplate),G=v.useMemo(()=>Jk(e.keybindings),[e.keybindings]),ee=v.useMemo(()=>{var je;return lbe(((je=e.chatSnapshot)==null?void 0:je.messages)??[])},[(Oi=e.chatSnapshot)==null?void 0:Oi.messages]),H=N.terminals.length>0,ue=!!(k&&N.isVisible&&H),ae=!!(k&&H),J=!!(k&&M.isVisible),te=!!k,ie=JEe(),de=te&&!ie,he=YEe(i),Le=v.useCallback((je,Ke)=>{if(!Number.isFinite(je))return D;const Ft=Ke??he,tr=Ft>0?pue/Ft*100:R1;return Math.max(R1,tr,je)},[D,he]),ce=Le(D??wd),De=e2e({layoutRootRef:i,shouldRenderTerminalLayout:ae,terminalMainSizes:N.mainSizes}),{isAnimating:pe,mainPanelGroupRef:st,terminalFocusRequestVersion:zt,terminalPanelRef:Et,terminalVisualRef:Qt}=Lbe({showTerminalPane:ue,shouldRenderTerminalLayout:ae,projectId:k,terminalLayout:N,chatInputRef:u}),{isAnimating:Dt,panelGroupRef:Tt,sidebarPanelRef:mt,sidebarVisualRef:At}=kbe({projectId:k,shouldRenderRightSidebarLayout:de,showRightSidebar:J,rightSidebarSize:ce}),{diffRenderMode:It,wrapDiffLines:ht,setDiffRenderMode:Ht,setWrapDiffLines:ge,scheduleTerminalDiffRefresh:we,handleOpenDiffFile:Be,handleCopyDiffFilePath:tt,handleCopyDiffRelativePath:Pe,handleLoadDiffPatch:Ve,handleDiscardDiffFile:qe,handleIgnoreDiffFile:Xe,handleIgnoreDiffFolder:We,handleOpenDiffInFinder:gt,handleCommitDiffs:ot,handleSyncBranch:Bt,handleGenerateCommitMessage:ut,handleInitializeGit:on,handleGetGitHubPublishInfo:cn,handleCheckGitHubRepoAvailability:vt,handleSetupGitHub:Rt,handleListBranches:St,handleCheckoutBranch:Ut,handlePreviewMergeBranch:xt,handleMergeBranch:ft,handleCreateBranch:Lt}=WEe({state:e,projectId:k,showRightSidebar:J}),{typedEmptyStateText:Pt,isEmptyStateTypingComplete:Ie}=qEe(E,e.activeChatId);Nbe({rootRef:c,fallbackRef:u,enabled:e.hasSelectedProject,canCancel:e.canCancel}),Rbe({socket:e.socket,activeChatId:e.activeChatId});const ze=v.useCallback(je=>{var Ke;!e.hasSelectedProject||je.length===0||(Ke=p.current)==null||Ke.enqueueFiles(je)},[e.hasSelectedProject]),{isPageFileDragActive:Te,handleTranscriptDragEnter:Ye,handleTranscriptDragOver:_e,handleTranscriptDragLeave:Je,handleTranscriptDrop:et}=KEe({hasSelectedProject:e.hasSelectedProject,onFilesDropped:ze}),$e=v.useCallback(()=>{if(k){if(H){P(k);return}U(k)}},[U,H,k,P]),Mt=v.useCallback(je=>{var li;if(!k||!ue||pe.current)return;const Ke=je.chat,Ft=je.terminal;if(!Number.isFinite(Ke)||!Number.isFinite(Ft))return;const tr=((li=i.current)==null?void 0:li.getBoundingClientRect().height)??0;if(vbe(tr,Ft)){z(k),P(k);return}O(k,[Ke,Ft])},[pe,k,z,O,ue,P]),un=v.useCallback(()=>{k&&V(k)},[k,V]),Zt=v.useCallback(()=>{var je;if(k){if(J){V(k);return}if(((je=e.chatDiffSnapshot)==null?void 0:je.status)==="no_repo"){(async()=>{if(!await r.confirm({title:"Initialize Git?",description:"Initialize a local git repository in this project?",confirmLabel:"Init Git",cancelLabel:"Cancel"}))return;const Ft=await on();Ft!=null&&Ft.ok&&!J&&V(k)})();return}V(k)}},[r,on,k,J,(ai=e.chatDiffSnapshot)==null?void 0:ai.status,V]),Fe=v.useCallback((je,Ke)=>{e.socket.command({type:"terminal.close",terminalId:Ke}).catch(()=>{}),j(je,Ke)},[j,e.socket]),hn=v.useCallback(()=>{l.current!==null&&(window.clearTimeout(l.current),l.current=null)},[]),lr=v.useCallback(je=>{if(o.current!==je){if(o.current=je,je){hn(),_(!1);return}hn(),l.current=window.setTimeout(()=>{_(!0),l.current=null},150)}},[hn]),se=v.useCallback(()=>{var Ke,Ft;const je=(Ft=(Ke=s.current)==null?void 0:Ke.getState)==null?void 0:Ft.call(Ke);je&&lr(je.isAtEnd)},[lr]),le=v.useCallback(async(je=!0)=>{var Ke,Ft;o.current=!0,hn(),_(!1),await((Ft=(Ke=s.current)==null?void 0:Ke.scrollToEnd)==null?void 0:Ft.call(Ke,{animated:je}))},[hn]),Ce=v.useCallback(async(je,Ke)=>{await le(!1),await e.handleSend(je,Ke)},[le,e]),Ee=v.useCallback((je,Ke)=>{const Ft=e.activeChatId;Ft&&e.socket.command({type:"autoContinue.accept",chatId:Ft,scheduleId:je,scheduledAt:Ke}).catch(()=>{})},[e.activeChatId,e.socket]),Qe=v.useCallback((je,Ke)=>{const Ft=e.activeChatId;Ft&&e.socket.command({type:"autoContinue.reschedule",chatId:Ft,scheduleId:je,scheduledAt:Ke}).catch(()=>{})},[e.activeChatId,e.socket]),ct=v.useCallback(je=>{const Ke=e.activeChatId;Ke&&e.socket.command({type:"autoContinue.cancel",chatId:Ke,scheduleId:je}).catch(()=>{})},[e.activeChatId,e.socket]),Ze=v.useCallback(async je=>{const Ke=e.activeChatId;Ke&&await e.socket.command({type:"tunnel.accept",chatId:Ke,tunnelId:je})},[e.activeChatId,e.socket]),Vt=v.useCallback(async je=>{const Ke=e.activeChatId;Ke&&await e.socket.command({type:"tunnel.stop",chatId:Ke,tunnelId:je})},[e.activeChatId,e.socket]),Dn=v.useCallback(async je=>{const Ke=e.activeChatId;Ke&&await e.socket.command({type:"tunnel.retry",chatId:Ke,tunnelId:je})},[e.activeChatId,e.socket]),fn=v.useCallback((je,Ke)=>{e.socket.command({type:"chat.cancelSubagentRun",chatId:je,runId:Ke}).catch(()=>{})},[e.socket]);v.useEffect(()=>()=>hn(),[hn]),v.useEffect(()=>{o.current=!0,hn(),_(!1)},[hn,e.activeChatId]),v.useEffect(()=>{function je(Ke){if(k){if(fh(G,"toggleEmbeddedTerminal",Ke)){Ke.preventDefault(),$e();return}if(fh(G,"toggleRightSidebar",Ke)){Ke.preventDefault(),Zt();return}if(fh(G,"openInFinder",Ke)){Ke.preventDefault(),n("open_finder");return}if(fh(G,"openInEditor",Ke)){Ke.preventDefault(),n("open_editor");return}fh(G,"addSplitTerminal",Ke)&&(Ke.preventDefault(),U(k))}}return window.addEventListener("keydown",je),()=>window.removeEventListener("keydown",je)},[U,n,$e,Zt,k,G]),v.useEffect(()=>{function je(Ke){(Ke.metaKey||Ke.ctrlKey)&&Ke.shiftKey&&Ke.key.toLowerCase()==="b"&&(Ke.preventDefault(),C())}return window.addEventListener("keydown",je),()=>window.removeEventListener("keydown",je)},[C]),v.useEffect(()=>{const je=window.requestAnimationFrame(()=>{se()}),Ke=window.setTimeout(()=>{se()},f0);return()=>{window.cancelAnimationFrame(je),window.clearTimeout(Ke)}},[ae,ue,se]),v.useEffect(()=>{function je(){se()}return window.addEventListener("resize",je),()=>window.removeEventListener("resize",je)},[se]),v.useEffect(()=>{if(!J||!ie)return;const je=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=je}},[ie,J]),v.useEffect(()=>{if(!J||!ie)return;function je(Ke){Ke.key==="Escape"&&(Ke.preventDefault(),un())}return window.addEventListener("keydown",je),()=>window.removeEventListener("keydown",je)},[un,ie,J]),v.useEffect(()=>{if(!o.current)return;let je=null;const Ke=window.requestAnimationFrame(()=>{var Ft,tr;(tr=(Ft=s.current)==null?void 0:Ft.scrollToEnd)==null||tr.call(Ft,{animated:!1}),je=window.requestAnimationFrame(()=>{var li,lo;(lo=(li=s.current)==null?void 0:li.scrollToEnd)==null||lo.call(li,{animated:!1})})});return()=>{window.cancelAnimationFrame(Ke),je!==null&&window.cancelAnimationFrame(je)}},[e.commandError,e.isDraining,e.isProcessing,e.messages.length,e.queuedMessages.length,e.runtimeStatus]),v.useLayoutEffect(()=>{var Ft,tr;if(!J||ie||he<=0||Dt.current)return;const je=Le(D,he),Ke=(Ft=Tt.current)==null?void 0:Ft.getLayout();Ke&&(Math.abs((Ke.rightSidebar??0)-je)<.1||(tr=Tt.current)==null||tr.setLayout({workspace:100-je,rightSidebar:je}))},[Le,D,Dt,he,Tt,J,ie]);const Si=f.jsxs(wk,{ref:c,className:"bg-background h-full flex flex-col overflow-hidden border-0 rounded-none relative",onDragEnter:Ye,onDragOver:_e,onDragLeave:Je,onDrop:et,children:[f.jsxs(Ck,{className:"flex flex-1 min-h-0 flex-col overflow-hidden p-0 relative",children:[f.jsx(xre,{sidebarCollapsed:e.sidebarCollapsed,onOpenSidebar:e.openSidebar,onExpandSidebar:e.expandSidebar,onNewChat:e.handleCompose,localPath:e.navbarLocalPath,embeddedTerminalVisible:ue,onToggleEmbeddedTerminal:k?$e:void 0,rightSidebarVisible:J,onToggleRightSidebar:k?Zt:void 0,onOpenExternal:n,onExportTranscript:e.activeChatId?()=>void e.handleShareChat(e.activeChatId):void 0,canExportTranscript:!!e.activeChatId&&!e.isExportingStandalone,isExportingTranscript:e.isExportingStandalone,exportTranscriptComplete:e.standaloneShareComplete,editorPreset:X,editorCommandTemplate:I,platform:(ts=e.localProjects)==null?void 0:ts.machine.platform,finderShortcut:G.bindings.openInFinder,editorShortcut:G.bindings.openInEditor,terminalShortcut:G.bindings.toggleEmbeddedTerminal,rightSidebarShortcut:G.bindings.toggleRightSidebar,branchName:(zi=e.chatDiffSnapshot)==null?void 0:zi.branchName,hasGitRepo:((_t=e.chatDiffSnapshot)==null?void 0:_t.status)!=="no_repo",gitStatus:(an=e.chatDiffSnapshot)==null?void 0:an.status,timings:(kn=e.runtime)==null?void 0:kn.timings,status:(gn=e.runtime)==null?void 0:gn.status,onOpenBgTasks:C}),f.jsx(u1e,{activeChatId:e.activeChatId,listRef:s,messages:e.messages,queuedMessages:e.queuedMessages,transcriptPaddingBottom:b,localPath:(ao=e.runtime)==null?void 0:ao.localPath,latestToolIds:e.latestToolIds,isHistoryLoading:e.isHistoryLoading,hasOlderHistory:e.hasOlderHistory,isProcessing:e.isProcessing,runtimeStatus:e.runtimeStatus,isDraining:e.isDraining,commandError:e.commandError,loadOlderHistory:e.loadOlderHistory,onStopDraining:e.handleStopDraining,onSteerQueuedMessage:e.handleSteerQueuedMessage,onRemoveQueuedMessage:e.handleRemoveQueuedMessage,onOpenLocalLink:e.handleOpenLocalLink,editorPreset:X,editorCommandTemplate:I,platform:(Da=e.localProjects)==null?void 0:Da.machine.platform,onAskUserQuestionSubmit:e.handleAskUserQuestion,onExitPlanModeConfirm:e.handleExitPlanMode,onToolRequestAnswer:e.handleToolRequestAnswer,onSubagentAskUserQuestionSubmit:e.handleSubagentAskUserQuestion,onSubagentExitPlanModeSubmit:e.handleSubagentExitPlanMode,schedules:((ns=e.chatSnapshot)==null?void 0:ns.schedules)??RF,onAutoContinueAccept:Ee,onAutoContinueReschedule:Qe,onAutoContinueCancel:ct,tunnels:(Fo=e.chatSnapshot)==null?void 0:Fo.tunnels,liveTunnelId:(rs=e.chatSnapshot)==null?void 0:rs.liveTunnelId,onTunnelAccept:Ze,onTunnelStop:Vt,onTunnelRetry:Dn,subagentRuns:(Ia=e.chatSnapshot)==null?void 0:Ia.subagentRuns,onCancelSubagentRun:fn,showScrollButton:x&&e.messages.length>0,onIsAtEndChange:lr,scrollToBottom:()=>le(!0),typedEmptyStateText:Pt,isEmptyStateTypingComplete:Ie,isPageFileDragActive:Te,showEmptyState:E})]}),f.jsx(__e,{inputRef:h,onLayoutChange:g,chatInputRef:p,chatInputElementRef:u,activeChatId:e.activeChatId,previousPrompt:e.previousPrompt,hasSelectedProject:e.hasSelectedProject,canCancel:e.canCancel,projectId:k,activeProvider:((cr=e.runtime)==null?void 0:cr.provider)??null,availableProviders:e.availableProviders,contextWindowSnapshot:ee,onSubmit:Ce,onCancel:t})]}),Vn=k?f.jsx(r2e,{chatCard:Si,projectId:k,shouldRenderTerminalLayout:ae,showTerminalPane:ue,terminalLayout:N,mainPanelGroupRef:st,terminalPanelRef:Et,terminalVisualRef:Qt,fixedTerminalHeight:De,terminalFocusRequestVersion:zt,addTerminal:U,socket:e.socket,connectionStatus:e.connectionStatus,scrollback:F,minColumnWidth:W,splitTerminalShortcut:G.bindings.addSplitTerminal,onTerminalCommandSent:we,onRemoveTerminal:Fe,onTerminalLayout:$,onLayoutChanged:Mt}):Si,Tr=v.useMemo(()=>k?{projectId:k,diffs:e.chatDiffSnapshot??s$,editorLabel:e.editorLabel,diffRenderMode:It,wrapLines:ht,onOpenFile:Be,onOpenInFinder:gt,onDiscardFile:qe,onIgnoreFile:Xe,onIgnoreFolder:We,onCopyFilePath:tt,onCopyRelativePath:Pe,onLoadPatch:Ve,onListBranches:St,onPreviewMergeBranch:xt,onMergeBranch:ft,onCheckoutBranch:Ut,onCreateBranch:Lt,onGenerateCommitMessage:ut,onInitializeGit:on,onGetGitHubPublishInfo:cn,onCheckGitHubRepoAvailability:vt,onSetupGitHub:Rt,onCommit:ot,onSyncWithRemote:Bt,onDiffRenderModeChange:Ht,onWrapLinesChange:ge,onClose:un}:null,[It,vt,Ut,un,ot,tt,Pe,Lt,qe,ut,cn,Xe,We,on,St,Ve,ft,Be,gt,xt,Rt,Bt,k,Ht,ge,e.chatDiffSnapshot,e.editorLabel,ht]);return f.jsxs("div",{ref:i,className:GEe,children:[f.jsx(Mxe,{open:w,onOpenChange:je=>{je?Ys.getState().openDialog():Ys.getState().closeDialog()},socket:e.socket}),de&&k?f.jsxs(o2,{groupRef:Tt,orientation:"horizontal",className:"flex-1 min-h-0",onLayoutChange:je=>{var Ft;if(!J||Dt.current)return;const Ke=Le(je.rightSidebar);Math.abs(Ke-je.rightSidebar)<.1||(Ft=Tt.current)==null||Ft.setLayout({workspace:100-Ke,rightSidebar:Ke})},onLayoutChanged:je=>{!J||Dt.current||B(Le(je.rightSidebar))},children:[f.jsx(Ap,{id:"workspace",defaultSize:`${100-ce}%`,minSize:"20%",className:"min-h-0 min-w-0",children:Vn}),f.jsx(a2,{withHandle:!1,orientation:"horizontal",disabled:!J,className:me(!J&&"pointer-events-none opacity-0")}),f.jsx(t2e,{showRightSidebar:J,sizePercent:ce,sidebarPanelRef:mt,sidebarVisualRef:At,content:Tr?f.jsx(RP,{...Tr}):null})]},`${k}-right-sidebar`):Vn,ie?f.jsx(n2e,{projectId:k,showRightSidebar:J,sidebarVisualRef:At,onClose:un,content:Tr?f.jsx(RP,{...Tr}):null}):null]})}function NP({narrow:e=!1,title:t,subtitle:n,icon:r=JC}){return f.jsxs("div",{className:me("w-full",e?"max-w-2xl px-6 pt-16 mx-auto":"px-6 pt-16 mb-10"),children:[f.jsxs("div",{className:me("flex items-center gap-1 mb-2",e&&"justify-center"),children:[f.jsx("div",{className:"p-2 pl-0 rounded-lg",children:f.jsx(r,{className:"h-6 w-6 text-muted-foreground"})}),f.jsx("h1",{className:"text-2xl font-semibold text-foreground",children:t})]}),n&&f.jsx("p",{className:me("text-muted-foreground",e&&"mb-10 text-center"),children:n})]})}function s2e(e){return e.toLowerCase().replace(/[\s_]+/g,"-").replace(/[^a-z0-9-]/g,"").replace(/-+/g,"-").replace(/^-|-$/g,"")}function o2e({open:e,onOpenChange:t,onConfirm:n}){const[r,i]=v.useState("new"),[s,o]=v.useState(""),[l,c]=v.useState(""),u=v.useRef(null),p=v.useRef(null);v.useEffect(()=>{e&&(i("new"),o(""),c(""),setTimeout(()=>{var w;return(w=u.current)==null?void 0:w.focus()},0))},[e]),v.useEffect(()=>{e&&setTimeout(()=>{var w,C;r==="new"?(w=u.current)==null||w.focus():(C=p.current)==null||C.focus()},0)},[r,e]);const h=s2e(s),g=h?`${DQ}/${h}`:"",b=l.trim(),x=r==="new"?!!h:!!b,_=()=>{if(x){if(r==="new")n({mode:"new",localPath:g,title:s.trim()});else{const w=b.split("/").pop()||b;n({mode:"existing",localPath:b,title:w})}t(!1)}};return f.jsx(Rs,{open:e,onOpenChange:t,children:f.jsxs(Zi,{size:"sm",children:[f.jsxs(Io,{className:"space-y-4",children:[f.jsx(Ns,{children:"Add Project"}),f.jsx(da,{value:r,onValueChange:i,options:[{value:"new",label:"New Folder"},{value:"existing",label:"Existing Path"}],className:"w-full mb-2",optionClassName:"flex-1 justify-center"}),r==="new"?f.jsxs("div",{className:"space-y-2",children:[f.jsx(Kn,{ref:u,type:"text",value:s,onChange:w=>o(w.target.value),onKeyDown:w=>{w.key==="Enter"&&_(),w.key==="Escape"&&t(!1)},placeholder:"Project name"}),g&&f.jsx("p",{className:"text-xs text-muted-foreground font-mono",children:g})]}):f.jsxs("div",{className:"space-y-2",children:[f.jsx(Kn,{ref:p,type:"text",value:l,onChange:w=>c(w.target.value),onKeyDown:w=>{w.key==="Enter"&&_(),w.key==="Escape"&&t(!1)},placeholder:"~/Projects/my-app"}),f.jsx("p",{className:"text-xs text-muted-foreground",children:"The folder will be created if it doesn't exist."})]})]}),f.jsxs(_a,{children:[f.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>t(!1),children:"Cancel"}),f.jsx(Ge,{variant:"secondary",size:"sm",onClick:_,disabled:!x,children:"Create"})]})]})})}function a2e({text:e}){const[t,n]=v.useState(!1);async function r(){await navigator.clipboard.writeText(e),n(!0),setTimeout(()=>n(!1),2e3)}return f.jsx(Ge,{variant:"ghost",size:"icon-mobile","aria-label":t?"Copied":"Copy to clipboard",className:"text-muted-foreground hover:text-foreground",onClick:()=>void r(),children:t?f.jsx(yi,{className:"h-4 w-4 text-success"}):f.jsx(jl,{className:"h-4 w-4"})})}function AP({children:e}){return f.jsxs("div",{className:"grid grid-cols-[1fr_auto] items-center group bg-background border border-border text-foreground rounded-xl p-1.5 pl-3 font-mono text-sm",children:[f.jsxs("pre",{className:"inline-flex items-center gap-2 overflow-x-auto",children:[f.jsx(Do,{className:"inline h-4 w-4 opacity-40"}),f.jsx("code",{children:e})]}),f.jsx(a2e,{text:e})]})}function jv({children:e}){return f.jsx("div",{className:"bg-card border border-border rounded-2xl p-4",children:e})}function xS({children:e}){return f.jsx("h2",{className:"text-[13px] font-medium text-muted-foreground uppercase tracking-wider mb-3",children:e})}function _S({icon:e,title:t,subtitle:n,iconClassName:r}){return f.jsxs("div",{className:"flex flex-col items-start gap-1.5 min-w-0",children:[f.jsx(e,{className:r||"h-5 w-5 text-muted-foreground"}),f.jsx("span",{className:"text-sm font-medium text-foreground",children:t}),f.jsx("span",{className:"text-xs text-muted-foreground leading-tight",children:n})]})}function MP(){return f.jsx("div",{"aria-hidden":!0,className:"mt-5 h-px w-6 shrink-0 bg-border"})}function LP({number:e,title:t,children:n}){return f.jsx("div",{className:"flex gap-4",children:f.jsxs("div",{className:"flex-1 min-w-0",children:[f.jsxs("div",{className:"grid grid-cols-[auto_1fr] items-baseline gap-3",children:[f.jsxs("div",{className:"flex-shrink-0 flex items-center justify-center font-medium text-logo",children:[e,"."]}),f.jsx("h3",{className:"font-medium text-foreground mb-2",children:t})]}),f.jsx("div",{className:"text-muted-foreground text-sm space-y-3",children:n})]})})}function l2e({localPath:e,loading:t,onClick:n}){return f.jsxs(Yr,{children:[f.jsx(Xr,{asChild:!0,children:f.jsxs("button",{className:me("border border-border hover:border-primary/30 group rounded-lg bg-card px-4 py-3 flex items-center gap-3 w-full text-left hover:bg-muted/50 transition-colors",t&&"opacity-50 cursor-not-allowed"),disabled:t,onClick:n,children:[f.jsx(y5,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),f.jsx("span",{className:"font-medium text-foreground truncate flex-1",children:Ek(e)}),t?f.jsx(Cn,{className:"h-4 w-4 text-muted-foreground group-hover:text-primary animate-spin flex-shrink-0"}):f.jsx(ek,{className:"h-4 w-4 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0"})]})}),f.jsx(Br,{children:f.jsx("p",{children:e})})]})}function c2e({connectionStatus:e,ready:t,snapshot:n,startingLocalPath:r,commandError:i,newProjectOpen:s,onNewProjectOpenChange:o,onOpenProject:l,onCreateProject:c}){const u=v.useMemo(()=>(n==null?void 0:n.projects)??[],[n==null?void 0:n.projects]),p=e==="connecting"||!t,h=e==="connected"&&t;return f.jsxs("div",{className:"flex-1 flex flex-col min-w-0 bg-background overflow-y-auto",children:[h?f.jsxs(f.Fragment,{children:[f.jsx(NP,{title:(n==null?void 0:n.machine.displayName)??"Local Projects",subtitle:`${or} is connected, choose a project below to get started.`}),f.jsxs("div",{className:"w-full px-6 mb-10",children:[f.jsxs("div",{className:"flex items-baseline justify-between mb-3",children:[f.jsx("h2",{className:"text-[13px] font-medium text-muted-foreground uppercase tracking-wider",children:"Projects"}),f.jsxs(Ge,{variant:"default",size:"sm",onClick:()=>o(!0),children:[f.jsx(Ed,{className:"h-4 w-4 mr-1.5"}),"Add Project"]})]}),u.length>0?f.jsx("div",{className:"grid gap-2 [grid-template-columns:repeat(auto-fill,minmax(min(260px,100%),1fr))]",children:u.map(g=>f.jsx(l2e,{localPath:g.localPath,loading:r===g.localPath,onClick:()=>{l(g.localPath)}},g.localPath))}):f.jsx(jv,{children:f.jsx("p",{className:"text-sm text-muted-foreground",children:"No local projects discovered yet. Open one with Claude or Codex, or create a new project here."})}),i?f.jsx("div",{className:"text-sm text-destructive border border-destructive/20 bg-destructive/5 rounded-xl px-4 py-3 mt-4",children:i}):null]})]}):f.jsxs(f.Fragment,{children:[f.jsx(NP,{narrow:!0,icon:IA,title:p?`Connecting ${or}`:`Connect ${or}`,subtitle:p?`${or} is starting up and loading your local projects.`:`Run ${or} directly on your machine with full access to your local files and agent project history.`}),f.jsxs("div",{className:"max-w-2xl w-full mx-auto pb-12 px-6",children:[f.jsx(xS,{children:"Status"}),f.jsx("div",{className:"mb-8",children:f.jsx(jv,{children:f.jsxs("div",{className:"flex items-center gap-3",children:[f.jsx(Cn,{className:"h-4 w-4 text-muted-foreground animate-spin"}),f.jsx("span",{className:"text-sm text-muted-foreground",children:p?`Connecting to your local ${or} server...`:f.jsxs(f.Fragment,{children:["Not connected. Run ",f.jsx("code",{className:"bg-background border border-border rounded-md mx-0.5 p-1 font-mono text-xs text-foreground",children:Pg()})," from any terminal on this machine."]})})]})})}),p?null:f.jsxs("div",{className:"mb-10",children:[f.jsx(xS,{children:"How it works"}),f.jsx(jv,{children:f.jsxs("div",{className:"flex items-start gap-4 py-2 px-2",children:[f.jsx(_S,{icon:my,title:`${or} CLI`,subtitle:"On Your Machine"}),f.jsx(MP,{}),f.jsx(_S,{icon:JC,title:`${or} Server`,subtitle:"Local WebSocket"}),f.jsx(MP,{}),f.jsx(_S,{icon:IA,title:`${or} UI`,subtitle:"Project Chat"})]})})]}),p?null:f.jsxs("div",{className:"mb-10",children:[f.jsx(xS,{children:"Setup"}),f.jsx(jv,{children:f.jsxs("div",{className:"space-y-4",children:[f.jsxs(LP,{number:1,title:`Start ${or}`,children:[f.jsx("p",{children:"Run this command in your terminal:"}),f.jsx(AP,{children:Pg()})]}),f.jsxs(LP,{number:2,title:"Open the local UI",children:[f.jsxs("p",{children:[or," serves the app locally and opens the Local Projects page in an app-style browser window."]}),f.jsx(AP,{children:"http://localhost:3210/local"})]}),f.jsxs("div",{className:"mt-8",children:[f.jsx("h3",{className:"text-sm font-medium text-muted-foreground uppercase tracking-wider mb-4",children:"Notes"}),f.jsxs("div",{className:"space-y-3 text-sm",children:[f.jsxs("div",{className:"flex gap-4",children:[f.jsx("code",{className:"font-mono text-foreground whitespace-nowrap",children:Pg("").trim()}),f.jsx("span",{className:"text-muted-foreground",children:"Start in the current directory"})]}),f.jsxs("div",{className:"flex gap-4",children:[f.jsx("code",{className:"font-mono text-foreground whitespace-nowrap",children:Pg("--no-open")}),f.jsx("span",{className:"text-muted-foreground",children:"Start the server without opening the browser"})]})]})]})]})})]})]})]}),f.jsx(o2e,{open:s,onOpenChange:o,onConfirm:g=>{c(g)}}),f.jsx("div",{className:"py-4 text-center",children:f.jsxs("span",{className:"text-xs text-muted-foreground/50",children:["v",kk.split("/")[1]]})})]})}function u2e(){const e=$C();return f.jsx("div",{className:"flex-1 flex flex-col min-w-0 relative",children:f.jsx(c2e,{connectionStatus:e.connectionStatus,ready:e.localProjectsReady,snapshot:e.localProjects,startingLocalPath:e.startingLocalPath,commandError:e.commandError,newProjectOpen:e.addProjectModalOpen,onNewProjectOpenChange:t=>{if(t){e.openAddProjectModal();return}e.closeAddProjectModal()},onOpenProject:e.handleOpenLocalProject,onCreateProject:e.handleCreateProject})})}const d2e=["app_launch","project_opened","project_created","project_removed","chat_created","chat_deleted","message_sent","update_checked","update_installed","update_failed","analytics_enabled","analytics_disabled"],f2e=["current_version","environment","latest_version","custom_port_enabled","no_open_enabled","password_enabled","strict_port_enabled","remote_enabled","host_enabled","share_quick_enabled","share_token_enabled"];function h2e(e){if(!e)return"—";const t=e.trim();if(!t)return"—";const n=t.slice(-4);return`${t.startsWith("sk-ant-")?"sk-ant-":""}…${n}`}function p2e(e){if(e<=0)return"reset now";const t=Math.ceil(e/1e3),n=Math.floor(t/60),r=t%60;if(n<60)return`reset in ${n}m ${r.toString().padStart(2,"0")}s`;const i=Math.floor(n/60),s=n%60;return`reset in ${i}h ${s.toString().padStart(2,"0")}m`}function m2e({entry:e,now:t}){if(e.status==="active")return f.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground",children:[f.jsx("span",{className:"size-1.5 rounded-full bg-muted-foreground/50","aria-hidden":"true"}),"Active"]});if(e.status==="limited"){const r=e.limitedUntil!==null?p2e(e.limitedUntil-t):null;return f.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-amber-600 dark:text-amber-400",children:[f.jsx("span",{className:"size-1.5 rounded-full bg-amber-500","aria-hidden":"true"}),"Limited",r!==null&&f.jsxs(f.Fragment,{children:[" ","(",f.jsx("span",{className:"tabular-nums",children:r}),")"]})]})}if(e.status==="disabled")return f.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground/60",children:[f.jsx("span",{className:"size-1.5 rounded-full bg-muted-foreground/30","aria-hidden":"true"}),"Disabled"]});const n=e.lastErrorMessage??"Unknown error";return f.jsx(My,{children:f.jsxs(Yr,{children:[f.jsx(Xr,{asChild:!0,children:f.jsxs("span",{className:"inline-flex cursor-default items-center gap-1.5 text-xs text-destructive",children:[f.jsx("span",{className:"size-1.5 rounded-full bg-destructive","aria-hidden":"true"}),"Error",f.jsx("span",{className:"sr-only",children:n})]})}),f.jsx(Br,{"aria-hidden":"true",children:n})]})})}function g2e({entry:e,now:t,isCurrent:n,onRemove:r,onToggleDisabled:i,onTest:s}){const[o,l]=v.useState(null),[c,u]=v.useState(!1),p=async()=>{u(!0),l(null);try{const g=await s(e.token),b=g.ok?"OK":g.error??"Error";l(b),setTimeout(()=>l(null),3e3)}catch{l("Error"),setTimeout(()=>l(null),3e3)}finally{u(!1)}},h=e.status==="disabled";return f.jsxs("div",{className:"flex items-center justify-between gap-3 border-t border-border py-3",children:[f.jsxs("div",{className:"min-w-0 flex-1",children:[f.jsxs("div",{className:"flex items-center gap-3",children:[f.jsx("span",{className:`text-sm font-medium ${h?"text-muted-foreground/60":"text-foreground"}`,children:e.label}),f.jsx("code",{className:"text-xs font-mono text-muted-foreground",children:h2e(e.token)}),n&&f.jsx("span",{className:"inline-flex items-center rounded-full border border-primary/40 bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-primary",children:"In use"})]}),f.jsx("div",{className:"mt-0.5",children:f.jsx(m2e,{entry:e,now:t})})]}),f.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[o!==null&&f.jsx("span",{className:"text-xs text-muted-foreground",children:o}),f.jsxs("button",{type:"button","aria-label":"Test",onClick:p,disabled:c||h,className:"inline-flex items-center gap-1 rounded px-2 py-1 text-xs text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",children:[f.jsx(pW,{className:"size-3","aria-hidden":"true"}),"Test"]}),f.jsx(My,{children:f.jsxs(Yr,{children:[f.jsx(Xr,{asChild:!0,children:f.jsxs("button",{type:"button","aria-label":h?"Enable":"Disable",onClick:i,className:"rounded p-1 text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[h?f.jsx(hG,{className:"size-3.5","aria-hidden":"true"}):f.jsx(dG,{className:"size-3.5","aria-hidden":"true"}),f.jsx("span",{className:"sr-only",children:h?"Enable":"Disable"})]})}),f.jsx(Br,{children:h?"Enable":"Disable"})]})}),f.jsxs("button",{type:"button","aria-label":"Remove",onClick:r,className:"rounded p-1 text-muted-foreground transition-colors hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[f.jsx(qd,{className:"size-3.5","aria-hidden":"true"}),f.jsx("span",{className:"sr-only",children:"Remove"})]})]})]})}function v2e({tokens:e,onWrite:t}){const[n,r]=v.useState(""),[i,s]=v.useState(""),[o,l]=v.useState(!1),c=n.trim().length>0&&i.trim().length>0&&!o,u=async()=>{if(c){l(!0);try{const p={id:crypto.randomUUID(),label:n.trim(),token:i.trim(),status:"active",limitedUntil:null,lastUsedAt:null,lastErrorAt:null,lastErrorMessage:null,addedAt:Date.now()};await t({tokens:[...e,p]}),r(""),s("")}finally{l(!1)}}};return f.jsx("div",{className:"border-t border-border pt-4",children:f.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-end sm:gap-3",children:[f.jsx("div",{className:"flex-1",children:f.jsx(Kn,{value:n,onChange:p=>r(p.target.value),placeholder:"e.g. personal",maxLength:64,className:"text-sm","aria-label":"Token label"})}),f.jsx("div",{className:"flex-[2]",children:f.jsx(Kn,{value:i,onChange:p=>s(p.target.value),type:"password",placeholder:"sk-ant-...",maxLength:1024,className:"text-sm font-mono","aria-label":"OAuth token"})}),f.jsx("button",{type:"button",onClick:u,disabled:!c,className:"inline-flex shrink-0 items-center rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",children:"Add token"})]})})}function b2e({tokens:e,onWrite:t,onTest:n,now:r}){var c;const i=r??Date.now(),s=((c=e.reduce((u,p)=>p.lastUsedAt!==null&&(u===null||p.lastUsedAt>(u.lastUsedAt??0))?p:u,null))==null?void 0:c.id)??null,o=u=>{t({tokens:e.filter(p=>p.id!==u)})},l=u=>{t({tokens:e.map(p=>p.id===u?{...p,status:p.status==="disabled"?"active":"disabled"}:p)})};return f.jsxs("div",{children:[e.map(u=>f.jsx(g2e,{entry:u,now:i,isCurrent:u.id===s,onRemove:()=>o(u.id),onToggleDisabled:()=>l(u.id),onTest:n},u.id)),f.jsx(v2e,{tokens:e,onWrite:t})]})}function tp({children:e,className:t,icon:n,type:r="button",variant:i="outline",...s}){return f.jsxs("button",{type:r,className:me(vy({variant:i,size:"sm"}),"h-auto gap-1.5 px-3 py-1.5",t),...s,children:[n,f.jsx("span",{children:e})]})}const jP="inline-flex items-center justify-center rounded-lg border border-border bg-background px-3 py-1.5 text-sm font-medium text-foreground transition-colors hover:bg-muted",y2e="inline-flex items-center justify-center rounded-lg bg-foreground px-3 py-1.5 text-sm font-medium text-background transition-colors hover:bg-foreground/90",DP="rounded bg-muted px-1 py-0.5 font-mono text-[12px] text-foreground",IP="text-[11px] font-medium uppercase tracking-wide text-muted-foreground";function x2e(e){const{permissionState:t}=e;if(t==="unsupported")return f.jsx("p",{className:"text-sm text-muted-foreground",children:"Push notifications are not supported in this browser."});if(t==="insecure-context")return f.jsxs("p",{className:"text-sm text-muted-foreground",children:["Push requires HTTPS. Run ",f.jsx("code",{className:DP,children:"kanna --share"})," or open Kanna over a tunnel, then enable on this device."]});if(t==="denied")return f.jsx("p",{className:"text-sm text-muted-foreground",children:"You blocked notifications for this site. Re-enable them in your browser settings, then reload."});if(!(t==="granted"&&e.config.devices.some(i=>i.id===e.currentDeviceId)))return f.jsx("button",{type:"button",onClick:()=>void e.onEnable(),className:y2e,children:"Enable on this device"});const r=new Set(e.config.preferences.mutedProjectPaths);return f.jsxs("div",{className:"flex w-full min-w-0 flex-col gap-5 md:w-[440px]",children:[f.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[f.jsxs("span",{className:"inline-flex items-center gap-2 rounded-full border border-border bg-card/40 px-3 py-1 text-xs font-medium text-foreground",children:[f.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-emerald-500","aria-hidden":!0}),"Enabled on this device"]}),f.jsx("button",{type:"button",onClick:()=>void e.onTest(),className:jP,children:"Send test"}),f.jsx("button",{type:"button",onClick:()=>void e.onDisable(),className:jP,children:"Disable"})]}),f.jsxs("div",{className:"flex flex-col gap-2",children:[f.jsx("div",{className:IP,children:"Devices"}),f.jsx("ul",{className:"flex flex-col gap-1.5",children:e.config.devices.map(i=>f.jsxs("li",{className:"flex items-start justify-between gap-3 rounded-lg border border-border bg-card/40 px-3 py-2",children:[f.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[f.jsx("span",{className:"truncate text-sm font-medium text-foreground",children:i.label}),f.jsx("span",{className:"line-clamp-2 break-all text-[11px] leading-snug text-muted-foreground",children:i.userAgent})]}),!i.isCurrentDevice&&f.jsx("button",{type:"button",onClick:()=>void e.onRemoveDevice(i.id),"aria-label":`Remove ${i.label}`,className:"shrink-0 rounded-md border border-border bg-background px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:"Remove"})]},i.id))})]}),f.jsxs("div",{className:"flex flex-col gap-2",children:[f.jsx("div",{className:IP,children:"Per-project"}),f.jsx("ul",{className:"flex flex-col",children:e.projects.map(i=>f.jsx("li",{children:f.jsxs("label",{className:"flex cursor-pointer items-center gap-3 rounded-md px-2 py-1.5 transition-colors hover:bg-muted/50",children:[f.jsx("input",{type:"checkbox",checked:!r.has(i.localPath),onChange:s=>void e.onMuteToggle(i.localPath,!s.target.checked),className:"h-4 w-4 shrink-0 rounded border-border accent-foreground"}),f.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[12px] text-foreground",title:i.localPath,children:i.localPath})]})},i.localPath))})]}),f.jsxs("p",{className:"text-xs leading-relaxed text-muted-foreground",children:["Phone setup: this page must be reachable over HTTPS. Run"," ",f.jsx("code",{className:DP,children:"kanna --share"})," or open Kanna over your tunnel on the phone, then enable on that device."]})]})}const zh=[{id:"general",label:"General",icon:AG,subtitle:"Manage appearance, editor behavior, and embedded terminal defaults."},{id:"skills",label:"Skills",icon:jA,subtitle:"Manage globally installed agent skills from the active skill lock file."},{id:"providers",label:"Providers",icon:GW,subtitle:"Manage the default chat provider and saved model defaults for Claude Code and Codex."},{id:"keybindings",label:"Keybindings",icon:IV,subtitle:"Edit global app shortcuts stored in the active keybindings file."},{id:"changelog",label:"Changelog",icon:jA,subtitle:"Release notes pulled from the public GitHub releases feed."}];function PP(e){return e&&zh.some(t=>t.id===e)?e:null}const _2e=[{value:"light",label:"Light",icon:YG},{value:"dark",label:"Dark",icon:ZW},{value:"system",label:"System",icon:JC}],w2e=[{value:"never",label:"Never"},{value:"unfocused",label:"When Unfocused"},{value:"always",label:"Always"}],S2e=[{value:"disabled",label:"Off"},{value:"enabled",label:"On"}],C2e=[{value:"disabled",label:"Off"},{value:"enabled",label:"On"}],k2e=[{value:"always-ask",label:"Always ask"},{value:"auto-expose",label:"Auto-expose"}],E2e=[{value:"openai",label:"OpenAI"},{value:"openrouter",label:"OpenRouter"},{value:"custom",label:"Custom"}],T2e="https://api.github.com/repos/cuongtranba/kanna/releases",R2e=300*1e3;let fd=null;const OP=Object.keys(O4);function N2e(e){return`Edit global app shortcuts stored in ${e}.`}function zP(e,t){return e!==t}async function A2e(e=fetch){const t=await e(T2e,{headers:{Accept:"application/vnd.github+json"}});if(!t.ok)throw new Error(`GitHub releases request failed with status ${t.status}`);return(await t.json()).filter(r=>!r.draft)}function M2e(){return fd?Date.now()>=fd.expiresAt?(fd=null,null):fd.releases:null}function L2e(e){fd={releases:e,expiresAt:Date.now()+R2e}}async function BP(e){const t=e!=null&&e.force?null:M2e();if(t)return t;const n=await A2e(e==null?void 0:e.fetchImpl);return L2e(n),n}function j2e(e){if(!e)return"Unpublished";const t=new Date(e);return Number.isNaN(t.getTime())?"Unknown date":new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",year:"numeric"}).format(t)}function D2e({status:e,releases:t,error:n,onRetry:r,updateSnapshot:i,currentVersion:s,onInstallUpdate:o,onCheckForUpdates:l,onForceReload:c}){var w;const u=(i==null?void 0:i.latestVersion)??((w=t[0])==null?void 0:w.tag_name)??"Unknown",p=(i==null?void 0:i.currentVersion)??s,h=(i==null?void 0:i.status)==="checking",g=(i==null?void 0:i.status)==="updating"||(i==null?void 0:i.status)==="restart_pending",b=(i==null?void 0:i.updateAvailable)===!0,x=u.replace(/^v/i,""),_=p.replace(/^v/i,"");return f.jsxs("div",{className:"space-y-4",children:[e==="loading"||e==="idle"?f.jsx("div",{className:"flex min-h-[180px] items-center justify-center rounded-2xl border border-border bg-card/40 px-6 py-8 text-sm text-muted-foreground",children:f.jsxs("div",{className:"flex items-center gap-3",children:[f.jsx(Cn,{className:"h-4 w-4 animate-spin"}),f.jsx("span",{children:"Loading release notes…"})]})}):null,e==="error"?f.jsx("div",{className:"rounded-lg border border-destructive/20 bg-destructive/5 px-6 py-5",children:f.jsxs("div",{className:"flex items-start justify-between gap-4",children:[f.jsxs("div",{children:[f.jsx("div",{className:"text-sm font-medium text-foreground",children:"Could not load changelog"}),f.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:n??"Unable to load changelog."})]}),f.jsx("button",{type:"button",onClick:r,className:"rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground transition-colors hover:bg-muted",children:"Retry"})]})}):null,e==="success"&&t.length===0?f.jsxs("div",{className:"rounded-lg border border-border bg-card/30 px-6 py-8",children:[f.jsx("div",{className:"text-sm font-medium text-foreground",children:"No releases yet"}),f.jsx("div",{className:"mt-2 text-sm text-muted-foreground",children:"GitHub did not return any published releases for this repository."})]}):null,e==="success"?f.jsxs("div",{className:"flex justify-end gap-2",children:[f.jsx(tp,{variant:"outline",onClick:c,disabled:g,children:g?"Re-deploying…":"Re-deploy"}),f.jsx(tp,{variant:"outline",onClick:l,disabled:h||g,children:h?"Checking…":"Check for updates"})]}):null,e==="success"&&t.length>0?t.map(C=>{var N,A;const E=C.tag_name.replace(/^v/i,""),k=E===x,R=E===_;return f.jsxs("article",{className:me("rounded-xl border bg-card/30 pl-6 pr-4 py-4",k?"border-border bg-muted":"border-border"),children:[f.jsxs("div",{className:"flex flex-row items-center min-w-0 flex-1 gap-3 ",children:[f.jsxs("div",{className:"flex flex-row items-center min-w-0 flex-1 gap-2 ",children:[f.jsx("div",{className:"text-lg font-semibold tracking-[-0.2px] text-foreground",children:((N=C.name)==null?void 0:N.trim())||C.tag_name}),f.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2 text-sm text-muted-foreground",children:[f.jsx("span",{children:j2e(C.published_at)}),C.prerelease?f.jsx("span",{className:"rounded-full border border-border px-2.5 py-1 uppercase tracking-wide",children:"Prerelease"}):null]})]}),f.jsxs("div",{className:"flex flex-row items-center justify-end min-w-0 flex-1 gap-2 ",children:[f.jsx("a",{href:C.html_url,target:"_blank",rel:"noopener noreferrer","aria-label":"View release on GitHub",className:me(vy({variant:"ghost",size:"icon-sm"}),"h-11 w-11 md:h-8 md:w-8 shrink-0 rounded-md hover:!bg-transparent hover:border-border/0"),children:f.jsx(I2e,{className:"h-4 w-4"})}),R?f.jsx("span",{className:me("bg-transparent border border-border text-secondary-foreground","h-9 rounded-full px-3 text-sm","h-auto gap-1.5 px-3 py-1.5"),children:"Current"}):null,k&&b?f.jsx(tp,{variant:"default",className:"",onClick:o,disabled:g,children:f.jsxs("div",{className:"flex flex-row items-center justify-center gap-2",children:[f.jsx(NV,{className:"size-4"}),g?"Updating…":"Update"]})}):null]})]}),(A=C.body)!=null&&A.trim()?f.jsx("div",{className:"prose prose-sm mt-5 max-w-none text-foreground dark:prose-invert",children:f.jsx(tu,{remarkPlugins:[uB],components:YE,children:C.body})}):f.jsx("div",{className:"mt-5 text-sm text-muted-foreground",children:"No release notes were provided."})]},C.id)}):null]})}function I2e({className:e}){return f.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",className:e,children:f.jsx("path",{d:"M12 .5C5.649.5.5 5.649.5 12A11.5 11.5 0 0 0 8.36 22.04c.575.106.785-.25.785-.556 0-.274-.01-1-.015-1.962-3.181.691-3.853-1.532-3.853-1.532-.52-1.322-1.27-1.674-1.27-1.674-1.038-.71.08-.695.08-.695 1.148.08 1.752 1.178 1.752 1.178 1.02 1.748 2.676 1.243 3.328.95.103-.738.399-1.243.725-1.53-2.54-.289-5.211-1.27-5.211-5.65 0-1.248.446-2.27 1.177-3.07-.118-.288-.51-1.45.112-3.024 0 0 .96-.307 3.145 1.173A10.91 10.91 0 0 1 12 6.03c.973.004 1.954.132 2.87.387 2.182-1.48 3.14-1.173 3.14-1.173.625 1.573.233 2.736.115 3.024.734.8 1.175 1.822 1.175 3.07 0 4.39-2.676 5.358-5.224 5.642.41.353.776 1.05.776 2.117 0 1.528-.014 2.761-.014 3.136 0 .309.207.668.79.555A11.502 11.502 0 0 0 23.5 12C23.5 5.649 18.351.5 12 .5Z"})})}function P2e(e){return!e||e<=0?"0 installs":e>=1e6?`${(e/1e6).toFixed(1).replace(/\.0$/,"")}M installs`:e>=1e3?`${(e/1e3).toFixed(1).replace(/\.0$/,"")}K installs`:`${e} install${e===1?"":"s"}`}function O2e({message:e}){return f.jsx("pre",{className:"max-w-full overflow-x-auto whitespace-pre-wrap rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-xs text-destructive",children:e})}function z2e({skill:e,uninstalling:t,onUninstall:n}){const r=e.source?`https://skills.sh/${e.source}/${e.name}`:null;return f.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3 rounded-lg border border-border bg-card/30 p-3",children:[f.jsxs("div",{className:"min-w-0",children:[f.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:e.name}),f.jsx("div",{className:"truncate text-xs text-muted-foreground",children:e.source||"Unknown source"})]}),f.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[r?f.jsx("a",{href:r,target:"_blank",rel:"noreferrer","aria-label":`View ${e.name} on skills.sh`,className:"touch-manipulation inline-flex h-8 w-8 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:f.jsx(XC,{className:"h-4 w-4"})}):null,f.jsx("button",{type:"button","aria-label":`Uninstall ${e.name}`,disabled:t,onClick:n,className:"touch-manipulation inline-flex h-8 w-8 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive disabled:pointer-events-none disabled:opacity-50",children:t?f.jsx(Cn,{className:"h-4 w-4 animate-spin"}):f.jsx(qd,{className:"h-4 w-4"})})]})]})}function B2e({skill:e,installing:t,installed:n,message:r,onInstall:i}){return f.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3 rounded-lg border border-border bg-card/30 p-3",children:[f.jsxs("div",{className:"min-w-0",children:[f.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:e.name}),f.jsxs("div",{className:"truncate text-xs text-muted-foreground",children:[e.source," · ",P2e(e.installs)]}),n&&r?f.jsx("div",{className:"mt-1 truncate text-xs text-emerald-500",children:r}):null]}),f.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[f.jsx("a",{href:`https://skills.sh/${e.id}`,target:"_blank",rel:"noreferrer","aria-label":`View ${e.name} on skills.sh`,className:"touch-manipulation inline-flex h-8 w-8 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:f.jsx(XC,{className:"h-4 w-4"})}),f.jsxs(Ge,{type:"button",size:"sm",variant:n?"secondary":"default",disabled:t||n,onClick:i,className:"h-6 rounded-full px-2 text-xs",children:[t?f.jsx(Cn,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):null,n?"Installed":t?"Installing":"Get"]})]})]})}function F2e({state:e}){const t=e.socket,n=e.connectionStatus,[r,i]=v.useState(""),[s,o]=v.useState([]),[l,c]=v.useState(!1),[u,p]=v.useState(null),[h,g]=v.useState([]),[b,x]=v.useState(()=>new Set),[_,w]=v.useState(!1),[C,E]=v.useState(null),[k,R]=v.useState(null),[N,A]=v.useState(null),[M,D]=v.useState(null),[U,j]=v.useState({}),P=v.useCallback(async()=>{if(n!=="connected"){g([]),x(new Set),E(null),w(!1);return}try{w(!0),E(null);const $=await t.command({type:"skills.listInstalled"});g($.skills),x(new Set($.skills.map(V=>V.name)))}catch($){g([]),x(new Set),E($ instanceof Error?$.message:"Unable to read installed skills.")}finally{w(!1)}},[n,t]);v.useEffect(()=>{P()},[n,P,t]),v.useEffect(()=>{const $=r.trim();if($.length<2){o([]),p(null),c(!1);return}if(n!=="connected"){o([]),c(!1),p("Backend connection required.");return}let V=!1;c(!0),p(null);const B=window.setTimeout(()=>{t.command({type:"skills.search",query:$,limit:100}).then(F=>{V||o(F.skills)}).catch(F=>{V||(o([]),p(F instanceof Error?F.message:"Unable to search skills."))}).finally(()=>{V||c(!1)})},250);return()=>{V=!0,window.clearTimeout(B)}},[n,r,t]);async function z($){if(n!=="connected"){R("Backend connection required.");return}try{A($.id),R(null),j(V=>{const B={...V};return delete B[$.id],B}),await t.command({type:"skills.install",source:$.source,skillId:$.skillId}),x(V=>new Set(V).add($.skillId)),j(V=>({...V,[$.id]:"Installed globally"})),P()}catch(V){R(V instanceof Error?V.message:"Install failed.")}finally{A(null)}}async function O($){if(n!=="connected"){R("Backend connection required.");return}try{D($.name),R(null),await t.command({type:"skills.uninstall",skillId:$.name}),g(V=>V.filter(B=>B.name!==$.name)),x(V=>{const B=new Set(V);return B.delete($.name),B}),j(V=>{const B={...V};for(const F of Object.keys(B))(F.endsWith(`/${$.name}`)||F===$.name)&&delete B[F];return B}),P()}catch(V){R(V instanceof Error?V.message:"Uninstall failed.")}finally{D(null)}}return f.jsxs("div",{className:"flex flex-col gap-6",children:[k?f.jsx(O2e,{message:k}):null,f.jsxs("section",{className:"flex flex-col gap-3",children:[f.jsxs("div",{className:"flex items-center justify-between gap-3",children:[f.jsx("div",{className:"text-sm font-medium text-foreground",children:"Installed"}),_?f.jsx(Cn,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}):null]}),C?f.jsx("div",{className:"text-xs text-destructive",children:C}):null,h.length>0?f.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:h.map($=>f.jsx(z2e,{skill:$,uninstalling:M===$.name,onUninstall:()=>{O($)}},`${$.source}/${$.name}`))}):_?null:f.jsx("div",{className:"rounded-lg border border-border bg-card/30 p-3 text-sm text-muted-foreground",children:"No global skills installed."})]}),f.jsxs("section",{className:"flex flex-col gap-3",children:[f.jsx("div",{className:"text-sm font-medium text-foreground",children:"Discover"}),f.jsxs("div",{className:"flex h-10 items-center gap-2 rounded-lg border border-border bg-card/30 px-3",children:[f.jsx(Bh,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),f.jsx("input",{type:"text",role:"searchbox",value:r,onChange:$=>i($.target.value),placeholder:"Search skills",className:"min-w-0 flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground"}),r?f.jsx("button",{type:"button","aria-label":"Clear skills search",onClick:()=>i(""),className:"touch-manipulation inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:f.jsx(io,{className:"h-3.5 w-3.5"})}):null,l?f.jsx(Cn,{className:"h-4 w-4 shrink-0 animate-spin text-muted-foreground"}):null]}),u?f.jsx("div",{className:"text-xs text-destructive",children:u}):null,f.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:s.map($=>f.jsx(B2e,{skill:$,installing:N===$.id,installed:b.has($.skillId),message:U[$.id],onInstall:()=>{z($)}},$.id))}),!l&&!u&&r.trim().length>=2&&s.length===0?f.jsx("div",{className:"rounded-lg border border-border bg-card/30 p-3 text-sm text-muted-foreground",children:"No skills found."}):null]})]})}function Gn({title:e,description:t,children:n,bordered:r=!0,alignStart:i=!1}){return f.jsx("div",{className:r?"border-t border-border":void 0,children:f.jsxs("div",{className:me("flex flex-col gap-4 py-5 md:flex-row md:justify-between md:gap-8",i?"md:items-start":"md:items-center"),children:[f.jsxs("div",{className:"min-w-0 max-w-xl",children:[f.jsx("div",{className:"text-sm font-medium text-foreground",children:e}),f.jsx("div",{className:"mt-1 text-[13px] text-muted-foreground",children:t})]}),f.jsx("div",{className:"flex items-center justify-start md:shrink-0 md:justify-end",children:n})]})})}function $2e({checked:e,onChange:t}){return f.jsxs("label",{className:"inline-flex items-center gap-2",children:[f.jsx("input",{type:"checkbox",checked:e,onChange:n=>t(n.target.checked)}),"Enabled"]})}function H2e(){var tr,li,lo;const e=Wd(),{sectionId:t}=o5(),n=$C(),{theme:r,setTheme:i}=u2(),[s,o]=v.useState("idle"),[l,c]=v.useState(!1),[u,p]=v.useState(!1),[h,g]=v.useState([]),[b,x]=v.useState(null),_=PP(t)??"general",w=n.connectionStatus==="connecting"||!n.localProjectsReady,C=((tr=n.localProjects)==null?void 0:tr.machine.displayName)??"Unavailable",E=((li=n.localProjects)==null?void 0:li.projects.length)??0,k=kk.split("/")[1]??"unknown",R=hi(Q=>Q.scrollbackLines),N=hi(Q=>Q.minColumnWidth),A=hi(Q=>Q.editorPreset),M=hi(Q=>Q.editorCommandTemplate),D=hi(Q=>Q.setScrollbackLines),U=hi(Q=>Q.setMinColumnWidth),j=hi(Q=>Q.setEditorPreset),P=hi(Q=>Q.setEditorCommandTemplate),z=Ec(Q=>Q.chatSoundPreference),O=Ec(Q=>Q.chatSoundId),$=Ec(Q=>Q.setChatSoundPreference),V=Ec(Q=>Q.setChatSoundId),B=n.keybindings,F=n.appSettings,W=n.llmProvider,X=G1(Q=>Q.autoResumeOnRateLimit),I=G1(Q=>Q.setAutoResumeOnRateLimit),G=gi(Q=>Q.defaultProvider),ee=gi(Q=>Q.providerDefaults),H=gi(Q=>Q.setDefaultProvider),ue=gi(Q=>Q.setProviderDefaultModel),ae=gi(Q=>Q.setProviderDefaultModelOptions),J=gi(Q=>Q.setProviderDefaultPlanMode),te=v.useMemo(()=>Jk(B),[B]),ie=te.filePathDisplay||zQ(),[de,he]=v.useState(()=>q1().state),[Le,ce]=v.useState(()=>cF()),[De,pe]=v.useState(String(R)),[st,zt]=v.useState(String(N)),Et=(F==null?void 0:F.uploads.maxFileSizeMb)??KM.maxFileSizeMb,[Qt,Dt]=v.useState(String(Et)),Tt=(F==null?void 0:F.claudeDriver.preference)??YM.preference,mt=Math.round(((F==null?void 0:F.claudeDriver.lifecycle.idleTimeoutMs)??Hv.idleTimeoutMs)/6e4),At=(F==null?void 0:F.claudeDriver.lifecycle.maxConcurrent)??Hv.maxConcurrent,[It,ht]=v.useState(String(mt)),[Ht,ge]=v.useState(String(At)),[we,Be]=v.useState(M),[tt,Pe]=v.useState({}),[Ve,qe]=v.useState(null),[Xe,We]=v.useState(null),[gt,ot]=v.useState(!1),[Bt,ut]=v.useState(null),[on,cn]=v.useState((F==null?void 0:F.cloudflareTunnel.cloudflaredPath)??XM.cloudflaredPath),[vt,Rt]=v.useState({provider:"openai",apiKey:"",model:"",baseUrl:""}),[St,Ut]=v.useState(null),[xt,ft]=v.useState("idle"),[Lt,Pt]=v.useState(null),[Ie,ze]=v.useState(!1),Te=n.updateSnapshot,Ye=n.handleWriteAppSettings,_e=n.handleWriteCloudflareTunnel,Je=n.handleWriteClaudeAuth,et=n.handleTestOAuthToken,$e=n.handleReadLlmProvider,Mt=n.handleWriteLlmProvider,un=n.handleValidateLlmProvider,Zt=(Te==null?void 0:Te.status)==="checking"?"Checking for updates…":(Te==null?void 0:Te.status)==="updating"?"Installing update…":(Te==null?void 0:Te.status)==="restart_pending"?"Restarting Kanna…":(Te==null?void 0:Te.status)==="available"?`Update available${Te.latestVersion?`: ${Te.latestVersion}`:""}`:(Te==null?void 0:Te.status)==="up_to_date"?"Up to date":(Te==null?void 0:Te.status)==="error"?"Update check failed":"Not checked yet";v.useEffect(()=>{pe(String(R))},[R]),v.useEffect(()=>{zt(String(N))},[N]),v.useEffect(()=>{Dt(String(Et))},[Et]),v.useEffect(()=>{ht(String(mt))},[mt]),v.useEffect(()=>{ge(String(At))},[At]),v.useEffect(()=>{const Q=()=>he(q1().state);return window.addEventListener("focus",Q),()=>window.removeEventListener("focus",Q)},[]),v.useEffect(()=>{Be(M)},[M]),v.useEffect(()=>{Pe(Object.fromEntries(OP.map(Q=>[Q,Q_(te.bindings[Q])])))},[te]),v.useEffect(()=>{W&&Rt({provider:W.provider,apiKey:W.apiKey,model:W.model,baseUrl:W.baseUrl})},[W]),v.useEffect(()=>{ft("idle"),Pt(null)},[vt.provider,vt.apiKey,vt.model,vt.baseUrl]),v.useEffect(()=>{t&&(PP(t)||e("/settings/general",{replace:!0}))},[e,t]),v.useEffect(()=>{F&&cn(F.cloudflareTunnel.cloudflaredPath)},[F]),v.useEffect(()=>{let Q=!1;return fetch("/auth/status",{method:"GET",cache:"no-store",headers:{Accept:"application/json"}}).then(async Oe=>Oe.ok?await Oe.json():{enabled:!1}).then(Oe=>{Q||p(Oe.enabled===!0)}).catch(()=>{Q||p(!1)}),()=>{Q=!0}},[]),v.useEffect(()=>{_!=="providers"||w||$e()},[$e,w,_]),v.useEffect(()=>{if(_!=="changelog"||w)return;let Q=!1;return o("loading"),x(null),BP().then(Oe=>{Q||(g(Oe),o("success"))}).catch(Oe=>{Q||(x(Oe instanceof Error?Oe.message:"Unable to load changelog."),o("error"))}),()=>{Q=!0}},[w,_]);function Fe(){const Q=Number(De);if(!Number.isFinite(Q)){pe(String(R));return}D(Q),Ye({terminal:{scrollbackLines:Q}}).catch(Oe=>{We(Oe instanceof Error?Oe.message:"Unable to save terminal settings.")})}function hn(){const Q=Number(st);if(!Number.isFinite(Q)){zt(String(N));return}U(Q),Ye({terminal:{minColumnWidth:Q}}).catch(Oe=>{We(Oe instanceof Error?Oe.message:"Unable to save terminal settings.")})}function lr(){const Q=Number(Qt);if(!Number.isFinite(Q)||Q<Fg||Q>$g){Dt(String(Et)),We(`Max file size must be between ${Fg} and ${$g} MB.`);return}if(Math.round(Q)===Et){Dt(String(Et));return}Ye({uploads:{maxFileSizeMb:Math.round(Q)}}).catch(Oe=>{We(Oe instanceof Error?Oe.message:"Unable to save upload settings.")})}function se(Q){Q!==Tt&&Ye({claudeDriver:{preference:Q}}).catch(Oe=>{We(Oe instanceof Error?Oe.message:"Unable to save Claude driver preference.")})}function le(){const Q=Number(It),Oe=Math.round(Y_/6e4),xn=Math.round(X_/6e4);if(!Number.isFinite(Q)||Q<Oe||Q>xn){ht(String(mt)),We(`Idle timeout must be between ${Oe} and ${xn} minutes.`);return}if(Math.round(Q)===mt){ht(String(mt));return}Ye({claudeDriver:{lifecycle:{idleTimeoutMs:Math.round(Q)*6e4}}}).catch(co=>{We(co instanceof Error?co.message:"Unable to save Claude lifecycle settings.")})}function Ce(){const Q=Number(Ht);if(!Number.isFinite(Q)||Q<Hg||Q>Ug){ge(String(At)),We(`Max concurrent sessions must be between ${Hg} and ${Ug}.`);return}if(Math.round(Q)===At){ge(String(At));return}Ye({claudeDriver:{lifecycle:{maxConcurrent:Math.round(Q)}}}).catch(Oe=>{We(Oe instanceof Error?Oe.message:"Unable to save Claude lifecycle settings.")})}function Ee(Q,Oe){Q.key==="Enter"&&(Oe(),Q.currentTarget.blur())}function Qe(Q,Oe){Q.key==="Enter"&&(Oe(),Q.currentTarget.blur())}function ct(){P(we),Ye({editor:{commandTemplate:we}}).catch(Q=>{We(Q instanceof Error?Q.message:"Unable to save editor settings.")})}function Ze(Q){i(Q),Ye({theme:Q}).catch(Oe=>{We(Oe instanceof Error?Oe.message:"Unable to save theme settings.")})}function Vt(Q){j(Q);const Oe=Q==="custom"?M:Md(Q);Ye({editor:{preset:Q,commandTemplate:Oe}}).catch(xn=>{We(xn instanceof Error?xn.message:"Unable to save editor settings.")})}function Dn(Q){zP(z,Q)&&($(Q),Ye({chatSoundPreference:Q}).catch(Oe=>{We(Oe instanceof Error?Oe.message:"Unable to save chat sound settings.")}),DS(O,1).catch(()=>{}))}function fn(Q){zP(O,Q)&&(V(Q),Ye({chatSoundId:Q}).catch(Oe=>{We(Oe instanceof Error?Oe.message:"Unable to save chat sound settings.")}),DS(Q,1).catch(()=>{}))}async function Si(Q){try{We(null),await Ye({analyticsEnabled:Q==="enabled"})}catch(Oe){We(Oe instanceof Error?Oe.message:"Unable to save analytics settings.")}}async function Vn(Q){try{ut(null),await _e(Q)}catch(Oe){ut(Oe instanceof Error?Oe.message:"Unable to save Cloudflare Tunnel settings.")}}function Tr(Q){H(Q),Ye({defaultProvider:Q}).catch(Oe=>{We(Oe instanceof Error?Oe.message:"Unable to save provider settings.")})}function Qr(Q,Oe){ue(Q,Oe),Ye({providerDefaults:{[Q]:{model:Oe}}}).catch(xn=>{We(xn instanceof Error?xn.message:"Unable to save provider settings.")})}function Oi(Q,Oe){ae(Q,Oe),Ye({providerDefaults:{[Q]:{modelOptions:Oe}}}).catch(xn=>{We(xn instanceof Error?xn.message:"Unable to save provider settings.")})}function ai(Q,Oe){J(Q,Oe),Ye({providerDefaults:{[Q]:{planMode:Oe}}}).catch(xn=>{We(xn instanceof Error?xn.message:"Unable to save provider settings.")})}async function ts(){try{qe(null),await n.socket.command({type:"settings.writeKeybindings",bindings:FP(tt)})}catch(Q){qe(Q instanceof Error?Q.message:"Unable to save keybindings.")}}async function zi(Q){const Oe={...tt,[Q]:Q_(mp[Q])};Pe(Oe);try{qe(null),await n.socket.command({type:"settings.writeKeybindings",bindings:FP(Oe)})}catch(xn){qe(xn instanceof Error?xn.message:"Unable to save keybindings.")}}async function _t(Q=vt){try{Ut(null),await Mt(Q);const Oe=await un(Q);ft(Oe.ok?"valid":"invalid"),Pt(Oe.error)}catch(Oe){const xn=Oe instanceof Error?{name:Oe.name,message:Oe.message}:Oe;ft("invalid"),Pt(xn),Ut(Oe instanceof Error?Oe.message:"Unable to save quick response provider settings.")}}function an(Q){const Oe={...vt,provider:Q,model:Q==="openai"?Kte:Q==="openrouter"?Yte:vt.model,baseUrl:Q==="custom"?vt.baseUrl:""};Rt(Oe),_t(Oe)}function kn(){fd=null,o("loading"),x(null),BP({force:!0}).then(Q=>{g(Q),o("success")}).catch(Q=>{x(Q instanceof Error?Q.message:"Unable to load changelog."),o("error")})}const gn=we.replaceAll("{path}","/Users/jake/Projects/kanna/src/client/app/App.tsx").replaceAll("{line}","12").replaceAll("{column}","1"),ao=d2e,Da=(F==null?void 0:F.analyticsEnabled)===!1?"disabled":"enabled",ns=(F==null?void 0:F.cloudflareTunnel)??XM,Fo=ns.enabled?"enabled":"disabled",rs=zh.find(Q=>Q.id===_)??zh[0],Ia=_==="keybindings"?N2e(ie):rs.subtitle,cr=!w,je=Lt?JSON.stringify(Lt,null,2):"",Ke=f.jsxs(f.Fragment,{children:[f.jsxs("span",{children:["Use an OpenAI-compatible API for title and commit message generation before Claude and Codex. Stored in ",(W==null?void 0:W.filePathDisplay)??"the active llm-provider.json file","."]}),f.jsx("span",{className:me("mt-2 block text-sm font-medium",xt==="valid"?"text-success":xt==="invalid"?"text-destructive":"hidden"),children:xt==="valid"?"Credentials valid & saved":xt==="invalid"?f.jsxs(f.Fragment,{children:[f.jsx("span",{children:"Credentials invalid."}),Lt?f.jsxs(f.Fragment,{children:[" ",f.jsx("button",{type:"button",onClick:()=>ze(!0),className:"underline underline-offset-2",children:"See error"})]}):null]}):null})]});async function Ft(){if(!l){c(!0);try{await n.handleSignOut()}finally{c(!1)}}}return f.jsxs("div",{className:"relative flex h-full flex-1 min-w-0 bg-background",children:[f.jsxs("div",{className:"flex min-w-0 flex-1",children:[f.jsx("aside",{className:`hidden w-[200px] shrink-0 md:block ${cr?"pb-[89px]":""}`,children:f.jsxs("div",{className:"flex flex-col gap-1 px-4 py-6",children:[f.jsx("div",{className:"px-3 pb-5 text-[22px] font-extrabold tracking-[-0.5px] text-foreground",children:"Settings"}),zh.map(Q=>{const Oe=Q.id==="changelog"&&(Te==null?void 0:Te.updateAvailable)===!0;return f.jsx("button",{type:"button",onClick:()=>e(`/settings/${Q.id}`),className:`cursor-pointer rounded-lg px-3 py-2 text-sm ${Q.id===_?"bg-muted font-medium text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"}`,children:f.jsxs("div",{className:"flex items-center gap-2.5",children:[f.jsx(Q.icon,{className:"h-4 w-4 shrink-0"}),f.jsx("span",{children:Q.label}),Oe?f.jsx("span",{className:"ml-auto inline-flex items-center rounded-full bg-logo/20 px-2 py-0.5 text-[10px] font-bold tracking-wider text-logo",children:"UPDATE"}):null]})},Q.label)}),u?f.jsx("button",{type:"button",onClick:()=>{Ft()},disabled:l,className:"cursor-pointer rounded-lg px-3 py-2 text-sm text-muted-foreground hover:bg-muted/50 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",children:f.jsxs("div",{className:"flex items-center gap-2.5",children:[f.jsx(OA,{className:"h-4 w-4 shrink-0"}),f.jsx("span",{children:l?"Signing out...":"Sign out"})]})}):null]})}),f.jsxs("div",{className:"min-w-0 flex-1 overflow-y-auto",children:[f.jsx("div",{className:"border-b border-border py-2 md:hidden",children:f.jsx("div",{className:"overflow-x-auto pr-4 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:f.jsxs("div",{className:"flex min-w-max items-center gap-2",children:[f.jsx("div",{className:" sticky left-0 bg-gradient-to-r from-background via-background/80 to-transparent px-2 py-1",children:f.jsx("button",{type:"button",onClick:n.openSidebar,className:"flex shrink-0 items-center p-2 text-sm text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground","aria-label":"Open sidebar",title:"Open sidebar",children:f.jsx(ZC,{className:"h-4 w-4 shrink-0"})})}),zh.map(Q=>f.jsxs("button",{type:"button",onClick:()=>e(`/settings/${Q.id}`),className:me("flex shrink-0 items-center gap-2 rounded-full border px-3 py-2 text-sm transition-colors",Q.id===_?"border-transparent bg-muted font-medium text-foreground":"border-border bg-background text-muted-foreground hover:bg-muted/50 hover:text-foreground"),children:[f.jsx(Q.icon,{className:"h-4 w-4 shrink-0"}),f.jsx("span",{className:"whitespace-nowrap",children:Q.label})]},Q.label)),u?f.jsxs("button",{type:"button",onClick:()=>{Ft()},disabled:l,className:me("flex shrink-0 items-center gap-2 rounded-full border px-3 py-2 text-sm transition-colors","border-border bg-background text-muted-foreground hover:bg-muted/50 hover:text-foreground","disabled:cursor-not-allowed disabled:opacity-50"),children:[f.jsx(OA,{className:"h-4 w-4 shrink-0"}),f.jsx("span",{className:"whitespace-nowrap",children:l?"Signing out...":"Sign out"})]}):null]})})}),f.jsxs("div",{className:"w-full px-4 pb-32 pt-8 md:px-6 md:pt-16",children:[w?f.jsx("div",{className:"flex min-h-[240px] items-center justify-center rounded-2xl border border-border bg-card/40 px-4 py-6 text-sm text-muted-foreground",children:f.jsxs("div",{className:"flex items-center gap-3",children:[f.jsx(Cn,{className:"h-4 w-4 animate-spin"}),f.jsx("span",{children:"Loading machine settings…"})]})}):f.jsxs("div",{className:"mx-auto max-w-4xl",children:[f.jsxs("div",{className:"pb-6",children:[f.jsxs("div",{className:"flex items-center justify-between gap-4 min-h-[34px]",children:[f.jsx("div",{className:"text-lg font-semibold tracking-[-0.2px] text-foreground",children:rs.label}),_==="general"?f.jsx(tp,{variant:"outline",onClick:()=>e("/settings/changelog"),children:"Check for updates"}):null,_==="keybindings"?f.jsxs(tp,{onClick:()=>{n.handleOpenExternalPath("open_editor",ie)},icon:f.jsx(KC,{className:"h-4 w-4"}),children:["Open in ",n.editorLabel]}):null]}),f.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:Ia})]}),_==="general"?f.jsxs(f.Fragment,{children:[Xe?f.jsx("div",{className:"mb-4 rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-sm text-destructive",children:Xe}):null,f.jsxs("div",{className:"border-b border-border",children:[f.jsx(Gn,{title:"Application Update",description:f.jsxs(f.Fragment,{children:[f.jsxs("span",{children:[Zt,"."]}),Te!=null&&Te.lastCheckedAt?f.jsxs("span",{children:[" Last checked ",new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(Te.lastCheckedAt),"."]}):null,Te!=null&&Te.error?f.jsxs("span",{children:[" ",Te.error]}):null]}),bordered:!1,children:f.jsxs("div",{className:"text-right text-sm text-foreground",children:[f.jsxs("div",{children:["Current: ",(Te==null?void 0:Te.currentVersion)??k]}),f.jsxs("div",{className:"text-xs text-muted-foreground",children:["Latest: ",(Te==null?void 0:Te.latestVersion)??"Unknown"]})]})}),f.jsx(Gn,{title:"Theme",description:"Choose between light, dark, or system appearance",children:f.jsx(da,{value:r,onValueChange:Ze,options:_2e,size:"sm"})}),f.jsx(Gn,{title:"Chat Sounds",description:"Play a pop when a chat starts waiting on you or the unread chat count increases",children:f.jsxs(Sl,{value:z,onValueChange:Q=>Dn(Q),children:[f.jsx(fa,{className:"min-w-[180px]",children:f.jsx(Sc,{})}),f.jsx(ha,{children:f.jsx(id,{children:w2e.map(Q=>f.jsx(Ws,{value:Q.value,children:Q.label},Q.value))})})]})}),f.jsx(Gn,{title:"Chat Sound",description:"The bundled sound used for chat notification playback and previews",children:f.jsxs(Sl,{value:O,onValueChange:Q=>fn(Q),children:[f.jsx(fa,{className:"min-w-[180px]",children:f.jsx(Sc,{})}),f.jsx(ha,{children:f.jsx(id,{children:UQ.map(Q=>f.jsx(Ws,{value:Q.value,children:Q.label},Q.value))})})]})}),f.jsx(Gn,{title:"Default Editor",description:"Used when opening transcript links or files from the git diff menu",alignStart:!0,children:f.jsxs(Sl,{value:A,onValueChange:Q=>Vt(Q),children:[f.jsx(fa,{className:"min-w-[180px]",children:f.jsx(Sc,{})}),f.jsx(ha,{children:f.jsx(id,{children:nE.map(Q=>f.jsx(Ws,{value:Q.value,children:f.jsxs("span",{className:"flex items-center gap-2",children:[f.jsx(U4,{preset:Q.value,className:"h-4 w-4 shrink-0"}),f.jsx("span",{children:Q.label})]})},Q.value))})})]})}),A==="custom"?f.jsx("div",{className:"border-t border-border",children:f.jsxs("div",{className:"flex justify-between gap-8 py-5 pl-6",children:[f.jsxs("div",{className:"min-w-0 max-w-xl",children:[f.jsx("div",{className:"text-sm font-medium text-foreground",children:"Command Template"}),f.jsxs("div",{className:"mt-1 text-[13px] text-muted-foreground",children:["Include ","{path}"," and optionally ","{line}"," and ","{column}"," in your command."]})]}),f.jsxs("div",{className:"flex min-w-0 max-w-[420px] flex-1 flex-col items-stretch gap-2",children:[f.jsx(Kn,{type:"text",value:we,onChange:Q=>Be(Q.target.value),onBlur:ct,onKeyDown:Q=>Qe(Q,ct),className:"font-mono"}),f.jsxs("div",{className:"text-xs text-muted-foreground",children:["Preview: ",f.jsx("span",{className:"font-mono",children:gn})]})]})]})}):null,f.jsx(Gn,{title:"Terminal Scrollback",description:"Lines retained for embedded terminal history",children:f.jsxs("div",{className:"flex w-full min-w-0 flex-col items-stretch gap-2 md:w-auto md:items-end",children:[f.jsx(Kn,{type:"number",min:YS,max:XS,step:100,value:De,onChange:Q=>pe(Q.target.value),onBlur:Fe,onKeyDown:Q=>Ee(Q,Fe),className:"hide-number-steppers w-full text-left font-mono md:w-28 md:text-right"}),f.jsxs("div",{className:"text-left text-xs text-muted-foreground md:text-right",children:[YS,"-",XS," lines",R===eE?" (default)":""]})]})}),f.jsx(Gn,{title:"Terminal Min Column Width",description:"Minimum width for each terminal pane",children:f.jsxs("div",{className:"flex w-full min-w-0 flex-col items-stretch gap-2 md:w-auto md:items-end",children:[f.jsx(Kn,{type:"number",min:QS,max:ZS,step:10,value:st,onChange:Q=>zt(Q.target.value),onBlur:hn,onKeyDown:Q=>Ee(Q,hn),className:"hide-number-steppers w-full text-left font-mono md:w-28 md:text-right"}),f.jsxs("div",{className:"text-left text-xs text-muted-foreground md:text-right",children:[QS,"-",ZS," px",N===tE?" (default)":""]})]})}),f.jsx(Gn,{title:"Max upload file size",description:"Largest single file the chat upload endpoint accepts.",children:f.jsxs("div",{className:"flex w-full min-w-0 flex-col items-stretch gap-1.5 md:w-auto md:items-end",children:[f.jsxs("div",{className:"flex items-center gap-2 md:justify-end",children:[f.jsx(Kn,{type:"number",min:Fg,max:$g,step:1,value:Qt,onChange:Q=>Dt(Q.target.value),onBlur:lr,onKeyDown:Q=>Ee(Q,lr),className:"hide-number-steppers w-full text-left font-mono tabular-nums md:w-24 md:text-right","aria-label":"Max upload file size in megabytes"}),f.jsx("span",{className:"text-sm text-muted-foreground",children:"MB"})]}),f.jsxs("div",{className:"text-left text-xs text-muted-foreground tabular-nums md:text-right",children:[Fg,"–",$g," MB · default ",KM.maxFileSizeMb]})]})}),f.jsx(Gn,{title:"Auto-resume on rate limit",description:'When you hit a rate limit, automatically schedule "continue" at the reset time instead of asking. You can still cancel each one from the chat.',children:f.jsx($2e,{checked:X,onChange:I})}),n.pushConfig?f.jsx(Gn,{title:"Push notifications",description:"Get notified when a chat is waiting for you, finishes, or fails. Works on iPhone (after Add to Home Screen), Android, and desktop browsers.",bordered:!1,alignStart:!0,children:f.jsx(x2e,{permissionState:de,config:n.pushConfig,projects:((lo=n.localProjects)==null?void 0:lo.projects)??[],currentDeviceId:Le,onEnable:async()=>{if(!n.pushConfig)return;const Q=await uye({vapidPublicKey:n.pushConfig.vapidPublicKey,sendToServer:async Oe=>{const xn=await n.socket.command({type:"push.subscribe",subscription:Oe.subscription,label:Oe.label,userAgent:Oe.userAgent});return iye(xn.id),{id:xn.id}}});ce(Q)},onDisable:async()=>{Le&&(await dye({pushDeviceId:Le,sendToServer:async Q=>{await n.socket.command({type:"push.unsubscribe",pushDeviceId:Q})}}),sye(),ce(null))},onTest:async()=>{await n.socket.command({type:"push.test"})},onMuteToggle:async(Q,Oe)=>{await n.socket.command({type:"push.setProjectMute",localPath:Q,muted:Oe})},onRemoveDevice:async Q=>{await n.socket.command({type:"push.unsubscribe",pushDeviceId:Q})}})}):null,f.jsx(Gn,{title:"Anonymous Analytics",description:f.jsxs(f.Fragment,{children:[f.jsx("span",{children:"Help improve Kanna with anonymous product analytics. Kanna sends tracked event names plus a small set of event properties like current version, environment, update version info, and launch flags. No message content, prompts, file paths, or provider credentials are sent."}),f.jsxs("span",{className:"mt-1 block",children:["Stored in ",(F==null?void 0:F.filePathDisplay)??"~/.kanna/data/settings.json","."," ",f.jsx("button",{type:"button",onClick:()=>ot(!0),className:"underline underline-offset-2 text-foreground hover:text-foreground/80",children:"View tracked events"})]}),F!=null&&F.warning?f.jsx("span",{className:"mt-1 block",children:F.warning}):null]}),children:f.jsx(da,{value:Da,onValueChange:Q=>{Si(Q)},options:S2e,size:"sm"})})]}),f.jsxs("div",{className:"border-b border-border",children:[Bt?f.jsx("div",{className:"mb-4 rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-sm text-destructive",children:Bt}):null,f.jsx(Gn,{title:"Cloudflare Tunnel",description:f.jsxs(f.Fragment,{children:[f.jsxs("span",{children:["When enabled, Claude can call the ",f.jsx("code",{className:"rounded bg-muted px-1 py-0.5 font-mono text-xs",children:"expose_port"})," tool to expose a local port via Cloudflare Tunnel. The mode below controls whether each call requires your approval or is exposed automatically. Requires"," ",f.jsx("code",{className:"rounded bg-muted px-1 py-0.5 font-mono text-xs",children:"cloudflared"})," ","to be installed."]}),f.jsxs("span",{className:"mt-1 block",children:["Stored in ",(F==null?void 0:F.filePathDisplay)??"~/.kanna/data/settings.json","."]})]}),bordered:!1,children:f.jsx(da,{value:Fo,onValueChange:Q=>{Vn({enabled:Q==="enabled"})},options:C2e,size:"sm"})}),ns.enabled&&f.jsxs(f.Fragment,{children:[f.jsx(Gn,{title:"Tool mode",description:"Always ask: each expose_port call shows an accept card. Auto-expose: expose_port calls spawn cloudflared immediately without prompting.",children:f.jsx(da,{value:ns.mode,onValueChange:Q=>{Vn({mode:Q})},options:k2e,size:"sm"})}),f.jsx(Gn,{title:"cloudflared path",description:"Path to the cloudflared binary. Defaults to the one found on $PATH.",children:f.jsx(Kn,{value:on,onChange:Q=>cn(Q.target.value),onBlur:()=>{Vn({cloudflaredPath:on})},placeholder:"cloudflared",className:"w-full font-mono md:w-64"})})]})]})]}):_==="providers"?f.jsxs("div",{className:"border-b border-border",children:[f.jsx(Gn,{title:"Claude OAuth tokens",description:"Manage multiple Claude OAuth tokens. Kanna switches automatically when one hits its rate limit.",bordered:!1,alignStart:!0,children:f.jsx("div",{className:"w-full md:w-[420px]",children:f.jsx(b2e,{tokens:(F==null?void 0:F.claudeAuth.tokens)??[],onWrite:Je,onTest:et})})}),f.jsx(Gn,{title:"Claude driver",description:"SDK uses the @anthropic-ai/claude-agent-sdk programmatic API (billed at API rates). PTY launches the `claude` CLI under a pseudo-terminal — preserves Pro/Max subscription billing. Requires `claude /login` to have been run once and ANTHROPIC_API_KEY to be unset. macOS/Linux only.",children:f.jsx(da,{value:Tt,onValueChange:Q=>se(Q),options:[{value:"sdk",label:"SDK (API)"},{value:"pty",label:"PTY (subscription)"}]})}),f.jsx(Gn,{title:"PTY idle timeout",description:"Stop a Claude PTY session after this many minutes without user activity. Lower values free subscription quota faster; higher values keep cold-start latency low.",children:f.jsxs("div",{className:"flex w-full min-w-0 flex-col items-stretch gap-2 md:w-auto md:items-end",children:[f.jsx(Kn,{type:"number",min:Math.round(Y_/6e4),max:Math.round(X_/6e4),step:1,value:It,onChange:Q=>ht(Q.target.value),onBlur:le,onKeyDown:Q=>Ee(Q,le),className:"hide-number-steppers w-full text-left font-mono md:w-28 md:text-right"}),f.jsxs("div",{className:"text-left text-xs text-muted-foreground md:text-right",children:[Math.round(Y_/6e4),"–",Math.round(X_/6e4)," min · default ",Math.round(Hv.idleTimeoutMs/6e4)]})]})}),f.jsx(Gn,{title:"PTY max concurrent sessions",description:"Hard cap on resident Claude PTY processes. Excess sessions are evicted LRU; their next activation cold-starts.",children:f.jsxs("div",{className:"flex w-full min-w-0 flex-col items-stretch gap-2 md:w-auto md:items-end",children:[f.jsx(Kn,{type:"number",min:Hg,max:Ug,step:1,value:Ht,onChange:Q=>ge(Q.target.value),onBlur:Ce,onKeyDown:Q=>Ee(Q,Ce),className:"hide-number-steppers w-full text-left font-mono md:w-28 md:text-right"}),f.jsxs("div",{className:"text-left text-xs text-muted-foreground md:text-right",children:[Hg,"–",Ug," · default ",YM.lifecycle.maxConcurrent]})]})}),f.jsx(Gn,{title:"Default Provider",description:"The default harness used for new chats before a provider is locked by an existing session.",children:f.jsxs(Sl,{value:G,onValueChange:Q=>Tr(Q),children:[f.jsx(fa,{className:"min-w-[180px]",children:f.jsx(Sc,{})}),f.jsx(ha,{children:f.jsxs(id,{children:[f.jsx(Ws,{value:"last_used",children:"Last Used"}),Uh.map(Q=>f.jsx(Ws,{value:Q.id,children:Q.label},Q.id))]})})]})}),f.jsx(Gn,{title:"Claude Code Defaults",description:"Saved defaults when using Claude Code.",alignStart:!0,children:f.jsx("div",{className:"max-w-[420px]",children:f.jsx(K1,{availableProviders:Uh,selectedProvider:"claude",showProviderPicker:!1,model:ee.claude.model,modelOptions:ee.claude.modelOptions,onModelChange:(Q,Oe)=>{Qr("claude",Oe)},onModelOptionChange:Q=>{Q.type==="claudeReasoningEffort"?Oi("claude",{reasoningEffort:Q.effort}):Q.type==="contextWindow"&&Oi("claude",{contextWindow:Q.contextWindow})},planMode:ee.claude.planMode,onPlanModeChange:Q=>ai("claude",Q),includePlanMode:!0,className:"justify-start flex-wrap"})})}),f.jsx(Gn,{title:"Codex Defaults",description:"Saved defaults when using Codex.",alignStart:!0,children:f.jsx("div",{className:"max-w-[420px]",children:f.jsx(K1,{availableProviders:Uh,selectedProvider:"codex",showProviderPicker:!1,model:ee.codex.model,modelOptions:ee.codex.modelOptions,onModelChange:(Q,Oe)=>{Qr("codex",Oe)},onModelOptionChange:Q=>{Q.type==="codexReasoningEffort"?Oi("codex",{reasoningEffort:Q.effort}):Q.type==="fastMode"&&Oi("codex",{fastMode:Q.fastMode})},planMode:ee.codex.planMode,onPlanModeChange:Q=>ai("codex",Q),includePlanMode:!0,className:"justify-start flex-wrap"})})}),f.jsx(Gn,{title:"Quick Response SDK",description:Ke,alignStart:!0,children:f.jsxs("div",{className:"flex w-full max-w-[420px] flex-col gap-3",children:[St?f.jsx("div",{className:"rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-sm text-destructive",children:St}):null,W!=null&&W.warning?f.jsx("div",{className:"rounded-lg border border-border bg-card/30 px-4 py-3 text-sm text-muted-foreground",children:W.warning}):null,f.jsxs(Sl,{value:vt.provider,onValueChange:Q=>an(Q),children:[f.jsx(fa,{className:"w-full",children:f.jsx(Sc,{})}),f.jsx(ha,{children:f.jsx(id,{children:E2e.map(Q=>f.jsx(Ws,{value:Q.value,children:Q.label},Q.value))})})]}),vt.provider==="custom"?f.jsx(Kn,{value:vt.baseUrl,onChange:Q=>Rt(Oe=>({...Oe,baseUrl:Q.target.value})),onBlur:()=>void _t(),onKeyDown:Q=>Qe(Q,()=>void _t()),placeholder:"https://your-provider.example/v1"}):null,f.jsx(Kn,{type:"password",value:vt.apiKey,onChange:Q=>Rt(Oe=>({...Oe,apiKey:Q.target.value})),onBlur:()=>void _t(),onKeyDown:Q=>Qe(Q,()=>void _t()),placeholder:"API key"}),f.jsx(Kn,{value:vt.model,onChange:Q=>Rt(Oe=>({...Oe,model:Q.target.value})),onBlur:()=>void _t(),onKeyDown:Q=>Qe(Q,()=>void _t()),placeholder:"Model id"})]})})]}):_==="keybindings"?f.jsxs("div",{className:"border-b border-border",children:[Ve?f.jsx("div",{className:"mb-4 rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-sm text-destructive",children:Ve}):null,te.warning?f.jsx("div",{className:"mb-4 rounded-lg border border-border bg-card/30 px-4 py-3 text-sm text-muted-foreground",children:te.warning}):null,OP.map((Q,Oe)=>{const xn=Q_(mp[Q]),co=tt[Q]??"",Wl=co!==xn;return f.jsx(Gn,{title:O4[Q],description:f.jsxs(f.Fragment,{children:[f.jsx("span",{children:"Comma-separated shortcuts."}),Wl?f.jsxs(f.Fragment,{children:[f.jsx("span",{children:" "}),f.jsxs("button",{type:"button",onClick:()=>{zi(Q)},className:"inline rounded text-foreground hover:text-foreground/80",children:["Restore: ",xn]})]}):null]}),bordered:Oe!==0,children:f.jsx("div",{className:"flex min-w-0 max-w-[420px] flex-1 flex-col items-stretch gap-2",children:f.jsx(Kn,{type:"text",value:co,onChange:is=>{const bf=is.target.value;Pe(Pa=>({...Pa,[Q]:bf}))},onBlur:()=>{ts()},onKeyDown:is=>Qe(is,()=>{ts()}),className:"font-mono"})})},Q)})]}):_==="skills"?f.jsx(F2e,{state:n}):f.jsx(D2e,{status:s,releases:h,error:b,onRetry:kn,updateSnapshot:Te,currentVersion:k,onInstallUpdate:()=>{n.handleInstallUpdate()},onCheckForUpdates:()=>{n.handleCheckForUpdates({force:!0})},onForceReload:()=>{n.handleForceReload()}})]}),n.commandError?f.jsxs("div",{className:"mx-auto mt-4 flex max-w-4xl items-start gap-3 rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-sm text-destructive",children:[f.jsx(MW,{className:"mt-0.5 h-4 w-4 flex-shrink-0"}),f.jsx("span",{children:n.commandError})]}):null]})]})]}),cr?f.jsx("div",{className:"absolute bottom-0 left-0 right-0 border-t border-border bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80",children:f.jsx("div",{className:"px-6 py-[14.25px]",children:f.jsxs("div",{className:"grid gap-3 text-xs text-muted-foreground grid-cols-2 lg:grid-cols-4",children:[f.jsxs("div",{children:[f.jsx("div",{className:"mb-1 uppercase tracking-wide text-[11px] text-muted-foreground/80",children:"Machine"}),f.jsx("div",{className:"text-foreground/80",children:C})]}),f.jsxs("div",{className:"hidden md:block",children:[f.jsx("div",{className:"mb-1 uppercase tracking-wide text-[11px] text-muted-foreground/80",children:"Connection"}),f.jsx("div",{className:"text-foreground/80",children:n.connectionStatus})]}),f.jsxs("div",{className:"hidden md:block",children:[f.jsx("div",{className:"mb-1 uppercase tracking-wide text-[11px] text-muted-foreground/80",children:"Projects Indexed"}),f.jsx("div",{className:"text-foreground/80",children:E})]}),f.jsxs("div",{children:[f.jsx("div",{className:"mb-1 uppercase tracking-wide text-[11px] text-muted-foreground/80",children:"App Version"}),f.jsx("div",{className:"text-foreground/80",children:k})]})]})})}):null,f.jsx(Rs,{open:gt,onOpenChange:ot,children:f.jsxs(Zi,{size:"lg",children:[f.jsxs(Io,{className:"space-y-4",children:[f.jsx(Ns,{children:"Tracked Events"}),f.jsx("div",{className:"text-sm text-muted-foreground",children:"Kanna sends these event names plus the limited property keys below, depending on the event type."}),f.jsxs("div",{className:"max-h-[60vh] overflow-auto rounded-lg border border-border bg-muted/40 p-3",children:[f.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Event Names"}),f.jsx("ul",{className:"mt-3 space-y-2 text-sm",children:ao.map(Q=>f.jsx("li",{className:"font-mono text-foreground",children:Q},Q))}),f.jsx("div",{className:"mt-6 text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Property Keys"}),f.jsx("ul",{className:"mt-3 space-y-2 text-sm",children:f2e.map(Q=>f.jsx("li",{className:"font-mono text-foreground",children:Q},Q))})]})]}),f.jsx(_a,{children:f.jsx(Ge,{variant:"secondary",size:"sm",onClick:()=>ot(!1),children:"Close"})})]})}),f.jsx(Rs,{open:Ie,onOpenChange:ze,children:f.jsxs(Zi,{size:"lg",children:[f.jsxs(Io,{className:"space-y-4",children:[f.jsx(Ns,{children:"Validation Error"}),f.jsx("pre",{className:"max-h-[60vh] overflow-auto rounded-lg border border-border bg-muted p-3 text-xs font-mono whitespace-pre-wrap break-words",children:je})]}),f.jsx(_a,{children:f.jsx(Ge,{variant:"secondary",size:"sm",onClick:()=>ze(!1),children:"Close"})})]})})]})}function FP(e){return{toggleEmbeddedTerminal:$s(e.toggleEmbeddedTerminal??""),toggleRightSidebar:$s(e.toggleRightSidebar??""),openInFinder:$s(e.openInFinder??""),openInEditor:$s(e.openInEditor??""),addSplitTerminal:$s(e.addSplitTerminal??""),jumpToSidebarChat:$s(e.jumpToSidebarChat??""),createChatInCurrentProject:$s(e.createChatInCurrentProject??""),openAddProject:$s(e.openAddProject??""),newStack:$s(e.newStack??""),newStackChat:$s(e.newStackChat??""),jumpToStacks:$s(e.jumpToStacks??"")}}const $P="kanna:last-seen-version",HP=500;function U2e(e){return!e.enabled||e.authenticated?{status:"ready"}:{status:"locked",error:null}}function V2e(e){return e!==!0}function W2e({error:e,onSubmit:t}){const[n,r]=v.useState(""),[i,s]=v.useState(!1);async function o(l){if(l.preventDefault(),!(!n||i)){s(!0);try{await t(n),r("")}finally{s(!1)}}}return f.jsx("div",{className:"flex min-h-[100dvh] items-center justify-center bg-background px-6 py-10",children:f.jsxs(wk,{className:"w-full max-w-md rounded-3xl border border-border bg-card shadow-sm",children:[f.jsxs(Sk,{className:"flex flex-col p-2 space-y-3 px-6 pt-6 pb-5 pl-[28px]",children:[f.jsxs("div",{className:"flex items-center gap-3",children:[f.jsx(hd,{className:"h-5 w-5 text-logo"}),f.jsx("div",{children:f.jsx(l3,{className:"font-logo text-xl uppercase text-foreground",children:or})})]}),f.jsx(c3,{className:"leading-6",children:"Enter your password to continue."})]}),f.jsx(Ck,{className:"px-6 pb-6",children:f.jsxs("form",{className:"space-y-4",onSubmit:l=>void o(l),children:[e?f.jsx("div",{className:"rounded-2xl border border-destructive/20 bg-destructive/10 px-4 py-3 text-sm text-foreground",children:e}):null,f.jsx(Kn,{id:"kanna-password",type:"password",autoComplete:"current-password",value:n,onChange:l=>r(l.target.value),placeholder:"Password",disabled:i,className:"h-11 rounded-2xl bg-background"}),f.jsx(Ge,{type:"submit",disabled:i||n.length===0,className:"h-11 w-full",children:i?"Unlocking...":"Unlock"})]})})]})})}function G2e(){const[e,t]=v.useState({status:"checking"}),n=v.useRef(null),r=v.useRef(async()=>{}),i=v.useCallback(async()=>{n.current!==null&&(window.clearTimeout(n.current),n.current=null),t(c=>c.status==="ready"?c:{status:"checking"});let o;try{o=await fetch("/auth/status",{method:"GET",cache:"no-store",headers:{Accept:"application/json"}})}catch{n.current=window.setTimeout(()=>{r.current()},HP);return}if(V2e(o.ok)){n.current=window.setTimeout(()=>{r.current()},HP);return}const l=await o.json();t(U2e(l))},[]);v.useLayoutEffect(()=>{r.current=i}),v.useEffect(()=>(i(),()=>{n.current!==null&&window.clearTimeout(n.current)}),[i]);const s=v.useCallback(async o=>{if(!(await fetch("/auth/login",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({password:o,next:window.location.pathname+window.location.search})})).ok){t({status:"locked",error:"Incorrect password. Try again."});return}await i()},[i]);return{state:e,submitPassword:s}}function q2e(e,t,n){return e==="/"&&!!t&&n!==t}function K2e(e,t,n=document){return!!e&&YQ(t,n)}function Y2e(){var de,he,Le;const e=ro(),t=Wd(),n=o5(),r=r0e(n.chatId??null),i=Kp(),s=Ec(ce=>ce.chatSoundPreference),o=Ec(ce=>ce.chatSoundId),l=e.pathname==="/",c=kk.split("/")[1]??"unknown",u=v.useRef(null),{handleCreateChat:p,handleForkChat:h,handleRenameChat:g,handleShareChat:b,handleArchiveChat:x,handleOpenArchivedChat:_,openAddProjectModal:w,handleDeleteChat:C,handleCopyPath:E,handleOpenExternalPath:k,handleHideProject:R,handleToggleProjectStar:N,handleReorderProjectGroups:A,importClaudeSessions:M}=r,D=v.useCallback(ce=>{p(ce)},[p]),U=v.useCallback(ce=>{h(ce)},[h]),j=v.useCallback(ce=>{g(ce)},[g]),P=v.useCallback(ce=>{b(ce)},[b]),z=v.useCallback(ce=>{x(ce)},[x]),O=v.useCallback(ce=>{_(ce)},[_]),$=v.useCallback(()=>{w()},[w]),V=v.useCallback(ce=>{C(ce)},[C]),B=v.useCallback(ce=>{E(ce)},[E]),F=v.useCallback((ce,De)=>{k(ce,De)},[k]),W=v.useCallback(ce=>{R(ce)},[R]),X=v.useCallback((ce,De)=>{N(ce,De)},[N]),I=v.useCallback(ce=>{A(ce)},[A]),G=v.useCallback(async()=>{try{const ce=await M(),De=[`Imported ${ce.imported}`,`updated ${ce.updated}`,`skipped ${ce.skipped}`,`failed ${ce.failed}`],pe=ce.newProjects>0?` (${ce.newProjects} new projects)`:"";await i.alert({title:"Import complete",description:`${De.join(", ")}.${pe}`})}catch(ce){console.error("[kanna/import] failed",ce),await i.alert({title:"Import failed",description:"See console for details."})}},[i,M]),[ee,H]=v.useState(null),ue=v.useCallback(ce=>{H(ce),r.activeChatId!==ce&&t(`/chat/${ce}`)},[t,r.activeChatId]),ae=((de=r.chatSnapshot)==null?void 0:de.runtime.title)??"Chat",J=((he=r.chatSnapshot)==null?void 0:he.runtime.policyOverride)??null,te=v.useMemo(()=>f.jsx(pne,{data:r.sidebarData,activeChatId:r.activeChatId,connectionStatus:r.connectionStatus,ready:r.sidebarReady,open:r.sidebarOpen,collapsed:r.sidebarCollapsed,showMobileOpenButton:l,onOpen:r.openSidebar,onClose:r.closeSidebar,onCollapse:r.collapseSidebar,onExpand:r.expandSidebar,onCreateChat:D,onForkChat:U,currentProjectId:r.activeProjectId,keybindings:r.keybindings,onRenameChat:j,onShareChat:P,onArchiveChat:z,onOpenArchivedChat:O,onDeleteChat:V,onEditChatPermissions:ue,onOpenAddProjectModal:$,onImportClaudeSessions:G,onCopyPath:B,onOpenExternalPath:F,onHideProject:W,onToggleStar:X,onReorderProjectGroups:I,onCreateStack:r.handleCreateStack,onRenameStack:r.handleRenameStack,onRemoveStack:r.handleRemoveStack,onCreateStackChat:r.handleCreateStackChat,onListStackWorktrees:r.handleListStackWorktrees,editorLabel:r.editorLabel,updateSnapshot:r.updateSnapshot}),[$,G,B,D,z,V,O,U,F,j,P,ue,I,W,X,l,r.activeChatId,r.activeProjectId,r.keybindings,r.closeSidebar,r.collapseSidebar,r.connectionStatus,r.editorLabel,r.expandSidebar,r.openSidebar,r.sidebarCollapsed,r.sidebarData,r.sidebarOpen,r.sidebarReady,r.updateSnapshot,r.handleCreateStack,r.handleRenameStack,r.handleRemoveStack,r.handleCreateStackChat,r.handleListStackWorktrees]);v.useEffect(()=>{const ce=window.localStorage.getItem($P),De=q2e(e.pathname,c,ce);window.localStorage.setItem($P,c),De&&t("/settings/changelog",{replace:!0})},[c,e.pathname,t]),v.useLayoutEffect(()=>{document.title=or},[e.key]),v.useEffect(()=>{function ce(){document.title=or}function De(){document.title=or}return window.addEventListener("pageshow",ce),window.addEventListener("pagehide",De),()=>{window.removeEventListener("pageshow",ce),window.removeEventListener("pagehide",De)}},[]),v.useEffect(()=>{const ce=XQ(r.sidebarData);document.title=ce>0?`[${ce}] ${or}`:or},[r.sidebarData]),v.useEffect(()=>{const ce=QQ(u.current,r.sidebarData);u.current=r.sidebarData,!(ce<=0)&&K2e(r.appSettings,s)&&DS(o,ce).catch(()=>{})},[o,s,r.appSettings,r.sidebarData]);const ie=((Le=r.appSettings)==null?void 0:Le.claudeDriver.preference)==="pty";return f.jsxs("div",{className:"flex h-[100dvh] min-h-[100dvh] overflow-hidden",children:[te,f.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[ie?f.jsxs("div",{role:"status",className:"flex items-center justify-center gap-2 border-b border-warning/40 bg-warning/10 px-3 py-1.5 text-xs text-warning-foreground",children:[f.jsx("span",{className:"font-medium",children:"PTY driver active."}),f.jsx("span",{className:"text-warning-foreground/80",children:"Tools run under the `claude` CLI with subscription billing. Use a worktree for risky tasks."})]}):null,f.jsx(c9,{context:r})]}),f.jsx(xQ,{open:!!r.standaloneShareUrl,shareUrl:r.standaloneShareUrl??"",onOpenChange:ce=>{ce||r.handleCloseStandaloneShareDialog()},onOpenLink:r.handleOpenStandaloneShareLink,onCopyLink:r.handleCopyStandaloneShareLink}),f.jsx(bQ,{open:ee!=null&&ee===r.activeChatId,chatTitle:ae,baseline:_Q,current:J,onCancel:()=>H(null),onApply:ce=>{ee&&(r.handleSetChatPolicyOverride(ee,ce).catch(()=>{}),H(null))}})]})}function X2e(){const e=G2e();return e.state.status==="checking"?f.jsx("div",{className:"flex min-h-[100dvh] items-center justify-center bg-background text-sm text-muted-foreground",children:"Checking session…"}):e.state.status==="locked"?f.jsx(W2e,{error:e.state.error,onSubmit:e.submitPassword}):f.jsx(My,{children:f.jsxs(wQ,{children:[f.jsx(d9,{children:f.jsxs(rd,{element:f.jsx(Y2e,{}),children:[f.jsx(rd,{path:"/",element:f.jsx(u2e,{})}),f.jsx(rd,{path:"/settings",element:f.jsx(l9,{to:"/settings/general",replace:!0})}),f.jsx(rd,{path:"/settings/:sectionId",element:f.jsx(H2e,{})}),f.jsx(rd,{path:"/chat/:chatId",element:f.jsx(i2e,{})})]})}),f.jsx(TQ,{})]})})}const i7=document.getElementById("root");if(!i7)throw new Error("Missing #root");dU.createRoot(i7).render(f.jsx(v.StrictMode,{children:f.jsx(I9,{children:f.jsx(Wbe,{children:f.jsx(X2e,{})})})}));export{_n as R,W9 as a};