@clawos-dev/clawd 0.2.716 → 0.2.718
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.
|
@@ -533,7 +533,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
533
533
|
`)},zk=function(){var e=parseInt(document.body.getAttribute(Xa)||"0",10);return isFinite(e)?e:0},Rq=function(){g.useEffect(function(){return document.body.setAttribute(Xa,(zk()+1).toString()),function(){var e=zk()-1;e<=0?document.body.removeAttribute(Xa):document.body.setAttribute(Xa,e.toString())}},[])},Mq=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,i=r===void 0?"margin":r;Rq();var s=g.useMemo(function(){return Nq(i)},[i]);return g.createElement(Tq,{styles:Pq(s,!t,i,n?"":"!important")})},wx=!1;if(typeof window<"u")try{var Qd=Object.defineProperty({},"passive",{get:function(){return wx=!0,!0}});window.addEventListener("test",Qd,Qd),window.removeEventListener("test",Qd,Qd)}catch{wx=!1}var ma=wx?{passive:!1}:!1,Aq=function(e){return e.tagName==="TEXTAREA"},k3=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Aq(e)&&n[t]==="visible")},jq=function(e){return k3(e,"overflowY")},Lq=function(e){return k3(e,"overflowX")},Fk=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var i=C3(e,r);if(i){var s=E3(e,r),o=s[1],a=s[2];if(o>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Dq=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Oq=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},C3=function(e,t){return e==="v"?jq(t):Lq(t)},E3=function(e,t){return e==="v"?Dq(t):Oq(t)},Bq=function(e,t){return e==="h"&&t==="rtl"?-1:1},$q=function(e,t,n,r,i){var s=Bq(e,window.getComputedStyle(t).direction),o=s*r,a=n.target,l=t.contains(a),c=!1,u=o>0,d=0,f=0;do{if(!a)break;var p=E3(e,a),m=p[0],v=p[1],w=p[2],x=v-w-s*m;(m||x)&&C3(e,a)&&(d+=x,f+=m);var _=a.parentNode;a=_&&_.nodeType===Node.DOCUMENT_FRAGMENT_NODE?_.host:_}while(!l&&a!==document.body||l&&(t.contains(a)||t===a));return(u&&Math.abs(d)<1||!u&&Math.abs(f)<1)&&(c=!0),c},Jd=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Hk=function(e){return[e.deltaX,e.deltaY]},Uk=function(e){return e&&"current"in e?e.current:e},zq=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Fq=function(e){return`
|
|
534
534
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
535
535
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
536
|
-
`)},Hq=0,ga=[];function Uq(e){var t=g.useRef([]),n=g.useRef([0,0]),r=g.useRef(),i=g.useState(Hq++)[0],s=g.useState(S3)[0],o=g.useRef(e);g.useEffect(function(){o.current=e},[e]),g.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(i));var v=uq([e.lockRef.current],(e.shards||[]).map(Uk),!0).filter(Boolean);return v.forEach(function(w){return w.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),v.forEach(function(w){return w.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var a=g.useCallback(function(v,w){if("touches"in v&&v.touches.length===2||v.type==="wheel"&&v.ctrlKey)return!o.current.allowPinchZoom;var x=Jd(v),_=n.current,b="deltaX"in v?v.deltaX:_[0]-x[0],S="deltaY"in v?v.deltaY:_[1]-x[1],C,k=v.target,N=Math.abs(b)>Math.abs(S)?"h":"v";if("touches"in v&&N==="h"&&k.type==="range")return!1;var E=window.getSelection(),j=E&&E.anchorNode,P=j?j===k||j.contains(k):!1;if(P)return!1;var L=Fk(N,k);if(!L)return!0;if(L?C=N:(C=N==="v"?"h":"v",L=Fk(N,k)),!L)return!1;if(!r.current&&"changedTouches"in v&&(b||S)&&(r.current=C),!C)return!0;var M=r.current||C;return $q(M,w,v,M==="h"?b:S)},[]),l=g.useCallback(function(v){var w=v;if(!(!ga.length||ga[ga.length-1]!==s)){var x="deltaY"in w?Hk(w):Jd(w),_=t.current.filter(function(C){return C.name===w.type&&(C.target===w.target||w.target===C.shadowParent)&&zq(C.delta,x)})[0];if(_&&_.should){w.cancelable&&w.preventDefault();return}if(!_){var b=(o.current.shards||[]).map(Uk).filter(Boolean).filter(function(C){return C.contains(w.target)}),S=b.length>0?a(w,b[0]):!o.current.noIsolation;S&&w.cancelable&&w.preventDefault()}}},[]),c=g.useCallback(function(v,w,x,_){var b={name:v,delta:w,target:x,should:_,shadowParent:Wq(x)};t.current.push(b),setTimeout(function(){t.current=t.current.filter(function(S){return S!==b})},1)},[]),u=g.useCallback(function(v){n.current=Jd(v),r.current=void 0},[]),d=g.useCallback(function(v){c(v.type,Hk(v),v.target,a(v,e.lockRef.current))},[]),f=g.useCallback(function(v){c(v.type,Jd(v),v.target,a(v,e.lockRef.current))},[]);g.useEffect(function(){return ga.push(s),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:f}),document.addEventListener("wheel",l,ma),document.addEventListener("touchmove",l,ma),document.addEventListener("touchstart",u,ma),function(){ga=ga.filter(function(v){return v!==s}),document.removeEventListener("wheel",l,ma),document.removeEventListener("touchmove",l,ma),document.removeEventListener("touchstart",u,ma)}},[]);var p=e.removeScrollBar,m=e.inert;return g.createElement(g.Fragment,null,m?g.createElement(s,{styles:Fq(i)}):null,p?g.createElement(Mq,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Wq(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const qq=yq(w3,Uq);var fm=g.forwardRef(function(e,t){return g.createElement(hm,pi({},e,{ref:t,sideCar:qq}))});fm.classNames=hm.classNames;var Sx=["Enter"," "],Vq=["ArrowDown","PageUp","Home"],I3=["ArrowUp","PageDown","End"],Kq=[...Vq,...I3],Gq={ltr:[...Sx,"ArrowRight"],rtl:[...Sx,"ArrowLeft"]},Yq={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Qu="Menu",[Iu,Xq,Zq]=F4(Qu),[ta,N3]=io(Qu,[Zq,Hl,p3]),Ju=Hl(),T3=p3(),[P3,so]=ta(Qu),[Qq,ed]=ta(Qu),R3=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,a=Ju(t),[l,c]=g.useState(null),u=g.useRef(!1),d=Ei(s),f=H4(i);return g.useEffect(()=>{const p=()=>{u.current=!0,document.addEventListener("pointerdown",m,{capture:!0,once:!0}),document.addEventListener("pointermove",m,{capture:!0,once:!0})},m=()=>u.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",m,{capture:!0}),document.removeEventListener("pointermove",m,{capture:!0})}},[]),h.jsx(cm,{...a,children:h.jsx(P3,{scope:t,open:n,onOpenChange:d,content:l,onContentChange:c,children:h.jsx(Qq,{scope:t,onClose:g.useCallback(()=>d(!1),[d]),isUsingKeyboardRef:u,dir:f,modal:o,children:r})})})};R3.displayName=Qu;var Jq="MenuAnchor",w_=g.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Ju(n);return h.jsx(um,{...i,...r,ref:t})});w_.displayName=Jq;var S_="MenuPortal",[eV,M3]=ta(S_,{forceMount:void 0}),A3=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=so(S_,t);return h.jsx(eV,{scope:t,forceMount:n,children:h.jsx(Jr,{present:n||s.open,children:h.jsx(dm,{asChild:!0,container:i,children:r})})})};A3.displayName=S_;var Pr="MenuContent",[tV,k_]=ta(Pr),j3=g.forwardRef((e,t)=>{const n=M3(Pr,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=so(Pr,e.__scopeMenu),o=ed(Pr,e.__scopeMenu);return h.jsx(Iu.Provider,{scope:e.__scopeMenu,children:h.jsx(Jr,{present:r||s.open,children:h.jsx(Iu.Slot,{scope:e.__scopeMenu,children:o.modal?h.jsx(nV,{...i,ref:t}):h.jsx(rV,{...i,ref:t})})})})}),nV=g.forwardRef((e,t)=>{const n=so(Pr,e.__scopeMenu),r=g.useRef(null),i=Ot(t,r);return g.useEffect(()=>{const s=r.current;if(s)return b_(s)},[]),h.jsx(C_,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:Ne(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),rV=g.forwardRef((e,t)=>{const n=so(Pr,e.__scopeMenu);return h.jsx(C_,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),iV=pl("MenuContent.ScrollLock"),C_=g.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,onDismiss:p,disableOutsideScroll:m,...v}=e,w=so(Pr,n),x=ed(Pr,n),_=Ju(n),b=T3(n),S=Xq(n),[C,k]=g.useState(null),N=g.useRef(null),E=Ot(t,N,w.onContentChange),j=g.useRef(0),P=g.useRef(""),L=g.useRef(0),M=g.useRef(null),R=g.useRef("right"),A=g.useRef(0),D=m?fm:g.Fragment,z=m?{as:iV,allowPinchZoom:!0}:void 0,F=O=>{var re,ke;const I=P.current+O,U=S().filter(oe=>!oe.disabled),q=document.activeElement,B=(re=U.find(oe=>oe.ref.current===q))==null?void 0:re.textValue,te=U.map(oe=>oe.textValue),le=gV(te,I,B),Y=(ke=U.find(oe=>oe.textValue===le))==null?void 0:ke.ref.current;(function oe(Ie){P.current=Ie,window.clearTimeout(j.current),Ie!==""&&(j.current=window.setTimeout(()=>oe(""),1e3))})(I),Y&&setTimeout(()=>Y.focus())};g.useEffect(()=>()=>window.clearTimeout(j.current),[]),u_();const $=g.useCallback(O=>{var U,q;return R.current===((U=M.current)==null?void 0:U.side)&&xV(O,(q=M.current)==null?void 0:q.area)},[]);return h.jsx(tV,{scope:n,searchRef:P,onItemEnter:g.useCallback(O=>{$(O)&&O.preventDefault()},[$]),onItemLeave:g.useCallback(O=>{var I;$(O)||((I=N.current)==null||I.focus(),k(null))},[$]),onTriggerLeave:g.useCallback(O=>{$(O)&&O.preventDefault()},[$]),pointerGraceTimerRef:L,onPointerGraceIntentChange:g.useCallback(O=>{M.current=O},[]),children:h.jsx(D,{...z,children:h.jsx(im,{asChild:!0,trapped:i,onMountAutoFocus:Ne(s,O=>{var I;O.preventDefault(),(I=N.current)==null||I.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:h.jsx(Yu,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,onDismiss:p,children:h.jsx(sq,{asChild:!0,...b,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:k,onEntryFocus:Ne(l,O=>{x.isUsingKeyboardRef.current||O.preventDefault()}),preventScrollOnEntryFocus:!0,children:h.jsx(y_,{role:"menu","aria-orientation":"vertical","data-state":Z3(w.open),"data-radix-menu-content":"",dir:x.dir,..._,...v,ref:E,style:{outline:"none",...v.style},onKeyDown:Ne(v.onKeyDown,O=>{const U=O.target.closest("[data-radix-menu-content]")===O.currentTarget,q=O.ctrlKey||O.altKey||O.metaKey,B=O.key.length===1;U&&(O.key==="Tab"&&O.preventDefault(),!q&&B&&F(O.key));const te=N.current;if(O.target!==te||!Kq.includes(O.key))return;O.preventDefault();const Y=S().filter(re=>!re.disabled).map(re=>re.ref.current);I3.includes(O.key)&&Y.reverse(),pV(Y)}),onBlur:Ne(e.onBlur,O=>{O.currentTarget.contains(O.target)||(window.clearTimeout(j.current),P.current="")}),onPointerMove:Ne(e.onPointerMove,Nu(O=>{const I=O.target,U=A.current!==O.clientX;if(O.currentTarget.contains(I)&&U){const q=O.clientX>A.current?"right":"left";R.current=q,A.current=O.clientX}}))})})})})})})});j3.displayName=Pr;var sV="MenuGroup",E_=g.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return h.jsx(wt.div,{role:"group",...r,ref:t})});E_.displayName=sV;var oV="MenuLabel",L3=g.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return h.jsx(wt.div,{...r,ref:t})});L3.displayName=oV;var Xf="MenuItem",Wk="menu.itemSelect",pm=g.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=g.useRef(null),o=ed(Xf,e.__scopeMenu),a=k_(Xf,e.__scopeMenu),l=Ot(t,s),c=g.useRef(!1),u=()=>{const d=s.current;if(!n&&d){const f=new CustomEvent(Wk,{bubbles:!0,cancelable:!0});d.addEventListener(Wk,p=>r==null?void 0:r(p),{once:!0}),z4(d,f),f.defaultPrevented?c.current=!1:o.onClose()}};return h.jsx(D3,{...i,ref:l,disabled:n,onClick:Ne(e.onClick,u),onPointerDown:d=>{var f;(f=e.onPointerDown)==null||f.call(e,d),c.current=!0},onPointerUp:Ne(e.onPointerUp,d=>{var f;c.current||(f=d.currentTarget)==null||f.click()}),onKeyDown:Ne(e.onKeyDown,d=>{const f=a.searchRef.current!=="";n||f&&d.key===" "||Sx.includes(d.key)&&(d.currentTarget.click(),d.preventDefault())})})});pm.displayName=Xf;var D3=g.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=k_(Xf,n),a=T3(n),l=g.useRef(null),c=Ot(t,l),[u,d]=g.useState(!1),[f,p]=g.useState("");return g.useEffect(()=>{const m=l.current;m&&p((m.textContent??"").trim())},[s.children]),h.jsx(Iu.ItemSlot,{scope:n,disabled:r,textValue:i??f,children:h.jsx(oq,{asChild:!0,...a,focusable:!r,children:h.jsx(wt.div,{role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:Ne(e.onPointerMove,Nu(m=>{r?o.onItemLeave(m):(o.onItemEnter(m),m.defaultPrevented||m.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Ne(e.onPointerLeave,Nu(m=>o.onItemLeave(m))),onFocus:Ne(e.onFocus,()=>d(!0)),onBlur:Ne(e.onBlur,()=>d(!1))})})})}),aV="MenuCheckboxItem",O3=g.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return h.jsx(H3,{scope:e.__scopeMenu,checked:n,children:h.jsx(pm,{role:"menuitemcheckbox","aria-checked":Zf(n)?"mixed":n,...i,ref:t,"data-state":T_(n),onSelect:Ne(i.onSelect,()=>r==null?void 0:r(Zf(n)?!0:!n),{checkForDefaultPrevented:!1})})})});O3.displayName=aV;var B3="MenuRadioGroup",[lV,cV]=ta(B3,{value:void 0,onValueChange:()=>{}}),$3=g.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=Ei(r);return h.jsx(lV,{scope:e.__scopeMenu,value:n,onValueChange:s,children:h.jsx(E_,{...i,ref:t})})});$3.displayName=B3;var z3="MenuRadioItem",F3=g.forwardRef((e,t)=>{const{value:n,...r}=e,i=cV(z3,e.__scopeMenu),s=n===i.value;return h.jsx(H3,{scope:e.__scopeMenu,checked:s,children:h.jsx(pm,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":T_(s),onSelect:Ne(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});F3.displayName=z3;var I_="MenuItemIndicator",[H3,uV]=ta(I_,{checked:!1}),U3=g.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=uV(I_,n);return h.jsx(Jr,{present:r||Zf(s.checked)||s.checked===!0,children:h.jsx(wt.span,{...i,ref:t,"data-state":T_(s.checked)})})});U3.displayName=I_;var dV="MenuSeparator",W3=g.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return h.jsx(wt.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});W3.displayName=dV;var hV="MenuArrow",q3=g.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Ju(n);return h.jsx(__,{...i,...r,ref:t})});q3.displayName=hV;var N_="MenuSub",[fV,V3]=ta(N_),K3=e=>{const{__scopeMenu:t,children:n,open:r=!1,onOpenChange:i}=e,s=so(N_,t),o=Ju(t),[a,l]=g.useState(null),[c,u]=g.useState(null),d=Ei(i);return g.useEffect(()=>(s.open===!1&&d(!1),()=>d(!1)),[s.open,d]),h.jsx(cm,{...o,children:h.jsx(P3,{scope:t,open:r,onOpenChange:d,content:c,onContentChange:u,children:h.jsx(fV,{scope:t,contentId:bi(),triggerId:bi(),trigger:a,onTriggerChange:l,children:n})})})};K3.displayName=N_;var kc="MenuSubTrigger",G3=g.forwardRef((e,t)=>{const n=so(kc,e.__scopeMenu),r=ed(kc,e.__scopeMenu),i=V3(kc,e.__scopeMenu),s=k_(kc,e.__scopeMenu),o=g.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},u=g.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return g.useEffect(()=>u,[u]),g.useEffect(()=>{const d=a.current;return()=>{window.clearTimeout(d),l(null)}},[a,l]),h.jsx(w_,{asChild:!0,...c,children:h.jsx(D3,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":Z3(n.open),...e,ref:Gu(t,i.onTriggerChange),onClick:d=>{var f;(f=e.onClick)==null||f.call(e,d),!(e.disabled||d.defaultPrevented)&&(d.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:Ne(e.onPointerMove,Nu(d=>{s.onItemEnter(d),!d.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),u()},100))})),onPointerLeave:Ne(e.onPointerLeave,Nu(d=>{var p,m;u();const f=(p=n.content)==null?void 0:p.getBoundingClientRect();if(f){const v=(m=n.content)==null?void 0:m.dataset.side,w=v==="right",x=w?-5:5,_=f[w?"left":"right"],b=f[w?"right":"left"];s.onPointerGraceIntentChange({area:[{x:d.clientX+x,y:d.clientY},{x:_,y:f.top},{x:b,y:f.top},{x:b,y:f.bottom},{x:_,y:f.bottom}],side:v}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(d),d.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:Ne(e.onKeyDown,d=>{var p;const f=s.searchRef.current!=="";e.disabled||f&&d.key===" "||Gq[r.dir].includes(d.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),d.preventDefault())})})})});G3.displayName=kc;var Y3="MenuSubContent",X3=g.forwardRef((e,t)=>{const n=M3(Pr,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=so(Pr,e.__scopeMenu),o=ed(Pr,e.__scopeMenu),a=V3(Y3,e.__scopeMenu),l=g.useRef(null),c=Ot(t,l);return h.jsx(Iu.Provider,{scope:e.__scopeMenu,children:h.jsx(Jr,{present:r||s.open,children:h.jsx(Iu.Slot,{scope:e.__scopeMenu,children:h.jsx(C_,{id:a.contentId,"aria-labelledby":a.triggerId,...i,ref:c,align:"start",side:o.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:u=>{var d;o.isUsingKeyboardRef.current&&((d=l.current)==null||d.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:Ne(e.onFocusOutside,u=>{u.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:Ne(e.onEscapeKeyDown,u=>{o.onClose(),u.preventDefault()}),onKeyDown:Ne(e.onKeyDown,u=>{var p;const d=u.currentTarget.contains(u.target),f=Yq[o.dir].includes(u.key);d&&f&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),u.preventDefault())})})})})})});X3.displayName=Y3;function Z3(e){return e?"open":"closed"}function Zf(e){return e==="indeterminate"}function T_(e){return Zf(e)?"indeterminate":e?"checked":"unchecked"}function pV(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function mV(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function gV(e,t,n){const i=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let o=mV(e,Math.max(s,0));i.length===1&&(o=o.filter(c=>c!==n));const l=o.find(c=>c.toLowerCase().startsWith(i.toLowerCase()));return l!==n?l:void 0}function vV(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 a=t[s],l=t[o],c=a.x,u=a.y,d=l.x,f=l.y;u>r!=f>r&&n<(d-c)*(r-u)/(f-u)+c&&(i=!i)}return i}function xV(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return vV(n,t)}function Nu(e){return t=>t.pointerType==="mouse"?e(t):void 0}var yV=R3,_V=w_,bV=A3,wV=j3,SV=E_,kV=L3,CV=pm,EV=O3,IV=$3,NV=F3,TV=U3,PV=W3,RV=q3,MV=K3,AV=G3,jV=X3,mm="DropdownMenu",[LV]=io(mm,[N3]),Rn=N3(),[DV,Q3]=LV(mm),J3=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:a=!0}=e,l=Rn(t),c=g.useRef(null),[u,d]=$l({prop:i,defaultProp:s??!1,onChange:o,caller:mm});return h.jsx(DV,{scope:t,triggerId:bi(),triggerRef:c,contentId:bi(),open:u,onOpenChange:d,onOpenToggle:g.useCallback(()=>d(f=>!f),[d]),modal:a,children:h.jsx(yV,{...l,open:u,onOpenChange:d,dir:r,modal:a,children:n})})};J3.displayName=mm;var eP="DropdownMenuTrigger",tP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=Q3(eP,n),o=Rn(n);return h.jsx(_V,{asChild:!0,...o,children:h.jsx(wt.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...i,ref:Gu(t,s.triggerRef),onPointerDown:Ne(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:Ne(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});tP.displayName=eP;var OV="DropdownMenuPortal",nP=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Rn(t);return h.jsx(bV,{...r,...n})};nP.displayName=OV;var rP="DropdownMenuContent",iP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Q3(rP,n),s=Rn(n),o=g.useRef(!1);return h.jsx(wV,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:Ne(e.onCloseAutoFocus,a=>{var l;o.current||(l=i.triggerRef.current)==null||l.focus(),o.current=!1,a.preventDefault()}),onInteractOutside:Ne(e.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,u=l.button===2||c;(!i.modal||u)&&(o.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});iP.displayName=rP;var BV="DropdownMenuGroup",$V=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Rn(n);return h.jsx(SV,{...i,...r,ref:t})});$V.displayName=BV;var zV="DropdownMenuLabel",sP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Rn(n);return h.jsx(kV,{...i,...r,ref:t})});sP.displayName=zV;var FV="DropdownMenuItem",oP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Rn(n);return h.jsx(CV,{...i,...r,ref:t})});oP.displayName=FV;var HV="DropdownMenuCheckboxItem",aP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Rn(n);return h.jsx(EV,{...i,...r,ref:t})});aP.displayName=HV;var UV="DropdownMenuRadioGroup",WV=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Rn(n);return h.jsx(IV,{...i,...r,ref:t})});WV.displayName=UV;var qV="DropdownMenuRadioItem",VV=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Rn(n);return h.jsx(NV,{...i,...r,ref:t})});VV.displayName=qV;var KV="DropdownMenuItemIndicator",lP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Rn(n);return h.jsx(TV,{...i,...r,ref:t})});lP.displayName=KV;var GV="DropdownMenuSeparator",cP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Rn(n);return h.jsx(PV,{...i,...r,ref:t})});cP.displayName=GV;var YV="DropdownMenuArrow",XV=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Rn(n);return h.jsx(RV,{...i,...r,ref:t})});XV.displayName=YV;var ZV=e=>{const{__scopeDropdownMenu:t,children:n,open:r,onOpenChange:i,defaultOpen:s}=e,o=Rn(t),[a,l]=$l({prop:r,defaultProp:s??!1,onChange:i,caller:"DropdownMenuSub"});return h.jsx(MV,{...o,open:a,onOpenChange:l,children:n})},QV="DropdownMenuSubTrigger",uP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Rn(n);return h.jsx(AV,{...i,...r,ref:t})});uP.displayName=QV;var JV="DropdownMenuSubContent",dP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Rn(n);return h.jsx(jV,{...i,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});dP.displayName=JV;var eK=J3,tK=tP,hP=nP,fP=iP,pP=sP,mP=oP,gP=aP,nK=lP,vP=cP,rK=ZV,xP=uP,yP=dP;const P_=eK,R_=tK,gm=g.forwardRef(({className:e,sideOffset:t=4,...n},r)=>h.jsx(hP,{children:h.jsx(fP,{ref:r,sideOffset:t,className:ie("z-50 min-w-[8rem] overflow-hidden rounded-md border border-border bg-elevated p-1","text-text-100 shadow-md",e),...n})}));gm.displayName=fP.displayName;const _P=rK,M_=g.forwardRef(({className:e,...t},n)=>h.jsx(xP,{ref:n,className:ie("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none","focus:bg-bg-200 focus:text-text-100 data-[highlighted]:bg-bg-200 data-[highlighted]:text-text-100 data-[state=open]:bg-bg-200","data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...t}));M_.displayName=xP.displayName;const A_=g.forwardRef(({className:e,...t},n)=>h.jsx(hP,{children:h.jsx(yP,{ref:n,className:ie("z-50 min-w-[6rem] overflow-hidden rounded-md border border-border bg-elevated p-1","text-text-100 shadow-md",e),...t})}));A_.displayName=yP.displayName;const Ir=g.forwardRef(({className:e,inset:t,...n},r)=>h.jsx(mP,{ref:r,className:ie("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none","focus:bg-bg-200 focus:text-text-100 data-[highlighted]:bg-bg-200 data-[highlighted]:text-text-100","data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));Ir.displayName=mP.displayName;const iK=g.forwardRef(({className:e,children:t,checked:n,...r},i)=>h.jsxs(gP,{ref:i,checked:n,className:ie("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-7 pr-2 text-sm outline-none","focus:bg-bg-200 focus:text-text-100 data-[highlighted]:bg-bg-200 data-[highlighted]:text-text-100","data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...r,children:[h.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:h.jsx(nK,{children:h.jsx(no,{className:"h-3.5 w-3.5"})})}),t]}));iK.displayName=gP.displayName;const vm=g.forwardRef(({className:e,...t},n)=>h.jsx(vP,{ref:n,className:ie("-mx-1 my-1 h-px bg-border",e),...t}));vm.displayName=vP.displayName;const j_=g.forwardRef(({className:e,...t},n)=>h.jsx(pP,{ref:n,className:ie("px-2 py-1.5 text-xs font-semibold text-text-400",e),...t}));j_.displayName=pP.displayName;function sK({tool:e,className:t}){const n=QH(e);return h.jsx("span",{"data-testid":n?`session-icon-${e}`:"session-icon-default","aria-label":n?l_(e):"未知引擎",className:ie("w-3.5 h-3.5 shrink-0 inline-flex items-center justify-center",rm(e),t),children:h.jsx(nm,{tool:e,className:"w-full h-full"})})}function oK({sessionId:e,hasUnread:t,running:n=!1,awaitingUser:r=!1,style:i}){return r?h.jsx(g7,{"data-testid":`awaiting-dot-${e}`,style:i,className:"w-3 h-3 text-warning shrink-0 animate-pulse",strokeWidth:2.25,"aria-label":"awaiting user"}):t?h.jsx("span",{"data-testid":`unread-dot-${e}`,style:i,className:"w-2 h-2 rounded-full bg-error shrink-0","aria-label":"unread"}):n?h.jsx("span",{"data-testid":`running-dot-${e}`,style:i,className:"w-2 h-2 rounded-full bg-success shrink-0 animate-pulse","aria-label":"running"}):null}function bP(e){return e.compositionActive||!!e.nativeIsComposing||e.keyCode===229}function wP(e){return e.key==="Enter"&&!e.shiftKey&&!bP(e)}function td(e,t){const n=g.useRef(!1),r=g.useCallback(()=>{n.current=!0},[]),i=g.useCallback(()=>{setTimeout(()=>{n.current=!1},0)},[]);return{onKeyDown:g.useCallback(o=>{const a=o.nativeEvent;if(wP({key:o.key,shiftKey:o.shiftKey,compositionActive:n.current,nativeIsComposing:a.isComposing,keyCode:a.keyCode})){o.preventDefault(),e();return}t&&o.key==="Escape"&&(o.preventDefault(),t())},[e,t]),onCompositionStart:r,onCompositionEnd:i}}function aK({open:e,initialLabel:t,placeholder:n,onSubmit:r,onCancel:i,title:s="Edit session",fieldLabel:o="Label",testId:a="session-edit-dialog",requireNonEmpty:l=!1}){const[c,u]=g.useState(t);g.useEffect(()=>{e&&u(t)},[e,t]);const d=c.trim(),f=l&&d==="",p=()=>{f||r({label:d})},m=td(p,i);return e?Oo.createPortal(h.jsx("div",{className:"fixed inset-0 z-[10000] flex items-center justify-center bg-bg-0/40 backdrop-blur-[2px]",onClick:i,"data-testid":`${a}-overlay`,children:h.jsxs("div",{"data-testid":a,className:"w-[420px] max-w-[calc(100vw-32px)] rounded-2xl border border-text-100/[0.12] flex flex-col gap-4 p-5",style:{backgroundColor:"var(--bg-0)",boxShadow:"0 12px 40px rgba(0,0,0,0.04)"},onClick:v=>v.stopPropagation(),children:[h.jsx("div",{className:"text-[15px] font-semibold text-text-100",children:s}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-[12px] font-semibold text-text-200 mb-1",children:o}),h.jsx("input",{autoFocus:!0,type:"text",value:c,onChange:v=>u(v.target.value),...m,placeholder:n,"data-testid":`${a}-label`,className:"w-full px-3 py-2 text-[13px] bg-bg-50 border border-bg-300 rounded-lg focus:outline-none focus:border-text-300 transition-colors"})]}),h.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[h.jsx("button",{type:"button",onClick:i,className:"px-4 py-1.5 text-[12px] text-text-300 rounded-lg hover:bg-text-100/5 transition-colors cursor-pointer",children:"Cancel"}),h.jsx("button",{type:"button",onClick:p,disabled:f,"data-testid":`${a}-save`,className:"px-4 py-1.5 text-[12px] font-medium text-bg-0 rounded-lg bg-text-100 hover:bg-text-200 transition-colors cursor-pointer disabled:cursor-not-allowed disabled:opacity-40",children:"Save"})]})]})}),document.body):null}var lK=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),cK="VisuallyHidden",SP=g.forwardRef((e,t)=>h.jsx(wt.span,{...e,ref:t,style:{...lK,...e.style}}));SP.displayName=cK;var uK=SP,[xm]=io("Tooltip",[Hl]),ym=Hl(),kP="TooltipProvider",dK=700,kx="tooltip.open",[hK,L_]=xm(kP),CP=e=>{const{__scopeTooltip:t,delayDuration:n=dK,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:s}=e,o=g.useRef(!0),a=g.useRef(!1),l=g.useRef(0);return g.useEffect(()=>{const c=l.current;return()=>window.clearTimeout(c)},[]),h.jsx(hK,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:g.useCallback(()=>{window.clearTimeout(l.current),o.current=!1},[]),onClose:g.useCallback(()=>{window.clearTimeout(l.current),l.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:a,onPointerInTransitChange:g.useCallback(c=>{a.current=c},[]),disableHoverableContent:i,children:s})};CP.displayName=kP;var Tu="Tooltip",[fK,_m]=xm(Tu),EP=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:a}=e,l=L_(Tu,e.__scopeTooltip),c=ym(t),[u,d]=g.useState(null),f=bi(),p=g.useRef(0),m=o??l.disableHoverableContent,v=a??l.delayDuration,w=g.useRef(!1),[x,_]=$l({prop:r,defaultProp:i??!1,onChange:N=>{N?(l.onOpen(),document.dispatchEvent(new CustomEvent(kx))):l.onClose(),s==null||s(N)},caller:Tu}),b=g.useMemo(()=>x?w.current?"delayed-open":"instant-open":"closed",[x]),S=g.useCallback(()=>{window.clearTimeout(p.current),p.current=0,w.current=!1,_(!0)},[_]),C=g.useCallback(()=>{window.clearTimeout(p.current),p.current=0,_(!1)},[_]),k=g.useCallback(()=>{window.clearTimeout(p.current),p.current=window.setTimeout(()=>{w.current=!0,_(!0),p.current=0},v)},[v,_]);return g.useEffect(()=>()=>{p.current&&(window.clearTimeout(p.current),p.current=0)},[]),h.jsx(cm,{...c,children:h.jsx(fK,{scope:t,contentId:f,open:x,stateAttribute:b,trigger:u,onTriggerChange:d,onTriggerEnter:g.useCallback(()=>{l.isOpenDelayedRef.current?k():S()},[l.isOpenDelayedRef,k,S]),onTriggerLeave:g.useCallback(()=>{m?C():(window.clearTimeout(p.current),p.current=0)},[C,m]),onOpen:S,onClose:C,disableHoverableContent:m,children:n})})};EP.displayName=Tu;var Cx="TooltipTrigger",IP=g.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=_m(Cx,n),s=L_(Cx,n),o=ym(n),a=g.useRef(null),l=Ot(t,a,i.onTriggerChange),c=g.useRef(!1),u=g.useRef(!1),d=g.useCallback(()=>c.current=!1,[]);return g.useEffect(()=>()=>document.removeEventListener("pointerup",d),[d]),h.jsx(um,{asChild:!0,...o,children:h.jsx(wt.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:l,onPointerMove:Ne(e.onPointerMove,f=>{f.pointerType!=="touch"&&!u.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),u.current=!0)}),onPointerLeave:Ne(e.onPointerLeave,()=>{i.onTriggerLeave(),u.current=!1}),onPointerDown:Ne(e.onPointerDown,()=>{i.open&&i.onClose(),c.current=!0,document.addEventListener("pointerup",d,{once:!0})}),onFocus:Ne(e.onFocus,()=>{c.current||i.onOpen()}),onBlur:Ne(e.onBlur,i.onClose),onClick:Ne(e.onClick,i.onClose)})})});IP.displayName=Cx;var pK="TooltipPortal",[Vde,mK]=xm(pK,{forceMount:void 0}),gl="TooltipContent",NP=g.forwardRef((e,t)=>{const n=mK(gl,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=_m(gl,e.__scopeTooltip);return h.jsx(Jr,{present:r||o.open,children:o.disableHoverableContent?h.jsx(TP,{side:i,...s,ref:t}):h.jsx(gK,{side:i,...s,ref:t})})}),gK=g.forwardRef((e,t)=>{const n=_m(gl,e.__scopeTooltip),r=L_(gl,e.__scopeTooltip),i=g.useRef(null),s=Ot(t,i),[o,a]=g.useState(null),{trigger:l,onClose:c}=n,u=i.current,{onPointerInTransitChange:d}=r,f=g.useCallback(()=>{a(null),d(!1)},[d]),p=g.useCallback((m,v)=>{const w=m.currentTarget,x={x:m.clientX,y:m.clientY},_=bK(x,w.getBoundingClientRect()),b=wK(x,_),S=SK(v.getBoundingClientRect()),C=CK([...b,...S]);a(C),d(!0)},[d]);return g.useEffect(()=>()=>f(),[f]),g.useEffect(()=>{if(l&&u){const m=w=>p(w,u),v=w=>p(w,l);return l.addEventListener("pointerleave",m),u.addEventListener("pointerleave",v),()=>{l.removeEventListener("pointerleave",m),u.removeEventListener("pointerleave",v)}}},[l,u,p,f]),g.useEffect(()=>{if(o){const m=v=>{const w=v.target,x={x:v.clientX,y:v.clientY},_=(l==null?void 0:l.contains(w))||(u==null?void 0:u.contains(w)),b=!kK(x,o);_?f():b&&(f(),c())};return document.addEventListener("pointermove",m),()=>document.removeEventListener("pointermove",m)}},[l,u,o,c,f]),h.jsx(TP,{...e,ref:s})}),[vK,xK]=xm(Tu,{isInside:!1}),yK=cU("TooltipContent"),TP=g.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...a}=e,l=_m(gl,n),c=ym(n),{onClose:u}=l;return g.useEffect(()=>(document.addEventListener(kx,u),()=>document.removeEventListener(kx,u)),[u]),g.useEffect(()=>{if(l.trigger){const d=f=>{const p=f.target;p!=null&&p.contains(l.trigger)&&u()};return window.addEventListener("scroll",d,{capture:!0}),()=>window.removeEventListener("scroll",d,{capture:!0})}},[l.trigger,u]),h.jsx(Yu,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:d=>d.preventDefault(),onDismiss:u,children:h.jsxs(y_,{"data-state":l.stateAttribute,...c,...a,ref:t,style:{...a.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[h.jsx(yK,{children:r}),h.jsx(vK,{scope:n,isInside:!0,children:h.jsx(uK,{id:l.contentId,role:"tooltip",children:i||r})})]})})});NP.displayName=gl;var PP="TooltipArrow",_K=g.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=ym(n);return xK(PP,n).isInside?null:h.jsx(__,{...i,...r,ref:t})});_K.displayName=PP;function bK(e,t){const n=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),i=Math.abs(t.right-e.x),s=Math.abs(t.left-e.x);switch(Math.min(n,r,i,s)){case s:return"left";case i:return"right";case n:return"top";case r:return"bottom";default:throw new Error("unreachable")}}function wK(e,t,n=5){const r=[];switch(t){case"top":r.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case"bottom":r.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case"left":r.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case"right":r.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n});break}return r}function SK(e){const{top:t,right:n,bottom:r,left:i}=e;return[{x:i,y:t},{x:n,y:t},{x:n,y:r},{x:i,y:r}]}function kK(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 a=t[s],l=t[o],c=a.x,u=a.y,d=l.x,f=l.y;u>r!=f>r&&n<(d-c)*(r-u)/(f-u)+c&&(i=!i)}return i}function CK(e){const t=e.slice();return t.sort((n,r)=>n.x<r.x?-1:n.x>r.x?1:n.y<r.y?-1:n.y>r.y?1:0),EK(t)}function EK(e){if(e.length<=1)return e.slice();const t=[];for(let r=0;r<e.length;r++){const i=e[r];for(;t.length>=2;){const s=t[t.length-1],o=t[t.length-2];if((s.x-o.x)*(i.y-o.y)>=(s.y-o.y)*(i.x-o.x))t.pop();else break}t.push(i)}t.pop();const n=[];for(let r=e.length-1;r>=0;r--){const i=e[r];for(;n.length>=2;){const s=n[n.length-1],o=n[n.length-2];if((s.x-o.x)*(i.y-o.y)>=(s.y-o.y)*(i.x-o.x))n.pop();else break}n.push(i)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}var IK=CP,NK=EP,TK=IP,RP=NP;const Pu=IK,nd=NK,rd=TK,Ul=g.forwardRef(({className:e,sideOffset:t=4,...n},r)=>h.jsx(RP,{ref:r,sideOffset:t,className:ie("z-50 overflow-hidden rounded-sm border border-border bg-bg-0 px-2 py-1 text-xs text-text-300 shadow-md",e),...n}));Ul.displayName=RP.displayName;const PK={held:!1,indexBySessionId:new Map},RK=g.createContext(PK);function MK(){return g.useContext(RK)}const AK=Array.from({length:9},(e,t)=>({id:`switch-session-${t+1}`,combo:{key:String(t+1),mod:!0},label:`切换到第 ${t+1} 个会话`,group:"会话",desktopOnly:!0,hiddenInList:!0})),jK=[{id:"new-session",combo:{key:"n",mod:!0},label:"新建任务",description:"打开快捷新建弹窗",group:"通用",desktopOnly:!0},{id:"open-search",combo:{key:"k",mod:!0},label:"全局搜索",description:"搜会话内容 / persona / 联系人",group:"通用",desktopOnly:!0},{id:"search-tab-prev",combo:{key:"ArrowLeft",mod:!0},label:"搜索:上一组",description:"搜索浮层里切到左边那个 tab(会话 / persona / 联系人)",group:"通用"},{id:"search-tab-next",combo:{key:"ArrowRight",mod:!0},label:"搜索:下一组",description:"搜索浮层里切到右边那个 tab",group:"通用"},...AK,{id:"archive-session",combo:{key:"Backspace",mod:!0,shift:!0},label:"归档当前会话",description:"归档当前聊天区的会话,Enter 确认 / Esc 取消",group:"会话",desktopOnly:!0},{id:"tab-prev",combo:{key:"ArrowLeft",mod:!0,shift:!0},label:"上一个标签页",description:"连按快速移动,停下或松开修饰键后切换",group:"标签页"},{id:"tab-next",combo:{key:"ArrowRight",mod:!0,shift:!0},label:"下一个标签页",description:"连按快速移动,停下或松开修饰键后切换",group:"标签页"},{id:"toggle-hive",combo:{key:"h",mod:!0,shift:!0},label:"Hive 看板",description:"全屏看所有 agent 在干什么;Esc 或点任意行退出",group:"通用"},{id:"send-message",combo:{key:"Enter"},label:"发送消息",description:"在输入框中发送当前内容",group:"输入",displayOnly:!0},{id:"newline",combo:{key:"Enter",shift:!0},label:"换行",description:"在输入框中插入换行",group:"输入",displayOnly:!0},{id:"interrupt",combo:{key:"Escape"},label:"打断回复",description:"打断当前回复;2 秒内按两次停止任务",group:"输入",displayOnly:!0}];jK.filter(e=>!e.displayOnly);function LK(){return/Mac|iP(hone|od|ad)/.test(navigator.platform)}const DK=10,OK=20,BK=16,qk=20,Vk=60,$K=4;function eh({testId:e,label:t,children:n}){return h.jsxs(nd,{children:[h.jsx(rd,{asChild:!0,children:h.jsx("span",{"data-testid":e,role:"img","aria-label":t,tabIndex:0,className:"inline-flex shrink-0",children:n})}),h.jsx(Ul,{side:"bottom",children:t})]})}function zK({session:e,active:t,hasUnread:n,running:r=!1,awaitingUser:i=!1,onSelect:s,onEdit:o,onDelete:a,onPin:l,onArchive:c,quickAction:u,depth:d=0,chevron:f,showCopyResume:p=!0,contactDisplayName:m,ownerPrincipalId:v,creatorDisplayName:w,dispatchedFromSessionTitle:x}){const[_,b]=g.useState(!1),S=MK(),C=S.held?S.indexBySessionId.get(e.sessionId):void 0,k=!!e.pinnedAt,N=d===0,E=d===0&&!!c,j=DK+d*OK;let P=null;u==="pin"&&N&&l?P={icon:k?h.jsx(ck,{className:"w-4 h-4"}):h.jsx(uk,{className:"w-4 h-4"}),label:k?"取消置顶":"置顶",run:()=>l(e.sessionId,!k)}:u==="archive"&&E&&c?P={icon:h.jsx(ok,{className:"w-4 h-4"}),label:"归档",run:()=>c(e.sessionId,!0)}:u==="rename"&&o&&(P={icon:h.jsx(px,{className:"w-4 h-4"}),label:"重命名",run:()=>b(!0)});const L=g.useCallback(async()=>{const z=B4(e);if(z)try{await navigator.clipboard.writeText(z)}catch{}},[e]),M=c_(e),R=e.originOwnerPrincipalId,A=R?`@${m??`…${R.slice(-8)}`}`:null,D=!!(e.ownerPersonaId&&v&&e.creatorPrincipalId&&e.creatorPrincipalId!==v&&!e.larkChatId&&!e.shiftFiredFromSessionId&&!e.dispatchedFromSessionId);return h.jsxs(h.Fragment,{children:[h.jsxs("div",{"data-testid":`session-item-${e.sessionId}`,onClick:s,style:{paddingLeft:j,display:"grid",gridTemplateColumns:f?`${BK}px ${qk}px 1fr auto ${Vk}px`:`${qk}px 1fr auto ${Vk}px`,gridTemplateAreas:f?'"chev icon name dot time"':'"icon name dot time"',columnGap:`${$K}px`,alignItems:"center"},className:ie("group relative rounded-lg cursor-pointer transition-all duration-150 pr-2.5 py-1.5",t?"bg-accent-dim":"hover:bg-sidebar-hover-bg"),children:[t?h.jsx("span",{"aria-hidden":"true",className:"absolute left-0 top-1/2 -translate-y-1/2 w-[3px] h-7 rounded-r-full bg-accent"}):null,h.jsx("div",{style:{gridArea:"chev"},className:"flex items-center justify-center",children:f??null}),h.jsx("div",{style:{gridArea:"icon"},className:"flex items-center justify-center",children:h.jsx(sK,{tool:e.tool})}),h.jsxs("div",{style:{gridArea:"name"},className:"flex items-center gap-1 min-w-0",children:[h.jsxs(Pu,{delayDuration:200,skipDelayDuration:100,children:[e.dispatchedFromSessionId?h.jsx(eh,{testId:`dispatched-icon-${e.sessionId}`,label:`来自【${x??"另一会话"}】dispatch`,children:h.jsx(F7,{"aria-hidden":"true",className:"w-3 h-3 text-accent",strokeWidth:2.25})}):null,e.shiftFiredFromSessionId?h.jsx(eh,{testId:`shift-fired-icon-${e.sessionId}`,label:"定时任务",children:h.jsx(l7,{"aria-hidden":"true",className:"w-3 h-3 text-accent",strokeWidth:2.25})}):null,e.larkChatId?h.jsx(eh,{testId:`lark-chat-icon-${e.sessionId}`,label:e.larkChatType==="p2p"?"来自飞书DM":"来自飞书群",children:h.jsx(yF,{"aria-hidden":"true",className:"w-3 h-3 text-accent",strokeWidth:2.25})}):null,D?h.jsx(eh,{testId:`guest-created-icon-${e.sessionId}`,label:w?`${w}创建`:"其他人创建",children:h.jsx(tH,{"aria-hidden":"true",className:"w-3 h-3 text-accent",strokeWidth:2.25})}):null]}),h.jsx("span",{"data-testid":`session-title-${e.sessionId}`,className:ie("text-[13px] truncate min-w-0","group-hover:whitespace-normal group-hover:overflow-visible group-hover:break-words",t?"text-text-100 font-medium":"text-text-200"),children:M}),A?h.jsx("span",{"data-testid":`session-mirror-chip-${e.sessionId}`,title:`在 ${A.replace(/^@/,"")} 的设备上`,className:"shrink-0 inline-flex items-center px-1.5 py-0 rounded text-[10px] bg-accent-dim/40 text-accent border border-accent/20 max-w-[120px] truncate",children:A}):null]}),h.jsx(oK,{sessionId:e.sessionId,hasUnread:n,running:r,awaitingUser:i,style:{gridArea:"dot"}}),C!=null?h.jsx("span",{style:{gridArea:"time"},"data-testid":`session-quick-switch-badge-${e.sessionId}`,className:"text-right shrink-0 transition-opacity duration-150 group-hover:opacity-0",children:h.jsx("span",{className:"inline-flex items-center justify-center h-[18px] px-1.5 rounded-[5px] border border-border bg-bg-200/70 text-[11px] text-text-200 font-medium leading-none",children:LK()?`⌘${C}`:`Ctrl+${C}`})}):h.jsx("span",{style:{gridArea:"time"},className:ie("text-[11px] text-text-400/70 text-right shrink-0","transition-opacity duration-150 group-hover:opacity-0"),children:e.updatedAt?eU(e.updatedAt):""}),o||a||l||c?h.jsxs("div",{className:"absolute right-2 top-[3px] flex items-center opacity-0 group-hover:opacity-100 data-[state=open]:opacity-100 transition-opacity",children:[P?h.jsx(Pu,{delayDuration:200,skipDelayDuration:100,children:h.jsxs(nd,{children:[h.jsx(rd,{asChild:!0,children:h.jsx("button",{type:"button",onClick:z=>{z.stopPropagation(),P.run()},className:"flex items-center justify-center w-7 h-7 rounded-md text-text-400 hover:text-text-100 hover:bg-text-100/5 transition-colors cursor-pointer","aria-label":P.label,"data-testid":`quick-action-${u}-${e.sessionId}`,children:P.icon})}),h.jsx(Ul,{side:"bottom",children:P.label})]})}):null,h.jsxs(P_,{modal:!1,children:[h.jsx(R_,{asChild:!0,children:h.jsx("button",{type:"button",onClick:z=>z.stopPropagation(),className:"flex items-center justify-center w-7 h-7 rounded-md text-text-400 hover:text-text-100 hover:bg-text-100/5 transition-colors cursor-pointer","aria-label":"session actions","data-testid":`session-menu-${e.sessionId}`,children:h.jsx(h4,{className:"w-4 h-4"})})}),h.jsxs(gm,{align:"end",onClick:z=>z.stopPropagation(),children:[l&&N&&h.jsxs(Ir,{onSelect:()=>l(e.sessionId,!k),"data-testid":`session-${k?"unpin":"pin"}-${e.sessionId}`,children:[k?h.jsx(ck,{className:"w-3 h-3 mr-2 text-text-400"}):h.jsx(uk,{className:"w-3 h-3 mr-2 text-text-400"}),k?"Unpin":"Pin"]}),E&&c&&h.jsxs(Ir,{onSelect:()=>c(e.sessionId,!0),"data-testid":`session-archive-${e.sessionId}`,children:[h.jsx(ok,{className:"w-3 h-3 mr-2 text-text-400"}),"Archive"]}),o&&h.jsxs(Ir,{onSelect:()=>b(!0),"data-testid":`session-rename-${e.sessionId}`,children:[h.jsx(px,{className:"w-3 h-3 mr-2 text-text-400"}),"Rename"]}),p&&e.toolSessionId?h.jsxs(Ir,{onSelect:()=>void L(),"data-testid":`session-copy-resume-${e.sessionId}`,children:[h.jsx(r_,{className:"w-3 h-3 mr-2 text-text-400"}),"Copy Resume Command"]}):null,(l||o||p&&e.toolSessionId)&&a&&h.jsx(vm,{}),a&&h.jsxs(Ir,{onSelect:()=>void a(e.sessionId),className:"text-destructive focus:text-destructive focus:bg-destructive/10","data-testid":`session-delete-${e.sessionId}`,children:[h.jsx(s_,{className:"w-3 h-3 mr-2"}),"Delete"]})]})]})]}):null]}),o?h.jsx(aK,{open:_,initialLabel:e.label??"",placeholder:e.cwd.split("/").pop()||"",onSubmit:z=>{o(e.sessionId,z),b(!1)},onCancel:()=>b(!1)}):null]})}function D_({node:e,depth:t=0,activeId:n,unreadIds:r,runningIds:i,awaitingIds:s,onSelect:o,onEdit:a,onDelete:l,onPin:c,onArchive:u,quickAction:d,getContactDisplayName:f,showCopyResume:p,ownerPrincipalId:m,getCreatorDisplayName:v,getSessionDisplayName:w,parentSession:x}){const _=e.children.length>0,{isCollapsed:b,toggle:S}=t7(),C=!b(e.session.sessionId),k=g.useCallback(E=>{E.stopPropagation(),S(e.session.sessionId)},[S,e.session.sessionId]),N=_?h.jsx("button",{type:"button",onClick:k,"data-testid":`session-chevron-${e.session.sessionId}`,"aria-label":C?"collapse":"expand","aria-expanded":C,className:"shrink-0 flex items-center justify-center w-4 h-4 text-text-400 hover:text-text-100 cursor-pointer",children:C?h.jsx(Pn,{className:"w-3 h-3"}):h.jsx(Fn,{className:"w-3 h-3"})}):null;return h.jsxs("div",{"data-testid":`session-tree-node-${e.session.sessionId}`,children:[h.jsx(zK,{session:e.session,active:n===e.session.sessionId,hasUnread:(r==null?void 0:r.has(e.session.sessionId))??!1,running:(i==null?void 0:i.has(e.session.sessionId))??!1,awaitingUser:(s==null?void 0:s.has(e.session.sessionId))??!1,onSelect:()=>o(e.session.sessionId),onEdit:a,onDelete:l,onPin:c,onArchive:u,quickAction:d,showCopyResume:p,ownerPrincipalId:m,creatorDisplayName:e.session.creatorPrincipalId?v==null?void 0:v(e.session.creatorPrincipalId):void 0,dispatchedFromSessionTitle:e.session.dispatchedFromSessionId?(w==null?void 0:w(e.session.dispatchedFromSessionId))??((x==null?void 0:x.sessionId)===e.session.dispatchedFromSessionId?c_(x):void 0):void 0,depth:t,chevron:N,contactDisplayName:e.session.originOwnerPrincipalId?f==null?void 0:f(e.session.originOwnerPrincipalId):void 0}),_&&C?h.jsx("div",{"data-testid":`session-tree-children-${e.session.sessionId}`,children:e.children.map(E=>h.jsx(D_,{node:E,depth:t+1,activeId:n,unreadIds:r,runningIds:i,awaitingIds:s,onSelect:o,onEdit:a,onDelete:l,onPin:c,onArchive:u,quickAction:d,getContactDisplayName:f,showCopyResume:p,ownerPrincipalId:m,getCreatorDisplayName:v,getSessionDisplayName:w,parentSession:e.session},E.session.sessionId))}):null]})}function FK(e){return e.forkedFromSessionId??e.dispatchedFromSessionId??e.shiftFiredFromSessionId}function O_(e,t){return e.updatedAt<t.updatedAt?1:e.updatedAt>t.updatedAt?-1:0}function MP(e){e=e.filter(s=>!s.ephemeral&&s.deployId===void 0&&s.testReleaseId===void 0);const t=new Map;for(const s of e)t.set(s.sessionId,s);const n=new Map,r=[];for(const s of e){const o=FK(s);if(o&&t.has(o)){const a=n.get(o)??[];a.push(s),n.set(o,a)}else r.push(s)}const i=s=>{const a=[...n.get(s.sessionId)??[]].sort(O_);return{session:s,children:a.map(i)}};return[...r].sort(HK).map(i)}function AP(e){return[...e].sort((t,n)=>O_(t.session,n.session))}function HK(e,t){const n=typeof e.pinnedAt=="number",r=typeof t.pinnedAt=="number";if(n&&r){const i=typeof e.pinSortOrder=="number",s=typeof t.pinSortOrder=="number";return i&&s?e.pinSortOrder-t.pinSortOrder:i?-1:s?1:t.pinnedAt-e.pinnedAt}return n?-1:r?1:O_(e,t)}function UK(e){return e.label?e.label:e.aiLabel?e.aiLabel:e.cwd.split("/").filter(Boolean).pop()??""}function Kk(e,t){const n=t.trim().toLowerCase();return n===""?!0:e.toLowerCase().includes(n)}const WK={isCollapsed:()=>!1,toggle:()=>{},prune:()=>{}};function qK({personas:e,activePersonaId:t,onSelectPersona:n,onCreateSession:r,sessions:i,activeSessionId:s,awaitingIds:o,runningIds:a,unreadIds:l,onSelectSession:c,onDeleteSession:u,ownerPrincipalId:d,creatorDisplayNameByOwnerId:f,isPersonaExpanded:p,onTogglePersonaExpanded:m,onEditSession:v,onPinSession:w,showCopyResume:x,treatSessionsAsRoots:_,searchQuery:b}){const[S,C]=g.useState(null),[k,N]=g.useState(()=>new Set),E=p??(D=>k.has(D)),j=g.useCallback(D=>{if(m){m(D);return}N(z=>{const F=new Set(z);return F.has(D)?F.delete(D):F.add(D),F})},[m]),P=g.useMemo(()=>i==null?void 0:i.filter(D=>!D.ephemeral),[i]),L=g.useMemo(()=>new Map((P??[]).map(D=>[D.sessionId,c_(D)])),[P]),M=g.useCallback(D=>f==null?void 0:f.get(D),[f]),R=g.useCallback(D=>L.get(D),[L]);if(e.length===0)return h.jsx(VK,{});const A=(b??"").trim();return A?h.jsx(t_.Provider,{value:WK,children:h.jsx("div",{"data-testid":"my-personas-list",className:"flex flex-col gap-0.5",children:e.map(D=>{const z=P?P.filter(I=>I.ownerPersonaId===D.personaId).sort((I,U)=>U.updatedAt>I.updatedAt?1:-1):[],F=Kk(D.label,A),$=z.filter(I=>Kk(UK(I),A));if(!F&&$.length===0)return null;const O=F?z:$;return h.jsx(Gk,{persona:D,active:D.personaId===t,editing:!1,onSelectPersona:n,onSubmitCreateSession:()=>{},onCancelCreateSession:()=>{},personaSessions:O,collapsed:!1,onToggleCollapsed:()=>{},activeSessionId:s??null,awaitingIds:o,runningIds:a,unreadIds:l,onSelectSession:c,onDeleteSession:u,onEditSession:v,onPinSession:w,showCopyResume:x,treatSessionsAsRoots:_,ownerPrincipalId:d,creatorDisplayNameByOwnerId:f,getCreatorDisplayName:M,getSessionDisplayName:R},D.personaId)})})}):h.jsx("div",{"data-testid":"my-personas-list",className:"flex flex-col gap-0.5",children:e.map(D=>{const z=P?P.filter(F=>F.ownerPersonaId===D.personaId).sort((F,$)=>$.updatedAt>F.updatedAt?1:-1):[];return h.jsx(Gk,{persona:D,active:D.personaId===t,editing:D.personaId===S,onSelectPersona:n,onStartCreateSession:r?()=>C(D.personaId):void 0,onSubmitCreateSession:F=>{C(null),r==null||r(D.personaId,F)},onCancelCreateSession:()=>C(null),personaSessions:z,collapsed:!E(D.personaId),onToggleCollapsed:()=>j(D.personaId),activeSessionId:s??null,awaitingIds:o,runningIds:a,unreadIds:l,onSelectSession:c,onDeleteSession:u,onEditSession:v,onPinSession:w,showCopyResume:x,treatSessionsAsRoots:_,ownerPrincipalId:d,creatorDisplayNameByOwnerId:f,getCreatorDisplayName:M,getSessionDisplayName:R},D.personaId)})})}function VK(){return h.jsx("div",{className:"px-3 py-3 text-[11px] leading-relaxed text-text-400",children:"还没有 persona。点上方 Personas 标题右侧 + 创建第一个。"})}function Gk({persona:e,active:t,editing:n,onSelectPersona:r,onStartCreateSession:i,onSubmitCreateSession:s,onCancelCreateSession:o,personaSessions:a,collapsed:l,onToggleCollapsed:c,activeSessionId:u,awaitingIds:d,runningIds:f,unreadIds:p,onSelectSession:m,onDeleteSession:v,onEditSession:w,onPinSession:x,showCopyResume:_,treatSessionsAsRoots:b,ownerPrincipalId:S,creatorDisplayNameByOwnerId:C,getCreatorDisplayName:k,getSessionDisplayName:N}){const E=a.length>0,j=!l,P=g.useMemo(()=>{const R=[],A=new Map;for(const D of a){const z=D.creatorPrincipalId;if(D.larkChatId!=null||!z||S&&z===S){R.push(D);continue}const F=z,$=(C==null?void 0:C.get(F))??`…${F.slice(-8)}`,O=A.get(F);O?O.sessions.push(D):A.set(F,{groupKey:F,displayName:$,sessions:[D]})}return{self:R,byPeer:[...A.values()]}},[a,S,C]),L=P.byPeer.length>0,M=g.useMemo(()=>j&&!L?AP(MP(a)):[],[j,L,a]);return h.jsxs("div",{"data-testid":`persona-node-${e.personaId}`,children:[h.jsxs("div",{className:ie("group flex items-center gap-1 px-2 py-1.5 cursor-pointer",t?"bg-accent-dim text-text-100":"hover:bg-bg-200 text-text-200"),onClick:()=>r==null?void 0:r(e.personaId),role:"button",tabIndex:0,children:[E?h.jsx("button",{type:"button",onClick:R=>{R.stopPropagation(),c()},"aria-label":j?"collapse":"expand","aria-expanded":j,"data-testid":`persona-chevron-${e.personaId}`,className:"flex h-4 w-4 shrink-0 items-center justify-center text-text-400 hover:text-text-100",children:j?h.jsx(Pn,{className:"h-3 w-3"}):h.jsx(Fn,{className:"h-3 w-3"})}):h.jsx("span",{className:"h-4 w-4 shrink-0","aria-hidden":"true"}),h.jsx(nm,{tool:e.tool,className:ie("h-3.5 w-3.5 shrink-0",rm(e.tool))}),h.jsx("span",{className:"flex-1 truncate text-[13px]",children:e.label}),E?h.jsx("span",{className:"shrink-0 text-[10px] text-text-400 tabular-nums","aria-label":`${a.length} sessions`,children:a.length}):null,i?h.jsx("button",{type:"button",onClick:R=>{R.stopPropagation(),i()},"aria-label":"新建会话",title:"新建会话","data-testid":`persona-create-session-${e.personaId}`,className:"flex h-5 w-5 shrink-0 items-center justify-center rounded text-text-400 opacity-0 hover:bg-text-100/10 hover:text-text-100 focus-visible:opacity-100 group-hover:opacity-100",children:h.jsx(g4,{className:"h-3.5 w-3.5"})}):null]}),n?h.jsx(KK,{personaId:e.personaId,tool:e.tool,onSubmit:s,onCancel:o}):null,E&&j?h.jsx("div",{"data-testid":`persona-sessions-${e.personaId}`,children:L?h.jsxs(h.Fragment,{children:[P.self.length>0&&h.jsx(Yk,{groupKey:`${e.personaId}-self`,label:"我自己",testId:`persona-sessions-${e.personaId}-self`,sessions:P.self,activeSessionId:u,awaitingIds:d,runningIds:f,unreadIds:p,onSelectSession:m,onDeleteSession:v,onEditSession:w,onPinSession:x,showCopyResume:_,ownerPrincipalId:S,getCreatorDisplayName:k,getSessionDisplayName:N}),P.byPeer.map(R=>h.jsx(Yk,{groupKey:`${e.personaId}-peer-${R.groupKey}`,label:R.displayName,testId:`persona-sessions-${e.personaId}-peer-${R.groupKey}`,sessions:R.sessions,activeSessionId:u,awaitingIds:d,runningIds:f,unreadIds:p,onSelectSession:m,onDeleteSession:v,onEditSession:w,onPinSession:x,showCopyResume:_,ownerPrincipalId:S,getCreatorDisplayName:k,getSessionDisplayName:N},`${e.personaId}-peer-${R.groupKey}`))]}):M.map(R=>h.jsx(D_,{node:R,depth:b?0:1,activeId:u,unreadIds:p,runningIds:f,awaitingIds:d,onSelect:A=>m==null?void 0:m(A),onDelete:v,onEdit:w,onPin:x,showCopyResume:_,ownerPrincipalId:S,getCreatorDisplayName:k,getSessionDisplayName:N},R.session.sessionId))}):null]})}function Yk({label:e,testId:t,sessions:n,activeSessionId:r,awaitingIds:i,runningIds:s,unreadIds:o,onSelectSession:a,onDeleteSession:l,onEditSession:c,onPinSession:u,showCopyResume:d,ownerPrincipalId:f,getCreatorDisplayName:p,getSessionDisplayName:m}){const[v,w]=g.useState(!1),x=!v,_=g.useMemo(()=>x?AP(MP(n)):[],[x,n]);return h.jsxs("div",{"data-testid":t,children:[h.jsxs("button",{type:"button",onClick:()=>w(b=>!b),"aria-label":x?"collapse":"expand","aria-expanded":x,"data-testid":`${t}-chevron`,className:"flex items-center gap-1 w-full pl-7 pr-2 py-0.5 text-[11px] text-text-400 hover:text-text-200 transition-colors",children:[x?h.jsx(Pn,{className:"h-3 w-3"}):h.jsx(Fn,{className:"h-3 w-3"}),h.jsx(_4,{className:"h-3 w-3","aria-hidden":!0}),h.jsx("span",{className:"truncate",children:e}),h.jsx("span",{className:"ml-auto tabular-nums",children:n.length})]}),x&&h.jsx("div",{children:_.map(b=>h.jsx(D_,{node:b,depth:2,activeId:r,unreadIds:o,runningIds:s,awaitingIds:i,onSelect:S=>a==null?void 0:a(S),onDelete:l,onEdit:c,onPin:u,showCopyResume:d,ownerPrincipalId:f,getCreatorDisplayName:p,getSessionDisplayName:m},b.session.sessionId))})]})}function KK({personaId:e,tool:t,onSubmit:n,onCancel:r}){const[i,s]=g.useState(""),o=g.useRef(null),a=i.trim(),l=a.length>0;g.useEffect(()=>{var d;(d=o.current)==null||d.focus()},[]);const c=g.useCallback(()=>{l&&n(a)},[l,a,n]),u=td(c,r);return h.jsxs("div",{className:"flex items-center gap-1.5 pl-9 pr-2 py-1","data-testid":`persona-new-session-row-${e}`,children:[h.jsx(nm,{tool:t,className:ie("h-3 w-3 shrink-0",rm(t))}),h.jsx("input",{ref:o,type:"text",value:i,onChange:d=>s(d.target.value),...u,onBlur:r,placeholder:"session label...","data-testid":`persona-new-session-input-${e}`,className:"flex-1 min-w-0 bg-bg-100 border border-text-100/15 rounded px-1.5 py-0.5 text-[12px] text-text-100 placeholder:text-text-400 focus:outline-none focus:border-text-100/40"}),h.jsx("button",{type:"button",onMouseDown:d=>{d.preventDefault(),c()},disabled:!l,"aria-label":"确认",title:"确认(Enter)","data-testid":`persona-new-session-confirm-${e}`,className:"flex h-4 w-4 shrink-0 items-center justify-center rounded text-text-300 hover:bg-text-100/10 hover:text-text-100 disabled:opacity-30 disabled:hover:bg-transparent disabled:hover:text-text-300",children:h.jsx(no,{className:"h-3 w-3"})}),h.jsx("button",{type:"button",onMouseDown:d=>{d.preventDefault(),r()},"aria-label":"取消",title:"取消(Esc)","data-testid":`persona-new-session-cancel-${e}`,className:"flex h-4 w-4 shrink-0 items-center justify-center rounded text-text-300 hover:bg-text-100/10 hover:text-text-100",children:h.jsx(Qr,{className:"h-3 w-3"})})]})}function GK(e,t){const n=getComputedStyle(e),r=parseFloat(n.fontSize);return t*r}function YK(e,t){const n=getComputedStyle(e.ownerDocument.documentElement),r=parseFloat(n.fontSize);return t*r}function XK(e){return e/100*window.innerHeight}function ZK(e){return e/100*window.innerWidth}function QK(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 Cc({groupSize:e,panelElement:t,styleProp:n}){let r;const[i,s]=QK(n);switch(s){case"%":{r=i/100*e;break}case"px":{r=i;break}case"rem":{r=YK(t,i);break}case"em":{r=GK(t,i);break}case"vh":{r=XK(i);break}case"vw":{r=ZK(i);break}}return r}function Dn(e){return parseFloat(e.toFixed(3))}function vl({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 Ex(e){const{panels:t}=e,n=vl({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 u=Cc({groupSize:n,panelElement:i,styleProp:s.collapsedSize});o=Dn(u/n*100)}let a;if(s.defaultSize!==void 0){const u=Cc({groupSize:n,panelElement:i,styleProp:s.defaultSize});a=Dn(u/n*100)}let l=0;if(s.minSize!==void 0){const u=Cc({groupSize:n,panelElement:i,styleProp:s.minSize});l=Dn(u/n*100)}let c=100;if(s.maxSize!==void 0){const u=Cc({groupSize:n,panelElement:i,styleProp:s.maxSize});c=Dn(u/n*100)}return{groupResizeBehavior:s.groupResizeBehavior,collapsedSize:o,collapsible:s.collapsible===!0,defaultSize:a,disabled:s.disabled,minSize:l,maxSize:c,panelId:r.id}})}function dt(e,t="Assertion error"){if(!e)throw Error(t)}function Ix(e,t){return Array.from(t).sort(e==="horizontal"?JK:eG)}function JK(e,t){const n=e.element.offsetLeft-t.element.offsetLeft;return n!==0?n:e.element.offsetWidth-t.element.offsetWidth}function eG(e,t){const n=e.element.offsetTop-t.element.offsetTop;return n!==0?n:e.element.offsetHeight-t.element.offsetHeight}function jP(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.ELEMENT_NODE}function LP(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 tG({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:a,y:l}=LP(r,o),c=e==="horizontal"?a:l;c<s&&(s=c,i=o)}return dt(i,"No rect found"),i}let th;function nG(){return th===void 0&&(typeof matchMedia=="function"?th=!!matchMedia("(pointer:coarse)").matches:th=!1),th}function DP(e){const{element:t,orientation:n,panels:r,separators:i}=e,s=Ix(n,Array.from(t.children).filter(jP).map(m=>({element:m}))).map(({element:m})=>m),o=[];let a=!1,l=!1,c=-1,u=-1,d=0,f,p=[];{let m=-1;for(const v of s)v.hasAttribute("data-panel")&&(m++,v.hasAttribute("data-disabled")||(d++,c===-1&&(c=m),u=m))}if(d>1){let m=-1;for(const v of s)if(v.hasAttribute("data-panel")){m++;const w=r.find(x=>x.element===v);if(w){if(f){const x=f.element.getBoundingClientRect(),_=v.getBoundingClientRect();let b;if(l){const S=n==="horizontal"?new DOMRect(x.right,x.top,0,x.height):new DOMRect(x.left,x.bottom,x.width,0),C=n==="horizontal"?new DOMRect(_.left,_.top,0,_.height):new DOMRect(_.left,_.top,_.width,0);switch(p.length){case 0:{b=[S,C];break}case 1:{const k=p[0],N=tG({orientation:n,rects:[x,_],targetRect:k.element.getBoundingClientRect()});b=[k,N===x?C:S];break}default:{b=p;break}}}else p.length?b=p:b=[n==="horizontal"?new DOMRect(x.right,_.top,_.left-x.right,_.height):new DOMRect(_.left,x.bottom,_.width,_.top-x.bottom)];for(const S of b){let C="width"in S?S:S.element.getBoundingClientRect();const k=nG()?e.resizeTargetMinimumSize.coarse:e.resizeTargetMinimumSize.fine;if(C.width<k){const E=k-C.width;C=new DOMRect(C.x-E/2,C.y,C.width+E,C.height)}if(C.height<k){const E=k-C.height;C=new DOMRect(C.x,C.y-E/2,C.width,C.height+E)}const N=m<=c||m>u;!a&&!N&&o.push({group:e,groupSize:vl({group:e}),panels:[f,w],separator:"width"in S?void 0:S,rect:C}),a=!1}}l=!1,f=w,p=[]}}else if(v.hasAttribute("data-separator")){v.ariaDisabled!==null&&(a=!0);const w=i.find(x=>x.element===v);w?p.push(w):(f=void 0,p=[])}else l=!0}return o}var Ns;class OP{constructor(){Fb(this,Ns,{})}addListener(t,n){const r=Ql(this,Ns)[t];return r===void 0?Ql(this,Ns)[t]=[n]:r.includes(n)||r.push(n),()=>{this.removeListener(t,n)}}emit(t,n){const r=Ql(this,Ns)[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 a=0;a<o.length;a++){const l=o[a];try{l.call(null,n)}catch(c){s===null&&(i=!0,s=c)}}if(i)throw s}}removeAllListeners(){Hb(this,Ns,{})}removeListener(t,n){const r=Ql(this,Ns)[t];if(r!==void 0){const i=r.indexOf(n);i>=0&&r.splice(i,1)}}}Ns=new WeakMap;let Za={cursorFlags:0,state:"inactive"};const B_=new OP;function Uo(){return Za}function rG(e){return B_.addListener("change",e)}function iG(e){const t=Za,n={...Za};n.cursorFlags=e,Za=n,B_.emit("change",{prev:t,next:n})}function Qa(e){const t=Za;Za=e,B_.emit("change",{prev:t,next:e})}const sG=e=>e,zg=()=>{},BP=1,$P=2,zP=4,FP=8,Xk=3,Zk=12;let nh;function Qk(){return nh===void 0&&(nh=!1,typeof window<"u"&&(window.navigator.userAgent.includes("Chrome")||window.navigator.userAgent.includes("Firefox"))&&(nh=!0)),nh}function oG({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&&Qk()){const s=(e&BP)!==0,o=(e&$P)!==0,a=(e&zP)!==0,l=(e&FP)!==0;if(s)return a?"se-resize":l?"ne-resize":"e-resize";if(o)return a?"sw-resize":l?"nw-resize":"w-resize";if(a)return"s-resize";if(l)return"n-resize"}break}}return Qk()?r>0&&i>0?"move":r>0?"ew-resize":"ns-resize":r>0&&i>0?"grab":r>0?"col-resize":"row-resize"}}const Jk=new WeakMap;function $_(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:n}=Jk.get(e)??{};n===void 0&&(n=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets&&(Object.isExtensible(e.adoptedStyleSheets)?e.adoptedStyleSheets.push(n):e.adoptedStyleSheets=[...e.adoptedStyleSheets,n]));const r=Uo();switch(r.state){case"active":case"hover":{const i=oG({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}}Jk.set(e,{prevStyle:t,styleSheet:n})}let gi=new Map;const HP=new OP;function aG(e){gi=new Map(gi),gi.delete(e)}function eC(e,t){for(const[n]of gi)if(n.id===e)return n}function Hs(e,t){for(const[n,r]of gi)if(n.id===e)return r;if(t)throw Error(`Could not find data for Group with id ${e}`)}function na(){return gi}function z_(e,t){return HP.addListener("groupChange",n=>{n.group.id===e&&t(n)})}function rs(e,t,n){const r=gi.get(e);gi=new Map(gi),gi.set(e,t),HP.emit("groupChange",{group:e,isUserInteraction:(n==null?void 0:n.isUserInteraction)===!0,prev:r,next:t})}function UP(e){const t=Uo();let n=!1;switch(t.state){case"active":Qa({cursorFlags:0,state:"inactive"}),t.hitRegions.length>0&&($_(e),n=!0,t.hitRegions.forEach(r=>{const i=Hs(r.group.id,!0);rs(r.group,i,{isUserInteraction:!0})}))}return n}function tC(e){e.defaultPrevented||UP(e.currentTarget)}function lG(e,t,n){let r,i={x:1/0,y:1/0};for(const s of t){const o=LP(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 cG(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function uG(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:iC(e),b:iC(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();dt(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:rC(nC(n.a)),b:rC(nC(n.b))};if(i.a===i.b){const s=r.childNodes,o={a:n.a.at(-1),b:n.b.at(-1)};let a=s.length;for(;a--;){const l=s[a];if(l===o.a)return 1;if(l===o.b)return-1}}return Math.sign(i.a-i.b)}const dG=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function hG(e){const t=getComputedStyle(WP(e)??e).display;return t==="flex"||t==="inline-flex"}function fG(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||hG(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"||dG.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function nC(e){let t=e.length;for(;t--;){const n=e[t];if(dt(n,"Missing node"),fG(n))return n}return null}function rC(e){return e&&Number(getComputedStyle(e).zIndex)||0}function iC(e){const t=[];for(;e;)t.push(e),e=WP(e);return t}function WP(e){const{parentNode:t}=e;return cG(t)?t.host:t}function pG(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 mG({groupElement:e,hitRegion:t,pointerEventTarget:n}){if(!jP(n)||n.contains(e)||e.contains(n))return!0;if(uG(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if(pG(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function F_(e,t){const n=[];return t.forEach((r,i)=>{if(i.disabled)return;const s=DP(i),o=lG(i.orientation,s,{x:e.clientX,y:e.clientY});o&&o.distance.x<=0&&o.distance.y<=0&&mG({groupElement:i.element,hitRegion:o.hitRegion.rect,pointerEventTarget:e.target})&&n.push(o.hitRegion)}),n}function gG(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 Cn(e,t,n=0){return Math.abs(Dn(e)-Dn(t))<=n}function hi(e,t){return Cn(e,t)?0:e>t?1:-1}function $a({overrideDisabledPanels:e,panelConstraints:t,prevSize:n,size:r}){const{collapsedSize:i=0,collapsible:s,disabled:o,maxSize:a=100,minSize:l=0}=t;if(o&&!e)return n;if(hi(r,l)<0)if(s){const c=(i+l)/2;hi(r,c)<0?r=i:r=l}else r=l;return r=Math.min(a,r),r=Dn(r),r}function Ru({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(Cn(e,0))return t;const o=s==="imperative-api",a=Object.values(t),l=Object.values(i),c=[...a],[u,d]=r;dt(u!=null,"Invalid first pivot index"),dt(d!=null,"Invalid second pivot index");let f=0;switch(s){case"keyboard":{{const v=e<0?d:u,w=n[v];dt(w,`Panel constraints not found for index ${v}`);const{collapsedSize:x=0,collapsible:_,minSize:b=0}=w;if(_){const S=a[v];if(dt(S!=null,`Previous layout not found for panel index ${v}`),Cn(S,x)){const C=b-S;hi(C,Math.abs(e))>0&&(e=e<0?0-C:C)}}}{const v=e<0?u:d,w=n[v];dt(w,`No panel constraints found for index ${v}`);const{collapsedSize:x=0,collapsible:_,minSize:b=0}=w;if(_){const S=a[v];if(dt(S!=null,`Previous layout not found for panel index ${v}`),Cn(S,b)){const C=S-x;hi(C,Math.abs(e))>0&&(e=e<0?0-C:C)}}}break}default:{const v=e<0?d:u,w=n[v];dt(w,`Panel constraints not found for index ${v}`);const x=a[v],{collapsible:_,collapsedSize:b,minSize:S}=w;if(_&&hi(x,S)<0)if(e>0){const C=S-b,k=C/2,N=x+e;hi(N,S)<0&&(e=hi(e,k)<=0?0:C)}else{const C=S-b,k=100-C/2,N=x-e;hi(N,S)<0&&(e=hi(100+e,k)>0?0:-C)}break}}{const v=e<0?1:-1;let w=e<0?d:u,x=0;for(;;){const b=a[w];dt(b!=null,`Previous layout not found for panel index ${w}`);const S=$a({overrideDisabledPanels:o,panelConstraints:n[w],prevSize:b,size:100})-b;if(x+=S,w+=v,w<0||w>=n.length)break}const _=Math.min(Math.abs(e),Math.abs(x));e=e<0?0-_:_}{let v=e<0?u:d;for(;v>=0&&v<n.length;){const w=Math.abs(e)-Math.abs(f),x=a[v];dt(x!=null,`Previous layout not found for panel index ${v}`);const _=x-w,b=$a({overrideDisabledPanels:o,panelConstraints:n[v],prevSize:x,size:_});if(!Cn(x,b)&&(f+=x-b,c[v]=b,f.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?v--:v++}}if(gG(l,c))return i;{const v=e<0?d:u,w=a[v];dt(w!=null,`Previous layout not found for panel index ${v}`);const x=w+f,_=$a({overrideDisabledPanels:o,panelConstraints:n[v],prevSize:w,size:x});if(c[v]=_,!Cn(_,x)){let b=x-_,S=e<0?d:u;for(;S>=0&&S<n.length;){const C=c[S];dt(C!=null,`Previous layout not found for panel index ${S}`);const k=C+b,N=$a({overrideDisabledPanels:o,panelConstraints:n[S],prevSize:C,size:k});if(Cn(C,N)||(b-=N-C,c[S]=N),Cn(b,0))break;e>0?S--:S++}}}const p=Object.values(c).reduce((v,w)=>w+v,0);if(!Cn(p,100,.1))return i;const m=Object.keys(i);return c.reduce((v,w,x)=>(v[m[x]]=w,v),{})}function Wo(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(t[n]===void 0||hi(e[n],t[n])!==0)return!1;return!0}function qo({layout:e,panelConstraints:t}){const n=Object.values(e),r=[...n],i=r.reduce((a,l)=>a+l,0);if(r.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${r.map(a=>`${a}%`).join(", ")}`);if(!Cn(i,100)&&r.length>0)for(let a=0;a<t.length;a++){const l=r[a];dt(l!=null,`No layout data found for index ${a}`);const c=100/i*l;r[a]=c}let s=0;for(let a=0;a<t.length;a++){const l=n[a];dt(l!=null,`No layout data found for index ${a}`);const c=r[a];dt(c!=null,`No layout data found for index ${a}`);const u=$a({overrideDisabledPanels:!0,panelConstraints:t[a],prevSize:l,size:c});c!=u&&(s+=c-u,r[a]=u)}if(!Cn(s,0))for(let a=0;a<t.length;a++){const l=r[a];dt(l!=null,`No layout data found for index ${a}`);const c=l+s,u=$a({overrideDisabledPanels:!0,panelConstraints:t[a],prevSize:l,size:c});if(l!==u&&(s-=u-l,r[a]=u,Cn(s,0)))break}const o=Object.keys(e);return r.reduce((a,l,c)=>(a[o[c]]=l,a),{})}function qP({groupId:e,panelId:t}){const n=()=>{const l=na();for(const[c,{defaultLayoutDeferred:u,derivedPanelConstraints:d,layout:f,groupSize:p,separatorToPanels:m}]of l)if(c.id===e)return{defaultLayoutDeferred:u,derivedPanelConstraints:d,group:c,groupSize:p,layout:f,separatorToPanels:m};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=({nextSize:l,panels:c,prevLayout:u,derivedPanelConstraints:d})=>{const f=s(),p=c.findIndex(w=>w.id===t),m=p===0,v=p===c.length-1;if(v&&l<f&&(m||c.slice(0,p).every((w,x)=>{const _=d[x];return(_==null?void 0:_.collapsible)&&Cn(_.collapsedSize,u[_.panelId])}))){const w=c.slice(0,p).reduce((x,_)=>x+u[_.id],0);return{...u,[t]:Dn(100-w)}}return Ru({delta:v?f-l:l-f,initialLayout:u,panelConstraints:d,pivotIndices:v?[p-1,p]:[p,p+1],prevLayout:u,trigger:"imperative-api"})},a=l=>{const c=s();if(l===c)return;const{defaultLayoutDeferred:u,derivedPanelConstraints:d,group:f,groupSize:p,layout:m,separatorToPanels:v}=n(),w=o({nextSize:l,panels:f.panels,prevLayout:m,derivedPanelConstraints:d}),x=qo({layout:w,panelConstraints:d});Wo(m,x)||rs(f,{defaultLayoutDeferred:u,derivedPanelConstraints:d,groupSize:p,layout:x,separatorToPanels:v})};return{collapse:()=>{const{collapsible:l,collapsedSize:c}=r(),{mutableValues:u}=i(),d=s();l&&d!==c&&(u.expandToSize=d,a(c))},expand:()=>{const{collapsible:l,collapsedSize:c,minSize:u}=r(),{mutableValues:d}=i(),f=s();if(l&&f===c){let p=d.expandToSize??u;p===0&&(p=1),a(p)}},getSize:()=>{const{group:l}=n(),c=s(),{element:u}=i(),d=l.orientation==="horizontal"?u.offsetWidth:u.offsetHeight;return{asPercentage:c,inPixels:d}},isCollapsed:()=>{const{collapsible:l,collapsedSize:c}=r(),u=s();return l&&Cn(c,u)},resize:l=>{const{group:c}=n(),{element:u}=i(),d=vl({group:c}),f=Cc({groupSize:d,panelElement:u,styleProp:l}),p=Dn(f/d*100);a(p)}}}function sC(e){if(e.defaultPrevented)return;const t=na();F_(e,t).forEach(n=>{if(n.separator&&!n.separator.disableDoubleClick){const r=n.panels.find(i=>i.panelConstraints.defaultSize!==void 0);if(r){const i=r.panelConstraints.defaultSize,s=qP({groupId:n.group.id,panelId:r.id});s&&i!==void 0&&(s.resize(i),e.preventDefault())}}})}function Fh(e){const t=na();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 VP({groupId:e}){const t=()=>{const n=na();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:a,separatorToPanels:l}=t(),c=qo({layout:n,panelConstraints:i});return r?a:(Wo(a,c)||rs(s,{defaultLayoutDeferred:r,derivedPanelConstraints:i,groupSize:o,layout:c,separatorToPanels:l}),c)}}}function po(e,t){const n=Fh(e),r=Hs(n.id,!0),i=n.separators.find(u=>u.element===e);dt(i,"Matching separator not found");const s=r.separatorToPanels.get(i);dt(s,"Matching panels not found");const o=s.map(u=>n.panels.indexOf(u)),a=VP({groupId:n.id}).getLayout(),l=Ru({delta:t,initialLayout:a,panelConstraints:r.derivedPanelConstraints,pivotIndices:o,prevLayout:a,trigger:"keyboard"}),c=qo({layout:l,panelConstraints:r.derivedPanelConstraints});Wo(a,c)||rs(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedPanelConstraints:r.derivedPanelConstraints,groupSize:r.groupSize,layout:c,separatorToPanels:r.separatorToPanels},{isUserInteraction:!0})}function oC(e){if(e.defaultPrevented)return;const t=e.currentTarget,n=Fh(t);if(!n.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),n.orientation==="vertical"&&po(t,5);break}case"ArrowLeft":{e.preventDefault(),n.orientation==="horizontal"&&po(t,-5);break}case"ArrowRight":{e.preventDefault(),n.orientation==="horizontal"&&po(t,5);break}case"ArrowUp":{e.preventDefault(),n.orientation==="vertical"&&po(t,-5);break}case"End":{e.preventDefault(),po(t,100);break}case"Enter":{e.preventDefault();const r=Fh(t),i=Hs(r.id,!0),{derivedPanelConstraints:s,layout:o,separatorToPanels:a}=i,l=r.separators.find(f=>f.element===t);dt(l,"Matching separator not found");const c=a.get(l);dt(c,"Matching panels not found");const u=c[0],d=s.find(f=>f.panelId===u.id);if(dt(d,"Panel metadata not found"),d.collapsible){const f=o[u.id],p=d.collapsedSize===f?r.mutableState.expandedPanelSizes[u.id]??d.minSize:d.collapsedSize;po(t,p-f)}break}case"F6":{e.preventDefault();const r=Fh(t).separators.map(o=>o.element),i=Array.from(r).findIndex(o=>o===e.currentTarget);dt(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(),po(t,-100);break}}}function aC(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=na(),n=F_(e,t),r=new Map;let i=!1;n.forEach(s=>{s.separator&&(i||(i=!0,s.separator.element.focus({focusVisible:!1,preventScroll:!0})));const o=t.get(s.group);o&&r.set(s.group,o.layout)}),Qa({cursorFlags:0,hitRegions:n,initialLayoutMap:r,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}),n.length&&e.preventDefault()}function KP({document:e,event:t,hitRegions:n,initialLayoutMap:r,mountedGroups:i,pointerDownAtPoint:s,prevCursorFlags:o}){let a=0;n.forEach(c=>{const{group:u,groupSize:d}=c,{orientation:f,panels:p}=u,{disableCursor:m}=u.mutableState;let v=0;s?f==="horizontal"?v=(t.clientX-s.x)/d*100:v=(t.clientY-s.y)/d*100:f==="horizontal"?v=t.clientX<0?-100:100:v=t.clientY<0?-100:100;const w=r.get(u),x=i.get(u);if(!w||!x)return;const{defaultLayoutDeferred:_,derivedPanelConstraints:b,groupSize:S,layout:C,separatorToPanels:k}=x;if(b&&C&&k){const N=Ru({delta:v,initialLayout:w,panelConstraints:b,pivotIndices:c.panels.map(E=>p.indexOf(E)),prevLayout:C,trigger:"mouse-or-touch"});if(Wo(N,C)){if(v!==0&&!m)switch(f){case"horizontal":{a|=v<0?BP:$P;break}case"vertical":{a|=v<0?zP:FP;break}}}else rs(c.group,{defaultLayoutDeferred:_,derivedPanelConstraints:b,groupSize:S,layout:N,separatorToPanels:k})}});let l=0;t.movementX===0?l|=o&Xk:l|=a&Xk,t.movementY===0?l|=o&Zk:l|=a&Zk,iG(l),$_(e)}function lC(e){const t=na(),n=Uo();switch(n.state){case"active":KP({document:e.currentTarget,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedGroups:t,prevCursorFlags:n.cursorFlags})}}function cC(e){var r,i;if(e.defaultPrevented)return;const t=Uo(),n=na();switch(t.state){case"active":{if(e.buttons===0){Qa({cursorFlags:0,state:"inactive"}),t.hitRegions.forEach(s=>{const o=Hs(s.group.id,!0);rs(s.group,o,{isUserInteraction:!0})});return}for(const s of t.hitRegions)if(s.separator){const{element:o}=s.separator;(r=o.hasPointerCapture)!=null&&r.call(o,e.pointerId)||((i=o.setPointerCapture)==null||i.call(o,e.pointerId))}KP({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break}default:{const s=F_(e,n);s.length===0?t.state!=="inactive"&&Qa({cursorFlags:0,state:"inactive"}):Qa({cursorFlags:0,hitRegions:s,state:"hover"}),$_(e.currentTarget);break}}}function uC(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(Uo().state){case"hover":Qa({cursorFlags:0,state:"inactive"})}}function dC(e){e.defaultPrevented||e.pointerType==="mouse"&&e.button>0||UP(e.currentTarget)&&e.preventDefault()}function hC(e){let t=0,n=0;const r={};for(const s of e)if(s.defaultSize!==void 0){t++;const o=Dn(s.defaultSize);n+=o,r[s.panelId]=o}else r[s.panelId]=void 0;const i=e.length-t;if(i!==0){const s=Dn((100-n)/i);for(const o of e)o.defaultSize===void 0&&(r[o.panelId]=s)}return r}function vG(e,t,n){if(!n[0])return;const r=e.panels.find(l=>l.element===t);if(!r||!r.onResize)return;const i=vl({group:e}),s=e.orientation==="horizontal"?r.element.offsetWidth:r.element.offsetHeight,o=r.mutableValues.prevSize,a={asPercentage:Dn(s/i*100),inPixels:s};r.mutableValues.prevSize=a,r.onResize(a,r.id,o)}function xG(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 yG({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 a=new Map,l=[];for(const d of e.panels){const f=r[d.id]??0;switch(d.panelConstraints.groupResizeBehavior){case"preserve-pixel-size":{o=!0;const p=f/100*n,m=Dn(p/t*100);a.set(d.id,m),i+=m;break}case"preserve-relative-size":default:{l.push(d.id),s+=f;break}}}if(!o||l.length===0)return r;const c=100-i,u={...r};if(a.forEach((d,f)=>{u[f]=d}),s>0)for(const d of l){const f=r[d]??0;u[d]=Dn(f/s*c)}else{const d=Dn(c/l.length);for(const f of l)u[f]=d}return u}function _G(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 va=new Map;function bG(e){let t=!0;dt(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(m=>{for(const v of m){const{borderBoxSize:w,target:x}=v;if(x===e.element){if(t){const _=vl({group:e});if(_===0)return;const b=Hs(e.id);if(!b)return;const S=Ex(e),C=b.defaultLayoutDeferred?hC(S):b.layout,k=yG({group:e,nextGroupSize:_,prevGroupSize:b.groupSize,prevLayout:C}),N=qo({layout:k,panelConstraints:S});if(!b.defaultLayoutDeferred&&Wo(b.layout,N)&&xG(b.derivedPanelConstraints,S)&&b.groupSize===_)return;rs(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:S,groupSize:_,layout:N,separatorToPanels:b.separatorToPanels})}}else vG(e,x,w)}});s.observe(e.element),e.panels.forEach(m=>{dt(!r.has(m.id),`Panel ids must be unique; id "${m.id}" was used more than once`),r.add(m.id),m.onResize&&s.observe(m.element)});const o=vl({group:e}),a=Ex(e),l=e.panels.map(({id:m})=>m).join(",");let c=e.mutableState.defaultLayout;c&&(_G(e.panels,c)||(c=void 0));const u=e.mutableState.layouts[l]??c??hC(a),d=qo({layout:u,panelConstraints:a}),f=e.element.ownerDocument;va.set(f,(va.get(f)??0)+1);const p=new Map;return DP(e).forEach(m=>{m.separator&&p.set(m.separator,m.panels)}),rs(e,{defaultLayoutDeferred:o===0,derivedPanelConstraints:a,groupSize:o,layout:d,separatorToPanels:p}),e.separators.forEach(m=>{dt(!i.has(m.id),`Separator ids must be unique; id "${m.id}" was used more than once`),i.add(m.id),m.element.addEventListener("keydown",oC)}),va.get(f)===1&&(f.addEventListener("contextmenu",tC,!0),f.addEventListener("dblclick",sC,!0),f.addEventListener("pointerdown",aC,!0),f.addEventListener("pointerleave",lC),f.addEventListener("pointermove",cC),f.addEventListener("pointerout",uC),f.addEventListener("pointerup",dC,!0)),function(){t=!1,va.set(f,Math.max(0,(va.get(f)??0)-1)),aG(e),e.separators.forEach(m=>{m.element.removeEventListener("keydown",oC)}),va.get(f)||(f.removeEventListener("contextmenu",tC,!0),f.removeEventListener("dblclick",sC,!0),f.removeEventListener("pointerdown",aC,!0),f.removeEventListener("pointerleave",lC),f.removeEventListener("pointermove",cC),f.removeEventListener("pointerout",uC),f.removeEventListener("pointerup",dC,!0)),s.disconnect()}}function wG(){const[e,t]=g.useState({}),n=g.useCallback(()=>t({}),[]);return[e,n]}function H_(e){const t=g.useId();return`${e??t}`}const ra=typeof window<"u"?g.useLayoutEffect:g.useEffect;function Vc(e){const t=g.useRef(e);return ra(()=>{t.current=e},[e]),g.useCallback((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[t])}function U_(...e){return Vc(t=>{e.forEach(n=>{if(n)switch(typeof n){case"function":{n(t);break}case"object":{n.current=t;break}}})})}function W_(e){const t=g.useRef({...e});return ra(()=>{for(const n in e)t.current[n]=e[n]},[e]),t.current}const GP=g.createContext(null);function SG(e,t){const n=g.useRef({getLayout:()=>({}),setLayout:sG});g.useImperativeHandle(t,()=>n.current,[]),ra(()=>{Object.assign(n.current,VP({groupId:e}))})}function q_({children:e,className:t,defaultLayout:n,disableCursor:r,disabled:i,elementRef:s,groupRef:o,id:a,onLayoutChange:l,onLayoutChanged:c,orientation:u="horizontal",resizeTargetMinimumSize:d={coarse:20,fine:10},style:f,...p}){const m=g.useRef({onLayoutChange:{},onLayoutChanged:{}}),v=Vc(L=>{Wo(m.current.onLayoutChange,L)||(m.current.onLayoutChange=L,l==null||l(L))}),w=Vc((L,M)=>{Wo(m.current.onLayoutChanged,L)||(m.current.onLayoutChanged=L,c==null||c(L,{isUserInteraction:M}))}),x=H_(a),_=g.useRef(null),[b,S]=wG(),C=g.useRef({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:d,separators:[]}),k=U_(_,s);SG(x,o);const N=Vc((L,M)=>{const R=Uo(),A=eC(L),D=Hs(L);if(D){let z=!1;switch(R.state){case"active":{z=R.hitRegions.some(F=>F.group===A);break}}return{flexGrow:D.layout[M]??1,pointerEvents:z?"none":void 0}}if(n!=null&&n[M])return{flexGrow:n==null?void 0:n[M]}}),E=W_({defaultLayout:n,disableCursor:r}),j=g.useMemo(()=>({get disableCursor(){return!!E.disableCursor},getPanelStyles:N,id:x,orientation:u,registerPanel:L=>{const M=C.current;return M.panels=Ix(u,[...M.panels,L]),S(),()=>{M.panels=M.panels.filter(R=>R!==L),S()}},registerSeparator:L=>{const M=C.current;return M.separators=Ix(u,[...M.separators,L]),S(),()=>{M.separators=M.separators.filter(R=>R!==L),S()}},updatePanelProps:(L,{disabled:M})=>{const R=C.current.panels.find(z=>z.id===L);R&&(R.panelConstraints.disabled=M);const A=eC(x),D=Hs(x);A&&D&&rs(A,{...D,derivedPanelConstraints:Ex(A)})},updateSeparatorProps:(L,{disabled:M,disableDoubleClick:R})=>{const A=C.current.separators.find(D=>D.id===L);A&&(A.disabled=M,A.disableDoubleClick=R)}}),[N,x,S,u,E]),P=g.useRef(null);return ra(()=>{const L=_.current;if(L===null)return;const M=C.current;let R;if(E.defaultLayout!==void 0&&Object.keys(E.defaultLayout).length===M.panels.length){R={};for(const I of M.panels){const U=E.defaultLayout[I.id];U!==void 0&&(R[I.id]=U)}}const A={disabled:!!i,element:L,id:x,mutableState:{defaultLayout:R,disableCursor:!!E.disableCursor,expandedPanelSizes:C.current.lastExpandedPanelSizes,layouts:C.current.layouts},orientation:u,panels:M.panels,resizeTargetMinimumSize:M.resizeTargetMinimumSize,separators:M.separators};P.current=A;const D=bG(A),{defaultLayoutDeferred:z,derivedPanelConstraints:F,layout:$}=Hs(A.id,!0);!z&&F.length>0&&(v($),w($,!1));const O=z_(x,I=>{const{defaultLayoutDeferred:U,derivedPanelConstraints:q,layout:B}=I.next;if(U||q.length===0)return;const te=A.panels.map(({id:Y})=>Y).join(",");A.mutableState.layouts[te]=B,q.forEach(Y=>{if(Y.collapsible){const{layout:re}=I.prev??{};if(re){const ke=Cn(Y.collapsedSize,B[Y.panelId]),oe=Cn(Y.collapsedSize,re[Y.panelId]);ke&&!oe&&(A.mutableState.expandedPanelSizes[Y.panelId]=re[Y.panelId])}}});const le=Uo().state!=="active";v(B),le&&w(B,I.isUserInteraction)});return()=>{P.current=null,D(),O()}},[i,x,w,v,u,b,E]),g.useEffect(()=>{const L=P.current;L&&(L.mutableState.defaultLayout=n,L.mutableState.disableCursor=!!r)}),h.jsx(GP.Provider,{value:j,children:h.jsx("div",{...p,className:t,"data-group":!0,"data-testid":x,id:x,ref:k,style:{height:"100%",width:"100%",overflow:"hidden",...f,display:"flex",flexDirection:u==="horizontal"?"row":"column",flexWrap:"nowrap",touchAction:u==="horizontal"?"pan-y":"pan-x"},children:e})})}q_.displayName="Group";function V_(){const e=g.useContext(GP);return dt(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function kG(e,t){const{id:n}=V_(),r=g.useRef({collapse:zg,expand:zg,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:zg});g.useImperativeHandle(t,()=>r.current,[]),ra(()=>{Object.assign(r.current,qP({groupId:n,panelId:e}))})}function Qf({children:e,className:t,collapsedSize:n="0%",collapsible:r=!1,defaultSize:i,disabled:s,elementRef:o,groupResizeBehavior:a="preserve-relative-size",id:l,maxSize:c="100%",minSize:u="0%",onResize:d,panelRef:f,style:p,...m}){const v=!!l,w=H_(l),x=W_({disabled:s}),_=g.useRef(null),b=U_(_,o),{getPanelStyles:S,id:C,orientation:k,registerPanel:N,updatePanelProps:E}=V_(),j=d!==null,P=Vc((A,D,z)=>{d==null||d(A,l,z)});ra(()=>{const A=_.current;if(A!==null){const D={element:A,id:w,idIsStable:v,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:j?P:void 0,panelConstraints:{groupResizeBehavior:a,collapsedSize:n,collapsible:r,defaultSize:i,disabled:x.disabled,maxSize:c,minSize:u}};return N(D)}},[a,n,r,i,j,w,v,c,u,P,N,x]),g.useEffect(()=>{E(w,{disabled:s})},[s,w,E]),kG(w,f);const L=()=>{const A=S(C,w);if(A)return JSON.stringify(A)},M=g.useSyncExternalStore(A=>z_(C,A),L,L);let R;return M?R=JSON.parse(M):i!==void 0?R={flexGrow:void 0,flexShrink:void 0,flexBasis:i}:R={flexGrow:1},h.jsx("div",{...m,"data-disabled":s||void 0,"data-panel":!0,"data-testid":w,id:w,ref:b,style:{...CG,display:"flex",flexBasis:0,flexShrink:1,overflow:"visible",...R},children:h.jsx("div",{className:t,style:{maxHeight:"100%",maxWidth:"100%",flexGrow:1,overflow:"auto",...p,touchAction:k==="horizontal"?"pan-y":"pan-x"},children:e})})}Qf.displayName="Panel";const CG={minHeight:0,maxHeight:"100%",height:"auto",minWidth:0,maxWidth:"100%",width:"auto",border:"none",borderWidth:0,padding:0,margin:0};function EG({layout:e,panelConstraints:t,panelId:n,panelIndex:r}){let i,s;const o=e[n],a=t.find(l=>l.panelId===n);if(a){const l=a.maxSize,c=a.collapsible?a.collapsedSize:a.minSize,u=[r,r+1];s=qo({layout:Ru({delta:c-o,initialLayout:e,panelConstraints:t,pivotIndices:u,prevLayout:e}),panelConstraints:t})[n],i=qo({layout:Ru({delta:l-o,initialLayout:e,panelConstraints:t,pivotIndices:u,prevLayout:e}),panelConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:s,valueNow:o}}function YP({children:e,className:t,disabled:n,disableDoubleClick:r,elementRef:i,id:s,style:o,...a}){const l=H_(s),c=W_({disabled:n,disableDoubleClick:r}),[u,d]=g.useState({}),[f,p]=g.useState("inactive"),[m,v]=g.useState(!1),w=g.useRef(null),x=U_(w,i),{disableCursor:_,id:b,orientation:S,registerSeparator:C,updateSeparatorProps:k}=V_(),N=S==="horizontal"?"vertical":"horizontal";ra(()=>{const P=w.current;if(P!==null){const L={disabled:c.disabled,disableDoubleClick:c.disableDoubleClick,element:P,id:l},M=C(L),R=rG(D=>{p(D.next.state!=="inactive"&&D.next.hitRegions.some(z=>z.separator===L)?D.next.state:"inactive")}),A=z_(b,D=>{const{derivedPanelConstraints:z,layout:F,separatorToPanels:$}=D.next,O=$.get(L);if(O){const I=O[0],U=O.indexOf(I);d(EG({layout:F,panelConstraints:z,panelId:I.id,panelIndex:U}))}});return()=>{R(),A(),M()}}},[b,l,C,c]),g.useEffect(()=>{k(l,{disabled:n,disableDoubleClick:r})},[n,r,l,k]);let E;n&&!_&&(E="not-allowed");let j;if(n)j="disabled";else switch(f){case"active":{j="active";break}default:m?j="focus":j=f}return h.jsx("div",{...a,"aria-controls":u.valueControls,"aria-disabled":n||void 0,"aria-orientation":N,"aria-valuemax":u.valueMax,"aria-valuemin":u.valueMin,"aria-valuenow":u.valueNow,children:e,className:t,"data-separator":j,"data-testid":l,id:l,onBlur:()=>v(!1),onFocus:()=>v(!0),ref:x,role:"separator",style:{flexBasis:"auto",cursor:E,...o,flexGrow:0,flexShrink:0,touchAction:"none"},tabIndex:n?void 0:0})}YP.displayName="Separator";function IG(e){if(!e)return;const t=e.contextUsage,n=e.contextWindowSize;if(!t||!n||n<=0)return;const r=t.inputTokens+(t.cacheReadTokens??0)+(t.cacheCreateTokens??0);if(!(r<=0))return Math.round(r/n*100)}function XP(e,t){const n=os(),r=e?`session/${e}`:"",i=es(r)??Fo,s=g.useCallback(d=>{!e||!r||n.setData(r,f=>Hf(f??Fo,d,e))},[n,r,e]),o=g.useCallback(()=>{e&&s({type:"session:change",sessionId:e})},[s,e]),a=g.useCallback(d=>{e&&s({type:"permission:clear",sessionId:e,requestId:d})},[s,e]),l=g.useCallback(d=>{e&&s({type:"permission:request",sessionId:e,requestId:d.requestId,tool:d.tool,input:d.input,...d.toolUseId?{toolUseId:d.toolUseId}:{}})},[s,e]),c=g.useCallback(d=>{e&&s({type:"session:question:clear",sessionId:e,toolUseId:d})},[s,e]),u=g.useCallback((d,f)=>{e&&s({type:"session:question:submitted",sessionId:e,toolUseId:d,answers:f})},[s,e]);return{...i,reset:o,clearPermission:a,restorePermission:l,clearQuestion:c,markQuestionSubmitted:u}}function NG(e){return e.kind!=="user-text"?!1:e.meta===void 0||e.meta==="slash-command"||Qp(e.meta)}function TG(e,t={}){let n=0;if(t.implicitCloseOnUserText){for(const r of e)NG(r)&&n++;return n}for(const r of e)r.kind==="turn-end"&&n++;return n}const PG=g.createContext(null);function bm(){return g.useContext(PG)}const RG=50;function MG({api:e,sessionId:t,focused:n=!0,toolSessionId:r,initialTurns:i,implicitCloseOnUserText:s,pageSize:o=RG,enabled:a=!0,refreshVersion:l=0}){const c=bm(),[u,d]=g.useState({messages:[],total:0,loading:!1,error:null}),f=g.useRef(r),p=g.useRef(n),m=g.useRef(null),v=g.useRef(l),w=g.useRef(0),x=g.useRef(!0);return g.useEffect(()=>(x.current=!0,()=>{x.current=!1}),[]),g.useEffect(()=>{const _=f.current;f.current=r;const b=n&&!p.current;if(p.current=n,!a){m.current!==null&&(m.current=null,++w.current,d({messages:[],total:0,loading:!1,error:null}));return}const S=m.current!==t,C=v.current!==l;v.current=l;const k=typeof _=="string"&&_!==r,N=b&&u.error!==null;if(_!==r&&(c==null||c.push({level:"info",msg:"chatflow.history.identity",sessionId:t,meta:{previousToolSessionId:_??null,toolSessionId:r??null,willReload:S||k}})),!S&&!k&&!N&&!C)return;if((S||k)&&d({messages:[],total:0,loading:!1,error:null}),!t){m.current=null;return}m.current=t;const E=++w.current;c==null||c.push({level:"info",msg:"chatflow.history.read.start",sessionId:t,meta:{toolSessionId:r??null,initialTurns:i??null,pageSize:i===void 0?null:o,readSeq:E}}),d(j=>({...j,loading:!0,error:null})),(async()=>{var A;let j=[],P=!1,L,M=i===void 0?{}:{limit:o},R=Number.POSITIVE_INFINITY;for(;;){let D;try{D=await e.historyRead({sessionId:t,...M})}catch(q){if(E!==w.current||!x.current)return;const B=q.message??"history load failed";c==null||c.push({level:"warn",msg:"chatflow.history.read.error",sessionId:t,meta:{readSeq:E,shown:P,errorCode:q&&typeof q=="object"&&"code"in q?String(q.code):null}}),d(te=>({...te,loading:!1,error:B}));return}if(E!==w.current||!x.current)return;c==null||c.push({level:"info",msg:"chatflow.history.read.result",sessionId:t,meta:{readSeq:E,pageMessages:((A=D.messages)==null?void 0:A.length)??0,total:D.total??0,offset:D.offset??null}}),L&&D.snapshotId&&L!==D.snapshotId&&(j=[],P=!1,R=Number.POSITIVE_INFINITY,d({messages:[],total:0,loading:!0,error:null})),L=D.snapshotId,j=[...D.messages??[],...j];const z=D.total??0,F=typeof D.offset=="number"?D.offset:0,$=F>=R,O=F<=0||$;R=F;const I=i!==void 0&&TG(j,{implicitCloseOnUserText:s})>=i;if(P?d({messages:j,total:z,loading:!1,error:null}):(O||I)&&(P=!0,d({messages:j,total:z,loading:!1,error:null})),O)return;const U=Math.max(0,F-o);M={offset:U,limit:F-U,...L?{snapshotId:L}:{}}}})()},[e,t,r,n,o,i,a,l,c]),u}const AG=["TaskCreate","TaskUpdate","TaskList","TaskGet"];function jG(e){return AG.includes(e)}function ZP(e){return e==="in_progress"||e==="completed"?e:"pending"}function LG(e,t){if(!t||typeof t!="object")return e;const n=t,r=typeof n.subject=="string"&&n.subject?n.subject:typeof n.content=="string"&&n.content?n.content:null;if(!r)return e;const i=typeof n.activeForm=="string"?n.activeForm:void 0,s=typeof n.description=="string"?n.description:void 0;return[...e,{id:String(e.length+1),content:r,status:ZP(n.status),activeForm:i,description:s}]}function DG(e,t){if(!t||typeof t!="object")return e;const n=t,r=typeof n.taskId=="string"&&n.taskId?n.taskId:typeof n.id=="string"&&n.id?n.id:null;if(!r)return e;const i=e.findIndex(a=>a.id===r);if(i<0)return e;const s=[...e],o={...s[i]};return"status"in n&&(o.status=ZP(n.status)),typeof n.subject=="string"&&(o.content=n.subject),typeof n.content=="string"&&(o.content=n.content),typeof n.activeForm=="string"&&(o.activeForm=n.activeForm),typeof n.description=="string"&&(o.description=n.description),s[i]=o,s}function OG(e){let t=[],n=-1;for(let r=0;r<e.length;r++){const i=e[r];if(i.kind==="task-event")switch(n=r,i.name){case"TaskCreate":t=LG(t,i.input);break;case"TaskUpdate":t=DG(t,i.input);break}}return{tasks:t,lastEventIndex:n}}function BG(e){return e==="TodoWrite"}function $G(e){if(!e||typeof e!="object")return null;const t=e;if(!Array.isArray(t.todos))return null;const n=[];for(const r of t.todos){if(!r||typeof r!="object")continue;const i=r,s=typeof i.content=="string"?i.content:"";if(!s)continue;const o=i.status==="in_progress"||i.status==="completed"?i.status:"pending",a=typeof i.activeForm=="string"?i.activeForm:void 0;n.push({content:s,status:o,activeForm:a})}return n}function Hh(e,t,n){var o;const r=[],i=new Map;for(let a=0;a<e.length;a++){const l=e[a],c=typeof l.seq=="number"?l.seq:a;switch(l.kind){case"session_init":r.push({kind:"session-init",seq:c,toolSessionId:l.toolSessionId});break;case"text":fC(r,c,"assistant-text",l.text,l.partialId,l.uuid);break;case"thinking":fC(r,c,"assistant-thinking",l.text,l.partialId);break;case"user_text":{l.meta==="task-notification"?r.push({kind:"agent-notification",seq:c,text:l.text,taskId:l.taskId,parentToolUseId:l.parentToolUseId}):l.meta?r.push({kind:"user-meta",seq:c,metaKind:l.meta,text:l.text}):r.push({kind:"user-text",seq:c,text:l.text,uuid:l.uuid,...l.sender&&(l.sender.principal!=="owner"||KT.test(l.text))?{senderDisplayName:l.sender.displayName}:{},senderPrincipal:((o=l.sender)==null?void 0:o.principal)==="guest"?"guest":"owner"});break}case"tool_call":QP(r,c,l.toolUseId,l.tool,l.input,l.toolKind);break;case"tool_result":{const u=i.get(l.toolUseId);if(u!==void 0){if(l.askQuestionAnswers){const f=r[u];f.submittedAnswers=l.askQuestionAnswers}i.delete(l.toolUseId);break}const d={kind:"tool-result",seq:c,toolUseId:l.toolUseId,output:l.output,error:l.error};l.toolResultExtra&&(d.toolResultExtra=l.toolResultExtra),r.push(d);break}case"attachment_memories":r.push({kind:"memory-callout",seq:c,memories:l.memories});break;case"permission_request":{if(!t||l.requestId!==t)break;r.push({kind:"permission-inline",seq:c,requestId:l.requestId,tool:l.tool,input:l.input});break}case"ask_user_question":i.set(l.toolUseId,r.length),r.push({kind:"question-card",seq:c,toolUseId:l.toolUseId,questions:l.questions});break;case"turn_end":{const u={kind:"turn-end",seq:c};l.durationMs!==void 0&&(u.durationMs=l.durationMs),l.reason!==void 0&&(u.reason=l.reason),l.turnId!==void 0&&(u.turnId=l.turnId),r.push(u);break}case"subagent_progress":{const u={kind:"agent-progress",seq:c,toolUseId:l.toolUseId,agentId:l.agentId,status:l.status};l.description&&(u.description=l.description),l.lastToolName&&(u.lastToolName=l.lastToolName),l.prompt&&(u.prompt=l.prompt),l.stats&&(u.stats=l.stats),r.push(u);break}case"error":r.push({kind:"error",seq:c,message:l.message});break}}const s=new Map(e.flatMap((a,l)=>a.turnId?[[a.seq??l,a.turnId]]:[]));for(const a of r){const l=s.get(a.seq);l&&(a.turnId=l)}for(let a=1;a<r.length;a++){const l=r[a],c=r[a-1];if(l.kind!=="session-init"||!l.turnId||c.kind!=="turn-end"||c.reason!=="interrupted"||c.turnId)continue;let u=a-1;for(;u>0&&r[u-1].kind!=="turn-end";)u--;for(;u<a-1&&r[u].kind==="session-init";)u++;const d=r.slice(u,a);if(!d.some(f=>f.turnId&&f.turnId!==l.turnId)){for(const f of d)f.turnId=l.turnId;r.splice(a,1),a--}}return r}function QP(e,t,n,r,i,s){if(BG(r)){const o=$G(i);if(o){e.push({kind:"todo-checklist",seq:t,toolUseId:n,todos:o});return}}if(r==="Agent"){const o=i??{},a=typeof o.description=="string"&&o.description?o.description:typeof o.subagent_type=="string"&&o.subagent_type?o.subagent_type:"Subagent";e.push({kind:"agent-call",seq:t,toolUseId:n,description:a,input:i});return}if(jG(r)){e.push({kind:"task-event",seq:t,toolUseId:n,name:r,input:i});return}e.push({kind:"tool-call",seq:t,toolUseId:n,tool:r,toolKind:s,input:i})}function fC(e,t,n,r,i,s){let o=-1;for(let c=e.length-1;c>=0;c--)if(e[c].kind===n){o=c;break}const a=o>=0?e[o]:null;if(i){if(a&&a.partialId===i){const u=n==="assistant-text"?{kind:n,seq:a.seq,text:a.text+r,partialId:i,...s?{uuid:s}:{}}:{kind:n,seq:a.seq,text:a.text+r,partialId:i};e[o]=u;return}const c=n==="assistant-text"?{kind:n,seq:t,text:r,partialId:i,...s?{uuid:s}:{}}:{kind:n,seq:t,text:r,partialId:i};e.push(c);return}if(a&&a.partialId){const c=n==="assistant-text"?{kind:n,seq:a.seq,text:r,...s?{uuid:s}:{}}:{kind:n,seq:a.seq,text:r};e[o]=c;return}const l=n==="assistant-text"?{kind:n,seq:t,text:r,...s?{uuid:s}:{}}:{kind:n,seq:t,text:r};e.push(l)}const zG="AskUserQuestion";function K_(e,t=0,n){var o;const r=[],i=new Map;let s=t;for(const a of e){const l=s++,c=a.toolUseId??`hist-${l}`;switch(a.kind){case"user-text":if(a.meta==="task-notification")r.push({kind:"agent-notification",seq:l,text:a.text??"",taskId:a.taskId,parentToolUseId:a.parentToolUseId});else if(a.meta)r.push({kind:"user-meta",seq:l,metaKind:a.meta,text:a.text??""});else{const u=KT.exec(a.text??""),d=(o=X$.exec(a.text??""))==null?void 0:o[1],f=(u==null?void 0:u[2])??d,p=(u==null?void 0:u[1])==="guest"||d?"guest":"owner";r.push({kind:"user-text",seq:l,text:a.text??"",uuid:a.uuid,...f?{senderDisplayName:f}:{},senderPrincipal:p})}break;case"assistant-text":r.push({kind:"assistant-text",seq:l,text:a.text??"",uuid:a.uuid});break;case"tool_call":{if(a.tool===zG){const u=a.input??{},d=Array.isArray(u.questions)?u.questions:[];i.set(c,r.length),r.push({kind:"question-card",seq:l,toolUseId:c,questions:d});break}QP(r,l,c,a.tool??"",a.input,n);break}case"tool_result":{const u=i.get(c);if(u!==void 0){if(a.askQuestionAnswers){const f=r[u];f.submittedAnswers=a.askQuestionAnswers}i.delete(c);break}const d={kind:"tool-result",seq:l,toolUseId:c,output:a.output};a.error!==void 0&&(d.error=a.error),a.toolResultExtra&&(d.toolResultExtra=a.toolResultExtra),r.push(d);break}case"attachment_memories":a.memories&&a.memories.length>0&&r.push({kind:"memory-callout",seq:l,memories:a.memories});break;case"summary":break;case"turn-end":{const u={kind:"turn-end",seq:l};typeof a.durationMs=="number"&&(u.durationMs=a.durationMs),typeof a.turnId=="string"&&(u.turnId=a.turnId),r.push(u);break}}}return r}const FG=5e5;function HG(e){const t=FG-e.length;return e.map(n=>({...n,seq:n.seq+t}))}const pC=/\[attachment:(image|file):([^\]]+)\]/g;function mC(e){try{return decodeURIComponent(e)}catch{return e}}function UG(e){var n,r;if(e.startsWith("data:")){const i=e.slice(5,e.indexOf(",")),s=(n=/;name=([^;]+)/i.exec(i))==null?void 0:n[1];if(s)return mC(s);const o=(r=i.split(";")[0])==null?void 0:r.toLowerCase(),a={"text/plain":"txt","application/pdf":"pdf","image/png":"png","image/jpeg":"jpg","image/gif":"gif","image/webp":"webp"}[o??""];return(o!=null&&o.startsWith("image/")?"图片":"附件")+(a?"."+a:"")}const t=e.split(/[?#]/,1)[0];return mC(t.split("/").pop()||"附件")}function Jf(e){const t=[];let n;for(;(n=pC.exec(e))!==null;){const i=n[2],s=UG(i);t.push({type:n[1],url:i,fileName:s})}const r=e.replace(pC,"").trim();return{attachments:t,text:r}}function WG(e,t){const n=t.filter(i=>i.status==="done"&&i.url);return n.length===0?e:n.map(i=>`[attachment:${i.mimeType.startsWith("image/")?"image":"file"}:${i.url}]`).join(`
|
|
536
|
+
`)},Hq=0,ga=[];function Uq(e){var t=g.useRef([]),n=g.useRef([0,0]),r=g.useRef(),i=g.useState(Hq++)[0],s=g.useState(S3)[0],o=g.useRef(e);g.useEffect(function(){o.current=e},[e]),g.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(i));var v=uq([e.lockRef.current],(e.shards||[]).map(Uk),!0).filter(Boolean);return v.forEach(function(w){return w.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),v.forEach(function(w){return w.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var a=g.useCallback(function(v,w){if("touches"in v&&v.touches.length===2||v.type==="wheel"&&v.ctrlKey)return!o.current.allowPinchZoom;var x=Jd(v),_=n.current,b="deltaX"in v?v.deltaX:_[0]-x[0],S="deltaY"in v?v.deltaY:_[1]-x[1],C,k=v.target,N=Math.abs(b)>Math.abs(S)?"h":"v";if("touches"in v&&N==="h"&&k.type==="range")return!1;var E=window.getSelection(),j=E&&E.anchorNode,P=j?j===k||j.contains(k):!1;if(P)return!1;var L=Fk(N,k);if(!L)return!0;if(L?C=N:(C=N==="v"?"h":"v",L=Fk(N,k)),!L)return!1;if(!r.current&&"changedTouches"in v&&(b||S)&&(r.current=C),!C)return!0;var M=r.current||C;return $q(M,w,v,M==="h"?b:S)},[]),l=g.useCallback(function(v){var w=v;if(!(!ga.length||ga[ga.length-1]!==s)){var x="deltaY"in w?Hk(w):Jd(w),_=t.current.filter(function(C){return C.name===w.type&&(C.target===w.target||w.target===C.shadowParent)&&zq(C.delta,x)})[0];if(_&&_.should){w.cancelable&&w.preventDefault();return}if(!_){var b=(o.current.shards||[]).map(Uk).filter(Boolean).filter(function(C){return C.contains(w.target)}),S=b.length>0?a(w,b[0]):!o.current.noIsolation;S&&w.cancelable&&w.preventDefault()}}},[]),c=g.useCallback(function(v,w,x,_){var b={name:v,delta:w,target:x,should:_,shadowParent:Wq(x)};t.current.push(b),setTimeout(function(){t.current=t.current.filter(function(S){return S!==b})},1)},[]),u=g.useCallback(function(v){n.current=Jd(v),r.current=void 0},[]),d=g.useCallback(function(v){c(v.type,Hk(v),v.target,a(v,e.lockRef.current))},[]),f=g.useCallback(function(v){c(v.type,Jd(v),v.target,a(v,e.lockRef.current))},[]);g.useEffect(function(){return ga.push(s),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:f}),document.addEventListener("wheel",l,ma),document.addEventListener("touchmove",l,ma),document.addEventListener("touchstart",u,ma),function(){ga=ga.filter(function(v){return v!==s}),document.removeEventListener("wheel",l,ma),document.removeEventListener("touchmove",l,ma),document.removeEventListener("touchstart",u,ma)}},[]);var p=e.removeScrollBar,m=e.inert;return g.createElement(g.Fragment,null,m?g.createElement(s,{styles:Fq(i)}):null,p?g.createElement(Mq,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Wq(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const qq=yq(w3,Uq);var fm=g.forwardRef(function(e,t){return g.createElement(hm,pi({},e,{ref:t,sideCar:qq}))});fm.classNames=hm.classNames;var Sx=["Enter"," "],Vq=["ArrowDown","PageUp","Home"],I3=["ArrowUp","PageDown","End"],Kq=[...Vq,...I3],Gq={ltr:[...Sx,"ArrowRight"],rtl:[...Sx,"ArrowLeft"]},Yq={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Qu="Menu",[Iu,Xq,Zq]=F4(Qu),[ta,N3]=io(Qu,[Zq,Hl,p3]),Ju=Hl(),T3=p3(),[P3,so]=ta(Qu),[Qq,ed]=ta(Qu),R3=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,a=Ju(t),[l,c]=g.useState(null),u=g.useRef(!1),d=Ei(s),f=H4(i);return g.useEffect(()=>{const p=()=>{u.current=!0,document.addEventListener("pointerdown",m,{capture:!0,once:!0}),document.addEventListener("pointermove",m,{capture:!0,once:!0})},m=()=>u.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",m,{capture:!0}),document.removeEventListener("pointermove",m,{capture:!0})}},[]),h.jsx(cm,{...a,children:h.jsx(P3,{scope:t,open:n,onOpenChange:d,content:l,onContentChange:c,children:h.jsx(Qq,{scope:t,onClose:g.useCallback(()=>d(!1),[d]),isUsingKeyboardRef:u,dir:f,modal:o,children:r})})})};R3.displayName=Qu;var Jq="MenuAnchor",w_=g.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Ju(n);return h.jsx(um,{...i,...r,ref:t})});w_.displayName=Jq;var S_="MenuPortal",[eV,M3]=ta(S_,{forceMount:void 0}),A3=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=so(S_,t);return h.jsx(eV,{scope:t,forceMount:n,children:h.jsx(Jr,{present:n||s.open,children:h.jsx(dm,{asChild:!0,container:i,children:r})})})};A3.displayName=S_;var Pr="MenuContent",[tV,k_]=ta(Pr),j3=g.forwardRef((e,t)=>{const n=M3(Pr,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=so(Pr,e.__scopeMenu),o=ed(Pr,e.__scopeMenu);return h.jsx(Iu.Provider,{scope:e.__scopeMenu,children:h.jsx(Jr,{present:r||s.open,children:h.jsx(Iu.Slot,{scope:e.__scopeMenu,children:o.modal?h.jsx(nV,{...i,ref:t}):h.jsx(rV,{...i,ref:t})})})})}),nV=g.forwardRef((e,t)=>{const n=so(Pr,e.__scopeMenu),r=g.useRef(null),i=Ot(t,r);return g.useEffect(()=>{const s=r.current;if(s)return b_(s)},[]),h.jsx(C_,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:Ne(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),rV=g.forwardRef((e,t)=>{const n=so(Pr,e.__scopeMenu);return h.jsx(C_,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),iV=pl("MenuContent.ScrollLock"),C_=g.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,onDismiss:p,disableOutsideScroll:m,...v}=e,w=so(Pr,n),x=ed(Pr,n),_=Ju(n),b=T3(n),S=Xq(n),[C,k]=g.useState(null),N=g.useRef(null),E=Ot(t,N,w.onContentChange),j=g.useRef(0),P=g.useRef(""),L=g.useRef(0),M=g.useRef(null),R=g.useRef("right"),A=g.useRef(0),D=m?fm:g.Fragment,z=m?{as:iV,allowPinchZoom:!0}:void 0,F=O=>{var re,ke;const I=P.current+O,U=S().filter(oe=>!oe.disabled),q=document.activeElement,B=(re=U.find(oe=>oe.ref.current===q))==null?void 0:re.textValue,te=U.map(oe=>oe.textValue),le=gV(te,I,B),Y=(ke=U.find(oe=>oe.textValue===le))==null?void 0:ke.ref.current;(function oe(Ie){P.current=Ie,window.clearTimeout(j.current),Ie!==""&&(j.current=window.setTimeout(()=>oe(""),1e3))})(I),Y&&setTimeout(()=>Y.focus())};g.useEffect(()=>()=>window.clearTimeout(j.current),[]),u_();const $=g.useCallback(O=>{var U,q;return R.current===((U=M.current)==null?void 0:U.side)&&xV(O,(q=M.current)==null?void 0:q.area)},[]);return h.jsx(tV,{scope:n,searchRef:P,onItemEnter:g.useCallback(O=>{$(O)&&O.preventDefault()},[$]),onItemLeave:g.useCallback(O=>{var I;$(O)||((I=N.current)==null||I.focus(),k(null))},[$]),onTriggerLeave:g.useCallback(O=>{$(O)&&O.preventDefault()},[$]),pointerGraceTimerRef:L,onPointerGraceIntentChange:g.useCallback(O=>{M.current=O},[]),children:h.jsx(D,{...z,children:h.jsx(im,{asChild:!0,trapped:i,onMountAutoFocus:Ne(s,O=>{var I;O.preventDefault(),(I=N.current)==null||I.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:h.jsx(Yu,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,onDismiss:p,children:h.jsx(sq,{asChild:!0,...b,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:k,onEntryFocus:Ne(l,O=>{x.isUsingKeyboardRef.current||O.preventDefault()}),preventScrollOnEntryFocus:!0,children:h.jsx(y_,{role:"menu","aria-orientation":"vertical","data-state":Z3(w.open),"data-radix-menu-content":"",dir:x.dir,..._,...v,ref:E,style:{outline:"none",...v.style},onKeyDown:Ne(v.onKeyDown,O=>{const U=O.target.closest("[data-radix-menu-content]")===O.currentTarget,q=O.ctrlKey||O.altKey||O.metaKey,B=O.key.length===1;U&&(O.key==="Tab"&&O.preventDefault(),!q&&B&&F(O.key));const te=N.current;if(O.target!==te||!Kq.includes(O.key))return;O.preventDefault();const Y=S().filter(re=>!re.disabled).map(re=>re.ref.current);I3.includes(O.key)&&Y.reverse(),pV(Y)}),onBlur:Ne(e.onBlur,O=>{O.currentTarget.contains(O.target)||(window.clearTimeout(j.current),P.current="")}),onPointerMove:Ne(e.onPointerMove,Nu(O=>{const I=O.target,U=A.current!==O.clientX;if(O.currentTarget.contains(I)&&U){const q=O.clientX>A.current?"right":"left";R.current=q,A.current=O.clientX}}))})})})})})})});j3.displayName=Pr;var sV="MenuGroup",E_=g.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return h.jsx(wt.div,{role:"group",...r,ref:t})});E_.displayName=sV;var oV="MenuLabel",L3=g.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return h.jsx(wt.div,{...r,ref:t})});L3.displayName=oV;var Xf="MenuItem",Wk="menu.itemSelect",pm=g.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=g.useRef(null),o=ed(Xf,e.__scopeMenu),a=k_(Xf,e.__scopeMenu),l=Ot(t,s),c=g.useRef(!1),u=()=>{const d=s.current;if(!n&&d){const f=new CustomEvent(Wk,{bubbles:!0,cancelable:!0});d.addEventListener(Wk,p=>r==null?void 0:r(p),{once:!0}),z4(d,f),f.defaultPrevented?c.current=!1:o.onClose()}};return h.jsx(D3,{...i,ref:l,disabled:n,onClick:Ne(e.onClick,u),onPointerDown:d=>{var f;(f=e.onPointerDown)==null||f.call(e,d),c.current=!0},onPointerUp:Ne(e.onPointerUp,d=>{var f;c.current||(f=d.currentTarget)==null||f.click()}),onKeyDown:Ne(e.onKeyDown,d=>{const f=a.searchRef.current!=="";n||f&&d.key===" "||Sx.includes(d.key)&&(d.currentTarget.click(),d.preventDefault())})})});pm.displayName=Xf;var D3=g.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=k_(Xf,n),a=T3(n),l=g.useRef(null),c=Ot(t,l),[u,d]=g.useState(!1),[f,p]=g.useState("");return g.useEffect(()=>{const m=l.current;m&&p((m.textContent??"").trim())},[s.children]),h.jsx(Iu.ItemSlot,{scope:n,disabled:r,textValue:i??f,children:h.jsx(oq,{asChild:!0,...a,focusable:!r,children:h.jsx(wt.div,{role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:Ne(e.onPointerMove,Nu(m=>{r?o.onItemLeave(m):(o.onItemEnter(m),m.defaultPrevented||m.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Ne(e.onPointerLeave,Nu(m=>o.onItemLeave(m))),onFocus:Ne(e.onFocus,()=>d(!0)),onBlur:Ne(e.onBlur,()=>d(!1))})})})}),aV="MenuCheckboxItem",O3=g.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return h.jsx(H3,{scope:e.__scopeMenu,checked:n,children:h.jsx(pm,{role:"menuitemcheckbox","aria-checked":Zf(n)?"mixed":n,...i,ref:t,"data-state":T_(n),onSelect:Ne(i.onSelect,()=>r==null?void 0:r(Zf(n)?!0:!n),{checkForDefaultPrevented:!1})})})});O3.displayName=aV;var B3="MenuRadioGroup",[lV,cV]=ta(B3,{value:void 0,onValueChange:()=>{}}),$3=g.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=Ei(r);return h.jsx(lV,{scope:e.__scopeMenu,value:n,onValueChange:s,children:h.jsx(E_,{...i,ref:t})})});$3.displayName=B3;var z3="MenuRadioItem",F3=g.forwardRef((e,t)=>{const{value:n,...r}=e,i=cV(z3,e.__scopeMenu),s=n===i.value;return h.jsx(H3,{scope:e.__scopeMenu,checked:s,children:h.jsx(pm,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":T_(s),onSelect:Ne(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});F3.displayName=z3;var I_="MenuItemIndicator",[H3,uV]=ta(I_,{checked:!1}),U3=g.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=uV(I_,n);return h.jsx(Jr,{present:r||Zf(s.checked)||s.checked===!0,children:h.jsx(wt.span,{...i,ref:t,"data-state":T_(s.checked)})})});U3.displayName=I_;var dV="MenuSeparator",W3=g.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return h.jsx(wt.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});W3.displayName=dV;var hV="MenuArrow",q3=g.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Ju(n);return h.jsx(__,{...i,...r,ref:t})});q3.displayName=hV;var N_="MenuSub",[fV,V3]=ta(N_),K3=e=>{const{__scopeMenu:t,children:n,open:r=!1,onOpenChange:i}=e,s=so(N_,t),o=Ju(t),[a,l]=g.useState(null),[c,u]=g.useState(null),d=Ei(i);return g.useEffect(()=>(s.open===!1&&d(!1),()=>d(!1)),[s.open,d]),h.jsx(cm,{...o,children:h.jsx(P3,{scope:t,open:r,onOpenChange:d,content:c,onContentChange:u,children:h.jsx(fV,{scope:t,contentId:bi(),triggerId:bi(),trigger:a,onTriggerChange:l,children:n})})})};K3.displayName=N_;var kc="MenuSubTrigger",G3=g.forwardRef((e,t)=>{const n=so(kc,e.__scopeMenu),r=ed(kc,e.__scopeMenu),i=V3(kc,e.__scopeMenu),s=k_(kc,e.__scopeMenu),o=g.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},u=g.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return g.useEffect(()=>u,[u]),g.useEffect(()=>{const d=a.current;return()=>{window.clearTimeout(d),l(null)}},[a,l]),h.jsx(w_,{asChild:!0,...c,children:h.jsx(D3,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":Z3(n.open),...e,ref:Gu(t,i.onTriggerChange),onClick:d=>{var f;(f=e.onClick)==null||f.call(e,d),!(e.disabled||d.defaultPrevented)&&(d.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:Ne(e.onPointerMove,Nu(d=>{s.onItemEnter(d),!d.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),u()},100))})),onPointerLeave:Ne(e.onPointerLeave,Nu(d=>{var p,m;u();const f=(p=n.content)==null?void 0:p.getBoundingClientRect();if(f){const v=(m=n.content)==null?void 0:m.dataset.side,w=v==="right",x=w?-5:5,_=f[w?"left":"right"],b=f[w?"right":"left"];s.onPointerGraceIntentChange({area:[{x:d.clientX+x,y:d.clientY},{x:_,y:f.top},{x:b,y:f.top},{x:b,y:f.bottom},{x:_,y:f.bottom}],side:v}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(d),d.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:Ne(e.onKeyDown,d=>{var p;const f=s.searchRef.current!=="";e.disabled||f&&d.key===" "||Gq[r.dir].includes(d.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),d.preventDefault())})})})});G3.displayName=kc;var Y3="MenuSubContent",X3=g.forwardRef((e,t)=>{const n=M3(Pr,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=so(Pr,e.__scopeMenu),o=ed(Pr,e.__scopeMenu),a=V3(Y3,e.__scopeMenu),l=g.useRef(null),c=Ot(t,l);return h.jsx(Iu.Provider,{scope:e.__scopeMenu,children:h.jsx(Jr,{present:r||s.open,children:h.jsx(Iu.Slot,{scope:e.__scopeMenu,children:h.jsx(C_,{id:a.contentId,"aria-labelledby":a.triggerId,...i,ref:c,align:"start",side:o.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:u=>{var d;o.isUsingKeyboardRef.current&&((d=l.current)==null||d.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:Ne(e.onFocusOutside,u=>{u.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:Ne(e.onEscapeKeyDown,u=>{o.onClose(),u.preventDefault()}),onKeyDown:Ne(e.onKeyDown,u=>{var p;const d=u.currentTarget.contains(u.target),f=Yq[o.dir].includes(u.key);d&&f&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),u.preventDefault())})})})})})});X3.displayName=Y3;function Z3(e){return e?"open":"closed"}function Zf(e){return e==="indeterminate"}function T_(e){return Zf(e)?"indeterminate":e?"checked":"unchecked"}function pV(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function mV(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function gV(e,t,n){const i=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let o=mV(e,Math.max(s,0));i.length===1&&(o=o.filter(c=>c!==n));const l=o.find(c=>c.toLowerCase().startsWith(i.toLowerCase()));return l!==n?l:void 0}function vV(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 a=t[s],l=t[o],c=a.x,u=a.y,d=l.x,f=l.y;u>r!=f>r&&n<(d-c)*(r-u)/(f-u)+c&&(i=!i)}return i}function xV(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return vV(n,t)}function Nu(e){return t=>t.pointerType==="mouse"?e(t):void 0}var yV=R3,_V=w_,bV=A3,wV=j3,SV=E_,kV=L3,CV=pm,EV=O3,IV=$3,NV=F3,TV=U3,PV=W3,RV=q3,MV=K3,AV=G3,jV=X3,mm="DropdownMenu",[LV]=io(mm,[N3]),Rn=N3(),[DV,Q3]=LV(mm),J3=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:a=!0}=e,l=Rn(t),c=g.useRef(null),[u,d]=$l({prop:i,defaultProp:s??!1,onChange:o,caller:mm});return h.jsx(DV,{scope:t,triggerId:bi(),triggerRef:c,contentId:bi(),open:u,onOpenChange:d,onOpenToggle:g.useCallback(()=>d(f=>!f),[d]),modal:a,children:h.jsx(yV,{...l,open:u,onOpenChange:d,dir:r,modal:a,children:n})})};J3.displayName=mm;var eP="DropdownMenuTrigger",tP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=Q3(eP,n),o=Rn(n);return h.jsx(_V,{asChild:!0,...o,children:h.jsx(wt.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...i,ref:Gu(t,s.triggerRef),onPointerDown:Ne(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:Ne(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});tP.displayName=eP;var OV="DropdownMenuPortal",nP=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Rn(t);return h.jsx(bV,{...r,...n})};nP.displayName=OV;var rP="DropdownMenuContent",iP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Q3(rP,n),s=Rn(n),o=g.useRef(!1);return h.jsx(wV,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:Ne(e.onCloseAutoFocus,a=>{var l;o.current||(l=i.triggerRef.current)==null||l.focus(),o.current=!1,a.preventDefault()}),onInteractOutside:Ne(e.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,u=l.button===2||c;(!i.modal||u)&&(o.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});iP.displayName=rP;var BV="DropdownMenuGroup",$V=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Rn(n);return h.jsx(SV,{...i,...r,ref:t})});$V.displayName=BV;var zV="DropdownMenuLabel",sP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Rn(n);return h.jsx(kV,{...i,...r,ref:t})});sP.displayName=zV;var FV="DropdownMenuItem",oP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Rn(n);return h.jsx(CV,{...i,...r,ref:t})});oP.displayName=FV;var HV="DropdownMenuCheckboxItem",aP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Rn(n);return h.jsx(EV,{...i,...r,ref:t})});aP.displayName=HV;var UV="DropdownMenuRadioGroup",WV=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Rn(n);return h.jsx(IV,{...i,...r,ref:t})});WV.displayName=UV;var qV="DropdownMenuRadioItem",VV=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Rn(n);return h.jsx(NV,{...i,...r,ref:t})});VV.displayName=qV;var KV="DropdownMenuItemIndicator",lP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Rn(n);return h.jsx(TV,{...i,...r,ref:t})});lP.displayName=KV;var GV="DropdownMenuSeparator",cP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Rn(n);return h.jsx(PV,{...i,...r,ref:t})});cP.displayName=GV;var YV="DropdownMenuArrow",XV=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Rn(n);return h.jsx(RV,{...i,...r,ref:t})});XV.displayName=YV;var ZV=e=>{const{__scopeDropdownMenu:t,children:n,open:r,onOpenChange:i,defaultOpen:s}=e,o=Rn(t),[a,l]=$l({prop:r,defaultProp:s??!1,onChange:i,caller:"DropdownMenuSub"});return h.jsx(MV,{...o,open:a,onOpenChange:l,children:n})},QV="DropdownMenuSubTrigger",uP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Rn(n);return h.jsx(AV,{...i,...r,ref:t})});uP.displayName=QV;var JV="DropdownMenuSubContent",dP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Rn(n);return h.jsx(jV,{...i,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});dP.displayName=JV;var eK=J3,tK=tP,hP=nP,fP=iP,pP=sP,mP=oP,gP=aP,nK=lP,vP=cP,rK=ZV,xP=uP,yP=dP;const P_=eK,R_=tK,gm=g.forwardRef(({className:e,sideOffset:t=4,...n},r)=>h.jsx(hP,{children:h.jsx(fP,{ref:r,sideOffset:t,className:ie("z-50 min-w-[8rem] overflow-hidden rounded-md border border-border bg-elevated p-1","text-text-100 shadow-md",e),...n})}));gm.displayName=fP.displayName;const _P=rK,M_=g.forwardRef(({className:e,...t},n)=>h.jsx(xP,{ref:n,className:ie("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none","focus:bg-bg-200 focus:text-text-100 data-[highlighted]:bg-bg-200 data-[highlighted]:text-text-100 data-[state=open]:bg-bg-200","data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...t}));M_.displayName=xP.displayName;const A_=g.forwardRef(({className:e,...t},n)=>h.jsx(hP,{children:h.jsx(yP,{ref:n,className:ie("z-50 min-w-[6rem] overflow-hidden rounded-md border border-border bg-elevated p-1","text-text-100 shadow-md",e),...t})}));A_.displayName=yP.displayName;const Ir=g.forwardRef(({className:e,inset:t,...n},r)=>h.jsx(mP,{ref:r,className:ie("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none","focus:bg-bg-200 focus:text-text-100 data-[highlighted]:bg-bg-200 data-[highlighted]:text-text-100","data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));Ir.displayName=mP.displayName;const iK=g.forwardRef(({className:e,children:t,checked:n,...r},i)=>h.jsxs(gP,{ref:i,checked:n,className:ie("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-7 pr-2 text-sm outline-none","focus:bg-bg-200 focus:text-text-100 data-[highlighted]:bg-bg-200 data-[highlighted]:text-text-100","data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...r,children:[h.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:h.jsx(nK,{children:h.jsx(no,{className:"h-3.5 w-3.5"})})}),t]}));iK.displayName=gP.displayName;const vm=g.forwardRef(({className:e,...t},n)=>h.jsx(vP,{ref:n,className:ie("-mx-1 my-1 h-px bg-border",e),...t}));vm.displayName=vP.displayName;const j_=g.forwardRef(({className:e,...t},n)=>h.jsx(pP,{ref:n,className:ie("px-2 py-1.5 text-xs font-semibold text-text-400",e),...t}));j_.displayName=pP.displayName;function sK({tool:e,className:t}){const n=QH(e);return h.jsx("span",{"data-testid":n?`session-icon-${e}`:"session-icon-default","aria-label":n?l_(e):"未知引擎",className:ie("w-3.5 h-3.5 shrink-0 inline-flex items-center justify-center",rm(e),t),children:h.jsx(nm,{tool:e,className:"w-full h-full"})})}function oK({sessionId:e,hasUnread:t,running:n=!1,awaitingUser:r=!1,style:i}){return r?h.jsx(g7,{"data-testid":`awaiting-dot-${e}`,style:i,className:"w-3 h-3 text-warning shrink-0 animate-pulse",strokeWidth:2.25,"aria-label":"awaiting user"}):t?h.jsx("span",{"data-testid":`unread-dot-${e}`,style:i,className:"w-2 h-2 rounded-full bg-error shrink-0","aria-label":"unread"}):n?h.jsx("span",{"data-testid":`running-dot-${e}`,style:i,className:"w-2 h-2 rounded-full bg-success shrink-0 animate-pulse","aria-label":"running"}):null}function bP(e){return e.compositionActive||!!e.nativeIsComposing||e.keyCode===229}function wP(e){return e.key==="Enter"&&!e.shiftKey&&!bP(e)}function td(e,t){const n=g.useRef(!1),r=g.useCallback(()=>{n.current=!0},[]),i=g.useCallback(()=>{setTimeout(()=>{n.current=!1},0)},[]);return{onKeyDown:g.useCallback(o=>{const a=o.nativeEvent;if(wP({key:o.key,shiftKey:o.shiftKey,compositionActive:n.current,nativeIsComposing:a.isComposing,keyCode:a.keyCode})){o.preventDefault(),e();return}t&&o.key==="Escape"&&(o.preventDefault(),t())},[e,t]),onCompositionStart:r,onCompositionEnd:i}}function aK({open:e,initialLabel:t,placeholder:n,onSubmit:r,onCancel:i,title:s="Edit session",fieldLabel:o="Label",testId:a="session-edit-dialog",requireNonEmpty:l=!1}){const[c,u]=g.useState(t);g.useEffect(()=>{e&&u(t)},[e,t]);const d=c.trim(),f=l&&d==="",p=()=>{f||r({label:d})},m=td(p,i);return e?Oo.createPortal(h.jsx("div",{className:"fixed inset-0 z-[10000] flex items-center justify-center bg-bg-0/40 backdrop-blur-[2px]",onClick:i,"data-testid":`${a}-overlay`,children:h.jsxs("div",{"data-testid":a,className:"w-[420px] max-w-[calc(100vw-32px)] rounded-2xl border border-text-100/[0.12] flex flex-col gap-4 p-5",style:{backgroundColor:"var(--bg-0)",boxShadow:"0 12px 40px rgba(0,0,0,0.04)"},onClick:v=>v.stopPropagation(),children:[h.jsx("div",{className:"text-[15px] font-semibold text-text-100",children:s}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-[12px] font-semibold text-text-200 mb-1",children:o}),h.jsx("input",{autoFocus:!0,type:"text",value:c,onChange:v=>u(v.target.value),...m,placeholder:n,"data-testid":`${a}-label`,className:"w-full px-3 py-2 text-[13px] bg-bg-50 border border-bg-300 rounded-lg focus:outline-none focus:border-text-300 transition-colors"})]}),h.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[h.jsx("button",{type:"button",onClick:i,className:"px-4 py-1.5 text-[12px] text-text-300 rounded-lg hover:bg-text-100/5 transition-colors cursor-pointer",children:"Cancel"}),h.jsx("button",{type:"button",onClick:p,disabled:f,"data-testid":`${a}-save`,className:"px-4 py-1.5 text-[12px] font-medium text-bg-0 rounded-lg bg-text-100 hover:bg-text-200 transition-colors cursor-pointer disabled:cursor-not-allowed disabled:opacity-40",children:"Save"})]})]})}),document.body):null}var lK=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),cK="VisuallyHidden",SP=g.forwardRef((e,t)=>h.jsx(wt.span,{...e,ref:t,style:{...lK,...e.style}}));SP.displayName=cK;var uK=SP,[xm]=io("Tooltip",[Hl]),ym=Hl(),kP="TooltipProvider",dK=700,kx="tooltip.open",[hK,L_]=xm(kP),CP=e=>{const{__scopeTooltip:t,delayDuration:n=dK,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:s}=e,o=g.useRef(!0),a=g.useRef(!1),l=g.useRef(0);return g.useEffect(()=>{const c=l.current;return()=>window.clearTimeout(c)},[]),h.jsx(hK,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:g.useCallback(()=>{window.clearTimeout(l.current),o.current=!1},[]),onClose:g.useCallback(()=>{window.clearTimeout(l.current),l.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:a,onPointerInTransitChange:g.useCallback(c=>{a.current=c},[]),disableHoverableContent:i,children:s})};CP.displayName=kP;var Tu="Tooltip",[fK,_m]=xm(Tu),EP=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:a}=e,l=L_(Tu,e.__scopeTooltip),c=ym(t),[u,d]=g.useState(null),f=bi(),p=g.useRef(0),m=o??l.disableHoverableContent,v=a??l.delayDuration,w=g.useRef(!1),[x,_]=$l({prop:r,defaultProp:i??!1,onChange:N=>{N?(l.onOpen(),document.dispatchEvent(new CustomEvent(kx))):l.onClose(),s==null||s(N)},caller:Tu}),b=g.useMemo(()=>x?w.current?"delayed-open":"instant-open":"closed",[x]),S=g.useCallback(()=>{window.clearTimeout(p.current),p.current=0,w.current=!1,_(!0)},[_]),C=g.useCallback(()=>{window.clearTimeout(p.current),p.current=0,_(!1)},[_]),k=g.useCallback(()=>{window.clearTimeout(p.current),p.current=window.setTimeout(()=>{w.current=!0,_(!0),p.current=0},v)},[v,_]);return g.useEffect(()=>()=>{p.current&&(window.clearTimeout(p.current),p.current=0)},[]),h.jsx(cm,{...c,children:h.jsx(fK,{scope:t,contentId:f,open:x,stateAttribute:b,trigger:u,onTriggerChange:d,onTriggerEnter:g.useCallback(()=>{l.isOpenDelayedRef.current?k():S()},[l.isOpenDelayedRef,k,S]),onTriggerLeave:g.useCallback(()=>{m?C():(window.clearTimeout(p.current),p.current=0)},[C,m]),onOpen:S,onClose:C,disableHoverableContent:m,children:n})})};EP.displayName=Tu;var Cx="TooltipTrigger",IP=g.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=_m(Cx,n),s=L_(Cx,n),o=ym(n),a=g.useRef(null),l=Ot(t,a,i.onTriggerChange),c=g.useRef(!1),u=g.useRef(!1),d=g.useCallback(()=>c.current=!1,[]);return g.useEffect(()=>()=>document.removeEventListener("pointerup",d),[d]),h.jsx(um,{asChild:!0,...o,children:h.jsx(wt.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:l,onPointerMove:Ne(e.onPointerMove,f=>{f.pointerType!=="touch"&&!u.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),u.current=!0)}),onPointerLeave:Ne(e.onPointerLeave,()=>{i.onTriggerLeave(),u.current=!1}),onPointerDown:Ne(e.onPointerDown,()=>{i.open&&i.onClose(),c.current=!0,document.addEventListener("pointerup",d,{once:!0})}),onFocus:Ne(e.onFocus,()=>{c.current||i.onOpen()}),onBlur:Ne(e.onBlur,i.onClose),onClick:Ne(e.onClick,i.onClose)})})});IP.displayName=Cx;var pK="TooltipPortal",[Vde,mK]=xm(pK,{forceMount:void 0}),gl="TooltipContent",NP=g.forwardRef((e,t)=>{const n=mK(gl,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=_m(gl,e.__scopeTooltip);return h.jsx(Jr,{present:r||o.open,children:o.disableHoverableContent?h.jsx(TP,{side:i,...s,ref:t}):h.jsx(gK,{side:i,...s,ref:t})})}),gK=g.forwardRef((e,t)=>{const n=_m(gl,e.__scopeTooltip),r=L_(gl,e.__scopeTooltip),i=g.useRef(null),s=Ot(t,i),[o,a]=g.useState(null),{trigger:l,onClose:c}=n,u=i.current,{onPointerInTransitChange:d}=r,f=g.useCallback(()=>{a(null),d(!1)},[d]),p=g.useCallback((m,v)=>{const w=m.currentTarget,x={x:m.clientX,y:m.clientY},_=bK(x,w.getBoundingClientRect()),b=wK(x,_),S=SK(v.getBoundingClientRect()),C=CK([...b,...S]);a(C),d(!0)},[d]);return g.useEffect(()=>()=>f(),[f]),g.useEffect(()=>{if(l&&u){const m=w=>p(w,u),v=w=>p(w,l);return l.addEventListener("pointerleave",m),u.addEventListener("pointerleave",v),()=>{l.removeEventListener("pointerleave",m),u.removeEventListener("pointerleave",v)}}},[l,u,p,f]),g.useEffect(()=>{if(o){const m=v=>{const w=v.target,x={x:v.clientX,y:v.clientY},_=(l==null?void 0:l.contains(w))||(u==null?void 0:u.contains(w)),b=!kK(x,o);_?f():b&&(f(),c())};return document.addEventListener("pointermove",m),()=>document.removeEventListener("pointermove",m)}},[l,u,o,c,f]),h.jsx(TP,{...e,ref:s})}),[vK,xK]=xm(Tu,{isInside:!1}),yK=cU("TooltipContent"),TP=g.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...a}=e,l=_m(gl,n),c=ym(n),{onClose:u}=l;return g.useEffect(()=>(document.addEventListener(kx,u),()=>document.removeEventListener(kx,u)),[u]),g.useEffect(()=>{if(l.trigger){const d=f=>{const p=f.target;p!=null&&p.contains(l.trigger)&&u()};return window.addEventListener("scroll",d,{capture:!0}),()=>window.removeEventListener("scroll",d,{capture:!0})}},[l.trigger,u]),h.jsx(Yu,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:d=>d.preventDefault(),onDismiss:u,children:h.jsxs(y_,{"data-state":l.stateAttribute,...c,...a,ref:t,style:{...a.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[h.jsx(yK,{children:r}),h.jsx(vK,{scope:n,isInside:!0,children:h.jsx(uK,{id:l.contentId,role:"tooltip",children:i||r})})]})})});NP.displayName=gl;var PP="TooltipArrow",_K=g.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=ym(n);return xK(PP,n).isInside?null:h.jsx(__,{...i,...r,ref:t})});_K.displayName=PP;function bK(e,t){const n=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),i=Math.abs(t.right-e.x),s=Math.abs(t.left-e.x);switch(Math.min(n,r,i,s)){case s:return"left";case i:return"right";case n:return"top";case r:return"bottom";default:throw new Error("unreachable")}}function wK(e,t,n=5){const r=[];switch(t){case"top":r.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case"bottom":r.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case"left":r.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case"right":r.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n});break}return r}function SK(e){const{top:t,right:n,bottom:r,left:i}=e;return[{x:i,y:t},{x:n,y:t},{x:n,y:r},{x:i,y:r}]}function kK(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 a=t[s],l=t[o],c=a.x,u=a.y,d=l.x,f=l.y;u>r!=f>r&&n<(d-c)*(r-u)/(f-u)+c&&(i=!i)}return i}function CK(e){const t=e.slice();return t.sort((n,r)=>n.x<r.x?-1:n.x>r.x?1:n.y<r.y?-1:n.y>r.y?1:0),EK(t)}function EK(e){if(e.length<=1)return e.slice();const t=[];for(let r=0;r<e.length;r++){const i=e[r];for(;t.length>=2;){const s=t[t.length-1],o=t[t.length-2];if((s.x-o.x)*(i.y-o.y)>=(s.y-o.y)*(i.x-o.x))t.pop();else break}t.push(i)}t.pop();const n=[];for(let r=e.length-1;r>=0;r--){const i=e[r];for(;n.length>=2;){const s=n[n.length-1],o=n[n.length-2];if((s.x-o.x)*(i.y-o.y)>=(s.y-o.y)*(i.x-o.x))n.pop();else break}n.push(i)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}var IK=CP,NK=EP,TK=IP,RP=NP;const Pu=IK,nd=NK,rd=TK,Ul=g.forwardRef(({className:e,sideOffset:t=4,...n},r)=>h.jsx(RP,{ref:r,sideOffset:t,className:ie("z-50 overflow-hidden rounded-sm border border-border bg-bg-0 px-2 py-1 text-xs text-text-300 shadow-md",e),...n}));Ul.displayName=RP.displayName;const PK={held:!1,indexBySessionId:new Map},RK=g.createContext(PK);function MK(){return g.useContext(RK)}const AK=Array.from({length:9},(e,t)=>({id:`switch-session-${t+1}`,combo:{key:String(t+1),mod:!0},label:`切换到第 ${t+1} 个会话`,group:"会话",desktopOnly:!0,hiddenInList:!0})),jK=[{id:"new-session",combo:{key:"n",mod:!0},label:"新建任务",description:"打开快捷新建弹窗",group:"通用",desktopOnly:!0},{id:"open-search",combo:{key:"k",mod:!0},label:"全局搜索",description:"搜会话内容 / persona / 联系人",group:"通用",desktopOnly:!0},{id:"search-tab-prev",combo:{key:"ArrowLeft",mod:!0},label:"搜索:上一组",description:"搜索浮层里切到左边那个 tab(会话 / persona / 联系人)",group:"通用"},{id:"search-tab-next",combo:{key:"ArrowRight",mod:!0},label:"搜索:下一组",description:"搜索浮层里切到右边那个 tab",group:"通用"},...AK,{id:"archive-session",combo:{key:"Backspace",mod:!0,shift:!0},label:"归档当前会话",description:"归档当前聊天区的会话,Enter 确认 / Esc 取消",group:"会话",desktopOnly:!0},{id:"tab-prev",combo:{key:"ArrowLeft",mod:!0,shift:!0},label:"上一个标签页",description:"连按快速移动,停下或松开修饰键后切换",group:"标签页"},{id:"tab-next",combo:{key:"ArrowRight",mod:!0,shift:!0},label:"下一个标签页",description:"连按快速移动,停下或松开修饰键后切换",group:"标签页"},{id:"close-tab",combo:{key:"w",mod:!0},label:"关闭当前标签页",description:"关闭当前聚焦的标签页",group:"标签页",desktopOnly:!0},{id:"toggle-hive",combo:{key:"h",mod:!0,shift:!0},label:"Hive 看板",description:"全屏看所有 agent 在干什么;Esc 或点任意行退出",group:"通用"},{id:"quit-app",combo:{key:"q",mod:!0},label:"退出 clawd",description:"退出应用,由 Electron 默认菜单处理",group:"通用",desktopOnly:!0,displayOnly:!0},{id:"send-message",combo:{key:"Enter"},label:"发送消息",description:"在输入框中发送当前内容",group:"输入",displayOnly:!0},{id:"newline",combo:{key:"Enter",shift:!0},label:"换行",description:"在输入框中插入换行",group:"输入",displayOnly:!0},{id:"interrupt",combo:{key:"Escape"},label:"打断回复",description:"打断当前回复;2 秒内按两次停止任务",group:"输入",displayOnly:!0}];jK.filter(e=>!e.displayOnly);function LK(){return/Mac|iP(hone|od|ad)/.test(navigator.platform)}const DK=10,OK=20,BK=16,qk=20,Vk=60,$K=4;function eh({testId:e,label:t,children:n}){return h.jsxs(nd,{children:[h.jsx(rd,{asChild:!0,children:h.jsx("span",{"data-testid":e,role:"img","aria-label":t,tabIndex:0,className:"inline-flex shrink-0",children:n})}),h.jsx(Ul,{side:"bottom",children:t})]})}function zK({session:e,active:t,hasUnread:n,running:r=!1,awaitingUser:i=!1,onSelect:s,onEdit:o,onDelete:a,onPin:l,onArchive:c,quickAction:u,depth:d=0,chevron:f,showCopyResume:p=!0,contactDisplayName:m,ownerPrincipalId:v,creatorDisplayName:w,dispatchedFromSessionTitle:x}){const[_,b]=g.useState(!1),S=MK(),C=S.held?S.indexBySessionId.get(e.sessionId):void 0,k=!!e.pinnedAt,N=d===0,E=d===0&&!!c,j=DK+d*OK;let P=null;u==="pin"&&N&&l?P={icon:k?h.jsx(ck,{className:"w-4 h-4"}):h.jsx(uk,{className:"w-4 h-4"}),label:k?"取消置顶":"置顶",run:()=>l(e.sessionId,!k)}:u==="archive"&&E&&c?P={icon:h.jsx(ok,{className:"w-4 h-4"}),label:"归档",run:()=>c(e.sessionId,!0)}:u==="rename"&&o&&(P={icon:h.jsx(px,{className:"w-4 h-4"}),label:"重命名",run:()=>b(!0)});const L=g.useCallback(async()=>{const z=B4(e);if(z)try{await navigator.clipboard.writeText(z)}catch{}},[e]),M=c_(e),R=e.originOwnerPrincipalId,A=R?`@${m??`…${R.slice(-8)}`}`:null,D=!!(e.ownerPersonaId&&v&&e.creatorPrincipalId&&e.creatorPrincipalId!==v&&!e.larkChatId&&!e.shiftFiredFromSessionId&&!e.dispatchedFromSessionId);return h.jsxs(h.Fragment,{children:[h.jsxs("div",{"data-testid":`session-item-${e.sessionId}`,onClick:s,style:{paddingLeft:j,display:"grid",gridTemplateColumns:f?`${BK}px ${qk}px 1fr auto ${Vk}px`:`${qk}px 1fr auto ${Vk}px`,gridTemplateAreas:f?'"chev icon name dot time"':'"icon name dot time"',columnGap:`${$K}px`,alignItems:"center"},className:ie("group relative rounded-lg cursor-pointer transition-all duration-150 pr-2.5 py-1.5",t?"bg-accent-dim":"hover:bg-sidebar-hover-bg"),children:[t?h.jsx("span",{"aria-hidden":"true",className:"absolute left-0 top-1/2 -translate-y-1/2 w-[3px] h-7 rounded-r-full bg-accent"}):null,h.jsx("div",{style:{gridArea:"chev"},className:"flex items-center justify-center",children:f??null}),h.jsx("div",{style:{gridArea:"icon"},className:"flex items-center justify-center",children:h.jsx(sK,{tool:e.tool})}),h.jsxs("div",{style:{gridArea:"name"},className:"flex items-center gap-1 min-w-0",children:[h.jsxs(Pu,{delayDuration:200,skipDelayDuration:100,children:[e.dispatchedFromSessionId?h.jsx(eh,{testId:`dispatched-icon-${e.sessionId}`,label:`来自【${x??"另一会话"}】dispatch`,children:h.jsx(F7,{"aria-hidden":"true",className:"w-3 h-3 text-accent",strokeWidth:2.25})}):null,e.shiftFiredFromSessionId?h.jsx(eh,{testId:`shift-fired-icon-${e.sessionId}`,label:"定时任务",children:h.jsx(l7,{"aria-hidden":"true",className:"w-3 h-3 text-accent",strokeWidth:2.25})}):null,e.larkChatId?h.jsx(eh,{testId:`lark-chat-icon-${e.sessionId}`,label:e.larkChatType==="p2p"?"来自飞书DM":"来自飞书群",children:h.jsx(yF,{"aria-hidden":"true",className:"w-3 h-3 text-accent",strokeWidth:2.25})}):null,D?h.jsx(eh,{testId:`guest-created-icon-${e.sessionId}`,label:w?`${w}创建`:"其他人创建",children:h.jsx(tH,{"aria-hidden":"true",className:"w-3 h-3 text-accent",strokeWidth:2.25})}):null]}),h.jsx("span",{"data-testid":`session-title-${e.sessionId}`,className:ie("text-[13px] truncate min-w-0","group-hover:whitespace-normal group-hover:overflow-visible group-hover:break-words",t?"text-text-100 font-medium":"text-text-200"),children:M}),A?h.jsx("span",{"data-testid":`session-mirror-chip-${e.sessionId}`,title:`在 ${A.replace(/^@/,"")} 的设备上`,className:"shrink-0 inline-flex items-center px-1.5 py-0 rounded text-[10px] bg-accent-dim/40 text-accent border border-accent/20 max-w-[120px] truncate",children:A}):null]}),h.jsx(oK,{sessionId:e.sessionId,hasUnread:n,running:r,awaitingUser:i,style:{gridArea:"dot"}}),C!=null?h.jsx("span",{style:{gridArea:"time"},"data-testid":`session-quick-switch-badge-${e.sessionId}`,className:"text-right shrink-0 transition-opacity duration-150 group-hover:opacity-0",children:h.jsx("span",{className:"inline-flex items-center justify-center h-[18px] px-1.5 rounded-[5px] border border-border bg-bg-200/70 text-[11px] text-text-200 font-medium leading-none",children:LK()?`⌘${C}`:`Ctrl+${C}`})}):h.jsx("span",{style:{gridArea:"time"},className:ie("text-[11px] text-text-400/70 text-right shrink-0","transition-opacity duration-150 group-hover:opacity-0"),children:e.updatedAt?eU(e.updatedAt):""}),o||a||l||c?h.jsxs("div",{className:"absolute right-2 top-[3px] flex items-center opacity-0 group-hover:opacity-100 data-[state=open]:opacity-100 transition-opacity",children:[P?h.jsx(Pu,{delayDuration:200,skipDelayDuration:100,children:h.jsxs(nd,{children:[h.jsx(rd,{asChild:!0,children:h.jsx("button",{type:"button",onClick:z=>{z.stopPropagation(),P.run()},className:"flex items-center justify-center w-7 h-7 rounded-md text-text-400 hover:text-text-100 hover:bg-text-100/5 transition-colors cursor-pointer","aria-label":P.label,"data-testid":`quick-action-${u}-${e.sessionId}`,children:P.icon})}),h.jsx(Ul,{side:"bottom",children:P.label})]})}):null,h.jsxs(P_,{modal:!1,children:[h.jsx(R_,{asChild:!0,children:h.jsx("button",{type:"button",onClick:z=>z.stopPropagation(),className:"flex items-center justify-center w-7 h-7 rounded-md text-text-400 hover:text-text-100 hover:bg-text-100/5 transition-colors cursor-pointer","aria-label":"session actions","data-testid":`session-menu-${e.sessionId}`,children:h.jsx(h4,{className:"w-4 h-4"})})}),h.jsxs(gm,{align:"end",onClick:z=>z.stopPropagation(),children:[l&&N&&h.jsxs(Ir,{onSelect:()=>l(e.sessionId,!k),"data-testid":`session-${k?"unpin":"pin"}-${e.sessionId}`,children:[k?h.jsx(ck,{className:"w-3 h-3 mr-2 text-text-400"}):h.jsx(uk,{className:"w-3 h-3 mr-2 text-text-400"}),k?"Unpin":"Pin"]}),E&&c&&h.jsxs(Ir,{onSelect:()=>c(e.sessionId,!0),"data-testid":`session-archive-${e.sessionId}`,children:[h.jsx(ok,{className:"w-3 h-3 mr-2 text-text-400"}),"Archive"]}),o&&h.jsxs(Ir,{onSelect:()=>b(!0),"data-testid":`session-rename-${e.sessionId}`,children:[h.jsx(px,{className:"w-3 h-3 mr-2 text-text-400"}),"Rename"]}),p&&e.toolSessionId?h.jsxs(Ir,{onSelect:()=>void L(),"data-testid":`session-copy-resume-${e.sessionId}`,children:[h.jsx(r_,{className:"w-3 h-3 mr-2 text-text-400"}),"Copy Resume Command"]}):null,(l||o||p&&e.toolSessionId)&&a&&h.jsx(vm,{}),a&&h.jsxs(Ir,{onSelect:()=>void a(e.sessionId),className:"text-destructive focus:text-destructive focus:bg-destructive/10","data-testid":`session-delete-${e.sessionId}`,children:[h.jsx(s_,{className:"w-3 h-3 mr-2"}),"Delete"]})]})]})]}):null]}),o?h.jsx(aK,{open:_,initialLabel:e.label??"",placeholder:e.cwd.split("/").pop()||"",onSubmit:z=>{o(e.sessionId,z),b(!1)},onCancel:()=>b(!1)}):null]})}function D_({node:e,depth:t=0,activeId:n,unreadIds:r,runningIds:i,awaitingIds:s,onSelect:o,onEdit:a,onDelete:l,onPin:c,onArchive:u,quickAction:d,getContactDisplayName:f,showCopyResume:p,ownerPrincipalId:m,getCreatorDisplayName:v,getSessionDisplayName:w,parentSession:x}){const _=e.children.length>0,{isCollapsed:b,toggle:S}=t7(),C=!b(e.session.sessionId),k=g.useCallback(E=>{E.stopPropagation(),S(e.session.sessionId)},[S,e.session.sessionId]),N=_?h.jsx("button",{type:"button",onClick:k,"data-testid":`session-chevron-${e.session.sessionId}`,"aria-label":C?"collapse":"expand","aria-expanded":C,className:"shrink-0 flex items-center justify-center w-4 h-4 text-text-400 hover:text-text-100 cursor-pointer",children:C?h.jsx(Pn,{className:"w-3 h-3"}):h.jsx(Fn,{className:"w-3 h-3"})}):null;return h.jsxs("div",{"data-testid":`session-tree-node-${e.session.sessionId}`,children:[h.jsx(zK,{session:e.session,active:n===e.session.sessionId,hasUnread:(r==null?void 0:r.has(e.session.sessionId))??!1,running:(i==null?void 0:i.has(e.session.sessionId))??!1,awaitingUser:(s==null?void 0:s.has(e.session.sessionId))??!1,onSelect:()=>o(e.session.sessionId),onEdit:a,onDelete:l,onPin:c,onArchive:u,quickAction:d,showCopyResume:p,ownerPrincipalId:m,creatorDisplayName:e.session.creatorPrincipalId?v==null?void 0:v(e.session.creatorPrincipalId):void 0,dispatchedFromSessionTitle:e.session.dispatchedFromSessionId?(w==null?void 0:w(e.session.dispatchedFromSessionId))??((x==null?void 0:x.sessionId)===e.session.dispatchedFromSessionId?c_(x):void 0):void 0,depth:t,chevron:N,contactDisplayName:e.session.originOwnerPrincipalId?f==null?void 0:f(e.session.originOwnerPrincipalId):void 0}),_&&C?h.jsx("div",{"data-testid":`session-tree-children-${e.session.sessionId}`,children:e.children.map(E=>h.jsx(D_,{node:E,depth:t+1,activeId:n,unreadIds:r,runningIds:i,awaitingIds:s,onSelect:o,onEdit:a,onDelete:l,onPin:c,onArchive:u,quickAction:d,getContactDisplayName:f,showCopyResume:p,ownerPrincipalId:m,getCreatorDisplayName:v,getSessionDisplayName:w,parentSession:e.session},E.session.sessionId))}):null]})}function FK(e){return e.forkedFromSessionId??e.dispatchedFromSessionId??e.shiftFiredFromSessionId}function O_(e,t){return e.updatedAt<t.updatedAt?1:e.updatedAt>t.updatedAt?-1:0}function MP(e){e=e.filter(s=>!s.ephemeral&&s.deployId===void 0&&s.testReleaseId===void 0);const t=new Map;for(const s of e)t.set(s.sessionId,s);const n=new Map,r=[];for(const s of e){const o=FK(s);if(o&&t.has(o)){const a=n.get(o)??[];a.push(s),n.set(o,a)}else r.push(s)}const i=s=>{const a=[...n.get(s.sessionId)??[]].sort(O_);return{session:s,children:a.map(i)}};return[...r].sort(HK).map(i)}function AP(e){return[...e].sort((t,n)=>O_(t.session,n.session))}function HK(e,t){const n=typeof e.pinnedAt=="number",r=typeof t.pinnedAt=="number";if(n&&r){const i=typeof e.pinSortOrder=="number",s=typeof t.pinSortOrder=="number";return i&&s?e.pinSortOrder-t.pinSortOrder:i?-1:s?1:t.pinnedAt-e.pinnedAt}return n?-1:r?1:O_(e,t)}function UK(e){return e.label?e.label:e.aiLabel?e.aiLabel:e.cwd.split("/").filter(Boolean).pop()??""}function Kk(e,t){const n=t.trim().toLowerCase();return n===""?!0:e.toLowerCase().includes(n)}const WK={isCollapsed:()=>!1,toggle:()=>{},prune:()=>{}};function qK({personas:e,activePersonaId:t,onSelectPersona:n,onCreateSession:r,sessions:i,activeSessionId:s,awaitingIds:o,runningIds:a,unreadIds:l,onSelectSession:c,onDeleteSession:u,ownerPrincipalId:d,creatorDisplayNameByOwnerId:f,isPersonaExpanded:p,onTogglePersonaExpanded:m,onEditSession:v,onPinSession:w,showCopyResume:x,treatSessionsAsRoots:_,searchQuery:b}){const[S,C]=g.useState(null),[k,N]=g.useState(()=>new Set),E=p??(D=>k.has(D)),j=g.useCallback(D=>{if(m){m(D);return}N(z=>{const F=new Set(z);return F.has(D)?F.delete(D):F.add(D),F})},[m]),P=g.useMemo(()=>i==null?void 0:i.filter(D=>!D.ephemeral),[i]),L=g.useMemo(()=>new Map((P??[]).map(D=>[D.sessionId,c_(D)])),[P]),M=g.useCallback(D=>f==null?void 0:f.get(D),[f]),R=g.useCallback(D=>L.get(D),[L]);if(e.length===0)return h.jsx(VK,{});const A=(b??"").trim();return A?h.jsx(t_.Provider,{value:WK,children:h.jsx("div",{"data-testid":"my-personas-list",className:"flex flex-col gap-0.5",children:e.map(D=>{const z=P?P.filter(I=>I.ownerPersonaId===D.personaId).sort((I,U)=>U.updatedAt>I.updatedAt?1:-1):[],F=Kk(D.label,A),$=z.filter(I=>Kk(UK(I),A));if(!F&&$.length===0)return null;const O=F?z:$;return h.jsx(Gk,{persona:D,active:D.personaId===t,editing:!1,onSelectPersona:n,onSubmitCreateSession:()=>{},onCancelCreateSession:()=>{},personaSessions:O,collapsed:!1,onToggleCollapsed:()=>{},activeSessionId:s??null,awaitingIds:o,runningIds:a,unreadIds:l,onSelectSession:c,onDeleteSession:u,onEditSession:v,onPinSession:w,showCopyResume:x,treatSessionsAsRoots:_,ownerPrincipalId:d,creatorDisplayNameByOwnerId:f,getCreatorDisplayName:M,getSessionDisplayName:R},D.personaId)})})}):h.jsx("div",{"data-testid":"my-personas-list",className:"flex flex-col gap-0.5",children:e.map(D=>{const z=P?P.filter(F=>F.ownerPersonaId===D.personaId).sort((F,$)=>$.updatedAt>F.updatedAt?1:-1):[];return h.jsx(Gk,{persona:D,active:D.personaId===t,editing:D.personaId===S,onSelectPersona:n,onStartCreateSession:r?()=>C(D.personaId):void 0,onSubmitCreateSession:F=>{C(null),r==null||r(D.personaId,F)},onCancelCreateSession:()=>C(null),personaSessions:z,collapsed:!E(D.personaId),onToggleCollapsed:()=>j(D.personaId),activeSessionId:s??null,awaitingIds:o,runningIds:a,unreadIds:l,onSelectSession:c,onDeleteSession:u,onEditSession:v,onPinSession:w,showCopyResume:x,treatSessionsAsRoots:_,ownerPrincipalId:d,creatorDisplayNameByOwnerId:f,getCreatorDisplayName:M,getSessionDisplayName:R},D.personaId)})})}function VK(){return h.jsx("div",{className:"px-3 py-3 text-[11px] leading-relaxed text-text-400",children:"还没有 persona。点上方 Personas 标题右侧 + 创建第一个。"})}function Gk({persona:e,active:t,editing:n,onSelectPersona:r,onStartCreateSession:i,onSubmitCreateSession:s,onCancelCreateSession:o,personaSessions:a,collapsed:l,onToggleCollapsed:c,activeSessionId:u,awaitingIds:d,runningIds:f,unreadIds:p,onSelectSession:m,onDeleteSession:v,onEditSession:w,onPinSession:x,showCopyResume:_,treatSessionsAsRoots:b,ownerPrincipalId:S,creatorDisplayNameByOwnerId:C,getCreatorDisplayName:k,getSessionDisplayName:N}){const E=a.length>0,j=!l,P=g.useMemo(()=>{const R=[],A=new Map;for(const D of a){const z=D.creatorPrincipalId;if(D.larkChatId!=null||!z||S&&z===S){R.push(D);continue}const F=z,$=(C==null?void 0:C.get(F))??`…${F.slice(-8)}`,O=A.get(F);O?O.sessions.push(D):A.set(F,{groupKey:F,displayName:$,sessions:[D]})}return{self:R,byPeer:[...A.values()]}},[a,S,C]),L=P.byPeer.length>0,M=g.useMemo(()=>j&&!L?AP(MP(a)):[],[j,L,a]);return h.jsxs("div",{"data-testid":`persona-node-${e.personaId}`,children:[h.jsxs("div",{className:ie("group flex items-center gap-1 px-2 py-1.5 cursor-pointer",t?"bg-accent-dim text-text-100":"hover:bg-bg-200 text-text-200"),onClick:()=>r==null?void 0:r(e.personaId),role:"button",tabIndex:0,children:[E?h.jsx("button",{type:"button",onClick:R=>{R.stopPropagation(),c()},"aria-label":j?"collapse":"expand","aria-expanded":j,"data-testid":`persona-chevron-${e.personaId}`,className:"flex h-4 w-4 shrink-0 items-center justify-center text-text-400 hover:text-text-100",children:j?h.jsx(Pn,{className:"h-3 w-3"}):h.jsx(Fn,{className:"h-3 w-3"})}):h.jsx("span",{className:"h-4 w-4 shrink-0","aria-hidden":"true"}),h.jsx(nm,{tool:e.tool,className:ie("h-3.5 w-3.5 shrink-0",rm(e.tool))}),h.jsx("span",{className:"flex-1 truncate text-[13px]",children:e.label}),E?h.jsx("span",{className:"shrink-0 text-[10px] text-text-400 tabular-nums","aria-label":`${a.length} sessions`,children:a.length}):null,i?h.jsx("button",{type:"button",onClick:R=>{R.stopPropagation(),i()},"aria-label":"新建会话",title:"新建会话","data-testid":`persona-create-session-${e.personaId}`,className:"flex h-5 w-5 shrink-0 items-center justify-center rounded text-text-400 opacity-0 hover:bg-text-100/10 hover:text-text-100 focus-visible:opacity-100 group-hover:opacity-100",children:h.jsx(g4,{className:"h-3.5 w-3.5"})}):null]}),n?h.jsx(KK,{personaId:e.personaId,tool:e.tool,onSubmit:s,onCancel:o}):null,E&&j?h.jsx("div",{"data-testid":`persona-sessions-${e.personaId}`,children:L?h.jsxs(h.Fragment,{children:[P.self.length>0&&h.jsx(Yk,{groupKey:`${e.personaId}-self`,label:"我自己",testId:`persona-sessions-${e.personaId}-self`,sessions:P.self,activeSessionId:u,awaitingIds:d,runningIds:f,unreadIds:p,onSelectSession:m,onDeleteSession:v,onEditSession:w,onPinSession:x,showCopyResume:_,ownerPrincipalId:S,getCreatorDisplayName:k,getSessionDisplayName:N}),P.byPeer.map(R=>h.jsx(Yk,{groupKey:`${e.personaId}-peer-${R.groupKey}`,label:R.displayName,testId:`persona-sessions-${e.personaId}-peer-${R.groupKey}`,sessions:R.sessions,activeSessionId:u,awaitingIds:d,runningIds:f,unreadIds:p,onSelectSession:m,onDeleteSession:v,onEditSession:w,onPinSession:x,showCopyResume:_,ownerPrincipalId:S,getCreatorDisplayName:k,getSessionDisplayName:N},`${e.personaId}-peer-${R.groupKey}`))]}):M.map(R=>h.jsx(D_,{node:R,depth:b?0:1,activeId:u,unreadIds:p,runningIds:f,awaitingIds:d,onSelect:A=>m==null?void 0:m(A),onDelete:v,onEdit:w,onPin:x,showCopyResume:_,ownerPrincipalId:S,getCreatorDisplayName:k,getSessionDisplayName:N},R.session.sessionId))}):null]})}function Yk({label:e,testId:t,sessions:n,activeSessionId:r,awaitingIds:i,runningIds:s,unreadIds:o,onSelectSession:a,onDeleteSession:l,onEditSession:c,onPinSession:u,showCopyResume:d,ownerPrincipalId:f,getCreatorDisplayName:p,getSessionDisplayName:m}){const[v,w]=g.useState(!1),x=!v,_=g.useMemo(()=>x?AP(MP(n)):[],[x,n]);return h.jsxs("div",{"data-testid":t,children:[h.jsxs("button",{type:"button",onClick:()=>w(b=>!b),"aria-label":x?"collapse":"expand","aria-expanded":x,"data-testid":`${t}-chevron`,className:"flex items-center gap-1 w-full pl-7 pr-2 py-0.5 text-[11px] text-text-400 hover:text-text-200 transition-colors",children:[x?h.jsx(Pn,{className:"h-3 w-3"}):h.jsx(Fn,{className:"h-3 w-3"}),h.jsx(_4,{className:"h-3 w-3","aria-hidden":!0}),h.jsx("span",{className:"truncate",children:e}),h.jsx("span",{className:"ml-auto tabular-nums",children:n.length})]}),x&&h.jsx("div",{children:_.map(b=>h.jsx(D_,{node:b,depth:2,activeId:r,unreadIds:o,runningIds:s,awaitingIds:i,onSelect:S=>a==null?void 0:a(S),onDelete:l,onEdit:c,onPin:u,showCopyResume:d,ownerPrincipalId:f,getCreatorDisplayName:p,getSessionDisplayName:m},b.session.sessionId))})]})}function KK({personaId:e,tool:t,onSubmit:n,onCancel:r}){const[i,s]=g.useState(""),o=g.useRef(null),a=i.trim(),l=a.length>0;g.useEffect(()=>{var d;(d=o.current)==null||d.focus()},[]);const c=g.useCallback(()=>{l&&n(a)},[l,a,n]),u=td(c,r);return h.jsxs("div",{className:"flex items-center gap-1.5 pl-9 pr-2 py-1","data-testid":`persona-new-session-row-${e}`,children:[h.jsx(nm,{tool:t,className:ie("h-3 w-3 shrink-0",rm(t))}),h.jsx("input",{ref:o,type:"text",value:i,onChange:d=>s(d.target.value),...u,onBlur:r,placeholder:"session label...","data-testid":`persona-new-session-input-${e}`,className:"flex-1 min-w-0 bg-bg-100 border border-text-100/15 rounded px-1.5 py-0.5 text-[12px] text-text-100 placeholder:text-text-400 focus:outline-none focus:border-text-100/40"}),h.jsx("button",{type:"button",onMouseDown:d=>{d.preventDefault(),c()},disabled:!l,"aria-label":"确认",title:"确认(Enter)","data-testid":`persona-new-session-confirm-${e}`,className:"flex h-4 w-4 shrink-0 items-center justify-center rounded text-text-300 hover:bg-text-100/10 hover:text-text-100 disabled:opacity-30 disabled:hover:bg-transparent disabled:hover:text-text-300",children:h.jsx(no,{className:"h-3 w-3"})}),h.jsx("button",{type:"button",onMouseDown:d=>{d.preventDefault(),r()},"aria-label":"取消",title:"取消(Esc)","data-testid":`persona-new-session-cancel-${e}`,className:"flex h-4 w-4 shrink-0 items-center justify-center rounded text-text-300 hover:bg-text-100/10 hover:text-text-100",children:h.jsx(Qr,{className:"h-3 w-3"})})]})}function GK(e,t){const n=getComputedStyle(e),r=parseFloat(n.fontSize);return t*r}function YK(e,t){const n=getComputedStyle(e.ownerDocument.documentElement),r=parseFloat(n.fontSize);return t*r}function XK(e){return e/100*window.innerHeight}function ZK(e){return e/100*window.innerWidth}function QK(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 Cc({groupSize:e,panelElement:t,styleProp:n}){let r;const[i,s]=QK(n);switch(s){case"%":{r=i/100*e;break}case"px":{r=i;break}case"rem":{r=YK(t,i);break}case"em":{r=GK(t,i);break}case"vh":{r=XK(i);break}case"vw":{r=ZK(i);break}}return r}function Dn(e){return parseFloat(e.toFixed(3))}function vl({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 Ex(e){const{panels:t}=e,n=vl({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 u=Cc({groupSize:n,panelElement:i,styleProp:s.collapsedSize});o=Dn(u/n*100)}let a;if(s.defaultSize!==void 0){const u=Cc({groupSize:n,panelElement:i,styleProp:s.defaultSize});a=Dn(u/n*100)}let l=0;if(s.minSize!==void 0){const u=Cc({groupSize:n,panelElement:i,styleProp:s.minSize});l=Dn(u/n*100)}let c=100;if(s.maxSize!==void 0){const u=Cc({groupSize:n,panelElement:i,styleProp:s.maxSize});c=Dn(u/n*100)}return{groupResizeBehavior:s.groupResizeBehavior,collapsedSize:o,collapsible:s.collapsible===!0,defaultSize:a,disabled:s.disabled,minSize:l,maxSize:c,panelId:r.id}})}function dt(e,t="Assertion error"){if(!e)throw Error(t)}function Ix(e,t){return Array.from(t).sort(e==="horizontal"?JK:eG)}function JK(e,t){const n=e.element.offsetLeft-t.element.offsetLeft;return n!==0?n:e.element.offsetWidth-t.element.offsetWidth}function eG(e,t){const n=e.element.offsetTop-t.element.offsetTop;return n!==0?n:e.element.offsetHeight-t.element.offsetHeight}function jP(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.ELEMENT_NODE}function LP(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 tG({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:a,y:l}=LP(r,o),c=e==="horizontal"?a:l;c<s&&(s=c,i=o)}return dt(i,"No rect found"),i}let th;function nG(){return th===void 0&&(typeof matchMedia=="function"?th=!!matchMedia("(pointer:coarse)").matches:th=!1),th}function DP(e){const{element:t,orientation:n,panels:r,separators:i}=e,s=Ix(n,Array.from(t.children).filter(jP).map(m=>({element:m}))).map(({element:m})=>m),o=[];let a=!1,l=!1,c=-1,u=-1,d=0,f,p=[];{let m=-1;for(const v of s)v.hasAttribute("data-panel")&&(m++,v.hasAttribute("data-disabled")||(d++,c===-1&&(c=m),u=m))}if(d>1){let m=-1;for(const v of s)if(v.hasAttribute("data-panel")){m++;const w=r.find(x=>x.element===v);if(w){if(f){const x=f.element.getBoundingClientRect(),_=v.getBoundingClientRect();let b;if(l){const S=n==="horizontal"?new DOMRect(x.right,x.top,0,x.height):new DOMRect(x.left,x.bottom,x.width,0),C=n==="horizontal"?new DOMRect(_.left,_.top,0,_.height):new DOMRect(_.left,_.top,_.width,0);switch(p.length){case 0:{b=[S,C];break}case 1:{const k=p[0],N=tG({orientation:n,rects:[x,_],targetRect:k.element.getBoundingClientRect()});b=[k,N===x?C:S];break}default:{b=p;break}}}else p.length?b=p:b=[n==="horizontal"?new DOMRect(x.right,_.top,_.left-x.right,_.height):new DOMRect(_.left,x.bottom,_.width,_.top-x.bottom)];for(const S of b){let C="width"in S?S:S.element.getBoundingClientRect();const k=nG()?e.resizeTargetMinimumSize.coarse:e.resizeTargetMinimumSize.fine;if(C.width<k){const E=k-C.width;C=new DOMRect(C.x-E/2,C.y,C.width+E,C.height)}if(C.height<k){const E=k-C.height;C=new DOMRect(C.x,C.y-E/2,C.width,C.height+E)}const N=m<=c||m>u;!a&&!N&&o.push({group:e,groupSize:vl({group:e}),panels:[f,w],separator:"width"in S?void 0:S,rect:C}),a=!1}}l=!1,f=w,p=[]}}else if(v.hasAttribute("data-separator")){v.ariaDisabled!==null&&(a=!0);const w=i.find(x=>x.element===v);w?p.push(w):(f=void 0,p=[])}else l=!0}return o}var Ns;class OP{constructor(){Fb(this,Ns,{})}addListener(t,n){const r=Ql(this,Ns)[t];return r===void 0?Ql(this,Ns)[t]=[n]:r.includes(n)||r.push(n),()=>{this.removeListener(t,n)}}emit(t,n){const r=Ql(this,Ns)[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 a=0;a<o.length;a++){const l=o[a];try{l.call(null,n)}catch(c){s===null&&(i=!0,s=c)}}if(i)throw s}}removeAllListeners(){Hb(this,Ns,{})}removeListener(t,n){const r=Ql(this,Ns)[t];if(r!==void 0){const i=r.indexOf(n);i>=0&&r.splice(i,1)}}}Ns=new WeakMap;let Za={cursorFlags:0,state:"inactive"};const B_=new OP;function Uo(){return Za}function rG(e){return B_.addListener("change",e)}function iG(e){const t=Za,n={...Za};n.cursorFlags=e,Za=n,B_.emit("change",{prev:t,next:n})}function Qa(e){const t=Za;Za=e,B_.emit("change",{prev:t,next:e})}const sG=e=>e,zg=()=>{},BP=1,$P=2,zP=4,FP=8,Xk=3,Zk=12;let nh;function Qk(){return nh===void 0&&(nh=!1,typeof window<"u"&&(window.navigator.userAgent.includes("Chrome")||window.navigator.userAgent.includes("Firefox"))&&(nh=!0)),nh}function oG({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&&Qk()){const s=(e&BP)!==0,o=(e&$P)!==0,a=(e&zP)!==0,l=(e&FP)!==0;if(s)return a?"se-resize":l?"ne-resize":"e-resize";if(o)return a?"sw-resize":l?"nw-resize":"w-resize";if(a)return"s-resize";if(l)return"n-resize"}break}}return Qk()?r>0&&i>0?"move":r>0?"ew-resize":"ns-resize":r>0&&i>0?"grab":r>0?"col-resize":"row-resize"}}const Jk=new WeakMap;function $_(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:n}=Jk.get(e)??{};n===void 0&&(n=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets&&(Object.isExtensible(e.adoptedStyleSheets)?e.adoptedStyleSheets.push(n):e.adoptedStyleSheets=[...e.adoptedStyleSheets,n]));const r=Uo();switch(r.state){case"active":case"hover":{const i=oG({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}}Jk.set(e,{prevStyle:t,styleSheet:n})}let gi=new Map;const HP=new OP;function aG(e){gi=new Map(gi),gi.delete(e)}function eC(e,t){for(const[n]of gi)if(n.id===e)return n}function Hs(e,t){for(const[n,r]of gi)if(n.id===e)return r;if(t)throw Error(`Could not find data for Group with id ${e}`)}function na(){return gi}function z_(e,t){return HP.addListener("groupChange",n=>{n.group.id===e&&t(n)})}function rs(e,t,n){const r=gi.get(e);gi=new Map(gi),gi.set(e,t),HP.emit("groupChange",{group:e,isUserInteraction:(n==null?void 0:n.isUserInteraction)===!0,prev:r,next:t})}function UP(e){const t=Uo();let n=!1;switch(t.state){case"active":Qa({cursorFlags:0,state:"inactive"}),t.hitRegions.length>0&&($_(e),n=!0,t.hitRegions.forEach(r=>{const i=Hs(r.group.id,!0);rs(r.group,i,{isUserInteraction:!0})}))}return n}function tC(e){e.defaultPrevented||UP(e.currentTarget)}function lG(e,t,n){let r,i={x:1/0,y:1/0};for(const s of t){const o=LP(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 cG(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function uG(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:iC(e),b:iC(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();dt(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:rC(nC(n.a)),b:rC(nC(n.b))};if(i.a===i.b){const s=r.childNodes,o={a:n.a.at(-1),b:n.b.at(-1)};let a=s.length;for(;a--;){const l=s[a];if(l===o.a)return 1;if(l===o.b)return-1}}return Math.sign(i.a-i.b)}const dG=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function hG(e){const t=getComputedStyle(WP(e)??e).display;return t==="flex"||t==="inline-flex"}function fG(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||hG(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"||dG.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function nC(e){let t=e.length;for(;t--;){const n=e[t];if(dt(n,"Missing node"),fG(n))return n}return null}function rC(e){return e&&Number(getComputedStyle(e).zIndex)||0}function iC(e){const t=[];for(;e;)t.push(e),e=WP(e);return t}function WP(e){const{parentNode:t}=e;return cG(t)?t.host:t}function pG(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 mG({groupElement:e,hitRegion:t,pointerEventTarget:n}){if(!jP(n)||n.contains(e)||e.contains(n))return!0;if(uG(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if(pG(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function F_(e,t){const n=[];return t.forEach((r,i)=>{if(i.disabled)return;const s=DP(i),o=lG(i.orientation,s,{x:e.clientX,y:e.clientY});o&&o.distance.x<=0&&o.distance.y<=0&&mG({groupElement:i.element,hitRegion:o.hitRegion.rect,pointerEventTarget:e.target})&&n.push(o.hitRegion)}),n}function gG(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 Cn(e,t,n=0){return Math.abs(Dn(e)-Dn(t))<=n}function hi(e,t){return Cn(e,t)?0:e>t?1:-1}function $a({overrideDisabledPanels:e,panelConstraints:t,prevSize:n,size:r}){const{collapsedSize:i=0,collapsible:s,disabled:o,maxSize:a=100,minSize:l=0}=t;if(o&&!e)return n;if(hi(r,l)<0)if(s){const c=(i+l)/2;hi(r,c)<0?r=i:r=l}else r=l;return r=Math.min(a,r),r=Dn(r),r}function Ru({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(Cn(e,0))return t;const o=s==="imperative-api",a=Object.values(t),l=Object.values(i),c=[...a],[u,d]=r;dt(u!=null,"Invalid first pivot index"),dt(d!=null,"Invalid second pivot index");let f=0;switch(s){case"keyboard":{{const v=e<0?d:u,w=n[v];dt(w,`Panel constraints not found for index ${v}`);const{collapsedSize:x=0,collapsible:_,minSize:b=0}=w;if(_){const S=a[v];if(dt(S!=null,`Previous layout not found for panel index ${v}`),Cn(S,x)){const C=b-S;hi(C,Math.abs(e))>0&&(e=e<0?0-C:C)}}}{const v=e<0?u:d,w=n[v];dt(w,`No panel constraints found for index ${v}`);const{collapsedSize:x=0,collapsible:_,minSize:b=0}=w;if(_){const S=a[v];if(dt(S!=null,`Previous layout not found for panel index ${v}`),Cn(S,b)){const C=S-x;hi(C,Math.abs(e))>0&&(e=e<0?0-C:C)}}}break}default:{const v=e<0?d:u,w=n[v];dt(w,`Panel constraints not found for index ${v}`);const x=a[v],{collapsible:_,collapsedSize:b,minSize:S}=w;if(_&&hi(x,S)<0)if(e>0){const C=S-b,k=C/2,N=x+e;hi(N,S)<0&&(e=hi(e,k)<=0?0:C)}else{const C=S-b,k=100-C/2,N=x-e;hi(N,S)<0&&(e=hi(100+e,k)>0?0:-C)}break}}{const v=e<0?1:-1;let w=e<0?d:u,x=0;for(;;){const b=a[w];dt(b!=null,`Previous layout not found for panel index ${w}`);const S=$a({overrideDisabledPanels:o,panelConstraints:n[w],prevSize:b,size:100})-b;if(x+=S,w+=v,w<0||w>=n.length)break}const _=Math.min(Math.abs(e),Math.abs(x));e=e<0?0-_:_}{let v=e<0?u:d;for(;v>=0&&v<n.length;){const w=Math.abs(e)-Math.abs(f),x=a[v];dt(x!=null,`Previous layout not found for panel index ${v}`);const _=x-w,b=$a({overrideDisabledPanels:o,panelConstraints:n[v],prevSize:x,size:_});if(!Cn(x,b)&&(f+=x-b,c[v]=b,f.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?v--:v++}}if(gG(l,c))return i;{const v=e<0?d:u,w=a[v];dt(w!=null,`Previous layout not found for panel index ${v}`);const x=w+f,_=$a({overrideDisabledPanels:o,panelConstraints:n[v],prevSize:w,size:x});if(c[v]=_,!Cn(_,x)){let b=x-_,S=e<0?d:u;for(;S>=0&&S<n.length;){const C=c[S];dt(C!=null,`Previous layout not found for panel index ${S}`);const k=C+b,N=$a({overrideDisabledPanels:o,panelConstraints:n[S],prevSize:C,size:k});if(Cn(C,N)||(b-=N-C,c[S]=N),Cn(b,0))break;e>0?S--:S++}}}const p=Object.values(c).reduce((v,w)=>w+v,0);if(!Cn(p,100,.1))return i;const m=Object.keys(i);return c.reduce((v,w,x)=>(v[m[x]]=w,v),{})}function Wo(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(t[n]===void 0||hi(e[n],t[n])!==0)return!1;return!0}function qo({layout:e,panelConstraints:t}){const n=Object.values(e),r=[...n],i=r.reduce((a,l)=>a+l,0);if(r.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${r.map(a=>`${a}%`).join(", ")}`);if(!Cn(i,100)&&r.length>0)for(let a=0;a<t.length;a++){const l=r[a];dt(l!=null,`No layout data found for index ${a}`);const c=100/i*l;r[a]=c}let s=0;for(let a=0;a<t.length;a++){const l=n[a];dt(l!=null,`No layout data found for index ${a}`);const c=r[a];dt(c!=null,`No layout data found for index ${a}`);const u=$a({overrideDisabledPanels:!0,panelConstraints:t[a],prevSize:l,size:c});c!=u&&(s+=c-u,r[a]=u)}if(!Cn(s,0))for(let a=0;a<t.length;a++){const l=r[a];dt(l!=null,`No layout data found for index ${a}`);const c=l+s,u=$a({overrideDisabledPanels:!0,panelConstraints:t[a],prevSize:l,size:c});if(l!==u&&(s-=u-l,r[a]=u,Cn(s,0)))break}const o=Object.keys(e);return r.reduce((a,l,c)=>(a[o[c]]=l,a),{})}function qP({groupId:e,panelId:t}){const n=()=>{const l=na();for(const[c,{defaultLayoutDeferred:u,derivedPanelConstraints:d,layout:f,groupSize:p,separatorToPanels:m}]of l)if(c.id===e)return{defaultLayoutDeferred:u,derivedPanelConstraints:d,group:c,groupSize:p,layout:f,separatorToPanels:m};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=({nextSize:l,panels:c,prevLayout:u,derivedPanelConstraints:d})=>{const f=s(),p=c.findIndex(w=>w.id===t),m=p===0,v=p===c.length-1;if(v&&l<f&&(m||c.slice(0,p).every((w,x)=>{const _=d[x];return(_==null?void 0:_.collapsible)&&Cn(_.collapsedSize,u[_.panelId])}))){const w=c.slice(0,p).reduce((x,_)=>x+u[_.id],0);return{...u,[t]:Dn(100-w)}}return Ru({delta:v?f-l:l-f,initialLayout:u,panelConstraints:d,pivotIndices:v?[p-1,p]:[p,p+1],prevLayout:u,trigger:"imperative-api"})},a=l=>{const c=s();if(l===c)return;const{defaultLayoutDeferred:u,derivedPanelConstraints:d,group:f,groupSize:p,layout:m,separatorToPanels:v}=n(),w=o({nextSize:l,panels:f.panels,prevLayout:m,derivedPanelConstraints:d}),x=qo({layout:w,panelConstraints:d});Wo(m,x)||rs(f,{defaultLayoutDeferred:u,derivedPanelConstraints:d,groupSize:p,layout:x,separatorToPanels:v})};return{collapse:()=>{const{collapsible:l,collapsedSize:c}=r(),{mutableValues:u}=i(),d=s();l&&d!==c&&(u.expandToSize=d,a(c))},expand:()=>{const{collapsible:l,collapsedSize:c,minSize:u}=r(),{mutableValues:d}=i(),f=s();if(l&&f===c){let p=d.expandToSize??u;p===0&&(p=1),a(p)}},getSize:()=>{const{group:l}=n(),c=s(),{element:u}=i(),d=l.orientation==="horizontal"?u.offsetWidth:u.offsetHeight;return{asPercentage:c,inPixels:d}},isCollapsed:()=>{const{collapsible:l,collapsedSize:c}=r(),u=s();return l&&Cn(c,u)},resize:l=>{const{group:c}=n(),{element:u}=i(),d=vl({group:c}),f=Cc({groupSize:d,panelElement:u,styleProp:l}),p=Dn(f/d*100);a(p)}}}function sC(e){if(e.defaultPrevented)return;const t=na();F_(e,t).forEach(n=>{if(n.separator&&!n.separator.disableDoubleClick){const r=n.panels.find(i=>i.panelConstraints.defaultSize!==void 0);if(r){const i=r.panelConstraints.defaultSize,s=qP({groupId:n.group.id,panelId:r.id});s&&i!==void 0&&(s.resize(i),e.preventDefault())}}})}function Fh(e){const t=na();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 VP({groupId:e}){const t=()=>{const n=na();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:a,separatorToPanels:l}=t(),c=qo({layout:n,panelConstraints:i});return r?a:(Wo(a,c)||rs(s,{defaultLayoutDeferred:r,derivedPanelConstraints:i,groupSize:o,layout:c,separatorToPanels:l}),c)}}}function po(e,t){const n=Fh(e),r=Hs(n.id,!0),i=n.separators.find(u=>u.element===e);dt(i,"Matching separator not found");const s=r.separatorToPanels.get(i);dt(s,"Matching panels not found");const o=s.map(u=>n.panels.indexOf(u)),a=VP({groupId:n.id}).getLayout(),l=Ru({delta:t,initialLayout:a,panelConstraints:r.derivedPanelConstraints,pivotIndices:o,prevLayout:a,trigger:"keyboard"}),c=qo({layout:l,panelConstraints:r.derivedPanelConstraints});Wo(a,c)||rs(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedPanelConstraints:r.derivedPanelConstraints,groupSize:r.groupSize,layout:c,separatorToPanels:r.separatorToPanels},{isUserInteraction:!0})}function oC(e){if(e.defaultPrevented)return;const t=e.currentTarget,n=Fh(t);if(!n.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),n.orientation==="vertical"&&po(t,5);break}case"ArrowLeft":{e.preventDefault(),n.orientation==="horizontal"&&po(t,-5);break}case"ArrowRight":{e.preventDefault(),n.orientation==="horizontal"&&po(t,5);break}case"ArrowUp":{e.preventDefault(),n.orientation==="vertical"&&po(t,-5);break}case"End":{e.preventDefault(),po(t,100);break}case"Enter":{e.preventDefault();const r=Fh(t),i=Hs(r.id,!0),{derivedPanelConstraints:s,layout:o,separatorToPanels:a}=i,l=r.separators.find(f=>f.element===t);dt(l,"Matching separator not found");const c=a.get(l);dt(c,"Matching panels not found");const u=c[0],d=s.find(f=>f.panelId===u.id);if(dt(d,"Panel metadata not found"),d.collapsible){const f=o[u.id],p=d.collapsedSize===f?r.mutableState.expandedPanelSizes[u.id]??d.minSize:d.collapsedSize;po(t,p-f)}break}case"F6":{e.preventDefault();const r=Fh(t).separators.map(o=>o.element),i=Array.from(r).findIndex(o=>o===e.currentTarget);dt(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(),po(t,-100);break}}}function aC(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=na(),n=F_(e,t),r=new Map;let i=!1;n.forEach(s=>{s.separator&&(i||(i=!0,s.separator.element.focus({focusVisible:!1,preventScroll:!0})));const o=t.get(s.group);o&&r.set(s.group,o.layout)}),Qa({cursorFlags:0,hitRegions:n,initialLayoutMap:r,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}),n.length&&e.preventDefault()}function KP({document:e,event:t,hitRegions:n,initialLayoutMap:r,mountedGroups:i,pointerDownAtPoint:s,prevCursorFlags:o}){let a=0;n.forEach(c=>{const{group:u,groupSize:d}=c,{orientation:f,panels:p}=u,{disableCursor:m}=u.mutableState;let v=0;s?f==="horizontal"?v=(t.clientX-s.x)/d*100:v=(t.clientY-s.y)/d*100:f==="horizontal"?v=t.clientX<0?-100:100:v=t.clientY<0?-100:100;const w=r.get(u),x=i.get(u);if(!w||!x)return;const{defaultLayoutDeferred:_,derivedPanelConstraints:b,groupSize:S,layout:C,separatorToPanels:k}=x;if(b&&C&&k){const N=Ru({delta:v,initialLayout:w,panelConstraints:b,pivotIndices:c.panels.map(E=>p.indexOf(E)),prevLayout:C,trigger:"mouse-or-touch"});if(Wo(N,C)){if(v!==0&&!m)switch(f){case"horizontal":{a|=v<0?BP:$P;break}case"vertical":{a|=v<0?zP:FP;break}}}else rs(c.group,{defaultLayoutDeferred:_,derivedPanelConstraints:b,groupSize:S,layout:N,separatorToPanels:k})}});let l=0;t.movementX===0?l|=o&Xk:l|=a&Xk,t.movementY===0?l|=o&Zk:l|=a&Zk,iG(l),$_(e)}function lC(e){const t=na(),n=Uo();switch(n.state){case"active":KP({document:e.currentTarget,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedGroups:t,prevCursorFlags:n.cursorFlags})}}function cC(e){var r,i;if(e.defaultPrevented)return;const t=Uo(),n=na();switch(t.state){case"active":{if(e.buttons===0){Qa({cursorFlags:0,state:"inactive"}),t.hitRegions.forEach(s=>{const o=Hs(s.group.id,!0);rs(s.group,o,{isUserInteraction:!0})});return}for(const s of t.hitRegions)if(s.separator){const{element:o}=s.separator;(r=o.hasPointerCapture)!=null&&r.call(o,e.pointerId)||((i=o.setPointerCapture)==null||i.call(o,e.pointerId))}KP({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break}default:{const s=F_(e,n);s.length===0?t.state!=="inactive"&&Qa({cursorFlags:0,state:"inactive"}):Qa({cursorFlags:0,hitRegions:s,state:"hover"}),$_(e.currentTarget);break}}}function uC(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(Uo().state){case"hover":Qa({cursorFlags:0,state:"inactive"})}}function dC(e){e.defaultPrevented||e.pointerType==="mouse"&&e.button>0||UP(e.currentTarget)&&e.preventDefault()}function hC(e){let t=0,n=0;const r={};for(const s of e)if(s.defaultSize!==void 0){t++;const o=Dn(s.defaultSize);n+=o,r[s.panelId]=o}else r[s.panelId]=void 0;const i=e.length-t;if(i!==0){const s=Dn((100-n)/i);for(const o of e)o.defaultSize===void 0&&(r[o.panelId]=s)}return r}function vG(e,t,n){if(!n[0])return;const r=e.panels.find(l=>l.element===t);if(!r||!r.onResize)return;const i=vl({group:e}),s=e.orientation==="horizontal"?r.element.offsetWidth:r.element.offsetHeight,o=r.mutableValues.prevSize,a={asPercentage:Dn(s/i*100),inPixels:s};r.mutableValues.prevSize=a,r.onResize(a,r.id,o)}function xG(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 yG({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 a=new Map,l=[];for(const d of e.panels){const f=r[d.id]??0;switch(d.panelConstraints.groupResizeBehavior){case"preserve-pixel-size":{o=!0;const p=f/100*n,m=Dn(p/t*100);a.set(d.id,m),i+=m;break}case"preserve-relative-size":default:{l.push(d.id),s+=f;break}}}if(!o||l.length===0)return r;const c=100-i,u={...r};if(a.forEach((d,f)=>{u[f]=d}),s>0)for(const d of l){const f=r[d]??0;u[d]=Dn(f/s*c)}else{const d=Dn(c/l.length);for(const f of l)u[f]=d}return u}function _G(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 va=new Map;function bG(e){let t=!0;dt(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(m=>{for(const v of m){const{borderBoxSize:w,target:x}=v;if(x===e.element){if(t){const _=vl({group:e});if(_===0)return;const b=Hs(e.id);if(!b)return;const S=Ex(e),C=b.defaultLayoutDeferred?hC(S):b.layout,k=yG({group:e,nextGroupSize:_,prevGroupSize:b.groupSize,prevLayout:C}),N=qo({layout:k,panelConstraints:S});if(!b.defaultLayoutDeferred&&Wo(b.layout,N)&&xG(b.derivedPanelConstraints,S)&&b.groupSize===_)return;rs(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:S,groupSize:_,layout:N,separatorToPanels:b.separatorToPanels})}}else vG(e,x,w)}});s.observe(e.element),e.panels.forEach(m=>{dt(!r.has(m.id),`Panel ids must be unique; id "${m.id}" was used more than once`),r.add(m.id),m.onResize&&s.observe(m.element)});const o=vl({group:e}),a=Ex(e),l=e.panels.map(({id:m})=>m).join(",");let c=e.mutableState.defaultLayout;c&&(_G(e.panels,c)||(c=void 0));const u=e.mutableState.layouts[l]??c??hC(a),d=qo({layout:u,panelConstraints:a}),f=e.element.ownerDocument;va.set(f,(va.get(f)??0)+1);const p=new Map;return DP(e).forEach(m=>{m.separator&&p.set(m.separator,m.panels)}),rs(e,{defaultLayoutDeferred:o===0,derivedPanelConstraints:a,groupSize:o,layout:d,separatorToPanels:p}),e.separators.forEach(m=>{dt(!i.has(m.id),`Separator ids must be unique; id "${m.id}" was used more than once`),i.add(m.id),m.element.addEventListener("keydown",oC)}),va.get(f)===1&&(f.addEventListener("contextmenu",tC,!0),f.addEventListener("dblclick",sC,!0),f.addEventListener("pointerdown",aC,!0),f.addEventListener("pointerleave",lC),f.addEventListener("pointermove",cC),f.addEventListener("pointerout",uC),f.addEventListener("pointerup",dC,!0)),function(){t=!1,va.set(f,Math.max(0,(va.get(f)??0)-1)),aG(e),e.separators.forEach(m=>{m.element.removeEventListener("keydown",oC)}),va.get(f)||(f.removeEventListener("contextmenu",tC,!0),f.removeEventListener("dblclick",sC,!0),f.removeEventListener("pointerdown",aC,!0),f.removeEventListener("pointerleave",lC),f.removeEventListener("pointermove",cC),f.removeEventListener("pointerout",uC),f.removeEventListener("pointerup",dC,!0)),s.disconnect()}}function wG(){const[e,t]=g.useState({}),n=g.useCallback(()=>t({}),[]);return[e,n]}function H_(e){const t=g.useId();return`${e??t}`}const ra=typeof window<"u"?g.useLayoutEffect:g.useEffect;function Vc(e){const t=g.useRef(e);return ra(()=>{t.current=e},[e]),g.useCallback((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[t])}function U_(...e){return Vc(t=>{e.forEach(n=>{if(n)switch(typeof n){case"function":{n(t);break}case"object":{n.current=t;break}}})})}function W_(e){const t=g.useRef({...e});return ra(()=>{for(const n in e)t.current[n]=e[n]},[e]),t.current}const GP=g.createContext(null);function SG(e,t){const n=g.useRef({getLayout:()=>({}),setLayout:sG});g.useImperativeHandle(t,()=>n.current,[]),ra(()=>{Object.assign(n.current,VP({groupId:e}))})}function q_({children:e,className:t,defaultLayout:n,disableCursor:r,disabled:i,elementRef:s,groupRef:o,id:a,onLayoutChange:l,onLayoutChanged:c,orientation:u="horizontal",resizeTargetMinimumSize:d={coarse:20,fine:10},style:f,...p}){const m=g.useRef({onLayoutChange:{},onLayoutChanged:{}}),v=Vc(L=>{Wo(m.current.onLayoutChange,L)||(m.current.onLayoutChange=L,l==null||l(L))}),w=Vc((L,M)=>{Wo(m.current.onLayoutChanged,L)||(m.current.onLayoutChanged=L,c==null||c(L,{isUserInteraction:M}))}),x=H_(a),_=g.useRef(null),[b,S]=wG(),C=g.useRef({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:d,separators:[]}),k=U_(_,s);SG(x,o);const N=Vc((L,M)=>{const R=Uo(),A=eC(L),D=Hs(L);if(D){let z=!1;switch(R.state){case"active":{z=R.hitRegions.some(F=>F.group===A);break}}return{flexGrow:D.layout[M]??1,pointerEvents:z?"none":void 0}}if(n!=null&&n[M])return{flexGrow:n==null?void 0:n[M]}}),E=W_({defaultLayout:n,disableCursor:r}),j=g.useMemo(()=>({get disableCursor(){return!!E.disableCursor},getPanelStyles:N,id:x,orientation:u,registerPanel:L=>{const M=C.current;return M.panels=Ix(u,[...M.panels,L]),S(),()=>{M.panels=M.panels.filter(R=>R!==L),S()}},registerSeparator:L=>{const M=C.current;return M.separators=Ix(u,[...M.separators,L]),S(),()=>{M.separators=M.separators.filter(R=>R!==L),S()}},updatePanelProps:(L,{disabled:M})=>{const R=C.current.panels.find(z=>z.id===L);R&&(R.panelConstraints.disabled=M);const A=eC(x),D=Hs(x);A&&D&&rs(A,{...D,derivedPanelConstraints:Ex(A)})},updateSeparatorProps:(L,{disabled:M,disableDoubleClick:R})=>{const A=C.current.separators.find(D=>D.id===L);A&&(A.disabled=M,A.disableDoubleClick=R)}}),[N,x,S,u,E]),P=g.useRef(null);return ra(()=>{const L=_.current;if(L===null)return;const M=C.current;let R;if(E.defaultLayout!==void 0&&Object.keys(E.defaultLayout).length===M.panels.length){R={};for(const I of M.panels){const U=E.defaultLayout[I.id];U!==void 0&&(R[I.id]=U)}}const A={disabled:!!i,element:L,id:x,mutableState:{defaultLayout:R,disableCursor:!!E.disableCursor,expandedPanelSizes:C.current.lastExpandedPanelSizes,layouts:C.current.layouts},orientation:u,panels:M.panels,resizeTargetMinimumSize:M.resizeTargetMinimumSize,separators:M.separators};P.current=A;const D=bG(A),{defaultLayoutDeferred:z,derivedPanelConstraints:F,layout:$}=Hs(A.id,!0);!z&&F.length>0&&(v($),w($,!1));const O=z_(x,I=>{const{defaultLayoutDeferred:U,derivedPanelConstraints:q,layout:B}=I.next;if(U||q.length===0)return;const te=A.panels.map(({id:Y})=>Y).join(",");A.mutableState.layouts[te]=B,q.forEach(Y=>{if(Y.collapsible){const{layout:re}=I.prev??{};if(re){const ke=Cn(Y.collapsedSize,B[Y.panelId]),oe=Cn(Y.collapsedSize,re[Y.panelId]);ke&&!oe&&(A.mutableState.expandedPanelSizes[Y.panelId]=re[Y.panelId])}}});const le=Uo().state!=="active";v(B),le&&w(B,I.isUserInteraction)});return()=>{P.current=null,D(),O()}},[i,x,w,v,u,b,E]),g.useEffect(()=>{const L=P.current;L&&(L.mutableState.defaultLayout=n,L.mutableState.disableCursor=!!r)}),h.jsx(GP.Provider,{value:j,children:h.jsx("div",{...p,className:t,"data-group":!0,"data-testid":x,id:x,ref:k,style:{height:"100%",width:"100%",overflow:"hidden",...f,display:"flex",flexDirection:u==="horizontal"?"row":"column",flexWrap:"nowrap",touchAction:u==="horizontal"?"pan-y":"pan-x"},children:e})})}q_.displayName="Group";function V_(){const e=g.useContext(GP);return dt(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function kG(e,t){const{id:n}=V_(),r=g.useRef({collapse:zg,expand:zg,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:zg});g.useImperativeHandle(t,()=>r.current,[]),ra(()=>{Object.assign(r.current,qP({groupId:n,panelId:e}))})}function Qf({children:e,className:t,collapsedSize:n="0%",collapsible:r=!1,defaultSize:i,disabled:s,elementRef:o,groupResizeBehavior:a="preserve-relative-size",id:l,maxSize:c="100%",minSize:u="0%",onResize:d,panelRef:f,style:p,...m}){const v=!!l,w=H_(l),x=W_({disabled:s}),_=g.useRef(null),b=U_(_,o),{getPanelStyles:S,id:C,orientation:k,registerPanel:N,updatePanelProps:E}=V_(),j=d!==null,P=Vc((A,D,z)=>{d==null||d(A,l,z)});ra(()=>{const A=_.current;if(A!==null){const D={element:A,id:w,idIsStable:v,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:j?P:void 0,panelConstraints:{groupResizeBehavior:a,collapsedSize:n,collapsible:r,defaultSize:i,disabled:x.disabled,maxSize:c,minSize:u}};return N(D)}},[a,n,r,i,j,w,v,c,u,P,N,x]),g.useEffect(()=>{E(w,{disabled:s})},[s,w,E]),kG(w,f);const L=()=>{const A=S(C,w);if(A)return JSON.stringify(A)},M=g.useSyncExternalStore(A=>z_(C,A),L,L);let R;return M?R=JSON.parse(M):i!==void 0?R={flexGrow:void 0,flexShrink:void 0,flexBasis:i}:R={flexGrow:1},h.jsx("div",{...m,"data-disabled":s||void 0,"data-panel":!0,"data-testid":w,id:w,ref:b,style:{...CG,display:"flex",flexBasis:0,flexShrink:1,overflow:"visible",...R},children:h.jsx("div",{className:t,style:{maxHeight:"100%",maxWidth:"100%",flexGrow:1,overflow:"auto",...p,touchAction:k==="horizontal"?"pan-y":"pan-x"},children:e})})}Qf.displayName="Panel";const CG={minHeight:0,maxHeight:"100%",height:"auto",minWidth:0,maxWidth:"100%",width:"auto",border:"none",borderWidth:0,padding:0,margin:0};function EG({layout:e,panelConstraints:t,panelId:n,panelIndex:r}){let i,s;const o=e[n],a=t.find(l=>l.panelId===n);if(a){const l=a.maxSize,c=a.collapsible?a.collapsedSize:a.minSize,u=[r,r+1];s=qo({layout:Ru({delta:c-o,initialLayout:e,panelConstraints:t,pivotIndices:u,prevLayout:e}),panelConstraints:t})[n],i=qo({layout:Ru({delta:l-o,initialLayout:e,panelConstraints:t,pivotIndices:u,prevLayout:e}),panelConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:s,valueNow:o}}function YP({children:e,className:t,disabled:n,disableDoubleClick:r,elementRef:i,id:s,style:o,...a}){const l=H_(s),c=W_({disabled:n,disableDoubleClick:r}),[u,d]=g.useState({}),[f,p]=g.useState("inactive"),[m,v]=g.useState(!1),w=g.useRef(null),x=U_(w,i),{disableCursor:_,id:b,orientation:S,registerSeparator:C,updateSeparatorProps:k}=V_(),N=S==="horizontal"?"vertical":"horizontal";ra(()=>{const P=w.current;if(P!==null){const L={disabled:c.disabled,disableDoubleClick:c.disableDoubleClick,element:P,id:l},M=C(L),R=rG(D=>{p(D.next.state!=="inactive"&&D.next.hitRegions.some(z=>z.separator===L)?D.next.state:"inactive")}),A=z_(b,D=>{const{derivedPanelConstraints:z,layout:F,separatorToPanels:$}=D.next,O=$.get(L);if(O){const I=O[0],U=O.indexOf(I);d(EG({layout:F,panelConstraints:z,panelId:I.id,panelIndex:U}))}});return()=>{R(),A(),M()}}},[b,l,C,c]),g.useEffect(()=>{k(l,{disabled:n,disableDoubleClick:r})},[n,r,l,k]);let E;n&&!_&&(E="not-allowed");let j;if(n)j="disabled";else switch(f){case"active":{j="active";break}default:m?j="focus":j=f}return h.jsx("div",{...a,"aria-controls":u.valueControls,"aria-disabled":n||void 0,"aria-orientation":N,"aria-valuemax":u.valueMax,"aria-valuemin":u.valueMin,"aria-valuenow":u.valueNow,children:e,className:t,"data-separator":j,"data-testid":l,id:l,onBlur:()=>v(!1),onFocus:()=>v(!0),ref:x,role:"separator",style:{flexBasis:"auto",cursor:E,...o,flexGrow:0,flexShrink:0,touchAction:"none"},tabIndex:n?void 0:0})}YP.displayName="Separator";function IG(e){if(!e)return;const t=e.contextUsage,n=e.contextWindowSize;if(!t||!n||n<=0)return;const r=t.inputTokens+(t.cacheReadTokens??0)+(t.cacheCreateTokens??0);if(!(r<=0))return Math.round(r/n*100)}function XP(e,t){const n=os(),r=e?`session/${e}`:"",i=es(r)??Fo,s=g.useCallback(d=>{!e||!r||n.setData(r,f=>Hf(f??Fo,d,e))},[n,r,e]),o=g.useCallback(()=>{e&&s({type:"session:change",sessionId:e})},[s,e]),a=g.useCallback(d=>{e&&s({type:"permission:clear",sessionId:e,requestId:d})},[s,e]),l=g.useCallback(d=>{e&&s({type:"permission:request",sessionId:e,requestId:d.requestId,tool:d.tool,input:d.input,...d.toolUseId?{toolUseId:d.toolUseId}:{}})},[s,e]),c=g.useCallback(d=>{e&&s({type:"session:question:clear",sessionId:e,toolUseId:d})},[s,e]),u=g.useCallback((d,f)=>{e&&s({type:"session:question:submitted",sessionId:e,toolUseId:d,answers:f})},[s,e]);return{...i,reset:o,clearPermission:a,restorePermission:l,clearQuestion:c,markQuestionSubmitted:u}}function NG(e){return e.kind!=="user-text"?!1:e.meta===void 0||e.meta==="slash-command"||Qp(e.meta)}function TG(e,t={}){let n=0;if(t.implicitCloseOnUserText){for(const r of e)NG(r)&&n++;return n}for(const r of e)r.kind==="turn-end"&&n++;return n}const PG=g.createContext(null);function bm(){return g.useContext(PG)}const RG=50;function MG({api:e,sessionId:t,focused:n=!0,toolSessionId:r,initialTurns:i,implicitCloseOnUserText:s,pageSize:o=RG,enabled:a=!0,refreshVersion:l=0}){const c=bm(),[u,d]=g.useState({messages:[],total:0,loading:!1,error:null}),f=g.useRef(r),p=g.useRef(n),m=g.useRef(null),v=g.useRef(l),w=g.useRef(0),x=g.useRef(!0);return g.useEffect(()=>(x.current=!0,()=>{x.current=!1}),[]),g.useEffect(()=>{const _=f.current;f.current=r;const b=n&&!p.current;if(p.current=n,!a){m.current!==null&&(m.current=null,++w.current,d({messages:[],total:0,loading:!1,error:null}));return}const S=m.current!==t,C=v.current!==l;v.current=l;const k=typeof _=="string"&&_!==r,N=b&&u.error!==null;if(_!==r&&(c==null||c.push({level:"info",msg:"chatflow.history.identity",sessionId:t,meta:{previousToolSessionId:_??null,toolSessionId:r??null,willReload:S||k}})),!S&&!k&&!N&&!C)return;if((S||k)&&d({messages:[],total:0,loading:!1,error:null}),!t){m.current=null;return}m.current=t;const E=++w.current;c==null||c.push({level:"info",msg:"chatflow.history.read.start",sessionId:t,meta:{toolSessionId:r??null,initialTurns:i??null,pageSize:i===void 0?null:o,readSeq:E}}),d(j=>({...j,loading:!0,error:null})),(async()=>{var A;let j=[],P=!1,L,M=i===void 0?{}:{limit:o},R=Number.POSITIVE_INFINITY;for(;;){let D;try{D=await e.historyRead({sessionId:t,...M})}catch(q){if(E!==w.current||!x.current)return;const B=q.message??"history load failed";c==null||c.push({level:"warn",msg:"chatflow.history.read.error",sessionId:t,meta:{readSeq:E,shown:P,errorCode:q&&typeof q=="object"&&"code"in q?String(q.code):null}}),d(te=>({...te,loading:!1,error:B}));return}if(E!==w.current||!x.current)return;c==null||c.push({level:"info",msg:"chatflow.history.read.result",sessionId:t,meta:{readSeq:E,pageMessages:((A=D.messages)==null?void 0:A.length)??0,total:D.total??0,offset:D.offset??null}}),L&&D.snapshotId&&L!==D.snapshotId&&(j=[],P=!1,R=Number.POSITIVE_INFINITY,d({messages:[],total:0,loading:!0,error:null})),L=D.snapshotId,j=[...D.messages??[],...j];const z=D.total??0,F=typeof D.offset=="number"?D.offset:0,$=F>=R,O=F<=0||$;R=F;const I=i!==void 0&&TG(j,{implicitCloseOnUserText:s})>=i;if(P?d({messages:j,total:z,loading:!1,error:null}):(O||I)&&(P=!0,d({messages:j,total:z,loading:!1,error:null})),O)return;const U=Math.max(0,F-o);M={offset:U,limit:F-U,...L?{snapshotId:L}:{}}}})()},[e,t,r,n,o,i,a,l,c]),u}const AG=["TaskCreate","TaskUpdate","TaskList","TaskGet"];function jG(e){return AG.includes(e)}function ZP(e){return e==="in_progress"||e==="completed"?e:"pending"}function LG(e,t){if(!t||typeof t!="object")return e;const n=t,r=typeof n.subject=="string"&&n.subject?n.subject:typeof n.content=="string"&&n.content?n.content:null;if(!r)return e;const i=typeof n.activeForm=="string"?n.activeForm:void 0,s=typeof n.description=="string"?n.description:void 0;return[...e,{id:String(e.length+1),content:r,status:ZP(n.status),activeForm:i,description:s}]}function DG(e,t){if(!t||typeof t!="object")return e;const n=t,r=typeof n.taskId=="string"&&n.taskId?n.taskId:typeof n.id=="string"&&n.id?n.id:null;if(!r)return e;const i=e.findIndex(a=>a.id===r);if(i<0)return e;const s=[...e],o={...s[i]};return"status"in n&&(o.status=ZP(n.status)),typeof n.subject=="string"&&(o.content=n.subject),typeof n.content=="string"&&(o.content=n.content),typeof n.activeForm=="string"&&(o.activeForm=n.activeForm),typeof n.description=="string"&&(o.description=n.description),s[i]=o,s}function OG(e){let t=[],n=-1;for(let r=0;r<e.length;r++){const i=e[r];if(i.kind==="task-event")switch(n=r,i.name){case"TaskCreate":t=LG(t,i.input);break;case"TaskUpdate":t=DG(t,i.input);break}}return{tasks:t,lastEventIndex:n}}function BG(e){return e==="TodoWrite"}function $G(e){if(!e||typeof e!="object")return null;const t=e;if(!Array.isArray(t.todos))return null;const n=[];for(const r of t.todos){if(!r||typeof r!="object")continue;const i=r,s=typeof i.content=="string"?i.content:"";if(!s)continue;const o=i.status==="in_progress"||i.status==="completed"?i.status:"pending",a=typeof i.activeForm=="string"?i.activeForm:void 0;n.push({content:s,status:o,activeForm:a})}return n}function Hh(e,t,n){var o;const r=[],i=new Map;for(let a=0;a<e.length;a++){const l=e[a],c=typeof l.seq=="number"?l.seq:a;switch(l.kind){case"session_init":r.push({kind:"session-init",seq:c,toolSessionId:l.toolSessionId});break;case"text":fC(r,c,"assistant-text",l.text,l.partialId,l.uuid);break;case"thinking":fC(r,c,"assistant-thinking",l.text,l.partialId);break;case"user_text":{l.meta==="task-notification"?r.push({kind:"agent-notification",seq:c,text:l.text,taskId:l.taskId,parentToolUseId:l.parentToolUseId}):l.meta?r.push({kind:"user-meta",seq:c,metaKind:l.meta,text:l.text}):r.push({kind:"user-text",seq:c,text:l.text,uuid:l.uuid,...l.sender&&(l.sender.principal!=="owner"||KT.test(l.text))?{senderDisplayName:l.sender.displayName}:{},senderPrincipal:((o=l.sender)==null?void 0:o.principal)==="guest"?"guest":"owner"});break}case"tool_call":QP(r,c,l.toolUseId,l.tool,l.input,l.toolKind);break;case"tool_result":{const u=i.get(l.toolUseId);if(u!==void 0){if(l.askQuestionAnswers){const f=r[u];f.submittedAnswers=l.askQuestionAnswers}i.delete(l.toolUseId);break}const d={kind:"tool-result",seq:c,toolUseId:l.toolUseId,output:l.output,error:l.error};l.toolResultExtra&&(d.toolResultExtra=l.toolResultExtra),r.push(d);break}case"attachment_memories":r.push({kind:"memory-callout",seq:c,memories:l.memories});break;case"permission_request":{if(!t||l.requestId!==t)break;r.push({kind:"permission-inline",seq:c,requestId:l.requestId,tool:l.tool,input:l.input});break}case"ask_user_question":i.set(l.toolUseId,r.length),r.push({kind:"question-card",seq:c,toolUseId:l.toolUseId,questions:l.questions});break;case"turn_end":{const u={kind:"turn-end",seq:c};l.durationMs!==void 0&&(u.durationMs=l.durationMs),l.reason!==void 0&&(u.reason=l.reason),l.turnId!==void 0&&(u.turnId=l.turnId),r.push(u);break}case"subagent_progress":{const u={kind:"agent-progress",seq:c,toolUseId:l.toolUseId,agentId:l.agentId,status:l.status};l.description&&(u.description=l.description),l.lastToolName&&(u.lastToolName=l.lastToolName),l.prompt&&(u.prompt=l.prompt),l.stats&&(u.stats=l.stats),r.push(u);break}case"error":r.push({kind:"error",seq:c,message:l.message});break}}const s=new Map(e.flatMap((a,l)=>a.turnId?[[a.seq??l,a.turnId]]:[]));for(const a of r){const l=s.get(a.seq);l&&(a.turnId=l)}for(let a=1;a<r.length;a++){const l=r[a],c=r[a-1];if(l.kind!=="session-init"||!l.turnId||c.kind!=="turn-end"||c.reason!=="interrupted"||c.turnId)continue;let u=a-1;for(;u>0&&r[u-1].kind!=="turn-end";)u--;for(;u<a-1&&r[u].kind==="session-init";)u++;const d=r.slice(u,a);if(!d.some(f=>f.turnId&&f.turnId!==l.turnId)){for(const f of d)f.turnId=l.turnId;r.splice(a,1),a--}}return r}function QP(e,t,n,r,i,s){if(BG(r)){const o=$G(i);if(o){e.push({kind:"todo-checklist",seq:t,toolUseId:n,todos:o});return}}if(r==="Agent"){const o=i??{},a=typeof o.description=="string"&&o.description?o.description:typeof o.subagent_type=="string"&&o.subagent_type?o.subagent_type:"Subagent";e.push({kind:"agent-call",seq:t,toolUseId:n,description:a,input:i});return}if(jG(r)){e.push({kind:"task-event",seq:t,toolUseId:n,name:r,input:i});return}e.push({kind:"tool-call",seq:t,toolUseId:n,tool:r,toolKind:s,input:i})}function fC(e,t,n,r,i,s){let o=-1;for(let c=e.length-1;c>=0;c--)if(e[c].kind===n){o=c;break}const a=o>=0?e[o]:null;if(i){if(a&&a.partialId===i){const u=n==="assistant-text"?{kind:n,seq:a.seq,text:a.text+r,partialId:i,...s?{uuid:s}:{}}:{kind:n,seq:a.seq,text:a.text+r,partialId:i};e[o]=u;return}const c=n==="assistant-text"?{kind:n,seq:t,text:r,partialId:i,...s?{uuid:s}:{}}:{kind:n,seq:t,text:r,partialId:i};e.push(c);return}if(a&&a.partialId){const c=n==="assistant-text"?{kind:n,seq:a.seq,text:r,...s?{uuid:s}:{}}:{kind:n,seq:a.seq,text:r};e[o]=c;return}const l=n==="assistant-text"?{kind:n,seq:t,text:r,...s?{uuid:s}:{}}:{kind:n,seq:t,text:r};e.push(l)}const zG="AskUserQuestion";function K_(e,t=0,n){var o;const r=[],i=new Map;let s=t;for(const a of e){const l=s++,c=a.toolUseId??`hist-${l}`;switch(a.kind){case"user-text":if(a.meta==="task-notification")r.push({kind:"agent-notification",seq:l,text:a.text??"",taskId:a.taskId,parentToolUseId:a.parentToolUseId});else if(a.meta)r.push({kind:"user-meta",seq:l,metaKind:a.meta,text:a.text??""});else{const u=KT.exec(a.text??""),d=(o=X$.exec(a.text??""))==null?void 0:o[1],f=(u==null?void 0:u[2])??d,p=(u==null?void 0:u[1])==="guest"||d?"guest":"owner";r.push({kind:"user-text",seq:l,text:a.text??"",uuid:a.uuid,...f?{senderDisplayName:f}:{},senderPrincipal:p})}break;case"assistant-text":r.push({kind:"assistant-text",seq:l,text:a.text??"",uuid:a.uuid});break;case"tool_call":{if(a.tool===zG){const u=a.input??{},d=Array.isArray(u.questions)?u.questions:[];i.set(c,r.length),r.push({kind:"question-card",seq:l,toolUseId:c,questions:d});break}QP(r,l,c,a.tool??"",a.input,n);break}case"tool_result":{const u=i.get(c);if(u!==void 0){if(a.askQuestionAnswers){const f=r[u];f.submittedAnswers=a.askQuestionAnswers}i.delete(c);break}const d={kind:"tool-result",seq:l,toolUseId:c,output:a.output};a.error!==void 0&&(d.error=a.error),a.toolResultExtra&&(d.toolResultExtra=a.toolResultExtra),r.push(d);break}case"attachment_memories":a.memories&&a.memories.length>0&&r.push({kind:"memory-callout",seq:l,memories:a.memories});break;case"summary":break;case"turn-end":{const u={kind:"turn-end",seq:l};typeof a.durationMs=="number"&&(u.durationMs=a.durationMs),typeof a.turnId=="string"&&(u.turnId=a.turnId),r.push(u);break}}}return r}const FG=5e5;function HG(e){const t=FG-e.length;return e.map(n=>({...n,seq:n.seq+t}))}const pC=/\[attachment:(image|file):([^\]]+)\]/g;function mC(e){try{return decodeURIComponent(e)}catch{return e}}function UG(e){var n,r;if(e.startsWith("data:")){const i=e.slice(5,e.indexOf(",")),s=(n=/;name=([^;]+)/i.exec(i))==null?void 0:n[1];if(s)return mC(s);const o=(r=i.split(";")[0])==null?void 0:r.toLowerCase(),a={"text/plain":"txt","application/pdf":"pdf","image/png":"png","image/jpeg":"jpg","image/gif":"gif","image/webp":"webp"}[o??""];return(o!=null&&o.startsWith("image/")?"图片":"附件")+(a?"."+a:"")}const t=e.split(/[?#]/,1)[0];return mC(t.split("/").pop()||"附件")}function Jf(e){const t=[];let n;for(;(n=pC.exec(e))!==null;){const i=n[2],s=UG(i);t.push({type:n[1],url:i,fileName:s})}const r=e.replace(pC,"").trim();return{attachments:t,text:r}}function WG(e,t){const n=t.filter(i=>i.status==="done"&&i.url);return n.length===0?e:n.map(i=>`[attachment:${i.mimeType.startsWith("image/")?"image":"file"}:${i.url}]`).join(`
|
|
537
537
|
`)+`
|
|
538
538
|
`+e}const br=e=>typeof e=="string"?e:"",gC=e=>Array.isArray(e)?e.filter(t=>typeof t=="string"):[];function qG(e){var s;if(e.type==="userMessage"){const a=(Array.isArray(e.content)?e.content:[]).map(c=>c.type==="text"?br(c.text):c.type==="image"?`[attachment:image:${br(c.url)}]`:c.type==="localImage"?`[图片](${br(c.path)})`:"").filter(Boolean).join(`
|
|
539
539
|
`),l=Z$(a);return K_([{kind:"user-text",text:a,uuid:e.id,...l?{meta:l==="task"?"dispatch-task":"dispatch-result"}:{}}],0,"codex")}if(e.type==="agentMessage")return[{kind:"assistant-text",seq:0,text:br(e.text),uuid:e.id}];if(e.type==="reasoning")return[{kind:"assistant-thinking",seq:0,text:[...gC(e.summary),...gC(e.content)].join(`
|
|
@@ -620,4 +620,4 @@ Minimum version required to store current data is: `+s+`.
|
|
|
620
620
|
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
621
621
|
|
|
622
622
|
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return g.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},Xce="DialogDescriptionWarning",Zce=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${nj(Xce).contentName}}.`;return g.useEffect(()=>{var s;const i=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&i&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},Qce=UA,Jce=VA,rj=KA,ij=GA,sj=XA,oj=QA,eue=ej;const aj=Qce,tue=Jce,lj=g.forwardRef(({className:e,...t},n)=>h.jsx(rj,{ref:n,className:ie("fixed inset-0 z-50 bg-black/50 backdrop-blur-sm",e),...t}));lj.displayName=rj.displayName;const Ab=g.forwardRef(({className:e,children:t,...n},r)=>h.jsxs(tue,{children:[h.jsx(lj,{}),h.jsxs(ij,{ref:r,className:ie("fixed left-1/2 top-1/2 z-50 grid w-full max-w-lg -translate-x-1/2 -translate-y-1/2","gap-4 rounded-lg border border-border bg-elevated p-6 shadow-lg",e),...n,children:[t,h.jsxs(eue,{className:"absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-accent",children:[h.jsx(Qr,{className:"h-4 w-4"}),h.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Ab.displayName=ij.displayName;const cj=({className:e,...t})=>h.jsx("div",{className:ie("flex flex-col space-y-1.5 text-left",e),...t});cj.displayName="DialogHeader";const jb=g.forwardRef(({className:e,...t},n)=>h.jsx(sj,{ref:n,className:ie("text-lg font-semibold leading-none text-text-100",e),...t}));jb.displayName=sj.displayName;const uj=g.forwardRef(({className:e,...t},n)=>h.jsx(oj,{ref:n,className:ie("text-sm text-text-300",e),...t}));uj.displayName=oj.displayName;function nue({persona:e,open:t,onClose:n,onDelete:r,embedded:i,onLoadPersonality:s,onSavePersonality:o,onLoadPersonalityLocal:a,onSavePersonalityLocal:l,hasPersonalityLocal:c=!1,onDirtyChange:u,initialPersonality:d,onShareCapability:f,readOnly:p=!1,larkBot:m}){const[v,w]=g.useState(!1),[x,_]=g.useState(!1),b=v||x,S=Ye.useRef(u);g.useEffect(()=>{S.current=u}),g.useEffect(()=>{var k;(k=S.current)==null||k.call(S,b)},[b]);const C=()=>{b&&!window.confirm("修改未保存,确定关闭?")||n()};return t?h.jsxs(h.Fragment,{children:[!i&&h.jsx("div",{className:"absolute inset-0 z-30 bg-black/30",onClick:C,"aria-hidden":"true"}),h.jsxs("aside",{className:i?"flex h-full w-full flex-col bg-bg-0":"absolute right-0 top-0 z-40 flex h-full w-[420px] flex-col bg-bg-0 border-l border-border shadow-xl","data-testid":"persona-settings-drawer",children:[h.jsxs("header",{className:"flex items-center justify-between border-b border-border px-4 py-3 shrink-0",children:[h.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[h.jsx($F,{className:"h-4 w-4 text-text-300"}),h.jsx("span",{className:"text-[13px] font-medium text-text-100 truncate",children:"Persona 设置"})]}),h.jsx("button",{type:"button",onClick:C,"aria-label":"关闭",className:"rounded-sm p-1.5 text-text-400 hover:bg-bg-200 hover:text-text-100",children:h.jsx(Qr,{className:"h-4 w-4"})})]}),h.jsxs("div",{className:"flex-1 overflow-y-auto p-6 flex flex-col gap-4",children:[h.jsxs("header",{className:"flex items-start justify-between gap-3",children:[h.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("h2",{className:"text-lg font-semibold text-text-100 truncate",children:e.label}),e.public?h.jsxs("span",{className:"inline-flex items-center gap-1 rounded-sm bg-bg-200 px-1.5 py-0.5 text-[10px] text-text-200",children:[h.jsx(iF,{className:"h-3 w-3"})," 公开"]}):h.jsxs("span",{className:"inline-flex items-center gap-1 rounded-sm bg-error-dim px-1.5 py-0.5 text-[10px] text-error",children:[h.jsx(nF,{className:"h-3 w-3"})," 已关闭"]})]}),h.jsx("span",{className:"font-mono text-[11px] text-text-400 truncate","data-testid":"persona-id-subtitle",children:e.personaId})]}),h.jsxs("div",{className:"flex items-center gap-1",children:[f?h.jsxs("button",{type:"button",onClick:f,"aria-label":"分享给他人",title:"分享给他人",className:"inline-flex items-center gap-1 rounded-sm px-2 py-1.5 text-xs text-text-200 hover:bg-bg-200 hover:text-text-100",children:[h.jsx(i_,{className:"h-3.5 w-3.5"}),"分享"]}):null,r?h.jsx("button",{type:"button",onClick:r,"aria-label":"删除 persona",className:"rounded-sm p-1.5 text-text-400 hover:bg-bg-200 hover:text-error",children:h.jsx(s_,{className:"h-4 w-4"})}):null]})]}),h.jsx("hr",{className:"border-border"}),m?h.jsxs(h.Fragment,{children:[h.jsx(sue,{...m}),h.jsx("hr",{className:"border-border"})]}):null,s?h.jsxs(h.Fragment,{children:[h.jsx(jE,{onLoad:s,...o&&!e.personalityManaged?{onSave:o}:{},onDirtyChange:w,initialPersonality:d,readOnly:p||!!e.personalityManaged,title:e.personalityManaged?"内置人格":"人格 (Personality)",hint:e.personalityManaged?p?"这个 persona 自带的人格,随 clawd 版本更新。":"这个 persona 自带的人格,随 clawd 版本更新——在这里改不会保留,要加自己的规则请写下面的「你的补充」。":void 0,testIdPrefix:"persona-personality"}),(e.personalityManaged||c)&&a?h.jsx(jE,{onLoad:a,...l?{onSave:l}:{},onDirtyChange:_,readOnly:p,title:p?"补充设定":"你的补充",hint:p?"这个 persona 的补充设定,由它的主人维护。与内置人格叠加生效。":"写入 <persona-dir>/.clawd/personality.local.md,不会被更新覆盖。与内置人格叠加生效,冲突时以你写的为准;对 owner 和访客会话都生效,要区分对象请在正文里写明。只对新启动的会话生效。",placeholder:"例:回答一律先给结论,再展开。",testIdPrefix:"persona-personality-local"}):null,h.jsx("hr",{className:"border-border"})]}):null,h.jsx(oue,{settings:e.sandboxSettings??null}),h.jsx("hr",{className:"border-border"}),h.jsx(aue,{skills:e.skills??[]}),h.jsx("hr",{className:"border-border"}),h.jsx(lue,{plugins:e.plugins??[]})]})]})]}):null}function AE({qrUrl:e,busy:t,onCancel:n,title:r="扫码关联飞书 Bot",hint:i="用手机飞书扫码,按页面提示创建应用。确认后自动完成关联。"}){const[s,o]=g.useState(null);return g.useEffect(()=>{let a=!1;return hd.toDataURL(e,{width:240,margin:1}).then(l=>{a||o(l)}).catch(()=>{a||o(null)}),()=>{a=!0}},[e]),h.jsx(aj,{open:!0,onOpenChange:a=>a||n==null?void 0:n(),children:h.jsxs(Ab,{className:"max-w-xs","data-testid":"lark-bot-qr-dialog",onInteractOutside:a=>a.preventDefault(),onEscapeKeyDown:a=>a.preventDefault(),children:[h.jsx(cj,{children:h.jsx(jb,{children:r})}),h.jsxs("div",{className:"flex flex-col items-center gap-2",children:[s?h.jsx("img",{src:s,alt:"飞书扫码创建应用二维码",className:"h-60 w-60 rounded bg-white p-2","data-testid":"lark-bot-qr-img"}):h.jsx("div",{className:"flex h-60 w-60 items-center justify-center text-[12px] text-text-400",children:"二维码生成中…"}),h.jsx("span",{className:"text-center text-[12px] text-text-300",children:i}),n?h.jsx("button",{type:"button",disabled:t,onClick:n,className:"rounded border border-border px-3 py-1.5 text-[12px] text-text-300 hover:bg-bg-200 disabled:opacity-50","data-testid":"lark-bot-provision-cancel",children:"取消"}):null]})]})})}const rue={expired:"二维码已过期,请重新扫码。",cancelled:"已取消。",access_denied:"你在飞书上取消了本次授权。",lark_protocol_error:"飞书返回了未预期的响应,请重试。",cloud_unreachable:"云端暂时不可达,请稍后重试。",internal_error:"关联失败。若飞书中已创建应用,可在开发者后台删除后重试,或改用手动绑定填入其凭证。"},iue=new Set(["expired","access_denied","lark_protocol_error","cloud_unreachable","internal_error"]);function sue({status:e,onProvision:t,onCancelProvision:n,onBindManual:r,onUnbind:i,onUpgrade:s,runtime:o="local"}){const[a,l]=g.useState(!1),[c,u]=g.useState(null),[d,f]=g.useState(""),[p,m]=g.useState(""),[v,w]=g.useState(null),x=N=>{N&&(l(!0),u(null),N().catch(E=>u(E instanceof Error?E.message:String(E))).finally(()=>l(!1)))},_=()=>{w(null),x(t)},b=!a&&!!d&&!!p,S=()=>{!b||!r||x(()=>r({appId:d,appSecret:p}))},C=td(S),k=h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx(tm,{className:"h-3.5 w-3.5 text-text-400","aria-hidden":!0}),h.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"飞书 Bot"})]});return e?h.jsxs("section",{className:"flex flex-col gap-1.5","data-testid":"lark-bot-section",children:[k,e.state==="unbound"||e.state==="provisioning"?h.jsxs(h.Fragment,{children:[h.jsxs("span",{className:"text-[11px] text-text-400",children:["关联一个飞书 bot 后,这个 persona 就是它:拉进群后群成员 @ 它提问、或直接私聊它,",o==="cloud"?"云 Persona 在云端处理消息,回复自动发回去。":"推理跑在你本机,回复自动发回去。"]}),t?h.jsx("button",{type:"button",disabled:a||e.state==="provisioning",onClick:_,className:"self-start rounded border border-border bg-bg-200 px-3 py-1.5 text-[12px] font-medium text-text-100 hover:bg-bg-300 disabled:opacity-50","data-testid":"lark-bot-provision",children:e.state==="provisioning"?"等待扫码…":"扫码关联飞书 Bot"}):null,e.state==="unbound"&&e.errorReason&&!v?h.jsxs("div",{className:"flex flex-col gap-1.5 rounded border border-error bg-error-dim px-2 py-1.5","data-testid":"lark-bot-provision-error",children:[h.jsx("span",{className:"text-[11px] text-error",children:rue[e.errorReason]}),h.jsxs("div",{className:"flex gap-1.5",children:[iue.has(e.errorReason)&&t?h.jsx("button",{type:"button",disabled:a,onClick:_,className:"rounded border border-border px-2 py-1 text-[11px] text-text-100 hover:bg-bg-200 disabled:opacity-50","data-testid":"lark-bot-provision-retry",children:"重新扫码"}):null,h.jsx("button",{type:"button",onClick:()=>w(e.errorReason??null),className:"rounded border border-border px-2 py-1 text-[11px] text-text-300 hover:bg-bg-200","data-testid":"lark-bot-provision-error-dismiss",children:"知道了"})]})]}):null,e.state==="provisioning"&&e.qrUrl?h.jsx(AE,{qrUrl:e.qrUrl,busy:a,onCancel:n?()=>x(n):void 0}):null,r&&e.state==="unbound"?h.jsxs("details",{"data-testid":"lark-bot-manual-details",children:[h.jsx("summary",{className:"cursor-pointer text-[11px] text-text-400 hover:text-text-300",children:"已有飞书应用?手动填入凭证"}),h.jsxs("div",{className:"mt-1.5 flex flex-col gap-1.5","data-testid":"lark-bot-manual-form",children:[h.jsx("span",{className:"text-[11px] text-text-400",children:"先在飞书开放平台(open.feishu.cn)创建企业自建应用并启用机器人能力,再填入凭证:"}),h.jsx("input",{value:d,onChange:N=>f(N.target.value),...C,placeholder:"App ID(cli_ 开头)",className:"rounded border border-border bg-bg-100 px-2 py-1 text-[12px] text-text-200","data-testid":"lark-bot-manual-appid"}),h.jsx("input",{value:p,onChange:N=>m(N.target.value),...C,type:"password",placeholder:"App Secret",className:"rounded border border-border bg-bg-100 px-2 py-1 text-[12px] text-text-200","data-testid":"lark-bot-manual-secret"}),h.jsx("button",{type:"button",disabled:!b,onClick:S,className:"self-start rounded border border-border px-3 py-1.5 text-[12px] text-text-100 hover:bg-bg-200 disabled:opacity-50","data-testid":"lark-bot-manual-submit",children:a?"绑定中…":"绑定"})]})]}):null]}):null,e.state==="bound"||e.state==="broken"?h.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.state==="bound"&&e.needsUpgrade?h.jsxs("div",{className:"flex flex-col gap-1.5 rounded border border-warning/30 bg-warning-dim px-2 py-1.5","data-testid":"lark-bot-upgrade-notice",children:[h.jsx("span",{className:"text-[11px] text-warning",children:"这个 bot 的权限配置有更新,扫码重新授权后生效。在此之前,新增能力对它不起作用。"}),s?h.jsx("button",{type:"button",disabled:a,onClick:()=>x(s),className:"self-start rounded border border-warning/30 bg-warning/10 px-2 py-1 text-[11px] text-warning hover:bg-warning/20 disabled:opacity-50","data-testid":"lark-bot-upgrade",children:"更新授权"}):null]}):null,e.state==="bound"&&e.upgradeQrUrl?h.jsx(AE,{qrUrl:e.upgradeQrUrl,busy:a,onCancel:n?()=>x(n):void 0,title:"扫码更新授权",hint:"用手机飞书扫码,确认页会列出将要添加的权限。期间 bot 照常服务,不会中断。"}):null,e.state==="broken"?h.jsxs("div",{className:"rounded border border-error bg-error-dim px-2 py-1.5 text-[11px] text-error","data-testid":"lark-bot-broken",children:["Bot 凭证失效:",e.brokenReason??"未知原因","。请解绑后重新填入有效凭证绑定。"]}):null,h.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-text-200",children:[h.jsx("span",{className:"font-medium text-text-100",children:e.botName??"未命名 bot"}),e.appId?h.jsx("span",{className:"text-[11px] text-text-400",children:e.appId}):null]}),h.jsx("span",{className:"text-[11px] text-text-400",children:"把 bot 拉进任意飞书群,群成员 @ 它即可提问。"}),e.groups.length>0?h.jsx("ul",{className:"flex flex-col gap-0.5","data-testid":"lark-bot-groups",children:e.groups.map(N=>h.jsxs("li",{className:"text-[11px] text-text-300 truncate",children:["· ",N.chatName??N.chatId]},N.chatId))}):h.jsx("span",{className:"text-[11px] text-text-400","data-testid":"lark-bot-groups-empty",children:"还没有服务中的群。"}),i?h.jsx("button",{type:"button",disabled:a,onClick:()=>x(i),className:"self-start rounded border border-border px-3 py-1.5 text-[12px] text-error hover:bg-error-dim disabled:opacity-50","data-testid":"lark-bot-unbind",children:"解绑"}):null]}):null,c?h.jsx("div",{className:"rounded border border-error bg-error-dim px-2 py-1.5 text-[11px] text-error","data-testid":"lark-bot-error",children:c}):null]}):h.jsxs("section",{className:"flex flex-col gap-1.5","data-testid":"lark-bot-section",children:[k,h.jsx("span",{className:"text-[11px] text-text-400",children:"状态加载中…"})]})}function oue({settings:e}){var t,n,r,i,s,o,a,l,c,u,d,f,p;return h.jsxs("section",{className:"flex flex-col gap-2","data-testid":"persona-sandbox-setting-section",children:[h.jsxs("header",{className:"flex flex-col gap-0.5",children:[h.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"Sandbox Setting"}),h.jsx("span",{className:"text-[11px] text-text-400",children:"约束此 persona 的沙箱权限(只读,需通过文件修改)。"})]}),e==null?h.jsx("span",{className:"text-[12px] text-text-300","data-testid":"persona-sandbox-setting-empty",children:"暂无 sandbox 配置"}):h.jsxs("div",{className:"flex flex-col gap-1.5 rounded-md border border-border bg-bg-100 px-3 py-2",children:[h.jsx(yh,{label:"权限默认模式",value:((t=e.permissions)==null?void 0:t.defaultMode)??"—"}),h.jsx(yh,{label:"沙箱启用",value:I0((n=e.sandbox)==null?void 0:n.enabled)}),h.jsx(yh,{label:"沙箱内自动放行 Bash",value:I0((r=e.sandbox)==null?void 0:r.autoAllowBashIfSandboxed)}),h.jsx(yh,{label:"允许非沙箱命令",value:I0((i=e.sandbox)==null?void 0:i.allowUnsandboxedCommands)}),h.jsxs("div",{className:"mt-1 flex flex-col gap-1.5 border-t border-border pt-1.5",children:[h.jsx(xc,{label:"沙箱外命令",paths:(s=e.sandbox)==null?void 0:s.excludedCommands}),h.jsx(xc,{label:"允许读取",paths:(a=(o=e.sandbox)==null?void 0:o.filesystem)==null?void 0:a.allowRead}),h.jsx(xc,{label:"拒绝读取",paths:(c=(l=e.sandbox)==null?void 0:l.filesystem)==null?void 0:c.denyRead}),h.jsx(xc,{label:"允许写入",paths:(d=(u=e.sandbox)==null?void 0:u.filesystem)==null?void 0:d.allowWrite}),h.jsx(xc,{label:"拒绝写入",paths:(p=(f=e.sandbox)==null?void 0:f.filesystem)==null?void 0:p.denyWrite})]})]})]})}function I0(e){return e===!0?"是":e===!1?"否":"—"}function yh({label:e,value:t}){return h.jsxs("div",{className:"flex items-center justify-between gap-3 text-[12px]",children:[h.jsx("span",{className:"text-text-300",children:e}),h.jsx("span",{className:"font-mono text-text-100",children:t})]})}function xc({label:e,paths:t}){const n=!t||t.length===0;return h.jsxs("div",{className:"flex flex-col gap-1",children:[h.jsx("span",{className:"text-[11px] text-text-300",children:e}),n?h.jsx("span",{className:"text-[11px] text-text-400",children:"—"}):h.jsx("div",{className:"flex flex-wrap gap-1",children:t.map((r,i)=>h.jsx("span",{className:"rounded-sm border border-border bg-bg-0 px-1.5 py-0.5 font-mono text-[11px] text-text-200",children:r},`${e}-${i}-${r}`))})]})}function aue({skills:e}){return h.jsxs("section",{className:"flex flex-col gap-2","data-testid":"persona-skills-section",children:[h.jsxs("header",{className:"flex flex-col gap-0.5",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"Persona Skills"}),h.jsx("span",{className:"rounded-sm border border-border px-1.5 py-0.5 text-[10px] text-text-300",children:e.length})]}),h.jsxs("span",{className:"text-[11px] text-text-400",children:["此 persona 私有 skills(来自"," ",h.jsx("code",{className:"font-mono",children:"<persona-dir>/.claude/skills/"}),")。"]})]}),e.length===0?h.jsx("span",{className:"text-[12px] text-text-300","data-testid":"persona-skills-empty",children:"暂无 skills"}):h.jsx("ul",{className:"flex flex-col divide-y divide-border rounded-md border border-border bg-bg-100",children:e.map(t=>h.jsxs("li",{className:"flex flex-col gap-0.5 px-3 py-2","data-testid":"persona-skill-row",children:[h.jsx("span",{className:"font-mono text-[13px] text-text-100",children:t.name}),t.description?h.jsx("span",{className:"text-[12px] text-text-300",children:t.description}):h.jsx("span",{className:"text-[11px] text-text-400 italic",children:"无描述"})]},t.name))})]})}function lue({plugins:e}){return h.jsxs("section",{className:"flex flex-col gap-2","data-testid":"persona-plugins-section",children:[h.jsxs("header",{className:"flex flex-col gap-0.5",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"Enabled Plugins"}),h.jsx("span",{className:"rounded-sm border border-border px-1.5 py-0.5 text-[10px] text-text-300",children:e.length})]}),h.jsxs("span",{className:"text-[11px] text-text-400",children:["此 persona 已启用的插件(来自"," ",h.jsx("code",{className:"font-mono",children:"<persona-dir>/.claude/settings.json"})," ","的 ",h.jsx("code",{className:"font-mono",children:"enabledPlugins"}),")。"]})]}),e.length===0?h.jsx("span",{className:"text-[12px] text-text-300","data-testid":"persona-plugins-empty",children:"暂无启用插件"}):h.jsx("ul",{className:"flex flex-col divide-y divide-border rounded-md border border-border bg-bg-100",children:e.map(t=>h.jsx("li",{className:"flex flex-col gap-0.5 px-3 py-2","data-testid":"persona-plugin-row",children:h.jsx("span",{className:"font-mono text-[13px] text-text-100",children:t.id})},t.id))})]})}function jE({onLoad:e,onSave:t,onDirtyChange:n,initialPersonality:r,readOnly:i=!1,title:s,hint:o,placeholder:a,testIdPrefix:l}){const c=r!==void 0,[u,d]=g.useState(c),[f,p]=g.useState(c?r:""),[m,v]=g.useState(c?r:""),[w,x]=g.useState(null),[_,b]=g.useState(!1),[S,C]=g.useState(null),k=Ye.useRef(e),N=Ye.useRef(t),E=Ye.useRef(n);Ye.useEffect(()=>{k.current=e,N.current=t,E.current=n});const j=Ye.useCallback(()=>{d(!1),x(null),k.current().then(A=>{p(A),v(A),d(!0)}).catch(A=>{x(A instanceof Error?A.message:String(A))})},[]);Ye.useEffect(()=>{c||j()},[c,j]);const P=!i&&u&&m!==f;Ye.useEffect(()=>{i||E.current(P)},[P,i]);const L=()=>{N.current&&(b(!0),C(null),N.current(m).then(()=>{p(m),b(!1)}).catch(A=>{C(A instanceof Error?A.message:String(A)),b(!1)}))},M=()=>{v(f),C(null)},R=td(()=>{!P||_||L()},()=>{!P||_||M()});return h.jsxs("section",{className:"flex flex-col gap-2","data-testid":`${l}-section`,children:[h.jsx("span",{className:"text-[12px] font-medium text-text-200",children:s}),w?h.jsxs("div",{"data-testid":`${l}-load-error`,className:"rounded-md border border-error bg-error-dim px-3 py-2 text-[12px] text-error flex items-center justify-between gap-2",children:[h.jsxs("span",{children:["加载失败:",w]}),h.jsx("button",{type:"button",onClick:j,className:"rounded-sm border border-error px-2 py-0.5 text-[11px] hover:bg-error/10",children:"重试"})]}):null,S?h.jsxs("div",{"data-testid":`${l}-save-error`,className:"rounded-md border border-error bg-error-dim px-3 py-2 text-[12px] text-error",children:["保存失败:",S]}):null,h.jsx("textarea",{"data-testid":`${l}-textarea`,value:m,onChange:A=>v(A.target.value),...R,readOnly:i,disabled:!i&&(!u||_),placeholder:u?a??"":"加载中…",rows:8,className:"min-h-[8rem] max-h-[18rem] resize-y rounded-md border border-border bg-bg-100 px-2 py-1.5 font-mono text-[11px] text-text-100 disabled:opacity-60"}),o?h.jsx("p",{className:"text-[10px] text-text-400",children:o}):i?null:h.jsx("p",{className:"text-[10px] text-text-400",children:"写入人格文件。修改只对新启动的会话生效。"}),u&&P?h.jsxs("div",{className:"flex justify-end gap-2",children:[h.jsx("button",{type:"button",onClick:M,disabled:_,className:"rounded-sm border border-border px-2 py-1 text-[12px] text-text-200 hover:bg-bg-200 disabled:opacity-60",children:"放弃"}),h.jsx("button",{type:"button",onClick:L,disabled:_,"data-testid":`${l}-save-btn`,className:"rounded-sm bg-accent-dim px-2 py-1 text-[12px] text-text-100 hover:opacity-90 disabled:opacity-60",children:_?"保存中…":"保存"})]}):null]})}const cue={state:"unbound",groups:[]};function uue(e,t,n="local"){const[r,i]=g.useState(null),s=d=>`${n==="cloud"?"cloud:":""}larkBot:${d}`;g.useEffect(()=>{if(!e)return;let d=!1,f=0,p=!1;i(null);const m=async()=>{const _=++f;p=!0;try{const b=await e.request(s("status"),{personaId:t});if(d||_!==f)return;i(S=>n==="cloud"&&(S!=null&&S.upgradeQrUrl)&&b.state==="bound"&&b.needsUpgrade!==!1?{...b,upgradeQrUrl:S.upgradeQrUrl}:b.state==="unbound"&&!b.errorReason&&(S==null?void 0:S.state)==="unbound"&&S.errorReason?{...b,errorReason:S.errorReason}:b)}catch{!d&&_===f&&i(b=>b??cue)}finally{_===f&&(p=!1)}};m();const v=e.on("larkBot:state",_=>{const b=_;if(b.personaId!==t)return;const{personaId:S,...C}=b;++f,p=!1,i(C)}),w=e.on("daemon:connected",()=>{m()}),x=n==="cloud"?setInterval(()=>{p||m()},5e3):null;return()=>{d=!0,x&&clearInterval(x),v(),w()}},[e,t,n]);const o=g.useCallback(async()=>{e&&await e.request(s("provision"),{personaId:t})},[e,t,n]),a=g.useCallback(async()=>{e&&await e.request(s("provisionCancel"),{personaId:t})},[e,t,n]),l=g.useCallback(async d=>{e&&await e.request(s("bindManual"),{personaId:t,...d})},[e,t,n]),c=g.useCallback(async()=>{e&&await e.request(s("upgrade"),{personaId:t})},[e,t,n]),u=g.useCallback(async()=>{e&&await e.request(s("unbind"),{personaId:t})},[e,t,n]);return{status:r,provision:o,cancelProvision:a,bindManual:l,unbind:u,upgrade:c}}function due(e,t="owner"){var N;const{persona:n}=a4(e),r=Yz(e),i=Xz(),s=Zz(),{httpBaseUrl:o}=Jp(),a=Ni(),l=uue(t==="guest"?null:a,e),{capabilities:c}=Am((n==null?void 0:n.tool)??"claude"),u=g.useMemo(()=>!(n!=null&&n.public)||!o||/^https?:\/\/(127\.0\.0\.1|localhost|0\.0\.0\.0|\[?::1\]?)([:/]|$)/i.test(o)?null:`${o}/s/${e}`,[n==null?void 0:n.public,o,e]),d=g.useCallback((E,j)=>{i(e,j).catch(P=>{$e("persona",`${E} failed`,P)})},[i,e]),f=g.useCallback(E=>d("togglePublic",{public:E}),[d]),p=g.useCallback(async E=>{await i(e,{codexSandbox:{network:E}}),await r.refresh()},[i,e,r]),m=g.useCallback(E=>d("changeTool",{tool:E}),[d]),v=g.useCallback(E=>d("changeModel",{model:E}),[d]),w=g.useCallback(E=>d("changeEffort",{effort:E}),[d]),x=g.useCallback(E=>d("toggleFastMode",{serviceTier:E?Ff.fast:Ff.standard}),[d]),_=g.useCallback(()=>!n||!confirm(`删除 persona "${n.label}"?`)?!1:(s(e).catch(E=>{$e("persona","delete failed",E)}),!0),[n,s,e]),b=g.useCallback(async()=>r.loaded?r.personality:(await r.refresh()).personality,[r]),S=g.useCallback(async E=>{await i(e,{personality:E}),await r.refresh()},[i,e,r]),C=g.useCallback(async()=>r.loaded?r.personalityLocal:(await r.refresh()).personalityLocal,[r]),k=g.useCallback(async E=>{await i(e,{personalityLocal:E}),await r.refresh()},[i,e,r]);return{persona:n,detail:r,configSchema:(c==null?void 0:c.configSchema)??[],larkBot:l,guestShareUrl:u,changeTool:m,changeModel:v,changeEffort:w,toggleFastMode:x,togglePublic:f,guestNetwork:((N=r.codexSandbox)==null?void 0:N.network)??!1,toggleGuestNetwork:p,remove:_,loadPersonality:b,savePersonality:S,loadPersonalityLocal:C,savePersonalityLocal:k}}function hue({personaId:e,open:t,onClose:n,api:r,embedded:i,onDirtyChange:s,onShareCapability:o,viewerRole:a="owner"}){const l=due(e,a),{persona:c,detail:u}=l,d=g.useCallback(()=>{l.remove()&&n()},[l,n]);if(!c)return null;const f=a==="guest";return h.jsx(nue,{embedded:i,persona:{...c,skills:u.skills,plugins:u.plugins,sandboxSettings:u.sandboxSettings,personalityManaged:u.personalityManaged},open:t,onClose:n,onLoadPersonality:l.loadPersonality,onLoadPersonalityLocal:l.loadPersonalityLocal,hasPersonalityLocal:u.personalityLocal!=="",onDirtyChange:s,readOnly:f,...f?{}:{onTogglePublic:l.togglePublic,guestShareUrl:l.guestShareUrl,onChangeTool:l.changeTool,onChangeModel:l.changeModel,onChangeEffort:l.changeEffort,configSchema:l.configSchema,onDelete:d,onSavePersonality:l.savePersonality,onSavePersonalityLocal:l.savePersonalityLocal,larkBot:{status:l.larkBot.status,onProvision:l.larkBot.provision,onCancelProvision:l.larkBot.cancelProvision,onBindManual:l.larkBot.bindManual,onUnbind:l.larkBot.unbind,onUpgrade:l.larkBot.upgrade},...o?{onShareCapability:o}:{}}})}const fue={resolve:()=>{}},pue=g.createContext(fue);function mue(){return g.useContext(pue)}const gue={...Qs,h1:({node:e,...t})=>h.jsx("h1",{...t,className:"mt-4 mb-3 text-[18px] font-semibold leading-tight text-text-100"}),h2:({node:e,...t})=>h.jsx("h2",{...t,className:"mt-4 mb-2 text-[16px] font-semibold leading-tight text-text-100"}),h3:({node:e,...t})=>h.jsx("h3",{...t,className:"mt-3 mb-2 text-[14px] font-semibold leading-tight text-text-100"}),h4:({node:e,...t})=>h.jsx("h4",{...t,className:"mt-3 mb-1 text-[13px] font-semibold text-text-100"}),h5:({node:e,...t})=>h.jsx("h5",{...t,className:"mt-2 mb-1 text-[12px] font-semibold text-text-100"}),h6:({node:e,...t})=>h.jsx("h6",{...t,className:"mt-2 mb-1 text-[12px] font-semibold text-text-300"}),p:({node:e,...t})=>h.jsx("p",{...t,className:"my-2 leading-relaxed"}),ul:({node:e,...t})=>h.jsx("ul",{...t,className:"my-2 list-disc space-y-1 pl-5"}),ol:({node:e,...t})=>h.jsx("ol",{...t,className:"my-2 list-decimal space-y-1 pl-5"}),li:({node:e,...t})=>h.jsx("li",{...t,className:"leading-relaxed"}),blockquote:({node:e,...t})=>h.jsx("blockquote",{...t,className:"my-2 border-l-2 border-border pl-3 italic text-text-300"}),code:({node:e,className:t,children:n,...r})=>t?h.jsx("code",{...r,className:`${t} font-mono text-[12px]`,children:n}):h.jsx("code",{...r,className:"rounded bg-bg-50 px-1 py-0.5 font-mono text-[12px] text-text-100",children:n}),pre:({node:e,...t})=>h.jsx("pre",{...t,className:"my-2 overflow-auto rounded border border-border bg-bg-0 p-3 text-[12px] font-mono text-text-100"}),hr:({node:e,...t})=>h.jsx("hr",{...t,className:"my-3 border-border"}),table:({node:e,...t})=>h.jsx("table",{...t,className:"my-2 w-full border-collapse text-[12px]"}),thead:({node:e,...t})=>h.jsx("thead",{...t,className:"bg-bg-50"}),th:({node:e,...t})=>h.jsx("th",{...t,className:"border border-border px-2 py-1 text-left font-semibold"}),td:({node:e,...t})=>h.jsx("td",{...t,className:"border border-border px-2 py-1"}),strong:({node:e,...t})=>h.jsx("strong",{...t,className:"font-semibold text-text-100"}),em:({node:e,...t})=>h.jsx("em",{...t,className:"italic"})};function vue(e){const t=e.split("/");return t[t.length-1]||e}function dj({relPath:e,loadMarkdown:t,headerRight:n,showTitleBar:r=!1}){const[i,s]=g.useState(null),[o,a]=g.useState(null),[l,c]=g.useState(!1);return g.useEffect(()=>{if(!e)return;let u=!1;return c(!0),a(null),s(null),(async()=>{try{const d=await t(e);if(u)return;s(d)}catch(d){if(u)return;a(d.message||String(d))}finally{u||c(!1)}})(),()=>{u=!0}},[e,t]),h.jsxs("div",{className:"flex flex-col h-full",children:[r&&e?h.jsxs("div",{className:"flex items-center justify-between border-b border-border px-3 py-2",children:[h.jsx("div",{"data-testid":"md-preview-title",className:"truncate text-[13px] font-medium text-text-100",title:e,children:vue(e)}),h.jsx("div",{className:"flex items-center gap-1",children:n})]}):null,h.jsx("div",{className:"flex-1 overflow-auto px-4 py-3 text-[13px] text-text-100",children:l?h.jsx("div",{"data-testid":"md-preview-loading",className:"text-text-400",children:"Loading…"}):o?h.jsx("div",{"data-testid":"md-preview-error",className:"text-destructive whitespace-pre-wrap",children:o}):i!==null?h.jsx("div",{"data-testid":"md-preview-content",className:"max-w-none",children:h.jsx(yl,{remarkPlugins:[_l],components:gue,children:i})}):null})]})}function xue({open:e,onOpenChange:t,relPath:n,loadMarkdown:r,onShare:i}){return e?h.jsx("div",{"data-testid":"md-preview-drawer",className:`${pb} z-50 flex w-1/2 max-w-[900px] flex-col border-l border-border bg-elevated shadow-2xl`,children:h.jsx(dj,{relPath:n,loadMarkdown:r,showTitleBar:!0,headerRight:h.jsxs(h.Fragment,{children:[i?h.jsx("button",{type:"button","data-testid":"md-preview-share","aria-label":"Share rendered preview link",onClick:i,className:"inline-flex h-6 w-6 items-center justify-center rounded text-text-400 hover:bg-bg-50 hover:text-text-200",children:h.jsx(hF,{className:"h-4 w-4"})}):null,h.jsx("button",{type:"button","aria-label":"Close preview",onClick:()=>t(!1),className:"inline-flex h-6 w-6 items-center justify-center rounded text-text-400 hover:bg-bg-50 hover:text-text-200",children:h.jsx(Qr,{className:"h-4 w-4"})})]})})}):null}const LE=4;function yue({children:e,onHeightChange:t}){const n=g.useRef(null),[r,i]=g.useState(0);return g.useEffect(()=>{const s=n.current;if(!s)return;const o=()=>i(s.offsetHeight>0?s.offsetHeight+LE*2:0);if(o(),typeof ResizeObserver>"u")return;const a=new ResizeObserver(o);return a.observe(s),()=>a.disconnect()},[]),g.useEffect(()=>{t==null||t(r)},[r,t]),h.jsx("div",{"data-testid":"chat-floating-dock","data-height":r,className:"relative z-20 h-0 shrink-0",children:h.jsx("div",{ref:n,className:"absolute left-4 right-4 flex flex-col items-end gap-1",style:{bottom:LE},children:e})})}function _ue(e,t,n,r,i,s){const o=bm(),[a,l]=g.useState(null),[c,u]=g.useState(i??null),[d,f]=g.useState(!1),[p,m]=g.useState(!1),[v,w]=g.useState(null),x=g.useRef({api:e,sessionId:t,enabled:n,epoch:0,read:null,again:!1,mutating:!1}),_=g.useRef({api:e,sessionId:t,enabled:n});_.current={api:e,sessionId:t,enabled:n};const b=g.useRef(t),S=g.useRef(async()=>{}),C=E=>{if(E.workspace!==void 0&&l(E.workspace),E.binding!==void 0)u(E.binding);else if(E.workspace){const{workspaceId:j,repoId:P,owner:L,name:M,sourceBranch:R,defaultBranch:A}=E.workspace;u({workspaceId:j,repoId:P,owner:L,name:M,sourceBranch:R,defaultBranch:A})}},k=g.useCallback(async()=>{const E=x.current;if(!n||E.sessionId!==t||E.api!==e)return;if(E.mutating){E.again=!0;return}if(E.read)return E.again=!0,E.read;const j=E.epoch;f(!0);const P=(async()=>{try{const L=await e.cloudWorkspace({sessionId:t,action:"status"});x.current===E&&E.epoch===j&&_.current.sessionId===t&&(C(L),w(null))}catch(L){x.current===E&&E.epoch===j&&w(L.message)}finally{x.current===E&&(E.read=null,f(!1),E.again&&!E.mutating&&(E.again=!1,S.current()))}})();return E.read=P,P},[e,t,n]);S.current=k;const N=g.useCallback(async(E,j)=>{const P=x.current;if(!n||P.sessionId!==t)throw new Error("Cloud workspace unavailable");const L=E.action==="bind",M=["repositories","branches"].includes(E.action);if(L&&P.mutating)throw new Error("工作区操作正在进行");L&&(P.mutating=!0,P.epoch++,P.again=!1,m(!0),w(null));try{const R=await(j?e.cloudWorkspace({...E,sessionId:t},{requestId:j}):e.cloudWorkspace({...E,sessionId:t}));return x.current===P&&_.current.sessionId===t&&(C(R),M||w(null)),R}catch(R){throw x.current===P&&!M&&w(R.message),R}finally{L&&x.current===P&&(P.mutating=!1,m(!1),(E.action==="bind"||P.again)&&(P.again=!1,S.current()))}},[e,t,n]);return g.useEffect(()=>{const E={api:e,sessionId:t,enabled:n,epoch:0,read:null,again:!1,mutating:!1};return x.current=E,b.current!==t&&(b.current=t,l(null),u(i??null)),w(null),m(!1),f(!1),n&&S.current(),()=>{E.epoch++,x.current===E&&(x.current={...E,enabled:!1,again:!1})}},[e,t,n]),g.useEffect(()=>{if(!n||!r)return;const E=r.on("session:event",P=>{var M;const L=P;L.sessionId===t&&((M=L.event)==null?void 0:M.kind)==="session_init"&&S.current()}),j=r.on("daemon:connected",()=>{S.current()});return()=>{E(),j()}},[r,t,n]),g.useEffect(()=>{if(!(!r||!n))return r.on("cloud:workspace:timing",E=>{const j=E;if(j.sessionId===t)try{o==null||o.push({level:"info",msg:"cloud.workspace.transport."+j.phase,sessionId:t,meta:j})}catch{}})},[r,n,o,t]),{sessionId:t,workspace:a,binding:c,branchIntent:s,loading:d,busy:p,error:v,refresh:k,run:N}}function bue(e,t,n=()=>performance.now(),r){const i="workspace-"+crypto.randomUUID(),s=n(),o=r!==void 0&&Number.isFinite(r)&&r>=0&&r<=s?r:s,a=Math.round(s-o);let l,c,u="ok",d=!1;const f=(m,v={})=>{try{t("cloud.workspace.ui."+m,{...e,hasSearch:e.searchLength>0,traceId:i,inputDelayMs:a,...v})}catch{}},p=m=>{if(d)return;d=!0;const v=n();f("finished",{outcome:m,durationMs:Math.round(v-o),waitMs:l===void 0?void 0:Math.round(l-o),requestMs:l===void 0||c===void 0?void 0:Math.round(c-l),commitMs:c===void 0?void 0:Math.round(v-c)})};return f("started"),{requestId:i,get done(){return d},request(){l=n(),f("requested",{waitMs:Math.round(l-o)})},response(m,v,w){c=n(),u=m,f("response",{outcome:u,ignored:v,count:w,requestMs:l===void 0?void 0:Math.round(c-l)})},commit(){c!==void 0&&p(u)},finish:p}}var $m="Popover",[hj]=io($m,[Hl]),pd=Hl(),[wue,lo]=hj($m),fj=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,a=pd(t),l=g.useRef(null),[c,u]=g.useState(!1),[d,f]=$l({prop:r,defaultProp:i??!1,onChange:s,caller:$m});return h.jsx(cm,{...a,children:h.jsx(wue,{scope:t,contentId:bi(),triggerRef:l,open:d,onOpenChange:f,onOpenToggle:g.useCallback(()=>f(p=>!p),[f]),hasCustomAnchor:c,onCustomAnchorAdd:g.useCallback(()=>u(!0),[]),onCustomAnchorRemove:g.useCallback(()=>u(!1),[]),modal:o,children:n})})};fj.displayName=$m;var pj="PopoverAnchor",Sue=g.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=lo(pj,n),s=pd(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:a}=i;return g.useEffect(()=>(o(),()=>a()),[o,a]),h.jsx(um,{...s,...r,ref:t})});Sue.displayName=pj;var mj="PopoverTrigger",gj=g.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=lo(mj,n),s=pd(n),o=Ot(t,i.triggerRef),a=h.jsx(wt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":bj(i.open),...r,ref:o,onClick:Ne(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?a:h.jsx(um,{asChild:!0,...s,children:a})});gj.displayName=mj;var Lb="PopoverPortal",[kue,Cue]=hj(Lb,{forceMount:void 0}),vj=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=lo(Lb,t);return h.jsx(kue,{scope:t,forceMount:n,children:h.jsx(Jr,{present:n||s.open,children:h.jsx(dm,{asChild:!0,container:i,children:r})})})};vj.displayName=Lb;var Il="PopoverContent",xj=g.forwardRef((e,t)=>{const n=Cue(Il,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=lo(Il,e.__scopePopover);return h.jsx(Jr,{present:r||s.open,children:s.modal?h.jsx(Iue,{...i,ref:t}):h.jsx(Nue,{...i,ref:t})})});xj.displayName=Il;var Eue=pl("PopoverContent.RemoveScroll"),Iue=g.forwardRef((e,t)=>{const n=lo(Il,e.__scopePopover),r=g.useRef(null),i=Ot(t,r),s=g.useRef(!1);return g.useEffect(()=>{const o=r.current;if(o)return b_(o)},[]),h.jsx(fm,{as:Eue,allowPinchZoom:!0,children:h.jsx(yj,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Ne(e.onCloseAutoFocus,o=>{var a;o.preventDefault(),s.current||(a=n.triggerRef.current)==null||a.focus()}),onPointerDownOutside:Ne(e.onPointerDownOutside,o=>{const a=o.detail.originalEvent,l=a.button===0&&a.ctrlKey===!0,c=a.button===2||l;s.current=c},{checkForDefaultPrevented:!1}),onFocusOutside:Ne(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),Nue=g.forwardRef((e,t)=>{const n=lo(Il,e.__scopePopover),r=g.useRef(!1),i=g.useRef(!1);return h.jsx(yj,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var o,a;(o=e.onCloseAutoFocus)==null||o.call(e,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:s=>{var l,c;(l=e.onInteractOutside)==null||l.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const o=s.target;((c=n.triggerRef.current)==null?void 0:c.contains(o))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&i.current&&s.preventDefault()}})}),yj=g.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onInteractOutside:u,...d}=e,f=lo(Il,n),p=pd(n);return u_(),h.jsx(im,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:h.jsx(Yu,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onDismiss:()=>f.onOpenChange(!1),children:h.jsx(y_,{"data-state":bj(f.open),role:"dialog",id:f.contentId,...p,...d,ref:t,style:{...d.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)"}})})})}),_j="PopoverClose",Tue=g.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=lo(_j,n);return h.jsx(wt.button,{type:"button",...r,ref:t,onClick:Ne(e.onClick,()=>i.onOpenChange(!1))})});Tue.displayName=_j;var Pue="PopoverArrow",Rue=g.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=pd(n);return h.jsx(__,{...i,...r,ref:t})});Rue.displayName=Pue;function bj(e){return e?"open":"closed"}var Mue=fj,Aue=gj,jue=vj,wj=xj;const Sj=Mue,kj=Aue,Db=g.forwardRef(({className:e,align:t="center",sideOffset:n=4,...r},i)=>h.jsx(jue,{children:h.jsx(wj,{ref:i,align:t,sideOffset:n,className:ie("z-50 w-72 rounded-md border border-border bg-elevated p-4 text-text-100 shadow-md outline-none",e),...r})}));Db.displayName=wj.displayName;const Gi="flex w-full min-w-0 items-center gap-2.5 rounded-md px-1.5 py-1.5 text-left text-[13px] hover:bg-text-100/5 disabled:opacity-40",Lue=6e4,Cj=300;function Ej({message:e,onRetry:t}){return h.jsxs("div",{role:"alert",className:"m-2 rounded-md bg-error/5 p-2 text-[11px] leading-relaxed text-error",children:[e,h.jsx("button",{className:"ml-2 underline",onClick:t,children:"重试"})]})}const Due=()=>{let e=!1;return{get done(){return e},request(){},response(){},commit(){e=!0},finish(){e=!0}}};function Ij(e,t){const n=g.useRef(null),r=g.useRef(void 0),i=a=>{r.current=a.timeStamp},s=(a,l,c)=>{var d;(d=n.current)==null||d.finish("superseded");const u=e(a,l,c);return n.current=u,u};return g.useLayoutEffect(()=>{var a;t||(a=n.current)==null||a.commit()}),g.useEffect(()=>()=>{var a;(a=n.current)==null||a.finish("unmounted")},[]),{current:n,begin:s,open:(a,l)=>{const c=r.current;r.current=void 0,s(a,l,c)},captureOpen:i}}function Oue({load:e,onPick:t,trigger:n,disabled:r,align:i="end",contentClassName:s="w-[330px] p-1.5",startTiming:o=Due}){const[a,l]=g.useState(!1),[c,u]=g.useState(""),[d,f]=g.useState(""),[p,m]=g.useState([]),[v,w]=g.useState(1),[x,_]=g.useState(!1),[b,S]=g.useState(!1),[C,k]=g.useState(null),[N,E]=g.useState(0),j=Ij(o,b),P=g.useRef(!1),L=g.useRef(e);L.current=e;const M=g.useRef(new Map);return g.useEffect(()=>{if(c===d)return;const R=setTimeout(()=>{f(c),w(1)},Cj);return()=>clearTimeout(R)},[c,d]),g.useEffect(()=>{if(!a)return;const R=j.current.current&&!j.current.current.done?j.current.current:j.begin(d.length,v),A=d+"|"+v,D=O=>{_(O.hasMore),m(I=>v===1?O.repos:[...I,...O.repos])},z=M.current.get(A);k(null);const F=P.current;if(P.current=!1,z&&Date.now()-z.at<Lue&&!F){R.response("cache",!1,z.repos.length),D({...z,repos:[...z.repos]}),S(!1);return}let $=!1;return S(!0),R.request(),L.current(v,d,R.requestId).then(O=>{var U;if(R.response("ok",$,((U=O.repositories)==null?void 0:U.length)??0),$)return;const I={at:Date.now(),repos:O.repositories??[],hasMore:O.hasMore??!1};M.current.set(A,I),D(I)}).catch(O=>{R.response("error",$),$||k(O.message)}).finally(()=>{$||S(!1)}),()=>{$=!0,R.finish("cancelled")}},[a,d,v,N]),h.jsxs(Sj,{open:a,onOpenChange:R=>{var A;R?j.open(d.length,v):(A=j.current.current)==null||A.finish("closed"),l(R),R||(w(1),u(""),f(""))},children:[h.jsx(kj,{asChild:!0,onClickCapture:j.captureOpen,children:n}),h.jsxs(Db,{align:i,className:s,children:[h.jsxs("div",{className:"flex items-center gap-2 border-b border-border p-2",children:[h.jsx(Uf,{className:"h-3.5 w-3.5 text-text-400"}),h.jsx("input",{autoFocus:!0,"aria-label":"搜索仓库",placeholder:"搜索 GitHub 仓库…",value:c,onChange:R=>{R.target.value!==c&&j.begin(R.target.value.length,1,R.timeStamp),u(R.target.value)},className:"w-full bg-transparent text-[12px] outline-none"})]}),h.jsxs("div",{className:"max-h-[340px] overflow-y-auto py-1",children:[p.map(R=>h.jsxs("button",{disabled:r,className:Gi,onClick:()=>{k(null),Promise.resolve(t(R)).then(()=>l(!1)).catch(A=>k(A.message))},children:[h.jsx(fx,{className:"h-4 w-4 shrink-0 text-text-400"}),h.jsxs("span",{className:"truncate text-[12px]",children:[R.owner,"/",R.name]})]},R.repoId)),C&&h.jsx(Ej,{message:C,onRetry:()=>{j.begin(d.length,v),P.current=!0,E(R=>R+1)}}),!b&&!C&&!p.length&&h.jsx("p",{className:"p-3 text-[12px] text-text-400",children:"没有找到仓库"}),b&&h.jsxs("div",{className:"flex items-center gap-2 p-3 text-[12px] text-text-400",children:[h.jsx(Tn,{className:"h-3 w-3 animate-spin"}),"正在读取…"]}),x&&!b&&h.jsx("button",{className:Gi,onClick:R=>{j.begin(d.length,v+1,R.timeStamp),w(A=>A+1)},children:"加载更多"})]})]})]})}function DE({title:e,children:t,trailing:n}){const[r,i]=g.useState(!0);return h.jsxs("section",{className:"rounded-[22px] border border-border bg-bg-100 p-3.5 shadow-[0_2px_12px_rgba(0,0,0,0.06)]",children:[h.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[h.jsxs("button",{onClick:()=>i(!r),className:"flex items-center gap-1.5 py-0.5 text-[13px] text-text-400","aria-expanded":r,children:[e,h.jsx(Pn,{className:`h-3 w-3 text-text-400 ${r?"":"-rotate-90"}`})]}),n]}),r&&t]})}function Bue(e,t,n){return Ij(Nj(e,t),n)}function Nj(e,t){const n=bm();return(r,i,s)=>bue({sessionId:e.sessionId,action:t,searchLength:r,page:i},(o,a)=>{n==null||n.push({level:"info",msg:o,sessionId:e.sessionId,meta:a})},void 0,s)}function Tj({controller:e,compact:t=!1}){const{binding:n,run:r,busy:i}=e,s=Nj(e,"repositories");return n?h.jsxs("button",{className:t?"flex min-w-0 items-center gap-1.5 text-[11px] text-text-300 hover:text-text-100":Gi,title:n.owner+"/"+n.name,"aria-label":"在 GitHub 查看仓库",onClick:()=>window.open(`https://github.com/${n.owner}/${n.name}`,"_blank","noopener"),children:[h.jsx(fx,{className:"h-4 w-4 shrink-0 text-text-400"}),h.jsx("span",{className:"truncate",children:n.name}),!t&&h.jsx(ku,{className:"ml-auto h-3 w-3 text-text-400"})]}):h.jsx(Oue,{load:(o,a,l)=>r({action:"repositories",page:o,search:a},l),onPick:async o=>{await r({action:"bind",repoId:o.repoId,branch:o.defaultBranch})},disabled:i,startTiming:s,trigger:h.jsxs("button",{disabled:i,className:t?"flex items-center gap-1.5 text-[11px] text-text-300":Gi,"aria-label":"添加或选择仓库",children:[h.jsx(fx,{className:"h-4 w-4 text-text-400"}),h.jsx("span",{className:"flex-1",children:"添加 repo"}),!t&&h.jsx(g4,{className:"h-3.5 w-3.5 text-text-400"})]})})}function Pj({controller:e,compact:t=!1,disabled:n=!1}){const{binding:r,workspace:i,branchIntent:s,run:o,busy:a}=e,[l,c]=g.useState(!1),[u,d]=g.useState(""),[f,p]=g.useState(""),[m,v]=g.useState([]),[w,x]=g.useState(1),[_,b]=g.useState(),[S,C]=g.useState(),[k,N]=g.useState(!1),[E,j]=g.useState(!1),[P,L]=g.useState(null),[M,R]=g.useState(0),A=Bue(e,"branches",E),D=u.trim();g.useEffect(()=>{if(D===f)return;if(!D){p("");return}const I=setTimeout(()=>p(D),Cj);return()=>clearTimeout(I)},[D,f]),g.useEffect(()=>{if(!l||!r||D!==f)return;const I=A.current.current&&!A.current.current.done?A.current.current:A.begin(f.length,w);let U=!1;return L(null),j(!0),I.request(),o({action:"branches",repoId:r.repoId,...f?{search:f,..._?{cursor:_}:{}}:{page:w}},I.requestId).then(q=>{var B;I.response("ok",U,((B=q.branches)==null?void 0:B.length)??0),U||(v(te=>(f?!_:w===1)?q.branches??[]:[...te,...q.branches??[]]),N(!!(q.hasMore&&(!f||q.nextCursor))),C(q.nextCursor))}).catch(q=>{I.response("error",U),U||L(q.message)}).finally(()=>{U||j(!1)}),()=>{U=!0,I.finish("cancelled")}},[l,r==null?void 0:r.repoId,D,f,w,_,M,o]);const z=I=>{var U;I?A.open(f.length,w):(U=A.current.current)==null||U.finish("closed"),c(I),I||(d(""),p(""),v([]),x(1),b(void 0),C(void 0),N(!1),j(!1),L(null))},F=s??(i==null?void 0:i.actualBranch)??(i?"HEAD · "+i.head.slice(0,7):(r==null?void 0:r.sourceBranch)??"选择 branch"),$=[...new Set([...[...r?[r.defaultBranch]:[],...i!=null&&i.actualBranch?[i.actualBranch]:[],...(i==null?void 0:i.branches)??[]].filter(I=>I.toLowerCase().includes(D.toLowerCase())),...m])],O=I=>{const U=I===((i==null?void 0:i.actualBranch)??(r==null?void 0:r.sourceBranch));o(U?{action:"intend"}:{action:"intend",branch:I}).then(()=>{z(!1)}).catch(()=>{})};return h.jsxs(Sj,{open:l,onOpenChange:z,children:[h.jsx(kj,{asChild:!0,children:h.jsxs("button",{onClickCapture:A.captureOpen,className:t?"flex min-w-0 items-center gap-1.5 text-[11px] text-text-300 disabled:opacity-40":Gi,"aria-label":`选择分支,当前 ${F}`,disabled:a||n,children:[h.jsx(Cu,{className:"h-3.5 w-3.5 shrink-0 text-text-400"}),h.jsx("span",{className:"truncate",children:F}),h.jsx(Pn,{className:"ml-auto h-3 w-3 shrink-0 text-text-400"})]})}),h.jsxs(Db,{align:"end",className:"w-[280px] p-1.5",children:[h.jsxs("div",{className:"flex items-center gap-2 border-b border-border p-2",children:[h.jsx(Uf,{className:"h-3.5 w-3.5 text-text-400"}),h.jsx("input",{autoFocus:!0,"aria-label":"搜索分支",placeholder:"搜索分支…",value:u,maxLength:100,onChange:I=>{d(I.target.value),I.target.value.trim()!==D&&(A.begin(I.target.value.trim().length,1,I.timeStamp),v([]),x(1),b(void 0),C(void 0),N(!1),L(null),j(!0))},className:"w-full bg-transparent text-[12px] outline-none"})]}),h.jsxs("div",{className:"max-h-[300px] overflow-y-auto",children:[(D===f?$:[]).map(I=>h.jsxs("button",{className:Gi,onClick:()=>O(I),children:[h.jsx(Cu,{className:"h-3.5 w-3.5 text-text-400"}),h.jsx("span",{className:"flex-1 truncate",children:I}),I===(r==null?void 0:r.defaultBranch)&&h.jsx("span",{className:"text-[10px] text-text-400",children:"默认"}),I===F&&h.jsx(no,{className:"h-3.5 w-3.5"})]},I)),P&&h.jsx(Ej,{message:P,onRetry:()=>{A.begin(f.length,w),R(I=>I+1)}}),E&&h.jsxs("div",{role:"status",className:"flex items-center gap-2 p-3 text-[12px] text-text-400",children:[h.jsx(Tn,{className:"h-3 w-3 animate-spin"}),"正在读取…"]}),!E&&!P&&!$.length&&h.jsx("p",{className:"p-3 text-[12px] text-text-400",children:"没有找到分支"}),k&&h.jsx("button",{className:Gi,disabled:E||!!P,onClick:I=>{A.begin(f.length,w+1,I.timeStamp),j(!0),f?b(S):x(U=>U+1)},children:"加载更多分支"})]})]})]})}function $ue({controller:e,disabled:t=!1}){return h.jsxs("div",{"data-testid":"workspace-input-chip",className:"flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 px-1 pb-2 text-text-300",children:[h.jsx("div",{className:"max-w-[200px] min-w-0",children:h.jsx(Tj,{controller:e,compact:!0})}),e.binding&&h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"h-3 w-px bg-border"}),h.jsx("div",{className:"min-w-0 max-w-[230px]",children:h.jsx(Pj,{controller:e,compact:!0,disabled:t},e.binding.repoId)})]}),e.loading&&h.jsx(Tn,{className:"h-3 w-3 shrink-0 animate-spin text-text-400"})]})}function zue({controller:e,disabled:t=!1}){var v;const{binding:n,workspace:r,branchIntent:i,loading:s,busy:o,error:a,refresh:l,run:c}=e,[u,d]=g.useState(null),[f,p]=g.useState();g.useEffect(()=>{if(!u){p(void 0);return}let w=!1;return p(void 0),c({action:"diff",filePath:u}).then(x=>{w||p(x.diff)}).catch(()=>{}),()=>{w=!0}},[u,c]);const m=(v=r==null?void 0:r.files.find(w=>w.path===u))==null?void 0:v.comparison;return h.jsxs("div",{className:"space-y-3",children:[h.jsxs(DE,{title:"环境",trailing:h.jsx("button",{"aria-label":"刷新工作区",title:"刷新工作区",disabled:o||s,onClick:()=>void l(),className:"p-1 text-text-400 disabled:opacity-40",children:h.jsx(AF,{className:`h-3 w-3 ${s?"animate-spin":""}`})}),children:[h.jsxs("div",{className:"flex items-center gap-2.5 px-1.5 py-1.5 text-[13px]",children:[h.jsx(B7,{className:"h-4 w-4 text-text-400"}),h.jsx("span",{children:"云端"}),h.jsx("span",{className:"ml-auto text-[11px] text-text-400",children:n?"已关联":"待关联"})]}),h.jsx(Tj,{controller:e}),n&&h.jsx(Pj,{controller:e,disabled:t},n.repoId),i&&h.jsxs("p",{className:"mt-1 px-1.5 text-[11px] text-text-400",children:["将在下一条消息里让 agent 切换到 ",i]}),r&&h.jsxs("p",{className:"mt-1 px-1.5 text-[10px] text-text-400",children:["截至 ",JH(new Date(r.measuredAt).toISOString())," ·"," ",r.head.slice(0,7)]}),!n&&h.jsx("p",{className:"mt-2 px-1.5 text-[11px] leading-relaxed text-text-400",children:"关联仓库和分支,在这个会话的独立工作区里开发。"}),a&&h.jsxs("div",{role:"alert",className:"mt-2 rounded-md bg-error/5 p-2 text-[11px] leading-relaxed text-error",children:[a,h.jsx("button",{className:"ml-2 underline",onClick:()=>void l(),children:"重试读取"})]})]}),!!(r!=null&&r.files.length)&&h.jsxs(DE,{title:"Changes",trailing:h.jsxs("span",{className:"text-[10px] text-text-400",children:[r.totalFiles??r.files.length," 个文件"]}),children:[h.jsxs("button",{"aria-label":"查看全部改动",className:Gi,onClick:()=>d(r.files[0].path),children:[h.jsx(K7,{className:"h-4 w-4 text-text-400"}),h.jsxs("span",{className:"tabular-nums text-success",children:["+",r.added]}),h.jsxs("span",{className:"tabular-nums text-error",children:["−",r.removed]}),h.jsx(u4,{className:"ml-auto h-3 w-3 text-text-400"})]}),h.jsx("div",{className:"mb-2",children:r.files.map(w=>h.jsxs("button",{className:"flex w-full min-w-0 items-center gap-2 rounded-md px-1.5 py-1.5 text-left text-[11px] hover:bg-text-100/5",onClick:()=>d(w.path),children:[h.jsx("span",{className:"w-4 shrink-0 text-[10px] text-text-400",children:w.status}),h.jsx("span",{title:w.path,className:"min-w-0 flex-1 truncate text-text-300",children:w.path.split("/").at(-1)}),h.jsxs("span",{className:"text-success",children:["+",w.added]}),h.jsxs("span",{className:"text-error",children:["−",w.removed]})]},w.path))}),r.filesTruncated&&h.jsx("p",{className:"mb-2 px-1 text-[11px] text-text-400",children:"仅展示前 200 个改动文件。"})]}),h.jsx(aj,{open:u!==null,onOpenChange:w=>{w||d(null)},children:h.jsxs(Ab,{className:"flex h-[min(680px,84vh)] w-[min(1080px,94vw)] max-w-none flex-col gap-0 overflow-hidden p-0",children:[h.jsxs("div",{className:"border-b border-border px-5 py-4",children:[h.jsx(jb,{className:"text-[14px]",children:"代码改动"}),h.jsxs(uj,{className:"mt-2 text-[11px]",children:[(r==null?void 0:r.actualBranch)??"HEAD"," ·"," ",m==="index"?"暂存区相对当前提交的改动":m==="head"?"尚未提交的改动":"相对起始提交 "+(r==null?void 0:r.initialCommit.slice(0,7))+" 的累计改动"]})]}),h.jsxs("div",{className:"flex min-h-0 flex-1",children:[h.jsx("nav",{"aria-label":"改动文件",className:"w-[225px] shrink-0 overflow-auto border-r border-border bg-bg-50 p-2 max-[700px]:hidden",children:r==null?void 0:r.files.map(w=>h.jsx("button",{className:Gi+" text-[11px]",onClick:()=>d(w.path),children:h.jsx("span",{className:"truncate",children:w.path.split("/").at(-1)})},w.path))}),h.jsxs("div",{className:"min-w-0 flex-1 overflow-auto",children:[h.jsx("div",{className:"sticky top-0 border-b border-border bg-bg-50 px-4 py-3 font-mono text-[11px]",children:u}),f?f.binary?h.jsx("p",{className:"p-5 text-[12px] text-text-400",children:"二进制文件发生变化"}):f.notStored?h.jsx("p",{className:"p-5 text-[12px] text-text-400",children:"这个文件的补丁暂不可用(文件较多或体积较大时只保存部分补丁)。"}):h.jsxs("pre",{className:"min-w-fit py-2 font-mono text-[11px] leading-6",children:[f.patch.split(`
|
|
623
|
-
`).map((w,x)=>h.jsx("div",{className:`px-4 ${w.startsWith("+")?"bg-success/8 text-success":w.startsWith("-")?"bg-error/8 text-error":"text-text-300"}`,children:w||" "},x)),f.truncated&&h.jsx("div",{className:"px-4 text-text-400",children:"Diff 较大,已截断显示。"})]}):h.jsx("div",{className:"p-5 text-[12px] text-text-400",children:a??"正在读取 diff…"})]})]})]})})]})}const Fue=250;function Hue(e){if(!e||!Number.isFinite(e))return null;const t=e/1e3;if(t<60)return`${t.toFixed(0)}s`;const n=Math.floor(t/60);return`${n}m${Math.round(t-n*60).toString().padStart(2,"0")}s`}function Uue({agents:e}){var l,c,u;const[t,n]=g.useState(!1),r=g.useRef(null);if(g.useEffect(()=>{if(!t)return;const d=f=>{const p=r.current;p&&f.target instanceof Node&&p.contains(f.target)||n(!1)};return window.addEventListener("pointerdown",d,!0),()=>window.removeEventListener("pointerdown",d,!0)},[t]),e.length===0)return null;const i=e.length===1?e[0]:null,s=i?i.description:`${e.length} 个后台任务`,o=i?Hue((c=(l=i.progress)==null?void 0:l.stats)==null?void 0:c.durationMs):null,a=i?(u=i.progress)==null?void 0:u.lastToolName:null;return h.jsxs("div",{ref:r,"data-testid":"running-agents-chip","data-agent-count":e.length,className:"relative",children:[t?h.jsx("div",{"data-testid":"running-agents-popover",className:"absolute bottom-full right-0 z-20 mb-1 w-[min(560px,80vw)]",children:h.jsx("div",{className:"min-w-0 overflow-y-auto rounded-lg border border-bg-200/60 bg-bg-100 px-2 py-1 shadow-lg",style:{maxHeight:Fue},children:e.map(d=>h.jsx(PM,{expandable:!1,description:d.description,input:d.input,output:d.output,...d.error!==void 0?{error:d.error}:{},pending:d.pending,notifications:d.notifications,...d.toolResultExtra?{toolResultExtra:d.toolResultExtra}:{},...d.progress?{progress:d.progress}:{}},d.toolUseId))})}):null,h.jsxs("button",{type:"button","data-testid":"running-agents-chip-toggle","aria-expanded":t,onClick:()=>n(d=>!d),className:ie("flex max-w-[min(560px,80vw)] min-w-0 items-center gap-2 rounded-full","border border-bg-200/60 bg-bg-100/95 px-3 py-1 text-[12px] shadow-md backdrop-blur","hover:bg-bg-200/95 transition-colors"),children:[h.jsx(Tn,{className:"w-3 h-3 shrink-0 animate-spin text-blue-400"}),h.jsx("span",{className:"min-w-0 flex-1 truncate text-left text-text-200",children:s}),o?h.jsx("span",{className:"shrink-0 tabular-nums text-text-400",children:o}):null,a?h.jsxs("span",{className:"shrink-0 font-mono tabular-nums text-blue-400",children:["now:",a]}):null,h.jsx(d4,{className:ie("w-3.5 h-3.5 shrink-0 text-text-400 transition-transform",t&&"rotate-180")})]})]})}const Wue={closeTrailing:!1},que={closeTrailing:!0};function Vue(e){return e?Wue:que}function Kue({session:e,api:t,onPromoteQuickAsk:n}){const r=eR(e.sessionId);return h.jsx(Rj,{state:r,extras:{session:e,api:t,...n?{onPromoteQuickAsk:n}:{}}})}function Gue({headerMeta:e,connState:t,liveWorktreeRoot:n,onOpenConfig:r,variant:i="full",ephemeral:s,onPromote:o,hideHeader:a=!1,flatProcess:l=!1,lines:c,pendingPermissions:u,procAlive:d,rewindableUserMessageIds:f,onPermissionRespond:p,onPermissionInterrupt:m,onRewind:v,onFork:w,onQuickAsk:x,topSlot:_,codexHistory:b,realtimeQuestionAnswers:S,onSubmitQuestion:C,onCancelQuestion:k,liveQuestionToolUseIds:N,api:E,cwd:j,tool:P,cloudVolume:L,sessionKey:M,onSend:R,awaitingUser:A,queued:D,onDequeue:z,onAbort:F,onNewSession:$,onClearSession:O,configSlot:I,workspaceInput:U,workspaceInputDisabled:q,chatRootRef:B,chatBodyRef:te,drawers:le,xtermSlot:Y,fileSharingScope:re,onShareFile:ke,onOpenInTab:oe,onPreviewMarkdown:Ie,onOpenFilePath:Ee,dispatchOrigin:Re}){const[he,Be]=g.useState(0),Je=g.useMemo(()=>i==="full"?NY(rR(c)):[],[c,i]),Ge=g.useMemo(()=>new Set(Je.map(ft=>ft.toolUseId)),[Je]);return h.jsx(wie,{children:h.jsxs("div",{ref:B,"data-cc-chat-root":"",className:"flex flex-col h-full bg-bg-100",children:[a?null:h.jsx(_se,{meta:e,...P?{tool:P}:{},...L?{cloudVolume:L}:{},connState:t,variant:i,...n!==void 0?{liveWorktreeRoot:n}:{},...i==="full"&&r?{onOpenConfig:r}:{},...i==="quickask"?{ephemeral:s??!1,...o?{onPromote:o}:{}}:{}}),h.jsx("div",{ref:te,"data-testid":"chat-body",className:"flex-1 overflow-y-auto min-h-0",style:{overflowAnchor:"none",paddingBottom:he},children:h.jsx(MM,{lines:c,forkByTurn:P==="codex"||P===Wy,...p?{onPermissionRespond:p}:{},...m&&d?{onPermissionInterrupt:m}:{},topSlot:_,codexHistory:b,...v?{onRewind:v}:{},rewindableUserMessageIds:f,...w?{onFork:w}:{},...x?{onQuickAsk:x}:{},realtimeQuestionAnswers:S,onSubmitQuestion:C,...k?{onCancelQuestion:k}:{},liveQuestionToolUseIds:N,...re?{fileSharingScope:re}:{},...ke?{onShareFile:ke}:{},...oe?{onOpenInTab:oe}:{},...Ie?{onPreviewMarkdown:Ie}:{},...Ee?{onOpenFilePath:Ee}:{},...Re?{dispatchOrigin:Re}:{},...i==="full"&&!l?{turnCollapse:Vue(d)}:{},dockedAgentToolUseIds:Ge})}),Y,h.jsx(yue,{onHeightChange:Be,children:h.jsx(Uue,{agents:Je})}),e.larkChatName?h.jsx("div",{className:"mx-3 mb-3 rounded-lg border border-border bg-bg-200 px-3 py-2 text-[12px] text-text-400","data-testid":"lark-readonly-notice",children:e.larkChatType==="p2p"?`此会话由与「${e.larkChatName}」的飞书私聊驱动——对方消息触发,这里仅供观察。`:`此会话由飞书群「${e.larkChatName}」驱动——群成员 @ bot 提问触发,这里仅供观察。`}):h.jsx(xse,{meta:e,aboveSlot:U,disabled:q,...E?{api:E}:{},cwd:j,...P?{tool:P}:{},sessionKey:M,onSend:R,awaitingUser:A,...D?{queued:D}:{},...z?{onDequeue:z}:{},...F?{onAbort:F}:{},...$?{onNewSession:$}:{},...O?{onClearSession:O}:{},...I?{configSlot:I}:{}}),le]})})}function Rj({state:e,extras:t,onQuickAskInternal:n,onPreviewMdInternal:r}){var xr;const{session:i,api:s,liveGitBranch:o,liveWorktreeRoot:a,cloudVolume:l,onNewSession:c,onTurnEnd:u,onOpenConfig:d,onFork:f,onQuickAsk:p,viewerRole:m,onPromoteQuickAsk:v,configSlot:w,hideHeader:x,flatProcess:_}=t,{capabilities:b}=Am(i.tool||"claude"),S=(b==null?void 0:b.features)??t4(i.tool),[C,k]=g.useState(null),[N,E]=g.useState(null),j=Jp(),P=!!s&&j.actionsLevel==="owner"&&S.fileSharing,L=a4(i.ownerPersonaId??null).persona,M=(L==null?void 0:L.label)??null,R=!!M&&!!i.ownerPersonaId,A=mue(),D=g.useMemo(()=>({resolve:(Z,we)=>A.resolve(Z,we,i.sessionId),...A.onOpenSession?{onOpenSession:A.onOpenSession}:{}}),[A,i.sessionId]),z=g.useCallback((Z,we)=>{k({kind:Z,text:we}),setTimeout(()=>{k(De=>(De==null?void 0:De.text)===we?null:De)},2e3)},[]),F=Ni(),$=Wc(i.tool)&&m!=="guest"&&!i.larkChatId&&!v,O=_ue(s,i.sessionId,$,F,i.cloudWorkspace,i.cloudBranchIntent),I=Cz(),U=XP(i.sessionId,i.toolSessionId),{events:q,pendingQuestions:B,clearQuestion:te,markQuestionSubmitted:le,status:Y}=U,re=e.historyLoading,ke=JP(Y);g.useEffect(()=>{$e("chat-panel","sessionStatus",{sessionId:i.sessionId,sessionStatus:Y,procAlive:ke})},[Y,ke,i.sessionId]);const oe=e.lines,Ie=e.pendingPermissions,Ee=Ie[0]??null,Re=g.useMemo(()=>EY(q),[q]),[he,Be]=g.useState(null),[Je,Ge]=g.useState(()=>new Set);SY(s,i.sessionId,i.toolSessionId,S.observe);const ft=g.useRef(i.sessionId);g.useEffect(()=>{if(ft.current=i.sessionId,!S.rewind){Be(null);return}let Z=!1;return Be(null),(async()=>{try{const we=await s.sessionRewindableMessageIds(i.sessionId);if(Z)return;Be(new Set(we.userMessageIds))}catch{Z||Be(null)}})(),()=>{Z=!0}},[s,i.sessionId,S.rewind]);const Kt=g.useCallback(()=>{const Z=i.sessionId;s.sessionRewindableMessageIds(Z).then(we=>{ft.current===Z&&Be(new Set(we.userMessageIds))}).catch(()=>{})},[s,i.sessionId]),fe=g.useMemo(()=>{if(he!==null){const ct=new Set(he);for(const Br of Je)ct.delete(Br);return ct}const Z=new Set(["Edit","Write","MultiEdit","NotebookEdit"]),we=new Set;let De=null;for(const ct of oe)ct.kind==="user-text"?De=ct.uuid??null:De&&ct.kind==="tool-call"&&Z.has(ct.tool)&&!Je.has(De)&&we.add(De);return we},[oe,Je,he]),He=g.useRef(u);He.current=u,kY(i.sessionId,i.toolSessionId,()=>{hn(null),Ge(new Set)});const Pe=Dse({sessionStatus:Y}),Me=g.useRef(null);g.useEffect(()=>{var De;const Z=Me.current,we=(Z==null?void 0:Z.sid)===i.sessionId;we&&Z.phase===Pe||(Me.current={sid:i.sessionId,phase:Pe},$e("session-phase",Pe,{sid:i.sessionId,phase:Pe,prev:we?Z.phase:null,desc:Lse[Pe]}),we&&Z.phase==="turn-running"&&Pe!=="turn-running"&&((De=He.current)==null||De.call(He),Kt()))},[Pe,i.sessionId,Kt]);const rt=g.useCallback(async()=>{const Z=await s.sessionInterrupt(i.sessionId).catch(()=>{});return(Z==null?void 0:Z.queued)??[]},[s,i.sessionId]),[tn,hn]=g.useState(null),W=g.useCallback(Z=>{hn(Z)},[]),[ee,be]=g.useState(!1),Oe=g.useCallback(()=>{s.sessionStop(i.sessionId).catch(()=>{}),be(!1)},[s,i.sessionId]);g.useCallback(Z=>{s.pinSession(i.sessionId,Z).catch(we=>{$e("chat-panel","pinSession failed",{err:we==null?void 0:we.message})})},[s,i.sessionId]);const Ue=v?"quickask":"full",{container:At,workspaceContainer:bn,onCollapse:nn,hostExtras:fn}=Ise(),ce=g.useRef(0),Se=g.useRef(null);g.useEffect(()=>{const Z=we=>{if(we.key!=="Escape")return;if(!ke){ce.current=0;return}if(we.isComposing)return;const ct=we.target;if(ct&&ct.closest("[data-cc-chat-root]")!==Se.current)return;const Br=Date.now();Br-ce.current<2e3?(ce.current=0,be(!0)):(ce.current=Br,rt())};return window.addEventListener("keydown",Z),()=>window.removeEventListener("keydown",Z)},[rt,ke]);const st=g.useRef(null),gt=g.useRef(null),gr=g.useRef(!!e.codexHistory);gr.current=!!e.codexHistory;const ae=g.useRef(!0),it=g.useRef(void 0),Bt=g.useRef(0),ti=g.useRef(0),oa=g.useRef(void 0);g.useEffect(()=>{E(null)},[i.sessionId]),g.useEffect(()=>{const Z=st.current;if(!Z)return;const we=150,De=ct=>{gr.current||Date.now()<ti.current&&(ct.preventDefault(),ti.current=Date.now()+we)};return Z.addEventListener("wheel",De,{passive:!1}),()=>Z.removeEventListener("wheel",De)},[]),g.useEffect(()=>{const Z=st.current;if(!Z)return;const we=32,De=()=>{var Br;const ct=Z.scrollHeight-Z.scrollTop-Z.clientHeight;ae.current=ct<=we,e.codexHistory&&(gt.current=S2(Z)),Z.scrollTop<=24&&e.historyHasMore&&!e.historyLoadingOlder&&!e.historyError&&!re&&((Br=e.loadOlderHistory)==null||Br.call(e))};return Z.addEventListener("scroll",De,{passive:!0}),()=>Z.removeEventListener("scroll",De)},[e.codexHistory,e.historyHasMore,e.historyLoadingOlder,e.historyError,e.loadOlderHistory,re]),g.useLayoutEffect(()=>{var Ob;const Z=st.current;if(!Z)return;const we=oa.current!==i.sessionId;we&&(oa.current=i.sessionId,ae.current=!0,it.current=void 0,Bt.current=0,ti.current=0,gt.current=null);const De=it.current,ct=(Ob=oe[0])==null?void 0:Ob.seq;if(it.current=ct,e.codexHistory){!we&>.current&&!ae.current?Fie(Z,gt.current):ae.current&&(Z.scrollTop=Z.scrollHeight),gt.current=S2(Z),Bt.current=Z.scrollHeight-Z.scrollTop;return}!we&&De!==void 0&&ct!==void 0&&ct<De?(Z.scrollTop=Z.scrollHeight-Bt.current,ti.current=Date.now()+200):ae.current&&(Z.scrollTop=Z.scrollHeight),Bt.current=Z.scrollHeight-Z.scrollTop},[oe,Ee==null?void 0:Ee.requestId,i.sessionId]);const aa=g.useMemo(()=>{const Z={};for(const[we,De]of Object.entries(B))De.submittedAnswers&&(Z[we]=De.submittedAnswers);return Z},[B]),ds=g.useMemo(()=>new Set(Object.keys(B)),[B]),la=g.useCallback(async(Z,we)=>{try{await s.answerQuestion({sessionId:i.sessionId,toolUseId:Z,answers:we}),le(Z,we)}catch{}},[s,i.sessionId,le]),Yl=g.useCallback(async Z=>{try{await s.cancelQuestion({sessionId:i.sessionId,toolUseId:Z}),te(Z)}catch{}},[s,i.sessionId,te]),Xl=g.useCallback(async(Z,we)=>{var De;if(Ee)try{await((De=e.respondPermission)==null?void 0:De.call(e,Ee.requestId,Z?"allow":"deny"))}catch{}},[e,Ee]),hs=g.useCallback(async()=>{const Z=i.sessionId;try{await s.sessionStop(Z)}catch{}e.clearSession?await e.clearSession():await s.sessionNew(Z)},[e,s,i.sessionId]),ni=e.meta.streamInProgress??!1,md=g.useMemo(()=>{if(e.codexHistory)return h.jsxs("div",{className:"flex flex-col items-center gap-2 py-2 text-xs text-text-400","data-testid":"codex-history-top",children:[e.historySyncError?h.jsx("span",{children:e.historySyncError}):null,e.historyError?h.jsx("span",{"data-testid":"history-error",children:e.historyError}):null,re||e.historyLoadingOlder?h.jsx("span",{"data-testid":"history-loading",children:"正在加载历史…"}):e.historyHasMore?h.jsx("button",{type:"button",onClick:()=>{var we;return void((we=e.loadOlderHistory)==null?void 0:we.call(e))},children:e.historyError?"重试更早记录":"加载更早记录"}):e.historyLoaded&&!e.historyError&&!e.historySyncError?h.jsx("span",{children:"已加载全部轮次摘要"}):null,e.historyError||e.historySyncError?h.jsx("button",{type:"button",onClick:()=>{var we;return void((we=e.refreshHistory)==null?void 0:we.call(e))},children:"刷新历史"}):null]});const Z=e.historySyncError?h.jsxs("div",{className:"flex justify-center items-center gap-2 py-2 text-[12px] text-text-400","data-testid":"history-sync-error",children:[h.jsx("span",{children:e.historySyncError}),e.reloadFromCloud?h.jsx("button",{type:"button","data-testid":"history-sync-reload",disabled:ni,onClick:e.reloadFromCloud,className:"text-accent hover:underline cursor-pointer disabled:cursor-not-allowed disabled:opacity-50 disabled:no-underline",children:"从云端重新加载"}):null]}):null;return e.historyError?h.jsxs(h.Fragment,{children:[Z,h.jsxs("div",{className:"flex justify-center py-2 text-[12px] text-text-400","data-testid":"history-error",children:["历史未加载完(",e.historyError,");切走再切回可重试"]})]}):Z||(re&&oe.length===0?h.jsx("div",{className:"flex justify-center py-4","data-testid":"history-loading",children:h.jsx(Tn,{className:"w-4 h-4 text-text-400 animate-spin"})}):null)},[re,oe.length,e.historyError,e.historySyncError,e.reloadFromCloud,ni,e.codexHistory,e.historyHasMore,e.historyLoaded,e.historyLoadingOlder,e.loadOlderHistory,e.refreshHistory]),ca=e.meta,Gt=h.jsxs(h.Fragment,{children:[i.toolSessionId&&S.subagents?h.jsx(Nse,{api:s,cwd:i.cwd,toolSessionId:i.toolSessionId,toolKind:i.tool??"claude"}):null,tn&&S.rewind?h.jsx(Pse,{open:!0,onOpenChange:Z=>{Z||hn(null)},api:s,sessionId:i.sessionId,userMessageId:tn,lines:oe,procAlive:ke,onNoChanges:Z=>{Ge(we=>{if(we.has(Z))return we;const De=new Set(we);return De.add(Z),De})}}):null,ee?h.jsx(Yue,{onConfirm:Oe,onCancel:()=>be(!1)}):null]}),Zl={kind:"session",sessionId:i.sessionId},gd=g.useCallback(async Z=>{if(s)try{await _C(s,F,i.sessionId,Z)}catch(we){const De=we.message;$e("chat-panel","open-in-tab failed",{err:De}),z("err",`Open in tab 失败:${De}`)}},[s,F,i.sessionId,z]),[jt,$t]=g.useState(!1),[Wn,vr]=g.useState(null),Mi=g.useCallback(Z=>{if(r){r(Z);return}vr(Z),$t(!0)},[r]),zm=g.useCallback(Z=>{if(!s)return;const we=async()=>{try{await s.attachmentGroupAdd(i.sessionId,Z)}catch(ct){$e("chat-panel","file-link groupAdd skipped",{err:ct.message})}},De=ct=>{const Br=ct.message;$e("chat-panel","file-link open failed",{err:Br}),z("err",`打开文件失败:${Br}`)};if(Nm(Z)){we().then(()=>Mi(Z),De);return}_C(s,F,i.sessionId,Z,60,we).catch(De)},[s,F,i.sessionId,Mi,z]),vd=g.useCallback(async Z=>{if(!s)throw new Error("daemon api not ready");const we=await G_(s,F,i.sessionId,Z,60),De=await fetch(we);if(!De.ok)throw new Error(`fetch ${De.status} ${De.statusText}`);return await De.text()},[s,F,i.sessionId]),co=g.useCallback(async(Z,we)=>{if(s)try{const{url:De}=await s.attachmentSignUrl({sessionId:i.sessionId,relPath:Z,...we?{view:we}:{}}),ct=await dY(De);z(ct?"ok":"err",ct?"分享链接已复制到剪贴板":"复制失败:请手动复制")}catch(De){const ct=De.message;$e("chat-panel","share-file failed",{err:ct}),z("err",`生成分享链接失败:${ct}`)}},[s,i.sessionId,z]),uo=g.useCallback(()=>E(null),[]),Fm=N==="files"&&P&&s?{title:"Edited Files",onBack:uo,content:h.jsx(Xle,{api:s,scope:Zl,sessionId:i.sessionId,onShareFile:co,onOpenInTab:gd,onPreviewMarkdown:Mi})}:N==="cron"?{title:`定时任务${Re.length?` (${Re.length})`:""}`,onBack:uo,content:h.jsx("div",{className:"p-3",children:h.jsx(jse,{jobs:Re})})}:N==="persona"&&R&&s&&i.ownerPersonaId?{title:`Persona · ${M??""}`,onBack:uo,content:h.jsx(hue,{personaId:i.ownerPersonaId,open:!0,onClose:uo,api:s,embedded:!0,...m?{viewerRole:m}:{}},i.ownerPersonaId)}:null,xd=Ue==="full"?h.jsx(Cse,{session:i,meta:ca,...$&&O.binding?{liveGitBranch:((xr=O.workspace)==null?void 0:xr.actualBranch)??null}:o!==void 0?{liveGitBranch:o}:{},...a!==void 0?{liveWorktreeRoot:a}:{},...R?{personaName:M}:{},...R?{onOpenPersona:()=>E("persona")}:{},...P?{onOpenFiles:()=>E("files")}:{},cronActiveCount:Re.length,onCronClick:()=>E("cron"),onForceStop:()=>be(!0),...Wc(i.tool)&&e.reloadFromCloud?{onReloadFromCloud:e.reloadFromCloud,reloadFromCloudDisabled:ni}:{},...m?{viewerRole:m}:{},...b!=null&&b.toolSessionIdLabel?{toolSessionIdLabel:b.toolSessionIdLabel}:{},drill:Fm,...nn?{onCollapse:nn}:{},...fn?{title:fn.title,leadingEntries:fn.leadingEntries}:{}}):null;return h.jsxs(h.Fragment,{children:[$&&bn?Oo.createPortal(h.jsx(zue,{controller:O,disabled:ca.streamInProgress}),bn):null,At&&xd?Oo.createPortal(xd,At):null,h.jsx(Gue,{headerMeta:ca,workspaceInput:$?h.jsx($ue,{controller:O,disabled:ca.streamInProgress}):void 0,workspaceInputDisabled:$&&O.busy,connState:e.connState,...a!==void 0?{liveWorktreeRoot:a}:{},...d?{onOpenConfig:d}:{},variant:Ue,...x||$?{hideHeader:!0}:{},..._?{flatProcess:_}:{},...Ue==="quickask"?{ephemeral:i.ephemeral!==!1,onPromote:()=>void(v==null?void 0:v(i.sessionId))}:{},lines:oe,pendingPermissions:Ie,procAlive:ke,rewindableUserMessageIds:fe,onPermissionRespond:Xl,onPermissionInterrupt:rt,onRewind:S.rewind?W:void 0,...f&&S.fork?{onFork:f}:{},...Wc(i.tool)?{}:n&&S.fork?{onQuickAsk:n}:p&&S.fork?{onQuickAsk:p}:{},topSlot:md,codexHistory:e.codexHistory,realtimeQuestionAnswers:aa,onSubmitQuestion:la,onCancelQuestion:Yl,liveQuestionToolUseIds:ds,api:s,cwd:i.cwd,...i.tool?{tool:i.tool}:{},...l?{cloudVolume:l}:{},sessionKey:i.sessionId,onSend:e.sendText,queued:e.queued,onDequeue:e.dequeue,awaitingUser:Ie.length>0||Object.values(B).some(Z=>!Z.submittedAnswers),onAbort:rt,...c?{onNewSession:c}:{},onClearSession:hs,...w?{configSlot:w}:{},chatRootRef:Se,chatBodyRef:st,drawers:Gt,xtermSlot:I==="tui"&&ke&&S.tui?h.jsx(Yle,{sessionId:i.sessionId,client:F},i.sessionId):null,fileSharingScope:Zl,...s?{onShareFile:co}:{},...s?{onOpenInTab:gd}:{},...s?{onPreviewMarkdown:Mi}:{},...s?{onOpenFilePath:zm}:{},dispatchOrigin:D}),s?h.jsx(xue,{open:jt,onOpenChange:$t,relPath:Wn,loadMarkdown:vd,onShare:Wn?()=>void co(Wn,"md-rendered"):void 0}):null,C?h.jsx("div",{"data-testid":"share-toast",role:"status","aria-live":"polite",className:C.kind==="ok"?"fixed left-1/2 top-4 z-50 -translate-x-1/2 rounded-md border border-emerald-500/40 bg-emerald-500/10 px-3 py-2 text-[12px] text-emerald-700 shadow-md dark:text-emerald-300":"fixed left-1/2 top-4 z-50 -translate-x-1/2 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-[12px] text-destructive shadow-md",children:C.text}):null]})}function Yue({onConfirm:e,onCancel:t}){return h.jsx("div",{role:"dialog","aria-modal":"true","data-testid":"force-stop-confirm",className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40",onClick:t,children:h.jsxs("div",{className:"max-w-sm w-[92%] rounded-lg border border-red-400/40 bg-bg-0 p-4 shadow-xl",onClick:n=>n.stopPropagation(),children:[h.jsxs("div",{className:"flex items-start gap-2 mb-3",children:[h.jsx(Wf,{className:"w-5 h-5 text-red-500 shrink-0 mt-0.5"}),h.jsx("div",{className:"text-[14px] text-text-100",children:"强制停止会话进程?会丢失 initialize / 预热缓存,下一次发送需要重新 spawn。"})]}),h.jsxs("div",{className:"flex justify-end gap-2",children:[h.jsx("button",{type:"button",onClick:t,className:"h-8 px-3 rounded-md text-[12px] text-text-300 hover:bg-text-100/5 cursor-pointer",children:"取消"}),h.jsx("button",{type:"button","data-testid":"force-stop-confirm-ok",onClick:e,className:"h-8 px-3 rounded-md bg-red-500 text-white text-[12px] font-medium hover:bg-red-600 cursor-pointer",children:"强制停止"})]})]})})}function Xue(e){return e.split("/").pop()||e}function Zue({state:e,api:t,onSwitchTab:n,onCloseQuickAsk:r,onCloseMd:i,loadMarkdown:s,quickAskSession:o,onPromoteQuickAsk:a}){if(!tR(e))return null;const l=[];e.quickAsk&&l.push({id:"quick-ask",label:"问一下",title:"问一下",icon:h.jsx(mx,{className:"w-3.5 h-3.5"})});for(const c of e.mds)l.push({id:{kind:"md",relPath:c},label:Xue(c),title:c,icon:h.jsx(Ci,{className:"w-3.5 h-3.5"})});return h.jsxs("div",{className:"flex flex-col h-full bg-bg-50/60 border-l border-border-strong",children:[h.jsx(Pu,{delayDuration:200,skipDelayDuration:100,children:h.jsx("div",{className:["flex items-stretch h-9 border-b border-text-100/10 shrink-0 overflow-x-auto","[scrollbar-width:none] [-ms-overflow-style:none]","[&::-webkit-scrollbar]:hidden"].join(" "),role:"tablist",children:l.map(c=>{const u=wY(e.active,c.id),d=c.id==="quick-ask"?"quick-ask":`md:${c.id.relPath}`;return h.jsxs(nd,{children:[h.jsx(rd,{asChild:!0,children:h.jsxs("div",{role:"tab","aria-selected":u,"data-tab-title":c.title,onClick:()=>n(c.id),className:["group relative flex items-center gap-2 px-3 h-full cursor-pointer select-none","text-[12px] max-w-[180px] shrink-0 transition-colors duration-100",u?"text-text-100":"text-text-400 hover:text-text-100 hover:bg-text-100/[0.04]"].join(" "),children:[c.icon,h.jsx("span",{className:"truncate",children:c.label}),h.jsx("button",{type:"button","aria-label":`关闭 ${c.label}`,className:["ml-1 rounded p-0.5 shrink-0 transition-opacity","hover:bg-text-100/10",u?"opacity-70 hover:opacity-100":"opacity-0 group-hover:opacity-70"].join(" "),onClick:f=>{f.stopPropagation(),c.id==="quick-ask"?r():i(c.id.relPath)},children:h.jsx(Qr,{className:"w-3 h-3"})}),u?h.jsx("span",{"aria-hidden":"true",className:"absolute left-2 right-2 -bottom-px h-[2px] rounded-full bg-accent"}):null]})}),h.jsx(Ul,{side:"bottom",align:"start",className:"max-w-sm break-all",children:c.title})]},d)})})}),h.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden relative",children:[e.quickAsk&&o?h.jsx("div",{className:"absolute inset-0",style:{display:e.active==="quick-ask"?"block":"none"},children:h.jsx(Kue,{session:o,api:t,...a?{onPromoteQuickAsk:a}:{}})}):null,e.mds.map(c=>{const u=e.active!==null&&e.active!=="quick-ask"&&e.active.relPath===c;return h.jsx("div",{className:"absolute inset-0",style:{display:u?"block":"none"},children:h.jsx(dj,{relPath:c,loadMarkdown:s,showTitleBar:!1})},`md-body:${c}`)})]})]})}function Que(e){const t=e instanceof Error?e.message:String(e);return t.length>200?`${t.slice(0,200)}…`:t}function Jue({state:e,extras:t}){const{api:n,session:r}=t,i=Ni(),[s,o]=g.useState(mY()),[a,l]=g.useState(null),c=r.ownerPersonaId!==MT,u=g.useRef(s);u.current=s;const d=g.useRef(!1),f=g.useCallback(async E=>{const j=u.current.quickAsk;l(null);let P;try{P=await aY(n,r,E)}catch(L){$e("quick-ask","fork failed",L),d.current||l(Que(L));return}if(!P){d.current||l("这条会话还没准备好(没有可派生的对话记录),稍后再试");return}if(d.current){n.sessionDelete(P.sessionId).catch(()=>{});return}ih(j)&&n.sessionDelete(j.sessionId).catch(()=>{}),o(L=>gY(L,{sessionId:P.sessionId}))},[n,r]),p=g.useCallback(async E=>{const j=u.current.quickAsk,P=(j==null?void 0:j.sessionId)===E;try{await lY(n,{sessionId:E,stillEphemeral:P&&ih(j)})&&o(M=>yY(M))}catch(L){$e("quick-ask","promote failed",L)}},[n]),m=g.useCallback(E=>{o(j=>vY(j,E))},[]),v=g.useCallback(E=>{o(j=>bY(j,E))},[]),w=g.useCallback(()=>{const E=u.current.quickAsk;ih(E)&&n.sessionDelete(E.sessionId).catch(()=>{}),o(j=>xY(j))},[n]),x=g.useCallback(E=>{o(j=>_Y(j,E))},[]);g.useEffect(()=>()=>{d.current=!0;const E=u.current.quickAsk;ih(E)&&n.sessionDelete(E.sessionId).catch(()=>{})},[]);const _=es("sessions")??[],b=s.quickAsk?_.find(E=>E.sessionId===s.quickAsk.sessionId)??{sessionId:s.quickAsk.sessionId,cwd:r.cwd,tool:r.tool}:null,S=g.useCallback(async E=>{const j=await G_(n,i,r.sessionId,E,60),P=await fetch(j);if(!P.ok)throw new Error(`fetch ${P.status} ${P.statusText}`);return P.text()},[n,i,r.sessionId]),C=h.jsx(Rj,{state:e,extras:t,onQuickAskInternal:f,onPreviewMdInternal:m}),{initialSize:k,setSize:N}=pY("chat-panel-right-slot-width",480);return h.jsxs(q_,{orientation:"horizontal",className:"flex-1 flex min-w-0 min-h-0",children:[h.jsx(Qf,{id:"chat",minSize:"400px",children:h.jsxs("div",{className:"relative flex flex-col min-w-0 min-h-0 h-full",children:[C,a?h.jsxs("div",{"data-testid":"quick-ask-error",className:"absolute bottom-24 left-1/2 z-10 -translate-x-1/2 max-w-[90%] rounded-md border border-border bg-bg-200 px-3 py-2 text-[12px] text-text-300 shadow-lg",children:[h.jsxs("span",{className:"mr-2",children:["问一下没能打开:",a]}),h.jsx("button",{type:"button","aria-label":"关闭提示",onClick:()=>l(null),className:"text-text-400 hover:text-text-200 cursor-pointer",children:"✕"})]}):null]})}),tR(s)?h.jsxs(h.Fragment,{children:[h.jsx(YP,{className:"w-1 bg-text-100/10 hover:bg-text-100/25 transition-colors cursor-col-resize"}),h.jsx(Qf,{id:"right-slot",defaultSize:`${k}px`,minSize:"360px",maxSize:"800px",onResize:E=>N(E.inPixels),children:h.jsx(Zue,{state:s,api:n,onSwitchTab:v,onCloseQuickAsk:w,onCloseMd:x,loadMarkdown:S,quickAskSession:b,...c?{onPromoteQuickAsk:p}:{}})})]}):null]})}function ede({extras:e}){const t=eR(e.session.sessionId,e.focused);return h.jsx(Jue,{state:t,extras:e})}function tde(e,t,n){var s;const r=n.find(o=>o.name==="effort"),i=e?t.find(o=>o.id===e):void 0;if(i!=null&&i.efforts&&i.efforts.length>0){const o=(s=r==null?void 0:r.options)==null?void 0:s.find(l=>l.value==="none");return{options:o?[o,...i.efforts.filter(l=>l.value!=="none")]:i.efforts,defaultValue:i.defaultEffort??""}}return{options:(r==null?void 0:r.options)??[],defaultValue:typeof(r==null?void 0:r.default)=="string"?r.default:""}}function nde(e,t,n){var l;if(!t)return((l=(e??[]).find(c=>c.id===""))==null?void 0:l.label)??"未指定";const r=t.toLowerCase(),i=[["opus","Opus"],["fable","Fable"],["sonnet","Sonnet"],["haiku","Haiku"]];for(const[c,u]of i){if(!r.includes(c))continue;const d=r.match(new RegExp(`${c}-(\\d+)(?:-(\\d+))?`));return d?d[2]?`${u} ${d[1]}.${d[2]}`:`${u} ${d[1]}`:u}const s=e??[],o=s.find(c=>c.id===t);if(o)return o.label;const a=s.find(c=>c.id&&t.toLowerCase().includes(c.id.toLowerCase()));return a?a.label:t}function rde(e,t){var m,v,w,x;const{models:n,modes:r,configSchema:i}=t,s=e.resolvedModel??e.model,o=tde(s,n,i),a=o.options,l=a.some(_=>_.value===e.effort)?e.effort:o.defaultValue,c=e.effort===""&&e.resolvedEffort?((m=a.find(_=>_.value===e.resolvedEffort))==null?void 0:m.label)??e.resolvedEffort:((v=a.find(_=>_.value===l))==null?void 0:v.label)??null,u=((w=i.find(_=>_.name==="permissionMode"))==null?void 0:w.default)??"",d=r.some(_=>_.id===e.permissionMode)?e.permissionMode:u,p=d===u?null:((x=r.find(_=>_.id===d))==null?void 0:x.label)??null;return{modelLabel:nde(n,s),effortOptions:a,effortValue:l,effortLabel:c,modeValue:d,modeLabel:p,modeTone:p===null?null:d==="bypassPermissions"?"danger":"info"}}function Mj(e){let t;return e.map(n=>{const r=n.group&&n.group!==t?n.group:null;return n.group&&(t=n.group),{...n,groupHeading:r}})}function ide(e){return e.map(t=>({value:t.id,label:t.label,...t.description?{description:t.description}:{},...t.group?{group:t.group}:{}}))}function sde({testid:e,list:t,options:n,current:r,onSelect:i}){if(t.loading)return h.jsx(Ir,{disabled:!0,"data-testid":`${e}-loading`,className:"text-[12px] text-text-400",children:"正在读取最新模型…"});if(t.error)return h.jsxs(h.Fragment,{children:[h.jsx("div",{"data-testid":`${e}-error`,className:"px-2 py-1.5 text-[11px] text-warning",children:t.error}),h.jsx(Ir,{"data-testid":`${e}-retry`,className:"text-[12px]",onSelect:o=>{o.preventDefault(),t.load()},children:"重试"})]});const s=n??ide(t.models);return s.length===0?h.jsx(Ir,{disabled:!0,"data-testid":`${e}-empty`,className:"text-[12px] text-text-400",children:"没有可选模型"}):h.jsx(h.Fragment,{children:Mj(s).map((o,a)=>{const l=o.value===r;return h.jsxs(Ye.Fragment,{children:[o.groupHeading?h.jsxs(h.Fragment,{children:[a>0?h.jsx(vm,{}):null,h.jsx(j_,{"data-testid":`${e}-group`,children:o.groupHeading})]}):null,h.jsxs(Ir,{"data-testid":`${e}-option-${o.value||"default"}`,onSelect:()=>i(o.value),className:"items-start gap-2",children:[h.jsxs("span",{className:"min-w-0 flex-1",children:[h.jsx("span",{className:ie("block text-[12px]",l?"font-medium text-text-100":"text-text-300"),children:o.label}),o.description?h.jsx("span",{className:"mt-0.5 block text-[11px] text-text-400",children:o.description}):null]}),l?h.jsx(no,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-accent"}):null]})]},o.value||"default")})})}function ode(e,t={}){return{models:e,loading:!1,error:null,load:()=>{},...t}}const ade=e=>e instanceof Error?e.message:String(e);function lde(e,t){const[n,r]=g.useState({key:e,loading:!1,error:null,data:t}),i=g.useRef(0),s=g.useCallback((a,l)=>{const c=++i.current;r(u=>({key:e,loading:!0,error:null,data:u.key===e?u.data:t})),a().then(u=>{i.current===c&&(l==null||l(u),r({key:e,loading:!1,error:null,data:u}))},u=>{i.current===c&&r(d=>({key:e,loading:!1,error:ade(u),data:d.key===e?d.data:t}))})},[e]);return{...n.key===e?n:{loading:!1,error:null,data:t},run:s}}const cde=[];function ude(e){const t=Ni(),n=g.useMemo(()=>new em(t),[t]),r=os(),{capabilities:i}=Am(e),s=lde(e??"",null),{run:o}=s,a=g.useCallback(()=>{e&&o(()=>n.capabilitiesGet(e,{refresh:!0}),l=>{l&&r.setData(`capabilities/${e}`,()=>l)})},[n,r,e,o]);return{models:(i==null?void 0:i.models)??cde,loading:s.loading,error:s.error,load:a}}function dde({models:e,modelList:t,modes:n=[],configSchema:r=[],model:i,resolvedModel:s,resolvedEffort:o,effort:a,permissionMode:l,onPatch:c}){var w;const u=t??ode(e??[]),d=u.models,f=rde({model:i,resolvedModel:s,resolvedEffort:o,effort:a,permissionMode:l},{models:d,modes:n,configSchema:r}),p=s??i,m=d.map(x=>{const _=x.id===""&&s?`${x.description?`${x.description};`:""}当前:${s}`:x.description;return{value:x.id,label:x.label,..._?{description:_}:{},...x.group?{group:x.group}:{}}}),v=n.map(x=>({value:x.id,label:x.label,...x.description?{description:x.description}:{}}));return h.jsxs(P_,{children:[h.jsx(R_,{asChild:!0,children:h.jsxs("button",{type:"button","data-testid":"session-config-chip",title:"Model / reasoning effort / permission mode",className:"inline-flex items-center gap-1 h-7 px-2.5 rounded-full text-[11px] text-text-400 transition-colors outline-none cursor-pointer hover:bg-text-100/5 hover:text-text-200 data-[state=open]:bg-text-100/5",children:[h.jsx("span",{className:"truncate max-w-[120px]","data-testid":"session-config-chip-model",children:p||f.modelLabel}),f.effortLabel?h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"text-text-500",children:"·"}),h.jsx("span",{className:"truncate max-w-[80px]","data-testid":"session-config-chip-effort",children:f.effortLabel})]}):null,f.modeLabel?h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"text-text-500",children:"·"}),h.jsx("span",{"data-testid":"session-config-chip-mode","data-tone":f.modeTone,className:ie("font-semibold",f.modeTone==="danger"?"text-red-400":"text-blue-400"),children:f.modeLabel})]}):null]})}),h.jsxs(gm,{side:"top",align:"end",className:"w-[230px]","data-testid":"session-config-menu",children:[h.jsx(hde,{list:u,current:i,currentLabel:f.modelLabel,options:m,onSelect:x=>c({model:x})}),h.jsx(OE,{testid:"session-config-effort",label:"Reasoning effort",current:f.effortValue,currentLabel:f.effortLabel??"—",options:f.effortOptions,onSelect:x=>c({effort:x})}),v.length>0?h.jsx(OE,{testid:"session-config-mode",label:"Permission mode",current:f.modeValue,currentLabel:((w=n.find(x=>x.id===f.modeValue))==null?void 0:w.label)??"—",currentTone:f.modeTone,options:v,onSelect:x=>c({permissionMode:x})}):null]})]})}function Aj({label:e,currentLabel:t,currentTone:n}){return h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"flex-1 text-text-200",children:e}),h.jsx("span",{className:ie("truncate max-w-[100px]",n==="danger"?"text-red-400 font-semibold":n==="info"?"text-blue-400 font-semibold":"text-text-400"),children:t}),h.jsx(Fn,{className:"w-3.5 h-3.5 shrink-0 text-text-500"})]})}function hde({list:e,current:t,currentLabel:n,options:r,onSelect:i}){const[s,o]=g.useState(!1),a=l=>{l&&!s&&e.load(),o(l)};return h.jsxs(_P,{open:s,onOpenChange:a,children:[h.jsx(M_,{"data-testid":"session-config-model",className:"gap-2 text-[12px]",children:h.jsx(Aj,{label:"Model",currentLabel:n})}),h.jsx(A_,{className:"w-[220px] max-h-[320px] overflow-y-auto",children:h.jsx(sde,{testid:"session-config-model",list:e,options:r,current:t,onSelect:i})})]})}function OE({testid:e,label:t,current:n,currentLabel:r,currentTone:i,options:s,onSelect:o}){const a=s.length===0;return h.jsxs(_P,{children:[h.jsx(M_,{"data-testid":e,disabled:a,className:"gap-2 text-[12px]",children:h.jsx(Aj,{label:t,currentLabel:r,currentTone:i??null})}),h.jsx(A_,{className:"w-[220px] max-h-[320px] overflow-y-auto",children:Mj(s).map((l,c)=>{const u=l.value===n;return h.jsxs(Ye.Fragment,{children:[l.groupHeading?h.jsxs(h.Fragment,{children:[c>0?h.jsx(vm,{}):null,h.jsx(j_,{"data-testid":`${e}-group`,children:l.groupHeading})]}):null,h.jsxs(Ir,{"data-testid":`${e}-option-${l.value||"default"}`,onSelect:()=>o(l.value),className:"items-start gap-2",children:[h.jsxs("span",{className:"flex-1 min-w-0",children:[h.jsx("span",{className:ie("block text-[12px]",u?"text-text-100 font-medium":"text-text-300"),children:l.label}),l.description?h.jsx("span",{className:"block text-[11px] text-text-400 mt-0.5",children:l.description}):null]}),u?h.jsx(no,{className:"w-3.5 h-3.5 shrink-0 text-accent mt-0.5"}):null]})]},l.value||"default")})})]})}Ye.forwardRef(function({icon:t,prefixNode:n,value:r,placeholder:i,selected:s,disabled:o,onOpen:a,testid:l,...c},u){return h.jsxs("button",{ref:u,type:"button",onClick:a,disabled:o,"data-testid":l,className:"inline-flex items-center gap-1.5 rounded-full border border-bg-300 px-3 py-1.5 text-[12px] transition-colors cursor-pointer "+(s?"bg-text-100/5 text-text-100 ":"text-text-300 hover:bg-text-100/5 ")+(o?"opacity-50 cursor-not-allowed ":""),...c,children:[n??(t?h.jsx(t,{className:"w-3.5 h-3.5"}):null),h.jsx("span",{className:"truncate max-w-[180px]",children:r??i})]})});const Qh=[{id:"claude",label:"Claude Code"},{id:"codex",label:"Codex"},{id:"pi",label:"pi"}];function fde(e){return Qh.some(t=>t.id===e)?e:"claude"}function pde({tool:e,onChange:t}){const n=fde(e),r=Qh.find(i=>i.id===n)??Qh[0];return h.jsxs(P_,{children:[h.jsx(R_,{asChild:!0,children:h.jsx("button",{type:"button","data-testid":"session-engine-chip",title:"Engine(发出第一条消息后锁定)",className:"inline-flex items-center h-7 px-2.5 rounded-full text-[11px] text-text-400 transition-colors outline-none cursor-pointer hover:bg-text-100/5 hover:text-text-200 data-[state=open]:bg-text-100/5",children:r.label})}),h.jsx(gm,{side:"top",align:"end",className:"w-[180px]","data-testid":"session-engine-menu",children:Qh.map(i=>h.jsxs(Ir,{"data-testid":`session-engine-option-${i.id}`,onSelect:()=>{i.id!==n&&t(i.id)},children:[h.jsx("span",{className:"flex-1",children:i.label}),i.id===n?h.jsx(no,{className:"w-3.5 h-3.5 text-text-300"}):null]},i.id))})]})}function mde(e,t,n=0){const[r,i]=g.useState(null),[s,o]=g.useState(!1),a=g.useCallback(async()=>{if(!t){i(null);return}o(!0);try{const l=await e.getGitBranch(t);i(l.branch??null)}catch{i(null)}finally{o(!1)}},[e,t]);return g.useEffect(()=>{a()},[a,n]),{branch:r,loading:s,refresh:()=>void a()}}function gde(e,t,n=0){const[r,i]=g.useState(null),[s,o]=g.useState(!1),a=g.useCallback(async()=>{if(!t){i(null);return}o(!0);try{const l=await e.getGitRoot(t);i(l.gitRoot??null)}catch{i(null)}finally{o(!1)}},[e,t]);return g.useEffect(()=>{a()},[a,n]),{worktreeRoot:r,loading:s,refresh:()=>void a()}}const vde=5e3;function xde(e,t,n=0){const[r,i]=g.useState(null);return g.useEffect(()=>{if(!t){i(null);return}let s=!1;const o=async()=>{try{const l=await e.cloudVolumeGet();s||i(l.volume??null)}catch{s||i(null)}},a=n>0?setTimeout(()=>void o(),vde):null;return a||o(),()=>{s=!0,a&&clearTimeout(a)}},[e,t,n]),{volume:r}}const yde=90;function _de(e){return e.sizeBytes>0?Math.min(100,Math.max(0,Math.round(e.usedBytes/e.sizeBytes*100))):0}function BE(e){const t=e/1073741824;return t>=.1?`${t.toFixed(1)} GB`:`${Math.max(1,Math.round(e/1024**2))} MB`}function bde({volume:e}){if(!e)return null;const t=_de(e),n=t>=yde?"warn":"ok",r=new Date(e.measuredAt).toLocaleString(),i=n==="ok"?"上一次任务结束时量的。":"盘快满了:在会话里说「清理一下云盘」,persona 会分析工作区里哪些能删、列给你确认后清掉。";return h.jsxs("span",{"data-testid":"chat-header-cloud-volume","data-tone":n,title:`云盘已用 ${BE(e.usedBytes)} / ${BE(e.sizeBytes)}(${r})。${i}`,className:ie("ml-1.5 inline-flex items-center gap-1.5 px-1.5 py-0.5 rounded text-[11px] tabular-nums",n==="ok"&&"bg-text-100/10 text-text-400",n==="warn"&&"bg-warning-dim text-warning"),children:[h.jsx("span",{className:"relative inline-block w-8 h-1 rounded-full bg-current/20 overflow-hidden","aria-hidden":!0,children:h.jsx("span",{className:"absolute inset-y-0 left-0 rounded-full bg-current",style:{width:`${t}%`}})}),"云盘 ",t,"%"]})}function wde({api:e,session:t,focused:n,totalPanes:r,onFocus:i,onClose:s,onNewSession:o,onOpenConfig:a,onFork:l,onQuickAsk:c,className:u,viewerRole:d="owner",hideHeader:f}){const{capabilities:p}=Am(t.tool),m=ude(t.tool),[v,w]=g.useState(0),[x,_]=g.useState(n);Ye.useEffect(()=>{n&&_(!0)},[n]);const b=Wc(t.tool),S=b?void 0:t.cwd,{branch:C}=mde(e,S,v),{worktreeRoot:k}=gde(e,S,v),{volume:N}=xde(e,b,v),E=r>1,j=!b&&d==="owner"&&!t.toolSessionId,P=L=>{e.sessionUpdate(t.sessionId,L).catch(M=>{console.error("[session-config] session:update failed",t.sessionId,M)})};return h.jsxs("div",{className:`group/pane relative flex-1 ${u??"flex"} flex-row min-w-0 min-h-0 overflow-hidden ${E?`rounded-md border transition-colors ${n?"border-accent ring-1 ring-accent":"border-border"}`:""}`,onMouseDown:i,"data-testid":`session-pane-${t.sessionId}`,children:[h.jsx(q_,{orientation:"horizontal",className:"flex-1 flex min-w-0 min-h-0",children:h.jsx(Qf,{id:"chat",minSize:"400px",children:h.jsx("div",{className:"flex flex-col min-w-0 min-h-0 h-full",children:(n||x)&&h.jsx(Sde,{api:e,session:t,focused:n,liveGitBranch:C,liveWorktreeRoot:k,...b&&N?{cloudVolume:h.jsx(bde,{volume:N})}:{},onNewSession:o,onTurnEnd:()=>w(L=>L+1),onOpenConfig:a,onFork:l,onQuickAsk:c,viewerRole:d,hideHeader:f,configSlot:h.jsxs(h.Fragment,{children:[j?h.jsx(pde,{tool:t.tool,onChange:L=>P({tool:L})}):null,p?h.jsx(dde,{modelList:m,modes:p.permissionModes,configSchema:p.configSchema,model:t.model??"",...t.resolvedModel?{resolvedModel:t.resolvedModel}:{},...t.resolvedEffort?{resolvedEffort:t.resolvedEffort}:{},effort:t.effort??"",permissionMode:t.permissionMode??"",onPatch:P}):null]})})})})}),E&&h.jsx("button",{type:"button",onClick:L=>{L.stopPropagation(),s()},className:"absolute top-1.5 right-1.5 z-10 p-1 rounded-md bg-bg-100/80 backdrop-blur-sm border border-border opacity-0 group-hover/pane:opacity-100 transition-opacity text-text-400 hover:text-text-100 hover:bg-bg-200","aria-label":"close pane","data-testid":`session-pane-close-${t.sessionId}`,children:h.jsx(Qr,{className:"w-3.5 h-3.5"})})]})}function Sde({api:e,session:t,focused:n,liveGitBranch:r,liveWorktreeRoot:i,cloudVolume:s,onNewSession:o,onTurnEnd:a,onOpenConfig:l,onFork:c,onQuickAsk:u,viewerRole:d,configSlot:f,hideHeader:p}){return h.jsx(ede,{extras:{session:t,api:e,focused:n,...r!==void 0?{liveGitBranch:r}:{},...i!==void 0?{liveWorktreeRoot:i}:{},...s!==void 0?{cloudVolume:s}:{},onNewSession:o,onTurnEnd:a,onOpenConfig:l,...c?{onFork:m=>{c(m)}}:{},...u?{onQuickAsk:m=>{u(m)}}:{},...d?{viewerRole:d}:{},...f?{configSlot:f}:{},...p?{hideHeader:p}:{}}})}function kde({personas:e,sessions:t,api:n,selfPrincipalId:r,selectedPersonaId:i,selectedSessionId:s,selectedSession:o,onSelectPersona:a,onSelectSession:l,onCreateSession:c,onDeleteSession:u,onEditSession:d,onCloseSession:f}){return h.jsxs("div",{className:"flex h-screen min-h-0 bg-bg-50","data-testid":"guest-share-page",children:[h.jsx("aside",{className:"w-[280px] shrink-0 overflow-y-auto border-r border-border bg-bg-50",children:h.jsx(qK,{personas:e,sessions:t,activePersonaId:i,activeSessionId:s,onSelectPersona:a,onSelectSession:l,onCreateSession:c,onDeleteSession:u,onEditSession:d,showCopyResume:!1,treatSessionsAsRoots:!0,...r?{ownerPrincipalId:r}:{},isPersonaExpanded:()=>!0})}),h.jsx("main",{className:"flex-1 min-w-0 min-h-0 flex",children:o?h.jsx(wde,{api:n,session:o,focused:!0,totalPanes:1,onFocus:()=>{},onClose:f,onNewSession:()=>{},onOpenConfig:()=>{},viewerRole:"guest"}):h.jsx("div",{className:"flex flex-1 items-center justify-center p-6 text-xs text-text-400","data-testid":"guest-share-empty",children:"选择左侧 persona 开始对话"})})]})}function Cde(){const e=Ni(),t=g.useMemo(()=>new em(e),[e]),n=Kz(e),{sessions:r,refresh:i}=Gz(n),{personas:s}=o4(),o=e7(),a=g.useMemo(()=>{const S=window.location.pathname.match(/^\/s\/([^/]+)/);return S?decodeURIComponent(S[1]):null},[]),l=g.useMemo(()=>r.filter(S=>!S.ephemeral&&S.larkChatId==null),[r]),c=g.useMemo(()=>a?s.filter(S=>S.personaId===a):s,[s,a]),[u,d]=g.useState(null),[f,p]=g.useState(null),[m,v]=g.useState(null);g.useEffect(()=>{let S=!1;return e.request("whoami",{}).then(C=>{S||d(C.capability.id)}).catch(()=>{}),()=>{S=!0}},[e]),g.useEffect(()=>{a&&p(a)},[a]);const w=g.useCallback(async(S,C)=>{const k=await t.sessionCreate({ownerPersonaId:S,...C.trim()?{label:C.trim()}:{}});await i(),p(S),v(k.sessionId)},[t,i]),x=g.useCallback(async S=>{await t.sessionDelete(S),await i(),v(C=>C===S?null:C)},[t,i]),_=g.useCallback(async(S,C)=>{await t.sessionUpdate(S,{label:C.label}),await i()},[t,i]),b=g.useMemo(()=>l.find(S=>S.sessionId===m)??null,[l,m]);return h.jsx(t_.Provider,{value:o,children:h.jsx(kde,{personas:c,sessions:l,api:t,selfPrincipalId:u,selectedPersonaId:f,selectedSessionId:m,selectedSession:b,onSelectPersona:p,onSelectSession:v,onCreateSession:(S,C)=>void w(S,C),onDeleteSession:S=>void x(S),onEditSession:(S,C)=>void _(S,C),onCloseSession:()=>v(null)})})}const $E="https://app.ttcadvisory.com";function Ede({onAuthed:e}){const[t,n]=g.useState(!1),[r,i]=g.useState(null),s=g.useRef(null);g.useEffect(()=>()=>{s.current&&window.removeEventListener("message",s.current)},[]);const o=g.useCallback(()=>{s.current&&(window.removeEventListener("message",s.current),s.current=null),n(!0),i(null);const a=window.location.origin,l=`${$E}/auth/authorize?callback_url=${encodeURIComponent(a)}&auto=1`,c=async d=>{if(d.origin!==$E)return;const f=d.data;if((f==null?void 0:f.type)==="AUTH_CANCEL"){u(),n(!1);return}if(!((f==null?void 0:f.type)!=="AUTH_SUCCESS"||!f.token)){u();try{const p=await fetch(`${window.location.origin}/share/exchange`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({ttcToken:f.token})});if(!p.ok){const v=await p.json().catch(()=>({}));throw new Error(v.code??`exchange failed (${p.status})`)}const m=await p.json();if(!m.visitorToken)throw new Error("no visitorToken in response");e(m.visitorToken)}catch(p){i(p instanceof Error?p.message:String(p)),n(!1)}}},u=()=>{window.removeEventListener("message",c),s.current=null};s.current=d=>void c(d),window.addEventListener("message",s.current),window.open(l,"ttc-login","width=480,height=640")},[e]);return h.jsx("div",{className:"flex min-h-screen items-center justify-center bg-bg-50 p-6 font-sans text-text-100","data-testid":"guest-login",children:h.jsxs("div",{className:"flex w-full max-w-xs flex-col gap-3 rounded-lg border border-border bg-bg-100 px-5 py-6",children:[h.jsx("h1",{className:"text-base font-semibold",children:"登录后进入分享"}),h.jsx("p",{className:"text-[11px] leading-snug text-text-400",children:"使用飞书账号登录,即可在浏览器里与分享给你的 persona 交互,无需安装。"}),r?h.jsxs("p",{className:"text-[11px] leading-snug text-error","data-testid":"guest-login-error",children:["登录失败:",r]}):null,h.jsx("button",{type:"button",disabled:t,onClick:()=>o(),"data-testid":"guest-login-button",className:"w-full rounded border border-border bg-bg-50 px-2 py-1.5 text-xs text-text-200 transition-colors hover:bg-text-100/5 hover:text-text-100 disabled:opacity-50",children:t?"请在弹窗中完成授权…":"飞书登录"})]})})}const R1="clawd-visitor:token";function Ide(e,t){const r=`${e.protocol==="https:"?"wss:":"ws:"}//${e.host}`;return t!=null&&t.devPath?`${r}${t.devPath}`:r}function Nde(){return{async getUrl(e){const t=localStorage.getItem(R1);if(!t)throw new Error("NO_VISITOR_TOKEN");const n=Ide(window.location,{});return await XT(e).upsert({id:"guest",name:"访客",mode:"remote",url:n,token:t}),{url:n}}}}function Tde(e){const t=n=>{document.documentElement.classList.toggle("dark",n==="dark")};return t(e.theme.mode),e.onThemeChange(n=>t(n.mode))}function Pde(){const e=Ni(),t=g.useMemo(()=>Vz(e),[e]);return h.jsx(Iz,{cache:t.cache,children:h.jsx(Pz,{children:h.jsx(Cde,{})})})}function Rde({host:e}){const[t]=g.useState(()=>localStorage.getItem(R1)),[n,r]=g.useState(!1),[i,s]=g.useState(null);return g.useEffect(()=>Tde(e),[e]),g.useEffect(()=>{if(!t)return;let o=!1;return Nde().getUrl(e).then(()=>{o||r(!0)}).catch(a=>{o||s(a instanceof Error?a.message:String(a))}),()=>{o=!0}},[e,t]),t?h.jsx(Jw,{host:e,children:h.jsx(MS,{children:i?h.jsxs("div",{className:"flex min-h-screen items-center justify-center bg-bg-50 p-6 text-center text-xs text-error","data-testid":"guest-share-connect-error",children:["连接失败:",i]}):n?h.jsx(kz,{host:e,children:h.jsx(Pde,{})}):h.jsx("div",{className:"flex min-h-screen items-center justify-center bg-bg-50 p-6 text-xs text-text-400",children:"正在连接…"})})}):h.jsx(Jw,{host:e,children:h.jsx(MS,{children:h.jsx(Ede,{onAuthed:o=>{localStorage.setItem(R1,o),window.location.reload()}})})})}function Mde({filePath:e,oldString:t,newString:n,content:r}){const i=g.useMemo(()=>r!=null?r.split(/\r?\n/).map(s=>({type:"add",text:s})):Ade(t??"",n??""),[t,n,r]);return h.jsxs("div",{"data-testid":"inline-diff",className:"min-w-0 max-w-full rounded-lg border border-bg-300/60 bg-bg-50 overflow-hidden text-[12px] font-mono",children:[h.jsx("div",{className:"flex min-w-0 items-center gap-2 px-3 py-1.5 border-b border-bg-300/40 bg-bg-100/30",children:h.jsx("span",{className:"min-w-0 text-text-400 truncate",title:e,children:e})}),h.jsx("div",{className:"max-h-[320px] max-w-full overflow-auto",children:i.map((s,o)=>h.jsxs("div",{"data-testid":`diff-line-${s.type}`,className:ie("flex min-w-max gap-2 px-3 py-0.5 whitespace-pre",s.type==="add"?"bg-success/10 text-success":s.type==="remove"?"bg-error/10 text-error":"text-text-300"),children:[h.jsx("span",{className:"w-3 shrink-0 select-none opacity-60",children:s.type==="add"?"+":s.type==="remove"?"-":" "}),h.jsx("span",{className:"flex-1",children:s.text||" "})]},o))})]})}function Ade(e,t){const n=e.split(/\r?\n/),r=t.split(/\r?\n/),i=n.length,s=r.length,o=Array.from({length:i+1},()=>new Array(s+1).fill(0));for(let u=i-1;u>=0;u--)for(let d=s-1;d>=0;d--)o[u][d]=n[u]===r[d]?o[u+1][d+1]+1:Math.max(o[u+1][d],o[u][d+1]);const a=[];let l=0,c=0;for(;l<i&&c<s;)n[l]===r[c]?(a.push({type:"equal",text:n[l]}),l++,c++):o[l+1][c]>=o[l][c+1]?(a.push({type:"remove",text:n[l]}),l++):(a.push({type:"add",text:r[c]}),c++);for(;l<i;)a.push({type:"remove",text:n[l++]});for(;c<s;)a.push({type:"add",text:r[c++]});return a}function jde({items:e}){return e.length===0?null:h.jsxs("div",{"data-testid":"todo-checklist",className:"rounded-lg border border-bg-300/60 bg-bg-50 px-3 py-2 text-[13px]",children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-1.5",children:"Todos"}),h.jsx("ul",{className:"flex flex-col gap-1",children:e.map((t,n)=>{const r=t.status==="in_progress"&&t.activeForm||t.content;return h.jsxs("li",{"data-testid":`todo-item-${t.status}`,className:"flex items-start gap-2",children:[h.jsx(Lde,{status:t.status}),h.jsx("span",{className:ie("flex-1 leading-snug",t.status==="completed"?"text-text-400 line-through":t.status==="in_progress"?"text-text-100 font-medium":"text-text-200"),children:r})]},n)})})]})}function Lde({status:e}){return e==="completed"?h.jsx(n_,{className:"w-3.5 h-3.5 text-success mt-0.5 shrink-0"}):e==="in_progress"?h.jsx(Tn,{className:"w-3.5 h-3.5 text-warning mt-0.5 shrink-0 animate-spin"}):h.jsx(M7,{className:"w-3.5 h-3.5 text-text-400 mt-0.5 shrink-0"})}function Dde(e){const t=e??{};return Array.isArray(t.todos)?t.todos.map(n=>{if(!n||typeof n!="object")return null;const r=n,i=typeof r.content=="string"?r.content:"",s=r.status==="pending"||r.status==="in_progress"||r.status==="completed"?r.status:"pending",o=typeof r.activeForm=="string"?r.activeForm:void 0;return{content:i,status:s,activeForm:o}}).filter(n=>n!==null):[]}function Ode({description:e,prompt:t,subagentType:n}){return h.jsxs("div",{"data-testid":"task-checklist",className:"rounded-lg border border-bg-300/60 bg-bg-50 px-3 py-2 text-[13px]",children:[h.jsxs("div",{className:"flex items-center gap-2 text-text-200 font-medium",children:[h.jsx(tm,{className:"w-3.5 h-3.5 text-accent shrink-0"}),h.jsx("span",{className:"truncate",children:e||"subagent task"}),n?h.jsx("span",{className:"shrink-0 px-1.5 py-0.5 rounded-md text-[10px] font-mono bg-accent/10 text-accent",children:n}):null]}),t?h.jsx("div",{className:"mt-1 text-[12px] text-text-400 leading-snug line-clamp-3",children:t}):null]})}function Bde(e){const t=e??{};return{description:typeof t.description=="string"?t.description:"",prompt:typeof t.prompt=="string"?t.prompt:void 0,subagentType:typeof t.subagent_type=="string"?t.subagent_type:void 0}}const $de={render:({input:e})=>Ye.createElement(jde,{items:Dde(e)})},zde={render:({input:e})=>{const{description:t,prompt:n,subagentType:r}=Bde(e);return Ye.createElement(Ode,{description:t,prompt:n,subagentType:r})}},zE={render:({input:e,output:t,error:n,pending:r,fileScope:i,onShareFile:s,onOpenInTab:o,onPreviewMarkdown:a})=>{const l=Hde(e),c=l?Ye.createElement(Mde,{filePath:l.filePath,oldString:l.oldString,newString:l.newString,content:l.content}):void 0;return Ye.createElement(kM,{tool:Fde(e),input:e,output:t,error:n,pending:r,expandedBody:c,...i?{fileScope:i}:{},...s?{onShareFile:s}:{},...o?{onOpenInTab:o}:{},...a?{onPreviewMarkdown:a}:{}})}};function Fde(e){const t=e??{};return"content"in t&&t.content!==void 0?"Write":("old_string"in t&&t.old_string!==void 0,"Edit")}function Hde(e){const t=e??{},n=typeof t.file_path=="string"?t.file_path:null;if(!n)return null;const r=typeof t.old_string=="string"?t.old_string:void 0,i=typeof t.new_string=="string"?t.new_string:void 0,s=typeof t.content=="string"?t.content:void 0;return r==null&&i==null&&s==null?null:{filePath:n,oldString:r,newString:i,content:s}}for(const e of["claude",h9])za.register(e,"TodoWrite",$de),za.register(e,"Task",zde),za.register(e,"Edit",zE),za.register(e,"Write",zE);const jj=document.getElementById("root");if(!jj)throw new Error("guest-main: #root not found");const Ude=pO({});N0.createRoot(jj).render(h.jsx(Ye.StrictMode,{children:h.jsx(Rde,{host:Ude})}));
|
|
623
|
+
`).map((w,x)=>h.jsx("div",{className:`px-4 ${w.startsWith("+")?"bg-success/8 text-success":w.startsWith("-")?"bg-error/8 text-error":"text-text-300"}`,children:w||" "},x)),f.truncated&&h.jsx("div",{className:"px-4 text-text-400",children:"Diff 较大,已截断显示。"})]}):h.jsx("div",{className:"p-5 text-[12px] text-text-400",children:a??"正在读取 diff…"})]})]})]})})]})}const Fue=250;function Hue(e){if(!e||!Number.isFinite(e))return null;const t=e/1e3;if(t<60)return`${t.toFixed(0)}s`;const n=Math.floor(t/60);return`${n}m${Math.round(t-n*60).toString().padStart(2,"0")}s`}function Uue({agents:e}){var l,c,u;const[t,n]=g.useState(!1),r=g.useRef(null);if(g.useEffect(()=>{if(!t)return;const d=f=>{const p=r.current;p&&f.target instanceof Node&&p.contains(f.target)||n(!1)};return window.addEventListener("pointerdown",d,!0),()=>window.removeEventListener("pointerdown",d,!0)},[t]),e.length===0)return null;const i=e.length===1?e[0]:null,s=i?i.description:`${e.length} 个后台任务`,o=i?Hue((c=(l=i.progress)==null?void 0:l.stats)==null?void 0:c.durationMs):null,a=i?(u=i.progress)==null?void 0:u.lastToolName:null;return h.jsxs("div",{ref:r,"data-testid":"running-agents-chip","data-agent-count":e.length,className:"relative",children:[t?h.jsx("div",{"data-testid":"running-agents-popover",className:"absolute bottom-full right-0 z-20 mb-1 w-[min(560px,80vw)]",children:h.jsx("div",{className:"min-w-0 overflow-y-auto rounded-lg border border-bg-200/60 bg-bg-100 px-2 py-1 shadow-lg",style:{maxHeight:Fue},children:e.map(d=>h.jsx(PM,{expandable:!1,description:d.description,input:d.input,output:d.output,...d.error!==void 0?{error:d.error}:{},pending:d.pending,notifications:d.notifications,...d.toolResultExtra?{toolResultExtra:d.toolResultExtra}:{},...d.progress?{progress:d.progress}:{}},d.toolUseId))})}):null,h.jsxs("button",{type:"button","data-testid":"running-agents-chip-toggle","aria-expanded":t,onClick:()=>n(d=>!d),className:ie("flex max-w-[min(560px,80vw)] min-w-0 items-center gap-2 rounded-full","border border-bg-200/60 bg-bg-100/95 px-3 py-1 text-[12px] shadow-md backdrop-blur","hover:bg-bg-200/95 transition-colors"),children:[h.jsx(Tn,{className:"w-3 h-3 shrink-0 animate-spin text-blue-400"}),h.jsx("span",{className:"min-w-0 flex-1 truncate text-left text-text-200",children:s}),o?h.jsx("span",{className:"shrink-0 tabular-nums text-text-400",children:o}):null,a?h.jsxs("span",{className:"shrink-0 font-mono tabular-nums text-blue-400",children:["now:",a]}):null,h.jsx(d4,{className:ie("w-3.5 h-3.5 shrink-0 text-text-400 transition-transform",t&&"rotate-180")})]})]})}const Wue={closeTrailing:!1},que={closeTrailing:!0};function Vue(e){return e?Wue:que}function Kue({session:e,api:t,onPromoteQuickAsk:n}){const r=eR(e.sessionId);return h.jsx(Rj,{state:r,extras:{session:e,api:t,...n?{onPromoteQuickAsk:n}:{}}})}function Gue({headerMeta:e,connState:t,liveWorktreeRoot:n,onOpenConfig:r,variant:i="full",ephemeral:s,onPromote:o,hideHeader:a=!1,flatProcess:l=!1,lines:c,pendingPermissions:u,procAlive:d,rewindableUserMessageIds:f,onPermissionRespond:p,onPermissionInterrupt:m,onRewind:v,onFork:w,onQuickAsk:x,topSlot:_,codexHistory:b,realtimeQuestionAnswers:S,onSubmitQuestion:C,onCancelQuestion:k,liveQuestionToolUseIds:N,api:E,cwd:j,tool:P,cloudVolume:L,sessionKey:M,onSend:R,awaitingUser:A,queued:D,onDequeue:z,onAbort:F,onNewSession:$,onClearSession:O,configSlot:I,workspaceInput:U,workspaceInputDisabled:q,chatRootRef:B,chatBodyRef:te,drawers:le,xtermSlot:Y,fileSharingScope:re,onShareFile:ke,onOpenInTab:oe,onPreviewMarkdown:Ie,onOpenFilePath:Ee,dispatchOrigin:Re}){const[he,Be]=g.useState(0),Je=g.useMemo(()=>i==="full"?NY(rR(c)):[],[c,i]),Ge=g.useMemo(()=>new Set(Je.map(ft=>ft.toolUseId)),[Je]);return h.jsx(wie,{children:h.jsxs("div",{ref:B,"data-cc-chat-root":"",className:"flex flex-col h-full bg-bg-100",children:[a?null:h.jsx(_se,{meta:e,...P?{tool:P}:{},...L?{cloudVolume:L}:{},connState:t,variant:i,...n!==void 0?{liveWorktreeRoot:n}:{},...i==="full"&&r?{onOpenConfig:r}:{},...i==="quickask"?{ephemeral:s??!1,...o?{onPromote:o}:{}}:{}}),h.jsx("div",{ref:te,"data-testid":"chat-body",className:"flex-1 overflow-y-auto min-h-0",style:{overflowAnchor:"none",paddingBottom:he},children:h.jsx(MM,{lines:c,forkByTurn:P==="codex"||P===Wy,...p?{onPermissionRespond:p}:{},...m&&d?{onPermissionInterrupt:m}:{},topSlot:_,codexHistory:b,...v?{onRewind:v}:{},rewindableUserMessageIds:f,...w?{onFork:w}:{},...x?{onQuickAsk:x}:{},realtimeQuestionAnswers:S,onSubmitQuestion:C,...k?{onCancelQuestion:k}:{},liveQuestionToolUseIds:N,...re?{fileSharingScope:re}:{},...ke?{onShareFile:ke}:{},...oe?{onOpenInTab:oe}:{},...Ie?{onPreviewMarkdown:Ie}:{},...Ee?{onOpenFilePath:Ee}:{},...Re?{dispatchOrigin:Re}:{},...i==="full"&&!l?{turnCollapse:Vue(d)}:{},dockedAgentToolUseIds:Ge})}),Y,h.jsx(yue,{onHeightChange:Be,children:h.jsx(Uue,{agents:Je})}),e.larkChatName?h.jsx("div",{className:"mx-3 mb-3 rounded-lg border border-border bg-bg-200 px-3 py-2 text-[12px] text-text-400","data-testid":"lark-readonly-notice",children:e.larkChatType==="p2p"?`此会话由与「${e.larkChatName}」的飞书私聊驱动——对方消息触发,这里仅供观察。`:`此会话由飞书群「${e.larkChatName}」驱动——群成员 @ bot 提问触发,这里仅供观察。`}):h.jsx(xse,{meta:e,aboveSlot:U,disabled:q,...E?{api:E}:{},cwd:j,...P?{tool:P}:{},sessionKey:M,onSend:R,awaitingUser:A,...D?{queued:D}:{},...z?{onDequeue:z}:{},...F?{onAbort:F}:{},...$?{onNewSession:$}:{},...O?{onClearSession:O}:{},...I?{configSlot:I}:{}}),le]})})}function Rj({state:e,extras:t,onQuickAskInternal:n,onPreviewMdInternal:r}){var xr;const{session:i,api:s,liveGitBranch:o,liveWorktreeRoot:a,cloudVolume:l,onNewSession:c,onTurnEnd:u,onOpenConfig:d,onFork:f,onQuickAsk:p,viewerRole:m,onPromoteQuickAsk:v,configSlot:w,hideHeader:x,flatProcess:_}=t,{capabilities:b}=Am(i.tool||"claude"),S=(b==null?void 0:b.features)??t4(i.tool),[C,k]=g.useState(null),[N,E]=g.useState(null),j=Jp(),P=!!s&&j.actionsLevel==="owner"&&S.fileSharing,L=a4(i.ownerPersonaId??null).persona,M=(L==null?void 0:L.label)??null,R=!!M&&!!i.ownerPersonaId,A=mue(),D=g.useMemo(()=>({resolve:(Z,we)=>A.resolve(Z,we,i.sessionId),...A.onOpenSession?{onOpenSession:A.onOpenSession}:{}}),[A,i.sessionId]),z=g.useCallback((Z,we)=>{k({kind:Z,text:we}),setTimeout(()=>{k(De=>(De==null?void 0:De.text)===we?null:De)},2e3)},[]),F=Ni(),$=Wc(i.tool)&&m!=="guest"&&!i.larkChatId&&!v,O=_ue(s,i.sessionId,$,F,i.cloudWorkspace,i.cloudBranchIntent),I=Cz(),U=XP(i.sessionId,i.toolSessionId),{events:q,pendingQuestions:B,clearQuestion:te,markQuestionSubmitted:le,status:Y}=U,re=e.historyLoading,ke=JP(Y);g.useEffect(()=>{$e("chat-panel","sessionStatus",{sessionId:i.sessionId,sessionStatus:Y,procAlive:ke})},[Y,ke,i.sessionId]);const oe=e.lines,Ie=e.pendingPermissions,Ee=Ie[0]??null,Re=g.useMemo(()=>EY(q),[q]),[he,Be]=g.useState(null),[Je,Ge]=g.useState(()=>new Set);SY(s,i.sessionId,i.toolSessionId,S.observe);const ft=g.useRef(i.sessionId);g.useEffect(()=>{if(ft.current=i.sessionId,!S.rewind){Be(null);return}let Z=!1;return Be(null),(async()=>{try{const we=await s.sessionRewindableMessageIds(i.sessionId);if(Z)return;Be(new Set(we.userMessageIds))}catch{Z||Be(null)}})(),()=>{Z=!0}},[s,i.sessionId,S.rewind]);const Kt=g.useCallback(()=>{const Z=i.sessionId;s.sessionRewindableMessageIds(Z).then(we=>{ft.current===Z&&Be(new Set(we.userMessageIds))}).catch(()=>{})},[s,i.sessionId]),fe=g.useMemo(()=>{if(he!==null){const ct=new Set(he);for(const Br of Je)ct.delete(Br);return ct}const Z=new Set(["Edit","Write","MultiEdit","NotebookEdit"]),we=new Set;let De=null;for(const ct of oe)ct.kind==="user-text"?De=ct.uuid??null:De&&ct.kind==="tool-call"&&Z.has(ct.tool)&&!Je.has(De)&&we.add(De);return we},[oe,Je,he]),He=g.useRef(u);He.current=u,kY(i.sessionId,i.toolSessionId,()=>{hn(null),Ge(new Set)});const Pe=Dse({sessionStatus:Y}),Me=g.useRef(null);g.useEffect(()=>{var De;const Z=Me.current,we=(Z==null?void 0:Z.sid)===i.sessionId;we&&Z.phase===Pe||(Me.current={sid:i.sessionId,phase:Pe},$e("session-phase",Pe,{sid:i.sessionId,phase:Pe,prev:we?Z.phase:null,desc:Lse[Pe]}),we&&Z.phase==="turn-running"&&Pe!=="turn-running"&&((De=He.current)==null||De.call(He),Kt()))},[Pe,i.sessionId,Kt]);const rt=g.useCallback(async()=>{const Z=await s.sessionInterrupt(i.sessionId).catch(()=>{});return(Z==null?void 0:Z.queued)??[]},[s,i.sessionId]),[tn,hn]=g.useState(null),W=g.useCallback(Z=>{hn(Z)},[]),[ee,be]=g.useState(!1),Oe=g.useCallback(()=>{s.sessionStop(i.sessionId).catch(()=>{}),be(!1)},[s,i.sessionId]);g.useCallback(Z=>{s.pinSession(i.sessionId,Z).catch(we=>{$e("chat-panel","pinSession failed",{err:we==null?void 0:we.message})})},[s,i.sessionId]);const Ue=v?"quickask":"full",{container:At,workspaceContainer:bn,onCollapse:nn,hostExtras:fn}=Ise(),ce=g.useRef(0),Se=g.useRef(null);g.useEffect(()=>{const Z=we=>{if(we.key!=="Escape")return;if(!ke){ce.current=0;return}if(we.isComposing)return;const ct=we.target;if(ct&&ct.closest("[data-cc-chat-root]")!==Se.current)return;const Br=Date.now();Br-ce.current<2e3?(ce.current=0,be(!0)):(ce.current=Br,rt())};return window.addEventListener("keydown",Z),()=>window.removeEventListener("keydown",Z)},[rt,ke]);const st=g.useRef(null),gt=g.useRef(null),gr=g.useRef(!!e.codexHistory);gr.current=!!e.codexHistory;const ae=g.useRef(!0),it=g.useRef(void 0),Bt=g.useRef(0),ti=g.useRef(0),oa=g.useRef(void 0);g.useEffect(()=>{E(null)},[i.sessionId]),g.useEffect(()=>{const Z=st.current;if(!Z)return;const we=150,De=ct=>{gr.current||Date.now()<ti.current&&(ct.preventDefault(),ti.current=Date.now()+we)};return Z.addEventListener("wheel",De,{passive:!1}),()=>Z.removeEventListener("wheel",De)},[]),g.useEffect(()=>{const Z=st.current;if(!Z)return;const we=32,De=()=>{var Br;const ct=Z.scrollHeight-Z.scrollTop-Z.clientHeight;ae.current=ct<=we,e.codexHistory&&(gt.current=S2(Z)),Z.scrollTop<=24&&e.historyHasMore&&!e.historyLoadingOlder&&!e.historyError&&!re&&((Br=e.loadOlderHistory)==null||Br.call(e))};return Z.addEventListener("scroll",De,{passive:!0}),()=>Z.removeEventListener("scroll",De)},[e.codexHistory,e.historyHasMore,e.historyLoadingOlder,e.historyError,e.loadOlderHistory,re]),g.useLayoutEffect(()=>{var Ob;const Z=st.current;if(!Z)return;const we=oa.current!==i.sessionId;we&&(oa.current=i.sessionId,ae.current=!0,it.current=void 0,Bt.current=0,ti.current=0,gt.current=null);const De=it.current,ct=(Ob=oe[0])==null?void 0:Ob.seq;if(it.current=ct,e.codexHistory){!we&>.current&&!ae.current?Fie(Z,gt.current):ae.current&&(Z.scrollTop=Z.scrollHeight),gt.current=S2(Z),Bt.current=Z.scrollHeight-Z.scrollTop;return}!we&&De!==void 0&&ct!==void 0&&ct<De?(Z.scrollTop=Z.scrollHeight-Bt.current,ti.current=Date.now()+200):ae.current&&(Z.scrollTop=Z.scrollHeight),Bt.current=Z.scrollHeight-Z.scrollTop},[oe,Ee==null?void 0:Ee.requestId,i.sessionId]);const aa=g.useMemo(()=>{const Z={};for(const[we,De]of Object.entries(B))De.submittedAnswers&&(Z[we]=De.submittedAnswers);return Z},[B]),ds=g.useMemo(()=>new Set(Object.keys(B)),[B]),la=g.useCallback(async(Z,we)=>{try{await s.answerQuestion({sessionId:i.sessionId,toolUseId:Z,answers:we}),le(Z,we)}catch{}},[s,i.sessionId,le]),Yl=g.useCallback(async Z=>{try{await s.cancelQuestion({sessionId:i.sessionId,toolUseId:Z}),te(Z)}catch{}},[s,i.sessionId,te]),Xl=g.useCallback(async(Z,we)=>{var De;if(Ee)try{await((De=e.respondPermission)==null?void 0:De.call(e,Ee.requestId,Z?"allow":"deny"))}catch{}},[e,Ee]),hs=g.useCallback(async()=>{const Z=i.sessionId;try{await s.sessionStop(Z)}catch{}e.clearSession?await e.clearSession():await s.sessionNew(Z)},[e,s,i.sessionId]),ni=e.meta.streamInProgress??!1,md=g.useMemo(()=>{if(e.codexHistory)return h.jsxs("div",{className:"flex flex-col items-center gap-2 py-2 text-xs text-text-400","data-testid":"codex-history-top",children:[e.historySyncError?h.jsx("span",{children:e.historySyncError}):null,e.historyError?h.jsx("span",{"data-testid":"history-error",children:e.historyError}):null,re||e.historyLoadingOlder?h.jsx("span",{"data-testid":"history-loading",children:"正在加载历史…"}):e.historyHasMore?h.jsx("button",{type:"button",onClick:()=>{var we;return void((we=e.loadOlderHistory)==null?void 0:we.call(e))},children:e.historyError?"重试更早记录":"加载更早记录"}):e.historyLoaded&&!e.historyError&&!e.historySyncError?h.jsx("span",{children:"已加载全部轮次摘要"}):null,e.historyError||e.historySyncError?h.jsx("button",{type:"button",onClick:()=>{var we;return void((we=e.refreshHistory)==null?void 0:we.call(e))},children:"刷新历史"}):null]});const Z=e.historySyncError?h.jsxs("div",{className:"flex justify-center items-center gap-2 py-2 text-[12px] text-text-400","data-testid":"history-sync-error",children:[h.jsx("span",{children:e.historySyncError}),e.reloadFromCloud?h.jsx("button",{type:"button","data-testid":"history-sync-reload",disabled:ni,onClick:e.reloadFromCloud,className:"text-accent hover:underline cursor-pointer disabled:cursor-not-allowed disabled:opacity-50 disabled:no-underline",children:"从云端重新加载"}):null]}):null;return e.historyError?h.jsxs(h.Fragment,{children:[Z,h.jsxs("div",{className:"flex justify-center py-2 text-[12px] text-text-400","data-testid":"history-error",children:["历史未加载完(",e.historyError,");切走再切回可重试"]})]}):Z||(re&&oe.length===0?h.jsx("div",{className:"flex justify-center py-4","data-testid":"history-loading",children:h.jsx(Tn,{className:"w-4 h-4 text-text-400 animate-spin"})}):null)},[re,oe.length,e.historyError,e.historySyncError,e.reloadFromCloud,ni,e.codexHistory,e.historyHasMore,e.historyLoaded,e.historyLoadingOlder,e.loadOlderHistory,e.refreshHistory]),ca=e.meta,Gt=h.jsxs(h.Fragment,{children:[i.toolSessionId&&S.subagents?h.jsx(Nse,{api:s,cwd:i.cwd,toolSessionId:i.toolSessionId,toolKind:i.tool??"claude"}):null,tn&&S.rewind?h.jsx(Pse,{open:!0,onOpenChange:Z=>{Z||hn(null)},api:s,sessionId:i.sessionId,userMessageId:tn,lines:oe,procAlive:ke,onNoChanges:Z=>{Ge(we=>{if(we.has(Z))return we;const De=new Set(we);return De.add(Z),De})}}):null,ee?h.jsx(Yue,{onConfirm:Oe,onCancel:()=>be(!1)}):null]}),Zl={kind:"session",sessionId:i.sessionId},gd=g.useCallback(async Z=>{if(s)try{await _C(s,F,i.sessionId,Z)}catch(we){const De=we.message;$e("chat-panel","open-in-tab failed",{err:De}),z("err",`Open in tab 失败:${De}`)}},[s,F,i.sessionId,z]),[jt,$t]=g.useState(!1),[Wn,vr]=g.useState(null),Mi=g.useCallback(Z=>{if(r){r(Z);return}vr(Z),$t(!0)},[r]),zm=g.useCallback(Z=>{if(!s)return;const we=async()=>{try{await s.attachmentGroupAdd(i.sessionId,Z)}catch(ct){$e("chat-panel","file-link groupAdd skipped",{err:ct.message})}},De=ct=>{const Br=ct.message;$e("chat-panel","file-link open failed",{err:Br}),z("err",`打开文件失败:${Br}`)};if(Nm(Z)){we().then(()=>Mi(Z),De);return}_C(s,F,i.sessionId,Z,60,we).catch(De)},[s,F,i.sessionId,Mi,z]),vd=g.useCallback(async Z=>{if(!s)throw new Error("daemon api not ready");const we=await G_(s,F,i.sessionId,Z,60),De=await fetch(we);if(!De.ok)throw new Error(`fetch ${De.status} ${De.statusText}`);return await De.text()},[s,F,i.sessionId]),co=g.useCallback(async(Z,we)=>{if(s)try{const{url:De}=await s.attachmentSignUrl({sessionId:i.sessionId,relPath:Z,...we?{view:we}:{}}),ct=await dY(De);z(ct?"ok":"err",ct?"分享链接已复制到剪贴板":"复制失败:请手动复制")}catch(De){const ct=De.message;$e("chat-panel","share-file failed",{err:ct}),z("err",`生成分享链接失败:${ct}`)}},[s,i.sessionId,z]),uo=g.useCallback(()=>E(null),[]),Fm=N==="files"&&P&&s?{title:"Edited Files",onBack:uo,content:h.jsx(Xle,{api:s,scope:Zl,sessionId:i.sessionId,onShareFile:co,onOpenInTab:gd,onPreviewMarkdown:Mi})}:N==="cron"?{title:`定时任务${Re.length?` (${Re.length})`:""}`,onBack:uo,content:h.jsx("div",{className:"p-3",children:h.jsx(jse,{jobs:Re})})}:N==="persona"&&R&&s&&i.ownerPersonaId?{title:`Persona · ${M??""}`,onBack:uo,content:h.jsx(hue,{personaId:i.ownerPersonaId,open:!0,onClose:uo,api:s,embedded:!0,...m?{viewerRole:m}:{}},i.ownerPersonaId)}:null,xd=Ue==="full"?h.jsx(Cse,{session:i,meta:ca,...$&&O.binding?{liveGitBranch:((xr=O.workspace)==null?void 0:xr.actualBranch)??null}:o!==void 0?{liveGitBranch:o}:{},...a!==void 0?{liveWorktreeRoot:a}:{},...R?{personaName:M}:{},...R?{onOpenPersona:()=>E("persona")}:{},...P?{onOpenFiles:()=>E("files")}:{},cronActiveCount:Re.length,onCronClick:()=>E("cron"),onForceStop:()=>be(!0),...Wc(i.tool)&&e.reloadFromCloud?{onReloadFromCloud:e.reloadFromCloud,reloadFromCloudDisabled:ni}:{},...m?{viewerRole:m}:{},...b!=null&&b.toolSessionIdLabel?{toolSessionIdLabel:b.toolSessionIdLabel}:{},drill:Fm,...nn?{onCollapse:nn}:{},...fn?{title:fn.title,leadingEntries:fn.leadingEntries}:{}}):null;return h.jsxs(h.Fragment,{children:[$&&bn?Oo.createPortal(h.jsx(zue,{controller:O,disabled:ca.streamInProgress}),bn):null,At&&xd?Oo.createPortal(xd,At):null,h.jsx(Gue,{headerMeta:ca,workspaceInput:$?h.jsx($ue,{controller:O,disabled:ca.streamInProgress}):void 0,workspaceInputDisabled:$&&O.busy,connState:e.connState,...a!==void 0?{liveWorktreeRoot:a}:{},...d?{onOpenConfig:d}:{},variant:Ue,...x||$?{hideHeader:!0}:{},..._?{flatProcess:_}:{},...Ue==="quickask"?{ephemeral:i.ephemeral!==!1,onPromote:()=>void(v==null?void 0:v(i.sessionId))}:{},lines:oe,pendingPermissions:Ie,procAlive:ke,rewindableUserMessageIds:fe,onPermissionRespond:Xl,onPermissionInterrupt:rt,onRewind:S.rewind?W:void 0,...f&&S.fork?{onFork:f}:{},...Wc(i.tool)?{}:n&&S.fork?{onQuickAsk:n}:p&&S.fork?{onQuickAsk:p}:{},topSlot:md,codexHistory:e.codexHistory,realtimeQuestionAnswers:aa,onSubmitQuestion:la,onCancelQuestion:Yl,liveQuestionToolUseIds:ds,api:s,cwd:i.cwd,...i.tool?{tool:i.tool}:{},...l?{cloudVolume:l}:{},sessionKey:i.sessionId,onSend:e.sendText,queued:e.queued,onDequeue:e.dequeue,awaitingUser:Ie.length>0||Object.values(B).some(Z=>!Z.submittedAnswers),onAbort:rt,...c?{onNewSession:c}:{},onClearSession:hs,...w?{configSlot:w}:{},chatRootRef:Se,chatBodyRef:st,drawers:Gt,xtermSlot:I==="tui"&&ke&&S.tui?h.jsx(Yle,{sessionId:i.sessionId,client:F},i.sessionId):null,fileSharingScope:Zl,...s?{onShareFile:co}:{},...s?{onOpenInTab:gd}:{},...s?{onPreviewMarkdown:Mi}:{},...s?{onOpenFilePath:zm}:{},dispatchOrigin:D}),s?h.jsx(xue,{open:jt,onOpenChange:$t,relPath:Wn,loadMarkdown:vd,onShare:Wn?()=>void co(Wn,"md-rendered"):void 0}):null,C?h.jsx("div",{"data-testid":"share-toast",role:"status","aria-live":"polite",className:C.kind==="ok"?"fixed left-1/2 top-4 z-50 -translate-x-1/2 rounded-md border border-emerald-500/40 bg-emerald-500/10 px-3 py-2 text-[12px] text-emerald-700 shadow-md dark:text-emerald-300":"fixed left-1/2 top-4 z-50 -translate-x-1/2 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-[12px] text-destructive shadow-md",children:C.text}):null]})}function Yue({onConfirm:e,onCancel:t}){return h.jsx("div",{role:"dialog","aria-modal":"true","data-testid":"force-stop-confirm",className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40",onClick:t,children:h.jsxs("div",{className:"max-w-sm w-[92%] rounded-lg border border-red-400/40 bg-bg-0 p-4 shadow-xl",onClick:n=>n.stopPropagation(),children:[h.jsxs("div",{className:"flex items-start gap-2 mb-3",children:[h.jsx(Wf,{className:"w-5 h-5 text-red-500 shrink-0 mt-0.5"}),h.jsx("div",{className:"text-[14px] text-text-100",children:"强制停止会话进程?会丢失 initialize / 预热缓存,下一次发送需要重新 spawn。"})]}),h.jsxs("div",{className:"flex justify-end gap-2",children:[h.jsx("button",{type:"button",onClick:t,className:"h-8 px-3 rounded-md text-[12px] text-text-300 hover:bg-text-100/5 cursor-pointer",children:"取消"}),h.jsx("button",{type:"button","data-testid":"force-stop-confirm-ok",onClick:e,className:"h-8 px-3 rounded-md bg-red-500 text-white text-[12px] font-medium hover:bg-red-600 cursor-pointer",children:"强制停止"})]})]})})}function Xue(e){return e.split("/").pop()||e}function Zue({state:e,api:t,onSwitchTab:n,onCloseQuickAsk:r,onCloseMd:i,loadMarkdown:s,quickAskSession:o,onPromoteQuickAsk:a}){if(!tR(e))return null;const l=[];e.quickAsk&&l.push({id:"quick-ask",label:"问一下",title:"问一下",icon:h.jsx(mx,{className:"w-3.5 h-3.5"})});for(const c of e.mds)l.push({id:{kind:"md",relPath:c},label:Xue(c),title:c,icon:h.jsx(Ci,{className:"w-3.5 h-3.5"})});return h.jsxs("div",{className:"flex flex-col h-full bg-bg-50/60 border-l border-border-strong",children:[h.jsx(Pu,{delayDuration:200,skipDelayDuration:100,children:h.jsx("div",{className:["flex items-stretch h-9 border-b border-text-100/10 shrink-0 overflow-x-auto","[scrollbar-width:none] [-ms-overflow-style:none]","[&::-webkit-scrollbar]:hidden"].join(" "),role:"tablist",children:l.map(c=>{const u=wY(e.active,c.id),d=c.id==="quick-ask"?"quick-ask":`md:${c.id.relPath}`;return h.jsxs(nd,{children:[h.jsx(rd,{asChild:!0,children:h.jsxs("div",{role:"tab","aria-selected":u,"data-tab-title":c.title,onClick:()=>n(c.id),className:["group relative flex items-center gap-2 px-3 h-full cursor-pointer select-none","text-[12px] max-w-[180px] shrink-0 transition-colors duration-100",u?"text-text-100":"text-text-400 hover:text-text-100 hover:bg-text-100/[0.04]"].join(" "),children:[c.icon,h.jsx("span",{className:"truncate",children:c.label}),h.jsx("button",{type:"button","aria-label":`关闭 ${c.label}`,className:["ml-1 rounded p-0.5 shrink-0 transition-opacity","hover:bg-text-100/10",u?"opacity-70 hover:opacity-100":"opacity-0 group-hover:opacity-70"].join(" "),onClick:f=>{f.stopPropagation(),c.id==="quick-ask"?r():i(c.id.relPath)},children:h.jsx(Qr,{className:"w-3 h-3"})}),u?h.jsx("span",{"aria-hidden":"true",className:"absolute left-2 right-2 -bottom-px h-[2px] rounded-full bg-accent"}):null]})}),h.jsx(Ul,{side:"bottom",align:"start",className:"max-w-sm break-all",children:c.title})]},d)})})}),h.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden relative",children:[e.quickAsk&&o?h.jsx("div",{className:"absolute inset-0",style:{display:e.active==="quick-ask"?"block":"none"},children:h.jsx(Kue,{session:o,api:t,...a?{onPromoteQuickAsk:a}:{}})}):null,e.mds.map(c=>{const u=e.active!==null&&e.active!=="quick-ask"&&e.active.relPath===c;return h.jsx("div",{className:"absolute inset-0",style:{display:u?"block":"none"},children:h.jsx(dj,{relPath:c,loadMarkdown:s,showTitleBar:!1})},`md-body:${c}`)})]})]})}function Que(e){const t=e instanceof Error?e.message:String(e);return t.length>200?`${t.slice(0,200)}…`:t}function Jue({state:e,extras:t}){const{api:n,session:r}=t,i=Ni(),[s,o]=g.useState(mY()),[a,l]=g.useState(null),c=r.ownerPersonaId!==MT,u=g.useRef(s);u.current=s;const d=g.useRef(!1),f=g.useCallback(async E=>{const j=u.current.quickAsk;l(null);let P;try{P=await aY(n,r,E)}catch(L){$e("quick-ask","fork failed",L),d.current||l(Que(L));return}if(!P){d.current||l("这条会话还没准备好(没有可派生的对话记录),稍后再试");return}if(d.current){n.sessionDelete(P.sessionId).catch(()=>{});return}ih(j)&&n.sessionDelete(j.sessionId).catch(()=>{}),o(L=>gY(L,{sessionId:P.sessionId}))},[n,r]),p=g.useCallback(async E=>{const j=u.current.quickAsk,P=(j==null?void 0:j.sessionId)===E;try{await lY(n,{sessionId:E,stillEphemeral:P&&ih(j)})&&o(M=>yY(M))}catch(L){$e("quick-ask","promote failed",L)}},[n]),m=g.useCallback(E=>{o(j=>vY(j,E))},[]),v=g.useCallback(E=>{o(j=>bY(j,E))},[]),w=g.useCallback(()=>{const E=u.current.quickAsk;ih(E)&&n.sessionDelete(E.sessionId).catch(()=>{}),o(j=>xY(j))},[n]),x=g.useCallback(E=>{o(j=>_Y(j,E))},[]);g.useEffect(()=>()=>{d.current=!0;const E=u.current.quickAsk;ih(E)&&n.sessionDelete(E.sessionId).catch(()=>{})},[]);const _=es("sessions")??[],b=s.quickAsk?_.find(E=>E.sessionId===s.quickAsk.sessionId)??{sessionId:s.quickAsk.sessionId,cwd:r.cwd,tool:r.tool}:null,S=g.useCallback(async E=>{const j=await G_(n,i,r.sessionId,E,60),P=await fetch(j);if(!P.ok)throw new Error(`fetch ${P.status} ${P.statusText}`);return P.text()},[n,i,r.sessionId]),C=h.jsx(Rj,{state:e,extras:t,onQuickAskInternal:f,onPreviewMdInternal:m}),{initialSize:k,setSize:N}=pY("chat-panel-right-slot-width",480);return h.jsxs(q_,{orientation:"horizontal",className:"flex-1 flex min-w-0 min-h-0",children:[h.jsx(Qf,{id:"chat",minSize:"400px",children:h.jsxs("div",{className:"relative flex flex-col min-w-0 min-h-0 h-full",children:[C,a?h.jsxs("div",{"data-testid":"quick-ask-error",className:"absolute bottom-24 left-1/2 z-10 -translate-x-1/2 max-w-[90%] rounded-md border border-border bg-bg-200 px-3 py-2 text-[12px] text-text-300 shadow-lg",children:[h.jsxs("span",{className:"mr-2",children:["问一下没能打开:",a]}),h.jsx("button",{type:"button","aria-label":"关闭提示",onClick:()=>l(null),className:"text-text-400 hover:text-text-200 cursor-pointer",children:"✕"})]}):null]})}),tR(s)?h.jsxs(h.Fragment,{children:[h.jsx(YP,{className:"w-1 bg-text-100/10 hover:bg-text-100/25 transition-colors cursor-col-resize"}),h.jsx(Qf,{id:"right-slot",defaultSize:`${k}px`,minSize:"360px",maxSize:"800px",onResize:E=>N(E.inPixels),children:h.jsx(Zue,{state:s,api:n,onSwitchTab:v,onCloseQuickAsk:w,onCloseMd:x,loadMarkdown:S,quickAskSession:b,...c?{onPromoteQuickAsk:p}:{}})})]}):null]})}function ede({extras:e}){const t=eR(e.session.sessionId,e.focused);return h.jsx(Jue,{state:t,extras:e})}function tde(e,t,n){var s;const r=n.find(o=>o.name==="effort"),i=e?t.find(o=>o.id===e):void 0;if(i!=null&&i.efforts&&i.efforts.length>0){const o=(s=r==null?void 0:r.options)==null?void 0:s.find(l=>l.value==="none");return{options:o?[o,...i.efforts.filter(l=>l.value!=="none")]:i.efforts,defaultValue:i.defaultEffort??""}}return{options:(r==null?void 0:r.options)??[],defaultValue:typeof(r==null?void 0:r.default)=="string"?r.default:""}}function nde(e,t,n){var l;if(!t)return((l=(e??[]).find(c=>c.id===""))==null?void 0:l.label)??"未指定";const r=t.toLowerCase(),i=[["opus","Opus"],["fable","Fable"],["sonnet","Sonnet"],["haiku","Haiku"]];for(const[c,u]of i){if(!r.includes(c))continue;const d=r.match(new RegExp(`${c}-(\\d+)(?:-(\\d+))?`));return d?d[2]?`${u} ${d[1]}.${d[2]}`:`${u} ${d[1]}`:u}const s=e??[],o=s.find(c=>c.id===t);if(o)return o.label;const a=s.find(c=>c.id&&t.toLowerCase().includes(c.id.toLowerCase()));return a?a.label:t}function rde(e,t){var m,v,w,x;const{models:n,modes:r,configSchema:i}=t,s=e.resolvedModel??e.model,o=tde(s,n,i),a=o.options,l=a.some(_=>_.value===e.effort)?e.effort:o.defaultValue,c=e.effort===""&&e.resolvedEffort?((m=a.find(_=>_.value===e.resolvedEffort))==null?void 0:m.label)??e.resolvedEffort:((v=a.find(_=>_.value===l))==null?void 0:v.label)??null,u=((w=i.find(_=>_.name==="permissionMode"))==null?void 0:w.default)??"",d=r.some(_=>_.id===e.permissionMode)?e.permissionMode:u,p=d===u?null:((x=r.find(_=>_.id===d))==null?void 0:x.label)??null;return{modelLabel:nde(n,s),effortOptions:a,effortValue:l,effortLabel:c,modeValue:d,modeLabel:p,modeTone:p===null?null:d==="bypassPermissions"?"danger":"info"}}function Mj(e){let t;return e.map(n=>{const r=n.group&&n.group!==t?n.group:null;return n.group&&(t=n.group),{...n,groupHeading:r}})}function ide(e){return e.map(t=>({value:t.id,label:t.label,...t.description?{description:t.description}:{},...t.group?{group:t.group}:{}}))}function sde({testid:e,list:t,options:n,current:r,onSelect:i}){if(t.loading)return h.jsx(Ir,{disabled:!0,"data-testid":`${e}-loading`,className:"text-[12px] text-text-400",children:"正在读取最新模型…"});if(t.error)return h.jsxs(h.Fragment,{children:[h.jsx("div",{"data-testid":`${e}-error`,className:"px-2 py-1.5 text-[11px] text-warning",children:t.error}),h.jsx(Ir,{"data-testid":`${e}-retry`,className:"text-[12px]",onSelect:o=>{o.preventDefault(),t.load()},children:"重试"})]});const s=n??ide(t.models);return s.length===0?h.jsx(Ir,{disabled:!0,"data-testid":`${e}-empty`,className:"text-[12px] text-text-400",children:"没有可选模型"}):h.jsx(h.Fragment,{children:Mj(s).map((o,a)=>{const l=o.value===r;return h.jsxs(Ye.Fragment,{children:[o.groupHeading?h.jsxs(h.Fragment,{children:[a>0?h.jsx(vm,{}):null,h.jsx(j_,{"data-testid":`${e}-group`,children:o.groupHeading})]}):null,h.jsxs(Ir,{"data-testid":`${e}-option-${o.value||"default"}`,onSelect:()=>i(o.value),className:"items-start gap-2",children:[h.jsxs("span",{className:"min-w-0 flex-1",children:[h.jsx("span",{className:ie("block text-[12px]",l?"font-medium text-text-100":"text-text-300"),children:o.label}),o.description?h.jsx("span",{className:"mt-0.5 block text-[11px] text-text-400",children:o.description}):null]}),l?h.jsx(no,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-accent"}):null]})]},o.value||"default")})})}function ode(e,t={}){return{models:e,loading:!1,error:null,load:()=>{},...t}}const ade=e=>e instanceof Error?e.message:String(e);function lde(e,t){const[n,r]=g.useState({key:e,loading:!1,error:null,data:t}),i=g.useRef(0),s=g.useCallback((a,l)=>{const c=++i.current;r(u=>({key:e,loading:!0,error:null,data:u.key===e?u.data:t})),a().then(u=>{i.current===c&&(l==null||l(u),r({key:e,loading:!1,error:null,data:u}))},u=>{i.current===c&&r(d=>({key:e,loading:!1,error:ade(u),data:d.key===e?d.data:t}))})},[e]);return{...n.key===e?n:{loading:!1,error:null,data:t},run:s}}const cde=[];function ude(e){const t=Ni(),n=g.useMemo(()=>new em(t),[t]),r=os(),{capabilities:i}=Am(e),s=lde(e??"",null),{run:o}=s,a=g.useCallback(()=>{e&&o(()=>n.capabilitiesGet(e,{refresh:!0}),l=>{l&&r.setData(`capabilities/${e}`,()=>l)})},[n,r,e,o]);return{models:(i==null?void 0:i.models)??cde,loading:s.loading,error:s.error,load:a}}function dde({models:e,modelList:t,modes:n=[],configSchema:r=[],model:i,resolvedModel:s,resolvedEffort:o,effort:a,permissionMode:l,onPatch:c,readOnly:u=!1}){var _;const d=t??ode(e??[]),f=d.models,p=rde({model:i,resolvedModel:s,resolvedEffort:o,effort:a,permissionMode:l},{models:f,modes:n,configSchema:r}),m=s??i,v=f.map(b=>{const S=b.id===""&&s?`${b.description?`${b.description};`:""}当前:${s}`:b.description;return{value:b.id,label:b.label,...S?{description:S}:{},...b.group?{group:b.group}:{}}}),w=n.map(b=>({value:b.id,label:b.label,...b.description?{description:b.description}:{}})),x=h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"truncate max-w-[120px]","data-testid":"session-config-chip-model",children:m||p.modelLabel}),p.effortLabel?h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"text-text-500",children:"·"}),h.jsx("span",{className:"truncate max-w-[80px]","data-testid":"session-config-chip-effort",children:p.effortLabel})]}):null,p.modeLabel?h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"text-text-500",children:"·"}),h.jsx("span",{"data-testid":"session-config-chip-mode","data-tone":p.modeTone,className:ie("font-semibold",p.modeTone==="danger"?"text-red-400":"text-blue-400"),children:p.modeLabel})]}):null]});return u?h.jsx("span",{"data-testid":"session-config-chip","data-readonly":"true",title:"模型由 persona 所有者设置,访客无法修改",className:"inline-flex items-center gap-1 h-7 px-2.5 rounded-full text-[11px] text-text-400 cursor-default",children:x}):h.jsxs(P_,{children:[h.jsx(R_,{asChild:!0,children:h.jsx("button",{type:"button","data-testid":"session-config-chip",title:"Model / reasoning effort / permission mode",className:"inline-flex items-center gap-1 h-7 px-2.5 rounded-full text-[11px] text-text-400 transition-colors outline-none cursor-pointer hover:bg-text-100/5 hover:text-text-200 data-[state=open]:bg-text-100/5",children:x})}),h.jsxs(gm,{side:"top",align:"end",className:"w-[230px]","data-testid":"session-config-menu",children:[h.jsx(hde,{list:d,current:i,currentLabel:p.modelLabel,options:v,onSelect:b=>c({model:b})}),h.jsx(OE,{testid:"session-config-effort",label:"Reasoning effort",current:p.effortValue,currentLabel:p.effortLabel??"—",options:p.effortOptions,onSelect:b=>c({effort:b})}),w.length>0?h.jsx(OE,{testid:"session-config-mode",label:"Permission mode",current:p.modeValue,currentLabel:((_=n.find(b=>b.id===p.modeValue))==null?void 0:_.label)??"—",currentTone:p.modeTone,options:w,onSelect:b=>c({permissionMode:b})}):null]})]})}function Aj({label:e,currentLabel:t,currentTone:n}){return h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"flex-1 text-text-200",children:e}),h.jsx("span",{className:ie("truncate max-w-[100px]",n==="danger"?"text-red-400 font-semibold":n==="info"?"text-blue-400 font-semibold":"text-text-400"),children:t}),h.jsx(Fn,{className:"w-3.5 h-3.5 shrink-0 text-text-500"})]})}function hde({list:e,current:t,currentLabel:n,options:r,onSelect:i}){const[s,o]=g.useState(!1),a=l=>{l&&!s&&e.load(),o(l)};return h.jsxs(_P,{open:s,onOpenChange:a,children:[h.jsx(M_,{"data-testid":"session-config-model",className:"gap-2 text-[12px]",children:h.jsx(Aj,{label:"Model",currentLabel:n})}),h.jsx(A_,{className:"w-[220px] max-h-[320px] overflow-y-auto",children:h.jsx(sde,{testid:"session-config-model",list:e,options:r,current:t,onSelect:i})})]})}function OE({testid:e,label:t,current:n,currentLabel:r,currentTone:i,options:s,onSelect:o}){const a=s.length===0;return h.jsxs(_P,{children:[h.jsx(M_,{"data-testid":e,disabled:a,className:"gap-2 text-[12px]",children:h.jsx(Aj,{label:t,currentLabel:r,currentTone:i??null})}),h.jsx(A_,{className:"w-[220px] max-h-[320px] overflow-y-auto",children:Mj(s).map((l,c)=>{const u=l.value===n;return h.jsxs(Ye.Fragment,{children:[l.groupHeading?h.jsxs(h.Fragment,{children:[c>0?h.jsx(vm,{}):null,h.jsx(j_,{"data-testid":`${e}-group`,children:l.groupHeading})]}):null,h.jsxs(Ir,{"data-testid":`${e}-option-${l.value||"default"}`,onSelect:()=>o(l.value),className:"items-start gap-2",children:[h.jsxs("span",{className:"flex-1 min-w-0",children:[h.jsx("span",{className:ie("block text-[12px]",u?"text-text-100 font-medium":"text-text-300"),children:l.label}),l.description?h.jsx("span",{className:"block text-[11px] text-text-400 mt-0.5",children:l.description}):null]}),u?h.jsx(no,{className:"w-3.5 h-3.5 shrink-0 text-accent mt-0.5"}):null]})]},l.value||"default")})})]})}Ye.forwardRef(function({icon:t,prefixNode:n,value:r,placeholder:i,selected:s,disabled:o,onOpen:a,testid:l,...c},u){return h.jsxs("button",{ref:u,type:"button",onClick:a,disabled:o,"data-testid":l,className:"inline-flex items-center gap-1.5 rounded-full border border-bg-300 px-3 py-1.5 text-[12px] transition-colors cursor-pointer "+(s?"bg-text-100/5 text-text-100 ":"text-text-300 hover:bg-text-100/5 ")+(o?"opacity-50 cursor-not-allowed ":""),...c,children:[n??(t?h.jsx(t,{className:"w-3.5 h-3.5"}):null),h.jsx("span",{className:"truncate max-w-[180px]",children:r??i})]})});const Qh=[{id:"claude",label:"Claude Code"},{id:"codex",label:"Codex"},{id:"pi",label:"pi"}];function fde(e){return Qh.some(t=>t.id===e)?e:"claude"}function pde({tool:e,onChange:t}){const n=fde(e),r=Qh.find(i=>i.id===n)??Qh[0];return h.jsxs(P_,{children:[h.jsx(R_,{asChild:!0,children:h.jsx("button",{type:"button","data-testid":"session-engine-chip",title:"Engine(发出第一条消息后锁定)",className:"inline-flex items-center h-7 px-2.5 rounded-full text-[11px] text-text-400 transition-colors outline-none cursor-pointer hover:bg-text-100/5 hover:text-text-200 data-[state=open]:bg-text-100/5",children:r.label})}),h.jsx(gm,{side:"top",align:"end",className:"w-[180px]","data-testid":"session-engine-menu",children:Qh.map(i=>h.jsxs(Ir,{"data-testid":`session-engine-option-${i.id}`,onSelect:()=>{i.id!==n&&t(i.id)},children:[h.jsx("span",{className:"flex-1",children:i.label}),i.id===n?h.jsx(no,{className:"w-3.5 h-3.5 text-text-300"}):null]},i.id))})]})}function mde(e,t,n=0){const[r,i]=g.useState(null),[s,o]=g.useState(!1),a=g.useCallback(async()=>{if(!t){i(null);return}o(!0);try{const l=await e.getGitBranch(t);i(l.branch??null)}catch{i(null)}finally{o(!1)}},[e,t]);return g.useEffect(()=>{a()},[a,n]),{branch:r,loading:s,refresh:()=>void a()}}function gde(e,t,n=0){const[r,i]=g.useState(null),[s,o]=g.useState(!1),a=g.useCallback(async()=>{if(!t){i(null);return}o(!0);try{const l=await e.getGitRoot(t);i(l.gitRoot??null)}catch{i(null)}finally{o(!1)}},[e,t]);return g.useEffect(()=>{a()},[a,n]),{worktreeRoot:r,loading:s,refresh:()=>void a()}}const vde=5e3;function xde(e,t,n=0){const[r,i]=g.useState(null);return g.useEffect(()=>{if(!t){i(null);return}let s=!1;const o=async()=>{try{const l=await e.cloudVolumeGet();s||i(l.volume??null)}catch{s||i(null)}},a=n>0?setTimeout(()=>void o(),vde):null;return a||o(),()=>{s=!0,a&&clearTimeout(a)}},[e,t,n]),{volume:r}}const yde=90;function _de(e){return e.sizeBytes>0?Math.min(100,Math.max(0,Math.round(e.usedBytes/e.sizeBytes*100))):0}function BE(e){const t=e/1073741824;return t>=.1?`${t.toFixed(1)} GB`:`${Math.max(1,Math.round(e/1024**2))} MB`}function bde({volume:e}){if(!e)return null;const t=_de(e),n=t>=yde?"warn":"ok",r=new Date(e.measuredAt).toLocaleString(),i=n==="ok"?"上一次任务结束时量的。":"盘快满了:在会话里说「清理一下云盘」,persona 会分析工作区里哪些能删、列给你确认后清掉。";return h.jsxs("span",{"data-testid":"chat-header-cloud-volume","data-tone":n,title:`云盘已用 ${BE(e.usedBytes)} / ${BE(e.sizeBytes)}(${r})。${i}`,className:ie("ml-1.5 inline-flex items-center gap-1.5 px-1.5 py-0.5 rounded text-[11px] tabular-nums",n==="ok"&&"bg-text-100/10 text-text-400",n==="warn"&&"bg-warning-dim text-warning"),children:[h.jsx("span",{className:"relative inline-block w-8 h-1 rounded-full bg-current/20 overflow-hidden","aria-hidden":!0,children:h.jsx("span",{className:"absolute inset-y-0 left-0 rounded-full bg-current",style:{width:`${t}%`}})}),"云盘 ",t,"%"]})}function wde({api:e,session:t,focused:n,totalPanes:r,onFocus:i,onClose:s,onNewSession:o,onOpenConfig:a,onFork:l,onQuickAsk:c,className:u,viewerRole:d="owner",hideHeader:f}){const{capabilities:p}=Am(t.tool),m=ude(t.tool),[v,w]=g.useState(0),[x,_]=g.useState(n);Ye.useEffect(()=>{n&&_(!0)},[n]);const b=Wc(t.tool),S=b?void 0:t.cwd,{branch:C}=mde(e,S,v),{worktreeRoot:k}=gde(e,S,v),{volume:N}=xde(e,b,v),E=r>1,j=!b&&d==="owner"&&!t.toolSessionId,P=L=>{e.sessionUpdate(t.sessionId,L).catch(M=>{console.error("[session-config] session:update failed",t.sessionId,M)})};return h.jsxs("div",{className:`group/pane relative flex-1 ${u??"flex"} flex-row min-w-0 min-h-0 overflow-hidden ${E?`rounded-md border transition-colors ${n?"border-accent ring-1 ring-accent":"border-border"}`:""}`,onMouseDown:i,"data-testid":`session-pane-${t.sessionId}`,children:[h.jsx(q_,{orientation:"horizontal",className:"flex-1 flex min-w-0 min-h-0",children:h.jsx(Qf,{id:"chat",minSize:"400px",children:h.jsx("div",{className:"flex flex-col min-w-0 min-h-0 h-full",children:(n||x)&&h.jsx(Sde,{api:e,session:t,focused:n,liveGitBranch:C,liveWorktreeRoot:k,...b&&N?{cloudVolume:h.jsx(bde,{volume:N})}:{},onNewSession:o,onTurnEnd:()=>w(L=>L+1),onOpenConfig:a,onFork:l,onQuickAsk:c,viewerRole:d,hideHeader:f,configSlot:h.jsxs(h.Fragment,{children:[j?h.jsx(pde,{tool:t.tool,onChange:L=>P({tool:L})}):null,p?h.jsx(dde,{modelList:m,modes:p.permissionModes,configSchema:p.configSchema,model:t.model??"",...t.resolvedModel?{resolvedModel:t.resolvedModel}:{},...t.resolvedEffort?{resolvedEffort:t.resolvedEffort}:{},effort:t.effort??"",permissionMode:t.permissionMode??"",onPatch:P,readOnly:d==="guest"}):null]})})})})}),E&&h.jsx("button",{type:"button",onClick:L=>{L.stopPropagation(),s()},className:"absolute top-1.5 right-1.5 z-10 p-1 rounded-md bg-bg-100/80 backdrop-blur-sm border border-border opacity-0 group-hover/pane:opacity-100 transition-opacity text-text-400 hover:text-text-100 hover:bg-bg-200","aria-label":"close pane","data-testid":`session-pane-close-${t.sessionId}`,children:h.jsx(Qr,{className:"w-3.5 h-3.5"})})]})}function Sde({api:e,session:t,focused:n,liveGitBranch:r,liveWorktreeRoot:i,cloudVolume:s,onNewSession:o,onTurnEnd:a,onOpenConfig:l,onFork:c,onQuickAsk:u,viewerRole:d,configSlot:f,hideHeader:p}){return h.jsx(ede,{extras:{session:t,api:e,focused:n,...r!==void 0?{liveGitBranch:r}:{},...i!==void 0?{liveWorktreeRoot:i}:{},...s!==void 0?{cloudVolume:s}:{},onNewSession:o,onTurnEnd:a,onOpenConfig:l,...c?{onFork:m=>{c(m)}}:{},...u?{onQuickAsk:m=>{u(m)}}:{},...d?{viewerRole:d}:{},...f?{configSlot:f}:{},...p?{hideHeader:p}:{}}})}function kde({personas:e,sessions:t,api:n,selfPrincipalId:r,selectedPersonaId:i,selectedSessionId:s,selectedSession:o,onSelectPersona:a,onSelectSession:l,onCreateSession:c,onDeleteSession:u,onEditSession:d,onCloseSession:f}){return h.jsxs("div",{className:"flex h-screen min-h-0 bg-bg-50","data-testid":"guest-share-page",children:[h.jsx("aside",{className:"w-[280px] shrink-0 overflow-y-auto border-r border-border bg-bg-50",children:h.jsx(qK,{personas:e,sessions:t,activePersonaId:i,activeSessionId:s,onSelectPersona:a,onSelectSession:l,onCreateSession:c,onDeleteSession:u,onEditSession:d,showCopyResume:!1,treatSessionsAsRoots:!0,...r?{ownerPrincipalId:r}:{},isPersonaExpanded:()=>!0})}),h.jsx("main",{className:"flex-1 min-w-0 min-h-0 flex",children:o?h.jsx(wde,{api:n,session:o,focused:!0,totalPanes:1,onFocus:()=>{},onClose:f,onNewSession:()=>{},onOpenConfig:()=>{},viewerRole:"guest"}):h.jsx("div",{className:"flex flex-1 items-center justify-center p-6 text-xs text-text-400","data-testid":"guest-share-empty",children:"选择左侧 persona 开始对话"})})]})}function Cde(){const e=Ni(),t=g.useMemo(()=>new em(e),[e]),n=Kz(e),{sessions:r,refresh:i}=Gz(n),{personas:s}=o4(),o=e7(),a=g.useMemo(()=>{const S=window.location.pathname.match(/^\/s\/([^/]+)/);return S?decodeURIComponent(S[1]):null},[]),l=g.useMemo(()=>r.filter(S=>!S.ephemeral&&S.larkChatId==null),[r]),c=g.useMemo(()=>a?s.filter(S=>S.personaId===a):s,[s,a]),[u,d]=g.useState(null),[f,p]=g.useState(null),[m,v]=g.useState(null);g.useEffect(()=>{let S=!1;return e.request("whoami",{}).then(C=>{S||d(C.capability.id)}).catch(()=>{}),()=>{S=!0}},[e]),g.useEffect(()=>{a&&p(a)},[a]);const w=g.useCallback(async(S,C)=>{const k=await t.sessionCreate({ownerPersonaId:S,...C.trim()?{label:C.trim()}:{}});await i(),p(S),v(k.sessionId)},[t,i]),x=g.useCallback(async S=>{await t.sessionDelete(S),await i(),v(C=>C===S?null:C)},[t,i]),_=g.useCallback(async(S,C)=>{await t.sessionUpdate(S,{label:C.label}),await i()},[t,i]),b=g.useMemo(()=>l.find(S=>S.sessionId===m)??null,[l,m]);return h.jsx(t_.Provider,{value:o,children:h.jsx(kde,{personas:c,sessions:l,api:t,selfPrincipalId:u,selectedPersonaId:f,selectedSessionId:m,selectedSession:b,onSelectPersona:p,onSelectSession:v,onCreateSession:(S,C)=>void w(S,C),onDeleteSession:S=>void x(S),onEditSession:(S,C)=>void _(S,C),onCloseSession:()=>v(null)})})}const $E="https://app.ttcadvisory.com";function Ede({onAuthed:e}){const[t,n]=g.useState(!1),[r,i]=g.useState(null),s=g.useRef(null);g.useEffect(()=>()=>{s.current&&window.removeEventListener("message",s.current)},[]);const o=g.useCallback(()=>{s.current&&(window.removeEventListener("message",s.current),s.current=null),n(!0),i(null);const a=window.location.origin,l=`${$E}/auth/authorize?callback_url=${encodeURIComponent(a)}&auto=1`,c=async d=>{if(d.origin!==$E)return;const f=d.data;if((f==null?void 0:f.type)==="AUTH_CANCEL"){u(),n(!1);return}if(!((f==null?void 0:f.type)!=="AUTH_SUCCESS"||!f.token)){u();try{const p=await fetch(`${window.location.origin}/share/exchange`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({ttcToken:f.token})});if(!p.ok){const v=await p.json().catch(()=>({}));throw new Error(v.code??`exchange failed (${p.status})`)}const m=await p.json();if(!m.visitorToken)throw new Error("no visitorToken in response");e(m.visitorToken)}catch(p){i(p instanceof Error?p.message:String(p)),n(!1)}}},u=()=>{window.removeEventListener("message",c),s.current=null};s.current=d=>void c(d),window.addEventListener("message",s.current),window.open(l,"ttc-login","width=480,height=640")},[e]);return h.jsx("div",{className:"flex min-h-screen items-center justify-center bg-bg-50 p-6 font-sans text-text-100","data-testid":"guest-login",children:h.jsxs("div",{className:"flex w-full max-w-xs flex-col gap-3 rounded-lg border border-border bg-bg-100 px-5 py-6",children:[h.jsx("h1",{className:"text-base font-semibold",children:"登录后进入分享"}),h.jsx("p",{className:"text-[11px] leading-snug text-text-400",children:"使用飞书账号登录,即可在浏览器里与分享给你的 persona 交互,无需安装。"}),r?h.jsxs("p",{className:"text-[11px] leading-snug text-error","data-testid":"guest-login-error",children:["登录失败:",r]}):null,h.jsx("button",{type:"button",disabled:t,onClick:()=>o(),"data-testid":"guest-login-button",className:"w-full rounded border border-border bg-bg-50 px-2 py-1.5 text-xs text-text-200 transition-colors hover:bg-text-100/5 hover:text-text-100 disabled:opacity-50",children:t?"请在弹窗中完成授权…":"飞书登录"})]})})}const R1="clawd-visitor:token";function Ide(e,t){const r=`${e.protocol==="https:"?"wss:":"ws:"}//${e.host}`;return t!=null&&t.devPath?`${r}${t.devPath}`:r}function Nde(){return{async getUrl(e){const t=localStorage.getItem(R1);if(!t)throw new Error("NO_VISITOR_TOKEN");const n=Ide(window.location,{});return await XT(e).upsert({id:"guest",name:"访客",mode:"remote",url:n,token:t}),{url:n}}}}function Tde(e){const t=n=>{document.documentElement.classList.toggle("dark",n==="dark")};return t(e.theme.mode),e.onThemeChange(n=>t(n.mode))}function Pde(){const e=Ni(),t=g.useMemo(()=>Vz(e),[e]);return h.jsx(Iz,{cache:t.cache,children:h.jsx(Pz,{children:h.jsx(Cde,{})})})}function Rde({host:e}){const[t]=g.useState(()=>localStorage.getItem(R1)),[n,r]=g.useState(!1),[i,s]=g.useState(null);return g.useEffect(()=>Tde(e),[e]),g.useEffect(()=>{if(!t)return;let o=!1;return Nde().getUrl(e).then(()=>{o||r(!0)}).catch(a=>{o||s(a instanceof Error?a.message:String(a))}),()=>{o=!0}},[e,t]),t?h.jsx(Jw,{host:e,children:h.jsx(MS,{children:i?h.jsxs("div",{className:"flex min-h-screen items-center justify-center bg-bg-50 p-6 text-center text-xs text-error","data-testid":"guest-share-connect-error",children:["连接失败:",i]}):n?h.jsx(kz,{host:e,children:h.jsx(Pde,{})}):h.jsx("div",{className:"flex min-h-screen items-center justify-center bg-bg-50 p-6 text-xs text-text-400",children:"正在连接…"})})}):h.jsx(Jw,{host:e,children:h.jsx(MS,{children:h.jsx(Ede,{onAuthed:o=>{localStorage.setItem(R1,o),window.location.reload()}})})})}function Mde({filePath:e,oldString:t,newString:n,content:r}){const i=g.useMemo(()=>r!=null?r.split(/\r?\n/).map(s=>({type:"add",text:s})):Ade(t??"",n??""),[t,n,r]);return h.jsxs("div",{"data-testid":"inline-diff",className:"min-w-0 max-w-full rounded-lg border border-bg-300/60 bg-bg-50 overflow-hidden text-[12px] font-mono",children:[h.jsx("div",{className:"flex min-w-0 items-center gap-2 px-3 py-1.5 border-b border-bg-300/40 bg-bg-100/30",children:h.jsx("span",{className:"min-w-0 text-text-400 truncate",title:e,children:e})}),h.jsx("div",{className:"max-h-[320px] max-w-full overflow-auto",children:i.map((s,o)=>h.jsxs("div",{"data-testid":`diff-line-${s.type}`,className:ie("flex min-w-max gap-2 px-3 py-0.5 whitespace-pre",s.type==="add"?"bg-success/10 text-success":s.type==="remove"?"bg-error/10 text-error":"text-text-300"),children:[h.jsx("span",{className:"w-3 shrink-0 select-none opacity-60",children:s.type==="add"?"+":s.type==="remove"?"-":" "}),h.jsx("span",{className:"flex-1",children:s.text||" "})]},o))})]})}function Ade(e,t){const n=e.split(/\r?\n/),r=t.split(/\r?\n/),i=n.length,s=r.length,o=Array.from({length:i+1},()=>new Array(s+1).fill(0));for(let u=i-1;u>=0;u--)for(let d=s-1;d>=0;d--)o[u][d]=n[u]===r[d]?o[u+1][d+1]+1:Math.max(o[u+1][d],o[u][d+1]);const a=[];let l=0,c=0;for(;l<i&&c<s;)n[l]===r[c]?(a.push({type:"equal",text:n[l]}),l++,c++):o[l+1][c]>=o[l][c+1]?(a.push({type:"remove",text:n[l]}),l++):(a.push({type:"add",text:r[c]}),c++);for(;l<i;)a.push({type:"remove",text:n[l++]});for(;c<s;)a.push({type:"add",text:r[c++]});return a}function jde({items:e}){return e.length===0?null:h.jsxs("div",{"data-testid":"todo-checklist",className:"rounded-lg border border-bg-300/60 bg-bg-50 px-3 py-2 text-[13px]",children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-1.5",children:"Todos"}),h.jsx("ul",{className:"flex flex-col gap-1",children:e.map((t,n)=>{const r=t.status==="in_progress"&&t.activeForm||t.content;return h.jsxs("li",{"data-testid":`todo-item-${t.status}`,className:"flex items-start gap-2",children:[h.jsx(Lde,{status:t.status}),h.jsx("span",{className:ie("flex-1 leading-snug",t.status==="completed"?"text-text-400 line-through":t.status==="in_progress"?"text-text-100 font-medium":"text-text-200"),children:r})]},n)})})]})}function Lde({status:e}){return e==="completed"?h.jsx(n_,{className:"w-3.5 h-3.5 text-success mt-0.5 shrink-0"}):e==="in_progress"?h.jsx(Tn,{className:"w-3.5 h-3.5 text-warning mt-0.5 shrink-0 animate-spin"}):h.jsx(M7,{className:"w-3.5 h-3.5 text-text-400 mt-0.5 shrink-0"})}function Dde(e){const t=e??{};return Array.isArray(t.todos)?t.todos.map(n=>{if(!n||typeof n!="object")return null;const r=n,i=typeof r.content=="string"?r.content:"",s=r.status==="pending"||r.status==="in_progress"||r.status==="completed"?r.status:"pending",o=typeof r.activeForm=="string"?r.activeForm:void 0;return{content:i,status:s,activeForm:o}}).filter(n=>n!==null):[]}function Ode({description:e,prompt:t,subagentType:n}){return h.jsxs("div",{"data-testid":"task-checklist",className:"rounded-lg border border-bg-300/60 bg-bg-50 px-3 py-2 text-[13px]",children:[h.jsxs("div",{className:"flex items-center gap-2 text-text-200 font-medium",children:[h.jsx(tm,{className:"w-3.5 h-3.5 text-accent shrink-0"}),h.jsx("span",{className:"truncate",children:e||"subagent task"}),n?h.jsx("span",{className:"shrink-0 px-1.5 py-0.5 rounded-md text-[10px] font-mono bg-accent/10 text-accent",children:n}):null]}),t?h.jsx("div",{className:"mt-1 text-[12px] text-text-400 leading-snug line-clamp-3",children:t}):null]})}function Bde(e){const t=e??{};return{description:typeof t.description=="string"?t.description:"",prompt:typeof t.prompt=="string"?t.prompt:void 0,subagentType:typeof t.subagent_type=="string"?t.subagent_type:void 0}}const $de={render:({input:e})=>Ye.createElement(jde,{items:Dde(e)})},zde={render:({input:e})=>{const{description:t,prompt:n,subagentType:r}=Bde(e);return Ye.createElement(Ode,{description:t,prompt:n,subagentType:r})}},zE={render:({input:e,output:t,error:n,pending:r,fileScope:i,onShareFile:s,onOpenInTab:o,onPreviewMarkdown:a})=>{const l=Hde(e),c=l?Ye.createElement(Mde,{filePath:l.filePath,oldString:l.oldString,newString:l.newString,content:l.content}):void 0;return Ye.createElement(kM,{tool:Fde(e),input:e,output:t,error:n,pending:r,expandedBody:c,...i?{fileScope:i}:{},...s?{onShareFile:s}:{},...o?{onOpenInTab:o}:{},...a?{onPreviewMarkdown:a}:{}})}};function Fde(e){const t=e??{};return"content"in t&&t.content!==void 0?"Write":("old_string"in t&&t.old_string!==void 0,"Edit")}function Hde(e){const t=e??{},n=typeof t.file_path=="string"?t.file_path:null;if(!n)return null;const r=typeof t.old_string=="string"?t.old_string:void 0,i=typeof t.new_string=="string"?t.new_string:void 0,s=typeof t.content=="string"?t.content:void 0;return r==null&&i==null&&s==null?null:{filePath:n,oldString:r,newString:i,content:s}}for(const e of["claude",h9])za.register(e,"TodoWrite",$de),za.register(e,"Task",zde),za.register(e,"Edit",zE),za.register(e,"Write",zE);const jj=document.getElementById("root");if(!jj)throw new Error("guest-main: #root not found");const Ude=pO({});N0.createRoot(jj).render(h.jsx(Ye.StrictMode,{children:h.jsx(Rde,{host:Ude})}));
|